Changeset 1449


Ignore:
Timestamp:
04/04/12 17:14:49 (14 months ago)
Author:
ebaudrez
Message:

do not hardcode $newroot

$newroot is composed of two elements: the Thunderbird profile, and a
directory inside this profile. Both can be specified on the command
line, but the profile will be determined automatically if possible. Note
that this commit also fixes a bug in the command-line handling of
$oldroot and $profile (oops!).

File:
1 edited

Legend:

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

    r1448 r1449  
    2626Aborting 
    2727EOF 
    28 my $oldroot = first { -d } "$ENV{HOME}/.Mail", "$ENV{HOME}/Mail"; 
    2928# CHANGE AS YOU WISH 
    30 my $newroot = "/users/segolene/.thunderbird/qk2f4dl6.default/Mail/pop.home.musique-ancienne.org/"; 
    3129# Is the newroot a file (1) or a dir (0) 
    3230my $nrisfile = 0; 
     
    3533my $help = 0; 
    3634my $man = 0; 
     35my $oldroot = first { -d } "$ENV{HOME}/.Mail", "$ENV{HOME}/Mail"; 
     36my @default_profiles = bsd_glob("$ENV{HOME}/.thunderbird/*.default"); 
     37my $profile = shift @default_profiles; 
     38# if there is more than one default profile (quite unlikely, but you never 
     39# know), unset $profile again and let the user resolve this 
     40if (@default_profiles) { undef $profile } 
     41my $subdir; 
    3742 
    3843# parse command-line options 
    3944GetOptions( 
    40     'debug|d'       => \$debug, 
    41     'help|h'        => \$help, 
    42     'man|m'         => \$man, 
    43     'oldroot|old|o' => \$oldroot, 
     45    'debug|d'         => \$debug, 
     46    'help|h'          => \$help, 
     47    'man|m'           => \$man, 
     48    'oldroot|old|o=s' => \$oldroot, 
     49    'profile|p=s'     => \$profile, 
     50    'subdir|s=s'      => \$subdir, 
    4451) or pod2usage(2); 
    4552pod2usage(1) if ($help); 
    4653pod2usage(-exitstatus => 0, -verbose => 2) if ($man); 
     54defined $subdir or pod2usage("Error: -subdir is a mandatory argument\n"); 
     55 
     56# the new root is constructed from the profile and the chosen subdirectory name 
     57my $newroot = "$profile/$subdir"; 
    4758 
    4859# debug mode overview 
     
    5364cmd     = $cmd 
    5465oldroot = $oldroot 
    55 newroot = $newroot 
     66profile = $profile 
     67subdir  = $subdir 
     68newroot = $newroot (constructed) 
    5669--- end --- 
    5770EOF 
     
    6073# some sanity checks before proceeding 
    6174-d $oldroot or die "cannot find mailbox root `$oldroot'"; 
     75-d $profile or die "cannot find Thunderbird profile directory `$profile'"; 
    6276 
    6377# create destination path 
     
    163177=head1 SYNOPSIS 
    164178 
    165 md2mb.pl  [options] 
     179md2mb.pl  [options]  -s name 
    166180 
    167181 Options: 
     
    170184   -man     | -m        full documentation 
    171185   -oldroot | -old | -o     location of the KMail mailboxes 
     186   -profile | -p        path to the Thunderbird profile to install to 
     187   -subdir  | -s        subdir that will be created to hold the 
     188                imported mails 
    172189 
    173190=head1 OPTIONS 
     
    188205Prints the manual page and exits. 
    189206 
    190 =item B<-oldroot> 
     207=item B<-oldroot> I<path> 
    191208 
    192209Specify where your B<KMail> mailboxes are to be found. By default assumes a 
     
    194211exists. 
    195212 
     213=item B<-profile> I<path> 
     214 
     215Specify the path to the Thunderbird profile. Your imported mails will go inside 
     216a directory in this profile. By default uses the default profile in the 
     217F<.thunderbird> directory in your home directory, if it is unique. 
     218 
     219=item B<-subdir> I<name> 
     220 
     221Specify the subdirectory I<name> that will be created inside the Thunderbird 
     222profile to hold the imported mails. This option is mandatory; there is no 
     223default. 
     224 
    196225=back 
     226 
     227=head1 EXAMPLES 
     228 
     229    # this will fetch all mails from the folder .Mail or Mail in your home 
     230    # directory, and import them into your default Thunderbird profile, in 
     231    # a directory called Mail/pop.home.musique-ancienne.org/ 
     232    # 
     233    # usually, this is all you need to specify: 
     234 
     235    perl md2mb.pl -s Mail/pop.home.musique-ancienne.org/ 
     236 
     237    # on your computer, the mails may end up in 
     238    # /users/segolene/.thunderbird/qk2f4dl6.default/Mail/pop.home.musique-ancienne.org/ 
     239 
     240    # if md2mb.pl cannot figure out where your default Thunderbird profile 
     241    # is, use the following: 
     242 
     243    perl md2mb.pl -p ~/.thunderbird/qk2f4dl6.default -s Mail/pop.home.musique-ancienne.org/ 
    197244 
    198245=head1 DESCRIPTION 
     
    206253incorrect, you need to specify the correct folder with B<-oldroot>. 
    207254 
     255The mails will be imported into the Thunderbird profile that is either 
     256specified with B<-profile> or determined automatically. The script will try to 
     257determine the default Thunderbird profile automatically. If there is a folder 
     258that ends in F<.default> in the F<.thunderbird> directory in your home dir, and 
     259if it is unique, that one will be used. 
     260 
     261The mails finally end up in a subdirectory below the profile. You must specify 
     262the subdirectory on the command line with B<-subdir>, as shown in the examples 
     263above. 
     264 
    208265=head1 AUTHOR 
    209266 
Note: See TracChangeset for help on using the changeset viewer.