[kde-doc-english] [trojita] src: GUI: click-to-show for unrecognized crypto parts

Jan Kundrát jkt at kde.org
Sun Mar 13 13:06:26 UTC 2016


Git commit 80e4e4475d82191ccb7950ced80b1da51b139c1a by Jan Kundrát.
Committed on 04/03/2016 at 00:14.
Pushed by gerrit into branch 'master'.

GUI: click-to-show for unrecognized crypto parts

The signatures were being shown in an expanded attachment view because
their MIME type typically inherits from text/plain. This patch makes
sure that all encrypted parts which we cannot decrypt and also the
unsupported message signatures are hidden behind a click-to-show
AttachmentView.

Change-Id: Ie6441663edbdb5deff937c10432bc3fa1bf89878

M  +21   -1    src/Gui/PartWidget.cpp
M  +4    -0    src/Gui/PartWidget.h
M  +2    -1    src/UiUtils/PartLoadingOptions.h
M  +1    -1    src/UiUtils/PartWalker_impl.h

http://commits.kde.org/trojita/80e4e4475d82191ccb7950ced80b1da51b139c1a

diff --git a/src/Gui/PartWidget.cpp b/src/Gui/PartWidget.cpp
index 17c9dc8..e8e0f1c 100644
--- a/src/Gui/PartWidget.cpp
+++ b/src/Gui/PartWidget.cpp
@@ -307,11 +307,16 @@ void AsynchronousPartWidget::buildWidgets()
     for (int i = 0; i < m_partIndex.model()->rowCount(m_partIndex); ++i) {
         QModelIndex anotherPart = m_partIndex.child(i, 0);
         Q_ASSERT(anotherPart.isValid());
-        QWidget *res = m_factory->walk(anotherPart, m_recursionDepth + 1, filteredForEmbedding(m_options));
+        QWidget *res = addingOneWidget(anotherPart, filteredForEmbedding(m_options));
         layout()->addWidget(res);
     }
 }
 
+QWidget *AsynchronousPartWidget::addingOneWidget(const QModelIndex &index, UiUtils::PartLoadingOptions options)
+{
+    return m_factory->walk(index, m_recursionDepth + 1, options);
+}
+
 void AsynchronousPartWidget::handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 {
     Q_ASSERT(topLeft == bottomRight);
@@ -349,6 +354,21 @@ QString MultipartSignedEncryptedWidget::quoteMe() const
     return quoteMeHelper(children());
 }
 
+QWidget *MultipartSignedEncryptedWidget::addingOneWidget(const QModelIndex &index, UiUtils::PartLoadingOptions options)
+{
+    auto parent = index.parent();
+    if (parent.isValid() && parent.model()->rowCount(parent) == 2) {
+        if (parent.data(Imap::Mailbox::RolePartMimeType).toByteArray() == "multipart/signed" && index.row() == 1) {
+            // do not expand the signature
+            options |= UiUtils::PART_IGNORE_INLINE;
+        } else if (parent.data(Imap::Mailbox::RolePartMimeType).toByteArray() == "multipart/encrypted") {
+            // click-to-show for everything within an encrypted message
+            options |= UiUtils::PART_IGNORE_INLINE;
+        }
+    }
+    return AsynchronousPartWidget::addingOneWidget(index, options);
+}
+
 GenericMultipartWidget::GenericMultipartWidget(QWidget *parent,
         PartWidgetFactory *factory, const QModelIndex &partIndex,
         int recursionDepth, const UiUtils::PartLoadingOptions options):
diff --git a/src/Gui/PartWidget.h b/src/Gui/PartWidget.h
index ce416fa..3709d75 100644
--- a/src/Gui/PartWidget.h
+++ b/src/Gui/PartWidget.h
@@ -88,6 +88,8 @@ private:
     void buildWidgets();
 
 protected:
+    virtual QWidget *addingOneWidget(const QModelIndex &index, UiUtils::PartLoadingOptions options);
+
     PartStatusWidget *m_statusWidget;
     PartWidgetFactory *m_factory;
     QPersistentModelIndex m_partIndex;
@@ -107,6 +109,8 @@ public:
     virtual void reloadContents() override;
 protected slots:
     virtual void updateStatusIndicator() override;
+protected:
+    virtual QWidget *addingOneWidget(const QModelIndex &index, UiUtils::PartLoadingOptions options) override;
 };
 
 /** @short Message quoting support for generic multipart/ * */
diff --git a/src/UiUtils/PartLoadingOptions.h b/src/UiUtils/PartLoadingOptions.h
index 968b803..bbae6e7 100644
--- a/src/UiUtils/PartLoadingOptions.h
+++ b/src/UiUtils/PartLoadingOptions.h
@@ -33,7 +33,8 @@ typedef enum {
     PART_IGNORE_CLICKTHROUGH = 1 << 1, /**< @short Ignore any heuristics which lead to wrapping in an LoadablePartView with a clickthrough */
     PART_IGNORE_LOAD_ON_SHOW = 1 << 2, /**< @short Ignore wrapping in a LoadablePartView set up to load on first show event */
     PART_IS_HIDDEN = 1 << 3, /**< @short Request wrapping this part in a LoadablePartView */
-    PART_PREFER_PLAINTEXT_OVER_HTML = 1 << 4 /**< @short The user's preferences indicate that a text/plain part shall be shown instead of a text/html if available */
+    PART_PREFER_PLAINTEXT_OVER_HTML = 1 << 4, /**< @short The user's preferences indicate that a text/plain part shall be shown instead of a text/html if available */
+    PART_IGNORE_INLINE = 1 << 5, /**< @short Do not auto-expand this attachment */
 } PartLoadingFlag;
 /** @short Which of these options shall be propagated to child Views when embedding them, and which shall be filtered? */
 enum {
diff --git a/src/UiUtils/PartWalker_impl.h b/src/UiUtils/PartWalker_impl.h
index ed0f70b..87841fd 100644
--- a/src/UiUtils/PartWalker_impl.h
+++ b/src/UiUtils/PartWalker_impl.h
@@ -86,7 +86,7 @@ Result PartWalker<Result, Context>::walk(const QModelIndex &partIndex,int recurs
     // Check whether it shall be wrapped inside an AttachmentView
     // From section 2.8 of RFC 2183: "Unrecognized disposition types should be treated as `attachment'."
     const QByteArray contentDisposition = partIndex.data(Imap::Mailbox::RolePartBodyDisposition).toByteArray().toLower();
-    const bool isInline = contentDisposition.isEmpty() || contentDisposition == "inline";
+    const bool isInline = (contentDisposition.isEmpty() || contentDisposition == "inline") && !(loadingMode & PART_IGNORE_INLINE);
     const bool looksLikeAttachment = !partIndex.data(Imap::Mailbox::RolePartFileName).toString().isEmpty();
     const bool wrapInAttachmentView = !(loadingMode & PART_IGNORE_DISPOSITION_ATTACHMENT)
             && (looksLikeAttachment || !isInline || !recognizedMimeType || isDerivedMimeType || isMessageRfc822);



More information about the kde-doc-english mailing list