fetch2gmail 1.1.0__tar.gz → 1.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {fetch2gmail-1.1.0/src/fetch2gmail.egg-info → fetch2gmail-1.1.2}/PKG-INFO +1 -1
  2. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/pyproject.toml +1 -1
  3. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2/src/fetch2gmail.egg-info}/PKG-INFO +1 -1
  4. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/gmail_client.py +34 -0
  5. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/run.py +7 -0
  6. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/LICENSE +0 -0
  7. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/README.md +0 -0
  8. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/setup.cfg +0 -0
  9. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetch2gmail.egg-info/SOURCES.txt +0 -0
  10. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetch2gmail.egg-info/dependency_links.txt +0 -0
  11. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetch2gmail.egg-info/entry_points.txt +0 -0
  12. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetch2gmail.egg-info/requires.txt +0 -0
  13. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetch2gmail.egg-info/top_level.txt +0 -0
  14. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/__init__.py +0 -0
  15. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/auth_server.py +0 -0
  16. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/auth_ui.py +0 -0
  17. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/cli.py +0 -0
  18. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/config.py +0 -0
  19. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/env_file.py +0 -0
  20. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/imap_client.py +0 -0
  21. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/log_buffer.py +0 -0
  22. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/state.py +0 -0
  23. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/ui_auth.py +0 -0
  24. {fetch2gmail-1.1.0 → fetch2gmail-1.1.2}/src/fetcher/web_ui.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fetch2gmail
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Self-hosted email fetcher: IMAP to Gmail API import with idempotent state tracking
5
5
  Author: Fetch2Gmail Contributors
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fetch2gmail"
7
- version = "1.1.0"
7
+ version = "1.1.2"
8
8
  description = "Self-hosted email fetcher: IMAP to Gmail API import with idempotent state tracking"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fetch2gmail
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Self-hosted email fetcher: IMAP to Gmail API import with idempotent state tracking
5
5
  Author: Fetch2Gmail Contributors
6
6
  License-Expression: MIT
@@ -12,6 +12,11 @@ from email.parser import BytesParser
12
12
  from pathlib import Path
13
13
  from typing import Any
14
14
 
15
+ # Raised when a message cannot be normalized for Gmail (e.g. no From/Sender/Reply-To).
16
+ class SkipMessageError(ValueError):
17
+ """Message should be skipped for import (e.g. missing From)."""
18
+ pass
19
+
15
20
  from google.oauth2.credentials import Credentials
16
21
  from google_auth_oauthlib.flow import InstalledAppFlow
17
22
  from google.auth.transport.requests import Request
@@ -50,6 +55,34 @@ def get_gmail_service(credentials_path: str | Path, token_path: str | Path):
50
55
  return build("gmail", "v1", credentials=creds, cache_discovery=False)
51
56
 
52
57
 
58
+ def _normalize_from_header(raw: bytes) -> bytes:
59
+ """
60
+ Ensure the message has exactly one From header. Gmail import requires it.
61
+ - Multiple From: keep the first.
62
+ - No From: use Sender or Reply-To if present; otherwise raise SkipMessageError
63
+ so the message is skipped (never inject a fake address).
64
+ """
65
+ try:
66
+ msg = BytesParser(policy=policy.default).parsebytes(raw)
67
+ from_vals = msg.get_all("From") or []
68
+ if len(from_vals) == 0:
69
+ fallback = (msg.get("Sender") or msg.get("Reply-To") or "").strip()
70
+ if not fallback:
71
+ raise SkipMessageError("Message has no From, Sender, or Reply-To header")
72
+ msg["From"] = fallback
73
+ logger.debug("Message had no From header; using %s", fallback[:50])
74
+ elif len(from_vals) > 1:
75
+ msg["From"] = from_vals[0]
76
+ logger.debug("Message had %s From headers; kept first", len(from_vals))
77
+ else:
78
+ return raw
79
+ return msg.as_bytes()
80
+ except SkipMessageError:
81
+ raise
82
+ except Exception: # noqa: BLE001
83
+ return raw
84
+
85
+
53
86
  def _parse_date_from_raw(raw: bytes) -> str | None:
54
87
  """Extract Date header from raw message for Gmail internalDate."""
55
88
  try:
@@ -102,6 +135,7 @@ def import_message(
102
135
  If mark_unread is False (message was read on ISP), the message is imported as read.
103
136
  Returns Gmail message ID.
104
137
  """
138
+ raw = _normalize_from_header(raw)
105
139
  body = {"raw": base64.urlsafe_b64encode(raw).decode("ascii")}
106
140
  internal_date = _parse_date_from_raw(raw)
107
141
  if internal_date:
@@ -11,6 +11,7 @@ from typing import Any
11
11
 
12
12
  from .config import load_config
13
13
  from .gmail_client import (
14
+ SkipMessageError,
14
15
  _parse_message_id_from_raw,
15
16
  get_gmail_service,
16
17
  get_inbox_label_id,
@@ -166,6 +167,9 @@ def run_once(config_path: str | None = None, dry_run: bool = False) -> dict[str,
166
167
  state.set_last_processed_uid(mailbox, uid_validity, msg.uid)
167
168
  imported += 1
168
169
  logger.info("Imported uid=%s -> Gmail id=%s", msg.uid, gmail_id)
170
+ except SkipMessageError as e:
171
+ logger.warning("Skipping uid=%s (no From/Sender/Reply-To): %s", msg.uid, e)
172
+ continue
169
173
  except Exception as e:
170
174
  logger.exception("Gmail import failed for uid=%s: %s", msg.uid, e)
171
175
  # Do not delete from ISP; do not advance last_uid. Next run will retry.
@@ -350,6 +354,9 @@ def run_copy_all(
350
354
  state.set_last_processed_uid(mailbox, uid_validity, msg.uid)
351
355
  imported += 1
352
356
  logger.info("Copy-all imported uid=%s -> Gmail id=%s", msg.uid, gmail_id)
357
+ except SkipMessageError as e:
358
+ logger.warning("Skipping uid=%s (no From/Sender/Reply-To): %s", msg.uid, e)
359
+ continue
353
360
  except Exception as e:
354
361
  logger.exception("Gmail import failed for uid=%s: %s", msg.uid, e)
355
362
  continue
File without changes
File without changes
File without changes