Commit a2de3967 a2de39676ae144aab016730c598d747f071ae581 by Sergey Poznyakoff

Fix semantics of -build/-draftmessage/-[no]draftfolder options for compatibility…

… with other implementations of MH
1 parent b347f37f
......@@ -80,6 +80,7 @@ const char *formfile;
static int initial_edit = 1;
static int build_only = 0; /* --build flag */
static int use_draft = 0; /* --use flag */
static char *draftmessage = "new";
static int
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
......@@ -112,11 +113,12 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
break;
case ARG_DRAFTMESSAGE:
wh_env.draftmessage = arg;
draftmessage = arg;
break;
case ARG_USE:
use_draft = is_true (arg);
draftmessage = "cur";
break;
case ARG_NOUSE:
......@@ -214,9 +216,14 @@ main (int argc, char **argv)
mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
wh_env.file = mh_expand_name (wh_env.draftfolder, "comp", 0);
if (!wh_env.draftfile)
wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0);
if (build_only || !wh_env.draftfolder)
wh_env.file = mh_expand_name (NULL, "draft", 0);
else if (wh_env.draftfolder)
{
if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file))
return 1;
}
wh_env.draftfile = wh_env.file;
switch (check_draft_disposition (&wh_env, use_draft))
{
......@@ -224,8 +231,6 @@ main (int argc, char **argv)
exit (0);
case DISP_USE:
unlink (wh_env.file);
rename (wh_env.draftfile, wh_env.file);
break;
case DISP_REPLACE:
......
......@@ -112,6 +112,7 @@ static enum encap_type encap = encap_clear; /* controlled by --format, --form
and --mime flags */
static int use_draft = 0; /* --use flag */
static int width = 80; /* --width flag */
static char *draftmessage = "new";
static mh_msgset_t msgset;
static mu_mailbox_t mbox;
......@@ -137,9 +138,13 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
case ARG_DRAFTFOLDER:
wh_env.draftfolder = arg;
break;
case ARG_NODRAFTFOLDER:
wh_env.draftfolder = NULL;
break;
case ARG_DRAFTMESSAGE:
wh_env.draftmessage = arg;
draftmessage = arg;
break;
case ARG_USE:
......@@ -432,9 +437,14 @@ main (int argc, char **argv)
mbox = mh_open_folder (current_folder, 0);
mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
wh_env.file = mh_expand_name (wh_env.draftfolder, "forw", 0);
if (!wh_env.draftfile)
wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0);
if (build_only || !wh_env.draftfolder)
wh_env.file = mh_expand_name (NULL, "draft", 0);
else
{
if (mh_draft_message (NULL, draftmessage, &wh_env.file))
return 1;
}
wh_env.draftfile = wh_env.file;
switch (build_only ?
DISP_REPLACE : check_draft_disposition (&wh_env, use_draft))
......@@ -443,8 +453,6 @@ main (int argc, char **argv)
exit (0);
case DISP_USE:
unlink (wh_env.file);
rename (wh_env.draftfile, wh_env.file);
break;
case DISP_REPLACE:
......@@ -456,7 +464,8 @@ main (int argc, char **argv)
/* Exit immediately if --build is given */
if (build_only)
{
rename (wh_env.file, wh_env.draftfile);
if (strcmp (wh_env.file, wh_env.draftfile))
rename (wh_env.file, wh_env.draftfile);
return 0;
}
......
......@@ -122,6 +122,7 @@ static int query_mode = 0; /* --query flag */
static int use_draft = 0; /* --use flag */
static char *mhl_filter = NULL; /* --filter flag */
static int annotate; /* --annotate flag */
static char *draftmessage = "new";
static int
decode_cc_flag (const char *opt, const char *arg)
......@@ -199,7 +200,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
break;
case ARG_DRAFTMESSAGE:
wh_env.draftmessage = arg;
draftmessage = arg;
break;
case ARG_USE:
......@@ -291,8 +292,6 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
exit (0);
case DISP_USE:
unlink (wh->file);
rename (wh->draftfile, wh->file);
break;
case DISP_REPLACE:
......@@ -359,7 +358,8 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
mu_mailbox_get_url (mbox, &url);
mh_message_number (msg, &num);
asprintf (&msgname, "%s/%s", mu_url_to_string (url), mu_umaxtostr (0, num));
asprintf (&msgname, "%s/%s",
mu_url_to_string (url), mu_umaxtostr (0, num));
p = strchr (msgname, ':');
if (!p)
wh->msg = msgname;
......@@ -397,8 +397,16 @@ main (int argc, char **argv)
return 1;
}
wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0);
wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0);
if (build_only)
wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0);
else if (wh_env.draftfolder)
{
if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file))
return 1;
}
else
wh_env.file = mh_expand_name (wh_env.draftfolder, "draft", 0);
wh_env.draftfile = wh_env.file;
make_draft (mbox, DISP_REPLACE, &wh_env);
......
......@@ -55,12 +55,18 @@ struct mh_option mh_option[] = {
struct mh_whatnow_env wh_env = { 0 };
static int initial_edit = 1;
static char *draftmessage = "cur";
static int
opt_handler (int key, char *arg, void *unused, struct argp_state *state)
{
switch (key)
{
case ARGP_KEY_INIT:
wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
break;
case ARG_DRAFTFOLDER:
wh_env.draftfolder = arg;
break;
......@@ -78,7 +84,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state)
break;
case ARG_DRAFTMESSAGE:
wh_env.draftmessage = arg;
draftmessage = arg;
break;
case ARG_PROMPT:
......@@ -109,9 +115,15 @@ main (int argc, char **argv)
argv += index;
if (argc)
wh_env.draftfile = argv[0];
else if (wh_env.draftfolder)
{
if (mh_draft_message (wh_env.draftfolder, draftmessage,
&wh_env.file))
return 1;
}
else
wh_env.draftfile = mh_draft_name ();
wh_env.file = wh_env.draftfile;
wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0);
wh_env.draftfile = wh_env.file;
wh_env.msg = getenv ("mhaltmsg");
return mh_whatnow (&wh_env, initial_edit);
}
......