gwynne                                   Tue, 01 Dec 2009 04:29:13 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=291534

Log:
1) sanitize Subject and From headers more thorughly, 2) calculate large email 
sizes more correctly

Changed paths:
    U   SVNROOT/commit-email.php

Modified: SVNROOT/commit-email.php
===================================================================
--- SVNROOT/commit-email.php    2009-12-01 02:05:28 UTC (rev 291533)
+++ SVNROOT/commit-email.php    2009-12-01 04:29:13 UTC (rev 291534)
@@ -162,18 +162,37 @@
 }

 // 
-----------------------------------------------------------------------------------------------------------------------------
+// Safely utf-8-ize an email header with the short version of quoted-printable
+function utf8_safe_header($header_value)
+{
+    // As per experience and 
http://www.php.net/manual/en/function.imap-8bit.php#75081
+    // 1 - Limit string to 900 chars, giving some slop for the replacements 
and extensions
+    // 2 - imap_8bit() the string
+    // 3 - Replace =\r\n with nothing, _ with =5F, and ? with =3F
+    // 6 - Replace <space> with _
+    // 7 - Surround with =?utf-8?q??=
+    return '=?utf-8?q?' . str_replace(' ', '_', str_replace(array('_', 
"=\r\n", '?'), array('=5F', '', '=3F'),
+        imap_8bit(substr($header_value, 0, 900)))) . '?=';
+}
+
+// 
-----------------------------------------------------------------------------------------------------------------------------
 // Build e-mail
 $boundary = sha1("{$commit_info['author']}{$commit_info['date']}");
 $messageid = "{$commit_info['author']}-{$commit_info['date']}-{$REV}-" . 
mt_rand();
-$subject = substr("svn: {$paths_list}", 0, 970); // Max SMTP line length = 
998. Some slop in this value.
+$subject = utf8_safe_header("svn: {$paths_list}");
 $email_date = date(DATE_RFC2822, $commit_info['date']);
-$fullname = "=?utf-8?q?" . imap_8bit(str_replace(array('?', ' '), array('=3F', 
'_'), $commit_info['author_name'])) . "?=";
+$fullname = utf8_safe_header($commit_info['author_name']);
 $email_list = implode(', ', $emails_to);
 $readable_path_list = "    " . implode(PHP_EOL . "    ", 
$commit_info['raw_changed_paths']);
 $nspaces = str_repeat(" ", max(1, 72 - strlen($commit_info['author']) - 
strlen($email_date)));

-// Help ensure all commits make it to the mailing lists, which have size 
restrictions
-if ((strlen($readable_path_list) + $diffs_length) > 262144) {
+// Help ensure all commits make it to the mailing lists, which have size 
restrictions.
+// Add the path list length to: 1) the diff string length (which will be zero 
if diffs ARE attached), and
+//  2) the diff data length (which will be zero if diffs are NOT attached).
+// If the total is larger than 256K, don't include the path list. If it still 
goes over the limit even after that,
+//  the email is gonna be too big to send no matter what we do.
+$diff_data = $diffs_string === NULL ? 
wordwrap(base64_encode($commit_info['diffs']), 80, PHP_EOL, TRUE) : '';
+if ((strlen($readable_path_list) + strlen($diffs_string) + strlen($diff_data)) 
> 262144) {
     $readable_path_list = '<changed paths exceeded maximum size>';
 }

@@ -205,7 +224,6 @@
 MIMEBODY;

 if ($diffs_string === NULL) {
-    $diff_data = wordwrap(base64_encode($commit_info['diffs']), 80, PHP_EOL, 
TRUE);
     $msg_body .= <<<MIMEBODY

 Content-Type: text/x-diff; charset="utf-8"

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to