{"id":351,"date":"2006-03-24T11:27:36","date_gmt":"2006-03-24T10:27:36","guid":{"rendered":"http:\/\/wp.devco.net\/?p=351"},"modified":"2009-10-09T16:52:58","modified_gmt":"2009-10-09T15:52:58","slug":"saving_copies_of_all_email_using_exim","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2006\/03\/24\/saving_copies_of_all_email_using_exim.php","title":{"rendered":"Saving copies of all email using Exim"},"content":{"rendered":"
I’ve often seen questions on lists by people who want to save all incoming and outgoing mail on a specific server in an archive, this is usually due to some auditor requesting it or corporate legal types requesting it.<\/p>\n
The Exim documentation says it can be done but does not give examples neither does any of the two Exim books, the mailing lists are short of working examples and Google does not help either! Eventually came across a russian language site that had a working setup so I figured I’d document it here in English.<\/p>\n
The basic idea is I want a maildir made that has sub folders for each user containing incoming and outgoing mail.<\/p>\n
You’ll need to use 2 types of Exim configuration, one being a System Filter<\/a> and one being a Shadow Transport<\/a>.<\/p>\n Handling outgoing mail is done using the system filter, I’ll set this up to only affect mail matching domain.com<\/i>. In the main Exim configuration configure the basics of system wide filters by simply adding the following to the top section:<\/p>\n This defines the file where the filter will live as well as a transport that will be used to delivery the mails created by the filter. You could potentially use one of your existing transports, I like using a separate one for clarity, in your transports section add the local_copy_outgoing<\/i>:<\/p>\n NOTE:<\/B> This is using user exim and group exim, you want to adjust it for your local needs.<\/p>\n Now simply create the filter in \/etc\/exim\/systemfilter.txt<\/i>:<\/p>\n This filter will save the mail in a maildir under \/var\/mail\/domain.com\/mailarchive\/ the mailbox for a name.surname@domain.com user will be name_surname@domain_com.outgoing<\/i> using this format means most IMAP clients will display it nicely since .’s tend to confuse them a bit. You can adjust this to taste.<\/p>\n Incoming mail is easier, Exim provides a shadow_transport facility that lets you call another transport for each local delivery, this transport will get a copy of the mail and its result won’t affect the further deliver of the actual email, perfect for calling vacation type commands or doing this kind of mail copying.<\/p>\n My needs are only for intercepting mail that reaches the Maildir’s so I’ll only need to hook into my address_directory<\/i> transport, if you have other needs like intercepting actual real unix account emails then you can hook into the local_delivery<\/i> transport using the same method. My address_directory transport looks like the one below, the last 2 lines are the important ones.<\/p>\n This calls a transport called local_copy_incoming<\/i> to deliver the copy of the email, just add the following into your transports again adjusting user id, group id and file paths to your liking. This will do the file name expansion in a similar format I’m just using a slightly more complex form of the text replace here as a different example of things you can do, end result is the same.<\/p>\n NOTE:<\/B> The above line that ends in “\\” is a continuation onto the next, remove the “\\” and join the two lines in your config.<\/p>\n You can now restart your Exim server, if you’ve done it all right and created the main Maildir where this all live under your incoming and outgoing mail for domain.com<\/i> will all be saved on a per user basis. <\/p>\n","protected":false},"excerpt":{"rendered":" I’ve often seen questions on lists by people who want to save all incoming and outgoing mail on a specific server in an archive, this is usually due to some auditor requesting it or corporate legal types requesting it. The Exim documentation says it can be done but does not give examples neither does any […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[7],"tags":[30,19,33],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/351"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":1,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":611,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/351\/revisions\/611"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
\nsystem_filter = \/etc\/exim\/systemfilter.txt\nsystem_filter_directory_transport = local_copy_outgoing\n<\/pre>\n<\/blockquote>\n
\n
\nlocal_copy_outgoing:\ndriver = appendfile\ndelivery_date_add\nenvelope_to_add\nreturn_path_add\ngroup = exim\nuser = exim\nmode = 0660\nmaildir_format = true\ncreate_directory = true\n<\/pre>\n<\/blockquote>\n
\n
\nif $sender_address_domain is domain.com\nthen\nunseen save \/var\/mail\/domain.com\/mailarchive\/.${tr{$sender_address}{.}{_}}.outgoing\/\nendif\n<\/pre>\n<\/blockquote>\n
\n
\naddress_directory:\ndriver = appendfile\ncreate_directory\ndelivery_date_add\ndirectory_mode = 770\nenvelope_to_add\nmaildir_format\nreturn_path_add\nshadow_transport = local_copy_incoming\nshadow_condition = ${if eq {$domain}{domain.com}{yes}{no}}\n<\/pre>\n<\/blockquote>\n
\n
\nlocal_copy_incoming:\ndriver = appendfile\ndirectory = \/var\/mail\/domain.com\/mailarchive\/ \\\n.${tr {$local_part}{.}{_}}@${tr {$domain}{.}{_}}.incoming\/\ndelivery_date_add\nenvelope_to_add\nreturn_path_add\ngroup = exim\nuser = exim\nmode = 0660\nmaildir_format = true\ncreate_directory = true\n<\/pre>\n<\/blockquote>\n