feat: Add invite compressor and compressed header display

- Add InviteCompressor for terminal-friendly calendar invite summaries
- Add test fixtures for large group invite and cancellation emails
- Compress To/CC headers to single line with '... (+N more)' truncation
- Add 'h' keybinding to toggle between compressed and full headers
- EnvelopeHeader now shows first 2 recipients by default
This commit is contained in:
Bendt
2025-12-29 10:53:19 -05:00
parent db58cb7a2f
commit 16995a4465
6 changed files with 693 additions and 6 deletions

View File

@@ -0,0 +1,105 @@
Content-Type: multipart/mixed; boundary="===============1234567890123456789=="
MIME-Version: 1.0
Message-ID: test-large-group-invite-001
Subject: Project Kickoff Meeting
From: Product Development <product.dev@example.com>
To: Wolf, Taylor <taylor.wolf@example.com>, Marshall, Cody <cody.marshall@example.com>,
Hernandez, Florencia <florencia.hernandez@example.com>, Santana, Jonatas <jonatas.santana@example.com>,
Product Development <product.dev@example.com>
Cc: Sevier, Josh <josh.sevier@example.com>, Rich, Melani <melani.rich@example.com>,
Gardner, Doug <doug.gardner@example.com>, Young, Lindsey <lindsey.young@example.com>,
Weathers, Robbie <robbie.weathers@example.com>, Wagner, Eric <eric.wagner@example.com>,
Richardson, Adrian <adrian.richardson@example.com>, Roeschlein, Mitch <mitch.roeschlein@example.com>,
Westphal, Bryan <bryan.westphal@example.com>, Jepsen, Gary <gary.jepsen@example.com>,
Srinivasan, Sathya <sathya.srinivasan@example.com>, Bomani, Zenobia <zenobia.bomani@example.com>,
Meyer, Andrew <andrew.meyer@example.com>, Stacy, Eric <eric.stacy@example.com>,
Bitra, Avinash <avinash.bitra@example.com>, Alvarado, Joseph <joseph.alvarado@example.com>,
Anderson, Pete <pete.anderson@example.com>, Modukuri, Savya <savya.modukuri@example.com>,
Vazrala, Sowjanya <sowjanya.vazrala@example.com>, Bendt, Timothy <timothy.bendt@example.com>
Date: Fri, 19 Dec 2025 21:42:58 +0000
--===============1234567890123456789==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Project Kickoff Meetings: officially launches each project. Provides alignment for everyone involved with the project (project team, scrum team members, stakeholders).
* Present project's purpose, goals, and scope. This meeting should ensure a shared understanding and commitment to success, preventing misunderstandings, building momentum, and setting clear expectations for collaboration from day one.
* Discuss possible subprojects and seasonal deliverables to meet commitments.
* Required Attendees: Project Team, Contributing Scrum Team Members, & Product Owners
* Optional Attendees: PDLT and Portfolio
Join the meeting: https://teams.microsoft.com/l/meetup-join/example
--===============1234567890123456789==
Content-Type: text/calendar; charset="utf-8"; method=REQUEST
Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:Microsoft Exchange Server 2010
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Central Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0600
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0600
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ORGANIZER;CN="Product Development":mailto:product.dev@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Wolf, Taylor":mailto:taylor.wolf@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Marshall, Cody":mailto:cody.marshall@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Hernandez, Florencia":mailto:florencia.hernandez@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Santana, Jonatas":mailto:jonatas.santana@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Sevier, Josh":mailto:josh.sevier@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Rich, Melani":mailto:melani.rich@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Gardner, Doug":mailto:doug.gardner@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Young, Lindsey":mailto:lindsey.young@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Weathers, Robbie":mailto:robbie.weathers@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Wagner, Eric":mailto:eric.wagner@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Richardson, Adrian":mailto:adrian.richardson@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Roeschlein, Mitch":mailto:mitch.roeschlein@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Westphal, Bryan":mailto:bryan.westphal@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Jepsen, Gary":mailto:gary.jepsen@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Srinivasan, Sathya":mailto:sathya.srinivasan@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Bomani, Zenobia":mailto:zenobia.bomani@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Meyer, Andrew":mailto:andrew.meyer@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Stacy, Eric":mailto:eric.stacy@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Bitra, Avinash":mailto:avinash.bitra@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Alvarado, Joseph":mailto:joseph.alvarado@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Anderson, Pete":mailto:pete.anderson@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Modukuri, Savya":mailto:savya.modukuri@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Vazrala, Sowjanya":mailto:sowjanya.vazrala@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Bendt, Timothy":mailto:timothy.bendt@example.com
UID:040000008200E00074C5B7101A82E0080000000004321F5267A12DA01000000000000000
10000000030899396012345678968B934EDD6628570
SUMMARY;LANGUAGE=en-US:Project Kickoff Meeting
DTSTART;TZID=Central Standard Time:20251219T140000
DTEND;TZID=Central Standard Time:20251219T150000
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20251219T214258Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION;LANGUAGE=en-US:Microsoft Teams Meeting
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
END:VEVENT
END:VCALENDAR
--===============1234567890123456789==--

View File

@@ -0,0 +1,72 @@
Content-Type: multipart/mixed; boundary="===============9876543210987654321=="
MIME-Version: 1.0
Message-ID: test-cancellation-001
Subject: Canceled: Technical Refinement
From: Marshall, Cody <cody.marshall@example.com>
To: Ruttencutter, Chris <chris.ruttencutter@example.com>, Dake, Ryan <ryan.dake@example.com>,
Smith, James <james.smith@example.com>, Santana, Jonatas <jonatas.santana@example.com>
Cc: Bendt, Timothy <timothy.bendt@example.com>
Date: Fri, 19 Dec 2025 19:12:46 +0000
Importance: high
X-Priority: 1
--===============9876543210987654321==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
The meeting has been cancelled.
--===============9876543210987654321==
Content-Type: text/calendar; charset="utf-8"; method=CANCEL
Content-Transfer-Encoding: 7bit
BEGIN:VCALENDAR
METHOD:CANCEL
PRODID:Microsoft Exchange Server 2010
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Central Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0600
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0600
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ORGANIZER;CN="Marshall, Cody":mailto:cody.marshall@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Ruttencutter, Chris":mailto:chris.ruttencutter@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Dake, Ryan":mailto:ryan.dake@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Smith, James":mailto:james.smith@example.com
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Santana, Jonatas":mailto:jonatas.santana@example.com
ATTENDEE;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="Bendt, Timothy":mailto:timothy.bendt@example.com
UID:040000008200E00074C5B7101A82E00800000000043F526712345678901000000000000000
10000000308993960B03FD4C968B934EDD662857
RECURRENCE-ID;TZID=Central Standard Time:20251224T133000
SUMMARY;LANGUAGE=en-US:Canceled: Technical Refinement
DTSTART;TZID=Central Standard Time:20251224T133000
DTEND;TZID=Central Standard Time:20251224T140000
CLASS:PUBLIC
PRIORITY:1
DTSTAMP:20251219T191240Z
TRANSP:TRANSPARENT
STATUS:CANCELLED
SEQUENCE:84
LOCATION;LANGUAGE=en-US:Microsoft Teams Meeting
X-MICROSOFT-CDO-APPT-SEQUENCE:84
X-MICROSOFT-CDO-BUSYSTATUS:FREE
X-MICROSOFT-CDO-INTENDEDSTATUS:FREE
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:2
X-MICROSOFT-CDO-INSTTYPE:3
END:VEVENT
END:VCALENDAR
--===============9876543210987654321==--

View File

@@ -0,0 +1,183 @@
"""Tests for calendar invite compression."""
import pytest
from pathlib import Path
from src.mail.invite_compressor import InviteCompressor, compress_invite
from src.mail.utils.calendar_parser import (
parse_calendar_from_raw_message,
is_cancelled_event,
is_event_request,
)
from src.mail.notification_detector import is_calendar_email
class TestInviteDetection:
"""Test detection of calendar invite emails."""
def test_detect_large_group_invite(self):
"""Test detection of large group meeting invite."""
fixture_path = Path(
"tests/fixtures/test_mailbox/INBOX/cur/17051227-large-group-invite.test:2,S"
)
assert fixture_path.exists(), f"Fixture not found: {fixture_path}"
with open(fixture_path, "r") as f:
raw_message = f.read()
# Create envelope from message
envelope = {
"from": {"addr": "product.dev@example.com", "name": "Product Development"},
"subject": "Project Kickoff Meeting",
"date": "2025-12-19T21:42:58+00:00",
}
# Should be detected as calendar email
assert is_calendar_email(envelope) is True
# Parse the ICS
event = parse_calendar_from_raw_message(raw_message)
assert event is not None
assert event.method == "REQUEST"
assert is_event_request(event) is True
assert event.summary == "Project Kickoff Meeting"
assert len(event.attendees) >= 20 # Large group
def test_detect_cancellation(self):
"""Test detection of meeting cancellation."""
fixture_path = Path(
"tests/fixtures/test_mailbox/INBOX/cur/17051228-cancellation.test:2,S"
)
assert fixture_path.exists(), f"Fixture not found: {fixture_path}"
with open(fixture_path, "r") as f:
raw_message = f.read()
envelope = {
"from": {"addr": "cody.marshall@example.com", "name": "Marshall, Cody"},
"subject": "Canceled: Technical Refinement",
"date": "2025-12-19T19:12:46+00:00",
}
# Should be detected as calendar email
assert is_calendar_email(envelope) is True
# Parse the ICS
event = parse_calendar_from_raw_message(raw_message)
assert event is not None
assert event.method == "CANCEL"
assert is_cancelled_event(event) is True
assert event.status == "CANCELLED"
class TestInviteCompression:
"""Test compression of calendar invite content."""
def test_compress_large_group_invite(self):
"""Test compression of large group meeting invite."""
fixture_path = Path(
"tests/fixtures/test_mailbox/INBOX/cur/17051227-large-group-invite.test:2,S"
)
with open(fixture_path, "r") as f:
raw_message = f.read()
envelope = {
"from": {"addr": "product.dev@example.com", "name": "Product Development"},
"subject": "Project Kickoff Meeting",
"date": "2025-12-19T21:42:58+00:00",
}
compressor = InviteCompressor(mode="summary")
compressed, event = compressor.compress(raw_message, envelope)
assert event is not None
assert "MEETING INVITE" in compressed
assert "Project Kickoff Meeting" in compressed
# Should show compressed attendee list
assert "more)" in compressed # Truncated attendee list
# Should show action hints for REQUEST
assert "Accept" in compressed
def test_compress_cancellation(self):
"""Test compression of meeting cancellation."""
fixture_path = Path(
"tests/fixtures/test_mailbox/INBOX/cur/17051228-cancellation.test:2,S"
)
with open(fixture_path, "r") as f:
raw_message = f.read()
envelope = {
"from": {"addr": "cody.marshall@example.com", "name": "Marshall, Cody"},
"subject": "Canceled: Technical Refinement",
"date": "2025-12-19T19:12:46+00:00",
}
compressor = InviteCompressor(mode="summary")
compressed, event = compressor.compress(raw_message, envelope)
assert event is not None
assert "CANCELLED" in compressed
# Title should be strikethrough (without the Canceled: prefix)
assert "~~Technical Refinement~~" in compressed
# Should NOT show action hints for cancelled meetings
assert "Accept" not in compressed
def test_attendee_compression(self):
"""Test attendee list compression."""
compressor = InviteCompressor()
# Test with few attendees
attendees = ["Alice <alice@example.com>", "Bob <bob@example.com>"]
result = compressor._compress_attendees(attendees)
assert result == "Alice, Bob"
# Test with many attendees
many_attendees = [
"Alice <alice@example.com>",
"Bob <bob@example.com>",
"Carol <carol@example.com>",
"Dave <dave@example.com>",
"Eve <eve@example.com>",
]
result = compressor._compress_attendees(many_attendees, max_shown=3)
assert "Alice" in result
assert "Bob" in result
assert "Carol" in result
assert "(+2 more)" in result
def test_compress_off_mode(self):
"""Test that compression can be disabled."""
fixture_path = Path(
"tests/fixtures/test_mailbox/INBOX/cur/17051227-large-group-invite.test:2,S"
)
with open(fixture_path, "r") as f:
raw_message = f.read()
envelope = {
"from": {"addr": "product.dev@example.com"},
"subject": "Project Kickoff Meeting",
}
compressor = InviteCompressor(mode="off")
assert compressor.should_compress(envelope) is False
compressed, event = compressor.compress(raw_message, envelope)
assert compressed == ""
assert event is None
def test_convenience_function(self):
"""Test the compress_invite convenience function."""
fixture_path = Path(
"tests/fixtures/test_mailbox/INBOX/cur/17051227-large-group-invite.test:2,S"
)
with open(fixture_path, "r") as f:
raw_message = f.read()
envelope = {
"from": {"addr": "product.dev@example.com"},
"subject": "Project Kickoff Meeting",
}
compressed, event = compress_invite(raw_message, envelope)
assert event is not None
assert "Project Kickoff Meeting" in compressed