1MAIL::ADDRESS(3x) Extra/Miscellaneous objects/methods MAIL::ADDRESS(3x)
2
3
4
6 mail::address - An E-mail address
7
9 #include <libmail/rfcaddr.H>
10
11 mail::address address("John Smith", "johnsmith@example.com");
12
13 std::string addr=address.getAddr();
14 std::string name=address.getName();
15
16 address.setAddr(addr);
17 address.setName(name);
18
19 std::string str=address.toString();
20
21 std::vector<mail::address> addressList;
22
23 std::string header= mail::address::toString("From: ", addressList,
24 size_t width=76);
25
26 size_t errorIndex;
27
28 bool error=mail::address::fromString(std::string addresses,
29 addressList,
30 errorIndex);
31
32 std::string stdAddr=address.getCanonAddress();
33
34 mail::address addr1, addr2;
35
36 bool same= addr1 == addr2;
37 bool notsame= addr1 != addr2;
38
40 mail::address represents a single E-mail address. An E-mail address
41 consists of the recipient's name, and the actual address in the format
42 of user@domain. The name and the address components may be accessed or
43 changed by getName(), getAddr(), setName() and setAddr() methods.
44
45 Note:
46
47 mail::emailAddress would be a more appropriate class for most
48 situations. The name component used by getName() and setName()
49 methods is the Internet-format, MIME-encoded name.
50 mail::emailAddress is a subclass of mail::address, and provides
51 more convenient methods for working with the name component of
52 an E-mail address.
53
54 The toString and fromString methods, defined below, will take a
55 vector of either mail::emailAddress or mail::address objects,
56 and in all other ways both classes are freely interchangable,
57 and may be converted to one another.
58
59 The toString method converts an address to a text string formatted as
60 "name <user@domain>". A second toString function creates an E-mail
61 header that contains a comma-separated list of E-mail addresses. The
62 first parameter must be the header's name (with a trailing space char‐
63 acter); the second parameter is a reference to a vector of
64 mail::address objects. An optional third parameter sets the maximum
65 line width; the text string returned by toString will have newline
66 characters, if necessary to make sure that each line is shorter than
67 the specified maximum.
68
69 fromString does the opposite: it converts the contents of an E-mail
70 header to an array of mail::address objects. The first parameter is
71 the E-mail header's contents (without Header-Name:). The second param‐
72 eter is a reference to a vector of mail::address objects. fromString
73 returns false if a fatal error has occured (out of memory, or something
74 else). errorIndex is normally set to string::npos. If the header can‐
75 not be parsed; errorIndex is set to the index of the character in
76 addresses where a syntax error was found (the header is still parsed,
77 and any recognizable addresses are still saved in addressList).
78
79 addressList should be empty. Otherwise the addresses are appended to
80 addressList's existing contents.
81
82 COMPARING ADDRESSES
83 The domain part of an E-mail address is case insensitive, however the
84 user part of an E-mail address is not case insensitive. It is up to
85 each individual domain whether or not the user part is case sensitive,
86 or not. Since it is not possible to determine whether user is case
87 sensitive; the getCanonAddress method returns the E-mail address as
88 user@domain, with only the domain part converted to lowercase.
89
90 The object also defines the equality and non-equality operators, which
91 compare the address portion of two mail::address objects (the name por‐
92 tions are ignored), with the domain part of each domain being case
93 insensitive
94
96 mail::emailAddress(3x), mail::envelope(3x).
97
98
99
100 10 April 2006 MAIL::ADDRESS(3x)