bbottema / outlook-message-parser

A Java parser for Outlook messages (.msg files)
76 stars 35 forks source link

getFromEmailFromHeaders cannot handle "quoted-name-with@at-sign" #43

Closed basinilya closed 3 years ago

basinilya commented 3 years ago

Even though Sender Name and Email addresse are stored in the fields 0xc1f and 0x42 respectively, the parser extracts and overwrites this info from the transport headers 0x7d.

If such a header contains quoted name with an @ at sign:

From: "bogus@domain.com" <bogus@domain.com>

it wrongly calls setFromEmail("\"bogus@domain.com\"", true)

When trying to use this e-mail with javax.mail it fails:

Caused by: javax.mail.internet.AddressException: Missing final '@domain' in string ``"bogus@domain.com"''
    at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1279)

Please consider reusing or copying new javax.mail.internet.InternetHeaders(InputStream) for splitting the headers and new javax.mail.internet.InternetAddress(String) for parsing the address string.

bbottema commented 3 years ago

It seems you have a better grasp of the internal Outlook model than I have. Would you be interested in providing pull requests? I would be happy to integrate any improvements you might have.

basinilya commented 3 years ago

Give me some time. Meanwhile I figured out it's not easy to construct a test .msg file for reproduction. The bug is only visible when 7d HEADERS is the last property seen. However, poi traverses the properties binary tree in a way that does not maintain the index order. So in my test message 7d HEADERS is followed by 65 SENT REPRESENTING EMAIL ADDRESS

basinilya commented 3 years ago

Attached the test file. (deleted property 65 with FlexHex, I hope it doesn't corrupt the message too much) Test at sign in personal From header.msg.zip getFromEmail() is expected to return "bogus@domain.com", but it actually returns "\"bogus@acme.com\""

bbottema commented 3 years ago

Fix released in 1.7.10. Thank you for your work!