Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
maildir-create.cc
Go to the documentation of this file.
1
7#include "maildir.h"
8
9#include <sys/types.h>
10#include <fcntl.h>
11#include <unistd.h>
12#include <errno.h>
13#include <sys/stat.h>
14
15using namespace ::std;
16using namespace Binc;
17
18//------------------------------------------------------------------------
19bool Binc::Maildir::createMailbox(const string &s_in, mode_t mode,
20 uid_t owner, gid_t group, bool root)
21{
22 if (s_in != "." && mkdir(s_in.c_str(), mode) == -1) {
23 setLastError("unable to create " + s_in + ": "
24 + string(strerror(errno)));
25 return false;
26 }
27
28 // Allow uidvalidity, which is generated from time(0), to
29 // increase with one second to avoid race conditions.
30 sleep(1);
31
32 if (mkdir((s_in + "/cur").c_str(), mode) == -1) {
33 setLastError("unable to create " + s_in + "/cur: "
34 + string(strerror(errno)));
35 return false;
36 }
37
38 if (mkdir((s_in + "/new").c_str(), mode) == -1) {
39 setLastError("unable to create " + s_in + "/new: "
40 + string(strerror(errno)));
41 return false;
42 }
43
44 if (mkdir((s_in + "/tmp").c_str(), mode) == -1) {
45 setLastError("unable to create " + s_in + "/tmp: "
46 + string(strerror(errno)));
47 return false;
48 }
49
50 if (owner == 0 && group == 0)
51 return true;
52
53 if (chown(s_in.c_str(), owner, group) == -1) {
54 setLastError("unable to chown " + s_in + ": "
55 + string(strerror(errno)));
56 return false;
57 }
58
59 if (chown((s_in + "/cur").c_str(), owner, group) == -1) {
60 setLastError("unable to chown " + s_in + "/cur: "
61 + string(strerror(errno)));
62 return false;
63 }
64
65 if (chown((s_in + "/new").c_str(), owner, group) == -1) {
66 setLastError("unable to chown " + s_in + "/new: "
67 + string(strerror(errno)));
68 return false;
69 }
70
71 if (chown((s_in + "/tmp").c_str(), owner, group) == -1) {
72 setLastError("unable to chown " + s_in + "/tmp: "
73 + string(strerror(errno)));
74 return false;
75 }
76
77 return true;
78}
void setLastError(const std::string &error) const
Definition: mailbox.cc:109
bool createMailbox(const std::string &s, mode_t mode, uid_t owner=0, gid_t group=0, bool root=false)
Declaration of the Maildir class.
Definition: bincimapd.cc:9