summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2020-09-02 18:27:21 +0200
committerMilan Crha <mcrha@redhat.com>2020-09-02 18:52:16 +0200
commit3854843cff3aaae10dd898602b05a78613937768 (patch)
tree9f396a3ecf4cc44c1339fd1e2534e0f6fff61f50
parent0c4fe75e91c9aa16b10ffccc9a99f61d2b1388e0 (diff)
downloadevolution-data-server-3854843cff3aaae10dd898602b05a78613937768.tar.gz
evo-I#461 - Let 'Wrap quoted text in replies' influence paragraph style
Related to https://gitlab.gnome.org/GNOME/evolution/-/issues/461
-rw-r--r--src/camel/camel-enums.h7
-rw-r--r--src/camel/camel-mime-filter-tohtml.c59
2 files changed, 63 insertions, 3 deletions
diff --git a/src/camel/camel-enums.h b/src/camel/camel-enums.h
index df3c9a70f..659e9d877 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 7fce56238..85254d271 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;