1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
   | # SNEC::MAIL.pm
#
# This program write a SNEC email alert into XML Mails file.
# 
package SNEC::MAIL;
use strict;
 
sub send_mail
{
	my $self = shift ;
	my $subject = shift ;
	my $message = shift ;
	my $type = shift ;
 
	my $date = `date`;
	chomp $date ;
 
	my $directory = `cd` ;
	my @word = split ('\\\\', $directory) ;
 
	my $country  = 	$word [$#word-3] ;
	my $platform = 	$word [$#word-2] ;
	my $report = 	$word [$#word-1] ;
 
  my $mails_file = "Mails.xml" ;	
  my $mails_temp = "Mails.tmp" ;
	my $mails_dtd = "Mails.dtd" ;
 
	# Mails DTD file	
	open (OUT,"> Mails.dtd") ;	
	print OUT "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" ;
	print OUT "<!ELEMENT MAILS (MAIL+)> \n" ;
	print OUT "<!ELEMENT MAIL (DATE, SUBJECT, CONTENT)> \n" ;
	print OUT "<!ELEMENT DATE (#PCDATA)> \n" ;
	print OUT "<!ELEMENT SUBJECT (#PCDATA)> \n" ;
	print OUT "<!ELEMENT CONTENT (#PCDATA)> \n" ;
	close (OUT) ;
 
	# Mails history file	
	open (OUT,">> Mails.txt") ;	
	print OUT "Date: ".$date."\n" ;
	print OUT "Subject: SNEC ".$type." : ".$country." / ".$platform." / ".$report." / ".$subject."\n" ;
	print OUT "Message:\n" ;
	print OUT $message."\n\n" ;
	close (OUT) ;
 
	# Open temporary mails file
	if ((-e $mails_temp) == 1) 
	{
		open (MAIL,">>$mails_temp") ;	
	}
	else
	{
	open (MAIL,">$mails_temp") ;	
  	print MAIL "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ;
	print MAIL "<!DOCTYPE MAILS SYSTEM \"Mails.dtd\">\n" ;
	print MAIL "<MAILS>\n" ;
	}
 
	# Write current mail in temporary file
	print MAIL "<MAIL>\n" ;
	print MAIL "<DATE>".$date."</DATE>\n" ;
	print MAIL "<SUBJECT>SNEC ".$type." : ".$country." / ".$platform." / ".$report." / ".$subject."</SUBJECT>\n" ;
  print MAIL "<CONTENT>\n" ;
	print MAIL $message."\n" ;
  print MAIL "</CONTENT>\n" ;
	print MAIL "</MAIL>\n" ;
	close (MAIL) ;
 
	# Copy temporary file into XML Mails file
	`copy $mails_temp $mails_file` ;
	# Write end of mails and close XML Mails file
	open (MAIL,">>$mails_file") ;	
	print MAIL "</MAILS>\n" ;
	close (MAIL) ;
 
}
 
1;
 
__END__ | 
Partager