summaryrefslogtreecommitdiff
path: root/src/maildir-scanfilesnames.cc
blob: 643460b50c2b115edd9988f4d3010f1dc589798d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**  --------------------------------------------------------------------
 *  @file maildir-scanfilesnames.cc
 *  @brief  Implementation of the Maildir class.
 *  @author Andreas Aardal Hanssen
 *  @date 2002-2005 
 *  -----------------------------------------------------------------  **/
#include "maildir.h"

#include <iostream>
#include <iomanip>

#include <dirent.h>
#include <unistd.h>
#include <errno.h>

#include "iodevice.h"
#include "iofactory.h"

using namespace ::std;

//------------------------------------------------------------------------
bool Binc::Maildir::scanFileNames(void) const
{
  string curpath = path + "/cur/";
  DIR *pdir = opendir(curpath.c_str());
  if (pdir == 0) {
    setLastError("when scanning mailbox \""
                  + path + "\": " + string(strerror(errno)));
    bincWarning << getLastError() << endl;
    return false;
  }

  index.clearFileNames();

  struct dirent *pdirent;
  while ((pdirent = readdir(pdir)) != 0) {
    if (!isdigit(pdirent->d_name[0])) continue;

    string filename = pdirent->d_name;
    string uniquename;

    string::size_type pos;
    if ((pos = filename.find(':')) == string::npos)
      uniquename = filename;
    else
      uniquename = filename.substr(0, pos);

    index.insert(uniquename, 0, pdirent->d_name);
  }

  closedir(pdir);
  return true;
}