| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
 | /*
** Copyright 2002-20011, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_rfcaddr_h
#define libmail_rfcaddr_h
#include "libmail_config.h"
#include "unicode/courier-unicode.h"
#include "namespace.H"
#include <stdlib.h>
#include <vector>
#include <string>
//
// An RFC 2822 address, a name and user@domain.
//
LIBMAIL_START
class address {
protected:
	std::string name;
	std::string addr;
public:
	std::string getName() const { return name; }
	std::string getAddr() const { return addr; }
	virtual void setName(std::string s);
	virtual void setAddr(std::string a);
	// If addr.size() == 0 this is the obsolete rfc 822
	// group list notation, and name is either ";" or "name:"
	address(std::string n, std::string a);
	virtual ~address();
	// Convert myself to "name" <addr> format.
	std::string toString() const;
	//
	// Create an RFC 2822 address header, from a vector of addresss.
	//
	template<class T>
	static std::string toString(std::string hdr, // Name:
				    const std::vector<T> &h,
				    size_t w=76); // Max length of lines.
	//
	// Create a vector of addresses from a string
	//
	template<class T> static bool fromString(std::string addresses,
						 std::vector<T> &h,
						 size_t &errIndex);
	// Addresses are appended to h
	// Returns false if memory allocation failed or addresses is
	// syntactically invalid.  errIndex points where in addresses the
	// syntax error is (or is string::npos if memory allocation failed)
	std::string getCanonAddress() const;
	// Return addr with domain portion converted to lowercase
	bool operator==(const address &) const;
	// Compare the addr portions only, ignoring domain case
	bool operator!=(const address &a) const
	{
		return !operator==(a);
	}
};
// INPROGRESS: slowly migrate to automatic MIME encoding of names.
//
// A subclass of address that MIME-decodes the name portion of the address,
// and IDN-decodes the hostname portion of the address (if libidn is available).
//
// emailAddress transparently casts to mail::address, importing/exporting
// the name and address in its decoded form.
class emailAddress : public address {
	// The name field as unicode characters
	std::vector<unicode_char> decodedName;
	//! The address field, with the hostname portion decoded
	std::vector<unicode_char> decodedAddr;
	void decode();
public:
	emailAddress();
	emailAddress(const address &);
	virtual ~emailAddress();
	std::string getDisplayName(const std::string &charset,
				   bool &errflag) const
	{
		return mail::iconvert::convert(decodedName, charset, errflag);
	}
	std::string getDisplayAddr(const std::string &charset,
				   bool &errflag) const
	{
		return mail::iconvert::convert(decodedAddr, charset, errflag);
	}
	std::string getDisplayName(const std::string &charset) const
	{
		bool dummy;
		return getDisplayName(charset, dummy);
	}
	std::string getDisplayAddr(const std::string &charset) const
	{
		bool dummy;
		return getDisplayAddr(charset, dummy);
	}
	std::string setDisplayName(const std::string &s,
				   const std::string &charset);
	std::string setDisplayAddr(const std::string &a,
				   const std::string &charset);
	virtual void setName(std::string s);
	virtual void setAddr(std::string s);
	bool operator==(const address &a) const
	{
		return mail::address::operator==(a);
	}
	bool operator!=(const address &a) const
	{
		return !operator==(a);
	}
};
LIBMAIL_END
#endif
 |