summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2017-06-15 22:09:30 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-06-16 09:50:36 +0300
commitc1f2442cd53e43cf11cc8f5b649b454b3f2cb03f (patch)
tree6ef0b4a8d01cb81d8f4f1ae2757ad4047ebb03f5
parent8b5715db380634336a231b0c8573c350992c8dce (diff)
parentfe90e86dac8c9c91a35347ee5bb4513195263ee2 (diff)
downloadmailutils-c1f2442cd53e43cf11cc8f5b649b454b3f2cb03f.tar.gz
mailutils-c1f2442cd53e43cf11cc8f5b649b454b3f2cb03f.tar.bz2
Merge branch 'master' into locus
-rw-r--r--NEWS9
-rw-r--r--mh/comp.c13
-rw-r--r--mh/forw.c14
-rw-r--r--mh/mh.h6
-rw-r--r--mh/mh_alias_gram.y3
-rw-r--r--mh/mh_getopt.c44
-rw-r--r--mh/mh_getopt.h13
-rw-r--r--mh/mh_whatnow.c7
-rw-r--r--mh/mh_whom.c86
-rw-r--r--mh/repl.c16
-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.c63
14 files changed, 431 insertions, 73 deletions
diff --git a/NEWS b/NEWS
index 266a99912..e35169161 100644
--- a/NEWS
+++ b/NEWS
@@ -1,13 +1,13 @@
-GNU mailutils NEWS -- history of user-visible changes. 2017-06-01
+GNU mailutils NEWS -- history of user-visible changes. 2017-06-16
Copyright (C) 2002-2017 Free Software Foundation, Inc.
See the end of file for copying conditions.
Please send mailutils bug reports to <bug-mailutils@gnu.org>.
Version 3.2.91 (Git)
* TLS configuration
Note the following changes to the TLS configuration:
@@ -66,24 +66,31 @@ is the same as for the global section described above, e.g.:
tls-mode required;
tls {
ssl-certificate-file /etc/ssl/cert/imap.pem;
ssl-key-file /etc/ssl/private/imap.key;
}
}
If the "tls" section is absent, but "tls-mode" is specified and it's
value is anything but "no", the settings from the global "tls" section
will be used. In this case, it is an error if the global "tls"
section is not defined.
+* Source location API
+
+Libmailutils provides functions for keeping track of locations in
+source files for diagnostic purposes.
+
+* Improve error reporting
+
* AM_GNU_MAILUTILS autoconf macro
Required version must be literal string.
The packed version number (MAILUTILS_VERSION_NUMBER) is no longer
defined. Instead, the following constants are defined in config.h:
MAILUTILS_VERSION_MAJOR Major version number
MAILUTILS_VERSION_MINOR Minor version number
MAILUTILS_VERSION_PATCH Patchlevel number (or 0, for stable releases).
* movemail: new option --progress-meter
diff --git a/mh/comp.c b/mh/comp.c
index 075bb4516..29389c69e 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -118,33 +118,34 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file)
mu_stream_destroy (&in);
mu_stream_close (out);
mu_stream_destroy (&out);
if (rc)
{
mu_error (_("error copying to \"%s\": %s"),
file, mu_strerror (rc));
}
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";
if (!formfile)
mh_find_file ("components", &formfile);
if (wh_env.file)
{
if (build_only)
{
mu_error (_("--build and --file cannot be used together"));
exit (1);
diff --git a/mh/forw.c b/mh/forw.c
index 5e0e08b97..016ac84bc 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -368,35 +368,37 @@ finish_draft ()
else
str = (char*) _("End of Forwarded messages");
rc = mu_stream_write (stream, str, strlen (str), NULL);
}
rc = mu_stream_write (stream, "\n\n", 2, NULL);
}
mu_stream_close (stream);
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,
- 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, MH_GETOPT_DEFAULT_FOLDER, optinit,
+ args_doc, prog_doc, NULL);
if (!formfile)
mh_find_file ("forwcomps", &formfile);
if (input_file)
{
if (encap == encap_mime)
{
mu_error (_("--build disables --mime"));
encap = encap_clear;
}
if (argc)
{
diff --git a/mh/mh.h b/mh/mh.h
index 69be72de2..76bc85e37 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -333,25 +333,29 @@ int mh_decode_rcpt_flag (const char *arg);
int mh_draft_message (const char *name, const char *msgspec, char **pname);
int mh_spawnp (const char *prog, const char *file);
int mh_whatnow (struct mh_whatnow_env *wh, int initial_edit);
int mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit,
const char *prog);
int mh_disposition (const char *filename);
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 *);
int mh_alias_read (char const *name, int fail);
int mh_alias_get (const char *name, mu_list_t *return_list);
int mh_alias_get_address (const char *name, mu_address_t *addr, int *incl);
int mh_alias_get_alias (const char *uname, mu_list_t *return_list);
int mh_read_aliases (void);
int mh_alias_expand (const char *str, mu_address_t *paddr, int *incl);
typedef int (*mh_alias_enumerator_t) (char *alias, mu_list_t names, void *data);
diff --git a/mh/mh_alias_gram.y b/mh/mh_alias_gram.y
index d7229983a..26b13ec83 100644
--- a/mh/mh_alias_gram.y
+++ b/mh/mh_alias_gram.y
@@ -493,24 +493,27 @@ unix_passwd_to_list ()
{
if (pw->pw_uid > 200)
mu_list_append (lst, mu_strdup (pw->pw_name));
}
endpwent();
return lst;
}
int
mh_read_aliases (void)
{
const char *p;
+
+ if (alias_list)
+ return 0;
p = mh_global_profile_get ("Aliasfile", NULL);
if (p)
{
struct mu_wordsplit ws;
if (mu_wordsplit (p, &ws, MU_WRDSF_DEFFLAGS))
{
mu_error (_("cannot split line `%s': %s"), p,
mu_wordsplit_strerror (&ws));
}
else
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
@@ -170,28 +170,57 @@ static int
has_folder_option (struct mu_option *opt)
{
while (!MU_OPTION_IS_END (opt))
{
if (MU_OPTION_IS_VALID_LONG_OPTION (opt)
&& strcmp (opt->opt_long, "folder") == 0)
return 1;
++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,
- char *argdoc, char *progdoc, char *extradoc)
+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;
char **argv = *pargv;
struct mu_parseopt po;
struct mu_option *optv[3];
struct getopt_data getopt_data;
char const *args[3];
int flags = MU_PARSEOPT_SINGLE_DASH | MU_PARSEOPT_IMMEDIATE;
int i;
/* Native Language Support */
MU_APP_INIT_NLS ();
@@ -247,24 +276,25 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
flags |= MU_PARSEOPT_VERSION_HOOK;
mu_set_program_name (argv[0]);
mh_init ();
augment_argv (&argc, &argv);
i = 0;
if (mhflags & MH_GETOPT_DEFAULT_FOLDER)
optv[i++] = folder_option;
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);
argc -= po.po_arg_start;
argv += po.po_arg_start;
process_std_options (argc, argv, &po);
process_folder_arg (&argc, argv, &po);
if (!argdoc && argc)
@@ -276,24 +306,32 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
mu_stream_printf (mu_strerr, " %s", argv[i]);
mu_stream_write (mu_strerr, "\n", 1, NULL);
exit (1);
}
*pargc = argc;
*pargv = argv;
mh_init2 ();
}
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);
exit (1);
}
void
mh_opt_notimpl_warning (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
if (opt->opt_type == mu_c_bool)
{
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
@@ -11,27 +11,36 @@
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <mailutils/nls.h>
#include <mailutils/opt.h>
#define MH_GETOPT_DEFAULT_FOLDER 0x1
+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);
+ 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,
char const *arg);
void mh_opt_clear_string (struct mu_parseopt *po, struct mu_option *opt,
char const *arg);
void mh_opt_find_file (struct mu_parseopt *po, struct mu_option *opt,
char const *arg);
void mh_opt_read_formfile (struct mu_parseopt *po, struct mu_option *opt,
char const *arg);
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
@@ -535,27 +535,28 @@ call_send (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
return 1;
}
return 0;
}
/* Whom action */
static int
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
- && (strcmp (argv[1], "-check") == 0
- || strcmp (argv[1], "--check") == 0)));
+ mh_whom_file (wh->file,
+ (argc == 2
+ && (strcmp (argv[1], "-check") == 0
+ || strcmp (argv[1], "--check") == 0)));
return 0;
}
/* Help table for whatnow */
static struct helpdata whatnow_helptab[] = {
{ "display [<>]",
N_("List the message being distributed/replied-to on the terminal.") },
{ "edit [<e <>]",
N_("Edit the message. If EDITOR is omitted use the one that was used on"
" the preceding round unless the profile entry \"LASTEDITOR-next\""
" names an alternate editor.") },
{ "list [<>]",
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
@@ -252,71 +252,99 @@ read_header (mu_stream_t stream)
rc = mu_header_create (&hdr, blurb, total);
free (blurb);
if (rc)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_header_create", NULL, rc);
exit (1);
}
return hdr;
}
int
-mh_whom (const char *filename, int check)
+mh_whom_header (mu_header_t hdr)
+{
+ size_t count = 0;
+ int rc;
+ const char *val;
+
+ mh_read_aliases ();
+
+ if (mu_header_sget_value (hdr, MU_HEADER_TO, &val) == 0)
+ scan_addrs (val, 0);
+ if (mu_header_sget_value (hdr, MU_HEADER_CC, &val) == 0)
+ scan_addrs (val, 0);
+ if (mu_header_sget_value (hdr, MU_HEADER_BCC, &val) == 0)
+ scan_addrs (val, 1);
+
+ if (local_rcp)
+ {
+ printf (" %s\n", _("-- Local Recipients --"));
+ mu_list_foreach (local_rcp, _print_local_recipient, &count);
+ }
+
+ if (network_rcp)
+ {
+ printf (" %s\n", _("-- Network Recipients --"));
+ mu_list_foreach (network_rcp, _print_recipient, &count);
+ }
+
+ if (count == 0)
+ {
+ mu_error(_("no recipients"));
+ rc = -1;
+ }
+
+ 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
{
- 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)
- scan_addrs (val, 0);
- if (mu_header_sget_value (hdr, MU_HEADER_CC, &val) == 0)
- scan_addrs (val, 0);
- if (mu_header_sget_value (hdr, MU_HEADER_BCC, &val) == 0)
- scan_addrs (val, 1);
-
- if (local_rcp)
- {
- printf (" %s\n", _("-- Local Recipients --"));
- mu_list_foreach (local_rcp, _print_local_recipient, &count);
- }
+ rc = mh_whom_header (hdr);
+ mu_header_destroy (&hdr);
+ }
+ return rc;
+}
- if (network_rcp)
- {
- printf (" %s\n", _("-- Network Recipients --"));
- mu_list_foreach (network_rcp, _print_recipient, &count);
- }
+int
+mh_whom_message (mu_message_t msg, int check)
+{
+ mu_header_t hdr;
+ int rc;
- if (count == 0)
- {
- mu_error(_("no recipients"));
- rc = -1;
- }
+ 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);
}
- destroy_addrs (&network_rcp);
- destroy_addrs (&local_rcp);
return rc;
}
+
diff --git a/mh/repl.c b/mh/repl.c
index 1cc192971..169f977c0 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -280,37 +280,37 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
mu_umaxtostr (0, num));
p = strchr (msgname, ':');
if (!p)
wh->msg = msgname;
else
{
wh->msg = mu_strdup (p+1);
free (msgname);
}
}
}
+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,
- 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, MH_GETOPT_DEFAULT_FOLDER, optinit,
+ args_doc, prog_doc, NULL);
if (!format_str)
format_str = default_format_str;
if (mh_format_parse (format_str, &format))
{
mu_error (_("Bad format string"));
exit (1);
}
mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
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
@@ -184,17 +184,60 @@ Subject: test input
message body
-- Input file end
What now? draft left on "./Mail/drafts/1".
From: gray
To: root
Subject: test input
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])
# End of comp.at
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
@@ -388,16 +388,139 @@ To:
cc:
Subject:
--------
From: gray
To: root
Subject: test input
message body
-- Input file end
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])
# End of forw.at
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
@@ -70,15 +70,79 @@ 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([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
@@ -12,70 +12,105 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <mh.h>
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
add_alias (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
mh_alias_read (arg, 1);
}
static void
set_draftmessage (struct mu_parseopt *po, struct mu_option *opt,
char const *arg)
{
if (!draft_folder)
draft_folder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
}
static struct mu_option options[] = {
{ "alias", 0, N_("FILE"), MU_OPTION_DEFAULT,
N_("specify additional alias file"),
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 },
{ "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT,
N_("undo the effect of the last -draftfolder option"),
mu_c_string, &draft_folder, mh_opt_clear_string },
{ "draftmessage", 0, NULL, MU_OPTION_DEFAULT,
N_("treat the arguments as a list of messages from the draftfolder"),
mu_c_string, NULL, set_draftmessage },
{ "check", 0, NULL, MU_OPTION_DEFAULT,
N_("check if addresses are deliverable"),
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;
}

Return to:

Send suggestions and report system problems to the System administrator.