Commit ad855c91 ad855c91be194b6ecbd4dfd44a7a322969727d32 by Alain Magloire

updated.

1 parent 3f0aa410
1 2003-10-05 Alain Magloire 1 2003-10-05 Alain Magloire
2 2
3 Implementation of the lower level functions for POP3 in a separate library.
4 This the first draft, the code is not yet enable in the Makefile.am
5
6 * mailbox/pop/pop3_apop.c: APOP
7 * mailbox/pop/pop3_capa.c: CAPA
8 * mailbox/pop/pop3_carrier.c: TCP stream.
9 * mailbox/pop/pop3_connect.c:
10 * mailbox/pop/pop3_create.c:
11 * mailbox/pop/pop3_debug.c:
12 * mailbox/pop/pop3_dele.c: DELE
13 * mailbox/pop/pop3_destroy.c:
14 * mailbox/pop/pop3_disconnect.c:
15 * mailbox/pop/pop3_lista.c: LIST
16 * mailbox/pop/pop3_list.c: LIST
17 * mailbox/pop/pop3_noop.c: NOOP
18 * mailbox/pop/pop3_pass.c: PASS
19 * mailbox/pop/pop3_quit.c: QUIT
20 * mailbox/pop/pop3_readline.c:
21 * mailbox/pop/pop3_response.c:
22 * mailbox/pop/pop3_retr.c: RETR
23 * mailbox/pop/pop3_rset.c: RSET
24 * mailbox/pop/pop3_sendline.c:
25 * mailbox/pop/pop3_stat.c: STAT
26 * mailbox/pop/pop3_stream.c:
27 * mailbox/pop/pop3_timeout.c:
28 * mailbox/pop/pop3_top.c: TOP
29 * mailbox/pop/pop3_uidl.c: UIDL
30 * mailbox/pop/pop3_uidla.c: UIDL
31 * mailbox/pop/pop3_user.c: USER
32
33 * include/mailutils/pop3.h: Declaration of the public functions.
34 * include/mailutils/sys/pop3.h: Declaration of the internal functions and structures.
35
36 * doc/texinfo/pop3.texi: updated.
37
38 2003-10-05 Alain Magloire
39
3 When list_destroy() is called, we need to provide also 40 When list_destroy() is called, we need to provide also
4 a way to free the item is necessary. To do this we added a new function: 41 a way to free the item is necessary. To do this we added a new function:
5 42
......
1 @c This is part of the GNU Mailutils manual. 1 \input texinfo @c -*-texinfo-* -
2 @c Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 2 @setfilename pop3.info
3 @c See file mailutils.texi for copying conditions. 3 @setchapternewpage off
4 @finalout
5
6 @comment This is part of the GNU Mailutils manual.
7 @comment Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
8 @comment See file mailutils.texi for copying conditions.
4 @comment ******************************************************************* 9 @comment *******************************************************************
5 @example 10 @example
6 @code{/* Prefix @emph{ pop3_ } is reserved */} 11 @code{/* Prefix "mu_pop3_" is reserved */}
7 @code{#include <mailutils/pop3.h>} 12 @code{#include <mailutils/pop3.h>}
8 13
9 @end example 14 @end example
...@@ -58,307 +63,195 @@ The servers removes all messages marked deleted, releases the exclusive lock ...@@ -58,307 +63,195 @@ The servers removes all messages marked deleted, releases the exclusive lock
58 and closes the TCP connection. 63 and closes the TCP connection.
59 64
60 @subsection Commands 65 @subsection Commands
61 @cindex pop3_t 66 @cindex mu_pop3_t
62 67
63 An opaque structure @var{pop3_t} is use as a handle for the session, it is allocated and initialized by calling @code{pop3_create ()}. 68 An opaque structure @var{mu_pop3_t} is use as a handle for the session, it is allocated and initialized by
64 All Functions will wait for a reply from the POP3 server before returning. The duration of the wait can be set by calling 69 calling @code{mu_pop3_create ()}. All Functions will wait for a reply from the POP3 server before returning. The duration of the
65 @code{pop3_set_timeout ()}, the default is 2 minutes. On the server side, there is also an idle timeout of 10 minutes 70 wait can be set by calling @code{mu_pop3_set_timeout ()}, the default is 2 minutes. On the server side, there is also an idle
66 before the POP3 server closes the connection. Although the @cite{RFC 1939} specifies that the minimum default timeout to be ten 71 timeout of 10 minutes before the POP3 server closes the connection, although the @cite{RFC 1939} specifies that the minimum
67 minutes many servers has shorter idle period, care should be taken to at least send a @code{pop3_noop ()} between lengthy period 72 default timeout to be ten minutes, many servers have shorter idle period, care should be taken to at least send a
68 of idle time. Once a successful connection is established with @code{pop3_connect ()}, two built-ins authentications are 73 @code{mu_pop3_noop ()} between lengthy period of idle time. Once a successful connection is established with
69 provided @code{pop3_apop ()} or @code{pop3_user ()}/@code{pop3_pass ()}. The @code{pop3_stat ()} and @code{pop3_list ()} functions 74 @code{mu_pop3_connect ()}, two built-ins authentications are provided @code{mu_pop3_apop ()} or
70 can be use to get the number and size of messages. The functions @code{pop3_list_all ()}, @code{pop3_uidl_all ()} and 75 @code{mu_pop3_user ()}/@code{mu_pop3_pass ()}. The @code{mu_pop3_stat ()} and @code{mu_pop3_list ()} functions can be use to
71 @code{pop3_capa ()} provide the information by going throught there iterators; @code{pop3_list_iterate ()}, @code{pop3_uidl_iterate ()} 76 get the number and size of messages. The functions @code{mu_pop3_list_all ()}, @code{mu_pop3_uidl_all ()} and
72 and @code{pop3_capa_iterate ()}. Downloading of messages is done via a two methods @code{pop3_retr ()} or @code{pop3_top ()} 77 @code{mu_pop3_capa ()} provide the information by going through there list iterators. Downloading of messages is done via a two methods
73 @footnote{@strong{Caution:} Some Internet Service Providers do not permit to leave mail on 78 @code{mu_pop3_retr ()} or @code{mu_pop3_top ()}; @strong{Caution: Some Internet Service Providers do not permit to leave mail on
74 server and the message will be deleted once downloaded.}. The functions @code{pop3_retr ()} or @code{pop3_top ()} initiates the 79 server and the message will be deleted once downloaded}.
75 dowloading of the message, the content is retrive with @code{pop_retr_read ()} or @code{pop3_top_read ()}. 80 The functions @code{mu_pop3_retr ()} or @code{mu_pop3_top ()} initiates the downloading of the message.
76 POP3 provides only a single channel for operation, it means only one operation can be done at a time, all the functions 81 POP3 provides only a single channel for operation, it means only one operation can be done at a time, all the functions
77 will return POP3_OPERATION_IN_PROGRESS if a different operation is call during another. 82 will return @code{EINPROGRESS}.
78 83
79 84
85 @subsubsection Callbacks
86 The POP3 library does not provide any callbacks, the approach is to leave flow control and policy outside of the
87 library. The functions do minimal state checking, for example when sending RETR with @code{mu_pop3_retr()}
88 it is the responsibility of the user to go through the entire message on the stream, any other call will fail.
89 To reset the state or break the downloading, the user should disconnect @code{mu_pop3_disconnect()} and reconnect
90 @code{mu_pop3_connect()}, after a sufficient waiting period, @strong{Some POP3 server, move the maildrop to a different
91 location after a sudden disconnect, it is necessary to wait before working on the same mailbox, if not the user may
92 receive a ``Mailbox busy''}.
93
94 @example
95 @group
96 int pop3_list_cb (mu_pop3_t pop3, int msgno, int (*callback_list)(int msgno, size_t octet))
97 @{
98 size_t octet = 0;
99 int status = mu_pop3_list (pop3, msgno, &octet);
100 if (status == 0)
101 @{
102 callback_retr (msgno, octect);
103 @}
104 return status;
105 @}
106 @end group
107 @end example
108
80 @subsubsection Initialization 109 @subsubsection Initialization
81 @cindex POP3 Initialization 110 @cindex POP3 Initialization
82 111
83 @deftypefun int pop3_create (pop3_t *@var{pop3}) 112 @deftypefun int mu_pop3_create (mu_pop3_t *@var{pop3})
84 113
85 Allocate and initialize a @var{pop3}, only memory is allocated. 114 Allocate and initialize a @var{pop3}, only memory is allocated.
86 115
87 Errors: 116 Errors:
88 @table @code 117 @table @code
89 @item POP3_NO_MEMORY 118 @item ENOMEM
90 @item POP3_INVALID_PARAMETER 119 @item EINVAL
91 @end table 120 @end table
92 @end deftypefun 121 @end deftypefun
93 122
94 @deftypefun void pop3_destroy (pop3_t *@var{pop3}) 123 @deftypefun void mu_pop3_destroy (mu_pop3_t *@var{pop3})
95 124
96 When a POP3 session is finished, any data use by the library is release. 125 When a POP3 session is finished, any data use by the library is release.
97 @end deftypefun 126 @end deftypefun
98 127
99 @deftypefun int pop3_connect (pop3_t @var{pop3}, const char *@var{hostname}, int @var{port}, int @var{flags}) 128 @deftypefun int mu_pop3_connect (mu_pop3_t @var{pop3})
100 129
101 A connection is established on @var{hostname:port}, if there was any previous connection it is close first. If non-blocking the 130 A connection is established on the carrier, if there was any previous connection it is close first. If non-blocking the
102 function should be recalled until the return value is not POP3_TRY_AGAIN or POP3_IN_PROGRESS. 131 function should be recalled until the return value is not EAGAIN or EINPROGRESS.
103 132
104 Errors: 133 Errors:
105 @table @code 134 @table @code
106 @item POP3_NO_MEMORY 135 @item ENOMEM
107 @item POP3_TRY_AGAIN 136 @item EAGAIN
108 @item POP3_TIMEOUT 137 @item ETIMEDOUT
109 @item POP3_CONN_REFUSED 138 @item EIO
110 @item POP3_NO_CONN 139 @item EINTR
111 @item POP3_INTERRUPTED
112 @end table 140 @end table
113 141
114 @end deftypefun 142 @end deftypefun
115 143
116 @deftypefun int pop3_disconnect (pop3_t @var{pop3}) 144 @deftypefun int mu_pop3_disconnect (mu_pop3_t @var{pop3})
117 145
118 Disconnect an establised POP3 session. 146 Disconnect an established POP3 session.
119 147
120 Errors: 148 Errors:
121 @table @code 149 @table @code
122 @item POP3_NO_CONN 150 @item EIO
123 @item POP3_INTERRUPTED 151 @item EINTR
124 @end table 152 @end table
125 153
126 @end deftypefun 154 @end deftypefun
127 @cindex POP3 carrier 155 @cindex POP3 carrier
128 156
129 @deftypefun int pop3_set_carrier (pop3_t @var{pop3}, pop3_carrier_t @var{carrier}) 157 @deftypefun int mu_pop3_set_carrier (mu_pop3_t @var{pop3}, stream_t @var{carrier})
130 158
131 The pop3 library abstracts the creation of the stream to the server and let the user overrides the access methods. The default, 159 Set the stream to be use as the carrier to the server , for example tcp_stream.
132 when no special carrier is provided, is to provide a carrier implemented with sockets and the use of @code{select ()}.
133 160
134 Errors: 161 Errors:
135 @table @code 162 @table @code
136 @item POP3_INVALID_PARAMETER 163 @item EINVAL
137 @end table 164 @end table
138 165
139 @deftp {Data Type} pop3_carrier_t
140 The @code{pop3_carrier_t} is defined as follows:
141
142 @example
143 @group
144 struct _pop3_carrier;
145 typedef struct _pop3_carrier* pop3_carrier_t;
146
147 #define POP3_CARRIER_NON_BLOCKING 1
148
149 struct _pop3_carrier @{
150 int (*open) (pop3_carrier_t, const char *hostname, int port, int flags);
151 int (*close) (pop3_carrier_t);
152
153 int (*read) (pop3_carrier_t, void *, size_t, size_t *);
154 int (*write) (pop3_carrier_t, const void *, size_t, size_t *);
155
156 int (*is_readready) (pop3_carrier_t, int timeout_seconds, int *ready);
157 int (*is_writeready) (pop3_carrier_t, int timeout_seconds, int *ready);
158
159 void (*destroy) (pop3_carrier_t *carrier);
160
161 void *data;
162 @};
163 @end group
164 @end example
165
166 @end deftp 166 @end deftp
167 167
168 The errors return by the carrier functions
169 @table @code
170 @item POP3_CARRIER_BAD
171 @item POP3_CARRIER_TRY_AGAIN
172 @item POP3_CARRIER_TIMEOUT
173 @item POP3_CARRIER_CONN_REFUSED
174 @item POP3_CARRIER_NOT_CONNECTED
175 @item POP3_CARRIER_INTERRUPTED
176 @end table
177
178 @end deftypefun
179
180 @subsubsection Authentication State 168 @subsubsection Authentication State
181 @cindex POP3 APOP 169 @cindex POP3 APOP
182 170
183 @deftypefun int pop3_apop (pop3_t @var{pop3}, const char *@var{user}, const char *@var{secret}) 171 @deftypefun int mu_pop3_apop (mu_pop3_t @var{pop3}, const char *@var{user}, const char *@var{secret})
184 172
185 APOP offers an alternative to USER/PASS authentication. For intermittent use of POP3, like checking for new mail, it is the 173 APOP offers an alternative to USER/PASS authentication. For intermittent use of POP3, like checking for new mail, it is the
186 preferred way to authenticate. It reduces the risk of password capture. The @var{user} and the shared @var{secret} are pass 174 preferred way to authenticate. It reduces the risk of password capture. The @var{user} and the shared @var{secret} are pass
187 to @code{pop3_apop ()}, the MD5 digest is calculated by applying the timestamp given by the server in the greeting followed by 175 to @code{mu_pop3_apop ()}, the MD5 digest is calculated by applying the time-stamp given by the server in the greeting followed by
188 the @var{secret}. 176 the @var{secret}.
189 177
190 @end deftypefun 178 @end deftypefun
191 179
192 @cindex POP3 USER 180 @cindex POP3 USER
193 181
194 @deftypefun int pop3_user (pop3_t, const char *@var{user}) 182 @deftypefun int mu_pop3_user (mu_pop3_t @var{pop3}, const char *@var{user})
195 183
196 Sends the USER command. 184 Sends the USER command.
197 185
198 Errors: 186 Errors:
199 @table @code 187 @table @code
200 @item POP3_INVALID_PARAMETER 188 @item EINVAL
201 @item POP3_OPERATION_DENIED 189 @item EACCES
202 @item any carrier errors.
203 @end table 190 @end table
204 @end deftypefun 191 @end deftypefun
205 192
206 @cindex POP3 PASS 193 @cindex POP3 PASS
207 194
208 @deftypefun int pop3_pass (pop3_t, const char *@var{passwd}) 195 @deftypefun int mu_pop3_pass (mu_pop3_t @var{pop3}, const char *@var{passwd})
209 196
210 Sends the PASS, to authenticate after the USER command. 197 Sends the PASS, to authenticate after the USER command.
211 198
212 Errors: 199 Errors:
213 @table @code 200 @table @code
214 @item POP3_INVALID_PARAMETER 201 @item EINVAL
215 @item POP3_OPERATION_DENIED 202 @item EACCES
216 @item any carrier errors
217 @end table 203 @end table
218 @end deftypefun 204 @end deftypefun
219 205
220 @cindex POP3 CAPA 206 @cindex POP3 CAPA
221 207
222 @deftypefun int pop3_capa (pop3_t @var{pop3}) 208 @deftypefun int mu_pop3_capa (mu_pop3_t @var{pop3})
223
224 The CAPA command is send to the sever and the list of capabilities is retrieve by calling @code{pop3_capa_iterate()}.
225
226 Errors:
227 @table @code
228 @item POP3_INVALID_PARAMETER
229 @item POP3_OPERATION_DENIED
230 @item any carrier errors.
231 @end table
232 @end deftypefun
233
234 @deftypefun int pop3_capa_iterate (pop3_t @var{pop3}, char **@var{capa})
235 209
236 To iterate through the capabilities response from the server, this function should be call in the loop. @var{capa} will be set 210 The CAPA command is send to the sever and the list of capabilities is retrieve by calling @code{mu_pop3_capa_iterate()}.
237 to @code{NULL} to indicate termination. Any other operations then @code{pop3_capa_iterate ()} will return
238 @var{POP3_OPERATION_IN_PROGRESS} until the CAPA command is complete.
239 211
240 Errors: 212 Errors:
241 @table @code 213 @table @code
242 @item POP3_INVALID_PARAMETER 214 @item EINVAL
243 @item POP3_OPERATION_DENIED 215 @item EACCES
244 @item any carrier errors.
245 @end table 216 @end table
246 @end deftypefun 217 @end deftypefun
247 218
248 @example
249 #include <stdio.h>
250 #include <stdlib.h>
251 #include <mailutils/pop3.h>
252
253 /* Assuming the pop3 is a valid connection. */
254 void print_capabilities (pop3_t pop3)
255 @{
256 status = pop3_capa (pop3);
257 if (status == 0)
258 @{
259 char *capa;
260 while ((status = pop3_capa_iterate(pop3, &capa) == 0) && capa != NULL)
261 @{
262 printf ("CAPA: %s\n", capa);
263 free (capa);
264 @}
265 @}
266 else
267 printf ("NONE\n");
268 @}
269 @end example
270
271 219
272 @subsubsection Transaction State 220 @subsubsection Transaction State
273 @cindex POP3 DELE 221 @cindex POP3 DELE
274 222
275 @deftypefun int pop3_dele (pop3_t @var{pop3}, unsigned @var{msgno}) 223 @deftypefun int mu_pop3_dele (mu_pop3_t @var{pop3}, unsigned @var{msgno})
276 224
277 Sends a DELE to the servers who will mark the @var{msgno} for deletion. The @var{msgno} may not refer to a message already marked 225 Sends a DELE to the servers who will mark the @var{msgno} for deletion. The @var{msgno} may not refer to a message already marked
278 deleted. If successful any future reference to @var{msgno} in other operations will be an error, unless unmarked by RSET. 226 deleted. If successful any future reference to @var{msgno} in other operations will be an error, unless unmarked by RSET.
279 227
280 Errors: 228 Errors:
281 @table @code 229 @table @code
282 @item POP3_INVALID_PARAMETER 230 @item EINVAL
283 @item POP3_OPERATION_DENIED 231 @item EACCES
284 @item POP3_OPERATION_IN_PROGRESS 232 @item EINPROGRESS
285 @item any carrier errors.
286 @end table 233 @end table
287 234
288 @end deftypefun 235 @end deftypefun
289 236
290 @cindex POP3 LIST 237 @cindex POP3 LIST
291 @cindex struct pop3_list 238 @cindex struct mu_pop3_list
292 239
293 @deftypefun int pop3_list (pop3_t @var{pop3}, unsigned @var{msgno}, size_t *@var{size}) 240 @deftypefun int mu_pop3_list (mu_pop3_t @var{pop3}, unsigned @var{msgno}, size_t *@var{size})
294 241
295 Sends a List for a specific @var{msgno} and returns the @var{size}. 242 Sends a List for a specific @var{msgno} and returns the @var{size}.
296 243
297 Errors: 244 Errors:
298 @table @code 245 @table @code
299 @item POP3_INVALID_PARAMETER 246 @item EINVAL
300 @item POP3_OPERATION_DENIED 247 @item EACCES
301 @item POP3_OPERATION_IN_PROGRESS 248 @item EINPROGRESS
302 @item any carrier errors.
303 @end table
304 @end deftypefun
305
306 @deftypefun int pop3_list_all (pop3_t @var{pop3})
307
308 Sends a LIST with no argument to the server. The @var{iterator} must be destroy after use, it will discard any remaining response
309 from LIST and clear the way for new operations. A cover function @code{pop3_list_current ()} around to scan properly the string
310 return by the @code{iterator_current ()}.
311
312 Errors:
313 @table @code
314 @item POP3_INVALID_PARAMETER
315 @item POP3_OPERATION_DENIED
316 @item POP3_OPERATION_IN_PROGRESS
317 @item any carrier errors.
318 @end table
319 @end deftypefun
320
321 @deftypefun int pop3_list_iterate (pop3_t @var{pop3}, unsigned int *@var{msgno}, sie_t *@var{size})
322
323 To iterate through the capabilities response from the server, this function should be call in the loop. @var{msgno} will be set
324 to @code{0} to indicate termination. Any other operations then @code{pop3_list_iterate ()} will return
325 @var{POP3_OPERATION_IN_PROGRESS} until the LIST command is complete.
326
327 Errors:
328 @table @code
329 @item POP3_INVALID_PARAMETER
330 @item POP3_OPERATION_DENIED
331 @item POP3_OPERATION_IN_PROGRESS
332 @item any carrier errors.
333 @end table 249 @end table
334 @end deftypefun 250 @end deftypefun
335 251
336 @example
337 #include <stdio.h>
338 #include <stdlib.h>
339 #include <mailutils/pop3.h>
340
341 /* Assuming pop3 is a valid session. */
342 void print_list (pop3_t pop3)
343 @{
344 status = pop3_list_all (pop3);
345 if (status == 0)
346 @{
347 unsigned int msgno = 0;
348 size_t size = 0;
349 while ((status = pop3_list_iterate (pop3, &msgno, &size)) == 0 && msgno != 0)
350 @{
351 printf ("LIST: %u %d\n", msgno, size);
352 @}
353 @}
354 else
355 printf ("NONE\n");
356 @}
357 @end example
358
359 @cindex POP3 NOOP 252 @cindex POP3 NOOP
360 253
361 @deftypefun int pop3_noop (pop3_t @var{pop3}) 254 @deftypefun int mu_pop3_noop (mu_pop3_t @var{pop3})
362 255
363 Sends a NOOP, useful to reset the timeout on the server. 256 Sends a NOOP, useful to reset the timeout on the server.
364 257
...@@ -373,26 +266,10 @@ Errors: ...@@ -373,26 +266,10 @@ Errors:
373 266
374 @cindex POP3 RETR 267 @cindex POP3 RETR
375 268
376 @deftypefun int pop3_retr (pop3_t @var{pop3}, unsigned @var{msgno}) 269 @deftypefun int mu_pop3_retr (mu_pop3_t @var{pop3}, unsigned @var{msgno}, stream_t *@var{stream})
377
378 If successful @code{pop3_retr_read} should be call to download the message, byte-stuff lines or handle internally, CRLFs are
379 converted to LF. All other operations will fail until the downloaed is complete by the caller.
380
381 Errors:
382 @table @code
383 @item POP3_INVALID_PARAMETER
384 @item POP3_OPERATION_DENIED
385 @item POP3_OPERATION_IN_PROGRESS
386 @item any carrier errors.
387 @end table
388 @end deftypefun
389
390 @deftypefun int pop3_retr_read (pop3_t @var{pop3}, char *@var{buffer}, size_t @var{len}, size_t *@var{nread})
391 270
392 After a @code{pop3_retr ()}, this function is use to get the content of the message, it will fill the @var{buffer} up to 271 If successful @code{stream} should be call to download the message, byte-stuff lines or handle internally, CRLFs are
393 a maximum of @var{len} and return in @var{nread} how much the @var{buffer} contains. If @var{nread} is zero, it signals 272 converted to LF. All other operations will fail until the downloaded is complete by the caller.
394 the termination of the command. Any other operations then @code{pop3_retr_read ()} will return
395 @var{POP3_OPERATION_IN_PROGRESS} until the RETR command is completed.
396 273
397 Errors: 274 Errors:
398 @table @code 275 @table @code
...@@ -408,14 +285,15 @@ Errors: ...@@ -408,14 +285,15 @@ Errors:
408 #include <mailutils/pop3.h> 285 #include <mailutils/pop3.h>
409 286
410 int 287 int
411 print_message (pop3_t pop3, unsigned int msgno) 288 print_message (mu_pop3_t pop3, unsigned int msgno)
412 @{ 289 @{
413 int status = pop3_retr (pop3, msgno); 290 stream_t stream;
291 int status = mu_pop3_retr (pop3, msgno, &stream);
414 if (status == 0) 292 if (status == 0)
415 @{ 293 @{
416 size_t n = 0; 294 size_t n = 0;
417 char buf[128]; 295 char buf[128];
418 while ((status = pop_retr_read (pop3, buf, sizeof buf, &n)) == 0) && n > 0) 296 while ((status = stream_readline (stream, buf, sizeof buf, &n)) == 0) && n > 0)
419 @{ 297 @{
420 printf ("%s", buf); 298 printf ("%s", buf);
421 @} 299 @}
...@@ -426,33 +304,16 @@ print_message (pop3_t pop3, unsigned int msgno) ...@@ -426,33 +304,16 @@ print_message (pop3_t pop3, unsigned int msgno)
426 304
427 @cindex POP3 TOP 305 @cindex POP3 TOP
428 306
429 @deftypefun int pop3_top (pop3_t @var{pop3}, unsigned int @var{msgno}, unsigned int @var{lines}) 307 @deftypefun int mu_pop3_top (mu_pop3_t @var{pop3}, unsigned int @var{msgno}, unsigned int @var{lines}, stream_t *@var{stream})
430 308
431 If successful @code{pop3_top_read} should be call to download the header, byte-stuff lines or handle internally, CRLFs are 309 If successful @code{stream} should be call to download the header, byte-stuff lines or handle internally, CRLFs are
432 converted to LF. All other operations will failed until the operation is completed by the caller. 310 converted to LF. All other operations will failed until the operation is completed by the caller.
433 311
434 Errors: 312 Errors:
435 @table @code 313 @table @code
436 @item POP3_INVALID_PARAMETER 314 @item EINVAL
437 @item POP3_OPERATION_DENIED 315 @item EACCES
438 @item POP3_OPERATION_IN_PROGRESS 316 @item EINPROGRESS
439 @item any carrier errors.
440 @end table
441 @end deftypefun
442
443 @deftypefun int pop3_top_read (pop3_t @var{pop3}, char *@var{buffer}, size_t @var{len}, size_t *@var{nread})
444
445 After a @code{pop3_top ()}, this function is use to get the content of the message, it will fill the @var{buffer} up to
446 a maximum of @var{len} and return in @var{nread} how much the @var{buffer} contains. If @var{nread} is zero, it signals
447 the termination of the command. Any other operations then @code{pop3_retr_read ()} will return
448 @var{POP3_OPERATION_IN_PROGRESS} until the TOP command is completed.
449
450 Errors:
451 @table @code
452 @item POP3_INVALID_PARAMETER
453 @item POP3_OPERATION_DENIED
454 @item POP3_OPERATION_IN_PROGRESS
455 @item any carrier errors.
456 @end table 317 @end table
457 @end deftypefun 318 @end deftypefun
458 319
...@@ -461,15 +322,15 @@ Errors: ...@@ -461,15 +322,15 @@ Errors:
461 #include <mailutils/pop3.h> 322 #include <mailutils/pop3.h>
462 323
463 int 324 int
464 print_top (pop3_t pop3, unsigned int msgno, unsigned int lines) 325 print_top (mu_pop3_t pop3, unsigned int msgno, unsigned int lines)
465 @{ 326 @{
466 int status = pop3_top (pop3, msgno, lines); 327 stream_t stream;
328 int status = mu_pop3_top (pop3, msgno, lines, &stream);
467 if (status == 0) 329 if (status == 0)
468 @{ 330 @{
469 size_t n = 0; 331 size_t n = 0;
470 char buf[128]; 332 char buf[128];
471 while ((status = pop3_top_read (pop3, buf, sizeof buf, &n)) == 0) 333 while ((status = stream_readline (stream, buf, sizeof buf, &n)) == 0) && n > 0)
472 && n > 0)
473 printf ("%s", buf); 334 printf ("%s", buf);
474 @} 335 @}
475 return status; 336 return status;
...@@ -479,75 +340,57 @@ print_top (pop3_t pop3, unsigned int msgno, unsigned int lines) ...@@ -479,75 +340,57 @@ print_top (pop3_t pop3, unsigned int msgno, unsigned int lines)
479 340
480 @cindex POP3 RSET 341 @cindex POP3 RSET
481 342
482 @deftypefun int pop3_rset (pop3_t @var{pop3}) 343 @deftypefun int mu_pop3_rset (mu_pop3_t @var{pop3})
483 344
484 Sends a RSET to unmark the messages marked as deleted. 345 Sends a RSET to unmarked the messages marked as deleted.
485 346
486 Errors: 347 Errors:
487 @table @code 348 @table @code
488 @item POP3_INVALID_PARAMETER 349 @item EINVAL
489 @item POP3_OPERATION_DENIED 350 @item EACCES
490 @item POP3_OPERATION_IN_PROGRESS 351 @item EINPROGRESS
491 @item any carrier errors.
492 @end table 352 @end table
493 @end deftypefun 353 @end deftypefun
494 354
495 @cindex POP3 STAT 355 @cindex POP3 STAT
496 356
497 @deftypefun int pop3_stat (pop3_t @var{pop3}, unsigned @var{msgno}, unsigned *@var{msg_count}, size_t *@var{size}) 357 @deftypefun int mu_pop3_stat (mu_pop3_t @var{pop3}, unsigned @var{msgno}, unsigned *@var{msg_count}, size_t *@var{size})
498 358
499 The number of messages in the mailbox and the size of the mailbox in octets. @strong{Caution:} The size is in RFC822 where 359 The number of messages in the mailbox and the size of the mailbox in octets. @strong{Caution:} The size is in RFC822 where
500 line termination is CRLF, messages marked as deleted are not counted in either total. 360 line termination is CRLF, messages marked as deleted are not counted in either total.
501 361
502 Errors: 362 Errors:
503 @table @code 363 @table @code
504 @item POP3_INVALID_PARAMETER 364 @item EINVAL
505 @item POP3_OPERATION_DENIED 365 @item EACCES
506 @item POP3_OPERATION_IN_PROGRESS 366 @item EINPROGRESS
507 @item any carrier errors.
508 @end table 367 @end table
509 @end deftypefun 368 @end deftypefun
510 369
511 @cindex POP3 UIDL 370 @cindex POP3 UIDL
512 371
513 @deftypefun int pop3_uidl (pop3_t @var{pop3}, unsigned int @var{msgno}, char **@var{uidl}) 372 @deftypefun int mu_pop3_uidl (mu_pop3_t @var{pop3}, unsigned int @var{msgno}, char **@var{uidl})
514 373
515 The UIDL is return in @var{uidl}, the string must be @code{free ()}'ed, by the caller. 374 The UIDL is return in @var{uidl}, the string must be @code{free ()}'ed, by the caller.
516 375
517 Errors: 376 Errors:
518 @table @code 377 @table @code
519 @item POP3_INVALID_PARAMETER 378 @item EINVAL
520 @item POP3_OPERATION_DENIED 379 @item EACCES
521 @item POP3_OPERATION_IN_PROGRESS 380 @item EINPROGRESS
522 @item any carrier errors.
523 @end table
524 @end deftypefun
525
526 @deftypefun int pop3_uidl_all (pop3_t @var{pop3})
527
528 A UIDL command is executed. The call should iterate with @code{pop3_uidl_iterate ()} to fetch the response.
529
530 Errors:
531 @table @code
532 @item POP3_INVALID_PARAMETER
533 @item POP3_OPERATION_DENIED
534 @item POP3_OPERATION_IN_PROGRESS
535 @item any carrier errors. 381 @item any carrier errors.
536 @end table 382 @end table
537 @end deftypefun 383 @end deftypefun
538 384
539 @deftypefun int pop3_uidl_iterate (pop3_t @var{pop3}, unsigned int *@var{msgno}, char **@var{uidl}) 385 @deftypefun int mu_pop3_uidl_all (mu_pop3_t @var{pop3}, list_t *@var{list})
540 386
541 To iterate through the uidl responses from the server, @code{pop3_uidl_iterate ()} should be call in a loop, @var{msgno} will be set 387 A UIDL command is executed. The call should iterate through the @code{list} to fetch the response.
542 to zero to indicate termination. Any other operations then @code{pop3_uidl;_iterate ()} will return
543 @var{POP3_OPERATION_IN_PROGRESS} until the UIDL command is completed. The @var{uidl} is @code{malloc()}
544 and should be @code{free()} by the caller.
545 388
546 Errors: 389 Errors:
547 @table @code 390 @table @code
548 @item POP3_INVALID_PARAMETER 391 @item EINVAL
549 @item POP3_OPERATION_DENIED 392 @item EACCES
550 @item any carrier errors. 393 @item EINPROGRESS
551 @end table 394 @end table
552 @end deftypefun 395 @end deftypefun
553 396
...@@ -556,21 +399,32 @@ Errors: ...@@ -556,21 +399,32 @@ Errors:
556 #include <stdlib.h> 399 #include <stdlib.h>
557 #include <mailutils/pop3.h> 400 #include <mailutils/pop3.h>
558 401
559 void print_uidl (pop3_t pop3) 402 void print_uidl (mu_pop3_t pop3)
560 @{ 403 @{
561 status = pop3_uidl_all (pop3); 404 list_t list;
405 status = mu_pop3_uidl_all (pop3, &list);
562 if (status == 0) 406 if (status == 0)
563 @{ 407 @{
564 unsigned int msgno; 408 iterator_t itr;
565 char *uidl; 409 int rc;
566 while (pop3_uidl_iterate (pop3, &msgno, &uidl) == 0 && msgno != 0) 410
411 rc = iterator_create (&itr, list);
412 if (rc)
413 lperror ("iterator_create", rc);
414
415 for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr))
567 @{ 416 @{
568 printf ("LIST: %d %s\n", msgno, uidl); 417 char *text;
569 free (uidl); 418
419 rc = iterator_current (itr, (void**) &text);
420 if (rc)
421 lperror ("iterator_current", rc);
422 printf ("%s\n", text);
570 @} 423 @}
424 iterator_destroy (&itr);
425 list_destroy(&list);
571 @} 426 @}
572 else 427
573 printf ("NONE\n");
574 @} 428 @}
575 @end example 429 @end example
576 430
...@@ -578,89 +432,84 @@ void print_uidl (pop3_t pop3) ...@@ -578,89 +432,84 @@ void print_uidl (pop3_t pop3)
578 @subsubsection Update State 432 @subsubsection Update State
579 @cindex POP3 QUIT 433 @cindex POP3 QUIT
580 434
581 @deftypefun int pop3_quit (pop3_t) 435 @deftypefun int mu_pop3_quit (mu_pop3_t @var{pop3})
582 436
583 QUIT will be send to enter the update state, if the command is successfull, the connection is close and any statein 437 QUIT will be send to enter the update state, if the command is successful, the connection is close and any state
584 the library is cleared. On the server side, all messages marked deleted before closing the connection will be removed.. 438 the library is cleared. On the server side, all messages marked deleted before closing the connection will be removed..
585 439
586 Errors: 440 Errors:
587 @table @code 441 @table @code
588 @item POP3_INVALID_PARAMETER 442 @item EINVAL
589 @item POP3_OPERATION_DENIED 443 @item EACCES
590 @item POP3_OPERATION_IN_PROGRESS 444 @item EINPROGRESS
591 @item any carrier errors.
592 @end table 445 @end table
593 @end deftypefun 446 @end deftypefun
594 447
595 448
596 @subsubsection Help functions 449 @subsubsection Help functions
597 450
598 @deftypefun int pop3_writeline (pop3_t, const char *@var{format}, ...); 451 @deftypefun int mu_pop3_writeline (mu_pop3_t @var{pop3}, const char *@var{format}, ...);
599 452
600 Copy in the internal buffer of @code{pop3_t} the formatted string, @code{pop3_send ()} should be called later to flush the string 453 Copy in the internal buffer of @code{mu_pop3_t} the formatted string, @code{mu_pop3_send ()} should be called later to flush the string
601 to the POP3 server. 454 to the POP3 server.
602 455
603 Errors: 456 Errors:
604 @table @code 457 @table @code
605 @item POP3_INVALID_PARAMETER 458 @item EINVAL
606 @item any carrier errors.
607 @end table 459 @end table
608 @end deftypefun 460 @end deftypefun
609 461
610 @deftypefun int pop3_sendline (pop3_t, const char *@var{cmd}); 462 @deftypefun int mu_pop3_sendline (mu_pop3_t @var{pop3}, const char *@var{cmd});
611 463
612 Cover function for @code{pop3_writeline ()} and @code{pop3_send ()}. 464 Cover function for @code{mu_pop3_writeline ()} and @code{mu_pop3_send ()}.
613 465
614 Errors: 466 Errors:
615 @table @code 467 @table @code
616 @item POP3_INVALID_PARAMETER 468 @item EINVAL
617 @item any carrier errors.
618 @end table 469 @end table
619 @end deftypefun 470 @end deftypefun
620 471
621 @deftypefun int pop3_send (pop3_t); 472 @deftypefun int mu_pop3_send (mu_pop3_t @var{pop3});
622 473
623 Flushes out the strings written by @code{pop3_writeline ()} in the internal buffer to the channel. 474 Flushes out the strings written by @code{mu_pop3_writeline ()} in the internal buffer to the channel.
624 475
625 Errors: 476 Errors:
626 @table @code 477 @table @code
627 @item POP3_INVALID_PARAMETER 478 @item EINVAL
628 @item any carrier errors.
629 @end table 479 @end table
630 @end deftypefun 480 @end deftypefun
631 481
632 @deftypefun int pop3_response (pop3_t, char *@var{buffer}, size_t @var{len}, size_t *@var{plen}) 482 @deftypefun int mu_pop3_response (mu_pop3_t @var{pop3}, char *@var{buffer}, size_t @var{len}, size_t *@var{plen})
633 483
634 The last response from the last command is save and can be examine after 484 The last response from the last command is save and can be examine after
635 a failure or success. 485 a failure or success.
636 486
637 Errors: 487 Errors:
638 @table @code 488 @table @code
639 @item POP3_INVALID_PARAMETER 489 @item EINVAL
640 @item any carrier errors.
641 @end table 490 @end table
642 @end deftypefun 491 @end deftypefun
643 492
644 @subsubsection Timeout 493 @subsubsection Timeout
645 @cindex Pop3 Timeout 494 @cindex Pop3 Timeout
646 495
647 @deftypefun int pop3_set_timeout (pop3_t, int @var{timeout}) 496 @deftypefun int mu_pop3_set_timeout (mu_pop3_t @var{pop3}, int @var{timeout})
648 497
649 Set the timeout time for I/O on the carrier. The default is 10 minutes. The @var{timeout} is given in milliseconds. 498 Set the timeout time for I/O on the carrier. The default is 10 minutes. The @var{timeout} is given in milliseconds.
650 499
651 Errors: 500 Errors:
652 @table @code 501 @table @code
653 @item POP3_INVALID_PARAMETER 502 @item EINVAL
654 @end table 503 @end table
655 @end deftypefun 504 @end deftypefun
656 505
657 @deftypefun int pop3_get_timeout (pop3_t, int *@var{timeout}) 506 @deftypefun int mu_pop3_get_timeout (mu_pop3_t @var{pop3}, int *@var{timeout})
658 507
659 Get the timeout time for I/O on the carrier. The @var{timeout} is given in milliseconds. 508 Get the timeout time for I/O on the carrier. The @var{timeout} is given in milliseconds.
660 509
661 Errors: 510 Errors:
662 @table @code 511 @table @code
663 @item POP3_INVALID_PARAMETER 512 @item EINVAL
664 @end table 513 @end table
665 514
666 @end deftypefun 515 @end deftypefun
......