| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use Mail::Audit; |
| 4 |
use MIME::Lite; |
| 5 |
#use MIME::Entity; |
| 6 |
#use MIME::Head; |
| 7 |
#use MIME::Parser; |
| 8 |
use Data::Dumper; |
| 9 |
#use MIME::Base64; |
| 10 |
use File::Copy; |
| 11 |
|
| 12 |
my $mail = Mail::Audit->new; |
| 13 |
my $from = $mail->from(); |
| 14 |
#study $from; |
| 15 |
my $to = $mail->to(); |
| 16 |
my $cc = $mail->cc(); |
| 17 |
my $subject = $mail->subject(); |
| 18 |
chomp($from, $to, $cc, $subject); |
| 19 |
my $body = $mail->body(); |
| 20 |
my $head = $mail->head(); |
| 21 |
my $user_path = "/home/janosch"; |
| 22 |
|
| 23 |
|
| 24 |
#SMS versand an Nummer im Subject nach dem Suchmuster "sms:0170123456 text" |
| 25 |
if ($subject =~ /^sms:(\d+)\s(.*)/) { |
| 26 |
$pathtoyaps = "/usr/bin/yaps"; |
| 27 |
$number = $1; |
| 28 |
$subjecttoprint = $2; |
| 29 |
$sms_txt = "You got e-mail from: $from orig_subject: $subject printed_subject: $subjecttoprint"; |
| 30 |
my $output = qx($pathtoyaps $number "$sms_txt"); |
| 31 |
|
| 32 |
#Status-Mail an To: Address |
| 33 |
my $message = MIME::Lite->new( |
| 34 |
From =>'sms-gateway@localhost', |
| 35 |
To =>"$to", |
| 36 |
Subject =>"SMS to $number was send", |
| 37 |
Data =>"$output\n" |
| 38 |
); |
| 39 |
|
| 40 |
$message->send(); # UNIX-sendmail |
| 41 |
} |
| 42 |
|
| 43 |
#Fax Versand an Nummer im Subject mit Txt,Pdf,Tiff-Attachment |
| 44 |
if ($subject =~ /^fax:(\d+)\s(.*)/) { |
| 45 |
$pathtofax = "/usr/bin/sendfax"; |
| 46 |
# $fax_cont = "fritz_pic.tif"; |
| 47 |
$fax_number = $1; |
| 48 |
$fax_subject_to_print = $2; |
| 49 |
$fax_txt = "You got Fax from: $from subject: $fax_subject_to_print"; |
| 50 |
|
| 51 |
my $create_an_object = qx(touch ~/mail/fax/noerror); |
| 52 |
my $delete_old_objects = qx(rm ~/mail/fax/*); |
| 53 |
#print "$delete_old_objects\n"; |
| 54 |
|
| 55 |
my $entity = $mail; |
| 56 |
my $head_entity; |
| 57 |
my $body_entity; |
| 58 |
|
| 59 |
my $current_entity; |
| 60 |
my $i; |
| 61 |
my $current_body; |
| 62 |
my $current_head; |
| 63 |
my $num_alt_parts = $entity->parts(); |
| 64 |
my $attachment_save_path; |
| 65 |
my $plain_counter = "0"; |
| 66 |
my $pdf_counter = "0"; |
| 67 |
my $tiff_counter = "0"; |
| 68 |
|
| 69 |
for ($i = 0; $i < $num_alt_parts; $i++) { |
| 70 |
|
| 71 |
$current_entity = $entity->parts($i); |
| 72 |
$current_body = $current_entity->bodyhandle(); |
| 73 |
|
| 74 |
$head_entity = $current_entity->head(); |
| 75 |
# print "MIME-Type: ", $head_entity->mime_type() , "\n"; |
| 76 |
$head_mime_type = $head_entity->mime_type(); |
| 77 |
#print "$attachment_save_path\n"; |
| 78 |
if ($head_mime_type =~ /text\/plain/) { |
| 79 |
# print "$current_body\n"; |
| 80 |
# print "Current_body: \n" . Dumper($current_body); |
| 81 |
my $tmp_body_path = $current_body->path; |
| 82 |
# print "Dateigroesse: ", -s $tmp_body_path,"\n"; |
| 83 |
my $filegroesse = -s $tmp_body_path; |
| 84 |
# print "$filegroesse\n"; |
| 85 |
if ($filegroesse > 1 ) { |
| 86 |
$plain_attachment_save_path = "$user_path/mail/fax/fax$i.txt"; |
| 87 |
# print "Plain-Datei $plain_attachment_save_path wird gespeichert\n"; |
| 88 |
copy $current_body->path, $plain_attachment_save_path; |
| 89 |
$plain_counter++; |
| 90 |
}} |
| 91 |
if ($head_mime_type =~ /image\/tiff/) { |
| 92 |
$tiff_attachment_save_path = "$user_path/mail/fax/fax$i.tif"; |
| 93 |
# print "Tiff-Datei $tiff_attachment_save_path wird gespeichert\n"; |
| 94 |
# print "$head_entity\n"; |
| 95 |
# print "Head_entity: \n" . Dumper($head_entity); |
| 96 |
copy $current_body->path, $tiff_attachment_save_path; |
| 97 |
$tiff_counter++ |
| 98 |
} |
| 99 |
|
| 100 |
if ($head_mime_type =~ /application\/pdf/) { |
| 101 |
$pdf_attachment_save_path = "$user_path/mail/fax/fax$i.pdf"; |
| 102 |
copy $current_body->path, $pdf_attachment_save_path; |
| 103 |
$pdf_counter++ |
| 104 |
} |
| 105 |
|
| 106 |
} |
| 107 |
# my $fax_output = `$pathtofax -n -d "$fax_number" ~/mail/fax/*`; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
#Status-Mail an To: Address |
| 112 |
my $message = MIME::Lite->new( |
| 113 |
From =>'fax-gateway@localhost', |
| 114 |
To =>"$to", |
| 115 |
Subject =>"Fax to $fax_number was send", |
| 116 |
Type =>"text/plain", |
| 117 |
# Data =>"Fax to $fax_number with subject: $fax_subject_to_print and $plain_counter Text-Attachment $tiff_counter Tiff-Attachment $pdf_counter Pdf-Attachment was sent Pages:$num_alt_parts\n" |
| 118 |
Data =>"Fax to $fax_number with $plain_counter Text-Attachment, $tiff_counter Tiff-Attachment, $pdf_counter Pdf-Attachment was sent.\n" |
| 119 |
|
| 120 |
); |
| 121 |
|
| 122 |
$message->send(); # UNIX-sendmail |
| 123 |
} |
| 124 |
#my $copy_objects = qx(cp ~/mail/fax/* /usr/local/httpd/htdocs/dav/mail-cont/); |
| 125 |
#print "$copy_objects\n"; |
| 126 |
$mail->accept; |