summaryrefslogtreecommitdiffstats
path: root/framework/domain/mimetreeparser/test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/mimetreeparser/test.cpp')
-rw-r--r--framework/domain/mimetreeparser/test.cpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/framework/domain/mimetreeparser/test.cpp b/framework/domain/mimetreeparser/test.cpp
new file mode 100644
index 00000000..e096ea78
--- /dev/null
+++ b/framework/domain/mimetreeparser/test.cpp
@@ -0,0 +1,146 @@
1Usecases:
2
3# plaintext msg + attachment
4* ContentPart => cp1
5* AttachmentPart => ap1
6
7(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
8(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
9
10(PlainText) == cp1.availableContent()
11
12# html msg + related attachment + normal attachment
13* ContentPart => cp1
14* AttachmentPart(mimetype="*/related", cid="12345678") => ap1
15* AttachmentPart => ap2
16
17(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
18(ap1, ap2) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
19(ap2) == collect<AttachmentParts>(select=NoEncapsulatedMessages, filter=filterelated)
20
21ap1 == getPart("cid:12345678")
22
23(Html) == cp1.availableContent()
24
25# alternative msg + attachment
26* ContentPart(html="HTML", plaintext="Text") => cp1
27* AttachmentPart => ap1
28
29(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
30(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
31
32(Html, PlainText) == cp1.availableContent()
33"HTML" == cp1.content(Html)
34"text" == cp1.content(Plaintext)
35
36# alternative msg with GPGInline
37* ContentPart(html="HTML", plaintext="Text cypted<foo>") => cp1
38 * TextPart(text="Text")
39 * TextPart(text=foo, encryption=(enc1)
40
41(Html, PlainText) == cp1.availableContent()
42
43TODO: but how to get plaintext/html content?
44
45# encrypted msg (not encrypted/error) with unencrypted attachment
46* EncryptionErrorPart => cp1
47* AttachmentPart => ap1
48
49(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
50(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
51
52#encrypted msg (decrypted with attachment) + unencrypted attachment
53* encrytion=(rec1,rec2) => enc1
54 * ContentPart(encrytion = (enc1,)) => cp1
55 * AttachmentPart(encryption = (enc1,)) => ap1
56* AttachmentPart => ap2
57
58(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
59(ap1, ap2) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
60
61#INLINE GPG encrypted msg + attachment
62* ContentPart => cp1
63 * TextPart
64 * TextPart(encrytion = (enc1(rec1,rec2),))
65 * TextPart(signed = (sig1,))
66 * TextPart
67* AttachmentPart => ap1
68
69(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
70(ap1) == collect<AttachmentParts>(select=NoEncapsulatedMessages)
71
72#forwared encrypted msg + attachments
73* ContentPart => cp1
74* EncapsulatedPart => ep1
75 * Encrytion=(rec1,rec2) => enc1
76 * Signature => sig1
77 * ContentPart(encrytion = (enc1,), signature = (sig1,)) => cp2
78 * TextPart(encrytion = (enc1,), signature = (sig1,))
79 * TextPart(encrytion = (enc1, enc2(rec3,rec4),), signature = (sig1,))
80 * AttachmentPart(encrytion = (enc1,), signature = (sig1,)) => ap1
81* AttachmentPart => ap2
82
83(cp1) = collect<ContentPart>(select=NoEncapsulatedMessages)
84(ap2) = collect<AttachmentParts>(select=NoEncapsulatedMessages)
85
86(cp2) = collect<ContentPart>(ep1, select=NoEncapsulatedMessages)
87(ap1) = collect<AttachmentParts>(ep1, select=NoEncapsulatedMessages)
88
89(cp1, cp2) == collect<ContentPart>()
90(ap1, ap2) == collect<AttachmentParts>()
91
92
93# plaintext msg + attachment + cert
94* ContentPart => cp1
95* AttachmentPart => ap1
96* CertPart => cep1
97
98(cp1) == collect<ContentPart>(select=NoEncapsulatedMessages)
99(ap1, cep1) == collect<AttachmentPart>(select=NoEncapsulatedMessages)
100(ap1) == collect<AttachmentPart>(select=NoEncapsulatedMessages, filter=filterSubAttachmentParts)
101
102(cep1) == collect<CertPart>(select=NoEncapsulatedMessages)
103
104
105collect function:
106
107bool noEncapsulatedMessages(Part part)
108{
109 if (is<EncapsulatedPart>(part)) {
110 return false;
111 }
112 return true;
113}
114
115bool filterRelated(T part)
116{
117 if (part.mimetype == related && !part.cid.isEmpty()) {
118 return false; //filter out related parts
119 }
120 return true;
121}
122
123bool filterSubAttachmentParts(AttachmentPart part)
124{
125 if (isSubPart<AttachmentPart>(part)) {
126 return false; // filter out CertPart f.ex.
127 }
128 return true;
129}
130
131List<T> collect<T>(Part start, std::function<bool(const Part &)> select, std::function<bool(const std::shared_ptr<T> &)> filter) {
132 List<T> col;
133 if (!select(start)) {
134 return col;
135 }
136
137 if(isOrSubTypeIs<T>(start) && filter(start.staticCast<T>)){
138 col.append(p);
139 }
140 foreach(childs as child) {
141 if (select(child)) {
142 col.expand(collect(child,select,filter);
143 }
144 }
145 return col;
146} \ No newline at end of file