Convert MBOX thunderbird to PST outlook

2021-02-07 Thread Kr4ck ALI
Hello,

I have to migrate multiple mailbox (emails, contacts, calendar, tasks) from
thunderbird to outlook Office 365.
I plan to export all items from thunderbird files (.mbox for email, .sqlite
or .sdb for calendar, .mab to contact) to PST files and import each PST
files to Office 365.
I know it's a tedious task ... But I know that nothing is impossible !
I found this script very helpfull to begin :

#!python3
import os, sys
import gzip
import mailbox
import urllib.request
import win32com.client

dispatch = win32com.client.gencache.EnsureDispatch
const = win32com.client.constants
PST_FILEPATH =
os.path.abspath(os.path.join(os.path.expandvars("%APPDATA%"),
"scratch.pst"))
if os.path.exists(PST_FILEPATH):
os.remove(PST_FILEPATH)
ARCHIVE_URL =
"https://mail.python.org/pipermail/python-list/2015-November.txt.gz";
MBOX_FILEPATH = "archive.mbox"

def download_archive(url, local_mbox):
with gzip.open(urllib.request.urlopen(url)) as archive:
with open(local_mbox, "wb") as f:
print("Writing %s to %s" % (url, local_mbox))
f.write(archive.read())

def copy_archive_to_pst(mbox_filepath, pst_folder):
archive = mailbox.mbox(mbox_filepath)
for message in archive:
print(message.get("Subject"))
pst_message = pst_folder.Items.Add()
pst_message.Subject = message.get("Subject")
pst_message.Sender = message.get("From")
pst_message.Body = message.get_payload()
pst_message.Move(pst_folder)
pst_message.Save()

def find_pst_folder(namespace, pst_filepath):
for store in dispatch(mapi.Stores):
if store.IsDataFileStore and store.FilePath == PST_FILEPATH:
return store.GetRootFolder()

download_archive(ARCHIVE_URL, MBOX_FILEPATH)
outlook = dispatch("Outlook.Application")
mapi = outlook.GetNamespace("MAPI")
pst_folder = find_pst_folder(mapi, PST_FILEPATH)
if not pst_folder:
mapi.AddStoreEx(PST_FILEPATH, const.olStoreDefault)
pst_folder = find_pst_folder(mapi, PST_FILEPATH)
if not pst_folder:
raise RuntimeError("Can't find PST folder at %s" % PST_FILEPATH)
copy_archive_to_pst(MBOX_FILEPATH, pst_folder)

My question is : Have you already make a mission like that ?

Thanks in advance !

@Kr4ckali
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert MBOX thunderbird to PST outlook

2021-02-07 Thread Kr4ck ALI
I have about 1000 mailbox to migrate and all are store in local on each
computers.
I know PST files store contacts, calendar, tasks... So, I think that is
possible to build a PST file with python to integrate the differents items
(emails, calendar, tasks,...) from thunderbird files.


Le lun. 8 févr. 2021 à 00:45, Cameron Simpson  a écrit :

> On 07Feb2021 15:06, Kr4ck ALI  wrote:
> >I have to migrate multiple mailbox (emails, contacts, calendar, tasks)
> >from thunderbird to outlook Office 365.
>
> I am also sorry to hear that.
>
> Had you considered getting them to enable IMAP access? Then you can
> migrate just by moving messages inside Thunderbird. And you can keep
> using your mail reader of choice.
>
> >I plan to export all items from thunderbird files (.mbox for email,
> .sqlite
> >or .sdb for calendar, .mab to contact) to PST files and import each PST
> >files to Office 365.
>
> The contacts and calendar stuff I have less idea about, alas. CalDAV for
> the calendar? I know that's a vague and unspecific suggestion.
>
> Cheers,
> Cameron Simpson 
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list