Commit b85f004f b85f004f0db5af63ea80aae4ad35aa0b65c75109 by Alain Magloire

internal structure of the pop3 libary.

1 parent e6c6ca30
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003 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 2 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 Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18 #ifndef _MAILUTILS_SYS_POP3_H
19 #define _MAILUTILS_SYS_POP3_H
20
21 #include <sys/types.h>
22 #include <mailutils/pop3.h>
23 #include <mailutils/errno.h>
24
25 #ifdef DMALLOC
26 # include <dmalloc.h>
27 #endif
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 enum mu_pop3_state
34 {
35 MU_POP3_NO_STATE,
36 MU_POP3_CONNECT, MU_POP3_GREETINGS,
37 MU_POP3_APOP, MU_POP3_APOP_ACK,
38 MU_POP3_AUTH, MU_POP3_AUTH_ACK,
39 MU_POP3_CAPA, MU_POP3_CAPA_ACK, MU_POP3_CAPA_RX,
40 MU_POP3_DELE, MU_POP3_DELE_ACK,
41 MU_POP3_LIST, MU_POP3_LIST_ACK, MU_POP3_LIST_RX,
42 MU_POP3_NOOP, MU_POP3_NOOP_ACK,
43 MU_POP3_PASS, MU_POP3_PASS_ACK,
44 MU_POP3_QUIT, MU_POP3_QUIT_ACK,
45 MU_POP3_RETR, MU_POP3_RETR_ACK, MU_POP3_RETR_RX,
46 MU_POP3_RSET, MU_POP3_RSET_ACK,
47 MU_POP3_STAT, MU_POP3_STAT_ACK,
48 MU_POP3_TOP, MU_POP3_TOP_ACK, MU_POP3_TOP_RX,
49 MU_POP3_UIDL, MU_POP3_UIDL_ACK, MU_POP3_UIDL_RX,
50 MU_POP3_USER, MU_POP3_USER_ACK,
51 MU_POP3_DONE, MU_POP3_UNKNOWN, MU_POP3_ERROR
52 };
53
54 /* Structure holding the data necessary to do proper buffering. */
55 struct mu_pop3_work_buf
56 {
57 char *buf;
58 char *ptr;
59 char *nl;
60 size_t len;
61 };
62
63 /* Structure to hold things general to POP3 mailbox, like its state, etc ... */
64 struct _mu_pop3
65 {
66 /* Working I/O buffer.
67 io.buf: Working io buffer
68 io.ptr: Points to the end of the buffer, the non consumed chars
69 io.nl: Points to the '\n' char in the string
70 io.len: Len of io_buf. */
71 struct mu_pop3_work_buf io;
72
73 /* Holds the first line response of the last command, i.e the ACK:
74 ack.buf: Buffer for the ack
75 ack.ptr: Working pointer, indicate the start of the non consumed chars
76 ack.len: Size 512 according to RFC2449. */
77 struct mu_pop3_work_buf ack;
78 int acknowledge;
79
80 char *timestamp; /* For apop, if supported. */
81 unsigned timeout; /* Default is 10 minutes. */
82
83 void (*debug)(const char *log); /* function to print debug long. */
84
85 enum mu_pop3_state state; /* Indicate the state of the running command. */
86
87 stream_t carrier; /* TCP Connection. */
88 };
89
90 extern int mu_pop3_debug_cmd (mu_pop3_t);
91 extern int mu_pop3_debug_ack (mu_pop3_t);
92 extern int mu_pop3_stream_create (mu_pop3_t pop3, stream_t *pstream);
93
94 /* Check for non recoverable error.
95 The error is consider not recoverable if not part of the signal set:
96 EAGAIN, EINPROGRESS, EINTR.
97 For unrecoverable error we reset, by moving the working ptr
98 to the begining of the buffer and setting the state to error.
99 */
100 #define MU_POP3_CHECK_EAGAIN(pop3, status) \
101 do \
102 { \
103 if (status != 0) \
104 { \
105 if (status != EAGAIN && status != EINPROGRESS && status != EINTR) \
106 { \
107 pop3->io.ptr = pop3->io.buf; \
108 pop3->state = MU_POP3_ERROR; \
109 } \
110 return status; \
111 } \
112 } \
113 while (0)
114
115 /* If error return.
116 Check status an reset(see MU_POP2_CHECK_EAGAIN) the buffer.
117 */
118 #define MU_POP3_CHECK_ERROR(pop3, status) \
119 do \
120 { \
121 if (status != 0) \
122 { \
123 pop3->io.ptr = pop3->io.buf; \
124 pop3->state = MU_POP3_ERROR; \
125 return status; \
126 } \
127 } \
128 while (0)
129
130 /* Check if we got "+OK".
131 In POP3 protocol and ack of "+OK" means the command was successfull.
132 */
133 #define MU_POP3_CHECK_OK(pop3) \
134 do \
135 { \
136 if (strncasecmp (pop3->ack.buf, "+OK", 3) != 0) \
137 { \
138 pop3->state = MU_POP3_NO_STATE; \
139 return EACCES; \
140 } \
141 } \
142 while (0)
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148 #endif /* _MAILUTILS_SYS_POP3_H */