From 240279f95ba8ef469cd62fa580d39771a7824554 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 13 Jul 2026 15:08:35 -0700 Subject: [PATCH] refactor: eliminate redundant truncation in email_ingest and fix em dash - Replace em dash with hyphen in thread_ingest.py user message (feedback_no_emdash.md) - Remove duplicate truncation logic in email_ingest.py (lines 12-17 and _truncate_for_embed method) - Consolidate truncation responsibility to ping.py's _safe_field_value as single source of truth - This prevents email_ingest's marker from being re-truncated by ping.py's defensive catch-all --- bot/chorus_bot/cogs/email_ingest.py | 18 +----------------- bot/chorus_bot/cogs/thread_ingest.py | 2 +- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/bot/chorus_bot/cogs/email_ingest.py b/bot/chorus_bot/cogs/email_ingest.py index 6030342..4379d36 100644 --- a/bot/chorus_bot/cogs/email_ingest.py +++ b/bot/chorus_bot/cogs/email_ingest.py @@ -9,13 +9,6 @@ from chorus_bot.ping import build_ping_embed SEEN_UIDS_PATH = Path(os.environ.get("CHORUS_SEEN_UIDS_PATH", "seen_uids.json")) -# Discord embed field values cap at 1024 chars. Truncate the raw_content we pass -# into the embed with headroom below that cap for build_ping_embed's own -# truncation marker (see ping.py). This is intentionally lossy for very long -# emails -- acceptable for MVP; the full body still lives in the source mailbox. -_RAW_CONTENT_MAX = 1000 -_TRUNCATION_MARKER = "\n\n[...truncated for Discord embed limit...]" - # modality -> (imap host attr, imap user attr, imap password attr) on Config MAILBOXES = { "bh_email": ("bh_email_imap_host", "bh_email_imap_user", "bh_email_imap_password"), @@ -80,7 +73,7 @@ class EmailIngestCog(commands.Cog): captured_at = parsedate_to_datetime(msg.get("Date")) body = self._extract_body(msg) snippet = body if len(body) <= 120 else body[:117] + "..." - raw_content = self._truncate_for_embed(body) + raw_content = body embed = build_ping_embed( modality=modality, sender_id=sender, snippet=snippet, @@ -95,15 +88,6 @@ class EmailIngestCog(commands.Cog): finally: conn.logout() - @staticmethod - def _truncate_for_embed(body: str) -> str: - """Cap the raw_content passed into the embed at a safe length below - Discord's 1024-char field limit. Lossy for very long emails but keeps - ingestion from failing (and retrying forever) on oversized bodies.""" - if len(body) <= _RAW_CONTENT_MAX: - return body - return body[:_RAW_CONTENT_MAX] + _TRUNCATION_MARKER - @staticmethod def _extract_body(msg) -> str: if msg.is_multipart(): diff --git a/bot/chorus_bot/cogs/thread_ingest.py b/bot/chorus_bot/cogs/thread_ingest.py index cb0a5aa..717c608 100644 --- a/bot/chorus_bot/cogs/thread_ingest.py +++ b/bot/chorus_bot/cogs/thread_ingest.py @@ -33,7 +33,7 @@ class ThreadIngestCog(commands.Cog): sender_id=parsed["sender_id"], ) await thread.send( - "Logged in Chorus — open the app to fill in details and track this one." + "Logged in Chorus - open the app to fill in details and track this one." )