kmail

messagecomposer.h

Go to the documentation of this file.
00001 /*
00002  *  messagecomposer.cpp
00003  *
00004  *  Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  *  In addition, as a special exception, the copyright holders give
00020  *  permission to link the code of this program with any edition of
00021  *  the Qt library by Trolltech AS, Norway (or with modified versions
00022  *  of Qt that use the same license as Qt), and distribute linked
00023  *  combinations including the two.  You must obey the GNU General
00024  *  Public License in all respects for all of the code used other than
00025  *  Qt.  If you modify this file, you may extend this exception to
00026  *  your version of the file, but you are not obligated to do so.  If
00027  *  you do not wish to do so, delete this exception statement from
00028  *  your version.
00029  */
00030 
00031 #ifndef MESSAGECOMPOSER_H
00032 #define MESSAGECOMPOSER_H
00033 
00034 #include "kmmsgpart.h"
00035 #include "keyresolver.h"
00036 
00037 #include <qobject.h>
00038 #include <qvaluevector.h>
00039 
00040 #include <mimelib/mediatyp.h>
00041 #include <kleo/cryptobackend.h>
00042 #include <kpgp.h>
00043 
00044 #include <vector>
00045 
00046 class KMMessage;
00047 class KMComposeWin;
00048 
00049 class MessageComposerJob;
00050 class EncryptMessageJob;
00051 class SetLastMessageAsUnencryptedVersionOfLastButOne;
00052 
00053 namespace Kleo {
00054   class KeyResolver;
00055 }
00056 
00057 namespace GpgME {
00058   class Key;
00059 }
00060 
00061 namespace KPIM {
00062   class Identity;
00063 }
00064 
00065 class MessageComposer : public QObject {
00066   Q_OBJECT
00067   friend class ::MessageComposerJob;
00068   friend class ::EncryptMessageJob;
00069   friend class ::SetLastMessageAsUnencryptedVersionOfLastButOne;
00070 
00071 public:
00072   class KeyResolver;
00073 
00074   MessageComposer( KMComposeWin* win, const char* name=0 );
00075   ~MessageComposer();
00076 
00084   void applyChanges( bool disableCrypto );
00085 
00086   QString originalBCC() const { return mBcc; }
00087 
00088   void setDisableBreaking( bool b ) { mDisableBreaking = b; }
00089 
00090   const QValueVector<KMMessage*> & composedMessageList() const {
00091     return mMessageList;
00092   }
00093 
00094   bool isPerformingSignOperation() const { return mPerformingSignOperation; }
00095 signals:
00096   void done( bool );
00097 
00098 private:
00099   void readFromComposeWin();
00100 
00101   void adjustCryptFlags();
00102 
00103   bool encryptWithChiasmus( const Kleo::CryptoBackend::Protocol * chiasmus,
00104                             const QByteArray& body,
00105                             QByteArray& resultData );
00106   void chiasmusEncryptAllAttachments();
00107   void composeChiasmusMessage( KMMessage& theMessage, Kleo::CryptoMessageFormat format );
00108 
00109   // This is the composeMessage method
00110   void composeMessage();
00111   // And these two are the parts that should be run after job completions
00112   void createUnencryptedMessageVersion();
00113 
00121   void composeMessage( KMMessage& theMessage,
00122                        bool doSign, bool doEncrypt,
00123                Kleo::CryptoMessageFormat format );
00124   void continueComposeMessage( KMMessage& theMessage, bool doSign,
00125                                bool doEncrypt,
00126                    Kleo::CryptoMessageFormat format );
00127 
00131   void composeInlineOpenPGPMessage( KMMessage& theMessage,
00132                                     bool doSign, bool doEncrypt );
00133 
00138   QByteArray breakLinesAndApplyCodec();
00139 
00144   QCString plainTextFromMarkup( const QString& markupText );
00145 
00150   void pgpSignedMsg( const QByteArray& cText, Kleo::CryptoMessageFormat f );
00155   Kpgp::Result pgpEncryptedMsg( QByteArray& rEncryptedBody,
00156                                 const QByteArray& cText,
00157                                 const std::vector<GpgME::Key> & encryptionKeys,
00158                 Kleo::CryptoMessageFormat f );
00159 
00164   Kpgp::Result pgpSignedAndEncryptedMsg( QByteArray& rEncryptedBody,
00165                      const QByteArray& cText,
00166                      const std::vector<GpgME::Key> & signingKeys,
00167                      const std::vector<GpgME::Key> & encryptionKeys,
00168                      Kleo::CryptoMessageFormat f );
00169 
00173   bool checkForEncryptCertificateExpiry( const QString& recipient,
00174                                          const QCString& certFingerprint );
00175 
00187   bool processStructuringInfo( const QString bugURL,
00188                                const QString contentDescriptionClear,
00189                                const QCString contentTypeClear,
00190                                const QCString contentSubtypeClear,
00191                                const QCString contentDispClear,
00192                                const QCString contentTEncClear,
00193                                const QByteArray& bodytext,
00194                                const QString contentDescriptionCiph,
00195                                const QByteArray& ciphertext,
00196                                KMMessagePart& resultingPart,
00197                    bool signing, Kleo::CryptoMessageFormat format );
00198 
00199   void encryptMessage( KMMessage* msg, const Kleo::KeyResolver::SplitInfo & si,
00200                        bool doSign, bool doEncrypt,
00201                        KMMessagePart newBodyPart,
00202                Kleo::CryptoMessageFormat format );
00203 
00204   void addBodyAndAttachments( KMMessage* msg, const Kleo::KeyResolver::SplitInfo & si,
00205                               bool doSign, bool doEncrypt,
00206                               const KMMessagePart& ourFineBodyPart,
00207                               Kleo::CryptoMessageFormat format );
00208 
00209 private slots:
00210   void slotDoNextJob();
00211 
00212 private:
00213   void doNextJob();
00214   void emitDone( bool ok );
00215 
00216   int encryptionPossible( const QStringList & recipients, bool openPGP );
00217   bool determineWhetherToSign( bool doSignCompletely );
00218   bool determineWhetherToEncrypt( bool doEncryptCompletely );
00219   void markAllAttachmentsForSigning( bool sign );
00220   void markAllAttachmentsForEncryption( bool enc );
00221 
00222   KMComposeWin* mComposeWin;
00223   MessageComposerJob * mCurrentJob;
00224   KMMessage* mReferenceMessage;
00225   QValueVector<KMMessage*> mMessageList;
00226 
00227   Kleo::KeyResolver * mKeyResolver;
00228 
00229   QCString mSignCertFingerprint;
00230 
00231   struct Attachment {
00232     Attachment( KMMessagePart * p=0, bool s=false, bool e=false )
00233       : part( p ), sign( s ), encrypt( e ) {}
00234     KMMessagePart * part;
00235     bool sign;
00236     bool encrypt;
00237   };
00238   QValueVector<Attachment> mAttachments;
00239 
00240   QString mPGPSigningKey, mSMIMESigningKey;
00241   bool mUseOpportunisticEncryption;
00242   bool mSignBody, mEncryptBody;
00243   bool mSigningRequested, mEncryptionRequested;
00244   bool mDoSign, mDoEncrypt;
00245   unsigned int mAllowedCryptoMessageFormats;
00246   bool mDisableCrypto;
00247   bool mDisableBreaking;
00248   QString mBcc;
00249   QStringList mTo, mCc, mBccList;
00250   bool mDebugComposerCrypto;
00251   bool mAutoCharset;
00252   QCString mCharset;
00253   bool mIsRichText;
00254   uint mIdentityUid;
00255   bool mRc; // Set this to false, if something fails during the processes
00256   bool mHoldJobs; // Don't run the next job yet
00257 
00258   QByteArray mText; // textual representation of the message text, encoded
00259   unsigned int mLineBreakColumn; // used for line breaking
00260 
00261   // These are the variables of the big composeMessage(X,Y,Z) message
00262   KMMessagePart* mNewBodyPart;
00263   QByteArray mSignature;
00264 
00265   QByteArray mEncodedBody; // Only needed if signing and/or encrypting
00266   bool mEarlyAddAttachments, mAllAttachmentsAreInBody;
00267   KMMessagePart mOldBodyPart;
00268   int mPreviousBoundaryLevel;
00269 
00270   // The boundary is saved for later addition into mp/a body
00271   DwString  mSaveBoundary;
00272   QCString mMultipartMixedBoundary;
00273 
00274   QValueList<MessageComposerJob*> mJobs;
00275   bool mEncryptWithChiasmus;
00276   bool mPerformingSignOperation;
00277 };
00278 
00279 #endif /* MESSAGECOMPOSER_H */