diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1997-09-16 23:24:18 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1997-09-16 23:24:18 +0000 |
commit | 763d1ace340134df6a237469bb5b76bc86cbbbec (patch) | |
tree | 35e2807b4c60c9e7719a5635c48780fea1d14e64 /etrn.c | |
parent | 54f14b712e3e8f6007192dfdc2c94d6aec369946 (diff) | |
download | fetchmail-763d1ace340134df6a237469bb5b76bc86cbbbec.tar.gz fetchmail-763d1ace340134df6a237469bb5b76bc86cbbbec.tar.bz2 fetchmail-763d1ace340134df6a237469bb5b76bc86cbbbec.zip |
improved ETRN handling.
svn path=/trunk/; revision=1358
Diffstat (limited to 'etrn.c')
-rw-r--r-- | etrn.c | 135 |
1 files changed, 46 insertions, 89 deletions
@@ -30,10 +30,9 @@ static int etrn_getrange(int sock, struct query *ctl, char *id, int *countp, int *newp) /* send ETRN and interpret the response */ { - int ok, opts, qdone = 0; + int ok, opts; char buf [POPBUFSIZE+1], hname[256]; - const char *qname; struct idlist *qnp; /* pointer to Q names */ struct hostent *hp; @@ -52,98 +51,56 @@ static int etrn_getrange(int sock, struct query *ctl, char *id, int *countp, *countp = *newp = -1; /* make sure we don't enter the fetch loop */ - /*** This is a sort of horrible HACK because the ETRN protocol - *** does not fit very well into the mailbox concept used in - *** this program (IMHO). The last element of ctl->smtphunt - *** turned out to be the host being queried (i.e., the smtp server). - *** for that reason the rather "funny" condition in the for loop. - *** Isn't it sort of unreasonable to add the server to the ETRN - *** hunt list? (Concerning ETRN I'm sure! In case I want a Q-run of - *** my SMTP-server I can always specify -Smyserver, and this is only - *** resonable if I start sendmail without -qtime and in Q-only mode.) - *** - *** -- 1997-06-22 Guenther Leber - ***/ - /* do it for all queues in the smtphunt list except the last one - which is the SMTP-server itself */ - for (qnp = ctl->smtphunt; ( (qnp != (struct idlist *) NULL) && - (qnp->next != (struct idlist *) NULL) ) || (qdone == 0); - qnp = qnp->next, qdone++) - { - - /* extract name of Q */ - if ( (qnp != (struct idlist *) NULL) && - (qnp->next != (struct idlist *) NULL) ) + /* + * Do it for all nondefault queues in the smtphunt list. + * We can tell the nondefault ones because they have a TRUE num field. + */ + for (qnp = ctl->smtphunt; qnp; qnp = qnp->next) + if (qnp->val.num) { - /* take Q-name given in smtp hunt list */ - qname = qnp->id; - } else { - assert(qdone == 0); - /*** use fully qualified host name as Q name ***/ - /* get hostname */ - if (gethostname(hname, sizeof hname) != 0) - { - /* exit with error message */ - error(0, errno, "gethostname failed: "); - return PS_UNDEFINED; - } - /* in case we got a host basename (as we do in Linux), - make a FQDN of it */ - hp = gethostbyname(hname); - if (hp == (struct hostent *) NULL) + /* ship the actual poll and get the response */ + gen_send(sock, "ETRN %s", qnp->id); + if ((ok = gen_recv(sock, buf, sizeof(buf)))) + return(ok); + + /* this switch includes all response codes described in RFC1985 */ + switch(atoi(buf)) { - /* exit with error message */ - error(0, 0, "gethostbyname failed for %s", hname); - return PS_TRANSIENT; + case 250: /* OK, queuing for node <x> started */ + error(0, 0, "Queuing for %s started", qnp->id); + break; + + case 251: /* OK, no messages waiting for node <x> */ + error(0, 0, "No messages waiting for %s", qnp->id); + return(PS_NOMAIL); + + case 252: /* OK, pending messages for node <x> started */ + case 253: /* OK, <n> pending messages for node <x> started */ + error(0, 0, "Pending messages for %s started", qnp->id); + break; + + case 458: /* Unable to queue messages for node <x> */ + error(0, -1, "Unable to queue messages for node %s",qnp->id); + return(PS_PROTOCOL); + + case 459: /* Node <x> not allowed: <reason> */ + error(0, -1, "Node %s not allowed: %s", qnp->id, buf); + return(PS_AUTHFAIL); + + case 500: /* Syntax Error */ + error(0, -1, "ETRN syntax error"); + return(PS_PROTOCOL); + + case 501: /* Syntax Error in Parameters */ + error(0, -1, "ETRN syntax error in parameters"); + return(PS_PROTOCOL); + + default: + error(0, -1, "Unknown ETRN error %d", atoi(buf)); + return(PS_PROTOCOL); } - /* here it is */ - qname = hp->h_name; } - - /* ship the actual poll and get the response */ - gen_send(sock, "ETRN %s", qname); - if ((ok = gen_recv(sock, buf, sizeof(buf)))) - return(ok); - - /* this switch includes all the response codes described in RFC1985 */ - switch(atoi(buf)) - { - case 250: /* OK, queuing for node <x> started */ - error(0, 0, "Queuing for %s started", qname); - break; - - case 251: /* OK, no messages waiting for node <x> */ - error(0, 0, "No messages waiting for %s", qname); - return(PS_NOMAIL); - - case 252: /* OK, pending messages for node <x> started */ - case 253: /* OK, <n> pending messages for node <x> started */ - error(0, 0, "Pending messages for %s started", qname); - break; - - case 458: /* Unable to queue messages for node <x> */ - error(0, -1, "Unable to queue messages for node %s", qname); - return(PS_PROTOCOL); - - case 459: /* Node <x> not allowed: <reason> */ - error(0, -1, "Node %s not allowed: %s", qname, buf); - return(PS_AUTHFAIL); - - case 500: /* Syntax Error */ - error(0, -1, "ETRN syntax error"); - return(PS_PROTOCOL); - - case 501: /* Syntax Error in Parameters */ - error(0, -1, "ETRN syntax error in parameters"); - return(PS_PROTOCOL); - - default: - error(0, -1, "Unknown ETRN error %d", atoi(buf)); - return(PS_PROTOCOL); - } - } - return(0); } |