--- amavisd.orig	2008-09-22 11:21:15.000000000 +0200
+++ amavisd	2008-09-22 11:23:53.000000000 +0200
@@ -16878,13 +16878,18 @@
       $data_command_accepted = $smtp_resp=~/^3/ ? 1 : 0;
       if (!$data_command_accepted) {
         do_log(0,"Negative SMTP resp. to DATA: %s", $smtp_resp);
+	$in_datasend_mode = 0; 
+	$smtp_session->timeout($smtp_rset_timeout); 
+	$what_cmd = 'RSET';  $smtp_handle->rset;  # send a RSET 
       } elsif (!$any_valid_recips) {  # pipelining
         do_log(2,"Too late, DATA accepted but no valid recips, send dummy");
         $which_section = 'fwd-data-contents';
         $smtp_session->timeout(
-          max(60,min($smtp_data_xfer_timeout,$deadline-time)));
+	  max(60,min($smtp_data_done_timeout,$deadline-time))); 
+	$what_cmd = 'data-dot'; 
         $smtp_handle->dataend;  # as required by rfc2920: if the DATA command
                       # was accepted the SMTP client should send a single dot
+	$in_datasend_mode = 0;
       } elsif ($any_tempfail_recips && !$dsn_per_recip_capable) {  # pipelining
         # we must not proceed if mail did not came in as LMTP,
         # or we would generate mail duplicates on each delivery attempt
