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>
Fix str.format() calls for Python 2.6.

Python 2.6 requires a slightly different string formatting that >2.7.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Remove the APPENDUID hack, previously introduced

As Gmail was only announcing the presence of the UIDPLUS extension
after we logged in, and we were then only getting server
capabilities before, a hack was introduced that checked the
existence of an APPENDUID reply, even if the server did not claim
to support it.

However, John Wiegley reports problems, where the APPENDUID would
be None, and we attempt to go this path (it seems that imaplib2
returns [None] if there is no such reply, so our test here for "!="
might fail. Given that this is an undocumented imaplib2 function
anyway, and we do fetch gmail capabilities after authentication,
this hack should no longer be necessary.

We had problems there earlier, where imapobj.response() would
return [None] although we had received a APPENDUID response from
the server, this might need more debugging and testing.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Add missing OfflineImapError import in folder/UIDMaps.py

Bug-Debian: http://bugs.debian.org/671279
Reported-by: Ansgar Burchardt <ansgar@debian.org>
Signed-off-by: Dmitrijs Ledkovs <xnox@debian.org>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
docs: split long lines (up to 80 characters)

Not everybody has a wide screen.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
IMAPlib mixin class: pass 'readonly' exception to our callers

This will allow our callers who are capable of dealing with
readonly folders to properly detect this condition and act
accordingly.

One example is Gmail's "Chats" folder that is read-only,
but contains logs of the quick chats.

Minor Changelog improvements.

Tested-by: Abdó Roig-Maranges <abdo.roig@gmail.com>
Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
docs: update links to the newly created github organization

Acually, these are the minimal expected changes.
More might be done and/or discussed.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
fix: createfolders setting is ignored if readonly is True

If 'readonly' is True, folders shouldn't be created (regardless of
'createfolders' option). With old behavior, instead folders were always created
when 'readonly' is True (even if 'createfolders' was also False), which is a
serious bug (offlineimap was creating folders in all read-only repositories).
'createfolders' should only play a role if 'readonly' is False, in which case
folders should only be created if 'createfolders' is True.

Submitted-by: Vladimir Nesov <robotact@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
Improve 'find first quotation' regex

Reported by http://www.dfranke.com/blog/2012/08/20/offlineimap-error-beim-syncen-mit-lotus-domino/
our 'find the first quote possible containing encoded quotation
marks' regex did not seem to have caught all cases. E.g. "\\".

Verified the fix as good. Thanks Daniel Franke.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Fix cut-off line

Commit 6e5fbebc introduced a cut-off line. Fixing that.
All tests ran successfully.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Throw OfflineImapErrors rather than weird Exceptions

When misconfiguring OLI, e.g. by specifying a repository name that was
not configured anywhere, we would bomb out with cryptic "NoSectionError".
Throw OfflineImapError that explains what has happened. We still need to
avoid throwing exceptions with Tracebacks here though.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Exit with nice error message failing to get repositories

If we throw an OfflineImapError in case of the Repository()
initialization, we display the nice error message and exit rather
than bomb out with a traceback. Misconfiguring a repository name in
the configuration file is now nicely pointed out to the user.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Use "with lock" pattern

While looking at the code to investigate if an why we sometimes don't
seem to honor the write lock, I made it use the more modern "with lock:"
pattern.

Still have not found out how we could ever be using 2 instances of the
LocalStatusFolder for the same folder.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Don't output initial blurb in "quiet" mode

When logging to a file using the -l switch, we would still write an initial
banner to the file. This was never intended. Quiet should be really quiet
unless it experiences an error. Simplify the logging statement, to do nothing
if logevel is set to "WARNING" aka quiet.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Reuse LocalStatus() folders rather than recreate instances

If we ask twice for a LocalStatusFolder via getfolder(), we would
get a newly created instance each time. This can lead to problems,
as e.g. write locks protecting files only work within the same Folder
instance. Make it so, that we cache all Folder instances that we have
asked for and hand back the existing one if we ask again for it,
rather than recreate a new instance.

Also, make getfolders() a noop for LocalStatus. We attempted to
derive the foldername from the name of the LocalStatusfile. However,
this is not really possible, as we do file name mangling
(".$" -> "dot", "/" -> ".") and there is no way to get the original folder
name from the LocalStatus file name anyway.

This commit could potentially solve the "file not found" errors, that people
have been seeing with their LocalStatusCache files. If we have 2
instances of a LocalStatusFolder pointing to the same file, our locking
system would not work.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Combine checks for ignored folders in one place

 - Factor out the code to find a local folder given a remote folder

Patch by Dave, split and modified by Sebastian.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Determine folder syncing on Folder initialization

Rather than later when retrieving them by IMAP, we determine the
"sync_this" value of a folder on Folder() initialization.

This also fixes a bug where folder structure was not propagated when
a folder was filtered out but included in the folderincludes list.

Patch by Dave, split and modified slightly by Sebastian

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
No need to filter Maildir folders here

commit e94642bb4d591a1ea12 centralized folder filtering by using the
repository.should_sync_folder() function. Therefore there is no need
to check for folderfilter in the Maildir backend separately.

Origina patch by Dave, split into 3 by Sebastian

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
LocalStatus._folders needs to be {} not None

the LocalStatus._folders cache was changed to be a dict that can be
searched for names. One instance were _folders was set to "None" was
accidentally left over. Fix this.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Fix fallout when filtering folders

Previous commit e7ca5b25cba0679aa800b490d063b24c40864839 combined
checks for filtered folders in one place. However, it turns out there
was a reason to have them separate. getfolder() on a non-existent Maildir
fails and there might not be an equivalent local Maildir folder for a
filtered out IMAP folder.

Fix this by first checking if the remote folder should be filtered, and
only then retrieving the local folder (which should exist then).

This bug was found by our test suite!

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>