Fix broken mail compose

This commit is contained in:
Hadi Nategh 2017-08-29 11:38:08 +02:00
parent 495d67d5d0
commit f788f001d0

View File

@ -23,7 +23,9 @@ use Horde_Text_Flowed;
use Horde_Stream; use Horde_Stream;
use Horde_Stream_Wrapper_Combine; use Horde_Stream_Wrapper_Combine;
use Horde_Mime_Headers; use Horde_Mime_Headers;
use Horde_Mime_Headers_UserAgent;
use Horde_Mime_Headers_Date;
use Horde_Mime_Translation;
/** /**
* Sending mail via Horde_Mime_Mail * Sending mail via Horde_Mime_Mail
* *
@ -522,7 +524,7 @@ class Mailer extends Horde_Mime_Mail
$body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now $body_sha1 = null; // skip sha1, it requires whole mail in memory, which we traing to avoid now
// Smime sign needs to be 7bit encoded to avoid any changes during the transportation // Smime sign needs to be 7bit encoded to avoid any changes during the transportation
if ($this->_base->getMetadata('X-EGroupware-Smime-signed')) $opts['encode'] = Horde_Mime_Part::ENCODE_7BIT; if ($this->_base && $this->_base->getMetadata('X-EGroupware-Smime-signed')) $opts['encode'] = Horde_Mime_Part::ENCODE_7BIT;
$mail_id = Hooks::process(array( $mail_id = Hooks::process(array(
'location' => 'send_mail', 'location' => 'send_mail',
@ -666,83 +668,83 @@ class Mailer extends Horde_Mime_Mail
*/ */
public function _send($mailer, $resend = false, $flowed = true, array $opts = array()) public function _send($mailer, $resend = false, $flowed = true, array $opts = array())
{ {
/* Add mandatory headers if missing. */ /* Add mandatory headers if missing. */
if (!$resend || !isset($this->_headers['Message-ID'])) { if (!$resend || !isset($this->_headers['Message-ID'])) {
$this->_headers->addHeaderOb( $this->_headers->addHeaderOb(
Horde_Mime_Headers_MessageId::create() Horde_Mime_Headers_MessageId::create()
); );
} }
if (!isset($this->_headers['User-Agent'])) { if (!isset($this->_headers['User-Agent'])) {
$this->_headers->addHeaderOb( $this->_headers->addHeaderOb(
Horde_Mime_Headers_UserAgent::create() Horde_Mime_Headers_UserAgent::create()
); );
} }
if (!$resend || !isset($this->_headers['Date'])) { if (!$resend || !isset($this->_headers['Date'])) {
$this->_headers->addHeaderOb(Horde_Mime_Headers_Date::create()); $this->_headers->addHeaderOb(Horde_Mime_Headers_Date::create());
} }
if (isset($this->_base)) { if (isset($this->_base)) {
$basepart = $this->_base; $basepart = $this->_base;
} else { } else {
/* Send in flowed format. */ /* Send in flowed format. */
if ($flowed && !empty($this->_body)) { if ($flowed && !empty($this->_body)) {
$flowed = new Horde_Text_Flowed($this->_body->getContents(), $this->_body->getCharset()); $flowed = new Horde_Text_Flowed($this->_body->getContents(), $this->_body->getCharset());
$flowed->setDelSp(true); $flowed->setDelSp(true);
$this->_body->setContentTypeParameter('format', 'flowed'); $this->_body->setContentTypeParameter('format', 'flowed');
$this->_body->setContentTypeParameter('DelSp', 'Yes'); $this->_body->setContentTypeParameter('DelSp', 'Yes');
$this->_body->setContents($flowed->toFlowed()); $this->_body->setContents($flowed->toFlowed());
} }
/* Build mime message. */ /* Build mime message. */
$body = new Horde_Mime_Part(); $body = new Horde_Mime_Part();
if (!empty($this->_body) && !empty($this->_htmlBody)) { if (!empty($this->_body) && !empty($this->_htmlBody)) {
$body->setType('multipart/alternative'); $body->setType('multipart/alternative');
$this->_body->setDescription(Horde_Mime_Translation::t("Plaintext Version of Message")); $this->_body->setDescription(Horde_Mime_Translation::t("Plaintext Version of Message"));
$body[] = $this->_body; $body[] = $this->_body;
$this->_htmlBody->setDescription(Horde_Mime_Translation::t("HTML Version of Message")); $this->_htmlBody->setDescription(Horde_Mime_Translation::t("HTML Version of Message"));
$body[] = $this->_htmlBody; $body[] = $this->_htmlBody;
} elseif (!empty($this->_htmlBody)) { } elseif (!empty($this->_htmlBody)) {
$body = $this->_htmlBody; $body = $this->_htmlBody;
} elseif (!empty($this->_body)) { } elseif (!empty($this->_body)) {
$body = $this->_body; $body = $this->_body;
} }
if (count($this->_parts)) { if (count($this->_parts)) {
$basepart = new Horde_Mime_Part(); $basepart = new Horde_Mime_Part();
$basepart->setType('multipart/mixed'); $basepart->setType('multipart/mixed');
$basepart->isBasePart(true); $basepart->isBasePart(true);
if ($body) { if ($body) {
$basepart[] = $body; $basepart[] = $body;
} }
foreach ($this->_parts as $mime_part) { foreach ($this->_parts as $mime_part) {
$basepart[] = $mime_part; $basepart[] = $mime_part;
} }
} else { } else {
$basepart = $body; $basepart = $body;
$basepart->isBasePart(true); $basepart->isBasePart(true);
} }
} }
$basepart->setHeaderCharset($this->_charset); $basepart->setHeaderCharset($this->_charset);
/* Build recipients. */ /* Build recipients. */
$recipients = clone $this->_recipients; $recipients = clone $this->_recipients;
foreach (array('to', 'cc') as $header) { foreach (array('to', 'cc') as $header) {
if ($h = $this->_headers[$header]) { if ($h = $this->_headers[$header]) {
$recipients->add($h->getAddressList()); $recipients->add($h->getAddressList());
} }
} }
if ($this->_bcc) { if ($this->_bcc) {
$recipients->add($this->_bcc); $recipients->add($this->_bcc);
} }
/* Trick Horde_Mime_Part into re-generating the message headers. */ /* Trick Horde_Mime_Part into re-generating the message headers. */
$this->_headers->removeHeader('MIME-Version'); $this->_headers->removeHeader('MIME-Version');
/* Send message. */ /* Send message. */
$recipients->unique(); $recipients->unique();
$basepart->send($recipients->writeAddress(), $this->_headers, $mailer, $opts); $basepart->send($recipients->writeAddress(), $this->_headers, $mailer, $opts);
/* Remember the basepart */ /* Remember the basepart */
$this->_base = $basepart; $this->_base = $basepart;
} }
/** /**