aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_mail.inc.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2007-10-08 23:13:56 +0000
committerrvelices <rv-github@modusoptimus.com>2007-10-08 23:13:56 +0000
commita15cc194b98bf25dc67a9009b0ee2c0f63671642 (patch)
treee78cb90a11a78d191499eb01d1d9b61e63be9d47 /include/functions_mail.inc.php
parentd446a221cde74616db3715f665b0ee7210cb133c (diff)
merge revisions 2121, 2122 and 2123 from trunk to branch-1_7
- function str2url is compatible with utf-8 - removed some old code (useless) - remove str_translate_to_ascii7bits and lang_table_translate_ascii7bits - mail subject and address names can contain accentuated characters git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2125 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions_mail.inc.php')
-rw-r--r--include/functions_mail.inc.php70
1 files changed, 50 insertions, 20 deletions
diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php
index ee7b2dc7e..a20a32797 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,19 @@ 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(
+ '"'
+ .addcslashes($cvt_name,'"')
+ .'"');
+ $cvt_name .= ' ';
+ }
if (strpos($cvt_email, '<') === false)
{
- return $cvt_name.' <'.$cvt_email.'>';
+ return $cvt_name.'<'.$cvt_email.'>';
}
else
{
@@ -112,7 +142,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 +181,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 +190,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 +244,7 @@ function switch_lang_to($language)
}
}
-/*
+/*
* Switch back language pushed with switch_lang_to function
*
* @param: none
@@ -251,7 +281,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 +344,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 +372,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 +382,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 +418,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 +447,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 +500,7 @@ function pwg_mail($to, $args = array())
{
return true;
}
-
+
if (!isset($conf_mail))
{
$conf_mail = get_mail_configuration();
@@ -508,7 +538,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 +606,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']) ?