From c3a414139285a24252354a7448f30920ffc8bf93 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Sun, 31 May 2009 11:32:06 +0200 Subject: [PATCH] f=f: Strip trailing spaces for interoperability. Closes #3001. If we make a fixed reply to a flowed message we remove trailing spaces and can now safely allow $indent_string to be used which is what users expect. Second, if we make a flowed reply to a fixed message we also strip trailing spaces since from format=fixed we assume all lines are fixed (i.e. we don't want to errorneously make fixed lines flowed). --- handler.c | 30 +++++++++++++++++++++++++++++- init.h | 7 +++---- rfc3676.c | 31 ++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/handler.c b/handler.c index a4c27ad01..e9cfafb49 100644 --- a/handler.c +++ b/handler.c @@ -1485,6 +1485,34 @@ void mutt_decode_attachment (BODY *b, STATE *s) iconv_close (cd); } +/* when generating format=flowed ($text_flowed is set) from format=fixed, + * strip all trailing spaces to improve interoperability; + * if $text_flowed is unset, simply verbatim copy input + */ +static int text_plain_handler (BODY *b, STATE *s) +{ + char buf[LONG_STRING]; + size_t l; + + while (fgets (buf, sizeof (buf), s->fpin)) + { + l = mutt_strlen (buf); + if (l > 0 && buf[l-1] == '\n') + buf[--l] = 0; + if (option (OPTTEXTFLOWED)) + { + while (l > 0 && buf[l-1] == ' ') + buf[--l] = 0; + } + if (s->prefix) + state_puts (s->prefix, s); + state_puts (buf, s); + state_putc ('\n', s); + } + + return 0; +} + int mutt_body_handler (BODY *b, STATE *s) { int decode = 0; @@ -1525,7 +1553,7 @@ int mutt_body_handler (BODY *b, STATE *s) else if (ascii_strcasecmp ("flowed", mutt_get_parameter ("format", b->parameter)) == 0) handler = rfc3676_handler; else - plaintext = 1; + handler = text_plain_handler; } else if (ascii_strcasecmp ("enriched", b->subtype) == 0) handler = text_enriched_handler; diff --git a/init.h b/init.h index b480f8ff9..44b46a5fd 100644 --- a/init.h +++ b/init.h @@ -1222,12 +1222,11 @@ struct option_t MuttVars[] = { ** message to which you are replying. You are strongly encouraged not to ** change this value, as it tends to agitate the more fanatical netizens. ** .pp + ** The value of this option is ignored if $$text_flowed is set, too because + ** the quoting mechanism is strictly defined for format=flowed. + ** .pp ** This option is a format string, please see the description of ** $$index_format for supported \fCprintf(3)\fP-style sequences. - ** .pp - ** Because for \fCformat=lowed\fP style messages the quoting mechanism - ** is strictly defined, this setting is ignored if $$text_flowed is - ** \fIset\fP. */ { "indent_str", DT_SYN, R_NONE, UL "indent_string", 0 }, /* diff --git a/rfc3676.c b/rfc3676.c index 872dbbffb..651975d22 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2005 Andreas Krennmair * Copyright (C) 2005 Peter J. Holzer - * Copyright (C) 2005-7 Rocco Rutte + * Copyright (C) 2005-9 Rocco Rutte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -56,14 +56,27 @@ static int get_quote_level (const char *line) static size_t print_indent (int ql, STATE *s, int sp) { int i; + size_t len = 0; if (s->prefix) - ql++; + { + /* use given prefix only for format=fixed replies to format=flowed, + * for format=flowed replies to format=flowed, use '>' indentation + */ + if (option (OPTTEXTFLOWED)) + ql++; + else + { + state_puts (s->prefix, s); + len = mutt_strlen (s->prefix); + sp = 0; + } + } for (i = 0; i < ql; i++) state_putc ('>', s); if (sp) state_putc (' ', s); - return ql + sp; + return ql + sp + len; } static void flush_par (STATE *s, size_t *sofar) @@ -109,9 +122,11 @@ static void print_flowed_line (char *line, STATE *s, int ql, size_t *sofar, int dprint (4, (debugfile, "f=f: word [%s], width = %ld, line = %ld\n", NONULL(p), (long)w, (long)*sofar)); if (w + 1 + (*sofar) > width) { - /* line would be too long, flush */ + /* line would be too long, flush; for format=flowed we keep a + * trailing space but remove it otherwise for interoperability + */ dprint (4, (debugfile, "f=f: width: %ld\n", (long)*sofar)); - state_puts (" \n", s); + state_puts (option (OPTTEXTFLOWED) ? " \n" : "\n", s); *sofar = 0; } if (*sofar == 0) @@ -122,8 +137,10 @@ static void print_flowed_line (char *line, STATE *s, int ql, size_t *sofar, int } if (words > 0) { - /* put space before current word if we have words already */ - state_putc (' ', s); + /* put space before current word if we have words already, + and the current word isn't the trailing space */ + if (w > 0) + state_putc (' ', s); (*sofar)++; } state_puts (NONULL(p), s); -- 2.40.0