From f7f75ff7d11b9e3cc722210f7037fc1e6c3c3b61 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Thu, 10 Sep 2015 15:56:40 -0400
Subject: [PATCH] Unify detection of pgp/mime message part
---
program/steps/mail/compose.inc | 21 ++++++----
program/steps/mail/func.inc | 17 ++------
program/lib/Roundcube/rcube_message.php | 22 +++++++++++
program/js/app.js | 1
4 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/program/js/app.js b/program/js/app.js
index 628fc19..c5e9e59 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3481,6 +3481,7 @@
}
}).catch(function(err) {
console.error(err);
+ console.log(options);
});
}
};
diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php
index 884141a..f478a44 100644
--- a/program/lib/Roundcube/rcube_message.php
+++ b/program/lib/Roundcube/rcube_message.php
@@ -484,6 +484,28 @@
}
/**
+ * In a multipart/encrypted encrypted message,
+ * find the encrypted message payload part.
+ *
+ * @return rcube_message_part
+ */
+ public function get_multipart_encrypted_part()
+ {
+ foreach ($this->mime_parts as $mime_id => $mpart) {
+ if ($mpart->mimetype == 'multipart/encrypted') {
+ $this->pgp_mime = true;
+ }
+ if ($this->pgp_mime && ($mpart->mimetype == 'application/octet-stream' ||
+ (!empty($mpart->filename) && $mpart->filename != 'version.txt'))) {
+ $this->encrypted_part = $mime_id;
+ return $mpart;
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Read the message structure returend by the IMAP server
* and build flat lists of content parts and attachments
*
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index c5450c5..fd87266 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -782,15 +782,13 @@
foreach ($MESSAGE->parts as $part) {
if ($part->realtype == 'multipart/encrypted') {
// find the encrypted message payload part
- foreach ($MESSAGE->mime_parts as $mime_id => $mpart) {
- if ($mpart->mimetype == 'application/octet-stream' || !empty($mpart->filename)) {
- $RCMAIL->output->set_env('pgp_mime_message', array(
- '_mbox' => $RCMAIL->storage->get_folder(), '_uid' => $MESSAGE->uid, '_part' => $mime_id,
- ));
- $RCMAIL->output->set_env('compose_mode', $compose_mode);
- $MESSAGE->pgp_mime = true;
- break;
- }
+ if ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part()) {
+ $RCMAIL->output->set_env('pgp_mime_message', array(
+ '_mbox' => $RCMAIL->storage->get_folder(),
+ '_uid' => $MESSAGE->uid,
+ '_part' => $pgp_mime_part->mime_id,
+ ));
+ $RCMAIL->output->set_env('compose_mode', $compose_mode);
}
continue;
}
@@ -1271,6 +1269,11 @@
continue;
}
+ // skip version.txt parts of multipart/encrypted messages
+ if ($message->pgp_mime && $part->mimetype == 'application/pgp-encrypted' && $part->filename == 'version.txt') {
+ continue;
+ }
+
// skip message/rfc822 attachments on forwards (#1489214)
// Thunderbird when forwarding in inline mode displays such attachments
// and skips any attachments from inside of such part, this however
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 09cf6ed..9feb767 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -1193,18 +1193,11 @@
// unsupported (e.g. encrypted)
if ($part->realtype) {
if ($part->realtype == 'multipart/encrypted' || $part->realtype == 'application/pkcs7-mime') {
- if (!empty($_SESSION['browser_caps']['pgpmime']) && $part->realtype == 'multipart/encrypted') {
- // find the encrypted message payload part
- foreach ($MESSAGE->mime_parts as $mime_id => $mpart) {
- if ($mpart->mimetype == 'application/octet-stream' || !empty($mpart->filename)) {
- $out .= html::span('part-notice', $RCMAIL->gettext('externalmessagedecryption'));
- $OUTPUT->set_env('pgp_mime_part', $mime_id);
- $OUTPUT->set_env('pgp_mime_container', '#' . $attrib['id']);
- $OUTPUT->add_label('loadingdata');
- $MESSAGE->encrypted_part = $mime_id;
- break;
- }
- }
+ if (!empty($_SESSION['browser_caps']['pgpmime']) && ($pgp_mime_part = $MESSAGE->get_multipart_encrypted_part())) {
+ $out .= html::span('part-notice', $RCMAIL->gettext('externalmessagedecryption'));
+ $OUTPUT->set_env('pgp_mime_part', $pgp_mime_part->mime_id);
+ $OUTPUT->set_env('pgp_mime_container', '#' . $attrib['id']);
+ $OUTPUT->add_label('loadingdata');
}
if (!$MESSAGE->encrypted_part) {
--
Gitblit v1.9.1