From: yamaoka Date: Mon, 23 Sep 2002 22:24:48 +0000 (+0000) Subject: Synch with Oort Gnus. X-Git-Tag: t-gnus-6_15_8-04-quimby~31 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f713ebc934a19a0edcadcc1e4cde74cb4a091fc6;p=elisp%2Fgnus.git- Synch with Oort Gnus. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5f961e3..12554b1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,31 @@ +2002-09-23 Kai Gro,b_(Bjohann + + * gnus-art.el (gnus-button-guessed-mid-regexp): Improved regexp. + (gnus-button-alist): Improved regexp for + gnus-button-handle-mid-or-mail (false positives), fixed + gnus-button-handle-man entries. + From Reiner Steib. + +2002-09-23 Paul Jarc + From Josh Huber. + + * nnmaildir.el (nnmaildir--update-nov): fix wrong-type error when + nnmail-extra-headers is non-nil. + +2002-09-23 Paul Jarc + + * nnmaildir.el: Store article numbers persistently. General + revision. + (nnmaildir-request-expire-articles): handle 'immediate and 'never + for nnmail-expiry-wait; delete instead of moving if 'force is + given. + +2002-09-23 Simon Josefsson + Trivial fix from beaker@iavmb.pl (Krzysztof J,Bj(Bdruczyk). + + * smime.el (smime-sign-buffer): Get key and extra certs. + (smime-get-key-with-certs-by-email): Utility function. + 2002-09-21 ShengHuo ZHU Trivial patch from Micha Wiedenmann diff --git a/lisp/gnus-art.el b/lisp/gnus-art.el index a226dfd..72dabcc 100644 --- a/lisp/gnus-art.el +++ b/lisp/gnus-art.el @@ -5791,8 +5791,9 @@ guessing." (const mail))) (defcustom gnus-button-guessed-mid-regexp - (concat "^= gnus-button-man-level 1) + ("\\b\\([a-z][a-z]+\\)([0-9])\\W" 0 + (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3)) gnus-button-handle-man 1) ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x) - ("\\b\\([a-zA-Z][-_.a-zA-Z0-9]+\\)([0-9]x?)\\W" 0 - (>= gnus-button-man-level 3) gnus-button-handle-man 3) + ("\\b\\([a-zA-Z][-_.a-zA-Z0-9]+\\)([0-9])\\W" 0 + (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5)) + gnus-button-handle-man 1) ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm), SoWWWAnchor(3iv) ("\\b\\([a-zA-Z][-_.:a-zA-Z0-9]+\\)([0-9][a-z]*)\\W" 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1) @@ -5943,7 +5946,7 @@ positves are possible." ;; at least one dot. TLD must contain two or three chars or be a know TLD ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist' ;; so that non-ambiguous entries (see above) match first. - ("\\b\\()!;:,{}\n\t ]*@[a-zA-Z0-9][-.a-zA-Z0-9]+\\.\\([a-zA-Z][a-zA-Z]\\([a-zA-Z]\\)?\\|[Ii][Nn][Ff][Oo]\\|[Nn][Aa][Mm][Ee]\\)>?\\)\\b" + ("\\b\\(\")!;:,{}\n\t ]*@[a-zA-Z0-9][-.a-zA-Z0-9]+\\.\\([a-zA-Z][a-zA-Z]\\([a-zA-Z]\\)?\\|[Ii][Nn][Ff][Oo]\\|[Nn][Aa][Mm][Ee]\\)>?\\)\\b" 0 (>= gnus-button-mail-level 5) gnus-button-handle-mid-or-mail 1)) "*Alist of regexps matching buttons in article bodies. diff --git a/lisp/nnmaildir.el b/lisp/nnmaildir.el index e9d5ef5..98faa57 100644 --- a/lisp/nnmaildir.el +++ b/lisp/nnmaildir.el @@ -22,31 +22,47 @@ ;;; Commentary: -;; Maildir format is documented in the maildir(5) man page from qmail -;; (available at ) and at -;; . nnmaildir also stores +;; Maildir format is documented at +;; and in the maildir(5) man page from qmail (available at +;; ). nnmaildir also stores ;; extra information in the .nnmaildir/ directory within a maildir. ;; ;; Some goals of nnmaildir: -;; * Everything Just Works, and correctly. E.g., stale NOV data is -;; ignored; no need for -generate-nov-databases. -;; * Perfect reliability: [C-g] will never corrupt its data in memory, -;; and SIGKILL will never corrupt its data in the filesystem. +;; * Everything Just Works, and correctly. E.g., NOV data is automatically +;; regenerated when stale; no need for manually running +;; *-generate-nov-databases. +;; * Perfect reliability: [C-g] will never corrupt its data in memory, and +;; SIGKILL will never corrupt its data in the filesystem. +;; * Allow concurrent operation as much as possible. If files change out +;; from under us, adapt to the changes or degrade gracefully. ;; * We use the filesystem as a database, so that, e.g., it's easy to ;; manipulate marks from outside Gnus. -;; * All information about a group is stored in the maildir, for easy -;; backup, copying, restoring, etc. +;; * All information about a group is stored in the maildir, for easy backup, +;; copying, restoring, etc. ;; ;; Todo: -;; * Don't force article renumbering, so nnmaildir can be used with -;; the cache and agent. Alternatively, completely rewrite the Gnus -;; backend interface, which would have other advantages as well. -;; -;; See also until that -;; information is added to the Gnus manual. +;; * Merge the information from +;; into the Gnus manual. +;; * Allow create-directory = ".", and configurable prefix of maildir names, +;; stripped off to produce group names. +;; * Add a hook for when moving messages from new/ to cur/, to support +;; nnmail's duplicate detection. +;; * Allow each mark directory in a group to have its own inode for mark +;; files, to accommodate AFS. +;; * Improve generated Xrefs, so crossposts are detectable. +;; * Improve readability. ;;; Code: +;; eval this before editing +[(progn + (put 'nnmaildir--with-nntp-buffer 'lisp-indent-function 0) + (put 'nnmaildir--with-work-buffer 'lisp-indent-function 0) + (put 'nnmaildir--with-nov-buffer 'lisp-indent-function 0) + (put 'nnmaildir--with-move-buffer 'lisp-indent-function 0) + ) +] + (eval-and-compile (require 'nnheader) (require 'gnus) @@ -82,7 +98,7 @@ by nnmaildir-request-article.") ;; A copy of nnmail-extra-headers (defvar nnmaildir--extra nil) -;; A disk NOV structure (must be prin1-able, so no defstruct) looks like this: +;; A NOV structure looks like this (must be prin1-able, so no defstruct): ["subject\tfrom\tdate" "references\tchars\lines" "To: you\tIn-Reply-To: " @@ -109,19 +125,19 @@ by nnmaildir-request-article.") (msgid nil :type string) ;; "" (nov nil :type vector)) ;; cached nov structure, or nil -(defstruct nnmaildir--lists +(defstruct nnmaildir--grp + (name nil :type string) ;; "group.name" + (new nil :type list) ;; new/ modtime + (cur nil :type list) ;; cur/ modtime + (min 1 :type natnum) ;; minimum article number + (count 0 :type natnum) ;; count of articles (nlist nil :type list) ;; list of articles, ordered descending by number (flist nil :type vector) ;; obarray mapping filename prefix->article - (mlist nil :type vector)) ;; obarray mapping message-id->article - -(defstruct nnmaildir--grp - (name nil :type string) ;; "group.name" - (new nil :type list) ;; new/ modtime - (cur nil :type list) ;; cur/ modtime - (lists nil :type nnmaildir--lists) ;; lists of articles in this group - (cache nil :type vector) ;; nov cache - (index nil :type natnum) ;; index of next cache entry to replace - (mmth nil :type vector)) ;; obarray mapping mark name->dir modtime + (mlist nil :type vector) ;; obarray mapping message-id->article + (cache nil :type vector) ;; nov cache + (index nil :type natnum) ;; index of next cache entry to replace + (mmth nil :type vector)) ;; obarray mapping mark name->dir modtime + ; ("Mark Mod Time Hash") (defstruct nnmaildir--srv (address nil :type string) ;; server address string @@ -136,13 +152,43 @@ by nnmaildir-request-article.") (gnm nil) ;; flag: split from mail-sources? (create-dir nil :type string)) ;; group creation directory -(defmacro nnmaildir--nlist-last-num (nlist) - `(let ((nlist ,nlist)) - (if nlist (nnmaildir--art-num (car nlist)) 0))) -(defmacro nnmaildir--nlist-art (nlist num) ;;;; evals args multiple times - `(and ,nlist - (>= (nnmaildir--art-num (car ,nlist)) ,num) - (nth (- (nnmaildir--art-num (car ,nlist)) ,num) ,nlist))) +(defun nnmaildir--expired-article (group article) + (setf (nnmaildir--art-nov article) nil) + (let ((flist (nnmaildir--grp-flist group)) + (mlist (nnmaildir--grp-mlist group)) + (min (nnmaildir--grp-min group)) + (count (1- (nnmaildir--grp-count group))) + (prefix (nnmaildir--art-prefix article)) + (msgid (nnmaildir--art-msgid article)) + (new-nlist nil) + (nlist-pre '(nil . nil)) + nlist-post num) + (unless (zerop count) + (setq nlist-post (nnmaildir--grp-nlist group) + num (nnmaildir--art-num article)) + (if (eq num (caar nlist-post)) + (setq new-nlist (cdr nlist-post)) + (setq new-nlist nlist-post + nlist-pre nlist-post + nlist-post (cdr nlist-post)) + (while (/= num (caar nlist-post)) + (setq nlist-pre nlist-post + nlist-post (cdr nlist-post))) + (setq nlist-post (cdr nlist-post)) + (if (eq num min) + (setq min (caar nlist-pre))))) + (let ((inhibit-quit t)) + (setf (nnmaildir--grp-min group) min) + (setf (nnmaildir--grp-count group) count) + (setf (nnmaildir--grp-nlist group) new-nlist) + (setcdr nlist-pre nlist-post) + (unintern prefix flist) + (unintern msgid mlist)))) + +(defun nnmaildir--nlist-art (group num) + (let ((entry (assq num (nnmaildir--grp-nlist group)))) + (if entry + (cdr entry)))) (defmacro nnmaildir--flist-art (list file) `(symbol-value (intern-soft ,file ,list))) (defmacro nnmaildir--mlist-art (list msgid) @@ -157,8 +203,8 @@ by nnmaildir-request-article.") gname))) (defun nnmaildir--param (pgname param) - (setq param (gnus-group-find-parameter pgname param 'allow-list) - param (if (vectorp param) (aref param 0) param)) + (setq param (gnus-group-find-parameter pgname param 'allow-list)) + (if (vectorp param) (setq param (aref param 0))) (eval param)) (defmacro nnmaildir--with-nntp-buffer (&rest body) @@ -188,6 +234,8 @@ by nnmaildir-request-article.") (defmacro nnmaildir--nndir (dir) `(nnmaildir--subdir ,dir ".nnmaildir")) (defmacro nnmaildir--nov-dir (dir) `(nnmaildir--subdir ,dir "nov")) (defmacro nnmaildir--marks-dir (dir) `(nnmaildir--subdir ,dir "marks")) +(defmacro nnmaildir--num-dir (dir) `(nnmaildir--subdir ,dir "num")) +(defmacro nnmaildir--num-file (dir) `(concat ,dir ":")) (defmacro nnmaildir--unlink (file-arg) `(let ((file ,file-arg)) @@ -195,98 +243,120 @@ by nnmaildir-request-article.") (defun nnmaildir--mkdir (dir) (or (file-exists-p (file-name-as-directory dir)) (make-directory-internal (directory-file-name dir)))) - +(defun nnmaildir--delete-dir-files (dir ls) + (mapcar 'delete-file (funcall ls dir 'full "\\`[^.]" 'nosort)) + (delete-directory dir)) + +(defun nnmaildir--group-maxnum (server group) + (let ((x (nnmaildir--srvgrp-dir (nnmaildir--srv-dir server) + (nnmaildir--grp-name group)))) + (setq x (nnmaildir--nndir x) + x (nnmaildir--num-dir x) + x (nnmaildir--num-file x) + x (file-attributes x)) + (if x (1- (nth 1 x)) 0))) + +;; Make the given server, if non-nil, be the current server. Then make the +;; 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) - (or (setq server nnmaildir--cur-server) - (throw 'return nil)) - (or (setq server (intern-soft server nnmaildir--servers)) + (unless (setq server nnmaildir--cur-server) (throw 'return nil)) + (unless (setq server (intern-soft server nnmaildir--servers)) + (throw 'return nil)) (setq server (symbol-value server) nnmaildir--cur-server server)) - (or (setq groups (nnmaildir--srv-groups server)) - (throw 'return nil)) - (if (nnmaildir--srv-method server) nil + (unless (setq groups (nnmaildir--srv-groups server)) + (throw 'return nil)) + (unless (nnmaildir--srv-method server) (setq x (concat "nnmaildir:" (nnmaildir--srv-address server)) x (gnus-server-to-method x)) - (or x (throw 'return nil)) + (unless x (throw 'return nil)) (setf (nnmaildir--srv-method server) x)) (if (null group) - (or (setq group (nnmaildir--srv-curgrp server)) - (throw 'return nil)) - (or (setq group (intern-soft group groups)) - (throw 'return nil)) + (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))) +(defun nnmaildir--tab-to-space (string) + (let ((pos 0)) + (while (string-match "\t" string pos) + (aset string (match-beginning 0) ? ) + (setq pos (match-end 0)))) + string) + (defun nnmaildir--update-nov (server group article) (let ((nnheader-file-coding-system 'binary) (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 pos extra val old-extra - new-extra deactivate-mark) + nov msgid nov-beg nov-mid nov-end field val old-extra num numdir + deactivate-mark) (catch 'return - (setq suffix (nnmaildir--art-suffix article)) - (if (stringp suffix) nil - (setf (nnmaildir--art-nov article) nil) - (throw 'return nil)) (setq gname (nnmaildir--grp-name group) pgname (nnmaildir--pgname server gname) dir (nnmaildir--srvgrp-dir srv-dir gname) msgdir (if (nnmaildir--param pgname 'read-only) (nnmaildir--new dir) (nnmaildir--cur dir)) prefix (nnmaildir--art-prefix article) + suffix (nnmaildir--art-suffix article) file (concat msgdir prefix suffix) attr (file-attributes file)) - (if attr nil - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil) + (unless attr + (nnmaildir--expired-article group article) (throw 'return nil)) (setq mtime (nth 5 attr) attr (nth 7 attr) nov (nnmaildir--art-nov article) - novdir (nnmaildir--nov-dir (nnmaildir--nndir dir)) + dir (nnmaildir--nndir dir) + novdir (nnmaildir--nov-dir dir) novfile (concat novdir prefix)) - (or (equal nnmaildir--extra nnmail-extra-headers) - (setq nnmaildir--extra (copy-sequence nnmail-extra-headers))) + (unless (equal nnmaildir--extra nnmail-extra-headers) + (setq nnmaildir--extra (copy-sequence nnmail-extra-headers))) (nnmaildir--with-nov-buffer - (when (file-exists-p novfile) ;; If not, force reparsing the message. - (if nov nil ;; It's already in memory. - ;; Else read the data from the NOV file. - (erase-buffer) - (nnheader-insert-file-contents novfile) - (setq nov (read (current-buffer))) - (setf (nnmaildir--art-msgid article) (car nov)) - (setq nov (cadr nov))) - ;; If the NOV's modtime matches the file's current modtime, and it - ;; has the right structure (i.e., it wasn't produced by a too-much - ;; older version of nnmaildir), then we may use this NOV data - ;; rather than parsing the message file, unless - ;; nnmail-extra-headers has been augmented since this data was last - ;; parsed. - (when (and (equal mtime (nnmaildir--nov-get-mtime nov)) - (= (length nov) nnmaildir--novlen) - (stringp (nnmaildir--nov-get-beg nov)) - (stringp (nnmaildir--nov-get-mid nov)) - (stringp (nnmaildir--nov-get-end nov)) - (listp (nnmaildir--nov-get-mtime nov)) - (listp (nnmaildir--nov-get-extra nov))) - ;; this NOV data is potentially up-to-date; now check extra headers - (setq old-extra (nnmaildir--nov-get-extra nov)) - (when (equal nnmaildir--extra old-extra) ;; common case - (nnmaildir--nov-set-extra nov nnmaildir--extra) ;; save memory + ;; First we'll check for already-parsed NOV data. + (cond ((not (file-exists-p novfile)) + ;; The NOV file doesn't exist; we have to parse the message. + (setq nov nil)) + ((not nov) + ;; The file exists, but the data isn't in memory; read the file. + (erase-buffer) + (nnheader-insert-file-contents novfile) + (setq nov (read (current-buffer))) + (if (not (and (vectorp nov) + (/= 0 (length nov)) + (equal storage-version (aref nov 0)))) + ;; This NOV data seems to be in the wrong format. + (setq nov nil) + (unless (nnmaildir--art-num article) + (setf (nnmaildir--art-num article) (aref nov 1))) + (unless (nnmaildir--art-msgid article) + (setf (nnmaildir--art-msgid article) (aref nov 2))) + (setq nov (aref nov 3))))) + ;; Now check whether the already-parsed data (if we have any) is + ;; usable: if the message has been edited or if nnmail-extra-headers + ;; has been augmented since this data was parsed from the message, + ;; then we have to reparse. Otherwise it's up-to-date. + (when (and nov (equal mtime (nnmaildir--nov-get-mtime nov))) + ;; The timestamp matches. Now check nnmail-extra-headers. + (setq old-extra (nnmaildir--nov-get-extra nov)) + (when (equal nnmaildir--extra old-extra) ;; common case + ;; Save memory; use a single copy of the list value. + (nnmaildir--nov-set-extra nov nnmaildir--extra) + (throw 'return nov)) + ;; They're not equal, but maybe the new is a subset of the old. + (if (null nnmaildir--extra) + ;; The empty set is a subset of every set. (throw 'return nov)) - ;; They're not equal, but maybe the new is a subset of the old... - (if (null nnmaildir--extra) (throw 'return nov)) - (setq new-extra nnmaildir--extra) - (while new-extra - (if (memq (car new-extra) old-extra) - (progn - (setq new-extra (cdr new-extra)) - (if new-extra nil (throw 'return nov))) - (setq new-extra nil))))) ;;found one not in old-extra;quit loop + (if (not (memq nil (mapcar (lambda (e) (memq e old-extra)) + nnmaildir--extra))) + (throw 'return nov))) ;; Parse the NOV data out of the message. (erase-buffer) (nnheader-insert-file-contents file) @@ -303,65 +373,67 @@ by nnmaildir-request-article.") (nnheader-fold-continuation-lines) (setq nov (nnheader-parse-head 'naked) field (or (mail-header-lines nov) 0))) - (if (or (zerop field) (nnmaildir--param pgname 'distrust-Lines:)) nil + (unless (or (zerop field) (nnmaildir--param pgname 'distrust-Lines:)) (setq nov-mid field)) (setq nov-mid (number-to-string nov-mid) - nov-mid (concat (number-to-string attr) "\t" nov-mid) - field (or (mail-header-references nov) "") - pos 0) + nov-mid (concat (number-to-string attr) "\t" nov-mid)) (save-match-data - (while (string-match "\t" field pos) - (aset field (match-beginning 0) ? ) - (setq pos (match-end 0))) + (setq field (or (mail-header-references nov) "")) + (nnmaildir--tab-to-space field) (setq nov-mid (concat field "\t" nov-mid) - extra (mail-header-extra nov) - nov-end "") - (while extra - (setq field (car extra) extra (cdr extra) - val (cdr field) field (symbol-name (car field)) - pos 0) - (while (string-match "\t" field pos) - (aset field (match-beginning 0) ? ) - (setq pos (match-end 0))) - (setq pos 0) - (while (string-match "\t" val pos) - (aset val (match-beginning 0) ? ) - (setq pos (match-end 0))) - (setq nov-end (concat nov-end "\t" field ": " val))) - (setq nov-end (if (zerop (length nov-end)) "" (substring nov-end 1)) - field (or (mail-header-subject nov) "") - pos 0) - (while (string-match "\t" field pos) - (aset field (match-beginning 0) ? ) - (setq pos (match-end 0))) - (setq nov-beg field - field (or (mail-header-from nov) "") - pos 0) - (while (string-match "\t" field pos) - (aset field (match-beginning 0) ? ) - (setq pos (match-end 0))) - (setq nov-beg (concat nov-beg "\t" field) - field (or (mail-header-date nov) "") - pos 0) - (while (string-match "\t" field pos) - (aset field (match-beginning 0) ? ) - (setq pos (match-end 0))) - (setq nov-beg (concat nov-beg "\t" field) - field (mail-header-id nov) - pos 0) - (while (string-match "\t" field pos) - (aset field (match-beginning 0) ? ) - (setq pos (match-end 0))) - (setq msgid field)) + nov-beg (mapconcat + (lambda (f) (nnmaildir--tab-to-space (or f ""))) + (list (mail-header-subject nov) + (mail-header-from nov) + (mail-header-date nov)) "\t") + nov-end (mapconcat + (lambda (extra) + (setq field (symbol-name (car extra)) + val (cdr extra)) + (nnmaildir--tab-to-space field) + (nnmaildir--tab-to-space val) + (concat field ": " val)) + (mail-header-extra nov) "\t"))) + (setq msgid (mail-header-id nov)) (if (or (null msgid) (nnheader-fake-message-id-p msgid)) (setq msgid (concat "<" prefix "@nnmaildir>"))) + (nnmaildir--tab-to-space msgid) + ;; The data is parsed; create an nnmaildir NOV structure. (setq nov (nnmaildir--nov-new nov-beg nov-mid nov-end mtime - nnmaildir--extra)) + nnmaildir--extra) + num (nnmaildir--art-num article)) + (unless num + ;; Allocate a new article number. + (erase-buffer) + (setq numdir (nnmaildir--num-dir dir) + file (nnmaildir--num-file numdir) + num -1) + (nnmaildir--mkdir numdir) + (write-region "" nil file nil 'no-message) + (while file + ;; Get the number of links to file. + (setq attr (nth 1 (file-attributes file))) + (if (= attr num) + ;; We've already tried this number, in the previous loop + ;; iteration, and failed. + (signal 'error `("Corrupt internal nnmaildir data" ,numdir))) + ;; If attr is 123, try to link file to "123". This atomically + ;; increases the link count and creates the "123" link, failing + ;; if that link was already created by another Gnus, just after + ;; we stat()ed file. + (condition-case nil + (progn + (add-name-to-file file (concat numdir (format "%x" attr))) + (setq file nil)) ;; Stop looping. + (file-already-exists nil)) + (setq num attr)) + (setf (nnmaildir--art-num article) num)) + ;; Store this new NOV data in a file (erase-buffer) - (prin1 (list msgid nov) (current-buffer)) + (prin1 (vector storage-version num msgid nov) (current-buffer)) (setq file (concat novfile ":")) (nnmaildir--unlink file) - (write-region (point-min) (point-max) file nil 'no-message)) + (write-region (point-min) (point-max) file nil 'no-message nil 'excl)) (rename-file file novfile 'replace) (setf (nnmaildir--art-msgid article) msgid) nov))) @@ -370,7 +442,7 @@ by nnmaildir-request-article.") (let ((cache (nnmaildir--grp-cache group)) (index (nnmaildir--grp-index group)) goner) - (if (nnmaildir--art-nov article) nil + (unless (nnmaildir--art-nov article) (setq goner (aref cache index)) (if goner (setf (nnmaildir--art-nov goner) nil)) (aset cache index article) @@ -379,20 +451,35 @@ by nnmaildir-request-article.") (defun nnmaildir--grp-add-art (server group article) (let ((nov (nnmaildir--update-nov server group article)) - old-lists new-lists) + count num min nlist nlist-cdr insert-nlist) (when nov - (setq old-lists (nnmaildir--grp-lists group) - new-lists (copy-nnmaildir--lists old-lists)) - (setf (nnmaildir--lists-nlist new-lists) - (cons article (nnmaildir--lists-nlist new-lists))) + (setq count (1+ (nnmaildir--grp-count group)) + min (nnmaildir--grp-min group) + num (nnmaildir--art-num article)) + (setq min (min min num)) + (setq nlist (nnmaildir--grp-nlist group)) + (if (or (null nlist) (> num (caar nlist))) + (setq nlist (cons (cons num article) nlist)) + (setq insert-nlist t + nlist-cdr (cdr nlist)) + (while (< num (caar nlist-cdr)) + (setq nlist nlist-cdr + nlist-cdr (cdr nlist)))) (let ((inhibit-quit t)) - (setf (nnmaildir--grp-lists group) new-lists) - (set (intern (nnmaildir--art-prefix article) - (nnmaildir--lists-flist new-lists)) - article) - (set (intern (nnmaildir--art-msgid article) - (nnmaildir--lists-mlist new-lists)) - article)) + (setf (nnmaildir--grp-count group) count) + (setf (nnmaildir--grp-min group) min) + (if insert-nlist + (setcdr nlist (cons (cons num article) nlist-cdr)) + (setf (nnmaildir--grp-nlist group) nlist)) + (set (intern (nnmaildir--art-prefix article) + (nnmaildir--grp-flist group)) + article) + (set (intern (nnmaildir--art-msgid article) + (nnmaildir--grp-mlist group)) + article) + (set (intern (nnmaildir--grp-name group) + (nnmaildir--srv-groups server)) + group)) (nnmaildir--cache-nov group article nov) t))) @@ -400,84 +487,68 @@ by nnmaildir-request-article.") (or (nnmaildir--param pgname 'directory-files) (nnmaildir--srv-ls server))) -(defun nnmaildir--article-count (group) - (let ((ct 0) - (min 1)) - (setq group (nnmaildir--grp-lists group) - group (nnmaildir--lists-nlist group)) - (while group - (if (stringp (nnmaildir--art-suffix (car group))) - (setq ct (1+ ct) - min (nnmaildir--art-num (car group)))) - (setq group (cdr group))) - (cons ct min))) - (defun nnmaildir-article-number-to-file-name (number group-name server-address-string) (let ((group (nnmaildir--prepare server-address-string group-name)) - list article suffix dir filename pgname) + article dir pgname) (catch 'return - (if (null group) - ;; The given group or server does not exist. - (throw 'return nil)) - (setq list (nnmaildir--grp-lists group) - list (nnmaildir--lists-nlist list) - article (nnmaildir--nlist-art list number)) - (if (null article) - ;; The given article number does not exist in this group. - (throw 'return nil)) - (setq suffix (nnmaildir--art-suffix article)) - (if (not (stringp suffix)) - ;; The article has expired. - (throw 'return nil)) - (setq dir (nnmaildir--srv-dir nnmaildir--cur-server) + (unless group + ;; The given group or server does not exist. + (throw 'return nil)) + (setq article (nnmaildir--nlist-art group number)) + (unless article + ;; The given article number does not exist in this group. + (throw 'return nil)) + (setq pgname (nnmaildir--pgname nnmaildir--cur-server group-name) + dir (nnmaildir--srv-dir nnmaildir--cur-server) dir (nnmaildir--srvgrp-dir dir group-name) - pgname (nnmaildir--pgname nnmaildir--cur-server group-name) - group (if (nnmaildir--param pgname 'read-only) - (nnmaildir--new dir) (nnmaildir--cur dir)) - filename (concat group (nnmaildir--art-prefix article) suffix)) - (if (file-exists-p filename) - filename - ;; The article disappeared out from under us. - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil) - nil)))) + dir (if (nnmaildir--param pgname 'read-only) + (nnmaildir--new dir) (nnmaildir--cur dir))) + (concat dir (nnmaildir--art-prefix article) + (nnmaildir--art-suffix article))))) (defun nnmaildir-article-number-to-base-name (number group-name server-address-string) - (let ((group (nnmaildir--prepare server-address-string group-name)) - list article suffix dir filename) - (catch 'return - (if (null group) - ;; The given group or server does not exist. - (throw 'return nil)) - (setq list (nnmaildir--grp-lists group) - list (nnmaildir--lists-nlist list) - article (nnmaildir--nlist-art list number)) - (if (null article) - ;; The given article number does not exist in this group. - (throw 'return nil)) - (setq suffix (nnmaildir--art-suffix article)) - (if (not (stringp suffix)) - ;; The article has expired. - (throw 'return nil)) - (cons (nnmaildir--art-prefix article) suffix)))) + (let ((x (nnmaildir--prepare server-address-string group-name))) + (when x + (setq x (nnmaildir--nlist-art x number)) + (and x (cons (nnmaildir--art-prefix x) + (nnmaildir--art-suffix x)))))) (defun nnmaildir-base-name-to-article-number (base-name group-name server-address-string) - (let ((group (nnmaildir--prepare server-address-string group-name)) - list article suffix dir filename) - (catch 'return - (if (null group) - ;; The given group or server does not exist. - (throw 'return nil)) - (setq list (nnmaildir--grp-lists group) - list (nnmaildir--lists-flist list) - article (nnmaildir--flist-art list base-name)) - (if (null article) - ;; The given article number does not exist in this group. - (throw 'return nil)) - (nnmaildir--art-num article)))) + (let ((x (nnmaildir--prepare server-address-string group-name))) + (when x + (setq x (nnmaildir--grp-flist x) + x (nnmaildir--flist-art x base-name)) + (and x (nnmaildir--art-num x))))) + +(defun nnmaildir--nlist-iterate (nlist ranges func) + (let (entry high low nlist2) + (if (eq ranges 'all) + (setq ranges `((1 . ,(caar nlist))))) + (while ranges + (setq entry (car ranges) ranges (cdr ranges)) + (while (and ranges (eq entry (car ranges))) + (setq ranges (cdr ranges))) ;; skip duplicates + (if (numberp entry) + (setq low entry + high entry) + (setq low (car entry) + high (cdr entry))) + (setq nlist2 nlist) ;; Don't assume any sorting of ranges + (catch 'iterate-loop + (while nlist2 + (if (<= (caar nlist2) high) (throw 'iterate-loop nil)) + (setq nlist2 (cdr nlist2)))) + (catch 'iterate-loop + (while nlist2 + (setq entry (car nlist2) nlist2 (cdr nlist2)) + (if (< (car entry) low) (throw 'iterate-loop nil)) + (funcall func (cdr entry))))))) + +(defun nnmaildir--up2-1 (n) + (if (zerop n) 1 (1- (lsh 1 (1+ (logb n)))))) (defun nnmaildir-request-type (group &optional article) 'mail) @@ -505,10 +576,10 @@ by nnmaildir-request-article.") (setq nnmaildir--cur-server server) (throw 'return t)) (setq server (make-nnmaildir--srv :address x)) - (let ((inhibit-quit t)) - (set (intern x nnmaildir--servers) server))) + (let ((inhibit-quit t)) + (set (intern x nnmaildir--servers) server))) (setq dir (assq 'directory defs)) - (if dir nil + (unless dir (setf (nnmaildir--srv-error server) "You must set \"directory\" in the select method") (throw 'return nil)) @@ -516,26 +587,22 @@ by nnmaildir-request-article.") dir (eval dir) dir (expand-file-name dir) dir (file-name-as-directory dir)) - (if (file-exists-p dir) nil + (unless (file-exists-p dir) (setf (nnmaildir--srv-error server) (concat "No such directory: " dir)) (throw 'return nil)) (setf (nnmaildir--srv-dir server) dir) (setq x (assq 'directory-files defs)) (if (null x) - (setq x (symbol-function (if nnheader-directory-files-is-safe - 'directory-files - 'nnheader-directory-files-safe))) + (setq x (if nnheader-directory-files-is-safe 'directory-files + 'nnheader-directory-files-safe)) (setq x (cadr x)) - (if (functionp x) nil + (unless (functionp x) (setf (nnmaildir--srv-error server) (concat "Not a function: " (prin1-to-string x))) (throw 'return nil))) (setf (nnmaildir--srv-ls server) x) - (setq x (funcall x dir nil "\\`[^.]" 'nosort) - x (length x) - size 1) - (while (<= size x) (setq size (* 2 size))) - (if (/= size 1) (setq size (1- size))) + (setq size (length (funcall x dir nil "\\`[^.]" 'nosort)) + size (nnmaildir--up2-1 size)) (and (setq x (assq 'get-new-mail defs)) (setq x (cdr x)) (car x) @@ -586,10 +653,10 @@ by nnmaildir-request-article.") (catch 'return (let ((36h-ago (- (car (current-time)) 2)) absdir nndir tdir ndir cdir nattr cattr isnew pgname read-only ls - files file num dir flist group x) + files num dir flist group x) (setq absdir (nnmaildir--srvgrp-dir srv-dir gname) nndir (nnmaildir--nndir absdir)) - (if (file-exists-p absdir) nil + (unless (file-exists-p absdir) (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such directory: " absdir)) (throw 'return nil)) @@ -598,7 +665,7 @@ by nnmaildir-request-article.") cdir (nnmaildir--cur absdir) nattr (file-attributes ndir) cattr (file-attributes cdir)) - (if (and (file-exists-p tdir) nattr cattr) nil + (unless (and (file-exists-p tdir) nattr cattr) (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "Not a maildir: " absdir)) (throw 'return nil)) @@ -607,26 +674,25 @@ by nnmaildir-request-article.") (if group (setq isnew nil) (setq isnew t - group (make-nnmaildir--grp :name gname :index 0 - :lists (make-nnmaildir--lists))) + group (make-nnmaildir--grp :name gname :index 0)) (nnmaildir--mkdir nndir) (nnmaildir--mkdir (nnmaildir--nov-dir nndir)) (nnmaildir--mkdir (nnmaildir--marks-dir nndir)) (write-region "" nil (concat nndir "markfile") nil 'no-message)) (setq read-only (nnmaildir--param pgname 'read-only) ls (or (nnmaildir--param pgname 'directory-files) srv-ls)) - (if read-only nil + (unless read-only (setq x (nth 11 (file-attributes tdir))) - (if (and (= x (nth 11 nattr)) (= x (nth 11 cattr))) nil + (unless (and (= x (nth 11 nattr)) (= x (nth 11 cattr))) (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "Maildir spans filesystems: " absdir)) (throw 'return nil)) - (setq files (funcall ls tdir 'full "\\`[^.]" 'nosort)) - (while files - (setq file (car files) files (cdr files) - x (file-attributes file)) - (if (or (< 1 (cadr x)) (> 36h-ago (car (nth 4 x)))) - (delete-file file)))) + (mapcar + (lambda (file) + (setq x (file-attributes file)) + (if (or (> (cadr x) 1) (< (car (nth 4 x)) 36h-ago)) + (delete-file file))) + (funcall ls tdir 'full "\\`[^.]" 'nosort))) (or scan-msgs isnew (throw 'return t)) @@ -635,65 +701,60 @@ by nnmaildir-request-article.") (setq nattr nil)) (if read-only (setq dir (and (or isnew nattr) ndir)) (when (or isnew nattr) - (setq files (funcall ls ndir nil "\\`[^.]" 'nosort)) - (while files - (setq file (car files) files (cdr files)) - (rename-file (concat ndir file) (concat cdir file ":2,"))) + (mapcar + (lambda (file) + (rename-file (concat ndir file) (concat cdir file ":2,"))) + (funcall ls ndir nil "\\`[^.]" 'nosort)) (setf (nnmaildir--grp-new group) nattr)) (setq cattr (nth 5 (file-attributes cdir))) (if (equal cattr (nnmaildir--grp-cur group)) (setq cattr nil)) (setq dir (and (or isnew cattr) cdir))) - (if dir nil (throw 'return t)) - (setq files (funcall ls dir nil "\\`[^.]" 'nosort)) + (unless dir (throw 'return t)) + (setq files (funcall ls dir nil "\\`[^.]" 'nosort) + files (save-match-data + (mapcar + (lambda (f) + (string-match "\\`\\([^:]*\\)\\(\\(:.*\\)?\\)\\'" f) + (cons (match-string 1 f) (match-string 2 f))) + files))) (when isnew - (setq x (length files) - num 1) - (while (<= num x) (setq num (* 2 num))) - (if (/= num 1) (setq num (1- num))) - (setq x (nnmaildir--grp-lists group)) - (setf (nnmaildir--lists-flist x) (make-vector num 0)) - (setf (nnmaildir--lists-mlist x) (make-vector num 0)) + (setq num (nnmaildir--up2-1 (length files))) + (setf (nnmaildir--grp-flist group) (make-vector num 0)) + (setf (nnmaildir--grp-mlist group) (make-vector num 0)) (setf (nnmaildir--grp-mmth group) (make-vector 1 0)) (setq num (nnmaildir--param pgname 'nov-cache-size)) (if (numberp num) (if (< num 1) (setq num 1)) - (setq x files - num 16 + (setq num 16 cdir (nnmaildir--marks-dir nndir) ndir (nnmaildir--subdir cdir "tick") cdir (nnmaildir--subdir cdir "read")) - (while x - (setq file (car x) x (cdr x)) - (string-match "\\`\\([^:]*\\)\\(\\(:.*\\)?\\)\\'" file) - (setq file (match-string 1 file)) - (if (or (not (file-exists-p (concat cdir file))) - (file-exists-p (concat ndir file))) - (setq num (1+ num))))) + (mapcar + (lambda (file) + (setq file (car file)) + (if (or (not (file-exists-p (concat cdir file))) + (file-exists-p (concat ndir file))) + (setq num (1+ num)))) + files)) (setf (nnmaildir--grp-cache group) (make-vector num nil)) (let ((inhibit-quit t)) (set (intern gname groups) group)) (or scan-msgs (throw 'return t))) - (setq flist (nnmaildir--grp-lists group) - num (nnmaildir--lists-nlist flist) - flist (nnmaildir--lists-flist flist) - num (nnmaildir--nlist-last-num num) - x files - files nil) - (while x - (setq file (car x) x (cdr x)) - (string-match "\\`\\([^:]*\\)\\(\\(:.*\\)?\\)\\'" file) - (setq file (cons (match-string 1 file) (match-string 2 file))) - (if (nnmaildir--flist-art flist (car file)) nil - (setq files (cons file files)))) - (setq files (mapcar 'nnmaildir--parse-filename files) + (setq flist (nnmaildir--grp-flist group) + files (mapcar + (lambda (file) + (and (null (nnmaildir--flist-art flist (car file))) + file)) + files) + files (delq nil files) + files (mapcar 'nnmaildir--parse-filename files) files (sort files 'nnmaildir--sort-files)) - (while files - (setq file (car files) files (cdr files) - file (if (consp file) file (aref file 5)) - x (make-nnmaildir--art :prefix (car file) :suffix(cdr file) - :num (1+ num))) - (if (nnmaildir--grp-add-art nnmaildir--cur-server group x) - (setq num (1+ num)))) + (mapcar + (lambda (file) + (setq file (if (consp file) file (aref file 5)) + x (make-nnmaildir--art :prefix (car file) :suffix (cdr file))) + (nnmaildir--grp-add-art nnmaildir--cur-server group x)) + files) (if read-only (setf (nnmaildir--grp-new group) nattr) (setf (nnmaildir--grp-cur group) cattr))) t)) @@ -729,25 +790,21 @@ by nnmaildir-request-article.") method srv-dir srv-ls)) groups)) (setq dirs (funcall srv-ls srv-dir nil "\\`[^.]" 'nosort) - x (length dirs) - seen 1) - (while (<= seen x) (setq seen (* 2 seen))) - (if (/= seen 1) (setq seen (1- seen))) - (setq seen (make-vector seen 0)) - (while dirs - (setq grp-dir (car dirs) dirs (cdr dirs)) - (if (nnmaildir--scan grp-dir scan-group groups method srv-dir - srv-ls) - (intern grp-dir seen))) + seen (nnmaildir--up2-1 (length dirs)) + seen (make-vector seen 0)) + (mapcar + (lambda (grp-dir) + (if (nnmaildir--scan grp-dir scan-group groups method srv-dir + srv-ls) + (intern grp-dir seen))) + dirs) (setq x nil) (mapatoms (lambda (group) (setq group (symbol-name group)) - (if (intern-soft group seen) nil + (unless (intern-soft group seen) (setq x (cons group x)))) groups) - (while x - (unintern (car x) groups) - (setq x (cdr x))) + (mapcar (lambda (grp) (unintern grp groups)) x) (setf (nnmaildir--srv-mtime nnmaildir--cur-server) (nth 5 (file-attributes srv-dir)))) (and scan-group @@ -757,7 +814,7 @@ by nnmaildir-request-article.") (defun nnmaildir-request-list (&optional server) (nnmaildir-request-scan 'find-new-groups server) - (let (pgname ro ct-min deactivate-mark) + (let (pgname ro deactivate-mark) (nnmaildir--prepare server nil) (nnmaildir--with-nntp-buffer (erase-buffer) @@ -765,15 +822,12 @@ by nnmaildir-request-article.") (setq pgname (symbol-name group) pgname (nnmaildir--pgname nnmaildir--cur-server pgname) group (symbol-value group) - ro (nnmaildir--param pgname 'read-only) - ct-min (nnmaildir--article-count group)) + ro (nnmaildir--param pgname 'read-only)) (insert (nnmaildir--grp-name group) " ") - (princ (nnmaildir--nlist-last-num - (nnmaildir--lists-nlist - (nnmaildir--grp-lists group))) - nntp-server-buffer) + (princ (nnmaildir--group-maxnum nnmaildir--cur-server group) + nntp-server-buffer) (insert " ") - (princ (cdr ct-min) nntp-server-buffer) + (princ (nnmaildir--grp-min group) nntp-server-buffer) (insert " " (if ro "n" "y") "\n")) (nnmaildir--srv-groups nnmaildir--cur-server)))) t) @@ -782,49 +836,44 @@ by nnmaildir-request-article.") (nnmaildir-request-list server)) (defun nnmaildir-retrieve-groups (groups &optional server) - (let (gname group ct-min deactivate-mark) + (let (group deactivate-mark) (nnmaildir--prepare server nil) (nnmaildir--with-nntp-buffer (erase-buffer) - (while groups - (setq gname (car groups) groups (cdr groups)) - (setq group (nnmaildir--prepare nil gname)) - (if (null group) (insert "411 no such news group\n") - (setq ct-min (nnmaildir--article-count group)) - (insert "211 ") - (princ (car ct-min) nntp-server-buffer) - (insert " ") - (princ (cdr ct-min) nntp-server-buffer) - (insert " ") - (princ (nnmaildir--nlist-last-num - (nnmaildir--lists-nlist - (nnmaildir--grp-lists group))) - nntp-server-buffer) - (insert " " gname "\n"))))) + (mapcar + (lambda (gname) + (setq group (nnmaildir--prepare nil gname)) + (if (null group) (insert "411 no such news group\n") + (insert "211 ") + (princ (nnmaildir--grp-count group) nntp-server-buffer) + (insert " ") + (princ (nnmaildir--grp-min group) nntp-server-buffer) + (insert " ") + (princ (nnmaildir--group-maxnum nnmaildir--cur-server group) + nntp-server-buffer) + (insert " " gname "\n"))) + groups))) 'group) (defun nnmaildir-request-update-info (gname info &optional server) (let ((group (nnmaildir--prepare server gname)) - pgname nlist flist last always-marks never-marks old-marks dotfile num - dir markdirs marks mark ranges articles article read end new-marks ls - old-mmth new-mmth mtime mark-sym deactivate-mark) + pgname flist all always-marks never-marks old-marks dotfile num dir + markdirs marks mark ranges markdir article read end new-marks ls + old-mmth new-mmth mtime mark-sym deactivate-mark) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) (throw 'return nil)) (setq gname (nnmaildir--grp-name group) pgname (nnmaildir--pgname nnmaildir--cur-server gname) - nlist (nnmaildir--grp-lists group) - flist (nnmaildir--lists-flist nlist) - nlist (nnmaildir--lists-nlist nlist)) - (if nlist nil + flist (nnmaildir--grp-flist group)) + (when (zerop (nnmaildir--grp-count group)) (gnus-info-set-read info nil) (gnus-info-set-marks info nil 'extend) (throw 'return info)) (setq old-marks (cons 'read (gnus-info-read info)) old-marks (cons old-marks (gnus-info-marks info)) - last (nnmaildir--nlist-last-num nlist) always-marks (nnmaildir--param pgname 'always-marks) never-marks (nnmaildir--param pgname 'never-marks) dir (nnmaildir--srv-dir nnmaildir--cur-server) @@ -833,37 +882,42 @@ by nnmaildir-request-article.") dir (nnmaildir--marks-dir dir) ls (nnmaildir--group-ls nnmaildir--cur-server pgname) markdirs (funcall ls dir nil "\\`[^.]" 'nosort) - num (length markdirs) - new-mmth 1) - (while (<= new-mmth num) (setq new-mmth (* 2 new-mmth))) - (if (/= new-mmth 1) (setq new-mmth (1- new-mmth))) - (setq new-mmth (make-vector new-mmth 0) + new-mmth (nnmaildir--up2-1 (length markdirs)) + new-mmth (make-vector new-mmth 0) old-mmth (nnmaildir--grp-mmth group)) - (while markdirs - (setq mark (car markdirs) markdirs (cdr markdirs) - articles (nnmaildir--subdir dir mark) - mark-sym (intern mark) - ranges nil) - (catch 'got-ranges - (if (memq mark-sym never-marks) (throw 'got-ranges nil)) - (when (memq mark-sym always-marks) - (setq ranges (list (cons 1 last))) - (throw 'got-ranges nil)) - (setq mtime (nth 5 (file-attributes articles))) - (set (intern mark new-mmth) mtime) - (when (equal mtime (symbol-value (intern-soft mark old-mmth))) - (setq ranges (assq mark-sym old-marks)) - (if ranges (setq ranges (cdr ranges))) - (throw 'got-ranges nil)) - (setq articles (funcall ls articles nil "\\`[^.]" 'nosort)) - (while articles - (setq article (car articles) articles (cdr articles) - article (nnmaildir--flist-art flist article)) - (if article - (setq num (nnmaildir--art-num article) - ranges (gnus-add-to-range ranges (list num)))))) - (if (eq mark-sym 'read) (setq read ranges) - (if ranges (setq marks (cons (cons mark-sym ranges) marks))))) + (mapcar + (lambda (mark) + (setq markdir (nnmaildir--subdir dir mark) + mark-sym (intern mark) + ranges nil) + (catch 'got-ranges + (if (memq mark-sym never-marks) (throw 'got-ranges nil)) + (when (memq mark-sym always-marks) + (unless all + (setq all (nnmaildir--grp-nlist group) + all (mapcar 'car all) + all (nreverse all) + all (gnus-compress-sequence all 'always-list) + all (cons 'dummy-mark-symbol all))) + (setq ranges (cdr all)) + (throw 'got-ranges nil)) + (setq mtime (nth 5 (file-attributes markdir))) + (set (intern mark new-mmth) mtime) + (when (equal mtime (symbol-value (intern-soft mark old-mmth))) + (setq ranges (assq mark-sym old-marks)) + (if ranges (setq ranges (cdr ranges))) + (throw 'got-ranges nil)) + (mapcar + (lambda (prefix) + (setq article (nnmaildir--flist-art flist prefix)) + (if article + (setq ranges + (gnus-add-to-range ranges + `(,(nnmaildir--art-num article)))))) + (funcall ls markdir nil "\\`[^.]" 'nosort))) + (if (eq mark-sym 'read) (setq read ranges) + (if ranges (setq marks (cons (cons mark-sym ranges) marks))))) + markdirs) (gnus-info-set-read info read) (gnus-info-set-marks info marks 'extend) (setf (nnmaildir--grp-mmth group) new-mmth) @@ -871,26 +925,23 @@ by nnmaildir-request-article.") (defun nnmaildir-request-group (gname &optional server fast) (let ((group (nnmaildir--prepare server gname)) - ct-min deactivate-mark) + deactivate-mark) (nnmaildir--with-nntp-buffer (erase-buffer) (catch 'return - (if group nil + (unless group (insert "411 no such news group\n") (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) (throw 'return nil)) (setf (nnmaildir--srv-curgrp nnmaildir--cur-server) group) (if fast (throw 'return t)) - (setq ct-min (nnmaildir--article-count group)) (insert "211 ") - (princ (car ct-min) nntp-server-buffer) + (princ (nnmaildir--grp-count group) nntp-server-buffer) (insert " ") - (princ (cdr ct-min) nntp-server-buffer) + (princ (nnmaildir--grp-min group) nntp-server-buffer) (insert " ") - (princ (nnmaildir--nlist-last-num - (nnmaildir--lists-nlist - (nnmaildir--grp-lists group))) + (princ (nnmaildir--group-maxnum nnmaildir--cur-server group) nntp-server-buffer) (insert " " gname "\n") t)))) @@ -942,7 +993,7 @@ by nnmaildir-request-article.") (file-coding-system-alist nil) srv-dir x groups) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) (throw 'return nil)) @@ -976,7 +1027,7 @@ by nnmaildir-request-article.") (setq x (nnmaildir--srv-groups nnmaildir--cur-server) groups (make-vector (length x) 0)) (mapatoms (lambda (sym) - (if (eq (symbol-value sym) group) nil + (unless (eq (symbol-value sym) group) (set (intern (symbol-name sym) groups) (symbol-value sym)))) x) @@ -988,9 +1039,9 @@ by nnmaildir-request-article.") (defun nnmaildir-request-delete-group (gname force &optional server) (let ((group (nnmaildir--prepare server gname)) - pgname grp-dir dir dirs files ls deactivate-mark) + pgname grp-dir dir ls deactivate-mark) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) (throw 'return nil)) @@ -1002,42 +1053,19 @@ by nnmaildir-request-article.") (setq grp-dir (nnmaildir--srv-dir nnmaildir--cur-server) grp-dir (nnmaildir--srvgrp-dir grp-dir gname)) (if (not force) (setq grp-dir (directory-file-name grp-dir)) + (setq ls (nnmaildir--group-ls nnmaildir--cur-server pgname)) (if (nnmaildir--param pgname 'read-only) (progn (delete-directory (nnmaildir--tmp grp-dir)) (nnmaildir--unlink (nnmaildir--new grp-dir)) (delete-directory (nnmaildir--cur grp-dir))) - (nnmaildir--with-work-buffer - (erase-buffer) - (setq ls (nnmaildir--group-ls nnmaildir--cur-server pgname) - files (funcall ls (nnmaildir--tmp grp-dir) 'full "\\`[^.]" - 'nosort)) - (while files - (delete-file (car files)) - (setq files (cdr files))) - (delete-directory (nnmaildir--tmp grp-dir)) - (setq files (funcall ls (nnmaildir--new grp-dir) 'full "\\`[^.]" - 'nosort)) - (while files - (delete-file (car files)) - (setq files (cdr files))) - (delete-directory (nnmaildir--new grp-dir)) - (setq files (funcall ls (nnmaildir--cur grp-dir) 'full "\\`[^.]" - 'nosort)) - (while files - (delete-file (car files)) - (setq files (cdr files))) - (delete-directory (nnmaildir--cur grp-dir)))) - (setq dir (nnmaildir--nndir grp-dir) - dirs (cons (nnmaildir--nov-dir dir) - (funcall ls (nnmaildir--marks-dir dir) 'full "\\`[^.]" - 'nosort))) - (while dirs - (setq dir (car dirs) dirs (cdr dirs) - files (funcall ls dir 'full "\\`[^.]" 'nosort)) - (while files - (delete-file (car files)) - (setq files (cdr files))) - (delete-directory dir)) + (nnmaildir--delete-dir-files (nnmaildir--tmp grp-dir) ls) + (nnmaildir--delete-dir-files (nnmaildir--new grp-dir) ls) + (nnmaildir--delete-dir-files (nnmaildir--cur grp-dir) ls)) + (setq dir (nnmaildir--nndir grp-dir)) + (mapcar (lambda (subdir) (nnmaildir--delete-dir-files subdir ls)) + `(,(nnmaildir--nov-dir dir) ,(nnmaildir--num-dir dir) + ,@(funcall ls (nnmaildir--marks-dir dir) 'full "\\`[^.]" + 'nosort))) (setq dir (nnmaildir--nndir grp-dir)) (nnmaildir--unlink (concat dir "markfile")) (nnmaildir--unlink (concat dir "markfile{new}")) @@ -1045,7 +1073,7 @@ by nnmaildir-request-article.") (delete-directory dir) (setq grp-dir (directory-file-name grp-dir) dir (car (file-attributes grp-dir))) - (if (eq (aref "/" 0) (aref dir 0)) nil + (unless (eq (aref "/" 0) (aref dir 0)) (setq dir (concat (file-truename (nnmaildir--srv-dir nnmaildir--cur-server)) dir))) @@ -1055,140 +1083,98 @@ 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 stop nov nlist2 deactivate-mark) + srv-dir dir nlist mlist article num start stop nov nlist2 insert-nov + deactivate-mark) + (setq insert-nov + (lambda (article) + (setq nov (nnmaildir--update-nov nnmaildir--cur-server group + article)) + (when nov + (nnmaildir--cache-nov group article nov) + (setq num (nnmaildir--art-num article)) + (princ num nntp-server-buffer) + (insert "\t" (nnmaildir--nov-get-beg nov) "\t" + (nnmaildir--art-msgid article) "\t" + (nnmaildir--nov-get-mid nov) "\tXref: nnmaildir " + gname ":") + (princ num nntp-server-buffer) + (insert "\t" (nnmaildir--nov-get-end nov) "\n")))) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (if gname (concat "No such group: " gname) "No current group")) (throw 'return nil)) (nnmaildir--with-nntp-buffer (erase-buffer) - (setq nlist (nnmaildir--grp-lists group) - mlist (nnmaildir--lists-mlist nlist) - nlist (nnmaildir--lists-nlist nlist) + (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)) (cond ((null nlist)) ((and fetch-old (not (numberp fetch-old))) - (while nlist - (setq article (car nlist) nlist (cdr nlist) - nov (nnmaildir--update-nov nnmaildir--cur-server group - article)) - (when nov - (nnmaildir--cache-nov group article nov) - (setq num (nnmaildir--art-num article)) - (princ num nntp-server-buffer) - (insert "\t" (nnmaildir--nov-get-beg nov) "\t" - (nnmaildir--art-msgid article) "\t" - (nnmaildir--nov-get-mid nov) "\tXref: nnmaildir " gname - ":") - (princ num nntp-server-buffer) - (insert "\t" (nnmaildir--nov-get-end nov) "\n") - (goto-char (point-min))))) + (nnmaildir--nlist-iterate nlist 'all insert-nov)) ((null articles)) ((stringp (car articles)) - (while articles - (setq article (car articles) articles (cdr articles) - article (nnmaildir--mlist-art mlist article)) - (when (and article - (setq nov (nnmaildir--update-nov nnmaildir--cur-server - group article))) - (nnmaildir--cache-nov group article nov) - (setq num (nnmaildir--art-num article)) - (princ num nntp-server-buffer) - (insert "\t" (nnmaildir--nov-get-beg nov) "\t" - (nnmaildir--art-msgid article) "\t" - (nnmaildir--nov-get-mid nov) "\tXref: nnmaildir " gname - ":") - (princ num nntp-server-buffer) - (insert "\t" (nnmaildir--nov-get-end nov) "\n")))) + (mapcar + (lambda (msgid) + (setq article (nnmaildir--mlist-art mlist msgid)) + (if article (funcall insert-nov article))) + articles)) (t (if fetch-old - ;; Assume the article range is sorted ascending + ;; Assume the article range list is sorted ascending (setq stop (car articles) - num (car (last articles)) - stop (if (numberp stop) stop (car stop)) - num (if (numberp num) num (cdr num)) + start (car (last articles)) + stop (if (numberp stop) stop (car stop)) + start (if (numberp start) start (cdr start)) stop (- stop fetch-old) stop (if (< stop 1) 1 stop) - articles (list (cons stop num)))) - (while articles - (setq stop (car articles) articles (cdr articles)) - (while (eq stop (car articles)) - (setq articles (cdr articles))) - (if (numberp stop) (setq num stop) - (setq num (cdr stop) stop (car stop))) - (setq nlist2 (nthcdr (- (nnmaildir--art-num (car nlist)) num) - nlist)) - (while (and nlist2 - (setq article (car nlist2) - num (nnmaildir--art-num article)) - (>= num stop)) - (setq nlist2 (cdr nlist2) - nov (nnmaildir--update-nov nnmaildir--cur-server group - article)) - (when nov - (nnmaildir--cache-nov group article nov) - (princ num nntp-server-buffer) - (insert "\t" (nnmaildir--nov-get-beg nov) "\t" - (nnmaildir--art-msgid article) "\t" - (nnmaildir--nov-get-mid nov) "\tXref: nnmaildir " gname - ":") - (princ num nntp-server-buffer) - (insert "\t" (nnmaildir--nov-get-end nov) "\n") - (goto-char (point-min))))))) + articles (list (cons stop start)))) + (nnmaildir--nlist-iterate nlist articles insert-nov))) (sort-numeric-fields 1 (point-min) (point-max)) 'nov)))) (defun nnmaildir-request-article (num-msgid &optional gname server to-buffer) (let ((group (nnmaildir--prepare server gname)) (case-fold-search t) - list article suffix dir pgname deactivate-mark) + list article dir pgname deactivate-mark) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (if gname (concat "No such group: " gname) "No current group")) (throw 'return nil)) - (setq list (nnmaildir--grp-lists group)) (if (numberp num-msgid) - (setq list (nnmaildir--lists-nlist list) - article (nnmaildir--nlist-art list num-msgid)) - (setq list (nnmaildir--lists-mlist list) + (setq article (nnmaildir--nlist-art group num-msgid)) + (setq list (nnmaildir--grp-mlist group) article (nnmaildir--mlist-art list num-msgid)) (if article (setq num-msgid (nnmaildir--art-num article)) (catch 'found (mapatoms - (lambda (grp) - (setq group (symbol-value grp) - list (nnmaildir--grp-lists group) - list (nnmaildir--lists-mlist list) + (lambda (group-sym) + (setq group (symbol-value group-sym) + list (nnmaildir--grp-mlist group) article (nnmaildir--mlist-art list num-msgid)) (when article (setq num-msgid (nnmaildir--art-num article)) (throw 'found nil))) - (nnmaildir--srv-groups nnmaildir--cur-server))))) - (if article nil - (setf (nnmaildir--srv-error nnmaildir--cur-server) "No such article") - (throw 'return nil)) - (if (stringp (setq suffix (nnmaildir--art-suffix article))) nil - (setf (nnmaildir--srv-error nnmaildir--cur-server) - "Article has expired") - (throw 'return nil)) + (nnmaildir--srv-groups nnmaildir--cur-server)))) + (unless article + (setf (nnmaildir--srv-error nnmaildir--cur-server) "No such article") + (throw 'return nil))) (setq gname (nnmaildir--grp-name group) pgname (nnmaildir--pgname nnmaildir--cur-server gname) dir (nnmaildir--srv-dir nnmaildir--cur-server) dir (nnmaildir--srvgrp-dir dir gname) - group (if (nnmaildir--param pgname 'read-only) - (nnmaildir--new dir) (nnmaildir--cur dir)) - nnmaildir-article-file-name (concat group - (nnmaildir--art-prefix - article) - suffix)) - (if (file-exists-p nnmaildir-article-file-name) nil - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil) + dir (if (nnmaildir--param pgname 'read-only) + (nnmaildir--new dir) (nnmaildir--cur dir)) + nnmaildir-article-file-name + (concat dir + (nnmaildir--art-prefix article) + (nnmaildir--art-suffix article))) + (unless (file-exists-p nnmaildir-article-file-name) + (nnmaildir--expired-article group article) (setf (nnmaildir--srv-error nnmaildir--cur-server) "Article has expired") (throw 'return nil)) @@ -1202,16 +1188,16 @@ by nnmaildir-request-article.") (let (message-required-mail-headers) (funcall message-send-mail-function))) -(defun nnmaildir-request-replace-article (article gname buffer) +(defun nnmaildir-request-replace-article (number gname buffer) (let ((group (nnmaildir--prepare nil gname)) (coding-system-for-write nnheader-file-coding-system) (output-coding-system nnheader-file-coding-system) (buffer-file-coding-system nil) (file-coding-system nil) (file-coding-system-alist nil) - file dir suffix tmpfile deactivate-mark) + dir file article suffix tmpfile deactivate-mark) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) (throw 'return nil)) @@ -1222,25 +1208,22 @@ by nnmaildir-request-article.") (throw 'return nil)) (setq dir (nnmaildir--srv-dir nnmaildir--cur-server) dir (nnmaildir--srvgrp-dir dir gname) - file (nnmaildir--grp-lists group) - file (nnmaildir--lists-nlist file) - file (nnmaildir--nlist-art file article)) - (if (and file (stringp (setq suffix (nnmaildir--art-suffix file)))) - nil + article (nnmaildir--nlist-art group number)) + (unless article + (setf (nnmaildir--srv-error nnmaildir--cur-server) + (concat "No such article: " (number-to-string number))) + (throw 'return nil)) + (setq suffix (nnmaildir--art-suffix article) + file (nnmaildir--art-prefix article) + tmpfile (concat (nnmaildir--tmp dir) file)) + (when (file-exists-p tmpfile) (setf (nnmaildir--srv-error nnmaildir--cur-server) - (format "No such article: %d" article)) + (concat "File exists: " tmpfile)) (throw 'return nil)) (save-excursion (set-buffer buffer) - (setq article file - file (nnmaildir--art-prefix article) - tmpfile (concat (nnmaildir--tmp dir) file)) - (when (file-exists-p tmpfile) - (setf (nnmaildir--srv-error nnmaildir--cur-server) - (concat "File exists: " tmpfile)) - (throw 'return nil)) (write-region (point-min) (point-max) tmpfile nil 'no-message nil - 'confirm-overwrite)) ;; error would be preferred :( + 'excl)) (unix-sync) ;; no fsync :( (rename-file tmpfile (concat (nnmaildir--cur dir) file suffix) 'replace) t))) @@ -1248,25 +1231,20 @@ by nnmaildir-request-article.") (defun nnmaildir-request-move-article (article gname server accept-form &optional last) (let ((group (nnmaildir--prepare server gname)) - pgname list suffix result nnmaildir--file deactivate-mark) + pgname suffix result nnmaildir--file deactivate-mark) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) (throw 'return nil)) (setq gname (nnmaildir--grp-name group) pgname (nnmaildir--pgname nnmaildir--cur-server gname) - list (nnmaildir--grp-lists group) - list (nnmaildir--lists-nlist list) - article (nnmaildir--nlist-art list article)) - (if article nil + article (nnmaildir--nlist-art group article)) + (unless article (setf (nnmaildir--srv-error nnmaildir--cur-server) "No such article") (throw 'return nil)) - (if (stringp (setq suffix (nnmaildir--art-suffix article))) nil - (setf (nnmaildir--srv-error nnmaildir--cur-server) - "Article has expired") - (throw 'return nil)) - (setq nnmaildir--file (nnmaildir--srv-dir nnmaildir--cur-server) + (setq suffix (nnmaildir--art-suffix article) + nnmaildir--file (nnmaildir--srv-dir nnmaildir--cur-server) nnmaildir--file (nnmaildir--srvgrp-dir nnmaildir--file gname) nnmaildir--file (if (nnmaildir--param pgname 'read-only) (nnmaildir--new nnmaildir--file) @@ -1274,9 +1252,8 @@ by nnmaildir-request-article.") nnmaildir--file (concat nnmaildir--file (nnmaildir--art-prefix article) suffix)) - (if (file-exists-p nnmaildir--file) nil - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil) + (unless (file-exists-p nnmaildir--file) + (nnmaildir--expired-article group article) (setf (nnmaildir--srv-error nnmaildir--cur-server) "Article has expired") (throw 'return nil)) @@ -1284,10 +1261,9 @@ by nnmaildir-request-article.") (erase-buffer) (nnheader-insert-file-contents nnmaildir--file) (setq result (eval accept-form))) - (if (or (null result) (nnmaildir--param pgname 'read-only)) nil + (unless (or (null result) (nnmaildir--param pgname 'read-only)) (nnmaildir--unlink nnmaildir--file) - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil)) + (nnmaildir--expired-article group article)) result))) (defun nnmaildir-request-accept-article (gname &optional server last) @@ -1297,9 +1273,9 @@ by nnmaildir-request-article.") (buffer-file-coding-system nil) (file-coding-system nil) (file-coding-system-alist nil) - srv-dir dir file tmpfile curfile 24h num article) + srv-dir dir file tmpfile curfile 24h article) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) (throw 'return nil)) @@ -1312,11 +1288,11 @@ by nnmaildir-request-article.") (setq srv-dir (nnmaildir--srv-dir nnmaildir--cur-server) dir (nnmaildir--srvgrp-dir srv-dir gname) file (format-time-string "%s" nil)) - (if (string-equal nnmaildir--delivery-time file) nil + (unless (string-equal nnmaildir--delivery-time file) (setq nnmaildir--delivery-time file nnmaildir--delivery-ct 0)) (setq file (concat file "." nnmaildir--delivery-pid)) - (if (zerop nnmaildir--delivery-ct) nil + (unless (zerop nnmaildir--delivery-ct) (setq file (concat file "_" (number-to-string nnmaildir--delivery-ct)))) (setq file (concat file "." (system-name)) @@ -1342,7 +1318,7 @@ by nnmaildir-request-article.") (add-name-to-file nnmaildir--file tmpfile) (error (write-region (point-min) (point-max) tmpfile nil 'no-message nil - 'confirm-overwrite) ;; error would be preferred :( + 'excl) (unix-sync))) ;; no fsync :( (cancel-timer 24h) (condition-case err @@ -1353,19 +1329,15 @@ by nnmaildir-request-article.") (nnmaildir--unlink tmpfile) (throw 'return nil))) (nnmaildir--unlink tmpfile) - (setq num (nnmaildir--grp-lists group) - num (nnmaildir--lists-nlist num) - num (1+ (nnmaildir--nlist-last-num num)) - article (make-nnmaildir--art :prefix file :suffix ":2," :num num)) + (setq article (make-nnmaildir--art :prefix file :suffix ":2,")) (if (nnmaildir--grp-add-art nnmaildir--cur-server group article) - (cons gname num))))) + (cons gname (nnmaildir--art-num article)))))) (defun nnmaildir-save-mail (group-art) (catch 'return - (if group-art nil + (unless group-art (throw 'return nil)) - (let ((ret group-art) - ga gname x groups nnmaildir--file deactivate-mark) + (let (ga gname x groups nnmaildir--file deactivate-mark) (save-excursion (goto-char (point-min)) (save-match-data @@ -1378,50 +1350,37 @@ by nnmaildir-request-article.") (or (intern-soft gname groups) (nnmaildir-request-create-group gname) (throw 'return nil)) ;; not that nnmail bothers to check :( - (if (nnmaildir-request-accept-article gname) nil + (unless (nnmaildir-request-accept-article gname) (throw 'return nil)) - (setq x (nnmaildir--prepare nil gname) - nnmaildir--file (nnmaildir--srv-dir nnmaildir--cur-server) - nnmaildir--file (nnmaildir--subdir nnmaildir--file - (nnmaildir--grp-name x)) - x (nnmaildir--grp-lists x) - x (nnmaildir--lists-nlist x) - x (car x) + (setq nnmaildir--file (nnmaildir--srv-dir nnmaildir--cur-server) + nnmaildir--file (nnmaildir--srvgrp-dir nnmaildir--file gname) + x (nnmaildir--prepare nil gname) + x (nnmaildir--grp-nlist x) + x (cdar x) nnmaildir--file (concat nnmaildir--file (nnmaildir--art-prefix x) (nnmaildir--art-suffix x))) - (while group-art - (setq ga (car group-art) group-art (cdr group-art) - gname (car ga)) - (if (and (or (intern-soft gname groups) - (nnmaildir-request-create-group gname)) - (nnmaildir-request-accept-article gname)) nil - (setq ret (delq ga ret)))) ;; We'll still try the other groups - ret))) - -(defun nnmaildir-active-number (group) - (let ((x (nnmaildir--prepare nil group))) - (catch 'return - (if x nil - (setf (nnmaildir--srv-error nnmaildir--cur-server) - (concat "No such group: " group)) - (throw 'return nil)) - (setq x (nnmaildir--grp-lists x) - x (nnmaildir--lists-nlist x)) - (if x - (setq x (car x) - x (nnmaildir--art-num x) - x (1+ x)) - 1)))) + (delq nil + (mapcar + (lambda (ga) + (setq gname (car ga)) + (and (or (intern-soft gname groups) + (nnmaildir-request-create-group gname)) + (nnmaildir-request-accept-article gname) + ga)) + group-art))))) + +(defun nnmaildir-active-number (gname) + 0) (defun nnmaildir-request-expire-articles (ranges &optional gname server force) (let ((no-force (not force)) (group (nnmaildir--prepare server gname)) - pgname time boundary time-iter bound-iter high low target dir nlist - stop number article didnt suffix nnmaildir--file - nnmaildir-article-file-name deactivate-mark) + pgname time boundary bound-iter high low target dir nlist nlist2 + stop article didnt nnmaildir--file nnmaildir-article-file-name + deactivate-mark) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (if gname (concat "No such group: " gname) "No current group")) (throw 'return (gnus-uncompress-range ranges))) @@ -1429,79 +1388,69 @@ by nnmaildir-request-article.") pgname (nnmaildir--pgname nnmaildir--cur-server gname)) (if (nnmaildir--param pgname 'read-only) (throw 'return (gnus-uncompress-range ranges))) - (setq time (or (nnmaildir--param pgname 'expire-age) - (* 86400 ;; seconds per day - (or (and nnmail-expiry-wait-function - (funcall nnmail-expiry-wait-function gname)) - nnmail-expiry-wait)))) - (if (or force (integerp time)) nil - (throw 'return (gnus-uncompress-range ranges))) - (setq boundary (current-time) - high (- (car boundary) (/ time 65536)) - low (- (cadr boundary) (% time 65536))) - (if (< low 0) - (setq low (+ low 65536) - high (1- high))) - (setcar (cdr boundary) low) - (setcar boundary high) + (setq time (nnmaildir--param pgname 'expire-age)) + (unless time + (setq time (or (and nnmail-expiry-wait-function + (funcall nnmail-expiry-wait-function gname)) + nnmail-expiry-wait)) + (if (eq time 'immediate) + (setq time 0) + (if (numberp time) + (setq time (* time 86400))))) + (when no-force + (unless (integerp time) ;; handle 'never + (throw 'return (gnus-uncompress-range ranges))) + (setq boundary (current-time) + high (- (car boundary) (/ time 65536)) + low (- (cadr boundary) (% time 65536))) + (if (< low 0) + (setq low (+ low 65536) + high (1- high))) + (setcar (cdr boundary) low) + (setcar boundary high)) (setq dir (nnmaildir--srv-dir nnmaildir--cur-server) dir (nnmaildir--srvgrp-dir dir gname) dir (nnmaildir--cur dir) - nlist (nnmaildir--grp-lists group) - nlist (nnmaildir--lists-nlist nlist) + nlist (nnmaildir--grp-nlist group) ranges (reverse ranges)) (nnmaildir--with-move-buffer - (while ranges - (setq number (car ranges) ranges (cdr ranges)) - (while (eq number (car ranges)) - (setq ranges (cdr ranges))) - (if (numberp number) (setq stop number) - (setq stop (car number) number (cdr number))) - (setq nlist (nthcdr (- (nnmaildir--art-num (car nlist)) number) - nlist)) - (while (and nlist - (setq article (car nlist) - number (nnmaildir--art-num article)) - (>= number stop)) - (setq nlist (cdr nlist) - suffix (nnmaildir--art-suffix article)) - (catch 'continue - (if (stringp suffix) nil - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil) - (throw 'continue nil)) - (setq nnmaildir--file (nnmaildir--art-prefix article) - nnmaildir--file (concat dir nnmaildir--file suffix) - time (file-attributes nnmaildir--file)) - (if time nil - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil) - (throw 'continue nil)) - (setq time (nth 5 time) - time-iter time - bound-iter boundary) - (if (and no-force - (progn - (while (and bound-iter time-iter - (= (car bound-iter) (car time-iter))) - (setq bound-iter (cdr bound-iter) - time-iter (cdr time-iter))) - (and bound-iter time-iter - (car-less-than-car bound-iter time-iter)))) - (setq didnt (cons number didnt)) - (save-excursion - (setq nnmaildir-article-file-name nnmaildir--file - target (nnmaildir--param pgname 'expire-group))) - (when (and (stringp target) - (not (string-equal target pgname))) ;; Move it. - (erase-buffer) - (nnheader-insert-file-contents nnmaildir--file) - (gnus-request-accept-article target nil nil 'no-encode)) - (if (equal target pgname) - (setq didnt (cons number didnt)) ;; Leave it here. - (nnmaildir--unlink nnmaildir--file) - (setf (nnmaildir--art-suffix article) 'expire) - (setf (nnmaildir--art-nov article) nil)))))) + (nnmaildir--nlist-iterate + nlist ranges + (lambda (article) + (setq nnmaildir--file (nnmaildir--art-prefix article) + nnmaildir--file (concat dir nnmaildir--file + (nnmaildir--art-suffix article)) + time (file-attributes nnmaildir--file)) + (cond + ((null time) + (nnmaildir--expired-article group article)) + ((and no-force + (progn + (setq time (nth 5 time) + bound-iter boundary) + (while (and bound-iter time + (= (car bound-iter) (car time))) + (setq bound-iter (cdr bound-iter) + time (cdr time))) + (and bound-iter time + (car-less-than-car bound-iter time)))) + (setq didnt (cons (nnmaildir--art-num article) didnt))) + (t + (setq nnmaildir-article-file-name nnmaildir--file + target (if force nil + (save-excursion + (save-restriction + (nnmaildir--param pgname 'expire-group))))) + (when (and (stringp target) + (not (string-equal target pgname))) ;; Move it. + (erase-buffer) + (nnheader-insert-file-contents nnmaildir--file) + (gnus-request-accept-article target nil nil 'no-encode)) + (if (equal target pgname) + ;; Leave it here. + (setq didnt (cons (nnmaildir--art-num article) didnt)) + (nnmaildir--unlink nnmaildir--file) + (nnmaildir--expired-article group article)))))) (erase-buffer)) didnt))) @@ -1512,42 +1461,50 @@ by nnmaildir-request-article.") (buffer-file-coding-system nil) (file-coding-system nil) (file-coding-system-alist nil) - del-mark add-marks marksdir markfile action group-nlist nlist ranges - begin end article all-marks todo-marks did-marks marks form mdir mfile + del-mark del-action add-action set-action marksdir markfile nlist + ranges begin end article all-marks todo-marks did-marks mdir mfile pgname ls markfilenew deactivate-mark) (setq del-mark - (lambda () - (setq mfile (nnmaildir--subdir marksdir (symbol-name (car marks))) + (lambda (mark) + (setq mfile (nnmaildir--subdir marksdir (symbol-name mark)) mfile (concat mfile (nnmaildir--art-prefix article))) (nnmaildir--unlink mfile)) - add-marks - (lambda () - (while marks - (setq mdir (nnmaildir--subdir marksdir (symbol-name (car marks))) - mfile (concat mdir (nnmaildir--art-prefix article))) - (if (memq (car marks) did-marks) nil - (nnmaildir--mkdir mdir) - (setq did-marks (cons (car marks) did-marks))) - (if (file-exists-p mfile) nil - (condition-case nil - (add-name-to-file markfile mfile) - (file-error - (if (file-exists-p mfile) nil - ;; too many links, maybe - (write-region "" nil markfilenew nil 'no-message) - (add-name-to-file markfilenew mfile 'ok-if-already-exists) - (rename-file markfilenew markfile 'replace))))) - (setq marks (cdr marks))))) + del-action (lambda (article) (mapcar del-mark todo-marks)) + add-action + (lambda (article) + (mapcar + (lambda (mark) + (setq mdir (nnmaildir--subdir marksdir (symbol-name mark)) + mfile (concat mdir (nnmaildir--art-prefix article))) + (unless (memq mark did-marks) + (nnmaildir--mkdir mdir) + (setq did-marks (cons mark did-marks))) + (unless (file-exists-p mfile) + (condition-case nil + (add-name-to-file markfile mfile) + (file-error + (unless (file-exists-p mfile) + ;; too many links, maybe + (write-region "" nil markfilenew nil 'no-message) + (add-name-to-file markfilenew mfile + 'ok-if-already-exists) + (rename-file markfilenew markfile 'replace)))))) + todo-marks)) + set-action (lambda (article) + (funcall add-action) + (mapcar (lambda (mark) + (unless (memq mark todo-marks) + (funcall del-mark mark))) + all-marks))) (catch 'return - (if group nil + (unless group (setf (nnmaildir--srv-error nnmaildir--cur-server) (concat "No such group: " gname)) - (while actions - (setq ranges (gnus-range-add ranges (caar actions)) - actions (cdr actions))) + (mapcar (lambda (action) + (setq ranges (gnus-range-add ranges (car action)))) + actions) (throw 'return ranges)) - (setq group-nlist (nnmaildir--grp-lists group) - group-nlist (nnmaildir--lists-nlist group-nlist) + (setq nlist (nnmaildir--grp-nlist group) marksdir (nnmaildir--srv-dir nnmaildir--cur-server) marksdir (nnmaildir--srvgrp-dir marksdir gname) marksdir (nnmaildir--nndir marksdir) @@ -1558,97 +1515,70 @@ by nnmaildir-request-article.") pgname (nnmaildir--pgname nnmaildir--cur-server gname) ls (nnmaildir--group-ls nnmaildir--cur-server pgname) all-marks (funcall ls marksdir nil "\\`[^.]" 'nosort) - marks all-marks) - (while marks - (setcar marks (intern (car marks))) - (setq marks (cdr marks))) - (while actions - (setq action (car actions) actions (cdr actions) - nlist group-nlist - ranges (car action) - todo-marks (caddr action) - marks todo-marks) - (while marks - (if (memq (car marks) all-marks) nil - (setq all-marks (cons (car marks) all-marks))) - (setq marks (cdr marks))) - (setq form - (cond - ((eq 'del (cadr action)) - '(while marks - (funcall del-mark) - (setq marks (cdr marks)))) - ((eq 'add (cadr action)) '(funcall add-marks)) - (t - '(progn - (funcall add-marks) - (setq marks all-marks) - (while marks - (if (memq (car marks) todo-marks) nil - (funcall del-mark)) - (setq marks (cdr marks))))))) - (if (numberp (cdr ranges)) (setq ranges (list ranges)) - (setq ranges (reverse ranges))) - (while ranges - (setq begin (car ranges) ranges (cdr ranges)) - (while (eq begin (car ranges)) - (setq ranges (cdr ranges))) - (if (numberp begin) (setq end begin) - (setq end (cdr begin) begin (car begin))) - (setq nlist (nthcdr (- (nnmaildir--art-num (car nlist)) end) - nlist)) - (while (and nlist - (setq article (car nlist)) - (>= (nnmaildir--art-num article) begin)) - (setq nlist (cdr nlist)) - (when (stringp (nnmaildir--art-suffix article)) - (setq marks todo-marks) - (eval form))))) + all-marks (mapcar 'intern all-marks)) + (mapcar + (lambda (action) + (setq ranges (car action) + todo-marks (caddr action)) + (mapcar (lambda (mark) (add-to-list 'all-marks mark)) todo-marks) + (if (numberp (cdr ranges)) (setq ranges (list ranges))) + (nnmaildir--nlist-iterate nlist ranges + (cond ((eq 'del (cadr action)) del-action) + ((eq 'add (cadr action)) add-action) + (t set-action)))) + actions) nil))) -(defun nnmaildir-close-group (group &optional server) - t) +(defun nnmaildir-close-group (gname &optional server) + (let ((group (nnmaildir--prepare server gname)) + pgname ls dir msgdir files flist dirs) + (if (null group) + (progn + (setf (nnmaildir--srv-error nnmaildir--cur-server) + (concat "No such group: " gname)) + nil) + (setq pgname (nnmaildir--pgname nnmaildir--cur-server gname) + ls (nnmaildir--group-ls nnmaildir--cur-server pgname) + dir (nnmaildir--srv-dir nnmaildir--cur-server) + dir (nnmaildir--srvgrp-dir dir gname) + msgdir (if (nnmaildir--param pgname 'read-only) + (nnmaildir--new dir) (nnmaildir--cur dir)) + dir (nnmaildir--nndir dir) + dirs (cons (nnmaildir--nov-dir dir) + (funcall ls (nnmaildir--marks-dir dir) 'full "\\`[^.]" + 'nosort)) + dirs (mapcar + (lambda (dir) + (cons dir (funcall ls dir nil "\\`[^.]" 'nosort))) + dirs) + files (funcall ls msgdir nil "\\`[^.]" 'nosort) + flist (nnmaildir--up2-1 (length files)) + flist (make-vector flist 0)) + (save-match-data + (mapcar + (lambda (file) + (string-match "\\`\\([^:]*\\)\\(:.*\\)?\\'" file) + (intern (match-string 1 file) flist)) + files)) + (mapcar + (lambda (dir) + (setq files (cdr dir) + dir (file-name-as-directory (car dir))) + (mapcar + (lambda (file) + (unless (intern-soft file flist) + (setq file (concat dir file)) + (delete-file file))) + files)) + dirs) + t))) (defun nnmaildir-close-server (&optional server) (let (flist ls dirs dir files file x) (nnmaildir--prepare server nil) - (setq server nnmaildir--cur-server) - (when server - (setq nnmaildir--cur-server nil) - (save-match-data - (mapatoms - (lambda (group) - (setq x (nnmaildir--pgname server (symbol-name group)) - group (symbol-value group) - ls (nnmaildir--group-ls server x) - dir (nnmaildir--srv-dir server) - dir (nnmaildir--srvgrp-dir dir (nnmaildir--grp-name group)) - x (nnmaildir--param x 'read-only) - x (if x (nnmaildir--new dir) (nnmaildir--cur dir)) - files (funcall ls x nil "\\`[^.]" 'nosort) - x (length files) - flist 1) - (while (<= flist x) (setq flist (* 2 flist))) - (if (/= flist 1) (setq flist (1- flist))) - (setq flist (make-vector flist 0)) - (while files - (setq file (car files) files (cdr files)) - (string-match "\\`\\([^:]*\\)\\(:.*\\)?\\'" file) - (intern (match-string 1 file) flist)) - (setq dir (nnmaildir--nndir dir) - dirs (cons (nnmaildir--nov-dir dir) - (funcall ls (nnmaildir--marks-dir dir) 'full - "\\`[^.]" 'nosort))) - (while dirs - (setq dir (car dirs) dirs (cdr dirs) - files (funcall ls dir nil "\\`[^.]" 'nosort) - dir (file-name-as-directory dir)) - (while files - (setq file (car files) files (cdr files)) - (if (intern-soft file flist) nil - (setq file (concat dir file)) - (delete-file file))))) - (nnmaildir--srv-groups server))) + (when nnmaildir--cur-server + (setq server nnmaildir--cur-server + nnmaildir--cur-server nil) (unintern (nnmaildir--srv-address server) nnmaildir--servers))) t) @@ -1657,9 +1587,7 @@ by nnmaildir-request-article.") (mapatoms (lambda (server) (setq servers (cons (symbol-name server) servers))) nnmaildir--servers) - (while servers - (nnmaildir-close-server (car servers)) - (setq servers (cdr servers))) + (mapcar 'nnmaildir-close-server servers) (setq buffer (get-buffer " *nnmaildir work*")) (if buffer (kill-buffer buffer)) (setq buffer (get-buffer " *nnmaildir nov*")) @@ -1668,28 +1596,11 @@ by nnmaildir-request-article.") (if buffer (kill-buffer buffer))) t) -(defun nnmaildir--edit-prep () - (let ((extras '(mapcar mapatoms)) - name) - (mapatoms - (lambda (sym) - (when (or (memq sym extras) - (and (fboundp sym) - (setq name (symbol-name sym)) - (>= (length name) 10) - (or (string-equal "nnmaildir-" (substring name 0 10)) - (and (>= (length name) 15) - (string-equal "make-nnmaildir-" - (substring name 0 15)))))) - (put sym 'lisp-indent-function 0)))) - 'done)) - (provide 'nnmaildir) ;; Local Variables: ;; indent-tabs-mode: t ;; fill-column: 77 -;; eval: (progn (require 'nnmaildir) (nnmaildir--edit-prep)) ;; End: ;;; nnmaildir.el ends here diff --git a/lisp/smime.el b/lisp/smime.el index 364e3b7..dc47c13 100644 --- a/lisp/smime.el +++ b/lisp/smime.el @@ -312,7 +312,7 @@ KEYFILE should contain a PEM encoded key and certificate." (point-min) (point-max) (if keyfile keyfile - (smime-get-key-by-email + (smime-get-key-with-certs-by-email (completing-read (concat "Sign using which key? " (if smime-keys (concat "(default " (caar smime-keys) ") ") @@ -605,6 +605,9 @@ The following commands are available: (defun smime-get-key-by-email (email) (cadr (assoc email smime-keys))) +(defun smime-get-key-with-certs-by-email (email) + (cdr (assoc email smime-keys))) + (provide 'smime) ;;; smime.el ends here