6 Replies Latest reply: Jan 24, 2012 12:37 PM by Bill Shannon-Oracle RSS

    JavaMail hangs on e-mails where there is an unclosed parentheses on CC

      Hi All,

      I'm reading e-mails via IMAP from a mail box with JavaMail. My program reads the e-mails correctly, except those who has an unclosed parentheses, only the "(" without the ")", in the CC field.
      This may happen when there is an unclosed parentheses in other fields, like TO, I couldn't test it so far.

      Well, when my program reaches this e-mail with unclosed parentheses, it simply hangs waiting forever to read the message until the timeout occurs. I can't even read the subject or from fields of this message.
      Debugging the JavaMail's code, I found that it hangs at this point:

      Line in the code: while (!gotCRLF && ((b = bin.read()) != -1)) {    (in the code this line actually has a line-break in the middle)
      Method: public ByteArray readResponse(ByteArray ba)
      Class: com.sun.mail.iap.ResponseInputStream

      The hangs occurs exactly in the "bin.read()" command, in the first try
      It seems that the program tries to read the response and the server gives no response. But sniffing the network, I realized that a response comes from the server.

      In order to test it, I installed ThunderBird and tried to read this problematic e-mail. And the Thunderbird read this e-mail with NO PROBLEMS.

      Nevertheless, I saw a difference between the JavaMail request text and the ThunderBird:

      JavaMail: A12 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)\x0d\x0a

      54 UID fetch 1:* (FLAGS)\x0d\x0a
      55 UID fetch 33 (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type)])\x0d\x0a

      It seems Thunderbird performs two commands, while JavaMail, just one. And this one is different from the Thunderbird ones.

      I'd appreciate any help in this problem.

      Thanks !

      Edited by: 909041 on 19/01/2012 07:12