From 5d49af37cc81c4fada69169c23cc12a5f9c4ce2e Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 06 Feb 2016 11:45:20 -0500
Subject: [PATCH] Enigma: Disable format=flowed for signed plain text messages (#1490646)

---
 CHANGELOG                            |    1 +
 plugins/enigma/composer.json         |    2 +-
 plugins/enigma/lib/enigma_engine.php |   13 +++++++++++++
 3 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 840525f..24baad0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Enigma: Disable format=flowed for signed plain text messages (#1490646)
 - Enigma: Fix handling of encrypted + signed messages (#1490632)
 - Enigma: Fix invalid boundary use in signed messages structure
 - Enable use of TLSv1.1 and TLSv1.2 for IMAP (#1490640)
diff --git a/plugins/enigma/composer.json b/plugins/enigma/composer.json
index 84695ef..3245ee7 100644
--- a/plugins/enigma/composer.json
+++ b/plugins/enigma/composer.json
@@ -3,7 +3,7 @@
     "type": "roundcube-plugin",
     "description": "PGP Encryption for Roundcube",
     "license": "GPLv3+",
-    "version": "0.3",
+    "version": "0.4",
     "authors": [
         {
             "name": "Aleksander Machniak",
diff --git a/plugins/enigma/lib/enigma_engine.php b/plugins/enigma/lib/enigma_engine.php
index 36693bd..584a5b2 100644
--- a/plugins/enigma/lib/enigma_engine.php
+++ b/plugins/enigma/lib/enigma_engine.php
@@ -186,6 +186,18 @@
             // in this mode we'll replace text part
             // with the one containing signature
             $body = $message->getTXTBody();
+
+            $text_charset = $message->getParam('text_charset');
+            $line_length  = $this->rc->config->get('line_length', 72);
+
+            // We can't use format=flowed for signed messages
+            if (strpos($text_charset, 'format=flowed')) {
+                list($charset, $params) = explode(';', $text_charset);
+                $body = rcube_mime::unfold_flowed($body);
+                $body = rcube_mime::wordwrap($body, $line_length, "\r\n", false, $charset);
+
+                $text_charset = str_replace(";\r\n format=flowed", '', $text_charset);
+            }
         }
         else {
             // here we'll build PGP/MIME message
@@ -208,6 +220,7 @@
         // replace message body
         if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) {
             $message->setTXTBody($body);
+            $message->setParam('text_charset', $text_charset);
         }
         else {
             $mime->addPGPSignature($body);

--
Gitblit v1.9.1