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 ok = SMTP_ok(sock, SMTP_MODE, TIMEOUT_DEFAULT);
30 if (ok == SM_UNRECOVERABLE)
36 static int etrn_getrange(int sock, struct query *ctl, const char *id,
37 int *countp, int *newp, int *bytes)
38 /* send ETRN and interpret the response */
41 char buf [MSGBUFSIZE+1];
42 struct idlist *qnp; /* pointer to Q names */
45 if ((ok = SMTP_ehlo(sock, SMTP_MODE, fetchmailhost,
46 ctl->server.esmtp_name, ctl->server.esmtp_password,
49 report(stderr, GT_("%s's SMTP listener does not support ESMTP\n"),
50 ctl->server.pollname);
53 else if (!(opts & ESMTP_ETRN))
55 report(stderr, GT_("%s's SMTP listener does not support ETRN\n"),
56 ctl->server.pollname);
60 /* make sure we don't enter the fetch loop */
61 *bytes = *countp = *newp = -1;
64 * By default, the hostlist has a single entry, the fetchmail host's
67 for (qnp = ctl->domainlist; qnp; qnp = qnp->next)
69 /* ship the actual poll and get the response */
70 gen_send(sock, "ETRN %s", qnp->id);
71 if ((ok = gen_recv(sock, buf, sizeof(buf))))
74 /* this switch includes all response codes described in RFC1985 */
77 case 250: /* OK, queuing for node <x> started */
78 if (outlevel > O_SILENT)
79 report(stdout, GT_("Queuing for %s started\n"), qnp->id);
82 case 251: /* OK, no messages waiting for node <x> */
83 if (outlevel > O_SILENT)
84 report(stdout, GT_("No messages waiting for %s\n"), qnp->id);
87 case 252: /* OK, pending messages for node <x> started */
88 case 253: /* OK, <n> pending messages for node <x> started */
89 if (outlevel > O_SILENT)
90 report(stdout, GT_("Pending messages for %s started\n"), qnp->id);
93 case 458: /* Unable to queue messages for node <x> */
94 report(stderr, GT_("Unable to queue messages for node %s\n"),qnp->id);
97 case 459: /* Node <x> not allowed: <reason> */
98 report(stderr, GT_("Node %s not allowed: %s\n"), qnp->id, buf);
101 case 500: /* Syntax Error */
102 report(stderr, GT_("ETRN syntax error\n"));
105 case 501: /* Syntax Error in Parameters */
106 report(stderr, GT_("ETRN syntax error in parameters\n"));
110 report(stderr, GT_("Unknown ETRN error %d\n"), atoi(buf));
118 static int etrn_logout(int sock, struct query *ctl)
119 /* send logout command */
122 return(gen_transact(sock, "QUIT"));
125 static const struct method etrn =
127 "ETRN", /* ESMTP ETRN extension */
128 "smtp", /* standard SMTP port */
129 "smtps", /* ssl SMTP port */
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, /* we cannot get a list of sizes of subsets */
137 NULL, /* how do we tell a message is old? */
138 NULL, /* no way to fetch headers */
139 NULL, /* no way to fetch body */
140 NULL, /* no message trailer */
141 NULL, /* how to delete a message */
142 NULL, /* how to mark a message as seen */
143 NULL, /* no mailbox support */
144 etrn_logout, /* log out, we're done */
145 FALSE, /* no, we can't re-poll */
148 int doETRN (struct query *ctl)
149 /* retrieve messages using ETRN */
154 fprintf(stderr, GT_("Option --keep is not supported with ETRN\n"));
158 fprintf(stderr, GT_("Option --flush is not supported with ETRN\n"));
161 if (ctl->mailboxes->id) {
162 fprintf(stderr, GT_("Option --folder is not supported with ETRN\n"));
166 fprintf(stderr, GT_("Option --check is not supported with ETRN\n"));
169 peek_capable = FALSE;
171 status = do_protocol(ctl, &etrn);
172 if (status == PS_NOMAIL)
176 #endif /* ETRN_ENABLE */
178 /* etrn.c ends here */