feat(picker): Gmail als zweites Postfach (Alle Nachrichten, readonly)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wd9aeH8MKgesfbsaS3kpnx
This commit is contained in:
parent
6bd9d8a6b0
commit
cc74635501
3 changed files with 38 additions and 9 deletions
|
|
@ -115,14 +115,46 @@ def _domain(sender: str) -> str:
|
||||||
return m[1].lower() if m else ""
|
return m[1].lower() if m else ""
|
||||||
|
|
||||||
|
|
||||||
|
def _mailboxes(db: Session):
|
||||||
|
"""Strato (Settings/Env) + optional Gmail (info@ lief bis Ende Mai 2026 über Google)."""
|
||||||
|
cfg = get_imap_config(db)
|
||||||
|
yield cfg, FOLDERS
|
||||||
|
if os.getenv("GMAIL_IMAP_PASSWORD"):
|
||||||
|
# ponytail: nur "Alle Nachrichten" (\All) statt jedes Label einzeln; Dedupe über Message-ID
|
||||||
|
yield {**cfg, "host": "imap.gmail.com", "port": 993, "user": os.getenv("GMAIL_IMAP_USER", "info@c-stone-dev.com"),
|
||||||
|
"password": os.environ["GMAIL_IMAP_PASSWORD"]}, None
|
||||||
|
|
||||||
|
|
||||||
|
def _all_mail(m) -> tuple:
|
||||||
|
for line in m.list()[1]:
|
||||||
|
s = line.decode(errors="ignore")
|
||||||
|
if "\\All" in s:
|
||||||
|
return (s.rsplit(' "/" ', 1)[-1].strip().strip('"'),)
|
||||||
|
return ("INBOX",)
|
||||||
|
|
||||||
|
|
||||||
def run(db: Session, since: date, state: Optional[dict] = None) -> dict:
|
def run(db: Session, since: date, state: Optional[dict] = None) -> dict:
|
||||||
state = state if state is not None else {}
|
state = state if state is not None else {}
|
||||||
state.setdefault("errors", [])
|
state.setdefault("errors", [])
|
||||||
counts = state.setdefault("counts", {})
|
counts = state.setdefault("counts", {})
|
||||||
cfg = get_imap_config(db)
|
for cfg, folders in _mailboxes(db):
|
||||||
|
try:
|
||||||
|
_scan(db, cfg, folders, since, state, counts)
|
||||||
|
except Exception as e:
|
||||||
|
state["errors"].append(f"{cfg['host']}: {e}"[:300])
|
||||||
|
if aws.ENABLED:
|
||||||
|
try:
|
||||||
|
sync_aws(db, since, get_imap_config(db)["storage_path"], counts)
|
||||||
|
except Exception as e:
|
||||||
|
db.rollback()
|
||||||
|
state["errors"].append(f"AWS-API: {e}"[:300])
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
def _scan(db: Session, cfg: dict, folders, since: date, state: dict, counts: dict):
|
||||||
m = connect_imap(cfg["host"], cfg["port"], cfg["user"], cfg["password"])
|
m = connect_imap(cfg["host"], cfg["port"], cfg["user"], cfg["password"])
|
||||||
try:
|
try:
|
||||||
for folder in FOLDERS:
|
for folder in folders or _all_mail(m):
|
||||||
if m.select(f'"{folder}"', readonly=True)[0] != "OK":
|
if m.select(f'"{folder}"', readonly=True)[0] != "OK":
|
||||||
continue
|
continue
|
||||||
ids = m.search(None, f"SINCE {since:%d-%b-%Y}")[1][0].split()
|
ids = m.search(None, f"SINCE {since:%d-%b-%Y}")[1][0].split()
|
||||||
|
|
@ -151,13 +183,6 @@ def run(db: Session, since: date, state: Optional[dict] = None) -> dict:
|
||||||
m.logout()
|
m.logout()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if aws.ENABLED:
|
|
||||||
try:
|
|
||||||
sync_aws(db, since, cfg["storage_path"], counts)
|
|
||||||
except Exception as e:
|
|
||||||
db.rollback()
|
|
||||||
state["errors"].append(f"AWS-API: {e}"[:300])
|
|
||||||
return state
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ services:
|
||||||
- SMTP_PORT=${SMTP_PORT:-465}
|
- SMTP_PORT=${SMTP_PORT:-465}
|
||||||
- INVOICING_AWS_ACCESS_KEY_ID=${INVOICING_AWS_ACCESS_KEY_ID:-}
|
- INVOICING_AWS_ACCESS_KEY_ID=${INVOICING_AWS_ACCESS_KEY_ID:-}
|
||||||
- INVOICING_AWS_SECRET_ACCESS_KEY=${INVOICING_AWS_SECRET_ACCESS_KEY:-}
|
- INVOICING_AWS_SECRET_ACCESS_KEY=${INVOICING_AWS_SECRET_ACCESS_KEY:-}
|
||||||
|
- GMAIL_IMAP_USER=${GMAIL_IMAP_USER:-info@c-stone-dev.com}
|
||||||
|
- GMAIL_IMAP_PASSWORD=${GMAIL_IMAP_PASSWORD:-}
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
networks:
|
networks:
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ ACCOUNTABLE_INBOX=${ACCOUNTABLE_INBOX:-}
|
||||||
GRAB_CUTOFF=${GRAB_CUTOFF:-}
|
GRAB_CUTOFF=${GRAB_CUTOFF:-}
|
||||||
INVOICING_AWS_ACCESS_KEY_ID=${INVOICING_AWS_ACCESS_KEY_ID:-}
|
INVOICING_AWS_ACCESS_KEY_ID=${INVOICING_AWS_ACCESS_KEY_ID:-}
|
||||||
INVOICING_AWS_SECRET_ACCESS_KEY=${INVOICING_AWS_SECRET_ACCESS_KEY:-}
|
INVOICING_AWS_SECRET_ACCESS_KEY=${INVOICING_AWS_SECRET_ACCESS_KEY:-}
|
||||||
|
GMAIL_IMAP_USER=${GMAIL_IMAP_USER:-info@c-stone-dev.com}
|
||||||
|
GMAIL_IMAP_PASSWORD=${GMAIL_IMAP_PASSWORD:-}
|
||||||
ENV
|
ENV
|
||||||
echo ".env geschrieben"
|
echo ".env geschrieben"
|
||||||
[ "${1:-}" = "--env-only" ] && exit 0
|
[ "${1:-}" = "--env-only" ] && exit 0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue