[evolution-data-server] evo-I#461 - Let 'Wrap quoted text in replies' influence paragraph style



commit 3854843cff3aaae10dd898602b05a78613937768
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 2 18:27:21 2020 +0200

    evo-I#461 - Let 'Wrap quoted text in replies' influence paragraph style
    
    Related to https://gitlab.gnome.org/GNOME/evolution/-/issues/461

 src/camel/camel-enums.h              |  7 ++++-
 src/camel/camel-mime-filter-tohtml.c | 59 ++++++++++++++++++++++++++++++++++--
 2 files changed, 63 insertions(+), 3 deletions(-)
---
diff --git a/src/camel/camel-enums.h b/src/camel/camel-enums.h
index df3c9a70f6..659e9d877b 100644
--- a/src/camel/camel-enums.h
+++ b/src/camel/camel-enums.h
@@ -168,6 +168,7 @@ typedef enum { /*< flags >*/
  * CamelMimeFilterToHTMLFlags:
  * @CAMEL_MIME_FILTER_TOHTML_PRE:
  *     Enclose the content in &lt;pre&gt; ... &lt;/pre&gt; tags.
+ *     Cannot be used together with %CAMEL_MIME_FILTER_TOHTML_DIV.
  * @CAMEL_MIME_FILTER_TOHTML_CONVERT_NL:
  *     Convert newline characters to &lt;br&gt; tags.
  * @CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES:
@@ -190,6 +191,9 @@ typedef enum { /*< flags >*/
  *     Group lines beginning with one or more '&gt;' characters in
  *     &lt;blockquote type="cite"&gt; ... &lt;/blockquote&gt; tags. The tags
  *     are nested according to the number of '&gt;' characters.
+ * @CAMEL_MIME_FILTER_TOHTML_DIV:
+ *     Enclose the paragraphs in &lt;div&gt; ... &lt;/div&gt; tags.
+ *     Cannot be used together with %CAMEL_MIME_FILTER_TOHTML_PRE.
  *
  * Flags for converting text/plain content into text/html.
  **/
@@ -204,7 +208,8 @@ typedef enum { /*< flags >*/
        CAMEL_MIME_FILTER_TOHTML_CITE = 1 << 7,
        CAMEL_MIME_FILTER_TOHTML_PRESERVE_8BIT = 1 << 8,
        CAMEL_MIME_FILTER_TOHTML_FORMAT_FLOWED = 1 << 9,
-       CAMEL_MIME_FILTER_TOHTML_QUOTE_CITATION = 1 << 10
+       CAMEL_MIME_FILTER_TOHTML_QUOTE_CITATION = 1 << 10,
+       CAMEL_MIME_FILTER_TOHTML_DIV = 1 << 11
 } CamelMimeFilterToHTMLFlags;
 
 /**
diff --git a/src/camel/camel-mime-filter-tohtml.c b/src/camel/camel-mime-filter-tohtml.c
index 7fce562385..85254d2714 100644
--- a/src/camel/camel-mime-filter-tohtml.c
+++ b/src/camel/camel-mime-filter-tohtml.c
@@ -37,6 +37,7 @@ struct _CamelMimeFilterToHTMLPrivate {
 
        guint32 column : 31;
        guint32 pre_open : 1;
+       gboolean div_open;
 };
 
 /*
@@ -277,7 +278,7 @@ html_convert (CamelMimeFilter *mime_filter,
        priv = CAMEL_MIME_FILTER_TOHTML (mime_filter)->priv;
 
        if (inlen == 0) {
-               if (!priv->pre_open && priv->blockquote_depth == 0) {
+               if (!priv->pre_open && !priv->div_open && !priv->blockquote_depth) {
                        /* No closing tags needed. */
                        *out = (gchar *) in;
                        *outlen = 0;
@@ -288,6 +289,12 @@ html_convert (CamelMimeFilter *mime_filter,
                outptr = mime_filter->outbuf;
                outend = mime_filter->outbuf + mime_filter->outsize;
 
+               if (priv->div_open) {
+                       outptr = check_size (mime_filter, outptr, &outend, 7);
+                       outptr = g_stpcpy (outptr, "</div>");
+                       priv->div_open = FALSE;
+               }
+
                while (priv->blockquote_depth > 0) {
                        outptr = check_size (mime_filter, outptr, &outend, 15);
                        outptr = g_stpcpy (outptr, "</blockquote>");
@@ -315,7 +322,7 @@ html_convert (CamelMimeFilter *mime_filter,
        outptr = mime_filter->outbuf;
        outend = mime_filter->outbuf + mime_filter->outsize;
 
-       if (priv->flags & CAMEL_MIME_FILTER_TOHTML_PRE && !priv->pre_open) {
+       if ((priv->flags & CAMEL_MIME_FILTER_TOHTML_PRE) != 0 && !priv->pre_open) {
                outptr = check_size (mime_filter, outptr, &outend, 6);
                outptr = g_stpcpy (outptr, "<pre>");
                priv->pre_open = TRUE;
@@ -338,6 +345,12 @@ html_convert (CamelMimeFilter *mime_filter,
                        if (depth > 0) {
                                /* FIXME: we could easily support multiple color depths here */
 
+                               if ((priv->flags & CAMEL_MIME_FILTER_TOHTML_DIV) != 0 && !priv->div_open) {
+                                       outptr = check_size (mime_filter, outptr, &outend, 6);
+                                       outptr = g_stpcpy (outptr, "<div>");
+                                       priv->div_open = TRUE;
+                               }
+
                                outptr = check_size (mime_filter, outptr, &outend, 25);
                                outptr += sprintf (outptr, "<font color=\"#%06x\">", (priv->color & 
0xffffff));
                        }
@@ -352,6 +365,13 @@ html_convert (CamelMimeFilter *mime_filter,
                        goffset skip = 0;
 
                        depth = citation_depth (start, inend, &skip);
+
+                       if (priv->div_open && depth != priv->blockquote_depth) {
+                               outptr = check_size (mime_filter, outptr, &outend, 7);
+                               outptr = g_stpcpy (outptr, "</div>");
+                               priv->div_open = FALSE;
+                       }
+
                        while (priv->blockquote_depth < depth) {
                                outptr = check_size (mime_filter, outptr, &outend, 25);
                                outptr = g_stpcpy (outptr, "<blockquote type=\"cite\">");
@@ -371,11 +391,23 @@ html_convert (CamelMimeFilter *mime_filter,
                        start += skip;
 
                } else if (priv->flags & CAMEL_MIME_FILTER_TOHTML_CITE) {
+                       if ((priv->flags & CAMEL_MIME_FILTER_TOHTML_DIV) != 0 && !priv->div_open) {
+                               outptr = check_size (mime_filter, outptr, &outend, 6);
+                               outptr = g_stpcpy (outptr, "<div>");
+                               priv->div_open = TRUE;
+                       }
+
                        outptr = check_size (mime_filter, outptr, &outend, 6);
                        outptr = g_stpcpy (outptr, "&gt; ");
                        priv->column += 2;
                }
 
+               if ((priv->flags & CAMEL_MIME_FILTER_TOHTML_DIV) != 0 && !priv->div_open) {
+                       outptr = check_size (mime_filter, outptr, &outend, 6);
+                       outptr = g_stpcpy (outptr, "<div>");
+                       priv->div_open = TRUE;
+               }
+
 #define CONVERT_URLS (CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES)
                if (priv->flags & CONVERT_URLS) {
                        gsize matchlen, len;
@@ -457,6 +489,17 @@ html_convert (CamelMimeFilter *mime_filter,
                                outptr = g_stpcpy (outptr, "<br>");
                        }
 
+                       if (priv->div_open) {
+                               if (inptr == start && *start != '\r' && *start != '\n' && !(priv->flags & 
CAMEL_MIME_FILTER_TOHTML_CONVERT_NL)) {
+                                       outptr = check_size (mime_filter, outptr, &outend, 5);
+                                       outptr = g_stpcpy (outptr, "<br>");
+                               }
+
+                               outptr = check_size (mime_filter, outptr, &outend, 7);
+                               outptr = g_stpcpy (outptr, "</div>");
+                               priv->div_open = FALSE;
+                       }
+
                        outptr = append_string_verbatim (mime_filter, "\n", outptr, &outend);
                }
 
@@ -472,6 +515,12 @@ html_convert (CamelMimeFilter *mime_filter,
                                inend,
                                outptr, &outend);
 
+               if (priv->div_open) {
+                       outptr = check_size (mime_filter, outptr, &outend, 7);
+                       outptr = g_stpcpy (outptr, "</div>");
+                       priv->div_open = FALSE;
+               }
+
                while (priv->blockquote_depth > 0) {
                        outptr = check_size (mime_filter, outptr, &outend, 14);
                        outptr = g_stpcpy (outptr, "</blockquote>");
@@ -587,6 +636,12 @@ camel_mime_filter_tohtml_new (CamelMimeFilterToHTMLFlags flags,
        CamelMimeFilterToHTMLPrivate *priv;
        gint i;
 
+       /* Prefer PRE over DIV, when used together (which they should not) */
+       if ((flags & (CAMEL_MIME_FILTER_TOHTML_PRE | CAMEL_MIME_FILTER_TOHTML_DIV)) ==
+           (CAMEL_MIME_FILTER_TOHTML_PRE | CAMEL_MIME_FILTER_TOHTML_DIV)) {
+               flags = flags & ~CAMEL_MIME_FILTER_TOHTML_DIV;
+       }
+
        filter = g_object_new (CAMEL_TYPE_MIME_FILTER_TOHTML, NULL);
        priv = CAMEL_MIME_FILTER_TOHTML (filter)->priv;
 


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