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, 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 
00515   QCString contentTransferEncodingStr() const;
00516   int contentTransferEncoding( DwEntity *entity = 0 ) const;
00517   void setContentTransferEncodingStr( const QCString& cteString, DwEntity *entity = 0 );
00518   void setContentTransferEncoding( int cte, DwEntity *entity = 0 );
00519 
00524   QCString cteStr() const { return contentTransferEncodingStr(); }
00525   int cte( DwEntity *entity = 0 ) const { return contentTransferEncoding( entity ); }
00526   void setCteStr( const QCString& aStr, DwEntity *entity = 0 ) {
00527     setContentTransferEncodingStr( aStr, entity );
00528   }
00529   void setCte( int aCte, DwEntity *entity = 0 ) {
00530     setContentTransferEncoding( aCte, entity );
00531   }
00532 
00540   void setBodyFromUnicode( const QString & str, DwEntity *entity = 0 );
00541 
00544   QString bodyToUnicode(const QTextCodec* codec=0) const;
00545 
00547   QCString body() const;
00548 
00550   void setBody(const QCString& aStr);
00551   void setBody(const DwString& aStr);
00552   void setBody(const char* aStr); // avoid ambiguous calls
00553 
00555   void setMultiPartBody( const QCString & aStr );
00556 
00566   void setBodyEncoded( const QCString& aStr, DwEntity *entity = 0 );
00567   void setBodyEncodedBinary( const QByteArray& aStr, DwEntity *entity = 0 );
00568 
00572   static QValueList<int> determineAllowedCtes( const KMime::CharFreq& cf,
00573                                                bool allow8Bit,
00574                                                bool willBeSigned );
00575 
00589   void setBodyAndGuessCte( const QByteArray& aBuf, QValueList<int>& allowedCte,
00590                            bool allow8Bit = false,
00591                            bool willBeSigned = false,
00592                            DwEntity *entity = 0 );
00593 
00594   void setBodyAndGuessCte( const QCString& aBuf,
00595                            QValueList<int>& allowedCte,
00596                            bool allow8Bit = false,
00597                            bool willBeSigned = false, 
00598                            DwEntity *entity = 0 );
00599 
00603   QCString bodyDecoded() const;
00604   QByteArray bodyDecodedBinary() const;
00605 
00608   int numBodyParts() const;
00609 
00612   DwBodyPart * findDwBodyPart( int type, int subtype ) const;
00613 
00616   DwBodyPart * findDwBodyPart( const QCString& type, const QCString&  subtype ) const;
00617 
00620   DwBodyPart* findDwBodyPart( DwBodyPart* part, const QString & partSpecifier );
00621 
00624   DwBodyPart * dwBodyPart( int aIdx ) const;
00625 
00628   int partNumber( DwBodyPart * aDwBodyPart ) const;
00629 
00632   DwBodyPart * getFirstDwBodyPart() const;
00633   DwMessage * getTopLevelPart() const { return mMsg; }
00634 
00638   static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
00639           bool withBody = true );
00640 
00644   void bodyPart(int aIdx, KMMessagePart* aPart) const;
00645 
00647   DwBodyPart* createDWBodyPart(const KMMessagePart* aPart);
00648 
00650   void addDwBodyPart(DwBodyPart * aDwPart);
00651 
00653   void addBodyPart(const KMMessagePart* aPart);
00654 
00656   void deleteBodyParts();
00657 
00660   void setStatusFields();
00661 
00666   static QString generateMessageId( const QString& addr );
00667 
00673   static QCString html2source( const QCString & src );
00674 
00677   static QString encodeMailtoUrl( const QString& str );
00678 
00681   static QString decodeMailtoUrl( const QString& url );
00682 
00689   static QCString stripEmailAddr(const QCString& emailAddr);
00690 
00693   static QString stripEmailAddr(const QString& emailAddr);
00694 
00700   static QString quoteHtmlChars( const QString& str,
00701                                  bool removeLineBreaks = false );
00702 
00707   static QString emailAddrAsAnchor(const QString& emailAddr,
00708           bool stripped=true, const QString& cssStyle = QString::null, bool link = true);
00709 
00713   static QStringList stripAddressFromAddressList( const QString& address,
00714                                                   const QStringList& addresses );
00715 
00719   static QStringList stripMyAddressesFromAddressList( const QStringList& list );
00720 
00723   static bool addressIsInAddressList( const QString& address,
00724                                       const QStringList& addresses );
00725 
00729   static QString expandAliases( const QString& recipients );
00730 
00734   static QString guessEmailAddressFromLoginName( const QString& userName );
00735 
00742   static QString smartQuote( const QString &msg, int maxLineLength );
00743 
00745   static QCString defaultCharset();
00746 
00748   static const QStringList &preferredCharsets();
00749 
00751   QString replaceHeadersInString( const QString & s ) const;
00752 
00754   QCString charset() const;
00755 
00764   void setCharset( const QCString& charset, DwEntity *entity = 0 );
00765 
00767   const QTextCodec * codec() const;
00768 
00770   void setOverrideCodec( const QTextCodec* codec ) { mOverrideCodec = codec; }
00771 
00773   void setDecodeHTML(bool aDecodeHTML)
00774   { mDecodeHTML = aDecodeHTML; }
00775 
00778   static void readConfig();
00779 
00783   QCString getRefStr() const;
00784 
00786   off_t folderOffset() const { return mFolderOffset; }
00787   void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(true); } }
00788 
00790   QString fileName() const { return mFileName; }
00791   void setFileName(const QString& file) { if(mFileName != file) { mFileName=file; setDirty(true); } }
00792 
00796   size_t msgSize() const { return mMsgSize; }
00797   void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(true); } }
00798 
00801   size_t msgLength() const
00802     { return (mMsgLength) ? mMsgLength : mMsgSize; }
00803   void setMsgLength(size_t sz) { mMsgLength = sz; }
00804 
00806   size_t msgSizeServer() const;
00807   void setMsgSizeServer(size_t sz);
00808 
00810   ulong UID() const;
00811   void setUID(ulong uid);
00812 
00814   KMMsgStatus status() const { return mStatus; }
00816   void setStatus(const KMMsgStatus status, int idx = -1);
00817   void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
00818 
00820   void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00821 
00823   void setSignatureState(const KMMsgSignatureState, int idx = -1);
00824 
00825   void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00826 
00828   KMMsgEncryptionState encryptionState() const { return mEncryptionState; }
00829 
00831   KMMsgSignatureState signatureState() const { return mSignatureState; }
00832 
00833   KMMsgMDNSentState mdnSentState() const { return mMDNSentState; }
00834 
00836   void link(const KMMessage *aMsg, KMMsgStatus aStatus);
00839   void getLink(int n, ulong *retMsgSerNum, KMMsgStatus *retStatus) const;
00840 
00842   QString formatString(const QString&) const;
00843 
00845   void updateBodyPart(const QString partSpecifier, const QByteArray & data);
00846 
00848   DwBodyPart* lastUpdatedPart() { return mLastUpdated; }
00849 
00851   bool isComplete() const { return mComplete; }
00853   void setComplete( bool v ) { mComplete = v; }
00854 
00856   bool readyToShow() const { return mReadyToShow; }
00858   void setReadyToShow( bool v ) { mReadyToShow = v; }
00859 
00860   void updateAttachmentState(DwBodyPart * part = 0);
00861 
00863   bool transferInProgress() const;
00865   void setTransferInProgress(bool value, bool force = false);
00866 
00871   QCString mboxMessageSeparator();
00872 
00888   QString asQuotedString( const QString & headerStr,
00889           const QString & indentStr,
00890           const QString & selection=QString::null,
00891           bool aStripSignature=true,
00892           bool allowDecryption=true) const;
00893 
00896   QString asPlainText( bool stripSignature, bool allowDecryption ) const;
00897 
00899   int getCursorPos() { return mCursorPos; };
00901   void setCursorPos(int pos) { mCursorPos = pos; };
00902 
00904   KMMsgInfo* msgInfo() { return mMsgInfo; }
00906   void setMsgInfo( KMMsgInfo* msgInfo ) { mMsgInfo = msgInfo; }
00907 
00908   /* This is set in kmreaderwin if a message is being parsed to avoid
00909      other parts of kmail (e.g. kmheaders) destroying the message.
00910      Parsing can take longer and can be async (in case of gpg mails) */
00911   bool isBeingParsed() const { return mIsParsed; }
00912   void setIsBeingParsed( bool t ) { mIsParsed = t; }
00913 
00915   void deleteWhenUnused();
00916 
00917 private:
00918 
00920   void init( DwMessage* aMsg = 0 );
00922   void assign( const KMMessage& other );
00923 
00924   QString mDrafts;
00925   QString mTemplates;
00926   mutable DwMessage* mMsg;
00927   mutable bool       mNeedsAssembly :1;
00928   bool mDecodeHTML :1;
00929   bool mReadyToShow :1;
00930   bool mComplete :1;
00931   bool mIsParsed : 1;
00932   static const KMail::HeaderStrategy * sHeaderStrategy;
00933   static QString sForwardStr;
00934   const QTextCodec * mOverrideCodec;
00935 
00936   QString mFileName;
00937   off_t mFolderOffset;
00938   size_t mMsgSize, mMsgLength;
00939   time_t mDate;
00940   KMMsgEncryptionState mEncryptionState;
00941   KMMsgSignatureState mSignatureState;
00942   KMMsgMDNSentState mMDNSentState;
00943   KMMessage* mUnencryptedMsg;
00944   DwBodyPart* mLastUpdated;
00945   int mCursorPos;
00946   KMMsgInfo* mMsgInfo; // used to remember the KMMsgInfo object this KMMessage replaced in the KMMsgList
00947   static QValueList<KMMessage*> sPendingDeletes;
00948 };
00949 
00950 
00951 #endif /*kmmessage_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys