blob: 0fe5f0d30294294b64d575b70b96f9c14c230ed3 (
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
|
/**
* @file maildir-scanfilesnames.cc
* @brief Implementation of the Maildir class.
* @author Andreas Aardal Hanssen
* @date 2002-2005
*/
#include "iodevice.h"
#include "iofactory.h"
#include "maildir.h"
#include <iomanip>
#include <iostream>
#include <errno.h>
#include <dirent.h>
#include <unistd.h>
using std::string;
bool Binc::Maildir::scanFileNames() const
{
string curpath = path + "/cur/";
DIR *pdir = opendir(curpath.c_str());
if (pdir == nullptr) {
setLastError("when scanning mailbox \"" + path + "\": " + string(strerror(errno)));
bincWarning << getLastError() << std::endl;
return false;
}
index.clearFileNames();
struct dirent *pdirent;
while ((pdirent = readdir(pdir)) != nullptr) {
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;
}
|