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
00114 void setCryptPlugWrapper( CryptPlugWrapper * wrapper ) {
00115 mCryptPlugWrapper = wrapper;
00116 }
00117 CryptPlugWrapper * cryptPlugWrapper() const {
00118 return mCryptPlugWrapper;
00119 }
00120
00121 bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
00122 void setShowOnlyOneMimePart( bool show ) {
00123 mShowOnlyOneMimePart = show;
00124 }
00125
00126 bool keepEncryptions() const { return mKeepEncryptions; }
00127 void setKeepEncryptions( bool keep ) {
00128 mKeepEncryptions = keep;
00129 }
00130
00131 bool includeSignatures() const { return mIncludeSignatures; }
00132 void setIncludeSignatures( bool include ) {
00133 mIncludeSignatures = include;
00134 }
00135
00136 const KMail::AttachmentStrategy * attachmentStrategy() const {
00137 return mAttachmentStrategy;
00138 }
00139
00140 KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
00141
00142 KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
00143
00146
00147
00148 void parseObjectTree( partNode * node );
00149
00156 static QString byteArrayToTempFile( KMReaderWin* reader,
00157 const QString& dirExt,
00158 const QString& fileName,
00159 const QByteArray& theBody );
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 struct CryptPlugWrapper::SignatureMetaData * paramSigMeta=0,
00194 bool hideErrors=false );
00195
00198 bool okDecryptMIME( partNode& data,
00199 QCString& decryptedData,
00200 bool& signatureFound,
00201 struct CryptPlugWrapper::SignatureMetaData& sigMeta,
00202 bool showWarning,
00203 bool& passphraseError,
00204 QString& aErrorText );
00205
00206 bool processMailmanMessage( partNode * node );
00207
00208 public:
00209
00210 bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00211 bool processTextVCalSubtype( partNode * node, ProcessResult & result );
00212 bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00213
00214 bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00215 bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00216 bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00217 bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00218 bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00219 bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00220
00221 bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00222
00223 bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00224 bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00225 bool processApplicationMsTnefSubtype( partNode * node, ProcessResult & result );
00226
00227 private:
00228 void writeBodyString( const QCString & bodyString,
00229 const QString & fromAddress,
00230 const QTextCodec * codec,
00231 ProcessResult & result );
00232
00233 void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00234
00235 QString sigStatusToString( CryptPlugWrapper * cryptPlug,
00236 int status_code,
00237 CryptPlugWrapper::SigStatusFlags statusFlags,
00238 int & frameColor,
00239 bool & showKeyInfos );
00240 QString writeSigstatHeader( KMail::PartMetaData & part,
00241 CryptPlugWrapper * cryptPlug,
00242 const QString & fromAddress,
00243 const QString & filename = QString::null );
00244 QString writeSigstatFooter( KMail::PartMetaData & part );
00245
00246 void writeBodyStr( const QCString & bodyString,
00247 const QTextCodec * aCodec,
00248 const QString & fromAddress,
00249 KMMsgSignatureState & inlineSignatureState,
00250 KMMsgEncryptionState & inlineEncryptionState );
00251 public:
00252 void writeBodyStr( const QCString & bodyString,
00253 const QTextCodec * aCodec,
00254 const QString & fromAddress );
00255
00256 private:
00259 QString quotedHTML(const QString& pos);
00260
00261 const QTextCodec * codecFor( partNode * node ) const;
00262
00263 #ifdef MARCS_DEBUG
00264 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00265 #else
00266 void dumpToFile( const char *, const char *, size_t ) {}
00267 #endif
00268
00269 private:
00270 KMReaderWin * mReader;
00271 QCString mRawReplyString;
00272 CryptPlugWrapper * mCryptPlugWrapper;
00273 bool mShowOnlyOneMimePart;
00274 bool mKeepEncryptions;
00275 bool mIncludeSignatures;
00276 bool mIsFirstTextPart;
00277 const KMail::AttachmentStrategy * mAttachmentStrategy;
00278 KMail::HtmlWriter * mHtmlWriter;
00279 KMail::CSSHelper * mCSSHelper;
00280 };
00281
00282 }
00283
00284 #endif // _KMAIL_OBJECTTREEPARSER_H_
00285