Commit e6927c46 e6927c46013d391242d76b63cdb7b044d9ba8065 by Sergey Poznyakoff

mh: Fix compatibility issues in the draftfolder facility. Implement whatnowproc.

* mh/whatnowenv.c: New source.
* mh/Makefile.am (libmh_a_SOURCES): Add whatnowenv.c
* mh/TODO: Update.
* mh/comp.c: Implement draftfolder, whatnowproc and the -use option.
* mh/forw.c: Likewise.
* mh/repl.c: Likewise.
* mh/compcommon.c (check_draft_disposition): Fix typo.
* mh/mh.h (mh_whatnow_env) <draftfolder>: Remove.
<mbox>: New member.
(mh_whatnowproc): New proto.
(mh_whatnow_env_from_environ)
(mh_whatnow_env_to_environ): New proto.
* mh/mh_global.c (prop_merger): Bugfix: initialize dst.
* mh/mh_init.c (mh_draft_message): Update cur msg.
* mh/mh_whatnow.c (mh_whatnowproc): New function.
* mh/whatnow.c (opt_handler): Do not read Draft-Folder variable.
(main): Initialize data from the environment.
1 parent 59740431
......@@ -78,7 +78,8 @@ libmh_a_SOURCES= \
mh_sequence.c\
mh_stream.c\
mh_whatnow.c\
mh_whom.c
mh_whom.c\
whatnowenv.c
noinst_HEADERS = mh.h mh_alias.h mh_format.h mh_getopt.h
LISPSRC = mailutils-mh.el
......
......@@ -19,9 +19,9 @@ State Nice Utility Comments
-------------------------------------------
+ -20 scan
+ -20 inc
* -20 repl --inplace,--whatnowproc
+ -20 comp Interactive prompting.
* -20 forw --inplace,--whatnowproc
* -20 repl --inplace
+ -20 comp
* -20 forw --inplace
* -20 send --alias,--filter,--format,--forward,--mime,
--width
* -20 refile --link copies messages; rmmproc ignored.
......
......@@ -47,9 +47,9 @@ static struct argp_option options[] = {
{"form", ARG_FORM, N_("FILE"), 0,
N_("read format from given file")},
{"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,
N_("* set the replacement for whatnow program")},
N_("set the replacement for whatnow program")},
{"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
N_("* ignore whatnowproc variable. Use standard `whatnow' shell instead.")},
N_("ignore whatnowproc variable. Use standard `whatnow' shell instead.")},
{"use", ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL,
N_("use draft file preserved after the last session") },
{"nouse", ARG_NOUSE, NULL, OPTION_HIDDEN, ""},
......@@ -68,15 +68,18 @@ struct mh_option mh_option[] = {
{ "noedit" },
{ "whatnowproc", MH_OPT_ARG, "program" },
{ "nowhatnowproc" },
{ "use" },
{ NULL }
};
struct mh_whatnow_env wh_env = { 0 };
const char *formfile;
static int initial_edit = 1;
static const char *whatnowproc;
const char *formfile;
static int build_only = 0; /* --build flag */
static int use_draft = 0; /* --use flag */
static char *draftmessage = "new";
static const char *draftfolder = NULL;
static error_t
opt_handler (int key, char *arg, struct argp_state *state)
......@@ -84,8 +87,9 @@ opt_handler (int key, char *arg, struct argp_state *state)
switch (key)
{
case ARGP_KEY_INIT:
wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
draftfolder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
break;
case ARG_BUILD:
......@@ -93,7 +97,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_DRAFTFOLDER:
wh_env.draftfolder = arg;
draftfolder = arg;
break;
case ARG_EDITOR:
......@@ -126,7 +130,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_NODRAFTFOLDER:
wh_env.draftfolder = NULL;
draftfolder = NULL;
break;
case ARG_NOEDIT:
......@@ -134,8 +138,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_WHATNOWPROC:
whatnowproc = arg;
break;
case ARG_NOWHATNOWPROC:
mh_opt_notimpl ("-[no]whatnowproc");
whatnowproc = NULL;
break;
default:
......@@ -143,7 +150,8 @@ opt_handler (int key, char *arg, struct argp_state *state)
}
return 0;
}
/* Copy Nth message from mailbox MBOX to FILE. */
int
copy_message (mu_mailbox_t mbox, size_t n, const char *file)
{
......@@ -188,16 +196,48 @@ main (int argc, char **argv)
mh_argp_init ();
mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
if (build_only || !wh_env.draftfolder)
wh_env.file = mh_expand_name (NULL, "draft", 0);
else if (wh_env.draftfolder)
if (wh_env.draftfile)
{
if (build_only)
{
mu_error (_("--build and --file cannot be used together"));
exit (1);
}
}
else
{
if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file))
return 1;
if (build_only || !draftfolder)
wh_env.file = mh_expand_name (NULL, "draft", 0);
else if (draftfolder)
{
/* Comp accepts a `file', and it will, if given
`-draftfolder +folder' treat this arguments as `msg'. */
if (index < argc)
{
mh_msgset_t msgset;
mu_mailbox_t mbox;
mbox = mh_open_folder (draftfolder, 1);
mh_msgset_parse (mbox, &msgset, argc - index, argv + index,
"new");
mu_mailbox_destroy (&mbox);
if (msgset.count != 1)
{
mu_error (_("only one message at a time!"));
return 1;
}
draftmessage = mu_umaxtostr (0, msgset.list[0]);
mh_msgset_free (&msgset);
index = argc;
}
if (mh_draft_message (draftfolder, draftmessage,
&wh_env.file))
return 1;
}
wh_env.draftfile = wh_env.file;
}
wh_env.draftfile = wh_env.file;
switch (check_draft_disposition (&wh_env, use_draft))
{
case DISP_QUIT:
......@@ -211,8 +251,8 @@ main (int argc, char **argv)
if (index < argc)
{
static mh_msgset_t msgset;
static mu_mailbox_t mbox;
mh_msgset_t msgset;
mu_mailbox_t mbox;
mbox = mh_open_folder (mh_current_folder (), 0);
mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
......@@ -222,6 +262,8 @@ main (int argc, char **argv)
return 1;
}
copy_message (mbox, msgset.list[0], wh_env.file);
mu_mailbox_destroy (&mbox);
mh_msgset_free (&msgset);
}
else
mh_comp_draft (formfile, "components", wh_env.file);
......@@ -231,5 +273,5 @@ main (int argc, char **argv)
if (build_only)
return 0;
return mh_whatnow (&wh_env, initial_edit);
return mh_whatnowproc (&wh_env, initial_edit, whatnowproc);
}
......
......@@ -90,7 +90,7 @@ check_draft_disposition (struct mh_whatnow_env *wh, int use_draft)
else
{
printf (ngettext ("Draft \"%s\" exists (%s byte).\n",
"Draft \"%s\" exists (%su bytes).\n",
"Draft \"%s\" exists (%s bytes).\n",
(unsigned long) st.st_size),
wh->draftfile, mu_umaxtostr (0, st.st_size));
disp = mh_disposition (wh->draftfile);
......
......@@ -60,9 +60,9 @@ static struct argp_option options[] = {
{"nomime", ARG_NOMIME, NULL, OPTION_HIDDEN, "" },
{"width", ARG_WIDTH, N_("NUMBER"), 0, N_("Set output width")},
{"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,
N_("* set the replacement for whatnow program")},
N_("set the replacement for whatnow program")},
{"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
N_("* ignore whatnowproc variable, use standard `whatnow' shell instead")},
N_("ignore whatnowproc variable, use standard `whatnow' shell instead")},
{"use", ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL,
N_("use draft file preserved after the last session") },
{"nouse", ARG_NOUSE, N_("BOOL"), OPTION_HIDDEN, "" },
......@@ -98,6 +98,7 @@ enum encap_type {
static char *formfile;
struct mh_whatnow_env wh_env = { 0 };
static int initial_edit = 1;
static const char *whatnowproc;
static char *mhl_filter = NULL; /* --filter flag */
static int build_only = 0; /* --build flag */
static int annotate = 0; /* --annotate flag */
......@@ -106,6 +107,7 @@ static enum encap_type encap = encap_clear; /* controlled by --format, --form
static int use_draft = 0; /* --use flag */
static int width = 80; /* --width flag */
static char *draftmessage = "new";
static const char *draftfolder = NULL;
static mh_msgset_t msgset;
static mu_mailbox_t mbox;
......@@ -116,8 +118,9 @@ opt_handler (int key, char *arg, struct argp_state *state)
switch (key)
{
case ARGP_KEY_INIT:
wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
draftfolder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
break;
case ARG_ANNOTATE:
......@@ -129,11 +132,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_DRAFTFOLDER:
wh_env.draftfolder = arg;
draftfolder = arg;
break;
case ARG_NODRAFTFOLDER:
wh_env.draftfolder = NULL;
draftfolder = NULL;
break;
case ARG_DRAFTMESSAGE:
......@@ -202,10 +205,13 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_WHATNOWPROC:
whatnowproc = arg;
break;
case ARG_NOWHATNOWPROC:
mh_opt_notimpl ("-[no]whatnowproc");
whatnowproc = NULL;
break;
default:
return ARGP_ERR_UNKNOWN;
}
......@@ -428,7 +434,7 @@ main (int argc, char **argv)
mbox = mh_open_folder (mh_current_folder (), 0);
mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
if (build_only || !wh_env.draftfolder)
if (build_only || !draftfolder)
wh_env.file = mh_expand_name (NULL, "draft", 0);
else
{
......@@ -460,7 +466,7 @@ main (int argc, char **argv)
return 0;
}
rc = mh_whatnow (&wh_env, initial_edit);
rc = mh_whatnowproc (&wh_env, initial_edit, whatnowproc);
mu_mailbox_sync (mbox);
mu_mailbox_close (mbox);
......
......@@ -218,11 +218,11 @@ struct mh_whatnow_env /* whatnow shell environment */
char *file; /* The file being processed */
char *msg; /* File name of the original message (if any) */
char *draftfile; /* File to preserve the draft into */
const char *draftfolder;
const char *editor;
char *prompt;
char *anno_field; /* Annotate field to be used */
mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */
mu_mailbox_t mbox;
};
#define DISP_QUIT 0
......@@ -330,6 +330,9 @@ 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);
......@@ -381,3 +384,5 @@ char *mh_safe_make_file_name (const char *dir, const char *file);
void mh_mailbox_get_cur (mu_mailbox_t mbox, size_t *pcur);
void mh_mailbox_set_cur (mu_mailbox_t mbox, size_t cur);
void mh_whatnow_env_from_environ (struct mh_whatnow_env *wh);
void mh_whatnow_env_to_environ (struct mh_whatnow_env *wh);
......
......@@ -45,7 +45,7 @@ mh_read_property_file (char *name, int ro)
static int
prop_merger (const char *field, const char *value, void *data)
{
mu_property_t dst;
mu_property_t dst = data;
return mu_property_set_value (dst, field, value, 1);
}
......
......@@ -982,10 +982,14 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
if (strcmp (msgspec, "new") == 0)
{
mu_property_t prop;
rc = mu_mailbox_uidnext (mbox, &uid);
if (rc)
mu_error (_("cannot obtain sequence number for the new message: %s"),
mu_strerror (rc));
mu_mailbox_get_property (mbox, &prop);
mu_property_set_value (prop, "cur", mu_umaxtostr (0, uid), 1);
}
else
{
......
......@@ -17,6 +17,14 @@
#include <mh.h>
#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
# define getmaxfd() sysconf (_SC_OPEN_MAX)
#elif defined (HAVE_GETDTABLESIZE)
# define getmaxfd() getdtablesize ()
#else
# define getmaxfd() 64
#endif
typedef int (*handler_fp) (struct mh_whatnow_env *wh,
int argc, char **argv,
int *status);
......@@ -342,10 +350,11 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
printf ("%s ", wh->prompt);
fflush (stdout);
status = mu_stream_getline (in, &line, &size, NULL);
rc = mu_stream_getline (in, &line, &size, NULL);
if (rc)
{
mu_error (_("cannot read input stream: %s"), mu_strerror (rc));
status = 1;
break;
}
......@@ -355,6 +364,7 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
{
mu_error (_("cannot split line `%s': %s"), line,
mu_wordsplit_strerror (&ws));
status = 1;
break;
}
wsflags |= MU_WRDSF_REUSE;
......@@ -554,8 +564,8 @@ static struct action_tab whatnow_tab[] = {
{ NULL }
};
int
mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
static void
set_default_editor (struct mh_whatnow_env *wh)
{
if (!wh->editor)
{
......@@ -565,6 +575,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
p : (p = (getenv ("EDITOR"))) ?
p : "prompter");
}
}
int
mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
{
set_default_editor (wh);
if (initial_edit)
mh_spawnp (wh->editor, wh->file);
......@@ -575,6 +591,62 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
return _whatnow (wh, whatnow_tab);
}
int
mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit, const char *prog)
{
int rc;
pid_t pid;
if (!prog)
return mh_whatnow (wh, initial_edit);
pid = fork ();
if (pid == -1)
{
mu_diag_funcall (MU_DIAG_ERROR, "fork", NULL, errno);
return 1;
}
if (pid == 0)
{
struct mu_wordsplit ws;
int i;
if (mu_wordsplit (prog, &ws,
MU_WRDSF_DEFFLAGS & ~MU_WRDSF_CESCAPES))
{
mu_error (_("cannot parse command line (%s): %s"), prog,
mu_wordsplit_strerror (&ws));
_exit (127);
}
set_default_editor (wh);
mh_whatnow_env_to_environ (wh);
for (i = getmaxfd (); i > 2; i--)
close (i);
execvp (ws.ws_wordv[0], ws.ws_wordv);
mu_diag_funcall (MU_DIAG_ERROR, "execvp", prog, errno);
_exit (127);
}
/* Master */
rc = 0;
while (1)
{
int status;
if (waitpid (pid, &status, 0) == (pid_t)-1)
{
if (errno == EINTR)
continue;
mu_diag_funcall (MU_DIAG_ERROR, "waitpid", prog, errno);
rc = 1;
}
break;
}
return rc;
}
/* Disposition shell */
static struct action_tab disp_tab[] = {
{ "help", disp_help },
......
......@@ -61,9 +61,9 @@ static struct argp_option options[] = {
N_("query for addresses to place in To: and Cc: lists")},
{"width", ARG_WIDTH, N_("NUMBER"), 0, N_("set output width")},
{"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,
N_("* set the replacement for whatnow program")},
N_("set the replacement for whatnow program")},
{"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
N_("* ignore whatnowproc variable; use standard `whatnow' shell instead")},
N_("ignore whatnowproc variable; use standard `whatnow' shell instead")},
{"use", ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL, N_("use draft file preserved after the last session") },
{ 0 }
};
......@@ -110,6 +110,7 @@ static int width = 80;
struct mh_whatnow_env wh_env = { 0 };
static int initial_edit = 1;
static const char *whatnowproc;
static mh_msgset_t msgset;
static mu_mailbox_t mbox;
static int build_only = 0; /* --build flag */
......@@ -118,6 +119,7 @@ static int use_draft = 0; /* --use flag */
static char *mhl_filter = NULL; /* --filter flag */
static int annotate; /* --annotate flag */
static char *draftmessage = "new";
static const char *draftfolder = NULL;
static struct obstack fcc_stack;
static int has_fcc;
......@@ -141,8 +143,9 @@ opt_handler (int key, char *arg, struct argp_state *state)
switch (key)
{
case ARGP_KEY_INIT:
wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
draftfolder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
break;
case ARG_ANNOTATE:
......@@ -162,7 +165,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_DRAFTFOLDER:
wh_env.draftfolder = arg;
draftfolder = arg;
break;
case ARG_EDITOR:
......@@ -214,7 +217,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_NODRAFTFOLDER:
wh_env.draftfolder = NULL;
draftfolder = NULL;
break;
case ARG_NOEDIT:
......@@ -255,8 +258,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_WHATNOWPROC:
whatnowproc = arg;
break;
case ARG_NOWHATNOWPROC:
mh_opt_notimpl ("-[no]whatnowproc");
whatnowproc = NULL;
break;
case ARGP_KEY_FINI:
......@@ -412,14 +418,14 @@ main (int argc, char **argv)
}
if (build_only)
wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0);
else if (wh_env.draftfolder)
wh_env.file = mh_expand_name (draftfolder, "reply", 0);
else if (draftfolder)
{
if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file))
if (mh_draft_message (draftfolder, draftmessage, &wh_env.file))
return 1;
}
else
wh_env.file = mh_expand_name (wh_env.draftfolder, "draft", 0);
wh_env.file = mh_expand_name (draftfolder, "draft", 0);
wh_env.draftfile = wh_env.file;
make_draft (mbox, DISP_REPLACE, &wh_env);
......@@ -428,7 +434,7 @@ main (int argc, char **argv)
if (build_only)
return 0;
rc = mh_whatnow (&wh_env, initial_edit);
rc = mh_whatnowproc (&wh_env, initial_edit, whatnowproc);
mu_mailbox_sync (mbox);
mu_mailbox_close (mbox);
......
......@@ -133,6 +133,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
switch (key)
{
case ARGP_KEY_INIT:
draft_folder = mh_global_profile_get ("Draft-Folder",
mu_folder_directory ());
break;
case ARG_ALIAS:
mh_alias_read (arg, 1);
break;
......@@ -785,7 +790,25 @@ main (int argc, char **argv)
{
struct stat st;
static char *xargv[2];
xargv[0] = mh_draft_name ();
if (draft_folder)
{
mh_msgset_t msgset;
mu_mailbox_t mbox;
mu_url_t url;
const char *path;
mbox = mh_open_folder (draft_folder, 1);
mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
mu_mailbox_get_url (mbox, &url);
mu_url_sget_path (url, &path);
xargv[0] = mu_make_file_name (path,
mu_umaxtostr (0, msgset.list[0]));
mu_mailbox_destroy (&mbox);
mh_msgset_free (&msgset);
}
else
xargv[0] = mh_draft_name ();
if (stat (xargv[0], &st))
{
......
......@@ -50,19 +50,15 @@ struct mh_option mh_option[] = {
struct mh_whatnow_env wh_env = { 0 };
static int initial_edit = 1;
static char *draftmessage = "cur";
static const char *draftfolder = NULL;
static error_t
opt_handler (int key, char *arg, 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;
draftfolder = arg;
break;
case ARG_EDITOR:
......@@ -70,7 +66,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
break;
case ARG_NODRAFTFOLDER:
wh_env.draftfolder = NULL;
draftfolder = NULL;
break;
case ARG_NOEDIT:
......@@ -99,22 +95,22 @@ main (int argc, char **argv)
MU_APP_INIT_NLS ();
mh_argp_init ();
mh_whatnow_env_from_environ (&wh_env);
mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
opt_handler, NULL, &index);
argc -= index;
argv += index;
if (argc)
wh_env.draftfile = argv[0];
else if (wh_env.draftfolder)
else if (draftfolder)
{
if (mh_draft_message (wh_env.draftfolder, draftmessage,
&wh_env.file))
if (mh_draft_message (draftfolder, draftmessage, &wh_env.file))
return 1;
}
else
wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0);
wh_env.draftfile = mh_expand_name (draftfolder, "draft", 0);
wh_env.draftfile = wh_env.file;
wh_env.msg = getenv ("mhaltmsg");
return mh_whatnow (&wh_env, initial_edit);
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2003, 2005, 2006, 2007, 2009, 2010 Free Software
Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
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 <mh.h>
void
mh_whatnow_env_from_environ (struct mh_whatnow_env *wh)
{
char *folder = getenv ("mhfolder");
memset (wh, 0, sizeof (*wh));
wh->file = getenv ("mhdraft");
wh->msg = getenv ("mhaltmsg");
wh->draftfile = wh->file;
wh->editor = getenv ("mheditor");
wh->prompt = getenv ("mhprompt"); /* extension */
if (folder)
{
wh->anno_field = getenv ("mhannotate");
if (wh->anno_field)
{
char *p = getenv ("mhmessages");
if (!p)
wh->anno_field = NULL;
else
{
size_t i;
struct mu_wordsplit ws;
mh_msgset_t msgset;
mu_mailbox_t mbox = mh_open_folder (folder, 0);
if (mu_wordsplit (p, &ws,
MU_WRDSF_DEFFLAGS & ~MU_WRDSF_CESCAPES))
{
mu_error (_("cannot parse mhmessages (%s): %s"), p,
mu_wordsplit_strerror (&ws));
exit (1);
}
mh_msgset_parse (mbox, &msgset, ws.ws_wordc, ws.ws_wordv, "cur");
mu_wordsplit_free (&ws);
wh->mbox = mbox;
mu_list_create (&wh->anno_list);
for (i = 0; i < msgset.count; i++)
{
mu_message_t msg;
int rc = mu_mailbox_get_message (mbox, msgset.list[i], &msg);
if (rc)
{
mu_error (_("cannot get message %lu from %s: %s"),
(unsigned long) msgset.list[i],
folder,
mu_strerror (rc));
continue;
}
mu_list_append (wh->anno_list, msg);
}
mh_msgset_free (&msgset);
/* FIXME:
wh->anno_inplace = getenv ("mhinplace");
*/
}
}
}
}
void
mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
{
if (wh->file)
setenv ("mhdraft", wh->file, 1);
if (wh->msg)
setenv ("mhaltmsg", wh->msg, 1);
if (wh->editor)
setenv ("mheditor", wh->editor, 1);
if (wh->prompt)
setenv ("mhprompt", wh->prompt, 1);
if (wh->anno_field)
setenv ("mhannotate", wh->anno_field, 1);
if (wh->anno_list)
{
mu_opool_t opool;
mu_iterator_t itr;
size_t prev_uid = 0;
int mrange = 0;
const char *s;
mu_opool_create (&opool, 1);
mu_list_get_iterator (wh->anno_list, &itr);
for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
mu_iterator_next (itr))
{
mu_message_t msg;
size_t uid;
mu_iterator_current (itr, (void**)&msg);
mu_message_get_uid (msg, &uid);
if (prev_uid == 0)
{
s = mu_umaxtostr (0, uid);
mu_opool_append (opool, s, strlen (s));
mrange = 0;
}
else if (uid == prev_uid + 1)
mrange = 1;
else
{
if (mrange)
{
mu_opool_append_char (opool, '-');
s = mu_umaxtostr (0, prev_uid);
mu_opool_append (opool, s, strlen (s));
}
mu_opool_append_char (opool, ' ');
s = mu_umaxtostr (0, uid);
mu_opool_append (opool, s, strlen (s));
mrange = 0;
}
}
if (mrange)
{
mu_opool_append_char (opool, '-');
s = mu_umaxtostr (0, prev_uid);
mu_opool_append (opool, s, strlen (s));
}
mu_opool_append_char (opool, 0);
s = mu_opool_finish (opool, NULL);
setenv ("mhmessages", s, 1);
mu_opool_destroy (&opool);
}
}