aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime/email_addr.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-25 16:25:36 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-25 16:25:36 +0100
commit91b2d72df64fc0d30dd18acd85c62cac7b00030c (patch)
tree46458d0f7057705015d2e5323f23cf035fd87689 /src/libmime/email_addr.c
parent2f08a47d852a3cfb75d27a82d65f7dbf77cbc8bd (diff)
downloadrspamd-91b2d72df64fc0d30dd18acd85c62cac7b00030c.tar.gz
rspamd-91b2d72df64fc0d30dd18acd85c62cac7b00030c.zip
[Fix] Fix RFC822 comments when processing a mime address
Diffstat (limited to 'src/libmime/email_addr.c')
-rw-r--r--src/libmime/email_addr.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c
index 08071afc8..a0ad9ac19 100644
--- a/src/libmime/email_addr.c
+++ b/src/libmime/email_addr.c
@@ -203,10 +203,12 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool,
struct rspamd_email_address addr;
const gchar *p = hdr, *end = hdr + len, *c = hdr, *t;
GString *ns;
+ gint obraces, ebraces;
enum {
parse_name = 0,
parse_quoted,
parse_addr,
+ skip_comment,
skip_spaces
} state = parse_name, next_state = parse_name;
@@ -290,6 +292,23 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool,
else if (*p == '@') {
seen_at = TRUE;
}
+ else if (*p == '(') {
+ if (p > c) {
+ t = p - 1;
+
+ while (t > c && g_ascii_isspace (*t)) {
+ t --;
+ }
+
+ g_string_append_len (ns, c, t - c + 1);
+ }
+
+ c = p;
+ obraces = 1;
+ ebraces = 0;
+ state = skip_comment;
+ next_state = parse_name;
+ }
p ++;
break;
case parse_quoted:
@@ -331,6 +350,12 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool,
else if (*p == '@') {
seen_at = TRUE;
}
+ else if (*p == '(') {
+ obraces = 1;
+ ebraces = 0;
+ state = skip_comment;
+ next_state = parse_addr;
+ }
p ++;
break;
case skip_spaces:
@@ -342,6 +367,33 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool,
p ++;
}
break;
+ case skip_comment:
+ if (*p == '(') {
+ obraces ++;
+ }
+ else if (*p == ')') {
+ ebraces --;
+ }
+
+ if (obraces == ebraces) {
+ if (next_state == parse_name) {
+ /* Include comment in name */
+ if (p > c) {
+ t = p - 1;
+
+ while (t > c && g_ascii_isspace (*t)) {
+ t --;
+ }
+
+ g_string_append_len (ns, c, t - c + 1);
+ }
+
+ c = p;
+ }
+ state = next_state;
+ }
+ p ++;
+ break;
}
}
@@ -396,7 +448,8 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool,
}
break;
case parse_quoted:
- /* Unfinished quoted string */
+ case skip_comment:
+ /* Unfinished quoted string or a comment */
break;
default:
/* Do nothing */