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