| 1 | # Mail::Alias.pm | ||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||
| 3 | # Version 1.13 Date: 26 February 2022 | ||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2022 Jonathan Kamens <jik@kamens.us>. All rights reserved. | ||||||||||||||||||||||||||||||||
| 6 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||
| 7 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||
| 9 | # Portions of earlier versions of this program were copyrighted by Tom | ||||||||||||||||||||||||||||||||
| 10 | # Zeltwanger and Graham Barr. The current copyright holder extends full | ||||||||||||||||||||||||||||||||
| 11 | # authorship rights to both of the previous authors. | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | # PERLDOC documentation is found at the end of this file | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | ################################## | ||||||||||||||||||||||||||||||||
| 18 | package Mail::Alias; # | ||||||||||||||||||||||||||||||||
| 19 | ################################## | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | $VERSION = 1.13; | |||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub Version { $VERSION } | ||||||||||||||||||||||||||||||
|
Subroutine
Version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | # Global variable initialization | ||||||||||||||||||||||||||||||||
| 29 | 1 | my $alias_error = ""; # String used for returning error messages | |||||||||||||||||||||||||||||||
| 30 | 1 | my $aliases_file_default = "/etc/mail/aliases"; # The default aliases file name | |||||||||||||||||||||||||||||||
| 31 | 1 | my $max_alias_length = "40"; # The max number of characters in aliases | |||||||||||||||||||||||||||||||
| 32 | 1 | my $alias_nochar = "@[]"; # Characters not allowed in aliases | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | #-------------# | ||||||||||||||||||||||||||||||||
| 36 | # new() method# | ||||||||||||||||||||||||||||||||
| 37 | #-------------# | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | sub new { | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | my ($class, $object, $filename); | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 1 | $class = shift; # Get the class name | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 1 | $filename = $aliases_file_default; # Use the default filenname | |||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if (defined($_[0])) { # Unless a new name was passed as 1st argument | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 1 | $filename = $_[0]; | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 1 | $object = { _filename => $filename, | |||||||||||||||||||||||||||||||
| 50 | _errormsg => "no error reported", | ||||||||||||||||||||||||||||||||
| 51 | _usemem => "0", | ||||||||||||||||||||||||||||||||
| 52 | _usefile=> "1" | ||||||||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 1 | my $self = bless ($object, $class); | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 1 | $self->_init($filename); # Execute the _init method for the calling class | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 1 | return $object; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | #----------# | ||||||||||||||||||||||||||||||||
| 66 | # _init() # | ||||||||||||||||||||||||||||||||
| 67 | #----------# | ||||||||||||||||||||||||||||||||
| 68 | sub _init { | ||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 70 | 1 | $self->usefile; # If Alias object, default to file access | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | #----------# | ||||||||||||||||||||||||||||||||
| 77 | # format() # | ||||||||||||||||||||||||||||||||
| 78 | #----------# | ||||||||||||||||||||||||||||||||
| 79 | sub format { | ||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
format: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 81 | 0 | my $fmt = shift; | |||||||||||||||||||||||||||||||
| 82 | 0 | my $pkg = "Mail::Alias::" . $fmt; | |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | croak "Unknown format '$fmt'" | ||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | unless @{$pkg . "::ISA"}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | bless $me, $pkg; | |||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | #----------# | ||||||||||||||||||||||||||||||||
| 92 | # usemem() # | ||||||||||||||||||||||||||||||||
| 93 | #----------# | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | sub usemem { | ||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
usemem: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 97 | 0 | $self->{_usemem} = "1"; | |||||||||||||||||||||||||||||||
| 98 | 0 | $self->{_usefile} = "0"; | |||||||||||||||||||||||||||||||
| 99 | 0 | return; | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | #----------# | ||||||||||||||||||||||||||||||||
| 104 | # usefile()# | ||||||||||||||||||||||||||||||||
| 105 | #----------# | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | sub usefile { | ||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
usefile: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 109 | 1 | $self->{_usefile} = "1"; | |||||||||||||||||||||||||||||||
| 110 | 1 | $self->{_usemem} = "0"; | |||||||||||||||||||||||||||||||
| 111 | 1 | return; | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | #----------# | ||||||||||||||||||||||||||||||||
| 117 | # exists() # | ||||||||||||||||||||||||||||||||
| 118 | #----------# | ||||||||||||||||||||||||||||||||
| 119 | sub exists { | ||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | my ($self, $alias) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | if ($self->{_usemem}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | 0 | return defined $self->{$alias}; | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 2 | my ($self, $alias) = @_; | |||||||||||||||||||||||||||||||
| 130 | 2 | my ($text_line) = undef; # Temp storage of the line from the alias file | |||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | 2 | $aliases_file = $self->{_filename}; | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | open (ALIASES_FILE , $aliases_file) || die "ERROR: Can't open $aliases_file\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | # search till alias is found or EOF | ||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | while (<ALIASES_FILE>) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 138 | 13 | ▶ | if (/^$alias:/i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 139 | 1 | $text_line = $_; | |||||||||||||||||||||||||||||||
| 140 | 1 | chomp($text_line); | |||||||||||||||||||||||||||||||
| 141 | 1 | close ALIASES_FILE; | |||||||||||||||||||||||||||||||
| 142 | 1 | return $text_line; | |||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | # If you got here, the EOF was hit - returns undefined | ||||||||||||||||||||||||||||||||
| 148 | 1 | $self->{_errormsg} = "ERROR: There is no alias $alias in $aliases_file"; | |||||||||||||||||||||||||||||||
| 149 | 1 | close ALIASES_FILE; | |||||||||||||||||||||||||||||||
| 150 | 1 | return undef; | |||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | #----------# | ||||||||||||||||||||||||||||||||
| 157 | # expand() # | ||||||||||||||||||||||||||||||||
| 158 | #----------# | ||||||||||||||||||||||||||||||||
| 159 | sub expand { | ||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
expand: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 161 | 0 | my @result = (); | |||||||||||||||||||||||||||||||
| 162 | 0 | my %done = (); | |||||||||||||||||||||||||||||||
| 163 | 0 | my $alias; | |||||||||||||||||||||||||||||||
| 164 | 0 | my @todo = @_; | |||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | while($alias = shift(@todo)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | next if(defined $done{$alias}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 168 | 0 | $done{$alias} = 1; | |||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if(defined $me->{$alias}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 170 | 0 | push(@todo,@{$me->{$alias}}); | |||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | else { | ||||||||||||||||||||||||||||||||
| 173 | 0 | push(@result,$alias); | |||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | wantarray ? @result : \@result; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | #---------------------------------# | ||||||||||||||||||||||||||||||||
| 182 | # Alias::append() Method # | ||||||||||||||||||||||||||||||||
| 183 | # Version 1.0 8/19/00 # | ||||||||||||||||||||||||||||||||
| 184 | #---------------------------------# | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | sub append { | ||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | my $return_string; | ||||||||||||||||||||||||||||||
|
Subroutine
append: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 189 | 1 | my ($self, $alias, $address_string) = @_; | |||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | # Die if no alias was passed | ||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | unless ($alias) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 193 | 0 | die "ERROR: Alias::append requires an Alias argument\n"; | |||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 1 | $aliases_file = $self->{_filename}; | |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | if ($self->exists($alias)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | 0 | $self->{_errormsg} = "ERROR: $alias is already in the file $aliases_file\n"; | |||||||||||||||||||||||||||||||
| 200 | 0 | undef ($return_string); | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 1 | ▶ | open (ALIASES_FILE ,">>$aliases_file") || die "ERROR: Can't open $alias_file\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 206 | 1 | print ALIASES_FILE "$alias: $address_string\n"; | |||||||||||||||||||||||||||||||
| 207 | 1 | close ALIASES_FILE; | |||||||||||||||||||||||||||||||
| 208 | 1 | $return_string = "1"; # Successfully added the alias | |||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | } # ELSE | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | #------------------------------# | ||||||||||||||||||||||||||||||||
| 216 | # Alias::delete() Method # | ||||||||||||||||||||||||||||||||
| 217 | # Version 1.0 8/13/00# | ||||||||||||||||||||||||||||||||
| 218 | #------------------------------# | ||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | sub delete { | ||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | my ($self, @alias_list) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 223 | 1 | $filename = $self->{_filename}; | |||||||||||||||||||||||||||||||
| 224 | 1 | my $deleted = undef; | |||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | 1 | my $working_file = ($filename . ".tmp"); | |||||||||||||||||||||||||||||||
| 230 | 1 | rename ("$filename", "$working_file"); | |||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 1 | ▶ | open (NEW_FILE ,">$filename") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 234 | || die "ERROR: Can't open $filename\n"; | ||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | open (EXISTING_FILE , "$working_file") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 238 | || die "ERROR: Can't open $working_file\n"; | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | while (defined ($textline = <EXISTING_FILE>)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 244 | 7 | chomp ($textline); | |||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | 7 | ▶ | if (($textline =~ /^\s*$/) || ($textline =~ /^#/)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$textline =~ /^\s*$/ or $textline =~ /^#/
MC/DC100%2/2
$textline =~ /^\s*$/ or $textline =~ /^#/
$textline =~ /^\s*$/
$textline =~ /^#/
Truth table100%3/3
A or B
A= $textline =~ /^\s*$/B= $textline =~ /^#/
| |||||||||||||||||||||||||||||||||
| 248 | 4 | print NEW_FILE "$textline\n"; | |||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | else { | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | 3 | ▶ | if (!alias_check ($textline , \@alias_list)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 256 | 2 | print NEW_FILE "$textline\n"; | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | else { | ||||||||||||||||||||||||||||||||
| 260 | 1 | print "DELETING: $textline\n"; | |||||||||||||||||||||||||||||||
| 261 | 1 | $deleted = "1"; | |||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||
| 269 | # Close the files | ||||||||||||||||||||||||||||||||
| 270 | 1 | close EXISTING_FILE; | |||||||||||||||||||||||||||||||
| 271 | 1 | close NEW_FILE; | |||||||||||||||||||||||||||||||
| 272 | 1 | return $deleted; | |||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | } # end delete | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | #------------------------------# | ||||||||||||||||||||||||||||||||
| 278 | # Alias::update() Method # | ||||||||||||||||||||||||||||||||
| 279 | # Version 1.0 8/13/00# | ||||||||||||||||||||||||||||||||
| 280 | #------------------------------# | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | sub update { | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | my ($self, $alias, $address_string) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 285 | 0 | my ($found_it, $alias_line); | |||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 0 | undef $found_it; | |||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | # Form the alias line from the passed arguments | ||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ($address_string) { # If there is a second argument passed | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 291 | 0 | $alias_line = "$alias" . ": " . " $address_string"; | |||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||
| 293 | else { | ||||||||||||||||||||||||||||||||
| 294 | 0 | $alias_line = $alias; # The whole alias line is in $alias | |||||||||||||||||||||||||||||||
| 295 | 0 | $alias_line =~ /^(\S+)\s*:\s*(\S*)$/; # Extract the alias from the alias_line | |||||||||||||||||||||||||||||||
| 296 | 0 | $alias = $1; | |||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | 0 | $filename = $self->{_filename}; # Get the name of the aliases_file to be updated | |||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||
| 304 | 0 | my $working_file = ($filename . ".tmp"); | |||||||||||||||||||||||||||||||
| 305 | 0 | rename ("$filename", "$working_file"); | |||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | open (NEW_FILE ,">$filename") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 309 | || die "ERROR: Can't open $filename\n"; | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | open (EXISTING_FILE , "$working_file") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 313 | || die "ERROR: Can't open $working_file\n"; | ||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | while (defined ($textline = <EXISTING_FILE>)) { # For every line | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | # If line is blank or comment, just write it out | ||||||||||||||||||||||||||||||||
| 320 | 0 | chomp ($textline); | |||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if (($textline =~ /^\s+$/) || ($textline =~ /^#/)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$textline =~ /^\s+$/ or $textline =~ /^#/
MC/DC0%0/2
$textline =~ /^\s+$/ or $textline =~ /^#/
$textline =~ /^\s+$/
$textline =~ /^#/
Truth table0%0/3
A or B
A= $textline =~ /^\s+$/B= $textline =~ /^#/
| |||||||||||||||||||||||||||||||||
| 323 | 0 | print NEW_FILE "$textline\n"; | |||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | else { # Process alias lines here | ||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ($textline =~ /^$alias:/i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 330 | 0 | print NEW_FILE "$alias_line\n"; | |||||||||||||||||||||||||||||||
| 331 | 0 | $found_it = "1"; | |||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||
| 334 | else { | ||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | 0 | print NEW_FILE "$textline\n"; | |||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | 0 | close EXISTING_FILE; | |||||||||||||||||||||||||||||||
| 347 | 0 | close NEW_FILE; | |||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||
| 349 | 0 | return $found_it; | |||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||
| 351 | } # end update | ||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||
| 354 | #-------------------# | ||||||||||||||||||||||||||||||||
| 355 | # valid_alias Method# | ||||||||||||||||||||||||||||||||
| 356 | #-------------------# | ||||||||||||||||||||||||||||||||
| 357 | # valid_alias performs validation of the alias passed as an argument. | ||||||||||||||||||||||||||||||||
| 358 | # Return 1 if success and UNDEF if the test fails | ||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | sub valid_alias { | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | my ($self, $alias) = @_; # Get the alias | ||||||||||||||||||||||||||||||
|
Subroutine
valid_alias: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 363 | 0 | my $return_string = 1; # Set return for success | |||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if (($alias =~ /[$alias_nochar]/) || (length($alias) > $max_alias_length)) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$alias =~ /[$alias_nochar]/ or length $alias > $max_alias_length
MC/DC0%0/2
$alias =~ /[$alias_nochar]/ or length $alias > $max_alias_length
$alias =~ /[$alias_nochar]/
length $alias > $max_alias_length
Truth table0%0/3
A or B
A= $alias =~ /[$alias_nochar]/B= length $alias > $max_alias_length
| |||||||||||||||||||||||||||||||||
| 366 | 0 | { undef($return_string) | |||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||
| 369 | 0 | return $return_string; | |||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | #------------------# | ||||||||||||||||||||||||||||||||
| 375 | # alias_file Method# | ||||||||||||||||||||||||||||||||
| 376 | #------------------# | ||||||||||||||||||||||||||||||||
| 377 | # alias_file returns the complete path to the alias file that is being operated upon | ||||||||||||||||||||||||||||||||
| 378 | # by the Mail::Alias methods. | ||||||||||||||||||||||||||||||||
| 379 | # If a filename is passed as an argument, it is set to be the new filename for | ||||||||||||||||||||||||||||||||
| 380 | # all future operations. The file must exist or nothing is done. | ||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | sub alias_file { | ||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | my ($self, $newname) = @_; # Get the new name if one was passed | ||||||||||||||||||||||||||||||
|
Subroutine
alias_file: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | # If an argument was passed, make it the new $aliases_file value and return | ||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | if ($newname) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if (-e $newname) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 391 | 0 | $self->{_filename} = $newname; | |||||||||||||||||||||||||||||||
| 392 | 0 | return "$newname"; | |||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | else { | ||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||
| 397 | 0 | $self->{_errormsg} = "ERROR: $newname does not exist\n"; | |||||||||||||||||||||||||||||||
| 398 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||
| 404 | # If no argument, just return the current working aliases file pathname | ||||||||||||||||||||||||||||||||
| 405 | else { | ||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | 1 | return $self->{_filename}; | |||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||
| 413 | #------------# | ||||||||||||||||||||||||||||||||
| 414 | # error_check# | ||||||||||||||||||||||||||||||||
| 415 | #------------# | ||||||||||||||||||||||||||||||||
| 416 | # Returns the last error message in a text string | ||||||||||||||||||||||||||||||||
| 417 | # This method can be used after any method failed (i.e. returned UNDEF) | ||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | sub error_check { | ||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
error_check: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 422 | 0 | my $return_string; | |||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | 0 | $return_string = $self->{_errormsg}; | |||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | 0 | $self->{_errormsg} = "No error found"; | |||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | 0 | return $return_string; | |||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||
| 435 | #------------# | ||||||||||||||||||||||||||||||||
| 436 | # alias_check# | ||||||||||||||||||||||||||||||||
| 437 | #------------# | ||||||||||||||||||||||||||||||||
| 438 | # Check a line of text to see if it begins with any alias in the alias_list | ||||||||||||||||||||||||||||||||
| 439 | # Return the matching alias if found or UNDEF if no match exists | ||||||||||||||||||||||||||||||||
| 440 | # Alias matching is not case sensitive | ||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||
| 442 | sub alias_check { | ||||||||||||||||||||||||||||||||
| 443 | # Define variables and get arguments | ||||||||||||||||||||||||||||||||
| 444 | 3 | ▶ | my ($list_length, $list_index, $text); | ||||||||||||||||||||||||||||||
|
Subroutine
alias_check: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 445 | 3 | $text = $_[0]; # 1st argument is the line of text | |||||||||||||||||||||||||||||||
| 446 | 3 | $list = $_[1]; # 2nd argument is an array reference | |||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||
| 448 | # Extract the first non-whitespace from the text_line | ||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||
| 450 | 3 | $text =~ /^\s*(\S+)\s+/; | |||||||||||||||||||||||||||||||
| 451 | 3 | $text = $1; | |||||||||||||||||||||||||||||||
| 452 | 3 | $text =~ s/://; # Get rid of trailing : | |||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | # Search for the string | ||||||||||||||||||||||||||||||||
| 455 | 3 | $list_length = @$list; | |||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | 3 | ▶ | for ($list_index = 0; $list_index < $list_length; $list_index++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||
| 459 | # Check each alias for a match with the beginning of the text line | ||||||||||||||||||||||||||||||||
| 460 | # to get a match, the alias must be: | ||||||||||||||||||||||||||||||||
| 461 | # the first non-whitespace on the line | ||||||||||||||||||||||||||||||||
| 462 | # followed by whitespace or a : character | ||||||||||||||||||||||||||||||||
| 463 | 3 | ▶ | if ($text =~ /^\s*$$list[$list_index]:?\s*$/i) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 464 | 1 | return $$list[$list_index]; # Return the matching string from the list | |||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||
| 470 | 2 | return undef; | |||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||
| 475 | ############################################################# | ||||||||||||||||||||||||||||||||
| 476 | package Mail::Alias::Sendmail; # | ||||||||||||||||||||||||||||||||
| 477 | # Defines the Sendmail alias class read() and write() # | ||||||||||||||||||||||||||||||||
| 478 | ############################################################# | ||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 481 | #use Mail::Address; | ||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||
| 485 | 1 | @ISA = qw(Mail::Alias); | |||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||
| 488 | #----------# | ||||||||||||||||||||||||||||||||
| 489 | # _init() # | ||||||||||||||||||||||||||||||||
| 490 | #----------# | ||||||||||||||||||||||||||||||||
| 491 | sub _init { | ||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | my ($self, $filename) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | $self->read($filename) if($filename); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 495 | 0 | $self->usemem; # If Alias::Sendmail object, default to memory access | |||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||
| 500 | #---------# | ||||||||||||||||||||||||||||||||
| 501 | # write() # | ||||||||||||||||||||||||||||||||
| 502 | #---------# | ||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||
| 504 | sub write { | ||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 506 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||
| 507 | 0 | my $alias; | |||||||||||||||||||||||||||||||
| 508 | my $fd; | ||||||||||||||||||||||||||||||||
| 509 | 0 | local *ALIAS; | |||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if(ref($file)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 512 | 0 | $fd = $file; | |||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||
| 514 | else { | ||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | open(ALIAS,$file) || croak "Cannot open $file: $!\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 516 | 0 | $fd = \*ALIAS; | |||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||
| 519 | 0 | foreach $alias (sort keys %$me) { | |||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | unless ($alias =~ /^_/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 521 | 0 | my $ln = $alias . ": " . join(", ",@{$me->{$alias}}); | |||||||||||||||||||||||||||||||
| 522 | 0 | $ln =~ s/(.{55,78},)/$1\n\t/g; | |||||||||||||||||||||||||||||||
| 523 | 0 | print $fd $ln,"\n"; | |||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | close(ALIAS) if($fd == \*ALIAS); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||
| 530 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||
| 531 | # _include_file Local sub for expanding :include: files # | ||||||||||||||||||||||||||||||||
| 532 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||
| 533 | sub _include_file { | ||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | my $file = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_include_file: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 535 | 0 | local *INC; | |||||||||||||||||||||||||||||||
| 536 | 0 | my @ln; | |||||||||||||||||||||||||||||||
| 537 | 0 | local $_; | |||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | open(INC,$file) or carp "Cannot open file '$file'" and return ""; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
open(INC, $file) || carp("Cannot open file '${file}'") && (return '')
carp("Cannot open file '${file}'") and return ""
MC/DC0%0/2
open(INC, $file) || carp("Cannot open file '${file}'") && (return '')
open(INC, $file)
carp("Cannot open file '${file}'")
Truth table0%0/3
A || B
A= open(INC, $file)B= carp("Cannot open file '${file}'")
| |||||||||||||||||||||||||||||||||
| 539 | 0 | @ln = grep(/^[^#]/,<INC>); | |||||||||||||||||||||||||||||||
| 540 | 0 | close(INC); | |||||||||||||||||||||||||||||||
| 541 | 0 | chomp(@ln); | |||||||||||||||||||||||||||||||
| 542 | 0 | join(",",@ln); | |||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||
| 545 | #--------# | ||||||||||||||||||||||||||||||||
| 546 | # read() # | ||||||||||||||||||||||||||||||||
| 547 | #--------# | ||||||||||||||||||||||||||||||||
| 548 | sub read { | ||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||
| 550 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||
| 552 | 0 | local *ALIAS; | |||||||||||||||||||||||||||||||
| 553 | 0 | local $_; | |||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | open(ALIAS,$file) || croak "Cannot open $file: $!\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||
| 556 | 0 | my $group = undef; | |||||||||||||||||||||||||||||||
| 557 | 0 | my $line = undef; | |||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | while(<ALIAS>) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 560 | 0 | chomp; | |||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | if(defined $line && /^\s/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $line and /^\s/
MC/DC0%0/2
defined $line and /^\s/
defined $line
/^\s/
Truth table0%0/3
A and B
A= defined $lineB= /^\s/
| |||||||||||||||||||||||||||||||||
| 562 | 0 | $line .= $_; | |||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||
| 564 | else { | ||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | if(defined $line) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | if($line =~ s/^([^:]+)://) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 567 | 0 | my @resp; | |||||||||||||||||||||||||||||||
| 568 | 0 | $group = $1; | |||||||||||||||||||||||||||||||
| 569 | 0 | $group =~ s/(\A\s+|\s+\Z)//g; | |||||||||||||||||||||||||||||||
| 570 | 0 | $line =~ s/\"?:include:(\S+)\"?/_include_file($1)/eg; | |||||||||||||||||||||||||||||||
| 571 | 0 | $line =~ s/(\A[\s,]+|[\s,]+\Z)//g; | |||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | while(length($line)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 574 | 0 | $line =~ s/\A([^\"][^ \t,]+|\"[^\"]+\")(\s*,\s*)*//; | |||||||||||||||||||||||||||||||
| 575 | 0 | push(@resp,$1); | |||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | 0 | $me->{$group} = \@resp; | |||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||
| 580 | 0 | undef $line; | |||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | next if (/^#/ || /^\s*$/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/^#/ or /^\s*$/
MC/DC0%0/2
/^#/ or /^\s*$/
/^#/
/^\s*$/
Truth table0%0/3
A or B
A= /^#/B= /^\s*$/
| |||||||||||||||||||||||||||||||||
| 583 | 0 | $line = $_; | |||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||
| 586 | 0 | close(ALIAS); | |||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||
| 589 | ############################### | ||||||||||||||||||||||||||||||||
| 590 | package Mail::Alias::Ucbmail; # | ||||||||||||||||||||||||||||||||
| 591 | ############################### | ||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||
| 593 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||
| 595 | 1 | @ISA = qw(Mail::Alias::Binmail); | |||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||
| 597 | ############################### | ||||||||||||||||||||||||||||||||
| 598 | package Mail::Alias::Binmail; # | ||||||||||||||||||||||||||||||||
| 599 | ############################### | ||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||
| 601 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 602 | #use Mail::Address; | ||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||
| 604 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||
| 606 | 1 | @ISA = qw(Mail::Alias); | |||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||
| 608 | #----------# | ||||||||||||||||||||||||||||||||
| 609 | # _init() # | ||||||||||||||||||||||||||||||||
| 610 | #----------# | ||||||||||||||||||||||||||||||||
| 611 | sub _init { | ||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | my ($self, $filename) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | $self->read($filename) if($filename); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 615 | 0 | $self->usemem; # If Alias::Binmail object, default to memory access | |||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||
| 619 | #--------# | ||||||||||||||||||||||||||||||||
| 620 | # read() # | ||||||||||||||||||||||||||||||||
| 621 | #--------# | ||||||||||||||||||||||||||||||||
| 622 | sub read { | ||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 624 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||
| 626 | 0 | local *ALIAS; | |||||||||||||||||||||||||||||||
| 627 | 0 | local $_; | |||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | open(ALIAS,$file) || croak "Cannot open $file: $!\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | while(<ALIAS>) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | next unless(/^\s*(alias|group)\s+(\S+)\s+(.*)/); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 632 | 0 | my($group,$who) = ($2,$3); | |||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||
| 634 | 0 | $who =~ s/(\A[\s,]+|[\s,]+\Z)//g; | |||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||
| 636 | 0 | my @resp = (); | |||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | while(length($who)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 639 | # $who =~ s/\A([^\"]\S*|\"[^\"]*\")\s*//; | ||||||||||||||||||||||||||||||||
| 640 | # my $ln = $1; | ||||||||||||||||||||||||||||||||
| 641 | # $ln =~ s/\A\s*\"|\"\s*\Z//g; | ||||||||||||||||||||||||||||||||
| 642 | 0 | $who =~ s/\A\s*(\"?)([^\"]*)\1\s*//; | |||||||||||||||||||||||||||||||
| 643 | 0 | push(@resp,$2); | |||||||||||||||||||||||||||||||
| 644 | # push(@resp,$ln); | ||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||
| 646 | 0 | $me->{$group} = [ @resp ]; | |||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||
| 648 | 0 | close(ALIAS); | |||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||
| 651 | #---------# | ||||||||||||||||||||||||||||||||
| 652 | # write() # | ||||||||||||||||||||||||||||||||
| 653 | #---------# | ||||||||||||||||||||||||||||||||
| 654 | sub write { | ||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 656 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||
| 657 | 0 | my $alias; | |||||||||||||||||||||||||||||||
| 658 | my $fd; | ||||||||||||||||||||||||||||||||
| 659 | 0 | local *ALIAS; | |||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | if(ref($file)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 662 | 0 | $fd = $file; | |||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||
| 664 | else { | ||||||||||||||||||||||||||||||||
| 665 | 0 | ▶ | open(ALIAS,$file) || croak "Cannot open $file: $!\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 666 | 0 | $fd = \*ALIAS; | |||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||
| 669 | 0 | foreach $alias (sort keys %$me) { | |||||||||||||||||||||||||||||||
| 670 | 0 | my @a = @{$me->{$alias}}; | |||||||||||||||||||||||||||||||
| 671 | 0 | ▶ | map { $_ = '"' . $_ . '"' if /\s/ } @a; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | unless ($alias =~ /^_/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 673 | 0 | print $fd "alias $alias ",join(" ",@a),"\n"; | |||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | close(ALIAS) if($fd == \*ALIAS); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||
| 681 | ############################# | ||||||||||||||||||||||||||||||||
| 682 | # Documentation starts here # | ||||||||||||||||||||||||||||||||
| 683 | ############################# | ||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||
| 685 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||
| 687 | Mail::Alias - Maniulates mail alias files of various formats. Works on files directly or loads files into memory and works on the buffer. | ||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||
| 689 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||
| 691 | use Mail::Alias; | ||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||
| 693 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||
| 695 | C<Mail::Alias> can read various formats of mail alias. Once an object has been created it can be used to expand aliases and output in another format. | ||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||
| 698 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||
| 700 | =over 4 | ||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||
| 702 | =item B<new ()> | ||||||||||||||||||||||||||||||||
| 703 | Alias objects can be created in two ways; | ||||||||||||||||||||||||||||||||
| 704 | With a format specified- Mail::Alias::Sendmail->new([filename]) | ||||||||||||||||||||||||||||||||
| 705 | Without a format specified- Mail::Alias->new([filename]}. Format defaults to | ||||||||||||||||||||||||||||||||
| 706 | SENDMAIL | ||||||||||||||||||||||||||||||||
| 707 | In either case, the filename is optional and, if supplied, it will be read in | ||||||||||||||||||||||||||||||||
| 708 | when the object is created. Available formats are Sendmail, Ucbmail, and | ||||||||||||||||||||||||||||||||
| 709 | Binmail. | ||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||
| 711 | =back | ||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||
| 713 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||
| 715 | =over 4 | ||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||
| 717 | =item B<read ()> | ||||||||||||||||||||||||||||||||
| 718 | Reads an alias file of the specified format into memory. Comments or blank | ||||||||||||||||||||||||||||||||
| 719 | lines are lost upon reading. Due to storage in a hash, ordering of the alias | ||||||||||||||||||||||||||||||||
| 720 | lines is also lost. | ||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||
| 722 | =item B<write ()> | ||||||||||||||||||||||||||||||||
| 723 | The current set of aliases contained in the object memory are written to a | ||||||||||||||||||||||||||||||||
| 724 | file using the current format. | ||||||||||||||||||||||||||||||||
| 725 | If a filehandle is passed, data is written to the already opened file. If a | ||||||||||||||||||||||||||||||||
| 726 | filename is passed, it is opened and the memory is written to the file. | ||||||||||||||||||||||||||||||||
| 727 | Note: if passing a filename, include the mode (i.e. to write to a file named | ||||||||||||||||||||||||||||||||
| 728 | aliases pass >aliases). Before writing, the alias lines are sorted | ||||||||||||||||||||||||||||||||
| 729 | alphabetically. | ||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||
| 731 | =item B<format ()> | ||||||||||||||||||||||||||||||||
| 732 | Set the current alias file format. | ||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||
| 734 | =item B<exists ()> | ||||||||||||||||||||||||||||||||
| 735 | Indicates the presence of the passed alias within the object (if using memory | ||||||||||||||||||||||||||||||||
| 736 | access), or the current aliases file (if using direct file access). For | ||||||||||||||||||||||||||||||||
| 737 | direct file access, the return value is the address string for the alias. | ||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||
| 739 | =item B<expand ()> | ||||||||||||||||||||||||||||||||
| 740 | Expands the passed alias into a list of addresses. Expansion properly handles | ||||||||||||||||||||||||||||||||
| 741 | :include: files, recursion, and continuation lines.Only works when memory | ||||||||||||||||||||||||||||||||
| 742 | access is being used. If the alias is not found in the object, you get back | ||||||||||||||||||||||||||||||||
| 743 | what you sent. | ||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||
| 745 | =item B<alias_file ()> | ||||||||||||||||||||||||||||||||
| 746 | Sets or gets the name of the current alias filename for direct access. | ||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||
| 748 | =item B<append () *-Sendmail only-*> | ||||||||||||||||||||||||||||||||
| 749 | Adds an alias to an existing Sendmail alias file. The alias and addresses can | ||||||||||||||||||||||||||||||||
| 750 | be passed as two separate arguments (alias, addresses) or as a single line of | ||||||||||||||||||||||||||||||||
| 751 | text (alias: addresses) | ||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||
| 753 | =item B<delete () *-Sendmail only-*> | ||||||||||||||||||||||||||||||||
| 754 | Deletes the entry for an alias from the current alias file. | ||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||
| 756 | =item B<update () *-Sendmail only-*> | ||||||||||||||||||||||||||||||||
| 757 | Replaces the address string entry for an alias in the current alias file. | ||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||
| 759 | =item B<usemem ()> | ||||||||||||||||||||||||||||||||
| 760 | Sets the working mode to use memory (indirect access). Use read(), write() and | ||||||||||||||||||||||||||||||||
| 761 | format() methods. | ||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||
| 763 | =item B<usefile ()> | ||||||||||||||||||||||||||||||||
| 764 | Sets the working mode to use files (direct access). Use append() and delete() | ||||||||||||||||||||||||||||||||
| 765 | methods. | ||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||
| 768 | =back | ||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||
| 770 | =head1 MAINTAINER | ||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||
| 772 | Jonathan Kamens <jik@kamens.us> (CPAN author ID: JIK) | ||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||
| 774 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||
| 776 | Copyright (c) 2022 Jonathan Kamens <jik@kamens.us>. All rights reserved. This | ||||||||||||||||||||||||||||||||
| 777 | program is free software; you can redistribute it and/or modify it under the | ||||||||||||||||||||||||||||||||
| 778 | same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||
| 780 | Portions of earlier versions of this program were copyrighted by Tom Zeltwanger | ||||||||||||||||||||||||||||||||
| 781 | and Graham Barr. The current copyright holder extends full authorship rights to | ||||||||||||||||||||||||||||||||
| 782 | both of the previous authors. | ||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||
| 784 | =cut | ||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||
| 786 | 1 | 1; | |||||||||||||||||||||||||||||||