Alpine on Mac OS X

Notes on building and running alpine under Mac OS X.

Paul Heinlein
First published on February 4, 2005
Last updated on August 21, 2017

Contents

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 all of Eduard Chappa’s enhancement patches. Doing so is certainly not a requirement, though I find that many tasks become much easier with them applied.

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.

The latest versions of Alpine require OpenSSL version 1.0.0c or higher. macOS 10.12 still ships with version 0.9.8, so you’ll have to link Alpine against a third-party OpenSSL installation. I use MacPorts, but a lot of people use Homebrew. The script below assumes a MacPorts version of OpenSSL, but it’d be easy to modify for Homebrew.

#!/bin/sh

# season to taste
VER="alpine-2.21"

# where does alpine live these days
SRCSITE="http://alpine.freeiz.com/alpine"

# use macports, esp. for openssl, since alpine now requires
# a version greater than 1.0
export PATH="/opt/local/bin:/opt/local/sbin:${PATH}"

# 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 ${SRCSITE}/release/src/${VER}.tar.xz
curl -C - -O ${SRCSITE}/patches/${VER}/all.patch.gz
xz -dc ${VER}.tar.xz | tar -x -f -
gzip -dc all.patch.gz | patch -p0
cd ${VER}

# configure and build
CPPFLAGS="-I/opt/local/include -I/opt/local/include/openssl" \
LDFLAGS="-L/opt/local/lib -lintl" \
./configure \
  --prefix=/usr/local \
  --without-tcl
make

echo
echo "when you're ready for installation, run"
echo "  sudo make -C ${BLDDIR}/${VER} install"
echo
exit

# eof

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.

Since this version of Alpine is linked against a non-system OpenSSL installation, you’ll have to figure out where it keeps its store of recognized CAs. For MacPorts, the file is off in /opt/local:

You’ll need to add the certificate(s) you want to that file manually:

cat /path/to/your/ca.crt >> /opt/local/share/curl/curl-ca-bundle.crt

Then relaunch Alpine.

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 Terminal -> Window Settings… -> Display -> Anti-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: Terminal Preferences Settings Antialias 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 Terminal -> Window Settings… -> Display -> Wide 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.

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

mailcap-search-path=~/.mailcap

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.