-1

I am trying to replicate a Google Apps mailbox into another Google account. I am using the IMAP library in Python.

I am able to get a unique UID for each mailbox. I could, download each message from each mailbox using thie UID.

The problem is that the unique UID is per mailbox, not per account. For example, one email may reside in two mailboxes, or have two labels. It will show up as two separate UIDs. If I download the email twice, they are no longer the same email. When one is deleted, the other will remain, etc.

Gmail has a X-GM-MSGID which gives a unique ID per the account.

At the moment, the only way I know of getting this X-GM-MSGID is by first getting the UID and requesting it's X-GM-MSGID. If the inbox has 10,000 emails, this will become a lot of requests. Is there a another way to get the X-GM-MSGID of all emails in an inbox, or even better, of all mailboxes?

I believe once I have the unique ID of each email, I can then FETCH the flags, time and content of each email and APPEND it onto the new server.

1 Answer 1

4

You can get multiple X-GM-MSGIDs using a bulk fetch:

FETCH 1:* X-GM-MSGID

However, there is a better approach.
Operate entirely within the All Mail folder (\AllMail from XLIST), and FETCH and STORE the X-GM-LABELS for each message.

3
  • Thank you. So the \AllMail includes everything: Sent, Drafts, Junk etc?
    – Michael
    Dec 11, 2012 at 16:41
  • @Mike: It doesn't include Spam or Trash.
    – SLaks
    Dec 11, 2012 at 16:41
  • Thanks SLaks! (char limit fluff)
    – Michael
    Dec 11, 2012 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.