forked from jonabbey/eudora2unix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEudora2Unix.py
executable file
·715 lines (610 loc) · 21.8 KB
/
Eudora2Unix.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
#!/usr/bin/env python
"""
Walk through a Eudora mail directory converting mailboxes to unix .mbox format,
for either pine or kmail
"""
__author__ = "Stevan White <[email protected]"
__credits__ = "Based on Eudora2Unix.sh by Eric Maryniak"
__date__ = "2010-11-28"
__version__ = "2.0"
import sys
import types
import time
import shutil
import os
from os.path import *
import re
import string
import argparse
if sys.hexversion < 33686000:
sys.stderr.write( "Aborted: Python version must be at least 2.2.1" \
+ os.linesep )
sys.exit( 1 )
import Eudora2Mbox
import EudoraTOC
OUT_SFX = '.E2U_OUT'
ORIG_SFX = '.E2U_ORIG'
re_mbx_sfx = re.compile( '(.*?)\.mbx$', re.IGNORECASE )
re_toc_sfx = re.compile( '(.*?)\.toc$', re.IGNORECASE )
re_fol_sfx = re.compile( '(.*?)\.fol$', re.IGNORECASE )
re_out_sfx = re.compile( '(.*?)\.e2p_out$', re.IGNORECASE )
re_in = re.compile( 'in\.mbx', re.IGNORECASE )
re_out = re.compile( 'out\.mbx', re.IGNORECASE )
re_trash = re.compile( 'trash\.mbx', re.IGNORECASE )
isMac = False; # global for convert_files
attachments_not_handled = set()
attachments_handled_by = {}
embedded_dir = None
# --------------------- Comments & complaints ----------------------
def target_directory_already_exists_complaint( maildir ):
return [
'Directory ' + maildir + ' already exits. Rename it, e.g. to ',
maildir + '-old',
'then you can merge the old into the new mail directory',
'(' + maildir + ') after conversion.'
]
def source_directory_not_readable_complaint( src ):
return '"' + src + '" is not a (readable) directory, abort.'
def not_eudora_directory_complaint():
return 'This is not a Eudora directory; cannot find inbox, abort.'
def entered_directory_remark( DIR ):
return 'Entered directory ' + DIR
def entering_directory_complaint( DIR, strerror ):
return "Cannot enter directory '" + DIR + "': " + strerror + ', abort.'
def cannot_open_complaint( fpath, strerror ):
return 'Cannot open "' + fpath + '"' + ": " + strerror
def cannot_move_complaint( src, dst, strerror ):
return "Cannot move '" + src + "' to '" + dst + "' : " + strerror
def cannot_remove_complaint( filename, strerror ):
return "Cannot delete '" + filename + "' : " + strerror
def cannot_copy_complaint( f, dst, strerror ):
return "Cannot copy '" + f + "' to '" + dst + f + "' : " + strerror
def copying_directory_message( src, dest ):
return 'Copying directory ' + src + ' to ' + dest
def finished_copying_directory_message( src, dest ):
return 'Finished copying directory ' + src + ' to ' + dest
def user_specific_script_message( user_pre_script ):
return [
'Pre-actions with script',
' ' + user_pre_script + 'started.'
]
def user_specific_script_success():
return 'finished successfully.'
def user_specific_script_complaint( strerror ):
return [
'Finished UNsuccessfully.',
'User-defined script failed. Abort.',
strerror
]
def ciao_remark():
return [
'Ok, see you later, alligator ;-)',
''
]
def initial_warning( eudor_directory ):
return [
'Quote:',
'',
' Beware of bugs in the above code;',
' I have only proved it correct, not tried it.',
'',
' - Donald Knuth',
'',
'',
'Ok, the Eudora mailbox converter is about to start.',
'In principle, the Eudora directory should be left unchanged...',
'But just in case, are you sure you have made a backup copy of the',
'Eudora directory:',
' ' + eudor_directory,
'',
]
def user_made_backup_prompt():
return 'I have made a backup copy [y/N]: '
def last_chance_to_bail_remark():
return [
"Right, let's rock.",
'Expect lots of output... which is OK.',
'',
'Last chance to bail out.'
]
def last_chance_prompt():
return 'Hit return to continue, control-C to stop: '
def starting_remark():
return [
'',
'Starting.'
]
def copying_special_mailboxes_remarks( maildir ):
return 'Copying Eudora mailboxes (In, Out, Trash) to ' + maildir
def beginning_conversion_remarks( maildir ):
return [
'',
'',
'Beginning conversion of files in ' + maildir
]
def moving_converted_remarks( maildir ):
return 'Moving converted files to original names in ' + maildir
def toc_complaint( f_toc, strerror ):
return "cannot analyse toc file '" + f_toc + "' : " + strerror
def fixing_permissions_remarks( maildir ):
return [
'',
'Fixing file permissions in ' + maildir
]
def aux_file_removal_remarks():
return [
'',
'DONE.',
'',
'Use the following command to analyze conversion problems:',
'',
' (',
' cd $HOME/Mail && for f in `find . -type f -print | sort`; do',
' [ -f $f.E2U_WARN ] && diff -u $f.E2U_ORIG $f',
' [ -f $f.E2U_ERR ] && diff -u $f.E2U_ORIG $f',
' inform',
' done',
' , \ | less -eiMs +/\"^\\@\\@\"',
'',
'You should first convert all *.E2U_ORIG files from DOS to Unix',
"EOL (End-Of-Line) convention, or else you will get lots of diff's.",
"Example: dos2unix \`find \$HOME/Mail -name '*.E2U_ORIG' -print\`",
'',
'After analysis, remove these files with:',
'',
' find $HOME/Mail -type f \\',
" ( -name '*.E2U_*' -o -name '*.toc*' -o ) -exec rm -v '{}' ';'",
'',
'You will also want to remove any directories or files that',
'do not correspond directly to mail folders or mailboxes,',
'or to the attachments directory.',
'',
]
def windows_concluding_remarks():
return [
"Windows Eudora has a file 'dscmap.pci' in each subdirectory.",
'Eudora2Unix uses these files, but you may delete them after ',
'conversion.',
'',
]
def concluding_remarks( target, targetdir ):
return [
"When you're satisfied, move " + targetdir + ".e2u to " + targetdir,
'and fire up ' + target +'. Good luck!',
'',
]
#
# Help functions and aliases.
#
def complain( message ):
if message:
if isinstance( message, types.ListType ):
for line in message[:]:
complain( line )
else:
sys.stderr.write( basename( sys.argv[0] ) + '! ' \
+ message + os.linesep )
def inform( message ):
if message:
if isinstance( message, types.ListType ):
for line in message[:]:
inform( line )
else:
print basename( sys.argv[0] ) + ': ' + message
def exit_msg( msg, maildir = None ):
complaint = [
'A fatal error occurred:',
' ' + msg,
]
if maildir:
complaint.append(
[ 'Aborting; directory ' + maildir + ' (if present)',
'probably has an inconsistent state and should be removed.', ] )
complain( complaint )
sys.exit( 1 )
def eudoaralike( d, isMac ):
if( isMac or re_fol_sfx.match( d ) or re_mbx_sfx.match( d ) ):
looksLikeEudora = 1
def convert_directory( eudoradir, opts ):
"""
GNU/Linux or Unix Mail directory and Eudora directory (arg 1).
Remove a trailing slash (eudoradir/ -> eudoradir) in the latter.
Enforce the Eudora directory to be an absolute path (below).
Relative paths (such as '.') will give problems, because this script
does a few cd's (change directory) and must therefore be able to come
back where it came from.
"""
global isMac
target = 'pine'
targetdir = ''
attachments_dirs = []
for f, v in opts:
if f == '-t':
target = v.strip().lower()
elif f == '-d':
targetdir = v.strip()
elif f == '-a':
attachments_dirs = v.strip().split(':')
if targetdir == '':
if target == 'kmail':
targetdir = 'Mail'
else:
targetdir = 'mail' # works for pine
opts.append( ( '-t', targetdir ) )
print targetdir
if targetdir[0] == '/':
maildir = targetdir
else:
maildir = join( os.environ['HOME'], targetdir + '.e2u' )
if attachments_dirs:
scan_attachment_dirs(attachments_dirs)
maildirLENGTH = len( maildir )
eudoradir = abspath( eudoradir )
if os.path.exists(eudoradir + os.sep + "Embedded"):
global embedded_dir
embedded_dir = eudoradir + os.sep + "Embedded"
if isdir( maildir ):
complain( target_directory_already_exists_complaint( maildir ) )
sys.exit( 1 )
if not os.access( eudoradir, os.R_OK ):
complain( source_directory_not_readable_complaint( eudoradir ) )
sys.exit( 1 )
try:
os.chdir( eudoradir )
inform( entered_directory_remark( eudoradir ) )
except OSError, ( errno, strerror ):
exit_msg( entering_directory_complaint( eudoradir, strerror ),
maildir)
sys.exit( 1 )
isMac = isfile( 'In' )
if ( not isMac and not isfile('In.mbx')
and not isfile('in.mbx')
and not isfile('IN.mbx')
and not isfile('IN.MBX') ):
complain( not_eudora_directory_complaint() )
sys.exit( 1 )
#
# Let's rock.
#
inform( initial_warning( eudoradir ) )
line = raw_input( user_made_backup_prompt() ).lower().strip()
if line != 'y':
inform( ciao_remark() )
sys.exit( 0 )
else:
inform( last_chance_to_bail_remark() )
raw_input( last_chance_prompt() )
inform( starting_remark() )
time.sleep( 1 )
inform( '' )
inform( copying_directory_message( eudoradir, maildir ) )
shutil.copytree( eudoradir, maildir )
inform( finished_copying_directory_message( eudoradir, maildir ) )
# runs ~/bin/eudora2unix-file-renames.sh
execute_user_pre_script( 'bin/eudora2unix-file-renames.sh', maildir )
move_special_mailboxes( target, maildir, isMac )
inform( beginning_conversion_remarks( maildir ) )
walk( maildir, convert_files, opts )
inform( moving_converted_remarks( maildir ) )
if target == 'pine':
to_pine( maildir, isMac )
elif target == 'kmail':
to_kmail( maildir, isMac )
inform( fixing_permissions_remarks( maildir ) )
walk( maildir, fix_file_permissions, 0 )
# Hasta la vista, baby.
inform( aux_file_removal_remarks() )
if not isMac:
inform( windows_concluding_remarks() )
inform( concluding_remarks( target, targetdir ) )
show_attachment_stats()
sys.exit( 0 )
def scan_attachment_dirs(attachments_dirs):
global attachments_not_handled
for adir in attachments_dirs:
fullpaths = [adir + "/" + dirname for dirname in os.listdir(adir)]
attachments_not_handled = attachments_not_handled.union(fullpaths)
def show_attachment_stats():
"""Writes a report on attachment handling to attachlog.txt."""
global attachments_not_handled, attachments_handled_by
common_names = set()
common_names = common_names.union(Eudora2Mbox.found_attachments.keys())
common_names = common_names.union(Eudora2Mbox.missing_attachments.keys())
total_missing = 0
total_attachments_listed = 0
total_attachments_found = 0
attachlog = "attachlog.txt"
print "\nWriting attachment statistics to %s\n" % (attachlog,)
OUT = open ( attachlog, 'w')
try:
for k in common_names:
OUT.write("\n--------------------\n")
OUT.write(k)
OUT.write("\n\n")
if k in Eudora2Mbox.found_attachments:
# OUT.write("\tFound Attachments:\n")
# OUT.write("\t==================\n")
writenewline = False
for (desc, filename) in Eudora2Mbox.found_attachments[k]:
total_attachments_listed = total_attachments_listed + 1
total_attachments_found = total_attachments_found + 1
try:
attachments_not_handled.remove(filename)
attachments_handled_by[filename] = k
except KeyError:
OUT.write("\tAttachment " + filename + " was already used by " + k + "\n")
total_attachments_found = total_attachments_found - 1
writenewline = True
# OUT.write("\t%s -- %s\n" % (desc, filename))
if writenewline:
OUT.write("\n")
if k in Eudora2Mbox.missing_attachments:
OUT.write("\tMissing Attachments:\n")
OUT.write("\t====================\n")
i = 1
for desc in Eudora2Mbox.missing_attachments[k]:
OUT.write("\t%d. %s\n" % (i, desc))
i = i+1
total_missing = total_missing + 1
total_attachments_listed = total_attachments_listed + 1
OUT.write("\n")
OUT.write("\n------------------------------------------------------------------------------------------------------------------------\n")
OUT.write(" Attachment files not used\n\n")
i = 1
for filename in attachments_not_handled:
OUT.write(str(i) + ". " + filename + "\n")
i = i+1
OUT.write("\n\n Total Number of Messages Processed: " + str(Eudora2Mbox.message_count) + "\n")
OUT.write(" Total Number of Attachments Referenced: " + str(total_attachments_listed) + "\n")
OUT.write(" Total Number of Attachments Successfully Found: " + str(total_attachments_found) + "\n")
OUT.write(" Total Count of Attachments Referenced in Email That Are Missing : " + str(total_missing) + "\n")
OUT.write("------------------------------------------------------------------------------------------------------------------------\n")
OUT.write("\n------------------------------------------------------------------------------------------------------------------------\n")
OUT.write(" Mangled Mac Names\n\n")
i = 1
for filename in Eudora2Mbox.mac_mismatches:
OUT.write(str(i) + ". " + filename + "\n")
i = i+1
OUT.write("------------------------------------------------------------------------------------------------------------------------\n")
finally:
OUT.close()
def execute_user_pre_script( local_script_path, maildir ):
""" User-specific pre-actions first. Add your hook here.
Note: script exit code is checked and must be 0, to continue. """
user_pre_script = join( os.environ['HOME'], local_script_path )
if isfile( user_pre_script ):
inform( user_specific_script_message( user_pre_script ) )
try:
os.system( user_pre_script )
inform( user_specific_script_success() )
except OSError, ( errno, strerror ):
complain( user_specific_script_complaint( strerror ) )
rmdir( maildir )
sys.exit( 1 )
def move_special_mailboxes( target, maildir, isMac ):
"""
Copy In, Out and Trash box.
Skip 'drafts' and touch 'outbox'.
Name conversions:
--------- ----------------- ----------------
Eudora * --> Pine KMail
--------- ----------------- ----------------
In.mbx saved-messages ** inbox
Out.mbx sent-mail sent-mail
Trash.mbx *** trash
n/a postponed-msgs outbox (touched)
n/a drafts (skipped)
--------- ----------------- ----------------
* Eudora for the Mac lacks the .mbx suffix
** When used as a POP client, Pine's INBOX is on the server; not a
real file; downloaded messages are in saved-messages
*** Pine doesn't have a trash mailbox--just marks messages for
deletion.
"""
if isMac:
mailbox_suffix = ''
else:
mailbox_suffix = '.mbx'
inTarget = ''
outTarget = ''
trashTarget = ''
if target == 'pine':
inTarget = 'saved-messages'
outTarget = 'sent-mail'
trashTarget = 'trash'
if target == 'kmail':
inTarget = 'inbox'
outTarget = 'sent-mail'
trashTarget = 'trash'
try:
os.chdir( maildir )
except OSError, ( errno, strerror ):
exit_msg( entering_directory_complaint( maildir, strerror ),
maildir)
inform( copying_special_mailboxes_remarks( maildir ) )
move_special_mbox( maildir, inTarget, mailbox_suffix,
[ 'In', 'In.mbx', 'in.mbx', 'IN.mbx', 'IN.MBX' ] )
move_special_mbox( maildir, outTarget, mailbox_suffix,
[ 'Out', 'Out.mbx', 'out.mbx', 'OUT.mbx', 'OUT.MBX' ] )
move_special_mbox( maildir, trashTarget, mailbox_suffix,
[ 'Trash', 'Trash.mbx', 'trash.mbx', 'TRASH.mbx', 'TRASH.MBX' ] )
def move_special_mbox( dir, targetname, suffix, namelist ):
for f in namelist:
fpath = join( dir, f )
if isfile( fpath ):
f_nombx = re_mbx_sfx.sub( '\\1', fpath )
t_nombx = join( dir, targetname )
t_mbx = t_nombx + suffix
moveFile( fpath, t_mbx )
f_toc = f_nombx + '.toc'
t_toc = t_nombx + '.toc'
if isfile( f_toc ):
moveFile( f_toc, t_toc )
def convert_files( avoid_dirlist, dir, names ):
"""
Copy Eudora folders in the top level Eudora directory recursively.
Only copy the mailbox files in those folders.
In the next step, the subfolders and mailboxes will be processed.
Typical Eudora Win directory has lots of files that arent mailboxes
and folders that don't contain mail
For Eudora 5.0,
All mail subfolders are in Subfolders.fol/
Then there's attach/ which contains attachments.
Then the standard mailboxes
In.mbx In.toc Out.mbx Out.toc Test.mbx Test.toc
Trash.mbx Trash.toc
In each directory, there's a database
descmap.pce
that associates DOS filenames with Eudora Mailbox names in Win 3.1,
and associates filenames with .mbx suffix with Mailbox names in other
versions of Windows.
Besides that, we have
Filters/ NNdbase.toc Audit.log History.lst
NNdbase.txt icons/ DoNotDel.tmp
Embedded/ Plugins/
eudora.ini LinkHistory/ RCPdbase.txt uchange.tlx
eudora.log LinkHistory.dat Sigs/ uignore.tlx
EudoraStats.xml lmos.dat spool/ usuggest.tlx
EudPriv/ Nickname/ Stationery/
SW THIS ASSUMES eudoradir DOESN"T END IN SLASH
Process all Eudora mailbox files with the per-mailbox
converter 'Eudora2Mbox.py'.
Rename the Eudora mailbox file to .E2U_ORIG (backup copy).
Move the converted mailbox, e.g. 'myproj.E2U_OUT', to 'myproj' which
will be the unix mbox.
Analyze by diffing with (e.g. diff-ing against the .E2U_ORIG version).
"""
# avoid any directory specified with a '-a' flag
for f, v in opts:
if f == '-a':
attachments_dirs = v.split(':')
for adir in attachments_dirs:
if samefile( dir, adir ):
return
descmap = parse_descmap( dir )
for f in names:
fpath = join( dir, f )
f_targ = join( dir, get_eudora_boxname( f, descmap, isMac ) );
if( isfile( fpath ) and ( isMac or re_mbx_sfx.match( f ) )
and not re_toc_sfx.match( f ) ):
f_nombx = re_mbx_sfx.sub( '\\1', fpath )
f_out = f_nombx + OUT_SFX
f_orig = f_nombx + ORIG_SFX
f_toc = f_nombx + '.toc'
if exists( f_toc ):
try:
# os.spawnlpe( os.P_WAIT, 'etoc', 'etoc',
# f_toc, f_toc + '.txt',
# os.environ )
EudoraTOC.parse( f_toc, isMac, f_toc + '.txt' )
except OSError, ( errno, str ):
complain( toc_complaint( f_toc, str ) )
moveFile( fpath, f_nombx )
global embedded_dir
Eudora2Mbox.convert( f_nombx, embedded_dir, opts )
file1 = f_nombx + ".new"
file2 = f_nombx
print "------Hey, I'm moving %s to %s\n" % (file1, file2)
moveFile( f_nombx + ".new", f_nombx )
if exists( f_nombx + ".toc" ):
removeFile( f_nombx + ".toc" )
removeFile( f_nombx + ".toc.txt" )
print
def parse_descmap( dir ):
"""Eudora Windows mailbox folders have associated 'descmap.pce' file,
which associates a Eudora mailbox name with a Windows filename. In
Windows 95+, the filename just has a '.mbx' added to the mailbox name.
In Windows 3.2-, the filename is 8 characters with '.mbx' suffix.
It has been known to happen that a Windows mailbox name contained
a slash, so such slashes are replaced by Unix-friendly underscores."""
nameMap = {}
fpath = join( dir, 'descmap.pce' )
if isfile( fpath ):
try:
dscfile = open( fpath, 'r' )
for line in dscfile:
desc_toc = line.split( ',' )
nameMap[desc_toc[1]] = string.replace(
desc_toc[0], "/", "_" )
except IOError, ( errno, strerror ):
complain( cannot_open_complaint( fpath, strerror ) )
return nameMap
def get_eudora_boxname( f, nameMap, isMac ):
if not isMac and nameMap:
try:
return nameMap[f]
except KeyError:
pass
return re_mbx_sfx.sub( '\\1', f )
def moveFile( src, dst ):
print 'Moving "%s" to "%s"' % (src, dst)
try:
os.rename( src, dst )
except OSError, ( errno, strerror ):
exit_msg( cannot_move_complaint( src, dst, strerror ) )
def removeFile( filename ):
print 'Removing %s' % filename
try:
os.remove( filename )
except OSError, ( errno, strerror ):
exit_msg( cannot_remove_complaint( filename, strerror ) )
# We now have all Eudora mailboxes (*.mbx with .mbx extension removed)
# properly processed in Eudora folders (*.fol).
re_fol_suffix = re.compile( '(.*?)\.fol$', re.IGNORECASE )
def to_kmail( d, isMac ):
"""
KMail handles folders and subfolders specially.
For a mail folder 'foobar', KMail uses a file 'foobar' and directory
'.foobar.directory' (note the dot) which is the actual container
of the folder contents, as well as a folder named 'foobar'
containing subdirectories 'cur', 'new', and 'tmp'.
"""
descmap = parse_descmap( d )
dirlist = os.listdir( d )
for f in dirlist:
fpath = join( d, f )
if isdir( fpath ) and ( isMac or re_fol_sfx.match( fpath ) ):
boxname = get_eudora_boxname( f, descmap, isMac )
f_targ = '.' + boxname + '.directory'
f_targ = join( d, f_targ )
to_kmail( fpath, isMac )
moveFile( fpath, f_targ ) # rename on way back up
print "in to_kmail" , fpath, f_targ
box = join( d, boxname )
os.mkdir( box )
os.mkdir( join( box, 'cur' ) )
os.mkdir( join( box, 'new' ) )
os.mkdir( join( box, 'tmp' ) )
def to_pine( d, isMac ):
"""Removes '.fol' suffix from Eudora Windows folders"""
if isMac:
return;
descmap = parse_descmap( d )
dirlist = os.listdir( d )
for f in dirlist:
fpath = join( d, f )
if isdir( fpath ) and re_fol_sfx.match( fpath ):
f_targ = get_eudora_boxname( f, descmap, isMac )
f_targ = join( d, f_targ )
to_pine( fpath, isMac )
moveFile( fpath, f_targ ) # rename on way back up
def fix_file_permissions( arg, dir, names ):
"""Fix permissions (your eyes only). """
for f in names:
fpath = join( dir, f )
if isfile( fpath ):
os.chmod( fpath, 0600 )
elif isdir( f ):
os.chmod( fpath, 0700 )
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('source_directory', help='Eudora directory to be converted')
parser.add_argument('-a', required=True, metavar='attach_dir', help='attachments directory')
parser.add_argument('-f', help='mailbox format', type=str, choices=('mbox','maildir','mmdf','mh','babyl'))
parser.add_argument('-d', metavar='target_dir', help='target directory')
parser.add_argument('-t', help='target client', type=str, choices=('kmail', 'pine'))
command_line_args = parser.parse_args()
eudoradir = command_line_args.source_directory
del command_line_args.source_directory
opts = [ ('-'+k, v) for k,v in vars(command_line_args).items() if v != None] # hack to convert to a getopts-style list
convert_directory( eudoradir, opts )