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

2FA not parsing mail properly? #96

Closed
Jopand opened this issue May 12, 2022 · 15 comments · May be fixed by #105
Closed

2FA not parsing mail properly? #96

Jopand opened this issue May 12, 2022 · 15 comments · May be fixed by #105

Comments

@Jopand
Copy link

Jopand commented May 12, 2022

When running 2FA, I get the following errors:
[pyaarlo] imap message read failed'int' object has no attribute 'decode'
[pyaarlo] 2fa core retrieval failed
[custom_components.aarlo] unable to connect to Arlo: attempt=1,sleep=15,error=2fa core retrieval failed

I added some printouts to debug a bit. Seems like this line is causing the issue:

for part in email.message_from_bytes(msg[0][1]).walk():

I have to change "[0][1]" to "[1][1]", then it seems to work

@qosmio
Copy link

qosmio commented Jun 11, 2022

I was having the same issue, however this didn't work for me. The correct format should always have a tuple that has a length of with the body in the first tuple at msg[0][1].

I haven't looked much into why it's returning a tuple with 3 items. It doesn't seem to be the correct email either, it seems to be for a "confirm your email". Could you confirm?

You can add a check to ensure the message is in bytes before processing.

"""check if msg is bytes, then process email"""
if isinstance(msg[0][1], bytes):
    for part in email.message_from_bytes(msg[0][1]).walk():
        if part.get_content_type() == "text/html":
            for line in part.get_payload(decode=True).splitlines():
...

@Jopand
Copy link
Author

Jopand commented Jun 18, 2022

I haven't digged much more into it, but my change has worked ever since. I'm using a yahoo mail, but not sure if that makes a difference

@Jopand
Copy link
Author

Jopand commented Jun 18, 2022

FYI, the mails I'm getting are titled "Your one-time authentication code from Arlo", so it's definitely the correct email it is parsing

@stelle11
Copy link

I had same problem (also using yahoo) and tried first by changing the index number from 0 to 1 as you suggested Jopand but that didn't solve it.
I then added the if statement you suggested qosmio and that actually solved it for me :)

@jkrcknbrg
Copy link

jkrcknbrg commented Jun 19, 2022

I'm having the same problem, also using Yahoo email.

With the 'if' statement, I was unsuccessful with this error:
2022-06-19 07:29:48,177 - pyaarlo - ERROR - 2fa core retrieval failed

Changing the index from "[0][1]" to "[1][1]" failed with this error:
2022-06-19 07:33:35,839 - pyaarlo - ERROR - unable to read mode, try forcing v2

Update: My workaround was to switch to outlook.com email and drop Yahoo. Working now.

@gtawelt
Copy link
Contributor

gtawelt commented Jun 20, 2022

Try this for yahoo Mail

                    if isinstance(msg[0][1], bytes):
                        for part in email.message_from_bytes(msg[0][1]).walk():
                            if part.get_content_type() == "text/plain":
                                for line in part.get_payload(decode=True).splitlines():

@qosmio
Copy link

qosmio commented Jun 20, 2022

@Jopand I believe it’s definitely related to Yahoo’s YMail as well. That’s what I’ve been using too.

@stelle11 I’m glad to here! Hopefully if this works for more people using Yahoo I can create a pull request.

@jkrcknbrg I know you’ve switched over to using a different email, but if you were to try again, I found that disabling the integration for 5 minutes, and deleting all email sent from Arlo should give you a clean slate of no expired tokens.

@Jopand
Copy link
Author

Jopand commented Jun 21, 2022

@qosmio I'll try out the fix tomorrow and see if it works for me as well

@Jopand
Copy link
Author

Jopand commented Jul 6, 2022

The fix seems to work here as well...

EDIT: Nope, seems like I was saved by a previous session. Will post the logs tonight
EDIT2: https://pastebin.com/pWGqy2Jb
It seems like the check, you've added skips parsing the 2FA mail (which is being sent properly to my inbox)

If I revert back to my fix, it works instantly.

So in my setup, this doesn't work:

    if isinstance(msg[0][1], bytes):
        for part in email.message_from_bytes(msg[0][1]).walk():

but this does work:
for part in email.message_from_bytes(msg[1][1]).walk():

@Jopand
Copy link
Author

Jopand commented Nov 10, 2022

I made a printout of msg[0][1] and msg[0][1]..

msg[0][1]: 50

... nothing else...

msg[1][1]:
b'Received: from 127.0.0.1\r\n by atlas-production.v2-mail-prod1-gq1.omega.yahoo.com pod-id atlas--production-gq1-6db95f6ddc-xz57w.gq1.yahoo.com with HTTP..... + a lot more. LOOOOOONG string containing the entire mail

@imopen
Copy link

imopen commented May 22, 2023

same issue for me, using Yahoo, i solved using:

                if isinstance(msg[1][1], bytes):
                    for part in email.message_from_bytes(msg[1][1]).walk():

@Jopand
Copy link
Author

Jopand commented Oct 31, 2023

Will this ever be fixed? Multiple users using Yahoo have this tfa issue. The solution is above. Why not take it in and make it work with Yahoo as well as other tfa sources?

Since hass-aarlo has excluded the code of this project and rely entirely on the package, we can no longer manually fix the code after each update. So it is now definitively broken until something is done.

@twrecked
Copy link
Owner

Sorry, I'll try and take a look later. I've just managed to find time to look at this stuff again.

@twrecked
Copy link
Owner

twrecked commented Nov 1, 2023

I pushed a fix (and updated the alpha hass-aarlo release). Let me know if it works.

I dug out an old yahoo account I had and the change works with that and gmail.

@Jopand
Copy link
Author

Jopand commented Nov 1, 2023

It seems to work for me as well... Nice job 👌

@Jopand Jopand closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants