kmail

objecttreeparser.h
1 /*
2  objecttreeparser.h
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2002-2003 Klarälvdalens Datakonsult AB
6  Copyright (c) 2003 Marc Mutz <mutz@kde.org>
7 
8  KMail is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License, version 2, as
10  published by the Free Software Foundation.
11 
12  KMail is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the TQt library by Trolltech AS, Norway (or with modified versions
24  of TQt that use the same license as TQt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  TQt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #ifndef _KMAIL_OBJECTTREEPARSER_H_
34 #define _KMAIL_OBJECTTREEPARSER_H_
35 
36 #include "kmmsgbase.h"
37 
38 #include <tqcstring.h>
39 
40 #include <kleo/cryptobackend.h>
41 #include <gpgmepp/verificationresult.h>
42 #include <gpgmepp/key.h>
43 
44 #include <cassert>
45 
46 class KMReaderWin;
47 class KMMessagePart;
48 class TQString;
49 class TQWidget;
50 class partNode;
51 
52 namespace GpgME {
53  class Error;
54 }
55 
56 namespace KMail {
57 
58  class AttachmentStrategy;
59  class HtmlWriter;
60  class PartMetaData;
61  class CSSHelper;
62 
63  class ProcessResult {
64  public:
65  ProcessResult( KMMsgSignatureState inlineSignatureState = KMMsgNotSigned,
66  KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
67  bool neverDisplayInline = false,
68  bool isImage = false )
69  : mInlineSignatureState( inlineSignatureState ),
70  mInlineEncryptionState( inlineEncryptionState ),
71  mNeverDisplayInline( neverDisplayInline ),
72  mIsImage( isImage ) {}
73 
74  KMMsgSignatureState inlineSignatureState() const {
75  return mInlineSignatureState;
76  }
77  void setInlineSignatureState( KMMsgSignatureState state ) {
78  mInlineSignatureState = state;
79  }
80 
81  KMMsgEncryptionState inlineEncryptionState() const {
82  return mInlineEncryptionState;
83  }
84  void setInlineEncryptionState( KMMsgEncryptionState state ) {
85  mInlineEncryptionState = state;
86  }
87 
88  bool neverDisplayInline() const { return mNeverDisplayInline; }
89  void setNeverDisplayInline( bool display ) {
90  mNeverDisplayInline = display;
91  }
92 
93  bool isImage() const { return mIsImage; }
94  void setIsImage( bool image ) {
95  mIsImage = image;
96  }
97 
98  void adjustCryptoStatesOfNode( partNode * node ) const;
99 
100  private:
101  KMMsgSignatureState mInlineSignatureState;
102  KMMsgEncryptionState mInlineEncryptionState;
103  bool mNeverDisplayInline : 1;
104  bool mIsImage : 1;
105  };
106 
107  class ObjectTreeParser {
108  class CryptoProtocolSaver;
110  ObjectTreeParser( const ObjectTreeParser & other );
111  public:
112  ObjectTreeParser( KMReaderWin * reader=0, const Kleo::CryptoBackend::Protocol * protocol=0,
113  bool showOneMimePart=false, bool keepEncryptions=false,
114  bool includeSignatures=true,
115  const KMail::AttachmentStrategy * attachmentStrategy=0,
116  KMail::HtmlWriter * htmlWriter=0,
117  KMail::CSSHelper * cssHelper=0 );
118  virtual ~ObjectTreeParser();
119 
120  void setAllowAsync( bool allow ) { assert( !mHasPendingAsyncJobs ); mAllowAsync = allow; }
121  bool allowAsync() const { return mAllowAsync; }
122 
123  bool hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; }
124 
125  TQCString rawReplyString() const { return mRawReplyString; }
126 
129  TQString textualContent() const { return mTextualContent; }
130 
131  TQCString textualContentCharset() const { return mTextualContentCharset; }
132 
133  void setCryptoProtocol( const Kleo::CryptoBackend::Protocol * protocol ) {
134  mCryptoProtocol = protocol;
135  }
136  const Kleo::CryptoBackend::Protocol* cryptoProtocol() const {
137  return mCryptoProtocol;
138  }
139 
140  bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
141  void setShowOnlyOneMimePart( bool show ) {
142  mShowOnlyOneMimePart = show;
143  }
144 
145  bool keepEncryptions() const { return mKeepEncryptions; }
146  void setKeepEncryptions( bool keep ) {
147  mKeepEncryptions = keep;
148  }
149 
150  bool includeSignatures() const { return mIncludeSignatures; }
151  void setIncludeSignatures( bool include ) {
152  mIncludeSignatures = include;
153  }
154 
155  // Controls whether Toltec invitations are displayed in their raw form or as a replacement text,
156  // which is used in processToltecMail().
157  void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
158  bool showRawToltecMail() const { return mShowRawToltecMail; }
159 
162  static TQString defaultToltecReplacementText();
163 
164  const KMail::AttachmentStrategy * attachmentStrategy() const {
165  return mAttachmentStrategy;
166  }
167 
168  KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
169 
170  KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
171 
174  // Function is called internally by "parseMsg(KMMessage* msg)"
175  // and it will be replaced once KMime is alive.
176  void parseObjectTree( partNode * node );
177 
178  private:
181  void stdChildHandling( partNode * child );
182 
183  void defaultHandling( partNode * node, ProcessResult & result );
184 
197  // Function will be replaced once KMime is alive.
198  void insertAndParseNewChildNode( partNode & node,
199  const char * content,
200  const char * cntDesc,
201  bool append=false,
202  bool addToTextualContent = true );
213  bool writeOpaqueOrMultipartSignedData( partNode * data,
214  partNode & sign,
215  const TQString & fromAddress,
216  bool doCheck=true,
217  bool hideErrors=false,
218  TQCString * cleartextData=0,
219  const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
220  const GpgME::Key & paramKey = GpgME::Key() );
221 
224  void writeDeferredDecryptionBlock();
225 
228  void writeDecryptionInProgressBlock();
229 
232  bool okDecryptMIME( partNode& data,
233  TQCString& decryptedData,
234  bool& signatureFound,
235  std::vector<GpgME::Signature> &signatures,
236  GpgME::Key &key,
237  bool showWarning,
238  bool& passphraseError,
239  bool& actuallyEncrypted,
240  bool& decryptionStarted,
241  TQString& aErrorText,
242  GpgME::Error & auditLogError,
243  TQString& auditLog );
244 
245  bool processMailmanMessage( partNode * node );
246 
256  bool processToltecMail( partNode * node );
257 
262  static bool containsExternalReferences( const TQCString & str );
263 
264  public:// (during refactoring)
265 
266  bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
267  bool processTextPlainSubtype( partNode * node, ProcessResult & result );
268 
269  bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
270  bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
271  bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
272  bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
273  bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
274  bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
275 
276  bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
277 
278  bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
279  bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
280  bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
281  bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
282 
283  private:
284  bool decryptChiasmus( const TQByteArray& data, TQByteArray& bodyDecoded, TQString& errorText );
285  void writeBodyString( const TQCString & bodyString,
286  const TQString & fromAddress,
287  const TQTextCodec * codec,
288  ProcessResult & result, bool decorate );
289 
290  void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
291 
292  TQString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
293  int status_code,
294  GpgME::Signature::Summary summary,
295  int & frameColor,
296  bool & showKeyInfos );
297  TQString writeSigstatHeader( KMail::PartMetaData & part,
298  const Kleo::CryptoBackend::Protocol * cryptProto,
299  const TQString & fromAddress,
300  partNode *node = 0 );
301  TQString writeSigstatFooter( KMail::PartMetaData & part );
302 
303  // The attachment mark is a div that is placed around the attchment. It is used for drawing
304  // a yellow border around the attachment when scrolling to it. When scrolling to it, the border
305  // color of the div is changed, see KMReaderWin::scrollToAttachment().
306  void writeAttachmentMarkHeader( partNode *node );
307  void writeAttachmentMarkFooter();
308 
309  void writeBodyStr( const TQCString & bodyString,
310  const TQTextCodec * aCodec,
311  const TQString & fromAddress,
312  KMMsgSignatureState & inlineSignatureState,
313  KMMsgEncryptionState & inlineEncryptionState,
314  bool decorate );
315  public: // KMReaderWin still needs this...
316  void writeBodyStr( const TQCString & bodyString,
317  const TQTextCodec * aCodec,
318  const TQString & fromAddress );
319 
320  private:
323  TQString quotedHTML(const TQString& pos, bool decorate);
324 
325  const TQTextCodec * codecFor( partNode * node ) const;
326 
327 #ifdef MARCS_DEBUG
328  void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
329 #else
330  void dumpToFile( const char *, const char *, size_t ) {}
331 #endif
332 
333  private:
334  KMReaderWin * mReader;
335  TQCString mRawReplyString;
336  TQCString mTextualContentCharset;
337  TQString mTextualContent;
338  const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
339  bool mShowOnlyOneMimePart;
340  bool mKeepEncryptions;
341  bool mIncludeSignatures;
342  bool mHasPendingAsyncJobs;
343  bool mAllowAsync;
344  bool mShowRawToltecMail;
345  const KMail::AttachmentStrategy * mAttachmentStrategy;
346  KMail::HtmlWriter * mHtmlWriter;
347  KMail::CSSHelper * mCSSHelper;
348  // DataUrl Icons cache
349  TQString mCollapseIcon;
350  TQString mExpandIcon;
351  };
352 
353 } // namespace KMail
354 
355 #endif // _KMAIL_OBJECTTREEPARSER_H_
356 
This class implements a "reader window", that is a window used for reading or viewing messages.
Definition: kmreaderwin.h:75
An interface to HTML sinks.
Definition: htmlwriter.h:99
folderdiaquotatab.h
Definition: aboutdata.cpp:40