unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Evan Gates <evan.gates@gmail.com>
To: meta@public-inbox.org
Subject: [PATCH] scripts: add script to export v1 inboxes to maildir
Date: Tue,  5 Apr 2022 17:01:56 -0600	[thread overview]
Message-ID: <20220405230156.25449-1-evan.gates@gmail.com> (raw)

---

I'm pretty sure this is a gross misuse of the public-inbox format, and
as such will not be offended if you decide not to include this script.

I read the public-inbox README and liked the idea of the pull model.
I briefly scanned clients.txt but didn't easily figure out how I was
supposed to pull and read mail locally.  Since the v1 format already
has a bunch of uniquely named files, that are themselves emails,
it was pretty simple to symlink them into a maildir format so I can
read them in my mail client.

As a followup to this abomination, what is the correct way to pull
and read mail locally?

 scripts/v1-to-maildir | 58 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100755 scripts/v1-to-maildir

diff --git a/scripts/v1-to-maildir b/scripts/v1-to-maildir
new file mode 100755
index 00000000..1cfcd2de
--- /dev/null
+++ b/scripts/v1-to-maildir
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+# Script to export v1 public-inbox repos to Maildir format.  Supports
+# updates.  Creates a .Maildirs directory in the PWD and a subdirectory
+# for each public-inbox git repo passed as an argument.  The repos ARE
+# NOT bare repos.
+#
+# Usage:
+#
+#     v1-to-maildir [public-inbox-v1-repo]...
+#
+# Example:
+#
+#     mkdir ~/lists
+#     cd ~/lists
+#     git clone https://public-inbox.org/meta public-inbox-meta
+#     git clone https://public-inbox.org/test public-inbox-test
+#     v1-to-maildir */
+# 
+#     Then point mail client to ~/lists/.Maildirs
+#     Run v1-to-maildir */ again to git pull and add new messages.
+
+dir=.Maildirs
+fmt=%-10s
+
+for d do
+	printf %s\\n "-- $d"
+	printf "$fmt" git\ pull:
+	if ! git -C "$d" pull -q; then
+		continue
+	fi
+	echo OK
+
+	printf "$fmt" mkdir:
+	for md in new cur tmp; do
+		if ! mkdir -p "$dir/$d/$md"; then
+			continue 2
+		fi
+	done
+	echo OK
+
+	printf "$fmt" new:
+	declare -A cur
+	new=()
+	for f in "$dir/$d/cur/"*; do
+		f=${f##*/}
+		f=${f%%:*}
+		cur[$f]=1
+	done
+	for f in "$d/"*/*; do
+		((cur[${f##*/}])) || new+=("$f")
+	done
+	((${#new[@]})) &&
+		printf %s\\0 "${new[@]/#/..\/..\/..\/}" |
+			xargs -0 ln -sft "$dir/$d/new"
+	printf %d\\n "${#new[@]}"
+	echo
+done
-- 
2.35.1


             reply	other threads:[~2022-04-05 23:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05 23:01 Evan Gates [this message]
2022-04-11 20:36 ` [PATCH] scripts: add script to export v1 inboxes to maildir Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220405230156.25449-1-evan.gates@gmail.com \
    --to=evan.gates@gmail.com \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).