drewr / postal

Clojure email support
MIT License
587 stars 85 forks source link

UTF-8 doesn't work for recipients #27

Closed pbiggar closed 11 years ago

pbiggar commented 12 years ago

postal acts like these two are the same thing, but they are not. As a result, I'm not able to send emails with the recipient's name in the To field, if the recipient has weird characters in their name.

circle.init=> (InternetAddress. "íč <p@p.com>")
#<InternetAddress "íč" <p@p.com>>

circle.init=> (InternetAddress. "p@p.com" "íč")
#<InternetAddress =?MacRoman?B?w63EjQ==?= <p@p.com>>
michaelklishin commented 12 years ago

You have MacRoman as encoding. Pass -Dfile.encoding=UTF-8 to the JVM (this is what Leiningen 2 automatically does, for example, starting with Preview 5 or so).

pbiggar commented 12 years ago

Thanks Michael. That changes the symptoms, but doesn't solve the problem:

circle.init=> (InternetAddress. "íč <p@p.com>")
#<InternetAddress "íč" <p@p.com>>

circle.init=> (InternetAddress. "p@p.com" "íč")
#<InternetAddress =?UTF-8?B?w63EjQ==?= <p@p.com>>

To elaborate, postal calls InternetAddress with only one argument, which means there is no way to get the second behaviour. This is causing my emails to encode incorrectly.

michaelklishin commented 12 years ago

As far as I can see in the javadoc for javax.mail, the charset parameter is in the 3-arity constructor.

But now it does sound like an issue in Postal.

drewr commented 12 years ago

Thanks for the report Paul. Please change your version to 1.9-SNAPSHOT and see if your issue is resolved. If so I'll make a new release.

scramjet commented 11 years ago

I've just run into this issue also, for non-ASCII characters in the sender's name.

It appears that commit 148beef hasn't made it into a release? Any chance of resurrecting it? Happy to test it out.

drewr commented 11 years ago

Sorry for dropping this! I should have released this anyway and just fixed whatever problems were lingering. It's in 1.11.0.

sfnelson commented 10 years ago

RFC6531 email addresses still don't work in postal after this change.

(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

@sfnelson Responded over on #51