Re: SEMI: pgg-gpg: garbled non-ascii message

Daiki Ueno <[email protected]>
Newsgroups gmane.mail.emacs.mime.japanese
Message-ID <[email protected]>
上野です。

>>>>> In [emacs-mime-ja : No.01587] 
>>>>>	Shinichiro HIDA <[email protected]> wrote:
> 参考になるかどうかわかりませんが、追試してみました。

ありがとうございます。おかげさまで原因がわかったような気がします。

> 追試していて、変な現象に気づきました。
 
> [文字化けする場合]
>  3. wl の Message バッファで region を選択しても pgg-verify-region を
>     呼べない
>  4. 木下さんのメールで v を押すと文字化けする。

> [文字化けしない場合]
>  3. wl で w を押し、draft バッファを尽くり、pgg-sign-region する。
>  4. これ以降、すべての pgg-* で正しく日本語が表示出来る。

バッファの buffer-file-coding-system が確定していない時点で raw-text-dos 
を指定してファイルの内容を読み込むと自動的に unibyte buffer にされます。

(cf. M-x describe-coding-system raw-text-dos)
|When you visit a file with this coding, the file is read into a
|unibyte buffer as is (except for EOL format), thus each byte of a file
|is treated as a character.

これは以下のコードを *scratch* で二回以上実行することで確認できます。

(with-current-buffer (get-buffer-create " test")
  (erase-buffer)
  (set-buffer-multibyte t)
  (let ((coding-system-for-read 'raw-text-dos)
	(file (make-temp-file "/tmp/tst")))
    (unwind-protect
	(insert-file-contents file nil 0 0)
      (delete-file file)))
  enable-multibyte-characters)

pgg-gpg の場合、pgg-sign-region はファイルを作りませんが、
pgg-verify-region は空のファイルを作るため、これを raw-text-dos として読
み込んだ時点で " *PGG output*" バッファが unibyte にされてしまいます。

解決策としては以下の 3 つが考えられます:

1. " *PGG errors*" バッファから署名確認のメッセージをコピーする直前に
   " *PGG output*" バッファを multibyte にする

2. " *PGG output*" は unibyte, " *PGG errors*" は multibyte とみなし、
   " *PGG output*" を介さずに " *PGG errors*" から署名確認のメッセージを
   コピーする

3. サイズが 0 のファイルは読み込まない

まともなのは 2. だと思いますが、とりあえず 1. の修正を添付いたします。
-- 
Daiki Ueno
pgg-gpg.el.diff (application/octet-stream, 595 B)
Index: pgg-gpg.el
===================================================================
RCS file: /cvs/root/semi/pgg-gpg.el,v
retrieving revision 1.2.2.8
diff -u -F^( -r1.2.2.8 pgg-gpg.el
--- pgg-gpg.el	9 Jun 2003 14:41:04 -0000	1.2.2.8
+++ pgg-gpg.el	16 Dec 2003 06:59:01 -0000
@@ -202,6 +202,7 @@ (luna-define-method pgg-scheme-verify-re
 	(goto-char (point-min))
 	(delete-matching-lines "^warning\\|\\[GNUPG:]")
 	(set-buffer pgg-output-buffer)
+	(set-buffer-multibyte t)
 	(insert-buffer-substring pgg-errors-buffer)))))
 
 (luna-define-method pgg-scheme-insert-key ((scheme pgg-scheme-gpg))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.