diff options
author | rub <rub@piwigo.org> | 2008-03-18 22:02:33 +0000 |
---|---|---|
committer | rub <rub@piwigo.org> | 2008-03-18 22:02:33 +0000 |
commit | 6ae74fe965c16e1e1dae654eb3e3d43e32224bce (patch) | |
tree | a064d0fcda4fd6091fd76dcbeed42ae889e1b40e | |
parent | 0da8401a9ccaa0c92821a0b38e5a9e27ca19af44 (diff) |
Resolved issue 0000815: Email format standardization
Merge branch-1_7 2282:2283 into BSF
git-svn-id: http://piwigo.org/svn/trunk@2284 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/include/functions_notification_by_mail.inc.php | 4 | ||||
-rw-r--r-- | include/class_smtp_mail.inc.php | 15 | ||||
-rw-r--r-- | include/config_default.inc.php | 10 | ||||
-rw-r--r-- | include/functions_mail.inc.php | 83 |
4 files changed, 68 insertions, 44 deletions
diff --git a/admin/include/functions_notification_by_mail.inc.php b/admin/include/functions_notification_by_mail.inc.php index 13a7e2aad..7328df82e 100644 --- a/admin/include/functions_notification_by_mail.inc.php +++ b/admin/include/functions_notification_by_mail.inc.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | file : $Id$ // | last update : $Date$ @@ -200,7 +200,7 @@ function begin_users_env_nbm($is_to_send_mail = false) { // Init mail configuration $env_nbm['email_format'] = get_str_email_format($conf['nbm_send_html_mail']); - $env_nbm['send_as_name'] = ((isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : $conf['gallery_title']); + $env_nbm['send_as_name'] = ((isset($conf['nbm_send_mail_as']) and !empty($conf['nbm_send_mail_as'])) ? $conf['nbm_send_mail_as'] : get_mail_sender_name()); $env_nbm['send_as_mail_address'] = get_webmaster_mail_address(); $env_nbm['send_as_mail_formated'] = format_email($env_nbm['send_as_name'], $env_nbm['send_as_mail_address']); // Init mail counter diff --git a/include/class_smtp_mail.inc.php b/include/class_smtp_mail.inc.php index 450bcada9..c3dbc7964 100644 --- a/include/class_smtp_mail.inc.php +++ b/include/class_smtp_mail.inc.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | file : $Id$ // | last update : $Date$ @@ -121,21 +121,26 @@ class smtp_mail $this->server_write('MAIL FROM: <'.$this->email_webmaster.'>'."\r\n"); $this->server_parse('250'); - $to_header = 'To: '; + if (preg_match('/^\s*to\s*:.*/mi', $headers) === 0) + { + $to_header = 'To: '.implode(',', array_map(create_function('$email','return "<".$email.">";'), $recipients)); + } + else + { + $to_header = ''; + } @reset($recipients); while (list(, $email) = @each($recipients)) { $this->server_write('RCPT TO: <'.$email.'>'."\r\n"); $this->server_parse('250'); - - $to_header .= '<'.$email.'>, '; } $this->server_write('DATA'."\r\n"); $this->server_parse('354'); - $this->server_write('Subject: '.$subject."\r\n".$to_header."\r\n".$headers."\r\n\r\n".$message."\r\n"); + $this->server_write('Subject: '.$subject."\r\n".(empty($to_header) ? "" : $to_header."\r\n").$headers."\r\n\r\n".$message."\r\n"); $this->server_write('.'."\r\n"); $this->server_parse('250'); diff --git a/include/config_default.inc.php b/include/config_default.inc.php index addb5a1f9..1143893d5 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -262,17 +262,15 @@ $conf['mail_options'] = false; // or test. $conf['send_bcc_mail_webmaster'] = false; -// enabled_format_email: -// on true email will be formatted with name and address -// on false email will be only address -// There are webhosting wich not allow email formatted (Lycos, ...) -$conf['enabled_format_email'] = true; - // default_email_format: // Define the default email format use to send email // Value could be text/plain or text/html $conf['default_email_format'] = 'text/html'; +// define the name of sender mail: +// If value is empty, gallery title is used +$conf['mail_sender_name'] = ''; + // smtp configuration // (work if fsockopen function is allowed for smtp port) // smtp_host: smtp server host diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index f826572a6..9ab25a428 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -52,6 +52,18 @@ function encode_mime_header($str) } /* + * Returns the name of the mail sender : + * + * @return string + */ +function get_mail_sender_name() +{ + global $conf; + + return (empty($conf['mail_sender_name']) ? $conf['gallery_title'] : $conf['mail_sender_name']); +} + +/* * Returns an array of mail configuration parameters : * * - mail_options: see $conf['mail_options'] @@ -81,7 +93,7 @@ function get_mail_configuration() // name of the webmaster is the title of the gallery $conf_mail['formated_email_webmaster'] = - format_email($conf['gallery_title'], $conf_mail['email_webmaster']); + format_email(get_mail_sender_name(), $conf_mail['email_webmaster']); $conf_mail['boundary_key'] = generate_key(32); @@ -96,41 +108,51 @@ function get_mail_configuration() */ function format_email($name, $email) { - global $conf; - // Spring cleaning $cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email)); + $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name)); - if ($conf['enabled_format_email']) + if ($cvt_name!="") { - // Spring cleaning - $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name)); - - if ($cvt_name!="") - { - $cvt_name = encode_mime_header( - '"' - .addcslashes($cvt_name,'"') - .'"'); - $cvt_name .= ' '; - } + $cvt_name = encode_mime_header( + '"' + .addcslashes($cvt_name,'"') + .'"'); + $cvt_name .= ' '; + } - if (strpos($cvt_email, '<') === false) - { - return $cvt_name.'<'.$cvt_email.'>'; - } - else - { - return $cvt_name.$cvt_email; - } + if (strpos($cvt_email, '<') === false) + { + return $cvt_name.'<'.$cvt_email.'>'; } else { - return $cvt_email; + return $cvt_name.$cvt_email; } } /** + * Returns an email address list with minimal email string + * + * @param string with email list (email separated by comma) + */ +function get_strict_email_list($email_list) +{ + $result = array(); + $list = explode(',', $email_list); + foreach ($list as $email) + { + if (strpos($email, '<') !== false) + { + $email = preg_replace('/.*<(.*)>.*/i', '$1', $email); + } + $result[] = trim($email); + } + + return implode(',', $result); +} + +/** * Returns an completed array template/theme * completed with get_default_template() * @@ -506,7 +528,7 @@ WHERE * sends an email, using PhpWebGallery specific informations * * @param: - * - to: receiver(s) of the mail. + * - to: receiver(s) of the mail (list separated by comma). * - args: function params of mail function: * o from: sender [default value webmaster email] * o Cc: array of carbon copy receivers of the mail. [default value empty] @@ -545,11 +567,6 @@ function pwg_mail($to, $args = array()) set_make_full_url(); } - if (!empty($to)) - { - $to = format_email('', $to); - } - if (empty($args['from'])) { $args['from'] = $conf_mail['formated_email_webmaster']; @@ -597,6 +614,10 @@ function pwg_mail($to, $args = array()) { $headers.= 'To: undisclosed-recipients: ;'."\n"; } + else + { + $headers.= 'To: '.$to."\n"; + } if (!empty($args['Cc'])) { @@ -719,7 +740,7 @@ function pwg_mail($to, $args = array()) return trigger_event('send_mail', false, /* Result */ - trigger_event('send_mail_to', $to), + trigger_event('send_mail_to', get_strict_email_list($to)), trigger_event('send_mail_subject', $cvt_subject), trigger_event('send_mail_content', $content), trigger_event('send_mail_headers', $headers), |