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     KMMsgStatusHasInvitation =     0x00020000,
00062     KMMsgStatusHasNoInvitation =   0x00040000
00063 };
00064 
00065 typedef uint KMMsgStatus;
00066 
00070 typedef enum
00071 {
00072     KMLegacyMsgStatusUnknown=' ',
00073     KMLegacyMsgStatusNew='N',
00074     KMLegacyMsgStatusUnread='U',
00075     KMLegacyMsgStatusRead='R',
00076     KMLegacyMsgStatusOld='O',
00077     KMLegacyMsgStatusDeleted='D',
00078     KMLegacyMsgStatusReplied='A',
00079     KMLegacyMsgStatusForwarded='F',
00080     KMLegacyMsgStatusQueued='Q',
00081     KMLegacyMsgStatusSent='S',
00082     KMLegacyMsgStatusFlag='G'
00083 } KMLegacyMsgStatus;
00084 
00085 
00086 
00088 typedef enum
00089 {
00090     KMMsgEncryptionStateUnknown=' ',
00091     KMMsgNotEncrypted='N',
00092     KMMsgPartiallyEncrypted='P',
00093     KMMsgFullyEncrypted='F',
00094     KMMsgEncryptionProblematic='X'
00095 } KMMsgEncryptionState;
00096 
00098 typedef enum
00099 {
00100     KMMsgSignatureStateUnknown=' ',
00101     KMMsgNotSigned='N',
00102     KMMsgPartiallySigned='P',
00103     KMMsgFullySigned='F',
00104     KMMsgSignatureProblematic='X'
00105 } KMMsgSignatureState;
00106 
00108 typedef enum
00109 {
00110     KMMsgMDNStateUnknown = ' ',
00111     KMMsgMDNNone = 'N',
00112     KMMsgMDNIgnore = 'I',
00113     KMMsgMDNDisplayed = 'R',
00114     KMMsgMDNDeleted = 'D',
00115     KMMsgMDNDispatched = 'F',
00116     KMMsgMDNProcessed = 'P',
00117     KMMsgMDNDenied = 'X',
00118     KMMsgMDNFailed = 'E'
00119 } KMMsgMDNSentState;
00120 
00122 typedef enum
00123 {
00124     KMMsgDnDActionMOVE=0,
00125     KMMsgDnDActionCOPY=1,
00126     KMMsgDnDActionASK=2
00127 } KMMsgDnDAction;
00128 
00130 typedef enum
00131 {
00132   KMMsgHasAttachment,
00133   KMMsgHasNoAttachment,
00134   KMMsgAttachmentUnknown
00135 } KMMsgAttachmentState;
00136 
00138 typedef enum
00139 {
00140   KMMsgHasInvitation,
00141   KMMsgHasNoInvitation,
00142   KMMsgInvitationUnknown
00143 } KMMsgInvitationState;
00144 
00145 class KMMsgBase
00146 {
00147 public:
00148   KMMsgBase(KMFolder* p=0);
00149   virtual ~KMMsgBase();
00150 
00152   KMFolderIndex* storage() const;
00153 
00155   KMFolder* parent() const { return mParent; }
00156 
00158   void setParent(KMFolder* p) { mParent = p; }
00159 
00161   static QCString statusToStr(const KMMsgStatus status);
00162 
00164   QString statusToSortRank();
00165 
00167   virtual bool isMessage(void) const;
00168 
00170   virtual bool isUnread(void) const;
00171 
00173   virtual bool isNew(void) const;
00174 
00176   virtual bool isOfUnknownStatus(void) const;
00177 
00179   virtual bool isOld(void) const;
00180 
00182   virtual bool isRead(void) const;
00183 
00185   virtual bool isDeleted(void) const;
00186 
00188   virtual bool isReplied(void) const;
00189 
00191   virtual bool isForwarded(void) const;
00192 
00194   virtual bool isQueued(void) const;
00195 
00197   virtual bool isTodo(void) const;
00198 
00200   virtual bool isSent(void) const;
00201 
00203   virtual bool isImportant(void) const;
00204 
00206   virtual bool isWatched(void) const;
00207 
00209   virtual bool isIgnored(void) const;
00210 
00212   virtual bool isSpam(void) const;
00213 
00215   virtual bool isHam(void) const;
00216 
00217 
00219   virtual KMMsgStatus status(void) const = 0;
00220 
00223   virtual void setStatus(const KMMsgStatus status, int idx = -1);
00224   virtual void toggleStatus(const KMMsgStatus status, int idx = -1);
00225   virtual void setStatus(const char* statusField, const char* xstatusField=0);
00226 
00228   virtual KMMsgEncryptionState encryptionState() const = 0;
00229 
00231   virtual KMMsgSignatureState signatureState() const = 0;
00232 
00234   virtual KMMsgMDNSentState mdnSentState() const = 0;
00235 
00237   virtual void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00238 
00242   virtual void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00243 
00247   virtual void setSignatureState(const KMMsgSignatureState, int idx = -1);
00248 
00252   virtual void setEncryptionStateChar( QChar status, int idx = -1 );
00253 
00257   virtual void setSignatureStateChar( QChar status, int idx = -1 );
00258 
00260   virtual QString subject(void) const = 0;
00261   virtual QString fromStrip(void) const = 0;
00262   virtual QString from() const = 0;
00263   virtual QString toStrip(void) const = 0;
00264   virtual QString to() const = 0;
00265   virtual QString replyToIdMD5(void) const = 0;
00266   virtual QString msgIdMD5(void) const = 0;
00267   virtual QString replyToAuxIdMD5() const = 0;
00268   virtual QString strippedSubjectMD5() const = 0;
00269   virtual bool subjectIsPrefixed() const = 0;
00270   virtual time_t date(void) const = 0;
00271   virtual QString dateStr(void) const;
00272   virtual QString xmark(void) const = 0;
00273 
00275   virtual void setDate(const QCString &aStrDate);
00276   virtual void setDate(time_t aUnixTime) = 0;
00277 
00279   virtual bool dirty(void) const { return mDirty; }
00280 
00282   void setDirty(bool b) { mDirty = b; }
00283 
00285   virtual void setSubject(const QString&) = 0;
00286   virtual void setXMark(const QString&) = 0;
00287 
00289   virtual void initStrippedSubjectMD5() = 0;
00290 
00292   const uchar *asIndexString(int &len) const;
00293 
00295   virtual off_t folderOffset(void) const = 0;
00296   virtual void setFolderOffset(off_t offs) = 0;
00297 
00299   virtual QString fileName(void) const = 0;
00300   virtual void setFileName(const QString& filename) = 0;
00301 
00303   virtual size_t msgSize(void) const = 0;
00304   virtual void setMsgSize(size_t sz) = 0;
00305 
00307   virtual size_t msgSizeServer(void) const = 0;
00308   virtual void setMsgSizeServer(size_t sz) = 0;
00309 
00311   virtual ulong UID(void) const = 0;
00312   virtual void setUID(ulong uid) = 0;
00313 
00315   virtual void setIndexOffset(off_t off) { mIndexOffset = off; }
00316   virtual off_t indexOffset() const { return mIndexOffset; }
00317 
00319   virtual void setIndexLength(short len) { mIndexLength = len; }
00320   virtual short indexLength() const { return mIndexLength; }
00321 
00326   static QString skipKeyword(const QString& str, QChar sepChar=':',
00327                  bool* keywordFound=0);
00328 
00331   static const QTextCodec* codecForName(const QCString& _str);
00332 
00336   static QCString toUsAscii(const QString& _str, bool *ok=0);
00337 
00339   static QStringList supportedEncodings(bool usAscii);
00340 
00342   void assign(const KMMsgBase* other);
00343 
00345   KMMsgBase& operator=(const KMMsgBase& other);
00346 
00348   KMMsgBase( const KMMsgBase& other );
00349 
00351   static QCString encodeRFC2047Quoted(const QCString& aStr, bool base64);
00352 
00355   static QString decodeRFC2047String(const QCString& aStr, const QCString prefCharset = "");
00356 
00359   static QCString encodeRFC2047String(const QString& aStr,
00360     const QCString& charset);
00361 
00364   static QCString encodeRFC2231String(const QString& aStr,
00365     const QCString& charset);
00366 
00371   static QCString encodeRFC2231StringAutoDetectCharset( const QString &str,
00372                                                         const QCString &defaultCharset = "" );
00373 
00375   static QString decodeRFC2231String(const QCString& aStr);
00380   static QCString extractRFC2231HeaderField( const QCString &aStr, const QCString &field );
00381 
00385   static QString base64EncodedMD5( const QString & aStr, bool utf8=false );
00386   static QString base64EncodedMD5( const QCString & aStr );
00387   static QString base64EncodedMD5( const char * aStr, int len=-1 );
00388 
00394   static QCString autoDetectCharset(const QCString &encoding, const QStringList &encodingList, const QString &text);
00395 
00397   virtual unsigned long getMsgSerNum() const;
00398 
00400   virtual bool enableUndo() { return mEnableUndo; }
00401   virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
00402 
00404   virtual KMMsgAttachmentState attachmentState() const;
00405 
00407   virtual KMMsgInvitationState invitationState() const;
00408 
00415   static QString replacePrefixes( const QString& str,
00416                                   const QStringList& prefixRegExps,
00417                                   bool replace,
00418                                   const QString& newPrefix );
00419 
00422   static QString stripOffPrefixes( const QString& str );
00423 
00430   QString cleanSubject(const QStringList& prefixRegExps, bool replace,
00431                const QString& newPrefix) const;
00432 
00435   QString cleanSubject() const;
00436 
00438   QString forwardSubject() const;
00439 
00441   QString replySubject() const;
00442 
00445   static void readConfig();
00446 
00447 protected:
00448   KMFolder* mParent;
00449   off_t mIndexOffset;
00450   short mIndexLength;
00451   bool mDirty;
00452   bool mEnableUndo;
00453   mutable KMMsgStatus mStatus;
00454   // This is kept to provide an upgrade path from the the old single status
00455   // to the new multiple status scheme.
00456   mutable KMLegacyMsgStatus mLegacyStatus;
00457 
00458 public:
00459   enum MsgPartType
00460   {
00461     MsgNoPart = 0,
00462     //unicode strings
00463     MsgFromStripPart = 1,
00464     MsgSubjectPart = 2,
00465     MsgToStripPart = 3,
00466     MsgReplyToIdMD5Part = 4,
00467     MsgIdMD5Part = 5,
00468     MsgXMarkPart = 6,
00469     //unsigned long
00470     MsgOffsetPart = 7,
00471     MsgLegacyStatusPart = 8,
00472     MsgSizePart = 9,
00473     MsgDatePart = 10,
00474     MsgFilePart = 11,
00475     MsgCryptoStatePart = 12,
00476     MsgMDNSentPart = 13,
00477     //another two unicode strings
00478     MsgReplyToAuxIdMD5Part = 14,
00479     MsgStrippedSubjectMD5Part = 15,
00480     // and another unsigned long
00481     MsgStatusPart = 16,
00482     MsgSizeServerPart = 17,
00483     MsgUIDPart = 18,
00484     MsgToPart = 19,
00485     MsgFromPart = 20
00486   };
00488   off_t getLongPart(MsgPartType) const;
00490   QString getStringPart(MsgPartType) const;
00492   bool syncIndexString() const;
00493 };
00494 
00495 #endif /*kmmsgbase_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys