Mercurial > emacs
annotate lisp/=gnuspost.el @ 776:a1d724d96f6b
entered into RCS
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Tue, 14 Jul 1992 23:23:55 +0000 |
parents | 22b98190b7ef |
children | 4f28bd14272c |
rev | line source |
---|---|
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; gnuspost.el --- post news commands for GNUS newsreader |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
711
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
3 ;; Copyright (C) 1989, 1990 Free Software Foundation, Inc. |
267 | 4 ;; $Header: gnuspost.el,v 1.2 90/03/23 13:25:16 umerin Locked $ |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
711
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
8 ;; GNU Emacs is free software; you can redistribute it and/or modify |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
9 ;; it under the terms of the GNU General Public License as published by |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
10 ;; the Free Software Foundation; either version 1, or (at your option) |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
11 ;; any later version. |
267 | 12 |
711
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
13 ;; GNU Emacs is distributed in the hope that it will be useful, |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
16 ;; GNU General Public License for more details. |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
17 |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
18 ;; You should have received a copy of the GNU General Public License |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
19 ;; along with GNU Emacs; see the file COPYING. If not, write to |
22b98190b7ef
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
660
diff
changeset
|
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
267 | 21 |
22 (require 'gnus) | |
23 | |
24 (defvar gnus-organization-file "/usr/lib/news/organization" | |
25 "*Local news organization file.") | |
26 | |
27 (defvar gnus-post-news-buffer "*post-news*") | |
28 (defvar gnus-winconf-post-news nil) | |
29 | |
30 (autoload 'news-reply-mode "rnewspost") | |
31 | |
32 ;;; Post news commands of GNUS Group Mode and Subject Mode | |
33 | |
34 (defun gnus-Group-post-news () | |
35 "Post an article." | |
36 (interactive) | |
37 ;; Save window configuration. | |
38 (setq gnus-winconf-post-news (current-window-configuration)) | |
39 (unwind-protect | |
40 (gnus-post-news) | |
41 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer)) | |
42 (not (zerop (buffer-size)))) | |
43 ;; Restore last window configuration. | |
44 (set-window-configuration gnus-winconf-post-news))) | |
45 ;; We don't want to return to Subject buffer nor Article buffer later. | |
46 (if (get-buffer gnus-Subject-buffer) | |
47 (bury-buffer gnus-Subject-buffer)) | |
48 (if (get-buffer gnus-Article-buffer) | |
49 (bury-buffer gnus-Article-buffer))) | |
50 | |
51 (defun gnus-Subject-post-news () | |
52 "Post an article." | |
53 (interactive) | |
54 (gnus-Subject-select-article t nil) | |
55 ;; Save window configuration. | |
56 (setq gnus-winconf-post-news (current-window-configuration)) | |
57 (unwind-protect | |
58 (progn | |
59 (switch-to-buffer gnus-Article-buffer) | |
60 (widen) | |
61 (delete-other-windows) | |
62 (gnus-post-news)) | |
63 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer)) | |
64 (not (zerop (buffer-size)))) | |
65 ;; Restore last window configuration. | |
66 (set-window-configuration gnus-winconf-post-news))) | |
67 ;; We don't want to return to Article buffer later. | |
68 (bury-buffer gnus-Article-buffer)) | |
69 | |
70 (defun gnus-Subject-post-reply (yank) | |
71 "Post a reply article. | |
72 If prefix argument YANK is non-nil, original article is yanked automatically." | |
73 (interactive "P") | |
74 (gnus-Subject-select-article t nil) | |
75 ;; Check Followup-To: poster. | |
76 (set-buffer gnus-Article-buffer) | |
77 (if (and gnus-use-followup-to | |
78 (string-equal "poster" (gnus-fetch-field "followup-to")) | |
79 (or (not (eq gnus-use-followup-to t)) | |
80 (not (y-or-n-p "Do you want to ignore `Followup-To: poster'? ")))) | |
81 ;; Mail to the poster. GNUS is now RFC1036 compliant. | |
82 (gnus-Subject-mail-reply yank) | |
83 ;; Save window configuration. | |
84 (setq gnus-winconf-post-news (current-window-configuration)) | |
85 (unwind-protect | |
86 (progn | |
87 (switch-to-buffer gnus-Article-buffer) | |
88 (widen) | |
89 (delete-other-windows) | |
90 (gnus-news-reply yank)) | |
91 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer)) | |
92 (not (zerop (buffer-size)))) | |
93 ;; Restore last window configuration. | |
94 (set-window-configuration gnus-winconf-post-news))) | |
95 ;; We don't want to return to Article buffer later. | |
96 (bury-buffer gnus-Article-buffer))) | |
97 | |
98 (defun gnus-Subject-post-reply-with-original () | |
99 "Post a reply article with original article." | |
100 (interactive) | |
101 (gnus-Subject-post-reply t)) | |
102 | |
103 (defun gnus-Subject-cancel-article () | |
104 "Cancel an article you posted." | |
105 (interactive) | |
106 (gnus-Subject-select-article t nil) | |
107 (gnus-eval-in-buffer-window gnus-Article-buffer | |
108 (gnus-cancel-news))) | |
109 | |
110 | |
111 ;;; Post a News using NNTP | |
112 | |
113 ;;;###autoload | |
114 (fset 'sendnews 'gnus-post-news) | |
115 ;;;###autoload | |
116 (fset 'postnews 'gnus-post-news) | |
117 ;;;###autoload | |
118 (defun gnus-post-news () | |
119 "Begin editing a new USENET news article to be posted. | |
120 Type \\[describe-mode] once editing the article to get a list of commands." | |
121 (interactive) | |
122 (if (or (not gnus-novice-user) | |
123 (y-or-n-p "Are you sure you want to post to all of USENET? ")) | |
124 (let ((artbuf (current-buffer)) | |
125 (newsgroups ;Default newsgroup. | |
126 (if (eq major-mode 'gnus-Article-mode) gnus-newsgroup-name)) | |
127 (subject nil) | |
128 (distribution nil)) | |
129 (save-restriction | |
130 (and (not (zerop (buffer-size))) | |
131 ;;(equal major-mode 'news-mode) | |
132 (equal major-mode 'gnus-Article-mode) | |
133 (progn | |
134 ;;(news-show-all-headers) | |
135 (gnus-Article-show-all-headers) | |
136 (narrow-to-region (point-min) | |
137 (progn (goto-char (point-min)) | |
138 (search-forward "\n\n") | |
139 (point))))) | |
140 (setq news-reply-yank-from (mail-fetch-field "from")) | |
141 (setq news-reply-yank-message-id (mail-fetch-field "message-id"))) | |
142 (pop-to-buffer gnus-post-news-buffer) | |
143 (news-reply-mode) | |
144 (gnus-overload-functions) | |
145 (if (and (buffer-modified-p) | |
146 (> (buffer-size) 0) | |
147 (not (y-or-n-p "Unsent article being composed; erase it? "))) | |
148 ;; Continue composition. | |
149 ;; Make news-reply-yank-original work on the current article. | |
150 (setq mail-reply-buffer artbuf) | |
151 (erase-buffer) | |
152 (if gnus-interactive-post | |
153 ;; Newsgroups, subject and distribution are asked for. | |
154 ;; Suggested by yuki@flab.fujitsu.junet. | |
155 (progn | |
156 ;; Subscribed newsgroup names are required for | |
157 ;; completing read of newsgroup. | |
158 (or gnus-newsrc-assoc | |
159 (gnus-read-newsrc-file)) | |
160 ;; Which do you like? (UMERIN) | |
161 ;; (setq newsgroups (read-string "Newsgroups: " "general")) | |
162 (or newsgroups ;Use the default newsgroup. | |
163 (setq newsgroups | |
164 (completing-read "Newsgroup: " gnus-newsrc-assoc | |
165 nil 'require-match | |
166 newsgroups ;Default newsgroup. | |
167 ))) | |
168 (setq subject (read-string "Subject: ")) | |
169 (setq distribution | |
170 (substring newsgroups 0 (string-match "\\." newsgroups))) | |
171 (if (string-equal distribution newsgroups) | |
172 ;; Newsgroup may be general or control. In this | |
173 ;; case, use default distribution. | |
174 (setq distribution gnus-default-distribution)) | |
175 (setq distribution | |
176 (read-string "Distribution: " distribution)) | |
177 ;; An empty string is ok to ignore gnus-default-distribution. | |
178 ;;(if (string-equal distribution "") | |
179 ;; (setq distribution nil)) | |
180 )) | |
181 (news-setup () subject () newsgroups artbuf) | |
182 ;; Make sure the article is posted by GNUS. | |
183 ;;(mail-position-on-field "Posting-Software") | |
184 ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs") | |
185 ;; Insert Distribution: field. | |
186 ;; Suggested by ichikawa@flab.fujitsu.junet. | |
187 (mail-position-on-field "Distribution") | |
188 (insert (or distribution gnus-default-distribution "")) | |
189 ;; Handle author copy using FCC field. | |
190 (if gnus-author-copy | |
191 (progn | |
192 (mail-position-on-field "FCC") | |
193 (insert gnus-author-copy))) | |
194 (if gnus-interactive-post | |
195 ;; All fields are filled in. | |
196 (goto-char (point-max)) | |
197 ;; Move point to Newsgroup: field. | |
198 (goto-char (point-min)) | |
199 (end-of-line)) | |
200 )) | |
201 (message ""))) | |
202 | |
203 (defun gnus-news-reply (&optional yank) | |
204 "Compose and post a reply (aka a followup) to the current article on USENET. | |
205 While composing the followup, use \\[news-reply-yank-original] to yank the | |
206 original message into it." | |
207 (interactive) | |
208 (if (or (not gnus-novice-user) | |
209 (y-or-n-p "Are you sure you want to followup to all of USENET? ")) | |
210 (let (from cc subject date to followup-to newsgroups message-of | |
211 references distribution message-id | |
212 (artbuf (current-buffer))) | |
213 (save-restriction | |
214 (and (not (zerop (buffer-size))) | |
215 ;;(equal major-mode 'news-mode) | |
216 (equal major-mode 'gnus-Article-mode) | |
217 (progn | |
218 ;; (news-show-all-headers) | |
219 (gnus-Article-show-all-headers) | |
220 (narrow-to-region (point-min) | |
221 (progn (goto-char (point-min)) | |
222 (search-forward "\n\n") | |
223 (point))))) | |
224 (setq from (mail-fetch-field "from")) | |
225 (setq news-reply-yank-from from) | |
226 (setq subject (mail-fetch-field "subject")) | |
227 (setq date (mail-fetch-field "date")) | |
228 (setq followup-to (mail-fetch-field "followup-to")) | |
229 ;; Ignore Followup-To: poster. | |
230 (if (or (null gnus-use-followup-to) ;Ignore followup-to: field. | |
231 (string-equal "" followup-to) ;Bogus header. | |
232 (string-equal "poster" followup-to)) | |
233 (setq followup-to nil)) | |
234 (setq newsgroups (or followup-to (mail-fetch-field "newsgroups"))) | |
235 (setq references (mail-fetch-field "references")) | |
236 (setq distribution (mail-fetch-field "distribution")) | |
237 (setq message-id (mail-fetch-field "message-id")) | |
238 (setq news-reply-yank-message-id message-id)) | |
239 (pop-to-buffer gnus-post-news-buffer) | |
240 (news-reply-mode) | |
241 (gnus-overload-functions) | |
242 (if (and (buffer-modified-p) | |
243 (> (buffer-size) 0) | |
244 (not (y-or-n-p "Unsent article being composed; erase it? "))) | |
245 ;; Continue composition. | |
246 ;; Make news-reply-yank-original work on current article. | |
247 (setq mail-reply-buffer artbuf) | |
248 (erase-buffer) | |
249 (and subject | |
250 (setq subject | |
251 (concat "Re: " (gnus-simplify-subject subject 're-only)))) | |
252 (and from | |
253 (progn | |
254 (let ((stop-pos | |
255 (string-match " *at \\| *@ \\| *(\\| *<" from))) | |
256 (setq message-of | |
257 (concat | |
258 (if stop-pos (substring from 0 stop-pos) from) | |
259 "'s message of " | |
260 date))))) | |
261 (news-setup nil subject message-of newsgroups artbuf) | |
262 (if followup-to | |
263 (progn (news-reply-followup-to) | |
264 (insert followup-to))) | |
265 ;; Fold long references line to follow RFC1036. | |
266 (mail-position-on-field "References") | |
267 (let ((begin (point)) | |
268 (fill-column 79) | |
269 (fill-prefix "\t")) | |
270 (if references | |
271 (insert references)) | |
272 (if (and references message-id) | |
273 (insert " ")) | |
274 (if message-id | |
275 (insert message-id)) | |
276 ;; The region must end with a newline to fill the region | |
277 ;; without inserting extra newline. | |
278 (fill-region-as-paragraph begin (1+ (point)))) | |
279 ;; Make sure the article is posted by GNUS. | |
280 ;;(mail-position-on-field "Posting-Software") | |
281 ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs") | |
282 ;; Distribution must be the same as original article. | |
283 (mail-position-on-field "Distribution") | |
284 (insert (or distribution "")) | |
285 ;; Handle author copy using FCC field. | |
286 (if gnus-author-copy | |
287 (progn | |
288 (mail-position-on-field "FCC") | |
289 (insert gnus-author-copy))) | |
290 (goto-char (point-max))) | |
291 ;; Yank original article automatically. | |
292 (if yank | |
293 (let ((last (point))) | |
294 (goto-char (point-max)) | |
295 (news-reply-yank-original nil) | |
296 (goto-char last))) | |
297 ) | |
298 (message ""))) | |
299 | |
300 (defun gnus-inews-news () | |
301 "Send a news message." | |
302 (interactive) | |
303 (let* ((case-fold-search nil) | |
304 (server-running (gnus-server-opened))) | |
305 (save-excursion | |
306 ;; It is possible to post a news without reading news using | |
307 ;; `gnus' before. | |
308 ;; Suggested by yuki@flab.fujitsu.junet. | |
309 (gnus-start-news-server) ;Use default server. | |
310 ;; NNTP server must be opened before current buffer is modified. | |
311 (widen) | |
312 (goto-char (point-min)) | |
313 (run-hooks 'news-inews-hook) | |
314 (goto-char (point-min)) | |
315 (search-forward (concat "\n" mail-header-separator "\n")) | |
316 (replace-match "\n\n") | |
317 (goto-char (point-max)) | |
318 ;; require a newline at the end for inews to append .signature to | |
319 (or (= (preceding-char) ?\n) | |
320 (insert ?\n)) | |
321 (message "Posting to USENET...") | |
322 ;; Post to NNTP server. | |
323 (if (gnus-inews-article) | |
324 (message "Posting to USENET... done") | |
325 ;; We cannot signal an error. | |
326 (ding) (message "Article rejected: %s" (gnus-status-message))) | |
327 (goto-char (point-min)) ;restore internal header separator | |
328 (search-forward "\n\n") | |
329 (replace-match (concat "\n" mail-header-separator "\n")) | |
330 (set-buffer-modified-p nil)) | |
331 ;; If NNTP server is opened by gnus-inews-news, close it by myself. | |
332 (or server-running | |
333 (gnus-close-server)) | |
334 (and (fboundp 'bury-buffer) (bury-buffer)) | |
335 ;; Restore last window configuration. | |
336 (and gnus-winconf-post-news | |
337 (set-window-configuration gnus-winconf-post-news)) | |
338 (setq gnus-winconf-post-news nil) | |
339 )) | |
340 | |
341 (defun gnus-cancel-news () | |
342 "Cancel an article you posted." | |
343 (interactive) | |
344 (if (yes-or-no-p "Do you really want to cancel this article? ") | |
345 (let ((from nil) | |
346 (newsgroups nil) | |
347 (message-id nil) | |
348 (distribution nil)) | |
349 (save-excursion | |
350 ;; Get header info. from original article. | |
351 (save-restriction | |
352 (gnus-Article-show-all-headers) | |
353 (goto-char (point-min)) | |
354 (search-forward "\n\n") | |
355 (narrow-to-region (point-min) (point)) | |
356 (setq from (mail-fetch-field "from")) | |
357 (setq newsgroups (mail-fetch-field "newsgroups")) | |
358 (setq message-id (mail-fetch-field "message-id")) | |
359 (setq distribution (mail-fetch-field "distribution"))) | |
360 ;; Verify if the article is absolutely user's by comparing | |
361 ;; user id with value of its From: field. | |
362 (if (not | |
363 (string-equal | |
364 (downcase (mail-strip-quoted-names from)) | |
365 (downcase (mail-strip-quoted-names (gnus-inews-user-name))))) | |
366 (progn | |
367 (ding) (message "This article is not yours")) | |
368 ;; Make control article. | |
369 (set-buffer (get-buffer-create " *GNUS-posting*")) | |
370 (buffer-flush-undo (current-buffer)) | |
371 (erase-buffer) | |
372 (insert "Newsgroups: " newsgroups "\n" | |
373 "Subject: cancel " message-id "\n" | |
374 "Control: cancel " message-id "\n" | |
375 ;; We should not use the value of | |
376 ;; `gnus-default-distribution' as default value, | |
377 ;; because distribution must be as same as original | |
378 ;; article. | |
379 "Distribution: " (or distribution "") "\n" | |
380 ) | |
381 ;; Prepare article headers. | |
382 (gnus-inews-insert-headers) | |
383 (goto-char (point-max)) | |
384 ;; Insert empty line. | |
385 (insert "\n") | |
386 ;; Send the control article to NNTP server. | |
387 (message "Canceling your article...") | |
388 (if (gnus-request-post) | |
389 (message "Canceling your article... done") | |
390 (ding) (message "Failed to cancel your article")) | |
391 (kill-buffer (current-buffer)) | |
392 ))) | |
393 )) | |
394 | |
395 | |
396 ;;; Lowlevel inews interface | |
397 | |
398 (defun gnus-inews-article () | |
399 "NNTP inews interface." | |
400 (let ((signature | |
401 (if gnus-signature-file | |
402 (expand-file-name gnus-signature-file nil))) | |
403 (distribution nil) | |
404 (artbuf (current-buffer)) | |
405 (tmpbuf (get-buffer-create " *GNUS-posting*"))) | |
406 (save-excursion | |
407 (set-buffer tmpbuf) | |
408 (buffer-flush-undo (current-buffer)) | |
409 (erase-buffer) | |
410 (insert-buffer-substring artbuf) | |
411 ;; Get distribution. | |
412 (save-restriction | |
413 (goto-char (point-min)) | |
414 (search-forward "\n\n") | |
415 (narrow-to-region (point-min) (point)) | |
416 (setq distribution (mail-fetch-field "distribution"))) | |
417 (widen) | |
418 (if signature | |
419 (progn | |
420 ;; Change signature file by distribution. | |
421 ;; Suggested by hyoko@flab.fujitsu.junet. | |
422 (if (file-exists-p (concat signature "-" distribution)) | |
423 (setq signature (concat signature "-" distribution))) | |
424 ;; Insert signature. | |
425 (if (file-exists-p signature) | |
426 (progn | |
427 (goto-char (point-max)) | |
428 (insert "--\n") | |
429 (insert-file-contents signature))) | |
430 )) | |
431 ;; Prepare article headers. | |
432 (save-restriction | |
433 (goto-char (point-min)) | |
434 (search-forward "\n\n") | |
435 (narrow-to-region (point-min) (point)) | |
436 (gnus-inews-insert-headers) | |
437 ;; Save author copy of posted article. The article must be | |
438 ;; copied before being posted because `gnus-request-post' | |
439 ;; modifies the buffer. | |
440 (let ((case-fold-search t)) | |
441 ;; Find and handle any FCC fields. | |
442 (goto-char (point-min)) | |
443 (if (re-search-forward "^FCC:" nil t) | |
444 (gnus-inews-do-fcc)))) | |
445 (widen) | |
446 ;; Run final inews hooks. | |
447 (run-hooks 'gnus-Inews-article-hook) | |
448 ;; Post an article to NNTP server. | |
449 ;; Return NIL if post failed. | |
450 (prog1 | |
451 (gnus-request-post) | |
452 (kill-buffer (current-buffer))) | |
453 ))) | |
454 | |
455 (defun gnus-inews-do-fcc () | |
456 "Process FCC: fields." | |
457 (let ((fcc-list nil) | |
458 (fcc-file nil) | |
459 (case-fold-search t)) ;Should ignore case. | |
460 (save-excursion | |
461 (save-restriction | |
462 (goto-char (point-min)) | |
463 (while (re-search-forward "^FCC:[ \t]*" nil t) | |
464 (setq fcc-list (cons (buffer-substring (point) | |
465 (progn | |
466 (end-of-line) | |
467 (skip-chars-backward " \t") | |
468 (point))) | |
469 fcc-list)) | |
470 (delete-region (match-beginning 0) | |
471 (progn (forward-line 1) (point)))) | |
472 ;; Process FCC operations. | |
473 (widen) | |
474 (while fcc-list | |
475 (setq fcc-file (car fcc-list)) | |
476 (setq fcc-list (cdr fcc-list)) | |
477 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file) | |
478 (let ((program (substring fcc-file | |
479 (match-beginning 1) (match-end 1)))) | |
480 ;; Suggested by yuki@flab.fujitsu.junet. | |
481 ;; Send article to named program. | |
482 (call-process-region (point-min) (point-max) shell-file-name | |
483 nil nil nil "-c" program) | |
484 )) | |
485 (t | |
486 ;; Suggested by hyoko@flab.fujitsu.junet. | |
487 ;; Save article in Unix mail format by default. | |
488 (funcall (or gnus-author-copy-saver 'rmail-output) fcc-file) | |
489 )) | |
490 ) | |
491 )) | |
492 )) | |
493 | |
494 (defun gnus-inews-insert-headers () | |
495 "Prepare article headers. | |
496 Path:, From:, Subject: and Distribution: are generated. | |
497 Message-ID:, Date: and Organization: are optional." | |
498 (save-excursion | |
499 (let ((date (gnus-inews-date)) | |
500 (message-id (gnus-inews-message-id)) | |
501 (organization (gnus-inews-organization))) | |
502 ;; Insert from the top of headers. | |
503 (goto-char (point-min)) | |
504 (insert "Path: " (gnus-inews-path) "\n") | |
505 (insert "From: " (gnus-inews-user-name) "\n") | |
506 ;; If there is no subject, make Subject: field. | |
507 (or (mail-fetch-field "subject") | |
508 (insert "Subject: \n")) | |
509 ;; Insert random headers. | |
510 (if message-id | |
511 (insert "Message-ID: " message-id "\n")) | |
512 (if date | |
513 (insert "Date: " date "\n")) | |
514 (if organization | |
515 (let ((begin (point)) | |
516 (fill-column 79) | |
517 (fill-prefix "\t")) | |
518 (insert "Organization: " organization "\n") | |
519 (fill-region-as-paragraph begin (point)))) | |
520 (or (mail-fetch-field "distribution") | |
521 (insert "Distribution: \n")) | |
522 ))) | |
523 | |
524 (defun gnus-inews-path () | |
525 "Return uucp path." | |
526 (let ((login-name (gnus-inews-login-name))) | |
527 (cond ((null gnus-use-generic-path) | |
528 (concat gnus-nntp-server "!" login-name)) | |
529 ((stringp gnus-use-generic-path) | |
530 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com. | |
531 (concat gnus-use-generic-path "!" login-name)) | |
532 (t login-name)) | |
533 )) | |
534 | |
535 (defun gnus-inews-user-name () | |
536 "Return user's network address as `NAME@DOMAIN (FULL NAME)'." | |
537 (let ((login-name (gnus-inews-login-name)) | |
538 (full-name (gnus-inews-full-name))) | |
539 (concat login-name "@" (gnus-inews-domain-name gnus-use-generic-from) | |
540 ;; User's full name. | |
541 (cond ((string-equal full-name "") "") | |
542 ((string-equal full-name "&") ;Unix hack. | |
543 (concat " (" login-name ")")) | |
544 (t | |
545 (concat " (" full-name ")"))) | |
546 ))) | |
547 | |
548 (defun gnus-inews-login-name () | |
549 "Return user login name. | |
550 Got from the variable `gnus-user-login-name', the environment variables | |
551 USER and LOGNAME, and the function `user-login-name'." | |
552 (or gnus-user-login-name | |
553 (getenv "USER") (getenv "LOGNAME") (user-login-name))) | |
554 | |
555 (defun gnus-inews-full-name () | |
556 "Return user full name. | |
557 Got from the variable `gnus-user-full-name', the environment variable | |
558 NAME, and the function `user-full-name'." | |
559 (or gnus-user-full-name | |
560 (getenv "NAME") (user-full-name))) | |
561 | |
562 (defun gnus-inews-domain-name (&optional genericfrom) | |
563 "Return user's domain name. | |
564 If optional argument GENERICFROM is a string, use it as the domain | |
565 name; if it is non-nil, strip of local host name from the domain name. | |
566 If the function `system-name' returns full internet name and the | |
567 domain is undefined, the domain name is got from it." | |
568 (let ((domain (or (if (stringp genericfrom) genericfrom) | |
569 (getenv "DOMAINNAME") | |
570 gnus-your-domain | |
571 ;; Function `system-name' may return full internet name. | |
572 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>. | |
573 (if (string-match "\\." (system-name)) | |
574 (substring (system-name) (match-end 0))) | |
575 (read-string "Domain name (no host): "))) | |
576 (host (or (if (string-match "\\." (system-name)) | |
577 (substring (system-name) 0 (match-beginning 0))) | |
578 (system-name)))) | |
579 (if (string-equal "." (substring domain 0 1)) | |
580 (setq domain (substring domain 1))) | |
581 (if (null gnus-your-domain) | |
582 (setq gnus-your-domain domain)) | |
583 ;; Support GENERICFROM as same as standard Bnews system. | |
584 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com. | |
585 (cond ((null genericfrom) | |
586 (concat host "." domain)) | |
587 ;;((stringp genericfrom) genericfrom) | |
588 (t domain)) | |
589 )) | |
590 | |
591 (defun gnus-inews-message-id () | |
592 "Generate unique Message-ID for user." | |
593 ;; Message-ID should not contain a slash and should be terminated by | |
594 ;; a number. I don't know the reason why it is so. | |
595 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-domain-name) ">")) | |
596 | |
597 (defun gnus-inews-unique-id () | |
598 "Generate unique ID from user name and current time." | |
599 (let ((date (current-time-string)) | |
600 (name (gnus-inews-login-name))) | |
601 (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) [0-9][0-9]\\([0-9][0-9]\\)" | |
602 date) | |
603 (concat (upcase name) "." | |
604 (substring date (match-beginning 6) (match-end 6)) ;Year | |
605 (substring date (match-beginning 1) (match-end 1)) ;Month | |
606 (substring date (match-beginning 2) (match-end 2)) ;Day | |
607 (substring date (match-beginning 3) (match-end 3)) ;Hour | |
608 (substring date (match-beginning 4) (match-end 4)) ;Minute | |
609 (substring date (match-beginning 5) (match-end 5)) ;Second | |
610 ) | |
611 (error "Cannot understand current-time-string: %s." date)) | |
612 )) | |
613 | |
614 (defun gnus-inews-date () | |
615 "Bnews date format string of today. Time zone is ignored." | |
616 ;; Insert buggy date (time zone is ignored), but I don't worry about | |
617 ;; it since inews will rewrite it. | |
618 (let ((date (current-time-string))) | |
619 (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9:]+\\) [0-9][0-9]\\([0-9][0-9]\\)" | |
620 date) | |
621 (concat (substring date (match-beginning 2) (match-end 2)) ;Day | |
622 " " | |
623 (substring date (match-beginning 1) (match-end 1)) ;Month | |
624 " " | |
625 (substring date (match-beginning 4) (match-end 4)) ;Year | |
626 " " | |
627 (substring date (match-beginning 3) (match-end 3))) ;Time | |
628 (error "Cannot understand current-time-string: %s." date)) | |
629 )) | |
630 | |
631 (defun gnus-inews-organization () | |
632 "Return user's organization. | |
633 The ORGANIZATION environment variable is used if defined. | |
634 If not, the variable `gnus-your-organization' is used instead. | |
635 If the value begins with a slash, it is taken as the name of a file | |
636 containing the organization." | |
637 ;; The organization must be got in this order since the ORGANIZATION | |
638 ;; environment variable is intended for user specific while | |
639 ;; gnus-your-organization is for machine or organization specific. | |
640 (let ((organization (or (getenv "ORGANIZATION") | |
641 gnus-your-organization | |
642 (expand-file-name "~/.organization" nil)))) | |
643 (and (stringp organization) | |
644 (string-equal (substring organization 0 1) "/") | |
645 ;; Get it from the user and system file. | |
646 ;; Suggested by roland@wheaties.ai.mit.edu (Roland McGrath). | |
647 (let ((dist (mail-fetch-field "distribution"))) | |
648 (setq organization | |
649 (cond ((file-exists-p (concat organization "-" dist)) | |
650 (concat organization "-" dist)) | |
651 ((file-exists-p organization) organization) | |
652 ((file-exists-p gnus-organization-file) | |
653 gnus-organization-file) | |
654 (t organization))) | |
655 )) | |
656 (cond ((not (stringp organization)) nil) | |
657 ((and (string-equal (substring organization 0 1) "/") | |
658 (file-exists-p organization)) | |
659 ;; If the first character is `/', assume it is the name of | |
660 ;; a file containing the organization. | |
661 (save-excursion | |
662 (let ((tmpbuf (get-buffer-create " *GNUS organization*"))) | |
663 (set-buffer tmpbuf) | |
664 (erase-buffer) | |
665 (insert-file-contents organization) | |
666 (prog1 (buffer-string) | |
667 (kill-buffer tmpbuf)) | |
668 ))) | |
669 (t organization)) | |
670 )) | |
584 | 671 |
672 (provide 'gnuspost) | |
660
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
673 |
08eb386dd0f3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
674 ;;; gnuspost.el ends here |