Commit | Line | Data |
---|---|---|
c88ab9ce ER |
1 | ;;; rnewspost.el --- USENET news poster/mailer for GNU Emacs |
2 | ||
f8c25f1b | 3 | ;; Copyright (C) 1985, 1986, 1987, 1995 Free Software Foundation, Inc. |
3a801d0c | 4 | |
e5167999 | 5 | ;; Maintainer: FSF |
d7b4d18f | 6 | ;; Keywords: mail, news |
e5167999 | 7 | |
0d20f9a0 JB |
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 | |
e5167999 | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
0d20f9a0 JB |
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 | |
b578f267 EN |
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. | |
0d20f9a0 | 24 | |
e5167999 ER |
25 | ;; Change Log: |
26 | ||
0d20f9a0 JB |
27 | ;; moved posting and mail code from rnews.el |
28 | ;; tower@prep.ai.mit.edu 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@prep Nov 86 | |
34 | ;; changed C-c C-r key-binding due to rename of news-caesar-buffer-body | |
35 | ;; tower@prep 21 Nov 86 | |
36 | ;; added (require 'rnews) tower@prep 22 Apr 87 | |
37 | ;; restricted call of news-show-all-headers in news-post-news & news-reply | |
38 | ;; tower@prep 28 Apr 87 | |
39 | ;; commented out Posting-Front-End to save USENET bytes tower@prep Jul 31 87 | |
40 | ;; commented out -n and -t args in news-inews tower@prep 15 Oct 87 | |
0d20f9a0 JB |
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 | |
a7acbbe4 | 50 | ;; sendmail and doesn't have to autoload these functions. |
0d20f9a0 JB |
51 | ;; |
52 | ;;; >> Nuked by Mly to autoload those functions again, as the duplication of | |
53 | ;;; >> code was making maintenance too difficult. | |
54 | ||
e5167999 ER |
55 | ;;; Code: |
56 | ||
57 | (require 'sendmail) | |
58 | (require 'rnews) | |
59 | ||
0d20f9a0 JB |
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)) | |
0d20f9a0 JB |
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) | |
4ad33138 | 71 | (define-key news-reply-mode-map "\C-c\C-t" 'mail-text) |
0d20f9a0 JB |
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) | |
ed17d24f RS |
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-signature] | |
100 | '("Signature" . news-reply-signature)) | |
101 | (define-key news-reply-mode-map [menu-bar news news-reply-yank-original] | |
102 | '("Yank Original" . news-reply-yank-original)) | |
103 | (define-key news-reply-mode-map [menu-bar news mail-fill-yanked-message] | |
104 | '("Fill Yanked Messages" . mail-fill-yanked-message)) | |
105 | (define-key news-reply-mode-map [menu-bar news news-inews] | |
106 | '("Send" . news-inews)))) | |
0d20f9a0 JB |
107 | |
108 | (defun news-reply-mode () | |
109 | "Major mode for editing news to be posted on USENET. | |
110 | First-time posters are asked to please read the articles in newsgroup: | |
111 | news.announce.newusers . | |
112 | Like Text Mode but with these additional commands: | |
113 | ||
114 | C-c C-s news-inews (post the message) C-c C-c news-inews | |
115 | C-c C-f move to a header field (and create it if there isn't): | |
116 | C-c C-f C-n move to Newsgroups: C-c C-f C-s move to Subj: | |
117 | C-c C-f C-f move to Followup-To: C-c C-f C-k move to Keywords: | |
118 | C-c C-f C-d move to Distribution: C-c C-f C-a move to Summary: | |
119 | C-c C-y news-reply-yank-original (insert current message, in NEWS). | |
120 | C-c C-q mail-fill-yanked-message (fill what was yanked). | |
121 | C-c C-r caesar rotate all letters by 13 places in the article's body (rot13)." | |
122 | (interactive) | |
123 | ;; require... | |
124 | (or (fboundp 'mail-setup) (load "sendmail")) | |
125 | (kill-all-local-variables) | |
126 | (make-local-variable 'mail-reply-buffer) | |
127 | (setq mail-reply-buffer nil) | |
128 | (set-syntax-table text-mode-syntax-table) | |
129 | (use-local-map news-reply-mode-map) | |
130 | (setq local-abbrev-table text-mode-abbrev-table) | |
131 | (setq major-mode 'news-reply-mode) | |
c6f5b077 | 132 | (setq mode-name "News Reply") |
0d20f9a0 JB |
133 | (make-local-variable 'paragraph-separate) |
134 | (make-local-variable 'paragraph-start) | |
7e31e83e RS |
135 | (setq paragraph-start |
136 | (concat "^" (regexp-quote mail-header-separator) "$\\|" | |
137 | paragraph-start)) | |
138 | (setq paragraph-separate | |
139 | (concat "^" (regexp-quote mail-header-separator) "$\\|" | |
140 | paragraph-separate)) | |
0d20f9a0 JB |
141 | (run-hooks 'text-mode-hook 'news-reply-mode-hook)) |
142 | ||
143 | (defvar news-reply-yank-from | |
d9f86af9 | 144 | "Save `From:' field for `news-reply-yank-original'." |
0d20f9a0 JB |
145 | "") |
146 | ||
147 | (defvar news-reply-yank-message-id | |
d9f86af9 | 148 | "Save `Message-Id:' field for `news-reply-yank-original'." |
0d20f9a0 JB |
149 | "") |
150 | ||
151 | (defun news-reply-yank-original (arg) | |
d9f86af9 | 152 | "Insert the message being replied to, if any (in Mail mode). |
0d20f9a0 JB |
153 | Puts point before the text and mark after. |
154 | Indents each nonblank line ARG spaces (default 3). | |
155 | Just \\[universal-argument] as argument means don't indent | |
156 | and don't delete any header fields." | |
157 | (interactive "P") | |
158 | (mail-yank-original arg) | |
159 | (exchange-point-and-mark) | |
160 | (run-hooks 'news-reply-header-hook)) | |
161 | ||
162 | (defvar news-reply-header-hook | |
163 | '(lambda () | |
164 | (insert "In article " news-reply-yank-message-id | |
165 | " " news-reply-yank-from " writes:\n\n")) | |
166 | "Hook for inserting a header at the top of a yanked message.") | |
167 | ||
168 | (defun news-reply-newsgroups () | |
d9f86af9 RS |
169 | "Move point to end of `Newsgroups:' field. |
170 | RFC 850 constrains the `Newsgroups:' field to be a comma-separated list | |
171 | of valid newsgroup names at your site. For example, | |
172 | Newsgroups: news.misc,comp.misc,rec.misc" | |
0d20f9a0 JB |
173 | (interactive) |
174 | (expand-abbrev) | |
175 | (goto-char (point-min)) | |
176 | (mail-position-on-field "Newsgroups")) | |
177 | ||
178 | (defun news-reply-followup-to () | |
d9f86af9 | 179 | "Move point to end of `Followup-To:' field. Create the field if none. |
0d20f9a0 | 180 | One usually requests followups to only one newsgroup. |
d9f86af9 RS |
181 | RFC 850 constrains the `Followup-To:' field to be a comma-separated list |
182 | of valid newsgroups names at your site, and it must be a subset of the | |
183 | `Newsgroups:' field. For example: | |
184 | Newsgroups: news.misc,comp.misc,rec.misc,misc.misc,soc.misc | |
185 | Followup-To: news.misc,comp.misc,rec.misc" | |
0d20f9a0 JB |
186 | (interactive) |
187 | (expand-abbrev) | |
188 | (or (mail-position-on-field "Followup-To" t) | |
189 | (progn (mail-position-on-field "newsgroups") | |
190 | (insert "\nFollowup-To: "))) | |
191 | ;; @@ could do a completing read based on the Newsgroups: field to | |
192 | ;; @@ fill in the Followup-To: field | |
193 | ) | |
194 | ||
195 | (defun news-reply-distribution () | |
d9f86af9 | 196 | "Move point to end of `Distribution:' optional field. |
0d20f9a0 JB |
197 | Create the field if none. Without this field the posting goes to all of |
198 | USENET. The field is used to restrict the posting to parts of USENET." | |
199 | (interactive) | |
200 | (expand-abbrev) | |
201 | (mail-position-on-field "Distribution") | |
202 | ;; @@could do a completing read based on the news library file: | |
203 | ;; @@ ../distributions to fill in the field. | |
204 | ) | |
205 | ||
206 | (defun news-reply-keywords () | |
d9f86af9 | 207 | "Move point to end of `Keywords:' optional field. Create the field if none. |
0d20f9a0 JB |
208 | Used as an aid to the news reader, it can contain a few, well selected keywords |
209 | identifying the message." | |
210 | (interactive) | |
211 | (expand-abbrev) | |
212 | (mail-position-on-field "Keywords")) | |
213 | ||
214 | (defun news-reply-summary () | |
d9f86af9 | 215 | "Move point to end of `Summary:' optional field. Create the field if none. |
0d20f9a0 JB |
216 | Used as an aid to the news reader, it can contain a succinct |
217 | summary (abstract) of the message." | |
218 | (interactive) | |
219 | (expand-abbrev) | |
220 | (mail-position-on-field "Summary")) | |
221 | ||
222 | (defun news-reply-signature () | |
e63b8030 | 223 | "The inews program appends `~/.signature' automatically." |
0d20f9a0 | 224 | (interactive) |
e63b8030 | 225 | (message "`~/.signature' will be appended automatically.")) |
0d20f9a0 JB |
226 | |
227 | (defun news-setup (to subject in-reply-to newsgroups replybuffer) | |
d9f86af9 | 228 | "Set up the news reply or posting buffer with the proper headers and mode." |
0d20f9a0 | 229 | (setq mail-reply-buffer replybuffer) |
e63b8030 RS |
230 | (let ((mail-setup-hook nil) |
231 | ;; Avoid inserting a signature. | |
232 | (mail-signature)) | |
0d20f9a0 JB |
233 | (if (null to) |
234 | ;; this hack is needed so that inews wont be confused by | |
235 | ;; the fcc: and bcc: fields | |
236 | (let ((mail-self-blind nil) | |
237 | (mail-archive-file-name nil)) | |
238 | (mail-setup to subject in-reply-to nil replybuffer nil) | |
239 | (beginning-of-line) | |
38c132a9 | 240 | (delete-region (point) (progn (forward-line 1) (point))) |
0d20f9a0 JB |
241 | (goto-char (point-max))) |
242 | (mail-setup to subject in-reply-to nil replybuffer nil)) | |
243 | ;;;(mail-position-on-field "Posting-Front-End") | |
244 | ;;;(insert (emacs-version)) | |
245 | (goto-char (point-max)) | |
246 | (if (let ((case-fold-search t)) | |
247 | (re-search-backward "^Subject:" (point-min) t)) | |
248 | (progn (beginning-of-line) | |
249 | (insert "Newsgroups: " (or newsgroups "") "\n") | |
250 | (if (not newsgroups) | |
251 | (backward-char 1) | |
252 | (goto-char (point-max))))) | |
253 | (run-hooks 'news-setup-hook))) | |
254 | ||
255 | (defun news-inews () | |
256 | "Send a news message using inews." | |
257 | (interactive) | |
258 | (let* (newsgroups subject | |
259 | (case-fold-search nil)) | |
260 | (save-excursion | |
261 | (save-restriction | |
262 | (goto-char (point-min)) | |
263 | (search-forward (concat "\n" mail-header-separator "\n")) | |
264 | (narrow-to-region (point-min) (point)) | |
265 | (setq newsgroups (mail-fetch-field "newsgroups") | |
266 | subject (mail-fetch-field "subject"))) | |
267 | (widen) | |
268 | (goto-char (point-min)) | |
269 | (run-hooks 'news-inews-hook) | |
270 | (goto-char (point-min)) | |
271 | (search-forward (concat "\n" mail-header-separator "\n")) | |
272 | (replace-match "\n\n") | |
273 | (goto-char (point-max)) | |
274 | ;; require a newline at the end for inews to append .signature to | |
275 | (or (= (preceding-char) ?\n) | |
276 | (insert ?\n)) | |
277 | (message "Posting to USENET...") | |
278 | (call-process-region (point-min) (point-max) | |
279 | news-inews-program nil 0 nil | |
280 | "-h") ; take all header lines! | |
281 | ;@@ setting of subject and newsgroups still needed? | |
282 | ;"-t" subject | |
283 | ;"-n" newsgroups | |
284 | (message "Posting to USENET... done") | |
285 | (goto-char (point-min)) ;restore internal header separator | |
286 | (search-forward "\n\n") | |
287 | (replace-match (concat "\n" mail-header-separator "\n")) | |
288 | (set-buffer-modified-p nil)) | |
289 | (and (fboundp 'bury-buffer) (bury-buffer)))) | |
290 | ||
291 | ;@@ shares some code with news-reply and news-post-news | |
292 | (defun news-mail-reply () | |
293 | "Mail a reply to the author of the current article. | |
294 | While composing the reply, use \\[news-reply-yank-original] to yank the | |
295 | original message into it." | |
296 | (interactive) | |
297 | (let (from cc subject date to reply-to | |
298 | (buffer (current-buffer))) | |
299 | (save-restriction | |
300 | (narrow-to-region (point-min) (progn (goto-line (point-min)) | |
301 | (search-forward "\n\n") | |
302 | (- (point) 1))) | |
303 | (setq from (mail-fetch-field "from") | |
304 | subject (mail-fetch-field "subject") | |
305 | reply-to (mail-fetch-field "reply-to") | |
56eb270e RS |
306 | date (mail-fetch-field "date"))) |
307 | (setq to from) | |
308 | (pop-to-buffer "*mail*") | |
309 | (mail nil | |
310 | (if reply-to reply-to to) | |
311 | subject | |
312 | (let ((stop-pos (string-match " *at \\| *@ \\| *(\\| *<" from))) | |
313 | (concat (if stop-pos (substring from 0 stop-pos) from) | |
314 | "'s message of " | |
315 | date)) | |
316 | nil | |
317 | buffer))) | |
0d20f9a0 JB |
318 | |
319 | ;@@ the guts of news-reply and news-post-news should be combined. -tower | |
320 | (defun news-reply () | |
321 | "Compose and post a reply (aka a followup) to the current article on USENET. | |
322 | While composing the followup, use \\[news-reply-yank-original] to yank the | |
323 | original message into it." | |
324 | (interactive) | |
325 | (if (y-or-n-p "Are you sure you want to followup to all of USENET? ") | |
326 | (let (from cc subject date to followup-to newsgroups message-of | |
327 | references distribution message-id | |
328 | (buffer (current-buffer))) | |
329 | (save-restriction | |
330 | (and (not (= 0 (buffer-size))) ;@@real problem is non-existence of | |
331 | ;@@ of article file | |
332 | (equal major-mode 'news-mode) ;@@ if rmail-mode, | |
333 | ;@@ should show full headers | |
334 | (progn | |
335 | (news-show-all-headers) ;@@ should save/restore header state, | |
336 | ;@@ but rnews.el lacks support | |
337 | (narrow-to-region (point-min) (progn (goto-char (point-min)) | |
338 | (search-forward "\n\n") | |
339 | (- (point) 1))))) | |
340 | (setq from (mail-fetch-field "from") | |
341 | news-reply-yank-from from | |
342 | ;; @@ not handling old Title: field | |
343 | subject (mail-fetch-field "subject") | |
344 | date (mail-fetch-field "date") | |
345 | followup-to (mail-fetch-field "followup-to") | |
346 | newsgroups (or followup-to | |
347 | (mail-fetch-field "newsgroups")) | |
348 | references (mail-fetch-field "references") | |
349 | ;; @@ not handling old Article-I.D.: field | |
350 | distribution (mail-fetch-field "distribution") | |
351 | message-id (mail-fetch-field "message-id") | |
352 | news-reply-yank-message-id message-id) | |
353 | (pop-to-buffer "*post-news*") | |
354 | (news-reply-mode) | |
355 | (if (and (buffer-modified-p) | |
356 | (not | |
357 | (y-or-n-p "Unsent article being composed; erase it? "))) | |
358 | () | |
359 | (progn | |
360 | (erase-buffer) | |
361 | (and subject | |
362 | (progn (if (string-match "\\`Re: " subject) | |
363 | (while (string-match "\\`Re: " subject) | |
364 | (setq subject (substring subject 4)))) | |
365 | (setq subject (concat "Re: " subject)))) | |
366 | (and from | |
367 | (progn | |
368 | (let ((stop-pos | |
369 | (string-match " *at \\| *@ \\| *(\\| *<" from))) | |
370 | (setq message-of | |
371 | (concat | |
372 | (if stop-pos (substring from 0 stop-pos) from) | |
373 | "'s message of " | |
374 | date))))) | |
375 | (news-setup | |
376 | nil | |
377 | subject | |
378 | message-of | |
379 | newsgroups | |
380 | buffer) | |
381 | (if followup-to | |
382 | (progn (news-reply-followup-to) | |
383 | (insert followup-to))) | |
384 | (if distribution | |
385 | (progn | |
386 | (mail-position-on-field "Distribution") | |
387 | (insert distribution))) | |
388 | (mail-position-on-field "References") | |
389 | (if references | |
390 | (insert references)) | |
391 | (if (and references message-id) | |
392 | (insert " ")) | |
393 | (if message-id | |
394 | (insert message-id)) | |
395 | (goto-char (point-max)))))) | |
396 | (message ""))) | |
397 | ||
398 | ;@@ the guts of news-reply and news-post-news should be combined. -tower | |
d9f86af9 | 399 | ;;;###autoload |
0d20f9a0 JB |
400 | (defun news-post-news () |
401 | "Begin editing a new USENET news article to be posted. | |
402 | Type \\[describe-mode] once editing the article to get a list of commands." | |
403 | (interactive) | |
404 | (if (y-or-n-p "Are you sure you want to post to all of USENET? ") | |
405 | (let ((buffer (current-buffer))) | |
406 | (save-restriction | |
407 | (and (not (= 0 (buffer-size))) ;@@real problem is non-existence of | |
408 | ;@@ of article file | |
409 | (equal major-mode 'news-mode) ;@@ if rmail-mode, | |
410 | ;@@ should show full headers | |
411 | (progn | |
412 | (news-show-all-headers) ;@@ should save/restore header state, | |
413 | ;@@ but rnews.el lacks support | |
414 | (narrow-to-region (point-min) (progn (goto-char (point-min)) | |
415 | (search-forward "\n\n") | |
416 | (- (point) 1))))) | |
417 | (setq news-reply-yank-from (mail-fetch-field "from") | |
418 | ;; @@ not handling old Article-I.D.: field | |
419 | news-reply-yank-message-id (mail-fetch-field "message-id"))) | |
420 | (pop-to-buffer "*post-news*") | |
421 | (news-reply-mode) | |
422 | (if (and (buffer-modified-p) | |
423 | (not (y-or-n-p "Unsent article being composed; erase it? "))) | |
424 | () ;@@ not saving point from last time | |
425 | (progn (erase-buffer) | |
426 | (news-setup () () () () buffer)))) | |
427 | (message ""))) | |
428 | ||
429 | (defun news-mail-other-window () | |
430 | "Send mail in another window. | |
431 | While composing the message, use \\[news-reply-yank-original] to yank the | |
432 | original message into it." | |
433 | (interactive) | |
434 | (mail-other-window nil nil nil nil nil (current-buffer))) | |
c88ab9ce ER |
435 | |
436 | ;;; rnewspost.el ends here |