diff --git a/kmheaders.cpp b/kmheaders.cpp index 9d70e98ba..5fd0419cb 100644 --- a/kmheaders.cpp +++ b/kmheaders.cpp @@ -1148,13 +1148,28 @@ void KMHeaders::msgHeaderChanged(KMFolder*, int msgId) //----------------------------------------------------------------------------- void KMHeaders::setMsgStatus (KMMsgStatus status, bool toggle) { + kdDebug() << k_funcinfo << endl; SerNumList serNums; - for (QListViewItemIterator it(this); it.current(); ++it) + QListViewItemIterator it(this, QListViewItemIterator::Selected|QListViewItemIterator::Visible); + while( it.current() ) { if ( it.current()->isSelected() && it.current()->isVisible() ) { + if ( it.current()->parent() && ( !it.current()->parent()->isOpen() ) ) { + // the item's parent is closed, don't traverse any more of this subtree + QListViewItem * lastAncestorWithSiblings = it.current()->parent(); + // travel towards the root until we find an ancestor with siblings + while ( ( lastAncestorWithSiblings->depth() > 0 ) && !lastAncestorWithSiblings->nextSibling() ) + lastAncestorWithSiblings = lastAncestorWithSiblings->parent(); + // move the iterator to that ancestor's next sibling + it = QListViewItemIterator( lastAncestorWithSiblings->nextSibling() ); + continue; + } + HeaderItem *item = static_cast(it.current()); KMMsgBase *msgBase = mFolder->getMsgBase(item->msgId()); serNums.append( msgBase->getMsgSerNum() ); } + ++it; + } if (serNums.empty()) return;