views:

103

answers:

1

I am accessing Lotus and Groupwise using javamail via IMAP, recursively accessing all folders and processing email I find. But in folders like Tasklist and Calendar (those are from Groupwise but I think I remember Lotus had similar things), I get the items in there as instances of IMAPMessage, and so they are processed as if they were mail.

I understand those items get exposed as mail through the IMAP protocol (either by design or by mistake), but I only want to process proper mail. Is there a way to do this? I have dismissed following approaches so far:

  • Make sure the message has a message-id, at least in Groupwise Calendar items have it.
  • Ignore folders by name (such as Calendar and Tasklist): is not totally correct as a user can move mail inside those folders.

What I am looking is some IMAP api call I have missed so far or something in those lines...

A: 

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.

Lukas Pokorny
thanks man!! Your first approach should work, I mean I am able to get the headers so this is not a problem. I'll check the Content-Type for Calendar and Tasks and report back. You seem to have lots of knowledge of IMAP...if you feel like have a look at another IMAP related question I posted: http://stackoverflow.com/questions/2479117/imap-protocol-support-in-different-email-servers
raticulin
I wrote a large part of Rebex IMAP component (.NET/C# - not useful for you), so I gained some knowledge during the process :-)
Lukas Pokorny
The Content-Type of the calendar items is multipart/alterntive, but I was able to detect them using your second method. This works with Groupwise (Tasklist and Calendar folders), didn't test Lotus yet. Thanks!
raticulin