summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/build_email.php21
-rw-r--r--test/build_email_test.php21
2 files changed, 41 insertions, 1 deletions
diff --git a/src/build_email.php b/src/build_email.php
index 5301106..41344ca 100644
--- a/src/build_email.php
+++ b/src/build_email.php
@@ -78,10 +78,29 @@ function build_body(array &$headers, $text, $attachments, $footer) {
return $body;
}
+function build_from($name, $email) {
+ $qname = '';
+
+ if (is_ascii($name)) {
+ if (has_rfc822_specials($name)) {
+ $qname = rfc822_quote($name);
+ }
+ else {
+ $qname = $name;
+ }
+ }
+ else {
+ // base64-encode if we have non-ASCII chars
+ $qname = utf8_quote($name);
+ }
+
+ return sprintf('%s <%s>', $qname, $email);
+}
+
function build_headers($userName, $userEmail, $to, $sender, $subject, $edit,
$time, $messageId, $forumURL, $inReplyTo, $references) {
- $from = sprintf('%s <%s>', utf8_quote_non_ascii($userName), $userEmail);
+ $from = build_from($userName, $userEmail);
$subject = utf8_quote_non_ascii($subject);
$date = date(DATE_RFC2822, $time);
diff --git a/test/build_email_test.php b/test/build_email_test.php
index c78ab7b..225e30f 100644
--- a/test/build_email_test.php
+++ b/test/build_email_test.php
@@ -32,6 +32,27 @@ http://www.example.com/viewtopic.php?p=42#p42",
);
}
+ public function test_build_from_nonascii() {
+ $this->assertEquals(
+ '=?UTF-8?B?SGVpesO2bHLDvGNrc3Rvw59hYmTDpG1wZnVuZw==?= <foo@example.com>';
+ build_from('Heizölrückstoßabdämpfung', 'foo@example.com')
+ );
+ }
+
+ public function test_build_from_ascii() {
+ $this->assertEquals(
+ 'Joel Uckelman <uckelman@nomic.net>',
+ build_from('Joel Uckelman', 'uckelman@nomic.net')
+ );
+ }
+
+ public function test_build_from_rfc822_specials() {
+ $this->assertEquals(
+ '"L.Tankersley" <leland53@comcast.net>',
+ build_from('L.Tankersley', 'leland53@comcast.net')
+ );
+ }
+
protected $default_headers = array(
'To' => 'messages@vassalengine.org',
'From' => 'Joel Uckelman <uckelman@nomic.net>',