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 std::vector<GpgME::Signature> paramSignatures = std::vector<GpgME::Signature>(),
00194 bool hideErrors=false );
00195
00198 bool okDecryptMIME( partNode& data,
00199 QCString& decryptedData,
00200 bool& signatureFound,
00201 std::vector<GpgME::Signature> &signatures,
00202 bool showWarning,
00203 bool& passphraseError,
00204 bool& actuallyEncrypted,
00205 QString& aErrorText,
00206 GpgME::Error & auditLogError,
00207 QString& auditLog );
00208
00209 bool processMailmanMessage( partNode * node );
00210
00215 static bool containsExternalReferences( const QCString & str );
00216
00217 public:
00218
00219 bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00220 bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00221
00222 bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00223 bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00224 bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00225 bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00226 bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00227 bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00228
00229 bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00230
00231 bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00232 bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00233 bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
00234 bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
00235
00236 private:
00237 bool decryptChiasmus( const QByteArray& data, QByteArray& bodyDecoded, QString& errorText );
00238 void writeBodyString( const QCString & bodyString,
00239 const QString & fromAddress,
00240 const QTextCodec * codec,
00241 ProcessResult & result, bool decorate );
00242
00243 void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00244
00245 QString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
00246 int status_code,
00247 GpgME::Signature::Summary summary,
00248 int & frameColor,
00249 bool & showKeyInfos );
00250 QString writeSigstatHeader( KMail::PartMetaData & part,
00251 const Kleo::CryptoBackend::Protocol * cryptProto,
00252 const QString & fromAddress,
00253 const QString & filename = QString::null );
00254 QString writeSigstatFooter( KMail::PartMetaData & part );
00255
00256 void writeBodyStr( const QCString & bodyString,
00257 const QTextCodec * aCodec,
00258 const QString & fromAddress,
00259 KMMsgSignatureState & inlineSignatureState,
00260 KMMsgEncryptionState & inlineEncryptionState,
00261 bool decorate );
00262 public:
00263 void writeBodyStr( const QCString & bodyString,
00264 const QTextCodec * aCodec,
00265 const QString & fromAddress );
00266
00267 private:
00270 QString quotedHTML(const QString& pos, bool decorate);
00271
00272 const QTextCodec * codecFor( partNode * node ) const;
00273
00274 #ifdef MARCS_DEBUG
00275 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00276 #else
00277 void dumpToFile( const char *, const char *, size_t ) {}
00278 #endif
00279
00280 private:
00281 KMReaderWin * mReader;
00282 QCString mRawReplyString;
00283 QCString mTextualContentCharset;
00284 QString mTextualContent;
00285 const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
00286 bool mShowOnlyOneMimePart;
00287 bool mKeepEncryptions;
00288 bool mIncludeSignatures;
00289 const KMail::AttachmentStrategy * mAttachmentStrategy;
00290 KMail::HtmlWriter * mHtmlWriter;
00291 KMail::CSSHelper * mCSSHelper;
00292
00293 QString mCollapseIcon;
00294 QString mExpandIcon;
00295 };
00296
00297 }
00298
00299 #endif // _KMAIL_OBJECTTREEPARSER_H_
00300