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 };
00040
00041 typedef uint KMMsgStatus;
00042
00046 typedef enum
00047 {
00048 KMLegacyMsgStatusUnknown=' ',
00049 KMLegacyMsgStatusNew='N',
00050 KMLegacyMsgStatusUnread='U',
00051 KMLegacyMsgStatusRead='R',
00052 KMLegacyMsgStatusOld='O',
00053 KMLegacyMsgStatusDeleted='D',
00054 KMLegacyMsgStatusReplied='A',
00055 KMLegacyMsgStatusForwarded='F',
00056 KMLegacyMsgStatusQueued='Q',
00057 KMLegacyMsgStatusSent='S',
00058 KMLegacyMsgStatusFlag='G'
00059 } KMLegacyMsgStatus;
00060
00061
00062
00064 typedef enum
00065 {
00066 KMMsgEncryptionStateUnknown=' ',
00067 KMMsgNotEncrypted='N',
00068 KMMsgPartiallyEncrypted='P',
00069 KMMsgFullyEncrypted='F',
00070 KMMsgEncryptionProblematic='X'
00071 } KMMsgEncryptionState;
00072
00074 typedef enum
00075 {
00076 KMMsgSignatureStateUnknown=' ',
00077 KMMsgNotSigned='N',
00078 KMMsgPartiallySigned='P',
00079 KMMsgFullySigned='F',
00080 KMMsgSignatureProblematic='X'
00081 } KMMsgSignatureState;
00082
00084 typedef enum
00085 {
00086 KMMsgMDNStateUnknown = ' ',
00087 KMMsgMDNNone = 'N',
00088 KMMsgMDNIgnore = 'I',
00089 KMMsgMDNDisplayed = 'R',
00090 KMMsgMDNDeleted = 'D',
00091 KMMsgMDNDispatched = 'F',
00092 KMMsgMDNProcessed = 'P',
00093 KMMsgMDNDenied = 'X',
00094 KMMsgMDNFailed = 'E'
00095 } KMMsgMDNSentState;
00096
00098 typedef enum
00099 {
00100 KMMsgDnDActionMOVE=0,
00101 KMMsgDnDActionCOPY=1,
00102 KMMsgDnDActionASK=2
00103 } KMMsgDnDAction;
00104
00105
00106
00107 class KMMsgBase
00108 {
00109 public:
00110 KMMsgBase(KMFolderIndex* p=0);
00111 virtual ~KMMsgBase();
00112
00114 KMFolderIndex* parent(void) const { return mParent; }
00115
00117 void setParent(KMFolderIndex* p) { mParent=p; }
00118
00120 static QCString statusToStr(const KMMsgStatus status);
00121
00123 QString statusToSortRank();
00124
00126 virtual bool isMessage(void) const;
00127
00129 virtual bool isUnread(void) const;
00130
00132 virtual bool isNew(void) const;
00133
00135 virtual bool isOfUnknownStatus(void) const;
00136
00138 virtual bool isOld(void) const;
00139
00141 virtual bool isRead(void) const;
00142
00144 virtual bool isDeleted(void) const;
00145
00147 virtual bool isReplied(void) const;
00148
00150 virtual bool isForwarded(void) const;
00151
00153 virtual bool isQueued(void) const;
00154
00156 virtual bool isSent(void) const;
00157
00159 virtual bool isFlag(void) const;
00160
00162 virtual bool isWatched(void) const;
00163
00165 virtual bool isIgnored(void) const;
00166
00168 virtual bool isSpam(void) const;
00169
00171 virtual bool isHam(void) const;
00172
00173
00175 virtual KMMsgStatus status(void) const = 0;
00176
00179 virtual void setStatus(const KMMsgStatus status, int idx = -1);
00180 virtual void toggleStatus(const KMMsgStatus status, int idx = -1);
00181 virtual void setStatus(const char* statusField, const char* xstatusField=0);
00182
00184 virtual KMMsgEncryptionState encryptionState() const = 0;
00185
00187 virtual KMMsgSignatureState signatureState() const = 0;
00188
00190 virtual KMMsgMDNSentState mdnSentState() const = 0;
00191
00193 virtual void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
00194
00198 virtual void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
00199
00203 virtual void setSignatureState(const KMMsgSignatureState, int idx = -1);
00204
00208 virtual void setEncryptionStateChar( QChar status, int idx = -1 );
00209
00213 virtual void setSignatureStateChar( QChar status, int idx = -1 );
00214
00216 virtual QString subject(void) const = 0;
00217 virtual QString fromStrip(void) const = 0;
00218 virtual QString toStrip(void) const = 0;
00219 virtual QString replyToIdMD5(void) const = 0;
00220 virtual QString msgIdMD5(void) const = 0;
00221 virtual QString replyToAuxIdMD5() const = 0;
00222 virtual QString strippedSubjectMD5() const = 0;
00223 virtual bool subjectIsPrefixed() const = 0;
00224 virtual time_t date(void) const = 0;
00225 virtual QString dateStr(void) const;
00226 virtual QString xmark(void) const = 0;
00227
00229 virtual void setDate(const QCString &aStrDate);
00230 virtual void setDate(time_t aUnixTime) = 0;
00231
00233 virtual bool dirty(void) const { return mDirty; }
00234
00236 void setDirty(bool b) { mDirty = b; }
00237
00239 virtual void setSubject(const QString&) = 0;
00240 virtual void setXMark(const QString&) = 0;
00241
00243 virtual void initStrippedSubjectMD5() = 0;
00244
00246 const uchar *asIndexString(int &len) const;
00247
00249 virtual off_t folderOffset(void) const = 0;
00250 virtual void setFolderOffset(off_t offs) = 0;
00251
00253 virtual QString fileName(void) const = 0;
00254 virtual void setFileName(const QString& filename) = 0;
00255
00257 virtual size_t msgSize(void) const = 0;
00258 virtual void setMsgSize(size_t sz) = 0;
00259
00261 virtual void setIndexOffset(off_t off) { mIndexOffset = off; }
00262 virtual off_t indexOffset() const { return mIndexOffset; }
00263
00265 virtual void setIndexLength(short len) { mIndexLength = len; }
00266 virtual short indexLength() const { return mIndexLength; }
00267
00272 static QString skipKeyword(const QString& str, QChar sepChar=':',
00273 bool* keywordFound=0);
00274
00277 static const QTextCodec* codecForName(const QCString& _str);
00278
00282 static QCString toUsAscii(const QString& _str, bool *ok=0);
00283
00285 static QStringList supportedEncodings(bool usAscii);
00286
00288 void assign(const KMMsgBase* other);
00289
00291 KMMsgBase& operator=(const KMMsgBase& other);
00292
00294 KMMsgBase( const KMMsgBase& other );
00295
00297 static QCString encodeRFC2047Quoted(const QCString& aStr, bool base64);
00298
00301 static QString decodeRFC2047String(const QCString& aStr);
00302
00305 static QCString encodeRFC2047String(const QString& aStr,
00306 const QCString& charset);
00307
00310 static QCString encodeRFC2231String(const QString& aStr,
00311 const QCString& charset);
00312
00314 static QString decodeRFC2231String(const QCString& aStr);
00315
00319 static QString base64EncodedMD5( const QString & aStr, bool utf8=false );
00320 static QString base64EncodedMD5( const QCString & aStr );
00321 static QString base64EncodedMD5( const char * aStr, int len=-1 );
00322
00328 static QCString autoDetectCharset(const QCString &encoding, const QStringList &encodingList, const QString &text);
00329
00331 virtual unsigned long getMsgSerNum() const;
00332
00334 virtual bool enableUndo() { return mEnableUndo; }
00335 virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
00336
00339 bool isComplete();
00341 void setComplete(bool value);
00342
00344 bool readyToShow();
00346 void setReadyToShow(bool);
00347
00349 bool transferInProgress();
00351 void setTransferInProgress(bool value, bool force = false);
00352
00353 protected:
00354 KMFolderIndex* mParent;
00355 bool mDirty;
00356 off_t mIndexOffset;
00357 short mIndexLength;
00358 bool mEnableUndo;
00359 mutable KMMsgStatus mStatus;
00360
00361
00362 mutable KMLegacyMsgStatus mLegacyStatus;
00363
00364 public:
00365 enum MsgPartType
00366 {
00367 MsgNoPart = 0,
00368
00369 MsgFromPart = 1,
00370 MsgSubjectPart = 2,
00371 MsgToPart = 3,
00372 MsgReplyToIdMD5Part = 4,
00373 MsgIdMD5Part = 5,
00374 MsgXMarkPart = 6,
00375
00376 MsgOffsetPart = 7,
00377 MsgLegacyStatusPart = 8,
00378 MsgSizePart = 9,
00379 MsgDatePart = 10,
00380 MsgFilePart = 11,
00381 MsgCryptoStatePart = 12,
00382 MsgMDNSentPart = 13,
00383
00384 MsgReplyToAuxIdMD5Part = 14,
00385 MsgStrippedSubjectMD5Part = 15,
00386
00387 MsgStatusPart = 16
00388 };
00390 off_t getLongPart(MsgPartType) const;
00392 QString getStringPart(MsgPartType) const;
00394 bool syncIndexString() const;
00395 };
00396
00397 #endif