So nobody said delaying until after the DATA phase if the sender is null
is a bad thing. Happy to be able to contribute easily, here is the patch
against 1.6 (I havn't tried the development versions because production
is my goal and of course this patch is bug free). Do with it whatevery
you want...
It's only slightly tested so far.
Greetings,
Moritz
diff -u -r milter-greylist-1.6/ChangeLog milter-greylist-1.6-mo/ChangeLog
--- milter-greylist-1.6/ChangeLog Thu Dec 9 00:24:56 2004
+++ milter-greylist-1.6-mo/ChangeLog Mon Jan 3 16:28:26 2005
@@ -1,3 +1,6 @@
+
+ Delay tempfail until end of DATA phase if envelope sender is <>
+ (Moritz Both)
1.6:
Updated default whitelist
1.6rc1:
diff -u -r milter-greylist-1.6/milter-greylist.c milter-greylist-1.6-mo/milter-greylist.c
--- milter-greylist-1.6/milter-greylist.c Sat Nov 27 15:43:17 2004
+++ milter-greylist-1.6-mo/milter-greylist.c Mon Jan 3 16:32:01 2005
@@ -78,6 +78,7 @@
static char *strncpy_rmsp(char *, char *, size_t);
static char *gmtoffset(time_t *, char *, size_t);
static void writepid(char *);
+static void log_and_report_greylisting(SMFICTX *ctx, struct mlfi_priv *priv, char *rcpt);
struct smfiDesc smfilter =
{
@@ -291,10 +292,8 @@
{
struct mlfi_priv *priv;
time_t remaining;
- char hdr[HDRLEN + 1];
char addrstr[IPADDRSTRLEN];
char rcpt[ADDRLEN + 1];
- int h, mn, s;
priv = (struct mlfi_priv *) smfi_getpriv(ctx);
@@ -384,29 +383,26 @@
priv->priv_queueid) != 0)
return SMFIS_CONTINUE;
+ priv->priv_remaining = remaining;
+
/*
* The message has been added to the greylist and will be delayed.
- * Log this and report to the client.
+ * If the sender address is null, this will be done after the DATA
+ * phase, otherwise immediately.
*/
- h = remaining / 3600;
- remaining = remaining % 3600;
- mn = (remaining / 60);
- remaining = remaining % 60;
- s = remaining;
-
- syslog(LOG_INFO, "%s: addr %s from %s to %s delayed for %02d:%02d:%02d",
- priv->priv_queueid, addrstr, priv->priv_from, *envrcpt, h, mn, s);
-
- if (conf.c_quiet) {
- (void)smfi_setreply(ctx, "451", "4.7.1",
- "Greylisting in action, please come back later");
- } else {
- snprintf(hdr, HDRLEN,
- "Greylisting in action, please come "
- "back in %02d:%02d:%02d", h, mn, s);
- (void)smfi_setreply(ctx, "451", "4.7.1", hdr);
+ if (strcmp(priv->priv_from, "<>") == 0) {
+ priv->priv_delayed_reject = 1;
+ if (*priv->priv_rcpt == 0)
+ strcpy(priv->priv_rcpt, rcpt);
+ else
+ strcpy(priv->priv_rcpt, "(multiple recipients)");
+ return SMFIS_CONTINUE;
}
+ /*
+ * Log temporary failure and report to the client.
+ */
+ log_and_report_greylisting(ctx, priv, *envrcpt);
return SMFIS_TEMPFAIL;
}
@@ -429,6 +425,11 @@
priv = (struct mlfi_priv *) smfi_getpriv(ctx);
+ if (priv->priv_delayed_reject) {
+ log_and_report_greylisting(ctx, priv, priv->priv_rcpt);
+ return SMFIS_TEMPFAIL;
+ }
+
if ((fqdn = smfi_getsymval(ctx, "{j}")) == NULL) {
syslog(LOG_DEBUG, "smfi_getsymval failed for {j}");
gethostname(host, ADDRLEN);
@@ -1134,4 +1135,50 @@
syslog(LOG_INFO, "Exiting");
return;
+}
+
+void
+log_and_report_greylisting(ctx, priv, rcpt)
+ SMFICTX *ctx;
+ struct mlfi_priv *priv;
+ char *rcpt;
+{
+ int h, mn, s;
+ char hdr[HDRLEN + 1];
+ char addrstr[IPADDRSTRLEN];
+ time_t remaining;
+ char *delayed_rj;
+
+ /*
+ * The message has been added to the greylist and will be delayed.
+ * Log this and report to the client.
+ */
+ iptostring(SA(&priv->priv_addr), priv->priv_addrlen, addrstr,
+ sizeof(addrstr));
+
+ remaining = priv->priv_remaining;
+ h = remaining / 3600;
+ remaining = remaining % 3600;
+ mn = (remaining / 60);
+ remaining = remaining % 60;
+ s = remaining;
+
+ if (priv->priv_delayed_reject)
+ delayed_rj = " after DATA phase";
+ else
+ delayed_rj = "";
+
+ syslog(LOG_INFO, "%s: addr %s from %s to %s delayed%s for %02d:%02d:%02d",
+ priv->priv_queueid, addrstr, priv->priv_from, rcpt, delayed_rj,
+ h, mn, s);
+
+ if (conf.c_quiet) {
+ (void)smfi_setreply(ctx, "451", "4.7.1",
+ "Greylisting in action, please come back later");
+ } else {
+ snprintf(hdr, HDRLEN,
+ "Greylisting in action, please come "
+ "back in %02d:%02d:%02d", h, mn, s);
+ (void)smfi_setreply(ctx, "451", "4.7.1", hdr);
+ }
}
diff -u -r milter-greylist-1.6/milter-greylist.h milter-greylist-1.6-mo/milter-greylist.h
--- milter-greylist-1.6/milter-greylist.h Mon Aug 2 14:11:48 2004
+++ milter-greylist-1.6-mo/milter-greylist.h Mon Jan 3 16:15:38 2005
@@ -85,9 +85,12 @@
char priv_hostname[ADDRLEN + 1];
char priv_helo[ADDRLEN + 1];
char priv_from[ADDRLEN + 1];
+ char priv_rcpt[ADDRLEN + 1];
time_t priv_elapsed;
int priv_whitelist;
char *priv_queueid;
+ int priv_delayed_reject;
+ time_t priv_remaining;
};
sfsistat mlfi_connect(SMFICTX *, char *, _SOCK_ADDR *);