How to influence the program used to open attachments?

339 views
Skip to first unread message

Marcin Borkowski

unread,
Feb 8, 2017, 1:03:04 PM2/8/17
to mu-discuss
Hi all,

when I open a text attachment (and being a LaTeX user and researcher,
I get those a lot), another instance of Emacs is fired (like xdg-open
would do). I'd like text files to be saved in some temp directory (or
better yet, in a place provided by the user, like when saving
attachments) and opened in this very instance of Emacs, however.

I could change emacs.desktop to launch emacsclient instead, but this
would make C-x # include this buffer in the list of server-edited
buffers, which is not exactly convenient. Is there a better way?
Looking at the code of `mu4e-view-open-attachment', there is a special
provision for message attachments; I do not know enough about message
handling to be able to hack it to do what I want.

TIA,

--
Marcin Borkowski

Mohamed HIBTI

unread,
Feb 9, 2017, 3:49:33 AM2/9/17
to mu-discuss
Hi Marcin,
I You have this by Phil Jackson,

https://gist.github.com/philjackson/aecfab1706f05079aec7000e328fd183

You can customize it to handle tex attachments and provide a specific directory for them.

Mohamed HIBTI

unread,
Feb 9, 2017, 4:12:35 AM2/9/17
to mu-discuss
This is how I did in my case (For those who are not familiar with lisp)
     
(defun view-attachments-dired (&optional msg)
      "Saves all of the attachments in `msg' to a directory under
      `bulk-saved-attachments-dir' which is derived from the subject
      beloning to `msg'. Existing filenames will be overwritten without
      prompt. The directories are not cleaned up in any way."
      (interactive)
      (let* ((msg (or msg (mu4e-message-at-point)))
          (preid (if (car (car (mu4e-message-field msg :from))) (car (car (mu4e-message-field msg :from)))  (cdr (car (mu4e-message-field msg :from))) ))
          (id (cleanse-subject  preid))
      (subject (mu4e-message-field msg :subject))
          (attachdir (concat bulk-saved-attachments-dir (if (string-match "SomeRegex" subject) "/someDirectory/" "/" ) id))
          (count (hash-table-count mu4e~view-attach-map)))
          (if (> count 0)
          (progn
              (mkdir attachdir t)
              (dolist (num (number-sequence 1 count))
                (let* ((att (mu4e~view-get-attach msg num))
                       (ftype (plist-get att :mime-type))
                       (fname (plist-get att :name))
                       (index (plist-get att :index))
                       fpath)
                       (setq fpath (if (equal ftype "text/x-tex") (concat "/tmp/"  fname)
               (concat attachdir "/" fname)))
          (message "mime-type is %s" ftype)
                  (mu4e~proc-extract
                   'save (mu4e-message-field msg :docid)
                   index mu4e-decryption-policy fpath)))
              (dired attachdir) // Here you can customize to jump to your directory if it exists
              (revert-buffer))
          (message "Nothing to extract."))))

    (add-hook 'mu4e-view-mode-hook
              (lambda ()
                (local-set-key (kbd "C-m") 'view-attachments-dired ))
              'append)

beo...@gmail.com

unread,
Feb 9, 2017, 6:24:02 PM2/9/17
to mu-di...@googlegroups.com
Hi Mohamed,

Do you (or anyone else) know a good way of getting mu4e to open up
.pdf's in a particular application (e.g. okular)? I have okular set
as the default app for .pdfs on my system, but mu4e seems to want to
open everything in firefox.

—Ben

Mohamed HIBTI

unread,
Feb 10, 2017, 4:32:33 AM2/10/17
to mu-discuss
Hi Ben,
My guess is that you have some customisation.
In the manual, you have also open-with action.

https://www.djcbsoftware.nl/code/mu/mu4e/MSGV-Actions.html#Attachment-actions-1

you can also try

(setq dired-guess-shell-alist-user
      '(("\\.pdf\\'" "okular")
        ("\\.eps\\'" "evince")
        ("\\.jpe?g\\'" "eog")
        ("\\.png\\'" "eog")
        ("\\.gif\\'" "eog")
        ("\\.csv\\'" "libreoffice")
        ("\\.tex\\'" "pdflatex" "latex")
        ("\\.html?\\'" "firefox")
        ))

 

Mohamed

Marcin Borkowski

unread,
Feb 10, 2017, 7:27:43 AM2/10/17
to mu-di...@googlegroups.com
What does xdg-mime query default application/pdf say?

> —Ben

Best,

--
Marcin Borkowski

beo...@gmail.com

unread,
Feb 10, 2017, 2:03:30 PM2/10/17
to mu-di...@googlegroups.com

On 2017-02-10T05:28:16-0700, Marcin Borkowski <mb...@mbork.pl> wrote:

> What does xdg-mime query default application/pdf say?

$ xdg-mime query default application/pdf
okularApplication_pdf.desktop;okular.desktop;okular;

which seems right to me.


—Ben

Dirk-Jan C. Binnema

unread,
Feb 12, 2017, 4:39:00 AM2/12/17
to mu-di...@googlegroups.com
For these things, we have "attachment actions", by default bound to 'A'
when in the message view.

You can save, open in (this) emacs, open-with, pipe etc.

Kind regards,
Dirk.


--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C
Reply all
Reply to author
Forward
0 new messages