Moving local pine folders to IMAP

This page will tell you how to move your local pine folders that sit under your UNIX home directory (i.e. ~/mail) onto the mail server so they can be seen with other IMAP programs like the webmail program or Outlook and Entourage. It will also tell you how to configure pine to look for its folders on the mail server via IMAP and not use your local home directory space.

After completing the move of your folders, your IMAP clients (e.g. webmail, Outlook) will most likely require you to Subscribe to them before you can see them in their folder list. Read your email client's help files for how to do this. Every client and even every version of Outlook does this differently.

Step 1: Move the folders

For the first step, you must ssh to gate or entry and run the file2imap script on your folder files. You simply give the folders you want to copy to the new server as arguments to the file2imap script. The script then prompts for you password which it needs to connect to the IMAP server and it then copies all the folders you gave it automatically.

There is one important issue to take note of. You must pass the folders as arguments to this script exactly as the folder name should appear in your email client. So if you want the folder 'mri-scan' to be listed on the imap server as just 'mri-scan', you must pass it to the file2imap script as 'mri-scan' and not '~/mri-scan' or '~/mail/mri-scan'. In other words, change directory to the directory that is the top level of your folder structure and then run the file2imap script there.

For those of you who have kept your folders in your '~/mail' subdirectory which is the default for pine, you can most likely can simply run

cd ~/mail
file2imap *

The script will ignore any argument that is a directory and not a file. Also, if you have subdirectories with folders further down in your hierarchy, you will need to add those to the list above explicitly. For example:

cd ~/mail
file2imap * archives/* partners/* lists/*

If you have even a third level, add those too giving the file2imap script the names relative to the toplevel of your folder structure as in the above examples.

For the case where every file in your top folder directory is not actually a folder (or you don't want transfer all your old pine folders), you have to individually give the script each valid folder. An example is:

cd ~/mail
file2imap sent-mail -r Sent mri-scan 'Human Subjects' archive/2004 archive/2005

This example shows a special feature of the script where you can rename the folder on the server to be different than the file name. In this case 'sent-mail' is copied to a folder named 'Sent' on the server using the '-r' option. Also note it is important to put quotes around any folder name with spaces or any non-alphanumeric characters.

If any of the folders you pass to the script already exist on the mail server, the script will report an error and skip it. If you really want to append the contents of the given file folder to an existing folder on the IMAP server, you need to rerun file2imap on those folders with the -a option. For example, if the folder 'subjects' already exists, you can run:

cd ~/mail
file2imap -a subjects

You may also get failures on folders due to Invalid Header or bare newlines. If so, .

Step 2: change your pine settings

To have pine see your IMAP subfolders you need to edit your ~/.pinerc file to change the folder-collections setting. This setting can take multiple comma separated values so you can have pine see both the IMAP folder and your old local folders.

Below is the setting you can use to see both your IMAP and local folders:

folder-collections=Main {${USER}/ssl/novalidate-cert}[],
     Local mail/[]

By default, for folder operations pine will use the first folder collection in this list. When you try to open a folder or save to a folder there is a ^N option to rotate to the next folder collection in the list. So to save a message to a local folder, you press 'S' for save, Ctrl-N to go to the Local collection and then type in the name of the folder.

You probably also want all your Sent email to go to a folder on the IMAP server rather than the sent-mail-* file in the ~/mail subdirectory. To do that use a setting like this:


NOTE #1: When your sent-mail mail folder is on a remote IMAP server like this, pine will no longer rename it at the beginning of each month to something like 'sent-mail-may-2005'. You will need to do such a thing by hand yourself.

NOTE #2: The default for all Martinos center pine installations is to get your INBOX from the mail IMAP server. But if you are using pine on another Linux box (such as at home or on a laptop) and want pine to use the Martinos mail server, you must define the following setting:


Step 3: verify you can see your folders

First, to make sure your old folders are not visible to pine so the test below is accurate, move your mail directory asside:

mv ~/mail ~/mail.SAVE

Run pine and use 'L' to see that all your folders are there. One important thing to keep in mind is in the folder list, pressing ENTER on a folder is different than pressing the ">" key. The difference is the imap server supports folders that are both mail folders and directories with subfolders at the same time. Hitting ENTER on the folders opens that folder as a mail folder. Hitting ">" on the folder navigates down to its subfolders.

Check that your folders are all there and check several of them to see they have the email you expect them to have.

Step 4: remove your old ~/mail.SAVE directory

You might want to keep it around for a while as a backup, but mostly likely you need to remove it for quota reasons

Contact the Webmaster