-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathaction.php
More file actions
103 lines (94 loc) · 3.09 KB
/
Copy pathaction.php
File metadata and controls
103 lines (94 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use splitbrain\dokuwiki\plugin\smtp\Message;
use splitbrain\dokuwiki\plugin\smtp\Logger;
use Tx\Mailer\SMTP;
/**
* DokuWiki Plugin smtp (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <andi@splitbrain.org>
*/
class action_plugin_smtp extends ActionPlugin
{
/**
* Registers a callback function for a given event
*
* @param EventHandler $controller DokuWiki's event controller object
* @return void
*/
public function register(EventHandler $controller)
{
$controller->register_hook('MAIL_MESSAGE_SEND', 'BEFORE', $this, 'handleMailMessageSend');
}
/**
* [Custom event handler which performs action]
*
* @param Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
* @return void
*/
public function handleMailMessageSend(Event $event, $param)
{
// prepare the message
/** @var Mailer $mailer Our Mailer with all the data */
$mailer = $event->data['mail'];
$body = $mailer->dump(); // this also prepares all internal variables of the mailer
$rcpt = $event->data['to'] . ',' .
$event->data['cc'] . ',' .
$event->data['bcc'];
$from = $event->data['from'];
$message = new Message(
$from,
$rcpt,
$body
);
// prepare the SMTP communication lib
$logger = new Logger();
$smtp = new SMTP($logger);
$smtp->setServer(
$this->getConf('smtp_host'),
$this->getConf('smtp_port'),
$this->getConf('smtp_ssl'),
$this->getConf('smtp_allow_insecure')
);
if ($this->getConf('auth_user')) {
$smtp->setAuth(
$this->getConf('auth_user'),
$this->getConf('auth_pass')
);
}
$smtp->setEhlo(
helper_plugin_smtp::getEHLO($this->getConf('localdomain'))
);
// send the message
try {
$smtp->send($message);
$ok = true;
} catch (Exception $e) {
msg('There was an unexpected problem communicating with SMTP: ' . $e->getMessage(), -1);
$ok = false;
}
// give debugging help on error
if (!$ok && $this->getConf('debug')) {
$log = [];
foreach ($logger->getLog() as $line) {
$log[] = trim($line[1]);
}
$log = trim(implode("\n", $log));
msg(
'SMTP log:<br /><pre>' . hsc($log) .
'</pre><b>Above may contain passwords - do not post online!</b>',
-1
);
}
// finish event handling
$event->preventDefault();
$event->stopPropagation();
$event->result = $ok;
$event->data['success'] = $ok;
}
}