a2a-source-edit: write agent.py
This commit is contained in:
11
agent.py
11
agent.py
@@ -358,14 +358,17 @@ def _parse_inbox(inbox_text: str) -> list[dict[str, str]]:
|
|||||||
normalized = inbox_text.replace("\r\n", "\n").strip()
|
normalized = inbox_text.replace("\r\n", "\n").strip()
|
||||||
blocks = [block.strip() for block in re.split(r"\n\s*---+\s*\n", normalized) if block.strip()]
|
blocks = [block.strip() for block in re.split(r"\n\s*---+\s*\n", normalized) if block.strip()]
|
||||||
if len(blocks) == 1:
|
if len(blocks) == 1:
|
||||||
# Also split common pasted inbox format with repeated From: headers.
|
# Single unstructured paragraphs should ask for a clearer paste instead of
|
||||||
|
# inventing a sender/subject. Repeated From: headers are still accepted.
|
||||||
|
if not re.search(r"(?im)^\s*(from|sender)\s*:", normalized):
|
||||||
|
return []
|
||||||
blocks = [b.strip() for b in re.split(r"(?=\n?From\s*:)", normalized) if b.strip()]
|
blocks = [b.strip() for b in re.split(r"(?=\n?From\s*:)", normalized) if b.strip()]
|
||||||
out: list[dict[str, str]] = []
|
out: list[dict[str, str]] = []
|
||||||
for idx, block in enumerate(blocks, start=1):
|
for idx, block in enumerate(blocks, start=1):
|
||||||
sender = _field(block, "from") or _field(block, "sender") or "unknown@example.com"
|
sender = _field(block, "from") or _field(block, "sender")
|
||||||
subject = _field(block, "subject") or f"People inbox message {idx}"
|
subject = _field(block, "subject")
|
||||||
body = _field(block, "body") or _strip_headers(block)
|
body = _field(block, "body") or _strip_headers(block)
|
||||||
if len(body.strip()) < 8 and subject.startswith("People inbox message"):
|
if not sender or not subject or len(body.strip()) < 8:
|
||||||
continue
|
continue
|
||||||
out.append(
|
out.append(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user