[evolution-data-server] Bug #516000 - Wrong formatted quoted text



commit 27dae082f51be0be0ed77d513eb86a40bdb595b4
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 15 18:08:56 2009 +0200

    Bug #516000 - Wrong formatted quoted text

 camel/camel-mime-filter-linewrap.c |   53 +++++++++++++++++++++++++++++++----
 camel/camel-mime-filter-linewrap.h |    8 +++++-
 2 files changed, 54 insertions(+), 7 deletions(-)
---
diff --git a/camel/camel-mime-filter-linewrap.c b/camel/camel-mime-filter-linewrap.c
index 222c5e8..fa767d0 100644
--- a/camel/camel-mime-filter-linewrap.c
+++ b/camel/camel-mime-filter-linewrap.c
@@ -86,10 +86,12 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 		} else if (isspace (*p)) {
 			if (nchars >= linewrap->wrap_len) {
 				*q++ = '\n';
-				p++;
+				while (p < inend && isspace (*p))
+					p++;
 				nchars = 0;
 			} else {
 				*q++ = *p++;
+				nchars++;
 			}
 		} else {
 			*q++ = *p++;
@@ -97,10 +99,48 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 		}
 
 		/* line is getting way too long, we must force a wrap here */
-		if (nchars >= (linewrap->max_len - 1) && *p != '\n') {
-			*q++ = '\n';
-			*q++ = linewrap->indent;
-			nchars = 0;
+		if (nchars >= linewrap->max_len && *p != '\n') {
+			gboolean wrapped = FALSE;
+
+			if (isspace (*p)) {
+				while (p < inend && isspace (*p) && *p != '\n')
+					p++;
+			} else if ((linewrap->flags & CAMEL_MIME_FILTER_LINEWRAP_WORD) != 0) {
+				gchar *r = q - 1;
+
+				/* find the first space backward */
+				while (r > f->outbuf && !isspace (*r))
+					r--;
+
+				if (r > f->outbuf && *r != '\n') {
+					/* found some valid */
+					*r = '\n';
+					wrapped = TRUE;
+
+					if ((linewrap->flags & CAMEL_MIME_FILTER_LINEWRAP_NOINDENT) == 0) {
+						gchar *s = q + 1;
+
+						while (s > r) {
+							*s = *(s - 1);
+							s--;
+						}
+
+						*r = linewrap->indent;
+						q++;
+					}
+
+					nchars = q - r - 1;
+				}
+			}
+
+			if (!wrapped) {
+				*q++ = '\n';
+				if ((linewrap->flags & CAMEL_MIME_FILTER_LINEWRAP_NOINDENT) == 0) {
+					*q++ = linewrap->indent;
+					nchars = 1;
+				} else
+					nchars = 0;
+			}
 		}
 	}
 
@@ -128,7 +168,7 @@ reset (CamelMimeFilter *f)
 }
 
 CamelMimeFilter *
-camel_mime_filter_linewrap_new (guint preferred_len, guint max_len, gchar indent_char)
+camel_mime_filter_linewrap_new (guint preferred_len, guint max_len, gchar indent_char, guint32 flags)
 {
 	CamelMimeFilterLinewrap *linewrap =
 		CAMEL_MIME_FILTER_LINEWRAP (camel_object_new (CAMEL_MIME_FILTER_LINEWRAP_TYPE));
@@ -137,6 +177,7 @@ camel_mime_filter_linewrap_new (guint preferred_len, guint max_len, gchar indent
 	linewrap->wrap_len = preferred_len;
 	linewrap->max_len = max_len;
 	linewrap->nchars = 0;
+	linewrap->flags = flags | (indent_char == 0 ? CAMEL_MIME_FILTER_LINEWRAP_NOINDENT : 0);
 
 	return (CamelMimeFilter *) linewrap;
 }
diff --git a/camel/camel-mime-filter-linewrap.h b/camel/camel-mime-filter-linewrap.h
index cd15d82..fada920 100644
--- a/camel/camel-mime-filter-linewrap.h
+++ b/camel/camel-mime-filter-linewrap.h
@@ -31,6 +31,11 @@
 
 G_BEGIN_DECLS
 
+enum {
+	CAMEL_MIME_FILTER_LINEWRAP_NOINDENT = (1<<0), /* does not indent; it's forced for indent_char = 0 */
+	CAMEL_MIME_FILTER_LINEWRAP_WORD     = (1<<1), /* indents on word boundary */
+};
+
 typedef struct _CamelMimeFilterLinewrapClass CamelMimeFilterLinewrapClass;
 
 struct _CamelMimeFilterLinewrap {
@@ -40,6 +45,7 @@ struct _CamelMimeFilterLinewrap {
 	guint max_len;
 	gchar indent;
 	gint nchars;
+	guint32 flags;
 };
 
 struct _CamelMimeFilterLinewrapClass {
@@ -48,7 +54,7 @@ struct _CamelMimeFilterLinewrapClass {
 
 CamelType camel_mime_filter_linewrap_get_type (void);
 
-CamelMimeFilter *camel_mime_filter_linewrap_new (guint preferred_len, guint max_len, gchar indent_char);
+CamelMimeFilter *camel_mime_filter_linewrap_new (guint preferred_len, guint max_len, gchar indent_char, guint32 flags);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]