drewr / postal

Clojure email support
MIT License
587 stars 85 forks source link

Postal doesn't correctly support RFC6531 email addresses #51

Open sfnelson opened 10 years ago

sfnelson commented 10 years ago

RFC6531 email addresses still don't work in postal, #27 only addressed sender names and not email addresses.

(defn make-address
  ([^String addr ^String charset]
     (let [a (try (InternetAddress. addr)
                  (catch Exception _))]
       (if a
         (InternetAddress. (.getAddress a)
                           (.getPersonal a)
                           charset))))
  ([^String addr ^String name-str ^String charset]
     (try (InternetAddress. addr name-str charset)
          (catch Exception _))))

The three argument version of this code is not called by any postal code afaict, and the two argument version returns nil when given non-ascii characters as input, e.g.

(make-address "Tést <test@example.com>" "utf-8") ;; good
=> #<InternetAddress =?utf-8?Q?T=C3=A9st?= <test@example.com>>
(make-address "tést@example.com" "utf-8") ;; bad
=> nil
(make-address "tést@example.com" "Tést" "utf-8") ;; good, but never called
=> #<InternetAddress =?utf-8?Q?T=C3=A9st?= <tést@example.com>>
drewr commented 10 years ago

This appears to be a limitation in JavaMail's InternetAddress parser. 1.5.0-b1 behaves the same way.

postal.message> (.getAddress (InternetAddress. "pépé@example.com" "pépé"))
"pépé@example.com"
postal.message> (.getPersonal (InternetAddress. "Pépé <pépé@example.com>"))
AddressException Local address contains control or whitespace  javax.mail.internet.InternetAddress.checkAddress (InternetAddress.java:1213)

Bill Shannon has responded to this issue and thinks RFC6531 support in JavaMail would be premature anyway because not many servers yet support it. That was almost a year ago though.

https://kenai.com/bugzilla/show_bug.cgi?id=6216

gws commented 7 years ago

We're encountering this issue, but it looks like there's been some recent movement in JavaMail and times have indeed changed - JavaMail 1.6.0 (in RC now, slated for a summer 2017 release) now supports RFC 653[0-2]: https://github.com/javaee/javamail/issues/93#issuecomment-298527783

I'm not familiar enough with postal to submit a PR today (and it may not be workable to depend on a release candidate of JavaMail), but let me know if it would help you out to create a PR for this.

Thank you!

drewr commented 3 years ago

These cases work now with Jakarta Mail (née JavaMail) 1.6.5:

postal.message> (.getPersonal (InternetAddress. "Pépé <pépé@example.com>"))
"Pépé"
postal.message> (make-address "tést@example.com" "Tést" "utf-8")
#object[javax.mail.internet.InternetAddress 0x353d19a4 "=?utf-8?Q?T=C3=A9st?= <tést@example.com>"]
postal.message> (make-address "tést@example.com" "utf-8")
#object[javax.mail.internet.InternetAddress 0x1a8ff709 "tést@example.com"]
postal.message> (make-address "Tést <test@example.com>" "utf-8")
#object[javax.mail.internet.InternetAddress 0x3671fd8a "=?utf-8?Q?T=C3=A9st?= <test@example.com>"]

Think we can close it?