]> the.earth.li Git - htag.git/blob - plugins/80header
5f9c52acdac3f467a28e369e8a018e89c54be174
[htag.git] / plugins / 80header
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2000-2001 Simon Huggins
4 # header adds headers to messages like "Hi @F"
5
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2 of the License, or (at your option)
9 # any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 # for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc., 59
18 # Temple Place, Suite 330, Boston, MA 02111-1307  USA
19
20 use strict;
21
22 my ($sig);
23
24 sub add_heading($) {
25         my $msgfile = shift;
26         my @msg;
27
28         return if (not defined $cfg{'randhead'});
29         
30         open(HANDLE,$msgfile) or htagdie "$0: Cannot open $msgfile: $!\n";
31         @msg = <HANDLE>;
32         close(HANDLE);
33         
34         my $head =  @{$cfg{'randhead'}}[rand scalar @{$cfg{'randhead'}}];
35         $head    =  subst_macros($head);
36         
37         my $i;
38         for ($i=0; $i<scalar @msg; $i++) {
39                 next if $msg[$i] =~ /^.*:/;
40                 next if $msg[$i] =~ /^[         ]/;
41                 last;
42         }
43
44         $msg[$i] = $msg[$i] . $head . "\n";
45
46         open(HANDLE, ">$msgfile") or htagdie "$0: Cannot open $msgfile: $!\n";
47         print HANDLE @msg;
48         close(HANDLE);
49
50 }
51
52 process_msgbody $cfg{'msgfile'};
53 add_heading $cfg{'msgfile'} if defined $cfg{'name'};
54 return;