Mail-Alias

 view release on metacpan or  search on metacpan

Alias.pm  view on Meta::CPAN

	my ($self, @alias_list) = @_;			
	$filename = $self->{_filename};			
	my $deleted = undef;					
										

	
	
		my $working_file = ($filename . ".tmp");
		rename ("$filename", "$working_file");		
	
	
	open (NEW_FILE ,">$filename")
		|| die "ERROR: Can't open $filename\n";
	
	
	open (EXISTING_FILE , "$working_file")
		|| die "ERROR: Can't open $working_file\n";

	
	

	while (defined ($textline = <EXISTING_FILE>)) {		
		chomp ($textline);
		
		
		if (($textline =~ /^\s*$/) || ($textline =~ /^#/)) {
			print NEW_FILE "$textline\n";
		}

		else {				
			
			
			
			if (!alias_check ($textline , \@alias_list)) {
				print NEW_FILE "$textline\n";
			} 
			
			else {		
				print "DELETING:  $textline\n";
				$deleted = "1";
			}
			
			
		} 
		
	} 

	# Close the files 
	close EXISTING_FILE;
	close NEW_FILE;
	return $deleted;
	
} # end delete


#------------------------------#
# Alias::update() Method       #
#	Version 1.0		8/13/00#
#------------------------------#

sub update {

	my ($self, $alias, $address_string) = @_;
	my ($found_it, $alias_line);

	undef $found_it;						

	# Form the alias line from the passed arguments
	if ($address_string) {					# If there is a second argument passed
		$alias_line = "$alias" . ": " . " $address_string";
	}
	else {
		$alias_line = $alias;					# The whole alias line is in $alias
		$alias_line =~ /^(\S+)\s*:\s*(\S*)$/;	# Extract the alias from the alias_line
		$alias = $1;					
	}
	
	
	$filename = $self->{_filename};				# Get the name of the aliases_file to be updated

	
	
	my $working_file = ($filename . ".tmp");
	rename ("$filename", "$working_file");		
	
	
	open (NEW_FILE ,">$filename")
		|| die "ERROR: Can't open $filename\n";
	
	
	open (EXISTING_FILE , "$working_file")
		|| die "ERROR: Can't open $working_file\n";

	
	
	while (defined ($textline = <EXISTING_FILE>)) {		# For every line
	
		# If line is blank or comment, just write it out
		chomp ($textline);
		
		if (($textline =~ /^\s+$/) || ($textline =~ /^#/)) {
			print NEW_FILE "$textline\n";
		}

		else {				# Process alias lines here
			
			
			if ($textline =~ /^$alias:/i) {
				print NEW_FILE "$alias_line\n";
				$found_it = "1";
			} 
			
			else {	
				
				print NEW_FILE "$textline\n";						
			
			} 


		} 
		



( run in 0.989 second using v1.01-cache-2.11-cpan-39bf76dae61 )