summaryrefslogtreecommitdiff
path: root/inc/Mailer.class.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2011-11-12 11:35:17 +0100
committerAndreas Gohr <andi@splitbrain.org>2011-11-12 11:35:17 +0100
commit28d2ad801d5eafcfdfc9a122966458b2689a7ec6 (patch)
treec1adf23a19583135a71c04f08018dce6c508e37a /inc/Mailer.class.php
parenta36fc3485fd92593133d56e9bb98d739d70ed94f (diff)
downloadrpg-28d2ad801d5eafcfdfc9a122966458b2689a7ec6.tar.gz
rpg-28d2ad801d5eafcfdfc9a122966458b2689a7ec6.tar.bz2
added old plugin hook back into Mailer class
it now passes the whole Mail object and also signals if the mail sending was successful to the AFTER event. A bunch of references should make it compatible with old plugins.
Diffstat (limited to 'inc/Mailer.class.php')
-rw-r--r--inc/Mailer.class.php95
1 files changed, 62 insertions, 33 deletions
diff --git a/inc/Mailer.class.php b/inc/Mailer.class.php
index 8f2992201..3b7762e77 100644
--- a/inc/Mailer.class.php
+++ b/inc/Mailer.class.php
@@ -452,47 +452,76 @@ class Mailer {
*
* Call this after all data was set
*
- * @fixme we need to support the old plugin hook here!
+ * @triggers MAIL_MESSAGE_SEND
* @return bool true if the mail was successfully passed to the MTA
*/
public function send(){
- // FIXME hook here
-
- $this->cleanHeaders();
-
- // any recipients?
- if(trim($this->headers['To']) === '' &&
- trim($this->headers['Cc']) === '' &&
- trim($this->headers['Bcc']) === '') return false;
+ $success = false;
+
+ // prepare hook data
+ $data = array(
+ // pass the whole mail class to plugin
+ 'mail' => $this,
+ // pass references for backward compatibility
+ 'to' => &$this->headers['To'],
+ 'cc' => &$this->headers['Cc'],
+ 'bcc' => &$this->headers['Bcc'],
+ 'from' => &$this->headers['From'],
+ 'subject' => &$this->headers['Subject'],
+ 'body' => &$this->text,
+ 'params' => &$this->sendparams,
+ 'headers' => '', // plugins shouldn't use this
+ // signal if we mailed successfully to AFTER event
+ 'success' => &$success,
+ );
- // The To: header is special
- if(isset($this->headers['To'])){
- $to = $this->headers['To'];
- unset($this->headers['To']);
- }else{
- $to = '';
- }
+ // do our thing if BEFORE hook approves
+ $evt = new Doku_Event('MAIL_MESSAGE_SEND', $data);
+ if ($evt->advise_before(true)) {
+ // clean up before using the headers
+ $this->cleanHeaders();
+
+ // any recipients?
+ if(trim($this->headers['To']) === '' &&
+ trim($this->headers['Cc']) === '' &&
+ trim($this->headers['Bcc']) === '') return false;
+
+ // The To: header is special
+ if(isset($this->headers['To'])){
+ $to = $this->headers['To'];
+ unset($this->headers['To']);
+ }else{
+ $to = '';
+ }
- // so is the subject
- if(isset($this->headers['Subject'])){
- $subject = $this->headers['Subject'];
- unset($this->headers['Subject']);
- }else{
- $subject = '';
- }
+ // so is the subject
+ if(isset($this->headers['Subject'])){
+ $subject = $this->headers['Subject'];
+ unset($this->headers['Subject']);
+ }else{
+ $subject = '';
+ }
- // make the body
- $body = $this->prepareBody();
- if($body === 'false') return false;
+ // make the body
+ $body = $this->prepareBody();
+ if($body === 'false') return false;
- // cook the headers
- $headers = $this->prepareHeaders();
+ // cook the headers
+ $headers = $this->prepareHeaders();
+ // add any headers set by legacy plugins
+ if(trim($data['headers'])){
+ $headers .= MAILHEADER_EOL.trim($data['headers']);
+ }
- // send the thing
- if(is_null($this->sendparam)){
- return @mail($to,$subject,$body,$headers);
- }else{
- return @mail($to,$subject,$body,$headers,$this->sendparam);
+ // send the thing
+ if(is_null($this->sendparam)){
+ $success = @mail($to,$subject,$body,$headers);
+ }else{
+ $success = @mail($to,$subject,$body,$headers,$this->sendparam);
+ }
}
+ // any AFTER actions?
+ $evt->advise_after();
+ return $success;
}
}