* gnus-mime-copy-part use charset param [patch]
@ 2005-02-07 22:41 Kevin Ryde
0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2005-02-07 22:41 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]
* gnus-art.el (gnus-mime-copy-part): Use mime part charset or
gnus-newsgroup-charset for decoding, like gnus-mime-inline-part does.
Set buffer-file-coding-system to tell save-buffer what was used.
(gnus-mime-copy-part-jka-insert): Renamed and adapted from
gnus-mime-jka-compr-maybe-uncompress.
gnus-mime-inline-part ("i") follows the charset indicated in a mime
part, but gnus-mime-copy-part ("c") doesn't.
This patch, which I've had kicking around for quite a while, is my
attempt to get it to do so. The jka-compr function is changed a bit
but the guts are mostly the same (I left it unindented to show that in
the diff).
I don't pretend to any expertise in all this coding systems disaster,
but I've tried to basically follow the same as inline-part does.
As a handy example to show the effect, the file "hello" below contains
a familiar message but with some diacriticals coded in utf-8, and with
a charset parameter. Before the patch with "c" you get junk chars,
after the patch it comes out right.
[-- Attachment #2: gnus-art.el.copy-decode.diff --]
[-- Type: text/plain, Size: 3452 bytes --]
--- gnus-art.el.~7.72.~ 2005-02-08 09:32:44.000000000 +1100
+++ gnus-art.el 2005-02-08 09:33:00.000000000 +1100
@@ -4235,20 +4235,18 @@
;; 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.
+(defun gnus-mime-copy-part-jka-insert (contents)
+ "Uncompress CONTENTS into the current buffer using jka-compr.
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))
+ (let* ((info (jka-compr-get-compression-info buffer-file-name))
+ (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))
+ (insert contents)
(unwind-protect
(unless (memq (apply 'call-process-region
(point-min) (point-max)
@@ -4257,7 +4255,7 @@
args)
jka-compr-acceptable-retval-list)
(jka-compr-error prog args basename message err-file))
- (jka-compr-delete-temp-file err-file)))))))
+ (jka-compr-delete-temp-file err-file))))
(defun gnus-mime-copy-part (&optional handle)
"Put the MIME part under point into a new buffer.
@@ -4267,6 +4265,10 @@
(gnus-article-check-buffer)
(let* ((handle (or handle (get-text-property (point) 'gnus-data)))
(contents (and handle (mm-get-part handle)))
+ (charset (and handle (or (mail-content-type-get
+ (mm-handle-type handle) 'charset)
+ gnus-newsgroup-charset)))
+ (coding-system (mm-charset-to-coding-system charset))
(base (and handle
(file-name-nondirectory
(or
@@ -4277,13 +4279,20 @@
(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.
+ (setq buffer-file-name (expand-file-name base))
+ (cond ((and (fboundp 'jka-compr-installed-p)
+ (jka-compr-installed-p)
+ (jka-compr-get-compression-info buffer-file-name))
+ (gnus-mime-copy-part-jka-insert contents))
+ (coding-system
+ (insert (mm-decode-coding-string contents coding-system))
+ (setq buffer-file-coding-system coding-system))
+ (t
+ (insert contents)))
+ ;; Run normal-mode with buffer-file-name set from the part, but then
+ ;; zap that variable so the user will be prompted in `save-buffer'.
(unwind-protect
- (progn
- (setq buffer-file-name (expand-file-name base))
- (gnus-mime-jka-compr-maybe-uncompress)
- (normal-mode))
+ (normal-mode)
(setq buffer-file-name nil))
(goto-char (point-min)))))
[-- Attachment #3: hello --]
[-- Type: text/plain, Size: 16 bytes --]
Héllò Wörld
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-02-07 22:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-07 22:41 gnus-mime-copy-part use charset param [patch] Kevin Ryde
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).