list

scripts

Repo containing scripts to be used with dovel, and git hooks that powers our web interface.

curl https://dovel.email/scripts.tar tar

183653c

Author: blmayer (bleemayer@gmail.com)

Date: Thu Sep 7 19:04:37 2023 -0300

Parent: eab07ce

Finished simple script

Diff

diff --git a/example-1.mbox b/example-1.mbox
index 4a177c3..183906e 100644
--- a/example-1.mbox
+++ b/example-1.mbox
@@ -1,5 +1,6 @@
From derp.herp@example.com Thu Jan  1 00:00:01 2015
From: derp.herp@example.com (Derp Herp)
+To: test@localhost
Date: Thu, 02 Jan 2015 00:00:01 +0100
Subject: Another test

diff --git a/receive-localhost b/receive-localhost
index 80f1b0f..9cc1e84 100755
--- a/receive-localhost
+++ b/receive-localhost
@@ -1,18 +1,177 @@
#!/bin/sh

-# first line is From email date:
-read -r foo from date
-
-# read headers
-while read -r k v
-do
-	case "$k" in
-		"Subject:") subj="$v" ;;
-		"") break ;;
-	esac
-done
-
-# now the rest is a body
-echo "email: $from, date: $date, subject: $subj"
-echo "body:"
-cat
+# update index page
+index() {
+	cat <<- EOF
+	<!DOCTYPE html>
+	<html>
+	<head>
+		<title>dovel</title>
+		<link rel=icon href=/assets/favicon.ico>
+		<meta name="viewport" content="width=device-width, initial-scale=1"/>
+		<meta name="color-scheme" content="light dark"/>
+		<style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif;}a{color:#888}small{float:right;}</style>
+		<link rel="manifest" href="/assets/manifest.json">
+		<link rel="apple-touch-icon" sizes="200x200" href="/logo.png">
+	</head>
+	<body>
+		<center>
+	<pre>
+	_________                 ______
+	______  /________   _________  /
+	_  __  /_  __ \_ | / /  _ \_  /
+	/ /_/ / / /_/ /_ |/ //  __/  /
+	\__,_/  \____/_____/ \___//_/
+
+	</pre>
+		</center>
+	<a href=compose.html>compose</a>&emsp;
+	<a href=logout.html>logout</a>
+	EOF
+
+	ls -ogdt --time-style long-iso * | while read -r g x s d t f
+		do
+			cat <<- EOF
+			<p>
+				<a href="$f/index.html">$f</a>
+				<small>$t $d</small>
+			</p>
+			EOF
+		done
+	cat <<- EOF
+	</body>
+	</html>
+	EOF
+}
+
+# update inbox page
+inbox() {
+	cat <<- EOF
+	<!DOCTYPE html>
+	<html>
+	<head>
+		<title>dovel</title>
+		<link rel=icon href=/assets/favicon.ico>
+		<meta name="viewport" content="width=device-width, initial-scale=1"/>
+		<meta name="color-scheme" content="light dark"/>
+		<style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif}a{color:#888}small{float:right}</style>
+		<link rel="manifest" href="/assets/manifest.json">
+		<link rel="apple-touch-icon" sizes="200x200" href="/logo.png">
+	</head>
+	<body>
+	<h1>$to</h1>
+	<a href=/index.html>go back</a>
+	EOF
+
+	ls -ogdt --time-style long-iso "$to"/* | while read -r g x s d t f
+		do
+			f="$(basename "$f")"
+			qty="$(ls -1 "$to/$f" | wc -l)"
+			cat <<- EOF
+			<p>
+				<a href="$f/index.html">$f</a>
+				<small>$t $d</small><br>
+				<i>$qty emails</i>
+			</p>
+			EOF
+		done
+	cat <<- EOF
+	</body>
+	</html>
+	EOF
+}
+
+# update emails page
+emails() {
+	cat <<- EOF
+	<!DOCTYPE html>
+	<html>
+	<head>
+		<title>dovel</title>
+		<link rel=icon href=/assets/favicon.ico>
+		<meta name="viewport" content="width=device-width, initial-scale=1"/>
+		<meta name="color-scheme" content="light dark"/>
+		<style>body{max-width:600px;padding:0 15px;margin:40px auto;font-family:sans-serif}a{color:#888}small{float:right}</style>
+		<link rel="manifest" href="/assets/manifest.json">
+		<link rel="apple-touch-icon" sizes="200x200" href="/logo.png">
+	</head>
+	<body>
+	<h1>$subj</h1>
+	<a href="/$to/$subj/index.html">go back</a><br><br>
+	EOF
+
+	# print each email
+	ls -1rt "$to/$subj"/* | while read -r f
+		do
+			{
+				# print headers
+				read -r foo from date
+				cat <<- EOF
+				<details>
+				<summary>
+					From: $from<br>
+					Date: $date
+				</summary>
+				<ul>
+				EOF
+
+				while read -r k v
+				do
+					case "$k" in
+						"") break ;;
+						*) printf "<li>$k $v</li>\n" ;;
+					esac
+				done
+
+				# print body
+				cat <<- EOF
+				</ul>
+				</details>
+				<pre>
+				EOF
+				cat -
+				printf "</pre>\n<br>\n"
+			} < "$f"
+		done
+
+	# finish
+	cat <<- EOF
+	</body>
+	</html>
+	EOF
+}
+
+save() {
+	# first line is From email date:
+	read -r foo from date
+
+	# read headers
+	while read -r k v
+	do
+		case "$k" in
+			"To:") to="$v" ;;
+			"Subject:") subj="$v" ;;
+			"Message-Id:") eid="$v" ;;
+			"") break ;;
+		esac
+	done
+	eid="${eid:-$(date -Iseconds)}"
+
+	# now the rest is a body
+	cat - > /dev/null
+
+	# move temp file
+	mkdir -p "$to/$subj"
+	mv "$tmp" "$to/$subj/$eid.mbox"
+
+	# create html pages
+	mkdir -p "out/$to/$subj"
+	index > out/index.html
+	inbox > "out/$to/index.html"
+	emails > "out/$to/$subj/index.html"
+}
+
+# copy to temp file
+tmp="$(mktemp)"
+tee "$tmp" | save
+