]> code.delx.au - gnu-emacs/blobdiff - lisp/gnus/nnmaildir.el
; Merge from origin/emacs-25
[gnu-emacs] / lisp / gnus / nnmaildir.el
index da3d5460c2bfdcbb257add860dd2de79ceb86da4..cebdc95876fec189765e3b6a47f1ee2a1987d87e 100644 (file)
@@ -75,6 +75,7 @@
 
 (defconst nnmaildir-flag-mark-mapping
   '((?F . tick)
+    (?P . forward)
     (?R . reply)
     (?S . read))
   "Alist mapping Maildir filename flags to Gnus marks.
@@ -96,14 +97,14 @@ See `nnmaildir-flag-mark-mapping'."
 
 (defun nnmaildir--ensure-suffix (filename)
   "Ensure that FILENAME contains the suffix \":2,\"."
-  (if (gnus-string-match-p ":2," filename)
+  (if (string-match-p ":2," filename)
       filename
     (concat filename ":2,")))
 
 (defun nnmaildir--add-flag (flag suffix)
   "Return a copy of SUFFIX where FLAG is set.
 SUFFIX should start with \":2,\"."
-  (unless (gnus-string-match-p "^:2," suffix)
+  (unless (string-match-p "^:2," suffix)
     (error "Invalid suffix `%s'" suffix))
   (let* ((flags (substring suffix 3))
         (flags-as-list (append flags nil))
@@ -116,7 +117,7 @@ SUFFIX should start with \":2,\"."
 (defun nnmaildir--remove-flag (flag suffix)
   "Return a copy of SUFFIX where FLAG is cleared.
 SUFFIX should start with \":2,\"."
-  (unless (gnus-string-match-p "^:2," suffix)
+  (unless (string-match-p "^:2," suffix)
     (error "Invalid suffix `%s'" suffix))
   (let* ((flags (substring suffix 3))
         (flags-as-list (append flags nil))
@@ -146,7 +147,7 @@ by nnmaildir-request-article.")
 
 ;; A NOV structure looks like this (must be prin1-able, so no defstruct):
 ["subject\tfrom\tdate"
- "references\tchars\lines"
+ "references\tchars\tlines"
  "To: you\tIn-Reply-To: <your.mess@ge>"
  (12345 67890)     ;; modtime of the corresponding article file
  (to in-reply-to)] ;; contemporary value of nnmail-extra-headers
@@ -333,29 +334,24 @@ by nnmaildir-request-article.")
 ;; given group, if non-nil, be the current group of the current server.  Then
 ;; return the group object for the current group.
 (defun nnmaildir--prepare (server group)
-  (let (x groups)
-    (catch 'return
-      (if (null server)
-         (unless (setq server nnmaildir--cur-server)
-           (throw 'return nil))
-       (unless (setq server (intern-soft server nnmaildir--servers))
+  (catch 'return
+    (if (null server)
+       (unless (setq server nnmaildir--cur-server)
          (throw 'return nil))
-       (setq server (symbol-value server)
-             nnmaildir--cur-server server))
-      (unless (setq groups (nnmaildir--srv-groups server))
+      (unless (setq server (intern-soft server nnmaildir--servers))
        (throw 'return nil))
-      (unless (nnmaildir--srv-method server)
-       (setq x (concat "nnmaildir:" (nnmaildir--srv-address server))
-             x (gnus-server-to-method x))
-       (unless x (throw 'return nil))
-       (setf (nnmaildir--srv-method server) x))
-      (if (null group)
-         (unless (setq group (nnmaildir--srv-curgrp server))
-           (throw 'return nil))
-       (unless (setq group (intern-soft group groups))
-         (throw 'return nil))
-       (setq group (symbol-value group)))
-      group)))
+      (setq server (symbol-value server)
+           nnmaildir--cur-server server))
+    (let ((groups (nnmaildir--srv-groups server)))
+      (when groups
+       (unless (nnmaildir--srv-method server)
+         (setf (nnmaildir--srv-method server)
+               (or (gnus-server-to-method
+                    (concat "nnmaildir:" (nnmaildir--srv-address server)))
+                   (throw 'return nil))))
+       (if (null group)
+           (nnmaildir--srv-curgrp server)
+         (symbol-value (intern-soft group groups)))))))
 
 (defun nnmaildir--tab-to-space (string)
   (let ((pos 0))
@@ -428,7 +424,7 @@ by nnmaildir-request-article.")
        (srv-dir (nnmaildir--srv-dir server))
        (storage-version 1) ;; [version article-number msgid [...nov...]]
        dir gname pgname msgdir prefix suffix file attr mtime novdir novfile
-       nov msgid nov-beg nov-mid nov-end field val old-extra num numdir
+       nov msgid nov-beg nov-mid nov-end field val old-extra num
        deactivate-mark)
     (catch 'return
       (setq gname (nnmaildir--grp-name group)
@@ -541,8 +537,8 @@ by nnmaildir-request-article.")
        (prin1 (vector storage-version num msgid nov) (current-buffer))
        (setq file (concat novfile ":"))
        (nnmaildir--unlink file)
-       (gmm-write-region (point-min) (point-max) file nil 'no-message nil
-                         'excl))
+       (write-region (point-min) (point-max) file nil 'no-message nil
+                     'excl))
       (rename-file file novfile 'replace)
       (setf (nnmaildir--art-msgid article) msgid)
       nov)))
@@ -660,15 +656,15 @@ by nnmaildir-request-article.")
   (if (zerop n) 1 (1- (lsh 1 (1+ (logb n))))))
 
 (defun nnmaildir--system-name ()
-  (gnus-replace-in-string
-   (gnus-replace-in-string
-    (gnus-replace-in-string
-     (system-name)
-     "\\\\" "\\134" 'literal)
-    "/" "\\057" 'literal)
-   ":" "\\072" 'literal))
-
-(defun nnmaildir-request-type (group &optional article)
+  (replace-regexp-in-string
+   ":" "\\072"
+   (replace-regexp-in-string
+    "/" "\\057"
+    (replace-regexp-in-string "\\\\" "\\134" (system-name) nil 'literal)
+    nil 'literal)
+   nil 'literal))
+
+(defun nnmaildir-request-type (_group &optional _article)
   'mail)
 
 (defun nnmaildir-status-message (&optional server)
@@ -768,7 +764,7 @@ by nnmaildir-request-article.")
     (if (> (aref a 1) (aref b 1)) (throw 'return nil))
     (string-lessp (aref a 2) (aref b 2))))
 
-(defun nnmaildir--scan (gname scan-msgs groups method srv-dir srv-ls)
+(defun nnmaildir--scan (gname scan-msgs groups _method srv-dir srv-ls)
   (catch 'return
     (let ((36h-ago (- (car (current-time)) 2))
          absdir nndir tdir ndir cdir nattr cattr isnew pgname read-only ls
@@ -852,11 +848,11 @@ by nnmaildir-request-article.")
              (when (or
                     ;; first look for marks in suffix, if it's valid...
                     (when (and (stringp suffix)
-                               (gnus-string-prefix-p ":2," suffix))
+                               (string-prefix-p ":2," suffix))
                       (or
-                       (not (gnus-string-match-p
+                       (not (string-match-p
                              (string (nnmaildir--mark-to-flag 'read)) suffix))
-                       (gnus-string-match-p
+                       (string-match-p
                         (string (nnmaildir--mark-to-flag 'tick)) suffix)))
                     ;; then look in marks directories
                     (not (file-exists-p (concat cdir prefix)))
@@ -883,6 +879,10 @@ by nnmaildir-request-article.")
        (setf (nnmaildir--grp-cur group) cattr)))
     t))
 
+(defvar nnmaildir-get-new-mail)
+(defvar nnmaildir-group-alist)
+(defvar nnmaildir-active-file)
+
 (defun nnmaildir-request-scan (&optional scan-group server)
   (let ((coding-system-for-write nnheader-file-coding-system)
        (buffer-file-coding-system nil)
@@ -890,7 +890,7 @@ by nnmaildir-request-article.")
        (nnmaildir-get-new-mail t)
        (nnmaildir-group-alist nil)
        (nnmaildir-active-file nil)
-       x srv-ls srv-dir method groups target-prefix group dirs grp-dir seen
+       x srv-ls srv-dir method groups target-prefix dirs seen
        deactivate-mark)
     (nnmaildir--prepare server nil)
     (setq srv-ls (nnmaildir--srv-ls nnmaildir--cur-server)
@@ -955,8 +955,9 @@ by nnmaildir-request-article.")
                        pgname (nnmaildir--pgname nnmaildir--cur-server pgname)
                        group (symbol-value group)
                        ro (nnmaildir--param pgname 'read-only))
-                 (insert (gnus-replace-in-string
-                          (nnmaildir--grp-name group) " " "\\ " t)
+                 (insert (replace-regexp-in-string
+                          " " "\\ "
+                          (nnmaildir--grp-name group) nil t)
                          " ")
                   (princ (nnmaildir--group-maxnum nnmaildir--cur-server group)
                         nntp-server-buffer)
@@ -966,7 +967,7 @@ by nnmaildir-request-article.")
                (nnmaildir--srv-groups nnmaildir--cur-server))))
   t)
 
-(defun nnmaildir-request-newgroups (date &optional server)
+(defun nnmaildir-request-newgroups (_date &optional server)
   (nnmaildir-request-list server))
 
 (defun nnmaildir-retrieve-groups (groups &optional server)
@@ -985,7 +986,7 @@ by nnmaildir-request-article.")
          (princ (nnmaildir--group-maxnum nnmaildir--cur-server group)
                 nntp-server-buffer)
          (insert " "
-                 (gnus-replace-in-string gname " " "\\ " t)
+                 (replace-regexp-in-string " " "\\ " gname nil t)
                  "\n")))))
   'group)
 
@@ -995,9 +996,9 @@ by nnmaildir-request-article.")
                  (nnmaildir--srvgrp-dir
                   (nnmaildir--srv-dir nnmaildir--cur-server) gname)))
         (curdir-mtime (nth 5 (file-attributes curdir)))
-        pgname flist always-marks never-marks old-marks dotfile num dir
-        all-marks marks mark ranges markdir read end new-marks ls
-        old-mmth new-mmth mtime mark-sym existing missing deactivate-mark)
+        pgname flist always-marks never-marks old-marks dir
+        all-marks marks ranges markdir read ls
+        old-mmth new-mmth mtime existing missing deactivate-mark)
     (catch 'return
       (unless group
        (setf (nnmaildir--srv-error nnmaildir--cur-server)
@@ -1096,7 +1097,7 @@ by nnmaildir-request-article.")
       (setf (nnmaildir--grp-mmth group) new-mmth)
       info)))
 
-(defun nnmaildir-request-group (gname &optional server fast info)
+(defun nnmaildir-request-group (gname &optional server fast _info)
   (let ((group (nnmaildir--prepare server gname))
        deactivate-mark)
     (catch 'return
@@ -1116,10 +1117,10 @@ by nnmaildir-request-article.")
        (insert " ")
        (princ (nnmaildir--group-maxnum nnmaildir--cur-server group)
               nntp-server-buffer)
-       (insert " " (gnus-replace-in-string gname " " "\\ " t) "\n")
+       (insert " " (replace-regexp-in-string " " "\\ " gname nil t) "\n")
        t))))
 
-(defun nnmaildir-request-create-group (gname &optional server args)
+(defun nnmaildir-request-create-group (gname &optional server _args)
   (nnmaildir--prepare server nil)
   (catch 'return
     (let ((target-prefix (nnmaildir--srv-target-prefix nnmaildir--cur-server))
@@ -1265,7 +1266,7 @@ by nnmaildir-request-article.")
 
 (defun nnmaildir-retrieve-headers (articles &optional gname server fetch-old)
   (let ((group (nnmaildir--prepare server gname))
-       srv-dir dir nlist mlist article num start stop nov nlist2 insert-nov
+       nlist mlist article num start stop nov insert-nov
        deactivate-mark)
     (setq insert-nov
          (lambda (article)
@@ -1278,7 +1279,7 @@ by nnmaildir-request-article.")
              (insert "\t" (nnmaildir--nov-get-beg nov) "\t"
                      (nnmaildir--art-msgid article) "\t"
                      (nnmaildir--nov-get-mid nov) "\tXref: nnmaildir "
-                     (gnus-replace-in-string gname " " "\\ " t) ":")
+                     (replace-regexp-in-string " " "\\ " gname nil t) ":")
              (princ num nntp-server-buffer)
              (insert "\t" (nnmaildir--nov-get-end nov) "\n"))))
     (catch 'return
@@ -1290,9 +1291,7 @@ by nnmaildir-request-article.")
        (erase-buffer)
        (setq mlist (nnmaildir--grp-mlist group)
              nlist (nnmaildir--grp-nlist group)
-             gname (nnmaildir--grp-name group)
-             srv-dir (nnmaildir--srv-dir nnmaildir--cur-server)
-             dir (nnmaildir--srvgrp-dir srv-dir gname))
+             gname (nnmaildir--grp-name group))
        (cond
         ((null nlist))
         ((and fetch-old (not (numberp fetch-old)))
@@ -1363,7 +1362,7 @@ by nnmaildir-request-article.")
        (nnheader-insert-file-contents nnmaildir-article-file-name))
       (cons gname num-msgid))))
 
-(defun nnmaildir-request-post (&optional server)
+(defun nnmaildir-request-post (&optional _server)
   (let (message-required-mail-headers)
     (funcall message-send-mail-function)))
 
@@ -1398,14 +1397,14 @@ by nnmaildir-request-article.")
              (concat "File exists: " tmpfile))
        (throw 'return nil))
       (with-current-buffer buffer
-       (gmm-write-region (point-min) (point-max) tmpfile nil 'no-message nil
-                         'excl))
+       (write-region (point-min) (point-max) tmpfile nil 'no-message nil
+                     'excl))
       (unix-sync) ;; no fsync :(
       (rename-file tmpfile (concat (nnmaildir--cur dir) file suffix) 'replace)
       t)))
 
 (defun nnmaildir-request-move-article (article gname server accept-form
-                                              &optional last move-is-internal)
+                                      &optional _last _move-is-internal)
   (let ((group (nnmaildir--prepare server gname))
        pgname suffix result nnmaildir--file deactivate-mark)
     (catch 'return
@@ -1442,7 +1441,7 @@ by nnmaildir-request-article.")
        (nnmaildir--expired-article group article))
       result)))
 
-(defun nnmaildir-request-accept-article (gname &optional server last)
+(defun nnmaildir-request-accept-article (gname &optional server _last)
   (let ((group (nnmaildir--prepare server gname))
        (coding-system-for-write nnheader-file-coding-system)
        (buffer-file-coding-system nil)
@@ -1492,8 +1491,8 @@ by nnmaildir-request-article.")
                                  (throw 'return nil))))
       (condition-case nil (add-name-to-file nnmaildir--file tmpfile)
        (error
-        (gmm-write-region (point-min) (point-max) tmpfile nil 'no-message nil
-                          'excl)
+        (write-region (point-min) (point-max) tmpfile nil 'no-message nil
+                      'excl)
         (when (fboundp 'unix-sync)
           (unix-sync)))) ;; no fsync :(
       (nnheader-cancel-timer 24h)
@@ -1546,7 +1545,7 @@ by nnmaildir-request-article.")
                    ga))
             group-art)))))
 
-(defun nnmaildir-active-number (gname)
+(defun nnmaildir-active-number (_gname)
   0)
 
 (declare-function gnus-group-mark-article-read "gnus-group" (group article))
@@ -1554,8 +1553,8 @@ by nnmaildir-request-article.")
 (defun nnmaildir-request-expire-articles (ranges &optional gname server force)
   (let ((no-force (not force))
        (group (nnmaildir--prepare server gname))
-       pgname time boundary bound-iter high low target dir nlist nlist2
-       stop article didnt nnmaildir--file nnmaildir-article-file-name
+       pgname time boundary bound-iter high low target dir nlist
+       didnt nnmaildir--file nnmaildir-article-file-name
        deactivate-mark)
     (catch 'return
       (unless group
@@ -1637,6 +1636,8 @@ by nnmaildir-request-article.")
        (erase-buffer))
       didnt)))
 
+(defvar nnmaildir--article)
+
 (defun nnmaildir-request-set-mark (gname actions &optional server)
   (let* ((group (nnmaildir--prepare server gname))
         (curdir (nnmaildir--cur
@@ -1646,27 +1647,30 @@ by nnmaildir-request-article.")
         (coding-system-for-write nnheader-file-coding-system)
         (buffer-file-coding-system nil)
         (file-coding-system-alist nil)
-        del-mark del-action add-action set-action marksdir nlist
-        ranges begin end article all-marks todo-marks mdir mfile
-        pgname ls permarkfile deactivate-mark)
-    (setq del-mark
+        marksdir nlist
+        ranges all-marks todo-marks mdir mfile
+        pgname ls permarkfile deactivate-mark
+        (del-mark
          (lambda (mark)
-           (let ((prefix (nnmaildir--art-prefix article))
-                 (suffix (nnmaildir--art-suffix article))
+           (let ((prefix (nnmaildir--art-prefix nnmaildir--article))
+                 (suffix (nnmaildir--art-suffix nnmaildir--article))
                  (flag (nnmaildir--mark-to-flag mark)))
              (when flag
                ;; If this mark corresponds to a flag, remove the flag from
                ;; the file name.
                (nnmaildir--article-set-flags
-                article (nnmaildir--remove-flag flag suffix) curdir))
+                nnmaildir--article (nnmaildir--remove-flag flag suffix)
+                curdir))
              ;; We still want to delete the hardlink in the marks dir if
              ;; present, regardless of whether this mark has a maildir flag or
              ;; not, to avoid getting out of sync.
              (setq mfile (nnmaildir--subdir marksdir (symbol-name mark))
                    mfile (concat mfile prefix))
-             (nnmaildir--unlink mfile)))
-         del-action (lambda (article) (mapcar del-mark todo-marks))
-         add-action
+             (nnmaildir--unlink mfile))))
+        (del-action (lambda (article)
+                      (let ((nnmaildir--article article))
+                        (mapcar del-mark todo-marks))))
+        (add-action
          (lambda (article)
            (mapcar
             (lambda (mark)
@@ -1695,13 +1699,14 @@ by nnmaildir-request-article.")
                         (rename-file permarkfilenew permarkfile 'replace)
                         (add-name-to-file permarkfile mfile)))
                      (t (signal (car err) (cdr err))))))))
-            todo-marks))
-         set-action (lambda (article)
+            todo-marks)))
+        (set-action (lambda (article)
                       (funcall add-action article)
-                      (mapcar (lambda (mark)
-                                (unless (memq mark todo-marks)
-                                  (funcall del-mark mark)))
-                              all-marks)))
+                      (let ((nnmaildir--article article))
+                        (mapcar (lambda (mark)
+                                  (unless (memq mark todo-marks)
+                                    (funcall del-mark mark)))
+                                all-marks)))))
     (catch 'return
       (unless group
        (setf (nnmaildir--srv-error nnmaildir--cur-server)
@@ -1728,7 +1733,7 @@ by nnmaildir-request-article.")
        (setq ranges (car action)
              todo-marks (caddr action))
        (dolist (mark todo-marks)
-         (add-to-list 'all-marks mark))
+         (pushnew mark all-marks :test #'equal))
        (if (numberp (cdr ranges)) (setq ranges (list ranges)))
        (nnmaildir--nlist-iterate nlist ranges
                                  (cond ((eq 'del (cadr action)) del-action)
@@ -1775,6 +1780,8 @@ by nnmaildir-request-article.")
       t)))
 
 (defun nnmaildir-close-server (&optional server)
+  (defvar flist) (defvar ls) (defvar dirs) (defvar dir)
+  (defvar files) (defvar file) (defvar x)
   (let (flist ls dirs dir files file x)
     (nnmaildir--prepare server nil)
     (when nnmaildir--cur-server