IMAP Import

I used this to upload all of my old chats saved as .eml files directly into my new Gmail account. It uses IMAP’s append to do this. I had tried Thunderbird and the ImportExportTools plugin, but ran into trouble.

This puts all of the messages into a label called “oldchats”. This label needs to exist before this program is run. It also deletes each message after it is uploaded. I made a backup copy of my messages.

import email
import os
import time
import imaplib

imap = imaplib.IMAP4_SSL('', 993)
imap.login('', 'password')

for filename in os.listdir("."):
    print filename,
    raw_eml = file(filename).read()
    msg = email.message_from_string(raw_eml)
    date = email.utils.parsedate(msg['Date'])
    print date,
    imap.append('oldchats', None, date, raw_eml)
    print "done"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s