summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2017-06-11 00:29:06 +0300
committerSergey Poznyakoff <gray@gnu.org>2017-06-11 00:29:06 +0300
commitfe90e86dac8c9c91a35347ee5bb4513195263ee2 (patch)
tree2fdb185baa9e0807641147881adf302e5aa39ea6
parent263e2e9f9fcf721c11a61a16dca4cb38d6385fe9 (diff)
downloadmailutils-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.
-rw-r--r--mh/comp.c13
-rw-r--r--mh/forw.c12
-rw-r--r--mh/mh.h6
-rw-r--r--mh/mh_alias.l0
-rw-r--r--mh/mh_alias.y3
-rw-r--r--mh/mh_getopt.c42
-rw-r--r--mh/mh_getopt.h13
-rw-r--r--mh/mh_whatnow.c3
-rw-r--r--mh/mh_whom.c76
-rw-r--r--mh/repl.c14
-rw-r--r--mh/tests/comp.at43
-rw-r--r--mh/tests/forw.at123
-rw-r--r--mh/tests/repl.at64
-rw-r--r--mh/whom.c59
14 files changed, 411 insertions, 60 deletions
diff --git a/mh/comp.c b/mh/comp.c
index 075bb4516..29389c69e 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -127,15 +127,16 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file)
return rc;
}
+static struct mh_optinit optinit[] = {
+ { "draftfolder", "Draft-Folder" },
+ { "whatnowproc", "whatnowproc" },
+ { NULL }
+};
+
int
main (int argc, char **argv)
{
- mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
-
- if (!draftfolder)
- draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
- if (!whatnowproc)
- whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
+ mh_getopt_ext (&argc, &argv, options, 0, optinit, args_doc, prog_doc, NULL);
if (use_draft)
draftmessage = "cur";
diff --git a/mh/forw.c b/mh/forw.c
index 5e0e08b97..016ac84bc 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -377,17 +377,19 @@ finish_draft ()
mu_stream_destroy (&stream);
}
+static struct mh_optinit optinit[] = {
+ { "draftfolder", "Draft-Folder" },
+ { "whatnowproc", "whatnowproc" },
+ { NULL }
+};
+
int
main (int argc, char **argv)
{
int rc;
- mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+ mh_getopt_ext (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, optinit,
args_doc, prog_doc, NULL);
- if (!draftfolder)
- draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
- if (!whatnowproc)
- whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
if (!formfile)
mh_find_file ("forwcomps", &formfile);
diff --git a/mh/mh.h b/mh/mh.h
index c15f8569f..2a3cd88a1 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -342,7 +342,11 @@ int mh_usedraft (const char *filename);
int mh_file_copy (const char *from, const char *to);
char *mh_draft_name (void);
char *mh_create_message_id (int);
-int mh_whom (const char *filename, int check);
+
+int mh_whom_header (mu_header_t hdr);
+int mh_whom_file (const char *filename, int check);
+int mh_whom_message (mu_message_t msg, int check);
+
void mh_set_reply_regex (const char *str);
int mh_decode_2047 (char *text, char **decoded_text);
const char *mh_charset (const char *);
diff --git a/mh/mh_alias.l b/mh/mh_alias.l
index df81ce30f..0deb7c99b 100644
--- a/mh/mh_alias.l
+++ b/mh/mh_alias.l
diff --git a/mh/mh_alias.y b/mh/mh_alias.y
index 0d6bffcc2..54e3cd1c6 100644
--- a/mh/mh_alias.y
+++ b/mh/mh_alias.y
@@ -493,6 +493,9 @@ mh_read_aliases ()
{
const char *p;
+ if (alias_list)
+ return 0;
+
p = mh_global_profile_get ("Aliasfile", NULL);
if (p)
{
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 65fe3e8c7..16a6e5c55 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -179,9 +179,38 @@ has_folder_option (struct mu_option *opt)
return 0;
}
+static void
+opt_init (struct mu_parseopt *po,
+ struct mu_option **optv, struct mh_optinit *optinit)
+{
+ if (!optinit)
+ return;
+ for (; optinit->opt; optinit++)
+ {
+ size_t i;
+ for (i = 0; optv[i]; i++)
+ {
+ struct mu_option *opt;
+ for (opt = optv[i]; !MU_OPTION_IS_END (opt); opt++)
+ {
+ if (strcmp (opt->opt_long, optinit->opt) == 0)
+ {
+ char const *val = mh_global_profile_get (optinit->var, NULL);
+ if (val)
+ {
+ (opt->opt_set ?
+ opt->opt_set : mu_option_set_value) (po, opt, val);
+ }
+ break;
+ }
+ }
+ }
+ }
+}
+
void
-mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
- int mhflags,
+mh_getopt_ext (int *pargc, char ***pargv, struct mu_option *options,
+ int mhflags, struct mh_optinit *optinit,
char *argdoc, char *progdoc, char *extradoc)
{
int argc = *pargc;
@@ -256,6 +285,7 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
if (options)
optv[i++] = options;
optv[i] = NULL;
+ opt_init (&po, optv, optinit);
if (mu_parseopt (&po, argc, argv, optv, flags))
exit (po.po_exit_error);
@@ -285,6 +315,14 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
}
void
+mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
+ int mhflags, char *argdoc, char *progdoc, char *extradoc)
+{
+ mh_getopt_ext (pargc, pargv, options, mhflags, NULL, argdoc, progdoc,
+ extradoc);
+}
+
+void
mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
mu_error (_("option is not yet implemented: %s"), opt->opt_long);
diff --git a/mh/mh_getopt.h b/mh/mh_getopt.h
index 2aa90b669..684ace678 100644
--- a/mh/mh_getopt.h
+++ b/mh/mh_getopt.h
@@ -20,10 +20,19 @@
#define MH_GETOPT_DEFAULT_FOLDER 0x1
-void mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
- int flags,
+struct mh_optinit
+{
+ char const *opt; /* Option name */
+ char const *var; /* mh_property name */
+};
+
+void mh_getopt_ext (int *pargc, char ***pargv, struct mu_option *options,
+ int mhflags, struct mh_optinit *optinit,
char *argdoc, char *progdoc, char *extradoc);
+void mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
+ int flags, char *argdoc, char *progdoc, char *extradoc);
+
void mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt,
char const *arg);
void mh_opt_notimpl_warning (struct mu_parseopt *po, struct mu_option *opt,
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 5dc15b553..0bd2acabe 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -544,7 +544,8 @@ whom (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
if (!wh->file)
mu_error (_("no draft file to display"));
else
- mh_whom (wh->file, (argc == 2
+ mh_whom_file (wh->file,
+ (argc == 2
&& (strcmp (argv[1], "-check") == 0
|| strcmp (argv[1], "--check") == 0)));
return 0;
diff --git a/mh/mh_whom.c b/mh/mh_whom.c
index bbdef7ac5..f3067d1ab 100644
--- a/mh/mh_whom.c
+++ b/mh/mh_whom.c
@@ -261,33 +261,12 @@ read_header (mu_stream_t stream)
}
int
-mh_whom (const char *filename, int check)
-{
- int rc = 0;
-
- if (access (filename, R_OK))
- {
- mu_error ("%s: %s", filename, mu_strerror (errno));
- rc = -1;
- }
- else
+mh_whom_header (mu_header_t hdr)
{
size_t count = 0;
- mu_header_t hdr;
- mu_stream_t str;
int rc;
const char *val;
- rc = mu_file_stream_create (&str, filename, MU_STREAM_READ);
- if (rc)
- {
- mu_diag_funcall (MU_DIAG_ERROR, "mu_file_stream_create",
- filename, rc);
- exit (1);
- }
- hdr = read_header (str);
- mu_stream_unref (str);
-
mh_read_aliases ();
if (mu_header_sget_value (hdr, MU_HEADER_TO, &val) == 0)
@@ -314,9 +293,58 @@ mh_whom (const char *filename, int check)
mu_error(_("no recipients"));
rc = -1;
}
- mu_header_destroy (&hdr);
- }
+
destroy_addrs (&network_rcp);
destroy_addrs (&local_rcp);
return rc;
}
+
+int
+mh_whom_file (const char *filename, int check)
+{
+ int rc = 0;
+
+ if (access (filename, R_OK))
+ {
+ mu_error ("%s: %s", filename, mu_strerror (errno));
+ rc = -1;
+ }
+ else
+ {
+ mu_header_t hdr;
+ mu_stream_t str;
+ int rc;
+
+ rc = mu_file_stream_create (&str, filename, MU_STREAM_READ);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_file_stream_create",
+ filename, rc);
+ exit (1);
+ }
+ hdr = read_header (str);
+ mu_stream_unref (str);
+
+ rc = mh_whom_header (hdr);
+ mu_header_destroy (&hdr);
+ }
+ return rc;
+}
+
+int
+mh_whom_message (mu_message_t msg, int check)
+{
+ mu_header_t hdr;
+ int rc;
+
+ rc = mu_message_get_header (msg, &hdr);
+ if (rc)
+ mu_error (_("can't get headers: %s"), mu_strerror (rc));
+ else
+ {
+ rc = mh_whom_header (hdr);
+ mu_header_destroy (&hdr);
+ }
+ return rc;
+}
+
diff --git a/mh/repl.c b/mh/repl.c
index 1cc192971..169f977c0 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -289,20 +289,20 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
}
}
+static struct mh_optinit optinit[] = {
+ { "draftfolder", "Draft-Folder" },
+ { "whatnowproc", "whatnowproc" },
+ { NULL }
+};
+
int
main (int argc, char **argv)
{
int rc;
- mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+ mh_getopt_ext (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, optinit,
args_doc, prog_doc, NULL);
- if (!draftfolder)
- draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
- if (!whatnowproc)
- whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
-
-
if (!format_str)
format_str = default_format_str;
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index 563310cca..7a63e5ff7 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -193,6 +193,49 @@ message body
Seen by mhed
])
+MH_CHECK([use Draft-Folder],[comp07 draftfolder],
+[mkdir Mail/drafts
+echo "Draft-Folder: +drafts" >> $MH
+echo 'quit' | compcmd | cwdrepl
+sed 's/ *$//' Mail/drafts/1
+],
+[0],
+[-- Editor invocation: ./Mail/drafts/1
+-- Input file:
+To:
+cc:
+Subject:
+--------
+-- Input file end
+What now? draft left on "./Mail/drafts/1".
+To:
+cc:
+Subject:
+--------
+Seen by mhed
+])
+
+MH_CHECK([-nodraftfolder],[comp08 nodraftfolder draftfolder],
+[mkdir Mail/drafts
+echo "Draft-Folder: +drafts" >> $MH
+echo 'quit' | compcmd -nodraftfolder | cwdrepl
+sed 's/ *$//' Mail/draft
+],
+[0],
+[-- Editor invocation: ./Mail/draft
+-- Input file:
+To:
+cc:
+Subject:
+--------
+-- Input file end
+What now? draft left on "./Mail/draft".
+To:
+cc:
+Subject:
+--------
+Seen by mhed
+])
m4_popdef([compcmd])
m4_popdef([MH_KEYWORDS])
diff --git a/mh/tests/forw.at b/mh/tests/forw.at
index e0566dfe7..f668a3389 100644
--- a/mh/tests/forw.at
+++ b/mh/tests/forw.at
@@ -397,6 +397,129 @@ message body
What now? draft left on "./Mail/draft".
])
+MH_CHECK([Draft-Folder],[forw07 forw-draftfolder draftfolder],[
+mkdir Mail/inbox
+mkdir Mail/drafts
+echo "Draft-Folder: +drafts" >> $MH
+
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+echo "quit" | forwcmd 1 | cwdrepl
+echo == Mail/drafts/1 ==
+cat Mail/drafts/1
+echo == Message ==
+sed '/^X-IMAPbase/d' Mail/inbox/1
+],
+[0],
+[-- Editor invocation: ./Mail/drafts/1
+-- Input file:
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+-- Input file end
+What now? draft left on "./Mail/drafts/1".
+== Mail/drafts/1 ==
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+Seen by mhed
+== Message ==
+From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+MH_CHECK([-nodraftfolder],[forw08 forw-nodraftfolder nodraftfolder draftfolder],[
+mkdir Mail/inbox
+mkdir Mail/drafts
+echo "Draft-Folder: +drafts" >> $MH
+
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+echo "quit" | forwcmd -nodraftfolder 1 | cwdrepl
+echo == Mail/draft ==
+cat Mail/draft
+echo == Message ==
+sed '/^X-IMAPbase/d' Mail/inbox/1
+],
+[0],
+[-- Editor invocation: ./Mail/draft
+-- Input file:
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+-- Input file end
+What now? draft left on "./Mail/draft".
+== Mail/draft ==
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+Seen by mhed
+== Message ==
+From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+
m4_popdef([forwcmd])
m4_popdef([MH_KEYWORDS])
diff --git a/mh/tests/repl.at b/mh/tests/repl.at
index bd58e9f33..f8a194c08 100644
--- a/mh/tests/repl.at
+++ b/mh/tests/repl.at
@@ -79,6 +79,70 @@ X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
Seen by mhed
])
+MH_CHECK([Draft-Folder],[repl02 repl-draftfolder draftfolder],[
+mkdir Mail/inbox
+mkdir Mail/drafts
+echo "Draft-Folder: +drafts" >> $MH
+
+AT_DATA([Mail/inbox/1],[From: gray@example.com
+To: root@example.com
+Subject: test input
+
+message body
+])
+echo "quit" | replcmd +inbox 1 | cwdrepl
+echo == Mail/drafts/1 ==
+cat Mail/drafts/1
+],
+[0],
+[-- Editor invocation: ./Mail/drafts/1
+-- Input file:
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+-- Input file end
+What now? draft left on "./Mail/drafts/1".
+== Mail/drafts/1 ==
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+Seen by mhed
+])
+
+MH_CHECK([-nodraftfolder],[repl03 repl-nodraftfolder nodraftfolder draftfolder],[
+mkdir Mail/inbox
+mkdir Mail/drafts
+echo "Draft-Folder: +drafts" >> $MH
+
+AT_DATA([Mail/inbox/1],[From: gray@example.com
+To: root@example.com
+Subject: test input
+
+message body
+])
+echo "quit" | replcmd -nodraftfolder +inbox 1 | cwdrepl
+echo == Mail/draft ==
+cat Mail/draft
+],
+[0],
+[-- Editor invocation: ./Mail/draft
+-- Input file:
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+-- Input file end
+What now? draft left on "./Mail/draft".
+== Mail/draft ==
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+Seen by mhed
+])
+
m4_popdef([replcmd])
m4_popdef([MH_KEYWORDS])
# End of repl.at
diff --git a/mh/whom.c b/mh/whom.c
index 7c3c5ab99..97deabb38 100644
--- a/mh/whom.c
+++ b/mh/whom.c
@@ -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 },
@@ -61,21 +61,56 @@ static struct mu_option options[] = {
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;
- if (!use_draft && argc > 0)
- name = argv[0];
+ mh_getopt_ext (&argc, &argv, options, 0, optinit, args_doc, prog_doc, NULL);
- if (!draft_folder)
- draft_folder = mh_global_profile_get ("Draft-Folder",
- mu_folder_directory ());
+ 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);
+ }
- return mh_whom (mh_expand_name (draft_folder, name, NAME_ANY),
- check_recipients) ? 1 : 0;
+ return rc ? 1 : 0;
}

Return to:

Send suggestions and report system problems to the System administrator.