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
00187
00188 void insertAndParseNewChildNode( partNode & node,
00189 const char * content,
00190 const char * cntDesc,
00191 bool append=false,
00192 bool addToTextualContent = true );
00203 bool writeOpaqueOrMultipartSignedData( partNode * data,
00204 partNode & sign,
00205 const QString & fromAddress,
00206 bool doCheck=true,
00207 QCString * cleartextData=0,
00208 const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
00209 bool hideErrors=false );
00210
00213 void writeDeferredDecryptionBlock();
00214
00217 void writeDecryptionInProgressBlock();
00218
00221 bool okDecryptMIME( partNode& data,
00222 QCString& decryptedData,
00223 bool& signatureFound,
00224 std::vector<GpgME::Signature> &signatures,
00225 bool showWarning,
00226 bool& passphraseError,
00227 bool& actuallyEncrypted,
00228 bool& decryptionStarted,
00229 QString& aErrorText,
00230 GpgME::Error & auditLogError,
00231 QString& auditLog );
00232
00233 bool processMailmanMessage( partNode * node );
00234
00239 static bool containsExternalReferences( const QCString & str );
00240
00241 public:
00242
00243 bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00244 bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00245
00246 bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00247 bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00248 bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00249 bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00250 bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00251 bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00252
00253 bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00254
00255 bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00256 bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00257 bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
00258 bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
00259
00260 private:
00261 bool decryptChiasmus( const QByteArray& data, QByteArray& bodyDecoded, QString& errorText );
00262 void writeBodyString( const QCString & bodyString,
00263 const QString & fromAddress,
00264 const QTextCodec * codec,
00265 ProcessResult & result, bool decorate );
00266
00267 void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00268
00269 QString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
00270 int status_code,
00271 GpgME::Signature::Summary summary,
00272 int & frameColor,
00273 bool & showKeyInfos );
00274 QString writeSigstatHeader( KMail::PartMetaData & part,
00275 const Kleo::CryptoBackend::Protocol * cryptProto,
00276 const QString & fromAddress,
00277 partNode *node = 0 );
00278 QString writeSigstatFooter( KMail::PartMetaData & part );
00279
00280
00281
00282
00283 void writeAttachmentMarkHeader( partNode *node );
00284 void writeAttachmentMarkFooter();
00285
00286 void writeBodyStr( const QCString & bodyString,
00287 const QTextCodec * aCodec,
00288 const QString & fromAddress,
00289 KMMsgSignatureState & inlineSignatureState,
00290 KMMsgEncryptionState & inlineEncryptionState,
00291 bool decorate );
00292 public:
00293 void writeBodyStr( const QCString & bodyString,
00294 const QTextCodec * aCodec,
00295 const QString & fromAddress );
00296
00297 private:
00300 QString quotedHTML(const QString& pos, bool decorate);
00301
00302 const QTextCodec * codecFor( partNode * node ) const;
00303
00304 #ifdef MARCS_DEBUG
00305 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00306 #else
00307 void dumpToFile( const char *, const char *, size_t ) {}
00308 #endif
00309
00310 private:
00311 KMReaderWin * mReader;
00312 QCString mRawReplyString;
00313 QCString mTextualContentCharset;
00314 QString mTextualContent;
00315 const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
00316 bool mShowOnlyOneMimePart;
00317 bool mKeepEncryptions;
00318 bool mIncludeSignatures;
00319 bool mHasPendingAsyncJobs;
00320 bool mAllowAsync;
00321 const KMail::AttachmentStrategy * mAttachmentStrategy;
00322 KMail::HtmlWriter * mHtmlWriter;
00323 KMail::CSSHelper * mCSSHelper;
00324
00325 QString mCollapseIcon;
00326 QString mExpandIcon;
00327 };
00328
00329 }
00330
00331 #endif // _KMAIL_OBJECTTREEPARSER_H_
00332