+ (replace-match "\\1"))
+ (mm-url-decode-entities)
+ (buffer-string))
+
+(defun nnwarchive-egroups-xover-files (group articles)
+ (let (aux auxs)
+ (setq auxs (nnwarchive-paged (sort articles '<)))
+ (while (setq aux (pop auxs))
+ (goto-char (point-max))
+ (nnwarchive-url nnwarchive-xover-url))
+ (if nnwarchive-xover-dissect
+ (nnwarchive-egroups-xover group))))
+
+;; mail-archive
+
+(defun nnwarchive-mail-archive-list-groups (groups)
+ (save-excursion
+ (let (articles)
+ (set-buffer nnwarchive-buffer)
+ (dolist (group groups)
+ (erase-buffer)
+ (nnwarchive-url nnwarchive-xover-last-url)
+ (goto-char (point-min))
+ (when (re-search-forward "msg\\([0-9]+\\)\\.html" nil t)
+ (setq articles (1+ (string-to-number (match-string 1)))))
+ (let ((elem (assoc group nnwarchive-groups)))
+ (if elem
+ (setcar (cdr elem) articles)
+ (push (list group articles "") nnwarchive-groups)))
+ (setq nnwarchive-headers (cdr (assoc group nnwarchive-headers-cache)))
+ (nnwarchive-mail-archive-xover group)
+ (let ((elem (assoc group nnwarchive-headers-cache)))
+ (if elem
+ (setcdr elem nnwarchive-headers)
+ (push (cons group nnwarchive-headers)
+ nnwarchive-headers-cache)))))))
+
+(defun nnwarchive-mail-archive-list ()
+ (let ((case-fold-search t)
+ group description elem articles)
+ (goto-char (point-min))
+ (while (re-search-forward "<a href=\"\\([^/]+\\)/\">\\([^>]+\\)<" nil t)
+ (setq group (match-string 1)
+ description (match-string 2))
+ (forward-line 1)
+ (setq articles 0)
+ (if (setq elem (assoc group nnwarchive-groups))
+ (setcar (cdr elem) articles)
+ (push (list group articles description) nnwarchive-groups))))
+ t)
+
+(defun nnwarchive-mail-archive-xover (group)
+ (let (article subject from date)
+ (goto-char (point-min))
+ (while (re-search-forward
+ "<A[^>]*HREF=\"msg\\([0-9]+\\)\\.html[^>]+>\\([^<]+\\)<"
+ nil t)
+ (setq article (1+ (string-to-number (match-string 1)))
+ subject (match-string 2))
+ (forward-line 1)
+ (unless (assq article nnwarchive-headers)
+ (if (looking-at "<UL><LI><EM>From</EM>: *\\([^<]*[^< ]\\) *<\\([^&]+\\)>")
+ (progn
+ (setq from (match-string 1)
+ date (identity (match-string 2))))
+ (setq from "" date ""))
+ (push (cons
+ article
+ (make-full-mail-header
+ article
+ (mm-url-decode-entities-string subject)
+ (mm-url-decode-entities-string from)
+ date
+ (format "<%05d%%%s>\n" (1- article) group)
+ ""
+ 0 0 "")) nnwarchive-headers))))
+ nnwarchive-headers)
+
+(defun nnwarchive-mail-archive-xover-files (group articles)
+ (unless nnwarchive-headers
+ (erase-buffer)
+ (nnwarchive-url nnwarchive-xover-last-url)
+ (goto-char (point-min))
+ (nnwarchive-mail-archive-xover group))
+ (let ((minart (apply 'min articles))
+ (min (apply 'min (mapcar 'car nnwarchive-headers)))
+ (aux 2))
+ (while (> min minart)
+ (erase-buffer)
+ (nnwarchive-url nnwarchive-xover-url)
+ (nnwarchive-mail-archive-xover group)
+ (setq min (apply 'min (mapcar 'car nnwarchive-headers))))))
+
+(defvar nnwarchive-caesar-translation-table nil
+ "Modified rot13 table. tr/@A-Z[a-z/N-Z[@A-Mn-za-m/.")
+
+(defun nnwarchive-make-caesar-translation-table ()
+ "Create modified rot13 table. tr/@A-Z[a-z/N-Z[@A-Mn-za-m/."
+ (let ((i -1)
+ (table (make-string 256 0))
+ (a (mm-char-int ?a))
+ (A (mm-char-int ?A)))
+ (while (< (incf i) 256)
+ (aset table i i))
+ (concat
+ (substring table 0 (1- A))
+ (substring table (+ A 13) (+ A 27))
+ (substring table (1- A) (+ A 13))
+ (substring table (+ A 27) a)
+ (substring table (+ a 13) (+ a 26))
+ (substring table a (+ a 13))
+ (substring table (+ a 26) 255))))
+
+(defun nnwarchive-from-r13 (from-r13)
+ (when from-r13
+ (with-temp-buffer
+ (insert from-r13)
+ (let ((message-caesar-translation-table
+ (or nnwarchive-caesar-translation-table
+ (setq nnwarchive-caesar-translation-table
+ (nnwarchive-make-caesar-translation-table)))))
+ (message-caesar-region (point-min) (point-max))
+ (buffer-string)))))
+
+(defun nnwarchive-mail-archive-article (group article)
+ (let (p refs url mime e
+ from subject date id
+ done
+ (case-fold-search t))
+ (save-restriction
+ (goto-char (point-min))
+ (when (search-forward "X-Head-End" nil t)
+ (beginning-of-line)
+ (narrow-to-region (point-min) (point))
+ (mm-url-decode-entities)
+ (goto-char (point-min))
+ (while (search-forward "<!--X-" nil t)
+ (replace-match ""))
+ (goto-char (point-min))
+ (while (search-forward " -->" nil t)
+ (replace-match ""))
+ (setq from
+ (or (mail-fetch-field "from")
+ (nnwarchive-from-r13
+ (mail-fetch-field "from-r13"))))
+ (setq date (mail-fetch-field "date"))
+ (setq id (mail-fetch-field "message-id"))
+ (setq subject (mail-fetch-field "subject"))
+ (goto-char (point-max))
+ (widen))
+ (when (search-forward "<ul>" nil t)
+ (forward-line)
+ (delete-region (point-min) (point))
+ (search-forward "</ul>" nil t)
+ (end-of-line)
+ (narrow-to-region (point-min) (point))
+ (mm-url-remove-markup)
+ (mm-url-decode-entities)
+ (goto-char (point-min))
+ (delete-blank-lines)
+ (when from
+ (message-remove-header "from")
+ (goto-char (point-max))
+ (insert "From: " from "\n"))
+ (when subject
+ (message-remove-header "subject")
+ (goto-char (point-max))
+ (insert "Subject: " subject "\n"))
+ (when id
+ (goto-char (point-max))
+ (insert "X-Message-ID: <" id ">\n"))
+ (when date
+ (message-remove-header "date")
+ (goto-char (point-max))
+ (insert "Date: " date "\n"))
+ (goto-char (point-max))
+ (widen)
+ (insert "\n"))
+ (setq p (point))
+ (when (search-forward "X-Body-of-Message" nil t)
+ (forward-line)
+ (delete-region p (point))
+ (search-forward "X-Body-of-Message-End" nil t)
+ (beginning-of-line)
+ (save-restriction
+ (narrow-to-region p (point))
+ (goto-char (point-min))
+ (if (> (skip-chars-forward "\040\n\r\t") 0)
+ (delete-region (point-min) (point)))
+ (while (not (eobp))
+ (cond
+ ((looking-at "<PRE>\r?\n?")
+ (delete-region (match-beginning 0) (match-end 0))
+ (setq p (point))
+ (when (search-forward "</PRE>" nil t)
+ (delete-region (match-beginning 0) (match-end 0))
+ (save-restriction
+ (narrow-to-region p (point))
+ (mm-url-remove-markup)
+ (mm-url-decode-entities)
+ (goto-char (point-max)))))
+ ((looking-at "<P><A HREF=\"\\([^\"]+\\)")
+ (setq url (match-string 1))
+ (delete-region (match-beginning 0)
+ (progn (forward-line) (point)))
+ ;; I hate to download the url encode it, then immediately
+ ;; decode it.
+ (insert "<#external"
+ " type="
+ (or (and url
+ (string-match "\\.[^\\.]+$" url)
+ (mailcap-extension-to-mime
+ (match-string 0 url)))
+ "application/octet-stream")
+ (format " url=\"http://www.mail-archive.com/%s/%s\""
+ group url)
+ ">\n"
+ "<#/external>")
+ (setq mime t))
+ (t
+ (setq p (point))
+ (insert "<#part type=\"text/html\" disposition=inline>")
+ (goto-char
+ (if (re-search-forward
+ "[\040\n\r\t]*<PRE>\\|[\040\n\r\t]*<P><A HREF=\""
+ nil t)
+ (match-beginning 0)
+ (point-max)))
+ (insert "<#/part>")
+ (setq mime t)))
+ (setq p (point))
+ (if (> (skip-chars-forward "\040\n\r\t") 0)
+ (delete-region p (point))))
+ (goto-char (point-max))))
+ (setq p (point))
+ (when (search-forward "X-References-End" nil t)
+ (setq e (point))
+ (beginning-of-line)
+ (search-backward "X-References" p t)
+ (while (re-search-forward "msg\\([0-9]+\\)\\.html" e t)
+ (push (concat "<" (match-string 1) "%" group ">") refs)))
+ (delete-region p (point-max))
+ (goto-char (point-min))
+ (insert (format "Message-ID: <%05d%%%s>\n" (1- article) group))
+ (when refs
+ (insert "References:")
+ (while refs
+ (insert " " (pop refs)))
+ (insert "\n"))
+ (when mime
+ (unless (looking-at "$")
+ (search-forward "\n\n" nil t)
+ (forward-line -1))
+ (narrow-to-region (point) (point-max))
+ (insert "MIME-Version: 1.0\n"
+ (prog1
+ (mml-generate-mime)
+ (delete-region (point-min) (point-max))))
+ (widen)))
+ (buffer-string)))