开发者

how to detect an IMAPMessage is not an email but a Task or Calendar item

开发者 https://www.devze.com 2022-12-22 19:06 出处:网络
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 fro开发者_如何学运维mGro

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 fro开发者_如何学运维m 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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号