X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fsmtp.php;h=d6cff03768b056a66e2f58c136d9667f6310c6ae;hp=9bcda6fcd0ab3051349e19aa3713e5bc4294d9a6;hb=eaaf577300d3f062095c5257d44768c1e227871f;hpb=46beee9f7b85b741b3920624bcf342d7ccb4a5e5;ds=sidebyside diff --git a/functions/smtp.php b/functions/smtp.php index 9bcda6fc..d6cff037 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -77,7 +77,6 @@ function expandAddrs ($array) { return $array; } - /* looks up aliases in the addressbook and expands them to * the RFC 821 valid RCPT address. ie * Adds @$domain if it wasn't in the address book and if it @@ -110,8 +109,8 @@ function expandRcptAddrs ($array) { /* Attach the files that are due to be attached */ -function attachFiles ($fp, $session, $rn="\r\n") { - global $attachments, $attachment_dir, $username; +function attachFiles ($fp, $session, $rn="\r\n", $checkdot = false) { + global $attachments, $attachment_dir, $username, $languages, $squirrelmail_language; $length = 0; @@ -129,10 +128,16 @@ function attachFiles ($fp, $session, $rn="\r\n") { $header = '--' . mimeBoundary() . "$rn"; if ( isset($info['remotefilename']) && $info['remotefilename'] != '') { + $remotefilename = $info['remotefilename']; + if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && + function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { + $remotefilename = + $languages[$squirrelmail_language]['XTRA_CODE']('encode', $remotefilename); + } $header .= "Content-Type: $filetype; name=\"" . - $info['remotefilename'] . "\"$rn"; + encodeHeader($remotefilename) . "\"$rn"; $header .= "Content-Disposition: attachment; filename=\"" - . $info['remotefilename'] . "\"$rn"; + . encodeHeader($remotefilename) . "\"$rn"; } else { $header .= "Content-Type: $filetype$rn"; } @@ -148,26 +153,51 @@ function attachFiles ($fp, $session, $rn="\r\n") { if (substr($filetype, 0, 5) == 'text/' || substr($filetype, 0, 8) == 'message/' ) { $header .= $rn; - if ($fp) { - fputs ($fp, $header); - } + if ($fp) { + fputs ($fp, $header); + } $length += strlen($header); + + if ($checkdot) { + $checkdot_begin=true; + } else { + $checkdot_begin=false; + } + while ($tmp = fgets($file, 4096)) { $tmp = str_replace("\r\n", "\n", $tmp); $tmp = str_replace("\r", "\n", $tmp); if ($rn == "\r\n"){ $tmp = str_replace("\n", "\r\n", $tmp); } + if ($tmp{0} == '.' && $checkdot_begin) { + $tmp = '.' . $tmp; + } + if ($checkdot) { + $tmp = str_replace("\n.","\n..",$tmp); + } + + $tmp_length = strlen($tmp); + if ($tmp_length && $tmp{$tmp_length-1} == "\n" && $checkdot) { + $checkdot_begin = true; + } else { + $checkdot_begin = false; + } + + if ($fp) { fputs($fp, $tmp); } - $length += strlen($tmp); + $length += $tmp_length; } - if (substr($tmp, strlen($tmp) - strlen($rn), strlen($rn)) != $rn) { + if (substr($tmp, $tmp_length - strlen($rn), strlen($rn)) != $rn) { if ($fp) { fputs($fp, $rn); } + $length += strlen($rn); } + + } else { $header .= "Content-Transfer-Encoding: base64" . "$rn" . "$rn"; @@ -248,7 +278,7 @@ function timezone () { } /* Print all the needed RFC822 headers */ -function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session, $rn="\r\n") { +function write822Header ($fp, $t, $c, $b, $subject, $body, $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; @@ -376,9 +406,19 @@ function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session, $rn $header .= mimeBoundary(); $header .= "\"$rn"; } else { + if (strtolower($default_charset) == 'iso-2022-jp') { + if (mb_detect_encoding($body) == 'ASCII') { + $header .= 'Content-Type: text/plain; US-ASCII' . $rn; + $header .= "Content-Transfer-Encoding: 8bit" . $rn; + } else { + $header .= 'Content-Type: '.$contentType . $rn; + $header .= "Content-Transfer-Encoding: 7bit" . $rn; + } + } else { $header .= 'Content-Type: ' . $contentType . $rn; $header .= "Content-Transfer-Encoding: 8bit" . $rn; } + } $header .= $rn; // One blank line to separate header and body $headerlength = strlen($header); @@ -398,7 +438,7 @@ function write822Header ($fp, $t, $c, $b, $subject, $more_headers, $session, $rn /* Send the body */ -function writeBody ($fp, $passedBody, $session, $rn="\r\n") { +function writeBody ($fp, $passedBody, $session, $rn="\r\n", $checkdot = false) { global $default_charset; $attachmentlength = 0; @@ -413,11 +453,23 @@ function writeBody ($fp, $passedBody, $session, $rn="\r\n") { $body .= "Content-Type: text/plain" . $rn; } - $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn; - $body .= $passedBody . $rn . $rn; - if ($fp) fputs ($fp, $body); + if (strtolower($default_charset) == 'iso-2022-jp') { + if (mb_detect_encoding($passedBody) == 'ASCII') { + $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn . + $passedBody . $rn . $rn; + } else { + $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n" . + mb_convert_encoding($passedBody, 'JIS') . "\r\n\r\n"; + } + } else { + $body .= "Content-Transfer-Encoding: 8bit" . $rn . $rn . + $passedBody . $rn . $rn; + } + if ($fp) { + fputs ($fp, $body); + } - $attachmentlength = attachFiles($fp, $session, $rn); + $attachmentlength = attachFiles($fp, $session, $rn, $checkdot); if (!isset($postbody)) { $postbody = ""; @@ -425,15 +477,24 @@ function writeBody ($fp, $passedBody, $session, $rn="\r\n") { $postbody .= $rn . "--" . mimeBoundary() . "--" . $rn . $rn; if ($fp) fputs ($fp, $postbody); } else { - $body = $passedBody . $rn; - if ($fp) fputs ($fp, $body); + if (strtolower($default_charset) == 'iso-2022-jp') { + $body = mb_convert_encoding($passedBody, 'JIS') . $rn; + } else { + $body = $passedBody . $rn; + } + if ($fp) { + fputs ($fp, $body); + } $postbody = $rn; - if ($fp) fputs ($fp, $postbody); + if ($fp) { + fputs ($fp, $postbody); + } } return (strlen($body) + strlen($postbody) + $attachmentlength); } + /* Send mail using the sendmail command */ function sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session) { @@ -458,9 +519,9 @@ function sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session) { $fp = popen (escapeshellcmd("$sendmail_path -t -f$envelopefrom"), "w"); } - $headerlength = write822Header ($fp, $t, $c, $b, $subject, + $headerlength = write822Header ($fp, $t, $c, $b, $subject, $body, $more_headers, $session, "\n"); - $bodylength = writeBody($fp, $body, $session, "\n"); + $bodylength = writeBody($fp, $body, $session, "\n", true); pclose($fp); @@ -616,8 +677,8 @@ function sendSMTP($t, $c, $b, $subject, $body, $more_headers, $session) { /* Send the message */ $headerlength = write822Header ($smtpConnection, $t, $c, $b, - $subject, $more_headers, $session); - $bodylength = writeBody($smtpConnection, $body, $session); + $subject, $body, $more_headers, $session); + $bodylength = writeBody($smtpConnection, $body, $session,"\r\n", true); fputs($smtpConnection, ".\r\n"); /* end the DATA part */ $tmp = fgets($smtpConnection, 1024); @@ -749,7 +810,7 @@ function calculate_references($refs, $inreplyto, $old_reply_to) { $refer = ""; for ($i=1;$i') { + $refer .= $ref . ' '; + } + } $refer = trim($refer); if (strlen($refer) > 2) { $refer .= ' ' . $inreplyto; @@ -789,7 +858,7 @@ function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, if (isset($reply_id) && $reply_id) { sqimap_mailbox_select ($imap_stream, $mailbox); - sqimap_messages_flag ($imap_stream, $reply_id, $reply_id, 'Answered'); + sqimap_messages_flag ($imap_stream, $reply_id, $reply_id, 'Answered', true); /* Insert In-Reply-To and References headers if the * message-id of the message we reply to is set (longer than "<>") @@ -836,41 +905,42 @@ function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, if ( $requestRecipt > 0) { $more_headers = array_merge($more_headers, createReceiptHeaders($requestRecipt)); } - - /* In order to remove the problem of users not able to create - * messages with "." on a blank line, RFC821 has made provision - * in section 4.5.2 (Transparency). - */ - $body = ereg_replace("\n\\.", "\n..", $body); - $body = ereg_replace("^\\.", "..", $body); - - /* this is to catch all plain \n instances and - * replace them with \r\n. All newlines were converted - * into just \n inside the compose.php file. - * But only if delimiter is, in fact, \r\n. - */ - if ($MDN) { $more_headers["Content-Type"] = "multipart/report; ". "report-type=disposition-notification;"; } - + $imap_body = $body; if ($useSendmail) { - $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers, + /* In order to remove the problem of users not able to create + * messages with "." on a blank line, RFC821 has made provision + * in section 4.5.2 (Transparency). + */ + if (($body && $body{0} == '.')) { + $body = '.' . $body; + } + $body = str_replace("\n.","\n..",$body); + $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers, $session); - $body = ereg_replace("\n", "\r\n", $body); } else { - $body = ereg_replace("\n", "\r\n", $body); + /* In order to remove the problem of users not able to create + * messages with "." on a blank line, RFC821 has made provision + * in section 4.5.2 (Transparency). + */ + if (($body && $body{0} == '.')) { + $body = '.' . $body; + } + $body = str_replace("\n.","\n..",$body); $length = sendSMTP($t, $c, $b, $subject, $body, $more_headers, $session); } if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) { - $headerlength = write822Header (FALSE, $t, $c, $b, $subject, $more_headers, $session, "\r\n"); - $bodylength = writeBody(FALSE, $body, $session, "\r\n"); - $length = $headerlength + $bodylength; - + $body = $imap_body; + $body = ereg_replace("\n", "\r\n", $body); + $headerlength = write822Header (false, $t, $c, $b, $subject, $body, $more_headers, $session, "\r\n"); + $bodylength = writeBody(false, $body, $session, "\r\n"); + $length = $headerlength + $bodylength; sqimap_append ($imap_stream, $sent_folder, $length); - write822Header ($imap_stream, $t, $c, $b, $subject, $more_headers, + write822Header ($imap_stream, $t, $c, $b, $subject, $body, $more_headers, $session); writeBody ($imap_stream, $body, $session); sqimap_append_done ($imap_stream); @@ -882,7 +952,6 @@ function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, if ($length) { ClearAttachments($session); } - return $length; }