+ mp_stream = tny_mime_part_get_decoded_stream (body);
+
+ if (g_strcmp0 (tny_mime_part_get_content_type (body), "text/html") == 0) {
+ input_stream = tny_camel_html_to_text_stream_new (mp_stream);
+ } else {
+ input_stream = g_object_ref (mp_stream);
+ }
+
+ total = 0;
+ total_lines = 0;
+ line_chars = 0;
+
+ while (!tny_stream_is_eos (input_stream)) {
+ gchar buffer [128];
+ gchar *offset;
+ gint n_read;
+ gint next_read;
+
+ next_read = MIN (128, MAX_BODY_LENGTH - total);
+ if (next_read == 0)
+ break;
+ n_read = tny_stream_read (input_stream, buffer, next_read);
+
+ offset = buffer;
+ while (offset < buffer + n_read) {
+
+ if (*offset == '\n') {
+ total_lines ++;
+ line_chars = 0;
+ } else {
+ line_chars ++;
+ if (line_chars >= LINE_WRAP) {
+ total_lines ++;
+ line_chars = 0;
+ }
+ }
+ if (total_lines >= MAX_BODY_LINES)
+ break;
+ offset++;
+ }
+
+
+
+ if (offset - buffer > 0) {
+ gint n_write;
+ n_write = tny_stream_write (stream, buffer, offset - buffer);
+ total += n_write;
+ } else if (n_read == -1) {
+ break;
+ }
+
+ if (total_lines >= MAX_BODY_LINES)
+ break;
+ }
+