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 <cryptplugwrapper.h>
00039 #include <qcstring.h>
00040
00041 class KMReaderWin;
00042 class KMMessagePart;
00043 class QString;
00044 class QWidget;
00045 class partNode;
00046
00047 namespace KMail {
00048
00049 class AttachmentStrategy;
00050 class HtmlWriter;
00051 class PartMetaData;
00052 class CSSHelper;
00053
00054 class ProcessResult {
00055 public:
00056 ProcessResult( KMMsgSignatureState inlineSignatureState = KMMsgNotSigned,
00057 KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
00058 bool neverDisplayInline = false,
00059 bool isImage = false )
00060 : mInlineSignatureState( inlineSignatureState ),
00061 mInlineEncryptionState( inlineEncryptionState ),
00062 mNeverDisplayInline( neverDisplayInline ),
00063 mIsImage( isImage ) {}
00064
00065 KMMsgSignatureState inlineSignatureState() const {
00066 return mInlineSignatureState;
00067 }
00068 void setInlineSignatureState( KMMsgSignatureState state ) {
00069 mInlineSignatureState = state;
00070 }
00071
00072 KMMsgEncryptionState inlineEncryptionState() const {
00073 return mInlineEncryptionState;
00074 }
00075 void setInlineEncryptionState( KMMsgEncryptionState state ) {
00076 mInlineEncryptionState = state;
00077 }
00078
00079 bool neverDisplayInline() const { return mNeverDisplayInline; }
00080 void setNeverDisplayInline( bool display ) {
00081 mNeverDisplayInline = display;
00082 }
00083
00084 bool isImage() const { return mIsImage; }
00085 void setIsImage( bool image ) {
00086 mIsImage = image;
00087 }
00088
00089 void adjustCryptoStatesOfNode( partNode * node ) const;
00090
00091 private:
00092 KMMsgSignatureState mInlineSignatureState;
00093 KMMsgEncryptionState mInlineEncryptionState;
00094 bool mNeverDisplayInline : 1;
00095 bool mIsImage : 1;
00096 };
00097
00098 class ObjectTreeParser {
00099 class CryptPlugWrapperSaver;
00102 ObjectTreeParser( const ObjectTreeParser & other );
00103 public:
00104 ObjectTreeParser( KMReaderWin * reader=0, CryptPlugWrapper * wrapper=0,
00105 bool showOneMimePart=false, bool keepEncryptions=false,
00106 bool includeSignatures=true,
00107 const KMail::AttachmentStrategy * attachmentStrategy=0,
00108 KMail::HtmlWriter * htmlWriter=0,
00109 KMail::CSSHelper * cssHelper=0 );
00110 virtual ~ObjectTreeParser();
00111
00112 QCString rawReplyString() const { return mRawReplyString; }
00113
00116 QString textualContent() const { return mTextualContent; }
00117
00118 QCString textualContentCharset() const { return mTextualContentCharset; }
00119
00120 void setCryptPlugWrapper( CryptPlugWrapper * wrapper ) {
00121 mCryptPlugWrapper = wrapper;
00122 }
00123 CryptPlugWrapper * cryptPlugWrapper() const {
00124 return mCryptPlugWrapper;
00125 }
00126
00127 bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
00128 void setShowOnlyOneMimePart( bool show ) {
00129 mShowOnlyOneMimePart = show;
00130 }
00131
00132 bool keepEncryptions() const { return mKeepEncryptions; }
00133 void setKeepEncryptions( bool keep ) {
00134 mKeepEncryptions = keep;
00135 }
00136
00137 bool includeSignatures() const { return mIncludeSignatures; }
00138 void setIncludeSignatures( bool include ) {
00139 mIncludeSignatures = include;
00140 }
00141
00142 const KMail::AttachmentStrategy * attachmentStrategy() const {
00143 return mAttachmentStrategy;
00144 }
00145
00146 KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
00147
00148 KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
00149
00152
00153
00154 void parseObjectTree( partNode * node );
00155
00156 private:
00159 void stdChildHandling( partNode * child );
00160
00161 void defaultHandling( partNode * node, ProcessResult & result );
00162
00168
00169 void insertAndParseNewChildNode( partNode & node,
00170 const char * content,
00171 const char * cntDesc,
00172 bool append=false );
00183 bool writeOpaqueOrMultipartSignedData( partNode * data,
00184 partNode & sign,
00185 const QString & fromAddress,
00186 bool doCheck=true,
00187 QCString * cleartextData=0,
00188 CryptPlug::SignatureMetaData * paramSigMeta=0,
00189 bool hideErrors=false );
00190
00193 bool okDecryptMIME( partNode& data,
00194 QCString& decryptedData,
00195 bool& signatureFound,
00196 CryptPlug::SignatureMetaData& sigMeta,
00197 bool showWarning,
00198 bool& passphraseError,
00199 QString& aErrorText );
00200
00201 bool processMailmanMessage( partNode * node );
00202
00203 public:
00204
00205 bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00206 bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00207
00208 bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00209 bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00210 bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00211 bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00212 bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00213 bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00214
00215 bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00216
00217 bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00218 bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00219
00220 private:
00221 void writeBodyString( const QCString & bodyString,
00222 const QString & fromAddress,
00223 const QTextCodec * codec,
00224 ProcessResult & result );
00225
00226 void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00227
00228 QString sigStatusToString( CryptPlugWrapper * cryptPlug,
00229 int status_code,
00230 CryptPlugWrapper::SigStatusFlags statusFlags,
00231 int & frameColor,
00232 bool & showKeyInfos );
00233 QString writeSigstatHeader( KMail::PartMetaData & part,
00234 CryptPlugWrapper * cryptPlug,
00235 const QString & fromAddress,
00236 const QString & filename = QString::null );
00237 QString writeSigstatFooter( KMail::PartMetaData & part );
00238
00239 void writeBodyStr( const QCString & bodyString,
00240 const QTextCodec * aCodec,
00241 const QString & fromAddress,
00242 KMMsgSignatureState & inlineSignatureState,
00243 KMMsgEncryptionState & inlineEncryptionState );
00244 public:
00245 void writeBodyStr( const QCString & bodyString,
00246 const QTextCodec * aCodec,
00247 const QString & fromAddress );
00248
00249 private:
00252 QString quotedHTML(const QString& pos);
00253
00254 const QTextCodec * codecFor( partNode * node ) const;
00255
00256 #ifdef MARCS_DEBUG
00257 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00258 #else
00259 void dumpToFile( const char *, const char *, size_t ) {}
00260 #endif
00261
00262 private:
00263 KMReaderWin * mReader;
00264 QCString mRawReplyString;
00265 QCString mTextualContentCharset;
00266 QString mTextualContent;
00267 CryptPlugWrapper * mCryptPlugWrapper;
00268 bool mShowOnlyOneMimePart;
00269 bool mKeepEncryptions;
00270 bool mIncludeSignatures;
00271 const KMail::AttachmentStrategy * mAttachmentStrategy;
00272 KMail::HtmlWriter * mHtmlWriter;
00273 KMail::CSSHelper * mCSSHelper;
00274 };
00275
00276 }
00277
00278 #endif // _KMAIL_OBJECTTREEPARSER_H_
00279