drewr / postal

Clojure email support
MIT License
587 stars 85 forks source link

NullPointerException when no file name in attachment #75

Open arichiardi opened 8 years ago

arichiardi commented 8 years ago

Dear Drew, I am using successfully your library for building an email and I found out today while creating

{:type :attachment
 :content-type (email-impl/guess-mime "http://lorempixel.com/400/200/" "image/jpeg")
 :content (io/as-url "http://lorempixel.com/400/200/")}

Throws a NPE:

java.lang.NullPointerException
    at javax.mail.internet.MimeUtility.quote(MimeUtility.java:927) ~[mailapi-1.4.3.jar:1.4.3]
    at javax.mail.internet.ParameterList.quote(ParameterList.java:649) ~[mailapi-1.4.3.jar:1.4.3]
    at javax.mail.internet.ParameterList.access$200(ParameterList.java:71) ~[mailapi-1.4.3.jar:1.4.3]
    at javax.mail.internet.ParameterList$ToStringBuffer.addNV(ParameterList.java:617) ~[mailapi-1.4.3.jar:1.4.3]
    at javax.mail.internet.ParameterList.toString(ParameterList.java:598) ~[mailapi-1.4.3.jar:1.4.3]
    at javax.mail.internet.ContentDisposition.toString(ContentDisposition.java:185) ~[mailapi-1.4.3.jar:1.4.3]
    at javax.mail.internet.MimeBodyPart.setFileName(MimeBodyPart.java:1161) ~[mailapi-1.4.3.jar:1.4.3]
    at javax.mail.internet.MimeBodyPart.setFileName(MimeBodyPart.java:531) ~[mailapi-1.4.3.jar:1.4.3]
    at postal.message$eval_bodypart.invokeStatic(message.clj:108) ~[?:?]
    at postal.message$eval_bodypart.invoke(message.clj:104) ~[?:?]
    at postal.message$eval54499$fn__54500.invoke(message.clj:98) ~[?:?]
    at postal.message$eval54482$fn__54483$G__54473__54488.invoke(message.clj:94) ~[?:?]
    at postal.message$eval_multipart.invokeStatic(message.clj:137) ~[?:?]
    at postal.message$eval_multipart.invoke(message.clj:127) ~[?:?]
    at postal.message$add_multipart_BANG_.invokeStatic(message.clj:141) ~[?:?]
    at postal.message$add_multipart_BANG_.invoke(message.clj:140) ~[?:?]
    at postal.message$add_body_BANG_.invokeStatic(message.clj:151) ~[?:?]
    at postal.message$add_body_BANG_.invoke(message.clj:148) ~[?:?]
    at postal.message$make_jmessage.invokeStatic(message.clj:177) ~[?:?]
    at postal.message$make_jmessage.invoke(message.clj:157) ~[?:?]
    at postal.message$make_jmessage.invokeStatic(message.clj:166) ~[?:?]
    at postal.message$make_jmessage.invoke(message.clj:157) ~[?:?]

I check the source and it fails here because re-find returns nil. Probably a simple dummy file name would avoid this issue right?

Thanks!

drewr commented 8 years ago

This is definitely some lame code. We need to decide what to do with paths that don't really have a "filename." I'd like to either use (:file-name part) or a UUID. See proposed patch 👇 .

arichiardi commented 8 years ago

Yes that looks great! :smile: If it is up somewhere I will try asap