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