Bug 68661 - kmail deletes the whole directory if it is existent. not only the one created by itself
Summary: kmail deletes the whole directory if it is existent. not only the one created...
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Applications
Component: general (show other bugs)
Version: 1.5
Platform: openSUSE Linux
: NOR grave
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-20 16:45 UTC by Benedikt Wachinger
Modified: 2007-09-14 12:17 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benedikt Wachinger 2003-11-20 16:45:15 UTC
Version:           1.5 (using KDE 3.1.0)
Installed from:    SuSE
Compiler:          gcc version 3.2
OS:          Linux (i686) release 2.4.19-4GB

Great Work!
KMail just deleted a whole folder named "Old" which was on the hard in the Mail-directory when I created one with the same name and deleted it afterwards.

This shouldn't have happened... kmail should only delete files and directorys created by kmail. not files that have been created by myself with the bash.

thanks... because of this i just lost 40MB of emails that I needed.

 Benedikt
Comment 1 Ingo Klöcker 2003-11-22 23:11:47 UTC
KMail must delete the maildir directory only if it doesn't contain non-KMail files.
Comment 2 Till Adam 2003-11-29 18:43:58 UTC
Subject: kdepim/kmail

CVS commit by tilladam: 

When the user deletes a maildir folder first delete the new, cur and tmp subdirs, then check if the dir itself is empty and only then delete the folder directory itself. This prevents data loss if the user has non-kmail data stored in a folder in ~/Mail and then creates a maildir folder of the same name and later deletes it. 
 
CCMAIL: 68661-done@bugs.kde.org 


  M +16 -3     kmfoldermaildir.cpp   1.72


--- kdepim/kmail/kmfoldermaildir.cpp  #1.71:1.72
@@ -887,7 +887,20 @@ bool KMFolderMaildir::removeFile(const Q
 int KMFolderMaildir::removeContents()
 {
-    if (KIO::NetAccess::del(KURL::fromPathOrURL(location()), 0))
-        return 0;
+    if (!KIO::NetAccess::del(KURL::fromPathOrURL(location()+ "/new/"), 0))
+        return 1;
+    if (!KIO::NetAccess::del(KURL::fromPathOrURL(location()+ "/cur/"), 0))
     return 1;
+    if (!KIO::NetAccess::del(KURL::fromPathOrURL(location()+ "/tmp/"), 0))
+        return 1;
+
+    /* The subdirs are removed now. Check if there is anything else in the dir
+     * and only if not delete the dir itself. The user could have data stored 
+     * that would otherwise be deleted. */
+    QDir *dir = new QDir(location());
+    if ( dir->count() == 2 ) { // only . and ..
+        if (!KIO::NetAccess::del(KURL::fromPathOrURL(location()), 0))
+            return 1;
+    }
+    return 0;
 }