(nnmail-split-it): Don't compare ".*" and VALUE of each element of
[elisp/gnus.git-] / lisp / nnmail.el
index 897df61..afd852a 100644 (file)
@@ -32,7 +32,6 @@
 (require 'custom)
 (require 'gnus-util)
 (require 'mail-source)
-(require 'mm-util)
 
 (eval-and-compile
   (autoload 'gnus-error "gnus-util")
@@ -438,8 +437,7 @@ parameter.  It should return nil, `warn' or `delete'."
 (defvar nnmail-file-coding-system 'raw-text
   "Coding system used in nnmail.")
 
-(defvar nnmail-incoming-coding-system
-  mm-text-coding-system
+(defvar nnmail-incoming-coding-system 'raw-text
   "Coding system used in reading inbox")
 
 (defvar nnmail-pathname-coding-system 'binary
@@ -452,10 +450,10 @@ 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)
-             (auto-mode-alist (nnheader-auto-mode-alist))
+       (let ((auto-mode-alist (nnheader-auto-mode-alist))
              (pathname-coding-system nnmail-pathname-coding-system))
-         (insert-file-contents file)
+         (insert-file-contents-as-coding-system
+          nnmail-file-coding-system file)
          t)
       (file-error nil))))
 
@@ -470,7 +468,7 @@ parameter.  It should return nil, `warn' or `delete'."
         (concat dir group "/")
        ;; If not, we translate dots into slashes.
        (concat dir
-              (mm-encode-coding-string
+              (encode-coding-string
                (nnheader-replace-chars-in-string group ?. ?/)
                nnmail-pathname-coding-system)
               "/")))
@@ -498,7 +496,8 @@ nn*-request-list should have been called before calling this function."
 
 (defun nnmail-save-active (group-assoc file-name)
   "Save GROUP-ASSOC in ACTIVE-FILE."
-  (let ((coding-system-for-write nnmail-active-file-coding-system))
+  (let ((coding-system-for-write nnmail-active-file-coding-system)
+       (output-coding-system nnmail-active-file-coding-system))
     (when file-name
       (with-temp-file file-name
        (nnmail-generate-active group-assoc)))))
@@ -850,7 +849,7 @@ FUNC will be called with the buffer narrowed to each mail."
       (set-buffer (get-buffer-create " *nnmail incoming*"))
       (erase-buffer)
       (let ((nnheader-file-coding-system nnmail-incoming-coding-system))
-       (mm-insert-file-contents incoming))
+       (nnheader-insert-file-contents incoming))
       (prog1
          (if (zerop (buffer-size))
              0
@@ -1022,7 +1021,7 @@ Return the number of characters in the body."
       (insert (format "Xref: %s" (system-name)))
       (while group-alist
        (insert (format " %s:%d"
-                       (mm-encode-coding-string
+                       (encode-coding-string
                         (caar group-alist)
                         nnmail-pathname-coding-system)
                        (cdar group-alist)))
@@ -1128,40 +1127,40 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
            (setq value (cdr (assq value nnmail-split-abbrev-alist))))
        (while (and (goto-char end-point)
                    (re-search-backward (cdr cached-pair) nil t))
-       (when nnmail-split-tracing
-         (push (cdr cached-pair) nnmail-split-trace))
-       (let ((split-rest (cddr split))
-             (end (match-end 0))
-             ;; The searched regexp is \(\(FIELD\).*\)\(VALUE\).  So,
-             ;; start-of-value is the the point just before the
-             ;; beginning of the value, whereas after-header-name is
-             ;; the point just after the field name.
-             (start-of-value (match-end 1))
-             (after-header-name (match-end 2)))
+         (when nnmail-split-tracing
+           (push (cdr cached-pair) nnmail-split-trace))
+         (let ((split-rest (cddr split))
+               (end (match-end 0))
+               ;; The searched regexp is \(\(FIELD\).*\)\(VALUE\).  So,
+               ;; start-of-value is the the point just before the
+               ;; beginning of the value, whereas after-header-name is
+               ;; the point just after the field name.
+               (start-of-value (match-end 1))
+               (after-header-name (match-end 2)))
            ;; Start the next search just before the beginning of the
            ;; VALUE match.
            (setq end-point (1- start-of-value))
-         ;; Handle - RESTRICTs
-         (while (eq (car split-rest) '-)
-           ;; RESTRICT must start after-header-name and
-           ;; end after start-of-value, so that, for
-           ;; (any "foo" - "x-foo" "foo.list")
-           ;; we do not exclude foo.list just because
-           ;; the header is: ``To: x-foo, foo''
-           (goto-char end)
-           (if (and (re-search-backward (cadr split-rest)
-                                        after-header-name t)
-                    (> (match-end 0) start-of-value))
-               (setq split-rest nil)
-             (setq split-rest (cddr split-rest))))
-         (when split-rest
-           (goto-char end)
-           (let ((value (nth 1 split)))
-             (if (symbolp value)
-                 (setq value (cdr (assq value nnmail-split-abbrev-alist))))
-             ;; Someone might want to do a \N sub on this match, so get the
-             ;; correct match positions.
-             (re-search-backward value start-of-value))
+           ;; Handle - RESTRICTs
+           (while (eq (car split-rest) '-)
+             ;; RESTRICT must start after-header-name and
+             ;; end after start-of-value, so that, for
+             ;; (any "foo" - "x-foo" "foo.list")
+             ;; we do not exclude foo.list just because
+             ;; the header is: ``To: x-foo, foo''
+             (goto-char end)
+             (if (and (re-search-backward (cadr split-rest)
+                                          after-header-name t)
+                      (> (match-end 0) start-of-value))
+                 (setq split-rest nil)
+               (setq split-rest (cddr split-rest))))
+           (when split-rest
+             (goto-char end)
+             (let ((value (nth 1 split)))
+               (if (symbolp value)
+                   (setq value (cdr (assq value nnmail-split-abbrev-alist))))
+               ;; Someone might want to do a \N sub on this match, so get the
+               ;; correct match positions.
+               (re-search-backward value start-of-value))
              (dolist (sp (nnmail-split-it (car split-rest)))
                (unless (memq sp split-result)
                  (push sp split-result))))))
@@ -1174,7 +1173,8 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
             partial regexp)
        (if (symbolp value)
            (setq value (cdr (assq value nnmail-split-abbrev-alist))))
-       (if (string= ".*" (substring value 0 2))
+       (if (and (>= (length value) 2)
+                (string= ".*" (substring value 0 2)))
            (setq value (substring value 2)
                  partial ""))
        (setq regexp (concat "^\\(\\("
@@ -1274,7 +1274,7 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
        (setq nnmail-cache-buffer
             (get-buffer-create " *nnmail message-id cache*")))
       (when (file-exists-p nnmail-message-id-cache-file)
-       (mm-insert-file-contents nnmail-message-id-cache-file))
+       (nnheader-insert-file-contents nnmail-message-id-cache-file))
       (set-buffer-modified-p nil)
       (current-buffer))))
 
@@ -1494,9 +1494,10 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
 
 (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 nnmail-pathname-coding-system))
-    (write-region start end filename append visit lockname)
+  (let ((pathname-coding-system nnmail-pathname-coding-system))
+    
+    (write-region-as-coding-system
+     nnmail-file-coding-system start end filename append visit lockname)
     (set-file-modes filename nnmail-default-file-modes)))
 
 ;;;