3 # perl script to convert mbox file to files in a new MH directory
4 # aka another mbox -> MH conversion tool
6 # Fred Marton <Fred.Marton@uni-bayreuth.de>
8 # Fixed (hopefully) to account for From lines
9 # that are of various length and that might have
10 # time zone info at the end
13 # Note: Running this with the -w flag generates the following warnings:
14 # Scalar value @word[1] better written as $word[1] at /path/to/convert_mbox.pl line 54
15 # Scalar value @word[0] better written as $word[1] at /path/to/convert_mbox.pl line 56
16 # Making these changes requires further changes in the script
17 # that results in much longer run-times.
19 # Copyright © 2003 Fred Marton
21 # This program is free software; you can redistribute it and/or
22 # modify it under the terms of the GNU General Public License
23 # as published by the Free Software Foundation; either version 2
24 # of the License, or (at your option) any later version.
26 # This program is distributed in the hope that it will be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 # GNU General Public License for more details.
31 # You should have received a copy of the GNU General Public License
32 # along with this program; if not, write to the Free Software
33 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
36 # check for both arguments
37 &usage if ($#ARGV < 1);
40 # check to make sure there isn't something named MH already
42 die (" The directory \"$mh\" already exists. Exiting.\n");
51 while ($line = <IN>) {
52 # check for the beginning of an e-mail
53 @word = split(/ +/m,$line);
54 # some lines might start with "From ", so check
55 # to see if the [second-to-]last word is a year
56 @word2 = split(/:/,$line);
57 chomp($word2[$#word2]);
58 @word3 = split(/ /,$word2[2]);
60 # ignore the MAILER-DAEMON message from pine
61 if (@word[1] ne "MAILER-DAEMON") {
62 # start a new file, assuming $year is > 1970
63 if (@word[0] eq "From" && $year > 1970) {
66 open (OUT, ">$mh/$i");
78 print "\n If it isn't there already, please move the directory \"$mh\"\n"
79 . " into your MH directory and rebuild your folder tree.\n\n";
83 die ( " usage: convert_mbox.pl MBOX MH_DIR\n");