<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Blog blog("Baptiste Wicht"); (Posts about Gmail)</title><link>https://baptiste-wicht.com/</link><description></description><atom:link href="https://baptiste-wicht.com/categories/gmail.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sun, 15 Feb 2026 06:57:40 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>A Mutt journey: Search mails with notmuch</title><link>https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html</link><dc:creator>Baptiste Wicht</dc:creator><description>&lt;p&gt;In the previous installment in the Mutt series, &lt;a class="reference external" href="http://baptiste-wicht.com/posts/2014/07/a-mutt-journey-my-mutt-configuration.html"&gt;I've talked about my Mutt
configuration&lt;/a&gt;.
In this post, I'll talk about notmuch and how to use it to search through mails.&lt;/p&gt;
&lt;p&gt;By default, you can search mails in Mutt by using the / key. By doing that, you
can only search in the current folder. This is very fast, but this is not always
what you want. When you don't know in which folder the mail you are looking for
is, you don't want to test each folder. By default, there are no feature to
achieve global searching in Mutt.&lt;/p&gt;
&lt;p&gt;That is where notmuch comes to the rescue. notmuch is a very simple tool that
allows you to search through your mail. As its name indicates, it does not do
much. It doesn't download your mails, you have to have them locally, which is
perfect &lt;a class="reference external" href="http://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html"&gt;if you use offlineimap&lt;/a&gt;.
It does not provide a user interface, but you can query it from the command line
and it can be used from other tools. It should be available in most of the
distributions.&lt;/p&gt;
&lt;section id="configuration"&gt;
&lt;h2&gt;Configuration&lt;/h2&gt;
&lt;p&gt;The configuration of notmuch is fairly simple. You can write your
&lt;code&gt;.notmuch-config&lt;/code&gt; directly or run &lt;code&gt;notmuch setup&lt;/code&gt; that will
interactively help you to fill the configuration.&lt;/p&gt;
&lt;p&gt;Here is my configuration:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-1" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-1" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-1"&gt;&lt;/a&gt;[database]
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-2" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-2" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-2"&gt;&lt;/a&gt;path=/data/oi/Gmail/
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-3" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-3" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-3"&gt;&lt;/a&gt;
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-4" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-4" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-4"&gt;&lt;/a&gt;[user]
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-5" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-5" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-5"&gt;&lt;/a&gt;name=Baptiste Wicht
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-6" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-6" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-6"&gt;&lt;/a&gt;primary_email=baptiste.wicht@gmail.com
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-7" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-7" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-7"&gt;&lt;/a&gt;
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-8" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-8" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-8"&gt;&lt;/a&gt;[new]
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-9" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-9" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-9"&gt;&lt;/a&gt;tags=inbox
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-10" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-10" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-10"&gt;&lt;/a&gt;ignore=
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-11" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-11" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-11"&gt;&lt;/a&gt;
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-12" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-12" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-12"&gt;&lt;/a&gt;[search]
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-13" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-13" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-13"&gt;&lt;/a&gt;exclude_tags=deleted;
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-14" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-14" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-14"&gt;&lt;/a&gt;
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-15" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-15" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-15"&gt;&lt;/a&gt;[maildir]
&lt;a id="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-16" name="rest_code_0532b396a3fb4dc3ac4366754c38f8ba-16" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_0532b396a3fb4dc3ac4366754c38f8ba-16"&gt;&lt;/a&gt;synchronize_flags=true
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It needs of cours the place where your mails are stored. Then, some information
about you. The next section is to specify which tags you want to add to new
mails. Here, I specified that each new mail must be tagged with &lt;cite&gt;inbox&lt;/cite&gt;. You can
add several tags to new mails. In the &lt;cite&gt;[search]&lt;/cite&gt; section, the excluded tags are
specified.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="usage"&gt;
&lt;h2&gt;Usage&lt;/h2&gt;
&lt;p&gt;Once you have configured notmuch, you can run &lt;cite&gt;notmuch new&lt;/cite&gt; to process all
existing mails. The first run may take some time (in minutes, it is still quite
fast), but the subsequent runs will be very fast. You should run notmuch after
each offlineimap run. I personally run it in a shell script that is run by cron.
You could also use one of the hooks of offlineimap to run notmuch.&lt;/p&gt;
&lt;p&gt;Once indexing has been done, you can start searching your mails. The first
option to search mail is simply to use &lt;cite&gt;notmuch search &amp;lt;query&amp;gt;&lt;/cite&gt; from the command
line. This will directly displays the results. Search is instant on my mails.&lt;/p&gt;
&lt;p&gt;If you use mutt-kz like me, notmuch support is directly integrated. You can type
X, and then type your query like &lt;code&gt;notmuch://?query=X&lt;/code&gt; and the results will
be displayed as a normal Mutt folder. You can open mails directly from here and
you can also edit the mails as if you were in their source folders. This is
really practical.&lt;/p&gt;
&lt;p&gt;If you use mutt, you can have the same experience, by using the &lt;cite&gt;notmuch-mutt&lt;/cite&gt;
patch (&lt;cite&gt;here &amp;lt;http://notmuchmail.org/notmuch-mutt/&amp;gt;&lt;/cite&gt;). In several distributions,
there is an option to build it with this support or another package to add the
feature.&lt;/p&gt;
&lt;p&gt;Another feature of notmuch is its ability to tag mails. It automatically tags
new mails and deleted mails. But you can also explicitely tag messages by using
&lt;code&gt;notmuch tag&lt;/code&gt;. For instance, to tag all messages from the notmuch mailing
list:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_ae433180bd83499b839943721522468a-1" name="rest_code_ae433180bd83499b839943721522468a-1" href="https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html#rest_code_ae433180bd83499b839943721522468a-1"&gt;&lt;/a&gt;notmuch tag +notmuch -- tag:new and to:notmuch@notmuchmail.org
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I personally don't use this feature since I use imapfilter and IMAP folders to
sort my mail, but it can be very useful. You can run these commands in the
cronjob and always have you tags up to date. Tags can then be used in notmuch to
search or to create virtual folder in Mutt.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;That is already more or less everything that there is to know about notmuch. It
does not do a lot of thing, but it does them really well.&lt;/p&gt;
&lt;p&gt;That concludes the series of posts on Mutt. If you have any question on my Mutt
configuration, I'd be glad to extend on the comments.&lt;/p&gt;
&lt;/section&gt;</description><category>Gentoo</category><category>Gmail</category><category>Linux</category><category>Mutt</category><guid>https://baptiste-wicht.com/posts/2014/08/a-mutt-journey-search-mails-with-notmuch.html</guid><pubDate>Sat, 02 Aug 2014 15:24:12 GMT</pubDate></item><item><title>A Mutt journey: Mutt configuration</title><link>https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-my-mutt-configuration.html</link><dc:creator>Baptiste Wicht</dc:creator><description>&lt;p&gt;If you've followed my Mutt posts, you'll know that I'm &lt;a class="reference external" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html"&gt;filtering my mails with
imapfilter&lt;/a&gt; and
&lt;a class="reference external" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html"&gt;downloading them with offlineimap&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In this post, I'll share my Mutt configuration. I'm not using Mutt directly, but
mutt-kz which is a fork with good notmuch integration. For this post, it won't
change anything.&lt;/p&gt;
&lt;section id="configuration"&gt;
&lt;h2&gt;Configuration&lt;/h2&gt;
&lt;p&gt;The complete configuration is made in the .muttrc file. Mutt configuration
supports the source command so that you can put some of your settings in another
files and source them from the .muttrc file. You'll see that the configuration
can soon grow large and therefore, splitting it in several files will save you a
lot of maintenance issues ;)&lt;/p&gt;
&lt;p&gt;First, let's tell Mutt who we are:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set from = "baptiste.wicht@gmail.com"
set realname = "Baptiste Wicht"&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="receive-mail"&gt;
&lt;h2&gt;Receive mail&lt;/h2&gt;
&lt;p&gt;As I'm using offlineimap to get my mails, there is no IMAP settings in my
configuration. But you need to tell Mutt where the mails are:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set folder = /data/oi/

set spoolfile = "+Gmail/INBOX"
set postponed = "+Gmail/drafts"

source ~/.mutt/mailboxes&lt;/pre&gt;
&lt;p&gt;The spoolfile and postponed are specifying the inbox and draft mailboxes. The
.mutt/mailboxes file is generated by offlineimap.&lt;/p&gt;
&lt;p&gt;By default, Mutt will ask you to move read messages from INBOX to another
mailbox (set by mbox). I personally let my read messages in my inbox and move
them myself in a folder. For that, you have to disable the move:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set move = no&lt;/pre&gt;
&lt;p&gt;If you move a mail from a mailbox to another, Mutt will ask for confirmation,
you can disable this confirmation:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set confirmappend = no&lt;/pre&gt;
&lt;p&gt;If you use Mutt, you want to read plaintext messages rather than monstruous
HTML. You can tell Mutt to always open text plain if any:&lt;/p&gt;
&lt;pre class="literal-block"&gt;alternative_order text/plain text/html&lt;/pre&gt;
&lt;p&gt;If the mail has no text/plain part, you can manage to read HTML in Mutt in an
almost sane format. First, you need to tell Mutt to open html messages:&lt;/p&gt;
&lt;pre class="literal-block"&gt;auto_view text/html&lt;/pre&gt;
&lt;p&gt;And then, you need to tell it how to open it. Mutt reads a mailcap file to know
how to open content. You can tell Mutt where it is:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set mailcap_path = ~/.mailcap&lt;/pre&gt;
&lt;p&gt;And then, you have to edit the .mailcap file:&lt;/p&gt;
&lt;pre class="literal-block"&gt;text/html; w3m -I %{charset} -T text/html; copiousoutput;&lt;/pre&gt;
&lt;p&gt;That will use w3m to output the message inside Mutt. It works quite well. You
can also use linx if you prefer.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="send-mail"&gt;
&lt;h2&gt;Send mail&lt;/h2&gt;
&lt;p&gt;You need to indicate Mutt how to send mail:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set smtp_url = "smtp://baptistewicht@smtp.gmail.com:587/"
set smtp_pass = "SECRET"&lt;/pre&gt;
&lt;p&gt;Some people prefer to use another SMTP client instead of Mutt builtin SMTP
support, you can also do that by setting sendmail to the mailer program.&lt;/p&gt;
&lt;p&gt;It is generally a good idea to enforce the charset of sent mail:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set send_charset="utf-8"&lt;/pre&gt;
&lt;p&gt;You can choose another charset if you prefer ;)&lt;/p&gt;
&lt;p&gt;You need to configure vim to correctly handle mail editing:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set editor='vim + -c "set textwidth=72" -c "set wrap" -c "set spell spelllang=en"'&lt;/pre&gt;
&lt;p&gt;It sets the width of the text, enable wrap and configure spelling.&lt;/p&gt;
&lt;p&gt;By default, Mutt will ask you if you want to include the body of the message you
reply to in your answer and the reply subject. You can make that faster by using
these two lines:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set include=yes
set fast_reply&lt;/pre&gt;
&lt;p&gt;Once mail are sent, they are copied in your outgoing mailbox. If you use GMail,
the STMP server already does that for you, therefore you should disable this
behavior:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set copy = no&lt;/pre&gt;
&lt;/section&gt;
&lt;section id="appearance"&gt;
&lt;h2&gt;Appearance&lt;/h2&gt;
&lt;p&gt;Many things can also be configured in the appearance of Mutt. If you like the
threaded view of GMail, you want to configure Mutt in a similar way:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set sort = 'threads'
set sort_aux = 'reverse-last-date-received'&lt;/pre&gt;
&lt;p&gt;It is not as good as the GMail view, but it does the job :)&lt;/p&gt;
&lt;p&gt;You can make reading mail more comfortable using smart wrapping:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set smart_wrap&lt;/pre&gt;
&lt;p&gt;A mail has many many headers and you don't want to see them all:&lt;/p&gt;
&lt;pre class="literal-block"&gt;ignore *
unignore From To Reply-To Cc Bcc Subject Date Organization X-Label X-Mailer User-Agent&lt;/pre&gt;
&lt;p&gt;With that, you just configure which headers you're interested in.&lt;/p&gt;
&lt;p&gt;If you're using the sidebar patch (and you should be ;), you can configure the
sidebar:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set sidebar_visible = yes
set sidebar_width = 35
set sort_sidebar = desc

color sidebar_new yellow default&lt;/pre&gt;
&lt;p&gt;It makes the sidebar always visible with a width of 35 and sort the mailboxes.
The last line makes yellow the mailboxes that have unread mails.&lt;/p&gt;
&lt;p&gt;The index_format allows you to set what will shown for every mail in the index
view:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set index_format = "%4C %Z %{%b %d} %-15.15L %?M?(#%03M)&amp;amp;(%4l)? %?y?{%.20y}? %?g?{%.20g} ?%s (%c)"&lt;/pre&gt;
&lt;p&gt;This is a classical example that display the sender, the flags, the date, the
subject, the size of the mail and so on. You will need to look at the &lt;a class="reference external" href="http://www.mutt.org/doc/manual/manual-6.html"&gt;Reference&lt;/a&gt; to have more information on
what you can do with the format variables. There are plenty of information that
can be shown.&lt;/p&gt;
&lt;p&gt;You can also configure the text that is present on the status bar:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set status_chars  = " *%A"
set status_format = "───[ Folder: %f ]───[%r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? ]───%&amp;gt;─%?p?( %p postponed )?───"&lt;/pre&gt;
&lt;p&gt;The example here displays the current folder, the number of mails in it with
some details on deleted and unread mails and finally the number of postponed
mail. Again, if you want more information, you can read the reference.&lt;/p&gt;
&lt;p&gt;You can configure Mutt so that the index view is always visible when you read
mails. For instance, to always show 8 mails in the index:&lt;/p&gt;
&lt;pre class="literal-block"&gt;set pager_index_lines=8&lt;/pre&gt;
&lt;p&gt;Another important thing you can configure is the colors of Mutt. I'm not gonna
cover everything, since Mutt is very powerful on this part. For instance, here
are some examples from my configuration:&lt;/p&gt;
&lt;p&gt;color index         red             white           "~v~(~F)!~N"                # collapsed thread with flagged, no unread
color index         yellow          white           "~v~(~F~N)"                 # collapsed thread with some unread &amp;amp; flagged
color index_subject brightred       default         "~z &amp;gt;100K"
color header        blue            default         "^(Subject)"&lt;/p&gt;
&lt;p&gt;Unless you are really wanting to spend time on this part, I recommend to pick an
existing theme. I took a Solarized theme &lt;a class="reference external" href="https://github.com/altercation/mutt-colors-solarized"&gt;here&lt;/a&gt;. It looks quite good
and works well. There other themes available, you'll surely find the one that
looks best for you.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="bindings"&gt;
&lt;h2&gt;Bindings&lt;/h2&gt;
&lt;p&gt;Bindings are always very important. If like me, you're a vim aficionado, you'll
want your Mutt bindings to be as close as possible to vim. The default settings
are quite good, but not always close to vim.&lt;/p&gt;
&lt;p&gt;Something that is important to know when you configure Mutt bindings is that
they are relative to the current view open (index, pager,browser,attach, ...).
You can bind a keystroke to a different action in each view. You can also select
several views in which the keystroke is valid.&lt;/p&gt;
&lt;p&gt;If you are using the sidebar patch (and again, you should ;) ), you'll want to
configure fast bindings for it. Here are mine:&lt;/p&gt;
&lt;pre class="literal-block"&gt;bind index,pager \Ck sidebar-prev
bind index,pager \Cj sidebar-next
bind index,pager \Cl sidebar-open
bind index,pager \Cn sidebar-scroll-up
bind index,pager \Cv sidebar-scroll-down
bind index,pager \Ct sidebar-toggle&lt;/pre&gt;
&lt;p&gt;I use Ctrl+j,k to move inside the sidebar. I use Ctrl+l to open a folder and
Ctrl+n,v to scroll up and down. The last one is to toggle between multiple
sidebars for instance if you use notmuch.&lt;/p&gt;
&lt;p&gt;I find l very good to open messages in the index too:&lt;/p&gt;
&lt;pre class="literal-block"&gt;bind index l display-message
bind index gg first-entry
bind index G last-entry
bind index h noop               # Disable h&lt;/pre&gt;
&lt;p&gt;gg and G are used to go to the first and last element. Here I disabled h which
had a not often used command.&lt;/p&gt;
&lt;p&gt;The pager is the view where you read mail:&lt;/p&gt;
&lt;pre class="literal-block"&gt;bind pager h exit
bind pager gg top
bind pager G bottom
bind pager J next-line
bind pager K previous-line&lt;/pre&gt;
&lt;p&gt;In this view, I use h to get out of the pager, gg and G as usual. As I always
let the index open, I already use j and k to move in the index, so I chose J and
K to move in the pager.&lt;/p&gt;
&lt;p&gt;The browser is the view where you select folders for instance:&lt;/p&gt;
&lt;pre class="literal-block"&gt;bind browser l select-entry
bind browser L view-file
bind browser gg first-entry
bind browser G last-entry
bind browser h exit&lt;/pre&gt;
&lt;p&gt;Again, I use l and h to go back and forth and gg and G to go first and last. j
and k are already used here to go up and down.&lt;/p&gt;
&lt;p&gt;In the attach view:&lt;/p&gt;
&lt;pre class="literal-block"&gt;bind attach h exit
bind attach e edit-type # Edit MIME Types
bind attach l view-attach&lt;/pre&gt;
&lt;p&gt;I use h to exit and l to view an attachment.&lt;/p&gt;
&lt;p&gt;That is it for my bindings, but you configure a lot more of them.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This is the end of this post. I have covered my complete Mutt configuration
here. My .muttrc is available &lt;a class="reference external" href="https://github.com/wichtounet/dotfiles/blob/master/.muttrc"&gt;online&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you have comments on my configuration, you're welcome to let a comment on
this post ;)&lt;/p&gt;
&lt;p&gt;In the next blog post about my "Mutt journey", I'll talk about notmuch and this
will likely be the last post on this series.&lt;/p&gt;
&lt;/section&gt;</description><category>Gentoo</category><category>Gmail</category><category>Linux</category><category>Mutt</category><guid>https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-my-mutt-configuration.html</guid><pubDate>Tue, 22 Jul 2014 20:14:32 GMT</pubDate></item><item><title>A Mutt Journey: Download mails with offlineimap</title><link>https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html</link><dc:creator>Baptiste Wicht</dc:creator><description>&lt;p&gt;In the series of posts about Mutt, I recently presented how I was &lt;a class="reference external" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html"&gt;filtering my email&lt;/a&gt;. In this
post, I'll show how I download my emails locally using offlineimap. This is the
perfect companion for Mutt.&lt;/p&gt;
&lt;p&gt;With Mutt, you can easily directly query an IMAP server and keep the views up to
date with it. There are a few problem with this approach:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;First, you wont' be able to read your mails when you'are offline. It is
rarely an issue in these days, but it can be useful.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Opening an IMAP folder with a large number of mails (&amp;gt;1000) can be quite
slow. I've several large folders and it was a pain opening them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When Mutt synchronizes with the state of the IMAP server, you'll encounter a
freeze. If you want to synchronize often, it is quite boring.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Having your mails offline on your computers solves all these problems. Moreover,
it is also a good way to have a backup of your mails. I'm gonna talk here about
the usage for Mutt, but you can use offlineimap just for backup or for migration
reasons. The downside is that you have to store it locally. My mails takes
around 5GB on my computer.&lt;/p&gt;
&lt;p&gt;offlineimap is a very simple tool to synchronize emails from IMAP servers. It
only supports IMAP, but in those days it is not a limitation. The
synchronization is made both ways, it will upload your local changes to the IMAP
server. It is very powerful when paired with a MUA such as Mutt.&lt;/p&gt;
&lt;p&gt;To use offlineimap, you have to put your configuration in the ~/.offlineimaprc.
You can synchronize several accounts at once, in this post, we'll focus on one,
but the process is the same for several accounts. I'll focus on Gmail too, but
again it is the same with a bit different parameters for other mail accounts.&lt;/p&gt;
&lt;section id="configuration"&gt;
&lt;h2&gt;Configuration&lt;/h2&gt;
&lt;p&gt;First, we have to declare the account:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_9fb08201c5cb40fd84976963d86bb79d-1" name="rest_code_9fb08201c5cb40fd84976963d86bb79d-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9fb08201c5cb40fd84976963d86bb79d-1"&gt;&lt;/a&gt;[general]
&lt;a id="rest_code_9fb08201c5cb40fd84976963d86bb79d-2" name="rest_code_9fb08201c5cb40fd84976963d86bb79d-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9fb08201c5cb40fd84976963d86bb79d-2"&gt;&lt;/a&gt;accounts = Gmail
&lt;a id="rest_code_9fb08201c5cb40fd84976963d86bb79d-3" name="rest_code_9fb08201c5cb40fd84976963d86bb79d-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9fb08201c5cb40fd84976963d86bb79d-3"&gt;&lt;/a&gt;
&lt;a id="rest_code_9fb08201c5cb40fd84976963d86bb79d-4" name="rest_code_9fb08201c5cb40fd84976963d86bb79d-4" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9fb08201c5cb40fd84976963d86bb79d-4"&gt;&lt;/a&gt;[Account Gmail]
&lt;a id="rest_code_9fb08201c5cb40fd84976963d86bb79d-5" name="rest_code_9fb08201c5cb40fd84976963d86bb79d-5" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9fb08201c5cb40fd84976963d86bb79d-5"&gt;&lt;/a&gt;localrepository = Gmail-Local
&lt;a id="rest_code_9fb08201c5cb40fd84976963d86bb79d-6" name="rest_code_9fb08201c5cb40fd84976963d86bb79d-6" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9fb08201c5cb40fd84976963d86bb79d-6"&gt;&lt;/a&gt;remoterepository = Gmail-Remote
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;accounts&lt;/strong&gt; is the list of accounts that we have, here only one. Then, in
account, repositories are just names of the repositories we'll declare now.&lt;/p&gt;
&lt;p&gt;The local repository has to be configured:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_e22eaced9014412b9f274a5ad49b7388-1" name="rest_code_e22eaced9014412b9f274a5ad49b7388-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_e22eaced9014412b9f274a5ad49b7388-1"&gt;&lt;/a&gt;[Repository Gmail-Local]
&lt;a id="rest_code_e22eaced9014412b9f274a5ad49b7388-2" name="rest_code_e22eaced9014412b9f274a5ad49b7388-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_e22eaced9014412b9f274a5ad49b7388-2"&gt;&lt;/a&gt;type = Maildir
&lt;a id="rest_code_e22eaced9014412b9f274a5ad49b7388-3" name="rest_code_e22eaced9014412b9f274a5ad49b7388-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_e22eaced9014412b9f274a5ad49b7388-3"&gt;&lt;/a&gt;localfolders = /data/oi/Gmail/
&lt;a id="rest_code_e22eaced9014412b9f274a5ad49b7388-4" name="rest_code_e22eaced9014412b9f274a5ad49b7388-4" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_e22eaced9014412b9f274a5ad49b7388-4"&gt;&lt;/a&gt;sep = /
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first important point is &lt;strong&gt;localfolders&lt;/strong&gt; that sets where the mail will be
put on your computer. &lt;strong&gt;sep&lt;/strong&gt; defines the separator used for nested IMAP
folders. I recommend / since Mutt will nest them automatically if / is used as
separator.&lt;/p&gt;
&lt;p&gt;Then, the remote repository has to be configured:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_9861571406e64145848463989edcea80-1" name="rest_code_9861571406e64145848463989edcea80-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-1"&gt;&lt;/a&gt;[Repository Gmail-Remote]
&lt;a id="rest_code_9861571406e64145848463989edcea80-2" name="rest_code_9861571406e64145848463989edcea80-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-2"&gt;&lt;/a&gt;type = Gmail
&lt;a id="rest_code_9861571406e64145848463989edcea80-3" name="rest_code_9861571406e64145848463989edcea80-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-3"&gt;&lt;/a&gt;remoteuser = USER
&lt;a id="rest_code_9861571406e64145848463989edcea80-4" name="rest_code_9861571406e64145848463989edcea80-4" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-4"&gt;&lt;/a&gt;remotepass = PASSWORD
&lt;a id="rest_code_9861571406e64145848463989edcea80-5" name="rest_code_9861571406e64145848463989edcea80-5" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-5"&gt;&lt;/a&gt;realdelete = no
&lt;a id="rest_code_9861571406e64145848463989edcea80-6" name="rest_code_9861571406e64145848463989edcea80-6" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-6"&gt;&lt;/a&gt;folderfilter = lambda folder: folder not in ['[Gmail]/All Mail',
&lt;a id="rest_code_9861571406e64145848463989edcea80-7" name="rest_code_9861571406e64145848463989edcea80-7" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-7"&gt;&lt;/a&gt;                                             '[Gmail]/Important',
&lt;a id="rest_code_9861571406e64145848463989edcea80-8" name="rest_code_9861571406e64145848463989edcea80-8" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-8"&gt;&lt;/a&gt;                                             '[Gmail]/Starred',
&lt;a id="rest_code_9861571406e64145848463989edcea80-9" name="rest_code_9861571406e64145848463989edcea80-9" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-9"&gt;&lt;/a&gt;                                             ]
&lt;a id="rest_code_9861571406e64145848463989edcea80-10" name="rest_code_9861571406e64145848463989edcea80-10" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_9861571406e64145848463989edcea80-10"&gt;&lt;/a&gt;sslcacertfile = /etc/ssl/certs/ca-certificates.crt
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;remotepass&lt;/strong&gt; and &lt;strong&gt;remoteuser&lt;/strong&gt; are your user names and password. You can also
use &lt;strong&gt;remotepassfile&lt;/strong&gt; to read the password from a file. &lt;strong&gt;realdelete=no&lt;/strong&gt;
indicates that we only want to remove all the labels of deleted mails. For
Gmail, it means that the mail will still be in the All Mail folder. The last
line (sslcacertfile) is mandatory for recent versions of offlineimap. The
&lt;strong&gt;folderfilter&lt;/strong&gt; is a function that filters some folders. In my case, I do not
want to get the "All Mail", "Important" and "Starred" of my Gmail account
because it is only a duplicata of the mails in other labels. What is pretty cool
with offlineimap is that you can write Python directly in it for some of the
configuration options. Here is rule for filter is plain Python, so you can
complicated filtering if you want.&lt;/p&gt;
&lt;p&gt;Last, but not least, offlineimap can generates a list of mailboxes (one for each
folder in every account). It is pretty useful since Mutt can then read this file
and you'll find your mailboxes directly configured in Mutt :)&lt;/p&gt;
&lt;p&gt;This code will generate a file ~/.mutt/mailboxes that you can source in your
Mutt configuration and get the complete list of available mailboxes. This will
be kept up to date if you add new IMAP folders on the server for instance.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_a92cbaee6d934b84864b18c97388988f-1" name="rest_code_a92cbaee6d934b84864b18c97388988f-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_a92cbaee6d934b84864b18c97388988f-1"&gt;&lt;/a&gt;[mbnames]
&lt;a id="rest_code_a92cbaee6d934b84864b18c97388988f-2" name="rest_code_a92cbaee6d934b84864b18c97388988f-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_a92cbaee6d934b84864b18c97388988f-2"&gt;&lt;/a&gt;enabled = yes
&lt;a id="rest_code_a92cbaee6d934b84864b18c97388988f-3" name="rest_code_a92cbaee6d934b84864b18c97388988f-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_a92cbaee6d934b84864b18c97388988f-3"&gt;&lt;/a&gt;filename = ~/.mutt/mailboxes
&lt;a id="rest_code_a92cbaee6d934b84864b18c97388988f-4" name="rest_code_a92cbaee6d934b84864b18c97388988f-4" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_a92cbaee6d934b84864b18c97388988f-4"&gt;&lt;/a&gt;header = "mailboxes "
&lt;a id="rest_code_a92cbaee6d934b84864b18c97388988f-5" name="rest_code_a92cbaee6d934b84864b18c97388988f-5" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_a92cbaee6d934b84864b18c97388988f-5"&gt;&lt;/a&gt;peritem = "+%(accountname)s/%(foldername)s"
&lt;a id="rest_code_a92cbaee6d934b84864b18c97388988f-6" name="rest_code_a92cbaee6d934b84864b18c97388988f-6" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_a92cbaee6d934b84864b18c97388988f-6"&gt;&lt;/a&gt;sep = " "
&lt;a id="rest_code_a92cbaee6d934b84864b18c97388988f-7" name="rest_code_a92cbaee6d934b84864b18c97388988f-7" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_a92cbaee6d934b84864b18c97388988f-7"&gt;&lt;/a&gt;footer = "\n"
&lt;/pre&gt;&lt;/div&gt;
&lt;/section&gt;
&lt;section id="translate-names"&gt;
&lt;h2&gt;Translate names&lt;/h2&gt;
&lt;p&gt;You may have seen in the previous section some weird folder name like
"[Gmail]/All mail", this is how Gmail names folders that are not labels. This is
quite ugly and will create odd looking folders on your computer. You can
configure offlineimap to rename these names to better ones. For that, you'll
need to rule (in Python ;) ), one to translate from remote to local and one to
do the reverse.&lt;/p&gt;
&lt;p&gt;Here is what I did:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-1" name="rest_code_245eec60fddd43928eb0529581c56583-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-1"&gt;&lt;/a&gt;[Repository Gmail-Local]
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-2" name="rest_code_245eec60fddd43928eb0529581c56583-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-2"&gt;&lt;/a&gt;nametrans = lambda folder: {'drafts':   '[Gmail]/Drafts',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-3" name="rest_code_245eec60fddd43928eb0529581c56583-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-3"&gt;&lt;/a&gt;                            'sent':     '[Gmail]/Sent Mail',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-4" name="rest_code_245eec60fddd43928eb0529581c56583-4" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-4"&gt;&lt;/a&gt;                            'important':'[Gmail]/Important',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-5" name="rest_code_245eec60fddd43928eb0529581c56583-5" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-5"&gt;&lt;/a&gt;                            'spam':     '[Gmail]/Spam',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-6" name="rest_code_245eec60fddd43928eb0529581c56583-6" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-6"&gt;&lt;/a&gt;                            'starred':  '[Gmail]/Starred',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-7" name="rest_code_245eec60fddd43928eb0529581c56583-7" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-7"&gt;&lt;/a&gt;                            'trash':    '[Gmail]/Trash',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-8" name="rest_code_245eec60fddd43928eb0529581c56583-8" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-8"&gt;&lt;/a&gt;                            'archive':  '[Gmail]/All Mail',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-9" name="rest_code_245eec60fddd43928eb0529581c56583-9" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-9"&gt;&lt;/a&gt;                            }.get(folder, folder)
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-10" name="rest_code_245eec60fddd43928eb0529581c56583-10" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-10"&gt;&lt;/a&gt;
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-11" name="rest_code_245eec60fddd43928eb0529581c56583-11" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-11"&gt;&lt;/a&gt;[Repository Gmail-Remote]
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-12" name="rest_code_245eec60fddd43928eb0529581c56583-12" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-12"&gt;&lt;/a&gt;nametrans = lambda folder: {'[Gmail]/Drafts':    'drafts',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-13" name="rest_code_245eec60fddd43928eb0529581c56583-13" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-13"&gt;&lt;/a&gt;                            '[Gmail]/Sent Mail': 'sent',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-14" name="rest_code_245eec60fddd43928eb0529581c56583-14" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-14"&gt;&lt;/a&gt;                            '[Gmail]/Starred':   'flagged',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-15" name="rest_code_245eec60fddd43928eb0529581c56583-15" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-15"&gt;&lt;/a&gt;                            '[Gmail]/Important':   'important',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-16" name="rest_code_245eec60fddd43928eb0529581c56583-16" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-16"&gt;&lt;/a&gt;                            '[Gmail]/Spam':   'spam',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-17" name="rest_code_245eec60fddd43928eb0529581c56583-17" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-17"&gt;&lt;/a&gt;                            '[Gmail]/Trash':     'trash',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-18" name="rest_code_245eec60fddd43928eb0529581c56583-18" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-18"&gt;&lt;/a&gt;                            '[Gmail]/All Mail':  'archive',
&lt;a id="rest_code_245eec60fddd43928eb0529581c56583-19" name="rest_code_245eec60fddd43928eb0529581c56583-19" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html#rest_code_245eec60fddd43928eb0529581c56583-19"&gt;&lt;/a&gt;                            }.get(folder, folder)
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I simply renamed all "[Gmail]" folders into something more readable and that
makes more sense to me. It is not limited to special Gmail folders of course,
this can also be applied to rename a folder X into a folder Y in the same. As it
is Python, you can do sophisticated stuff if necessary.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="speed-up-things"&gt;
&lt;h2&gt;Speed up things&lt;/h2&gt;
&lt;p&gt;If you happen to sync your mails often, you may want to speed things up. There
are several ways to do that.&lt;/p&gt;
&lt;p&gt;The first thing you can do is use several connections to the server. You can set
maxconnections to a number higher than 1 in the remote repository configuration.
I tested several values and for Gmail 2 was the fastest choice. You can try some
values with your server to see what value is good.&lt;/p&gt;
&lt;p&gt;Instead of plain old text files for the status of the mails, offlineimap can use
a sqlite backend. This is much faster since the complete file is not rewritten
for each update of the flags. For that behaviour, you have to set
&lt;strong&gt;status_backend = sqlite&lt;/strong&gt; in the Account configuration.&lt;/p&gt;
&lt;p&gt;Another thing you can do is reduce the I/O involved during sync by setting
general.fsync to false. With that, offlineimap won't have to wait for disk
operation completion after each operation.&lt;/p&gt;
&lt;p&gt;You can run offlineimap in quick mode with -q option. With this option, change
in flags of remote messages will not be updated locally. Changes on the local
side will be uploaded corectly. It is generally a good idea is to run
offlineimap in quick mode often (every X minutes) and run it in normal mode once
or twice a day.&lt;/p&gt;
&lt;p&gt;You can also specify which folder to sync with the -f option. Sometimes it is
enough to sync INBOX for instance. It may be much faster.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Now that you have fully configured offlineimap, you can make it run by hand or
in a cron job. I personally run it every 5 minutes, you can choose your
favourite frequency according to your workflow. I think I'll reduce the
frequency further, it is more comfortable to get mails only by batch and not
too much of them.&lt;/p&gt;
&lt;p&gt;If you're interested, you can take a look at &lt;a class="reference external" href="https://github.com/wichtounet/dotfiles/blob/master/.offlineimaprc"&gt;my .offlineimaprc configuration&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you want more information about this awesome tool, you can take a look at the
&lt;a class="reference external" href="http://docs.offlineimap.org/en/latest/"&gt;reference documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is it for this part of this series. In the next post, I'll present my Mutt
configuration and how I use it.&lt;/p&gt;
&lt;/section&gt;</description><category>Gentoo</category><category>Gmail</category><category>Linux</category><category>Mutt</category><category>Python</category><guid>https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-download-mails-with-offlineimap.html</guid><pubDate>Wed, 16 Jul 2014 17:54:40 GMT</pubDate></item><item><title>A Mutt Journey: Filter mails with imapfilter</title><link>https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html</link><dc:creator>Baptiste Wicht</dc:creator><description>&lt;p&gt;About a month ago, I decided to switch to Mutt to read my emails. I kept my
GMail account, but I don't use the web interface anymore. It took me a long time
to prepare a complete enviromnent.&lt;/p&gt;
&lt;p&gt;Currently, i'm using:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;imapfilter to filter mails&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;offlineimap to download my mails&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;notmuch to quickly search all my mails&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And of course Mutt. To be precise, I use mutt-kz, a fork of mutt with very good
notmuch integration.&lt;/p&gt;
&lt;p&gt;I'll try to explain each part of my environment in a series of articles on this
blog. The first one will be about imapfilter.&lt;/p&gt;
&lt;p&gt;imapfilter is a mail filtering utility. It connects to a remote server using
IMAP and is then able to move, copy or delete mails around. You can use it for
several tasks:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Delete unwanted mail&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Move mails into folders according to rules&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What is pretty cool is that the configuration is entirely made in Lua. It is
quite easy to write rules and then apply them to several mailboxes as if you
were programming.&lt;/p&gt;
&lt;p&gt;Another advantage of imapfilter is that it works at the server level. Therefore,
even if you use your web client from time to time or check your mail on your
phone, the changes will still be viewable.&lt;/p&gt;
&lt;p&gt;The configuration is done in the ~/.imapfilter/config.lua file. The
configuration is quite easy, you have to declare an IMAP object as the account.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code lua"&gt;&lt;a id="rest_code_7807a6f0641048789df68ccaa0436054-1" name="rest_code_7807a6f0641048789df68ccaa0436054-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_7807a6f0641048789df68ccaa0436054-1"&gt;&lt;/a&gt;&lt;span class="kd"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;IMAP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_7807a6f0641048789df68ccaa0436054-2" name="rest_code_7807a6f0641048789df68ccaa0436054-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_7807a6f0641048789df68ccaa0436054-2"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'imap_sever'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_7807a6f0641048789df68ccaa0436054-3" name="rest_code_7807a6f0641048789df68ccaa0436054-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_7807a6f0641048789df68ccaa0436054-3"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'username'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_7807a6f0641048789df68ccaa0436054-4" name="rest_code_7807a6f0641048789df68ccaa0436054-4" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_7807a6f0641048789df68ccaa0436054-4"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_7807a6f0641048789df68ccaa0436054-5" name="rest_code_7807a6f0641048789df68ccaa0436054-5" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_7807a6f0641048789df68ccaa0436054-5"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;ssl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'ssl3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_7807a6f0641048789df68ccaa0436054-6" name="rest_code_7807a6f0641048789df68ccaa0436054-6" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_7807a6f0641048789df68ccaa0436054-6"&gt;&lt;/a&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As the configuration is in Lua, you can easily get the password from another
file. For instance, here is my account declaration:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code lua"&gt;&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-1" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-1"&gt;&lt;/a&gt;&lt;span class="kd"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;IMAP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-2" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-2"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'imap.gmail.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-3" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-3"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'baptiste.wicht@gmail.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-4" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-4" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-4"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;get_imap_password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".password.offlineimaprc"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-5" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-5" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-5"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nv"&gt;ssl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'ssl3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-6" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-6" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-6"&gt;&lt;/a&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-7" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-7" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-7"&gt;&lt;/a&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-8" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-8" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-8"&gt;&lt;/a&gt;&lt;span class="c1"&gt;-- Utility function to get IMAP password from file&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-9" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-9" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-9"&gt;&lt;/a&gt;&lt;span class="kr"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;get_imap_password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-10" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-10" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-10"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;home&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;os.getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"HOME"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-11" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-11" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-11"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;file&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;home&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;file&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-12" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-12" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-12"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;str&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;io.open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;file&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-13" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-13" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-13"&gt;&lt;/a&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kr"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;str&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_ae01d1a888734f458e9a1439bc672fd8-14" name="rest_code_ae01d1a888734f458e9a1439bc672fd8-14" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_ae01d1a888734f458e9a1439bc672fd8-14"&gt;&lt;/a&gt;&lt;span class="kr"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It gets the password by reading a file in the home directory.&lt;/p&gt;
&lt;p&gt;Once, you have the account, you can check the status of a folder with the
check_status() function. For instance:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code lua"&gt;&lt;a id="rest_code_598a8cc4171047cdb2ab53817aec2202-1" name="rest_code_598a8cc4171047cdb2ab53817aec2202-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_598a8cc4171047cdb2ab53817aec2202-1"&gt;&lt;/a&gt;&lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;INBOX&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;check_status&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;a id="rest_code_598a8cc4171047cdb2ab53817aec2202-2" name="rest_code_598a8cc4171047cdb2ab53817aec2202-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_598a8cc4171047cdb2ab53817aec2202-2"&gt;&lt;/a&gt;&lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'[Gmail]/Trash'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;&lt;span class="nf"&gt;check_status&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can run imapfilter simply by launching imapfilter on the command line. Once
imapfilter is run, it will print the status of the folder you choses:&lt;/p&gt;
&lt;pre class="literal-block"&gt;38 messages, 0 recent, 6 unseen, in baptiste.wicht@gmail.com@imap.gmail.com/INBOX.
70 messages, 0 recent, 67 unseen, in baptiste.wicht@gmail.com@imap.gmail.com/[Gmail]/Trash.&lt;/pre&gt;
&lt;p&gt;Several functions are important:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;select_all() on a folder allows you to get messages from an account to them
perform action on them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;contain_subject('subject') on a list of mails allows you to keep only the mails
that contains 'subject' in their subject&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;contain_from('from') on a list of mails allows you to keep only the mails
that comes from 'from'&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;contain_to('to') on a list of mails allows you to keep only the mails
that are addressed to 'to'&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;delete_messages() on a collection of mails deletes all of them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;move_messages(folder) on a collection of mails moves all of them to another
folder.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can also mix different IMAP accounts, you don't have to use only one.&lt;/p&gt;
&lt;p&gt;For instance, if you would delete all the mail coming from me, you could do:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code lua"&gt;&lt;a id="rest_code_3b09e01b94354a239a37b35108c0c7d1-1" name="rest_code_3b09e01b94354a239a37b35108c0c7d1-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_3b09e01b94354a239a37b35108c0c7d1-1"&gt;&lt;/a&gt;&lt;span class="nv"&gt;mails&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;INBOX&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;select_all&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;a id="rest_code_3b09e01b94354a239a37b35108c0c7d1-2" name="rest_code_3b09e01b94354a239a37b35108c0c7d1-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_3b09e01b94354a239a37b35108c0c7d1-2"&gt;&lt;/a&gt;&lt;span class="nv"&gt;filtered&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;mails&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;contains_from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"baptiste.wicht@gmail.com"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_3b09e01b94354a239a37b35108c0c7d1-3" name="rest_code_3b09e01b94354a239a37b35108c0c7d1-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_3b09e01b94354a239a37b35108c0c7d1-3"&gt;&lt;/a&gt;&lt;span class="nv"&gt;filtered&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;delete_messages&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or you could move all the mails containing Urgent in the subject line to an IMAP
folder:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code lua"&gt;&lt;a id="rest_code_cd123bd4438b4a55b6ac257fdcc38c37-1" name="rest_code_cd123bd4438b4a55b6ac257fdcc38c37-1" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_cd123bd4438b4a55b6ac257fdcc38c37-1"&gt;&lt;/a&gt;&lt;span class="nv"&gt;mails&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;INBOX&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;select_all&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;a id="rest_code_cd123bd4438b4a55b6ac257fdcc38c37-2" name="rest_code_cd123bd4438b4a55b6ac257fdcc38c37-2" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_cd123bd4438b4a55b6ac257fdcc38c37-2"&gt;&lt;/a&gt;&lt;span class="nv"&gt;filtered&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;mails&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;contains_subject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Urgent"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_cd123bd4438b4a55b6ac257fdcc38c37-3" name="rest_code_cd123bd4438b4a55b6ac257fdcc38c37-3" href="https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html#rest_code_cd123bd4438b4a55b6ac257fdcc38c37-3"&gt;&lt;/a&gt;&lt;span class="nv"&gt;filtered&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;move_messages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;account&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"urgent_mails"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you want some more examples, you can take a look at &lt;a class="reference external" href="https://github.com/wichtounet/dotfiles/blob/master/.imapfilter/config.lua"&gt;my imapfilter
configuration&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The best way to start using it is to look at examples, there are plenty of them
in the internet, especially in Github dotfiles repositories.&lt;/p&gt;
&lt;p&gt;The reference documentation is available using 'man imapfilter_config', there is
plenty more to see.&lt;/p&gt;
&lt;p&gt;For more information, you can also consult the &lt;a class="reference external" href="https://github.com/lefcha/imapfilter"&gt;offical site&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;That is it for this part of the mutt series. In the next post about mutt, I'll
talk about how I use offlineimap to get my mails.&lt;/p&gt;</description><category>Gentoo</category><category>Gmail</category><category>Linux</category><category>Mutt</category><guid>https://baptiste-wicht.com/posts/2014/07/a-mutt-journey-filter-mails-with-imapfilter.html</guid><pubDate>Tue, 08 Jul 2014 18:58:32 GMT</pubDate></item></channel></rss>