> -----Original Message----- > From: owner-postfix-us...@postfix.org > [mailto:owner-postfix-us...@postfix.org] On Behalf Of Jack Bates > Sent: Thursday, November 18, 2010 3:33 PM > To: postfix-users@postfix.org > Subject: Can a milter split one message into multiple messages? > > Can a "milter" split one message with multiple RCPT into multiple > messages, each with one RCPT and different return addresses?
The only way to do that is to delete all of the recipients you don't want from the main message (M) and then create a new message (M') with the rest of the recipients, and inject it whatever way you want (pipe to a postfix/sendmail instance, SMTP, etc.). Milter doesn't have a "split envelope" primitive. > I started writing a milter to rewrite the envelope from and the From: > header such that messages to each different RCPT have different return > addresses > > Works for messages with one RCPT, but to handle messages with multiple > RCPT, I need to transform it to multiple messages, so they can each have > different return addresses In your case, you'll want to remove all the recipients, change the envelope sender for the remaining one, and then iterate through the rest creating clones of the message for each remaining recipient, each with a different envelope sender. That means a pipe-pipe-fork-close-close-exec (and probably some dup2s) for all recipients but the first one, with arguments set to change the envelope as appropriate, then feed it the message, close the pipes and wait for status from the child... and all the while the thread managing the original client connection is waiting for that mess to complete strolling towards a timeout. You can parallelize a lot of that, or you can use SMTP to serialize it to keep the forking and descriptor use down, but you still need to collect all the results and figure out what to return for the one whose SMTP reply you still control. There are a lot of places where things can go wrong, and you need to recover in each case as gracefully as possible. It's messy. -MSK