[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    PATCH: really delete messages in maildir folders
From:       Kurt Granroth <granroth () kde ! org>
Date:       2001-10-10 23:01:30
[Download RAW message or body]

Due to the way that folders are compacted in KMail, messages are never really
deleted in maildir folders UNLESS you do an expunge on the folder.  This
is because the "delete" methods in KMail simply remove the message from
the mMsgList.  For mbox mailboxes this is fine due to it's way of compacting
messages.  For maildir, it results in all deleted messages hanging around
forever.

AFAICT, this only affects outbox and trash since those are the only two
folders that have "true" deleted messages (all others just move to trash).

I am attaching a patch that fixes this.  It's fairly simple.. but I'm
attaching it rather than just committing it in the hope that there is a
more elegant way of doing this.  If you know of a better way, please
speak up!
-- 
Kurt Granroth            | http://www.granroth.org
KDE Developer/Evangelist | SuSE Labs Open Source Developer
granroth@kde.org         | granroth@suse.com
            KDE -- Conquer Your Desktop

["kmfoldermaildir.patch" (text/x-diff)]

Index: kmfoldermaildir.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfoldermaildir.cpp,v
retrieving revision 1.5
diff -b -u -r1.5 kmfoldermaildir.cpp
--- kmfoldermaildir.cpp	2001/10/05 22:43:14	1.5
+++ kmfoldermaildir.cpp	2001/10/10 22:57:05
@@ -256,6 +256,20 @@
   QString subdirNew(location() + "/new/");
   QString subdirCur(location() + "/cur/");
 
+  // first, get a list of all files in this folder.  we will
+  // eventually compare it to the list of messages that we already
+  // know of
+  QDir newDir(subdirNew);
+  newDir.setFilter(QDir::Files);
+  QDir curDir(subdirCur);
+  curDir.setFilter(QDir::Files);
+  QStringList fileList( newDir.entryList() + curDir.entryList() );
+
+  // we add it to a QMap to allow for faster lookups
+  QMap<QString,bool> allFiles;
+  for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it)
+    allFiles[(*it)] = true;
+
   for (int i = 0; i < count(); i++)
   {
     KMMsgInfo *mi = (KMMsgInfo*)mMsgList[i];
@@ -266,6 +280,12 @@
     if (filename.isNull() || filename.isEmpty())
       continue;
 
+    // if we have this file, we remove it from the Map.  the only
+    // files left will be deleted ones
+    QMap<QString,bool>::Iterator file_it = allFiles.find( filename );
+    if ( file_it != allFiles.end() )
+      allFiles.remove( file_it );
+
     // first, make sure this isn't in the 'new' subdir
     QString newFile(subdirNew + filename);
     if (QFile::exists(newFile))
@@ -290,6 +310,15 @@
       mDirty = TRUE;
     }
   }
+
+  // okay, any files that are left were ones that were marked deleted
+  // earlier but never physically removed from this folder.  we assume
+  // that it is in 'cur' since deleted mails should never be left in
+  // 'new'
+  QMap<QString,bool>::Iterator file;
+  for( file = allFiles.begin(); file != allFiles.end(); ++file )
+    QFile::remove(curDir.filePath(file.key()));
+
   close(true);
 
   needsCompact = false;
@@ -347,26 +376,8 @@
   QString tmp_file(location() + "/tmp/");
   tmp_file += filename;
 
-#if 0
-  if (name() == "trash")
-  {
-    filename += ".lzo";
-    tmp_file += filename;
-kdDebug(0) << "Writing to " << tmp_file << endl;
-    if (!kCStringToFile(msgText, tmp_file, false, false, true, true))
-     return 0;
-    else
-kdDebug(0) << "Write succeeded" << endl;
-  }
-  else
-  {
-  tmp_file += filename;
-#endif
   if (!kCStringToFile(msgText, tmp_file, false, false, false))
     return 0;
-#if 0
-  }
-#endif
 
   QFile file(tmp_file);
   size = msgText.length();

_______________________________________________
Kmail Developers mailing list
Kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic