summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-06 00:27:24 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-06-06 00:27:24 +0200
commit37983d97ec0eb03845f11eb03f429174acfd327b (patch)
tree9dbb5cdf8bbc463b43d38f45353b80b0f8ad7fe7
parente98793cb59a1f29fe3b6980e0af3a48ed049024d (diff)
downloadkube-37983d97ec0eb03845f11eb03f429174acfd327b.tar.gz
kube-37983d97ec0eb03845f11eb03f429174acfd327b.zip
A simplistic security border
Still a bit obnoxious and doesn't really convey a whole lot of information. Consider it a stub for now
-rw-r--r--components/mailviewer/contents/ui/MailDataModel.qml33
-rw-r--r--components/mailviewer/contents/ui/TextContent.qml7
-rw-r--r--framework/qml/MailViewer.qml2
-rw-r--r--framework/src/domain/mime/mimetreeparser/enums.h20
-rw-r--r--framework/src/domain/mime/mimetreeparser/messagepart.cpp28
-rw-r--r--framework/src/domain/mime/mimetreeparser/messagepart.h7
-rw-r--r--framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp9
-rw-r--r--framework/src/domain/mime/partmodel.cpp4
8 files changed, 82 insertions, 28 deletions
diff --git a/components/mailviewer/contents/ui/MailDataModel.qml b/components/mailviewer/contents/ui/MailDataModel.qml
index 99bd0dc2..46427194 100644
--- a/components/mailviewer/contents/ui/MailDataModel.qml
+++ b/components/mailviewer/contents/ui/MailDataModel.qml
@@ -18,6 +18,7 @@
18 18
19import QtQuick 2.4 19import QtQuick 2.4
20import QtQml.Models 2.2 20import QtQml.Models 2.2
21import org.kube.framework 1.0 as Kube
21 22
22DelegateModel { 23DelegateModel {
23 id: mailDataModel 24 id: mailDataModel
@@ -25,16 +26,38 @@ DelegateModel {
25 26
26 delegate: Item { 27 delegate: Item {
27 id: partColumn 28 id: partColumn
29
28 width: parent.width 30 width: parent.width
29 height: childrenRect.height 31 height: childrenRect.height
30 Loader { 32
31 id: partLoader 33 Row {
32 anchors { 34 anchors {
33 top: parent.top 35 top: parent.top
34 left: parent.left 36 left: parent.left
37 right: parent.right
38 }
39 height: partLoader.height
40 spacing: Kube.Units.smallSpacing
41 Rectangle {
42 id: border
43 visible: model.encrypted || model.signed
44 anchors {
45 top: parent.top
46 bottom: parent.bottom
47 }
48 width: Kube.Units.smallSpacing
49 color: Kube.Colors.positiveColor
50 opacity: 0.5
51 }
52
53 Loader {
54 id: partLoader
55 anchors {
56 top: parent.top
57 }
58 height: item? item.contentHeight : 0
59 width: parent.width
35 } 60 }
36 height: item? item.contentHeight : 0
37 width: parent.width
38 } 61 }
39 Component.onCompleted: { 62 Component.onCompleted: {
40 switch (model.type) { 63 switch (model.type) {
@@ -42,14 +65,12 @@ DelegateModel {
42 partLoader.setSource("TextContent.qml", 65 partLoader.setSource("TextContent.qml",
43 {"content": model.content, 66 {"content": model.content,
44 "embedded": model.embeded, 67 "embedded": model.embeded,
45 "securityLevel": model.securityLevel,
46 "type": model.type, 68 "type": model.type,
47 "debug": debug}) 69 "debug": debug})
48 break 70 break
49 case "html": 71 case "html":
50 partLoader.setSource("HtmlContent.qml", 72 partLoader.setSource("HtmlContent.qml",
51 {"content": model.content, 73 {"content": model.content,
52 "securityLevel": model.securityLevel,
53 "debug": debug}) 74 "debug": debug})
54 break; 75 break;
55 case "error": 76 case "error":
diff --git a/components/mailviewer/contents/ui/TextContent.qml b/components/mailviewer/contents/ui/TextContent.qml
index 90442b8f..f8ef7f9a 100644
--- a/components/mailviewer/contents/ui/TextContent.qml
+++ b/components/mailviewer/contents/ui/TextContent.qml
@@ -21,14 +21,13 @@ import QtQuick 2.7
21import org.kube.framework 1.0 as Kube 21import org.kube.framework 1.0 as Kube
22 22
23Item { 23Item {
24 id: textItem 24 id: root
25 25
26 property string content 26 property string content
27 property bool debug: true 27 property bool debug: true
28 property bool embedded: true 28 property bool embedded: true
29 property string type 29 property string type
30 30
31 width: partColumn.width
32 height: textColumn.height 31 height: textColumn.height
33 32
34 Column { 33 Column {
@@ -37,9 +36,9 @@ Item {
37 anchors { 36 anchors {
38 top: parent.top 37 top: parent.top
39 left: parent.left 38 left: parent.left
39 right: parent.right
40 } 40 }
41 41
42 width: parent.width
43 spacing: 5 42 spacing: 5
44 43
45 TextEdit { 44 TextEdit {
@@ -59,7 +58,7 @@ Item {
59 //BEGIN debug 58 //BEGIN debug
60 Text { 59 Text {
61 width: parent.width 60 width: parent.width
62 visible: textItem.debug 61 visible: root.debug
63 text: type 62 text: type
64 } 63 }
65 //END debug 64 //END debug
diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml
index ad1ad734..9e14fc7f 100644
--- a/framework/qml/MailViewer.qml
+++ b/framework/qml/MailViewer.qml
@@ -436,7 +436,7 @@ Rectangle {
436 role: "content" 436 role: "content"
437 title: "Content" 437 title: "Content"
438 } 438 }
439 model: messageParser.newTree 439 model: messageParser.parts
440 itemDelegate: Item { 440 itemDelegate: Item {
441 property variant currentData: styleData.value 441 property variant currentData: styleData.value
442 Text { 442 Text {
diff --git a/framework/src/domain/mime/mimetreeparser/enums.h b/framework/src/domain/mime/mimetreeparser/enums.h
index bec5a028..db3af165 100644
--- a/framework/src/domain/mime/mimetreeparser/enums.h
+++ b/framework/src/domain/mime/mimetreeparser/enums.h
@@ -33,20 +33,20 @@ enum UpdateMode {
33 33
34/** Flags for the encryption state. */ 34/** Flags for the encryption state. */
35typedef enum { 35typedef enum {
36 KMMsgEncryptionStateUnknown = ' ', 36 KMMsgEncryptionStateUnknown,
37 KMMsgNotEncrypted = 'N', 37 KMMsgNotEncrypted,
38 KMMsgPartiallyEncrypted = 'P', 38 KMMsgPartiallyEncrypted,
39 KMMsgFullyEncrypted = 'F', 39 KMMsgFullyEncrypted,
40 KMMsgEncryptionProblematic = 'X' 40 KMMsgEncryptionProblematic
41} KMMsgEncryptionState; 41} KMMsgEncryptionState;
42 42
43/** Flags for the signature state. */ 43/** Flags for the signature state. */
44typedef enum { 44typedef enum {
45 KMMsgSignatureStateUnknown = ' ', 45 KMMsgSignatureStateUnknown,
46 KMMsgNotSigned = 'N', 46 KMMsgNotSigned,
47 KMMsgPartiallySigned = 'P', 47 KMMsgPartiallySigned,
48 KMMsgFullySigned = 'F', 48 KMMsgFullySigned,
49 KMMsgSignatureProblematic = 'X' 49 KMMsgSignatureProblematic
50} KMMsgSignatureState; 50} KMMsgSignatureState;
51 51
52} 52}
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp
index b4db4016..00abb003 100644
--- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp
+++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp
@@ -312,6 +312,22 @@ QVector<EncryptedMessagePart*> MessagePart::encryptions() const
312 return list; 312 return list;
313} 313}
314 314
315KMMsgEncryptionState MessagePart::encryptionState() const
316{
317 if (!encryptions().isEmpty()) {
318 return KMMsgFullyEncrypted;
319 }
320 return KMMsgNotEncrypted;
321}
322
323KMMsgSignatureState MessagePart::signatureState() const
324{
325 if (!signatures().isEmpty()) {
326 return KMMsgFullySigned;
327 }
328 return KMMsgNotSigned;
329}
330
315void MessagePart::bindLifetime(KMime::Content *node) 331void MessagePart::bindLifetime(KMime::Content *node)
316{ 332{
317 mNodesToDelete << node; 333 mNodesToDelete << node;
@@ -346,7 +362,9 @@ QString MessagePartList::htmlContent() const
346//-----TextMessageBlock---------------------- 362//-----TextMessageBlock----------------------
347 363
348TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node) 364TextMessagePart::TextMessagePart(ObjectTreeParser *otp, KMime::Content *node)
349 : MessagePartList(otp, node) 365 : MessagePartList(otp, node),
366 mSignatureState(KMMsgSignatureStateUnknown),
367 mEncryptionState(KMMsgEncryptionStateUnknown)
350{ 368{
351 if (!mNode) { 369 if (!mNode) {
352 qCWarning(MIMETREEPARSER_LOG) << "not a valid node"; 370 qCWarning(MIMETREEPARSER_LOG) << "not a valid node";
@@ -401,7 +419,6 @@ void TextMessagePart::parseContent()
401 mp->bindLifetime(content); 419 mp->bindLifetime(content);
402 mp->setIsEncrypted(true); 420 mp->setIsEncrypted(true);
403 appendSubPart(mp); 421 appendSubPart(mp);
404 continue;
405 } else if (block.type() == ClearsignedBlock) { 422 } else if (block.type() == ClearsignedBlock) {
406 KMime::Content *content = new KMime::Content; 423 KMime::Content *content = new KMime::Content;
407 content->setBody(block.text()); 424 content->setBody(block.text());
@@ -410,7 +427,6 @@ void TextMessagePart::parseContent()
410 mp->bindLifetime(content); 427 mp->bindLifetime(content);
411 mp->setIsSigned(true); 428 mp->setIsSigned(true);
412 appendSubPart(mp); 429 appendSubPart(mp);
413 continue;
414 } else { 430 } else {
415 continue; 431 continue;
416 } 432 }
@@ -445,11 +461,17 @@ void TextMessagePart::parseContent()
445 461
446KMMsgEncryptionState TextMessagePart::encryptionState() const 462KMMsgEncryptionState TextMessagePart::encryptionState() const
447{ 463{
464 if (mEncryptionState == KMMsgNotEncrypted) {
465 return MessagePart::encryptionState();
466 }
448 return mEncryptionState; 467 return mEncryptionState;
449} 468}
450 469
451KMMsgSignatureState TextMessagePart::signatureState() const 470KMMsgSignatureState TextMessagePart::signatureState() const
452{ 471{
472 if (mSignatureState == KMMsgNotSigned) {
473 return MessagePart::signatureState();
474 }
453 return mSignatureState; 475 return mSignatureState;
454} 476}
455 477
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h
index 9fe34c3b..dd3a842f 100644
--- a/framework/src/domain/mime/mimetreeparser/messagepart.h
+++ b/framework/src/domain/mime/mimetreeparser/messagepart.h
@@ -112,6 +112,9 @@ public:
112 112
113 KMime::Content *node() const; 113 KMime::Content *node() const;
114 114
115 virtual KMMsgSignatureState signatureState() const;
116 virtual KMMsgEncryptionState encryptionState() const;
117
115 QVector<SignedMessagePart*> signatures() const; 118 QVector<SignedMessagePart*> signatures() const;
116 QVector<EncryptedMessagePart*> encryptions() const; 119 QVector<EncryptedMessagePart*> encryptions() const;
117 120
@@ -178,8 +181,8 @@ public:
178 TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node); 181 TextMessagePart(MimeTreeParser::ObjectTreeParser *otp, KMime::Content *node);
179 virtual ~TextMessagePart(); 182 virtual ~TextMessagePart();
180 183
181 KMMsgSignatureState signatureState() const; 184 KMMsgSignatureState signatureState() const Q_DECL_OVERRIDE;
182 KMMsgEncryptionState encryptionState() const; 185 KMMsgEncryptionState encryptionState() const Q_DECL_OVERRIDE;
183 186
184private: 187private:
185 void parseContent(); 188 void parseContent();
diff --git a/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp b/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp
index 74f12eec..f9b557c9 100644
--- a/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp
+++ b/framework/src/domain/mime/mimetreeparser/tests/interfacetest.cpp
@@ -125,16 +125,22 @@ private slots:
125 QCOMPARE(part->charset(), QStringLiteral("us-ascii").toLocal8Bit()); 125 QCOMPARE(part->charset(), QStringLiteral("us-ascii").toLocal8Bit());
126 QCOMPARE(part->encryptions().size(), 1); 126 QCOMPARE(part->encryptions().size(), 1);
127 QCOMPARE(part->signatures().size(), 1); 127 QCOMPARE(part->signatures().size(), 1);
128 QCOMPARE(part->encryptionState(), MimeTreeParser::KMMsgFullyEncrypted);
129 QCOMPARE(part->signatureState(), MimeTreeParser::KMMsgFullySigned);
128 auto contentAttachmentList = otp.collectAttachmentParts(); 130 auto contentAttachmentList = otp.collectAttachmentParts();
129 QCOMPARE(contentAttachmentList.size(), 2); 131 QCOMPARE(contentAttachmentList.size(), 2);
130 // QCOMPARE(contentAttachmentList[0]->availableContents(), QVector<QByteArray>() << "text/plain"); 132 // QCOMPARE(contentAttachmentList[0]->availableContents(), QVector<QByteArray>() << "text/plain");
131 // QCOMPARE(contentAttachmentList[0]->content().size(), 1); 133 // QCOMPARE(contentAttachmentList[0]->content().size(), 1);
132 QCOMPARE(contentAttachmentList[0]->encryptions().size(), 1); 134 QCOMPARE(contentAttachmentList[0]->encryptions().size(), 1);
133 QCOMPARE(contentAttachmentList[0]->signatures().size(), 1); 135 QCOMPARE(contentAttachmentList[0]->signatures().size(), 1);
136 QCOMPARE(contentAttachmentList[0]->encryptionState(), MimeTreeParser::KMMsgFullyEncrypted);
137 QCOMPARE(contentAttachmentList[0]->signatureState(), MimeTreeParser::KMMsgFullySigned);
134 // QCOMPARE(contentAttachmentList[1]->availableContents(), QVector<QByteArray>() << "image/png"); 138 // QCOMPARE(contentAttachmentList[1]->availableContents(), QVector<QByteArray>() << "image/png");
135 // QCOMPARE(contentAttachmentList[1]->content().size(), 1); 139 // QCOMPARE(contentAttachmentList[1]->content().size(), 1);
136 QCOMPARE(contentAttachmentList[1]->encryptions().size(), 0); 140 QCOMPARE(contentAttachmentList[1]->encryptions().size(), 0);
137 QCOMPARE(contentAttachmentList[1]->signatures().size(), 0); 141 QCOMPARE(contentAttachmentList[1]->signatures().size(), 0);
142 QCOMPARE(contentAttachmentList[1]->encryptionState(), MimeTreeParser::KMMsgNotEncrypted);
143 QCOMPARE(contentAttachmentList[1]->signatureState(), MimeTreeParser::KMMsgNotSigned);
138 } 144 }
139 145
140 void testOpenPGPInline() 146 void testOpenPGPInline()
@@ -173,6 +179,9 @@ private slots:
173 //TODO test if we get the proper subparts with the appropriate encryptions 179 //TODO test if we get the proper subparts with the appropriate encryptions
174 QCOMPARE(part1->charset(), QStringLiteral("us-ascii").toLocal8Bit()); 180 QCOMPARE(part1->charset(), QStringLiteral("us-ascii").toLocal8Bit());
175 181
182 QCOMPARE(part1->encryptionState(), MimeTreeParser::KMMsgPartiallyEncrypted);
183 QCOMPARE(part1->signatureState(), MimeTreeParser::KMMsgNotSigned);
184
176 // QCOMPARE(part1->text(), QStringLiteral("Not encrypted not signed :(\n\n")); 185 // QCOMPARE(part1->text(), QStringLiteral("Not encrypted not signed :(\n\n"));
177 // QCOMPARE(part1->charset(), QStringLiteral("us-ascii").toLocal8Bit()); 186 // QCOMPARE(part1->charset(), QStringLiteral("us-ascii").toLocal8Bit());
178 // QCOMPARE(contentList[1]->content(), QStringLiteral("some random text").toLocal8Bit()); 187 // QCOMPARE(contentList[1]->content(), QStringLiteral("some random text").toLocal8Bit());
diff --git a/framework/src/domain/mime/partmodel.cpp b/framework/src/domain/mime/partmodel.cpp
index b86251ef..ea3e90e1 100644
--- a/framework/src/domain/mime/partmodel.cpp
+++ b/framework/src/domain/mime/partmodel.cpp
@@ -151,9 +151,9 @@ QVariant PartModel::data(const QModelIndex &index, int role) const
151 return text; 151 return text;
152 } 152 }
153 case IsEncryptedRole: 153 case IsEncryptedRole:
154 return messagePart->encryptions().size() > 0; 154 return messagePart->encryptionState() != MimeTreeParser::KMMsgNotEncrypted;
155 case IsSignedRole: 155 case IsSignedRole:
156 return messagePart->signatures().size() > 0; 156 return messagePart->signatureState() != MimeTreeParser::KMMsgNotSigned;
157 case EncryptionErrorType: 157 case EncryptionErrorType:
158 return messagePart->error(); 158 return messagePart->error();
159 case EncryptionErrorString: 159 case EncryptionErrorString: