--- postfix-1.1.11-0.woody3/src/global/mail_params.h	Mon Mar 25 14:22:11 2002
+++ postfix-1.1.11-0.woody3-xheader/src/global/mail_params.h	Fri May  3 23:44:39 2002
@@ -1172,6 +1172,7 @@
 #define CHECK_ETRN_ACL		"check_etrn_access"
 
 #define WARN_IF_REJECT		"warn_if_reject"
+#define XHEADER_IF_REJECT 	"xheader_if_reject"
 
 #define REJECT_MAPS_RBL		"reject_maps_rbl"
 #define VAR_MAPS_RBL_CODE	"maps_rbl_reject_code"
--- postfix-1.1.11-0.woody3/src/smtpd/smtpd.c	Tue Mar 26 22:14:41 2002
+++ postfix-1.1.11-0.woody3-xheader/src/smtpd/smtpd.c	Fri May  3 23:49:36 2002
@@ -963,6 +963,11 @@
     rec_fprintf(state->cleanup, REC_TYPE_NORM,
 		"\t(envelope-from %s)", state->sender);
 #endif
+
+/* This is where we add the X-Header from smtpd_check if it exists. */ 
+    if (LEN(state->xheader))
+	rec_fputs(state->cleanup, REC_TYPE_NORM, STR(state->xheader)); 
+    
     smtpd_chat_reply(state, "354 End data with <CR><LF>.<CR><LF>");
 
     /*
--- postfix-1.1.11-0.woody3/src/smtpd/smtpd.h	Tue Nov  6 18:35:29 2001
+++ postfix-1.1.11-0.woody3-xheader/src/smtpd/smtpd.h	Fri May  3 23:53:13 2002
@@ -77,6 +77,9 @@
     VSTRING *sasl_decoded;
 #endif
     int     warn_if_reject;
+    int     xheader_if_reject; 
+    VSTRING *xheader; 
+    
 } SMTPD_STATE;
 
 extern void smtpd_state_init(SMTPD_STATE *, VSTREAM *);
--- postfix-1.1.11-0.woody3/src/smtpd/smtpd_check.c	Mon Mar 18 21:10:27 2002
+++ postfix-1.1.11-0.woody3-xheader/src/smtpd/smtpd_check.c	Sat May  4 01:10:04 2002
@@ -468,6 +468,10 @@
 	    rest += 1;
 	    continue;
 	}
+	if (strcmp(*rest, XHEADER_IF_REJECT) == 0 && rest[1] != 0) { 
+	    rest += 1; 
+	    continue; 
+	} 
 	for (reqd = required; *reqd; reqd++)
 	    if (strcmp(*rest, *reqd) == 0)
 		return (1);
@@ -618,6 +622,7 @@
 {
     va_list ap;
     int     warn_if_reject;
+    int     xheader_if_reject;
     const char *whatsup;
 
     /*
@@ -627,8 +632,13 @@
     if (state->warn_if_reject && error_class != MAIL_ERROR_SOFTWARE) {
 	warn_if_reject = 1;
 	whatsup = "reject_warning";
+    }
+    else if (state->xheader_if_reject && error_class != MAIL_ERROR_SOFTWARE) { 
+	xheader_if_reject = 1; 
+	whatsup = "reject_xheader"; 
     } else {
 	warn_if_reject = 0;
+	xheader_if_reject = 0;
 	whatsup = "reject";
     }
 
@@ -695,7 +705,18 @@
 	msg_info("%s: %s from %s: %s",
 		 whatsup, state->where, state->namaddr, STR(error_text));
     }
-    return (warn_if_reject ? 0 : SMTPD_CHECK_REJECT);
+
+    /*     
+     * Generate an X-Header for the rejection, rather than actually 
+     * rejecting the message.             
+     */                               
+    if (xheader_if_reject) { 
+	vstring_sprintf(state->xheader, "X-Reject: %s", STR(error_text)); 
+    } 
+
+	if (warn_if_reject || xheader_if_reject) return 0; 
+ 	else return SMTPD_CHECK_REJECT; 
+		
 }
 
 /* reject_dict_retry - reject with temporary failure if dict lookup fails */
@@ -2017,6 +2038,11 @@
 		state->warn_if_reject = state->recursion;
 	    continue;
 	}
+	if (strcasecmp(name, XHEADER_IF_REJECT) == 0) {
+	    if (state->xheader_if_reject == 0)
+		state->xheader_if_reject = state->recursion;
+	    continue;
+	}
 
 	/*
 	 * Spoof the is_map_command() routine, so that we do not have to make
@@ -2032,14 +2058,16 @@
 	 */
 	if (strcasecmp(name, PERMIT_ALL) == 0) {
 	    status = SMTPD_CHECK_OK;
-	    if (cpp[1] != 0 && state->warn_if_reject == 0)
+	    if (cpp[1] != 0 && state->warn_if_reject == 0 &&
+		state->xheader_if_reject == 0)
 		msg_warn("restriction `%s' after `%s' is ignored",
 			 cpp[1], PERMIT_ALL);
 	} else if (strcasecmp(name, REJECT_ALL) == 0) {
 	    status = smtpd_check_reject(state, MAIL_ERROR_POLICY,
 				      "%d <%s>: %s rejected: Access denied",
 				  var_reject_code, reply_name, reply_class);
-	    if (cpp[1] != 0 && state->warn_if_reject == 0)
+	    if (cpp[1] != 0 && state->warn_if_reject == 0 &&
+		state->xheader_if_reject == 0)
 		msg_warn("restriction `%s' after `%s' is ignored",
 			 cpp[1], REJECT_ALL);
 	} else if (strcasecmp(name, REJECT_UNAUTH_PIPE) == 0) {
@@ -2155,7 +2183,8 @@
 	    if (state->recipient)
 		status = check_relay_domains(state, state->recipient,
 				    state->recipient, SMTPD_NAME_RECIPIENT);
-	    if (cpp[1] != 0 && state->warn_if_reject == 0)
+	    if (cpp[1] != 0 && state->warn_if_reject == 0 &&
+		state->xheader_if_reject == 0)
 		msg_warn("restriction `%s' after `%s' is ignored",
 			 cpp[1], CHECK_RELAY_DOMAINS);
 	} else if (strcasecmp(name, PERMIT_SASL_AUTH) == 0) {
@@ -2207,6 +2236,9 @@
 
 	if (state->warn_if_reject >= state->recursion)
 	    state->warn_if_reject = 0;
+	
+	if (state->xheader_if_reject >= state->recursion)
+	    state->xheader_if_reject = 0;
 
 	if (status != 0)
 	    break;
--- postfix-1.1.11-0.woody3/src/smtpd/smtpd_state.c	Tue Nov  6 18:35:40 2001
+++ postfix-1.1.11-0.woody3-xheader/src/smtpd/smtpd_state.c	Sat May  4 00:37:48 2002
@@ -92,6 +92,8 @@
     state->msg_size = 0;
     state->junk_cmds = 0;
     state->warn_if_reject = 0;
+    state->xheader_if_reject = 0;        
+    state->xheader = vstring_alloc(80);
 
 #ifdef USE_SASL_AUTH
     if (SMTPD_STAND_ALONE(state))
@@ -123,6 +125,8 @@
      */
     if (state->buffer)
 	vstring_free(state->buffer);
+    if (state->xheader)
+	vstring_free(state->xheader);
     smtpd_peer_reset(state);
 
 #ifdef USE_SASL_AUTH

