This patch changes qmail-smtpd so that it parses incoming emails. It looks at the first line of MIME attachments to see if they're Windows executables which are base64-encoded. This catches nearly all current Microsoft viruses. Apply this patch like so: cd /usr/local/src/qmail-1.03 wget http://qmail.org/qmail-smtpd-viruscan-1.1.patch patch boundary.len && + !str_diffn(line.s,boundary.s,boundary.len)) { + linespastheader = 0; + } else if (linespastheader == 0 && line.len == 1) { + linespastheader = 1; + } else if (linespastheader == 1) { + if (line.len >= 9) + if (!str_diffn(line.s,"TVqQAAMAA",9) || + !str_diffn(line.s,"TVpQAAIAA",9) || + !str_diffn(line.s,"TVpAALQAc",9) || + !str_diffn(line.s,"TVpyAXkAX",9) || + !str_diffn(line.s,"TVrmAU4AA",9) || + !str_diffn(line.s,"TVrhARwAk",9) || + !str_diffn(line.s,"TVoFAQUAA",9) || + !str_diffn(line.s,"TVoAAAQAA",9) || + !str_diffn(line.s,"TVoIARMAA",9) || + !str_diffn(line.s,"TVouARsAA",9) || + !str_diffn(line.s,"TVrQAT8AA",9)) { + flagexecutable = 1; + qmail_fail(&qqt); + } + linespastheader = 2; + } + } + line.len = 0; + } + } + if (bytestooverflow) if (!--bytestooverflow) qmail_fail(&qqt); @@ -374,6 +478,12 @@ if (!rcptto.len) { err_wantrcpt(); return; } seenmail = 0; if (databytes) bytestooverflow = databytes + 1; + boundary.len = 0; + content.len = 0; + putinheader = 1; + linespastheader = -1; + flagexecutable = 0; + linetype = ' '; if (qmail_open(&qqt) == -1) { err_qqt(); return; } qp = qmail_qp(&qqt); out("354 go ahead\r\n"); @@ -389,6 +499,7 @@ if (!*qqx) { acceptmessage(qp); return; } if (hops) { out("554 too many hops, this message is looping (#5.4.6)\r\n"); return; } if (databytes) if (!bytestooverflow) { out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n"); return; } + if (flagexecutable) { out("552 we don't accept email with executable content (#5.3.4)\r\n"); return; } if (*qqx == 'D') out("554 "); else out("451 "); out(qqx + 1); out("\r\n"); .