home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / mail-add-header.el < prev    next >
Encoding:
Text File  |  1991-07-07  |  2.1 KB  |  55 lines

  1. ; Newsgroups: dg.ml.emacs.vm
  2. ; Path: dg-rtp!uunet!uunet!elroy.jpl.nasa.gov!decwrl!waikato.ac.nz!aukuni.ac.nz!mike-w
  3. ; From: mike-w@cs.aukuni.ac.nz (Mike Williams)
  4. ; Subject: Re: Correcting/Augmenting Mail Headers (was: User setting From: address in sendmail input)
  5. ; Organization: University of Auckland, New Zealand.
  6. ; Date: 3 Jul 91 09:26:27
  7. ;   Here's a couple of elisp functions which facilitate adding and removing
  8. ;   mail (or news) headers.  Just stick the appropriate calls in your
  9. ;   mail-setup-hook, eg.
  10. ;     | (setq mail-setup-hook 'my-mail-setup-hook)
  11. ;     | 
  12. ;     | (defun my-mail-setup-hook ()
  13. ;     |   (mail-add-header "Return-Receipt-To" my-email-address)
  14. ;     |   (mail-add-header "Reply-To" my-email-address 'replace)
  15. ;     |   )
  16. ; --- Shnip 'ere ------------------------------------------------------------
  17. (require 'mail-utils)
  18.  
  19. ;; LCD Archive Entry:
  20. ;; mail-add-header|Mike Williams|mike-w@cs.aukuni.ac.nz
  21. ;; |Functions to add and remove named mail headers
  22. ;; |91-07-03||~/functions/mail-add-header.el.Z
  23.  
  24. (defun mail-add-header (HEADER CONTENTS &optional REPLACE)
  25.   "Add the specified HEADER to the current mail message, with the given 
  26. CONTENTS.  
  27. If the header already exists, the contents are left unchanged, unless optional 
  28. argument REPLACE is non-nil."
  29.   (save-excursion
  30.     (let ((header-exists (mail-position-on-field HEADER)))
  31.       ;; Delete old contents if REPLACE is set
  32.       (if (and header-exists REPLACE)
  33.       (let ((end (point))
  34.         (beg (progn
  35.                (re-search-backward (concat HEADER ": "))
  36.                (goto-char (match-end 0)))))
  37.         (delete-region beg end)))
  38.       ;; Add new contents if REPLACE is set, or this is a new header.
  39.       (if (or (not header-exists) REPLACE)
  40.       (progn (insert CONTENTS) CONTENTS)))))
  41.  
  42. (defun mail-remove-header (HEADER)
  43.   "Remove the specified HEADER from the current mail message."
  44.   (save-excursion
  45.     (if (mail-position-on-field HEADER 'soft)
  46.     (let ((end (point))
  47.           (beg (progn
  48.              (re-search-backward (concat HEADER ": "))
  49.              (goto-char (match-beginning 0)))))
  50.       (delete-region beg (1+ end))))))
  51.