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 static int pound_arg, equal_arg;
21 int pop2_ok (socket, argbuf)
22 /* parse POP2 command response */
27 char buf [POPBUFSIZE+1];
29 pound_arg = equal_arg = -1;
30 if (SockGets(socket, buf, sizeof(buf)) >= 0) {
31 if (outlevel == O_VERBOSE)
32 fprintf(stderr,"%s\n",buf);
36 else if (buf[0] == '#')
38 pound_arg = atoi(buf+1);
41 else if (buf[0] == '=')
43 equal_arg = atoi(buf+1);
46 else if (buf[0] == '-')
60 int pop2_getauth(socket, queryctl, buf)
61 /* apply for connection authorization */
63 struct hostrec *queryctl;
66 return(gen_transact(socket,
68 queryctl->remotename, queryctl->password));
71 static pop2_getrange(socket, queryctl, countp)
72 /* get range of messages to be fetched */
74 struct hostrec *queryctl;
78 * We should have picked up a count of messages in the user's
79 * default inbox from the pop2_getauth() response.
84 /* maybe the user wanted a non-default folder */
85 if (queryctl->mailbox[0])
87 int ok = gen_transact(socket, "FOLD %s", queryctl->mailbox);
100 static int pop2_fetch(socket, number, lenp)
101 /* request nth message */
109 ok = gen_transact(socket, "READ %d", number);
114 gen_send(socket, "RETR");
119 static pop2_trail(socket, queryctl, number)
120 /* send acknowledgement for message data */
122 struct hostrec *queryctl;
125 return(gen_transact(socket, queryctl->keep ? "ACKS" : "ACKD"));
128 const static struct method pop2 =
130 "POP2", /* Post Office Protocol v2 */
131 109, /* standard POP2 port */
132 0, /* this is not a tagged protocol */
133 0, /* does not use message delimiter */
134 pop2_ok, /* parse command response */
135 pop2_getauth, /* get authorization */
136 pop2_getrange, /* query range of messages */
137 NULL, /* messages are always new */
138 pop2_fetch, /* request given message */
139 pop2_trail, /* eat message trailer */
140 NULL, /* no POP2 delete method */
141 NULL, /* no POP2 expunge command */
142 "QUIT", /* the POP2 exit command */
145 int doPOP2 (queryctl)
146 struct hostrec *queryctl;
148 return(do_protocol(queryctl, &pop2));