Mercurial > dovecot > core-2.2
diff src/lib-mail/message-address.c @ 988:8028c4dcf38f HEAD
mail-storage.h interface changes, affects pretty much everything.
FETCH, SEARCH, SORT and THREAD handling were pretty much moved from
lib-storage/ to imap/ so adding non-index storages would be much easier now.
Also POP3 server can now be easily implemented with lib-storage.
Not too well tested, and at least one major problem: partial fetching is
_slow_.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 20 Jan 2003 16:52:51 +0200 |
parents | fd8888f6f037 |
children | 39b899338c99 |
line wrap: on
line diff
--- a/src/lib-mail/message-address.c Mon Jan 20 15:56:55 2003 +0200 +++ b/src/lib-mail/message-address.c Mon Jan 20 16:52:51 2003 +0200 @@ -19,7 +19,8 @@ } struct message_address * -message_address_parse(pool_t pool, const unsigned char *data, size_t size) +message_address_parse(pool_t pool, const unsigned char *data, size_t size, + unsigned int max_addresses) { static const enum message_token stop_tokens_init[] = { ',', '@', '<', ':', TOKEN_LAST }; @@ -74,8 +75,11 @@ ingroup = FALSE; len = 0; stop_tokens = stop_tokens_init; + if (max_addresses == 0) + max_addresses = (unsigned int)-1; + next_phrase = mailbox; stop = FALSE; - while (!stop) { + while (!stop && max_addresses > 0) { if (next_phrase == name && str_len(name) > 0) { /* continuing previously started name, separate it from us with space */ @@ -101,6 +105,7 @@ if (str_len(mailbox) > 0 || str_len(domain) > 0 || str_len(route) > 0 || str_len(name) > 0) { addr = new_address(pool, &next_addr); + max_addresses--; addr->mailbox = p_strdup(pool, str_c(mailbox)); addr->domain = str_len(domain) == 0 ? NULL : p_strdup(pool, str_c(domain)); @@ -115,6 +120,7 @@ /* end of group - add end of group marker */ ingroup = FALSE; (void)new_address(pool, &next_addr); + max_addresses--; } if (token == TOKEN_LAST) { @@ -187,6 +193,7 @@ case ':': /* beginning of group */ addr = new_address(pool, &next_addr); + max_addresses--; addr->name = p_strdup(pool, str_c(mailbox)); str_truncate(mailbox, 0); @@ -210,3 +217,61 @@ return first_addr; } +void message_address_write(string_t *str, const struct message_address *addr) +{ + int first = TRUE, in_group = FALSE; + + /* a) mailbox@domain + b) name <@route:mailbox@domain> + c) group: .. ; */ + + while (addr != NULL) { + if (first) + first = FALSE; + else + str_append(str, ", "); + + if (addr->mailbox == NULL && addr->domain == NULL) { + if (!in_group) { + if (addr->name != NULL) + str_append(str, addr->name); + str_append(str, ": "); + first = TRUE; + } else { + i_assert(addr->name == NULL); + + /* cut out the ", " */ + str_truncate(str, str_len(str)-2); + str_append_c(str, ';'); + } + + in_group = !in_group; + } else if ((addr->name == NULL || *addr->name == '\0') && + addr->route == NULL) { + i_assert(addr->mailbox != NULL); + i_assert(addr->domain != NULL); + + str_append(str, addr->mailbox); + str_append_c(str, '@'); + str_append(str, addr->domain); + } else { + i_assert(addr->mailbox != NULL); + i_assert(addr->domain != NULL); + + if (addr->name != NULL) { + str_append(str, addr->name); + str_append_c(str, ' '); + } + str_append_c(str, '<'); + if (addr->route != NULL) { + str_append_c(str, '@'); + str_append(str, addr->route); + str_append_c(str, ':'); + } + str_append(str, addr->mailbox); + str_append_c(str, '@'); + str_append(str, addr->domain); + str_append_c(str, '>'); + } + } +}