2 * pop2.c -- POP2 protocol methods
4 * Copyright 1997 by Eric S. Raymond
5 * For license terms, see the file COPYING in this directory.
12 #if defined(STDC_HEADERS)
18 #include "fetchmail.h"
21 static int pound_arg, equal_arg;
23 static int pop2_ok (int sock, char *argbuf)
24 /* parse POP2 command response */
27 char buf [POPBUFSIZE+1];
29 pound_arg = equal_arg = -1;
31 if ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
35 else if (buf[0] == '#')
37 pound_arg = atoi(buf+1);
40 else if (buf[0] == '=')
42 equal_arg = atoi(buf+1);
45 else if (buf[0] == '-')
57 static int pop2_getauth(int sock, struct query *ctl, char *buf)
58 /* apply for connection authorization */
63 strlcpy(shroud, ctl->password, sizeof(shroud));
64 status = gen_transact(sock,
66 ctl->remotename, ctl->password);
71 static int pop2_getrange(int sock, struct query *ctl, const char *folder,
72 int *countp, int *newp, int *bytes)
73 /* get range of messages to be fetched */
77 /* maybe the user wanted a non-default folder */
80 int ok = gen_transact(sock, "FOLD %s", folder);
89 * We should have picked up a count of messages in the user's
90 * default inbox from the pop2_getauth() response.
92 * Note: this logic only works because there is no way to select
93 * both the unnamed folder and named folders within a single
94 * fetchmail run. If that assumption ever becomes invalid, the
95 * pop2_getauth code will have to stash the pound response away
96 * explicitly in case it gets stepped on.
107 static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
108 /* request nth message */
114 ok = gen_transact(sock, "READ %d", number);
119 gen_send(sock, "RETR");
124 static int pop2_trail(int sock, struct query *ctl, const char *tag)
125 /* send acknowledgement for message data */
129 return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
132 static int pop2_logout(int sock, struct query *ctl)
133 /* send logout command */
136 return(gen_transact(sock, "QUIT"));
139 static const struct method pop2 =
141 "POP2", /* Post Office Protocol v2 */
142 "pop2", /* standard POP2 port */
143 "pop2", /* ssl POP2 port - not */
144 FALSE, /* this is not a tagged protocol */
145 FALSE, /* does not use message delimiter */
146 pop2_ok, /* parse command response */
147 pop2_getauth, /* get authorization */
148 pop2_getrange, /* query range of messages */
149 NULL, /* no way to get sizes */
150 NULL, /* no way to get sizes of subsets */
151 NULL, /* messages are always new */
152 pop2_fetch, /* request given message */
153 NULL, /* no way to fetch body alone */
154 pop2_trail, /* eat message trailer */
155 NULL, /* no POP2 delete method */
156 NULL, /* how to mark a message as seen */
157 NULL, /* how to end mailbox processing */
158 pop2_logout, /* log out, we're done */
159 FALSE /* no, we can't re-poll */
162 int doPOP2 (struct query *ctl)
163 /* retrieve messages using POP2 */
165 peek_capable = FALSE;
166 return(do_protocol(ctl, &pop2));
168 #endif /* POP2_ENABLE */
170 /* pop2.c ends here */