--- courier-0.61.2/courier/bofh.h	2004-08-16 20:26:17.000000000 -0300
+++ courier-0.61.2-task/courier/bofh.h	2009-04-27 16:10:12.000000000 -0300
@@ -27,6 +27,7 @@
 void bofh_init();
 
 int bofh_chkbadfrom(const char *);
+int bofh_chkbadhost(const char *);
 int bofh_chkspamtrap(const char *);
 struct bofh_list *bofh_chkfreemail(const char *);
 int bofh_chkbadmx(const char *);
--- courier-0.61.2/courier/bofh.c	2004-08-16 20:26:17.000000000 -0300
+++ courier-0.61.2-task/courier/bofh.c	2009-04-27 16:10:12.000000000 -0300
@@ -17,8 +17,9 @@
 static const char rcsid[]="$Id: bofh.c,v 1.9 2004/08/16 23:26:17 mrsam Exp $";
 
 static struct bofh_list *bofh_freemail, *bofh_spamtrap, *bofh_badmx,
-	*bofh_badfrom;
-static struct bofh_list **freemailp, **spamtrapp, **badmxp, **badfromp;
+	*bofh_badfrom, *bofh_badhost;
+static struct bofh_list **freemailp, **spamtrapp, **badmxp, **badfromp,
+	**badhostp;
 
 static void addbofh(struct bofh_list ***, void (*)(char *), int);
 
@@ -91,6 +92,13 @@
 	}
 	badfromp= &bofh_badfrom;
 
+	while ((p=bofh_badhost) != 0)
+	{
+		bofh_badhost=p->next;
+		bofh_free(p);
+	}
+	badhostp= &bofh_badhost;
+
 	if (!fp)
 		return;
 
@@ -124,6 +132,10 @@
 		{
 			addbofh(&badfromp, &address_lower, 0);
 		}
+		else if (strcasecmp(p, "badhost") == 0)
+		{
+                        addbofh(&badhostp, NULL, 0);
+                }
 		else if (strcasecmp(p, "maxrcpts") == 0)
 		{
 			char *q=strtok(NULL, " \t\r");
@@ -215,6 +227,25 @@
 	return (chkbadlist(pp, bofh_badfrom));
 }
 
+int bofh_chkbadhost(const char *p)
+{
+	struct bofh_list *b;
+	int l, ll;
+
+	l=strlen(p);
+
+	for (b=bofh_badhost; b; b=b->next)
+	{
+		if (strcmp(p,b->name) == 0)
+			return (1);
+		else if ((ll=strlen(b->name)) < l
+			&& p[l -ll -1] == '.'
+			&& strcmp(p+l - ll, b->name) == 0)
+			return (1);
+	}
+	return (0);
+}
+
 int bofh_chkspamtrap(const char *pp)
 {
 	return (chkbadlist(pp, bofh_spamtrap));
--- courier-0.61.2/courier/submit.C	2009-02-22 13:24:25.000000000 -0300
+++ courier-0.61.2-task/courier/submit.C	2009-04-27 16:10:11.000000000 -0300
@@ -1015,25 +1015,35 @@
 		    struct mailfrominfo *mf)
 {
 	struct	rfc1035_mxlist *mxlist, *p;
-	const char *q;
+	const char *q, *ip;
+	
 	int	docheckdomain=1;
 	struct bofh_list *d;
 
+	/* Bypass bofh check if especified */
+	if (getenv("NOBOFH") != 0)
+		return (0);
+
 	if (bofh_chkbadfrom(sender))
 	{
 		std::cout << "517 Sender rejected: " << sender << std::endl << std::flush;
 		return (-1);
 	}
 
+	q=getenv("TCPREMOTEHOST");
+	if (q && *q && bofh_chkbadhost(q))
+	{
+		std::cout << "517 Host rejected: " << q << std::endl << std::flush;
+		return (-1);
+	}
+
 	if (strcmp(mf->module->name, "esmtp") == 0
 	    && getenv("RELAYCLIENT") == 0
 	    && (d=bofh_chkfreemail(sender)) != NULL)
 	{
-		q=getenv("TCPREMOTEIP");
-		if (q && *q)
+		ip=getenv("TCPREMOTEIP");
+		if (ip && *ip)
 		{
-			q=getenv("TCPREMOTEHOST");
-
 			if (!q || checkfreemail(q, d))
 			{
 				std::cout << "517-Sender rejected: " << sender
