(defvar signature-random-stuff "" "*Random stuff to put after your name in the signature") (defvar sigfile-sigs-dir (concat (getenv "HOME") "/txt/sigs/") "*Where to find signatures") (defun insert-random-sig() "Insert a random signature into the buffer. The .sig is picked at random from a file called \"~/.signatures\", which consists of a collection of quotes - see http://www.waider.ie/misc/quotes.txt for an example. This function automatically discards anything that will go over four lines, and inserts various other information depending on how much room there is in the .sig area. The -- sequence is automatically appended to your email before the .sig." (save-excursion ;; new feature: check for a domain-specific .sig first, in case I'm ;; MAILING FROM THE OFFICE (let ((dotsig nil) (dotsigfile nil) (from (or (car (fmailutils-header-contents "FROM")) "")) (domains (directory-files sigfile-sigs-dir nil "^[^.][^.]?.*$"))) ;; icky, works ;; this is dubious but workable (while (and domains (null dotsigfile)) (if (string-match (concat "@" (car domains) ">?$") from) (setq dotsigfile (car domains)) (setq domains (cdr domains)))) ;; and this is a kludge, because I'm too lazy to rewrite (if dotsigfile (setq dotsigfile (concat sigfile-sigs-dir dotsigfile)) (setq dotsigfile (expand-file-name "~/.signatures"))) (goto-char (point-max));; slightly bogus ;; Check if there's already a signature. This is a godawful ;; hack. (save-excursion (let ((end (point))) (if (re-search-backward "^-- \n" (point-min) t) (delete-region (point) end)))) (insert "-- \n") (let (siglen) (save-excursion ;; Must be a nicer way to do this (set-buffer (get-buffer-create ".signatures")) (erase-buffer) (insert-file dotsigfile) ;; narrow off the top region (if (re-search-forward "^-----" (point-max) t) (progn (forward-line 1) (let ((top (point)) (bottom (point-max))) (narrow-to-region top bottom)))) (while (null dotsig) ;; Jump to a random point in the file (goto-char (random (point-max))) ;; Locate the .sig delimiters (let ((stab (point)) beg end) (or (re-search-backward "^$" nil t) (goto-char (point-min))) (skip-chars-forward "\r\n") (setq beg (point)) (or (re-search-forward "^$" nil t) (goto-char (point-max))) (skip-chars-backward " \t\r\n") (setq end (point)) ;; Copy the .sig, making sure it's under four lines ;; sillywalk (setq siglen (let ((foo (count-lines-region beg end))) (string-match "has \\([0-9]*\\) lines" foo) (string-to-int (substring foo (match-beginning 1) (match-end 1))))) (if (< siglen 5) (progn (setq dotsig (buffer-substring beg end)) ;; because I want to save quotes that my mother ;; shouldn't see in my email... (if (string-match "fuck\\|shit" dotsig) (setq dotsig nil))))))) ;; See how much room we have before the .sig (if (< siglen 4) (if (or (equal from "") (string-match "@waider.ie" from)) (insert "waider@waider.ie / Yes, it /is/ very personal of me.\n") ;; also bogus: if the sigfile is in HOME, i.e. it's the ;; quotes file, then we need more goop. (if (string= (file-name-directory dotsigfile) (concat (getenv "HOME") "/")) (insert user-full-name " / " signature-random-stuff "\n")))) ;; newline, if there's room (if (and (< siglen 3) (not (string-match user-full-name dotsig))) (insert "\n")) ;; Stick it in the buffer (insert dotsig) (insert "\n"))))) ;; FIXME: put this on if i'm mailing to a list ;; If this helped you, please take the time to rate the value of this post: ;; http://svcs.affero.net/rm.php?r=waider