send OpenPGP/Mime message according to rfc3156, section 4

This commit is contained in:
Ralf Becker 2015-05-18 19:23:05 +00:00
parent 09fdc8d0fe
commit 38b3122bb8
2 changed files with 36 additions and 1 deletions

View File

@ -2159,6 +2159,10 @@ class mail_compose
*/
function createMessage(egw_mailer $_mailObject, array $_formData, array $_identity, $_autosaving=false)
{
if (substr($_formData['body'], 0, 27) == '-----BEGIN PGP MESSAGE-----')
{
$_formData['mimeType'] = 'openpgp';
}
//error_log(__METHOD__."(, formDate[filemode]=$_formData[filemode], _autosaving=".array2string($_autosaving).') '.function_backtrace());
$mail_bo = $this->mail_bo;
$activeMailProfile = emailadmin_account::read($this->mail_bo->profileID);
@ -2292,6 +2296,10 @@ class mail_compose
}
$_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody()
}
elseif ($_formData['mimeType'] == 'openpgp')
{
$_mailObject->setOpenPgpBody($_formData['body']);
}
else
{
$body = $this->convertHTMLToText($_formData['body'],false);

View File

@ -453,7 +453,8 @@ class egw_mailer extends Horde_Mime_Mail
), array(), true); // true = call all apps
try {
parent::send($this->account->smtpTransport(), true); // true: keep Message-ID
parent::send($this->account->smtpTransport(), true, // true: keep Message-ID
$this->_body->getType() != 'multipart/encrypted'); // no flowed for encrypted messages
}
catch (Exception $e) {
// in case of errors/exceptions call hook again with previous returned mail_id and error-message to log
@ -632,6 +633,32 @@ class egw_mailer extends Horde_Mime_Mail
return parent::addMimePart($part);
}
/**
* Sets OpenPGP encrypted body according to rfc3156, section 4
*
* @param string $body The message content.
* @link https://tools.ietf.org/html/rfc3156#section-4
*/
public function setOpenPgpBody($body)
{
$this->_body = new Horde_Mime_Part();
$this->_body->setType('multipart/encrypted');
$this->_body->setContentTypeParameter('protocol', 'application/pgp-encrypted');
$this->_body->setContents('');
$part1 = new Horde_Mime_Part();
$part1->setType('application/pgp-encrypted');
$part1->setContents("Version: 1\r\n", array('encoding' => '7bit'));
$this->_body->addPart($part1);
$part2 = new Horde_Mime_Part();
$part2->setType('application/octet-stream');
$part2->setContents($body, array('encoding' => '7bit'));
$this->_body->addPart($part2);
$this->_base = null;
}
/**
* Clear all non-standard headers
*