Commit Graph

1781 Commits

Author SHA1 Message Date
Rodolfo García Peñas (kix)
646cb4354b Maildir.py renamed variable names
This patch renames some variables to avoid these warnings:

Variable name "e" doesn't conform to snake_case naming style (invalid-name)
2020-11-01 09:26:42 +01:00
Rodolfo García Peñas (kix)
5c6e95103e Maildir.py added docstrings
This patch adds the docstring for the class and for two methods.
2020-11-01 09:21:08 +01:00
Rodolfo García Peñas (kix)
e12a702128 GmailMaildir.py Removed __init__
First, in Python 3 we don't need call the super().__init__ explicitly, because Python does it. So, we can remove the line:

super().__init__(reposname, account)

If we leafe the method __init__ empty, the parent __init__ method is not called, we need remove the __init__ and then Python uses the parent __init__ method.
2020-11-01 09:13:17 +01:00
Rodolfo García Peñas (kix)
5f338454ee GmailMaildir.py Removed parent class for super call
The super() call in Python 3 does not need the parent class. The MRO get it.
2020-11-01 09:06:35 +01:00
Rodolfo García Peñas (kix)
caea1b7baa GmailMaildir.py included class docstring
Only added docstring for the class.
2020-11-01 09:03:37 +01:00
Rodolfo García Peñas (kix)
c2fce5de38 Gmail.py removed parent class in super calls
In Python 3 we don't need specify the class for these calls, the MRO find it.
2020-11-01 09:02:09 +01:00
Rodolfo García Peñas (kix)
3f7e9fe1bd Gmail.py Changed comments to docstring
This patch changes the comments in these functions to docstrings
and remove pylint warnings.
2020-11-01 08:57:43 +01:00
Rodolfo García Peñas (kix)
fc2055de8c Gmail.py else statement not needed
Always is else here.
2020-11-01 08:54:16 +01:00
Rodolfo García Peñas (kix)
0454e3e2f1 Gmail.py swap if block
I swapped this if - else block, with the "is not". Code now is clear.
2020-11-01 08:53:08 +01:00
Rodolfo García Peñas (kix)
4198fa8201 Gmail.py else statement not needed
We don't need speficify the else here. Always is else.
2020-11-01 08:51:03 +01:00
Rodolfo García Peñas (kix)
d50a28a68f repository add docstring to files
This patch includes the docstrings for all files, removing the pylint
warning
2020-11-01 08:43:16 +01:00
Rodolfo García Peñas (kix)
e5f0f10334 distro_utils.py renamed variable f
The variable f is renamed to l_file to avoid pylint warning:

utils/distro_utils.py:95:8: C0103: Variable name "f" doesn't conform to snake_case naming style (invalid-name)
2020-11-01 08:31:47 +01:00
Rodolfo García Peñas (kix)
b51fa3b9f6 distro_utils.py get dictionary value using get
This patch use get to get the value of os_name. Else, None is get.
2020-11-01 08:29:15 +01:00
Rodolfo García Peñas (kix)
4e31762ec6 distro_utils.py added docstring
Remove pylint warning about

C0114: Missing module docstring (missing-module-docstring)
2020-11-01 08:23:28 +01:00
Rodolfo García Peñas (kix)
9f34b14f72 const.py added docstring
Remove pylint warning about

C0114: Missing module docstring (missing-module-docstring)
2020-11-01 08:22:44 +01:00
Rodolfo García Peñas (kix)
3be65bf5dd pylint renamed variables
This patch renames some variables to avoid pylint warning about

Variable name "f" doesn't conform to snake_case naming style (invalid-name)

f is now file
th is now the_en
n is now count
2020-11-01 08:21:24 +01:00
Rodolfo García Peñas (kix)
cbfcd38bca stacktrace.py added docstring
Removed warning:

C0114: Missing module docstring (missing-module-docstring)
2020-11-01 08:16:19 +01:00
Rodolfo García Peñas (kix)
9239c804e9 Base.py remove redundant parenthesis
Just remove these parenthesis
2020-10-31 16:55:58 +01:00
Rodolfo García Peñas (kix)
8504cdc6b8 Base.py long lines style
This patch changes long lines (>80 chars) to lines <80 chars.
The patch only changes the style.
2020-10-31 16:55:20 +01:00
Rodolfo García Peñas (kix)
23f67019cc Base.py long lines style
This patch changes long lines (>80 chars) to lines <80 chars.
The patch only changes the style.
2020-10-31 16:43:52 +01:00
Rodolfo García Peñas (kix)
332a6d7240 IMAP.py long lines style
This patch changes long lines (>80 chars) to lines <80 chars.
The patch only changes the style.
2020-10-31 16:14:53 +01:00
Rodolfo García Peñas (kix)
1ce229ca9d IMAP.py comparison with None should use is
Comparison with None should be "is" not "=="
2020-10-31 16:12:02 +01:00
Rodolfo García Peñas (kix)
2f2f4ef918 IMAP.py long lines style
This patch changes long lines (>80 chars) to lines <80 chars.
The patch only changes the style.
2020-10-31 16:09:34 +01:00
Rodolfo García Peñas (kix)
5033340c2f IMAP.py should use encoding to read the file
This patch includes the word "encoding" to select the right argument in remotepassfile.
2020-10-31 15:53:45 +01:00
Rodolfo García Peñas (kix)
cbbeebbf44 imapserver.py removed extra parenthesis
We can remove this parenthesis.
2020-10-31 15:39:28 +01:00
Rodolfo García Peñas (kix)
0e90bcbf38 IMAP.py too many arguments for string format
We need only two arguments, not three. We can remove the self argument.
2020-10-31 15:37:50 +01:00
Rodolfo García Peñas (kix)
352133dcc0 call to setDaemon uses Bool argument
The argument 1 should be True in these files.
2020-10-31 15:35:54 +01:00
Rodolfo García Peñas (kix)
78aeed20a9 imapserver call to OfflineImapError with right arguments
Call to OfflineImapError has the arguments:

- message
- severity
- error code

The None argument ir wrong here, we can remove it and then we have three arguments not four.
2020-10-31 15:29:24 +01:00
Rodolfo García Peñas (kix)
26efc62ba7 imapserver import style
This patch removes the unused import socket line. (warning)

Split the line with multiple imports in different lines. (warning)
2020-10-31 15:24:40 +01:00
Rodolfo García Peñas (kix)
a60ca038ce Updated cram-md5 authentication
This patch updates the cram-md5 auth. We include two steps:

- Convert the password variable from string to bytes. This change is
  because in Python2 strings and bytes are the same, but not in Python3
- Updates the call to hmac.new, now the digestmod argument is mandatory.
  I used hashlib.md5, because we need md5 hash.

Closes #19

    Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
2020-10-31 00:09:38 +01:00
Rodolfo García Peñas (kix)
a4863b2f04 Use system sslcacertfile by default
This patch includes a new functionality to get the sslcacertfile.

With this patch is possible to remove the sslcacertfile variable form the
.offlineimaprc and use the system's default. This could be easy for new users.

With this patch, the user can use ssl without the sslcacertfile option
in .offlineimaprc, use sslcacertfile = <empty> (no include anything
after the equal sign, os specify the sslcacertfile as previosly.

Currently, these are the options:

    User specifies sslacertfile -> OK
    User specifies sslacertfile=OS-DEFAULT
        If the system's default is provided -> OK
        If the system's default is not provided -> Fail
    User do not specifies sslacertfile -> Fail
    User specifies empty sslacertfile -> Fail

With the new option (this patch).

    User specifies sslacertfile -> OK
    User specifies sslacertfile=OS-DEFAULT or
    User do not specifies sslacertfile or
    User specifies empty sslacertfile
        If the system's default is provided -> OK
        If the system's default is not provided -> Fail

Closes #14
2020-10-26 12:10:49 +01:00
Rodolfo García Peñas (kix)
442c88d838 imaplib expect bytes in the append
imaplib2 is doing this code for strings:

        if isinstance(message, str):
            message = bytes(message, 'ASCII')

But our message is already encoded using 'utf-8'.
Then, we can set the message as bytes, encoded using 'utf-8'
in offlineimap and imaplib2 won't change our message.

This patch solves this problem:

WARNING:OfflineImap:
Traceback:
  File "/home/kix/src/offlineimap3/offlineimap/folder/Base.py", line 1127, in syncmessagesto
    action(dstfolder, statusfolder)
  File "/home/kix/src/offlineimap3/offlineimap/folder/Base.py", line 955, in __syncmessagesto_copy
    self.copymessageto(uid, dstfolder, statusfolder, register=0)
  File "/home/kix/src/offlineimap3/offlineimap/folder/Base.py", line 855, in copymessageto
    new_uid = dstfolder.savemessage(uid, message, flags, rtime)
  File "/home/kix/src/offlineimap3/offlineimap/folder/IMAP.py", line 668, in savemessage
    (typ, dat) = imapobj.append(self.getfullIMAPname(),
  File "/usr/lib/python3/dist-packages/imaplib2.py", line 660, in append
    message = bytes(message, 'ASCII')
2020-10-25 20:36:07 +01:00
Rodolfo García Peñas (kix)
47f7b1ba3c get_os_sslcertfile_searchpath do not check iterable
Now, location is always an iterable, so we don't need check it.
2020-10-25 17:32:38 +01:00
Rodolfo García Peñas (kix)
a1f8576937 distro_utils do not compare types
This patch now use isinstance to compare types.
2020-10-25 17:27:40 +01:00
Rodolfo García Peñas (kix)
fe25a5c752 Distro default certificates must be iterables
This patch changes the __DEF_OS_LOCATIONS to an iterable value.

The reason is because a list is an iterable, but an string is an
iterable too, and this is a mistake.

The function get_os_sslcertfile() has a loop to iterate the return of
get_os_sslcertfile_searchpath(), that returns the value in the
__DEF_OS_LOCATIONS dictionary. When the value is an iterable, the "f"
variable is set to the iterable value and works fine.
If the value of "f" is an string, the for-loop iterates over every
character, so the test for os.path.exists is always false (is comparing
the path with a character, not with the full path), so this function
fails and return None.

To check this change, edit your .offlineimaprc file and change the
sslcacertfile to OS-DEFAULT:

sslcacertfile = OS-DEFAULT

And run offlineimap. If you are not using 'darwin0 (the only iterable)
it will fails. Now, apply this patch, and run offlineimap again. Problem
is solved.

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
2020-10-25 17:26:20 +01:00
Rodolfo García Peñas (kix)
bde48fe2c7 Renamed l variable to location_name
This variable is renamed to avoid a warning about ambiguous name.

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
2020-10-25 16:42:09 +01:00
Rodolfo García Peñas (kix)
5777553a96 Renamed l variable to location_name
This variable is renamed to avoid a warning about ambiguous name.

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
2020-10-25 16:40:50 +01:00
Rodolfo García Peñas (kix)
714cbe2327 Renamed OS to os_name in get_os_sslcertificate_searchpath
This patch changes this variable name only.
2020-10-25 16:40:07 +01:00
Rodolfo García Peñas (kix)
07c1a5c9db Deprecated linux_distribution
The call from platform.linux_distribution was depdrecated in Python 3.7.

This patch solves this problem, using the recomended package distro.

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
2020-10-25 16:38:16 +01:00
Rodolfo García Peñas (kix)
f66bfb0026 Renamed utils/distro.py
The file utils/distro.py is renamed to utils/distro_utils.py
because we need import the distro file to update some calls.

The file is used in IMAP.py, I need change the import.
2020-10-25 16:33:52 +01:00
Rodolfo García Peñas (kix)
faff27f0c9 Renamed variable DISTRO to distro_name
Variable DISTRO should be lowercase. I renamed it to distro_name.
2020-10-25 15:47:50 +01:00
Rodolfo García Peñas (kix)
997f5b27c5 Renamed variable OS to os_name
Variable OS should be in lowercase.
2020-10-25 15:47:22 +01:00
Thomas De Schampheleire
33e0efa163 IMAP: replace non-UTF-8 characters rather than aborting
Emails received may not be UTF-8. Following error was observed on a specific
mail:

Traceback (most recent call last):
  File "/home/tdescham/repo/offlineimap3/offlineimap/threadutil.py", line 146, in run
    Thread.run(self)
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/tdescham/repo/offlineimap3/offlineimap/folder/Base.py", line 850, in copymessageto
    message = self.getmessage(uid)
  File "/home/tdescham/repo/offlineimap3/offlineimap/folder/IMAP.py", line 327, in getmessage
    data = self._fetch_from_imap(str(uid), self.retrycount)
  File "/home/tdescham/repo/offlineimap3/offlineimap/folder/IMAP.py", line 844, in _fetch_from_imap
    ndata1 = data[0][1].decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 10177: invalid start byte

This completely aborted offlineimap3, blocking further mail reception.

Instead, use the 'replace' error strategy in Python:

    Replace with a suitable replacement character; Python will use the
    official U+FFFD REPLACEMENT CHARACTER for the built-in Unicode codecs on
    decoding and ‘?’ on encoding.
    https://docs.python.org/2/library/codecs.html#codec-base-classes
2020-10-21 16:29:13 +02:00
Thomas De Schampheleire
820e5c855f IMAP: Python 3 bytes fix on first download of account
ERROR: ERROR in syncfolder for gmail folder INBOX: Traceback (most recent call last):
  File ".../offlineimap3/offlineimap/accounts.py", line 634, in syncfolder
    cachemessagelists_upto_date(maxage)
  File ".../offlineimap3/offlineimap/accounts.py", line 526, in cachemessagelists_upto_date
    min_date=time.gmtime(time.mktime(date) + 24 * 60 * 60))
  File ".../offlineimap3/offlineimap/folder/IMAP.py", line 277, in cachemessagelist
    imapobj, min_date=min_date, min_uid=min_uid)
  File ".../offlineimap3/offlineimap/folder/IMAP.py", line 259, in _msgs_to_fetch
    search_result = search(search_cond)
  File ".../offlineimap3/offlineimap/folder/IMAP.py", line 222, in search
    if ' ' in res_data[0] or res_data[0] == '':
TypeError: a bytes-like object is required, not 'str'
2020-10-21 14:28:23 +02:00
Rodolfo García Peñas (kix)
49c85d732d Using isinstance instead type
This patch uses isinstance, like Thomas pointed in their last commit.
2020-10-12 12:52:04 +02:00
Rodolfo García Peñas (kix)
d8149c1ec1
Merge pull request #7 from patrickdepinguin/py3fix
More python 3 related fixes
2020-10-12 12:44:19 +02: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
Thomas De Schampheleire
c00af91990 accounts: decode output of hooks
When a hook is configured, the output is a bytes object.
This is then printed on the console/logfile as:

    2020-10-12 08:36:17 INFO: Hook stdout: b'Processed 3 total files in almost no time.\nAdded 3 new messages to the database.\n'
    Hook stderr:b''

Decode the output so that it is printed nicely, as:

    2020-10-12 08:36:17 INFO: Hook stdout: Processed 3 total files in almost no time.
    Added 3 new messages to the database.

    Hook stderr:

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
2020-10-12 09:01:59 +02:00
Thomas De Schampheleire
423785725b IMAP.py: server responses are in bytes, not string
Following error is seen when parsing server responses for sent mail:

2020-10-12 08:19:11 WARNING: Can't parse FETCH response, we awaited string: b' UID 26855)'
2020-10-12 08:19:11 WARNING: savemessage: Searching mails for new Message-ID failed. Could not determine new UID on Sent.

The comparison with 'type("")' means comparing with 'string' type in Python
3, but the left-hand side is a bytes object.

In case a tuple was received (first case in the code), the input is already
decoded from bytes to strings, but in case a single input was received it
was not.

Note that the comparison with 'type("")' is a bit odd, a more logical way
seems to be:
    if isinstance(item, bytes)

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
2020-10-12 09:01:51 +02:00