(gnus-post-news): Call gnus-read-distributions-file.
[bpt/emacs.git] / lisp / gnuspost.el
1 ;;; gnuspost.el --- post news commands for GNUS newsreader
2
3 ;; Copyright (C) 1989, 1990, 1993 Free Software Foundation, Inc.
4
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Version: $Header: /home/fsf/rms/e19/lisp/RCS/gnuspost.el,v 1.16 1993/11/22 06:44:12 rms Exp $
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Code:
26
27 (require 'gnus)
28
29 (defvar gnus-organization-file "/usr/lib/news/organization"
30 "*Local news organization file.")
31
32 (defvar gnus-post-news-buffer "*post-news*")
33 (defvar gnus-winconf-post-news nil)
34
35 (autoload 'news-reply-mode "rnewspost")
36 (autoload 'timezone-make-date-arpa-standard "timezone")
37
38 ;;; Post news commands of GNUS Group Mode and Summary Mode
39
40 (defun gnus-group-post-news ()
41 "Post an article."
42 (interactive)
43 ;; Save window configuration.
44 (setq gnus-winconf-post-news (current-window-configuration))
45 (unwind-protect
46 (gnus-post-news)
47 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer))
48 (not (zerop (buffer-size))))
49 ;; Restore last window configuration.
50 (set-window-configuration gnus-winconf-post-news)))
51 ;; We don't want to return to Summary buffer nor Article buffer later.
52 (if (get-buffer gnus-summary-buffer)
53 (bury-buffer gnus-summary-buffer))
54 (if (get-buffer gnus-article-buffer)
55 (bury-buffer gnus-article-buffer)))
56
57 (defun gnus-summary-post-news ()
58 "Post an article."
59 (interactive)
60 (gnus-summary-select-article t nil)
61 ;; Save window configuration.
62 (setq gnus-winconf-post-news (current-window-configuration))
63 (unwind-protect
64 (progn
65 (switch-to-buffer gnus-article-buffer)
66 (widen)
67 (delete-other-windows)
68 (gnus-post-news))
69 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer))
70 (not (zerop (buffer-size))))
71 ;; Restore last window configuration.
72 (set-window-configuration gnus-winconf-post-news)))
73 ;; We don't want to return to Article buffer later.
74 (bury-buffer gnus-article-buffer))
75
76 (defun gnus-summary-followup (yank)
77 "Post a reply article.
78 If prefix argument YANK is non-nil, original article is yanked automatically."
79 (interactive "P")
80 (gnus-summary-select-article t nil)
81 ;; Check Followup-To: poster.
82 (set-buffer gnus-article-buffer)
83 (if (and gnus-use-followup-to
84 (string-equal "poster" (gnus-fetch-field "followup-to"))
85 (or (not (eq gnus-use-followup-to t))
86 (not (y-or-n-p "Do you want to ignore `Followup-To: poster'? "))))
87 ;; Mail to the poster. GNUS is now RFC1036 compliant.
88 (gnus-summary-reply yank)
89 ;; Save window configuration.
90 (setq gnus-winconf-post-news (current-window-configuration))
91 (unwind-protect
92 (progn
93 (switch-to-buffer gnus-article-buffer)
94 (widen)
95 (delete-other-windows)
96 (gnus-news-reply yank))
97 (or (and (eq (current-buffer) (get-buffer gnus-post-news-buffer))
98 (not (zerop (buffer-size))))
99 ;; Restore last window configuration.
100 (set-window-configuration gnus-winconf-post-news)))
101 ;; We don't want to return to Article buffer later.
102 (bury-buffer gnus-article-buffer)))
103
104 (defun gnus-summary-followup-with-original ()
105 "Post a reply article with original article."
106 (interactive)
107 (gnus-summary-followup t))
108
109 (defun gnus-summary-cancel-article ()
110 "Cancel an article you posted."
111 (interactive)
112 (gnus-summary-select-article t nil)
113 (gnus-eval-in-buffer-window gnus-article-buffer
114 (gnus-cancel-news)))
115
116 \f
117 ;;; Post a News using NNTP
118
119 ;;;###autoload
120 (fset 'sendnews 'gnus-post-news)
121
122 ;;;###autoload
123 (fset 'postnews 'gnus-post-news)
124
125 ;;;###autoload
126 (defun gnus-post-news ()
127 "Begin editing a new USENET news article to be posted.
128 Type \\[describe-mode] once editing the article to get a list of commands."
129 (interactive)
130 (if (or (not gnus-novice-user)
131 (y-or-n-p "Are you sure you want to post to all of USENET? "))
132 (let ((artbuf (current-buffer))
133 (newsgroups ;Default newsgroup.
134 (if (eq major-mode 'gnus-article-mode) gnus-newsgroup-name))
135 (subject nil)
136 ;; Get default distribution.
137 (distribution (car gnus-local-distributions)))
138 ;; Connect to NNTP server if not connected yet, and get
139 ;; several information.
140 (if (not (gnus-server-opened))
141 (progn
142 (gnus-start-news-server t) ;Confirm server.
143 (gnus-setup-news)))
144 ;; Get current article information.
145 (save-restriction
146 (and (not (zerop (buffer-size)))
147 ;;(equal major-mode 'news-mode)
148 (equal major-mode 'gnus-article-mode)
149 (progn
150 ;;(news-show-all-headers)
151 (gnus-article-show-all-headers)
152 (narrow-to-region (point-min)
153 (progn (goto-char (point-min))
154 (search-forward "\n\n")
155 (point)))))
156 (setq news-reply-yank-from (mail-fetch-field "from"))
157 (setq news-reply-yank-message-id (mail-fetch-field "message-id")))
158 (pop-to-buffer gnus-post-news-buffer)
159 (news-reply-mode)
160 (gnus-overload-functions)
161 (if (and (buffer-modified-p)
162 (> (buffer-size) 0)
163 (not (y-or-n-p "Unsent article being composed; erase it? ")))
164 ;; Continue composition.
165 ;; Make news-reply-yank-original work on the current article.
166 (setq mail-reply-buffer artbuf)
167 (erase-buffer)
168 (if gnus-interactive-post
169 ;; Newsgroups, subject and distribution are asked for.
170 ;; Suggested by yuki@flab.fujitsu.junet.
171 (progn
172 ;; Subscribed newsgroup names are required for
173 ;; completing read of newsgroup.
174 (or gnus-newsrc-assoc
175 (gnus-read-newsrc-file))
176 ;; Which do you like? (UMERIN)
177 ;; (setq newsgroups (read-string "Newsgroups: " "general"))
178 (or newsgroups ;Use the default newsgroup.
179 (setq newsgroups
180 (completing-read "Newsgroup: "
181 gnus-newsrc-assoc
182 nil 'require-match
183 newsgroups ;Default newsgroup.
184 )))
185 (setq subject (read-string "Subject: "))
186 ;; Choose a distribution from gnus-distribution-list.
187 ;; completing-read should not be used with
188 ;; 'require-match functionality in order to allow use
189 ;; of unknow distribution.
190 (gnus-read-distributions-file)
191 (setq distribution
192 (if (consp gnus-distribution-list)
193 (completing-read "Distribution: "
194 gnus-distribution-list
195 nil nil ;Never 'require-match
196 distribution ;Default distribution.
197 )
198 (read-string "Distribution: ")))
199 ;; Empty string is okay.
200 ;;(if (string-equal distribution "")
201 ;; (setq distribution nil))
202 ))
203 (news-setup () subject () newsgroups artbuf)
204 ;; Make sure the article is posted by GNUS.
205 ;;(mail-position-on-field "Posting-Software")
206 ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs")
207 ;; Insert Distribution: field.
208 ;; Suggested by ichikawa@flab.fujitsu.junet.
209 (mail-position-on-field "Distribution")
210 (insert (or distribution ""))
211 ;; Handle author copy using FCC field.
212 (if gnus-author-copy
213 (progn
214 (mail-position-on-field "FCC")
215 (insert gnus-author-copy)))
216 (if gnus-interactive-post
217 ;; All fields are filled in.
218 (goto-char (point-max))
219 ;; Move point to Newsgroup: field.
220 (goto-char (point-min))
221 (end-of-line))
222 ))
223 (message "")))
224
225 (defun gnus-news-reply (&optional yank)
226 "Compose and post a reply (aka a followup) to the current article on USENET.
227 While composing the followup, use \\[news-reply-yank-original] to yank the
228 original message into it."
229 (interactive)
230 (if (or (not gnus-novice-user)
231 (y-or-n-p "Are you sure you want to followup to all of USENET? "))
232 (let (from cc subject date to followup-to newsgroups message-of
233 references distribution message-id
234 (artbuf (current-buffer)))
235 (save-restriction
236 (and (not (zerop (buffer-size)))
237 ;;(equal major-mode 'news-mode)
238 (equal major-mode 'gnus-article-mode)
239 (progn
240 ;; (news-show-all-headers)
241 (gnus-article-show-all-headers)
242 (narrow-to-region (point-min)
243 (progn (goto-char (point-min))
244 (search-forward "\n\n")
245 (point)))))
246 (setq from (mail-fetch-field "from"))
247 (setq news-reply-yank-from from)
248 (setq subject (mail-fetch-field "subject"))
249 (setq date (mail-fetch-field "date"))
250 (setq followup-to (mail-fetch-field "followup-to"))
251 ;; Ignore Followup-To: poster.
252 (if (or (null gnus-use-followup-to) ;Ignore followup-to: field.
253 (string-equal "" followup-to) ;Bogus header.
254 (string-equal "poster" followup-to))
255 (setq followup-to nil))
256 (setq newsgroups (or followup-to (mail-fetch-field "newsgroups")))
257 (setq references (mail-fetch-field "references"))
258 (setq distribution (mail-fetch-field "distribution"))
259 (setq message-id (mail-fetch-field "message-id"))
260 (setq news-reply-yank-message-id message-id))
261 (pop-to-buffer gnus-post-news-buffer)
262 (news-reply-mode)
263 (gnus-overload-functions)
264 (if (and (buffer-modified-p)
265 (> (buffer-size) 0)
266 (not (y-or-n-p "Unsent article being composed; erase it? ")))
267 ;; Continue composition.
268 ;; Make news-reply-yank-original work on current article.
269 (setq mail-reply-buffer artbuf)
270 (erase-buffer)
271 (and subject
272 (setq subject
273 (concat "Re: " (gnus-simplify-subject subject 're-only))))
274 (and from
275 (progn
276 (let ((stop-pos
277 (string-match " *at \\| *@ \\| *(\\| *<" from)))
278 (setq message-of
279 (concat
280 (if stop-pos (substring from 0 stop-pos) from)
281 "'s message of "
282 date)))))
283 (news-setup nil subject message-of newsgroups artbuf)
284 (if followup-to
285 (progn (news-reply-followup-to)
286 (insert followup-to)))
287 ;; Fold long references line to follow RFC1036.
288 (mail-position-on-field "References")
289 (let ((begin (point))
290 (fill-column 79)
291 (fill-prefix "\t"))
292 (if references
293 (insert references))
294 (if (and references message-id)
295 (insert " "))
296 (if message-id
297 (insert message-id))
298 ;; The region must end with a newline to fill the region
299 ;; without inserting extra newline.
300 (fill-region-as-paragraph begin (1+ (point))))
301 ;; Make sure the article is posted by GNUS.
302 ;;(mail-position-on-field "Posting-Software")
303 ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs")
304 ;; Distribution must be the same as original article.
305 (mail-position-on-field "Distribution")
306 (insert (or distribution ""))
307 ;; Handle author copy using FCC field.
308 (if gnus-author-copy
309 (progn
310 (mail-position-on-field "FCC")
311 (insert gnus-author-copy)))
312 ;; Insert To: FROM field, which is expected to mail the
313 ;; message to the author of the article too.
314 (if (and gnus-auto-mail-to-author from)
315 (progn
316 (goto-char (point-min))
317 (insert "To: " from "\n")))
318 (goto-char (point-max)))
319 ;; Yank original article automatically.
320 (if yank
321 (let ((last (point)))
322 ;;(goto-char (point-max))
323 ;; Insert at current point.
324 (news-reply-yank-original nil)
325 (goto-char last)))
326 )
327 (message "")))
328
329 (defun gnus-inews-news ()
330 "Send a news message."
331 (interactive)
332 (let* ((case-fold-search nil)
333 (server-running (gnus-server-opened)))
334 (save-excursion
335 ;; Connect to default NNTP server if necessary.
336 ;; Suggested by yuki@flab.fujitsu.junet.
337 (gnus-start-news-server) ;Use default server.
338 ;; NNTP server must be opened before current buffer is modified.
339 (widen)
340 (goto-char (point-min))
341 (run-hooks 'news-inews-hook)
342 ;; Mail the message too if To: or Cc: exists.
343 (if (save-restriction
344 (narrow-to-region
345 (point-min)
346 (progn
347 (goto-char (point-min))
348 (search-forward (concat "\n" mail-header-separator "\n"))
349 (point)))
350 (or (mail-fetch-field "to" nil t)
351 (mail-fetch-field "cc" nil t)))
352 (if gnus-mail-send-method
353 (progn
354 (message "Sending via mail...")
355 (funcall gnus-mail-send-method)
356 (message "Sending via mail... done"))
357 (ding)
358 (message "No mailer defined. To: and/or Cc: fields ignored.")
359 (sit-for 1)))
360 ;; Send to NNTP server.
361 (message "Posting to USENET...")
362 (if (gnus-inews-article)
363 (message "Posting to USENET... done")
364 ;; We cannot signal an error.
365 (ding) (message "Article rejected: %s" (gnus-status-message)))
366 (set-buffer-modified-p nil))
367 ;; If NNTP server is opened by gnus-inews-news, close it by myself.
368 (or server-running
369 (gnus-close-server))
370 (and (fboundp 'bury-buffer) (bury-buffer))
371 ;; Restore last window configuration.
372 (and gnus-winconf-post-news
373 (set-window-configuration gnus-winconf-post-news))
374 (setq gnus-winconf-post-news nil)
375 ))
376
377 (defun gnus-cancel-news ()
378 "Cancel an article you posted."
379 (interactive)
380 (if (yes-or-no-p "Do you really want to cancel this article? ")
381 (let ((from nil)
382 (newsgroups nil)
383 (message-id nil)
384 (distribution nil))
385 (save-excursion
386 ;; Get header info. from original article.
387 (save-restriction
388 (gnus-article-show-all-headers)
389 (goto-char (point-min))
390 (search-forward "\n\n" nil 'move)
391 (narrow-to-region (point-min) (point))
392 (setq from (mail-fetch-field "from"))
393 (setq newsgroups (mail-fetch-field "newsgroups"))
394 (setq message-id (mail-fetch-field "message-id"))
395 (setq distribution (mail-fetch-field "distribution")))
396 ;; Verify if the article is absolutely user's by comparing
397 ;; user id with value of its From: field.
398 (if (not
399 (string-equal
400 (downcase (mail-strip-quoted-names from))
401 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
402 (progn
403 (ding) (message "This article is not yours."))
404 ;; Make control article.
405 (set-buffer (get-buffer-create " *GNUS-canceling*"))
406 (buffer-flush-undo (current-buffer))
407 (erase-buffer)
408 (insert "Newsgroups: " newsgroups "\n"
409 "Subject: cancel " message-id "\n"
410 "Control: cancel " message-id "\n"
411 ;; We should not use the first value of
412 ;; `gnus-distribution-list' as default value,
413 ;; because distribution must be as same as original
414 ;; article.
415 "Distribution: " (or distribution "") "\n"
416 mail-header-separator "\n"
417 )
418 ;; Send the control article to NNTP server.
419 (message "Canceling your article...")
420 (if (gnus-inews-article)
421 (message "Canceling your article... done")
422 (ding) (message "Failed to cancel your article"))
423 ;; Kill the article buffer.
424 (kill-buffer (current-buffer))
425 )))
426 ))
427
428 \f
429 ;;; Lowlevel inews interface
430
431 (defun gnus-inews-article ()
432 "Post an article in current buffer using NNTP protocol."
433 (let ((artbuf (current-buffer))
434 (tmpbuf (get-buffer-create " *GNUS-posting*")))
435 (save-excursion
436 (set-buffer tmpbuf)
437 (buffer-flush-undo (current-buffer))
438 (erase-buffer)
439 (insert-buffer-substring artbuf)
440 ;; Remove the header separator.
441 (goto-char (point-min))
442 (search-forward (concat "\n" mail-header-separator "\n"))
443 (replace-match "\n\n")
444 (goto-char (point-max))
445 ;; require a newline at the end for inews to append .signature to
446 (or (= (preceding-char) ?\n)
447 (insert ?\n))
448 ;; This hook may insert a signature.
449 (run-hooks 'gnus-prepare-article-hook)
450 ;; Prepare article headers. All message body such as signature
451 ;; must be inserted before Lines: field is prepared.
452 (save-restriction
453 (goto-char (point-min))
454 (search-forward "\n\n")
455 (narrow-to-region (point-min) (point))
456 (gnus-inews-insert-headers))
457 ;; Run final inews hooks. This hook may do FCC.
458 ;; The article must be saved before being posted because
459 ;; `gnus-request-post' modifies the buffer.
460 (run-hooks 'gnus-inews-article-hook)
461 ;; Post an article to NNTP server.
462 ;; Return NIL if post failed.
463 (prog1
464 (gnus-request-post)
465 (kill-buffer (current-buffer)))
466 )))
467
468 (defun gnus-inews-insert-headers ()
469 "Prepare article headers.
470 Fields already prepared in the buffer are not modified.
471 Fields in gnus-required-headers will be generated."
472 (save-excursion
473 (let ((date (gnus-inews-date))
474 (message-id (gnus-inews-message-id))
475 (organization (gnus-inews-organization)))
476 (goto-char (point-min))
477 (or (mail-fetch-field "path")
478 (and (memq 'Path gnus-required-headers)
479 (insert "Path: " (gnus-inews-path) "\n")))
480 (or (mail-fetch-field "from")
481 (and (memq 'From gnus-required-headers)
482 (insert "From: " (gnus-inews-user-name) "\n")))
483 ;; If there is no subject, make Subject: field.
484 (or (mail-fetch-field "subject")
485 (and (memq 'Subject gnus-required-headers)
486 (insert "Subject: \n")))
487 ;; If there is no newsgroups, make Newsgroups: field.
488 (or (mail-fetch-field "newsgroups")
489 (and (memq 'Newsgroups gnus-required-headers)
490 (insert "Newsgroups: \n")))
491 (or (mail-fetch-field "message-id")
492 (and message-id
493 (memq 'Message-ID gnus-required-headers)
494 (insert "Message-ID: " message-id "\n")))
495 (or (mail-fetch-field "date")
496 (and date
497 (memq 'Date gnus-required-headers)
498 (insert "Date: " date "\n")))
499 ;; Optional fields in RFC977 and RFC1036
500 (or (mail-fetch-field "organization")
501 (and organization
502 (memq 'Organization gnus-required-headers)
503 (let ((begin (point))
504 (fill-column 79)
505 (fill-prefix "\t"))
506 (insert "Organization: " organization "\n")
507 (fill-region-as-paragraph begin (point)))))
508 (or (mail-fetch-field "distribution")
509 (and (memq 'Distribution gnus-required-headers)
510 (insert "Distribution: \n")))
511 (or (mail-fetch-field "lines")
512 (and (memq 'Lines gnus-required-headers)
513 (insert "Lines: " (gnus-inews-lines) "\n")))
514 )))
515
516 \f
517 ;; Utility functions.
518
519 (defun gnus-inews-insert-signature ()
520 "Insert signature file in current article buffer.
521 If there is a file named .signature-DISTRIBUTION, it is used instead
522 of usual .signature when the distribution of the article is
523 DISTRIBUTION. Set the variable to nil to prevent appending the
524 signature file automatically.
525 Signature file is specified by the variable gnus-signature-file."
526 (save-excursion
527 (save-restriction
528 ;; Change signature file by distribution.
529 ;; Suggested by hyoko@flab.fujitsu.co.jp.
530 (let ((signature
531 (if gnus-signature-file
532 (expand-file-name gnus-signature-file nil)))
533 (distribution nil))
534 (goto-char (point-min))
535 (search-forward "\n\n")
536 (narrow-to-region (point-min) (point))
537 (setq distribution (mail-fetch-field "distribution"))
538 (widen)
539 (if signature
540 (progn
541 (if (file-exists-p (concat signature "-" distribution))
542 (setq signature (concat signature "-" distribution)))
543 ;; Insert signature.
544 (if (file-exists-p signature)
545 (progn
546 (goto-char (point-max))
547 (insert "--\n")
548 (insert-file-contents signature)))
549 ))))))
550
551 (defun gnus-inews-do-fcc ()
552 "Process FCC: fields in current article buffer.
553 Unless the first character of the field is `|', the article is saved
554 to the specified file using the function specified by the variable
555 gnus-author-copy-saver. The default function rmail-output saves in
556 Unix mailbox format.
557 If the first character is `|', the contents of the article is send to
558 a program specified by the rest of the value."
559 (let ((fcc-list nil)
560 (fcc-file nil)
561 (case-fold-search t)) ;Should ignore case.
562 (save-excursion
563 (save-restriction
564 (goto-char (point-min))
565 (search-forward "\n\n")
566 (narrow-to-region (point-min) (point))
567 (goto-char (point-min))
568 (while (re-search-forward "^FCC:[ \t]*" nil t)
569 (setq fcc-list
570 (cons (buffer-substring
571 (point)
572 (progn
573 (end-of-line)
574 (skip-chars-backward " \t")
575 (point)))
576 fcc-list))
577 (delete-region (match-beginning 0)
578 (progn (forward-line 1) (point))))
579 ;; Process FCC operations.
580 (widen)
581 (while fcc-list
582 (setq fcc-file (car fcc-list))
583 (setq fcc-list (cdr fcc-list))
584 (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
585 (let ((program (substring fcc-file
586 (match-beginning 1) (match-end 1))))
587 ;; Suggested by yuki@flab.fujitsu.junet.
588 ;; Send article to named program.
589 (call-process-region (point-min) (point-max) shell-file-name
590 nil nil nil "-c" program)
591 ))
592 (t
593 ;; Suggested by hyoko@flab.fujitsu.junet.
594 ;; Save article in Unix mail format by default.
595 (if (and gnus-author-copy-saver
596 (not (eq gnus-author-copy-saver 'rmail-output)))
597 (funcall gnus-author-copy-saver fcc-file)
598 (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
599 (gnus-output-to-rmail fcc-file)
600 (rmail-output fcc-file 1 t t)))
601 ))
602 )
603 ))
604 ))
605
606 (defun gnus-inews-path ()
607 "Return uucp path."
608 (let ((login-name (gnus-inews-login-name)))
609 (cond ((null gnus-use-generic-path)
610 (concat gnus-nntp-server "!" login-name))
611 ((stringp gnus-use-generic-path)
612 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
613 (concat gnus-use-generic-path "!" login-name))
614 (t login-name))
615 ))
616
617 (defun gnus-inews-user-name ()
618 "Return user's network address as `NAME@DOMAIN (FULL NAME)'."
619 (let ((login-name (gnus-inews-login-name))
620 (full-name (gnus-inews-full-name)))
621 (concat login-name "@" (gnus-inews-domain-name gnus-use-generic-from)
622 ;; User's full name.
623 (cond ((string-equal full-name "") "")
624 ((string-equal full-name "&") ;Unix hack.
625 (concat " (" login-name ")"))
626 (t
627 (concat " (" full-name ")")))
628 )))
629
630 (defun gnus-inews-login-name ()
631 "Return user login name.
632 Got from the variable gnus-user-login-name, the environment variables
633 USER and LOGNAME, and the function user-login-name."
634 (or gnus-user-login-name
635 (getenv "USER") (getenv "LOGNAME") (user-login-name)))
636
637 (defun gnus-inews-full-name ()
638 "Return user full name.
639 Got from the variable gnus-user-full-name, the environment variable
640 NAME, and the function user-full-name."
641 (or gnus-user-full-name
642 (getenv "NAME") (user-full-name)))
643
644 (defun gnus-inews-domain-name (&optional genericfrom)
645 "Return user's domain name.
646 If optional argument GENERICFROM is a string, use it as the domain
647 name; if it is non-nil, strip of local host name from the domain name.
648 If the function `system-name' returns full internet name and the
649 domain is undefined, the domain name is got from it."
650 ;; Note: compatibility hack. This will be removed in the next version.
651 (and (null gnus-local-domain)
652 (boundp 'gnus-your-domain)
653 (setq gnus-local-domain gnus-your-domain))
654 ;; End of compatibility hack.
655 (let ((domain (or (if (stringp genericfrom) genericfrom)
656 (getenv "DOMAINNAME")
657 gnus-local-domain
658 ;; Function `system-name' may return full internet name.
659 ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
660 (if (string-match "\\." (system-name))
661 (substring (system-name) (match-end 0)))
662 (read-string "Domain name (no host): ")))
663 (host (or (if (string-match "\\." (system-name))
664 (substring (system-name) 0 (match-beginning 0)))
665 (system-name))))
666 (if (string-equal "." (substring domain 0 1))
667 (setq domain (substring domain 1)))
668 (if (null gnus-local-domain)
669 (setq gnus-local-domain domain))
670 ;; Support GENERICFROM as same as standard Bnews system.
671 ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
672 (cond ((null genericfrom)
673 (concat host "." domain))
674 ;;((stringp genericfrom) genericfrom)
675 (t domain))
676 ))
677
678 (defun gnus-inews-message-id ()
679 "Generate unique Message-ID for user."
680 ;; Message-ID should not contain a slash and should be terminated by
681 ;; a number. I don't know the reason why it is so.
682 (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-domain-name) ">"))
683
684 (defun gnus-inews-unique-id ()
685 "Generate unique ID from user name and current time."
686 (let ((date (current-time-string))
687 (name (gnus-inews-login-name)))
688 (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) [0-9][0-9]\\([0-9][0-9]\\)"
689 date)
690 (concat (upcase name) "."
691 (substring date (match-beginning 6) (match-end 6)) ;Year
692 (substring date (match-beginning 1) (match-end 1)) ;Month
693 (substring date (match-beginning 2) (match-end 2)) ;Day
694 (substring date (match-beginning 3) (match-end 3)) ;Hour
695 (substring date (match-beginning 4) (match-end 4)) ;Minute
696 (substring date (match-beginning 5) (match-end 5)) ;Second
697 )
698 (error "Cannot understand current-time-string: %s." date))
699 ))
700
701 (defun gnus-current-time-zone (time)
702 "The local time zone in effect at TIME, or nil if not known."
703 (let ((z (and (fboundp 'current-time-zone) (current-time-zone time))))
704 (if (and z (car z)) z gnus-local-timezone)))
705
706 (defun gnus-inews-date ()
707 "Date string of today.
708 If `current-time-zone' works, or if `gnus-local-timezone' is set correctly,
709 this yields a date that conforms to RFC 822. Otherwise a buggy date will
710 be generated; this might work with some older news servers."
711 (let* ((now (and (fboundp 'current-time) (current-time)))
712 (zone (gnus-current-time-zone now)))
713 (if zone
714 (gnus-inews-valid-date now zone)
715 ;; No timezone info.
716 (gnus-inews-buggy-date now))))
717
718 (defun gnus-inews-valid-date (&optional time zone)
719 "A date string that represents TIME and conforms to the Usenet standard.
720 TIME is optional and defaults to the current time.
721 Some older versions of Emacs always act as if TIME is nil.
722 The optional argument ZONE specifies the local time zone (default GMT)."
723 (timezone-make-date-arpa-standard
724 (if (fboundp 'current-time)
725 (current-time-string time)
726 (current-time-string))
727 zone "GMT"))
728
729 (defun gnus-inews-buggy-date (&optional time)
730 "A buggy date string that represents TIME.
731 TIME is optional and defaults to the current time.
732 Some older versions of Emacs always act as if TIME is nil."
733 (let ((date (if (fboundp 'current-time)
734 (current-time-string time)
735 (current-time-string))))
736 (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9:]+\\) [0-9][0-9]\\([0-9][0-9]\\)"
737 date)
738 (concat (substring date (match-beginning 2) (match-end 2)) ;Day
739 " "
740 (substring date (match-beginning 1) (match-end 1)) ;Month
741 " "
742 (substring date (match-beginning 4) (match-end 4)) ;Year
743 " "
744 (substring date (match-beginning 3) (match-end 3))) ;Time
745 (error "Cannot understand current-time-string: %s." date))
746 ))
747
748 (defun gnus-inews-organization ()
749 "Return user's organization.
750 The ORGANIZATION environment variable is used if defined.
751 If not, the variable gnus-local-organization is used instead.
752 If the value begins with a slash, it is taken as the name of a file
753 containing the organization."
754 ;; The organization must be got in this order since the ORGANIZATION
755 ;; environment variable is intended for user specific while
756 ;; gnus-local-organization is for machine or organization specific.
757
758 ;; Note: compatibility hack. This will be removed in the next version.
759 (and (null gnus-local-organization)
760 (boundp 'gnus-your-organization)
761 (setq gnus-local-organization gnus-your-organization))
762 ;; End of compatibility hack.
763 (let* ((private-file (expand-file-name "~/.organization" nil))
764 (organization (or (getenv "ORGANIZATION")
765 gnus-local-organization
766 private-file)))
767 (and (stringp organization)
768 (> (length organization) 0)
769 (string-equal (substring organization 0 1) "/")
770 ;; Get it from the user and system file.
771 ;; Suggested by roland@wheaties.ai.mit.edu (Roland McGrath).
772 (let ((dist (mail-fetch-field "distribution")))
773 (setq organization
774 (cond ((file-exists-p (concat organization "-" dist))
775 (concat organization "-" dist))
776 ((file-exists-p organization) organization)
777 ((file-exists-p gnus-organization-file)
778 gnus-organization-file)
779 (t organization)))
780 ))
781 (cond ((not (stringp organization)) nil)
782 ((and (string-equal (substring organization 0 1) "/")
783 (file-exists-p organization))
784 ;; If the first character is `/', assume it is the name of
785 ;; a file containing the organization.
786 (save-excursion
787 (let ((tmpbuf (get-buffer-create " *GNUS organization*")))
788 (set-buffer tmpbuf)
789 (erase-buffer)
790 (insert-file-contents organization)
791 (prog1 (buffer-string)
792 (kill-buffer tmpbuf))
793 )))
794 ((string-equal organization private-file) nil) ;No such file
795 (t organization))
796 ))
797
798 (defun gnus-inews-lines ()
799 "Count the number of lines and return numeric string."
800 (save-excursion
801 (save-restriction
802 (widen)
803 (goto-char (point-min))
804 (search-forward "\n\n" nil 'move)
805 (int-to-string (count-lines (point) (point-max))))))
806
807 (provide 'gnuspost)
808
809 ;;; gnuspost.el ends here