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)
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);
95 static int pop2_fetch(socket, number, lenp)
96 /* request nth message */
104 ok = gen_transact(socket, "READ %d", number);
109 gen_send(socket, "RETR");
114 static pop2_trail(socket, queryctl, number)
115 /* send acknowledgement for message data */
117 struct hostrec *queryctl;
120 return(gen_transact(socket, queryctl->keep ? "ACKS" : "ACKD"));
123 const static struct method pop2 =
125 "POP2", /* Post Office Protocol v2 */
126 109, /* standard POP2 port */
127 0, /* this is not a tagged protocol */
128 0, /* does not use message delimiter */
129 pop2_ok, /* parse command response */
130 pop2_getauth, /* get authorization */
131 pop2_getrange, /* query range of messages */
132 NULL, /* messages are always new */
133 pop2_fetch, /* request given message */
134 pop2_trail, /* eat message trailer */
135 NULL, /* no POP2 delete method */
136 NULL, /* no POP2 expunge command */
137 "QUIT", /* the POP2 exit command */
140 int doPOP2 (queryctl)
141 /* retrieve messages using POP2 */
142 struct hostrec *queryctl;
144 return(do_protocol(queryctl, &pop2));
147 /* pop2.c ends here */