Changeset 1389 in ProjectBuilder for projects/md2mb
- Timestamp:
- Jan 7, 2012, 9:20:20 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
projects/md2mb/devel/md2mb/bin/md2mb.pl
r1328 r1389 8 8 use File::Basename; 9 9 use File::Path; 10 use File::Glob ':glob'; 10 11 11 12 my $cmd="formail"; 12 13 # CHANGE AS YOU WISH 13 14 my $oldroot = "/users/segolene/.Mail"; 14 my $newroot = "/users/segolene/.thunderbird/60q6hqwp.default/Mail/ Local Folders/";15 my $newroot = "/users/segolene/.thunderbird/60q6hqwp.default/Mail/pop.home.musique-ancienne.org/"; 15 16 # Is the newroot a file (1) or a dir (0) 16 17 my $nrisfile = 0; … … 21 22 print "DEBUG MODE, not doing anything, just printing\n" if ($debug); 22 23 if ($debug) { 23 print "CMD1: mkdir -p $newroot\n" if ((not -d "$newroot") && (not $nrisfile)); 24 print "TARGET DIR: mkdir -p $newroot\n" if ((not -d "$newroot") && (not $nrisfile)); 25 print "CMD: mkdir -p $newroot\n" if ((not -d "$newroot") && (not $nrisfile)); 24 26 } else { 25 27 mkpath("$newroot",0, 0755) if ((not -d "$newroot") && (not $nrisfile)); … … 32 34 33 35 if (-f $File::Find::name) { 34 return if ( 35 ($File::Find::name =~ /\.ids$/) || 36 if (($File::Find::name =~ /\.ids$/) || 36 37 ($File::Find::name =~ /\.sorted$/) || 37 ($File::Find::name =~ /\.index$/) ||38 ($File::Find::name =~ /\/cur\//) ||39 ($File::Find::name =~ /\/new\//) ||40 ($File::Find::name =~ /\/tmp\//));38 ($File::Find::name =~ /\.index$/)) { 39 print "SKIP FILE: $File::Find::name\n" if ($debug); 40 return; 41 } 41 42 } 42 43 if (-d $File::Find::name) { 43 return if ( 44 ($File::Find::name =~ /\/cur$/) || 44 if (($File::Find::name =~ /\/cur$/) || 45 45 ($File::Find::name =~ /\/new$/) || 46 ($File::Find::name =~ /\/tmp$/)) ;47 } 48 if ($debug) { 49 print "CURR: $File::Find::name\n";46 ($File::Find::name =~ /\/tmp$/)) { 47 print "SKIP DIR: $File::Find::name\n" if ($debug); 48 return; 49 } 50 50 } 51 51 my $destname = $File::Find::name; 52 # Target name is under a different root dir 52 53 $destname =~ s|^$oldroot||; 54 # Target name is not under a .directory dir but under a .sdb one 53 55 $destname =~ s|\.([[:alnum:]éèçàù\s]*)\.directory|$1.sbd|g; 54 if ($debug) { 55 print "DEST: $destname\n"; 56 } 56 # Here we create the target dir and target name 57 57 my $cdir = dirname("$newroot/$destname"); 58 58 my $outputfile="$newroot/$destname"; 59 # Handle case where target file name is empty 59 60 $outputfile="$newroot" if ($destname =~ /^\s*$/); 61 # When we treat a dir, we will have to handle what it has below 60 62 if (-d $File::Find::name) { 61 63 if ($debug) { 62 print " HANDLING: $File::Find::name content\n";64 print "DIR SRC: $File::Find::name\n"; 63 65 } 64 my @files = ( <"$File::Find::name"/cur/*>,<"$File::Find::name"/new/*>);66 my @files = (bsd_glob("$File::Find::name/cur/*"),bsd_glob("$File::Find::name/new/*")); 65 67 if (@files) { 66 68 if ($debug) { 67 print " CMD2: mkdir -p $cdir\n" if (not -d "$cdir");69 print "DIR ($File::Find::name) DIR TARGET: mkdir -p $cdir\n" if (not -d "$cdir"); 68 70 } else { 69 71 mkpath("$cdir",0, 0755) if (not -d "$cdir"); … … 74 76 next unless -s $file; # skip empty files 75 77 next unless -r $file; # skip unreadable files 76 $file =~ s/'/'"'"'/ ; # escape ' (single quote)78 $file =~ s/'/'"'"'/g; # escape ' (single quote) 77 79 # NOTE! The output file must not contain single quotes (')! 78 80 my $run = "cat '$file' | $cmd >> '$outputfile'"; 79 81 if ($debug) { 80 print "CMD3: $run\n"; 82 print "COPYING CONTENT maildir($file) to $outputfile\n"; 83 print "CMD: $run\n"; 81 84 } else { 82 print "Copying maildir content from $ File::Find::name to $outputfile\n";85 print "Copying maildir content from $file to $outputfile\n"; 83 86 system($run) == 0 or warn "cannot run \"$run\"."; 84 87 } … … 86 89 } 87 90 if (-f $File::Find::name) { 91 if (($File::Find::name =~ /\/cur\//) || 92 ($File::Find::name =~ /\/new\//) || 93 ($File::Find::name =~ /\/tmp\//)) { 94 print "SKIP FILE: $File::Find::name\n" if ($debug); 95 return; 96 } 88 97 if ($debug) { 89 print " CMD2: mkdir -p $cdir\n" if (not -d "$cdir");90 print "CMD 3: cp $File::Find::name $cdir\n";98 print "FILE ($File::Find::name) TARGET DIR: mkdir -p $cdir\n" if (not -d "$cdir"); 99 print "CMD: cp $File::Find::name $cdir\n"; 91 100 } else { 101 print "Copying mailbox content from $File::Find::name to $cdir\n"; 92 102 mkpath("$cdir",0, 0755) if (not -d "$cdir"); 93 103 copy($File::Find::name,$cdir); 94 print "Copying mailbox content from $File::Find::name to $outputfile\n";95 104 } 96 105 }
Note:
See TracChangeset
for help on using the changeset viewer.