} else {
$boundary='';
}
+ $raw_length = 0;
$reply_rfc822_header = (isset($message->reply_rfc822_header)
? $message->reply_rfc822_header : '');
- $header = $this->prepareRFC822_Header($rfc822_header, $reply_rfc822_header);
- $raw_length = strlen($header);
+ $header = $this->prepareRFC822_Header($rfc822_header, $reply_rfc822_header, $raw_length);
+
if ($stream) {
$this->preWriteToStream($header);
$this->writeToStream($stream, $header);
if ($i == $entCount-1) $last = true;
}
if ($boundary && $last) {
- $s = "\r\n--".$boundary."--\r\n\r\n";
+ $s = "--".$boundary."--\r\n\r\n";
$length_raw += strlen($s);
if ($stream) {
$this->preWriteToStream($s);
} else {
$type0 = $message->rfc822_header->content_type->type0;
}
+
+ $body_part_trailing = $last = '';
switch ($type0) {
case 'text':
case 'message':
$this->preWriteToStream($body_part);
$this->writeToStream($stream, $body_part);
}
+ $last = $body_part;
} elseif ($message->att_local_name) {
$filename = $message->att_local_name;
$file = fopen ($filename, 'rb');
- while ($tmp = fgets($file, 4096)) {
- $length += $this->clean_crlf($tmp);
+ while ($body_part = fgets($file, 4096)) {
+ $length += $this->clean_crlf($body_part);
if ($stream) {
- $this->preWriteToStream($tmp);
- $this->writeToStream($stream, $tmp);
+ $this->preWriteToStream($body_part);
+ $this->writeToStream($stream, $body_part);
}
+ $last = $body_part;
}
fclose($file);
}
} elseif ($message->att_local_name) {
$filename = $message->att_local_name;
$file = fopen ($filename, 'rb');
+ $encoded = '';
while ($tmp = fread($file, 570)) {
- $encoded = chunk_split(base64_encode($tmp));
-
+ $body_part = chunk_split(base64_encode($tmp));
+ $length += $this->clean_crlf($body_part);
if ($stream) {
- $this->writeToStream($stream, $encoded);
+ $this->writeToStream($stream, $body_part);
}
}
fclose($file);
}
break;
}
- $body_part_trailing = "\r\n";
- $length += strlen($body_part_trailing);
- if ($stream) {
- $this->preWriteToStream($body_part_trailing);
- $this->writeToStream($stream, $body_part_trailing);
+ $body_part_trailing = '';
+ if ($last && substr($last,-1) != "\n") {
+ $body_part_trailing = "\r\n";
+ }
+ if ($body_part_trailing) {
+ $length += strlen($body_part_trailing);
+ if ($stream) {
+ $this->preWriteToStream($body_part_trailing);
+ $this->writeToStream($stream, $body_part_trailing);
+ }
}
}
$cnt = count($header);
$hdr_s = '';
for ($i = 0 ; $i < $cnt ; $i++) {
- $hdr_s .= $this->foldLine($header[$i], 78, ' ');
+ $hdr_s .= $this->foldLine($header[$i], 78,str_pad('',4));
}
$header = $hdr_s;
$header .= $rn; /* One blank line to separate mimeheader and body-entity */
return $header;
}
- function prepareRFC822_Header($rfc822_header, $reply_rfc822_header) {
+ function prepareRFC822_Header($rfc822_header, $reply_rfc822_header, &$raw_length) {
global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
global $version, $useSendmail, $username;
global $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
if (count($rfc822_header->from) > 1) {
$header[] = 'Sender: '. encodeHeader($rfc822_header->getAddr_s('sender')) . $rn;
}
- $header[] = 'To: '. encodeHeader($rfc822_header->getAddr_s('to')) . $rn; // Who it's TO
+ if (count($rfc822_header->to)) {
+ $header[] = 'To: '. encodeHeader($rfc822_header->getAddr_s('to')) . $rn;
+ }
if (count($rfc822_header->cc)) {
$header[] = 'Cc: '. encodeHeader($rfc822_header->getAddr_s('cc')) . $rn;
}
}
/* Sendmail should return true. Default = false */
$bcc = $this->getBcc();
- if ($bcc && count($rfc822_header->bcc)) {
- $header[] = 'Bcc: '. encodeHeader($rfc822_header->getAddr_s('bcc')) . $rn;
+ if (count($rfc822_header->bcc)) {
+ $s = 'Bcc: '. encodeHeader($rfc822_header->getAddr_s('bcc')) . $rn;
+ if (!$bcc) {
+ $s = $this->foldLine($s, 78, str_pad('',4));
+ $raw_length += strlen($s);
+ } else {
+ $header[] = $s;
+ }
}
/* Identify SquirrelMail */
$header[] = "X-Mailer: SquirrelMail (version $version)" . $rn;
$cnt = count($header);
$hdr_s = '';
for ($i = 0 ; $i < $cnt ; $i++) {
- $hdr_s .= $this->foldLine($header[$i], 78, ' ');
+ $hdr_s .= $this->foldLine($header[$i], 78, str_pad('',4));
}
$header = $hdr_s;
$header .= $rn; /* One blank line to separate header and body */
+ $raw_length += strlen($header);
return $header;
}