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 (SockGets(buf, sizeof(buf), sockfp) >= 0) {
27 if (outlevel == O_VERBOSE)
28 error(0, 0, "< %s", buf);
32 else if (buf[0] == '#')
34 pound_arg = atoi(buf+1);
37 else if (buf[0] == '=')
39 equal_arg = atoi(buf+1);
42 else if (buf[0] == '-')
56 int pop2_getauth(FILE *sockfp, struct query *ctl, char *buf)
57 /* apply for connection authorization */
59 return(gen_transact(sockfp,
61 ctl->remotename, ctl->password));
64 static int pop2_getrange(FILE *sockfp, struct query *ctl, int*countp, int*newp)
65 /* get range of messages to be fetched */
68 * We should have picked up a count of messages in the user's
69 * default inbox from the pop2_getauth() response.
74 /* maybe the user wanted a non-default folder */
77 int ok = gen_transact(sockfp, "FOLD %s", ctl->mailbox);
91 static int pop2_fetch(FILE *sockfp, int number, int *lenp)
92 /* request nth message */
97 ok = gen_transact(sockfp, "READ %d", number);
102 gen_send(sockfp, "RETR");
107 static int pop2_trail(FILE *sockfp, struct query *ctl, int number)
108 /* send acknowledgement for message data */
110 return(gen_transact(sockfp, ctl->keep ? "ACKS" : "ACKD"));
113 const static struct method pop2 =
115 "POP2", /* Post Office Protocol v2 */
116 109, /* standard POP2 port */
117 0, /* this is not a tagged protocol */
118 0, /* does not use message delimiter */
119 pop2_ok, /* parse command response */
120 pop2_getauth, /* get authorization */
121 pop2_getrange, /* query range of messages */
122 NULL, /* no way to get sizes */
123 NULL, /* messages are always new */
124 pop2_fetch, /* request given message */
125 pop2_trail, /* eat message trailer */
126 NULL, /* no POP2 delete method */
127 NULL, /* no POP2 expunge command */
128 "QUIT", /* the POP2 exit command */
131 int doPOP2 (struct query *ctl)
132 /* retrieve messages using POP2 */
134 peek_capable = FALSE;
135 return(do_protocol(ctl, &pop2));
138 /* pop2.c ends here */