Gnus development mailing list
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: Re: gnus-mime-copy-part and jka-compr
Date: Fri, 03 Jan 2003 09:02:05 +1000	[thread overview]
Message-ID: <874r8rxij6.fsf@zip.com.au> (raw)
In-Reply-To: <m3y96968au.fsf@quimbies.gnus.org>

[I posted this to ding@gnus the other day, but it didn't seem to make
it through to gmane.  Apologies to anyone getting a duplicate.]

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
>
> `c' just puts the bytes in a buffer and calls `normal-mode',
> which will make the right mode appear.  However, for strange modes
> like tar mode, that just doesn't seem to work -- it gets triggered
> even though the file is called .tar.gz, but doesn't seem to accept
> having gzipped contents.

jka-compr puts a dummy into auto-mode-alist to lose the .gz, assuming
that its uncompress will have already been done via
file-name-handler-alist.  Or I think that's what's going on.

> Well, for gzip you can just put the stuff in a buffer, do "gunzip -c"
> in a `shell-command-on-region' and use the output.

I should have followed up earlier.  I had a go myself and came up with
the stuff below.  It uses call-process-region based on info from
jka-compr's setups.

(The only change to gnus-mime-copy-part is the addition of the call to
gnus-mime-jka-compr-maybe-uncompress.  I've got this stuff in my
.gnus.el, hence copying the code to make that insertion.)

> So that can be
> done, but that's avoiding jka-compr altogether and kinda
> re-implementing the entire package on a buffer basis instead of a
> file basis.  Which we don't want to do.

I don't think jka-compr has anything for acting directly on a buffer
as such, it just seems oriented towards file reading and writing, as a
filename handler.


In any case, what I'm not at all sure about below is coding system
issues.

Does call-process-region do enough on its own, or does it want to be
helped by working the notional filename (from the mail message) into
its figurings?

I'm thinking of say .tar wanting raw 8-bit but .txt wanting the usual
emacs inferences.




;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
;; emacs can do that itself.
;;
(defun gnus-mime-jka-compr-maybe-uncompress ()
  "Uncompress the current buffer if `auto-compression-mode' is enabled.
The uncompress method used is derived from `buffer-file-name'."
  (when (and (fboundp 'jka-compr-installed-p)
             (jka-compr-installed-p))
    (let ((info (jka-compr-get-compression-info buffer-file-name)))
      (when info
        (let ((basename (file-name-nondirectory buffer-file-name))
              (args     (jka-compr-info-uncompress-args    info))
              (prog     (jka-compr-info-uncompress-program info))
              (message  (jka-compr-info-uncompress-message info))
              (err-file (jka-compr-make-temp-name)))
          (if message
              (message "%s %s..." message basename))
          (unwind-protect
              (unless (memq (apply 'call-process-region
                                   (point-min) (point-max) 
                                   prog
                                   t (list t err-file) nil
                                   args)
                            jka-compr-acceptable-retval-list)
                (jka-compr-error prog args basename message err-file))
            (jka-compr-delete-temp-file err-file)))))))

(require 'gnus-art)
(defun gnus-mime-copy-part (&optional handle)
  "Put the MIME part under point into a new buffer."
  (interactive)
  (gnus-article-check-buffer)
  (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
	 (contents (and handle (mm-get-part handle)))
	 (base (and handle
		    (file-name-nondirectory
		     (or
		      (mail-content-type-get (mm-handle-type handle) 'name)
		      (mail-content-type-get (mm-handle-disposition handle)
					     'filename)
		      "*decoded*"))))
	 (buffer (and base (generate-new-buffer base))))
    (when contents
      (switch-to-buffer buffer)
      (insert contents)
      ;; We do it this way to make `normal-mode' set the appropriate mode.
      (unwind-protect
	  (progn
	    (setq buffer-file-name (expand-file-name base))
            (gnus-mime-jka-compr-maybe-uncompress)
	    (normal-mode))
	(setq buffer-file-name nil))
      (goto-char (point-min)))))



  reply	other threads:[~2003-01-02 23:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-17 22:51 Kevin Ryde
2002-12-28 21:16 ` Lars Magne Ingebrigtsen
2002-12-28 22:12   ` Kai Großjohann
2002-12-28 22:37     ` Lars Magne Ingebrigtsen
2002-12-28 23:03       ` Kai Großjohann
2002-12-28 23:19         ` Lars Magne Ingebrigtsen
2003-01-02 23:02           ` Kevin Ryde [this message]
2003-01-02 23:10             ` Lars Magne Ingebrigtsen
2003-01-03 21:19               ` Kevin Ryde
2003-01-03 21:27                 ` Lars Magne Ingebrigtsen
2003-01-04  0:35                   ` Kevin Ryde
2003-01-04  0:41                     ` Lars Magne Ingebrigtsen
2003-01-15  0:34                       ` Kevin Ryde
2003-01-15  1:34                         ` New IMAP user with some Q's dave-mlist
2003-01-15  7:14                           ` Kai Großjohann
2003-01-15 12:58                           ` Simon Josefsson
2003-01-15 20:18                         ` gnus-mime-copy-part and jka-compr Lars Magne Ingebrigtsen
2002-12-28 21:17 ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874r8rxij6.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).