[PATCH v2] completion: complete mimetype: search prefix

Tomi Ollila domo141 at gmail.com
Tue Oct 25 07:55:18 PDT 2016


Jani Nikula <jani at nikula.org> writes:

> Use /etc/mime.types if available, with a homebrew sed parser, and fall
> back to a handful of common types otherwise.

I'd suggest the following line:

	sed -n '/^[[:alpha:]]/ s/[[:space:]].*//p' /etc/mime.types

I tested the sed expression works on Linux and Darwin (macOS sierra).

I'd guess that any future 'ietf-token' starts with alpha character, and
'x-token' always starts with 'x'.

I agree with Jani that we'd rather used some other solution but so far
using sed(1) looks like best tolerable choice there is.

Tomi

PS: used something like the following to start the emacs to send this email:


  #!/bin/sh
  :; exec "${EMACS:-emacs}" --debug-init --load "$0" "$@"; exit

  (eval-after-load "notmuch"
    (lambda ()
      (setq notmuch-command (concat (file-name-directory load-file-name)
                                    "my-notmuch-remote-command"))
      (setq smtpmail-smtp-server "smtp.gmail.com"
            smtpmail-smtp-service 465
            smtpmail-stream-type 'tls
            smtpmail-debug-info t
            smtpmail-debug-verb t
            message-send-mail-function 'message-smtpmail-send-it)
      ))
  (notmuch)

  ;; Local Variables:
  ;; mode: emacs-lisp
  ;; End:


PPS: first send failed, had to visit

  https://www.google.com/settings/security/lesssecureapps

... it would be nice to know what makes this "less secure" application ...


>  completion/notmuch-completion.bash | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash
> index 78047b5f424d..e7e7d68b04ed 100644
> --- a/completion/notmuch-completion.bash
> +++ b/completion/notmuch-completion.bash
> @@ -58,6 +58,34 @@ _notmuch_email()
>  	sed 's/[^<]*<\([^>]*\)>/\1/' | tr "[:upper:]" "[:lower:]" | sort -u
>  }
>  
> +_notmuch_mimetype()
> +{
> +    # use mime types from mime-support package if available, and fall
> +    # back to a handful of common ones otherwise
> +    if [ -r "/etc/mime.types" ]; then
> +	sed -n '/^[^ \t#]/{s/[ \t].*//;p;}' < /etc/mime.types
> +    else
> +	cat <<EOF
> +application/gzip
> +application/msword
> +application/pdf
> +application/zip
> +audio/mpeg
> +audio/ogg
> +image/gif
> +image/jpeg
> +image/png
> +message/rfc822
> +text/calendar
> +text/html
> +text/plain
> +text/vcard
> +text/x-diff
> +text/x-vcalendar
> +EOF
> +    fi
> +}
> +
>  _notmuch_search_terms()
>  {
>      local cur prev words cword split
> @@ -85,6 +113,10 @@ _notmuch_search_terms()
>  	    COMPREPLY=( $(compgen -d "$path/${cur##folder:}" | \
>  		sed "s|^$path/||" | grep -v "\(^\|/\)\(cur\|new\|tmp\)$" ) )
>  	    ;;
> +	mimetype:*)
> +	    compopt -o nospace
> +	    COMPREPLY=( $(compgen -P "mimetype:" -W "`_notmuch_mimetype ${cur}`" -- ${cur##mimetype:}) )
> +	    ;;
>  	*)
>  	    local search_terms="from: to: subject: attachment: mimetype: tag: id: thread: folder: path: date: lastmod:"
>  	    compopt -o nospace
> -- 
> 2.1.4


More information about the notmuch mailing list