diff -urN qmail-1.03.orig/Makefile qmail-1.03/Makefile
--- qmail-1.03.orig/Makefile	2009-11-03 16:42:15.000000000 -0200
+++ qmail-1.03/Makefile	2009-11-03 16:42:42.000000000 -0200
@@ -2061,13 +2061,13 @@
 timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o received.o \
 date822fmt.o now.o qmail.o execcheck.o cdb.a smtpcall.o coe.o fd.a \
 seek.a wait.a datetime.a getln.a open.a sig.a case.a env.a stralloc.a \
-alloc.a substdio.a error.a str.a fs.a auto_qmail.o auto_break.o \
+alloc.a strerr.a substdio.a error.a str.a fs.a auto_qmail.o auto_break.o \
 dns.lib socket.lib
 	./load qmail-smtpd rcpthosts.o commands.o timeoutread.o rbl.o \
 	timeoutwrite.o ip.o ipme.o ipalloc.o control.o constmap.o \
 	received.o date822fmt.o now.o qmail.o execcheck.o cdb.a \
 	smtpcall.o coe.o fd.a seek.a wait.a datetime.a getln.a \
-	open.a sig.a case.a env.a stralloc.a alloc.a substdio.a \
+	open.a sig.a case.a env.a stralloc.a alloc.a strerr.a substdio.a \
 	error.a fs.a auto_qmail.o dns.o str.a auto_break.o \
 	`cat dns.lib` `cat socket.lib` $(TLSLIBS) $(ZLIB)
 
@@ -2340,7 +2340,7 @@
 FILES BLURB BLURB2 BLURB3 BLURB4 README FAQ INSTALL INSTALL.alias \
 INSTALL.ctl INSTALL.ids INSTALL.maildir INSTALL.mbox INSTALL.vsm \
 REMOVE.sendmail REMOVE.binmail TEST.deliver TEST.receive UPGRADE \
-THOUGHTS TODO THANKS CHANGES SECURITY INTERNALS SENDMAIL \
+THOUGHTS TODO THANKS CHANGES SECURITY INTERNALS SENDMAIL README.GREETDELAY \
 PIC.local2alias PIC.local2ext PIC.local2local PIC.local2rem \
 PIC.local2virt PIC.nullclient PIC.relaybad PIC.relaygood \
 PIC.rem2local FILES VERSION SYSDEPS TARGETS Makefile BIN.README \
diff -urN qmail-1.03.orig/README.GREETDELAY qmail-1.03/README.GREETDELAY
--- qmail-1.03.orig/README.GREETDELAY	1969-12-31 21:00:00.000000000 -0300
+++ qmail-1.03/README.GREETDELAY	2009-11-03 16:42:42.000000000 -0200
@@ -0,0 +1,25 @@
+This patch is a port of the qmail greetdelay patch by
+John M. Simpson <jms1@spamcop.net>.
+
+The code checks for the existence of the GRTDELAY env var, which should be
+set to the amount of seconds that qmail-smtpd should wait until sending out
+the SMTP greeting message. If GRTDELAY is set but no value is specified (eg,
+GRTDELAY="" or > /var/qmail/boot/qmail-smtpd/env/GRTDELAY), the default value
+of zero will be used.
+
+In addition to GRTDELAY, the env var DROP_PRE_GREET can also be set to "1".
+In that case, no only qmail-smtpd will delay the SMTP greeting, but will also
+make qmail-smtpd enforce the SMTP rfc, exiting with an SMTP protocol violation
+error if any data is sent to the server before the greeting message is 
+presented.
+
+Hugo Monteiro <hugo.monteiro@fct.unl.pt> has ported this patch do qmail-ldap.
+
+Patrick Tracanelli <patrick@freebsdbrasil.com.br> has added it to the FreeBSD
+Ports Collection with the following changes:
+
+- Compiler switch DGREETDELAY is not needed. Once this patch is applied, the
+feature is compiled in.
+- Enhaced logs for Disconnected_Before_Greet and Sent_Data_Before_Greet errs
+
+
diff -urN qmail-1.03.orig/qmail-smtpd.c qmail-1.03/qmail-smtpd.c
--- qmail-1.03.orig/qmail-smtpd.c	2009-11-03 16:42:15.000000000 -0200
+++ qmail-1.03/qmail-smtpd.c	2009-11-03 16:42:42.000000000 -0200
@@ -4,6 +4,7 @@
 #include "stralloc.h"
 #include "substdio.h"
 #include "subfd.h"
+#include "strerr.h"
 #include "alloc.h"
 #include "auto_qmail.h"
 #include "auto_break.h"
@@ -46,6 +47,8 @@
 #define MAXHOPS 100
 #define MAXLINELEN 10000
 unsigned long databytes = 0;
+unsigned int greetdelay = 0;
+unsigned int drop_pre_greet = 0;
 int timeout = 1200;
 
 #ifdef TLS_SMTPD
@@ -161,6 +164,7 @@
 void die_control(void) { out("421 unable to read controls (#4.3.0)\r\n"); logline(1,"unable to read controls, closing connection"); flush(); _exit(1); }
 void die_ipme(void) { out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); logline(1,"unable to figure out my IP address, closing connection"); flush(); _exit(1); }
 void straynewline(void) { out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"); logline(1,"stray new line detected, closing connection"); flush(); _exit(1); }
+void die_pre_greet() { out("554 SMTP protocol violation\r\n"); flush(); _exit(1); }
 void oversizedline(void) { out("500 Text line too long."); logline(1,"Oversized line in data part, closing connection"); flush(); _exit(1); }
 void err_qqt(void) { out("451 qqt failure (#4.3.0)\r\n"); }
 void err_dns(void) { out("421 DNS temporary failure at return MX check, try again later (#4.3.0)\r\n"); }
@@ -412,7 +416,12 @@
   x = env_get("DATABYTES");
   if (x) scan_ulong(x,&databytes);
   if (!(databytes + 1)) --databytes; /* poor man overflow detection */
- 
+
+  x = env_get("GRTDELAY");
+  if((x) && !(relayok)) { scan_ulong(x,&u); greetdelay = u; }
+  x = env_get("DROP_PRE_GREET");
+  if(x) { scan_ulong(x,&u); drop_pre_greet = u; }
+
   remoteip = env_get("TCPREMOTEIP");
   if (!remoteip) remoteip = "unknown";
   remotehost = env_get("TCPREMOTEHOST");
@@ -1735,10 +1744,32 @@
 #ifdef TLS_SMTPD
   sig_alarmcatch(sigalrm);
 #endif
+  int x;
   sig_pipeignore();
   if (chdir(auto_qmail) == -1) die_control();
   setup();
   if (ipme_init() != 1) die_ipme();
+  if (!relayclient) {
+    if (greetdelay||drop_pre_greet) {
+    x = timeoutread(greetdelay?greetdelay:0,0,ssinbuf,sizeof ssinbuf);
+    if(-1 == x) {
+      if(errno != error_timeout)
+        strerr_die1sys(1,"qmail-smtpd: before greeting: ");
+      } else if ( 0 == x ) {
+       /* FreeBSD Brasil: enhace logging */
+       logstring(2,"Reject::HELO::Disconnected_Before_Greet: S:");
+       logstring(2,remoteip);
+       logflush(2);
+        strerr_die1x(1,"qmail-smtpd: before greeting: client disconnected");
+      } else if ( drop_pre_greet ) {
+      /* FreeBSD Brasil: enhace logging */
+       logstring(2,"Reject::HELO::Sent_Data_Before_Greet: S:");
+       logstring(2,remoteip);
+       logflush(2);
+        die_pre_greet();
+      }
+    }
+  }
   if (greeting550 || greeting421) {
     if (!stralloc_copys(&greeting,greeting550 ? greeting550 : greeting421))
       die_nomem();
