00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _KMAIL_OBJECTTREEPARSER_H_
00034 #define _KMAIL_OBJECTTREEPARSER_H_
00035
00036 #include "kmmsgbase.h"
00037
00038 #include <tqcstring.h>
00039
00040 #include <kleo/cryptobackend.h>
00041 #include <gpgmepp/verificationresult.h>
00042
00043 #include <cassert>
00044
00045 class KMReaderWin;
00046 class KMMessagePart;
00047 class TQString;
00048 class TQWidget;
00049 class partNode;
00050
00051 namespace GpgME {
00052 class Error;
00053 }
00054
00055 namespace KMail {
00056
00057 class AttachmentStrategy;
00058 class HtmlWriter;
00059 class PartMetaData;
00060 class CSSHelper;
00061
00062 class ProcessResult {
00063 public:
00064 ProcessResult( KMMsgSignatureState inlineSignatureState = KMMsgNotSigned,
00065 KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
00066 bool neverDisplayInline = false,
00067 bool isImage = false )
00068 : mInlineSignatureState( inlineSignatureState ),
00069 mInlineEncryptionState( inlineEncryptionState ),
00070 mNeverDisplayInline( neverDisplayInline ),
00071 mIsImage( isImage ) {}
00072
00073 KMMsgSignatureState inlineSignatureState() const {
00074 return mInlineSignatureState;
00075 }
00076 void setInlineSignatureState( KMMsgSignatureState state ) {
00077 mInlineSignatureState = state;
00078 }
00079
00080 KMMsgEncryptionState inlineEncryptionState() const {
00081 return mInlineEncryptionState;
00082 }
00083 void setInlineEncryptionState( KMMsgEncryptionState state ) {
00084 mInlineEncryptionState = state;
00085 }
00086
00087 bool neverDisplayInline() const { return mNeverDisplayInline; }
00088 void setNeverDisplayInline( bool display ) {
00089 mNeverDisplayInline = display;
00090 }
00091
00092 bool isImage() const { return mIsImage; }
00093 void setIsImage( bool image ) {
00094 mIsImage = image;
00095 }
00096
00097 void adjustCryptoStatesOfNode( partNode * node ) const;
00098
00099 private:
00100 KMMsgSignatureState mInlineSignatureState;
00101 KMMsgEncryptionState mInlineEncryptionState;
00102 bool mNeverDisplayInline : 1;
00103 bool mIsImage : 1;
00104 };
00105
00106 class ObjectTreeParser {
00107 class CryptoProtocolSaver;
00109 ObjectTreeParser( const ObjectTreeParser & other );
00110 public:
00111 ObjectTreeParser( KMReaderWin * reader=0, const Kleo::CryptoBackend::Protocol * protocol=0,
00112 bool showOneMimePart=false, bool keepEncryptions=false,
00113 bool includeSignatures=true,
00114 const KMail::AttachmentStrategy * attachmentStrategy=0,
00115 KMail::HtmlWriter * htmlWriter=0,
00116 KMail::CSSHelper * cssHelper=0 );
00117 virtual ~ObjectTreeParser();
00118
00119 void setAllowAsync( bool allow ) { assert( !mHasPendingAsyncJobs ); mAllowAsync = allow; }
00120 bool allowAsync() const { return mAllowAsync; }
00121
00122 bool hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; }
00123
00124 TQCString rawReplyString() const { return mRawReplyString; }
00125
00128 TQString textualContent() const { return mTextualContent; }
00129
00130 TQCString textualContentCharset() const { return mTextualContentCharset; }
00131
00132 void setCryptoProtocol( const Kleo::CryptoBackend::Protocol * protocol ) {
00133 mCryptoProtocol = protocol;
00134 }
00135 const Kleo::CryptoBackend::Protocol* cryptoProtocol() const {
00136 return mCryptoProtocol;
00137 }
00138
00139 bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
00140 void setShowOnlyOneMimePart( bool show ) {
00141 mShowOnlyOneMimePart = show;
00142 }
00143
00144 bool keepEncryptions() const { return mKeepEncryptions; }
00145 void setKeepEncryptions( bool keep ) {
00146 mKeepEncryptions = keep;
00147 }
00148
00149 bool includeSignatures() const { return mIncludeSignatures; }
00150 void setIncludeSignatures( bool include ) {
00151 mIncludeSignatures = include;
00152 }
00153
00154
00155
00156 void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
00157 bool showRawToltecMail() const { return mShowRawToltecMail; }
00158
00161 static TQString defaultToltecReplacementText();
00162
00163 const KMail::AttachmentStrategy * attachmentStrategy() const {
00164 return mAttachmentStrategy;
00165 }
00166
00167 KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
00168
00169 KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
00170
00173
00174
00175 void parseObjectTree( partNode * node );
00176
00177 private:
00180 void stdChildHandling( partNode * child );
00181
00182 void defaultHandling( partNode * node, ProcessResult & result );
00183
00196
00197 void insertAndParseNewChildNode( partNode & node,
00198 const char * content,
00199 const char * cntDesc,
00200 bool append=false,
00201 bool addToTextualContent = true );
00212 bool writeOpaqueOrMultipartSignedData( partNode * data,
00213 partNode & sign,
00214 const TQString & fromAddress,
00215 bool doCheck=true,
00216 TQCString * cleartextData=0,
00217 const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
00218 bool hideErrors=false );
00219
00222 void writeDeferredDecryptionBlock();
00223
00226 void writeDecryptionInProgressBlock();
00227
00230 bool okDecryptMIME( partNode& data,
00231 TQCString& decryptedData,
00232 bool& signatureFound,
00233 std::vector<GpgME::Signature> &signatures,
00234 bool showWarning,
00235 bool& passphraseError,
00236 bool& actuallyEncrypted,
00237 bool& decryptionStarted,
00238 TQString& aErrorText,
00239 GpgME::Error & auditLogError,
00240 TQString& auditLog );
00241
00242 bool processMailmanMessage( partNode * node );
00243
00253 bool processToltecMail( partNode * node );
00254
00259 static bool containsExternalReferences( const TQCString & str );
00260
00261 public:
00262
00263 bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00264 bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00265
00266 bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00267 bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00268 bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00269 bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00270 bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00271 bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00272
00273 bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00274
00275 bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00276 bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00277 bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
00278 bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
00279
00280 private:
00281 bool decryptChiasmus( const TQByteArray& data, TQByteArray& bodyDecoded, TQString& errorText );
00282 void writeBodyString( const TQCString & bodyString,
00283 const TQString & fromAddress,
00284 const TQTextCodec * codec,
00285 ProcessResult & result, bool decorate );
00286
00287 void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00288
00289 TQString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
00290 int status_code,
00291 GpgME::Signature::Summary summary,
00292 int & frameColor,
00293 bool & showKeyInfos );
00294 TQString writeSigstatHeader( KMail::PartMetaData & part,
00295 const Kleo::CryptoBackend::Protocol * cryptProto,
00296 const TQString & fromAddress,
00297 partNode *node = 0 );
00298 TQString writeSigstatFooter( KMail::PartMetaData & part );
00299
00300
00301
00302
00303 void writeAttachmentMarkHeader( partNode *node );
00304 void writeAttachmentMarkFooter();
00305
00306 void writeBodyStr( const TQCString & bodyString,
00307 const TQTextCodec * aCodec,
00308 const TQString & fromAddress,
00309 KMMsgSignatureState & inlineSignatureState,
00310 KMMsgEncryptionState & inlineEncryptionState,
00311 bool decorate );
00312 public:
00313 void writeBodyStr( const TQCString & bodyString,
00314 const TQTextCodec * aCodec,
00315 const TQString & fromAddress );
00316
00317 private:
00320 TQString quotedHTML(const TQString& pos, bool decorate);
00321
00322 const TQTextCodec * codecFor( partNode * node ) const;
00323
00324 #ifdef MARCS_DEBUG
00325 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00326 #else
00327 void dumpToFile( const char *, const char *, size_t ) {}
00328 #endif
00329
00330 private:
00331 KMReaderWin * mReader;
00332 TQCString mRawReplyString;
00333 TQCString mTextualContentCharset;
00334 TQString mTextualContent;
00335 const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
00336 bool mShowOnlyOneMimePart;
00337 bool mKeepEncryptions;
00338 bool mIncludeSignatures;
00339 bool mHasPendingAsyncJobs;
00340 bool mAllowAsync;
00341 bool mShowRawToltecMail;
00342 const KMail::AttachmentStrategy * mAttachmentStrategy;
00343 KMail::HtmlWriter * mHtmlWriter;
00344 KMail::CSSHelper * mCSSHelper;
00345
00346 TQString mCollapseIcon;
00347 TQString mExpandIcon;
00348 };
00349
00350 }
00351
00352 #endif // _KMAIL_OBJECTTREEPARSER_H_
00353