Bugfixes in MH show
* mh/show.c: Set cur before returning. Allow for arguments in showproc settings. Move to next or prev if invoked with the corresponding argv[0] * mh/mh.h (mh_msgset_parse): def argument is const. (mh_msgset_first_current, mh_msgset_first_uid): Remove proto. (mh_msgset_first): Change signature. (mh_msgset_last): New function. * mh/mh_msgset.c (mh_msgset_first): Return UID or message number depending on the value of the second parameter. (mh_msgset_first_current, mh_msgset_first_uid): Remove. (mh_msgset_last): New function. * mh/anno.c: Update. * mh/comp.c: Update. * mh/folder.c: Update. * mh/mh_init.c: Update. * mh/repl.c: Update. * mh/Makefile.am (install-exec-hook): Link show to prev and next
Showing
9 changed files
with
87 additions
and
53 deletions
... | @@ -170,6 +170,8 @@ mh_alias_lex.c: $(srcdir)/mh_alias.l mh_alias.h | ... | @@ -170,6 +170,8 @@ mh_alias_lex.c: $(srcdir)/mh_alias.l mh_alias.h |
170 | install-exec-hook: | 170 | install-exec-hook: |
171 | @here=`pwd`; \ | 171 | @here=`pwd`; \ |
172 | cd $(DESTDIR)$(bindir); \ | 172 | cd $(DESTDIR)$(bindir); \ |
173 | rm -f folders; \ | 173 | rm -f folders next prev; \ |
174 | $(LN_S) folder folders; \ | 174 | $(LN_S) folder folders; \ |
175 | $(LN_S) show next; \ | ||
176 | $(LN_S) show prev; \ | ||
175 | cd $$here | 177 | cd $$here | ... | ... |
... | @@ -110,7 +110,7 @@ main (int argc, char **argv) | ... | @@ -110,7 +110,7 @@ main (int argc, char **argv) |
110 | exit (1); | 110 | exit (1); |
111 | } | 111 | } |
112 | 112 | ||
113 | mh_msgset_first_current (mbox, msgset); | 113 | mh_mailbox_set_cur (mbox, mh_msgset_first (msgset, RET_UID)); |
114 | mu_msgset_free (msgset); | 114 | mu_msgset_free (msgset); |
115 | mh_global_save_state (); | 115 | mh_global_save_state (); |
116 | mu_mailbox_sync (mbox); | 116 | mu_mailbox_sync (mbox); | ... | ... |
... | @@ -189,7 +189,8 @@ main (int argc, char **argv) | ... | @@ -189,7 +189,8 @@ main (int argc, char **argv) |
189 | mu_error (_("only one message at a time!")); | 189 | mu_error (_("only one message at a time!")); |
190 | return 1; | 190 | return 1; |
191 | } | 191 | } |
192 | draftmessage = (char*) mu_umaxtostr (0, mh_msgset_first_uid (msgset)); | 192 | draftmessage = |
193 | (char*) mu_umaxtostr (0, mh_msgset_first (msgset, RET_UID)); | ||
193 | mu_msgset_free (msgset); | 194 | mu_msgset_free (msgset); |
194 | mu_mailbox_destroy (&mbox); | 195 | mu_mailbox_destroy (&mbox); |
195 | } | 196 | } |
... | @@ -213,7 +214,7 @@ main (int argc, char **argv) | ... | @@ -213,7 +214,7 @@ main (int argc, char **argv) |
213 | return 1; | 214 | return 1; |
214 | } | 215 | } |
215 | unlink (wh_env.file); | 216 | unlink (wh_env.file); |
216 | copy_message (mbox, mh_msgset_first (msgset), wh_env.file); | 217 | copy_message (mbox, mh_msgset_first (msgset, RET_MSGNO), wh_env.file); |
217 | mu_mailbox_destroy (&mbox); | 218 | mu_mailbox_destroy (&mbox); |
218 | mu_msgset_free (msgset); | 219 | mu_msgset_free (msgset); |
219 | } | 220 | } | ... | ... |
... | @@ -914,7 +914,7 @@ main (int argc, char **argv) | ... | @@ -914,7 +914,7 @@ main (int argc, char **argv) |
914 | mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), | 914 | mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), |
915 | MU_STREAM_RDWR); | 915 | MU_STREAM_RDWR); |
916 | mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur"); | 916 | mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur"); |
917 | mh_msgset_first_current (mbox, msgset); | 917 | mh_mailbox_set_cur (mbox, mh_msgset_first (msgset, RET_UID)); |
918 | mu_msgset_free (msgset); | 918 | mu_msgset_free (msgset); |
919 | mh_global_save_state (); | 919 | mh_global_save_state (); |
920 | mu_mailbox_close (mbox); | 920 | mu_mailbox_close (mbox); | ... | ... |
... | @@ -300,12 +300,13 @@ int mh_message_number (mu_message_t msg, size_t *pnum); | ... | @@ -300,12 +300,13 @@ int mh_message_number (mu_message_t msg, size_t *pnum); |
300 | mu_mailbox_t mh_open_folder (const char *folder, int flags); | 300 | mu_mailbox_t mh_open_folder (const char *folder, int flags); |
301 | 301 | ||
302 | void mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, | 302 | void mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, |
303 | int argc, char **argv, char *def); | 303 | int argc, char **argv, const char *def); |
304 | void mh_msgset_parse_string (mu_msgset_t *msgset, mu_mailbox_t mbox, | 304 | void mh_msgset_parse_string (mu_msgset_t *msgset, mu_mailbox_t mbox, |
305 | const char *string, char *def); | 305 | const char *string, const char *def); |
306 | void mh_msgset_first_current (mu_mailbox_t mbox, mu_msgset_t msgset); | 306 | #define RET_MSGNO 0 |
307 | size_t mh_msgset_first (mu_msgset_t msgset); | 307 | #define RET_UID 1 |
308 | size_t mh_msgset_first_uid (mu_msgset_t msgset); | 308 | size_t mh_msgset_first (mu_msgset_t msgset, int uid); |
309 | size_t mh_msgset_last (mu_msgset_t msgset, int uid); | ||
309 | int mh_msgset_single_message (mu_msgset_t msgset); | 310 | int mh_msgset_single_message (mu_msgset_t msgset); |
310 | 311 | ||
311 | #define NAME_ANY 0 | 312 | #define NAME_ANY 0 | ... | ... |
... | @@ -1026,7 +1026,7 @@ mh_draft_message (const char *name, const char *msgspec, char **pname) | ... | @@ -1026,7 +1026,7 @@ mh_draft_message (const char *name, const char *msgspec, char **pname) |
1026 | if (!mh_msgset_single_message (msgset)) | 1026 | if (!mh_msgset_single_message (msgset)) |
1027 | mu_error (_("only one message at a time!")); | 1027 | mu_error (_("only one message at a time!")); |
1028 | else | 1028 | else |
1029 | uid = mh_msgset_first_uid (msgset); | 1029 | uid = mh_msgset_first (msgset, RET_UID); |
1030 | mu_msgset_free (msgset); | 1030 | mu_msgset_free (msgset); |
1031 | } | 1031 | } |
1032 | 1032 | ... | ... |
... | @@ -21,51 +21,47 @@ | ... | @@ -21,51 +21,47 @@ |
21 | #include <mailutils/sys/msgset.h> | 21 | #include <mailutils/sys/msgset.h> |
22 | 22 | ||
23 | size_t | 23 | size_t |
24 | mh_msgset_first (mu_msgset_t msgset) | 24 | mh_msgset_first (mu_msgset_t msgset, int uid) |
25 | { | 25 | { |
26 | mu_list_t list; | 26 | size_t n; |
27 | struct mu_msgrange *r; | 27 | int rc = mu_msgset_first (msgset, &n); |
28 | int rc; | ||
29 | |||
30 | rc = mu_msgset_get_list (msgset, &list); | ||
31 | if (rc) | 28 | if (rc) |
32 | { | 29 | { |
33 | mu_diag_funcall (MU_DIAG_ERROR, "mu_msgset_get_list", NULL, rc); | 30 | mu_diag_funcall (MU_DIAG_ERROR, "mu_msgset_first", NULL, rc); |
34 | exit (1); | 31 | exit (1); |
35 | } | 32 | } |
36 | rc = mu_list_head (list, (void**)&r); | 33 | if (uid) |
37 | if (rc) | ||
38 | { | 34 | { |
39 | mu_diag_funcall (MU_DIAG_ERROR, "mu_list_get", NULL, rc); | 35 | rc = mu_mailbox_translate (msgset->mbox, MU_MAILBOX_MSGNO_TO_UID, n, &n); |
40 | exit (1); | 36 | if (rc) |
37 | { | ||
38 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_translate", NULL, rc); | ||
39 | exit (1); | ||
40 | } | ||
41 | } | 41 | } |
42 | return r->msg_beg; | 42 | return n; |
43 | } | 43 | } |
44 | 44 | ||
45 | size_t | 45 | size_t |
46 | mh_msgset_first_uid (mu_msgset_t msgset) | 46 | mh_msgset_last (mu_msgset_t msgset, int uid) |
47 | { | 47 | { |
48 | int rc; | 48 | size_t n; |
49 | size_t cur; | 49 | int rc = mu_msgset_last (msgset, &n); |
50 | |||
51 | cur = mh_msgset_first (msgset); | ||
52 | rc = mu_mailbox_translate (msgset->mbox, MU_MAILBOX_MSGNO_TO_UID, cur, &cur); | ||
53 | if (rc) | 50 | if (rc) |
54 | { | 51 | { |
55 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_translate", NULL, rc); | 52 | mu_diag_funcall (MU_DIAG_ERROR, "mu_msgset_last", NULL, rc); |
56 | exit (1); | 53 | exit (1); |
57 | } | 54 | } |
58 | return cur; | 55 | if (uid) |
59 | } | 56 | { |
60 | 57 | rc = mu_mailbox_translate (msgset->mbox, MU_MAILBOX_MSGNO_TO_UID, n, &n); | |
61 | /* Set the current message to that contained at position 0 | 58 | if (rc) |
62 | in the given message set. | 59 | { |
63 | FIXME: mbox is superfluous | 60 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_translate", NULL, rc); |
64 | */ | 61 | exit (1); |
65 | void | 62 | } |
66 | mh_msgset_first_current (mu_mailbox_t mbox, mu_msgset_t msgset) | 63 | } |
67 | { | 64 | return n; |
68 | mh_mailbox_set_cur (mbox, mh_msgset_first_uid (msgset)); | ||
69 | } | 65 | } |
70 | 66 | ||
71 | int | 67 | int |
... | @@ -617,7 +613,7 @@ msgset_parser_run (struct msgset_parser *parser) | ... | @@ -617,7 +613,7 @@ msgset_parser_run (struct msgset_parser *parser) |
617 | /* Parse a message specification from (argc;argv). */ | 613 | /* Parse a message specification from (argc;argv). */ |
618 | void | 614 | void |
619 | mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, | 615 | mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, |
620 | int argc, char **argv, char *def) | 616 | int argc, char **argv, const char *def) |
621 | { | 617 | { |
622 | struct msgset_parser parser; | 618 | struct msgset_parser parser; |
623 | char *xargv[2]; | 619 | char *xargv[2]; |
... | @@ -626,7 +622,7 @@ mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, | ... | @@ -626,7 +622,7 @@ mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, |
626 | { | 622 | { |
627 | argc = 1; | 623 | argc = 1; |
628 | argv = xargv; | 624 | argv = xargv; |
629 | argv[0] = def ? def : "cur"; | 625 | argv[0] = (char*) (def ? def : "cur"); |
630 | argv[1] = NULL; | 626 | argv[1] = NULL; |
631 | } | 627 | } |
632 | 628 | ||
... | @@ -646,7 +642,7 @@ mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, | ... | @@ -646,7 +642,7 @@ mh_msgset_parse (mu_msgset_t *msgset, mu_mailbox_t mbox, |
646 | 642 | ||
647 | void | 643 | void |
648 | mh_msgset_parse_string (mu_msgset_t *msgset, mu_mailbox_t mbox, | 644 | mh_msgset_parse_string (mu_msgset_t *msgset, mu_mailbox_t mbox, |
649 | const char *string, char *def) | 645 | const char *string, const char *def) |
650 | { | 646 | { |
651 | struct mu_wordsplit ws; | 647 | struct mu_wordsplit ws; |
652 | 648 | ... | ... |
... | @@ -208,7 +208,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) | ... | @@ -208,7 +208,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh) |
208 | break; | 208 | break; |
209 | } | 209 | } |
210 | 210 | ||
211 | msgno = mh_msgset_first (msgset); | 211 | msgno = mh_msgset_first (msgset, RET_MSGNO); |
212 | rc = mu_mailbox_get_message (mbox, msgno, &msg); | 212 | rc = mu_mailbox_get_message (mbox, msgno, &msg); |
213 | if (rc) | 213 | if (rc) |
214 | { | 214 | { | ... | ... |
... | @@ -54,6 +54,36 @@ insarg (char *arg) | ... | @@ -54,6 +54,36 @@ insarg (char *arg) |
54 | showargv[1] = p; | 54 | showargv[1] = p; |
55 | } | 55 | } |
56 | } | 56 | } |
57 | |||
58 | static void | ||
59 | finisarg (void) | ||
60 | { | ||
61 | struct mu_wordsplit ws; | ||
62 | char *p; | ||
63 | |||
64 | mu_wordsplit (showproc, &ws, MU_WRDSF_DEFFLAGS); | ||
65 | if (ws.ws_wordc > 1) | ||
66 | { | ||
67 | size_t i; | ||
68 | |||
69 | if (showargc + ws.ws_wordc > showargmax) | ||
70 | { | ||
71 | showargmax = showargc + ws.ws_wordc; | ||
72 | showargv = mu_realloc (showargv, showargmax * sizeof showargv[0]); | ||
73 | } | ||
74 | |||
75 | memmove (showargv + ws.ws_wordc, showargv + 1, | ||
76 | sizeof (showargv[0]) * (showargc - 1)); | ||
77 | for (i = 1; i < ws.ws_wordc; i++) | ||
78 | showargv[i] = ws.ws_wordv[i]; | ||
79 | showargc += ws.ws_wordc - 1; | ||
80 | showproc = ws.ws_wordv[0]; | ||
81 | } | ||
82 | |||
83 | p = strrchr (showproc, '/'); | ||
84 | showargv[0] = (char*) (p ? p + 1 : showproc); | ||
85 | addarg (NULL); | ||
86 | } | ||
57 | 87 | ||
58 | static void | 88 | static void |
59 | set_draft (struct mu_parseopt *po, struct mu_option *opt, char const *arg) | 89 | set_draft (struct mu_parseopt *po, struct mu_option *opt, char const *arg) |
... | @@ -181,8 +211,9 @@ int | ... | @@ -181,8 +211,9 @@ int |
181 | main (int argc, char **argv) | 211 | main (int argc, char **argv) |
182 | { | 212 | { |
183 | mu_mailbox_t mbox; | 213 | mu_mailbox_t mbox; |
184 | mu_msgset_t msgset; | 214 | mu_msgset_t msgset = NULL; |
185 | const char *p; | 215 | const char *p; |
216 | const char *mode = "cur"; | ||
186 | 217 | ||
187 | showargmax = 2; | 218 | showargmax = 2; |
188 | showargc = 1; | 219 | showargc = 1; |
... | @@ -191,6 +222,9 @@ main (int argc, char **argv) | ... | @@ -191,6 +222,9 @@ main (int argc, char **argv) |
191 | mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, | 222 | mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER, |
192 | args_doc, prog_doc, NULL); | 223 | args_doc, prog_doc, NULL); |
193 | 224 | ||
225 | if (strcmp (mu_program_name, "next") == 0 | ||
226 | || strcmp (mu_program_name, "prev") == 0) | ||
227 | mode = mu_program_name; | ||
194 | 228 | ||
195 | mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR); | 229 | mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR); |
196 | 230 | ||
... | @@ -203,7 +237,7 @@ main (int argc, char **argv) | ... | @@ -203,7 +237,7 @@ main (int argc, char **argv) |
203 | } | 237 | } |
204 | } | 238 | } |
205 | else | 239 | else |
206 | mh_msgset_parse (&msgset, mbox, argc, argv, "cur"); | 240 | mh_msgset_parse (&msgset, mbox, argc, argv, mode); |
207 | 241 | ||
208 | /* 1. If !use_showproc set showproc to /bin/cat and go to X. | 242 | /* 1. If !use_showproc set showproc to /bin/cat and go to X. |
209 | 2. If -file or -draft is given | 243 | 2. If -file or -draft is given |
... | @@ -241,7 +275,7 @@ main (int argc, char **argv) | ... | @@ -241,7 +275,7 @@ main (int argc, char **argv) |
241 | mu_mailbox_close (mbox); | 275 | mu_mailbox_close (mbox); |
242 | mu_mailbox_destroy (&mbox); | 276 | mu_mailbox_destroy (&mbox); |
243 | mbox = mh_open_folder (dfolder, MU_STREAM_RDWR); | 277 | mbox = mh_open_folder (dfolder, MU_STREAM_RDWR); |
244 | mh_msgset_parse (&msgset, mbox, 0, NULL, "cur"); | 278 | mh_msgset_parse (&msgset, mbox, 0, NULL, mode); |
245 | 279 | ||
246 | mu_msgset_foreach_message (msgset, resolve_mime, &ismime); | 280 | mu_msgset_foreach_message (msgset, resolve_mime, &ismime); |
247 | if (ismime) | 281 | if (ismime) |
... | @@ -294,9 +328,12 @@ main (int argc, char **argv) | ... | @@ -294,9 +328,12 @@ main (int argc, char **argv) |
294 | mu_msgset_foreach_msguid (msgset, printheader, (void*) path); | 328 | mu_msgset_foreach_msguid (msgset, printheader, (void*) path); |
295 | } | 329 | } |
296 | 330 | ||
297 | mu_stream_flush (mu_strout); | 331 | if (!mu_msgset_is_empty (msgset)) |
332 | mh_mailbox_set_cur (mbox, mh_msgset_last (msgset, RET_UID)); | ||
298 | mu_mailbox_close (mbox); | 333 | mu_mailbox_close (mbox); |
299 | mu_mailbox_destroy (&mbox); | 334 | mu_mailbox_destroy (&mbox); |
335 | |||
336 | mu_stream_flush (mu_strout); | ||
300 | 337 | ||
301 | if (!showproc) | 338 | if (!showproc) |
302 | { | 339 | { |
... | @@ -304,10 +341,7 @@ main (int argc, char **argv) | ... | @@ -304,10 +341,7 @@ main (int argc, char **argv) |
304 | if (!showproc) | 341 | if (!showproc) |
305 | showproc = "/usr/bin/more"; | 342 | showproc = "/usr/bin/more"; |
306 | } | 343 | } |
307 | 344 | finisarg (); | |
308 | addarg (NULL); | ||
309 | p = strrchr (showproc, '/'); | ||
310 | showargv[0] = (char*) (p ? p + 1 : showproc); | ||
311 | execvp (showproc, showargv); | 345 | execvp (showproc, showargv); |
312 | mu_error (_("unable to exec %s: %s"), showargv[0], mu_strerror (errno)); | 346 | mu_error (_("unable to exec %s: %s"), showargv[0], mu_strerror (errno)); |
313 | return 1; | 347 | return 1; | ... | ... |
-
Please register or sign in to post a comment