Thatbytes

Mostly Interesting

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

1
Imap Server -> Offlineimap -> Mutt -> Offlineimap -> Imap Server

Firstly you need to install / configure offlineimap. So do a

1
apt-get install offlineimap 

and then create ~/.offlineimaprc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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

1
2
3
4
5
6
7
8
9
10
11
#! /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

1
2
3
# m h  dom mon dow   command
*/2 * * * * /home/username/utils/mail.sh

Thats it now i have all my mail synced locally and can search and open mails 100 times faster.

Comments