]> granicus.if.org Git - mutt/commitdiff
Don't hallucinate a '\n' in the end of quoted-printable encoded
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 15 Jan 2002 22:02:47 +0000 (22:02 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 15 Jan 2002 22:02:47 +0000 (22:02 +0000)
attachments.

handler.c

index de24134e502ecbb6efc2b34a2b26ef97b6fa39cc..6933edd895aaf699c63c2c92b6fe9873349b3d9d 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -169,7 +169,8 @@ static int qp_decode_triple (char *s, char *d)
   return -1;
 }
 
-static void qp_decode_line (char *dest, char *src, size_t *l)
+static void qp_decode_line (char *dest, char *src, size_t *l,
+                           int last)
 {
   char *d, *s;
   char c;
@@ -199,7 +200,7 @@ static void qp_decode_line (char *dest, char *src, size_t *l)
     }
   }
 
-  if (!soft)
+  if (!soft && last == '\n')
     *d++ = '\n';
   
   *d = '\0';
@@ -237,13 +238,17 @@ void mutt_decode_quoted (STATE *s, long len, int istext, iconv_t cd)
   size_t l = 0;
   size_t l2;
   size_t l3;
-
+  
+  int last;
+  
   if (istext)
     state_set_prefix(s);
 
   while (len > 0)
   {
-    if (fgets (line, sizeof (line), s->fpin) == NULL)
+    last = 0;
+    
+    if (fgets (line, MIN (sizeof (line), len + 1), s->fpin) == NULL)
       break;
 
     len -= (l2 = strlen (line));
@@ -254,15 +259,15 @@ void mutt_decode_quoted (STATE *s, long len, int istext, iconv_t cd)
      * i.e. garbage.
      */
 
-    if (l2 && line[l2 - 1] != '\n')
-      while (len > 0 && fgetc (s->fpin) != '\n')
+    if (l2 && (last = line[l2 - 1]) != '\n')
+      while (len > 0 && (last = fgetc (s->fpin)) != '\n')
        len--;
 
     /* 
      * decode and do character set conversion
      */
     
-    qp_decode_line (decline + l, line, &l3);
+    qp_decode_line (decline + l, line, &l3, last);
     l += l3;
     convert_to_state (cd, decline, &l, s);
   }