Skip to content

Instantly share code, notes, and snippets.

@metrafonic
Created March 20, 2026 21:35
Show Gist options
  • Select an option

  • Save metrafonic/1cee3978f5cc949e1766e32def5eaef9 to your computer and use it in GitHub Desktop.

Select an option

Save metrafonic/1cee3978f5cc949e1766e32def5eaef9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import os
import RNS
import LXMF
from datetime import datetime
MSG_FILE = sys.argv[1]
PRINTER = "/dev/usb/lp0" # adjust as needed
message = LXMF.LXMessage.unpack_from_file(open(MSG_FILE, "rb"))
content = message.content_as_string()
sender = RNS.prettyhexrep(message.source_hash)
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(PRINTER, "wb") as p:
p.write(f"""
==============================
LXMF MESSAGE
------------------------------
{time}
From: {sender}
{content}
==============================
\n\n""".encode())
p.write(b'\x1d\x56\x00') # full cut
os.remove(MSG_FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment