https://wiki.archlinux.org/api.php?action=feedcontributions&user=Copycat-killer&feedformat=atomArchWiki - User contributions [en]2024-03-29T06:03:17ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=OfflineIMAP&diff=272024OfflineIMAP2013-08-21T18:17:01Z<p>Copycat-killer: /* Gnome Keyring */</p>
<hr />
<div>[[Category:Email Client]]<br />
{{Article summary start|Related}}<br />
{{Article summary wiki|isync}}<br />
{{Article summary wiki|notmuch}}<br />
{{Article summary wiki|msmtp}}<br />
{{Article summary end}}<br />
[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]].<br />
==Installing==<br />
Install {{pkg|offlineimap}} from the [[official repositories]]<br />
<br />
==Configuring==<br />
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]]).<br />
<br />
Copy one of the default configuration files to {{ic|~/.offlineimaprc}}.<br />
<br />
{{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.}}<br />
<br />
===Minimal===<br />
The following file is a commented version of {{ic|offlineimap.conf.minimal}}.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# List of accounts to be synced, separated by a comma.<br />
accounts = main<br />
<br />
[Account main]<br />
# Identifier for the local repository; e.g. the maildir to be synced via IMAP.<br />
localrepository = main-local<br />
# Identifier for the remote repository; i.e. the actual IMAP, usually non-local.<br />
remoterepository = main-remote<br />
# Status cache. Default is plain, which eventually becomes huge and slow.<br />
status_backend = sqlite<br />
<br />
[Repository main-local]<br />
# Currently, offlineimap only supports maildir and IMAP for local repositories.<br />
type = Maildir<br />
# Where should the mail be placed?<br />
localfolders = ~/Maildir<br />
<br />
[Repository main-remote]<br />
# Remote repos can be IMAP or Gmail, the latter being a preconfigured IMAP.<br />
type = IMAP<br />
remotehost = host.domain.tld<br />
remoteuser = username<br />
</nowiki><br />
}}<br />
<br />
==Usage==<br />
Before running offlineimap, create any parent directories that were allocated to local repositories:<br />
$ mkdir ~/Maildir<br />
<br />
Now, run the program:<br />
$ offlineimap<br />
<br />
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.<br />
<br />
==Miscellaneous==<br />
''Various settings and improvements''<br />
<br />
===Running offlineimap in the background===<br />
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.<br />
<br />
Confusingly, they are spread thin all-over the configuration file:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
# In the general section<br />
[general]<br />
# Controls how many accounts may be synced simultaneously<br />
maxsyncaccounts = 1<br />
<br />
# In the account identifier<br />
[Account main]<br />
# Minutes between syncs<br />
autorefresh = 5<br />
# Number of quick-syncs between autorefreshes. Quick-syncs do not update if the<br />
# only changes were to IMAP flags<br />
quick = 10<br />
<br />
# In the remote repository identifier<br />
[Repository main-remote]<br />
# Instead of closing the connection once a sync is complete, offlineimap will<br />
# send empty data to the server to hold the connection open. A value of 60<br />
# attempts to hold the connection for a minute between syncs (both quick and<br />
# autorefresh).This setting has no effect if autorefresh and holdconnectionopen<br />
# are not both set.<br />
keepalive = 60<br />
# OfflineIMAP normally closes IMAP server connections between refreshes if<br />
# the global option autorefresh is specified. If you wish it to keep the<br />
# connection open, set this to true. This setting has no effect if autorefresh<br />
is not set.<br />
holdconnectionopen = yes<br />
</nowiki><br />
}}<br />
<br />
====systemd Service====<br />
Writing a systemd service for offlineimap is trivial, just be sure to run it as the correct user by replacing the {{ic|User&#61;UserToRunAs}} with your user. (e.g. {{ic|User&#61;wgiokas}})<br />
{{hc|offlineimap-user.service|2=<br />
<nowiki><br />
[Unit]<br />
Description=Start offlineimap as a daemon<br />
Requires=network.target<br />
After=network.target<br />
<br />
[Service]<br />
User=UserToRunAs<br />
ExecStart=/usr/bin/offlineimap<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
====cron job====<br />
1. Configure background jobs as shown in [[#Running offlineimap in the background]].<br />
<br />
2. Use a log-friendly user interface:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# This will suppress anything but errors<br />
ui = quiet<br />
</nowiki><br />
}}<br />
<br />
3. Write a wrapper script for [[daemon]]izing programs, or use the one shown below:<br />
{{hc|/usr/local/bin/start_daemon|2=<br />
<nowiki><br />
#!/bin/sh<br />
<br />
set -efu<br />
<br />
ionice_class=<br />
ionice_priority=<br />
nice=<br />
<br />
while getopts c:p:n: f; do<br />
case $f in<br />
c) ionice_class=$OPTARG;;<br />
p) ionice_priority=$OPTARG;;<br />
n) nice=$OPTARG;;<br />
*) exit 2;;<br />
esac<br />
done<br />
shift $((OPTIND - 1))<br />
<br />
cmd=$*<br />
io=<br />
<br />
if pgrep -u "$(id -u)" -xf -- "$cmd" >/dev/null 2>&1; then<br />
exit 0<br />
fi<br />
<br />
if type ionice >/dev/null 2>&1; then<br />
[ -n "$ionice_class" ] && { io=1; cmd="-c $ionice_class $cmd"; }<br />
[ -n "$ionice_priority" ] && { io=1; cmd="-n $ionice_priority $cmd"; }<br />
[ -n "$io" ] && cmd="ionice $cmd"<br />
fi<br />
<br />
if type nice >/dev/null 2>&1; then<br />
[ -n "$nice" ] && cmd="nice -n $nice $cmd"<br />
fi<br />
<br />
exec $cmd<br />
</nowiki><br />
}}<br />
<br />
4. Finally, add a crontab entry:<br />
$ crontab -e<br />
The line should specify the interpreter for correct {{Ic|pgrep -xf}} results:<br />
*/5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap<br />
<br />
<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><br />
<br />
===Automatic mutt mailbox generation===<br />
[[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.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[mbnames]<br />
enabled = yes<br />
filename = ~/.mutt/mailboxes<br />
header = "mailboxes "<br />
peritem = "+%(accountname)s/%(foldername)s"<br />
sep = " "<br />
footer = "\n"<br />
</nowiki><br />
}}<br />
<br />
Then add {{Ic|source ~/.mutt/mailboxes}} to {{ic|~/.mutt/muttrc}}.<br />
<br />
===Gmail configuration===<br />
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:<br />
<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository gmail-remote]<br />
type = Gmail<br />
remoteuser = user@gmail.com<br />
remotepass = password<br />
nametrans = lambda foldername: re.sub ('^\[gmail\]', 'bak',<br />
re.sub ('sent_mail', 'sent',<br />
re.sub ('starred', 'flagged',<br />
re.sub (' ', '_', foldername.lower()))))<br />
folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail'<br />
# Necessary as of OfflineIMAP 6.5.4<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
</nowiki><br />
}}<br />
<br />
{{Note|If you have Gmail set to another language, the folder names may appear translated too, e.g. "verzonden_berichten" instead of "sent_mail".}}<br />
<br />
{{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.}}<br />
<br />
{{Note|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]]).}}<br />
<br />
===Not having to enter the password all the time===<br />
====.netrc====<br />
Add the following lines to your {{ic|~/.netrc}}:<br />
<br />
machine hostname.tld<br />
login [your username]<br />
password [your password]<br />
<br />
Don't forget to give the file appropriate rights like 600 or 700:<br />
chmod 600 ~/.netrc<br />
<br />
====Gnome Keyring====<br />
http://www.clasohm.com/blog/one-entry?entry_id=90957 gives an example of how to use gnome-keyring to store the password. <br />
<br />
In the example, functions from a python file are imported in order to get passwords from gnome-keyring.<br />
<br />
Alternatively, if youre using {{AUR|gnome-keyring-query}}, you can use this simpler python file:<br />
<br />
#!/usb/bin/python<br />
# executes gnome-keyring-query get passwd<br />
# and returns the output<br />
<br />
import locale<br />
from subprocess import Popen, PIPE<br />
<br />
encoding = locale.getdefaultlocale()[1]<br />
<br />
def get_password(p):<br />
(out, err) = Popen(["gnome-keyring-query", "get", p], stdout=PIPE).communicate()<br />
return out.decode(encoding).strip()<br />
<br />
====python2-keyring====<br />
There's 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:<br />
<br />
{{bc|1=<br />
[general]<br />
pythonfile = /home/user/offlineimap.py<br />
…<br />
[Repository RemoteEmail]<br />
remoteuser = username@host.net<br />
remotepasseval = keyring.get_password("offlineimap","username@host.net")<br />
…<br />
}}<br />
<br />
and somewhere in ~/offlineimap.py add {{ic|import keyring}}. Now all you have to do is set your password, like so:<br />
<br />
{{bc|$ python2 <br />
>>> import keyring<br />
>>> keyring.set_password("offlineimap","username@host.net", "MYPASSWORD")}}<br />
<br />
and it'll grab the password from your (kwallet/gnome-) keyring instead of having to keep it in plaintext or enter it each time.<br />
<br />
====Emacs EasyPG====<br />
See http://www.emacswiki.org/emacs/OfflineIMAP#toc2<br />
<br />
===Kerberos authentication===<br />
Install python2-kerberos from [https://aur.archlinux.org/packages.php?ID=50639 AUR] and do not specify remotepass in your .offlineimaprc. <br />
OfflineImap figure out the reset all if have a valid Kerberos TGT. <br />
If you have 'maxconnections', it will fail for some connection. Comment 'maxconnections' out will solve this problem.<br />
<br />
==Troubleshooting==<br />
<br />
===Overriding UI and autorefresh settings===<br />
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:<br />
$ offlineimap [ -o ] [ -d <debug_type> ] [ -u <ui> ]<br />
;-o<br />
:Disable autorefresh, keepalive, etc.<br />
<br />
;-d <debug_type><br />
:Where ''<debug_type>'' is one of {{Ic|imap}}, {{Ic|maildir}} or {{Ic|thread}}. Debugging imap and maildir are, by far, the most useful.<br />
<br />
;-u <ui><br />
:Where ''<ui>'' is one of {{Ic|CURSES.BLINKENLIGHTS}}, {{Ic|TTY.TTYUI}}, {{Ic|NONINTERACTIVE.BASIC}}, {{Ic|NONINTERACTIVE.QUIET}} or {{Ic|MACHINE.MACHINEUI}}. TTY.TTYUI is sufficient for debugging purposes.<br />
<br />
{{Note|More recent versions use the following for <ui>: {{Ic|blinkenlights}}, {{Ic|ttyui}}, {{Ic|basic}}, {{Ic|quiet}} or {{Ic|machineui}}.}}<br />
<br />
===netrc authentication===<br />
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).<br />
Using the package you can collect all passwords in {{ic|~/.netrc}}. And do not forget to set it's access rights:<br />
chmod 600 ~/.netrc<br />
An example netrc file would be<br />
{{hc|~/.netrc|<br />
machine mail.myhost.de<br />
login mr_smith<br />
password secret<br />
}}<br />
<br />
===Folder could not be created===<br />
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].<br />
<br />
This can lead to errors of the following form when using {{Ic|nametrans}} on the remote repository:<br />
ERROR: Creating folder bar on repository foo-remote<br />
Folder 'bar'[foo-remote] could not be created. Server responded: ('NO', ['[ALREADYEXISTS] Duplicate folder name bar (Failure)'])<br />
<br />
The solution is to provide an inverse {{Ic|nametrans}} lambda for the local repository, e.g.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository foo-local]<br />
nametrans = lambda foldername: foldername.replace('bar', 'BAR')<br />
<br />
[Repository foo-remote]<br />
nametrans = lambda foldername: foldername.replace('BAR', 'bar')<br />
</nowiki><br />
}}<br />
<br />
* For working out the correct inverse mapping. the output of {{Ic|offlineimap --info}} should help.<br />
* After updating the mapping, it may be necessary to remove all of the folders under {{Ic|$HOME/.offlineimap/}} for the affected accounts.<br />
<br />
===SSL fingerprint does not match===<br />
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.<br />
<br />
To solve this, add to {{ic|~/.offlineimaprc}} (in the same section as {{ic|1=ssl = yes}}) one of the following:<br />
* either add {{ic|cert_fingerprint}}, with the certificate fingerprint of the remote server. This checks whether the remote server certificate matches the given fingerprint.<br />
cert_fingerprint = keykeykey<br />
* 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.<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
<br />
==External links==<br />
* [http://lists.alioth.debian.org/mailman/listinfo/offlineimap-project Official OfflineIMAP mailing list]<br />
* [http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html Gnus, Dovecot, OfflineIMAP, search: a HOWTO]<br />
** 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)<br />
* [http://pbrisbin.com/posts/mutt_gmail_offlineimap/ Mutt + Gmail + Offlineimap]<br />
** An outline of brisbin's simple gmail/mutt setup using cron to keep offlineimap syncing.<br />
* [https://github.com/OfflineIMAP/offlineimap Current OfflineIMAP maintainer's fork on GitHub]<br />
** Note that a strict build of this on current Arch will fail due to python references unless they are replaced with python2</div>Copycat-killerhttps://wiki.archlinux.org/index.php?title=OfflineIMAP&diff=272023OfflineIMAP2013-08-21T18:16:43Z<p>Copycat-killer: /* Gnome Keyring */</p>
<hr />
<div>[[Category:Email Client]]<br />
{{Article summary start|Related}}<br />
{{Article summary wiki|isync}}<br />
{{Article summary wiki|notmuch}}<br />
{{Article summary wiki|msmtp}}<br />
{{Article summary end}}<br />
[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]].<br />
==Installing==<br />
Install {{pkg|offlineimap}} from the [[official repositories]]<br />
<br />
==Configuring==<br />
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]]).<br />
<br />
Copy one of the default configuration files to {{ic|~/.offlineimaprc}}.<br />
<br />
{{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.}}<br />
<br />
===Minimal===<br />
The following file is a commented version of {{ic|offlineimap.conf.minimal}}.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# List of accounts to be synced, separated by a comma.<br />
accounts = main<br />
<br />
[Account main]<br />
# Identifier for the local repository; e.g. the maildir to be synced via IMAP.<br />
localrepository = main-local<br />
# Identifier for the remote repository; i.e. the actual IMAP, usually non-local.<br />
remoterepository = main-remote<br />
# Status cache. Default is plain, which eventually becomes huge and slow.<br />
status_backend = sqlite<br />
<br />
[Repository main-local]<br />
# Currently, offlineimap only supports maildir and IMAP for local repositories.<br />
type = Maildir<br />
# Where should the mail be placed?<br />
localfolders = ~/Maildir<br />
<br />
[Repository main-remote]<br />
# Remote repos can be IMAP or Gmail, the latter being a preconfigured IMAP.<br />
type = IMAP<br />
remotehost = host.domain.tld<br />
remoteuser = username<br />
</nowiki><br />
}}<br />
<br />
==Usage==<br />
Before running offlineimap, create any parent directories that were allocated to local repositories:<br />
$ mkdir ~/Maildir<br />
<br />
Now, run the program:<br />
$ offlineimap<br />
<br />
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.<br />
<br />
==Miscellaneous==<br />
''Various settings and improvements''<br />
<br />
===Running offlineimap in the background===<br />
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.<br />
<br />
Confusingly, they are spread thin all-over the configuration file:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
# In the general section<br />
[general]<br />
# Controls how many accounts may be synced simultaneously<br />
maxsyncaccounts = 1<br />
<br />
# In the account identifier<br />
[Account main]<br />
# Minutes between syncs<br />
autorefresh = 5<br />
# Number of quick-syncs between autorefreshes. Quick-syncs do not update if the<br />
# only changes were to IMAP flags<br />
quick = 10<br />
<br />
# In the remote repository identifier<br />
[Repository main-remote]<br />
# Instead of closing the connection once a sync is complete, offlineimap will<br />
# send empty data to the server to hold the connection open. A value of 60<br />
# attempts to hold the connection for a minute between syncs (both quick and<br />
# autorefresh).This setting has no effect if autorefresh and holdconnectionopen<br />
# are not both set.<br />
keepalive = 60<br />
# OfflineIMAP normally closes IMAP server connections between refreshes if<br />
# the global option autorefresh is specified. If you wish it to keep the<br />
# connection open, set this to true. This setting has no effect if autorefresh<br />
is not set.<br />
holdconnectionopen = yes<br />
</nowiki><br />
}}<br />
<br />
====systemd Service====<br />
Writing a systemd service for offlineimap is trivial, just be sure to run it as the correct user by replacing the {{ic|User&#61;UserToRunAs}} with your user. (e.g. {{ic|User&#61;wgiokas}})<br />
{{hc|offlineimap-user.service|2=<br />
<nowiki><br />
[Unit]<br />
Description=Start offlineimap as a daemon<br />
Requires=network.target<br />
After=network.target<br />
<br />
[Service]<br />
User=UserToRunAs<br />
ExecStart=/usr/bin/offlineimap<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
====cron job====<br />
1. Configure background jobs as shown in [[#Running offlineimap in the background]].<br />
<br />
2. Use a log-friendly user interface:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# This will suppress anything but errors<br />
ui = quiet<br />
</nowiki><br />
}}<br />
<br />
3. Write a wrapper script for [[daemon]]izing programs, or use the one shown below:<br />
{{hc|/usr/local/bin/start_daemon|2=<br />
<nowiki><br />
#!/bin/sh<br />
<br />
set -efu<br />
<br />
ionice_class=<br />
ionice_priority=<br />
nice=<br />
<br />
while getopts c:p:n: f; do<br />
case $f in<br />
c) ionice_class=$OPTARG;;<br />
p) ionice_priority=$OPTARG;;<br />
n) nice=$OPTARG;;<br />
*) exit 2;;<br />
esac<br />
done<br />
shift $((OPTIND - 1))<br />
<br />
cmd=$*<br />
io=<br />
<br />
if pgrep -u "$(id -u)" -xf -- "$cmd" >/dev/null 2>&1; then<br />
exit 0<br />
fi<br />
<br />
if type ionice >/dev/null 2>&1; then<br />
[ -n "$ionice_class" ] && { io=1; cmd="-c $ionice_class $cmd"; }<br />
[ -n "$ionice_priority" ] && { io=1; cmd="-n $ionice_priority $cmd"; }<br />
[ -n "$io" ] && cmd="ionice $cmd"<br />
fi<br />
<br />
if type nice >/dev/null 2>&1; then<br />
[ -n "$nice" ] && cmd="nice -n $nice $cmd"<br />
fi<br />
<br />
exec $cmd<br />
</nowiki><br />
}}<br />
<br />
4. Finally, add a crontab entry:<br />
$ crontab -e<br />
The line should specify the interpreter for correct {{Ic|pgrep -xf}} results:<br />
*/5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap<br />
<br />
<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><br />
<br />
===Automatic mutt mailbox generation===<br />
[[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.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[mbnames]<br />
enabled = yes<br />
filename = ~/.mutt/mailboxes<br />
header = "mailboxes "<br />
peritem = "+%(accountname)s/%(foldername)s"<br />
sep = " "<br />
footer = "\n"<br />
</nowiki><br />
}}<br />
<br />
Then add {{Ic|source ~/.mutt/mailboxes}} to {{ic|~/.mutt/muttrc}}.<br />
<br />
===Gmail configuration===<br />
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:<br />
<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository gmail-remote]<br />
type = Gmail<br />
remoteuser = user@gmail.com<br />
remotepass = password<br />
nametrans = lambda foldername: re.sub ('^\[gmail\]', 'bak',<br />
re.sub ('sent_mail', 'sent',<br />
re.sub ('starred', 'flagged',<br />
re.sub (' ', '_', foldername.lower()))))<br />
folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail'<br />
# Necessary as of OfflineIMAP 6.5.4<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
</nowiki><br />
}}<br />
<br />
{{Note|If you have Gmail set to another language, the folder names may appear translated too, e.g. "verzonden_berichten" instead of "sent_mail".}}<br />
<br />
{{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.}}<br />
<br />
{{Note|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]]).}}<br />
<br />
===Not having to enter the password all the time===<br />
====.netrc====<br />
Add the following lines to your {{ic|~/.netrc}}:<br />
<br />
machine hostname.tld<br />
login [your username]<br />
password [your password]<br />
<br />
Don't forget to give the file appropriate rights like 600 or 700:<br />
chmod 600 ~/.netrc<br />
<br />
====Gnome Keyring====<br />
http://www.clasohm.com/blog/one-entry?entry_id=90957 gives an example of how to use gnome-keyring to store the password. <br />
<br />
In the example, functions from a python file are imported in order to get passwords from gnome-keyring.<br />
<br />
Alternatively, if youre using {{AUR|gnome-keyring-query}}, you can use this simpler python file instead:<br />
<br />
#!/usb/bin/python<br />
# executes gnome-keyring-query get passwd<br />
# and returns the output<br />
<br />
import locale<br />
from subprocess import Popen, PIPE<br />
<br />
encoding = locale.getdefaultlocale()[1]<br />
<br />
def get_password(p):<br />
(out, err) = Popen(["gnome-keyring-query", "get", p], stdout=PIPE).communicate()<br />
return out.decode(encoding).strip()<br />
<br />
====python2-keyring====<br />
There's 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:<br />
<br />
{{bc|1=<br />
[general]<br />
pythonfile = /home/user/offlineimap.py<br />
…<br />
[Repository RemoteEmail]<br />
remoteuser = username@host.net<br />
remotepasseval = keyring.get_password("offlineimap","username@host.net")<br />
…<br />
}}<br />
<br />
and somewhere in ~/offlineimap.py add {{ic|import keyring}}. Now all you have to do is set your password, like so:<br />
<br />
{{bc|$ python2 <br />
>>> import keyring<br />
>>> keyring.set_password("offlineimap","username@host.net", "MYPASSWORD")}}<br />
<br />
and it'll grab the password from your (kwallet/gnome-) keyring instead of having to keep it in plaintext or enter it each time.<br />
<br />
====Emacs EasyPG====<br />
See http://www.emacswiki.org/emacs/OfflineIMAP#toc2<br />
<br />
===Kerberos authentication===<br />
Install python2-kerberos from [https://aur.archlinux.org/packages.php?ID=50639 AUR] and do not specify remotepass in your .offlineimaprc. <br />
OfflineImap figure out the reset all if have a valid Kerberos TGT. <br />
If you have 'maxconnections', it will fail for some connection. Comment 'maxconnections' out will solve this problem.<br />
<br />
==Troubleshooting==<br />
<br />
===Overriding UI and autorefresh settings===<br />
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:<br />
$ offlineimap [ -o ] [ -d <debug_type> ] [ -u <ui> ]<br />
;-o<br />
:Disable autorefresh, keepalive, etc.<br />
<br />
;-d <debug_type><br />
:Where ''<debug_type>'' is one of {{Ic|imap}}, {{Ic|maildir}} or {{Ic|thread}}. Debugging imap and maildir are, by far, the most useful.<br />
<br />
;-u <ui><br />
:Where ''<ui>'' is one of {{Ic|CURSES.BLINKENLIGHTS}}, {{Ic|TTY.TTYUI}}, {{Ic|NONINTERACTIVE.BASIC}}, {{Ic|NONINTERACTIVE.QUIET}} or {{Ic|MACHINE.MACHINEUI}}. TTY.TTYUI is sufficient for debugging purposes.<br />
<br />
{{Note|More recent versions use the following for <ui>: {{Ic|blinkenlights}}, {{Ic|ttyui}}, {{Ic|basic}}, {{Ic|quiet}} or {{Ic|machineui}}.}}<br />
<br />
===netrc authentication===<br />
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).<br />
Using the package you can collect all passwords in {{ic|~/.netrc}}. And do not forget to set it's access rights:<br />
chmod 600 ~/.netrc<br />
An example netrc file would be<br />
{{hc|~/.netrc|<br />
machine mail.myhost.de<br />
login mr_smith<br />
password secret<br />
}}<br />
<br />
===Folder could not be created===<br />
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].<br />
<br />
This can lead to errors of the following form when using {{Ic|nametrans}} on the remote repository:<br />
ERROR: Creating folder bar on repository foo-remote<br />
Folder 'bar'[foo-remote] could not be created. Server responded: ('NO', ['[ALREADYEXISTS] Duplicate folder name bar (Failure)'])<br />
<br />
The solution is to provide an inverse {{Ic|nametrans}} lambda for the local repository, e.g.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository foo-local]<br />
nametrans = lambda foldername: foldername.replace('bar', 'BAR')<br />
<br />
[Repository foo-remote]<br />
nametrans = lambda foldername: foldername.replace('BAR', 'bar')<br />
</nowiki><br />
}}<br />
<br />
* For working out the correct inverse mapping. the output of {{Ic|offlineimap --info}} should help.<br />
* After updating the mapping, it may be necessary to remove all of the folders under {{Ic|$HOME/.offlineimap/}} for the affected accounts.<br />
<br />
===SSL fingerprint does not match===<br />
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.<br />
<br />
To solve this, add to {{ic|~/.offlineimaprc}} (in the same section as {{ic|1=ssl = yes}}) one of the following:<br />
* either add {{ic|cert_fingerprint}}, with the certificate fingerprint of the remote server. This checks whether the remote server certificate matches the given fingerprint.<br />
cert_fingerprint = keykeykey<br />
* 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.<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
<br />
==External links==<br />
* [http://lists.alioth.debian.org/mailman/listinfo/offlineimap-project Official OfflineIMAP mailing list]<br />
* [http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html Gnus, Dovecot, OfflineIMAP, search: a HOWTO]<br />
** 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)<br />
* [http://pbrisbin.com/posts/mutt_gmail_offlineimap/ Mutt + Gmail + Offlineimap]<br />
** An outline of brisbin's simple gmail/mutt setup using cron to keep offlineimap syncing.<br />
* [https://github.com/OfflineIMAP/offlineimap Current OfflineIMAP maintainer's fork on GitHub]<br />
** Note that a strict build of this on current Arch will fail due to python references unless they are replaced with python2</div>Copycat-killerhttps://wiki.archlinux.org/index.php?title=OfflineIMAP&diff=272022OfflineIMAP2013-08-21T18:15:32Z<p>Copycat-killer: /* Gnome Keyring */</p>
<hr />
<div>[[Category:Email Client]]<br />
{{Article summary start|Related}}<br />
{{Article summary wiki|isync}}<br />
{{Article summary wiki|notmuch}}<br />
{{Article summary wiki|msmtp}}<br />
{{Article summary end}}<br />
[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]].<br />
==Installing==<br />
Install {{pkg|offlineimap}} from the [[official repositories]]<br />
<br />
==Configuring==<br />
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]]).<br />
<br />
Copy one of the default configuration files to {{ic|~/.offlineimaprc}}.<br />
<br />
{{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.}}<br />
<br />
===Minimal===<br />
The following file is a commented version of {{ic|offlineimap.conf.minimal}}.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# List of accounts to be synced, separated by a comma.<br />
accounts = main<br />
<br />
[Account main]<br />
# Identifier for the local repository; e.g. the maildir to be synced via IMAP.<br />
localrepository = main-local<br />
# Identifier for the remote repository; i.e. the actual IMAP, usually non-local.<br />
remoterepository = main-remote<br />
# Status cache. Default is plain, which eventually becomes huge and slow.<br />
status_backend = sqlite<br />
<br />
[Repository main-local]<br />
# Currently, offlineimap only supports maildir and IMAP for local repositories.<br />
type = Maildir<br />
# Where should the mail be placed?<br />
localfolders = ~/Maildir<br />
<br />
[Repository main-remote]<br />
# Remote repos can be IMAP or Gmail, the latter being a preconfigured IMAP.<br />
type = IMAP<br />
remotehost = host.domain.tld<br />
remoteuser = username<br />
</nowiki><br />
}}<br />
<br />
==Usage==<br />
Before running offlineimap, create any parent directories that were allocated to local repositories:<br />
$ mkdir ~/Maildir<br />
<br />
Now, run the program:<br />
$ offlineimap<br />
<br />
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.<br />
<br />
==Miscellaneous==<br />
''Various settings and improvements''<br />
<br />
===Running offlineimap in the background===<br />
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.<br />
<br />
Confusingly, they are spread thin all-over the configuration file:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
# In the general section<br />
[general]<br />
# Controls how many accounts may be synced simultaneously<br />
maxsyncaccounts = 1<br />
<br />
# In the account identifier<br />
[Account main]<br />
# Minutes between syncs<br />
autorefresh = 5<br />
# Number of quick-syncs between autorefreshes. Quick-syncs do not update if the<br />
# only changes were to IMAP flags<br />
quick = 10<br />
<br />
# In the remote repository identifier<br />
[Repository main-remote]<br />
# Instead of closing the connection once a sync is complete, offlineimap will<br />
# send empty data to the server to hold the connection open. A value of 60<br />
# attempts to hold the connection for a minute between syncs (both quick and<br />
# autorefresh).This setting has no effect if autorefresh and holdconnectionopen<br />
# are not both set.<br />
keepalive = 60<br />
# OfflineIMAP normally closes IMAP server connections between refreshes if<br />
# the global option autorefresh is specified. If you wish it to keep the<br />
# connection open, set this to true. This setting has no effect if autorefresh<br />
is not set.<br />
holdconnectionopen = yes<br />
</nowiki><br />
}}<br />
<br />
====systemd Service====<br />
Writing a systemd service for offlineimap is trivial, just be sure to run it as the correct user by replacing the {{ic|User&#61;UserToRunAs}} with your user. (e.g. {{ic|User&#61;wgiokas}})<br />
{{hc|offlineimap-user.service|2=<br />
<nowiki><br />
[Unit]<br />
Description=Start offlineimap as a daemon<br />
Requires=network.target<br />
After=network.target<br />
<br />
[Service]<br />
User=UserToRunAs<br />
ExecStart=/usr/bin/offlineimap<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
====cron job====<br />
1. Configure background jobs as shown in [[#Running offlineimap in the background]].<br />
<br />
2. Use a log-friendly user interface:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# This will suppress anything but errors<br />
ui = quiet<br />
</nowiki><br />
}}<br />
<br />
3. Write a wrapper script for [[daemon]]izing programs, or use the one shown below:<br />
{{hc|/usr/local/bin/start_daemon|2=<br />
<nowiki><br />
#!/bin/sh<br />
<br />
set -efu<br />
<br />
ionice_class=<br />
ionice_priority=<br />
nice=<br />
<br />
while getopts c:p:n: f; do<br />
case $f in<br />
c) ionice_class=$OPTARG;;<br />
p) ionice_priority=$OPTARG;;<br />
n) nice=$OPTARG;;<br />
*) exit 2;;<br />
esac<br />
done<br />
shift $((OPTIND - 1))<br />
<br />
cmd=$*<br />
io=<br />
<br />
if pgrep -u "$(id -u)" -xf -- "$cmd" >/dev/null 2>&1; then<br />
exit 0<br />
fi<br />
<br />
if type ionice >/dev/null 2>&1; then<br />
[ -n "$ionice_class" ] && { io=1; cmd="-c $ionice_class $cmd"; }<br />
[ -n "$ionice_priority" ] && { io=1; cmd="-n $ionice_priority $cmd"; }<br />
[ -n "$io" ] && cmd="ionice $cmd"<br />
fi<br />
<br />
if type nice >/dev/null 2>&1; then<br />
[ -n "$nice" ] && cmd="nice -n $nice $cmd"<br />
fi<br />
<br />
exec $cmd<br />
</nowiki><br />
}}<br />
<br />
4. Finally, add a crontab entry:<br />
$ crontab -e<br />
The line should specify the interpreter for correct {{Ic|pgrep -xf}} results:<br />
*/5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap<br />
<br />
<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><br />
<br />
===Automatic mutt mailbox generation===<br />
[[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.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[mbnames]<br />
enabled = yes<br />
filename = ~/.mutt/mailboxes<br />
header = "mailboxes "<br />
peritem = "+%(accountname)s/%(foldername)s"<br />
sep = " "<br />
footer = "\n"<br />
</nowiki><br />
}}<br />
<br />
Then add {{Ic|source ~/.mutt/mailboxes}} to {{ic|~/.mutt/muttrc}}.<br />
<br />
===Gmail configuration===<br />
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:<br />
<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository gmail-remote]<br />
type = Gmail<br />
remoteuser = user@gmail.com<br />
remotepass = password<br />
nametrans = lambda foldername: re.sub ('^\[gmail\]', 'bak',<br />
re.sub ('sent_mail', 'sent',<br />
re.sub ('starred', 'flagged',<br />
re.sub (' ', '_', foldername.lower()))))<br />
folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail'<br />
# Necessary as of OfflineIMAP 6.5.4<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
</nowiki><br />
}}<br />
<br />
{{Note|If you have Gmail set to another language, the folder names may appear translated too, e.g. "verzonden_berichten" instead of "sent_mail".}}<br />
<br />
{{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.}}<br />
<br />
{{Note|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]]).}}<br />
<br />
===Not having to enter the password all the time===<br />
====.netrc====<br />
Add the following lines to your {{ic|~/.netrc}}:<br />
<br />
machine hostname.tld<br />
login [your username]<br />
password [your password]<br />
<br />
Don't forget to give the file appropriate rights like 600 or 700:<br />
chmod 600 ~/.netrc<br />
<br />
====Gnome Keyring====<br />
http://www.clasohm.com/blog/one-entry?entry_id=90957 gives an example of how to use gnome-keyring to store the password. <br />
<br />
In the example, functions from a python file are imported in order to get passwords from gnome-keyring.<br />
<br />
Alternatively, if youre using {{AUR|gnome-keyring-query}}, you can use this simpler script instead:<br />
<br />
#!/usb/bin/python<br />
# executes gnome-keyring-query get passwd<br />
# and returns the output<br />
<br />
import locale<br />
from subprocess import Popen, PIPE<br />
<br />
encoding = locale.getdefaultlocale()[1]<br />
<br />
def get_password(p):<br />
(out, err) = Popen(["gnome-keyring-query", "get", p], stdout=PIPE).communicate()<br />
return out.decode(encoding).strip()<br />
<br />
====python2-keyring====<br />
There's 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:<br />
<br />
{{bc|1=<br />
[general]<br />
pythonfile = /home/user/offlineimap.py<br />
…<br />
[Repository RemoteEmail]<br />
remoteuser = username@host.net<br />
remotepasseval = keyring.get_password("offlineimap","username@host.net")<br />
…<br />
}}<br />
<br />
and somewhere in ~/offlineimap.py add {{ic|import keyring}}. Now all you have to do is set your password, like so:<br />
<br />
{{bc|$ python2 <br />
>>> import keyring<br />
>>> keyring.set_password("offlineimap","username@host.net", "MYPASSWORD")}}<br />
<br />
and it'll grab the password from your (kwallet/gnome-) keyring instead of having to keep it in plaintext or enter it each time.<br />
<br />
====Emacs EasyPG====<br />
See http://www.emacswiki.org/emacs/OfflineIMAP#toc2<br />
<br />
===Kerberos authentication===<br />
Install python2-kerberos from [https://aur.archlinux.org/packages.php?ID=50639 AUR] and do not specify remotepass in your .offlineimaprc. <br />
OfflineImap figure out the reset all if have a valid Kerberos TGT. <br />
If you have 'maxconnections', it will fail for some connection. Comment 'maxconnections' out will solve this problem.<br />
<br />
==Troubleshooting==<br />
<br />
===Overriding UI and autorefresh settings===<br />
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:<br />
$ offlineimap [ -o ] [ -d <debug_type> ] [ -u <ui> ]<br />
;-o<br />
:Disable autorefresh, keepalive, etc.<br />
<br />
;-d <debug_type><br />
:Where ''<debug_type>'' is one of {{Ic|imap}}, {{Ic|maildir}} or {{Ic|thread}}. Debugging imap and maildir are, by far, the most useful.<br />
<br />
;-u <ui><br />
:Where ''<ui>'' is one of {{Ic|CURSES.BLINKENLIGHTS}}, {{Ic|TTY.TTYUI}}, {{Ic|NONINTERACTIVE.BASIC}}, {{Ic|NONINTERACTIVE.QUIET}} or {{Ic|MACHINE.MACHINEUI}}. TTY.TTYUI is sufficient for debugging purposes.<br />
<br />
{{Note|More recent versions use the following for <ui>: {{Ic|blinkenlights}}, {{Ic|ttyui}}, {{Ic|basic}}, {{Ic|quiet}} or {{Ic|machineui}}.}}<br />
<br />
===netrc authentication===<br />
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).<br />
Using the package you can collect all passwords in {{ic|~/.netrc}}. And do not forget to set it's access rights:<br />
chmod 600 ~/.netrc<br />
An example netrc file would be<br />
{{hc|~/.netrc|<br />
machine mail.myhost.de<br />
login mr_smith<br />
password secret<br />
}}<br />
<br />
===Folder could not be created===<br />
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].<br />
<br />
This can lead to errors of the following form when using {{Ic|nametrans}} on the remote repository:<br />
ERROR: Creating folder bar on repository foo-remote<br />
Folder 'bar'[foo-remote] could not be created. Server responded: ('NO', ['[ALREADYEXISTS] Duplicate folder name bar (Failure)'])<br />
<br />
The solution is to provide an inverse {{Ic|nametrans}} lambda for the local repository, e.g.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository foo-local]<br />
nametrans = lambda foldername: foldername.replace('bar', 'BAR')<br />
<br />
[Repository foo-remote]<br />
nametrans = lambda foldername: foldername.replace('BAR', 'bar')<br />
</nowiki><br />
}}<br />
<br />
* For working out the correct inverse mapping. the output of {{Ic|offlineimap --info}} should help.<br />
* After updating the mapping, it may be necessary to remove all of the folders under {{Ic|$HOME/.offlineimap/}} for the affected accounts.<br />
<br />
===SSL fingerprint does not match===<br />
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.<br />
<br />
To solve this, add to {{ic|~/.offlineimaprc}} (in the same section as {{ic|1=ssl = yes}}) one of the following:<br />
* either add {{ic|cert_fingerprint}}, with the certificate fingerprint of the remote server. This checks whether the remote server certificate matches the given fingerprint.<br />
cert_fingerprint = keykeykey<br />
* 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.<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
<br />
==External links==<br />
* [http://lists.alioth.debian.org/mailman/listinfo/offlineimap-project Official OfflineIMAP mailing list]<br />
* [http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html Gnus, Dovecot, OfflineIMAP, search: a HOWTO]<br />
** 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)<br />
* [http://pbrisbin.com/posts/mutt_gmail_offlineimap/ Mutt + Gmail + Offlineimap]<br />
** An outline of brisbin's simple gmail/mutt setup using cron to keep offlineimap syncing.<br />
* [https://github.com/OfflineIMAP/offlineimap Current OfflineIMAP maintainer's fork on GitHub]<br />
** Note that a strict build of this on current Arch will fail due to python references unless they are replaced with python2</div>Copycat-killerhttps://wiki.archlinux.org/index.php?title=OfflineIMAP&diff=272021OfflineIMAP2013-08-21T18:14:45Z<p>Copycat-killer: added gnome keyring alternative script for those who use gnome-keyring-query, because it's simpler that way</p>
<hr />
<div>[[Category:Email Client]]<br />
{{Article summary start|Related}}<br />
{{Article summary wiki|isync}}<br />
{{Article summary wiki|notmuch}}<br />
{{Article summary wiki|msmtp}}<br />
{{Article summary end}}<br />
[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]].<br />
==Installing==<br />
Install {{pkg|offlineimap}} from the [[official repositories]]<br />
<br />
==Configuring==<br />
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]]).<br />
<br />
Copy one of the default configuration files to {{ic|~/.offlineimaprc}}.<br />
<br />
{{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.}}<br />
<br />
===Minimal===<br />
The following file is a commented version of {{ic|offlineimap.conf.minimal}}.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# List of accounts to be synced, separated by a comma.<br />
accounts = main<br />
<br />
[Account main]<br />
# Identifier for the local repository; e.g. the maildir to be synced via IMAP.<br />
localrepository = main-local<br />
# Identifier for the remote repository; i.e. the actual IMAP, usually non-local.<br />
remoterepository = main-remote<br />
# Status cache. Default is plain, which eventually becomes huge and slow.<br />
status_backend = sqlite<br />
<br />
[Repository main-local]<br />
# Currently, offlineimap only supports maildir and IMAP for local repositories.<br />
type = Maildir<br />
# Where should the mail be placed?<br />
localfolders = ~/Maildir<br />
<br />
[Repository main-remote]<br />
# Remote repos can be IMAP or Gmail, the latter being a preconfigured IMAP.<br />
type = IMAP<br />
remotehost = host.domain.tld<br />
remoteuser = username<br />
</nowiki><br />
}}<br />
<br />
==Usage==<br />
Before running offlineimap, create any parent directories that were allocated to local repositories:<br />
$ mkdir ~/Maildir<br />
<br />
Now, run the program:<br />
$ offlineimap<br />
<br />
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.<br />
<br />
==Miscellaneous==<br />
''Various settings and improvements''<br />
<br />
===Running offlineimap in the background===<br />
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.<br />
<br />
Confusingly, they are spread thin all-over the configuration file:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
# In the general section<br />
[general]<br />
# Controls how many accounts may be synced simultaneously<br />
maxsyncaccounts = 1<br />
<br />
# In the account identifier<br />
[Account main]<br />
# Minutes between syncs<br />
autorefresh = 5<br />
# Number of quick-syncs between autorefreshes. Quick-syncs do not update if the<br />
# only changes were to IMAP flags<br />
quick = 10<br />
<br />
# In the remote repository identifier<br />
[Repository main-remote]<br />
# Instead of closing the connection once a sync is complete, offlineimap will<br />
# send empty data to the server to hold the connection open. A value of 60<br />
# attempts to hold the connection for a minute between syncs (both quick and<br />
# autorefresh).This setting has no effect if autorefresh and holdconnectionopen<br />
# are not both set.<br />
keepalive = 60<br />
# OfflineIMAP normally closes IMAP server connections between refreshes if<br />
# the global option autorefresh is specified. If you wish it to keep the<br />
# connection open, set this to true. This setting has no effect if autorefresh<br />
is not set.<br />
holdconnectionopen = yes<br />
</nowiki><br />
}}<br />
<br />
====systemd Service====<br />
Writing a systemd service for offlineimap is trivial, just be sure to run it as the correct user by replacing the {{ic|User&#61;UserToRunAs}} with your user. (e.g. {{ic|User&#61;wgiokas}})<br />
{{hc|offlineimap-user.service|2=<br />
<nowiki><br />
[Unit]<br />
Description=Start offlineimap as a daemon<br />
Requires=network.target<br />
After=network.target<br />
<br />
[Service]<br />
User=UserToRunAs<br />
ExecStart=/usr/bin/offlineimap<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki><br />
}}<br />
<br />
====cron job====<br />
1. Configure background jobs as shown in [[#Running offlineimap in the background]].<br />
<br />
2. Use a log-friendly user interface:<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[general]<br />
# This will suppress anything but errors<br />
ui = quiet<br />
</nowiki><br />
}}<br />
<br />
3. Write a wrapper script for [[daemon]]izing programs, or use the one shown below:<br />
{{hc|/usr/local/bin/start_daemon|2=<br />
<nowiki><br />
#!/bin/sh<br />
<br />
set -efu<br />
<br />
ionice_class=<br />
ionice_priority=<br />
nice=<br />
<br />
while getopts c:p:n: f; do<br />
case $f in<br />
c) ionice_class=$OPTARG;;<br />
p) ionice_priority=$OPTARG;;<br />
n) nice=$OPTARG;;<br />
*) exit 2;;<br />
esac<br />
done<br />
shift $((OPTIND - 1))<br />
<br />
cmd=$*<br />
io=<br />
<br />
if pgrep -u "$(id -u)" -xf -- "$cmd" >/dev/null 2>&1; then<br />
exit 0<br />
fi<br />
<br />
if type ionice >/dev/null 2>&1; then<br />
[ -n "$ionice_class" ] && { io=1; cmd="-c $ionice_class $cmd"; }<br />
[ -n "$ionice_priority" ] && { io=1; cmd="-n $ionice_priority $cmd"; }<br />
[ -n "$io" ] && cmd="ionice $cmd"<br />
fi<br />
<br />
if type nice >/dev/null 2>&1; then<br />
[ -n "$nice" ] && cmd="nice -n $nice $cmd"<br />
fi<br />
<br />
exec $cmd<br />
</nowiki><br />
}}<br />
<br />
4. Finally, add a crontab entry:<br />
$ crontab -e<br />
The line should specify the interpreter for correct {{Ic|pgrep -xf}} results:<br />
*/5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap<br />
<br />
<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><br />
<br />
===Automatic mutt mailbox generation===<br />
[[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.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[mbnames]<br />
enabled = yes<br />
filename = ~/.mutt/mailboxes<br />
header = "mailboxes "<br />
peritem = "+%(accountname)s/%(foldername)s"<br />
sep = " "<br />
footer = "\n"<br />
</nowiki><br />
}}<br />
<br />
Then add {{Ic|source ~/.mutt/mailboxes}} to {{ic|~/.mutt/muttrc}}.<br />
<br />
===Gmail configuration===<br />
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:<br />
<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository gmail-remote]<br />
type = Gmail<br />
remoteuser = user@gmail.com<br />
remotepass = password<br />
nametrans = lambda foldername: re.sub ('^\[gmail\]', 'bak',<br />
re.sub ('sent_mail', 'sent',<br />
re.sub ('starred', 'flagged',<br />
re.sub (' ', '_', foldername.lower()))))<br />
folderfilter = lambda foldername: foldername not in '[Gmail]/All Mail'<br />
# Necessary as of OfflineIMAP 6.5.4<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
</nowiki><br />
}}<br />
<br />
{{Note|If you have Gmail set to another language, the folder names may appear translated too, e.g. "verzonden_berichten" instead of "sent_mail".}}<br />
<br />
{{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.}}<br />
<br />
{{Note|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]]).}}<br />
<br />
===Not having to enter the password all the time===<br />
====.netrc====<br />
Add the following lines to your {{ic|~/.netrc}}:<br />
<br />
machine hostname.tld<br />
login [your username]<br />
password [your password]<br />
<br />
Don't forget to give the file appropriate rights like 600 or 700:<br />
chmod 600 ~/.netrc<br />
<br />
====Gnome Keyring====<br />
http://www.clasohm.com/blog/one-entry?entry_id=90957 gives an example of how to use gnome-keyring to store the password. <br />
<br />
In the example, functions from a python file are imported in order to get passwords from gnome-keyring.<br />
<br />
Alternatively, if youre using {{AUR|gnome-keyring-query}} from AUR, you can use this simpler script instead:<br />
<br />
#!/usb/bin/python<br />
# executes gnome-keyring-query get passwd<br />
# and returns the output<br />
<br />
import locale<br />
from subprocess import Popen, PIPE<br />
<br />
encoding = locale.getdefaultlocale()[1]<br />
<br />
def get_password(p):<br />
(out, err) = Popen(["gnome-keyring-query", "get", p], stdout=PIPE).communicate()<br />
return out.decode(encoding).strip()<br />
<br />
====python2-keyring====<br />
There's 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:<br />
<br />
{{bc|1=<br />
[general]<br />
pythonfile = /home/user/offlineimap.py<br />
…<br />
[Repository RemoteEmail]<br />
remoteuser = username@host.net<br />
remotepasseval = keyring.get_password("offlineimap","username@host.net")<br />
…<br />
}}<br />
<br />
and somewhere in ~/offlineimap.py add {{ic|import keyring}}. Now all you have to do is set your password, like so:<br />
<br />
{{bc|$ python2 <br />
>>> import keyring<br />
>>> keyring.set_password("offlineimap","username@host.net", "MYPASSWORD")}}<br />
<br />
and it'll grab the password from your (kwallet/gnome-) keyring instead of having to keep it in plaintext or enter it each time.<br />
<br />
====Emacs EasyPG====<br />
See http://www.emacswiki.org/emacs/OfflineIMAP#toc2<br />
<br />
===Kerberos authentication===<br />
Install python2-kerberos from [https://aur.archlinux.org/packages.php?ID=50639 AUR] and do not specify remotepass in your .offlineimaprc. <br />
OfflineImap figure out the reset all if have a valid Kerberos TGT. <br />
If you have 'maxconnections', it will fail for some connection. Comment 'maxconnections' out will solve this problem.<br />
<br />
==Troubleshooting==<br />
<br />
===Overriding UI and autorefresh settings===<br />
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:<br />
$ offlineimap [ -o ] [ -d <debug_type> ] [ -u <ui> ]<br />
;-o<br />
:Disable autorefresh, keepalive, etc.<br />
<br />
;-d <debug_type><br />
:Where ''<debug_type>'' is one of {{Ic|imap}}, {{Ic|maildir}} or {{Ic|thread}}. Debugging imap and maildir are, by far, the most useful.<br />
<br />
;-u <ui><br />
:Where ''<ui>'' is one of {{Ic|CURSES.BLINKENLIGHTS}}, {{Ic|TTY.TTYUI}}, {{Ic|NONINTERACTIVE.BASIC}}, {{Ic|NONINTERACTIVE.QUIET}} or {{Ic|MACHINE.MACHINEUI}}. TTY.TTYUI is sufficient for debugging purposes.<br />
<br />
{{Note|More recent versions use the following for <ui>: {{Ic|blinkenlights}}, {{Ic|ttyui}}, {{Ic|basic}}, {{Ic|quiet}} or {{Ic|machineui}}.}}<br />
<br />
===netrc authentication===<br />
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).<br />
Using the package you can collect all passwords in {{ic|~/.netrc}}. And do not forget to set it's access rights:<br />
chmod 600 ~/.netrc<br />
An example netrc file would be<br />
{{hc|~/.netrc|<br />
machine mail.myhost.de<br />
login mr_smith<br />
password secret<br />
}}<br />
<br />
===Folder could not be created===<br />
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].<br />
<br />
This can lead to errors of the following form when using {{Ic|nametrans}} on the remote repository:<br />
ERROR: Creating folder bar on repository foo-remote<br />
Folder 'bar'[foo-remote] could not be created. Server responded: ('NO', ['[ALREADYEXISTS] Duplicate folder name bar (Failure)'])<br />
<br />
The solution is to provide an inverse {{Ic|nametrans}} lambda for the local repository, e.g.<br />
{{hc|~/.offlineimaprc|2=<br />
<nowiki><br />
[Repository foo-local]<br />
nametrans = lambda foldername: foldername.replace('bar', 'BAR')<br />
<br />
[Repository foo-remote]<br />
nametrans = lambda foldername: foldername.replace('BAR', 'bar')<br />
</nowiki><br />
}}<br />
<br />
* For working out the correct inverse mapping. the output of {{Ic|offlineimap --info}} should help.<br />
* After updating the mapping, it may be necessary to remove all of the folders under {{Ic|$HOME/.offlineimap/}} for the affected accounts.<br />
<br />
===SSL fingerprint does not match===<br />
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.<br />
<br />
To solve this, add to {{ic|~/.offlineimaprc}} (in the same section as {{ic|1=ssl = yes}}) one of the following:<br />
* either add {{ic|cert_fingerprint}}, with the certificate fingerprint of the remote server. This checks whether the remote server certificate matches the given fingerprint.<br />
cert_fingerprint = keykeykey<br />
* 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.<br />
sslcacertfile = /etc/ssl/certs/ca-certificates.crt<br />
<br />
==External links==<br />
* [http://lists.alioth.debian.org/mailman/listinfo/offlineimap-project Official OfflineIMAP mailing list]<br />
* [http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html Gnus, Dovecot, OfflineIMAP, search: a HOWTO]<br />
** 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)<br />
* [http://pbrisbin.com/posts/mutt_gmail_offlineimap/ Mutt + Gmail + Offlineimap]<br />
** An outline of brisbin's simple gmail/mutt setup using cron to keep offlineimap syncing.<br />
* [https://github.com/OfflineIMAP/offlineimap Current OfflineIMAP maintainer's fork on GitHub]<br />
** Note that a strict build of this on current Arch will fail due to python references unless they are replaced with python2</div>Copycat-killer