I'm trying to extract incoming emails from gmail (well, Google 开发者_如何学编程Apps mail, but near enough) using IMAP. I want all good messages (not spam/deleted) even if they have been filed in different folders (so running through the Inbox is not sufficient), but I don't want messages sent from the current account, or drafts (both of which show up in the 'All Mail' folder).
This is for widespread use, so I can't just assume that there's only certain specific known folder names in addition to the Inbox to check.
UPDATE
Nope, this doesn't actually work properly. Working with another domain doesn't have the [$]NOTJUNK
flags; my guess is that these are set by Apple Mail.
/UPDATE
The best result I've managed to get so far is to find the messages in the AllMail folder with the $NOTJUNK
flag set, but the NOTJUNK
(no $) flag unset and filter out the messages that are returned from the Sent folder.
From the brief testing I've done NOTJUNK
was only set for draft messages (eg from Apple Mail, but not for drafts from within the web interface - in that case neither NOTJUNK
nor $NOTJUNK
were set)
Note: I'm using xlist
to find the correct localised versions of these folders.
Since the NOTJUNK
flags seem unreliable, I'm now getting all messages from the AllMail folder, throwing away the ones from the Sent folder, and then throwing away the ones that don't have the Delivered-To
header (I hope the drafts are the only ones without this header)
精彩评论