rss logo

My maildrop notes

Configuration

Intro

maildrop is a powerful and feature-rich tool Mail delivery agent for GNU/Linux.

Enable maildrop

  • Go to the user's email inbox directory :
vmail@host:~$ cd std.rocks/user/
  • Enter the following command to activate maildrop for the user :
vmail@host:~$ echo "|/usr/bin/maildrop" > .courier

My maildrop file

Here is an example of a maildrop file that I use to automatically sort my emails. The goal is to move emails into specific directories automatically.

logfile "/var/log/maildrop.log" #log "MAILDIR : $MAILDIR" import RECIPIENT import HOME log "HOMME : $HOME" #log "RECIPIENT : $RECIPIENT" #log "FROM : $FROM" VERBOSE="5" SHELL=/bin/bash DEFAULT="$HOME/Maildir/." #######shebang@shebangthedolphins.net########### `[[ $MATCH =~ .*@personal.com ]]` if ( $RETURNCODE == 0 ) { to "$HOME/Maildir/.perso/." } #######work@shebangthedolphins.net########### `[[ $MATCH =~ .*@toto.com ]]` if ( $RETURNCODE == 0 && ( /^To: .*support@shebangthedolphins.net.*/ || /^Cc: .*tech@shebangthedolphins.net.*/ ) && ! /^To: .*bye@shebangthedolphins\.net.*/ ) { to "$HOME/Maildir/.toto/." } if ( /^To: .*insurance@shebangthedolphins.net.*/ || /^To: .*INSURANCE@SHEBANGTHEDOLPHINS.NET.*/ ) { to "$HOME/Maildir/.axa/." } if ( /^To: .*bank@shebangthedolphins.net.*/ ) { to "$HOME/Maildir/.bank/." } #######buy@shebangthedolphins.net########### `[[ $MATCH =~ .*@.*ebay.(com|fr) ]]` if ( $RETURNCODE == 0 && /^To: .*buy@shebangthedolphins\.net.*/ ) { to "$HOME/Maildir/.ebay/." } `[[ $MATCH =~ .*@fnac.com ]]` if ( $RETURNCODE == 0 && /^To: buy@shebangthedolphins\.net/ ) { to "$HOME/Maildir/.fnac/." } `[[ $MATCH =~ .*@amazon.fr ]]` if ( $RETURNCODE == 0 && /^To: buy@shebangthedolphins\.net/ ) { to "$HOME/Maildir/.amazon/." } if ( /^To: flattr@shebangthedolphins\.net/ ) { to "$HOME/Maildir/.flattr/." } if ( /^To: playstation@shebangthedolphins\.net/ ) { to "$HOME/Maildir/.playstation/." }

Whitelist with maildrop

  • Mails for which addresses are not present in the /var/vmail/shebangthedolphins.net/boby/whitelist file will be moved into the Junk folder
if ( /To: .*boby@shebangthedolphins.net.*/ && ( /^From:\s.*<(.*)>/ && !lookup(tolower($MATCH1), "/var/vmail/shebangthedolphins.net/boby/whitelist" ))) #to lower doesn't seems to be useful { log "MATCH : $MATCH1" to "$HOME/Maildir/.Junk/." }

Play a sound

We can play a sound alert each time we receive a specific mail

  • First we install aplay
root@host:~# apt-get install alsa-utils
  • List audio peripherals
root@host:~# aplay -l root@host:~# aplay -L
  • Script to play sound
#! /bin/bash aplay -D front:CARD=Device,DEV=0 -t wav /usr/local/sbin/alert.wav
  • vigr and vigr -s
audio:x:29:vmail
  • /etc/sudoers

I had ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM front:CARD=Device,DEV=0 and aplay: main:788: audio open error: Invalid argument errors so I had to create a sudo rule.

vmail ALL=(ALL) NOPASSWD:/usr/local/sbin/play_sound.sh
  • /etc/maildropc
if ( /^From: .*santa@claus.*/ || /^Subject: .*specific subject.*/ ) { `sudo /usr/local/sbin/play_sound.sh` }
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address