Alpine on Mac OS X

Paul Heinlein

Initial publication: February 4, 2005
Most recent revision: July 27, 2011

Notes on building and running alpine under Mac OS X.


Table of Contents

Introduction
Compiling
OpenSSL Certificates
LDAP and TLS/SSL in 10.5
Running in Terminal
Wide Glyphs in 10.4
Helper Applications
Opening URLs
Opening attachments
Printing

Introduction

Several years ago, my main workstation at work became a PowerBook G4 running Mac OS X. I tried using the included Mail.app, but I missed the flexibility of Pine, my favorite mail client. So I set to compiling and installing it on my laptop. It wasn’t initially obvious how to work around the Mac-isms, but so far I’ve been able to get most things to work as well as they do on my Linux boxes.

Since then, I've migrated from Pine to Alpine, its successor. At least one Pine developer has said that it’s not too much of a stretch to say that Alpine 1.0 could be considered Pine 5.0. In a standard terminal window, Alpine looks and acts pretty much like Pine, but under the hood there have been some substantial code revisions. Among other things, Alpine works and plays pretty well with UTF-8 (aka Unicode) characters and typefaces. Also, the license has been altered, making it likely that people will be able to distribute patched binary versions of Alpine—something not permitted under Pine’s license.

I should note that I don’t store any mail locally; my inboxes and folders are all on remote IMAP hosts. I assume that a local mail store on a Mac will work as expected, but I don’t have any experience with it.

(A reader has very kindly translated this document into Belorussian, Альпійскія на Mac OS X.)

Compiling

Pine had a idiosyncratic build process, but with Alpine the UW development team has begun to use the GNU autoconf system. The migration isn’t complete—too many legacy operating environments supported by the c-client code can’t use it—but the developers have hinted strongly that they’ll be dropping support for many older environments in the near future. The upshot is that while Alpine builds using the standard configure script, there’s still several old Pine build scripts under the hood.

I build Alpine with Eduard Chappa’s paragraph-justification patch. It’s certainly not a requirement, though I find that it eases the task of replying to messages that contain multiple levels of quoting.

To build Alpine on OS X, you’ll need to install the Xcode package. My hunch is that anyone interested in using a command-line mail client on the Mac has already done that, but stranger things have happened.

Alpine compiles fine on OS X 10.4 (Tiger), 10.5 (Leopard), and 10.6 (Snow Leopard) with the latest Xcode releases. The alpine binary produced by the procedure below is capable of both LDAP and SSL without any special instructions.

#!/bin/sh

# season to taste
VER="alpine-2.00"

# create a build directory, but save source files if they exist
BLDDIR=/var/tmp/${VER}-build
test -d $BLDDIR || mkdir $BLDDIR
test -d ${BLDDIR}/${VER} && /bin/rm -rf ${BLDDIR}/${VER}
cd $BLDDIR

# fetch and unpack the source
curl -C - \
  -O ftp://ftp.cac.washington.edu/alpine/${VER}.tar.gz
curl -C - \
  -O http://staff.washington.edu/chappa/alpine/patches/${VER}/fillpara.patch.gz
tar xzf ${VER}.tar.gz
gzip -dc fillpara.patch.gz | patch -p0
cd ${VER}

# configure and build
./configure --prefix=/usr/local
make

# install alpine (optional)
sudo make install

OpenSSL Certificates

If you’re connecting to your mail server using a secure SSL or TLS session, you will likely encounter Alpine’s dreaded SSL/TLS Certificate Validation Failure warning:

There was a failure validating the SSL/TLS certificate for the server

                                mail.blah.com

The reason for the failure was

                unable to get local issuer certificate (details)

You will see this message even if your server has a certificate signed by a well known Certificate Authority (CA) like VeriSign or Thawte.

OS X ships with a full OpenSSL installation and it ships with public certificates from recognized CAs. The problem is that Unix applications compiled against the OpenSSL libraries (like Alpine) cannot make use of those certificates. You’ll need to export them from the system keychain in order to make them available to Alpine.

  1. Open the Keychain Access application and choose the System Roots keychain. Select the Certificates category and you should see 100 or more certificates listed in the main panel of the window.

  2. Click your mouse on any of those certificate entries and then select them all with EditSelect All (Cmd+A).

  3. Once the certificates are all highlighted, export them to a file: FileExport Items…. Use cert as the filename and make sure Privacy Enhanced Mail (.pem) has been chosen as the file format.

  4. Copy the newly created cert.pem into the /System/Library/OpenSSL directory.

  5. Relaunch Alpine.

If your remote mail server has a certificate signed by a Certificate Authority recognized by Apple, you'll no longer get any warnings about untrusted certificates.

If your mail server’s certificate is self-signed, retrieve the remote certificate and add it to the end of your cert.pem file.

LDAP and TLS/SSL in 10.5

I regularly use an LDAP directory for looking up e-mail addresses, but that directory requires that I connect using TLS or SSL. The LDAP libraries in 10.5, however, require a couple configuration settings be added to /etc/openldap/ldap.conf before secure directory connections can be made from within Alpine:

TLS_CACERT              /System/Library/OpenSSL/cert.pem
TLS_CACERTDIR           /System/Library/OpenSSL/certs

See the ldap.conf(5) man page for details about these directives.

Running in Terminal

I’ve tried running Alpine both in the standard Terminal utility and in the xterm provided by X11 for Mac OS X (aka XDarwin). It works in either environment, but I prefer the Terminal because it’s got better cut-and-paste support and it seems to handle character-set issues better.

I use a larger font for mail than I do for regular Terminal sessions. For me, 12 or 13 pt. Monaco works well, and it looks even better with anti-aliasing turned on.

In 10.4, you can access the anti-aliasing check box by navigating to TerminalWindow Settings…DisplayAnti-aliasing.

The Terminal that ships with 10.5 has several different presets, each with its own colors and fonts. To activate anti-aliasing, go to the checkbox: TerminalPreferencesSettingsAntialias text. In 10.5, you’ll need to repeat that step for each setting you use regularly.

Wide Glyphs in 10.4

Alpine can take advantage of Terminal’s default UTF-8 display character set, but in 10.4 it requires one adjustment to display wide glyphs (typically used in oriental character sets) in the proper width.

Bring into focus the Terminal shell in which you’ll be runnning alpine and then check TerminalWindow Settings…DisplayWide glyphs for Japanese/Chinese/etc.. Leave unchecked, however, the setting for Wide glyphs count as 2 columns.

This adjustment is not necessary in 10.5 or 10.6.

Helper Applications

Mac OS X makes it easy to launch helper applications for viewing URLs embedded in messages or attached files like images, PDF files, MS Word docs, or whatever. The secret lies in the open utility, which knows all about which applications you prefer for which MIME types.

Opening URLs

Two settings need to be tweaked if you want to be able to view URLs embedded in messages sent to you. First, you need to enable enable-msg-view-urls option. Second, tell the url-viewers option about open:

url-viewers="/usr/bin/open _URL_"

Note that the quotation marks are necessary to preserve the whitespace.

That’s it! If someone sends you something with some text that even vaguely resembles a URL, it’ll appear in bold within your Terminal. Use the up or down arrows to highlight it, then press the Enter key. Your default web browser will appear and begin loading the page.

Opening attachments

Alpine relies on the system mailcap to associate any given MIME type with the application used to execute it. The Darwin build Alpine doesn’t include a default search path for mailcap, and OS X doesn’t include one anyway. Overcoming all this is pretty simple.

  1. Modify .pinerc so that it knows how to find your mailcap:

    mailcap-search-path=~/.mailcap
    
  2. Create a simple ~/.mailcap file that essentially relies on open and LaunchServices for all its MIME savvy:

    application/PDF; /usr/bin/open -a /Applications/Preview.app %s
    application/*; /usr/bin/open %s
    audio/*; /usr/bin/open %s
    image/*; /usr/bin/open %s
    text/*; /usr/bin/open %s
    video/*; /usr/bin/open %s
    

    I had to add the entry for PDFs around the time of the 10.4.8 update. For some reason, PDF files became associated with the ColorSync application rather than Preview.

That does it. Alpine is now able to launch attachments without any trouble.

Printing

Wisely, Apple’s software developers tied command-line printing into the larger print system, so lpr and its ilk work as expected. Printing from Alpine is therefore just a matter of getting the output formatted according to your tastes and piped off the lpr. Personally, I like the e-mail formatting provided by enscript, which is included with Darwin.

printer=enscript [] enscript -Email -G -j --margins=36:36:36:36

The one potential pitfall of this recipe is that it will only send output to your default printer. If you want to send mail to a different printer, then you’ll have to change your default printer before printing from Alpine, or you’ll have to set up a separate definition for each potential printer using enscript’s -P option.

This article is licensed under a Creative Commons License.

Return to Technical Writings

Home - Tech - Praise - Paul - Books - About

printer-friendly layout