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