14dc22474SAndreas Gohr<?php 24dc22474SAndreas Gohr/** 34dc22474SAndreas Gohr * DokuWiki Plugin smtp (Action Component) 44dc22474SAndreas Gohr * 54dc22474SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 64dc22474SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 74dc22474SAndreas Gohr */ 84dc22474SAndreas Gohr 94dc22474SAndreas Gohr// must be run within Dokuwiki 104dc22474SAndreas Gohrif(!defined('DOKU_INC')) die(); 114dc22474SAndreas Gohr 124dc22474SAndreas Gohrclass action_plugin_smtp extends DokuWiki_Action_Plugin { 134dc22474SAndreas Gohr 144dc22474SAndreas Gohr /** 154dc22474SAndreas Gohr * Registers a callback function for a given event 164dc22474SAndreas Gohr * 174dc22474SAndreas Gohr * @param Doku_Event_Handler $controller DokuWiki's event controller object 184dc22474SAndreas Gohr * @return void 194dc22474SAndreas Gohr */ 204dc22474SAndreas Gohr public function register(Doku_Event_Handler $controller) { 214dc22474SAndreas Gohr 220b7ac7c9SAndreas Gohr $controller->register_hook('MAIL_MESSAGE_SEND', 'BEFORE', $this, 'handle_mail_message_send'); 234dc22474SAndreas Gohr 244dc22474SAndreas Gohr } 254dc22474SAndreas Gohr 264dc22474SAndreas Gohr /** 274dc22474SAndreas Gohr * [Custom event handler which performs action] 284dc22474SAndreas Gohr * 294dc22474SAndreas Gohr * @param Doku_Event $event event object by reference 304dc22474SAndreas Gohr * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 314dc22474SAndreas Gohr * handler was registered] 324dc22474SAndreas Gohr * @return void 334dc22474SAndreas Gohr */ 344dc22474SAndreas Gohr 354dc22474SAndreas Gohr public function handle_mail_message_send(Doku_Event &$event, $param) { 360b7ac7c9SAndreas Gohr require_once __DIR__ . '/loader.php'; 370b7ac7c9SAndreas Gohr 380b7ac7c9SAndreas Gohr /** @var Mailer $mailer Our Mailer with all the data */ 390b7ac7c9SAndreas Gohr $mailer = $event->data['mail']; 40*25673c62SAndreas Gohr $rcpt = $mailer->cleanAddress($event->data['to']) . ',' . 41*25673c62SAndreas Gohr $mailer->cleanAddress($event->data['cc']) . ',' . 42*25673c62SAndreas Gohr $mailer->cleanAddress($event->data['bcc']); 430b7ac7c9SAndreas Gohr $from = $event->data['from']; 440b7ac7c9SAndreas Gohr 450b7ac7c9SAndreas Gohr $message = new \splitbrain\dokuwiki\plugin\smtp\Message( 460b7ac7c9SAndreas Gohr $from, 47*25673c62SAndreas Gohr $rcpt, 480b7ac7c9SAndreas Gohr $mailer->dump() 490b7ac7c9SAndreas Gohr ); 500b7ac7c9SAndreas Gohr 510b7ac7c9SAndreas Gohr $smtp = new \Tx\Mailer\SMTP(); 520b7ac7c9SAndreas Gohr $smtp->setServer('localhost', 2525, null); 530b7ac7c9SAndreas Gohr 540b7ac7c9SAndreas Gohr $smtp->send($message); 554dc22474SAndreas Gohr } 564dc22474SAndreas Gohr 574dc22474SAndreas Gohr} 584dc22474SAndreas Gohr 594dc22474SAndreas Gohr// vim:ts=4:sw=4:et: 60