forked from extern/egroupware
S/MIME:
- Override send function in mailer object to be able to use additional options of part->send - Fix Signed html message gets not working
This commit is contained in:
parent
4fcebd2f93
commit
8fd6325c3d
@ -494,11 +494,22 @@ class Mailer extends Horde_Mime_Mail
|
||||
* @param boolean $flowed =null send message in flowed text format,
|
||||
* default null used flowed by default for everything but multipart/encrypted,
|
||||
* unless disabled in site configuration ("disable_rfc3676_flowed")
|
||||
*
|
||||
* * @param array $opts Additional options:
|
||||
* <pre>
|
||||
* - broken_rfc2231: (boolean) Attempt to work around non-RFC
|
||||
* 2231-compliant MUAs by generating both a RFC
|
||||
* 2047-like parameter name and also the correct RFC
|
||||
* 2231 parameter (@since 2.5.0).
|
||||
* DEFAULT: false
|
||||
* - encode: (integer) The encoding to use. A mask of self::ENCODE_*
|
||||
* values.
|
||||
* DEFAULT: Auto-determined based on transport driver.
|
||||
* </pre>
|
||||
*
|
||||
* @throws Exception\NotFound for no smtp account available
|
||||
* @throws Horde_Mime_Exception
|
||||
*/
|
||||
function send(Horde_Mail_Transport $transport=null, $resend=true, $flowed=null)
|
||||
function send(Horde_Mail_Transport $transport=null, $resend=true, $flowed=null, array $opts = array())
|
||||
{
|
||||
unset($resend); // parameter is not used, but required by function signature
|
||||
|
||||
@ -510,6 +521,9 @@ class Mailer extends Horde_Mime_Mail
|
||||
}
|
||||
$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
|
||||
if ($this->_base->getMetadata('X-EGroupware-Smime-signed')) $opts['encode'] = Horde_Mime_Part::ENCODE_7BIT;
|
||||
|
||||
$mail_id = Hooks::process(array(
|
||||
'location' => 'send_mail',
|
||||
'subject' => $subject=$this->getHeader('Subject'),
|
||||
@ -581,7 +595,7 @@ class Mailer extends Horde_Mime_Mail
|
||||
$this->_body = $body;
|
||||
$flowed = false;
|
||||
}
|
||||
parent::send($transport ? $transport : $this->account->smtpTransport(), true, $flowed); // true: keep Message-ID
|
||||
$this->_send($transport ? $transport : $this->account->smtpTransport(), true, $flowed, $opts); // true: keep Message-ID
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// in case of errors/exceptions call hook again with previous returned mail_id and error-message to log
|
||||
@ -628,6 +642,108 @@ class Mailer extends Horde_Mime_Mail
|
||||
if (isset($e)) throw $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends this message.
|
||||
*
|
||||
* @param Mail $mailer A Mail object.
|
||||
* @param boolean $resend If true, the message id and date are re-used;
|
||||
* If false, they will be updated.
|
||||
* @param boolean $flowed Send message in flowed text format.
|
||||
* * @param array $opts Additional options:
|
||||
* <pre>
|
||||
* - broken_rfc2231: (boolean) Attempt to work around non-RFC
|
||||
* 2231-compliant MUAs by generating both a RFC
|
||||
* 2047-like parameter name and also the correct RFC
|
||||
* 2231 parameter (@since 2.5.0).
|
||||
* DEFAULT: false
|
||||
* - encode: (integer) The encoding to use. A mask of self::ENCODE_*
|
||||
* values.
|
||||
* DEFAULT: Auto-determined based on transport driver.
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @throws Horde_Mime_Exception
|
||||
*/
|
||||
public function _send($mailer, $resend = false, $flowed = true, array $opts = array())
|
||||
{
|
||||
/* Add mandatory headers if missing. */
|
||||
if (!$resend || !isset($this->_headers['Message-ID'])) {
|
||||
$this->_headers->addHeaderOb(
|
||||
Horde_Mime_Headers_MessageId::create()
|
||||
);
|
||||
}
|
||||
if (!isset($this->_headers['User-Agent'])) {
|
||||
$this->_headers->addHeaderOb(
|
||||
Horde_Mime_Headers_UserAgent::create()
|
||||
);
|
||||
}
|
||||
if (!$resend || !isset($this->_headers['Date'])) {
|
||||
$this->_headers->addHeaderOb(Horde_Mime_Headers_Date::create());
|
||||
}
|
||||
|
||||
if (isset($this->_base)) {
|
||||
$basepart = $this->_base;
|
||||
} else {
|
||||
/* Send in flowed format. */
|
||||
if ($flowed && !empty($this->_body)) {
|
||||
$flowed = new Horde_Text_Flowed($this->_body->getContents(), $this->_body->getCharset());
|
||||
$flowed->setDelSp(true);
|
||||
$this->_body->setContentTypeParameter('format', 'flowed');
|
||||
$this->_body->setContentTypeParameter('DelSp', 'Yes');
|
||||
$this->_body->setContents($flowed->toFlowed());
|
||||
}
|
||||
|
||||
/* Build mime message. */
|
||||
$body = new Horde_Mime_Part();
|
||||
if (!empty($this->_body) && !empty($this->_htmlBody)) {
|
||||
$body->setType('multipart/alternative');
|
||||
$this->_body->setDescription(Horde_Mime_Translation::t("Plaintext Version of Message"));
|
||||
$body[] = $this->_body;
|
||||
$this->_htmlBody->setDescription(Horde_Mime_Translation::t("HTML Version of Message"));
|
||||
$body[] = $this->_htmlBody;
|
||||
} elseif (!empty($this->_htmlBody)) {
|
||||
$body = $this->_htmlBody;
|
||||
} elseif (!empty($this->_body)) {
|
||||
$body = $this->_body;
|
||||
}
|
||||
if (count($this->_parts)) {
|
||||
$basepart = new Horde_Mime_Part();
|
||||
$basepart->setType('multipart/mixed');
|
||||
$basepart->isBasePart(true);
|
||||
if ($body) {
|
||||
$basepart[] = $body;
|
||||
}
|
||||
foreach ($this->_parts as $mime_part) {
|
||||
$basepart[] = $mime_part;
|
||||
}
|
||||
} else {
|
||||
$basepart = $body;
|
||||
$basepart->isBasePart(true);
|
||||
}
|
||||
}
|
||||
$basepart->setHeaderCharset($this->_charset);
|
||||
|
||||
/* Build recipients. */
|
||||
$recipients = clone $this->_recipients;
|
||||
foreach (array('to', 'cc') as $header) {
|
||||
if ($h = $this->_headers[$header]) {
|
||||
$recipients->add($h->getAddressList());
|
||||
}
|
||||
}
|
||||
if ($this->_bcc) {
|
||||
$recipients->add($this->_bcc);
|
||||
}
|
||||
|
||||
/* Trick Horde_Mime_Part into re-generating the message headers. */
|
||||
$this->_headers->removeHeader('MIME-Version');
|
||||
|
||||
/* Send message. */
|
||||
$recipients->unique();
|
||||
$basepart->send($recipients->writeAddress(), $this->_headers, $mailer, $opts);
|
||||
|
||||
/* Remember the basepart */
|
||||
$this->_base = $basepart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all Settings to send multiple Messages
|
||||
@ -1057,6 +1173,7 @@ class Mailer extends Horde_Mime_Mail
|
||||
{
|
||||
case Mail\Smime::TYPE_SIGN:
|
||||
$this->_base = $smime->signMIMEPart($this->_base, $sign_params);
|
||||
$this->_base->setMetadata('X-EGroupware-Smime-signed', true);
|
||||
break;
|
||||
case Mail\Smime::TYPE_ENCRYPT:
|
||||
$this->_base = $smime->encryptMIMEPart($this->_base, $encrypt_params);
|
||||
|
Loading…
Reference in New Issue
Block a user