home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / insert-signature.el < prev    next >
Encoding:
Text File  |  1991-03-30  |  5.7 KB  |  166 lines

  1. ; Path: utkcs2!emory!swrinde!ucsd!ucbvax!CHAOS.CS.BRANDEIS.EDU!morgan
  2. ; >From: morgan@CHAOS.CS.BRANDEIS.EDU ("Dylan Kaufman")
  3. ; Newsgroups: comp.emacs
  4. ; Subject: appending .signature to outgoing mail in RMAIL [Shameful C-c C-w]
  5. ; Date: 15 Aug 90 01:28:38 GMT
  6. ; References: <1990Aug14.135931.8296@cbnewse.att.com>
  7. ; -> Date: 14 Aug 90 13:59:31 GMT
  8. ; -> From: att!cbnewse!danj1@cis.ohio-state.edu
  9. ; -> 
  10. ; -> In gnu.emacs, kondaman@aludra.usc.edu (Arjun Krishna Kondamani) writes:
  11. ; -> >I am thinking of the easiest way that I can append my .signature file
  12. ; -> >to any mail I send. Any tips/pointers will be greatly appreciated.
  13. ; -> 
  14. ; -> [I think this is just a mail-mode thing, not an RMAIL thing, I don't
  15. ; -> know, I'm a VM kind of guy.]
  16. ; -> 
  17. ; -> But: Isn't is a shame that C-c C-w insists on sticking your .signature at
  18. ; -> the end of the mail message, no matter what argument you give it, etc.
  19. ; -> 
  20. ; -> About 37% of the time I want to stick it, say, above a chunk of
  21. ; -> forwarded material, but, no, no go... I have to type C-x i ~/.signature .
  22. ; -> 
  23. ; -> [version 18.55]
  24. ; ->
  25. ; Here is something which I worked up which will put the .signature file
  26. ; into the message you are trying to send.  However, it does a little
  27. ; bit of processing first.  
  28. ; My idea was that sometimes I put a P.S. or an enclosure at the end of
  29. ; the message.  As with a 'normal' handwritten letter I would send to a
  30. ; friend, I would want the P.S. or enclosure to follow my signature.
  31. ; (As I describe what this does, I am not entirely sure of the order)
  32. ; First it will try to determine whether it is being sent to 'friends'
  33. ; or not.  The definition of a 'friend' is someone who is either on your
  34. ; local system or aliases (ie. with no '@' in the address).  All I have
  35. ; done to make this determination is to search in the header for '@'.
  36. ; Needless to say, that is not terribly reliable, but I didn't know
  37. ; anything about regexps then and know very little now.. someone want to
  38. ; make it more reliable?  The purpose of this definition is that it uses
  39. ; .signature-local for 'friends' and .signature for non-'friends'
  40. ; (enemies? ;> ).
  41. ; Once it knows what signature to use, the procedure decides WHERE to
  42. ; put the signature.  The first thing it does is search for P.S. at the
  43. ; beginning of a line.  If it finds it, it will put the signature there.
  44. ; If it does not, it searches for E.F. (enclosure follows) at the
  45. ; beginning of a line.  
  46. ; Having decided WHERE to put the signature, it goes through and changes
  47. ; the first occurence of \^JE.F. with a header which says something to
  48. ; the effect of Enclosure Follows.
  49. ; This is a very incomplete set of functions.  
  50. ;     First of all, it ought to do some kind of REAL searching to
  51. ; determine whether the message is being sent to any non-'friend's.
  52. ;     Second, I want to have a marker which doesn't put in a
  53. ; separator like E.F.  This would be for cases in which you only wanted
  54. ; to put the sig in at a specific place.
  55. ;     Third, I want to have it search more than once for E.F. to
  56. ; have more than one 'enclosure'.  Next, I want to set it up so that if
  57. ; I put a filename or some sort of description on the line with the
  58. ; ---------------------------An enclosure follows---------------------------
  59. ; I have the function send-out-mail bound to C-c C-e.
  60. ;     Anyone else have any suggestions?
  61. ;                  -<>Dylan<>-
  62. ;  
  63. ;              morgan@chaos.cs.brandeis.edu
  64. ; P.S.  It searches for the first E.F. _after_ a P.S., so the signature
  65. ; will always be before the P.S., not the E.F., if it exists.
  66. ; P.P.S.  It ignores postscripts after the first. ;)
  67. ; P.P.P.S.  If it finds neither \^JP.S. nor \^JE.F., it will put the
  68. ; signature at the end... (thus the idea listed above)
  69. ; P.P.P.P.S. Yes, there will be an end! ;)  The function allows three
  70. ; lines of separator for the E.F. as you will notice below.
  71. ; P.P.P.P.P.S. There is a variable called to-cc-separator which I put
  72. ; (when I remember) after the To: and (if it's there) CC: files which
  73. ; marks the end of the area to search.  This will make the '@' search
  74. ; faintly more reliable.
  75. ; E.F.
  76. ;
  77.  
  78. ;;; Mail sending functions
  79.  
  80. (defun send-out-mail ()
  81.   "This function places the signature file into a mail file before sending it out."
  82.   (interactive)
  83.   (beginning-of-buffer)
  84.   (if (search-forward "\^JP.S." (buffer-size) t)
  85.       (set-sig-mark)
  86.       (if (search-forward "\^JE.F." (buffer-size) t)
  87.       (set-sig-mark)
  88.       (sig-at-end)))
  89.   (beginning-of-buffer)
  90.   (if (search-forward "\^JE.F." (buffer-size) t)
  91.       (set-up-enclosure))
  92.   (send-it))
  93.  
  94. (defvar sig-mark-string "\^J-insert signature here-")
  95.  
  96. (defun set-sig-mark () 
  97.   (beginning-of-line)
  98.   (insert sig-mark-string "\n"))
  99.  
  100. (defun sig-at-end ()
  101.   (interactive)
  102.   (end-of-buffer)
  103.   (set-sig-mark))
  104.  
  105. (defvar separator-string "---------------------------An enclosure follows---------------------------")
  106. (defvar encl-head-1 "")
  107. (defvar encl-head-2 "")
  108.  
  109. (defun set-up-enclosure ()
  110.   (interactive)
  111.   (beginning-of-line)
  112.   (kill-line 1)
  113.   (insert separator-string "\n" encl-head-1 encl-head-2))
  114.  
  115. (defvar to-cc-separator "\^JPlace the to and cc fields above this line")
  116.  
  117. (defun determine-sig-file ()
  118.   (interactive)
  119.   (beginning-of-buffer)
  120.   (if (not (search-forward to-cc-separator (buffer-size) t))
  121.       (search-forward mail-header-separator (buffer-size) t)
  122.       (remove-separator))
  123.   (if (search-backward "@" '0 t)
  124.       (setq sig-file "~/.signature")
  125.       (setq sig-file "~/.signature-local")))
  126.  
  127. (defun remove-separator ()
  128.   (interactive)
  129.   (beginning-of-line)
  130.   (kill-line 1))
  131.  
  132. (defvar sig-file nil)
  133.  
  134. (defun send-it ()
  135.   (interactive)
  136.   (beginning-of-buffer)
  137.   (determine-sig-file)
  138.   (search-forward sig-mark-string (buffer-size) t)
  139.   (beginning-of-line)
  140.   (kill-line 1)
  141.   (insert-file sig-file)
  142.   (mail-send-and-exit ()))
  143.  
  144.  
  145.