3 #=======================================================================
5 # File ID: 953fa428-5d39-11df-8ca0-90e6ba3022ac
6 # Extracts messages from a mailbox into separate files
7 # ©opyleft 2002 Øyvind A. Holm <sunny@sunbase.org>
8 # License: GNU General Public License version 2 or later.
9 #=======================================================================
35 -d
$dest_dir || mkdir($dest_dir, 0777) || die("mkdir($dest_dir): $!");
42 ($Date =~ /^\d{8}T\d{6}$/) || die("Line $.: Invalid date format: \"$Date\"");
43 my $file_name = "$dest_dir/mail.${Date}$TZ_ext.txt";
44 -e
$file_name && (warn("$file_name: File already exists"), $Date .= "b");
45 open(ToFP
, ">$file_name") || die("$file_name: Opening for write: $!");
51 warn("Datoen var tom");
54 ($Date, $date_done, $TZ_ext) = ("", 0, "");
58 if (/^Date: / && !$date_done) {
60 /^\D
* # Before the date
76 my ($Year, $Mon, $Day, $Hour, $Min, $Sec, $Timezone) = ($3, $2, $1, $4, $5, $6, "");
77 (defined($7) && ($Timezone = $7)) || warn("Line $.: Date missing time zone");
79 D
("Day = \"$Day\", Mon = \"$Mon\"\n");
80 defined($mon_str{$Mon}) || (die("Unknown month: \"$Mon\""), ($Mon = "XX"));
81 $Mon = $mon_str{$Mon};
82 my $curr_date = timelocal
($Sec, $Min, $Hour, $Day, $Mon-1, $Year);
84 if ($Timezone =~ /^(\+|-)(\d\d)(\d\d)$/) {
85 $zone_diff = $2*3600 + $3*60;
86 ($1 eq "+") && ($zone_diff = 0-$zone_diff);
87 } elsif ($Timezone =~ /^GMT$/i) {
90 warn("Line $.: Unknown timezone format");
93 D
("curr_date before tz: \"$curr_date\", Timezone = \"$Timezone\"\n");
94 $zone_diff = 0; # Temporary until the timezone problems are eliminated.
95 $curr_date += $zone_diff;
96 D
("curr_date after tz : \"$curr_date\", Timezone = \"$Timezone\"\n");
97 D
("zone_diff = \"$zone_diff\"\n");
98 ($Sec, $Min, $Hour, $Day, $Mon, $Year) = gmtime($curr_date);
100 $Mon = sprintf("%02u", $Mon+1); # Urgh II
101 $Day = sprintf("%02u", $Day);
102 $Hour = sprintf("%02u", $Hour);
103 $Min = sprintf("%02u", $Min);
104 $Sec = sprintf("%02u", $Sec);
105 $Date = "$Year$Mon${Day}T$Hour$Min$Sec";
108 warn("Line $.: Weird date: \"$Date\"");
121 This program is free software; you can redistribute it and/or modify it
122 under the terms of the GNU General Public License as published by the
123 Free Software Foundation; either version 2 of the License, or (at your
124 option) any later version.
126 This program is distributed in the hope that it will be useful, but
127 WITHOUT ANY WARRANTY; without even the implied warranty of
128 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
129 See the GNU General Public License for more details.
131 You should have received a copy of the GNU General Public License along
132 with this program; if not, write to the Free Software Foundation, Inc.,
133 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
137 #### End of file extract_mail ####