root / offlineimap / init.py

init.py

View | Annotate | Download (8.5 KB)

# Date Author Comment
e1fb9492 12/01/2008 04:13 PM John Goerzen

Patch for signal handling to start a sync by Jim Pryor
Here's the way I'd like to use offlineimap on my laptop:
1. Have a regular cron job running infrequently. The cron job
checks to see
if I'm online, plugged in, and that no other copy of offlineimap is
running. If
all of these conditions are satisfied, it runs offlineimap just once:
"offlineimap -o -u Noninteractive.Quiet" until cron-started copies of offlineimap have finished, then starts
offlineimap
on its regular, stay-alive and keep checking schedule. When I quit
mutt, the
wrapper script tells offlineimap to stop.

2. When I start up mutt, I do it by calling a wrapper script that
delays

This way I get frequent regular checks while I have mutt running, but
I don't
waste my battery/cpu checking frequently for mail when I'm not
interested in
it.

To make this work, though, it'd be nicer if it were easier to tell
offlineimap,
from the outside, things like "terminate cleanly now" and "when you've
finished
synching, then terminate instead of sleeping and synching again."

OK, to put my money where my mouth is, I attach two patches against
offlineimap
6.0.3.

The first, "cleanup.patch", cleans up a few spots that tend to throw
exceptions
for me as offlineimap is exiting from a KeyboardInterrupt.

The second adds signaling capabilities to offlineimap.

  • sending a SIGTERM tells offlineimap to terminate immediately but
    cleanly,
    just as if "q" had been pressed in the GUI interface
  • sending a SIGUSR1 tells every account to do a full sync asap: if
    it's
    sleeping, then wake up and do the sync now. If it's mid-sync, then
    re-synch
    any folders whose syncing has already been started or completed, and
    continue
    to synch the other, queued but not-yet-synched folders.
  • sending a SIGHUP tells every account to die as soon as it can (but
    not
    immediately: only after finishing any synch it's now engaged in)
  • sending a SIGUSR2 tells every account to do a full sync asap (as
    with
    SIGUSR1), then die

It's tricky to mix signals with threads, but I think I've done this
correctly.
I've been using it now for a few weeks without any obvious
problems. But I'm passing it
on so that others can review the code and test it out on their
systems. I developed the
patch when I was running Python 2.5.2, but to my knowledge I don't use
any Python 2.5-specific
code. Now I'm using the patch with Python 2.6.

Although I said "without any obvious problems," let me confess that
I'm
seeing offlineimap regularly choke when I do things like this: start
up
my offlineimap-wrapped copy of mutt, wait a while, put the machine to
sleep (not sure if offlineimap is active in the background or idling),
move to a different spot, wake the machine up again and it acquires a
new network, sometimes a wired network instead of wifi. Offlineimap
doesn't like that so much. I don't yet have any reason to think the
problems here come from my patches. But I'm just acknowledging them,
so
that if others are able to use offlineimap without any difficulty in
situations like I described, then maybe the fault is with my patches.

04a62700 08/07/2008 09:16 PM Ben Willard

Fix a bug preventing the pid file from being empty.

Convert os.getpid() to a string before writing it to the pid file in
order to avoid generating an empty pid file.

ec89c3eb 01/03/2008 04:15 AM Riccardo Murri

Add option '-f' for sync'ing only selected folders

2985ddc6 01/03/2008 04:13 AM Riccardo Murri

Add option '-k' for overriding config options

3305d8cd 10/01/2007 10:20 PM John Goerzen

Daniel Jacobowitz patches

fixes deb#433732

Date: Sun, 30 Sep 2007 13:54:56 -0400
From: Daniel Jacobowitz <>
To:
Subject: Assorted patches

Here's the result of a lazy Sunday hacking on offlineimap. Sorry for
not breaking this into multiple patches. They're mostly logically
independent so just ask if that would make a difference.
First, a new -q (quick) option. The quick option means to only update
folders that seem to have had significant changes. For Maildir, any
change to any message UID or flags is significant, because checking
the flags doesn't add a significant cost. For IMAP, only a change to
the total number of messages or a change in the UID of the most recent
message is significant. This should catch everything except for
flags changes.

The difference in bandwidth is astonishing: a quick sync takes 80K
instead of 5.3MB, and 28 seconds instead of 90.

There's a configuration variable that lets you say every tenth sync
should update flags, but let all the intervening ones be lighter.

Second, a fix to the UID validity problems many people have been
reporting with Courier. As discussed in Debian bug #433732, I changed
the UID validity check to use SELECT unless the server complains that
the folder is read-only. This avoids the Courier bug (see the Debian
log for more details). This won't fix existing validity errors, you
need to remove the local status and validity files by hand and resync.

Third, some speedups in Maildir checking. It's still pretty slow
due to a combination of poor performance in os.listdir (never reads
more than 4K of directory entries at a time) and some semaphore that
leads to lots of futex wake operations, but at least this saves
20% or so of the CPU time running offlineimap on a single folder:

Time with quick refresh and md5 in loop: 4.75s user 0.46s system 12%
cpu 41.751 total
Time with quick refresh and md5 out of loop: 4.38s user 0.50s system
14% cpu 34.799 total
Time using string compare to check folder: 4.11s user 0.47s system 13%
cpu 34.788 total

And fourth, some display fixes for Curses.Blinkenlights. I made
warnings more visible, made the new quick sync message cyan, and
made all not explicitly colored messages grey. That last one was
really bugging me. Any time OfflineIMAP printed a warning in
this UI, it had even odds of coming out black on black!

Anyway, I hope these are useful. I'm happy to revise them if you see
a problem.

--
Daniel Jacobowitz
CodeSourcery

09d71143 07/10/2007 12:57 PM John Goerzen

Fix version.py importing

acc597ff 07/07/2007 01:50 AM John Goerzen

Write current PID to ~/.offlineimap/pid

fixes deb#217550
refs deb#410181

f0d48365 07/06/2007 05:37 PM John Goerzen

Added timeouts

abf9648f 07/04/2007 06:53 PM John Goerzen

Clean up imaplib imports

71c8b2e7 12/11/2006 06:12 AM aaron

Configurable thread status character for ui.Curses.Blinkenlights

dc8f3c94 12/01/2006 11:59 AM Daniel Burrows

Add a try: block to catch exceptions that occur before the main loop and to call ui.mainException().

I'm not sure if this is the "right" way to handle exceptions, but it does
correctly print the error message AFTER shutting down curses for me.

c7894a01 12/01/2006 11:54 AM Daniel Burrows

Instead of blowing up when the account name is missing, display a useful error message that gives the correct account names.

39a18fef 08/12/2006 05:15 AM John Goerzen

Update FSF address

d839be3c 04/16/2005 08:33 PM John Goerzen

Step 2 of SVN to arch tree conversion