]> granicus.if.org Git - mutt/commitdiff
Actually commit patch-1.5.1.me.long_qp.2.
authorMichael Elkins <me@sigpipe.org>
Tue, 12 Nov 2002 08:00:51 +0000 (08:00 +0000)
committerMichael Elkins <me@sigpipe.org>
Tue, 12 Nov 2002 08:00:51 +0000 (08:00 +0000)
handler.c

index 3cdd24fcc274b80841dcd43a7226e9606c49681a..fd9f24354ee90cce1302beebd9360f4aad48f505 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -182,16 +182,6 @@ static void qp_decode_line (char *dest, char *src, size_t *l,
   int kind;
   int soft = 0;
 
-  /* chop trailing whitespace */
-
-  if (*src)
-  {
-    s = src + strlen(src) - 1;
-    while (s >= src && ISSPACE(*s))
-      s--;
-    *(++s) = '\0';
-  }
-
   /* decode the line */
   
   for (d = dest, s = src; *s;)
@@ -240,10 +230,10 @@ void mutt_decode_quoted (STATE *s, long len, int istext, iconv_t cd)
   char line[STRING];
   char decline[2*STRING];
   size_t l = 0;
-  size_t linelen;      /* number of input bytes in `line' */
+  size_t linelen;      /* number of input bytes in `line' */
   size_t l3;
   
-  int last;    /* store the last character in the input line */
+  int last;    /* store the last character in the input line */
   
   if (istext)
     state_set_prefix(s);
@@ -253,11 +243,11 @@ void mutt_decode_quoted (STATE *s, long len, int istext, iconv_t cd)
     last = 0;
     
     /*
-     * its ok to use a fixed since buffer for input, even if the line turns
-     * out to be longer than this.  we will just dynamically grow the output
-     * buffer and process the line in chunks.  this really shouldn't happen
-     * according the MIME spec, since Q-P encoded lines are at most 76
-     * characters, but we should be liberal about what we expect.
+     * It's ok to use a fixed size buffer for input, even if the line turns
+     * out to be longer than this.  Just process the line in chunks.  This
+     * really shouldn't happen according the MIME spec, since Q-P encoded
+     * lines are at most 76 characters, but we should be liberal about what
+     * we accept.
      */
     if (fgets (line, MIN ((ssize_t)sizeof (line), len + 1), s->fpin) == NULL)
       break;
@@ -271,6 +261,14 @@ void mutt_decode_quoted (STATE *s, long len, int istext, iconv_t cd)
      */
     last = linelen ? line[linelen - 1] : 0;
 
+    /* chop trailing whitespace if we got the full line */
+    if (last == '\n')
+    {
+      while (linelen > 0 && ISSPACE (line[linelen-1]))
+       linelen--;
+      line[linelen]=0;
+    }
+
     /* decode and do character set conversion */
     qp_decode_line (decline + l, line, &l3, last);
     l += l3;