home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / emacs / sources / 814 < prev    next >
Encoding:
Text File  |  1992-11-21  |  11.5 KB  |  327 lines

  1. Newsgroups: gnu.emacs.sources
  2. Path: sparky!uunet!psinntp!snoopy!short
  3. From: short@asf.com (Lee Short)
  4. Subject: rmail utilities
  5. Message-ID: <1992Nov20.225236.5809@asf.com>
  6. Sender: short@asf.com (Lee Short)
  7. Organization: ASF
  8. Date: Fri, 20 Nov 1992 22:52:36 GMT
  9. Lines: 316
  10.  
  11.  
  12. Here are some utilities for rmail.  In addition to the utilities
  13. themselves is a short file called init.el which shows a sample piece
  14. of code a typical user might put in his/her .emacs to utilize the
  15. functions.  
  16.  
  17. The first of utility is a redefinition of rmail-reply designed to
  18. allow you to automatically copy yourself on all replies to rmail
  19. messages.  It is in a file called rmail-reply-cc.el.  What it does is
  20. allow the user to set a variable which will automatically CC him on
  21. all replies to rmail messages.
  22.  
  23. The other two utilities have to do with mailing lists, and are placed
  24. together in a file called maillist.el.  The first of these is a
  25. utility that is designed to allow you to easily separate out the
  26. messages from a mailing list into an rmail file of their own.  When
  27. called, it files the current mailing list message to a separate rmail
  28. file, and deletes the message from the current rmail file.  
  29.  
  30. The other utility is designed to alleviate the problem of users
  31. accidentally replying to a mailing list when they intended to send
  32. email to the author of the article.  How it does this is by making any
  33. reply to a mailing list message go to the author of the message, not
  34. the mailing list.  An alternative function submits a followup message
  35. to the list.
  36.  
  37.  
  38. --------------------------------CUT HERE-----------------------------
  39. ;;  rmail-reply-cc.el
  40. ;;  automatically CC's the author of replies to GNU Emacs rmail messages.
  41. ;;
  42. ;;  written by Lee Short (short@asf.com)
  43. ;;  Copyright (C) 1992 Lee Short.
  44. ;;  last mod: 20 November, 1992
  45.  
  46. ;; This is free software; you can redistribute it and/or modify
  47. ;; it under the terms of the GNU General Public License as published by
  48. ;; the Free Software Foundation.  
  49.  
  50. ;; This software is distributed in the hope that it will be useful,
  51. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  52. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  53. ;; GNU General Public License for more details.
  54.  
  55. ;; For a copy of the GNU General Public License write to
  56. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  57.  
  58.  
  59. (defvar  my-mail-address "foo@bar.com" 
  60. "The users email address as it will be automaticlly inserted on CC: 
  61. lines.")
  62.  
  63. (defvar  auto-cc nil 
  64. "The value of this variable determines if the user will be automatically 
  65. CCed on mail messages.  If maillist.el is also used, then this
  66. variable is overridden by the three auto-cc-on-* variables found in 
  67. that file." )
  68.  
  69. (defun rmail-reply (just-sender)
  70.   "Reply to the current message.
  71. Normally include CC: to all other recipients of original message;
  72. prefix argument means ignore them.
  73. While composing the reply, use \\[mail-yank-original] to yank the
  74. original message into it."
  75.   (interactive "P")
  76.   ;;>> this gets set even if we abort. Can't do anything about it, though.
  77.   (rmail-set-attribute "answered" t)
  78.   (rmail-display-labels)
  79.   (let (from reply-to cc subject date to message-id resent-reply-to)
  80.     (save-excursion
  81.       (save-restriction
  82.     (widen)
  83.     (goto-char (rmail-msgbeg rmail-current-message))
  84.     (forward-line 1)
  85.     (if (= (following-char) ?0)
  86.         (narrow-to-region
  87.          (progn (forward-line 2)
  88.             (point))
  89.          (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
  90.                     'move)
  91.             (point)))
  92.       (narrow-to-region (point)
  93.                 (progn (search-forward "\n*** EOOH ***\n")
  94.                    (beginning-of-line) (point))))
  95.     (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
  96.           from (mail-fetch-field "from")
  97.           reply-to (or resent-reply-to
  98.                (mail-fetch-field "reply-to" nil t)
  99.                from)
  100.           cc (cond (just-sender nil)
  101.                (resent-reply-to (mail-fetch-field "resent-cc" t))
  102.                (t (mail-fetch-field "cc" nil t)))
  103.           subject (or (and resent-reply-to
  104.                    (mail-fetch-field "resent-subject" t))
  105.               (mail-fetch-field "subject"))
  106.           date (cond (resent-reply-to
  107.               (mail-fetch-field "resent-date" t))
  108.              ((mail-fetch-field "date")))
  109.           to (cond (resent-reply-to
  110.             (mail-fetch-field "resent-to" t))
  111.                ((mail-fetch-field "to" nil t))
  112.                ;((mail-fetch-field "apparently-to")) ack gag barf
  113.                (t ""))
  114.           message-id (cond (resent-reply-to
  115.                 (mail-fetch-field "resent-message-id" t))
  116.                    ((mail-fetch-field "message-id"))))))
  117.     (and subject
  118.      (string-match "\\`Re: " subject)
  119.      (setq subject (substring subject 4)))
  120.     (mail-other-window nil
  121.       (mail-strip-quoted-names reply-to)
  122.       subject
  123.       (rmail-make-in-reply-to-field from date message-id)
  124.       (let  ((cc-string
  125.           (if just-sender
  126.           nil
  127.                 (let* ((cc-list (rmail-dont-reply-to
  128.                           (mail-strip-quoted-names
  129.                           (if (null cc) to (concat to ", " cc))))))
  130.              (if (string= cc-list "") nil cc-list)))))
  131.          (if  (null cc-string)
  132.               (if auto-cc my-mail-address nil)
  133.               (if auto-cc
  134.                   (concat cc-string ", " my-mail-address)
  135.                   cc-string)))
  136.       (current-buffer))))
  137.  
  138. --------------------------------CUT HERE-----------------------------
  139. ;;  maillist.el
  140. ;;  mailing list utilities for GNU Emacs.
  141. ;;
  142. ;;  written by Lee Short (short@asf.com)
  143. ;;  Copyright (C) 1992 Lee Short.
  144. ;;  last mod: 20 November, 1992
  145.  
  146. ;; This is free software; you can redistribute it and/or modify
  147. ;; it under the terms of the GNU General Public License as published by
  148. ;; the Free Software Foundation.  
  149.  
  150. ;; This software is distributed in the hope that it will be useful,
  151. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  152. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  153. ;; GNU General Public License for more details.
  154.  
  155. ;; For a copy of the GNU General Public License write to
  156. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  157.  
  158.  
  159. (defvar  auto-cc-on-maillist-reply nil
  160. "This variable determines if the user will be automatically CCed on replies
  161. to the author of a mailing list message.  This will not work properly unless 
  162. you also have rmail-reply-cc.el" )
  163.  
  164. (defvar  auto-cc-on-maillist-followup nil
  165. "This variable determines if the user will be automatically CCed on followups
  166. to a mailing list message.  This will not work properly unless 
  167. you also have rmail-reply-cc.el" )
  168.  
  169. (defvar  auto-cc-on-nonlist-reply nil
  170. "This variable determines if the user will be automatically CCed on replies
  171. to a mail message.  This will not work properly unless 
  172. you also have rmail-reply-cc.el" )
  173.  
  174. ; the following defvar should be uncommented if rmail-reply-cc.el is not used
  175. ;
  176. ; (defvar  my-mail-address "foo@bar.com" 
  177. ; "The user's email address as it will be automaticlly inserted on CC: 
  178. ; lines.")
  179.  
  180. ; the following defvar should be uncommented if rmail-reply-cc.el is not used
  181. ;
  182. ; (defvar  auto-cc nil 
  183. ; "The value of this variable determines if the user will be automatically 
  184. ; CC'd on mail messages.  )
  185.  
  186.  
  187. (defconst maillists 
  188.        '( ( "Reply-to: DRS@utxvm.cc.utexas.edu" "~/drs.rmail" ) 
  189.           ( "Reply-To: Dead Runners Mind <DRM@DARTCMS1.BITNET>" "~/drs.rmail" )
  190.         )
  191.  "A list which describes the user's mailing lists in a format usable by 
  192. maillist.el.  Each entry in the list is itself a list.  The first entry in 
  193. each sublist is an identifying string in the text of messages from the 
  194. mailing list, the second is the name of the rmail file in which to save 
  195. messages from the mailing list.  Any message in which the identifying 
  196. string is found is assumed to be a message from the mailing list.  Thus, 
  197. a forwarded message from the mailing list is likely to be flagged as 
  198. coming from the list."
  199. )
  200.  
  201.  
  202. (defun file-to-maillist ()
  203. "Saves the current rmail message to the rmail file for its mailing list, as 
  204. specified in the constant maillists."
  205. ;;  searches the message for a match with any of the identifying strings 
  206. ;;  given in maillists.  As soon as it finds a match, it outputs the message
  207. ;;  to the mailing list's rmail file and deletes it from the current rmail
  208. ;;  file
  209.    (interactive)
  210.    (rmail-output-to-rmail-file 
  211.       (let  ( (current-list maillists) 
  212.               (rmail-filename nil)  )
  213.           (while  (and (car current-list) (not rmail-filename) )
  214.               (if (my-string-find (car (car current-list) ) )
  215.                   (setq rmail-filename (car (cdr ( car current-list) ) ) )  )
  216.               (setq current-list (cdr current-list) )
  217.           )
  218.           rmail-filename
  219.       )
  220.    )
  221.    (rmail-delete-forward)
  222. )
  223.  
  224.  
  225. (defun reply-to-maillist-message ()
  226. "Initiates a reply to the author of a mailing list article."
  227.    (let  ( (from nil) )
  228.       (interactive)
  229.       (delete-other-windows)
  230.       (setq auto-cc auto-cc-on-maillist-reply)
  231.       (rmail-reply t)        ;; you are now in the mail buffer
  232.  
  233.       (beginning-of-buffer)
  234.       (word-search-forward "To: " nil t)
  235.       (kill-line)               ;; waste the old "to" field
  236.       (insert ": ")
  237.  
  238.       (other-window 1)          ;; you are now in the rmail buffer
  239.       (setq from (mail-fetch-field "from") )      ;; find the author's name
  240.  
  241.       (other-window 1)        ;; you are now in the mail buffer
  242.       (insert from)          ;; insert the name of the author
  243.  
  244.       (end-of-buffer)
  245.       (newline)
  246.    )
  247. )
  248.  
  249.  
  250. (defun my-rmail-followup  ()
  251. "Initiates a followup to the mailing list in reply to a mailing list article."
  252.    (interactive)
  253.    (delete-other-windows)
  254.    (setq auto-cc auto-cc-on-maillist-followup)
  255.    (rmail-reply t)
  256. )
  257.  
  258. (defun my-string-find  (string-arg)
  259. "Searches for a string in the current buffer.  Returns t if it is found, 
  260. nil otherwise."
  261.    (set-mark-command nil)          ;;  store point
  262.    (beginning-of-buffer)
  263.    (if  (word-search-forward string-arg nil t)
  264.        (progn
  265.           (set-mark-command t)          ;;  restore point
  266.           t
  267.        )
  268.        (progn
  269.           (set-mark-command t)          ;;  restore point
  270.           nil
  271.        )
  272.    )
  273. )
  274.  
  275. (defun maillist-p ()
  276. "Determines if the current rmail message is in one of the mailing lists as 
  277. defined by the constant maillists."
  278.    (let  ( (current-list maillists) 
  279.            (found nil)  )
  280.        (while  (and (car current-list) (not found) )
  281.            (if (my-string-find (car (car current-list) ) )
  282.                (setq found t)  )
  283.            (setq current-list (cdr current-list) )
  284.        )
  285.        found
  286.    )
  287. )
  288.  
  289. (defun my-rmail-reply  ()
  290. "Sends a reply to the author of an rmail message, if the message is either a 
  291. regular message, or a message from one of the mailing lists defined by the 
  292. variable maillists.  Any other mailing list message will likely result in 
  293. a reply to the mailing list, rather than the author."  
  294.     (interactive)
  295.     (if (maillist-p)
  296.         (reply-to-maillist-message)
  297.         (progn
  298.            (setq auto-cc auto-cc-on-nonlist-reply)
  299.            (rmail-reply nil)
  300.         )
  301.     )
  302. )
  303.  
  304. --------------------------------CUT HERE-----------------------------
  305. ;;  init.el
  306. ;;  sample of code for a .emacs
  307.  
  308. (load "rmail-reply-cc.el")
  309. (load "maillist.el")
  310.  
  311. (setq  auto-cc-on-maillist-reply t)
  312. (setq  auto-cc-on-maillist-followup t)
  313. (setq  auto-cc-on-nonlist-reply t)
  314.  
  315. (define-key rmail-mode-map "b" 'file-to-maillist)
  316. (define-key rmail-mode-map "r" 'my-rmail-reply)
  317. (define-key rmail-mode-map "F" 'my-rmail-followup)
  318. --------------------------------CUT HERE-----------------------------
  319.  
  320. hope this is useful,
  321. Lee
  322. -- 
  323. short@asf.com              The mystery of government is not how Washington
  324. Lee Short                  works, but how to make it stop.  -- P.J. O'Rourke
  325. Software Janitor        I speak for none of the many steps in the food chain
  326. Hughes Training, Inc.         between myself and General Motors corporation.
  327.