fix text-selection for replying
[claws.git] / tools / convert_mbox.pl
1 #!/usr/bin/perl
2 # convert_mbox.pl
3 # perl script to convert mbox file to files in a new MH directory
4 # aka another mbox -> MH conversion tool
5 # 29 April 2003  
6 # Fred Marton <Fred.Marton@uni-bayreuth.de>
7 #
8 # Note: Running this with the -w flag generates the following warnings:
9 # Scalar value @word[1] better written as $word[1] at /path/to/convert_mbox.pl line 54
10 # Scalar value @word[0] better written as $word[1] at /path/to/convert_mbox.pl line 56
11 # Making these changes requires further changes in the script
12 # that results in much longer run-times.  
13 #
14 # Copyright © 2003 Fred Marton
15
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation; either version 2
19 # of the License, or (at your option) any later version.
20
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 # 02111-1307, USA.
30
31 # check for both arguments
32 &usage if ($#ARGV < 1);
33 $mbox =  $ARGV[0];
34 $mh = $ARGV[1];
35 # check to make sure there isn't something named MH already
36 if (-e $mh) {
37    die (" The directory \"$mh\" already exists.  Exiting.\n");
38 }
39 else {
40    mkdir $mh;
41 }
42 # start numbering
43 $i = 0;
44 # open the mbox file
45 open (IN, $mbox);
46 while ($line = <IN>) {
47 # check for the beginning of an e-mail
48    @word = split(/ +/m,$line);
49 # some lines might start with "From ", so check
50 # to see if the seventh word is a year
51    chomp($word[6]);
52    $year = $word[6];
53 # ignore the MAILER-DAEMON message from pine
54    if (@word[1] ne "MAILER-DAEMON") {
55 # start a new file, assuming $year is > 1970
56       if (@word[0] eq "From" && $year > 1970) {
57          $i++;
58          close (OUT);
59          open (OUT, ">$mh/$i");
60          print OUT $line;
61       }
62       else {
63 # continue the file
64          print OUT $line;
65       }
66    }
67 }
68 close (OUT);
69 close (IN);
70 # and we're done
71 print "\n If it isn't there already, please move the directory \"$mh\"\n"
72     . " into your MH directory and rebuild your folder tree.\n\n";
73
74 sub usage
75 {
76    die ( " usage: convert_mbox.pl MBOX MH_DIR\n");
77 }