Adds support for "catchmail" config value
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Wed, 27 May 2009 13:57:58 +0000 (15:57 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Wed, 27 May 2009 13:57:58 +0000 (15:57 +0200)
Set in [Core] section, forces all mails to be sent to admin_email instead of
the recipients defined by addTo, addCc, addBcc.
Useful for development purposes.

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/plglobals.php
classes/plmailer.php

index 9818db1..0fe88f1 100644 (file)
@@ -64,6 +64,13 @@ class PlGlobals
                                // 'r'  => read/only
                                // ''   => site down
 
+    /** Catch-all mode for mails
+     * If set to 1, all emails are sent to admin_email (defined in [Core])
+     * instead of their actual destination (but apparent from and to aren't
+     * modified)
+     */
+    public $catchmail = false;
+
     /** Tell smarty to check the timestamps of the templates to decide
      * whether recompile the template or not. If this option is false and
      * debug mode is not activate, templates won't be recompile if they changed.
index 2106f02..e3e348d 100644 (file)
@@ -347,6 +347,18 @@ class PlMailer extends Mail_Mime {
             $dests[] = "{$a->mailbox}@{$a->host}";
         }
 
+        // Support for "catch-all" mail address : all emails are sent to
+        // admin_email instead of actual recipients
+        global $globals;
+        if($globals->catchmail) {
+            require_once 'Mail/RFC822.php';
+            if(@Mail_RFC822::isValidInetAddress($globals->admin_email)){
+                $dests = array($globals->admin_email);
+            }else if(@Mail_RFC822::isValidInetAddress($globals->core->admin_email)){
+                $dests = array($globals->core->admin_email);
+            }
+        }
+
         // very important to do it in THIS order very precisely.
         $body = $this->get(array('text_charset' => $this->charset,
                                  'text_encoding' => '8bit',