Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAP Unread E-mail - Search charset for outlook.office365.com #20642

Closed
MerijnF opened this issue Jan 31, 2019 · 5 comments
Closed

IMAP Unread E-mail - Search charset for outlook.office365.com #20642

MerijnF opened this issue Jan 31, 2019 · 5 comments

Comments

@MerijnF
Copy link

MerijnF commented Jan 31, 2019

Home Assistant release with the issue:

0.86.4

Last working Home Assistant release (if known):
Unknown

Operating environment (Hass.io/Docker/Windows/etc.):

Ubuntu 18.04 venv

Component/platform:

https://www.home-assistant.io/components/sensor.imap/

Description of problem:
I have been having problems while connecting to the outlook.office365.com imap server. With the config below i was getting an unread mail count of 8 allways, even when there were less ore more unread mails.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

  - platform: imap
    server: outlook.office365.com
    port: 993
    username: 'email@outlook.com'
    password: password

Traceback (if applicable):


Additional information:

Affter learning python and the imap protocol, and inspecting the source code for the component i found that it is linked to the charset. The library used for connection to imap servers sends utf-8 as default encoding for search commands. This (for some unknown reason does not work for outlook.office365.com) i was getting the response [BADCHARSET (US-ASCII)] The specified charset is not supported. witch is split as 8 results. Setting it to None fixed the issue.

When manualy changing line 157 from

            _, lines = await self._connection.search('UnSeen UnDeleted')

to

            _, lines = await self._connection.search('UnSeen UnDeleted', charset=None)

the component works for microsoft email adresses.

Im not sure about making this a configurable value and how contributing to open source projects would work. So here is my issue.

@jimz011
Copy link

jimz011 commented Feb 28, 2019

I tried this but still get that same error though. It is the imap.py right?

@MerijnF
Copy link
Author

MerijnF commented Feb 28, 2019

Indeed its it imap.py.
I noticed some changes to the file in 0.88.x witch improved error handling. For this specific error.

In the new files the line that i changed is 161 from

result, lines = await self._connection.search(self._search)

to

result, lines = await self._connection.search(self._search, charset=None)

@jimz011
Copy link

jimz011 commented Feb 28, 2019

@MysteryMerijn Fixed it for me ty (it appears I editted the wrong file before)

@jimz011
Copy link

jimz011 commented Apr 12, 2019

For the ones looking for this, the file has been renamed in later versions of Home Assistant. You can now find it here:

~site-packages/homeassistant/components/imap/sensor.py

@stale
Copy link

stale bot commented Jul 11, 2019

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants