Debian Codegraph @

Debbugs/Email.pm

raw
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( %GTags );
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( %GTags );
19 }
20
21 use vars @EXPORT_OK;
22 use Debbugs::Config qw(%Globals);
23
24 # initialize package globals, first exported ones
25 %GTags= ( );
26
27 #############################################################################
28 # Initialize Global Tags
29 #############################################################################
30 sub InitEmailTags
31 { my @config = @_;
32
33 print "V: Initializing Email Tags\n" if $Globals{ 'verbose' };
34 for( my $i=0; $i<=$#config; $i++)
35 { $_ = $config[$i];
36 chop $_;
37 next unless length $_;
38 next if /^#/;
39 if ( /^GTAG\s*[:=]\s*(\S)+\s*[:=]\s*([^#]*)/i )
40 { $GTags{ $1 } = $2;
41 print "D2: (email) GTag $1=$GTags{$1}\n" if $Globals{ 'debug' } > 1;
42 }
43 }
44 }
45
46 #############################################################################
47 # Load File with Tags
48 #############################################################################
49 sub LoadEmail
50 { my $emailfile = $_[0];
51 my @email;
52
53 open( LETTER, $emailfile ) or &::fail( "Unable to open $emailfile: $!" );
54 @email = <LETTER>;
55 close LETTER;
56 &ProcessTags( \@email, \%GTags, "GTAG" );
57 return @email;
58 }
59 #############################################################################
60 # Process Tags
61 #############################################################################
62 sub ProcessTags
63 { my ($email, $tagsin, $marker) = @_;
64 my %tags=%$tagsin;
65 my $tag;
66
67 print "V: Processing Template Mail\n" if $Globals{ 'verbose' };
68 foreach my $line ( @$email )
69 { while( $line =~ /\%$marker\_(\S*)\%/s )
70 { if( defined( $tags{ $1 } ) ) { $tag = $tags{ $1 }; }
71 else { $tag = "(missed tag $1)"; }
72 $line =~ s/\%$marker\_(\S*)\%/$tag/;
73 }
74 }
75 1;
76 }
77
78 END { } # module clean-up code here (global destructor)
79 1;