Representation of an email address. More...
#include "config.h"
#include <stdbool.h>
#include <stdint.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, mask) ((ch) >= 32 && (ch) < 96 && ((mask >> ((ch) - 32)) & 1)) |
Is this character special to an email address? | |
#define | ADDRESS_SPECIAL_MASK 0x380000015c005304ULL |
AddressSpecials, for is_special() | |
#define | USER_SPECIAL_MASK 0x280000015c001200ULL |
AddressSpecials except " ( . | |
#define | DOMAIN_SPECIAL_MASK 0x000000015c001204ULL |
AddressSpecials except ( . | |
#define | ROUTE_SPECIAL_MASK 0x000000015c000204ULL |
AddressSpecials except ( , . | |
Functions | |
static const char * | parse_comment (const char *s, char *comment, size_t *commentlen, size_t commentmax) |
Extract a comment (parenthesised string) | |
static const char * | parse_quote (const char *s, char *token, size_t *tokenlen, size_t tokenmax) |
Extract a quoted string. | |
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. | |
static const char * | parse_mailboxdomain (const char *s, uint64_t special_mask, 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 * | 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. | |
static const char * | parse_route_addr (const char *s, char *comment, size_t *commentlen, size_t commentmax, struct Address *addr) |
Parse an email addresses. | |
static const char * | parse_addr_spec (const char *s, char *comment, size_t *commentlen, size_t commentmax, struct Address *addr) |
Parse an email 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. | |
struct Address * | mutt_addr_new (void) |
Create a new Address. | |
struct Address * | mutt_addr_create (const char *personal, const char *mailbox) |
Create and populate a new Address. | |
int | mutt_addrlist_remove (struct AddressList *al, const char *mailbox) |
Remove an Address from a list. | |
void | mutt_addr_free (struct Address **ptr) |
Free a single Address. | |
int | mutt_addrlist_parse (struct AddressList *al, const char *s) |
Parse a list of email addresses. | |
int | mutt_addrlist_parse2 (struct AddressList *al, const char *s) |
Parse a list of email addresses. | |
void | mutt_addrlist_qualify (struct AddressList *al, const char *host) |
Expand local names in an Address list using a hostname. | |
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. | |
struct Address * | mutt_addr_copy (const struct Address *addr) |
Copy the real address. | |
void | mutt_addrlist_copy (struct AddressList *dst, const struct AddressList *src, bool prune) |
Copy a list of addresses into another list. | |
bool | mutt_addr_valid_msgid (const char *msgid) |
Is this a valid Message ID? | |
bool | mutt_addrlist_equal (const struct AddressList *ala, const struct AddressList *alb) |
Compare two Address lists for equality. | |
int | mutt_addrlist_count_recips (const struct AddressList *al) |
Count the number of Addresses with valid recipients. | |
bool | mutt_addr_cmp (const struct Address *a, const struct Address *b) |
Compare two e-mail addresses. | |
bool | mutt_addrlist_search (const struct AddressList *haystack, const struct Address *needle) |
Search for an e-mail address in a list. | |
static bool | addr_is_intl (const struct Address *a) |
Does the Address have IDN components. | |
static bool | addr_is_local (const struct Address *a) |
Does the Address have NO IDN components. | |
static int | addr_mbox_to_udomain (const char *mbox, char **user, char **domain) |
Split a mailbox name into user and domain. | |
static void | addr_set_intl (struct Address *a, char *intl_mailbox) |
Mark an Address as having IDN components. | |
static void | addr_set_local (struct Address *a, char *local_mailbox) |
Mark an Address as having NO IDN components. | |
const char * | mutt_addr_for_display (const struct Address *a) |
Convert an Address for display purposes. | |
size_t | mutt_addr_write (struct Buffer *buf, struct Address *addr, bool display) |
Write a single Address to a buffer. | |
static 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. | |
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. | |
size_t | mutt_addrlist_write (const struct AddressList *al, struct Buffer *buf, bool display) |
Write an Address to a buffer. | |
size_t | mutt_addrlist_write_list (const struct AddressList *al, struct ListHead *list) |
Write Addresses to a List. | |
void | mutt_addrlist_write_file (const struct AddressList *al, FILE *fp, const char *header) |
Wrapper for mutt_write_address() | |
bool | mutt_addr_to_intl (struct Address *a) |
Convert an Address to Punycode. | |
int | mutt_addrlist_to_intl (struct AddressList *al, char **err) |
Convert an Address list to Punycode. | |
bool | mutt_addr_to_local (struct Address *a) |
Convert an Address from Punycode. | |
int | mutt_addrlist_to_local (struct AddressList *al) |
Convert an Address list from Punycode. | |
void | mutt_addrlist_dedupe (struct AddressList *al) |
Remove duplicate addresses. | |
void | mutt_addrlist_remove_xrefs (const struct AddressList *a, struct AddressList *b) |
Remove cross-references. | |
void | mutt_addrlist_clear (struct AddressList *al) |
Unlink and free all Address in an AddressList. | |
void | mutt_addrlist_append (struct AddressList *al, struct Address *a) |
Append an Address to an AddressList. | |
void | mutt_addrlist_prepend (struct AddressList *al, struct Address *a) |
Prepend an Address to an AddressList. | |
bool | mutt_addr_uses_unicode (const char *str) |
Does this address use Unicode character. | |
bool | mutt_addrlist_uses_unicode (const struct AddressList *al) |
Do any of a list of addresses use Unicode characters. | |
Variables | |
const char | AddressSpecials [] = "\"(),.:;<>@[\\]" |
Characters with special meaning for email addresses. | |
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, | |
mask | |||
) | ((ch) >= 32 && (ch) < 96 && ((mask >> ((ch) - 32)) & 1)) |
Is this character special to an email address?
ch | Character |
mask | Bitmask of characters 32-95 that are special (others are always zero) |
Character bitmasks
The four bitmasks below are used for matching characters at speed, instead of using strchr(3)
.
To generate them, consider the value of each character, e.g. ,
== 44. Now set the 44th bit of a unsigned long long
(presumed to be 64 bits), i.e., 1ULL << 44. Repeat for each character.
To test a character, say (
(40), we check if the 40th bit is set in the mask.
The characters we want to test, AddressSpecials, range in value between 34 and 93 (inclusive). This is too large for an integer type, so we subtract 32 to bring the values down to 2 to 61.
#define ADDRESS_SPECIAL_MASK 0x380000015c005304ULL |
#define USER_SPECIAL_MASK 0x280000015c001200ULL |
#define DOMAIN_SPECIAL_MASK 0x000000015c001204ULL |
#define ROUTE_SPECIAL_MASK 0x000000015c000204ULL |
|
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 91 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 134 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 166 of file address.c.
|
static |
Extract part of an email address (and a comment)
[in] | s | String to parse |
[in] | special_mask | Characters that are special (see is_special()) |
[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 213 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 260 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 300 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 356 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 380 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 401 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 414 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 435 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 480 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 644 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 680 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 708 of file address.c.
Copy the real address.
addr | Address to copy |
ptr | New Address |
Definition at line 745 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 765 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 792 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 840 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 872 of file address.c.
Compare two e-mail addresses.
true | They are equivalent |
Definition at line 892 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 909 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 957 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 1012 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 1050 of file address.c.
|
static |
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 1126 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 |
Definition at line 1189 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 1206 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 1217 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 1248 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 1263 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 1293 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 1340 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 1378 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 1397 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 1433 of file address.c.
void mutt_addrlist_clear | ( | struct AddressList * | al | ) |
Unlink and free all Address in an AddressList.
al | AddressList |
Definition at line 1460 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 1480 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 1491 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 1502 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 1522 of file address.c.