bincimap

Log | Files | Refs | LICENSE

maildir-writecache.cc (2348B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    maildir-writecache.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 "maildir.h"
     39 
     40 #include "io.h"
     41 #include "storage.h"
     42 
     43 using namespace ::std;
     44 
     45 //------------------------------------------------------------------------
     46 bool Binc::Maildir::writeCache(void)
     47 {
     48   if (readOnly)
     49     return true;
     50 
     51   const string cachefilename = path + "/bincimap-cache";
     52   const string uidvalfilename = path + "/bincimap-uidvalidity";
     53 
     54   Storage cache(cachefilename, Storage::WriteOnly);
     55   int n = 0;
     56 
     57   Mailbox::iterator i = begin(SequenceSet::all(), INCLUDE_EXPUNGED);
     58   for (; i != end(); ++i) {
     59     MaildirMessage &message = (MaildirMessage &)*i;
     60     string nstr = toString(n++);
     61 
     62     cache.put(nstr, "_UID", toString(message.getUID()));
     63     if (message.getSize() != 0)
     64       cache.put(nstr, "_Size", toString(message.getSize()));
     65     
     66     cache.put(nstr, "_ID", message.getUnique());
     67     cache.put(nstr, "_InternalDate",
     68 	      toString((int) message.getInternalDate()));
     69   }
     70 
     71   cache.put("depot", "_version", CACHEFILEVERSION);
     72   if (!cache.commit()) {
     73     setLastError(cache.getLastError());
     74     return false;
     75   }
     76 
     77   return true;
     78 }