(mu_path_maildir,mu_path_folder_dir): Removed
(mu_set_mail_directory,mu_set_folder_directory) (mu_mail_directory,mu_folder_directory) (mu_construct_user_mailbox_url,mailbox_get_flags): New functions.
Showing
2 changed files
with
66 additions
and
16 deletions
... | @@ -27,8 +27,11 @@ | ... | @@ -27,8 +27,11 @@ |
27 | extern "C" { | 27 | extern "C" { |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | extern const char *mu_path_maildir; | 30 | int mu_set_mail_directory __P ((const char *p)); |
31 | extern const char *mu_path_folder_dir; | 31 | void mu_set_folder_directory __P ((const char *p)); |
32 | const char *mu_mail_directory __P ((void)); | ||
33 | const char *mu_folder_directory __P ((void)); | ||
34 | int mu_construct_user_mailbox_url __P ((char **pout, const char *name)); | ||
32 | 35 | ||
33 | /* Constructor/destructor and possible types. */ | 36 | /* Constructor/destructor and possible types. */ |
34 | extern int mailbox_create __P ((mailbox_t *, const char *)); | 37 | extern int mailbox_create __P ((mailbox_t *, const char *)); |
... | @@ -66,6 +69,7 @@ extern int mailbox_get_locker __P ((mailbox_t, locker_t *)); | ... | @@ -66,6 +69,7 @@ extern int mailbox_get_locker __P ((mailbox_t, locker_t *)); |
66 | extern int mailbox_set_locker __P ((mailbox_t, locker_t)); | 69 | extern int mailbox_set_locker __P ((mailbox_t, locker_t)); |
67 | 70 | ||
68 | /* Property. */ | 71 | /* Property. */ |
72 | extern int mailbox_get_flags __P ((mailbox_t, int *)); | ||
69 | extern int mailbox_get_property __P ((mailbox_t, property_t *)); | 73 | extern int mailbox_get_property __P ((mailbox_t, property_t *)); |
70 | 74 | ||
71 | /* URL. */ | 75 | /* URL. */ | ... | ... |
... | @@ -37,8 +37,53 @@ | ... | @@ -37,8 +37,53 @@ |
37 | #include <mailutils/errno.h> | 37 | #include <mailutils/errno.h> |
38 | #include <mailutils/mu_auth.h> | 38 | #include <mailutils/mu_auth.h> |
39 | 39 | ||
40 | const char *mu_path_maildir = MU_PATH_MAILDIR; | 40 | static char *_default_mail_dir = MU_PATH_MAILDIR; |
41 | const char *mu_path_folder_dir = "Mail"; | 41 | static char *_mu_mail_dir; |
42 | static char *_default_folder_dir = "Mail"; | ||
43 | static char *_mu_folder_dir; | ||
44 | |||
45 | int | ||
46 | mu_set_mail_directory (const char *p) | ||
47 | { | ||
48 | if (_mu_mail_dir != _default_mail_dir) | ||
49 | free (_mu_mail_dir); | ||
50 | return mu_normalize_mailbox_url (&_mu_mail_dir, p); | ||
51 | } | ||
52 | |||
53 | void | ||
54 | mu_set_folder_directory (const char *p) | ||
55 | { | ||
56 | if (_mu_folder_dir != _default_folder_dir) | ||
57 | free (_mu_folder_dir); | ||
58 | _mu_folder_dir = strdup (p); | ||
59 | } | ||
60 | |||
61 | const char * | ||
62 | mu_mail_directory () | ||
63 | { | ||
64 | if (!_mu_mail_dir) | ||
65 | _mu_mail_dir = _default_mail_dir; | ||
66 | return _mu_mail_dir; | ||
67 | } | ||
68 | |||
69 | const char * | ||
70 | mu_folder_directory () | ||
71 | { | ||
72 | if (!_mu_folder_dir) | ||
73 | _mu_folder_dir = _default_folder_dir; | ||
74 | return _mu_folder_dir; | ||
75 | } | ||
76 | |||
77 | int | ||
78 | mu_construct_user_mailbox_url (char **pout, const char *name) | ||
79 | { | ||
80 | const char *p = mu_mail_directory (); | ||
81 | *pout = malloc (strlen (p) + strlen (name) + 1); | ||
82 | if (!*pout) | ||
83 | return errno; | ||
84 | strcat (strcpy (*pout, p), name); | ||
85 | return 0; | ||
86 | } | ||
42 | 87 | ||
43 | /* Is this a security risk? */ | 88 | /* Is this a security risk? */ |
44 | #define USE_ENVIRON 1 | 89 | #define USE_ENVIRON 1 |
... | @@ -141,11 +186,12 @@ static int | ... | @@ -141,11 +186,12 @@ static int |
141 | user_mailbox_name (const char *user, char **mailbox_name) | 186 | user_mailbox_name (const char *user, char **mailbox_name) |
142 | { | 187 | { |
143 | char *p; | 188 | char *p; |
189 | const char *url = mu_mail_directory (); | ||
144 | 190 | ||
145 | p = strchr (mu_path_maildir, ':'); | 191 | p = strchr (url, ':'); |
146 | if (p && strncmp (mu_path_maildir, "mbox", p - mu_path_maildir)) | 192 | if (p && strncmp (url, "mbox", p - url)) |
147 | { | 193 | { |
148 | *mailbox_name = strdup (mu_path_maildir); | 194 | *mailbox_name = strdup (url); |
149 | return 0; | 195 | return 0; |
150 | } | 196 | } |
151 | 197 | ||
... | @@ -156,10 +202,9 @@ user_mailbox_name (const char *user, char **mailbox_name) | ... | @@ -156,10 +202,9 @@ user_mailbox_name (const char *user, char **mailbox_name) |
156 | 202 | ||
157 | if (user) | 203 | if (user) |
158 | { | 204 | { |
159 | *mailbox_name = malloc (strlen (user) + strlen (mu_path_maildir) + 2); | 205 | int rc = mu_construct_user_mailbox_url (mailbox_name, user); |
160 | if (*mailbox_name == NULL) | 206 | if (rc) |
161 | return ENOMEM; | 207 | return rc; |
162 | sprintf (*mailbox_name, "%s%s", mu_path_maildir, user); | ||
163 | } | 208 | } |
164 | else | 209 | else |
165 | { | 210 | { |
... | @@ -183,6 +228,7 @@ plus_expand (const char *file, char **buf) | ... | @@ -183,6 +228,7 @@ plus_expand (const char *file, char **buf) |
183 | char *user = NULL; | 228 | char *user = NULL; |
184 | char *path = NULL; | 229 | char *path = NULL; |
185 | char *home; | 230 | char *home; |
231 | const char *folder_dir = mu_folder_directory (); | ||
186 | int status, len; | 232 | int status, len; |
187 | 233 | ||
188 | if ((status = split_shortcut (file, "+=", &path, &user))) | 234 | if ((status = split_shortcut (file, "+=", &path, &user))) |
... | @@ -202,17 +248,17 @@ plus_expand (const char *file, char **buf) | ... | @@ -202,17 +248,17 @@ plus_expand (const char *file, char **buf) |
202 | return ENOENT; | 248 | return ENOENT; |
203 | } | 249 | } |
204 | 250 | ||
205 | if (mu_path_folder_dir[0] == '/' || is_proto (mu_path_folder_dir)) | 251 | if (folder_dir[0] == '/' || is_proto (folder_dir)) |
206 | { | 252 | { |
207 | len = strlen (mu_path_folder_dir) + strlen (path) + 2; | 253 | len = strlen (folder_dir) + strlen (path) + 2; |
208 | *buf = malloc (len); | 254 | *buf = malloc (len); |
209 | sprintf (*buf, "%s/%s", mu_path_folder_dir, path); | 255 | sprintf (*buf, "%s/%s", folder_dir, path); |
210 | } | 256 | } |
211 | else | 257 | else |
212 | { | 258 | { |
213 | len = strlen (home) + strlen (mu_path_folder_dir) + strlen (path) + 3; | 259 | len = strlen (home) + strlen (folder_dir) + strlen (path) + 3; |
214 | *buf = malloc (len); | 260 | *buf = malloc (len); |
215 | sprintf (*buf, "%s/%s/%s", home, mu_path_folder_dir, path); | 261 | sprintf (*buf, "%s/%s/%s", home, folder_dir, path); |
216 | } | 262 | } |
217 | (*buf)[len-1] = 0; | 263 | (*buf)[len-1] = 0; |
218 | 264 | ... | ... |
-
Please register or sign in to post a comment