user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
 Warning: Initial query:
 %22import ssoma-replay example script I%27ve been using%22
 returned no results, used:
 "import ssoma-replay example script I've been using"
 instead

Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] import ssoma-replay example script I've been using
@ 2016-05-14  2:24  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-05-14  2:24 UTC (permalink / raw)
  To: meta

Unfortunately, most users still prefer their mail delivered
over SMTP; so we'll at least document mlmmj integration for now
until we can popularize pull-based reading over POP3/NNTP/ssoma.
---
 Makefile.PL          |  3 +-
 TODO                 |  3 --
 scripts/ssoma-replay | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 4 deletions(-)
 create mode 100755 scripts/ssoma-replay

diff --git a/Makefile.PL b/Makefile.PL
index 1948848..de0ac4a 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -37,7 +37,8 @@ WriteMakefile(
 sub MY::postamble {
   <<EOF;
 -include Documentation/include.mk
-my_syntax := \$(addsuffix .syntax, $PM_FILES \$(EXE_FILES))
+SCRIPTS := scripts/ssoma-replay
+my_syntax := \$(addsuffix .syntax, $PM_FILES \$(EXE_FILES) \$(SCRIPTS))
 
 N := \$(shell echo \$\$(( \$\$(nproc 2>/dev/null || echo 2) + 1)))
 
diff --git a/TODO b/TODO
index b6a3af3..1a40311 100644
--- a/TODO
+++ b/TODO
@@ -44,6 +44,3 @@ TODO items for public-inbox
 * more test cases (use git fast-import to speed up creation)
 
 * large mbox/Maildir/MH/NNTP spool import (use git fast-import)
-
-* improve + document mlmmj integration, currently only at:
-  http://bogomips.org/unicorn-public/20140508084301.GA2033%40dcvr.yhbt.net/
diff --git a/scripts/ssoma-replay b/scripts/ssoma-replay
new file mode 100755
index 0000000..bfcea0a
--- /dev/null
+++ b/scripts/ssoma-replay
@@ -0,0 +1,95 @@
+#!/usr/bin/perl -w
+# Copyright (C) 2015-2016 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+#
+# A work-in-progress, but one day I hope this script is no longer
+# necessary and users will all pull from public-inboxes instead
+# of having mail pushed to them via mlmmj.
+#
+# This is for use with ssoma, using "command:" delivery mechanism
+# (as opposed to normal Maildir or mbox).
+# It assumes mlmmj-process is in /usr/bin (mlmmj requires absolute paths)
+# and assumes FOO@domain.example.com has web archives available at:
+# https://domain.example.com/FOO/
+#
+# The goal here is _anybody_ can setup a mirror of any public-inbox
+# repository and run their own mlmmj instance to replay traffic.
+=begin usage with ssoma:
+
+NAME=meta
+URL=https://public-inbox.org/meta/
+ssoma add $NAME $URL "command:/path/to/ssoma-replay -L /path/to/spool/$NAME"
+
+; $GIT_DIR/ssoma.state should have something like the following target:
+; (where GIT_DIR is ~/.ssoma/meta.git/ in the above example)
+[target "local"]
+	command = /path/to/ssoma-replay -L /path/to/spool/meta
+=cut
+use strict;
+use Email::Simple;
+use URI::Escape qw/uri_escape_utf8/;
+use File::Temp qw/tempfile/;
+my ($fh, $filename) = tempfile('pi-replay-XXXXXXXX');
+my $msg = eval {
+	local $/;
+	Email::Simple->new(<STDIN>);
+};
+select $fh;
+
+# Note: the archive URL makes assumptions about where the
+# archive is hosted.  It is currently true of all the domains
+# hosted by me.
+
+my $header_obj = $msg->header_obj;
+my $body = $msg->body;
+my $list_id = $header_obj->header('List-Id');
+my ($archive_url, $user, $domain);
+if (defined $list_id) {
+	($user, $domain) = ($list_id =~ /<(.+)\@(.+)>/g);
+
+	if (defined $domain) {
+		$archive_url = "https://$domain/$user/";
+		my $mid = $header_obj->header('Message-Id');
+		if ($mid =~ /\A<(.+)>\z/) {
+			$mid = $1;
+		}
+		$mid = uri_escape_utf8($mid);
+		$header_obj->header_set('List-Archive', "<$archive_url>");
+
+		foreach my $h (qw(Help Unsubscribe Subscribe Owner)) {
+			my $lch = lc $h;
+			my $v = "<mailto:$user+$lch\@$domain>";
+			$header_obj->header_set("List-$h", $v);
+		}
+		$header_obj->header_set('List-Post', "<mailto:$user\@$domain>");
+
+		# RFC 5064
+		$header_obj->header_set('Archived-At', "<$archive_url$mid/>");
+		$header_obj->header_set('X-Archived-At');
+	}
+}
+
+print $header_obj->as_string, $msg->crlf, $body;
+
+# don't break inline signatures
+goto out if ($body =~ /^-----BEGIN PGP SIG.+-----/sm);
+
+# try not to break dkim/dmarc/spf crap, either
+foreach (qw(domainkey-signature dkim-signature authentication-results)) {
+	goto out if defined $header_obj->header($_);
+}
+
+my $ct = $header_obj->header('Content-Type');
+
+if (!defined($ct) || $ct =~ m{\A\s*text/plain\b}i) {
+	print "\n" unless $body =~ /\n\z/s;
+	defined $archive_url or goto out;
+	# Do not add a space after '--' as is standard for user-generated
+	# signatures, we want to preserve the "-- \n" in original user sigs
+	# for mail software which splits on that.
+	print "--\n", "unsubscribe: $user+unsubscribe\@$domain\n",
+		 "archive: $archive_url\n";
+}
+out:
+$| = 1;
+exec '/usr/bin/mlmmj-process', @ARGV, '-m', $filename;

^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-05-14  2:24  7% [PATCH] import ssoma-replay example script I've been using Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).