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 */
62 strcpy(shroud, ctl->password);
63 status = gen_transact(sock,
65 ctl->remotename, ctl->password);
70 static int pop2_getrange(int sock, struct query *ctl, const char *folder,
71 int *countp, int *newp, int *bytes)
72 /* get range of messages to be fetched */
74 /* maybe the user wanted a non-default folder */
77 int ok = gen_transact(sock, "FOLD %s", folder);
86 * We should have picked up a count of messages in the user's
87 * default inbox from the pop2_getauth() response.
89 * Note: this logic only works because there is no way to select
90 * both the unnamed folder and named folders within a single
91 * fetchmail run. If that assumption ever becomes invalid, the
92 * pop2_getauth code will have to stash the pound response away
93 * explicitly in case it gets stepped on.
104 static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
105 /* request nth message */
110 ok = gen_transact(sock, "READ %d", number);
115 gen_send(sock, "RETR");
120 static int pop2_trail(int sock, struct query *ctl, int number)
121 /* send acknowledgement for message data */
123 return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
126 static int pop2_logout(int sock, struct query *ctl)
127 /* send logout command */
129 return(gen_transact(sock, "QUIT"));
132 static const struct method pop2 =
134 "POP2", /* Post Office Protocol v2 */
136 "pop2", /* standard POP2 port */
137 "pop2", /* ssl POP2 port */
138 #else /* INET6_ENABLE */
139 109, /* standard POP2 port */
140 109, /* ssl POP2 port - not */
141 #endif /* INET6_ENABLE */
142 FALSE, /* this is not a tagged protocol */
143 FALSE, /* does not use message delimiter */
144 pop2_ok, /* parse command response */
145 pop2_getauth, /* get authorization */
146 pop2_getrange, /* query range of messages */
147 NULL, /* no way to get sizes */
148 NULL, /* no way to get sizes of subsets */
149 NULL, /* messages are always new */
150 pop2_fetch, /* request given message */
151 NULL, /* no way to fetch body alone */
152 pop2_trail, /* eat message trailer */
153 NULL, /* no POP2 delete method */
154 NULL, /* how to mark a message as seen */
155 pop2_logout, /* log out, we're done */
156 FALSE, /* no, we can't re-poll */
159 int doPOP2 (struct query *ctl)
160 /* retrieve messages using POP2 */
162 peek_capable = FALSE;
163 return(do_protocol(ctl, &pop2));
165 #endif /* POP2_ENABLE */
167 /* pop2.c ends here */