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

mail signatures



  | Date: Thu, 25 June 1992, 11:45 +0200
  | From: Vincent Keunen
  |
  | Is there a way to define signatures to be automatically added to the end
  | of a mail message?
  | 
  | vk

With GNU Emacs a plain ~/.signature will do. I don't know if Zmacs or
Zmail have anything similar.

However, with GNU Emacs you can do better than that (I bet you'll find a
bunch of people offering a GNU Emacs package similar to this one):

;Author: Eyvind Ness (eyvind) 
;Date:   Wednesday, June 3 1992 08:06 GMT
;File:   /usr/local/gnu/emacs/elisp/site-extensions/en-signature-hook.el

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; A util to help you select a proper ~/.signature for all outgoing
;;; mail based on a database of citations and jokes.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Example usage:
;;;
;;; In ~/.emacs do:
;;;
;;; (setq
;;;  mail-setup-hook
;;;  (function
;;;   (lambda ()
;;;    ;; It's painful to add :before methods when the -hook variable is
;;;    ;; missing:
;;;    (or (boundp 'vm-mail-send-and-exit-rebound-p)
;;;        (progn
;;;          (require 'vm)
;;;          (require 'en-signature-hook)
;;;          (defvar vm-mail-send-and-exit-rebound-p
;;;            (symbol-function 'vm-mail-send-and-exit))
;;;          (fset 'vm-mail-send-and-exit
;;;                (function
;;;                 (lambda (arg)
;;;                  (interactive "P")
;;;                  (en-signature-hook-choose-insert)
;;;                  (funcall vm-mail-send-and-exit-rebound-p arg)))))))))
;;;
;;;
;;; To just test it - try:
;;; M-x eval-expression (en-signature-hook-choose-insert)
;;; after loading the contents of this file.

(provide 'en-signature-hook)

(defvar en-signature-hook-db 
  (expand-file-name "~/.signature.collection")
  "*Where your formatted database of citations and jokes are supposed to
be.")

(defvar en-signature-hook-plain-sigfile
  (expand-file-name "~/.signature")
  "*Where your .signature file is supposed to be.")


(defun en-signature-hook-parse-db ()
  (save-excursion
    (set-buffer (get-buffer-create "*.sig output*"))
    (erase-buffer)
    (goto-char (point-min))
    (insert-file-contents en-signature-hook-db nil)
    (let ((cit-list nil) (page-delimiter "^"))
      (while (not (eobp))
	;; skips past 1st item - which is supposed to be a file-header.
	(forward-page 1)
	(setq cit-list
	      (cons
	       (buffer-substring
		(point)
		(save-excursion 
		  (forward-page 1)
		  (beginning-of-line)
		  (point)))
	       cit-list)))
      cit-list)))


(defun en-signature-hook-choose-insert ()
  "Suggests a ~/.signature from ~/.singature.collection"
  (interactive)
  (let* ((cit-db (en-signature-hook-parse-db)) (ch nil)
	 (db-ix (% (random t) (length cit-db)))
	 before-dot-sig after-dot-sig
	 (short-help-string
	  "y(es) n(ext) p(revious) C-l (recenter@bot) q(uit) a(bort))")
	 (inserter-confirm
	  (function (lambda ()
	    (setq db-ix (% (1+ db-ix) (length cit-db)))
	    (insert (elt cit-db db-ix))))))
    (save-excursion
      (goto-char (point-max))
      (setq before-dot-sig (point))
      (insert-file-contents en-signature-hook-plain-sigfile)
      (goto-char (point-max))
      (setq after-dot-sig (point))
      (funcall inserter-confirm)
      (catch 'out
	(while (not (memq ch '(?y ?\ )))
	  (message "%s" short-help-string)
	  (setq ch (read-char))
	  (cond ((= ch ?a)
		 (delete-region (point) before-dot-sig)
		 (throw 'out nil))
		((= ch ?q)
		 (delete-region (point) after-dot-sig)
		 (throw 'out nil))
		((= ch ?\C-l)
		 (recenter -1))
		((= ch ?n)
		 (delete-region (point) after-dot-sig)
		 (funcall inserter-confirm))
		((= ch ?p)
		 (delete-region (point) after-dot-sig)
		 (setq db-ix (- db-ix 2))
		 (if (< db-ix 0) (setq db-ix (1- (length cit-db))))
		 (funcall inserter-confirm))))))))


Put the above file somewhere along your `load-path' and give it a spin.

BTW: I'm using Kyle Jones' VM (View Mail) package for GNU Emacs. Try it
- it's great.

Eyvind.

+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 Eyvind Ness                    Internet Email: Eyvind.Ness@HRP.No
 Research Scientist             Phone: +47 9 183100
 Control Room Systems Division  Fax: +47 9 187109
 OECD Halden Reactor Project    Surface Mail: P.O. Box 173, N-1751 Halden
 Norway
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+


 -A language that doesn't affect the way you think about programming is
not worth knowing. Alan Perlis