aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-25 13:21:51 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-25 13:21:51 +0100
commita03b2c328b0c9cb332527adb584b6e3496de5e46 (patch)
treea46ff1eabb22c94e76324805be0d38d6ae8efa72 /src/libutil
parentd21fdd376f883510ae2bf5de7307eb59d84cb614 (diff)
downloadrspamd-a03b2c328b0c9cb332527adb584b6e3496de5e46.tar.gz
rspamd-a03b2c328b0c9cb332527adb584b6e3496de5e46.zip
[Fix] Deal with 8bit characters in email addresses
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/str_util.h31
-rw-r--r--src/libutil/util.h2
2 files changed, 33 insertions, 0 deletions
diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h
index 2fec42987..473b5cbbb 100644
--- a/src/libutil/str_util.h
+++ b/src/libutil/str_util.h
@@ -339,4 +339,35 @@ const void *rspamd_memrchr (const void *m, gint c, gsize len);
*/
gsize rspamd_memcspn (const gchar *s, const gchar *e, gsize len);
+
+/* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */
+#define rspamd_str_hasmore(x,n) ((((x)+~0UL/255*(127-(n)))|(x))&~0UL/255*128)
+
+static inline gboolean
+rspamd_str_has_8bit (const guchar *beg, gsize len)
+{
+ unsigned long *w;
+ gsize i, leftover = len % sizeof (*w);
+
+ w = (unsigned long *)beg;
+
+ for (i = 0; i < len / sizeof (*w); i ++) {
+ if (rspamd_str_hasmore (*w, 127)) {
+ return TRUE;
+ }
+
+ w ++;
+ }
+
+ beg = (const guchar *)w;
+
+ for (i = 0; i < leftover; i ++) {
+ if (beg[i] > 127) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
#endif /* SRC_LIBUTIL_STR_UTIL_H_ */
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 48381ed92..605822fee 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -517,4 +517,6 @@ gdouble rspamd_normalize_probability (gdouble x, gdouble bias);
guint64 rspamd_tm_to_time (const struct tm *tm, glong tz);
#define PTR_ARRAY_FOREACH(ar, i, cur) for ((i) = 0; (ar) != NULL && (i) < (ar)->len && (((cur) = g_ptr_array_index((ar), (i))) || 1); ++(i))
+
+
#endif