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;
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:
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:
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;
}
}
}
break;
case parse_quoted:
- /* Unfinished quoted string */
+ case skip_comment:
+ /* Unfinished quoted string or a comment */
break;
default:
/* Do nothing */