[gmime: 3/10] Better find citation cut depth



commit bb18b243a3a9fb13afa1d293e05885e3db220abd
Author: M. Dietrich <mdt emdete de>
Date:   Mon Feb 13 09:28:26 2017 +0100

    Better find citation cut depth

 gmime/gmime-filter-html.c |   59 ++++++++++++++++++++++++++------------------
 1 files changed, 35 insertions(+), 24 deletions(-)
---
diff --git a/gmime/gmime-filter-html.c b/gmime/gmime-filter-html.c
index 6996423..71f6c79 100644
--- a/gmime/gmime-filter-html.c
+++ b/gmime/gmime-filter-html.c
@@ -185,24 +185,47 @@ check_size (GMimeFilter *filter, char *outptr, char **outend, size_t len)
 static int
 citation_depth (const char *in, const char *inend)
 {
-       register const char *inptr = in;
-       int depth = 0;
+       register char *inptr = in;
+       /* check that it isn't an escaped From line */
+       if (!strncmp (inptr, ">From", 5))
+               return inptr;
+       while (inptr < inend && *inptr != '\n') {
+               if (*inptr == ' ')
+                       inptr++;
+               if (inptr >= inend || *inptr != '>')
+                       break;
+               inptr++;
+       }
+       return inptr;
+}
+
+
+static char *
+citation_cut (char *in, const char *inend)
+{
+       register char *inptr = in;
+  register char *start;
 
        /* check that it isn't an escaped From line */
        if (!strncmp (inptr, ">From", 5))
-               return 0;
+               return inptr;
 
        while (inptr < inend && *inptr != '\n') {
-               if (*inptr == ' ')
+
+    /* remove an arbitrary number of spaces between '>' and next '>' */
+    start = inptr;
+               while (*inptr == ' ' && inptr < inend)
                        inptr++;
 
-               if (inptr >= inend || *inptr++ != '>')
+               if (inptr >= inend || *inptr != '>') {
+      if (*start == ' ' && start < inend) start++;
+      inptr = start; // not followed by '>', revert.
                        break;
+    }
 
-               depth++;
+               inptr++;
        }
-
-       return depth;
+       return inptr;
 }
 
 static inline gunichar
@@ -368,11 +391,7 @@ html_convert (GMimeFilter *filter, char *in, size_t inlen, size_t prespace,
           outptr = g_stpcpy (outptr, bq);
         }
 
-        /* remove '>' */
-        while (*start == '>' && start < inptr) start++;
-
-        /* remove leading space */
-        if (*start == ' ' && start < inptr) start++;
+        start = citation_cut(start, inptr);
 
       } else if (html->prev_cit_depth > depth) {
 
@@ -383,20 +402,12 @@ html_convert (GMimeFilter *filter, char *in, size_t inlen, size_t prespace,
           html->prev_cit_depth--;
         }
 
-        /* remove '>' */
-        while (*start == '>' && start < inptr) start++;
-
-        /* remove leading space */
-        if (*start == ' ' && start < inptr) start++;
+        start = citation_cut(start, inptr);
 
       } else if (depth > 0) {
-        /* we are still at the same depth: remove '>' */
-        while (*start == '>' && start < inptr) start++;
-
-        /* remove leading space */
-        if (*start == ' ' && start < inptr) start++;
+        start = citation_cut(start, inptr);
 
-                       } else if (*start == '>') {
+                       } else if (start < inptr && *start == '>') {
                                /* >From line */
                                start++;
                        }


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