1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/*
objecttreeparser.h
This file is part of KMail, the KDE mail client.
Copyright (c) 2002-2003 Klarälvdalens Datakonsult AB
Copyright (c) 2003 Marc Mutz <[email protected]>
KMail is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
KMail is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the TQt library by Trolltech AS, Norway (or with modified versions
of TQt that use the same license as TQt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
TQt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifndef _KMAIL_OBJECTTREEPARSER_H_
#define _KMAIL_OBJECTTREEPARSER_H_
#include "kmmsgbase.h"
#include <tqcstring.h>
#include <kleo/cryptobackend.h>
#include <gpgmepp/verificationresult.h>
#include <cassert>
class KMReaderWin;
class KMMessagePart;
class TQString;
class TQWidget;
class partNode;
namespace GpgME {
class Error;
}
namespace KMail {
class AttachmentStrategy;
class HtmlWriter;
class PartMetaData;
class CSSHelper;
class ProcessResult {
public:
ProcessResult( KMMsgSignatureState inlineSignatureState = KMMsgNotSigned,
KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
bool neverDisplayInline = false,
bool isImage = false )
: mInlineSignatureState( inlineSignatureState ),
mInlineEncryptionState( inlineEncryptionState ),
mNeverDisplayInline( neverDisplayInline ),
mIsImage( isImage ) {}
KMMsgSignatureState inlineSignatureState() const {
return mInlineSignatureState;
}
void setInlineSignatureState( KMMsgSignatureState state ) {
mInlineSignatureState = state;
}
KMMsgEncryptionState inlineEncryptionState() const {
return mInlineEncryptionState;
}
void setInlineEncryptionState( KMMsgEncryptionState state ) {
mInlineEncryptionState = state;
}
bool neverDisplayInline() const { return mNeverDisplayInline; }
void setNeverDisplayInline( bool display ) {
mNeverDisplayInline = display;
}
bool isImage() const { return mIsImage; }
void setIsImage( bool image ) {
mIsImage = image;
}
void adjustCryptoStatesOfNode( partNode * node ) const;
private:
KMMsgSignatureState mInlineSignatureState;
KMMsgEncryptionState mInlineEncryptionState;
bool mNeverDisplayInline : 1;
bool mIsImage : 1;
};
class ObjectTreeParser {
class CryptoProtocolSaver;
/** Internal. Copies the context of @p other, but not it's rawReplyString() */
ObjectTreeParser( const ObjectTreeParser & other );
public:
ObjectTreeParser( KMReaderWin * reader=0, const Kleo::CryptoBackend::Protocol * protocol=0,
bool showOneMimePart=false, bool keepEncryptions=false,
bool includeSignatures=true,
const KMail::AttachmentStrategy * attachmentStrategy=0,
KMail::HtmlWriter * htmlWriter=0,
KMail::CSSHelper * cssHelper=0 );
virtual ~ObjectTreeParser();
void setAllowAsync( bool allow ) { assert( !mHasPendingAsyncJobs ); mAllowAsync = allow; }
bool allowAsync() const { return mAllowAsync; }
bool hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; }
TQCString rawReplyString() const { return mRawReplyString; }
/*! @return the text of the message, ie. what would appear in the
composer's text editor if this was edited. */
TQString textualContent() const { return mTextualContent; }
TQCString textualContentCharset() const { return mTextualContentCharset; }
void setCryptoProtocol( const Kleo::CryptoBackend::Protocol * protocol ) {
mCryptoProtocol = protocol;
}
const Kleo::CryptoBackend::Protocol* cryptoProtocol() const {
return mCryptoProtocol;
}
bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
void setShowOnlyOneMimePart( bool show ) {
mShowOnlyOneMimePart = show;
}
bool keepEncryptions() const { return mKeepEncryptions; }
void setKeepEncryptions( bool keep ) {
mKeepEncryptions = keep;
}
bool includeSignatures() const { return mIncludeSignatures; }
void setIncludeSignatures( bool include ) {
mIncludeSignatures = include;
}
// Controls whether Toltec invitations are displayed in their raw form or as a replacement text,
// which is used in processToltecMail().
void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
bool showRawToltecMail() const { return mShowRawToltecMail; }
/// default text for processToltecMail(), which is used in kmail.kcfg, therefore it
/// needs to be static here.
static TQString defaultToltecReplacementText();
const KMail::AttachmentStrategy * attachmentStrategy() const {
return mAttachmentStrategy;
}
KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
/** Parse beginning at a given node and recursively parsing
the children of that node and it's next sibling. */
// Function is called internally by "parseMsg(KMMessage* msg)"
// and it will be replaced once KMime is alive.
void parseObjectTree( partNode * node );
private:
/** Standard children handling a.k.a. multipart/mixed (w/o
kroupware hacks) */
void stdChildHandling( partNode * child );
void defaultHandling( partNode * node, ProcessResult & result );
/**
* 1. Create a new partNode using 'content' data and Content-Description
* found in 'cntDesc'.
* 2. Make this node the child of 'node'.
* 3. Insert the respective entries in the Mime Tree Viewer.
* 3. Parse the 'node' to display the content.
*
* @param addToTextualContent If true, this will add the textual content of the parsed node
* to the textual content of the current object tree parser.
* Setting this to false is useful for encapsulated messages, as we
* do not want the text in those to appear in the editor
*/
// Function will be replaced once KMime is alive.
void insertAndParseNewChildNode( partNode & node,
const char * content,
const char * cntDesc,
bool append=false,
bool addToTextualContent = true );
/** if data is 0:
Feeds the HTML widget with the contents of the opaque signed
data found in partNode 'sign'.
if data is set:
Feeds the HTML widget with the contents of the given
multipart/signed object.
Signature is tested. May contain body parts.
Returns whether a signature was found or not: use this to
find out if opaque data is signed or not. */
bool writeOpaqueOrMultipartSignedData( partNode * data,
partNode & sign,
const TQString & fromAddress,
bool doCheck=true,
TQCString * cleartextData=0,
const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
bool hideErrors=false );
/** Writes out the block that we use when the node is encrypted,
but we're deferring decryption for later. */
void writeDeferredDecryptionBlock();
/** Writes out the block that we use when the node is encrypted,
but we've just kicked off async decryption. */
void writeDecryptionInProgressBlock();
/** Returns the contents of the given multipart/encrypted
object. Data is decypted. May contain body parts. */
bool okDecryptMIME( partNode& data,
TQCString& decryptedData,
bool& signatureFound,
std::vector<GpgME::Signature> &signatures,
bool showWarning,
bool& passphraseError,
bool& actuallyEncrypted,
bool& decryptionStarted,
TQString& aErrorText,
GpgME::Error & auditLogError,
TQString& auditLog );
bool processMailmanMessage( partNode * node );
/**
* This is called for all multipart/mixed nodes. It checks if that belongs to a Toltec mail,
* by checking various criteria.
* If it is a toltec mail, a special text, instead of the confusing toltec text, will be
* displayed.
*
* @return true if the mail was indeed a toltec mail, in which case the node should not be
* processed further
*/
bool processToltecMail( partNode * node );
/** Checks whether @p str contains external references. To be precise,
we only check whether @p str contains 'xxx="http[s]:' where xxx is
not href. Obfuscated external references are ignored on purpose.
*/
static bool containsExternalReferences( const TQCString & str );
public:// (during refactoring)
bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
bool processTextPlainSubtype( partNode * node, ProcessResult & result );
bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
private:
bool decryptChiasmus( const TQByteArray& data, TQByteArray& bodyDecoded, TQString& errorText );
void writeBodyString( const TQCString & bodyString,
const TQString & fromAddress,
const TQTextCodec * codec,
ProcessResult & result, bool decorate );
void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
TQString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
int status_code,
GpgME::Signature::Summary summary,
int & frameColor,
bool & showKeyInfos );
TQString writeSigstatHeader( KMail::PartMetaData & part,
const Kleo::CryptoBackend::Protocol * cryptProto,
const TQString & fromAddress,
partNode *node = 0 );
TQString writeSigstatFooter( KMail::PartMetaData & part );
// The attachment mark is a div that is placed around the attchment. It is used for drawing
// a yellow border around the attachment when scrolling to it. When scrolling to it, the border
// color of the div is changed, see KMReaderWin::scrollToAttachment().
void writeAttachmentMarkHeader( partNode *node );
void writeAttachmentMarkFooter();
void writeBodyStr( const TQCString & bodyString,
const TQTextCodec * aCodec,
const TQString & fromAddress,
KMMsgSignatureState & inlineSignatureState,
KMMsgEncryptionState & inlineEncryptionState,
bool decorate );
public: // KMReaderWin still needs this...
void writeBodyStr( const TQCString & bodyString,
const TQTextCodec * aCodec,
const TQString & fromAddress );
private:
/** Change the string to `quoted' html (meaning, that the quoted
part of the message get italized */
TQString quotedHTML(const TQString& pos, bool decorate);
const TQTextCodec * codecFor( partNode * node ) const;
#ifdef MARCS_DEBUG
void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
#else
void dumpToFile( const char *, const char *, size_t ) {}
#endif
private:
KMReaderWin * mReader;
TQCString mRawReplyString;
TQCString mTextualContentCharset;
TQString mTextualContent;
const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
bool mShowOnlyOneMimePart;
bool mKeepEncryptions;
bool mIncludeSignatures;
bool mHasPendingAsyncJobs;
bool mAllowAsync;
bool mShowRawToltecMail;
const KMail::AttachmentStrategy * mAttachmentStrategy;
KMail::HtmlWriter * mHtmlWriter;
KMail::CSSHelper * mCSSHelper;
// DataUrl Icons cache
TQString mCollapseIcon;
TQString mExpandIcon;
};
} // namespace KMail
#endif // _KMAIL_OBJECTTREEPARSER_H_
|