diff options
author | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-04-21 14:13:10 +0000 |
---|---|---|
committer | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-04-21 14:13:10 +0000 |
commit | 786c8c2a06233e4b9c31678c44aa5bfec79cf8a2 (patch) | |
tree | 90d9de44cbb03e0df56202e9bf26ffb2a2141027 | |
parent | 5107b7aafa77fab8533c794ab41d54e5efc8e9b7 (diff) | |
download | forums-786c8c2a06233e4b9c31678c44aa5bfec79cf8a2.tar forums-786c8c2a06233e4b9c31678c44aa5bfec79cf8a2.tar.gz forums-786c8c2a06233e4b9c31678c44aa5bfec79cf8a2.tar.bz2 forums-786c8c2a06233e4b9c31678c44aa5bfec79cf8a2.tar.xz forums-786c8c2a06233e4b9c31678c44aa5bfec79cf8a2.zip |
Altered various aspects of emailing ... tested on a windows platform with both mail() and direct smtp ... it worked in both cases.
git-svn-id: file:///svn/phpbb/trunk@3902 89ea8834-ac86-4346-8a33-228a782c2dd0
-rwxr-xr-x | phpBB/includes/emailer.php | 129 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 39 |
2 files changed, 100 insertions, 68 deletions
diff --git a/phpBB/includes/emailer.php b/phpBB/includes/emailer.php index ea55a2ac90..1934224648 100755 --- a/phpBB/includes/emailer.php +++ b/phpBB/includes/emailer.php @@ -21,7 +21,9 @@ class emailer { - var $msg, $subject, $extra_headers, $address; + var $msg, $subject, $extra_headers; + var $to_addres, $cc_address, $bcc_address; + var $tpl_msg = array(); function emailer() @@ -32,56 +34,50 @@ class emailer // Resets all the data (address, template file, etc etc to default function reset() { - $this->address = ''; - $this->msg = ''; - $this->vars = ''; + $this->addresses = array(); + $this->vars = $this->msg = $this->extra_headers = $this->replyto = ''; } // Sets an email address to send to - function email_address($address, $lang_var = '', $template_lang = '') + function to($address, $realname = '') { - global $config, $phpbb_root_path, $phpEx; - - $this->address = ''; - - // If a language variable for non-disclosure is passed, we prepend it to the address. - if ($lang_var != '') - { - if ($template_lang == '') - { - $template_lang = $config['default_lang']; - } + $pos = sizeof($this->addresses['to']); + $this->addresses['to'][$pos]['email'] = trim($address); + $this->addresses['to'][$pos]['name'] = trim($realname); + } - $language_file = $phpbb_root_path . 'language/' . $template_lang . '/lang_main.' . $phpEx; + function cc($address, $realname = '') + { + $pos = sizeof($this->addresses['cc']); + $this->addresses['cc'][$pos]['email'] = trim($address); + $this->addresses['cc'][$pos]['name'] = trim($realname); + } - if (!@file_exists($language_file)) - { - $language_file = $phpbb_root_path . 'language/' . $config['default_lang'] . '/lang_main.' . $phpEx; - } - - if (@file_exists($language_file)) - { - include($language_file); - $this->address .= $lang[$lang_var]; - } - } + function bcc($address, $realname = '') + { + $pos = sizeof($this->addresses['bcc']); + $this->addresses['bcc'][$pos]['email'] = trim($address); + $this->addresses['bcc'][$pos]['name'] = trim($realname); + } - $this->address .= $address; + function replyto($address) + { + $this->replyto = trim($address); } // set up subject for mail - function set_subject($subject = '') + function subject($subject = '') { - $this->subject = $subject; + $this->subject = trim($subject); } // set up extra mail headers - function extra_headers($headers) + function headers($headers) { - $this->extra_headers = $headers; + $this->extra_headers .= trim($headers) . "\r\n"; } - function use_template($template_file, $template_lang = '') + function template($template_file, $template_lang = '') { global $config, $phpbb_root_path; @@ -186,23 +182,61 @@ class emailer $this->msg = trim(preg_replace('#' . $drop_header . '#s', '', $this->msg)); } - // Split up message into 76 chars as per RFC2045 -// $this->msg = chunk_split($this->msg); + $to = $cc = $bcc = ''; + // Build to, cc and bcc strings + foreach ($this->addresses as $type => $address_ary) + { + foreach ($address_ary as $which_ary) + { + $$type .= (($$type != '') ? ',' : '') . (($which_ary['name'] != '') ? '"' . $this->encode($which_ary['name']) . '" <' . $which_ary['email'] . '>' : '<' . $which_ary['email'] . '>'); + } + } // Build header - $this->extra_headers = "From: " . $config['board_email'] . "\nReturn-Path: " . $config['board_email'] . "\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 7bit\nDate: " . gmdate('D, d M Y H:i:s', time()) . " UT\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\n" . trim($this->extra_headers); + $this->extra_headers = (($this->replyto !='') ? "Reply-to: <$this->replyto>\r\n" : '') . "From: <" . $config['board_email'] . ">\r\nReturn-Path: <" . $config['board_email'] . ">\r\nMessage-ID: <" . md5(uniqid(time())) . "@" . $config['server_name'] . ">\r\nMIME-Version: 1.0\r\nContent-type: text/plain; charset=" . $this->encoding . "\r\nContent-transfer-encoding: 8bit\r\nDate: " . gmdate('D, d M Y H:i:s Z', time()) . "\r\nX-Priority: 3\r\nX-MSMail-Priority: Normal\r\nX-Mailer: PHP\r\n" . (($cc != '') ? "Cc:$cc\r\n" : '') . (($bcc != '') ? "Bcc:$bcc\r\n" : '') . trim($this->extra_headers); - // Send message - $result = ($config['smtp_delivery']) ? smtpmail($this->address, $this->subject, $this->msg, $this->extra_headers) : @mail($this->address, $this->subject, $this->msg, $this->extra_headers); + // Send message ... removed $this->encode() from subject for time being + $result = ($config['smtp_delivery']) ? smtpmail($to, $this->subject, $this->msg, $this->extra_headers) : mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\r\n", $this->msg), $this->extra_headers); + // Did it work? if (!$result) { $message = '<u>EMAIL ERROR</u> [ ' . (($config['smtp_delivery']) ? 'SMTP' : 'PHP') . ' ]<br /><br />' . $result . '<br /><br /><u>CALLING PAGE</u><br /><br />' . ((!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']) . '<br />'; trigger_error($message, E_USER_ERROR); } - + return true; } + + // Encodes the given string for proper display for this encoding ... nabbed + // from php.net and modified. There is an alternative encoding method which + // may produce lesd output but it's questionable as to its worth in this + // scenario IMO + function encode($str) + { + if ($this->encoding == '') + { + return $str; + } + + // define start delimimter, end delimiter and spacer + $end = "?="; + $start = "=?$this->encoding?B?"; + $spacer = "$end\r\n $start"; + + // determine length of encoded text within chunks and ensure length is even + $length = 75 - strlen($start) - strlen($end); + $length = floor($length / 2) * 2; + + // encode the string and split it into chunks with spacers after each chunk + $str = chunk_split(base64_encode($str), $length, $spacer); + + // remove trailing spacer and add start and end delimiters + $str = preg_replace('#' . preg_quote($spacer) . '$#', '', $str); + + return $start . $str . $end; + } + } // class emailer // This function has been modified as provided by SirSir to allow multiline responses when @@ -262,7 +296,7 @@ function smtpmail($mail_to, $subject, $message, $headers = '') { $cc = preg_replace('#^cc:(.*)#si', '\1', $header); } - else if (preg_match('#^bcc:/si', $header)) + else if (preg_match('#^bcc:#si', $header)) { $bcc = preg_replace('#^bcc:(.*)#si', '\1', $header); $header = ''; @@ -325,7 +359,6 @@ function smtpmail($mail_to, $subject, $message, $headers = '') server_parse($socket, "250"); // Specify each user to send to and build to header. - $to_header = "To: "; @reset($mail_to_array); while(list(, $mail_to_address) = each($mail_to_array)) { @@ -333,12 +366,11 @@ function smtpmail($mail_to, $subject, $message, $headers = '') $mail_to_address = trim($mail_to_address); if (preg_match('#[^ ]+\@[^ ]+#', $mail_to_address)) { - fputs($socket, "RCPT TO: <$mail_to_address>\r\n"); + fputs($socket, "RCPT TO: $mail_to_address\r\n"); server_parse($socket, "250"); } - $to_header .= "<$mail_to_address>, "; + $to_header .= (($to_header !='') ? ', ' : '') . "$mail_to_address"; } - // Ok now do the CC and BCC fields... @reset($bcc); while(list(, $bcc_address) = each($bcc)) @@ -347,7 +379,7 @@ function smtpmail($mail_to, $subject, $message, $headers = '') $bcc_address = trim($bcc_address); if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address)) { - fputs($socket, "RCPT TO: <$bcc_address>\r\n"); + fputs($socket, "RCPT TO: $bcc_address\r\n"); server_parse($socket, "250"); } } @@ -359,7 +391,7 @@ function smtpmail($mail_to, $subject, $message, $headers = '') $cc_address = trim($cc_address); if (preg_match('#[^ ]+\@[^ ]+#', $cc_address)) { - fputs($socket, "RCPT TO: <$cc_address>\r\n"); + fputs($socket, "RCPT TO: $cc_address\r\n"); server_parse($socket, "250"); } } @@ -374,7 +406,8 @@ function smtpmail($mail_to, $subject, $message, $headers = '') fputs($socket, "Subject: $subject\r\n"); // Now the To Header. - fputs($socket, "$to_header\r\n"); + $to_header = ($to_header == '') ? "<Undisclosed-recipients:;>" : $to_header; + fputs($socket, "To: $to_header\r\n"); // Now any custom headers.... fputs($socket, "$headers\r\n\r\n"); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index efd0098471..225b286b51 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -90,7 +90,7 @@ function generate_smilies($mode) // DECODE TEXT -> This will/should be handled by bbcode.php eventually function decode_text(&$message, $bbcode_uid) { - global $config, $censors; + global $config; $server_protocol = ($config['cookie_secure']) ? 'https://' : 'http://'; $server_port = ($config['server_port'] <> 80) ? ':' . trim($config['server_port']) . '/' : '/'; @@ -108,17 +108,11 @@ function decode_text(&$message, $bbcode_uid) '\1', '\1', '\1', - $server_protocol . trim($config['server_name']) . $server_port . preg_replace('/^\/?(.*?)(\/)?$/', '\1', trim($config['script_path'])) . '/\1', + $server_protocol . trim($config['server_name']) . $server_port . preg_replace('#^\/?(.*?)(\/)?$#', '\1', trim($config['script_path'])) . '/\1', '\1', '' ); - if (empty($censors)) - { - $censors = array(); - obtain_word_list($censors); - } - $message = str_replace(":$bbcode_uid", '', $message); $message = str_replace('<br />', "\n", $message); $message = preg_replace($match, $replace, $message); @@ -1270,12 +1264,12 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id) { if ($topic_notification) { - $topic_title = decode_text($row['topic_title']); - $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $topic_title) : $topic_title; + decode_text($row['topic_title']); + $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $row['topic_title']) : $row['topic_title']; } else { - $subject = decode_text($subject); + decode_text($subject); $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $subject) : $subject; } @@ -1311,8 +1305,7 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id) if ($row = $db->sql_fetchrow($result)) { - $topic_title = decode_text($row['topic_title']); - $topic_title = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $topic_title) : $topic_title; + $forum_name = $row['forum_name']; do { @@ -1342,8 +1335,10 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id) $bcc_list_ary = array(); foreach ($email_users as $row) - { - $bcc_list_ary[$row['email_template']][$row['user_lang']] .= (($bcc_list != '') ? ', ' : '') . $row['user_email']; + { + $pos = sizeof($bcc_list_ary[$row['email_template']][$row['user_lang']]); + $bcc_list_ary[$row['email_template']][$row['user_lang']][$pos]['email'] = $row['user_email']; + $bcc_list_ary[$row['email_template']][$row['user_lang']][$pos]['name'] = $row['username']; } unset($email_users); @@ -1351,15 +1346,19 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id) { foreach ($bcc_list as $lang => $bcc) { - $emailer->use_template($email_template, $lang); - $emailer->email_address(':;'); - $emailer->extra_headers($email_headers . "Bcc: $bcc\n"); + $emailer->template($email_template, $lang); + + $emailer->replyto($config['board_email']); + foreach ($bcc as $addr) + { + $emailer->bcc($addr['email'], $addr['name']); + } $emailer->assign_vars(array( 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'SITENAME' => $config['sitename'], - 'TOPIC_TITLE' => $topic_title, - 'FORUM_NAME' => $row['forum_name'], + 'TOPIC_TITLE' => trim($topic_title), + 'FORUM_NAME' => trim($forum_name), 'U_TOPIC' => generate_board_url() . 'viewtopic.'.$phpEx . '?t=' . $topic_id . '&p=' . $post_id . '#' . $post_id, 'U_FORUM' => generate_board_url() . 'viewforum.'.$phpEx . '?f=' . $forum_id, |