00001
00002
00003
00004
00005 #ifndef kmmsgbase_h
00006 #define kmmsgbase_h
00007
00008
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,
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
00342 static QString base64EncodedMD5( const QString & aStr, bool utf8=false );
00343 static QString base64EncodedMD5( const QCString & aStr );
00344 static QString base64EncodedMD5( const char * aStr, int len=-1 );
00345
00351 static QCString autoDetectCharset(const QCString &encoding, const QStringList &encodingList, const QString &text);
00352
00354 virtual unsigned long getMsgSerNum() const;
00355
00357 virtual bool enableUndo() { return mEnableUndo; }
00358 virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
00359
00361 bool readyToShow();
00363 void setReadyToShow(bool);
00364
00366 bool transferInProgress();
00368 void setTransferInProgress(bool value, bool force = false);
00369
00371 virtual KMMsgAttachmentState attachmentState() const;
00372
00379 static QString replacePrefixes( const QString& str,
00380 const QStringList& prefixRegExps,
00381 bool replace,
00382 const QString& newPrefix );
00383
00386 static QString stripOffPrefixes( const QString& str );
00387
00394 QString cleanSubject(const QStringList& prefixRegExps, bool replace,
00395 const QString& newPrefix) const;
00396
00399 QString cleanSubject() const;
00400
00402 QString forwardSubject() const;
00403
00405 QString replySubject() const;
00406
00409 static void readConfig();
00410
00411 protected:
00412 KMFolder* mParent;
00413 off_t mIndexOffset;
00414 short mIndexLength;
00415 bool mDirty;
00416 bool mEnableUndo;
00417 mutable KMMsgStatus mStatus;
00418
00419
00420 mutable KMLegacyMsgStatus mLegacyStatus;
00421
00422 public:
00423 enum MsgPartType
00424 {
00425 MsgNoPart = 0,
00426
00427 MsgFromPart = 1,
00428 MsgSubjectPart = 2,
00429 MsgToPart = 3,
00430 MsgReplyToIdMD5Part = 4,
00431 MsgIdMD5Part = 5,
00432 MsgXMarkPart = 6,
00433
00434 MsgOffsetPart = 7,
00435 MsgLegacyStatusPart = 8,
00436 MsgSizePart = 9,
00437 MsgDatePart = 10,
00438 MsgFilePart = 11,
00439 MsgCryptoStatePart = 12,
00440 MsgMDNSentPart = 13,
00441
00442 MsgReplyToAuxIdMD5Part = 14,
00443 MsgStrippedSubjectMD5Part = 15,
00444
00445 MsgStatusPart = 16,
00446 MsgSizeServerPart = 17,
00447 MsgUIDPart = 18
00448 };
00450 off_t getLongPart(MsgPartType) const;
00452 QString getStringPart(MsgPartType) const;
00454 bool syncIndexString() const;
00455 };
00456
00457 #endif