Tag Archives: mutt

Using your Gmail contacts in Mutt

I really enjoy using Mutt as my email client. However, sometimes I have to log
into my Gmail account to view my contacts. Tired of this, I exported my Gmail
contacts and imported them into abook.

Now I can view my Gmail contacts in Mutt.

Here’s how I did it:

(Sorry, no cut and paste instructions.)

* Export your Gmail contacts in the vcard format

* Download the abook source and patch it with the vcard diff (available on the abook website). NOTE: you can also use the vcard2abook.pl script available in the contrib/ dir in the source.

* Import your contacts by invoking abook with the following options: ‘–convert –informat vcard –infile INPUT.vcf –outformat abook –outfile ~/.abook/addressbook’

* Configure your abook (see `man abookrc`). abook has sane defaults so your config file can be very minimal:

set www_command=elinks
set add_email_prevent_duplicates=true

* Next, configure mutt to interact with abook. I added the following lines to my muttrc
set query_command=”abook –mutt-query ‘%s'”
macro index,pager A “abook –add-email-query” “add the sender to the address book”

That’s all :). Press A while in Mutt to add a contact and Q to query the address book.

Advertisements

Setting up IMAP on Mutt

After receiving my HP 2710p, I decided to use IMAP instead of POP for
managing my email.  As you know, Mutt is my primary MUA (mail user agent).

The benefits of this setup are obvious: synchronous email (both on the computer
and on the webserver), space savings, and less programs to configure.

In this example, I’ll be setting up an IMAP connection to Gmail from Mutt.

First download the certificate of the organisation that is providing the IMAP
service.  Gmail uses “ThawtePremiumServerCA.crt”.  Make sure you compare your
checksum with the one provided by the Thawte Certificate Authority.  Place this
certificate in “~/.certs”.

Next, configure a profile for use with the IMAP connection.  I have an
engineering account with my university as well as a Gmail account, so I need two
profiles.  The Mutt profile is simple.

---~/.mutt/mutt1---
# email@gmail.com

source ~/.muttrc
set imap_user="email@gmail.com"
set folder="imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed=+"[Gmail]/Drafts"
set smtp_url="smtp://email@smtp.gmail.com:587/"
------

Note: My ~/.muttrc” contains global configuration values.

Next, simply add aliases for each profile that you create.  For example:

---~/.bashrc---
[ ... ]
alias mutt1="mutt -F ~/.mutt/muttrc_gmail"
alias mutt2="mutt -F ~/.mutt/muttrc_college"
------

To use your configuration, issue “mutt1” or “mutt2” at the prompt.

Customising Email Signatures with Fortune

When I look at someone’s email signature and see a thought-provoking quote like “Violence is the last refuge of the incompetent” (Salvor Hardin), I add it to my mental list of quotes, which, of course, is soon forgotten. Now, with a bit of pipe magic, I can use Mutt and fortune to make my signatures a bit more creative.

Preparing the database

1. Create a .fortune file in your home directory and insert your quotes.  Separate each quote/phrase with a % (percentage sign).

~ %   touch ~/fortune
~ %   vim ~/fortune
  1 De duobus malis minus est semper eligendum.
  2   -- Thomas a Kempis
  3 %
  4 Sic transit gloria mundi.
  5   -- Thomas a Kempis
  6 %

2. Randomise access to the strings with strfile.

~ %   strfile -r ~/fortune ~/fortune.dat
"/home/antony/fortune.dat" created
There were 2 strings
Longest string: 65 bytes
Shortest string: 47 bytes

To save yourself embarrassment in the future, keep your quotes short and SFW.

Integrating the database with Mutt

3. Create a simple script to use with Mutt.

~ %   touch bin/signature.sh
~ %   vim bin/signature.sh
  1 #!/bin/bash
  2
  3 cat ~/.signature
  4 fortune ~/fortune
~ %   chmod +x bin/signature.sh

4. Finally, set the script as Mutt’s default signature.

~ %   vim ~/.mutt/muttrc
17 set signature="~/bin/signature.sh |"

Now you can enjoy creative, original signatures in your emails.

After a bit of thought, I came up with a heavily customised signature script that will: print the contents of ~/.signature, append a justified fortune quote from my database and right justify the attributed author.  Of course, it needs some work because the last line is right justified regardless of if there is an attributed author or not.

1 #!/bin/bash
2
3 fortune ~/fortune | sed -e 's/^/++ /' -e 's/$/ ++/' > /tmp/signature.1
4 sed -n '$!p' /tmp/signature.1 | par -58s3p3 > /tmp/signature.2
5 tail -n1 /tmp/signature.1 | sed -e :a -e 's/^.\{1,56\}$/ &/;ta' -e 's/++/\ \ /' -e 's/^./++/' >> /tmp/signature.2
6 cat ~/.signature
7 cat /tmp/signature.2

outputting something similar to:

Antony Jepson / <aaaaaaaa@gmail.com> / GPG Key: 0x00000000
++ Sapere aude! (Dare to be wise!)                      ++
++                          -- Quintus Horatius Flaccus ++

Adding additional email accounts to your email setup

Upon hearing that my college offers email access through its POP and SMTP servers, I immediately set out to integrate it into my email setup.

Today I will show you how.

Note: I use Mutt to read my email, getmail to retrieve my mail, procmail to filter my mail, and msmtp to send my mail.  This tutorial can also be used for configuring a new account in a similar setup.

Because my email setup is quite complicated, this will take longer to configure than it would with a mail client such as Thunderbird or Outlook.  However, I enjoy the level of customization offered by such a setup.

1. Setting up getmail

First, make sure that you have the .getmail directory in your home dir.  If not, create it (mkdir -m 700 ~/.getmail)

~ %  ls -la | grep getmail
drwx------  2 antony antony 4.0K 2008-07-09 17:30 .getmail/

Change to the .getmail directory and create the account file.

~ %  cd .getmail
.getmail %  touch getmailrc_college

Edit the file.  Note: !$ means the last space separated word from the previous command, in this case “getmailrc_college”

.getmail %  vim !$
1 [retriever]
2 type = SimplePOP3SSLRetriever
3 server = pop.college.edu
4 username = name
5 port = 995
6 password = password
7
8 [destination]
9 type = MDA_external
10 path = /usr/bin/procmail

Change the file permissions (read, write for user)

.getmail %  chmod 600 getmailrc_college

2. Setting up procmail

All we have to do is add a filter for email from the college domain address.  Note: Because my college email address can have a number 0-9 appended to the end of the username, I used the regex [0-9], which matches one digit.gt

.getmail %  cd
~ % vim ~/.procmailrc
20 :0
21 * ^TO_name[0-9]@college\.edu
22 college/

3. Setting up msmtp

This is the most involved step.

Security is always first, so check the available authentication options of the server.  I’ll use Gmail as an example (yep, straight from the manpage).

~ %  msmtp --serverinfo --host=smtp.gmail.com --tls=on --port=587 --tls-certcheck=off
SMTP server at smtp.gmail.com (yw-in-f109.google.com [74.125.47.109]), port 587:
    mx.google.com ESMTP 6sm2875694ywp.3
TLS certificate information:
    Owner:
        Common Name: smtp.gmail.com
        Organization: Google Inc
        Locality: Mountain View
        State or Province: California
        Country: US
    Issuer:
        Common Name: Thawte Premium Server CA
        Organization: Thawte Consulting cc
        Organizational unit: Certification Services Division
        Locality: Cape Town
        State or Province: Western Cape
        Country: ZA
[truncated]
Capabilities:
    SIZE 28311552:
        Maximum message size is 28311552 bytes = 27.00 MB
    STARTTLS:
        Support for TLS encryption via the STARTTLS command
    AUTH:
        Supported authentication methods:
        PLAIN LOGIN

The important part here is the issuer of the certificate (shown by the Common Name). In this case, the issuer is “Thawte Premium Server CA” so we need to download that certificate from the Thawte website and place it in our ~/.certs directory.

~ %  cd ~/.certs
.certs %  unzip thawte-roots.zip -d thawte [truncated output]
.certs %  cd thawte
thawte %  cd Thawte\ Server\ Roots
Thawte Server Roots %  ls
Thawte Server Roots.txt    ThawtePremiumServerCA.cer      ThawteServerCA.509  ThawteServerCA_b64.txt
ThawtePremiumServerCA.509  ThawtePremiumServerCA_b64.txt  ThawteServerCA.cer
Thawte Server Roots %  cp ThawtePremiumServerCA.cer ../../
Thawte Server Roots %  cd !$
.certs %  ls
ThawtePremiumServerCA.cer  thawte/  thawte-roots.zip
.certs %  rm -r thawte*

Now you can use TLS, so edit your ~/.msmtprc file

.certs %  cd
~ % vim .msmtprc
21 account college
22 host smtp.college.edu
23 from name@college.edu
24 user name@college.edu
25 password somepassword
26 port 587
27 auth on
28 tls on
29 tls_trust_file /home/antony/.certs/ThawtePremiumServerCA.crt

4. Next, configure Mutt for account switching.

~ %  cd .mutt

Create a profile for each account. Because I include my email address in my signature, I have to switch to a different signature when I change email accounts.  The unmy_hdr resets the my_hdr variable, which is then defined by the following my_hdrset sendmail= tells Mutt to use a different sendmail command.  And set compose_format changes the display at the bottom of the screen so I know which mail account I am using.

~ % vim muttrc.local1
  1 # default Mutt profile
  2 set signature="~/.signature"
  3 unmy_hdr
  4 my_hdr From: Antony Jepson <email@gmail.com>
  5 my_hdr Reply-To: Antony Jepson <email@gmail.com>
  6 set sendmail="/usr/bin/msmtp --account default"
  7 set compose_format="-- default Mutt: Compose [Approx. msg size: %l] Atts:%a]%>-"
~ % vim muttrc.local2
  1 # college Mutt profile
  2 set signature="~/.signature2"
  3 unmy_hdr
  4 my_hdr From: First Last <name@college.edu>
  5 my_hdr Reply-To: First Last <name@college.edu>
  6 set sendmail="/usr/bin/msmtp --account college"
  7 set compose_format="-- college Mutt: Compose [Approx. msg size: %l] Atts:%a]%>-"

All we have to do is add a keyboard-binding that will source each different profile.  This configuration will switch to a different profile when I press Control-q and Control-w.

.mutt %  vim macros.rc
  4 macro index "\Cq" ":source ~/.mutt/muttrc.local1\n" "Load default profile"
  5 macro index "\Cw" ":source ~/.mutt/muttrc.local2\n" "Load college profile"

And, if you are not already sourcing this rc file in the default mutt configuration, add it.

.mutt %  echo "source ~/.mutt/macros.rc" >> ~/.mutt/muttrc

5. Finally, because I will be using this address for the next four years, I’ll add it to my gpg key.

.mutt %  cd
~ %  gpg --edit-key Antony\ Jepson [truncated output]
Command> adduid
Real name: Antony Jepson
Email address: name@college.edu
Comment: College email
You selected this USER-ID:
    "Antony Jepson (College email) <name@college.edu>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O

You need a passphrase to unlock the secret key for
    user: "Antony Jepson (College email) <name@college.edu>"
    [truncated]
    Passphrase: somepassphrase
Command> save

Finally, send your updated key to the keysever.

~ %  gpg --send-key name@college.edu

And that’s it.  You now (or I, at least) have a working, secure, additional, Mutt-enabled, email account!

I’m still getting used to the WYSIWYG WordPress formatting toolbar, I’ll make (hopefully better) use of it as I write more posts.

Setting up Mutt

Mutt is an extremely fast and flexible text-based mail user agent with local maildir, POP3, and IMAP support.  It is my default mail client by choice.  Today, I will show you my Mutt configuration; perhaps it’ll help you to setup Mutt as well.

The diagram to the left (created with Xy-pic) shows my ~/.mutt hierarchy.  I’ll explain what each file/directory contains and then I’ll concatenate my the main configuration file, ~/.mutt/muttrc.

~/.mutt/aliases.rc – contains a list of my contacts in the format:

alias shortname Firstname Lastname email@address.com

~/.mutt/cache/ – contains a cache my mail headers for faster access

~/.mutt/gpg.rc – contains the commands for use with pgp/gpg encryption

~/.mutt/lists.rc – contains the subscribe command for each mailing-list I am subscribed to.  The subscribe command makes Mutt behave differently when reading mailing-lists (changes the default reply-to to the mailing list).

~/.mutt/muttrc – the main configuration file.  It is heavily commented below for your convenience.

~/.mutt/muttrc.local{1,2,3} – supplemental configuration files used for when I switch email accounts.

~ %  cat ~/.mutt/muttrc

#==============================================================================#
set realname="Antony Jepson"    # My real name.
set sendmail="/usr/bin/msmtp"   # Sends the mail.
set edit_headers=no             # Can I edit headers of a message?
set index_format="%4C %Z %d %-15.15L (%-5c) %s" # Specify the index format.
# %4C - index number
# %Z - status flags
# %-15.15F - left justify the From: with a max of 15 characters
# %c - number of characters in the message
# %s - subject line

set date_format="%F"
set wait_key=no                 # Don't wait after using external programs.
set editor="vim + -c 'setlocal tw=72'" # Use vim as my default editor.
set signature="~/.signature"    # Set the default signature file.
#==============================================================================#
set alias_file=~/.mutt/aliases.rc  # Store aliases here.
source ~/.mutt/aliases.rc       # Source the aliases file.
source ~/.mutt/lists.rc         # Source the mailing-lists file.
source ~/.mutt/macros.rc        # Source the macros file.
source ~/.mutt/gpg.rc		# Source the GPG file.
set sort_alias=alias            # Sort the alias list (alphabetically).
set header_cache=~/.mutt/cache/ # Cache headers for speedier message reading.
#==============================================================================#
set folder=/home/antony/mail    # Default mail folder.
set mbox_type=Maildir           # Type of mbox (inbox).
set postpone=yes                # Postpone messages when not sent immediately?
set postponed=+drafts           # Where to store postponed messages.
set spoolfile=+inbox            # Replaces the environment variable $MAIL.
set copy=yes                    # Save a copy of messages?
#==============================================================================#
set include=yes                 # Include copy of message in reply?
set fast_reply=yes              # Prompt for recipients and subjects?
set beep=no                     # Beep when an error occurs?
set move=no                     # Do not move read messages.
set mark_old=no                 # New unread messages = old after exiting mbox?
set sort=threads                # How to sort messages in index menu.
set mail_check=60               # How often to check for mail (every hour).
set smart_wrap                  # Wrap long lines by words.
#==============================================================================#

# mailboxes - which folders receive mail and will be checked for messages.
mailboxes =inbox =quarantined =college

# my_hdr - Create custom header fields which are added to every message sent.
my_hdr From: Antony Jepson 

# ignore * - ignore all headers then specify only the ones wanted.
ignore *
unignore From:
unignore To:
unignore Reply-To:
unignore Subject:
unignore Date:
unignore CC:
unignore BCC:
unignore X-Virus-Status:

folder-hook .           set record="^"
# ^ = save sent messages in currently open folder

# hdr_order - specify the order to present headers.
hdr_order From: To: Reply-To: CC: BCC: Date: Subject: X-Virus-Status:

# pager_context - specify how many lines that are given when changing pages.
set pager_context=5

# pager_index_lines - specify how many lines of the index to show in the pager.
set pager_index_lines=7

# print_command - defines how should mutt print files
# First convert the file for printing with pr and then pipe the output to
# the printer (without a banner)
set print_command="/usr/bin/pr | /usr/bin/lpr -h"

#==============================================================================#
# custom colour scheme
color   hdrdefault      brightcyan      blue
color   header          brightwhite     blue  "^from:"
color   header          brightwhite     blue  "^subject:"
color   quoted          brightgreen     blue
color   signature       brightwhite     blue
color   indicator       blue            green
color   error           red             black
mono    error           bold
color   status          black cyan
mono    status          bold
color   tree            yellow          blue
color   tilde           blue            blue
color   body            brightwhite     blue  "[-a-z_0-9.]+@[-a-z_0-9.]+"
mono    body            bold                  "[-a-z_0-9.]+@[-a-z_0-9.]+"
color   body            brightyellow    black "^Good signature"
mono    body            bold                  "^Good signature"
color   body            brightwhite     red   "^Bad signature from.*"
mono    body            bold                  "^Bad signature from.*"
color   normal          white           blue
color   message         green           black
color   attachment      brightgreen     blue

Diagram

If you wondered how I created the diagram, it’s pretty simple:

tmp %  cat mutt.tex

\documentclass{article}
\usepackage[all]{xy}
\begin{document}

\xymatrix{
& aliases.rc \\
& cache/ \\
& gpg.rc \\
& lists.rc \\
.mutt \ar@/^/[uuuur]
      \ar@/^/[uuur]
      \ar@/^/[uur]
      \ar@/^/[ur]
      \ar[r]
      \ar@/_/[dr]
      \ar@/_/[ddr]
      \ar@/_1pc/[dddr]
      \ar@/_1.8pc/[ddddr] & macros.rc \\
& muttrc \\
& muttrc.local1 \\
& muttrc.local2 \\
& muttrc.local3
}
\end{document}

Take a look at my article on using Xy-pic for some more examples of its capabilities.

My Desktop – The Terminal

AJ\'s Workspace (2008-06-25)This will be the final post covering my desktop.
If you look in the bottom left corner of the screenshot, you will see my terminal, rxvt-unicode.

For the most part, I’m a cli person.  I prefer the terminal because of it’s speed.

In the terminal, you can see me running irssi (an irc client) within screen, a detachable terminal multiplex.  Basically, screen allows me to continue using the terminal’s applications even in the event of an X server crash.tirssit

A terminal is basically a portal into the underlying filesystem of my Linux installation.  Much like a MS-DOS prompt, it allows me to navigate this hidden infrastructure with uncanny ease.

Some of my frequently used terminal programs include:

gnu mc (midnight commander) – a file browser

irssi – an irc client (you can find me on freenode)

vim – a text editor (although capable of much, much more)

abcde (A Better CD Encoder) – a cd ripper (makes ripping easy)

nethack – a great rpg

ncmpc – a cli client for mpd (the music player daemon)

mutt – my favourite mail user agent