Commit 744c4a9c 744c4a9c94064a0dae7d2ed8237ac8129e65510c by Sergey Poznyakoff

Fix MH initialization order

Calls to mh_global_profile_get and similar functions must appear
only after a call to mh_getopt (more properly, after mh_init and
mh_init2 are callead).  This sequence was inadvertently changed
by commit e267ac86, due to which comp, forw, repl and burst stopped
reading important information from .mh_profile.  Bug spotted by
Pierre-Jean.

* mh/burst.c: Make sure profile variables are accessed after
the profile is read.
* mh/comp.c: Likewise.
* mh/forw.c: Likewise.
* mh/repl.c: Likewise.
* mh/mh.h (mh_whatnow_env_from_environ): Split into two functions:
mh_whatnow_env_from_environ_early, to be called before mh_getopt,
and mh_whatnow_env_from_environ_late, to be called after it.
* mh/whatnowenv.c: Ditto.
* mh/whatnow.c: Call these two in the right order.

* THANKS: Update.
1 parent a79ec559
......@@ -24,6 +24,7 @@ Matthew Whitworth <matthew@okcomputer.org>
maks <maksqwe1@ukr.net>
Neil R. Ormos <ormos@ormos.org>
Olivier Bornet <Olivier.Bornet@smartdata.ch>
Pierre-Jean <lists@utroff.org>
Robby Villegas <robby.villegas@gmail.com>
Ronan KERYELL <Ronan.Keryell@enstb.org>
Sam Roberts <sroberts@uniserve.com>
......
......@@ -650,10 +650,12 @@ main (int argc, char **argv)
int rc;
mu_mailbox_t mbox;
mu_msgset_t msgset;
const char *tempfolder = mh_global_profile_get ("Temp-Folder", ".temp");
const char *tempfolder = NULL;
mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL);
if (!tempfolder)
tempfolder = mh_global_profile_get ("Temp-Folder", ".temp");
if (eb_min_length == 0)
eb_min_length = 1;
......
......@@ -130,10 +130,13 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file)
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 (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
if (use_draft)
draftmessage = "cur";
if (!formfile)
......
......@@ -382,10 +382,12 @@ main (int argc, char **argv)
{
int rc;
draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
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);
if (!formfile)
mh_find_file ("forwcomps", &formfile);
......
......@@ -387,5 +387,6 @@ 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_from_environ_early (struct mh_whatnow_env *wh);
void mh_whatnow_env_from_environ_late (struct mh_whatnow_env *wh);
void mh_whatnow_env_to_environ (struct mh_whatnow_env *wh);
......
......@@ -294,11 +294,14 @@ 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 (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL);
if (!format_str)
format_str = default_format_str;
......
......@@ -52,9 +52,9 @@ static struct mu_option options[] = {
int
main (int argc, char **argv)
{
mh_whatnow_env_from_environ (&wh_env);
mh_whatnow_env_from_environ_early (&wh_env);
mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
mh_whatnow_env_from_environ_late (&wh_env);
if (argc)
wh_env.draftfile = argv[0];
......
......@@ -25,10 +25,8 @@ _add_to_list (size_t num, mu_message_t msg, void *data)
}
void
mh_whatnow_env_from_environ (struct mh_whatnow_env *wh)
mh_whatnow_env_from_environ_early (struct mh_whatnow_env *wh)
{
char *folder = getenv ("mhfolder");
memset (wh, 0, sizeof (*wh));
wh->file = getenv ("mhdraft");
......@@ -36,6 +34,14 @@ mh_whatnow_env_from_environ (struct mh_whatnow_env *wh)
wh->draftfile = wh->file;
wh->editor = getenv ("mheditor");
wh->prompt = getenv ("mhprompt"); /* extension */
}
void
mh_whatnow_env_from_environ_late (struct mh_whatnow_env *wh)
{
char *folder = getenv ("mhfolder");
if (folder)
{
wh->anno_field = getenv ("mhannotate");
......