emacs-devel
[Top][All Lists]
Advanced

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

Re: Emacs 22 branch created.


From: Kenichi Handa
Subject: Re: Emacs 22 branch created.
Date: Wed, 02 May 2007 11:17:23 +0900
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/23.0.0 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

In article <address@hidden>, Richard Stallman <address@hidden> writes:

> #1 is intolerable because it means C-x b RMAIL RET won't take you
> to the current message.

>     Why not?  We could arrange for RMAIL to be that separate buffer where
>     we display decoded message text.

> Normally the buffer named RMAIL is the one that visits the file RMAIL.
> If we break that correspondence it is likely to cause a lot of
> trouble.  And what would we do for other mail files?

I've long used the rmail-mime package which uses different
buffer than the RMAIL file buffer for displaying a decoded
message, and it doesn't have a serious problem.  The only
problem I feel is the somewhat slowness of
rmail-search-forward/backward.  As rmail.el already has
various *-function variables
(e.g. rmail-show-mime-function), what rmail-mime does is
just setting proper functions to those variables.  I'll
attach the core file (rmail-mime.el) of that package so that
you can see how it works.

Unfortunately, rmail-mime package provides various its own
functions for handling mime features that conflicts with the
current Gnus, and is not maintained now.  So it seems very
difficult to include it in Emacs.  But, I think it's
possible to utilze Gnus' mime facilities in the similar way.

>     file, and the question I was asking is how to store the decoded
>     characters in that file, if you don't want to decode them each time
>     you look at that message.  Are you suggesting to store them, after
>     decoding, in the internal Emacs format (i.e. emacs-mule)?  That would
>     mean that only Emacs will be able to read the resulting mbox file.

> That is a valid point.

> A new idea just occurred to me.  Moving to a message could copy that
> message in the buffer, decode the copy, and display that copy using
> narrowing instead of the original message.  If you edit the message,
> exiting the editing mode will reencode it and put that in place
> of the original message.

> We could have a new feature to omit part of the buffer when saving the
> file.  Rmail could use it so that this copy is not saved.  This
> feature should not affect auto-saving.

> As an optimization, if there are attachments, don't copy them.  Just
> copy and decode the main text of the message.  (Attachments don't need
> character set decoding, since they are in ASCII.)  Put the copy after
> the original, and the attachments will effecvtively become part of it.

> Does anyone see a flaw in this?

One disadvantage of that method compared to using a
different buffer is that, RMAIL file must be read into a
multibyte buffer, which requires decoding all 8-bit bytes
into multibyte 8-bit characters.  I think the percentage of
8-bit bytes is small, but the decoding process move memories
many times.  If we use a different buffer for decoding, that
process becomes unnecessary.  RMAIL file tends to become
very big (especially for novice users).

---
Kenichi Handa
address@hidden

----------------------------------------------------------------------
;;; rmail-mime.el --- Add MIME handling facility to RMAIL

;; Copyright (C) 2001 Free Software Foundation, Inc.

;; Author: MORIOKA Tomohiko <address@hidden>
;; Keywords: mail, news, MIME, multimedia, multilingual, encoded-word

;; This file is part of SEMI (Setting for Emacs MIME Interfaces).

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Code:

(require 'mime-view)

(defun rmail-decode-header (decoded-buffer original-buffer start end)
  (set-buffer (get-buffer-create decoded-buffer))
  (erase-buffer)
  (insert-buffer-substring original-buffer start end)
  (mime-decode-header-in-buffer rmail-enable-mime))

(defun rmail-decode-mime-message (decoded-buffer original-buffer msg)
  (save-excursion
    (set-buffer original-buffer)
    (save-restriction
      (narrow-to-region (rmail-msgbeg msg)
                        (rmail-msgend msg))
      (setq mime-message-structure
            (mime-open-entity 'babyl original-buffer))
      (mime-display-message mime-message-structure decoded-buffer)))
  (set-buffer decoded-buffer))

(defun rmail-view-kill-rmail-buffer ()
  (if rmail-buffer (kill-buffer rmail-buffer)))

(defvar rmail-view-mode-map nil)

(defun rmail-show-mime-message ()
  (let ((abuf (current-buffer))
        (buf-name (concat (buffer-name) "-view"))
        buf win)
    (narrow-to-region (rmail-msgbeg rmail-current-message)
                      (rmail-msgend rmail-current-message))
    (setq mime-message-structure
          (mime-open-entity 'babyl abuf))
    (set-buffer (mime-display-message mime-message-structure
                                      buf-name nil
                                      nil nil rmail-view-mode-map))
    (setq buf (current-buffer))
    (make-local-variable 'font-lock-defaults)
    (setq font-lock-defaults
          '(rmail-font-lock-keywords
            t nil nil nil
            (font-lock-maximum-size . nil)
            (font-lock-fontify-buffer-function
             . rmail-fontify-buffer-function)
            (font-lock-unfontify-buffer-function
             . rmail-unfontify-buffer-function)
            (font-lock-inhibit-thing-lock
             . (lazy-lock-mode fast-lock-mode))))
    (make-local-variable 'rmail-buffer)
    (setq rmail-buffer abuf)
    (make-local-variable 'rmail-view-buffer)
    (setq rmail-view-buffer (current-buffer))
    (make-local-variable 'rmail-summary-buffer)
    (setq rmail-summary-buffer
          (with-current-buffer rmail-buffer
            rmail-summary-buffer))
    (make-local-variable 'rmail-current-message)
    (setq rmail-current-message
          (with-current-buffer rmail-buffer
            rmail-current-message))
    (make-local-variable 'kill-buffer-hook)
    (add-hook 'kill-buffer-hook 'rmail-view-kill-rmail-buffer)
    (let ((mode-line
           (with-current-buffer abuf
             (setq rmail-view-buffer buf)
             mode-line-process)))
      (setq mode-line-process mode-line))
    (if (and (setq win (get-buffer-window abuf))
             buf)
        (set-window-buffer win buf))
    (bury-buffer rmail-buffer)
    (run-hooks 'rmail-show-mime-message-hook)))

(defun rmail-insert-mime-forwarded-message (forward-buffer)
  (insert (mime-make-tag "message" "rfc822"))
  (insert "\n")
  (mime-insert-entity (with-current-buffer forward-buffer
                        mime-message-structure)))

(defun rmail-insert-mime-resent-message (forward-buffer)
  (mime-insert-entity (with-current-buffer forward-buffer
                        mime-message-structure)))

(defun rmail-enable-mime ()
  (interactive)
  (setq rmail-enable-mime t)
  (rmail-show-message))

(defun rmail-disable-mime ()
  (interactive)
  (let ((buf rmail-buffer))
    (when rmail-enable-mime
      (remove-hook 'kill-buffer-hook 'rmail-view-kill-rmail-buffer)
      (set-window-buffer (selected-window) buf)
      (kill-buffer rmail-view-buffer))
    (set-buffer buf))
  (setq rmail-enable-mime nil
        rmail-view-buffer (current-buffer))
  (rmail-show-message))

(defun rmail-search-mime-message (msg regexp)
  "Search the message of number MSG for REGEXP.
If the search succeeds, return non-nil.  Otherwise, return nil."
  (save-excursion
    (rmail-decode-mime-message " *RMAIL-temp-VIEW*" (current-buffer) msg)
    (goto-char (point-min))
    (prog1 (re-search-forward regexp nil t)
      (kill-buffer " *RMAIL-temp-VIEW*"))))

(defun rmail-search-mime-header (msg regexp limit)
  "Search the message header of number MSG for REGEXP.
The current point is the beginninf of header,
and LIMIT is the end position of header.
If the search succeeds, return non-nil.  Otherwise, return nil."
  (save-excursion
    (rmail-decode-header " *RMAIL-temp-VIEW*" (current-buffer) (point) limit)
    (goto-char (point-min))
    (prog1 (re-search-forward regexp nil t)
      (kill-buffer " *RMAIL-temp-VIEW*"))))

(set-alist 'mime-raw-representation-type-alist 'rmail-mode
           (if rmail-enable-mime
               'binary
             'cooked))

(set-alist 'mime-preview-over-to-previous-method-alist
           'rmail-mode
           (function
            (lambda ()
              (message "Beginning of buffer")
              ;; (rmail-previous-undeleted-message 1)
              )))

(set-alist 'mime-preview-over-to-next-method-alist
           'rmail-mode
           (function
            (lambda ()
              (message "End of buffer")
              ;; (rmail-next-undeleted-message 1)
              )))

(set-alist 'mime-preview-quitting-method-alist 'rmail-mode #'rmail-quit)

;; Override values defined in rmail.
(eval-after-load "rmail"
  '(progn
     (define-key rmail-mode-map "v" 'rmail-enable-mime)
     (setq rmail-show-mime-function
           (function rmail-show-mime-message)
           rmail-insert-mime-forwarded-message-function
           (function rmail-insert-mime-forwarded-message)
           rmail-insert-mime-resent-message-function
           (function rmail-insert-mime-resent-message)
           rmail-search-mime-message-function
           (function rmail-search-mime-message)
           rmail-search-mime-header-function
           (function rmail-search-mime-header))
     (unless rmail-view-mode-map
       (setq rmail-view-mode-map (mime-view-define-keymap rmail-mode-map))
       (define-key rmail-view-mode-map
         "p" (function rmail-previous-undeleted-message))
       (define-key rmail-view-mode-map
         "n" (function rmail-next-undeleted-message))
       (define-key rmail-view-mode-map
         "u" (function rmail-undelete-previous-message))
       (define-key rmail-view-mode-map
         "a" (function rmail-add-label))
       (define-key rmail-view-mode-map
         "\C-c\C-c" (function rmail-disable-mime)))))

;; Override values defined in rmailsum.
(eval-after-load "rmailsum"
  '(setq rmail-summary-line-decoder
         (function
          (lambda (string)
            (eword-decode-string
             (decode-coding-string string 'undecided))))))

;; Override values defined in sendmail.
(eval-after-load "sendmail"
  '(progn
     (add-hook 'mail-setup-hook 'turn-on-mime-edit)
     (add-hook 'mail-send-hook 'mime-edit-maybe-translate)))

(provide 'rmail-mime)




reply via email to

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