kmail

kmmessage.h
1 // -*- mode: C++; c-file-style: "gnu" -*-
2 /* kmmessage.h: Mime Message Class
3  *
4  */
5 #ifndef kmmessage_h
6 #define kmmessage_h
7 
10 // for large file support
11 #include <config.h>
12 #include <sys/types.h>
13 
14 #include <mimelib/string.h>
15 #include "kmmsgbase.h"
16 #include "isubject.h"
17 
18 #include <kmime_mdn.h>
19 
20 #include<libemailfunctions/email.h>
21 
22 template <typename T>
23 class TQValueList;
24 
25 class TQStringList;
26 class TQString;
27 class TQTextCodec;
28 class TQStrList;
29 
30 class KMFolder;
31 class KMFolderIndex;
32 class DwMessage;
33 class KMMessagePart;
34 class KMMsgInfo;
35 class KMHeaders;
36 class KMForwardDigestCommand;
37 
38 namespace KMime {
39  class CharFreq;
40  namespace Types {
41  class AddrSpec;
42  class Address;
43  typedef TQValueList<Address> AddressList;
44  typedef TQValueList<AddrSpec> AddrSpecList;
45  }
46 }
47 
48 namespace KMail {
49  class HeaderStrategy;
50 }
51 
52 class DwEntity;
53 class DwBodyPart;
54 class DwMediaType;
55 class DwHeaders;
56 
57 class partNode;
58 
59 namespace KMail {
60  enum ReplyStrategy { ReplySmart = 0,
61  ReplyAuthor,
62  ReplyList,
63  ReplyAll,
64  ReplyNone };
65 }
66 
68 class KMMessage: public KMMsgBase, public KMail::ISubject
69 {
70  friend class ::KMForwardDigestCommand; // needed for MIME Digest forward
71 
72 public:
73  // promote some of KMMsgBase's methods to public:
74  using KMMsgBase::parent;
75  using KMMsgBase::setParent;
76  using KMMsgBase::enableUndo; // KMFolder
77  using KMMsgBase::setEnableUndo; // dto.
78  using KMMsgBase::isRead; // dto.
79  using KMMsgBase::isUnread; // dto.
80  using KMMsgBase::isNew; // dto.
81  using KMMsgBase::isOld;
82  using KMMsgBase::isWatched;
83  using KMMsgBase::isIgnored;
84  using KMMsgBase::setEncryptionStateChar; // KMAcct*
85  using KMMsgBase::setSignatureStateChar; // dto.
86 
88  KMMessage(KMFolder* parent=0);
89 
93  KMMessage(DwMessage*);
94 
96  KMMessage(KMMsgInfo& msgInfo);
97 
99  KMMessage( const KMMessage& other );
100 
101 #if 0 // currently unused
102 
103  const KMMessage& operator=( const KMMessage& other ) {
104  if( &other == this )
105  return *this;
106  assign( other );
107  return *this;
108  }
109 #endif
110 
112  virtual ~KMMessage();
113 
115  KMMsgBase & toMsgBase() { return *this; }
116  const KMMsgBase & toMsgBase() const { return *this; }
117 
119  bool isMessage() const;
120 
124  bool isUrgent() const;
125 
132  void setUnencryptedMsg( KMMessage* unencrypted );
133 
135  bool hasUnencryptedMsg() const { return 0 != mUnencryptedMsg; }
136 
138  KMMessage* unencryptedMsg() const { return mUnencryptedMsg; }
139 
146  {
147  KMMessage* ret = mUnencryptedMsg;
148  mUnencryptedMsg = 0;
149  return ret;
150  }
151 
153  void del() { setStatus(KMMsgStatusDeleted); }
154 
156  void undel() { setStatus(KMMsgStatusOld); }
157 
159  void touch() { setStatus(KMMsgStatusOld); }
160 
164  KMMessage* createReply( KMail::ReplyStrategy replyStrategy = KMail::ReplySmart,
165  TQString selection=TQString(), bool noQuote = false,
166  bool allowDecryption = true,
167  const TQString &tmpl = TQString() );
168 
176  KMMessage* createRedirect( const TQString &toStr );
177 
179  TQCString createForwardBody();
180 
184  KMMessage* createForward( const TQString &tmpl = TQString() );
185 
190 
204  KMMessage* createMDN( KMime::MDN::ActionMode a,
205  KMime::MDN::DispositionType d,
206  bool allowGUI=false,
207  TQValueList<KMime::MDN::DispositionModifier> m=TQValueList<KMime::MDN::DispositionModifier>() );
208 
210  void sanitizeHeaders( const TQStringList& whiteList = TQStringList() );
211 
213  void fromDwString(const DwString& str, bool setStatus=false);
214  void fromString(const TQCString& str, bool setStatus=false);
215  void fromByteArray(const TQByteArray & ba, bool setStatus=false);
216 
221  const DwString& asDwString() const;
222  const DwMessage *asDwMessage();
223 
231  TQCString asString() const;
232 
237  TQByteArray asSendableString() const;
238 
243  TQCString headerAsSendableString() const;
244 
249 
251  DwMediaType& dwContentType();
252 
254  TQString headerAsString() const;
255 
260  void parseTextStringFromDwPart( partNode * root,
261  TQCString& parsedString,
262  const TQTextCodec*& codec,
263  bool& isHTML ) const;
264 
268  void initHeader(uint identity=0);
269 
272  void initFromMessage(const KMMessage *msg, bool idHeaders = true);
273 
279  uint identityUoid() const;
280 
283  void applyIdentity( uint id );
284 
287  void cleanupHeader();
288 
294  void setAutomaticFields(bool isMultipart=false);
295 
297  TQString dateStr() const;
300  TQCString dateShortStr() const;
301  TQString dateIsoStr() const;
302  time_t date() const;
303  void setDate(const TQCString& str);
304  void setDate(time_t aUnixTime);
305 
307  void setDateToday();
308 
310  TQString to() const;
311  void setTo(const TQString& aStr);
312  TQString toStrip() const;
313 
315  TQString replyTo() const;
316  void setReplyTo( const TQString &aStr );
317  void setReplyTo(KMMessage*);
318 
320  TQString cc() const;
321  void setCc( const TQString &aStr );
322  TQString ccStrip() const;
323 
325  TQString bcc() const;
326  void setBcc( const TQString &aStr );
327 
329  TQString fcc() const;
330  void setFcc( const TQString &aStr );
331 
333  TQString drafts() const { return mDrafts; }
334  void setDrafts( const TQString &aStr );
335 
337  TQString templates() const { return mTemplates; }
338  void setTemplates( const TQString &aStr );
339 
341  TQString from() const;
342  void setFrom(const TQString& aStr);
343  TQString fromStrip() const;
344 
347  TQString sender() const;
348 
352  TQString who() const;
353 
355  TQString subject() const;
356  void setSubject(const TQString& aStr);
357 
360 
362  TQString xmark() const;
363  void setXMark(const TQString& aStr);
364 
366  TQString replyToId() const;
367  void setReplyToId(const TQString& aStr);
368  TQString replyToIdMD5() const;
369 
384  TQString replyToAuxIdMD5() const;
385 
390  TQString strippedSubjectMD5() const;
391 
402  static KPIM::EmailParseResult isValidEmailAddressList( const TQString& aStr,
403  TQString& brokenAddress );
404 
409  TQString subjectMD5() const;
410 
412  bool subjectIsPrefixed() const;
413 
415  TQString msgId() const;
416  void setMsgId(const TQString& aStr);
417  TQString msgIdMD5() const;
418 
420  TQString references() const;
421  void setReferences(const TQCString& aStr);
422 
424  TQCString id() const;
425 
430  void setMsgSerNum(unsigned long newMsgSerNum = 0);
431 
436  TQString headerField(const TQCString& name) const;
437 
438  enum HeaderFieldType { Unstructured, Structured, Address };
439 
444  void setHeaderField( const TQCString& name, const TQString& value,
445  HeaderFieldType type = Unstructured,
446  bool prepend = false );
447 
449  TQStringList headerFields( const TQCString& name ) const;
450 
455  TQCString rawHeaderField( const TQCString & name ) const;
456 
460  TQValueList<TQCString> rawHeaderFields( const TQCString & field ) const;
461 
463  static KMime::Types::AddressList splitAddrField( const TQCString & str );
464 
468  KMime::Types::AddressList headerAddrField(const TQCString& name) const;
469  KMime::Types::AddrSpecList extractAddrSpecs( const TQCString & headerNames ) const;
470 
472  void removeHeaderField(const TQCString& name);
473 
475  void removeHeaderFields(const TQCString& name);
476 
480  TQCString typeStr() const;
481  int type() const;
482  void setTypeStr(const TQCString& aStr);
483  void setType(int aType);
485  TQCString subtypeStr() const;
486  int subtype() const;
487  void setSubtypeStr(const TQCString& aStr);
488  void setSubtype(int aSubtype);
490  static void setDwMediaTypeParam( DwMediaType &mType,
491  const TQCString& attr,
492  const TQCString& val );
494  void setContentTypeParam(const TQCString& attr, const TQCString& val);
495 
499  DwHeaders& headers() const;
500 
505  void setNeedsAssembly();
506 
511  void assembleIfNeeded();
512 
521  TQCString contentTransferEncodingStr() const;
522  int contentTransferEncoding( DwEntity *entity = 0 ) const;
523  void setContentTransferEncodingStr( const TQCString& cteString, DwEntity *entity = 0 );
524  void setContentTransferEncoding( int cte, DwEntity *entity = 0 );
525 
530  TQCString cteStr() const { return contentTransferEncodingStr(); }
531  int cte( DwEntity *entity = 0 ) const { return contentTransferEncoding( entity ); }
532  void setCteStr( const TQCString& aStr, DwEntity *entity = 0 ) {
533  setContentTransferEncodingStr( aStr, entity );
534  }
535  void setCte( int aCte, DwEntity *entity = 0 ) {
536  setContentTransferEncoding( aCte, entity );
537  }
538 
546  void setBodyFromUnicode( const TQString & str, DwEntity *entity = 0 );
547 
550  TQString bodyToUnicode(const TQTextCodec* codec=0) const;
551 
553  TQCString body() const;
554 
556  void setBody(const TQCString& aStr);
557  void setBody(const DwString& aStr);
558  void setBody(const char* aStr); // avoid ambiguous calls
559 
561  void setMultiPartBody( const TQCString & aStr );
562 
572  void setBodyEncoded( const TQCString& aStr, DwEntity *entity = 0 );
573  void setBodyEncodedBinary( const TQByteArray& aStr, DwEntity *entity = 0 );
574 
578  static TQValueList<int> determineAllowedCtes( const KMime::CharFreq& cf,
579  bool allow8Bit,
580  bool willBeSigned );
581 
595  void setBodyAndGuessCte( const TQByteArray& aBuf, TQValueList<int>& allowedCte,
596  bool allow8Bit = false,
597  bool willBeSigned = false,
598  DwEntity *entity = 0 );
599 
600  void setBodyAndGuessCte( const TQCString& aBuf,
601  TQValueList<int>& allowedCte,
602  bool allow8Bit = false,
603  bool willBeSigned = false,
604  DwEntity *entity = 0 );
605 
609  TQCString bodyDecoded() const;
610  TQByteArray bodyDecodedBinary() const;
611 
614  int numBodyParts() const;
615 
618  DwBodyPart * findDwBodyPart( int type, int subtype ) const;
619 
622  DwBodyPart * findDwBodyPart( const TQCString& type, const TQCString& subtype ) const;
623 
626  DwBodyPart* findDwBodyPart( DwBodyPart* part, const TQString & partSpecifier );
627 
630  DwBodyPart * dwBodyPart( int aIdx ) const;
631 
634  int partNumber( DwBodyPart * aDwBodyPart ) const;
635 
638  DwBodyPart * getFirstDwBodyPart() const;
639  DwMessage * getTopLevelPart() const { return mMsg; }
640 
644  static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
645  bool withBody = true );
646 
650  void bodyPart(int aIdx, KMMessagePart* aPart) const;
651 
653  DwBodyPart* createDWBodyPart(const KMMessagePart* aPart);
654 
656  void addDwBodyPart(DwBodyPart * aDwPart);
657 
659  void addBodyPart(const KMMessagePart* aPart);
660 
662  void deleteBodyParts();
663 
668  bool deleteBodyPart( int partIndex );
669 
672  void setStatusFields();
673 
678  static TQString generateMessageId( const TQString& addr );
679 
685  static TQCString html2source( const TQCString & src );
686 
689  static TQString encodeMailtoUrl( const TQString& str );
690 
693  static TQString decodeMailtoUrl( const TQString& url );
694 
701  static TQCString stripEmailAddr(const TQCString& emailAddr);
702 
705  static TQString stripEmailAddr(const TQString& emailAddr);
706 
712  static TQString quoteHtmlChars( const TQString& str,
713  bool removeLineBreaks = false );
714 
719  static TQString emailAddrAsAnchor(const TQString& emailAddr,
720  bool stripped=true, const TQString& cssStyle = TQString(), bool link = true);
721 
725  static TQStringList stripAddressFromAddressList( const TQString& address,
726  const TQStringList& addresses );
727 
731  static TQStringList stripMyAddressesFromAddressList( const TQStringList& list );
732 
735  static bool addressIsInAddressList( const TQString& address,
736  const TQStringList& addresses );
737 
741  static TQString expandAliases( const TQString& recipients );
742 
746  static TQString guessEmailAddressFromLoginName( const TQString& userName );
747 
754  static TQString smartQuote( const TQString &msg, int maxLineLength );
755 
757  static TQCString defaultCharset();
758 
760  static const TQStringList &preferredCharsets();
761 
763  TQString replaceHeadersInString( const TQString & s ) const;
764 
766  TQCString charset() const;
767 
776  void setCharset( const TQCString& charset, DwEntity *entity = 0 );
777 
779  const TQTextCodec * codec() const;
780 
782  void setOverrideCodec( const TQTextCodec* codec ) { mOverrideCodec = codec; }
783 
785  void setDecodeHTML(bool aDecodeHTML)
786  { mDecodeHTML = aDecodeHTML; }
787 
790  static void readConfig();
791 
795  TQCString getRefStr() const;
796 
798  off_t folderOffset() const { return mFolderOffset; }
799  void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(true); } }
800 
802  TQString fileName() const { return mFileName; }
803  void setFileName(const TQString& file) { if(mFileName != file) { mFileName=file; setDirty(true); } }
804 
808  size_t msgSize() const { return mMsgSize; }
809  void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(true); } }
810 
813  size_t msgLength() const
814  { return (mMsgLength) ? mMsgLength : mMsgSize; }
815  void setMsgLength(size_t sz) { mMsgLength = sz; }
816 
818  size_t msgSizeServer() const;
819  void setMsgSizeServer(size_t sz);
820 
822  ulong UID() const;
823  void setUID(ulong uid);
824 
826  KMMsgStatus status() const { return mStatus; }
828  void setStatus(const KMMsgStatus status, int idx = -1);
829  void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
830 
832  void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
833 
835  void setSignatureState(const KMMsgSignatureState, int idx = -1);
836 
837  void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
838 
840  KMMsgEncryptionState encryptionState() const { return mEncryptionState; }
841 
843  KMMsgSignatureState signatureState() const { return mSignatureState; }
844 
845  KMMsgMDNSentState mdnSentState() const { return mMDNSentState; }
846 
848  void link(const KMMessage *aMsg, KMMsgStatus aStatus);
851  void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *reStatus) const;
852 
854  TQString formatString(const TQString&) const;
855 
857  void updateBodyPart(const TQString partSpecifier, const TQByteArray & data);
858 
860  DwBodyPart* lastUpdatedPart() { return mLastUpdated; }
861 
863  bool isComplete() const { return mComplete; }
865  void setComplete( bool v ) { mComplete = v; }
866 
868  bool readyToShow() const { return mReadyToShow; }
870  void setReadyToShow( bool v ) { mReadyToShow = v; }
871 
872  void updateAttachmentState( DwBodyPart *part = 0 );
873  void updateInvitationState();
874 
876  bool transferInProgress() const;
878  void setTransferInProgress(bool value, bool force = false);
879 
884  TQCString mboxMessageSeparator();
885 
901  TQString asQuotedString( const TQString & headerStr,
902  const TQString & indentStr,
903  const TQString & selection=TQString(),
904  bool aStripSignature=true,
905  bool allowDecryption=true) const;
906 
909  TQString asPlainText( bool stripSignature, bool allowDecryption ) const;
910 
917  TQString asPlainTextFromObjectTree( partNode *root, bool stripSignature,
918  bool allowDecryption ) const;
919 
921  int getCursorPos() { return mCursorPos; };
923  void setCursorPos(int pos) { mCursorPos = pos; };
924 
926  KMMsgInfo* msgInfo() { return mMsgInfo; }
928  void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; }
929 
930  /* This is set in kmreaderwin if a message is being parsed to avoid
931  other parts of kmail (e.g. kmheaders) destroying the message.
932  Parsing can take longer and can be async (in case of gpg mails) */
933  bool isBeingParsed() const { return mIsParsed; }
934  void setIsBeingParsed( bool t ) { mIsParsed = t; }
935 
937  void deleteWhenUnused();
938 
939  DwBodyPart* findPart( int index );
940 
941 private:
942 
944  void init( DwMessage* aMsg = 0 );
946  void assign( const KMMessage& other );
947 
948  DwBodyPart* findPartInternal( DwEntity* root, int index, int &accu );
949 
950  TQString mDrafts;
951  TQString mTemplates;
952  mutable DwMessage* mMsg;
953  mutable bool mNeedsAssembly :1;
954  bool mDecodeHTML :1;
955  bool mReadyToShow :1;
956  bool mComplete :1;
957  bool mIsParsed : 1;
958  static const KMail::HeaderStrategy * sHeaderStrategy;
959  static TQString sForwardStr;
960  const TQTextCodec * mOverrideCodec;
961 
962  TQString mFileName;
963  off_t mFolderOffset;
964  size_t mMsgSize, mMsgLength;
965  time_t mDate;
966  KMMsgEncryptionState mEncryptionState;
967  KMMsgSignatureState mSignatureState;
968  KMMsgMDNSentState mMDNSentState;
969  KMMessage* mUnencryptedMsg;
970  DwBodyPart* mLastUpdated;
971  int mCursorPos;
972  KMMsgInfo* mMsgInfo; // used to remember the KMMsgInfo object this KMMessage replaced in the KMMsgList
973  static TQValueList<KMMessage*> sPendingDeletes;
974 };
975 
976 
977 #endif /*kmmessage_h*/