kmmessage.h
00001 // -*- mode: C++; c-file-style: "gnu" -*- 00002 /* kmmessage.h: Mime Message Class 00003 * 00004 */ 00005 #ifndef kmmessage_h 00006 #define kmmessage_h 00007 00010 // for large file support 00011 #include <config.h> 00012 #include <sys/types.h> 00013 00014 #include <mimelib/string.h> 00015 #include "kmmsgbase.h" 00016 #include "isubject.h" 00017 00018 #include <kmime_mdn.h> 00019 00020 #include<libemailfunctions/email.h> 00021 00022 template <typename T> 00023 class TQValueList; 00024 00025 class TQStringList; 00026 class TQString; 00027 class TQTextCodec; 00028 class TQStrList; 00029 00030 class KMFolder; 00031 class KMFolderIndex; 00032 class DwMessage; 00033 class KMMessagePart; 00034 class KMMsgInfo; 00035 class KMHeaders; 00036 class KMForwardDigestCommand; 00037 00038 namespace KMime { 00039 class CharFreq; 00040 namespace Types { 00041 class AddrSpec; 00042 class Address; 00043 typedef TQValueList<Address> AddressList; 00044 typedef TQValueList<AddrSpec> AddrSpecList; 00045 } 00046 } 00047 00048 namespace KMail { 00049 class HeaderStrategy; 00050 } 00051 00052 class DwEntity; 00053 class DwBodyPart; 00054 class DwMediaType; 00055 class DwHeaders; 00056 00057 class partNode; 00058 00059 namespace KMail { 00060 enum ReplyStrategy { ReplySmart = 0, 00061 ReplyAuthor, 00062 ReplyList, 00063 ReplyAll, 00064 ReplyNone }; 00065 } 00066 00068 class KMMessage: public KMMsgBase, public KMail::ISubject 00069 { 00070 friend class ::KMForwardDigestCommand; // needed for MIME Digest forward 00071 00072 public: 00073 // promote some of KMMsgBase's methods to public: 00074 using KMMsgBase::parent; 00075 using KMMsgBase::setParent; 00076 using KMMsgBase::enableUndo; // KMFolder 00077 using KMMsgBase::setEnableUndo; // dto. 00078 using KMMsgBase::isRead; // dto. 00079 using KMMsgBase::isUnread; // dto. 00080 using KMMsgBase::isNew; // dto. 00081 using KMMsgBase::isOld; 00082 using KMMsgBase::isWatched; 00083 using KMMsgBase::isIgnored; 00084 using KMMsgBase::setEncryptionStateChar; // KMAcct* 00085 using KMMsgBase::setSignatureStateChar; // dto. 00086 00088 KMMessage(KMFolder* parent=0); 00089 00093 KMMessage(DwMessage*); 00094 00096 KMMessage(KMMsgInfo& msgInfo); 00097 00099 KMMessage( const KMMessage& other ); 00100 00101 #if 0 // currently unused 00102 00103 const KMMessage& operator=( const KMMessage& other ) { 00104 if( &other == this ) 00105 return *this; 00106 assign( other ); 00107 return *this; 00108 } 00109 #endif 00110 00112 virtual ~KMMessage(); 00113 00115 KMMsgBase & toMsgBase() { return *this; } 00116 const KMMsgBase & toMsgBase() const { return *this; } 00117 00119 bool isMessage() const; 00120 00124 bool isUrgent() const; 00125 00132 void setUnencryptedMsg( KMMessage* unencrypted ); 00133 00135 bool hasUnencryptedMsg() const { return 0 != mUnencryptedMsg; } 00136 00138 KMMessage* unencryptedMsg() const { return mUnencryptedMsg; } 00139 00145 KMMessage* takeUnencryptedMsg() 00146 { 00147 KMMessage* ret = mUnencryptedMsg; 00148 mUnencryptedMsg = 0; 00149 return ret; 00150 } 00151 00153 void del() { setStatus(KMMsgStatusDeleted); } 00154 00156 void undel() { setStatus(KMMsgStatusOld); } 00157 00159 void touch() { setStatus(KMMsgStatusOld); } 00160 00164 KMMessage* createReply( KMail::ReplyStrategy replyStrategy = KMail::ReplySmart, 00165 TQString selection=TQString(), bool noQuote = false, 00166 bool allowDecryption = true, 00167 const TQString &tmpl = TQString() ); 00168 00176 KMMessage* createRedirect( const TQString &toStr ); 00177 00179 TQCString createForwardBody(); 00180 00184 KMMessage* createForward( const TQString &tmpl = TQString() ); 00185 00189 KMMessage* createDeliveryReceipt() const; 00190 00204 KMMessage* createMDN( KMime::MDN::ActionMode a, 00205 KMime::MDN::DispositionType d, 00206 bool allowGUI=false, 00207 TQValueList<KMime::MDN::DispositionModifier> m=TQValueList<KMime::MDN::DispositionModifier>() ); 00208 00210 void sanitizeHeaders( const TQStringList& whiteList = TQStringList() ); 00211 00213 void fromDwString(const DwString& str, bool setStatus=false); 00214 void fromString(const TQCString& str, bool setStatus=false); 00215 void fromByteArray(const TQByteArray & ba, bool setStatus=false); 00216 00221 const DwString& asDwString() const; 00222 const DwMessage *asDwMessage(); 00223 00231 TQCString asString() const; 00232 00237 TQByteArray asSendableString() const; 00238 00243 TQCString headerAsSendableString() const; 00244 00248 void removePrivateHeaderFields(); 00249 00251 DwMediaType& dwContentType(); 00252 00254 TQString headerAsString() const; 00255 00260 void parseTextStringFromDwPart( partNode * root, 00261 TQCString& parsedString, 00262 const TQTextCodec*& codec, 00263 bool& isHTML ) const; 00264 00268 void initHeader(uint identity=0); 00269 00272 void initFromMessage(const KMMessage *msg, bool idHeaders = true); 00273 00279 uint identityUoid() const; 00280 00283 void applyIdentity( uint id ); 00284 00287 void cleanupHeader(); 00288 00294 void setAutomaticFields(bool isMultipart=false); 00295 00297 TQString dateStr() const; 00300 TQCString dateShortStr() const; 00301 TQString dateIsoStr() const; 00302 time_t date() const; 00303 void setDate(const TQCString& str); 00304 void setDate(time_t aUnixTime); 00305 00307 void setDateToday(); 00308 00310 TQString to() const; 00311 void setTo(const TQString& aStr); 00312 TQString toStrip() const; 00313 00315 TQString replyTo() const; 00316 void setReplyTo( const TQString &aStr ); 00317 void setReplyTo(KMMessage*); 00318 00320 TQString cc() const; 00321 void setCc( const TQString &aStr ); 00322 TQString ccStrip() const; 00323 00325 TQString bcc() const; 00326 void setBcc( const TQString &aStr ); 00327 00329 TQString fcc() const; 00330 void setFcc( const TQString &aStr ); 00331 00333 TQString drafts() const { return mDrafts; } 00334 void setDrafts( const TQString &aStr ); 00335 00337 TQString templates() const { return mTemplates; } 00338 void setTemplates( const TQString &aStr ); 00339 00341 TQString from() const; 00342 void setFrom(const TQString& aStr); 00343 TQString fromStrip() const; 00344 00347 TQString sender() const; 00348 00352 TQString who() const; 00353 00355 TQString subject() const; 00356 void setSubject(const TQString& aStr); 00357 00359 void initStrippedSubjectMD5() {}; 00360 00362 TQString xmark() const; 00363 void setXMark(const TQString& aStr); 00364 00366 TQString replyToId() const; 00367 void setReplyToId(const TQString& aStr); 00368 TQString replyToIdMD5() const; 00369 00384 TQString replyToAuxIdMD5() const; 00385 00390 TQString strippedSubjectMD5() const; 00391 00402 static KPIM::EmailParseResult isValidEmailAddressList( const TQString& aStr, 00403 TQString& brokenAddress ); 00404 00409 TQString subjectMD5() const; 00410 00412 bool subjectIsPrefixed() const; 00413 00415 TQString msgId() const; 00416 void setMsgId(const TQString& aStr); 00417 TQString msgIdMD5() const; 00418 00420 TQString references() const; 00421 void setReferences(const TQCString& aStr); 00422 00424 TQCString id() const; 00425 00430 void setMsgSerNum(unsigned long newMsgSerNum = 0); 00431 00436 TQString headerField(const TQCString& name) const; 00437 00438 enum HeaderFieldType { Unstructured, Structured, Address }; 00439 00444 void setHeaderField( const TQCString& name, const TQString& value, 00445 HeaderFieldType type = Unstructured, 00446 bool prepend = false ); 00447 00449 TQStringList headerFields( const TQCString& name ) const; 00450 00455 TQCString rawHeaderField( const TQCString & name ) const; 00456 00460 TQValueList<TQCString> rawHeaderFields( const TQCString & field ) const; 00461 00463 static KMime::Types::AddressList splitAddrField( const TQCString & str ); 00464 00468 KMime::Types::AddressList headerAddrField(const TQCString& name) const; 00469 KMime::Types::AddrSpecList extractAddrSpecs( const TQCString & headerNames ) const; 00470 00472 void removeHeaderField(const TQCString& name); 00473 00475 void removeHeaderFields(const TQCString& name); 00476 00480 TQCString typeStr() const; 00481 int type() const; 00482 void setTypeStr(const TQCString& aStr); 00483 void setType(int aType); 00485 TQCString subtypeStr() const; 00486 int subtype() const; 00487 void setSubtypeStr(const TQCString& aStr); 00488 void setSubtype(int aSubtype); 00490 static void setDwMediaTypeParam( DwMediaType &mType, 00491 const TQCString& attr, 00492 const TQCString& val ); 00494 void setContentTypeParam(const TQCString& attr, const TQCString& val); 00495 00499 DwHeaders& headers() const; 00500 00505 void setNeedsAssembly(); 00506 00511 void assembleIfNeeded(); 00512 00521 TQCString contentTransferEncodingStr() const; 00522 int contentTransferEncoding( DwEntity *entity = 0 ) const; 00523 void setContentTransferEncodingStr( const TQCString& cteString, DwEntity *entity = 0 ); 00524 void setContentTransferEncoding( int cte, DwEntity *entity = 0 ); 00525 00530 TQCString cteStr() const { return contentTransferEncodingStr(); } 00531 int cte( DwEntity *entity = 0 ) const { return contentTransferEncoding( entity ); } 00532 void setCteStr( const TQCString& aStr, DwEntity *entity = 0 ) { 00533 setContentTransferEncodingStr( aStr, entity ); 00534 } 00535 void setCte( int aCte, DwEntity *entity = 0 ) { 00536 setContentTransferEncoding( aCte, entity ); 00537 } 00538 00546 void setBodyFromUnicode( const TQString & str, DwEntity *entity = 0 ); 00547 00550 TQString bodyToUnicode(const TQTextCodec* codec=0) const; 00551 00553 TQCString body() const; 00554 00556 void setBody(const TQCString& aStr); 00557 void setBody(const DwString& aStr); 00558 void setBody(const char* aStr); // avoid ambiguous calls 00559 00561 void setMultiPartBody( const TQCString & aStr ); 00562 00572 void setBodyEncoded( const TQCString& aStr, DwEntity *entity = 0 ); 00573 void setBodyEncodedBinary( const TQByteArray& aStr, DwEntity *entity = 0 ); 00574 00578 static TQValueList<int> determineAllowedCtes( const KMime::CharFreq& cf, 00579 bool allow8Bit, 00580 bool willBeSigned ); 00581 00595 void setBodyAndGuessCte( const TQByteArray& aBuf, TQValueList<int>& allowedCte, 00596 bool allow8Bit = false, 00597 bool willBeSigned = false, 00598 DwEntity *entity = 0 ); 00599 00600 void setBodyAndGuessCte( const TQCString& aBuf, 00601 TQValueList<int>& allowedCte, 00602 bool allow8Bit = false, 00603 bool willBeSigned = false, 00604 DwEntity *entity = 0 ); 00605 00609 TQCString bodyDecoded() const; 00610 TQByteArray bodyDecodedBinary() const; 00611 00614 int numBodyParts() const; 00615 00618 DwBodyPart * findDwBodyPart( int type, int subtype ) const; 00619 00622 DwBodyPart * findDwBodyPart( const TQCString& type, const TQCString& subtype ) const; 00623 00626 DwBodyPart* findDwBodyPart( DwBodyPart* part, const TQString & partSpecifier ); 00627 00630 DwBodyPart * dwBodyPart( int aIdx ) const; 00631 00634 int partNumber( DwBodyPart * aDwBodyPart ) const; 00635 00638 DwBodyPart * getFirstDwBodyPart() const; 00639 DwMessage * getTopLevelPart() const { return mMsg; } 00640 00644 static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart, 00645 bool withBody = true ); 00646 00650 void bodyPart(int aIdx, KMMessagePart* aPart) const; 00651 00653 DwBodyPart* createDWBodyPart(const KMMessagePart* aPart); 00654 00656 void addDwBodyPart(DwBodyPart * aDwPart); 00657 00659 void addBodyPart(const KMMessagePart* aPart); 00660 00662 void deleteBodyParts(); 00663 00668 bool deleteBodyPart( int partIndex ); 00669 00672 void setStatusFields(); 00673 00678 static TQString generateMessageId( const TQString& addr ); 00679 00685 static TQCString html2source( const TQCString & src ); 00686 00689 static TQString encodeMailtoUrl( const TQString& str ); 00690 00693 static TQString decodeMailtoUrl( const TQString& url ); 00694 00701 static TQCString stripEmailAddr(const TQCString& emailAddr); 00702 00705 static TQString stripEmailAddr(const TQString& emailAddr); 00706 00712 static TQString quoteHtmlChars( const TQString& str, 00713 bool removeLineBreaks = false ); 00714 00719 static TQString emailAddrAsAnchor(const TQString& emailAddr, 00720 bool stripped=true, const TQString& cssStyle = TQString(), bool link = true); 00721 00725 static TQStringList stripAddressFromAddressList( const TQString& address, 00726 const TQStringList& addresses ); 00727 00731 static TQStringList stripMyAddressesFromAddressList( const TQStringList& list ); 00732 00735 static bool addressIsInAddressList( const TQString& address, 00736 const TQStringList& addresses ); 00737 00741 static TQString expandAliases( const TQString& recipients ); 00742 00746 static TQString guessEmailAddressFromLoginName( const TQString& userName ); 00747 00754 static TQString smartQuote( const TQString &msg, int maxLineLength ); 00755 00757 static TQCString defaultCharset(); 00758 00760 static const TQStringList &preferredCharsets(); 00761 00763 TQString replaceHeadersInString( const TQString & s ) const; 00764 00766 TQCString charset() const; 00767 00776 void setCharset( const TQCString& charset, DwEntity *entity = 0 ); 00777 00779 const TQTextCodec * codec() const; 00780 00782 void setOverrideCodec( const TQTextCodec* codec ) { mOverrideCodec = codec; } 00783 00785 void setDecodeHTML(bool aDecodeHTML) 00786 { mDecodeHTML = aDecodeHTML; } 00787 00790 static void readConfig(); 00791 00795 TQCString getRefStr() const; 00796 00798 off_t folderOffset() const { return mFolderOffset; } 00799 void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(true); } } 00800 00802 TQString fileName() const { return mFileName; } 00803 void setFileName(const TQString& file) { if(mFileName != file) { mFileName=file; setDirty(true); } } 00804 00808 size_t msgSize() const { return mMsgSize; } 00809 void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(true); } } 00810 00813 size_t msgLength() const 00814 { return (mMsgLength) ? mMsgLength : mMsgSize; } 00815 void setMsgLength(size_t sz) { mMsgLength = sz; } 00816 00818 size_t msgSizeServer() const; 00819 void setMsgSizeServer(size_t sz); 00820 00822 ulong UID() const; 00823 void setUID(ulong uid); 00824 00826 KMMsgStatus status() const { return mStatus; } 00828 void setStatus(const KMMsgStatus status, int idx = -1); 00829 void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); } 00830 00832 void setEncryptionState(const KMMsgEncryptionState, int idx = -1); 00833 00835 void setSignatureState(const KMMsgSignatureState, int idx = -1); 00836 00837 void setMDNSentState( KMMsgMDNSentState status, int idx=-1 ); 00838 00840 KMMsgEncryptionState encryptionState() const { return mEncryptionState; } 00841 00843 KMMsgSignatureState signatureState() const { return mSignatureState; } 00844 00845 KMMsgMDNSentState mdnSentState() const { return mMDNSentState; } 00846 00848 void link(const KMMessage *aMsg, KMMsgStatus aStatus); 00851 void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *reStatus) const; 00852 00854 TQString formatString(const TQString&) const; 00855 00857 void updateBodyPart(const TQString partSpecifier, const TQByteArray & data); 00858 00860 DwBodyPart* lastUpdatedPart() { return mLastUpdated; } 00861 00863 bool isComplete() const { return mComplete; } 00865 void setComplete( bool v ) { mComplete = v; } 00866 00868 bool readyToShow() const { return mReadyToShow; } 00870 void setReadyToShow( bool v ) { mReadyToShow = v; } 00871 00872 void updateAttachmentState( DwBodyPart *part = 0 ); 00873 void updateInvitationState(); 00874 00876 bool transferInProgress() const; 00878 void setTransferInProgress(bool value, bool force = false); 00879 00884 TQCString mboxMessageSeparator(); 00885 00901 TQString asQuotedString( const TQString & headerStr, 00902 const TQString & indentStr, 00903 const TQString & selection=TQString(), 00904 bool aStripSignature=true, 00905 bool allowDecryption=true) const; 00906 00909 TQString asPlainText( bool stripSignature, bool allowDecryption ) const; 00910 00917 TQString asPlainTextFromObjectTree( partNode *root, bool stripSignature, 00918 bool allowDecryption ) const; 00919 00921 int getCursorPos() { return mCursorPos; }; 00923 void setCursorPos(int pos) { mCursorPos = pos; }; 00924 00926 KMMsgInfo* msgInfo() { return mMsgInfo; } 00928 void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; } 00929 00930 /* This is set in kmreaderwin if a message is being parsed to avoid 00931 other parts of kmail (e.g. kmheaders) destroying the message. 00932 Parsing can take longer and can be async (in case of gpg mails) */ 00933 bool isBeingParsed() const { return mIsParsed; } 00934 void setIsBeingParsed( bool t ) { mIsParsed = t; } 00935 00937 void deleteWhenUnused(); 00938 00939 DwBodyPart* findPart( int index ); 00940 00941 private: 00942 00944 void init( DwMessage* aMsg = 0 ); 00946 void assign( const KMMessage& other ); 00947 00948 DwBodyPart* findPartInternal( DwEntity* root, int index, int &accu ); 00949 00950 TQString mDrafts; 00951 TQString mTemplates; 00952 mutable DwMessage* mMsg; 00953 mutable bool mNeedsAssembly :1; 00954 bool mDecodeHTML :1; 00955 bool mReadyToShow :1; 00956 bool mComplete :1; 00957 bool mIsParsed : 1; 00958 static const KMail::HeaderStrategy * sHeaderStrategy; 00959 static TQString sForwardStr; 00960 const TQTextCodec * mOverrideCodec; 00961 00962 TQString mFileName; 00963 off_t mFolderOffset; 00964 size_t mMsgSize, mMsgLength; 00965 time_t mDate; 00966 KMMsgEncryptionState mEncryptionState; 00967 KMMsgSignatureState mSignatureState; 00968 KMMsgMDNSentState mMDNSentState; 00969 KMMessage* mUnencryptedMsg; 00970 DwBodyPart* mLastUpdated; 00971 int mCursorPos; 00972 KMMsgInfo* mMsgInfo; // used to remember the KMMsgInfo object this KMMessage replaced in the KMMsgList 00973 static TQValueList<KMMessage*> sPendingDeletes; 00974 }; 00975 00976 00977 #endif /*kmmessage_h*/