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> ...@@ -24,6 +24,7 @@ Matthew Whitworth <matthew@okcomputer.org>
24 maks <maksqwe1@ukr.net> 24 maks <maksqwe1@ukr.net>
25 Neil R. Ormos <ormos@ormos.org> 25 Neil R. Ormos <ormos@ormos.org>
26 Olivier Bornet <Olivier.Bornet@smartdata.ch> 26 Olivier Bornet <Olivier.Bornet@smartdata.ch>
27 Pierre-Jean <lists@utroff.org>
27 Robby Villegas <robby.villegas@gmail.com> 28 Robby Villegas <robby.villegas@gmail.com>
28 Ronan KERYELL <Ronan.Keryell@enstb.org> 29 Ronan KERYELL <Ronan.Keryell@enstb.org>
29 Sam Roberts <sroberts@uniserve.com> 30 Sam Roberts <sroberts@uniserve.com>
......
...@@ -650,10 +650,12 @@ main (int argc, char **argv) ...@@ -650,10 +650,12 @@ main (int argc, char **argv)
650 int rc; 650 int rc;
651 mu_mailbox_t mbox; 651 mu_mailbox_t mbox;
652 mu_msgset_t msgset; 652 mu_msgset_t msgset;
653 const char *tempfolder = mh_global_profile_get ("Temp-Folder", ".temp"); 653 const char *tempfolder = NULL;
654 654
655 mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, 655 mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
656 args_doc, prog_doc, NULL); 656 args_doc, prog_doc, NULL);
657 if (!tempfolder)
658 tempfolder = mh_global_profile_get ("Temp-Folder", ".temp");
657 if (eb_min_length == 0) 659 if (eb_min_length == 0)
658 eb_min_length = 1; 660 eb_min_length = 1;
659 661
......
...@@ -130,10 +130,13 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file) ...@@ -130,10 +130,13 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file)
130 int 130 int
131 main (int argc, char **argv) 131 main (int argc, char **argv)
132 { 132 {
133 mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
134
135 if (!draftfolder)
133 draftfolder = mh_global_profile_get ("Draft-Folder", NULL); 136 draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
137 if (!whatnowproc)
134 whatnowproc = mh_global_profile_get ("whatnowproc", NULL); 138 whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
135 139
136 mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
137 if (use_draft) 140 if (use_draft)
138 draftmessage = "cur"; 141 draftmessage = "cur";
139 if (!formfile) 142 if (!formfile)
......
...@@ -382,10 +382,12 @@ main (int argc, char **argv) ...@@ -382,10 +382,12 @@ main (int argc, char **argv)
382 { 382 {
383 int rc; 383 int rc;
384 384
385 draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
386 whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
387 mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, 385 mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
388 args_doc, prog_doc, NULL); 386 args_doc, prog_doc, NULL);
387 if (!draftfolder)
388 draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
389 if (!whatnowproc)
390 whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
389 if (!formfile) 391 if (!formfile)
390 mh_find_file ("forwcomps", &formfile); 392 mh_find_file ("forwcomps", &formfile);
391 393
......
...@@ -387,5 +387,6 @@ char *mh_safe_make_file_name (const char *dir, const char *file); ...@@ -387,5 +387,6 @@ char *mh_safe_make_file_name (const char *dir, const char *file);
387 void mh_mailbox_get_cur (mu_mailbox_t mbox, size_t *pcur); 387 void mh_mailbox_get_cur (mu_mailbox_t mbox, size_t *pcur);
388 void mh_mailbox_set_cur (mu_mailbox_t mbox, size_t cur); 388 void mh_mailbox_set_cur (mu_mailbox_t mbox, size_t cur);
389 389
390 void mh_whatnow_env_from_environ (struct mh_whatnow_env *wh); 390 void mh_whatnow_env_from_environ_early (struct mh_whatnow_env *wh);
391 void mh_whatnow_env_from_environ_late (struct mh_whatnow_env *wh);
391 void mh_whatnow_env_to_environ (struct mh_whatnow_env *wh); 392 void mh_whatnow_env_to_environ (struct mh_whatnow_env *wh);
......
...@@ -294,11 +294,14 @@ main (int argc, char **argv) ...@@ -294,11 +294,14 @@ main (int argc, char **argv)
294 { 294 {
295 int rc; 295 int rc;
296 296
297 mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
298 args_doc, prog_doc, NULL);
299
300 if (!draftfolder)
297 draftfolder = mh_global_profile_get ("Draft-Folder", NULL); 301 draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
302 if (!whatnowproc)
298 whatnowproc = mh_global_profile_get ("whatnowproc", NULL); 303 whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
299 304
300 mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
301 args_doc, prog_doc, NULL);
302 305
303 if (!format_str) 306 if (!format_str)
304 format_str = default_format_str; 307 format_str = default_format_str;
......
...@@ -52,9 +52,9 @@ static struct mu_option options[] = { ...@@ -52,9 +52,9 @@ static struct mu_option options[] = {
52 int 52 int
53 main (int argc, char **argv) 53 main (int argc, char **argv)
54 { 54 {
55 mh_whatnow_env_from_environ (&wh_env); 55 mh_whatnow_env_from_environ_early (&wh_env);
56
57 mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL); 56 mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
57 mh_whatnow_env_from_environ_late (&wh_env);
58 58
59 if (argc) 59 if (argc)
60 wh_env.draftfile = argv[0]; 60 wh_env.draftfile = argv[0];
......
...@@ -25,10 +25,8 @@ _add_to_list (size_t num, mu_message_t msg, void *data) ...@@ -25,10 +25,8 @@ _add_to_list (size_t num, mu_message_t msg, void *data)
25 } 25 }
26 26
27 void 27 void
28 mh_whatnow_env_from_environ (struct mh_whatnow_env *wh) 28 mh_whatnow_env_from_environ_early (struct mh_whatnow_env *wh)
29 { 29 {
30 char *folder = getenv ("mhfolder");
31
32 memset (wh, 0, sizeof (*wh)); 30 memset (wh, 0, sizeof (*wh));
33 31
34 wh->file = getenv ("mhdraft"); 32 wh->file = getenv ("mhdraft");
...@@ -36,6 +34,14 @@ mh_whatnow_env_from_environ (struct mh_whatnow_env *wh) ...@@ -36,6 +34,14 @@ mh_whatnow_env_from_environ (struct mh_whatnow_env *wh)
36 wh->draftfile = wh->file; 34 wh->draftfile = wh->file;
37 wh->editor = getenv ("mheditor"); 35 wh->editor = getenv ("mheditor");
38 wh->prompt = getenv ("mhprompt"); /* extension */ 36 wh->prompt = getenv ("mhprompt"); /* extension */
37 }
38
39
40 void
41 mh_whatnow_env_from_environ_late (struct mh_whatnow_env *wh)
42 {
43 char *folder = getenv ("mhfolder");
44
39 if (folder) 45 if (folder)
40 { 46 {
41 wh->anno_field = getenv ("mhannotate"); 47 wh->anno_field = getenv ("mhannotate");
......