2 * etrn.c -- ETRN protocol methods
4 * For license terms, see the file COPYING in this directory.
6 * i18n by Arnaldo Carvalho de Melo <acme@conectiva.com.br> 7-Nov-1998
18 #include "fetchmail.h"
22 static int etrn_ok (int sock, char *argbuf)
23 /* parse command response */
28 if (ok == SM_UNRECOVERABLE)
34 static int etrn_getrange(int sock, struct query *ctl, const char *id,
35 int *countp, int *newp, int *bytes)
36 /* send ETRN and interpret the response */
39 char buf [MSGBUFSIZE+1];
40 struct idlist *qnp; /* pointer to Q names */
42 if ((ok = SMTP_ehlo(sock, ctl->server.truename, &opts)))
44 error(0, 0, _("%s's SMTP listener does not support ESMTP"),
45 ctl->server.pollname);
48 else if (!(opts & ESMTP_ETRN))
50 error(0, 0, _("%s's SMTP listener does not support ETRN"),
51 ctl->server.pollname);
55 /* make sure we don't enter the fetch loop */
56 *bytes = *countp = *newp = -1;
59 * By default, the hostlist has a single entry, the fetchmail host's
62 for (qnp = ctl->smtphunt; qnp; qnp = qnp->next)
64 /* ship the actual poll and get the response */
65 gen_send(sock, "ETRN %s", qnp->id);
66 if ((ok = gen_recv(sock, buf, sizeof(buf))))
69 /* this switch includes all response codes described in RFC1985 */
72 case 250: /* OK, queuing for node <x> started */
73 if (outlevel >= O_SILENT)
74 error(0, 0, _("Queuing for %s started"), qnp->id);
77 case 251: /* OK, no messages waiting for node <x> */
78 if (outlevel >= O_SILENT)
79 error(0, 0, _("No messages waiting for %s"), qnp->id);
82 case 252: /* OK, pending messages for node <x> started */
83 case 253: /* OK, <n> pending messages for node <x> started */
84 if (outlevel >= O_SILENT)
85 error(0, 0, _("Pending messages for %s started"), qnp->id);
88 case 458: /* Unable to queue messages for node <x> */
89 error(0, -1, _("Unable to queue messages for node %s"),qnp->id);
92 case 459: /* Node <x> not allowed: <reason> */
93 error(0, -1, _("Node %s not allowed: %s"), qnp->id, buf);
96 case 500: /* Syntax Error */
97 error(0, -1, _("ETRN syntax error"));
100 case 501: /* Syntax Error in Parameters */
101 error(0, -1, _("ETRN syntax error in parameters"));
105 error(0, -1, _("Unknown ETRN error %d"), atoi(buf));
113 static int etrn_logout(int sock, struct query *ctl)
114 /* send logout command */
116 return(gen_transact(sock, "QUIT"));
119 const static struct method etrn =
121 "ETRN", /* ESMTP ETRN extension */
123 "smtp", /* standard SMTP port */
125 25, /* standard 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 password canonicalization */
131 NULL, /* no need to get authentication */
132 etrn_getrange, /* initialize message sending */
133 NULL, /* we cannot get a list of sizes */
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 etrn_logout, /* log out, we're done */
140 FALSE, /* no, we can't re-poll */
143 int doETRN (struct query *ctl)
144 /* retrieve messages using ETRN */
149 fprintf(stderr, _("Option --keep is not supported with ETRN\n"));
153 fprintf(stderr, _("Option --flush is not supported with ETRN\n"));
156 if (ctl->mailboxes->id) {
157 fprintf(stderr, _("Option --remote is not supported with ETRN\n"));
161 fprintf(stderr, _("Option --check is not supported with ETRN\n"));
164 peek_capable = FALSE;
166 status = do_protocol(ctl, &etrn);
167 if (status == PS_NOMAIL)
171 #endif /* ETRN_ENABLE */
173 /* etrn.c ends here */