Search code examples
javagmailjakarta-mailimap

Downloading messages from Gmail using IMAPS hangs


I am facing a strange issue while i try to download the emails from GMAIL using IMAPS. I use JavaMail API. When it tries to download a particular file, it just gets hang and doesn't get timeout. I don't have any timeout configured. so, it stays there simply. But,there is no error or any exception in console. I have set the mail.imaps.prefetch property to false. I have shown the debug trace on the hanging mail below

A87 FETCH 22 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 22 FETCH (RFC822.SIZE 18474 INTERNALDATE "09-Oct-2012 05:26:11 +0000" ENVELOPE ("Tue, 9 Oct 2012 10:56:11 +0530" "HI" (("XXX" NIL "XXX" "gmail.com")) (("XXX.MCA" NIL "XXX" "gmail.com")) (("YYY" NIL "YYY" "gmail.com")) (("YYY" NIL "YYY" "gmail.com")) NIL NIL NIL "<CAM_EtGJGGOg-AQvMNsnGbbO-AWaVORk8NjwYU2XtsbeOR7MpuA@mail.gmail.com>"))
A87 OK Success
Message subject : HI
A88 FETCH 22 (BODYSTRUCTURE)
* 22 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1") NIL NIL "7BIT" 44 1 NIL NIL NIL)("APPLICATION" "VND.OPENXMLFORMATS-OFFICEDOCUMENT.WORDPROCESSINGML.DOCUMENT" ("NAME" "Servlets are server side components that provide a powerful mechanism for developing server side programs.docx") NIL NIL "BASE64" 15964 NIL ("ATTACHMENT" ("FILENAME" "Servlets are server side components that provide a powerful mechanism for developing server side programs.docx")) NIL) "MIXED" ("BOUNDARY" "bcaec55554467e8be004cb99931c") NIL NIL))
A88 OK Success
A89 FETCH 22 (BODY[1])
* 22 FETCH (BODY[1] {44}
 ur definition is here....................
)
A89 OK Success

May be the length of the filename is the problem here. But,i'd expect it to throw some error on it. I'm not sure as well. What would be the problem with this particular message? Please somebody help!


Solution

  • It looks like you replaced the body with some fake content in the debug output. It might help to see the actual content to make sure there's not an error in the formatting of the protocol message.

    Have you gotten a thread dump to see exactly where the program is hung? Is it hung trying to read data from the IMAP connection? What method is your program calling when it gets hung?

    As mentioned in the comments below, you need to be sure your program isn't throwing a runtime exception that you're not catching, making it appear that your program is hung when in fact it has been aborted.