/[drupal]/contributions/modules/reroute_email/reroute_email.module
ViewVC logotype

Diff of /contributions/modules/reroute_email/reroute_email.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.5, Tue Aug 21 19:50:21 2007 UTC revision 1.6, Thu Jul 24 14:32:35 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: reroute_email.module,v 1.1.2.4 2007/08/21 18:42:01 kbahey Exp $  // $Id: reroute_email.module,v 1.1.2.5 2008/04/03 03:18:43 kbahey Exp $
4    
5  define('REROUTE_EMAIL_ADDRESS',  'reroute_email_address');  define('REROUTE_EMAIL_ADDRESS',  'reroute_email_address');
6    
7  function reroute_email_menu($may_cache) {  /**
8     * Implementation of hook_perm().
9     */
10    function reroute_email_perm() {
11      return array('administer reroute email');
12    }
13    
14    function reroute_email_menu() {
15    $items = array();    $items = array();
16    
17    if ($may_cache) {    $items['admin/settings/reroute_email'] = array(
18      $items[] = array(      'title'              => t('Reroute Email'),
19        'path'               => 'admin/settings/reroute_email',      'description'        => t('Reroute emails to a test address.'),
20        'title'              => t('Reroute Email'),      'page callback'      => 'drupal_get_form',
21        'description'        => t('Reroute emails to a test address.'),      'page arguments'     => array('reroute_email_settings'),
22        'callback'           => 'drupal_get_form',      'access arguments'   => array('administer reroute email'),
23        'callback arguments' => array('reroute_email_settings'),    );
       'type'               => MENU_NORMAL_ITEM,  
     );  
   }  
24    
25    return $items;    return $items;
26  }  }
# Line 34  function reroute_email_settings() { Line 38  function reroute_email_settings() {
38    return system_settings_form($form);    return system_settings_form($form);
39  }  }
40    
41  function reroute_email_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {  function reroute_email_mail_alter(&$message) {
42    global $base_url;    global $base_url;
43    
44      if (!empty($message) && is_array($message)) {
45        $mailkey = isset($message['id']) ? $message['id'] : t('<mail id> is missing');
46        $to = isset($message['to']) ? $message['to'] : t('<to> is missing');
47      // Suppress Bcc and Cc fields otherwise email will still go out to those addresses
48        if (isset($message['headers']) && is_array($message['headers'])) {
49          if (isset($message['headers']['Bcc'])) {
50            unset($message['headers']['Bcc']);
51          }
52          if (isset($message['headers']['Cc'])) {
53            unset($message['headers']['Cc']);
54          }
55        }
56      }
57    
58    // Format a message to show at the top    // Format a message to show at the top
59    $msg  = "This email was rerouted.\n";    $msg[] = t("This email was rerouted.");
60    $msg .= "Web site: @site\n";    $msg[] = t("Web site: @site", array('@site' => $base_url));
61    $msg .= "Mail key: @key\n";    $msg[] = t("Mail key: @key", array('@key' => $mailkey));
62    $msg .= "Originally to: <@to>\n";    $msg[] = t("Originally to: <@to>", array('@to' => $to));
63    $msg .= "-----------------------\n";    $msg[] = "-----------------------";
64    
65    // Prepend to the body of the email    // Prepend to the body of the email
66    $body = t($msg, array('@site' => $base_url, '@to' => $to, '@key' => $mailkey)) . $body;    $message['body'] = array_merge($msg, isset($message['body']) ? (is_array($message['body']) ? $message['body'] : array($message['body'])) : array());
67    
68    // Change the $to address to be the one we defined    // Change the $to address to be the one we defined
69    $to = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from'));    $message['to'] = variable_get(REROUTE_EMAIL_ADDRESS, ini_get('sendmail_from'));
70  }  }
71    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.2