Skip to content

Commit

Permalink
fix: fix utf8 searches (#833)
Browse files Browse the repository at this point in the history
* fix: fix utf8 searches

* formatting

* more formatting

* wrong serch criteria

* fix imap command syntax
  • Loading branch information
firstof9 authored Jun 12, 2023
1 parent 38525fa commit cb74afa
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions custom_components/mail_and_packages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,11 @@ def build_search(address: list, date: str, subject: str = None) -> tuple:
if subject is not None:
if not subject.isascii():
utf8_flag = True
# if prefix_list is not None:
# imap_search = f"CHARSET UTF-8 {prefix_list}"
# imap_search = f'{imap_search} FROM "{email_list} {the_date} SUBJECT'
# else:
# imap_search = (
# f"CHARSET UTF-8 FROM {email_list} {the_date} SUBJECT"
# )
imap_search = f"{the_date} SUBJECT"
if prefix_list is not None:
imap_search = f'{prefix_list} FROM "{email_list}" {the_date} SUBJECT'
else:
imap_search = f'FROM "{email_list}" {the_date} SUBJECT'
# imap_search = f"{the_date} SUBJECT"
else:
if prefix_list is not None:
imap_search = f'({prefix_list} FROM "{email_list}" SUBJECT "{subject}" {the_date})'
Expand Down Expand Up @@ -541,7 +538,7 @@ def email_search(
subject = subject.encode("utf-8")
account.literal = subject
try:
value = account.search("utf-8", "SUBJECT")
value = account.search("utf-8", search)
except Exception as err:
_LOGGER.debug(
"Error searching emails with unicode characters: %s", str(err)
Expand Down

0 comments on commit cb74afa

Please sign in to comment.