2 * etrn.c -- ETRN protocol methods
4 * For license terms, see the file COPYING in this directory.
15 #include "fetchmail.h"
19 static int etrn_ok (int sock, char *argbuf)
20 /* parse command response */
25 if (ok == SM_UNRECOVERABLE)
31 static int etrn_getrange(int sock, struct query *ctl, char *id, int *countp,
33 /* send ETRN and interpret the response */
36 char buf [POPBUFSIZE+1];
37 struct idlist *qnp; /* pointer to Q names */
39 if ((ok = SMTP_ehlo(sock, ctl->server.truename, &opts)))
41 error(0, 0, "%s's SMTP listener does not support ESMTP",
42 ctl->server.pollname);
45 else if (!(opts & ESMTP_ETRN))
47 error(0, 0, "%s's SMTP listener does not support ETRN",
48 ctl->server.pollname);
52 *countp = *newp = -1; /* make sure we don't enter the fetch loop */
55 * Do it for all nondefault queues in the smtphunt list.
56 * We can tell the nondefault ones because they have a TRUE num field.
58 for (qnp = ctl->smtphunt; qnp; qnp = qnp->next)
61 /* ship the actual poll and get the response */
62 gen_send(sock, "ETRN %s", qnp->id);
63 if ((ok = gen_recv(sock, buf, sizeof(buf))))
66 /* this switch includes all response codes described in RFC1985 */
69 case 250: /* OK, queuing for node <x> started */
70 error(0, 0, "Queuing for %s started", qnp->id);
73 case 251: /* OK, no messages waiting for node <x> */
74 error(0, 0, "No messages waiting for %s", qnp->id);
77 case 252: /* OK, pending messages for node <x> started */
78 case 253: /* OK, <n> pending messages for node <x> started */
79 error(0, 0, "Pending messages for %s started", qnp->id);
82 case 458: /* Unable to queue messages for node <x> */
83 error(0, -1, "Unable to queue messages for node %s",qnp->id);
86 case 459: /* Node <x> not allowed: <reason> */
87 error(0, -1, "Node %s not allowed: %s", qnp->id, buf);
90 case 500: /* Syntax Error */
91 error(0, -1, "ETRN syntax error");
94 case 501: /* Syntax Error in Parameters */
95 error(0, -1, "ETRN syntax error in parameters");
99 error(0, -1, "Unknown ETRN error %d", atoi(buf));
107 static int etrn_logout(int sock, struct query *ctl)
108 /* send logout command */
110 return(gen_transact(sock, "QUIT"));
113 const static struct method etrn =
115 "ETRN", /* ESMTP ETRN extension */
116 25, /* standard SMTP port */
117 FALSE, /* this is not a tagged protocol */
118 FALSE, /* this does not use a message delimiter */
119 etrn_ok, /* parse command response */
120 NULL, /* no need to get authentication */
121 etrn_getrange, /* initialize message sending */
122 NULL, /* we cannot get a list of sizes */
123 NULL, /* how do we tell a message is old? */
124 NULL, /* no way to fetch headers */
125 NULL, /* no way to fetch body */
126 NULL, /* no message trailer */
127 NULL, /* how to delete a message */
128 etrn_logout, /* log out, we're done */
129 FALSE, /* no, we can't re-poll */
132 int doETRN (struct query *ctl)
133 /* retrieve messages using ETRN */
138 fprintf(stderr, "Option --keep is not supported with ETRN\n");
142 fprintf(stderr, "Option --flush is not supported with ETRN\n");
145 if (ctl->mailboxes->id) {
146 fprintf(stderr, "Option --remote is not supported with ETRN\n");
150 fprintf(stderr, "Option --check is not supported with ETRN\n");
153 peek_capable = FALSE;
155 status = do_protocol(ctl, &etrn);
156 if (status == PS_NOMAIL)
160 #endif /* ETRN_ENABLE */
162 /* etrn.c ends here */