X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fsmtp.php;h=0c66f44e96779aecea0d956e03ef2925b49ed5d9;hb=f972eb466c6678220bd89b217d7904ce7ae3072e;hp=56524653dc73274648359d67adc090b31ee287b2;hpb=1b618a3dc66161a769647bc4791fd501df91e088;p=squirrelmail.git diff --git a/functions/smtp.php b/functions/smtp.php index 56524653..0c66f44e 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -8,6 +8,8 @@ **/ $smtp_php = true; + if (!isset($addressbook_php)) + include('../functions/addressbook.php'); // This should most probably go to some initialization... if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { @@ -31,6 +33,28 @@ return false; } + // looks up aliases in the addressbook and expands them to + // the full address. + function expandAddrs ($array) { + $abook = addressbook_init(); + for ($i=0; $i < count($array); $i++) { + $result = $abook->lookup($array[$i]); + $ret = ""; + if (isset($result['email'])) { + if (isset($result['name'])) { + $ret = '"'.$result['name'].'" '; + } + $ret .= '<'.$result['email'].'>'; + $array[$i] = $ret; + } + else + { + $array[$i] = '<' . $array[$i] . '>'; + } + } + return $array; + } + // Attach the files that are due to be attached function attachFiles ($fp) { global $attachments, $attachment_dir; @@ -38,27 +62,22 @@ $length = 0; if (isMultipart()) { - reset($attachments); - while (list($localname, $remotename) = each($attachments)) { - // This is to make sure noone is giving a filename in another - // directory - $localname = ereg_replace ("\\/", '', $localname); - - $fileinfo = fopen ($attachment_dir.$localname.'.info', 'r'); - $filetype = fgets ($fileinfo, 8192); - fclose ($fileinfo); - $filetype = trim ($filetype); - if ($filetype=='') + foreach ($attachments as $info) + { + $filetype = $info['type']; + if ($filetype == '') $filetype = 'application/octet-stream'; $header = '--'.mimeBoundary()."\r\n"; - $header .= "Content-Type: $filetype;name=\"$remotename\"\r\n"; - $header .= "Content-Disposition: attachment; filename=\"$remotename\"\r\n"; + $header .= "Content-Type: $filetype; name=\"" . + $info['remotefilename'] . "\"\r\n"; + $header .= "Content-Disposition: attachment; filename=\"" . + $info['remotefilename'] . "\"\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n\r\n"; fputs ($fp, $header); $length += strlen($header); - $file = fopen ($attachment_dir.$localname, 'r'); + $file = fopen ($attachment_dir . $info['localfilename'], 'r'); while ($tmp = fread($file, 570)) { $encoded = chunk_split(base64_encode($tmp)); $length += strlen($encoded); @@ -91,7 +110,8 @@ static $mimeBoundaryString; if ($mimeBoundaryString == "") { - $mimeBoundaryString = GenerateRandomString(70, '\'()+,-./:=?_', 7); + $mimeBoundaryString = "----=_" . + GenerateRandomString(60, '\'()+,-./:=?_', 7); } return $mimeBoundaryString; @@ -131,9 +151,9 @@ static $header, $headerlength; if ($header == '') { - $to = parseAddrs($t); - $cc = parseAddrs($c); - $bcc = parseAddrs($b); + $to = expandAddrs(parseAddrs($t)); + $cc = expandAddrs(parseAddrs($c)); + $bcc = expandAddrs(parseAddrs($b)); $reply_to = getPref($data_dir, $username, 'reply_to'); $from = getPref($data_dir, $username, 'full_name'); $from_addr = getPref($data_dir, $username, 'email_address'); @@ -146,7 +166,7 @@ $bcc_list = getLineOfAddrs($bcc); /* Encoding 8-bit characters and making from line */ - $subject = sqStripSlashes(encodeHeader($subject)); + $subject = encodeHeader($subject); if ($from == '') $from = "<$from_addr>"; else @@ -181,7 +201,7 @@ $header .= "Date: $date\r\n"; $header .= "Subject: $subject\r\n"; $header .= "From: $from\r\n"; - $header .= "To: $to_list \r\n"; // Who it's TO + $header .= "To: $to_list\r\n"; // Who it's TO /* Insert headers from the $more_headers array */ if(is_array($more_headers)) { @@ -247,15 +267,16 @@ $body .= "Content-Type: text/plain\r\n"; $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; - $body .= sqStripSlashes($passedBody) . "\r\n\r\n"; + $body .= $passedBody . "\r\n\r\n"; fputs ($fp, $body); $attachmentlength = attachFiles($fp); + if (!isset($postbody)) $postbody = ""; $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n"; fputs ($fp, $postbody); } else { - $body = sqStripSlashes($passedBody) . "\r\n"; + $body = $passedBody . "\r\n"; fputs ($fp, $body); $postbody = "\r\n"; fputs ($fp, $postbody); @@ -302,9 +323,9 @@ global $username, $popuser, $domain, $version, $smtpServerAddress, $smtpPort, $data_dir, $color; - $to = parseAddrs($t); - $cc = parseAddrs($c); - $bcc = parseAddrs($b); + $to = expandAddrs(parseAddrs($t)); + $cc = expandAddrs(parseAddrs($c)); + $bcc = expandAddrs(parseAddrs($b)); $from_addr = getPref($data_dir, $username, 'email_address'); if (!$from_addr) @@ -328,23 +349,23 @@ errorCheck($tmp, $smtpConnection); /** Ok, who is sending the message? */ - fputs($smtpConnection, "MAIL FROM:<$from_addr>\r\n"); + fputs($smtpConnection, "MAIL FROM: <$from_addr>\r\n"); $tmp = fgets($smtpConnection, 1024); errorCheck($tmp, $smtpConnection); /** send who the recipients are */ for ($i = 0; $i < count($to); $i++) { - fputs($smtpConnection, "RCPT TO:<$to[$i]>\r\n"); + fputs($smtpConnection, "RCPT TO: $to[$i]\r\n"); $tmp = fgets($smtpConnection, 1024); errorCheck($tmp, $smtpConnection); } for ($i = 0; $i < count($cc); $i++) { - fputs($smtpConnection, "RCPT TO:<$cc[$i]>\r\n"); + fputs($smtpConnection, "RCPT TO: $cc[$i]\r\n"); $tmp = fgets($smtpConnection, 1024); errorCheck($tmp, $smtpConnection); } for ($i = 0; $i < count($bcc); $i++) { - fputs($smtpConnection, "RCPT TO:<$bcc[$i]>\r\n"); + fputs($smtpConnection, "RCPT TO: $bcc[$i]\r\n"); $tmp = fgets($smtpConnection, 1024); errorCheck($tmp, $smtpConnection); } @@ -490,7 +511,7 @@ $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1); - if ($reply_id) { + if (isset($reply_id) && $reply_id) { sqimap_mailbox_select ($imap_stream, $mailbox); sqimap_messages_flag ($imap_stream, $reply_id, $reply_id, 'Answered'); @@ -508,17 +529,14 @@ // 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); + $body = ereg_replace("\n\\.", "\n..", $body); + $body = ereg_replace("^\\.", "..", $body); // this is to catch all plain \n instances and // replace them with \r\n. $body = ereg_replace("\r\n", "\n", $body); $body = ereg_replace("\n", "\r\n", $body); - // Make sure that $t does not contain newlines. - $t = ereg_replace("[\n|\r]", "", $t); - if ($useSendmail) { $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers); } else { @@ -533,7 +551,7 @@ } sqimap_logout($imap_stream); // Delete the files uploaded for attaching (if any). - deleteAttachments(); + ClearAttachments(); } ?>