1 /* Copyright 1993-95 by Carl Harris, Jr. Copyright 1996 by Eric S. Raymond
3 * For license terms, see the file COPYING in this directory.
6 /***********************************************************************
9 programmer: Carl Harris, ceharris@mal.com
10 Hacks and bug fixes by esr.
11 description: POP2 client code.
13 ***********************************************************************/
18 #if defined(STDC_HEADERS)
21 #if defined(HAVE_UNISTD_H)
29 #include "fetchmail.h"
34 /*********************************************************************
36 Method declarations for POP2
38 *********************************************************************/
40 static int pound_arg, equal_arg;
42 int pop2_ok (argbuf,socket)
43 /* parse POP2 command response */
48 char buf [POPBUFSIZE+1];
50 pound_arg = equal_arg = -1;
51 if (SockGets(socket, buf, sizeof(buf)) >= 0) {
52 if (outlevel == O_VERBOSE)
53 fprintf(stderr,"%s\n",buf);
57 else if (buf[0] == '#')
59 pound_arg = atoi(buf+1);
62 else if (buf[0] == '=')
64 equal_arg = atoi(buf+1);
67 else if (buf[0] == '-')
81 int pop2_getauth(socket, queryctl, buf)
82 /* apply for connection authorization */
84 struct hostrec *queryctl;
87 return(gen_transact(socket,
89 queryctl->remotename, queryctl->password));
92 static pop2_getrange(socket, queryctl, countp, firstp)
93 /* get range of messages to be fetched */
95 struct hostrec *queryctl;
100 * We should have picked up a count of messages in the user's
101 * default inbox from the pop2_getauth() response.
106 /* maybe the user wanted a non-default folder */
107 if (queryctl->remotefolder[0])
109 int ok = gen_transact(socket, "FOLD %s", queryctl->remotefolder);
123 static int pop2_fetch(socket, number, limit, lenp)
124 /* request nth message */
133 ok = gen_transact(socket, "READ %d", number);
138 gen_send(socket, "RETR");
143 static pop2_trail(socket, queryctl, number)
144 /* send acknowledgement for message data */
146 struct hostrec *queryctl;
149 return(gen_transact(socket, queryctl->keep ? "ACKS" : "ACKD"));
152 static struct method pop2 =
154 "POP2", /* Post Office Protocol v2 */
155 109, /* standard POP2 port */
156 0, /* this is not a tagged protocol */
157 0, /* does not use message delimiter */
158 pop2_ok, /* parse command response */
159 pop2_getauth, /* get authorization */
160 pop2_getrange, /* query range of messages */
161 pop2_fetch, /* request given message */
162 pop2_trail, /* eat message trailer */
163 NULL, /* no POP2 delete command */
164 NULL, /* no POP2 expunge command */
165 "QUIT", /* the POP2 exit command */
168 int doPOP2 (queryctl)
169 struct hostrec *queryctl;
171 /* check for unsupported options */
173 fprintf(stderr,"Option --limit is not supported with POP2\n");
176 else if (queryctl->flush) {
177 fprintf(stderr,"Option --flush is not supported with POP2\n");
180 else if (queryctl->fetchall) {
181 fprintf(stderr,"Option --all is not supported with POP2\n");
185 return(do_protocol(queryctl, &pop2));