2 * pop2.c -- POP2 protocol methods
4 * Copyright 1997 by Eric S. Raymond
5 * For license terms, see the file COPYING in this directory.
11 #if defined(STDC_HEADERS)
14 #include "fetchmail.h"
17 static int pound_arg, equal_arg;
19 int pop2_ok (int sock, char *argbuf)
20 /* parse POP2 command response */
23 char buf [POPBUFSIZE+1];
25 pound_arg = equal_arg = -1;
27 if ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
31 else if (buf[0] == '#')
33 pound_arg = atoi(buf+1);
36 else if (buf[0] == '=')
38 equal_arg = atoi(buf+1);
41 else if (buf[0] == '-')
53 int pop2_getauth(int sock, struct query *ctl, char *buf)
54 /* apply for connection authorization */
56 return(gen_transact(sock,
58 ctl->remotename, ctl->password));
61 static int pop2_getrange(int sock, struct query *ctl, const char *folder, int*countp, int*newp)
62 /* get range of messages to be fetched */
64 /* maybe the user wanted a non-default folder */
67 int ok = gen_transact(sock, "FOLD %s", folder);
76 * We should have picked up a count of messages in the user's
77 * default inbox from the pop2_getauth() response.
79 * Note: this logic only works because there is no way to select
80 * both the unnamed folder and named folders within a single
81 * fetchmail run. If that assumption ever becomes invalid, the
82 * pop2_getauth code will have to stash the pound response away
83 * explicitly in case it gets stepped on.
94 static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
95 /* request nth message */
100 ok = gen_transact(sock, "READ %d", number);
105 gen_send(sock, "RETR");
110 static int pop2_trail(int sock, struct query *ctl, int number)
111 /* send acknowledgement for message data */
113 return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
116 const static struct method pop2 =
118 "POP2", /* Post Office Protocol v2 */
119 109, /* standard POP2 port */
120 FALSE, /* this is not a tagged protocol */
121 FALSE, /* does not use message delimiter */
122 pop2_ok, /* parse command response */
123 pop2_getauth, /* get authorization */
124 pop2_getrange, /* query range of messages */
125 NULL, /* no way to get sizes */
126 NULL, /* messages are always new */
127 pop2_fetch, /* request given message */
128 NULL, /* no way to fetch body alone */
129 pop2_trail, /* eat message trailer */
130 NULL, /* no POP2 delete method */
131 "QUIT", /* the POP2 exit command */
134 int doPOP2 (struct query *ctl)
135 /* retrieve messages using POP2 */
137 peek_capable = FALSE;
138 return(do_protocol(ctl, &pop2));
140 #endif /* POP2_ENABLE */
142 /* pop2.c ends here */