Commit 4d642922 4d642922b63bdf1a312b5f76b1f827e794e23da6 by Sergey Poznyakoff

Minor fixes

* libmailutils/mailbox/mbx_default.c (mu_normalize_mailbox_url): don't
place / in front of the username.
(plus_expand): Use mu_make_file_name and mu_asprintf.  Check for errors.
(mu_mailbox_create_default): Check for errors.
1 parent 10adba52
...@@ -64,12 +64,19 @@ mu_normalize_mailbox_url (char **pout, const char *dir) ...@@ -64,12 +64,19 @@ mu_normalize_mailbox_url (char **pout, const char *dir)
64 { 64 {
65 if (!(len > 5 && strcmp (dir + len - 5, "user=") == 0)) 65 if (!(len > 5 && strcmp (dir + len - 5, "user=") == 0))
66 return MU_ERR_BAD_FILENAME; 66 return MU_ERR_BAD_FILENAME;
67 else
68 {
69 int rc = mu_asprintf (pout, "%s%s", dir, USERSUFFIX);
70 if (rc)
71 return rc;
72 }
67 } 73 }
68 else 74 else
75 {
69 *pout = mu_make_file_name (dir, USERSUFFIX); 76 *pout = mu_make_file_name (dir, USERSUFFIX);
70
71 if (!*pout) 77 if (!*pout)
72 return errno; 78 return errno;
79 }
73 80
74 return 0; 81 return 0;
75 } 82 }
...@@ -280,7 +287,6 @@ plus_expand (const char *file, char **buf) ...@@ -280,7 +287,6 @@ plus_expand (const char *file, char **buf)
280 { 287 {
281 char *home; 288 char *home;
282 const char *folder_dir = mu_folder_directory (); 289 const char *folder_dir = mu_folder_directory ();
283 int len;
284 290
285 home = get_homedir (NULL); 291 home = get_homedir (NULL);
286 if (!home) 292 if (!home)
...@@ -290,17 +296,16 @@ plus_expand (const char *file, char **buf) ...@@ -290,17 +296,16 @@ plus_expand (const char *file, char **buf)
290 296
291 if (folder_dir[0] == '/' || mu_is_proto (folder_dir)) 297 if (folder_dir[0] == '/' || mu_is_proto (folder_dir))
292 { 298 {
293 len = strlen (folder_dir) + strlen (file) + 2; 299 *buf = mu_make_file_name (folder_dir, file);
294 *buf = malloc (len); 300 if (!*buf)
295 sprintf (*buf, "%s/%s", folder_dir, file); 301 return errno;
296 } 302 }
297 else 303 else
298 { 304 {
299 len = strlen (home) + strlen (folder_dir) + strlen (file) + 3; 305 int rc = mu_asprintf (buf, "%s/%s/%s", home, folder_dir, file);
300 *buf = malloc (len); 306 if (rc)
301 sprintf (*buf, "%s/%s/%s", home, folder_dir, file); 307 return rc;
302 } 308 }
303 (*buf)[len-1] = 0;
304 309
305 free (home); 310 free (home);
306 return 0; 311 return 0;
...@@ -433,18 +438,25 @@ mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail) ...@@ -433,18 +438,25 @@ mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
433 438
434 case '/': 439 case '/':
435 mbox = strdup (mail); 440 mbox = strdup (mail);
441 if (!mbox)
442 status = errno;
436 break; 443 break;
437 444
438 default: 445 default:
439 if (!mu_is_proto (mail)) 446 if (!mu_is_proto (mail))
440 { 447 {
441 p = mu_getcwd(); 448 p = mu_getcwd();
442 mbox = malloc (strlen (p) + strlen (mail) + 2); 449 mbox = mu_make_file_name (p, mail);
443 sprintf (mbox, "%s/%s", p, mail); 450 if (!mbox)
451 status = errno;
444 free (p); 452 free (p);
445 } 453 }
446 else 454 else
455 {
447 mbox = strdup (mail); 456 mbox = strdup (mail);
457 if (!mbox)
458 status = errno;
459 }
448 break; 460 break;
449 } 461 }
450 462
......