Skip to content

Commit

Permalink
Minor lint improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrob committed Jul 8, 2024
1 parent 6958f0c commit 8ebb6a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions plugins/IMAPCleanO365ATPLinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ def edit_message(self, byte_message):
try:
# parse_qsl not parse_qs because we only ever care about non-array values; extra dict formatting
# as IntelliJ has a bug incorrectly detecting parse_qs/l as returning a dict with string-type keys
# pylint: disable-next=unnecessary-comprehension
atp_url_parts = {key: value for key, value in urllib.parse.parse_qsl(atp_url_query)}
except UnicodeEncodeError:
# the encoding and errors parameters for parse_qsl are not actually passed to _encode_result, so invalid
# (or incorrectly hyperlinked) values can cause decoding errors - we temporarily patch as a workaround
# noinspection PyUnresolvedReferences,PyProtectedMember
original_encode_result = urllib.parse._encode_result
urllib.parse._encode_result = lambda obj, encoding='utf-8', err='replace': obj.encode(encoding, err)
# pylint: disable-next=unnecessary-comprehension
atp_url_parts = {key: value for key, value in urllib.parse.parse_qsl(atp_url_query)}
urllib.parse._encode_result = original_encode_result
if b'url' in atp_url_parts:
Expand All @@ -56,6 +58,6 @@ def edit_message(self, byte_message):
if link_count > 0:
self.log_debug('Removed', link_count, 'O365 ATP links from message requested via', self.fetch_command)
return edited_message
else:
# no links to replace (or potentially some encoding not handled by IMAPMessageEditor)
return byte_message

# no links to replace (or potentially some encoding not handled by IMAPMessageEditor)
return byte_message
6 changes: 3 additions & 3 deletions plugins/IMAPLinkDestinationRevealer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def edit_message(self, byte_message):
if link_count > 0:
self.log_debug('Expanded target for', link_count, 'links from message requested via', self.fetch_command)
return edited_message
else:
# no links to replace (or potentially some encoding not handled by IMAPMessageEditor)
return byte_message

# no links to replace (or potentially some encoding not handled by IMAPMessageEditor)
return byte_message

@staticmethod
def normalise_url(url):
Expand Down
3 changes: 2 additions & 1 deletion plugins/IMAPMessageEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def receive_from_server(self, byte_data):
else:
return byte_data # pass through all other messages unedited

# pylint: disable-next=too-many-nested-blocks
if self.fetching:
self.fetched_message += byte_data
if len(self.fetched_message) < self.expected_message_length:
Expand All @@ -86,7 +87,7 @@ def receive_from_server(self, byte_data):
parsed_message_bytes = parsed_message.as_bytes()
for part in parsed_message.walk():
if part.get_content_type().startswith('text/') and part.get_filename() is None:
part_header, original_part_body = part.as_bytes().split(b'\r\n\r\n', maxsplit=1)
_part_header, original_part_body = part.as_bytes().split(b'\r\n\r\n', maxsplit=1)
cte = part['content-transfer-encoding'] if 'content-transfer-encoding' in part else None
part_body_edited, new_part_body = self._decode_and_edit_message_part(original_part_body,
encoding=cte)
Expand Down

0 comments on commit 8ebb6a9

Please sign in to comment.