aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2007-02-12 23:21:23 +0000
committerrub <rub@piwigo.org>2007-02-12 23:21:23 +0000
commit9ceec74971f85022ad61699dc209d7044945b149 (patch)
tree4372d31f0ab0540c4a877cd70a1d8a4068f21657
parent62c1993adcfc257d98e47dc7efa8633209dbac3b (diff)
When not template are selected for mail, PWG uses default template..
Sent multi-part message in MIME format. (With only one part for the moment). Improvement pwg_mail function. git-svn-id: http://piwigo.org/svn/trunk@1809 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/include/functions_notification_by_mail.inc.php31
-rw-r--r--admin/notification_by_mail.php21
-rw-r--r--include/functions_mail.inc.php170
-rw-r--r--include/picture_comment.inc.php6
-rw-r--r--password.php3
-rw-r--r--register.php11
-rw-r--r--template/yoga/mail/text/html/header.tpl7
-rw-r--r--template/yoga/mail/text/plain/header.tpl4
8 files changed, 177 insertions, 76 deletions
diff --git a/admin/include/functions_notification_by_mail.inc.php b/admin/include/functions_notification_by_mail.inc.php
index 64358ec9e..10ffd15ae 100644
--- a/admin/include/functions_notification_by_mail.inc.php
+++ b/admin/include/functions_notification_by_mail.inc.php
@@ -257,12 +257,12 @@ function end_users_env_nbm()
*
* Return none
*/
-function set_user_on_env_nbm($user_id, $is_action_send)
+function set_user_on_env_nbm(&$nbm_user, $is_action_send)
{
global $user, $lang, $lang_info, $env_nbm;
$user = array();
- $user['id'] = $user_id;
+ $user['id'] = $nbm_user['user_id'];
$user = array_merge($user, getuserdata($user['id'], true));
list($user['template'], $user['theme']) = explode('/', $user['template']);
@@ -286,7 +286,11 @@ function set_user_on_env_nbm($user_id, $is_action_send)
if ($is_action_send)
{
- $env_nbm['mail_template'] = get_mail_template($env_nbm['email_format']);
+ $nbm_user['template'] = $user['template'];
+ $nbm_user['theme'] = $user['theme'];
+ $env_nbm['mail_template'] =
+ get_mail_template($env_nbm['email_format'],
+ array('template' => $nbm_user['template'], 'theme' => $nbm_user['theme']));
$env_nbm['mail_template']->set_filename('notification_by_mail', 'admin/notification_by_mail.tpl');
}
}
@@ -431,7 +435,7 @@ function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, $is_su
if ($nbm_user['mail_address'] != '')
{
// set env nbm user
- set_user_on_env_nbm($nbm_user['user_id'], true);
+ set_user_on_env_nbm($nbm_user, true);
$subject = '['.$conf['gallery_title'].']: '.($is_subscribe ? l10n('nbm_object_subscribe'): l10n('nbm_object_unsubscribe'));
@@ -445,13 +449,20 @@ function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, $is_su
$section_action_by, array('DUMMY' => 'dummy')
);
- if (pwg_mail(
+ if (pwg_mail
+ (
format_email($nbm_user['username'], $nbm_user['mail_address']),
- $env_nbm['send_as_mail_formated'],
- $subject,
- $env_nbm['mail_template']->parse('notification_by_mail', true),
- $env_nbm['email_format'], $env_nbm['email_format']
- ))
+ array
+ (
+ 'from' => $env_nbm['send_as_mail_formated'],
+ 'subject' => $subject,
+ 'email_format' => $env_nbm['email_format'],
+ 'content' => $env_nbm['mail_template']->parse('notification_by_mail', true),
+ 'content_format' => $env_nbm['email_format'],
+ 'template' => $nbm_user['template'],
+ 'theme' => $nbm_user['theme']
+ )
+ ))
{
inc_mail_sent_success($nbm_user);
}
diff --git a/admin/notification_by_mail.php b/admin/notification_by_mail.php
index a000fdb4b..33e5f59dd 100644
--- a/admin/notification_by_mail.php
+++ b/admin/notification_by_mail.php
@@ -273,7 +273,7 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
}
// set env nbm user
- set_user_on_env_nbm($nbm_user['user_id'], $is_action_send);
+ set_user_on_env_nbm($nbm_user, $is_action_send);
if ($is_action_send)
{
@@ -377,13 +377,20 @@ function do_action_send_mail_notification($action = 'list_to_send', $check_key_l
'byebye', array('SEND_AS_NAME' => $env_nbm['send_as_name'])
);
- if (pwg_mail(
+ if (pwg_mail
+ (
format_email($nbm_user['username'], $nbm_user['mail_address']),
- $env_nbm['send_as_mail_formated'],
- $subject,
- $env_nbm['mail_template']->parse('notification_by_mail', true),
- $env_nbm['email_format'], $env_nbm['email_format']
- ))
+ array
+ (
+ 'from' => $env_nbm['send_as_mail_formated'],
+ 'subject' => $subject,
+ 'email_format' => $env_nbm['email_format'],
+ 'content' => $env_nbm['mail_template']->parse('notification_by_mail', true),
+ 'content_format' => $env_nbm['email_format'],
+ 'template' => $nbm_user['template'],
+ 'theme' => $nbm_user['theme']
+ )
+ ))
{
inc_mail_sent_success($nbm_user);
diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php
index f201cd32f..d534c073b 100644
--- a/include/functions_mail.inc.php
+++ b/include/functions_mail.inc.php
@@ -64,6 +64,8 @@ function get_mail_configuration()
$conf_mail['formated_email_webmaster'] =
format_email($conf['gallery_title'], $conf_mail['email_webmaster']);
+ $conf_mail['boundary_key'] = generate_key(32);
+
return $conf_mail;
}
@@ -97,16 +99,53 @@ function format_email($name, $email)
}
/**
- * Returns an new mail template
+ * Return an completed array template/theme
+ * completed with $conf['default_template']
*
- * @param none
+ * @params:
+ * - args: incompleted array of template/theme
+ * o template: template to use [default $conf['default_template']]
+ * o theme: template to use [default $conf['default_template']]
*/
-function get_mail_template($email_format)
+function get_array_template_theme($args = array())
{
- global $user;
+ global $conf;
+
+ $res = array();
+
+ if (empty($args['template']) or empty($args['theme']))
+ {
+ list($res['template'], $res['theme']) = explode('/', $conf['default_template']);
+ }
+
+ if (!empty($args['template']))
+ {
+ $res['template'] = $args['template'];
+ }
+
+ if (!empty($args['theme']))
+ {
+ $res['theme'] = $args['theme'];
+ }
- $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme']);
- $mail_template->set_rootdir(PHPWG_ROOT_PATH.'template/'.$user['template'].'/mail/'.$email_format);
+ return $res;
+}
+
+/**
+ * Return an new mail template
+ *
+ * @params:
+ * - email_format: mail format
+ * - args: function params of mail function:
+ * o template: template to use [default $conf['default_template']]
+ * o theme: template to use [default $conf['default_template']]
+ */
+function get_mail_template($email_format, $args = array())
+{
+ $args = get_array_template_theme($args);
+
+ $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']);
+ $mail_template->set_rootdir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format);
return $mail_template;
}
@@ -123,50 +162,79 @@ function get_str_email_format($is_html)
/**
* sends an email, using PhpWebGallery specific informations
+ *
+ * @param:
+ * - to: Receiver, or receivers of the mail.
+ * - args: function params of mail function:
+ * o from: sender [default value webmaster email]
+ * o subject [default value 'PhpWebGallery']
+ * o content: content of mail [default value '']
+ * o content_format: format of mail content [default value 'text/plain']
+ * o email_format: global mail format [default value $conf_mail['default_email_format']]
+ * o template: template to use [default $conf['default_template']]
+ * o theme: template to use [default $conf['default_template']]
*/
-function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $format_infos = 'text/plain', $email_format = null)
+//function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $infos_format = 'text/plain', $email_format = null)
+function pwg_mail($to, $args = array())
{
- global $conf, $conf_mail, $lang_info, $page, $user;
-
- $cvt7b_subject = str_translate_to_ascii7bits($subject);
+ global $conf, $conf_mail, $lang_info, $page;
if (!isset($conf_mail))
{
$conf_mail = get_mail_configuration();
}
- if (is_null($email_format))
+ if (empty($args['email_format']))
{
- $email_format = $conf_mail['default_email_format'];
+ $args['email_format'] = $conf_mail['default_email_format'];
}
- if (($format_infos == 'text/html') and ($email_format == 'text/plain'))
- {
- // Todo find function to convert html text to plain text
- return false;
- }
-
// Compute root_path in order have complete path
- if ($email_format == 'text/html')
+ if ($args['email_format'] == 'text/html')
{
set_make_full_url();
}
$to = format_email('', $to);
- if ($from == '')
+ if (empty($args['from']))
{
- $from = $conf_mail['formated_email_webmaster'];
+ $args['from'] = $conf_mail['formated_email_webmaster'];
}
else
{
- $from = format_email('', $from);
+ $args['from'] = format_email('', $args['from']);
+ }
+
+ if (empty($args['subject']))
+ {
+ $args['subject'] = 'PhpWebGallery';
}
+ $cvt7b_subject = str_translate_to_ascii7bits($args['subject']);
- $headers = 'From: '.$from."\n";
- $headers.= 'Reply-To: '.$from."\n";
- $headers.= 'Content-Type: '.$email_format.';format=flowed;charset="'.$lang_info['charset'].'";';
- $headers.= 'reply-type=original'."\n";
+ if (!isset($args['content']))
+ {
+ $args['content'] = '';
+ }
+
+ if (empty($args['content_format']))
+ {
+ $args['content_format'] = 'text/plain';
+ }
+
+ if (($args['content_format'] == 'text/html') and ($args['email_format'] == 'text/plain'))
+ {
+ // Todo find function to convert html text to plain text
+ return false;
+ }
+
+ $args = array_merge($args, get_array_template_theme($args));
+
+ $headers = 'From: '.$args['from']."\n";
+ $headers.= 'Reply-To: '.$args['from']."\n";
+ $headers.= 'Content-Type: multipart/alternative;'."\n";
+ $headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'."\n";
+ $headers.= ' reply-type=original'."\n";
$headers.= 'MIME-Version: 1.0'."\n";
if ($conf_mail['send_bcc_mail_webmaster'])
@@ -176,11 +244,11 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $for
$content = '';
- if (!isset($conf_mail[$email_format][$lang_info['charset']][$user['template']][$user['theme']]))
+ if (!isset($conf_mail[$args['email_format']][$lang_info['charset']][$args['template']][$args['theme']]))
{
if (!isset($mail_template))
{
- $mail_template = get_mail_template($email_format);
+ $mail_template = get_mail_template($args['email_format']);
}
$mail_template->set_filename('mail_header', 'header.tpl');
@@ -189,7 +257,9 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $for
$mail_template->assign_vars(
array(
//Header
- 'CONTENT_ENCODING' => $lang_info['charset'],
+ 'BOUNDARY_KEY' => $conf_mail['boundary_key'],
+ 'CONTENT_TYPE' => $args['email_format'],
+ 'CONTENT_ENCODING' => $lang_info['charset'],
'LANG' => $lang_info['code'],
'DIR' => $lang_info['direction'],
@@ -207,7 +277,7 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $for
'MAIL' => get_webmaster_mail_address()
));
- if ($email_format == 'text/html')
+ if ($args['email_format'] == 'text/html')
{
$old_root = $mail_template->root;
@@ -217,7 +287,7 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $for
$mail_template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'global_mail_css');
}
- $mail_template->root = PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/'.$user['theme'];
+ $mail_template->root = PHPWG_ROOT_PATH.'template/'.$args['template'].'/theme/'.$args['theme'];
if (is_file($mail_template->root.'/mail-css.tpl'))
{
$mail_template->set_filename('mail_css', 'mail-css.tpl');
@@ -235,37 +305,43 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $for
}
// what are displayed on the header of each mail ?
- $conf_mail[$email_format]
+ $conf_mail[$args['email_format']]
[$lang_info['charset']]
- [$user['template']][$user['theme']]['header'] =
+ [$args['template']][$args['theme']]['header'] =
$mail_template->parse('mail_header', true);
// what are displayed on the footer of each mail ?
- $conf_mail[$email_format]
+ $conf_mail[$args['email_format']]
[$lang_info['charset']]
- [$user['template']][$user['theme']]['footer'] =
+ [$args['template']][$args['theme']]['footer'] =
$mail_template->parse('mail_footer', true);
}
-
- $content.= $conf_mail[$email_format]
+
+ // Header
+ $content.= $conf_mail[$args['email_format']]
[$lang_info['charset']]
- [$user['template']][$user['theme']]['header'];
+ [$args['template']][$args['theme']]['header'];
- if (($format_infos == 'text/plain') and ($email_format == 'text/html'))
+ // Content
+ if (($args['content_format'] == 'text/plain') and ($args['email_format'] == 'text/html'))
{
- $content.= '<pre>'.htmlentities($infos).'</pre>';
+ $content.= '<p>'.nl2br(htmlentities($args['content'])).'</p>';
}
else
{
- $content.= $infos;
+ $content.= $args['content'];
}
-
- $content.= $conf_mail[$email_format]
+
+ // Footer
+ $content.= $conf_mail[$args['email_format']]
[$lang_info['charset']]
- [$user['template']][$user['theme']]['footer'];
-
+ [$args['template']][$args['theme']]['footer'];
+
+ // Close boundary
+ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
+
// Undo Compute root_path in order have complete path
- if ($email_format == 'text/html')
+ if ($args['email_format'] == 'text/html')
{
unset_make_full_url();
}
@@ -275,7 +351,7 @@ function pwg_mail($to, $from = '', $subject = 'PhpWebGallery', $infos = '', $for
global $user;
@mkdir(PHPWG_ROOT_PATH.'testmail');
$filename = PHPWG_ROOT_PATH.'testmail/mail.'.$user['username'];
- if ($format_infos == 'text/plain')
+ if ($args['content_format'] == 'text/plain')
{
$filename .= '.txt';
}
diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php
index 194e715c8..e9bad6f79 100644
--- a/include/picture_comment.inc.php
+++ b/include/picture_comment.inc.php
@@ -223,10 +223,8 @@ if ( $page['show_comments'] and isset( $_POST['content'] ) )
'Validate: '.get_absolute_root_url()
.'comments.php?validate='.$comm['id'];
}
- pwg_mail( get_webmaster_mail_address(), '',
- 'PWG comment by '.$comm['author'],
- $content
- );
+ pwg_mail(get_webmaster_mail_address(),
+ array('subject' => 'PWG comment by '.$comm['author'], 'content' => $content));
}
}
else
diff --git a/password.php b/password.php
index ea470da27..9d3833447 100644
--- a/password.php
+++ b/password.php
@@ -84,7 +84,8 @@ WHERE '
."\n".l10n('Password').': '.$new_password
;
- if (pwg_mail($row['email'], '', l10n('password updated'), $infos))
+ if (pwg_mail($row['email'],
+ array('subject' => l10n('password updated'), 'content' => $infos)))
{
$data =
array(
diff --git a/register.php b/register.php
index 0218119fa..0d42a4795 100644
--- a/register.php
+++ b/register.php
@@ -70,10 +70,13 @@ if (isset($_POST['submit']))
.'Browser: '.$_SERVER['HTTP_USER_AGENT']."\n\n"
.l10n('admin').': '.$admin_url;
- pwg_mail( get_webmaster_mail_address(), '',
- 'PWG '.l10n('register_title').' '.$username,
- $content
- );
+ pwg_mail(get_webmaster_mail_address(),
+ array
+ (
+ 'subject' => 'PWG '.l10n('register_title').' '.$username,
+ 'content' => $content
+ )
+ );
}
redirect(make_index_url());
}
diff --git a/template/yoga/mail/text/html/header.tpl b/template/yoga/mail/text/html/header.tpl
index 20d3a9780..8ac637793 100644
--- a/template/yoga/mail/text/html/header.tpl
+++ b/template/yoga/mail/text/html/header.tpl
@@ -1,5 +1,8 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
+-----={BOUNDARY_KEY}
+Content-Type: {CONTENT_TYPE}; charset={CONTENT_ENCODING};
+Content-Transfer-Encoding: 8bit
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="{LANG}" dir="{DIR}">
<head>
<title>PhpWebGallery Mail</title>
diff --git a/template/yoga/mail/text/plain/header.tpl b/template/yoga/mail/text/plain/header.tpl
index fec68b422..d409439bc 100644
--- a/template/yoga/mail/text/plain/header.tpl
+++ b/template/yoga/mail/text/plain/header.tpl
@@ -1 +1,3 @@
-{FAKE_SIMULATE_EMPTY_FILE} \ No newline at end of file
+-----={BOUNDARY_KEY}
+Content-Type: {CONTENT_TYPE}; charset={CONTENT_ENCODING}; format=flowed;
+Content-Transfer-Encoding: 8bit