kmail Library API Documentation

kmmsgbase.h

00001 /* Virtual base class for messages and message infos
00002  * Author: Stefan Taferner <taferner@kde.org>
00003  * This code is under GPL.
00004  */
00005 #ifndef kmmsgbase_h
00006 #define kmmsgbase_h
00007 
00008 // for large file support flags
00009 #include <config.h>
00010 #include <sys/types.h>
00011 #include <qstring.h>
00012 #include <time.h>
00013 
00014 class QCString;
00015 class QStringList;
00016 class QTextCodec;
00017 class KMFolder;
00018 class KMFolderIndex;
00019 
00021 enum MsgStatus
00022 {
00023     KMMsgStatusUnknown =           0x00000000,
00024     KMMsgStatusNew =               0x00000001,
00025     KMMsgStatusUnread =            0x00000002,
00026     KMMsgStatusRead =              0x00000004,
00027     KMMsgStatusOld =               0x00000008,
00028     KMMsgStatusDeleted =           0x00000010,
00029     KMMsgStatusReplied =           0x00000020,
00030     KMMsgStatusForwarded =         0x00000040,
00031     KMMsgStatusQueued =            0x00000080,
00032     KMMsgStatusSent =              0x00000100,
00033     KMMsgStatusFlag =              0x00000200, // important
00034     KMMsgStatusWatched =           0x00000400,
00035     KMMsgStatusIgnored =           0x00000800,
00036     KMMsgStatusTodo =              0x00001000,
00037     KMMsgStatusSpam =              0x00002000,
00038     KMMsgStatusHam =               0x00004000,
00039     KMMsgStatusHasAttach =         0x00008000,
00040     KMMsgStatusHasNoAttach =       0x00010000
00041 };
00042 
00043 typedef uint KMMsgStatus;
00044 
00048 typedef enum
00049 {
00050     KMLegacyMsgStatusUnknown=' ',
00051     KMLegacyMsgStatusNew='N',
00052     KMLegacyMsgStatusUnread='U',
00053     KMLegacyMsgStatusRead='R',
00054     KMLegacyMsgStatusOld='O',
00055     KMLegacyMsgStatusDeleted='D',
00056     KMLegacyMsgStatusReplied='A',
00057     KMLegacyMsgStatusForwarded='F',
00058     KMLegacyMsgStatusQueued='Q',
00059     KMLegacyMsgStatusSent='S',
00060     KMLegacyMsgStatusFlag='G'
00061 } KMLegacyMsgStatus;
00062 
00063 
00064 
00066 typedef enum
00067 {
00068     KMMsgEncryptionStateUnknown=' ',
00069     KMMsgNotEncrypted='N',
00070     KMMsgPartiallyEncrypted='P',
00071     KMMsgFullyEncrypted='F',
00072     KMMsgEncryptionProblematic='X'
00073 } KMMsgEncryptionState;
00074 
00076 typedef enum
00077 {
00078     KMMsgSignatureStateUnknown=' ',
00079     KMMsgNotSigned='N',
00080     KMMsgPartiallySigned='P',
00081     KMMsgFullySigned='F',
00082     KMMsgSignatureProblematic='X'
00083 } KMMsgSignatureState;
00084 
00086 typedef enum
00087 {
00088     KMMsgMDNStateUnknown = ' ',
00089     KMMsgMDNNone = 'N',
00090     KMMsgMDNIgnore = 'I',
00091     KMMsgMDNDisplayed = 'R',
00092     KMMsgMDNDeleted = 'D',
00093     KMMsgMDNDispatched = 'F',
00094     KMMsgMDNProcessed = 'P',
00095     KMMsgMDNDenied = 'X',
00096     KMMsgMDNFailed = 'E'
00097 } KMMsgMDNSentState;
00098 
00100 typedef enum
00101 {
00102     KMMsgDnDActionMOVE=0,
00103     KMMsgDnDActionCOPY=1,
00104     KMMsgDnDActionASK=2
00105 } KMMsgDnDAction;
00106 
00108 typedef enum
00109 {
00110   KMMsgHasAttachment,
00111   KMMsgHasNoAttachment,
00112   KMMsgAttachmentUnknown
00113 } KMMsgAttachmentState;
00114 
00115 
00116 class KMMsgBase
00117 {
00118 public:
00119   KMMsgBase(KMFolder* p=0);
00120   virtual ~KMMsgBase();
00121 
00123   KMFolderIndex* storage() const;
00124 
00126   KMFolder* parent() const { return mParent; }
00127 
00129   void setParent(KMFolder* p) { mParent = p; }
00130 
00132   static QCString statusToStr(const KMMsgStatus status);
00133 
00135   QString statusToSortRank();
00136 
00138   virtual bool isMessage(void) const;
00139 
00141   virtual bool isUnread(void) const;
00142 
00144   virtual bool isNew(void) const;
00145 
00147   virtual bool isOfUnknownStatus(void) const;
00148 
00150   virtual bool isOld(void) const;
00151 
00153   virtual bool isRead(void) const;
00154 
00156   virtual bool isDeleted(void) const;
00157 
00159   virtual bool isReplied(void) const;
00160 
00162   virtual bool isForwarded(void) const;
00163 
00165   virtual bool isQueued(void) const;
00166 
00168   virtual bool isSent(void) const;
00169 
00171   virtual bool isImportant(void) const;
00172 
00174   virtual bool isWatched(void) const;
00175 
00177   virtual bool isIgnored(void) const;
00178 
00180   virtual bool isSpam(void) const;
00181 
00183   virtual bool isHam(void) const;
00184 
00186   virtual bool isTodo(void) const;
00187 
00188 
00190   virtual KMMsgStatus status(void) const = 0;
00191 
00194   virtual void setStatus(const KMMsgStatus status, int idx = -1);
00195   virtual void toggleStatus(const KMMsgStatus status, int idx = -1);
00196   virtual void setStatus(const char* statusField, const char* xstatusField=0);
00197 
00199   virtual KMMsgEncryptionState encryptionState() const = 0;
00200 
00202   virtual KMMsgSignatureState signatureState() const = 0;
00203 
00205   virtual KMMsgMDNSentState mdnSentState() const = 0;
00206 
00208   virtual void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00209 
00213   virtual void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00214 
00218   virtual void setSignatureState(const KMMsgSignatureState, int idx = -1);
00219 
00223   virtual void setEncryptionStateChar( QChar status, int idx = -1 );
00224 
00228   virtual void setSignatureStateChar( QChar status, int idx = -1 );
00229 
00231   virtual QString subject(void) const = 0;
00232   virtual QString fromStrip(void) const = 0;
00233   virtual QString toStrip(void) const = 0;
00234   virtual QString replyToIdMD5(void) const = 0;
00235   virtual QString msgIdMD5(void) const = 0;
00236   virtual QString replyToAuxIdMD5() const = 0;
00237   virtual QString strippedSubjectMD5() const = 0;
00238   virtual bool subjectIsPrefixed() const = 0;
00239   virtual time_t date(void) const = 0;
00240   virtual QString dateStr(void) const;
00241   virtual QString xmark(void) const = 0;
00242 
00244   virtual void setDate(const QCString &aStrDate);
00245   virtual void setDate(time_t aUnixTime) = 0;
00246 
00248   virtual bool dirty(void) const { return mDirty; }
00249 
00251   void setDirty(bool b) { mDirty = b; }
00252 
00254   virtual void setSubject(const QString&) = 0;
00255   virtual void setXMark(const QString&) = 0;
00256 
00258   virtual void initStrippedSubjectMD5() = 0;
00259 
00261   const uchar *asIndexString(int &len) const;
00262 
00264   virtual off_t folderOffset(void) const = 0;
00265   virtual void setFolderOffset(off_t offs) = 0;
00266 
00268   virtual QString fileName(void) const = 0;
00269   virtual void setFileName(const QString& filename) = 0;
00270 
00272   virtual size_t msgSize(void) const = 0;
00273   virtual void setMsgSize(size_t sz) = 0;
00274 
00276   virtual size_t msgSizeServer(void) const = 0;
00277   virtual void setMsgSizeServer(size_t sz) = 0;
00278 
00280   virtual ulong UID(void) const = 0;
00281   virtual void setUID(ulong uid) = 0;
00282 
00284   virtual void setIndexOffset(off_t off) { mIndexOffset = off; }
00285   virtual off_t indexOffset() const { return mIndexOffset; }
00286 
00288   virtual void setIndexLength(short len) { mIndexLength = len; }
00289   virtual short indexLength() const { return mIndexLength; }
00290 
00295   static QString skipKeyword(const QString& str, QChar sepChar=':',
00296                  bool* keywordFound=0);
00297 
00300   static const QTextCodec* codecForName(const QCString& _str);
00301 
00305   static QCString toUsAscii(const QString& _str, bool *ok=0);
00306 
00308   static QStringList supportedEncodings(bool usAscii);
00309 
00311   void assign(const KMMsgBase* other);
00312 
00314   KMMsgBase& operator=(const KMMsgBase& other);
00315 
00317   KMMsgBase( const KMMsgBase& other );
00318 
00320   static QCString encodeRFC2047Quoted(const QCString& aStr, bool base64);
00321 
00324   static QString decodeRFC2047String(const QCString& aStr);
00325 
00328   static QCString encodeRFC2047String(const QString& aStr,
00329     const QCString& charset);
00330 
00333   static QCString encodeRFC2231String(const QString& aStr,
00334     const QCString& charset);
00335 
00337   static QString decodeRFC2231String(const QCString& aStr);
00338 
00343   static QCString extractRFC2231HeaderField( const QCString &aStr, const QCString &field );
00344 
00348   static QString base64EncodedMD5( const QString & aStr, bool utf8=false );
00349   static QString base64EncodedMD5( const QCString & aStr );
00350   static QString base64EncodedMD5( const char * aStr, int len=-1 );
00351 
00357   static QCString autoDetectCharset(const QCString &encoding, const QStringList &encodingList, const QString &text);
00358 
00360   virtual unsigned long getMsgSerNum() const;
00361 
00363   virtual bool enableUndo() { return mEnableUndo; }
00364   virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
00365 
00367   bool readyToShow();
00369   void setReadyToShow(bool);
00370 
00372   bool transferInProgress();
00374   void setTransferInProgress(bool value, bool force = false);
00375 
00377   virtual KMMsgAttachmentState attachmentState() const;
00378 
00385   static QString replacePrefixes( const QString& str,
00386                                   const QStringList& prefixRegExps,
00387                                   bool replace,
00388                                   const QString& newPrefix );
00389 
00392   static QString stripOffPrefixes( const QString& str );
00393 
00400   QString cleanSubject(const QStringList& prefixRegExps, bool replace,
00401                const QString& newPrefix) const;
00402 
00405   QString cleanSubject() const;
00406 
00408   QString forwardSubject() const;
00409 
00411   QString replySubject() const;
00412 
00415   static void readConfig();
00416 
00417 protected:
00418   KMFolder* mParent;
00419   off_t mIndexOffset;
00420   short mIndexLength;
00421   bool mDirty;
00422   bool mEnableUndo;
00423   mutable KMMsgStatus mStatus;
00424   // This is kept to provide an upgrade path from the the old single status
00425   // to the new multiple status scheme.
00426   mutable KMLegacyMsgStatus mLegacyStatus;
00427 
00428 public:
00429   enum MsgPartType
00430   {
00431     MsgNoPart = 0,
00432     //unicode strings
00433     MsgFromPart = 1,
00434     MsgSubjectPart = 2,
00435     MsgToPart = 3,
00436     MsgReplyToIdMD5Part = 4,
00437     MsgIdMD5Part = 5,
00438     MsgXMarkPart = 6,
00439     //unsigned long
00440     MsgOffsetPart = 7,
00441     MsgLegacyStatusPart = 8,
00442     MsgSizePart = 9,
00443     MsgDatePart = 10,
00444     MsgFilePart = 11,
00445     MsgCryptoStatePart = 12,
00446     MsgMDNSentPart = 13,
00447     //another two unicode strings
00448     MsgReplyToAuxIdMD5Part = 14,
00449     MsgStrippedSubjectMD5Part = 15,
00450     // and another unsigned long
00451     MsgStatusPart = 16,
00452     MsgSizeServerPart = 17,
00453     MsgUIDPart = 18
00454   };
00456   off_t getLongPart(MsgPartType) const;
00458   QString getStringPart(MsgPartType) const;
00460   bool syncIndexString() const;
00461 };
00462 
00463 #endif /*kmmsgbase_h*/
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:21:29 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003