Moving to GitHub.
[platal.git] / bin / lists.mhonarc_by_month.pl
1 #! /bin/perl -w
2 #
3 use strict;
4 ################################################################################
5 # the RCFILE is the first arg
6 #
7 my $rcfile = shift;
8 #
9 ################################################################################
10 # the list prefix is the second one
11 #
12 my $list = shift;
13 #
14 ################################################################################
15 # CONSTANTS
16 #
17 my $spool = "/var/spool/platal/archives/";
18 my $tmpbox = "mytmpbox.mbox";
19
20 my %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 #
37 my $mail = "";
38 my $line = "";
39 my $odir = "";
40
41 my $y = '';
42 my $m = '';
43 #
44 ################################################################################
45
46 while(<>) {
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 }
67
68 $m = $conv{$1};
69 $y = $2;
70 open FILE,"> $tmpbox";
71 }
72 }
73
74 print FILE $line;
75 }
76
77 if($odir) {
78 close FILE;
79 unlink $tmpbox;
80 }