postal icon indicating copy to clipboard operation
postal copied to clipboard

Postal doesn't correctly support RFC6531 email addresses

Open sfnelson opened this issue 10 years ago • 3 comments

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 <[email protected]>" "utf-8") ;; good
=> #<InternetAddress =?utf-8?Q?T=C3=A9st?= <[email protected]>>
(make-address "té[email protected]" "utf-8") ;; bad
=> nil
(make-address "té[email protected]" "Tést" "utf-8") ;; good, but never called
=> #<InternetAddress =?utf-8?Q?T=C3=A9st?= <té[email protected]>>

sfnelson avatar Sep 11 '14 19:09 sfnelson

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

drewr avatar Oct 28 '14 14:10 drewr

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!

gws avatar May 09 '17 15:05 gws

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é[email protected]" "Tést" "utf-8")
#object[javax.mail.internet.InternetAddress 0x353d19a4 "=?utf-8?Q?T=C3=A9st?= <té[email protected]>"]
postal.message> (make-address "té[email protected]" "utf-8")
#object[javax.mail.internet.InternetAddress 0x1a8ff709 "té[email protected]"]
postal.message> (make-address "Tést <[email protected]>" "utf-8")
#object[javax.mail.internet.InternetAddress 0x3671fd8a "=?utf-8?Q?T=C3=A9st?= <[email protected]>"]

Think we can close it?

drewr avatar Nov 16 '20 21:11 drewr