aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_mail.inc.php
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2007-10-09 23:03:30 +0000
committerrub <rub@piwigo.org>2007-10-09 23:03:30 +0000
commit26d336bd3b8027ec67f30e92c6fc5309060adb3a (patch)
tree894278ec4bcc7ab95b024efb95fb8f19f3e0f28f /include/functions_mail.inc.php
parent33b7f46dd32f2495407957364a259f95aa2be218 (diff)
Commit 2128 was done with a latest version.
Fix my mistake! git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2133 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/functions_mail.inc.php')
-rw-r--r--include/functions_mail.inc.php72
1 files changed, 51 insertions, 21 deletions
diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php
index 5c84c2b11..1a498dba8 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;
@@ -387,11 +417,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'].'\'
@@ -416,7 +446,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']) ?
@@ -669,7 +699,7 @@ function pwg_mail($to, $args = array())
{
global $user;
@mkdir(PHPWG_ROOT_PATH.'testmail');
- $filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'].$cvt_subject;
+ $filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'];
if ($args['content_format'] == 'text/plain')
{
$filename .= '.txt';