nndoc.el 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. ;;; nndoc.el --- single file access for Gnus
  2. ;; Copyright (C) 1995-2015 Free Software Foundation, Inc.
  3. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  4. ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
  5. ;; Keywords: news
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; For Outlook mail boxes format, see http://mbx2mbox.sourceforge.net/
  19. ;;; Code:
  20. (require 'nnheader)
  21. (require 'message)
  22. (require 'nnmail)
  23. (require 'nnoo)
  24. (require 'gnus-util)
  25. (require 'mm-util)
  26. (eval-when-compile (require 'cl))
  27. (nnoo-declare nndoc)
  28. (defvoo nndoc-article-type 'guess
  29. "*Type of the file.
  30. One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward',
  31. `rfc934', `rfc822-forward', `mime-parts', `standard-digest',
  32. `slack-digest', `clari-briefs', `nsmail', `outlook', `oe-dbx',
  33. `mailman', `exim-bounce', or `guess'.")
  34. (defvoo nndoc-post-type 'mail
  35. "*Whether the nndoc group is `mail' or `post'.")
  36. (defvoo nndoc-open-document-hook 'nnheader-ms-strip-cr
  37. "Hook run after opening a document.
  38. The default function removes all trailing carriage returns
  39. from the document.")
  40. (defvar nndoc-type-alist
  41. `((mmdf
  42. (article-begin . "^\^A\^A\^A\^A\n")
  43. (body-end . "^\^A\^A\^A\^A\n"))
  44. (debbugs-db
  45. (file-begin . "^\005")
  46. (article-begin . "^[\005\007]\n")
  47. (body-end . "^\003"))
  48. (mime-digest
  49. (article-begin . "")
  50. (head-begin . "^ ?\n")
  51. (head-end . "^ ?$")
  52. (body-end . "")
  53. (file-end . "")
  54. (subtype digest guess))
  55. (nsmail
  56. (article-begin . "^From - "))
  57. (news
  58. (article-begin . "^Path:"))
  59. (rnews
  60. (article-begin . "^#! *rnews +\\([0-9]+\\) *\n")
  61. (body-end-function . nndoc-rnews-body-end))
  62. (mbox
  63. (article-begin-function . nndoc-mbox-article-begin)
  64. (body-end-function . nndoc-mbox-body-end))
  65. (babyl
  66. (article-begin . "\^_\^L *\n")
  67. (body-end . "\^_")
  68. (body-begin-function . nndoc-babyl-body-begin)
  69. (head-begin-function . nndoc-babyl-head-begin))
  70. (mime-parts
  71. (generate-head-function . nndoc-generate-mime-parts-head)
  72. (article-transform-function . nndoc-transform-mime-parts))
  73. (exim-bounce
  74. (article-begin . "^------ This is a copy of the message, including all the headers. ------\n\n")
  75. (body-end-function . nndoc-exim-bounce-body-end-function))
  76. (rfc934
  77. (article-begin . "^--.*\n+")
  78. (body-end . "^--.*$")
  79. (prepare-body-function . nndoc-unquote-dashes))
  80. (mailman
  81. (article-begin . "^--__--__--\n\nMessage:")
  82. (body-end . "^--__--__--$")
  83. (prepare-body-function . nndoc-unquote-dashes))
  84. (clari-briefs
  85. (article-begin . "^ \\*")
  86. (body-end . "^\t------*[ \t]^*\n^ \\*")
  87. (body-begin . "^\t")
  88. (head-end . "^\t")
  89. (generate-head-function . nndoc-generate-clari-briefs-head)
  90. (article-transform-function . nndoc-transform-clari-briefs))
  91. (standard-digest
  92. (first-article . ,(concat "^" (make-string 70 ?-) "\n *\n+"))
  93. (article-begin . ,(concat "^\n" (make-string 30 ?-) "\n *\n+"))
  94. (prepare-body-function . nndoc-unquote-dashes)
  95. (body-end-function . nndoc-digest-body-end)
  96. (head-end . "^ *$")
  97. (body-begin . "^ *\n")
  98. (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")
  99. (subtype digest guess))
  100. (slack-digest
  101. (article-begin . "^------------------------------*[\n \t]+")
  102. (head-end . "^ ?$")
  103. (body-end-function . nndoc-digest-body-end)
  104. (body-begin . "^ ?$")
  105. (file-end . "^End of")
  106. (prepare-body-function . nndoc-unquote-dashes)
  107. (subtype digest guess))
  108. (google
  109. (pre-dissection-function . nndoc-decode-content-transfer-encoding)
  110. (article-begin . "^== [0-9]+ of [0-9]+ ==$")
  111. (head-begin . "^Date:")
  112. (head-end . "^$")
  113. (body-end-function . nndoc-digest-body-end)
  114. (body-begin . "^$")
  115. (file-end . "^==============================================================================$")
  116. (prepare-body-function . nndoc-unquote-dashes)
  117. (subtype digest guess))
  118. (lanl-gov-announce
  119. (article-begin . "^\\\\\\\\\n")
  120. (head-begin . "^\\(Paper.*:\\|arXiv:\\)")
  121. (head-end . "\\(^\\\\\\\\.*\n\\|-----------------\\)")
  122. (body-begin . "")
  123. (body-end . "\\(-------------------------------------------------\\|%-%-%-%-%-%-%-%-%-%-%-%-%-%-\\|%%--%%--%%--%%--%%--%%--%%--%%--\\|%%%---%%%---%%%---%%%---\\)")
  124. (file-end . "\\(^Title: Recent Seminal\\|%%%---%%%---%%%---%%%---\\)")
  125. (generate-head-function . nndoc-generate-lanl-gov-head)
  126. (article-transform-function . nndoc-transform-lanl-gov-announce)
  127. (subtype preprints guess))
  128. (git
  129. (file-begin . "\n- Log ---.*")
  130. (article-begin . "^commit ")
  131. (head-begin . "^Author: ")
  132. (body-begin . "^$")
  133. (file-end . "\n-----------------------------------------------------------------------")
  134. (article-transform-function . nndoc-transform-git-article)
  135. (header-transform-function . nndoc-transform-git-headers))
  136. (rfc822-forward
  137. (article-begin . "^\n+")
  138. (body-end-function . nndoc-rfc822-forward-body-end-function)
  139. (generate-head-function . nndoc-rfc822-forward-generate-head)
  140. (generate-article-function . nndoc-rfc822-forward-generate-article))
  141. (outlook
  142. (article-begin-function . nndoc-outlook-article-begin)
  143. (body-end . "\0"))
  144. (oe-dbx ;; Outlook Express DBX format
  145. (dissection-function . nndoc-oe-dbx-dissection)
  146. (generate-head-function . nndoc-oe-dbx-generate-head)
  147. (generate-article-function . nndoc-oe-dbx-generate-article))
  148. (forward
  149. (article-begin . "^-+ \\(Start of \\)?forwarded message.*\n+")
  150. (body-end . "^-+ End \\(of \\)?forwarded message.*$")
  151. (prepare-body-function . nndoc-unquote-dashes))
  152. (mail-in-mail ;; Wild guess on mailer daemon's messages or others
  153. (article-begin-function . nndoc-mail-in-mail-article-begin))
  154. (guess
  155. (guess . t)
  156. (subtype nil))
  157. (digest
  158. (guess . t)
  159. (subtype nil))
  160. (preprints
  161. (guess . t)
  162. (subtype nil))))
  163. (defvar nndoc-binary-file-names ".[Dd][Bb][Xx]$"
  164. "Regexp for binary nndoc file names.")
  165. (defvoo nndoc-file-begin nil)
  166. (defvoo nndoc-first-article nil)
  167. (defvoo nndoc-article-begin nil)
  168. (defvoo nndoc-head-begin nil)
  169. (defvoo nndoc-head-end nil)
  170. (defvoo nndoc-file-end nil)
  171. (defvoo nndoc-body-begin nil)
  172. (defvoo nndoc-body-end-function nil)
  173. (defvoo nndoc-body-begin-function nil)
  174. (defvoo nndoc-head-begin-function nil)
  175. (defvoo nndoc-body-end nil)
  176. ;; nndoc-dissection-alist is a list of sublists. Each sublist holds the
  177. ;; following items. ARTICLE acts as the association key and is an ordinal
  178. ;; starting at 1. HEAD-BEGIN [0], HEAD-END [1], BODY-BEGIN [2] and BODY-END
  179. ;; [3] are positions in the `nndoc' buffer. LINE-COUNT [4] is a count of
  180. ;; lines in the body. For MIME dissections only, ARTICLE-INSERT [5] and
  181. ;; SUMMARY-INSERT [6] give headers to insert for full article or summary line
  182. ;; generation, respectively. Other headers usually follow directly from the
  183. ;; buffer. Value nil means no insert.
  184. (defvoo nndoc-dissection-alist nil)
  185. (defvoo nndoc-prepare-body-function nil)
  186. (defvoo nndoc-generate-head-function nil)
  187. (defvoo nndoc-article-transform-function nil)
  188. (defvoo nndoc-header-transform-function nil)
  189. (defvoo nndoc-article-begin-function nil)
  190. (defvoo nndoc-generate-article-function nil)
  191. (defvoo nndoc-dissection-function nil)
  192. (defvoo nndoc-pre-dissection-function nil)
  193. (defvoo nndoc-status-string "")
  194. (defvoo nndoc-group-alist nil)
  195. (defvoo nndoc-current-buffer nil
  196. "Current nndoc news buffer.")
  197. (defvoo nndoc-address nil)
  198. (defconst nndoc-version "nndoc 1.0"
  199. "nndoc version.")
  200. ;;; Interface functions
  201. (nnoo-define-basics nndoc)
  202. (deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old)
  203. (when (nndoc-possibly-change-buffer newsgroup server)
  204. (with-current-buffer nntp-server-buffer
  205. (erase-buffer)
  206. (let (article entry)
  207. (if (stringp (car articles))
  208. 'headers
  209. (while articles
  210. (when (setq entry (cdr (assq (setq article (pop articles))
  211. nndoc-dissection-alist)))
  212. (let ((start (point)))
  213. (insert (format "221 %d Article retrieved.\n" article))
  214. (if nndoc-generate-head-function
  215. (funcall nndoc-generate-head-function article)
  216. (insert-buffer-substring
  217. nndoc-current-buffer (car entry) (nth 1 entry)))
  218. (goto-char (point-max))
  219. (unless (eq (char-after (1- (point))) ?\n)
  220. (insert "\n"))
  221. (insert (format "Lines: %d\n" (nth 4 entry)))
  222. (insert ".\n")
  223. (when nndoc-header-transform-function
  224. (save-excursion
  225. (save-restriction
  226. (narrow-to-region start (point))
  227. (funcall nndoc-header-transform-function entry)))))))
  228. (nnheader-fold-continuation-lines)
  229. 'headers)))))
  230. (deffoo nndoc-request-article (article &optional newsgroup server buffer)
  231. (nndoc-possibly-change-buffer newsgroup server)
  232. (save-excursion
  233. (let ((buffer (or buffer nntp-server-buffer))
  234. (entry (cdr (assq article nndoc-dissection-alist)))
  235. beg)
  236. (set-buffer buffer)
  237. (erase-buffer)
  238. (when entry
  239. (cond
  240. ((stringp article) nil)
  241. (nndoc-generate-article-function
  242. (funcall nndoc-generate-article-function article))
  243. (t
  244. (insert-buffer-substring
  245. nndoc-current-buffer (car entry) (nth 1 entry))
  246. (insert "\n")
  247. (setq beg (point))
  248. (insert-buffer-substring
  249. nndoc-current-buffer (nth 2 entry) (nth 3 entry))
  250. (goto-char beg)
  251. (when nndoc-prepare-body-function
  252. (funcall nndoc-prepare-body-function))
  253. (when nndoc-article-transform-function
  254. (funcall nndoc-article-transform-function article))
  255. t))))))
  256. (deffoo nndoc-request-group (group &optional server dont-check info)
  257. "Select news GROUP."
  258. (let (number)
  259. (cond
  260. ((not (nndoc-possibly-change-buffer group server))
  261. (nnheader-report 'nndoc "No such file or buffer: %s"
  262. nndoc-address))
  263. (dont-check
  264. (nnheader-report 'nndoc "Selected group %s" group)
  265. t)
  266. ((zerop (setq number (length nndoc-dissection-alist)))
  267. (nndoc-close-group group)
  268. (nnheader-report 'nndoc "No articles in group %s" group))
  269. (t
  270. (nnheader-insert "211 %d %d %d %s\n" number 1 number group)))))
  271. (deffoo nndoc-retrieve-groups (groups &optional server)
  272. (dolist (group groups)
  273. (nndoc-request-group group server))
  274. t)
  275. (deffoo nndoc-request-type (group &optional article)
  276. (cond ((not article) 'unknown)
  277. (nndoc-post-type nndoc-post-type)
  278. (t 'unknown)))
  279. (deffoo nndoc-close-group (group &optional server)
  280. (nndoc-possibly-change-buffer group server)
  281. (and nndoc-current-buffer
  282. (buffer-name nndoc-current-buffer)
  283. (kill-buffer nndoc-current-buffer))
  284. (setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
  285. nndoc-group-alist))
  286. (setq nndoc-current-buffer nil)
  287. (nnoo-close-server 'nndoc server)
  288. (setq nndoc-dissection-alist nil)
  289. t)
  290. (deffoo nndoc-request-list (&optional server)
  291. t)
  292. (deffoo nndoc-request-newgroups (date &optional server)
  293. nil)
  294. (deffoo nndoc-request-list-newsgroups (&optional server)
  295. nil)
  296. ;;; Internal functions.
  297. (defun nndoc-possibly-change-buffer (group source)
  298. (let (buf)
  299. (cond
  300. ;; The current buffer is this group's buffer.
  301. ((and nndoc-current-buffer
  302. (buffer-name nndoc-current-buffer)
  303. (eq nndoc-current-buffer
  304. (setq buf (cdr (assoc group nndoc-group-alist))))))
  305. ;; We change buffers by taking an old from the group alist.
  306. ;; `source' is either a string (a file name) or a buffer object.
  307. (buf
  308. (setq nndoc-current-buffer buf))
  309. ;; It's a totally new group.
  310. ((or (and (bufferp nndoc-address)
  311. (buffer-name nndoc-address))
  312. (and (stringp nndoc-address)
  313. (file-exists-p nndoc-address)
  314. (not (file-directory-p nndoc-address))))
  315. (push (cons group (setq nndoc-current-buffer
  316. (get-buffer-create
  317. (concat " *nndoc " group "*"))))
  318. nndoc-group-alist)
  319. (setq nndoc-dissection-alist nil)
  320. (with-current-buffer nndoc-current-buffer
  321. (erase-buffer)
  322. (if (and (stringp nndoc-address)
  323. (string-match nndoc-binary-file-names nndoc-address))
  324. (let ((coding-system-for-read 'binary))
  325. (mm-insert-file-contents nndoc-address))
  326. (if (stringp nndoc-address)
  327. (nnheader-insert-file-contents nndoc-address)
  328. (insert-buffer-substring nndoc-address))
  329. (run-hooks 'nndoc-open-document-hook)))))
  330. ;; Initialize the nndoc structures according to this new document.
  331. (when (and nndoc-current-buffer
  332. (not nndoc-dissection-alist))
  333. (with-current-buffer nndoc-current-buffer
  334. (nndoc-set-delims)
  335. (if (eq nndoc-article-type 'mime-parts)
  336. (nndoc-dissect-mime-parts)
  337. (nndoc-dissect-buffer))))
  338. (unless nndoc-current-buffer
  339. (nndoc-close-server))
  340. ;; Return whether we managed to select a file.
  341. nndoc-current-buffer))
  342. ;;;
  343. ;;; Deciding what document type we have
  344. ;;;
  345. (defun nndoc-set-delims ()
  346. "Set the nndoc delimiter variables according to the type of the document."
  347. (let ((vars '(nndoc-file-begin
  348. nndoc-first-article
  349. nndoc-article-begin-function
  350. nndoc-head-begin nndoc-head-end
  351. nndoc-file-end nndoc-article-begin
  352. nndoc-body-begin nndoc-body-end-function nndoc-body-end
  353. nndoc-prepare-body-function nndoc-article-transform-function
  354. nndoc-header-transform-function
  355. nndoc-generate-head-function nndoc-body-begin-function
  356. nndoc-head-begin-function
  357. nndoc-generate-article-function
  358. nndoc-dissection-function
  359. nndoc-pre-dissection-function)))
  360. (while vars
  361. (set (pop vars) nil)))
  362. (let (defs)
  363. ;; Guess away until we find the real file type.
  364. (while (assq 'guess (setq defs (cdr (assq nndoc-article-type
  365. nndoc-type-alist))))
  366. (setq nndoc-article-type (nndoc-guess-type nndoc-article-type)))
  367. ;; Set the nndoc variables.
  368. (while defs
  369. (set (intern (format "nndoc-%s" (caar defs)))
  370. (cdr (pop defs))))))
  371. (defun nndoc-guess-type (subtype)
  372. (let ((alist nndoc-type-alist)
  373. results result entry)
  374. (while (and (not result)
  375. (setq entry (pop alist)))
  376. (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess)))
  377. (goto-char (point-min))
  378. ;; Remove blank lines.
  379. (while (eq (following-char) ?\n)
  380. (delete-char 1))
  381. (when (numberp (setq result (funcall (intern
  382. (format "nndoc-%s-type-p"
  383. (car entry))))))
  384. (push (cons result entry) results)
  385. (setq result nil))))
  386. (unless (or result results)
  387. (error "Document is not of any recognized type"))
  388. (if result
  389. (car entry)
  390. (cadar (last (sort results 'car-less-than-car))))))
  391. ;;;
  392. ;;; Built-in type predicates and functions
  393. ;;;
  394. (defun nndoc-mbox-type-p ()
  395. (when (looking-at message-unix-mail-delimiter)
  396. t))
  397. (defun nndoc-mbox-article-begin ()
  398. (when (re-search-forward (concat "^" message-unix-mail-delimiter) nil t)
  399. (goto-char (match-beginning 0))))
  400. (defun nndoc-mbox-body-end ()
  401. (let ((beg (point))
  402. len end)
  403. (when
  404. (save-excursion
  405. (and (re-search-backward
  406. (concat "^" message-unix-mail-delimiter) nil t)
  407. (setq end (point))
  408. (search-forward "\n\n" beg t)
  409. (re-search-backward
  410. "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t)
  411. (setq len (string-to-number (match-string 1)))
  412. (search-forward "\n\n" beg t)
  413. (unless (= (setq len (+ (point) len)) (point-max))
  414. (and (< len (point-max))
  415. (goto-char len)
  416. (looking-at message-unix-mail-delimiter)))))
  417. (goto-char len))))
  418. (defun nndoc-mmdf-type-p ()
  419. (when (looking-at "\^A\^A\^A\^A$")
  420. t))
  421. (defun nndoc-debbugs-db-type-p ()
  422. (when (looking-at "\006$")
  423. t))
  424. (defun nndoc-news-type-p ()
  425. (when (looking-at "^Path:.*\n")
  426. t))
  427. (defun nndoc-rnews-type-p ()
  428. (when (looking-at "#! *rnews")
  429. t))
  430. (defun nndoc-rnews-body-end ()
  431. (and (re-search-backward nndoc-article-begin nil t)
  432. (forward-line 1)
  433. (goto-char (+ (point) (string-to-number (match-string 1))))))
  434. (defun nndoc-google-type-p ()
  435. (when (re-search-forward "^=3D=3D 1 of [0-9]+ =3D=3D$" nil t)
  436. t))
  437. (defun nndoc-decode-content-transfer-encoding ()
  438. (let ((encoding
  439. (save-restriction
  440. (message-narrow-to-head)
  441. (message-fetch-field "content-transfer-encoding"))))
  442. (when (and encoding
  443. (search-forward "\n\n" nil t))
  444. (save-restriction
  445. (narrow-to-region (point) (point-max))
  446. (mm-decode-content-transfer-encoding
  447. (intern (downcase (mail-header-strip encoding))))))))
  448. (defun nndoc-babyl-type-p ()
  449. (when (re-search-forward "\^_\^L *\n" nil t)
  450. t))
  451. (defun nndoc-babyl-body-begin ()
  452. (re-search-forward "^\n" nil t)
  453. (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
  454. (let ((next (or (save-excursion
  455. (re-search-forward nndoc-article-begin nil t))
  456. (point-max))))
  457. (unless (re-search-forward "^\n" next t)
  458. (goto-char next)
  459. (forward-line -1)
  460. (insert "\n")
  461. (forward-line -1)))))
  462. (defun nndoc-babyl-head-begin ()
  463. (when (re-search-forward "^[0-9].*\n" nil t)
  464. (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
  465. (forward-line 1))
  466. t))
  467. (defun nndoc-forward-type-p ()
  468. (when (and (re-search-forward "^-+ \\(Start of \\)?forwarded message.*\n+"
  469. nil t)
  470. (looking-at "[\r\n]*[a-zA-Z][a-zA-Z0-9-]*:\\|^>?From "))
  471. t))
  472. (defun nndoc-rfc934-type-p ()
  473. (when (and (re-search-forward "^-+ Start of forwarded.*\n+" nil t)
  474. (not (re-search-forward "^Subject:.*digest" nil t))
  475. (not (re-search-backward "^From:" nil t 2))
  476. (not (re-search-forward "^From:" nil t 2)))
  477. t))
  478. (defun nndoc-mailman-type-p ()
  479. (when (re-search-forward "^--__--__--\n+" nil t)
  480. t))
  481. (defun nndoc-rfc822-forward-type-p ()
  482. (save-restriction
  483. (message-narrow-to-head)
  484. (when (re-search-forward "^Content-Type: *message/rfc822" nil t)
  485. t)))
  486. (defun nndoc-rfc822-forward-body-end-function ()
  487. (goto-char (point-max)))
  488. (defun nndoc-rfc822-forward-generate-article (article &optional head)
  489. (let ((entry (cdr (assq article nndoc-dissection-alist)))
  490. (begin (point))
  491. encoding)
  492. (with-current-buffer nndoc-current-buffer
  493. (save-restriction
  494. (message-narrow-to-head)
  495. (setq encoding (message-fetch-field "content-transfer-encoding"))))
  496. (insert-buffer-substring nndoc-current-buffer (car entry) (nth 3 entry))
  497. (when encoding
  498. (save-restriction
  499. (narrow-to-region begin (point-max))
  500. (mm-decode-content-transfer-encoding
  501. (intern (downcase (mail-header-strip encoding))))))
  502. (when head
  503. (goto-char begin)
  504. (when (search-forward "\n\n" nil t)
  505. (delete-region (1- (point)) (point-max)))))
  506. t)
  507. (defun nndoc-rfc822-forward-generate-head (article)
  508. (nndoc-rfc822-forward-generate-article article 'head))
  509. (defun nndoc-mime-parts-type-p ()
  510. (let ((case-fold-search t)
  511. (limit (search-forward "\n\n" nil t)))
  512. (goto-char (point-min))
  513. (when (and limit
  514. (re-search-forward
  515. (concat "\
  516. ^Content-Type:[ \t]*multipart/[a-z]+ *; *\\(\\(\n[ \t]\\)?.*;\\)*"
  517. "\\(\n[ \t]\\)?[ \t]*boundary=\"?[^\"\n]*[^\" \t\n]")
  518. limit t))
  519. t)))
  520. (defun nndoc-transform-mime-parts (article)
  521. (let* ((entry (cdr (assq article nndoc-dissection-alist)))
  522. (headers (nth 5 entry)))
  523. (when headers
  524. (goto-char (point-min))
  525. (insert headers))))
  526. (defun nndoc-generate-mime-parts-head (article)
  527. (let* ((entry (cdr (assq article nndoc-dissection-alist)))
  528. (headers (nth 6 entry)))
  529. (save-restriction
  530. (narrow-to-region (point) (point))
  531. (insert-buffer-substring
  532. nndoc-current-buffer (car entry) (nth 1 entry))
  533. (goto-char (point-max)))
  534. (when headers
  535. (insert headers))))
  536. (defun nndoc-clari-briefs-type-p ()
  537. (when (let ((case-fold-search nil))
  538. (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t))
  539. t))
  540. (defun nndoc-transform-clari-briefs (article)
  541. (goto-char (point-min))
  542. (when (looking-at " *\\*\\(.*\\)\n")
  543. (replace-match "" t t))
  544. (nndoc-generate-clari-briefs-head article))
  545. (defun nndoc-generate-clari-briefs-head (article)
  546. (let ((entry (cdr (assq article nndoc-dissection-alist)))
  547. subject from)
  548. (with-current-buffer nndoc-current-buffer
  549. (save-restriction
  550. (narrow-to-region (car entry) (nth 3 entry))
  551. (goto-char (point-min))
  552. (when (looking-at " *\\*\\(.*\\)$")
  553. (setq subject (match-string 1))
  554. (when (string-match "[ \t]+$" subject)
  555. (setq subject (substring subject 0 (match-beginning 0)))))
  556. (when
  557. (let ((case-fold-search nil))
  558. (re-search-forward
  559. "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t))
  560. (setq from (match-string 1)))))
  561. (insert "From: " "clari@clari.net (" (or from "unknown") ")"
  562. "\nSubject: " (or subject "(no subject)") "\n")))
  563. (defun nndoc-exim-bounce-type-p ()
  564. (and (re-search-forward "^------ This is a copy of the message, including all the headers. ------" nil t)
  565. t))
  566. (defun nndoc-exim-bounce-body-end-function ()
  567. (goto-char (point-max)))
  568. (defun nndoc-mime-digest-type-p ()
  569. (let ((case-fold-search t)
  570. boundary-id b-delimiter entry)
  571. (when (and
  572. (re-search-forward
  573. (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]"
  574. "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)")
  575. nil t)
  576. (match-beginning 1))
  577. (setq boundary-id (match-string 1)
  578. b-delimiter (concat "\n--" boundary-id "[ \t]*$"))
  579. (setq entry (assq 'mime-digest nndoc-type-alist))
  580. (setcdr entry
  581. (list
  582. (cons 'head-begin "^ ?\n")
  583. (cons 'head-end "^ ?$")
  584. (cons 'body-begin "^ ?\n")
  585. (cons 'article-begin b-delimiter)
  586. (cons 'body-end-function 'nndoc-digest-body-end)
  587. (cons 'file-end (concat "^--" boundary-id "--[ \t]*$"))))
  588. t)))
  589. (defun nndoc-standard-digest-type-p ()
  590. (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t)
  591. (re-search-forward
  592. (concat "\n\n" (make-string 30 ?-) "\n\n") nil t))
  593. t))
  594. (defun nndoc-digest-body-end ()
  595. (and (re-search-forward nndoc-article-begin nil t)
  596. (goto-char (match-beginning 0))))
  597. (defun nndoc-slack-digest-type-p ()
  598. 0)
  599. (defun nndoc-git-type-p ()
  600. (and (search-forward "\n- Log ---" nil t)
  601. (search-forward "\ncommit " nil t)
  602. (search-forward "\nAuthor: " nil t)))
  603. (defun nndoc-transform-git-article (article)
  604. (goto-char (point-min))
  605. (when (re-search-forward "^Author: " nil t)
  606. (replace-match "From: " t t)))
  607. (defun nndoc-transform-git-headers (entry)
  608. (goto-char (point-min))
  609. (when (re-search-forward "^Author: " nil t)
  610. (replace-match "From: " t t))
  611. (let (subject)
  612. (with-current-buffer nndoc-current-buffer
  613. (goto-char (car entry))
  614. (when (search-forward "\n\n" nil t)
  615. (setq subject (buffer-substring (point) (line-end-position)))))
  616. (when subject
  617. (goto-char (point-min))
  618. (forward-line 1)
  619. (insert (format "Subject: %s\n" subject)))))
  620. (defun nndoc-lanl-gov-announce-type-p ()
  621. (when (let ((case-fold-search nil))
  622. (re-search-forward "^\\\\\\\\\n\\(Paper\\( (\\*cross-listing\\*)\\)?: [a-zA-Z-\\.]+/[0-9]+\\|arXiv:\\)" nil t))
  623. t))
  624. (defun nndoc-transform-lanl-gov-announce (article)
  625. (let ((case-fold-search nil))
  626. (goto-char (point-max))
  627. (when (re-search-backward "^\\\\\\\\ +( *\\([^ ]*\\) , *\\([^ ]*\\))" nil t)
  628. (replace-match "\n\nGet it at \\1 (\\2)" t nil))
  629. (goto-char (point-min))
  630. (while (re-search-forward "^\\\\\\\\$" nil t)
  631. (replace-match "" t nil))
  632. (goto-char (point-min))
  633. (when (re-search-forward "^replaced with revised version +\\(.*[^ ]\\) +" nil t)
  634. (replace-match "Date: \\1 (revised) " t nil))
  635. (goto-char (point-min))
  636. (unless (re-search-forward "^From" nil t)
  637. (goto-char (point-min))
  638. (when (re-search-forward "^Authors?: \\(.*\\)" nil t)
  639. (goto-char (point-min))
  640. (insert "From: " (match-string 1) "\n")))
  641. (when (re-search-forward "^arXiv:" nil t)
  642. (replace-match "Paper: arXiv:" t nil))))
  643. (defun nndoc-generate-lanl-gov-head (article)
  644. (let ((entry (cdr (assq article nndoc-dissection-alist)))
  645. (from "<no address given>")
  646. subject date)
  647. (with-current-buffer nndoc-current-buffer
  648. (save-restriction
  649. (narrow-to-region (car entry) (nth 1 entry))
  650. (goto-char (point-min))
  651. (when (looking-at "^\\(Paper.*: \\|arXiv:\\)\\([0-9a-zA-Z-\\./]+\\)")
  652. (setq subject (concat " (" (match-string 2) ")"))
  653. (when (re-search-forward "^From: \\(.*\\)" nil t)
  654. (setq from (concat "<"
  655. (cadr (funcall gnus-extract-address-components
  656. (match-string 1))) ">")))
  657. (if (re-search-forward "^Date: +\\([^(]*\\)" nil t)
  658. (setq date (match-string 1))
  659. (when (re-search-forward "^replaced with revised version +\\([^(]*\\)" nil t)
  660. (setq date (match-string 1))))
  661. (when (re-search-forward "^Title: \\([^\f]*\\)\nAuthors?: \\(.*\\)"
  662. nil t)
  663. (setq subject (concat (match-string 1) subject))
  664. (setq from (concat (match-string 2) " " from))))))
  665. (while (and from (string-match "([^)]*)" from))
  666. (setq from (replace-match "" t t from)))
  667. (insert "From: " (or from "unknown")
  668. "\nSubject: " (or subject "(no subject)") "\n")
  669. (if date (insert "Date: " date))))
  670. (defun nndoc-nsmail-type-p ()
  671. (when (looking-at "From - ")
  672. t))
  673. (defun nndoc-outlook-article-begin ()
  674. (prog1 (re-search-forward "From:\\|Received:" nil t)
  675. (goto-char (match-beginning 0))))
  676. (defun nndoc-outlook-type-p ()
  677. ;; FIXME: Is JMF the magic of outlook mailbox? -- ShengHuo.
  678. (looking-at "JMF"))
  679. (defun nndoc-oe-dbx-type-p ()
  680. (looking-at (mm-string-to-multibyte "\317\255\022\376")))
  681. (defun nndoc-read-little-endian ()
  682. (+ (prog1 (char-after) (forward-char 1))
  683. (lsh (prog1 (char-after) (forward-char 1)) 8)
  684. (lsh (prog1 (char-after) (forward-char 1)) 16)
  685. (lsh (prog1 (char-after) (forward-char 1)) 24)))
  686. (defun nndoc-oe-dbx-decode-block ()
  687. (list
  688. (nndoc-read-little-endian) ;; this address
  689. (nndoc-read-little-endian) ;; next address offset
  690. (nndoc-read-little-endian) ;; blocksize
  691. (nndoc-read-little-endian))) ;; next address
  692. (defun nndoc-oe-dbx-dissection ()
  693. (let ((i 0) blk p tp)
  694. (goto-char 60117) ;; 0x0000EAD4+1
  695. (setq p (point))
  696. (unless (eobp)
  697. (setq blk (nndoc-oe-dbx-decode-block)))
  698. (while (and blk (> (car blk) 0) (or (zerop (nth 3 blk))
  699. (> (nth 3 blk) p)))
  700. (push (list (incf i) p nil nil nil 0) nndoc-dissection-alist)
  701. (while (and (> (car blk) 0) (> (nth 3 blk) p))
  702. (goto-char (1+ (nth 3 blk)))
  703. (setq blk (nndoc-oe-dbx-decode-block)))
  704. (if (or (<= (car blk) p)
  705. (<= (nth 1 blk) 0)
  706. (not (zerop (nth 3 blk))))
  707. (setq blk nil)
  708. (setq tp (+ (car blk) (nth 1 blk) 17))
  709. (if (or (<= tp p) (>= tp (point-max)))
  710. (setq blk nil)
  711. (goto-char tp)
  712. (setq p tp
  713. blk (nndoc-oe-dbx-decode-block)))))))
  714. (defun nndoc-oe-dbx-generate-article (article &optional head)
  715. (let ((entry (cdr (assq article nndoc-dissection-alist)))
  716. (cur (current-buffer))
  717. (begin (point))
  718. blk p)
  719. (with-current-buffer nndoc-current-buffer
  720. (setq p (car entry))
  721. (while (> p (point-min))
  722. (goto-char p)
  723. (setq blk (nndoc-oe-dbx-decode-block))
  724. (setq p (point))
  725. (with-current-buffer cur
  726. (insert-buffer-substring nndoc-current-buffer p (+ p (nth 2 blk))))
  727. (setq p (1+ (nth 3 blk)))))
  728. (goto-char begin)
  729. (while (re-search-forward "\r$" nil t)
  730. (delete-char -1))
  731. (when head
  732. (goto-char begin)
  733. (when (search-forward "\n\n" nil t)
  734. (setcar (cddddr entry) (count-lines (point) (point-max)))
  735. (delete-region (1- (point)) (point-max))))
  736. t))
  737. (defun nndoc-oe-dbx-generate-head (article)
  738. (nndoc-oe-dbx-generate-article article 'head))
  739. (defun nndoc-mail-in-mail-type-p ()
  740. (let (found)
  741. (save-excursion
  742. (catch 'done
  743. (while (re-search-forward "\n\n[-A-Za-z0-9]+:" nil t)
  744. (setq found 0)
  745. (forward-line)
  746. (while (looking-at "[ \t]\\|[-A-Za-z0-9]+:")
  747. (if (looking-at "[-A-Za-z0-9]+:")
  748. (setq found (1+ found)))
  749. (forward-line))
  750. (if (and (> found 0) (looking-at "\n"))
  751. (throw 'done 9999)))
  752. nil))))
  753. (defun nndoc-mail-in-mail-article-begin ()
  754. (let (point found)
  755. (if (catch 'done
  756. (while (re-search-forward "\n\n\\([-A-Za-z0-9]+:\\)" nil t)
  757. (setq found 0)
  758. (setq point (match-beginning 1))
  759. (forward-line)
  760. (while (looking-at "[ \t]\\|[-A-Za-z0-9]+:")
  761. (if (looking-at "[-A-Za-z0-9]+:")
  762. (setq found (1+ found)))
  763. (forward-line))
  764. (if (and (> found 0) (looking-at "\n"))
  765. (throw 'done t)))
  766. nil)
  767. (goto-char point))))
  768. (deffoo nndoc-request-accept-article (group &optional server last)
  769. nil)
  770. ;;;
  771. ;;; Functions for dissecting the documents
  772. ;;;
  773. (defun nndoc-search (regexp)
  774. (prog1
  775. (re-search-forward regexp nil t)
  776. (beginning-of-line)))
  777. (defun nndoc-dissect-buffer ()
  778. "Go through the document and partition it into heads/bodies/articles."
  779. (let ((i 0)
  780. (first t)
  781. art-begin head-begin head-end body-begin body-end)
  782. (setq nndoc-dissection-alist nil)
  783. (with-current-buffer nndoc-current-buffer
  784. (goto-char (point-min))
  785. ;; Remove blank lines.
  786. (while (eq (following-char) ?\n)
  787. (delete-char 1))
  788. (when nndoc-pre-dissection-function
  789. (save-excursion
  790. (funcall nndoc-pre-dissection-function)))
  791. (if nndoc-dissection-function
  792. (funcall nndoc-dissection-function)
  793. ;; Find the beginning of the file.
  794. (when nndoc-file-begin
  795. (nndoc-search nndoc-file-begin))
  796. ;; Go through the file.
  797. (while (if (and first nndoc-first-article)
  798. (nndoc-search nndoc-first-article)
  799. (if art-begin
  800. (goto-char art-begin)
  801. (nndoc-article-begin)))
  802. (setq first nil
  803. art-begin nil)
  804. (cond (nndoc-head-begin-function
  805. (funcall nndoc-head-begin-function))
  806. (nndoc-head-begin
  807. (nndoc-search nndoc-head-begin)))
  808. (if (or (eobp)
  809. (and nndoc-file-end
  810. (looking-at nndoc-file-end)))
  811. (goto-char (point-max))
  812. (setq head-begin (point))
  813. (nndoc-search (or nndoc-head-end "^$"))
  814. (setq head-end (point))
  815. (if nndoc-body-begin-function
  816. (funcall nndoc-body-begin-function)
  817. (nndoc-search (or nndoc-body-begin "^\n")))
  818. (setq body-begin (point))
  819. (or (and nndoc-body-end-function
  820. (funcall nndoc-body-end-function))
  821. (and nndoc-body-end
  822. (nndoc-search nndoc-body-end))
  823. (and (nndoc-article-begin)
  824. (setq art-begin (point)))
  825. (progn
  826. (goto-char (point-max))
  827. (when nndoc-file-end
  828. (and (re-search-backward nndoc-file-end nil t)
  829. (beginning-of-line)))))
  830. (setq body-end (point))
  831. (push (list (incf i) head-begin head-end body-begin body-end
  832. (count-lines body-begin body-end))
  833. nndoc-dissection-alist)))))
  834. (setq nndoc-dissection-alist (nreverse nndoc-dissection-alist))))
  835. (defun nndoc-article-begin ()
  836. (if nndoc-article-begin-function
  837. (funcall nndoc-article-begin-function)
  838. (ignore-errors
  839. (nndoc-search nndoc-article-begin))))
  840. (defun nndoc-unquote-dashes ()
  841. "Unquote quoted non-separators in digests."
  842. (while (re-search-forward "^- -"nil t)
  843. (replace-match "-" t t)))
  844. ;; Against compiler warnings.
  845. (defvar nndoc-mime-split-ordinal)
  846. (defun nndoc-dissect-mime-parts ()
  847. "Go through a MIME composite article and partition it into sub-articles.
  848. When a MIME entity contains sub-entities, dissection produces one article for
  849. the header of this entity, and one article per sub-entity."
  850. (setq nndoc-dissection-alist nil
  851. nndoc-mime-split-ordinal 0)
  852. (with-current-buffer nndoc-current-buffer
  853. (nndoc-dissect-mime-parts-sub (point-min) (point-max) nil nil nil)))
  854. (defun nndoc-dissect-mime-parts-sub (head-begin body-end article-insert
  855. position parent)
  856. "Dissect an entity, within a composite MIME message.
  857. The complete message or MIME entity extends from HEAD-BEGIN to BODY-END.
  858. ARTICLE-INSERT should be added at beginning for generating a full article.
  859. The string POSITION holds a dotted decimal representation of the article
  860. position in the hierarchical structure, it is nil for the outer entity.
  861. PARENT is the message-ID of the parent summary line, or nil for none."
  862. (let ((case-fold-search t)
  863. (message-id (nnmail-message-id))
  864. head-end body-begin summary-insert message-rfc822 multipart-any
  865. subject content-type type subtype boundary-regexp)
  866. ;; Gracefully handle a missing body.
  867. (goto-char head-begin)
  868. (if (or (and (eq (char-after) ?\n) (or (forward-char 1) t))
  869. (search-forward "\n\n" body-end t))
  870. (setq head-end (1- (point))
  871. body-begin (point))
  872. (setq head-end body-end
  873. body-begin body-end))
  874. (narrow-to-region head-begin head-end)
  875. ;; Save MIME attributes.
  876. (goto-char head-begin)
  877. (setq content-type (message-fetch-field "Content-Type"))
  878. (when content-type
  879. (when (string-match
  880. "^ *\\([^ \t\n/;]+\\)/\\([^ \t\n/;]+\\)" content-type)
  881. (setq type (downcase (match-string 1 content-type))
  882. subtype (downcase (match-string 2 content-type))
  883. message-rfc822 (and (string= type "message")
  884. (string= subtype "rfc822"))
  885. multipart-any (string= type "multipart")))
  886. (when (string-match ";[ \t\n]*name=\\([^ \t\n;]+\\)" content-type)
  887. (setq subject (match-string 1 content-type)))
  888. (when (string-match "boundary=\"?\\([^\"\n]*[^\" \t\n]\\)" content-type)
  889. (setq boundary-regexp (concat "^--"
  890. (regexp-quote
  891. (match-string 1 content-type))
  892. "\\(--\\)?[ \t]*\n"))))
  893. (unless subject
  894. (when (or multipart-any (not article-insert))
  895. (setq subject (message-fetch-field "Subject"))))
  896. (unless type
  897. (setq type "text"
  898. subtype "plain"))
  899. ;; Prepare the article and summary inserts.
  900. (unless article-insert
  901. (setq article-insert (buffer-string)
  902. head-end head-begin))
  903. ;; Fix MIME-Version
  904. (unless (string-match "MIME-Version:" article-insert)
  905. (setq article-insert
  906. (concat article-insert "MIME-Version: 1.0\n")))
  907. (setq summary-insert article-insert)
  908. ;; - summary Subject.
  909. (setq summary-insert
  910. (let ((line (concat "Subject: <" position
  911. (and position multipart-any ".")
  912. (and multipart-any "*")
  913. (and (or position multipart-any) " ")
  914. (cond ((string= subtype "plain") type)
  915. ((string= subtype "basic") type)
  916. (t subtype))
  917. ">"
  918. (and subject " ")
  919. subject
  920. "\n")))
  921. (if (string-match "Subject:.*\n\\([ \t].*\n\\)*" summary-insert)
  922. (replace-match line t t summary-insert)
  923. (concat summary-insert line))))
  924. ;; - summary Message-ID.
  925. (setq summary-insert
  926. (let ((line (concat "Message-ID: " message-id "\n")))
  927. (if (string-match "Message-ID:.*\n\\([ \t].*\n\\)*" summary-insert)
  928. (replace-match line t t summary-insert)
  929. (concat summary-insert line))))
  930. ;; - summary References.
  931. (when parent
  932. (setq summary-insert
  933. (let ((line (concat "References: " parent "\n")))
  934. (if (string-match "References:.*\n\\([ \t].*\n\\)*"
  935. summary-insert)
  936. (replace-match line t t summary-insert)
  937. (concat summary-insert line)))))
  938. ;; Generate dissection information for this entity.
  939. (push (list (incf nndoc-mime-split-ordinal)
  940. head-begin head-end body-begin body-end
  941. (count-lines body-begin body-end)
  942. article-insert summary-insert)
  943. nndoc-dissection-alist)
  944. ;; Recurse for all sub-entities, if any.
  945. (widen)
  946. (cond
  947. (message-rfc822
  948. (save-excursion
  949. (nndoc-dissect-mime-parts-sub body-begin body-end nil
  950. position message-id)))
  951. ((and multipart-any boundary-regexp)
  952. (let ((part-counter 0)
  953. part-begin part-end eof-flag)
  954. (while (string-match "\
  955. ^\\(Lines\\|Content-\\(Type\\|Transfer-Encoding\\|Disposition\\)\\):.*\n\\([ \t].*\n\\)*"
  956. article-insert)
  957. (setq article-insert (replace-match "" t t article-insert)))
  958. (let ((case-fold-search nil))
  959. (goto-char body-begin)
  960. (setq eof-flag (not (re-search-forward boundary-regexp body-end t)))
  961. (while (not eof-flag)
  962. (setq part-begin (point))
  963. (cond ((re-search-forward boundary-regexp body-end t)
  964. (or (not (match-string 1))
  965. (string= (match-string 1) "")
  966. (setq eof-flag t))
  967. (forward-line -1)
  968. (setq part-end (point))
  969. (forward-line 1))
  970. (t (setq part-end body-end
  971. eof-flag t)))
  972. (save-excursion
  973. (nndoc-dissect-mime-parts-sub
  974. part-begin part-end article-insert
  975. (concat position
  976. (and position ".")
  977. (format "%d" (incf part-counter)))
  978. message-id)))))))))
  979. ;;;###autoload
  980. (defun nndoc-add-type (definition &optional position)
  981. "Add document DEFINITION to the list of nndoc document definitions.
  982. If POSITION is nil or `last', the definition will be added
  983. as the last checked definition, if t or `first', add as the
  984. first definition, and if any other symbol, add after that
  985. symbol in the alist."
  986. ;; First remove any old instances.
  987. (gnus-alist-pull (car definition) nndoc-type-alist)
  988. ;; Then enter the new definition in the proper place.
  989. (cond
  990. ((or (null position) (eq position 'last))
  991. (setq nndoc-type-alist (nconc nndoc-type-alist (list definition))))
  992. ((or (eq position t) (eq position 'first))
  993. (push definition nndoc-type-alist))
  994. (t
  995. (let ((list (memq (assq position nndoc-type-alist)
  996. nndoc-type-alist)))
  997. (unless list
  998. (error "No such position: %s" position))
  999. (setcdr list (cons definition (cdr list)))))))
  1000. (provide 'nndoc)
  1001. ;;; nndoc.el ends here