diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2017-06-11 00:29:06 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2017-06-11 00:29:06 +0300 |
commit | fe90e86dac8c9c91a35347ee5bb4513195263ee2 (patch) | |
tree | 2fdb185baa9e0807641147881adf302e5aa39ea6 /mh/whom.c | |
parent | 263e2e9f9fcf721c11a61a16dca4cb38d6385fe9 (diff) | |
download | mailutils-fe90e86dac8c9c91a35347ee5bb4513195263ee2.tar.gz mailutils-fe90e86dac8c9c91a35347ee5bb4513195263ee2.tar.bz2 |
Fix the -nodraftfolder and -nowhatnowproc options.
The commit 744c4a9c didn't take into account the -nodraftfolder
and -nowhatnowproc options, which can be used to cancel the
effect of the corresponding facilities. This commit fixes it.
* mh/mh_getopt.c (mh_getopt_ext): New function.
* mh/mh_getopt.h (mh_getopt_ext): New prototype.
(mh_optinit): New struct.
* mh/tests/comp.at: Test the use of Draft-Folder
* mh/tests/forw.at: Likewise.
* mh/tests/repl.at: Likewise.
* mh/comp.c (main): use mh_getopt_ext to properly process draftfolder
and whatnowproc.
* mh/forw.c: Likewise.
* mh/repl.c: Likewise.
* mh/mh.h (mh_whom): Remove.
(mh_whom_header, mh_whom_file, mh_whom_message): New protos.
* mh/mh_alias.y (mh_read_aliases): Don't read aliases twice.
* mh/mh_whatnow.c (whom): Use mh_whom_file.
* mh/mh_whom.c (mh_whom): Rewrite and rename to mh_whom_file.
(mh_whom_header, mh_whom_message): New functions.
* mh/whom.c: Use mh_getopt_ext. Interpret command line
arguments, depending on whether the draftfile facility is in use.
Diffstat (limited to 'mh/whom.c')
-rw-r--r-- | mh/whom.c | 63 |
1 files changed, 49 insertions, 14 deletions
@@ -21,7 +21,7 @@ static char prog_doc[] = N_("Report to whom a message would go"); static char args_doc[] = "[FILE]"; static int check_recipients; -static int use_draft; /* Use the prepared draft */ +static char *message; static const char *draft_folder; /* Use this draft folder */ static void @@ -45,7 +45,7 @@ static struct mu_option options[] = { mu_c_string, NULL, add_alias }, { "draft", 0, NULL, MU_OPTION_DEFAULT, N_("use prepared draft"), - mu_c_bool, &use_draft }, + mu_c_string, &message, NULL, "draft" }, { "draftfolder", 0, N_("FOLDER"), MU_OPTION_DEFAULT, N_("specify the folder for message drafts"), mu_c_string, &draft_folder }, @@ -60,22 +60,57 @@ static struct mu_option options[] = { mu_c_bool, &check_recipients }, MU_OPTION_END }; + +static struct mh_optinit optinit[] = { + { "draftfolder", "Draft-Folder" }, + { NULL } +}; int main (int argc, char **argv) { - char *name = "draft"; - - mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL); + int rc; + + mh_getopt_ext (&argc, &argv, options, 0, optinit, args_doc, prog_doc, NULL); - if (!use_draft && argc > 0) - name = argv[0]; + if (draft_folder) + { + mu_mailbox_t mbox = mh_open_folder (draft_folder, MU_STREAM_READ); + mu_msgset_t msgset; + size_t msgno; + mu_message_t msg; + + mh_msgset_parse (&msgset, mbox, argc, argv, "cur"); + if (!mh_msgset_single_message (msgset)) + { + mu_error (_("only one message at a time!")); + return 1; + } + msgno = mh_msgset_first (msgset, RET_MSGNO); + rc = mu_mailbox_get_message (mbox, msgno, &msg); + if (rc) + { + mu_error (_("can't read message: %s"), mu_strerror (rc)); + exit (1); + } + rc = mh_whom_message (msg, check_recipients); + } + else + { + if (argc > 0) + { + if (message || argc > 1) + { + mu_error (_("only one file at a time!")); + exit (1); + } + message = argv[0]; + } + else + message = "draft"; + rc = mh_whom_file (mh_expand_name (draft_folder, message, NAME_ANY), + check_recipients); + } - if (!draft_folder) - draft_folder = mh_global_profile_get ("Draft-Folder", - mu_folder_directory ()); - - - return mh_whom (mh_expand_name (draft_folder, name, NAME_ANY), - check_recipients) ? 1 : 0; + return rc ? 1 : 0; } |