From 55b342a896877fd18b3c7064be4d25104d1a8eb1 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 8 Mar 2018 11:41:20 +0400 Subject: [PATCH 01/16] match future lca lists --- .mutt/lists | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mutt/lists b/.mutt/lists index d36896f..7b41ea1 100644 --- a/.mutt/lists +++ b/.mutt/lists @@ -38,7 +38,7 @@ subscribe debconf16-team@lists.debian.org subscribe debconf-kids@lists.debian.org subscribe lca-announce@lists.linux.org.au -subscribe chat@lists.(lca20[0-9][0-9]\.)?linux.org.au +subscribe (lca20[0-9][0-9]-)?chat@lists.(lca20[0-9][0-9]\.)?linux.org.au subscribe yct@lists.lca20[1-9][0-9]\.linux\.org\.au subscribe area-muc@teams.debian.net -- 2.39.5 From f44295774f814c854c0cde49fc59b5a756ffcda8 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 8 Mar 2018 11:41:32 +0400 Subject: [PATCH 02/16] source multiple mailboxes files --- .mutt/muttrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.mutt/muttrc b/.mutt/muttrc index ad2d8d2..2b54bdf 100644 --- a/.mutt/muttrc +++ b/.mutt/muttrc @@ -4547,8 +4547,9 @@ source $my_confdir/lists source $my_confdir/spam source $my_confdir/hooks -set my_mailboxes = `ls ~/.var/offlineimap/mailboxes 2>/dev/null || echo /dev/null` -source $my_mailboxes +set my_offlineimap_mailboxes = "$VARDIR/offlineimap/mailboxes" +set my_mutt_mailboxes = "$VARDIR/mutt/mailboxes" +source "cat $my_offlineimap_mailboxes $my_mutt_mailboxes 2>/dev/null|" set alias_file="$my_confdir/aliases" source "test -f $alias_file && cat $alias_file 2>/dev/null || echo unset alias_file|" -- 2.39.5 From 3811e4be579a17d24400251933aaec704059bf98 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 8 Mar 2018 12:19:33 +0400 Subject: [PATCH 03/16] list mailboxes with cron, not offlineimap --- .crontab.d/mutt | 1 + .gitignore.d/mutt | 1 + .mutt/list-mailboxes | 6 ++++++ .mutt/muttrc | 4 ++-- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100755 .mutt/list-mailboxes diff --git a/.crontab.d/mutt b/.crontab.d/mutt index 6b170bf..c144ab5 100644 --- a/.crontab.d/mutt +++ b/.crontab.d/mutt @@ -1 +1,2 @@ 29 4 * * * [[ -d $VARDIR/mutt/header_cache ]] && echo '- *' >| $VARDIR/mutt/header_cache/.backup-filter && autoload -U zargs && zargs --no-run-if-empty -- $VARDIR/mutt/header_cache/*~*/.gitignore(.NDa+28) -- rm -- +6 * * * * ~/.mutt/list-mailboxes ~/mail =inbox >| $VARDIR/mutt/mailboxes diff --git a/.gitignore.d/mutt b/.gitignore.d/mutt index 6015555..4d243a4 100644 --- a/.gitignore.d/mutt +++ b/.gitignore.d/mutt @@ -15,6 +15,7 @@ !/.mutt/headers !/.mutt/hooks !/.mutt/keybindings +!/.mutt/list-mailboxes !/.mutt/lists !/.mutt/mailcap-edit-wrapper !/.mutt/muttrc diff --git a/.mutt/list-mailboxes b/.mutt/list-mailboxes new file mode 100755 index 0000000..5e2460c --- /dev/null +++ b/.mutt/list-mailboxes @@ -0,0 +1,6 @@ +#!/bin/sh + +find "$1" -type d -name cur -printf '%h\n' | \ + sed -e "s,^$1/,=,g" -e "s,^$1\$,$2," | \ + egrep -v '^=(spool|discard|retrain(/(sp|h)am)?)$' | \ + sort | xargs echo mailboxes diff --git a/.mutt/muttrc b/.mutt/muttrc index 2b54bdf..9315ab1 100644 --- a/.mutt/muttrc +++ b/.mutt/muttrc @@ -4547,9 +4547,9 @@ source $my_confdir/lists source $my_confdir/spam source $my_confdir/hooks -set my_offlineimap_mailboxes = "$VARDIR/offlineimap/mailboxes" set my_mutt_mailboxes = "$VARDIR/mutt/mailboxes" -source "cat $my_offlineimap_mailboxes $my_mutt_mailboxes 2>/dev/null|" +source "test -f $my_mutt_mailboxes && cat $my_mutt_mailboxes| +#source "$my_confdir/list-mailboxes $folder $spoolfile|" set alias_file="$my_confdir/aliases" source "test -f $alias_file && cat $alias_file 2>/dev/null || echo unset alias_file|" -- 2.39.5 From ba0b3ce951fb0b9942149f0943e3f078853d2f18 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 8 Mar 2018 12:45:12 +0400 Subject: [PATCH 04/16] trailing slash to maildir in case it's a symlink --- .mutt/list-mailboxes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mutt/list-mailboxes b/.mutt/list-mailboxes index 5e2460c..c65c47c 100755 --- a/.mutt/list-mailboxes +++ b/.mutt/list-mailboxes @@ -1,6 +1,6 @@ #!/bin/sh -find "$1" -type d -name cur -printf '%h\n' | \ +find "$1/" -type d -name cur -printf '%h\n' | \ sed -e "s,^$1/,=,g" -e "s,^$1\$,$2," | \ egrep -v '^=(spool|discard|retrain(/(sp|h)am)?)$' | \ sort | xargs echo mailboxes -- 2.39.5 From c734a415a3bcbdfde490557edf83d0c3158a107d Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 8 Mar 2018 11:23:02 +0100 Subject: [PATCH 05/16] escape the default mailbox for the '=' is zsh --- .crontab.d/mutt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.crontab.d/mutt b/.crontab.d/mutt index c144ab5..5aa06bd 100644 --- a/.crontab.d/mutt +++ b/.crontab.d/mutt @@ -1,2 +1,2 @@ 29 4 * * * [[ -d $VARDIR/mutt/header_cache ]] && echo '- *' >| $VARDIR/mutt/header_cache/.backup-filter && autoload -U zargs && zargs --no-run-if-empty -- $VARDIR/mutt/header_cache/*~*/.gitignore(.NDa+28) -- rm -- -6 * * * * ~/.mutt/list-mailboxes ~/mail =inbox >| $VARDIR/mutt/mailboxes +6 * * * * ~/.mutt/list-mailboxes ~/mail '=inbox' >| $VARDIR/mutt/mailboxes -- 2.39.5 From 7a2362cccd490f567bbacf77018e7db34453e99f Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 11 Mar 2018 13:48:05 +0100 Subject: [PATCH 06/16] more basic sidebar divider --- .mutt/sidebar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.mutt/sidebar b/.mutt/sidebar index 97d1cac..b8d027c 100644 --- a/.mutt/sidebar +++ b/.mutt/sidebar @@ -1,6 +1,6 @@ set sidebar_width=20 set sidebar_visible=yes -set sidebar_divider_char="│" +set sidebar_divider_char=" " set sidebar_folder_indent=yes set sidebar_short_path=yes set sidebar_indent_string=" " @@ -14,7 +14,7 @@ bind index,pager \e sidebar-open bind index,pager \e sidebar-page-up bind index,pager \e sidebar-page-down -bind index,pager \\ sidebar-toggle-visible +bind index,pager \\ sidebar-toggle-visible color sidebar_new red default color sidebar_divider white black -- 2.39.5 From a941246cf7b167c2221170054d7d4ab22d0d4dc3 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Mon, 19 Mar 2018 11:22:31 +0100 Subject: [PATCH 07/16] filter out spam mailbox --- .mutt/list-mailboxes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mutt/list-mailboxes b/.mutt/list-mailboxes index c65c47c..497a253 100755 --- a/.mutt/list-mailboxes +++ b/.mutt/list-mailboxes @@ -2,5 +2,5 @@ find "$1/" -type d -name cur -printf '%h\n' | \ sed -e "s,^$1/,=,g" -e "s,^$1\$,$2," | \ - egrep -v '^=(spool|discard|retrain(/(sp|h)am)?)$' | \ + egrep -v '^=(sp(ool|am)|discard|retrain(/(sp|h)am)?)$' | \ sort | xargs echo mailboxes -- 2.39.5 From 37ca89d75972f497133da07a56f09d21da55fee9 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Tue, 3 Apr 2018 14:28:25 +1200 Subject: [PATCH 08/16] remove notmuch search overrides --- .mutt/keybindings | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.mutt/keybindings b/.mutt/keybindings index 6a33e3b..5fc17ec 100644 --- a/.mutt/keybindings +++ b/.mutt/keybindings @@ -80,8 +80,8 @@ macro index,pager \er 'set my_editor="$editor"set my_editor="$editor"set editor="~/.mutt/reuse-message $my_editor"set editor="$my_editor"' "invoke normal editor to edit message" macro index,pager \el 'set my_editor="$editor"set editor="~/.mutt/reuse-message $my_editor"set editor="$my_editor"' "invoke normal editor to edit message" -macro index "unset wait_key~/.mutt/mutt-notmuch --prompt search~/.cache/mutt_results" "search mail (using notmuch)" -macro index "unset wait_key~/.mutt/mutt-notmuch thread~/.cache/mutt_resultsset wait_key" "search and reconstruct owning thread (using notmuch)" +# override F6 from notmuch-mutt +macro index "" "do nothing" macro attach e 'set my_mailcap_path="$mailcap_path"set mailcap_path="~/.mutt/mailcap-edit-wrapper"set mailcap_path="$my_mailcap_path"' "edit temporary file of attachment" -- 2.39.5 From efa3b67730c201eb1cc453eeaa42188638cefa8e Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 12 Apr 2018 10:36:41 +1200 Subject: [PATCH 09/16] new email address --- .mutt/alternates | 1 + 1 file changed, 1 insertion(+) diff --git a/.mutt/alternates b/.mutt/alternates index 562e854..a8a8c7e 100644 --- a/.mutt/alternates +++ b/.mutt/alternates @@ -29,6 +29,7 @@ alternates .+@tahi\.(vc|cc|kiwi\.nz|ventures) alternates .+@grounded.ventures alternates .+@portfolio\.tahi\.v(c|entures) alternates martin@keyp\.io +alternates m@rtin\.kiwi #alternates .+@(rw|int|home)\.madduck\.net # vim:ft=muttrc -- 2.39.5 From 843e189b8e12d8e580b9d999baa5245722f9db6c Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 12 Aug 2018 13:16:11 +1200 Subject: [PATCH 10/16] rename editing mailcap file --- .mutt/keybindings | 2 +- .mutt/mailcap-edit-wrapper | 2 -- .mutt/mailcap.editing | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 .mutt/mailcap-edit-wrapper create mode 100644 .mutt/mailcap.editing diff --git a/.mutt/keybindings b/.mutt/keybindings index 5fc17ec..a23c46f 100644 --- a/.mutt/keybindings +++ b/.mutt/keybindings @@ -83,7 +83,7 @@ macro index,pager \el 'set my_editor="$editor" "" "do nothing" -macro attach e 'set my_mailcap_path="$mailcap_path"set mailcap_path="~/.mutt/mailcap-edit-wrapper"set mailcap_path="$my_mailcap_path"' "edit temporary file of attachment" +macro attach e 'set my_mailcap_path="$mailcap_path"set mailcap_path="~/.mutt/mailcap.editing"set mailcap_path="$my_mailcap_path"' "edit temporary file of attachment" macro index,pager M 'set my_weed="$weed"set noweedformail -czx X-RSS-URL: | xargs sensible-browserset weed="$my_weed"' diff --git a/.mutt/mailcap-edit-wrapper b/.mutt/mailcap-edit-wrapper deleted file mode 100644 index ee271ae..0000000 --- a/.mutt/mailcap-edit-wrapper +++ /dev/null @@ -1,2 +0,0 @@ -application/*; chmod +w '%s' && run-mailcap --action=edit %t:'%s' -image/*; chmod +w '%s' && run-mailcap --action=edit %t:'%s' diff --git a/.mutt/mailcap.editing b/.mutt/mailcap.editing new file mode 100644 index 0000000..6e94104 --- /dev/null +++ b/.mutt/mailcap.editing @@ -0,0 +1,2 @@ +application/*; chmod +w %s && run-mailcap --action=edit %t:%s +image/*; chmod +w %s && run-mailcap --action=edit %t:%s -- 2.39.5 From ab4a7bac0c452d69330b94acb6871f37a952217f Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 12 Aug 2018 13:16:21 +1200 Subject: [PATCH 11/16] remove obsolete files --- .mutt/error | 7 ------- .mutt/offline | 3 --- 2 files changed, 10 deletions(-) delete mode 100755 .mutt/error delete mode 100644 .mutt/offline diff --git a/.mutt/error b/.mutt/error deleted file mode 100755 index ea81cf1..0000000 --- a/.mutt/error +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -set -eu - -ret=$1; shift -msg="$@"; msg="${msg%% --*}" -echo "$msg" -exit $ret diff --git a/.mutt/offline b/.mutt/offline deleted file mode 100644 index be1674d..0000000 --- a/.mutt/offline +++ /dev/null @@ -1,3 +0,0 @@ -set sendmail="~/.mutt/sendmail" - -# vim:ft=muttrc -- 2.39.5 From 71e4ef2b822967ea63b9885edb35e39c4cf18a06 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 12 Aug 2018 13:17:17 +1200 Subject: [PATCH 12/16] import viewmailattachments script from alana --- .mutt/keybindings | 2 + .mutt/viewmailattachments | 381 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 383 insertions(+) create mode 100755 .mutt/viewmailattachments diff --git a/.mutt/keybindings b/.mutt/keybindings index a23c46f..3a76bee 100644 --- a/.mutt/keybindings +++ b/.mutt/keybindings @@ -87,4 +87,6 @@ macro attach e 'set my_mailcap_path="$mailcap_path"set my_weed="$weed"set noweedformail -czx X-RSS-URL: | xargs sensible-browserset weed="$my_weed"' +macro index,pager 'set my_pipe_decode="$pipe_decode"unset pipe_decode~/.mutt/viewmailattachmentsset pipe_decode="$my_pipe_decode"' "view attachments in browser" + # vim:sw=12:noet:sts=12:ts=12:ft=muttrc diff --git a/.mutt/viewmailattachments b/.mutt/viewmailattachments new file mode 100755 index 0000000..9ab3650 --- /dev/null +++ b/.mutt/viewmailattachments @@ -0,0 +1,381 @@ +#! /usr/bin/env python + +# Source: https://raw.githubusercontent.com/akkana/scripts/master/viewmailattachments + +# Take an mbox HTML message (e.g. from mutt), split it +# and rewrite it so all of its attachments can be viewed in a browser +# (perhaps after being converted to HTML from DOC or whatever first). +# +# Can be run from within a mailer like mutt, or independently +# on a single message file. +# +# Grew out of a simpler script called viewhtmlmail. +# +# Copyright 2015 by Akkana Peck. Share and enjoy under the GPL v2 or later. +# Changes: +# Holger Klawitter 2014: create a secure temp file and avoid temp mbox + +# To use it from mutt, put the following lines in your .muttrc: +# macro index "~/bin/viewmailattachments\n" "View attachments in browser" +# macro pager "~/bin/viewmailattachments\n" "View attachments in browser" + +import os, sys +import re +import time +import shutil +import email, email.header, mimetypes +import tempfile +import subprocess +from bs4 import BeautifulSoup + +################################################ +# Some prefs: +USE_WVHTML_FOR_DOC = False +BROWSER_ARGS = [] +TMPDIR=os.path.join(os.getenv('TMPDIR'), 'volatile') + +# How many seconds do we need to wait for unoconv? +# It defaults to 6, but on a 64-bit machine that's not enough. +UNOCONV_STARTUP_TIME = "10" + +# Does the browser need a one-time argument for bringing up an initial window, +# like Firefox's -private-window -new-instance ? +BROWSER_FIRST_ARG = [] + +# What browser to use: +USE_QUICKBROWSE = False + +if USE_QUICKBROWSE: + BROWSER = "quickbrowse" + + # Browser argument to precede new tabs: + BROWSER_FIRST_ARGS = [] + BROWSER_ARGS = [ "--new-tab" ] + + # Will the browser block when first run until its window is closed? + # If so, we have to run it in the background. + BROWSER_BACKGROUND = False + + # Should we convert PDF to HTML? Depends on BROWSER: + # Firefox has a built-in PDF viewer, but quickbrowse doesn't. + CONVERT_PDF_TO_HTML = False + +else: # Firefox in private browsing mode + BROWSER = "firefox" + + # Not clear what to do here: Firefox has a built-in PDF viewer, + # but for some mime types it can't figure out that it should use it. + BROWSER_FIRST_ARGS = [ "-private-window" ] + BROWSER_ARGS = [ "-new-tab", "-private-window" ] + # Firefox doesn't run in the background. + BROWSER_BACKGROUND = True + + CONVERT_PDF_TO_HTML = False + +# End global prefs +################################################ + +# Temporary for debugging: +class mysubprocess: + @staticmethod + def call(arr): + print("\n\n================\n=== Calling: %s" % str(arr)) + subprocess.call(arr) + + @staticmethod + def call_bg(arr): + print("\n\n================\n=== Calling in background: %s" % str(arr)) + subprocess.Popen(arr, shell=False, + stdin=None, stdout=None, stderr=None) + +def view_message_attachments(fp, tmpdir): + '''View message attachments coming from the file-like object fp. + ''' + + msg = email.message_from_string(fp.read()) + + html_part = None + counter = 1 + subfiles = [] + subparts = [] + htmlfiles = [] + htmlparts = [] + + def tmp_file_name(part): + partfile=part.get_filename() + if partfile: + n, enc = email.header.decode_header(partfile)[0] + if n: + partfile = n.decode(enc) if enc else n + + # Applications should really sanitize the given filename so that an + # email message can't be used to overwrite important files. + # As a first step, warn about ../ + if partfile and '../' in partfile: + print("Eek! Possible security problem in filename %s" % partfile) + return None + + # Make a filename in the tmp dir: + if not partfile: + ext = mimetypes.guess_extension(part.get_content_type()) + if not ext: + # Use a generic bag-of-bits extension + ext = '.bin' + return tempfile.mkstemp(dir=tmpdir, suffix=ext, prefix='part-')[1] + else: + return os.path.join(tmpdir, partfile) + + def save_tmp_file(part): + '''Saves this part's payload to a tmp file, returning the new filename. + ''' + partfile = tmp_file_name(part) + + tmpfile = open(partfile, "wb") + tmpfile.write(part.get_payload(decode=True)) + tmpfile.close() + return partfile + + # Walk through the message a first, preliminary time + # to separate out any images that might be referred to by + # an HTML part. + for part in msg.walk(): + # walk() includes the top-level message + if part == msg: + # print " Skipping the top-level message" + continue + + if part.get_content_type() != "multipart/related": + continue + + # It's multipart. Walk the subtree looking for image children. + for child in part.walk(): + # print " ", child.get_content_type() + + # At least for now, only save images as parts of multipart. + if child.get_content_maintype() != "image": + continue + + filename = save_tmp_file(child) + # print " Saved to", filename + + # Rewrite image and other inline URLs in terms of content-id. + # Mailers may use Content-Id or Content-ID (or, presumably, + # other capitalizations). So we can't just look it up simply. + content_id = None + for k in list(child.keys()): + if k.lower() == 'content-id': + # Remove angle brackets, if present. + # child['Content-Id'] is unmutable: attempts to change it + # are just ignored. Copy it to a local mutable string. + content_id = child[k] + if content_id.startswith('<') and \ + content_id.endswith('>'): + content_id = content_id[1:-1] + + subfiles.append({ 'filename': filename, + 'Content-Id': content_id }) + subparts.append(child) + counter += 1 + fp = open(filename, 'wb') + fp.write(child.get_payload(decode=True)) + fp.close() + break # no need to look at other keys + + # if not content_id: + # print filename, "doesn't have a Content-Id, not saving" + # # print "keys:", child.keys() + + # print "Subfiles:" + # for sf in subfiles: + # print sf + + # Call up the browser window right away, + # so the user can see something is happening. + # Firefox, alas, has no way from the commandline of calling up + # a new private window with content, then replacing that content. + # So we'll create a file that refreshes, so that when content is ready, + # it can redirect to the first content page. + def write_to_index(outfile, msg, timeout_secs, redirect_url): + if not redirect_url: + redirect_url = "file://" + outfile + ofp = open(outfile, "w") + ofp.write(''' + + + + +





%s + +''' % (timeout_secs, redirect_url, msg)) + ofp.close() + + redirect_timeout = 3 + pleasewait_file = tmpdir + "/index.html" + write_to_index(pleasewait_file, "Please wait ...", redirect_timeout, None) + + cmd = [ BROWSER ] + if BROWSER_FIRST_ARGS: + cmd += BROWSER_FIRST_ARGS + + cmd.append("file://" + pleasewait_file) + print("Calling: %s" % ' '.join(cmd)) + if BROWSER_BACKGROUND: + mysubprocess.call_bg(cmd) + else: + mysubprocess.call(cmd) + + # "data:text/html,




Translating documents, please wait ..." + # Use JS if we can figure out how to close or replace + # the "please wait" tab once we have content to show. + # But for now, setTimeout() doesn't work at all + # in newly popped up private windows. + # "javascript:document.writeln('




Translating documents, please wait ...');setTimeout(function(){alert('hi');}, 500);" + # ]) + + # Now walk through looking for the real parts: + # HTML, doc and docx. + for part in msg.walk(): + + # part has, for example: + # items: [('Content-Type', 'image/jpeg'), + # ('Content-Transfer-Encoding', 'base64'), + # ('Content-ID', '<14.3631871432@web82503.mail.mud.yahoo.com>'), + # ('Content-Disposition', + # 'attachment; filename="ATT0001414.jpg"')] + # keys: ['Content-Type', 'Content-Transfer-Encoding', + # 'Content-ID', 'Content-Disposition'] + # values: ['image/jpeg', 'base64', + # '<14.3631871432@web82503.mail.mud.yahoo.com>', + # 'attachment; filename="ATT0001414.jpg"'] + + # multipart/* are just containers + #if part.get_content_maintype() == 'multipart': + if part.is_multipart() or part.get_content_type == 'message/rfc822': + continue + + if part.get_content_maintype() == "application": + partfile = save_tmp_file(part) + fileparts = os.path.splitext(partfile) + htmlfilename = fileparts[0] + ".html" + + if part.get_content_subtype() == "msword" and USE_WVHTML_FOR_DOC: + mysubprocess.call(["wvHtml", partfile, htmlfilename]) + htmlfiles.append(htmlfilename) + + elif part.get_content_subtype() == \ + "vnd.openxmlformats-officedocument.wordprocessingml.document" \ + or part.get_content_subtype() == "msword": + mysubprocess.call(["unoconv", "-f", "html", + "-T", UNOCONV_STARTUP_TIME, + "-o", htmlfilename, partfile]) + + htmlfilename = os.path.join(fileparts[0] + ".html") + htmlfiles.append(htmlfilename) + + # unoconv conversions from powerpoint to HTML drop all images. + # Try converting to PDF instead: + elif part.get_content_subtype() == "vnd.ms-powerpoint" \ + or part.get_content_subtype() == \ + "vnd.openxmlformats-officedocument.presentationml.presentation" : + pdffile = fileparts[0] + ".pdf" + mysubprocess.call(["unoconv", "-f", "pdf", + "-o", pdffile, partfile]) + htmlfiles.append(pdffile) + + elif part.get_content_subtype() == "pdf": + if CONVERT_PDF_TO_HTML: + mysubprocess.call(["pdftohtml", "-s", partfile]) + + # But pdftohtml is idiotic about output filename + # and won't let you override it: + htmlfiles.append(fileparts[0] + "-html.html") + else: + htmlfiles.append(partfile) + + elif part.get_content_maintype() == "text" and \ + part.get_content_subtype() == 'html': + + htmlfile = tmp_file_name(part) + + fp = open(htmlfile, 'wb') + htmlsrc = part.get_payload(decode=True) + + soup = BeautifulSoup(htmlsrc, "lxml") + + # Substitute filenames for CIDs: + for tag in soup.body.find_all("img", src=True): + if tag['src'].lower().startswith("cid:"): + for sf in subfiles: + if tag['src'][4:] == sf['Content-Id']: + tag['src'] = "file://" + sf['filename'] + # for sf in subfiles: + # htmlsrc = re.sub('cid: ?' + sf['Content-Id'], + # 'file://' + sf['filename'], + # htmlsrc, flags=re.IGNORECASE) + + # If it's HTML, we may need to add a meta charset tag. Sigh. + # If it's text/plain, there's nothing we can do to fix charset. + charset = part.get_charset() + if not charset: + charset = "UTF-8" + head = soup.find("head") + if not head: + head = soup.new_tag("head") + html = soup.find("html") + if html: + html.insert(0, head) + else: + soup.insert(0, head) + + if not head.findAll("meta", attrs={"http-equiv": "encoding"}) and \ + not head.findAll("meta", attrs={"http-equiv": "content-type"}): + meta = soup.new_tag("meta") + meta["content"] = charset + meta["http-equiv"] = "encoding" + head.insert(0, meta) + meta = soup.new_tag("meta") + meta["http-equiv"] = "content-type" + meta["content"] = "text/html; charset=%s" % charset + head.insert(0, meta) + + fp.write(soup.prettify().encode("utf-8", "xmlcharrefreplace")) + fp.close() + + htmlfiles.append(htmlfile) + elif part.get_content_maintype() == "image" and part not in subparts: + partfile = save_tmp_file(part) + htmlfiles.append(partfile) + + # Done processing attachments. Call the browser for everything. + if htmlfiles: + # For the first URL, just put a redirect in + write_to_index(pleasewait_file, + "Redirecting to file://" + htmlfiles[0], + 0, "file://" + htmlfiles[0]) + + for f in htmlfiles[1:]: + # If we don't wait for the new window to pop up before + # calling new-tab, bad things will happen: the document + # may load in a new tab in the old window and THEN pop up + # an unwanted third window. Go firefox. + # Not clear whether this is true for all browsers. + time.sleep(1) + if BROWSER_ARGS: + mysubprocess.call([BROWSER] + BROWSER_ARGS + ["file://" + f]) + else: + mysubprocess.call([BROWSER, "file://" + f]) + + # Wait a while to make sure the browser has loads the imgaes, then clean up. + time.sleep(6) + shutil.rmtree(tmpdir) + +if __name__ == '__main__': + tmpdir = tempfile.mkdtemp(dir=TMPDIR) + + if len(sys.argv) > 1: + for f in sys.argv[1:]: + fp = open(f) + view_message_attachments(fp, tmpdir) + fp.close() + else: + view_message_attachments(sys.stdin, tmpdir) -- 2.39.5 From 76227d1c302ee76d82c037e923c70edc61fd5aea Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 12 Aug 2018 13:19:48 +1200 Subject: [PATCH 13/16] Attachment viewing in the background This makes use of Mutt's internal mailcap handling to inject a script before deferring to run-mailcap, saving the attachment to a temporary file, backgrounding the viewer process, and then cleaning up the temporary stuff after its return. Stdout/stderr are reported using Awesome's naughty library, so this will not work on other window managers for now. text/html files are handled differently to address the issue that Firefox would return to the shell before the remote process even accessed the file (https://bugzilla.mozilla.org/show_bug.cgi?id=1482024) --- .mutt/bgrun | 60 +++++++++++++++++++++++++++++++++++++ .mutt/browserrun | 1 + .mutt/mailcap.backgrounding | 6 ++++ .mutt/muttrc | 1 + 4 files changed, 68 insertions(+) create mode 100755 .mutt/bgrun create mode 120000 .mutt/browserrun create mode 100644 .mutt/mailcap.backgrounding diff --git a/.mutt/bgrun b/.mutt/bgrun new file mode 100755 index 0000000..e0bcd20 --- /dev/null +++ b/.mutt/bgrun @@ -0,0 +1,60 @@ +#!/bin/sh + +SELF="${0##*/}" + +if [ -z "$TMPDIR" ]; then + TMPDIR=/tmp +elif [ -d "${TMPDIR}/volatile" ]; then + TMPDIR="${TMPDIR}/volatile" +fi +export TMPDIR +TMPDIR=$(mktemp -dp "$TMPDIR" mutt.XXXXXXXXXX) +trap "rm -rf '$TMPDIR'" 1 2 3 4 5 6 7 8 10 11 12 13 14 15 + +BASENAME="${1##*/}" +TEMPFILE="${TMPDIR}/${BASENAME}" + +notify() { + if [ -x "$(command -v awesome-client)" ]; then + awesome-client <<-_eof + local naughty = require("naughty") + naughty.notify({ preset = naughty.config.presets.low, + title = "$3", + text = [[stdout: + $(sed -e 's,\",\\\",g' "$1") + stderr: + $(sed -e 's,\",\\\",g' "$2")]] + }) + _eof + fi +} + +case "$SELF" in + (bgrun) + # make a copy of the file, then launch a shell process in the background + # to divert to run-mailcap, after which the temporary directory gets + # cleaned up. + cp -a "$1" $TMPDIR + MIMETYPE="$2" + ( + run-mailcap --action=view "$MIMETYPE":"$TEMPFILE" + rm -rf "$TMPDIR" + if [ -s "$TMPDIR/output.stdout" ] || [ -s "$TMPDIR/output.stderr" ]; then + notify $TMPDIR/output.stdout $TMPDIR/output.stderr \ + "Output from mutt/$SELF on $BASENAME" + fi + ) & + trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15 + ;; + (browserrun) + # hack to stay around until the browser has read the file: make a fifo and + # wait for the cat process to finish writing to it, which means that it + # must have been consumed on the other end. + mkfifo "$TEMPFILE" + INPUTFILE="$1" + cat "$INPUTFILE" > $TEMPFILE & + sensible-browser "$TEMPFILE" > $TMPDIR/output.stdout 2> $TMPDIR/output.stderr + wait + ;; +esac + diff --git a/.mutt/browserrun b/.mutt/browserrun new file mode 120000 index 0000000..b07e7aa --- /dev/null +++ b/.mutt/browserrun @@ -0,0 +1 @@ +bgrun \ No newline at end of file diff --git a/.mutt/mailcap.backgrounding b/.mutt/mailcap.backgrounding new file mode 100644 index 0000000..37b57ed --- /dev/null +++ b/.mutt/mailcap.backgrounding @@ -0,0 +1,6 @@ +# +# Mutt mailcap for backgrounding + +text/html; ~/.mutt/browserrun %s; description=Open file in browser via FIFO +application/*; ~/.mutt/bgrun %s %t; description=Backgrounded run of run-mailcap +image/*; ~/.mutt/bgrun %s %t; description=Backgrounded run of run-mailcap diff --git a/.mutt/muttrc b/.mutt/muttrc index 9315ab1..4281b4b 100644 --- a/.mutt/muttrc +++ b/.mutt/muttrc @@ -1552,6 +1552,7 @@ set include=yes # This variable specifies which files to consult when attempting to # display MIME bodies not directly supported by Mutt. # +set mailcap_path="$my_confdir/mailcap.backgrounding" # # set mailcap_sanitize=yes # -- 2.39.5 From 893251e8f6b86521f95558bced4b773d7854b336 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 12 Aug 2018 13:20:50 +1200 Subject: [PATCH 14/16] improved HTML auto_view --- .mutt/mailcap.htmldump | 5 +++++ .mutt/muttrc | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .mutt/mailcap.htmldump diff --git a/.mutt/mailcap.htmldump b/.mutt/mailcap.htmldump new file mode 100644 index 0000000..13fda90 --- /dev/null +++ b/.mutt/mailcap.htmldump @@ -0,0 +1,5 @@ +# +# Mutt mailcap for dumping HTML to text +# + +text/html; w3m -T %t -I %{charset} -O utf-8 -dump %s; description=HTML Text; nametemplate=%s.html; copiousoutput diff --git a/.mutt/muttrc b/.mutt/muttrc index 4281b4b..1ab606a 100644 --- a/.mutt/muttrc +++ b/.mutt/muttrc @@ -1552,7 +1552,7 @@ set include=yes # This variable specifies which files to consult when attempting to # display MIME bodies not directly supported by Mutt. # -set mailcap_path="$my_confdir/mailcap.backgrounding" +set mailcap_path="$my_confdir/mailcap.backgrounding:$my_confdir/mailcap.htmldump" # # set mailcap_sanitize=yes # @@ -4530,14 +4530,16 @@ set xterm_set_titles=yes # Controls the format of the title bar of the xterm provided that # xterm_set_titles has been set. This string is identical in formatting # to the one used by ``$status_format''. -# +# set xterm_title="mutt@%h [%?M?%M/?%m, n:%n]%?V? [%V]?" -# +# auto_view text/html #auto_view application/x-gunzip application/x-tar-gz application/x-tar application/x-gtar #auto_view application/postscript -alternative_order text/enriched text/plain text application/postscript image/* +alternative_order multipart/mixed multipart/related text/html text/enriched text/* +#alternative_order text/plain text/enriched text/html +#alternative_order text/enriched text/plain text application/postscript image/* mime_lookup application/octet-stream source $my_confdir/colours -- 2.39.5 From c31f466633bef4b563ff1ca0358c72ffcaf6c01b Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 12 Aug 2018 13:21:11 +1200 Subject: [PATCH 15/16] do not hardcode mutt config path --- .mutt/muttrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mutt/muttrc b/.mutt/muttrc index 1ab606a..da9af1b 100644 --- a/.mutt/muttrc +++ b/.mutt/muttrc @@ -3688,7 +3688,7 @@ set save_history=100 # arguments as recipient addresses. # #set sendmail="/bin/true" -set sendmail="~/.mutt/sendmail" +set sendmail="$my_confdir/sendmail" #set sendmail="/usr/sbin/sendmail -oem -oi" # # set sendmail_wait=0 -- 2.39.5 From 8dc38a337af79fe836b7d31951088befa0dd6e1f Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Sun, 12 Aug 2018 13:21:35 +1200 Subject: [PATCH 16/16] lists cleanup --- .mutt/lists | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.mutt/lists b/.mutt/lists index 7b41ea1..1f77b28 100644 --- a/.mutt/lists +++ b/.mutt/lists @@ -86,6 +86,7 @@ subscribe gnupg-users@gnupg.org subscribe awesome@naquadah.org subscribe germany@lists.fsfe.org subscribe talk@lists.muc.ccc.de +subscribe cryptography@metzdowd.com subscribe vcs-home@lists.madduck.net @@ -98,7 +99,7 @@ subscribe (alteherren|info)@sudetia\.de subscribe ip@(v2.)?listbox.com subscribe cypherpunks@cpunks.org -subscribe sandstorm-app-committee@googlegroups.com +subscribe tuesdaysquash@lists.madduck.net subscribe .+@r2e\.madduck\.net subscribe blog@lists.madduck.net -- 2.39.5