00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef kmmsgbase_h
00021 #define kmmsgbase_h
00022
00023
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,
00054 KMMsgStatusWatched = 0x00000400,
00055 KMMsgStatusIgnored = 0x00000800,
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
00357 static QString decodeRFC2231String(const QCString& aStr);
00362 static QCString extractRFC2231HeaderField( const QCString &aStr, const QCString &field );
00363
00367 static QString base64EncodedMD5( const QString & aStr, bool utf8=false );
00368 static QString base64EncodedMD5( const QCString & aStr );
00369 static QString base64EncodedMD5( const char * aStr, int len=-1 );
00370
00376 static QCString autoDetectCharset(const QCString &encoding, const QStringList &encodingList, const QString &text);
00377
00379 virtual unsigned long getMsgSerNum() const;
00380
00382 virtual bool enableUndo() { return mEnableUndo; }
00383 virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
00384
00386 virtual KMMsgAttachmentState attachmentState() const;
00387
00394 static QString replacePrefixes( const QString& str,
00395 const QStringList& prefixRegExps,
00396 bool replace,
00397 const QString& newPrefix );
00398
00401 static QString stripOffPrefixes( const QString& str );
00402
00409 QString cleanSubject(const QStringList& prefixRegExps, bool replace,
00410 const QString& newPrefix) const;
00411
00414 QString cleanSubject() const;
00415
00417 QString forwardSubject() const;
00418
00420 QString replySubject() const;
00421
00424 static void readConfig();
00425
00426 protected:
00427 KMFolder* mParent;
00428 off_t mIndexOffset;
00429 short mIndexLength;
00430 bool mDirty;
00431 bool mEnableUndo;
00432 mutable KMMsgStatus mStatus;
00433
00434
00435 mutable KMLegacyMsgStatus mLegacyStatus;
00436
00437 public:
00438 enum MsgPartType
00439 {
00440 MsgNoPart = 0,
00441
00442 MsgFromPart = 1,
00443 MsgSubjectPart = 2,
00444 MsgToPart = 3,
00445 MsgReplyToIdMD5Part = 4,
00446 MsgIdMD5Part = 5,
00447 MsgXMarkPart = 6,
00448
00449 MsgOffsetPart = 7,
00450 MsgLegacyStatusPart = 8,
00451 MsgSizePart = 9,
00452 MsgDatePart = 10,
00453 MsgFilePart = 11,
00454 MsgCryptoStatePart = 12,
00455 MsgMDNSentPart = 13,
00456
00457 MsgReplyToAuxIdMD5Part = 14,
00458 MsgStrippedSubjectMD5Part = 15,
00459
00460 MsgStatusPart = 16,
00461 MsgSizeServerPart = 17,
00462 MsgUIDPart = 18
00463 };
00465 off_t getLongPart(MsgPartType) const;
00467 QString getStringPart(MsgPartType) const;
00469 bool syncIndexString() const;
00470 };
00471
00472 #endif