Commit Graph

436 Commits

Author SHA1 Message Date
Nicolas Sebrecht 21332efb08 folder: IMAP: fix issue when the response of searchforheaders is the same UID multiple times
When the IMAP server doesn't support the UIDPLUS extension so we fallback on the
internal legacy way of mapping the UID to the uploaded message (with the email
header). If the server responds with 2 UIDs offlineimap doesn't know which one
is correct and reports an error.

If for some reason all the returned UIDs are equals it's very likely fine to
map either one.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
Tested-by: https://github.com/mpsq
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/676
2020-07-22 22:31:01 +02:00
Nicolas Sebrecht fc61c6fd30 Gmail: allow parenthesis in labels
Reported-by Heinrich Hartmann <Heinrich@HeinrichHartmann.com>
Tested-by Heinrich Hartmann <Heinrich@HeinrichHartmann.com>
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/545
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2018-05-18 02:10:56 +02:00
Eygene Ryabinkin 3a807d0f2b Create filenames with no path separators in them
We use current hostname as the element of the unique file name.
Sometimes there is non-/24 zone delegation,
{{{
$ host 144.206.233.65
65.233.206.144.in-addr.arpa is an alias for 65.26/64.233.206.144.in-addr.arpa.
}}}
as per RFC 2317,
  https://www.rfc-editor.org/rfc/rfc2317.txt

So on Un*x systems we may run into having path separator inside
the file name.  Not good, things will choke.  Prevented this
by substituting all appeared path separators in the return value.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
Tested-at: my MacOSX instance, my FreeBSD instances
2018-04-09 20:09:56 +03:00
Nicolas Sebrecht e802f5fbd5 folder: IMAP: improve search logging
Log when exception occured during search command, too.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/512
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-12-22 15:13:51 +01:00
John Ferlito 3c6b07b25f Add missing space to output string
It was previously printing "Upgrading LocalStatus cache from version 1to version 2 for XXX"

Signed-off-by: John Ferlito <johnf@inodes.org>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-11-26 18:05:10 +01:00
Nicolas Sebrecht 9805d3e7af no UIDPLUS: improve logging on failures
When there is not UIDPLUS we have to figure the UID by our means. When this
process fails, we don't know if the email was successfully uploaded. This patch
provides better logs to explain what happened.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-11-12 22:40:06 +01:00
Nicolas Sebrecht 5836970d51 utf8foldernames: fix missing decode argument
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/502
Tested-by: https://github.com/pprw
Reviewed-by: Ilias Tsitsimpis <i.tsitsimpis@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-10-29 00:45:32 +02:00
Urs Liska ef3299b7ce Remove some unnecessary whitespace (in existing code)
Addresses https://github.com/OfflineIMAP/offlineimap/pull/498#discussion_r141672756

Signed-off-by: Urs Liska <git@ursliska.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-10-02 21:09:43 +02:00
Urs Liska 36d726763d utf8: implement utf8foldernames option
If utf8foldernames is enabled on account level all folder names read
from the IMAP server will immediately be reencoded to UTF-8. Names
will be treated as UTF-8 as long as the IMAP server isn't contacted again,
for which they are reencoded to IMAP4-UTF-7.

This means that any further processing such as nametrans, folderfilter
etc. will act upon the UTF-8 names, which will have to be documented
carefully.

NOTE 1:
GMail repositories and folders inherit from the IMAP... classes, so I don't
know yet if these changes have ugly side-effects. But web research suggests
that GMail IMAP folders are equally encoded in UTF-7 so that should work
identically here and incorporate the same improvements.

NOTE 2:
I could not test the behaviour with idlefolders as I didn't get this option
to work at all, not even with the latest stable version.

NOTE 3:
I *did* test to sync an IMAP repository against another IMAP repository.

Signed-off-by: Urs Liska <git@ursliska.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-10-02 21:09:43 +02:00
Urs Liska dca5f1846d utf8 (aside): Move code for decodefoldernames
While intending *not* to change the behaviour of the existing
decodefoldernames option this commit transparently improves
the coding.
So far this worked by overriding the folder's getvisiblename() method
which reads self.visiblename from and applies the conversion on
*every* invocation of getvisiblename().
This commit does the calculation once in the IMAPFolder's __init__.

Signed-off-by: Urs Liska <git@ursliska.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-10-02 21:09:43 +02:00
Nicolas Sebrecht 19442d0010 folder: Gmail: fix copyright header
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-08-15 01:24:23 +02:00
Nicolas Sebrecht a5d9edc560 folder: Gmail: remove dead code
The support for the realdelete configuration option was removed because this
could lead to data loss.

See 51728ed to know more.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-08-15 01:19:56 +02:00
Nicolas Sebrecht 6079755b20 sqlite: provide better message error for insert
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/488
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-07-25 11:28:56 +02:00
Nicolas Sebrecht ba47138616 folder/IMAP: introduce dedicated parsing for davmail (not supporting UIDPLUS)
Some returned responses end with ')' rather than 'UID XXX)' as expected.

BTW, a better policy could be to request for the 'X-OfflineIMAP' header only
rather than fetching all the headers and looking for it manually.

Also:
- Strip the output when error occurs: we don't need the full response unless
  'imap' debug mode is enabled.
- Improve the comments.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/479
Tested-by: https://github.com/secomi
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-06-27 20:32:58 +02:00
Nicolas Sebrecht ce83efc3c7 folder/IMAP: improve the warning when we can't parse the returned UID
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/479
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-06-14 09:47:51 +02:00
Nicolas Sebrecht 05ff68c7e1 IMAP/IMAP: continue to sync if the local side does not return a valid UID on upload
There's no reason we should abort the full sync.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/479
Tested-by: https://github.com/secomi
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-06-14 09:12:15 +02:00
Nicolas Sebrecht e8f0e82f6c IMAP: UIDPLUS: correctly warn about weird responses from some servers
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/455
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-04-26 19:39:04 +02:00
Nicolas Sebrecht e9d8e87a71 IMAP: UIDPLUS: improve error message on response error for new UID
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-04-26 18:40:51 +02:00
Nicolas Sebrecht 2c6fac6449 folder/IMAP: improve handling of "matchinguids" error while searching headers
Raise OfflineImapError instead of ValueError.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/452
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-04-07 20:27:39 +02:00
Nicolas Sebrecht ebf5fd527e folder: UIDMaps: ignore KeyError failure while removing keys
This would require more digging to understand how this is possible. I suspect
that a previous run has been interrupted.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/445
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-03-22 14:33:31 +01:00
Nicolas Sebrecht 4df06d57c3 SQLite: avoid concurrent writes on backend migration
The saveall() method must acquire the lock to make writes.

Reported-and-tested-by: Julien Cubizolles <j.cubizolles@free.fr>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-01-31 17:59:25 +01:00
Nicolas Sebrecht ba52030923 folder: IMAP: improve error message when Dovecot returns any data for UID FETCH
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/429
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-01-24 19:11:16 +01:00
Nicolas Sebrecht 6c0828b77c folder: IMAP: add missing whitespace in error message
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2017-01-24 16:08:41 +01:00
lkcl dab5737265 learn repository retrycount configuration option
Allow retrying the download of messages more than twice.

Signed-off-by: Luke Kenneth Casson Leighton <lkcl@lkcl.net>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-12-19 12:55:55 +01:00
Nicolas Sebrecht 04ae3c8dad folder: IMAP: display error message before starting next try
Fetching messages is tried more than once. Display the error message at correct
time.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-11-22 00:58:14 +01:00
Nicolas Sebrecht 01a744a0f8 folder: Maildir: actually try to use Delivery-Date if Date is broken
This value is used to set the timestamp prefix in the filename.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-11-07 23:14:32 +01:00
Nicolas Sebrecht e452c344d9 minor code refactoring
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-11-07 23:03:40 +01:00
Stéphane Albert 2d885fda4c Fix md5 folder generation wanting unicode
Using standard offlineimap without specific utf8 nametrans makes
offlineimap crash when generating md5 of the folder because the
foldername is already an str.

Signed-off-by: Stéphane Albert <sheeprine@oh.its.fake.nullplace.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-11-02 12:24:31 +01:00
Xudong Zhang a92816bd6d fix bug: should not compare list to int
Signed-off-by: Xudong Zhang <felixmelon@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-11-02 05:34:30 +01:00
Giel van Schijndel b6ede627a9 SQLite: make postponing transaction committing possible.
This should significantly improve performance when used to write large
amounts of messages.

This feature is enabled through the fsync configuration option.

Code refactorize around fsync.

This addresses #390 (although it doesn't necessarily fix all instances
of that problem yet).

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/390
Originally-written-by: Giel van Schijndel <me@mortis.eu>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-10-28 20:31:57 +02:00
Nicolas Sebrecht 41c9694488 UIDMaps: ensure we don't update the map file in dry run mode
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/380
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-10-24 20:03:44 +02:00
Nicolas Sebrecht 2ac68d82aa UIDMaps: prevent from leaving a truncated map file
If the map file is not properly written (e.g. due to unexpected kill)
offlineimap might wrongly consider some UIDs to have been deleted from the local
side which could lead to data loss.

Use a temporary map file rather than writing to the map file directly.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/380
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-10-24 20:02:53 +02:00
Nicolas Sebrecht 5d705f26e2 UIDMaps: reorder imports
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-10-18 14:58:02 +02:00
Nicolas Sebrecht 097d1e07fa folder: IMAP: remove unused import
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-10-18 13:56:35 +02:00
Stéphane Albert 57e6eda617 Fix implicit call to unicode() from UI functions
BaseFolder now exposes an __unicode__ method so that function needing
unicode transcoding don't crash due to ascii encoding errors.

Signed-off-by: Stéphane Albert <sheeprine@oh.its.fake.nullplace.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-09-23 17:40:44 +02:00
Nicolas Sebrecht c287ecb7cc set singlethreadperfolder configuration option when in idle mode
Git-reference: https://github.com/OfflineIMAP/offlineimap/issues/376
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-09-20 02:36:56 +02:00
James E. Blair 560363ef73 learn singlethreadperfolder configuration option
To further ensure that messages are synchronized strictly in UID
order, this option can be set to cause only one thread to be used
to synchronise an individual folder, though other folders may
be synchronized simultaneously by other threads.

Signed-off-by: James E. Blair <corvus@gnu.org>
Based-on-patch-by: James E. Blair <corvus@gnu.org>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-14 02:20:51 +02:00
James E. Blair a5ea1827fb folder: Base: sort message UID list
Return a sorted list of UIDs in getmessageuidlist.

Some MUAs (and their users) like to display messages in UID order
(or "order received").  If offlineimap is used in IMAP<->IMAP mode,
then the order messages are received by the second IMAP server will
be different because offlineimap iterates over a UID list produced
from the keys of a dictionary, which is unsorted.

This change sorts that list of UIDs so that both IMAP servers will
have their messages in the same order (except those times where
messages are appended to folders on both repositories between
syncs).

Signed-off-by: James E. Blair <corvus@gnu.org>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-14 01:56:13 +02:00
Nicolas Sebrecht d263af91e0 Maildir: add missing exception instance "as e" in except clause
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-13 16:28:32 +02:00
Nicolas Sebrecht 473be4c66f folder: Base: minor fix style
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-09 17:36:26 +02:00
Nicolas Sebrecht 6b313aabd3 don't delete messages in local cache in dry-run mode
This makes dry-run consitent when called more than once.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/370
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-09 15:02:03 +02:00
Łukasz Żarnowiecki f634546980 explicitly set __hash__ of Base class to None
This suppressing the warning generated when running offlineimap on
python2 with -3 switch:

  offlineimap/folder/Base.py:29: DeprecationWarning: Overriding __eq__
  blocks inheritance of __hash__ in 3.x

Since this object is mutable it should not be hashable.

From Python documentation[1]:

  A class that overrides __eq__() and does not define __hash__() will
  have its __hash__() implicitly set to None.

Therefore old behaviour is preserved.

[1] https://docs.python.org/3/reference/datamodel.html

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-06 01:32:26 +02:00
Nicolas Sebrecht cbd1a8929a folder: IMAP: change raw assert to OfflineImapError
There is not reason to block remainings actions on first error on UID STORE.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-04 02:21:22 +02:00
Nicolas Sebrecht fc54fe52a0 folder: IMAP: add 'imap' debug output before calling FETCH
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-08-03 01:25:39 +02:00
Nicolas Sebrecht be285e522d IMAP: don't take junk data for valid mail content
OfflineIMAP frequently delivers mail files to the Maildir consisting exclusively
of a single ASCII digit in IDLE mode. IMAPFolder.getmessage expects 'data' to be
of the form

  [(fetch-info, message-body)]

However, the imapobj.uid call in getmessage returns a list of *all* pending
untagged FETCH responses.  If any message flags were changed in the selected
IMAP folder since the last command (by another client or another thread in
OfflineIMAP itself), the IMAP server will issue unsolicited FETCH responses
indicating these flag changes (RFC3501, section 7).  When this happens, 'data'
will look like, for example

  ['1231 (FLAGS (\\Seen) UID 5300)',
   '1238 (FLAGS (\\Seen) UID 5318)',
   ('1242 (UID 5325 BODY[] {7976}', message-body)]

Unfortunately, getmessage retrieves the message body as data[0][1], which in
this example is just the string "2", and this is what gets stored in the mail
file.

Multi-threaded OfflineIMAP with IDLE or holdconnectionopen is particularly
susceptible to this problem because flag changes synced back to the IMAP server
on one thread will appear as unsolicited FETCH responses on another thread if it
happens to have the same folder selected.  This can also happen without IDLE or
holdconnectionopen or even in single-threaded OfflineIMAP with concurrent access
from other IMAP clients (webmail clients, etc.), though the window for the bug
is much smaller.

Ideally, either imaplib2 or getmessage would parse the fetch responses to find
the response for the requested UID.  However, since IMAP only specifies
unilateral FETCH responses for flag changes, it's almost certainly safe to
simply find the element of 'data' that is a tuple (perhaps aborting if there is
more than one tuple) and use that.

Github-fix: https://github.com/OfflineIMAP/offlineimap/issues/162
Based-on-patch-by: Austin Clements <amdragon@MIT.EDU>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-28 07:18:23 +02:00
Nicolas Sebrecht 0ef11a8392 folder/IMAP: code style
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-28 06:51:47 +02:00
Philipp Meier 560d631706 GmailMaildir: don't add a tuple to syncmessagesto_passes
Regression introduced by 59b712ecbc.

Fix-found-by: Abdo Roig-Maranges <abdo.roig@gmail.com>
Signed-off-by: Philipp Meier <github@philipp.meier.name>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-27 16:29:34 +02:00
Ævar Arnfjörð Bjarmason a1efae0703 Remove double import of "six"
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-27 03:19:14 +02:00
Nicolas Sebrecht 2f060aa269 Merge tag 'v6.7.0.3' into next
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-26 08:47:19 +02:00
Nicolas Sebrecht 77a6f9a7ba LocalStatusSQLite: code refactoring around database lock
Backported-from: 05e5b9c6bb
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-26 02:58:09 +02:00