(defvar nnfolder-directory (expand-file-name "~/Mail/")
"The name of the mail box file in the users home directory.")
-(defvar nnfolder-active-file (concat nnfolder-directory "active")
+(defvar nnfolder-active-file
+ (concat (file-name-as-directory nnfolder-directory) "active")
"The name of the active file.")
;; I renamed this variable to somehting more in keeping with the general GNU
close, but not killing it), speeding some things up tremendously, especially
such things as moving mail. All buffers always get killed upon server close.")
-(defvar nnfolder-newsgroups-file (concat nnfolder-directory "newsgroups")
+(defvar nnfolder-newsgroups-file
+ (concat (file-name-as-directory nnfolder-directory) "newsgroups")
"Mail newsgroups description file.")
(defvar nnfolder-get-new-mail t
- "If non-nil, nnml will check the incoming mail file and split the mail.")
+ "If non-nil, nnfolder will check the incoming mail file and split the mail.")
(defvar nnfolder-prepare-save-mail-hook nil
"Hook run narrowed to an article before saving.")
\f
-(defconst nnfolder-version "nnfolder 0.2"
+(defconst nnfolder-version "nnfolder 1.0"
"nnfolder version.")
(defconst nnfolder-article-marker "X-Gnus-Article-Number: "
(defvar nnfolder-status-string "")
(defvar nnfolder-group-alist nil)
(defvar nnfolder-buffer-alist nil)
+(defvar nnfolder-active-timestamp nil)
(defmacro nnfolder-article-string (article)
(` (concat "\n" nnfolder-article-marker (int-to-string (, article)) " ")))
'(nnfolder-current-buffer nil)
'(nnfolder-status-string "")
'(nnfolder-group-alist nil)
- '(nnfolder-buffer-alist nil)))
+ '(nnfolder-buffer-alist nil)
+ '(nnfolder-active-timestamp nil)))
\f
(save-excursion
(set-buffer nntp-server-buffer)
(erase-buffer)
- (let ((file nil)
- (number (length sequence))
- (delim-string (concat "^" rmail-unix-mail-delimiter))
- beg article art-string start stop)
+ (let ((delim-string (concat "^" rmail-unix-mail-delimiter))
+ article art-string start stop)
(nnfolder-possibly-change-group newsgroup)
(set-buffer nnfolder-current-buffer)
(goto-char (point-min))
(setq stop (1- (point)))
(set-buffer nntp-server-buffer)
(insert (format "221 %d Article retrieved.\n" article))
- (setq beg (point))
(insert-buffer-substring nnfolder-current-buffer start stop)
(goto-char (point-max))
(insert ".\n")))
(defun nnfolder-request-group (group &optional server dont-check)
(save-excursion
+ (nnmail-activate 'nnfolder)
(nnfolder-possibly-change-group group)
(and (assoc group nnfolder-group-alist)
(progn
(if dont-check
t
- (nnfolder-get-new-mail group))
- (let* ((active (assoc group nnfolder-group-alist))
- (group (car active))
- (range (car (cdr active)))
- (minactive (car range))
- (maxactive (cdr range)))
- ;; I've been getting stray 211 lines in my nnfolder active
- ;; file. So, let's make sure that doesn't happen. -SLB
- (set-buffer nntp-server-buffer)
- (erase-buffer)
- (insert (format "211 %d %d %d %s\n"
- (1+ (- maxactive minactive))
- minactive maxactive group))
- t)))))
+ (nnfolder-get-new-mail group)
+ (let* ((active (assoc group nnfolder-group-alist))
+ (group (car active))
+ (range (car (cdr active)))
+ (minactive (car range))
+ (maxactive (cdr range)))
+ ;; I've been getting stray 211 lines in my nnfolder active
+ ;; file. So, let's make sure that doesn't happen. -SLB
+ (set-buffer nntp-server-buffer)
+ (erase-buffer)
+ (if (not active)
+ ()
+ (insert (format "211 %d %d %d %s\n"
+ (1+ (- maxactive minactive))
+ minactive maxactive group))
+ t)))))))
;; Don't close the buffer if we're not shutting down the server. This way,
;; we can keep the buffer in the group buffer cache, and not have to grovel
t)
(defun nnfolder-request-create-group (group &optional server)
- (nnfolder-request-list)
- (setq nnfolder-group-alist (nnmail-get-active))
+ (nnmail-activate 'nnfolder)
(or (assoc group nnfolder-group-alist)
(let (active)
(setq nnfolder-group-alist
- (cons (list group (setq active (cons 0 0)))
+ (cons (list group (setq active (cons 1 0)))
nnfolder-group-alist))
+ (nnfolder-possibly-change-group group)
(nnmail-save-active nnfolder-group-alist nnfolder-active-file)))
t)
(defun nnfolder-request-list (&optional server)
(if server (nnfolder-get-new-mail))
(save-excursion
- (or nnfolder-group-alist
- (nnmail-find-file nnfolder-active-file)
- (progn
- (setq nnfolder-group-alist (nnmail-get-active))
- (nnmail-save-active nnfolder-group-alist nnfolder-active-file)
- (nnmail-find-file nnfolder-active-file)))))
+ (nnmail-find-file nnfolder-active-file)
+ (setq nnfolder-group-alist (nnmail-get-active))))
(defun nnfolder-request-newgroups (date &optional server)
(nnfolder-request-list server))
(defalias 'nnfolder-request-post-buffer 'nnmail-request-post-buffer)
-(defun nnfolder-request-expire-articles (articles newsgroup &optional server force)
+(defun nnfolder-request-expire-articles
+ (articles newsgroup &optional server force)
(nnfolder-possibly-change-group newsgroup)
(let* ((days (or (and nnmail-expiry-wait-function
(funcall nnmail-expiry-wait-function newsgroup))
nnmail-expiry-wait))
- article rest)
+ (is-old t)
+ rest)
+ (nnmail-activate 'nnfolder)
+
(save-excursion
(set-buffer nnfolder-current-buffer)
- (while articles
+ (while (and articles is-old)
(goto-char (point-min))
(if (search-forward (nnfolder-article-string (car articles)) nil t)
(if (or force
- (> (nnmail-days-between
- (current-time-string)
- (buffer-substring
- (point) (progn (end-of-line) (point))))
- days))
+ (setq is-old
+ (> (nnmail-days-between
+ (current-time-string)
+ (buffer-substring
+ (point) (progn (end-of-line) (point))))
+ days)))
(progn
(and gnus-verbose-backends
- (message "Deleting: %s" (car articles)))
+ (message "Deleting article %s..." (car articles)))
(nnfolder-delete-mail))
(setq rest (cons (car articles) rest))))
(setq articles (cdr articles)))
(match-end 0))))))
(setcar active activemin))
(nnmail-save-active nnfolder-group-alist nnfolder-active-file)
- rest)))
+ (nconc rest articles))))
(defun nnfolder-request-move-article
(article group server accept-form &optional last)
(insert-buffer-substring nntp-server-buffer)
(goto-char (point-min))
(while (re-search-forward
- "^X-Gnus-Newsgroup:"
+ (concat "^" nnfolder-article-marker)
(save-excursion (search-forward "\n\n" nil t) (point)) t)
(delete-region (progn (beginning-of-line) (point))
(progn (forward-line 1) (point))))
result))
(defun nnfolder-request-accept-article (group &optional last)
- (nnfolder-possibly-change-group group)
+ (and (stringp group) (nnfolder-possibly-change-group group))
(let ((buf (current-buffer))
- result beg)
+ result)
(goto-char (point-min))
- (if (looking-at "X-From-Line: ")
- (replace-match "From ")
- (insert "From nobody " (current-time-string) "\n"))
+ (cond ((looking-at "X-From-Line: ")
+ (replace-match "From "))
+ ((not (looking-at "From "))
+ (insert "From nobody " (current-time-string) "\n")))
(and
(nnfolder-request-list)
(save-excursion
(goto-char (point-min))
(search-forward "\n\n" nil t)
(forward-line -1)
- (while (re-search-backward "^X-Gnus-Newsgroup: " nil t)
+ (while (re-search-backward (concat "^" nnfolder-article-marker) nil t)
(delete-region (point) (progn (forward-line 1) (point))))
(setq result (car (nnfolder-save-mail (and (stringp group) group)))))
(save-excursion
(make-directory (directory-file-name nnfolder-directory)))
(nnfolder-possibly-activate-groups nil)
(or (assoc group nnfolder-group-alist)
- (not (file-exists-p (concat nnfolder-directory group)))
+ (not (file-exists-p (concat (file-name-as-directory nnfolder-directory)
+ group)))
(progn
(setq nnfolder-group-alist
(cons (list group (cons 1 0)) nnfolder-group-alist))
(nnmail-save-active nnfolder-group-alist nnfolder-active-file)))
(let (inf file)
(if (and (equal group nnfolder-current-group)
+ nnfolder-current-buffer
(buffer-name nnfolder-current-buffer))
()
(setq nnfolder-current-group group)
;; If the buffer is not live, make sure it isn't in the alist. If it
;; is live, verify that nobody else has touched the file since last
;; time.
- (if (or (not (buffer-name nnfolder-current-buffer))
+ (if (or (not (and nnfolder-current-buffer
+ (buffer-name nnfolder-current-buffer)))
(not (and (bufferp nnfolder-current-buffer)
(verify-visited-file-modtime
nnfolder-current-buffer))))
(progn
- (if (and (buffer-name nnfolder-current-buffer)
+ (if (and nnfolder-current-buffer
+ (buffer-name nnfolder-current-buffer)
(bufferp nnfolder-current-buffer))
(kill-buffer nnfolder-current-buffer))
(setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist))
(if inf
()
(save-excursion
- (setq file (concat nnfolder-directory group))
- (if (or (file-directory-p file)
- (file-symlink-p file))
+ (setq file (concat (file-name-as-directory nnfolder-directory)
+ group))
+ (if (file-directory-p (file-truename file))
()
(if (not (file-exists-p file))
(write-region 1 1 file t 'nomesg))
+ (setq nnfolder-current-buffer
+ (set-buffer (nnfolder-read-folder file)))
(setq nnfolder-buffer-alist (cons (list group (current-buffer))
- nnfolder-buffer-alist))
- (set-buffer (nnfolder-read-folder file)))))))
+ nnfolder-buffer-alist)))))))
(setq nnfolder-current-group group))
(defun nnfolder-save-mail (&optional group)
(search-forward "\n\n" nil t)
(forward-line -1)
(while (search-backward (concat "\n" nnfolder-article-marker) nil t)
- (delete-region (point) (progn (forward-line 1) (point))))
+ (delete-region (1+ (point)) (progn (forward-line 2) (point))))
;; Insert the new newsgroup marker.
(nnfolder-possibly-change-group (car group-art))
(defun nnfolder-possibly-activate-groups (&optional group)
(save-excursion
;; If we're looking for the activation of a specific group, find out
- ;; it's real name and switch to it.
+ ;; its real name and switch to it.
(if group (nnfolder-possibly-change-group group))
;; If the group alist isn't active, activate it now.
- (if (not nnfolder-group-alist)
- (progn
- (nnfolder-request-list)
- (setq nnfolder-group-alist (nnmail-get-active))))))
+ (nnmail-activate 'nnfolder)))
(defun nnfolder-active-number (group)
(save-excursion
- (nnfolder-possibly-activate-groups group)
- (let ((active (car (cdr (assoc group nnfolder-group-alist)))))
- (setcdr active (1+ (cdr active)))
- (cdr active))))
+ ;; Find the next article number in GROUP.
+ (prog1
+ (let ((active (car (cdr (assoc group nnfolder-group-alist)))))
+ (if active
+ (setcdr active (1+ (cdr active)))
+ ;; This group is new, so we create a new entry for it.
+ ;; This might be a bit naughty... creating groups on the drop of
+ ;; a hat, but I don't know...
+ (setq nnfolder-group-alist
+ (cons (list group (setq active (cons 1 1)))
+ nnfolder-group-alist)))
+ (cdr active))
+ (nnfolder-possibly-activate-groups group))))
+
;; This method has a problem if you've accidentally let the active list get
;; out of sync with the files. This could happen, say, if you've
-;; accidentally gotten new mail with something other than (ding) (but why
+;; accidentally gotten new mail with something other than Gnus (but why
;; would _that_ ever happen? :-). In that case, we will be in the middle of
;; processing the file, ready to add new X-Gnus article number markers, and
;; we'll run accross a message with no ID yet - the active list _may_not_ be
;; We should be paranoid here and make sure the group is in the alist,
;; and add it if it isn't.
;;(if (not (assoc nnfoler-current-group nnfolder-group-alist)
- (set-buffer (setq nnfolder-current-buffer (find-file-noselect file)))
+ (set-buffer (setq nnfolder-current-buffer
+ (nnheader-find-file-noselect file nil 'raw)))
(buffer-disable-undo (current-buffer))
(let ((delim (concat "^" rmail-unix-mail-delimiter))
(marker (concat "\n" nnfolder-article-marker))
(while (and (search-forward marker nil t)
(re-search-forward number nil t))
(let ((newnum (string-to-number (buffer-substring
- (match-beginning 0)
- (match-end 0)))))
+ (match-beginning 0)
+ (match-end 0)))))
(setq activenumber (max activenumber newnum))
(setq activemin (min activemin newnum))))
(setcar active (min activemin activenumber))
- (setcdr active activenumber)
+ (setcdr active (max activenumber (cdr active)))
(goto-char (point-min))))
;; Keep track of the active number on our own, and insert it back into
(while (not (= end (point-max)))
(setq start (marker-position end))
(goto-char end)
- (end-of-line)
+ ;; There may be more than one "From " line, so we skip past
+ ;; them.
+ (while (looking-at delim)
+ (forward-line 1))
(set-marker end (or (and (re-search-forward delim nil t)
(match-beginning 0))
(point-max)))
(progn
(narrow-to-region start end)
(nnmail-insert-lines)
- (setq activenumber (1+ activenumber))
- (nnfolder-insert-newsgroup-line (cons nil activenumber))
+ (nnfolder-insert-newsgroup-line
+ (cons nil (nnfolder-active-number nnfolder-current-group)))
(widen))))
;; Make absolutely sure that the active list reflects reality!
- (setcdr active activenumber)
(nnmail-save-active nnfolder-group-alist nnfolder-active-file)
(current-buffer))))
(defun nnfolder-get-new-mail (&optional group)
"Read new incoming mail."
(let* ((spools (nnmail-get-spool-files group))
- (all-spools spools)
(group-in group)
incomings incoming)
(if (or (not nnfolder-get-new-mail) (not nnmail-spool-file))
(progn
(and gnus-verbose-backends
(message "nnfolder: Reading incoming mail..."))
- (setq incoming
- (nnmail-move-inbox
- (car spools) (concat nnfolder-directory "Incoming")))
- (setq incomings (cons incoming incomings))
- (setq group (nnmail-get-split-group (car spools) group-in))
- (nnmail-split-incoming incoming 'nnfolder-save-mail nil group)))
+ (if (not (setq incoming
+ (nnmail-move-inbox
+ (car spools)
+ (concat (file-name-as-directory nnfolder-directory)
+ "Incoming"))))
+ ()
+ (setq incomings (cons incoming incomings))
+ (setq group (nnmail-get-split-group (car spools) group-in))
+ (nnmail-split-incoming incoming 'nnfolder-save-mail nil group))))
(setq spools (cdr spools)))
;; If we did indeed read any incoming spools, we save all info.
(if incoming
(and (buffer-modified-p) (save-buffer)))
(setq bufs (cdr bufs)))))
(while incomings
+ (setq incoming (car incomings))
(and
nnmail-delete-incoming
(file-writable-p incoming)
+ (file-exists-p incoming)
(delete-file incoming))
(setq incomings (cdr incomings))))))