--- name: email_mime_message_rungs description: "Create an email that has both a plain-text and formatted version of your message plus one or more file attachments, with a subject line that can include accents or non-English characters. email_mime_message_rungs: An RFC 5322 email file written with the standard library email package: a multipart/mi" --- # email_mime_message_rungs (a Neruva verified skill for `email`) Create an email that has both a plain-text and formatted version of your message plus one or more file attachments, with a subject line that can include accents or non-English characters. Verified helper code for `email`, python. Entry points: `make_attachment`, `build_email_message`, `write_message_to_file`. Code hash sha256 `e703247724c778af571d6984d5b80b10986a1b8cdc9894ab83eb660c0e58f9b3`, signed (ed25519). Banked by `legacy-dev`. ## One call Call `build(**args)` with an object matching this schema. You do not have to write code or match the helper signatures below. ```json { "type": "object", "properties": { "from_addr": { "type": "string", "description": "Value for the From header, placed verbatim (e.g. 'sysadmin@neruva.io')." }, "to_addr": { "type": "string", "description": "Value for the To header, placed verbatim (e.g. 'jane@acme.test')." }, "subject": { "type": "string", "description": "Value for the Subject header; may contain non-ASCII characters, which will be RFC2047-encoded and round-trip via policy.default parsing." }, "plain_text": { "type": "string", "description": "Exact body text for the text/plain alternative part (utf-8 encoded)." }, "html_text": { "type": "string", "description": "Exact body markup for the text/html alternative part (utf-8 encoded)." }, "attachment": { "type": "object", "description": "The single attachment to include in the message.", "properties": { "filename": { "type": "string", "description": "Filename to declare for the attachment, e.g. 'report.csv'." }, "content_type": { "type": "string", "description": "MIME content type of the attachment, e.g. 'text/csv'." }, "content": { "type": "string", "description": "Attachment content as a string (UTF-8 encoded) or base64/plain text depending on need; passed through as-is to make_attachment which will UTF-8 encode strings." } }, "required": [ "filename", "content_type", "content" ] }, "date": { "type": "string", "description": "Optional ISO 8601 date-time string (e.g. '2024-05-01T12:00:00+00:00') for the Date header. If omitted, the current UTC time is used. If timezone-naive, UTC is assumed." }, "output_path": { "type": "string", "description": "Filesystem path where the resulting .eml file will be written. Returned by build() on success." } }, "required": [ "from_addr", "to_addr", "subject", "plain_text", "html_text", "attachment", "output_path" ] } ``` Example arguments: ```json { "from_addr": "sysadmin@neruva.io", "to_addr": "jane@acme.test", "subject": "R\u00e9sum\u00e9 du d\u00e9ploiement \u2014 \u5efa\u7acb", "plain_text": "All systems operational.", "html_text": "
Your invoice is paid.
", "attachment": { "filename": "report.csv", "content_type": "text/csv", "content": "step,status\nbuild,ok\n" }, "date": "2024-05-01T12:00:00+00:00", "output_path": "/tmp/out.eml" } ``` ```python def build(**kwargs): from_addr = kwargs['from_addr'] to_addr = kwargs['to_addr'] subject = kwargs['subject'] plain_text = kwargs['plain_text'] html_text = kwargs['html_text'] attachment = kwargs['attachment'] output_path = kwargs['output_path'] date_str = kwargs.get('date') date = None if date_str: date = dt.datetime.fromisoformat(date_str) if date.tzinfo is None: date = date.replace(tzinfo=dt.timezone.utc) att = make_attachment( attachment['filename'], attachment['content_type'], attachment['content'], ) msg = build_email_message( from_addr, to_addr, subject, plain_text, html_text, attachments=[att], date=date, ) write_message_to_file(msg, output_path) return output_path ``` ## How to use it make_attachment(filename, content_type, content) -> (filename, content_type, bytes) Normalizes an attachment's content (str or bytes) into a tuple ready for build_email_message's attachments argument. Example: make_attachment("report.csv", "text/csv", "a,b\n1,2\n") build_email_message(from_addr, to_addr, subject, plain_text, html_text, attachments=None, date=None, policy=None) -> email.message.EmailMessage Builds a multipart/mixed message whose first part is a multipart/alternative (text/plain + text/html, both utf-8) and whose remaining parts are attachments (each marked Content-Disposition: attachment). From/To/Subject/Date headers are set as given; Subject may contain non-ASCII and will round-trip via policy.default parsing. Example: msg = build_email_message( "sysadmin@neruva.io", "jane@acme.test", "R\u00e9sum\u00e9 du d\u00e9ploiement \u2014 \u5efa\u7acb", "All systems operational.", "Your invoice is paid.
", attachments=[make_attachment("report.csv", "text/csv", "step,status\nbuild,ok\n")], ) write_message_to_file(msg, path) -> None Serializes msg (an EmailMessage) to RFC 5322 bytes and writes them to the given filesystem path. Example: write_message_to_file(msg, "/tmp/out.eml") ## Evidence (corpus named) - held-out 16 specs, best-of-2, deepseek-chat: cold 0.312 -> 0.750 with the rung (CI +0.188..+0.688); helper reuse 1.00 - checker forged and mutation-gated, not hand-written: references accepted, every spoiler rejected, empty rejected, on 2 given specs plus 6 generated ($0.17) - stage-1 gate before forging: 4/8 for the cheap tier cold, so the gate opened ## Files - `scripts/skill.py`: the verified code (GET /v1/commons/rungs/rec_d0107eda77bd4c19ade8c9074df8d3ef/code) - verify: POST /v1/commons/verify {"id": "rec_d0107eda77bd4c19ade8c9074df8d3ef"}