Make SIGHUP singal handler equivalent to SIGTERM and SIGINT.

offlineimap has several frontends that encourage running it from a
terminal under an X session. When X session closes for a system
shutdown, the terminals exit, after sending SIGHUP to their children.

Previously SIGHUP was treated to be equivalent to SIGUSR1, i.e. wake
up and sync all accounts. This causes delays during shutdown.

According to Wikipedia [0], SIGHUP has been repurposed from a
historical meaning to one of:
 * re-read configuration files, or reinitialize (e.g. Apache, sendmail)
 * controlling pseudo or virtual terminal has been closed

I believe second meaning is more appropriate for offlineimap, and
hence this patch makes SIGHUP to be handled in the same way SIGTERM
and SIGINT are handled.

[0] http://en.wikipedia.org/wiki/SIGHUP

Debian-Bug: http://bugs.debian.org/670120
Reported-By: Steve Langasek <steve.langasek@canonical.com>
Signed-off-by: Dmitrijs Ledkovs <xnox@debian.org>
Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
Implement stack trace dump for all running threads on SIGQUIT

This is handy when we're debugging the thread locks: we can try to
understand which thread does what and how it was called.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
Add offlineimap.utils to the list of our modules

Forgot to do it while was adding stacktrace support.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
And add forgotten __init__.py for offlineimap.utils

I should learn to check my commits when rebasing and reordering.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
Fix deadlock for IMAP folder synced in singlethreaded mode

The problem lies in the fact that offlineimap.folder.Base's method
syncmessagesto_copy() uses threaded code everytime it is suggested by
the derived class's suggeststhreads() (currently, only IMAP does this
suggestion), but offlineimap/init.py will not spawn the
exitnotifymonitorloop() from offlineimap.threadutil.

The root cause is that ExitNotifyThread-derived threads need
offlineimap.threadutil's exitnotifymonitorloop() to be running the
cleaner for the exitthreads Queue(), because it fills the queue via
the run() method from this class: it wants to put() itself to the
Queue on exit, so when no exitnotifymonitorloop() is running, the
queue will fill up.  And if this thread is an instance of
InstanceLimitedThread that hits the limit on the number of threads,
then it will hold the instancelimitedsems[] semaphore will prevent
other InstanceLimitedThread()s of the same name to pass its start()
method.

The fix is to avoid using threaded code if we're running
single-threaded.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
Obtained-from: X-Ryl669 <boite.pour.spam@gmail.com>
Create global instance of command-line options

This eases testing of option values inside the code.  This instance
is implemented as the read-only copy of the obtained 'options' object,
so callers won't be able to modify its contents.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
IMAP class: don't suggest multithreading in single-threaded mode

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
Don't fail if no dry-run setting has been specified

Somehow we failed if no dry-run setting had been specified in the config
file. This got caught thanks to extending the test suite with a stock
configuration.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
change_message_uid did not update messagelist's filename

This broke code that relied on the filename being up to date in memory after
messages are copied.
Changed NotImplementedException to NotImplementedError

It seems NotImplementedException does not exist. It must be a relic from old
python...
Enable compressed connections to the IMAP server

Added the configuration setting usecompression for the IMAP repositories.
When enabled, the data from and to the IMAP server is compressed.
Restructured folder.IMAP code

Preparing for a sequence of commits implementing gmail label sync, I have split
some functions so I will be able to change some functionality in folder.Gmail,
with less code repetition.

Also added some functions to folder.base and imaputil I will later need.
Adds labels and mtime to LocalStatus Sqlite table

Adds two columns to the LocalStatus Sqlite table:
  * labels: A comma separated list of labels, to be used by Gmail folder.
  * mtime: The POSIX modification time for the message in a local Maildir.

The interface for the class LocalStatusSQLite remains compatible with what it
was (i.e. new arguments to functions are optional with default values).
Make GmailFolder sync gmail labels

When synclabels config flag is set to "yes" for the gmail repo, offlineimap
fetches the message labels along with the messages, and embeds them into the
body under the header X-Keywords, as a comma separated list.

The configuration option labelsheader allows to change that header under which
labels are stored. X-Keywords is a useful choice as some mail programs may
recognize it.

It also adds an extra pass to savemessageto, that performs label synchronization
on existing messages from gmail to local, the same way it is done with flags.

The ignorelabels configuration seting contains is a list of comma separated
labels that will be left alone. They will not be added nor removed from any
message.
Implements a GmailMaildir repository

The GmailMaildir repository adds functionality to change message labels. Also
keeps track of messages modification time, so that it can quickly detect when
the labels may have changed.
Added a filterheaders option

When filterheaders is set to a comma-separated list of headers, offlineimap
removes those headers from messages before uploading them to the server.
Update documentation with the recent gmail changes
fixed re.sub call, that was using python 2.7 features.
fixes setting labels on new local messages

This fixes a bug, that would crash offlineimap when:
  - synclabels is enabled
  - there is a new local message not present on gmail
  - the new local message has embedded labels

In this case, the label sync would use the wrong uid and crash. In particular,
this happens when moving messages between different folders "the IMAP way",
instead of changing labels.
Better handling of gmail labels header

In particular, now formats X-Label and Keywords as a space separated list
instead of comma separated list.