Category Archives: Internet

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

Elinks advanced URI management

In the process of whipping elinks into a tame beast, I discovered several options that I wasn’t aware of.

URI rewriting: allows me to execute Google searches, dictionary lookups, and imdb queries within the ‘Goto URL’ dialog box. It should be enabled by default but if not, go to the Option manager -> Protocols -> URI rewriting and select either Dumb or Smart Prefixes. Once enabled, you can type ‘g search_term’ in the search box to quickly search Google for search_term. Look at the other prefixes to determine your options.

I wasn’t satisfied with having to use a prefix every time I wanted to search, so I modified the default template (Option manager -> Protocols -> URI rewriting -> Default template) to ‘http://www.google.com/search?q=%s’. This means that any entry in the ‘Goto URL’ dialog box that doesn’t look like a URL, a file, or an existing prefix will result in a Google search with that string!

Sessions: It turns out that elinks is a beast with many abilities, I wasn’t aware that it supported session saving/restoring (Option manager -> User interface -> Sessions).

URI passing: Often, when on the console, I’ll want to share a link with someone but I’ll be restricted by the atrocious lack of copy/paste. To solve the issue while using elinks, I enabled the link-external-command and tab-external-command options to save the highlighted link and current link, respectively, to a file.

To enable it, first go into the keybinding manager, toggle the display, and choose a keybinding for ‘main -> link-external-command’. This will be the keybinding you will press when you want to save the highlighted URL to a file. Likewise, choose a keybinding for ‘main -> tab-external-command.’ This is the keybinding you will press when you want to save the URL of the current tab to a file. After setting those shortcuts, go to ‘Option manager -> Document -> URI passing’ and create an entry with the contents ‘echo -n %c > ~/url’ (modify as you see fit). From now on, when you use (link|tab)-external-command the URL will be saved in ~/url.

For my inspiration, have a look at .

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.

Managing your wireless connection with Wireless Tools for Linux

A lot of distributions offer their own wireless management tools.  While this can be helpful for a new user, an experienced GNU/Linux user knows that all these tools rely on the generic wireless extension offered by Wireless Tools for Linux.
Today I will show you how to manage your wireless connection by using a subset of the Wireless Tools (iwconfig, iwlist, and ifrename).

Note: I do not use wpa_supplicant.

Some required settings.

You need CONFIG_NET_RADIO=y in your kernel config (it creates /proc/net/wireless).  Also, your results from this tutorial will improve with Wireless Tools version 27 and above.  Use iwconfig –version to determine your version.

Make your interface consistent with ifrename.

ifrename allows you to assign a consistent name to each of your network interfaces.  Normally, interface names are dynamic, meaning that each interface is assigned a name on a first detected, first assigned basis.  Because each interface has some static elements, you can apply naming rules on them to provide a consistent name regardless of when the interface was detected.

Of course, you need to ascertain some information from each device before applying rules to them.  The file to edit is /etc/iftab.

Entries in /etc/iftab consist of a set of mappings: interface name and descriptors.  I find it easier to match devices based on their drivers.  Example entries can be found in `man iftab`.  I use:

b44 driver b44
iwl driver iwl3945

After you have finished editing /etc/iftab, add ifrename to your boot up scripts to automatically rename your devices.  You’ll need to make sure that the command is issued before the devices are brought up.  Use `ifrename -V -D` to see what would happen if you actually issued the command.

Managing the network.

iwconfig iwlist are your tools.

The first thing you usually do is search for available networks.  `iwlist scanning` will show all the available networks.

Once you find a network, connect to it with iwconfig.  iwconfig is your tool for configuring the wireless interface; it is normally used to connect to a network.  Usage is simple, usually in the form: iwconfig <interface> <option> <parameters>.  Typically you’ll be using the following:

iwconfig <interface> essid <ESSID>

iwconfig <interface> key <KEY>

That’s all there is too it.  You can view your current authentication settings with `iwlist auth`.

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.

My Desktop – The Web

We all spend a lot of time browsing the web.  The only thing that makes us different is how we interact with the web, whether it be through our choice of web browser or frequented websites.

AJ\'s Workspace (2008-06-25)

When browsing the web, Firefox 3 is my first choice because of its vast number of extensions and themes.

On the bottom right of the Firefox window you can see various icons representing my extensions:

In order from left to right: Vimperator, Firebug, Greasemonkey, NoSquint, and NoScript.

Vimperator: allows me to use Vim’s keyboard mappings in Firefox.  Sounds insane?  For me, it completely removes the need for the mouse.  Need to go home, no problem just type “gh”.  Need to get to the top of the page, just type “gg”.  Need to quickly select a link: type “f” which turns on HINTS and press the corresponding number.  One bad thing is that it does not take advantage of the awesome bar so I use Alt-D to access it instead.  In addition to changing the keyboard bindings, it can remove the menu, bookmarks, or tab bar by changing the guioptions (:set go={m,b,T}).

Firebug: In my spare time I tinker with HTML and CSS.  Firebug enables me to easily view the relationship between elements of the page and the corresponding HTML/CSS/XHTML.  Great for debugging those problematic webpages.

Greasemonkey: The holy grail of extensibility.  Whereas Firefox extensions allow you to customise Firefox, Greasemonkey allows you to customize every aspect of a webpage.  In the screenshot I am using the Google Reader – Colourful List View script that applies a different colour to each feed; it is very handy when you have a lot of feeds.

NoSquint: Although Firefox 3 remembers the zoom level for individual pages, I prefer NoSquint’s incarnation of the feature.

NoScript – Speeds up browsing by disabling scripts (both embedded and external) on webpages unless you explicitly enable them.

This basically surmises my browsing extensions.

I’ve been keeping my eye on the Flock browser: it syndicates all of your online activity into one central interface.  It will destroy my productivity, however.