home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / packages / rnewspost.el < prev    next >
Encoding:
Text File  |  1993-01-29  |  15.5 KB  |  410 lines

  1. ;;; USENET news poster/mailer for GNU Emacs
  2. ;; Copyright (C) 1985-1993 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 2, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;; moved posting and mail code from rnews.el
  21. ;;    tower@prep.ai.mit.edu Wed Oct 29 1986
  22. ;; brought posting code almost up to the revision of RFC 850 for News 2.11
  23. ;; - couldn't see handling the special meaning of the Keyword: poster
  24. ;; - not worth the code space to support the old A news Title: (which
  25. ;;   Subject: replaced) and Article-I.D.: (which Message-ID: replaced)
  26. ;;    tower@prep Nov 86
  27. ;; changed C-c C-r key-binding due to rename of news-caesar-buffer-body
  28. ;;    tower@prep 21 Nov 86
  29. ;; added (require 'rnews)    tower@prep 22 Apr 87
  30. ;; restricted call of news-show-all-headers in news-post-news & news-reply
  31. ;;    tower@prep 28 Apr 87
  32. ;; commented out Posting-Front-End to save USENET bytes tower@prep Jul 31 87
  33. ;; commented out -n and -t args in news-inews     tower@prep 15 Oct 87
  34. (require 'sendmail)
  35. (require 'rnews)
  36.  
  37. ;Now in paths.el.
  38. ;(defvar news-inews-program "inews"
  39. ;  "Function to post news.")
  40.  
  41. ;; Replying and posting news items are done by these functions.
  42. ;; imported from rmail and modified to work with rnews ...
  43. ;; Mon Mar 25,1985 at 03:07:04 ads@mit-hermes.
  44. ;; this is done so that rnews can operate independently from rmail.el and
  45. ;; sendmail and dosen't have to autoload these functions.
  46. ;;
  47. ;;; >> Nuked by Mly to autoload those functions again, as the duplication of
  48. ;;; >>  code was making maintenance too difficult.
  49.  
  50. (defvar news-reply-mode-map () "Mode map used by news-reply.")
  51.  
  52. (or news-reply-mode-map
  53.     (progn
  54.       (setq news-reply-mode-map (make-keymap))
  55.       (define-key news-reply-mode-map "\C-c?" 'describe-mode)
  56.       (define-key news-reply-mode-map "\C-c\C-f\C-d" 'news-reply-distribution)
  57.       (define-key news-reply-mode-map "\C-c\C-f\C-k" 'news-reply-keywords)
  58.       (define-key news-reply-mode-map "\C-c\C-f\C-n" 'news-reply-newsgroups)
  59.       (define-key news-reply-mode-map "\C-c\C-f\C-f" 'news-reply-followup-to)
  60.       (define-key news-reply-mode-map "\C-c\C-f\C-s" 'mail-subject)
  61.       (define-key news-reply-mode-map "\C-c\C-f\C-a" 'news-reply-summary)
  62.       (define-key news-reply-mode-map "\C-c\C-r" 'news-caesar-buffer-body)
  63.       (define-key news-reply-mode-map "\C-c\C-w" 'news-reply-signature)
  64.       (define-key news-reply-mode-map "\C-c\C-y" 'news-reply-yank-original)
  65.       (define-key news-reply-mode-map "\C-c\C-q" 'mail-fill-yanked-message)
  66.       (define-key news-reply-mode-map "\C-c\C-c" 'news-inews)
  67.       (define-key news-reply-mode-map "\C-c\C-s" 'news-inews)))
  68.  
  69. (defun news-reply-mode ()
  70.   "Major mode for editing news to be posted on USENET.
  71. First-time posters are asked to please read the articles in newsgroup:
  72.                                                      news.announce.newusers .
  73. Like Text Mode but with these additional commands:
  74.  
  75. C-c C-s  news-inews (post the message)    C-c C-c  news-inews
  76. C-c C-f     move to a header field (and create it if there isn't):
  77.      C-c C-f C-n  move to Newsgroups:    C-c C-f C-s  move to Subj:
  78.      C-c C-f C-f  move to Followup-To:      C-c C-f C-k  move to Keywords:
  79.      C-c C-f C-d  move to Distribution:    C-c C-f C-a  move to Summary:
  80. C-c C-y  news-reply-yank-original (insert current message, in NEWS).
  81. C-c C-q  mail-fill-yanked-message (fill what was yanked).
  82. C-c C-r  caesar rotate all letters by 13 places in the article's body (rot13)."
  83.   (interactive)
  84.   ;; require...
  85.   (or (fboundp 'mail-setup) (load "sendmail"))
  86.   (kill-all-local-variables)
  87.   (make-local-variable 'mail-reply-buffer)
  88.   (setq mail-reply-buffer nil)
  89.   (set-syntax-table text-mode-syntax-table)
  90.   (use-local-map news-reply-mode-map)
  91.   (setq local-abbrev-table text-mode-abbrev-table)
  92.   (setq major-mode 'news-reply-mode)
  93.   (setq mode-name "News")
  94.   (make-local-variable 'paragraph-separate)
  95.   (make-local-variable 'paragraph-start)
  96.   (setq paragraph-start (concat "^" mail-header-separator "$\\|"
  97.                 paragraph-start))
  98.   (setq paragraph-separate (concat "^" mail-header-separator "$\\|"
  99.                    paragraph-separate))
  100.   (run-hooks 'text-mode-hook 'news-reply-mode-hook))
  101.  
  102. (defvar news-reply-yank-from
  103.   "Save From: field for news-reply-yank-original."
  104.   "")
  105.  
  106. (defvar news-reply-yank-message-id
  107.   "Save Message-Id: field for news-reply-yank-original."
  108.   "")
  109.  
  110. (defun news-reply-yank-original (arg)
  111.   "Insert the message being replied to, if any (in postnews).
  112. Puts point before the text and mark after.
  113. Indents each nonblank line ARG spaces (default 3).
  114. Just \\[universal-argument] as argument means don't indent
  115. and don't delete any header fields."
  116.   (interactive "P")
  117.   (let ((zmacs-regions nil))
  118.     (mail-yank-original arg)
  119.     (exchange-point-and-mark)
  120.     (run-hooks 'news-reply-header-hook)))
  121.  
  122. (defvar news-reply-header-hook
  123.   '(lambda ()
  124.      (insert "In article " news-reply-yank-message-id
  125.              " " news-reply-yank-from " writes:\n\n"))
  126.   "Hook for inserting a header at the top of a yanked message.")
  127.  
  128. (defun news-reply-newsgroups ()
  129.   "Move point to end of Newsgroups: field.
  130. RFC 850 constrains the Newsgroups: field to be a comma separated list of valid
  131. newsgroups names at your site:
  132. Newsgroups: news.misc,comp.misc,rec.misc"
  133.   (interactive)
  134.   (expand-abbrev)
  135.   (goto-char (point-min))
  136.   (mail-position-on-field "Newsgroups"))
  137.  
  138. (defun news-reply-followup-to ()
  139.   "Move point to end of Followup-To: field.  Create the field if none.
  140. One usually requests followups to only one newsgroup.
  141. RFC 850 constrains the Followup-To: field to be a comma separated list of valid
  142. newsgroups names at your site, that are also in the Newsgroups: field:
  143. Newsgroups: news.misc,comp.misc,rec.misc,misc.misc,soc.misc
  144. Followup-To: news.misc,comp.misc,rec.misc"
  145.   (interactive)
  146.   (expand-abbrev)
  147.   (or (mail-position-on-field "Followup-To" t)
  148.       (progn (mail-position-on-field "newsgroups")
  149.          (insert "\nFollowup-To: ")))
  150.      ;; @@ could do a completing read based on the Newsgroups: field to
  151.      ;; @@ fill in the Followup-To: field
  152. )
  153.  
  154. (defun news-reply-distribution ()
  155.   "Move point to end of Distribution: optional field.
  156. Create the field if none.  Without this field the posting goes to all of
  157. USENET.  The field is used to restrict the posting to parts of USENET."
  158.   (interactive)
  159.   (expand-abbrev)
  160.   (mail-position-on-field "Distribution")
  161.   ;; @@could do a completing read based on the news library file:
  162.   ;; @@    ../distributions  to fill in the field.
  163.   )
  164.  
  165. (defun news-reply-keywords ()
  166.   "Move point to end of Keywords: optional field.  Create the field if none.
  167. Used as an aid to the news reader, it can contain a few, well selected keywords
  168. identifying the message."
  169.   (interactive)
  170.   (expand-abbrev)
  171.   (mail-position-on-field "Keywords"))
  172.  
  173. (defun news-reply-summary ()
  174.   "Move point to end of Summary: optional field.  Create the field if none.
  175. Used as an aid to the news reader, it can contain a succinct
  176. summary (abstract) of the message."
  177.   (interactive)
  178.   (expand-abbrev)
  179.   (mail-position-on-field "Summary"))
  180.  
  181. (defun news-reply-signature ()
  182.   "The inews program appends ~/.signature automatically."
  183.   (interactive)
  184.   (message "~/.signature will be appended automatically."))
  185.  
  186. (defun news-setup (to subject in-reply-to newsgroups replybuffer)
  187.   "Setup the news reply or posting buffer with the proper headers and in
  188. news-reply-mode."
  189.   (setq mail-reply-buffer replybuffer)
  190.   (let ((mail-setup-hook nil))
  191.     (if (null to)
  192.     ;; this hack is needed so that inews wont be confused by 
  193.     ;; the fcc: and bcc: fields
  194.     (let ((mail-self-blind nil)
  195.           (mail-archive-file-name nil))
  196.       (mail-setup to subject in-reply-to nil replybuffer nil)
  197.       (beginning-of-line)
  198.       (kill-line 1)
  199.       (goto-char (point-max)))
  200.       (mail-setup to subject in-reply-to nil replybuffer nil))
  201.     ;;;(mail-position-on-field "Posting-Front-End")
  202.     ;;;(insert (emacs-version))
  203.     (goto-char (point-max))
  204.     (if (let ((case-fold-search t))
  205.       (re-search-backward "^Subject:" (point-min) t))
  206.     (progn (beginning-of-line)
  207.            (insert "Newsgroups: " (or newsgroups "") "\n")
  208.            (if (not newsgroups)
  209.            (backward-char 1)
  210.          (goto-char (point-max)))))
  211.     (run-hooks 'news-setup-hook)))
  212.    
  213. (defun news-inews ()
  214.   "Send a news message using inews."
  215.   (interactive)
  216.   (let* (newsgroups subject
  217.             (case-fold-search nil))
  218.     (save-excursion
  219.       (save-restriction
  220.     (goto-char (point-min))
  221.     (search-forward (concat "\n" mail-header-separator "\n"))
  222.     (narrow-to-region (point-min) (point))
  223.     (setq newsgroups (mail-fetch-field "newsgroups")
  224.           subject (mail-fetch-field "subject")))
  225.       (widen)
  226.       (goto-char (point-min))
  227.       (run-hooks 'news-inews-hook)
  228.       (goto-char (point-min))
  229.       (search-forward (concat "\n" mail-header-separator "\n"))
  230.       (replace-match "\n\n")
  231.       (goto-char (point-max))
  232.       ;; require a newline at the end for inews to append .signature to
  233.       (or (= (preceding-char) ?\n)
  234.       (insert ?\n))
  235.       (message "Posting to USENET...")
  236.       (call-process-region (point-min) (point-max) 
  237.                news-inews-program nil 0 nil
  238.                "-h")    ; take all header lines!
  239.                ;@@ setting of subject and newsgroups still needed?
  240.                ;"-t" subject
  241.                ;"-n" newsgroups
  242.       (message "Posting to USENET... done")
  243.       (goto-char (point-min))        ;restore internal header separator
  244.       (search-forward "\n\n")
  245.       (replace-match (concat "\n" mail-header-separator "\n"))
  246.       (set-buffer-modified-p nil))
  247.     (and (fboundp 'bury-buffer) (bury-buffer))))
  248.  
  249. (defvar news-reply-subject-prefix nil
  250.   "*The prefix to use when replying to a news message (such as \"Re:\").")
  251.  
  252. ;@@ shares some code with news-reply and news-post-news
  253. (defun news-mail-reply ()
  254.   "Mail a reply to the author of the current article.
  255. While composing the reply, use \\[news-reply-yank-original] to yank the
  256. original message into it."
  257.   (interactive)
  258.   (let (from cc subject date to reply-to references message-id ;;b
  259.     (buffer (current-buffer)))
  260.     (save-restriction
  261.       (widen)
  262.       (narrow-to-region (point-min) (progn (goto-char (point-min))
  263.                        (search-forward "\n\n")
  264.                        (- (point) 1)))
  265.       (setq from (mail-fetch-field "from")
  266.         subject (mail-fetch-field "subject")
  267.         reply-to (mail-fetch-field "reply-to")
  268.         date (mail-fetch-field "date")
  269.         references (mail-fetch-field "references")
  270.         message-id (mail-fetch-field "message-id"))
  271.       (if (and news-reply-subject-prefix subject
  272.        (not (string-match
  273.          (concat "^[ \t]*" (regexp-quote news-reply-subject-prefix)
  274.              "[ )t]*")
  275.          subject)))
  276.       (setq subject (concat news-reply-subject-prefix " " subject)))
  277.       (setq to from)
  278.       (pop-to-buffer "*mail*")
  279. ;;      (setq b (current-buffer))
  280.       (if (mail nil (if reply-to reply-to to) subject
  281.         (let ((stop-pos
  282.                (string-match "  *at \\|  *@ \\| *(\\| *<" from)))
  283.           (concat (if stop-pos (substring from 0 stop-pos) from)
  284.               "'s message of "
  285.               date))
  286.         nil
  287.         buffer)
  288.       (save-excursion
  289. ;;        (set-buffer b)
  290.         (mail-position-on-field "References")
  291.         (if references (insert references))
  292.         (if (and references message-id) (insert " "))
  293.         (if message-id (insert message-id)))))))
  294.  
  295. ;@@ the guts of news-reply and news-post-news should be combined. -tower
  296. (defun news-reply ()
  297.   "Compose and post a reply (aka a followup) to the current article on USENET.
  298. While composing the followup, use \\[news-reply-yank-original] to yank the
  299. original message into it."
  300.   (interactive)
  301.   (if (y-or-n-p "Are you sure you want to followup to all of USENET? ")
  302.       (let (from cc subject date to followup-to newsgroups message-of
  303.          references distribution message-id
  304.          (buffer (current-buffer)))
  305.     (save-restriction
  306.       (and (not (= 0 (buffer-size))) ;@@real problem is non-existence of
  307.                     ;@@    of article file
  308.            (equal major-mode 'news-mode) ;@@ if rmail-mode,
  309.                     ;@@    should show full headers
  310.            (progn
  311.          (news-show-all-headers) ;@@ should save/restore header state,
  312.                     ;@@    but rnews.el lacks support
  313.          (narrow-to-region (point-min) (progn (goto-char (point-min))
  314.                               (search-forward "\n\n")
  315.                               (- (point) 1)))))
  316.       (setq from (mail-fetch-field "from")
  317.         news-reply-yank-from from
  318.         ;; @@ not handling old Title: field
  319.         subject (mail-fetch-field "subject")
  320.         date (mail-fetch-field "date")
  321.         followup-to (mail-fetch-field "followup-to")
  322.         newsgroups (or followup-to
  323.                    (mail-fetch-field "newsgroups"))
  324.         references (mail-fetch-field "references")
  325.         ;; @@ not handling old Article-I.D.: field
  326.         distribution (mail-fetch-field "distribution")
  327.         message-id (mail-fetch-field "message-id")
  328.         news-reply-yank-message-id message-id)
  329.       (pop-to-buffer "*post-news*")
  330.       (news-reply-mode)
  331.       (if (and (buffer-modified-p)
  332.            (not
  333.             (y-or-n-p "Unsent article being composed; erase it? ")))
  334.           ()
  335.         (progn
  336.           (erase-buffer)
  337.           (and subject
  338.            (progn (if (string-match "\\`Re: " subject)
  339.                   (while (string-match "\\`Re: " subject)
  340.                 (setq subject (substring subject 4))))
  341.               (setq subject (concat "Re: " subject))))
  342.           (and from
  343.            (progn
  344.              (let ((stop-pos
  345.                 (string-match "  *at \\|  *@ \\| *(\\| *<" from)))
  346.                (setq message-of
  347.                  (concat
  348.                   (if stop-pos (substring from 0 stop-pos) from)
  349.                   "'s message of "
  350.                   date)))))
  351.           (news-setup
  352.            nil
  353.            subject
  354.            message-of
  355.            newsgroups
  356.            buffer)
  357.           (if followup-to
  358.           (progn (news-reply-followup-to)
  359.              (insert followup-to)))
  360.           (if distribution
  361.           (progn
  362.             (mail-position-on-field "Distribution")
  363.             (insert distribution)))
  364.           (mail-position-on-field "References")
  365.           (if references
  366.           (insert references))
  367.           (if (and references message-id)
  368.           (insert " "))
  369.           (if message-id
  370.           (insert message-id))
  371.           (goto-char (point-max))))))
  372.     (message "")))
  373.  
  374. ;@@ the guts of news-reply and news-post-news should be combined. -tower
  375. (defun news-post-news ()
  376.   "Begin editing a new USENET news article to be posted.
  377. Type \\[describe-mode] once editing the article to get a list of commands."
  378.   (interactive)
  379.   (if (y-or-n-p "Are you sure you want to post to all of USENET? ")
  380.       (let ((buffer (current-buffer)))
  381.     (save-restriction
  382.       (and (not (= 0 (buffer-size))) ;@@real problem is non-existence of
  383.                     ;@@    of article file
  384.            (equal major-mode 'news-mode) ;@@ if rmail-mode,
  385.                     ;@@    should show full headers
  386.            (progn
  387.          (news-show-all-headers) ;@@ should save/restore header state,
  388.                     ;@@    but rnews.el lacks support
  389.          (narrow-to-region (point-min) (progn (goto-char (point-min))
  390.                               (search-forward "\n\n")
  391.                               (- (point) 1)))))
  392.       (setq news-reply-yank-from (mail-fetch-field "from")
  393.         ;; @@ not handling old Article-I.D.: field
  394.         news-reply-yank-message-id (mail-fetch-field "message-id")))
  395.     (pop-to-buffer "*post-news*")
  396.     (news-reply-mode)
  397.     (if (and (buffer-modified-p)
  398.          (not (y-or-n-p "Unsent article being composed; erase it? ")))
  399.         ()                ;@@ not saving point from last time
  400.       (progn (erase-buffer)
  401.          (news-setup () () () () buffer))))
  402.   (message "")))
  403.  
  404. (defun news-mail-other-window ()
  405.   "Send mail in another window.
  406. While composing the message, use \\[news-reply-yank-original] to yank the
  407. original message into it."
  408.   (interactive)
  409.   (mail-other-window nil nil nil nil nil (current-buffer)))
  410.