From f189d72943c490ae97323997aef8987bc58f3b5e Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Thu, 10 Sep 2015 15:27:58 -0400
Subject: [PATCH] Merged branch 'dev-mailvelope'

---
 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 6866c51..bb32f6e 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -246,6 +246,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();
 
@@ -475,6 +487,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