*** /tmp/qmail-smtpd.c.orig	Tue Sep  4 14:54:00 2001
--- /tmp/qmail-smtpd.c	Tue Sep  4 14:56:52 2001
***************
*** 52,57 ****
--- 52,58 ----
  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_databytes() { out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\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"); }
***************
*** 139,144 ****
--- 140,146 ----
  
  
  stralloc addr = {0}; /* will be 0-terminated, if addrparse returns 1 */
+ char *argshook;	/* address arguments */
  
  int addrparse(arg)
  char *arg;
***************
*** 150,155 ****
--- 152,158 ----
    int flagesc;
    int flagquoted;
   
+   argshook = 0;
    terminator = '>';
    i = str_chr(arg,'<');
    if (arg[i])
***************
*** 173,179 ****
        flagesc = 0;
      }
      else {
!       if (!flagquoted && (ch == terminator)) break;
        switch(ch) {
          case '\\': flagesc = 1; break;
          case '"': flagquoted = !flagquoted; break;
--- 176,185 ----
        flagesc = 0;
      }
      else {
!       if (!flagquoted && (ch == terminator)) {
!         argshook = arg + i + 1;
!         break;
!       }
        switch(ch) {
          case '\\': flagesc = 1; break;
          case '"': flagquoted = !flagquoted; break;
***************
*** 200,205 ****
--- 206,234 ----
    return 1;
  }
  
+ static char c_upper(c) char c; { if (c >= 'a' && c <= 'z') c = c - 'a' + 'A'; return c; }
+ char *addrarg(name)
+ char *name;
+ {
+   char *x; int i;
+ 
+   if (!argshook) return 0;
+   x = argshook;
+   while (*x)
+   {
+     for (i=0;*x;x++,i++)
+     {
+       if (name[i] == 0)
+         return x;
+       if (c_upper(name[i]) != c_upper(*x))
+         break;
+     }
+     while (*x) if (*x++ == ' ') break;
+     while (*x == ' ') x++;
+   } 
+   return 0;
+ }
+ 
  int bmfcheck()
  {
    int j;
***************
*** 242,248 ****
--- 271,284 ----
  }
  void smtp_mail(arg) char *arg;
  {
+   char *x;
+   unsigned long u;
    if (!addrparse(arg)) { err_syntax(); return; }
+   if (databytes)
+     if (x = addrarg("SIZE=")) {
+       scan_ulong(x,&u);
+       if (u > databytes) { err_databytes(); return; }
+     }
    flagbarf = bmfcheck();
    seenmail = 1;
    if (!stralloc_copys(&rcptto,"")) die_nomem();
***************
*** 409,415 ****
    qqx = qmail_close(&qqt);
    if (!*qqx) { acceptmessage(qp); return; }
    if (hops) { out("554 too many hops, this message is looping (#5.4.6)\r\n"); return; }
!   if (databytes) if (!bytestooverflow) { out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n"); return; }
    if (*qqx == 'D') out("554 "); else out("451 ");
    out(qqx + 1);
    out("\r\n");
--- 445,451 ----
    qqx = qmail_close(&qqt);
    if (!*qqx) { acceptmessage(qp); return; }
    if (hops) { out("554 too many hops, this message is looping (#5.4.6)\r\n"); return; }
!   if (databytes) if (!bytestooverflow) { err_databytes(); return; }
    if (*qqx == 'D') out("554 "); else out("451 ");
    out(qqx + 1);
    out("\r\n");

