+(defun gnus-inews-insert-headers ()
+ "Prepare article headers.
+Fields already prepared in the buffer are not modified.
+Fields in gnus-required-headers will be generated."
+ (save-excursion
+ (let ((date (gnus-inews-date))
+ (message-id (gnus-inews-message-id))
+ (organization (gnus-inews-organization)))
+ (goto-char (point-min))
+ (or (mail-fetch-field "path")
+ (and (memq 'Path gnus-required-headers)
+ (insert "Path: " (gnus-inews-path) "\n")))
+ (or (mail-fetch-field "from")
+ (and (memq 'From gnus-required-headers)
+ (insert "From: " (gnus-inews-user-name) "\n")))
+ ;; If there is no subject, make Subject: field.
+ (or (mail-fetch-field "subject")
+ (and (memq 'Subject gnus-required-headers)
+ (insert "Subject: \n")))
+ ;; If there is no newsgroups, make Newsgroups: field.
+ (or (mail-fetch-field "newsgroups")
+ (and (memq 'Newsgroups gnus-required-headers)
+ (insert "Newsgroups: \n")))
+ (or (mail-fetch-field "message-id")
+ (and message-id
+ (memq 'Message-ID gnus-required-headers)
+ (insert "Message-ID: " message-id "\n")))
+ (or (mail-fetch-field "date")
+ (and date
+ (memq 'Date gnus-required-headers)
+ (insert "Date: " date "\n")))
+ ;; Optional fields in RFC977 and RFC1036
+ (or (mail-fetch-field "organization")
+ (and organization
+ (memq 'Organization gnus-required-headers)
+ (let ((begin (point))
+ (fill-column 79)
+ (fill-prefix "\t"))
+ (insert "Organization: " organization "\n")
+ (fill-region-as-paragraph begin (point)))))
+ (or (mail-fetch-field "distribution")
+ (and (memq 'Distribution gnus-required-headers)
+ (insert "Distribution: \n")))
+ (or (mail-fetch-field "lines")
+ (and (memq 'Lines gnus-required-headers)
+ (insert "Lines: " (gnus-inews-lines) "\n")))
+ )))
+
+\f
+;; Utility functions.
+
+(defun gnus-inews-insert-signature ()
+ "Insert signature file in current article buffer.
+If there is a file named .signature-DISTRIBUTION, it is used instead
+of usual .signature when the distribution of the article is
+DISTRIBUTION. Set the variable to nil to prevent appending the
+signature file automatically.
+Signature file is specified by the variable gnus-signature-file."
+ (save-excursion
+ (save-restriction
+ ;; Change signature file by distribution.
+ ;; Suggested by hyoko@flab.fujitsu.co.jp.
+ (let ((signature
+ (if gnus-signature-file
+ (expand-file-name gnus-signature-file nil)))
+ (distribution nil))
+ (goto-char (point-min))
+ (search-forward "\n\n")
+ (narrow-to-region (point-min) (point))
+ (setq distribution (mail-fetch-field "distribution"))
+ (widen)
+ (if signature
+ (progn
+ (if (file-exists-p (concat signature "-" distribution))
+ (setq signature (concat signature "-" distribution)))
+ ;; Insert signature.
+ (if (file-exists-p signature)
+ (progn
+ (goto-char (point-max))
+ (insert "--\n")
+ (insert-file-contents signature)))
+ ))))))
+