2 * pop2.c -- POP@ protocol methods
4 * Copyright 1996 by Eric S. Raymond
6 * For license terms, see the file COPYING in this directory.
12 #include "fetchmail.h"
14 static int pound_arg, equal_arg;
16 int pop2_ok (socket, argbuf)
17 /* parse POP2 command response */
22 char buf [POPBUFSIZE+1];
24 pound_arg = equal_arg = -1;
25 if (SockGets(socket, buf, sizeof(buf)) >= 0) {
26 if (outlevel == O_VERBOSE)
27 fprintf(stderr,"%s\n",buf);
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] == '-')
55 int pop2_getauth(socket, queryctl, buf)
56 /* apply for connection authorization */
58 struct hostrec *queryctl;
61 return(gen_transact(socket,
63 queryctl->remotename, queryctl->password));
66 static pop2_getrange(socket, queryctl, countp, newp)
67 /* get range of messages to be fetched */
69 struct hostrec *queryctl;
73 * We should have picked up a count of messages in the user's
74 * default inbox from the pop2_getauth() response.
79 /* maybe the user wanted a non-default folder */
80 if (queryctl->mailbox[0])
82 int ok = gen_transact(socket, "FOLD %s", queryctl->mailbox);
96 static int pop2_fetch(socket, number, lenp)
97 /* request nth message */
105 ok = gen_transact(socket, "READ %d", number);
110 gen_send(socket, "RETR");
115 static pop2_trail(socket, queryctl, number)
116 /* send acknowledgement for message data */
118 struct hostrec *queryctl;
121 return(gen_transact(socket, queryctl->keep ? "ACKS" : "ACKD"));
124 const static struct method pop2 =
126 "POP2", /* Post Office Protocol v2 */
127 109, /* standard POP2 port */
128 0, /* this is not a tagged protocol */
129 0, /* does not use message delimiter */
130 pop2_ok, /* parse command response */
131 pop2_getauth, /* get authorization */
132 pop2_getrange, /* query range of messages */
133 NULL, /* no way to get sizes */
134 NULL, /* messages are always new */
135 pop2_fetch, /* request given message */
136 pop2_trail, /* eat message trailer */
137 NULL, /* no POP2 delete method */
138 NULL, /* no POP2 expunge command */
139 "QUIT", /* the POP2 exit command */
142 int doPOP2 (queryctl)
143 /* retrieve messages using POP2 */
144 struct hostrec *queryctl;
146 return(do_protocol(queryctl, &pop2));
149 /* pop2.c ends here */