home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / gnus / gnuspost.el < prev    next >
Encoding:
Text File  |  1995-04-28  |  30.3 KB  |  849 lines

  1. ;;; gnuspost.el --- post news commands for GNUS newsreader
  2.  
  3. ;; Copyright (C) 1989, 1990, 1993, 1994 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 XEmacs.
  10.  
  11. ;; XEmacs is free software; you can redistribute it and/or modify it
  12. ;; 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. ;; XEmacs is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  23. ;; 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.  
  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.         (setq distribution
  191.               (if (consp gnus-distribution-list)
  192.               (completing-read "Distribution: "
  193.                        gnus-distribution-list
  194.                        nil nil ;Never 'require-match
  195.                        distribution ;Default distribution.
  196.                        )
  197.             (read-string "Distribution: ")))
  198.         ;; Empty string is okay.
  199.         ;;(if (string-equal distribution "")
  200.         ;;    (setq distribution nil))
  201.         ))
  202.       ;; XEmacs change: the news-setup-hook should be run after all
  203.       ;; default modifications to the buffer are complete.  So we inhibit
  204.       ;; `news-setup' from running it, and run it ourselves later.
  205.       (let ((news-setup-hook nil))
  206.         (news-setup () subject () newsgroups artbuf))
  207.       ;; Make sure the article is posted by GNUS.
  208.       ;;(mail-position-on-field "Posting-Software")
  209.       ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs")
  210.       ;; Insert Distribution: field.
  211.       ;; Suggested by ichikawa@flab.fujitsu.junet.
  212.       (mail-position-on-field "Distribution")
  213.       (insert (or distribution ""))
  214.       ;; Handle author copy using FCC field.
  215.       (if gnus-author-copy
  216.           (progn
  217.         (mail-position-on-field "FCC")
  218.         (insert gnus-author-copy)))
  219.       (if gnus-interactive-post
  220.           ;; All fields are filled in.
  221.           (goto-char (point-max))
  222.         ;; Move point to Newsgroup: field.
  223.         (goto-char (point-min))
  224.         (end-of-line))
  225.       ;; XEmacs change: see comment above.
  226.       (run-hooks 'news-setup-hook)
  227.       ))
  228.     (message "")))
  229.  
  230. (defun gnus-news-reply (&optional yank)
  231.   "Compose and post a reply (aka a followup) to the current article on USENET.
  232. While composing the followup, use \\[news-reply-yank-original] to yank the
  233. original message into it."
  234.   (interactive)
  235.   (if (or (not gnus-novice-user)
  236.       (y-or-n-p "Are you sure you want to followup to all of USENET? "))
  237.       (let (from subject date followup-to newsgroups message-of
  238.          references distribution message-id
  239.          (artbuf (current-buffer)))
  240.     (save-restriction
  241.       (and (not (zerop (buffer-size)))
  242.            ;;(equal major-mode 'news-mode)
  243.            (equal major-mode 'gnus-article-mode)
  244.            (progn
  245.          ;; (news-show-all-headers)
  246.          (gnus-article-show-all-headers)
  247.          (narrow-to-region (point-min)
  248.                    (progn (goto-char (point-min))
  249.                       (search-forward "\n\n")
  250.                       (point)))))
  251.       (setq from (mail-fetch-field "from"))
  252.       (setq    news-reply-yank-from from)
  253.       (setq    subject (mail-fetch-field "subject"))
  254.       (setq    date (mail-fetch-field "date"))
  255.       (setq followup-to (mail-fetch-field "followup-to"))
  256.       ;; Ignore Followup-To: poster.
  257.       (if (or (null gnus-use-followup-to) ;Ignore followup-to: field.
  258.           (string-equal "" followup-to)    ;Bogus header.
  259.           (string-equal "poster" followup-to))
  260.           (setq followup-to nil))
  261.       (setq    newsgroups (or followup-to (mail-fetch-field "newsgroups")))
  262.       (setq    references (mail-fetch-field "references"))
  263.       (setq    distribution (mail-fetch-field "distribution"))
  264.       (setq    message-id (mail-fetch-field "message-id"))
  265.       (setq    news-reply-yank-message-id message-id))
  266.     (pop-to-buffer gnus-post-news-buffer)
  267.     (news-reply-mode)
  268.     (gnus-overload-functions)
  269.     (if (and (buffer-modified-p)
  270.          (> (buffer-size) 0)
  271.          (not (y-or-n-p "Unsent article being composed; erase it? ")))
  272.         ;; Continue composition.
  273.         ;; Make news-reply-yank-original work on current article.
  274.         (setq mail-reply-buffer artbuf)
  275.       (erase-buffer)
  276.       (and subject
  277.            (setq subject
  278.              (concat "Re: " (gnus-simplify-subject subject 're-only))))
  279.       ;; change by jwz: encourage people to pick meaningful subjects
  280.       (and subject
  281.            (setq subject
  282.              (read-from-minibuffer "Subject: " subject)))
  283.       (and from
  284.            (progn
  285.          (let ((stop-pos
  286.             (string-match "  *at \\|  *@ \\| *(\\| *<" from)))
  287.            (setq message-of
  288.              (concat
  289.               (if stop-pos (substring from 0 stop-pos) from)
  290.               "'s message of "
  291.               date)))))
  292.       ;; XEmacs change: the news-setup-hook should be run after all
  293.       ;; default modifications to the buffer are complete.  So we inhibit
  294.       ;; `news-setup' from running it, and run it ourselves later.
  295.       (let ((news-setup-hook nil))
  296.         (news-setup nil subject message-of newsgroups artbuf))
  297.       (if followup-to
  298.           (progn (news-reply-followup-to)
  299.              (insert followup-to)))
  300.       ;; Fold long references line to follow RFC1036.
  301.       (mail-position-on-field "References")
  302.       (let ((begin (point))
  303.         (fill-column 79)
  304.         (fill-prefix "\t"))
  305.         (if references
  306.         (insert references))
  307.         (if (and references message-id)
  308.         (insert " "))
  309.         (if message-id
  310.         (insert message-id))
  311.         ;; The region must end with a newline to fill the region
  312.         ;; without inserting extra newline.
  313.         (fill-region-as-paragraph begin (1+ (point))))
  314.       ;; Make sure the article is posted by GNUS.
  315.       ;;(mail-position-on-field "Posting-Software")
  316.       ;;(insert "GNUS: NNTP-based News Reader for GNU Emacs")
  317.       ;; Distribution must be the same as original article.
  318.       (mail-position-on-field "Distribution")
  319.       (insert (or distribution ""))
  320.       ;; Handle author copy using FCC field.
  321.       (if gnus-author-copy
  322.           (progn
  323.         (mail-position-on-field "FCC")
  324.         (insert gnus-author-copy)))
  325.       ;; Insert To: FROM field, which is expected to mail the
  326.       ;; message to the author of the article too.
  327.       (if (and gnus-auto-mail-to-author from)
  328.           (progn
  329.         (goto-char (point-min))
  330.         (insert "To: " from "\n")))
  331.       (goto-char (point-max)))
  332.     ;; Yank original article automatically.
  333.     (if yank
  334.         (let ((last (point)))
  335.           ;;(goto-char (point-max))
  336.           ;; Insert at current point.
  337.           (news-reply-yank-original nil)
  338.           (goto-char last)))
  339.     ;; XEmacs change: see comment above.
  340.     (run-hooks 'news-setup-hook)
  341.     )
  342.     (message "")))
  343.  
  344. (defun gnus-clean-newsgroups-field ()
  345.   ;; XEmacs: clean up the Newsgroups: field.  NNTP bogusly says
  346.   ;; it can't contain whitespace.
  347.   (let ((p (point-marker)))
  348.     (goto-char (point-min))
  349.     (or (re-search-forward "^Newsgroups: *" nil t)
  350.     (error "No `Newsgroups' field."))
  351.     (just-one-space)
  352.     (while (/= (following-char) ?\n)
  353.       (skip-chars-forward "^ \t\n,")
  354.       (cond ((looking-at "\\([ \t]*\\)\n[^ \t]")
  355.          (goto-char (match-end 1))
  356.          (delete-region (match-beginning 1) (match-end 1)))
  357.         ((or (looking-at "\\([ \t]*\\),\\([, \t]*\n[ \t]+\\)")
  358.          (looking-at "\\([ \t]*\\),\\([, \t]*\\)"))
  359.          (goto-char (match-end 0))
  360.          (delete-region (match-beginning 2) (match-end 2))
  361.          (delete-region (match-beginning 1) (match-end 1)))
  362.         (t
  363.          (error "illegal characters in `Newsgroups' field"))))
  364.     (goto-char (prog1 (marker-position p) (set-marker p nil)))))
  365.  
  366. (defun gnus-inews-news ()
  367.   "Send a news message."
  368.   (interactive)
  369.   (let* ((case-fold-search nil)
  370.      (server-running (gnus-server-opened)))
  371.     (save-excursion
  372.       ;; Connect to default NNTP server if necessary.
  373.       ;; Suggested by yuki@flab.fujitsu.junet.
  374.       (gnus-start-news-server)        ;Use default server.
  375.       ;; NNTP server must be opened before current buffer is modified.
  376.       (widen)
  377.       (goto-char (point-min))
  378.       (run-hooks 'news-inews-hook)
  379.       (gnus-clean-newsgroups-field) ; XEmacs (do this before the hook?)
  380.       ;; Mail the message too if To: or Cc: exists.
  381.       (if (save-restriction
  382.         (narrow-to-region
  383.          (point-min)
  384.          (progn
  385.            (goto-char (point-min))
  386.            (search-forward (concat "\n" mail-header-separator "\n"))
  387.            (point)))
  388.         (or (mail-fetch-field "to" nil t)
  389.         (mail-fetch-field "cc" nil t)))
  390.       (if gnus-mail-send-method
  391.           (progn
  392.         (message "Sending via mail...")
  393.         (funcall gnus-mail-send-method)
  394.         (message "Sending via mail... done"))
  395.         (ding)
  396.         (message "No mailer defined.  To: and/or Cc: fields ignored.")
  397.         (sit-for 1)))
  398.       ;; Send to NNTP server. 
  399.       (message "Posting to USENET...")
  400.       (if (gnus-inews-article)
  401.       (message "Posting to USENET... done")
  402.     ;; We cannot signal an error.
  403.     (ding) (message "Article rejected: %s" (gnus-status-message)))
  404.       (set-buffer-modified-p nil))
  405.     ;; If NNTP server is opened by gnus-inews-news, close it by myself.
  406.     (or server-running
  407.     (gnus-close-server))
  408.     (and (fboundp 'bury-buffer) (bury-buffer))
  409.     ;; Restore last window configuration.
  410.     (and gnus-winconf-post-news
  411.      (set-window-configuration gnus-winconf-post-news))
  412.     (setq gnus-winconf-post-news nil)
  413.     ))
  414.  
  415. (defun gnus-cancel-news ()
  416.   "Cancel an article you posted."
  417.   (interactive)
  418.   (if (yes-or-no-p "Do you really want to cancel this article? ")
  419.       (let ((from nil)
  420.         (newsgroups nil)
  421.         (message-id nil)
  422.         (distribution nil))
  423.     (save-excursion
  424.       ;; Get header info. from original article.
  425.       (save-restriction
  426.         (gnus-article-show-all-headers)
  427.         (goto-char (point-min))
  428.         (search-forward "\n\n" nil 'move)
  429.         (narrow-to-region (point-min) (point))
  430.         (setq from (mail-fetch-field "from"))
  431.         (setq newsgroups (mail-fetch-field "newsgroups"))
  432.         (setq message-id (mail-fetch-field "message-id"))
  433.         (setq distribution (mail-fetch-field "distribution")))
  434.       ;; Verify if the article is absolutely user's by comparing
  435.       ;; user id with value of its From: field.
  436.       (if (not
  437.            (string-equal
  438.         (downcase (mail-strip-quoted-names from))
  439.         (downcase (mail-strip-quoted-names (gnus-inews-user-name)))))
  440.           (progn
  441.         (ding) (message "This article is not yours."))
  442.         ;; Make control article.
  443.         (set-buffer (get-buffer-create " *GNUS-canceling*"))
  444.         (buffer-flush-undo (current-buffer))
  445.         (erase-buffer)
  446.         (insert "Newsgroups: " newsgroups "\n"
  447.             "Subject: cancel " message-id "\n"
  448.             "Control: cancel " message-id "\n"
  449.             ;; We should not use the first value of
  450.             ;;  `gnus-distribution-list' as default value,
  451.             ;;  because distribution must be as same as original
  452.             ;;  article.
  453.             "Distribution: " (or distribution "") "\n"
  454.             mail-header-separator "\n"
  455.             )
  456.         ;; Send the control article to NNTP server.
  457.         (message "Canceling your article...")
  458.         (if (gnus-inews-article)
  459.         (message "Canceling your article... done")
  460.           (ding) (message "Failed to cancel your article"))
  461.         ;; Kill the article buffer.
  462.         (kill-buffer (current-buffer))
  463.         )))
  464.     ))
  465.  
  466.  
  467. ;;; Lowlevel inews interface
  468.  
  469. (defun gnus-inews-article ()
  470.   "Post an article in current buffer using NNTP protocol."
  471.   (let ((artbuf (current-buffer))
  472.     (tmpbuf (get-buffer-create " *GNUS-posting*")))
  473.     (save-excursion
  474.       (set-buffer tmpbuf)
  475.       (buffer-flush-undo (current-buffer))
  476.       (erase-buffer)
  477.       (insert-buffer-substring artbuf)
  478.       ;; Remove the header separator.
  479.       (goto-char (point-min))
  480.       (search-forward (concat "\n" mail-header-separator "\n"))
  481.       (replace-match "\n\n")
  482.       (goto-char (point-max))
  483.       ;; require a newline at the end for inews to append .signature to
  484.       (or (= (preceding-char) ?\n)
  485.       (insert ?\n))
  486.       ;; This hook may insert a signature.
  487.       (run-hooks 'gnus-prepare-article-hook)
  488.       ;; Prepare article headers.  All message body such as signature
  489.       ;; must be inserted before Lines: field is prepared.
  490.       (save-restriction
  491.     (goto-char (point-min))
  492.     (search-forward "\n\n")
  493.     (narrow-to-region (point-min) (point))
  494.     (gnus-inews-insert-headers))
  495.       ;; Run final inews hooks.  This hook may do FCC.
  496.       ;; The article must be saved before being posted because
  497.       ;; `gnus-request-post' modifies the buffer.
  498.       (run-hooks 'gnus-inews-article-hook)
  499.       ;; Post an article to NNTP server.
  500.       ;; Return NIL if post failed.
  501.       (prog1
  502.       (gnus-request-post)
  503.     (kill-buffer (current-buffer)))
  504.       )))
  505.  
  506. (defun gnus-inews-insert-headers ()
  507.   "Prepare article headers.
  508. Fields already prepared in the buffer are not modified.
  509. Fields in gnus-required-headers will be generated."
  510.   (save-excursion
  511.     (let ((date (gnus-inews-date))
  512.       (message-id (gnus-inews-message-id))
  513.       (organization (gnus-inews-organization)))
  514.       (goto-char (point-min))
  515.       (or (mail-fetch-field "path")
  516.       (and (memq 'Path gnus-required-headers)
  517.            (insert "Path: " (gnus-inews-path) "\n")))
  518.       (or (mail-fetch-field "from")
  519.       (and (memq 'From gnus-required-headers)
  520.            (insert "From: " (gnus-inews-user-name) "\n")))
  521.       ;; If there is no subject, make Subject: field.
  522.       (or (mail-fetch-field "subject")
  523.       (and (memq 'Subject gnus-required-headers)
  524.            (insert "Subject: \n")))
  525.       ;; If there is no newsgroups, make Newsgroups: field.
  526.       (or (mail-fetch-field "newsgroups")
  527.       (and (memq 'Newsgroups gnus-required-headers)
  528.            (insert "Newsgroups: \n")))
  529.       (or (mail-fetch-field "message-id")
  530.       (and message-id
  531.            (memq 'Message-ID gnus-required-headers)
  532.            (insert "Message-ID: " message-id "\n")))
  533.       (or (mail-fetch-field "date")
  534.       (and date
  535.            (memq 'Date gnus-required-headers)
  536.            (insert "Date: " date "\n")))
  537.       ;; Optional fields in RFC977 and RFC1036
  538.       (or (mail-fetch-field "organization")
  539.       (and organization
  540.            (memq 'Organization gnus-required-headers)
  541.            (let ((begin (point))
  542.              (fill-column 79)
  543.              (fill-prefix "\t"))
  544.          (insert "Organization: " organization "\n")
  545.          (fill-region-as-paragraph begin (point)))))
  546.       (or (mail-fetch-field "distribution")
  547.       (and (memq 'Distribution gnus-required-headers)
  548.            (insert "Distribution: \n")))
  549.       (or (mail-fetch-field "lines")
  550.       (and (memq 'Lines gnus-required-headers)
  551.            (insert "Lines: " (gnus-inews-lines) "\n")))
  552.       )))
  553.  
  554.  
  555. ;; Utility functions.
  556.  
  557. (defun gnus-inews-insert-signature ()
  558.   "Insert signature file in current article buffer.
  559. The signature file is specified by the variable `gnus-signature-file'.
  560. If there is a file named .signature-DISTRIBUTION, it is used instead
  561. of usual .signature when the distribution of the article is
  562. DISTRIBUTION.  Set the variable to nil to prevent appending the
  563. signature file automatically." 
  564.   (save-excursion
  565.     (save-restriction
  566.       ;; Change signature file by distribution.
  567.       ;; Suggested by hyoko@flab.fujitsu.co.jp.
  568.       (let ((signature
  569.          (if gnus-signature-file
  570.          (expand-file-name gnus-signature-file nil)))
  571.         (distribution nil))
  572.     (goto-char (point-min))
  573.     (search-forward "\n\n")
  574.     (narrow-to-region (point-min) (point))
  575.     (setq distribution (mail-fetch-field "distribution"))
  576.     (widen)
  577.     (if signature
  578.         (progn
  579.           (if (file-exists-p (concat signature "-" distribution))
  580.           (setq signature (concat signature "-" distribution)))
  581.           ;; Insert signature.
  582.           (if (file-exists-p signature)
  583.           (progn
  584.             (goto-char (point-max))
  585.             ;; change by jwz: the standard delimiter is "-- \n"
  586.             (insert "-- \n")
  587.             (insert-file-contents signature)))
  588.           ))))))
  589.  
  590. (defun gnus-inews-do-fcc ()
  591.   "Process FCC: fields in current article buffer.
  592. Unless the first character of the field is `|', the article is saved
  593. to the specified file using the function specified by the variable
  594. gnus-author-copy-saver.  The default function rmail-output saves in
  595. Unix mailbox format.
  596. If the first character is `|', the contents of the article is send to
  597. a program specified by the rest of the value."
  598.   (let ((fcc-list nil)
  599.     (fcc-file nil)
  600.     (case-fold-search t))        ;Should ignore case.
  601.     (save-excursion
  602.       (save-restriction
  603.     (goto-char (point-min))
  604.     (search-forward "\n\n")
  605.     (narrow-to-region (point-min) (point))
  606.     (goto-char (point-min))
  607.     (while (re-search-forward "^FCC:[ \t]*" nil t)
  608.       (setq fcc-list
  609.         (cons (buffer-substring
  610.                (point)
  611.                (progn
  612.              (end-of-line)
  613.              (skip-chars-backward " \t")
  614.              (point)))
  615.               fcc-list))
  616.       (delete-region (match-beginning 0)
  617.              (progn (forward-line 1) (point))))
  618.     ;; Process FCC operations.
  619.     (widen)
  620.     (while fcc-list
  621.       (setq fcc-file (car fcc-list))
  622.       (setq fcc-list (cdr fcc-list))
  623.       (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file)
  624.          (let ((program (substring fcc-file
  625.                        (match-beginning 1) (match-end 1))))
  626.            ;; Suggested by yuki@flab.fujitsu.junet.
  627.            ;; Send article to named program.
  628.            (call-process-region (point-min) (point-max) shell-file-name
  629.                     nil nil nil "-c" program)
  630.            ))
  631.         (t
  632.          ;; Suggested by hyoko@flab.fujitsu.junet.
  633.          ;; Save article in Unix mail format by default.
  634.          (if (and gnus-author-copy-saver
  635.               (not (eq gnus-author-copy-saver 'rmail-output)))
  636.              (funcall gnus-author-copy-saver fcc-file)
  637.            (if (and (file-readable-p fcc-file) (rmail-file-p fcc-file))
  638.                (gnus-output-to-rmail fcc-file)
  639.              (rmail-output fcc-file 1 t t)))
  640.          ))
  641.       )
  642.     ))
  643.     ))
  644.  
  645. (defun gnus-inews-path ()
  646.   "Return uucp path."
  647.   (let ((login-name (gnus-inews-login-name)))
  648.     (cond ((null gnus-use-generic-path)
  649.        (concat gnus-nntp-server "!" login-name))
  650.       ((stringp gnus-use-generic-path)
  651.        ;; Support GENERICPATH.  Suggested by vixie@decwrl.dec.com.
  652.        (concat gnus-use-generic-path "!" login-name))
  653.       (t login-name))
  654.     ))
  655.  
  656. (defun gnus-inews-user-name ()
  657.   "Return user's network address as `NAME@DOMAIN (FULL NAME)'."
  658.   (let ((login-name (gnus-inews-login-name))
  659.     (full-name (gnus-inews-full-name)))
  660.     (concat login-name "@" (gnus-inews-domain-name gnus-use-generic-from)
  661.         ;; User's full name.
  662.         (cond ((string-equal full-name "") "")
  663.           ((string-equal full-name "&")    ;Unix hack.
  664.            (concat " (" login-name ")"))
  665.           (t
  666.            (concat " (" full-name ")")))
  667.         )))
  668.  
  669. (defun gnus-inews-login-name ()
  670.   "Return user login name.
  671. Got from the variable gnus-user-login-name, the environment variables
  672. USER and LOGNAME, and the function user-login-name."
  673.   (or gnus-user-login-name
  674.       (getenv "USER") (getenv "LOGNAME") (user-login-name)))
  675.  
  676. (defun gnus-inews-full-name ()
  677.   "Return user full name.
  678. Got from the variable gnus-user-full-name, the environment variable
  679. NAME, and the function user-full-name."
  680.   (or gnus-user-full-name
  681.       (getenv "NAME") (user-full-name)))
  682.  
  683. (defun gnus-inews-domain-name (&optional genericfrom)
  684.   "Return user's domain name.
  685. If optional argument GENERICFROM is a string, use it as the domain
  686. name; if it is non-nil, strip of local host name from the domain name.
  687. If the function `system-name' returns full internet name and the
  688. domain is undefined, the domain name is got from it."
  689.   ;; Note: compatibility hack.  This will be removed in the next version.
  690.   (and (null gnus-local-domain)
  691.        (boundp 'gnus-your-domain)
  692.        (setq gnus-local-domain gnus-your-domain))
  693.   ;; End of compatibility hack.
  694.   (let ((domain (or (if (stringp genericfrom) genericfrom)
  695.             (getenv "DOMAINNAME")
  696.             gnus-local-domain
  697.             ;; Function `system-name' may return full internet name.
  698.             ;; Suggested by Mike DeCorte <mrd@sun.soe.clarkson.edu>.
  699.             (if (string-match "\\." (system-name))
  700.             (substring (system-name) (match-end 0)))
  701.             (read-string "Domain name (no host): ")))
  702.     (host (or (if (string-match "\\." (system-name))
  703.               (substring (system-name) 0 (match-beginning 0)))
  704.           (system-name))))
  705.     (if (string-equal "." (substring domain 0 1))
  706.     (setq domain (substring domain 1)))
  707.     (if (null gnus-local-domain)
  708.     (setq gnus-local-domain domain))
  709.     ;; Support GENERICFROM as same as standard Bnews system.
  710.     ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com.
  711.     (cond ((null genericfrom)
  712.        (concat host "." domain))
  713.       ;;((stringp genericfrom) genericfrom)
  714.       (t domain))
  715.     ))
  716.  
  717. (defun gnus-inews-message-id ()
  718.   "Generate unique Message-ID for user."
  719.   ;; Message-ID should not contain a slash and should be terminated by
  720.   ;; a number.  I don't know the reason why it is so.
  721.   (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-domain-name) ">"))
  722.  
  723. (defun gnus-inews-unique-id ()
  724.   "Generate unique ID from user name and current time."
  725.   (let ((date (current-time-string))
  726.     (name (gnus-inews-login-name)))
  727.     (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) [0-9][0-9]\\([0-9][0-9]\\)"
  728.               date)
  729.     (concat (upcase name) "."
  730.         (substring date (match-beginning 6) (match-end 6)) ;Year
  731.         (substring date (match-beginning 1) (match-end 1)) ;Month
  732.         (substring date (match-beginning 2) (match-end 2)) ;Day
  733.         (substring date (match-beginning 3) (match-end 3)) ;Hour
  734.         (substring date (match-beginning 4) (match-end 4)) ;Minute
  735.         (substring date (match-beginning 5) (match-end 5)) ;Second
  736.         )
  737.       (error "Cannot understand current-time-string: %s." date))
  738.     ))
  739.  
  740. (defun gnus-current-time-zone (time)
  741.   "The local time zone in effect at TIME, or nil if not known."
  742.   (let ((z (and (fboundp 'current-time-zone) (current-time-zone time))))
  743.     (if (and z (car z)) z gnus-local-timezone)))
  744.  
  745. (defun gnus-inews-date ()
  746.   "Date string of today.
  747. If `current-time-zone' works, or if `gnus-local-timezone' is set correctly,
  748. this yields a date that conforms to RFC 822.  Otherwise a buggy date will
  749. be generated; this might work with some older news servers."
  750.   (let* ((now (and (fboundp 'current-time) (current-time)))
  751.      (zone (gnus-current-time-zone now)))
  752.     (if zone
  753.     (gnus-inews-valid-date now zone)
  754.       ;; No timezone info.
  755.       (gnus-inews-buggy-date now))))
  756.  
  757. (defun gnus-inews-valid-date (&optional time zone)
  758.   "A date string that represents TIME and conforms to the Usenet standard.
  759. TIME is optional and defaults to the current time.
  760. Some older versions of Emacs always act as if TIME is nil.
  761. The optional argument ZONE specifies the local time zone (default GMT)."
  762.   (timezone-make-date-arpa-standard
  763.    (if (fboundp 'current-time)
  764.        (current-time-string time)
  765.      (current-time-string))
  766.    zone "GMT"))
  767.  
  768. (defun gnus-inews-buggy-date (&optional time)
  769.   "A buggy date string that represents TIME.
  770. TIME is optional and defaults to the current time.
  771. Some older versions of Emacs always act as if TIME is nil."
  772.   (let ((date (if (fboundp 'current-time)
  773.           (current-time-string time)
  774.         (current-time-string))))
  775.     (if (string-match "^[^ ]+ \\([^ ]+\\)[ ]+\\([0-9]+\\) \\([0-9:]+\\) [0-9][0-9]\\([0-9][0-9]\\)"
  776.               date)
  777.     (concat (substring date (match-beginning 2) (match-end 2)) ;Day
  778.         " "
  779.         (substring date (match-beginning 1) (match-end 1)) ;Month
  780.         " "
  781.         (substring date (match-beginning 4) (match-end 4)) ;Year
  782.         " "
  783.         (substring date (match-beginning 3) (match-end 3))) ;Time
  784.       (error "Cannot understand current-time-string: %s." date))
  785.     ))
  786.  
  787. (defun gnus-inews-organization ()
  788.   "Return user's organization.
  789. The ORGANIZATION environment variable is used if defined.
  790. If not, the variable gnus-local-organization is used instead.
  791. If the value begins with a slash, it is taken as the name of a file
  792. containing the organization."
  793.   ;; The organization must be got in this order since the ORGANIZATION
  794.   ;; environment variable is intended for user specific while
  795.   ;; gnus-local-organization is for machine or organization specific.
  796.  
  797.   ;; Note: compatibility hack.  This will be removed in the next version.
  798.   (and (null gnus-local-organization)
  799.        (boundp 'gnus-your-organization)
  800.        (setq gnus-local-organization gnus-your-organization))
  801.   ;; End of compatibility hack.
  802.   (let* ((private-file (expand-file-name "~/.organization" nil))
  803.      (organization (or (getenv "ORGANIZATION")
  804.                gnus-local-organization
  805.                private-file)))
  806.     (and (stringp organization)
  807.      (> (length organization) 0)
  808.      (string-equal (substring organization 0 1) "/")
  809.      ;; Get it from the user and system file.
  810.      ;; Suggested by roland@wheaties.ai.mit.edu (Roland McGrath).
  811.      (let ((dist (mail-fetch-field "distribution")))
  812.        (setq organization
  813.          (cond ((file-exists-p (concat organization "-" dist))
  814.             (concat organization "-" dist))
  815.                ((file-exists-p organization) organization)
  816.                ((file-exists-p gnus-organization-file)
  817.             gnus-organization-file)
  818.                (t organization)))
  819.        ))
  820.     (cond ((not (stringp organization)) nil)
  821.       ((and (string-equal (substring organization 0 1) "/")
  822.         (file-exists-p organization))
  823.        ;; If the first character is `/', assume it is the name of
  824.        ;; a file containing the organization.
  825.        (save-excursion
  826.          (let ((tmpbuf (get-buffer-create " *GNUS organization*")))
  827.            (set-buffer tmpbuf)
  828.            (erase-buffer)
  829.            (insert-file-contents organization)
  830.            (prog1 (buffer-string)
  831.          (kill-buffer tmpbuf))
  832.            )))
  833.       ((string-equal organization private-file) nil) ;No such file
  834.       (t organization))
  835.     ))
  836.  
  837. (defun gnus-inews-lines ()
  838.   "Count the number of lines and return numeric string."
  839.   (save-excursion
  840.     (save-restriction
  841.       (widen)
  842.       (goto-char (point-min))
  843.       (search-forward "\n\n" nil 'move)
  844.       (int-to-string (count-lines (point) (point-max))))))
  845.  
  846. (provide 'gnuspost)
  847.  
  848. ;;; gnuspost.el ends here
  849.