PageRenderTime 101ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 3ms

/lisp/gnus/gnus-art.el

http://github.com/typester/emacs
Emacs Lisp | 8630 lines | 7559 code | 610 blank | 461 comment | 118 complexity | ad39fc4b6e91d76c037bdf1ff2e220c5 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, AGPL-3.0
  1. ;;; gnus-art.el --- article mode commands for Gnus
  2. ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
  3. ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
  4. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  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. ;;; Code:
  19. ;; For Emacs < 22.2.
  20. (eval-and-compile
  21. (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
  22. (eval-when-compile
  23. (require 'cl))
  24. (defvar tool-bar-map)
  25. (defvar w3m-minor-mode-map)
  26. (require 'gnus)
  27. ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
  28. (eval-and-compile
  29. (let ((recursive-load-depth-limit 100))
  30. (require 'gnus-sum)))
  31. (require 'gnus-spec)
  32. (require 'gnus-int)
  33. (require 'gnus-win)
  34. (require 'mm-bodies)
  35. (require 'mail-parse)
  36. (require 'mm-decode)
  37. (require 'mm-view)
  38. (require 'wid-edit)
  39. (require 'mm-uu)
  40. (require 'message)
  41. (autoload 'gnus-msg-mail "gnus-msg" nil t)
  42. (autoload 'gnus-button-mailto "gnus-msg")
  43. (autoload 'gnus-button-reply "gnus-msg" nil t)
  44. (autoload 'parse-time-string "parse-time" nil nil)
  45. (autoload 'ansi-color-apply-on-region "ansi-color")
  46. (autoload 'mm-url-insert-file-contents-external "mm-url")
  47. (autoload 'mm-extern-cache-contents "mm-extern")
  48. (defgroup gnus-article nil
  49. "Article display."
  50. :link '(custom-manual "(gnus)Article Buffer")
  51. :group 'gnus)
  52. (defgroup gnus-article-treat nil
  53. "Treating article parts."
  54. :link '(custom-manual "(gnus)Article Hiding")
  55. :group 'gnus-article)
  56. (defgroup gnus-article-hiding nil
  57. "Hiding article parts."
  58. :link '(custom-manual "(gnus)Article Hiding")
  59. :group 'gnus-article)
  60. (defgroup gnus-article-highlight nil
  61. "Article highlighting."
  62. :link '(custom-manual "(gnus)Article Highlighting")
  63. :group 'gnus-article
  64. :group 'gnus-visual)
  65. (defgroup gnus-article-signature nil
  66. "Article signatures."
  67. :link '(custom-manual "(gnus)Article Signature")
  68. :group 'gnus-article)
  69. (defgroup gnus-article-headers nil
  70. "Article headers."
  71. :link '(custom-manual "(gnus)Hiding Headers")
  72. :group 'gnus-article)
  73. (defgroup gnus-article-washing nil
  74. "Special commands on articles."
  75. :link '(custom-manual "(gnus)Article Washing")
  76. :group 'gnus-article)
  77. (defgroup gnus-article-emphasis nil
  78. "Fontisizing articles."
  79. :link '(custom-manual "(gnus)Article Fontisizing")
  80. :group 'gnus-article)
  81. (defgroup gnus-article-saving nil
  82. "Saving articles."
  83. :link '(custom-manual "(gnus)Saving Articles")
  84. :group 'gnus-article)
  85. (defgroup gnus-article-mime nil
  86. "Worshiping the MIME wonder."
  87. :link '(custom-manual "(gnus)Using MIME")
  88. :group 'gnus-article)
  89. (defgroup gnus-article-buttons nil
  90. "Pushable buttons in the article buffer."
  91. :link '(custom-manual "(gnus)Article Buttons")
  92. :group 'gnus-article)
  93. (defgroup gnus-article-various nil
  94. "Other article options."
  95. :link '(custom-manual "(gnus)Misc Article")
  96. :group 'gnus-article)
  97. (defcustom gnus-ignored-headers
  98. (mapcar
  99. (lambda (header)
  100. (concat "^" header ":"))
  101. '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
  102. "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
  103. "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
  104. "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
  105. "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
  106. "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
  107. "X-Attribution" "X-Originating-IP" "Delivered-To"
  108. "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
  109. "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
  110. "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
  111. "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
  112. "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
  113. "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
  114. "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
  115. "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
  116. "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
  117. "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
  118. "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
  119. "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
  120. "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
  121. "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
  122. "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
  123. "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
  124. "List-[A-Za-z]+" "X-Listprocessor-Version"
  125. "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
  126. "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
  127. "X-Received" "Content-length" "X-precedence"
  128. "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
  129. "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
  130. "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
  131. "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
  132. "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
  133. "X-Content-length" "X-Posting-Agent" "Original-Received"
  134. "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
  135. "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
  136. "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
  137. "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
  138. "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
  139. "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
  140. "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
  141. "Envelope-Sender" "Envelope-Recipients"))
  142. "*All headers that start with this regexp will be hidden.
  143. This variable can also be a list of regexps of headers to be ignored.
  144. If `gnus-visible-headers' is non-nil, this variable will be ignored."
  145. :type '(choice :custom-show nil
  146. regexp
  147. (repeat regexp))
  148. :group 'gnus-article-hiding)
  149. (defcustom gnus-visible-headers
  150. "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
  151. "*All headers that do not match this regexp will be hidden.
  152. This variable can also be a list of regexp of headers to remain visible.
  153. If this variable is non-nil, `gnus-ignored-headers' will be ignored."
  154. :type '(choice
  155. (repeat :value-to-internal (lambda (widget value)
  156. (custom-split-regexp-maybe value))
  157. :match (lambda (widget value)
  158. (or (stringp value)
  159. (widget-editable-list-match widget value)))
  160. regexp)
  161. (const :tag "Use gnus-ignored-headers" nil)
  162. regexp)
  163. :group 'gnus-article-hiding)
  164. (defcustom gnus-sorted-header-list
  165. '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
  166. "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
  167. "*This variable is a list of regular expressions.
  168. If it is non-nil, headers that match the regular expressions will
  169. be placed first in the article buffer in the sequence specified by
  170. this list."
  171. :type '(repeat regexp)
  172. :group 'gnus-article-hiding)
  173. (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
  174. "Headers that are only to be displayed if they have interesting data.
  175. Possible values in this list are:
  176. 'empty Headers with no content.
  177. 'newsgroups Newsgroup identical to Gnus group.
  178. 'to-address To identical to To-address.
  179. 'to-list To identical to To-list.
  180. 'cc-list CC identical to To-list.
  181. 'followup-to Followup-to identical to Newsgroups.
  182. 'reply-to Reply-to identical to From.
  183. 'date Date less than four days old.
  184. 'long-to To and/or Cc longer than 1024 characters.
  185. 'many-to Multiple To and/or Cc."
  186. :type '(set (const :tag "Headers with no content." empty)
  187. (const :tag "Newsgroups identical to Gnus group." newsgroups)
  188. (const :tag "To identical to To-address." to-address)
  189. (const :tag "To identical to To-list." to-list)
  190. (const :tag "CC identical to To-list." cc-list)
  191. (const :tag "Followup-to identical to Newsgroups." followup-to)
  192. (const :tag "Reply-to identical to From." reply-to)
  193. (const :tag "Date less than four days old." date)
  194. (const :tag "To and/or Cc longer than 1024 characters." long-to)
  195. (const :tag "Multiple To and/or Cc headers." many-to))
  196. :group 'gnus-article-hiding)
  197. (defcustom gnus-article-skip-boring nil
  198. "Skip over text that is not worth reading.
  199. By default, if you set this t, then Gnus will display citations and
  200. signatures, but will never scroll down to show you a page consisting
  201. only of boring text. Boring text is controlled by
  202. `gnus-article-boring-faces'."
  203. :version "22.1"
  204. :type 'boolean
  205. :group 'gnus-article-hiding)
  206. (defcustom gnus-signature-separator '("^-- $" "^-- *$")
  207. "Regexp matching signature separator.
  208. This can also be a list of regexps. In that case, it will be checked
  209. from head to tail looking for a separator. Searches will be done from
  210. the end of the buffer."
  211. :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
  212. (regexp)
  213. (repeat :tag "List of regexp" regexp))
  214. :group 'gnus-article-signature)
  215. (defcustom gnus-signature-limit nil
  216. "Provide a limit to what is considered a signature.
  217. If it is a number, no signature may not be longer (in characters) than
  218. that number. If it is a floating point number, no signature may be
  219. longer (in lines) than that number. If it is a function, the function
  220. will be called without any parameters, and if it returns nil, there is
  221. no signature in the buffer. If it is a string, it will be used as a
  222. regexp. If it matches, the text in question is not a signature.
  223. This can also be a list of the above values."
  224. :type '(choice (const nil)
  225. (integer :value 200)
  226. (number :value 4.0)
  227. function
  228. (regexp :value ".*"))
  229. :group 'gnus-article-signature)
  230. (defcustom gnus-hidden-properties '(invisible t intangible t)
  231. "Property list to use for hiding text."
  232. :type 'sexp
  233. :group 'gnus-article-hiding)
  234. ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
  235. ;; frames in a session.
  236. (defcustom gnus-article-x-face-command
  237. (if (featurep 'xemacs)
  238. (if (or (gnus-image-type-available-p 'xface)
  239. (gnus-image-type-available-p 'pbm))
  240. 'gnus-display-x-face-in-from
  241. "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
  242. (if (gnus-image-type-available-p 'pbm)
  243. 'gnus-display-x-face-in-from
  244. "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
  245. display -"))
  246. "*String or function to be executed to display an X-Face header.
  247. If it is a string, the command will be executed in a sub-shell
  248. asynchronously. The compressed face will be piped to this command."
  249. :type `(choice string
  250. (function-item gnus-display-x-face-in-from)
  251. function)
  252. :version "21.1"
  253. :group 'gnus-picon
  254. :group 'gnus-article-washing)
  255. (defcustom gnus-article-x-face-too-ugly nil
  256. "Regexp matching posters whose face shouldn't be shown automatically."
  257. :type '(choice regexp (const nil))
  258. :group 'gnus-article-washing)
  259. (defcustom gnus-article-banner-alist nil
  260. "Banner alist for stripping.
  261. For example,
  262. ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
  263. :version "21.1"
  264. :type '(repeat (cons symbol regexp))
  265. :group 'gnus-article-washing)
  266. (gnus-define-group-parameter
  267. banner
  268. :variable-document
  269. "Alist of regexps (to match group names) and banner."
  270. :variable-group gnus-article-washing
  271. :parameter-type
  272. '(choice :tag "Banner"
  273. :value nil
  274. (const :tag "Remove signature" signature)
  275. (symbol :tag "Item in `gnus-article-banner-alist'" none)
  276. regexp
  277. (const :tag "None" nil))
  278. :parameter-document
  279. "If non-nil, specify how to remove `banners' from articles.
  280. Symbol `signature' means to remove signatures delimited by
  281. `gnus-signature-separator'. Any other symbol is used to look up a
  282. regular expression to match the banner in `gnus-article-banner-alist'.
  283. A string is used as a regular expression to match the banner
  284. directly.")
  285. (defcustom gnus-article-address-banner-alist nil
  286. "Alist of mail addresses and banners.
  287. Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
  288. to match a mail address in the From: header, BANNER is one of a symbol
  289. `signature', an item in `gnus-article-banner-alist', a regexp and nil.
  290. If ADDRESS matches author's mail address, it will remove things like
  291. advertisements. For example:
  292. \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
  293. "
  294. :type '(repeat
  295. (cons
  296. (regexp :tag "Address")
  297. (choice :tag "Banner" :value nil
  298. (const :tag "Remove signature" signature)
  299. (symbol :tag "Item in `gnus-article-banner-alist'" none)
  300. regexp
  301. (const :tag "None" nil))))
  302. :version "22.1"
  303. :group 'gnus-article-washing)
  304. (defmacro gnus-emphasis-custom-with-format (&rest body)
  305. `(let ((format "\
  306. \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
  307. \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
  308. ,@body))
  309. (defun gnus-emphasis-custom-value-to-external (value)
  310. (gnus-emphasis-custom-with-format
  311. (if (consp (car value))
  312. (list (format format (car (car value)) (cdr (car value)))
  313. 2
  314. (if (nth 1 value) 2 3)
  315. (nth 2 value))
  316. value)))
  317. (defun gnus-emphasis-custom-value-to-internal (value)
  318. (gnus-emphasis-custom-with-format
  319. (let ((regexp (concat "\\`"
  320. (format (regexp-quote format)
  321. "\\([^()]+\\)" "\\([^()]+\\)")
  322. "\\'"))
  323. pattern)
  324. (if (string-match regexp (setq pattern (car value)))
  325. (list (cons (match-string 1 pattern) (match-string 2 pattern))
  326. (= (nth 2 value) 2)
  327. (nth 3 value))
  328. value))))
  329. (defcustom gnus-emphasis-alist
  330. (let ((types
  331. '(("\\*" "\\*" bold nil 2)
  332. ("_" "_" underline)
  333. ("/" "/" italic)
  334. ("_/" "/_" underline-italic)
  335. ("_\\*" "\\*_" underline-bold)
  336. ("\\*/" "/\\*" bold-italic)
  337. ("_\\*/" "/\\*_" underline-bold-italic))))
  338. (nconc
  339. (gnus-emphasis-custom-with-format
  340. (mapcar (lambda (spec)
  341. (list (format format (car spec) (cadr spec))
  342. (or (nth 3 spec) 2)
  343. (or (nth 4 spec) 3)
  344. (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
  345. types))
  346. '(;; I've never seen anyone use this strikethru convention whereas I've
  347. ;; several times seen it triggered by normal text. --Stef
  348. ;; Miles suggests that this form is sometimes used but for italics,
  349. ;; so maybe we should map it to `italic'.
  350. ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
  351. ;; 2 3 gnus-emphasis-strikethru)
  352. ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
  353. 2 3 gnus-emphasis-underline))))
  354. "*Alist that says how to fontify certain phrases.
  355. Each item looks like this:
  356. (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
  357. The first element is a regular expression to be matched. The second
  358. is a number that says what regular expression grouping used to find
  359. the entire emphasized word. The third is a number that says what
  360. regexp grouping should be displayed and highlighted. The fourth
  361. is the face used for highlighting."
  362. :type
  363. '(repeat
  364. (menu-choice
  365. :format "%[Customizing Style%]\n%v"
  366. :indent 2
  367. (group :tag "Default"
  368. :value ("" 0 0 default)
  369. :value-create
  370. (lambda (widget)
  371. (let ((value (widget-get
  372. (cadr (widget-get (widget-get widget :parent)
  373. :args))
  374. :value)))
  375. (if (not (eq (nth 2 value) 'default))
  376. (widget-put
  377. widget
  378. :value
  379. (gnus-emphasis-custom-value-to-external value))))
  380. (widget-group-value-create widget))
  381. regexp
  382. (integer :format "Match group: %v")
  383. (integer :format "Emphasize group: %v")
  384. face)
  385. (group :tag "Simple"
  386. :value (("_" . "_") nil default)
  387. (cons :format "%v"
  388. (regexp :format "Start regexp: %v")
  389. (regexp :format "End regexp: %v"))
  390. (boolean :format "Show start and end patterns: %[%v%]\n"
  391. :on " On " :off " Off ")
  392. face)))
  393. :get (lambda (symbol)
  394. (mapcar 'gnus-emphasis-custom-value-to-internal
  395. (default-value symbol)))
  396. :set (lambda (symbol value)
  397. (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
  398. value)))
  399. :group 'gnus-article-emphasis)
  400. (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
  401. "A regexp to describe whitespace which should not be emphasized.
  402. Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
  403. The former avoids underlining of leading and trailing whitespace,
  404. and the latter avoids underlining any whitespace at all."
  405. :version "21.1"
  406. :group 'gnus-article-emphasis
  407. :type 'regexp)
  408. (defface gnus-emphasis-bold '((t (:bold t)))
  409. "Face used for displaying strong emphasized text (*word*)."
  410. :group 'gnus-article-emphasis)
  411. (defface gnus-emphasis-italic '((t (:italic t)))
  412. "Face used for displaying italic emphasized text (/word/)."
  413. :group 'gnus-article-emphasis)
  414. (defface gnus-emphasis-underline '((t (:underline t)))
  415. "Face used for displaying underlined emphasized text (_word_)."
  416. :group 'gnus-article-emphasis)
  417. (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
  418. "Face used for displaying underlined bold emphasized text (_*word*_)."
  419. :group 'gnus-article-emphasis)
  420. (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
  421. "Face used for displaying underlined italic emphasized text (_/word/_)."
  422. :group 'gnus-article-emphasis)
  423. (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
  424. "Face used for displaying bold italic emphasized text (/*word*/)."
  425. :group 'gnus-article-emphasis)
  426. (defface gnus-emphasis-underline-bold-italic
  427. '((t (:bold t :italic t :underline t)))
  428. "Face used for displaying underlined bold italic emphasized text.
  429. Example: (_/*word*/_)."
  430. :group 'gnus-article-emphasis)
  431. (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
  432. '((t (:strikethru t)))
  433. '((t (:strike-through t))))
  434. "Face used for displaying strike-through text (-word-)."
  435. :group 'gnus-article-emphasis)
  436. (defface gnus-emphasis-highlight-words
  437. '((t (:background "black" :foreground "yellow")))
  438. "Face used for displaying highlighted words."
  439. :group 'gnus-article-emphasis)
  440. (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
  441. "Format for display of Date headers in article bodies.
  442. See `format-time-string' for the possible values.
  443. The variable can also be function, which should return a complete Date
  444. header. The function is called with one argument, the time, which can
  445. be fed to `format-time-string'."
  446. :type '(choice string function)
  447. :link '(custom-manual "(gnus)Article Date")
  448. :group 'gnus-article-washing)
  449. (defcustom gnus-save-all-headers t
  450. "*If non-nil, don't remove any headers before saving.
  451. This will be overridden by the `:headers' property that the symbol of
  452. the saver function, which is specified by `gnus-default-article-saver',
  453. might have."
  454. :group 'gnus-article-saving
  455. :type 'boolean)
  456. (defcustom gnus-prompt-before-saving 'always
  457. "*This variable says how much prompting is to be done when saving articles.
  458. If it is nil, no prompting will be done, and the articles will be
  459. saved to the default files. If this variable is `always', each and
  460. every article that is saved will be preceded by a prompt, even when
  461. saving large batches of articles. If this variable is neither nil not
  462. `always', there the user will be prompted once for a file name for
  463. each invocation of the saving commands."
  464. :group 'gnus-article-saving
  465. :type '(choice (item always)
  466. (item :tag "never" nil)
  467. (sexp :tag "once" :format "%t\n" :value t)))
  468. (defcustom gnus-saved-headers gnus-visible-headers
  469. "Headers to keep if `gnus-save-all-headers' is nil.
  470. If `gnus-save-all-headers' is non-nil, this variable will be ignored.
  471. If that variable is nil, however, all headers that match this regexp
  472. will be kept while the rest will be deleted before saving. This and
  473. `gnus-save-all-headers' will be overridden by the `:headers' property
  474. that the symbol of the saver function, which is specified by
  475. `gnus-default-article-saver', might have."
  476. :group 'gnus-article-saving
  477. :type 'regexp)
  478. ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
  479. (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
  480. "A function to save articles in your favourite format.
  481. The function will be called by way of the `gnus-summary-save-article'
  482. command, and friends such as `gnus-summary-save-article-rmail'.
  483. Gnus provides the following functions:
  484. * gnus-summary-save-in-rmail (Rmail format)
  485. * gnus-summary-save-in-mail (Unix mail format)
  486. * gnus-summary-save-in-folder (MH folder)
  487. * gnus-summary-save-in-file (article format)
  488. * gnus-summary-save-body-in-file (article body)
  489. * gnus-summary-save-in-vm (use VM's folder format)
  490. * gnus-summary-write-to-file (article format -- overwrite)
  491. * gnus-summary-write-body-to-file (article body -- overwrite)
  492. * gnus-summary-save-in-pipe (article format)
  493. The symbol of each function may have the following properties:
  494. * :decode
  495. The value non-nil means save decoded articles. This is meaningful
  496. only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
  497. `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
  498. `gnus-summary-save-in-pipe'.
  499. * :function
  500. The value specifies an alternative function which appends, not
  501. overwrites, articles to a file. This implies that when saving many
  502. articles at a time, `gnus-prompt-before-saving' is bound to t and all
  503. articles are saved in a single file. This is meaningful only with
  504. `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
  505. * :headers
  506. The value specifies the symbol of a variable of which the value
  507. specifies headers to be saved. If it is omitted,
  508. `gnus-save-all-headers' and `gnus-saved-headers' control what
  509. headers should be saved."
  510. :group 'gnus-article-saving
  511. :type '(radio (function-item gnus-summary-save-in-rmail)
  512. (function-item gnus-summary-save-in-mail)
  513. (function-item gnus-summary-save-in-folder)
  514. (function-item gnus-summary-save-in-file)
  515. (function-item gnus-summary-save-body-in-file)
  516. (function-item gnus-summary-save-in-vm)
  517. (function-item gnus-summary-write-to-file)
  518. (function-item gnus-summary-write-body-to-file)
  519. (function-item gnus-summary-save-in-pipe)
  520. (function)))
  521. (defcustom gnus-article-save-coding-system
  522. (or (and (mm-coding-system-p 'utf-8) 'utf-8)
  523. (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
  524. (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
  525. (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
  526. "Coding system used to save decoded articles to a file.
  527. The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
  528. which can safely encode any characters in text. This is used by the
  529. commands including:
  530. * gnus-summary-save-article-file
  531. * gnus-summary-save-article-body-file
  532. * gnus-summary-write-article-file
  533. * gnus-summary-write-article-body-file
  534. and the functions to which you may set `gnus-default-article-saver':
  535. * gnus-summary-save-in-file
  536. * gnus-summary-save-body-in-file
  537. * gnus-summary-write-to-file
  538. * gnus-summary-write-body-to-file
  539. Those commands and functions save just text displayed in the article
  540. buffer to a file if the value of this variable is non-nil. Note that
  541. buttonized MIME parts will be lost in a saved file in that case.
  542. Otherwise, raw articles will be saved."
  543. :group 'gnus-article-saving
  544. :type `(choice
  545. :format "%{%t%}:\n %[Value Menu%] %v"
  546. (const :tag "Save raw articles" nil)
  547. ,@(delq nil
  548. (mapcar
  549. (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
  550. '((const :tag "UTF-8" utf-8)
  551. (const :tag "iso-2022-7bit" iso-2022-7bit)
  552. (const :tag "Emacs internal" emacs-mule)
  553. (const :tag "escape-quoted" escape-quoted))))
  554. (symbol :tag "Coding system")))
  555. (defcustom gnus-rmail-save-name 'gnus-plain-save-name
  556. "A function generating a file name to save articles in Rmail format.
  557. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  558. :group 'gnus-article-saving
  559. :type 'function)
  560. (defcustom gnus-mail-save-name 'gnus-plain-save-name
  561. "A function generating a file name to save articles in Unix mail format.
  562. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  563. :group 'gnus-article-saving
  564. :type 'function)
  565. (defcustom gnus-folder-save-name 'gnus-folder-save-name
  566. "A function generating a file name to save articles in MH folder.
  567. The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
  568. :group 'gnus-article-saving
  569. :type 'function)
  570. (defcustom gnus-file-save-name 'gnus-numeric-save-name
  571. "A function generating a file name to save articles in article format.
  572. The function is called with NEWSGROUP, HEADERS, and optional
  573. LAST-FILE."
  574. :group 'gnus-article-saving
  575. :type 'function)
  576. (defcustom gnus-split-methods
  577. '((gnus-article-archive-name)
  578. (gnus-article-nndoc-name))
  579. "*Variable used to suggest where articles are to be saved.
  580. For instance, if you would like to save articles related to Gnus in
  581. the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
  582. you could set this variable to something like:
  583. '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
  584. (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
  585. This variable is an alist where the key is the match and the
  586. value is a list of possible files to save in if the match is
  587. non-nil.
  588. If the match is a string, it is used as a regexp match on the
  589. article. If the match is a symbol, that symbol will be funcalled
  590. from the buffer of the article to be saved with the newsgroup as the
  591. parameter. If it is a list, it will be evaled in the same buffer.
  592. If this form or function returns a string, this string will be used as a
  593. possible file name; and if it returns a non-nil list, that list will be
  594. used as possible file names."
  595. :group 'gnus-article-saving
  596. :type '(repeat (choice (list :value (fun) function)
  597. (cons :value ("" "") regexp (repeat string))
  598. (sexp :value nil))))
  599. (defcustom gnus-page-delimiter "^\^L"
  600. "*Regexp describing what to use as article page delimiters.
  601. The default value is \"^\^L\", which is a form linefeed at the
  602. beginning of a line."
  603. :type 'regexp
  604. :group 'gnus-article-various)
  605. (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
  606. "*The format specification for the article mode line.
  607. See `gnus-summary-mode-line-format' for a closer description.
  608. The following additional specs are available:
  609. %w The article washing status.
  610. %m The number of MIME parts in the article."
  611. :type 'string
  612. :group 'gnus-article-various)
  613. (defcustom gnus-article-mode-hook nil
  614. "*A hook for Gnus article mode."
  615. :type 'hook
  616. :group 'gnus-article-various)
  617. (when (featurep 'xemacs)
  618. ;; Extracted from gnus-xmas-define in order to preserve user settings
  619. (when (fboundp 'turn-off-scroll-in-place)
  620. (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
  621. ;; Extracted from gnus-xmas-redefine in order to preserve user settings
  622. (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
  623. (defcustom gnus-article-menu-hook nil
  624. "*Hook run after the creation of the article mode menu."
  625. :type 'hook
  626. :group 'gnus-article-various)
  627. (defcustom gnus-article-prepare-hook nil
  628. "*A hook called after an article has been prepared in the article buffer."
  629. :type 'hook
  630. :group 'gnus-article-various)
  631. (defcustom gnus-copy-article-ignored-headers nil
  632. "List of headers to be removed when copying an article.
  633. Each element is a regular expression."
  634. :version "23.1" ;; No Gnus
  635. :type '(repeat regexp)
  636. :group 'gnus-article-various)
  637. (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
  638. "Gnus 5.10 (Emacs-22.1)")
  639. (defface gnus-button
  640. '((t (:weight bold)))
  641. "Face used for highlighting a button in the article buffer."
  642. :group 'gnus-article-buttons)
  643. (defcustom gnus-article-button-face 'gnus-button
  644. "Face used for highlighting buttons in the article buffer.
  645. An article button is a piece of text that you can activate by pressing
  646. `RET' or `mouse-2' above it."
  647. :type 'face
  648. :group 'gnus-article-buttons)
  649. (defcustom gnus-article-mouse-face 'highlight
  650. "Face used for mouse highlighting in the article buffer.
  651. Article buttons will be displayed in this face when the cursor is
  652. above them."
  653. :type 'face
  654. :group 'gnus-article-buttons)
  655. (defcustom gnus-signature-face 'gnus-signature
  656. "Face used for highlighting a signature in the article buffer.
  657. Obsolete; use the face `gnus-signature' for customizations instead."
  658. :type 'face
  659. :group 'gnus-article-highlight
  660. :group 'gnus-article-signature)
  661. (defface gnus-signature
  662. '((t
  663. (:italic t)))
  664. "Face used for highlighting a signature in the article buffer."
  665. :group 'gnus-article-highlight
  666. :group 'gnus-article-signature)
  667. ;; backward-compatibility alias
  668. (put 'gnus-signature-face 'face-alias 'gnus-signature)
  669. (put 'gnus-signature-face 'obsolete-face "22.1")
  670. (defface gnus-header-from
  671. '((((class color)
  672. (background dark))
  673. (:foreground "PaleGreen1"))
  674. (((class color)
  675. (background light))
  676. (:foreground "red3"))
  677. (t
  678. (:italic t)))
  679. "Face used for displaying from headers."
  680. :group 'gnus-article-headers
  681. :group 'gnus-article-highlight)
  682. ;; backward-compatibility alias
  683. (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
  684. (put 'gnus-header-from-face 'obsolete-face "22.1")
  685. (defface gnus-header-subject
  686. '((((class color)
  687. (background dark))
  688. (:foreground "SeaGreen1"))
  689. (((class color)
  690. (background light))
  691. (:foreground "red4"))
  692. (t
  693. (:bold t :italic t)))
  694. "Face used for displaying subject headers."
  695. :group 'gnus-article-headers
  696. :group 'gnus-article-highlight)
  697. ;; backward-compatibility alias
  698. (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
  699. (put 'gnus-header-subject-face 'obsolete-face "22.1")
  700. (defface gnus-header-newsgroups
  701. '((((class color)
  702. (background dark))
  703. (:foreground "yellow" :italic t))
  704. (((class color)
  705. (background light))
  706. (:foreground "MidnightBlue" :italic t))
  707. (t
  708. (:italic t)))
  709. "Face used for displaying newsgroups headers.
  710. In the default setup this face is only used for crossposted
  711. articles."
  712. :group 'gnus-article-headers
  713. :group 'gnus-article-highlight)
  714. ;; backward-compatibility alias
  715. (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
  716. (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
  717. (defface gnus-header-name
  718. '((((class color)
  719. (background dark))
  720. (:foreground "SpringGreen2"))
  721. (((class color)
  722. (background light))
  723. (:foreground "maroon"))
  724. (t
  725. (:bold t)))
  726. "Face used for displaying header names."
  727. :group 'gnus-article-headers
  728. :group 'gnus-article-highlight)
  729. ;; backward-compatibility alias
  730. (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
  731. (put 'gnus-header-name-face 'obsolete-face "22.1")
  732. (defface gnus-header-content
  733. '((((class color)
  734. (background dark))
  735. (:foreground "SpringGreen1" :italic t))
  736. (((class color)
  737. (background light))
  738. (:foreground "indianred4" :italic t))
  739. (t
  740. (:italic t))) "Face used for displaying header content."
  741. :group 'gnus-article-headers
  742. :group 'gnus-article-highlight)
  743. ;; backward-compatibility alias
  744. (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
  745. (put 'gnus-header-content-face 'obsolete-face "22.1")
  746. (defcustom gnus-header-face-alist
  747. '(("From" nil gnus-header-from)
  748. ("Subject" nil gnus-header-subject)
  749. ("Newsgroups:.*," nil gnus-header-newsgroups)
  750. ("" gnus-header-name gnus-header-content))
  751. "*Controls highlighting of article headers.
  752. An alist of the form (HEADER NAME CONTENT).
  753. HEADER is a regular expression which should match the name of a
  754. header and NAME and CONTENT are either face names or nil.
  755. The name of each header field will be displayed using the face
  756. specified by the first element in the list where HEADER matches
  757. the header name and NAME is non-nil. Similarly, the content will
  758. be displayed by the first non-nil matching CONTENT face."
  759. :group 'gnus-article-headers
  760. :group 'gnus-article-highlight
  761. :type '(repeat (list (regexp :tag "Header")
  762. (choice :tag "Name"
  763. (item :tag "skip" nil)
  764. (face :value default))
  765. (choice :tag "Content"
  766. (item :tag "skip" nil)
  767. (face :value default)))))
  768. (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
  769. '((xface . (:face gnus-x-face)))
  770. '((pbm . (:face gnus-x-face))
  771. (png . nil)))
  772. "Alist of image types and properties applied to Face and X-Face images.
  773. Here are examples:
  774. ;; Specify the altitude of Face images in the From header.
  775. \(setq gnus-face-properties-alist
  776. '((pbm . (:face gnus-x-face :ascent 80))
  777. (png . (:ascent 80))))
  778. ;; Show Face images as pressed buttons.
  779. \(setq gnus-face-properties-alist
  780. '((pbm . (:face gnus-x-face :relief -2))
  781. (png . (:relief -2))))
  782. See the manual for the valid properties for various image types.
  783. Currently, `pbm' is used for X-Face images and `png' is used for Face
  784. images in Emacs. Only the `:face' property is effective on the `xface'
  785. image type in XEmacs if it is built with the libcompface library."
  786. :version "23.1" ;; No Gnus
  787. :group 'gnus-article-headers
  788. :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
  789. (defcustom gnus-article-decode-hook
  790. '(article-decode-charset article-decode-encoded-words
  791. article-decode-group-name article-decode-idna-rhs)
  792. "*Hook run to decode charsets in articles."
  793. :group 'gnus-article-headers
  794. :type 'hook)
  795. (defcustom gnus-display-mime-function 'gnus-display-mime
  796. "Function to display MIME articles."
  797. :group 'gnus-article-mime
  798. :type 'function)
  799. (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
  800. "Function used to decode headers.")
  801. (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
  802. "Function used to decode addresses.")
  803. (defvar gnus-article-dumbquotes-map
  804. '(("\200" "EUR")
  805. ("\202" ",")
  806. ("\203" "f")
  807. ("\204" ",,")
  808. ("\205" "...")
  809. ("\213" "<")
  810. ("\214" "OE")
  811. ("\221" "`")
  812. ("\222" "'")
  813. ("\223" "``")
  814. ("\224" "\"")
  815. ("\225" "*")
  816. ("\226" "-")
  817. ("\227" "--")
  818. ("\230" "~")
  819. ("\231" "(TM)")
  820. ("\233" ">")
  821. ("\234" "oe")
  822. ("\264" "'"))
  823. "Table for MS-to-Latin1 translation.")
  824. (defcustom gnus-ignored-mime-types nil
  825. "List of MIME types that should be ignored by Gnus."
  826. :version "21.1"
  827. :group 'gnus-article-mime
  828. :type '(repeat regexp))
  829. (defcustom gnus-unbuttonized-mime-types '(".*/.*")
  830. "List of MIME types that should not be given buttons when rendered inline.
  831. See also `gnus-buttonized-mime-types' which may override this variable.
  832. This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
  833. :version "21.1"
  834. :group 'gnus-article-mime
  835. :type '(repeat regexp))
  836. (defcustom gnus-buttonized-mime-types nil
  837. "List of MIME types that should be given buttons when rendered inline.
  838. If set, this variable overrides `gnus-unbuttonized-mime-types'.
  839. To see e.g. security buttons you could set this to
  840. `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
  841. this list to display radio buttons that allow you to choose one of two
  842. media types those mails include. See also `mm-discouraged-alternatives'.
  843. This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
  844. :version "22.1"
  845. :group 'gnus-article-mime
  846. :type '(repeat regexp))
  847. (defcustom gnus-inhibit-mime-unbuttonizing nil
  848. "If non-nil, all MIME parts get buttons.
  849. When nil (the default value), then some MIME parts do not get buttons,
  850. as described by the variables `gnus-buttonized-mime-types' and
  851. `gnus-unbuttonized-mime-types'."
  852. :version "22.1"
  853. :group 'gnus-article-mime
  854. :type 'boolean)
  855. (defcustom gnus-body-boundary-delimiter "_"
  856. "String used to delimit header and body.
  857. This variable is used by `gnus-article-treat-body-boundary' which can
  858. be controlled by `gnus-treat-body-boundary'."
  859. :version "22.1"
  860. :group 'gnus-article-various
  861. :type '(choice (item :tag "None" :value nil)
  862. string))
  863. (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
  864. "/usr/share/picons")
  865. "Defines the location of the faces database.
  866. For information on obtaining this database of pretty pictures, please
  867. see http://www.cs.indiana.edu/picons/ftp/index.html"
  868. :version "22.1"
  869. :type '(repeat directory)
  870. :link '(url-link :tag "download"
  871. "http://www.cs.indiana.edu/picons/ftp/index.html")
  872. :link '(custom-manual "(gnus)Picons")
  873. :group 'gnus-picon)
  874. (defun gnus-picons-installed-p ()
  875. "Say whether picons are installed on your machine."
  876. (let ((installed nil))
  877. (dolist (database gnus-picon-databases)
  878. (when (file-exists-p database)
  879. (setq installed t)))
  880. installed))
  881. (defcustom gnus-article-mime-part-function nil
  882. "Function called with a MIME handle as the argument.
  883. This is meant for people who want to do something automatic based
  884. on parts -- for instance, adding Vcard info to a database."
  885. :group 'gnus-article-mime
  886. :type '(choice (const nil)
  887. function))
  888. (defcustom gnus-mime-multipart-functions nil
  889. "An alist of MIME types to functions to display them."
  890. :version "21.1"
  891. :group 'gnus-article-mime
  892. :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
  893. (defcustom gnus-article-date-lapsed-new-header nil
  894. "Whether the X-Sent and Date headers can coexist.
  895. When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
  896. either replace the old \"Date:\" header (if this variable is nil), or
  897. be added below it (otherwise)."
  898. :version "21.1"
  899. :group 'gnus-article-headers
  900. :type 'boolean)
  901. (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
  902. "Function called with a MIME handle as the argument.
  903. This is meant for people who want to view first matched part.
  904. For `undisplayed-alternative' (default), the first undisplayed
  905. part or alternative part is used. For `undisplayed', the first
  906. undisplayed part is used. For a function, the first part which
  907. the function return t is used. For nil, the first part is
  908. used."
  909. :version "21.1"
  910. :group 'gnus-article-mime
  911. :type '(choice
  912. (item :tag "first" :value nil)
  913. (item :tag "undisplayed" :value undisplayed)
  914. (item :tag "undisplayed or alternative"
  915. :value undisplayed-alternative)
  916. (function)))
  917. (defcustom gnus-mime-action-alist
  918. '(("save to file" . gnus-mime-save-part)
  919. ("save and strip" . gnus-mime-save-part-and-strip)
  920. ("replace with file" . gnus-mime-replace-part)
  921. ("delete part" . gnus-mime-delete-part)
  922. ("display as text" . gnus-mime-inline-part)
  923. ("view the part" . gnus-mime-view-part)
  924. ("pipe to command" . gnus-mime-pipe-part)
  925. ("toggle display" . gnus-article-press-button)
  926. ("toggle display" . gnus-article-view-part-as-charset)
  927. ("view as type" . gnus-mime-view-part-as-type)
  928. ("view internally" . gnus-mime-view-part-internally)
  929. ("view externally" . gnus-mime-view-part-externally))
  930. "An alist of actions that run on the MIME attachment."
  931. :group 'gnus-article-mime
  932. :type '(repeat (cons (string :tag "name")
  933. (function))))
  934. (defcustom gnus-auto-select-part 1
  935. "Advance to next MIME part when deleting or stripping parts.
  936. When 0, point will be placed on the same part as before. When
  937. positive (negative), move point forward (backwards) this many
  938. parts. When nil, redisplay article."
  939. :version "23.1" ;; No Gnus
  940. :group 'gnus-article-mime
  941. :type '(choice (const nil :tag "Redisplay article.")
  942. (const 1 :tag "Next part.")
  943. (const 0 :tag "Current part.")
  944. integer))
  945. ;;;
  946. ;;; The treatment variables
  947. ;;;
  948. (defvar gnus-part-display-hook nil
  949. "Hook called on parts that are to receive treatment.")
  950. (defvar gnus-article-treat-custom
  951. '(choice (const :tag "Off" nil)
  952. (const :tag "On" t)
  953. (const :tag "Header" head)
  954. (const :tag "First" first)
  955. (const :tag "Last" last)
  956. (integer :tag "Less")
  957. (repeat :tag "Groups" regexp)
  958. (sexp :tag "Predicate")))
  959. (defvar gnus-article-treat-head-custom
  960. '(choice (const :tag "Off" nil)
  961. (const :tag "Header" head)))
  962. (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
  963. "text/x-patch")
  964. "Parts to treat.")
  965. (defvar gnus-inhibit-treatment nil
  966. "Whether to inhibit treatment.")
  967. (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
  968. "Highlight the signature.
  969. Valid values are nil, t, `head', `first', `last', an integer or a
  970. predicate. See Info node `(gnus)Customizing Articles'."
  971. :group 'gnus-article-treat
  972. :link '(custom-manual "(gnus)Customizing Articles")
  973. :type gnus-article-treat-custom)
  974. (put 'gnus-treat-highlight-signature 'highlight t)
  975. (defcustom gnus-treat-buttonize 100000
  976. "Add buttons.
  977. Valid values are nil, t, `head', `first', `last', an integer or a
  978. predicate. See Info node `(gnus)Customizing Articles'."
  979. :group 'gnus-article-treat
  980. :link '(custom-manual "(gnus)Customizing Articles")
  981. :type gnus-article-treat-custom)
  982. (put 'gnus-treat-buttonize 'highlight t)
  983. (defcustom gnus-treat-buttonize-head 'head
  984. "Add buttons to the head.
  985. Valid values are nil, t, `head', `first', `last', an integer or a
  986. predicate. See Info node `(gnus)Customizing Articles'."
  987. :group 'gnus-article-treat
  988. :link '(custom-manual "(gnus)Customizing Articles")
  989. :type gnus-article-treat-head-custom)
  990. (put 'gnus-treat-buttonize-head 'highlight t)
  991. (defcustom gnus-treat-emphasize 50000
  992. "Emphasize text.
  993. Valid values are nil, t, `head', `first', `last', an integer or a
  994. predicate. See Info node `(gnus)Customizing Articles'."
  995. :group 'gnus-article-treat
  996. :link '(custom-manual "(gnus)Customizing Articles")
  997. :type gnus-article-treat-custom)
  998. (put 'gnus-treat-emphasize 'highlight t)
  999. (defcustom gnus-treat-strip-cr nil
  1000. "Remove carriage returns.
  1001. Valid values are nil, t, `head', `first', `last', an integer or a
  1002. predicate. See Info node `(gnus)Customizing Articles'."
  1003. :version "22.1"
  1004. :group 'gnus-article-treat
  1005. :link '(custom-manual "(gnus)Customizing Articles")
  1006. :type gnus-article-treat-custom)
  1007. (defcustom gnus-treat-unsplit-urls nil
  1008. "Remove newlines from within URLs.
  1009. Valid values are nil, t, `head', `first', `last', an integer or a
  1010. predicate. See Info node `(gnus)Customizing Articles'."
  1011. :version "22.1"
  1012. :group 'gnus-article-treat
  1013. :link '(custom-manual "(gnus)Customizing Articles")
  1014. :type gnus-article-treat-custom)
  1015. (defcustom gnus-treat-leading-whitespace nil
  1016. "Remove leading whitespace in headers.
  1017. Valid values are nil, t, `head', `first', `last', an integer or a
  1018. predicate. See Info node `(gnus)Customizing Articles'."
  1019. :version "22.1"
  1020. :group 'gnus-article-treat
  1021. :link '(custom-manual "(gnus)Customizing Articles")
  1022. :type gnus-article-treat-custom)
  1023. (defcustom gnus-treat-hide-headers 'head
  1024. "Hide headers.
  1025. Valid values are nil, t, `head', `first', `last', an integer or a
  1026. predicate. See Info node `(gnus)Customizing Articles'."
  1027. :group 'gnus-article-treat
  1028. :link '(custom-manual "(gnus)Customizing Articles")
  1029. :type gnus-article-treat-head-custom)
  1030. (defcustom gnus-treat-hide-boring-headers nil
  1031. "Hide boring headers.
  1032. Valid values are nil, t, `head', `first', `last', an integer or a
  1033. predicate. See Info node `(gnus)Customizing Articles'."
  1034. :group 'gnus-article-treat
  1035. :link '(custom-manual "(gnus)Customizing Articles")
  1036. :type gnus-article-treat-head-custom)
  1037. (defcustom gnus-treat-hide-signature nil
  1038. "Hide the signature.
  1039. Valid values are nil, t, `head', `first', `last', an integer or a
  1040. predicate. See Info node `(gnus)Customizing Articles'."
  1041. :group 'gnus-article-treat
  1042. :link '(custom-manual "(gnus)Customizing Articles")
  1043. :type gnus-article-treat-custom)
  1044. (defcustom gnus-treat-fill-article nil
  1045. "Fill the article.
  1046. Valid values are nil, t, `head', `first', `last', an integer or a
  1047. predicate. See Info node `(gnus)Customizing Articles'."
  1048. :group 'gnus-article-treat
  1049. :link '(custom-manual "(gnus)Customizing Articles")
  1050. :type gnus-article-treat-custom)
  1051. (defcustom gnus-treat-hide-citation nil
  1052. "Hide cited text.
  1053. Valid values are nil, t, `head', `first', `last', an integer or a
  1054. predicate. See Info node `(gnus)Customizing Articles'."
  1055. :group 'gnus-article-treat
  1056. :link '(custom-manual "(gnus)Customizing Articles")
  1057. :type gnus-article-treat-custom)
  1058. (defcustom gnus-treat-hide-citation-maybe nil
  1059. "Hide cited text.
  1060. Valid values are nil, t, `head', `first', `last', an integer or a
  1061. predicate. See Info node `(gnus)Customizing Articles'."
  1062. :group 'gnus-article-treat
  1063. :link '(custom-manual "(gnus)Customizing Articles")
  1064. :type gnus-article-treat-custom)
  1065. (defcustom gnus-treat-strip-list-identifiers 'head
  1066. "Strip list identifiers from `gnus-list-identifiers`.
  1067. Valid values are nil, t, `head', `first', `last', an integer or a
  1068. predicate. See Info node `(gnus)Customizing Articles'."
  1069. :version "21.1"
  1070. :group 'gnus-article-treat
  1071. :link '(custom-manual "(gnus)Customizing Articles")
  1072. :type gnus-article-treat-custom)
  1073. (make-obsolete-variable 'gnus-treat-strip-pgp nil
  1074. "Gnus 5.10 (Emacs 22.1)")
  1075. (defcustom gnus-treat-strip-pem nil
  1076. "Strip PEM signatures.
  1077. Valid values are nil, t, `head', `first', `last', an integer or a
  1078. predicate. See Info node `(gnus)Customizing Articles'."
  1079. :group 'gnus-article-treat
  1080. :link '(custom-manual "(gnus)Customizing Articles")
  1081. :type gnus-article-treat-custom)
  1082. (defcustom gnus-treat-strip-banner t
  1083. "Strip banners from articles.
  1084. The banner to be stripped is specified in the `banner' group parameter.
  1085. Valid values are nil, t, `head', `first', `last', an integer or a
  1086. predicate. See Info node `(gnus)Customizing Articles'."
  1087. :group 'gnus-article-treat
  1088. :link '(custom-manual "(gnus)Customizing Articles")
  1089. :type gnus-article-treat-custom)
  1090. (defcustom gnus-treat-highlight-headers 'head
  1091. "Highlight the headers.
  1092. Valid values are nil, t, `head', `first', `last', an integer or a
  1093. predicate. See Info node `(gnus)Customizing Articles'."
  1094. :group 'gnus-article-treat
  1095. :link '(custom-manual "(gnus)Customizing Articles")
  1096. :type gnus-article-treat-head-custom)
  1097. (put 'gnus-treat-highlight-headers 'highlight t)
  1098. (defcustom gnus-treat-highlight-citation t
  1099. "Highlight cited text.
  1100. Valid values are nil, t, `head', `first', `last', an integer or a
  1101. predicate. See Info node `(gnus)Customizing Articles'."
  1102. :group 'gnus-article-treat
  1103. :link '(custom-manual "(gnus)Customizing Articles")
  1104. :type gnus-article-treat-custom)
  1105. (put 'gnus-treat-highlight-citation 'highlight t)
  1106. (defcustom gnus-treat-date-ut nil
  1107. "Display the Date in UT (GMT).
  1108. Valid values are nil, t, `head', `first', `last', an integer or a
  1109. predicate. See Info node `(gnus)Customizing Articles'."
  1110. :group 'gnus-article-treat
  1111. :link '(custom-manual "(gnus)Customizing Articles")
  1112. :type gnus-article-treat-head-custom)
  1113. (defcustom gnus-treat-date-local nil
  1114. "Display the Date in the local timezone.
  1115. Valid values are nil, t, `head', `first', `last', an integer or a
  1116. predicate. See Info node `(gnus)Customizing Articles'."
  1117. :group 'gnus-article-treat
  1118. :link '(custom-manual "(gnus)Customizing Articles")
  1119. :type gnus-article-treat-head-custom)
  1120. (defcustom gnus-treat-date-english nil
  1121. "Display the Date in a format that can be read aloud in English.
  1122. Valid values are nil, t, `head', `first', `last', an integer or a
  1123. predicate. See Info node `(gnus)Customizing Articles'."
  1124. :version "22.1"
  1125. :group 'gnus-article-treat
  1126. :link '(custom-manual "(gnus)Customizing Articles")
  1127. :type gnus-article-treat-head-custom)
  1128. (defcustom gnus-treat-date-lapsed nil
  1129. "Display the Date header in a way that says how much time has elapsed.
  1130. Valid values are nil, t, `head', `first', `last', an integer or a
  1131. predicate. See Info node `(gnus)Customizing Articles'."
  1132. :group 'gnus-article-treat
  1133. :link '(custom-manual "(gnus)Customizing Articles")
  1134. :type gnus-article-treat-head-custom)
  1135. (defcustom gnus-treat-date-original nil
  1136. "Display the date in the original timezone.
  1137. Valid values are nil, t, `head', `first', `last', an integer or a
  1138. predicate. See Info node `(gnus)Customizing Articles'."
  1139. :group 'gnus-article-treat
  1140. :link '(custom-manual "(gnus)Customizing Articles")
  1141. :type gnus-article-treat-head-custom)
  1142. (defcustom gnus-treat-date-iso8601 nil
  1143. "Display the date in the ISO8601 format.
  1144. Valid values are nil, t, `head', `first', `last', an integer or a
  1145. predicate. See Info node `(gnus)Customizing Articles'."
  1146. :version "21.1"
  1147. :group 'gnus-article-treat
  1148. :link '(custom-manual "(gnus)Customizing Articles")
  1149. :type gnus-article-treat-head-custom)
  1150. (defcustom gnus-treat-date-user-defined nil
  1151. "Display the date in a user-defined format.
  1152. The format is defined by the `gnus-article-time-format' variable.
  1153. Valid values are nil, t, `head', `first', `last', an integer or a
  1154. predicate. See Info node `(gnus)Customizing Articles'."
  1155. :group 'gnus-article-treat
  1156. :link '(custom-manual "(gnus)Customizing Articles")
  1157. :type gnus-article-treat-head-custom)
  1158. (defcustom gnus-treat-strip-headers-in-body t
  1159. "Strip the X-No-Archive header line from the beginning of the body.
  1160. Valid values are nil, t, `head', `first', `last', an integer or a
  1161. predicate. See Info node `(gnus)Customizing Articles'."
  1162. :version "21.1"
  1163. :group 'gnus-article-treat
  1164. :link '(custom-manual "(gnus)Customizing Articles")
  1165. :type gnus-article-treat-custom)
  1166. (defcustom gnus-treat-strip-trailing-blank-lines nil
  1167. "Strip trailing blank lines.
  1168. Valid values are nil, t, `head', `first', `last', an integer or a
  1169. predicate. See Info node `(gnus)Customizing Articles'.
  1170. When set to t, it also strips trailing blanks in all MIME parts.
  1171. Consider to use `last' instead."
  1172. :group 'gnus-article-treat
  1173. :link '(custom-manual "(gnus)Customizing Articles")
  1174. :type gnus-article-treat-custom)
  1175. (defcustom gnus-treat-strip-leading-blank-lines nil
  1176. "Strip leading blank lines.
  1177. Valid values are nil, t, `head', `first', `last', an integer or a
  1178. predicate. See Info node `(gnus)Customizing Articles'.
  1179. When set to t, it also strips trailing blanks in all MIME parts."
  1180. :group 'gnus-article-treat
  1181. :link '(custom-manual "(gnus)Customizing Articles")
  1182. :type gnus-article-treat-custom)
  1183. (defcustom gnus-treat-strip-multiple-blank-lines nil
  1184. "Strip multiple blank lines.
  1185. Valid values are nil, t, `head', `first', `last', an integer or a
  1186. predicate. See Info node `(gnus)Customizing Articles'."
  1187. :group 'gnus-article-treat
  1188. :link '(custom-manual "(gnus)Customizing Articles")
  1189. :type gnus-article-treat-custom)
  1190. (defcustom gnus-treat-unfold-headers 'head
  1191. "Unfold folded header lines.
  1192. Valid values are nil, t, `head', `first', `last', an integer or a
  1193. predicate. See Info node `(gnus)Customizing Articles'."
  1194. :version "22.1"
  1195. :group 'gnus-article-treat
  1196. :link '(custom-manual "(gnus)Customizing Articles")
  1197. :type gnus-article-treat-custom)
  1198. (defcustom gnus-article-unfold-long-headers nil
  1199. "If non-nil, allow unfolding headers even if the header is long.
  1200. If it is a regexp, only long headers matching this regexp are unfolded.
  1201. If it is t, all long headers are unfolded.
  1202. This variable has no effect if `gnus-treat-unfold-headers' is nil."
  1203. :version "23.1" ;; No Gnus
  1204. :group 'gnus-article-treat
  1205. :type '(choice (const nil)
  1206. (const :tag "all" t)
  1207. (regexp)))
  1208. (defcustom gnus-treat-fold-headers nil
  1209. "Fold headers.
  1210. Valid values are nil, t, `head', `first', `last', an integer or a
  1211. predicate. See Info node `(gnus)Customizing Articles'."
  1212. :version "22.1"
  1213. :group 'gnus-article-treat
  1214. :link '(custom-manual "(gnus)Customizing Articles")
  1215. :type gnus-article-treat-custom)
  1216. (defcustom gnus-treat-fold-newsgroups 'head
  1217. "Fold the Newsgroups and Followup-To headers.
  1218. Valid values are nil, t, `head', `first', `last', an integer or a
  1219. predicate. See Info node `(gnus)Customizing Articles'."
  1220. :version "22.1"
  1221. :group 'gnus-article-treat
  1222. :link '(custom-manual "(gnus)Customizing Articles")
  1223. :type gnus-article-treat-custom)
  1224. (defcustom gnus-treat-overstrike t
  1225. "Treat overstrike highlighting.
  1226. Valid values are nil, t, `head', `first', `last', an integer or a
  1227. predicate. See Info node `(gnus)Customizing Articles'."
  1228. :group 'gnus-article-treat
  1229. :link '(custom-manual "(gnus)Customizing Articles")
  1230. :type gnus-article-treat-custom)
  1231. (put 'gnus-treat-overstrike 'highlight t)
  1232. (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
  1233. "Treat ANSI SGR control sequences.
  1234. Valid values are nil, t, `head', `first', `last', an integer or a
  1235. predicate. See Info node `(gnus)Customizing Articles'."
  1236. :group 'gnus-article-treat
  1237. :link '(custom-manual "(gnus)Customizing Articles")
  1238. :type gnus-article-treat-custom)
  1239. (make-obsolete-variable 'gnus-treat-display-xface
  1240. 'gnus-treat-display-x-face "22.1")
  1241. (defcustom gnus-treat-display-x-face
  1242. (and (not noninteractive)
  1243. (gnus-image-type-available-p 'xbm)
  1244. (if (featurep 'xemacs)
  1245. (featurep 'xface)
  1246. (and (string-match "^0x" (shell-command-to-string "uncompface"))
  1247. (executable-find "icontopbm")))
  1248. 'head)
  1249. "Display X-Face headers.
  1250. Valid values are nil and `head'.
  1251. See Info node `(gnus)Customizing Articles' and Info node
  1252. `(gnus)X-Face' for details."
  1253. :group 'gnus-article-treat
  1254. :version "21.1"
  1255. :link '(custom-manual "(gnus)Customizing Articles")
  1256. :link '(custom-manual "(gnus)X-Face")
  1257. :type gnus-article-treat-head-custom
  1258. :set (lambda (symbol value)
  1259. (set-default
  1260. symbol
  1261. (cond ((or (boundp symbol) (get symbol 'saved-value))
  1262. value)
  1263. ((boundp 'gnus-treat-display-xface)
  1264. (message "\
  1265. ** gnus-treat-display-xface is an obsolete variable;\
  1266. use gnus-treat-display-x-face instead")
  1267. (default-value 'gnus-treat-display-xface))
  1268. ((get 'gnus-treat-display-xface 'saved-value)
  1269. (message "\
  1270. ** gnus-treat-display-xface is an obsolete variable;\
  1271. use gnus-treat-display-x-face instead")
  1272. (eval (car (get 'gnus-treat-display-xface 'saved-value))))
  1273. (t
  1274. value)))))
  1275. (put 'gnus-treat-display-x-face 'highlight t)
  1276. (defcustom gnus-treat-display-face
  1277. (and (not noninteractive)
  1278. (gnus-image-type-available-p 'png)
  1279. 'head)
  1280. "Display Face headers.
  1281. Valid values are nil, t, `head', `first', `last', an integer or a
  1282. predicate. See Info node `(gnus)Customizing Articles' and Info
  1283. node `(gnus)Face' for details."
  1284. :group 'gnus-article-treat
  1285. :version "22.1"
  1286. :link '(custom-manual "(gnus)Customizing Articles")
  1287. :link '(custom-manual "(gnus)X-Face")
  1288. :type gnus-article-treat-head-custom)
  1289. (put 'gnus-treat-display-face 'highlight t)
  1290. (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
  1291. "Display smileys.
  1292. Valid values are nil, t, `head', `first', `last', an integer or a
  1293. predicate. See Info node `(gnus)Customizing Articles' and Info
  1294. node `(gnus)Smileys' for details."
  1295. :group 'gnus-article-treat
  1296. :version "21.1"
  1297. :link '(custom-manual "(gnus)Customizing Articles")
  1298. :link '(custom-manual "(gnus)Smileys")
  1299. :type gnus-article-treat-custom)
  1300. (put 'gnus-treat-display-smileys 'highlight t)
  1301. (defcustom gnus-treat-from-picon
  1302. (if (and (gnus-image-type-available-p 'xpm)
  1303. (gnus-picons-installed-p))
  1304. 'head nil)
  1305. "Display picons in the From header.
  1306. Valid values are nil, t, `head', `first', `last', an integer or a
  1307. predicate. See Info node `(gnus)Customizing Articles' and Info
  1308. node `(gnus)Picons' for details."
  1309. :version "22.1"
  1310. :group 'gnus-article-treat
  1311. :group 'gnus-picon
  1312. :link '(custom-manual "(gnus)Customizing Articles")
  1313. :link '(custom-manual "(gnus)Picons")
  1314. :type gnus-article-treat-head-custom)
  1315. (put 'gnus-treat-from-picon 'highlight t)
  1316. (defcustom gnus-treat-mail-picon
  1317. (if (and (gnus-image-type-available-p 'xpm)
  1318. (gnus-picons-installed-p))
  1319. 'head nil)
  1320. "Display picons in To and Cc headers.
  1321. Valid values are nil, t, `head', `first', `last', an integer or a
  1322. predicate. See Info node `(gnus)Customizing Articles' and Info
  1323. node `(gnus)Picons' for details."
  1324. :version "22.1"
  1325. :group 'gnus-article-treat
  1326. :group 'gnus-picon
  1327. :link '(custom-manual "(gnus)Customizing Articles")
  1328. :link '(custom-manual "(gnus)Picons")
  1329. :type gnus-article-treat-head-custom)
  1330. (put 'gnus-treat-mail-picon 'highlight t)
  1331. (defcustom gnus-treat-newsgroups-picon
  1332. (if (and (gnus-image-type-available-p 'xpm)
  1333. (gnus-picons-installed-p))
  1334. 'head nil)
  1335. "Display picons in the Newsgroups and Followup-To headers.
  1336. Valid values are nil, t, `head', `first', `last', an integer or a
  1337. predicate. See Info node `(gnus)Customizing Articles' and Info
  1338. node `(gnus)Picons' for details."
  1339. :version "22.1"
  1340. :group 'gnus-article-treat
  1341. :group 'gnus-picon
  1342. :link '(custom-manual "(gnus)Customizing Articles")
  1343. :link '(custom-manual "(gnus)Picons")
  1344. :type gnus-article-treat-head-custom)
  1345. (put 'gnus-treat-newsgroups-picon 'highlight t)
  1346. (defcustom gnus-treat-body-boundary
  1347. (if (or gnus-treat-newsgroups-picon
  1348. gnus-treat-mail-picon
  1349. gnus-treat-from-picon)
  1350. ;; If there's much decoration, the user might prefer a boundery.
  1351. 'head
  1352. nil)
  1353. "Draw a boundary at the end of the headers.
  1354. Valid values are nil and `head'.
  1355. See Info node `(gnus)Customizing Articles' for details."
  1356. :version "22.1"
  1357. :group 'gnus-article-treat
  1358. :link '(custom-manual "(gnus)Customizing Articles")
  1359. :type gnus-article-treat-head-custom)
  1360. (defcustom gnus-treat-capitalize-sentences nil
  1361. "Capitalize sentence-starting words.
  1362. Valid values are nil, t, `head', `first', `last', an integer or a
  1363. predicate. See Info node `(gnus)Customizing Articles'."
  1364. :version "21.1"
  1365. :group 'gnus-article-treat
  1366. :link '(custom-manual "(gnus)Customizing Articles")
  1367. :type gnus-article-treat-custom)
  1368. (defcustom gnus-treat-wash-html nil
  1369. "Format as HTML.
  1370. Valid values are nil, t, `head', `first', `last', an integer or a
  1371. predicate. See Info node `(gnus)Customizing Articles'."
  1372. :version "22.1"
  1373. :group 'gnus-article-treat
  1374. :link '(custom-manual "(gnus)Customizing Articles")
  1375. :type gnus-article-treat-custom)
  1376. (defcustom gnus-treat-fill-long-lines nil
  1377. "Fill long lines.
  1378. Valid values are nil, t, `head', `first', `last', an integer or a
  1379. predicate. See Info node `(gnus)Customizing Articles'."
  1380. :group 'gnus-article-treat
  1381. :link '(custom-manual "(gnus)Customizing Articles")
  1382. :type gnus-article-treat-custom)
  1383. (defcustom gnus-treat-play-sounds nil
  1384. "Play sounds.
  1385. Valid values are nil, t, `head', `first', `last', an integer or a
  1386. predicate. See Info node `(gnus)Customizing Articles'."
  1387. :version "21.1"
  1388. :group 'gnus-article-treat
  1389. :link '(custom-manual "(gnus)Customizing Articles")
  1390. :type gnus-article-treat-custom)
  1391. (defcustom gnus-treat-translate nil
  1392. "Translate articles from one language to another.
  1393. Valid values are nil, t, `head', `first', `last', an integer or a
  1394. predicate. See Info node `(gnus)Customizing Articles'."
  1395. :version "21.1"
  1396. :group 'gnus-article-treat
  1397. :link '(custom-manual "(gnus)Customizing Articles")
  1398. :type gnus-article-treat-custom)
  1399. (defcustom gnus-treat-x-pgp-sig nil
  1400. "Verify X-PGP-Sig.
  1401. To automatically treat X-PGP-Sig, set it to head.
  1402. Valid values are nil, t, `head', `first', `last', an integer or a
  1403. predicate. See Info node `(gnus)Customizing Articles'."
  1404. :version "22.1"
  1405. :group 'gnus-article-treat
  1406. :group 'mime-security
  1407. :link '(custom-manual "(gnus)Customizing Articles")
  1408. :type gnus-article-treat-custom)
  1409. (defvar gnus-article-encrypt-protocol-alist
  1410. '(("PGP" . mml2015-self-encrypt)))
  1411. ;; Set to nil if more than one protocol added to
  1412. ;; gnus-article-encrypt-protocol-alist.
  1413. (defcustom gnus-article-encrypt-protocol "PGP"
  1414. "The protocol used for encrypt articles.
  1415. It is a string, such as \"PGP\". If nil, ask user."
  1416. :version "22.1"
  1417. :type 'string
  1418. :group 'mime-security)
  1419. (defvar gnus-article-wash-function nil
  1420. "Function used for converting HTML into text.")
  1421. (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
  1422. (mm-coding-system-p 'utf-8)
  1423. (executable-find idna-program))
  1424. "Whether IDNA decoding of headers is used when viewing messages.
  1425. This requires GNU Libidn, and by default only enabled if it is found."
  1426. :version "22.1"
  1427. :group 'gnus-article-headers
  1428. :type 'boolean)
  1429. (defcustom gnus-article-over-scroll nil
  1430. "If non-nil, allow scrolling the article buffer even when there no more text."
  1431. :version "22.1"
  1432. :group 'gnus-article
  1433. :type 'boolean)
  1434. ;;; Internal variables
  1435. (defvar gnus-english-month-names
  1436. '("January" "February" "March" "April" "May" "June" "July" "August"
  1437. "September" "October" "November" "December"))
  1438. (defvar article-goto-body-goes-to-point-min-p nil)
  1439. (defvar gnus-article-wash-types nil)
  1440. (defvar gnus-article-emphasis-alist nil)
  1441. (defvar gnus-article-image-alist nil)
  1442. (defvar gnus-article-mime-handle-alist-1 nil)
  1443. (defvar gnus-treatment-function-alist
  1444. '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
  1445. (gnus-treat-strip-banner gnus-article-strip-banner)
  1446. (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
  1447. (gnus-treat-highlight-signature gnus-article-highlight-signature)
  1448. (gnus-treat-buttonize gnus-article-add-buttons)
  1449. (gnus-treat-fill-article gnus-article-fill-cited-article)
  1450. (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
  1451. (gnus-treat-strip-cr gnus-article-remove-cr)
  1452. (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
  1453. (gnus-treat-date-ut gnus-article-date-ut)
  1454. (gnus-treat-date-local gnus-article-date-local)
  1455. (gnus-treat-date-english gnus-article-date-english)
  1456. (gnus-treat-date-original gnus-article-date-original)
  1457. (gnus-treat-date-user-defined gnus-article-date-user)
  1458. (gnus-treat-date-iso8601 gnus-article-date-iso8601)
  1459. (gnus-treat-date-lapsed gnus-article-date-lapsed)
  1460. (gnus-treat-display-x-face gnus-article-display-x-face)
  1461. (gnus-treat-display-face gnus-article-display-face)
  1462. (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
  1463. (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
  1464. (gnus-treat-hide-signature gnus-article-hide-signature)
  1465. (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
  1466. (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
  1467. (gnus-treat-strip-pem gnus-article-hide-pem)
  1468. (gnus-treat-from-picon gnus-treat-from-picon)
  1469. (gnus-treat-mail-picon gnus-treat-mail-picon)
  1470. (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
  1471. (gnus-treat-highlight-headers gnus-article-highlight-headers)
  1472. (gnus-treat-highlight-signature gnus-article-highlight-signature)
  1473. (gnus-treat-strip-trailing-blank-lines
  1474. gnus-article-remove-trailing-blank-lines)
  1475. (gnus-treat-strip-leading-blank-lines
  1476. gnus-article-strip-leading-blank-lines)
  1477. (gnus-treat-strip-multiple-blank-lines
  1478. gnus-article-strip-multiple-blank-lines)
  1479. (gnus-treat-overstrike gnus-article-treat-overstrike)
  1480. (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
  1481. (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
  1482. (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
  1483. (gnus-treat-fold-headers gnus-article-treat-fold-headers)
  1484. (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
  1485. (gnus-treat-display-smileys gnus-treat-smiley)
  1486. (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
  1487. (gnus-treat-wash-html gnus-article-wash-html)
  1488. (gnus-treat-emphasize gnus-article-emphasize)
  1489. (gnus-treat-hide-citation gnus-article-hide-citation)
  1490. (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
  1491. (gnus-treat-highlight-citation gnus-article-highlight-citation)
  1492. (gnus-treat-body-boundary gnus-article-treat-body-boundary)
  1493. (gnus-treat-play-sounds gnus-earcon-display)))
  1494. (defvar gnus-article-mime-handle-alist nil)
  1495. (defvar article-lapsed-timer nil)
  1496. (defvar gnus-article-current-summary nil)
  1497. (defvar gnus-article-mode-syntax-table
  1498. (let ((table (copy-syntax-table text-mode-syntax-table)))
  1499. ;; This causes the citation match run O(2^n).
  1500. ;; (modify-syntax-entry ?- "w" table)
  1501. (modify-syntax-entry ?> ")<" table)
  1502. (modify-syntax-entry ?< "(>" table)
  1503. ;; make M-. in article buffers work for `foo' strings
  1504. (modify-syntax-entry ?' " " table)
  1505. (modify-syntax-entry ?` " " table)
  1506. table)
  1507. "Syntax table used in article mode buffers.
  1508. Initialized from `text-mode-syntax-table.")
  1509. (defvar gnus-save-article-buffer nil)
  1510. (defvar gnus-number-of-articles-to-be-saved nil)
  1511. (defvar gnus-inhibit-hiding nil)
  1512. (defvar gnus-article-edit-mode nil)
  1513. ;;; Macros for dealing with the article buffer.
  1514. (defmacro gnus-with-article-headers (&rest forms)
  1515. `(with-current-buffer gnus-article-buffer
  1516. (save-restriction
  1517. (let ((inhibit-read-only t)
  1518. (inhibit-point-motion-hooks t)
  1519. (case-fold-search t))
  1520. (article-narrow-to-head)
  1521. ,@forms))))
  1522. (put 'gnus-with-article-headers 'lisp-indent-function 0)
  1523. (put 'gnus-with-article-headers 'edebug-form-spec '(body))
  1524. (defmacro gnus-with-article-buffer (&rest forms)
  1525. `(with-current-buffer gnus-article-buffer
  1526. (let ((inhibit-read-only t))
  1527. ,@forms)))
  1528. (put 'gnus-with-article-buffer 'lisp-indent-function 0)
  1529. (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
  1530. (defun gnus-article-goto-header (header)
  1531. "Go to HEADER, which is a regular expression."
  1532. (re-search-forward (concat "^\\(" header "\\):") nil t))
  1533. (defsubst gnus-article-hide-text (b e props)
  1534. "Set text PROPS on the B to E region, extending `intangible' 1 past B."
  1535. (gnus-add-text-properties-when 'article-type nil b e props)
  1536. (when (memq 'intangible props)
  1537. (put-text-property
  1538. (max (1- b) (point-min))
  1539. b 'intangible (cddr (memq 'intangible props)))))
  1540. (defsubst gnus-article-unhide-text (b e)
  1541. "Remove hidden text properties from region between B and E."
  1542. (remove-text-properties b e gnus-hidden-properties)
  1543. (when (memq 'intangible gnus-hidden-properties)
  1544. (put-text-property (max (1- b) (point-min))
  1545. b 'intangible nil)))
  1546. (defun gnus-article-hide-text-type (b e type)
  1547. "Hide text of TYPE between B and E."
  1548. (gnus-add-wash-type type)
  1549. (gnus-article-hide-text
  1550. b e (cons 'article-type (cons type gnus-hidden-properties))))
  1551. (defun gnus-article-unhide-text-type (b e type)
  1552. "Unhide text of TYPE between B and E."
  1553. (gnus-delete-wash-type type)
  1554. (remove-text-properties
  1555. b e (cons 'article-type (cons type gnus-hidden-properties)))
  1556. (when (memq 'intangible gnus-hidden-properties)
  1557. (put-text-property (max (1- b) (point-min))
  1558. b 'intangible nil)))
  1559. (defun gnus-article-hide-text-of-type (type)
  1560. "Hide text of TYPE in the current buffer."
  1561. (save-excursion
  1562. (let ((b (point-min))
  1563. (e (point-max)))
  1564. (while (setq b (text-property-any b e 'article-type type))
  1565. (add-text-properties b (incf b) gnus-hidden-properties)))))
  1566. (defun gnus-article-delete-text-of-type (type)
  1567. "Delete text of TYPE in the current buffer."
  1568. (save-excursion
  1569. (let ((b (point-min)))
  1570. (if (eq type 'multipart)
  1571. ;; Remove MIME buttons associated with multipart/alternative parts.
  1572. (progn
  1573. (goto-char b)
  1574. (while (if (get-text-property (point) 'gnus-part)
  1575. (setq b (point))
  1576. (when (setq b (next-single-property-change (point)
  1577. 'gnus-part))
  1578. (goto-char b)
  1579. t))
  1580. (end-of-line)
  1581. (skip-chars-forward "\n")
  1582. (when (eq (get-text-property b 'article-type) 'multipart)
  1583. (delete-region b (point)))))
  1584. (while (setq b (text-property-any b (point-max) 'article-type type))
  1585. (delete-region
  1586. b (or (text-property-not-all b (point-max) 'article-type type)
  1587. (point-max))))))))
  1588. (defun gnus-article-delete-invisible-text ()
  1589. "Delete all invisible text in the current buffer."
  1590. (save-excursion
  1591. (let ((b (point-min)))
  1592. (while (setq b (text-property-any b (point-max) 'invisible t))
  1593. (delete-region
  1594. b (or (text-property-not-all b (point-max) 'invisible t)
  1595. (point-max)))))))
  1596. (defun gnus-article-text-type-exists-p (type)
  1597. "Say whether any text of type TYPE exists in the buffer."
  1598. (text-property-any (point-min) (point-max) 'article-type type))
  1599. (defsubst gnus-article-header-rank ()
  1600. "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
  1601. (let ((list gnus-sorted-header-list)
  1602. (i 1))
  1603. (while list
  1604. (if (looking-at (car list))
  1605. (setq list nil)
  1606. (setq list (cdr list))
  1607. (incf i)))
  1608. i))
  1609. (defun article-hide-headers (&optional arg delete)
  1610. "Hide unwanted headers and possibly sort them as well."
  1611. (interactive)
  1612. ;; This function might be inhibited.
  1613. (unless gnus-inhibit-hiding
  1614. (let ((inhibit-read-only t)
  1615. (case-fold-search t)
  1616. (max (1+ (length gnus-sorted-header-list)))
  1617. (inhibit-point-motion-hooks t)
  1618. (cur (current-buffer))
  1619. ignored visible beg)
  1620. (save-excursion
  1621. ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
  1622. ;; group parameters, so we should go to the summary buffer.
  1623. (when (prog1
  1624. (condition-case nil
  1625. (progn (set-buffer gnus-summary-buffer) t)
  1626. (error nil))
  1627. (setq ignored (when (not gnus-visible-headers)
  1628. (cond ((stringp gnus-ignored-headers)
  1629. gnus-ignored-headers)
  1630. ((listp gnus-ignored-headers)
  1631. (mapconcat 'identity
  1632. gnus-ignored-headers
  1633. "\\|"))))
  1634. visible (cond ((stringp gnus-visible-headers)
  1635. gnus-visible-headers)
  1636. ((and gnus-visible-headers
  1637. (listp gnus-visible-headers))
  1638. (mapconcat 'identity
  1639. gnus-visible-headers
  1640. "\\|")))))
  1641. (set-buffer cur))
  1642. (save-restriction
  1643. ;; First we narrow to just the headers.
  1644. (article-narrow-to-head)
  1645. ;; Hide any "From " lines at the beginning of (mail) articles.
  1646. (while (looking-at "From ")
  1647. (forward-line 1))
  1648. (unless (bobp)
  1649. (delete-region (point-min) (point)))
  1650. ;; Then treat the rest of the header lines.
  1651. ;; Then we use the two regular expressions
  1652. ;; `gnus-ignored-headers' and `gnus-visible-headers' to
  1653. ;; select which header lines is to remain visible in the
  1654. ;; article buffer.
  1655. (while (re-search-forward "^[^ \t:]*:" nil t)
  1656. (beginning-of-line)
  1657. ;; Mark the rank of the header.
  1658. (put-text-property
  1659. (point) (1+ (point)) 'message-rank
  1660. (if (or (and visible (looking-at visible))
  1661. (and ignored
  1662. (not (looking-at ignored))))
  1663. (gnus-article-header-rank)
  1664. (+ 2 max)))
  1665. (forward-line 1))
  1666. (message-sort-headers-1)
  1667. (when (setq beg (text-property-any
  1668. (point-min) (point-max) 'message-rank (+ 2 max)))
  1669. ;; We delete the unwanted headers.
  1670. (gnus-add-wash-type 'headers)
  1671. (add-text-properties (point-min) (+ 5 (point-min))
  1672. '(article-type headers dummy-invisible t))
  1673. (delete-region beg (point-max))))))))
  1674. (defun article-hide-boring-headers (&optional arg)
  1675. "Toggle hiding of headers that aren't very interesting.
  1676. If given a negative prefix, always show; if given a positive prefix,
  1677. always hide."
  1678. (interactive (gnus-article-hidden-arg))
  1679. (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
  1680. (not gnus-show-all-headers))
  1681. (save-excursion
  1682. (save-restriction
  1683. (let ((inhibit-read-only t)
  1684. (inhibit-point-motion-hooks t))
  1685. (article-narrow-to-head)
  1686. (dolist (elem gnus-boring-article-headers)
  1687. (goto-char (point-min))
  1688. (cond
  1689. ;; Hide empty headers.
  1690. ((eq elem 'empty)
  1691. (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
  1692. (forward-line -1)
  1693. (gnus-article-hide-text-type
  1694. (point-at-bol)
  1695. (progn
  1696. (end-of-line)
  1697. (if (re-search-forward "^[^ \t]" nil t)
  1698. (match-beginning 0)
  1699. (point-max)))
  1700. 'boring-headers)))
  1701. ;; Hide boring Newsgroups header.
  1702. ((eq elem 'newsgroups)
  1703. (when (gnus-string-equal
  1704. (gnus-fetch-field "newsgroups")
  1705. (gnus-group-real-name
  1706. (if (boundp 'gnus-newsgroup-name)
  1707. gnus-newsgroup-name
  1708. "")))
  1709. (gnus-article-hide-header "newsgroups")))
  1710. ((eq elem 'to-address)
  1711. (let ((to (message-fetch-field "to"))
  1712. (to-address
  1713. (gnus-parameter-to-address
  1714. (if (boundp 'gnus-newsgroup-name)
  1715. gnus-newsgroup-name ""))))
  1716. (when (and to to-address
  1717. (ignore-errors
  1718. (gnus-string-equal
  1719. ;; only one address in To
  1720. (nth 1 (mail-extract-address-components to))
  1721. to-address)))
  1722. (gnus-article-hide-header "to"))))
  1723. ((eq elem 'to-list)
  1724. (let ((to (message-fetch-field "to"))
  1725. (to-list
  1726. (gnus-parameter-to-list
  1727. (if (boundp 'gnus-newsgroup-name)
  1728. gnus-newsgroup-name ""))))
  1729. (when (and to to-list
  1730. (ignore-errors
  1731. (gnus-string-equal
  1732. ;; only one address in To
  1733. (nth 1 (mail-extract-address-components to))
  1734. to-list)))
  1735. (gnus-article-hide-header "to"))))
  1736. ((eq elem 'cc-list)
  1737. (let ((cc (message-fetch-field "cc"))
  1738. (to-list
  1739. (gnus-parameter-to-list
  1740. (if (boundp 'gnus-newsgroup-name)
  1741. gnus-newsgroup-name ""))))
  1742. (when (and cc to-list
  1743. (ignore-errors
  1744. (gnus-string-equal
  1745. ;; only one address in CC
  1746. (nth 1 (mail-extract-address-components cc))
  1747. to-list)))
  1748. (gnus-article-hide-header "cc"))))
  1749. ((eq elem 'followup-to)
  1750. (when (gnus-string-equal
  1751. (message-fetch-field "followup-to")
  1752. (message-fetch-field "newsgroups"))
  1753. (gnus-article-hide-header "followup-to")))
  1754. ((eq elem 'reply-to)
  1755. (if (gnus-group-find-parameter
  1756. gnus-newsgroup-name 'broken-reply-to)
  1757. (gnus-article-hide-header "reply-to")
  1758. (let ((from (message-fetch-field "from"))
  1759. (reply-to (message-fetch-field "reply-to")))
  1760. (when
  1761. (and
  1762. from reply-to
  1763. (ignore-errors
  1764. (equal
  1765. (sort (mapcar
  1766. (lambda (x) (downcase (cadr x)))
  1767. (mail-extract-address-components from t))
  1768. 'string<)
  1769. (sort (mapcar
  1770. (lambda (x) (downcase (cadr x)))
  1771. (mail-extract-address-components reply-to t))
  1772. 'string<))))
  1773. (gnus-article-hide-header "reply-to")))))
  1774. ((eq elem 'date)
  1775. (let ((date (with-current-buffer gnus-original-article-buffer
  1776. ;; If date in `gnus-article-buffer' is localized
  1777. ;; (`gnus-treat-date-user-defined'),
  1778. ;; `days-between' might fail.
  1779. (message-fetch-field "date"))))
  1780. (when (and date
  1781. (< (days-between (current-time-string) date)
  1782. 4))
  1783. (gnus-article-hide-header "date"))))
  1784. ((eq elem 'long-to)
  1785. (let ((to (message-fetch-field "to"))
  1786. (cc (message-fetch-field "cc")))
  1787. (when (> (length to) 1024)
  1788. (gnus-article-hide-header "to"))
  1789. (when (> (length cc) 1024)
  1790. (gnus-article-hide-header "cc"))))
  1791. ((eq elem 'many-to)
  1792. (let ((to-count 0)
  1793. (cc-count 0))
  1794. (goto-char (point-min))
  1795. (while (re-search-forward "^to:" nil t)
  1796. (setq to-count (1+ to-count)))
  1797. (when (> to-count 1)
  1798. (while (> to-count 0)
  1799. (goto-char (point-min))
  1800. (save-restriction
  1801. (re-search-forward "^to:" nil nil to-count)
  1802. (forward-line -1)
  1803. (narrow-to-region (point) (point-max))
  1804. (gnus-article-hide-header "to"))
  1805. (setq to-count (1- to-count))))
  1806. (goto-char (point-min))
  1807. (while (re-search-forward "^cc:" nil t)
  1808. (setq cc-count (1+ cc-count)))
  1809. (when (> cc-count 1)
  1810. (while (> cc-count 0)
  1811. (goto-char (point-min))
  1812. (save-restriction
  1813. (re-search-forward "^cc:" nil nil cc-count)
  1814. (forward-line -1)
  1815. (narrow-to-region (point) (point-max))
  1816. (gnus-article-hide-header "cc"))
  1817. (setq cc-count (1- cc-count)))))))))))))
  1818. (defun gnus-article-hide-header (header)
  1819. (save-excursion
  1820. (goto-char (point-min))
  1821. (when (re-search-forward (concat "^" header ":") nil t)
  1822. (gnus-article-hide-text-type
  1823. (point-at-bol)
  1824. (progn
  1825. (end-of-line)
  1826. (if (re-search-forward "^[^ \t]" nil t)
  1827. (match-beginning 0)
  1828. (point-max)))
  1829. 'boring-headers))))
  1830. (defvar gnus-article-normalized-header-length 40
  1831. "Length of normalized headers.")
  1832. (defun article-normalize-headers ()
  1833. "Make all header lines 40 characters long."
  1834. (interactive)
  1835. (let ((inhibit-read-only t)
  1836. column)
  1837. (save-excursion
  1838. (save-restriction
  1839. (article-narrow-to-head)
  1840. (while (not (eobp))
  1841. (cond
  1842. ((< (setq column (- (point-at-eol) (point)))
  1843. gnus-article-normalized-header-length)
  1844. (end-of-line)
  1845. (insert (make-string
  1846. (- gnus-article-normalized-header-length column)
  1847. ? )))
  1848. ((> column gnus-article-normalized-header-length)
  1849. (gnus-put-text-property
  1850. (progn
  1851. (forward-char gnus-article-normalized-header-length)
  1852. (point))
  1853. (point-at-eol)
  1854. 'invisible t))
  1855. (t
  1856. ;; Do nothing.
  1857. ))
  1858. (forward-line 1))))))
  1859. (defun article-treat-dumbquotes ()
  1860. "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
  1861. Note that this function guesses whether a character is a sm*rtq**t* or
  1862. not, so it should only be used interactively.
  1863. Sm*rtq**t*s are M****s***'s unilateral extension to the
  1864. iso-8859-1 character map in an attempt to provide more quoting
  1865. characters. If you see something like \\222 or \\264 where
  1866. you're expecting some kind of apostrophe or quotation mark, then
  1867. try this wash."
  1868. (interactive)
  1869. (article-translate-strings gnus-article-dumbquotes-map))
  1870. (defun article-translate-characters (from to)
  1871. "Translate all characters in the body of the article according to FROM and TO.
  1872. FROM is a string of characters to translate from; to is a string of
  1873. characters to translate to."
  1874. (save-excursion
  1875. (when (article-goto-body)
  1876. (let ((inhibit-read-only t)
  1877. (x (make-string 225 ?x))
  1878. (i -1))
  1879. (while (< (incf i) (length x))
  1880. (aset x i i))
  1881. (setq i 0)
  1882. (while (< i (length from))
  1883. (aset x (aref from i) (aref to i))
  1884. (incf i))
  1885. (translate-region (point) (point-max) x)))))
  1886. (defun article-translate-strings (map)
  1887. "Translate all string in the body of the article according to MAP.
  1888. MAP is an alist where the elements are on the form (\"from\" \"to\")."
  1889. (save-excursion
  1890. (when (article-goto-body)
  1891. (let ((inhibit-read-only t))
  1892. (dolist (elem map)
  1893. (save-excursion
  1894. (while (search-forward (car elem) nil t)
  1895. (replace-match (cadr elem)))))))))
  1896. (defun article-treat-overstrike ()
  1897. "Translate overstrikes into bold text."
  1898. (interactive)
  1899. (save-excursion
  1900. (when (article-goto-body)
  1901. (let ((inhibit-read-only t))
  1902. (while (search-forward "\b" nil t)
  1903. (let ((next (char-after))
  1904. (previous (char-after (- (point) 2))))
  1905. ;; We do the boldification/underlining by hiding the
  1906. ;; overstrikes and putting the proper text property
  1907. ;; on the letters.
  1908. (cond
  1909. ((eq next previous)
  1910. (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
  1911. (put-text-property (point) (1+ (point)) 'face 'bold))
  1912. ((eq next ?_)
  1913. (gnus-article-hide-text-type
  1914. (1- (point)) (1+ (point)) 'overstrike)
  1915. (put-text-property
  1916. (- (point) 2) (1- (point)) 'face 'underline))
  1917. ((eq previous ?_)
  1918. (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
  1919. (put-text-property
  1920. (point) (1+ (point)) 'face 'underline)))))))))
  1921. (defun article-treat-ansi-sequences ()
  1922. "Translate ANSI SGR control sequences into overlays or extents."
  1923. (interactive)
  1924. (save-excursion
  1925. (when (article-goto-body)
  1926. (let ((inhibit-read-only t))
  1927. (ansi-color-apply-on-region (point) (point-max))))))
  1928. (defun gnus-article-treat-unfold-headers ()
  1929. "Unfold folded message headers.
  1930. Only the headers that fit into the current window width will be
  1931. unfolded."
  1932. (interactive)
  1933. (gnus-with-article-headers
  1934. (let (length)
  1935. (while (not (eobp))
  1936. (save-restriction
  1937. (mail-header-narrow-to-field)
  1938. (let* ((header (buffer-string))
  1939. (unfoldable
  1940. (or (equal gnus-article-unfold-long-headers t)
  1941. (and (stringp gnus-article-unfold-long-headers)
  1942. (string-match gnus-article-unfold-long-headers header)))))
  1943. (with-temp-buffer
  1944. (insert header)
  1945. (goto-char (point-min))
  1946. (while (re-search-forward "\n[\t ]" nil t)
  1947. (replace-match " " t t)))
  1948. (setq length (- (point-max) (point-min) 1))
  1949. (when (or unfoldable
  1950. (< length (window-width)))
  1951. (while (re-search-forward "\n[\t ]" nil t)
  1952. (replace-match " " t t))))
  1953. (goto-char (point-max)))))))
  1954. (defun gnus-article-treat-fold-headers ()
  1955. "Fold message headers."
  1956. (interactive)
  1957. (gnus-with-article-headers
  1958. (while (not (eobp))
  1959. (save-restriction
  1960. (mail-header-narrow-to-field)
  1961. (mail-header-fold-field)
  1962. (goto-char (point-max))))))
  1963. (defun gnus-treat-smiley ()
  1964. "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
  1965. (interactive)
  1966. (gnus-with-article-buffer
  1967. (if (memq 'smiley gnus-article-wash-types)
  1968. (gnus-delete-images 'smiley)
  1969. (article-goto-body)
  1970. (let ((images (smiley-region (point) (point-max))))
  1971. (when images
  1972. (gnus-add-wash-type 'smiley)
  1973. (dolist (image images)
  1974. (gnus-add-image 'smiley image)))))))
  1975. (defun gnus-article-remove-images ()
  1976. "Remove all images from the article buffer."
  1977. (interactive)
  1978. (gnus-with-article-buffer
  1979. (dolist (elem gnus-article-image-alist)
  1980. (gnus-delete-images (car elem)))))
  1981. (defun gnus-article-treat-fold-newsgroups ()
  1982. "Unfold folded message headers.
  1983. Only the headers that fit into the current window width will be
  1984. unfolded."
  1985. (interactive)
  1986. (gnus-with-article-headers
  1987. (while (gnus-article-goto-header "newsgroups\\|followup-to")
  1988. (save-restriction
  1989. (mail-header-narrow-to-field)
  1990. (while (re-search-forward ", *" nil t)
  1991. (replace-match ", " t t))
  1992. (mail-header-fold-field)
  1993. (goto-char (point-max))))))
  1994. (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
  1995. "Value of `truncate-lines' in Gnus Article buffer.
  1996. Valid values are nil, t, `head', `first', `last', an integer or a
  1997. predicate. See Info node `(gnus)Customizing Articles'."
  1998. :version "23.1" ;; No Gnus
  1999. :group 'gnus-article
  2000. ;; :link '(custom-manual "(gnus)Customizing Articles")
  2001. :type 'boolean)
  2002. (defun gnus-article-toggle-truncate-lines (&optional arg)
  2003. "Toggle whether to fold or truncate long lines in article the buffer.
  2004. If ARG is non-nil and not a number, toggle
  2005. `gnus-article-truncate-lines' too. If ARG is a number, truncate
  2006. long lines if and only if arg is positive."
  2007. (interactive "P")
  2008. (cond
  2009. ((and (numberp arg) (> arg 0))
  2010. (setq gnus-article-truncate-lines t))
  2011. ((numberp arg)
  2012. (setq gnus-article-truncate-lines nil))
  2013. (arg
  2014. (setq gnus-article-truncate-lines
  2015. (not gnus-article-truncate-lines))))
  2016. (gnus-with-article-buffer
  2017. (cond
  2018. ((and (numberp arg) (> arg 0))
  2019. (setq truncate-lines nil))
  2020. ((numberp arg)
  2021. (setq truncate-lines t)))
  2022. ;; In versions of Emacs 22 (CVS) before 2006-05-26,
  2023. ;; `toggle-truncate-lines' needs an argument.
  2024. (toggle-truncate-lines)))
  2025. (defun gnus-article-treat-body-boundary ()
  2026. "Place a boundary line at the end of the headers."
  2027. (interactive)
  2028. (when (and gnus-body-boundary-delimiter
  2029. (> (length gnus-body-boundary-delimiter) 0))
  2030. (gnus-with-article-headers
  2031. (goto-char (point-max))
  2032. (let ((start (point)))
  2033. (insert "X-Boundary: ")
  2034. (gnus-add-text-properties start (point) '(invisible t intangible t))
  2035. (insert (let (str)
  2036. (while (>= (1- (window-width)) (length str))
  2037. (setq str (concat str gnus-body-boundary-delimiter)))
  2038. (substring str 0 (1- (window-width))))
  2039. "\n")
  2040. (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
  2041. (defun article-fill-long-lines ()
  2042. "Fill lines that are wider than the window width."
  2043. (interactive)
  2044. (save-excursion
  2045. (let ((inhibit-read-only t)
  2046. (width (window-width (get-buffer-window (current-buffer)))))
  2047. (save-restriction
  2048. (article-goto-body)
  2049. (let ((adaptive-fill-mode nil)) ;Why? -sm
  2050. (while (not (eobp))
  2051. (end-of-line)
  2052. (when (>= (current-column) (min fill-column width))
  2053. (narrow-to-region (min (1+ (point)) (point-max))
  2054. (point-at-bol))
  2055. (let ((goback (point-marker)))
  2056. (fill-paragraph nil)
  2057. (goto-char (marker-position goback)))
  2058. (widen))
  2059. (forward-line 1)))))))
  2060. (defun article-capitalize-sentences ()
  2061. "Capitalize the first word in each sentence."
  2062. (interactive)
  2063. (save-excursion
  2064. (let ((inhibit-read-only t)
  2065. (paragraph-start "^[\n\^L]"))
  2066. (article-goto-body)
  2067. (while (not (eobp))
  2068. (capitalize-word 1)
  2069. (forward-sentence)))))
  2070. (defun article-remove-cr ()
  2071. "Remove trailing CRs and then translate remaining CRs into LFs."
  2072. (interactive)
  2073. (save-excursion
  2074. (let ((inhibit-read-only t))
  2075. (goto-char (point-min))
  2076. (while (re-search-forward "\r+$" nil t)
  2077. (replace-match "" t t))
  2078. (goto-char (point-min))
  2079. (while (search-forward "\r" nil t)
  2080. (replace-match "\n" t t)))))
  2081. (defun article-remove-trailing-blank-lines ()
  2082. "Remove all trailing blank lines from the article."
  2083. (interactive)
  2084. (save-excursion
  2085. (let ((inhibit-read-only t))
  2086. (goto-char (point-max))
  2087. (delete-region
  2088. (point)
  2089. (progn
  2090. (while (and (not (bobp))
  2091. (looking-at "^[ \t]*$")
  2092. (not (gnus-annotation-in-region-p
  2093. (point) (point-at-eol))))
  2094. (forward-line -1))
  2095. (forward-line 1)
  2096. (point))))))
  2097. (defvar gnus-face-properties-alist)
  2098. (defun article-display-face (&optional force)
  2099. "Display any Face headers in the header."
  2100. (interactive (list 'force))
  2101. (let ((wash-face-p buffer-read-only))
  2102. (gnus-with-article-headers
  2103. ;; When displaying parts, this function can be called several times on
  2104. ;; the same article, without any intended toggle semantic (as typing `W
  2105. ;; D d' would have). So face deletion must occur only when we come from
  2106. ;; an interactive command, that is when the *Article* buffer is
  2107. ;; read-only.
  2108. (if (and wash-face-p (memq 'face gnus-article-wash-types))
  2109. (gnus-delete-images 'face)
  2110. (let ((from (message-fetch-field "from"))
  2111. face faces)
  2112. (save-current-buffer
  2113. (when (and wash-face-p
  2114. (gnus-buffer-live-p gnus-original-article-buffer)
  2115. (not (re-search-forward "^Face:[\t ]*" nil t)))
  2116. (set-buffer gnus-original-article-buffer))
  2117. (save-restriction
  2118. (mail-narrow-to-head)
  2119. (when (or force
  2120. ;; Check whether this face is censored.
  2121. (not (and gnus-article-x-face-too-ugly
  2122. (or from
  2123. (setq from (message-fetch-field "from")))
  2124. (string-match gnus-article-x-face-too-ugly
  2125. from))))
  2126. (while (gnus-article-goto-header "Face")
  2127. (push (mail-header-field-value) faces)))))
  2128. (when faces
  2129. (goto-char (point-min))
  2130. (let (png image)
  2131. (unless (setq from (gnus-article-goto-header "from"))
  2132. (insert "From:")
  2133. (setq from (point))
  2134. (insert " [no `from' set]\n"))
  2135. (while faces
  2136. (when (setq png (gnus-convert-face-to-png (pop faces)))
  2137. (setq image
  2138. (apply 'gnus-create-image png 'png t
  2139. (cdr (assq 'png gnus-face-properties-alist))))
  2140. (goto-char from)
  2141. (gnus-add-wash-type 'face)
  2142. (gnus-add-image 'face image)
  2143. (gnus-put-image image nil 'face))))))))))
  2144. (defun article-display-x-face (&optional force)
  2145. "Look for an X-Face header and display it if present."
  2146. (interactive (list 'force))
  2147. (let ((wash-face-p buffer-read-only)) ;; When type `W f'
  2148. (gnus-with-article-headers
  2149. ;; Delete the old process, if any.
  2150. (when (process-status "article-x-face")
  2151. (delete-process "article-x-face"))
  2152. ;; See the comment in `article-display-face'.
  2153. (if (and wash-face-p (memq 'xface gnus-article-wash-types))
  2154. ;; We have already displayed X-Faces, so we remove them
  2155. ;; instead.
  2156. (gnus-delete-images 'xface)
  2157. ;; Display X-Faces.
  2158. (let ((from (message-fetch-field "from"))
  2159. x-faces face)
  2160. (save-current-buffer
  2161. (when (and wash-face-p
  2162. (gnus-buffer-live-p gnus-original-article-buffer)
  2163. (not (re-search-forward "^X-Face:[\t ]*" nil t)))
  2164. ;; If type `W f', use gnus-original-article-buffer,
  2165. ;; otherwise use the current buffer because displaying
  2166. ;; RFC822 parts calls this function too.
  2167. (set-buffer gnus-original-article-buffer))
  2168. (save-restriction
  2169. (mail-narrow-to-head)
  2170. (and gnus-article-x-face-command
  2171. (or force
  2172. ;; Check whether this face is censored.
  2173. (not (and gnus-article-x-face-too-ugly
  2174. (or from
  2175. (setq from (message-fetch-field "from")))
  2176. (string-match gnus-article-x-face-too-ugly
  2177. from))))
  2178. (while (gnus-article-goto-header "X-Face")
  2179. (push (mail-header-field-value) x-faces)))))
  2180. (when x-faces
  2181. ;; We display the face.
  2182. (cond ((functionp gnus-article-x-face-command)
  2183. ;; The command is a lisp function, so we call it.
  2184. (mapc gnus-article-x-face-command x-faces))
  2185. ((stringp gnus-article-x-face-command)
  2186. ;; The command is a string, so we interpret the command
  2187. ;; as a, well, command, and fork it off.
  2188. (let ((process-connection-type nil))
  2189. (gnus-set-process-query-on-exit-flag
  2190. (start-process
  2191. "article-x-face" nil shell-file-name
  2192. shell-command-switch gnus-article-x-face-command)
  2193. nil)
  2194. ;; Sending multiple EOFs to xv doesn't work,
  2195. ;; so we only do a single external face.
  2196. (with-temp-buffer
  2197. (insert (car x-faces))
  2198. (process-send-region "article-x-face"
  2199. (point-min) (point-max)))
  2200. (process-send-eof "article-x-face")))
  2201. (t
  2202. (error "`%s' set to `%s' is not a function"
  2203. gnus-article-x-face-command
  2204. 'gnus-article-x-face-command)))))))))
  2205. (defun article-decode-mime-words ()
  2206. "Decode all MIME-encoded words in the article."
  2207. (interactive)
  2208. (gnus-with-article-buffer
  2209. (let ((inhibit-point-motion-hooks t)
  2210. (mail-parse-charset gnus-newsgroup-charset)
  2211. (mail-parse-ignored-charsets
  2212. (with-current-buffer gnus-summary-buffer
  2213. gnus-newsgroup-ignored-charsets)))
  2214. (mail-decode-encoded-word-region (point-min) (point-max)))))
  2215. (defun article-decode-charset (&optional prompt)
  2216. "Decode charset-encoded text in the article.
  2217. If PROMPT (the prefix), prompt for a coding system to use."
  2218. (interactive "P")
  2219. (let ((inhibit-point-motion-hooks t) (case-fold-search t)
  2220. (inhibit-read-only t)
  2221. (mail-parse-charset gnus-newsgroup-charset)
  2222. (mail-parse-ignored-charsets
  2223. (save-excursion (condition-case nil
  2224. (set-buffer gnus-summary-buffer)
  2225. (error))
  2226. gnus-newsgroup-ignored-charsets))
  2227. ct cte ctl charset format)
  2228. (save-excursion
  2229. (save-restriction
  2230. (article-narrow-to-head)
  2231. (setq ct (message-fetch-field "Content-Type" t)
  2232. cte (message-fetch-field "Content-Transfer-Encoding" t)
  2233. ctl (and ct (mail-header-parse-content-type ct))
  2234. charset (cond
  2235. (prompt
  2236. (mm-read-coding-system "Charset to decode: "))
  2237. (ctl
  2238. (mail-content-type-get ctl 'charset)))
  2239. format (and ctl (mail-content-type-get ctl 'format)))
  2240. (when cte
  2241. (setq cte (mail-header-strip cte)))
  2242. (if (and ctl (not (string-match "/" (car ctl))))
  2243. (setq ctl nil))
  2244. (goto-char (point-max)))
  2245. (forward-line 1)
  2246. (save-restriction
  2247. (narrow-to-region (point) (point-max))
  2248. (when (and (eq mail-parse-charset 'gnus-decoded)
  2249. (eq (mm-body-7-or-8) '8bit))
  2250. ;; The text code could have been decoded.
  2251. (setq charset mail-parse-charset))
  2252. (when (and (or (not ctl)
  2253. (equal (car ctl) "text/plain"))
  2254. (not format)) ;; article with format will decode later.
  2255. (mm-decode-body
  2256. charset (and cte (intern (downcase
  2257. (gnus-strip-whitespace cte))))
  2258. (car ctl)))))))
  2259. (defun article-decode-encoded-words ()
  2260. "Remove encoded-word encoding from headers."
  2261. (let ((inhibit-point-motion-hooks t)
  2262. (mail-parse-charset gnus-newsgroup-charset)
  2263. (mail-parse-ignored-charsets
  2264. (save-excursion (condition-case nil
  2265. (set-buffer gnus-summary-buffer)
  2266. (error))
  2267. gnus-newsgroup-ignored-charsets))
  2268. (inhibit-read-only t)
  2269. end start)
  2270. (goto-char (point-min))
  2271. (when (search-forward "\n\n" nil 'move)
  2272. (forward-line -1))
  2273. (setq end (point))
  2274. (while (not (bobp))
  2275. (while (progn
  2276. (forward-line -1)
  2277. (and (not (bobp))
  2278. (memq (char-after) '(?\t ? )))))
  2279. (setq start (point))
  2280. (if (looking-at "\
  2281. \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
  2282. \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
  2283. (funcall gnus-decode-address-function start end)
  2284. (funcall gnus-decode-header-function start end))
  2285. (goto-char (setq end start)))))
  2286. (defun article-decode-group-name ()
  2287. "Decode group names in Newsgroups, Followup-To and Xref headers."
  2288. (let ((inhibit-point-motion-hooks t)
  2289. (inhibit-read-only t)
  2290. (method (gnus-find-method-for-group gnus-newsgroup-name))
  2291. regexp)
  2292. (when (and (or gnus-group-name-charset-method-alist
  2293. gnus-group-name-charset-group-alist)
  2294. (gnus-buffer-live-p gnus-original-article-buffer))
  2295. (save-restriction
  2296. (article-narrow-to-head)
  2297. (dolist (header '("Newsgroups" "Followup-To" "Xref"))
  2298. (with-current-buffer gnus-original-article-buffer
  2299. (goto-char (point-min)))
  2300. (setq regexp (concat "^" header
  2301. ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
  2302. (while (re-search-forward regexp nil t)
  2303. (replace-match (save-match-data
  2304. (gnus-decode-newsgroups
  2305. ;; XXX how to use data in article buffer?
  2306. (with-current-buffer gnus-original-article-buffer
  2307. (re-search-forward regexp nil t)
  2308. (match-string 1))
  2309. gnus-newsgroup-name method))
  2310. t t nil 1))
  2311. (goto-char (point-min)))))))
  2312. (autoload 'idna-to-unicode "idna")
  2313. (defun article-decode-idna-rhs ()
  2314. "Decode IDNA strings in RHS in various headers in current buffer.
  2315. The following headers are decoded: From:, To:, Cc:, Reply-To:,
  2316. Mail-Reply-To: and Mail-Followup-To:."
  2317. (when gnus-use-idna
  2318. (save-restriction
  2319. (let ((inhibit-point-motion-hooks t)
  2320. (inhibit-read-only t))
  2321. (article-narrow-to-head)
  2322. (goto-char (point-min))
  2323. (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
  2324. (let (ace unicode)
  2325. (when (save-match-data
  2326. (and (setq ace (match-string 1))
  2327. (save-excursion
  2328. (and (re-search-backward "^[^ \t]" nil t)
  2329. (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
  2330. (setq unicode (idna-to-unicode ace))))
  2331. (unless (string= ace unicode)
  2332. (replace-match unicode nil nil nil 1)))))))))
  2333. (defun article-de-quoted-unreadable (&optional force read-charset)
  2334. "Translate a quoted-printable-encoded article.
  2335. If FORCE, decode the article whether it is marked as quoted-printable
  2336. or not.
  2337. If READ-CHARSET, ask for a coding system."
  2338. (interactive (list 'force current-prefix-arg))
  2339. (save-excursion
  2340. (let ((inhibit-read-only t) type charset)
  2341. (if (gnus-buffer-live-p gnus-original-article-buffer)
  2342. (with-current-buffer gnus-original-article-buffer
  2343. (setq type
  2344. (gnus-fetch-field "content-transfer-encoding"))
  2345. (let* ((ct (gnus-fetch-field "content-type"))
  2346. (ctl (and ct (mail-header-parse-content-type ct))))
  2347. (setq charset (and ctl
  2348. (mail-content-type-get ctl 'charset)))
  2349. (if (stringp charset)
  2350. (setq charset (intern (downcase charset)))))))
  2351. (if read-charset
  2352. (setq charset (mm-read-coding-system "Charset: " charset)))
  2353. (unless charset
  2354. (setq charset gnus-newsgroup-charset))
  2355. (when (or force
  2356. (and type (let ((case-fold-search t))
  2357. (string-match "quoted-printable" type))))
  2358. (article-goto-body)
  2359. (quoted-printable-decode-region
  2360. (point) (point-max) (mm-charset-to-coding-system charset))))))
  2361. (defun article-de-base64-unreadable (&optional force read-charset)
  2362. "Translate a base64 article.
  2363. If FORCE, decode the article whether it is marked as base64 not.
  2364. If READ-CHARSET, ask for a coding system."
  2365. (interactive (list 'force current-prefix-arg))
  2366. (save-excursion
  2367. (let ((inhibit-read-only t) type charset)
  2368. (if (gnus-buffer-live-p gnus-original-article-buffer)
  2369. (with-current-buffer gnus-original-article-buffer
  2370. (setq type
  2371. (gnus-fetch-field "content-transfer-encoding"))
  2372. (let* ((ct (gnus-fetch-field "content-type"))
  2373. (ctl (and ct (mail-header-parse-content-type ct))))
  2374. (setq charset (and ctl
  2375. (mail-content-type-get ctl 'charset)))
  2376. (if (stringp charset)
  2377. (setq charset (intern (downcase charset)))))))
  2378. (if read-charset
  2379. (setq charset (mm-read-coding-system "Charset: " charset)))
  2380. (unless charset
  2381. (setq charset gnus-newsgroup-charset))
  2382. (when (or force
  2383. (and type (let ((case-fold-search t))
  2384. (string-match "base64" type))))
  2385. (article-goto-body)
  2386. (save-restriction
  2387. (narrow-to-region (point) (point-max))
  2388. (base64-decode-region (point-min) (point-max))
  2389. (mm-decode-coding-region
  2390. (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
  2391. (eval-when-compile
  2392. (require 'rfc1843))
  2393. (defun article-decode-HZ ()
  2394. "Translate a HZ-encoded article."
  2395. (interactive)
  2396. (require 'rfc1843)
  2397. (save-excursion
  2398. (let ((inhibit-read-only t))
  2399. (rfc1843-decode-region (point-min) (point-max)))))
  2400. (defun article-unsplit-urls ()
  2401. "Remove the newlines that some other mailers insert into URLs."
  2402. (interactive)
  2403. (save-excursion
  2404. (let ((inhibit-read-only t))
  2405. (goto-char (point-min))
  2406. (while (re-search-forward
  2407. "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
  2408. (replace-match "\\1\\3" t)))
  2409. (when (interactive-p)
  2410. (gnus-treat-article nil))))
  2411. (defun article-wash-html (&optional read-charset)
  2412. "Format an HTML article.
  2413. If READ-CHARSET, ask for a coding system. If it is a number, the
  2414. charset defined in `gnus-summary-show-article-charset-alist' is used."
  2415. (interactive "P")
  2416. (save-excursion
  2417. (let ((inhibit-read-only t)
  2418. charset)
  2419. (if read-charset
  2420. (if (or (and (numberp read-charset)
  2421. (setq charset
  2422. (cdr
  2423. (assq read-charset
  2424. gnus-summary-show-article-charset-alist))))
  2425. (setq charset (mm-read-coding-system "Charset: ")))
  2426. (let ((gnus-summary-show-article-charset-alist
  2427. (list (cons 1 charset))))
  2428. (with-current-buffer gnus-summary-buffer
  2429. (gnus-summary-show-article 1)))
  2430. (error "No charset is given"))
  2431. (when (gnus-buffer-live-p gnus-original-article-buffer)
  2432. (with-current-buffer gnus-original-article-buffer
  2433. (let* ((ct (gnus-fetch-field "content-type"))
  2434. (ctl (and ct (mail-header-parse-content-type ct))))
  2435. (setq charset (and ctl
  2436. (mail-content-type-get ctl 'charset)))
  2437. (when (stringp charset)
  2438. (setq charset (intern (downcase charset)))))))
  2439. (unless charset
  2440. (setq charset gnus-newsgroup-charset)))
  2441. (article-goto-body)
  2442. (save-window-excursion
  2443. (save-restriction
  2444. (narrow-to-region (point) (point-max))
  2445. (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
  2446. (entry (assq func mm-text-html-washer-alist)))
  2447. (when entry
  2448. (setq func (cdr entry)))
  2449. (cond
  2450. ((functionp func)
  2451. (funcall func))
  2452. (t
  2453. (apply (car func) (cdr func))))))))))
  2454. ;; External.
  2455. (declare-function w3-region "ext:w3-display" (st nd))
  2456. (defun gnus-article-wash-html-with-w3 ()
  2457. "Wash the current buffer with w3."
  2458. (mm-setup-w3)
  2459. (let ((w3-strict-width (window-width))
  2460. (url-standalone-mode t)
  2461. (url-gateway-unplugged t)
  2462. (w3-honor-stylesheets nil))
  2463. (condition-case ()
  2464. (w3-region (point-min) (point-max))
  2465. (error))))
  2466. ;; External.
  2467. (declare-function w3m-region "ext:w3m" (start end &optional url charset))
  2468. (defun gnus-article-wash-html-with-w3m ()
  2469. "Wash the current buffer with emacs-w3m."
  2470. (mm-setup-w3m)
  2471. (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
  2472. w3m-force-redisplay)
  2473. (w3m-region (point-min) (point-max)))
  2474. ;; Put the mark meaning this part was rendered by emacs-w3m.
  2475. (put-text-property (point-min) (point-max) 'mm-inline-text-html-with-w3m t)
  2476. (when (and mm-inline-text-html-with-w3m-keymap
  2477. (boundp 'w3m-minor-mode-map)
  2478. w3m-minor-mode-map)
  2479. (if (and (boundp 'w3m-link-map)
  2480. w3m-link-map)
  2481. (let* ((start (point-min))
  2482. (end (point-max))
  2483. (on (get-text-property start 'w3m-href-anchor))
  2484. (map (copy-keymap w3m-link-map))
  2485. next)
  2486. (set-keymap-parent map w3m-minor-mode-map)
  2487. (while (< start end)
  2488. (if on
  2489. (progn
  2490. (setq next (or (text-property-any start end
  2491. 'w3m-href-anchor nil)
  2492. end))
  2493. (put-text-property start next 'keymap map))
  2494. (setq next (or (text-property-not-all start end
  2495. 'w3m-href-anchor nil)
  2496. end))
  2497. (put-text-property start next 'keymap w3m-minor-mode-map))
  2498. (setq start next
  2499. on (not on))))
  2500. (put-text-property (point-min) (point-max) 'keymap w3m-minor-mode-map))))
  2501. (defvar charset) ;; Bound by `article-wash-html'.
  2502. (defun gnus-article-wash-html-with-w3m-standalone ()
  2503. "Wash the current buffer with w3m."
  2504. (if (mm-w3m-standalone-supports-m17n-p)
  2505. (progn
  2506. (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
  2507. ;; The default.
  2508. (setq charset 'iso-8859-1))
  2509. (let ((coding-system-for-write charset)
  2510. (coding-system-for-read charset))
  2511. (call-process-region
  2512. (point-min) (point-max)
  2513. "w3m" t t nil "-dump" "-T" "text/html"
  2514. "-I" (symbol-name charset) "-O" (symbol-name charset))))
  2515. (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
  2516. (defvar gnus-article-browse-html-temp-list nil
  2517. "List of temporary files created by `gnus-article-browse-html-parts'.
  2518. Internal variable.")
  2519. (defcustom gnus-article-browse-delete-temp 'ask
  2520. "What to do with temporary files from `gnus-article-browse-html-parts'.
  2521. If nil, don't delete temporary files. If it is t, delete them on
  2522. exit from the summary buffer. If it is the symbol `file', query
  2523. on each file, if it is `ask' ask once when exiting from the
  2524. summary buffer."
  2525. :group 'gnus-article
  2526. :version "23.1" ;; No Gnus
  2527. :type '(choice (const :tag "Don't delete" nil)
  2528. (const :tag "Don't ask" t)
  2529. (const :tag "Ask" ask)
  2530. (const :tag "Ask for each file" file)))
  2531. ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
  2532. (defun gnus-article-browse-delete-temp-files (&optional how)
  2533. "Delete temp-files created by `gnus-article-browse-html-parts'."
  2534. (when (and gnus-article-browse-html-temp-list
  2535. (or how
  2536. (setq how gnus-article-browse-delete-temp)))
  2537. (when (and (eq how 'ask)
  2538. (gnus-y-or-n-p (format
  2539. "Delete all %s temporary HTML file(s)? "
  2540. (length gnus-article-browse-html-temp-list)))
  2541. (setq how t)))
  2542. (dolist (file gnus-article-browse-html-temp-list)
  2543. (when (and (file-exists-p file)
  2544. (or (eq how t)
  2545. ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
  2546. (gnus-y-or-n-p
  2547. (format "Delete temporary HTML file `%s'? " file))))
  2548. (delete-file file)))
  2549. ;; Also remove file from the list when not deleted or if file doesn't
  2550. ;; exist anymore.
  2551. (setq gnus-article-browse-html-temp-list nil))
  2552. gnus-article-browse-html-temp-list)
  2553. (defun gnus-article-browse-html-parts (list &optional header)
  2554. "View all \"text/html\" parts from LIST.
  2555. Recurse into multiparts. The optional HEADER that should be a decoded
  2556. message header will be added to the bodies of the \"text/html\" parts."
  2557. ;; Internal function used by `gnus-article-browse-html-article'.
  2558. (let (type file charset tmp-file showed)
  2559. ;; Find and show the html-parts.
  2560. (dolist (handle list)
  2561. ;; If HTML, show it:
  2562. (cond ((not (listp handle)))
  2563. ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
  2564. (and (equal (car type) "message/external-body")
  2565. (or header
  2566. (setq file (or (mail-content-type-get type 'name)
  2567. (mail-content-type-get
  2568. (mm-handle-disposition handle)
  2569. 'filename))))
  2570. (or (mm-handle-cache handle)
  2571. (condition-case code
  2572. (progn (mm-extern-cache-contents handle) t)
  2573. (error
  2574. (gnus-message 3 "%s" (error-message-string code))
  2575. (when (>= gnus-verbose 3) (sit-for 2))
  2576. nil)))
  2577. (progn
  2578. (setq handle (mm-handle-cache handle)
  2579. type (mm-handle-type handle))
  2580. (equal (car type) "text/html"))))
  2581. (when (or (setq charset (mail-content-type-get type 'charset))
  2582. header
  2583. (not file))
  2584. (setq tmp-file (mm-make-temp-file
  2585. ;; Do we need to care for 8.3 filenames?
  2586. "mm-" nil ".html")))
  2587. ;; Add a meta html tag to specify charset and a header.
  2588. (cond
  2589. (header
  2590. (let (title eheader body hcharset coding)
  2591. (with-temp-buffer
  2592. (mm-enable-multibyte)
  2593. (setq case-fold-search t)
  2594. (insert header "\n")
  2595. (setq title (message-fetch-field "subject"))
  2596. (goto-char (point-min))
  2597. (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
  2598. (replace-match (cond ((match-beginning 1) "&lt;")
  2599. ((match-beginning 2) "&gt;")
  2600. (t "&amp;"))))
  2601. (goto-char (point-min))
  2602. (insert "<pre>\n")
  2603. (goto-char (point-max))
  2604. (insert "</pre>\n<hr>\n")
  2605. ;; We have to examine charset one by one since
  2606. ;; charset specified in parts might be different.
  2607. (if (eq charset 'gnus-decoded)
  2608. (setq charset 'utf-8
  2609. eheader (mm-encode-coding-string (buffer-string)
  2610. charset)
  2611. title (when title
  2612. (mm-encode-coding-string title charset))
  2613. body (mm-encode-coding-string (mm-get-part handle)
  2614. charset))
  2615. (setq hcharset (mm-find-mime-charset-region (point-min)
  2616. (point-max)))
  2617. (cond ((= (length hcharset) 1)
  2618. (setq hcharset (car hcharset)
  2619. coding (mm-charset-to-coding-system
  2620. hcharset)))
  2621. ((> (length hcharset) 1)
  2622. (setq hcharset 'utf-8
  2623. coding hcharset)))
  2624. (if coding
  2625. (if charset
  2626. (progn
  2627. (setq body
  2628. (mm-charset-to-coding-system charset))
  2629. (if (eq coding body)
  2630. (setq eheader (mm-encode-coding-string
  2631. (buffer-string) coding)
  2632. title (when title
  2633. (mm-encode-coding-string
  2634. title coding))
  2635. body (mm-get-part handle))
  2636. (setq charset 'utf-8
  2637. eheader (mm-encode-coding-string
  2638. (buffer-string) charset)
  2639. title (when title
  2640. (mm-encode-coding-string
  2641. title charset))
  2642. body (mm-encode-coding-string
  2643. (mm-decode-coding-string
  2644. (mm-get-part handle) body)
  2645. charset))))
  2646. (setq charset hcharset
  2647. eheader (mm-encode-coding-string
  2648. (buffer-string) coding)
  2649. title (when title
  2650. (mm-encode-coding-string
  2651. title coding))
  2652. body (mm-get-part handle)))
  2653. (setq eheader (mm-string-as-unibyte (buffer-string))
  2654. body (mm-get-part handle))))
  2655. (erase-buffer)
  2656. (mm-disable-multibyte)
  2657. (insert body)
  2658. (when charset
  2659. (mm-add-meta-html-tag handle charset))
  2660. (when title
  2661. (goto-char (point-min))
  2662. (unless (search-forward "<title>" nil t)
  2663. (re-search-forward "<head>\\s-*" nil t)
  2664. (insert "<title>" title "</title>\n")))
  2665. (goto-char (point-min))
  2666. (or (re-search-forward
  2667. "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
  2668. (re-search-forward
  2669. "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
  2670. (insert eheader)
  2671. (mm-write-region (point-min) (point-max)
  2672. tmp-file nil nil nil 'binary t))))
  2673. (charset
  2674. (mm-with-unibyte-buffer
  2675. (insert (if (eq charset 'gnus-decoded)
  2676. (mm-encode-coding-string
  2677. (mm-get-part handle)
  2678. (setq charset 'utf-8))
  2679. (mm-get-part handle)))
  2680. (if (or (mm-add-meta-html-tag handle charset)
  2681. (not file))
  2682. (mm-write-region (point-min) (point-max)
  2683. tmp-file nil nil nil 'binary t)
  2684. (setq tmp-file nil))))
  2685. (tmp-file
  2686. (mm-save-part-to-file handle tmp-file)))
  2687. (when tmp-file
  2688. (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
  2689. (add-hook 'gnus-summary-prepare-exit-hook
  2690. 'gnus-article-browse-delete-temp-files)
  2691. (add-hook 'gnus-exit-gnus-hook
  2692. (lambda ()
  2693. (gnus-article-browse-delete-temp-files t)))
  2694. ;; FIXME: Warn if there's an <img> tag?
  2695. (browse-url-of-file (or tmp-file (expand-file-name file)))
  2696. (setq showed t))
  2697. ;; If multipart, recurse
  2698. ((equal (mm-handle-media-supertype handle) "multipart")
  2699. (when (gnus-article-browse-html-parts handle header)
  2700. (setq showed t)))
  2701. ((equal (mm-handle-media-type handle) "message/rfc822")
  2702. (mm-with-multibyte-buffer
  2703. (mm-insert-part handle)
  2704. (setq handle (mm-dissect-buffer t t))
  2705. (when (and (bufferp (car handle))
  2706. (stringp (car (mm-handle-type handle))))
  2707. (setq handle (list handle)))
  2708. (when header
  2709. (article-decode-encoded-words)
  2710. (let ((gnus-visible-headers
  2711. (or (get 'gnus-visible-headers 'standard-value)
  2712. gnus-visible-headers)))
  2713. (article-hide-headers))
  2714. (goto-char (point-min))
  2715. (search-forward "\n\n" nil 'move)
  2716. (skip-chars-backward "\t\n ")
  2717. (setq header (buffer-substring (point-min) (point)))))
  2718. (when (prog1
  2719. (gnus-article-browse-html-parts handle header)
  2720. (mm-destroy-parts handle))
  2721. (setq showed t)))))
  2722. showed))
  2723. (defun gnus-article-browse-html-article (&optional arg)
  2724. "View \"text/html\" parts of the current article with a WWW browser.
  2725. The message header is added to the beginning of every html part unless
  2726. the prefix argument ARG is given.
  2727. Warning: Spammers use links to images in HTML articles to verify
  2728. whether you have read the message. As
  2729. `gnus-article-browse-html-article' passes the HTML content to the
  2730. browser without eliminating these \"web bugs\" you should only
  2731. use it for mails from trusted senders.
  2732. If you always want to display HTML parts in the browser, set
  2733. `mm-text-html-renderer' to nil."
  2734. ;; Cf. `mm-w3m-safe-url-regexp'
  2735. (interactive "P")
  2736. (if arg
  2737. (gnus-summary-show-article)
  2738. (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
  2739. gnus-visible-headers))
  2740. ;; As we insert a <hr>, there's no need for the body boundary.
  2741. (gnus-treat-body-boundary nil))
  2742. (gnus-summary-show-article)))
  2743. (with-current-buffer gnus-article-buffer
  2744. (let ((header (unless arg
  2745. (save-restriction
  2746. (widen)
  2747. (buffer-substring-no-properties
  2748. (goto-char (point-min))
  2749. (if (search-forward "\n\n" nil t)
  2750. (match-beginning 0)
  2751. (goto-char (point-max))
  2752. (skip-chars-backward "\t\n ")
  2753. (point))))))
  2754. parts)
  2755. (set-buffer gnus-original-article-buffer)
  2756. (setq parts (mm-dissect-buffer t t))
  2757. ;; If singlepart, enforce a list.
  2758. (when (and (bufferp (car parts))
  2759. (stringp (car (mm-handle-type parts))))
  2760. (setq parts (list parts)))
  2761. ;; Process the list
  2762. (unless (gnus-article-browse-html-parts parts header)
  2763. (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
  2764. (mm-destroy-parts parts)
  2765. (unless arg
  2766. (gnus-summary-show-article)))))
  2767. (defun article-hide-list-identifiers ()
  2768. "Remove list identifies from the Subject header.
  2769. The `gnus-list-identifiers' variable specifies what to do."
  2770. (interactive)
  2771. (let ((inhibit-point-motion-hooks t)
  2772. (regexp (if (consp gnus-list-identifiers)
  2773. (mapconcat 'identity gnus-list-identifiers " *\\|")
  2774. gnus-list-identifiers))
  2775. (inhibit-read-only t))
  2776. (when regexp
  2777. (save-excursion
  2778. (save-restriction
  2779. (article-narrow-to-head)
  2780. (goto-char (point-min))
  2781. (while (re-search-forward
  2782. (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
  2783. nil t)
  2784. (delete-region (match-beginning 2) (match-end 0))
  2785. (beginning-of-line))
  2786. (when (re-search-forward
  2787. "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
  2788. (delete-region (match-beginning 1) (match-end 1))))))))
  2789. (defun article-hide-pem (&optional arg)
  2790. "Toggle hiding of any PEM headers and signatures in the current article.
  2791. If given a negative prefix, always show; if given a positive prefix,
  2792. always hide."
  2793. (interactive (gnus-article-hidden-arg))
  2794. (unless (gnus-article-check-hidden-text 'pem arg)
  2795. (save-excursion
  2796. (let ((inhibit-read-only t) end)
  2797. (goto-char (point-min))
  2798. ;; Hide the horrendously ugly "header".
  2799. (when (and (search-forward
  2800. "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
  2801. nil t)
  2802. (setq end (1+ (match-beginning 0))))
  2803. (gnus-add-wash-type 'pem)
  2804. (gnus-article-hide-text-type
  2805. end
  2806. (if (search-forward "\n\n" nil t)
  2807. (match-end 0)
  2808. (point-max))
  2809. 'pem)
  2810. ;; Hide the trailer as well
  2811. (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
  2812. nil t)
  2813. (gnus-article-hide-text-type
  2814. (match-beginning 0) (match-end 0) 'pem)))))))
  2815. (defun article-strip-banner ()
  2816. "Strip the banners specified by the `banner' group parameter and by
  2817. `gnus-article-address-banner-alist'."
  2818. (interactive)
  2819. (save-excursion
  2820. (save-restriction
  2821. (let ((inhibit-point-motion-hooks t))
  2822. (when (gnus-parameter-banner gnus-newsgroup-name)
  2823. (article-really-strip-banner
  2824. (gnus-parameter-banner gnus-newsgroup-name)))
  2825. (when gnus-article-address-banner-alist
  2826. ;; Note that the From header is decoded here, so it is
  2827. ;; required that the *-extract-address-components function
  2828. ;; supports non-ASCII text.
  2829. (let ((from (save-restriction
  2830. (widen)
  2831. (article-narrow-to-head)
  2832. (mail-fetch-field "from"))))
  2833. (when (and from
  2834. (setq from
  2835. (cadr (funcall gnus-extract-address-components
  2836. from))))
  2837. (catch 'found
  2838. (dolist (pair gnus-article-address-banner-alist)
  2839. (when (string-match (car pair) from)
  2840. (throw 'found
  2841. (article-really-strip-banner (cdr pair)))))))))))))
  2842. (defun article-really-strip-banner (banner)
  2843. "Strip the banner specified by the argument."
  2844. (save-excursion
  2845. (save-restriction
  2846. (let ((inhibit-point-motion-hooks t)
  2847. (gnus-signature-limit nil)
  2848. (inhibit-read-only t))
  2849. (article-goto-body)
  2850. (cond
  2851. ((eq banner 'signature)
  2852. (when (gnus-article-narrow-to-signature)
  2853. (widen)
  2854. (forward-line -1)
  2855. (delete-region (point) (point-max))))
  2856. ((symbolp banner)
  2857. (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
  2858. (while (re-search-forward banner nil t)
  2859. (delete-region (match-beginning 0) (match-end 0)))))
  2860. ((stringp banner)
  2861. (while (re-search-forward banner nil t)
  2862. (delete-region (match-beginning 0) (match-end 0)))))))))
  2863. (defun article-babel ()
  2864. "Translate article using an online translation service."
  2865. (interactive)
  2866. (require 'babel)
  2867. (gnus-with-article-buffer
  2868. (when (article-goto-body)
  2869. (let* ((start (point))
  2870. (end (point-max))
  2871. (orig (buffer-substring start end))
  2872. (trans (babel-as-string orig)))
  2873. (save-restriction
  2874. (narrow-to-region start end)
  2875. (delete-region start end)
  2876. (insert trans))))))
  2877. (defun article-hide-signature (&optional arg)
  2878. "Hide the signature in the current article.
  2879. If given a negative prefix, always show; if given a positive prefix,
  2880. always hide."
  2881. (interactive (gnus-article-hidden-arg))
  2882. (unless (gnus-article-check-hidden-text 'signature arg)
  2883. (save-excursion
  2884. (save-restriction
  2885. (let ((inhibit-read-only t))
  2886. (when (gnus-article-narrow-to-signature)
  2887. (gnus-article-hide-text-type
  2888. (point-min) (point-max) 'signature))))))
  2889. (gnus-set-mode-line 'article))
  2890. (defun article-strip-headers-in-body ()
  2891. "Strip offensive headers from bodies."
  2892. (interactive)
  2893. (save-excursion
  2894. (article-goto-body)
  2895. (let ((case-fold-search t))
  2896. (when (looking-at "x-no-archive:")
  2897. (gnus-delete-line)))))
  2898. (defun article-strip-leading-blank-lines ()
  2899. "Remove all blank lines from the beginning of the article."
  2900. (interactive)
  2901. (save-excursion
  2902. (let ((inhibit-point-motion-hooks t)
  2903. (inhibit-read-only t))
  2904. (when (article-goto-body)
  2905. (while (and (not (eobp))
  2906. (looking-at "[ \t]*$"))
  2907. (gnus-delete-line))))))
  2908. (defun article-narrow-to-head ()
  2909. "Narrow the buffer to the head of the message.
  2910. Point is left at the beginning of the narrowed-to region."
  2911. (narrow-to-region
  2912. (goto-char (point-min))
  2913. (if (search-forward "\n\n" nil 1)
  2914. (1- (point))
  2915. (point-max)))
  2916. (goto-char (point-min)))
  2917. (defun article-goto-body ()
  2918. "Place point at the start of the body."
  2919. (goto-char (point-min))
  2920. (cond
  2921. ;; This variable is only bound when dealing with separate
  2922. ;; MIME body parts.
  2923. (article-goto-body-goes-to-point-min-p
  2924. t)
  2925. ((search-forward "\n\n" nil t)
  2926. t)
  2927. (t
  2928. (goto-char (point-max))
  2929. nil)))
  2930. (defun article-strip-multiple-blank-lines ()
  2931. "Replace consecutive blank lines with one empty line."
  2932. (interactive)
  2933. (save-excursion
  2934. (let ((inhibit-point-motion-hooks t)
  2935. (inhibit-read-only t))
  2936. ;; First make all blank lines empty.
  2937. (article-goto-body)
  2938. (while (re-search-forward "^[ \t]+$" nil t)
  2939. (unless (gnus-annotation-in-region-p
  2940. (match-beginning 0) (match-end 0))
  2941. (replace-match "" nil t)))
  2942. ;; Then replace multiple empty lines with a single empty line.
  2943. (article-goto-body)
  2944. (while (re-search-forward "\n\n\\(\n+\\)" nil t)
  2945. (unless (gnus-annotation-in-region-p
  2946. (match-beginning 0) (match-end 0))
  2947. (delete-region (match-beginning 1) (match-end 1)))))))
  2948. (defun article-strip-leading-space ()
  2949. "Remove all white space from the beginning of the lines in the article."
  2950. (interactive)
  2951. (save-excursion
  2952. (let ((inhibit-point-motion-hooks t)
  2953. (inhibit-read-only t))
  2954. (article-goto-body)
  2955. (while (re-search-forward "^[ \t]+" nil t)
  2956. (replace-match "" t t)))))
  2957. (defun article-strip-trailing-space ()
  2958. "Remove all white space from the end of the lines in the article."
  2959. (interactive)
  2960. (save-excursion
  2961. (let ((inhibit-point-motion-hooks t)
  2962. (inhibit-read-only t))
  2963. (article-goto-body)
  2964. (while (re-search-forward "[ \t]+$" nil t)
  2965. (replace-match "" t t)))))
  2966. (defun article-strip-blank-lines ()
  2967. "Strip leading, trailing and multiple blank lines."
  2968. (interactive)
  2969. (article-strip-leading-blank-lines)
  2970. (article-remove-trailing-blank-lines)
  2971. (article-strip-multiple-blank-lines))
  2972. (defun article-strip-all-blank-lines ()
  2973. "Strip all blank lines."
  2974. (interactive)
  2975. (save-excursion
  2976. (let ((inhibit-point-motion-hooks t)
  2977. (inhibit-read-only t))
  2978. (article-goto-body)
  2979. (while (re-search-forward "^[ \t]*\n" nil t)
  2980. (replace-match "" t t)))))
  2981. (defun gnus-article-narrow-to-signature ()
  2982. "Narrow to the signature; return t if a signature is found, else nil."
  2983. (let ((inhibit-point-motion-hooks t))
  2984. (when (gnus-article-search-signature)
  2985. (forward-line 1)
  2986. ;; Check whether we have some limits to what we consider
  2987. ;; to be a signature.
  2988. (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
  2989. (list gnus-signature-limit)))
  2990. limit limited)
  2991. (while (setq limit (pop limits))
  2992. (if (or (and (integerp limit)
  2993. (< (- (point-max) (point)) limit))
  2994. (and (floatp limit)
  2995. (< (count-lines (point) (point-max)) limit))
  2996. (and (functionp limit)
  2997. (funcall limit))
  2998. (and (stringp limit)
  2999. (not (re-search-forward limit nil t))))
  3000. () ; This limit did not succeed.
  3001. (setq limited t
  3002. limits nil)))
  3003. (unless limited
  3004. (narrow-to-region (point) (point-max))
  3005. t)))))
  3006. (defun gnus-article-search-signature ()
  3007. "Search the current buffer for the signature separator.
  3008. Put point at the beginning of the signature separator."
  3009. (let ((cur (point)))
  3010. (goto-char (point-max))
  3011. (if (if (stringp gnus-signature-separator)
  3012. (re-search-backward gnus-signature-separator nil t)
  3013. (let ((seps gnus-signature-separator))
  3014. (while (and seps
  3015. (not (re-search-backward (car seps) nil t)))
  3016. (pop seps))
  3017. seps))
  3018. t
  3019. (goto-char cur)
  3020. nil)))
  3021. (defun gnus-article-hidden-arg ()
  3022. "Return the current prefix arg as a number, or 0 if no prefix."
  3023. (list (if current-prefix-arg
  3024. (prefix-numeric-value current-prefix-arg)
  3025. 0)))
  3026. (defun gnus-article-check-hidden-text (type arg)
  3027. "Return nil if hiding is necessary.
  3028. Arg can be nil or a number. nil and positive means hide, negative
  3029. means show, 0 means toggle."
  3030. (save-excursion
  3031. (save-restriction
  3032. (let ((hide (gnus-article-hidden-text-p type)))
  3033. (cond
  3034. ((or (null arg)
  3035. (> arg 0))
  3036. nil)
  3037. ((< arg 0)
  3038. (gnus-article-show-hidden-text type)
  3039. t)
  3040. (t
  3041. (if (eq hide 'hidden)
  3042. (progn
  3043. (gnus-article-show-hidden-text type)
  3044. t)
  3045. nil)))))))
  3046. (defun gnus-article-hidden-text-p (type)
  3047. "Say whether the current buffer contains hidden text of type TYPE."
  3048. (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
  3049. (while (and pos
  3050. (not (get-text-property pos 'invisible))
  3051. (not (get-text-property pos 'dummy-invisible)))
  3052. (setq pos
  3053. (text-property-any (1+ pos) (point-max) 'article-type type)))
  3054. (if pos
  3055. 'hidden
  3056. nil)))
  3057. (defun gnus-article-show-hidden-text (type &optional dummy)
  3058. "Show all hidden text of type TYPE.
  3059. Originally it is hide instead of DUMMY."
  3060. (let ((inhibit-read-only t)
  3061. (inhibit-point-motion-hooks t))
  3062. (gnus-remove-text-properties-when
  3063. 'article-type type
  3064. (point-min) (point-max)
  3065. (cons 'article-type (cons type
  3066. gnus-hidden-properties)))
  3067. (gnus-delete-wash-type type)))
  3068. (defconst article-time-units
  3069. `((year . ,(* 365.25 24 60 60))
  3070. (week . ,(* 7 24 60 60))
  3071. (day . ,(* 24 60 60))
  3072. (hour . ,(* 60 60))
  3073. (minute . 60)
  3074. (second . 1))
  3075. "Mapping from time units to seconds.")
  3076. (defun gnus-article-forward-header ()
  3077. "Move point to the start of the next header.
  3078. If the current header is a continuation header, this can be several
  3079. lines forward."
  3080. (let ((ended nil))
  3081. (while (not ended)
  3082. (forward-line 1)
  3083. (if (looking-at "[ \t]+[^ \t]")
  3084. (forward-line 1)
  3085. (setq ended t)))))
  3086. (defun article-date-ut (&optional type highlight)
  3087. "Convert DATE date to universal time in the current article.
  3088. If TYPE is `local', convert to local time; if it is `lapsed', output
  3089. how much time has lapsed since DATE. For `lapsed', the value of
  3090. `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
  3091. should replace the \"Date:\" one, or should be added below it."
  3092. (interactive (list 'ut t))
  3093. (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
  3094. (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
  3095. tdate-regexp)
  3096. ((eq type 'lapsed)
  3097. "^X-Sent:[ \t]")
  3098. (article-lapsed-timer
  3099. "^Date:[ \t]")
  3100. (t
  3101. tdate-regexp)))
  3102. (case-fold-search t)
  3103. (inhibit-read-only t)
  3104. (inhibit-point-motion-hooks t)
  3105. pos date bface eface)
  3106. (save-excursion
  3107. (save-restriction
  3108. (widen)
  3109. (goto-char (point-min))
  3110. (while (or (setq date (get-text-property (setq pos (point))
  3111. 'original-date))
  3112. (when (setq pos (next-single-property-change
  3113. (point) 'original-date))
  3114. (setq date (get-text-property pos 'original-date))
  3115. t))
  3116. (narrow-to-region
  3117. pos (if (setq pos (text-property-any pos (point-max)
  3118. 'original-date nil))
  3119. (progn
  3120. (goto-char pos)
  3121. (if (or (bolp) (eobp))
  3122. (point)
  3123. (1+ (point))))
  3124. (point-max)))
  3125. (goto-char (point-min))
  3126. (when (re-search-forward tdate-regexp nil t)
  3127. (setq bface (get-text-property (point-at-bol) 'face)
  3128. eface (get-text-property (1- (point-at-eol)) 'face)))
  3129. (goto-char (point-min))
  3130. (setq pos nil)
  3131. ;; Delete any old Date headers.
  3132. (while (re-search-forward date-regexp nil t)
  3133. (if pos
  3134. (delete-region (point-at-bol) (progn
  3135. (gnus-article-forward-header)
  3136. (point)))
  3137. (delete-region (point-at-bol) (progn
  3138. (gnus-article-forward-header)
  3139. (forward-char -1)
  3140. (point)))
  3141. (setq pos (point))))
  3142. (when (and (not pos)
  3143. (re-search-forward tdate-regexp nil t))
  3144. (forward-line 1))
  3145. (gnus-goto-char pos)
  3146. (insert (article-make-date-line date (or type 'ut)))
  3147. (unless pos
  3148. (insert "\n")
  3149. (forward-line -1))
  3150. ;; Do highlighting.
  3151. (beginning-of-line)
  3152. (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
  3153. (put-text-property (match-beginning 1) (1+ (match-end 1))
  3154. 'face bface)
  3155. (put-text-property (match-beginning 2) (match-end 2)
  3156. 'face eface))
  3157. (put-text-property (point-min) (1- (point-max)) 'original-date date)
  3158. (goto-char (point-max))
  3159. (widen))))))
  3160. (defun article-make-date-line (date type)
  3161. "Return a DATE line of TYPE."
  3162. (unless (memq type '(local ut original user iso8601 lapsed english))
  3163. (error "Unknown conversion type: %s" type))
  3164. (condition-case ()
  3165. (let ((time (date-to-time date)))
  3166. (cond
  3167. ;; Convert to the local timezone.
  3168. ((eq type 'local)
  3169. (concat "Date: " (message-make-date time)))
  3170. ;; Convert to Universal Time.
  3171. ((eq type 'ut)
  3172. (concat "Date: "
  3173. (substring
  3174. (message-make-date
  3175. (let* ((e (parse-time-string date))
  3176. (tm (apply 'encode-time e))
  3177. (ms (car tm))
  3178. (ls (- (cadr tm) (car (current-time-zone time)))))
  3179. (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
  3180. ((> ls 65535) (list (1+ ms) (- ls 65536)))
  3181. (t (list ms ls)))))
  3182. 0 -5)
  3183. "UT"))
  3184. ;; Get the original date from the article.
  3185. ((eq type 'original)
  3186. (concat "Date: " (if (string-match "\n+$" date)
  3187. (substring date 0 (match-beginning 0))
  3188. date)))
  3189. ;; Let the user define the format.
  3190. ((eq type 'user)
  3191. (let ((format (or (condition-case nil
  3192. (with-current-buffer gnus-summary-buffer
  3193. gnus-article-time-format)
  3194. (error nil))
  3195. gnus-article-time-format)))
  3196. (if (functionp format)
  3197. (funcall format time)
  3198. (concat "Date: " (format-time-string format time)))))
  3199. ;; ISO 8601.
  3200. ((eq type 'iso8601)
  3201. (let ((tz (car (current-time-zone time))))
  3202. (concat
  3203. "Date: "
  3204. (format-time-string "%Y%m%dT%H%M%S" time)
  3205. (format "%s%02d%02d"
  3206. (if (> tz 0) "+" "-") (/ (abs tz) 3600)
  3207. (/ (% (abs tz) 3600) 60)))))
  3208. ;; Do an X-Sent lapsed format.
  3209. ((eq type 'lapsed)
  3210. ;; If the date is seriously mangled, the timezone functions are
  3211. ;; liable to bug out, so we ignore all errors.
  3212. (let* ((now (current-time))
  3213. (real-time (subtract-time now time))
  3214. (real-sec (and real-time
  3215. (+ (* (float (car real-time)) 65536)
  3216. (cadr real-time))))
  3217. (sec (and real-time (abs real-sec)))
  3218. num prev)
  3219. (cond
  3220. ((null real-time)
  3221. "X-Sent: Unknown")
  3222. ((zerop sec)
  3223. "X-Sent: Now")
  3224. (t
  3225. (concat
  3226. "X-Sent: "
  3227. ;; This is a bit convoluted, but basically we go
  3228. ;; through the time units for years, weeks, etc,
  3229. ;; and divide things to see whether that results
  3230. ;; in positive answers.
  3231. (mapconcat
  3232. (lambda (unit)
  3233. (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
  3234. ;; The (remaining) seconds are too few to
  3235. ;; be divided into this time unit.
  3236. ""
  3237. ;; It's big enough, so we output it.
  3238. (setq sec (- sec (* num (cdr unit))))
  3239. (prog1
  3240. (concat (if prev ", " "") (int-to-string
  3241. (floor num))
  3242. " " (symbol-name (car unit))
  3243. (if (> num 1) "s" ""))
  3244. (setq prev t))))
  3245. article-time-units "")
  3246. ;; If dates are odd, then it might appear like the
  3247. ;; article was sent in the future.
  3248. (if (> real-sec 0)
  3249. " ago"
  3250. " in the future"))))))
  3251. ;; Display the date in proper English
  3252. ((eq type 'english)
  3253. (let ((dtime (decode-time time)))
  3254. (concat
  3255. "Date: the "
  3256. (number-to-string (nth 3 dtime))
  3257. (let ((digit (% (nth 3 dtime) 10)))
  3258. (cond
  3259. ((memq (nth 3 dtime) '(11 12 13)) "th")
  3260. ((= digit 1) "st")
  3261. ((= digit 2) "nd")
  3262. ((= digit 3) "rd")
  3263. (t "th")))
  3264. " of "
  3265. (nth (1- (nth 4 dtime)) gnus-english-month-names)
  3266. " "
  3267. (number-to-string (nth 5 dtime))
  3268. " at "
  3269. (format "%02d" (nth 2 dtime))
  3270. ":"
  3271. (format "%02d" (nth 1 dtime)))))))
  3272. (error
  3273. (format "Date: %s (from Gnus)" date))))
  3274. (defun article-date-local (&optional highlight)
  3275. "Convert the current article date to the local timezone."
  3276. (interactive (list t))
  3277. (article-date-ut 'local highlight))
  3278. (defun article-date-english (&optional highlight)
  3279. "Convert the current article date to something that is proper English."
  3280. (interactive (list t))
  3281. (article-date-ut 'english highlight))
  3282. (defun article-date-original (&optional highlight)
  3283. "Convert the current article date to what it was originally.
  3284. This is only useful if you have used some other date conversion
  3285. function and want to see what the date was before converting."
  3286. (interactive (list t))
  3287. (article-date-ut 'original highlight))
  3288. (defun article-date-lapsed (&optional highlight)
  3289. "Convert the current article date to time lapsed since it was sent."
  3290. (interactive (list t))
  3291. (article-date-ut 'lapsed highlight))
  3292. (defun article-update-date-lapsed ()
  3293. "Function to be run from a timer to update the lapsed time line."
  3294. (save-match-data
  3295. (let (deactivate-mark)
  3296. (save-excursion
  3297. (ignore-errors
  3298. (walk-windows
  3299. (lambda (w)
  3300. (set-buffer (window-buffer w))
  3301. (when (eq major-mode 'gnus-article-mode)
  3302. (let ((mark (point-marker)))
  3303. (goto-char (point-min))
  3304. (when (re-search-forward "^X-Sent:" nil t)
  3305. (article-date-lapsed t))
  3306. (goto-char (marker-position mark))
  3307. (move-marker mark nil))))
  3308. nil 'visible))))))
  3309. (defun gnus-start-date-timer (&optional n)
  3310. "Start a timer to update the X-Sent header in the article buffers.
  3311. The numerical prefix says how frequently (in seconds) the function
  3312. is to run."
  3313. (interactive "p")
  3314. (unless n
  3315. (setq n 1))
  3316. (gnus-stop-date-timer)
  3317. (setq article-lapsed-timer
  3318. (run-at-time 1 n 'article-update-date-lapsed)))
  3319. (defun gnus-stop-date-timer ()
  3320. "Stop the X-Sent timer."
  3321. (interactive)
  3322. (when article-lapsed-timer
  3323. (nnheader-cancel-timer article-lapsed-timer)
  3324. (setq article-lapsed-timer nil)))
  3325. (defun article-date-user (&optional highlight)
  3326. "Convert the current article date to the user-defined format.
  3327. This format is defined by the `gnus-article-time-format' variable."
  3328. (interactive (list t))
  3329. (article-date-ut 'user highlight))
  3330. (defun article-date-iso8601 (&optional highlight)
  3331. "Convert the current article date to ISO8601."
  3332. (interactive (list t))
  3333. (article-date-ut 'iso8601 highlight))
  3334. (defmacro gnus-article-save-original-date (&rest forms)
  3335. "Save the original date as a text property and evaluate FORMS."
  3336. `(let* ((case-fold-search t)
  3337. (start (progn
  3338. (goto-char (point-min))
  3339. (when (and (re-search-forward "^date:[\t\n ]+" nil t)
  3340. (not (bolp)))
  3341. (match-end 0))))
  3342. (date (when (and start
  3343. (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
  3344. nil t))
  3345. (buffer-substring-no-properties start
  3346. (match-beginning 0)))))
  3347. (goto-char (point-max))
  3348. (skip-chars-backward "\n")
  3349. (put-text-property (point-min) (point) 'original-date date)
  3350. ,@forms
  3351. (goto-char (point-max))
  3352. (skip-chars-backward "\n")
  3353. (put-text-property (point-min) (point) 'original-date date)))
  3354. ;; (defun article-show-all ()
  3355. ;; "Show all hidden text in the article buffer."
  3356. ;; (interactive)
  3357. ;; (save-excursion
  3358. ;; (let ((inhibit-read-only t))
  3359. ;; (gnus-article-unhide-text (point-min) (point-max)))))
  3360. (defun article-remove-leading-whitespace ()
  3361. "Remove excessive whitespace from all headers."
  3362. (interactive)
  3363. (save-excursion
  3364. (save-restriction
  3365. (let ((inhibit-read-only t))
  3366. (article-narrow-to-head)
  3367. (goto-char (point-min))
  3368. (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
  3369. (delete-region (match-beginning 1) (match-end 1)))))))
  3370. (defun article-emphasize (&optional arg)
  3371. "Emphasize text according to `gnus-emphasis-alist'."
  3372. (interactive (gnus-article-hidden-arg))
  3373. (unless (gnus-article-check-hidden-text 'emphasis arg)
  3374. (save-excursion
  3375. (let ((alist (or
  3376. (condition-case nil
  3377. (with-current-buffer gnus-summary-buffer
  3378. gnus-article-emphasis-alist)
  3379. (error))
  3380. gnus-emphasis-alist))
  3381. (inhibit-read-only t)
  3382. (props (append '(article-type emphasis)
  3383. gnus-hidden-properties))
  3384. regexp elem beg invisible visible face)
  3385. (article-goto-body)
  3386. (setq beg (point))
  3387. (while (setq elem (pop alist))
  3388. (goto-char beg)
  3389. (setq regexp (car elem)
  3390. invisible (nth 1 elem)
  3391. visible (nth 2 elem)
  3392. face (nth 3 elem))
  3393. (while (re-search-forward regexp nil t)
  3394. (when (and (match-beginning visible) (match-beginning invisible))
  3395. (gnus-article-hide-text
  3396. (match-beginning invisible) (match-end invisible) props)
  3397. (gnus-article-unhide-text-type
  3398. (match-beginning visible) (match-end visible) 'emphasis)
  3399. (gnus-put-overlay-excluding-newlines
  3400. (match-beginning visible) (match-end visible) 'face face)
  3401. (gnus-add-wash-type 'emphasis)
  3402. (goto-char (match-end invisible)))))))))
  3403. (defun gnus-article-setup-highlight-words (&optional highlight-words)
  3404. "Setup newsgroup emphasis alist."
  3405. (unless gnus-article-emphasis-alist
  3406. (let ((name (and gnus-newsgroup-name
  3407. (gnus-group-real-name gnus-newsgroup-name))))
  3408. (make-local-variable 'gnus-article-emphasis-alist)
  3409. (setq gnus-article-emphasis-alist
  3410. (nconc
  3411. (let ((alist gnus-group-highlight-words-alist) elem highlight)
  3412. (while (setq elem (pop alist))
  3413. (when (and name (string-match (car elem) name))
  3414. (setq alist nil
  3415. highlight (copy-sequence (cdr elem)))))
  3416. highlight)
  3417. (copy-sequence highlight-words)
  3418. (if gnus-newsgroup-name
  3419. (copy-sequence (gnus-group-find-parameter
  3420. gnus-newsgroup-name 'highlight-words t)))
  3421. gnus-emphasis-alist)))))
  3422. (defvar gnus-summary-article-menu)
  3423. (defvar gnus-summary-post-menu)
  3424. ;;; Saving functions.
  3425. (defun gnus-article-save (save-buffer file &optional num)
  3426. "Save the currently selected article."
  3427. (when (or (get gnus-default-article-saver :headers)
  3428. (not gnus-save-all-headers))
  3429. ;; Remove headers according to `gnus-saved-headers' or the value
  3430. ;; of the `:headers' property that the saver function might have.
  3431. (let ((gnus-visible-headers
  3432. (or (symbol-value (get gnus-default-article-saver :headers))
  3433. gnus-saved-headers gnus-visible-headers))
  3434. ;; Ignore group parameter. See `article-hide-headers'.
  3435. (gnus-summary-buffer nil))
  3436. (with-current-buffer save-buffer
  3437. (article-hide-headers 1 t))))
  3438. (save-window-excursion
  3439. (if (not gnus-default-article-saver)
  3440. (error "No default saver is defined")
  3441. ;; !!! Magic! The saving functions all save
  3442. ;; `gnus-save-article-buffer' (or so they think), but we
  3443. ;; bind that variable to our save-buffer.
  3444. (set-buffer gnus-article-buffer)
  3445. (let* ((gnus-save-article-buffer save-buffer)
  3446. (filename
  3447. (cond
  3448. ((not gnus-prompt-before-saving) 'default)
  3449. ((eq gnus-prompt-before-saving 'always) nil)
  3450. (t file)))
  3451. (gnus-number-of-articles-to-be-saved
  3452. (when (eq gnus-prompt-before-saving t)
  3453. num))) ; Magic
  3454. (set-buffer gnus-article-current-summary)
  3455. (funcall gnus-default-article-saver filename)))))
  3456. (defun gnus-read-save-file-name (prompt &optional filename
  3457. function group headers variable
  3458. dir-var)
  3459. (let ((default-name
  3460. (funcall function group headers (symbol-value variable)))
  3461. result)
  3462. (setq result
  3463. (expand-file-name
  3464. (cond
  3465. ((eq filename 'default)
  3466. default-name)
  3467. ((eq filename t)
  3468. default-name)
  3469. (filename filename)
  3470. (t
  3471. (when (symbol-value dir-var)
  3472. (setq default-name (expand-file-name
  3473. (file-name-nondirectory default-name)
  3474. (symbol-value dir-var))))
  3475. (let* ((split-name (gnus-get-split-value gnus-split-methods))
  3476. (prompt
  3477. (format prompt
  3478. (if (and gnus-number-of-articles-to-be-saved
  3479. (> gnus-number-of-articles-to-be-saved 1))
  3480. (format "these %d articles"
  3481. gnus-number-of-articles-to-be-saved)
  3482. "this article")))
  3483. (file
  3484. ;; Let the split methods have their say.
  3485. (cond
  3486. ;; No split name was found.
  3487. ((null split-name)
  3488. (read-file-name
  3489. (concat prompt " (default "
  3490. (file-name-nondirectory default-name) "): ")
  3491. (file-name-directory default-name)
  3492. default-name))
  3493. ;; A single group name is returned.
  3494. ((stringp split-name)
  3495. (setq default-name
  3496. (funcall function split-name headers
  3497. (symbol-value variable)))
  3498. (read-file-name
  3499. (concat prompt " (default "
  3500. (file-name-nondirectory default-name) "): ")
  3501. (file-name-directory default-name)
  3502. default-name))
  3503. ;; A single split name was found
  3504. ((= 1 (length split-name))
  3505. (let* ((name (expand-file-name
  3506. (car split-name)
  3507. gnus-article-save-directory))
  3508. (dir (cond ((file-directory-p name)
  3509. (file-name-as-directory name))
  3510. ((file-exists-p name) name)
  3511. (t gnus-article-save-directory))))
  3512. (read-file-name
  3513. (concat prompt " (default " name "): ")
  3514. dir name)))
  3515. ;; A list of splits was found.
  3516. (t
  3517. (setq split-name (nreverse split-name))
  3518. (let (result)
  3519. (let ((file-name-history
  3520. (nconc split-name file-name-history)))
  3521. (setq result
  3522. (expand-file-name
  3523. (read-file-name
  3524. (concat prompt " (`M-p' for defaults): ")
  3525. gnus-article-save-directory
  3526. (car split-name))
  3527. gnus-article-save-directory)))
  3528. (car (push result file-name-history)))))))
  3529. ;; Create the directory.
  3530. (gnus-make-directory (file-name-directory file))
  3531. ;; If we have read a directory, we append the default file name.
  3532. (when (file-directory-p file)
  3533. (setq file (expand-file-name (file-name-nondirectory
  3534. default-name)
  3535. (file-name-as-directory file))))
  3536. ;; Possibly translate some characters.
  3537. (nnheader-translate-file-chars file))))))
  3538. (gnus-make-directory (file-name-directory result))
  3539. (when variable
  3540. (set variable result))
  3541. (when dir-var
  3542. (set dir-var (file-name-directory result)))
  3543. result))
  3544. (defun gnus-article-archive-name (group)
  3545. "Return the first instance of an \"Archive-name\" in the current buffer."
  3546. (let ((case-fold-search t))
  3547. (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
  3548. (nnheader-concat gnus-article-save-directory
  3549. (match-string 1)))))
  3550. (defun gnus-article-nndoc-name (group)
  3551. "If GROUP is an nndoc group, return the name of the parent group."
  3552. (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
  3553. (gnus-group-get-parameter group 'save-article-group)))
  3554. (defun gnus-summary-save-in-rmail (&optional filename)
  3555. "Append this article to Rmail file.
  3556. Optional argument FILENAME specifies file name.
  3557. Directory to save to is default to `gnus-article-save-directory'."
  3558. (setq filename (gnus-read-save-file-name
  3559. "Save %s in rmail file" filename
  3560. gnus-rmail-save-name gnus-newsgroup-name
  3561. gnus-current-headers 'gnus-newsgroup-last-rmail))
  3562. (gnus-eval-in-buffer-window gnus-save-article-buffer
  3563. (save-excursion
  3564. (save-restriction
  3565. (widen)
  3566. ;; Note that unlike gnus-summary-save-in-mail, there is no
  3567. ;; check to see if filename is Babyl. Rmail in Emacs 23 does
  3568. ;; not use Babyl.
  3569. (gnus-output-to-rmail filename))))
  3570. filename)
  3571. (defun gnus-summary-save-in-mail (&optional filename)
  3572. "Append this article to Unix mail file.
  3573. Optional argument FILENAME specifies file name.
  3574. Directory to save to is default to `gnus-article-save-directory'."
  3575. (setq filename (gnus-read-save-file-name
  3576. "Save %s in Unix mail file" filename
  3577. gnus-mail-save-name gnus-newsgroup-name
  3578. gnus-current-headers 'gnus-newsgroup-last-mail))
  3579. (gnus-eval-in-buffer-window gnus-save-article-buffer
  3580. (save-excursion
  3581. (save-restriction
  3582. (widen)
  3583. (if (and (file-readable-p filename)
  3584. (file-regular-p filename)
  3585. (mail-file-babyl-p filename))
  3586. (gnus-output-to-rmail filename)
  3587. (gnus-output-to-mail filename)))))
  3588. filename)
  3589. (put 'gnus-summary-save-in-file :decode t)
  3590. (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
  3591. (defun gnus-summary-save-in-file (&optional filename overwrite)
  3592. "Append this article to file.
  3593. Optional argument FILENAME specifies file name.
  3594. Directory to save to is default to `gnus-article-save-directory'."
  3595. (setq filename (gnus-read-save-file-name
  3596. "Save %s in file" filename
  3597. gnus-file-save-name gnus-newsgroup-name
  3598. gnus-current-headers 'gnus-newsgroup-last-file))
  3599. (gnus-eval-in-buffer-window gnus-save-article-buffer
  3600. (save-excursion
  3601. (save-restriction
  3602. (widen)
  3603. (when (and overwrite
  3604. (file-exists-p filename))
  3605. (delete-file filename))
  3606. (gnus-output-to-file filename))))
  3607. filename)
  3608. (put 'gnus-summary-write-to-file :decode t)
  3609. (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
  3610. (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
  3611. (defun gnus-summary-write-to-file (&optional filename)
  3612. "Write this article to a file, overwriting it if the file exists.
  3613. Optional argument FILENAME specifies file name.
  3614. The directory to save in defaults to `gnus-article-save-directory'."
  3615. (setq filename (gnus-read-save-file-name
  3616. "Save %s in file" filename
  3617. gnus-file-save-name gnus-newsgroup-name
  3618. gnus-current-headers nil 'gnus-newsgroup-last-directory))
  3619. (gnus-summary-save-in-file filename t))
  3620. (put 'gnus-summary-save-body-in-file :decode t)
  3621. (defun gnus-summary-save-body-in-file (&optional filename overwrite)
  3622. "Append this article body to a file.
  3623. Optional argument FILENAME specifies file name.
  3624. The directory to save in defaults to `gnus-article-save-directory'."
  3625. (setq filename (gnus-read-save-file-name
  3626. "Save %s body in file" filename
  3627. gnus-file-save-name gnus-newsgroup-name
  3628. gnus-current-headers 'gnus-newsgroup-last-file))
  3629. (gnus-eval-in-buffer-window gnus-save-article-buffer
  3630. (save-excursion
  3631. (save-restriction
  3632. (widen)
  3633. (when (article-goto-body)
  3634. (narrow-to-region (point) (point-max)))
  3635. (when (and overwrite
  3636. (file-exists-p filename))
  3637. (delete-file filename))
  3638. (gnus-output-to-file filename))))
  3639. filename)
  3640. (put 'gnus-summary-write-body-to-file :decode t)
  3641. (put 'gnus-summary-write-body-to-file
  3642. :function 'gnus-summary-save-body-in-file)
  3643. (defun gnus-summary-write-body-to-file (&optional filename)
  3644. "Write this article body to a file, overwriting it if the file exists.
  3645. Optional argument FILENAME specifies file name.
  3646. The directory to save in defaults to `gnus-article-save-directory'."
  3647. (setq filename (gnus-read-save-file-name
  3648. "Save %s body in file" filename
  3649. gnus-file-save-name gnus-newsgroup-name
  3650. gnus-current-headers nil 'gnus-newsgroup-last-directory))
  3651. (gnus-summary-save-body-in-file filename t))
  3652. (put 'gnus-summary-save-in-pipe :decode t)
  3653. (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
  3654. (defun gnus-summary-save-in-pipe (&optional command raw)
  3655. "Pipe this article to subprocess COMMAND.
  3656. Valid values for COMMAND include:
  3657. a string
  3658. The executable command name and possibly arguments.
  3659. nil
  3660. You will be prompted for the command in the minibuffer.
  3661. the symbol `default'
  3662. It will be replaced with the command which the variable
  3663. `gnus-summary-pipe-output-default-command' holds or the command
  3664. last used for saving.
  3665. Non-nil value for RAW overrides `:decode' and `:headers' properties
  3666. and the raw article including all headers will be piped."
  3667. (let ((article (gnus-summary-article-number))
  3668. (decode (unless raw
  3669. (get 'gnus-summary-save-in-pipe :decode)))
  3670. save-buffer default)
  3671. (if article
  3672. (if (vectorp (gnus-summary-article-header article))
  3673. (save-current-buffer
  3674. (gnus-summary-select-article decode decode nil article)
  3675. (insert-buffer-substring
  3676. (prog1
  3677. (if decode
  3678. gnus-article-buffer
  3679. gnus-original-article-buffer)
  3680. (setq save-buffer
  3681. (nnheader-set-temp-buffer " *Gnus Save*"))))
  3682. ;; Remove unwanted headers.
  3683. (when (and (not raw)
  3684. (or (get 'gnus-summary-save-in-pipe :headers)
  3685. (not gnus-save-all-headers)))
  3686. (let ((gnus-visible-headers
  3687. (or (symbol-value (get 'gnus-summary-save-in-pipe
  3688. :headers))
  3689. gnus-saved-headers gnus-visible-headers))
  3690. (gnus-summary-buffer nil))
  3691. (article-hide-headers 1 t))))
  3692. (error "%d is not a real article" article))
  3693. (error "No article to pipe"))
  3694. (setq default (or gnus-summary-pipe-output-default-command
  3695. gnus-last-shell-command))
  3696. (unless (stringp command)
  3697. (setq command
  3698. (if (and (eq command 'default) default)
  3699. default
  3700. (gnus-read-shell-command "Shell command on this article: "
  3701. default))))
  3702. (when (string-equal command "")
  3703. (if default
  3704. (setq command default)
  3705. (error "A command is required")))
  3706. (gnus-eval-in-buffer-window save-buffer
  3707. (save-restriction
  3708. (widen)
  3709. (shell-command-on-region (point-min) (point-max) command nil)))
  3710. (gnus-kill-buffer save-buffer))
  3711. (setq gnus-summary-pipe-output-default-command command))
  3712. (defun gnus-summary-pipe-to-muttprint (&optional command)
  3713. "Pipe this article to muttprint."
  3714. (unless (stringp command)
  3715. (setq command (read-string
  3716. "Print using command: " gnus-summary-muttprint-program
  3717. nil gnus-summary-muttprint-program)))
  3718. (let ((gnus-summary-pipe-output-default-command
  3719. gnus-summary-pipe-output-default-command))
  3720. (gnus-summary-save-in-pipe command))
  3721. (setq gnus-summary-muttprint-program command))
  3722. ;;; Article file names when saving.
  3723. (defun gnus-capitalize-newsgroup (newsgroup)
  3724. "Capitalize NEWSGROUP name."
  3725. (when (not (zerop (length newsgroup)))
  3726. (concat (char-to-string (upcase (aref newsgroup 0)))
  3727. (substring newsgroup 1))))
  3728. (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
  3729. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3730. If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
  3731. Otherwise, it is like ~/News/news/group/num."
  3732. (let ((default
  3733. (expand-file-name
  3734. (concat (if (gnus-use-long-file-name 'not-save)
  3735. (gnus-capitalize-newsgroup newsgroup)
  3736. (gnus-newsgroup-directory-form newsgroup))
  3737. "/" (int-to-string (mail-header-number headers)))
  3738. gnus-article-save-directory)))
  3739. (if (and last-file
  3740. (string-equal (file-name-directory default)
  3741. (file-name-directory last-file))
  3742. (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  3743. default
  3744. (or last-file default))))
  3745. (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
  3746. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3747. If variable `gnus-use-long-file-name' is non-nil, it is
  3748. ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
  3749. (let ((default
  3750. (expand-file-name
  3751. (concat (if (gnus-use-long-file-name 'not-save)
  3752. newsgroup
  3753. (gnus-newsgroup-directory-form newsgroup))
  3754. "/" (int-to-string (mail-header-number headers)))
  3755. gnus-article-save-directory)))
  3756. (if (and last-file
  3757. (string-equal (file-name-directory default)
  3758. (file-name-directory last-file))
  3759. (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  3760. default
  3761. (or last-file default))))
  3762. (defun gnus-plain-save-name (newsgroup headers &optional last-file)
  3763. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3764. If variable `gnus-use-long-file-name' is non-nil, it is
  3765. ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
  3766. (or last-file
  3767. (expand-file-name
  3768. (if (gnus-use-long-file-name 'not-save)
  3769. newsgroup
  3770. (file-relative-name
  3771. (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
  3772. default-directory))
  3773. gnus-article-save-directory)))
  3774. (defun gnus-sender-save-name (newsgroup headers &optional last-file)
  3775. "Generate file name from sender."
  3776. (let ((from (mail-header-from headers)))
  3777. (expand-file-name
  3778. (if (and from (string-match "\\([^ <]+\\)@" from))
  3779. (match-string 1 from)
  3780. "nobody")
  3781. gnus-article-save-directory)))
  3782. (defun article-verify-x-pgp-sig ()
  3783. "Verify X-PGP-Sig."
  3784. ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
  3785. (interactive)
  3786. (if (gnus-buffer-live-p gnus-original-article-buffer)
  3787. (let ((sig (with-current-buffer gnus-original-article-buffer
  3788. (gnus-fetch-field "X-PGP-Sig")))
  3789. items info headers)
  3790. (when (and sig
  3791. mml2015-use
  3792. (mml2015-clear-verify-function))
  3793. (with-temp-buffer
  3794. (insert-buffer-substring gnus-original-article-buffer)
  3795. (setq items (split-string sig))
  3796. (message-narrow-to-head)
  3797. (let ((inhibit-point-motion-hooks t)
  3798. (case-fold-search t))
  3799. ;; Don't verify multiple headers.
  3800. (setq headers (mapconcat (lambda (header)
  3801. (concat header ": "
  3802. (mail-fetch-field header)
  3803. "\n"))
  3804. (split-string (nth 1 items) ",") "")))
  3805. (delete-region (point-min) (point-max))
  3806. (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
  3807. (insert "X-Signed-Headers: " (nth 1 items) "\n")
  3808. (insert headers)
  3809. (widen)
  3810. (forward-line)
  3811. (while (not (eobp))
  3812. (if (looking-at "^-")
  3813. (insert "- "))
  3814. (forward-line))
  3815. (insert "\n-----BEGIN PGP SIGNATURE-----\n")
  3816. (insert "Version: " (car items) "\n\n")
  3817. (insert (mapconcat 'identity (cddr items) "\n"))
  3818. (insert "\n-----END PGP SIGNATURE-----\n")
  3819. (let ((mm-security-handle (list (format "multipart/signed"))))
  3820. (mml2015-clean-buffer)
  3821. (let ((coding-system-for-write (or gnus-newsgroup-charset
  3822. 'iso-8859-1)))
  3823. (funcall (mml2015-clear-verify-function)))
  3824. (setq info
  3825. (or (mm-handle-multipart-ctl-parameter
  3826. mm-security-handle 'gnus-details)
  3827. (mm-handle-multipart-ctl-parameter
  3828. mm-security-handle 'gnus-info)))))
  3829. (when info
  3830. (let ((inhibit-read-only t) bface eface)
  3831. (save-restriction
  3832. (message-narrow-to-head)
  3833. (goto-char (point-max))
  3834. (forward-line -1)
  3835. (setq bface (get-text-property (point-at-bol) 'face)
  3836. eface (get-text-property (1- (point-at-eol)) 'face))
  3837. (message-remove-header "X-Gnus-PGP-Verify")
  3838. (if (re-search-forward "^X-PGP-Sig:" nil t)
  3839. (forward-line)
  3840. (goto-char (point-max)))
  3841. (narrow-to-region (point) (point))
  3842. (insert "X-Gnus-PGP-Verify: " info "\n")
  3843. (goto-char (point-min))
  3844. (forward-line)
  3845. (while (not (eobp))
  3846. (if (not (looking-at "^[ \t]"))
  3847. (insert " "))
  3848. (forward-line))
  3849. ;; Do highlighting.
  3850. (goto-char (point-min))
  3851. (when (looking-at "\\([^:]+\\): *")
  3852. (put-text-property (match-beginning 1) (1+ (match-end 1))
  3853. 'face bface)
  3854. (put-text-property (match-end 0) (point-max)
  3855. 'face eface)))))))))
  3856. (defun article-verify-cancel-lock ()
  3857. "Verify Cancel-Lock header."
  3858. (interactive)
  3859. (if (gnus-buffer-live-p gnus-original-article-buffer)
  3860. (canlock-verify gnus-original-article-buffer)))
  3861. (eval-and-compile
  3862. (mapc
  3863. (lambda (func)
  3864. (let (afunc gfunc)
  3865. (if (consp func)
  3866. (setq afunc (car func)
  3867. gfunc (cdr func))
  3868. (setq afunc func
  3869. gfunc (intern (format "gnus-%s" func))))
  3870. (defalias gfunc
  3871. (when (fboundp afunc)
  3872. `(lambda (&optional interactive &rest args)
  3873. ,(documentation afunc t)
  3874. (interactive (list t))
  3875. (with-current-buffer gnus-article-buffer
  3876. (if interactive
  3877. (call-interactively ',afunc)
  3878. (apply ',afunc args))))))))
  3879. '(article-hide-headers
  3880. article-verify-x-pgp-sig
  3881. article-verify-cancel-lock
  3882. article-hide-boring-headers
  3883. article-treat-overstrike
  3884. article-treat-ansi-sequences
  3885. article-fill-long-lines
  3886. article-capitalize-sentences
  3887. article-remove-cr
  3888. article-remove-leading-whitespace
  3889. article-display-x-face
  3890. article-display-face
  3891. article-de-quoted-unreadable
  3892. article-de-base64-unreadable
  3893. article-decode-HZ
  3894. article-wash-html
  3895. article-unsplit-urls
  3896. article-hide-list-identifiers
  3897. article-strip-banner
  3898. article-babel
  3899. article-hide-pem
  3900. article-hide-signature
  3901. article-strip-headers-in-body
  3902. article-remove-trailing-blank-lines
  3903. article-strip-leading-blank-lines
  3904. article-strip-multiple-blank-lines
  3905. article-strip-leading-space
  3906. article-strip-trailing-space
  3907. article-strip-blank-lines
  3908. article-strip-all-blank-lines
  3909. article-date-local
  3910. article-date-english
  3911. article-date-iso8601
  3912. article-date-original
  3913. article-date-ut
  3914. article-decode-mime-words
  3915. article-decode-charset
  3916. article-decode-encoded-words
  3917. article-date-user
  3918. article-date-lapsed
  3919. article-emphasize
  3920. article-treat-dumbquotes
  3921. article-normalize-headers
  3922. ;;(article-show-all . gnus-article-show-all-headers)
  3923. )))
  3924. ;;;
  3925. ;;; Gnus article mode
  3926. ;;;
  3927. (put 'gnus-article-mode 'mode-class 'special)
  3928. (set-keymap-parent gnus-article-mode-map widget-keymap)
  3929. (gnus-define-keys gnus-article-mode-map
  3930. " " gnus-article-goto-next-page
  3931. "\177" gnus-article-goto-prev-page
  3932. [delete] gnus-article-goto-prev-page
  3933. [backspace] gnus-article-goto-prev-page
  3934. "\C-c^" gnus-article-refer-article
  3935. "h" gnus-article-show-summary
  3936. "s" gnus-article-show-summary
  3937. "\C-c\C-m" gnus-article-mail
  3938. "?" gnus-article-describe-briefly
  3939. "<" beginning-of-buffer
  3940. ">" end-of-buffer
  3941. "\C-c\C-i" gnus-info-find-node
  3942. "\C-c\C-b" gnus-bug
  3943. "R" gnus-article-reply-with-original
  3944. "F" gnus-article-followup-with-original
  3945. "\C-hk" gnus-article-describe-key
  3946. "\C-hc" gnus-article-describe-key-briefly
  3947. "\C-hb" gnus-article-describe-bindings
  3948. "e" gnus-article-read-summary-keys
  3949. "\C-d" gnus-article-read-summary-keys
  3950. "\M-*" gnus-article-read-summary-keys
  3951. "\M-#" gnus-article-read-summary-keys
  3952. "\M-^" gnus-article-read-summary-keys
  3953. "\M-g" gnus-article-read-summary-keys)
  3954. (substitute-key-definition
  3955. 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
  3956. (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
  3957. "W" gnus-article-wide-reply-with-original)
  3958. (if (featurep 'xemacs)
  3959. (set-keymap-default-binding gnus-article-send-map
  3960. 'gnus-article-read-summary-send-keys)
  3961. (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
  3962. (defun gnus-article-make-menu-bar ()
  3963. (unless (boundp 'gnus-article-commands-menu)
  3964. (gnus-summary-make-menu-bar))
  3965. (gnus-turn-off-edit-menu 'article)
  3966. (unless (boundp 'gnus-article-article-menu)
  3967. (easy-menu-define
  3968. gnus-article-article-menu gnus-article-mode-map ""
  3969. '("Article"
  3970. ["Scroll forwards" gnus-article-goto-next-page t]
  3971. ["Scroll backwards" gnus-article-goto-prev-page t]
  3972. ["Show summary" gnus-article-show-summary t]
  3973. ["Fetch Message-ID at point" gnus-article-refer-article t]
  3974. ["Mail to address at point" gnus-article-mail t]
  3975. ["Send a bug report" gnus-bug t]))
  3976. (easy-menu-define
  3977. gnus-article-treatment-menu gnus-article-mode-map ""
  3978. ;; Fixme: this should use :active (and maybe :visible).
  3979. '("Treatment"
  3980. ["Hide headers" gnus-article-hide-headers t]
  3981. ["Hide signature" gnus-article-hide-signature t]
  3982. ["Hide citation" gnus-article-hide-citation t]
  3983. ["Treat overstrike" gnus-article-treat-overstrike t]
  3984. ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
  3985. ["Remove carriage return" gnus-article-remove-cr t]
  3986. ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
  3987. ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
  3988. ["Remove base64" gnus-article-de-base64-unreadable t]
  3989. ["Treat html" gnus-article-wash-html t]
  3990. ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
  3991. ["Decode HZ" gnus-article-decode-HZ t]))
  3992. ;; Note "Commands" menu is defined in gnus-sum.el for consistency
  3993. ;; Note "Post" menu is defined in gnus-sum.el for consistency
  3994. (gnus-run-hooks 'gnus-article-menu-hook)))
  3995. (defun gnus-article-mode ()
  3996. "Major mode for displaying an article.
  3997. All normal editing commands are switched off.
  3998. The following commands are available in addition to all summary mode
  3999. commands:
  4000. \\<gnus-article-mode-map>
  4001. \\[gnus-article-next-page]\t Scroll the article one page forwards
  4002. \\[gnus-article-prev-page]\t Scroll the article one page backwards
  4003. \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
  4004. \\[gnus-article-show-summary]\t Display the summary buffer
  4005. \\[gnus-article-mail]\t Send a reply to the address near point
  4006. \\[gnus-article-describe-briefly]\t Describe the current mode briefly
  4007. \\[gnus-info-find-node]\t Go to the Gnus info node"
  4008. (interactive)
  4009. (kill-all-local-variables)
  4010. (gnus-simplify-mode-line)
  4011. (setq mode-name "Article")
  4012. (setq major-mode 'gnus-article-mode)
  4013. (make-local-variable 'minor-mode-alist)
  4014. (use-local-map gnus-article-mode-map)
  4015. (when (gnus-visual-p 'article-menu 'menu)
  4016. (gnus-article-make-menu-bar)
  4017. (when gnus-summary-tool-bar-map
  4018. (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
  4019. (gnus-update-format-specifications nil 'article-mode)
  4020. (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
  4021. (set (make-local-variable 'gnus-page-broken) nil)
  4022. (make-local-variable 'gnus-button-marker-list)
  4023. (make-local-variable 'gnus-article-current-summary)
  4024. (make-local-variable 'gnus-article-mime-handles)
  4025. (make-local-variable 'gnus-article-decoded-p)
  4026. (make-local-variable 'gnus-article-mime-handle-alist)
  4027. (make-local-variable 'gnus-article-wash-types)
  4028. (make-local-variable 'gnus-article-image-alist)
  4029. (make-local-variable 'gnus-article-charset)
  4030. (make-local-variable 'gnus-article-ignored-charsets)
  4031. ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
  4032. ;; face.
  4033. (set (make-local-variable 'nobreak-char-display) nil)
  4034. (setq cursor-in-non-selected-windows nil)
  4035. (setq truncate-lines gnus-article-truncate-lines)
  4036. (gnus-set-default-directory)
  4037. (buffer-disable-undo)
  4038. (setq buffer-read-only t
  4039. show-trailing-whitespace nil)
  4040. (set-syntax-table gnus-article-mode-syntax-table)
  4041. (mm-enable-multibyte)
  4042. (gnus-run-mode-hooks 'gnus-article-mode-hook))
  4043. (defvar gnus-button-marker-list nil
  4044. "Regexp matching any of the regexps from `gnus-button-alist'.
  4045. Internal variable.")
  4046. (defun gnus-article-setup-buffer ()
  4047. "Initialize the article buffer."
  4048. (let* ((name (if gnus-single-article-buffer "*Article*"
  4049. (concat "*Article " gnus-newsgroup-name "*")))
  4050. (original
  4051. (progn (string-match "\\*Article" name)
  4052. (concat " *Original Article"
  4053. (substring name (match-end 0))))))
  4054. (setq gnus-article-buffer name)
  4055. (setq gnus-original-article-buffer original)
  4056. (setq gnus-article-mime-handle-alist nil)
  4057. (with-current-buffer gnus-summary-buffer
  4058. ;; This might be a variable local to the summary buffer.
  4059. (unless gnus-single-article-buffer
  4060. (setq gnus-article-buffer name)
  4061. (setq gnus-original-article-buffer original)
  4062. (gnus-set-global-variables)))
  4063. (gnus-article-setup-highlight-words)
  4064. ;; Init original article buffer.
  4065. (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
  4066. (mm-enable-multibyte)
  4067. (setq major-mode 'gnus-original-article-mode)
  4068. (make-local-variable 'gnus-original-article))
  4069. (if (and (get-buffer name)
  4070. (with-current-buffer name
  4071. (if gnus-article-edit-mode
  4072. (if (y-or-n-p "Article mode edit in progress; discard? ")
  4073. (progn
  4074. (set-buffer-modified-p nil)
  4075. (gnus-kill-buffer name)
  4076. (message "")
  4077. nil)
  4078. (error "Action aborted"))
  4079. t)))
  4080. (with-current-buffer name
  4081. (set (make-local-variable 'gnus-article-edit-mode) nil)
  4082. (when gnus-article-mime-handles
  4083. (mm-destroy-parts gnus-article-mime-handles)
  4084. (setq gnus-article-mime-handles nil))
  4085. ;; Set it to nil in article-buffer!
  4086. (setq gnus-article-mime-handle-alist nil)
  4087. (buffer-disable-undo)
  4088. (setq buffer-read-only t)
  4089. ;; This list just keeps growing if we don't reset it.
  4090. (setq gnus-button-marker-list nil)
  4091. (unless (eq major-mode 'gnus-article-mode)
  4092. (gnus-article-mode))
  4093. (current-buffer))
  4094. (with-current-buffer (gnus-get-buffer-create name)
  4095. (gnus-article-mode)
  4096. (make-local-variable 'gnus-summary-buffer)
  4097. (setq gnus-summary-buffer
  4098. (gnus-summary-buffer-name gnus-newsgroup-name))
  4099. (gnus-summary-set-local-parameters gnus-newsgroup-name)
  4100. (current-buffer)))))
  4101. ;; Set article window start at LINE, where LINE is the number of lines
  4102. ;; from the head of the article.
  4103. (defun gnus-article-set-window-start (&optional line)
  4104. (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
  4105. (when article-window
  4106. (set-window-start
  4107. article-window
  4108. (with-current-buffer gnus-article-buffer
  4109. (goto-char (point-min))
  4110. (if (not line)
  4111. (point-min)
  4112. (gnus-message 6 "Moved to bookmark")
  4113. (search-forward "\n\n" nil t)
  4114. (forward-line line)
  4115. (point)))))))
  4116. (defun gnus-article-prepare (article &optional all-headers header)
  4117. "Prepare ARTICLE in article mode buffer.
  4118. ARTICLE should either be an article number or a Message-ID.
  4119. If ARTICLE is an id, HEADER should be the article headers.
  4120. If ALL-HEADERS is non-nil, no headers are hidden."
  4121. (save-excursion
  4122. ;; Make sure we start in a summary buffer.
  4123. (unless (eq major-mode 'gnus-summary-mode)
  4124. (set-buffer gnus-summary-buffer))
  4125. (setq gnus-summary-buffer (current-buffer))
  4126. (let* ((gnus-article (if header (mail-header-number header) article))
  4127. (summary-buffer (current-buffer))
  4128. (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
  4129. (group gnus-newsgroup-name)
  4130. result)
  4131. (save-excursion
  4132. (gnus-article-setup-buffer)
  4133. (set-buffer gnus-article-buffer)
  4134. ;; Deactivate active regions.
  4135. (when (and (boundp 'transient-mark-mode)
  4136. transient-mark-mode)
  4137. (setq mark-active nil))
  4138. (if (not (setq result (let ((inhibit-read-only t))
  4139. (gnus-request-article-this-buffer
  4140. article group))))
  4141. ;; There is no such article.
  4142. (save-excursion
  4143. (when (and (numberp article)
  4144. (not (memq article gnus-newsgroup-sparse)))
  4145. (setq gnus-article-current
  4146. (cons gnus-newsgroup-name article))
  4147. (set-buffer gnus-summary-buffer)
  4148. (setq gnus-current-article article)
  4149. (if (and (memq article gnus-newsgroup-undownloaded)
  4150. (not (gnus-online (gnus-find-method-for-group
  4151. gnus-newsgroup-name))))
  4152. (progn
  4153. (gnus-summary-set-agent-mark article)
  4154. (message "Message marked for downloading"))
  4155. (gnus-summary-mark-article article gnus-canceled-mark)
  4156. (unless (memq article gnus-newsgroup-sparse)
  4157. (gnus-error 1 "No such article (may have expired or been canceled)")))))
  4158. (if (or (eq result 'pseudo)
  4159. (eq result 'nneething))
  4160. (progn
  4161. (with-current-buffer summary-buffer
  4162. (push article gnus-newsgroup-history)
  4163. (setq gnus-last-article gnus-current-article
  4164. gnus-current-article 0
  4165. gnus-current-headers nil
  4166. gnus-article-current nil)
  4167. (if (eq result 'nneething)
  4168. (gnus-configure-windows 'summary)
  4169. (gnus-configure-windows 'article))
  4170. (gnus-set-global-variables))
  4171. (let ((gnus-article-mime-handle-alist-1
  4172. gnus-article-mime-handle-alist))
  4173. (gnus-set-mode-line 'article)))
  4174. ;; The result from the `request' was an actual article -
  4175. ;; or at least some text that is now displayed in the
  4176. ;; article buffer.
  4177. (when (and (numberp article)
  4178. (not (eq article gnus-current-article)))
  4179. ;; Seems like a new article has been selected.
  4180. ;; `gnus-current-article' must be an article number.
  4181. (with-current-buffer summary-buffer
  4182. (push article gnus-newsgroup-history)
  4183. (setq gnus-last-article gnus-current-article
  4184. gnus-current-article article
  4185. gnus-current-headers
  4186. (gnus-summary-article-header gnus-current-article)
  4187. gnus-article-current
  4188. (cons gnus-newsgroup-name gnus-current-article))
  4189. (unless (vectorp gnus-current-headers)
  4190. (setq gnus-current-headers nil))
  4191. (gnus-summary-goto-subject gnus-current-article)
  4192. (when (gnus-summary-show-thread)
  4193. ;; If the summary buffer really was folded, the
  4194. ;; previous goto may not actually have gone to
  4195. ;; the right article, but the thread root instead.
  4196. ;; So we go again.
  4197. (gnus-summary-goto-subject gnus-current-article))
  4198. (gnus-run-hooks 'gnus-mark-article-hook)
  4199. (gnus-set-mode-line 'summary)
  4200. (when (gnus-visual-p 'article-highlight 'highlight)
  4201. (gnus-run-hooks 'gnus-visual-mark-article-hook))
  4202. ;; Set the global newsgroup variables here.
  4203. (gnus-set-global-variables)
  4204. (setq gnus-have-all-headers
  4205. (or all-headers gnus-show-all-headers))))
  4206. (save-excursion
  4207. (gnus-configure-windows 'article))
  4208. (when (or (numberp article)
  4209. (stringp article))
  4210. (gnus-article-prepare-display)
  4211. ;; Do page break.
  4212. (goto-char (point-min))
  4213. (when gnus-break-pages
  4214. (gnus-narrow-to-page)))
  4215. (let ((gnus-article-mime-handle-alist-1
  4216. gnus-article-mime-handle-alist))
  4217. (gnus-set-mode-line 'article))
  4218. (article-goto-body)
  4219. (unless (bobp)
  4220. (forward-line -1))
  4221. (set-window-point (get-buffer-window (current-buffer)) (point))
  4222. (gnus-configure-windows 'article)
  4223. t))))))
  4224. ;;;###autoload
  4225. (defun gnus-article-prepare-display ()
  4226. "Make the current buffer look like a nice article."
  4227. ;; Hooks for getting information from the article.
  4228. ;; This hook must be called before being narrowed.
  4229. (let ((gnus-article-buffer (current-buffer))
  4230. buffer-read-only
  4231. (inhibit-read-only t))
  4232. (unless (eq major-mode 'gnus-article-mode)
  4233. (gnus-article-mode))
  4234. (setq buffer-read-only nil
  4235. gnus-article-wash-types nil
  4236. gnus-article-image-alist nil)
  4237. (gnus-run-hooks 'gnus-tmp-internal-hook)
  4238. (when gnus-display-mime-function
  4239. (funcall gnus-display-mime-function))
  4240. (gnus-run-hooks 'gnus-article-prepare-hook)))
  4241. ;;;
  4242. ;;; Gnus Sticky Article Mode
  4243. ;;;
  4244. (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
  4245. "Mode for sticky articles."
  4246. ;; Release bindings that won't work.
  4247. (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
  4248. gnus-sticky-article-mode-map)
  4249. (substitute-key-definition 'gnus-article-refer-article 'undefined
  4250. gnus-sticky-article-mode-map)
  4251. (dolist (k '("e" "h" "s" "F" "R"))
  4252. (define-key gnus-sticky-article-mode-map k nil))
  4253. (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
  4254. (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
  4255. (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
  4256. (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
  4257. (defun gnus-sticky-article (arg)
  4258. "Make the current article sticky.
  4259. If a prefix ARG is given, ask for a name for this sticky article buffer."
  4260. (interactive "P")
  4261. (gnus-summary-show-thread)
  4262. (gnus-summary-select-article nil nil 'pseudo)
  4263. (let (new-art-buf-name)
  4264. (gnus-eval-in-buffer-window gnus-article-buffer
  4265. (setq new-art-buf-name
  4266. (concat
  4267. "*Sticky Article: "
  4268. (if arg
  4269. (read-from-minibuffer "Sticky article buffer name: ")
  4270. (gnus-with-article-headers
  4271. (gnus-article-goto-header "subject")
  4272. (setq new-art-buf-name
  4273. (buffer-substring-no-properties
  4274. (line-beginning-position) (line-end-position)))
  4275. (goto-char (point-min))
  4276. (gnus-article-goto-header "from")
  4277. (setq new-art-buf-name
  4278. (concat
  4279. new-art-buf-name ", "
  4280. (buffer-substring-no-properties
  4281. (line-beginning-position) (line-end-position))))
  4282. (goto-char (point-min))
  4283. (gnus-article-goto-header "date")
  4284. (setq new-art-buf-name
  4285. (concat
  4286. new-art-buf-name ", "
  4287. (buffer-substring-no-properties
  4288. (line-beginning-position) (line-end-position))))))
  4289. "*"))
  4290. (if (and (gnus-buffer-live-p new-art-buf-name)
  4291. (with-current-buffer new-art-buf-name
  4292. (eq major-mode 'gnus-sticky-article-mode)))
  4293. (switch-to-buffer new-art-buf-name)
  4294. (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
  4295. (gnus-sticky-article-mode))
  4296. (setq gnus-article-buffer new-art-buf-name))
  4297. (gnus-summary-recenter)
  4298. (gnus-summary-position-point))
  4299. (defun gnus-kill-sticky-article-buffer (&optional buffer)
  4300. "Kill the given sticky article BUFFER.
  4301. If none is given, assume the current buffer and kill it if it has
  4302. `gnus-sticky-article-mode'."
  4303. (interactive)
  4304. (unless buffer
  4305. (setq buffer (current-buffer)))
  4306. (with-current-buffer buffer
  4307. (when (eq major-mode 'gnus-sticky-article-mode)
  4308. (gnus-kill-buffer buffer))))
  4309. (defun gnus-kill-sticky-article-buffers (arg)
  4310. "Kill all sticky article buffers.
  4311. If a prefix ARG is given, ask for confirmation."
  4312. (interactive "P")
  4313. (dolist (buf (gnus-buffers))
  4314. (with-current-buffer buf
  4315. (when (eq major-mode 'gnus-sticky-article-mode)
  4316. (if (not arg)
  4317. (gnus-kill-buffer buf)
  4318. (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
  4319. (gnus-kill-buffer buf)))))))
  4320. ;;;
  4321. ;;; Gnus MIME viewing functions
  4322. ;;;
  4323. (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
  4324. "Format of the MIME buttons.
  4325. Valid specifiers include:
  4326. %t The MIME type
  4327. %T MIME type, along with additional info
  4328. %n The `name' parameter
  4329. %d The description, if any
  4330. %l The length of the encoded part
  4331. %p The part identifier number
  4332. %e Dots if the part isn't displayed
  4333. General format specifiers can also be used. See Info node
  4334. `(gnus)Formatting Variables'.")
  4335. (defvar gnus-mime-button-line-format-alist
  4336. '((?t gnus-tmp-type ?s)
  4337. (?T gnus-tmp-type-long ?s)
  4338. (?n gnus-tmp-name ?s)
  4339. (?d gnus-tmp-description ?s)
  4340. (?p gnus-tmp-id ?s)
  4341. (?l gnus-tmp-length ?d)
  4342. (?e gnus-tmp-dots ?s)))
  4343. (defvar gnus-mime-button-commands
  4344. '((gnus-article-press-button "\r" "Toggle Display")
  4345. (gnus-mime-view-part "v" "View Interactively...")
  4346. (gnus-mime-view-part-as-type "t" "View As Type...")
  4347. (gnus-mime-view-part-as-charset "C" "View As charset...")
  4348. (gnus-mime-save-part "o" "Save...")
  4349. (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
  4350. (gnus-mime-replace-part "r" "Replace part")
  4351. (gnus-mime-delete-part "d" "Delete part")
  4352. (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
  4353. (gnus-mime-inline-part "i" "View As Text, In This Buffer")
  4354. (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
  4355. (gnus-mime-view-part-externally "e" "View Externally")
  4356. (gnus-mime-print-part "p" "Print")
  4357. (gnus-mime-pipe-part "|" "Pipe To Command...")
  4358. (gnus-mime-action-on-part "." "Take action on the part...")))
  4359. (defun gnus-article-mime-part-status ()
  4360. (if gnus-article-mime-handle-alist-1
  4361. (if (eq 1 (length gnus-article-mime-handle-alist-1))
  4362. " (1 part)"
  4363. (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
  4364. ""))
  4365. (defvar gnus-mime-button-map
  4366. (let ((map (make-sparse-keymap)))
  4367. (define-key map gnus-mouse-2 'gnus-article-push-button)
  4368. (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
  4369. (dolist (c gnus-mime-button-commands)
  4370. (define-key map (cadr c) (car c)))
  4371. map))
  4372. (easy-menu-define
  4373. gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
  4374. `("MIME Part"
  4375. ,@(mapcar (lambda (c)
  4376. (vector (caddr c) (car c) :active t))
  4377. gnus-mime-button-commands)))
  4378. (defmacro gnus-bind-safe-url-regexp (&rest body)
  4379. "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
  4380. `(let ((mm-w3m-safe-url-regexp
  4381. (let ((group (if (and (eq major-mode 'gnus-article-mode)
  4382. (gnus-buffer-live-p
  4383. gnus-article-current-summary))
  4384. (with-current-buffer gnus-article-current-summary
  4385. gnus-newsgroup-name)
  4386. gnus-newsgroup-name)))
  4387. (if (cond ((stringp gnus-safe-html-newsgroups)
  4388. (string-match gnus-safe-html-newsgroups group))
  4389. ((consp gnus-safe-html-newsgroups)
  4390. (member group gnus-safe-html-newsgroups)))
  4391. nil
  4392. mm-w3m-safe-url-regexp))))
  4393. ,@body))
  4394. (defun gnus-mime-button-menu (event prefix)
  4395. "Construct a context-sensitive menu of MIME commands."
  4396. (interactive "e\nP")
  4397. (save-window-excursion
  4398. (let ((pos (event-start event)))
  4399. (select-window (posn-window pos))
  4400. (goto-char (posn-point pos))
  4401. (gnus-article-check-buffer)
  4402. (popup-menu gnus-mime-button-menu nil prefix))))
  4403. (defun gnus-mime-view-all-parts (&optional handles)
  4404. "View all the MIME parts."
  4405. (interactive)
  4406. (with-current-buffer gnus-article-buffer
  4407. (let ((handles (or handles gnus-article-mime-handles))
  4408. (mail-parse-charset gnus-newsgroup-charset)
  4409. (mail-parse-ignored-charsets
  4410. (with-current-buffer gnus-summary-buffer
  4411. gnus-newsgroup-ignored-charsets)))
  4412. (when handles
  4413. (mm-remove-parts handles)
  4414. (goto-char (point-min))
  4415. (or (search-forward "\n\n") (goto-char (point-max)))
  4416. (let ((inhibit-read-only t))
  4417. (delete-region (point) (point-max))
  4418. (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
  4419. (defun gnus-article-jump-to-part (n)
  4420. "Jump to MIME part N."
  4421. (interactive "P")
  4422. (pop-to-buffer gnus-article-buffer)
  4423. ;; FIXME: why is it necessary?
  4424. (sit-for 0)
  4425. (let ((parts (length gnus-article-mime-handle-alist)))
  4426. (or n (setq n
  4427. (string-to-number
  4428. (read-string ;; Emacs 21 doesn't have `read-number'.
  4429. (format "Jump to part (2..%s): " parts)))))
  4430. (unless (and (integerp n) (<= n parts) (>= n 1))
  4431. (setq n
  4432. (progn
  4433. (gnus-message 7 "Invalid part `%s', using %s instead."
  4434. n parts)
  4435. parts)))
  4436. (gnus-message 9 "Jumping to part %s." n)
  4437. (cond ((>= gnus-auto-select-part 1)
  4438. (while (and (<= n parts)
  4439. (not (gnus-article-goto-part n)))
  4440. (setq n (1+ n))))
  4441. ((< gnus-auto-select-part 0)
  4442. (while (and (>= n 1)
  4443. (not (gnus-article-goto-part n)))
  4444. (setq n (1- n))))
  4445. (t
  4446. (gnus-article-goto-part n)))))
  4447. (eval-when-compile
  4448. (defsubst gnus-article-edit-part (handles &optional current-id)
  4449. "Edit an article in order to delete a mime part.
  4450. This function is exclusively used by `gnus-mime-save-part-and-strip'
  4451. and `gnus-mime-delete-part', and not provided at run-time normally."
  4452. (gnus-article-edit-article
  4453. `(lambda ()
  4454. (buffer-disable-undo)
  4455. (erase-buffer)
  4456. (let ((mail-parse-charset (or gnus-article-charset
  4457. ',gnus-newsgroup-charset))
  4458. (mail-parse-ignored-charsets
  4459. (or gnus-article-ignored-charsets
  4460. ',gnus-newsgroup-ignored-charsets))
  4461. (mbl mml-buffer-list))
  4462. (setq mml-buffer-list nil)
  4463. (insert-buffer-substring gnus-original-article-buffer)
  4464. (mime-to-mml ',handles)
  4465. (setq gnus-article-mime-handles nil)
  4466. (let ((mbl1 mml-buffer-list))
  4467. (setq mml-buffer-list mbl)
  4468. (set (make-local-variable 'mml-buffer-list) mbl1))
  4469. (gnus-make-local-hook 'kill-buffer-hook)
  4470. (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
  4471. `(lambda (no-highlight)
  4472. (let ((mail-parse-charset (or gnus-article-charset
  4473. ',gnus-newsgroup-charset))
  4474. (message-options message-options)
  4475. (message-options-set-recipient)
  4476. (mail-parse-ignored-charsets
  4477. (or gnus-article-ignored-charsets
  4478. ',gnus-newsgroup-ignored-charsets)))
  4479. (mml-to-mime)
  4480. (mml-destroy-buffers)
  4481. (remove-hook 'kill-buffer-hook
  4482. 'mml-destroy-buffers t)
  4483. (kill-local-variable 'mml-buffer-list))
  4484. (gnus-summary-edit-article-done
  4485. ,(or (mail-header-references gnus-current-headers) "")
  4486. ,(gnus-group-read-only-p)
  4487. ,gnus-summary-buffer no-highlight))
  4488. t)
  4489. (gnus-article-edit-done)
  4490. (gnus-configure-windows 'article)
  4491. (when (and current-id (integerp gnus-auto-select-part))
  4492. (gnus-article-jump-to-part (+ current-id gnus-auto-select-part)))))
  4493. (defun gnus-mime-replace-part (file)
  4494. "Replace MIME part under point with an external body."
  4495. ;; Useful if file has already been saved to disk
  4496. (interactive
  4497. (list
  4498. (read-file-name "Replace MIME part with file: "
  4499. (or mm-default-directory default-directory)
  4500. nil nil)))
  4501. (gnus-mime-save-part-and-strip file))
  4502. (defun gnus-mime-save-part-and-strip (&optional file)
  4503. "Save the MIME part under point then replace it with an external body.
  4504. If FILE is given, use it for the external part."
  4505. (interactive)
  4506. (gnus-article-check-buffer)
  4507. (when (gnus-group-read-only-p)
  4508. (error "The current group does not support deleting of parts"))
  4509. (when (mm-complicated-handles gnus-article-mime-handles)
  4510. (error "\
  4511. The current article has a complicated MIME structure, giving up..."))
  4512. (let* ((data (get-text-property (point) 'gnus-data))
  4513. (id (get-text-property (point) 'gnus-part))
  4514. param
  4515. (handles gnus-article-mime-handles))
  4516. (unless file
  4517. (setq file
  4518. (and data (mm-save-part data "Delete MIME part and save to: "))))
  4519. (when file
  4520. (with-current-buffer (mm-handle-buffer data)
  4521. (erase-buffer)
  4522. (insert "Content-Type: " (mm-handle-media-type data))
  4523. (mml-insert-parameter-string (cdr (mm-handle-type data))
  4524. '(charset))
  4525. ;; Add a filename for the sake of saving the part again.
  4526. (mml-insert-parameter
  4527. (mail-header-encode-parameter "name" (file-name-nondirectory file)))
  4528. (insert "\n")
  4529. (insert "Content-ID: " (message-make-message-id) "\n")
  4530. (insert "Content-Transfer-Encoding: binary\n")
  4531. (insert "\n"))
  4532. (setcdr data
  4533. (cdr (mm-make-handle nil
  4534. `("message/external-body"
  4535. (access-type . "LOCAL-FILE")
  4536. (name . ,file)))))
  4537. ;; (set-buffer gnus-summary-buffer)
  4538. (gnus-article-edit-part handles id))))
  4539. ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
  4540. ;; parts...>') but with stripping would be nice.
  4541. (defun gnus-mime-delete-part ()
  4542. "Delete the MIME part under point.
  4543. Replace it with some information about the removed part."
  4544. (interactive)
  4545. (gnus-article-check-buffer)
  4546. (when (gnus-group-read-only-p)
  4547. (error "The current group does not support deleting of parts"))
  4548. (when (mm-complicated-handles gnus-article-mime-handles)
  4549. (error "\
  4550. The current article has a complicated MIME structure, giving up..."))
  4551. (when (or gnus-expert-user
  4552. (gnus-yes-or-no-p "\
  4553. Deleting parts may malfunction or destroy the article; continue? "))
  4554. (let* ((data (get-text-property (point) 'gnus-data))
  4555. (id (get-text-property (point) 'gnus-part))
  4556. (handles gnus-article-mime-handles)
  4557. (none "(none)")
  4558. (description
  4559. (let ((desc (mm-handle-description data)))
  4560. (when desc
  4561. (mail-decode-encoded-word-string desc))))
  4562. (filename
  4563. (or (mail-content-type-get (mm-handle-disposition data) 'filename)
  4564. none))
  4565. (type (mm-handle-media-type data)))
  4566. (unless data
  4567. (error "No MIME part under point"))
  4568. (with-current-buffer (mm-handle-buffer data)
  4569. (let ((bsize (format "%s" (buffer-size))))
  4570. (erase-buffer)
  4571. (insert
  4572. (concat
  4573. ",----\n"
  4574. "| The following attachment has been deleted:\n"
  4575. "|\n"
  4576. "| Type: " type "\n"
  4577. "| Filename: " filename "\n"
  4578. "| Size (encoded): " bsize " Byte\n"
  4579. (when description
  4580. (concat "| Description: " description "\n"))
  4581. "`----\n"))
  4582. (setcdr data
  4583. (cdr (mm-make-handle
  4584. nil `("text/plain" (charset . gnus-decoded)) nil nil
  4585. (list "attachment")
  4586. (format "Deleted attachment (%s bytes)" bsize))))))
  4587. ;; (set-buffer gnus-summary-buffer)
  4588. (gnus-article-edit-part handles id))))
  4589. (defun gnus-mime-save-part ()
  4590. "Save the MIME part under point."
  4591. (interactive)
  4592. (gnus-article-check-buffer)
  4593. (let ((data (get-text-property (point) 'gnus-data)))
  4594. (when data
  4595. (mm-save-part data))))
  4596. (defun gnus-mime-pipe-part ()
  4597. "Pipe the MIME part under point to a process."
  4598. (interactive)
  4599. (gnus-article-check-buffer)
  4600. (let ((data (get-text-property (point) 'gnus-data)))
  4601. (when data
  4602. (mm-pipe-part data))))
  4603. (defun gnus-mime-view-part ()
  4604. "Interactively choose a viewing method for the MIME part under point."
  4605. (interactive)
  4606. (gnus-article-check-buffer)
  4607. (let ((data (get-text-property (point) 'gnus-data)))
  4608. (when data
  4609. (setq gnus-article-mime-handles
  4610. (mm-merge-handles
  4611. gnus-article-mime-handles (setq data (copy-sequence data))))
  4612. (mm-interactively-view-part data))))
  4613. (defun gnus-mime-view-part-as-type-internal ()
  4614. (gnus-article-check-buffer)
  4615. (let* ((handle (get-text-property (point) 'gnus-data))
  4616. (name (or
  4617. ;; Content-Type: foo/bar; name=...
  4618. (mail-content-type-get (mm-handle-type handle) 'name)
  4619. ;; Content-Disposition: attachment; filename=...
  4620. (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
  4621. (def-type (and name (mm-default-file-encoding name))))
  4622. (or (and def-type (cons def-type 0))
  4623. (and handle
  4624. (equal (mm-handle-media-supertype handle) "text")
  4625. '("text/plain" . 0))
  4626. '("application/octet-stream" . 0))))
  4627. (defun gnus-mime-view-part-as-type (&optional mime-type pred)
  4628. "Choose a MIME media type, and view the part as such.
  4629. If non-nil, PRED is a predicate to use during completion to limit the
  4630. available media-types."
  4631. (interactive)
  4632. (unless mime-type
  4633. (setq mime-type
  4634. (let ((default (gnus-mime-view-part-as-type-internal)))
  4635. (completing-read
  4636. (format "View as MIME type (default %s): "
  4637. (car default))
  4638. (mapcar #'list (mailcap-mime-types))
  4639. pred nil nil nil
  4640. (car default)))))
  4641. (gnus-article-check-buffer)
  4642. (let ((handle (get-text-property (point) 'gnus-data)))
  4643. (when handle
  4644. (when (equal (mm-handle-media-type handle) "message/external-body")
  4645. (unless (mm-handle-cache handle)
  4646. (mm-extern-cache-contents handle))
  4647. (setq handle (mm-handle-cache handle)))
  4648. (setq handle
  4649. (mm-make-handle (mm-handle-buffer handle)
  4650. (cons mime-type (cdr (mm-handle-type handle)))
  4651. (mm-handle-encoding handle)
  4652. (mm-handle-undisplayer handle)
  4653. (mm-handle-disposition handle)
  4654. (mm-handle-description handle)
  4655. nil
  4656. (mm-handle-id handle)))
  4657. (setq gnus-article-mime-handles
  4658. (mm-merge-handles gnus-article-mime-handles handle))
  4659. (when (mm-handle-displayed-p handle)
  4660. (mm-remove-part handle))
  4661. (gnus-mm-display-part handle))))
  4662. (defun gnus-mime-copy-part (&optional handle arg)
  4663. "Put the MIME part under point into a new buffer.
  4664. If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
  4665. are decompressed."
  4666. (interactive (list nil current-prefix-arg))
  4667. (gnus-article-check-buffer)
  4668. (unless handle
  4669. (setq handle (get-text-property (point) 'gnus-data)))
  4670. (when handle
  4671. (let ((filename (or (mail-content-type-get (mm-handle-type handle)
  4672. 'name)
  4673. (mail-content-type-get (mm-handle-disposition handle)
  4674. 'filename)))
  4675. contents dont-decode charset coding-system)
  4676. (mm-with-unibyte-buffer
  4677. (mm-insert-part handle)
  4678. (setq contents (or (condition-case nil
  4679. (mm-decompress-buffer filename nil 'sig)
  4680. (error
  4681. (setq dont-decode t)
  4682. nil))
  4683. (buffer-string))))
  4684. (setq filename (cond (filename (file-name-nondirectory filename))
  4685. (dont-decode "*raw data*")
  4686. (t "*decoded*")))
  4687. (cond
  4688. (dont-decode)
  4689. ((not arg)
  4690. (unless (setq charset (mail-content-type-get
  4691. (mm-handle-type handle) 'charset))
  4692. (unless (setq coding-system (mm-with-unibyte-buffer
  4693. (insert contents)
  4694. (mm-find-buffer-file-coding-system)))
  4695. (setq charset gnus-newsgroup-charset))))
  4696. ((numberp arg)
  4697. (setq charset (or (cdr (assq arg
  4698. gnus-summary-show-article-charset-alist))
  4699. (mm-read-coding-system "Charset: ")))))
  4700. (switch-to-buffer (generate-new-buffer filename))
  4701. (if (or coding-system
  4702. (and charset
  4703. (setq coding-system (mm-charset-to-coding-system charset))
  4704. (not (eq charset 'ascii))))
  4705. (progn
  4706. (mm-enable-multibyte)
  4707. (insert (mm-decode-coding-string contents coding-system))
  4708. (setq buffer-file-coding-system
  4709. (if (boundp 'last-coding-system-used)
  4710. (symbol-value 'last-coding-system-used)
  4711. coding-system)))
  4712. (mm-disable-multibyte)
  4713. (insert contents)
  4714. (setq buffer-file-coding-system mm-binary-coding-system))
  4715. ;; We do it this way to make `normal-mode' set the appropriate mode.
  4716. (unwind-protect
  4717. (progn
  4718. (setq buffer-file-name (expand-file-name filename))
  4719. (normal-mode))
  4720. (setq buffer-file-name nil))
  4721. (goto-char (point-min)))))
  4722. (defun gnus-mime-print-part (&optional handle filename)
  4723. "Print the MIME part under point."
  4724. (interactive (list nil (ps-print-preprint current-prefix-arg)))
  4725. (gnus-article-check-buffer)
  4726. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  4727. (contents (and handle (mm-get-part handle)))
  4728. (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
  4729. (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
  4730. (when contents
  4731. (if printer
  4732. (unwind-protect
  4733. (progn
  4734. (mm-save-part-to-file handle file)
  4735. (call-process shell-file-name nil
  4736. (generate-new-buffer " *mm*")
  4737. nil
  4738. shell-command-switch
  4739. (mm-mailcap-command
  4740. printer file (mm-handle-type handle))))
  4741. (delete-file file))
  4742. (with-temp-buffer
  4743. (insert contents)
  4744. (gnus-print-buffer))
  4745. (ps-despool filename)))))
  4746. (defun gnus-mime-inline-part (&optional handle arg)
  4747. "Insert the MIME part under point into the current buffer.
  4748. Compressed files like .gz and .bz2 are decompressed."
  4749. (interactive (list nil current-prefix-arg))
  4750. (gnus-article-check-buffer)
  4751. (unless handle
  4752. (setq handle (get-text-property (point) 'gnus-data)))
  4753. (when handle
  4754. (let ((b (point))
  4755. (inhibit-read-only t)
  4756. contents charset coding-system)
  4757. (if (and (not arg) (mm-handle-undisplayer handle))
  4758. (mm-remove-part handle)
  4759. (mm-with-unibyte-buffer
  4760. (mm-insert-part handle)
  4761. (setq contents
  4762. (or (mm-decompress-buffer
  4763. (or (mail-content-type-get (mm-handle-type handle)
  4764. 'name)
  4765. (mail-content-type-get (mm-handle-disposition handle)
  4766. 'filename))
  4767. nil t)
  4768. (buffer-string))))
  4769. (cond
  4770. ((not arg)
  4771. (unless (setq charset (mail-content-type-get
  4772. (mm-handle-type handle) 'charset))
  4773. (unless (setq coding-system
  4774. (mm-with-unibyte-buffer
  4775. (insert contents)
  4776. (mm-find-buffer-file-coding-system)))
  4777. (setq charset gnus-newsgroup-charset))))
  4778. ((numberp arg)
  4779. (if (mm-handle-undisplayer handle)
  4780. (mm-remove-part handle))
  4781. (setq charset
  4782. (or (cdr (assq arg
  4783. gnus-summary-show-article-charset-alist))
  4784. (mm-read-coding-system "Charset: "))))
  4785. (t
  4786. (if (mm-handle-undisplayer handle)
  4787. (mm-remove-part handle))))
  4788. (forward-line 2)
  4789. (mm-insert-inline
  4790. handle
  4791. (if (or coding-system
  4792. (and charset
  4793. (setq coding-system
  4794. (mm-charset-to-coding-system charset))
  4795. (not (eq coding-system 'ascii))))
  4796. (mm-decode-coding-string contents coding-system)
  4797. (mm-string-to-multibyte contents)))
  4798. (goto-char b)))))
  4799. (defun gnus-mime-set-charset-parameters (handle charset)
  4800. "Set CHARSET to parameters in HANDLE.
  4801. CHARSET may either be a string or a symbol."
  4802. (unless (stringp charset)
  4803. (setq charset (symbol-name charset)))
  4804. (if (stringp (car handle))
  4805. (dolist (h (cdr handle))
  4806. (gnus-mime-set-charset-parameters h charset))
  4807. (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
  4808. "message/external-body")
  4809. (progn
  4810. (unless (mm-handle-cache handle)
  4811. (mm-extern-cache-contents handle))
  4812. (mm-handle-cache handle))
  4813. handle)))
  4814. (param (assq 'charset (cdr type))))
  4815. (if param
  4816. (setcdr param charset)
  4817. (setcdr type (cons (cons 'charset charset) (cdr type)))))))
  4818. (defun gnus-mime-view-part-as-charset (&optional handle arg)
  4819. "Insert the MIME part under point into the current buffer using the
  4820. specified charset."
  4821. (interactive (list nil current-prefix-arg))
  4822. (gnus-article-check-buffer)
  4823. (let ((handle (or handle (get-text-property (point) 'gnus-data)))
  4824. (fun (get-text-property (point) 'gnus-callback))
  4825. (gnus-newsgroup-ignored-charsets 'gnus-all)
  4826. charset form preferred parts)
  4827. (when handle
  4828. (when (prog1
  4829. (and fun
  4830. (setq charset
  4831. (or (cdr (assq
  4832. arg
  4833. gnus-summary-show-article-charset-alist))
  4834. (mm-read-coding-system "Charset: "))))
  4835. (if (mm-handle-undisplayer handle)
  4836. (mm-remove-part handle)))
  4837. (gnus-mime-set-charset-parameters handle charset)
  4838. (when (and (consp (setq form (cdr-safe fun)))
  4839. (setq form (ignore-errors
  4840. (assq 'gnus-mime-display-alternative form)))
  4841. (setq preferred (caddr form))
  4842. (progn
  4843. (when (eq (car preferred) 'quote)
  4844. (setq preferred (cadr preferred)))
  4845. (not (equal preferred
  4846. (get-text-property (point) 'gnus-data))))
  4847. (setq parts (get-text-property (point) 'gnus-part))
  4848. (setq parts (cdr (assq parts
  4849. gnus-article-mime-handle-alist)))
  4850. (equal (mm-handle-media-type parts) "multipart/alternative")
  4851. (setq parts (reverse (cdr parts))))
  4852. (setcar (cddr form)
  4853. (list 'quote (or (cadr (member preferred parts))
  4854. (car parts)))))
  4855. (funcall fun handle)))))
  4856. (defun gnus-mime-view-part-externally (&optional handle)
  4857. "View the MIME part under point with an external viewer."
  4858. (interactive)
  4859. (gnus-article-check-buffer)
  4860. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  4861. (mm-user-display-methods nil)
  4862. (mm-inlined-types nil)
  4863. (mail-parse-charset gnus-newsgroup-charset)
  4864. (mail-parse-ignored-charsets
  4865. (with-current-buffer gnus-summary-buffer
  4866. gnus-newsgroup-ignored-charsets))
  4867. (type (mm-handle-media-type handle))
  4868. (method (mailcap-mime-info type))
  4869. (mm-enable-external t))
  4870. (if (not (stringp method))
  4871. (gnus-mime-view-part-as-type
  4872. nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
  4873. (when handle
  4874. (if (mm-handle-undisplayer handle)
  4875. (mm-remove-part handle)
  4876. (mm-display-part handle))))))
  4877. (defun gnus-mime-view-part-internally (&optional handle)
  4878. "View the MIME part under point with an internal viewer.
  4879. If no internal viewer is available, use an external viewer."
  4880. (interactive)
  4881. (gnus-article-check-buffer)
  4882. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  4883. (mm-inlined-types '(".*"))
  4884. (mm-inline-large-images t)
  4885. (mail-parse-charset gnus-newsgroup-charset)
  4886. (mail-parse-ignored-charsets
  4887. (with-current-buffer gnus-summary-buffer
  4888. gnus-newsgroup-ignored-charsets))
  4889. (inhibit-read-only t))
  4890. (if (not (mm-inlinable-p handle))
  4891. (gnus-mime-view-part-as-type
  4892. nil (lambda (types) (mm-inlinable-p handle (car types))))
  4893. (when handle
  4894. (if (mm-handle-undisplayer handle)
  4895. (mm-remove-part handle)
  4896. (gnus-bind-safe-url-regexp (mm-display-part handle)))))))
  4897. (defun gnus-mime-action-on-part (&optional action)
  4898. "Do something with the MIME attachment at \(point\)."
  4899. (interactive
  4900. (list (completing-read "Action: " gnus-mime-action-alist nil t)))
  4901. (gnus-article-check-buffer)
  4902. (let ((action-pair (assoc action gnus-mime-action-alist)))
  4903. (if action-pair
  4904. (funcall (cdr action-pair)))))
  4905. (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
  4906. "Call FUNCTION on MIME part N.
  4907. Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
  4908. If INTERACTIVE, call FUNCTION interactivly."
  4909. (let (window frame)
  4910. ;; Check whether the article is displayed.
  4911. (unless (and (gnus-buffer-live-p gnus-article-buffer)
  4912. (setq window (get-buffer-window gnus-article-buffer t))
  4913. (frame-visible-p (setq frame (window-frame window))))
  4914. (error "No article is displayed"))
  4915. (with-current-buffer gnus-article-buffer
  4916. ;; Check whether the article displays the right contents.
  4917. (unless (with-current-buffer gnus-summary-buffer
  4918. (eq gnus-current-article (gnus-summary-article-number)))
  4919. (error "You should select the right article first"))
  4920. (if n
  4921. (setq n (prefix-numeric-value n))
  4922. (let ((pt (point)))
  4923. (setq n (or (get-text-property pt 'gnus-part)
  4924. (and (not (bobp))
  4925. (get-text-property (1- pt) 'gnus-part))
  4926. (get-text-property (prog2
  4927. (forward-line 1)
  4928. (point)
  4929. (goto-char pt))
  4930. 'gnus-part)
  4931. (get-text-property
  4932. (or (and (setq pt (previous-single-property-change
  4933. pt 'gnus-part))
  4934. (1- pt))
  4935. (next-single-property-change (point) 'gnus-part)
  4936. (point))
  4937. 'gnus-part)
  4938. 1))))
  4939. ;; Check whether the specified part exists.
  4940. (when (> n (length gnus-article-mime-handle-alist))
  4941. (error "No such part")))
  4942. (unless
  4943. (progn
  4944. ;; To select the window is needed so that the cursor
  4945. ;; might be visible on the MIME button.
  4946. (select-window (prog1
  4947. window
  4948. (setq window (selected-window))
  4949. ;; Article may be displayed in the other frame.
  4950. (gnus-select-frame-set-input-focus
  4951. (prog1
  4952. frame
  4953. (setq frame (selected-frame))))))
  4954. (when (gnus-article-goto-part n)
  4955. ;; We point the cursor and the arrow at the MIME button
  4956. ;; when the `function' prompt the user for something.
  4957. (let ((cursor-in-non-selected-windows t)
  4958. (overlay-arrow-string "=>")
  4959. (overlay-arrow-position (point-marker)))
  4960. (unwind-protect
  4961. (cond
  4962. ((and no-handle interactive)
  4963. (call-interactively function))
  4964. (no-handle
  4965. (funcall function))
  4966. (interactive
  4967. (call-interactively
  4968. function
  4969. (cdr (assq n gnus-article-mime-handle-alist))))
  4970. (t
  4971. (funcall function
  4972. (cdr (assq n gnus-article-mime-handle-alist)))))
  4973. (set-marker overlay-arrow-position nil)
  4974. (unless gnus-auto-select-part
  4975. (gnus-select-frame-set-input-focus frame)
  4976. (select-window window))))
  4977. t))
  4978. (if gnus-inhibit-mime-unbuttonizing
  4979. ;; This is the default though the program shouldn't reach here.
  4980. (error "No such part")
  4981. ;; The part which doesn't have the MIME button is selected.
  4982. ;; So, we display all the buttons and redo it.
  4983. (let ((gnus-inhibit-mime-unbuttonizing t))
  4984. (gnus-summary-show-article)
  4985. (gnus-article-part-wrapper n function no-handle))))))
  4986. (defun gnus-article-pipe-part (n)
  4987. "Pipe MIME part N, which is the numerical prefix."
  4988. (interactive "P")
  4989. (gnus-article-part-wrapper n 'mm-pipe-part))
  4990. (defun gnus-article-save-part (n)
  4991. "Save MIME part N, which is the numerical prefix."
  4992. (interactive "P")
  4993. (gnus-article-part-wrapper n 'mm-save-part))
  4994. (defun gnus-article-interactively-view-part (n)
  4995. "View MIME part N interactively, which is the numerical prefix."
  4996. (interactive "P")
  4997. (gnus-article-part-wrapper n 'mm-interactively-view-part))
  4998. (defun gnus-article-copy-part (n)
  4999. "Copy MIME part N, which is the numerical prefix."
  5000. (interactive "P")
  5001. (gnus-article-part-wrapper n 'gnus-mime-copy-part))
  5002. (defun gnus-article-view-part-as-charset (n)
  5003. "View MIME part N using a specified charset.
  5004. N is the numerical prefix."
  5005. (interactive "P")
  5006. (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
  5007. (defun gnus-article-view-part-externally (n)
  5008. "View MIME part N externally, which is the numerical prefix."
  5009. (interactive "P")
  5010. (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
  5011. (defun gnus-article-inline-part (n)
  5012. "Inline MIME part N, which is the numerical prefix."
  5013. (interactive "P")
  5014. (gnus-article-part-wrapper n 'gnus-mime-inline-part))
  5015. (defun gnus-article-save-part-and-strip (n)
  5016. "Save MIME part N and replace it with an external body.
  5017. N is the numerical prefix."
  5018. (interactive "P")
  5019. (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
  5020. (defun gnus-article-replace-part (n)
  5021. "Replace MIME part N with an external body.
  5022. N is the numerical prefix."
  5023. (interactive "P")
  5024. (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
  5025. (defun gnus-article-delete-part (n)
  5026. "Delete MIME part N and add some information about the removed part.
  5027. N is the numerical prefix."
  5028. (interactive "P")
  5029. (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
  5030. (defun gnus-article-view-part-as-type (n)
  5031. "Choose a MIME media type, and view part N as such.
  5032. N is the numerical prefix."
  5033. (interactive "P")
  5034. (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
  5035. (defun gnus-article-mime-match-handle-first (condition)
  5036. (if condition
  5037. (let (n)
  5038. (dolist (ihandle gnus-article-mime-handle-alist)
  5039. (if (and (cond
  5040. ((functionp condition)
  5041. (funcall condition (cdr ihandle)))
  5042. ((eq condition 'undisplayed)
  5043. (not (or (mm-handle-undisplayer (cdr ihandle))
  5044. (equal (mm-handle-media-type (cdr ihandle))
  5045. "multipart/alternative"))))
  5046. ((eq condition 'undisplayed-alternative)
  5047. (not (mm-handle-undisplayer (cdr ihandle))))
  5048. (t t))
  5049. (gnus-article-goto-part (car ihandle))
  5050. (or (not n) (< (car ihandle) n)))
  5051. (setq n (car ihandle))))
  5052. (or n 1))
  5053. 1))
  5054. (defun gnus-article-view-part (&optional n)
  5055. "View MIME part N, which is the numerical prefix."
  5056. (interactive "P")
  5057. (with-current-buffer gnus-article-buffer
  5058. (or (numberp n) (setq n (gnus-article-mime-match-handle-first
  5059. gnus-article-mime-match-handle-function)))
  5060. (when (> n (length gnus-article-mime-handle-alist))
  5061. (error "No such part"))
  5062. (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
  5063. (when (gnus-article-goto-part n)
  5064. (if (equal (car handle) "multipart/alternative")
  5065. (gnus-article-press-button)
  5066. (when (eq (gnus-mm-display-part handle) 'internal)
  5067. (gnus-set-window-start)))))))
  5068. (defsubst gnus-article-mime-total-parts ()
  5069. (if (bufferp (car gnus-article-mime-handles))
  5070. 1 ;; single part
  5071. (1- (length gnus-article-mime-handles))))
  5072. (defun gnus-mm-display-part (handle)
  5073. "Display HANDLE and fix MIME button."
  5074. (let ((id (get-text-property (point) 'gnus-part))
  5075. (point (point))
  5076. (inhibit-read-only t))
  5077. (forward-line 1)
  5078. (prog1
  5079. (let ((window (selected-window))
  5080. (mail-parse-charset gnus-newsgroup-charset)
  5081. (mail-parse-ignored-charsets
  5082. (if (gnus-buffer-live-p gnus-summary-buffer)
  5083. (with-current-buffer gnus-summary-buffer
  5084. gnus-newsgroup-ignored-charsets)
  5085. nil)))
  5086. (save-excursion
  5087. (unwind-protect
  5088. (let ((win (gnus-get-buffer-window (current-buffer) t))
  5089. (beg (point)))
  5090. (when win
  5091. (select-window win))
  5092. (goto-char point)
  5093. (forward-line)
  5094. (if (mm-handle-displayed-p handle)
  5095. ;; This will remove the part.
  5096. (mm-display-part handle)
  5097. (save-restriction
  5098. (narrow-to-region (point)
  5099. (if (eobp) (point) (1+ (point))))
  5100. (gnus-bind-safe-url-regexp (mm-display-part handle))
  5101. ;; We narrow to the part itself and
  5102. ;; then call the treatment functions.
  5103. (goto-char (point-min))
  5104. (forward-line 1)
  5105. (narrow-to-region (point) (point-max))
  5106. (gnus-treat-article
  5107. nil id
  5108. (gnus-article-mime-total-parts)
  5109. (mm-handle-media-type handle)))))
  5110. (if (window-live-p window)
  5111. (select-window window)))))
  5112. (goto-char point)
  5113. (gnus-delete-line)
  5114. (gnus-insert-mime-button
  5115. handle id (list (mm-handle-displayed-p handle)))
  5116. (goto-char point))))
  5117. (defun gnus-article-goto-part (n)
  5118. "Go to MIME part N."
  5119. (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
  5120. (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
  5121. (let ((gnus-tmp-name
  5122. (or (mail-content-type-get (mm-handle-type handle) 'name)
  5123. (mail-content-type-get (mm-handle-disposition handle) 'filename)
  5124. (mail-content-type-get (mm-handle-type handle) 'url)
  5125. ""))
  5126. (gnus-tmp-type (mm-handle-media-type handle))
  5127. (gnus-tmp-description (or (mm-handle-description handle) ""))
  5128. (gnus-tmp-dots
  5129. (if (if displayed (car displayed)
  5130. (mm-handle-displayed-p handle))
  5131. "" "..."))
  5132. (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
  5133. (buffer-size)))
  5134. gnus-tmp-type-long b e)
  5135. (when (string-match ".*/" gnus-tmp-name)
  5136. (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
  5137. (setq gnus-tmp-type-long (concat gnus-tmp-type
  5138. (and (not (equal gnus-tmp-name ""))
  5139. (concat "; " gnus-tmp-name))))
  5140. (unless (equal gnus-tmp-description "")
  5141. (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
  5142. (unless (bolp)
  5143. (insert "\n"))
  5144. (setq b (point))
  5145. (gnus-eval-format
  5146. gnus-mime-button-line-format gnus-mime-button-line-format-alist
  5147. `(keymap ,gnus-mime-button-map
  5148. gnus-callback gnus-mm-display-part
  5149. gnus-part ,gnus-tmp-id
  5150. article-type annotation
  5151. gnus-data ,handle))
  5152. (setq e (if (bolp)
  5153. ;; Exclude a newline.
  5154. (1- (point))
  5155. (point)))
  5156. (when gnus-article-button-face
  5157. (gnus-overlay-put (gnus-make-overlay b e nil t)
  5158. 'face gnus-article-button-face))
  5159. (widget-convert-button
  5160. 'link b e
  5161. :mime-handle handle
  5162. :action 'gnus-widget-press-button
  5163. :button-keymap gnus-mime-button-map
  5164. :help-echo
  5165. (lambda (widget/window &optional overlay pos)
  5166. ;; Needed to properly clear the message due to a bug in
  5167. ;; wid-edit (XEmacs only).
  5168. (if (boundp 'help-echo-owns-message)
  5169. (setq help-echo-owns-message t))
  5170. (format
  5171. "%S: %s the MIME part; %S: more options"
  5172. (aref gnus-mouse-2 0)
  5173. ;; XEmacs will get a single widget arg; Emacs 21 will get
  5174. ;; window, overlay, position.
  5175. (if (mm-handle-displayed-p
  5176. (if overlay
  5177. (with-current-buffer (gnus-overlay-buffer overlay)
  5178. (widget-get (widget-at (gnus-overlay-start overlay))
  5179. :mime-handle))
  5180. (widget-get widget/window :mime-handle)))
  5181. "hide" "show")
  5182. (aref gnus-down-mouse-3 0))))))
  5183. (defun gnus-widget-press-button (elems el)
  5184. (goto-char (widget-get elems :from))
  5185. (gnus-article-press-button))
  5186. (defvar gnus-displaying-mime nil)
  5187. (defun gnus-display-mime (&optional ihandles)
  5188. "Display the MIME parts."
  5189. (save-excursion
  5190. (save-selected-window
  5191. (let ((window (get-buffer-window gnus-article-buffer))
  5192. (point (point)))
  5193. (when window
  5194. (select-window window)
  5195. ;; We have to do this since selecting the window
  5196. ;; may change the point. So we set the window point.
  5197. (set-window-point window point)))
  5198. (let ((handles ihandles)
  5199. (inhibit-read-only t)
  5200. handle)
  5201. (cond (handles)
  5202. ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
  5203. (when gnus-article-emulate-mime
  5204. (mm-uu-dissect-text-parts handles)))
  5205. (gnus-article-emulate-mime
  5206. (setq handles (mm-uu-dissect))))
  5207. (when (and (not ihandles)
  5208. (not gnus-displaying-mime))
  5209. ;; Top-level call; we clean up.
  5210. (when gnus-article-mime-handles
  5211. (mm-destroy-parts gnus-article-mime-handles)
  5212. (setq gnus-article-mime-handle-alist nil));; A trick.
  5213. (setq gnus-article-mime-handles handles)
  5214. ;; We allow users to glean info from the handles.
  5215. (when gnus-article-mime-part-function
  5216. (gnus-mime-part-function handles)))
  5217. (if (and handles
  5218. (or (not (stringp (car handles)))
  5219. (cdr handles)))
  5220. (progn
  5221. (when (and (not ihandles)
  5222. (not gnus-displaying-mime))
  5223. ;; Clean up for mime parts.
  5224. (article-goto-body)
  5225. (delete-region (point) (point-max)))
  5226. (let ((gnus-displaying-mime t))
  5227. (gnus-mime-display-part handles)))
  5228. (save-restriction
  5229. (article-goto-body)
  5230. (narrow-to-region (point) (point-max))
  5231. (gnus-treat-article nil 1 1)
  5232. (widen)))
  5233. (unless ihandles
  5234. ;; Highlight the headers.
  5235. (save-excursion
  5236. (save-restriction
  5237. (article-goto-body)
  5238. (narrow-to-region (point-min) (point))
  5239. (gnus-article-save-original-date
  5240. (gnus-treat-article 'head)))))))
  5241. ;; Cope with broken MIME messages.
  5242. (goto-char (point-max))
  5243. (unless (bolp)
  5244. (insert "\n"))))
  5245. (defcustom gnus-mime-display-multipart-as-mixed nil
  5246. "Display \"multipart\" parts as \"multipart/mixed\".
  5247. If t, it overrides nil values of
  5248. `gnus-mime-display-multipart-alternative-as-mixed' and
  5249. `gnus-mime-display-multipart-related-as-mixed'."
  5250. :group 'gnus-article-mime
  5251. :type 'boolean)
  5252. (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
  5253. "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
  5254. :version "22.1"
  5255. :group 'gnus-article-mime
  5256. :type 'boolean)
  5257. (defcustom gnus-mime-display-multipart-related-as-mixed nil
  5258. "Display \"multipart/related\" parts as \"multipart/mixed\".
  5259. If displaying \"text/html\" is discouraged \(see
  5260. `mm-discouraged-alternatives'\) images or other material inside a
  5261. \"multipart/related\" part might be overlooked when this variable is nil."
  5262. :version "22.1"
  5263. :group 'gnus-article-mime
  5264. :type 'boolean)
  5265. (defun gnus-mime-display-part (handle)
  5266. (cond
  5267. ;; Maybe a broken MIME message.
  5268. ((null handle))
  5269. ;; Single part.
  5270. ((not (stringp (car handle)))
  5271. (gnus-mime-display-single handle))
  5272. ;; User-defined multipart
  5273. ((cdr (assoc (car handle) gnus-mime-multipart-functions))
  5274. (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
  5275. handle))
  5276. ;; multipart/alternative
  5277. ((and (equal (car handle) "multipart/alternative")
  5278. (not (or gnus-mime-display-multipart-as-mixed
  5279. gnus-mime-display-multipart-alternative-as-mixed)))
  5280. (let ((id (1+ (length gnus-article-mime-handle-alist))))
  5281. (push (cons id handle) gnus-article-mime-handle-alist)
  5282. (gnus-mime-display-alternative (cdr handle) nil nil id)))
  5283. ;; multipart/related
  5284. ((and (equal (car handle) "multipart/related")
  5285. (not (or gnus-mime-display-multipart-as-mixed
  5286. gnus-mime-display-multipart-related-as-mixed)))
  5287. ;;;!!!We should find the start part, but we just default
  5288. ;;;!!!to the first part.
  5289. ;;(gnus-mime-display-part (cadr handle))
  5290. ;;;!!! Most multipart/related is an HTML message plus images.
  5291. ;;;!!! Unfortunately we are unable to let W3 display those
  5292. ;;;!!! included images, so we just display it as a mixed multipart.
  5293. ;;(gnus-mime-display-mixed (cdr handle))
  5294. ;;;!!! No, w3 can display everything just fine.
  5295. (gnus-mime-display-part (cadr handle)))
  5296. ((equal (car handle) "multipart/signed")
  5297. (gnus-add-wash-type 'signed)
  5298. (gnus-mime-display-security handle))
  5299. ((equal (car handle) "multipart/encrypted")
  5300. (gnus-add-wash-type 'encrypted)
  5301. (gnus-mime-display-security handle))
  5302. ;; Other multiparts are handled like multipart/mixed.
  5303. (t
  5304. (gnus-mime-display-mixed (cdr handle)))))
  5305. (defun gnus-mime-part-function (handles)
  5306. (if (stringp (car handles))
  5307. (mapcar 'gnus-mime-part-function (cdr handles))
  5308. (funcall gnus-article-mime-part-function handles)))
  5309. (defun gnus-mime-display-mixed (handles)
  5310. (mapcar 'gnus-mime-display-part handles))
  5311. (defun gnus-mime-display-single (handle)
  5312. (let ((type (mm-handle-media-type handle))
  5313. (ignored gnus-ignored-mime-types)
  5314. (not-attachment t)
  5315. (move nil)
  5316. display text)
  5317. (catch 'ignored
  5318. (progn
  5319. (while ignored
  5320. (when (string-match (pop ignored) type)
  5321. (throw 'ignored nil)))
  5322. (if (and (setq not-attachment
  5323. (and (not (mm-inline-override-p handle))
  5324. (or (not (mm-handle-disposition handle))
  5325. (equal (car (mm-handle-disposition handle))
  5326. "inline")
  5327. (mm-attachment-override-p handle))))
  5328. (mm-automatic-display-p handle)
  5329. (or (and
  5330. (mm-inlinable-p handle)
  5331. (mm-inlined-p handle))
  5332. (mm-automatic-external-display-p type)))
  5333. (setq display t)
  5334. (when (equal (mm-handle-media-supertype handle) "text")
  5335. (setq text t)))
  5336. (let ((id (1+ (length gnus-article-mime-handle-alist)))
  5337. beg)
  5338. (push (cons id handle) gnus-article-mime-handle-alist)
  5339. (when (and display
  5340. (equal (mm-handle-media-supertype handle) "message"))
  5341. (insert-char
  5342. ?\n
  5343. (cond ((not (bolp)) 2)
  5344. ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
  5345. (t 1))))
  5346. (when (or (not display)
  5347. (not (gnus-unbuttonized-mime-type-p type)))
  5348. (gnus-insert-mime-button
  5349. handle id (list (or display (and not-attachment text))))
  5350. (gnus-article-insert-newline)
  5351. ;; Remember modify the number of forward lines.
  5352. (setq move t))
  5353. (setq beg (point))
  5354. (cond
  5355. (display
  5356. (when move
  5357. (forward-line -1)
  5358. (setq beg (point)))
  5359. (let ((mail-parse-charset gnus-newsgroup-charset)
  5360. (mail-parse-ignored-charsets
  5361. (save-excursion (condition-case ()
  5362. (set-buffer gnus-summary-buffer)
  5363. (error))
  5364. gnus-newsgroup-ignored-charsets)))
  5365. (gnus-bind-safe-url-regexp (mm-display-part handle t)))
  5366. (goto-char (point-max)))
  5367. ((and text not-attachment)
  5368. (when move
  5369. (forward-line -1)
  5370. (setq beg (point)))
  5371. (gnus-article-insert-newline)
  5372. (mm-insert-inline
  5373. handle
  5374. (let ((charset (or (mail-content-type-get (mm-handle-type handle)
  5375. 'charset)
  5376. (and (equal type "text/calendar") 'utf-8))))
  5377. (cond ((not charset)
  5378. (mm-string-as-multibyte (mm-get-part handle)))
  5379. ((eq charset 'gnus-decoded)
  5380. (with-current-buffer (mm-handle-buffer handle)
  5381. (buffer-string)))
  5382. (t
  5383. (mm-decode-string (mm-get-part handle) charset)))))
  5384. (goto-char (point-max))))
  5385. ;; Do highlighting.
  5386. (save-excursion
  5387. (save-restriction
  5388. (narrow-to-region beg (point))
  5389. (if (eq handle gnus-article-mime-handles)
  5390. ;; The format=flowed case.
  5391. (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
  5392. ;; Don't count signature parts that are never displayed.
  5393. ;; The part number should be re-calculated supposing this
  5394. ;; might be a message/rfc822 part.
  5395. (let (handles)
  5396. (dolist (part gnus-article-mime-handles)
  5397. (unless (or (stringp part)
  5398. (equal (car (mm-handle-type part))
  5399. "application/pgp-signature"))
  5400. (push part handles)))
  5401. (gnus-treat-article
  5402. nil (length (memq handle handles)) (length handles)
  5403. (mm-handle-media-type handle)))))))))))
  5404. (defun gnus-unbuttonized-mime-type-p (type)
  5405. "Say whether TYPE is to be unbuttonized."
  5406. (unless gnus-inhibit-mime-unbuttonizing
  5407. (when (catch 'found
  5408. (let ((types gnus-unbuttonized-mime-types))
  5409. (while types
  5410. (when (string-match (pop types) type)
  5411. (throw 'found t)))))
  5412. (not (catch 'found
  5413. (let ((types gnus-buttonized-mime-types))
  5414. (while types
  5415. (when (string-match (pop types) type)
  5416. (throw 'found t)))))))))
  5417. (defun gnus-article-insert-newline ()
  5418. "Insert a newline, but mark it as undeletable."
  5419. (gnus-put-text-property
  5420. (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
  5421. (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
  5422. (let* ((preferred (or preferred (mm-preferred-alternative handles)))
  5423. (ihandles handles)
  5424. (point (point))
  5425. handle (inhibit-read-only t) from props begend not-pref)
  5426. (save-window-excursion
  5427. (save-restriction
  5428. (when ibegend
  5429. (narrow-to-region (car ibegend)
  5430. (or (cdr ibegend)
  5431. (progn
  5432. (goto-char (car ibegend))
  5433. (forward-line 2)
  5434. (point))))
  5435. (delete-region (point-min) (point-max))
  5436. (mm-remove-parts handles))
  5437. (setq begend (list (point-marker)))
  5438. ;; Do the toggle.
  5439. (unless (setq not-pref (cadr (member preferred ihandles)))
  5440. (setq not-pref (car ihandles)))
  5441. (when (or ibegend
  5442. (not preferred)
  5443. (not (gnus-unbuttonized-mime-type-p
  5444. "multipart/alternative")))
  5445. (gnus-add-text-properties
  5446. (setq from (point))
  5447. (progn
  5448. (insert (format "%d. " id))
  5449. (point))
  5450. `(gnus-callback
  5451. (lambda (handles)
  5452. (unless ,(not ibegend)
  5453. (setq gnus-article-mime-handle-alist
  5454. ',gnus-article-mime-handle-alist))
  5455. (gnus-mime-display-alternative
  5456. ',ihandles ',not-pref ',begend ,id))
  5457. keymap ,gnus-mime-button-map
  5458. ,gnus-mouse-face-prop ,gnus-article-mouse-face
  5459. face ,gnus-article-button-face
  5460. gnus-part ,id
  5461. article-type multipart))
  5462. (widget-convert-button 'link from (point)
  5463. :action 'gnus-widget-press-button
  5464. :button-keymap gnus-widget-button-keymap)
  5465. ;; Do the handles
  5466. (while (setq handle (pop handles))
  5467. (gnus-add-text-properties
  5468. (setq from (point))
  5469. (progn
  5470. (insert (format "(%c) %-18s"
  5471. (if (equal handle preferred) ?* ? )
  5472. (mm-handle-media-type handle)))
  5473. (point))
  5474. `(gnus-callback
  5475. (lambda (handles)
  5476. (unless ,(not ibegend)
  5477. (setq gnus-article-mime-handle-alist
  5478. ',gnus-article-mime-handle-alist))
  5479. (gnus-mime-display-alternative
  5480. ',ihandles ',handle ',begend ,id))
  5481. keymap ,gnus-mime-button-map
  5482. ,gnus-mouse-face-prop ,gnus-article-mouse-face
  5483. face ,gnus-article-button-face
  5484. gnus-part ,id
  5485. gnus-data ,handle))
  5486. (widget-convert-button 'link from (point)
  5487. :action 'gnus-widget-press-button
  5488. :button-keymap gnus-widget-button-keymap)
  5489. (insert " "))
  5490. (insert "\n\n"))
  5491. (when preferred
  5492. (if (stringp (car preferred))
  5493. (gnus-display-mime preferred)
  5494. (let ((mail-parse-charset gnus-newsgroup-charset)
  5495. (mail-parse-ignored-charsets
  5496. (with-current-buffer gnus-summary-buffer
  5497. gnus-newsgroup-ignored-charsets)))
  5498. (gnus-bind-safe-url-regexp (mm-display-part preferred))
  5499. ;; Do highlighting.
  5500. (save-excursion
  5501. (save-restriction
  5502. (narrow-to-region (car begend) (point-max))
  5503. (gnus-treat-article
  5504. nil (length gnus-article-mime-handle-alist)
  5505. (gnus-article-mime-total-parts)
  5506. (mm-handle-media-type handle))))))
  5507. (goto-char (point-max))
  5508. (setcdr begend (point-marker)))))
  5509. (when ibegend
  5510. (goto-char point))))
  5511. (defconst gnus-article-wash-status-strings
  5512. (let ((alist '((cite "c" "Possible hidden citation text"
  5513. " " "All citation text visible")
  5514. (headers "h" "Hidden headers"
  5515. " " "All headers visible.")
  5516. (pgp "p" "Encrypted or signed message status hidden"
  5517. " " "No hidden encryption nor digital signature status")
  5518. (signature "s" "Signature has been hidden"
  5519. " " "Signature is visible")
  5520. (overstrike "o" "Overstrike (^H) characters applied"
  5521. " " "No overstrike characters applied")
  5522. (emphasis "e" "/*_Emphasis_*/ characters applied"
  5523. " " "No /*_emphasis_*/ characters applied")))
  5524. result)
  5525. (dolist (entry alist result)
  5526. (let ((key (nth 0 entry))
  5527. (on (copy-sequence (nth 1 entry)))
  5528. (on-help (nth 2 entry))
  5529. (off (copy-sequence (nth 3 entry)))
  5530. (off-help (nth 4 entry)))
  5531. (put-text-property 0 1 'help-echo on-help on)
  5532. (put-text-property 0 1 'help-echo off-help off)
  5533. (push (list key on off) result))))
  5534. "Alist of strings describing wash status in the mode line.
  5535. Each entry has the form (KEY ON OF), where the KEY is a symbol
  5536. representing the particular washing function, ON is the string to use
  5537. in the article mode line when the washing function is active, and OFF
  5538. is the string to use when it is inactive.")
  5539. (defun gnus-article-wash-status-entry (key value)
  5540. (let ((entry (assoc key gnus-article-wash-status-strings)))
  5541. (if value (nth 1 entry) (nth 2 entry))))
  5542. (defun gnus-article-wash-status ()
  5543. "Return a string which display status of article washing."
  5544. (with-current-buffer gnus-article-buffer
  5545. (let ((cite (memq 'cite gnus-article-wash-types))
  5546. (headers (memq 'headers gnus-article-wash-types))
  5547. (boring (memq 'boring-headers gnus-article-wash-types))
  5548. (pgp (memq 'pgp gnus-article-wash-types))
  5549. (pem (memq 'pem gnus-article-wash-types))
  5550. (signed (memq 'signed gnus-article-wash-types))
  5551. (encrypted (memq 'encrypted gnus-article-wash-types))
  5552. (signature (memq 'signature gnus-article-wash-types))
  5553. (overstrike (memq 'overstrike gnus-article-wash-types))
  5554. (emphasis (memq 'emphasis gnus-article-wash-types)))
  5555. (concat
  5556. (gnus-article-wash-status-entry 'cite cite)
  5557. (gnus-article-wash-status-entry 'headers (or headers boring))
  5558. (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
  5559. (gnus-article-wash-status-entry 'signature signature)
  5560. (gnus-article-wash-status-entry 'overstrike overstrike)
  5561. (gnus-article-wash-status-entry 'emphasis emphasis)))))
  5562. (defun gnus-add-wash-type (type)
  5563. "Add a washing of TYPE to the current status."
  5564. (add-to-list 'gnus-article-wash-types type))
  5565. (defun gnus-delete-wash-type (type)
  5566. "Add a washing of TYPE to the current status."
  5567. (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
  5568. (defun gnus-add-image (category image)
  5569. "Add IMAGE of CATEGORY to the list of displayed images."
  5570. (let ((entry (assq category gnus-article-image-alist)))
  5571. (unless entry
  5572. (setq entry (list category))
  5573. (push entry gnus-article-image-alist))
  5574. (nconc entry (list image))))
  5575. (defun gnus-delete-images (category)
  5576. "Delete all images in CATEGORY."
  5577. (let ((entry (assq category gnus-article-image-alist)))
  5578. (dolist (image (cdr entry))
  5579. (gnus-remove-image image category))
  5580. (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
  5581. (gnus-delete-wash-type category)))
  5582. (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
  5583. (defun gnus-article-maybe-hide-headers ()
  5584. "Hide unwanted headers if `gnus-have-all-headers' is nil.
  5585. Provided for backwards compatibility."
  5586. (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
  5587. (not (with-current-buffer gnus-summary-buffer
  5588. gnus-have-all-headers)))
  5589. (not gnus-inhibit-hiding))
  5590. (gnus-article-hide-headers)))
  5591. ;;; Article savers.
  5592. (defun gnus-output-to-file (file-name)
  5593. "Append the current article to a file named FILE-NAME.
  5594. If `gnus-article-save-coding-system' is non-nil, it is used to encode
  5595. text and used as the value of the coding cookie which is added to the
  5596. top of a file. Otherwise, this function saves a raw article without
  5597. the coding cookie."
  5598. (let* ((artbuf (current-buffer))
  5599. (file-name-coding-system nnmail-pathname-coding-system)
  5600. (coding gnus-article-save-coding-system)
  5601. (coding-system-for-read (if coding
  5602. nil ;; Rely on the coding cookie.
  5603. mm-text-coding-system))
  5604. (coding-system-for-write (or coding
  5605. mm-text-coding-system-for-write
  5606. mm-text-coding-system))
  5607. (exists (file-exists-p file-name)))
  5608. (with-temp-buffer
  5609. (when exists
  5610. (insert-file-contents file-name)
  5611. (goto-char (point-min))
  5612. ;; Remove the existing coding cookie.
  5613. (when (looking-at "X-Gnus-Coding-System: .+\n\n")
  5614. (delete-region (match-beginning 0) (match-end 0))))
  5615. (goto-char (point-max))
  5616. (insert-buffer-substring artbuf)
  5617. ;; Append newline at end of the buffer as separator, and then
  5618. ;; save it to file.
  5619. (goto-char (point-max))
  5620. (insert "\n")
  5621. (when coding
  5622. ;; If the coding system is not suitable to encode the text,
  5623. ;; ask a user for a proper one.
  5624. (when (fboundp 'select-safe-coding-system)
  5625. (setq coding (coding-system-base
  5626. (save-window-excursion
  5627. (select-safe-coding-system (point-min) (point-max)
  5628. coding))))
  5629. (setq coding-system-for-write
  5630. (or (cdr (assq coding '((mule-utf-8 . utf-8))))
  5631. coding)))
  5632. (goto-char (point-min))
  5633. ;; Add the coding cookie.
  5634. (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
  5635. coding-system-for-write)))
  5636. (if exists
  5637. (progn
  5638. (write-region (point-min) (point-max) file-name nil 'no-message)
  5639. (message "Appended to %s" file-name))
  5640. (write-region (point-min) (point-max) file-name))))
  5641. t)
  5642. (defun gnus-narrow-to-page (&optional arg)
  5643. "Narrow the article buffer to a page.
  5644. If given a numerical ARG, move forward ARG pages."
  5645. (interactive "P")
  5646. (setq arg (if arg (prefix-numeric-value arg) 0))
  5647. (with-current-buffer gnus-article-buffer
  5648. (widen)
  5649. ;; Remove any old next/prev buttons.
  5650. (when (gnus-visual-p 'page-marker)
  5651. (let ((inhibit-read-only t))
  5652. (gnus-remove-text-with-property 'gnus-prev)
  5653. (gnus-remove-text-with-property 'gnus-next)))
  5654. (let (st nd pt)
  5655. (when (save-excursion
  5656. (cond ((< arg 0)
  5657. (if (re-search-backward page-delimiter nil 'move (abs arg))
  5658. (prog1
  5659. (setq nd (match-beginning 0)
  5660. pt nd)
  5661. (when (re-search-backward page-delimiter nil t)
  5662. (setq st (match-end 0))))
  5663. (when (re-search-forward page-delimiter nil t)
  5664. (setq nd (match-beginning 0)
  5665. pt (point-min)))))
  5666. ((> arg 0)
  5667. (if (re-search-forward page-delimiter nil 'move arg)
  5668. (prog1
  5669. (setq st (match-end 0)
  5670. pt st)
  5671. (when (re-search-forward page-delimiter nil t)
  5672. (setq nd (match-beginning 0))))
  5673. (when (re-search-backward page-delimiter nil t)
  5674. (setq st (match-end 0)
  5675. pt (point-max)))))
  5676. (t
  5677. (when (re-search-backward page-delimiter nil t)
  5678. (goto-char (setq st (match-end 0))))
  5679. (when (re-search-forward page-delimiter nil t)
  5680. (setq nd (match-beginning 0)))
  5681. (or st nd))))
  5682. (setq gnus-page-broken t)
  5683. (when pt (goto-char pt))
  5684. (narrow-to-region (or st (point-min)) (or nd (point-max)))
  5685. (when (gnus-visual-p 'page-marker)
  5686. (save-excursion
  5687. (when nd
  5688. (goto-char nd)
  5689. (gnus-insert-next-page-button))
  5690. (when st
  5691. (goto-char st)
  5692. (gnus-insert-prev-page-button))))))))
  5693. ;; Article mode commands
  5694. (defun gnus-article-goto-next-page ()
  5695. "Show the next page of the article."
  5696. (interactive)
  5697. (when (gnus-article-next-page)
  5698. (goto-char (point-min))
  5699. (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
  5700. (defun gnus-article-goto-prev-page ()
  5701. "Show the previous page of the article."
  5702. (interactive)
  5703. (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
  5704. (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
  5705. (gnus-article-prev-page nil)))
  5706. ;; This is cleaner but currently breaks `gnus-pick-mode':
  5707. ;;
  5708. ;; (defun gnus-article-goto-next-page ()
  5709. ;; "Show the next page of the article."
  5710. ;; (interactive)
  5711. ;; (gnus-eval-in-buffer-window gnus-summary-buffer
  5712. ;; (gnus-summary-next-page)))
  5713. ;;
  5714. ;; (defun gnus-article-goto-prev-page ()
  5715. ;; "Show the next page of the article."
  5716. ;; (interactive)
  5717. ;; (gnus-eval-in-buffer-window gnus-summary-buffer
  5718. ;; (gnus-summary-prev-page)))
  5719. (defun gnus-article-next-page (&optional lines)
  5720. "Show the next page of the current article.
  5721. If end of article, return non-nil. Otherwise return nil.
  5722. Argument LINES specifies lines to be scrolled up."
  5723. (interactive "p")
  5724. (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
  5725. (if (and (not (and gnus-article-over-scroll
  5726. (> (count-lines (window-start) (point-max))
  5727. (if (featurep 'xemacs)
  5728. (or lines (1- (window-height)))
  5729. (+ (or lines (1- (window-height))) scroll-margin)))))
  5730. (save-excursion
  5731. (end-of-line)
  5732. (and (pos-visible-in-window-p) ;Not continuation line.
  5733. (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
  5734. ;; Nothing in this page.
  5735. (if (or (not gnus-page-broken)
  5736. (save-excursion
  5737. (save-restriction
  5738. (widen)
  5739. (forward-line)
  5740. (eobp)))) ;Real end-of-buffer?
  5741. (progn
  5742. (when gnus-article-over-scroll
  5743. (gnus-article-next-page-1 lines))
  5744. t) ;Nothing more.
  5745. (gnus-narrow-to-page 1) ;Go to next page.
  5746. nil)
  5747. ;; More in this page.
  5748. (gnus-article-next-page-1 lines)
  5749. nil))
  5750. (defmacro gnus-article-beginning-of-window ()
  5751. "Move point to the beginning of the window.
  5752. In Emacs, the point is placed at the line number which `scroll-margin'
  5753. specifies."
  5754. (if (featurep 'xemacs)
  5755. '(move-to-window-line 0)
  5756. '(move-to-window-line
  5757. (min (max 0 scroll-margin)
  5758. (max 1 (- (window-height)
  5759. (if mode-line-format 1 0)
  5760. (if header-line-format 1 0)
  5761. 2))))))
  5762. (defun gnus-article-next-page-1 (lines)
  5763. (unless (featurep 'xemacs)
  5764. ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
  5765. ;; too many number of lines if `scroll-margin' is set as two or greater.
  5766. (when (and (numberp lines)
  5767. (> lines 0)
  5768. (> scroll-margin 0))
  5769. (setq lines (min lines
  5770. (max 0 (- (count-lines (window-start) (point-max))
  5771. scroll-margin))))))
  5772. (condition-case ()
  5773. (let ((scroll-in-place nil))
  5774. (scroll-up lines))
  5775. (end-of-buffer
  5776. ;; Long lines may cause an end-of-buffer error.
  5777. (goto-char (point-max))))
  5778. (gnus-article-beginning-of-window))
  5779. (defun gnus-article-prev-page (&optional lines)
  5780. "Show previous page of current article.
  5781. Argument LINES specifies lines to be scrolled down."
  5782. (interactive "p")
  5783. (move-to-window-line 0)
  5784. (if (and gnus-page-broken
  5785. (bobp)
  5786. (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
  5787. (progn
  5788. (gnus-narrow-to-page -1) ;Go to previous page.
  5789. (goto-char (point-max))
  5790. (recenter (if gnus-article-over-scroll
  5791. (if lines
  5792. (max (if (featurep 'xemacs)
  5793. lines
  5794. (+ lines scroll-margin))
  5795. 3)
  5796. (- (window-height) 2))
  5797. -1)))
  5798. (prog1
  5799. (condition-case ()
  5800. (let ((scroll-in-place nil))
  5801. (scroll-down lines))
  5802. (beginning-of-buffer
  5803. (goto-char (point-min))))
  5804. (gnus-article-beginning-of-window))))
  5805. (defun gnus-article-only-boring-p ()
  5806. "Decide whether there is only boring text remaining in the article.
  5807. Something \"interesting\" is a word of at least two letters that does
  5808. not have a face in `gnus-article-boring-faces'."
  5809. (when (and gnus-article-skip-boring
  5810. (boundp 'gnus-article-boring-faces)
  5811. (symbol-value 'gnus-article-boring-faces))
  5812. (save-excursion
  5813. (let ((inhibit-point-motion-hooks t))
  5814. (catch 'only-boring
  5815. (while (re-search-forward "\\b\\w\\w" nil t)
  5816. (forward-char -1)
  5817. (when (not (gnus-intersection
  5818. (gnus-faces-at (point))
  5819. (symbol-value 'gnus-article-boring-faces)))
  5820. (throw 'only-boring nil)))
  5821. (throw 'only-boring t))))))
  5822. (defun gnus-article-refer-article ()
  5823. "Read article specified by message-id around point."
  5824. (interactive)
  5825. (save-excursion
  5826. (re-search-backward "[ \t]\\|^" (point-at-bol) t)
  5827. (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
  5828. (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
  5829. (let ((msg-id (concat "<" (match-string 0) ">")))
  5830. (set-buffer gnus-summary-buffer)
  5831. (gnus-summary-refer-article msg-id))
  5832. (error "No references around point"))))
  5833. (defun gnus-article-show-summary ()
  5834. "Reconfigure windows to show summary buffer."
  5835. (interactive)
  5836. (if (not (gnus-buffer-live-p gnus-summary-buffer))
  5837. (error "There is no summary buffer for this article buffer")
  5838. (gnus-article-set-globals)
  5839. (gnus-configure-windows 'article)
  5840. (gnus-summary-goto-subject gnus-current-article)
  5841. (gnus-summary-position-point)))
  5842. (defun gnus-article-describe-briefly ()
  5843. "Describe article mode commands briefly."
  5844. (interactive)
  5845. (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
  5846. (defun gnus-article-check-buffer ()
  5847. "Beep if not in an article buffer."
  5848. (unless (equal major-mode 'gnus-article-mode)
  5849. (error "Command invoked outside of a Gnus article buffer")))
  5850. (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
  5851. "Read a summary buffer key sequence and execute it from the article buffer."
  5852. (interactive "P")
  5853. (gnus-article-check-buffer)
  5854. (let ((nosaves
  5855. '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
  5856. "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
  5857. "=" "^" "\M-^" "|"))
  5858. (nosave-but-article
  5859. '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
  5860. "An" "Ap" [?A (meta return)] [?A delete]))
  5861. (nosave-in-article
  5862. '("AS" "\C-d"))
  5863. (up-to-top
  5864. '("n" "Gn" "p" "Gp"))
  5865. keys new-sum-point)
  5866. (with-current-buffer gnus-article-current-summary
  5867. (let (gnus-pick-mode)
  5868. (setq unread-command-events (nconc unread-command-events
  5869. (list (or key last-command-event)))
  5870. keys (if (featurep 'xemacs)
  5871. (events-to-keys (read-key-sequence nil t))
  5872. (read-key-sequence nil t)))))
  5873. (message "")
  5874. (cond
  5875. ((eq (aref keys (1- (length keys))) ?\C-h)
  5876. (gnus-article-describe-bindings (substring keys 0 -1)))
  5877. ((or (member keys nosaves)
  5878. (member keys nosave-but-article)
  5879. (member keys nosave-in-article))
  5880. (let (func)
  5881. (save-window-excursion
  5882. (pop-to-buffer gnus-article-current-summary)
  5883. ;; We disable the pick minor mode commands.
  5884. (let (gnus-pick-mode)
  5885. (setq func (key-binding keys t))))
  5886. (if (or (not func)
  5887. (numberp func))
  5888. (ding)
  5889. (unless (member keys nosave-in-article)
  5890. (set-buffer gnus-article-current-summary))
  5891. (call-interactively func)
  5892. (setq new-sum-point (point)))
  5893. (when (member keys nosave-but-article)
  5894. (pop-to-buffer gnus-article-buffer))))
  5895. (t
  5896. ;; These commands should restore window configuration.
  5897. (let ((obuf (current-buffer))
  5898. (owin (current-window-configuration))
  5899. win func in-buffer selected new-sum-start new-sum-hscroll err)
  5900. (cond (not-restore-window
  5901. (pop-to-buffer gnus-article-current-summary)
  5902. (setq win (selected-window)))
  5903. ((setq win (get-buffer-window gnus-article-current-summary))
  5904. (select-window win))
  5905. (t
  5906. (let ((summary-buffer gnus-article-current-summary))
  5907. (gnus-configure-windows 'article)
  5908. (unless (setq win (get-buffer-window summary-buffer 'visible))
  5909. (let ((gnus-buffer-configuration
  5910. '((article ((vertical 1.0
  5911. (summary 0.25 point)
  5912. (article 1.0)))))))
  5913. (gnus-configure-windows 'article))
  5914. (setq win (get-buffer-window summary-buffer 'visible)))
  5915. (gnus-select-frame-set-input-focus (window-frame win))
  5916. (select-window win))))
  5917. (setq in-buffer (current-buffer))
  5918. ;; We disable the pick minor mode commands.
  5919. (if (and (setq func (let (gnus-pick-mode)
  5920. (key-binding keys t)))
  5921. (functionp func)
  5922. (condition-case code
  5923. (progn
  5924. (call-interactively func)
  5925. t)
  5926. (error
  5927. (setq err code)
  5928. nil)))
  5929. (progn
  5930. (when (eq win (selected-window))
  5931. (setq new-sum-point (point)
  5932. new-sum-start (window-start win)
  5933. new-sum-hscroll (window-hscroll win)))
  5934. (when (or (eq in-buffer (current-buffer))
  5935. (when (eq obuf (current-buffer))
  5936. (set-buffer in-buffer)
  5937. t))
  5938. (setq selected (gnus-summary-select-article))
  5939. (set-buffer obuf)
  5940. (unless not-restore-window
  5941. (set-window-configuration owin))
  5942. (when (and (eq selected 'old)
  5943. new-sum-point)
  5944. (set-window-start (get-buffer-window (current-buffer))
  5945. 1)
  5946. (set-window-point (get-buffer-window (current-buffer))
  5947. (if (article-goto-body)
  5948. (1- (point))
  5949. (point))))
  5950. (when (and (not not-restore-window)
  5951. new-sum-point
  5952. (window-live-p win)
  5953. (with-current-buffer (window-buffer win)
  5954. (eq major-mode 'gnus-summary-mode)))
  5955. (set-window-point win new-sum-point)
  5956. (set-window-start win new-sum-start)
  5957. (set-window-hscroll win new-sum-hscroll))))
  5958. (set-window-configuration owin)
  5959. (if err
  5960. (signal (car err) (cdr err))
  5961. (ding))))))))
  5962. (defun gnus-article-read-summary-send-keys ()
  5963. (interactive)
  5964. (let ((unread-command-events (list (gnus-character-to-event ?S))))
  5965. (gnus-article-read-summary-keys)))
  5966. (defun gnus-article-describe-key (key)
  5967. "Display documentation of the function invoked by KEY.
  5968. KEY is a string or a vector."
  5969. (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
  5970. (read-key-sequence "Describe key: "))))
  5971. (gnus-article-check-buffer)
  5972. (if (memq (key-binding key t) '(gnus-article-read-summary-keys
  5973. gnus-article-read-summary-send-keys))
  5974. (with-current-buffer gnus-article-current-summary
  5975. (setq unread-command-events
  5976. (if (featurep 'xemacs)
  5977. (append key nil)
  5978. (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
  5979. (list 'meta (- x 128))
  5980. x))
  5981. key)))
  5982. (let ((cursor-in-echo-area t)
  5983. gnus-pick-mode)
  5984. (describe-key (read-key-sequence nil t))))
  5985. (describe-key key)))
  5986. (defun gnus-article-describe-key-briefly (key &optional insert)
  5987. "Display documentation of the function invoked by KEY.
  5988. KEY is a string or a vector."
  5989. (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
  5990. (read-key-sequence "Describe key: "))
  5991. current-prefix-arg))
  5992. (gnus-article-check-buffer)
  5993. (if (memq (key-binding key t) '(gnus-article-read-summary-keys
  5994. gnus-article-read-summary-send-keys))
  5995. (with-current-buffer gnus-article-current-summary
  5996. (setq unread-command-events
  5997. (if (featurep 'xemacs)
  5998. (append key nil)
  5999. (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
  6000. (list 'meta (- x 128))
  6001. x))
  6002. key)))
  6003. (let ((cursor-in-echo-area t)
  6004. gnus-pick-mode)
  6005. (describe-key-briefly (read-key-sequence nil t) insert)))
  6006. (describe-key-briefly key insert)))
  6007. ;;`gnus-agent-mode' in gnus-agent.el will define it.
  6008. (defvar gnus-agent-summary-mode)
  6009. (defvar gnus-draft-mode)
  6010. ;; Calling help-buffer will autoload help-mode.
  6011. (defvar help-xref-stack-item)
  6012. (defun gnus-article-describe-bindings (&optional prefix)
  6013. "Show a list of all defined keys, and their definitions.
  6014. The optional argument PREFIX, if non-nil, should be a key sequence;
  6015. then we display only bindings that start with that prefix."
  6016. (interactive)
  6017. (gnus-article-check-buffer)
  6018. (let ((keymap (copy-keymap gnus-article-mode-map))
  6019. (map (copy-keymap gnus-article-send-map))
  6020. (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
  6021. agent draft)
  6022. (define-key keymap "S" map)
  6023. (define-key map [t] nil)
  6024. (with-current-buffer gnus-article-current-summary
  6025. (set-keymap-parent map (key-binding "S"))
  6026. (let (key def gnus-pick-mode)
  6027. (while sumkeys
  6028. (setq key (pop sumkeys))
  6029. (cond ((and (vectorp key) (= (length key) 1)
  6030. (consp (setq def (aref key 0)))
  6031. (numberp (car def)) (numberp (cdr def)))
  6032. (when (< (max (car def) (cdr def)) 128)
  6033. (setq sumkeys
  6034. (append (mapcar
  6035. #'vector
  6036. (nreverse (gnus-uncompress-range def)))
  6037. sumkeys))))
  6038. ((setq def (key-binding key))
  6039. (unless (eq def 'undefined)
  6040. (define-key keymap key def))))))
  6041. (when (boundp 'gnus-agent-summary-mode)
  6042. (setq agent gnus-agent-summary-mode))
  6043. (when (boundp 'gnus-draft-mode)
  6044. (setq draft gnus-draft-mode)))
  6045. (with-temp-buffer
  6046. (use-local-map keymap)
  6047. (set (make-local-variable 'gnus-agent-summary-mode) agent)
  6048. (set (make-local-variable 'gnus-draft-mode) draft)
  6049. (describe-bindings prefix))
  6050. (let ((item `((lambda (prefix)
  6051. (with-current-buffer ,(current-buffer)
  6052. (gnus-article-describe-bindings prefix)))
  6053. ,prefix)))
  6054. (with-current-buffer (if (fboundp 'help-buffer)
  6055. (let (help-xref-following) (help-buffer))
  6056. "*Help*") ;; Emacs 21
  6057. (setq help-xref-stack-item item)))))
  6058. (defun gnus-article-reply-with-original (&optional wide)
  6059. "Start composing a reply mail to the current message.
  6060. The text in the region will be yanked. If the region isn't active,
  6061. the entire article will be yanked."
  6062. (interactive)
  6063. (let ((article (cdr gnus-article-current))
  6064. contents)
  6065. (if (not (gnus-region-active-p))
  6066. (with-current-buffer gnus-summary-buffer
  6067. (gnus-summary-reply (list (list article)) wide))
  6068. (setq contents (buffer-substring (point) (mark t)))
  6069. ;; Deactivate active regions.
  6070. (when (and (boundp 'transient-mark-mode)
  6071. transient-mark-mode)
  6072. (setq mark-active nil))
  6073. (with-current-buffer gnus-summary-buffer
  6074. (gnus-summary-reply
  6075. (list (list article contents)) wide)))))
  6076. (defun gnus-article-wide-reply-with-original ()
  6077. "Start composing a wide reply mail to the current message.
  6078. The text in the region will be yanked. If the region isn't active,
  6079. the entire article will be yanked."
  6080. (interactive)
  6081. (gnus-article-reply-with-original t))
  6082. (defun gnus-article-followup-with-original ()
  6083. "Compose a followup to the current article.
  6084. The text in the region will be yanked. If the region isn't active,
  6085. the entire article will be yanked."
  6086. (interactive)
  6087. (let ((article (cdr gnus-article-current))
  6088. contents)
  6089. (if (not (gnus-region-active-p))
  6090. (with-current-buffer gnus-summary-buffer
  6091. (gnus-summary-followup (list (list article))))
  6092. (setq contents (buffer-substring (point) (mark t)))
  6093. ;; Deactivate active regions.
  6094. (when (and (boundp 'transient-mark-mode)
  6095. transient-mark-mode)
  6096. (setq mark-active nil))
  6097. (with-current-buffer gnus-summary-buffer
  6098. (gnus-summary-followup
  6099. (list (list article contents)))))))
  6100. (defun gnus-article-hide (&optional arg force)
  6101. "Hide all the gruft in the current article.
  6102. This means that signatures, cited text and (some) headers will be
  6103. hidden.
  6104. If given a prefix, show the hidden text instead."
  6105. (interactive (append (gnus-article-hidden-arg) (list 'force)))
  6106. (gnus-article-hide-headers arg)
  6107. (gnus-article-hide-list-identifiers arg)
  6108. (gnus-article-hide-citation-maybe arg force)
  6109. (gnus-article-hide-signature arg))
  6110. (defun gnus-article-maybe-highlight ()
  6111. "Do some article highlighting if article highlighting is requested."
  6112. (when (gnus-visual-p 'article-highlight 'highlight)
  6113. (gnus-article-highlight-some)))
  6114. (defun gnus-check-group-server ()
  6115. ;; Make sure the connection to the server is alive.
  6116. (unless (gnus-server-opened
  6117. (gnus-find-method-for-group gnus-newsgroup-name))
  6118. (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
  6119. (gnus-request-group gnus-newsgroup-name t)))
  6120. (eval-when-compile
  6121. (autoload 'nneething-get-file-name "nneething"))
  6122. (defun gnus-request-article-this-buffer (article group)
  6123. "Get an article and insert it into this buffer."
  6124. (let (do-update-line sparse-header)
  6125. (prog1
  6126. (save-excursion
  6127. (erase-buffer)
  6128. (gnus-kill-all-overlays)
  6129. (setq group (or group gnus-newsgroup-name))
  6130. ;; Using `gnus-request-article' directly will insert the article into
  6131. ;; `nntp-server-buffer' - so we'll save some time by not having to
  6132. ;; copy it from the server buffer into the article buffer.
  6133. ;; We only request an article by message-id when we do not have the
  6134. ;; headers for it, so we'll have to get those.
  6135. (when (stringp article)
  6136. (gnus-read-header article))
  6137. ;; If the article number is negative, that means that this article
  6138. ;; doesn't belong in this newsgroup (possibly), so we find its
  6139. ;; message-id and request it by id instead of number.
  6140. (when (and (numberp article)
  6141. gnus-summary-buffer
  6142. (get-buffer gnus-summary-buffer)
  6143. (gnus-buffer-exists-p gnus-summary-buffer))
  6144. (with-current-buffer gnus-summary-buffer
  6145. (let ((header (gnus-summary-article-header article)))
  6146. (when (< article 0)
  6147. (cond
  6148. ((memq article gnus-newsgroup-sparse)
  6149. ;; This is a sparse gap article.
  6150. (setq do-update-line article)
  6151. (setq article (mail-header-id header))
  6152. (setq sparse-header (gnus-read-header article))
  6153. (setq gnus-newsgroup-sparse
  6154. (delq article gnus-newsgroup-sparse)))
  6155. ((vectorp header)
  6156. ;; It's a real article.
  6157. (setq article (mail-header-id header)))
  6158. (t
  6159. ;; It is an extracted pseudo-article.
  6160. (setq article 'pseudo)
  6161. (gnus-request-pseudo-article header))))
  6162. (let ((method (gnus-find-method-for-group
  6163. gnus-newsgroup-name)))
  6164. (when (and (eq (car method) 'nneething)
  6165. (vectorp header))
  6166. (let ((dir (nneething-get-file-name
  6167. (mail-header-id header))))
  6168. (when (and (stringp dir)
  6169. (file-directory-p dir))
  6170. (setq article 'nneething)
  6171. (gnus-group-enter-directory dir))))))))
  6172. (cond
  6173. ;; Refuse to select canceled articles.
  6174. ((and (numberp article)
  6175. gnus-summary-buffer
  6176. (get-buffer gnus-summary-buffer)
  6177. (gnus-buffer-exists-p gnus-summary-buffer)
  6178. (eq (cdr (with-current-buffer gnus-summary-buffer
  6179. (assq article gnus-newsgroup-reads)))
  6180. gnus-canceled-mark))
  6181. nil)
  6182. ;; We first check `gnus-original-article-buffer'.
  6183. ((and (get-buffer gnus-original-article-buffer)
  6184. (numberp article)
  6185. (with-current-buffer gnus-original-article-buffer
  6186. (and (equal (car gnus-original-article) group)
  6187. (eq (cdr gnus-original-article) article))))
  6188. ;; `insert-buffer-substring' would incorrectly use the
  6189. ;; equivalent of string-make-multibyte which amount to decoding
  6190. ;; with locale-coding-system, causing failure of
  6191. ;; subsequent decoding.
  6192. (insert (mm-string-to-multibyte
  6193. (with-current-buffer gnus-original-article-buffer
  6194. (buffer-substring (point-min) (point-max)))))
  6195. 'article)
  6196. ;; Check the backlog.
  6197. ((and gnus-keep-backlog
  6198. (gnus-backlog-request-article group article (current-buffer)))
  6199. 'article)
  6200. ;; Check asynchronous pre-fetch.
  6201. ((gnus-async-request-fetched-article group article (current-buffer))
  6202. (gnus-async-prefetch-next group article gnus-summary-buffer)
  6203. (when (and (numberp article) gnus-keep-backlog)
  6204. (gnus-backlog-enter-article group article (current-buffer)))
  6205. 'article)
  6206. ;; Check the cache.
  6207. ((and gnus-use-cache
  6208. (numberp article)
  6209. (gnus-cache-request-article article group))
  6210. 'article)
  6211. ;; Check the agent cache.
  6212. ((gnus-agent-request-article article group)
  6213. 'article)
  6214. ;; Get the article and put into the article buffer.
  6215. ((or (stringp article)
  6216. (numberp article))
  6217. (let ((gnus-override-method gnus-override-method)
  6218. (methods (and (stringp article)
  6219. gnus-refer-article-method))
  6220. (backend (car (gnus-find-method-for-group
  6221. gnus-newsgroup-name)))
  6222. result
  6223. (inhibit-read-only t))
  6224. (if (or (not (listp methods))
  6225. (and (symbolp (car methods))
  6226. (assq (car methods) nnoo-definition-alist)))
  6227. (setq methods (list methods)))
  6228. (when (and (null gnus-override-method)
  6229. methods)
  6230. (setq gnus-override-method (pop methods)))
  6231. (while (not result)
  6232. (when (eq gnus-override-method 'current)
  6233. (setq gnus-override-method
  6234. (with-current-buffer gnus-summary-buffer
  6235. gnus-current-select-method)))
  6236. (erase-buffer)
  6237. (gnus-kill-all-overlays)
  6238. (let ((gnus-newsgroup-name group))
  6239. (gnus-check-group-server))
  6240. (cond
  6241. ((gnus-request-article article group (current-buffer))
  6242. (when (numberp article)
  6243. (gnus-async-prefetch-next group article
  6244. gnus-summary-buffer)
  6245. (when gnus-keep-backlog
  6246. (gnus-backlog-enter-article
  6247. group article (current-buffer))))
  6248. (setq result 'article))
  6249. (methods
  6250. (setq gnus-override-method (pop methods)))
  6251. ((not (string-match "^400 "
  6252. (nnheader-get-report backend)))
  6253. ;; If we get 400 server disconnect, reconnect and
  6254. ;; retry; otherwise, assume the article has expired.
  6255. (setq result 'done))))
  6256. (and (eq result 'article) 'article)))
  6257. ;; It was a pseudo.
  6258. (t article)))
  6259. ;; Associate this article with the current summary buffer.
  6260. (setq gnus-article-current-summary gnus-summary-buffer)
  6261. ;; Take the article from the original article buffer
  6262. ;; and place it in the buffer it's supposed to be in.
  6263. (when (and (get-buffer gnus-article-buffer)
  6264. (equal (buffer-name (current-buffer))
  6265. (buffer-name (get-buffer gnus-article-buffer))))
  6266. (save-excursion
  6267. (if (get-buffer gnus-original-article-buffer)
  6268. (set-buffer gnus-original-article-buffer)
  6269. (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
  6270. (buffer-disable-undo)
  6271. (setq major-mode 'gnus-original-article-mode)
  6272. (setq buffer-read-only t))
  6273. (let ((inhibit-read-only t))
  6274. (erase-buffer)
  6275. (insert-buffer-substring gnus-article-buffer))
  6276. (setq gnus-original-article (cons group article)))
  6277. ;; Decode charsets.
  6278. (run-hooks 'gnus-article-decode-hook)
  6279. ;; Mark article as decoded or not.
  6280. (setq gnus-article-decoded-p gnus-article-decode-hook))
  6281. ;; Update sparse articles.
  6282. (when (and do-update-line
  6283. (or (numberp article)
  6284. (stringp article)))
  6285. (let ((buf (current-buffer)))
  6286. (set-buffer gnus-summary-buffer)
  6287. (gnus-summary-update-article do-update-line sparse-header)
  6288. (gnus-summary-goto-subject do-update-line nil t)
  6289. (set-window-point (gnus-get-buffer-window (current-buffer) t)
  6290. (point))
  6291. (set-buffer buf))))))
  6292. ;;;
  6293. ;;; Article editing
  6294. ;;;
  6295. (defcustom gnus-article-edit-mode-hook nil
  6296. "Hook run in article edit mode buffers."
  6297. :group 'gnus-article-various
  6298. :type 'hook)
  6299. (defvar gnus-article-edit-done-function nil)
  6300. (defvar gnus-article-edit-mode-map nil)
  6301. ;; Should we be using derived.el for this?
  6302. (unless gnus-article-edit-mode-map
  6303. (setq gnus-article-edit-mode-map (make-keymap))
  6304. (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
  6305. (gnus-define-keys gnus-article-edit-mode-map
  6306. "\C-c?" describe-mode
  6307. "\C-c\C-c" gnus-article-edit-done
  6308. "\C-c\C-k" gnus-article-edit-exit
  6309. "\C-c\C-f\C-t" message-goto-to
  6310. "\C-c\C-f\C-o" message-goto-from
  6311. "\C-c\C-f\C-b" message-goto-bcc
  6312. ;;"\C-c\C-f\C-w" message-goto-fcc
  6313. "\C-c\C-f\C-c" message-goto-cc
  6314. "\C-c\C-f\C-s" message-goto-subject
  6315. "\C-c\C-f\C-r" message-goto-reply-to
  6316. "\C-c\C-f\C-n" message-goto-newsgroups
  6317. "\C-c\C-f\C-d" message-goto-distribution
  6318. "\C-c\C-f\C-f" message-goto-followup-to
  6319. "\C-c\C-f\C-m" message-goto-mail-followup-to
  6320. "\C-c\C-f\C-k" message-goto-keywords
  6321. "\C-c\C-f\C-u" message-goto-summary
  6322. "\C-c\C-f\C-i" message-insert-or-toggle-importance
  6323. "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
  6324. "\C-c\C-b" message-goto-body
  6325. "\C-c\C-i" message-goto-signature
  6326. "\C-c\C-t" message-insert-to
  6327. "\C-c\C-n" message-insert-newsgroups
  6328. "\C-c\C-o" message-sort-headers
  6329. "\C-c\C-e" message-elide-region
  6330. "\C-c\C-v" message-delete-not-region
  6331. "\C-c\C-z" message-kill-to-signature
  6332. "\M-\r" message-newline-and-reformat
  6333. "\C-c\C-a" mml-attach-file
  6334. "\C-a" message-beginning-of-line
  6335. "\t" message-tab
  6336. "\M-;" comment-region)
  6337. (gnus-define-keys (gnus-article-edit-wash-map
  6338. "\C-c\C-w" gnus-article-edit-mode-map)
  6339. "f" gnus-article-edit-full-stops))
  6340. (easy-menu-define
  6341. gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
  6342. '("Field"
  6343. ["Fetch To" message-insert-to t]
  6344. ["Fetch Newsgroups" message-insert-newsgroups t]
  6345. "----"
  6346. ["To" message-goto-to t]
  6347. ["From" message-goto-from t]
  6348. ["Subject" message-goto-subject t]
  6349. ["Cc" message-goto-cc t]
  6350. ["Reply-To" message-goto-reply-to t]
  6351. ["Summary" message-goto-summary t]
  6352. ["Keywords" message-goto-keywords t]
  6353. ["Newsgroups" message-goto-newsgroups t]
  6354. ["Followup-To" message-goto-followup-to t]
  6355. ["Mail-Followup-To" message-goto-mail-followup-to t]
  6356. ["Distribution" message-goto-distribution t]
  6357. ["Body" message-goto-body t]
  6358. ["Signature" message-goto-signature t]))
  6359. (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
  6360. "Major mode for editing articles.
  6361. This is an extended text-mode.
  6362. \\{gnus-article-edit-mode-map}"
  6363. (make-local-variable 'gnus-article-edit-done-function)
  6364. (make-local-variable 'gnus-prev-winconf)
  6365. (set (make-local-variable 'font-lock-defaults)
  6366. '(message-font-lock-keywords t))
  6367. (set (make-local-variable 'mail-header-separator) "")
  6368. (set (make-local-variable 'gnus-article-edit-mode) t)
  6369. (easy-menu-add message-mode-field-menu message-mode-map)
  6370. (mml-mode)
  6371. (setq buffer-read-only nil)
  6372. (buffer-enable-undo)
  6373. (widen))
  6374. (defun gnus-article-edit (&optional force)
  6375. "Edit the current article.
  6376. This will have permanent effect only in mail groups.
  6377. If FORCE is non-nil, allow editing of articles even in read-only
  6378. groups."
  6379. (interactive "P")
  6380. (when (and (not force)
  6381. (gnus-group-read-only-p))
  6382. (error "The current newsgroup does not support article editing"))
  6383. (gnus-article-date-original)
  6384. (gnus-article-edit-article
  6385. 'ignore
  6386. `(lambda (no-highlight)
  6387. 'ignore
  6388. (gnus-summary-edit-article-done
  6389. ,(or (mail-header-references gnus-current-headers) "")
  6390. ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
  6391. (defun gnus-article-edit-article (start-func exit-func &optional quiet)
  6392. "Start editing the contents of the current article buffer."
  6393. (let ((winconf (current-window-configuration)))
  6394. (set-buffer gnus-article-buffer)
  6395. (let ((message-auto-save-directory
  6396. ;; Don't associate the article buffer with a draft file.
  6397. nil))
  6398. (gnus-article-edit-mode))
  6399. (funcall start-func)
  6400. (set-buffer-modified-p nil)
  6401. (gnus-configure-windows 'edit-article)
  6402. (setq gnus-article-edit-done-function exit-func)
  6403. (setq gnus-prev-winconf winconf)
  6404. (unless quiet
  6405. (gnus-message 6 "C-c C-c to end edits"))))
  6406. (defun gnus-article-edit-done (&optional arg)
  6407. "Update the article edits and exit."
  6408. (interactive "P")
  6409. (let ((func gnus-article-edit-done-function)
  6410. (buf (current-buffer))
  6411. (start (window-start))
  6412. (p (point))
  6413. (winconf gnus-prev-winconf))
  6414. (widen) ;; Widen it in case that users narrowed the buffer.
  6415. (funcall func arg)
  6416. (set-buffer buf)
  6417. ;; The cache and backlog have to be flushed somewhat.
  6418. (when gnus-keep-backlog
  6419. (gnus-backlog-remove-article
  6420. (car gnus-article-current) (cdr gnus-article-current)))
  6421. ;; Flush original article as well.
  6422. (when (get-buffer gnus-original-article-buffer)
  6423. (with-current-buffer gnus-original-article-buffer
  6424. (setq gnus-original-article nil)))
  6425. (when gnus-use-cache
  6426. (gnus-cache-update-article
  6427. (car gnus-article-current) (cdr gnus-article-current)))
  6428. ;; We remove all text props from the article buffer.
  6429. (kill-all-local-variables)
  6430. (set-text-properties (point-min) (point-max) nil)
  6431. (gnus-article-mode)
  6432. (set-window-configuration winconf)
  6433. (set-buffer buf)
  6434. (set-window-start (get-buffer-window buf) start)
  6435. (set-window-point (get-buffer-window buf) (point)))
  6436. (gnus-summary-show-article))
  6437. (defun gnus-article-edit-exit ()
  6438. "Exit the article editing without updating."
  6439. (interactive)
  6440. (when (or (not (buffer-modified-p))
  6441. (yes-or-no-p "Article modified; kill anyway? "))
  6442. (let ((curbuf (current-buffer))
  6443. (p (point))
  6444. (window-start (window-start)))
  6445. (erase-buffer)
  6446. (if (gnus-buffer-live-p gnus-original-article-buffer)
  6447. (insert-buffer-substring gnus-original-article-buffer))
  6448. (let ((winconf gnus-prev-winconf))
  6449. (kill-all-local-variables)
  6450. (gnus-article-mode)
  6451. (set-window-configuration winconf)
  6452. ;; Tippy-toe some to make sure that point remains where it was.
  6453. (save-current-buffer
  6454. (set-buffer curbuf)
  6455. (set-window-start (get-buffer-window (current-buffer)) window-start)
  6456. (goto-char p))))
  6457. (gnus-summary-show-article)))
  6458. (defun gnus-article-edit-full-stops ()
  6459. "Interactively repair spacing at end of sentences."
  6460. (interactive)
  6461. (save-excursion
  6462. (goto-char (point-min))
  6463. (search-forward-regexp "^$" nil t)
  6464. (let ((case-fold-search nil))
  6465. (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
  6466. ;;;
  6467. ;;; Article highlights
  6468. ;;;
  6469. ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
  6470. ;;; Internal Variables:
  6471. (defcustom gnus-button-url-regexp
  6472. (concat
  6473. "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
  6474. "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
  6475. "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
  6476. (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
  6477. (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
  6478. (punct "!?:;.,"))
  6479. (concat
  6480. "\\(?:"
  6481. ;; Match paired parentheses, e.g. in Wikipedia URLs:
  6482. ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
  6483. "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
  6484. "\\|"
  6485. "[" chars punct "]+" "[" chars "]"
  6486. "\\)"))
  6487. (concat ;; XEmacs 21.4 doesn't support POSIX.
  6488. "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
  6489. "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
  6490. "\\)")
  6491. "Regular expression that matches URLs."
  6492. :group 'gnus-article-buttons
  6493. :type 'regexp)
  6494. (defcustom gnus-button-valid-fqdn-regexp
  6495. message-valid-fqdn-regexp
  6496. "Regular expression that matches a valid FQDN."
  6497. :version "22.1"
  6498. :group 'gnus-article-buttons
  6499. :type 'regexp)
  6500. ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
  6501. (defcustom gnus-button-valid-localpart-regexp
  6502. "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
  6503. "Regular expression that matches a localpart of mail addresses or MIDs."
  6504. :version "22.1"
  6505. :group 'gnus-article-buttons
  6506. :type 'regexp)
  6507. (defcustom gnus-button-man-handler 'manual-entry
  6508. "Function to use for displaying man pages.
  6509. The function must take at least one argument with a string naming the
  6510. man page."
  6511. :version "22.1"
  6512. :type '(choice (function-item :tag "Man" manual-entry)
  6513. (function-item :tag "Woman" woman)
  6514. (function :tag "Other"))
  6515. :group 'gnus-article-buttons)
  6516. (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
  6517. "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
  6518. If the default site is too slow, try to find a CTAN mirror, see
  6519. <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
  6520. the variable `gnus-button-handle-ctan'."
  6521. :version "22.1"
  6522. :group 'gnus-article-buttons
  6523. :link '(custom-manual "(gnus)Group Parameters")
  6524. :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
  6525. (const "http://tug.ctan.org/tex-archive/")
  6526. (const "http://www.dante.de/CTAN/")
  6527. (string :tag "Other")))
  6528. (defcustom gnus-button-ctan-handler 'browse-url
  6529. "Function to use for displaying CTAN links.
  6530. The function must take one argument, the string naming the URL."
  6531. :version "22.1"
  6532. :type '(choice (function-item :tag "Browse Url" browse-url)
  6533. (function :tag "Other"))
  6534. :group 'gnus-article-buttons)
  6535. (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
  6536. "Bogus strings removed from CTAN URLs."
  6537. :version "22.1"
  6538. :group 'gnus-article-buttons
  6539. :type '(choice (const "^/?tex-archive/\\|/")
  6540. (regexp :tag "Other")))
  6541. (defcustom gnus-button-ctan-directory-regexp
  6542. (regexp-opt
  6543. (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
  6544. "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
  6545. "languages" "macros" "nonfree" "obsolete" "support" "systems"
  6546. "tds" "tools" "usergrps" "web") t)
  6547. "Regular expression for ctan directories.
  6548. It should match all directories in the top level of `gnus-ctan-url'."
  6549. :version "22.1"
  6550. :group 'gnus-article-buttons
  6551. :type 'regexp)
  6552. (defcustom gnus-button-mid-or-mail-regexp
  6553. (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
  6554. gnus-button-valid-fqdn-regexp
  6555. ">?\\)\\b")
  6556. "Regular expression that matches a message ID or a mail address."
  6557. :version "22.1"
  6558. :group 'gnus-article-buttons
  6559. :type 'regexp)
  6560. (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
  6561. "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
  6562. Strings like this can be either a message ID or a mail address. If it is one
  6563. of the symbols `mid' or `mail', Gnus will always assume that the string is a
  6564. message ID or a mail address, respectively. If this variable is set to the
  6565. symbol `ask', always query the user what do do. If it is a function, this
  6566. function will be called with the string as its only argument. The function
  6567. must return `mid', `mail', `invalid' or `ask'."
  6568. :version "22.1"
  6569. :group 'gnus-article-buttons
  6570. :type '(choice (function-item :tag "Heuristic function"
  6571. gnus-button-mid-or-mail-heuristic)
  6572. (const ask)
  6573. (const mid)
  6574. (const mail)))
  6575. (defcustom gnus-button-mid-or-mail-heuristic-alist
  6576. '((-10.0 . ".+\\$.+@")
  6577. (-10.0 . "#")
  6578. (-10.0 . "\\*")
  6579. (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
  6580. (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
  6581. (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
  6582. (-1.0 . "^[^a-z]+@")
  6583. ;;
  6584. (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
  6585. (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
  6586. (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
  6587. (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
  6588. ;;
  6589. (-2.0 . "^[0-9]")
  6590. (-1.0 . "^[0-9][0-9]")
  6591. ;;
  6592. ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
  6593. (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
  6594. ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
  6595. (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
  6596. ;;
  6597. (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
  6598. (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
  6599. ;; "[0-9]{8,}.*\@"
  6600. (-3.0
  6601. . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
  6602. ;; "[0-9]{12,}.*\@"
  6603. ;; compensation for TDMA dated mail addresses:
  6604. (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
  6605. ;;
  6606. (-20.0 . "\\.fsf@") ;; Gnus
  6607. (-20.0 . "^slrn")
  6608. (-20.0 . "^Pine")
  6609. (-20.0 . "^alpine\\.")
  6610. (-20.0 . "_-_") ;; Subject change in thread
  6611. ;;
  6612. (-20.0 . "\\.ln@") ;; leafnode
  6613. (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
  6614. (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
  6615. ;;
  6616. ;; (5.0 . "") ;; $local_part_len <= 7
  6617. (10.0 . "^[^0-9]+@")
  6618. (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
  6619. ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
  6620. (3.0 . "\@stud")
  6621. ;;
  6622. (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
  6623. ;;
  6624. (0.5 . "^[A-Z][a-z]")
  6625. (0.5 . "^[A-Z][a-z][a-z]")
  6626. (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
  6627. (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
  6628. "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
  6629. A negative RATE indicates a message IDs, whereas a positive indicates a mail
  6630. address. The REGEXP is processed with `case-fold-search' set to nil."
  6631. :version "22.1"
  6632. :group 'gnus-article-buttons
  6633. :type '(repeat (cons (number :tag "Rate")
  6634. (regexp :tag "Regexp"))))
  6635. (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
  6636. "Guess whether MID-OR-MAIL is a message ID or a mail address.
  6637. Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
  6638. address, `ask' if unsure and `invalid' if the string is invalid."
  6639. (let ((case-fold-search nil)
  6640. (list gnus-button-mid-or-mail-heuristic-alist)
  6641. (result 0) rate regexp lpartlen elem)
  6642. (setq lpartlen
  6643. (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
  6644. (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
  6645. ;; Certain special cases...
  6646. (when (string-match
  6647. (concat
  6648. "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
  6649. "^[0-9]+\\.[0-9]+@compuserve\\|"
  6650. "@public\\.gmane\\.org")
  6651. mid-or-mail)
  6652. (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
  6653. (setq result 'mail))
  6654. (when (string-match "@.*@\\| " mid-or-mail)
  6655. (gnus-message 8 "`%s' is invalid." mid-or-mail)
  6656. (setq result 'invalid))
  6657. ;; Nothing more to do, if result is not a number here...
  6658. (when (numberp result)
  6659. (while list
  6660. (setq elem (car list)
  6661. rate (car elem)
  6662. regexp (cdr elem)
  6663. list (cdr list))
  6664. (when (string-match regexp mid-or-mail)
  6665. (setq result (+ result rate))
  6666. (gnus-message
  6667. 9 "`%s' matched `%s', rate `%s', result `%s'."
  6668. mid-or-mail regexp rate result)))
  6669. (when (<= lpartlen 7)
  6670. (setq result (+ result 5.0))
  6671. (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
  6672. mid-or-mail result))
  6673. (when (>= lpartlen 12)
  6674. (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
  6675. (cond
  6676. ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
  6677. ;; Long local part should contain realname if e-mail address,
  6678. ;; too many digits: message-id.
  6679. ;; $score -= 5.0 + 0.1 * $local_part_len;
  6680. (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
  6681. (setq result (+ result rate))
  6682. (gnus-message
  6683. 9 "Many digits in `%s', rate `%s', result `%s'."
  6684. mid-or-mail rate result))
  6685. ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
  6686. mid-or-mail)
  6687. ;; Too few vowels [^aeiouy]{4,}.*\@
  6688. (setq result (+ result -5.0))
  6689. (gnus-message
  6690. 9 "Few vowels in `%s', rate `%s', result `%s'."
  6691. mid-or-mail -5.0 result))
  6692. (t
  6693. (setq result (+ result 5.0))
  6694. (gnus-message
  6695. 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
  6696. (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
  6697. ;; Maybe we should make this a customizable alist: (condition . 'result)
  6698. (cond
  6699. ((symbolp result) result)
  6700. ;; Now convert number into proper results:
  6701. ((< result -10.0) 'mid)
  6702. ((> result 10.0) 'mail)
  6703. (t 'ask))))
  6704. (defun gnus-button-handle-mid-or-mail (mid-or-mail)
  6705. (let* ((pref gnus-button-prefer-mid-or-mail) guessed
  6706. (url-mid (concat "news" ":" mid-or-mail))
  6707. (url-mailto (concat "mailto" ":" mid-or-mail)))
  6708. (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
  6709. (when (fboundp pref)
  6710. (setq guessed
  6711. ;; get rid of surrounding angles...
  6712. (funcall pref
  6713. (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
  6714. (if (or (eq 'mid guessed) (eq 'mail guessed))
  6715. (setq pref guessed)
  6716. (setq pref 'ask)))
  6717. (if (eq pref 'ask)
  6718. (save-window-excursion
  6719. (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
  6720. (setq pref 'mail)
  6721. (setq pref 'mid))))
  6722. (cond ((eq pref 'mid)
  6723. (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
  6724. (gnus-button-handle-news url-mid))
  6725. ((eq pref 'mail)
  6726. (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
  6727. (gnus-url-mailto url-mailto))
  6728. (t (gnus-message 3 "Invalid string.")))))
  6729. (defun gnus-button-handle-custom (fun arg)
  6730. "Call function FUN on argument ARG.
  6731. Both FUN and ARG are supposed to be strings. ARG will be passed
  6732. as a symbol to FUN."
  6733. (funcall (intern fun)
  6734. (if (string-match "^customize-apropos" fun)
  6735. arg
  6736. (intern arg))))
  6737. (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
  6738. ;; FIXME: Maybe we should merge some of the functions that do quite similar
  6739. ;; stuff?
  6740. (defun gnus-button-handle-describe-function (url)
  6741. "Call `describe-function' when pushing the corresponding URL button."
  6742. (describe-function
  6743. (intern
  6744. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
  6745. (defun gnus-button-handle-describe-variable (url)
  6746. "Call `describe-variable' when pushing the corresponding URL button."
  6747. (describe-variable
  6748. (intern
  6749. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
  6750. (defun gnus-button-handle-symbol (url)
  6751. "Display help on variable or function.
  6752. Calls `describe-variable' or `describe-function'."
  6753. (let ((sym (intern url)))
  6754. (cond
  6755. ((fboundp sym) (describe-function sym))
  6756. ((boundp sym) (describe-variable sym))
  6757. (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
  6758. (defun gnus-button-handle-describe-key (url)
  6759. "Call `describe-key' when pushing the corresponding URL button."
  6760. (let* ((key-string
  6761. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
  6762. (keys (ignore-errors (eval `(kbd ,key-string)))))
  6763. (if keys
  6764. (describe-key keys)
  6765. (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
  6766. (defun gnus-button-handle-apropos (url)
  6767. "Call `apropos' when pushing the corresponding URL button."
  6768. (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6769. (defun gnus-button-handle-apropos-command (url)
  6770. "Call `apropos' when pushing the corresponding URL button."
  6771. (apropos-command
  6772. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6773. (defun gnus-button-handle-apropos-variable (url)
  6774. "Call `apropos' when pushing the corresponding URL button."
  6775. (funcall
  6776. (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
  6777. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6778. (defun gnus-button-handle-apropos-documentation (url)
  6779. "Call `apropos' when pushing the corresponding URL button."
  6780. (funcall
  6781. (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
  6782. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6783. (defun gnus-button-handle-library (url)
  6784. "Call `locate-library' when pushing the corresponding URL button."
  6785. (gnus-message 9 "url=`%s'" url)
  6786. (let* ((lib (locate-library url))
  6787. (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
  6788. (if (not lib)
  6789. (gnus-message 1 "Cannot locale library `%s'." url)
  6790. (find-file-read-only file))))
  6791. (defun gnus-button-handle-ctan (url)
  6792. "Call `browse-url' when pushing a CTAN URL button."
  6793. (funcall
  6794. gnus-button-ctan-handler
  6795. (concat
  6796. gnus-ctan-url
  6797. (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
  6798. (defcustom gnus-button-tex-level 5
  6799. "*Integer that says how many TeX-related buttons Gnus will show.
  6800. The higher the number, the more buttons will appear and the more false
  6801. positives are possible. Note that you can set this variable local to
  6802. specific groups. Setting it higher in TeX groups is probably a good idea.
  6803. See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
  6804. how to set variables in specific groups."
  6805. :version "22.1"
  6806. :group 'gnus-article-buttons
  6807. :link '(custom-manual "(gnus)Group Parameters")
  6808. :type 'integer)
  6809. (defcustom gnus-button-man-level 5
  6810. "*Integer that says how many man-related buttons Gnus will show.
  6811. The higher the number, the more buttons will appear and the more false
  6812. positives are possible. Note that you can set this variable local to
  6813. specific groups. Setting it higher in Unix groups is probably a good idea.
  6814. See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
  6815. how to set variables in specific groups."
  6816. :version "22.1"
  6817. :group 'gnus-article-buttons
  6818. :link '(custom-manual "(gnus)Group Parameters")
  6819. :type 'integer)
  6820. (defcustom gnus-button-emacs-level 5
  6821. "*Integer that says how many emacs-related buttons Gnus will show.
  6822. The higher the number, the more buttons will appear and the more false
  6823. positives are possible. Note that you can set this variable local to
  6824. specific groups. Setting it higher in Emacs or Gnus related groups is
  6825. probably a good idea. See Info node `(gnus)Group Parameters' and the variable
  6826. `gnus-parameters' on how to set variables in specific groups."
  6827. :version "22.1"
  6828. :group 'gnus-article-buttons
  6829. :link '(custom-manual "(gnus)Group Parameters")
  6830. :type 'integer)
  6831. (defcustom gnus-button-message-level 5
  6832. "*Integer that says how many buttons for news or mail messages will appear.
  6833. The higher the number, the more buttons will appear and the more false
  6834. positives are possible."
  6835. ;; mail addresses, MIDs, URLs for news, ...
  6836. :version "22.1"
  6837. :group 'gnus-article-buttons
  6838. :type 'integer)
  6839. (defcustom gnus-button-browse-level 5
  6840. "*Integer that says how many buttons for browsing will appear.
  6841. The higher the number, the more buttons will appear and the more false
  6842. positives are possible."
  6843. ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
  6844. :version "22.1"
  6845. :group 'gnus-article-buttons
  6846. :type 'integer)
  6847. (defcustom gnus-button-alist
  6848. '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
  6849. 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
  6850. ((concat "\\b\\(nntp\\|news\\):\\("
  6851. gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
  6852. 0 t gnus-button-handle-news 2)
  6853. ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
  6854. 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
  6855. ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
  6856. 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
  6857. ;; RFC 2392 (Don't allow `/' in domain part --> CID)
  6858. ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
  6859. 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
  6860. ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
  6861. 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
  6862. ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
  6863. 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
  6864. ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
  6865. 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
  6866. ;; RFC 2368 (The mailto URL scheme)
  6867. ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
  6868. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  6869. ("\\bmailto:\\([^ \n\t]+\\)"
  6870. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  6871. ;; CTAN
  6872. ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
  6873. gnus-button-ctan-directory-regexp
  6874. "[^][>)!;:,'\n\t ]+\\)")
  6875. 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
  6876. ((concat "\\btex-archive/\\("
  6877. gnus-button-ctan-directory-regexp
  6878. "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
  6879. 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
  6880. ((concat
  6881. "\\b\\("
  6882. gnus-button-ctan-directory-regexp
  6883. "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
  6884. 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
  6885. ;; Info Konqueror style <info:/foo/bar baz>.
  6886. ;; Must come before " Gnus home-grown style".
  6887. ("\\binfo://?\\([^'\">\n\t]+\\)"
  6888. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
  6889. ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
  6890. ("\\binfo://\\([^'\">\n\t ]+\\)"
  6891. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
  6892. ;; Info GNOME style <info:foo#bar_baz>
  6893. ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
  6894. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
  6895. ;; Info KDE style <info:(foo)bar baz>
  6896. ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
  6897. 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
  6898. ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
  6899. (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
  6900. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
  6901. ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
  6902. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
  6903. ;; This is custom
  6904. ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
  6905. (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
  6906. ;; Emacs help commands
  6907. ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
  6908. ;; regexp doesn't match arguments containing ` '.
  6909. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
  6910. ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
  6911. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
  6912. ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
  6913. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
  6914. ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
  6915. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
  6916. ;; The following entries may lead to many false positives so don't enable
  6917. ;; them by default (use a high button level).
  6918. ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
  6919. ;; Exclude [.?] for URLs in gmane.emacs.cvs
  6920. 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
  6921. ("`\\([a-z][-a-z0-9]+\\.el\\)'"
  6922. 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
  6923. ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
  6924. 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
  6925. ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
  6926. 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
  6927. ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
  6928. 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
  6929. ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
  6930. 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
  6931. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
  6932. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
  6933. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
  6934. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
  6935. ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
  6936. ;; Unlike the other regexps we really have to require quoting
  6937. ;; here to determine where it ends.
  6938. 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
  6939. ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
  6940. ("<URL: *\\([^\n<>]*\\)>"
  6941. 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
  6942. ;; RFC 2396 (2.4.3., delims) ...
  6943. ("\"URL: *\\([^\n\"]*\\)\""
  6944. 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
  6945. ;; Raw URLs.
  6946. (gnus-button-url-regexp
  6947. 0 (>= gnus-button-browse-level 0) browse-url 0)
  6948. ;; man pages
  6949. ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
  6950. 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
  6951. gnus-button-handle-man 1)
  6952. ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
  6953. ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
  6954. 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
  6955. gnus-button-handle-man 1)
  6956. ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
  6957. ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
  6958. ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
  6959. 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
  6960. ;; Recognizing patches to .el files. This is somewhat obscure,
  6961. ;; but considering the percentage of Gnus users who hack Emacs
  6962. ;; Lisp files...
  6963. ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
  6964. (>= gnus-button-message-level 4) gnus-button-patch 1 2)
  6965. ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
  6966. (>= gnus-button-message-level 4) gnus-button-patch 1 2)
  6967. ;; MID or mail: To avoid too many false positives we don't try to catch
  6968. ;; all kind of allowed MIDs or mail addresses. Domain part must contain
  6969. ;; at least one dot. TLD must contain two or three chars or be a know TLD
  6970. ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
  6971. ;; so that non-ambiguous entries (see above) match first.
  6972. (gnus-button-mid-or-mail-regexp
  6973. 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
  6974. "*Alist of regexps matching buttons in article bodies.
  6975. Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
  6976. REGEXP: is the string (case insensitive) matching text around the button (can
  6977. also be Lisp expression evaluating to a string),
  6978. BUTTON: is the number of the regexp grouping actually matching the button,
  6979. FORM: is a Lisp expression which must eval to true for the button to
  6980. be added,
  6981. CALLBACK: is the function to call when the user push this button, and each
  6982. PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
  6983. CALLBACK can also be a variable, in that case the value of that
  6984. variable it the real callback function."
  6985. :group 'gnus-article-buttons
  6986. :type '(repeat (list (choice regexp variable sexp)
  6987. (integer :tag "Button")
  6988. (sexp :tag "Form")
  6989. (function :tag "Callback")
  6990. (repeat :tag "Par"
  6991. :inline t
  6992. (integer :tag "Regexp group")))))
  6993. (put 'gnus-button-alist 'risky-local-variable t)
  6994. (defcustom gnus-header-button-alist
  6995. '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
  6996. 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
  6997. ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
  6998. 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
  6999. ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
  7000. 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
  7001. ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
  7002. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7003. ("^Subject:" gnus-button-url-regexp
  7004. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7005. ("^[^:]+:" gnus-button-url-regexp
  7006. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7007. ("^OpenPGP:.*url=" gnus-button-url-regexp
  7008. 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
  7009. ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
  7010. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  7011. ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
  7012. 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
  7013. "*Alist of headers and regexps to match buttons in article heads.
  7014. This alist is very similar to `gnus-button-alist', except that each
  7015. alist has an additional HEADER element first in each entry:
  7016. \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
  7017. HEADER is a regexp to match a header. For a fuller explanation, see
  7018. `gnus-button-alist'."
  7019. :group 'gnus-article-buttons
  7020. :group 'gnus-article-headers
  7021. :type '(repeat (list (regexp :tag "Header")
  7022. (choice regexp variable)
  7023. (integer :tag "Button")
  7024. (sexp :tag "Form")
  7025. (function :tag "Callback")
  7026. (repeat :tag "Par"
  7027. :inline t
  7028. (integer :tag "Regexp group")))))
  7029. (put 'gnus-header-button-alist 'risky-local-variable t)
  7030. ;;; Commands:
  7031. (defun gnus-article-push-button (event)
  7032. "Check text under the mouse pointer for a callback function.
  7033. If the text under the mouse pointer has a `gnus-callback' property,
  7034. call it with the value of the `gnus-data' text property."
  7035. (interactive "e")
  7036. (set-buffer (window-buffer (posn-window (event-start event))))
  7037. (let* ((pos (posn-point (event-start event)))
  7038. (data (get-text-property pos 'gnus-data))
  7039. (fun (get-text-property pos 'gnus-callback)))
  7040. (goto-char pos)
  7041. (when fun
  7042. (funcall fun data))))
  7043. (defun gnus-article-press-button ()
  7044. "Check text at point for a callback function.
  7045. If the text at point has a `gnus-callback' property,
  7046. call it with the value of the `gnus-data' text property."
  7047. (interactive)
  7048. (let ((data (get-text-property (point) 'gnus-data))
  7049. (fun (get-text-property (point) 'gnus-callback)))
  7050. (when fun
  7051. (funcall fun data))))
  7052. (defun gnus-article-highlight (&optional force)
  7053. "Highlight current article.
  7054. This function calls `gnus-article-highlight-headers',
  7055. `gnus-article-highlight-citation',
  7056. `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
  7057. do the highlighting. See the documentation for those functions."
  7058. (interactive (list 'force))
  7059. (gnus-article-highlight-headers)
  7060. (gnus-article-highlight-citation force)
  7061. (gnus-article-highlight-signature)
  7062. (gnus-article-add-buttons force)
  7063. (gnus-article-add-buttons-to-head))
  7064. (defun gnus-article-highlight-some (&optional force)
  7065. "Highlight current article.
  7066. This function calls `gnus-article-highlight-headers',
  7067. `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
  7068. do the highlighting. See the documentation for those functions."
  7069. (interactive (list 'force))
  7070. (gnus-article-highlight-headers)
  7071. (gnus-article-highlight-signature)
  7072. (gnus-article-add-buttons))
  7073. (defun gnus-article-highlight-headers ()
  7074. "Highlight article headers as specified by `gnus-header-face-alist'."
  7075. (interactive)
  7076. (gnus-with-article-headers
  7077. (let (regexp header-face field-face from hpoints fpoints)
  7078. (dolist (entry gnus-header-face-alist)
  7079. (goto-char (point-min))
  7080. (setq regexp (concat "^\\("
  7081. (if (string-equal "" (nth 0 entry))
  7082. "[^\t ]"
  7083. (nth 0 entry))
  7084. "\\)")
  7085. header-face (nth 1 entry)
  7086. field-face (nth 2 entry))
  7087. (while (and (re-search-forward regexp nil t)
  7088. (not (eobp)))
  7089. (beginning-of-line)
  7090. (setq from (point))
  7091. (unless (search-forward ":" nil t)
  7092. (forward-char 1))
  7093. (when (and header-face
  7094. (not (memq (point) hpoints)))
  7095. (push (point) hpoints)
  7096. (gnus-put-text-property from (point) 'face header-face))
  7097. (when (and field-face
  7098. (not (memq (setq from (point)) fpoints)))
  7099. (push from fpoints)
  7100. (if (re-search-forward "^[^ \t]" nil t)
  7101. (forward-char -2)
  7102. (goto-char (point-max)))
  7103. (gnus-put-text-property from (point) 'face field-face)))))))
  7104. (defun gnus-article-highlight-signature ()
  7105. "Highlight the signature in an article.
  7106. It does this by highlighting everything after
  7107. `gnus-signature-separator' using the face `gnus-signature'."
  7108. (interactive)
  7109. (gnus-with-article-buffer
  7110. (let ((inhibit-point-motion-hooks t))
  7111. (save-restriction
  7112. (when (and gnus-signature-face
  7113. (gnus-article-narrow-to-signature))
  7114. (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
  7115. 'face gnus-signature-face)
  7116. (widen)
  7117. (gnus-article-search-signature)
  7118. (let ((start (match-beginning 0))
  7119. (end (set-marker (make-marker) (1+ (match-end 0)))))
  7120. (gnus-article-add-button start (1- end) 'gnus-signature-toggle
  7121. end)))))))
  7122. (defun gnus-button-in-region-p (b e prop)
  7123. "Say whether PROP exists in the region."
  7124. (text-property-not-all b e prop nil))
  7125. (defun gnus-article-add-buttons (&optional force)
  7126. "Find external references in the article and make buttons of them.
  7127. \"External references\" are things like Message-IDs and URLs, as
  7128. specified by `gnus-button-alist'."
  7129. (interactive (list 'force))
  7130. (gnus-with-article-buffer
  7131. (let ((inhibit-point-motion-hooks t)
  7132. (case-fold-search t)
  7133. (alist gnus-button-alist)
  7134. beg entry regexp)
  7135. ;; Remove all old markers.
  7136. (let (marker entry new-list)
  7137. (while (setq marker (pop gnus-button-marker-list))
  7138. (if (or (< marker (point-min)) (>= marker (point-max)))
  7139. (push marker new-list)
  7140. (goto-char marker)
  7141. (when (setq entry (gnus-button-entry))
  7142. (put-text-property (match-beginning (nth 1 entry))
  7143. (match-end (nth 1 entry))
  7144. 'gnus-callback nil))
  7145. (set-marker marker nil)))
  7146. (setq gnus-button-marker-list new-list))
  7147. ;; We skip the headers.
  7148. (article-goto-body)
  7149. (setq beg (point))
  7150. (while (setq entry (pop alist))
  7151. (setq regexp (eval (car entry)))
  7152. (goto-char beg)
  7153. (while (re-search-forward regexp nil t)
  7154. (let ((start (match-beginning (nth 1 entry)))
  7155. (end (match-end (nth 1 entry)))
  7156. (from (match-beginning 0)))
  7157. (when (and (or (eq t (nth 2 entry))
  7158. (eval (nth 2 entry)))
  7159. (not (gnus-button-in-region-p
  7160. start end 'gnus-callback)))
  7161. ;; That optional form returned non-nil, so we add the
  7162. ;; button.
  7163. (setq from (set-marker (make-marker) from))
  7164. (push from gnus-button-marker-list)
  7165. (unless (and (eq (car entry) 'gnus-button-url-regexp)
  7166. (gnus-article-extend-url-button from start end))
  7167. (gnus-article-add-button start end
  7168. 'gnus-button-push from)))))))))
  7169. (defun gnus-article-extend-url-button (beg start end)
  7170. "Extend url button if url is folded into two or more lines.
  7171. Return non-nil if button is extended. BEG is a marker that points to
  7172. the beginning position of a text containing url. START and END are
  7173. the endpoints of a url button before it is extended. The concatenated
  7174. url is put as the `gnus-button-url' overlay property on the button."
  7175. (let ((opoint (point))
  7176. (points (list start end))
  7177. url delim regexp)
  7178. (prog1
  7179. (when (and (progn
  7180. (goto-char end)
  7181. (not (looking-at "[\t ]*[\">]")))
  7182. (progn
  7183. (goto-char start)
  7184. (string-match
  7185. "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
  7186. (buffer-substring (point-at-bol) start)))
  7187. (progn
  7188. (setq url (list (buffer-substring start end))
  7189. delim (if (match-beginning 1) ">" "\""))
  7190. (beginning-of-line)
  7191. (setq regexp (concat
  7192. (when (and (looking-at
  7193. message-cite-prefix-regexp)
  7194. (< (match-end 0) start))
  7195. (regexp-quote (match-string 0)))
  7196. "\
  7197. \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
  7198. delim "\\)"))
  7199. (while (progn
  7200. (forward-line 1)
  7201. (and (looking-at regexp)
  7202. (prog1
  7203. (match-beginning 1)
  7204. (push (or (match-string 2)
  7205. (match-string 1))
  7206. url)
  7207. (push (setq end (or (match-end 2)
  7208. (match-end 1)))
  7209. points)
  7210. (push (or (match-beginning 2)
  7211. (match-beginning 1))
  7212. points)))))
  7213. (match-beginning 2)))
  7214. (let (gnus-article-mouse-face widget-mouse-face)
  7215. (while points
  7216. (gnus-article-add-button (pop points) (pop points)
  7217. 'gnus-button-push beg)))
  7218. (let ((overlay (gnus-make-overlay start end)))
  7219. (gnus-overlay-put overlay 'evaporate t)
  7220. (gnus-overlay-put overlay 'gnus-button-url
  7221. (list (mapconcat 'identity (nreverse url) "")))
  7222. (when gnus-article-mouse-face
  7223. (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
  7224. t)
  7225. (goto-char opoint))))
  7226. ;; Add buttons to the head of an article.
  7227. (defun gnus-article-add-buttons-to-head ()
  7228. "Add buttons to the head of the article."
  7229. (interactive)
  7230. (gnus-with-article-headers
  7231. (let (beg end)
  7232. (dolist (entry gnus-header-button-alist)
  7233. ;; Each alist entry.
  7234. (goto-char (point-min))
  7235. (while (re-search-forward (car entry) nil t)
  7236. ;; Each header matching the entry.
  7237. (setq beg (match-beginning 0))
  7238. (setq end (or (and (re-search-forward "^[^ \t]" nil t)
  7239. (match-beginning 0))
  7240. (point-max)))
  7241. (goto-char beg)
  7242. (while (re-search-forward (eval (nth 1 entry)) end t)
  7243. ;; Each match within a header.
  7244. (let* ((entry (cdr entry))
  7245. (start (match-beginning (nth 1 entry)))
  7246. (end (match-end (nth 1 entry)))
  7247. (form (nth 2 entry)))
  7248. (goto-char (match-end 0))
  7249. (when (eval form)
  7250. (gnus-article-add-button
  7251. start end (nth 3 entry)
  7252. (buffer-substring (match-beginning (nth 4 entry))
  7253. (match-end (nth 4 entry)))))))
  7254. (goto-char end))))))
  7255. ;;; External functions:
  7256. (defun gnus-article-add-button (from to fun &optional data)
  7257. "Create a button between FROM and TO with callback FUN and data DATA."
  7258. (when gnus-article-button-face
  7259. (gnus-overlay-put (gnus-make-overlay from to nil t)
  7260. 'face gnus-article-button-face))
  7261. (gnus-add-text-properties
  7262. from to
  7263. (nconc (and gnus-article-mouse-face
  7264. (list gnus-mouse-face-prop gnus-article-mouse-face))
  7265. (list 'gnus-callback fun)
  7266. (and data (list 'gnus-data data))))
  7267. (widget-convert-button 'link from to :action 'gnus-widget-press-button
  7268. :button-keymap gnus-widget-button-keymap))
  7269. ;;; Internal functions:
  7270. (defun gnus-article-set-globals ()
  7271. (with-current-buffer gnus-summary-buffer
  7272. (gnus-set-global-variables)))
  7273. (defun gnus-signature-toggle (end)
  7274. (gnus-with-article-buffer
  7275. (let ((inhibit-point-motion-hooks t))
  7276. (if (text-property-any end (point-max) 'article-type 'signature)
  7277. (progn
  7278. (gnus-delete-wash-type 'signature)
  7279. (gnus-remove-text-properties-when
  7280. 'article-type 'signature end (point-max)
  7281. (cons 'article-type (cons 'signature
  7282. gnus-hidden-properties))))
  7283. (gnus-add-wash-type 'signature)
  7284. (gnus-add-text-properties-when
  7285. 'article-type nil end (point-max)
  7286. (cons 'article-type (cons 'signature
  7287. gnus-hidden-properties)))))
  7288. (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
  7289. (gnus-set-mode-line 'article))))
  7290. (defun gnus-button-entry ()
  7291. ;; Return the first entry in `gnus-button-alist' matching this place.
  7292. (let ((alist gnus-button-alist)
  7293. (entry nil))
  7294. (while alist
  7295. (setq entry (pop alist))
  7296. (if (looking-at (eval (car entry)))
  7297. (setq alist nil)
  7298. (setq entry nil)))
  7299. entry))
  7300. (defun gnus-button-push (marker)
  7301. ;; Push button starting at MARKER.
  7302. (save-excursion
  7303. (goto-char marker)
  7304. (let* ((entry (gnus-button-entry))
  7305. (inhibit-point-motion-hooks t)
  7306. (fun (nth 3 entry))
  7307. (args (or (and (eq (car entry) 'gnus-button-url-regexp)
  7308. (get-char-property marker 'gnus-button-url))
  7309. (mapcar (lambda (group)
  7310. (let ((string (match-string group)))
  7311. (set-text-properties
  7312. 0 (length string) nil string)
  7313. string))
  7314. (nthcdr 4 entry)))))
  7315. (cond
  7316. ((fboundp fun)
  7317. (apply fun args))
  7318. ((and (boundp fun)
  7319. (fboundp (symbol-value fun)))
  7320. (apply (symbol-value fun) args))
  7321. (t
  7322. (gnus-message 1 "You must define `%S' to use this button"
  7323. (cons fun args)))))))
  7324. (defun gnus-parse-news-url (url)
  7325. (let (scheme server port group message-id articles)
  7326. (with-temp-buffer
  7327. (insert url)
  7328. (goto-char (point-min))
  7329. (when (looking-at "\\([A-Za-z]+\\):")
  7330. (setq scheme (match-string 1))
  7331. (goto-char (match-end 0)))
  7332. (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
  7333. (setq server (match-string 1))
  7334. (setq port (if (stringp (match-string 3))
  7335. (string-to-number (match-string 3))
  7336. (match-string 3)))
  7337. (goto-char (match-end 0)))
  7338. (cond
  7339. ((looking-at "\\(.*@.*\\)")
  7340. (setq message-id (match-string 1)))
  7341. ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
  7342. (setq group (match-string 1)
  7343. articles (split-string (match-string 2) "-")))
  7344. ((looking-at "\\([^/]+\\)/?")
  7345. (setq group (match-string 1)))
  7346. (t
  7347. (error "Unknown news URL syntax"))))
  7348. (list scheme server port group message-id articles)))
  7349. (defun gnus-button-handle-news (url)
  7350. "Fetch a news URL."
  7351. (destructuring-bind (scheme server port group message-id articles)
  7352. (gnus-parse-news-url url)
  7353. (cond
  7354. (message-id
  7355. (with-current-buffer gnus-summary-buffer
  7356. (if server
  7357. (let ((gnus-refer-article-method
  7358. (nconc (list (list 'nntp server))
  7359. gnus-refer-article-method))
  7360. (nntp-port-number (or port "nntp")))
  7361. (gnus-message 7 "Fetching %s with %s"
  7362. message-id gnus-refer-article-method)
  7363. (gnus-summary-refer-article message-id))
  7364. (gnus-summary-refer-article message-id))))
  7365. (group
  7366. (gnus-button-fetch-group url)))))
  7367. (defun gnus-button-patch (library line)
  7368. "Visit an Emacs Lisp library LIBRARY on line LINE."
  7369. (interactive)
  7370. (let ((file (locate-library (file-name-nondirectory library))))
  7371. (unless file
  7372. (error "Couldn't find library %s" library))
  7373. (find-file file)
  7374. (goto-char (point-min))
  7375. (forward-line (1- (string-to-number line)))))
  7376. (defun gnus-button-handle-man (url)
  7377. "Fetch a man page."
  7378. (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
  7379. (when (eq gnus-button-man-handler 'woman)
  7380. (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
  7381. (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
  7382. (funcall gnus-button-man-handler url))
  7383. (defun gnus-button-handle-info-url (url)
  7384. "Fetch an info URL."
  7385. (setq url (mm-subst-char-in-string ?+ ?\ url))
  7386. (cond
  7387. ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
  7388. (gnus-info-find-node
  7389. (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
  7390. "Gnus")
  7391. ")" (gnus-url-unhex-string (match-string 2 url)))))
  7392. ((string-match "([^)\"]+)[^\"]+" url)
  7393. (setq url
  7394. (gnus-replace-in-string
  7395. (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
  7396. (gnus-info-find-node url))
  7397. (t (error "Can't parse %s" url))))
  7398. (defun gnus-button-handle-info-url-gnome (url)
  7399. "Fetch GNOME style info URL."
  7400. (setq url (mm-subst-char-in-string ?_ ?\ url))
  7401. (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
  7402. (gnus-info-find-node
  7403. (concat "("
  7404. (gnus-url-unhex-string
  7405. (match-string 1 url))
  7406. ")"
  7407. (or (gnus-url-unhex-string
  7408. (match-string 2 url))
  7409. "Top")))
  7410. (error "Can't parse %s" url)))
  7411. (defun gnus-button-handle-info-url-kde (url)
  7412. "Fetch KDE style info URL."
  7413. (gnus-info-find-node (gnus-url-unhex-string url)))
  7414. ;; (info) will autoload info.el
  7415. (declare-function Info-menu "info" (menu-item &optional fork))
  7416. (declare-function Info-index-next "info" (num))
  7417. (defun gnus-button-handle-info-keystrokes (url)
  7418. "Call `info' when pushing the corresponding URL button."
  7419. ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
  7420. (let (node indx comma)
  7421. (if (string-match
  7422. (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
  7423. "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
  7424. "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET"
  7425. "\\(?:[ \t\n,]*\\)\\)?")
  7426. url)
  7427. (setq node (match-string 2 url)
  7428. indx (match-string 3 url))
  7429. (error "Can't parse %s" url))
  7430. (info)
  7431. (Info-directory)
  7432. (Info-menu node)
  7433. (when (> (length indx) 0)
  7434. (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
  7435. "\\([ \t\n,]*\\)")
  7436. indx)
  7437. (setq comma (match-string 2 indx))
  7438. (setq indx (match-string 1 indx))
  7439. (Info-index indx)
  7440. (when comma
  7441. (dotimes (i (with-temp-buffer
  7442. (insert comma)
  7443. ;; Note: the XEmacs version of `how-many' takes
  7444. ;; no optional argument.
  7445. (goto-char (point-min))
  7446. (how-many ",")))
  7447. (Info-index-next 1)))
  7448. nil)))
  7449. ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
  7450. (declare-function pgg-display-output-buffer "pgg" (start end status))
  7451. (defun gnus-button-openpgp (url)
  7452. "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
  7453. (with-temp-buffer
  7454. (mm-url-insert-file-contents-external url)
  7455. (pgg-snarf-keys-region (point-min) (point-max))
  7456. (pgg-display-output-buffer nil nil nil)))
  7457. (defun gnus-button-message-id (message-id)
  7458. "Fetch MESSAGE-ID."
  7459. (with-current-buffer gnus-summary-buffer
  7460. (gnus-summary-refer-article message-id)))
  7461. (defun gnus-button-fetch-group (address &rest ignore)
  7462. "Fetch GROUP specified by ADDRESS."
  7463. (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
  7464. address)
  7465. ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
  7466. ;; for nntp:// and news://
  7467. (setq address (match-string 3 address)))
  7468. (if (not (string-match "[:/]" address))
  7469. ;; This is just a simple group url.
  7470. (gnus-group-read-ephemeral-group address gnus-select-method)
  7471. (if (not
  7472. (string-match
  7473. "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
  7474. address))
  7475. (error "Can't parse %s" address)
  7476. (gnus-group-read-ephemeral-group
  7477. (match-string 4 address)
  7478. `(nntp ,(match-string 1 address)
  7479. (nntp-address ,(match-string 1 address))
  7480. (nntp-port-number ,(if (match-end 3)
  7481. (match-string 3 address)
  7482. "nntp")))
  7483. nil nil nil
  7484. (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
  7485. (defun gnus-url-parse-query-string (query &optional downcase)
  7486. (let (retval pairs cur key val)
  7487. (setq pairs (split-string query "&"))
  7488. (while pairs
  7489. (setq cur (car pairs)
  7490. pairs (cdr pairs))
  7491. (if (not (string-match "=" cur))
  7492. nil ; Grace
  7493. (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
  7494. val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
  7495. (if downcase
  7496. (setq key (downcase key)))
  7497. (setq cur (assoc key retval))
  7498. (if cur
  7499. (setcdr cur (cons val (cdr cur)))
  7500. (setq retval (cons (list key val) retval)))))
  7501. retval))
  7502. (defun gnus-url-mailto (url)
  7503. ;; Send mail to someone
  7504. (when (string-match "mailto:/*\\(.*\\)" url)
  7505. (setq url (substring url (match-beginning 1) nil)))
  7506. (let (to args subject func)
  7507. (setq args (gnus-url-parse-query-string
  7508. (if (string-match "^\\?" url)
  7509. (substring url 1)
  7510. (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
  7511. (concat "to=" (match-string 1 url) "&"
  7512. (match-string 2 url))
  7513. (concat "to=" url)))
  7514. t)
  7515. subject (cdr-safe (assoc "subject" args)))
  7516. (gnus-msg-mail)
  7517. (while args
  7518. (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
  7519. (if (fboundp func)
  7520. (funcall func)
  7521. (message-position-on-field (caar args)))
  7522. (insert (gnus-replace-in-string
  7523. (mapconcat 'identity (reverse (cdar args)) ", ")
  7524. "\r\n" "\n" t))
  7525. (setq args (cdr args)))
  7526. (if subject
  7527. (message-goto-body)
  7528. (message-goto-subject))))
  7529. (defun gnus-button-embedded-url (address)
  7530. "Activate ADDRESS with `browse-url'."
  7531. (browse-url (gnus-strip-whitespace address)))
  7532. ;;; Next/prev buttons in the article buffer.
  7533. (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
  7534. (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
  7535. (defvar gnus-prev-page-map
  7536. (let ((map (make-sparse-keymap)))
  7537. (define-key map gnus-mouse-2 'gnus-button-prev-page)
  7538. (define-key map "\r" 'gnus-button-prev-page)
  7539. map))
  7540. (defvar gnus-next-page-map
  7541. (let ((map (make-sparse-keymap)))
  7542. (unless (>= emacs-major-version 21)
  7543. ;; XEmacs doesn't care.
  7544. (set-keymap-parent map gnus-article-mode-map))
  7545. (define-key map gnus-mouse-2 'gnus-button-next-page)
  7546. (define-key map "\r" 'gnus-button-next-page)
  7547. map))
  7548. (defun gnus-insert-prev-page-button ()
  7549. (let ((b (point)) e
  7550. (inhibit-read-only t))
  7551. (gnus-eval-format
  7552. gnus-prev-page-line-format nil
  7553. `(keymap ,gnus-prev-page-map
  7554. gnus-prev t
  7555. gnus-callback gnus-article-button-prev-page
  7556. article-type annotation))
  7557. (setq e (if (bolp)
  7558. ;; Exclude a newline.
  7559. (1- (point))
  7560. (point)))
  7561. (when gnus-article-button-face
  7562. (gnus-overlay-put (gnus-make-overlay b e nil t)
  7563. 'face gnus-article-button-face))
  7564. (widget-convert-button
  7565. 'link b e
  7566. :action 'gnus-button-prev-page
  7567. :button-keymap gnus-prev-page-map)))
  7568. (defun gnus-button-next-page (&optional args more-args)
  7569. "Go to the next page."
  7570. (interactive)
  7571. (let ((win (selected-window)))
  7572. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7573. (gnus-article-next-page)
  7574. (select-window win)))
  7575. (defun gnus-button-prev-page (&optional args more-args)
  7576. "Go to the prev page."
  7577. (interactive)
  7578. (let ((win (selected-window)))
  7579. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7580. (gnus-article-prev-page)
  7581. (select-window win)))
  7582. (defun gnus-insert-next-page-button ()
  7583. (let ((b (point)) e
  7584. (inhibit-read-only t))
  7585. (gnus-eval-format gnus-next-page-line-format nil
  7586. `(keymap ,gnus-next-page-map
  7587. gnus-next t
  7588. gnus-callback gnus-article-button-next-page
  7589. article-type annotation))
  7590. (setq e (if (bolp)
  7591. ;; Exclude a newline.
  7592. (1- (point))
  7593. (point)))
  7594. (when gnus-article-button-face
  7595. (gnus-overlay-put (gnus-make-overlay b e nil t)
  7596. 'face gnus-article-button-face))
  7597. (widget-convert-button
  7598. 'link b e
  7599. :action 'gnus-button-next-page
  7600. :button-keymap gnus-next-page-map)))
  7601. (defun gnus-article-button-next-page (arg)
  7602. "Go to the next page."
  7603. (interactive "P")
  7604. (let ((win (selected-window)))
  7605. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7606. (gnus-article-next-page)
  7607. (select-window win)))
  7608. (defun gnus-article-button-prev-page (arg)
  7609. "Go to the prev page."
  7610. (interactive "P")
  7611. (let ((win (selected-window)))
  7612. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7613. (gnus-article-prev-page)
  7614. (select-window win)))
  7615. (defvar gnus-decode-header-methods
  7616. '(mail-decode-encoded-word-region)
  7617. "List of methods used to decode headers.
  7618. This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
  7619. is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
  7620. \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
  7621. whose names match REGEXP.
  7622. For example:
  7623. \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
  7624. mail-decode-encoded-word-region
  7625. (\"chinese\" . rfc1843-decode-region))
  7626. ")
  7627. (defvar gnus-decode-header-methods-cache nil)
  7628. (defun gnus-multi-decode-header (start end)
  7629. "Apply the functions from `gnus-encoded-word-methods' that match."
  7630. (unless (and gnus-decode-header-methods-cache
  7631. (eq gnus-newsgroup-name
  7632. (car gnus-decode-header-methods-cache)))
  7633. (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
  7634. (dolist (x gnus-decode-header-methods)
  7635. (if (symbolp x)
  7636. (nconc gnus-decode-header-methods-cache (list x))
  7637. (if (and gnus-newsgroup-name
  7638. (string-match (car x) gnus-newsgroup-name))
  7639. (nconc gnus-decode-header-methods-cache
  7640. (list (cdr x)))))))
  7641. (let ((xlist gnus-decode-header-methods-cache))
  7642. (pop xlist)
  7643. (save-restriction
  7644. (narrow-to-region start end)
  7645. (while xlist
  7646. (funcall (pop xlist) (point-min) (point-max))))))
  7647. ;;;
  7648. ;;; Treatment top-level handling.
  7649. ;;;
  7650. (defun gnus-treat-article (condition &optional part-number total-parts type)
  7651. (let ((length (- (point-max) (point-min)))
  7652. (alist gnus-treatment-function-alist)
  7653. (article-goto-body-goes-to-point-min-p t)
  7654. (treated-type
  7655. (or (not type)
  7656. (catch 'found
  7657. (let ((list gnus-article-treat-types))
  7658. (while list
  7659. (when (string-match (pop list) type)
  7660. (throw 'found t)))))))
  7661. (highlightp (gnus-visual-p 'article-highlight 'highlight))
  7662. val elem)
  7663. (gnus-run-hooks 'gnus-part-display-hook)
  7664. (dolist (elem alist)
  7665. (setq val
  7666. (save-excursion
  7667. (when (gnus-buffer-live-p gnus-summary-buffer)
  7668. (set-buffer gnus-summary-buffer))
  7669. (symbol-value (car elem))))
  7670. (when (and (or (consp val)
  7671. treated-type)
  7672. (gnus-treat-predicate val)
  7673. (or (not (get (car elem) 'highlight))
  7674. highlightp))
  7675. (save-restriction
  7676. (funcall (cadr elem)))))))
  7677. ;; Dynamic variables.
  7678. (defvar part-number)
  7679. (defvar total-parts)
  7680. (defvar type)
  7681. (defvar condition)
  7682. (defvar length)
  7683. (defun gnus-treat-predicate (val)
  7684. (cond
  7685. ((null val)
  7686. nil)
  7687. (condition
  7688. (eq condition val))
  7689. ((and (listp val)
  7690. (stringp (car val)))
  7691. (apply 'gnus-or (mapcar `(lambda (s)
  7692. (string-match s ,(or gnus-newsgroup-name "")))
  7693. val)))
  7694. ((listp val)
  7695. (let ((pred (pop val)))
  7696. (cond
  7697. ((eq pred 'or)
  7698. (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
  7699. ((eq pred 'and)
  7700. (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
  7701. ((eq pred 'not)
  7702. (not (gnus-treat-predicate (car val))))
  7703. ((eq pred 'typep)
  7704. (equal (car val) type))
  7705. (t
  7706. (error "%S is not a valid predicate" pred)))))
  7707. ((eq val t)
  7708. t)
  7709. ((eq val 'head)
  7710. nil)
  7711. ((eq val 'first)
  7712. (eq part-number 1))
  7713. ((eq val 'last)
  7714. (eq part-number total-parts))
  7715. ((numberp val)
  7716. (< length val))
  7717. (t
  7718. (error "%S is not a valid value" val))))
  7719. (defun gnus-article-encrypt-body (protocol &optional n)
  7720. "Encrypt the article body."
  7721. (interactive
  7722. (list
  7723. (or gnus-article-encrypt-protocol
  7724. (completing-read "Encrypt protocol: "
  7725. gnus-article-encrypt-protocol-alist
  7726. nil t))
  7727. current-prefix-arg))
  7728. ;; User might hit `K E' instead of `K e', so prompt once.
  7729. (when (and gnus-article-encrypt-protocol
  7730. gnus-novice-user)
  7731. (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
  7732. (error "Encrypt aborted")))
  7733. (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
  7734. (unless func
  7735. (error "Can't find the encrypt protocol %s" protocol))
  7736. (if (member gnus-newsgroup-name '("nndraft:delayed"
  7737. "nndraft:drafts"
  7738. "nndraft:queue"))
  7739. (error "Can't encrypt the article in group %s"
  7740. gnus-newsgroup-name))
  7741. (gnus-summary-iterate n
  7742. (with-current-buffer gnus-summary-buffer
  7743. (let ((mail-parse-charset gnus-newsgroup-charset)
  7744. (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
  7745. (summary-buffer gnus-summary-buffer)
  7746. references point)
  7747. (gnus-set-global-variables)
  7748. (when (gnus-group-read-only-p)
  7749. (error "The current newsgroup does not support article encrypt"))
  7750. (gnus-summary-show-article t)
  7751. (setq references
  7752. (or (mail-header-references gnus-current-headers) ""))
  7753. (set-buffer gnus-article-buffer)
  7754. (let* ((inhibit-read-only t)
  7755. (headers
  7756. (mapcar (lambda (field)
  7757. (and (save-restriction
  7758. (message-narrow-to-head)
  7759. (goto-char (point-min))
  7760. (search-forward field nil t))
  7761. (prog2
  7762. (message-narrow-to-field)
  7763. (buffer-string)
  7764. (delete-region (point-min) (point-max))
  7765. (widen))))
  7766. '("Content-Type:" "Content-Transfer-Encoding:"
  7767. "Content-Disposition:"))))
  7768. (message-narrow-to-head)
  7769. (message-remove-header "MIME-Version")
  7770. (goto-char (point-max))
  7771. (setq point (point))
  7772. (insert (apply 'concat headers))
  7773. (widen)
  7774. (narrow-to-region point (point-max))
  7775. (let ((message-options message-options))
  7776. (message-options-set 'message-sender user-mail-address)
  7777. (message-options-set 'message-recipients user-mail-address)
  7778. (message-options-set 'message-sign-encrypt 'not)
  7779. (funcall func))
  7780. (goto-char (point-min))
  7781. (insert "MIME-Version: 1.0\n")
  7782. (widen)
  7783. (gnus-summary-edit-article-done
  7784. references nil summary-buffer t))
  7785. (when gnus-keep-backlog
  7786. (gnus-backlog-remove-article
  7787. (car gnus-article-current) (cdr gnus-article-current)))
  7788. (when (get-buffer gnus-original-article-buffer)
  7789. (with-current-buffer gnus-original-article-buffer
  7790. (setq gnus-original-article nil)))
  7791. (when gnus-use-cache
  7792. (gnus-cache-update-article
  7793. (car gnus-article-current) (cdr gnus-article-current))))))))
  7794. (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
  7795. "The following specs can be used:
  7796. %t The security MIME type
  7797. %i Additional info
  7798. %d Details
  7799. %D Details if button is pressed")
  7800. (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
  7801. "The following specs can be used:
  7802. %t The security MIME type
  7803. %i Additional info
  7804. %d Details
  7805. %D Details if button is pressed")
  7806. (defvar gnus-mime-security-button-line-format-alist
  7807. '((?t gnus-tmp-type ?s)
  7808. (?i gnus-tmp-info ?s)
  7809. (?d gnus-tmp-details ?s)
  7810. (?D gnus-tmp-pressed-details ?s)))
  7811. (defvar gnus-mime-security-button-commands
  7812. '((gnus-article-press-button "\r" "Show Detail")
  7813. (undefined "v")
  7814. (undefined "t")
  7815. (undefined "C")
  7816. (gnus-mime-security-save-part "o" "Save...")
  7817. (undefined "\C-o")
  7818. (undefined "r")
  7819. (undefined "d")
  7820. (undefined "c")
  7821. (undefined "i")
  7822. (undefined "E")
  7823. (undefined "e")
  7824. (undefined "p")
  7825. (gnus-mime-security-pipe-part "|" "Pipe To Command...")
  7826. (undefined ".")))
  7827. (defvar gnus-mime-security-button-map
  7828. (let ((map (make-sparse-keymap)))
  7829. (define-key map gnus-mouse-2 'gnus-article-push-button)
  7830. (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
  7831. (dolist (c gnus-mime-security-button-commands)
  7832. (define-key map (cadr c) (car c)))
  7833. map))
  7834. (easy-menu-define
  7835. gnus-mime-security-button-menu gnus-mime-security-button-map
  7836. "Security button menu."
  7837. `("Security Part"
  7838. ,@(delq nil
  7839. (mapcar (lambda (c)
  7840. (unless (eq (car c) 'undefined)
  7841. (vector (caddr c) (car c) :active t)))
  7842. gnus-mime-security-button-commands))))
  7843. (defun gnus-mime-security-button-menu (event prefix)
  7844. "Construct a context-sensitive menu of security commands."
  7845. (interactive "e\nP")
  7846. (save-window-excursion
  7847. (let ((pos (event-start event)))
  7848. (select-window (posn-window pos))
  7849. (goto-char (posn-point pos))
  7850. (gnus-article-check-buffer)
  7851. (popup-menu gnus-mime-security-button-menu nil prefix))))
  7852. (defvar gnus-mime-security-details-buffer nil)
  7853. (defvar gnus-mime-security-button-pressed nil)
  7854. (defvar gnus-mime-security-show-details-inline t
  7855. "If non-nil, show details in the article buffer.")
  7856. (defun gnus-mime-security-verify-or-decrypt (handle)
  7857. (mm-remove-parts (cdr handle))
  7858. (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
  7859. point (inhibit-read-only t))
  7860. (if region
  7861. (goto-char (car region)))
  7862. (setq point (point))
  7863. (with-current-buffer (mm-handle-multipart-original-buffer handle)
  7864. (let* ((mm-verify-option 'known)
  7865. (mm-decrypt-option 'known)
  7866. (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
  7867. (unless (eq nparts (cdr handle))
  7868. (mm-destroy-parts (cdr handle))
  7869. (setcdr handle nparts))))
  7870. (gnus-mime-display-security handle)
  7871. (when region
  7872. (delete-region (point) (cdr region))
  7873. (set-marker (car region) nil)
  7874. (set-marker (cdr region) nil))
  7875. (goto-char point)))
  7876. (defun gnus-mime-security-show-details (handle)
  7877. (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
  7878. (if (not details)
  7879. (gnus-message 5 "No details.")
  7880. (if gnus-mime-security-show-details-inline
  7881. (let ((gnus-mime-security-button-pressed
  7882. (not (get-text-property (point) 'gnus-mime-details)))
  7883. (gnus-mime-security-button-line-format
  7884. (get-text-property (point) 'gnus-line-format))
  7885. (inhibit-read-only t))
  7886. (forward-char -1)
  7887. (while (eq (get-text-property (point) 'gnus-line-format)
  7888. gnus-mime-security-button-line-format)
  7889. (forward-char -1))
  7890. (forward-char)
  7891. (save-restriction
  7892. (narrow-to-region (point) (point))
  7893. (gnus-insert-mime-security-button handle))
  7894. (delete-region (point)
  7895. (or (text-property-not-all
  7896. (point) (point-max)
  7897. 'gnus-line-format
  7898. gnus-mime-security-button-line-format)
  7899. (point-max))))
  7900. ;; Not inlined.
  7901. (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
  7902. (with-current-buffer gnus-mime-security-details-buffer
  7903. (erase-buffer)
  7904. t)
  7905. (setq gnus-mime-security-details-buffer
  7906. (gnus-get-buffer-create "*MIME Security Details*")))
  7907. (with-current-buffer gnus-mime-security-details-buffer
  7908. (insert details)
  7909. (goto-char (point-min)))
  7910. (pop-to-buffer gnus-mime-security-details-buffer)))))
  7911. (defun gnus-mime-security-press-button (handle)
  7912. (save-excursion
  7913. (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
  7914. (gnus-mime-security-show-details handle)
  7915. (gnus-mime-security-verify-or-decrypt handle))))
  7916. (defun gnus-insert-mime-security-button (handle &optional displayed)
  7917. (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
  7918. (gnus-tmp-type
  7919. (concat
  7920. (or (nth 2 (assoc protocol mm-verify-function-alist))
  7921. (nth 2 (assoc protocol mm-decrypt-function-alist))
  7922. "Unknown")
  7923. (if (equal (car handle) "multipart/signed")
  7924. " Signed" " Encrypted")
  7925. " Part"))
  7926. (gnus-tmp-info
  7927. (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
  7928. "Undecided"))
  7929. (gnus-tmp-details
  7930. (mm-handle-multipart-ctl-parameter handle 'gnus-details))
  7931. gnus-tmp-pressed-details
  7932. b e)
  7933. (setq gnus-tmp-details
  7934. (if gnus-tmp-details
  7935. (concat "\n" gnus-tmp-details)
  7936. ""))
  7937. (setq gnus-tmp-pressed-details
  7938. (if gnus-mime-security-button-pressed gnus-tmp-details ""))
  7939. (unless (bolp)
  7940. (insert "\n"))
  7941. (setq b (point))
  7942. (gnus-eval-format
  7943. gnus-mime-security-button-line-format
  7944. gnus-mime-security-button-line-format-alist
  7945. `(keymap ,gnus-mime-security-button-map
  7946. gnus-callback gnus-mime-security-press-button
  7947. gnus-line-format ,gnus-mime-security-button-line-format
  7948. gnus-mime-details ,gnus-mime-security-button-pressed
  7949. article-type annotation
  7950. gnus-data ,handle))
  7951. (setq e (if (bolp)
  7952. ;; Exclude a newline.
  7953. (1- (point))
  7954. (point)))
  7955. (when gnus-article-button-face
  7956. (gnus-overlay-put (gnus-make-overlay b e nil t)
  7957. 'face gnus-article-button-face))
  7958. (widget-convert-button
  7959. 'link b e
  7960. :mime-handle handle
  7961. :action 'gnus-widget-press-button
  7962. :button-keymap gnus-mime-security-button-map
  7963. :help-echo
  7964. (lambda (widget/window &optional overlay pos)
  7965. ;; Needed to properly clear the message due to a bug in
  7966. ;; wid-edit (XEmacs only).
  7967. (when (boundp 'help-echo-owns-message)
  7968. (setq help-echo-owns-message t))
  7969. (format
  7970. "%S: show detail; %S: more options"
  7971. (aref gnus-mouse-2 0)
  7972. (aref gnus-down-mouse-3 0))))))
  7973. (defun gnus-mime-display-security (handle)
  7974. (save-restriction
  7975. (narrow-to-region (point) (point))
  7976. (unless (gnus-unbuttonized-mime-type-p (car handle))
  7977. (gnus-insert-mime-security-button handle))
  7978. (gnus-mime-display-part (cadr handle))
  7979. (unless (bolp)
  7980. (insert "\n"))
  7981. (unless (gnus-unbuttonized-mime-type-p (car handle))
  7982. (let ((gnus-mime-security-button-line-format
  7983. gnus-mime-security-button-end-line-format))
  7984. (gnus-insert-mime-security-button handle)))
  7985. (mm-set-handle-multipart-parameter
  7986. handle 'gnus-region
  7987. (cons (set-marker (make-marker) (point-min))
  7988. (set-marker (make-marker) (point-max))))
  7989. (goto-char (point-max))))
  7990. (defun gnus-mime-security-run-function (function)
  7991. "Run FUNCTION with the security part under point."
  7992. (gnus-article-check-buffer)
  7993. (let ((data (get-text-property (point) 'gnus-data))
  7994. buffer handle)
  7995. (when (and (stringp (car-safe data))
  7996. (setq buffer (mm-handle-multipart-original-buffer data))
  7997. (setq handle (cadr data)))
  7998. (if (bufferp (mm-handle-buffer handle))
  7999. (progn
  8000. (setq handle (cons buffer (copy-sequence (cdr handle))))
  8001. (mm-handle-set-undisplayer handle nil))
  8002. (setq handle (mm-make-handle
  8003. buffer
  8004. (mm-handle-multipart-ctl-parameter handle 'protocol)
  8005. nil nil nil nil nil nil)))
  8006. (funcall function handle))))
  8007. (defun gnus-mime-security-save-part ()
  8008. "Save the security part under point."
  8009. (interactive)
  8010. (gnus-mime-security-run-function 'mm-save-part))
  8011. (defun gnus-mime-security-pipe-part ()
  8012. "Pipe the security part under point to a process."
  8013. (interactive)
  8014. (gnus-mime-security-run-function 'mm-pipe-part))
  8015. (gnus-ems-redefine)
  8016. (provide 'gnus-art)
  8017. (run-hooks 'gnus-art-load-hook)
  8018. ;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
  8019. ;;; gnus-art.el ends here