aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime
diff options
context:
space:
mode:
authorMikhail Galanin <mgalanin@mimecast.com>2018-09-18 10:34:37 +0100
committerMikhail Galanin <mgalanin@mimecast.com>2018-09-18 10:34:37 +0100
commit2d6d215df32c129b15502efdf5ec3c21c3d167ff (patch)
tree8795a09e92950f6bc41271947ae1381e0b817bce /src/libmime
parent5b571379f3a2493f53eabd331da42ddcdcce4921 (diff)
downloadrspamd-2d6d215df32c129b15502efdf5ec3c21c3d167ff.tar.gz
rspamd-2d6d215df32c129b15502efdf5ec3c21c3d167ff.zip
[Minor] Insert spaces only if text part is not suspected to be a link
sa_body requires newlines to be replaces with spaces. However, some email clients highlight URL in triangular braces (<>) even if it's broken by a newline. Let's just remove \n if current text part potentially can be such URL.
Diffstat (limited to 'src/libmime')
-rw-r--r--src/libmime/message.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libmime/message.c b/src/libmime/message.c
index f0a235a4c..39768e0e0 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -244,6 +244,8 @@ rspamd_strip_newlines_parse (const gchar *begin, const gchar *pe,
const gchar *p = begin, *c = begin;
gchar last_c = '\0';
gboolean crlf_added = FALSE;
+ gboolean url_open_bracket = FALSE;
+
enum {
normal_char,
seen_cr,
@@ -285,6 +287,8 @@ rspamd_strip_newlines_parse (const gchar *begin, const gchar *pe,
break;
}
+ url_open_bracket = FALSE;
+
p ++;
}
else if (G_UNLIKELY (*p == '\n')) {
@@ -300,7 +304,7 @@ rspamd_strip_newlines_parse (const gchar *begin, const gchar *pe,
c = p + 1;
- if (IS_PART_HTML (part) || g_ascii_ispunct (last_c)) {
+ if (IS_PART_HTML (part) || !url_open_bracket) {
g_byte_array_append (part->utf_stripped_content,
(const guint8 *)" ", 1);
g_ptr_array_add (part->newlines,
@@ -315,7 +319,7 @@ rspamd_strip_newlines_parse (const gchar *begin, const gchar *pe,
case seen_cr:
/* \r\n */
if (!crlf_added) {
- if (IS_PART_HTML (part) || g_ascii_ispunct (last_c)) {
+ if (IS_PART_HTML (part) || !url_open_bracket) {
g_byte_array_append (part->utf_stripped_content,
(const guint8 *) " ", 1);
crlf_added = TRUE;
@@ -345,10 +349,18 @@ rspamd_strip_newlines_parse (const gchar *begin, const gchar *pe,
c = p + 1;
break;
}
+ url_open_bracket = FALSE;
p ++;
}
else {
+ if ((*p) == '<') {
+ url_open_bracket = TRUE;
+ }
+ else if ((*p) == '>') {
+ url_open_bracket = FALSE;
+ }
+
switch (state) {
case normal_char:
if (G_UNLIKELY (*p) == ' ') {