Function: gnus-output-to-file
gnus-output-to-file is a byte-compiled function defined in
gnus-art.el.gz.
Signature
(gnus-output-to-file FILE-NAME)
Documentation
Append the current article to a file named FILE-NAME.
If gnus-article-save-coding-system is non-nil, it is used to encode
text and used as the value of the coding cookie which is added to the
top of a file. Otherwise, this function saves a raw article without
the coding cookie.
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/gnus-art.el.gz
;;; Article savers.
(defun gnus-output-to-file (file-name)
"Append the current article to a file named FILE-NAME.
If `gnus-article-save-coding-system' is non-nil, it is used to encode
text and used as the value of the coding cookie which is added to the
top of a file. Otherwise, this function saves a raw article without
the coding cookie."
(let* ((artbuf (current-buffer))
(file-name-coding-system nnmail-pathname-coding-system)
(coding gnus-article-save-coding-system)
(coding-system-for-read (if coding
nil ;; Rely on the coding cookie.
mm-text-coding-system))
(coding-system-for-write (or coding
mm-text-coding-system-for-write
mm-text-coding-system))
(exists (file-exists-p file-name)))
(with-temp-buffer
(when exists
(insert-file-contents file-name)
(goto-char (point-min))
;; Remove the existing coding cookie.
(when (looking-at "X-Gnus-Coding-System: .+\n\n")
(delete-region (match-beginning 0) (match-end 0))))
(goto-char (point-max))
(insert-buffer-substring artbuf)
;; Append newline at end of the buffer as separator, and then
;; save it to file.
(goto-char (point-max))
(insert "\n")
(when coding
;; If the coding system is not suitable to encode the text,
;; ask a user for a proper one.
(setq coding (coding-system-base
(save-window-excursion
(select-safe-coding-system (point-min) (point-max)
coding))))
(setq coding-system-for-write
(or (cdr (assq coding '((mule-utf-8 . utf-8))))
coding))
(goto-char (point-min))
;; Add the coding cookie.
(insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
coding-system-for-write)))
(if exists
(progn
(write-region (point-min) (point-max) file-name nil 'no-message)
(message "Appended to %s" file-name))
(write-region (point-min) (point-max) file-name))))
t)