JavaMail IMAP Groupwise 7.01 Calendar

Recently I have been given the task to write a piece of Java code to get todays appointments from GroupWise and display them to a user through a website.

I am receiving NPE (Null Pointer Exception) for getContent(), getContentType(), getDisposition(), etc. However getHeaders(), getSubject(), writeTo(System.out) and other methods work fine.

From the headers I can see the message is multipart/alternative, with text/calendar and text/plain as the parts. However I can not use the methods provided to get this information.

I can develop a work around, but was hoping I might have missed something as I have not used this API for very long.

...

Folder calendar = imapStore.getFolder("Calendar");

calendar.open(Folder.READ_ONLY);

Message [] msgs = calendar.getMessages();

if(msgs.length > 0)

System.out.println(msgs[1].getContentType());//NPE throws here

....

The above code throws null exception on the "Calendar" folder, however if you run the same code on the "Inbox" all is okay.

Any help/comments would be great.

Swunx.

[1202 byte] By [Swunxa] at [2007-10-3 3:45:04]
# 1

New to Java?

> if(msgs.length > 0)

> System.out.println(msgs[1].getContentType());

> //NPE throws here

You check that there are more than zero elements in the array,

then you access the second element. Are you sure you're not

getting ArrayIndexOutOfBoundsException?

If you're really getting NullPointerException, a stack trace would

be helpful, as would a protocol trace (see the JavaMail FAQ).

Also, make sure you have all the latest patches for GroupWise.

It's had more than its share of bugs with complex MIME messages.

bshannona at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

I was testing it on my inbox /calendar (where I new I had 10+ items) and item 2 in my inbox was also a multipart/alternative just like the calendar.

I forgot to change it back to 0 when I pasted the code :( sorry.

Obviously I'm not likely to use an if statement here in the final code. The NPE is defintely being thrown when any of the getContent, getDisposition methods are called.

Folder calendar = imapStore.getFolder(DEFAULT_CALENDAR);

calendar.open(Folder.READ_ONLY);

msgs = calendar.getMessages();

for(int i=0; i<msgs.length; i++)

{

System.out.println(msgs[i].getContentType()); //NPE HERE

}

And the Exception

null

java.lang.NullPointerException

at javax.mail.internet.ParameterList.set(ParameterList.java:113)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:221)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.><init>(BODYSTRUCTURE.java:128)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:66)

at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:129)

at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:35)

at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:107)

at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:153)

at com.sun.mail.iap.Protocol.command(Protocol.java:215)

at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:882)

at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:874)

at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:616)

at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1027)

at com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:321)

at au.edu.swin.portal.IMAPUtil.getCalendarAppointments(IMAPUtil.java:179)

at au.edu.swin.portal.IMAPUtil.main(IMAPUtil.java:34)

Thanks for pointing that out though :)

Swunxa at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

It's getting the exception while parsing the BODYSTRUCTURE response

from the server, which almost always means that the server is broken and

has sent a response that doesn't obey the IMAP spec. I've certainly seen this

kind of thing with GroupWise before. If you want to trun on session debugging

and post the protocol trace, I'll show you where the server is sending bad

data, but you have to promise to report the bug to the vendor! :-)

bshannona at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

As soon as I had this problem I thought... Groupwise Issue.

Here is the Session Debug as requested. We do have full support with Novell and I intend to log this problem to them. I will post any replies I receive.

DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]

* OK [CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN AUTH=XGWTRUSTEDAPP UNSELECT XGWEXTENSIONS] GroupWise Server Ready

A0 CAPABILITY

* CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN AUTH=XGWTRUSTEDAPP UNSELECT XGWEXTENSIONS

A0 OK CAPABILITY completed

A1 LOGIN USERNAME PASSWORD

A1 OK LOGIN completed

A2 NOOP

A2 OK NOOP completed

A3 LIST "" Calendar

* LIST (\Unmarked) "/" "Calendar"

A3 OK LIST completed

DEBUG: connection available -- size: 1

A4 EXAMINE Calendar

* 34 EXISTS

* 2 RECENT

* OK [UIDVALIDITY 1115116956]

* OK [UIDNEXT 132]

* FLAGS (\Answered \Flagged \Deleted \Draft \Seen)

* OK [PERMANENTFLAGS ()]

A4 OK [READ-ONLY] EXAMINE completed

A5 FETCH 1 (BODYSTRUCTURE)

* 1 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 140 7 NIL ("inline" NIL) NIL)("text" "calendar" ("charset" "utf-8" "component" ""vevent"") NIL NIL "quoted-printable" 650 23 NIL NIL NIL) "alternative" ("boundary" "_ZFYPCZJMDKLXPTVZSNJR_") NIL NIL))

A5 OK FETCH completed

null

java.lang.NullPointerException

at javax.mail.internet.ParameterList.set(ParameterList.java:113)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:221)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:128)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:66)

at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:129)

at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:35)

at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:107)

at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:153)

at com.sun.mail.iap.Protocol.command(Protocol.java:215)

at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:882)

at com.sun.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:874)

at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:616)

at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1027)

at com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:321)

at au.edu.swin.portal.IMAPUtil.getCalendarAppointments(IMAPUtil.java:182)

at au.edu.swin.portal.IMAPUtil.main(IMAPUtil.java:35)

Process exited with exit code 0.

Swunxa at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
You can see the problem here:("charset" "utf-8" "component" ""vevent"")Notice the quoted string that seems to contain a quoted string.
bshannona at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Same exception (slightly different stack trace - JM 1.3.1) with the following BODYSTRUCTURE. It's because text, plain, and html are not quoted, correct?

A10 UID FETCH 808395212 (BODYSTRUCTURE)

* 3 FETCH (UID 808395212 BODYSTRUCTURE ( (text plain ("CHARSET" "iso-8859-1") NIL NIL "7bit" 0 1 NIL NIL NIL) (text html ("CHARSET" "iso-8859-1") NIL NIL "7bit" 45 1 NIL NIL NIL)))

java.lang.NullPointerException

at javax.mail.internet.ParameterList.set(ParameterList.java:115)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:227)

at com.sun.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:134)

at com.sun.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:128)

at com.sun.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:37)

at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:106)

at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:154)at com.sun.mail.iap.Protocol.command(Protocol.java:220)

burridgea at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
> Same exception (slightly different stack trace - JM> 1.3.1) with the following BODYSTRUCTURE. It's> because text, plain, and html are not quoted,> correct?Yes.Is this also with Groupwise? Report the bug to them.
bshannona at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
Mail2World IMAP4 Server 2.5. I'll report the issue to them.
burridgea at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
You might want to consider a server built by someone who has abetter understanding of the IMAP protocol...
bshannona at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
Touch?.. ;)
burridgea at 2007-7-14 21:41:28 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...