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 <qcstring.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 QString;
00048 class QWidget;
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 QCString rawReplyString() const { return mRawReplyString; }
00125
00128 QString textualContent() const { return mTextualContent; }
00129
00130 QCString 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 const KMail::AttachmentStrategy * attachmentStrategy() const {
00155 return mAttachmentStrategy;
00156 }
00157
00158 KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
00159
00160 KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
00161
00164
00165
00166 void parseObjectTree( partNode * node );
00167
00168 private:
00171 void stdChildHandling( partNode * child );
00172
00173 void defaultHandling( partNode * node, ProcessResult & result );
00174
00180
00181 void insertAndParseNewChildNode( partNode & node,
00182 const char * content,
00183 const char * cntDesc,
00184 bool append=false );
00195 bool writeOpaqueOrMultipartSignedData( partNode * data,
00196 partNode & sign,
00197 const QString & fromAddress,
00198 bool doCheck=true,
00199 QCString * cleartextData=0,
00200 const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
00201 bool hideErrors=false );
00202
00205 void writeDeferredDecryptionBlock();
00206
00209 void writeDecryptionInProgressBlock();
00210
00213 bool okDecryptMIME( partNode& data,
00214 QCString& decryptedData,
00215 bool& signatureFound,
00216 std::vector<GpgME::Signature> &signatures,
00217 bool showWarning,
00218 bool& passphraseError,
00219 bool& actuallyEncrypted,
00220 bool& decryptionStarted,
00221 QString& aErrorText,
00222 GpgME::Error & auditLogError,
00223 QString& auditLog );
00224
00225 bool processMailmanMessage( partNode * node );
00226
00231 static bool containsExternalReferences( const QCString & str );
00232
00233 public:
00234
00235 bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00236 bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00237
00238 bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00239 bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00240 bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00241 bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00242 bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00243 bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00244
00245 bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00246
00247 bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00248 bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00249 bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
00250 bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
00251
00252 private:
00253 bool decryptChiasmus( const QByteArray& data, QByteArray& bodyDecoded, QString& errorText );
00254 void writeBodyString( const QCString & bodyString,
00255 const QString & fromAddress,
00256 const QTextCodec * codec,
00257 ProcessResult & result, bool decorate );
00258
00259 void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00260
00261 QString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
00262 int status_code,
00263 GpgME::Signature::Summary summary,
00264 int & frameColor,
00265 bool & showKeyInfos );
00266 QString writeSigstatHeader( KMail::PartMetaData & part,
00267 const Kleo::CryptoBackend::Protocol * cryptProto,
00268 const QString & fromAddress,
00269 partNode *node = 0 );
00270 QString writeSigstatFooter( KMail::PartMetaData & part );
00271
00272
00273
00274
00275 void writeAttachmentMarkHeader( partNode *node );
00276 void writeAttachmentMarkFooter();
00277
00278 void writeBodyStr( const QCString & bodyString,
00279 const QTextCodec * aCodec,
00280 const QString & fromAddress,
00281 KMMsgSignatureState & inlineSignatureState,
00282 KMMsgEncryptionState & inlineEncryptionState,
00283 bool decorate );
00284 public:
00285 void writeBodyStr( const QCString & bodyString,
00286 const QTextCodec * aCodec,
00287 const QString & fromAddress );
00288
00289 private:
00292 QString quotedHTML(const QString& pos, bool decorate);
00293
00294 const QTextCodec * codecFor( partNode * node ) const;
00295
00296 #ifdef MARCS_DEBUG
00297 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00298 #else
00299 void dumpToFile( const char *, const char *, size_t ) {}
00300 #endif
00301
00302 private:
00303 KMReaderWin * mReader;
00304 QCString mRawReplyString;
00305 QCString mTextualContentCharset;
00306 QString mTextualContent;
00307 const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
00308 bool mShowOnlyOneMimePart;
00309 bool mKeepEncryptions;
00310 bool mIncludeSignatures;
00311 bool mHasPendingAsyncJobs;
00312 bool mAllowAsync;
00313 const KMail::AttachmentStrategy * mAttachmentStrategy;
00314 KMail::HtmlWriter * mHtmlWriter;
00315 KMail::CSSHelper * mCSSHelper;
00316
00317 QString mCollapseIcon;
00318 QString mExpandIcon;
00319 };
00320
00321 }
00322
00323 #endif // _KMAIL_OBJECTTREEPARSER_H_
00324