help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cannot open attachments with gnus


From: Alan Schmitt
Subject: Re: Cannot open attachments with gnus
Date: Tue, 17 Dec 2013 22:16:05 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin)

Hi Ted,

Ted Zlatanov <tzz@lifelogs.com> writes:

> I think so.  My system doesn't have `open' so I don't know if it has an
> option to run synchronously, but you could either write a wrapper script
> or set up the MIME handling to call the PDF viewer directly.

I tried to change my .mailcap, but the change did not seem to have
taken. I'll have to try restarting emacs to see if it matters.

What kind of wrapper script should I write? Something that first copies
the file somewhere where emacs won't delete it? Is it common practice
for asynchronous viewers?

> AS> If so, is there a way to tell gnus not to clean up after opening an
> AS> attachment? (The /tmp files will eventually be deleted.)
>
> I don't think there's built-in functionality for this, but it can
> probably be written.

I tried to look at the code, and I found it lives in function
`mm-display-external' in mm-decode.el. The code that matters is at the
end, but I'm not sure I'm reading it correctly.

The way I read it: the process is launched, and whatever happens, after
30 seconds the file is going to be deleted (I guess this is what the
"run-at-time" part does). Even though the command says deletion "should
be postponed for some wrappers", I could not find a way where it is
done. I'd gladly take any suggestion.

#+begin_src emacs-lisp
            ;; Deleting the temp file should be postponed for some wrappers,
            ;; shell scripts, and so on, which might exit right after having
            ;; started a viewer command as a background job.
            (let ((command (mm-mailcap-command
                            method file (mm-handle-type handle))))
              (unwind-protect
                  (progn
                    (start-process "*display*"
                                   (setq buffer
                                         (generate-new-buffer " *mm*"))
                                   shell-file-name
                                   shell-command-switch command)
                    (set-process-sentinel
                     (get-buffer-process buffer)
                     (lexical-let ((outbuf outbuf)
                                   (file file)
                                   (buffer buffer)
                                   (command command)
                                   (handle handle))
                       (run-at-time
                        30.0 nil
                        (lambda ()
                          (ignore-errors
                            (delete-file file))
                          (ignore-errors
                            (delete-directory (file-name-directory file)))))
                       (lambda (process state)
                         (when (eq (process-status process) 'exit)
                           (condition-case nil
                               (delete-file file)
                             (error))
                           (condition-case nil
                               (delete-directory (file-name-directory file))
                             (error))
                           (when (buffer-live-p outbuf)
                             (with-current-buffer outbuf
                               (let ((buffer-read-only nil)
                                     (point (point)))
                                 (forward-line 2)
                                 (mm-insert-inline
                                  handle (with-current-buffer buffer
                                           (buffer-string)))
                                 (goto-char point))))
                           (when (buffer-live-p buffer)
                             (kill-buffer buffer)))
                         (message "Displaying %s...done" command)))))
   ...))
#+end_src

Thanks a lot,

Alan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]