2006-08-01 [wwp] 2.4.0cvs10
[claws.git] / tools / convert_mbox.pl
index fa1e8eef71ee69616856943b5a317abbe6d6f25a..d7757c091dd1ea41556f279e59f355f0f065b284 100644 (file)
@@ -4,10 +4,15 @@
 # aka another mbox -> MH conversion tool
 # 29 April 2003  
 # Fred Marton <Fred.Marton@uni-bayreuth.de>
+# 
+# Fixed (hopefully) to account for From lines
+# that are of various length and that might have
+# time zone info at the end
+# 20 January 2004
 #
 # Note: Running this with the -w flag generates the following warnings:
-# Scalar value @word[1] better written as $word[1] at /path/to/convert_mbox.pl line 44
-# Scalar value @word[0] better written as $word[1] at /path/to/convert_mbox.pl line 46
+# Scalar value @word[1] better written as $word[1] at /path/to/convert_mbox.pl line 54
+# Scalar value @word[0] better written as $word[1] at /path/to/convert_mbox.pl line 56
 # Making these changes requires further changes in the script
 # that results in much longer run-times.  
 #
@@ -30,7 +35,7 @@
 
 # check for both arguments
 &usage if ($#ARGV < 1);
-$mbox =  $ARGV[0];
+$mbox = $ARGV[0];
 $mh = $ARGV[1];
 # check to make sure there isn't something named MH already
 if (-e $mh) {
@@ -45,11 +50,17 @@ $i = 0;
 open (IN, $mbox);
 while ($line = <IN>) {
 # check for the beginning of an e-mail
-   @word = split(/ /m,$line);
+   @word = split(/ +/m,$line);
+# some lines might start with "From ", so check
+# to see if the [second-to-]last word is a year
+   @word2 = split(/:/,$line);
+   chomp($word2[$#word2]);
+   @word3 = split(/ /,$word2[2]);
+   $year = @word3[1];
 # ignore the MAILER-DAEMON message from pine
    if (@word[1] ne "MAILER-DAEMON") {
-# start a new file
-      if (@word[0] eq "From") {
+# start a new file, assuming $year is > 1970
+      if (@word[0] eq "From" && $year > 1970) {
          $i++;
          close (OUT);
          open (OUT, ">$mh/$i");