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 */
64 if (ctl->sslproto && !strcasecmp(ctl->sslproto, "tls1") && !ctl->use_ssl)
66 report(stderr, GT_("POP2 does not support STARTTLS. Giving up.\n"));
69 strlcpy(shroud, ctl->password, sizeof(shroud));
70 status = gen_transact(sock,
72 ctl->remotename, ctl->password);
77 static int pop2_getrange(int sock, struct query *ctl, const char *folder,
78 int *countp, int *newp, int *bytes)
79 /* get range of messages to be fetched */
83 /* maybe the user wanted a non-default folder */
86 int ok = gen_transact(sock, "FOLD %s", folder);
95 * We should have picked up a count of messages in the user's
96 * default inbox from the pop2_getauth() response.
98 * Note: this logic only works because there is no way to select
99 * both the unnamed folder and named folders within a single
100 * fetchmail run. If that assumption ever becomes invalid, the
101 * pop2_getauth code will have to stash the pound response away
102 * explicitly in case it gets stepped on.
113 static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
114 /* request nth message */
120 ok = gen_transact(sock, "READ %d", number);
125 gen_send(sock, "RETR");
130 static int pop2_trail(int sock, struct query *ctl, const char *tag)
131 /* send acknowledgement for message data */
135 return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
138 static int pop2_logout(int sock, struct query *ctl)
139 /* send logout command */
142 return(gen_transact(sock, "QUIT"));
145 static const struct method pop2 =
147 "POP2", /* Post Office Protocol v2 */
148 "pop2", /* standard POP2 port */
149 "pop2", /* ssl POP2 port - not */
150 FALSE, /* this is not a tagged protocol */
151 FALSE, /* does not use message delimiter */
152 pop2_ok, /* parse command response */
153 pop2_getauth, /* get authorization */
154 pop2_getrange, /* query range of messages */
155 NULL, /* no way to get sizes */
156 NULL, /* no way to get sizes of subsets */
157 NULL, /* messages are always new */
158 pop2_fetch, /* request given message */
159 NULL, /* no way to fetch body alone */
160 pop2_trail, /* eat message trailer */
161 NULL, /* no POP2 delete method */
162 NULL, /* how to mark a message as seen */
163 NULL, /* how to end mailbox processing */
164 pop2_logout, /* log out, we're done */
165 FALSE /* no, we can't re-poll */
168 int doPOP2 (struct query *ctl)
169 /* retrieve messages using POP2 */
171 peek_capable = FALSE;
172 return(do_protocol(ctl, &pop2));
174 #endif /* POP2_ENABLE */
176 /* pop2.c ends here */