Representation of an email address. More...
#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "mutt/lib.h"
#include "address.h"
#include "idna2.h"
Go to the source code of this file.
Macros | |
#define | is_special(ch) strchr(AddressSpecials, ch) |
Is this character special to an email address? More... | |
Functions | |
static const char * | parse_comment (const char *s, char *comment, size_t *commentlen, size_t commentmax) |
Extract a comment (parenthesised string) More... | |
static const char * | parse_quote (const char *s, char *token, size_t *tokenlen, size_t tokenmax) |
Extract a quoted string. More... | |
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. More... | |
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) More... | |
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. More... | |
static const char * | parse_route_addr (const char *s, char *comment, size_t *commentlen, size_t commentmax, struct Address *addr) |
Parse an email addresses. More... | |
static const char * | parse_addr_spec (const char *s, char *comment, size_t *commentlen, size_t commentmax, struct Address *addr) |
Parse an email address. More... | |
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. More... | |
struct Address * | mutt_addr_new (void) |
Create a new Address. More... | |
struct Address * | mutt_addr_create (const char *personal, const char *mailbox) |
Create and populate a new Address. More... | |
int | mutt_addrlist_remove (struct AddressList *al, const char *mailbox) |
Remove an Address from a list. More... | |
void | mutt_addr_free (struct Address **ptr) |
Free a single Address. More... | |
int | mutt_addrlist_parse (struct AddressList *al, const char *s) |
Parse a list of email addresses. More... | |
int | mutt_addrlist_parse2 (struct AddressList *al, const char *s) |
Parse a list of email addresses. More... | |
void | mutt_addrlist_qualify (struct AddressList *al, const char *host) |
Expand local names in an Address list using a hostname. More... | |
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. More... | |
struct Address * | mutt_addr_copy (const struct Address *addr) |
Copy the real address. More... | |
void | mutt_addrlist_copy (struct AddressList *dst, const struct AddressList *src, bool prune) |
Copy a list of addresses into another list. More... | |
bool | mutt_addr_valid_msgid (const char *msgid) |
Is this a valid Message ID? More... | |
bool | mutt_addrlist_equal (const struct AddressList *ala, const struct AddressList *alb) |
Compare two Address lists for equality. More... | |
int | mutt_addrlist_count_recips (const struct AddressList *al) |
Count the number of Addresses with valid recipients. More... | |
bool | mutt_addr_cmp (const struct Address *a, const struct Address *b) |
Compare two e-mail addresses. More... | |
bool | mutt_addrlist_search (const struct AddressList *haystack, const struct Address *needle) |
Search for an e-mail address in a list. More... | |
static bool | addr_is_intl (const struct Address *a) |
Does the Address have IDN components. More... | |
static bool | addr_is_local (const struct Address *a) |
Does the Address have NO IDN components. More... | |
static int | addr_mbox_to_udomain (const char *mbox, char **user, char **domain) |
Split a mailbox name into user and domain. More... | |
static void | addr_set_intl (struct Address *a, char *intl_mailbox) |
Mark an Address as having IDN components. More... | |
static void | addr_set_local (struct Address *a, char *local_mailbox) |
Mark an Address as having NO IDN components. More... | |
const char * | mutt_addr_for_display (const struct Address *a) |
Convert an Address for display purposes. More... | |
size_t | mutt_addr_write (struct Buffer *buf, struct Address *addr, bool display) |
Write a single Address to a buffer. More... | |
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. More... | |
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. More... | |
size_t | mutt_addrlist_write (const struct AddressList *al, struct Buffer *buf, bool display) |
Write an Address to a buffer. More... | |
size_t | mutt_addrlist_write_list (const struct AddressList *al, struct ListHead *list) |
Write Addresses to a List. More... | |
void | mutt_addrlist_write_file (const struct AddressList *al, FILE *fp, const char *header) |
Wrapper for mutt_write_address() More... | |
bool | mutt_addr_to_intl (struct Address *a) |
Convert an Address to Punycode. More... | |
int | mutt_addrlist_to_intl (struct AddressList *al, char **err) |
Convert an Address list to Punycode. More... | |
bool | mutt_addr_to_local (struct Address *a) |
Convert an Address from Punycode. More... | |
int | mutt_addrlist_to_local (struct AddressList *al) |
Convert an Address list from Punycode. More... | |
void | mutt_addrlist_dedupe (struct AddressList *al) |
Remove duplicate addresses. More... | |
void | mutt_addrlist_remove_xrefs (const struct AddressList *a, struct AddressList *b) |
Remove cross-references. More... | |
void | mutt_addrlist_clear (struct AddressList *al) |
Unlink and free all Address in an AddressList. More... | |
void | mutt_addrlist_append (struct AddressList *al, struct Address *a) |
Append an Address to an AddressList. More... | |
void | mutt_addrlist_prepend (struct AddressList *al, struct Address *a) |
Prepend an Address to an AddressList. More... | |
bool | mutt_addr_uses_unicode (const char *str) |
Does this address use Unicode character. More... | |
bool | mutt_addrlist_uses_unicode (const struct AddressList *al) |
Do any of a list of addresses use Unicode characters. More... | |
Variables | |
const char | AddressSpecials [] = "@.,:;<>[]\\\"()" |
Characters with special meaning for email addresses. More... | |
int | AddressError = 0 |
An out-of-band error code. More... | |
const char *const | AddressErrors [] |
Messages for the error codes in AddressError. More... | |
Representation of an email address.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file address.c.
#define is_special | ( | ch | ) | strchr(AddressSpecials, ch) |
|
static |
Extract a comment (parenthesised string)
[in] | s | String, just after the opening parenthesis |
[out] | comment | Buffer to store parenthesised string |
[out] | commentlen | Length of parenthesised string |
[in] | commentmax | Length of buffer |
ptr | First character after parenthesised string |
NULL | Error |
Definition at line 78 of file address.c.
|
static |
Extract a quoted string.
[in] | s | String, just after the opening quote mark |
[out] | token | Buffer to store quoted string |
[out] | tokenlen | Length of quoted string |
[in] | tokenmax | Length of buffer |
ptr | First character after quoted string |
NULL | Error |
Definition at line 120 of file address.c.
|
static |
Find the next word, skipping quoted and parenthesised text.
[in] | s | String to search |
[out] | token | Buffer for the token |
[out] | tokenlen | Length of the next token |
[in] | tokenmax | Length of the buffer |
ptr | First character after the next token |
Definition at line 151 of file address.c.
|
static |
Extract part of an email address (and a comment)
[in] | s | String to parse |
[in] | nonspecial | Specific characters that are valid |
[out] | mailbox | Buffer for email address |
[out] | mailboxlen | Length of saved email address |
[in] | mailboxmax | Length of mailbox buffer |
[out] | comment | Buffer for comment |
[out] | commentlen | Length of saved comment |
[in] | commentmax | Length of comment buffer |
ptr | First character after the email address part |
This will be called twice to parse an email address, first for the mailbox name, then for the domain name. Each part can also have a comment in ()
. The comment can be at the start or end of the mailbox or domain.
Examples:
The first call will return "john.doe" with optional comment, "comment". The second call will return "example.com" with optional comment, "comment".
Definition at line 198 of file address.c.
|
static |
Extract an email address.
[in] | s | String, just after the opening < |
[out] | token | Buffer for the email address |
[out] | tokenlen | Length of the email address |
[in] | tokenmax | Length of the email address buffer |
[out] | comment | Buffer for any comments |
[out] | commentlen | Length of any comments |
[in] | commentmax | Length of the comment buffer |
[in] | addr | Address to store the results |
ptr | The closing > of the email address |
NULL | Error |
Definition at line 243 of file address.c.
|
static |
Parse an email addresses.
[in] | s | String, just after the opening < |
[out] | comment | Buffer for any comments |
[out] | commentlen | Length of any comments |
[in] | commentmax | Length of the comments buffer |
[in] | addr | Address to store the details |
ptr | First character after the email address |
Definition at line 283 of file address.c.
|
static |
Parse an email address.
[in] | s | String to parse |
[out] | comment | Buffer for any comments |
[out] | commentlen | Length of any comments |
[in] | commentmax | Length of the comments buffer |
[in] | addr | Address to fill in |
ptr | First character after the email address |
Definition at line 339 of file address.c.
|
static |
Parse an email address and add an Address to a list.
[out] | al | Address list |
[in] | phrase | String to parse |
[out] | comment | Buffer for any comments |
[out] | commentlen | Length of any comments |
[in] | commentmax | Length of the comments buffer |
true | An address was successfully parsed and added |
Definition at line 364 of file address.c.
struct Address * mutt_addr_new | ( | void | ) |
Create a new Address.
ptr | Newly allocated Address |
Free the result with mutt_addr_free()
Definition at line 385 of file address.c.
struct Address * mutt_addr_create | ( | const char * | personal, |
const char * | mailbox | ||
) |
Create and populate a new Address.
[in] | personal | The personal name for the Address (can be NULL) |
[in] | mailbox | The mailbox for the Address (can be NULL) |
ptr | Newly allocated Address |
Definition at line 398 of file address.c.
int mutt_addrlist_remove | ( | struct AddressList * | al, |
const char * | mailbox | ||
) |
Remove an Address from a list.
[in,out] | al | AddressList |
[in] | mailbox | Email address to match |
0 | Success |
-1 | Error, or email not found |
Definition at line 413 of file address.c.
void mutt_addr_free | ( | struct Address ** | ptr | ) |
int mutt_addrlist_parse | ( | struct AddressList * | al, |
const char * | s | ||
) |
Parse a list of email addresses.
al | AddressList to append addresses |
s | String to parse |
num | Number of parsed addresses |
Definition at line 458 of file address.c.
int mutt_addrlist_parse2 | ( | struct AddressList * | al, |
const char * | s | ||
) |
Parse a list of email addresses.
al | Add to this List of Addresses |
s | String to parse |
num | Number of parsed addresses |
Simple email addresses (without any personal name or grouping) can be separated by whitespace or commas.
Definition at line 616 of file address.c.
void mutt_addrlist_qualify | ( | struct AddressList * | al, |
const char * | host | ||
) |
Expand local names in an Address list using a hostname.
al | Address list |
host | Hostname |
Any addresses containing a bare name will be expanded using the hostname. e.g. "john", "example.com" -> 'john@.nosp@m.exam.nosp@m.ple.c.nosp@m.om'. This function has no effect if host is NULL or the empty string.
Definition at line 650 of file address.c.
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.
buf | Buffer for the result |
buflen | Length of the result buffer |
value | String to copy |
specials | Characters to lookup |
This function copies the string in the "value" parameter in the buffer pointed to by "buf" parameter. If the input string contains any of the characters specified in the "specials" parameters, the output string is wrapped in double quoted. Additionally, any backslashes or quotes inside the input string are backslash-escaped.
Definition at line 681 of file address.c.
void mutt_addrlist_copy | ( | struct AddressList * | dst, |
const struct AddressList * | src, | ||
bool | prune | ||
) |
Copy a list of addresses into another list.
dst | Destination Address list |
src | Source Address list |
prune | Skip groups if there are more addresses |
Definition at line 737 of file address.c.
bool mutt_addr_valid_msgid | ( | const char * | msgid | ) |
Is this a valid Message ID?
msgid | Message ID |
true | It is a valid message ID |
Incomplete. Only used to thwart the APOP MD5 attack
Definition at line 764 of file address.c.
bool mutt_addrlist_equal | ( | const struct AddressList * | ala, |
const struct AddressList * | alb | ||
) |
Compare two Address lists for equality.
true | Address lists are strictly identical |
Definition at line 812 of file address.c.
int mutt_addrlist_count_recips | ( | const struct AddressList * | al | ) |
Count the number of Addresses with valid recipients.
al | Address list |
num | Number of valid Addresses |
An Address has a recipient if the mailbox is set and is not a group
Definition at line 844 of file address.c.
bool mutt_addrlist_search | ( | const struct AddressList * | haystack, |
const struct Address * | needle | ||
) |
Search for an e-mail address in a list.
true | The Address is in the list |
Definition at line 881 of file address.c.
|
static |
|
static |
|
static |
Split a mailbox name into user and domain.
[in] | mbox | Mailbox name to split |
[out] | user | User |
[out] | domain | Domain |
0 | Success |
-1 | Error |
Definition at line 929 of file address.c.
|
static |
|
static |
const char * mutt_addr_for_display | ( | const struct Address * | a | ) |
Convert an Address for display purposes.
a | Address to convert |
ptr | Address to display |
Definition at line 986 of file address.c.
Write a single Address to a buffer.
buf | Buffer for the Address |
addr | Address to display |
display | This address will be displayed to the user |
num | Length of the string written to buf |
If 'display' is set, then it doesn't matter if the transformation isn't reversible.
Definition at line 1024 of file address.c.
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.
al | AddressList to display |
buf | Buffer for the Address |
display | True if these addresses will be displayed to the user |
header | Header name; if present, addresses we be written after ": " |
cols | Max columns at which to wrap, disabled if -1 |
num | Length of the string written to buf |
If 'display' is set, then it doesn't matter if the transformation isn't reversible.
Definition at line 1100 of file address.c.
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.
al | AddressList to display |
buf | Buffer for the Address |
header | Header name; if present, addresses we be written after ": " |
num | Length of the string written to buf |
If 'display' is set, then it doesn't matter if the transformation isn't reversible.
Definition at line 1167 of file address.c.
size_t mutt_addrlist_write | ( | const struct AddressList * | al, |
struct Buffer * | buf, | ||
bool | display | ||
) |
Write an Address to a buffer.
al | AddressList to display |
buf | Buffer for the Address |
display | This address will be displayed to the user |
num | Length of the string written to buf |
If 'display' is set, then it doesn't matter if the transformation isn't reversible.
Definition at line 1184 of file address.c.
size_t mutt_addrlist_write_list | ( | const struct AddressList * | al, |
struct ListHead * | list | ||
) |
Write Addresses to a List.
al | AddressList to write |
list | List for the Addresses |
num | Number of addresses written |
Definition at line 1195 of file address.c.
void mutt_addrlist_write_file | ( | const struct AddressList * | al, |
FILE * | fp, | ||
const char * | header | ||
) |
Wrapper for mutt_write_address()
al | Address list |
fp | File to write to |
header | Header name; if present, addresses we be written after ": " |
So we can handle very large recipient lists without needing a huge temporary buffer in memory
Definition at line 1226 of file address.c.
bool mutt_addr_to_intl | ( | struct Address * | a | ) |
Convert an Address to Punycode.
a | Address to convert |
true | Success |
false | Otherwise |
Definition at line 1241 of file address.c.
int mutt_addrlist_to_intl | ( | struct AddressList * | al, |
char ** | err | ||
) |
Convert an Address list to Punycode.
[in] | al | Address list to modify |
[out] | err | Pointer for failed addresses |
0 | Success, all addresses converted |
-1 | Error, err will be set to the failed address |
Definition at line 1270 of file address.c.
bool mutt_addr_to_local | ( | struct Address * | a | ) |
Convert an Address from Punycode.
a | Address to convert |
true | Success |
false | Otherwise |
Definition at line 1316 of file address.c.
int mutt_addrlist_to_local | ( | struct AddressList * | al | ) |
Convert an Address list from Punycode.
al | Address list to modify |
0 | Always |
Definition at line 1353 of file address.c.
void mutt_addrlist_dedupe | ( | struct AddressList * | al | ) |
Remove duplicate addresses.
al | Address list to de-dupe |
Given a list of addresses, return a list of unique addresses
Definition at line 1372 of file address.c.
void mutt_addrlist_remove_xrefs | ( | const struct AddressList * | a, |
struct AddressList * | b | ||
) |
Remove cross-references.
a | Reference AddressList |
b | AddressLis to trim |
Remove addresses from "b" which are contained in "a"
Definition at line 1408 of file address.c.
void mutt_addrlist_clear | ( | struct AddressList * | al | ) |
Unlink and free all Address in an AddressList.
al | AddressList |
Definition at line 1435 of file address.c.
void mutt_addrlist_append | ( | struct AddressList * | al, |
struct Address * | a | ||
) |
Append an Address to an AddressList.
al | AddressList |
a | Address |
Definition at line 1455 of file address.c.
void mutt_addrlist_prepend | ( | struct AddressList * | al, |
struct Address * | a | ||
) |
Prepend an Address to an AddressList.
al | AddressList |
a | Address |
Definition at line 1466 of file address.c.
bool mutt_addr_uses_unicode | ( | const char * | str | ) |
Does this address use Unicode character.
str | Address string to check |
true | The string uses 8-bit characters |
Definition at line 1477 of file address.c.
bool mutt_addrlist_uses_unicode | ( | const struct AddressList * | al | ) |
Do any of a list of addresses use Unicode characters.
al | Address list to check |
true | Any use 8-bit characters |
Definition at line 1497 of file address.c.
const char AddressSpecials[] = "@.,:;<>[]\\\"()" |
int AddressError = 0 |
An out-of-band error code.
Many of the Address functions set this variable on error. Its values are defined in AddressError. Text for the errors can be looked up using AddressErrors.
const char* const AddressErrors[] |
Messages for the error codes in AddressError.
These must defined in the same order as enum AddressError.