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  const TQString &originatingAccount = TQString() );
169 
177  KMMessage* createRedirect( const TQString &toStr );
178 
180  TQCString createForwardBody();
181 
185  KMMessage* createForward( const TQString &tmpl = TQString() );
186 
190  KMMessage* createDeliveryReceipt() const;
191 
205  KMMessage* createMDN( KMime::MDN::ActionMode a,
206  KMime::MDN::DispositionType d,
207  bool allowGUI=false,
208  TQValueList<KMime::MDN::DispositionModifier> m=TQValueList<KMime::MDN::DispositionModifier>() );
209 
211  void sanitizeHeaders( const TQStringList& whiteList = TQStringList() );
212 
214  void fromDwString(const DwString& str, bool setStatus=false);
215  void fromString(const TQCString& str, bool setStatus=false);
216  void fromByteArray(const TQByteArray & ba, bool setStatus=false);
217 
222  const DwString& asDwString() const;
223  const DwMessage *asDwMessage();
224 
232  TQCString asString() const;
233 
238  TQByteArray asSendableString() const;
239 
244  TQCString headerAsSendableString() const;
245 
249  void removePrivateHeaderFields();
250 
252  DwMediaType& dwContentType();
253 
255  TQString headerAsString() const;
256 
261  void parseTextStringFromDwPart( partNode * root,
262  TQCString& parsedString,
263  const TQTextCodec*& codec,
264  bool& isHTML ) const;
265 
269  void initHeader(uint identity=0);
270 
273  void initFromMessage(const KMMessage *msg, bool idHeaders = true);
274 
280  uint identityUoid() const;
281 
284  void applyIdentity( uint id );
285 
288  void cleanupHeader();
289 
295  void setAutomaticFields(bool isMultipart=false);
296 
298  TQString dateStr() const;
301  TQCString dateShortStr() const;
302  TQString dateIsoStr() const;
303  time_t date() const;
304  void setDate(const TQCString& str);
305  void setDate(time_t aUnixTime);
306 
308  void setDateToday();
309 
311  TQString to() const;
312  void setTo(const TQString& aStr);
313  TQString toStrip() const;
314 
316  TQString replyTo() const;
317  void setReplyTo( const TQString &aStr );
318  void setReplyTo(KMMessage*);
319 
321  TQString cc() const;
322  void setCc( const TQString &aStr );
323  TQString ccStrip() const;
324 
326  TQString bcc() const;
327  void setBcc( const TQString &aStr );
328 
330  TQString fcc() const;
331  void setFcc( const TQString &aStr );
332 
334  TQString drafts() const { return mDrafts; }
335  void setDrafts( const TQString &aStr );
336 
338  TQString templates() const { return mTemplates; }
339  void setTemplates( const TQString &aStr );
340 
342  TQString from() const;
343  void setFrom(const TQString& aStr);
344  TQString fromStrip() const;
345 
348  TQString sender() const;
349 
353  TQString who() const;
354 
356  TQString subject() const;
357  void setSubject(const TQString& aStr);
358 
361 
363  TQString xmark() const;
364  void setXMark(const TQString& aStr);
365 
367  TQString replyToId() const;
368  void setReplyToId(const TQString& aStr);
369  TQString replyToIdMD5() const;
370 
385  TQString replyToAuxIdMD5() const;
386 
391  TQString strippedSubjectMD5() const;
392 
403  static KPIM::EmailParseResult isValidEmailAddressList( const TQString& aStr,
404  TQString& brokenAddress );
405 
410  TQString subjectMD5() const;
411 
413  bool subjectIsPrefixed() const;
414 
416  TQString msgId() const;
417  void setMsgId(const TQString& aStr);
418  TQString msgIdMD5() const;
419 
421  TQString references() const;
422  void setReferences(const TQCString& aStr);
423 
425  TQCString id() const;
426 
431  void setMsgSerNum(unsigned long newMsgSerNum = 0);
432 
437  TQString headerField(const TQCString& name) const;
438 
439  enum HeaderFieldType { Unstructured, Structured, Address };
440 
445  void setHeaderField( const TQCString& name, const TQString& value,
446  HeaderFieldType type = Unstructured,
447  bool prepend = false );
448 
450  TQStringList headerFields( const TQCString& name ) const;
451 
456  TQCString rawHeaderField( const TQCString & name ) const;
457 
461  TQValueList<TQCString> rawHeaderFields( const TQCString & field ) const;
462 
464  static KMime::Types::AddressList splitAddrField( const TQCString & str );
465 
469  KMime::Types::AddressList headerAddrField(const TQCString& name) const;
470  KMime::Types::AddrSpecList extractAddrSpecs( const TQCString & headerNames ) const;
471 
473  void removeHeaderField(const TQCString& name);
474 
476  void removeHeaderFields(const TQCString& name);
477 
481  TQCString typeStr() const;
482  int type() const;
483  void setTypeStr(const TQCString& aStr);
484  void setType(int aType);
486  TQCString subtypeStr() const;
487  int subtype() const;
488  void setSubtypeStr(const TQCString& aStr);
489  void setSubtype(int aSubtype);
491  static void setDwMediaTypeParam( DwMediaType &mType,
492  const TQCString& attr,
493  const TQCString& val );
495  void setContentTypeParam(const TQCString& attr, const TQCString& val);
496 
500  DwHeaders& headers() const;
501 
506  void setNeedsAssembly();
507 
512  void assembleIfNeeded();
513 
522  TQCString contentTransferEncodingStr() const;
523  int contentTransferEncoding( DwEntity *entity = 0 ) const;
524  void setContentTransferEncodingStr( const TQCString& cteString, DwEntity *entity = 0 );
525  void setContentTransferEncoding( int cte, DwEntity *entity = 0 );
526 
531  TQCString cteStr() const { return contentTransferEncodingStr(); }
532  int cte( DwEntity *entity = 0 ) const { return contentTransferEncoding( entity ); }
533  void setCteStr( const TQCString& aStr, DwEntity *entity = 0 ) {
534  setContentTransferEncodingStr( aStr, entity );
535  }
536  void setCte( int aCte, DwEntity *entity = 0 ) {
537  setContentTransferEncoding( aCte, entity );
538  }
539 
547  void setBodyFromUnicode( const TQString & str, DwEntity *entity = 0 );
548 
551  TQString bodyToUnicode(const TQTextCodec* codec=0) const;
552 
554  TQCString body() const;
555 
557  void setBody(const TQCString& aStr);
558  void setBody(const DwString& aStr);
559  void setBody(const char* aStr); // avoid ambiguous calls
560 
562  void setMultiPartBody( const TQCString & aStr );
563 
573  void setBodyEncoded( const TQCString& aStr, DwEntity *entity = 0 );
574  void setBodyEncodedBinary( const TQByteArray& aStr, DwEntity *entity = 0 );
575 
579  static TQValueList<int> determineAllowedCtes( const KMime::CharFreq& cf,
580  bool allow8Bit,
581  bool willBeSigned );
582 
596  void setBodyAndGuessCte( const TQByteArray& aBuf, TQValueList<int>& allowedCte,
597  bool allow8Bit = false,
598  bool willBeSigned = false,
599  DwEntity *entity = 0 );
600 
601  void setBodyAndGuessCte( const TQCString& aBuf,
602  TQValueList<int>& allowedCte,
603  bool allow8Bit = false,
604  bool willBeSigned = false,
605  DwEntity *entity = 0 );
606 
610  TQCString bodyDecoded() const;
611  TQByteArray bodyDecodedBinary() const;
612 
615  int numBodyParts() const;
616 
619  DwBodyPart * findDwBodyPart( int type, int subtype ) const;
620 
623  DwBodyPart * findDwBodyPart( const TQCString& type, const TQCString& subtype ) const;
624 
627  DwBodyPart* findDwBodyPart( DwBodyPart* part, const TQString & partSpecifier );
628 
631  DwBodyPart * dwBodyPart( int aIdx ) const;
632 
635  int partNumber( DwBodyPart * aDwBodyPart ) const;
636 
639  DwBodyPart * getFirstDwBodyPart() const;
640  DwMessage * getTopLevelPart() const { return mMsg; }
641 
645  static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
646  bool withBody = true );
647 
651  void bodyPart(int aIdx, KMMessagePart* aPart) const;
652 
654  DwBodyPart* createDWBodyPart(const KMMessagePart* aPart);
655 
657  void addDwBodyPart(DwBodyPart * aDwPart);
658 
660  void addBodyPart(const KMMessagePart* aPart);
661 
663  void deleteBodyParts();
664 
669  bool deleteBodyPart( int partIndex );
670 
673  void setStatusFields();
674 
679  static TQString generateMessageId( const TQString& addr );
680 
686  static TQCString html2source( const TQCString & src );
687 
690  static TQString encodeMailtoUrl( const TQString& str );
691 
694  static TQString decodeMailtoUrl( const TQString& url );
695 
702  static TQCString stripEmailAddr(const TQCString& emailAddr);
703 
706  static TQString stripEmailAddr(const TQString& emailAddr);
707 
713  static TQString quoteHtmlChars( const TQString& str,
714  bool removeLineBreaks = false );
715 
720  static TQString emailAddrAsAnchor(const TQString& emailAddr,
721  bool stripped=true, const TQString& cssStyle = TQString(), bool link = true);
722 
726  static TQStringList stripAddressFromAddressList( const TQString& address,
727  const TQStringList& addresses );
728 
732  static TQStringList stripMyAddressesFromAddressList( const TQStringList& list );
733 
736  static bool addressIsInAddressList( const TQString& address,
737  const TQStringList& addresses );
738 
742  static TQString expandAliases( const TQString& recipients );
743 
747  static TQString guessEmailAddressFromLoginName( const TQString& userName );
748 
755  static TQString smartQuote( const TQString &msg, int maxLineLength );
756 
758  static TQCString defaultCharset();
759 
761  static const TQStringList &preferredCharsets();
762 
764  TQString replaceHeadersInString( const TQString & s ) const;
765 
767  TQCString charset() const;
768 
777  void setCharset( const TQCString& charset, DwEntity *entity = 0 );
778 
780  const TQTextCodec * codec() const;
781 
783  void setOverrideCodec( const TQTextCodec* codec ) { mOverrideCodec = codec; }
784 
786  void setDecodeHTML(bool aDecodeHTML)
787  { mDecodeHTML = aDecodeHTML; }
788 
791  static void readConfig();
792 
796  TQCString getRefStr() const;
797 
799  off_t folderOffset() const { return mFolderOffset; }
800  void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(true); } }
801 
803  TQString fileName() const { return mFileName; }
804  void setFileName(const TQString& file) { if(mFileName != file) { mFileName=file; setDirty(true); } }
805 
807  TQString originatingAccountName() const { return mOriginatingAccountName; }
808  void setOriginatingAccountName(const TQString& account) { if(mOriginatingAccountName != account) { mOriginatingAccountName=account; setDirty(true); } }
809 
813  size_t msgSize() const { return mMsgSize; }
814  void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(true); } }
815 
818  size_t msgLength() const
819  { return (mMsgLength) ? mMsgLength : mMsgSize; }
820  void setMsgLength(size_t sz) { mMsgLength = sz; }
821 
823  size_t msgSizeServer() const;
824  void setMsgSizeServer(size_t sz);
825 
827  ulong UID() const;
828  void setUID(ulong uid);
829 
831  KMMsgStatus status() const { return mStatus; }
833  void setStatus(const KMMsgStatus status, int idx = -1);
834  void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
835 
837  void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
838 
840  void setSignatureState(const KMMsgSignatureState, int idx = -1);
841 
842  void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
843 
845  KMMsgEncryptionState encryptionState() const { return mEncryptionState; }
846 
848  KMMsgSignatureState signatureState() const { return mSignatureState; }
849 
850  KMMsgMDNSentState mdnSentState() const { return mMDNSentState; }
851 
853  void link(const KMMessage *aMsg, KMMsgStatus aStatus);
856  void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *reStatus) const;
857 
859  TQString formatString(const TQString&) const;
860 
862  void updateBodyPart(const TQString partSpecifier, const TQByteArray & data);
863 
865  DwBodyPart* lastUpdatedPart() { return mLastUpdated; }
866 
868  bool isComplete() const { return mComplete; }
870  void setComplete( bool v ) { mComplete = v; }
871 
873  bool readyToShow() const { return mReadyToShow; }
875  void setReadyToShow( bool v ) { mReadyToShow = v; }
876 
877  void updateAttachmentState( DwBodyPart *part = 0 );
878  void updateInvitationState();
879 
881  bool transferInProgress() const;
883  void setTransferInProgress(bool value, bool force = false);
884 
889  TQCString mboxMessageSeparator();
890 
906  TQString asQuotedString( const TQString & headerStr,
907  const TQString & indentStr,
908  const TQString & selection=TQString(),
909  bool aStripSignature=true,
910  bool allowDecryption=true) const;
911 
914  TQString asPlainText( bool stripSignature, bool allowDecryption ) const;
915 
922  TQString asPlainTextFromObjectTree( partNode *root, bool stripSignature,
923  bool allowDecryption ) const;
924 
926  int getCursorPos() { return mCursorPos; };
928  void setCursorPos(int pos) { mCursorPos = pos; };
929 
931  KMMsgInfo* msgInfo() { return mMsgInfo; }
933  void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; }
934 
935  /* This is set in kmreaderwin if a message is being parsed to avoid
936  other parts of kmail (e.g. kmheaders) destroying the message.
937  Parsing can take longer and can be async (in case of gpg mails) */
938  bool isBeingParsed() const { return mIsParsed; }
939  void setIsBeingParsed( bool t ) { mIsParsed = t; }
940 
942  void deleteWhenUnused();
943 
944  DwBodyPart* findPart( int index );
945 
946 private:
947 
949  void init( DwMessage* aMsg = 0 );
951  void assign( const KMMessage& other );
952 
953  DwBodyPart* findPartInternal( DwEntity* root, int index, int &accu );
954 
955  TQString mDrafts;
956  TQString mTemplates;
957  mutable DwMessage* mMsg;
958  mutable bool mNeedsAssembly :1;
959  bool mDecodeHTML :1;
960  bool mReadyToShow :1;
961  bool mComplete :1;
962  bool mIsParsed : 1;
963  static const KMail::HeaderStrategy * sHeaderStrategy;
964  static TQString sForwardStr;
965  const TQTextCodec * mOverrideCodec;
966 
967  TQString mFileName;
968  TQString mOriginatingAccountName;
969  off_t mFolderOffset;
970  size_t mMsgSize, mMsgLength;
971  time_t mDate;
972  KMMsgEncryptionState mEncryptionState;
973  KMMsgSignatureState mSignatureState;
974  KMMsgMDNSentState mMDNSentState;
975  KMMessage* mUnencryptedMsg;
976  DwBodyPart* mLastUpdated;
977  int mCursorPos;
978  KMMsgInfo* mMsgInfo; // used to remember the KMMsgInfo object this KMMessage replaced in the KMMsgList
979  static TQValueList<KMMessage*> sPendingDeletes;
980 };
981 
982 
983 #endif /*kmmessage_h*/
bool hasUnencryptedMsg() const
Returns TRUE if the message contains an unencrypted copy of itself.
Definition: kmmessage.h:135
TQString originatingAccountName() const
Get/set originating account name.
Definition: kmmessage.h:807
A FolderStorage with an index for faster access to often used message properties. ...
Definition: kmfolderindex.h:37
TQCString cteStr() const
Cte is short for ContentTransferEncoding.
Definition: kmmessage.h:531
void del()
Mark the message as deleted.
Definition: kmmessage.h:153
size_t msgLength() const
Unlike the above function this works also, if the message is not in a folder.
Definition: kmmessage.h:818
KMMsgBase & toMsgBase()
Get KMMsgBase for this object.
Definition: kmmessage.h:115
off_t folderOffset() const
Get/set offset in mail folder.
Definition: kmmessage.h:799
void setComplete(bool v)
Set if the message is a complete message.
Definition: kmmessage.h:870
The widget that shows the contents of folders.
Definition: kmheaders.h:48
KMMsgInfo * msgInfo()
Get the KMMsgInfo object that was set with setMsgInfo().
Definition: kmmessage.h:931
void setMsgInfo(KMMsgInfo *msgInfo)
Set the KMMsgInfo object corresponding to this message.
Definition: kmmessage.h:933
void setReadyToShow(bool v)
Set if the message is ready to be shown.
Definition: kmmessage.h:875
TQString templates() const
Get or set the &#39;Templates&#39; folder.
Definition: kmmessage.h:338
void touch()
Touch the message - mark it as read.
Definition: kmmessage.h:159
Mail folder.
Definition: kmfolder.h:68
void setCursorPos(int pos)
Set cursor position as offset from message start.
Definition: kmmessage.h:928
size_t msgSize() const
Get/set size of message in the folder including the whole header in bytes.
Definition: kmmessage.h:813
void initStrippedSubjectMD5()
Calculate strippedSubject.
Definition: kmmessage.h:360
bool isComplete() const
Return true if the complete message is available without referring to the backing store...
Definition: kmmessage.h:868
KMMessage * takeUnencryptedMsg()
Returns an unencrypted copy of this message or 0 if none exists.
Definition: kmmessage.h:145
KMMessage * unencryptedMsg() const
Returns an unencrypted copy of this message or 0 if none exists.
Definition: kmmessage.h:138
TQString drafts() const
Get or set the &#39;Drafts&#39; folder.
Definition: kmmessage.h:334
void setDecodeHTML(bool aDecodeHTML)
Allow decoding of HTML for quoting.
Definition: kmmessage.h:786
DwBodyPart * lastUpdatedPart()
Returns the last DwBodyPart that was updated.
Definition: kmmessage.h:865
void undel()
Undelete the message.
Definition: kmmessage.h:156
KMMsgStatus status() const
Status of the message.
Definition: kmmessage.h:831
folderdiaquotatab.h
Definition: aboutdata.cpp:40
This is a Mime Message.
Definition: kmmessage.h:68
TQString fileName() const
Get/set filename in mail folder.
Definition: kmmessage.h:803
int getCursorPos()
Get stored cursor position.
Definition: kmmessage.h:926
KMMsgSignatureState signatureState() const
Signature status of the message.
Definition: kmmessage.h:848
void setOverrideCodec(const TQTextCodec *codec)
Set the charset the user selected for the message to display.
Definition: kmmessage.h:783
KMMsgEncryptionState encryptionState() const
Encryption status of the message.
Definition: kmmessage.h:845
bool readyToShow() const
Return if the message is ready to be shown.
Definition: kmmessage.h:873