home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / gnus / gnuspost.el < prev    next >
Encoding:
Text File  |  1992-08-18  |  25.3 KB  |  723 lines

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