Evolution to IMAP migration script

Hi everyone,

I’m ready to release my Evolution to IMAP migration script. The script will check your local evolution mbox store and tries to upload all mbox files to an IMAP server like google-mail.

You need to make sure that:

  • you have downloaded and extracted the upload_imap.py script [see this link]
  • you have enough space on the IMAP server
  • no mails are stored in a folder which contains sub-folder(s)
  • you have some time
  • you have copied the upload_imap.py script to the location where the migration_script.py is stored

Download my script here and extract it. Make sure you read the readme file and changed the settings to plausible values. The script is very dirty and nasty and does not check any mistakes done by the user.

Run the script by typing this in your terminal:

python migration_script.py

Find below the script:

#!/usr/bin/env python
'''
Small and dirty script to scan my Evolution mbox folder.
This script will set up an environment to allow a simple and fast
creation and migration of evolution emails done by [tool]
'''
 
import os, sys, imaplib, string, array
 
############# declaration #############
server_hostname = ''    # your mail-server
server_user = ''    # username used for authentication
server_password = ''    # password used for authentication
 
evolution_rootdir = '~/.local/share/evolution/mail/local' # your default evolution folder
 
imap_rootdir = 'imported' # use something else than 'INBOX'
imap_delimiter = '/'      # default on most servers seems to be a period, mine uses a slash
imap_use_SSL = True      # we want to use ssl
imap_Err_Logging = True   # we want to log errors 
 
############# implementation #############
fld = list()
 
TL = list()
t = ''
 
def readEvolutionFolder():
    for root, subFolders, Files in os.walk(evolution_rootdir):
        for file in Files:
            if (string.find(file, '.cmeta') != -1) or (string.find(file, '.ibex.') != -1) or (string.find(file,'folder.db') != -1):
                TL.append(file)
            else:
                EvolutionMbox = evoFld()
                t = os.path.join(root, file)
                EvolutionMbox.folderpath = t
                t = string.replace(t,evolution_rootdir,'')
                t = string.replace(t, '.sbd', '')
                t = string.replace(t, 'Inbox',imap_rootdir)
                t = string.replace(t, '/', '', 1)
                t = string.replace(t, '/', imap_delimiter)
                EvolutionMbox.boxpath = t
                fld.append(EvolutionMbox)
 
def createIMAPPostBox( name ):
    if (imap_use_SSL == True):
        MailBox = imaplib.IMAP4_SSL(server_hostname)
    else:
        MailBox = imaplib.IMAP4(server_hostname)
    MailBox.login(server_user, server_password)
 
    print MailBox.create(name)
 
    MailBox.logout()
 
def compareSlashes1(f1, f2):
    cntSlashesF1 = 0
    cntSlashesF2 = 0
 
    cntSlashesF1 = string.find(f1.boxpath, '/')
    cntSlashesF2 = string.find(f2.boxpath, '/')
 
    if (cntSlashesF1 <= cntSlashesF2):
        return -1
    else:
        return 1
 
class evoFld:
    def __init__(self):
        self.folderpath = ''
        self.boxpath = ''
 
def syncFolders ():
    imap_upload = ''
 
    for f in fld:
        if(f.boxpath != imap_rootdir):
            print 'creating: ', f.boxpath
            createIMAPPostBox(f.boxpath)
            print 'passing credentials to imap_upload.py'
            imap_upload = ' --host='
            imap_upload += server_hostname
            if (imap_use_SSL == True):
                imap_upload += ' --ssl'
            imap_upload += ' --user='
            imap_upload += server_user
            imap_upload += ' --pass='
            imap_upload += server_password
            imap_upload += ' --box="'
            imap_upload += f.boxpath
            imap_upload += '" "'
            imap_upload += f.folderpath
            imap_upload += '"'
            if (imap_Err_Logging == True):
                imap_upload += ' --error="Import_Errors"'
            os.system('python imap_upload.py' + imap_upload)
 
        else:
            print 'passing credentials to imap_upload.py'
            imap_upload = ' --host='
            imap_upload += server_hostname
            if (imap_use_SSL == True):
                imap_upload += ' --ssl'
            imap_upload += ' --user='
            imap_upload += server_user
            imap_upload += ' --pass='
            imap_upload += server_password
            imap_upload += ' --box="Inbox"'
            imap_upload += ' "'
            imap_upload += f.folderpath
            imap_upload += '"'
            if (imap_Err_Logging == True):
                imap_upload += ' --error="Import_Errors"'
            os.system('python imap_upload.py' + imap_upload)
 
readEvolutionFolder()
fld.sort(compareSlashes1)
syncFolders()

 

This entry was posted in Gentoo, python and tagged , , , , , . Bookmark the permalink.

3 Responses to Evolution to IMAP migration script

  1. I think this is among the most significant information for me. And i’m glad reading your article. But wanna remark on few general things, The web site style is perfect, the articles is really nice : D. Good job, cheers
    louis vuitton bags http://louisvuittonbagsonlines.overblog.com

  2. It? exhausting to find educated folks on this matter, however you sound like you recognize what you?e speaking about! Thanks

  3. National American Football League is the National Football League,referred to the [url=http://www.6pmsjerseys.com]NFL Jerseys For Cheap[/url]. Is a huge American Football League. A total of 32 teams in the league, is divided into two federations: the United States [url=http://www.6pmsjerseys.com]Cheap Authentic NFL Jerseys[/url]Football League (American Football Conference, referred to as the AFC, Midland) and the National Football League (National Football Conference,referred to as the NFC, the League of Nations). Each Federation has 16 teams, divided into four sub-Division: eastern, southern, western and northern. Each sub-Division has four teams. Reebok company is the only raw nfl jerseys clothing manufacturers, have specialized wholesale jerseys in foreign countries, genuine [url=http://www.6pmsjerseys.com]China NFL Jerseys[/url] can be roughly divided into three categories, from low-end to high-level are: offset fans version (Replica Jersey), senior fans version (Premier Jersey / EQT Jersey), player version (Authentic). Several jersey main difference is that the jersey fabric, numbers fabrics, clothing type aspects.
    China NFL Jerseys http://www.6pmsjerseys.com/

Leave a Reply