commit d0218f100db70093d7e75ab9e152cd3d19beeb8b
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 10 Oct 2020 14:35:27 +0200
Initial commit of sfeed_sendmail.
Diffstat:
| README.md |  |  | 31 | +++++++++++++++++++++++++++++++ | 
| sfeed_sendmail |  |  | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 
2 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -0,0 +1,31 @@
+# sfeed_sendmail
+
+A utility to convert sfeed(5) format files into MIME e-mails,
+which are piped to some command compatible to sendmail(1).
+
+## Install
+
+	git clone git://r-36.net/sfeed_sendmail
+	cd sfeed_sendmail
+	make install
+
+## Variables
+
+The environment variable $SENDMAILCMD defines which command
+to execute.
+
+	$SENDMAILCMD $fromaddr $toaddr
+
+Example commands are:
+
+	SENDMAILCMD="sendmail -f"
+	SENDMAILCMD="msmtp -f"
+
+## Bugs
+
+Send them to
+
+	Christoph Lohmann <20h@r-36.net>
+
+Have fun!
+
diff --git a/sfeed_sendmail b/sfeed_sendmail
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+#set -x
+
+if [ $# -lt 1 ];
+then
+	printf "usage: %s to-addr\n" "$(basename "$0")" >&2
+	exit 1
+fi
+
+toaddr="$1"
+
+[ -z "$SENDMAILCMD" ] && SENDMAILCMD="sendmail -f"
+#[ -z "$SENDMAILCMD" ] && SENDMAILCMD="msmtp -f"
+
+while IFS=$'\n' read -r line;
+do
+	timestamp="$(printf "%s\n" "${line}" | cut -f 1)";
+	title="$(printf "%s\n" "${line}" | cut -f 2)";
+	link="$(printf "%s\n" "${line}" | cut -f 3)";
+	content="$(printf "%s\n" "${line}" | cut -f 4)";
+	contenttype="$(printf "%s\n" "${line}" | cut -f 5)";
+	id="$(printf "%s\n" "${line}" | cut -f 6)";
+	author="$(printf "%s\n" "${line}" | cut -f 7)";
+	enclosure="$(printf "%s\n" "${line}" | cut -f 8)";
+
+	[ -z "${timestamp}" ] && timestamp="$(TZ=UTC date +%s)"
+	timestamp="$(TZ=UTC date -R -d @${timestamp})"
+	[ -z "${title}" ] && title="$(printf "%s\n" "${content}" | cut -b 30-)"
+	fromaddr="$(printf "%s none@none.no" "${author}")"
+
+	{
+		printf "From: %s\r\n" "${fromaddr}"
+		printf "To: %s\r\n" "${toaddr}"
+		printf "Date: %s\r\n" "${timestamp}"
+		printf "Subject: %s\r\n" "$(rputil -e "${title}")"
+		if [ -n "${link}" ];
+		then
+			printf "X-RSS-URL: %s\r\n" "${link}"
+			printf "X-RSS-Feed: %s\r\n" "${link}"
+		fi
+		if [ -n "${id}" ];
+		then
+			printf "X-RSS-ID: %s\r\n" "${id}"
+		fi
+		printf "User-Agent: sfeed_sendmail/1.0\r\n"
+		printf "\r\n"
+
+		if [ "${contenttype}" = "html" ];
+		then
+			printf "%s\n" "${content}" \
+				| sed 's,\\n,\n,g; s,\\t,\t,g; s,\\\\,\\,g' \
+				| lynx -dump -stdin -nomargins \
+				-display_charset="utf-8" \
+				-image_links \
+				-assume_charset="utf-8"
+		else
+			printf "%s\n" "${content}" \
+				| sed 's,\\n,\n,g; s,\\t,\t,g; s,\\\\,\\,g'
+		fi
+		
+	#} | cat
+	} | $SENDMAILCMD "${fromaddr}" "${toaddr}"
+done
+