2 * etrn.c -- ETRN protocol methods (see RFC 1985)
4 * For license terms, see the file COPYING in this directory.
12 #ifdef HAVE_NET_SOCKET_H /* BeOS needs this */
13 #include <net/socket.h>
19 #include "fetchmail.h"
23 static int etrn_ok (int sock, char *argbuf)
24 /* parse command response */
29 if (ok == SM_UNRECOVERABLE)
35 static int etrn_getrange(int sock, struct query *ctl, const char *id,
36 int *countp, int *newp, int *bytes)
37 /* send ETRN and interpret the response */
40 char buf [MSGBUFSIZE+1];
41 struct idlist *qnp; /* pointer to Q names */
43 if ((ok = SMTP_ehlo(sock, fetchmailhost,
44 ctl->server.esmtp_name, ctl->server.esmtp_password,
47 report(stderr, GT_("%s's SMTP listener does not support ESMTP\n"),
48 ctl->server.pollname);
51 else if (!(opts & ESMTP_ETRN))
53 report(stderr, GT_("%s's SMTP listener does not support ETRN\n"),
54 ctl->server.pollname);
58 /* make sure we don't enter the fetch loop */
59 *bytes = *countp = *newp = -1;
62 * By default, the hostlist has a single entry, the fetchmail host's
65 for (qnp = ctl->domainlist; qnp; qnp = qnp->next)
67 /* ship the actual poll and get the response */
68 gen_send(sock, "ETRN %s", (char *)qnp->id);
69 if ((ok = gen_recv(sock, buf, sizeof(buf))))
72 /* this switch includes all response codes described in RFC1985 */
75 case 250: /* OK, queuing for node <x> started */
76 if (outlevel > O_SILENT)
77 report(stdout, GT_("Queuing for %s started\n"), qnp->id);
80 case 251: /* OK, no messages waiting for node <x> */
81 if (outlevel > O_SILENT)
82 report(stdout, GT_("No messages waiting for %s\n"), qnp->id);
85 case 252: /* OK, pending messages for node <x> started */
86 case 253: /* OK, <n> pending messages for node <x> started */
87 if (outlevel > O_SILENT)
88 report(stdout, GT_("Pending messages for %s started\n"), qnp->id);
91 case 458: /* Unable to queue messages for node <x> */
92 report(stderr, GT_("Unable to queue messages for node %s\n"),qnp->id);
95 case 459: /* Node <x> not allowed: <reason> */
96 report(stderr, GT_("Node %s not allowed: %s\n"), qnp->id, buf);
99 case 500: /* Syntax Error */
100 report(stderr, GT_("ETRN syntax error\n"));
103 case 501: /* Syntax Error in Parameters */
104 report(stderr, GT_("ETRN syntax error in parameters\n"));
108 report(stderr, GT_("Unknown ETRN error %d\n"), atoi(buf));
116 static int etrn_logout(int sock, struct query *ctl)
117 /* send logout command */
119 return(gen_transact(sock, "QUIT"));
122 static const struct method etrn =
124 "ETRN", /* ESMTP ETRN extension */
125 "smtp", /* standard SMTP port */
126 "smtps", /* ssl SMTP port */
127 FALSE, /* this is not a tagged protocol */
128 FALSE, /* this does not use a message delimiter */
129 etrn_ok, /* parse command response */
130 NULL, /* no need to get authentication */
131 etrn_getrange, /* initialize message sending */
132 NULL, /* we cannot get a list of sizes */
133 NULL, /* we cannot get a list of sizes of subsets */
134 NULL, /* how do we tell a message is old? */
135 NULL, /* no way to fetch headers */
136 NULL, /* no way to fetch body */
137 NULL, /* no message trailer */
138 NULL, /* how to delete a message */
139 NULL, /* how to mark a message as seen */
140 NULL, /* no mailbox support */
141 etrn_logout, /* log out, we're done */
142 FALSE, /* no, we can't re-poll */
145 int doETRN (struct query *ctl)
146 /* retrieve messages using ETRN */
151 fprintf(stderr, GT_("Option --keep is not supported with ETRN\n"));
155 fprintf(stderr, GT_("Option --flush is not supported with ETRN\n"));
158 if (ctl->mailboxes->id) {
159 fprintf(stderr, GT_("Option --folder is not supported with ETRN\n"));
163 fprintf(stderr, GT_("Option --check is not supported with ETRN\n"));
166 peek_capable = FALSE;
168 status = do_protocol(ctl, &etrn);
169 if (status == PS_NOMAIL)
173 #endif /* ETRN_ENABLE */
175 /* etrn.c ends here */