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)
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
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.
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>
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
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')
We cannot use these asserts, becasue the returned value of res is:
ERROR: getfolder() asked for a nonexisting folder 'INBOX.OLItest'.
ERROR: Exceptions occurred during the run!
ERROR: getfolder() asked for a nonexisting folder 'INBOX.OLItest'.
So, if we have an assert, to compare if the string is empty,
the test stops here. We can check if we have or not folder in the
next check (count_maildir_mails().
We cannot use this assert, becasue the returned value of res is:
ERROR: getfolder() asked for a nonexisting folder 'INBOX.OLItest'.
ERROR: Exceptions occurred during the run!
ERROR: getfolder() asked for a nonexisting folder 'INBOX.OLItest'.
So, if we have an assert, to compare if the string is empty,
the test stops here. We can check if we have or not folder in the
next check (count_maildir_mails().
We cannot use this assert, becasue the returned value of res is:
ERROR: getfolder() asked for a nonexisting folder 'INBOX.OLItest'.
ERROR: Exceptions occurred during the run!
ERROR: getfolder() asked for a nonexisting folder 'INBOX.OLItest'.
So, if we have an assert, to compare if the string is empty,
the test stops here. We can check if we have or not folder in the
next check (count_maildir_mails().
We cannot use this assert, becasue the returned value of res is:
ERROR: Account test: no folder to sync (f[388 chars]\n\n' != ''
- ERROR: Account test: no folder to sync (folderfilter issue?)
- ERROR: Exceptions occurred during the run!
- ERROR: Account test: no folder to sync (folderfilter issue?)
So, if we have an assert to test if the string is empty,
the test stops here. We can check if we have or not folder
in the next check (count_maildir_mails().
This patch changes the test to use always strings and not bytes or
bytearrays.
Now the test runs fine.
Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
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>
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>
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.
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