1 /* Copyright 1996 by Eric S. Raymond
3 * For license terms, see the file COPYING in this directory.
6 /***********************************************************************
9 programmer: Eric S. Raymond
10 description: POP2 method code.
12 ***********************************************************************/
17 #include "fetchmail.h"
19 /*********************************************************************
21 Method declarations for POP2
23 *********************************************************************/
25 static int pound_arg, equal_arg;
27 int pop2_ok (argbuf,socket)
28 /* parse POP2 command response */
33 char buf [POPBUFSIZE+1];
35 pound_arg = equal_arg = -1;
36 if (SockGets(socket, buf, sizeof(buf)) >= 0) {
37 if (outlevel == O_VERBOSE)
38 fprintf(stderr,"%s\n",buf);
42 else if (buf[0] == '#')
44 pound_arg = atoi(buf+1);
47 else if (buf[0] == '=')
49 equal_arg = atoi(buf+1);
52 else if (buf[0] == '-')
66 int pop2_getauth(socket, queryctl, buf)
67 /* apply for connection authorization */
69 struct hostrec *queryctl;
72 return(gen_transact(socket,
74 queryctl->remotename, queryctl->password));
77 static pop2_getrange(socket, queryctl, countp, firstp)
78 /* get range of messages to be fetched */
80 struct hostrec *queryctl;
85 * We should have picked up a count of messages in the user's
86 * default inbox from the pop2_getauth() response.
91 /* maybe the user wanted a non-default folder */
92 if (queryctl->remotefolder[0])
94 int ok = gen_transact(socket, "FOLD %s", queryctl->remotefolder);
108 static int pop2_fetch(socket, number, limit, lenp)
109 /* request nth message */
118 ok = gen_transact(socket, "READ %d", number);
123 gen_send(socket, "RETR");
128 static pop2_trail(socket, queryctl, number)
129 /* send acknowledgement for message data */
131 struct hostrec *queryctl;
134 return(gen_transact(socket, queryctl->keep ? "ACKS" : "ACKD"));
137 static struct method pop2 =
139 "POP2", /* Post Office Protocol v2 */
140 109, /* standard POP2 port */
141 0, /* this is not a tagged protocol */
142 0, /* does not use message delimiter */
143 pop2_ok, /* parse command response */
144 pop2_getauth, /* get authorization */
145 pop2_getrange, /* query range of messages */
146 pop2_fetch, /* request given message */
147 pop2_trail, /* eat message trailer */
148 NULL, /* no POP2 delete command */
149 NULL, /* no POP2 expunge command */
150 "QUIT", /* the POP2 exit command */
153 int doPOP2 (queryctl)
154 struct hostrec *queryctl;
156 /* check for unsupported options */
158 fprintf(stderr,"Option --limit is not supported with POP2\n");
161 else if (queryctl->flush) {
162 fprintf(stderr,"Option --flush is not supported with POP2\n");
165 else if (queryctl->fetchall) {
166 fprintf(stderr,"Option --all is not supported with POP2\n");
170 return(do_protocol(queryctl, &pop2));