gwynne          Mon, 13 Jul 2009 23:40:16 +0000

ViewVC URL: http://svn.php.net/viewvc?view=revision&revision=284032

Changed paths:
        U   SVNROOT/commit-email.php

Log:
make use of Mail_MIME to correctly encode email, deal with ISO-8859-1/UTF-8
inconsistencies in users.db with an ugly hack, other small tweaks

Modified: SVNROOT/commit-email.php
===================================================================
--- SVNROOT/commit-email.php    2009-07-13 22:30:37 UTC (rev 284031)
+++ SVNROOT/commit-email.php    2009-07-13 23:40:16 UTC (rev 284032)
@@ -111,13 +111,24 @@
 // Determine "from" address
 // Various repositories can play with this to read from their equivelant of 
the old cvsusers folder, or whatever else they like
 $usersDB = file(dirname(__FILE__) . '/users.db');
+$from = NULL;
+$saw_last_ISO = FALSE;
 foreach ($usersDB as $userline) {
     list ($username, $fullname, $email) = explode(":", trim($userline));
-    if ($username == $commit_user) {
-        $from = imap_8bit("\"{$fullname}\" <{$userna...@php.net>");
+    if ($username === 'ladderalice') {
+        $saw_last_ISO = TRUE;
+    }
+    if ($username === $commit_user) {
+        if (!$saw_last_ISO) {
+            $fullname = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $fullname);
+        }
+        $from = "\"{$fullname}\" <{$userna...@php.net>";
         break;
     }
 }
+if (is_null($from)) {
+    die("Couldn't find user\n");
+}

 // 
-----------------------------------------------------------------------------------------------------------------------------
 // Build list of e-mail addresses and parent changed path
@@ -148,17 +159,16 @@

 // 
-----------------------------------------------------------------------------------------------------------------------------
 // Build e-mail
-$subject = "svn: {$parent_path}";
+$old_er = error_reporting(E_ERROR | E_WARNING); // Because it's PEAR code and 
thus throws E_STRICT and E_DEPRECATED all over the place, sigh
+require 'Mail/mime.php';

-$msg_headers = "From: {$from}\n" .
-               "To: " . implode(', ', $emails_to) . "\n" .
-               "Message-ID: <svn{$commit_user}{$commit_da...@svn.php.net>\n" .
-               "Date: " . date(DATE_RFC822, $commit_date) . "\n" .
-               "Subject: {$subject}\n";
+$mime_email = new Mail_mime("\r\n");
+$mime_email->setFrom($from);
+$mime_email->setSubject("svn: {$parent_path}");

 $msg_body = "{$commit_user}\t\t" . date(DATE_RFC2822, $commit_date) . "\n" .
             "\n" .
-            "ViewVC URL: 
http://svn.php.net/viewvc?view=revision&revision={$REV}\n"; .
+            "URL: http://svn.php.net/viewvc?view=revision&revision={$REV}\n"; .
             "\n" .
             "Changed paths:\n" .
             "\t" . implode("\n\t", $changed_paths) . "\n" .
@@ -166,30 +176,30 @@
             "Log:\n" .
             wordwrap($commit_log, 80, "\n") . "\n" .
             "\n";
-
-if (strlen($diffs) >= (96 * 1024)) {
-   $msg_body .= "<diffs exceeded maximum size>\n";
-} else if (strlen($diffs) >= 8192) {
-    $boundary = $commit_user. $commit_date;
-    $msg_headers .= "MIME-Version: 1.0\n" .
-                    "Content-Type: multipart/mixed; 
boundary=\"{$boundary}\"\n";
-    $msg_body = "This is a MIME encoded message.\n\n--{$boundary}\n" .
-                "Content-Type: text/plain\n" .
-                "\n" .
-                "{$msg_body}\n" .
-                "--{$boundary}\n" .
-                "Content-Type: text/plain\n" .
-                "Content-Disposition: attachment; 
filename=\"{$boundary}.txt\"\n" .
-                "\n" .
-                "{$diffs}\n" .
-                "--{$boundary}--\n";
+if (strlen($diffs) >= (256 * 1024)) {
+    $msg_body .= "<diffs exceeded maximum size>\n";
+} else if (strlen($diffs) > 8192) {
+    $mime_email->addAttachment($diffs, "text/x-diff",
+        "{$commit_user}{$commit_date}.txt", FALSE, "base64", "attachment",
+        "utf-8");
 } else {
     $msg_body .= $diffs;
 }
+$mime_email->setTXTBody($msg_body, FALSE, FALSE);

-$complete_email = $msg_headers . "\n" . $msg_body;
-$complete_email = str_replace(array("\r", "\n", "\r\n."), array("", "\r\n", 
".."), $complete_email);
+$complete_email = $mime_email->getMessage(NULL, array(
+        'head_encoding' => 'quoted-printable',
+        'text_encoding' => 'quoted-printable',
+        'text_charset' => 'utf-8',
+        'head_charset' => 'utf-8'
+    ), array(
+        'To' => implode(', ', $emails_to),
+        'Message-ID' => "<svn{$commit_user}{$commit_da...@svn.php.net>",
+        'Date' => date(DATE_RFC2822, $commit_date)
+    ), TRUE);

+error_reporting($old_er);
+
 // 
-----------------------------------------------------------------------------------------------------------------------------
 // Send e-mail
 if (isset($_ENV['DEBUG']) && $_ENV['DEBUG'] == 'DEBUG') {
@@ -213,7 +223,9 @@
     ".\r\n" .
     "QUIT\r\n");

-$discard = stream_get_contents($socket);
+if (!isset($_ENV['DEBUG']) || $_ENV['DEBUG'] != 'DEBUG') {
+    $discard = stream_get_contents($socket);
+}
 fclose($socket);

 ?>


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

Reply via email to