Changeset 1389 in ProjectBuilder for projects/md2mb/devel/md2mb/bin/md2mb.pl


Ignore:
Timestamp:
Jan 7, 2012, 9:20:20 PM (12 years ago)
Author:
Bruno Cornec
Message:
  • Fix problems with md2mb by using bsd_glob to avoid space issues.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • projects/md2mb/devel/md2mb/bin/md2mb.pl

    r1328 r1389  
    88use File::Basename;
    99use File::Path;
     10use File::Glob ':glob';
    1011
    1112my $cmd="formail";
    1213# CHANGE AS YOU WISH
    1314my $oldroot = "/users/segolene/.Mail";
    14 my $newroot = "/users/segolene/.thunderbird/60q6hqwp.default/Mail/Local Folders/";
     15my $newroot = "/users/segolene/.thunderbird/60q6hqwp.default/Mail/pop.home.musique-ancienne.org/";
    1516# Is the newroot a file (1) or a dir (0)
    1617my $nrisfile = 0;
     
    2122print "DEBUG MODE, not doing anything, just printing\n" if ($debug);
    2223if ($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));
    2426} else {
    2527    mkpath("$newroot",0, 0755) if ((not -d "$newroot") && (not $nrisfile));
     
    3234
    3335if (-f $File::Find::name) {
    34     return if (
    35         ($File::Find::name =~ /\.ids$/) ||
     36    if (($File::Find::name =~ /\.ids$/) ||
    3637        ($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    }
    4142}
    4243if (-d $File::Find::name) {
    43     return if (
    44         ($File::Find::name =~ /\/cur$/) ||
     44    if (($File::Find::name =~ /\/cur$/) ||
    4545        ($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    }
    5050}
    5151my $destname = $File::Find::name;
     52# Target name is under a different root dir
    5253$destname =~ s|^$oldroot||;
     54# Target name is not under a .directory dir but under a .sdb one
    5355$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
    5757my $cdir = dirname("$newroot/$destname");
    5858my $outputfile="$newroot/$destname";
     59# Handle case where target file name is empty
    5960$outputfile="$newroot" if ($destname =~ /^\s*$/);
     61# When we treat a dir, we will have to handle what it has below
    6062if (-d $File::Find::name) {
    6163    if ($debug) {
    62         print "HANDLING: $File::Find::name content\n";
     64        print "DIR SRC: $File::Find::name\n";
    6365    }
    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/*"));
    6567    if (@files) {
    6668        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");
    6870        } else {
    6971            mkpath("$cdir",0, 0755) if (not -d "$cdir");
     
    7476        next unless -s $file; # skip empty files
    7577        next unless -r $file; # skip unreadable files
    76         $file =~ s/'/'"'"'/;  # escape ' (single quote)
     78        $file =~ s/'/'"'"'/g;  # escape ' (single quote)
    7779        # NOTE! The output file must not contain single quotes (')!
    7880        my $run = "cat '$file' | $cmd >> '$outputfile'";
    7981        if ($debug) {
    80             print "CMD3: $run\n";
     82            print "COPYING CONTENT maildir($file) to $outputfile\n";
     83            print "CMD: $run\n";
    8184        } else {
    82             print "Copying maildir content from $File::Find::name to $outputfile\n";
     85            print "Copying maildir content from $file to $outputfile\n";
    8386            system($run) == 0 or warn "cannot run \"$run\".";
    8487        }
     
    8689}
    8790if (-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    }
    8897    if ($debug) {
    89         print "CMD2: mkdir -p $cdir\n" if (not -d "$cdir");
    90         print "CMD3: 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";
    91100    } else {
     101        print "Copying mailbox content from $File::Find::name to $cdir\n";
    92102        mkpath("$cdir",0, 0755) if (not -d "$cdir");
    93103        copy($File::Find::name,$cdir);
    94         print "Copying mailbox content from $File::Find::name to $outputfile\n";
    95104    }
    96105}
Note: See TracChangeset for help on using the changeset viewer.