From 40ee94523e96a5023b4989bcba8fc244980c2129 Mon Sep 17 00:00:00 2001 From: lkehresman Date: Sat, 4 Dec 1999 21:42:37 +0000 Subject: [PATCH] Composing messages works great! git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@59 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/smtp.php | 52 +++++++++++++++++++++++++++---------------- functions/strings.php | 20 +++++++++++++++++ src/compose.php | 35 ++++++++++++++++++++++++++--- src/compose_send.php | 14 +++++++++--- 4 files changed, 96 insertions(+), 25 deletions(-) diff --git a/functions/smtp.php b/functions/smtp.php index bae3ccb8..d2865bec 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -16,9 +16,11 @@ } } - function sendMessage($smtpServerAddress, $smtpPort, $to, $subject, $body) { - $to = addslashes($to); - $body = addslashes($body); + function sendMessage($smtpServerAddress, $smtpPort, $username, $domain, $t, $c, $b, $subject, $body, $version) { + $to = parseAddrs($t); + $cc = parseAddrs($c); + $bcc = parseAddrs($b); + $body = $body; $from = "$username@$domain"; echo ""; @@ -28,27 +30,39 @@ echo "$errorNumber : $errorString
"; exit; } - echo htmlspecialchars(fgets($smtpConnection, 1024)) . "
"; + $to_list = getLineOfAddrs($to); + $cc_list = getLineOfAddrs($cc); + + /** Lets introduce ourselves */ + fputs($smtpConnection, "HELO $domain\n"); + /** Ok, who is sending the message? */ fputs($smtpConnection, "MAIL FROM:<$from>\n"); - echo htmlspecialchars(fgets($smtpConnection, 1024)) . "
"; - fputs($smtpConnection, "RCPT TO:<$to>\n"); - echo htmlspecialchars(fgets($smtpConnection, 1024)) . "
"; + /** send who the recipients are */ + for ($i = 0; $i < count($to); $i++) { + fputs($smtpConnection, "RCPT TO:<$to[$i]>\n"); + } + for ($i = 0; $i < count($cc); $i++) { + fputs($smtpConnection, "RCPT TO:<$cc[$i]>\n"); + } + for ($i = 0; $i < count($bcc); $i++) { + fputs($smtpConnection, "RCPT TO:<$bcc[$i]>\n"); + } + /** Lets start sending the actual message */ fputs($smtpConnection, "DATA\n"); - echo htmlspecialchars(fgets($smtpConnection, 1024)) . "
"; - - fputs($smtpConnection, "Subject: $subject\n"); - fputs($smtpConnection, "Date: " . date() . "\n"); - fputs($smtpConnection, "To: <$to>\n"); - fputs($smtpConnection, "From: <$from>\n"); - fputs($smtpConnection, "$body\n"); - fputs($smtpConnection, ".\n"); - echo htmlspecialchars(fgets($smtpConnection, 1024)) . "
"; - - fputs($smtpConnection, "QUIT\n"); - echo htmlspecialchars(fgets($smtpConnection, 1024)) . "
"; + fputs($smtpConnection, "Subject: $subject\n"); // Subject + fputs($smtpConnection, "To: <$to_list>\n"); // Who it's TO + if ($cc_list) { + fputs($smtpConnection, "Cc: <$cc_list>\n"); // Who the CCs are + } + fputs($smtpConnection, "X-Mailer: SquirrelMail (version $version)\n"); // Identify SquirrelMail + + fputs($smtpConnection, "$body\n"); // send the body of the message + fputs($smtpConnection, ".\n"); // end the DATA part + fputs($smtpConnection, "QUIT\n"); // log off + echo "
"; } ?> \ No newline at end of file diff --git a/functions/strings.php b/functions/strings.php index d00cd835..348b62d7 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -57,4 +57,24 @@ } return $line; } + + /** Returns an array of email addresses **/ + function parseAddrs($text) { + $text = str_replace(" ", "", $text); + $text = str_replace(",", ";", $text); + $array = explode(";", $text); + return $array; + } + + /** Returns a line of comma separated email addresses from an array **/ + function getLineOfAddrs($array) { + $to_line = ""; + for ($i = 0; $i < count($array); $i++) { + if ($to_line) + $to_line = "$to_line, $array[$i]"; + else + $to_line = "$array[$i]"; + } + return $to_line; + } ?> diff --git a/src/compose.php b/src/compose.php index e78c515b..d88e087d 100644 --- a/src/compose.php +++ b/src/compose.php @@ -12,9 +12,38 @@ echo "
\n"; echo "
"; - echo ""; - echo ""; - echo "
"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " To: \n"; + echo " \n"; + echo "
"; + echo "
\n"; + echo " CC:\n"; + echo " \n"; + echo "
"; + echo "
\n"; + echo " BCC:\n"; + echo " \n"; + echo "
"; + echo "
\n"; + echo " Subject:\n"; + echo " \n"; + echo "
"; + echo "
\n"; + + echo "
"; echo ""; echo "
"; echo "
"; diff --git a/src/compose_send.php b/src/compose_send.php index aba3ccf7..b3d6a79c 100644 --- a/src/compose_send.php +++ b/src/compose_send.php @@ -1,3 +1,6 @@ + + + RETURN"; -?> \ No newline at end of file + sendMessage($smtpServerAddress, $smtpPort, $username, $domain, $passed_to, $passed_cc, $passed_bcc, $passed_subject, $passed_body, $version); + + echo ""; + echo "


Message Sent!

"; + echo "You will be automatically forwarded.
If not, click here"; + echo "
"; +?> + \ No newline at end of file -- 2.25.1