diff options
-rw-r--r-- | email/email.scm | 9 | ||||
-rw-r--r-- | tests/email.scm | 15 |
2 files changed, 23 insertions, 1 deletions
diff --git a/email/email.scm b/email/email.scm index 2c4178e..f276019 100644 --- a/email/email.scm +++ b/email/email.scm @@ -605,7 +605,14 @@ values. The returned headers is a string and body is a bytevector." (call-with-port (open-bytevector-input-port email) (lambda (port) - (set-port-encoding! port "us-ascii") + ;; Email headers must strictly be ASCII characters. But for the + ;; sake of supporting Emacs message mode parens style addresses + ;; that may use non-ASCII characters, typically for the full + ;; name, we relax this requirement. We assume an encoding of + ;; UTF-8, and hope that everything turns out fine. Since UTF-8 + ;; is a superset of ASCII, this should not affect standards + ;; conforming headers. + (set-port-encoding! port "utf-8") (let ((headers (read-while port get-line-with-delimiter (lambda (line) (not (or (string= line "\n") diff --git a/tests/email.scm b/tests/email.scm index 530cb8b..8aa9082 100644 --- a/tests/email.scm +++ b/tests/email.scm @@ -282,6 +282,21 @@ foo foo " "utf-8"))) +(test-equal "tolerate non-ascii characters in headers" + (parse-email + (string->bytevector + "From: foo@bar.org (Foo Bãr) + +body" "utf-8")) + (make-email + `((content-type (type . text) + (subtype . plain) + (charset . "utf-8")) + (content-transfer-encoding . 7bit) + (from ((name . "Foo Bãr") + (address . "foo@bar.org")))) + "body")) + (test-equal "parse name-addr email address" (parse-email-address "Foo <foo@example.org>") '((name . "Foo") (address . "foo@example.org"))) |