Mail Ddlivering filter tool
- Ruby
- Mail Gem
- Oj Gem
- Dovecot (Optional)
- SpamAssassin (Optional)
- Systemd (Optional)
Maildeliver called as filter.
Maildeliver reads mail from STDIN, routing filters, and pass to LDA program. They are customizable.
- Copy
bin/*
to on your path. - Write
/etc/maildeliver/maildeliver.rb
. I recommend to start withcp config/maildeliver.rb /etc/maildeliver/
. - Optionally, write
/etc/maildeliver/basic.yaml
. - Create queue directories.
- Optionally,
cp systemd/maildeliver.service /etc/systemd/system/
, edit to fit your environment, and start and enable it.
Maildeliver uses /var/maildeliver
by default (you can override with spooldir
.)
For exmaple;
# mkdir -p /var/maildeliver/{queue,error,unreadable}
# chmod 777 /var/maildeliver/{queue,error,unreadable}
maildeliver.rb
Starting maildeliver server.
maildeliver-q.rb <original> <selector> < email
maildeliver-q.rb
reads email from STDIN, and pass to maildeliver server.
If you want to use this as Postfix local(8) alias command, you can use like
haruka: |"/usr/local/bin/maildeliver.rb haruka [email protected]"
Notice: Postfix alias command is execused with nobody
user with private /tmp
.
maildeliver.rb
is a Ruby library.
$mdfilter
is mail filtering object.
You can set filtering proc like:
$mdfilter.filter_procs.push ->(data, mail) {
IO.popen("foofilter", "w") do |io|
io.write data["mail"]
end
unless $?.zero?
data["spam"] = true
end
}
data
object is a Hash.
Key | Type | Description |
---|---|---|
mail |
String |
Mail full string |
original |
String |
maildeliver-q.rb's 1st argument |
selector |
String |
maildeliver-q.rb's 2nd argument |
proxy |
MailProxy |
Object has some check method. |
drop |
Boolean |
Request to drop this mail |
save |
Boolean |
Request to save without applying more filter |
spam |
Boolean |
Mark as spam |
folder |
String |
Set folder name |
data["proxy"]
has some method for custom filtering.
Method | Argument | Description |
---|---|---|
from? |
glob |
return true if any from address matches glob pattern. |
to? |
glob |
return true if any to address matches glob pattern. |
mail
is a Mail
(Ruby gem) object.
MailDeliver has SpamAssassin filter. You can you like:
$mdfilter.filter_procs.push $mdfilter.method(:filter_spamc)
You can set proc how to deliver mail.
$mdfilter.deliver_proc = ->(data) {
IO.popen(["foodeliver", data["selector"]], "w") {|io| io.write data["mail"]}
}
MailDeliver has some delivering method.
$mdfilter.deliver_proc = $mdfilter.method(:deliver_dovecot)
Use dovecot-lda (/usr/lib/dovecot/deliver
).
selector
is used as -d
option's argument.
folder
is used as -m
option's argument.
If spam flag is set, add -m Junk
argument.
$mdfilter.deliver_proc = $mdfilter.method(:deliver_mh)
Put MH mail folder.
if folder
is set, put there under inbox
.
if spam flag is set, put spam floder.
$mdfilter.options[:mh_folder_spam]
is path to Spam folder. /
means MH Mailbox root. /Junk
is default.
$mdfilter.options[:mh_box]
is path to MH Mailbox. ~/Mail
is default.
You can register hook Proc to $mdfilter.hooks
.
Key | Argument | Description |
---|---|---|
:drop |
Mail |
Mail is flagged as drop . |
:spam |
Mail |
Mail is flagged as spam . |
:error_data_avilable |
data (Hash ) |
Queue item JSON is parsed but exception is raised. You can mail data as data["mail"] |
:error_on_parse_json |
String (JSON) |
Queue item is dequeued but failed to parse JSON. |
:error_unreadable |
id (String ) |
Failed to read queue item (file.) |
Spam folder name (Junk
is default.)
If it is set, immidiately drop mail when spam flag is set.
How to do when filter raises exception.
:drop
- Drop (remove) email immidiately.
:save
- Save email immidiately.
:spam
- Mark as spam.
:ignore
- Do nothing and continue. (default)
Filter raises exception after this seconds left.
If nil
, do not timeout.
Notice: The note about Ruby's Timeout.timeout
should be noted.
TCP Port number.
10751
is default.
If true, maildeliver uses Unix Domain Socket instread of TCP.
Unix Domain Socket file path.
This option is effective only if use_unixsock is enabled.
/tmp/maildeliver.sock
is by default.
Base directory path for maildeliver uses.
/var/maildeliver
is by default.
maildeliver-q outs log into the directory.
maildeliver-q outs queuing mail object into the directory on error.
maildeliver-q-retry.rb
resends these mails.
maildeliver-q outs queuing mail object into the directory before pass to maildeliver server.