From 96af3d925f09c196e9c0a0c7fe0b3c1922ea5aa1 Mon Sep 17 00:00:00 2001 From: yamaoka Date: Thu, 10 Dec 1998 08:15:58 +0000 Subject: [PATCH] * lisp/pop3.el (pop3-movemail): Use `write-region-as-binary' instead of `append-to-file'. (pop3-movemail-file-coding-system): Abolished. * lisp/nnheader.el (nnheader-find-file-noselect): Use `find-file-noselect-as-specified-coding-system' instead of `find-file-noselect'. * lisp/nnmail.el (nnmail-find-file): Use `insert-file-contents-as-specified-coding-system' instead of `insert-file-contents'. * lisp/nnheader.el (nnheader-insert-file-contents): Likewise. * lisp/message.el (message-send-mail-with-qmail): Enclose `call-process-region' with `as-binary-process'. (message-send-mail-with-sendmail): Likewise. (message-send-coding-system): Abolished. * lisp/gnus-start.el (gnus-save-newsrc-file): Emulate `save-buffer' with `write-region-as-specified-coding-system'. (gnus-read-newsrc-el-file): Emulate `load' with `insert-file-contents-as-specified-coding-system' and `eval-region'. * lisp/gnus-cache.el (gnus-cache-save-buffers): Use `gnus-write-buffer-as-specified-coding-system' instead of `gnus-write-buffer'. * lisp/gnus-util.el (gnus-output-to-mail): Use `write-region-as-binary' instead of `append-to-file'. (gnus-output-to-mail): Use `gnus-write-buffer-as-binary' instead of `gnus-write-buffer'. (gnus-write-buffer-as-specified-coding-system): New function. (gnus-write-buffer-as-binary): New function. * lisp/nnmail.el (nnmail-write-region): Use `write-region-as-specified-coding-system' instead of `write-region'. * lisp/gnus-start.el (gnus-save-newsrc-file): Likewise. * lisp/gnus-agent.el (gnus-agent-expire): Likewise. (gnus-agent-fetch-headers): Likewise. (gnus-agent-flush-cache): Likewise. (gnus-agent-fetch-articles): Likewise. (gnus-agent-save-history): Likewise. (gnus-agent-save-groups): Likewise. (gnus-agent-save-active): Likewise. --- lisp/gnus-agent.el | 48 +++++++++++++------------- lisp/gnus-cache.el | 5 ++- lisp/gnus-start.el | 12 ++++--- lisp/gnus-util.el | 26 ++++++++++---- lisp/message.el | 97 +++++++++++++++++++++++++--------------------------- lisp/nnheader.el | 14 ++++---- lisp/nnmail.el | 12 +++---- lisp/pop3.el | 6 +--- 8 files changed, 115 insertions(+), 105 deletions(-) diff --git a/lisp/gnus-agent.el b/lisp/gnus-agent.el index 613b682..c0894fa 100644 --- a/lisp/gnus-agent.el +++ b/lisp/gnus-agent.el @@ -517,8 +517,9 @@ the actual number of articles toggled is returned." (let* ((gnus-command-method method) (file (gnus-agent-lib-file "active"))) (gnus-make-directory (file-name-directory file)) - (let ((coding-system-for-write gnus-agent-file-coding-system)) - (write-region (point-min) (point-max) file nil 'silent)) + (write-region-as-specified-coding-system + (point-min) (point-max) file nil 'silent + gnus-agent-file-coding-system) (when (file-exists-p (gnus-agent-lib-file "groups")) (delete-file (gnus-agent-lib-file "groups")))))) @@ -526,8 +527,9 @@ the actual number of articles toggled is returned." (let* ((gnus-command-method method) (file (gnus-agent-lib-file "groups"))) (gnus-make-directory (file-name-directory file)) - (let ((coding-system-for-write gnus-agent-file-coding-system)) - (write-region (point-min) (point-max) file nil 'silent)) + (write-region-as-specified-coding-system + (point-min) (point-max) file nil 'silent + gnus-agent-file-coding-system) (when (file-exists-p (gnus-agent-lib-file "active")) (delete-file (gnus-agent-lib-file "active"))))) @@ -598,9 +600,9 @@ the actual number of articles toggled is returned." (save-excursion (set-buffer gnus-agent-current-history) (gnus-make-directory (file-name-directory gnus-agent-file-name)) - (let ((coding-system-for-write gnus-agent-file-coding-system)) - (write-region (1+ (point-min)) (point-max) - gnus-agent-file-name nil 'silent)))) + (write-region-as-specified-coding-system + (1+ (point-min)) (point-max) gnus-agent-file-name nil 'silent + gnus-agent-file-coding-system))) (defun gnus-agent-close-history () (when (gnus-buffer-live-p gnus-agent-current-history) @@ -697,11 +699,10 @@ the actual number of articles toggled is returned." (if (not (re-search-forward "^Message-ID: *<\\([^>\n]+\\)>" nil t)) (setq id "No-Message-ID-in-article") (setq id (buffer-substring (match-beginning 1) (match-end 1)))) - (let ((coding-system-for-write - gnus-agent-file-coding-system)) - (write-region (point-min) (point-max) - (concat dir (number-to-string (caar pos))) - nil 'silent)) + (write-region-as-specified-coding-system + (point-min) (point-max) + (concat dir (number-to-string (caar pos))) nil 'silent + gnus-agent-file-coding-system) (when (setq elem (assq (caar pos) gnus-agent-article-alist)) (setcdr elem t)) (gnus-agent-enter-history @@ -741,12 +742,11 @@ the actual number of articles toggled is returned." (save-excursion (while gnus-agent-buffer-alist (set-buffer (cdar gnus-agent-buffer-alist)) - (let ((coding-system-for-write - gnus-agent-file-coding-system)) - (write-region (point-min) (point-max) - (gnus-agent-article-name ".overview" - (caar gnus-agent-buffer-alist)) - nil 'silent)) + (write-region-as-specified-coding-system + (point-min) (point-max) + (gnus-agent-article-name ".overview" + (caar gnus-agent-buffer-alist)) + nil 'silent gnus-agent-file-coding-system) (pop gnus-agent-buffer-alist)) (while gnus-agent-group-alist (nnheader-temp-write (caar gnus-agent-group-alist) @@ -777,9 +777,9 @@ the actual number of articles toggled is returned." (gnus-agent-braid-nov group articles file)) (gnus-make-directory (nnheader-translate-file-chars (file-name-directory file))) - (let ((coding-system-for-write - gnus-agent-file-coding-system)) - (write-region (point-min) (point-max) file nil 'silent)) + (write-region-as-specified-coding-system + (point-min) (point-max) file nil 'silent + gnus-agent-file-coding-system) (gnus-agent-save-alist group articles nil) (gnus-agent-enter-history "last-header-fetched-for-session" @@ -1349,9 +1349,9 @@ The following commands are available: ;; Schedule the history line for nuking. (push (cdr elem) histories))) (gnus-make-directory (file-name-directory nov-file)) - (let ((coding-system-for-write - gnus-agent-file-coding-system)) - (write-region (point-min) (point-max) nov-file nil 'silent)) + (write-region-as-specified-coding-system + (point-min) (point-max) nov-file nil 'silent + gnus-agent-file-coding-system) ;; Delete the unwanted entries in the alist. (setq gnus-agent-article-alist (sort gnus-agent-article-alist 'car-less-than-car)) diff --git a/lisp/gnus-cache.el b/lisp/gnus-cache.el index 7ac6ba2..6a996b8 100644 --- a/lisp/gnus-cache.el +++ b/lisp/gnus-cache.el @@ -124,9 +124,8 @@ it's not cached." (set-buffer buffer) (if (> (buffer-size) 0) ;; Non-empty overview, write it to a file. - (let ((coding-system-for-write - gnus-cache-overview-coding-system)) - (gnus-write-buffer overview-file)) + (gnus-write-buffer-as-specified-coding-system + overview-file gnus-cache-overview-coding-system) ;; Empty overview file, remove it (when (file-exists-p overview-file) (delete-file overview-file)) diff --git a/lisp/gnus-start.el b/lisp/gnus-start.el index 8c73a33..363682f 100644 --- a/lisp/gnus-start.el +++ b/lisp/gnus-start.el @@ -1917,8 +1917,10 @@ If FORCE is non-nil, the .newsrc file is read." (gnus-message 5 "Reading %s..." ding-file) (let (gnus-newsrc-assoc) (condition-case nil - (let ((coding-system-for-read gnus-startup-file-coding-system)) - (load ding-file t t t)) + (with-temp-buffer + (insert-file-contents-as-specified-coding-system + ding-file gnus-startup-file-coding-system) + (eval-region (point-min) (point-max))) (error (ding) (unless (gnus-yes-or-no-p @@ -2279,8 +2281,10 @@ If FORCE is non-nil, the .newsrc file is read." (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file) (gnus-gnus-to-quick-newsrc-format) (gnus-run-hooks 'gnus-save-quick-newsrc-hook) - (let ((coding-system-for-write gnus-startup-file-coding-system)) - (save-buffer)) + (write-region-as-specified-coding-system + (point-min) (point-max) (buffer-file-name) + gnus-startup-file-coding-system) + (set-buffer-modified-p nil) (kill-buffer (current-buffer)) (gnus-message 5 "Saving %s.eld...done" gnus-current-startup-file)) diff --git a/lisp/gnus-util.el b/lisp/gnus-util.el index 7d9dafa..1e2dd18 100644 --- a/lisp/gnus-util.el +++ b/lisp/gnus-util.el @@ -610,6 +610,21 @@ Bind `print-quoted' and `print-readably' to t while printing." ;; Write the buffer. (write-region (point-min) (point-max) file nil 'quietly)) +(defun gnus-write-buffer-as-binary (file) + "Write the current buffer's contents to FILE without code conversion." + ;; Make sure the directory exists. + (gnus-make-directory (file-name-directory file)) + ;; Write the buffer. + (write-region-as-binary (point-min) (point-max) file nil 'quietly)) + +(defun gnus-write-buffer-as-specified-coding-system (file coding-system) + "Write the current buffer's contents to FILE with code conversion." + ;; Make sure the directory exists. + (gnus-make-directory (file-name-directory file)) + ;; Write the buffer. + (write-region-as-specified-coding-system + (point-min) (point-max) file nil 'quietly coding-system)) + (defun gnus-delete-file (file) "Delete FILE if it exists." (when (file-exists-p file) @@ -791,9 +806,8 @@ with potentially long computations." (let ((file-buffer (create-file-buffer filename))) (save-excursion (set-buffer file-buffer) - (let ((require-final-newline nil) - (coding-system-for-write 'binary)) - (gnus-write-buffer filename))) + (let ((require-final-newline nil)) + (gnus-write-buffer-as-binary filename))) (kill-buffer file-buffer)) (error "Output file does not exist"))) (set-buffer tmpbuf) @@ -810,8 +824,7 @@ with potentially long computations." ;; Decide whether to append to a file or to an Emacs buffer. (let ((outbuf (get-file-buffer filename))) (if (not outbuf) - (let ((buffer-read-only nil) - (coding-system-for-write 'binary)) + (let ((buffer-read-only nil)) (save-excursion (goto-char (point-max)) (forward-char -2) @@ -821,7 +834,8 @@ with potentially long computations." (insert "\n")) (insert "\n")) (goto-char (point-max)) - (append-to-file (point-min) (point-max) filename))) + (write-region-as-binary (point-min) (point-max) + filename 'append))) ;; File has been visited, in buffer OUTBUF. (set-buffer outbuf) (let ((buffer-read-only nil)) diff --git a/lisp/message.el b/lisp/message.el index bf0355a..82923d6 100644 --- a/lisp/message.el +++ b/lisp/message.el @@ -917,9 +917,6 @@ The cdr of ech entry is a function for applying the face to a region.") (const :tag "always" t) (const :tag "ask" ask))) -(defvar message-send-coding-system 'binary - "Coding system to encode outgoing mail.") - ;;; Internal variables. (defvar message-buffer-list nil) @@ -2222,31 +2219,31 @@ the user from the mailer." (save-excursion (set-buffer errbuf) (erase-buffer)))) - (let ((default-directory "/") - (coding-system-for-write message-send-coding-system)) - (apply 'call-process-region - (append (list (point-min) (point-max) - (if (boundp 'sendmail-program) - sendmail-program - "/usr/lib/sendmail") - nil errbuf nil "-oi") - ;; Always specify who from, - ;; since some systems have broken sendmails. - ;; But some systems are more broken with -f, so - ;; we'll let users override this. - (if (null message-sendmail-f-is-evil) - (list "-f" (user-login-name))) - ;; These mean "report errors by mail" - ;; and "deliver in background". - (if (null message-interactive) '("-oem" "-odb")) - ;; Get the addresses from the message - ;; unless this is a resend. - ;; We must not do that for a resend - ;; because we would find the original addresses. - ;; For a resend, include the specific addresses. - (if resend-to-addresses - (list resend-to-addresses) - '("-t"))))) + (let ((default-directory "/")) + (as-binary-process + (apply 'call-process-region + (append (list (point-min) (point-max) + (if (boundp 'sendmail-program) + sendmail-program + "/usr/lib/sendmail") + nil errbuf nil "-oi") + ;; Always specify who from, + ;; since some systems have broken sendmails. + ;; But some systems are more broken with -f, so + ;; we'll let users override this. + (if (null message-sendmail-f-is-evil) + (list "-f" (user-login-name))) + ;; These mean "report errors by mail" + ;; and "deliver in background". + (if (null message-interactive) '("-oem" "-odb")) + ;; Get the addresses from the message + ;; unless this is a resend. + ;; We must not do that for a resend + ;; because we would find the original addresses. + ;; For a resend, include the specific addresses. + (if resend-to-addresses + (list resend-to-addresses) + '("-t")))))) (when message-interactive (save-excursion (set-buffer errbuf) @@ -2271,28 +2268,28 @@ to find out how to use this." (run-hooks 'message-send-mail-hook) ;; send the message (case - (let ((coding-system-for-write message-send-coding-system)) - (apply - 'call-process-region 1 (point-max) message-qmail-inject-program - nil nil nil - ;; qmail-inject's default behaviour is to look for addresses on the - ;; command line; if there're none, it scans the headers. - ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin. - ;; - ;; in general, ALL of qmail-inject's defaults are perfect for simply - ;; reading a formatted (i. e., at least a To: or Resent-To header) - ;; message from stdin. - ;; - ;; qmail also has the advantage of not having been raped by - ;; various vendors, so we don't have to allow for that, either -- - ;; compare this with message-send-mail-with-sendmail and weep - ;; for sendmail's lost innocence. - ;; - ;; all this is way cool coz it lets us keep the arguments entirely - ;; free for -inject-arguments -- a big win for the user and for us - ;; since we don't have to play that double-guessing game and the user - ;; gets full control (no gestapo'ish -f's, for instance). --sj - message-qmail-inject-args)) + (as-binary-process + (apply + 'call-process-region 1 (point-max) message-qmail-inject-program + nil nil nil + ;; qmail-inject's default behaviour is to look for addresses on the + ;; command line; if there're none, it scans the headers. + ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin. + ;; + ;; in general, ALL of qmail-inject's defaults are perfect for simply + ;; reading a formatted (i. e., at least a To: or Resent-To header) + ;; message from stdin. + ;; + ;; qmail also has the advantage of not having been raped by + ;; various vendors, so we don't have to allow for that, either -- + ;; compare this with message-send-mail-with-sendmail and weep + ;; for sendmail's lost innocence. + ;; + ;; all this is way cool coz it lets us keep the arguments entirely + ;; free for -inject-arguments -- a big win for the user and for us + ;; since we don't have to play that double-guessing game and the user + ;; gets full control (no gestapo'ish -f's, for instance). --sj + message-qmail-inject-args)) ;; qmail-inject doesn't say anything on it's stdout/stderr, ;; we have to look at the retval instead (0 nil) diff --git a/lisp/nnheader.el b/lisp/nnheader.el index f0835cd..19e3f6f 100644 --- a/lisp/nnheader.el +++ b/lisp/nnheader.el @@ -773,10 +773,10 @@ find-file-hooks, etc. (auto-mode-alist (nnheader-auto-mode-alist)) (default-major-mode 'fundamental-mode) (enable-local-variables nil) - (after-insert-file-functions nil) - (find-file-hooks nil) - (coding-system-for-read nnheader-file-coding-system)) - (insert-file-contents filename visit beg end replace))) + (after-insert-file-functions nil) + (find-file-hooks nil)) + (insert-file-contents-as-specified-coding-system + filename visit beg end replace nnheader-file-coding-system))) (defun nnheader-find-file-noselect (&rest args) (let ((format-alist nil) @@ -784,9 +784,9 @@ find-file-hooks, etc. (default-major-mode 'fundamental-mode) (enable-local-variables nil) (after-insert-file-functions nil) - (find-file-hooks nil) - (coding-system-for-read nnheader-file-coding-system)) - (apply 'find-file-noselect args))) + (find-file-hooks nil)) + (apply 'find-file-noselect-as-specified-coding-system + (append args (list nnheader-file-coding-system))))) (defun nnheader-auto-mode-alist () "Return an `auto-mode-alist' with only the .gz (etc) thingies." diff --git a/lisp/nnmail.el b/lisp/nnmail.el index a323f87..77f39f6 100644 --- a/lisp/nnmail.el +++ b/lisp/nnmail.el @@ -493,9 +493,9 @@ parameter. It should return nil, `warn' or `delete'." (let ((format-alist nil) (after-insert-file-functions nil)) (condition-case () - (let ((coding-system-for-read nnmail-file-coding-system) - (pathname-coding-system 'binary)) - (insert-file-contents file) + (let ((pathname-coding-system 'binary)) + (insert-file-contents-as-specified-coding-system + file nnmail-file-coding-system) t) (file-error nil)))) @@ -1703,9 +1703,9 @@ If ARGS, PROMPT is used as an argument to `format'." (defun nnmail-write-region (start end filename &optional append visit lockname) "Do a `write-region', and then set the file modes." - (let ((coding-system-for-write nnmail-file-coding-system) - (pathname-coding-system 'binary)) - (write-region start end filename append visit lockname) + (let ((pathname-coding-system 'binary)) + (write-region-as-specified-coding-system + start end filename append visit lockname nnmail-file-coding-system) (set-file-modes filename nnmail-default-file-modes))) ;;; diff --git a/lisp/pop3.el b/lisp/pop3.el index 7bfe466..a07b805 100644 --- a/lisp/pop3.el +++ b/lisp/pop3.el @@ -60,9 +60,6 @@ values are 'apop.") "Timestamp returned when initially connected to the POP server. Used for APOP authentication.") -(defvar pop3-movemail-file-coding-system 'binary - "Crashbox made by pop3-movemail with this coding system.") - (defvar pop3-read-point nil) (defvar pop3-debug nil) @@ -94,8 +91,7 @@ Used for APOP authentication.") (pop3-retr process n crashbuf) (save-excursion (set-buffer crashbuf) - (let ((coding-system-for-write pop3-movemail-file-coding-system)) - (append-to-file (point-min) (point-max) crashbox)) + (write-region-as-binary (point-min) (point-max) crashbox 'append) (set-buffer (process-buffer process)) (while (> (buffer-size) 5000) (goto-char (point-min)) -- 1.7.10.4