diff --git a/kmfolderimap.cpp b/kmfolderimap.cpp index 5c174c7fa..4b3cef22b 100644 --- a/kmfolderimap.cpp +++ b/kmfolderimap.cpp @@ -1212,7 +1212,16 @@ void KMFolderImap::deleteMessage(KMMessage * msg) { KURL url = mAccount->getUrl(); KMFolderImap *msg_parent = static_cast(msg->storage()); - url.setPath(msg_parent->imapPath() + ";UID=" + msg->headerField("X-UID")); + QString uid = msg->headerField("X-UID"); + /* If the uid is empty the delete job below will nuke all mail in the + folder, so we better safeguard against that. See ::expungeFolder, as + to why. :( */ + if ( uid.isEmpty() ) { + kdDebug( 5006 ) << "KMFolderImap::deleteMessage: Attempt to delete " + "an empty UID. Aborting." << endl; + return; + } + url.setPath(msg_parent->imapPath() + ";UID=" + uid ); if ( mAccount->makeConnection() != ImapAccountBase::Connected ) return; KIO::SimpleJob *job = KIO::file_delete(url, FALSE); @@ -1233,7 +1242,11 @@ void KMFolderImap::deleteMessage(QPtrList msgList) KMFolderImap *msg_parent = static_cast(msgList.first()->storage()); for ( QStringList::Iterator it = sets.begin(); it != sets.end(); ++it ) { - url.setPath(msg_parent->imapPath() + ";UID=" + *it); + QString uid = *it; + // Don't delete with no uid, that nukes the folder. Should not happen, but + // better safe than sorry. + if ( uid.isEmpty() ) continue; + url.setPath(msg_parent->imapPath() + ";UID=" + uid); if ( mAccount->makeConnection() != ImapAccountBase::Connected ) return; KIO::SimpleJob *job = KIO::file_delete(url, FALSE);