A simple SMTP microdaemon for rewriting the mail headers and envelope on recipient-by-recipient basis. Written for pine mailclient when a need to have different return addresses for different people arose. It's also efficient for throwaway email addresses used for communication with selected people, and for mailing lists subscribed to a different address than your mailclient's default one.
Added recipient "nobody", allowing throwing away emails instead of sending them.
smtpreident is run from xinetd, when the mail client opens connection to an arbitrary port we selected for it. It then acts as a trivial SMTP server, with only HELO, MAIL FROM, RCPT TO, DATA, and QUIT commands and little to no error checking. It saves down the envelope of the mail (MAIL FROM and RCPT TO parameters), and then saves the mail body (all after DATA command) into a temporary file. Then, for each recipient in RCPT TO list, it reads the config file where the requested changes are listed in, and pipes the temporary file with the mail body through the filter (in order to execute the requested changes) into /sbin/sendmail, which then puts the mail into the mail queue.
The supported changes at this moment involve rewriting the return address in mail envelope (by using sendmail -f parameter), rewriting the sender address (the From: header), filtering out requested headers, and adding a filter command into the pipe ending with /sbin/sendmail invocation (eg. for adding custom headers, encrypting the message,
If the ReSent-From: header is present, indicating it is a message bounced by Pine, the From: header is left intact instead of being rewritten. Other recipient-specific functions still apply.
Because of the nature of the system - turning mail processing from one mails to several recipients (multiple RCPT TO: for one DATA) to one mail per one recipient - it is possible to implement any kind of email processing, including but not limited to automatic GPG signing or encrypting, forwarding mail through remailer, adding custom headers on per-recipient basis, and more or less anything you can imagine (the easiest way is possibly adding filters into the popen() call as pipes in front of the sendmail command, which is implemented by the filter: directive).
Do not allow access to the system from untrusted machines. The code has no authorization built in (use firewall and xinetd access limits), so it can act as an open relay. It also contains more than one buffer overflow (but what would you expect from a Saturday morning proof-of-concept hack).
The system-wide configuration file is set to be /etc/smtpreident.conf
.
The user-specific configuration files are by default /etc/smtpreident.conf.email@address
.
See the heavily commented config.demo file. Allows matching to recipient by the pine addressbook, to complete email address, or to any email from a domain.