#!/usr/bin/perl ################################################################################### # # # PerlDesk - Customer Help Desk Software # # # ################################################################################### # # # Author: John Bennett # # Email: j.bennett@perldesk.com # # Web: http://www.perldesk.com # # Filename: email.cgi # # Details: The main email gateway file # # Release: 1.8 # # Revision: 0 # # # ################################################################################### # Please direct bug reports,suggestions or feedback to the perldesk forums. # # www.perldesk.com/board # # # # (c) PerlDesk (JBSERVE LTD) 2002/2003 # # PerlDesk is protected under copyright laws and cannot be resold, redistributed # # in any form without prior written permission from JBServe LTD. # # # # This program is commercial and only licensed customers may have an installation # ################################################################################### #~~ # Please set the path information below use lib '/home/httpd/vhosts/netinvoicing.com/httpdocs/support/include/mods'; require "/home/httpd/vhosts/netinvoicing.com/httpdocs/support/include/conf.cgi"; require "/home/httpd/vhosts/netinvoicing.com/httpdocs/support/include/lang/en.inc"; #~~ No further editing required use CGI qw(:standard); use DBI(); use MIME::Parser; use Mail::Address; use MIME::Entity; use MIME::Body; use Data::Dumper; &get_time(); $parser = new MIME::Parser; $parser->ignore_errors(1); $parser->output_to_core(1); my $MIME_entity = $parser->parse(\*STDIN); my $error = ($@ || $parser->last_error); $header = $MIME_entity->head; $subject = $header->get('Subject') || "no subject"; $cto = $header->get('To'); $from = $header->get('From'); $priority = $header->get('X-Priority'); $priority = "3" if $priority eq "N"; @to_addresses = Mail::Address->parse($cto); @from_addresses = Mail::Address->parse($from); my $address; if (@to_addresses) { $to = $to_addresses[0]->address(); } else { exit; } if (@from_addresses) { $address = $from_addresses[0]->address(); if($address eq 'MAILER-DAEMON') { exit; } } else { exit; } $id = 0; if ($MIME_entity->parts > 0) { for (my $i=0;$i<$MIME_entity->parts;$i++) { my $subEntity = $MIME_entity->parts($i); #~~ # Get the $body of the email #~~ my $ignore_plain = "0"; my $ignore_html = "0"; $ishtml = "1" if $subEntity->mime_type eq 'text/html'; $ishtml = "0" if $subEntity->mime_type eq 'text/plain'; #~~ # This is a multipart/alternative message if ($subEntity->mime_type eq 'multipart/alternative' && !$ignore_all ) { for (my $j=0;$j<$subEntity->parts;$j++) { my $subSubEntity = $subEntity->parts($j); if ($subSubEntity->mime_type eq 'text/plain' && $ignore_plain == "0" && !$ignore_all) { if (my $io = $subSubEntity->open("r")) { while (defined($_=$io->getline)) { $_ =~ s/"/\"/g; $body .= $_; } $ignore_all = 1; last; } } } } #~~ # Test / Plain Email Body if ($subEntity->mime_type eq 'text/plain' && $ignore_plain == "0" && !$ignore_all) { if (my $io = $subEntity->open("r")) { while (defined($_=$io->getline)) { $_ =~ s/"/\"/g; $body .= $_; } $io->close; $ignore_html = 1; $ignore_all = 1; last; } } #~~ # Text / HTML Email Body if ($subEntity->mime_type eq 'text/html' && $ignore_html == "0" && !$ignore_all) { if (my $io = $subEntity->open("r")) { while (defined($_=$io->getline)) { $_ =~ s/"/\"/g; $body .= $_; } $io->close; $ignore_plain = 1; $ignore_all = 1; } } $id++; } } else { $body = join "", @{$MIME_entity->body}; } $to = $1 if $to =~ /<(\S+)>/; if ($from =~ /<(\S+)>/) { $newfrom = $1 } else { $newfrom = $from } $body =~ s/"/\"/g; chomp($newfrom); #~~ # Remove JavaScript From BODY #~~ $body =~ s#]*>#NOTE: This email contained Javascript, which was removed upon arrival#ig; $body =~ s#document.cookie##gi; #~~ # Remove FORM tags #~~ $body =~ s/