rspamd_email_address_parse_heuristic (const char *data, size_t len,
struct rspamd_email_address *addr)
{
- const gchar *p = data;
+ const gchar *p = data, *at = NULL, *end = data + len;
+ gboolean ret = FALSE;
memset (addr, 0, sizeof (*addr));
addr->addr = p + 1;
addr->raw = p;
addr->raw_len = len;
+ ret = TRUE;
- return TRUE;
+ p = p + 1;
+ len = addr->addr_len;
+ end = p + len;
}
else if (len > 0) {
addr->addr = p;
addr->addr_len = len;
addr->raw = p;
addr->raw_len = len;
+ ret = TRUE;
+ }
+
+ if (ret) {
+ at = memchr (p, '@', len);
+
+ if (at != NULL && at + 1 < end) {
+ addr->domain = at + 1;
+ addr->domain_len = end - (at + 1);
+ addr->user = p;
+ addr->user_len = at - p;
+ }
- return TRUE;
+ if (rspamd_str_has_8bit (p, len)) {
+ addr->flags |= RSPAMD_EMAIL_ADDR_HAS_8BIT;
+ }
}
- return FALSE;
+ return ret;
}
GPtrArray *
state = skip_spaces;
next_state = parse_name;
}
+ else if (*p == '@') {
+ seen_at = TRUE;
+ }
p ++;
break;
case skip_spaces:
RSPAMD_EMAIL_ADDR_HAS_BACKSLASH = (1 << 6),
RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED = (1 << 7),
RSPAMD_EMAIL_ADDR_USER_ALLOCATED = (1 << 8),
+ RSPAMD_EMAIL_ADDR_HAS_8BIT = (1 << 9),
};
/*
return FALSE;
}
-/* https://graphics.stanford.edu/~seander/bithacks.html#HasMoreInWord */
-#define hasmore(x,n) (((x)+~0UL/255*(127-(n))|(x))&~0UL/255*128)
-
-static inline gboolean
-rspamd_mime_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 (hasmore (*w, 127)) {
- return TRUE;
- }
-
- w ++;
- }
-
- beg = (const guchar *)w;
-
- for (i = 0; i < leftover; i ++) {
- if (beg[i] > 127) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
GByteArray *
rspamd_mime_text_part_maybe_convert (struct rspamd_task *task,
struct rspamd_mime_text_part *text_part)
rspamd_ftok_t charset_tok;
struct rspamd_mime_part *part = text_part->mime_part;
- if (rspamd_mime_has_8bit (text_part->raw.begin, text_part->raw.len)) {
+ if (rspamd_str_has_8bit (text_part->raw.begin, text_part->raw.len)) {
text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_8BIT;
}
memcpy (part_content->data, text_part->parsed.begin, text_part->parsed.len);
part_content->len = text_part->parsed.len;
- if (rspamd_mime_has_8bit (text_part->parsed.begin, text_part->parsed.len)) {
+ if (rspamd_str_has_8bit (text_part->parsed.begin, text_part->parsed.len)) {
text_part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_8BIT_ENCODED;
}
*/
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_ */
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
}
action Valid_addr {
- addr->flags |= RSPAMD_EMAIL_ADDR_VALID;
+ if (addr->addr_len > 0) {
+ addr->flags |= RSPAMD_EMAIL_ADDR_VALID;
+ }
}
action Addr_has_angle {