OfflineIMAP

From ArchWiki

Jump to: navigation, search

OfflineIMAP is an utility to retrieve mail from IMAP servers. It does not work with the POP3 protocol or mbox, and is usually paired with a MUA such as Mutt.

Contents

Installing

Install the offlineimap package with pacman:

# pacman -S offlineimap

Configuring

Copy the example ~/.offlineimaprc provided by the package and edit it with your favorite editor:

$ cp /usr/share/offlineimap/offlineimap.conf ~/.offlineimaprc
$ $EDITOR ~/.offlineimaprc

Edit the sample configuration as desired, but take care that comments are placed on their own separate line, since placing a comment after an option/value on the same line will cause errors. A condensed version follows:

File: ~/.offlineimaprc
[general]
# Change to whatever you want:
accounts = myaccount

# The default Curses.Blinkenlights is bugged and will cause the terminal
# to lock up after OfflineIMAP exits, so change it:
ui = TTY.TTYUI

# If uncommented, this would show nothing at all. Great for cronjobs or
# background-processes:
# ui = Noninteractive.Quiet 

[Account myaccount]
# Profile-Name for the local Mails for a given Account:
localrepository = mylocal

# Profile-Name for the remote Mails for a given Account:
remoterepository = myremote

# Fetches your mails every 5 Minutes:
autorefresh = 5

[Repository mylocal]
# Way of storing Mails locally. Only Maildir is currently supported:
type = Maildir

# Place where the synced Mails should be:
localfolders = ~/Mail

[Repository myremote]
# Type of remote Mailbox. Only IMAP is supported right now:
type = IMAP

# Where to connect:
remotehost = imap.myhost.com

# Whether to use SSL or not:
ssl = yes

# Would specify a port if uncommented. This way, it just tries to use a
# default-port:
# remoteport = 993

# Specify login-name:
remoteuser = myremoteusername

# Specify login-password (there are other/safer options for storing
# passwords for use by OfflineIMAP, see the OfflineIMAP manual. Make
# sure that ~/.offlineimaprc is readable only by you, if you  specify
# your password here!):
remotepass = myremotepassword

This is a minimal setup to get you going. For more advanced features, consult the OfflineIMAP Homepage and check the annotated offlineimaprc, which is also placed by the package at /usr/share/offlineimap.

Usage

You are now almost ready to run the program. Create the directory you have defined in the offlineimaprc:

$ mkdir ~/Mail

Then run OfflineIMAP:

$ offlineimap

Your mails will now be synced. If anything goes wrong, take a closer look at the error messages. OfflineIMAP is usually very verbose about problems.

Miscellaneous

Various settings and improvements

Gmail configuration

This offlinemaprc is modified specifically for Gmail support, substituting folder names in uppercase for lowercase, among other small additions. Keep in mind that this configuration does not sync the All Mail folder, since it is usually unnecessary and skipping it prevents bandwidth costs:

File: ~/.offlineimaprc
# Main configuration
[general]
metadata = ~/.dat/offlineimap
accounts = acc1
maxsyncaccounts = 1
ui = TTY.TTYUI, Noninteractive.Basic, Noninteractive.Quiet
ignore-readonly = no

[mbnames]
enabled = yes
filename = ~/.cfg/mutt/mailboxes
header = "mailboxes "
peritem = "+%(foldername)s"
sep = " "
footer = "\n"

[ui.Curses.Blinkenlights]
statuschar = .

# Accounts
[Account acc1]
localrepository = acc1_local
remoterepository = acc1_remote

# Local repositories
[Repository acc1_local]
type = Maildir
localfolders = ~/mail
subscribedonly = no
sep = /
restoreatime = no

# External repositories
[Repository acc1_remote]
type = Gmail
remoteuser = user@gmail.com
remotepass = password
realdelete = no
nametrans = lambda foldername: re.sub ('^\[gmail\]', 'bak',
                               re.sub ('sent_mail', 'sent',
                               re.sub ('starred', 'flagged',
                               re.sub (' ', '_', foldername.lower()))))
folderfilter = lambda foldername: foldername in ['INBOX', '[Gmail]/Sent Mail',
                                                 '[Gmail]/Drafts', '[Gmail]/Spam',
                                                 '[Gmail]/Starred', '[Gmail]/Trash']

Troubleshooting

Curses interface (Curses.Blinkenlights) locks terminal

This UI is currently defective and the bug is already widely-known at the OfflineIMAP bug tracker. While it appears to irreparably lock the terminal, in reality it only prevents commands from being displayed.

In order to solve the issue:

  • either append reset to OfflineIMAP's launch command:
$ offlineimap; reset
  • or change the UI to a fully functional one, as previously suggested in the article:
ui = TTY.TTYUI
Personal tools