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 class KMReaderWin;
00044 class KMMessagePart;
00045 class QString;
00046 class QWidget;
00047 class partNode;
00048
00049 namespace GpgME {
00050 class Error;
00051 }
00052
00053 namespace KMail {
00054
00055 class AttachmentStrategy;
00056 class HtmlWriter;
00057 class PartMetaData;
00058 class CSSHelper;
00059
00060 class ProcessResult {
00061 public:
00062 ProcessResult( KMMsgSignatureState inlineSignatureState = KMMsgNotSigned,
00063 KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
00064 bool neverDisplayInline = false,
00065 bool isImage = false )
00066 : mInlineSignatureState( inlineSignatureState ),
00067 mInlineEncryptionState( inlineEncryptionState ),
00068 mNeverDisplayInline( neverDisplayInline ),
00069 mIsImage( isImage ) {}
00070
00071 KMMsgSignatureState inlineSignatureState() const {
00072 return mInlineSignatureState;
00073 }
00074 void setInlineSignatureState( KMMsgSignatureState state ) {
00075 mInlineSignatureState = state;
00076 }
00077
00078 KMMsgEncryptionState inlineEncryptionState() const {
00079 return mInlineEncryptionState;
00080 }
00081 void setInlineEncryptionState( KMMsgEncryptionState state ) {
00082 mInlineEncryptionState = state;
00083 }
00084
00085 bool neverDisplayInline() const { return mNeverDisplayInline; }
00086 void setNeverDisplayInline( bool display ) {
00087 mNeverDisplayInline = display;
00088 }
00089
00090 bool isImage() const { return mIsImage; }
00091 void setIsImage( bool image ) {
00092 mIsImage = image;
00093 }
00094
00095 void adjustCryptoStatesOfNode( partNode * node ) const;
00096
00097 private:
00098 KMMsgSignatureState mInlineSignatureState;
00099 KMMsgEncryptionState mInlineEncryptionState;
00100 bool mNeverDisplayInline : 1;
00101 bool mIsImage : 1;
00102 };
00103
00104 class ObjectTreeParser {
00105 class CryptoProtocolSaver;
00107 ObjectTreeParser( const ObjectTreeParser & other );
00108 public:
00109 ObjectTreeParser( KMReaderWin * reader=0, const Kleo::CryptoBackend::Protocol * protocol=0,
00110 bool showOneMimePart=false, bool keepEncryptions=false,
00111 bool includeSignatures=true,
00112 const KMail::AttachmentStrategy * attachmentStrategy=0,
00113 KMail::HtmlWriter * htmlWriter=0,
00114 KMail::CSSHelper * cssHelper=0 );
00115 virtual ~ObjectTreeParser();
00116
00117 QCString rawReplyString() const { return mRawReplyString; }
00118
00121 QString textualContent() const { return mTextualContent; }
00122
00123 QCString textualContentCharset() const { return mTextualContentCharset; }
00124
00125 void setCryptoProtocol( const Kleo::CryptoBackend::Protocol * protocol ) {
00126 mCryptoProtocol = protocol;
00127 }
00128 const Kleo::CryptoBackend::Protocol* cryptoProtocol() const {
00129 return mCryptoProtocol;
00130 }
00131
00132 bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
00133 void setShowOnlyOneMimePart( bool show ) {
00134 mShowOnlyOneMimePart = show;
00135 }
00136
00137 bool keepEncryptions() const { return mKeepEncryptions; }
00138 void setKeepEncryptions( bool keep ) {
00139 mKeepEncryptions = keep;
00140 }
00141
00142 bool includeSignatures() const { return mIncludeSignatures; }
00143 void setIncludeSignatures( bool include ) {
00144 mIncludeSignatures = include;
00145 }
00146
00147 const KMail::AttachmentStrategy * attachmentStrategy() const {
00148 return mAttachmentStrategy;
00149 }
00150
00151 KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
00152
00153 KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
00154
00157
00158
00159 void parseObjectTree( partNode * node );
00160
00161 private:
00164 void stdChildHandling( partNode * child );
00165
00166 void defaultHandling( partNode * node, ProcessResult & result );
00167
00173
00174 void insertAndParseNewChildNode( partNode & node,
00175 const char * content,
00176 const char * cntDesc,
00177 bool append=false );
00188 bool writeOpaqueOrMultipartSignedData( partNode * data,
00189 partNode & sign,
00190 const QString & fromAddress,
00191 bool doCheck=true,
00192 QCString * cleartextData=0,
00193 const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
00194 bool hideErrors=false );
00195
00198 void writeDeferredDecryptionBlock();
00199
00202 bool okDecryptMIME( partNode& data,
00203 QCString& decryptedData,
00204 bool& signatureFound,
00205 std::vector<GpgME::Signature> &signatures,
00206 bool showWarning,
00207 bool& passphraseError,
00208 bool& actuallyEncrypted,
00209 QString& aErrorText,
00210 GpgME::Error & auditLogError,
00211 QString& auditLog );
00212
00213 bool processMailmanMessage( partNode * node );
00214
00219 static bool containsExternalReferences( const QCString & str );
00220
00221 public:
00222
00223 bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00224 bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00225
00226 bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00227 bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00228 bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00229 bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00230 bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00231 bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00232
00233 bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00234
00235 bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00236 bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00237 bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
00238 bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
00239
00240 private:
00241 bool decryptChiasmus( const QByteArray& data, QByteArray& bodyDecoded, QString& errorText );
00242 void writeBodyString( const QCString & bodyString,
00243 const QString & fromAddress,
00244 const QTextCodec * codec,
00245 ProcessResult & result, bool decorate );
00246
00247 void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00248
00249 QString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
00250 int status_code,
00251 GpgME::Signature::Summary summary,
00252 int & frameColor,
00253 bool & showKeyInfos );
00254 QString writeSigstatHeader( KMail::PartMetaData & part,
00255 const Kleo::CryptoBackend::Protocol * cryptProto,
00256 const QString & fromAddress,
00257 const QString & filename = QString::null );
00258 QString writeSigstatFooter( KMail::PartMetaData & part );
00259
00260 void writeBodyStr( const QCString & bodyString,
00261 const QTextCodec * aCodec,
00262 const QString & fromAddress,
00263 KMMsgSignatureState & inlineSignatureState,
00264 KMMsgEncryptionState & inlineEncryptionState,
00265 bool decorate );
00266 public:
00267 void writeBodyStr( const QCString & bodyString,
00268 const QTextCodec * aCodec,
00269 const QString & fromAddress );
00270
00271 private:
00274 QString quotedHTML(const QString& pos, bool decorate);
00275
00276 const QTextCodec * codecFor( partNode * node ) const;
00277
00278 #ifdef MARCS_DEBUG
00279 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00280 #else
00281 void dumpToFile( const char *, const char *, size_t ) {}
00282 #endif
00283
00284 private:
00285 KMReaderWin * mReader;
00286 QCString mRawReplyString;
00287 QCString mTextualContentCharset;
00288 QString mTextualContent;
00289 const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
00290 bool mShowOnlyOneMimePart;
00291 bool mKeepEncryptions;
00292 bool mIncludeSignatures;
00293 const KMail::AttachmentStrategy * mAttachmentStrategy;
00294 KMail::HtmlWriter * mHtmlWriter;
00295 KMail::CSSHelper * mCSSHelper;
00296
00297 QString mCollapseIcon;
00298 QString mExpandIcon;
00299 };
00300
00301 }
00302
00303 #endif // _KMAIL_OBJECTTREEPARSER_H_
00304