thomascube
2009-05-14 e54f6c7a9efa28633616064bea68a3d2b4468272
Add hook 'message_sent' for logging or backup purpose

1 files modified
27 ■■■■ changed files
program/steps/mail/func.inc 27 ●●●● patch | view | raw | blame | history
program/steps/mail/func.inc
@@ -1293,8 +1293,7 @@
  $headers = $message->headers();
  // send thru SMTP server using custom SMTP library
  if ($CONFIG['smtp_server'])
    {
  if ($CONFIG['smtp_server']) {
    // generate list of recipients
    $a_recipients = array($mailto);
  
@@ -1317,11 +1316,9 @@
    if (!$sent)
      raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__,
                        'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE);
    }
  }
  // send mail using PHP's mail() function
  else
    {
  else {
    // unset some headers because they will be added by the mail() function
    $headers_enc = $message->headers($headers);
    $headers_php = $message->_headers;
@@ -1342,19 +1339,21 @@
      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str);
    else
      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from");
    }
  }
  
  if ($sent)
  {
  if ($sent) {
    $RCMAIL->plugins->exec_hook('message_sent', array('headers' => $headers, 'body' => $msg_body));
    // remove MDN headers after sending
    unset($headers['Return-Receipt-To'], $headers['Disposition-Notification-To']);
    
    if ($CONFIG['smtp_log'])
    if ($CONFIG['smtp_log']) {
      write_log('sendmail', sprintf("User %s [%s]; Message for %s; %s",
        $RCMAIL->user->get_username(),
        $_SERVER['REMOTE_ADDR'],
        $mailto,
        !empty($smtp_response) ? join('; ', $smtp_response) : ''));
        $RCMAIL->user->get_username(),
        $_SERVER['REMOTE_ADDR'],
        $mailto,
        !empty($smtp_response) ? join('; ', $smtp_response) : ''));
    }
  }
  
  $message->_headers = array();