[evolution-data-server] evo-i#1206 - Mail: Preserve TABs in plain text body preview



commit 581e6f877d8af71b701ffea2e1281226722eade2
Author: Milan Crha <mcrha redhat com>
Date:   Wed Nov 4 11:17:06 2020 +0100

    evo-i#1206 - Mail: Preserve TABs in plain text body preview
    
    Add a new flag to cover the Evolution requirement.
    
    Related to https://gitlab.gnome.org/GNOME/evolution/-/issues/1206

 src/camel/camel-enums.h              |  6 +++++-
 src/camel/camel-mime-filter-tohtml.c | 24 +++++++++++++++++++-----
 2 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/src/camel/camel-enums.h b/src/camel/camel-enums.h
index 659e9d877..3a73c9db4 100644
--- a/src/camel/camel-enums.h
+++ b/src/camel/camel-enums.h
@@ -194,6 +194,9 @@ typedef enum { /*< flags >*/
  * @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.
+ * @CAMEL_MIME_FILTER_TOHTML_PRESERVE_TABS:
+ *     Set in combination with %CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES,
+ *     to keep tab characters. If not set, converts them into the spaces.
  *
  * Flags for converting text/plain content into text/html.
  **/
@@ -209,7 +212,8 @@ typedef enum { /*< flags >*/
        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_DIV = 1 << 11
+       CAMEL_MIME_FILTER_TOHTML_DIV = 1 << 11,
+       CAMEL_MIME_FILTER_TOHTML_PRESERVE_TABS = 1 << 12
 } CamelMimeFilterToHTMLFlags;
 
 /**
diff --git a/src/camel/camel-mime-filter-tohtml.c b/src/camel/camel-mime-filter-tohtml.c
index 85254d271..8893ee1d7 100644
--- a/src/camel/camel-mime-filter-tohtml.c
+++ b/src/camel/camel-mime-filter-tohtml.c
@@ -218,11 +218,25 @@ writeln (CamelMimeFilter *mime_filter,
                        break;
                case '\t':
                        if (priv->flags & (CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES)) {
-                               do {
-                                       outptr = check_size (mime_filter, outptr, outend, 7);
-                                       outptr = g_stpcpy (outptr, "&nbsp;");
-                                       priv->column++;
-                               } while (priv->column % 8);
+                               if ((priv->flags & CAMEL_MIME_FILTER_TOHTML_PRESERVE_TABS) != 0) {
+                                       const gchar *tmp = "<span class=\"Apple-tab-span\" 
style=\"white-space:pre\">\t</span>";
+                                       gint tmp_len = 61 /* strlen (tmp) */;
+                                       #ifdef ENABLE_MAINTAINER_MODE
+                                       static gboolean tested = FALSE;
+                                       if (!tested) {
+                                               tested = TRUE;
+                                               g_warn_if_fail (strlen (tmp) == tmp_len);
+                                       }
+                                       #endif
+                                       outptr = check_size (mime_filter, outptr, outend, tmp_len + 1);
+                                       outptr = g_stpcpy (outptr, tmp);
+                               } else {
+                                       do {
+                                               outptr = check_size (mime_filter, outptr, outend, 7);
+                                               outptr = g_stpcpy (outptr, "&nbsp;");
+                                               priv->column++;
+                                       } while (priv->column % 8);
+                               }
                                break;
                        }
                        /* falls through */


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