2 * pop2.c -- POP@ protocol methods
4 * Copyright 1996 by Eric S. Raymond
6 * For license terms, see the file COPYING in this directory.
11 #if defined(STDC_HEADERS)
15 #include "fetchmail.h"
17 static int pound_arg, equal_arg;
19 int pop2_ok (FILE *sockfp, char *argbuf)
20 /* parse POP2 command response */
23 char buf [POPBUFSIZE+1];
25 pound_arg = equal_arg = -1;
26 if (fgets(buf, sizeof(buf), sockfp)) {
27 if (buf[strlen(buf)-1] == '\n')
28 buf[strlen(buf)-1] = '\0';
29 if (buf[strlen(buf)-1] == '\r')
30 buf[strlen(buf)-1] = '\r';
31 if (outlevel == O_VERBOSE)
32 error(0, 0, "POP2< %s", 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(FILE *sockfp, struct query *ctl, char *buf)
61 /* apply for connection authorization */
63 return(gen_transact(sockfp,
65 ctl->remotename, ctl->password));
68 static int pop2_getrange(FILE *sockfp, struct query *ctl, int*countp, int*newp)
69 /* get range of messages to be fetched */
72 * We should have picked up a count of messages in the user's
73 * default inbox from the pop2_getauth() response.
78 /* maybe the user wanted a non-default folder */
81 int ok = gen_transact(sockfp, "FOLD %s", ctl->mailbox);
95 static int pop2_fetch(FILE *sockfp, int number, int *lenp)
96 /* request nth message */
101 ok = gen_transact(sockfp, "READ %d", number);
106 gen_send(sockfp, "RETR");
111 static int pop2_trail(FILE *sockfp, struct query *ctl, int number)
112 /* send acknowledgement for message data */
114 return(gen_transact(sockfp, ctl->keep ? "ACKS" : "ACKD"));
117 const static struct method pop2 =
119 "POP2", /* Post Office Protocol v2 */
120 109, /* standard POP2 port */
121 0, /* this is not a tagged protocol */
122 0, /* does not use message delimiter */
123 pop2_ok, /* parse command response */
124 pop2_getauth, /* get authorization */
125 pop2_getrange, /* query range of messages */
126 NULL, /* no way to get sizes */
127 NULL, /* messages are always new */
128 pop2_fetch, /* request given message */
129 pop2_trail, /* eat message trailer */
130 NULL, /* no POP2 delete method */
131 NULL, /* no POP2 expunge command */
132 "QUIT", /* the POP2 exit command */
135 int doPOP2 (struct query *ctl)
136 /* retrieve messages using POP2 */
138 peek_capable = FALSE;
139 return(do_protocol(ctl, &pop2));
142 /* pop2.c ends here */