![拦截消息并将其传送至任意命令](https://linux22.com/image/700546/%E6%8B%A6%E6%88%AA%E6%B6%88%E6%81%AF%E5%B9%B6%E5%B0%86%E5%85%B6%E4%BC%A0%E9%80%81%E8%87%B3%E4%BB%BB%E6%84%8F%E5%91%BD%E4%BB%A4.png)
我想在 PostgreSQL 数据库中保留通过我的 exim SMTP 传输的每封电子邮件的副本。我需要基本信息:
From, To, CC, BCC and email body
因为如果有可疑活动发生,我可能需要公司经理检查。(在我居住的地方,隐私不是问题!)
我已经设置了一个shadow_transport
来实现这一点:
Exim 配置:
maildir_home:
debug_print = "T: maildir_home for $local_part@$domain"
driver = appendfile
.ifdef MAILDIR_HOME_MAILDIR_LOCATION
directory = MAILDIR_HOME_MAILDIR_LOCATION
.else
directory = $home/Maildir
.endif
.ifdef MAILDIR_HOME_CREATE_DIRECTORY
create_directory
.endif
.ifdef MAILDIR_HOME_CREATE_FILE
create_file = MAILDIR_HOME_CREATE_FILE
.endif
delivery_date_add
envelope_to_add
return_path_add
maildir_format
.ifdef MAILDIR_HOME_DIRECTORY_MODE
directory_mode = MAILDIR_HOME_DIRECTORY_MODE
.else
directory_mode = 0700
.endif
.ifdef MAILDIR_HOME_MODE
mode = MAILDIR_HOME_MODE
.else
mode = 0600
.endif
mode_fail_narrower = false
shadow_transport = save_to_db
save_to_db:
debug_print = "PG: $sender_address"
driver = pipe
command = /usr/sbin/exim_save_to_db "test" "test2"
user = Debian-exim
group = mail
这只是一个简单的脚本,将测试和测试2附加到/tmp/eximtest
文件,当我让它正常工作时我会扩展它。
剧本:
#!/bin/sh
# Get data from exim server and save to postgres database for future reference
# Args: 1->recipients (from to bcc etc ) 2->emailbody
echo "$1" >> /tmp/eximtest
echo "$2" >> /tmp/eximtest
# return 0 as success for Exim
echo 0
使用任意 2 个参数从命令行运行exim_save_to_db
即可完成此任务。从 exim 运行则不会,尽管我在日志中发现影子传输已执行:
R=local_user T=maildir_home ST=save_to_db
我还添加了debug_print = "PG: $sender_address"
查看日志中是否发生了某些事情但未打印消息。
答案1
拦截消息并将其传送至任意命令
进出控制配置文件:
system_filter = /etc/exim/system_filter.conf
系统过滤器配置文件:
if $h_subject contains "PIPETEST"
then
unseen pipe "/usr/local/bin/pipetest_filter.php $message_size"
endif