+(defun nnultimate-prune-days (group time)
+ "Compute the number of days to fetch info for."
+ (let ((old-time (nth 7 (assoc group nnultimate-groups))))
+ (if (null old-time)
+ 1000
+ (- (time-to-days time) (time-to-days old-time)))))
+
+(defun nnultimate-create-mapping (group)
+ (let* ((entry (assoc group nnultimate-groups))
+ (sid (nth 2 entry))
+ (topics (nth 4 entry))
+ (mapping (nth 5 entry))
+ (old-total (or (nth 6 entry) 1))
+ (current-time (current-time))
+ (furl
+ (concat "forumdisplay.cgi?action=topics&number=%d&DaysPrune="
+ (number-to-string
+ (nnultimate-prune-days group current-time))))
+ (furls (list (concat nnultimate-address (format furl sid))))
+ contents forum-contents furl-fetched a subject href
+ garticles topic tinfo old-max inc parse)
+ (mm-with-unibyte-buffer
+ (while furls
+ (erase-buffer)
+ (nnweb-insert (pop furls))
+ (goto-char (point-min))
+ (setq parse (w3-parse-buffer (current-buffer)))
+ (setq contents
+ (cdr (nth 2 (car (nth 2 (nnultimate-find-forum-table
+ parse))))))
+ (setq forum-contents (nconc contents forum-contents))
+ (unless furl-fetched
+ (setq furl-fetched t)
+ ;; On the first time through this loop, we find all the
+ ;; forum URLs.
+ (dolist (a (nnweb-parse-find-all 'a parse))
+ (let ((href (cdr (assq 'href (nth 1 a)))))
+ (when (and href
+ (string-match "forumdisplay.*startpoint" href))
+ (push href furls))))
+ (setq furls (nreverse furls))))
+ ;; The main idea here is to map Gnus article numbers to
+ ;; nnultimate article numbers. Say there are three topics in
+ ;; this forum, the first with 4 articles, the seconds with 2,
+ ;; and the third with 1. Then this will translate into 7 Gnus
+ ;; article numbers, where 1-4 comes from the first topic, 5-6
+ ;; from the second and 7 from the third. Now, then next time
+ ;; the group is entered, there's 2 new articles in topic one
+ ;; and 1 in topic three. Then Gnus article number 8-9 be 5-6
+ ;; in topic one and 10 will be the 2 in topic three.
+ (dolist (row (reverse forum-contents))
+ (setq row (nth 2 row))
+ (when (setq a (nnweb-parse-find 'a row))
+ (setq subject (car (last (nnweb-text a)))
+ href (cdr (assq 'href (nth 1 a))))
+ (let ((artlist (nreverse (nnweb-text row)))
+ art)
+ (while (and (not art)
+ artlist)
+ (when (string-match "^[0-9]+$" (car artlist))
+ (setq art (1+ (string-to-number (car artlist)))))
+ (pop artlist))
+ (setq garticles art))
+ (when garticles
+ (string-match "/\\([0-9]+\\).html" href)
+ (setq topic (string-to-number (match-string 1 href)))
+ (if (setq tinfo (assq topic topics))
+ (progn
+ (setq old-max (cadr tinfo))
+ (setcar (cdr tinfo) garticles))
+ (setq old-max 0)
+ (push (list topic garticles subject href) topics)
+ (setcar (nthcdr 4 entry) topics))
+ (when (not (= old-max garticles))
+ (setq inc (- garticles old-max))
+ (setq mapping (nconc mapping
+ (list
+ (list
+ old-total (1- (incf old-total inc))
+ topic (1+ old-max)))))
+ (incf old-max inc)
+ (setcar (nthcdr 5 entry) mapping)
+ (setcar (nthcdr 6 entry) old-total))))))
+ (setcar (nthcdr 7 entry) current-time)
+ (setcar (nthcdr 1 entry) (1- old-total))
+ (nnultimate-write-groups)
+ mapping))
+