00001
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 class CryptPlugWrapper;
00049
00050 class MessageComposerJob;
00051
00052 namespace Kleo {
00053 class KeyResolver;
00054 }
00055
00056 namespace GpgME {
00057 class Key;
00058 }
00059
00060 class MessageComposer : public QObject {
00061 Q_OBJECT
00062 friend class MessageComposerJob;
00063 friend class EncryptMessageJob;
00064 friend class SetLastMessageAsUnencryptedVersionOfLastButOne;
00065
00066 public:
00067 class KeyResolver;
00068
00069 MessageComposer( KMComposeWin* win, const char* name=0 );
00070 ~MessageComposer();
00071
00079 void applyChanges( bool disableCrypto );
00080
00081 QString originalBCC() const { return mBcc; }
00082
00083 void setDisableBreaking( bool b ) { mDisableBreaking = b; }
00084
00085 const QValueVector<KMMessage*> & composedMessageList() const {
00086 return mMessageList;
00087 }
00088
00089 signals:
00090 void done( bool );
00091
00092 private:
00093 void readFromComposeWin();
00094
00095 void adjustCryptFlags();
00096
00097 #ifdef KLEO_CHIASMUS
00098 bool encryptWithChiasmus( const Kleo::CryptoBackend::Protocol * chiasmus,
00099 const QByteArray& body,
00100 QByteArray& resultData );
00101 void chiasmusEncryptAllAttachments();
00102 void composeChiasmusMessage( KMMessage& theMessage, Kleo::CryptoMessageFormat format );
00103 #endif
00104
00105
00106 void composeMessage();
00107
00108 void createUnencryptedMessageVersion();
00109
00117 void composeMessage( KMMessage& theMessage,
00118 bool doSign, bool doEncrypt,
00119 Kleo::CryptoMessageFormat format );
00120 void continueComposeMessage( KMMessage& theMessage, bool doSign,
00121 bool doEncrypt,
00122 Kleo::CryptoMessageFormat format );
00123
00127 void composeInlineOpenPGPMessage( KMMessage& theMessage,
00128 bool doSign, bool doEncrypt );
00129
00134 QCString breakLinesAndApplyCodec();
00136 QCString bodyText();
00137
00142 void pgpSignedMsg( const QCString & cText, Kleo::CryptoMessageFormat f );
00147 Kpgp::Result pgpEncryptedMsg( QByteArray& rEncryptedBody,
00148 const QCString & cText,
00149 const std::vector<GpgME::Key> & encryptionKeys,
00150 Kleo::CryptoMessageFormat f );
00151
00156 Kpgp::Result pgpSignedAndEncryptedMsg( QByteArray& rEncryptedBody,
00157 const QCString & cText,
00158 const std::vector<GpgME::Key> & signingKeys,
00159 const std::vector<GpgME::Key> & encryptionKeys,
00160 Kleo::CryptoMessageFormat f );
00161
00165 bool checkForEncryptCertificateExpiry( const QString& recipient,
00166 const QCString& certFingerprint );
00167
00179 bool processStructuringInfo( const QString bugURL,
00180 const QString contentDescriptionClear,
00181 const QCString contentTypeClear,
00182 const QCString contentSubtypeClear,
00183 const QCString contentDispClear,
00184 const QCString contentTEncClear,
00185 const QCString& bodytext,
00186 const QString contentDescriptionCiph,
00187 const QByteArray& ciphertext,
00188 KMMessagePart& resultingPart,
00189 bool signing, Kleo::CryptoMessageFormat format );
00190
00191 void encryptMessage( KMMessage* msg, const Kleo::KeyResolver::SplitInfo & si,
00192 bool doSign, bool doEncrypt,
00193 KMMessagePart newBodyPart,
00194 Kleo::CryptoMessageFormat format );
00195
00196 void addBodyAndAttachments( KMMessage* msg, const Kleo::KeyResolver::SplitInfo & si,
00197 bool doSign, bool doEncrypt,
00198 const KMMessagePart& ourFineBodyPart,
00199 Kleo::CryptoMessageFormat format );
00200
00201 private slots:
00202 void slotDoNextJob();
00203
00204 private:
00205 void doNextJob();
00206
00207 int encryptionPossible( const QStringList & recipients, bool openPGP );
00208 bool determineWhetherToSign( bool doSignCompletely );
00209 bool determineWhetherToEncrypt( bool doEncryptCompletely );
00210 void markAllAttachmentsForSigning( bool sign );
00211 void markAllAttachmentsForEncryption( bool enc );
00212
00213 KMComposeWin* mComposeWin;
00214 MessageComposerJob * mCurrentJob;
00215 KMMessage* mReferenceMessage;
00216 QValueVector<KMMessage*> mMessageList;
00217
00218 Kleo::KeyResolver * mKeyResolver;
00219
00220 QCString mSignCertFingerprint;
00221
00222 struct Attachment {
00223 Attachment( KMMessagePart * p=0, bool s=false, bool e=false )
00224 : part( p ), sign( s ), encrypt( e ) {}
00225 KMMessagePart * part;
00226 bool sign;
00227 bool encrypt;
00228 };
00229 QValueVector<Attachment> mAttachments;
00230
00231 QString mPGPSigningKey, mSMIMESigningKey;
00232 bool mUseOpportunisticEncryption;
00233 bool mSignBody, mEncryptBody;
00234 bool mSigningRequested, mEncryptionRequested;
00235 bool mDoSign, mDoEncrypt;
00236 unsigned int mAllowedCryptoMessageFormats;
00237 bool mDisableCrypto;
00238 bool mDisableBreaking;
00239 QString mBcc;
00240 QStringList mTo, mCc, mBccList;
00241 bool mDebugComposerCrypto;
00242 bool mAutoCharset;
00243 QCString mCharset;
00244 bool mRc;
00245 bool mHoldJobs;
00246
00247
00248 KMMessagePart* mNewBodyPart;
00249 QByteArray mSignature;
00250
00251 QCString mEncodedBody;
00252 bool mEarlyAddAttachments, mAllAttachmentsAreInBody;
00253 KMMessagePart mOldBodyPart;
00254 int mPreviousBoundaryLevel;
00255
00256
00257 DwString mSaveBoundary;
00258
00259 QValueList<MessageComposerJob*> mJobs;
00260 #ifdef KLEO_CHIASMUS
00261 bool mEncryptWithChiasmus;
00262 bool mEncryptBodyWithChiasmus;
00263 QString mChiasmusKey;
00264 QString mChiasmusOptions;
00265 #endif
00266 };
00267
00268 #endif