ikvk / imap_tools

Work with email by IMAP
Apache License 2.0
719 stars 83 forks source link

Connection drop while login or fetch #211

Closed vdessotti closed 1 year ago

vdessotti commented 1 year ago

Hello! When logging in or fetching mail the library hangs if the connection drops or in a slow connection. It does not give any errors. Just get stuck until the script gets reseted. I am using it like the example

Thanks for the help and for the library.

ikvk commented 1 year ago

Greet.

How did you understand what exactly the library freezes? Where does it hang? Show me your code.

vdessotti commented 1 year ago

Hello, The tests I did were trying to login or fetch and shutting down internet connection. Then the library gets stuck there and does not give any errors. Sometimes after the connection is back the program continues.


from imap_tools import MailBox, AND

with MailBox('imap.mail.com').login('test@mail.com', 'pwd') as mailbox: for msg in mailbox.fetch(): print(msg.date, msg.subject, len(msg.text or msg.html))


It is as standard as it can be.

Thanks,

ikvk commented 1 year ago

I have reproduce your scenario: And I immediately got trace:

Traceback (most recent call last): File "C:\kvk\develop\Python\imap_tools\examples\check.py", line 872, in for m in mailbox.fetch(): File "C:\kvk\develop\Python\imap_tools\imap_tools\mailbox.py", line 161, in fetch for fetch_item in (self._fetch_in_bulk if bulk else self._fetch_by_one)(uids, message_parts, reverse): # noqa File "C:\kvk\develop\Python\imap_tools\imap_tools\mailbox.py", line 125, in _fetch_by_one fetch_result = self.client.uid('fetch', uid, message_parts) File "C:\python\Python36-32\lib\imaplib.py", line 874, in uid typ, dat = self._simple_command(name, command, args) File "C:\python\Python36-32\lib\imaplib.py", line 1191, in _simple_command return self._command_complete(name, self._command(name, args)) File "C:\python\Python36-32\lib\imaplib.py", line 1014, in _command_complete typ, data = self._get_tagged_response(tag) File "C:\python\Python36-32\lib\imaplib.py", line 1134, in _get_tagged_response self._get_response() File "C:\python\Python36-32\lib\imaplib.py", line 1042, in _get_response resp = self._get_line() File "C:\python\Python36-32\lib\imaplib.py", line 1144, in _get_line line = self.readline() File "C:\python\Python36-32\lib\imaplib.py", line 305, in readline line = self.file.readline(_MAXLINE + 1) File "C:\python\Python36-32\lib\socket.py", line 586, in readinto return self._sock.recv_into(b) File "C:\python\Python36-32\lib\ssl.py", line 1009, in recv_into return self.read(nbytes, buffer) File "C:\python\Python36-32\lib\ssl.py", line 871, in read return self._sslobj.read(len, buffer) File "C:\python\Python36-32\lib\ssl.py", line 631, in read v = self._sslobj.read(len, buffer) ConnectionAbortedError: [WinError 10053] Программа на вашем хост-компьютере разорвала установленное подключение

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\kvk\develop\Python\imap_tools\examples\check.py", line 874, in time.sleep(1) File "C:\kvk\develop\Python\imap_tools\imap_tools\mailbox.py", line 41, in exit self.logout() File "C:\kvk\develop\Python\imap_tools\imap_tools\mailbox.py", line 94, in logout check_command_status(result, MailboxLogoutError, expected='BYE') File "C:\kvk\develop\Python\imap_tools\imap_tools\utils.py", line 46, in check_command_status raise exception(command_result=command_result, expected=expected) imap_tools.errors.MailboxLogoutError: Response status "BYE" expected, but "NO" received. Data: ["<class 'imaplib.IMAP4.abort'>: socket error: [WinError 10054] Удаленный хост принудительно разорвал существующее подключение"]

Process finished with exit code 1

===

What am I doing wrong?