*** empty log message ***
[gnus] / lisp / nnmail.el
index 49cbd6b..4dcfc88 100644 (file)
@@ -204,8 +204,8 @@ GROUP: Mail will be stored in GROUP (a string).
 \(& SPLIT...): Process each SPLIT expression.
 
 FIELD must match a complete field name.  VALUE must match a complete
-word according to the fundamental mode syntax table.  You can use .*
-in the regexps to match partial field names or words.
+word according to the `nnmail-split-fancy-syntax-table' syntax table.
+You can use .* in the regexps to match partial field names or words.
 
 FIELD and VALUE can also be lisp symbols, in that case they are expanded
 as specified in `nnmail-split-abbrev-alist'.
@@ -261,6 +261,10 @@ parameter.  It should return nil, `warn' or `delete'.")
 
 ;;; Internal variables.
 
+(defvar nnmail-split-fancy-syntax-table
+  (copy-syntax-table (standard-syntax-table))
+  "Syntax table used by `nnmail-split-fancy'.")
+
 \f
 
 (defconst nnmail-version "nnmail 1.0"
@@ -436,8 +440,8 @@ nn*-request-list should have been called before calling this function."
        (erase-buffer)
        (while group-assoc
          (setq group (pop group-assoc))
-         (insert (format "%s %d %d y\n" (car group) (cdr (car (cdr group)) )
-                         (car (car (cdr group))))))
+         (insert (format "%s %d %d y\n" (car group) (cdadr group) 
+                         (caadr group))))
        (unless (file-exists-p (file-name-directory file-name))
          (make-directory (file-name-directory file-name) t))
        (write-region 1 (point-max) (expand-file-name file-name) nil 'nomesg)
@@ -529,7 +533,9 @@ nn*-request-list should have been called before calling this function."
        found)
     (while (not found)
       (if (re-search-forward delim nil t)
-         (when (looking-at "[^ :]+:")
+         (when (or (looking-at "[^\n :]+ *:")
+                   (looking-at delim)
+                   (looking-at (concat ">" rmail-unix-mail-delimiter)))
            (forward-line -1)
            (setq found 'yes))
        (setq found 'no)))
@@ -585,15 +591,25 @@ nn*-request-list should have been called before calling this function."
        (goto-char (point-max))
        (widen)
        (setq head-end (point))
-       ;; We try the Content-Length value.
+       ;; We try the Content-Length value.  The idea: skip over the header
+       ;; separator, then check what happens content-length bytes into the
+       ;; message body.  This should be either the end ot the buffer, the
+       ;; message separator or a blank line followed by the separator.
+       ;; The blank line should probably be deleted.  If neither of the
+       ;; three is met, the content-length header is probably invalid.
        (when content-length
          (forward-line 1)
          (setq skip (+ (point) content-length))
-         (when (or (= skip (point-max))
-                   (and (< skip (point-max))
-                        (goto-char skip)
-                        (looking-at delim)))
-           (setq end skip)))
+         (goto-char skip)
+         (cond ((or (= skip (point-max))
+                    (= (1+ skip) (point-max)))
+                (setq end (point-max)))
+               ((looking-at delim)
+                (setq end skip))
+               ((looking-at
+                 (concat "[ \t]*\n\\(" delim "\\)"))
+                (setq end (match-beginning 1)))
+               (t (setq end nil))))
        (if end
            (goto-char end)
          ;; No Content-Length, so we find the beginning of the next 
@@ -670,30 +686,26 @@ FUNC will be called with the buffer narrowed to each mail."
                                           nnmail-use-procmail)
                                       (not nnmail-resplit-incoming))
                                  (list (list group ""))
-                               nnmail-split-methods))
-       start end do-search message-id)
+                               nnmail-split-methods)))
     (save-excursion
-      ;; Open the message-id cache.
-      (nnmail-cache-open)
       ;; Insert the incoming file.
       (set-buffer (get-buffer-create " *nnmail incoming*"))
       (buffer-disable-undo (current-buffer))
       (erase-buffer)
       (insert-file-contents incoming)
-      (goto-char (point-min))
-      (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
-      ;; Handle both babyl, MMDF and unix mail formats, since movemail will
-      ;; use the former when fetching from a mailbox, the latter when
-      ;; fetches from a file.
-      (cond ((or (looking-at "\^L")
-                (looking-at "BABYL OPTIONS:"))
-            (nnmail-process-babyl-mail-format func))
-           ((looking-at "\^A\^A\^A\^A")
-            (nnmail-process-mmdf-mail-format func))
-           (t
-            (nnmail-process-unix-mail-format func)))
-      ;; Close the message-id cache.
-      (nnmail-cache-close)
+      (unless (zerop (buffer-size))
+       (goto-char (point-min))
+       (save-excursion (run-hooks 'nnmail-prepare-incoming-hook))
+       ;; Handle both babyl, MMDF and unix mail formats, since movemail will
+       ;; use the former when fetching from a mailbox, the latter when
+       ;; fetches from a file.
+       (cond ((or (looking-at "\^L")
+                  (looking-at "BABYL OPTIONS:"))
+              (nnmail-process-babyl-mail-format func))
+             ((looking-at "\^A\^A\^A\^A")
+              (nnmail-process-mmdf-mail-format func))
+             (t
+              (nnmail-process-unix-mail-format func))))
       (if exit-func (funcall exit-func))
       (kill-buffer (current-buffer)))))
 
@@ -709,8 +721,7 @@ FUNC will be called with the group name to determine the article number."
        ;; If there is only just one group to put everything in, we
        ;; just return a list with just this one method in.
        (setq group-art
-             (list (cons (car (car methods))
-                         (funcall func (car (car methods))))))
+             (list (cons (caar methods) (funcall func (caar methods)))))
       ;; We do actual comparison.
       (save-excursion
        ;; Find headers.
@@ -747,7 +758,7 @@ FUNC will be called with the group name to determine the article number."
                (when (and
                       (condition-case () 
                           (if (stringp (nth 1 method))
-                              (re-search-backward (car (cdr method)) nil t)
+                              (re-search-backward (cadr method) nil t)
                             ;; Function to say whether this is a match.
                             (funcall (nth 1 method) (car method)))
                         (error nil))
@@ -791,8 +802,7 @@ Return the number of characters in the body."
                         (progn (forward-line 1) (point))))
       (insert (format "Xref: %s" (system-name)))
       (while group-alist
-       (insert (format " %s:%d" (car (car group-alist)) 
-                       (cdr (car group-alist))))
+       (insert (format " %s:%d" (caar group-alist) (cdar group-alist)))
        (setq group-alist (cdr group-alist)))
       (insert "\n"))))
 
@@ -810,7 +820,12 @@ Return the number of characters in the body."
 (defun nnmail-split-fancy ()
   "Fancy splitting method.
 See the documentation for the variable `nnmail-split-fancy' for documentation."
-  (nnmail-split-it nnmail-split-fancy))
+  (let ((syntab (syntax-table)))
+    (unwind-protect
+       (progn
+         (set-syntax-table nnmail-split-fancy-syntax-table)
+         (nnmail-split-it nnmail-split-fancy))
+      (set-syntax-table syntab))))
 
 (defvar nnmail-split-cache nil)
 ;; Alist of split expressions their equivalent regexps.
@@ -973,6 +988,7 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
       (buffer-disable-undo (current-buffer))
       (and (file-exists-p nnmail-message-id-cache-file)
           (insert-file-contents nnmail-message-id-cache-file))
+      (set-buffer-modified-p nil)
       (current-buffer))))
 
 (defun nnmail-cache-close ()
@@ -996,7 +1012,8 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
                    nnmail-message-id-cache-file nil 'silent)
       (set-buffer-modified-p nil)
       (setq nnmail-cache-buffer nil)
-      (kill-buffer (current-buffer)))))
+      ;;(kill-buffer (current-buffer))
+      )))
 
 (defun nnmail-cache-insert (id)
   (when nnmail-treat-duplicates
@@ -1038,9 +1055,9 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
          (beginning-of-line)
          (insert "Original-"))
        (beginning-of-line)
-       (insert "Message-ID: " newid "\n")
-       (insert "Gnus-Warning: This is a duplication of message "
-               message-id "\n")
+       (insert 
+        "Message-ID: " newid "\n"
+        "Gnus-Warning: This is a duplicate of message " message-id "\n")
        (nnmail-cache-insert newid)
        (funcall func)))
      (t
@@ -1065,6 +1082,8 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
       (nnmail-activate method)
       ;; Allow the user to hook.
       (run-hooks 'nnmail-pre-get-new-mail-hook)
+      ;; Open the message-id cache.
+      (nnmail-cache-open)
       ;; The we go through all the existing spool files and split the
       ;; mail from each.
       (while spools
@@ -1105,6 +1124,8 @@ See the documentation for the variable `nnmail-split-fancy' for documentation."
          (funcall exit-func))
        (run-hooks 'nnmail-read-incoming-hook)
        (nnheader-message 3 "%s: Reading incoming mail...done" method))
+      ;; Close the message-id cache.
+      (nnmail-cache-close)
       ;; Allow the user to hook.
       (run-hooks 'nnmail-post-get-new-mail-hook)
       ;; Delete all the temporary files.