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"
22 static int pound_arg, equal_arg;
24 static int pop2_ok (int sock, char *argbuf)
25 /* parse POP2 command response */
28 char buf [POPBUFSIZE+1];
30 pound_arg = equal_arg = -1;
32 if ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
36 else if (buf[0] == '#')
38 pound_arg = atoi(buf+1);
41 else if (buf[0] == '=')
43 equal_arg = atoi(buf+1);
46 else if (buf[0] == '-')
58 static int pop2_getauth(int sock, struct query *ctl, char *buf)
59 /* apply for connection authorization */
65 if (ctl->sslproto && !strcasecmp(ctl->sslproto, "tls1") && !ctl->use_ssl)
67 report(stderr, GT_("POP2 does not support STLS. Giving up.\n"));
71 if (ctl->server.authenticate != A_ANY && ctl->server.authenticate != A_PASSWORD)
73 report(stderr, GT_("POP2 only supports password authentication. Giving up.\n"));
77 strlcpy(shroud, ctl->password, sizeof(shroud));
78 status = gen_transact(sock,
80 ctl->remotename, ctl->password);
81 memset(shroud, 0x55, sizeof(shroud));
86 static int pop2_getrange(int sock, struct query *ctl, const char *folder,
87 int *countp, int *newp, int *bytes)
88 /* get range of messages to be fetched */
92 /* maybe the user wanted a non-default folder */
95 int ok = gen_transact(sock, "FOLD %s", folder);
104 * We should have picked up a count of messages in the user's
105 * default inbox from the pop2_getauth() response.
107 * Note: this logic only works because there is no way to select
108 * both the unnamed folder and named folders within a single
109 * fetchmail run. If that assumption ever becomes invalid, the
110 * pop2_getauth code will have to stash the pound response away
111 * explicitly in case it gets stepped on.
122 static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
123 /* request nth message */
129 ok = gen_transact(sock, "READ %d", number);
134 gen_send(sock, "RETR");
139 static int pop2_trail(int sock, struct query *ctl, const char *tag)
140 /* send acknowledgement for message data */
144 return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
147 static int pop2_logout(int sock, struct query *ctl)
148 /* send logout command */
151 return(gen_transact(sock, "QUIT"));
154 static const struct method pop2 =
156 "POP2", /* Post Office Protocol v2 */
157 "pop2", /* standard POP2 port */
158 "pop2", /* ssl POP2 port - not */
159 FALSE, /* this is not a tagged protocol */
160 FALSE, /* does not use message delimiter */
161 pop2_ok, /* parse command response */
162 pop2_getauth, /* get authorization */
163 pop2_getrange, /* query range of messages */
164 NULL, /* no way to get sizes */
165 NULL, /* no way to get sizes of subsets */
166 NULL, /* messages are always new */
167 pop2_fetch, /* request given message */
168 NULL, /* no way to fetch body alone */
169 pop2_trail, /* eat message trailer */
170 NULL, /* no POP2 delete method */
171 NULL, /* how to mark a message as seen */
172 NULL, /* how to end mailbox processing */
173 pop2_logout, /* log out, we're done */
174 FALSE /* no, we can't re-poll */
177 int doPOP2 (struct query *ctl)
178 /* retrieve messages using POP2 */
180 peek_capable = FALSE;
181 return(do_protocol(ctl, &pop2));
183 #endif /* POP2_ENABLE */
185 /* pop2.c ends here */