2 * etrn.c -- ETRN protocol methods
4 * For license terms, see the file COPYING in this directory.
16 #include "fetchmail.h"
20 static int etrn_ok (int sock, char *argbuf)
21 /* parse command response */
26 if (ok == SM_UNRECOVERABLE)
32 static int etrn_getrange(int sock, struct query *ctl, const char *id,
33 int *countp, int *newp, int *bytes)
34 /* send ETRN and interpret the response */
37 char buf [MSGBUFSIZE+1];
38 struct idlist *qnp; /* pointer to Q names */
40 if ((ok = SMTP_ehlo(sock, fetchmailhost, &opts)))
42 report(stderr, _("%s's SMTP listener does not support ESMTP\n"),
43 ctl->server.pollname);
46 else if (!(opts & ESMTP_ETRN))
48 report(stderr, _("%s's SMTP listener does not support ETRN\n"),
49 ctl->server.pollname);
53 /* make sure we don't enter the fetch loop */
54 *bytes = *countp = *newp = -1;
57 * By default, the hostlist has a single entry, the fetchmail host's
60 for (qnp = ctl->smtphunt; qnp; qnp = qnp->next)
62 /* ship the actual poll and get the response */
63 gen_send(sock, "ETRN %s", qnp->id);
64 if ((ok = gen_recv(sock, buf, sizeof(buf))))
67 /* this switch includes all response codes described in RFC1985 */
70 case 250: /* OK, queuing for node <x> started */
71 if (outlevel >= O_SILENT)
72 report(stdout, _("Queuing for %s started\n"), qnp->id);
75 case 251: /* OK, no messages waiting for node <x> */
76 if (outlevel >= O_SILENT)
77 report(stdout, _("No messages waiting for %s\n"), qnp->id);
80 case 252: /* OK, pending messages for node <x> started */
81 case 253: /* OK, <n> pending messages for node <x> started */
82 if (outlevel >= O_SILENT)
83 report(stdout, _("Pending messages for %s started\n"), qnp->id);
86 case 458: /* Unable to queue messages for node <x> */
87 report(stderr, _("Unable to queue messages for node %s\n"),qnp->id);
90 case 459: /* Node <x> not allowed: <reason> */
91 report(stderr, _("Node %s not allowed: %s\n"), qnp->id, buf);
94 case 500: /* Syntax Error */
95 report(stderr, _("ETRN syntax error\n"));
98 case 501: /* Syntax Error in Parameters */
99 report(stderr, _("ETRN syntax error in parameters\n"));
103 report(stderr, _("Unknown ETRN error %d\n"), atoi(buf));
111 static int etrn_logout(int sock, struct query *ctl)
112 /* send logout command */
114 return(gen_transact(sock, "QUIT"));
117 const static struct method etrn =
119 "ETRN", /* ESMTP ETRN extension */
121 "smtp", /* standard SMTP port */
123 25, /* standard SMTP port */
125 FALSE, /* this is not a tagged protocol */
126 FALSE, /* this does not use a message delimiter */
127 etrn_ok, /* parse command response */
128 NULL, /* no password canonicalization */
129 NULL, /* no need to get authentication */
130 etrn_getrange, /* initialize message sending */
131 NULL, /* we cannot get a list of sizes */
132 NULL, /* how do we tell a message is old? */
133 NULL, /* no way to fetch headers */
134 NULL, /* no way to fetch body */
135 NULL, /* no message trailer */
136 NULL, /* how to delete a message */
137 etrn_logout, /* log out, we're done */
138 FALSE, /* no, we can't re-poll */
141 int doETRN (struct query *ctl)
142 /* retrieve messages using ETRN */
147 fprintf(stderr, _("Option --keep is not supported with ETRN\n"));
151 fprintf(stderr, _("Option --flush is not supported with ETRN\n"));
154 if (ctl->mailboxes->id) {
155 fprintf(stderr, _("Option --remote is not supported with ETRN\n"));
159 fprintf(stderr, _("Option --check is not supported with ETRN\n"));
162 peek_capable = FALSE;
164 status = do_protocol(ctl, &etrn);
165 if (status == PS_NOMAIL)
169 #endif /* ETRN_ENABLE */
171 /* etrn.c ends here */