kmail

messagecomposer.h
1 /*
2  * messagecomposer.cpp
3  *
4  * Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * In addition, as a special exception, the copyright holders give
20  * permission to link the code of this program with any edition of
21  * the TQt library by Trolltech AS, Norway (or with modified versions
22  * of TQt that use the same license as TQt), and distribute linked
23  * combinations including the two. You must obey the GNU General
24  * Public License in all respects for all of the code used other than
25  * TQt. If you modify this file, you may extend this exception to
26  * your version of the file, but you are not obligated to do so. If
27  * you do not wish to do so, delete this exception statement from
28  * your version.
29  */
30 
31 #ifndef MESSAGECOMPOSER_H
32 #define MESSAGECOMPOSER_H
33 
34 #include "kmmsgpart.h"
35 #include "keyresolver.h"
36 
37 #include <tqobject.h>
38 #include <tqvaluevector.h>
39 
40 #include <mimelib/mediatyp.h>
41 #include <kleo/cryptobackend.h>
42 #include <kpgp.h>
43 
44 #include <vector>
45 
46 class KMMessage;
47 class KMComposeWin;
48 
49 class MessageComposerJob;
50 class EncryptMessageJob;
51 class SetLastMessageAsUnencryptedVersionOfLastButOne;
52 
53 namespace Kleo {
54  class KeyResolver;
55 }
56 
57 namespace GpgME {
58  class Key;
59 }
60 
61 namespace KPIM {
62  class Identity;
63 }
64 
65 class MessageComposer : public TQObject {
66  TQ_OBJECT
67 
68  friend class ::MessageComposerJob;
69  friend class ::EncryptMessageJob;
70  friend class ::SetLastMessageAsUnencryptedVersionOfLastButOne;
71 
72 public:
73  class KeyResolver;
74 
75  MessageComposer( KMComposeWin* win, const char* name=0 );
76  ~MessageComposer();
77 
85  void applyChanges( bool disableCrypto );
86 
87  TQString originalBCC() const { return mBcc; }
88 
89  void setDisableBreaking( bool b ) { mDisableBreaking = b; }
90 
91  const TQValueVector<KMMessage*> & composedMessageList() const {
92  return mMessageList;
93  }
94 
95  bool isPerformingSignOperation() const { return mPerformingSignOperation; }
96 signals:
97  void done( bool );
98 
99 private:
100  void readFromComposeWin();
101 
102  void adjustCryptFlags();
103 
104  bool encryptWithChiasmus( const Kleo::CryptoBackend::Protocol * chiasmus,
105  const TQByteArray& body,
106  TQByteArray& resultData );
107  void chiasmusEncryptAllAttachments();
108  void composeChiasmusMessage( KMMessage& theMessage, Kleo::CryptoMessageFormat format );
109 
110  // This is the composeMessage method
111  void composeMessage();
112  // And these two are the parts that should be run after job completions
113  void createUnencryptedMessageVersion();
114 
122  void composeMessage( KMMessage& theMessage,
123  bool doSign, bool doEncrypt,
124  Kleo::CryptoMessageFormat format );
125  void continueComposeMessage( KMMessage& theMessage, bool doSign,
126  bool doEncrypt,
127  Kleo::CryptoMessageFormat format );
128 
132  void composeInlineOpenPGPMessage( KMMessage& theMessage,
133  bool doSign, bool doEncrypt );
134 
139  TQByteArray breakLinesAndApplyCodec();
140 
145  TQCString plainTextFromMarkup( const TQString& markupText );
146 
151  void pgpSignedMsg( const TQByteArray& cText, Kleo::CryptoMessageFormat f );
156  Kpgp::Result pgpEncryptedMsg( TQByteArray& rEncryptedBody,
157  const TQByteArray& cText,
158  const std::vector<GpgME::Key> & encryptionKeys,
159  Kleo::CryptoMessageFormat f );
160 
165  Kpgp::Result pgpSignedAndEncryptedMsg( TQByteArray& rEncryptedBody,
166  const TQByteArray& cText,
167  const std::vector<GpgME::Key> & signingKeys,
168  const std::vector<GpgME::Key> & encryptionKeys,
169  Kleo::CryptoMessageFormat f );
170 
174  bool checkForEncryptCertificateExpiry( const TQString& recipient,
175  const TQCString& certFingerprint );
176 
188  bool processStructuringInfo( const TQString bugURL,
189  const TQString contentDescriptionClear,
190  const TQCString contentTypeClear,
191  const TQCString contentSubtypeClear,
192  const TQCString contentDispClear,
193  const TQCString contentTEncClear,
194  const TQByteArray& bodytext,
195  const TQString contentDescriptionCiph,
196  const TQByteArray& ciphertext,
197  KMMessagePart& resultingPart,
198  bool signing, Kleo::CryptoMessageFormat format );
199 
200  void encryptMessage( KMMessage* msg, const Kleo::KeyResolver::SplitInfo & si,
201  bool doSign, bool doEncrypt,
202  KMMessagePart newBodyPart,
203  Kleo::CryptoMessageFormat format );
204 
205  void addBodyAndAttachments( KMMessage* msg, const Kleo::KeyResolver::SplitInfo & si,
206  bool doSign, bool doEncrypt,
207  const KMMessagePart& ourFineBodyPart,
208  Kleo::CryptoMessageFormat format );
209 
210 private slots:
211  void slotDoNextJob();
212 
213 private:
214  void doNextJob();
215  void emitDone( bool ok );
216 
217  int encryptionPossible( const TQStringList & recipients, bool openPGP );
218  bool determineWhetherToSign( bool doSignCompletely );
219  bool determineWhetherToEncrypt( bool doEncryptCompletely );
220  void markAllAttachmentsForSigning( bool sign );
221  void markAllAttachmentsForEncryption( bool enc );
222 
223  KMComposeWin* mComposeWin;
224  MessageComposerJob * mCurrentJob;
225  KMMessage* mReferenceMessage;
226  TQValueVector<KMMessage*> mMessageList;
227 
228  Kleo::KeyResolver * mKeyResolver;
229 
230  TQCString mSignCertFingerprint;
231 
232  struct Attachment {
233  Attachment( KMMessagePart * p=0, bool s=false, bool e=false )
234  : part( p ), sign( s ), encrypt( e ) {}
235  KMMessagePart * part;
236  bool sign;
237  bool encrypt;
238  };
239  TQValueVector<Attachment> mAttachments;
240 
241  TQString mPGPSigningKey, mSMIMESigningKey;
242  bool mUseOpportunisticEncryption;
243  bool mSignBody, mEncryptBody;
244  bool mSigningRequested, mEncryptionRequested;
245  bool mDoSign, mDoEncrypt;
246  unsigned int mAllowedCryptoMessageFormats;
247  bool mDisableCrypto;
248  bool mDisableBreaking;
249  TQString mBcc;
250  TQStringList mTo, mCc, mBccList;
251  bool mDebugComposerCrypto;
252  bool mAutoCharset;
253  TQCString mCharset;
254  bool mIsRichText;
255  uint mIdentityUid;
256  bool mRc; // Set this to false, if something fails during the processes
257  bool mHoldJobs; // Don't run the next job yet
258 
259  TQByteArray mText; // textual representation of the message text, encoded
260  unsigned int mLineBreakColumn; // used for line breaking
261 
262  // These are the variables of the big composeMessage(X,Y,Z) message
263  KMMessagePart* mNewBodyPart;
264  TQByteArray mSignature;
265 
266  TQByteArray mEncodedBody; // Only needed if signing and/or encrypting
267  bool mEarlyAddAttachments, mAllAttachmentsAreInBody;
268  KMMessagePart mOldBodyPart;
269  int mPreviousBoundaryLevel;
270 
271  // The boundary is saved for later addition into mp/a body
272  DwString mSaveBoundary;
273  TQCString mMultipartMixedBoundary;
274 
275  TQValueList<MessageComposerJob*> mJobs;
276  bool mEncryptWithChiasmus;
277  bool mPerformingSignOperation;
278 };
279 
280 #endif /* MESSAGECOMPOSER_H */
This is a Mime Message.
Definition: kmmessage.h:68
A class to resolve signing/encryption keys w.r.t.
Definition: keyresolver.h:127