Check email header for RFC 822 standard and match emails between imap servers.

Vincent Davis vincent at
Thu Aug 18 19:53:35 EDT 2011

The sort story, I have been attempting to use the Google Migration assistant
to migrate emails from one google account to another, about 80,000 emails.
I have two problems.
1. Many emails that fail to transfer because of errors like "Invalid RFC 822
Message: Date header "Mon Feb 05 22:07:16 2007" is invalid." See
full error below.
 emails that.
2. I need to delete the emails from the old account that have been

And the Two question are:
I am able to connect and get an email. But I am not clear how I would check
that the header is valid or identify the problem.
grl = imaplib.IMAP4_SSL('', 993)
grl.login('name at', 'password')
grl.fetch(17006, 'uid')
# So now I have an email how do I check the header, I know how to view it
but not check it for RFC 822.

Since I don't know which emails have been transferred I want to delete all
the email that have. To be more correct I don't know which ones on the old
account, when they are moved to the new account they get the label as
transferred. How should I compare emails? The uid is different on each
server so I think using the TO: FROM: and DATE: TIME: would work.
How do I compare emails in this way?
How to I get the TO: FROM: DATE: TIME: from one email to reach for the same
email in the other account.

Sample error from google migration app.

2011-08-16T16:47:47.141-06:00  808 E:Network
ExchangeMigration!WinHttp::ExecuteHttpRequestIStreamResponse @ 696 (
gmetanias at <gmetanias at>)> Response:

Invalid RFC 822 Message: Date header "Mon Feb 05 22:07:16 2007" is

2011-08-16T16:47:47.141-06:00  808 E:Migration
ExchangeMigration!EmailUploader::HandleStatus @ 462
(gmetanias at<gmetanias at>)>
Permanent Message Failure, skipping the message!.

2011-08-16T16:47:47.328-06:00  808 E:Migration
ExchangeMigration!IMAPMessageWrapper::GetMessageSentTime @ 154 (
gmetanias at <gmetanias at>)> Failed with 0x80004005, last
successful line = 151.

2011-08-16T16:47:47.328-06:00  808 E:Migration
ExchangeMigration!IMAPMessageWrapper::GetMessageReceivedTime @ 170 (
gmetanias at <gmetanias at>)> Failed with 0x80004001, last
successful line = 168.

2011-08-16T16:47:47.328-06:00  808 E:Migration
ExchangeMigration!GetMessageDescription @ 198
(gmetanias at<gmetanias at>)>
Sent: 2011-08-16T22:47:47.000Z. Received: 2011-08-16T22:47:47.000Z. Size:
196114. Subject RE: ppt templates.

Vincent Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list