[1141] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # Program to import a maildir kmail environement into a thunderbird one.
|
---|
| 4 |
|
---|
| 5 | use strict;
|
---|
| 6 | use File::Find;
|
---|
| 7 | use File::Copy;
|
---|
| 8 | use File::Basename;
|
---|
| 9 | use File::Path;
|
---|
| 10 |
|
---|
| 11 | my $cmd="formail";
|
---|
| 12 | # CHANGE AS YOU WISH
|
---|
| 13 | my $oldroot = "/users/beatrice/.Mail.sav";
|
---|
| 14 | my $newroot = "/users/beatrice/.thunderbird/30cq2rn3.default/Mail/Local Folders/";
|
---|
| 15 | # Is the newroot a file (1) or a dir (0)
|
---|
| 16 | my $nrisfile = 0;
|
---|
| 17 | my $debug = 0;
|
---|
| 18 | # END CHANGE
|
---|
| 19 |
|
---|
| 20 | $debug++ if ((defined $ARGV[0]) && ($ARGV[0] eq "-v"));
|
---|
| 21 | print "DEBUG MODE, not doing anything, just printing\n" if ($debug);
|
---|
| 22 | if ($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 | }
|
---|
| 27 | system("$cmd </dev/null >/dev/null 2>/dev/null") == 0 or die "cannot find formail on your \$PATH!\nAborting";
|
---|
| 28 |
|
---|
| 29 | find(\&md2mb,($oldroot));
|
---|
| 30 |
|
---|
| 31 | sub md2mb {
|
---|
| 32 |
|
---|
| 33 | if (-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 | }
|
---|
| 42 | if (-d $File::Find::name) {
|
---|
| 43 | return if (
|
---|
| 44 | ($File::Find::name =~ /\/cur$/) ||
|
---|
| 45 | ($File::Find::name =~ /\/new$/) ||
|
---|
| 46 | ($File::Find::name =~ /\/tmp$/));
|
---|
| 47 | }
|
---|
| 48 | if ($debug) {
|
---|
| 49 | print "CURR: $File::Find::name\n";
|
---|
| 50 | }
|
---|
| 51 | my $destname = $File::Find::name;
|
---|
| 52 | $destname =~ s|^$oldroot||;
|
---|
| 53 | $destname =~ s|\.([[:alnum:]éèçàù\s]*)\.directory|$1.sbd|g;
|
---|
| 54 | if ($debug) {
|
---|
| 55 | print "DEST: $destname\n";
|
---|
| 56 | }
|
---|
| 57 | my $cdir = dirname("$newroot/$destname");
|
---|
| 58 | my $outputfile="$newroot/$destname";
|
---|
| 59 | $outputfile="$newroot" if ($destname =~ /^\s*$/);
|
---|
| 60 | if (-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 | }
|
---|
| 84 | if (-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 | }
|
---|