<<< Date Index >>>     <<< Thread Index >>>

[PATCH] Improve f=f interoperability (was: [PATCH] fix indent_string handling with format=flowed)



Hi,

* Johannes Stezenbach [07-10-19 14:39:48 +0200] wrote:
On Thu, Oct 18, 2007, Rocco Rutte wrote:

But I see your point and agree there's a problem and "format=flawed" is true once more. If trimming spaces is the preferred solution, I need more time to come up with the logic of when to do it and when not. First thought:

   original: flowed? | reply: flowed? | trim spaces
1          N                 N               N
2          N                 Y               Y
3          Y                 N               Y
4          Y                 Y               N

1: fixed reply to fixed mail: no problem
2: flowed reply to fixed mail: your example, problem
3: fixed reply to flowed mail: potential problem later on, esp. with other MUAs
4: flowed reply to flowed mail: no problem

For 1, 2, and 4 I fully agree. For 3 I think it isn't required
(because plain old MUAs also wouldn't do it), but it could
potentially improve interoperability because it avoids problems
caused later by other MUAs which don't implement 2.

Attached is a patch which is a first take at implementing the above matrix. I only tested each case once but it seems to work.

Now that I look at the changes, the behavior differs quite a lot compare to the current one. Maybe we should only use these changes depending on $flowed_compat (or something like that) defaulting to 'no' (to keep the current behavior as default)?

Rocco
diff --git a/handler.c b/handler.c
index d2ad711..33a3944 100644
--- a/handler.c
+++ b/handler.c
@@ -1480,6 +1480,33 @@ void mutt_decode_attachment (BODY *b, STATE *s)
     iconv_close (cd);
 }
 
+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) && l >= 3 && ascii_strncmp (buf + l - 3, "-- ", 
3) != 0)
+    {
+      /* when generating format=flowed from format=fixed,
+       * strip all trailing spaces except for the signature
+       * separator to improve interoperability */
+      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;
@@ -1520,7 +1547,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/rfc3676.c b/rfc3676.c
index 916bde0..532f0a2 100644
--- a/rfc3676.c
+++ b/rfc3676.c
@@ -58,7 +58,16 @@ static void print_indent (int ql, STATE *s, int sp)
   int i;
 
   if (s->prefix)
-    ql++;
+  {
+    /* use given prefix only for format=fixed replies to format=flowed */
+    if (option (OPTTEXTFLOWED))
+      ql++;
+    else
+    {
+      state_puts (s->prefix, s);
+      sp = 0;
+    }
+  }
   for (i = 0; i < ql; i++)
     state_putc ('>', s);
   if (sp)
@@ -133,7 +142,9 @@ static void print_flowed_line (const char *line, STATE *s, 
int ql)
     print_indent (ql, s, ql > 0 || s->prefix);
     state_puts (oldpos, s);
 
-    if (pos < line + len)
+    /* only keep flowed paragraph flowable when generating f=f,
+     * for format=fixed strip them to improve interoperability */
+    if (pos < line + len && option (OPTTEXTFLOWED))
       state_putc (' ', s);
     state_putc ('\n', s);
     oldpos = pos;