2 * pop2.c -- POP@ protocol methods
4 * Copyright 1996 by Eric S. Raymond
6 * 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, int*countp, int*newp)
62 /* get range of messages to be fetched */
65 * We should have picked up a count of messages in the user's
66 * default inbox from the pop2_getauth() response.
71 /* maybe the user wanted a non-default folder */
74 int ok = gen_transact(sock, "FOLD %s", ctl->mailbox);
88 static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
89 /* request nth message */
94 ok = gen_transact(sock, "READ %d", number);
99 gen_send(sock, "RETR");
104 static int pop2_trail(int sock, struct query *ctl, int number)
105 /* send acknowledgement for message data */
107 return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
110 const static struct method pop2 =
112 "POP2", /* Post Office Protocol v2 */
113 109, /* standard POP2 port */
114 0, /* this is not a tagged protocol */
115 0, /* does not use message delimiter */
116 pop2_ok, /* parse command response */
117 pop2_getauth, /* get authorization */
118 pop2_getrange, /* query range of messages */
119 NULL, /* no way to get sizes */
120 NULL, /* messages are always new */
121 pop2_fetch, /* request given message */
122 pop2_trail, /* eat message trailer */
123 NULL, /* no POP2 delete method */
124 "QUIT", /* the POP2 exit command */
127 int doPOP2 (struct query *ctl)
128 /* retrieve messages using POP2 */
130 peek_capable = FALSE;
131 return(do_protocol(ctl, &pop2));
134 /* pop2.c ends here */