Archive

Posts Tagged ‘mutt’

Fixing mailto-mutt in Linux Mint Maya

November 6th, 2012 subogero Comments off

I tried Linux Mint Maya KDE over the weekend in a virtual machine. It came after a brief tour of the Xfce edition. The latter does not really let me set a small and tasty window title bar without editing pixmaps of the window decoration. KDE in general is extremely configurable, apart from the size and colour of the… yes, the window decoration theme. But it left a good impression. Except that some KDE apps look so cluttered and tasteless compared to their Gnome2 counterparts. Step forward Ktorrent.

Switching back to the real machine’s MATE was such a relief. So I decided to debug my main niggle with this half-baked DE: the disfunctional “Email Link…” in Firefox, which just brings up Mutt in normal mode, instead of composing a new mail in it. Same for clicking mailto links anywhere.

First configure Firefox mailto: handling. Edit, Preferences, Applications, mailto. “Mutt (default)” does not work as intended. So I set it to the recommended /usr/lib/mutt/mailto-mutt which is just a wrapper to start mutt in a new terminal:

exec x-terminal-emulator -e mutt "$@"

It did not work either. I just checked, x-terminal-emulator is just a symlink to a symlink to /usr/bin/mate-terminal.

Next step: check whether Firefox really sends the mailto parameters to mailto-mutt. So I replaced it with a one-liner to copy the argument list into a log file.

echo "$@" > ~/mailto.log

That worked fine, the proper mailto URI was copied to the log file.

So it must be either the mate-terminal or the mutt invocation. I tried it manually without a new terminal first:

mutt `cat mailto.log`

Everything fine, mutt starts in email-compose mode. So it’s the mate-terminal, then:

mate-terminal -e mutt `cat mailto.log`

There you go! The mailto URI from the log file was now ignored. It turns out the -e option ignores the rest of the command line, it just takes one argument. Should have used -x instead, or quote the whole thing. Not that mate-terminal has a manual page. I looked it up in that of gnome-terminal on Ubuntu 10.04. Anyway, here it is:

mate-terminal -e "mutt `cat mailto.log`"

works fine. So the fix to mailto-mutt is this, watch the opening quote:

exec x-terminal-emulator -e "mutt $@"

Then, even though I don’t believe society exists at all, I tried to do the civil thing towards the so-called community and tracked down the origins of the bug.

/usr/lib/mutt/mailto-mutt is part of the mutt package, version 1.5.21-5ubuntu2.
The original Debian package 1.5.21-5 has an identical mailto-mutt.

The only Debian bug about mailto-mutt is #576313 which contains an interesting observation:

On top of that, mailto-mutt doesn't handle body specifications properly.
  /usr/lib/mutt/mailto-mutt 'mailto:test?body=test'
doesn't do anything, but
  mutt 'mailto:test?body=test'
works just fine.

The “upstream tarball” (mutt-1.5.21.orig.tar.gz) contains no mailto-mutt whatsoever. So it’s a Debian bug. I emailed the maintainer about the bug and the fix.

It seems few people have time to fix real usability bugs in these chaotic years of the Linux desktop. And why? Because the brilliant GNOME Usability people decided to discontinue Gnome 2, the best desktop environment ever. It’s so incredible that it hurts.

Mutt aka Bash Is Still King

December 5th, 2011 subogero 4 comments

I’ve had problems with sending emails from the command line before. On Windows. That’s how mapis was born. This time it’s the same story on Linux. I want to send an email from the command line with an attachment. The rather lovely Evolution does not support it.

In comes mutt, the even more lovely terminal based email client. But I don’t want to loose features:

  • Gmail IMAP access
  • integration with my Gmail contacts
  • Hungarian spell-check
  • mutt as my default mail client in Gnome, so Firefox uses it when Sending Link…

And while I’m at it, I want some new features as well:

  • editing email with vim (with Hungarian spell-check, obviously)
  • bonus: email desktop notifications, even when the client is not running

Installation

apt-get install mutt  # as root

My ~/.muttrc config file:

set from = "your@email"
set realname = "Your Name"
set imap_user = "your@email"
set imap_pass = "yourpassword"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed = "+[Gmail],Drafts"
set trash = "imaps://imap.gmail.com/[Gmail]/Trash"
set header_cache = ~/.mutt/cache/headers
set message_cachedir = ~/.mutt/cache/bodies
set certificate_file = ~/.mutt/certificates
set smtp_url = "smtp://your@email:587/"
set smtp_pass = "your_password"
set editor  = "vi"
set query_command = "goobook query '%s'"
set sort = "threads"
set sort_aux = "last-date-received"

color normal white default
color index white default ~p
color index white default ~P
color index white default ~O
color index brightwhite default ~N
color tree red default
color hdrdefault cyan default
color quoted green default
color tilde white default
color signature blue default
color attachment brightyellow default
color status brightwhite green
color indicator black white

You’ve probably noticed vi as the editor, some options that don’t let you miss new posts to old email threads and a colour scheme that fits well into Linux Mint. Also goobook is mentioned, which can access your Gmail  contacts from the command line. Homework: find the goobook website on the internet! Then download and extract the source tarball, run

sudo ./setup.py install

Then create its config file ~/.goobookrc

[DEFAULT]
email: your@email
password: your_password

As the above config files store your password, don’t forget to change their permissions:

chmod 700 ~/.muttrc ~/.goobookrc

As to the Hungarian spell-check in vi, add a line to ~/.vimrc which maps it to <F7>, like some office tools:

map <F7> :setlocal spell spelllang=hu<Enter>

The first time you activate it, it will download the Hungarian database, then highlight the misspelled words with red. Move around them with [s and ]s and let vim suggest correct spelling with the z= key combo. It kicks ass indeed.

Mutt as Gnome’s default email client? Main Menu (I don’t use the Mint Menu), System, Preferences, Preferred Applications. Mail Reader. Choose Custom, then specify “/usr/bin/mutt %s” as the command. Run in terminal of course. Test with Send Link… in Firefox.

Now all is well. Just try to send a file attachment from the command line.

mutt -a foo.txt

opens mutt, which in turn asks for the mail recipient. Just type a part of the name or email, hit Ctrl-t, and mutt will complete the email address from your Gmail Contacts. Then enter a subject and voilá, vi opens up to edit the mail body. Edit, spellcheck, ZZ, y. Done.

And now for something completely different. Desktop notifications for new email, even when no email client is running. I’ve found a nice mutt-Gmail tutorial blogpost somewhere, I forget where. It contained a Python script for email notifications. I opened it. I got scared. 200 lines of code! I nearly gave up. But after  taking a courageous look I realized it just parsed the Gmail atom feed and called Gnome’s notify-send. Using a class and using an XML parsing module.

Python is a rather lovely language, but I have to say its adherents are famous for writing bloated code. I bet I can write a 10-line shell script for that. I ended up with 11 lines, but including the shebang and a configurable checking period. It’s among my Gnome Startup Applications:

#!/bin/sh
SLEEP=`echo $1 | egrep '^[1-9][0-9]*$'`
[ -z "$SLEEP" ] && SLEEP=300
USER=`sed -rn 's/^set imap_user = "(.+)"$/\1/p' ~/.muttrc`
PASS=`sed -rn 's/^set imap_pass = "(.+)"$/\1/p' ~/.muttrc`
while true; do
 EMAILS=`curl -u ${USER}:${PASS} https://mail.google.com/mail/feed/atom \
 | sed -rn 's/<name>(.+)<\/name>$/\1/p'`
 [ -n "$EMAILS" ] && notify-send "NEW EMAIL" "$EMAILS"
 sleep $SLEEP
done

Bash is still king.

Categories: Uncategorized Tags: , , , ,