[geeklog-cvs] geeklog: Changed the former $cc parameter for COM_mail into an o...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sat Sep 19 08:17:32 EDT 2009
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/6bfe0553c0e3
changeset: 7322:6bfe0553c0e3
user: Dirk Haun <dirk at haun-online.de>
date: Sat Sep 19 11:50:37 2009 +0200
description:
Changed the former $cc parameter for COM_mail into an optional array of additional email headers
diffstat:
public_html/docs/history | 2 +
public_html/lib-common.php | 115 ++++++++++++++++++-------------------
2 files changed, 58 insertions(+), 59 deletions(-)
diffs (179 lines):
diff -r 1a45dcdd9ce7 -r 6bfe0553c0e3 public_html/docs/history
--- a/public_html/docs/history Sat Sep 19 09:44:15 2009 +0200
+++ b/public_html/docs/history Sat Sep 19 11:50:37 2009 +0200
@@ -3,6 +3,8 @@
Oct ??, 2009 (1.6.1)
------------
+- Made the former $cc parameter for COM_mail an optional array of additional
+ email headers (using a string for that parameter still works as CC:) [Dirk]
- Fixed reply notification for the very first comment (bug #0000973)
[dengen, Dirk]
- When an anonymous commentor left a name, use it in the comment notification
diff -r 1a45dcdd9ce7 -r 6bfe0553c0e3 public_html/lib-common.php
--- a/public_html/lib-common.php Sat Sep 19 09:44:15 2009 +0200
+++ b/public_html/lib-common.php Sat Sep 19 11:50:37 2009 +0200
@@ -3217,10 +3217,10 @@
/**
* Send an email.
*
-* All emails sent by Geeklog are sent through this function now.
-*
-* NOTE: Please note that using the $cc parameter will expose the email addresses
-* of all recipients. Use with care.
+* All emails sent by Geeklog are sent through this function.
+*
+* NOTE: Please note that using CC: will expose the email addresses of
+* all recipients. Use with care.
*
* @param string $to recipients name and email address
* @param string $subject subject of the email
@@ -3228,47 +3228,44 @@
* @param string $from (optional) sender of the the email
* @param boolean $html (optional) true if to be sent as HTML email
* @param int $priority (optional) add X-Priority header, if > 0
-* @param string $cc (optional) other recipients (name + email)
+* @param mixed $optional (optional) other headers or CC:
* @return boolean true if successful, otherwise false
*
*/
-function COM_mail( $to, $subject, $message, $from = '', $html = false, $priority = 0, $cc = '' )
+function COM_mail($to, $subject, $message, $from = '', $html = false, $priority = 0, $optional = null)
{
global $_CONF;
static $mailobj;
- if( empty( $from ))
- {
- $from = COM_formatEmailAddress( $_CONF['site_name'], $_CONF['site_mail']);
- }
-
- $to = substr( $to, 0, strcspn( $to, "\r\n" ));
- $cc = substr( $cc, 0, strcspn( $cc, "\r\n" ));
- $from = substr( $from, 0, strcspn( $from, "\r\n" ));
- $subject = substr( $subject, 0, strcspn( $subject, "\r\n" ));
- $subject = COM_emailEscape( $subject );
-
- if( function_exists( 'CUSTOM_mail' ))
- {
- return CUSTOM_mail( $to, $subject, $message, $from, $html, $priority, $cc );
- }
-
- include_once( 'Mail.php' );
- include_once( 'Mail/RFC822.php' );
+ if (empty($from)) {
+ $from = COM_formatEmailAddress($_CONF['site_name'], $_CONF['site_mail']);
+ }
+
+ $to = substr($to, 0, strcspn($to, "\r\n"));
+ if (($optional != null) && !is_array($optional)) {
+ $optional = substr($optional, 0, strcspn($optional, "\r\n"));
+ }
+ $from = substr($from, 0, strcspn($from, "\r\n"));
+ $subject = substr($subject, 0, strcspn($subject, "\r\n"));
+ $subject = COM_emailEscape($subject);
+
+ if (function_exists('CUSTOM_mail')) {
+ return CUSTOM_mail($to, $subject, $message, $from, $html, $priority,
+ $optional);
+ }
+
+ include_once 'Mail.php';
+ include_once 'Mail/RFC822.php';
$method = $_CONF['mail_settings']['backend'];
- if( !isset( $mailobj ))
- {
- if(( $method == 'sendmail' ) || ( $method == 'smtp' ))
- {
- $mailobj =& Mail::factory( $method, $_CONF['mail_settings'] );
- }
- else
- {
+ if (! isset($mailobj)) {
+ if (($method == 'sendmail') || ($method == 'smtp')) {
+ $mailobj =& Mail::factory($method, $_CONF['mail_settings']);
+ } else {
$method = 'mail';
- $mailobj =& Mail::factory( $method );
+ $mailobj =& Mail::factory($method);
}
}
@@ -3276,34 +3273,28 @@
$headers = array();
$headers['From'] = $from;
- if( $method != 'mail' )
- {
+ if ($method != 'mail') {
$headers['To'] = $to;
}
- if( !empty( $cc ))
- {
- $headers['Cc'] = $cc;
- }
- $headers['Date'] = date( 'r' ); // RFC822 formatted date
- if( $method == 'smtp' )
- {
- list( $usec, $sec ) = explode( ' ', microtime());
- $m = substr( $usec, 2, 5 );
- $headers['Message-Id'] = '<' . date( 'YmdHis' ) . '.' . $m
+ if (($optional != null) && !is_array($optional) && !empty($optional)) {
+ // assume old (optional) CC: header
+ $headers['Cc'] = $optional;
+ }
+ $headers['Date'] = date('r'); // RFC822 formatted date
+ if($method == 'smtp') {
+ list($usec, $sec) = explode(' ', microtime());
+ $m = substr($usec, 2, 5);
+ $headers['Message-Id'] = '<' . date('YmdHis') . '.' . $m
. '@' . $_CONF['mail_settings']['host'] . '>';
}
- if( $html )
- {
+ if ($html) {
$headers['Content-Type'] = 'text/html; charset=' . $charset;
$headers['Content-Transfer-Encoding'] = '8bit';
- }
- else
- {
+ } else {
$headers['Content-Type'] = 'text/plain; charset=' . $charset;
}
$headers['Subject'] = $subject;
- if( $priority > 0 )
- {
+ if ($priority > 0) {
$headers['X-Priority'] = $priority;
}
$headers['X-Mailer'] = 'Geeklog ' . VERSION;
@@ -3317,13 +3308,19 @@
}
}
- $retval = $mailobj->send( $to, $headers, $message );
- if( $retval !== true )
- {
- COM_errorLog( $retval->toString(), 1 );
- }
-
- return( $retval === true ? true : false );
+ // add optional headers last
+ if (($optional != null) && is_array($optional)) {
+ foreach ($optional as $h => $v) {
+ $headers[$h] = $v;
+ }
+ }
+
+ $retval = $mailobj->send($to, $headers, $message);
+ if ($retval !== true) {
+ COM_errorLog($retval->toString(), 1);
+ }
+
+ return($retval === true ? true : false);
}
More information about the geeklog-cvs
mailing list