Avoid mutt sending mail with too many entries in To: or Cc: fields

emailmutt

Frequently, I use mutt's alias functionality, to send a message to larger groups of people (legitimate, not spam!). Normally, I put the alias into the Bcc: field, to cancel out spam harvesters, and for privacy reasons (not all recipient know each other).

By accident, I sometimes put the alias into the To: or Cc: field, where it is expanded, revealing all addresses do all recipients. This is very bad, since once sent, the information is leaked, and there's no way back.

  • How can I make mutt refuse to send a mail, if there is more than, say, 1 entry in the To: or 5 entries in the Cc: field?

  • Improvement: How can I make mutt send the mail anyways, if I add a user-defined header, e.g., X-limit-cc: 50?

Setting up a separate mailing list service is not what I'm asking for, this would rather be a separate solution to the problem.

Best Answer

AFAIK, Mutt itself cannot do such checks, but there's a workaround! The idea is to redefine the $sendmail variable to use a wrapper that will check the mail before sending it. For instance, in your .muttrc file:

set sendmail=$HOME/scripts/sendmail-mutt

This script can either terminate with an error (non-zero exit status) or terminate successfully with something like:

exec /usr/sbin/sendmail -oem -oi "$@"

in a shell script, or:

exec qw(/usr/sbin/sendmail -oem -oi), @ARGV;

in Perl.

Related Question