+### Convert ".pdf" and ".docx" to text and pop to buffer
+
+Add the following (hacky but effective!) code to `.emacs.d/notmuch-config.el`;
+the overwritten `defcustom` will change action when pressing RET on top of an
+attachment; ".pdf" and ".docx" attachments are converted to text (using
+"pdf2text" and "docx2txt.pl" commands to do the conversion), saving to file
+(the default action of `notmuch-show-part-button-default-action`) is offered
+to attachments of other types.
+
+ (defun user/mm-pipe-- (handle cmd)
+ ;; conveniently, '-' '-' a args to pdftotext and docx2txt.pl work fine
+ ;; fixme: naming inconsistency (fn name and buffer name)
+ (let ((buffer (get-buffer-create "*attachment-to-text*")))
+ (with-current-buffer buffer
+ (setq buffer-read-only nil)
+ (erase-buffer))
+ (with-temp-buffer
+ ;; "based on mm-pipe-part in mm-decode.el"
+ (mm-with-unibyte-buffer
+ (mm-insert-part handle)
+ (mm-add-meta-html-tag handle)
+ (let ((coding-system-for-write 'binary))
+ (call-process-region (point-min) (point-max)
+ cmd nil buffer nil "-" "-"))))
+ (pop-to-buffer buffer)
+ (goto-char (point-min))
+ (text-mode)
+ (visual-line-mode)
+ (view-mode)))
+
+ (defun user/notmuch-show-pop-attachment-to-buffer ()
+ ;; "based on notmuch-show-apply-to-current-part-handle"
+ (interactive)
+ (let ((handle (notmuch-show-current-part-handle)))
+ ;;(message "%s" handle)
+ (unwind-protect
+ (pcase (car (nth 1 handle))
+ ("application/pdf"
+ (user/mm-pipe-- handle "pdftotext"))
+ ("application/vnd.openxmlformats-officedocument.wordprocessingml.document"
+ (user/mm-pipe-- handle "docx2txt.pl"))
+ (_ (notmuch-show-save-part)))
+ (kill-buffer (mm-handle-buffer handle)))))
+
+ (setq notmuch-show-part-button-default-action
+ #'user/notmuch-show-pop-attachment-to-buffer)
+