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 <tqstring.h>
00027 #include <time.h>
00028
00029 class TQCString;
00030 class TQStringList;
00031 class TQTextCodec;
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 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 TQCString statusToStr(const KMMsgStatus status);
00162
00164 TQString 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( TQChar status, int idx = -1 );
00253
00257 virtual void setSignatureStateChar( TQChar status, int idx = -1 );
00258
00260 virtual TQString subject(void) const = 0;
00261 virtual TQString fromStrip(void) const = 0;
00262 virtual TQString from() const = 0;
00263 virtual TQString toStrip(void) const = 0;
00264 virtual TQString to() const = 0;
00265 virtual TQString replyToIdMD5(void) const = 0;
00266 virtual TQString msgIdMD5(void) const = 0;
00267 virtual TQString replyToAuxIdMD5() const = 0;
00268 virtual TQString strippedSubjectMD5() const = 0;
00269 virtual bool subjectIsPrefixed() const = 0;
00270 virtual time_t date(void) const = 0;
00271 virtual TQString dateStr(void) const;
00272 virtual TQString xmark(void) const = 0;
00273
00275 virtual void setDate(const TQCString &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 TQString&) = 0;
00286 virtual void setXMark(const TQString&) = 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 TQString fileName(void) const = 0;
00300 virtual void setFileName(const TQString& 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 TQString skipKeyword(const TQString& str, TQChar sepChar=':',
00327 bool* keywordFound=0);
00328
00331 static const TQTextCodec* codecForName(const TQCString& _str);
00332
00336 static TQCString toUsAscii(const TQString& _str, bool *ok=0);
00337
00339 static TQStringList 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 TQCString encodeRFC2047Quoted(const TQCString& aStr, bool base64);
00352
00355 static TQString decodeRFC2047String(const TQCString& aStr, const TQCString prefCharset = "");
00356
00359 static TQCString encodeRFC2047String(const TQString& aStr,
00360 const TQCString& charset);
00361
00364 static TQCString encodeRFC2231String(const TQString& aStr,
00365 const TQCString& charset);
00366
00371 static TQCString encodeRFC2231StringAutoDetectCharset( const TQString &str,
00372 const TQCString &defaultCharset = "" );
00373
00375 static TQString decodeRFC2231String(const TQCString& aStr);
00380 static TQCString extractRFC2231HeaderField( const TQCString &aStr, const TQCString &field );
00381
00385 static TQString base64EncodedMD5( const TQString & aStr, bool utf8=false );
00386 static TQString base64EncodedMD5( const TQCString & aStr );
00387 static TQString base64EncodedMD5( const char * aStr, int len=-1 );
00388
00394 static TQCString autoDetectCharset(const TQCString &encoding, const TQStringList &encodingList, const TQString &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 TQString replacePrefixes( const TQString& str,
00416 const TQStringList& prefixRegExps,
00417 bool replace,
00418 const TQString& newPrefix );
00419
00422 static TQString stripOffPrefixes( const TQString& str );
00423
00430 TQString cleanSubject(const TQStringList& prefixRegExps, bool replace,
00431 const TQString& newPrefix) const;
00432
00435 TQString cleanSubject() const;
00436
00438 TQString forwardSubject() const;
00439
00441 TQString 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
00455
00456 mutable KMLegacyMsgStatus mLegacyStatus;
00457
00458 public:
00459 enum MsgPartType
00460 {
00461 MsgNoPart = 0,
00462
00463 MsgFromStripPart = 1,
00464 MsgSubjectPart = 2,
00465 MsgToStripPart = 3,
00466 MsgReplyToIdMD5Part = 4,
00467 MsgIdMD5Part = 5,
00468 MsgXMarkPart = 6,
00469
00470 MsgOffsetPart = 7,
00471 MsgLegacyStatusPart = 8,
00472 MsgSizePart = 9,
00473 MsgDatePart = 10,
00474 MsgFilePart = 11,
00475 MsgCryptoStatePart = 12,
00476 MsgMDNSentPart = 13,
00477
00478 MsgReplyToAuxIdMD5Part = 14,
00479 MsgStrippedSubjectMD5Part = 15,
00480
00481 MsgStatusPart = 16,
00482 MsgSizeServerPart = 17,
00483 MsgUIDPart = 18,
00484 MsgToPart = 19,
00485 MsgFromPart = 20
00486 };
00488 off_t getLongPart(MsgPartType) const;
00490 TQString getStringPart(MsgPartType) const;
00492 bool syncIndexString() const;
00493 };
00494
00495 #endif