kmail

kmmsginfo.cpp

Go to the documentation of this file.
00001 // kmmsginfo.cpp
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include "kmmsginfo.h"
00008 #include "kmmessage.h"
00009 //#include "kmmsgpart.h" // for encode
00010 
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include <stdio.h>
00014 #include <assert.h>
00015 #include <mimelib/datetime.h>
00016 
00017 class KMMsgInfo::KMMsgInfoPrivate
00018 {
00019 public:
00020     enum {
00021         SUBJECT_SET = 0x01, TO_SET = 0x02, REPLYTO_SET = 0x04, MSGID_SET=0x08,
00022         DATE_SET = 0x10, OFFSET_SET = 0x20, SIZE_SET = 0x40, SIZESERVER_SET = 0x80,
00023         XMARK_SET=0x100, FROM_SET=0x200, FILE_SET=0x400, ENCRYPTION_SET=0x800,
00024         SIGNATURE_SET=0x1000, MDN_SET=0x2000, REPLYTOAUX_SET = 0x4000,
00025         STRIPPEDSUBJECT_SET = 0x8000,  UID_SET = 0x10000,
00026 
00027         ALL_SET = 0xFFFFFF, NONE_SET = 0x000000
00028     };
00029     uint modifiers;
00030     QString subject, from, to, replyToIdMD5, replyToAuxIdMD5,
00031             strippedSubjectMD5, msgIdMD5, xmark, file;
00032     off_t folderOffset;
00033     size_t msgSize, msgSizeServer;
00034     time_t date;
00035     KMMsgEncryptionState encryptionState;
00036     KMMsgSignatureState signatureState;
00037     KMMsgMDNSentState mdnSentState;
00038     ulong UID;
00039 
00040     KMMsgInfoPrivate() : modifiers(NONE_SET) { }
00041     KMMsgInfoPrivate& operator=(const KMMsgInfoPrivate& other) {
00042         modifiers = NONE_SET;
00043         if (other.modifiers & SUBJECT_SET) {
00044             modifiers |= SUBJECT_SET;
00045             subject = other.subject;
00046         }
00047         if (other.modifiers & STRIPPEDSUBJECT_SET) {
00048             modifiers |= STRIPPEDSUBJECT_SET;
00049             strippedSubjectMD5 = other.strippedSubjectMD5;
00050         }
00051         if (other.modifiers & FROM_SET) {
00052             modifiers |= FROM_SET;
00053             from = other.from;
00054         }
00055         if (other.modifiers & FILE_SET) {
00056             modifiers |= FILE_SET;
00057             file = other.from;
00058         }
00059         if (other.modifiers & TO_SET) {
00060             modifiers |= TO_SET;
00061             to = other.to;
00062         }
00063         if (other.modifiers & REPLYTO_SET) {
00064             modifiers |= REPLYTO_SET;
00065             replyToIdMD5 = other.replyToIdMD5;
00066         }
00067         if (other.modifiers & REPLYTOAUX_SET) {
00068             modifiers |= REPLYTOAUX_SET;
00069             replyToAuxIdMD5 = other.replyToAuxIdMD5;
00070         }
00071 
00072         if(other.modifiers & MSGID_SET) {
00073             modifiers |= MSGID_SET;
00074             msgIdMD5 = other.msgIdMD5;
00075         }
00076         if(other.modifiers & XMARK_SET) {
00077             modifiers |= XMARK_SET;
00078             xmark = other.xmark;
00079         }
00080         if(other.modifiers & OFFSET_SET) {
00081             modifiers |= OFFSET_SET;
00082             folderOffset = other.folderOffset;
00083         }
00084         if(other.modifiers & SIZE_SET) {
00085             modifiers |= SIZE_SET;
00086             msgSize = other.msgSize;
00087         }
00088         if(other.modifiers & DATE_SET) {
00089             modifiers |= DATE_SET;
00090             date = other.date;
00091         }
00092         if(other.modifiers & ENCRYPTION_SET) {
00093             modifiers |= ENCRYPTION_SET;
00094             encryptionState = other.encryptionState;
00095         }
00096         if(other.modifiers & SIGNATURE_SET) {
00097             modifiers |= SIGNATURE_SET;
00098             signatureState = other.signatureState;
00099         }
00100         if(other.modifiers & MDN_SET) {
00101             modifiers |= MDN_SET;
00102             mdnSentState = other.mdnSentState;
00103         }
00104         if(other.modifiers & SIZESERVER_SET) {
00105             modifiers |= SIZESERVER_SET;
00106             msgSizeServer = other.msgSizeServer;
00107         }
00108         if(other.modifiers & UID_SET) {
00109             modifiers |= UID_SET;
00110             UID = other.UID;
00111         }
00112         return *this;
00113     }
00114 };
00115 
00116 //-----------------------------------------------------------------------------
00117 KMMsgInfo::KMMsgInfo(KMFolder* p, off_t off, short len) :
00118     KMMsgBase(p),
00119     kd(0)
00120 {
00121     setIndexOffset(off);
00122     setIndexLength(len);
00123     setEnableUndo(true);
00124 }
00125 
00126 
00127 //-----------------------------------------------------------------------------
00128 KMMsgInfo::~KMMsgInfo()
00129 {
00130     delete kd;
00131 }
00132 
00133 
00134 #if 0 // currently unused
00135 //-----------------------------------------------------------------------------
00136 KMMsgInfo& KMMsgInfo::operator=(const KMMsgInfo& other)
00137 {
00138     KMMsgBase::assign(&other);
00139     if(other.kd) {
00140         if(!kd)
00141             kd = new KMMsgInfoPrivate;
00142         *kd = *other.kd;
00143     } else {
00144         delete kd;
00145         kd = 0;
00146     }
00147     mStatus = other.status();
00148     return *this;
00149 }
00150 #endif
00151 
00152 //-----------------------------------------------------------------------------
00153 KMMsgInfo& KMMsgInfo::operator=(const KMMessage& msg)
00154 {
00155     KMMsgBase::assign(&msg.toMsgBase());
00156     if(!kd)
00157         kd = new KMMsgInfoPrivate;
00158     kd->modifiers = KMMsgInfoPrivate::ALL_SET;
00159     kd->subject = msg.subject();
00160     kd->from = msg.fromStrip();
00161     kd->to = msg.toStrip();
00162     kd->replyToIdMD5 = msg.replyToIdMD5();
00163     kd->replyToAuxIdMD5 = msg.replyToAuxIdMD5();
00164     kd->strippedSubjectMD5 = msg.strippedSubjectMD5();
00165     kd->msgIdMD5 = msg.msgIdMD5();
00166     kd->xmark = msg.xmark();
00167     mStatus = msg.status();
00168     kd->folderOffset = msg.folderOffset();
00169     kd->msgSize = msg.msgSize();
00170     kd->date = msg.date();
00171     kd->file = msg.fileName();
00172     kd->encryptionState = msg.encryptionState();
00173     kd->signatureState = msg.signatureState();
00174     kd->mdnSentState = msg.mdnSentState();
00175     kd->msgSizeServer = msg.msgSizeServer();
00176     kd->UID = msg.UID();
00177     return *this;
00178 }
00179 
00180 //-----------------------------------------------------------------------------
00181 void KMMsgInfo::init(const QCString& aSubject, const QCString& aFrom,
00182                      const QCString& aTo, time_t aDate,
00183                      KMMsgStatus aStatus, const QCString& aXMark,
00184                      const QCString& replyToId, const QCString& replyToAuxId,
00185                      const QCString& msgId,
00186                      KMMsgEncryptionState encryptionState,
00187                      KMMsgSignatureState signatureState,
00188                      KMMsgMDNSentState mdnSentState,
00189                      const QCString& prefCharset,
00190              off_t aFolderOffset, size_t aMsgSize,
00191              size_t aMsgSizeServer, ulong aUID)
00192 {
00193     mIndexOffset = 0;
00194     mIndexLength = 0;
00195     if(!kd)
00196         kd = new KMMsgInfoPrivate;
00197     kd->modifiers = KMMsgInfoPrivate::ALL_SET;
00198     kd->subject = decodeRFC2047String(aSubject, prefCharset);
00199     kd->from = decodeRFC2047String( KMMessage::stripEmailAddr( aFrom ), prefCharset );
00200     kd->to = decodeRFC2047String( KMMessage::stripEmailAddr( aTo ), prefCharset );
00201     kd->replyToIdMD5 = base64EncodedMD5( replyToId );
00202     kd->replyToAuxIdMD5 = base64EncodedMD5( replyToAuxId );
00203     kd->strippedSubjectMD5 = base64EncodedMD5( KMMessage::stripOffPrefixes( kd->subject ), true /*utf8*/ );
00204     kd->msgIdMD5 = base64EncodedMD5( msgId );
00205     kd->xmark = aXMark;
00206     kd->folderOffset = aFolderOffset;
00207     mStatus    = aStatus;
00208     kd->msgSize = aMsgSize;
00209     kd->date = aDate;
00210     kd->file = "";
00211     kd->encryptionState = encryptionState;
00212     kd->signatureState = signatureState;
00213     kd->mdnSentState = mdnSentState;
00214     kd->msgSizeServer = aMsgSizeServer;
00215     kd->UID = aUID;
00216     mDirty     = false;
00217 }
00218 
00219 void KMMsgInfo::init(const QCString& aSubject, const QCString& aFrom,
00220                      const QCString& aTo, time_t aDate,
00221                      KMMsgStatus aStatus, const QCString& aXMark,
00222                      const QCString& replyToId, const QCString& replyToAuxId,
00223                      const QCString& msgId,
00224                      const QCString& aFileName,
00225                      KMMsgEncryptionState encryptionState,
00226                      KMMsgSignatureState signatureState,
00227                      KMMsgMDNSentState mdnSentState,
00228                      const QCString& prefCharset,
00229                      size_t aMsgSize,
00230              size_t aMsgSizeServer, ulong aUID)
00231 {
00232   // use the "normal" init for most stuff
00233   init( aSubject, aFrom, aTo, aDate, aStatus, aXMark, replyToId, replyToAuxId,
00234         msgId, encryptionState, signatureState, mdnSentState, prefCharset,
00235         (unsigned long)0, aMsgSize, aMsgSizeServer, aUID );
00236   kd->file = aFileName;
00237 }
00238 
00239 
00240 //-----------------------------------------------------------------------------
00241 QString KMMsgInfo::subject(void) const
00242 {
00243     if (kd && kd->modifiers & KMMsgInfoPrivate::SUBJECT_SET)
00244         return kd->subject;
00245     return getStringPart(MsgSubjectPart);
00246 }
00247 
00248 
00249 //-----------------------------------------------------------------------------
00250 QString KMMsgInfo::fromStrip(void) const
00251 {
00252     if (kd && kd->modifiers & KMMsgInfoPrivate::FROM_SET)
00253         return kd->from;
00254     return getStringPart(MsgFromPart);
00255 }
00256 
00257 //-----------------------------------------------------------------------------
00258 QString KMMsgInfo::fileName(void) const
00259 {
00260     if (kd && kd->modifiers & KMMsgInfoPrivate::FILE_SET)
00261         return kd->file;
00262     return getStringPart(MsgFilePart);
00263 }
00264 
00265 
00266 //-----------------------------------------------------------------------------
00267 QString KMMsgInfo::toStrip(void) const
00268 {
00269     if (kd && kd->modifiers & KMMsgInfoPrivate::TO_SET)
00270         return kd->to;
00271     return getStringPart(MsgToPart);
00272 }
00273 
00274 //-----------------------------------------------------------------------------
00275 QString KMMsgInfo::xmark(void) const
00276 {
00277     if (kd && kd->modifiers & KMMsgInfoPrivate::XMARK_SET)
00278         return kd->xmark;
00279     return getStringPart(MsgXMarkPart);
00280 }
00281 
00282 
00283 //-----------------------------------------------------------------------------
00284 QString KMMsgInfo::replyToIdMD5(void) const
00285 {
00286     if (kd && kd->modifiers & KMMsgInfoPrivate::REPLYTO_SET)
00287         return kd->replyToIdMD5;
00288     return getStringPart(MsgReplyToIdMD5Part);
00289 }
00290 
00291 //-----------------------------------------------------------------------------
00292 QString KMMsgInfo::replyToAuxIdMD5() const
00293 {
00294     if( kd && kd->modifiers & KMMsgInfoPrivate::REPLYTOAUX_SET )
00295         return kd->replyToAuxIdMD5;
00296     return getStringPart( MsgReplyToAuxIdMD5Part );
00297 }
00298 
00299 //-----------------------------------------------------------------------------
00300 QString KMMsgInfo::strippedSubjectMD5() const
00301 {
00302     if( kd && kd->modifiers & KMMsgInfoPrivate::STRIPPEDSUBJECT_SET )
00303         return kd->strippedSubjectMD5;
00304     return getStringPart( MsgStrippedSubjectMD5Part );
00305 }
00306 
00307 
00308 //-----------------------------------------------------------------------------
00309 bool KMMsgInfo::subjectIsPrefixed() const
00310 {
00311     return strippedSubjectMD5() != base64EncodedMD5( subject().stripWhiteSpace(), true /*utf8*/ );
00312 }
00313 
00314 //-----------------------------------------------------------------------------
00315 QString KMMsgInfo::msgIdMD5(void) const
00316 {
00317     if (kd && kd->modifiers & KMMsgInfoPrivate::MSGID_SET)
00318         return kd->msgIdMD5;
00319     return getStringPart(MsgIdMD5Part);
00320 }
00321 
00322 
00323 //-----------------------------------------------------------------------------
00324 void KMMsgInfo::setSubject(const QString& aSubject)
00325 {
00326     if(aSubject == subject())
00327         return;
00328 
00329     if (!kd)
00330         kd = new KMMsgInfoPrivate;
00331     kd->modifiers |= KMMsgInfoPrivate::SUBJECT_SET;
00332     kd->subject = aSubject;
00333     mDirty = true;
00334 }
00335 
00336 
00337 //-----------------------------------------------------------------------------
00338 void KMMsgInfo::setXMark(const QString& aXMark)
00339 {
00340     if (aXMark == xmark())
00341         return;
00342 
00343     if (!kd)
00344         kd = new KMMsgInfoPrivate;
00345     kd->modifiers |= KMMsgInfoPrivate::XMARK_SET;
00346     kd->xmark = aXMark;
00347     mDirty = true;
00348 }
00349 
00350 
00351 //-----------------------------------------------------------------------------
00352 void KMMsgInfo::setReplyToIdMD5(const QString& aReplyToIdMD5)
00353 {
00354     if (aReplyToIdMD5 == replyToIdMD5())
00355         return;
00356 
00357     if (!kd)
00358         kd = new KMMsgInfoPrivate;
00359     kd->modifiers |= KMMsgInfoPrivate::REPLYTO_SET;
00360     kd->replyToIdMD5 = aReplyToIdMD5;
00361     mDirty = true;
00362 }
00363 
00364 
00365 //-----------------------------------------------------------------------------
00366 void KMMsgInfo::setReplyToAuxIdMD5( const QString& aReplyToAuxIdMD5 )
00367 {
00368     if( aReplyToAuxIdMD5 == replyToAuxIdMD5() )
00369         return;
00370 
00371     if( !kd )
00372         kd = new KMMsgInfoPrivate;
00373     kd->modifiers |= KMMsgInfoPrivate::REPLYTOAUX_SET;
00374     kd->replyToAuxIdMD5 = aReplyToAuxIdMD5;
00375     mDirty = true;
00376 }
00377 
00378 
00379 //-----------------------------------------------------------------------------
00380 void KMMsgInfo::initStrippedSubjectMD5()
00381 {
00382     if( kd && kd->modifiers & KMMsgInfoPrivate::STRIPPEDSUBJECT_SET )
00383         return;
00384     QString rawSubject = KMMessage::stripOffPrefixes( subject() );
00385     QString subjectMD5 = base64EncodedMD5( rawSubject, true /*utf8*/ );
00386     if( !kd )
00387         kd = new KMMsgInfoPrivate;
00388     kd->modifiers |= KMMsgInfoPrivate::STRIPPEDSUBJECT_SET;
00389     kd->strippedSubjectMD5 = subjectMD5;
00390     mDirty = true;
00391 }
00392 
00393 
00394 //-----------------------------------------------------------------------------
00395 void KMMsgInfo::setMsgIdMD5(const QString& aMsgIdMD5)
00396 {
00397     if (aMsgIdMD5 == msgIdMD5())
00398         return;
00399 
00400     if (!kd)
00401         kd = new KMMsgInfoPrivate;
00402     kd->modifiers |= KMMsgInfoPrivate::MSGID_SET;
00403     kd->msgIdMD5 = aMsgIdMD5;
00404     mDirty = true;
00405 }
00406 
00407 //-----------------------------------------------------------------------------
00408 void KMMsgInfo::setEncryptionState( const KMMsgEncryptionState s, int idx )
00409 {
00410     if (s == encryptionState())
00411         return;
00412 
00413     if (!kd)
00414         kd = new KMMsgInfoPrivate;
00415     kd->modifiers |= KMMsgInfoPrivate::ENCRYPTION_SET;
00416     kd->encryptionState = s;
00417     KMMsgBase::setEncryptionState(s, idx); //base does more "stuff"
00418     mDirty = true;
00419 }
00420 
00421 //-----------------------------------------------------------------------------
00422 void KMMsgInfo::setSignatureState( const KMMsgSignatureState s, int idx )
00423 {
00424     if (s == signatureState())
00425         return;
00426 
00427     if (!kd)
00428         kd = new KMMsgInfoPrivate;
00429     kd->modifiers |= KMMsgInfoPrivate::SIGNATURE_SET;
00430     kd->signatureState = s;
00431     KMMsgBase::setSignatureState(s, idx); //base does more "stuff"
00432     mDirty = true;
00433 }
00434 
00435 //-----------------------------------------------------------------------------
00436 void KMMsgInfo::setMDNSentState( const KMMsgMDNSentState s, int idx )
00437 {
00438     if (s == mdnSentState())
00439         return;
00440 
00441     if (!kd)
00442         kd = new KMMsgInfoPrivate;
00443     kd->modifiers |= KMMsgInfoPrivate::MDN_SET;
00444     kd->mdnSentState = s;
00445     KMMsgBase::setMDNSentState(s, idx); //base does more "stuff"
00446     mDirty = true;
00447 }
00448 
00449 //-----------------------------------------------------------------------------
00450 KMMsgStatus KMMsgInfo::status(void) const
00451 {
00452     if (mStatus == KMMsgStatusUnknown) {
00453         KMMsgStatus st = (KMMsgStatus)getLongPart(MsgStatusPart);
00454         if (!st) {
00455             // We are opening an old index for the first time, get the legacy
00456             // status and merge it in.
00457             mLegacyStatus = (KMLegacyMsgStatus)getLongPart(MsgLegacyStatusPart);
00458             st = KMMsgStatusRead;
00459             switch (mLegacyStatus) {
00460                 case KMLegacyMsgStatusUnknown:
00461                     st = KMMsgStatusUnknown;
00462                     break;
00463                 case KMLegacyMsgStatusNew:
00464                     st = KMMsgStatusNew;
00465                     break;
00466                 case KMLegacyMsgStatusUnread:
00467                     st = KMMsgStatusUnread;
00468                     break;
00469                 case KMLegacyMsgStatusRead:
00470                     st = KMMsgStatusRead;
00471                     break;
00472                 case KMLegacyMsgStatusOld:
00473                     st = KMMsgStatusOld;
00474                     break;
00475                 case KMLegacyMsgStatusDeleted:
00476                     st |= KMMsgStatusDeleted;
00477                     break;
00478                 case KMLegacyMsgStatusReplied:
00479                     st |= KMMsgStatusReplied;
00480                     break;
00481                 case KMLegacyMsgStatusForwarded:
00482                     st |= KMMsgStatusForwarded;
00483                     break;
00484                 case KMLegacyMsgStatusQueued:
00485                     st |= KMMsgStatusQueued;
00486                     break;
00487                 case KMLegacyMsgStatusSent:
00488                     st |= KMMsgStatusSent;
00489                     break;
00490                 case KMLegacyMsgStatusFlag:
00491                     st |= KMMsgStatusFlag;
00492                     break;
00493                 default:
00494                     break;
00495             }
00496 
00497         }
00498         mStatus = st;
00499     }
00500     return mStatus;
00501 }
00502 
00503 
00504 //-----------------------------------------------------------------------------
00505 KMMsgEncryptionState KMMsgInfo::encryptionState() const
00506 {
00507     if (kd && kd->modifiers & KMMsgInfoPrivate::ENCRYPTION_SET)
00508       return kd->encryptionState;
00509     unsigned long encState = getLongPart(MsgCryptoStatePart) & 0x0000FFFF;
00510     return encState ? (KMMsgEncryptionState)encState : KMMsgEncryptionStateUnknown;
00511 }
00512 
00513 
00514 KMMsgSignatureState KMMsgInfo::signatureState() const
00515 {
00516     if (kd && kd->modifiers & KMMsgInfoPrivate::SIGNATURE_SET)
00517       return kd->signatureState;
00518     unsigned long sigState = getLongPart(MsgCryptoStatePart) >> 16;
00519     return sigState ? (KMMsgSignatureState)sigState : KMMsgSignatureStateUnknown;
00520 }
00521 
00522 KMMsgMDNSentState KMMsgInfo::mdnSentState() const {
00523     if (kd && kd->modifiers & KMMsgInfoPrivate::MDN_SET)
00524       return kd->mdnSentState;
00525     unsigned long mdnState = getLongPart(MsgMDNSentPart);
00526     return mdnState ? (KMMsgMDNSentState)mdnState : KMMsgMDNStateUnknown;
00527 }
00528 
00529 
00530 //-----------------------------------------------------------------------------
00531 off_t KMMsgInfo::folderOffset(void) const
00532 {
00533     if (kd && kd->modifiers & KMMsgInfoPrivate::OFFSET_SET)
00534         return kd->folderOffset;
00535     return getLongPart(MsgOffsetPart);
00536 }
00537 
00538 //-----------------------------------------------------------------------------
00539 size_t KMMsgInfo::msgSize(void) const
00540 {
00541     if (kd && kd->modifiers & KMMsgInfoPrivate::SIZE_SET)
00542         return kd->msgSize;
00543     return getLongPart(MsgSizePart);
00544 }
00545 
00546 //-----------------------------------------------------------------------------
00547 time_t KMMsgInfo::date(void) const
00548 {
00549     time_t res;
00550     if (kd && kd->modifiers & KMMsgInfoPrivate::DATE_SET)
00551       res = kd->date;
00552     else
00553       res = getLongPart(MsgDatePart);
00554     return res;
00555 }
00556 
00557 //-----------------------------------------------------------------------------
00558 size_t KMMsgInfo::msgSizeServer(void) const
00559 {
00560     if (kd && kd->modifiers & KMMsgInfoPrivate::SIZESERVER_SET)
00561       return kd->msgSizeServer;
00562     return getLongPart(MsgSizeServerPart);
00563 }
00564 
00565 //-----------------------------------------------------------------------------
00566 ulong KMMsgInfo::UID(void) const
00567 {
00568     if (kd && kd->modifiers & KMMsgInfoPrivate::UID_SET)
00569       return kd->UID;
00570     return getLongPart(MsgUIDPart);
00571 }
00572 
00573 //-----------------------------------------------------------------------------
00574 void KMMsgInfo::setMsgSize(size_t sz)
00575 {
00576     if (sz == msgSize())
00577         return;
00578 
00579     if(!kd)
00580         kd = new KMMsgInfoPrivate;
00581     kd->modifiers |= KMMsgInfoPrivate::SIZE_SET;
00582     kd->msgSize = sz;
00583     mDirty = true;
00584 }
00585 
00586 //-----------------------------------------------------------------------------
00587 void KMMsgInfo::setMsgSizeServer(size_t sz)
00588 {
00589     if (sz == msgSizeServer())
00590       return;
00591 
00592     if(!kd)
00593       kd = new KMMsgInfoPrivate;
00594     kd->modifiers |= KMMsgInfoPrivate::SIZESERVER_SET;
00595     kd->msgSizeServer = sz;
00596     mDirty = true;
00597 }
00598 
00599 //-----------------------------------------------------------------------------
00600 void KMMsgInfo::setUID(ulong uid)
00601 {
00602     if (uid == UID())
00603       return;
00604 
00605     if(!kd)
00606       kd = new KMMsgInfoPrivate;
00607     kd->modifiers |= KMMsgInfoPrivate::UID_SET;
00608     kd->UID = uid;
00609     mDirty = true;
00610 }
00611 
00612 //-----------------------------------------------------------------------------
00613 void KMMsgInfo::setFolderOffset(off_t offs)
00614 {
00615     if (folderOffset() == offs)
00616         return;
00617 
00618     if (!kd)
00619         kd = new KMMsgInfoPrivate;
00620     kd->modifiers |= KMMsgInfoPrivate::OFFSET_SET;
00621     kd->folderOffset = offs;
00622     mDirty = true;
00623 }
00624 
00625 //-----------------------------------------------------------------------------
00626 void KMMsgInfo::setFileName(const QString& file)
00627 {
00628     if (fileName() == file)
00629         return;
00630 
00631     if (!kd)
00632         kd = new KMMsgInfoPrivate;
00633     kd->modifiers |= KMMsgInfoPrivate::FILE_SET;
00634     kd->file = file;
00635     mDirty = true;
00636 }
00637 
00638 //-----------------------------------------------------------------------------
00639 void KMMsgInfo::setStatus(const KMMsgStatus aStatus, int idx)
00640 {
00641     if(aStatus == status())
00642         return;
00643     KMMsgBase::setStatus(aStatus, idx); //base does more "stuff"
00644 }
00645 
00646 //-----------------------------------------------------------------------------
00647 void KMMsgInfo::setDate(time_t aUnixTime)
00648 {
00649     if(aUnixTime == date())
00650         return;
00651 
00652     if(!kd)
00653         kd = new KMMsgInfoPrivate;
00654     kd->modifiers |= KMMsgInfoPrivate::DATE_SET;
00655     kd->date = aUnixTime;
00656     mDirty = true;
00657 }
00658 
00659 //--- For compatability with old index files
00660 void KMMsgInfo::compat_fromOldIndexString(const QCString& str, bool toUtf8)
00661 {
00662     char *start, *offset;
00663 
00664     if(!kd)
00665         kd = new KMMsgInfoPrivate;
00666     kd->modifiers = KMMsgInfoPrivate::ALL_SET;
00667     kd->xmark   = str.mid(33, 3).stripWhiteSpace();
00668     kd->folderOffset = str.mid(2,9).toULong();
00669     kd->msgSize = str.mid(12,9).toULong();
00670     kd->date = (time_t)str.mid(22,10).toULong();
00671     mStatus = (KMMsgStatus)str.at(0);
00672     if (toUtf8) {
00673         kd->subject = str.mid(37, 100).stripWhiteSpace();
00674         kd->from = str.mid(138, 50).stripWhiteSpace();
00675         kd->to = str.mid(189, 50).stripWhiteSpace();
00676     } else {
00677         start = offset = str.data() + 37;
00678         while (*start == ' ' && start - offset < 100) start++;
00679         kd->subject = QString::fromUtf8(str.mid(start - str.data(),
00680             100 - (start - offset)), 100 - (start - offset));
00681         start = offset = str.data() + 138;
00682         while (*start == ' ' && start - offset < 50) start++;
00683         kd->from = QString::fromUtf8(str.mid(start - str.data(),
00684             50 - (start - offset)), 50 - (start - offset));
00685         start = offset = str.data() + 189;
00686         while (*start == ' ' && start - offset < 50) start++;
00687         kd->to = QString::fromUtf8(str.mid(start - str.data(),
00688             50 - (start - offset)), 50 - (start - offset));
00689     }
00690     kd->replyToIdMD5 = str.mid(240, 22).stripWhiteSpace();
00691     kd->msgIdMD5 = str.mid(263, 22).stripWhiteSpace();
00692     mDirty = false;
00693 }
00694 
00695 bool KMMsgInfo::dirty(void) const
00696 {
00697     if( KMMsgBase::dirty() )
00698       return true;
00699     return kd && kd->modifiers != KMMsgInfoPrivate::NONE_SET;
00700 }