Synch to No Gnus 200409231508.
[elisp/gnus.git-] / lisp / nnheader.el
index ddd87ad..141fce0 100644 (file)
@@ -1,7 +1,7 @@
 ;;; nnheader.el --- header access macros for Semi-gnus and its backends
 
 ;; Copyright (C) 1987, 1988, 1989, 1990, 1993, 1994, 1995, 1996,
-;;        1997, 1998, 2000, 2001, 2002, 2003
+;;        1997, 1998, 2000, 2001, 2002, 2003, 2004
 ;;        Free Software Foundation, Inc.
 
 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
@@ -67,7 +67,7 @@ they will keep on jabbering all the time."
   :group 'gnus-server
   :type 'boolean)
 
-(defvar nnheader-max-head-length 4096
+(defvar nnheader-max-head-length 8192
   "*Max length of the head of articles.
 
 Value is an integer, nil, or t.  nil means read in chunks of a file
@@ -286,7 +286,24 @@ nil, ."
     "Return non-nil if SYM is a coding system."
     (or (and (fboundp 'find-coding-system) (find-coding-system sym))
        (and (fboundp 'coding-system-p) (coding-system-p sym))))
-  (defalias 'mm-coding-system-p 'nnheader-coding-system-p))
+  (defalias 'mm-coding-system-p 'nnheader-coding-system-p)
+
+  (defalias 'mm-disable-multibyte
+    (static-if (featurep 'xemacs)
+       'ignore
+      (lambda nil (set-buffer-multibyte nil))))
+  (defalias 'mm-enable-multibyte
+    (static-if (featurep 'xemacs)
+       'ignore
+      ;; Why isn't it t but `to'?  See mm-util.el.
+      (lambda nil (set-buffer-multibyte 'to))))
+
+  (defalias 'mm-encode-coding-region 'encode-coding-region)
+
+  (defalias 'mm-string-make-unibyte
+    (if (fboundp 'string-make-unibyte)
+       'string-make-unibyte
+      'identity)))
 
 ;; mail-parse stuff.
 (unless (featurep 'mail-parse)
@@ -598,12 +615,16 @@ given, the return value will not contain the last newline."
 
 (defvar nnheader-fake-message-id 1)
 
-(defsubst nnheader-generate-fake-message-id ()
-  (concat "fake+none+" (int-to-string (incf nnheader-fake-message-id))))
+(defsubst nnheader-generate-fake-message-id (&optional number)
+  (if (numberp number)
+      (format "fake+none+%s+%d" gnus-newsgroup-name number)
+    (format "fake+none+%s+%s"
+           gnus-newsgroup-name
+           (int-to-string (incf nnheader-fake-message-id)))))
 
 (defsubst nnheader-fake-message-id-p (id)
   (save-match-data                     ; regular message-id's are <.*>
-    (string-match "\\`fake\\+none\\+[0-9]+\\'" id)))
+    (string-match "\\`fake\\+none\\+.*\\+[0-9]+\\'" id)))
 
 ;; Parsing headers and NOV lines.
 
@@ -668,7 +689,7 @@ given, the return value will not contain the last newline."
                (or (search-forward ">" (point-at-eol) t) (point)))
             ;; If there was no message-id, we just fake one to make
             ;; subsequent routines simpler.
-            (nnheader-generate-fake-message-id)))
+            (nnheader-generate-fake-message-id number)))
         ;; References.
         (progn
           (goto-char p)
@@ -767,20 +788,28 @@ given, the return value will not contain the last newline."
               out)))
      out))
 
-(defmacro nnheader-nov-read-message-id ()
-  '(let ((id (nnheader-nov-field)))
+(defvar nnheader-uniquify-message-id nil)
+
+(defmacro nnheader-nov-read-message-id (&optional number)
+  `(let ((id (nnheader-nov-field)))
      (if (string-match "^<[^>]+>$" id)
-        id
-       (nnheader-generate-fake-message-id))))
+        ,(if nnheader-uniquify-message-id
+             `(if (string-match "__[^@]+@" id)
+                  (concat (substring id 0 (match-beginning 0))
+                          (substring id (1- (match-end 0))))
+                id)
+           'id)
+       (nnheader-generate-fake-message-id ,number))))
 
 (defun nnheader-parse-nov ()
-  (let ((eol (point-at-eol)))
+  (let* ((eol (point-at-eol))
+        (number (nnheader-nov-read-integer)))
     (make-full-mail-header
-     (nnheader-nov-read-integer)       ; number
+     number                            ; number
      (nnheader-nov-field)              ; subject
      (nnheader-nov-field)              ; from
      (nnheader-nov-field)              ; date
-     (nnheader-nov-read-message-id)    ; id
+     (nnheader-nov-read-message-id number) ; id
      (nnheader-nov-field)              ; refs
      (nnheader-nov-read-integer)       ; chars
      (nnheader-nov-read-integer)       ; lines
@@ -1211,6 +1240,14 @@ list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
      (point-max)))
   (goto-char (point-min)))
 
+(defun nnheader-get-lines-and-char ()
+  "Return the number of lines and chars in the article body."
+  (goto-char (point-min))
+  (if (not (re-search-forward "\n\r?\n" nil t))
+      (list 0 0)
+    (list (count-lines (point) (point-max))
+         (- (point-max) (point)))))
+
 (defun nnheader-remove-body ()
   "Remove the body from an article in this current buffer."
   (goto-char (point-min))
@@ -1250,8 +1287,7 @@ list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
 
 (defvar nnheader-directory-files-is-safe
   (or (eq system-type 'windows-nt)
-      (and (not (featurep 'xemacs))
-          (> emacs-major-version 20)))
+      (not (featurep 'xemacs)))
   "If non-nil, Gnus believes `directory-files' is safe.
 It has been reported numerous times that `directory-files' fails with
 an alarming frequency on NFS mounted file systems. If it is nil,