bincimap

Log | Files | Refs | LICENSE

maildir-scanfilesnames.cc (2337B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    maildir-scanfilesnames.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 <iostream>
     41 #include <iomanip>
     42 
     43 #include <dirent.h>
     44 #include <unistd.h>
     45 #include <errno.h>
     46 
     47 #include "io.h"
     48 
     49 using namespace ::std;
     50 
     51 //------------------------------------------------------------------------
     52 bool Binc::Maildir::scanFileNames(void) const
     53 {
     54   string curpath = path + "/cur/";
     55   DIR *pdir = opendir(curpath.c_str());
     56   if (pdir == 0) {
     57     setLastError("when scanning mailbox \""
     58 		 + path + "\": " + string(strerror(errno)));
     59     IO &logger = IOFactory::getInstance().get(2);
     60     logger << getLastError() << endl;
     61     return false;
     62   }
     63 
     64   index.clearFileNames();
     65 
     66   struct dirent *pdirent;
     67   while ((pdirent = readdir(pdir)) != 0) {
     68     if (!isdigit(pdirent->d_name[0])) continue;
     69 
     70     string filename = pdirent->d_name;
     71     string uniquename;
     72 
     73     string::size_type pos;
     74     if ((pos = filename.find(':')) == string::npos)
     75       uniquename = filename;
     76     else
     77       uniquename = filename.substr(0, pos);
     78 
     79     index.insert(uniquename, 0, pdirent->d_name);
     80   }
     81 
     82   closedir(pdir);
     83   return true;
     84 }