diff --git a/kmmessage.cpp b/kmmessage.cpp index 140a2fc54..9580fe026 100644 --- a/kmmessage.cpp +++ b/kmmessage.cpp @@ -15,6 +15,7 @@ using KMail::MessageProperty; #include "objecttreeparser.h" using KMail::ObjectTreeParser; #include "kmfolderindex.h" +#include "kmmsgdict.h" #include "undostack.h" #include "kmversion.h" #include @@ -208,7 +209,11 @@ QCString KMMessage::id() const //----------------------------------------------------------------------------- void KMMessage::setMsgSerNum(unsigned long newMsgSerNum) { + unsigned long oldMsgSerNum = getMsgSerNum(); MessageProperty::setSerialCache( this, newMsgSerNum ); + + if ( newMsgSerNum && oldMsgSerNum ) + kmkernel->msgDict()->replace( newMsgSerNum, this ); } diff --git a/kmmsgdict.cpp b/kmmsgdict.cpp index 15883ce0d..315f36d19 100644 --- a/kmmsgdict.cpp +++ b/kmmsgdict.cpp @@ -211,6 +211,28 @@ unsigned long KMMsgDict::insert(const KMMsgBase *msg, int index) //----------------------------------------------------------------------------- +void KMMsgDict::replace(unsigned long msgSerNum, + const KMMsgBase *msg, int index) +{ + KMFolderIndex* folder = static_cast( msg->storage() ); + if ( folder && index == -1 ) + index = folder->find( msg ); + + remove( msgSerNum ); + KMMsgDictEntry *entry = new KMMsgDictEntry( folder->folder(), index ); + dict->insert( (long)msgSerNum, entry ); + + KMMsgDictREntry *rentry = folder->rDict(); + if (!rentry) { + rentry = new KMMsgDictREntry(); + folder->setRDict(rentry); + } + rentry->set(index, entry); + +} + +//----------------------------------------------------------------------------- + void KMMsgDict::remove(unsigned long msgSerNum) { long key = (long)msgSerNum; diff --git a/kmmsgdict.h b/kmmsgdict.h index d2da33494..b4c5f48f1 100644 --- a/kmmsgdict.h +++ b/kmmsgdict.h @@ -31,6 +31,10 @@ public: * serial number. */ unsigned long insert(const KMMsgBase *msg, int index = -1); + /** Set the serial number of @p msg to @p msgSerNum */ + void replace(unsigned long msgSerNum, + const KMMsgBase *msg, int index = -1); + /** Removes a message. */ void remove(unsigned long msgSerNum);