15 #include <mimelib/datetime.h>
17 class KMMsgInfo::KMMsgInfoPrivate
21 SUBJECT_SET = 0x01, TOSTRIP_SET = 0x02, REPLYTO_SET = 0x04, MSGID_SET=0x08,
22 DATE_SET = 0x10, OFFSET_SET = 0x20, SIZE_SET = 0x40, SIZESERVER_SET = 0x80,
23 XMARK_SET=0x100, FROMSTRIP_SET=0x200, FILE_SET=0x400, ENCRYPTION_SET=0x800,
24 SIGNATURE_SET=0x1000, MDN_SET=0x2000, REPLYTOAUX_SET = 0x4000,
25 STRIPPEDSUBJECT_SET = 0x8000, UID_SET = 0x10000,
26 TO_SET = 0x20000, FROM_SET = 0x40000,
28 ALL_SET = 0xFFFFFF, NONE_SET = 0x000000
31 TQString subject, fromStrip, toStrip, replyToIdMD5, replyToAuxIdMD5,
32 strippedSubjectMD5, msgIdMD5, xmark, file;
34 size_t msgSize, msgSizeServer;
36 KMMsgEncryptionState encryptionState;
37 KMMsgSignatureState signatureState;
38 KMMsgMDNSentState mdnSentState;
42 KMMsgInfoPrivate() : modifiers(NONE_SET) { }
43 KMMsgInfoPrivate& operator=(
const KMMsgInfoPrivate& other) {
45 if (other.modifiers & SUBJECT_SET) {
46 modifiers |= SUBJECT_SET;
47 subject = other.subject;
49 if (other.modifiers & STRIPPEDSUBJECT_SET) {
50 modifiers |= STRIPPEDSUBJECT_SET;
51 strippedSubjectMD5 = other.strippedSubjectMD5;
53 if (other.modifiers & FROMSTRIP_SET) {
54 modifiers |= FROMSTRIP_SET;
55 fromStrip = other.fromStrip;
57 if (other.modifiers & FILE_SET) {
58 modifiers |= FILE_SET;
61 if (other.modifiers & TOSTRIP_SET) {
62 modifiers |= TOSTRIP_SET;
63 toStrip = other.toStrip;
65 if (other.modifiers & REPLYTO_SET) {
66 modifiers |= REPLYTO_SET;
67 replyToIdMD5 = other.replyToIdMD5;
69 if (other.modifiers & REPLYTOAUX_SET) {
70 modifiers |= REPLYTOAUX_SET;
71 replyToAuxIdMD5 = other.replyToAuxIdMD5;
74 if(other.modifiers & MSGID_SET) {
75 modifiers |= MSGID_SET;
76 msgIdMD5 = other.msgIdMD5;
78 if(other.modifiers & XMARK_SET) {
79 modifiers |= XMARK_SET;
82 if(other.modifiers & OFFSET_SET) {
83 modifiers |= OFFSET_SET;
84 folderOffset = other.folderOffset;
86 if(other.modifiers & SIZE_SET) {
87 modifiers |= SIZE_SET;
88 msgSize = other.msgSize;
90 if(other.modifiers & DATE_SET) {
91 modifiers |= DATE_SET;
94 if(other.modifiers & ENCRYPTION_SET) {
95 modifiers |= ENCRYPTION_SET;
96 encryptionState = other.encryptionState;
98 if(other.modifiers & SIGNATURE_SET) {
99 modifiers |= SIGNATURE_SET;
100 signatureState = other.signatureState;
102 if(other.modifiers & MDN_SET) {
103 modifiers |= MDN_SET;
104 mdnSentState = other.mdnSentState;
106 if(other.modifiers & SIZESERVER_SET) {
107 modifiers |= SIZESERVER_SET;
108 msgSizeServer = other.msgSizeServer;
110 if(other.modifiers & UID_SET) {
111 modifiers |= UID_SET;
114 if (other.modifiers & TO_SET) {
118 if (other.modifiers & FROM_SET) {
119 modifiers |= FROM_SET;
127 KMMsgInfo::KMMsgInfo(
KMFolder* p, off_t off,
short len) :
138 KMMsgInfo::~KMMsgInfo()
146 KMMsgInfo& KMMsgInfo::operator=(
const KMMsgInfo& other)
148 KMMsgBase::assign(&other);
151 kd =
new KMMsgInfoPrivate;
157 mStatus = other.status();
163 KMMsgInfo& KMMsgInfo::operator=(
const KMMessage& msg)
167 kd =
new KMMsgInfoPrivate;
168 kd->modifiers = KMMsgInfoPrivate::ALL_SET;
170 kd->fromStrip = msg.fromStrip();
171 kd->toStrip = msg.toStrip();
172 kd->replyToIdMD5 = msg.replyToIdMD5();
175 kd->msgIdMD5 = msg.msgIdMD5();
176 kd->xmark = msg.
xmark();
180 kd->date = msg.date();
184 kd->mdnSentState = msg.mdnSentState();
188 kd->from = msg.
from();
193 void KMMsgInfo::init(
const TQCString& aSubject,
const TQCString& aFrom,
194 const TQCString& aTo, time_t aDate,
195 KMMsgStatus aStatus,
const TQCString& aXMark,
196 const TQCString& replyToId,
const TQCString& replyToAuxId,
197 const TQCString& msgId,
198 KMMsgEncryptionState encryptionState,
199 KMMsgSignatureState signatureState,
200 KMMsgMDNSentState mdnSentState,
201 const TQCString& prefCharset,
202 off_t aFolderOffset,
size_t aMsgSize,
203 size_t aMsgSizeServer, ulong aUID)
208 kd =
new KMMsgInfoPrivate;
209 kd->modifiers = KMMsgInfoPrivate::ALL_SET;
210 kd->subject = decodeRFC2047String(aSubject, prefCharset);
213 kd->replyToIdMD5 = base64EncodedMD5( replyToId );
214 kd->replyToAuxIdMD5 = base64EncodedMD5( replyToAuxId );
215 kd->strippedSubjectMD5 = base64EncodedMD5( KMMessage::stripOffPrefixes( kd->subject ),
true );
216 kd->msgIdMD5 = base64EncodedMD5( msgId );
218 kd->folderOffset = aFolderOffset;
220 kd->msgSize = aMsgSize;
223 kd->encryptionState = encryptionState;
224 kd->signatureState = signatureState;
225 kd->mdnSentState = mdnSentState;
226 kd->msgSizeServer = aMsgSizeServer;
233 void KMMsgInfo::init(
const TQCString& aSubject,
const TQCString& aFrom,
234 const TQCString& aTo, time_t aDate,
235 KMMsgStatus aStatus,
const TQCString& aXMark,
236 const TQCString& replyToId,
const TQCString& replyToAuxId,
237 const TQCString& msgId,
238 const TQCString& aFileName,
239 KMMsgEncryptionState encryptionState,
240 KMMsgSignatureState signatureState,
241 KMMsgMDNSentState mdnSentState,
242 const TQCString& prefCharset,
244 size_t aMsgSizeServer, ulong aUID)
247 init( aSubject, aFrom, aTo, aDate, aStatus, aXMark, replyToId, replyToAuxId,
248 msgId, encryptionState, signatureState, mdnSentState, prefCharset,
249 (
unsigned long)0, aMsgSize, aMsgSizeServer, aUID );
250 kd->file = aFileName;
255 TQString KMMsgInfo::subject(
void)
const
257 if (kd && kd->modifiers & KMMsgInfoPrivate::SUBJECT_SET)
259 return getStringPart(MsgSubjectPart);
263 TQString KMMsgInfo::fromStrip(
void)
const
265 if (kd && kd->modifiers & KMMsgInfoPrivate::FROMSTRIP_SET)
266 return kd->fromStrip;
267 return getStringPart(MsgFromStripPart);
271 TQString KMMsgInfo::from()
const
273 if (kd && kd->modifiers & KMMsgInfoPrivate::FROM_SET)
275 return getStringPart( MsgFromPart );
280 TQString KMMsgInfo::fileName(
void)
const
282 if (kd && kd->modifiers & KMMsgInfoPrivate::FILE_SET)
284 return getStringPart(MsgFilePart);
289 TQString KMMsgInfo::toStrip(
void)
const
291 if (kd && kd->modifiers & KMMsgInfoPrivate::TOSTRIP_SET)
293 return getStringPart(MsgToStripPart);
297 TQString KMMsgInfo::to()
const
299 if (kd && kd->modifiers & KMMsgInfoPrivate::TO_SET)
301 return getStringPart( MsgToPart );
305 TQString KMMsgInfo::xmark(
void)
const
307 if (kd && kd->modifiers & KMMsgInfoPrivate::XMARK_SET)
309 return getStringPart(MsgXMarkPart);
314 TQString KMMsgInfo::replyToIdMD5(
void)
const
316 if (kd && kd->modifiers & KMMsgInfoPrivate::REPLYTO_SET)
317 return kd->replyToIdMD5;
318 return getStringPart(MsgReplyToIdMD5Part);
322 TQString KMMsgInfo::replyToAuxIdMD5()
const
324 if( kd && kd->modifiers & KMMsgInfoPrivate::REPLYTOAUX_SET )
325 return kd->replyToAuxIdMD5;
326 return getStringPart( MsgReplyToAuxIdMD5Part );
330 TQString KMMsgInfo::strippedSubjectMD5()
const
332 if( kd && kd->modifiers & KMMsgInfoPrivate::STRIPPEDSUBJECT_SET )
333 return kd->strippedSubjectMD5;
334 return getStringPart( MsgStrippedSubjectMD5Part );
339 bool KMMsgInfo::subjectIsPrefixed()
const
341 return strippedSubjectMD5() != base64EncodedMD5( subject().stripWhiteSpace(),
true );
345 TQString KMMsgInfo::msgIdMD5(
void)
const
347 if (kd && kd->modifiers & KMMsgInfoPrivate::MSGID_SET)
349 return getStringPart(MsgIdMD5Part);
354 void KMMsgInfo::setSubject(
const TQString& aSubject)
356 if(aSubject == subject())
360 kd =
new KMMsgInfoPrivate;
361 kd->modifiers |= KMMsgInfoPrivate::SUBJECT_SET;
362 kd->subject = aSubject;
368 void KMMsgInfo::setXMark(
const TQString& aXMark)
370 if (aXMark == xmark())
374 kd =
new KMMsgInfoPrivate;
375 kd->modifiers |= KMMsgInfoPrivate::XMARK_SET;
382 void KMMsgInfo::setReplyToIdMD5(
const TQString& aReplyToIdMD5)
384 if (aReplyToIdMD5 == replyToIdMD5())
388 kd =
new KMMsgInfoPrivate;
389 kd->modifiers |= KMMsgInfoPrivate::REPLYTO_SET;
390 kd->replyToIdMD5 = aReplyToIdMD5;
396 void KMMsgInfo::setReplyToAuxIdMD5(
const TQString& aReplyToAuxIdMD5 )
398 if( aReplyToAuxIdMD5 == replyToAuxIdMD5() )
402 kd =
new KMMsgInfoPrivate;
403 kd->modifiers |= KMMsgInfoPrivate::REPLYTOAUX_SET;
404 kd->replyToAuxIdMD5 = aReplyToAuxIdMD5;
410 void KMMsgInfo::initStrippedSubjectMD5()
412 if( kd && kd->modifiers & KMMsgInfoPrivate::STRIPPEDSUBJECT_SET )
414 TQString rawSubject = KMMessage::stripOffPrefixes( subject() );
415 TQString subjectMD5 = base64EncodedMD5( rawSubject,
true );
417 kd =
new KMMsgInfoPrivate;
418 kd->modifiers |= KMMsgInfoPrivate::STRIPPEDSUBJECT_SET;
419 kd->strippedSubjectMD5 = subjectMD5;
425 void KMMsgInfo::setMsgIdMD5(
const TQString& aMsgIdMD5)
427 if (aMsgIdMD5 == msgIdMD5())
431 kd =
new KMMsgInfoPrivate;
432 kd->modifiers |= KMMsgInfoPrivate::MSGID_SET;
433 kd->msgIdMD5 = aMsgIdMD5;
438 void KMMsgInfo::setEncryptionState(
const KMMsgEncryptionState s,
int idx )
440 if (s == encryptionState())
444 kd =
new KMMsgInfoPrivate;
445 kd->modifiers |= KMMsgInfoPrivate::ENCRYPTION_SET;
446 kd->encryptionState = s;
447 KMMsgBase::setEncryptionState(s, idx);
452 void KMMsgInfo::setSignatureState(
const KMMsgSignatureState s,
int idx )
454 if (s == signatureState())
458 kd =
new KMMsgInfoPrivate;
459 kd->modifiers |= KMMsgInfoPrivate::SIGNATURE_SET;
460 kd->signatureState = s;
461 KMMsgBase::setSignatureState(s, idx);
466 void KMMsgInfo::setMDNSentState(
const KMMsgMDNSentState s,
int idx )
468 if (s == mdnSentState())
472 kd =
new KMMsgInfoPrivate;
473 kd->modifiers |= KMMsgInfoPrivate::MDN_SET;
474 kd->mdnSentState = s;
475 KMMsgBase::setMDNSentState(s, idx);
480 KMMsgStatus KMMsgInfo::status(
void)
const
482 if (mStatus == KMMsgStatusUnknown) {
483 KMMsgStatus st = (KMMsgStatus)getLongPart(MsgStatusPart);
487 mLegacyStatus = (KMLegacyMsgStatus)getLongPart(MsgLegacyStatusPart);
488 st = KMMsgStatusRead;
489 switch (mLegacyStatus) {
490 case KMLegacyMsgStatusUnknown:
491 st = KMMsgStatusUnknown;
493 case KMLegacyMsgStatusNew:
496 case KMLegacyMsgStatusUnread:
497 st = KMMsgStatusUnread;
499 case KMLegacyMsgStatusRead:
500 st = KMMsgStatusRead;
502 case KMLegacyMsgStatusOld:
505 case KMLegacyMsgStatusDeleted:
506 st |= KMMsgStatusDeleted;
508 case KMLegacyMsgStatusReplied:
509 st |= KMMsgStatusReplied;
511 case KMLegacyMsgStatusForwarded:
512 st |= KMMsgStatusForwarded;
514 case KMLegacyMsgStatusQueued:
515 st |= KMMsgStatusQueued;
517 case KMLegacyMsgStatusSent:
518 st |= KMMsgStatusSent;
520 case KMLegacyMsgStatusFlag:
521 st |= KMMsgStatusFlag;
535 KMMsgEncryptionState KMMsgInfo::encryptionState()
const
537 if (kd && kd->modifiers & KMMsgInfoPrivate::ENCRYPTION_SET)
538 return kd->encryptionState;
539 unsigned long encState = getLongPart(MsgCryptoStatePart) & 0x0000FFFF;
540 return encState ? (KMMsgEncryptionState)encState : KMMsgEncryptionStateUnknown;
544 KMMsgSignatureState KMMsgInfo::signatureState()
const
546 if (kd && kd->modifiers & KMMsgInfoPrivate::SIGNATURE_SET)
547 return kd->signatureState;
548 unsigned long sigState = getLongPart(MsgCryptoStatePart) >> 16;
549 return sigState ? (KMMsgSignatureState)sigState : KMMsgSignatureStateUnknown;
552 KMMsgMDNSentState KMMsgInfo::mdnSentState()
const {
553 if (kd && kd->modifiers & KMMsgInfoPrivate::MDN_SET)
554 return kd->mdnSentState;
555 unsigned long mdnState = getLongPart(MsgMDNSentPart);
556 return mdnState ? (KMMsgMDNSentState)mdnState : KMMsgMDNStateUnknown;
561 off_t KMMsgInfo::folderOffset(
void)
const
563 if (kd && kd->modifiers & KMMsgInfoPrivate::OFFSET_SET)
564 return kd->folderOffset;
565 return getLongPart(MsgOffsetPart);
569 size_t KMMsgInfo::msgSize(
void)
const
571 if (kd && kd->modifiers & KMMsgInfoPrivate::SIZE_SET)
573 return getLongPart(MsgSizePart);
577 time_t KMMsgInfo::date(
void)
const
580 if (kd && kd->modifiers & KMMsgInfoPrivate::DATE_SET)
583 res = getLongPart(MsgDatePart);
588 size_t KMMsgInfo::msgSizeServer(
void)
const
590 if (kd && kd->modifiers & KMMsgInfoPrivate::SIZESERVER_SET)
591 return kd->msgSizeServer;
592 return getLongPart(MsgSizeServerPart);
596 ulong KMMsgInfo::UID(
void)
const
598 if (kd && kd->modifiers & KMMsgInfoPrivate::UID_SET)
600 return getLongPart(MsgUIDPart);
604 void KMMsgInfo::setMsgSize(
size_t sz)
610 kd =
new KMMsgInfoPrivate;
611 kd->modifiers |= KMMsgInfoPrivate::SIZE_SET;
617 void KMMsgInfo::setMsgSizeServer(
size_t sz)
619 if (sz == msgSizeServer())
623 kd =
new KMMsgInfoPrivate;
624 kd->modifiers |= KMMsgInfoPrivate::SIZESERVER_SET;
625 kd->msgSizeServer = sz;
630 void KMMsgInfo::setUID(ulong uid)
636 kd =
new KMMsgInfoPrivate;
637 kd->modifiers |= KMMsgInfoPrivate::UID_SET;
643 void KMMsgInfo::setFolderOffset(off_t offs)
645 if (folderOffset() == offs)
649 kd =
new KMMsgInfoPrivate;
650 kd->modifiers |= KMMsgInfoPrivate::OFFSET_SET;
651 kd->folderOffset = offs;
656 void KMMsgInfo::setFileName(
const TQString& file)
658 if (fileName() == file)
662 kd =
new KMMsgInfoPrivate;
663 kd->modifiers |= KMMsgInfoPrivate::FILE_SET;
669 void KMMsgInfo::setStatus(
const KMMsgStatus aStatus,
int idx)
671 if(aStatus == status())
673 KMMsgBase::setStatus(aStatus, idx);
677 void KMMsgInfo::setDate(time_t aUnixTime)
679 if(aUnixTime == date())
683 kd =
new KMMsgInfoPrivate;
684 kd->modifiers |= KMMsgInfoPrivate::DATE_SET;
685 kd->date = aUnixTime;
689 void KMMsgInfo::setFrom(
const TQString &from )
692 kd =
new KMMsgInfoPrivate;
693 kd->modifiers |= KMMsgInfoPrivate::FROM_SET;
698 void KMMsgInfo::setTo(
const TQString &to )
701 kd =
new KMMsgInfoPrivate;
702 kd->modifiers |= KMMsgInfoPrivate::TO_SET;
708 void KMMsgInfo::compat_fromOldIndexString(
const TQCString& str,
bool toUtf8)
710 const char *start, *offset;
713 kd =
new KMMsgInfoPrivate;
714 kd->modifiers = KMMsgInfoPrivate::ALL_SET;
715 kd->xmark = str.mid(33, 3).stripWhiteSpace();
716 kd->folderOffset = str.mid(2,9).toULong();
717 kd->msgSize = str.mid(12,9).toULong();
718 kd->date = (time_t)str.mid(22,10).toULong();
719 mStatus = (KMMsgStatus)str.at(0);
721 kd->subject = str.mid(37, 100).stripWhiteSpace();
722 kd->fromStrip = str.mid(138, 50).stripWhiteSpace();
723 kd->toStrip = str.mid(189, 50).stripWhiteSpace();
725 start = offset = str.data() + 37;
726 while (*start ==
' ' && start - offset < 100) start++;
727 kd->subject = TQString::fromUtf8(str.mid(start - str.data(),
728 100 - (start - offset)), 100 - (start - offset));
729 start = offset = str.data() + 138;
730 while (*start ==
' ' && start - offset < 50) start++;
731 kd->fromStrip = TQString::fromUtf8(str.mid(start - str.data(),
732 50 - (start - offset)), 50 - (start - offset));
733 start = offset = str.data() + 189;
734 while (*start ==
' ' && start - offset < 50) start++;
735 kd->toStrip = TQString::fromUtf8(str.mid(start - str.data(),
736 50 - (start - offset)), 50 - (start - offset));
738 kd->replyToIdMD5 = str.mid(240, 22).stripWhiteSpace();
739 kd->msgIdMD5 = str.mid(263, 22).stripWhiteSpace();
743 bool KMMsgInfo::dirty(
void)
const
745 if( KMMsgBase::dirty() )
747 return kd && kd->modifiers != KMMsgInfoPrivate::NONE_SET;
size_t msgSizeServer() const
Get/set size on server.
TQString from() const
Get or set the 'From' header field.
TQString xmark() const
Get or set the 'X-Mark' header field.
TQString replyToAuxIdMD5() const
Get the second to last id from the References header field.
TQString to() const
Get or set the 'To' header field.
TQString subject() const
Get or set the 'Subject' header field.
KMMsgEncryptionState encryptionState() const
Encryption status of the message.
static TQCString stripEmailAddr(const TQCString &emailAddr)
This function generates a displayable string from a list of email addresses.
KMMsgStatus status() const
Status of the message.
TQString fileName() const
Get/set filename in mail folder.
TQString strippedSubjectMD5() const
Get a hash of the subject with all prefixes such as Re: removed.
off_t folderOffset() const
Get/set offset in mail folder.
size_t msgSize() const
Get/set size of message in the folder including the whole header in bytes.
KMMsgBase & toMsgBase()
Get KMMsgBase for this object.
ulong UID() const
Get/set UID.
KMMsgSignatureState signatureState() const
Signature status of the message.