Moving to GitHub.
[platal.git] / bin / lists.mhonarc_by_month.pl
CommitLineData
0337d704 1#! /bin/perl -w
2#
3use strict;
4################################################################################
5# the RCFILE is the first arg
6#
7my $rcfile = shift;
8#
9################################################################################
10# the list prefix is the second one
11#
12my $list = shift;
13#
14################################################################################
15# CONSTANTS
7a5e6559 16#
0337d704 17my $spool = "/var/spool/platal/archives/";
18my $tmpbox = "mytmpbox.mbox";
19
20my %conv;
21$conv{'Jan'} = "01";
22$conv{'Feb'} = "02";
23$conv{'Mar'} = "03";
24$conv{'Apr'} = "04";
25$conv{'May'} = "05";
26$conv{'Jun'} = "06";
27$conv{'Jul'} = "07";
28$conv{'Aug'} = "08";
29$conv{'Sep'} = "09";
30$conv{'Oct'} = "10";
31$conv{'Nov'} = "11";
32$conv{'Dec'} = "12";
33#
34################################################################################
35# local vars
36#
37my $mail = "";
38my $line = "";
39my $odir = "";
40
41my $y = '';
42my $m = '';
43#
44################################################################################
45
46while(<>) {
47 $line = $_;
48
49 ##
50 ## Do we start a new mail ?
51 ##
52 if($line =~ /^From +[^@ ]*@[^@ ]* +[a-z]* +([a-z]*) +\d* +\d*:\d*:\d* +(\d*)$/i) {
53 if ($conv{$1} ne $m || $y ne $2) {
54 if($odir) {
55 ##
56 ## If we are here, then we just finished a month.
57 ## -> we close the file, and exec mhonarc on the stuff
58 ##
59 close FILE;
60 $odir = $spool.$list."/$y/$m";
61 system("mkdir -p $odir") unless (-d $odir);
62 system("mhonarc -add -outdir $odir -rcfile $rcfile $tmpbox");
63 } else {
64 # dummy init
65 $odir = 1;
66 }
7a5e6559 67
0337d704 68 $m = $conv{$1};
69 $y = $2;
70 open FILE,"> $tmpbox";
71 }
72 }
7a5e6559 73
0337d704 74 print FILE $line;
75}
76
77if($odir) {
78 close FILE;
79 unlink $tmpbox;
80}