--- src/version.c      2007-07-07 13:14:58.000000000 +0200
+++ src/version.c      2007-07-07 13:13:27.000000000 +0200
@@ -83,2 +83,3 @@
 static char *included_patches[] =
 {
+ "encoded_newline",
--- src/mime.c	(revision 5)
+++ src/mime.c	(working copy)
@@ -232,6 +232,37 @@
 /*}}}*/
 #endif /* NOT SLRNPULL_CODE*/
 
+/* call this with option keep_nl_tab = 0 when handling headers */
+static char *cp_decoded_char(char *dest, char ch, int keep_nl_tab)
+{
+  if(keep_nl_tab)
+  {
+    *dest++=ch;
+  }
+  else
+  {
+    /* Throw away newlines and carriage returns. 
+     * Change tabs to spaces.
+     * only broken readers place them in headers and
+     * slrn does not like that. */
+    switch(ch)
+    {
+     case '\n':
+     case '\r':
+      break;
+
+     case '\t':
+       *dest++ = ' ';
+       break;
+
+     default:
+       *dest++ = ch;
+       break;
+    }
+  }
+  return dest;
+}
+
 static int Index_Hex[128] =/*{{{*/
 {
    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
@@ -250,10 +281,10 @@
 static char *decode_quoted_printable (char *dest,/*{{{*/
 				      char *src, char *srcmax,
 				      int treat_underscore_as_space,
-				      int strip_8bit)
+				      int keep_nl_tab)
 {
    char *allowed_in_qp = "0123456789ABCDEFabcdef";
-   unsigned char ch, mask = 0x0;
+   unsigned char ch;
 /*
 #ifndef SLRNPULL_CODE
    if (strip_8bit && (NULL == Char_Set))
@@ -269,8 +300,8 @@
 	    && (NULL != slrn_strchr (allowed_in_qp, src[1])))
 	  {
 	     ch = (16 * HEX(src[0])) + HEX(src[1]);
-	     if (ch & mask) ch = '?';
-	     *dest++ = (char) ch;
+             /* remove nl and tab from line if wanted */
+             dest=cp_decoded_char(dest, ch, keep_nl_tab);
 	     src += 2;
 	  }
 	else if ((ch == '_') && treat_underscore_as_space)
@@ -298,17 +329,23 @@
 /*}}}*/
 #define BASE64(c) (Index_64[(unsigned char)(c) & 0x7F])
 
-static char *decode_base64 (char *dest, char *src, char *srcmax) /*{{{*/
+
+static char *decode_base64 (char *dest, char *src, char *srcmax, int keep_nl_tab) /*{{{*/
 {
+   char tmp;
+
    while (src + 3 < srcmax)
      {
-	*dest++ = (BASE64(src[0]) << 2) | (BASE64(src[1]) >> 4);
-	
+	tmp = (BASE64(src[0]) << 2) | (BASE64(src[1]) >> 4);
+        dest=cp_decoded_char(dest, tmp, keep_nl_tab);
+
 	if (src[2] == '=') break;
-	*dest++ = ((BASE64(src[1]) & 0xf) << 4) | (BASE64(src[2]) >> 2);
+	tmp = ((BASE64(src[1]) & 0xf) << 4) | (BASE64(src[2]) >> 2);
+        dest=cp_decoded_char(dest, tmp, keep_nl_tab);
 	
 	if (src[3] == '=') break;
-	*dest++ = ((BASE64(src[2]) & 0x3) << 6) | BASE64(src[3]);
+	tmp = ((BASE64(src[2]) & 0x3) << 6) | BASE64(src[3]);
+        dest=cp_decoded_char(dest, tmp, keep_nl_tab);
 	src += 4;
      }
    return dest;
@@ -425,7 +462,7 @@
 	s2 = s1;
 	
 	if (method == 'B')
-	  s1 = decode_base64 (s1, txt, s);
+	  s1 = decode_base64 (s1, txt, s, 0);
 	else s1 = decode_quoted_printable (s1, txt, s, 1, 0);
 	
 	/* Now move everything over */
@@ -546,7 +583,7 @@
      }
    
    /* put decoded article into buf_dest */
-   buf_pos = decode_base64(buf_dest, buf_src, buf_src+len);
+   buf_pos = decode_base64(buf_dest, buf_src, buf_src+len, 1);
    *buf_pos = '\0';
    
 #ifndef HAVE_ICONV_H
@@ -778,6 +815,49 @@
 
 /*}}}*/
 
+int split_qp_lines(Slrn_Article_Type *a)/*{{{*/
+{
+   struct Slrn_Article_Line_Type *line, *new_line;
+   char   *qp_nl, *tmp_buf;
+
+   line=a->lines;
+
+   /* skip header lines */
+   while((line->flags & HEADER_LINE) == 0)
+   {
+     line=line->next;
+   }
+
+   while(line != NULL)
+   {
+       qp_nl = slrn_strchr((unsigned char*)line->buf, 0x0A);
+       /* if there is a newline inside a Slrn_Article_Line_Type->buf split this line into two */
+       if(qp_nl != NULL)
+       {
+           *qp_nl = 0;
+
+           new_line=(Slrn_Article_Line_Type *) slrn_malloc(sizeof(Slrn_Article_Line_Type),1,1);
+           new_line->buf=slrn_safe_strmalloc(qp_nl+1);
+
+           tmp_buf=slrn_safe_strmalloc((unsigned char*)line->buf);
+           slrn_free((unsigned char*)line->buf);
+           line->buf=tmp_buf;
+
+           new_line->next   = line->next;
+           new_line->prev   = line;
+           if(line->next != NULL)
+           {
+             line->next->prev = new_line;
+           }
+           line->next       = new_line;
+
+       }
+       line=line->next;
+   }
+}
+/*}}}*/
+
+
 int slrn_mime_process_article (Slrn_Article_Type *a)/*{{{*/
 {
    if ((a == NULL) || (a->mime.was_parsed))
@@ -815,6 +895,7 @@
 	
       case ENCODED_QUOTED:
 	decode_mime_quoted_printable (a);
+        split_qp_lines(a);
 	break;
 	
       default:
