check_msgid.m4 is a HACK() that can be used in a sendmail.mc file to perform validation against the Message-Id: header in incoming e-mail. It is essentially a word-for-word copy of an existing chunk of code found in sendmail documentation with two minor additions:
  1. Mail is quarantined instead of being rejected; (see quarantine CGI)
  2. You can selectivly turn this check off!

By adding MsgId:remote.domain.name <tab> OK to your /etc/mail/access database, you can permit remote.domain.name to send you mail and not Questions? Comments? Shoot me an email at richard ((__NOSPAM__)) richardharman.com.

Click here to download the sourcecode.
divert(-1)

LOCAL_CONFIG
Kstorage macro
# call ruleset CheckMessageId with the value of the message-id header
HMessage-Id: $>CheckMessageId

LOCAL_RULESETS
SCheckMessageId

R$*			$: $(storage {MessageIdCheck} $@ OK $) $1	
R< $+ @ $+ >		$@ OK
R$*			$#error $@ quarantine $: "553 Invalid Message-Id Header Error"

Scheck_eoh
# Check the macro
R$*			$: < $&{MessageIdCheck} >
# Clear the macro for the next message
R$*			$: $(storage {MessageIdCheck} $) $1
# Has a Message-Id: header
R< $+ >			$@ OK
# Allow missing Message-Id: from local mail
R$*			$: < $&{client_name} >
R< >			$@ OK
R< $=w >		$@ OK
# Allow missing Message-Id: from access list
# MsgId:remote.domain.name	OK
R$*			$: $>D <$&{client_name}> <?> <! MsgId> <>
R<$={Accept}> <$*>	$@ $1                           return value of lookup
# Otherwise, reject the mail
R$*			$#error $@ quarantine $: "553 Invalid Message-Id Header Error"