Use mu_mail_directory, mu_folder_directory and related calls.
Showing
15 changed files
with
56 additions
and
56 deletions
... | @@ -347,7 +347,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, | ... | @@ -347,7 +347,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, |
347 | } | 347 | } |
348 | else | 348 | else |
349 | { | 349 | { |
350 | char *mailbox_name; | 350 | char *mailbox_name = NULL; |
351 | char *name; | 351 | char *name; |
352 | 352 | ||
353 | mu_sql_get_column (conn, 0, 0, &name); | 353 | mu_sql_get_column (conn, 0, 0, &name); |
... | @@ -360,10 +360,8 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, | ... | @@ -360,10 +360,8 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data, |
360 | } | 360 | } |
361 | else | 361 | else |
362 | { | 362 | { |
363 | mailbox_name = malloc (strlen (mu_path_maildir) + | 363 | mu_construct_user_mailbox_url (&mailbox_name, name); |
364 | strlen (name) + 1); | 364 | /* FIXME: Error code is lost */ |
365 | if (mailbox_name) | ||
366 | sprintf (mailbox_name, "%s%s", mu_path_maildir, name); | ||
367 | } | 365 | } |
368 | 366 | ||
369 | if (mailbox_name) | 367 | if (mailbox_name) |
... | @@ -481,7 +479,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, | ... | @@ -481,7 +479,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, |
481 | else | 479 | else |
482 | { | 480 | { |
483 | char *name; | 481 | char *name; |
484 | char *mailbox_name; | 482 | char *mailbox_name = NULL; |
485 | 483 | ||
486 | mu_sql_get_column (conn, 0, 0, &name); | 484 | mu_sql_get_column (conn, 0, 0, &name); |
487 | 485 | ||
... | @@ -493,10 +491,8 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, | ... | @@ -493,10 +491,8 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data, |
493 | } | 491 | } |
494 | else | 492 | else |
495 | { | 493 | { |
496 | mailbox_name = malloc (strlen (mu_path_maildir) + | 494 | mu_construct_user_mailbox_url (&mailbox_name, name); |
497 | strlen (name) + 1); | 495 | /* FIXME: Error code is lost */ |
498 | if (mailbox_name) | ||
499 | sprintf (mailbox_name, "%s%s", mu_path_maildir, name); | ||
500 | } | 496 | } |
501 | 497 | ||
502 | if (mailbox_name) | 498 | if (mailbox_name) | ... | ... |
... | @@ -29,10 +29,11 @@ collect_open_default () | ... | @@ -29,10 +29,11 @@ collect_open_default () |
29 | 29 | ||
30 | if (!default_mailbox) | 30 | if (!default_mailbox) |
31 | { | 31 | { |
32 | asprintf (&default_mailbox, "%s%s", mu_path_maildir, user_name); | 32 | int rc = mu_construct_user_mailbox_url (&default_mailbox, user_name); |
33 | if (!default_mailbox) | 33 | if (rc) |
34 | { | 34 | { |
35 | util_error (_("Not enough memory")); | 35 | util_error (_("Cannot construct default mailbox URL: %s"), |
36 | mu_strerror (rc)); | ||
36 | exit (1); | 37 | exit (1); |
37 | } | 38 | } |
38 | } | 39 | } | ... | ... |
... | @@ -378,7 +378,6 @@ static error_t | ... | @@ -378,7 +378,6 @@ static error_t |
378 | mu_common_argp_parser (int key, char *arg, struct argp_state *state) | 378 | mu_common_argp_parser (int key, char *arg, struct argp_state *state) |
379 | { | 379 | { |
380 | int err = 0; | 380 | int err = 0; |
381 | char *p; | ||
382 | 381 | ||
383 | switch (key) | 382 | switch (key) |
384 | { | 383 | { |
... | @@ -394,7 +393,10 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) | ... | @@ -394,7 +393,10 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) |
394 | 393 | ||
395 | /* mailbox */ | 394 | /* mailbox */ |
396 | case 'm': | 395 | case 'm': |
397 | mu_path_maildir = arg; | 396 | err = mu_set_mail_directory (arg); |
397 | if (err) | ||
398 | argp_error (state, _("Cannot set mail directory name: %s"), | ||
399 | mu_strerror (err)); | ||
398 | break; | 400 | break; |
399 | 401 | ||
400 | case ARG_LOCK_FLAGS: | 402 | case ARG_LOCK_FLAGS: |
... | @@ -462,7 +464,7 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) | ... | @@ -462,7 +464,7 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) |
462 | if ((err = mu_set_user_email(arg)) != 0) | 464 | if ((err = mu_set_user_email(arg)) != 0) |
463 | { | 465 | { |
464 | argp_error (state, _("Invalid email address `%s': %s"), | 466 | argp_error (state, _("Invalid email address `%s': %s"), |
465 | arg, mu_strerror(err)); | 467 | arg, mu_strerror(err)); |
466 | } | 468 | } |
467 | break; | 469 | break; |
468 | 470 | ||
... | @@ -489,12 +491,6 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) | ... | @@ -489,12 +491,6 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state) |
489 | break; | 491 | break; |
490 | 492 | ||
491 | case ARGP_KEY_FINI: | 493 | case ARGP_KEY_FINI: |
492 | p = mu_normalize_maildir (mu_path_maildir); | ||
493 | if (!p) | ||
494 | { | ||
495 | argp_error (state, _("Badly formed mailspool path: %s"), mu_path_maildir); | ||
496 | } | ||
497 | mu_path_maildir = p; | ||
498 | break; | 494 | break; |
499 | 495 | ||
500 | default: | 496 | default: | ... | ... |
... | @@ -518,25 +518,33 @@ mu_normalize_path (char *path, const char *delim) | ... | @@ -518,25 +518,33 @@ mu_normalize_path (char *path, const char *delim) |
518 | return path; | 518 | return path; |
519 | } | 519 | } |
520 | 520 | ||
521 | char * | 521 | int |
522 | mu_normalize_maildir (const char *dir) | 522 | mu_normalize_mailbox_url (char **pout, const char *dir) |
523 | { | 523 | { |
524 | int len = strlen (dir); | 524 | int len; |
525 | |||
526 | if (!pout) | ||
527 | return MU_ERR_OUT_PTR_NULL; | ||
528 | |||
529 | len = strlen (dir); | ||
525 | if (dir[len-1] == '/') | 530 | if (dir[len-1] == '/') |
526 | return strdup (dir); | 531 | *pout = strdup (dir); |
527 | else if (strncasecmp (dir, "mbox:", 5) == 0 && dir[len-1] == '=') | 532 | else if (strncasecmp (dir, "mbox:", 5) == 0 && dir[len-1] == '=') |
528 | { | 533 | { |
529 | if (len > 5 && strcmp (dir + len - 5, "user=") == 0) | 534 | if (len > 5 && strcmp (dir + len - 5, "user=") == 0) |
530 | return strdup (dir); | 535 | *pout = strdup (dir); |
531 | else | 536 | else |
532 | return NULL; | 537 | return MU_ERR_BAD_FILENAME; |
533 | } | 538 | } |
534 | else | 539 | else |
535 | { | 540 | { |
536 | char *p = malloc (strlen (dir) + 2); | 541 | *pout = malloc (strlen (dir) + 2); |
537 | strcat (strcpy (p, dir), "/"); | 542 | if (*pout) |
538 | return p; | 543 | strcat (strcpy (*pout, dir), "/"); |
539 | } | 544 | } |
545 | |||
546 | /* Final check */ | ||
547 | return (*pout == NULL) ? errno : 0; | ||
540 | } | 548 | } |
541 | 549 | ||
542 | /* Create and open a temporary file. Be very careful about it, since we | 550 | /* Create and open a temporary file. Be very careful about it, since we | ... | ... |
... | @@ -53,12 +53,9 @@ mu_auth_system (struct mu_auth_data **return_data, const struct passwd *pw) | ... | @@ -53,12 +53,9 @@ mu_auth_system (struct mu_auth_data **return_data, const struct passwd *pw) |
53 | if (!pw) | 53 | if (!pw) |
54 | return 1; | 54 | return 1; |
55 | 55 | ||
56 | mailbox_name = malloc (strlen (mu_path_maildir) + | 56 | rc = mu_construct_user_mailbox_url (&mailbox_name, pw->pw_name); |
57 | strlen (pw->pw_name) + 1); | 57 | if (rc) |
58 | if (!mailbox_name) | 58 | return 1; /* FIXME: Return code is lost */ |
59 | return 1; | ||
60 | |||
61 | sprintf (mailbox_name, "%s%s", mu_path_maildir, pw->pw_name); | ||
62 | 59 | ||
63 | rc = mu_auth_data_alloc (return_data, | 60 | rc = mu_auth_data_alloc (return_data, |
64 | pw->pw_name, | 61 | pw->pw_name, | ... | ... |
... | @@ -211,7 +211,7 @@ main (int argc, char **argv) | ... | @@ -211,7 +211,7 @@ main (int argc, char **argv) |
211 | 211 | ||
212 | if (!wh_env.draftfolder) | 212 | if (!wh_env.draftfolder) |
213 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", | 213 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", |
214 | mu_path_folder_dir); | 214 | mu_folder_directory ()); |
215 | 215 | ||
216 | wh_env.file = mh_expand_name (wh_env.draftfolder, "comp", 0); | 216 | wh_env.file = mh_expand_name (wh_env.draftfolder, "comp", 0); |
217 | if (!wh_env.draftfile) | 217 | if (!wh_env.draftfile) | ... | ... |
... | @@ -417,10 +417,11 @@ print_fast () | ... | @@ -417,10 +417,11 @@ print_fast () |
417 | static int | 417 | static int |
418 | action_print () | 418 | action_print () |
419 | { | 419 | { |
420 | char *folder_dir = mu_folder_directory (); | ||
420 | mh_seq_name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE); | 421 | mh_seq_name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE); |
421 | 422 | ||
422 | name_prefix_len = strlen (mu_path_folder_dir); | 423 | name_prefix_len = strlen (folder_dir); |
423 | if (mu_path_folder_dir[name_prefix_len - 1] == '/') | 424 | if (folder_dir[name_prefix_len - 1] == '/') |
424 | name_prefix_len++; | 425 | name_prefix_len++; |
425 | name_prefix_len++; /* skip past the slash */ | 426 | name_prefix_len++; /* skip past the slash */ |
426 | 427 | ||
... | @@ -428,7 +429,7 @@ action_print () | ... | @@ -428,7 +429,7 @@ action_print () |
428 | 429 | ||
429 | if (show_all) | 430 | if (show_all) |
430 | { | 431 | { |
431 | _scan (mu_path_folder_dir, 0); | 432 | _scan (folder_dir, 0); |
432 | } | 433 | } |
433 | else | 434 | else |
434 | { | 435 | { | ... | ... |
... | @@ -372,7 +372,7 @@ main (int argc, char **argv) | ... | @@ -372,7 +372,7 @@ main (int argc, char **argv) |
372 | 372 | ||
373 | if (!wh_env.draftfolder) | 373 | if (!wh_env.draftfolder) |
374 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", | 374 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", |
375 | mu_path_folder_dir); | 375 | mu_folder_directory ()); |
376 | 376 | ||
377 | wh_env.file = mh_expand_name (wh_env.draftfolder, "forw", 0); | 377 | wh_env.file = mh_expand_name (wh_env.draftfolder, "forw", 0); |
378 | if (!wh_env.draftfile) | 378 | if (!wh_env.draftfile) | ... | ... |
... | @@ -310,7 +310,7 @@ mh_audit_open (char *name, mailbox_t mbox) | ... | @@ -310,7 +310,7 @@ mh_audit_open (char *name, mailbox_t mbox) |
310 | { | 310 | { |
311 | char *p = NULL; | 311 | char *p = NULL; |
312 | 312 | ||
313 | asprintf (&p, "%s/%s", mu_path_folder_dir, namep); | 313 | asprintf (&p, "%s/%s", mu_folder_directory (), namep); |
314 | if (!p) | 314 | if (!p) |
315 | { | 315 | { |
316 | mh_error (_("Not enough memory")); | 316 | mh_error (_("Not enough memory")); |
... | @@ -422,7 +422,7 @@ mh_expand_name (const char *base, const char *name, int is_folder) | ... | @@ -422,7 +422,7 @@ mh_expand_name (const char *base, const char *name, int is_folder) |
422 | namep = tmp; | 422 | namep = tmp; |
423 | 423 | ||
424 | if (!base) | 424 | if (!base) |
425 | base = mu_path_folder_dir; | 425 | base = mu_folder_directory (); |
426 | if (is_folder) | 426 | if (is_folder) |
427 | { | 427 | { |
428 | if (namep[0] == '/') | 428 | if (namep[0] == '/') |
... | @@ -749,7 +749,7 @@ char * | ... | @@ -749,7 +749,7 @@ char * |
749 | mh_draft_name () | 749 | mh_draft_name () |
750 | { | 750 | { |
751 | char *draftfolder = mh_global_profile_get ("Draft-Folder", | 751 | char *draftfolder = mh_global_profile_get ("Draft-Folder", |
752 | mu_path_folder_dir); | 752 | mu_folder_directory ()); |
753 | return mh_expand_name (draftfolder, "draft", 0); | 753 | return mh_expand_name (draftfolder, "draft", 0); |
754 | } | 754 | } |
755 | 755 | ... | ... |
... | @@ -2551,7 +2551,7 @@ main (int argc, char **argv) | ... | @@ -2551,7 +2551,7 @@ main (int argc, char **argv) |
2551 | mh_error (_("extra arguments")); | 2551 | mh_error (_("extra arguments")); |
2552 | return 1; | 2552 | return 1; |
2553 | } | 2553 | } |
2554 | message = mh_file_to_message (mu_path_folder_dir, input_file); | 2554 | message = mh_file_to_message (mu_folder_directory (), input_file); |
2555 | if (!message) | 2555 | if (!message) |
2556 | return 1; | 2556 | return 1; |
2557 | } | 2557 | } |
... | @@ -2563,7 +2563,7 @@ main (int argc, char **argv) | ... | @@ -2563,7 +2563,7 @@ main (int argc, char **argv) |
2563 | return 1; | 2563 | return 1; |
2564 | } | 2564 | } |
2565 | input_file = argc == 1 ? argv[0] : "draft"; | 2565 | input_file = argc == 1 ? argv[0] : "draft"; |
2566 | message = mh_file_to_message (mu_path_folder_dir, input_file); | 2566 | message = mh_file_to_message (mu_folder_directory (), input_file); |
2567 | if (!message) | 2567 | if (!message) |
2568 | return 1; | 2568 | return 1; |
2569 | } | 2569 | } |
... | @@ -2578,7 +2578,7 @@ main (int argc, char **argv) | ... | @@ -2578,7 +2578,7 @@ main (int argc, char **argv) |
2578 | case mode_compose: | 2578 | case mode_compose: |
2579 | /* Prepare filename for diagnostic purposes */ | 2579 | /* Prepare filename for diagnostic purposes */ |
2580 | if (input_file[0] != '/') | 2580 | if (input_file[0] != '/') |
2581 | asprintf (&input_file, "%s/%s", mu_path_folder_dir, input_file); | 2581 | asprintf (&input_file, "%s/%s", mu_folder_directory (), input_file); |
2582 | rc = mhn_compose (); | 2582 | rc = mhn_compose (); |
2583 | break; | 2583 | break; |
2584 | 2584 | ... | ... |
... | @@ -91,7 +91,7 @@ main (int argc, char **argv) | ... | @@ -91,7 +91,7 @@ main (int argc, char **argv) |
91 | can be useful is shell scripts. */ | 91 | can be useful is shell scripts. */ |
92 | if (current_folder[0] == 0) | 92 | if (current_folder[0] == 0) |
93 | { | 93 | { |
94 | printf ("%s\n", mu_path_folder_dir); | 94 | printf ("%s\n", mu_folder_directory ()); |
95 | exit (0); | 95 | exit (0); |
96 | } | 96 | } |
97 | 97 | ... | ... |
... | @@ -261,7 +261,7 @@ main (int argc, char **argv) | ... | @@ -261,7 +261,7 @@ main (int argc, char **argv) |
261 | mh_error (_("Both message set and source file given")); | 261 | mh_error (_("Both message set and source file given")); |
262 | exit (1); | 262 | exit (1); |
263 | } | 263 | } |
264 | msg = mh_file_to_message (mu_path_folder_dir, source_file); | 264 | msg = mh_file_to_message (mu_folder_directory (), source_file); |
265 | refile (msg); | 265 | refile (msg); |
266 | if (!link_flag) | 266 | if (!link_flag) |
267 | unlink (source_file); | 267 | unlink (source_file); | ... | ... |
... | @@ -376,7 +376,7 @@ main (int argc, char **argv) | ... | @@ -376,7 +376,7 @@ main (int argc, char **argv) |
376 | 376 | ||
377 | if (!wh_env.draftfolder) | 377 | if (!wh_env.draftfolder) |
378 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", | 378 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", |
379 | mu_path_folder_dir); | 379 | mu_folder_directory ()); |
380 | 380 | ||
381 | mbox = mh_open_folder (current_folder, 0); | 381 | mbox = mh_open_folder (current_folder, 0); |
382 | mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); | 382 | mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur"); | ... | ... |
... | @@ -148,7 +148,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) | ... | @@ -148,7 +148,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) |
148 | case ARG_DRAFTMESSAGE: | 148 | case ARG_DRAFTMESSAGE: |
149 | if (!draft_folder) | 149 | if (!draft_folder) |
150 | draft_folder = mh_global_profile_get ("Draft-Folder", | 150 | draft_folder = mh_global_profile_get ("Draft-Folder", |
151 | mu_path_folder_dir); | 151 | mu_folder_directory ()); |
152 | break; | 152 | break; |
153 | 153 | ||
154 | case ARG_FILTER: | 154 | case ARG_FILTER: |
... | @@ -524,8 +524,9 @@ send (int argc, char **argv) | ... | @@ -524,8 +524,9 @@ send (int argc, char **argv) |
524 | 524 | ||
525 | /* Prepend url specifier to the folder dir. We won't need this | 525 | /* Prepend url specifier to the folder dir. We won't need this |
526 | when the default format becomes configurable */ | 526 | when the default format becomes configurable */ |
527 | asprintf (&p, "mh:%s", mu_path_folder_dir); | 527 | asprintf (&p, "mh:%s", mu_folder_directory ()); |
528 | mu_path_folder_dir = p; | 528 | mu_set_folder_directory (p); |
529 | free (p); | ||
529 | 530 | ||
530 | /* Finally, do the work */ | 531 | /* Finally, do the work */ |
531 | rc = list_do (mesg_list, _action_send, NULL); | 532 | rc = list_do (mesg_list, _action_send, NULL); | ... | ... |
... | @@ -86,7 +86,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) | ... | @@ -86,7 +86,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) |
86 | case ARG_DRAFTMESSAGE: | 86 | case ARG_DRAFTMESSAGE: |
87 | if (!draft_folder) | 87 | if (!draft_folder) |
88 | draft_folder = mh_global_profile_get ("Draft-Folder", | 88 | draft_folder = mh_global_profile_get ("Draft-Folder", |
89 | mu_path_folder_dir); | 89 | mu_folder_directory ()); |
90 | break; | 90 | break; |
91 | 91 | ||
92 | case ARG_CHECK: | 92 | case ARG_CHECK: |
... | @@ -127,7 +127,7 @@ main (int argc, char **argv) | ... | @@ -127,7 +127,7 @@ main (int argc, char **argv) |
127 | 127 | ||
128 | if (!draft_folder) | 128 | if (!draft_folder) |
129 | draft_folder = mh_global_profile_get ("Draft-Folder", | 129 | draft_folder = mh_global_profile_get ("Draft-Folder", |
130 | mu_path_folder_dir); | 130 | mu_folder_directory ()); |
131 | 131 | ||
132 | 132 | ||
133 | return mh_whom (mh_expand_name (draft_folder, name, 0), check_recipients) ? | 133 | return mh_whom (mh_expand_name (draft_folder, name, 0), check_recipients) ? | ... | ... |
-
Please register or sign in to post a comment