[http://offlineimap.org/ OfflineIMAP] is an utility to sync mail from IMAP servers. It does not work with the POP3 protocol or mbox, and is usually paired with a MUA such as [[Mutt]].

+

{{Article summary start|Related}}

+

{{Article summary wiki|isync}}

+

{{Article summary wiki|notmuch}}

+

{{Article summary wiki|msmtp}}

+

{{Article summary end}}

+

[http://offlineimap.org/ OfflineIMAP] is a Python utility to sync mail from IMAP servers. It does not work with the POP3 protocol or mbox, and is usually paired with a MUA such as [[Mutt]].

==Installing==

==Installing==

−

Install the {{Pkg|offlineimap}} package with [[pacman]]:

+

−

# pacman -S offlineimap

+

Install {{pkg|offlineimap}} from the [[official repositories]]. For a development version, install {{AUR|offlineimap-git}} from [[AUR]].

==Configuring==

==Configuring==

−

Offlineimap is distributed with two default configuration files, which are both located in {{ic|/usr/share/offlineimap/}}. {{ic|offlineimap.conf}} contains every setting and is thorougly documented. Alternatively, {{ic|offlineimap.conf.minimal}} is is not commented and only contains a small number of settings (see: [[#Minimal|Minimal]]).

+

+

Offlineimap is distributed with two default configuration files, which are both located in {{ic|/usr/share/offlineimap/}}. {{ic|offlineimap.conf}} contains every setting and is thorougly documented. Alternatively, {{ic|offlineimap.conf.minimal}} is not commented and only contains a small number of settings (see: [[#Minimal|Minimal]]).

Copy one of the default configuration files to {{ic|~/.offlineimaprc}}.

Copy one of the default configuration files to {{ic|~/.offlineimaprc}}.

Line 14:

Line 20:

===Minimal===

===Minimal===

+

The following file is a commented version of {{ic|offlineimap.conf.minimal}}.

The following file is a commented version of {{ic|offlineimap.conf.minimal}}.

−

{{hc|~/.offlineimaprc|2=

+

−

<nowiki>

+

{{hc|~/.offlineimaprc|<nowiki>

[general]

[general]

# List of accounts to be synced, separated by a comma.

# List of accounts to be synced, separated by a comma.

Line 40:

Line 47:

remotehost = host.domain.tld

remotehost = host.domain.tld

remoteuser = username

remoteuser = username

−

</nowiki>

+

</nowiki>}}

−

}}

+

==Usage==

==Usage==

+

Before running offlineimap, create any parent directories that were allocated to local repositories:

Before running offlineimap, create any parent directories that were allocated to local repositories:

$ mkdir ~/Maildir

$ mkdir ~/Maildir

Line 50:

Line 57:

$ offlineimap

$ offlineimap

−

Mail accounts will now be synced. If anything goes wrong, take a closer look at the error messages. OfflineIMAP is usually very verbose about problems; partly because the developers didn't bother with taking away tracebacks from the final product.

+

Mail accounts will now be synced. If anything goes wrong, take a closer look at the error messages. OfflineIMAP is usually very verbose about problems; partly because the developers did not bother with taking away tracebacks from the final product.

==Miscellaneous==

==Miscellaneous==

−

''Various settings and improvements''

===Running offlineimap in the background===

===Running offlineimap in the background===

+

Most other mail transfer agents assume that the user will be using the tool as a [[daemon]] by making the program sync periodically by default. In offlineimap, there are a few settings that control backgrounded tasks.

Most other mail transfer agents assume that the user will be using the tool as a [[daemon]] by making the program sync periodically by default. In offlineimap, there are a few settings that control backgrounded tasks.

Confusingly, they are spread thin all-over the configuration file:

Confusingly, they are spread thin all-over the configuration file:

−

{{hc|~/.offlineimaprc|2=

+

−

<nowiki>

+

{{hc|~/.offlineimaprc|<nowiki>

# In the general section

# In the general section

[general]

[general]

Line 79:

Line 86:

# send empty data to the server to hold the connection open. A value of 60

# send empty data to the server to hold the connection open. A value of 60

# attempts to hold the connection for a minute between syncs (both quick and

# attempts to hold the connection for a minute between syncs (both quick and

−

# autorefresh)

+

# autorefresh).This setting has no effect if autorefresh and holdconnectionopen

The wrapper script is needed because offlineimap has the tendency to sporadically crash, even more so when facing connection problems.

+

<span id="Sporadic_Crashes">The wrapper script is needed because offlineimap has the tendency to sporadically crash, even more so when facing connection problems.</span>

===Automatic mutt mailbox generation===

===Automatic mutt mailbox generation===

+

[[Mutt]] cannot be simply pointed to an IMAP or maildir directory and be expected to guess which subdirectories happen to be the mailboxes, yet offlineimap can generate a muttrc fragment containing the mailboxes that it syncs.

[[Mutt]] cannot be simply pointed to an IMAP or maildir directory and be expected to guess which subdirectories happen to be the mailboxes, yet offlineimap can generate a muttrc fragment containing the mailboxes that it syncs.

−

{{hc|~/.offlineimaprc|2=

+

−

<nowiki>

+

{{hc|~/.offlineimaprc|<nowiki>

[mbnames]

[mbnames]

enabled = yes

enabled = yes

Line 156:

Line 189:

sep = " "

sep = " "

footer = "\n"

footer = "\n"

−

</nowiki>

+

</nowiki>}}

−

}}

+

−

Then add {{Ic|source ~/.mutt/mailboxes}} to {{ic|~/.mutt/muttrc}}.

+

Then add the following lines to {{ic|~/.mutt/muttrc}}.

+

+

{{hc|~/.mutt/muttrc|<nowiki>

+

# IMAP: offlineimap

+

set folder = "~/Mail"

+

source ~/.mutt/mailboxes

+

set spoolfile = "+account/INBOX"

+

set record = "+account/Sent\ Items"

+

set postponed = "+account/Drafts"

+

</nowiki>}}

+

+

{{ic|account}} is the name you have given to your IMAP account in {{ic|~/.offlineimaprc}}.

===Gmail configuration===

===Gmail configuration===

+

This remote repository is configured 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:

This remote repository is configured 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:

Note: if you have Gmail set to another language, the folder names may appear translated too, e.g. "verzonden_berichten" instead of "sent_mail".

+

{{Note|

−

+

* If you have Gmail set to another language, the folder names may appear translated too, e.g. "verzonden_berichten" instead of "sent_mail".

−

Note: after version 6.3.5, offlineimap also creates remote folders to match your local ones. Thus you may need a nametrans rule for your local repository too that reverses the effects of this nametrans rule.

+

* After version 6.3.5, offlineimap also creates remote folders to match your local ones. Thus you may need a nametrans rule for your local repository too that reverses the effects of this nametrans rule.

+

* As of 1 October 2012 gmail SSL certificate fingerprint is not always the same. This prevents from using {{ic|cert_fingerprint}} and makes the {{ic|sslcacertfile}} way a better solution for the SSL verification (see [[OfflineIMAP#SSL fingerprint does not match]]).

+

}}

===Not having to enter the password all the time===

===Not having to enter the password all the time===

+

====.netrc====

====.netrc====

+

Add the following lines to your {{ic|~/.netrc}}:

Add the following lines to your {{ic|~/.netrc}}:

−

machine hostname.tld

+

machine hostname.tld

−

login [your username]

+

login [your username]

−

password [your password]

+

password [your password]

−

Don't forget to give the file appropriate rights like 600 or 700:

+

Do not forget to give the file appropriate rights like 600 or 700:

−

chmod 600 ~/.netrc

+

$ chmod 600 ~/.netrc

====Gnome Keyring====

====Gnome Keyring====

+

http://www.clasohm.com/blog/one-entry?entry_id=90957 gives an example of how to use gnome-keyring to store the password.

http://www.clasohm.com/blog/one-entry?entry_id=90957 gives an example of how to use gnome-keyring to store the password.

−

====python-keyring====

+

In the example, functions from a python file are imported in order to get passwords from gnome-keyring.

−

There's a general solution that should work for any keyring. Install [http://pypi.python.org/pypi/keyring python-keyring] from [[AUR]], then change your ~/.offlineimaprc to say something like:

+

−

{{bc|1=

+

Alternatively, if youre using {{AUR|gnome-keyring-query}}, you can use this simpler python file:

There are some bugs in the current {{Pkg|offlineimap}} which makes it impossible to read the authentication data from {{ic|~/.netrc}} if there are multiple Accounts per remote machine. ( see [http://comments.gmane.org/gmane.mail.imap.offlineimap.general/3024 Mail Archive ] ) But they are fixed in the GIT package {{AUR|offlineimap-git}} (note that is AUR package is flagged as out of date; see the current GitHub external link below).

+

−

Using the package you can collect all passwords in {{ic|~/.netrc}}. And do not forget to set it's access rights:

+

−

chmod 600 ~/.netrc

+

−

An example netrc file would be

+

−

{{hc|~/.netrc|

+

−

machine mail.myhost.de

+

−

login mr_smith

+

−

password secret

+

−

}}

+

−

===socket.ssl deprecation warnings===

−

Depending on the currently installed python version, running offlineimap throws this warning:

The diff is relative to the root buildir and it can be applied by using [[ABS]].

−

−

===Folder could not be created===

In version 6.5.3, offlineimap gained the ability to create folders in the remote repository, as described [http://comments.gmane.org/gmane.mail.imap.offlineimap.general/4784 here].

In version 6.5.3, offlineimap gained the ability to create folders in the remote repository, as described [http://comments.gmane.org/gmane.mail.imap.offlineimap.general/4784 here].

Line 312:

Line 361:

The solution is to provide an inverse {{Ic|nametrans}} lambda for the local repository, e.g.

The solution is to provide an inverse {{Ic|nametrans}} lambda for the local repository, e.g.

−

{{hc|~/.offlineimaprc|2=

+

−

<nowiki>

+

{{hc|~/.offlineimaprc|<nowiki>

[Repository foo-local]

[Repository foo-local]

nametrans = lambda foldername: foldername.replace('bar', 'BAR')

nametrans = lambda foldername: foldername.replace('bar', 'BAR')

Line 319:

Line 368:

[Repository foo-remote]

[Repository foo-remote]

nametrans = lambda foldername: foldername.replace('BAR', 'bar')

nametrans = lambda foldername: foldername.replace('BAR', 'bar')

−

</nowiki>

+

</nowiki>}}

−

}}

+

* For working out the correct inverse mapping. the output of {{Ic|offlineimap --info}} should help.

* For working out the correct inverse mapping. the output of {{Ic|offlineimap --info}} should help.

−

* After updating the mapping, it map be necessary to remove all of the folders under {{Ic|$HOME/.offlineimap/}} for the affected accounts.

+

* After updating the mapping, it may be necessary to remove all of the folders under {{Ic|$HOME/.offlineimap/}} for the affected accounts.

===SSL fingerprint does not match===

===SSL fingerprint does not match===

−

ERROR: Server SSL fingerprint 'keykeykey' for hostname 'example.com' does not match configured fingerprint. Please verify and set 'cert_fingerprint' accordingly if not set yet.

−

Add cert_fingerprint to .offlineimaprc (in the same section as "ssl = yes")

+

ERROR: Server SSL fingerprint 'keykeykey' for hostname 'example.com' does not match configured fingerprint. Please verify and set 'cert_fingerprint' accordingly if not set yet.

−

cert_fingerprint = keykeykey

+

+

To solve this, add to {{ic|~/.offlineimaprc}} (in the same section as {{ic|1=ssl = yes}}) one of the following:

+

* either add {{ic|cert_fingerprint}}, with the certificate fingerprint of the remote server. This checks whether the remote server certificate matches the given fingerprint.

+

cert_fingerprint = keykeykey

+

* or add {{ic|sslcacertfile}} with the path to the system CA certificates file. Needs {{Pkg|ca-certificates}} installed. This validates the remote ssl certificate chain against the Certification Authorities in that file.

** This setup worked for me, only difference being I had to add {{ic|1=mail_location = maildir:~/Maildir}} to {{ic|/etc/dovecot/dovecot.conf}}. Also, I used the [[OfflineIMAP#Gmail_configuration|Gmail configuration above]]. --[[User:Unhammer|Unhammer]] 09:24, 22 October 2010 (EDT)

Installing

Configuring

Offlineimap is distributed with two default configuration files, which are both located in /usr/share/offlineimap/. offlineimap.conf contains every setting and is thorougly documented. Alternatively, offlineimap.conf.minimal is not commented and only contains a small number of settings (see: Minimal).

Copy one of the default configuration files to ~/.offlineimaprc.

Note: Writing a comment after an option/value on the same line is invalid syntax, hence take care that comments are placed on their own separate line.

Minimal

The following file is a commented version of offlineimap.conf.minimal.

Usage

Before running offlineimap, create any parent directories that were allocated to local repositories:

$ mkdir ~/Maildir

Now, run the program:

$ offlineimap

Mail accounts will now be synced. If anything goes wrong, take a closer look at the error messages. OfflineIMAP is usually very verbose about problems; partly because the developers did not bother with taking away tracebacks from the final product.

Miscellaneous

Running offlineimap in the background

Most other mail transfer agents assume that the user will be using the tool as a daemon by making the program sync periodically by default. In offlineimap, there are a few settings that control backgrounded tasks.

Confusingly, they are spread thin all-over the configuration file:

~/.offlineimaprc

# In the general section
[general]
# Controls how many accounts may be synced simultaneously
maxsyncaccounts = 1
# In the account identifier
[Account main]
# Minutes between syncs
autorefresh = 5
# Number of quick-syncs between autorefreshes. Quick-syncs do not update if the
# only changes were to IMAP flags
quick = 10
# In the remote repository identifier
[Repository main-remote]
# Instead of closing the connection once a sync is complete, offlineimap will
# send empty data to the server to hold the connection open. A value of 60
# attempts to hold the connection for a minute between syncs (both quick and
# autorefresh).This setting has no effect if autorefresh and holdconnectionopen
# are not both set.
keepalive = 60
# OfflineIMAP normally closes IMAP server connections between refreshes if
# the global option autorefresh is specified. If you wish it to keep the
# connection open, set this to true. This setting has no effect if autorefresh
is not set.
holdconnectionopen = yes

The wrapper script is needed because offlineimap has the tendency to sporadically crash, even more so when facing connection problems.

Automatic mutt mailbox generation

Mutt cannot be simply pointed to an IMAP or maildir directory and be expected to guess which subdirectories happen to be the mailboxes, yet offlineimap can generate a muttrc fragment containing the mailboxes that it syncs.

account is the name you have given to your IMAP account in ~/.offlineimaprc.

Gmail configuration

This remote repository is configured 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:

If you have Gmail set to another language, the folder names may appear translated too, e.g. "verzonden_berichten" instead of "sent_mail".

After version 6.3.5, offlineimap also creates remote folders to match your local ones. Thus you may need a nametrans rule for your local repository too that reverses the effects of this nametrans rule.

As of 1 October 2012 gmail SSL certificate fingerprint is not always the same. This prevents from using cert_fingerprint and makes the sslcacertfile way a better solution for the SSL verification (see OfflineIMAP#SSL fingerprint does not match).

[general]
# VVV Set this path correctly VVV
pythonfile = /home/user/offlineimap.py
...
[Repository RemoteEmail]
remoteuser = username@host.net
# Set the DB path as well as the title and username of the specific entry you'd like to use.
# This will prompt you on STDIN at runtime for the kdb master password.
remotepasseval = get_keepass_pw("/path/to/database.kdb", title="<entry title>", username="<entry username>")
...

Note that as-is, this does not support KDBs with keyfiles, only KDBs with password-only auth.

Kerberos authentication

Install python2-kerberosAUR from AUR and do not specify remotepass in your .offlineimaprc.
OfflineImap figure out the reset all if have a valid Kerberos TGT.
If you have 'maxconnections', it will fail for some connection. Comment 'maxconnections' out will solve this problem.

Troubleshooting

Overriding UI and autorefresh settings

For the sake of troubleshooting, it is sometimes convenient to launch offlineimap with a more verbose UI, no background syncs and perhaps even a debug level:

$ offlineimap [ -o ] [ -d <debug_type> ] [ -u <ui> ]

-o

Disable autorefresh, keepalive, etc.

-d <debug_type>

Where <debug_type> is one of imap, maildir or thread. Debugging imap and maildir are, by far, the most useful.

-u <ui>

Where <ui> is one of CURSES.BLINKENLIGHTS, TTY.TTYUI, NONINTERACTIVE.BASIC, NONINTERACTIVE.QUIET or MACHINE.MACHINEUI. TTY.TTYUI is sufficient for debugging purposes.

Note: More recent versions use the following for <ui>: blinkenlights, ttyui, basic, quiet or machineui.

Folder could not be created

In version 6.5.3, offlineimap gained the ability to create folders in the remote repository, as described here.

This can lead to errors of the following form when using nametrans on the remote repository:

For working out the correct inverse mapping. the output of offlineimap --info should help.

After updating the mapping, it may be necessary to remove all of the folders under $HOME/.offlineimap/ for the affected accounts.

SSL fingerprint does not match

ERROR: Server SSL fingerprint 'keykeykey' for hostname 'example.com' does not match configured fingerprint. Please verify and set 'cert_fingerprint' accordingly if not set yet.

To solve this, add to ~/.offlineimaprc (in the same section as ssl = yes) one of the following:

either add cert_fingerprint, with the certificate fingerprint of the remote server. This checks whether the remote server certificate matches the given fingerprint.

cert_fingerprint = keykeykey

or add sslcacertfile with the path to the system CA certificates file. Needs ca-certificates installed. This validates the remote ssl certificate chain against the Certification Authorities in that file.