-address_t *rfc822_parse_adrlist (address_t * top, const char *s)
-{
- int ws_pending;
- const char *begin, *ps;
- char comment[STRING], phrase[STRING];
- size_t phraselen = 0, commentlen = 0;
- address_t *cur, *last = NULL;
-
- RFC822Error = 0;
-
- last = top;
- while (last && last->next)
- last = last->next;
-
- ws_pending = isspace ((unsigned char) *s);
-
- begin = s = vskipspaces(s);
- while (*s) {
- if (*s == ',') {
- if (phraselen) {
- terminate_buffer (phrase, phraselen);
- add_addrspec (&top, &last, phrase, comment, &commentlen,
- sizeof (comment) - 1);
- }
- else if (commentlen && last && !last->personal) {
- terminate_buffer (comment, commentlen);
- last->personal = m_strdup(comment);
- }
-
- commentlen = 0;
- phraselen = 0;
- s++;
- begin = vskipspaces(s);
- }
- else if (*s == '(') {
- if (commentlen && commentlen < sizeof (comment) - 1)
- comment[commentlen++] = ' ';
- if ((ps =
- next_token (s, comment, &commentlen,
- sizeof (comment) - 1)) == NULL) {
- address_delete (&top);
- return NULL;
- }
- s = ps;
- }
- else if (*s == ':') {
- cur = address_new ();
- terminate_buffer (phrase, phraselen);
- cur->mailbox = m_strdup(phrase);
- cur->group = 1;
-
- if (last)
- last->next = cur;
- else
- top = cur;
- last = cur;
-
- phraselen = 0;
- commentlen = 0;
- s++;
- begin = vskipspaces(s);
- }
- else if (*s == ';') {
- if (phraselen) {
- terminate_buffer (phrase, phraselen);
- add_addrspec (&top, &last, phrase, comment, &commentlen,
- sizeof (comment) - 1);
- }
- else if (commentlen && last && !last->personal) {
- terminate_buffer (comment, commentlen);
- last->personal = m_strdup(comment);
- }
-
- /* add group terminator */
- cur = address_new ();
- if (last) {
- last->next = cur;
- last = cur;
- }
-
- phraselen = 0;
- commentlen = 0;
- s++;
- begin = vskipspaces(s);
- }
- else if (*s == '<') {
- terminate_buffer (phrase, phraselen);
- cur = address_new ();
- if (phraselen) {
- if (cur->personal)
- p_delete(&cur->personal);
- /* if we get something like "Michael R. Elkins" remove the quotes */
- rfc822_dequote_comment (phrase);
- cur->personal = m_strdup(phrase);
- }
- if ((ps =
- parse_route_addr (s + 1, comment, &commentlen,
- sizeof (comment) - 1, cur)) == NULL) {
- address_delete (&top);
- address_delete (&cur);
- return NULL;
- }