commit 60e234c: [Minor] Compare parts with many words by just using their length

Vsevolod Stakhov vsevolod at rspamd.com
Wed May 31 14:07:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-05-31 15:04:51 +0100
URL: https://github.com/rspamd/rspamd/commit/60e234c400d1063db48d2ac42e46329ef148d32e (HEAD -> master)

[Minor] Compare parts with many words by just using their length

---
 src/libmime/message.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/libmime/message.c b/src/libmime/message.c
index af8ad0e56..bdc1378d9 100644
--- a/src/libmime/message.c
+++ b/src/libmime/message.c
@@ -585,9 +585,17 @@ rspamd_words_levenshtein_distance (struct rspamd_task *task,
 	s2len = w2->len;
 
 	if (s1len + s2len > max_words) {
-		msg_err_task ("cannot compare parts with more than %ud words: (%ud + %ud)",
+		msg_info_task ("cannot direct compare multipart/alternative parts with more than %ud words in total: "
+					   "(%ud words in one part and %ud in another)",
 				max_words, s1len, s2len);
-		return 0;
+
+		/* Use approximate comparison of number of words */
+		if (s1len > s2len) {
+			return s1len - s2len;
+		}
+		else {
+			return s2len - s1len;
+		}
 	}
 
 	column = g_malloc0 ((s1len + 1) * sizeof (guint));


More information about the Commits mailing list