Offlineimap + Mutt = Less Pain
I receive a lot of email as im a system administrator in order to handle this i prefer to use Mutt. One problem, Mutt sucks when using imap connections. In order to over come this you can use a nice little util called offlineimap that with sync a imap server to a local folder in mail dir format.
So the flow of mail into my computer is now
Imap Server -> Offlineimap -> Mutt -> Offlineimap -> Imap Server
Firstly you need to install / configure offlineimap. So do a
apt-get install offlineimap
[general]
accounts = Mail
# Gives you a nice blinky output on the console so you know what's happening.
#ui = Curses.Blinkenlights
# If uncommented, this would show nothing at all. Great for cronjobs or background-processes
ui = Noninteractive.Quiet
[Account Mail]
localrepository = Local
# Profile-Name for the remote Mails for a given Account
remoterepository = Remote
[Repository Local]
# Way of storing Mails locally. Only Maildir is currently supported
type = Maildir
# Place where the synced Mails should be
localfolders = ~/Mail/Server
[Repository Remote]
type = IMAP
# Specify the user name. This is the only mandatory parameter.
remotehost = mailserver
remoteuser = username
ssl = yes
remotepass = password
Now comment out the ui = Noninteractive.Quiet and give it a run. The first time it runs its going to sync all your mail locally so its going to take a long time. Once this is completed then you can go about setting up mutt
.muttrc
set spoolfile=~/Mail/Server/INBOX
set folder="~/Mail/"
set envelope_from=yes
mailboxes !
mailboxes "=INBOX"
mailboxes "=Server2/INBOX"
folder-hook =Server 'set from="Stephen <[email protected]>"'
folder-hook =Server 'set smtp_url="smtp://[email protected]"'
folder-hook =Server 'set signature ="~/.mutt/sig"'
folder-hook =Server2 'set from="Stephen <[email protected]>"'
older-hook = Server2 'set smtp_url="smtp://[email protected]"'
folder-hook =Server2 'set smtp_url=""'
folder-hook =Server2 'set signature =""'
set move = no #Stop asking to "move read messages to mbox"!
# Header stuff
ignore "Authentication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc
ignore *
unignore from: date subject to cc
unignore x-mailing-list: posted-to:
unignore x-mailer:
# For better looks
set markers=no # don't put '+' at the beginning of wrapped lines
set pager_index_lines= 5 # how large is the index window?
set sort = threads
set sort_aux = 'last-date-received'
set query_command = "~/.mutt/lookup.pl '%s'"
set timeout=15
set editor="vim -c ':set tw=72' -c':set spell'"
set ispell="aspell -e -c"
set fast_reply
##chache
set header_cache = "~/.mutt/header"
set message_cachedir = "~/.mutt/body"
##save sent messages
set copy= no
bind index ! next-unread-mailbox
bind pager ! next-unread-mailbox
# Colours for items in the index
color index brightcyan black ~N
# Hmm, don't like this.
#color index brightgreen black "~N (~x byers.world)|(~x byers.x)|(~x langly.levallois123.axialys.net)|(~x the.earth.li)"
color index brightyellow black ~F
color index black green ~T
color index brightred black ~D
color index black white ~N
mono index bold ~N
mono index bold ~F
mono index bold ~T
mono index bold ~D
# URLs
color body brightgreen black "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
color body brightgreen black "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
# email addresses
color body brightgreen black "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
mono body bold "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
# header
color header green black "^from:"
color header green black "^to:"
color header green black "^cc:"
color header green black "^date:"
color header yellow black "^newsgroups:"
color header yellow black "^reply-to:"
color header brightcyan black "^subject:"
color header red black "^x-spam-rule:"
color header green black "^x-mailer:"
color header yellow black "^message-id:"
color header yellow black "^Organization:"
color header yellow black "^Organisation:"
color header yellow black "^User-Agent:"
color header yellow black "^message-id: .*pine"
color header yellow black "^X-Fnord:"
color header yellow black "^X-WebTV-Stationery:"
color header yellow black "^X-Message-Flag:"
color header yellow black "^X-Spam-Status:"
color header yellow black "^X-SpamProbe:"
color header red black "^X-SpamProbe: SPAM"
# Coloring quoted text - coloring the first 7 levels:
color quoted cyan black
color quoted1 yellow black
color quoted2 red black
color quoted3 green black
color quoted4 cyan black
color quoted5 yellow black
color quoted6 red black
color quoted7 green black
# Default color definitions
#color hdrdefault white green
color signature red black
color indicator black cyan
color attachment black green
color error red black
color message white black
color search brightwhite magenta
color status brightyellow blue
color tree brightblue black
color normal white black
color tilde green black
color bold brightyellow black
#color underline magenta black
color markers brightcyan black
# Colour definitions when on a mono screen
mono bold bold
mono underline underline
mono indicator reverse
macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'
macro pager S "<save-message>=Server/Calendar<enter>y"
macro index S "<save-message>=Server/Calendar<enter>y"
auto_view text/html
alternative_order text/enriched text/plain text/html
As you can see have multiple accounts in my mutt config, you can add multiple accounts into the offlineimap config and have them sync into different mail dir folders. I then have a wrapper script around offlineimap that run every 2 minutes from cron. In order to have to pop notifications you need to install libnotify-bin.
~/utils/mail.sh
#! /bin/bash
ignored="All Mail|Sent Mail|Trash|geekup|uknot|Spam"
export DISPLAY=:0.0
offlineimap
newmail=`find ~/Mail -wholename "*/new/*" | egrep -v "$ignored" | awk -F \/ '{print $5"/"$6}' | sort | uniq`
if [ -n "$newmail" ];
then
`notify-send "You have New Mail In" "$newmail" -u low -t 200 -i /usr/share/icons/Humanity/categories/48/applications-mail.svg`
fi
And finally in my contrab
# m h dom mon dow command
*/2 * * * * /home/username/utils/mail.sh