From 8ebb6a9cdaf053ffa681ece900c5cc9f4bbc8afc Mon Sep 17 00:00:00 2001 From: Simon Robinson Date: Mon, 8 Jul 2024 17:24:09 +0100 Subject: [PATCH] Minor lint improvements --- plugins/IMAPCleanO365ATPLinks.py | 8 +++++--- plugins/IMAPLinkDestinationRevealer.py | 6 +++--- plugins/IMAPMessageEditor.py | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/IMAPCleanO365ATPLinks.py b/plugins/IMAPCleanO365ATPLinks.py index 68a5d83..21f9520 100644 --- a/plugins/IMAPCleanO365ATPLinks.py +++ b/plugins/IMAPCleanO365ATPLinks.py @@ -35,6 +35,7 @@ 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 @@ -42,6 +43,7 @@ def edit_message(self, byte_message): # 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: @@ -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 diff --git a/plugins/IMAPLinkDestinationRevealer.py b/plugins/IMAPLinkDestinationRevealer.py index 44febfb..07ef663 100644 --- a/plugins/IMAPLinkDestinationRevealer.py +++ b/plugins/IMAPLinkDestinationRevealer.py @@ -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): diff --git a/plugins/IMAPMessageEditor.py b/plugins/IMAPMessageEditor.py index e090ea0..eeb7668 100644 --- a/plugins/IMAPMessageEditor.py +++ b/plugins/IMAPMessageEditor.py @@ -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: @@ -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)