Commit Graph

121 Commits

Author SHA1 Message Date
Joseph Ishac
84b96e1daa Adding re.DOTALL to catch potentially folded lines and fixed formatting 2021-04-14 17:08:16 -04:00
Joseph Ishac
a4532294ae Correcting an issue where dbg_output was not defined when the server was
unreachable due to an optimization in PR#56.  Since message-id is more
useful to better pin point the correct message, removing dbg_output.

Also fixing https://github.com/OfflineIMAP/offlineimap3/issues/62 by
correcting broken multipart boundaries or raising an error if as_bytes()
fails.  Related python bug submitted: https://bugs.python.org/issue43818
although this workaround should be sufficent in the interim.

Signed-off-by: Joseph Ishac <jishac@nasa.gov>
2021-04-14 14:54:25 -04:00
Joseph Ishac
f024bb9e4c Wrap bytes check in a wrapper to be a bit more efficient 2021-04-14 11:19:22 -04:00
Joseph Ishac
0345390aa1 Fixed oversight in regular expression (boundary cannot be empty) 2021-04-14 11:14:44 -04:00
Joseph Ishac
b78af75064 Adding a handler to detect the unlikely edge case where a message may
have an improperly quoted boundary that can cause the python library to
fail to reproduce the original message with msg.as_bytes().  See:
https://bugs.python.org/issue43818 and
https://github.com/OfflineIMAP/offlineimap3/issues/62
2021-04-13 00:01:26 -04:00
Joseph Ishac
259bf83607 Fixing up the rest of the parsing and IMAP functions, and GMAIL classes as well. Also adding is_debugging() to the UI to allow us to quickly determine if we should build some of the expensive debug objects 2021-02-23 16:17:54 -05:00
Joseph Ishac
3166723baa Removing obsolete emailutil.py. The date functionality was pulled into folder/Base.py which now handles messages as binary objects 2021-02-21 23:20:39 -05:00
Joseph Ishac
14b318b0e2 Formatting and adding the requirements that were removed as part of the "Included charset detection" patch that was reverted. Added all but chardet~=3.0.4 which is not needed with this fix. 2021-02-21 23:09:33 -05:00
Joseph Ishac
49b6c30ace Cleaning up some more use of the old message string "content" to use "msg" email object instead. 2021-02-19 17:00:15 -05:00
Joseph Ishac
1d2478bcb6 Series of *UNTESTED* changes that should move the internal structure of
a message from a string to an email object that is part of the built-in
email library.  The allows for emails to be processed as bytes and
re-encoded properly if they are not UTF-8 or ascii encoded.  Currently
these changes cover the Base, IMAP, and Maildir classes but not the
specialized GMAIL class yet.
2021-02-09 14:58:30 -05:00
Rodolfo García Peñas (kix)
ba6857bc87 Remove email.Parse
The Parse funcion was deprecated in python 2.4. We can use this new
code.
2020-10-12 12:40:54 +02:00
Rodolfo García Peñas (kix)
62df6e70c3 Rigth comparison with err EEXIST
This is the right code. The OSError doesn't have the EEXIST variable.
2020-10-12 12:35:56 +02:00
Rodolfo García Peñas (kix)
7ff65be690 Removed mutable arguments
This patch remves the set() mutable argument as default value,
sets the default value to None and check if the argument is none
in the code to call set().
2020-10-10 15:00:34 +02:00
Rodolfo García Peñas (kix)
9123cb83fc Remove md5 import
The library md5 is only for python2, hashlib is used in python3

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
2020-09-03 21:36:09 +02:00
Rodolfo García Peñas (kix)
ba11b2d684 six: changed offlineimap/folder/Maildir.py
This patch removes the library six, compatible with python2.

I need change these re-raise calls.

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
2020-09-03 21:36:00 +02:00
Rodolfo García Peñas (kix)
c68e70519d folder/Maildir.py split the if
This patch splits the if to avoid multiple commands in the same line.
2020-08-30 13:51:34 +02:00
Rodolfo García Peñas (kix)
1bcd7d3d4d folder/Maildir.py Removed unused variables
These variables are not used.
2020-08-30 13:51:34 +02:00
Rodolfo García Peñas (kix)
91df77f69f folder/Maildir.py Updated docstrings 2020-08-30 13:51:29 +02:00
Rodolfo García Peñas (kix)
3d2692103f folder/Maildir.py changed not var in
This patch changes:

if not var1 in var2

with

if var1 not in var2
2020-08-30 13:42:09 +02:00
Rodolfo García Peñas (kix)
28910df6c2 folder/Maildir.py removed extra chars
I removed some extra ()
2020-08-30 13:40:14 +02:00
Rodolfo García Peñas (kix)
7b082f0fe9 offlineimap/folder files singleton-comparison
This patch change these errors in the 'folder' folder

C0121: Comparison to None should be 'expr is None' (singleton-comparison)
C0121: Comparison to None should be 'expr is not None' (singleton-comparison)
2020-08-30 11:15:00 +02:00
Rodolfo García Peñas (kix)
7d62441dc2 Changed import order
These changes close the lintian warning C0411.
2020-08-29 21:10:16 +02:00
Rodolfo García Peñas (kix)
eafd9eb51d Reformat offlineimap/folder/Maildir.py
Add some spaces, remove lines,... now format is better (lintian).
2020-08-29 19:46:43 +02:00
Rodolfo García Peñas (kix)
7ba9ca1cca Maildir set is a builtin in python3
set() is a builtin, it is already included.
2020-08-29 09:22:23 +02:00
Rodolfo García Peñas (kix)
bb5b1f2dcf Encode folder name before md5
Avoid the error:

Unicode-objects must be encoded before hashing
2020-08-28 16:51:11 +02:00
Rodolfo García Peñas (kix)
6ec6111896 2to3 main 2020-08-28 03:32:43 +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
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
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
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
59f5da5e9e Maildir: OfflineImapError is missing the severity argument
Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/350
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-16 18:02:01 +02:00
Nicolas Sebrecht
7945e10a76 correctly reraise errors with six
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-03 19:56:14 +02:00
Nicolas Sebrecht
932e826d7c folder: Maildir: add comments about FMD5 issues
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-07-03 19:53:45 +02:00
Nicolas Sebrecht
e3fe848c6b minor code cleanups
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-06-08 19:03:02 +02:00
Łukasz Żarnowiecki
0addcbabf0 py3: raise exceptions using six module
There is no other way to make Python2 and Python3 happy, because syntax
raise E, V, T is incompatible with the latter.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-05-18 01:49:09 +02:00
Łukasz Żarnowiecki
23f96ba880 Encode utf-8 argument for md5 function
Python3 accepts binary input for md5 function.

This patch is known to break setups using folder names not strictly conforming
the IMAP UTF-7 encoding. We always made it clear that such setup is unsupported
and might be broken at some point in time. See documentation about
'decodefoldernames' in the provided configuration file. This is why this patch
is considered introducing no regression for this use case.

Patches to support both Python 3 and Python 2 by re-encoding the MD5 in the
filenames are welcome. This likely requires a new CLI option to allow
backporting the feature for users downgrading or changing of Python environment.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-05-17 00:44:02 +02:00
Łukasz Żarnowiecki
2465e1ce6a Replace dictionary iteration methods
Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-05-16 23:18:26 +02:00
Nicolas Sebrecht
bf8bfbc872 folder: utime_from_header is for Maildir only
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-05-11 04:10:13 +02:00
Łukasz Żarnowiecki
a3bd5d4d38 Replace has_key method to "key in dict"
There is no such method in Python3 any more.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-05-10 02:53:09 +02:00
Łukasz Żarnowiecki
19c43308b9 Change filter with lambda to list comprehension
It is more readable and returns a list therefore it is compatible both
with Python 2 and 3.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-05-10 02:53:09 +02:00
Łukasz Żarnowiecki
068ac7c410 Replace calls to long with int calls
long was removed from Python3

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-05-10 02:53:09 +02:00
Nicolas Sebrecht
657f258196 folder: properly factorize initialization and dropping of self.message
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-04-09 18:12:18 +02:00
Ilias Tsitsimpis
c84d23b656 Identify and fix messages with FMD5 inconsistencies
Introduce the '--migrate-fmd5-using-nametrans' option which migrates the
FMD5 hashes from versions prior to 6.3.5.

It seems that commit 'Apply nametrans to all Foldertypes' (6b2ec956cf)
introduced a regression because it changed the FMD5 part of the filename
calculated by OfflineIMAP. Thus, OfflineIMAP believes that the messages
has been removed and adds them back.

For more information, see:
http://www.offlineimap.org/configuration/2016/02/12/debian-upgrade-from-jessie-to-stretch.html

Bug-Debian: https://bugs.debian.org/812108
Reported-by: François <francois@avalenn.eu>
Signed-off-by: Ilias Tsitsimpis <i.tsitsimpis@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-03-06 21:01:51 +01:00
Nicolas Sebrecht
36375daee6 fix: exceptions.OSError might not have attribute EEXIST defined
Since this is used in an except calse, we first don't mask the real cause and
raise the original error.

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2016-02-19 12:33:57 +01:00
Nicolas Sebrecht
452ada330a folder/Maildir: ignore dot files
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-12-05 12:49:41 +01:00
Igor Almeida
c52ca66874 Maildir folder: extract lower-case letters (custom flags) from filename
Remove filtering that was previously done to avoid errors in flag
handling.

Signed-off-by: Igor Almeida <igor.contato@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-11-22 19:50:22 +01:00
Sébastien Gross
3b30c4aa93 add new config option filename_use_mail_timestamp
If this value is true, use (if possible) a timestamp based on message
Date or Delivery-date headers. The current system time is used
otherwise.

filename_use_mail_timestamp and utime_from_header are now completely
separated option that do not interfere one with other.

To handle this feature in a multithread context we use a hash to count
the number of mail with the same timestamp. This method is more accurate
than using the old lasttime and timeseq variables.

Signed-off-by: Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-11-04 00:56:46 +01:00
Janna Martl
ee0de28cc4 utime_from_header: handle out-of-bounds dates
Handle case where email's internal time is erroneously so large as to
cause overflow errors when setting file modification time with
utime_from_header = true.

Reported-by: Cameron Simpson <cs@zip.com.au>
Signed-off-by: Janna Martl <janna.martl109@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2015-10-12 16:19:23 +02:00