aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-07 22:32:10 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-07 22:32:10 +0100
commit8ddac787506f4d68ef1ec7501c53afe065b8040f (patch)
tree37e5e674fcb0b528dcbd436b45decced5ac52d03 /src/libserver
parent27cd26c8d57e29304d4e48fe739fa02a5922a77b (diff)
downloadrspamd-8ddac787506f4d68ef1ec7501c53afe065b8040f.tar.gz
rspamd-8ddac787506f4d68ef1ec7501c53afe065b8040f.zip
Fix text emails parsing.
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/url.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/libserver/url.c b/src/libserver/url.c
index 1342ae92c..55f4c30e0 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -1454,6 +1454,16 @@ url_email_start (struct url_callback_data *cb,
return TRUE;
}
+ else {
+ /* Just '@' */
+
+ /* Check if this match is a part of the previous mailto: email */
+ if (cb->last_at != NULL && cb->last_at == pos) {
+ cb->last_at = NULL;
+ }
+
+ return FALSE;
+ }
return FALSE;
}
@@ -1463,7 +1473,7 @@ url_email_end (struct url_callback_data *cb,
const gchar *pos,
url_match_t *match)
{
- const gchar *last = NULL;
+ const gchar *last = NULL, *c, *p;
struct http_parser_url u;
if (!match->prefix || match->prefix[0] == '\0') {
@@ -1484,6 +1494,47 @@ url_email_end (struct url_callback_data *cb,
return TRUE;
}
+ else {
+ /*
+ * Here we have just '@', so we need to find both start and end of the
+ * pattern
+ */
+ g_assert (*pos == '@');
+
+ if (pos >= cb->end - 2 || pos <= cb->begin + 1) {
+ /* Boundary violation */
+ return FALSE;
+ }
+
+ if (!g_ascii_isalnum (pos[1]) || !g_ascii_isalnum (*(pos - 1))) {
+ return FALSE;
+ }
+
+ c = pos - 1;
+ while (c > cb->begin && is_usersafe (*c)) {
+ c --;
+ }
+ /* Rewind to the first alphanumeric character */
+ while (c < pos && !g_ascii_isalnum (c)) {
+ c ++;
+ }
+
+ /* Find the end of email */
+ p = pos + 1;
+ while (p < cb->end && is_domain (*p)) {
+ p ++;
+ }
+ /* Rewind it again to avoid bad emails to be detected */
+ while (p > pos && !g_ascii_isalnum (*p)) {
+ p --;
+ }
+
+ if (p > c) {
+ match->m_begin = c;
+ match->m_len = p - c;
+ return TRUE;
+ }
+ }
return FALSE;
}