mhn: minor changes.
* mh/etc/mhl.headers: New file. * mh/etc/Makefile.am (MH_FILES): Add mhl.headers. * mh/mhn.c (opt_handler): Use mh_find_file to resolve format file name. (mhn_show): Always open the formfile. (copy_header_to_stream): Rewrite using mu_stream_copy + HEADER filter.
Showing
3 changed files
with
45 additions
and
28 deletions
mh/etc/mhl.headers
0 → 100644
1 | ; mhl.headers | ||
2 | ; | ||
3 | ; GNU Mailutils -- a suite of utilities for electronic mail | ||
4 | ; Copyright (C) 2010 Free Software Foundation, Inc. | ||
5 | ; Distributed under GPLv3+. See <http://gnu.org/licenses/gpl.html>. | ||
6 | ; | ||
7 | ; Mhn uses this format file for displaying headers in MIME messages. | ||
8 | ; | ||
9 | overflowtext="***",overflowoffset=5 | ||
10 | leftadjust,compwidth=9 | ||
11 | ignores=msgid,message-id,received,content-type,content-transfer-encoding,content-id | ||
12 | Date:formatfield="%<(nodate{text})%{text}%|%(pretty{text})%>" | ||
13 | To: | ||
14 | cc: | ||
15 | From:decode | ||
16 | Subject:decode | ||
17 | : | ||
18 | extras:nocomponent | ||
19 | : | ||
20 | ; End of mhl.headers |
... | @@ -96,6 +96,7 @@ static struct argp_option options[] = { | ... | @@ -96,6 +96,7 @@ static struct argp_option options[] = { |
96 | /* Traditional MH options */ | 96 | /* Traditional MH options */ |
97 | struct mh_option mh_option[] = { | 97 | struct mh_option mh_option[] = { |
98 | { "file", MH_OPT_ARG, "filename" }, | 98 | { "file", MH_OPT_ARG, "filename" }, |
99 | { "compose" }, | ||
99 | { "list", MH_OPT_BOOL }, | 100 | { "list", MH_OPT_BOOL }, |
100 | { "headers", MH_OPT_BOOL }, | 101 | { "headers", MH_OPT_BOOL }, |
101 | { "realsize", MH_OPT_BOOL }, | 102 | { "realsize", MH_OPT_BOOL }, |
... | @@ -357,7 +358,7 @@ opt_handler (int key, char *arg, struct argp_state *state) | ... | @@ -357,7 +358,7 @@ opt_handler (int key, char *arg, struct argp_state *state) |
357 | break; | 358 | break; |
358 | 359 | ||
359 | case ARG_FORM: | 360 | case ARG_FORM: |
360 | formfile = arg; | 361 | mh_find_file (arg, &formfile); |
361 | break; | 362 | break; |
362 | 363 | ||
363 | /* Common options */ | 364 | /* Common options */ |
... | @@ -390,6 +391,11 @@ opt_handler (int key, char *arg, struct argp_state *state) | ... | @@ -390,6 +391,11 @@ opt_handler (int key, char *arg, struct argp_state *state) |
390 | charset = arg; | 391 | charset = arg; |
391 | break; | 392 | break; |
392 | 393 | ||
394 | case ARGP_KEY_FINI: | ||
395 | if (!formfile) | ||
396 | mh_find_file ("mhl.headers", &formfile); | ||
397 | break; | ||
398 | |||
393 | default: | 399 | default: |
394 | return ARGP_ERR_UNKNOWN; | 400 | return ARGP_ERR_UNKNOWN; |
395 | } | 401 | } |
... | @@ -1444,22 +1450,7 @@ mhn_show () | ... | @@ -1444,22 +1450,7 @@ mhn_show () |
1444 | exit (1); | 1450 | exit (1); |
1445 | } | 1451 | } |
1446 | 1452 | ||
1447 | if (formfile) | 1453 | mhl_format = mhl_format_compile (formfile); |
1448 | { | ||
1449 | char *s = mh_expand_name (MHLIBDIR, "mhl.headers", 0); | ||
1450 | if (access (s, R_OK) == 0) | ||
1451 | formfile = "mhl.headers"; | ||
1452 | free (s); | ||
1453 | } | ||
1454 | |||
1455 | if (formfile) | ||
1456 | { | ||
1457 | char *s = mh_expand_name (MHLIBDIR, formfile, 0); | ||
1458 | mhl_format = mhl_format_compile (s); | ||
1459 | if (!mhl_format) | ||
1460 | exit (1); | ||
1461 | free (s); | ||
1462 | } | ||
1463 | 1454 | ||
1464 | if (message) | 1455 | if (message) |
1465 | rc = show_message (message, 0, ostr); | 1456 | rc = show_message (message, 0, ostr); |
... | @@ -1895,22 +1886,27 @@ copy_header (mu_message_t msg, mu_header_t out) | ... | @@ -1895,22 +1886,27 @@ copy_header (mu_message_t msg, mu_header_t out) |
1895 | void | 1886 | void |
1896 | copy_header_to_stream (mu_message_t msg, mu_stream_t stream) | 1887 | copy_header_to_stream (mu_message_t msg, mu_stream_t stream) |
1897 | { | 1888 | { |
1889 | int rc; | ||
1898 | mu_header_t hdr; | 1890 | mu_header_t hdr; |
1899 | mu_stream_t in; | 1891 | mu_stream_t flt, str; |
1900 | char *buf = NULL; | ||
1901 | size_t bufsize = 0, n = 0; | ||
1902 | 1892 | ||
1903 | mu_message_get_header (msg, &hdr); | 1893 | mu_message_get_header (msg, &hdr); |
1904 | mu_header_get_streamref (hdr, &in); | 1894 | mu_header_get_streamref (hdr, &str); |
1905 | /* FIXME: Use mu_stream_copy */ | 1895 | rc = mu_filter_create (&flt, str, "HEADER", |
1906 | while (mu_stream_getline (in, &buf, &bufsize, &n) == 0 && n > 0) | 1896 | MU_FILTER_DECODE, MU_STREAM_READ); |
1897 | mu_stream_unref (str); | ||
1898 | if (rc) | ||
1907 | { | 1899 | { |
1908 | if (n == 1 && buf[0] == '\n') | 1900 | mu_error (_("cannot open filter stream: %s"), mu_strerror (rc)); |
1909 | break; | 1901 | exit (1); |
1910 | mu_stream_write (stream, buf, n, NULL); | ||
1911 | } | 1902 | } |
1912 | mu_stream_destroy (&in); | 1903 | rc = mu_stream_copy (stream, flt, 0, NULL); |
1913 | free (buf); | 1904 | if (rc) |
1905 | { | ||
1906 | mu_error (_("error reading headers: %s"), mu_strerror (rc)); | ||
1907 | exit (1); | ||
1908 | } | ||
1909 | mu_stream_destroy (&flt); | ||
1914 | } | 1910 | } |
1915 | 1911 | ||
1916 | void | 1912 | void | ... | ... |
-
Please register or sign in to post a comment