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