2 * odmr.c -- ODMR protocol methods (see RFC 2645)
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>
15 #include <sys/types.h>
17 #ifdef HAVE_NET_SELECT_H /* AIX needs this */
18 #include <net/select.h>
24 #include "fetchmail.h"
28 static int odmr_ok (int sock, char *argbuf)
29 /* parse command response */
34 if (ok == SM_UNRECOVERABLE)
40 static int odmr_getrange(int sock, struct query *ctl, const char *id,
41 int *countp, int *newp, int *bytes)
42 /* send ODMR and then run a reverse SMTP session */
44 int ok, opts, smtp_sock;
45 char buf [MSGBUFSIZE+1];
46 struct idlist *qnp; /* pointer to Q names */
48 if ((ok = SMTP_ehlo(sock, fetchmailhost, &opts)))
50 report(stderr, _("%s's SMTP listener does not support ESMTP\n"),
51 ctl->server.pollname);
54 else if (!(opts & ESMTP_ATRN))
56 report(stderr, _("%s's SMTP listener does not support ATRN\n"),
57 ctl->server.pollname);
61 /* make sure we don't enter the fetch loop */
62 *bytes = *countp = *newp = -1;
64 /* authenticate via CRAM-MD5 */
65 ok = do_cram_md5(sock, "AUTH", ctl);
70 * By default, the hostlist has a single entry, the fetchmail host's
74 for (qnp = ctl->smtphunt; qnp; qnp = qnp->next)
75 if (strlen(buf) + strlen(qnp->id) + 1 >= sizeof(buf))
82 buf[strlen(buf) - 1] = '\0'; /* nuke final comma */
84 /* ship the domain list and get turnaround */
85 gen_send(sock, "ATRN %s", buf);
86 if ((ok = gen_recv(sock, buf, sizeof(buf))))
89 /* this switch includes all response codes described in RFC2645 */
92 case 250: /* OK, turnaround is about to happe */
93 if (outlevel >= O_SILENT)
94 report(stdout, _("Turnaround now...\n"));
97 case 450: /* ATRN request refused */
98 if (outlevel >= O_SILENT)
99 report(stdout, _("ATRN request refused.\n"));
102 case 451: /* Unable to process ATRN request now */
103 report(stderr, _("Unable to process ATRN request now\n"));
106 case 453: /* You have no mail */
107 report(stderr, _("You have no mail.\n"));
110 case 502: /* Command not implemented */
111 report(stderr, _("Command not implemented\n"));
114 case 530: /* Authentication required */
115 report(stderr, _("Authentication required.\n"));
119 report(stderr, _("Unknown ODMR error %d\n"), atoi(buf));
124 * OK, if we got here it's time to become a pipe between the ODMR
125 * remote server (sending) and the local SMTP daemon (receiving).
126 * We're npt going to try to be a protocol machine; instead, we'll
127 * use select(2) to watch the read sides of both sockets and just
128 * throw their data at each other.
130 smtp_sock = SockOpen(ctl->smtphost, SMTP_PORT, NULL, NULL);
135 int maxfd = (sock > smtp_sock) ? sock : smtp_sock;
140 struct timeval timeout;
141 char buf[MSGBUFSIZE];
144 FD_SET(sock, &readfds);
145 FD_SET(smtp_sock, &readfds);
147 timeout.tv_sec = ctl->server.timeout;
150 if (select(maxfd+1, &readfds, NULL, NULL, &timeout) == -1)
151 return(PS_PROTOCOL); /* timeout */
153 if (FD_ISSET(sock, &readfds))
155 int n = SockRead(sock, buf, sizeof(buf));
159 SockWrite(smtp_sock, buf, n);
160 if (outlevel >= O_MONITOR)
161 report(stdout, "ODMR< %s\n", buf);
163 if (FD_ISSET(smtp_sock, &readfds))
165 int n = SockRead(smtp_sock, buf, sizeof(buf));
169 SockWrite(sock, buf, n);
170 if (outlevel >= O_MONITOR)
171 report(stdout, "ODMR> %s\n", buf);
174 SockClose(smtp_sock);
180 const static struct method odmr =
182 "ODMR", /* ODMR protocol */
184 "odmr", /* standard SMTP port */
185 "odmrs", /* ssl SMTP port */
186 #else /* INET6_ENABLE */
187 366, /* standard SMTP port */
188 2366, /* ssl SMTP port (BOGUS! RANDOM VALUE) */
189 #endif /* INET6_ENABLE */
190 FALSE, /* this is not a tagged protocol */
191 FALSE, /* this does not use a message delimiter */
192 odmr_ok, /* parse command response */
193 NULL, /* no need to get authentication */
194 odmr_getrange, /* initialize message sending */
195 NULL, /* we cannot get a list of sizes */
196 NULL, /* how do we tell a message is old? */
197 NULL, /* no way to fetch headers */
198 NULL, /* no way to fetch body */
199 NULL, /* no message trailer */
200 NULL, /* how to delete a message */
201 NULL, /* log out, we're done */
202 FALSE, /* no, we can't re-poll */
205 int doODMR (struct query *ctl)
206 /* retrieve messages using ODMR */
211 fprintf(stderr, _("Option --keep is not supported with ODMR\n"));
215 fprintf(stderr, _("Option --flush is not supported with ODMR\n"));
218 if (ctl->mailboxes->id) {
219 fprintf(stderr, _("Option --remote is not supported with ODMR\n"));
223 fprintf(stderr, _("Option --check is not supported with ODMR\n"));
226 peek_capable = FALSE;
228 status = do_protocol(ctl, &odmr);
229 if (status == PS_NOMAIL)
233 #endif /* ODMR_ENABLE */
235 /* odmr.c ends here */