domovoy_bot/services/email_auditor/debug_imap.py

41 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import re
from pathlib import Path
from datetime import date, timedelta
from imap_tools import MailBox, AND
# Извлекаем учётку из .muttrc
BASE_DIR = Path(__file__).resolve().parent
MUTT_CONF = Path("/home/matrixhasyou/domovoy_bot/services/email_auditor/.muttrc")
def get_creds():
config = {}
with open(MUTT_CONF) as f:
for line in f:
line = line.strip()
match = re.match(r'set\s+(\w+)\s*=\s*"([^"]*)"', line)
if match: config[match.group(1)] = match.group(2)
return config.get('imap_user'), config.get('imap_pass')
def debug_imap():
user, password = get_creds()
print(f"🔍 Сканирую ВСЕ папки в поисках sudrf.ru...")
with MailBox("imap.gmail.com").login(user, password) as mailbox:
for folder in mailbox.folder.list():
try:
mailbox.folder.set(folder.name)
# Ищем за все время (без даты), просто по домену
count = 0
for msg in mailbox.fetch(AND(from_="sudrf.ru")):
print(f"✅ НАШЁЛ В '{folder.name}': [{msg.date}] {msg.from_} | {msg.subject}")
count += 1
if count == 0:
# Попробуем еще раз широким поиском по тексту
for msg in mailbox.fetch(AND(text="sudrf.ru")):
print(f"🔸 НАШЁЛ ТЕКСТ В '{folder.name}': [{msg.date}] {msg.from_} | {msg.subject}")
except Exception as e:
print(f"⚠️ Ошибка в папке {folder.name}: {e}")
if __name__ == "__main__":
debug_imap()