Difference between revisions of "OfflineIMAP"
(→Minimal: Updated, shortened) |
(→netrc authentication: rm outdated section) |
||
(40 intermediate revisions by 20 users not shown) | |||
Line 1: | Line 1: | ||
− | [[Category: | + | [[Category:Email Client]] |
− | [http://offlineimap.org/ OfflineIMAP] is | + | {{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== | |
− | + | Install {{pkg|offlineimap}} from the [[official repositories]]. For a development version, install {{AUR|offlineimap-git}} from [[AUR]]. | |
− | Install the {{ | ||
− | |||
==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}} | + | |
+ | 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 16: | 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| | + | |
− | <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 42: | 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 52: | 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 | + | 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== | ||
− | |||
===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| | + | |
− | <nowiki> | + | {{hc|~/.offlineimaprc|<nowiki> |
# In the general section | # In the general section | ||
[general] | [general] | ||
Line 81: | 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 |
+ | # are not both set. | ||
keepalive = 60 | keepalive = 60 | ||
− | </nowiki> | + | # 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 | ||
+ | </nowiki>}} | ||
+ | |||
+ | ====systemd Service==== | ||
+ | |||
+ | # Configure background jobs as shown in [[#Running offlineimap in the background]]. | ||
+ | # Writing a systemd service runnable as an user. | ||
+ | |||
+ | {{hc|/etc/systemd/system/offlineimap@.service|<nowiki> | ||
+ | [Unit] | ||
+ | Description=Start offlineimap as a daemon | ||
+ | Requires=network.target | ||
+ | After=network.target | ||
+ | |||
+ | [Service] | ||
+ | User=%i | ||
+ | ExecStart=/usr/bin/offlineimap | ||
+ | KillSignal=SIGUSR2 | ||
+ | Restart=always | ||
+ | |||
+ | [Install] | ||
+ | WantedBy=multi-user.target | ||
+ | </nowiki>}} | ||
====cron job==== | ====cron job==== | ||
+ | |||
1. Configure background jobs as shown in [[#Running offlineimap in the background]]. | 1. Configure background jobs as shown in [[#Running offlineimap in the background]]. | ||
2. Use a log-friendly user interface: | 2. Use a log-friendly user interface: | ||
− | {{hc|~/.offlineimaprc| | + | |
− | <nowiki> | + | {{hc|~/.offlineimaprc|<nowiki> |
[general] | [general] | ||
# This will suppress anything but errors | # This will suppress anything but errors | ||
− | ui = | + | ui = quiet |
− | </nowiki> | + | </nowiki>}} |
− | }} | ||
3. Write a wrapper script for [[daemon]]izing programs, or use the one shown below: | 3. Write a wrapper script for [[daemon]]izing programs, or use the one shown below: | ||
− | {{hc|/usr/local/bin/start_daemon| | + | |
− | <nowiki> | + | {{hc|/usr/local/bin/start_daemon|<nowiki> |
#!/bin/sh | #!/bin/sh | ||
Line 137: | Line 168: | ||
exec $cmd | exec $cmd | ||
− | </nowiki> | + | </nowiki>}} |
− | }} | ||
4. Finally, add a crontab entry: | 4. Finally, add a crontab entry: | ||
$ crontab -e | $ crontab -e | ||
The line should specify the interpreter for correct {{Ic|pgrep -xf}} results: | The line should specify the interpreter for correct {{Ic|pgrep -xf}} results: | ||
− | */5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap | + | */5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap |
− | + | <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=== | |
− | |||
[[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| | + | |
− | <nowiki> | + | {{hc|~/.offlineimaprc|<nowiki> |
[mbnames] | [mbnames] | ||
enabled = yes | enabled = yes | ||
Line 160: | Line 189: | ||
sep = " " | sep = " " | ||
footer = "\n" | footer = "\n" | ||
− | </nowiki> | + | </nowiki>}} |
− | }} | + | |
+ | 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: | ||
− | {{hc|~/.offlineimaprc| | + | {{hc|~/.offlineimaprc|<nowiki> |
− | <nowiki> | ||
[Repository gmail-remote] | [Repository gmail-remote] | ||
type = Gmail | type = Gmail | ||
Line 179: | Line 218: | ||
re.sub (' ', '_', foldername.lower())))) | re.sub (' ', '_', foldername.lower())))) | ||
folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail' | folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail' | ||
− | </nowiki> | + | # Necessary as of OfflineIMAP 6.5.4 |
+ | sslcacertfile = /etc/ssl/certs/ca-certificates.crt | ||
+ | </nowiki>}} | ||
+ | |||
+ | {{Note| | ||
+ | * 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 {{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=== | |
− | + | ====.netrc==== | |
− | |||
− | |||
Add the following lines to your {{ic|~/.netrc}}: | Add the following lines to your {{ic|~/.netrc}}: | ||
− | + | machine hostname.tld | |
− | + | login [your username] | |
− | + | password [your password] | |
− | + | Do not forget to give the file appropriate rights like 600 or 700: | |
− | + | $ 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. | ||
− | + | In the example, functions from a python file are imported in order to get passwords from gnome-keyring. | |
− | + | ||
+ | Alternatively, if youre using {{AUR|gnome-keyring-query}}, you can use this simpler python file: | ||
+ | |||
+ | {{bc|<nowiki> | ||
+ | #!/usb/bin/python | ||
+ | # executes gnome-keyring-query get passwd | ||
+ | # and returns the output | ||
+ | |||
+ | import locale | ||
+ | from subprocess import Popen, PIPE | ||
+ | |||
+ | encoding = locale.getdefaultlocale()[1] | ||
− | {{bc| | + | def get_password(p): |
+ | (out, err) = Popen(["gnome-keyring-query", "get", p], stdout=PIPE).communicate() | ||
+ | return out.decode(encoding).strip() | ||
+ | </nowiki>}} | ||
+ | |||
+ | ====python2-keyring==== | ||
+ | |||
+ | There is a general solution that should work for any keyring. Install [http://pypi.python.org/pypi/keyring python2-keyring] from [[AUR]], then change your ~/.offlineimaprc to say something like: | ||
+ | |||
+ | {{bc|<nowiki> | ||
[general] | [general] | ||
pythonfile = /home/user/offlineimap.py | pythonfile = /home/user/offlineimap.py | ||
− | + | ... | |
[Repository RemoteEmail] | [Repository RemoteEmail] | ||
remoteuser = username@host.net | remoteuser = username@host.net | ||
remotepasseval = keyring.get_password("offlineimap","username@host.net") | remotepasseval = keyring.get_password("offlineimap","username@host.net") | ||
− | + | ... | |
− | }} | + | </nowiki>}} |
and somewhere in ~/offlineimap.py add {{ic|import keyring}}. Now all you have to do is set your password, like so: | and somewhere in ~/offlineimap.py add {{ic|import keyring}}. Now all you have to do is set your password, like so: | ||
Line 217: | Line 282: | ||
{{bc|$ python2 | {{bc|$ python2 | ||
>>> import keyring | >>> import keyring | ||
− | >>> keyring.set_password("offlineimap","username@host.net", "MYPASSWORD") | + | >>> keyring.set_password("offlineimap","username@host.net", "MYPASSWORD")}} |
− | and it | + | and it will grab the password from your (kwallet/gnome-) keyring instead of having to keep it in plaintext or enter it each time. |
====Emacs EasyPG==== | ====Emacs EasyPG==== | ||
+ | |||
See http://www.emacswiki.org/emacs/OfflineIMAP#toc2 | See http://www.emacswiki.org/emacs/OfflineIMAP#toc2 | ||
===Kerberos authentication=== | ===Kerberos authentication=== | ||
− | Install python2-kerberos from [ | + | |
+ | Install {{AUR|python2-kerberos}} from [[AUR]] and do not specify remotepass in your .offlineimaprc. | ||
OfflineImap figure out the reset all if have a valid Kerberos TGT. | 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. | If you have 'maxconnections', it will fail for some connection. Comment 'maxconnections' out will solve this problem. | ||
Line 232: | Line 299: | ||
===Overriding UI and autorefresh settings=== | ===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: | 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> ] | $ offlineimap [ -o ] [ -d <debug_type> ] [ -u <ui> ] | ||
Line 245: | Line 313: | ||
{{Note|More recent versions use the following for <ui>: {{Ic|blinkenlights}}, {{Ic|ttyui}}, {{Ic|basic}}, {{Ic|quiet}} or {{Ic|machineui}}.}} | {{Note|More recent versions use the following for <ui>: {{Ic|blinkenlights}}, {{Ic|ttyui}}, {{Ic|basic}}, {{Ic|quiet}} or {{Ic|machineui}}.}} | ||
− | === | + | ===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 314: | Line 322: | ||
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| | + | |
− | <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 321: | Line 329: | ||
[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 | + | * 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. | |
− | + | ||
+ | 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. | ||
+ | sslcacertfile = /etc/ssl/certs/ca-certificates.crt | ||
+ | |||
+ | == See also == | ||
− | |||
* [http://lists.alioth.debian.org/mailman/listinfo/offlineimap-project Official OfflineIMAP mailing list] | * [http://lists.alioth.debian.org/mailman/listinfo/offlineimap-project Official OfflineIMAP mailing list] | ||
* [http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html Gnus, Dovecot, OfflineIMAP, search: a HOWTO] | * [http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html Gnus, Dovecot, OfflineIMAP, search: a HOWTO] | ||
− | + | * [http://pbrisbin.com/posts/mutt_gmail_offlineimap/ Mutt + Gmail + Offlineimap] - An outline of brisbin's simple gmail/mutt setup using cron to keep offlineimap syncing. | |
− | * [http://pbrisbin.com/posts/mutt_gmail_offlineimap/ Mutt + Gmail + Offlineimap] | ||
− | |||
− | |||
− |
Revision as of 15:40, 14 November 2013
Template:Article summary start Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end 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
Install offlineimap from the official repositories. For a development version, install offlineimap-gitAUR from AUR.
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
.
Minimal
The following file is a commented version of offlineimap.conf.minimal
.
~/.offlineimaprc
[general] # List of accounts to be synced, separated by a comma. accounts = main [Account main] # Identifier for the local repository; e.g. the maildir to be synced via IMAP. localrepository = main-local # Identifier for the remote repository; i.e. the actual IMAP, usually non-local. remoterepository = main-remote # Status cache. Default is plain, which eventually becomes huge and slow. status_backend = sqlite [Repository main-local] # Currently, offlineimap only supports maildir and IMAP for local repositories. type = Maildir # Where should the mail be placed? localfolders = ~/Maildir [Repository main-remote] # Remote repos can be IMAP or Gmail, the latter being a preconfigured IMAP. type = IMAP remotehost = host.domain.tld remoteuser = username
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
systemd Service
- Configure background jobs as shown in #Running offlineimap in the background.
- Writing a systemd service runnable as an user.
/etc/systemd/system/offlineimap@.service
[Unit] Description=Start offlineimap as a daemon Requires=network.target After=network.target [Service] User=%i ExecStart=/usr/bin/offlineimap KillSignal=SIGUSR2 Restart=always [Install] WantedBy=multi-user.target
cron job
1. Configure background jobs as shown in #Running offlineimap in the background.
2. Use a log-friendly user interface:
~/.offlineimaprc
[general] # This will suppress anything but errors ui = quiet
3. Write a wrapper script for daemonizing programs, or use the one shown below:
/usr/local/bin/start_daemon
#!/bin/sh set -efu ionice_class= ionice_priority= nice= while getopts c:p:n: f; do case $f in c) ionice_class=$OPTARG;; p) ionice_priority=$OPTARG;; n) nice=$OPTARG;; *) exit 2;; esac done shift $((OPTIND - 1)) cmd=$* io= if pgrep -u "$(id -u)" -xf -- "$cmd" >/dev/null 2>&1; then exit 0 fi if type ionice >/dev/null 2>&1; then [ -n "$ionice_class" ] && { io=1; cmd="-c $ionice_class $cmd"; } [ -n "$ionice_priority" ] && { io=1; cmd="-n $ionice_priority $cmd"; } [ -n "$io" ] && cmd="ionice $cmd" fi if type nice >/dev/null 2>&1; then [ -n "$nice" ] && cmd="nice -n $nice $cmd" fi exec $cmd
4. Finally, add a crontab entry:
$ crontab -e
The line should specify the interpreter for correct pgrep -xf
results:
*/5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap
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.
~/.offlineimaprc
[mbnames] enabled = yes filename = ~/.mutt/mailboxes header = "mailboxes " peritem = "+%(accountname)s/%(foldername)s" sep = " " footer = "\n"
Then add the following lines to ~/.mutt/muttrc
.
~/.mutt/muttrc
# IMAP: offlineimap set folder = "~/Mail" source ~/.mutt/mailboxes set spoolfile = "+account/INBOX" set record = "+account/Sent\ Items" set postponed = "+account/Drafts"
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:
~/.offlineimaprc
[Repository gmail-remote] type = Gmail remoteuser = user@gmail.com remotepass = password nametrans = lambda foldername: re.sub ('^\[gmail\]', 'bak', re.sub ('sent_mail', 'sent', re.sub ('starred', 'flagged', re.sub (' ', '_', foldername.lower())))) folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail' # Necessary as of OfflineIMAP 6.5.4 sslcacertfile = /etc/ssl/certs/ca-certificates.crt
- 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 thesslcacertfile
way a better solution for the SSL verification (see OfflineIMAP#SSL fingerprint does not match).
Not having to enter the password all the time
.netrc
Add the following lines to your ~/.netrc
:
machine hostname.tld login [your username] password [your password]
Do not forget to give the file appropriate rights like 600 or 700:
$ chmod 600 ~/.netrc
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.
In the example, functions from a python file are imported in order to get passwords from gnome-keyring.
Alternatively, if youre using gnome-keyring-queryAUR, you can use this simpler python file:
#!/usb/bin/python # executes gnome-keyring-query get passwd # and returns the output import locale from subprocess import Popen, PIPE encoding = locale.getdefaultlocale()[1] def get_password(p): (out, err) = Popen(["gnome-keyring-query", "get", p], stdout=PIPE).communicate() return out.decode(encoding).strip()
python2-keyring
There is a general solution that should work for any keyring. Install python2-keyring from AUR, then change your ~/.offlineimaprc to say something like:
[general] pythonfile = /home/user/offlineimap.py ... [Repository RemoteEmail] remoteuser = username@host.net remotepasseval = keyring.get_password("offlineimap","username@host.net") ...
and somewhere in ~/offlineimap.py add import keyring
. Now all you have to do is set your password, like so:
$ python2 >>> import keyring >>> keyring.set_password("offlineimap","username@host.net", "MYPASSWORD")
and it will grab the password from your (kwallet/gnome-) keyring instead of having to keep it in plaintext or enter it each time.
Emacs EasyPG
See http://www.emacswiki.org/emacs/OfflineIMAP#toc2
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
orthread
. 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
orMACHINE.MACHINEUI
. TTY.TTYUI is sufficient for debugging purposes.
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:
ERROR: Creating folder bar on repository foo-remote Folder 'bar'[foo-remote] could not be created. Server responded: ('NO', ['[ALREADYEXISTS] Duplicate folder name bar (Failure)'])
The solution is to provide an inverse nametrans
lambda for the local repository, e.g.
~/.offlineimaprc
[Repository foo-local] nametrans = lambda foldername: foldername.replace('bar', 'BAR') [Repository foo-remote] nametrans = lambda foldername: foldername.replace('BAR', 'bar')
- 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.
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
See also
- Official OfflineIMAP mailing list
- Gnus, Dovecot, OfflineIMAP, search: a HOWTO
- Mutt + Gmail + Offlineimap - An outline of brisbin's simple gmail/mutt setup using cron to keep offlineimap syncing.