public function CreateBody()
{
$result = '';
if ($this->sign_key_file) {
$result .= $this->GetMailMIME();
}
$this->SetWordWrap();
switch ($this->message_type) {
case 'alt':
$result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
$result .= $this->EncodeString($this->AltBody, $this->Encoding);
$result .= $this->LE . $this->LE;
$result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
$result .= $this->EncodeString($this->Body, $this->Encoding);
$result .= $this->LE . $this->LE;
$result .= $this->EndBoundary($this->boundary[1]);
break;
case 'plain':
$result .= $this->EncodeString($this->Body, $this->Encoding);
break;
case 'attachments':
$result .= $this->GetBoundary($this->boundary[1], '', '', '');
$result .= $this->EncodeString($this->Body, $this->Encoding);
$result .= $this->LE;
$result .= $this->AttachAll();
break;
case 'alt_attachments':
$result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
$result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE . $this->LE);
$result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE;
// Create text body
$result .= $this->EncodeString($this->AltBody, $this->Encoding);
$result .= $this->LE . $this->LE;
$result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE;
// Create the HTML body
$result .= $this->EncodeString($this->Body, $this->Encoding);
$result .= $this->LE . $this->LE;
$result .= $this->EndBoundary($this->boundary[2]);
$result .= $this->AttachAll();
break;
}
if ($this->IsError()) {
$result = '';
} else {
if ($this->sign_key_file) {
$file = tempnam("", "mail");
$fp = fopen($file, "w");
fwrite($fp, $result);
fclose($fp);
$signed = tempnam("", "signed");
if (@openssl_pkcs7_sign($file, $signed, "file://" . $this->sign_cert_file, array("file://" . $this->sign_key_file, $this->sign_key_pass), null)) {
$fp = fopen($signed, "r");
$result = '';
while (!feof($fp)) {
$result = $result . fread($fp, 1024);
}
fclose($fp);
} else {
$this->SetError($this->Lang("signing") . openssl_error_string());
$result = '';
}
unlink($file);
unlink($signed);
}
}
return $result;
}