From e50950894f3cf0b5df8c9b6b236cb2d923dfc39e Mon Sep 17 00:00:00 2001 From: Jaromil Date: Mon, 1 May 2017 09:23:36 +0200 Subject: [PATCH] character encoding conversion in from field when needed --- maildir | 201 ++++++-------------------------------------------------- 1 file changed, 21 insertions(+), 180 deletions(-) diff --git a/maildir b/maildir index 3cdbf9f..9744b6e 100755 --- a/maildir +++ b/maildir @@ -168,6 +168,25 @@ mail_getinfo() { mail_from=`print "$_hdr" | cut -d'<' -f1 | awk ' /^From/ { for(i=2;i<=NF;i++) printf "%s ", $i; } ' | sed 's/"//g'` + # if from is base64 encapsulated, get it out + # i.e: =?UTF-8?B?w5Zyc2FuIMWeZW5hbHA=?= + [[ "${mail_from[1]}" = "=" ]] && [[ "${mail_from[2]}" = "?" ]] && { + _enc="${mail_from[(ws:?:)2]}" + func "CONVERT: $mail_from" + # can be B or Q. B is for base64 + if [[ "${mail_from[(ws:?:)3]}" = "B" ]]; then + _tmp=`print "${mail_from[(ws:?:)4]}" | recode ${_enc}/base64..UTF8` + [[ "$_tmp" = "" ]] || mail_from=$_tmp + elif [[ "${mail_from[(ws:?:)3]}" = "Q" ]]; then + _tmp=`print "${mail_from[(ws:?:)4]}" | recode ${_enc}/QP..UTF8` + [[ "$_tmp" = "" ]] || mail_from=$_tmp + fi + func "converted to $mail_from" + + } + + + mail_subj=`print "$_hdr" | awk ' @@ -236,33 +255,13 @@ BEGIN { body=0 } warning "nothing found to render in $_path" return 1 - # to make http text a link: (breaks if there are &|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://[^ |<]*|&|g - # s|https://[^ |<]*|&|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 } } mail_index_render() { fn mail_index_render $* _db="${mdsrc}.db" - req=(mdsrc mdname) + req=(mdsrc mdname) freq=($mdsrc $_db) ckreq || return 1 @@ -293,7 +292,7 @@ EOF mail_atom_render() { fn mail_atom_render $* _db="${mdsrc}.db" - req=(mdsrc mdname) + req=(mdsrc mdname) freq=($mdsrc $_db) ckreq || return 1 @@ -348,161 +347,3 @@ EOF EOF } - - # 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=`maildb_list $md | head -n ${FEED_LIMIT:=30}` - - # source webnomad's configurations - [[ -r "${md}/config.zsh" ]] && { source "${md}/config.zsh" } - - cat < ${md}/views/atom.xml - - - -${TITLE} - - - -${WEB_ROOT}/atom.xml - -`date --rfc-3339=seconds | sed 's/ /T/'` -JaroMail - -${DESCRIPTION} -http://dyne.org/dyne.png - -EOF - - - cat < "${md}/views/index.html" - - - - - - -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 <> ${md}/views/atom.xml - - - $_subject - - ${WEB_ROOT}/${upath} - `pubdb_date "$m"` - -`print ${(f)_body} | escape_html` - - - ${_fname} - ${WEB_ROOT}/${upath} - - - ${_subject} - From: ${_fname} - ${_daterss} - - ${WEB_ROOT}/${upath} - - - -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 < "${md}/views/${upath}" -

${_subject}

-

From: ${_fname} - ${_datestring}

- -${_body} - -EOF - # add entry in index - cat <> "${md}/views/index.html" - -
- - - - -EOF - } - done # loop is over - - cat <> "${md}/views/atom.xml" - -EOF - - cat <> "${md}/views/index.html" -
${_fname} -${_subject} -
-EOF - - notice "Archive website rendering completed" - }