diff options
author | rvelices <rv-github@modusoptimus.com> | 2007-10-04 04:39:59 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2007-10-04 04:39:59 +0000 |
commit | c4a4ea480652d8589707667e678e2fb74982161c (patch) | |
tree | 4ffccea53f6aa0a0d6e5fe94311f89c82bc35f6a /include/functions_mail.inc.php | |
parent | fb9abe8fea6bf40c5628467158edf2fc6881a8dd (diff) |
- mail subject and address names can contain accentuated characters (completely obsoleted str_translate_to_ascii7bits and lang_table_translate_ascii7bits but not yet removed from code)
git-svn-id: http://piwigo.org/svn/trunk@2121 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions_mail.inc.php')
-rw-r--r-- | include/functions_mail.inc.php | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index ee7b2dc7e..19ec06ed7 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -28,6 +28,29 @@ // | functions | // +-----------------------------------------------------------------------+ + +/** + * Encodes a string using Q form if required (RFC2045) + * mail headers MUST contain only US-ASCII characters + */ +function encode_mime_header($str) +{ + $x = preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); + if ($x==0) + { + return $str; + } + // Replace every high ascii, control =, ? and _ characters + $str = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', + "'='.sprintf('%02X', ord('\\1'))", $str); + + // Replace every spaces to _ (more readable than =20) + $str = str_replace(" ", "_", $str); + + global $lang_info; + return '=?'.$lang_info['charset'].'?Q?'.$str.'?='; +} + /* * Returns an array of mail configuration parameters : * @@ -80,12 +103,15 @@ function format_email($name, $email) // Spring cleaning $cvt_name = trim(preg_replace('#[\n\r]+#s', '', $name)); $cvt_email = trim(preg_replace('#[\n\r]+#s', '', $email)); - // Ascii convertion - $cvt_name = '"'.addslashes(str_translate_to_ascii7bits($cvt_name)).'"'; + + if ($cvt_name!="") + { + $cvt_name = encode_mime_header('"'.$cvt_name.'"').' '; + } if (strpos($cvt_email, '<') === false) { - return $cvt_name.' <'.$cvt_email.'>'; + return $cvt_name.'<'.$cvt_email.'>'; } else { @@ -112,7 +138,7 @@ function get_array_template_theme($args = array()) global $conf; $res = array(); - + if (empty($args['template']) or empty($args['theme'])) { list($res['template'], $res['theme']) = explode('/', get_default_template()); @@ -151,7 +177,7 @@ function get_mail_template($email_format, $args = array()) } /** - * Return string email format (html or not) + * Return string email format (html or not) * * @param string format */ @@ -160,7 +186,7 @@ function get_str_email_format($is_html) return ($is_html ? 'text/html' : 'text/plain'); } -/* +/* * Switch language to param language * All entries are push on language stack * @@ -214,7 +240,7 @@ function switch_lang_to($language) } } -/* +/* * Switch back language pushed with switch_lang_to function * * @param: none @@ -251,7 +277,7 @@ function switch_lang_back() */ /* * send en notification email to all administrators - * if a administrator is doing action, + * if a administrator is doing action, * he's be removed to email list * * @param: @@ -314,7 +340,7 @@ order by ( 'Bcc' => $admins, 'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject), - 'content' => + 'content' => l10n_args($keyargs_content)."\n\n" .l10n_args($keyargs_content_admin_info)."\n", 'content_format' => 'text/plain' @@ -342,7 +368,7 @@ order by * @return boolean (Ok or not) */ function pwg_mail_group( - $group_id, $email_format, $keyargs_subject, + $group_id, $email_format, $keyargs_subject, $dirname, $tpl_shortname, $assign_vars = array(), $language_selected = '') { @@ -352,11 +378,11 @@ function pwg_mail_group( $query = ' SELECT distinct language, template -FROM - '.USER_GROUP_TABLE.' as ug +FROM + '.USER_GROUP_TABLE.' as ug INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id -WHERE +WHERE '.$conf['user_fields']['email'].' IS NOT NULL AND group_id = '.$group_id; @@ -388,11 +414,11 @@ WHERE SELECT u.'.$conf['user_fields']['username'].' as username, u.'.$conf['user_fields']['email'].' as mail_address -FROM - '.USER_GROUP_TABLE.' as ug +FROM + '.USER_GROUP_TABLE.' as ug INNER JOIN '.USERS_TABLE.' as u ON '.$conf['user_fields']['id'].' = ug.user_id INNER JOIN '.USER_INFOS_TABLE.' as ui ON ui.user_id = ug.user_id -WHERE +WHERE '.$conf['user_fields']['email'].' IS NOT NULL AND group_id = '.$group_id.' AND language = \''.$elem['language'].'\' @@ -417,7 +443,7 @@ WHERE switch_lang_to($elem['language']); $mail_template = get_mail_template($email_format, $elem); - $mail_template->set_filename($tpl_shortname, + $mail_template->set_filename($tpl_shortname, (empty($dirname) ? '' : $dirname.'/').$tpl_shortname.'.tpl'); $mail_template->assign_vars($assign_vars); @@ -470,7 +496,7 @@ function pwg_mail($to, $args = array()) { return true; } - + if (!isset($conf_mail)) { $conf_mail = get_mail_configuration(); @@ -508,7 +534,7 @@ function pwg_mail($to, $args = array()) // Spring cleaning $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject'])); // Ascii convertion - $cvt_subject = str_translate_to_ascii7bits($cvt_subject); + $cvt_subject = encode_mime_header($cvt_subject); if (!isset($args['content'])) { @@ -576,7 +602,7 @@ function pwg_mail($to, $args = array()) 'CONTENT_ENCODING' => $lang_info['charset'], 'LANG' => $lang_info['code'], 'DIR' => $lang_info['direction'], - + // Footer 'GALLERY_URL' => isset($page['gallery_url']) ? |