https://wiki.archlinux.org/api.php?action=feedcontributions&user=Dastagg&feedformat=atomArchWiki - User contributions [en]2024-03-29T14:23:55ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=OfflineIMAP&diff=147593OfflineIMAP2011-06-29T14:32:18Z<p>Dastagg: Updated user interface names for the -u flag</p>
<hr />
<div>[[Category:Web Server (English)]]<br />
<br />
[http://offlineimap.org/ OfflineIMAP] is an utility to sync mail from IMAP servers. It does not work with the POP3 protocol or mbox, and is usually paired with a MUA such as [[Mutt]].<br />
<br />
As of 06/26/2010, the original author of offlineimap [http://article.gmane.org/gmane.mail.imap.offlineimap.general/1759 ceased development]. A new maintainer has since [http://lists.alioth.debian.org/pipermail/offlineimap-project/2010-November/000286.html stepped forward] and as of 12/16/2010 developed seemed to be active.<br />
<br />
==Installing==<br />
Install the {{package Official|offlineimap}} package with [[pacman]]:<br />
# pacman -S offlineimap<br />
<br />
==Configuring==<br />
The example configuration that is distributed with offlineimap contains every setting and is thorougly documented.<br />
<br />
Copy it to {{filename|~/.offlineimaprc}} and edit it:<br />
$ cp /usr/share/offlineimap/offlineimap.conf ~/.offlineimaprc<br />
$ vi ~/.offlineimaprc<br />
<br />
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 />
===Quick-start===<br />
Following is a commented version of {{filename|/usr/share/offlineimap.conf.minimal}}. The setup only contains settings that are absolutely necessary.<br />
{{file|name=~/.offlineimaprc|content=<br />
<nowiki><br />
[general]<br />
# This should contain a comma delimited list of all identifiers of the accounts<br />
# that are to be synced<br />
accounts = main<br />
# If there are two accounts; `main' and `alternative'...<br />
#accounts = main,alternative<br />
<br />
[Account main]<br />
# The identifier for the local repository; e.g., the maildir that offlineimap<br />
# will sync with an IMAP server<br />
localrepository = main-local<br />
# The identifier for the remote repository. This is the actual IMAP, which is<br />
# usually foreign to the system<br />
remoterepository = main-remote<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 />
{{file|name=~/.offlineimaprc|content=<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)<br />
keepalive = 60<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 />
{{file|name=~/.offlineimaprc|content=<br />
<nowiki><br />
[general]<br />
# This will suppress anything but errors<br />
ui = Noninteractive.Quiet<br />
</nowiki><br />
}}<br />
<br />
3. Write a wrapper script for [[daemon]]izing programs, or use the one shown below:<br />
{{file|name=/usr/local/bin/start_daemon|content=<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 {{codeline|pgrep -xf}} results:<br />
*/5 * * * * exec /usr/local/bin/start_daemon -n19 -c2 -p7 python2 /usr/bin/offlineimap <br />
<br />
If you are using offlineimap-git from AUR, you'll want to change python2 to python<br />
<br />
The wrapper script is needed because offlineimap has the tendency to sporadically crash, even more so when facing connection problems.<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 />
{{file|name=~/.offlineimaprc|content=<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 {{codeline|source ~/.mutt/mailboxes}} to {{filename|~/.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 />
{{file|name=~/.offlineimaprc|content=<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 />
</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 />
===Not having to enter the password all the time===<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 />
: Anyone know whether this is possible with KDE wallets?<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 {{codeline|imap}}, {{codeline|maildir}} or {{codeline|thread}}. Debugging imap and maildir are, by far, the most useful.<br />
<br />
;-u <ui><br />
:Where ''<ui>'' is one of {{codeline|CURSES.BLINKENLIGHTS}}, {{codeline|TTY.TTYUI}}, {{codeline|NONINTERACTIVE.BASIC}}, {{codeline|NONINTERACTIVE.QUIET}} or {{codeline|MACHINE.MACHINEUI}}. TTY.TTYUI is sufficient for debugging purposes.<br />
<br />
{{Note|More recent versions use the following for <ui>: {{codeline|blinkenlights}}, {{codeline|ttyui}}, {{codeline|basic}}, {{codeline|quiet}} or {{codeline|machineui}}.}}<br />
<br />
===Curses interface (Curses.Blinkenlights) locks terminal===<br />
Because of a bug in Python's ncurses package (http://bugs.python.org/issue7567) the Curses interface of OfflineIMAP breaks the terminal on exit.<br />
While it appears to irreparably lock the terminal, in reality it only prevents commands from being displayed.<br />
The bug has been fixed in Python's SVN for all versions 2.6 up to 3.2 but the current package in the repositories (Python 2.6.5) is still buggy.<br />
<br />
In order to solve the issue:<br />
*either append {{codeline|reset}} to OfflineIMAP's launch command:<br />
$ offlineimap; reset<br />
*or change the {{codeline|ui}} field in {{filename|~/.offlineimaprc}} to select a fully functional one:<br />
ui = TTY.TTYUI<br />
*or as quick workaround you can just use the following command to skip the reset() function in Curses.py which causes the problem<br />
# sed -i '125i\ \ \ \ \ \ \ \ return' /usr/lib/python2.6/site-packages/offlineimap/ui/Curses.py<br />
<br />
===netrc authentication===<br />
There are some bugs in the current {{Package Official|offlineimap}} which makes it impossible to read the authentication data from {{Filename|~/.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 {{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 {{Filename|~/.netrc}}. And don't forget to set it's access rights:<br />
chmod 600 ~/.netrc<br />
An example netrc file would be<br />
{{file|name=~/.netrc|content=<br />
machine mail.myhost.de<br />
login mr_smith<br />
password secret<br />
}}<br />
<br />
===socket.ssl deprecation warnings===<br />
Depending on the currently installed python version, running offlineimap throws this warning:<br />
DeprecationWarning: socket.ssl() is deprecated. Use ssl.wrap_socket() instead.<br />
<br />
This can be particularly annoying when offlineimap's output is being logged or mailed through [[cron]].<br />
<br />
To fix the problem, apply this [http://github.com/jgoerzen/offlineimap/commit/a7810166335bb0e6f5c7dab26adf707c38adf6ff upstream] patch or install {{Package AUR|offlineimap-git}}:<br />
<pre><br />
--- offlineimap/imaplibutil.py.orig 2009-08-12 01:24:23.000000000 -0430<br />
+++ offlineimap/imaplibutil.py 2010-06-07 11:17:37.849038683 -0430<br />
@@ -23,9 +23,11 @@<br />
# Import the symbols we need that aren't exported by default<br />
from imaplib import IMAP4_PORT, IMAP4_SSL_PORT, InternalDate, Mon2num<br />
<br />
-# ssl is new in python 2.6<br />
-if (sys.version_info[0] == 2 and sys.version_info[1] >= 6) or sys.version_info[0] >= 3:<br />
+try:<br />
import ssl<br />
+ ssl_wrap = ssl.wrap_socket<br />
+except ImportError:<br />
+ ssl_wrap = socket.ssl<br />
<br />
class IMAP4_Tunnel(IMAP4):<br />
"""IMAP4 client class over a tunnel<br />
@@ -169,7 +171,7 @@<br />
if last_error != 0:<br />
# FIXME<br />
raise socket.error(last_error)<br />
- self.sslobj = socket.ssl(self.sock, self.keyfile, self.certfile)<br />
+ self.sslobj = ssl_wrap(self.sock, self.keyfile, self.certfile)<br />
self.sslobj = sslwrapper(self.sslobj)<br />
<br />
mustquote = re.compile(r"[^\w!#$%&'+,.:;<=>?^`|~-]")<br />
</pre><br />
<br />
The diff is relative to the root buildir and it can be applied by using [[ABS]].<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 <code>mail_location = maildir:~/Maildir</code> to <code>/etc/dovecot/dovecot.conf</code>. 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/nicolas33/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>Dastagg