issues@javamail.java.net

[Bug 5090] New: Yahoo: Error reading emails containing "undisclosed recipients" as a recipient

From: <bugzilla-daemon_at_kenai.com>
Date: Wed, 25 Apr 2012 13:25:09 +0000

http://kenai.com/bugzilla/show_bug.cgi?id=5090

             Bug #: 5090
           Summary: Yahoo: Error reading emails containing "undisclosed
                    recipients" as a recipient
    Classification: Unclassified
           Product: javamail
           Version: 1.4.5
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P5
         Component: imap
        AssignedTo: shannon_at_kenai.com
        ReportedBy: tking_at_kenai.com
                CC: issues_at_javamail.kenai.com


Hello all,

with Javamail 1.4.5 it is not possible to retrieve the envelope of emails from
Yahoo containing "undisclosed recipients" as a recipient. If you try to
retrieve such an email you get an exception:
javax.mail.MessagingException: Failed to load IMAP envelope
        at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1265)
        at com.sun.mail.imap.IMAPMessage.getSize(IMAPMessage.java:394)
...

The reason is that Yahoo returns the recipient in a wrong format:
A8 FETCH 2 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 2 FETCH (INTERNALDATE "24-Apr-2012 20:28:58 +0000" RFC822.SIZE 155937
ENVELOPE ("Wed, 28 Sep 2011 11:16:17 +0100" "[WI] Call for Papers
(Neurocomputing Special Issue on Image Feature Detection and Description)"
((NIL NIL "xxx" "tju.edu.cn")) ((NIL NIL "xxx" "gmail.com")) ((NIL NIL "xx"
"tju.edu.cn")) (("undisclosed-recipients" NIL "\"undisclosed-recipients\"" NIL
)) NIL NIL NIL
"<CAPr0uQNP+cSbqaJ_J1fA6A0vY6v6WhjwfTL5yRVX8Vbu5YpvZQ_at_mail.gmail.com>"))

To be more precise the reason is the space after the last NIL in
("undisclosed-recipients" NIL "\"undisclosed-recipients\"" NIL ))

The root cause of the problem is Yahoo as it delivers the emails in a wrong
format. However, in order to make Javamail more robust I propose the following
patch:
tking_at_linux-tu08:~/test/javamail_hg/javamail~mercurial/mail/src/main/java/com/sun/mail/imap/protocol>
hg diff ENVELOPE.java
diff -r 42b6d8c53009
mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java
--- a/mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java Fri Mar
23 14:31:07 2012 -0700
+++ b/mail/src/main/java/com/sun/mail/imap/protocol/ENVELOPE.java Wed Apr
25 00:10:20 2012 +0200
@@ -158,7 +158,14 @@
         r.readString(); // throw away address_list
        String mb = r.readString();
        String host = r.readString();
- if (r.readByte() != ')') // skip past terminating ')'
+ byte character = r.readByte();
+ // this check is required because Yahoo IMAP servers set such a
string if undisclosed-recipients (or similar strings) are used as a recipient:
+ // (("undisclosed-recipients" NIL "\"undisclosed-recipients\"" NIL
))
+ // here the last character in the string before the brakets is a
space
+ if (character == ' ') {
+ character = r.readByte();
+ }
+ if (character != ')') // skip past terminating ')'
             throw new ParsingException("ADDRESS parse error");

        if (host == null) {


Please review the patch and my proposed solution.


Best regards,
Thomas

-- 
Configure bugmail: http://kenai.com/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.