commit a75550b384bf1d1f65aa006c144e2f725edf12b8
parent 3cb14f5abd9987168acee468c19c1f67299aecba
Author: parazyd <parazyd@dyne.org>
Date: Sun, 8 Oct 2017 21:17:18 +0200
remove build dir
Diffstat:
D | src/zlibs/publish | | | 390 | ------------------------------------------------------------------------------- |
1 file changed, 0 insertions(+), 390 deletions(-)
diff --git a/src/zlibs/publish b/src/zlibs/publish
@@ -1,390 +0,0 @@
-#!/usr/bin/env zsh
-#
-# Jaro Mail, your humble and faithful electronic postman
-#
-# a tool to easily and privately handle your e-mail communication
-#
-# Copyleft (C) 2010-2015 Denis Roio <jaromil@dyne.org>
-#
-# This source code is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This source code is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# Please refer to the GNU Public License for more details.
-#
-# You should have received a copy of the GNU Public License along with
-# this source code; if not, write to:
-# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-md=""
-uid=""
-upath=""
-pub=""
-pubdb=""
-
-# creates the database keeping up-to-date information
-# on which emails inside the maildir are already published
-pubdb_create() {
- func "create PubDB"
- [[ -r "$1" ]] && {
- error "PubDBalready exists: $1"
- return 1
- }
- cat <<EOF | ${SQL} -batch "$1"
-CREATE TABLE published
-(
- uid text collate nocase unique,
- file text collate nocase,
- path text collate nocase,
- date timestamp
-);
-EOF
- [[ $? != 0 ]] && {
- error "Error creating PubDB in $1"
- return 1
- }
- # make sure is private
- chmod 600 "$1"
- chown $_uid:$_gid "$1"
-
- return 0
-}
-
-pubdb_lookup_uid() {
- func "lookup uid from PubDB: $1"
- cat <<EOF | ${SQL} -column -batch "$pubdb"
-SELECT file FROM published
-WHERE uid IS "${(Q)1}";
-EOF
-}
-
-pubdb_insert() {
- _path="$1"
- _file=`basename "$_path"`
- # TODO:
- # _time=`${WORKDIR}/bin/fetchdate "$1" "%Y-%m-%d-%H-%M-%S"`
- func "insert mail in pubdb: $_path"
- cat <<EOF | ${SQL} -batch "$pubdb"
-INSERT INTO published (uid, file, path, date)
-VALUES ("${uid}", "${_file}", "${_path}", "`pubdb_date ${_path}`");
-EOF
- { test $? != 0 } && {
- error "insert_mail: duplicate insert in $pubdb"
- return 1
- }
- return 0
-}
-
-pubdb_list() {
- func "pubdb_list() $1"
- cat <<EOF | ${SQL} -batch "$pubdb"
-.width 64 128
-SELECT path FROM published
-ORDER BY date DESC;
-EOF
-}
-
-pubdb_getuid() {
- func "pubdb_getuid() $@"
- # TODO: path should be file only, find through all maildir
- _path="$1"
- { test -r "$_path" } || {
- error "path not found for getuid: $_path"
- # TODO: remove from pubdb
- return 1 }
- uid=`hdr "$_path" | awk '/^Message-ID:/ { gsub(/<|>|,/ , "" , $2); print $2 }'`
- uid="${(Q)uid%\\n*}" # trim
- uid="${uid/@/.}" # s/@/./
- { test "$uid" = "" } && { uid=`basename "$_path"` }
- upath=`print ${uid} | sed -e 's/\///g'`.html
-
-}
-
-# Takes an email file, parse headers and returns an RFC3339 formatted
-# date value that is suitable for both RSS and SQLITE use. Uses the
-# small C program parsedate for RFC822 parsing (borrowed from Mairix)
-pubdb_date() {
- _path="$1"
- { test -r "$_path" } || {
- error "path not found for pubdb_date: $_path"
- return 1 }
- _datestring=`hdr "$_path" | awk '/^Date/ { print $0 }'`
- func "pubdb_date parsed string: $_datestring"
- _dateseconds=`${WORKDIR}/bin/parsedate "$_datestring"`
- { test "$_dateseconds" = "-1" } && {
- error "could not parse date: $_datestring"
- return 1 }
- func "pubdb_date parsed seconds: $_dateseconds"
- _daterss=`date -d"@${_dateseconds}" --rfc-3339=seconds | sed 's/ /T/'`
- print "${_daterss}"
- return 0
-
- # ATOM spec wants a T where date puts a space
- # date --rfc-3339=seconds | sed 's/ /T/'
-}
-
-pubdb_update() {
- func "pubdb_update() $@"
- md="$1"
- [[ "$md" = "" ]] && {
- error "Pubdb_update: maildir not found: $md"
- return 1
- }
- maildircheck "${md}" || {
- error "Pubdb_update: not a maildir: $md"
- return 1
- }
- pub="${md}/pub"
- ${=mkdir} "$pub"
- pubdb="${md}/.pubdb"
- [[ -r "$pubdb" ]] || pubdb_create "$pubdb"
-
- # iterate through emails in maildir and check if new
- mails=`${=find} "${md}/new" "${md}/cur" "${md}/tmp" -type f`
- notice "Publishing emails in $md"
- for m in ${(f)mails}; do
- pubdb_getuid "$m"
- u=`pubdb_lookup_uid "$uid"`
- { test "$u" = "" } && {
- # $u is a new message
- func "publish_rss: new message found with uid: $uid"
- pubdb_insert "$m"
- }
- done
- return 0
-}
-
-
-pubdb_extract_body() {
- func "pubdb_extract_body() $*"
- _path="$1"
- { test -r "$_path" } || { error "mail not found for body extraction: $_path"; return 1 }
-
- mkdir -p ${MAILDIRS}/pubdb
- pushd ${MAILDIRS}/pubdb
-
- # check if it has already html
- _html=`mu extract "$_path" | awk '/text\/html/ {print $1; exit}'`
- [[ "$_html" = "" ]] || {
- mu extract --overwrite --parts="$_html" "$_path"
- # check if there is an html header to weed out
- grep '<body>' "$_html".part > /dev/null
- if [ $? = 0 ]; then
- awk '
-BEGIN { body=0 }
-/<body/ { body=1; next }
-/<\/body/ { body=0; next }
-{ if(body==1) print $0 }' "$_html".part | iconv -c
- else
- cat "$_html".part | iconv -c
- fi
- rm "$_html".part
- return 0 }
-
- # use the first text/plain
- _text=`mu extract "$_path" | awk '/text\/plain/ {print $1; exit}'`
- { test "$_text" = "" } || {
- mu extract --overwrite --parts="$_text" "$_path"
-
-
- case $markdown_render in
- redcarpet)
- func "render using redcarpet"
- cat "$_text".part | iconv -c | escape_html | redcarpet -
- ;;
- maruku|*)
- func "render using maruku"
- cat "$_text".part | iconv -c | escape_html | maruku --html-frag 2>/dev/null
- ;;
- esac
- rm "$_text".part
-
- return 0
- }
-
- # to make http text a link: (breaks if there are <a refs already)
- # s|www\.[^ |<]*|<a href="http://&">&</a>|g'
-
- # here we tweak the origin to avoid headers in markdown
- # preferring to interpret # as inline preformat
-
- # cat "$_text".part | sed '
- # s/^#/ /g
- # ' | iconv -c | maruku --html-frag 2>/dev/null | sed '
- # s|http://[^ |<]*|<a href="&">&</a>|g
- # s|https://[^ |<]*|<a href="&">&</a>|g
- # '
-
-# check if its an html only mail
-# _html=`mu extract "$_path" | awk '/text\/html/ {print $1; exit}'`
-# { test "$_html" = "" } || {
-# mu extract --overwrite --parts="$_html" "$_path"
-# elinks -dump "$_html".part
-# rm "$_html".part
-# return 0 }
-
-return 0
-}
-
-
-# iterate through the pubdb and publish an rss
-pubdb_render_maildir() {
- func "publish_render_maildir() $@"
- md="$1"
- [[ "$md" = "" ]] && {
- error "Publish_render_maildir: not found: $md"
- return 1
- }
- maildircheck "${md}" || {
- error "Publish_render_maildir: not a maildir: $md"
- return 1
- }
- [[ -r "${md}/pub" ]] || {
- error "Publish_render_maildir: webnomad not found in ${md}"
- error "Initialize Webnomad inside the maildir that you want published."
- return 1
- }
-
- views="${md}/views"
- pubdb="${md}/.pubdb"
- [[ -r "$pubdb" ]] || {
- error "Publish_render_maildir: first run update_pubdb for $md"; return 1 }
-
- # ${=mkdir} $TMPPREFIX/pubdb
-
- mails=`pubdb_list $md | head -n ${FEED_LIMIT:=30}`
-
- # source webnomad's configurations
- [[ -r "${md}/config.zsh" ]] && { source "${md}/config.zsh" }
-
- cat <<EOF > ${md}/views/atom.xml
-<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
-<feed xmlns="http://www.w3.org/2005/Atom">
-
-<title type="text">${TITLE}</title>
-
-<link rel="self" href="${WEB_ROOT}/atom.xml" />
-<link href="${WEB_ROOT}" />
-<id>${WEB_ROOT}/atom.xml</id>
-
-<updated>`date --rfc-3339=seconds | sed 's/ /T/'`</updated>
-<generator uri="http://www.dyne.org/software/jaro-mail/">JaroMail</generator>
-
-<subtitle type="html">${DESCRIPTION}</subtitle>
-<logo>http://dyne.org/dyne.png</logo>
-
-EOF
-
-
- cat <<EOF > "${md}/views/index.html"
-<table class="table table-hover table-condensed">
-<thead><tr>
-<th style="width:100px"><!-- from name --></th>
-<th><!-- subject --></th>
-</tr></thead>
-
-EOF
-
- # main loop
- c=0
-
- for m in ${(f)mails}; do
- [[ "$m[1]" = "." ]] && { _base=`pwd` }
- # fill in uid and upath
- pubdb_getuid "$_base/$m"
-
- # but skip entries no more existing in maildir
- [[ -r "$m" ]] || { continue }
- # TODO: remove $m from database if not in maildir
-
- _from=`hdr "$m" | ${WORKDIR}/bin/fetchaddr -x From -a`
-
- _fname=`print ${(Q)_from[(ws:,:)2]}` # | iconv -c`
-
- func "From: ${_fname}"
- _subject=`hdr "$m" | awk '
-/^Subject:/ { for(i=2;i<=NF;i++) printf "%s ", $i; printf "\n" }
-' | escape_html`
-
- # fill in uid and upath
- pubdb_getuid "$m"
-
- # fill in the body
- _body=`pubdb_extract_body $_base/$m`
-
- [[ "$_body" = "" ]] && { error "Error rendering $m" }
-
- (( ++c ))
- if (( $c < ${FEED_LIMIT:=30} )); then
-
- # write out the atom entry
- cat <<EOF >> ${md}/views/atom.xml
-
-<entry>
- <title type="html" xml:lang="en-US">$_subject</title>
- <link href="${WEB_ROOT}/${upath}" />
- <id>${WEB_ROOT}/${upath}</id>
- <updated>`pubdb_date "$m"`</updated>
-<content type="html" xml:lang="en-US">
-`print ${(f)_body} | escape_html`
-</content>
-<author>
- <name>${_fname}</name>
- <uri>${WEB_ROOT}/${upath}</uri>
-</author>
-<source>
- <title type="html">${_subject}</title>
- <subtitle type="html">From: ${_fname}</subtitle>
- <updated>${_daterss}</updated>
- <link rel="self" href="${WEB_ROOT}/${upath}" />
- <id>${WEB_ROOT}/${upath}</id>
-</source>
-</entry>
-
-EOF
-
- fi # FEED LIMIT not reached
-
- #######
- # now build an index and the sitemap
-
-
- # if using webnomad write out also the message page
- [[ -d "${md}/views" ]] && {
- act "${_datestring} - ${_subject}"
- _datestring=`hdr "$_path" | awk '/^Date/ { print $0 }'`
- cat <<EOF > "${md}/views/${upath}"
-<h2>${_subject}</h2>
-<h4>From: ${_fname} - ${_datestring}</h4>
-
-${_body}
-
-EOF
- # add entry in index
- cat <<EOF >> "${md}/views/index.html"
-
-<tr>
-<td style="vertical-align:middle;"><a href="${WEB_ROOT}/${upath}">${_fname}</a></td>
-<td style="vertical-align:middle;word-wrap:break-word">
-<a href="${WEB_ROOT}/${upath}">${_subject}</a>
-</td>
-</tr>
-
-EOF
- }
- done # loop is over
-
- cat <<EOF >> "${md}/views/atom.xml"
-</feed>
-EOF
-
- cat <<EOF >> "${md}/views/index.html"
-</table>
-EOF
-
- notice "Archive website rendering completed"
-}