/
notes2mbox.py
64 lines (52 loc) · 2.18 KB
/
notes2mbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
# hugues.bernard@gmail.com
# viktor.vojnovski@gmail.com
# Pour utiliser ce script :
# * Installer python 2.6 pour windows
# * Installer pywin 2.6 pour windows
# * (optionnellement) enregistrer la dll com de notes : "regsvr32 c:\notes\nlsxbe.dll"
# * en ligne de commande (cmd) :
# SET PATH=%PATH%;C:\Python26
# **pour l'instant** fixer notesPasswd et notesNsfPath plus bas
# python notes2mbox.py
# => un fichier .mbox sera créé qu'il suffit de copier dans le répertoire ad-hoc de Thunderbird (ou d'un autre client...)
import sys
import NlconverterLib
#Constantes
notesNsfPath = 'D:\\Userfiles\\vvojnovski\\Desktop\\viktorvojnovski.nsf'
notesPasswd = 'blablabla'
outputFolder = 'D:\\Userfiles\\vvojnovski\\Desktop\\mails\\'
#Connection à Notes
db = NlconverterLib.getNotesDb(notesNsfPath, notesPasswd)
#all = tous les documents
all=db.AllDocuments
ac = all.Count
print "Nombre de documents :", ac
c = 0 #compteur de documents
e = 0 #compteur d'erreur à la conversion
# Iterates on each folder. Note that if a message is not in a folder it won't be converted
for view in db.Views:
if view.IsFolder:
folderName = view.Name
folderNameClean = folderName.replace('$', '').replace('(', '').replace(')', '').replace('/', '').replace('\\', '')
print("Processing folder %s", folderName)
folder = db.GetView(folderName)
if not folder:
print('Folder "%s" not found' % folderName)
continue
mc = NlconverterLib.NotesToMboxConverter(outputFolder + folderNameClean + ".mbox")
doc = folder.GetFirstDocument()
while doc and c < 100000 and e < 99999:
try:
mc.addDocument(doc)
except Exception, ex:
e += 1 #compte les exceptions
print "\n--Exception for message %d (%s)" % (c, ex)
mc.debug(doc)
finally:
doc = folder.GetNextDocument(doc)
c+=1
if (c % 100) == 0:
sys.stderr.write("%.1f%%, e=%d, c=%d\n" % (float(100.*c/ac), e, c) )
mc.close()
print "Exceptions a traiter manuellement:", e, "... documents OK : ", c