1 |
/* ============================================================================ |
2 |
* Douglas Thrift's Web Contact License |
3 |
* |
4 |
* Copyright (C) 2002, Douglas Thrift. All Rights Reserved. |
5 |
* |
6 |
* Redistribution and use in source and binary forms, with or without |
7 |
* modification, are permitted provided that the following conditions are met: |
8 |
* |
9 |
* 1. Redistributions of source code must retain the above copyright notice, |
10 |
* this list of conditions and the following disclaimer. |
11 |
* |
12 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
13 |
* this list of conditions and the following disclaimer in the documentation |
14 |
* and/or other materials provided with the distribution. |
15 |
* |
16 |
* 3. The end-user documentation included with the redistribution, if any, must |
17 |
* include the following acknowledgment: |
18 |
* |
19 |
* "This product includes software developed by Douglas Thrift |
20 |
* (http://computers.douglasthrift.net/webcontact.html)." |
21 |
* |
22 |
* Alternately, this acknowledgment may appear in the software itself, if |
23 |
* and wherever such third-party acknowledgments normally appear. |
24 |
* |
25 |
* 4. The names "Douglas Thrift" and "Douglas Thrift's Web Contact" must not be |
26 |
* used to endorse or promote products derived from this software without |
27 |
* specific prior written permission. For written permission, please visit |
28 |
* http://www.douglasthrift.net/contact.html for contact information. |
29 |
* |
30 |
* 5. Products derived from this software may not be called "Douglas Thrift's |
31 |
* Web Contact", nor may "Douglas Thrift's Web Contact" appear in their |
32 |
* name, without prior written permission. |
33 |
* |
34 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
35 |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
36 |
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
37 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
38 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
39 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
40 |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
41 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
42 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
43 |
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
44 |
* ============================================================================ |
45 |
*/ |
46 |
// Windows XP FAQ Poll |
47 |
// |
48 |
// Douglas Thrift |
49 |
// |
50 |
// Account.cpp |
51 |
|
52 |
#include "Account.h" |
53 |
|
54 |
istream& operator>>(istream& is, Account& account) |
55 |
{ |
56 |
string line; |
57 |
getline(is, line); |
58 |
if (line == "<account>") |
59 |
{ |
60 |
do |
61 |
{ |
62 |
getline(is, line); |
63 |
if (line.find(" <host>") == 0) |
64 |
{ |
65 |
unsigned start = line.find("<host>") + 6; |
66 |
unsigned finish = line.find("</host>", start); |
67 |
|
68 |
string host = line.substr(start, finish - start); |
69 |
|
70 |
entities(host, "<", '<'); |
71 |
entities(host, ">", '>'); |
72 |
entities(host, "&", '&'); |
73 |
|
74 |
account.setHost(host); |
75 |
} |
76 |
else if (line.find(" <port>") == 0) |
77 |
{ |
78 |
unsigned start = line.find("<port>") + 6; |
79 |
unsigned finish = line.find("</port>", start); |
80 |
|
81 |
string port = line.substr(start, finish - start); |
82 |
|
83 |
account.setPort(strtoul(port.c_str(), 0, 0)); |
84 |
} |
85 |
else if (line.find(" <login>") == 0) |
86 |
{ |
87 |
unsigned start = line.find("<login>") + 7; |
88 |
unsigned finish = line.find("</login>", start); |
89 |
|
90 |
string login = line.substr(start, finish - start); |
91 |
|
92 |
entities(login, "<", '<'); |
93 |
entities(login, ">", '>'); |
94 |
entities(login, "&", '&'); |
95 |
|
96 |
account.setLogin(login); |
97 |
} |
98 |
else if (line.find(" <name>") == 0) |
99 |
{ |
100 |
unsigned start = line.find("<name>") + 6; |
101 |
unsigned finish = line.find("</name>", start); |
102 |
|
103 |
string name = line.substr(start, finish - start); |
104 |
|
105 |
entities(name, "<", '<'); |
106 |
entities(name, ">", '>'); |
107 |
entities(name, "&", '&'); |
108 |
|
109 |
account.setName(name); |
110 |
} |
111 |
else if (line.find(" <email>") == 0) |
112 |
{ |
113 |
unsigned start = line.find("<email>") + 7; |
114 |
unsigned finish = line.find("</email>", start); |
115 |
|
116 |
string email = line.substr(start, finish - start); |
117 |
|
118 |
entities(email, "<", '<'); |
119 |
entities(email, ">", '>'); |
120 |
entities(email, "&", '&'); |
121 |
|
122 |
account.setEmail(email); |
123 |
} |
124 |
else if (line.find(" <password>") == 0) |
125 |
{ |
126 |
unsigned start = line.find("<password>") + 10; |
127 |
unsigned finish = line.find("</password>", start); |
128 |
|
129 |
string password = line.substr(start, finish - start); |
130 |
|
131 |
entities(password, "<", '<'); |
132 |
entities(password, ">", '>'); |
133 |
entities(password, "&", '&'); |
134 |
|
135 |
account.setPassword(password); |
136 |
} |
137 |
else if (line.find(" <mailbox>") == 0) |
138 |
{ |
139 |
unsigned start = line.find("<mailbox>") + 9; |
140 |
unsigned finish = line.find("</mailbox>", start); |
141 |
|
142 |
string mailbox = line.substr(start, finish - start); |
143 |
|
144 |
entities(mailbox, "<", '<'); |
145 |
entities(mailbox, ">", '>'); |
146 |
entities(mailbox, "&", '&'); |
147 |
|
148 |
account.setMailbox(mailbox); |
149 |
} |
150 |
} |
151 |
while (line != "</account>"); |
152 |
} |
153 |
|
154 |
return is; |
155 |
} |
156 |
|
157 |
ostream& operator<<(ostream& os, Account& account) |
158 |
{ |
159 |
string host = account.getHost(); |
160 |
|
161 |
entities(host, '&', "&"); |
162 |
entities(host, '<', "<"); |
163 |
entities(host, '>', ">"); |
164 |
|
165 |
os << "<account>\n" << " <host>" << host << "</host>\n"; |
166 |
|
167 |
if (account.getPort() != 143) |
168 |
{ |
169 |
os << " <port>" << account.getPort() << "</port>\n"; |
170 |
} |
171 |
|
172 |
string login = account.getLogin(); |
173 |
|
174 |
entities(login, '&', "&"); |
175 |
entities(login, '<', "<"); |
176 |
entities(login, '>', ">"); |
177 |
|
178 |
os << " <login>" << login << "</login>\n"; |
179 |
|
180 |
string name = account.getName(); |
181 |
|
182 |
entities(name, '&', "&"); |
183 |
entities(name, '<', "<"); |
184 |
entities(name, '>', ">"); |
185 |
|
186 |
os << " <name>" << name << "</name>\n"; |
187 |
|
188 |
string email = account.getEmail(); |
189 |
|
190 |
entities(email, '&', "&"); |
191 |
entities(email, '<', "<"); |
192 |
entities(email, '>', ">"); |
193 |
|
194 |
os << " <email>" << email << "</email>\n"; |
195 |
|
196 |
if (account.getPassword() != "") |
197 |
{ |
198 |
string password = account.getPassword(); |
199 |
|
200 |
entities(password, '&', "&"); |
201 |
entities(password, '<', "<"); |
202 |
entities(password, '>', ">"); |
203 |
|
204 |
os << " <password>" << password << "</password>\n"; |
205 |
} |
206 |
|
207 |
if (account.getMailbox() != "INBOX") |
208 |
{ |
209 |
string mailbox = account.getMailbox(); |
210 |
|
211 |
entities(mailbox, '&', "&"); |
212 |
entities(mailbox, '<', "<"); |
213 |
entities(mailbox, '>', ">"); |
214 |
|
215 |
os << " <mailbox>" << mailbox << "</mailbox>\n"; |
216 |
} |
217 |
|
218 |
os << "</account>"; |
219 |
|
220 |
return os; |
221 |
} |