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 toStrip(void) const = 0;
00263   virtual QString replyToIdMD5(void) const = 0;
00264   virtual QString msgIdMD5(void) const = 0;
00265   virtual QString replyToAuxIdMD5() const = 0;
00266   virtual QString strippedSubjectMD5() const = 0;
00267   virtual bool subjectIsPrefixed() const = 0;
00268   virtual time_t date(void) const = 0;
00269   virtual QString dateStr(void) const;
00270   virtual QString xmark(void) const = 0;
00271 
00273   virtual void setDate(const QCString &aStrDate);
00274   virtual void setDate(time_t aUnixTime) = 0;
00275 
00277   virtual bool dirty(void) const { return mDirty; }
00278 
00280   void setDirty(bool b) { mDirty = b; }
00281 
00283   virtual void setSubject(const QString&) = 0;
00284   virtual void setXMark(const QString&) = 0;
00285 
00287   virtual void initStrippedSubjectMD5() = 0;
00288 
00290   const uchar *asIndexString(int &len) const;
00291 
00293   virtual off_t folderOffset(void) const = 0;
00294   virtual void setFolderOffset(off_t offs) = 0;
00295 
00297   virtual QString fileName(void) const = 0;
00298   virtual void setFileName(const QString& filename) = 0;
00299 
00301   virtual size_t msgSize(void) const = 0;
00302   virtual void setMsgSize(size_t sz) = 0;
00303 
00305   virtual size_t msgSizeServer(void) const = 0;
00306   virtual void setMsgSizeServer(size_t sz) = 0;
00307 
00309   virtual ulong UID(void) const = 0;
00310   virtual void setUID(ulong uid) = 0;
00311 
00313   virtual void setIndexOffset(off_t off) { mIndexOffset = off; }
00314   virtual off_t indexOffset() const { return mIndexOffset; }
00315 
00317   virtual void setIndexLength(short len) { mIndexLength = len; }
00318   virtual short indexLength() const { return mIndexLength; }
00319 
00324   static QString skipKeyword(const QString& str, QChar sepChar=':',
00325                  bool* keywordFound=0);
00326 
00329   static const QTextCodec* codecForName(const QCString& _str);
00330 
00334   static QCString toUsAscii(const QString& _str, bool *ok=0);
00335 
00337   static QStringList supportedEncodings(bool usAscii);
00338 
00340   void assign(const KMMsgBase* other);
00341 
00343   KMMsgBase& operator=(const KMMsgBase& other);
00344 
00346   KMMsgBase( const KMMsgBase& other );
00347 
00349   static QCString encodeRFC2047Quoted(const QCString& aStr, bool base64);
00350 
00353   static QString decodeRFC2047String(const QCString& aStr, const QCString prefCharset = "");
00354 
00357   static QCString encodeRFC2047String(const QString& aStr,
00358     const QCString& charset);
00359 
00362   static QCString encodeRFC2231String(const QString& aStr,
00363     const QCString& charset);
00364 
00369   static QCString encodeRFC2231StringAutoDetectCharset( const QString &str,
00370                                                         const QCString &defaultCharset = "" );
00371 
00373   static QString decodeRFC2231String(const QCString& aStr);
00378   static QCString extractRFC2231HeaderField( const QCString &aStr, const QCString &field );
00379 
00383   static QString base64EncodedMD5( const QString & aStr, bool utf8=false );
00384   static QString base64EncodedMD5( const QCString & aStr );
00385   static QString base64EncodedMD5( const char * aStr, int len=-1 );
00386 
00392   static QCString autoDetectCharset(const QCString &encoding, const QStringList &encodingList, const QString &text);
00393 
00395   virtual unsigned long getMsgSerNum() const;
00396 
00398   virtual bool enableUndo() { return mEnableUndo; }
00399   virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
00400 
00402   virtual KMMsgAttachmentState attachmentState() const;
00403 
00405   virtual KMMsgInvitationState invitationState() const;
00406 
00413   static QString replacePrefixes( const QString& str,
00414                                   const QStringList& prefixRegExps,
00415                                   bool replace,
00416                                   const QString& newPrefix );
00417 
00420   static QString stripOffPrefixes( const QString& str );
00421 
00428   QString cleanSubject(const QStringList& prefixRegExps, bool replace,
00429                const QString& newPrefix) const;
00430 
00433   QString cleanSubject() const;
00434 
00436   QString forwardSubject() const;
00437 
00439   QString replySubject() const;
00440 
00443   static void readConfig();
00444 
00445 protected:
00446   KMFolder* mParent;
00447   off_t mIndexOffset;
00448   short mIndexLength;
00449   bool mDirty;
00450   bool mEnableUndo;
00451   mutable KMMsgStatus mStatus;
00452   // This is kept to provide an upgrade path from the the old single status
00453   // to the new multiple status scheme.
00454   mutable KMLegacyMsgStatus mLegacyStatus;
00455 
00456 public:
00457   enum MsgPartType
00458   {
00459     MsgNoPart = 0,
00460     //unicode strings
00461     MsgFromPart = 1,
00462     MsgSubjectPart = 2,
00463     MsgToPart = 3,
00464     MsgReplyToIdMD5Part = 4,
00465     MsgIdMD5Part = 5,
00466     MsgXMarkPart = 6,
00467     //unsigned long
00468     MsgOffsetPart = 7,
00469     MsgLegacyStatusPart = 8,
00470     MsgSizePart = 9,
00471     MsgDatePart = 10,
00472     MsgFilePart = 11,
00473     MsgCryptoStatePart = 12,
00474     MsgMDNSentPart = 13,
00475     //another two unicode strings
00476     MsgReplyToAuxIdMD5Part = 14,
00477     MsgStrippedSubjectMD5Part = 15,
00478     // and another unsigned long
00479     MsgStatusPart = 16,
00480     MsgSizeServerPart = 17,
00481     MsgUIDPart = 18
00482   };
00484   off_t getLongPart(MsgPartType) const;
00486   QString getStringPart(MsgPartType) const;
00488   bool syncIndexString() const;
00489 };
00490 
00491 #endif /*kmmsgbase_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys