Fix semantics of -build/-draftmessage/-[no]draftfolder options for compatibility…
… with other implementations of MH
Showing
4 changed files
with
56 additions
and
22 deletions
... | @@ -80,6 +80,7 @@ const char *formfile; | ... | @@ -80,6 +80,7 @@ const char *formfile; |
80 | static int initial_edit = 1; | 80 | static int initial_edit = 1; |
81 | static int build_only = 0; /* --build flag */ | 81 | static int build_only = 0; /* --build flag */ |
82 | static int use_draft = 0; /* --use flag */ | 82 | static int use_draft = 0; /* --use flag */ |
83 | static char *draftmessage = "new"; | ||
83 | 84 | ||
84 | static int | 85 | static int |
85 | opt_handler (int key, char *arg, void *unused, struct argp_state *state) | 86 | 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) | ... | @@ -112,11 +113,12 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) |
112 | break; | 113 | break; |
113 | 114 | ||
114 | case ARG_DRAFTMESSAGE: | 115 | case ARG_DRAFTMESSAGE: |
115 | wh_env.draftmessage = arg; | 116 | draftmessage = arg; |
116 | break; | 117 | break; |
117 | 118 | ||
118 | case ARG_USE: | 119 | case ARG_USE: |
119 | use_draft = is_true (arg); | 120 | use_draft = is_true (arg); |
121 | draftmessage = "cur"; | ||
120 | break; | 122 | break; |
121 | 123 | ||
122 | case ARG_NOUSE: | 124 | case ARG_NOUSE: |
... | @@ -214,9 +216,14 @@ main (int argc, char **argv) | ... | @@ -214,9 +216,14 @@ main (int argc, char **argv) |
214 | mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, | 216 | mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc, |
215 | opt_handler, NULL, &index); | 217 | opt_handler, NULL, &index); |
216 | 218 | ||
217 | wh_env.file = mh_expand_name (wh_env.draftfolder, "comp", 0); | 219 | if (build_only || !wh_env.draftfolder) |
218 | if (!wh_env.draftfile) | 220 | wh_env.file = mh_expand_name (NULL, "draft", 0); |
219 | wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0); | 221 | else if (wh_env.draftfolder) |
222 | { | ||
223 | if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file)) | ||
224 | return 1; | ||
225 | } | ||
226 | wh_env.draftfile = wh_env.file; | ||
220 | 227 | ||
221 | switch (check_draft_disposition (&wh_env, use_draft)) | 228 | switch (check_draft_disposition (&wh_env, use_draft)) |
222 | { | 229 | { |
... | @@ -224,8 +231,6 @@ main (int argc, char **argv) | ... | @@ -224,8 +231,6 @@ main (int argc, char **argv) |
224 | exit (0); | 231 | exit (0); |
225 | 232 | ||
226 | case DISP_USE: | 233 | case DISP_USE: |
227 | unlink (wh_env.file); | ||
228 | rename (wh_env.draftfile, wh_env.file); | ||
229 | break; | 234 | break; |
230 | 235 | ||
231 | case DISP_REPLACE: | 236 | case DISP_REPLACE: | ... | ... |
... | @@ -112,6 +112,7 @@ static enum encap_type encap = encap_clear; /* controlled by --format, --form | ... | @@ -112,6 +112,7 @@ static enum encap_type encap = encap_clear; /* controlled by --format, --form |
112 | and --mime flags */ | 112 | and --mime flags */ |
113 | static int use_draft = 0; /* --use flag */ | 113 | static int use_draft = 0; /* --use flag */ |
114 | static int width = 80; /* --width flag */ | 114 | static int width = 80; /* --width flag */ |
115 | static char *draftmessage = "new"; | ||
115 | 116 | ||
116 | static mh_msgset_t msgset; | 117 | static mh_msgset_t msgset; |
117 | static mu_mailbox_t mbox; | 118 | static mu_mailbox_t mbox; |
... | @@ -137,9 +138,13 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) | ... | @@ -137,9 +138,13 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) |
137 | case ARG_DRAFTFOLDER: | 138 | case ARG_DRAFTFOLDER: |
138 | wh_env.draftfolder = arg; | 139 | wh_env.draftfolder = arg; |
139 | break; | 140 | break; |
141 | |||
142 | case ARG_NODRAFTFOLDER: | ||
143 | wh_env.draftfolder = NULL; | ||
144 | break; | ||
140 | 145 | ||
141 | case ARG_DRAFTMESSAGE: | 146 | case ARG_DRAFTMESSAGE: |
142 | wh_env.draftmessage = arg; | 147 | draftmessage = arg; |
143 | break; | 148 | break; |
144 | 149 | ||
145 | case ARG_USE: | 150 | case ARG_USE: |
... | @@ -432,9 +437,14 @@ main (int argc, char **argv) | ... | @@ -432,9 +437,14 @@ main (int argc, char **argv) |
432 | mbox = mh_open_folder (current_folder, 0); | 437 | mbox = mh_open_folder (current_folder, 0); |
433 | mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); | 438 | mh_msgset_parse (mbox, &msgset, argc, argv, "cur"); |
434 | 439 | ||
435 | wh_env.file = mh_expand_name (wh_env.draftfolder, "forw", 0); | 440 | if (build_only || !wh_env.draftfolder) |
436 | if (!wh_env.draftfile) | 441 | wh_env.file = mh_expand_name (NULL, "draft", 0); |
437 | wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0); | 442 | else |
443 | { | ||
444 | if (mh_draft_message (NULL, draftmessage, &wh_env.file)) | ||
445 | return 1; | ||
446 | } | ||
447 | wh_env.draftfile = wh_env.file; | ||
438 | 448 | ||
439 | switch (build_only ? | 449 | switch (build_only ? |
440 | DISP_REPLACE : check_draft_disposition (&wh_env, use_draft)) | 450 | DISP_REPLACE : check_draft_disposition (&wh_env, use_draft)) |
... | @@ -443,8 +453,6 @@ main (int argc, char **argv) | ... | @@ -443,8 +453,6 @@ main (int argc, char **argv) |
443 | exit (0); | 453 | exit (0); |
444 | 454 | ||
445 | case DISP_USE: | 455 | case DISP_USE: |
446 | unlink (wh_env.file); | ||
447 | rename (wh_env.draftfile, wh_env.file); | ||
448 | break; | 456 | break; |
449 | 457 | ||
450 | case DISP_REPLACE: | 458 | case DISP_REPLACE: |
... | @@ -456,7 +464,8 @@ main (int argc, char **argv) | ... | @@ -456,7 +464,8 @@ main (int argc, char **argv) |
456 | /* Exit immediately if --build is given */ | 464 | /* Exit immediately if --build is given */ |
457 | if (build_only) | 465 | if (build_only) |
458 | { | 466 | { |
459 | rename (wh_env.file, wh_env.draftfile); | 467 | if (strcmp (wh_env.file, wh_env.draftfile)) |
468 | rename (wh_env.file, wh_env.draftfile); | ||
460 | return 0; | 469 | return 0; |
461 | } | 470 | } |
462 | 471 | ... | ... |
... | @@ -122,6 +122,7 @@ static int query_mode = 0; /* --query flag */ | ... | @@ -122,6 +122,7 @@ static int query_mode = 0; /* --query flag */ |
122 | static int use_draft = 0; /* --use flag */ | 122 | static int use_draft = 0; /* --use flag */ |
123 | static char *mhl_filter = NULL; /* --filter flag */ | 123 | static char *mhl_filter = NULL; /* --filter flag */ |
124 | static int annotate; /* --annotate flag */ | 124 | static int annotate; /* --annotate flag */ |
125 | static char *draftmessage = "new"; | ||
125 | 126 | ||
126 | static int | 127 | static int |
127 | decode_cc_flag (const char *opt, const char *arg) | 128 | 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) | ... | @@ -199,7 +200,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) |
199 | break; | 200 | break; |
200 | 201 | ||
201 | case ARG_DRAFTMESSAGE: | 202 | case ARG_DRAFTMESSAGE: |
202 | wh_env.draftmessage = arg; | 203 | draftmessage = arg; |
203 | break; | 204 | break; |
204 | 205 | ||
205 | case ARG_USE: | 206 | case ARG_USE: |
... | @@ -291,8 +292,6 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) | ... | @@ -291,8 +292,6 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) |
291 | exit (0); | 292 | exit (0); |
292 | 293 | ||
293 | case DISP_USE: | 294 | case DISP_USE: |
294 | unlink (wh->file); | ||
295 | rename (wh->draftfile, wh->file); | ||
296 | break; | 295 | break; |
297 | 296 | ||
298 | case DISP_REPLACE: | 297 | case DISP_REPLACE: |
... | @@ -359,7 +358,8 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) | ... | @@ -359,7 +358,8 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) |
359 | 358 | ||
360 | mu_mailbox_get_url (mbox, &url); | 359 | mu_mailbox_get_url (mbox, &url); |
361 | mh_message_number (msg, &num); | 360 | mh_message_number (msg, &num); |
362 | asprintf (&msgname, "%s/%s", mu_url_to_string (url), mu_umaxtostr (0, num)); | 361 | asprintf (&msgname, "%s/%s", |
362 | mu_url_to_string (url), mu_umaxtostr (0, num)); | ||
363 | p = strchr (msgname, ':'); | 363 | p = strchr (msgname, ':'); |
364 | if (!p) | 364 | if (!p) |
365 | wh->msg = msgname; | 365 | wh->msg = msgname; |
... | @@ -397,8 +397,16 @@ main (int argc, char **argv) | ... | @@ -397,8 +397,16 @@ main (int argc, char **argv) |
397 | return 1; | 397 | return 1; |
398 | } | 398 | } |
399 | 399 | ||
400 | wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0); | 400 | if (build_only) |
401 | wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0); | 401 | wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0); |
402 | else if (wh_env.draftfolder) | ||
403 | { | ||
404 | if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file)) | ||
405 | return 1; | ||
406 | } | ||
407 | else | ||
408 | wh_env.file = mh_expand_name (wh_env.draftfolder, "draft", 0); | ||
409 | wh_env.draftfile = wh_env.file; | ||
402 | 410 | ||
403 | make_draft (mbox, DISP_REPLACE, &wh_env); | 411 | make_draft (mbox, DISP_REPLACE, &wh_env); |
404 | 412 | ... | ... |
... | @@ -55,12 +55,18 @@ struct mh_option mh_option[] = { | ... | @@ -55,12 +55,18 @@ struct mh_option mh_option[] = { |
55 | 55 | ||
56 | struct mh_whatnow_env wh_env = { 0 }; | 56 | struct mh_whatnow_env wh_env = { 0 }; |
57 | static int initial_edit = 1; | 57 | static int initial_edit = 1; |
58 | static char *draftmessage = "cur"; | ||
58 | 59 | ||
59 | static int | 60 | static int |
60 | opt_handler (int key, char *arg, void *unused, struct argp_state *state) | 61 | opt_handler (int key, char *arg, void *unused, struct argp_state *state) |
61 | { | 62 | { |
62 | switch (key) | 63 | switch (key) |
63 | { | 64 | { |
65 | case ARGP_KEY_INIT: | ||
66 | wh_env.draftfolder = mh_global_profile_get ("Draft-Folder", | ||
67 | mu_folder_directory ()); | ||
68 | break; | ||
69 | |||
64 | case ARG_DRAFTFOLDER: | 70 | case ARG_DRAFTFOLDER: |
65 | wh_env.draftfolder = arg; | 71 | wh_env.draftfolder = arg; |
66 | break; | 72 | break; |
... | @@ -78,7 +84,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) | ... | @@ -78,7 +84,7 @@ opt_handler (int key, char *arg, void *unused, struct argp_state *state) |
78 | break; | 84 | break; |
79 | 85 | ||
80 | case ARG_DRAFTMESSAGE: | 86 | case ARG_DRAFTMESSAGE: |
81 | wh_env.draftmessage = arg; | 87 | draftmessage = arg; |
82 | break; | 88 | break; |
83 | 89 | ||
84 | case ARG_PROMPT: | 90 | case ARG_PROMPT: |
... | @@ -109,9 +115,15 @@ main (int argc, char **argv) | ... | @@ -109,9 +115,15 @@ main (int argc, char **argv) |
109 | argv += index; | 115 | argv += index; |
110 | if (argc) | 116 | if (argc) |
111 | wh_env.draftfile = argv[0]; | 117 | wh_env.draftfile = argv[0]; |
118 | else if (wh_env.draftfolder) | ||
119 | { | ||
120 | if (mh_draft_message (wh_env.draftfolder, draftmessage, | ||
121 | &wh_env.file)) | ||
122 | return 1; | ||
123 | } | ||
112 | else | 124 | else |
113 | wh_env.draftfile = mh_draft_name (); | 125 | wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0); |
114 | wh_env.file = wh_env.draftfile; | 126 | wh_env.draftfile = wh_env.file; |
115 | wh_env.msg = getenv ("mhaltmsg"); | 127 | wh_env.msg = getenv ("mhaltmsg"); |
116 | return mh_whatnow (&wh_env, initial_edit); | 128 | return mh_whatnow (&wh_env, initial_edit); |
117 | } | 129 | } | ... | ... |
-
Please register or sign in to post a comment