From 40d152cfdcace360138ab332e084dfb39a2d2798 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli <thomas@roundcube.net> Date: Mon, 01 Jun 2015 06:53:32 -0400 Subject: [PATCH] Make encrypted pgp/mime message composition work --- program/steps/mail/sendmail.inc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-) diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index b3034f5..a766640 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -273,6 +273,18 @@ // fetch message body $message_body = rcube_utils::get_input_value('_message', rcube_utils::INPUT_POST, TRUE, $message_charset); +if (isset($_POST['_pgpmime'])) { + $pgp_mime = rcube_utils::get_input_value('_pgpmime', rcube_utils::INPUT_POST); + $message_body = 'This is an OpenPGP/MIME encrypted message (RFC 2440 and 3156)'; + $isHtml = false; + + // clear unencrypted attachments + foreach ($COMPOSE['attachments'] as $attach) { + $RCMAIL->plugins->exec_hook('attachment_delete', $attach); + } + $COMPOSE['attachments'] = array(); +} + if ($isHtml) { $bstyle = array(); @@ -503,6 +515,43 @@ $text_charset .= ";\r\n format=flowed"; } +// compose PGP/Mime message +if ($pgp_mime) { + $MAIL_MIME->addAttachment( + 'Version: 1', + 'application/pgp-encrypted', + 'version.txt', // required by Mail_mime::addAttachment() + false, + '8bit', + '', // $disposition + '', // $charset + '', // $language + '', // $location + null, // $n_encoding + null, // $f_encoding + 'PGP/MIME version identification' + ); + + // patch filename out of the version part + foreach ($MAIL_MIME->_parts as $_i => $_part) { + if ($_part['c_type'] == 'application/pgp-encrypted') { + $MAIL_MIME->_parts[$_i]['name'] = ''; + break; + } + } + + $MAIL_MIME->addAttachment( + $pgp_mime, + 'application/octet-stream', + 'encrypted.asc', + false, + '8bit', + 'inline' + ); + + $MAIL_MIME->setContentType('multipart/encrypted', array('protocol' => "application/pgp-encrypted")); +} + // encoding settings for mail composing $MAIL_MIME->setParam('text_encoding', $transfer_encoding); $MAIL_MIME->setParam('html_encoding', 'quoted-printable'); -- Gitblit v1.9.1