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