kmail

kmmsgbase.h
1 /*
2  * kmail: KDE mail client
3  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 #ifndef kmmsgbase_h
21 #define kmmsgbase_h
22 
23 // for large file support flags
24 #include <config.h>
25 #include <sys/types.h>
26 #include <tqstring.h>
27 #include <time.h>
28 
29 class TQCString;
30 class TQStringList;
31 class TQTextCodec;
32 class KMFolder;
33 class KMFolderIndex;
34 
41 enum MsgStatus
42 {
43  KMMsgStatusUnknown = 0x00000000,
44  KMMsgStatusNew = 0x00000001,
45  KMMsgStatusUnread = 0x00000002,
46  KMMsgStatusRead = 0x00000004,
47  KMMsgStatusOld = 0x00000008,
48  KMMsgStatusDeleted = 0x00000010,
49  KMMsgStatusReplied = 0x00000020,
50  KMMsgStatusForwarded = 0x00000040,
51  KMMsgStatusQueued = 0x00000080,
52  KMMsgStatusSent = 0x00000100,
53  KMMsgStatusFlag = 0x00000200, // flag means important
54  KMMsgStatusWatched = 0x00000400,
55  KMMsgStatusIgnored = 0x00000800, // forces isRead()
56  KMMsgStatusTodo = 0x00001000,
57  KMMsgStatusSpam = 0x00002000,
58  KMMsgStatusHam = 0x00004000,
59  KMMsgStatusHasAttach = 0x00008000,
60  KMMsgStatusHasNoAttach = 0x00010000,
61  KMMsgStatusHasInvitation = 0x00020000,
62  KMMsgStatusHasNoInvitation = 0x00040000
63 };
64 
65 typedef uint KMMsgStatus;
66 
70 typedef enum
71 {
72  KMLegacyMsgStatusUnknown=' ',
73  KMLegacyMsgStatusNew='N',
74  KMLegacyMsgStatusUnread='U',
75  KMLegacyMsgStatusRead='R',
76  KMLegacyMsgStatusOld='O',
77  KMLegacyMsgStatusDeleted='D',
78  KMLegacyMsgStatusReplied='A',
79  KMLegacyMsgStatusForwarded='F',
80  KMLegacyMsgStatusQueued='Q',
81  KMLegacyMsgStatusSent='S',
82  KMLegacyMsgStatusFlag='G'
83 } KMLegacyMsgStatus;
84 
85 
86 
88 typedef enum
89 {
90  KMMsgEncryptionStateUnknown=' ',
91  KMMsgNotEncrypted='N',
92  KMMsgPartiallyEncrypted='P',
93  KMMsgFullyEncrypted='F',
94  KMMsgEncryptionProblematic='X'
95 } KMMsgEncryptionState;
96 
98 typedef enum
99 {
100  KMMsgSignatureStateUnknown=' ',
101  KMMsgNotSigned='N',
102  KMMsgPartiallySigned='P',
103  KMMsgFullySigned='F',
104  KMMsgSignatureProblematic='X'
105 } KMMsgSignatureState;
106 
108 typedef enum
109 {
110  KMMsgMDNStateUnknown = ' ',
111  KMMsgMDNNone = 'N',
112  KMMsgMDNIgnore = 'I',
113  KMMsgMDNDisplayed = 'R',
114  KMMsgMDNDeleted = 'D',
115  KMMsgMDNDispatched = 'F',
116  KMMsgMDNProcessed = 'P',
117  KMMsgMDNDenied = 'X',
118  KMMsgMDNFailed = 'E'
119 } KMMsgMDNSentState;
120 
122 typedef enum
123 {
124  KMMsgDnDActionMOVE=0,
125  KMMsgDnDActionCOPY=1,
126  KMMsgDnDActionASK=2
127 } KMMsgDnDAction;
128 
130 typedef enum
131 {
132  KMMsgHasAttachment,
133  KMMsgHasNoAttachment,
134  KMMsgAttachmentUnknown
135 } KMMsgAttachmentState;
136 
138 typedef enum
139 {
140  KMMsgHasInvitation,
141  KMMsgHasNoInvitation,
142  KMMsgInvitationUnknown
143 } KMMsgInvitationState;
144 
145 class KMMsgBase
146 {
147 public:
148  KMMsgBase(KMFolder* p=0);
149  virtual ~KMMsgBase();
150 
152  KMFolderIndex* storage() const;
153 
155  KMFolder* parent() const { return mParent; }
156 
158  void setParent(KMFolder* p) { mParent = p; }
159 
161  static TQCString statusToStr(const KMMsgStatus status);
162 
164  TQString statusToSortRank();
165 
167  virtual bool isMessage(void) const;
168 
170  virtual bool isUnread(void) const;
171 
173  virtual bool isNew(void) const;
174 
176  virtual bool isOfUnknownStatus(void) const;
177 
179  virtual bool isOld(void) const;
180 
182  virtual bool isRead(void) const;
183 
185  virtual bool isDeleted(void) const;
186 
188  virtual bool isReplied(void) const;
189 
191  virtual bool isForwarded(void) const;
192 
194  virtual bool isQueued(void) const;
195 
197  virtual bool isTodo(void) const;
198 
200  virtual bool isSent(void) const;
201 
203  virtual bool isImportant(void) const;
204 
206  virtual bool isWatched(void) const;
207 
209  virtual bool isIgnored(void) const;
210 
212  virtual bool isSpam(void) const;
213 
215  virtual bool isHam(void) const;
216 
217 
219  virtual KMMsgStatus status(void) const = 0;
220 
223  virtual void setStatus(const KMMsgStatus status, int idx = -1);
224  virtual void toggleStatus(const KMMsgStatus status, int idx = -1);
225  virtual void setStatus(const char* statusField, const char* xstatusField=0);
226 
228  virtual KMMsgEncryptionState encryptionState() const = 0;
229 
231  virtual KMMsgSignatureState signatureState() const = 0;
232 
234  virtual KMMsgMDNSentState mdnSentState() const = 0;
235 
237  virtual void setMDNSentState( KMMsgMDNSentState status, int idx=-1 );
238 
242  virtual void setEncryptionState(const KMMsgEncryptionState, int idx = -1);
243 
247  virtual void setSignatureState(const KMMsgSignatureState, int idx = -1);
248 
252  virtual void setEncryptionStateChar( TQChar status, int idx = -1 );
253 
257  virtual void setSignatureStateChar( TQChar status, int idx = -1 );
258 
260  virtual TQString subject(void) const = 0;
261  virtual TQString fromStrip(void) const = 0;
262  virtual TQString from() const = 0;
263  virtual TQString toStrip(void) const = 0;
264  virtual TQString to() const = 0;
265  virtual TQString replyToIdMD5(void) const = 0;
266  virtual TQString msgIdMD5(void) const = 0;
267  virtual TQString replyToAuxIdMD5() const = 0;
268  virtual TQString strippedSubjectMD5() const = 0;
269  virtual bool subjectIsPrefixed() const = 0;
270  virtual time_t date(void) const = 0;
271  virtual TQString dateStr(void) const;
272  virtual TQString xmark(void) const = 0;
273 
275  virtual void setDate(const TQCString &aStrDate);
276  virtual void setDate(time_t aUnixTime) = 0;
277 
279  virtual bool dirty(void) const { return mDirty; }
280 
282  void setDirty(bool b) { mDirty = b; }
283 
285  virtual void setSubject(const TQString&) = 0;
286  virtual void setXMark(const TQString&) = 0;
287 
289  virtual void initStrippedSubjectMD5() = 0;
290 
292  const uchar *asIndexString(int &len) const;
293 
295  virtual off_t folderOffset(void) const = 0;
296  virtual void setFolderOffset(off_t offs) = 0;
297 
299  virtual TQString fileName(void) const = 0;
300  virtual void setFileName(const TQString& filename) = 0;
301 
303  virtual size_t msgSize(void) const = 0;
304  virtual void setMsgSize(size_t sz) = 0;
305 
307  virtual size_t msgSizeServer(void) const = 0;
308  virtual void setMsgSizeServer(size_t sz) = 0;
309 
311  virtual ulong UID(void) const = 0;
312  virtual void setUID(ulong uid) = 0;
313 
315  virtual void setIndexOffset(off_t off) { mIndexOffset = off; }
316  virtual off_t indexOffset() const { return mIndexOffset; }
317 
319  virtual void setIndexLength(short len) { mIndexLength = len; }
320  virtual short indexLength() const { return mIndexLength; }
321 
326  static TQString skipKeyword(const TQString& str, TQChar sepChar=':',
327  bool* keywordFound=0);
328 
331  static const TQTextCodec* codecForName(const TQCString& _str);
332 
336  static TQCString toUsAscii(const TQString& _str, bool *ok=0);
337 
339  static TQStringList supportedEncodings(bool usAscii);
340 
342  void assign(const KMMsgBase* other);
343 
345  KMMsgBase& operator=(const KMMsgBase& other);
346 
348  KMMsgBase( const KMMsgBase& other );
349 
351  static TQCString encodeRFC2047Quoted(const TQCString& aStr, bool base64);
352 
355  static TQString decodeRFC2047String(const TQCString& aStr, const TQCString prefCharset = "");
356 
359  static TQCString encodeRFC2047String(const TQString& aStr,
360  const TQCString& charset);
361 
364  static TQCString encodeRFC2231String(const TQString& aStr,
365  const TQCString& charset);
366 
371  static TQCString encodeRFC2231StringAutoDetectCharset( const TQString &str,
372  const TQCString &defaultCharset = "" );
373 
375  static TQString decodeRFC2231String(const TQCString& aStr);
380  static TQCString extractRFC2231HeaderField( const TQCString &aStr, const TQCString &field );
381 
385  static TQString base64EncodedMD5( const TQString & aStr, bool utf8=false );
386  static TQString base64EncodedMD5( const TQCString & aStr );
387  static TQString base64EncodedMD5( const char * aStr, int len=-1 );
388 
394  static TQCString autoDetectCharset(const TQCString &encoding, const TQStringList &encodingList, const TQString &text);
395 
397  virtual unsigned long getMsgSerNum() const;
398 
400  virtual bool enableUndo() { return mEnableUndo; }
401  virtual void setEnableUndo( bool enable ) { mEnableUndo = enable; }
402 
404  virtual KMMsgAttachmentState attachmentState() const;
405 
407  virtual KMMsgInvitationState invitationState() const;
408 
415  static TQString replacePrefixes( const TQString& str,
416  const TQStringList& prefixRegExps,
417  bool replace,
418  const TQString& newPrefix );
419 
422  static TQString stripOffPrefixes( const TQString& str );
423 
430  TQString cleanSubject(const TQStringList& prefixRegExps, bool replace,
431  const TQString& newPrefix) const;
432 
435  TQString cleanSubject() const;
436 
438  TQString forwardSubject() const;
439 
441  TQString replySubject() const;
442 
445  static void readConfig();
446 
447 protected:
448  KMFolder* mParent;
449  off_t mIndexOffset;
450  short mIndexLength;
451  bool mDirty;
452  bool mEnableUndo;
453  mutable KMMsgStatus mStatus;
454  // This is kept to provide an upgrade path from the the old single status
455  // to the new multiple status scheme.
456  mutable KMLegacyMsgStatus mLegacyStatus;
457 
458 public:
459  enum MsgPartType
460  {
461  MsgNoPart = 0,
462  //unicode strings
463  MsgFromStripPart = 1,
464  MsgSubjectPart = 2,
465  MsgToStripPart = 3,
466  MsgReplyToIdMD5Part = 4,
467  MsgIdMD5Part = 5,
468  MsgXMarkPart = 6,
469  //unsigned long
470  MsgOffsetPart = 7,
471  MsgLegacyStatusPart = 8,
472  MsgSizePart = 9,
473  MsgDatePart = 10,
474  MsgFilePart = 11,
475  MsgCryptoStatePart = 12,
476  MsgMDNSentPart = 13,
477  //another two unicode strings
478  MsgReplyToAuxIdMD5Part = 14,
479  MsgStrippedSubjectMD5Part = 15,
480  // and another unsigned long
481  MsgStatusPart = 16,
482  MsgSizeServerPart = 17,
483  MsgUIDPart = 18,
484  MsgToPart = 19,
485  MsgFromPart = 20
486  };
488  off_t getLongPart(MsgPartType) const;
490  TQString getStringPart(MsgPartType) const;
492  bool syncIndexString() const;
493 };
494 
495 #endif /*kmmsgbase_h*/
A FolderStorage with an index for faster access to often used message properties.
Definition: kmfolderindex.h:38
Mail folder.
Definition: kmfolder.h:69