Commit 55475517 554755172702ace341b4ed113408804984270789 by Sergey Poznyakoff

Use mu_mail_directory, mu_folder_directory and related calls.

1 parent 8c6fcf1e
......@@ -347,7 +347,7 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
}
else
{
char *mailbox_name;
char *mailbox_name = NULL;
char *name;
mu_sql_get_column (conn, 0, 0, &name);
......@@ -360,10 +360,8 @@ mu_auth_sql_by_name (struct mu_auth_data **return_data,
}
else
{
mailbox_name = malloc (strlen (mu_path_maildir) +
strlen (name) + 1);
if (mailbox_name)
sprintf (mailbox_name, "%s%s", mu_path_maildir, name);
mu_construct_user_mailbox_url (&mailbox_name, name);
/* FIXME: Error code is lost */
}
if (mailbox_name)
......@@ -481,7 +479,7 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
else
{
char *name;
char *mailbox_name;
char *mailbox_name = NULL;
mu_sql_get_column (conn, 0, 0, &name);
......@@ -493,10 +491,8 @@ mu_auth_sql_by_uid (struct mu_auth_data **return_data,
}
else
{
mailbox_name = malloc (strlen (mu_path_maildir) +
strlen (name) + 1);
if (mailbox_name)
sprintf (mailbox_name, "%s%s", mu_path_maildir, name);
mu_construct_user_mailbox_url (&mailbox_name, name);
/* FIXME: Error code is lost */
}
if (mailbox_name)
......
......@@ -29,10 +29,11 @@ collect_open_default ()
if (!default_mailbox)
{
asprintf (&default_mailbox, "%s%s", mu_path_maildir, user_name);
if (!default_mailbox)
int rc = mu_construct_user_mailbox_url (&default_mailbox, user_name);
if (rc)
{
util_error (_("Not enough memory"));
util_error (_("Cannot construct default mailbox URL: %s"),
mu_strerror (rc));
exit (1);
}
}
......
......@@ -378,7 +378,6 @@ static error_t
mu_common_argp_parser (int key, char *arg, struct argp_state *state)
{
int err = 0;
char *p;
switch (key)
{
......@@ -394,7 +393,10 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state)
/* mailbox */
case 'm':
mu_path_maildir = arg;
err = mu_set_mail_directory (arg);
if (err)
argp_error (state, _("Cannot set mail directory name: %s"),
mu_strerror (err));
break;
case ARG_LOCK_FLAGS:
......@@ -462,7 +464,7 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state)
if ((err = mu_set_user_email(arg)) != 0)
{
argp_error (state, _("Invalid email address `%s': %s"),
arg, mu_strerror(err));
arg, mu_strerror(err));
}
break;
......@@ -489,12 +491,6 @@ mu_common_argp_parser (int key, char *arg, struct argp_state *state)
break;
case ARGP_KEY_FINI:
p = mu_normalize_maildir (mu_path_maildir);
if (!p)
{
argp_error (state, _("Badly formed mailspool path: %s"), mu_path_maildir);
}
mu_path_maildir = p;
break;
default:
......
......@@ -518,25 +518,33 @@ mu_normalize_path (char *path, const char *delim)
return path;
}
char *
mu_normalize_maildir (const char *dir)
int
mu_normalize_mailbox_url (char **pout, const char *dir)
{
int len = strlen (dir);
int len;
if (!pout)
return MU_ERR_OUT_PTR_NULL;
len = strlen (dir);
if (dir[len-1] == '/')
return strdup (dir);
*pout = strdup (dir);
else if (strncasecmp (dir, "mbox:", 5) == 0 && dir[len-1] == '=')
{
if (len > 5 && strcmp (dir + len - 5, "user=") == 0)
return strdup (dir);
*pout = strdup (dir);
else
return NULL;
return MU_ERR_BAD_FILENAME;
}
else
{
char *p = malloc (strlen (dir) + 2);
strcat (strcpy (p, dir), "/");
return p;
*pout = malloc (strlen (dir) + 2);
if (*pout)
strcat (strcpy (*pout, dir), "/");
}
/* Final check */
return (*pout == NULL) ? errno : 0;
}
/* 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)
if (!pw)
return 1;
mailbox_name = malloc (strlen (mu_path_maildir) +
strlen (pw->pw_name) + 1);
if (!mailbox_name)
return 1;
sprintf (mailbox_name, "%s%s", mu_path_maildir, pw->pw_name);
rc = mu_construct_user_mailbox_url (&mailbox_name, pw->pw_name);
if (rc)
return 1; /* FIXME: Return code is lost */
rc = mu_auth_data_alloc (return_data,
pw->pw_name,
......
......@@ -211,7 +211,7 @@ main (int argc, char **argv)
if (!wh_env.draftfolder)
wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
mu_path_folder_dir);
mu_folder_directory ());
wh_env.file = mh_expand_name (wh_env.draftfolder, "comp", 0);
if (!wh_env.draftfile)
......
......@@ -417,10 +417,11 @@ print_fast ()
static int
action_print ()
{
char *folder_dir = mu_folder_directory ();
mh_seq_name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE);
name_prefix_len = strlen (mu_path_folder_dir);
if (mu_path_folder_dir[name_prefix_len - 1] == '/')
name_prefix_len = strlen (folder_dir);
if (folder_dir[name_prefix_len - 1] == '/')
name_prefix_len++;
name_prefix_len++; /* skip past the slash */
......@@ -428,7 +429,7 @@ action_print ()
if (show_all)
{
_scan (mu_path_folder_dir, 0);
_scan (folder_dir, 0);
}
else
{
......
......@@ -372,7 +372,7 @@ main (int argc, char **argv)
if (!wh_env.draftfolder)
wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
mu_path_folder_dir);
mu_folder_directory ());
wh_env.file = mh_expand_name (wh_env.draftfolder, "forw", 0);
if (!wh_env.draftfile)
......
......@@ -310,7 +310,7 @@ mh_audit_open (char *name, mailbox_t mbox)
{
char *p = NULL;
asprintf (&p, "%s/%s", mu_path_folder_dir, namep);
asprintf (&p, "%s/%s", mu_folder_directory (), namep);
if (!p)
{
mh_error (_("Not enough memory"));
......@@ -422,7 +422,7 @@ mh_expand_name (const char *base, const char *name, int is_folder)
namep = tmp;
if (!base)
base = mu_path_folder_dir;
base = mu_folder_directory ();
if (is_folder)
{
if (namep[0] == '/')
......@@ -749,7 +749,7 @@ char *
mh_draft_name ()
{
char *draftfolder = mh_global_profile_get ("Draft-Folder",
mu_path_folder_dir);
mu_folder_directory ());
return mh_expand_name (draftfolder, "draft", 0);
}
......
......@@ -2551,7 +2551,7 @@ main (int argc, char **argv)
mh_error (_("extra arguments"));
return 1;
}
message = mh_file_to_message (mu_path_folder_dir, input_file);
message = mh_file_to_message (mu_folder_directory (), input_file);
if (!message)
return 1;
}
......@@ -2563,7 +2563,7 @@ main (int argc, char **argv)
return 1;
}
input_file = argc == 1 ? argv[0] : "draft";
message = mh_file_to_message (mu_path_folder_dir, input_file);
message = mh_file_to_message (mu_folder_directory (), input_file);
if (!message)
return 1;
}
......@@ -2578,7 +2578,7 @@ main (int argc, char **argv)
case mode_compose:
/* Prepare filename for diagnostic purposes */
if (input_file[0] != '/')
asprintf (&input_file, "%s/%s", mu_path_folder_dir, input_file);
asprintf (&input_file, "%s/%s", mu_folder_directory (), input_file);
rc = mhn_compose ();
break;
......
......@@ -91,7 +91,7 @@ main (int argc, char **argv)
can be useful is shell scripts. */
if (current_folder[0] == 0)
{
printf ("%s\n", mu_path_folder_dir);
printf ("%s\n", mu_folder_directory ());
exit (0);
}
......
......@@ -261,7 +261,7 @@ main (int argc, char **argv)
mh_error (_("Both message set and source file given"));
exit (1);
}
msg = mh_file_to_message (mu_path_folder_dir, source_file);
msg = mh_file_to_message (mu_folder_directory (), source_file);
refile (msg);
if (!link_flag)
unlink (source_file);
......
......@@ -376,7 +376,7 @@ main (int argc, char **argv)
if (!wh_env.draftfolder)
wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
mu_path_folder_dir);
mu_folder_directory ());
mbox = mh_open_folder (current_folder, 0);
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)
case ARG_DRAFTMESSAGE:
if (!draft_folder)
draft_folder = mh_global_profile_get ("Draft-Folder",
mu_path_folder_dir);
mu_folder_directory ());
break;
case ARG_FILTER:
......@@ -524,8 +524,9 @@ send (int argc, char **argv)
/* Prepend url specifier to the folder dir. We won't need this
when the default format becomes configurable */
asprintf (&p, "mh:%s", mu_path_folder_dir);
mu_path_folder_dir = p;
asprintf (&p, "mh:%s", mu_folder_directory ());
mu_set_folder_directory (p);
free (p);
/* Finally, do the work */
rc = list_do (mesg_list, _action_send, NULL);
......
......@@ -86,7 +86,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
case ARG_DRAFTMESSAGE:
if (!draft_folder)
draft_folder = mh_global_profile_get ("Draft-Folder",
mu_path_folder_dir);
mu_folder_directory ());
break;
case ARG_CHECK:
......@@ -127,7 +127,7 @@ main (int argc, char **argv)
if (!draft_folder)
draft_folder = mh_global_profile_get ("Draft-Folder",
mu_path_folder_dir);
mu_folder_directory ());
return mh_whom (mh_expand_name (draft_folder, name, 0), check_recipients) ?
......