Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
None
-
None
-
Security Level: public (Regular issues)
-
- org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:1.8.3 (I can't find this version in JIRA list)
- Ubuntu 11.10 amd64
- Dovecot 1:2.0.13-1ubuntu3.2
- Oracle JDK 1.6.0_31-b04
Description
Sample code is pretty simple:
List<Emails> emails = new ArrayList<Emails>(); List<Recipients> recipients = new ArrayList<Recipients>(); try { log.debug("Getting the session ({}) for accessing email.", session); store = session.getStore("imap"); store.connect("localhost", "rudi", "password"); log.debug("Connection is established with IMAP server: {}", store); folder = store.getDefaultFolder(); log.debug("Getting the {}", target); if (target.equals("inbox")) { folder = store.getFolder("INBOX"); } else if (target.equals("sent")){ folder = store.getFolder("Sent"); } folder.open(Folder.READ_WRITE); // FetchProfile fetchProfile = new FetchProfile(); // fetchProfile.add(FetchProfile.Item.CONTENT_INFO); messages = folder.getMessages(); log.debug("No of messages is {}", folder.getMessageCount()); log.debug("No of unread messages is {}", folder.getUnreadMessageCount()); for (int i = 0; i < messages.length; i++) { message = messages[i]; subject = message.getSubject(); Date date = message.getSentDate(); Address[] sender = message.getFrom(); Address[] addRecipients = message.getAllRecipients(); String mimeType = message.getContentType(); log.debug("Detail of email-{} is date({}) - sender({}) - subject({}) - mimeType({})", new Object[]{i, date, sender, subject, ""}); for (int j = 0; j < addRecipients.length; j++) { recipients.add(new Recipients(addRecipients[j].toString())); log.debug("Recipient-{} is {}", j, addRecipients[j].toString()); } emails.add(new Emails(sender.toString(), recipients, subject, "message not found", date)); messageContentObject = message.getContent(); if (messageContentObject instanceof Multipart) { log.debug("Found email-{} with attachment", i); senderStr = ((InternetAddress) message.getFrom()[0]).getPersonal(); if (senderStr == null) { senderStr = ((InternetAddress) message.getFrom()[0]).getAddress(); log.debug("Sender is null, address is {}", sender); } subject = message.getSubject(); log.debug("subject is {} for message-{}", subject, i); multipart = (Multipart) message.getContent(); for (int j = 0; j < multipart.getCount(); j++) { part = multipart.getBodyPart(j); contentType = part.getContentType(); log.debug("Content type is {}", contentType); if (contentType.startsWith("text/plain")) { log.debug("Reading content type text/plain mail"); } else { String fileName = part.getFileName(); log.debug("File name is {}", fileName); } } } else { log.debug("Found mail without attachment"); senderStr = ((InternetAddress) message.getFrom()[0]).getPersonal(); if (senderStr == null) { senderStr = ((InternetAddress) message.getFrom()[0]).getAddress(); log.debug("Sender is null, address is {}", sender); } subject = message.getSubject(); log.debug("subject is {} for message-{} type: {}", new Object[] { subject, i, messageContentObject.getClass() }); log.debug("Message {} content: {}", i, messageContentObject); } } folder.close(true); store.close(); } catch (Exception e) { e.printStackTrace(); }
Log + stack trace:
A8 FETCH 1 (BODYSTRUCTURE) * 1 FETCH (BODYSTRUCTURE ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 6 1 NIL NIL NIL NIL)) A8 OK Fetch completed. java.lang.NullPointerException 01:00:05 [main] DEBUG i.c.bippo.commerce.dao.EmailsDaoTest - Emails are [] at javax.mail.internet.ParameterList.set(ParameterList.java:165) at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:390) at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:224) at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:158) at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:67) at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:136) at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:267) at com.sun.mail.iap.Protocol.command(Protocol.java:312) at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1453) at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:1445) at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:1145) at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1285) at com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:450) at id.co.bippo.commerce.dao.EmailsDao.getEmails2(EmailsDao.java:136) at id.co.bippo.commerce.dao.EmailsDaoTest.gettingMailInbox(EmailsDaoTest.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Also encountered another error:
01:51:52 [main] DEBUG id.co.bippo.commerce.dao.EmailDao - Getting the session (javax.mail.Session@3c3c9217) for accessing email. Loading javamail.default.providers from jar:file:/together/m2_repository/org/apache/geronimo/javamail/geronimo-javamail_1.4_mail/1.8.3/geronimo-javamail_1.4_mail-1.8.3.jar!/META-INF/javamail.default.providers DEBUG: loading new provider protocol=smtp, className=org.apache.geronimo.javamail.transport.smtp.SMTPTransport, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=smtps, className=org.apache.geronimo.javamail.transport.smtp.SMTPSTransport, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=nntp-post, className=org.apache.geronimo.javamail.transport.nntp.NNTPTransport, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=nntp-posts, className=org.apache.geronimo.javamail.transport.nntp.NNTPSSLTransport, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=nntp, className=org.apache.geronimo.javamail.store.nntp.NNTPStore, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=nntps, className=org.apache.geronimo.javamail.store.nntp.NNTPSSLStore, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=pop3, className=org.apache.geronimo.javamail.store.pop3.POP3Store, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=pop3s, className=org.apache.geronimo.javamail.store.pop3.POP3SSLStore, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=imap, className=org.apache.geronimo.javamail.store.imap.IMAPStore, vendor=Apache Software Foundation, version=1.0 DEBUG: loading new provider protocol=imaps, className=org.apache.geronimo.javamail.store.imap.IMAPSSLStore, vendor=Apache Software Foundation, version=1.0 DEBUG: getProvider() returning provider protocol=imap; type=javax.mail.Provider$Type@4e513d61; class=org.apache.geronimo.javamail.store.imap.IMAPStore; vendor=Apache Software Foundation;version=1.0 IMAPStore DEBUG: Connecting to server localhost:-1 for user rudi imap DEBUG: Attempting plain socket connection to server localhost:143 a0 CAPABILITY * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN] Dovecot ready. * CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN a0 OK Pre-login capabilities listed, post-login capabilities have more. imap DEBUG: Authenticating for user: rudi using PLAIN a1 AUTHENTICATE PLAIN + java.lang.NullPointerException at org.apache.geronimo.javamail.store.imap.connection.IMAPTaggedResponse.isBAD(IMAPTaggedResponse.java:86) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.receiveResponse(IMAPConnection.java:410) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.sendCommand(IMAPConnection.java:324) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.processLogin(IMAPConnection.java:598) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.processPlainAuthentication(IMAPConnection.java:537) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.login(IMAPConnection.java:488) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnection.protocolConnect(IMAPConnection.java:176) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.createPoolConnection(IMAPConnectionPool.java:211) at org.apache.geronimo.javamail.store.imap.connection.IMAPConnectionPool.protocolConnect(IMAPConnectionPool.java:177) at org.apache.geronimo.javamail.store.imap.IMAPStore.protocolConnect(IMAPStore.java:156) at javax.mail.Service.connect(Service.java:251) at javax.mail.Service.connect(Service.java:91) at id.co.bippo.commerce.dao.EmailDao.getEmails2(EmailDao.java:105) at id.co.bippo.commerce.dao.EmailDaoTest.gettingMailInbox(EmailDaoTest.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 01:51:52 [main] DEBUG i.co.bippo.commerce.dao.EmailDaoTest - Emails are []
Probably relevant code snippet at com.sun.mail.imap.protocol.BODYSTRUCTURE:
private ParameterList parseParameters(Response r) throws ParsingException { r.skipSpaces(); ParameterList list = null; byte b = r.readByte(); if (b == '(') { list = new ParameterList(); do { String name = r.readString(); if (parseDebug) System.out.println("DEBUG IMAP: parameter name " + name); if (name == null) throw new ParsingException( "BODYSTRUCTURE parse error: " + type + "/" + subtype + ": " + "null name in parameter list"); String value = r.readString(); if (parseDebug) System.out.println("DEBUG IMAP: parameter value " + value); list.set(name, value); } while (r.readByte() != ')'); list.set(null, "DONE"); // XXX - hack } else if (b == 'N' || b == 'n') { if (parseDebug) System.out.println("DEBUG IMAP: parameter list NIL"); r.skip(2); } else throw new ParsingException("Parameter list parse error"); return list; }
and the one in javax.mail.internet.ParameterList :
public void set(String name, String value) { name = name.toLowerCase(); _parameters.put(name, new ParameterValue(name, value)); }
Workaround:
Replacing geronimo-javamail_1.4_mail with javax.mail:mail:1.4.5 works beautifully. Complete log when using javax.mail:mail :
DEBUG: JavaMail version 1.4.5 DEBUG: successfully loaded resource: /META-INF/javamail.default.providers DEBUG: Tables of loaded providers DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]} DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]} DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map DEBUG: setDebug: JavaMail version 1.4.5 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - Getting the session (javax.mail.Session@46c837cd) for accessing email. DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc] DEBUG: mail.imap.fetchsize: 16384 DEBUG: mail.imap.statuscachetimeout: 1000 DEBUG: mail.imap.appendbuffersize: -1 DEBUG: mail.imap.minidletime: 10 DEBUG: trying to connect to host "localhost", port 143, isSSL false * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN] Dovecot ready. DEBUG IMAP: AUTH: PLAIN DEBUG: protocolConnect login, host=localhost, user=rudi, password=<non-null> DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed DEBUG IMAP: AUTHENTICATE PLAIN command result: A0 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - Connection is established with IMAP server: imap://rudi@localhost 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - Getting the inbox DEBUG: connection available -- size: 1 A1 SELECT INBOX * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted. * 1 EXISTS * 0 RECENT * OK [UIDVALIDITY 1336586379] UIDs valid * OK [UIDNEXT 2] Predicted next UID * OK [HIGHESTMODSEQ 1] Highest A1 OK [READ-WRITE] Select completed. 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - No of messages is 1 A2 SEARCH UNSEEN ALL * SEARCH A2 OK Search completed (0.000 secs). 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - No of unread messages is 0 A3 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE) * 1 FETCH (INTERNALDATE "10-May-2012 00:59:39 +0700" RFC822.SIZE 410 ENVELOPE ("Thu, 10 May 2012 00:59:39 +0700 (WIT)" "halo" (("Hendy Irawan" NIL "ceefour" "annafi")) (("Hendy Irawan" NIL "ceefour" "annafi")) (("Hendy Irawan" NIL "ceefour" "annafi")) ((NIL NIL "rudi" "annafi.dev")) NIL NIL NIL "<20120509175939.C2275A2463@annafi>")) A3 OK Fetch completed. A4 FETCH 1 (BODY.PEEK[HEADER.FIELDS (Newsgroups)]) * 1 FETCH (BODY[HEADER.FIELDS (NEWSGROUPS)] {2} ) A4 OK Fetch completed. A5 FETCH 1 (BODYSTRUCTURE) * 1 FETCH (BODYSTRUCTURE ("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 6 1 NIL NIL NIL NIL)) A5 OK Fetch completed. 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - Detail of email-0 is date(Thu May 10 00:59:39 WIT 2012) - sender([Hendy Irawan <ceefour@annafi>]) - subject(halo) - mimeType() 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - Recipient-0 is rudi@annafi.dev A6 FETCH 1 (BODY[TEXT]<0.6>) * 1 FETCH (BODY[TEXT]<0> {6} yuhu ) A6 OK Fetch completed. A7 FETCH 1 (FLAGS) * 1 FETCH (FLAGS (\Seen)) A7 OK Fetch completed. 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - Found mail without attachment 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - subject is halo for message-0 type: class java.lang.String 01:24:28 [main] DEBUG id.co.bippo.commerce.dao.EmailsDao - Message 0 content: yuhu A8 CLOSE A8 OK Close completed. DEBUG: added an Authenticated connection -- size: 1 A9 LOGOUT * BYE Logging out A9 OK Logout completed. DEBUG: IMAPStore connection dead DEBUG: IMAPStore cleanup, force false DEBUG: IMAPStore cleanup done 01:24:28 [main] DEBUG i.c.bippo.commerce.dao.EmailsDaoTest - Emails are [Emails [sender=[Ljavax.mail.internet.InternetAddress;@4bd53f5b, recipients=[Recipients [recipient=rudi@annafi.dev]], subject=halo, message=message not found, sentDate=Thu May 10 00:59:39 WIT 2012]]
Attachments
Issue Links
- relates to
-
GERONIMO-6526 IMAP connection via java mail api (geronimo-javamail_1.4_mail) throws NPE
- Resolved