summaryrefslogtreecommitdiff
path: root/www/digest/mailify.pl
diff options
context:
space:
mode:
Diffstat (limited to 'www/digest/mailify.pl')
-rwxr-xr-xwww/digest/mailify.pl130
1 files changed, 130 insertions, 0 deletions
diff --git a/www/digest/mailify.pl b/www/digest/mailify.pl
new file mode 100755
index 0000000000..4e0c7d60fd
--- /dev/null
+++ b/www/digest/mailify.pl
@@ -0,0 +1,130 @@
1#!/usr/bin/perl
2
3my $end++;
4
5my @out;
6my $url;
7
8my $urlnum=1;
9
10sub showlinks {
11 my ($date)=@_;
12 if(scalar(keys %store)) {
13 print "\n";
14
15 for(sort {$store{$a} <=> $store{$b} } keys %store) {
16 my $url=$_;
17
18 $url =~ s/^\"(.*)\"/$1/g;
19 printf("[%d] = %s\n", $store{$_}, $url);
20 }
21 undef %store;
22 $urlnum=1; # reset to 1
23 }
24}
25
26sub showitem {
27 my @text=@_;
28
29 if(@text) {
30 my $c=3;
31 my $width=72;
32 print " * ";
33
34 my $thelot = join(" ", @text);
35
36 for (split(/[ \t\n]/, $thelot)) {
37 my $word = $_;
38
39 $word =~ s/[ \t]//g;
40
41 my $len = length($word);
42 if(!$len) {
43 next; # skip blanks
44 }
45
46 if($len + $c + 1> $width) {
47 print "\n ";
48 $c = 3;
49 }
50 elsif($c != 3) {
51 print " ";
52 $c++;
53 }
54 print $word;
55 $c += $len;
56 }
57 }
58 print "\n"; # end of item
59
60 # my @words=split(
61
62}
63
64sub date2secs {
65 my ($date)=@_;
66 my $secs = `date -d "$date" +"%s"`;
67 return 0+$secs;
68}
69
70while(<STDIN>) {
71 my $line = $_;
72
73 if($_ =~ /^Date: (.*)/) {
74 my $date=$1;
75 my $secs = date2secs($date);
76 my $tendaysago = time()-(14*24*60*60);
77 showitem(@out);
78 undef @out;
79 chomp;
80
81 showlinks();
82
83 if($secs < $tendaysago) {
84 last;
85 }
86
87 print "\n----------------------------------------------------------------------\n$_";
88 next;
89 }
90 elsif($line =~ /^ *(---)(.*)/) {
91
92 showitem(@out);
93
94 @out="";
95 $line = $2;
96 }
97
98 if($line =~ s/\[URL\](.*)\[URL\]//) {
99 $url=$1;
100
101 if(!$store{$url}) {
102 $footnote = "[$urlnum]";
103 $store{$url} = $urlnum;
104 $urlnum++;
105 }
106 else {
107 $footnote = "[".$store{$url}."]";
108 }
109 # print STDERR "Set $footnote for $url\n";
110 }
111 if($line =~ s/\[TEXT\](.*)\[TEXT\]/$1$footnote/) {
112 # print STDERR "Output $footnote (full TEXT)\n";
113 undef $text;
114 }
115 elsif(!$text && ($line =~ s/\[TEXT\](.*)/$1/)) {
116 # print STDERR "Detected start of TEXT\n";
117 $text = $1;
118 }
119 elsif($text && ($line =~ s/(.*)\[TEXT\]/$1$footnote/)) {
120 # print STDERR "Output $footnote (end-TEXT)\n";
121 undef $text;
122 }
123
124 push @out, $line;
125}
126
127if(@out) {
128 showitem(@out);
129}
130