kmail

objecttreeparser.h

00001 /*  -*- mode: C++; c-file-style: "gnu" -*-
00002     objecttreeparser.h
00003 
00004     This file is part of KMail, the KDE mail client.
00005     Copyright (c) 2002-2003 Klarälvdalens Datakonsult AB
00006     Copyright (c) 2003      Marc Mutz <mutz@kde.org>
00007 
00008     KMail is free software; you can redistribute it and/or modify it
00009     under the terms of the GNU General Public License, version 2, as
00010     published by the Free Software Foundation.
00011 
00012     KMail is distributed in the hope that it will be useful, but
00013     WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
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 #include <cassert>
00044 
00045 class KMReaderWin;
00046 class KMMessagePart;
00047 class QString;
00048 class QWidget;
00049 class partNode;
00050 
00051 namespace GpgME {
00052   class Error;
00053 }
00054 
00055 namespace KMail {
00056 
00057   class AttachmentStrategy;
00058   class HtmlWriter;
00059   class PartMetaData;
00060   class CSSHelper;
00061 
00062   class ProcessResult {
00063   public:
00064     ProcessResult( KMMsgSignatureState  inlineSignatureState  = KMMsgNotSigned,
00065                    KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
00066                    bool neverDisplayInline = false,
00067                    bool isImage = false )
00068       : mInlineSignatureState( inlineSignatureState ),
00069         mInlineEncryptionState( inlineEncryptionState ),
00070         mNeverDisplayInline( neverDisplayInline ),
00071         mIsImage( isImage ) {}
00072 
00073     KMMsgSignatureState inlineSignatureState() const {
00074       return mInlineSignatureState;
00075     }
00076     void setInlineSignatureState( KMMsgSignatureState state ) {
00077       mInlineSignatureState = state;
00078     }
00079 
00080     KMMsgEncryptionState inlineEncryptionState() const {
00081       return mInlineEncryptionState;
00082     }
00083     void setInlineEncryptionState( KMMsgEncryptionState state ) {
00084       mInlineEncryptionState = state;
00085     }
00086 
00087     bool neverDisplayInline() const { return mNeverDisplayInline; }
00088     void setNeverDisplayInline( bool display ) {
00089       mNeverDisplayInline = display;
00090     }
00091 
00092     bool isImage() const { return mIsImage; }
00093     void setIsImage( bool image ) {
00094       mIsImage = image;
00095     }
00096 
00097     void adjustCryptoStatesOfNode( partNode * node ) const;
00098 
00099   private:
00100     KMMsgSignatureState mInlineSignatureState;
00101     KMMsgEncryptionState mInlineEncryptionState;
00102     bool mNeverDisplayInline : 1;
00103     bool mIsImage : 1;
00104   };
00105 
00106   class ObjectTreeParser {
00107     class CryptoProtocolSaver;
00109     ObjectTreeParser( const ObjectTreeParser & other );
00110   public:
00111     ObjectTreeParser( KMReaderWin * reader=0, const Kleo::CryptoBackend::Protocol * protocol=0,
00112                       bool showOneMimePart=false, bool keepEncryptions=false,
00113                       bool includeSignatures=true,
00114                       const KMail::AttachmentStrategy * attachmentStrategy=0,
00115                       KMail::HtmlWriter * htmlWriter=0,
00116                       KMail::CSSHelper * cssHelper=0 );
00117     virtual ~ObjectTreeParser();
00118 
00119     void setAllowAsync( bool allow ) { assert( !mHasPendingAsyncJobs ); mAllowAsync = allow; }
00120     bool allowAsync() const { return mAllowAsync; }
00121 
00122     bool hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; }
00123 
00124     QCString rawReplyString() const { return mRawReplyString; }
00125 
00128     QString textualContent() const { return mTextualContent; }
00129 
00130     QCString textualContentCharset() const { return mTextualContentCharset; }
00131 
00132     void setCryptoProtocol( const Kleo::CryptoBackend::Protocol * protocol ) {
00133       mCryptoProtocol = protocol;
00134     }
00135     const Kleo::CryptoBackend::Protocol* cryptoProtocol() const {
00136       return mCryptoProtocol;
00137     }
00138 
00139     bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
00140     void setShowOnlyOneMimePart( bool show ) {
00141       mShowOnlyOneMimePart = show;
00142     }
00143 
00144     bool keepEncryptions() const { return mKeepEncryptions; }
00145     void setKeepEncryptions( bool keep ) {
00146       mKeepEncryptions = keep;
00147     }
00148 
00149     bool includeSignatures() const { return mIncludeSignatures; }
00150     void setIncludeSignatures( bool include ) {
00151       mIncludeSignatures = include;
00152     }
00153 
00154     // Controls whether Toltec invitations are displayed in their raw form or as a replacement text,
00155     // which is used in processToltecMail().
00156     void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
00157     bool showRawToltecMail() const { return mShowRawToltecMail; }
00158 
00159     const KMail::AttachmentStrategy * attachmentStrategy() const {
00160       return mAttachmentStrategy;
00161     }
00162 
00163     KMail::HtmlWriter * htmlWriter() const { return mHtmlWriter; }
00164 
00165     KMail::CSSHelper * cssHelper() const { return mCSSHelper; }
00166 
00169     //  Function is called internally by "parseMsg(KMMessage* msg)"
00170     //  and it will be replaced once KMime is alive.
00171     void parseObjectTree( partNode * node );
00172 
00173   private:
00176     void stdChildHandling( partNode * child );
00177 
00178     void defaultHandling( partNode * node, ProcessResult & result );
00179 
00192     //  Function will be replaced once KMime is alive.
00193     void insertAndParseNewChildNode( partNode & node,
00194                                      const char * content,
00195                                      const char * cntDesc,
00196                                      bool append=false,
00197                                      bool addToTextualContent = true );
00208     bool writeOpaqueOrMultipartSignedData( partNode * data,
00209                                            partNode & sign,
00210                                            const QString & fromAddress,
00211                                            bool doCheck=true,
00212                                            QCString * cleartextData=0,
00213                                            const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
00214                                            bool hideErrors=false );
00215 
00218     void writeDeferredDecryptionBlock();
00219 
00222     void writeDecryptionInProgressBlock();
00223 
00226     bool okDecryptMIME( partNode& data,
00227                         QCString& decryptedData,
00228                         bool& signatureFound,
00229                         std::vector<GpgME::Signature> &signatures,
00230                         bool showWarning,
00231                         bool& passphraseError,
00232                         bool& actuallyEncrypted,
00233                         bool& decryptionStarted,
00234                         QString& aErrorText,
00235                         GpgME::Error & auditLogError,
00236                         QString& auditLog );
00237 
00238     bool processMailmanMessage( partNode * node );
00239 
00249     bool processToltecMail( partNode * node );
00250 
00255     static bool containsExternalReferences( const QCString & str );
00256 
00257   public:// (during refactoring)
00258 
00259     bool processTextHtmlSubtype( partNode * node, ProcessResult & result );
00260     bool processTextPlainSubtype( partNode * node, ProcessResult & result );
00261 
00262     bool processMultiPartMixedSubtype( partNode * node, ProcessResult & result );
00263     bool processMultiPartAlternativeSubtype( partNode * node, ProcessResult & result );
00264     bool processMultiPartDigestSubtype( partNode * node, ProcessResult & result );
00265     bool processMultiPartParallelSubtype( partNode * node, ProcessResult & result );
00266     bool processMultiPartSignedSubtype( partNode * node, ProcessResult & result );
00267     bool processMultiPartEncryptedSubtype( partNode * node, ProcessResult & result );
00268 
00269     bool processMessageRfc822Subtype( partNode * node, ProcessResult & result );
00270 
00271     bool processApplicationOctetStreamSubtype( partNode * node, ProcessResult & result );
00272     bool processApplicationPkcs7MimeSubtype( partNode * node, ProcessResult & result );
00273     bool processApplicationChiasmusTextSubtype( partNode * node, ProcessResult & result );
00274     bool processApplicationMsTnefSubtype( partNode *node, ProcessResult &result );
00275 
00276   private:
00277     bool decryptChiasmus( const QByteArray& data, QByteArray& bodyDecoded, QString& errorText );
00278     void writeBodyString( const QCString & bodyString,
00279                           const QString & fromAddress,
00280                           const QTextCodec * codec,
00281                           ProcessResult & result, bool decorate );
00282 
00283     void writePartIcon( KMMessagePart * msgPart, int partNumber, bool inlineImage=false );
00284 
00285     QString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
00286                                int status_code,
00287                                GpgME::Signature::Summary summary,
00288                                int & frameColor,
00289                                bool & showKeyInfos );
00290     QString writeSigstatHeader( KMail::PartMetaData & part,
00291                                 const Kleo::CryptoBackend::Protocol * cryptProto,
00292                                 const QString & fromAddress,
00293                                 partNode *node = 0 );
00294     QString writeSigstatFooter( KMail::PartMetaData & part );
00295 
00296     // The attachment mark is a div that is placed around the attchment. It is used for drawing
00297     // a yellow border around the attachment when scrolling to it. When scrolling to it, the border
00298     // color of the div is changed, see KMReaderWin::scrollToAttachment().
00299     void writeAttachmentMarkHeader( partNode *node );
00300     void writeAttachmentMarkFooter();
00301 
00302     void writeBodyStr( const QCString & bodyString,
00303                        const QTextCodec * aCodec,
00304                        const QString & fromAddress,
00305                        KMMsgSignatureState &  inlineSignatureState,
00306                        KMMsgEncryptionState & inlineEncryptionState,
00307                        bool decorate );
00308   public: // KMReaderWin still needs this...
00309     void writeBodyStr( const QCString & bodyString,
00310                        const QTextCodec * aCodec,
00311                        const QString & fromAddress );
00312 
00313   private:
00316     QString quotedHTML(const QString& pos, bool decorate);
00317 
00318     const QTextCodec * codecFor( partNode * node ) const;
00319 
00320 #ifdef MARCS_DEBUG
00321     void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
00322 #else
00323     void dumpToFile( const char *, const char *, size_t ) {}
00324 #endif
00325 
00326   private:
00327     KMReaderWin * mReader;
00328     QCString mRawReplyString;
00329     QCString mTextualContentCharset;
00330     QString mTextualContent;
00331     const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
00332     bool mShowOnlyOneMimePart;
00333     bool mKeepEncryptions;
00334     bool mIncludeSignatures;
00335     bool mHasPendingAsyncJobs;
00336     bool mAllowAsync;
00337     bool mShowRawToltecMail;
00338     const KMail::AttachmentStrategy * mAttachmentStrategy;
00339     KMail::HtmlWriter * mHtmlWriter;
00340     KMail::CSSHelper * mCSSHelper;
00341     // DataUrl Icons cache
00342     QString mCollapseIcon;
00343     QString mExpandIcon;
00344   };
00345 
00346 } // namespace KMail
00347 
00348 #endif // _KMAIL_OBJECTTREEPARSER_H_
00349 
KDE Home | KDE Accessibility Home | Description of Access Keys