1 ;;; gnuspost.el --- post news commands for GNUS newsreader
3 ;; Copyright (C) 1989, 1990, 1993 Free Software Foundation, Inc.
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 $
9 ;; This file is part of GNU Emacs.
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)
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.
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.
29 (defvar gnus-organization-file
"/usr/lib/news/organization"
30 "*Local news organization file.")
32 (defvar gnus-post-news-buffer
"*post-news*")
33 (defvar gnus-winconf-post-news nil
)
35 (autoload 'news-reply-mode
"rnewspost")
36 (autoload 'timezone-make-date-arpa-standard
"timezone")
38 ;;; Post news commands of GNUS Group Mode and Summary Mode
40 (defun gnus-group-post-news ()
43 ;; Save window configuration.
44 (setq gnus-winconf-post-news
(current-window-configuration))
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
)))
57 (defun gnus-summary-post-news ()
60 (gnus-summary-select-article t nil
)
61 ;; Save window configuration.
62 (setq gnus-winconf-post-news
(current-window-configuration))
65 (switch-to-buffer gnus-article-buffer
)
67 (delete-other-windows)
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
))
76 (defun gnus-summary-followup (yank)
77 "Post a reply article.
78 If prefix argument YANK is non-nil, original article is yanked automatically."
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))
93 (switch-to-buffer gnus-article-buffer
)
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
)))
104 (defun gnus-summary-followup-with-original ()
105 "Post a reply article with original article."
107 (gnus-summary-followup t
))
109 (defun gnus-summary-cancel-article ()
110 "Cancel an article you posted."
112 (gnus-summary-select-article t nil
)
113 (gnus-eval-in-buffer-window gnus-article-buffer
117 ;;; Post a News using NNTP
120 (fset 'sendnews
'gnus-post-news
)
123 (fset 'postnews
'gnus-post-news
)
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."
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
))
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))
142 (gnus-start-news-server t
) ;Confirm server.
144 ;; Get current article information.
146 (and (not (zerop (buffer-size)))
147 ;;(equal major-mode 'news-mode)
148 (equal major-mode
'gnus-article-mode
)
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")
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
)
160 (gnus-overload-functions)
161 (if (and (buffer-modified-p)
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
)
168 (if gnus-interactive-post
169 ;; Newsgroups, subject and distribution are asked for.
170 ;; Suggested by yuki@flab.fujitsu.junet.
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.
180 (completing-read "Newsgroup: "
183 newsgroups
;Default newsgroup.
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)
192 (if (consp gnus-distribution-list
)
193 (completing-read "Distribution: "
194 gnus-distribution-list
195 nil nil
;Never 'require-match
196 distribution
;Default distribution.
198 (read-string "Distribution: ")))
199 ;; Empty string is okay.
200 ;;(if (string-equal distribution "")
201 ;; (setq distribution nil))
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.
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))
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."
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)))
236 (and (not (zerop (buffer-size)))
237 ;;(equal major-mode 'news-mode)
238 (equal major-mode
'gnus-article-mode
)
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")
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
)
263 (gnus-overload-functions)
264 (if (and (buffer-modified-p)
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
)
273 (concat "Re: " (gnus-simplify-subject subject
're-only
))))
277 (string-match " *at \\| *@ \\| *(\\| *<" from
)))
280 (if stop-pos
(substring from
0 stop-pos
) from
)
283 (news-setup nil subject message-of newsgroups artbuf
)
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))
294 (if (and references 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.
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
)
316 (goto-char (point-min))
317 (insert "To: " from
"\n")))
318 (goto-char (point-max)))
319 ;; Yank original article automatically.
321 (let ((last (point)))
322 ;;(goto-char (point-max))
323 ;; Insert at current point.
324 (news-reply-yank-original nil
)
329 (defun gnus-inews-news ()
330 "Send a news message."
332 (let* ((case-fold-search nil
)
333 (server-running (gnus-server-opened)))
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.
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
347 (goto-char (point-min))
348 (search-forward (concat "\n" mail-header-separator
"\n"))
350 (or (mail-fetch-field "to" nil t
)
351 (mail-fetch-field "cc" nil t
)))
352 (if gnus-mail-send-method
354 (message "Sending via mail...")
355 (funcall gnus-mail-send-method
)
356 (message "Sending via mail... done"))
358 (message "No mailer defined. To: and/or Cc: fields ignored.")
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.
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
)
377 (defun gnus-cancel-news ()
378 "Cancel an article you posted."
380 (if (yes-or-no-p "Do you really want to cancel this article? ")
386 ;; Get header info. from original article.
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.
400 (downcase (mail-strip-quoted-names from
))
401 (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
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))
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
415 "Distribution: " (or distribution
"") "\n"
416 mail-header-separator
"\n"
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))
429 ;;; Lowlevel inews interface
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*")))
437 (buffer-flush-undo (current-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)
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.
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.
465 (kill-buffer (current-buffer)))
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."
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")
493 (memq 'Message-ID gnus-required-headers
)
494 (insert "Message-ID: " message-id
"\n")))
495 (or (mail-fetch-field "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")
502 (memq 'Organization gnus-required-headers
)
503 (let ((begin (point))
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")))
517 ;; Utility functions.
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."
528 ;; Change signature file by distribution.
529 ;; Suggested by hyoko@flab.fujitsu.co.jp.
531 (if gnus-signature-file
532 (expand-file-name gnus-signature-file 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"))
541 (if (file-exists-p (concat signature
"-" distribution
))
542 (setq signature
(concat signature
"-" distribution
)))
544 (if (file-exists-p signature
)
546 (goto-char (point-max))
548 (insert-file-contents signature
)))
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
557 If the first character is `|', the contents of the article is send to
558 a program specified by the rest of the value."
561 (case-fold-search t
)) ;Should ignore case.
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
)
570 (cons (buffer-substring
574 (skip-chars-backward " \t")
577 (delete-region (match-beginning 0)
578 (progn (forward-line 1) (point))))
579 ;; Process FCC operations.
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
)
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
)))
606 (defun gnus-inews-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
))
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
)
623 (cond ((string-equal full-name
"") "")
624 ((string-equal full-name
"&") ;Unix hack.
625 (concat " (" login-name
")"))
627 (concat " (" full-name
")")))
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)))
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)))
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")
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)))
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)
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) ">"))
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]\\)"
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
698 (error "Cannot understand current-time-string: %s." date
))
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
)))
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
)))
714 (gnus-inews-valid-date now zone
)
716 (gnus-inews-buggy-date now
))))
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))
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]\\)"
738 (concat (substring date
(match-beginning 2) (match-end 2)) ;Day
740 (substring date
(match-beginning 1) (match-end 1)) ;Month
742 (substring date
(match-beginning 4) (match-end 4)) ;Year
744 (substring date
(match-beginning 3) (match-end 3))) ;Time
745 (error "Cannot understand current-time-string: %s." date
))
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.
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
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")))
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
)
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.
787 (let ((tmpbuf (get-buffer-create " *GNUS organization*")))
790 (insert-file-contents organization
)
791 (prog1 (buffer-string)
792 (kill-buffer tmpbuf
))
794 ((string-equal organization private-file
) nil
) ;No such file
798 (defun gnus-inews-lines ()
799 "Count the number of lines and return numeric string."
803 (goto-char (point-min))
804 (search-forward "\n\n" nil
'move
)
805 (int-to-string (count-lines (point) (point-max))))))
809 ;;; gnuspost.el ends here