[Mew-dist 05775] bbdb-mew.el
Linn H. Stanton
lstanton at example.com
1998年 8月 1日 (土) 12:18:57 JST
Just a small contribution...
-------------- next part --------------
;;; -*- Mode:Emacs-Lisp -*-
;;; an elisp hack to glue mew and bbdb together, modified from
;;; Kaufmann, knabe, and Repenning's bbdb-mhe.el by stanton at example.com
;;; use at your own risk, and have fun.
(require 'bbdb)
;; We advise several mew functions
(require 'mew)
(require 'advice)
(defun bbdb-mew-get-file-name ()
(if (and (boundp 'fld) (boundp 'msg))
(setq bbdb_mew_file_name (mew-expand-folder fld msg))
)
bbdb_mew_file_name
)
(defmacro bbdb/mew-cache-key (message)
"Return a (numeric) key for MESSAGE"
(`(let* ((attrs (file-attributes (bbdb-mew-get-file-name)))
(status-time (nth 6 attrs))
(status-time-2 (cdr status-time)))
(logxor (nth 10 attrs)
(car status-time)
;; We need the following test because XEmacs returns the
;; status time as a dotted pair, whereas FSF and Epoch
;; return it as list.
(if (integerp status-time-2)
status-time-2
(car status-time-2))))))
(defun bbdb/mew-update-record (&optional offer-to-create)
"Returns the record corresponding to the current mew message, creating or
modifying it as necessary. A record will be created if
bbdb/mail-auto-create-p is non-nil, or if OFFER-TO-CREATE is true and
the user confirms the creation."
(save-excursion
(and (mew-buffer-message) (set-buffer (mew-buffer-message)))
(if bbdb-use-pop-up (bbdb/mew-pop-up-bbdb-buffer offer-to-create)
(let ((msg (bbdb/mew-cache-key (mew-summary-message-number))))
(if (eq msg 0) (setq msg nil)) ; 0 could mean trouble; be safe.
(or (bbdb-message-cache-lookup msg nil) ; nil = current-buffer
(let ((from (bbdb/mew-get-field "^From[ \t]*:"))
name net)
(if (or (string= "" from)
(string-match (bbdb-user-mail-names)
(mail-strip-quoted-names from)))
;; if logged-in user sent this, use recipients.
(progn
(setq from (bbdb/mew-get-field "^To[ \t]*:"))
(if (or (string= "" from)
(string-match (bbdb-user-mail-names)
(mail-strip-quoted-names from)))
(setq from nil))))
(if from
(bbdb-encache-message msg
(bbdb-annotate-message-sender from t
(or (bbdb-invoke-hook-for-value bbdb/mail-auto-create-p)
offer-to-create)
offer-to-create)))))))))
(defun bbdb/mew-annotate-sender (string &optional replace)
"Add a line to the end of the Notes field of the BBDB record
corresponding to the sender of this message. If REPLACE is non-nil,
replace the existing notes entry (if any)."
(interactive (list (if bbdb-readonly-p
(error "The Insidious Big Brother Database is read-only.")
(read-string "Comments: "))))
(mew-summary-display)
(let ((b (current-buffer))
(p (point)))
(set-buffer (mew-buffer-message))
(bbdb-annotate-notes (bbdb/mew-update-record t) string 'notes replace)
(set-buffer b)
(goto-char p)))
(defun bbdb/mew-edit-notes (&optional arg)
"Edit the notes field or (with a prefix arg) a user-defined field
of the BBDB record corresponding to the sender of this message."
(interactive "P")
(mew-summary-display)
(let ((b (current-buffer))
(p (point)))
(set-buffer (mew-buffer-message))
(let (bbdb-electric-p (record (or (bbdb/mew-update-record t) (error ""))))
(bbdb-display-records (list record))
(if arg
(bbdb-record-edit-property record nil t)
(bbdb-record-edit-notes record t)))
(set-buffer b)
(goto-char p)))
(defun bbdb/mew-show-sender ()
"Display the contents of the BBDB for the sender of this message.
This buffer will be in bbdb-mode, with associated keybindings."
(interactive)
(mew-summary-display)
(let ((b (current-buffer))
(p (point)))
(set-buffer (mew-buffer-message))
(let ((record (bbdb/mew-update-record t)))
(if record
(bbdb-display-records (list record))
(error "unperson")))
(set-buffer b)
(goto-char p)))
(defun bbdb/mew-pop-up-bbdb-buffer (&optional offer-to-create)
"Make the *BBDB* buffer be displayed along with the mew window,
displaying the record corresponding to the sender of the current message."
(bbdb-pop-up-bbdb-buffer
(function (lambda (w)
(let ((b (current-buffer)))
(set-buffer (window-buffer w))
(prog1 (eq major-mode 'mew-summary-mode)
(set-buffer b))))))
(let ((bbdb-gag-messages t)
(bbdb-use-pop-up nil)
(bbdb-electric-p nil))
(let ((record (bbdb/mew-update-record offer-to-create))
(bbdb-elided-display (bbdb-pop-up-elided-display)))
(bbdb-display-records (if record (list record) nil))
record)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; this is a more strict version of mew-get-field which takes an regexp
(defun bbdb/mew-get-field (field)
;; Find and return the value of field FIELD (regexp) in the current buffer.
;; Returns the empty string if the field is not in the message.
(let ((case-fold-search nil))
(goto-char (point-min))
(cond ((not (re-search-forward field nil t)) "")
((looking-at "[\t ]*$") "")
(t (re-search-forward "[\t ]*\\([^\t \n].*\\)$" nil t)
(let ((field (buffer-substring (match-beginning 1) (match-end 1)))
(end-of-match (point)))
(forward-line)
(while (looking-at "[ \t]") (forward-line 1))
(backward-char 1)
(if (<= (point) end-of-match)
field
(format "%s%s" field
(buffer-substring end-of-match (point)))))))))
(defadvice mew-process-commands (after mew-bbdb-process act)
(bbdb-offer-save))
(defadvice mew-send (before mew-bbdb-send act)
(interactive (list
(bbdb-read-addresses-with-completion "To: ")
(bbdb-read-addresses-with-completion "Cc: ")
(read-string "Subject: "))))
(defadvice mew-send-other-window (before mew-bbdb-send-other act)
(interactive (list
(bbdb-read-addresses-with-completion "To: ")
(bbdb-read-addresses-with-completion "Cc: ")
(read-string "Subject: "))))
(defadvice mew-forward (before mew-bbdb-forward act)
(interactive (list (bbdb-read-addresses-with-completion "To: ")
(bbdb-read-addresses-with-completion "Cc: ")
)))
;;; (if current-prefix-arg
;;; (mew-read-seq-default "Forward" t)
;;; (mew-summary-display-message t)))))
(defadvice mew-redistribute (before mew-bbdb-redist act)
(interactive (list
(bbdb-read-addresses-with-completion "Redist-To: ")
(bbdb-read-addresses-with-completion "Redist-Cc: ")
)))
;;; (mew-get-msg-num t))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; mail from bbdb-mode using mew
;; these redefine the bbdb-send-mail functions to use mew-send.
;;; Install bbdb into mew's show-message function
(defun bbdb-insinuate-mew ()
"Call this function to hook BBDB into MEW."
(define-key mew-summary-mode-map ":" 'bbdb/mew-show-sender)
(define-key mew-summary-mode-map ";" 'bbdb/mew-edit-notes)
(add-hook 'mew-message-hook 'bbdb/mew-update-record)
(define-key mew-draft-mode-map "\t" 'bbdb-complete-name))
(provide 'bbdb-mew)
Mew-dist メーリングリストの案内