1. xemacs
  2. hyperbole


hyperbole / hrmail.el

;; FILE:         hrmail.el
;; SUMMARY:      Support for Hyperbole buttons in mail reader: Rmail.
;; USAGE:        GNU Emacs Lisp Library
;; KEYWORDS:     hypermedia, mail
;; AUTHOR:       Bob Weiner
;; ORG:          BeOpen.com
;; ORIG-DATE:     9-May-91 at 04:22:02
;; LAST-MOD:     13-Jun-99 at 01:18:21 by Bob Weiner
;; Copyright (C) 1991-1995, BeOpen.com and the Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;; This file is part of Hyperbole.
;;   Automatically configured for use in "hyperbole.el".
;;   If hsite loading fails prior to initializing Hyperbole Rmail support,
;;       {M-x Rmail-init RET}
;;   will do it.

;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************

(require 'hmail)
(require 'hact)
(load "hsmail")
(require 'rmail)
(load "rmailedit")
(provide 'rmailedit)

;;; ************************************************************************
;;; Public variables
;;; ************************************************************************

;;; ************************************************************************
;;; Public functions
;;; ************************************************************************

(defun Rmail-init ()
  "Initializes Hyperbole support for Rmail mail reading."
  (setq hmail:composer  'mail-mode
	hmail:lister    'rmail-summary-mode
	hmail:modifier  'rmail-edit-mode
	hmail:reader    'rmail-mode)
  (var:append 'rmail-show-message-hook '(hmail:msg-narrow))
  ;; Setup public abstract interface to Hyperbole defined mail
  ;; reader-specific functions used in "hmail.el".
  ;; Setup private abstract interface to mail reader-specific functions
  ;; used in "hmail.el".
  (defalias 'rmail:get-new       'rmail-get-new-mail)
  (defalias 'rmail:msg-forward   'rmail-forward)
  (defalias 'rmail:summ-msg-to   'rmail-summary-goto-msg)
  (defalias 'rmail:summ-new      'rmail-new-summary)
  (if (interactive-p)
      (message "Hyperbole RMAIL mail reader support initialized."))

(defun Rmail-msg-hdrs-full (toggled)
  "If TOGGLED is non-nil, toggle full/hidden headers, else show full headers."
    (if (or toggled
	    (let ((tog nil))
		  (narrow-to-region (rmail-msgbeg rmail-current-message)
		  (let ((buffer-read-only nil))
		    (goto-char (point-min))
		    (forward-line 1)
		    ;; Need to show full header
		    (if (eq (following-char) ?1)
			(setq tog t)))))
	(progn (rmail-toggle-header)
	       (setq toggled t)))

(defun Rmail-msg-narrow ()
  "Narrows mail reader buffer to current message.
This includes Hyperbole button data."
  (let ((beg (rmail-msgbeg rmail-current-message))
	(end (rmail-msgend rmail-current-message)))
    (narrow-to-region beg end)))

(defun Rmail-msg-next ()        (rmail-next-undeleted-message 1))

(defun Rmail-msg-num ()
  "Returns number of Rmail message that point is within."
  (let ((count 0) opoint)
     (while (and (not (eobp))
		 (progn (setq opoint (point))
			(re-search-backward "^\^_" nil t)))
       (if (= opoint (point))
	   (backward-char 1)
	 (setq count (1+ count)))))

(defun Rmail-msg-prev ()        (rmail-previous-undeleted-message 1))

(defun Rmail-msg-to-p (mail-msg-id mail-file)
  "Sets current buffer to start of msg with MAIL-MSG-ID in MAIL-FILE.
Returns t if successful, else nil."
  (if (not (file-readable-p mail-file))
    (let ((buf (get-file-buffer mail-file)))
      (cond (buf
	     (switch-to-buffer buf)
	     (or (eq major-mode 'rmail-mode)
		 (rmail mail-file)))
	    (t (rmail mail-file))))
    (goto-char 1)
    (if (re-search-forward (concat rmail:msg-hdr-prefix
				   (regexp-quote mail-msg-id)) nil t)
	;; Found matching msg
	  (setq buffer-read-only t)
	  (rmail-show-message (Rmail-msg-num))

(defun Rmail-msg-widen ()
  "Widens buffer to full current message including Hyperbole button data."
  (let ((start (point-min))
	(end (point-max)))
	  (if (re-search-forward "^\^_" nil t)
	      (progn (forward-char -1)
		     (setq end (point)))))
      (narrow-to-region start end))))

(defun Rmail-to ()
  "Sets current buffer to a mail reader buffer."
  (and (eq major-mode 'rmail-summary-mode) (set-buffer rmail-buffer)))

(defalias 'Rmail-Summ-delete        'rmail-summary-delete-forward)

(defalias 'Rmail-Summ-expunge       'rmail-summary-expunge)

(defalias 'Rmail-Summ-goto          'rmail-summary-goto-msg)

(defun Rmail-Summ-to ()
  "Sets current buffer to a mail listing buffer."
  (and (eq major-mode 'rmail-mode) (set-buffer rmail-summary-buffer)))

(defalias 'Rmail-Summ-undelete-all  'rmail-summary-undelete-many)

;;; ************************************************************************
;;; Overloaded functions
;;; ************************************************************************

(if (featurep 'rmail-hyperbole)
    ;; No overloads are necessary, the needed features are built-in.

;;; else
;;; Overlay version of this function from "rmailedit.el" to include any
;;; hidden Hyperbole button data when computing message length.
(defun rmail-cease-edit ()
  "Finish editing message; switch back to Rmail proper."
  ;; Make sure buffer ends with a newline.
    (goto-char (point-max))
    (if (not (eq (preceding-char) ?\n))
	(insert "\n"))
    ;; Adjust the marker that points to the end of this message.
    (set-marker (aref rmail-message-vector (1+ rmail-current-message))
  (let ((old rmail-old-text))
    ;; Update the mode line.
    (set-buffer-modified-p (buffer-modified-p))
    (if (and (= (length old) (- (point-max) (point-min)))
	     (string-equal old (buffer-substring (point-min) (point-max))))
      (setq old nil)
      (rmail-set-attribute "edited" t)
      (if (boundp 'rmail-summary-vector)
	    (aset rmail-summary-vector (1- rmail-current-message) nil)
	       (function (lambda ()
			   (forward-line 2)
			   ;; Delete summary line which may have changed.
			   (if (looking-at "Summary-line: ")
			       (let ((buffer-read-only nil))
				 (delete-region (point)
						(progn (forward-line 1)
			   ;; Update internal copy of subject line, from
			   ;; message subject line, which may have changed.
			   (let ((subject
				    (if (re-search-forward "^Subject:" nil t)
					  ;; Try to find subject in msg header.
					  (re-search-forward "^Subject:" nil t)
					  (skip-chars-forward " \t")
					   (point) (progn (re-search-forward
							   "\n[^ \t]" nil t)
							  (- (point) 2))))))))
			     (if (and subject
				      (search-forward "\n*** EOOH ***\n" nil t))
				 (let ((buffer-read-only nil))
				   (goto-char (match-beginning 0))
				   (if (re-search-backward "^Subject:" nil t)
				       (delete-region (point)
						      (progn (re-search-forward
							      "\n[^ \t]" nil t)
							     (1- (point)))))
				   (insert "Subject: " subject "\n")))))))

	      ;; Adjust the marker that points to the end of this message
	      ;; since editing may have occured above.
	      (goto-char (point-max))
	      (set-marker (aref rmail-message-vector (1+ rmail-current-message))

	      ;; Update summary line for current message, if it exists in the
	      ;; summary buffer.
	      (rmail-summary-update-line rmail-current-message)

	      ;; This may set the current buffer to the summary buffer.
  (setq buffer-read-only t))

;;; Overlay version of this function from "rmail.el" to include any
;;; Hyperbole button data.
(defun rmail-forward (resend)
  "Forward the current message to another user.
With prefix argument, \"resend\" the message instead of forwarding it;
see the documentation of `rmail-resend'."
  (interactive "P")
  (if resend
      (call-interactively 'rmail-resend)
    (let* ((forward-buffer (current-buffer))
	    (or (mail-fetch-field "Mime-Version")
		(progn (rmail-toggle-header)
		       (setq toggle-header-flag t)
		(mail-fetch-field "Mime-Version")))
	    (if mime-version (mail-fetch-field "Content-Type")))
	    (if mime-version (mail-fetch-field "Content-Transfer-Encoding")))
	   (subject (concat "["
			    (let ((from (or (mail-fetch-field "From")
					    (mail-fetch-field ">From"))))
			      (if from
				  (concat (mail-strip-quoted-names from) ": ")
			    (or (mail-fetch-field "Subject") "")
      (if toggle-header-flag (rmail-toggle-header))
      (if mime-version (setq subject (concat subject "\nMime-Version: "
					     (if mime-content-type
						 (concat "\nContent-Type: "
					     (if mime-content-encoding
						  "\nContent-Transfer-Encoding: "
	;; Turn off the usual actions for initializing the message body
	;; because we want to get only the text from the failure message.
	(let (mail-signature mail-setup-hook)
	  ;; If only one window, use it for the mail buffer.
	  ;; Otherwise, use another window for the mail buffer
	  ;; so that the Rmail buffer remains visible
	  ;; and sending the mail will get back to it.
	  (if (funcall (cond ((and (not rmail-mail-new-frame) (one-window-p t))
			     ((fboundp 'rmail-start-mail)
			     (t 'mail-other-window))
		       nil nil subject nil nil nil
		       (list (list (function (lambda (buf msgnum)
						 (set-buffer buf)
						  "forwarded" t msgnum))))
		;; Insert after header separator--before signature if any.
		(goto-char (point-min))
		 (concat "^" (regexp-quote mail-header-separator)))
		(forward-line 1)
		(insert-buffer forward-buffer)

;;; Overlay version of 'rmail-get-new-mail' from "rmail.el" to highlight
;;; Hyperbole buttons when possible.
(if (boundp 'rmail-get-new-mail-post-hook)
    (add-hook 'rmail-get-new-mail-post-hook
	       (lambda ()
		 (if (fboundp 'hproperty:but-create)
		     (progn (widen) (hproperty:but-create)
  (hypb:function-overload 'rmail-get-new-mail nil
			  '(if (fboundp 'hproperty:but-create)
			       (progn (widen) (hproperty:but-create)

;;; Overlay version of 'rmail-new-summary' from "rmailsum.el" to
;;; highlight Hyperbole buttons when possible.
(or (fboundp 'rmail-new-summary) (load "rmailsum"))

(if (boundp 'rmail-summary-create-post-hook)
    (add-hook 'rmail-summary-create-post-hook
	       (lambda ()
		 (if (fboundp 'hproperty:but-create)
  (hypb:function-overload 'rmail-new-summary nil
			  '(if (fboundp 'hproperty:but-create)

;; end not InfoDock

;;; ************************************************************************
;;; Private variables
;;; ************************************************************************

(provide 'hrmail)