Skip to content

Commit 6e7db9e

Browse files
authored
Fixed Yahoo IMAP support. (#138)
1 parent b86bd22 commit 6e7db9e

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.8.0.1
2+
Better Yahoo IMAP handling. It will now better parse out the emails and
3+
better keep track of the used IDs.
14
0.8.0.0
25
Try multiple EDHC curves
36
Allow `Source: arloWebCam` header entry to be turned on and off

pyaarlo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
_LOGGER = logging.getLogger("pyaarlo")
4848

49-
__version__ = "0.8.0.0"
49+
__version__ = "0.8.0.1"
5050

5151

5252
class PyArlo(object):

pyaarlo/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def _auth(self):
771771
return False
772772

773773
# look for code source choice
774-
self.debug("looking for {}".format(self._arlo.cfg.tfa_type))
774+
self.debug(f"looking for {self._arlo.cfg.tfa_type}/{self._arlo.cfg.tfa_nickname}")
775775
factors_of_type = []
776776
factor_id = None
777777

pyaarlo/tfa.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,36 +112,40 @@ def get(self):
112112
self.debug("no change in emails")
113113
continue
114114

115-
# new message...
115+
# New message. Reverse so we look at the newest one first.
116116
old_ids = self._old_ids[0].split()
117-
for msg_id in self._new_ids[0].split():
117+
msg_ids = self._new_ids[0].split()
118+
msg_ids.reverse()
119+
for msg_id in msg_ids:
118120

119-
# seen it?
121+
# Seen it?
120122
if msg_id in old_ids:
121123
continue
122124

123125
# New message. Look at all the parts and try to grab the code, if we catch an exception
124126
# just move onto the next part.
125127
self.debug("new-msg={}".format(msg_id))
126-
res, msg = self._imap.fetch(msg_id, "(BODY.PEEK[])")
127-
if isinstance(msg[0][1], bytes):
128-
for part in email.message_from_bytes(msg[0][1]).walk():
129-
if part.get_content_type() != "text/html":
130-
continue
131-
try:
132-
for line in part.get_payload(decode=True).splitlines():
133-
# match code in email, this might need some work if the email changes
134-
code = re.match(r"^\W+(\d{6})\W*$", line.decode())
135-
if code is not None:
136-
self.debug(
137-
"code={}".format(code.group(1))
138-
)
139-
return code.group(1)
140-
except:
141-
self.debug("trying next part")
142-
143-
# update old so we don't keep trying new
144-
self._old_ids = self._new_ids
128+
res, parts = self._imap.fetch(msg_id, "(BODY.PEEK[])")
129+
# res, parts = self._imap.fetch(msg_id, "(RFC822)")
130+
131+
for msg in parts:
132+
try:
133+
if isinstance(msg[1], bytes):
134+
for part in email.message_from_bytes(msg[1]).walk():
135+
if part.get_content_type() != "text/html":
136+
continue
137+
for line in part.get_payload(decode=True).splitlines():
138+
# match code in email, this might need some work if the email changes
139+
code = re.match(r"^\W+(\d{6})\W*$", line.decode())
140+
if code is not None:
141+
self.debug(f"code={code.group(1)}")
142+
return code.group(1)
143+
except Exception as e:
144+
self.debug(f"trying next part {str(e)}")
145+
146+
# Update old so we don't keep trying new.
147+
# Yahoo can lose ids so we extend the old list.
148+
self._old_ids.extend(new_id for new_id in self._new_ids if new_id not in self._old_ids)
145149

146150
# problem parsing the message, force a fail
147151
except Exception as e:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def readme():
1111
setup(
1212

1313
name='pyaarlo',
14-
version='0.8.0.0',
14+
version='0.8.0.1',
1515
packages=['pyaarlo'],
1616

1717
python_requires='>=3.7',

0 commit comments

Comments
 (0)