2 * etrn.c -- ETRN protocol methods (see RFC 1985)
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 ok = SMTP_ok(sock, SMTP_MODE, TIMEOUT_DEFAULT);
27 if (ok == SM_UNRECOVERABLE)
33 static int etrn_getrange(int sock, struct query *ctl, const char *id,
34 int *countp, int *newp, int *bytes)
35 /* send ETRN and interpret the response */
38 char buf [MSGBUFSIZE+1];
39 struct idlist *qnp; /* pointer to Q names */
42 if ((ok = SMTP_ehlo(sock, SMTP_MODE, fetchmailhost,
43 ctl->server.esmtp_name, ctl->server.esmtp_password,
46 report(stderr, GT_("%s's SMTP listener does not support ESMTP\n"),
47 ctl->server.pollname);
50 else if (!(opts & ESMTP_ETRN))
52 report(stderr, GT_("%s's SMTP listener does not support ETRN\n"),
53 ctl->server.pollname);
57 /* make sure we don't enter the fetch loop */
58 *bytes = *countp = *newp = -1;
61 * By default, the hostlist has a single entry, the fetchmail host's
64 for (qnp = ctl->domainlist; qnp; qnp = qnp->next)
66 /* ship the actual poll and get the response */
67 gen_send(sock, "ETRN %s", qnp->id);
68 if ((ok = gen_recv(sock, buf, sizeof(buf))))
71 /* this switch includes all response codes described in RFC1985 */
74 case 250: /* OK, queuing for node <x> started */
75 if (outlevel > O_SILENT)
76 report(stdout, GT_("Queuing for %s started\n"), qnp->id);
79 case 251: /* OK, no messages waiting for node <x> */
80 if (outlevel > O_SILENT)
81 report(stdout, GT_("No messages waiting for %s\n"), qnp->id);
84 case 252: /* OK, pending messages for node <x> started */
85 case 253: /* OK, <n> pending messages for node <x> started */
86 if (outlevel > O_SILENT)
87 report(stdout, GT_("Pending messages for %s started\n"), qnp->id);
90 case 458: /* Unable to queue messages for node <x> */
91 report(stderr, GT_("Unable to queue messages for node %s\n"),qnp->id);
94 case 459: /* Node <x> not allowed: <reason> */
95 report(stderr, GT_("Node %s not allowed: %s\n"), qnp->id, buf);
98 case 500: /* Syntax Error */
99 report(stderr, GT_("ETRN syntax error\n"));
102 case 501: /* Syntax Error in Parameters */
103 report(stderr, GT_("ETRN syntax error in parameters\n"));
107 report(stderr, GT_("Unknown ETRN error %d\n"), atoi(buf));
115 static int etrn_logout(int sock, struct query *ctl)
116 /* 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 */