davis@scr.slb.com (Paul Davis) (04/25/89)
Another piece of code I find useful: I really do not have a need for
an archive of complete mail messages I send to others, but I do find
it a help to have a log of when I send mail and to whom. The following
function performs this, writing the date, and the visible mail header
to a file. Its a bit naughty in that it inserts and then deletes the
date into your *mail* buffer without telling you, but then I didn't
want to have to set up a new buffer, farm off the header, add the
date, write the buffer to a file and then kill the new buffer.
I load this as part of my mail-mode-hook:
(setq mail-mode-hook '(lambda ()
(require 'mail-log)
(setq mail-log-outgoing t))
Here's a sample of my mail log file:
----------------------
Date: Mon Apr 24 08:32:01 1989
To: info-gnu-emacs@prep.ai.mit.edu
Subject: generic completion functions/function expansion
----------------------
Date: Mon Apr 24 08:35:59 1989
To: mansfiel
Subject: see Blair in FIN re: travellers cheques
----------------------
Date: Mon Apr 24 08:42:23 1989
To: dingwall%sifvx3%sifvx7.psi@prsrtr.psi
In-reply-to: Schlumberger Technologies Instruments, Farnborough,
Computer Systems Department.'s message of
Mon, 24 Apr 89 16:35:58 PDT <8904242335.AA07489@indigo.scr.slb.com>
Subject: RE: "UKnet"
----------------------
enjoy
Paul
Paul Davis at Schlumberger Cambridge Research
<davis%scrsu1%sdr.slb.com@relay.cs.net>
"to shatter tradition makes us feel free ..."
---- cut here ----
;;; mail-logging
;;; Paul Davis <davis%scr.slb.com@relay.cs.net> April 1989
;;;
;;; this code is subject to the terms of the GNU Emacs general public license
;;; provide logging of outgoing mail messages
;;; if mail-log-outgoing is non-nil, then each call to
;;; mail-send will append the date and header of the outgoing
;;; mail message to mail-log-file (~/.mail-log by default).
(defvar mail-log-outgoing nil
"*If non-nil, write the addressee and date of each outgoing mail
message to mail-log-file")
(defvar mail-log-file "~/.mail-log")
(defun mail-send ()
"Send the message in the current buffer.
If mail-interactive is non-nil, wait for success indication
or error messages, and inform user.
Otherwise any failure is reported in a message back to
the user from the mailer.
If mail-log-outgoing is non-nil, write a summary of the outgoing mail
to mail-log-file."
(interactive)
(if mail-log-outgoing
(mail-write-log))
(message "Sending...")
(funcall send-mail-function)
(set-buffer-modified-p nil)
(delete-auto-save-file-if-necessary)
(message "Sending...done"))
(defun mail-write-log ()
(save-excursion
(save-restriction
(goto-char (point-min))
(insert (concat "----------------------\nDate: "
(current-time-string) "\n"))
(re-search-forward
(concat "^" (regexp-quote mail-header-separator)))
(beginning-of-line)
(write-region (point-min) (point) mail-log-file t 1)
(delete-region (point-min)
(save-excursion
(goto-char (point-min))
(end-of-line 2)
(1+ (point)))))))
(provide 'mail-log)