kindle-digest

command module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 52 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

kindle-digest

A single-binary Go CLI that turns a Miniflux newsreader's last 24 hours of entries into one or more EPUB volumes and emails them to your Kindle. It fetches entries from the Miniflux API, sanitizes the article HTML, downloads and normalizes the images for e-ink, packs the articles into size-capped parts, and sends each part as its own attachment.

Features

  • Fetches every entry published in the last 24 hours (read or unread), following pagination — or any explicit window with -since/-until.
  • Strips scripts, styles, iframes, forms, navs, buttons, SVG and embedded media — video, audio, object, embed, canvas, frame, frameset, applet — from article HTML, subtrees included. Images, picture and figure are kept.
  • Downloads article images, flattens transparency onto white, converts WebP to JPEG, resizes to at most 800px wide at JPEG quality 75, with a per-article image budget.
  • Builds EPUB3 volumes with a generated cover, e-ink-friendly CSS and one section per article.
  • Groups the daily digest by feed: sections are alphabetical by feed title (case-insensitive), articles are newest first, and each feed opens on a separator page with its title, article count, publication dates and a tappable link to each of that source's articles in reading order.
  • Adds a hand-built Contents page per part linking to those feed sections, plus an A–Z Index of every article in the part (# for titles starting with a digit, symbol or non-ASCII letter). Collection exports get the Index only.
  • Greedy-packs articles into parts, backing off to the last feed boundary instead of splitting a feed when the shortened part stays at least half full, then merges adjacent parts whose real built sizes fit the cap.
  • Emails each part to your @kindle.com address, one message per part, or runs generate-only when mail settings are absent.
  • Optionally folds newsletter emails into the same digest, read read-only over IMAP: one entry per email, grouped under the source's name, with images stripped.
  • Optionally drains a Linkwarden tag queue into the same digest: each readability-tested link becomes an article under one Linkwarden section, and links are retagged only after the digest was actually sent.
  • Serves an optional single-page web UI (-serve) to trigger today's digest or a custom feed/window run and watch its status.
  • Writes a JSON run manifest per digest, so the web UI can mark exactly the exported Miniflux entries as read with one click.
  • Logs to a file and exits non-zero on failure.

Requirements

  • A Miniflux instance with the v2 API reachable over HTTP(S), and an API key from Settings → API Keys.
  • An SMTP account that allows authenticated submission with TLS, ideally using an app password rather than your main account password.
  • A send-to-Kindle address: your device's @kindle.com address, found in Amazon's Manage Your Content and Devices → Devices.
  • Amazon's "Approved Personal Document Email list": add the sender address (smtp_from) to that list in your Amazon account. Documents from unapproved senders are silently dropped by Amazon — no bounce, no error, they just never arrive.

Quickstart

Install with Go:

go install github.com/myleshen/kindle-digest@latest

Or build from source (Go 1.27+):

git clone https://github.com/myleshen/kindle-digest
cd kindle-digest
go build -o kindle-digest .

Cross-compile for a small server or Raspberry Pi:

CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o kindle-digest .

Copy the example config and fill it in:

cp config.example.json config.json
chmod 600 config.json

A complete config looks like this:

{
  "miniflux_url": "https://miniflux.example.com",
  "miniflux_api_key": "your-miniflux-api-key",
  "kindle_email": "you@kindle.com",
  "smtp_host": "smtp.example.com",
  "smtp_port": 587,
  "smtp_username": "you@example.com",
  "smtp_password": "your-app-password",
  "smtp_from": "you@example.com",
  "output_dir": "/opt/kindle-digest/output",
  "log_file": "/opt/kindle-digest/kindle-digest.log",
  "max_part_bytes": 4500000,
  "web_token": "long-random-string-for-the-web-ui",
  "ntfy_url": "https://ntfy.example.org",
  "ntfy_topic": "kindle-digest",
  "ntfy_token": "ntfy-access-token",
  "ntfy_click": "",
  "imap_host": "imap.zoho.in",
  "imap_port": 993,
  "imap_username": "you@example.com",
  "imap_password": "your-app-password",
  "max_emails_total": 5,
  "email_sources": [
    {
      "name": "Example Newsletter",
      "folder": "Newsletters",
      "from": "newsletter@example.com",
      "from_name": "",
      "subject_match": "",
      "max_per_day": 1
    }
  ],
  "linkwarden_url": "https://linkwarden.example.com",
  "linkwarden_token": "linkwarden-api-token",
  "linkwarden_tag": "kindle",
  "linkwarden_skipped_tag": "kindle-skipped",
  "linkwarden_completed_tag": "kindle-completed",
  "linkwarden_max": 10
}

Run it:

./kindle-digest -config /path/to/config.json

Schedule it with cron:

45 6 * * * /path/to/kindle-digest -config /path/to/config.json

Usage

Daily digest and late arrivals

By default the tool exports the last 24 hours of entries and emails the digest. Miniflux can crawl an article after that run has finished even though it was published earlier, which would otherwise leave it in neither day's window. The daily run therefore also asks Miniflux for entries inserted since the anchor (GET /v1/entries?after_entry_id=...), keeping those published no more than 24 hours before the window start (lateGrace). An arrival merges into its feed's section like any other entry; ids already exported or already in the window are skipped, so each article appears once. A fresh output_dir has no anchor yet, so the first run only writes the manifest the next one sweeps from. Windowed (-since/-until) and collection (-feed) runs never sweep — they return exactly the requested range and a same-window re-run still includes every entry in it. Every non-backfill manifest records max_entry_id (the highest Miniflux id it wrote) and kind; only kind: "daily" manifests move the anchor, because a collection or windowed run can export a high id without covering the entries around it. Every non-backfill manifest still counts in the dedupe, so the sweep never re-exports what a manual run already shipped. Manifests written before kind existed are treated as daily; older manifests without max_entry_id fall back to their listed entry ids. mode: "backfill" (or kind: "backfill") manifests carry no anchor and are excluded from both the anchor and the dedupe — they are reconstructed from a published window after the fact and can claim entries their EPUB never contained — while still showing up in the dashboard and remaining markable.

One feed (collection mode)

-feed exports a single feed instead of the daily digest. It accepts a numeric feed id, an exact title (case-insensitive) or a unique title substring; -limit defaults to 50 and is clamped to 1–500. Use -list-feeds to see the ids and titles Miniflux reports, one <id>\t<title> per line:

./kindle-digest -config config.json -list-feeds
./kindle-digest -config config.json -feed "Ars Technica" -limit 20
./kindle-digest -config config.json -feed 42 -limit 20 -send

On-demand runs are generate-only unless you pass -send; -send needs a complete SMTP block in the config and fails with an error otherwise. The plain daily run needs no -send (it sends from the config), so -send on its own is an error. The output is named <Feed title> - N articles - <date>.epub, with , Part N appended when the article count needs more than one volume.

Time windows

-since and -until replace the default last-24-hours window. Both accept RFC3339 (2026-11-26T06:00:00+05:30), 2006-01-02T15:04 and 2006-01-02; the two short forms are read in Asia/Kolkata, and a bare date means local midnight. The window is half-open, [since, until), and -until defaults to now. -until without -since is an error.

./kindle-digest -config config.json -since 2026-11-26 -until 2026-11-27 -send

Windowed runs are named Daily Digest - 26 Nov 2026 to 27 Nov 2026.epub (a single date when the window sits inside one day). A windowed run only sends with an explicit -send — the plain daily cron run keeps auto-sending from the config. Combine with -feed for one feed's window.

Email sources

Newsletter emails can join the same daily digest as a second content source. Each configured source is a folder plus a sender filter, and every matching email becomes one entry: the subject is the title and the email body is the article. Email sections merge into the same alphabetical grouping, Contents page and A–Z Index as the RSS feeds, under the source's name (for example TLDR AI).

"email_sources": [
  {"name": "Example AI", "folder": "Newsletters", "from": "news@example.com", "from_name": "Example AI Daily", "max_per_day": 1},
  {"name": "Example Habits", "folder": "Weekly", "from": "james@example.com", "max_per_day": 1}
]

Selection, per run:

  • The mailbox is opened read-only: EXAMINE instead of SELECT, headers and bodies via BODY.PEEK[] only. Messages are never marked \Seen, moved, copied or deleted.
  • Candidates are searched with IMAP SINCE (date granularity) and then filtered on the message's internal date to the same [since, until) window as the RSS digest.
  • from must equal the sender address (case-insensitive); from_name and subject_match, when set, must also match (case-insensitive, substring for the subject). from_name exists because senders such as TLDR run several editions from one address.
  • At most max_per_day newest emails are kept per source, then at most max_emails_total newest across all sources. Every drop is logged with its reason, and duplicate Message-IDs are dropped once per run.
  • Bodies prefer the text/html part, falling back to paragraphs from text/plain, and are decoded with the declared charset. The existing sanitizer removes scripts, styles, iframes, forms and inline CSS; all images are stripped (tracking pixels and logos included) while links are kept.
  • Accepted emails are logged with source, subject, received time, word count and estimated reading minutes at 220 wpm.

Failures never block the digest: if a folder cannot be read, the error is logged with the source and folder, the remaining sources and all RSS entries still build and send, and the process exits non-zero at the end to flag the partial failure. If every email source fails, the RSS-only digest still goes out.

Email bodies are used as-is: links in them are never fetched or followed, and no remote content is downloaded from them. email_sources empty (or absent) turns the feature off entirely and all IMAP fields are ignored.

Linkwarden queue

Point linkwarden_url and linkwarden_token at your Linkwarden instance to read the links carrying the linkwarden_tag (default kindle) into the same digest. Each accepted link becomes one article under a single Linkwarden section, which merges alphabetically with the feed and email sections in Contents and the A–Z Index. The title is the link name (or the URL hostname when it is empty) and the byline uses the link description.

Links are listed with GET /api/v1/search (tagId plus nextCursor paging until the cursor is null) and ordered client-side oldest first, by creation time then id, because that endpoint ignores the sort parameter.

Per run, oldest link first:

  • Readable: the page is fetched with a desktop user agent and read as an article. At least 800 characters of extracted text makes it an article. Images are downloaded and compressed like any other article's.
  • Skipped: fewer than 800 characters, a permanent HTTP error (4xx such as 404/410/403) or a non-article domain (YouTube, Vimeo, X/Twitter, Reddit, GitHub, Stack Overflow). These do not count toward the cap and are moved to linkwarden_skipped_tag after a send. Links whose type is not url (PDF, image, …) are left queued untouched.
  • Transient: timeouts, DNS failures and 5xx responses after one retry. The link stays in the gate for tomorrow; it does not count toward the cap.
  • Cap: at most linkwarden_max (default 10, 1–50) readable links per digest. The rest stay queued in order for tomorrow.

The queue is only mutated after a digest was actually emailed: delivered links move from the gate tag to linkwarden_completed_tag, skipped ones to linkwarden_skipped_tag. Every other tag on the link is preserved. Generate-only runs, failed sends and the whole sweep below without -linkwarden-sweep-apply change nothing. Linkwarden API failures are logged, the RSS and email digest still builds and sends, and the process exits non-zero at the end.

Delivered link ids are recorded in the run manifest (linkwarden_links) and any id a send-mode manifest already shipped is skipped, so a crash between the send and the tag swap cannot deliver the same link twice.

Before turning this on for a large library, classify it once:

./kindle-digest -config config.json -linkwarden-sweep          # dry run: counts and samples only
./kindle-digest -config config.json -linkwarden-sweep-apply    # writes the tags

The sweep pages through every link, ignores links that already carry any of the three kindle tags, and fetches the remaining URL links two at a time with a 20-second timeout and one retry. It reports scanned, readable, skipped and transient counts plus up to 10 sample titles per class and the elapsed time. -linkwarden-sweep-apply writes the gate tag for readable links and the skipped tag for thin ones, preserving every other tag; transient links are left alone.

Web UI

-serve <addr> starts a small dashboard. The config must set web_token; the process refuses to start without it and never logs the token. Sign in once with that token and the browser keeps an HttpOnly cookie for 30 days.

./kindle-digest -config config.json -serve 0.0.0.0:8090

Two actions: Send today's digest now (the same daily run as cron, following the config's send mode) and a custom run — any feed or all feeds, optional since/until dates, a limit of 1–500 and an explicit Send to Kindle checkbox. The page polls /api/status, so the current run and the last five runs (kept in memory, lost on restart) show their outcome, parts and sizes without a reload. Only one run happens at a time: the UI single-flights and takes the same flock in output_dir as a CLI or cron run, so overlapping runs are rejected instead of racing.

The UI deliberately has no EPUB download or file browser — it triggers runs and reports status, and files stay on disk under output_dir. It has no TLS or user management of its own, so put it behind your reverse proxy or VPN and treat web_token like a password.

Run manifests and marking read

Every successful run that writes parts — daily, windowed or collection, send or generate-only, CLI or web — records what it exported in output_dir/runs/<timestamp>.json:

{
  "created_at": "2026-11-28T06:45:12+05:30",
  "title": "Daily Digest - 28 Nov 2026",
  "kind": "daily",
  "mode": "send",
  "since": "2026-11-27T06:45:12+05:30",
  "until": "2026-11-28T06:45:12+05:30",
  "max_entry_id": 1235,
  "parts": [
    {"file": "Daily Digest - 28 Nov 2026, Part 1.epub",
     "entries": [1234, 1235], "feeds": ["Example Feed"], "email_count": 0,
     "linkwarden_links": [318, 322]}
  ]
}

entries are Miniflux entries (markable as read), email_count counts newsletters, and linkwarden_links records the Linkwarden link ids a send-mode run delivered. Linkwarden ids are only deduped from send-mode manifests: a generate-only run records what it built but changed no tags, so those links are still queued for the next run.

The Recent digests card on the dashboard lists the newest 10 manifests with a Mark whole digest read button and a Mark read button per part. Marking sends the manifest's entry ids to Miniflux's PUT /v1/entries in batches of 100; nothing outside the manifest is touched, already-read entries are harmless, and a non-2xx response is shown instead of a success message. It is one-way: the UI has no undo, so use Miniflux to restore entries if needed. A run that fails before writing parts, or whose send fails, leaves no manifest. Manifests older than 30 days are pruned at startup.

A successful mark also writes a sidecar next to the manifest, output_dir/runs/<timestamp>.marked.json, recording when it happened and how many entries per part have been marked. The sidecar accumulates: marking one part records that part and leaves the others as they were, and marking the whole digest fills in every part, so the digest badge reads the running total of part counts (✓ 14 of 54, then ✓ 54 of 54). A part whose recorded count equals its Miniflux entry count renders a disabled ✓ Marked button, and the Mark whole digest read button is disabled once every part is full. A manifest without a sidecar counts as unmarked, sidecars written before part counts were recorded treat every part as unmarked, and pruning removes the sidecar together with its manifest.

Digests written before manifests existed can be added retrospectively with -backfill-manifests:

./kindle-digest -config config.json -backfill-manifests

For each output_dir/YYYY-MM-DD/ directory that contains EPUBs but no manifest for that date, it queries Miniflux for entries published in [date 06:45 IST, next day 06:45 IST), paging through /v1/entries, and writes one mode: "backfill" manifest pointing at the directory's first EPUB. It is idempotent: dates that already have a manifest are skipped without a query, so running it again writes nothing. It only reads from Miniflux and writes manifests — it never marks anything read.

When the newest manifest records a since window, the dashboard shows an Older unread card: the Miniflux count of unread entries published before that since — the backlog no digest has covered. Marking it is manual and one-way: its Mark N older entries as read button marks exactly those entries (in the same 100-id batches) only when clicked, and the UI has no undo. It is never run automatically and only ever sets status=read; nothing else about those entries changes.

Email newsletter items come from IMAP, not Miniflux, so they have no Miniflux read state and are never marked — each part reports its email count separately.

ntfy notifications

Set ntfy_url (for example https://ntfy.example.org), ntfy_topic and a token with publish permission on that topic as ntfy_token to get a push when a run finishes. ntfy_click is optional: it is the URL opened when the notification is tapped. All four fields are optional, but the first three must be set together — a partial block is a fatal config error.

  • Send mode, success: one notification titled Daily Digest ready (the run's own title for windowed and collection runs) with the article count, part count and total size. Priority 3, tag books.
  • Any failed run: one notification titled Digest failed with the error text (truncated to 200 characters). Priority 4, tag warning.
  • Generate-only runs: no notification, because nothing reached the Kindle.
  • Best-effort: if the notification itself fails, the error is logged and the run's exit code is unchanged — a broken ntfy server never fails the digest.

The ntfy server must allow the token to publish to the topic (ntfy's write-only access token covers this).

Docker Compose (Alpine plus the cross-built binary; the project directory is bind-mounted at the same absolute path so the paths in config.json keep working):

services:
  kindle-digest:
    image: alpine:3.20
    command: sh -c "apk add --no-cache ca-certificates && exec /opt/kindle-digest/kindle-digest -config /opt/kindle-digest/config.json -serve 0.0.0.0:8090"
    volumes:
      - /opt/kindle-digest:/opt/kindle-digest
    ports:
      - "8090:8090"
    restart: unless-stopped

Configuration

Field Meaning Default / validation
miniflux_url Base URL of your Miniflux instance Required; must be http or https with a host
miniflux_api_key Miniflux API key (sent as X-Auth-Token) Required
kindle_email Send-to-Kindle address for your device Optional; empty means generate-only
smtp_host SMTP server hostname Required when kindle_email is set
smtp_port SMTP submission port Required when kindle_email is set; 1–65535 (587 typical)
smtp_username SMTP username Required when kindle_email is set
smtp_password SMTP password or app password Required when kindle_email is set
smtp_from From address; must be on Amazon's approved sender list Required when kindle_email is set
output_dir Directory for generated EPUBs; each run writes to <output_dir>/YYYY-MM-DD/ Required
log_file File to append log lines to; stdout/stderr always get them too Optional; empty disables file logging
max_part_bytes Target size of each EPUB part Default 4500000; must be 100000–50000000 (Amazon's per-attachment limit)
web_token Shared secret for the web UI login Required only with -serve; the server refuses to start if empty
ntfy_url Base URL of your ntfy server, e.g. https://ntfy.example.org Optional; required together with ntfy_topic and ntfy_token
ntfy_topic ntfy topic to publish on Optional; required together with ntfy_url and ntfy_token
ntfy_token ntfy access token with publish permission on the topic Optional; required together with ntfy_url and ntfy_topic
ntfy_click URL opened when the notification is tapped Optional; valid alone or with the other ntfy fields
imap_host IMAP server for email sources Default imap.zoho.in; only read when email_sources is non-empty
imap_port IMAP implicit-TLS port Default 993; 1–65535
imap_username IMAP username Required when email_sources is non-empty
imap_password IMAP password or app password Required when email_sources is non-empty
max_emails_total Most emails in one digest, newest first across sources Default 5; at least 1
email_sources Array of {name, folder, from, from_name, subject_match, max_per_day} Empty or absent disables email sources
email_sources[].name Section name in the digest Required
email_sources[].folder IMAP folder to read read-only Required
email_sources[].from Sender address, matched exactly and case-insensitively Required
email_sources[].from_name Sender display name, matched exactly Optional
email_sources[].subject_match Case-insensitive subject substring Optional
email_sources[].max_per_day Newest emails kept per source per run Default 1
linkwarden_url Base URL of your Linkwarden instance, e.g. https://linkwarden.example.com Optional; required together with linkwarden_token
linkwarden_token Linkwarden API token (sent as a bearer token) Optional; required together with linkwarden_url
linkwarden_tag Tag whose links are queued for the digest Default kindle; must differ from the other two
linkwarden_skipped_tag Tag applied to links that never extract as an article Default kindle-skipped
linkwarden_completed_tag Tag applied to links the digest delivered Default kindle-completed
linkwarden_max Most Linkwarden articles per digest Default 10; 1–50

Mode rules:

  • kindle_email empty → generate-only. EPUBs are written to output_dir; nothing is sent. Other SMTP fields are ignored.
  • kindle_email set and all SMTP fields present → send mode. One email per part, with a pause between sends.
  • kindle_email set but any SMTP field missing → fatal config error; the run exits non-zero before doing anything.

Typography

The generated CSS is tuned for e-ink readers and for the Kindle's own accessibility settings:

  • Only relative font sizes (1em, 1.6em, 1.3em, 1.1em, 0.85em, 0.9em), never px or pt, so the Kindle's size slider and per-book font settings keep working.
  • No embedded font files. The stacks name fonts already on the device — Bookerly/Caecilia for body text, Amazon Ember for headings, Courier for code — and fall back to Georgia/Arial/monospace elsewhere. Embedding fonts would bloat every part, override the reader's chosen typeface and defeat those same controls.
  • Left-aligned text and 1.5 line-height rather than justified text, which avoids the wide word gaps e-ink is prone to, and EPUB dc:language en so hyphenation and the dictionary work.

Kindle gotchas

  • The attachment filename becomes the book title in your Kindle library. This tool names parts Daily Digest - <date>, Part N.epub in pure ASCII for that reason. Non-ASCII filenames came out malformed as titles.
  • Zoho Mail on the India or EU datacenter needs the regional SMTP host. Accounts hosted on Zoho's Indian datacenter must use smtp.zoho.in, and EU accounts smtp.zoho.eu; the generic smtp.zoho.com endpoint fails authentication with SMTP 535 errors for those accounts.
  • Amazon caps email attachments at 25 files per message and 50 MB per file. Large or complex EPUBs are also rejected by some send-to-Kindle paths regardless, so parts default to a 4.5 MB target; max_part_bytes can be raised to 50 MB, Amazon's per-attachment limit. More than one part per day is normal.
  • Digest quality depends on what Miniflux stores. Feeds that only publish summaries (common for paywalled or aggregated sites) produce thin articles. Enable the per-feed Fetch original content option in Miniflux so the digest gets the full article HTML.
  • One embedded video can turn the whole digest into a PDF. Amazon's EPUB converter silently renders a book as PDF when it finds embedded media, and a single <video> in one article is enough. E-ink EPUBs do not need media embeds, so the sanitizer removes them and their subtrees; a <source> inside a kept <picture> is untouched.
  • Send-to-Kindle converts EPUBs to AZW3 a few minutes after delivery. The book may appear briefly as a document and then re-render; that is normal.
  • Dates and the 24-hour window are computed in Asia/Kolkata (IST), matching the intended daily reading schedule.

How it works

  1. Fetch — lists feeds and pages through /v1/entries for entries inside the window (last 24 hours by default, or -since/-until), sorted by feed title and newest first.
  2. Email sources — when configured, reads each folder read-only over IMAP, filters by sender, window and caps, and decodes the selected messages into entries alongside the feed entries.
  3. Sanitize — parses each entry's HTML, drops non-content elements, and rewrites image references. Email bodies skip image handling entirely; their images were already stripped. Linkwarden links are fetched first and reduced to their <article>/<main> content.
  4. Images — downloads each image concurrently (bounded), flattens it onto white, downscales to ≤800px wide, re-encodes as JPEG q75, and drops the largest images if an article exceeds its 2.5 MB image budget.
  5. Build — groups the digest by feed or email source with a separator, Contents and Index page per part (collection mode gets the Index only), and writes each EPUB3.
  6. Pack — greedily fills parts by estimated size, pulls each cut back to the last feed boundary if the shortened part is still at least half of max_part_bytes, then verifies the real file size against the 50 MB hard cap, splitting or shrinking only when it overflows. Finally, adjacent parts whose real built sizes together fit max_part_bytes are rebuilt as a single part, so estimates that overstate compressed text do not leave the run with two half-empty volumes; a merge that fails or overflows keeps the originals.
  7. Send — emails each part to the Kindle address over authenticated TLS SMTP.
  8. Retag — after a successful send, moves the delivered Linkwarden links to linkwarden_completed_tag and the skipped ones to linkwarden_skipped_tag, then exits non-zero if anything failed.
  9. Record — writes the run manifest under output_dir/runs with each part's file, Miniflux entry ids, feed titles, email count and delivered Linkwarden link ids.

Every digest run also logs a timings: line — fetch=… linkwarden=… prepare=… build=… total=… — so a slow source, image set or pack step is visible without timing the whole run.

License

MIT — see LICENSE.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址