sfeed_sendmail - sfeed_sendmail - sfeed to sendmail command
(HTM) git clone git://r-36.net/sfeed_sendmail
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
sfeed_sendmail (2558B)
---
1 #!/bin/sh
2
3 if [ $# -lt 2 ];
4 then
5 printf "usage: %s to-addr tsvfile\n" "$(basename "$0")" >&2
6 exit 1
7 fi
8
9 toaddr="$1"
10 tsvfile="$2"
11
12 [ -z "$SENDMAILCMD" ] && SENDMAILCMD="sendmail -f"
13 #[ -z "$SENDMAILCMD" ] && SENDMAILCMD="msmtp -f"
14
15 while IFS=$'\n' read -r line;
16 do
17 timestamp="$(printf "%s\n" "${line}" | cut -f 1)";
18 title="$(printf "%s\n" "${line}" | cut -f 2)";
19 link="$(printf "%s\n" "${line}" | cut -f 3)";
20 content="$(printf "%s\n" "${line}" | cut -f 4)";
21 contenttype="$(printf "%s\n" "${line}" | cut -f 5)";
22 id="$(printf "%s\n" "${line}" | cut -f 6)";
23 author="$(printf "%s\n" "${line}" | cut -f 7)";
24 enclosure="$(printf "%s\n" "${line}" | cut -f 8)";
25 category="$(printf "%s\n" "${line}" | cut -f 9)";
26
27 [ -z "${timestamp}" ] && timestamp="$(TZ=UTC date +%s)"
28 timestamp="$(TZ=UTC date -R -d @${timestamp})"
29
30 case "${title}" in
31 *\;*|*\<\/*|*\=\"*)
32 # HTML encoding in title.
33 title="$(printf "%s\n" "${title}" \
34 | lynx -dump -stdin -nomargins \
35 -display_charset="utf-8" \
36 -image_links \
37 -width=1024 \
38 -assume_charset="utf-8" \
39 | tr '\n' ' ')"
40 ;;
41 esac
42 [ -z "${title}" ] && title="${link}"
43 [ -z "${title}" ] && title="$(printf "%s\n" "${content}" | cut -c 10-)"
44 [ -z "${title}" ] && title="No Title"
45
46 case "${author}" in
47 *@*)
48 fromaddr="${author}"
49 ;;
50 *)
51 fromaddr="$(printf "\"%s\" <none@none.no>" "${author}")"
52 ;;
53 esac
54
55 {
56 printf "From: %s\r\n" "${fromaddr}"
57 printf "To: %s\r\n" "${toaddr}"
58 printf "Date: %s\r\n" "${timestamp}"
59 if [ -n "${title}" ];
60 then
61 printf "Subject: %s\r\n" "$(rputil -e "${title}" 2>/dev/null)"
62 fi
63 printf "Content-Type: text/plain; charset=\"UTF-8\"\r\n"
64 if [ -n "${link}" ];
65 then
66 printf "X-RSS-URL: %s\r\n" "${link}"
67 printf "X-RSS-Feed: %s\r\n" "${link}"
68 fi
69 printf "X-RSS-File: %s\r\n" "${tsvfile}"
70 if [ -n "${id}" ];
71 then
72 printf "X-RSS-ID: %s\r\n" "${id}"
73 fi
74 if [ -n "${category}" ];
75 then
76 printf "X-RSS-Category: %s\r\n" "${category}"
77 fi
78 printf "User-Agent: sfeed_sendmail/1.0\r\n"
79 printf "\r\n"
80
81 if [ "${contenttype}" = "html" ];
82 then
83 printf "%s\n" "${content}" \
84 | sed 's,\\n,\n,g; s,\\t,\t,g; s,\\\\,\\,g' \
85 | lynx -dump -stdin -nomargins \
86 -display_charset="utf-8" \
87 -image_links \
88 -assume_charset="utf-8"
89 else
90 printf "%s\n" "${content}" \
91 | sed 's,\\n,\n,g; s,\\t,\t,g; s,\\\\,\\,g'
92 fi
93
94 printf "\n"
95 [ -n "${link}" ] && printf "URL: %s\n" "${link}"
96 [ -n "${enclosure}" ] && printf "Enclosure: %s\n" "${enclosure}"
97
98 #} | cat
99 } | $SENDMAILCMD "${fromaddr}" "${toaddr}"
100 done
101