]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Email.pm
6a97f7674f3f89a9ec879c9907cfa60c54aece37
[debbugs.git] / Debbugs / Email.pm
1 package Debbugs::Email;  
2
3 use strict;
4
5 BEGIN {
6         use Exporter   ();
7         use vars       qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
8
9         # set the version for version checking
10         $VERSION     = 1.00;
11
12         @ISA         = qw(Exporter);
13         @EXPORT      = qw( );
14         %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
15
16         # your exported package globals go here,
17         # as well as any optionally exported functions
18         @EXPORT_OK   = qw( );
19 }
20
21 use vars @EXPORT_OK;
22 use Debbugs::Config qw(%Globals);
23
24 # initialize package globals, first exported ones
25 %gtags= (       "SECRETARY_TITLE" => "Debian Project Secretary",
26                 "SECRETARY_NAME" => "Darren Benham",
27                 "ERRORS_TITLE" => "Nobody",
28                 "ERRORS_EMAIL" => "errors\@benham.net",
29                 "VOTE_TITLE" => "Set Vote Title",
30                 "SECRETARY_EMAIL" => "secretary\@debian.org");
31
32 #############################################################################
33 #  Initialize Global Tags
34 #############################################################################
35 sub InitEmailTags
36 {   my @config = @_;
37         
38     print "V: Initializing Email Tags\n" if $Globals{ 'verbose' };
39     for( my $i=0; $i<=$#config; $i++)
40     {   $_ = $config[$i];
41         chop $_;
42         next unless length $_;
43         next if /^#/;
44         if ( /^GTAG\s*[:=]\s*(\S)+\s*[:=]\s*([^#]*)/i )
45         {   $gtags{ $1 } = $2;
46             print "D2: (email) GTag $1=$gtags{$1}\n" if $Globals{ 'debug' } > 1;
47         }
48     }
49 }
50
51 #############################################################################
52 #  Load File with Tags
53 #############################################################################
54 sub LoadEmail
55 {   my $emailfile = $_[0];
56     my @email;
57
58     open( LETTER, $emailfile ) or &::fail( "Unable to open $emailfile: $!" );
59     @email = <LETTER>;
60     close LETTER;
61     &ProcessTags( \@email, \%gtags, "GTAG" );
62     return @email;
63 }
64 #############################################################################
65 #  Process Tags
66 #############################################################################
67 sub ProcessTags
68 {   my ($email, $tagsin, $marker) = @_;
69     my %tags=%$tagsin;
70     my $tag;
71
72     print "V: Processing Template Mail\n" if $Globals{ 'verbose' };
73     foreach my $line ( @$email )
74     {   while( $line =~ /\%$marker\_(\S*)\%/s )
75         {   if( defined( $tags{ $1 } ) ) { $tag = $tags{ $1 }; }
76             else { $tag = "(missed tag $1)"; }
77             $line =~ s/\%$marker\_(\S*)\%/$tag/;
78         }
79     }
80     1;
81 }
82
83 END { }       # module clean-up code here (global destructor)
84 1;