2 * pop2.c -- POP2 protocol methods
4 * Copyright 1996 by Eric S. Raymond
6 * For license terms, see the file COPYING in this directory.
12 #if defined(STDC_HEADERS)
15 #include "fetchmail.h"
18 static int pound_arg, equal_arg;
20 int pop2_ok (int sock, char *argbuf)
21 /* parse POP2 command response */
24 char buf [POPBUFSIZE+1];
26 pound_arg = equal_arg = -1;
28 if ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
32 else if (buf[0] == '#')
34 pound_arg = atoi(buf+1);
37 else if (buf[0] == '=')
39 equal_arg = atoi(buf+1);
42 else if (buf[0] == '-')
54 int pop2_getauth(int sock, struct query *ctl, char *buf)
55 /* apply for connection authorization */
57 return(gen_transact(sock,
59 ctl->remotename, ctl->password));
62 static int pop2_getrange(int sock, struct query *ctl, const char *folder, int*countp, int*newp)
63 /* get range of messages to be fetched */
65 /* maybe the user wanted a non-default folder */
68 int ok = gen_transact(sock, "FOLD %s", folder);
77 * We should have picked up a count of messages in the user's
78 * default inbox from the pop2_getauth() response.
80 * Note: this logic only works because there is no way to select
81 * both the unnamed folder and named folders within a single
82 * fetchmail run. If that assumption ever becomes invalid, the
83 * pop2_getauth code will have to stash the pound response away
84 * explicitly in case it gets stepped on.
95 static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
96 /* request nth message */
101 ok = gen_transact(sock, "READ %d", number);
106 gen_send(sock, "RETR");
111 static int pop2_trail(int sock, struct query *ctl, int number)
112 /* send acknowledgement for message data */
114 return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
117 const static struct method pop2 =
119 "POP2", /* Post Office Protocol v2 */
120 109, /* standard POP2 port */
121 0, /* this is not a tagged protocol */
122 0, /* does not use message delimiter */
123 pop2_ok, /* parse command response */
124 pop2_getauth, /* get authorization */
125 pop2_getrange, /* query range of messages */
126 NULL, /* no way to get sizes */
127 NULL, /* messages are always new */
128 pop2_fetch, /* request given message */
129 NULL, /* no way to fetch body alone */
130 pop2_trail, /* eat message trailer */
131 NULL, /* no POP2 delete method */
132 "QUIT", /* the POP2 exit command */
135 int doPOP2 (struct query *ctl)
136 /* retrieve messages using POP2 */
138 peek_capable = FALSE;
139 return(do_protocol(ctl, &pop2));
141 #endif /* POP2_ENABLE */
143 /* pop2.c ends here */