48#define is_special(ch) strchr(AddressSpecials, ch)
65 "out of memory",
"mismatched parentheses",
"mismatched quotes",
66 "bad route in <>",
"bad address in <>",
"bad address spec",
78static const char *
parse_comment(
const char *s,
char *comment,
size_t *commentlen,
size_t commentmax)
99 if (*commentlen < commentmax)
100 comment[(*commentlen)++] = *s;
120static const char *
parse_quote(
const char *s,
char *token,
size_t *tokenlen,
size_t tokenmax)
124 if (*tokenlen < tokenmax)
125 token[*tokenlen] = *s;
131 if (*tokenlen < tokenmax)
132 token[*tokenlen] = *s;
151static const char *
next_token(
const char *s,
char *token,
size_t *tokenlen,
size_t tokenmax)
156 return parse_quote(s + 1, token, tokenlen, tokenmax);
159 if (*tokenlen < tokenmax)
160 token[(*tokenlen)++] = *s;
167 if (*tokenlen < tokenmax)
168 token[(*tokenlen)++] = *s;
199 char *
mailbox,
size_t *mailboxlen,
200 size_t mailboxmax,
char *comment,
201 size_t *commentlen,
size_t commentmax)
203 const char *ps = NULL;
211 if (!strchr(nonspecial, *s) &&
is_special(*s))
216 if (*commentlen && (*commentlen < commentmax))
217 comment[(*commentlen)++] =
' ';
218 ps =
next_token(s, comment, commentlen, commentmax);
243static const char *
parse_address(
const char *s,
char *token,
size_t *tokenlen,
244 size_t tokenmax,
char *comment,
size_t *commentlen,
245 size_t commentmax,
struct Address *addr)
248 commentlen, commentmax);
254 if (*tokenlen < tokenmax)
255 token[(*tokenlen)++] =
'@';
257 commentlen, commentmax);
284 size_t commentmax,
struct Address *addr)
286 char token[1024] = { 0 };
294 while (s && (*s ==
'@'))
296 if (tokenlen < (
sizeof(token) - 1))
297 token[tokenlen++] =
'@';
299 sizeof(token) - 1, comment, commentlen, commentmax);
301 if (!s || (*s !=
':'))
307 if (tokenlen < (
sizeof(token) - 1))
308 token[tokenlen++] =
':';
312 s =
parse_address(s, token, &tokenlen,
sizeof(token) - 1, comment, commentlen,
340 size_t commentmax,
struct Address *addr)
342 char token[1024] = { 0 };
345 s =
parse_address(s, token, &tokenlen,
sizeof(token) - 1, comment, commentlen,
347 if (s && *s && (*s !=
',') && (*s !=
';'))
365 char *comment,
size_t *commentlen,
size_t commentmax)
422 struct Address *a = NULL, *tmp = NULL;
464 char comment[1024], phrase[1024];
465 size_t phraselen = 0, commentlen = 0;
480 if (
add_addrspec(al, phrase, comment, &commentlen,
sizeof(comment) - 1))
485 else if (commentlen != 0)
507 if ((commentlen != 0) && (commentlen < (
sizeof(comment) - 1)))
508 comment[commentlen++] =
' ';
509 s =
next_token(s, comment, &commentlen,
sizeof(comment) - 1);
518 if ((phraselen != 0) && (phraselen < (
sizeof(phrase) - 1)))
519 phrase[phraselen++] =
' ';
520 s =
parse_quote(s + 1, phrase, &phraselen,
sizeof(phrase) - 1);
561 if ((phraselen != 0) && (phraselen < (
sizeof(phrase) - 1)) && ws_pending)
562 phrase[phraselen++] =
' ';
566 if (*s && (phraselen < (
sizeof(phrase) - 1)))
568 phrase[phraselen++] = *s;
572 s =
next_token(s, phrase, &phraselen,
sizeof(phrase) - 1);
589 if (
add_addrspec(al, phrase, comment, &commentlen,
sizeof(comment) - 1))
594 else if (commentlen != 0)
618 if (!s || (*s ==
'\0'))
624 if (!strpbrk(s,
"\"<>():;,\\"))
628 while ((r = strtok(r,
" \t")))
652 if (!al || !host || (*host ==
'\0'))
661 sprintf(p,
"%s@%s", a->
mailbox, host);
681void mutt_addr_cat(
char *buf,
size_t buflen,
const char *value,
const char *specials)
683 if (!buf || !value || !specials)
686 if (strpbrk(value, specials))
688 char tmp[256] = { 0 };
690 size_t tmplen =
sizeof(tmp) - 3;
693 for (; *value && (tmplen > 1); value++)
695 if ((*value ==
'\\') || (*value ==
'"'))
787 if (!msgid || (*msgid ==
'\0'))
793 if ((msgid[0] !=
'<') || (msgid[l - 1] !=
'>'))
795 if (!(strrchr(msgid,
'@')))
799 for (
size_t i = 0; i < l; i++)
800 if ((
unsigned char) msgid[i] > 127)
816 return !(ala || alb);
834 return !(ana || anb);
883 if (!needle || !haystack)
931 if (!mbox || !user || !domain)
934 char *ptr = strchr(mbox,
'@');
937 if (!ptr || (ptr == mbox) || (ptr[1] ==
'\0'))
991 char *user = NULL, *domain = NULL;
992 static char *buf = NULL;
1009 FREE(&local_mailbox);
1038 for (
const char *pc = addr->
personal; *pc; pc++)
1040 if ((*pc ==
'"') || (*pc ==
'\\'))
1101 bool display,
const char *header,
int cols)
1112 bool in_group =
false;
1168 struct Buffer *buf,
const char *header)
1204 struct Buffer buf = { 0 };
1247 char *domain = NULL;
1287 char *domain = NULL;
1329 char *domain = NULL;
1413 struct Address *aa = NULL, *ab = NULL, *tmp = NULL;
1484 if ((
unsigned char) *str & (1 << 7))
static bool addr_is_intl(const struct Address *a)
Does the Address have IDN components.
struct Address * mutt_addr_create(const char *personal, const char *mailbox)
Create and populate a new Address.
static bool add_addrspec(struct AddressList *al, const char *phrase, char *comment, size_t *commentlen, size_t commentmax)
Parse an email address and add an Address to a list.
static const char * parse_addr_spec(const char *s, char *comment, size_t *commentlen, size_t commentmax, struct Address *addr)
Parse an email address.
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
static int addr_mbox_to_udomain(const char *mbox, char **user, char **domain)
Split a mailbox name into user and domain.
static bool addr_is_local(const struct Address *a)
Does the Address have NO IDN components.
static const char * parse_address(const char *s, char *token, size_t *tokenlen, size_t tokenmax, char *comment, size_t *commentlen, size_t commentmax, struct Address *addr)
Extract an email address.
bool mutt_addrlist_equal(const struct AddressList *ala, const struct AddressList *alb)
Compare two Address lists for equality.
static const char * parse_route_addr(const char *s, char *comment, size_t *commentlen, size_t commentmax, struct Address *addr)
Parse an email addresses.
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
static const char * parse_mailboxdomain(const char *s, const char *nonspecial, char *mailbox, size_t *mailboxlen, size_t mailboxmax, char *comment, size_t *commentlen, size_t commentmax)
Extract part of an email address (and a comment)
static const char * next_token(const char *s, char *token, size_t *tokenlen, size_t tokenmax)
Find the next word, skipping quoted and parenthesised text.
size_t mutt_addrlist_write_list(const struct AddressList *al, struct ListHead *list)
Write Addresses to a List.
void mutt_addr_free(struct Address **ptr)
Free a single Address.
bool mutt_addr_valid_msgid(const char *msgid)
Is this a valid Message ID?
static void addr_set_intl(struct Address *a, char *intl_mailbox)
Mark an Address as having IDN components.
size_t mutt_addr_write(struct Buffer *buf, struct Address *addr, bool display)
Write a single Address to a buffer.
const char *const AddressErrors[]
Messages for the error codes in AddressError.
static void addr_set_local(struct Address *a, char *local_mailbox)
Mark an Address as having NO IDN components.
bool mutt_addrlist_uses_unicode(const struct AddressList *al)
Do any of a list of addresses use Unicode characters.
void mutt_addr_cat(char *buf, size_t buflen, const char *value, const char *specials)
Copy a string and wrap it in quotes if it contains special characters.
bool mutt_addr_cmp(const struct Address *a, const struct Address *b)
Compare two e-mail addresses.
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
size_t mutt_addrlist_write_wrap(const struct AddressList *al, struct Buffer *buf, const char *header)
Write an AddressList to a buffer, perform line wrapping.
struct Address * mutt_addr_new(void)
Create a new Address.
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
bool mutt_addr_uses_unicode(const char *str)
Does this address use Unicode character.
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
size_t addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display, const char *header, int cols)
Write an AddressList to a buffer, optionally perform line wrapping and display conversion.
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
const char AddressSpecials[]
Characters with special meaning for email addresses.
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
void mutt_addrlist_remove_xrefs(const struct AddressList *a, struct AddressList *b)
Remove cross-references.
int mutt_addrlist_count_recips(const struct AddressList *al)
Count the number of Addresses with valid recipients.
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
void mutt_addrlist_prepend(struct AddressList *al, struct Address *a)
Prepend an Address to an AddressList.
static const char * parse_comment(const char *s, char *comment, size_t *commentlen, size_t commentmax)
Extract a comment (parenthesised string)
void mutt_addrlist_write_file(const struct AddressList *al, FILE *fp, const char *header)
Wrapper for mutt_write_address()
#define is_special(ch)
Is this character special to an email address?
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
bool mutt_addr_to_intl(struct Address *a)
Convert an Address to Punycode.
int mutt_addrlist_remove(struct AddressList *al, const char *mailbox)
Remove an Address from a list.
bool mutt_addrlist_search(const struct AddressList *haystack, const struct Address *needle)
Search for an e-mail address in a list.
static const char * parse_quote(const char *s, char *token, size_t *tokenlen, size_t tokenmax)
Extract a quoted string.
const char * mutt_addr_for_display(const struct Address *a)
Convert an Address for display purposes.
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
AddressError
Possible values for AddressError.
@ ADDR_ERR_BAD_ROUTE
Bad route.
@ ADDR_ERR_BAD_ROUTE_ADDR
Bad route address.
@ ADDR_ERR_BAD_ADDR_SPEC
Bad address specifier.
@ ADDR_ERR_MISMATCH_PAREN
Mismatched parentheses.
@ ADDR_ERR_MISMATCH_QUOTE
Mismatches quotes.
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
size_t mutt_buffer_insert(struct Buffer *buf, size_t offset, const char *s)
Add a string in the middle of a buffer.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Type representing an email address.
#define mutt_debug(LEVEL,...)
Handling of international domain names.
#define MI_MAY_BE_IRREVERSIBLE
char * mutt_idna_local_to_intl(const char *user, const char *domain)
Convert an email's domain to Punycode.
char * mutt_idna_intl_to_local(const char *user, const char *domain, uint8_t flags)
Convert an email's domain from Punycode.
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
@ LL_DEBUG2
Log at debug level 2.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Convenience wrapper for the library headers.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
char * mutt_str_dup(const char *str)
Copy a string, safely.
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
#define TAILQ_FOREACH(var, head, field)
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_FIRST(head)
#define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_NEXT(elm, field)
#define TAILQ_EMPTY(head)
#define TAILQ_LAST(head, headname)
#define TAILQ_INSERT_HEAD(head, elm, field)
#define terminate_string(str, strlen, buflen)
#define terminate_buffer(str, strlen)
bool intl_checked
Checked for IDN?
char * mailbox
Mailbox and host address.
bool is_intl
International Domain Name.
char * personal
Real name of address.
String manipulation buffer.