pop3.cc
5.25 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2006-2007, 2009-2012, 2014-2016 Free Software
Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#include <cstdlib>
#include <mailutils/cpp/pop3.h>
using namespace mailutils;
//
// POP3
//
Pop3 :: Pop3 ()
{
int status = mu_pop3_create (&pop3);
if (status)
throw Exception ("Pop3::Pop3", status);
this->pStream = 0;
}
Pop3 :: Pop3 (const mu_pop3_t pop3)
{
if (pop3 == 0)
throw Exception ("Pop3::Pop3", EINVAL);
this->pop3 = pop3;
this->pStream = 0;
}
Pop3 :: ~Pop3 ()
{
mu_pop3_destroy (&pop3);
}
void
Pop3 :: set_carrier (const Stream& carrier)
{
int status = mu_pop3_set_carrier (pop3, carrier.stm);
if (status)
throw Exception ("Pop3::set_carrier", status);
this->pStream = (Stream*) &carrier;
}
Stream&
Pop3 :: get_carrier ()
{
return *pStream;
}
void
Pop3 :: connect ()
{
int status = mu_pop3_connect (pop3);
if (status)
throw Exception ("Pop3::connect", status);
}
void
Pop3 :: disconnect ()
{
int status = mu_pop3_disconnect (pop3);
if (status)
throw Exception ("Pop3::disconnect", status);
}
void
Pop3 :: set_timeout (int timeout)
{
int status = mu_pop3_set_timeout (pop3, timeout);
if (status)
throw Exception ("Pop3::set_timeout", status);
}
int
Pop3 :: get_timeout ()
{
int timeout;
int status = mu_pop3_get_timeout (pop3, &timeout);
if (status)
throw Exception ("Pop3::get_timeout", status);
return timeout;
}
void
Pop3 :: apop (const char* name, const char* digest)
{
int status = mu_pop3_apop (pop3, name, digest);
if (status)
throw Exception ("Pop3::apop", status);
}
void
Pop3 :: stls ()
{
int status = mu_pop3_stls (pop3);
if (status)
throw Exception ("Pop3::stls", status);
}
Iterator&
Pop3 :: capa (bool reread = false)
{
mu_iterator_t mu_itr;
int status = mu_pop3_capa (pop3, reread, &mu_itr);
if (status)
throw Exception ("Pop3::capa", status);
return *new Iterator (mu_itr);
}
void
Pop3 :: dele (unsigned int msgno)
{
int status = mu_pop3_dele (pop3, msgno);
if (status)
throw Exception ("Pop3::dele", status);
}
size_t
Pop3 :: list (unsigned int msgno)
{
size_t msg_octet;
int status = mu_pop3_list (pop3, msgno, &msg_octet);
if (status)
throw Exception ("Pop3::list", status);
return msg_octet;
}
Iterator&
Pop3 :: list_all ()
{
mu_iterator_t mu_itr;
int status = mu_pop3_list_all (pop3, &mu_itr);
if (status)
throw Exception ("Pop3::list_all", status);
return *new Iterator (mu_itr);
}
void
Pop3 :: noop ()
{
int status = mu_pop3_noop (pop3);
if (status)
throw Exception ("Pop3::noop", status);
}
void
Pop3 :: pass (const char* pass)
{
int status = mu_pop3_pass (pop3, pass);
if (status)
throw Exception ("Pop3::pass", status);
}
void
Pop3 :: quit ()
{
int status = mu_pop3_quit (pop3);
if (status)
throw Exception ("Pop3::quit", status);
}
Stream&
Pop3 :: retr (unsigned int msgno)
{
mu_stream_t c_stm;
int status = mu_pop3_retr (pop3, msgno, &c_stm);
if (status)
throw Exception ("Pop3::retr", status);
return *new Stream (c_stm);
}
void
Pop3 :: rset ()
{
int status = mu_pop3_rset (pop3);
if (status)
throw Exception ("Pop3::rset", status);
}
void
Pop3 :: stat (unsigned int* count, mu_off_t* octets)
{
int status = mu_pop3_stat (pop3, count, octets);
if (status)
throw Exception ("Pop3::stat", status);
}
Stream&
Pop3 :: top (unsigned int msgno, unsigned int lines)
{
mu_stream_t c_stm;
int status = mu_pop3_top (pop3, msgno, lines, &c_stm);
if (status)
throw Exception ("Pop3::top", status);
return *new Stream (c_stm);
}
std::string
Pop3 :: uidl (unsigned int msgno)
{
char *c_uidl = NULL;
int status = mu_pop3_uidl (pop3, msgno, &c_uidl);
if (status)
throw Exception ("Pop3::uidl", status);
if (c_uidl) {
std::string uidl (c_uidl);
free (c_uidl);
return uidl;
}
return NULL;
}
Iterator&
Pop3 :: uidl_all ()
{
mu_iterator_t mu_itr;
int status = mu_pop3_uidl_all (pop3, &mu_itr);
if (status)
throw Exception ("Pop3::uidl_all", status);
return *new Iterator (mu_itr);
}
void
Pop3 :: user (const char* user)
{
int status = mu_pop3_user (pop3, user);
if (status)
throw Exception ("Pop3::user", status);
}
void
Pop3 :: getline ()
{
int status = mu_pop3_getline (pop3);
if (status)
throw Exception ("Pop3::getline", status);
}
void
Pop3 :: response (size_t* nread)
{
int status = mu_pop3_response (pop3, nread);
if (status)
throw Exception ("Pop3::response", status);
}
void
Pop3 :: sendline (const char* line)
{
int status = mu_pop3_sendline (pop3, line);
if (status)
throw Exception ("Pop3::sendline", status);
}