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, &opts)))
45 report(stderr, _("%s's SMTP listener does not support ESMTP\n"),
46 ctl->server.pollname);
49 else if (!(opts & ESMTP_ETRN))
51 report(stderr, _("%s's SMTP listener does not support ETRN\n"),
52 ctl->server.pollname);
56 /* make sure we don't enter the fetch loop */
57 *bytes = *countp = *newp = -1;
60 * By default, the hostlist has a single entry, the fetchmail host's
63 for (qnp = ctl->smtphunt; qnp; qnp = qnp->next)
65 /* ship the actual poll and get the response */
66 gen_send(sock, "ETRN %s", qnp->id);
67 if ((ok = gen_recv(sock, buf, sizeof(buf))))
70 /* this switch includes all response codes described in RFC1985 */
73 case 250: /* OK, queuing for node <x> started */
74 if (outlevel >= O_SILENT)
75 report(stdout, _("Queuing for %s started\n"), qnp->id);
78 case 251: /* OK, no messages waiting for node <x> */
79 if (outlevel >= O_SILENT)
80 report(stdout, _("No messages waiting for %s\n"), qnp->id);
83 case 252: /* OK, pending messages for node <x> started */
84 case 253: /* OK, <n> pending messages for node <x> started */
85 if (outlevel >= O_SILENT)
86 report(stdout, _("Pending messages for %s started\n"), qnp->id);
89 case 458: /* Unable to queue messages for node <x> */
90 report(stderr, _("Unable to queue messages for node %s\n"),qnp->id);
93 case 459: /* Node <x> not allowed: <reason> */
94 report(stderr, _("Node %s not allowed: %s\n"), qnp->id, buf);
97 case 500: /* Syntax Error */
98 report(stderr, _("ETRN syntax error\n"));
101 case 501: /* Syntax Error in Parameters */
102 report(stderr, _("ETRN syntax error in parameters\n"));
106 report(stderr, _("Unknown ETRN error %d\n"), atoi(buf));
114 static int etrn_logout(int sock, struct query *ctl)
115 /* send logout command */
117 return(gen_transact(sock, "QUIT"));
120 const static struct method etrn =
122 "ETRN", /* ESMTP ETRN extension */
124 "smtp", /* standard SMTP port */
125 "smtps", /* ssl SMTP port */
126 #else /* INET6_ENABLE */
127 25, /* standard SMTP port */
128 465, /* ssl SMTP port */
129 #endif /* INET6_ENABLE */
130 FALSE, /* this is not a tagged protocol */
131 FALSE, /* this does not use a message delimiter */
132 etrn_ok, /* parse command response */
133 NULL, /* no need to get authentication */
134 etrn_getrange, /* initialize message sending */
135 NULL, /* we cannot get a list of sizes */
136 NULL, /* how do we tell a message is old? */
137 NULL, /* no way to fetch headers */
138 NULL, /* no way to fetch body */
139 NULL, /* no message trailer */
140 NULL, /* how to delete a message */
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, _("Option --keep is not supported with ETRN\n"));
155 fprintf(stderr, _("Option --flush is not supported with ETRN\n"));
158 if (ctl->mailboxes->id) {
159 fprintf(stderr, _("Option --remote is not supported with ETRN\n"));
163 fprintf(stderr, _("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 */