Viewing file: send.pl (4.27 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/perl
###########################################################################
# send.pl - Let the user send a message
###########################################################################
require "common.pl";
use Socket;
use POSIX qw(strftime);
###########################################################################
# Print the header
###########################################################################
if ($button eq $cancel_button) {
&cancel;
} elsif ($remip ne $fromip) {
&diffip;
}
&print_header;
if ($button eq $send_button) {
$display_message = $message;
$message =~ s/\>\;/>/g;
$message =~ s/\<\;/</g;
$message =~ s/\"\;/"/g;
###########################################################################
# Open socket to SMTP server
###########################################################################
$proto = getprotobyname('tcp');
socket(SOCK, AF_INET, SOCK_STREAM, $proto);
$iaddr = gethostbyname($smtpserver);
$port = getservbyname('smtp', 'tcp');
$sin = sockaddr_in($port, $iaddr);
connect(SOCK, $sin);
@to = split (/,\s/, $to);
@cc = split (/,\s/, $cc);
@bcc = split (/,\s/, $bcc);
$message =~ s/\n\.[\r|\n]/\n. $1/g;
$date = strftime("%a, %d %b %Y %T %z (%Z)", localtime);
###########################################################################
# Send message
###########################################################################
$bad = "No";
send SOCK, "HELO $domain\r\n", 0;
recv SOCK, $junk, 512, 0;
if ($junk =~ /^5/) {
$bad = "Yes";
}
send SOCK, "MAIL From:<$from>\r\n", 0;
recv SOCK, $junk, 512, 0;
if ($junk =~ /^5/) {
$bad = "Yes";
}
foreach $line (@to) {
send SOCK, "RCPT To:<$line>\r\n", 0;
}
foreach $line (@cc) {
send SOCK, "RCPT To:<$line>\r\n", 0;
}
foreach $line (@bcc) {
send SOCK, "RCPT To:<$line>\r\n", 0;
}
recv SOCK, $junk, 512, 0;
if ($junk =~ /^5/) {
$bad = "Yes";
}
send SOCK, "DATA\r\n", 0;
recv SOCK, $junk, 512, 0;
if ($junk =~ /^5/) {
$bad = "Yes";
}
if ($resent) {
send SOCK, "Resent-From: $resent\r\n", 0;
}
send SOCK, "Date: $date\r\n", 0;
send SOCK, "To: $to\r\n", 0;
if ($cc) {
send SOCK, "Cc: $cc\r\n", 0;
}
if (!($resent)) {
send SOCK, "Subject: $subject\r\n", 0;
send SOCK, "X-Mailer: $version\r\n", 0;
send SOCK, "X-URL: $x_url\r\n", 0;
}
if ($attachment) {
$type = $query->uploadInfo($attachment)->{"Content-Type"};
$boundary = "-ATDOT-ATTACH-BOUNDARY-" . time . "---";
@filename = split(/\/|\\|:/, $attachment);
send SOCK, "MIME-Version: 1.0\r\n", 0;
send SOCK, "Content-Type: multipart/mixed; ", 0;
send SOCK, "boundary=\"$boundary\"\r\n", 0;
send SOCK, "\r\n--$boundary\r\n", 0;
send SOCK, "Content-type: text/plain\r\n\r\n", 0;
send SOCK, "$message\r\n", 0;
send SOCK, "\r\n--$boundary\r\n", 0;
send SOCK, "Content-Type: $type; name=\"$filename[-1]\"\r\n", 0;
send SOCK, "Content-Transfer-Encoding: BASE64\r\n", 0;
send SOCK, "Content-Description:\r\n\r\n", 0;
while (<$attachment>) { $temp .= $_; }
send SOCK, encode_base64($temp), 0;
send SOCK, "--$boundary--", 0;
send SOCK, "\r\n.\r\n", 0;
} else {
send SOCK, "\r\n$message\r\n.\r\n", 0;
}
recv SOCK, $junk, 512, 0;
if ($junk =~ /^5/) {
$bad = "Yes";
}
send SOCK, "QUIT\r\n", 0;
recv SOCK, $junk, 512, 0;
if ($junk =~ /^5/) {
$bad = "Yes";
}
close SOCK;
###########################################################################
# Show the user what was sent
###########################################################################
if ($bad eq "No"){
if ($btns eq 'top' || $btns eq 'both' ) { &print_options; }
print $message_sent_info;
print "<PRE>$from_input $from\n";
print "$to_input $to\n";
if ($cc) {
print "$cc_input $cc\n";
}
if ($bcc) {
print "$bcc_input $bcc\n";
}
if ($attachment) {
print "$attach_input $filename[-1]\n";
}
print "$subj_input $subject\n";
if ($resent) {
print "$resent_input $resent\n";
} else {
print "\n";
}
print "$message</PRE>";
} else {
print $no_send_info;
&send_form;
}
}
###########################################################################
# Done
###########################################################################
if (($btns eq 'bottom' || $btns eq 'both') && ($bad eq 'No')) { &print_options; }
&update_sess;
&print_footer;
|