mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 10:15:27 -04:00
fix: IMAP connection leak in _imap_move on store/expunge failure (#1325)
If c.store() or c.expunge() raised an exception, the connection was never logged out. Use try/finally to ensure c.logout() is always called regardless of how the function exits.
This commit is contained in:
committed by
GitHub
parent
97f855b40d
commit
4019283eba
@@ -847,20 +847,25 @@ def _detect_spam_folder(conn):
|
|||||||
|
|
||||||
def _imap_move(uid, dest, src="INBOX", account_id: str | None = None, owner: str = ""):
|
def _imap_move(uid, dest, src="INBOX", account_id: str | None = None, owner: str = ""):
|
||||||
"""Move a single IMAP UID from src folder to dest. Returns True on success."""
|
"""Move a single IMAP UID from src folder to dest. Returns True on success."""
|
||||||
|
c = None
|
||||||
try:
|
try:
|
||||||
c = _imap_connect(account_id, owner=owner)
|
c = _imap_connect(account_id, owner=owner)
|
||||||
c.select(_q(src))
|
c.select(_q(src))
|
||||||
status, _ = c.copy(uid, _q(dest))
|
status, _ = c.copy(uid, _q(dest))
|
||||||
if status != "OK":
|
if status != "OK":
|
||||||
c.logout()
|
|
||||||
return False
|
return False
|
||||||
c.store(uid, "+FLAGS", "\\Deleted")
|
c.store(uid, "+FLAGS", "\\Deleted")
|
||||||
c.expunge()
|
c.expunge()
|
||||||
c.logout()
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"IMAP move {uid} → {dest} failed: {e}")
|
logger.warning(f"IMAP move {uid} → {dest} failed: {e}")
|
||||||
return False
|
return False
|
||||||
|
finally:
|
||||||
|
if c:
|
||||||
|
try:
|
||||||
|
c.logout()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _extract_attachment_text(msg, max_chars: int = 6000) -> str:
|
def _extract_attachment_text(msg, max_chars: int = 6000) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user