I'm not familiar with javamail, but I am familiar with the IMAP protocol (RFC 3501) and I would try following approaches:
- Use FETCH command to retrieve the item's Content-Type header. This only works if the Content-Type header field of Tasklist or Calendar items is different from the field used by ordinary e-mail messages. Another problem is that some IMAP servers are known not to support retrieving individual header fields (but you might still be able to retrieve all the full header with all fields in this case using BODY.PEEK[HEADER]).
Sample IMAP command:
TAG0001 FETCH 1 BODY.PEEK[HEADER.FIELDS (CONTENT-TYPE)]
Sample IMAP server response:
* 1 FETCH (BODY[HEADER.FIELDS (CONTENT-TYPE)] {69}...data..})
TAG0001 OK Success
The content of "...data..." is the Content-type header:
Content-Type: text/calendar;
name="meeting.ics";
method=REQUEST
- If it's not possible to decide whether the item is a calendar item the message's Content-Type header because it's a common type like multipart/something, use the FETCH command to retrieve the message structure and search the MIME tree for any calendar items with appropriate Content-type.
Sample IMAP command:
TAG0002 FETCH 2 (BODY)
Sample IMAP server response:
* 1 FETCH (
BODY
(
(
("text" "plain" ("charset" "iso-8859-2") NIL NIL "quoted-printable" 194 1)
("text" "html" ("charset" "iso-8859-2") NIL NIL "quoted-printable" 1173 1)
("text" "calendar"
("name" "meeting.ics" "charset" "windows-1252" "method" "REQUEST") NIL NIL "8bit" 1531 1)
"alternative"
)
"mixed"
)
)
TAG0002 OK FETCH completed.
(lots of whitespaces added for better readability)
Check out sections 6.4.5 and 7.4.2 of RFC 3501 for more information about the FETCH command and its response format. I don't know how to achieve this using javamail, unfortunately.