kmail

kmmsgbase.h

00001 /*
00002  * kmail: KDE mail client
00003  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #ifndef kmmsgbase_h
00021 #define kmmsgbase_h
00022 
00023 // for large file support flags
00024 #include <config.h>
00025 #include <sys/types.h>
00026 #include <qstring.h>
00027 #include <time.h>
00028 
00029 class QCString;
00030 class QStringList;
00031 class QTextCodec;
00032 class KMFolder;
00033 class KMFolderIndex;
00034 
00041 enum MsgStatus
00042 {
00043     KMMsgStatusUnknown =           0x00000000,
00044     KMMsgStatusNew =               0x00000001,
00045     KMMsgStatusUnread =            0x00000002,
00046     KMMsgStatusRead =              0x00000004,
00047     KMMsgStatusOld =               0x00000008,
00048     KMMsgStatusDeleted =           0x00000010,
00049     KMMsgStatusReplied =           0x00000020,
00050     KMMsgStatusForwarded =         0x00000040,
00051     KMMsgStatusQueued =            0x00000080,
00052     KMMsgStatusSent =              0x00000100,
00053     KMMsgStatusFlag =              0x00000200, // flag means important
00054     KMMsgStatusWatched =           0x00000400,
00055     KMMsgStatusIgnored =           0x00000800, // forces isRead()
00056     KMMsgStatusTodo =              0x00001000,
00057     KMMsgStatusSpam =              0x00002000,
00058     KMMsgStatusHam =               0x00004000,
00059     KMMsgStatusHasAttach =         0x00008000,
00060     KMMsgStatusHasNoAttach =       0x00010000
00061 };
00062 
00063 typedef uint KMMsgStatus;
00064 
00068 typedef enum
00069 {
00070     KMLegacyMsgStatusUnknown=' ',
00071     KMLegacyMsgStatusNew='N',
00072     KMLegacyMsgStatusUnread='U',
00073     KMLegacyMsgStatusRead='R',
00074     KMLegacyMsgStatusOld='O',
00075     KMLegacyMsgStatusDeleted='D',
00076     KMLegacyMsgStatusReplied='A',
00077     KMLegacyMsgStatusForwarded='F',
00078     KMLegacyMsgStatusQueued='Q',
00079     KMLegacyMsgStatusSent='S',
00080     KMLegacyMsgStatusFlag='G'
00081 } KMLegacyMsgStatus;
00082 
00083 
00084 
00086 typedef enum
00087 {
00088     KMMsgEncryptionStateUnknown=' ',
00089     KMMsgNotEncrypted='N',
00090     KMMsgPartiallyEncrypted='P',
00091     KMMsgFullyEncrypted='F',
00092     KMMsgEncryptionProblematic='X'
00093 } KMMsgEncryptionState;
00094 
00096 typedef enum
00097 {
00098     KMMsgSignatureStateUnknown=' ',
00099     KMMsgNotSigned='N',
00100     KMMsgPartiallySigned='P',
00101     KMMsgFullySigned='F',
00102     KMMsgSignatureProblematic='X'
00103 } KMMsgSignatureState;
00104 
00106 typedef enum
00107 {
00108     KMMsgMDNStateUnknown = ' ',
00109     KMMsgMDNNone = 'N',
00110     KMMsgMDNIgnore = 'I',
00111     KMMsgMDNDisplayed = 'R',
00112     KMMsgMDNDeleted = 'D',
00113     KMMsgMDNDispatched = 'F',
00114     KMMsgMDNProcessed = 'P',
00115     KMMsgMDNDenied = 'X',
00116     KMMsgMDNFailed = 'E'
00117 } KMMsgMDNSentState;
00118 
00120 typedef enum
00121 {
00122     KMMsgDnDActionMOVE=0,
00123     KMMsgDnDActionCOPY=1,
00124     KMMsgDnDActionASK=2
00125 } KMMsgDnDAction;
00126 
00128 typedef enum
00129 {
00130   KMMsgHasAttachment,
00131   KMMsgHasNoAttachment,
00132   KMMsgAttachmentUnknown
00133 } KMMsgAttachmentState;
00134 
00135 
00136 class KMMsgBase
00137 {
00138 public:
00139   KMMsgBase(KMFolder* p=0);
00140   virtual ~KMMsgBase();
00141 
00143   KMFolderIndex* storage() const;
00144 
00146   KMFolder* parent() const { return mParent; }
00147 
00149   void setParent(KMFolder* p) { mParent = p; }
00150 
00152   static QCString statusToStr(const KMMsgStatus status);
00153 
00155   QString statusToSortRank();
00156 
00158   virtual bool isMessage(void) const;
00159 
00161   virtual bool isUnread(void) const;
00162 
00164   virtual bool isNew(void) const;
00165 
00167   virtual bool isOfUnknownStatus(void) const;
00168 
00170   virtual bool isOld(void) const;
00171 
00173   virtual bool isRead(void) const;
00174 
00176   virtual bool isDeleted(void) const;
00177 
00179   virtual bool isReplied(void) const;
00180 
00182   virtual bool isForwarded(void) const;
00183 
00185   virtual bool isQueued(void) const;
00186 
00188   virtual bool isTodo(void) const;
00189 
00191   virtual bool isSent(void) const;
00192 
00194   virtual bool isImportant(void) const;
00195 
00197   virtual bool isWatched(void) const;
00198 
00200   virtual bool isIgnored(void) const;
00201 
00203   virtual bool isSpam(void) const;
00204 
00206   virtual bool isHam(void) const;
00207 
00208 
00210   virtual KMMsgStatus status(void) const = 0;
00211 
00214   virtual void setStatus(const KMMsgStatus status, int idx = -1);
00215   virtual void toggleStatus(const KMMsgStatus status, int idx = -1);
00216   virtual void setStatus(const char* statusField, const char* xstatusField=0);
00217 
00219   virtual KMMsgEncryptionState encryptionState() const = 0;
00220 
00222   virtual KMMsgSignatureState signatureState() const = 0;
00223 
00225   virtual KMMsgMDNSentState mdnSentState() const = 0;
00226 
00228   virtual void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00229 
00233   virtual void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00234 
00238   virtual void setSignatureState(const KMMsgSignatureState, int idx = -1);
00239 
00243   virtual void setEncryptionStateChar( QChar status, int idx = -1 );
00244 
00248   virtual void setSignatureStateChar( QChar status, int idx = -1 );
00249 
00251   virtual QString subject(void) const = 0;
00252   virtual QString fromStrip(void) const = 0;
00253   virtual QString toStrip(void) const = 0;
00254   virtual QString replyToIdMD5(void) const = 0;
00255   virtual QString msgIdMD5(void) const = 0;
00256   virtual QString replyToAuxIdMD5() const = 0;
00257   virtual QString strippedSubjectMD5() const = 0;
00258   virtual bool subjectIsPrefixed() const = 0;
00259   virtual time_t date(void) const = 0;
00260   virtual QString dateStr(void) const;
00261   virtual QString xmark(void) const = 0;
00262 
00264   virtual void setDate(const QCString &aStrDate);
00265   virtual void setDate(time_t aUnixTime) = 0;
00266 
00268   virtual bool dirty(void) const { return mDirty; }
00269 
00271   void setDirty(bool b) { mDirty = b; }
00272 
00274   virtual void setSubject(const QString&) = 0;
00275   virtual void setXMark(const QString&) = 0;
00276 
00278   virtual void initStrippedSubjectMD5() = 0;
00279 
00281   const uchar *asIndexString(int &len) const;
00282 
00284   virtual off_t folderOffset(void) const = 0;
00285   virtual void setFolderOffset(off_t offs) = 0;
00286 
00288   virtual QString fileName(void) const = 0;
00289   virtual void setFileName(const QString& filename) = 0;
00290 
00292   virtual size_t msgSize(void) const = 0;
00293   virtual void setMsgSize(size_t sz) = 0;
00294 
00296   virtual size_t msgSizeServer(void) const = 0;
00297   virtual void setMsgSizeServer(size_t sz) = 0;
00298 
00300   virtual ulong UID(void) const = 0;
00301   virtual void setUID(ulong uid) = 0;
00302 
00304   virtual void setIndexOffset(off_t off) { mIndexOffset = off; }
00305   virtual off_t indexOffset() const { return mIndexOffset; }
00306 
00308   virtual void setIndexLength(short len) { mIndexLength = len; }
00309   virtual short indexLength() const { return mIndexLength; }
00310 
00315   static QString skipKeyword(const QString& str, QChar sepChar=':',
00316                  bool* keywordFound=0);
00317 
00320   static const QTextCodec* codecForName(const QCString& _str);
00321 
00325   static QCString toUsAscii(const QString& _str, bool *ok=0);
00326 
00328   static QStringList supportedEncodings(bool usAscii);
00329 
00331   void assign(const KMMsgBase* other);
00332 
00334   KMMsgBase& operator=(const KMMsgBase& other);
00335 
00337   KMMsgBase( const KMMsgBase& other );
00338 
00340   static QCString encodeRFC2047Quoted(const QCString& aStr, bool base64);
00341 
00344   static QString decodeRFC2047String(const QCString& aStr, const QCString prefCharset = "");
00345 
00348   static QCString encodeRFC2047String(const QString& aStr,
00349     const QCString& charset);
00350 
00353   static QCString encodeRFC2231String(const QString& aStr,
00354     const QCString& charset);
00355 
00360   static QCString encodeRFC2231StringAutoDetectCharset( const QString &str,
00361                                                         const QCString &defaultCharset = "" );
00362 
00364   static QString decodeRFC2231String(const QCString& aStr);
00369   static QCString extractRFC2231HeaderField( const QCString &aStr, const QCString &field );
00370 
00374   static QString base64EncodedMD5( const QString & aStr, bool utf8=false );
00375   static QString base64EncodedMD5( const QCString & aStr );
00376   static QString base64EncodedMD5( const char * aStr, int len=-1 );
00377 
00383   static QCString autoDetectCharset(const QCString &encoding, const QStringList &encodingList, const QString &text);
00384 
00386   virtual unsigned long getMsgSerNum() const;
00387 
00389   virtual bool enableUndo() { return mEnableUndo; }
00390   virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
00391 
00393   virtual KMMsgAttachmentState attachmentState() const;
00394 
00401   static QString replacePrefixes( const QString& str,
00402                                   const QStringList& prefixRegExps,
00403                                   bool replace,
00404                                   const QString& newPrefix );
00405 
00408   static QString stripOffPrefixes( const QString& str );
00409 
00416   QString cleanSubject(const QStringList& prefixRegExps, bool replace,
00417                const QString& newPrefix) const;
00418 
00421   QString cleanSubject() const;
00422 
00424   QString forwardSubject() const;
00425 
00427   QString replySubject() const;
00428 
00431   static void readConfig();
00432 
00433 protected:
00434   KMFolder* mParent;
00435   off_t mIndexOffset;
00436   short mIndexLength;
00437   bool mDirty;
00438   bool mEnableUndo;
00439   mutable KMMsgStatus mStatus;
00440   // This is kept to provide an upgrade path from the the old single status
00441   // to the new multiple status scheme.
00442   mutable KMLegacyMsgStatus mLegacyStatus;
00443 
00444 public:
00445   enum MsgPartType
00446   {
00447     MsgNoPart = 0,
00448     //unicode strings
00449     MsgFromPart = 1,
00450     MsgSubjectPart = 2,
00451     MsgToPart = 3,
00452     MsgReplyToIdMD5Part = 4,
00453     MsgIdMD5Part = 5,
00454     MsgXMarkPart = 6,
00455     //unsigned long
00456     MsgOffsetPart = 7,
00457     MsgLegacyStatusPart = 8,
00458     MsgSizePart = 9,
00459     MsgDatePart = 10,
00460     MsgFilePart = 11,
00461     MsgCryptoStatePart = 12,
00462     MsgMDNSentPart = 13,
00463     //another two unicode strings
00464     MsgReplyToAuxIdMD5Part = 14,
00465     MsgStrippedSubjectMD5Part = 15,
00466     // and another unsigned long
00467     MsgStatusPart = 16,
00468     MsgSizeServerPart = 17,
00469     MsgUIDPart = 18
00470   };
00472   off_t getLongPart(MsgPartType) const;
00474   QString getStringPart(MsgPartType) const;
00476   bool syncIndexString() const;
00477 };
00478 
00479 #endif /*kmmsgbase_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys