Mutt: Viewing Attachments / HTML via .mailcap and a Custom Fortune as a Signature in Mutt

It’s funny how small, trivial things can lead you to make radical changes in the tools you use. As regular readers of this blog know, I collect sayings that I publish every month. I then compile these sayings into a custom fortune file that displays one saying every time I login to my computer or open a new terminal window/shell process.

I recently learned that I can call this custom fortune file as a signature and have one added automatically to every email I write by adding this line to my .muttrc configuration file.

set signature="fortune /usr/share/games/fortunes/cafebedouin -s|"

This is simply calling the fortune program, specifying the location of the file and the -s flag is telling fortune to find a small quote to add. This is a completely trivial feature, but I love it. It is what provided the motivation to actually get mutt to work as my main email client.

My main problem with mutt has been that I couldn’t figure out how to get it to render HTML emails in a readable format, which makes mutt a poor choice as an everyday email client. Half of the emails I receive are in HTML format. The problem, it turns out, is that my email provider encrypts all my email, so I needed an additional line in .mailcap that processes the pgp/mime format, like so:

text/plain; cat %s; copiousoutput
text/html; mkdir -p /tmp/mutt \; cp %s /tmp/mutt \; firefox /tmp/mutt/$(basename %s) &
text/html; lynx -nonumbers -dump %s; copiousoutput; nametemplate=%s.html 
pgp/mime; lynx -dump %s; copiousoutput; nametemplate=%s.html

This points to something I didn’t understand. .mailcap is basically how you tell mutt to process email attachments, and you simply associate file types with programs on your system. There’s also default behavior, where the text/html with copiousoutput will be used when you hit enter by default and when you go to view the attachment, mutt will call the first relevant line in mailcap, as mentioned here.. The same idea applies to other file types, such as images.

image/*; mkdir -p /tmp/mutt \; cp %s /tmp/mutt \; xdg-open /tmp/mutt/$(basename %s) &

So, once the change above is made, you then need to change this line in .muttrc:

alternative_order text/html text/plain text/enriched text multipart/alternative 
auto_view text/html

# Removes temporary attachment files
folder-hook . `rm -f /tmp/mutt/*`

And now, it works beautifully. I’ve completely stopped using thunderbird, and I only use mutt. And, it has improved my email experience so much. I receive something like 50-100 emails a day, most of them newsletters or promotional material from organizations I signed up to hear more about. But, mutt makes it so easy to navigate and delete email.

Since making the transition, my inbox – which I had always relatively good control over and rarely had more than a day’s worth of email in – is down to a couple of leftover emails per day. I read what I want and delete them. I highly recommend making the transition.

Newsboat

Newsboat is the Mutt of RSS readers. Works and looks pretty much the same as mutt. In making the conversion, I learned that I have over 500 RSS feeds, which in combination with a few dozen newsletters via email is how I discover the material to post to this blog.

I used to use an app on my phone to scroll through when I had time, but I found using Newsboat sped up the process considerably. So, even though I have to sit down at the computer and go through each feed, Newsboat will be my default method moving forward. Recommended.

bash: Cryptocurrency Prices From the Linux Terminal

#!/bin/bash
printf -v coin '%s' -1   # crypto.sh bitcoin

price() {
  # A function that pulls cryptocurrency price data from coingecko
    
  curl -X 'GET' 'https://api.coingecko.com/api/v3/simple/price?ids='"$1"'&vs_currencies=usd' \
     -H 'accept: application/json' 2> /dev/null | # sends download data to /dev/null
      
  sed  's/.*usd"://' |   # Removes everything before the price
  sed 's/..$//' |        # Removes back two }}
  sed 's/^/\$/'          # Adds dollar sign to the front, returns
}

bitcoin=$(price bitcoin)
ethereum=$(price ethereum)

# Checks to see if there is a command line variable and prints to console
if [[ -z $1 ]]; then
    echo "bitcoin: ${bitcoin} | ethereum: ${ethereum}"
else
    price=$(price $1) # calls function with command line variable
    echo "${1}: ${price} | bitcoin: ${bitcoin} | ethereum: ${ethereum}"
fi

h/t Techstructive for the basic idea. I simplified their code by cutting out the I/O and putting the coin as a variable when calling the script, e.g. crypto.sh bitcoin, and formatting it by piping it through sed. Have I mentioned how much I love sed?

Edit: Modified this on August 12, 2021 so it is now a function and prints a portfolio of coins. I track two or three, and it was getting annoying to have to do them each individually. All you need to do to modify it for the coins you are interested in is create a new function call:

cardano=$(price cardano)

Then add that to both the if and else print results.

    echo "${1}: ${price} | bitcoin: ${bitcoin} | ethereum: ${ethereum} | cardano: ${cardano}"

An Introduction To Data Science On The Linux Command Line

…provide[s] the reader with a brief overview for a number of different Linux commands. A special emphasis will be placed on explaining how each command can be used in the context of performing data science tasks. The goal will be to convince the reader that each of these commands can be extremely useful, and to allow them to understand what role each command can play when manipulating or analyzing data.”

-Robert Elder, “An Introduction To Data Science On The Linux Command Line.” RobertElder.org. October 16, 2019.