X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fsmtp.php;h=5e75527d6bfbf9584f022de6282066fb44887690;hp=ffa3d43f2fb34a9ca3d0915470d9ee8e97664997;hb=e12256041f08f9e254885450572bd27033307ab0;hpb=41336c5f3546db383788319f4a5e325202f904ee diff --git a/functions/smtp.php b/functions/smtp.php index ffa3d43f..5e75527d 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -31,20 +31,6 @@ if (!$domain) { $domain = getenv('HOSTNAME'); } -/** - * Return which separator we should be using. - * \r\n for SMTP delivery, just \n for Sendmail. - */ -function sqm_nrn(){ - global $useSendmail; - if ($useSendmail){ - return "\n"; - } else { - return "\r\n"; - } -} - - /* Returns true only if this message is multipart */ function isMultipart ($session) { global $attachments; @@ -124,11 +110,10 @@ function expandRcptAddrs ($array) { /* Attach the files that are due to be attached */ -function attachFiles ($fp, $session) { +function attachFiles ($fp, $session, $rn="\r\n") { global $attachments, $attachment_dir, $username; $length = 0; - $rn = sqm_nrn(); $hashed_attachment_dir = getHashedDir($username, $attachment_dir); if (isMultipart($session)) { @@ -260,15 +245,12 @@ function timezone () { } /* Print all the needed RFC822 headers */ -function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session) { +function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session, $rn="\r\n") { global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT; global $data_dir, $username, $popuser, $domain, $version, $useSendmail; global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR; global $REMOTE_HOST, $identity; - /** - * Get which delimiter we are going to use. - */ - $rn = sqm_nrn(); + /* Storing the header to make sure the header is the same * everytime the header is printed. */ @@ -281,16 +263,11 @@ function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session) { if (isset($identity) && $identity != 'default') { $reply_to = getPref($data_dir, $username, 'reply_to' . $identity); $from = getPref($data_dir, $username, 'full_name' . $identity); - $from_addr = getPref($data_dir, $username, - 'email_address' . $identity); + $from_addr = getFrom(); } else { $reply_to = getPref($data_dir, $username, 'reply_to'); $from = getPref($data_dir, $username, 'full_name'); - $from_addr = getPref($data_dir, $username, 'email_address'); - } - - if ($from_addr == '') { - $from_addr = $popuser.'@'.$domain; + $from_addr = getFrom(); } $to_list = getLineOfAddrs($to); @@ -362,6 +339,9 @@ function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session) { if(is_array($more_headers)) { reset($more_headers); while(list($h_name, $h_val) = each($more_headers)) { + if ($h_name == 'References') { + $h_val = str_replace(' ', "$rn ", $h_val); + } $header .= sprintf("%s: %s%s", $h_name, $h_val, $rn); } } @@ -408,12 +388,8 @@ function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session) { /* Send the body */ -function writeBody ($fp, $passedBody, $session) { +function writeBody ($fp, $passedBody, $session, $rn="\r\n") { global $default_charset; - /** - * Get delimiter. - */ - $rn = sqm_nrn(); $attachmentlength = 0; @@ -431,7 +407,7 @@ function writeBody ($fp, $passedBody, $session) { $body .= $passedBody . $rn . $rn; fputs ($fp, $body); - $attachmentlength = attachFiles($fp, $session); + $attachmentlength = attachFiles($fp, $session, $rn); if (!isset($postbody)) { $postbody = ""; @@ -457,7 +433,7 @@ function sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session) { * spaces or other "weird" chars that would allow a user to * exploit the shell/pipe it is used in. */ - $envelopefrom = "$popuser@$domain"; + $envelopefrom = getFrom(); $envelopefrom = ereg_replace("[[:blank:]]",'', $envelopefrom); $envelopefrom = ereg_replace("[[:space:]]",'', $envelopefrom); $envelopefrom = ereg_replace("[[:cntrl:]]",'', $envelopefrom); @@ -473,11 +449,11 @@ function sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session) { } $headerlength = write822Header ($fp, $t, $c, $b, $subject, - $more_headers, $session); - $bodylength = writeBody($fp, $body, $session); + $more_headers, $session, "\n"); + $bodylength = writeBody($fp, $body, $session, "\n"); pclose($fp); - + return ($headerlength + $bodylength); } @@ -759,10 +735,7 @@ function errorCheck($line, $smtpConnection, $verbose = false) { /* create new reference header per rfc2822 */ function calculate_references($refs, $inreplyto, $old_reply_to) { - /** - * Get the delimiter. - */ - $rn = sqm_nrn(); + $refer = ""; for ($i=1;$i 2) { $refs = get_reference_header ($imap_stream, $reply_id); $inreplyto = $message_id; @@ -872,9 +839,6 @@ function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, * into just \n inside the compose.php file. * But only if delimiter is, in fact, \r\n. */ - if ($rn == "\r\n"){ - $body = ereg_replace("\n", "\r\n", $body); - } if ($MDN) { $more_headers["Content-Type"] = "multipart/report; ". @@ -885,10 +849,12 @@ function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session); } else { + $body = ereg_replace("\n", "\r\n", $body); $length = sendSMTP($t, $c, $b, $subject, $body, $more_headers, $session); } if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) { + if ($useSendmail) $body = ereg_replace("\n", "\r\n", $body); sqimap_append ($imap_stream, $sent_folder, $length); write822Header ($imap_stream, $t, $c, $b, $subject, $more_headers, $session); @@ -966,5 +932,24 @@ function createReceiptHeaders($receipt) { return $receipt_headers; } +/* Figure out what the 'From:' address is + */ + +function getFrom() { + global $username, $popuser, $domain, $data_dir, $identity; + if (isset($identity) && $identity != 'default') { + $from_addr = getPref($data_dir, $username, + 'email_address' . $identity); + } + else { + $from_addr = getPref($data_dir, $username, 'email_address'); + } + + if (!$from_addr) { + $from_addr = "$popuser@$domain"; + } + return $from_addr; +} + ?>