bincimap

Log | Files | Refs | LICENSE

maildir-expunge.cc (2461B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    maildir-expunge.cc
      5  *  
      6  *  Description:
      7  *    Implementation of the Maildir class.
      8  *
      9  *  Authors:
     10  *    Andreas Aardal Hanssen <andreas-binc curly bincimap spot org>
     11  *
     12  *  Bugs:
     13  *
     14  *  ChangeLog:
     15  *
     16  *  --------------------------------------------------------------------
     17  *  Copyright 2002-2005 Andreas Aardal Hanssen
     18  *
     19  *  This program is free software; you can redistribute it and/or modify
     20  *  it under the terms of the GNU General Public License as published by
     21  *  the Free Software Foundation; either version 2 of the License, or
     22  *  (at your option) any later version.
     23  *
     24  *  This program is distributed in the hope that it will be useful,
     25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     27  *  GNU General Public License for more details.
     28  *
     29  *  You should have received a copy of the GNU General Public License
     30  *  along with this program; if not, write to the Free Software
     31  *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
     32  *  --------------------------------------------------------------------
     33  */
     34 #ifdef HAVE_CONFIG_H
     35 #include <config.h>
     36 #endif
     37 
     38 #include "io.h"
     39 #include "maildir.h"
     40 #include "maildirmessage.h"
     41 
     42 using namespace ::std;
     43 using namespace Binc;
     44 
     45 //------------------------------------------------------------------------
     46 void Maildir::expungeMailbox(void)
     47 {
     48   if (readOnly) return;
     49 
     50   Mailbox::iterator i = begin(SequenceSet::all(), SQNR_MODE|INCLUDE_EXPUNGED);
     51 
     52   bool success = true;
     53   for (; success && i != end(); ++i) {
     54     MaildirMessage &message = reinterpret_cast<MaildirMessage &>(*i);
     55 
     56     if ((message.getStdFlags() & Message::F_DELETED) == 0)
     57       continue;
     58 
     59     message.setExpunged();
     60 
     61     const string &id = message.getUnique();
     62 
     63     // The message might be gone already
     64     MaildirIndexItem *item = index.find(id);
     65     if (!item)
     66       continue;
     67 
     68     string fpath = path + "/cur/" + item->fileName;
     69 
     70     while (unlink(fpath.c_str()) != 0) {
     71       if (errno != ENOENT) {
     72 	IO &logger = IOFactory::getInstance().get(2);
     73 	logger << "unable to remove " << fpath << ": "
     74 	       << strerror(errno) << endl;
     75 	break;
     76       }
     77 
     78       if (!scanFileNames()) {
     79 	success = false;
     80 	break;
     81       }
     82 
     83       if ((item = index.find(id)))
     84 	break;
     85       else
     86 	fpath = path + "/cur/" + item->fileName;
     87     }
     88   }
     89 }