X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=imap.c;h=a598519b59e1685c1d6eee7fb937cc609620837a;hb=87bcf29364c4640edb87cc2186b965d1a564d70c;hp=dca3bab9f51448cba5c3e81804ca775c4773f648;hpb=1e909f8b8b6f9705134389164a211e1eb591c4b6;p=~andy%2Ffetchmail diff --git a/imap.c b/imap.c index dca3bab9..a598519b 100644 --- a/imap.c +++ b/imap.c @@ -10,18 +10,15 @@ #include #include #include -#if defined(STDC_HEADERS) #include #include #include -#endif #include "fetchmail.h" #include "socket.h" -#include "i18n.h" +#include "gettext.h" /* imap_version values */ -#define IMAP2 -1 /* IMAP2 or IMAP2BIS, RFC1176 */ #define IMAP4 0 /* IMAP4 rev 0, RFC1730 */ #define IMAP4rev1 1 /* IMAP4 rev 1, RFC2060 */ @@ -354,12 +351,6 @@ static int capa_probe(int sock, struct query *ctl) report(stdout, GT_("Protocol identified as IMAP4 rev 0\n")); } } - else if (ok == PS_ERROR) - { - imap_version = IMAP2; - if (outlevel >= O_DEBUG) - report(stdout, GT_("Protocol identified as IMAP2 or IMAP2BIS\n")); - } else return ok; @@ -378,7 +369,7 @@ static int capa_probe(int sock, struct query *ctl) report(stdout, GT_("will idle after poll\n")); } - peek_capable = (imap_version >= IMAP4); + peek_capable = TRUE; return PS_SUCCESS; } @@ -447,9 +438,9 @@ static int imap_getauth(int sock, struct query *ctl, char *greeting) * whether TLS is mandatory or opportunistic unless SSLOpen() fails * (see below). */ if (gen_transact(sock, "STARTTLS") == PS_SUCCESS - && SSLOpen(sock, ctl->sslcert, ctl->sslkey, "tls1", ctl->sslcertck, + && (set_timeout(mytimeout), SSLOpen(sock, ctl->sslcert, ctl->sslkey, "tls1", ctl->sslcertck, ctl->sslcertfile, ctl->sslcertpath, ctl->sslfingerprint, commonname, - ctl->server.pollname, &ctl->remotename) != -1) + ctl->server.pollname, &ctl->remotename)) != -1) { /* * RFC 2595 says this: @@ -473,9 +464,11 @@ static int imap_getauth(int sock, struct query *ctl, char *greeting) } else if (must_tls(ctl)) { /* Config required TLS but we couldn't guarantee it, so we must * stop. */ + set_timeout(0); report(stderr, GT_("%s: upgrade to TLS failed.\n"), commonname); return PS_SOCKET; } else { + set_timeout(0); if (outlevel >= O_VERBOSE) { report(stdout, GT_("%s: opportunistic upgrade to TLS failed, trying to continue\n"), commonname); } @@ -540,24 +533,6 @@ static int imap_getauth(int sock, struct query *ctl, char *greeting) } #endif /* GSSAPI */ -#ifdef KERBEROS_V4 - if ((ctl->server.authenticate == A_ANY - || ctl->server.authenticate == A_KERBEROS_V4 - || ctl->server.authenticate == A_KERBEROS_V5) - && strstr(capabilities, "AUTH=KERBEROS_V4")) - { - if ((ok = do_rfc1731(sock, "AUTHENTICATE", ctl->server.truename))) - { - /* SASL cancellation of authentication */ - gen_send(sock, "*"); - if(ctl->server.authenticate != A_ANY) - return ok; - } - else - return ok; - } -#endif /* KERBEROS_V4 */ - /* * No such luck. OK, now try the variants that mask your password * in a challenge-response. @@ -617,15 +592,6 @@ static int imap_getauth(int sock, struct query *ctl, char *greeting) } #endif /* NTLM_ENABLE */ -#ifdef __UNUSED__ /* The Cyrus IMAP4rev1 server chokes on this */ - /* this handles either AUTH=LOGIN or AUTH-LOGIN */ - if ((imap_version >= IMAP4rev1) && (!strstr(capabilities, "LOGIN"))) - { - report(stderr, - GT_("Required LOGIN capability not supported by server\n")); - } -#endif /* __UNUSED__ */ - /* * We're stuck with sending the password en clair. * The reason for this odd-looking logic is that some @@ -774,7 +740,7 @@ static int imap_search(int sock, struct query *ctl, int count) * higher and only when keeping mails. This flag will have an * effect only when user has marked some unread mails for deletion * using another e-mail client. */ - flag skipdeleted = (imap_version >= IMAP4) && ctl->keep; + flag skipdeleted = ctl->keep; const char *undeleted; /* structure to keep the end portion of the incomplete response */ @@ -1164,7 +1130,8 @@ static int imap_fetch_headers(int sock, struct query *ctl,int number,int *lenp) /* try to recover for some responses */ if (!strncmp(buf, "* NO", 4) || - !strncmp(buf, "* BAD", 5)) + !strncmp(buf, "* BAD", 5) || + strstr(buf, "FETCH ()")) { return(PS_TRANSIENT); } @@ -1179,7 +1146,7 @@ static int imap_fetch_headers(int sock, struct query *ctl,int number,int *lenp) /* an unexpected tagged response */ if (outlevel > O_SILENT) report(stderr, GT_("Incorrect FETCH response: %s.\n"), buf); - return(PS_ERROR); + return(PS_TRANSIENT); } return(ok); } @@ -1205,28 +1172,23 @@ static int imap_fetch_body(int sock, struct query *ctl, int number, int *lenp) * equivalent". However, we know of at least one server that * treats them differently in the presence of MIME attachments; * the latter form downloads the attachment, the former does not. - * The server is InterChange, and the fool who implemented this - * misfeature ought to be strung up by his thumbs. + * The server is InterChange. * * When I tried working around this by disabling use of the 4rev1 form, * I found that doing this breaks operation with M$ Exchange. * Annoyingly enough, Exchange's refusal to cope is technically legal - * under RFC2062. Trust Microsoft, the Great Enemy of interoperability - * standards, to find a way to make standards compliance irritating.... + * under RFC2062. */ switch (imap_version) { case IMAP4rev1: /* RFC 2060 */ + default: gen_send(sock, "FETCH %d BODY.PEEK[TEXT]", number); break; case IMAP4: /* RFC 1730 */ gen_send(sock, "FETCH %d RFC822.TEXT.PEEK", number); break; - - default: /* RFC 1176 */ - gen_send(sock, "FETCH %d RFC822.TEXT", number); - break; } /* looking for FETCH response */ @@ -1295,43 +1257,19 @@ static int imap_delete(int sock, struct query *ctl, int number) /* set delete flag for given message */ { int ok; - /* Select which flags to set on message deletion: */ - const char delflags_seen[] = "\\Seen \\Deleted"; - const char delflags_unseen[] = "\\Deleted"; - static const char *delflags; - /* Which environment variable to look for: */ - const char dis_env[] = "FETCHMAIL_IMAP_DELETED_REMAINS_UNSEEN"; - - if (!delflags) { - char *tmp; - if ((tmp = getenv(dis_env)) != NULL && *tmp) { - delflags = delflags_unseen; - } else { - /* DEFAULT since many fetchmail versions <= 6.3.X */ - delflags = delflags_seen; - } - } (void)ctl; /* expunges change the fetch numbers */ number -= expunged; /* - * Use SILENT if possible as a minor throughput optimization. - * Note: this has been dropped from IMAP4rev1. - * - * We set \Seen because there are some IMAP servers (notably HP - * OpenMail and MS Exchange) do message-receipt DSNs, - * but only when the seen bit gets set. - * This is the appropriate time -- we get here right + * We set Seen because there are some IMAP servers (notably HP + * OpenMail) that do message-receipt DSNs, but only when the seen + * bit is set. This is the appropriate time -- we get here right * after the local SMTP response that says delivery was * successful. */ - if ((ok = gen_transact(sock, - imap_version == IMAP4 - ? "STORE %d +FLAGS.SILENT (%s)" - : "STORE %d +FLAGS (%s)", - number, delflags))) + if ((ok = gen_transact(sock, "STORE %d +FLAGS.SILENT (\\Seen \\Deleted)", number))) return(ok); else deletions++; @@ -1359,11 +1297,7 @@ static int imap_mark_seen(int sock, struct query *ctl, int number) /* expunges change the message numbers */ number -= expunged; - return(gen_transact(sock, - imap_version == IMAP4 - ? "STORE %d +FLAGS.SILENT (\\Seen)" - : "STORE %d +FLAGS (\\Seen)", - number)); + return(gen_transact(sock,"STORE %d +FLAGS.SILENT (\\Seen)", number)); } static int imap_end_mailbox_poll(int sock, struct query *ctl)