Troubleshooters.Com®, Linux Library
and Alpine: The Simple Email Client Present:

Viewing IMAP With Alpine

CONTENTS:

Introduction

In some ways, Alpine is the ideal window into an IMAP account. Alpine has no caching, so online synchronization is instantaneous. For comparision, "import" a large IMAP account into Thunderbird. It could take hours, days, or simply stall. Another no-caching advantage is that what you see in Alpine is almost certainly what exists in your IMAP folder. Alpine is an outstanding IMAP diagnostic tool, and also an excellent backup email client for when your daily driver email client gets borked, by something you did, or more likely by a new "feature" the client's project's developers felt was just so necessary.

All the action happens in your ~/.pinerc config file. When you use Alpine's config facilities, the result is changes to ~/.pinerc. You can accomplish the same thing, with an editor, by making the same changes directly in ~/.pinerc. When directly editing ~/.pinerc, exit all instances of Alpine. After exiting all Alpine instances, be sure to refresh the ~/.pinerc in your editor, so your changes won't override the last changes made by Alpine itself.

In my opinion, Alpine's facility for "importing" folders (really just looking into them on the IMAP server) have such ambiguous error messages that you're better off simply editing ~/.pinerc manually for this purpose. However, even that isn't without its difficulties, as ~/.pinerc is space-aware. I suggest you import one folder, and then when you have that complete and working, import and debug the next. One you have a few under your belt, you'll understand. Later in this document you'll see a shellscript that can do most of the work in mass-importing folders from a Dovecot IMAP Maildir that uses dots to separate subfolders.

Alpine User Interface

The first two things you do in Alpine is to type alpine at the command prompt, and then type in the account's IMAP password. If you fail to type the correct password when prompted for it (for instance, by pressing Enter), Alpine will go through a time consuming mumbo jumbo you cannot abort or shorten, so be looking for that password prompt, and type the password correctly.

If you're not prompted for a password, the probably reason is you don't have an IMAP account set up yet.

Either way, you arrive at the main menu, which gives you choices of HELP, COMPOSE MESSAGE, MESSAGE INDEX, FOLDER LIST, ADDRESS BOOK, SETUP and QUIT. You can choose one by moving the highlight to it and pressing the Enter key, or by pressing the letter (uppercase or lowercase) to the left of the choice. QUIT enables you to leave the program. SETUP enables you to access a secondary menu letting you pick the kinds of setup activities you can perform.

From the main menu, the selection I choose the most is L, FOLDER LIST. Then you're presented with a list of folders, which you can navigate with the arrow keys and PgUp and PgDown. Folders with new or unread messages have numbers after them. Go to a folder with such a number and press Enter. You'll be brought to a message list, with the highlight on the oldest New message. New messages are identified by an N before the email number. To read a message, press the Enter key to read the message. If you know it should be deleted, press the d key, after which a D replaces the N and the highlight moves down one.

Within an email, you can go down with the PgDn key or the spacebar, or the down arrow for short moves down. When using the down arrow, web URLs become highlighted so you can run a browser on them by pressing the Enter key. However, Alpine must be adequately configured to run the browser, and run it correctly.

Alpine is built as a menu selection hierarchy. In most cases, the Less Than key (<) brings you to the next higher level, and the Greater Than Key (>) tends to bring you down to the last place you were in at the level below current. Beyond that, just look at all the prompts on the screen.

Adding Folders to the Incoming List

If you're only adding five or six folders, from the main menu go to SETUP and then to FOLDER LIST and then A for ADD, and put in the right stuff. Make sure the highlight is either on a folder in the folder list, or if none, just below the heading saying "Folder-Collection <Incoming Folders>. That's the only way you'll get Alpine to query for your server. Then just press the A key to ADD.

You'll first be asked for the "Name of server to contain folder". The following is the correct entry for my setup, where my Maildir-based ssl enabled Dovecot server is located on my desktop at 192.168.100.2:

192.168.100.2/ssl/user=slitt

Then it asks for the folder name, and I put a name I know is a folder on the Dovecot server. For instance, perhaps "garbage". Note that what I type in must be an exact match for what's on the Dovecot server. Case counts. Finally it asks me for a nickname, and although I could write anything, I once again write "garbage". I'm done!

But my Dovecot server has over 300 folders, so I'd be several days doing that job. No problem at all. Here's a shellscript, called list_alpine_import_folders.sh to do it:

#!/bin/sh

# CHANGE FOLLOWING LINE TO REFLECT YOUR IMAP FOLDER LOCATION:
mymaildir=$HOME/mail/Maildir

cd $mymaildir
#for f in *; do
ls -1adF .* | xargs --max-lines=1 list_one_alpine_folder.sh | sort -i

You'll notice the preceding shellscript calls list_one_alpine_folder.sh. That shellscript's code follows:

#!/bin/sh
[ "$1" = './' ] && exit 0
[ "$1" = '../' ] && exit 0
myrawdir=`echo $1 | sed -e"s/^\.//"`
myrawdir=`echo $myrawdir | sed -e"s/\/\s*$//"`
mynickname=`echo $myrawdir | sed -e"s/\./\//g"`

myserverstring='{192.168.100.2/ssl/user=slitt}'
mycomma=','
myoutput="\t$mynickname $myserverstring$myrawdir$mycomma"
echo $myoutput

Basically, the list_one_alpine_folder.sh takes an input line like the following:

pygroup.2014

and outputs the following:

	pygroup/2014 {192.168.100.2/ssl/user=slitt}pygroup.2014,

The preceding output line is exactly what you'd put in the incoming-folders= section of ~/.pinerc.

Well Excuuuuuuse -- Me!

Yeah, the preceding shellscripts are barbaric, they're throwaway code, they're not canonical use of commands, and list_alpine_import_folders.sh takes between 2 and 30 seconds depending on how many folders and the power of the computer. But they work.

If you find the preceding shellscripts offensive, inconvenient or too slow, it's easy to replace them with a Python or C program.

Make Your Work File

A cool advantage of Alpine is that you can sort your folders any way you want. This helps make up for the fact that you can't expand and collapse subfolders. So you want to do all your sorting and rearranging in a work file, not in ~/.pinerc itself. Perform the following command:

list_alpine_import_folders.sh > ~/workfile.jnk

Now, edit ~/workfile.jnk and sort as desired. It's a good idea to keep subfolder trees together and the most used folders toward the top.

Add Folders to the Config File

Before continuing, exit all instances of Alpine. You want to edit your .pinerc free of changes made by Alpine.

The definition of what folders appear in Alpine, and in what order, is totally controlled by the incoming-folders= variable inside the ~/.pinerc file. The following is a short example of how the folder list is defined within ~/.pinerc:

incoming-folders=claws {192.168.100.2/ssl/user=slitt}claws,
	dabo {192.168.100.2/ssl/user=slitt}dabo,
	garbage {192.168.100.2/ssl/user=slitt}garbage,
	junk {192.168.100.2/ssl/user=slitt}junk,
	junk/steve {192.168.100.2/ssl/user=slitt}junk.steve,
	litttest {192.168.100.2/ssl/user=slitt}litttest,
	Trilug {192.168.100.2/ssl/user=slitt}TriLUG,

The incoming-folders= list has some very strict rules of the road. The following is an enumeration of those rules, and please remember this list applies specifically to the incoming-folders= variable; not necessarily to the file as a whole:

Once you've properly copied the folder lines to the incoming-folders= list, save ~/.pinerc, exit the editor, and run Alpine. If everything's gone well, you should now see all your folders and be able to browse the messages in each.

Troubleshooting Alpine