X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/19304f7c526fbe36ba0db2fb80bcaf3bd974d81d..9ae284163f491c64de122fcd555019040e0d4da7:/rfc822.c?ds=inline diff --git a/rfc822.c b/rfc822.c index f5d4aee..eca2d7d 100644 --- a/rfc822.c +++ b/rfc822.c @@ -60,7 +60,7 @@ const char *RFC822Errors[] = { "bad address spec" }; -static void rfc822_dequote_comment (char *s) +void rfc822_dequote_comment (char *s) { char *w = s; @@ -82,6 +82,46 @@ static void rfc822_dequote_comment (char *s) *w = 0; } +static void free_address (ADDRESS *a) +{ + FREE(&a->personal); + FREE(&a->mailbox); +#ifdef EXACT_ADDRESS + FREE(&a->val); +#endif + FREE(&a); +} + +int rfc822_remove_from_adrlist (ADDRESS **a, const char *mailbox) +{ + ADDRESS *p, *last = NULL, *t; + int rv = -1; + + p = *a; + last = NULL; + while (p) + { + if (ascii_strcasecmp (mailbox, p->mailbox) == 0) + { + if (last) + last->next = p->next; + else + (*a) = p->next; + t = p; + p = p->next; + free_address (t); + rv = 0; + } + else + { + last = p; + p = p->next; + } + } + + return (rv); +} + void rfc822_free_address (ADDRESS **p) { ADDRESS *t; @@ -137,17 +177,10 @@ parse_comment (const char *s, static const char * parse_quote (const char *s, char *token, size_t *tokenlen, size_t tokenmax) { - if (*tokenlen < tokenmax) - token[(*tokenlen)++] = '"'; while (*s) { if (*tokenlen < tokenmax) token[*tokenlen] = *s; - if (*s == '"') - { - (*tokenlen)++; - return (s + 1); - } if (*s == '\\') { if (!*++s) @@ -156,6 +189,8 @@ parse_quote (const char *s, char *token, size_t *tokenlen, size_t tokenmax) if (*tokenlen < tokenmax) token[*tokenlen] = *s; } + else if (*s == '"') + return (s + 1); (*tokenlen)++; s++; } @@ -391,6 +426,17 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s) } s = ps; } + else if (*s == '"') + { + if (phraselen && phraselen < sizeof (phrase) - 1) + phrase[phraselen++] = ' '; + if ((ps = parse_quote (s + 1, phrase, &phraselen, sizeof (phrase) - 1)) == NULL) + { + rfc822_free_address (&top); + return NULL; + } + s = ps; + } else if (*s == ':') { cur = rfc822_new_address (); @@ -450,13 +496,7 @@ ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s) terminate_buffer (phrase, phraselen); cur = rfc822_new_address (); if (phraselen) - { - if (cur->personal) - FREE (&cur->personal); - /* if we get something like "Michael R. Elkins" remove the quotes */ - rfc822_dequote_comment (phrase); cur->personal = safe_strdup (phrase); - } if ((ps = parse_route_addr (s + 1, comment, &commentlen, sizeof (comment) - 1, cur)) == NULL) { rfc822_free_address (&top); @@ -757,12 +797,17 @@ ADDRESS *rfc822_cpy_adr_real (ADDRESS *addr) } /* this should be rfc822_cpy_adrlist */ -ADDRESS *rfc822_cpy_adr (ADDRESS *addr) +ADDRESS *rfc822_cpy_adr (ADDRESS *addr, int prune) { ADDRESS *top = NULL, *last = NULL; for (; addr; addr = addr->next) { + if (prune && addr->group && (!addr->next || !addr->next->mailbox)) + { + addr = addr->next; + continue; + } if (last) { last->next = rfc822_cpy_adr_real (addr); @@ -775,7 +820,7 @@ ADDRESS *rfc822_cpy_adr (ADDRESS *addr) } /* append list 'b' to list 'a' and return the last element in the new list */ -ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b) +ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b, int prune) { ADDRESS *tmp = *a; @@ -784,9 +829,9 @@ ADDRESS *rfc822_append (ADDRESS **a, ADDRESS *b) if (!b) return tmp; if (tmp) - tmp->next = rfc822_cpy_adr (b); + tmp->next = rfc822_cpy_adr (b, prune); else - tmp = *a = rfc822_cpy_adr (b); + tmp = *a = rfc822_cpy_adr (b, prune); while (tmp && tmp->next) tmp = tmp->next; return tmp; @@ -816,7 +861,6 @@ int rfc822_valid_msgid (const char *msgid) * domain-literal = "[" *(dtext / quoted-pair) "]" */ - char* dom; unsigned int l, i; if (!msgid || !*msgid) @@ -827,7 +871,7 @@ int rfc822_valid_msgid (const char *msgid) return -1; if (msgid[0] != '<' || msgid[l-1] != '>') return -1; - if (!(dom = strrchr (msgid, '@'))) + if (!(strrchr (msgid, '@'))) return -1; /* TODO: complete parser */