00001
00002
00003
00004
00005 #ifndef kmmessage_h
00006 #define kmmessage_h
00007
00010
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 QValueList;
00024
00025 class QStringList;
00026 class QString;
00027 class QTextCodec;
00028 class QStrList;
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 QValueList<Address> AddressList;
00044 typedef QValueList<AddrSpec> AddrSpecList;
00045 }
00046 }
00047
00048 namespace KMail {
00049 class HeaderStrategy;
00050 }
00051
00052 class DwBodyPart;
00053 class DwMediaType;
00054 class DwHeaders;
00055
00056 class partNode;
00057
00058 namespace KMail {
00059 enum ReplyStrategy { ReplySmart = 0,
00060 ReplyAuthor,
00061 ReplyList,
00062 ReplyAll,
00063 ReplyNone };
00064 }
00065
00067 class KMMessage: public KMMsgBase, public KMail::ISubject
00068 {
00069 friend class ::KMForwardDigestCommand;
00070
00071 public:
00072
00073 using KMMsgBase::parent;
00074 using KMMsgBase::setParent;
00075 using KMMsgBase::enableUndo;
00076 using KMMsgBase::setEnableUndo;
00077 using KMMsgBase::isRead;
00078 using KMMsgBase::isUnread;
00079 using KMMsgBase::isNew;
00080 using KMMsgBase::isOld;
00081 using KMMsgBase::isWatched;
00082 using KMMsgBase::isIgnored;
00083 using KMMsgBase::setEncryptionStateChar;
00084 using KMMsgBase::setSignatureStateChar;
00085
00087 KMMessage(KMFolder* parent=0);
00088
00092 KMMessage(DwMessage*);
00093
00095 KMMessage(KMMsgInfo& msgInfo);
00096
00098 KMMessage( const KMMessage& other );
00099
00100 #if 0 // currently unused
00101
00102 const KMMessage& operator=( const KMMessage& other ) {
00103 if( &other == this )
00104 return *this;
00105 assign( other );
00106 return *this;
00107 }
00108 #endif
00109
00111 virtual ~KMMessage();
00112
00114 KMMsgBase & toMsgBase() { return *this; }
00115 const KMMsgBase & toMsgBase() const { return *this; }
00116
00118 bool isMessage() const;
00119
00123 bool isUrgent() const;
00124
00131 void setUnencryptedMsg( KMMessage* unencrypted );
00132
00134 bool hasUnencryptedMsg() const { return 0 != mUnencryptedMsg; }
00135
00137 KMMessage* unencryptedMsg() const { return mUnencryptedMsg; }
00138
00144 KMMessage* takeUnencryptedMsg()
00145 {
00146 KMMessage* ret = mUnencryptedMsg;
00147 mUnencryptedMsg = 0;
00148 return ret;
00149 }
00150
00152 void del() { setStatus(KMMsgStatusDeleted); }
00153
00155 void undel() { setStatus(KMMsgStatusOld); }
00156
00158 void touch() { setStatus(KMMsgStatusOld); }
00159
00163 KMMessage* createReply( KMail::ReplyStrategy replyStrategy = KMail::ReplySmart,
00164 QString selection=QString::null, bool noQuote=false,
00165 bool allowDecryption=true, bool selectionIsBody=false,
00166 const QString &tmpl = QString::null );
00167
00175 KMMessage* createRedirect( const QString &toStr );
00176
00178 QCString createForwardBody();
00179
00183 KMMessage* createForward( const QString &tmpl = QString::null );
00184
00188 KMMessage* createDeliveryReceipt() const;
00189
00203 KMMessage* createMDN( KMime::MDN::ActionMode a,
00204 KMime::MDN::DispositionType d,
00205 bool allowGUI=false,
00206 QValueList<KMime::MDN::DispositionModifier> m=QValueList<KMime::MDN::DispositionModifier>() );
00207
00209 void sanitizeHeaders( const QStringList& whiteList = QStringList() );
00210
00212 void fromDwString(const DwString& str, bool setStatus=false);
00213 void fromString(const QCString& str, bool setStatus=false);
00214 void fromByteArray(const QByteArray & ba, bool setStatus=false);
00215
00220 const DwString& asDwString() const;
00221 const DwMessage *asDwMessage();
00222
00230 QCString asString() const;
00231
00236 QByteArray asSendableString() const;
00237
00242 QCString headerAsSendableString() const;
00243
00247 void removePrivateHeaderFields();
00248
00250 DwMediaType& dwContentType();
00251
00253 QString headerAsString() const;
00254
00259 void parseTextStringFromDwPart( partNode * root,
00260 QCString& parsedString,
00261 const QTextCodec*& codec,
00262 bool& isHTML ) const;
00263
00267 void initHeader(uint identity=0);
00268
00271 void initFromMessage(const KMMessage *msg, bool idHeaders = true);
00272
00278 uint identityUoid() const;
00279
00282 void applyIdentity( uint id );
00283
00286 void cleanupHeader();
00287
00293 void setAutomaticFields(bool isMultipart=false);
00294
00296 QString dateStr() const;
00299 QCString dateShortStr() const;
00300 QString dateIsoStr() const;
00301 time_t date() const;
00302 void setDate(const QCString& str);
00303 void setDate(time_t aUnixTime);
00304
00306 void setDateToday();
00307
00309 QString to() const;
00310 void setTo(const QString& aStr);
00311 QString toStrip() const;
00312
00314 QString replyTo() const;
00315 void setReplyTo( const QString &aStr );
00316 void setReplyTo(KMMessage*);
00317
00319 QString cc() const;
00320 void setCc( const QString &aStr );
00321 QString ccStrip() const;
00322
00324 QString bcc() const;
00325 void setBcc( const QString &aStr );
00326
00328 QString fcc() const;
00329 void setFcc( const QString &aStr );
00330
00332 QString drafts() const { return mDrafts; }
00333 void setDrafts( const QString &aStr );
00334
00336 QString templates() const { return mTemplates; }
00337 void setTemplates( const QString &aStr );
00338
00340 QString from() const;
00341 void setFrom(const QString& aStr);
00342 QString fromStrip() const;
00343
00346 QString sender() const;
00347
00351 QString who() const;
00352
00354 QString subject() const;
00355 void setSubject(const QString& aStr);
00356
00358 void initStrippedSubjectMD5() {};
00359
00361 QString xmark() const;
00362 void setXMark(const QString& aStr);
00363
00365 QString replyToId() const;
00366 void setReplyToId(const QString& aStr);
00367 QString replyToIdMD5() const;
00368
00383 QString replyToAuxIdMD5() const;
00384
00389 QString strippedSubjectMD5() const;
00390
00401 static KPIM::EmailParseResult isValidEmailAddressList( const QString& aStr,
00402 QString& brokenAddress );
00403
00408 QString subjectMD5() const;
00409
00411 bool subjectIsPrefixed() const;
00412
00414 QString msgId() const;
00415 void setMsgId(const QString& aStr);
00416 QString msgIdMD5() const;
00417
00419 QString references() const;
00420 void setReferences(const QCString& aStr);
00421
00423 QCString id() const;
00424
00429 void setMsgSerNum(unsigned long newMsgSerNum = 0);
00430
00435 QString headerField(const QCString& name) const;
00436
00437 enum HeaderFieldType { Unstructured, Structured, Address };
00438
00443 void setHeaderField( const QCString& name, const QString& value,
00444 HeaderFieldType type = Unstructured,
00445 bool prepend = false );
00446
00448 QStringList headerFields( const QCString& name ) const;
00449
00454 QCString rawHeaderField( const QCString & name ) const;
00455
00459 QValueList<QCString> rawHeaderFields( const QCString & field ) const;
00460
00462 static KMime::Types::AddressList splitAddrField( const QCString & str );
00463
00467 KMime::Types::AddressList headerAddrField(const QCString& name) const;
00468 KMime::Types::AddrSpecList extractAddrSpecs( const QCString & headerNames ) const;
00469
00471 void removeHeaderField(const QCString& name);
00472
00474 void removeHeaderFields(const QCString& name);
00475
00479 QCString typeStr() const;
00480 int type() const;
00481 void setTypeStr(const QCString& aStr);
00482 void setType(int aType);
00484 QCString subtypeStr() const;
00485 int subtype() const;
00486 void setSubtypeStr(const QCString& aStr);
00487 void setSubtype(int aSubtype);
00489 static void setDwMediaTypeParam( DwMediaType &mType,
00490 const QCString& attr,
00491 const QCString& val );
00493 void setContentTypeParam(const QCString& attr, const QCString& val);
00494
00498 DwHeaders& headers() const;
00499
00504 void setNeedsAssembly();
00505
00509 QCString contentTransferEncodingStr() const;
00510 int contentTransferEncoding() const;
00511 void setContentTransferEncodingStr(const QCString& aStr);
00512 void setContentTransferEncoding(int aCte);
00513
00516 QCString cteStr() const { return contentTransferEncodingStr(); }
00517 int cte() const { return contentTransferEncoding(); }
00518 void setCteStr(const QCString& aStr) { setContentTransferEncodingStr(aStr); }
00519 void setCte(int aCte) { setContentTransferEncoding(aCte); }
00520
00524 void setBodyFromUnicode( const QString & str );
00525
00528 QString bodyToUnicode(const QTextCodec* codec=0) const;
00529
00531 QCString body() const;
00532
00534 void setBody(const QCString& aStr);
00535 void setBody(const DwString& aStr);
00536 void setBody(const char* aStr);
00537
00539 void setMultiPartBody( const QCString & aStr );
00540
00544 void setBodyEncoded(const QCString& aStr);
00545 void setBodyEncodedBinary(const QByteArray& aStr);
00546
00550 static QValueList<int> determineAllowedCtes( const KMime::CharFreq& cf,
00551 bool allow8Bit,
00552 bool willBeSigned );
00553
00563 void setBodyAndGuessCte( const QByteArray& aBuf,
00564 QValueList<int>& allowedCte,
00565 bool allow8Bit = false,
00566 bool willBeSigned = false );
00567 void setBodyAndGuessCte( const QCString& aBuf,
00568 QValueList<int>& allowedCte,
00569 bool allow8Bit = false,
00570 bool willBeSigned = false );
00571
00575 QCString bodyDecoded() const;
00576 QByteArray bodyDecodedBinary() const;
00577
00580 int numBodyParts() const;
00581
00584 DwBodyPart * findDwBodyPart( int type, int subtype ) const;
00585
00588 DwBodyPart * findDwBodyPart( const QCString& type, const QCString& subtype ) const;
00589
00592 DwBodyPart* findDwBodyPart( DwBodyPart* part, const QString & partSpecifier );
00593
00596 DwBodyPart * dwBodyPart( int aIdx ) const;
00597
00600 int partNumber( DwBodyPart * aDwBodyPart ) const;
00601
00604 DwBodyPart * getFirstDwBodyPart() const;
00605 DwMessage * getTopLevelPart() const { return mMsg; }
00606
00610 static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
00611 bool withBody = true );
00612
00616 void bodyPart(int aIdx, KMMessagePart* aPart) const;
00617
00619 DwBodyPart* createDWBodyPart(const KMMessagePart* aPart);
00620
00622 void addDwBodyPart(DwBodyPart * aDwPart);
00623
00625 void addBodyPart(const KMMessagePart* aPart);
00626
00628 void deleteBodyParts();
00629
00632 void setStatusFields();
00633
00638 static QString generateMessageId( const QString& addr );
00639
00645 static QCString html2source( const QCString & src );
00646
00649 static QString encodeMailtoUrl( const QString& str );
00650
00653 static QString decodeMailtoUrl( const QString& url );
00654
00661 static QCString stripEmailAddr(const QCString& emailAddr);
00662
00665 static QString stripEmailAddr(const QString& emailAddr);
00666
00672 static QString quoteHtmlChars( const QString& str,
00673 bool removeLineBreaks = false );
00674
00679 static QString emailAddrAsAnchor(const QString& emailAddr,
00680 bool stripped=true, const QString& cssStyle = QString::null, bool link = true);
00681
00685 static QStringList stripAddressFromAddressList( const QString& address,
00686 const QStringList& addresses );
00687
00691 static QStringList stripMyAddressesFromAddressList( const QStringList& list );
00692
00695 static bool addressIsInAddressList( const QString& address,
00696 const QStringList& addresses );
00697
00701 static QString expandAliases( const QString& recipients );
00702
00706 static QString guessEmailAddressFromLoginName( const QString& userName );
00707
00714 static QString smartQuote( const QString &msg, int maxLineLength );
00715
00717 static QCString defaultCharset();
00718
00720 static const QStringList &preferredCharsets();
00721
00723 QString replaceHeadersInString( const QString & s ) const;
00724
00726 QCString charset() const;
00727
00729 void setCharset(const QCString& aStr);
00730
00732 const QTextCodec * codec() const;
00733
00735 void setOverrideCodec( const QTextCodec* codec ) { mOverrideCodec = codec; }
00736
00738 void setDecodeHTML(bool aDecodeHTML)
00739 { mDecodeHTML = aDecodeHTML; }
00740
00743 static void readConfig();
00744
00748 QCString getRefStr() const;
00749
00751 off_t folderOffset() const { return mFolderOffset; }
00752 void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(true); } }
00753
00755 QString fileName() const { return mFileName; }
00756 void setFileName(const QString& file) { if(mFileName != file) { mFileName=file; setDirty(true); } }
00757
00761 size_t msgSize() const { return mMsgSize; }
00762 void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(true); } }
00763
00766 size_t msgLength() const
00767 { return (mMsgLength) ? mMsgLength : mMsgSize; }
00768 void setMsgLength(size_t sz) { mMsgLength = sz; }
00769
00771 size_t msgSizeServer() const;
00772 void setMsgSizeServer(size_t sz);
00773
00775 ulong UID() const;
00776 void setUID(ulong uid);
00777
00779 KMMsgStatus status() const { return mStatus; }
00781 void setStatus(const KMMsgStatus status, int idx = -1);
00782 void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
00783
00785 void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00786
00788 void setSignatureState(const KMMsgSignatureState, int idx = -1);
00789
00790 void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00791
00793 KMMsgEncryptionState encryptionState() const { return mEncryptionState; }
00794
00796 KMMsgSignatureState signatureState() const { return mSignatureState; }
00797
00798 KMMsgMDNSentState mdnSentState() const { return mMDNSentState; }
00799
00801 void link(const KMMessage *aMsg, KMMsgStatus aStatus);
00804 void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *retStatus) const;
00805
00807 QString formatString(const QString&) const;
00808
00810 void updateBodyPart(const QString partSpecifier, const QByteArray & data);
00811
00813 DwBodyPart* lastUpdatedPart() { return mLastUpdated; }
00814
00816 bool isComplete() const { return mComplete; }
00818 void setComplete( bool v ) { mComplete = v; }
00819
00821 bool readyToShow() const { return mReadyToShow; }
00823 void setReadyToShow( bool v ) { mReadyToShow = v; }
00824
00825 void updateAttachmentState(DwBodyPart * part = 0);
00826
00828 bool transferInProgress() const;
00830 void setTransferInProgress(bool value, bool force = false);
00831
00836 QCString mboxMessageSeparator();
00837
00853 QString asQuotedString( const QString & headerStr,
00854 const QString & indentStr,
00855 const QString & selection=QString::null,
00856 bool aStripSignature=true,
00857 bool allowDecryption=true) const;
00858
00861 QString asPlainText( bool stripSignature, bool allowDecryption ) const;
00862
00864 int getCursorPos() { return mCursorPos; };
00866 void setCursorPos(int pos) { mCursorPos = pos; };
00867
00869 KMMsgInfo* msgInfo() { return mMsgInfo; }
00871 void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; }
00872
00873
00874
00875
00876 bool isBeingParsed() const { return mIsParsed; }
00877 void setIsBeingParsed( bool t ) { mIsParsed = t; }
00878
00880 void deleteWhenUnused();
00881
00882 private:
00883
00885 void init( DwMessage* aMsg = 0 );
00887 void assign( const KMMessage& other );
00888
00889 QString mDrafts;
00890 QString mTemplates;
00891 mutable DwMessage* mMsg;
00892 mutable bool mNeedsAssembly :1;
00893 bool mDecodeHTML :1;
00894 bool mReadyToShow :1;
00895 bool mComplete :1;
00896 bool mIsParsed : 1;
00897 static const KMail::HeaderStrategy * sHeaderStrategy;
00898 static QString sForwardStr;
00899 const QTextCodec * mOverrideCodec;
00900
00901 QString mFileName;
00902 off_t mFolderOffset;
00903 size_t mMsgSize, mMsgLength;
00904 time_t mDate;
00905 KMMsgEncryptionState mEncryptionState;
00906 KMMsgSignatureState mSignatureState;
00907 KMMsgMDNSentState mMDNSentState;
00908 KMMessage* mUnencryptedMsg;
00909 DwBodyPart* mLastUpdated;
00910 int mCursorPos;
00911 KMMsgInfo* mMsgInfo;
00912 static QValueList<KMMessage*> sPendingDeletes;
00913 };
00914
00915
00916 #endif