diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-12-02 22:01:43 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-12-02 22:19:38 +0200 |
commit | 04474c2918cc831e953dc37ae1d90cac170cd5b0 (patch) | |
tree | 33fe8bcf8c902f50f0dd86718a0c623fbf3d907a /mail/escape.c | |
parent | 88009983722512ea36ce3112ffb0cf657ca18d67 (diff) | |
download | mailutils-04474c2918cc831e953dc37ae1d90cac170cd5b0.tar.gz mailutils-04474c2918cc831e953dc37ae1d90cac170cd5b0.tar.bz2 |
Improve the inline-comment filter.
* libmailutils/filter/inline-comment.c: Recognize multi-char
comment sequences.
Implement encode mode.
* libmailutils/tests/inline-comment.at: Test the new modes.
* mail/escape.c (quote0): Re-implement using inline-comment
encode mode.
* mail/mailvar.c (mailvar_tab): Fix a typo.
Diffstat (limited to 'mail/escape.c')
-rw-r--r-- | mail/escape.c | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/mail/escape.c b/mail/escape.c index 18e60e0aa..e42919604 100644 --- a/mail/escape.c +++ b/mail/escape.c @@ -447,12 +447,35 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) size_t size = 0; size_t n = 0; char *prefix = "\t"; + mu_stream_t outstr, flt; + char *argv[3]; fprintf (stdout, _("Interpolating: %lu\n"), (unsigned long) mspec->msg_part[0]); mailvar_get (&prefix, "indentprefix", mailvar_type_string, 0); + fflush (ofile); + rc = mu_stdio_stream_create (&outstr, fileno (ofile), MU_STREAM_WRITE); + if (rc) + { + mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create", NULL, rc); + return rc; + } + argv[0] = "INLINE-COMMENT"; + argv[1] = prefix; + argv[2] = NULL; + rc = mu_filter_create_args (&flt, outstr, "INLINE-COMMENT", + 2, argv, + MU_FILTER_ENCODE, + MU_STREAM_WRITE); + mu_stream_unref (outstr); + if (rc) + { + mu_diag_funcall (MU_DIAG_ERROR, "mu_filter_create_args", NULL, rc); + return rc; + } + if (*(int*)data) { size_t i, num = 0; @@ -468,20 +491,15 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) { const char *value; - fprintf (ofile, "%s%s: ", prefix, sptr); + mu_stream_printf (flt, "%s: ", sptr); if (mu_header_sget_value (hdr, sptr, &value) == 0) { - for (; *value; value++) - { - fputc (*value, ofile); - if (*value == '\n') - fprintf (ofile, "%s", prefix); - } - fputc ('\n', ofile); + mu_stream_write (flt, value, strlen (value), NULL); + mu_stream_write (flt, "\n", 1, NULL); } } } - fprintf (ofile, "%s\n", prefix); + mu_stream_write (flt, "\n", 1, NULL); mu_message_get_body (mesg, &body); rc = mu_body_get_streamref (body, &stream); } @@ -494,11 +512,11 @@ quote0 (msgset_t *mspec, mu_message_t mesg, void *data) return rc; } - /* FIXME: Use mu_stream_copy? */ - while (mu_stream_getline (stream, &buffer, &size, &n) == 0 && n != 0) - fprintf (ofile, "%s%s", prefix, buffer); - free (buffer); + mu_stream_copy (flt, stream, 0, NULL); + mu_stream_destroy (&stream); + mu_stream_destroy (&flt); + return 0; } |