server.nntp_article

Functions for building NNTP articles (RFC 5322 email messages) that carry OME metadata as MIME enclosures.

Public API:

nntp_article() — low-level builder: title + arbitrary JSON attachments. make_plugin_article() — high-level helper: plugin + raw item JSON → article.

Attributes

here

Functions

nntp_article(→ email.message.EmailMessage)

Returns an NNTP article (EmailMessage) with the given subject, optional body text,

make_plugin_article(→ email.message.EmailMessage)

Build an NNTP article from a plugin and a raw source-item JSON file.

Module Contents

server.nntp_article.nntp_article(title: str, attachments: collections.abc.Iterable[str | pathlib.Path], *, body: str = '') email.message.EmailMessage

Returns an NNTP article (EmailMessage) with the given subject, optional body text, and JSON file attachments (enclosures).

Args:

title: The article subject line. attachments: Paths to JSON files to attach as NNTP enclosures. body: Optional plain-text body for the article (e.g., serialised OME JSON).

server.nntp_article.make_plugin_article(plugin: server.plugins.ome_plugin.OMEPlugin, item_json_path: str | pathlib.Path, *, ome_json_path: str | pathlib.Path | None = None) email.message.EmailMessage

Build an NNTP article from a plugin and a raw source-item JSON file.

This is a convenience wrapper around nntp_article() that handles the boilerplate required to turn a raw source JSON record into a publishable NNTP article:

  1. Reads item_json_path and calls plugin.make_metadata_card_from_json() to produce an EducationResource.

  2. Serialises the resource to JSON and writes it to ome_json_path (<stem>_ome_item.json in the same directory by default).

  3. Calls nntp_article() with: - body = the OME JSON string - first attachment = the raw source-item JSON file - second attachment = the OME JSON file

Args:
plugin: The OMEPlugin subclass

instance to use for the metadata transformation.

item_json_path: Path to the raw source-item JSON file

(e.g. eric_item.json).

ome_json_path: Optional explicit path for the OME JSON output file.

When omitted the path is derived by replacing the _item suffix of item_json_path’s stem with _ome_item (e.g. eric_item.jsoneric_ome_item.json).

Returns:

An email.message.EmailMessage ready to be posted to INN or written to disk with Path(...).write_text(str(article)).

Example:

from pathlib import Path
from server.nntp_article import make_plugin_article
from server.plugins.eric.plugin import EricPlugin

plugin = EricPlugin()
here = Path(__file__).resolve().parent
article = make_plugin_article(plugin, here / "eric_item.json")
(here / "eric_article.eml").write_text(str(article))
server.nntp_article.here