diff -Naur courier-0.43.1.orig/courier/aliases.config courier-0.43.1/courier/aliases.config --- courier-0.43.1.orig/courier/aliases.config Fri Feb 4 03:43:26 2000 +++ courier-0.43.1/courier/aliases.config Sat Aug 23 17:47:26 2003 @@ -319,13 +352,93 @@ rwinput(info, func); } +/* Helper functions to set the host */ + +static char *get_esmtproutes() +{ +char *filename=config_search("esmtproutes"); +char *buf=readfile(filename, 0); + + free(filename); + if (!buf) return (0); + + removecomments(buf); + return (buf); +} + +static char *fetch_mailhost(const char *domain) +{ +char *buf=get_esmtproutes(); +const char *p=buf; + + while (*p) + { + unsigned i; + + for (i=0; p[i] && p[i] != '\n' && p[i] != '\r' && p[i] != ':'; i++) + ; + //need to check for either a smarthost or another route for this host + if (p[i] == ':' && (i == 0 || config_domaincmp(domain, p, i) == 0)) + { + //we only want to actually set the host to the smart host if there is no other route to host + if (i == 0) + { + char *q; + + ++p; + for (i=0; p[i] && p[i] != '\n' && p[i] != '\r' && p[i] != ',' && p[i] != '/'; i++) + ; + + while (i && isspace((int)(unsigned char)p[i-1])) + --i; + while (i && isspace((int)(unsigned char)*p)) + { + ++p; + --i; + } + if (i == 0) + { + free(buf); + return (0); + } + + q=courier_malloc(i+1); + memcpy(q, p, i); + q[i]=0; + free(buf); + return (q); + } + else + { + free(buf); + return (0); + } + } + + while (p[i]) + { + if (p[i] == '\n' || p[i] == '\r') + { + ++i; + break; + } + ++i; + } + p += i; + } + + free(buf); + return (0); +} + + static void rw_del_esmtp(struct rw_info *rwi, void (*nextfunc)(struct rw_info *), void (*delfunc)(struct rw_info *, const struct rfc822token *, const struct rfc822token *)) { struct rfc822token *p; -char *c; +char *c, *r; struct rfc822token host, addr; for (p=rwi->ptr; p; p=p->next) @@ -363,6 +476,8 @@ host.next=0; host.token=0; host.ptr=strchr(c, '@')+1; + r = fetch_mailhost(host.ptr); + if (r != NULL) host.ptr=r; host.len=strlen(host.ptr); addr.next=0; addr.token=0; @@ -371,6 +486,7 @@ (*delfunc)(rwi, &host, &addr); free(c); + free(r); }