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 
43 #include <cassert>
44 
45 class KMReaderWin;
46 class KMMessagePart;
47 class TQString;
48 class TQWidget;
49 class partNode;
50 
51 namespace GpgME {
52  class Error;
53 }
54 
55 namespace KMail {
56 
57  class AttachmentStrategy;
58  class HtmlWriter;
59  class PartMetaData;
60  class CSSHelper;
61 
62  class ProcessResult {
63  public:
64  ProcessResult( KMMsgSignatureState inlineSignatureState = KMMsgNotSigned,
65  KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
66  bool neverDisplayInline = false,
67  bool isImage = false )
68  : mInlineSignatureState( inlineSignatureState ),
69  mInlineEncryptionState( inlineEncryptionState ),
70  mNeverDisplayInline( neverDisplayInline ),
71  mIsImage( isImage ) {}
72 
73  KMMsgSignatureState inlineSignatureState() const {
74  return mInlineSignatureState;
75  }
76  void setInlineSignatureState( KMMsgSignatureState state ) {
77  mInlineSignatureState = state;
78  }
79 
80  KMMsgEncryptionState inlineEncryptionState() const {
81  return mInlineEncryptionState;
82  }
83  void setInlineEncryptionState( KMMsgEncryptionState state ) {
84  mInlineEncryptionState = state;
85  }
86 
87  bool neverDisplayInline() const { return mNeverDisplayInline; }
88  void setNeverDisplayInline( bool display ) {
89  mNeverDisplayInline = display;
90  }
91 
92  bool isImage() const { return mIsImage; }
93  void setIsImage( bool image ) {
94  mIsImage = image;
95  }
96 
97  void adjustCryptoStatesOfNode( partNode * node ) const;
98 
99  private:
100  KMMsgSignatureState mInlineSignatureState;
101  KMMsgEncryptionState mInlineEncryptionState;
102  bool mNeverDisplayInline : 1;
103  bool mIsImage : 1;
104  };
105 
106  class ObjectTreeParser {
107  class CryptoProtocolSaver;
109  ObjectTreeParser( const ObjectTreeParser & other );
110  public:
111  ObjectTreeParser( KMReaderWin * reader=0, const Kleo::CryptoBackend::Protocol * protocol=0,
112  bool showOneMimePart=false, bool keepEncryptions=false,
113  bool includeSignatures=true,
114  const KMail::AttachmentStrategy * attachmentStrategy=0,
115  KMail::HtmlWriter * htmlWriter=0,
116  KMail::CSSHelper * cssHelper=0 );
117  virtual ~ObjectTreeParser();
118 
119  void setAllowAsync( bool allow ) { assert( !mHasPendingAsyncJobs ); mAllowAsync = allow; }
120  bool allowAsync() const { return mAllowAsync; }
121 
122  bool hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; }
123 
124  TQCString rawReplyString() const { return mRawReplyString; }
125 
128  TQString textualContent() const { return mTextualContent; }
129 
130  TQCString textualContentCharset() const { return mTextualContentCharset; }
131 
132  void setCryptoProtocol( const Kleo::CryptoBackend::Protocol * protocol ) {
133  mCryptoProtocol = protocol;
134  }
135  const Kleo::CryptoBackend::Protocol* cryptoProtocol() const {
136  return mCryptoProtocol;
137  }
138 
139  bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
140  void setShowOnlyOneMimePart( bool show ) {
141  mShowOnlyOneMimePart = show;
142  }
143 
144  bool keepEncryptions() const { return mKeepEncryptions; }
145  void setKeepEncryptions( bool keep ) {
146  mKeepEncryptions = keep;
147  }
148 
149  bool includeSignatures() const { return mIncludeSignatures; }
150  void setIncludeSignatures( bool include ) {
151  mIncludeSignatures = include;
152  }
153 
154  // Controls whether Toltec invitations are displayed in their raw form or as a replacement text,
155  // which is used in processToltecMail().
156  void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
157  bool showRawToltecMail() const { return mShowRawToltecMail; }
158 
161  static TQString defaultToltecReplacementText();
162 
163  const KMail::AttachmentStrategy * attachmentStrategy() const {
164  return mAttachmentStrategy;
165  }
166 
167  KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
168 
169  KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
170 
173  // Function is called internally by "parseMsg(KMMessage* msg)"
174  // and it will be replaced once KMime is alive.
175  void parseObjectTree( partNode * node );
176 
177  private:
180  void stdChildHandling( partNode * child );
181 
182  void defaultHandling( partNode * node, ProcessResult & result );
183 
196  // Function will be replaced once KMime is alive.
197  void insertAndParseNewChildNode( partNode & node,
198  const char * content,
199  const char * cntDesc,
200  bool append=false,
201  bool addToTextualContent = true );
212  bool writeOpaqueOrMultipartSignedData( partNode * data,
213  partNode & sign,
214  const TQString & fromAddress,
215  bool doCheck=true,
216  TQCString * cleartextData=0,
217  const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
218  bool hideErrors=false );
219 
222  void writeDeferredDecryptionBlock();
223 
226  void writeDecryptionInProgressBlock();
227 
230  bool okDecryptMIME( partNode& data,
231  TQCString& decryptedData,
232  bool& signatureFound,
233  std::vector<GpgME::Signature> &signatures,
234  bool showWarning,
235  bool& passphraseError,
236  bool& actuallyEncrypted,
237  bool& decryptionStarted,
238  TQString& aErrorText,
239  GpgME::Error & auditLogError,
240  TQString& auditLog );
241 
242  bool processMailmanMessage( partNode * node );
243 
253  bool processToltecMail( partNode * node );
254 
259  static bool containsExternalReferences( const TQCString & str );
260 
261  public:// (during refactoring)
262 
263  bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
264  bool processTextPlainSubtype( partNode * node, ProcessResult & result );
265 
266  bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
267  bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
268  bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
269  bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
270  bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
271  bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
272 
273  bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
274 
275  bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
276  bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
277  bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
278  bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
279 
280  private:
281  bool decryptChiasmus( const TQByteArray& data, TQByteArray& bodyDecoded, TQString& errorText );
282  void writeBodyString( const TQCString & bodyString,
283  const TQString & fromAddress,
284  const TQTextCodec * codec,
285  ProcessResult & result, bool decorate );
286 
287  void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
288 
289  TQString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
290  int status_code,
291  GpgME::Signature::Summary summary,
292  int & frameColor,
293  bool & showKeyInfos );
294  TQString writeSigstatHeader( KMail::PartMetaData & part,
295  const Kleo::CryptoBackend::Protocol * cryptProto,
296  const TQString & fromAddress,
297  partNode *node = 0 );
298  TQString writeSigstatFooter( KMail::PartMetaData & part );
299 
300  // The attachment mark is a div that is placed around the attchment. It is used for drawing
301  // a yellow border around the attachment when scrolling to it. When scrolling to it, the border
302  // color of the div is changed, see KMReaderWin::scrollToAttachment().
303  void writeAttachmentMarkHeader( partNode *node );
304  void writeAttachmentMarkFooter();
305 
306  void writeBodyStr( const TQCString & bodyString,
307  const TQTextCodec * aCodec,
308  const TQString & fromAddress,
309  KMMsgSignatureState & inlineSignatureState,
310  KMMsgEncryptionState & inlineEncryptionState,
311  bool decorate );
312  public: // KMReaderWin still needs this...
313  void writeBodyStr( const TQCString & bodyString,
314  const TQTextCodec * aCodec,
315  const TQString & fromAddress );
316 
317  private:
320  TQString quotedHTML(const TQString& pos, bool decorate);
321 
322  const TQTextCodec * codecFor( partNode * node ) const;
323 
324 #ifdef MARCS_DEBUG
325  void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
326 #else
327  void dumpToFile( const char *, const char *, size_t ) {}
328 #endif
329 
330  private:
331  KMReaderWin * mReader;
332  TQCString mRawReplyString;
333  TQCString mTextualContentCharset;
334  TQString mTextualContent;
335  const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
336  bool mShowOnlyOneMimePart;
337  bool mKeepEncryptions;
338  bool mIncludeSignatures;
339  bool mHasPendingAsyncJobs;
340  bool mAllowAsync;
341  bool mShowRawToltecMail;
342  const KMail::AttachmentStrategy * mAttachmentStrategy;
343  KMail::HtmlWriter * mHtmlWriter;
344  KMail::CSSHelper * mCSSHelper;
345  // DataUrl Icons cache
346  TQString mCollapseIcon;
347  TQString mExpandIcon;
348  };
349 
350 } // namespace KMail
351 
352 #endif // _KMAIL_OBJECTTREEPARSER_H_
353 
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