Commit fc6840c1 fc6840c10b65b96bc33a12ad173a50c502b5ff55 by Sergey Poznyakoff

Bugfix.

* imap4d/create.c: Rewrite to create mailboxes honoring mailbox-type.
* mailbox/mailbox.c (mu_mailbox_create): Bugfix.
1 parent 131f9b04
1 2008-08-07 Sergey Poznyakoff <gray@gnu.org.ua>
2
3 * imap4d/create.c: Rewrite to create mailboxes honoring
4 mailbox-type.
5 * mailbox/mailbox.c (mu_mailbox_create): Bugfix.
6
1 2008-08-04 Sergey Poznyakoff <gray@gnu.org.ua> 7 2008-08-04 Sergey Poznyakoff <gray@gnu.org.ua>
2 8
3 * pop3d/retr.c (pop3d_retr): Use constant-size buffer. This 9 * pop3d/retr.c (pop3d_retr): Use constant-size buffer. This
......
...@@ -19,9 +19,49 @@ ...@@ -19,9 +19,49 @@
19 #include "imap4d.h" 19 #include "imap4d.h"
20 #include <unistd.h> 20 #include <unistd.h>
21 21
22 /* 22 #define MKDIR_PERMISSIONS 0700
23 * Must create a new mailbox 23
24 */ 24 static int
25 mkdir_p (char *name, int delim)
26 {
27 char *p, *dir;
28 int rc = 0;
29
30 dir = name;
31 if (dir[0] == delim)
32 dir++;
33 for (; rc == 0 && (p = strchr (dir, delim)); dir = p)
34 {
35 struct stat st;
36
37 *p++ = 0;
38 if (stat (name, &st) == 0)
39 {
40 if (!S_ISDIR (st.st_mode))
41 {
42 mu_diag_output (MU_DIAG_ERR,
43 _("component %s is not a directory"), name);
44 rc = 1;
45 }
46 }
47 else if (errno != ENOENT)
48 {
49 mu_diag_output (MU_DIAG_ERR,
50 _("cannot stat file %s: %s"),
51 name, mu_strerror (errno));
52 rc = 1;
53 }
54 else if (mkdir (name, MKDIR_PERMISSIONS))
55 {
56 mu_diag_output (MU_DIAG_ERR,
57 _("cannot create directory %s: %s"), name,
58 mu_strerror (errno));
59 rc = 1;
60 }
61 p[-1] = delim;
62 }
63 return 0;
64 }
25 65
26 /* FIXME: How do we do this ??????: 66 /* FIXME: How do we do this ??????:
27 IF a new mailbox is created with the same name as a mailbox which was 67 IF a new mailbox is created with the same name as a mailbox which was
...@@ -76,45 +116,39 @@ imap4d_create (struct imap4d_command *command, char *arg) ...@@ -76,45 +116,39 @@ imap4d_create (struct imap4d_command *command, char *arg)
76 /* It will fail if the mailbox already exists. */ 116 /* It will fail if the mailbox already exists. */
77 if (access (name, F_OK) != 0) 117 if (access (name, F_OK) != 0)
78 { 118 {
79 if (!isdir) 119 if (mkdir_p (name, delim[0]))
80 { 120 {
81 char *dir; 121 rc = RESP_NO;
82 char *d = name + strlen (delim); /* Pass the root delimeter. */ 122 msg = "Cannot create mailbox";
123 }
83 124
84 /* If the server's hierarchy separtor character appears elsewhere in 125 if (rc == RESP_OK && !isdir)
85 name, the server SHOULD create any superior hierarchcal names
86 that are needed for the CREATE command to complete successfully.
87 */
88 if (chdir (delim) == 0) /* start on the root. */
89 for (; (dir = strchr (d, delim[0])); d = dir)
90 {
91 *dir++ = '\0';
92 if (chdir (d) != 0)
93 { 126 {
94 if (mkdir (d, 0700) == 0) 127 mu_mailbox_t mbox;
95 { 128
96 if (chdir (d) == 0) 129 rc = mu_mailbox_create_default (&mbox, name);
97 continue; 130 if (rc)
98 else
99 { 131 {
132 mu_diag_output (MU_DIAG_ERR,
133 _("Cannot create mailbox %s: %s"), name,
134 mu_strerror (rc));
100 rc = RESP_NO; 135 rc = RESP_NO;
101 msg = "Cannot create mailbox"; 136 msg = "Cannot create mailbox";
102 break;
103 }
104 } 137 }
105 } 138 else if ((rc = mu_mailbox_open (mbox,
106 } 139 MU_STREAM_RDWR|MU_STREAM_CREAT)))
107
108 if (rc == RESP_OK && d && *d != '\0')
109 {
110 int fd = creat (d, 0600);
111 if (fd != -1)
112 close (fd);
113 else
114 { 140 {
141 mu_diag_output (MU_DIAG_ERR,
142 _("Cannot open mailbox %s: %s"),
143 name, mu_strerror (rc));
115 rc = RESP_NO; 144 rc = RESP_NO;
116 msg = "Cannot create mailbox"; 145 msg = "Cannot create mailbox";
117 } 146 }
147 else
148 {
149 mu_mailbox_close (mbox);
150 mu_mailbox_destroy (&mbox);
151 rc = RESP_OK;
118 } 152 }
119 } 153 }
120 } 154 }
...@@ -123,7 +157,7 @@ imap4d_create (struct imap4d_command *command, char *arg) ...@@ -123,7 +157,7 @@ imap4d_create (struct imap4d_command *command, char *arg)
123 rc = RESP_NO; 157 rc = RESP_NO;
124 msg = "already exists"; 158 msg = "already exists";
125 } 159 }
126 chdir (homedir); 160
127 free (name); 161 free (name);
128 return util_finish (command, rc, msg); 162 return util_finish (command, rc, msg);
129 } 163 }
......
...@@ -234,7 +234,7 @@ mu_mailbox_create (mu_mailbox_t *pmbox, const char *name) ...@@ -234,7 +234,7 @@ mu_mailbox_create (mu_mailbox_t *pmbox, const char *name)
234 char *tmp_name = malloc (strlen (default_proto) + strlen (name) + 1); 234 char *tmp_name = malloc (strlen (default_proto) + strlen (name) + 1);
235 strcpy (tmp_name, default_proto); 235 strcpy (tmp_name, default_proto);
236 strcat (tmp_name, name); 236 strcat (tmp_name, name);
237 rc = _create_mailbox (pmbox, name); 237 rc = _create_mailbox (pmbox, tmp_name);
238 free (tmp_name); 238 free (tmp_name);
239 } 239 }
240 else 240 else
......