kmail

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 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; // 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                           QString selection=QString::null, bool noQuote = false,
00166                           bool allowDecryption = true,
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 
00214   KMMessage* createDecryptedCopy();
00215 
00217   void sanitizeHeaders( const QStringList& whiteList = QStringList() );
00218 
00220   void fromDwString(const DwString& str, bool setStatus=false);
00221   void fromString(const QCString& str, bool setStatus=false);
00222   void fromByteArray(const QByteArray & ba, bool setStatus=false);
00223 
00228   const DwString& asDwString() const;
00229   const DwMessage *asDwMessage();
00230 
00238   QCString asString() const;
00239 
00244   QByteArray asSendableString() const;
00245 
00250   QCString headerAsSendableString() const;
00251 
00255   void removePrivateHeaderFields();
00256 
00258   DwMediaType& dwContentType();
00259 
00261   QString headerAsString() const;
00262 
00267   void parseTextStringFromDwPart( partNode * root,
00268                                           QCString& parsedString,
00269                                           const QTextCodec*& codec,
00270                                           bool& isHTML ) const;
00271 
00275   void initHeader(uint identity=0);
00276 
00279   void initFromMessage(const KMMessage *msg, bool idHeaders = true);
00280 
00286   uint identityUoid() const;
00287 
00290   void applyIdentity( uint id );
00291 
00294   void cleanupHeader();
00295 
00301   void setAutomaticFields(bool isMultipart=false);
00302 
00304   QString dateStr() const;
00307   QCString dateShortStr() const;
00308   QString dateIsoStr() const;
00309   time_t date() const;
00310   void setDate(const QCString& str);
00311   void setDate(time_t aUnixTime);
00312 
00314   void setDateToday();
00315 
00317   QString to() const;
00318   void setTo(const QString& aStr);
00319   QString toStrip() const;
00320 
00322   QString replyTo() const;
00323   void setReplyTo( const QString &aStr );
00324   void setReplyTo(KMMessage*);
00325 
00327   QString cc() const;
00328   void setCc( const QString &aStr );
00329   QString ccStrip() const;
00330 
00332   QString bcc() const;
00333   void setBcc( const QString &aStr );
00334 
00336   QString fcc() const;
00337   void setFcc( const QString &aStr );
00338 
00340   QString drafts() const { return mDrafts; }
00341   void setDrafts( const QString &aStr );
00342 
00344   QString templates() const { return mTemplates; }
00345   void setTemplates( const QString &aStr );
00346 
00348   QString from() const;
00349   void setFrom(const QString& aStr);
00350   QString fromStrip() const;
00351 
00354   QString sender() const;
00355 
00359   QString who() const;
00360 
00362   QString subject() const;
00363   void setSubject(const QString& aStr);
00364 
00366   void initStrippedSubjectMD5() {};
00367 
00369   QString xmark() const;
00370   void setXMark(const QString& aStr);
00371 
00373   QString replyToId() const;
00374   void setReplyToId(const QString& aStr);
00375   QString replyToIdMD5() const;
00376 
00391   QString replyToAuxIdMD5() const;
00392 
00397   QString strippedSubjectMD5() const;
00398 
00409   static KPIM::EmailParseResult isValidEmailAddressList( const QString& aStr,
00410                                                          QString& brokenAddress );
00411 
00416   QString subjectMD5() const;
00417 
00419   bool subjectIsPrefixed() const;
00420 
00422   QString msgId() const;
00423   void setMsgId(const QString& aStr);
00424   QString msgIdMD5() const;
00425 
00427   QString references() const;
00428   void setReferences(const QCString& aStr);
00429 
00431   QCString id() const;
00432 
00437   void setMsgSerNum(unsigned long newMsgSerNum = 0);
00438 
00443   QString headerField(const QCString& name) const;
00444 
00445   enum HeaderFieldType { Unstructured, Structured, Address };
00446 
00451   void setHeaderField( const QCString& name, const QString& value,
00452                        HeaderFieldType type = Unstructured,
00453                        bool prepend = false );
00454 
00456   QStringList headerFields( const QCString& name ) const;
00457 
00462   QCString rawHeaderField( const QCString & name ) const;
00463 
00467   QValueList<QCString> rawHeaderFields( const QCString & field ) const;
00468 
00470   static KMime::Types::AddressList splitAddrField( const QCString & str );
00471 
00475   KMime::Types::AddressList headerAddrField(const QCString& name) const;
00476   KMime::Types::AddrSpecList extractAddrSpecs( const QCString & headerNames ) const;
00477 
00479   void removeHeaderField(const QCString& name);
00480 
00482   void removeHeaderFields(const QCString& name);
00483 
00487   QCString typeStr() const;
00488   int type() const;
00489   void setTypeStr(const QCString& aStr);
00490   void setType(int aType);
00492   QCString subtypeStr() const;
00493   int subtype() const;
00494   void setSubtypeStr(const QCString& aStr);
00495   void setSubtype(int aSubtype);
00497   static void setDwMediaTypeParam( DwMediaType &mType,
00498                                    const QCString& attr,
00499                                    const QCString& val );
00501   void setContentTypeParam(const QCString& attr, const QCString& val);
00502 
00506   DwHeaders& headers() const;
00507 
00512   void setNeedsAssembly();
00513 
00518   void assembleIfNeeded();
00519 
00528   QCString contentTransferEncodingStr() const;
00529   int contentTransferEncoding( DwEntity *entity = 0 ) const;
00530   void setContentTransferEncodingStr( const QCString& cteString, DwEntity *entity = 0 );
00531   void setContentTransferEncoding( int cte, DwEntity *entity = 0 );
00532 
00537   QCString cteStr() const { return contentTransferEncodingStr(); }
00538   int cte( DwEntity *entity = 0 ) const { return contentTransferEncoding( entity ); }
00539   void setCteStr( const QCString& aStr, DwEntity *entity = 0 ) {
00540     setContentTransferEncodingStr( aStr, entity );
00541   }
00542   void setCte( int aCte, DwEntity *entity = 0 ) {
00543     setContentTransferEncoding( aCte, entity );
00544   }
00545 
00553   void setBodyFromUnicode( const QString & str, DwEntity *entity = 0 );
00554 
00557   QString bodyToUnicode(const QTextCodec* codec=0) const;
00558 
00560   QCString body() const;
00561 
00563   void setBody(const QCString& aStr);
00564   void setBody(const DwString& aStr);
00565   void setBody(const char* aStr); // avoid ambiguous calls
00566 
00568   void setMultiPartBody( const QCString & aStr );
00569 
00579   void setBodyEncoded( const QCString& aStr, DwEntity *entity = 0 );
00580   void setBodyEncodedBinary( const QByteArray& aStr, DwEntity *entity = 0 );
00581 
00585   static QValueList<int> determineAllowedCtes( const KMime::CharFreq& cf,
00586                                                bool allow8Bit,
00587                                                bool willBeSigned );
00588 
00602   void setBodyAndGuessCte( const QByteArray& aBuf, QValueList<int>& allowedCte,
00603                            bool allow8Bit = false,
00604                            bool willBeSigned = false,
00605                            DwEntity *entity = 0 );
00606 
00607   void setBodyAndGuessCte( const QCString& aBuf,
00608                            QValueList<int>& allowedCte,
00609                            bool allow8Bit = false,
00610                            bool willBeSigned = false,
00611                            DwEntity *entity = 0 );
00612 
00616   QCString bodyDecoded() const;
00617   QByteArray bodyDecodedBinary() const;
00618 
00621   int numBodyParts() const;
00622 
00625   DwBodyPart * findDwBodyPart( int type, int subtype ) const;
00626 
00629   DwBodyPart * findDwBodyPart( const QCString& type, const QCString&  subtype ) const;
00630 
00633   DwBodyPart* findDwBodyPart( DwBodyPart* part, const QString & partSpecifier );
00634 
00637   DwBodyPart * dwBodyPart( int aIdx ) const;
00638 
00641   int partNumber( DwBodyPart * aDwBodyPart ) const;
00642 
00645   DwBodyPart * getFirstDwBodyPart() const;
00646   DwMessage * getTopLevelPart() const { return mMsg; }
00647 
00651   static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
00652           bool withBody = true );
00653 
00657   void bodyPart(int aIdx, KMMessagePart* aPart) const;
00658 
00660   DwBodyPart* createDWBodyPart(const KMMessagePart* aPart);
00661 
00663   void addDwBodyPart(DwBodyPart * aDwPart);
00664 
00666   void addBodyPart(const KMMessagePart* aPart);
00667 
00669   void deleteBodyParts();
00670 
00675   bool deleteBodyPart( int partIndex );
00676 
00679   void setStatusFields();
00680 
00685   static QString generateMessageId( const QString& addr );
00686 
00692   static QCString html2source( const QCString & src );
00693 
00696   static QString encodeMailtoUrl( const QString& str );
00697 
00700   static QString decodeMailtoUrl( const QString& url );
00701 
00708   static QCString stripEmailAddr(const QCString& emailAddr);
00709 
00712   static QString stripEmailAddr(const QString& emailAddr);
00713 
00719   static QString quoteHtmlChars( const QString& str,
00720                                  bool removeLineBreaks = false );
00721 
00726   static QString emailAddrAsAnchor(const QString& emailAddr,
00727           bool stripped=true, const QString& cssStyle = QString::null, bool link = true);
00728 
00732   static QStringList stripAddressFromAddressList( const QString& address,
00733                                                   const QStringList& addresses );
00734 
00738   static QStringList stripMyAddressesFromAddressList( const QStringList& list );
00739 
00742   static bool addressIsInAddressList( const QString& address,
00743                                       const QStringList& addresses );
00744 
00748   static QString expandAliases( const QString& recipients );
00749 
00753   static QString guessEmailAddressFromLoginName( const QString& userName );
00754 
00761   static QString smartQuote( const QString &msg, int maxLineLength );
00762 
00764   static QCString defaultCharset();
00765 
00767   static const QStringList &preferredCharsets();
00768 
00770   QString replaceHeadersInString( const QString & s ) const;
00771 
00773   QCString charset() const;
00774 
00783   void setCharset( const QCString& charset, DwEntity *entity = 0 );
00784 
00786   const QTextCodec * codec() const;
00787 
00789   void setOverrideCodec( const QTextCodec* codec ) { mOverrideCodec = codec; }
00790 
00792   void setDecodeHTML(bool aDecodeHTML)
00793   { mDecodeHTML = aDecodeHTML; }
00794 
00797   static void readConfig();
00798 
00802   QCString getRefStr() const;
00803 
00805   off_t folderOffset() const { return mFolderOffset; }
00806   void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(true); } }
00807 
00809   QString fileName() const { return mFileName; }
00810   void setFileName(const QString& file) { if(mFileName != file) { mFileName=file; setDirty(true); } }
00811 
00815   size_t msgSize() const { return mMsgSize; }
00816   void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(true); } }
00817 
00820   size_t msgLength() const
00821     { return (mMsgLength) ? mMsgLength : mMsgSize; }
00822   void setMsgLength(size_t sz) { mMsgLength = sz; }
00823 
00825   size_t msgSizeServer() const;
00826   void setMsgSizeServer(size_t sz);
00827 
00829   ulong UID() const;
00830   void setUID(ulong uid);
00831 
00833   KMMsgStatus status() const { return mStatus; }
00835   void setStatus(const KMMsgStatus status, int idx = -1);
00836   void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
00837 
00839   void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00840 
00842   void setSignatureState(const KMMsgSignatureState, int idx = -1);
00843 
00844   void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00845 
00847   KMMsgEncryptionState encryptionState() const { return mEncryptionState; }
00848 
00850   KMMsgSignatureState signatureState() const { return mSignatureState; }
00851 
00852   KMMsgMDNSentState mdnSentState() const { return mMDNSentState; }
00853 
00855   void link(const KMMessage *aMsg, KMMsgStatus aStatus);
00858   void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *retStatus) const;
00859 
00861   QString formatString(const QString&) const;
00862 
00864   void updateBodyPart(const QString partSpecifier, const QByteArray & data);
00865 
00867   DwBodyPart* lastUpdatedPart() { return mLastUpdated; }
00868 
00870   bool isComplete() const { return mComplete; }
00872   void setComplete( bool v ) { mComplete = v; }
00873 
00875   bool readyToShow() const { return mReadyToShow; }
00877   void setReadyToShow( bool v ) { mReadyToShow = v; }
00878 
00879   void updateAttachmentState( DwBodyPart *part = 0 );
00880   void updateInvitationState();
00881 
00883   bool transferInProgress() const;
00885   void setTransferInProgress(bool value, bool force = false);
00886 
00891   QCString mboxMessageSeparator();
00892 
00908   QString asQuotedString( const QString & headerStr,
00909           const QString & indentStr,
00910           const QString & selection=QString::null,
00911           bool aStripSignature=true,
00912           bool allowDecryption=true) const;
00913 
00916   QString asPlainText( bool stripSignature, bool allowDecryption ) const;
00917 
00924   QString asPlainTextFromObjectTree( partNode *root, bool stripSignature,
00925                                      bool allowDecryption ) const;
00926 
00928   int getCursorPos() { return mCursorPos; };
00930   void setCursorPos(int pos) { mCursorPos = pos; };
00931 
00933   KMMsgInfo* msgInfo() { return mMsgInfo; }
00935   void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; }
00936 
00937   /* This is set in kmreaderwin if a message is being parsed to avoid
00938      other parts of kmail (e.g. kmheaders) destroying the message.
00939      Parsing can take longer and can be async (in case of gpg mails) */
00940   bool isBeingParsed() const { return mIsParsed; }
00941   void setIsBeingParsed( bool t ) { mIsParsed = t; }
00942 
00944   void deleteWhenUnused();
00945 
00946   DwBodyPart* findPart( int index );
00947 
00948 private:
00949 
00951   void init( DwMessage* aMsg = 0 );
00953   void assign( const KMMessage& other );
00954 
00955   DwBodyPart* findPartInternal( DwEntity* root, int index, int &accu );
00956 
00957   QString mDrafts;
00958   QString mTemplates;
00959   mutable DwMessage* mMsg;
00960   mutable bool mNeedsAssembly :1;
00961   bool mDecodeHTML :1;
00962   bool mReadyToShow :1;
00963   bool mComplete :1;
00964   bool mIsParsed : 1;
00965   static const KMail::HeaderStrategy * sHeaderStrategy;
00966   static QString sForwardStr;
00967   const QTextCodec * mOverrideCodec;
00968 
00969   QString mFileName;
00970   off_t mFolderOffset;
00971   size_t mMsgSize, mMsgLength;
00972   time_t mDate;
00973   KMMsgEncryptionState mEncryptionState;
00974   KMMsgSignatureState mSignatureState;
00975   KMMsgMDNSentState mMDNSentState;
00976   KMMessage* mUnencryptedMsg;
00977   DwBodyPart* mLastUpdated;
00978   int mCursorPos;
00979   KMMsgInfo* mMsgInfo; // used to remember the KMMsgInfo object this KMMessage replaced in the KMMsgList
00980   static QValueList<KMMessage*> sPendingDeletes;
00981 };
00982 
00983 
00984 #endif /*kmmessage_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys