kmail Library API Documentation

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 
00008 // for large file support
00009 #include <config.h>
00010 #include <sys/types.h>
00011 
00012 #include <mimelib/string.h>
00013 #include "kmmsgbase.h"
00014 #include "isubject.h"
00015 
00016 #include <kmime_mdn.h>
00017 
00018 template <typename T>
00019 class QValueList;
00020 
00021 class QStringList;
00022 class QString;
00023 class QTextCodec;
00024 class QStrList;
00025 
00026 class KMFolder;
00027 class KMFolderIndex;
00028 class DwMessage;
00029 class KMMessagePart;
00030 class KMMsgInfo;
00031 class KMHeaders;
00032 
00033 namespace KMime {
00034   class CharFreq;
00035   namespace Types {
00036     class AddrSpec;
00037     class Address;
00038     typedef QValueList<Address> AddressList;
00039     typedef QValueList<AddrSpec> AddrSpecList;
00040   }
00041 }
00042 
00043 namespace KMail {
00044   class HeaderStrategy;
00045 }
00046 
00047 class DwBodyPart;
00048 class DwMediaType;
00049 class DwHeaders;
00050 
00051 namespace KMail {
00052   enum ReplyStrategy { ReplySmart = 0,
00053                        ReplyAuthor,
00054                        ReplyList,
00055                        ReplyAll,
00056                        ReplyNone };
00057 }
00058 
00059 class KMMessage: public KMMsgBase, public KMail::ISubject
00060 {
00061   friend class KMForwardCommand;    // needed for MIME Digest forward
00062 
00063 public:
00064   // promote some of KMMsgBase's methods to public:
00065   using KMMsgBase::parent;
00066   using KMMsgBase::setParent;
00067   using KMMsgBase::enableUndo; // KMFolder
00068   using KMMsgBase::setEnableUndo; // dto.
00069   using KMMsgBase::isRead; // dto.
00070   using KMMsgBase::isUnread; // dto.
00071   using KMMsgBase::isNew; // dto.
00072   using KMMsgBase::isOld;
00073   using KMMsgBase::isWatched;
00074   using KMMsgBase::isIgnored;
00075   using KMMsgBase::setEncryptionStateChar; // KMAcct*
00076   using KMMsgBase::setSignatureStateChar; // dto.
00077 
00079   KMMessage(KMFolderIndex* parent=0);
00080 
00082   KMMessage(DwMessage*);
00083 
00085   KMMessage(KMMsgInfo& msgInfo);
00086 
00088   KMMessage( const KMMessage& other );
00089     //KMMessage( const KMMessage& other,
00090     //           bool preserveArrivalTime=false  );
00091     //  note: By setting preserveArrivalTime true you get
00092     //        a message containing the arrival time of the
00093     //        old one - this is useful if this new message
00094     //        is to replace the old one in the same folder
00095     // note2: temporarily uncommented this again (khz)
00096 
00098   const KMMessage& operator=( const KMMessage& other ) {
00099     //const KMMessage& operator=( const KMMessage& other,
00100     //                          bool preserveArrivalTime=false ) {
00101     //  note: By setting preserveArrivalTime true you get
00102     //        a message containing the arrival time of the
00103     //        old one - this is useful if this new message
00104     //        is to replace the old one in the same folder
00105     // note2: temporarily uncommented this again (khz)
00106     if( &other == this )
00107       return *this;
00108     assign( other ); return *this;
00109   }
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 
00175   KMMessage* createRedirect();
00176 
00181   KMMessage* createBounce( bool withUI );
00182 
00184   QCString createForwardBody();
00185 
00189   KMMessage* createForward();
00190 
00194   KMMessage* createDeliveryReceipt() const;
00195 
00209   KMMessage* createMDN( KMime::MDN::ActionMode a,
00210             KMime::MDN::DispositionType d,
00211             bool allowGUI=false,
00212             QValueList<KMime::MDN::DispositionModifier> m=QValueList<KMime::MDN::DispositionModifier>() );
00213 
00215   void fromDwString(const DwString& str, bool setStatus=FALSE);
00216   void fromString(const QCString& str, bool setStatus=FALSE);
00217   void fromByteArray( const QByteArray & ba, bool setStatus=false );
00218 
00223   const DwString& asDwString() const;
00224   const DwMessage *asDwMessage();
00225 
00235   QCString asString() const;
00236 
00241   QCString asSendableString() const;
00242 
00247   QCString headerAsSendableString() const;
00248 
00252   void removePrivateHeaderFields();
00253 
00255   DwMediaType& dwContentType();
00256 
00258   QString headerAsString() const;
00259 
00264   void parseTextStringFromDwPart( DwBodyPart * mainBody,
00265                       DwBodyPart * firstBodyPart,
00266                                           QCString& parsedString,
00267                                           const QTextCodec*& codec,
00268                                           bool& isHTML ) const;
00269 
00273   void initHeader(uint identity=0);
00274 
00277   void initFromMessage(const KMMessage *msg, bool idHeaders = TRUE);
00278 
00284   uint identityUoid() const;
00285 
00288   void cleanupHeader();
00289 
00295   void setAutomaticFields(bool isMultipart=FALSE);
00296 
00298   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 from() const;
00337   void setFrom(const QString& aStr);
00338   QString fromStrip() const;
00339   QCString fromEmail() const;
00340 
00343   QString sender() const;
00344 
00348   QString who() const;
00349 
00351   QString subject() const;
00352   void setSubject(const QString& aStr);
00353 
00355   void initStrippedSubjectMD5() {};
00356 
00363   static QString replacePrefixes( const QString& str,
00364                                   const QStringList& prefixRegExps,
00365                                   bool replace,
00366                                   const QString& newPrefix );
00367 
00370   static QString stripOffPrefixes( const QString& str );
00371 
00378   QString cleanSubject(const QStringList& prefixRegExps, bool replace,
00379                const QString& newPrefix) const;
00380 
00383   QString cleanSubject() const;
00384 
00386   QString forwardSubject() const;
00387 
00389   QString replySubject() const;
00390 
00392   QString xmark() const;
00393   void setXMark(const QString& aStr);
00394 
00396   QString replyToId() const;
00397   void setReplyToId(const QString& aStr);
00398   QString replyToIdMD5() const;
00399 
00414   QString replyToAuxIdMD5() const;
00415 
00420   QString strippedSubjectMD5() const;
00421 
00426   QString subjectMD5() const;
00427 
00429   bool subjectIsPrefixed() const;
00430 
00432   QString msgId() const;
00433   void setMsgId(const QString& aStr);
00434   QString msgIdMD5() const;
00435 
00437   QString references() const;
00438   void setReferences(const QCString& aStr);
00439 
00441   QCString id() const;
00442 
00445   void setMsgSerNum(unsigned long newMsgSerNum = 0);
00446 
00448   QString headerField(const QCString& name) const;
00449   void setHeaderField(const QCString& name, const QString& value);
00450 
00452   QString allHeaderFields(const QCString& aName) const;
00453 
00455   QCString rawHeaderField( const QCString & name ) const;
00456 
00460   KMime::Types::AddressList headerAddrField(const QCString& name) const;
00461   KMime::Types::AddrSpecList extractAddrSpecs( const QCString & headerNames ) const;
00462 
00464   void removeHeaderField(const QCString& name);
00465 
00469   QCString typeStr() const;
00470   int type() const;
00471   void setTypeStr(const QCString& aStr);
00472   void setType(int aType);
00474   QCString subtypeStr() const;
00475   int subtype() const;
00476   void setSubtypeStr(const QCString& aStr);
00477   void setSubtype(int aSubtype);
00479   static void setDwMediaTypeParam( DwMediaType &mType,
00480                                    const QCString& attr,
00481                                    const QCString& val );
00483   void setContentTypeParam(const QCString& attr, const QCString& val);
00484 
00488   DwHeaders& headers() const;
00489 
00494   void setNeedsAssembly();
00495 
00499   QCString contentTransferEncodingStr() const;
00500   int  contentTransferEncoding() const;
00501   void setContentTransferEncodingStr(const QCString& aStr);
00502   void setContentTransferEncoding(int aCte);
00503 
00506   QCString cteStr() const { return contentTransferEncodingStr(); }
00507   int cte() const { return contentTransferEncoding(); }
00508   void setCteStr(const QCString& aStr) { setContentTransferEncodingStr(aStr); }
00509   void setCte(int aCte) { setContentTransferEncoding(aCte); }
00510 
00514   void setBodyFromUnicode( const QString & str );
00515 
00518   QString bodyToUnicode(const QTextCodec* codec=0) const;
00519 
00521   QCString body() const;
00522 
00524   void setBody(const QCString& aStr);
00525 
00527   void setMultiPartBody( const QCString & aStr );
00528 
00532   void setBodyEncoded(const QCString& aStr);
00533   void setBodyEncodedBinary(const QByteArray& aStr);
00534 
00538   static QValueList<int> determineAllowedCtes( const KMime::CharFreq& cf,
00539                                                bool allow8Bit,
00540                                                bool willBeSigned );
00541 
00551   void setBodyAndGuessCte( const QByteArray& aBuf,
00552                                    QValueList<int>& allowedCte,
00553                                    bool allow8Bit = false,
00554                                    bool willBeSigned = false );
00555   void setBodyAndGuessCte( const QCString& aBuf,
00556                                    QValueList<int>& allowedCte,
00557                                    bool allow8Bit = false,
00558                                    bool willBeSigned = false );
00559 
00563   QCString bodyDecoded() const;
00564   QByteArray bodyDecodedBinary() const;
00565 
00568   int numBodyParts() const;
00569 
00572   DwBodyPart * findDwBodyPart( int type, int subtype ) const;
00573 
00576   DwBodyPart* findDwBodyPart( DwBodyPart* part, const QString & partSpecifier );
00577 
00580   DwBodyPart * dwBodyPart( int aIdx ) const;
00581 
00584   int partNumber( DwBodyPart * aDwBodyPart ) const;
00585 
00588   DwBodyPart * getFirstDwBodyPart() const;
00589 
00593   static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
00594                bool withBody = true );
00595 
00599   void bodyPart(int aIdx, KMMessagePart* aPart) const;
00600 
00602   DwBodyPart* createDWBodyPart(const KMMessagePart* aPart);
00603 
00605   void addDwBodyPart(DwBodyPart * aDwPart);
00606 
00608   void addBodyPart(const KMMessagePart* aPart);
00609 
00611   void deleteBodyParts();
00612 
00615   void setStatusFields();
00616 
00621   static QString generateMessageId( const QString& addr );
00622 
00628   static QCString html2source( const QCString & src );
00629 
00632   static QCString lf2crlf( const QCString & src );
00633 
00636   static QString encodeMailtoUrl( const QString& str );
00637 
00640   static QString decodeMailtoUrl( const QString& url );
00641 
00648   static QCString stripEmailAddr(const QCString& emailAddr);
00649 
00652   static QString stripEmailAddr(const QString& emailAddr);
00653 
00658   static QCString getEmailAddr(const QString& emailAddr);
00659 
00665   static QString quoteHtmlChars( const QString& str,
00666                                  bool removeLineBreaks = false );
00667 
00672   static QString emailAddrAsAnchor(const QString& emailAddr,
00673                      bool stripped=TRUE);
00674 
00676   static QStringList splitEmailAddrList(const QString&);
00677 
00681   static QStringList stripAddressFromAddressList( const QString& address,
00682                                                   const QStringList& addresses );
00683 
00687   static QStringList stripMyAddressesFromAddressList( const QStringList& list );
00688 
00691   static bool addressIsInAddressList( const QString& address,
00692                                       const QStringList& addresses );
00693 
00697   static QString expandAliases( const QString& recipients );
00698 
00702   static QString guessEmailAddressFromLoginName( const QString& userName );
00703 
00704 
00706   static QCString defaultCharset();
00707 
00709   static const QStringList &preferredCharsets();
00710 
00713   QString replaceHeadersInString( const QString & s ) const;
00714 
00716   QCString charset() const;
00717 
00719   void setCharset(const QCString& aStr);
00720 
00722   const QTextCodec * codec() const;
00723 
00725   void setOverrideCodec( const QTextCodec* codec ) { mOverrideCodec = codec; }
00726 
00728   void setDecodeHTML(bool aDecodeHTML)
00729   { mDecodeHTML = aDecodeHTML; }
00730 
00733   static void readConfig();
00734 
00738   QCString getRefStr() const;
00739 
00741   off_t folderOffset() const { return mFolderOffset; }
00742   void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(TRUE); } }
00743 
00745   QString fileName() const { return mFileName; }
00746   void setFileName(const QString& file) { if(mFileName != file) { mFileName=file; setDirty(TRUE); } }
00747 
00751   size_t msgSize() const { return mMsgSize; }
00752   void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(TRUE); } }
00753 
00756   size_t msgLength() const
00757     { return (mMsgLength) ? mMsgLength : mMsgSize; }
00758   void setMsgLength(size_t sz) { mMsgLength = sz; }
00759 
00761   KMMsgStatus status() const { return mStatus; }
00763   void setStatus(const KMMsgStatus status, int idx = -1);
00764   void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
00765 
00767   void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00768 
00770   void setSignatureState(const KMMsgSignatureState, int idx = -1);
00771 
00772   void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00773 
00775   KMMsgEncryptionState encryptionState() const { return mEncryptionState; }
00776 
00778   KMMsgSignatureState signatureState() const { return mSignatureState; }
00779 
00780   KMMsgMDNSentState mdnSentState() const { return mMDNSentState; }
00781 
00783   void link(const KMMessage *aMsg, KMMsgStatus aStatus);
00786   void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *retStatus) const;
00787 
00789   QString formatString(const QString&) const;
00790 
00792   void updateBodyPart(const QString partSpecifier, const QByteArray & data);
00793 
00795   DwBodyPart* lastUpdatedPart() { return mLastUpdated; }
00796 
00797 private:
00813   QString asQuotedString( const QString & headerStr,
00814               const QString & indentStr,
00815               const QString & selection=QString::null,
00816               bool aStripSignature=true,
00817               bool allowDecryption=true) const;
00818 
00821   QString asPlainText( bool stripSignature, bool allowDecryption ) const;
00822 
00823   void assign( const KMMessage& other );
00824 
00825   QString mDrafts;
00826   mutable DwMessage* mMsg;
00827   mutable bool       mNeedsAssembly;
00828   bool mDecodeHTML;
00829   static const KMail::HeaderStrategy * sHeaderStrategy;
00830   static QString sForwardStr;
00831   const QTextCodec * mOverrideCodec;
00832 
00833   QString mFileName;
00834   off_t mFolderOffset;
00835   size_t mMsgSize, mMsgLength;
00836   time_t mDate;
00837   KMMsgEncryptionState mEncryptionState;
00838   KMMsgSignatureState mSignatureState;
00839   KMMsgMDNSentState mMDNSentState;
00840   KMMessage* mUnencryptedMsg;
00841   DwBodyPart* mLastUpdated;
00842 };
00843 
00844 
00845 #endif /*kmmessage_h*/
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:37:33 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003