source: ProjectBuilder/projects/md2mb/devel/md2mb/bin/md2mb.pl@ 1141

Last change on this file since 1141 was 1141, checked in by Bruno Cornec, 13 years ago
File size: 2.7 KB
Line 
1#!/usr/bin/perl -w
2#
3# Program to import a maildir kmail environement into a thunderbird one.
4
5use strict;
6use File::Find;
7use File::Copy;
8use File::Basename;
9use File::Path;
10
11my $cmd="formail";
12# CHANGE AS YOU WISH
13my $oldroot = "/users/beatrice/.Mail.sav";
14my $newroot = "/users/beatrice/.thunderbird/30cq2rn3.default/Mail/Local Folders/";
15# Is the newroot a file (1) or a dir (0)
16my $nrisfile = 0;
17my $debug = 0;
18# END CHANGE
19
20$debug++ if ((defined $ARGV[0]) && ($ARGV[0] eq "-v"));
21print "DEBUG MODE, not doing anything, just printing\n" if ($debug);
22if ($debug) {
23 print "CMD1: mkdir -p $newroot\n" if ((not -d "$newroot") && (not $nrisfile));
24} else {
25 mkpath("$newroot",0, 0755) if ((not -d "$newroot") && (not $nrisfile));
26}
27system("$cmd </dev/null >/dev/null 2>/dev/null") == 0 or die "cannot find formail on your \$PATH!\nAborting";
28
29find(\&md2mb,($oldroot));
30
31sub md2mb {
32
33if (-f $File::Find::name) {
34 return if (
35 ($File::Find::name =~ /\.ids$/) ||
36 ($File::Find::name =~ /\.sorted$/) ||
37 ($File::Find::name =~ /\.index$/) ||
38 ($File::Find::name =~ /\/cur\//) ||
39 ($File::Find::name =~ /\/new\//) ||
40 ($File::Find::name =~ /\/tmp\//));
41}
42if (-d $File::Find::name) {
43 return if (
44 ($File::Find::name =~ /\/cur$/) ||
45 ($File::Find::name =~ /\/new$/) ||
46 ($File::Find::name =~ /\/tmp$/));
47}
48if ($debug) {
49 print "CURR: $File::Find::name\n";
50}
51my $destname = $File::Find::name;
52$destname =~ s|^$oldroot||;
53$destname =~ s|\.([[:alnum:]éèçàù\s]*)\.directory|$1.sbd|g;
54if ($debug) {
55 print "DEST: $destname\n";
56}
57my $cdir = dirname("$newroot/$destname");
58my $outputfile="$newroot/$destname";
59$outputfile="$newroot" if ($destname =~ /^\s*$/);
60if (-d $File::Find::name) {
61 my @files = (<"$File::Find::name"/cur/*>,<"$File::Find::name"/new/*>);
62 if (@files) {
63 if ($debug) {
64 print "CMD2: mkdir -p $cdir\n" if (not -d "$cdir");
65 } else {
66 mkpath("$cdir",0, 0755) if (not -d "$cdir");
67 }
68 }
69 foreach my $file (@files) {
70 next unless -f $file; # skip non-regular files
71 next unless -s $file; # skip empty files
72 next unless -r $file; # skip unreadable files
73 $file =~ s/'/'"'"'/; # escape ' (single quote)
74 # NOTE! The output file must not contain single quotes (')!
75 my $run = "cat '$file' | $cmd >> '$outputfile'";
76 if ($debug) {
77 print "CMD3: $run\n";
78 } else {
79 print "Copying maildir content from $File::Find::name to $outputfile\n";
80 system($run) == 0 or warn "cannot run \"$run\".";
81 }
82 }
83}
84if (-f $File::Find::name) {
85 if ($debug) {
86 print "CMD2: mkdir -p $cdir\n" if (not -d "$cdir");
87 print "CMD3: cp $File::Find::name $cdir\n";
88 } else {
89 mkpath("$cdir",0, 0755) if (not -d "$cdir");
90 copy($File::Find::name,$cdir);
91 print "Copying mailbox content from $File::Find::name to $outputfile\n";
92 }
93}
94}
Note: See TracBrowser for help on using the repository browser.