Skip to content

Security issue-import: support extracting email attachments from PonyMail #1768

Closed

Description

@jfclere

Problem

When importing security vulnerability reports from a PonyMail-backed mailing list via the issue-import skill, email attachments (test files, patches, PoC archives) cannot be downloaded. The PonyMail MCP server's get_source tool truncates output to 12,000 characters, and get_mbox similarly truncates — base64-encoded attachments are always cut off.

The get_email tool lists attachments with their hashes and filenames but provides no way to download the actual content.

Impact

Security reports frequently include reproducer test files and patches as attachments. Without attachment extraction, a PMC member must manually download them from a browser, breaking the import workflow.

Workaround

A Python script that bypasses the MCP truncation by fetching the raw MIME source directly from the PonyMail API (/api/source.json) and decoding the MIME parts with Python's email module:

#!/usr/bin/env python3
"""Extract MIME attachments from a PonyMail email by message ID.

Usage:
    python3 -I extract-email-attachments.py <message-id> [output-dir]

Requires a valid PonyMail session in ~/.ponymail-mcp/session.json.
"""
import email
import email.policy
import json
import os
import sys
import urllib.request


def main():
    if len(sys.argv) < 2:
        print(f"Usage: {sys.argv[0]} <message-id> [output-dir]", file=sys.stderr)
        sys.exit(2)

    msg_id = sys.argv[1]
    outdir = sys.argv[2] if len(sys.argv) > 2 else "."
    outdir = os.path.abspath(outdir)

    base_url = os.environ.get("PONYMAIL_BASE_URL", "https://lists.apache.org")
    api_url = f"{base_url}/api/source.json"

    session_file = os.path.expanduser("~/.ponymail-mcp/session.json")
    with open(session_file) as f:
        cookie = json.load(f)["cookie"]

    req = urllib.request.Request(
        api_url,
        data=json.dumps({"id": msg_id}).encode(),
        headers={
            "Content-Type": "application/json",
            "Accept": "text/plain",
            "Cookie": cookie,
        },
        method="POST",
    )

    with urllib.request.urlopen(req) as resp:
        raw = resp.read()

    msg = email.message_from_bytes(raw, policy=email.policy.default)

    count = 0
    for part in msg.walk():
        fn = part.get_filename()
        if fn:
            data = part.get_content()
            if isinstance(data, str):
                data = data.encode()
            outpath = os.path.join(outdir, fn)
            with open(outpath, "wb") as f:
                f.write(data)
            print(f"Saved: {fn} ({len(data)} bytes)")
            count += 1

    if count == 0:
        print("No attachments found in MIME message", file=sys.stderr)
        sys.exit(1)

    print(f"\nExtracted {count} attachment(s) to {outdir}")


if __name__ == "__main__":
    main()

Suggested approach

  1. Preferred: Add a get_attachment tool to the PonyMail MCP server that downloads individual attachments by email ID + attachment hash (already available from get_email response). This would fix the problem at the source for all MCP consumers.

  2. Alternative: Ship the workaround script above as a utility in the magpie-security family, and have issue-import call it when attachments are detected. The script reuses the PonyMail session cookie from ~/.ponymail-mcp/session.json.

Context

Discovered while importing security reports for the Apache Tomcat PMC. Emails with .java test files and .patch attachments (4-7 KB each) were truncated by the MCP tool. The workaround script successfully extracted all attachments.

Activity

  1. added
    good first issue
    on Oct 23, 2026
  2. potiuk commented on Oct 23, 2026

    @potiuk
    Member

    Nice !

  3. added a commit that references this issue on Oct 25, 2026
    4d5263c
  4. added
    family:security
    family:setup
    family:docs
    capability:intake
    capability:platform
    contract:mail-archive
    contract:mail-source
    substrate:sandbox
    substrate:framework-dev
    on Oct 25, 2026
  5. added a commit that references this issue on Oct 25, 2026
    95b0e91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    capability:intakecapability:platformcontract:mail-archivecontract:mail-sourcefamily:docsfamily:securityfamily:setupfamily:toolsgood first issuesubstrate:framework-devsubstrate:sandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions