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 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;
00071
00072 public:
00073
00074 using KMMsgBase::parent;
00075 using KMMsgBase::setParent;
00076 using KMMsgBase::enableUndo;
00077 using KMMsgBase::setEnableUndo;
00078 using KMMsgBase::isRead;
00079 using KMMsgBase::isUnread;
00080 using KMMsgBase::isNew;
00081 using KMMsgBase::isOld;
00082 using KMMsgBase::isWatched;
00083 using KMMsgBase::isIgnored;
00084 using KMMsgBase::setEncryptionStateChar;
00085 using KMMsgBase::setSignatureStateChar;
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 QString selection=QString::null, bool noQuote=false,
00166 bool allowDecryption=true, bool selectionIsBody=false,
00167 const QString &tmpl = QString::null );
00168
00176 KMMessage* createRedirect( const QString &toStr );
00177
00179 QCString createForwardBody();
00180
00184 KMMessage* createForward( const QString &tmpl = QString::null );
00185
00189 KMMessage* createDeliveryReceipt() const;
00190
00204 KMMessage* createMDN( KMime::MDN::ActionMode a,
00205 KMime::MDN::DispositionType d,
00206 bool allowGUI=false,
00207 QValueList<KMime::MDN::DispositionModifier> m=QValueList<KMime::MDN::DispositionModifier>() );
00208
00210 void sanitizeHeaders( const QStringList& whiteList = QStringList() );
00211
00213 void fromDwString(const DwString& str, bool setStatus=false);
00214 void fromString(const QCString& str, bool setStatus=false);
00215 void fromByteArray(const QByteArray & ba, bool setStatus=false);
00216
00221 const DwString& asDwString() const;
00222 const DwMessage *asDwMessage();
00223
00231 QCString asString() const;
00232
00237 QByteArray asSendableString() const;
00238
00243 QCString headerAsSendableString() const;
00244
00248 void removePrivateHeaderFields();
00249
00251 DwMediaType& dwContentType();
00252
00254 QString headerAsString() const;
00255
00260 void parseTextStringFromDwPart( partNode * root,
00261 QCString& parsedString,
00262 const QTextCodec*& 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 QString dateStr() const;
00300 QCString dateShortStr() const;
00301 QString dateIsoStr() const;
00302 time_t date() const;
00303 void setDate(const QCString& str);
00304 void setDate(time_t aUnixTime);
00305
00307 void setDateToday();
00308
00310 QString to() const;
00311 void setTo(const QString& aStr);
00312 QString toStrip() const;
00313
00315 QString replyTo() const;
00316 void setReplyTo( const QString &aStr );
00317 void setReplyTo(KMMessage*);
00318
00320 QString cc() const;
00321 void setCc( const QString &aStr );
00322 QString ccStrip() const;
00323
00325 QString bcc() const;
00326 void setBcc( const QString &aStr );
00327
00329 QString fcc() const;
00330 void setFcc( const QString &aStr );
00331
00333 QString drafts() const { return mDrafts; }
00334 void setDrafts( const QString &aStr );
00335
00337 QString templates() const { return mTemplates; }
00338 void setTemplates( const QString &aStr );
00339
00341 QString from() const;
00342 void setFrom(const QString& aStr);
00343 QString fromStrip() const;
00344
00347 QString sender() const;
00348
00352 QString who() const;
00353
00355 QString subject() const;
00356 void setSubject(const QString& aStr);
00357
00359 void initStrippedSubjectMD5() {};
00360
00362 QString xmark() const;
00363 void setXMark(const QString& aStr);
00364
00366 QString replyToId() const;
00367 void setReplyToId(const QString& aStr);
00368 QString replyToIdMD5() const;
00369
00384 QString replyToAuxIdMD5() const;
00385
00390 QString strippedSubjectMD5() const;
00391
00402 static KPIM::EmailParseResult isValidEmailAddressList( const QString& aStr,
00403 QString& brokenAddress );
00404
00409 QString subjectMD5() const;
00410
00412 bool subjectIsPrefixed() const;
00413
00415 QString msgId() const;
00416 void setMsgId(const QString& aStr);
00417 QString msgIdMD5() const;
00418
00420 QString references() const;
00421 void setReferences(const QCString& aStr);
00422
00424 QCString id() const;
00425
00430 void setMsgSerNum(unsigned long newMsgSerNum = 0);
00431
00436 QString headerField(const QCString& name) const;
00437
00438 enum HeaderFieldType { Unstructured, Structured, Address };
00439
00444 void setHeaderField( const QCString& name, const QString& value,
00445 HeaderFieldType type = Unstructured,
00446 bool prepend = false );
00447
00449 QStringList headerFields( const QCString& name ) const;
00450
00455 QCString rawHeaderField( const QCString & name ) const;
00456
00460 QValueList<QCString> rawHeaderFields( const QCString & field ) const;
00461
00463 static KMime::Types::AddressList splitAddrField( const QCString & str );
00464
00468 KMime::Types::AddressList headerAddrField(const QCString& name) const;
00469 KMime::Types::AddrSpecList extractAddrSpecs( const QCString & headerNames ) const;
00470
00472 void removeHeaderField(const QCString& name);
00473
00475 void removeHeaderFields(const QCString& name);
00476
00480 QCString typeStr() const;
00481 int type() const;
00482 void setTypeStr(const QCString& aStr);
00483 void setType(int aType);
00485 QCString subtypeStr() const;
00486 int subtype() const;
00487 void setSubtypeStr(const QCString& aStr);
00488 void setSubtype(int aSubtype);
00490 static void setDwMediaTypeParam( DwMediaType &mType,
00491 const QCString& attr,
00492 const QCString& val );
00494 void setContentTypeParam(const QCString& attr, const QCString& val);
00495
00499 DwHeaders& headers() const;
00500
00505 void setNeedsAssembly();
00506
00511 void assembleIfNeeded();
00512
00521 QCString contentTransferEncodingStr() const;
00522 int contentTransferEncoding( DwEntity *entity = 0 ) const;
00523 void setContentTransferEncodingStr( const QCString& cteString, DwEntity *entity = 0 );
00524 void setContentTransferEncoding( int cte, DwEntity *entity = 0 );
00525
00530 QCString cteStr() const { return contentTransferEncodingStr(); }
00531 int cte( DwEntity *entity = 0 ) const { return contentTransferEncoding( entity ); }
00532 void setCteStr( const QCString& 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 QString & str, DwEntity *entity = 0 );
00547
00550 QString bodyToUnicode(const QTextCodec* codec=0) const;
00551
00553 QCString body() const;
00554
00556 void setBody(const QCString& aStr);
00557 void setBody(const DwString& aStr);
00558 void setBody(const char* aStr);
00559
00561 void setMultiPartBody( const QCString & aStr );
00562
00572 void setBodyEncoded( const QCString& aStr, DwEntity *entity = 0 );
00573 void setBodyEncodedBinary( const QByteArray& aStr, DwEntity *entity = 0 );
00574
00578 static QValueList<int> determineAllowedCtes( const KMime::CharFreq& cf,
00579 bool allow8Bit,
00580 bool willBeSigned );
00581
00595 void setBodyAndGuessCte( const QByteArray& aBuf, QValueList<int>& allowedCte,
00596 bool allow8Bit = false,
00597 bool willBeSigned = false,
00598 DwEntity *entity = 0 );
00599
00600 void setBodyAndGuessCte( const QCString& aBuf,
00601 QValueList<int>& allowedCte,
00602 bool allow8Bit = false,
00603 bool willBeSigned = false,
00604 DwEntity *entity = 0 );
00605
00609 QCString bodyDecoded() const;
00610 QByteArray bodyDecodedBinary() const;
00611
00614 int numBodyParts() const;
00615
00618 DwBodyPart * findDwBodyPart( int type, int subtype ) const;
00619
00622 DwBodyPart * findDwBodyPart( const QCString& type, const QCString& subtype ) const;
00623
00626 DwBodyPart* findDwBodyPart( DwBodyPart* part, const QString & 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 QString generateMessageId( const QString& addr );
00679
00685 static QCString html2source( const QCString & src );
00686
00689 static QString encodeMailtoUrl( const QString& str );
00690
00693 static QString decodeMailtoUrl( const QString& url );
00694
00701 static QCString stripEmailAddr(const QCString& emailAddr);
00702
00705 static QString stripEmailAddr(const QString& emailAddr);
00706
00712 static QString quoteHtmlChars( const QString& str,
00713 bool removeLineBreaks = false );
00714
00719 static QString emailAddrAsAnchor(const QString& emailAddr,
00720 bool stripped=true, const QString& cssStyle = QString::null, bool link = true);
00721
00725 static QStringList stripAddressFromAddressList( const QString& address,
00726 const QStringList& addresses );
00727
00731 static QStringList stripMyAddressesFromAddressList( const QStringList& list );
00732
00735 static bool addressIsInAddressList( const QString& address,
00736 const QStringList& addresses );
00737
00741 static QString expandAliases( const QString& recipients );
00742
00746 static QString guessEmailAddressFromLoginName( const QString& userName );
00747
00754 static QString smartQuote( const QString &msg, int maxLineLength );
00755
00757 static QCString defaultCharset();
00758
00760 static const QStringList &preferredCharsets();
00761
00763 QString replaceHeadersInString( const QString & s ) const;
00764
00766 QCString charset() const;
00767
00776 void setCharset( const QCString& charset, DwEntity *entity = 0 );
00777
00779 const QTextCodec * codec() const;
00780
00782 void setOverrideCodec( const QTextCodec* codec ) { mOverrideCodec = codec; }
00783
00785 void setDecodeHTML(bool aDecodeHTML)
00786 { mDecodeHTML = aDecodeHTML; }
00787
00790 static void readConfig();
00791
00795 QCString 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 QString fileName() const { return mFileName; }
00803 void setFileName(const QString& 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 *retStatus) const;
00852
00854 QString formatString(const QString&) const;
00855
00857 void updateBodyPart(const QString partSpecifier, const QByteArray & 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
00875 bool transferInProgress() const;
00877 void setTransferInProgress(bool value, bool force = false);
00878
00883 QCString mboxMessageSeparator();
00884
00900 QString asQuotedString( const QString & headerStr,
00901 const QString & indentStr,
00902 const QString & selection=QString::null,
00903 bool aStripSignature=true,
00904 bool allowDecryption=true) const;
00905
00908 QString asPlainText( bool stripSignature, bool allowDecryption ) const;
00909
00916 QString asPlainTextFromObjectTree( partNode *root, bool stripSignature,
00917 bool allowDecryption ) const;
00918
00920 int getCursorPos() { return mCursorPos; };
00922 void setCursorPos(int pos) { mCursorPos = pos; };
00923
00925 KMMsgInfo* msgInfo() { return mMsgInfo; }
00927 void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; }
00928
00929
00930
00931
00932 bool isBeingParsed() const { return mIsParsed; }
00933 void setIsBeingParsed( bool t ) { mIsParsed = t; }
00934
00936 void deleteWhenUnused();
00937
00938 DwBodyPart* findPart( int index );
00939
00940 private:
00941
00943 void init( DwMessage* aMsg = 0 );
00945 void assign( const KMMessage& other );
00946
00947 DwBodyPart* findPartInternal( DwEntity* root, int index, int &accu );
00948
00949 QString mDrafts;
00950 QString mTemplates;
00951 mutable DwMessage* mMsg;
00952 mutable bool mNeedsAssembly :1;
00953 bool mDecodeHTML :1;
00954 bool mReadyToShow :1;
00955 bool mComplete :1;
00956 bool mIsParsed : 1;
00957 static const KMail::HeaderStrategy * sHeaderStrategy;
00958 static QString sForwardStr;
00959 const QTextCodec * mOverrideCodec;
00960
00961 QString mFileName;
00962 off_t mFolderOffset;
00963 size_t mMsgSize, mMsgLength;
00964 time_t mDate;
00965 KMMsgEncryptionState mEncryptionState;
00966 KMMsgSignatureState mSignatureState;
00967 KMMsgMDNSentState mMDNSentState;
00968 KMMessage* mUnencryptedMsg;
00969 DwBodyPart* mLastUpdated;
00970 int mCursorPos;
00971 KMMsgInfo* mMsgInfo;
00972 static QValueList<KMMessage*> sPendingDeletes;
00973 };
00974
00975
00976 #endif