*** qmail-smtpd.c.orig	Fri Jul  6 16:27:32 2001
--- qmail-smtpd.c	Fri Jul  6 16:41:05 2001
***************
*** 51,56 ****
--- 51,57 ----
  
  void err_bmf() { out("553 sorry, your envelope sender is in my badmailfrom list (#5.7.1)\r\n"); }
  void err_nogateway() { out("553 sorry, that domain isn't in my list of allowed rcpthosts (#5.7.1)\r\n"); }
+ void err_relayhack(s) char *s; { out("553 "); out(s); out(" (#5.7.1)\r\n"); }
  void err_unimpl() { out("502 unimplemented (#5.5.1)\r\n"); }
  void err_syntax() { out("555 syntax error (#5.5.4)\r\n"); }
  void err_wantmail() { out("503 MAIL first (#5.5.1)\r\n"); }
***************
*** 81,86 ****
--- 82,88 ----
  char *remoteinfo;
  char *local;
  char *relayclient;
+ char *barfrelayhack;
  
  stralloc helohost = {0};
  char *fakehelo; /* pointer into helohost, or 0 */
***************
*** 131,136 ****
--- 133,139 ----
    if (!remotehost) remotehost = "unknown";
    remoteinfo = env_get("TCPREMOTEINFO");
    relayclient = env_get("RELAYCLIENT");
+   barfrelayhack = env_get("BARFRELAYHACK");
    dohelo(remotehost);
  }
  
***************
*** 247,252 ****
--- 250,271 ----
    if (!stralloc_0(&mailfrom)) die_nomem();
    out("250 ok\r\n");
  }
+ int relayhack(s) char *s; {
+   int at;
+   at = 0;
+   while (*s) {
+     if (at) {
+       if (*s == '@') return 1;
+     }
+     else {
+       if (*s == '!') return 1;
+       if (*s == '%') return 1;
+       if (*s == '@') at++;
+     }
+     s++;
+   }
+   return 0;
+ }
  void smtp_rcpt(arg) char *arg; {
    if (!seenmail) { err_wantmail(); return; }
    if (!addrparse(arg)) { err_syntax(); return; }
***************
*** 256,261 ****
--- 275,282 ----
      if (!stralloc_cats(&addr,relayclient)) die_nomem();
      if (!stralloc_0(&addr)) die_nomem();
    }
+   else
+     if (barfrelayhack && relayhack(addr.s)) { err_relayhack(barfrelayhack); return; }
    else
      if (!addrallowed()) { err_nogateway(); return; }
    if (!stralloc_cats(&rcptto,"T")) die_nomem();

