• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kmail

kmmessage.h

Go to the documentation of this file.
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 <sys/types.h>
00012 
00013 #include <mimelib/string.h>
00014 #include "kmmsgbase.h"
00015 #include "isubject.h"
00016 
00017 #include <kmime/kmime_mdn.h>
00018 
00019 #include<kpimutils/email.h>
00020 
00021 #include <QList>
00022 #include <QByteArray>
00023 
00024 // Forward declarations
00025 class QStringList;
00026 class QString;
00027 class QTextCodec;
00028 
00029 class KMFolder;
00030 class KMMessagePart;
00031 class KMMsgInfo;
00032 class KMForwardCommand;
00033 
00034 class DwMessage;
00035 class DwBodyPart;
00036 class DwMediaType;
00037 class DwHeaders;
00038 
00039 class partNode;
00040 
00041 namespace KMime {
00042   class CharFreq;
00043   namespace Types {
00044     struct AddrSpec;
00045     struct Address;
00046     typedef QList<Address> AddressList;
00047     typedef QList<AddrSpec> AddrSpecList;
00048   }
00049 }
00050 
00051 namespace KMail {
00052   class HeaderStrategy;
00053 }
00054 
00055 
00056 // Real code starts here :)
00057 
00058 namespace KMail {
00062   enum ReplyStrategy {
00063     ReplySmart = 0,    //< Attempt to automatically guess the best recipient for the reply
00064     ReplyAuthor,       //< Reply to the author of the message (possibly NOT the mailing list, if any)
00065     ReplyList,         //< Reply to the mailing list (and not the author of the message)
00066     ReplyAll,          //< Reply to author and all the recipients in CC
00067     ReplyNone          //< Don't set reply addresses: they will be set manually
00068   };
00069 }
00070 
00072 class KMMessage: public KMMsgBase, public KMail::ISubject
00073 {
00074   friend class ::KMForwardCommand;    // needed for MIME Digest forward
00075 
00076 public:
00077   // promote some of KMMsgBase's methods to public:
00078   using KMMsgBase::parent;
00079   using KMMsgBase::setParent;
00080   using KMMsgBase::enableUndo; // KMFolder
00081   using KMMsgBase::setEnableUndo; // dto.
00082   using KMMsgBase::setEncryptionStateChar; // KMAcct*
00083   using KMMsgBase::setSignatureStateChar; // dto.
00084 
00086   KMMessage(KMFolder* parent=0);
00087 
00091   KMMessage(DwMessage*);
00092 
00094   KMMessage(KMMsgInfo& msgInfo);
00095 
00097   KMMessage( const KMMessage& other );
00098 
00099 #if 0 // currently unused
00100 
00101   const KMMessage& operator=( const KMMessage& other ) {
00102     if( &other == this )
00103       return *this;
00104     assign( other );
00105     return *this;
00106   }
00107 #endif
00108 
00110   virtual ~KMMessage();
00111 
00113   KMMsgBase & toMsgBase() { return *this; }
00114   const KMMsgBase & toMsgBase() const { return *this; }
00115 
00117   bool isMessage() const;
00118 
00122   bool isUrgent() const;
00123 
00130   void setUnencryptedMsg( KMMessage* unencrypted );
00131 
00133   bool hasUnencryptedMsg() const { return 0 != mUnencryptedMsg; }
00134 
00136   KMMessage* unencryptedMsg() const { return mUnencryptedMsg; }
00137 
00143   KMMessage* takeUnencryptedMsg()
00144   {
00145     KMMessage* ret = mUnencryptedMsg;
00146     mUnencryptedMsg = 0;
00147     return ret;
00148   }
00149 
00151   void del() { setStatus( MessageStatus::statusDeleted() ); }
00152 
00154   void undel() { setStatus( MessageStatus::statusOld() ); }
00155 
00157   void touch() { setStatus( MessageStatus::statusOld() ); }
00158 
00162   KMMessage* createReply( KMail::ReplyStrategy replyStrategy = KMail::ReplySmart,
00163                           const QString &selection=QString(), bool noQuote=false,
00164                           bool allowDecryption=true, bool selectionIsBody=false,
00165                           const QString &tmpl = QString() );
00166 
00167 
00175   KMMessage* createRedirect( const QString &toStr );
00176 
00180   KMMessage* createForward( const QString &tmpl = QString() );
00181 
00185   KMMessage* createDeliveryReceipt() const;
00186 
00200   KMMessage* createMDN( KMime::MDN::ActionMode a,
00201           KMime::MDN::DispositionType d,
00202           bool allowGUI=false,
00203           QList<KMime::MDN::DispositionModifier> m=QList<KMime::MDN::DispositionModifier>() );
00204 
00206   void sanitizeHeaders( const QStringList& whiteList = QStringList() );
00207 
00209   void fromDwString(const DwString& str, bool setStatus=false);
00210   void fromString( const QByteArray & ba, bool setStatus=false );
00211 
00216   const DwString& asDwString() const;
00217   const DwMessage *asDwMessage();
00218 
00226   QByteArray asString() const;
00227 
00232   QByteArray asSendableString() const;
00233 
00238   QByteArray headerAsSendableString() const;
00239 
00243   void removePrivateHeaderFields();
00244 
00246   DwMediaType& dwContentType();
00247 
00249   QString headerAsString() const;
00250 
00255   void parseTextStringFromDwPart( partNode * root,
00256                                           QByteArray& parsedString,
00257                                           const QTextCodec*& codec,
00258                                           bool& isHTML ) const;
00259 
00263   void initHeader(uint identity=0);
00264 
00267   void initFromMessage(const KMMessage *msg, bool idHeaders = true);
00268 
00274   uint identityUoid() const;
00275 
00278   void applyIdentity( uint id );
00279 
00282   void cleanupHeader();
00283 
00289   void setAutomaticFields(bool isMultipart=false);
00290 
00292   QString dateStr() const;
00295   QByteArray dateShortStr() const;
00296   QString dateIsoStr() const;
00297   time_t date() const;
00298   void setDate(const QByteArray& str);
00299   void setDate(time_t aUnixTime);
00300 
00302   void setDateToday();
00303 
00305   QString to() const;
00306   void setTo(const QString& aStr);
00307   QString toStrip() const;
00308 
00310   QString replyTo() const;
00311   void setReplyTo(const QString& aStr);
00312   void setReplyTo(KMMessage*);
00313 
00315   QString cc() const;
00316   void setCc(const QString& aStr);
00317   QString ccStrip() const;
00318 
00320   QString bcc() const;
00321   void setBcc(const QString& aStr);
00322 
00324   QString fcc() const;
00325   void setFcc(const QString& aStr);
00326 
00328   QString drafts() const { return mDrafts; }
00329   void setDrafts(const QString& aStr);
00330 
00332   QString templates() const { return mTemplates; }
00333   void setTemplates(const QString& aStr);
00334 
00336   QString from() const;
00337   void setFrom(const QString& aStr);
00338   QString fromStrip() const;
00339 
00342   QString sender() const;
00343 
00347   QString who() const;
00348 
00350   QString subject() const;
00351   void setSubject(const QString& aStr);
00352 
00354   void initStrippedSubjectMD5() {}
00355 
00357   QString xmark() const;
00358   void setXMark(const QString& aStr);
00359 
00361   QString replyToId() const;
00362   void setReplyToId(const QString& aStr);
00363   QString replyToIdMD5() const;
00364 
00379   QString replyToAuxIdMD5() const;
00380 
00385   QString strippedSubjectMD5() const;
00386 
00391   QString subjectMD5() const;
00392 
00394   bool subjectIsPrefixed() const;
00395 
00397   QString msgId() const;
00398   void setMsgId(const QString& aStr);
00399   QString msgIdMD5() const;
00400 
00402   QString references() const;
00403   void setReferences(const QByteArray& aStr);
00404 
00406   QByteArray id() const;
00407 
00412   void setMsgSerNum(unsigned long newMsgSerNum = 0);
00413 
00418   QString headerField(const QByteArray& name) const;
00419 
00420   enum HeaderFieldType { Unstructured, Structured, Address };
00421 
00426   void setHeaderField( const QByteArray& name, const QString& value,
00427                        HeaderFieldType type = Unstructured,
00428                        bool prepend = false );
00429 
00431   QStringList headerFields( const QByteArray& name ) const;
00432 
00437   QByteArray rawHeaderField( const QByteArray & name ) const;
00438 
00442   QList<QByteArray> rawHeaderFields( const QByteArray & field ) const;
00443 
00445   static KMime::Types::AddressList splitAddrField( const QByteArray & str );
00446 
00450   KMime::Types::AddressList headerAddrField(const QByteArray& name) const;
00451   KMime::Types::AddrSpecList extractAddrSpecs( const QByteArray & headerNames ) const;
00452 
00454   void removeHeaderField(const QByteArray& name);
00455 
00457   void removeHeaderFields(const QByteArray& name);
00458 
00462   QByteArray typeStr() const;
00463   int type() const;
00464   void setTypeStr(const QByteArray& aStr);
00465   void setType(int aType);
00467   QByteArray subtypeStr() const;
00468   int subtype() const;
00469   void setSubtypeStr(const QByteArray& aStr);
00470   void setSubtype(int aSubtype);
00472   static void setDwMediaTypeParam( DwMediaType &mType,
00473                                    const QByteArray& attr,
00474                                    const QByteArray& val );
00476   void setContentTypeParam(const QByteArray& attr, const QByteArray& val);
00477 
00481   DwHeaders& headers() const;
00482 
00487   void setNeedsAssembly();
00488 
00492   QByteArray contentTransferEncodingStr() const;
00493   int  contentTransferEncoding() const;
00494   void setContentTransferEncodingStr(const QByteArray& aStr);
00495   void setContentTransferEncoding(int aCte);
00496 
00499   QByteArray cteStr() const { return contentTransferEncodingStr(); }
00500   int cte() const { return contentTransferEncoding(); }
00501   void setCteStr(const QByteArray& aStr) { setContentTransferEncodingStr(aStr); }
00502   void setCte(int aCte) { setContentTransferEncoding(aCte); }
00503 
00507   void setBodyFromUnicode( const QString & str );
00508 
00511   QString bodyToUnicode(const QTextCodec* codec=0) const;
00512 
00514   QByteArray body() const;
00515 
00517   void setBody(const QByteArray& aStr);
00518 
00520   void setMultiPartBody( const QByteArray & aStr );
00521 
00525   void setBodyEncoded(const QByteArray& aStr);
00526   void setBodyEncodedBinary(const QByteArray& aStr);
00527 
00531   static QList<int> determineAllowedCtes( const KMime::CharFreq& cf,
00532                                                bool allow8Bit,
00533                                                bool willBeSigned );
00534 
00544   void setBodyAndGuessCte( const QByteArray& aBuf,
00545                                  QList<int>& allowedCte,
00546                                  bool allow8Bit = false,
00547                                  bool willBeSigned = false );
00548 
00552   QByteArray bodyDecoded() const;
00553   QByteArray bodyDecodedBinary() const;
00554 
00557   int numBodyParts() const;
00558 
00561   DwBodyPart * findDwBodyPart( int type, int subtype ) const;
00562 
00565   DwBodyPart * findDwBodyPart( const QByteArray& type, const QByteArray&  subtype ) const;
00566 
00569   DwBodyPart* findDwBodyPart( DwBodyPart* part, const QString & partSpecifier );
00570 
00573   DwBodyPart * dwBodyPart( int aIdx ) const;
00574 
00577   int partNumber( DwBodyPart * aDwBodyPart ) const;
00578 
00581   DwBodyPart * getFirstDwBodyPart() const;
00582   DwMessage * getTopLevelPart() const { return mMsg; }
00583 
00587   static void bodyPart(DwBodyPart* aDwBodyPart, KMMessagePart* aPart,
00588           bool withBody = true );
00589 
00593   void bodyPart(int aIdx, KMMessagePart* aPart) const;
00594 
00596   DwBodyPart* createDWBodyPart(const KMMessagePart* aPart);
00597 
00599   void addDwBodyPart(DwBodyPart * aDwPart);
00600 
00602   void addBodyPart(const KMMessagePart* aPart);
00603 
00605   void deleteBodyParts();
00606 
00609   void setStatusFields();
00610 
00615   static QString generateMessageId( const QString& addr );
00616 
00622   static QByteArray html2source( const QByteArray & src );
00623 
00626   static QString encodeMailtoUrl( const QString& str );
00627 
00630   static QString decodeMailtoUrl( const QString& url );
00631 
00638   static QByteArray stripEmailAddr(const QByteArray& emailAddr);
00639 
00642   static QString stripEmailAddr(const QString& emailAddr);
00643 
00649   static QString quoteHtmlChars( const QString& str,
00650                                  bool removeLineBreaks = false );
00651 
00656   static QString emailAddrAsAnchor(const QString& emailAddr,
00657           bool stripped = true, const QString& cssStyle = QString(), bool link = true);
00658 
00662   static QStringList stripAddressFromAddressList( const QString& address,
00663                                                   const QStringList& addresses );
00664 
00668   static QStringList stripMyAddressesFromAddressList( const QStringList& list );
00669 
00672   static bool addressIsInAddressList( const QString& address,
00673                                       const QStringList& addresses );
00674 
00678   static QString expandAliases( const QString& recipients );
00679 
00683   static QString guessEmailAddressFromLoginName( const QString& userName );
00684 
00691   static QString smartQuote( const QString &msg, int maxLineLength );
00692 
00694   static QByteArray defaultCharset();
00695 
00697   static const QStringList &preferredCharsets();
00698 
00700   QString replaceHeadersInString( const QString & s ) const;
00701 
00703   QByteArray charset() const;
00704 
00706   void setCharset(const QByteArray& aStr);
00707 
00709   const QTextCodec * codec() const;
00710 
00712   void setOverrideCodec( const QTextCodec* codec ) { mOverrideCodec = codec; }
00713 
00715   void setDecodeHTML(bool aDecodeHTML)
00716   { mDecodeHTML = aDecodeHTML; }
00717 
00720   static void readConfig();
00721 
00725   QByteArray getRefStr() const;
00726 
00728   off_t folderOffset() const { return mFolderOffset; }
00729   void setFolderOffset(off_t offs) { if(mFolderOffset != offs) { mFolderOffset=offs; setDirty(true); } }
00730 
00732   QString fileName() const { return mFileName; }
00733   void setFileName(const QString& file) { if(mFileName != file) { mFileName=file; setDirty(true); } }
00734 
00738   size_t msgSize() const { return mMsgSize; }
00739   void setMsgSize(size_t sz) { if(mMsgSize != sz) { mMsgSize = sz; setDirty(true); } }
00740 
00743   size_t msgLength() const
00744     { return (mMsgLength) ? mMsgLength : mMsgSize; }
00745   void setMsgLength(size_t sz) { mMsgLength = sz; }
00746 
00748   size_t msgSizeServer() const;
00749   void setMsgSizeServer(size_t sz);
00750 
00752   ulong UID() const;
00753   void setUID(ulong uid);
00754 
00756   MessageStatus& status() const { return mStatus; }
00758   void setStatus(const MessageStatus& status, int idx = -1);
00759   void setStatus(const char* s1, const char* s2=0) { KMMsgBase::setStatus(s1, s2); }
00760 
00761   virtual QString tagString( void ) const;
00762   virtual KMMessageTagList *tagList( void ) const;
00763 
00765   void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00766 
00768   void setSignatureState(const KMMsgSignatureState, int idx = -1);
00769 
00770   void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00771 
00773   KMMsgEncryptionState encryptionState() const { return mEncryptionState; }
00774 
00776   KMMsgSignatureState signatureState() const { return mSignatureState; }
00777 
00778   KMMsgMDNSentState mdnSentState() const { return mMDNSentState; }
00779 
00781   void link(const KMMessage *aMsg, const MessageStatus& aStatus);
00784   void getLink(int n, ulong *retMsgSerNum, MessageStatus& retStatus) const;
00785 
00787   QString formatString(const QString&) const;
00788 
00790   void updateBodyPart(const QString partSpecifier, const QByteArray & data);
00791 
00793   DwBodyPart* lastUpdatedPart() { return mLastUpdated; }
00794 
00796   bool isComplete() const { return mComplete; }
00798   void setComplete( bool v ) { mComplete = v; }
00799 
00801   bool readyToShow() const { return mReadyToShow; }
00803   void setReadyToShow( bool v ) { mReadyToShow = v; }
00804 
00805   void updateAttachmentState(DwBodyPart * part = 0);
00806 
00808   bool transferInProgress() const;
00810   void setTransferInProgress(bool value, bool force = false);
00811 
00816   QByteArray mboxMessageSeparator();
00817 
00827   QString asQuotedString( const QString & indentStr,
00828           const QString & selection=QString(),
00829           bool aStripSignature=true,
00830           bool allowDecryption=true) const;
00831 
00834   QString asPlainText( bool stripSignature, bool allowDecryption ) const;
00835 
00837   int getCursorPos() { return mCursorPos; }
00839   void setCursorPos(int pos) { mCursorPos = pos; }
00840 
00841   /* This is set in kmreaderwin if a message is being parsed to avoid
00842      other parts of kmail (e.g. kmheaders) destroying the message.
00843      Parsing can take longer and can be async (in case of gpg mails) */
00844   bool isBeingParsed() const { return mIsParsed; }
00845   void setIsBeingParsed( bool t ) { mIsParsed = t; }
00846 
00848   void deleteWhenUnused();
00849 
00850 private:
00851 
00853   void init( DwMessage* aMsg = 0 );
00855   void assign( const KMMessage& other );
00856 
00857   QString mDrafts;
00858   QString mTemplates;
00859   mutable DwMessage* mMsg;
00860   mutable bool       mNeedsAssembly :1;
00861   bool mDecodeHTML :1;
00862   bool mReadyToShow :1;
00863   bool mComplete :1;
00864   bool mIsParsed :1;
00865   const QTextCodec * mOverrideCodec;
00866 
00867   QString mFileName;
00868   off_t mFolderOffset;
00869   size_t mMsgSize, mMsgLength;
00870   time_t mDate;
00871   KMMsgEncryptionState mEncryptionState;
00872   KMMsgSignatureState mSignatureState;
00873   KMMsgMDNSentState mMDNSentState;
00874   KMMessage* mUnencryptedMsg;
00875   DwBodyPart* mLastUpdated;
00876   int mCursorPos;
00877 };
00878 
00879 
00880 #endif /*kmmessage_h*/

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages