1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 1999-2021 Free Software Foundation, Inc.
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 3 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General
15    Public License along with this library.  If not, see
16    <http://www.gnu.org/licenses/>. */
17 
18 #ifndef _MAILUTILS_POP3_H
19 #define _MAILUTILS_POP3_H
20 
21 #include <mailutils/iterator.h>
22 #include <mailutils/debug.h>
23 #include <mailutils/stream.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct _mu_pop3;
30 typedef struct _mu_pop3 *mu_pop3_t;
31 
32 #define MU_POP3_DEFAULT_PORT 110
33 #define MU_POP3_DEFAULT_SSL_PORT 995
34 
35 int  mu_pop3_create (mu_pop3_t *pop3);
36 void mu_pop3_destroy (mu_pop3_t *pop3);
37 
38 int  mu_pop3_set_carrier (mu_pop3_t pop3, mu_stream_t carrier);
39 int  mu_pop3_get_carrier (mu_pop3_t pop3, mu_stream_t *pcarrier);
40 
41 int  mu_pop3_connect (mu_pop3_t pop3);
42 int  mu_pop3_disconnect (mu_pop3_t pop3);
43 
44 int  mu_pop3_set_timeout (mu_pop3_t pop3, int timeout);
45 int  mu_pop3_get_timeout (mu_pop3_t pop3, int *timeout);
46 
47 #define MU_POP3_TRACE_CLR 0
48 #define MU_POP3_TRACE_SET 1
49 #define MU_POP3_TRACE_QRY 2
50 int mu_pop3_trace (mu_pop3_t pop3, int op);
51 int mu_pop3_trace_mask (mu_pop3_t pop3, int op, int lev);
52 
53 int  mu_pop3_apop (mu_pop3_t pop3, const char *name, const char *digest);
54 
55 int  mu_pop3_stls (mu_pop3_t pop3);
56 
57 /* It is the responsibility of the caller to call mu_iterator_destroy() when
58    done with the iterator.  The items returned by the iterator are of type
59    "const char *", no processing is done on the item except the removal of
60    the trailing newline.  */
61 int mu_pop3_capa (mu_pop3_t pop3, int reread, mu_iterator_t *piter);
62 int mu_pop3_capa_test (mu_pop3_t pop3, const char *name, const char **pret);
63 
64 int  mu_pop3_dele (mu_pop3_t pop3, unsigned int mesgno);
65 
66 int  mu_pop3_list (mu_pop3_t pop3, unsigned int mesgno, size_t *mesg_octet);
67 
68 /* Send the LIST command and prepare pop3 for receiving a multiline answer.
69    The caller is expected to obtain a stream via mu_pop3_stream_create,
70    or an iterator via mu_pop3_iterator_create and read data from them.
71 
72    This function is not intended for use by a casual user, better use
73    mu_pop3_list_all or mu_pop3_list_all_stream. */
74 int mu_pop3_list_cmd (mu_pop3_t pop3);
75 int mu_pop3_list_all (mu_pop3_t pop3, mu_iterator_t *pitr);
76 int mu_pop3_list_all_stream (mu_pop3_t pop3, mu_stream_t *pstream);
77 
78 int  mu_pop3_noop (mu_pop3_t pop3);
79 
80 int  mu_pop3_pass (mu_pop3_t pop3, const char *pass);
81 
82 int  mu_pop3_quit (mu_pop3_t pop3);
83 
84 /* A stream is returned with the multi-line answer.  It is the responsibility
85    of the caller to call mu_stream_destroy() to dipose of the stream.  */
86 int  mu_pop3_retr (mu_pop3_t pop3, unsigned int mesgno,
87 		   mu_stream_t *pstream);
88 
89 int  mu_pop3_rset (mu_pop3_t pop3);
90 
91 int  mu_pop3_stat (mu_pop3_t pop3, size_t *count, mu_off_t *octets);
92 
93 /* A stream is returned with the multi-line answer.  It is the responsibility
94    of the caller to call mu_stream_destroy() to dipose of the stream.  */
95 int  mu_pop3_top (mu_pop3_t pop3, unsigned int mesgno,
96 		  unsigned int lines, mu_stream_t *pstream);
97 
98 /* The uidl is malloc'ed and returned in puidl; it is the responsibility of
99    the caller to free() the uild when done.  */
100 int  mu_pop3_uidl (mu_pop3_t pop3, unsigned int mesgno, char **puidl);
101 
102 /* Send the UIDL command and prepare pop3 for receiving a multiline answer.
103    The caller is expected to obtain a stream via mu_pop3_stream_create,
104    or an iterator via mu_pop3_iterator_create and read data from them.
105 
106    This function is not intended for use by a casual user, better use
107    mu_pop3_uidl_all or mu_pop3_uidl_all_stream. */
108 int mu_pop3_uidl_all_cmd (mu_pop3_t pop3);
109 int mu_pop3_uidl_all (mu_pop3_t pop3, mu_iterator_t *piterator);
110 int mu_pop3_uidl_all_stream (mu_pop3_t pop3, mu_stream_t *pstream);
111 
112 int mu_pop3_user (mu_pop3_t pop3, const char *user);
113 
114 /* Returns the last command acknowledge.  If the server supports RESP-CODE,
115    the message could be retrieved, but it is up to the caller to do the
116    parsing.  */
117 int  mu_pop3_response (mu_pop3_t pop3, size_t *nread);
118 const char *mu_pop3_strresp (mu_pop3_t pop3);
119 int mu_pop3_sget_response (mu_pop3_t pop3, const char **sptr);
120 int mu_pop3_aget_response (mu_pop3_t pop3, char **sptr);
121 int mu_pop3_get_response (mu_pop3_t pop3, char *buf, size_t len, size_t *plen);
122 
123 int  mu_pop3_writeline (mu_pop3_t pop3, const char *format, ...)
124                                   MU_PRINTFLIKE(2,3);
125 
126 int  mu_pop3_sendline (mu_pop3_t pop3, const char *line);
127 int mu_pop3_getline (mu_pop3_t pop3);
128 int mu_pop3_read_list (mu_pop3_t pop3, mu_list_t list);
129 int mu_pop3_stream_to_list (mu_pop3_t pop3, mu_stream_t stream,
130 			    mu_list_t list);
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* _MAILUTILS_POP3_H */
137