From 465db5d77d307359c7e4a2f526186c758db0dd50 Mon Sep 17 00:00:00 2001 From: nehresma Date: Wed, 12 Jan 2000 14:04:29 +0000 Subject: [PATCH] added patch to allow use of sendmail instead of connecting to SMTP port if desired. (Thanks to Gustav Foseid for this patch) git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@152 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- config/config.php | 5 ++++ functions/smtp.php | 60 ++++++++++++++++++++++++++++++++++++++++++-- src/compose_send.php | 4 +-- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/config/config.php b/config/config.php index 58b3ebad..8a49bf27 100644 --- a/config/config.php +++ b/config/config.php @@ -23,6 +23,11 @@ $smtpServerAddress = "localhost"; $smtpPort = 25; +// Uncomment this if you want to deliver locally using sendmail instead +// of connecting to a SMTP-server +// $useSendmail = true; +// $sendmail_path = "/usr/sbin/sendmail"; + // This is displayed right after they log in $motd = "You are using SquirrelMail's web-based email client. If you run into any bugs or have suggestions, please report them to our mailing list"; diff --git a/functions/smtp.php b/functions/smtp.php index 05f16f3c..2034191d 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -5,6 +5,62 @@ ** an smtp server. **/ + function sendMessage($username, $domain, $t, $c, $b, $subject, $body, $version) { + include("../config/config.php"); + + if ($useSendmail==true) { + sendSendmail($username, $domain, $t, $c, $b, $subject, $body, $version); + } else { + sendSMTP($username, $domain, $t, $c, $b, $subject, $body, $version); + } + + } + + // Send mail using the sendmail command + function sendSendmail($username, $domain, $t, $c, $b, $subject, $body, $version) { + include("../config/config.php"); + + // This is pretty much equal to the code in sendSMTP + $to = parseAddrs($t); + $cc = parseAddrs($c); + $bcc = parseAddrs($b); + $from_addr = "$username@$domain"; + $reply_to = getPref($data_dir, $username, "reply_to"); + $from = getPref($data_dir, $username, "full_name"); + + $to_list = getLineOfAddrs($to); + $cc_list = getLineOfAddrs($cc); + $bcc_list = getLineOfAddrs($bcc); + + if ($from == "") + $from = "<$from_addr>"; + else + $from = $from . " <$from_addr>"; + + // open pipe to sendmail + $fp = popen ("$sendmail_path -t -f$from_addr", "w"); + + fputs($fp, "Subject: $subject\n"); // Subject + fputs($fp, "From: $from\n"); // Subject + fputs($fp, "To: $to_list\n"); // Who it's TO + + if ($cc_list) { + fputs($fp, "Cc: $cc_list\n"); // Who the CCs are + } + if ($bcc_list) { + fputs($fp, "Bcc: $bcc_list\n"); // BCCs is removed from header by sendmail + } + fputs($fp, "X-Mailer: SquirrelMail (version $version)\n"); // Identify SquirrelMail + fputs($fp, "MIME-Version: 1.0\n"); + fputs($fp, "Content-Type: text/plain\n"); + if ($reply_to != "") + fputs($fp, "Reply-To: $reply_to\n"); + + fputs($fp, "\n$body\n"); // send the body of the message + + pclose($fp); + } + function smtpReadData($smtpConnection) { $read = fgets($smtpConnection, 1024); $counter = 0; @@ -16,7 +72,7 @@ } } - function sendMessage($smtpServerAddress, $smtpPort, $username, $domain, $t, $c, $b, $subject, $body, $version) { + function sendSMTP($username, $domain, $t, $c, $b, $subject, $body, $version) { include("../config/config.php"); $to = parseAddrs($t); @@ -197,4 +253,4 @@ } return $err_num; } -?> \ No newline at end of file +?> diff --git a/src/compose_send.php b/src/compose_send.php index ce159eec..1890d792 100644 --- a/src/compose_send.php +++ b/src/compose_send.php @@ -52,7 +52,7 @@ $passed_bcc = stripslashes($passed_bcc); $passed_subject = stripslashes($passed_subject); - sendMessage($smtpServerAddress, $smtpPort, $username, $domain, $passed_to, $passed_cc, $passed_bcc, $passed_subject, $passed_body, $version); + sendMessage($username, $domain, $passed_to, $passed_cc, $passed_bcc, $passed_subject, $passed_body, $version); if ($auto_forward == true) echo ""; @@ -64,4 +64,4 @@ echo "You will be automatically forwarded.
If not, click here"; echo ""; ?> - \ No newline at end of file + -- 2.25.1