PageRenderTime 107ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 2ms

/lisp/gnus/gnus-art.el

http://github.com/davidswelt/aquamacs-emacs
Emacs Lisp | 9035 lines | 7925 code | 629 blank | 481 comment | 121 complexity | 30dd8ce4a54c8af6353cb17adf8e1e7e MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, GPL-2.0, AGPL-3.0
  1. ;;; gnus-art.el --- article mode commands for Gnus
  2. ;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
  3. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  4. ;; Keywords: news
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. (eval-when-compile
  19. (require 'cl))
  20. (defvar tool-bar-map)
  21. (defvar w3m-minor-mode-map)
  22. (require 'gnus)
  23. (require 'gnus-sum)
  24. (require 'gnus-spec)
  25. (require 'gnus-int)
  26. (require 'gnus-win)
  27. (require 'mm-bodies)
  28. (require 'mail-parse)
  29. (require 'mm-decode)
  30. (require 'mm-view)
  31. (require 'wid-edit)
  32. (require 'mm-uu)
  33. (require 'message)
  34. (require 'mouse)
  35. (autoload 'gnus-msg-mail "gnus-msg" nil t)
  36. (autoload 'gnus-button-mailto "gnus-msg")
  37. (autoload 'gnus-button-reply "gnus-msg" nil t)
  38. (autoload 'parse-time-string "parse-time" nil nil)
  39. (autoload 'ansi-color-apply-on-region "ansi-color")
  40. (autoload 'mm-url-insert-file-contents-external "mm-url")
  41. (autoload 'mm-extern-cache-contents "mm-extern")
  42. (autoload 'url-expand-file-name "url-expand")
  43. (defgroup gnus-article nil
  44. "Article display."
  45. :link '(custom-manual "(gnus)Article Buffer")
  46. :group 'gnus)
  47. (defgroup gnus-article-treat nil
  48. "Treating article parts."
  49. :link '(custom-manual "(gnus)Article Hiding")
  50. :group 'gnus-article)
  51. (defgroup gnus-article-hiding nil
  52. "Hiding article parts."
  53. :link '(custom-manual "(gnus)Article Hiding")
  54. :group 'gnus-article)
  55. (defgroup gnus-article-highlight nil
  56. "Article highlighting."
  57. :link '(custom-manual "(gnus)Article Highlighting")
  58. :group 'gnus-article
  59. :group 'gnus-visual)
  60. (defgroup gnus-article-signature nil
  61. "Article signatures."
  62. :link '(custom-manual "(gnus)Article Signature")
  63. :group 'gnus-article)
  64. (defgroup gnus-article-headers nil
  65. "Article headers."
  66. :link '(custom-manual "(gnus)Hiding Headers")
  67. :group 'gnus-article)
  68. (defgroup gnus-article-washing nil
  69. "Special commands on articles."
  70. :link '(custom-manual "(gnus)Article Washing")
  71. :group 'gnus-article)
  72. (defgroup gnus-article-emphasis nil
  73. "Fontisizing articles."
  74. :link '(custom-manual "(gnus)Article Fontisizing")
  75. :group 'gnus-article)
  76. (defgroup gnus-article-saving nil
  77. "Saving articles."
  78. :link '(custom-manual "(gnus)Saving Articles")
  79. :group 'gnus-article)
  80. (defgroup gnus-article-mime nil
  81. "Worshiping the MIME wonder."
  82. :link '(custom-manual "(gnus)Using MIME")
  83. :group 'gnus-article)
  84. (defgroup gnus-article-buttons nil
  85. "Pushable buttons in the article buffer."
  86. :link '(custom-manual "(gnus)Article Buttons")
  87. :group 'gnus-article)
  88. (defgroup gnus-article-various nil
  89. "Other article options."
  90. :link '(custom-manual "(gnus)Misc Article")
  91. :group 'gnus-article)
  92. (defcustom gnus-ignored-headers
  93. (mapcar
  94. (lambda (header)
  95. (concat "^" header ":"))
  96. '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
  97. "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
  98. "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
  99. "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
  100. "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
  101. "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
  102. "X-Attribution" "X-Originating-IP" "Delivered-To"
  103. "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
  104. "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
  105. "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
  106. "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
  107. "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
  108. "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
  109. "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
  110. "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
  111. "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
  112. "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
  113. "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
  114. "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
  115. "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
  116. "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
  117. "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
  118. "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
  119. "List-[A-Za-z]+" "X-Listprocessor-Version"
  120. "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
  121. "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
  122. "X-Received" "Content-length" "X-precedence"
  123. "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
  124. "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
  125. "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
  126. "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
  127. "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
  128. "X-Content-length" "X-Posting-Agent" "Original-Received"
  129. "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
  130. "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
  131. "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
  132. "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
  133. "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
  134. "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
  135. "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
  136. "Envelope-Sender" "Envelope-Recipients"))
  137. "*All headers that start with this regexp will be hidden.
  138. This variable can also be a list of regexps of headers to be ignored.
  139. If `gnus-visible-headers' is non-nil, this variable will be ignored."
  140. :type '(choice regexp
  141. (repeat regexp))
  142. :group 'gnus-article-hiding)
  143. (defcustom gnus-visible-headers
  144. "^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:"
  145. "*All headers that do not match this regexp will be hidden.
  146. This variable can also be a list of regexp of headers to remain visible.
  147. If this variable is non-nil, `gnus-ignored-headers' will be ignored."
  148. :type '(choice
  149. (repeat :value-to-internal (lambda (widget value)
  150. (custom-split-regexp-maybe value))
  151. :match (lambda (widget value)
  152. (or (stringp value)
  153. (widget-editable-list-match widget value)))
  154. regexp)
  155. (const :tag "Use gnus-ignored-headers" nil)
  156. regexp)
  157. :group 'gnus-article-hiding)
  158. (defcustom gnus-sorted-header-list
  159. '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
  160. "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
  161. "*This variable is a list of regular expressions.
  162. If it is non-nil, headers that match the regular expressions will
  163. be placed first in the article buffer in the sequence specified by
  164. this list."
  165. :type '(repeat regexp)
  166. :group 'gnus-article-hiding)
  167. (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
  168. "Headers that are only to be displayed if they have interesting data.
  169. Possible values in this list are:
  170. `empty' Headers with no content.
  171. `newsgroups' Newsgroup identical to Gnus group.
  172. `to-address' To identical to To-address.
  173. `to-list' To identical to To-list.
  174. `cc-list' CC identical to To-list.
  175. `followup-to' Followup-to identical to Newsgroups.
  176. `reply-to' Reply-to identical to From.
  177. `date' Date less than four days old.
  178. `long-to' To and/or Cc longer than 1024 characters.
  179. `many-to' Multiple To and/or Cc."
  180. :type '(set (const :tag "Headers with no content." empty)
  181. (const :tag "Newsgroups identical to Gnus group." newsgroups)
  182. (const :tag "To identical to To-address." to-address)
  183. (const :tag "To identical to To-list." to-list)
  184. (const :tag "CC identical to To-list." cc-list)
  185. (const :tag "Followup-to identical to Newsgroups." followup-to)
  186. (const :tag "Reply-to identical to From." reply-to)
  187. (const :tag "Date less than four days old." date)
  188. (const :tag "To and/or Cc longer than 1024 characters." long-to)
  189. (const :tag "Multiple To and/or Cc headers." many-to))
  190. :group 'gnus-article-hiding)
  191. (defcustom gnus-article-skip-boring nil
  192. "Skip over text that is not worth reading.
  193. By default, if you set this t, then Gnus will display citations and
  194. signatures, but will never scroll down to show you a page consisting
  195. only of boring text. Boring text is controlled by
  196. `gnus-article-boring-faces'."
  197. :version "22.1"
  198. :type 'boolean
  199. :group 'gnus-article-hiding)
  200. (defcustom gnus-signature-separator '("^-- $" "^-- *$")
  201. "Regexp matching signature separator.
  202. This can also be a list of regexps. In that case, it will be checked
  203. from head to tail looking for a separator. Searches will be done from
  204. the end of the buffer."
  205. :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
  206. (regexp)
  207. (repeat :tag "List of regexp" regexp))
  208. :group 'gnus-article-signature)
  209. (defcustom gnus-signature-limit nil
  210. "Provide a limit to what is considered a signature.
  211. If it is a number, no signature may not be longer (in characters) than
  212. that number. If it is a floating point number, no signature may be
  213. longer (in lines) than that number. If it is a function, the function
  214. will be called without any parameters, and if it returns nil, there is
  215. no signature in the buffer. If it is a string, it will be used as a
  216. regexp. If it matches, the text in question is not a signature.
  217. This can also be a list of the above values."
  218. :type '(choice (const nil)
  219. (integer :value 200)
  220. (number :value 4.0)
  221. function
  222. (regexp :value ".*"))
  223. :group 'gnus-article-signature)
  224. (defcustom gnus-hidden-properties
  225. ;; We use to have `intangible' here as well, but Emacs's command loop moves
  226. ;; point out of invisible text anyway, so `intangible' is clearly not
  227. ;; needed there. And XEmacs doesn't handle `intangible' anyway.
  228. '(invisible t)
  229. "Property list to use for hiding text."
  230. :type 'plist
  231. :group 'gnus-article-hiding)
  232. ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
  233. ;; frames in a session.
  234. (defcustom gnus-article-x-face-command
  235. (if (featurep 'xemacs)
  236. (if (or (gnus-image-type-available-p 'xface)
  237. (gnus-image-type-available-p 'pbm))
  238. 'gnus-display-x-face-in-from
  239. "{ echo \
  240. '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
  241. ; uncompface; } | icontopbm | ee -")
  242. (if (gnus-image-type-available-p 'pbm)
  243. 'gnus-display-x-face-in-from
  244. "{ echo \
  245. '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
  246. ; uncompface; } | icontopbm | display -"))
  247. "*String or function to be executed to display an X-Face header.
  248. If it is a string, the command will be executed in a sub-shell
  249. asynchronously. The compressed face will be piped to this command."
  250. :type `(choice string
  251. (function-item gnus-display-x-face-in-from)
  252. function)
  253. :version "21.1"
  254. :group 'gnus-picon
  255. :group 'gnus-article-washing)
  256. (defcustom gnus-article-x-face-too-ugly nil
  257. "Regexp matching posters whose face shouldn't be shown automatically."
  258. :type '(choice regexp (const nil))
  259. :group 'gnus-article-washing)
  260. (defcustom gnus-article-banner-alist nil
  261. "Banner alist for stripping.
  262. For example,
  263. ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
  264. :version "21.1"
  265. :type '(repeat (cons symbol regexp))
  266. :group 'gnus-article-washing)
  267. (gnus-define-group-parameter
  268. banner
  269. :variable-document
  270. "Alist of regexps (to match group names) and banner."
  271. :variable-group gnus-article-washing
  272. :parameter-type
  273. '(choice :tag "Banner"
  274. :value nil
  275. (const :tag "Remove signature" signature)
  276. (symbol :tag "Item in `gnus-article-banner-alist'" none)
  277. regexp
  278. (const :tag "None" nil))
  279. :parameter-document
  280. "If non-nil, specify how to remove `banners' from articles.
  281. Symbol `signature' means to remove signatures delimited by
  282. `gnus-signature-separator'. Any other symbol is used to look up a
  283. regular expression to match the banner in `gnus-article-banner-alist'.
  284. A string is used as a regular expression to match the banner
  285. directly.")
  286. (defcustom gnus-article-address-banner-alist nil
  287. "Alist of mail addresses and banners.
  288. Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
  289. to match a mail address in the From: header, BANNER is one of a symbol
  290. `signature', an item in `gnus-article-banner-alist', a regexp and nil.
  291. If ADDRESS matches author's mail address, it will remove things like
  292. advertisements. For example:
  293. \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
  294. "
  295. :type '(repeat
  296. (cons
  297. (regexp :tag "Address")
  298. (choice :tag "Banner" :value nil
  299. (const :tag "Remove signature" signature)
  300. (symbol :tag "Item in `gnus-article-banner-alist'" none)
  301. regexp
  302. (const :tag "None" nil))))
  303. :version "22.1"
  304. :group 'gnus-article-washing)
  305. (defmacro gnus-emphasis-custom-with-format (&rest body)
  306. `(let ((format "\
  307. \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
  308. \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
  309. ,@body))
  310. (defun gnus-emphasis-custom-value-to-external (value)
  311. (gnus-emphasis-custom-with-format
  312. (if (consp (car value))
  313. (list (format format (car (car value)) (cdr (car value)))
  314. 2
  315. (if (nth 1 value) 2 3)
  316. (nth 2 value))
  317. value)))
  318. (defun gnus-emphasis-custom-value-to-internal (value)
  319. (gnus-emphasis-custom-with-format
  320. (let ((regexp (concat "\\`"
  321. (format (regexp-quote format)
  322. "\\([^()]+\\)" "\\([^()]+\\)")
  323. "\\'"))
  324. pattern)
  325. (if (string-match regexp (setq pattern (car value)))
  326. (list (cons (match-string 1 pattern) (match-string 2 pattern))
  327. (= (nth 2 value) 2)
  328. (nth 3 value))
  329. value))))
  330. (defcustom gnus-emphasis-alist
  331. (let ((types
  332. '(("\\*" "\\*" bold nil 2)
  333. ("_" "_" underline)
  334. ("/" "/" italic)
  335. ("_/" "/_" underline-italic)
  336. ("_\\*" "\\*_" underline-bold)
  337. ("\\*/" "/\\*" bold-italic)
  338. ("_\\*/" "/\\*_" underline-bold-italic))))
  339. (nconc
  340. (gnus-emphasis-custom-with-format
  341. (mapcar (lambda (spec)
  342. (list (format format (car spec) (cadr spec))
  343. (or (nth 3 spec) 2)
  344. (or (nth 4 spec) 3)
  345. (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
  346. types))
  347. '(;; I've never seen anyone use this strikethru convention whereas I've
  348. ;; several times seen it triggered by normal text. --Stef
  349. ;; Miles suggests that this form is sometimes used but for italics,
  350. ;; so maybe we should map it to `italic'.
  351. ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
  352. ;; 2 3 gnus-emphasis-strikethru)
  353. ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
  354. 2 3 gnus-emphasis-underline))))
  355. "*Alist that says how to fontify certain phrases.
  356. Each item looks like this:
  357. (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
  358. The first element is a regular expression to be matched. The second
  359. is a number that says what regular expression grouping used to find
  360. the entire emphasized word. The third is a number that says what
  361. regexp grouping should be displayed and highlighted. The fourth
  362. is the face used for highlighting."
  363. :type
  364. '(repeat
  365. (menu-choice
  366. :format "%[Customizing Style%]\n%v"
  367. :indent 2
  368. (group :tag "Default"
  369. :value ("" 0 0 default)
  370. :value-create
  371. (lambda (widget)
  372. (let ((value (widget-get
  373. (cadr (widget-get (widget-get widget :parent)
  374. :args))
  375. :value)))
  376. (if (not (eq (nth 2 value) 'default))
  377. (widget-put
  378. widget
  379. :value
  380. (gnus-emphasis-custom-value-to-external value))))
  381. (widget-group-value-create widget))
  382. regexp
  383. (integer :format "Match group: %v")
  384. (integer :format "Emphasize group: %v")
  385. face)
  386. (group :tag "Simple"
  387. :value (("_" . "_") nil default)
  388. (cons :format "%v"
  389. (regexp :format "Start regexp: %v")
  390. (regexp :format "End regexp: %v"))
  391. (boolean :format "Show start and end patterns: %[%v%]\n"
  392. :on " On " :off " Off ")
  393. face)))
  394. :get (lambda (symbol)
  395. (mapcar 'gnus-emphasis-custom-value-to-internal
  396. (default-value symbol)))
  397. :set (lambda (symbol value)
  398. (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
  399. value)))
  400. :group 'gnus-article-emphasis)
  401. (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
  402. "A regexp to describe whitespace which should not be emphasized.
  403. Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
  404. The former avoids underlining of leading and trailing whitespace,
  405. and the latter avoids underlining any whitespace at all."
  406. :version "21.1"
  407. :group 'gnus-article-emphasis
  408. :type 'regexp)
  409. (defface gnus-emphasis-bold '((t (:bold t)))
  410. "Face used for displaying strong emphasized text (*word*)."
  411. :group 'gnus-article-emphasis)
  412. (defface gnus-emphasis-italic '((t (:italic t)))
  413. "Face used for displaying italic emphasized text (/word/)."
  414. :group 'gnus-article-emphasis)
  415. (defface gnus-emphasis-underline '((t (:underline t)))
  416. "Face used for displaying underlined emphasized text (_word_)."
  417. :group 'gnus-article-emphasis)
  418. (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
  419. "Face used for displaying underlined bold emphasized text (_*word*_)."
  420. :group 'gnus-article-emphasis)
  421. (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
  422. "Face used for displaying underlined italic emphasized text (_/word/_)."
  423. :group 'gnus-article-emphasis)
  424. (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
  425. "Face used for displaying bold italic emphasized text (/*word*/)."
  426. :group 'gnus-article-emphasis)
  427. (defface gnus-emphasis-underline-bold-italic
  428. '((t (:bold t :italic t :underline t)))
  429. "Face used for displaying underlined bold italic emphasized text.
  430. Example: (_/*word*/_)."
  431. :group 'gnus-article-emphasis)
  432. (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
  433. '((t (:strikethru t)))
  434. '((t (:strike-through t))))
  435. "Face used for displaying strike-through text (-word-)."
  436. :group 'gnus-article-emphasis)
  437. (defface gnus-emphasis-highlight-words
  438. '((t (:background "black" :foreground "yellow")))
  439. "Face used for displaying highlighted words."
  440. :group 'gnus-article-emphasis)
  441. (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
  442. "Format for display of Date headers in article bodies.
  443. See `format-time-string' for the possible values.
  444. The variable can also be function, which should return a complete Date
  445. header. The function is called with one argument, the time, which can
  446. be fed to `format-time-string'."
  447. :type '(choice string function)
  448. :link '(custom-manual "(gnus)Article Date")
  449. :group 'gnus-article-washing)
  450. (defcustom gnus-save-all-headers t
  451. "*If non-nil, don't remove any headers before saving.
  452. This will be overridden by the `:headers' property that the symbol of
  453. the saver function, which is specified by `gnus-default-article-saver',
  454. might have."
  455. :group 'gnus-article-saving
  456. :type 'boolean)
  457. (defcustom gnus-prompt-before-saving 'always
  458. "*This variable says how much prompting is to be done when saving articles.
  459. If it is nil, no prompting will be done, and the articles will be
  460. saved to the default files. If this variable is `always', each and
  461. every article that is saved will be preceded by a prompt, even when
  462. saving large batches of articles. If this variable is neither nil not
  463. `always', there the user will be prompted once for a file name for
  464. each invocation of the saving commands."
  465. :group 'gnus-article-saving
  466. :type '(choice (item always)
  467. (item :tag "never" nil)
  468. (sexp :tag "once" :format "%t\n" :value t)))
  469. (defcustom gnus-article-show-cursor nil
  470. "If non-nil, show the cursor in the Article buffer even when not selected."
  471. :version "25.1"
  472. :group 'gnus-article
  473. :type 'bool)
  474. (defcustom gnus-saved-headers gnus-visible-headers
  475. "Headers to keep if `gnus-save-all-headers' is nil.
  476. If `gnus-save-all-headers' is non-nil, this variable will be ignored.
  477. If that variable is nil, however, all headers that match this regexp
  478. will be kept while the rest will be deleted before saving. This and
  479. `gnus-save-all-headers' will be overridden by the `:headers' property
  480. that the symbol of the saver function, which is specified by
  481. `gnus-default-article-saver', might have."
  482. :group 'gnus-article-saving
  483. :type 'regexp)
  484. ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
  485. (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
  486. "A function to save articles in your favorite format.
  487. The function will be called by way of the `gnus-summary-save-article'
  488. command, and friends such as `gnus-summary-save-article-rmail'.
  489. Gnus provides the following functions:
  490. * gnus-summary-save-in-rmail (Rmail format)
  491. * gnus-summary-save-in-mail (Unix mail format)
  492. * gnus-summary-save-in-folder (MH folder)
  493. * gnus-summary-save-in-file (article format)
  494. * gnus-summary-save-body-in-file (article body)
  495. * gnus-summary-save-in-vm (use VM's folder format)
  496. * gnus-summary-write-to-file (article format -- overwrite)
  497. * gnus-summary-write-body-to-file (article body -- overwrite)
  498. * gnus-summary-save-in-pipe (article format)
  499. The symbol of each function may have the following properties:
  500. * :decode
  501. The value non-nil means save decoded articles. This is meaningful
  502. only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
  503. `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
  504. `gnus-summary-save-in-pipe'.
  505. * :function
  506. The value specifies an alternative function which appends, not
  507. overwrites, articles to a file. This implies that when saving many
  508. articles at a time, `gnus-prompt-before-saving' is bound to t and all
  509. articles are saved in a single file. This is meaningful only with
  510. `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
  511. * :headers
  512. The value specifies the symbol of a variable of which the value
  513. specifies headers to be saved. If it is omitted,
  514. `gnus-save-all-headers' and `gnus-saved-headers' control what
  515. headers should be saved."
  516. :group 'gnus-article-saving
  517. :type '(radio (function-item gnus-summary-save-in-rmail)
  518. (function-item gnus-summary-save-in-mail)
  519. (function-item gnus-summary-save-in-folder)
  520. (function-item gnus-summary-save-in-file)
  521. (function-item gnus-summary-save-body-in-file)
  522. (function-item gnus-summary-save-in-vm)
  523. (function-item gnus-summary-write-to-file)
  524. (function-item gnus-summary-write-body-to-file)
  525. (function-item gnus-summary-save-in-pipe)
  526. (function)))
  527. (defcustom gnus-article-save-coding-system
  528. (or (and (mm-coding-system-p 'utf-8) 'utf-8)
  529. (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
  530. (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
  531. (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
  532. "Coding system used to save decoded articles to a file.
  533. The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
  534. which can safely encode any characters in text. This is used by the
  535. commands including:
  536. * gnus-summary-save-article-file
  537. * gnus-summary-save-article-body-file
  538. * gnus-summary-write-article-file
  539. * gnus-summary-write-article-body-file
  540. and the functions to which you may set `gnus-default-article-saver':
  541. * gnus-summary-save-in-file
  542. * gnus-summary-save-body-in-file
  543. * gnus-summary-write-to-file
  544. * gnus-summary-write-body-to-file
  545. Those commands and functions save just text displayed in the article
  546. buffer to a file if the value of this variable is non-nil. Note that
  547. buttonized MIME parts will be lost in a saved file in that case.
  548. Otherwise, raw articles will be saved."
  549. :group 'gnus-article-saving
  550. :type `(choice
  551. :format "%{%t%}:\n %[Value Menu%] %v"
  552. (const :tag "Save raw articles" nil)
  553. ,@(delq nil
  554. (mapcar
  555. (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
  556. '((const :tag "UTF-8" utf-8)
  557. (const :tag "iso-2022-7bit" iso-2022-7bit)
  558. (const :tag "Emacs internal" emacs-mule)
  559. (const :tag "escape-quoted" escape-quoted))))
  560. (symbol :tag "Coding system")))
  561. (defcustom gnus-rmail-save-name 'gnus-plain-save-name
  562. "A function generating a file name to save articles in Rmail format.
  563. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  564. :group 'gnus-article-saving
  565. :type 'function)
  566. (defcustom gnus-mail-save-name 'gnus-plain-save-name
  567. "A function generating a file name to save articles in Unix mail format.
  568. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  569. :group 'gnus-article-saving
  570. :type 'function)
  571. (defcustom gnus-folder-save-name 'gnus-folder-save-name
  572. "A function generating a file name to save articles in MH folder.
  573. The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
  574. :group 'gnus-article-saving
  575. :type 'function)
  576. (defcustom gnus-file-save-name 'gnus-numeric-save-name
  577. "A function generating a file name to save articles in article format.
  578. The function is called with NEWSGROUP, HEADERS, and optional
  579. LAST-FILE."
  580. :group 'gnus-article-saving
  581. :type 'function)
  582. (defcustom gnus-split-methods
  583. '((gnus-article-archive-name)
  584. (gnus-article-nndoc-name))
  585. "*Variable used to suggest where articles are to be saved.
  586. For instance, if you would like to save articles related to Gnus in
  587. the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
  588. you could set this variable to something like:
  589. ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
  590. (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
  591. This variable is an alist where the key is the match and the
  592. value is a list of possible files to save in if the match is
  593. non-nil.
  594. If the match is a string, it is used as a regexp match on the
  595. article. If the match is a symbol, that symbol will be funcalled
  596. from the buffer of the article to be saved with the newsgroup as the
  597. parameter. If it is a list, it will be evalled in the same buffer.
  598. If this form or function returns a string, this string will be used as a
  599. possible file name; and if it returns a non-nil list, that list will be
  600. used as possible file names."
  601. :group 'gnus-article-saving
  602. :type '(repeat (choice (list :value (fun) function)
  603. (cons :value ("" "") regexp (repeat string))
  604. (sexp :value nil))))
  605. (defcustom gnus-page-delimiter "^\^L"
  606. "*Regexp describing what to use as article page delimiters.
  607. The default value is \"^\^L\", which is a form linefeed at the
  608. beginning of a line."
  609. :type 'regexp
  610. :group 'gnus-article-various)
  611. (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
  612. "*The format specification for the article mode line.
  613. See `gnus-summary-mode-line-format' for a closer description.
  614. The following additional specs are available:
  615. %w The article washing status.
  616. %m The number of MIME parts in the article."
  617. :version "24.1"
  618. :type 'string
  619. :group 'gnus-article-various)
  620. (defcustom gnus-article-mode-hook nil
  621. "*A hook for Gnus article mode."
  622. :type 'hook
  623. :group 'gnus-article-various)
  624. (when (featurep 'xemacs)
  625. ;; Extracted from gnus-xmas-define in order to preserve user settings
  626. (when (fboundp 'turn-off-scroll-in-place)
  627. (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
  628. ;; Extracted from gnus-xmas-redefine in order to preserve user settings
  629. (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
  630. (defcustom gnus-article-menu-hook nil
  631. "*Hook run after the creation of the article mode menu."
  632. :type 'hook
  633. :group 'gnus-article-various)
  634. (defcustom gnus-article-prepare-hook nil
  635. "*A hook called after an article has been prepared in the article buffer."
  636. :type 'hook
  637. :group 'gnus-article-various)
  638. (defcustom gnus-copy-article-ignored-headers nil
  639. "List of headers to be removed when copying an article.
  640. Each element is a regular expression."
  641. :version "23.1" ;; No Gnus
  642. :type '(repeat regexp)
  643. :group 'gnus-article-various)
  644. (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
  645. "Gnus 5.10 (Emacs 22.1)")
  646. (defface gnus-button
  647. '((t (:weight bold)))
  648. "Face used for highlighting a button in the article buffer."
  649. :group 'gnus-article-buttons)
  650. (defcustom gnus-article-button-face 'gnus-button
  651. "Face used for highlighting buttons in the article buffer.
  652. An article button is a piece of text that you can activate by pressing
  653. `RET' or `mouse-2' above it."
  654. :type 'face
  655. :group 'gnus-article-buttons)
  656. (defcustom gnus-article-mouse-face 'highlight
  657. "Face used for mouse highlighting in the article buffer.
  658. Article buttons will be displayed in this face when the cursor is
  659. above them."
  660. :type 'face
  661. :group 'gnus-article-buttons)
  662. (defcustom gnus-signature-face 'gnus-signature
  663. "Face used for highlighting a signature in the article buffer.
  664. Obsolete; use the face `gnus-signature' for customizations instead."
  665. :type 'face
  666. :group 'gnus-article-highlight
  667. :group 'gnus-article-signature)
  668. (defface gnus-signature
  669. '((t
  670. (:italic t)))
  671. "Face used for highlighting a signature in the article buffer."
  672. :group 'gnus-article-highlight
  673. :group 'gnus-article-signature)
  674. ;; backward-compatibility alias
  675. (put 'gnus-signature-face 'face-alias 'gnus-signature)
  676. (put 'gnus-signature-face 'obsolete-face "22.1")
  677. (defface gnus-header-from
  678. '((((class color)
  679. (background dark))
  680. (:foreground "PaleGreen1"))
  681. (((class color)
  682. (background light))
  683. (:foreground "red3"))
  684. (t
  685. (:italic t)))
  686. "Face used for displaying from headers."
  687. :group 'gnus-article-headers
  688. :group 'gnus-article-highlight)
  689. ;; backward-compatibility alias
  690. (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
  691. (put 'gnus-header-from-face 'obsolete-face "22.1")
  692. (defface gnus-header-subject
  693. '((((class color)
  694. (background dark))
  695. (:foreground "SeaGreen1"))
  696. (((class color)
  697. (background light))
  698. (:foreground "red4"))
  699. (t
  700. (:bold t :italic t)))
  701. "Face used for displaying subject headers."
  702. :group 'gnus-article-headers
  703. :group 'gnus-article-highlight)
  704. ;; backward-compatibility alias
  705. (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
  706. (put 'gnus-header-subject-face 'obsolete-face "22.1")
  707. (defface gnus-header-newsgroups
  708. '((((class color)
  709. (background dark))
  710. (:foreground "yellow" :italic t))
  711. (((class color)
  712. (background light))
  713. (:foreground "MidnightBlue" :italic t))
  714. (t
  715. (:italic t)))
  716. "Face used for displaying newsgroups headers.
  717. In the default setup this face is only used for crossposted
  718. articles."
  719. :group 'gnus-article-headers
  720. :group 'gnus-article-highlight)
  721. ;; backward-compatibility alias
  722. (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
  723. (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
  724. (defface gnus-header-name
  725. '((((class color)
  726. (background dark))
  727. (:foreground "SpringGreen2"))
  728. (((class color)
  729. (background light))
  730. (:foreground "maroon"))
  731. (t
  732. (:bold t)))
  733. "Face used for displaying header names."
  734. :group 'gnus-article-headers
  735. :group 'gnus-article-highlight)
  736. ;; backward-compatibility alias
  737. (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
  738. (put 'gnus-header-name-face 'obsolete-face "22.1")
  739. (defface gnus-header-content
  740. '((((class color)
  741. (background dark))
  742. (:foreground "SpringGreen1" :italic t))
  743. (((class color)
  744. (background light))
  745. (:foreground "indianred4" :italic t))
  746. (t
  747. (:italic t))) "Face used for displaying header content."
  748. :group 'gnus-article-headers
  749. :group 'gnus-article-highlight)
  750. ;; backward-compatibility alias
  751. (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
  752. (put 'gnus-header-content-face 'obsolete-face "22.1")
  753. (defcustom gnus-header-face-alist
  754. '(("From" nil gnus-header-from)
  755. ("Subject" nil gnus-header-subject)
  756. ("Newsgroups:.*," nil gnus-header-newsgroups)
  757. ("" gnus-header-name gnus-header-content))
  758. "*Controls highlighting of article headers.
  759. An alist of the form (HEADER NAME CONTENT).
  760. HEADER is a regular expression which should match the name of a
  761. header and NAME and CONTENT are either face names or nil.
  762. The name of each header field will be displayed using the face
  763. specified by the first element in the list where HEADER matches
  764. the header name and NAME is non-nil. Similarly, the content will
  765. be displayed by the first non-nil matching CONTENT face."
  766. :group 'gnus-article-headers
  767. :group 'gnus-article-highlight
  768. :type '(repeat (list (regexp :tag "Header")
  769. (choice :tag "Name"
  770. (item :tag "skip" nil)
  771. (face :value default))
  772. (choice :tag "Content"
  773. (item :tag "skip" nil)
  774. (face :value default)))))
  775. (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
  776. '((xface . (:face gnus-x-face)))
  777. '((pbm . (:face gnus-x-face))
  778. (png . nil)))
  779. "Alist of image types and properties applied to Face and X-Face images.
  780. Here are examples:
  781. ;; Specify the altitude of Face images in the From header.
  782. \(setq gnus-face-properties-alist
  783. \\='((pbm . (:face gnus-x-face :ascent 80))
  784. (png . (:ascent 80))))
  785. ;; Show Face images as pressed buttons.
  786. \(setq gnus-face-properties-alist
  787. \\='((pbm . (:face gnus-x-face :relief -2))
  788. (png . (:relief -2))))
  789. See the manual for the valid properties for various image types.
  790. Currently, `pbm' is used for X-Face images and `png' is used for Face
  791. images in Emacs. Only the `:face' property is effective on the `xface'
  792. image type in XEmacs if it is built with the libcompface library."
  793. :version "23.1" ;; No Gnus
  794. :group 'gnus-article-headers
  795. :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
  796. (defcustom gnus-article-decode-hook
  797. '(article-decode-charset article-decode-encoded-words
  798. article-decode-group-name article-decode-idna-rhs)
  799. "*Hook run to decode charsets in articles."
  800. :group 'gnus-article-headers
  801. :type 'hook)
  802. (defcustom gnus-display-mime-function 'gnus-display-mime
  803. "Function to display MIME articles."
  804. :group 'gnus-article-mime
  805. :type 'function)
  806. (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
  807. "Function used to decode headers.")
  808. (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
  809. "Function used to decode addresses.")
  810. (defvar gnus-article-dumbquotes-map
  811. '((?\200 "EUR")
  812. (?\202 ",")
  813. (?\203 "f")
  814. (?\204 ",,")
  815. (?\205 "...")
  816. (?\213 "<")
  817. (?\214 "OE")
  818. (?\221 "`")
  819. (?\222 "'")
  820. (?\223 "``")
  821. (?\224 "\"")
  822. (?\225 "*")
  823. (?\226 "-")
  824. (?\227 "--")
  825. (?\230 "~")
  826. (?\231 "(TM)")
  827. (?\233 ">")
  828. (?\234 "oe")
  829. (?\264 "'"))
  830. "Table for MS-to-Latin1 translation.")
  831. (defcustom gnus-ignored-mime-types nil
  832. "List of MIME types that should be ignored by Gnus."
  833. :version "21.1"
  834. :group 'gnus-article-mime
  835. :type '(repeat regexp))
  836. (defcustom gnus-unbuttonized-mime-types '(".*/.*")
  837. "List of MIME types that should not be given buttons when rendered inline.
  838. See also `gnus-buttonized-mime-types' which may override this variable.
  839. This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
  840. :version "21.1"
  841. :group 'gnus-article-mime
  842. :type '(repeat regexp))
  843. (defcustom gnus-buttonized-mime-types nil
  844. "List of MIME types that should be given buttons when rendered inline.
  845. If set, this variable overrides `gnus-unbuttonized-mime-types'.
  846. To see e.g. security buttons you could set this to
  847. `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
  848. this list to display radio buttons that allow you to choose one of two
  849. media types those mails include. See also `mm-discouraged-alternatives'.
  850. This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
  851. :version "22.1"
  852. :group 'gnus-article-mime
  853. :type '(repeat regexp))
  854. (defcustom gnus-inhibit-mime-unbuttonizing nil
  855. "If non-nil, all MIME parts get buttons.
  856. When nil (the default value), then some MIME parts do not get buttons,
  857. as described by the variables `gnus-buttonized-mime-types' and
  858. `gnus-unbuttonized-mime-types'."
  859. :version "22.1"
  860. :group 'gnus-article-mime
  861. :type 'boolean)
  862. (defcustom gnus-body-boundary-delimiter "_"
  863. "String used to delimit header and body.
  864. This variable is used by `gnus-article-treat-body-boundary' which can
  865. be controlled by `gnus-treat-body-boundary'."
  866. :version "22.1"
  867. :group 'gnus-article-various
  868. :type '(choice (item :tag "None" :value nil)
  869. string))
  870. (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
  871. "/usr/share/picons")
  872. "Defines the location of the faces database.
  873. For information on obtaining this database of pretty pictures, please
  874. see http://www.cs.indiana.edu/picons/ftp/index.html"
  875. :version "22.1"
  876. :type '(repeat directory)
  877. :link '(url-link :tag "download"
  878. "http://www.cs.indiana.edu/picons/ftp/index.html")
  879. :link '(custom-manual "(gnus)Picons")
  880. :group 'gnus-picon)
  881. (defun gnus-picons-installed-p ()
  882. "Say whether picons are installed on your machine."
  883. (let ((installed nil))
  884. (dolist (database gnus-picon-databases)
  885. (when (file-exists-p database)
  886. (setq installed t)))
  887. installed))
  888. (defcustom gnus-article-mime-part-function nil
  889. "Function called with a MIME handle as the argument.
  890. This is meant for people who want to do something automatic based
  891. on parts -- for instance, adding Vcard info to a database."
  892. :group 'gnus-article-mime
  893. :type '(choice (const nil)
  894. function))
  895. (defcustom gnus-mime-multipart-functions nil
  896. "An alist of MIME types to functions to display them."
  897. :version "21.1"
  898. :group 'gnus-article-mime
  899. :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
  900. (defcustom gnus-article-date-headers '(combined-lapsed)
  901. "A list of Date header formats to display.
  902. Valid formats are `ut' (Universal Time), `local' (local time
  903. zone), `english' (readable English), `lapsed' (elapsed time),
  904. `combined-lapsed' (both the original date and the elapsed time),
  905. `original' (the original date header), `iso8601' (ISO8601
  906. format), and `user-defined' (a user-defined format defined by the
  907. `gnus-article-time-format' variable).
  908. You have as many date headers as you want in the article buffer.
  909. Some of these headers are updated automatically. See
  910. `gnus-article-update-date-headers' for details."
  911. :version "24.1"
  912. :group 'gnus-article-headers
  913. :type '(set
  914. (const :tag "Universal time (UT)" ut)
  915. (const :tag "Local time zone" local)
  916. (const :tag "Readable English" english)
  917. (const :tag "Elapsed time" lapsed)
  918. (const :tag "Original and elapsed time" combined-lapsed)
  919. (const :tag "Original date header" original)
  920. (const :tag "ISO8601 format" iso8601)
  921. (const :tag "User-defined" user-defined)))
  922. (defcustom gnus-article-update-date-headers nil
  923. "A number that says how often to update the date header (in seconds).
  924. If nil, don't update it at all."
  925. :version "24.1"
  926. :group 'gnus-article-headers
  927. :type '(choice
  928. (item :tag "Don't update" :value nil)
  929. integer))
  930. (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
  931. "Function called with a MIME handle as the argument.
  932. This is meant for people who want to view first matched part.
  933. For `undisplayed-alternative' (default), the first undisplayed
  934. part or alternative part is used. For `undisplayed', the first
  935. undisplayed part is used. For a function, the first part which
  936. the function return t is used. For nil, the first part is
  937. used."
  938. :version "21.1"
  939. :group 'gnus-article-mime
  940. :type '(choice
  941. (item :tag "first" :value nil)
  942. (item :tag "undisplayed" :value undisplayed)
  943. (item :tag "undisplayed or alternative"
  944. :value undisplayed-alternative)
  945. (function)))
  946. (defcustom gnus-mime-action-alist
  947. '(("save to file" . gnus-mime-save-part)
  948. ("save and strip" . gnus-mime-save-part-and-strip)
  949. ("replace with file" . gnus-mime-replace-part)
  950. ("delete part" . gnus-mime-delete-part)
  951. ("display as text" . gnus-mime-inline-part)
  952. ("view the part" . gnus-mime-view-part)
  953. ("pipe to command" . gnus-mime-pipe-part)
  954. ("toggle display" . gnus-article-press-button)
  955. ("toggle display" . gnus-article-view-part-as-charset)
  956. ("view as type" . gnus-mime-view-part-as-type)
  957. ("view internally" . gnus-mime-view-part-internally)
  958. ("view externally" . gnus-mime-view-part-externally))
  959. "An alist of actions that run on the MIME attachment."
  960. :group 'gnus-article-mime
  961. :type '(repeat (cons (string :tag "name")
  962. (function))))
  963. (defcustom gnus-auto-select-part 1
  964. "Advance to next MIME part when deleting or stripping parts.
  965. When 0, point will be placed on the same part as before. When
  966. positive (negative), move point forward (backwards) this many
  967. parts. When nil, redisplay article."
  968. :version "23.1" ;; No Gnus
  969. :group 'gnus-article-mime
  970. :type '(choice (const nil :tag "Redisplay article.")
  971. (const 1 :tag "Next part.")
  972. (const 0 :tag "Current part.")
  973. integer))
  974. ;;;
  975. ;;; The treatment variables
  976. ;;;
  977. (defvar gnus-part-display-hook nil
  978. "Hook called on parts that are to receive treatment.")
  979. (defvar gnus-article-treat-custom
  980. '(choice (const :tag "Off" nil)
  981. (const :tag "On" t)
  982. (const :tag "Header" head)
  983. (const :tag "First" first)
  984. (const :tag "Last" last)
  985. (integer :tag "Less")
  986. (repeat :tag "Groups" regexp)
  987. (sexp :tag "Predicate")))
  988. (defvar gnus-article-treat-head-custom
  989. '(choice (const :tag "Off" nil)
  990. (const :tag "Header" head)))
  991. (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
  992. "text/x-patch" "text/html")
  993. "Part types eligible for treatment.")
  994. (defvar gnus-inhibit-treatment nil
  995. "Whether to inhibit treatment.")
  996. (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
  997. "Highlight the signature.
  998. Valid values are nil, t, `head', `first', `last', an integer or a
  999. predicate. See Info node `(gnus)Customizing Articles'."
  1000. :group 'gnus-article-treat
  1001. :link '(custom-manual "(gnus)Customizing Articles")
  1002. :type gnus-article-treat-custom)
  1003. (put 'gnus-treat-highlight-signature 'highlight t)
  1004. (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
  1005. "Add buttons.
  1006. Valid values are nil, t, `head', `first', `last', an integer or a
  1007. predicate. See Info node `(gnus)Customizing Articles'."
  1008. :group 'gnus-article-treat
  1009. :link '(custom-manual "(gnus)Customizing Articles")
  1010. :type gnus-article-treat-custom)
  1011. (put 'gnus-treat-buttonize 'highlight t)
  1012. (defcustom gnus-treat-buttonize-head 'head
  1013. "Add buttons to the head.
  1014. Valid values are nil, t, `head', `first', `last', an integer or a
  1015. predicate. See Info node `(gnus)Customizing Articles'."
  1016. :group 'gnus-article-treat
  1017. :link '(custom-manual "(gnus)Customizing Articles")
  1018. :type gnus-article-treat-head-custom)
  1019. (put 'gnus-treat-buttonize-head 'highlight t)
  1020. (defcustom gnus-treat-date 'head
  1021. "Display dates according to the `gnus-article-date-headers' variable.
  1022. Valid values are nil, t, `head', `first', `last', an integer or a
  1023. predicate. See Info node `(gnus)Customizing Articles'."
  1024. :version "24.1"
  1025. :group 'gnus-article-treat
  1026. :link '(custom-manual "(gnus)Customizing Articles")
  1027. :type gnus-article-treat-head-custom)
  1028. (defcustom gnus-treat-emphasize 50000
  1029. "Emphasize text.
  1030. Valid values are nil, t, `head', `first', `last', an integer or a
  1031. predicate. See Info node `(gnus)Customizing Articles'."
  1032. :group 'gnus-article-treat
  1033. :link '(custom-manual "(gnus)Customizing Articles")
  1034. :type gnus-article-treat-custom)
  1035. (put 'gnus-treat-emphasize 'highlight t)
  1036. (defcustom gnus-treat-strip-cr nil
  1037. "Remove carriage returns.
  1038. Valid values are nil, t, `head', `first', `last', an integer or a
  1039. predicate. See Info node `(gnus)Customizing Articles'."
  1040. :version "22.1"
  1041. :group 'gnus-article-treat
  1042. :link '(custom-manual "(gnus)Customizing Articles")
  1043. :type gnus-article-treat-custom)
  1044. (defcustom gnus-treat-unsplit-urls nil
  1045. "Remove newlines from within URLs.
  1046. Valid values are nil, t, `head', `first', `last', an integer or a
  1047. predicate. See Info node `(gnus)Customizing Articles'."
  1048. :version "22.1"
  1049. :group 'gnus-article-treat
  1050. :link '(custom-manual "(gnus)Customizing Articles")
  1051. :type gnus-article-treat-custom)
  1052. (defcustom gnus-treat-leading-whitespace nil
  1053. "Remove leading whitespace in headers.
  1054. Valid values are nil, t, `head', `first', `last', an integer or a
  1055. predicate. See Info node `(gnus)Customizing Articles'."
  1056. :version "22.1"
  1057. :group 'gnus-article-treat
  1058. :link '(custom-manual "(gnus)Customizing Articles")
  1059. :type gnus-article-treat-custom)
  1060. (defcustom gnus-treat-hide-headers 'head
  1061. "Hide headers.
  1062. Valid values are nil, t, `head', `first', `last', an integer or a
  1063. predicate. See Info node `(gnus)Customizing Articles'."
  1064. :group 'gnus-article-treat
  1065. :link '(custom-manual "(gnus)Customizing Articles")
  1066. :type gnus-article-treat-head-custom)
  1067. (defcustom gnus-treat-hide-boring-headers nil
  1068. "Hide boring headers.
  1069. Valid values are nil, t, `head', `first', `last', an integer or a
  1070. predicate. See Info node `(gnus)Customizing Articles'."
  1071. :group 'gnus-article-treat
  1072. :link '(custom-manual "(gnus)Customizing Articles")
  1073. :type gnus-article-treat-head-custom)
  1074. (defcustom gnus-treat-hide-signature nil
  1075. "Hide the signature.
  1076. Valid values are nil, t, `head', `first', `last', an integer or a
  1077. predicate. See Info node `(gnus)Customizing Articles'."
  1078. :group 'gnus-article-treat
  1079. :link '(custom-manual "(gnus)Customizing Articles")
  1080. :type gnus-article-treat-custom)
  1081. (defcustom gnus-treat-fill-article nil
  1082. "Fill the article.
  1083. Valid values are nil, t, `head', `first', `last', an integer or a
  1084. predicate. See Info node `(gnus)Customizing Articles'."
  1085. :group 'gnus-article-treat
  1086. :link '(custom-manual "(gnus)Customizing Articles")
  1087. :type gnus-article-treat-custom)
  1088. (defcustom gnus-treat-hide-citation nil
  1089. "Hide cited text.
  1090. Valid values are nil, t, `head', `first', `last', an integer or a
  1091. predicate. See Info node `(gnus)Customizing Articles'.
  1092. See `gnus-article-highlight-citation' for variables used to
  1093. control what it hides."
  1094. :group 'gnus-article-treat
  1095. :link '(custom-manual "(gnus)Customizing Articles")
  1096. :type gnus-article-treat-custom)
  1097. (defcustom gnus-treat-hide-citation-maybe nil
  1098. "Hide cited text according to certain conditions.
  1099. Valid values are nil, t, `head', `first', `last', an integer or a
  1100. predicate. See Info node `(gnus)Customizing Articles'.
  1101. See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
  1102. how to control what it hides."
  1103. :group 'gnus-article-treat
  1104. :link '(custom-manual "(gnus)Customizing Articles")
  1105. :type gnus-article-treat-custom)
  1106. (defcustom gnus-treat-strip-list-identifiers 'head
  1107. "Strip list identifiers from `gnus-list-identifiers'.
  1108. Valid values are nil, t, `head', `first', `last', an integer or a
  1109. predicate. See Info node `(gnus)Customizing Articles'."
  1110. :version "21.1"
  1111. :group 'gnus-article-treat
  1112. :link '(custom-manual "(gnus)Customizing Articles")
  1113. :type gnus-article-treat-custom)
  1114. (gnus-define-group-parameter
  1115. list-identifier
  1116. :variable-document
  1117. "Alist of regexps and correspondent identifiers."
  1118. :variable-group gnus-article-washing
  1119. :parameter-type
  1120. '(choice :tag "Identifier"
  1121. :value nil
  1122. (symbol :tag "Item in `gnus-list-identifiers'" none)
  1123. regexp
  1124. (const :tag "None" nil))
  1125. :parameter-document
  1126. "If non-nil, specify how to remove `identifiers' from articles' subject.
  1127. Any symbol is used to look up a regular expression to match the
  1128. banner in `gnus-list-identifiers'. A string is used as a regular
  1129. expression to match the identifier directly.")
  1130. (make-obsolete-variable 'gnus-treat-strip-pgp nil
  1131. "Gnus 5.10 (Emacs 22.1)")
  1132. (defcustom gnus-treat-strip-pem nil
  1133. "Strip PEM signatures.
  1134. Valid values are nil, t, `head', `first', `last', an integer or a
  1135. predicate. See Info node `(gnus)Customizing Articles'."
  1136. :group 'gnus-article-treat
  1137. :link '(custom-manual "(gnus)Customizing Articles")
  1138. :type gnus-article-treat-custom)
  1139. (defcustom gnus-treat-strip-banner t
  1140. "Strip banners from articles.
  1141. The banner to be stripped is specified in the `banner' group parameter.
  1142. Valid values are nil, t, `head', `first', `last', an integer or a
  1143. predicate. See Info node `(gnus)Customizing Articles'."
  1144. :group 'gnus-article-treat
  1145. :link '(custom-manual "(gnus)Customizing Articles")
  1146. :type gnus-article-treat-custom)
  1147. (defcustom gnus-treat-highlight-headers 'head
  1148. "Highlight the headers.
  1149. Valid values are nil, t, `head', `first', `last', an integer or a
  1150. predicate. See Info node `(gnus)Customizing Articles'."
  1151. :group 'gnus-article-treat
  1152. :link '(custom-manual "(gnus)Customizing Articles")
  1153. :type gnus-article-treat-head-custom)
  1154. (put 'gnus-treat-highlight-headers 'highlight t)
  1155. (defcustom gnus-treat-highlight-citation t
  1156. "Highlight cited text.
  1157. Valid values are nil, t, `head', `first', `last', an integer or a
  1158. predicate. See Info node `(gnus)Customizing Articles'."
  1159. :group 'gnus-article-treat
  1160. :link '(custom-manual "(gnus)Customizing Articles")
  1161. :type gnus-article-treat-custom)
  1162. (put 'gnus-treat-highlight-citation 'highlight t)
  1163. (defcustom gnus-treat-strip-headers-in-body t
  1164. "Strip the X-No-Archive header line from the beginning of the body.
  1165. Valid values are nil, t, `head', `first', `last', an integer or a
  1166. predicate. See Info node `(gnus)Customizing Articles'."
  1167. :version "21.1"
  1168. :group 'gnus-article-treat
  1169. :link '(custom-manual "(gnus)Customizing Articles")
  1170. :type gnus-article-treat-custom)
  1171. (defcustom gnus-treat-strip-trailing-blank-lines nil
  1172. "Strip trailing blank lines.
  1173. Valid values are nil, t, `head', `first', `last', an integer or a
  1174. predicate. See Info node `(gnus)Customizing Articles'.
  1175. When set to t, it also strips trailing blanks in all MIME parts.
  1176. Consider to use `last' instead."
  1177. :group 'gnus-article-treat
  1178. :link '(custom-manual "(gnus)Customizing Articles")
  1179. :type gnus-article-treat-custom)
  1180. (defcustom gnus-treat-strip-leading-blank-lines nil
  1181. "Strip leading blank lines.
  1182. Valid values are nil, t, `head', `first', `last', an integer or a
  1183. predicate. See Info node `(gnus)Customizing Articles'.
  1184. When set to t, it also strips trailing blanks in all MIME parts."
  1185. :group 'gnus-article-treat
  1186. :link '(custom-manual "(gnus)Customizing Articles")
  1187. :type gnus-article-treat-custom)
  1188. (defcustom gnus-treat-strip-multiple-blank-lines nil
  1189. "Strip multiple blank lines.
  1190. Valid values are nil, t, `head', `first', `last', an integer or a
  1191. predicate. See Info node `(gnus)Customizing Articles'."
  1192. :group 'gnus-article-treat
  1193. :link '(custom-manual "(gnus)Customizing Articles")
  1194. :type gnus-article-treat-custom)
  1195. (defcustom gnus-treat-unfold-headers 'head
  1196. "Unfold folded header lines.
  1197. Valid values are nil, t, `head', `first', `last', an integer or a
  1198. predicate. See Info node `(gnus)Customizing Articles'."
  1199. :version "22.1"
  1200. :group 'gnus-article-treat
  1201. :link '(custom-manual "(gnus)Customizing Articles")
  1202. :type gnus-article-treat-custom)
  1203. (defcustom gnus-article-unfold-long-headers nil
  1204. "If non-nil, allow unfolding headers even if the header is long.
  1205. If it is a regexp, only long headers matching this regexp are unfolded.
  1206. If it is t, all long headers are unfolded.
  1207. This variable has no effect if `gnus-treat-unfold-headers' is nil."
  1208. :version "23.1" ;; No Gnus
  1209. :group 'gnus-article-treat
  1210. :type '(choice (const nil)
  1211. (const :tag "all" t)
  1212. (regexp)))
  1213. (defcustom gnus-treat-fold-headers nil
  1214. "Fold headers.
  1215. Valid values are nil, t, `head', `first', `last', an integer or a
  1216. predicate. See Info node `(gnus)Customizing Articles'."
  1217. :version "22.1"
  1218. :group 'gnus-article-treat
  1219. :link '(custom-manual "(gnus)Customizing Articles")
  1220. :type gnus-article-treat-custom)
  1221. (defcustom gnus-treat-fold-newsgroups 'head
  1222. "Fold the Newsgroups and Followup-To headers.
  1223. Valid values are nil, t, `head', `first', `last', an integer or a
  1224. predicate. See Info node `(gnus)Customizing Articles'."
  1225. :version "22.1"
  1226. :group 'gnus-article-treat
  1227. :link '(custom-manual "(gnus)Customizing Articles")
  1228. :type gnus-article-treat-custom)
  1229. (defcustom gnus-treat-overstrike t
  1230. "Treat overstrike highlighting.
  1231. Valid values are nil, t, `head', `first', `last', an integer or a
  1232. predicate. See Info node `(gnus)Customizing Articles'."
  1233. :group 'gnus-article-treat
  1234. :link '(custom-manual "(gnus)Customizing Articles")
  1235. :type gnus-article-treat-custom)
  1236. (put 'gnus-treat-overstrike 'highlight t)
  1237. (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
  1238. "Treat ANSI SGR control sequences.
  1239. Valid values are nil, t, `head', `first', `last', an integer or a
  1240. predicate. See Info node `(gnus)Customizing Articles'."
  1241. :group 'gnus-article-treat
  1242. :link '(custom-manual "(gnus)Customizing Articles")
  1243. :type gnus-article-treat-custom)
  1244. (make-obsolete-variable 'gnus-treat-display-xface
  1245. 'gnus-treat-display-x-face "Emacs 22.1")
  1246. (defcustom gnus-treat-display-x-face
  1247. (and (not noninteractive)
  1248. (gnus-image-type-available-p 'xbm)
  1249. (if (featurep 'xemacs)
  1250. (featurep 'xface)
  1251. (condition-case nil
  1252. (and (string-match "^0x" (shell-command-to-string "uncompface"))
  1253. (executable-find "icontopbm"))
  1254. ;; shell-command-to-string may signal an error, e.g. if
  1255. ;; shell-file-name is not found.
  1256. (error nil)))
  1257. 'head)
  1258. "Display X-Face headers.
  1259. Valid values are nil and `head'.
  1260. See Info node `(gnus)Customizing Articles' and Info node
  1261. `(gnus)X-Face' for details."
  1262. :group 'gnus-article-treat
  1263. :version "21.1"
  1264. :link '(custom-manual "(gnus)Customizing Articles")
  1265. :link '(custom-manual "(gnus)X-Face")
  1266. :type gnus-article-treat-head-custom
  1267. :set (lambda (symbol value)
  1268. (set-default
  1269. symbol
  1270. (cond ((or (boundp symbol) (get symbol 'saved-value))
  1271. value)
  1272. ((boundp 'gnus-treat-display-xface)
  1273. (message "\
  1274. ** gnus-treat-display-xface is an obsolete variable;\
  1275. use gnus-treat-display-x-face instead")
  1276. (default-value 'gnus-treat-display-xface))
  1277. ((get 'gnus-treat-display-xface 'saved-value)
  1278. (message "\
  1279. ** gnus-treat-display-xface is an obsolete variable;\
  1280. use gnus-treat-display-x-face instead")
  1281. (eval (car (get 'gnus-treat-display-xface 'saved-value))))
  1282. (t
  1283. value)))))
  1284. (put 'gnus-treat-display-x-face 'highlight t)
  1285. (defcustom gnus-treat-display-face
  1286. (and (not noninteractive)
  1287. (gnus-image-type-available-p 'png)
  1288. 'head)
  1289. "Display Face headers.
  1290. Valid values are nil, t, `head', `first', `last', an integer or a
  1291. predicate. See Info node `(gnus)Customizing Articles' and Info
  1292. node `(gnus)Face' for details."
  1293. :group 'gnus-article-treat
  1294. :version "22.1"
  1295. :link '(custom-manual "(gnus)Customizing Articles")
  1296. :link '(custom-manual "(gnus)X-Face")
  1297. :type gnus-article-treat-head-custom)
  1298. (put 'gnus-treat-display-face 'highlight t)
  1299. (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
  1300. "Display smileys.
  1301. Valid values are nil, t, `head', `first', `last', an integer or a
  1302. predicate. See Info node `(gnus)Customizing Articles' and Info
  1303. node `(gnus)Smileys' for details."
  1304. :group 'gnus-article-treat
  1305. :version "21.1"
  1306. :link '(custom-manual "(gnus)Customizing Articles")
  1307. :link '(custom-manual "(gnus)Smileys")
  1308. :type gnus-article-treat-custom)
  1309. (put 'gnus-treat-display-smileys 'highlight t)
  1310. (defcustom gnus-treat-from-picon
  1311. (if (and (gnus-image-type-available-p 'xpm)
  1312. (gnus-picons-installed-p))
  1313. 'head nil)
  1314. "Display picons in the From header.
  1315. Valid values are nil, t, `head', `first', `last', an integer or a
  1316. predicate. See Info node `(gnus)Customizing Articles' and Info
  1317. node `(gnus)Picons' for details."
  1318. :version "22.1"
  1319. :group 'gnus-article-treat
  1320. :group 'gnus-picon
  1321. :link '(custom-manual "(gnus)Customizing Articles")
  1322. :link '(custom-manual "(gnus)Picons")
  1323. :type gnus-article-treat-head-custom)
  1324. (put 'gnus-treat-from-picon 'highlight t)
  1325. (defcustom gnus-treat-mail-picon
  1326. (if (and (gnus-image-type-available-p 'xpm)
  1327. (gnus-picons-installed-p))
  1328. 'head nil)
  1329. "Display picons in To and Cc headers.
  1330. Valid values are nil, t, `head', `first', `last', an integer or a
  1331. predicate. See Info node `(gnus)Customizing Articles' and Info
  1332. node `(gnus)Picons' for details."
  1333. :version "22.1"
  1334. :group 'gnus-article-treat
  1335. :group 'gnus-picon
  1336. :link '(custom-manual "(gnus)Customizing Articles")
  1337. :link '(custom-manual "(gnus)Picons")
  1338. :type gnus-article-treat-head-custom)
  1339. (put 'gnus-treat-mail-picon 'highlight t)
  1340. (defcustom gnus-treat-newsgroups-picon
  1341. (if (and (gnus-image-type-available-p 'xpm)
  1342. (gnus-picons-installed-p))
  1343. 'head nil)
  1344. "Display picons in the Newsgroups and Followup-To headers.
  1345. Valid values are nil, t, `head', `first', `last', an integer or a
  1346. predicate. See Info node `(gnus)Customizing Articles' and Info
  1347. node `(gnus)Picons' for details."
  1348. :version "22.1"
  1349. :group 'gnus-article-treat
  1350. :group 'gnus-picon
  1351. :link '(custom-manual "(gnus)Customizing Articles")
  1352. :link '(custom-manual "(gnus)Picons")
  1353. :type gnus-article-treat-head-custom)
  1354. (put 'gnus-treat-newsgroups-picon 'highlight t)
  1355. (defcustom gnus-treat-from-gravatar nil
  1356. "Display gravatars in the From header.
  1357. Valid values are nil, t, `head', `first', `last', an integer or a
  1358. predicate. See Info node `(gnus)Customizing Articles' and Info
  1359. node `(gnus)Gravatars' for details."
  1360. :version "24.1"
  1361. :group 'gnus-article-treat
  1362. :group 'gnus-gravatar
  1363. :link '(custom-manual "(gnus)Customizing Articles")
  1364. :link '(custom-manual "(gnus)Gravatars")
  1365. :type gnus-article-treat-head-custom)
  1366. (put 'gnus-treat-from-gravatar 'highlight t)
  1367. (defcustom gnus-treat-mail-gravatar nil
  1368. "Display gravatars in To and Cc headers.
  1369. Valid values are nil, t, `head', `first', `last', an integer or a
  1370. predicate. See Info node `(gnus)Customizing Articles' and Info
  1371. node `(gnus)Gravatars' for details."
  1372. :version "24.1"
  1373. :group 'gnus-article-treat
  1374. :group 'gnus-gravatar
  1375. :link '(custom-manual "(gnus)Customizing Articles")
  1376. :link '(custom-manual "(gnus)Gravatars")
  1377. :type gnus-article-treat-head-custom)
  1378. (put 'gnus-treat-mail-gravatar 'highlight t)
  1379. (defcustom gnus-treat-body-boundary
  1380. (if (or gnus-treat-newsgroups-picon
  1381. gnus-treat-mail-picon
  1382. gnus-treat-from-picon
  1383. gnus-treat-from-gravatar
  1384. gnus-treat-mail-gravatar)
  1385. ;; If there's much decoration, the user might prefer a boundary.
  1386. 'head
  1387. nil)
  1388. "Draw a boundary at the end of the headers.
  1389. Valid values are nil and `head'.
  1390. See Info node `(gnus)Customizing Articles' for details."
  1391. :version "22.1"
  1392. :group 'gnus-article-treat
  1393. :link '(custom-manual "(gnus)Customizing Articles")
  1394. :type gnus-article-treat-head-custom)
  1395. (defcustom gnus-treat-capitalize-sentences nil
  1396. "Capitalize sentence-starting words.
  1397. Valid values are nil, t, `head', `first', `last', an integer or a
  1398. predicate. See Info node `(gnus)Customizing Articles'."
  1399. :version "21.1"
  1400. :group 'gnus-article-treat
  1401. :link '(custom-manual "(gnus)Customizing Articles")
  1402. :type gnus-article-treat-custom)
  1403. (defcustom gnus-treat-wash-html nil
  1404. "Format as HTML.
  1405. Valid values are nil, t, `head', `first', `last', an integer or a
  1406. predicate. See Info node `(gnus)Customizing Articles'."
  1407. :version "22.1"
  1408. :group 'gnus-article-treat
  1409. :link '(custom-manual "(gnus)Customizing Articles")
  1410. :type gnus-article-treat-custom)
  1411. (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
  1412. "Fill long lines.
  1413. Valid values are nil, t, `head', `first', `last', an integer or a
  1414. predicate. See Info node `(gnus)Customizing Articles'."
  1415. :version "24.1"
  1416. :group 'gnus-article-treat
  1417. :link '(custom-manual "(gnus)Customizing Articles")
  1418. :type gnus-article-treat-custom)
  1419. (defcustom gnus-treat-x-pgp-sig nil
  1420. "Verify X-PGP-Sig.
  1421. To automatically treat X-PGP-Sig, set it to head.
  1422. Valid values are nil, t, `head', `first', `last', an integer or a
  1423. predicate. See Info node `(gnus)Customizing Articles'."
  1424. :version "22.1"
  1425. :group 'gnus-article-treat
  1426. :group 'mime-security
  1427. :link '(custom-manual "(gnus)Customizing Articles")
  1428. :type gnus-article-treat-custom)
  1429. (defvar gnus-article-encrypt-protocol-alist
  1430. '(("PGP" . mml2015-self-encrypt)))
  1431. ;; Set to nil if more than one protocol added to
  1432. ;; gnus-article-encrypt-protocol-alist.
  1433. (defcustom gnus-article-encrypt-protocol "PGP"
  1434. "The protocol used for encrypt articles.
  1435. It is a string, such as \"PGP\". If nil, ask user."
  1436. :version "22.1"
  1437. :type 'string
  1438. :group 'mime-security)
  1439. (defvar idna-program)
  1440. (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
  1441. (condition-case nil
  1442. (require 'idna)
  1443. (file-error)
  1444. (invalid-operation))
  1445. idna-program
  1446. (executable-find idna-program))
  1447. "Whether IDNA decoding of headers is used when viewing messages.
  1448. This requires GNU Libidn, and by default only enabled if it is found."
  1449. :version "22.1"
  1450. :group 'gnus-article-headers
  1451. :type 'boolean)
  1452. (defcustom gnus-article-over-scroll nil
  1453. "If non-nil, allow scrolling the article buffer even when there no more text."
  1454. :version "22.1"
  1455. :group 'gnus-article
  1456. :type 'boolean)
  1457. (defcustom gnus-inhibit-images nil
  1458. "Non-nil means inhibit displaying of images inline in the article body."
  1459. :version "24.1"
  1460. :group 'gnus-article
  1461. :type 'boolean)
  1462. (defcustom gnus-blocked-images 'gnus-block-private-groups
  1463. "Images that have URLs matching this regexp will be blocked.
  1464. This can also be a function to be evaluated. If so, it will be
  1465. called with the group name as the parameter, and should return a
  1466. regexp."
  1467. :version "24.1"
  1468. :group 'gnus-art
  1469. :type '(choice (const :tag "Allow all" nil)
  1470. (regexp :tag "Regular expression")
  1471. (function :tag "Use a function")))
  1472. ;;; Internal variables
  1473. (defvar gnus-english-month-names
  1474. '("January" "February" "March" "April" "May" "June" "July" "August"
  1475. "September" "October" "November" "December"))
  1476. (defvar article-goto-body-goes-to-point-min-p nil)
  1477. (defvar gnus-article-wash-types nil)
  1478. (defvar gnus-article-emphasis-alist nil)
  1479. (defvar gnus-article-image-alist nil)
  1480. (defvar gnus-article-mime-handle-alist-1 nil)
  1481. (defvar gnus-treatment-function-alist
  1482. '((gnus-treat-strip-cr gnus-article-remove-cr)
  1483. (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
  1484. (gnus-treat-strip-banner gnus-article-strip-banner)
  1485. (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
  1486. (gnus-treat-highlight-signature gnus-article-highlight-signature)
  1487. (gnus-treat-buttonize gnus-article-add-buttons)
  1488. (gnus-treat-fill-article gnus-article-fill-cited-article)
  1489. (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
  1490. (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
  1491. (gnus-treat-display-x-face gnus-article-display-x-face)
  1492. (gnus-treat-display-face gnus-article-display-face)
  1493. (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
  1494. (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
  1495. (gnus-treat-hide-signature gnus-article-hide-signature)
  1496. (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
  1497. (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
  1498. (gnus-treat-from-picon gnus-treat-from-picon)
  1499. (gnus-treat-mail-picon gnus-treat-mail-picon)
  1500. (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
  1501. (gnus-treat-strip-pem gnus-article-hide-pem)
  1502. (gnus-treat-date gnus-article-treat-date)
  1503. (gnus-treat-from-gravatar gnus-treat-from-gravatar)
  1504. (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
  1505. (gnus-treat-highlight-headers gnus-article-highlight-headers)
  1506. (gnus-treat-highlight-signature gnus-article-highlight-signature)
  1507. (gnus-treat-strip-trailing-blank-lines
  1508. gnus-article-remove-trailing-blank-lines)
  1509. (gnus-treat-strip-leading-blank-lines
  1510. gnus-article-strip-leading-blank-lines)
  1511. (gnus-treat-strip-multiple-blank-lines
  1512. gnus-article-strip-multiple-blank-lines)
  1513. (gnus-treat-overstrike gnus-article-treat-overstrike)
  1514. (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
  1515. (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
  1516. (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
  1517. (gnus-treat-fold-headers gnus-article-treat-fold-headers)
  1518. (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
  1519. (gnus-treat-display-smileys gnus-treat-smiley)
  1520. (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
  1521. (gnus-treat-wash-html gnus-article-wash-html)
  1522. (gnus-treat-emphasize gnus-article-emphasize)
  1523. (gnus-treat-hide-citation gnus-article-hide-citation)
  1524. (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
  1525. (gnus-treat-highlight-citation gnus-article-highlight-citation)
  1526. (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
  1527. (defvar gnus-article-mime-handle-alist nil)
  1528. (defvar article-lapsed-timer nil)
  1529. (defvar gnus-article-current-summary nil)
  1530. (defvar gnus-article-mode-syntax-table
  1531. (let ((table (copy-syntax-table text-mode-syntax-table)))
  1532. ;; This causes the citation match run O(2^n).
  1533. ;; (modify-syntax-entry ?- "w" table)
  1534. (modify-syntax-entry ?> ")<" table)
  1535. (modify-syntax-entry ?< "(>" table)
  1536. ;; make M-. in article buffers work for `foo' strings
  1537. (modify-syntax-entry ?' " " table)
  1538. (modify-syntax-entry ?` " " table)
  1539. table)
  1540. "Syntax table used in article mode buffers.
  1541. Initialized from `text-mode-syntax-table'.")
  1542. (defvar gnus-save-article-buffer nil)
  1543. (defvar gnus-number-of-articles-to-be-saved nil)
  1544. (defvar gnus-inhibit-hiding nil)
  1545. (defvar gnus-article-edit-mode nil)
  1546. ;;; Macros for dealing with the article buffer.
  1547. (defmacro gnus-with-article-headers (&rest forms)
  1548. `(with-current-buffer gnus-article-buffer
  1549. (save-restriction
  1550. (let ((inhibit-read-only t)
  1551. (inhibit-point-motion-hooks t)
  1552. (case-fold-search t))
  1553. (article-narrow-to-head)
  1554. ,@forms))))
  1555. (put 'gnus-with-article-headers 'lisp-indent-function 0)
  1556. (put 'gnus-with-article-headers 'edebug-form-spec '(body))
  1557. (defmacro gnus-with-article-buffer (&rest forms)
  1558. `(when (buffer-live-p (get-buffer gnus-article-buffer))
  1559. (with-current-buffer gnus-article-buffer
  1560. (let ((inhibit-read-only t))
  1561. ,@forms))))
  1562. (put 'gnus-with-article-buffer 'lisp-indent-function 0)
  1563. (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
  1564. (defun gnus-article-goto-header (header)
  1565. "Go to HEADER, which is a regular expression."
  1566. (re-search-forward (concat "^\\(" header "\\):") nil t))
  1567. (defsubst gnus-article-hide-text (b e props)
  1568. "Set text PROPS on the B to E region."
  1569. (gnus-add-text-properties-when 'article-type nil b e props))
  1570. (defsubst gnus-article-unhide-text (b e)
  1571. "Remove hidden text properties from region between B and E."
  1572. (remove-text-properties b e gnus-hidden-properties))
  1573. (defun gnus-article-hide-text-type (b e type)
  1574. "Hide text of TYPE between B and E."
  1575. (gnus-add-wash-type type)
  1576. (gnus-article-hide-text
  1577. b e (cons 'article-type (cons type gnus-hidden-properties))))
  1578. (defun gnus-article-unhide-text-type (b e type)
  1579. "Unhide text of TYPE between B and E."
  1580. (gnus-delete-wash-type type)
  1581. (remove-text-properties
  1582. b e (cons 'article-type (cons type gnus-hidden-properties))))
  1583. (defun gnus-article-delete-text-of-type (type)
  1584. "Delete text of TYPE in the current buffer."
  1585. (save-excursion
  1586. (let ((b (point-min)))
  1587. (if (eq type 'multipart)
  1588. ;; Remove MIME buttons associated with multipart/alternative parts.
  1589. (progn
  1590. (goto-char b)
  1591. (while (if (get-text-property (point) 'gnus-part)
  1592. (setq b (point))
  1593. (when (setq b (next-single-property-change (point)
  1594. 'gnus-part))
  1595. (goto-char b)
  1596. t))
  1597. (end-of-line)
  1598. (skip-chars-forward "\n")
  1599. (when (eq (get-text-property b 'article-type) 'multipart)
  1600. (delete-region b (point)))))
  1601. (while (setq b (text-property-any b (point-max) 'article-type type))
  1602. (delete-region
  1603. b (or (text-property-not-all b (point-max) 'article-type type)
  1604. (point-max))))))))
  1605. (defun gnus-article-delete-invisible-text ()
  1606. "Delete all invisible text in the current buffer."
  1607. (save-excursion
  1608. (let ((b (point-min)))
  1609. (while (setq b (text-property-any b (point-max) 'invisible t))
  1610. (delete-region
  1611. b (or (text-property-not-all b (point-max) 'invisible t)
  1612. (point-max)))))))
  1613. (defsubst gnus-article-header-rank ()
  1614. "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
  1615. (let ((list gnus-sorted-header-list)
  1616. (i 1))
  1617. (while list
  1618. (if (looking-at (car list))
  1619. (setq list nil)
  1620. (setq list (cdr list))
  1621. (incf i)))
  1622. i))
  1623. (defun article-hide-headers (&optional _arg _delete)
  1624. "Hide unwanted headers and possibly sort them as well."
  1625. (interactive)
  1626. ;; This function might be inhibited.
  1627. (unless gnus-inhibit-hiding
  1628. (let ((inhibit-read-only t)
  1629. (case-fold-search t)
  1630. (max (1+ (length gnus-sorted-header-list)))
  1631. (inhibit-point-motion-hooks t)
  1632. (cur (current-buffer))
  1633. ignored visible beg)
  1634. (save-excursion
  1635. ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
  1636. ;; group parameters, so we should go to the summary buffer.
  1637. (when (prog1
  1638. (condition-case nil
  1639. (progn (set-buffer gnus-summary-buffer) t)
  1640. (error nil))
  1641. (setq ignored (when (not gnus-visible-headers)
  1642. (cond ((stringp gnus-ignored-headers)
  1643. gnus-ignored-headers)
  1644. ((listp gnus-ignored-headers)
  1645. (mapconcat 'identity
  1646. gnus-ignored-headers
  1647. "\\|"))))
  1648. visible (cond ((stringp gnus-visible-headers)
  1649. gnus-visible-headers)
  1650. ((and gnus-visible-headers
  1651. (listp gnus-visible-headers))
  1652. (mapconcat 'identity
  1653. gnus-visible-headers
  1654. "\\|")))))
  1655. (set-buffer cur))
  1656. (save-restriction
  1657. ;; First we narrow to just the headers.
  1658. (article-narrow-to-head)
  1659. ;; Hide any "From " lines at the beginning of (mail) articles.
  1660. (while (looking-at "From ")
  1661. (forward-line 1))
  1662. (unless (bobp)
  1663. (delete-region (point-min) (point)))
  1664. ;; Then treat the rest of the header lines.
  1665. ;; Then we use the two regular expressions
  1666. ;; `gnus-ignored-headers' and `gnus-visible-headers' to
  1667. ;; select which header lines is to remain visible in the
  1668. ;; article buffer.
  1669. (while (re-search-forward "^[^ \t:]*:" nil t)
  1670. (beginning-of-line)
  1671. ;; Mark the rank of the header.
  1672. (put-text-property
  1673. (point) (1+ (point)) 'message-rank
  1674. (if (or (and visible (looking-at visible))
  1675. (and ignored
  1676. (not (looking-at ignored))))
  1677. (gnus-article-header-rank)
  1678. (+ 2 max)))
  1679. (forward-line 1))
  1680. (message-sort-headers-1)
  1681. (when (setq beg (text-property-any
  1682. (point-min) (point-max) 'message-rank (+ 2 max)))
  1683. ;; We delete the unwanted headers.
  1684. (gnus-add-wash-type 'headers)
  1685. (add-text-properties (point-min) (+ 5 (point-min))
  1686. '(article-type headers dummy-invisible t))
  1687. (delete-region beg (point-max))))))))
  1688. (defun article-hide-boring-headers (&optional arg)
  1689. "Toggle hiding of headers that aren't very interesting.
  1690. If given a negative prefix, always show; if given a positive prefix,
  1691. always hide."
  1692. (interactive (gnus-article-hidden-arg))
  1693. (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
  1694. (not gnus-show-all-headers))
  1695. (save-excursion
  1696. (save-restriction
  1697. (let ((inhibit-read-only t)
  1698. (inhibit-point-motion-hooks t))
  1699. (article-narrow-to-head)
  1700. (dolist (elem gnus-boring-article-headers)
  1701. (goto-char (point-min))
  1702. (cond
  1703. ;; Hide empty headers.
  1704. ((eq elem 'empty)
  1705. (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
  1706. (forward-line -1)
  1707. (gnus-article-hide-text-type
  1708. (point-at-bol)
  1709. (progn
  1710. (end-of-line)
  1711. (if (re-search-forward "^[^ \t]" nil t)
  1712. (match-beginning 0)
  1713. (point-max)))
  1714. 'boring-headers)))
  1715. ;; Hide boring Newsgroups header.
  1716. ((eq elem 'newsgroups)
  1717. (when (gnus-string-equal
  1718. (gnus-fetch-field "newsgroups")
  1719. (gnus-group-real-name
  1720. (if (boundp 'gnus-newsgroup-name)
  1721. gnus-newsgroup-name
  1722. "")))
  1723. (gnus-article-hide-header "newsgroups")))
  1724. ((eq elem 'to-address)
  1725. (let ((to (message-fetch-field "to"))
  1726. (to-address
  1727. (gnus-parameter-to-address
  1728. (if (boundp 'gnus-newsgroup-name)
  1729. gnus-newsgroup-name ""))))
  1730. (when (and to to-address
  1731. (ignore-errors
  1732. (gnus-string-equal
  1733. ;; only one address in To
  1734. (nth 1 (mail-extract-address-components to))
  1735. to-address)))
  1736. (gnus-article-hide-header "to"))))
  1737. ((eq elem 'to-list)
  1738. (let ((to (message-fetch-field "to"))
  1739. (to-list
  1740. (gnus-parameter-to-list
  1741. (if (boundp 'gnus-newsgroup-name)
  1742. gnus-newsgroup-name ""))))
  1743. (when (and to to-list
  1744. (ignore-errors
  1745. (gnus-string-equal
  1746. ;; only one address in To
  1747. (nth 1 (mail-extract-address-components to))
  1748. to-list)))
  1749. (gnus-article-hide-header "to"))))
  1750. ((eq elem 'cc-list)
  1751. (let ((cc (message-fetch-field "cc"))
  1752. (to-list
  1753. (gnus-parameter-to-list
  1754. (if (boundp 'gnus-newsgroup-name)
  1755. gnus-newsgroup-name ""))))
  1756. (when (and cc to-list
  1757. (ignore-errors
  1758. (gnus-string-equal
  1759. ;; only one address in CC
  1760. (nth 1 (mail-extract-address-components cc))
  1761. to-list)))
  1762. (gnus-article-hide-header "cc"))))
  1763. ((eq elem 'followup-to)
  1764. (when (gnus-string-equal
  1765. (message-fetch-field "followup-to")
  1766. (message-fetch-field "newsgroups"))
  1767. (gnus-article-hide-header "followup-to")))
  1768. ((eq elem 'reply-to)
  1769. (if (gnus-group-find-parameter
  1770. gnus-newsgroup-name 'broken-reply-to)
  1771. (gnus-article-hide-header "reply-to")
  1772. (let ((from (message-fetch-field "from"))
  1773. (reply-to (message-fetch-field "reply-to")))
  1774. (when
  1775. (and
  1776. from reply-to
  1777. (ignore-errors
  1778. (equal
  1779. (sort (mapcar
  1780. (lambda (x) (downcase (cadr x)))
  1781. (mail-extract-address-components from t))
  1782. 'string<)
  1783. (sort (mapcar
  1784. (lambda (x) (downcase (cadr x)))
  1785. (mail-extract-address-components reply-to t))
  1786. 'string<))))
  1787. (gnus-article-hide-header "reply-to")))))
  1788. ((eq elem 'date)
  1789. (let ((date (with-current-buffer gnus-original-article-buffer
  1790. ;; If date in `gnus-article-buffer' is localized
  1791. ;; (`gnus-treat-date-user-defined'),
  1792. ;; `days-between' might fail.
  1793. (message-fetch-field "date"))))
  1794. (when (and date
  1795. (< (days-between (current-time-string) date)
  1796. 4))
  1797. (gnus-article-hide-header "date"))))
  1798. ((eq elem 'long-to)
  1799. (let ((to (message-fetch-field "to"))
  1800. (cc (message-fetch-field "cc")))
  1801. (when (> (length to) 1024)
  1802. (gnus-article-hide-header "to"))
  1803. (when (> (length cc) 1024)
  1804. (gnus-article-hide-header "cc"))))
  1805. ((eq elem 'many-to)
  1806. (let ((to-count 0)
  1807. (cc-count 0))
  1808. (goto-char (point-min))
  1809. (while (re-search-forward "^to:" nil t)
  1810. (setq to-count (1+ to-count)))
  1811. (when (> to-count 1)
  1812. (while (> to-count 0)
  1813. (goto-char (point-min))
  1814. (save-restriction
  1815. (re-search-forward "^to:" nil nil to-count)
  1816. (forward-line -1)
  1817. (narrow-to-region (point) (point-max))
  1818. (gnus-article-hide-header "to"))
  1819. (setq to-count (1- to-count))))
  1820. (goto-char (point-min))
  1821. (while (re-search-forward "^cc:" nil t)
  1822. (setq cc-count (1+ cc-count)))
  1823. (when (> cc-count 1)
  1824. (while (> cc-count 0)
  1825. (goto-char (point-min))
  1826. (save-restriction
  1827. (re-search-forward "^cc:" nil nil cc-count)
  1828. (forward-line -1)
  1829. (narrow-to-region (point) (point-max))
  1830. (gnus-article-hide-header "cc"))
  1831. (setq cc-count (1- cc-count)))))))))))))
  1832. (defun gnus-article-hide-header (header)
  1833. (save-excursion
  1834. (goto-char (point-min))
  1835. (when (re-search-forward (concat "^" header ":") nil t)
  1836. (gnus-article-hide-text-type
  1837. (point-at-bol)
  1838. (progn
  1839. (end-of-line)
  1840. (if (re-search-forward "^[^ \t]" nil t)
  1841. (match-beginning 0)
  1842. (point-max)))
  1843. 'boring-headers))))
  1844. (defvar gnus-article-normalized-header-length 40
  1845. "Length of normalized headers.")
  1846. (defun article-normalize-headers ()
  1847. "Make all header lines 40 characters long."
  1848. (interactive)
  1849. (let ((inhibit-read-only t)
  1850. column)
  1851. (save-excursion
  1852. (save-restriction
  1853. (article-narrow-to-head)
  1854. (while (not (eobp))
  1855. (cond
  1856. ((< (setq column (- (point-at-eol) (point)))
  1857. gnus-article-normalized-header-length)
  1858. (end-of-line)
  1859. (insert (make-string
  1860. (- gnus-article-normalized-header-length column)
  1861. ? )))
  1862. ((> column gnus-article-normalized-header-length)
  1863. (gnus-put-text-property
  1864. (progn
  1865. (forward-char gnus-article-normalized-header-length)
  1866. (point))
  1867. (point-at-eol)
  1868. 'invisible t))
  1869. (t
  1870. ;; Do nothing.
  1871. ))
  1872. (forward-line 1))))))
  1873. (defun article-treat-dumbquotes ()
  1874. "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
  1875. Note that this function guesses whether a character is a sm*rtq**t* or
  1876. not, so it should only be used interactively.
  1877. Sm*rtq**t*s are M****s***'s unilateral extension to the
  1878. iso-8859-1 character map in an attempt to provide more quoting
  1879. characters. If you see something like \\222 or \\264 where
  1880. you're expecting some kind of apostrophe or quotation mark, then
  1881. try this wash."
  1882. (interactive)
  1883. (article-translate-strings gnus-article-dumbquotes-map))
  1884. (defvar org-entities)
  1885. (defun article-treat-non-ascii ()
  1886. "Translate many Unicode characters into their ASCII equivalents."
  1887. (interactive)
  1888. (require 'org-entities)
  1889. (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
  1890. (dolist (elem org-entities)
  1891. (when (and (listp elem)
  1892. (= (length (nth 6 elem)) 1))
  1893. (if (featurep 'xemacs)
  1894. (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
  1895. (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
  1896. (save-excursion
  1897. (when (article-goto-body)
  1898. (let ((inhibit-read-only t)
  1899. replace props)
  1900. (while (not (eobp))
  1901. (if (not (setq replace (if (featurep 'xemacs)
  1902. (get-char-table (following-char) table)
  1903. (aref table (following-char)))))
  1904. (forward-char 1)
  1905. (if (prog1
  1906. (setq props (text-properties-at (point)))
  1907. (delete-char 1))
  1908. (add-text-properties (point) (progn (insert replace) (point))
  1909. props)
  1910. (insert replace)))))))))
  1911. (defun article-translate-strings (map)
  1912. "Translate all string in the body of the article according to MAP.
  1913. MAP is an alist where the elements are on the form (\"from\" \"to\")."
  1914. (save-excursion
  1915. (when (article-goto-body)
  1916. (let ((inhibit-read-only t))
  1917. (dolist (elem map)
  1918. (let ((from (car elem))
  1919. (to (cadr elem)))
  1920. (save-excursion
  1921. (if (stringp from)
  1922. (while (search-forward from nil t)
  1923. (replace-match to))
  1924. (while (not (eobp))
  1925. (if (eq (following-char) from)
  1926. (progn
  1927. (delete-char 1)
  1928. (insert to))
  1929. (forward-char 1)))))))))))
  1930. (defun article-treat-overstrike ()
  1931. "Translate overstrikes into bold text."
  1932. (interactive)
  1933. (save-excursion
  1934. (when (article-goto-body)
  1935. (let ((inhibit-read-only t))
  1936. (while (search-forward "\b" nil t)
  1937. (let ((next (char-after))
  1938. (previous (char-after (- (point) 2))))
  1939. ;; We do the boldification/underlining by hiding the
  1940. ;; overstrikes and putting the proper text property
  1941. ;; on the letters.
  1942. (cond
  1943. ((eq next previous)
  1944. (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
  1945. (put-text-property (point) (1+ (point)) 'face 'bold))
  1946. ((eq next ?_)
  1947. (gnus-article-hide-text-type
  1948. (1- (point)) (1+ (point)) 'overstrike)
  1949. (put-text-property
  1950. (- (point) 2) (1- (point)) 'face 'underline))
  1951. ((eq previous ?_)
  1952. (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
  1953. (put-text-property
  1954. (point) (1+ (point)) 'face 'underline)))))))))
  1955. (defun article-treat-ansi-sequences ()
  1956. "Translate ANSI SGR control sequences into overlays or extents."
  1957. (interactive)
  1958. (save-excursion
  1959. (when (article-goto-body)
  1960. (let ((inhibit-read-only t))
  1961. (ansi-color-apply-on-region (point) (point-max))))))
  1962. (defun gnus-article-treat-unfold-headers ()
  1963. "Unfold folded message headers.
  1964. Only the headers that fit into the current window width will be
  1965. unfolded."
  1966. (interactive)
  1967. (gnus-with-article-headers
  1968. (let (length)
  1969. (while (not (eobp))
  1970. (save-restriction
  1971. (mail-header-narrow-to-field)
  1972. (let* ((header (buffer-string))
  1973. (unfoldable
  1974. (or (equal gnus-article-unfold-long-headers t)
  1975. (and (stringp gnus-article-unfold-long-headers)
  1976. (string-match gnus-article-unfold-long-headers
  1977. header)))))
  1978. (with-temp-buffer
  1979. (insert header)
  1980. (goto-char (point-min))
  1981. (while (re-search-forward "\n[\t ]" nil t)
  1982. (replace-match " " t t)))
  1983. (setq length (- (point-max) (point-min) 1))
  1984. (when (or unfoldable
  1985. (< length (window-width)))
  1986. (while (re-search-forward "\n[\t ]" nil t)
  1987. (replace-match " " t t))))
  1988. (goto-char (point-max)))))))
  1989. (defun gnus-article-treat-fold-headers ()
  1990. "Fold message headers."
  1991. (interactive)
  1992. (gnus-with-article-headers
  1993. (while (not (eobp))
  1994. (save-restriction
  1995. (mail-header-narrow-to-field)
  1996. (mail-header-fold-field)
  1997. (goto-char (point-max))))))
  1998. (defun gnus-treat-smiley ()
  1999. "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
  2000. (interactive)
  2001. (gnus-with-article-buffer
  2002. (if (memq 'smiley gnus-article-wash-types)
  2003. (gnus-delete-images 'smiley)
  2004. (article-goto-body)
  2005. (let ((images (smiley-region (point) (point-max))))
  2006. (when images
  2007. (gnus-add-wash-type 'smiley)
  2008. (dolist (image images)
  2009. (gnus-add-image 'smiley image)))))))
  2010. (defun gnus-article-remove-images ()
  2011. "Remove all images from the article buffer."
  2012. (interactive)
  2013. (gnus-with-article-buffer
  2014. (save-restriction
  2015. (widen)
  2016. (dolist (elem gnus-article-image-alist)
  2017. (gnus-delete-images (car elem))))))
  2018. (autoload 'w3m-toggle-inline-images "w3m")
  2019. (defun gnus-article-show-images ()
  2020. "Show any images that are in the HTML-rendered article buffer.
  2021. This only works if the article in question is HTML."
  2022. (interactive)
  2023. (gnus-with-article-buffer
  2024. (save-restriction
  2025. (widen)
  2026. (if (eq mm-text-html-renderer 'w3m)
  2027. (w3m-toggle-inline-images)
  2028. (dolist (region (gnus-find-text-property-region (point-min) (point-max)
  2029. 'image-displayer))
  2030. (destructuring-bind (start end function) region
  2031. (funcall function (get-text-property start 'image-url)
  2032. start end)))))))
  2033. (defun gnus-article-treat-fold-newsgroups ()
  2034. "Unfold folded message headers.
  2035. Only the headers that fit into the current window width will be
  2036. unfolded."
  2037. (interactive)
  2038. (gnus-with-article-headers
  2039. (while (gnus-article-goto-header "newsgroups\\|followup-to")
  2040. (save-restriction
  2041. (mail-header-narrow-to-field)
  2042. (while (re-search-forward ", *" nil t)
  2043. (replace-match ", " t t))
  2044. (mail-header-fold-field)
  2045. (goto-char (point-max))))))
  2046. (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
  2047. "Value of `truncate-lines' in Gnus Article buffer.
  2048. Valid values are nil, t, `head', `first', `last', an integer or a
  2049. predicate. See Info node `(gnus)Customizing Articles'."
  2050. :version "23.1" ;; No Gnus
  2051. :group 'gnus-article
  2052. ;; :link '(custom-manual "(gnus)Customizing Articles")
  2053. :type 'boolean)
  2054. (defun gnus-article-toggle-truncate-lines (&optional arg)
  2055. "Toggle whether to fold or truncate long lines in article the buffer.
  2056. If ARG is non-nil and not a number, toggle
  2057. `gnus-article-truncate-lines' too. If ARG is a number, truncate
  2058. long lines if and only if arg is positive."
  2059. (interactive "P")
  2060. (cond
  2061. ((and (numberp arg) (> arg 0))
  2062. (setq gnus-article-truncate-lines t))
  2063. ((numberp arg)
  2064. (setq gnus-article-truncate-lines nil))
  2065. (arg
  2066. (setq gnus-article-truncate-lines
  2067. (not gnus-article-truncate-lines))))
  2068. (gnus-with-article-buffer
  2069. (cond
  2070. ((and (numberp arg) (> arg 0))
  2071. (setq truncate-lines nil))
  2072. ((numberp arg)
  2073. (setq truncate-lines t)))
  2074. ;; In versions of Emacs 22 (CVS) before 2006-05-26,
  2075. ;; `toggle-truncate-lines' needs an argument.
  2076. (toggle-truncate-lines)))
  2077. (defun gnus-article-treat-body-boundary ()
  2078. "Place a boundary line at the end of the headers."
  2079. (interactive)
  2080. (when (and gnus-body-boundary-delimiter
  2081. (> (length gnus-body-boundary-delimiter) 0))
  2082. (gnus-with-article-headers
  2083. (goto-char (point-max))
  2084. (let ((start (point)))
  2085. (insert "X-Boundary: ")
  2086. (gnus-add-text-properties start (point) gnus-hidden-properties)
  2087. (insert (let (str (max (window-width)))
  2088. (if (featurep 'xemacs)
  2089. (setq max (1- max)))
  2090. (while (>= max (length str))
  2091. (setq str (concat str gnus-body-boundary-delimiter)))
  2092. (substring str 0 max))
  2093. "\n")
  2094. (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
  2095. (defun article-fill-long-lines ()
  2096. "Fill lines that are wider than the window width."
  2097. (interactive)
  2098. (save-excursion
  2099. (let ((inhibit-read-only t)
  2100. (width (window-width (get-buffer-window (current-buffer)))))
  2101. (save-restriction
  2102. (article-goto-body)
  2103. (let ((adaptive-fill-mode nil)) ;Why? -sm
  2104. (while (not (eobp))
  2105. (end-of-line)
  2106. (when (>= (current-column) (min fill-column width))
  2107. (narrow-to-region (min (1+ (point)) (point-max))
  2108. (point-at-bol))
  2109. (let ((goback (point-marker)))
  2110. (fill-paragraph nil)
  2111. (goto-char (marker-position goback)))
  2112. (widen))
  2113. (forward-line 1)))))))
  2114. (defun article-capitalize-sentences ()
  2115. "Capitalize the first word in each sentence."
  2116. (interactive)
  2117. (save-excursion
  2118. (let ((inhibit-read-only t)
  2119. (paragraph-start "^[\n\^L]"))
  2120. (article-goto-body)
  2121. (while (not (eobp))
  2122. (capitalize-word 1)
  2123. (forward-sentence)))))
  2124. (defun article-remove-cr ()
  2125. "Remove trailing CRs and then translate remaining CRs into LFs."
  2126. (interactive)
  2127. (save-excursion
  2128. (let ((inhibit-read-only t))
  2129. (goto-char (point-min))
  2130. (while (re-search-forward "\r+$" nil t)
  2131. (replace-match "" t t))
  2132. (goto-char (point-min))
  2133. (while (search-forward "\r" nil t)
  2134. (replace-match "\n" t t)))))
  2135. (defun article-remove-trailing-blank-lines ()
  2136. "Remove all trailing blank lines from the article."
  2137. (interactive)
  2138. (save-excursion
  2139. (let ((inhibit-read-only t))
  2140. (goto-char (point-max))
  2141. (delete-region
  2142. (point)
  2143. (progn
  2144. (while (and (not (bobp))
  2145. (looking-at "^[ \t]*$")
  2146. (not (gnus-annotation-in-region-p
  2147. (point) (point-at-eol))))
  2148. (forward-line -1))
  2149. (forward-line 1)
  2150. (point))))))
  2151. (defvar gnus-face-properties-alist)
  2152. (defun article-display-face (&optional force)
  2153. "Display any Face headers in the header."
  2154. (interactive (list 'force))
  2155. (let ((wash-face-p buffer-read-only))
  2156. (gnus-with-article-headers
  2157. ;; When displaying parts, this function can be called several times on
  2158. ;; the same article, without any intended toggle semantic (as typing `W
  2159. ;; D d' would have). So face deletion must occur only when we come from
  2160. ;; an interactive command, that is when the *Article* buffer is
  2161. ;; read-only.
  2162. (if (and wash-face-p (memq 'face gnus-article-wash-types))
  2163. (gnus-delete-images 'face)
  2164. (let ((from (message-fetch-field "from"))
  2165. faces)
  2166. (save-current-buffer
  2167. (when (and wash-face-p
  2168. (gnus-buffer-live-p gnus-original-article-buffer)
  2169. (not (re-search-forward "^Face:[\t ]*" nil t)))
  2170. (set-buffer gnus-original-article-buffer))
  2171. (save-restriction
  2172. (mail-narrow-to-head)
  2173. (when (or force
  2174. ;; Check whether this face is censored.
  2175. (not (and gnus-article-x-face-too-ugly
  2176. (or from
  2177. (setq from (message-fetch-field "from")))
  2178. (string-match gnus-article-x-face-too-ugly
  2179. from))))
  2180. (while (gnus-article-goto-header "Face")
  2181. (push (mail-header-field-value) faces)))))
  2182. (when faces
  2183. (goto-char (point-min))
  2184. (let (png image)
  2185. (unless (setq from (gnus-article-goto-header "from"))
  2186. (insert "From:")
  2187. (setq from (point))
  2188. (insert " [no 'from' set]\n"))
  2189. (while faces
  2190. (when (setq png (gnus-convert-face-to-png (pop faces)))
  2191. (setq image
  2192. (apply 'gnus-create-image png 'png t
  2193. (cdr (assq 'png gnus-face-properties-alist))))
  2194. (goto-char from)
  2195. (when image
  2196. (gnus-add-wash-type 'face)
  2197. (gnus-add-image 'face image)
  2198. (gnus-put-image image nil 'face)))))))))))
  2199. (defun article-display-x-face (&optional force)
  2200. "Look for an X-Face header and display it if present."
  2201. (interactive (list 'force))
  2202. (let ((wash-face-p buffer-read-only)) ;; When type `W f'
  2203. (gnus-with-article-headers
  2204. ;; Delete the old process, if any.
  2205. (when (process-status "article-x-face")
  2206. (delete-process "article-x-face"))
  2207. ;; See the comment in `article-display-face'.
  2208. (if (and wash-face-p (memq 'xface gnus-article-wash-types))
  2209. ;; We have already displayed X-Faces, so we remove them
  2210. ;; instead.
  2211. (gnus-delete-images 'xface)
  2212. ;; Display X-Faces.
  2213. (let ((from (message-fetch-field "from"))
  2214. x-faces)
  2215. (save-current-buffer
  2216. (when (and wash-face-p
  2217. (gnus-buffer-live-p gnus-original-article-buffer)
  2218. (not (re-search-forward "^X-Face:[\t ]*" nil t)))
  2219. ;; If type `W f', use gnus-original-article-buffer,
  2220. ;; otherwise use the current buffer because displaying
  2221. ;; RFC822 parts calls this function too.
  2222. (set-buffer gnus-original-article-buffer))
  2223. (save-restriction
  2224. (mail-narrow-to-head)
  2225. (and gnus-article-x-face-command
  2226. (or force
  2227. ;; Check whether this face is censored.
  2228. (not (and gnus-article-x-face-too-ugly
  2229. (or from
  2230. (setq from (message-fetch-field "from")))
  2231. (string-match gnus-article-x-face-too-ugly
  2232. from))))
  2233. (while (gnus-article-goto-header "X-Face")
  2234. (push (mail-header-field-value) x-faces)))))
  2235. (when x-faces
  2236. ;; We display the face.
  2237. (cond ((functionp gnus-article-x-face-command)
  2238. ;; The command is a lisp function, so we call it.
  2239. (mapc gnus-article-x-face-command x-faces))
  2240. ((stringp gnus-article-x-face-command)
  2241. ;; The command is a string, so we interpret the command
  2242. ;; as a, well, command, and fork it off.
  2243. (let ((process-connection-type nil))
  2244. (gnus-set-process-query-on-exit-flag
  2245. (start-process
  2246. "article-x-face" nil shell-file-name
  2247. shell-command-switch gnus-article-x-face-command)
  2248. nil)
  2249. ;; Sending multiple EOFs to xv doesn't work,
  2250. ;; so we only do a single external face.
  2251. (with-temp-buffer
  2252. (insert (car x-faces))
  2253. (process-send-region "article-x-face"
  2254. (point-min) (point-max)))
  2255. (process-send-eof "article-x-face")))
  2256. (t
  2257. (error "`%s' set to `%s' is not a function"
  2258. gnus-article-x-face-command
  2259. 'gnus-article-x-face-command)))))))))
  2260. (defun article-decode-mime-words ()
  2261. "Decode all MIME-encoded words in the article."
  2262. (interactive)
  2263. (gnus-with-article-buffer
  2264. (let ((inhibit-point-motion-hooks t)
  2265. (mail-parse-charset gnus-newsgroup-charset)
  2266. (mail-parse-ignored-charsets
  2267. (with-current-buffer gnus-summary-buffer
  2268. gnus-newsgroup-ignored-charsets)))
  2269. (mail-decode-encoded-word-region (point-min) (point-max)))))
  2270. (defun article-decode-charset (&optional prompt)
  2271. "Decode charset-encoded text in the article.
  2272. If PROMPT (the prefix), prompt for a coding system to use."
  2273. (interactive "P")
  2274. (let ((inhibit-point-motion-hooks t) (case-fold-search t)
  2275. (inhibit-read-only t)
  2276. (mail-parse-charset gnus-newsgroup-charset)
  2277. (mail-parse-ignored-charsets
  2278. (save-excursion (condition-case nil
  2279. (set-buffer gnus-summary-buffer)
  2280. (error))
  2281. gnus-newsgroup-ignored-charsets))
  2282. ct cte ctl charset format)
  2283. (save-excursion
  2284. (save-restriction
  2285. (article-narrow-to-head)
  2286. (setq ct (message-fetch-field "Content-Type" t)
  2287. cte (message-fetch-field "Content-Transfer-Encoding" t)
  2288. ctl (and ct (mail-header-parse-content-type ct))
  2289. charset (cond
  2290. (prompt
  2291. (mm-read-coding-system "Charset to decode: "))
  2292. (ctl
  2293. (mail-content-type-get ctl 'charset)))
  2294. format (and ctl (mail-content-type-get ctl 'format)))
  2295. (when cte
  2296. (setq cte (mail-header-strip cte)))
  2297. (if (and ctl (not (string-match "/" (car ctl))))
  2298. (setq ctl nil))
  2299. (goto-char (point-max)))
  2300. (forward-line 1)
  2301. (save-restriction
  2302. (narrow-to-region (point) (point-max))
  2303. (when (and (eq mail-parse-charset 'gnus-decoded)
  2304. (eq (mm-body-7-or-8) '8bit))
  2305. ;; The text code could have been decoded.
  2306. (setq charset mail-parse-charset))
  2307. (when (and (or (not ctl)
  2308. (equal (car ctl) "text/plain"))
  2309. (not format)) ;; article with format will decode later.
  2310. (mm-decode-body
  2311. charset (and cte (intern (downcase
  2312. (gnus-strip-whitespace cte))))
  2313. (car ctl)))))))
  2314. (defun article-decode-encoded-words ()
  2315. "Remove encoded-word encoding from headers."
  2316. (let ((inhibit-point-motion-hooks t)
  2317. (mail-parse-charset gnus-newsgroup-charset)
  2318. (mail-parse-ignored-charsets
  2319. (save-excursion (condition-case nil
  2320. (set-buffer gnus-summary-buffer)
  2321. (error))
  2322. gnus-newsgroup-ignored-charsets))
  2323. (inhibit-read-only t)
  2324. end start)
  2325. (goto-char (point-min))
  2326. (when (search-forward "\n\n" nil 'move)
  2327. (forward-line -1))
  2328. (setq end (point))
  2329. (while (not (bobp))
  2330. (while (progn
  2331. (forward-line -1)
  2332. (and (not (bobp))
  2333. (memq (char-after) '(?\t ? )))))
  2334. (setq start (point))
  2335. (if (looking-at "\
  2336. \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
  2337. \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
  2338. (funcall gnus-decode-address-function start end)
  2339. (funcall gnus-decode-header-function start end))
  2340. (goto-char (setq end start)))))
  2341. (defun article-decode-group-name ()
  2342. "Decode group names in Newsgroups, Followup-To and Xref headers."
  2343. (let ((inhibit-point-motion-hooks t)
  2344. (inhibit-read-only t)
  2345. (method (gnus-find-method-for-group gnus-newsgroup-name))
  2346. regexp)
  2347. (when (and (or gnus-group-name-charset-method-alist
  2348. gnus-group-name-charset-group-alist)
  2349. (gnus-buffer-live-p gnus-original-article-buffer))
  2350. (save-restriction
  2351. (article-narrow-to-head)
  2352. (dolist (header '("Newsgroups" "Followup-To" "Xref"))
  2353. (with-current-buffer gnus-original-article-buffer
  2354. (goto-char (point-min)))
  2355. (setq regexp (concat "^" header
  2356. ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
  2357. (while (re-search-forward regexp nil t)
  2358. (replace-match (save-match-data
  2359. (gnus-decode-newsgroups
  2360. ;; XXX how to use data in article buffer?
  2361. (with-current-buffer gnus-original-article-buffer
  2362. (re-search-forward regexp nil t)
  2363. (match-string 1))
  2364. gnus-newsgroup-name method))
  2365. t t nil 1))
  2366. (goto-char (point-min)))))))
  2367. (autoload 'idna-to-unicode "idna")
  2368. (defun article-decode-idna-rhs ()
  2369. "Decode IDNA strings in RHS in various headers in current buffer.
  2370. The following headers are decoded: From:, To:, Cc:, Reply-To:,
  2371. Mail-Reply-To: and Mail-Followup-To:."
  2372. (when gnus-use-idna
  2373. (save-restriction
  2374. (let ((inhibit-point-motion-hooks t)
  2375. (inhibit-read-only t))
  2376. (article-narrow-to-head)
  2377. (goto-char (point-min))
  2378. (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
  2379. (let (ace unicode)
  2380. (when (save-match-data
  2381. (and (setq ace (match-string 1))
  2382. (save-excursion
  2383. (and (re-search-backward "^[^ \t]" nil t)
  2384. (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
  2385. (setq unicode (idna-to-unicode ace))))
  2386. (unless (string= ace unicode)
  2387. (replace-match unicode nil nil nil 1)))))))))
  2388. (defun article-de-quoted-unreadable (&optional force read-charset)
  2389. "Translate a quoted-printable-encoded article.
  2390. If FORCE, decode the article whether it is marked as quoted-printable
  2391. or not.
  2392. If READ-CHARSET, ask for a coding system."
  2393. (interactive (list 'force current-prefix-arg))
  2394. (save-excursion
  2395. (let ((inhibit-read-only t) type charset)
  2396. (if (gnus-buffer-live-p gnus-original-article-buffer)
  2397. (with-current-buffer gnus-original-article-buffer
  2398. (setq type
  2399. (gnus-fetch-field "content-transfer-encoding"))
  2400. (let* ((ct (gnus-fetch-field "content-type"))
  2401. (ctl (and ct (mail-header-parse-content-type ct))))
  2402. (setq charset (and ctl
  2403. (mail-content-type-get ctl 'charset)))
  2404. (if (stringp charset)
  2405. (setq charset (intern (downcase charset)))))))
  2406. (if read-charset
  2407. (setq charset (mm-read-coding-system "Charset: " charset)))
  2408. (unless charset
  2409. (setq charset gnus-newsgroup-charset))
  2410. (when (or force
  2411. (and type (let ((case-fold-search t))
  2412. (string-match "quoted-printable" type))))
  2413. (article-goto-body)
  2414. (quoted-printable-decode-region
  2415. (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
  2416. (defun article-de-base64-unreadable (&optional force read-charset)
  2417. "Translate a base64 article.
  2418. If FORCE, decode the article whether it is marked as base64 not.
  2419. If READ-CHARSET, ask for a coding system."
  2420. (interactive (list 'force current-prefix-arg))
  2421. (save-excursion
  2422. (let ((inhibit-read-only t) type charset)
  2423. (if (gnus-buffer-live-p gnus-original-article-buffer)
  2424. (with-current-buffer gnus-original-article-buffer
  2425. (setq type
  2426. (gnus-fetch-field "content-transfer-encoding"))
  2427. (let* ((ct (gnus-fetch-field "content-type"))
  2428. (ctl (and ct (mail-header-parse-content-type ct))))
  2429. (setq charset (and ctl
  2430. (mail-content-type-get ctl 'charset)))
  2431. (if (stringp charset)
  2432. (setq charset (intern (downcase charset)))))))
  2433. (if read-charset
  2434. (setq charset (mm-read-coding-system "Charset: " charset)))
  2435. (unless charset
  2436. (setq charset gnus-newsgroup-charset))
  2437. (when (or force
  2438. (and type (let ((case-fold-search t))
  2439. (string-match "base64" type))))
  2440. (article-goto-body)
  2441. (save-restriction
  2442. (narrow-to-region (point) (point-max))
  2443. (base64-decode-region (point-min) (point-max))
  2444. (mm-decode-coding-region
  2445. (point-min) (point-max)
  2446. (mm-charset-to-coding-system charset nil t)))))))
  2447. (eval-when-compile
  2448. (require 'rfc1843))
  2449. (defun article-decode-HZ ()
  2450. "Translate a HZ-encoded article."
  2451. (interactive)
  2452. (require 'rfc1843)
  2453. (save-excursion
  2454. (let ((inhibit-read-only t))
  2455. (rfc1843-decode-region (point-min) (point-max)))))
  2456. (defun article-unsplit-urls ()
  2457. "Remove the newlines that some other mailers insert into URLs."
  2458. (interactive)
  2459. (save-excursion
  2460. (let ((inhibit-read-only t))
  2461. (goto-char (point-min))
  2462. (while (re-search-forward
  2463. "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
  2464. (replace-match "\\1\\3" t)))
  2465. (when (gmm-called-interactively-p 'any)
  2466. (gnus-treat-article nil))))
  2467. (defun article-wash-html ()
  2468. "Format an HTML article."
  2469. (interactive)
  2470. (let ((handles nil)
  2471. (buffer-read-only nil))
  2472. (when (gnus-buffer-live-p gnus-original-article-buffer)
  2473. (with-current-buffer gnus-original-article-buffer
  2474. (setq handles (mm-dissect-buffer t t))))
  2475. (article-goto-body)
  2476. (delete-region (point) (point-max))
  2477. (mm-enable-multibyte)
  2478. (mm-inline-text-html handles)))
  2479. (defvar gnus-article-browse-html-temp-list nil
  2480. "List of temporary files created by `gnus-article-browse-html-parts'.
  2481. Internal variable.")
  2482. (defcustom gnus-article-browse-delete-temp 'ask
  2483. "What to do with temporary files from `gnus-article-browse-html-parts'.
  2484. If nil, don't delete temporary files. If it is t, delete them on
  2485. exit from the summary buffer. If it is the symbol `file', query
  2486. on each file, if it is `ask' ask once when exiting from the
  2487. summary buffer."
  2488. :group 'gnus-article
  2489. :version "23.1" ;; No Gnus
  2490. :type '(choice (const :tag "Don't delete" nil)
  2491. (const :tag "Don't ask" t)
  2492. (const :tag "Ask" ask)
  2493. (const :tag "Ask for each file" file)))
  2494. ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
  2495. (defun gnus-article-browse-delete-temp-files (&optional how)
  2496. "Delete temp-files created by `gnus-article-browse-html-parts'."
  2497. (when (and gnus-article-browse-html-temp-list
  2498. (progn
  2499. (or how (setq how gnus-article-browse-delete-temp))
  2500. (if (eq how 'ask)
  2501. (let ((files (length gnus-article-browse-html-temp-list)))
  2502. (or (gnus-y-or-n-p
  2503. (if (= files 1)
  2504. "Delete the temporary HTML file? "
  2505. (format "Delete all %s temporary HTML files? "
  2506. files)))
  2507. (setq gnus-article-browse-html-temp-list nil)))
  2508. how)))
  2509. (dolist (file gnus-article-browse-html-temp-list)
  2510. (cond ((file-directory-p file)
  2511. (when (or (not (eq how 'file))
  2512. (gnus-y-or-n-p
  2513. (gnus-format-message
  2514. "Delete temporary HTML file(s) in directory `%s'? "
  2515. (file-name-as-directory file))))
  2516. (gnus-delete-directory file)))
  2517. ((file-exists-p file)
  2518. (when (or (not (eq how 'file))
  2519. (gnus-y-or-n-p
  2520. (format "Delete temporary HTML file `%s'? " file)))
  2521. (delete-file file)))))
  2522. ;; Also remove file from the list when not deleted or if file doesn't
  2523. ;; exist anymore.
  2524. (setq gnus-article-browse-html-temp-list nil))
  2525. gnus-article-browse-html-temp-list)
  2526. (defun gnus-article-browse-html-save-cid-content (cid handles directory)
  2527. "Find CID content in HANDLES and save it in a file in DIRECTORY.
  2528. Return file name relative to the parent of DIRECTORY."
  2529. (save-match-data
  2530. (let (file afile)
  2531. (catch 'found
  2532. (dolist (handle handles)
  2533. (cond
  2534. ((not (listp handle)))
  2535. ;; Exclude broken handles that `gnus-summary-enter-digest-group'
  2536. ;; may create.
  2537. ((not (or (bufferp (car handle)) (stringp (car handle)))))
  2538. ((equal (mm-handle-media-supertype handle) "multipart")
  2539. (when (setq file (gnus-article-browse-html-save-cid-content
  2540. cid handle directory))
  2541. (throw 'found file)))
  2542. ((equal (concat "<" cid ">") (mm-handle-id handle))
  2543. (setq file (or (mm-handle-filename handle)
  2544. (concat
  2545. (make-temp-name "cid")
  2546. (car (rassoc (car (mm-handle-type handle))
  2547. mailcap-mime-extensions))))
  2548. afile (expand-file-name file directory))
  2549. (mm-save-part-to-file handle afile)
  2550. (throw 'found (concat (file-name-nondirectory
  2551. (directory-file-name directory))
  2552. "/" file)))))))))
  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 content cid-dir 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 (mm-handle-filename handle)))
  2567. (or (mm-handle-cache handle)
  2568. (condition-case code
  2569. (progn (mm-extern-cache-contents handle) t)
  2570. (error
  2571. (gnus-message 3 "%s" (error-message-string code))
  2572. (when (>= gnus-verbose 3) (sit-for 2))
  2573. nil)))
  2574. (progn
  2575. (setq handle (mm-handle-cache handle)
  2576. type (mm-handle-type handle))
  2577. (equal (car type) "text/html"))))
  2578. (setq charset (mail-content-type-get type 'charset)
  2579. content (mm-get-part handle))
  2580. (with-temp-buffer
  2581. (if (eq charset 'gnus-decoded)
  2582. (mm-enable-multibyte)
  2583. (mm-disable-multibyte))
  2584. (insert content)
  2585. ;; resolve cid contents
  2586. (let ((case-fold-search t)
  2587. st base regexp cid-file)
  2588. (goto-char (point-min))
  2589. (when (and (re-search-forward "<head[\t\n >]" nil t)
  2590. (progn
  2591. (setq st (match-end 0))
  2592. (re-search-forward "</head[\t\n >]" nil t))
  2593. (re-search-backward "<base\
  2594. \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
  2595. (setq base (match-string 1))
  2596. (replace-match "<!--\\&-->")
  2597. (setq st (point))
  2598. (dolist (tag '(("a" . "href") ("form" . "action")
  2599. ("img" . "src")))
  2600. (setq regexp (concat "<" (car tag)
  2601. "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
  2602. (cdr tag) "=\"\\([^\"]+\\)"))
  2603. (while (re-search-forward regexp nil t)
  2604. (insert (prog1
  2605. (condition-case nil
  2606. (save-match-data
  2607. (url-expand-file-name (match-string 1)
  2608. base))
  2609. (error (match-string 1)))
  2610. (delete-region (match-beginning 1)
  2611. (match-end 1)))))
  2612. (goto-char st)))
  2613. (while (re-search-forward "\
  2614. <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
  2615. nil t)
  2616. (unless cid-dir
  2617. (setq cid-dir (mm-make-temp-file "cid" t))
  2618. (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
  2619. (setq file nil
  2620. content nil)
  2621. (when (setq cid-file
  2622. (gnus-article-browse-html-save-cid-content
  2623. (match-string 2)
  2624. (with-current-buffer gnus-article-buffer
  2625. gnus-article-mime-handles)
  2626. cid-dir))
  2627. (replace-match cid-file nil nil nil 1))))
  2628. (unless content (setq content (buffer-string))))
  2629. (when (or charset header (not file))
  2630. (setq tmp-file (mm-make-temp-file
  2631. ;; Do we need to care for 8.3 filenames?
  2632. "mm-" nil ".html")))
  2633. ;; Add a meta html tag to specify charset and a header.
  2634. (cond
  2635. (header
  2636. (let (title eheader body hcharset coding)
  2637. (with-temp-buffer
  2638. (mm-enable-multibyte)
  2639. (setq case-fold-search t)
  2640. (insert header "\n")
  2641. (setq title (message-fetch-field "subject"))
  2642. (goto-char (point-min))
  2643. (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
  2644. nil t)
  2645. (replace-match (cond ((match-beginning 1) "&lt;")
  2646. ((match-beginning 2) "&gt;")
  2647. ((match-beginning 3) "&amp;")
  2648. (t "<br>\n"))))
  2649. (goto-char (point-min))
  2650. (while (re-search-forward "^[\t ]+" nil t)
  2651. (dotimes (i (prog1
  2652. (current-column)
  2653. (delete-region (match-beginning 0)
  2654. (match-end 0))))
  2655. (insert "&nbsp;")))
  2656. (goto-char (point-min))
  2657. (insert "<div align=\"left\">\n")
  2658. (goto-char (point-max))
  2659. (insert "</div>\n<hr>\n")
  2660. ;; We have to examine charset one by one since
  2661. ;; charset specified in parts might be different.
  2662. (if (eq charset 'gnus-decoded)
  2663. (setq charset 'utf-8
  2664. eheader (mm-encode-coding-string (buffer-string)
  2665. charset)
  2666. title (when title
  2667. (mm-encode-coding-string title charset))
  2668. body (mm-encode-coding-string content charset))
  2669. (setq hcharset (mm-find-mime-charset-region (point-min)
  2670. (point-max)))
  2671. (cond ((= (length hcharset) 1)
  2672. (setq hcharset (car hcharset)
  2673. coding (mm-charset-to-coding-system
  2674. hcharset nil t)))
  2675. ((> (length hcharset) 1)
  2676. (setq hcharset 'utf-8
  2677. coding hcharset)))
  2678. (if coding
  2679. (if charset
  2680. (progn
  2681. (setq body
  2682. (mm-charset-to-coding-system charset
  2683. nil t))
  2684. (if (eq coding body)
  2685. (setq eheader (mm-encode-coding-string
  2686. (buffer-string) coding)
  2687. title (when title
  2688. (mm-encode-coding-string
  2689. title coding))
  2690. body content)
  2691. (setq charset 'utf-8
  2692. eheader (mm-encode-coding-string
  2693. (buffer-string) charset)
  2694. title (when title
  2695. (mm-encode-coding-string
  2696. title charset))
  2697. body (mm-encode-coding-string
  2698. (mm-decode-coding-string
  2699. content body)
  2700. charset))))
  2701. (setq charset hcharset
  2702. eheader (mm-encode-coding-string
  2703. (buffer-string) coding)
  2704. title (when title
  2705. (mm-encode-coding-string
  2706. title coding))
  2707. body content))
  2708. (setq eheader (mm-string-as-unibyte (buffer-string))
  2709. body content)))
  2710. (erase-buffer)
  2711. (mm-disable-multibyte)
  2712. (insert body)
  2713. (when charset
  2714. (mm-add-meta-html-tag handle charset t))
  2715. (when title
  2716. (goto-char (point-min))
  2717. (unless (search-forward "<title>" nil t)
  2718. (re-search-forward "<head>\\s-*" nil t)
  2719. (insert "<title>" title "</title>\n")))
  2720. (goto-char (point-min))
  2721. (or (re-search-forward
  2722. "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
  2723. (re-search-forward
  2724. "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
  2725. (insert eheader)
  2726. (mm-write-region (point-min) (point-max)
  2727. tmp-file nil nil nil 'binary t))))
  2728. (charset
  2729. (mm-with-unibyte-buffer
  2730. (insert (if (eq charset 'gnus-decoded)
  2731. (mm-encode-coding-string content
  2732. (setq charset 'utf-8))
  2733. content))
  2734. (if (or (mm-add-meta-html-tag handle charset)
  2735. (not file))
  2736. (mm-write-region (point-min) (point-max)
  2737. tmp-file nil nil nil 'binary t)
  2738. (setq tmp-file nil))))
  2739. (tmp-file
  2740. (mm-save-part-to-file handle tmp-file)))
  2741. (when tmp-file
  2742. (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
  2743. (add-hook 'gnus-summary-prepare-exit-hook
  2744. 'gnus-article-browse-delete-temp-files)
  2745. (add-hook 'gnus-exit-gnus-hook
  2746. (lambda ()
  2747. (gnus-article-browse-delete-temp-files t)))
  2748. ;; FIXME: Warn if there's an <img> tag?
  2749. (browse-url-of-file (or tmp-file (expand-file-name file)))
  2750. (setq showed t))
  2751. ;; If multipart, recurse
  2752. ((equal (mm-handle-media-supertype handle) "multipart")
  2753. (when (gnus-article-browse-html-parts handle header)
  2754. (setq showed t)))
  2755. ((equal (mm-handle-media-type handle) "message/rfc822")
  2756. (mm-with-multibyte-buffer
  2757. (mm-insert-part handle)
  2758. (setq handle (mm-dissect-buffer t t))
  2759. (when (and (bufferp (car handle))
  2760. (stringp (car (mm-handle-type handle))))
  2761. (setq handle (list handle)))
  2762. (when header
  2763. (article-decode-encoded-words)
  2764. (let ((gnus-visible-headers
  2765. (or (get 'gnus-visible-headers 'standard-value)
  2766. gnus-visible-headers)))
  2767. (article-hide-headers))
  2768. (goto-char (point-min))
  2769. (search-forward "\n\n" nil 'move)
  2770. (skip-chars-backward "\t\n ")
  2771. (setq header (buffer-substring (point-min) (point)))))
  2772. (when (prog1
  2773. (gnus-article-browse-html-parts handle header)
  2774. (mm-destroy-parts handle))
  2775. (setq showed t)))))
  2776. showed))
  2777. (defun gnus-article-browse-html-article (&optional arg)
  2778. "View \"text/html\" parts of the current article with a WWW browser.
  2779. Inline images embedded in a message using the cid scheme, as they are
  2780. generally considered to be safe, will be processed properly.
  2781. The message header is added to the beginning of every html part unless
  2782. the prefix argument ARG is given.
  2783. Warning: Spammers use links to images (using the http scheme) in HTML
  2784. articles to verify whether you have read the message. As
  2785. `gnus-article-browse-html-article' passes the HTML content to the
  2786. browser without eliminating these \"web bugs\" you should only
  2787. use it for mails from trusted senders.
  2788. If you always want to display HTML parts in the browser, set
  2789. `mm-text-html-renderer' to nil.
  2790. This command creates temporary files to pass HTML contents including
  2791. images if any to the browser, and deletes them when exiting the group
  2792. \(if you want)."
  2793. ;; Cf. `mm-w3m-safe-url-regexp'
  2794. (interactive "P")
  2795. (if arg
  2796. (gnus-summary-show-article)
  2797. (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
  2798. gnus-visible-headers))
  2799. ;; As we insert a <hr>, there's no need for the body boundary.
  2800. (gnus-treat-body-boundary nil))
  2801. (gnus-summary-show-article)))
  2802. (with-current-buffer gnus-article-buffer
  2803. (let ((header (unless arg
  2804. (save-restriction
  2805. (widen)
  2806. (buffer-substring-no-properties
  2807. (goto-char (point-min))
  2808. (if (search-forward "\n\n" nil t)
  2809. (match-beginning 0)
  2810. (goto-char (point-max))
  2811. (skip-chars-backward "\t\n ")
  2812. (point))))))
  2813. parts)
  2814. (set-buffer gnus-original-article-buffer)
  2815. (setq parts (mm-dissect-buffer t t))
  2816. ;; If singlepart, enforce a list.
  2817. (when (and (bufferp (car parts))
  2818. (stringp (car (mm-handle-type parts))))
  2819. (setq parts (list parts)))
  2820. ;; Process the list
  2821. (unless (gnus-article-browse-html-parts parts header)
  2822. (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
  2823. (mm-destroy-parts parts)
  2824. (unless arg
  2825. (gnus-summary-show-article)))))
  2826. (defun article-hide-list-identifiers ()
  2827. "Remove list identifiers from the Subject header.
  2828. The `gnus-list-identifiers' variable specifies what to do."
  2829. (interactive)
  2830. (let ((inhibit-point-motion-hooks t)
  2831. (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
  2832. (inhibit-read-only t))
  2833. (when regexp
  2834. (save-excursion
  2835. (save-restriction
  2836. (article-narrow-to-head)
  2837. (goto-char (point-min))
  2838. (while (re-search-forward
  2839. (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
  2840. nil t)
  2841. (delete-region (match-beginning 2) (match-end 0))
  2842. (beginning-of-line))
  2843. (when (re-search-forward
  2844. "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
  2845. (delete-region (match-beginning 1) (match-end 1))))))))
  2846. (defun article-hide-pem (&optional arg)
  2847. "Toggle hiding of any PEM headers and signatures in the current article.
  2848. If given a negative prefix, always show; if given a positive prefix,
  2849. always hide."
  2850. (interactive (gnus-article-hidden-arg))
  2851. (unless (gnus-article-check-hidden-text 'pem arg)
  2852. (save-excursion
  2853. (let ((inhibit-read-only t) end)
  2854. (goto-char (point-min))
  2855. ;; Hide the horrendously ugly "header".
  2856. (when (and (search-forward
  2857. "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
  2858. nil t)
  2859. (setq end (1+ (match-beginning 0))))
  2860. (gnus-add-wash-type 'pem)
  2861. (gnus-article-hide-text-type
  2862. end
  2863. (if (search-forward "\n\n" nil t)
  2864. (match-end 0)
  2865. (point-max))
  2866. 'pem)
  2867. ;; Hide the trailer as well
  2868. (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
  2869. nil t)
  2870. (gnus-article-hide-text-type
  2871. (match-beginning 0) (match-end 0) 'pem)))))))
  2872. (defun article-strip-banner ()
  2873. "Strip the banners specified by the `banner' group parameter and by
  2874. `gnus-article-address-banner-alist'."
  2875. (interactive)
  2876. (save-excursion
  2877. (save-restriction
  2878. (let ((inhibit-point-motion-hooks t))
  2879. (when (gnus-parameter-banner gnus-newsgroup-name)
  2880. (article-really-strip-banner
  2881. (gnus-parameter-banner gnus-newsgroup-name)))
  2882. (when gnus-article-address-banner-alist
  2883. ;; Note that the From header is decoded here, so it is
  2884. ;; required that the *-extract-address-components function
  2885. ;; supports non-ASCII text.
  2886. (let ((from (save-restriction
  2887. (widen)
  2888. (article-narrow-to-head)
  2889. (mail-fetch-field "from"))))
  2890. (when (and from
  2891. (setq from
  2892. (cadr (funcall gnus-extract-address-components
  2893. from))))
  2894. (catch 'found
  2895. (dolist (pair gnus-article-address-banner-alist)
  2896. (when (string-match (car pair) from)
  2897. (throw 'found
  2898. (article-really-strip-banner (cdr pair)))))))))))))
  2899. (defun article-really-strip-banner (banner)
  2900. "Strip the banner specified by the argument."
  2901. (save-excursion
  2902. (save-restriction
  2903. (let ((inhibit-point-motion-hooks t)
  2904. (gnus-signature-limit nil)
  2905. (inhibit-read-only t))
  2906. (article-goto-body)
  2907. (cond
  2908. ((eq banner 'signature)
  2909. (when (gnus-article-narrow-to-signature)
  2910. (widen)
  2911. (forward-line -1)
  2912. (delete-region (point) (point-max))))
  2913. ((symbolp banner)
  2914. (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
  2915. (while (re-search-forward banner nil t)
  2916. (delete-region (match-beginning 0) (match-end 0)))))
  2917. ((stringp banner)
  2918. (while (re-search-forward banner nil t)
  2919. (delete-region (match-beginning 0) (match-end 0)))))))))
  2920. (defun article-babel ()
  2921. "Translate article using an online translation service."
  2922. (interactive)
  2923. (require 'babel)
  2924. (gnus-with-article-buffer
  2925. (when (article-goto-body)
  2926. (let* ((start (point))
  2927. (end (point-max))
  2928. (orig (buffer-substring start end))
  2929. (trans (babel-as-string orig)))
  2930. (save-restriction
  2931. (narrow-to-region start end)
  2932. (delete-region start end)
  2933. (insert trans))))))
  2934. (defun article-hide-signature (&optional arg)
  2935. "Hide the signature in the current article.
  2936. If given a negative prefix, always show; if given a positive prefix,
  2937. always hide."
  2938. (interactive (gnus-article-hidden-arg))
  2939. (unless (gnus-article-check-hidden-text 'signature arg)
  2940. (save-excursion
  2941. (save-restriction
  2942. (let ((inhibit-read-only t))
  2943. (when (gnus-article-narrow-to-signature)
  2944. (gnus-article-hide-text-type
  2945. (point-min) (point-max) 'signature))))))
  2946. (gnus-set-mode-line 'article))
  2947. (defun article-strip-headers-in-body ()
  2948. "Strip offensive headers from bodies."
  2949. (interactive)
  2950. (save-excursion
  2951. (article-goto-body)
  2952. (let ((case-fold-search t))
  2953. (when (looking-at "x-no-archive:")
  2954. (gnus-delete-line)))))
  2955. (defun article-strip-leading-blank-lines ()
  2956. "Remove all blank lines from the beginning of the article."
  2957. (interactive)
  2958. (save-excursion
  2959. (let ((inhibit-point-motion-hooks t)
  2960. (inhibit-read-only t))
  2961. (when (article-goto-body)
  2962. (while (and (not (eobp))
  2963. (looking-at "[ \t]*$"))
  2964. (gnus-delete-line))))))
  2965. (defun article-narrow-to-head ()
  2966. "Narrow the buffer to the head of the message.
  2967. Point is left at the beginning of the narrowed-to region."
  2968. (narrow-to-region
  2969. (goto-char (point-min))
  2970. (cond
  2971. ;; Absolutely no headers displayed.
  2972. ((looking-at "\n")
  2973. (point))
  2974. ;; Normal headers.
  2975. ((search-forward "\n\n" nil 1)
  2976. (1- (point)))
  2977. ;; Nothing but headers.
  2978. (t
  2979. (point-max))))
  2980. (goto-char (point-min)))
  2981. (defun article-goto-body ()
  2982. "Place point at the start of the body."
  2983. (goto-char (point-min))
  2984. (cond
  2985. ;; This variable is only bound when dealing with separate
  2986. ;; MIME body parts.
  2987. (article-goto-body-goes-to-point-min-p
  2988. t)
  2989. ((search-forward "\n\n" nil t)
  2990. t)
  2991. (t
  2992. (goto-char (point-max))
  2993. nil)))
  2994. (defun article-strip-multiple-blank-lines ()
  2995. "Replace consecutive blank lines with one empty line."
  2996. (interactive)
  2997. (save-excursion
  2998. (let ((inhibit-point-motion-hooks t)
  2999. (inhibit-read-only t))
  3000. ;; First make all blank lines empty.
  3001. (article-goto-body)
  3002. (while (re-search-forward "^[ \t]+$" nil t)
  3003. (unless (gnus-annotation-in-region-p
  3004. (match-beginning 0) (match-end 0))
  3005. (replace-match "" nil t)))
  3006. ;; Then replace multiple empty lines with a single empty line.
  3007. (article-goto-body)
  3008. (while (re-search-forward "\n\n\\(\n+\\)" nil t)
  3009. (unless (gnus-annotation-in-region-p
  3010. (match-beginning 0) (match-end 0))
  3011. (delete-region (match-beginning 1) (match-end 1)))))))
  3012. (defun article-strip-leading-space ()
  3013. "Remove all white space from the beginning of the lines in the article."
  3014. (interactive)
  3015. (save-excursion
  3016. (let ((inhibit-point-motion-hooks t)
  3017. (inhibit-read-only t))
  3018. (article-goto-body)
  3019. (while (re-search-forward "^[ \t]+" nil t)
  3020. (replace-match "" t t)))))
  3021. (defun article-strip-trailing-space ()
  3022. "Remove all white space from the end of the lines in the article."
  3023. (interactive)
  3024. (save-excursion
  3025. (let ((inhibit-point-motion-hooks t)
  3026. (inhibit-read-only t))
  3027. (article-goto-body)
  3028. (while (re-search-forward "[ \t]+$" nil t)
  3029. (replace-match "" t t)))))
  3030. (defun article-strip-blank-lines ()
  3031. "Strip leading, trailing and multiple blank lines."
  3032. (interactive)
  3033. (article-strip-leading-blank-lines)
  3034. (article-remove-trailing-blank-lines)
  3035. (article-strip-multiple-blank-lines))
  3036. (defun article-strip-all-blank-lines ()
  3037. "Strip all blank lines."
  3038. (interactive)
  3039. (save-excursion
  3040. (let ((inhibit-point-motion-hooks t)
  3041. (inhibit-read-only t))
  3042. (article-goto-body)
  3043. (while (re-search-forward "^[ \t]*\n" nil t)
  3044. (replace-match "" t t)))))
  3045. (defun gnus-article-narrow-to-signature ()
  3046. "Narrow to the signature; return t if a signature is found, else nil."
  3047. (let ((inhibit-point-motion-hooks t))
  3048. (when (gnus-article-search-signature)
  3049. (forward-line 1)
  3050. ;; Check whether we have some limits to what we consider
  3051. ;; to be a signature.
  3052. (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
  3053. (list gnus-signature-limit)))
  3054. limit limited)
  3055. (while (setq limit (pop limits))
  3056. (if (or (and (integerp limit)
  3057. (< (- (point-max) (point)) limit))
  3058. (and (floatp limit)
  3059. (< (count-lines (point) (point-max)) limit))
  3060. (and (functionp limit)
  3061. (funcall limit))
  3062. (and (stringp limit)
  3063. (not (re-search-forward limit nil t))))
  3064. () ; This limit did not succeed.
  3065. (setq limited t
  3066. limits nil)))
  3067. (unless limited
  3068. (narrow-to-region (point) (point-max))
  3069. t)))))
  3070. (defun gnus-article-search-signature ()
  3071. "Search the current buffer for the signature separator.
  3072. Put point at the beginning of the signature separator."
  3073. (let ((cur (point)))
  3074. (goto-char (point-max))
  3075. (if (if (stringp gnus-signature-separator)
  3076. (re-search-backward gnus-signature-separator nil t)
  3077. (let ((seps gnus-signature-separator))
  3078. (while (and seps
  3079. (not (re-search-backward (car seps) nil t)))
  3080. (pop seps))
  3081. seps))
  3082. t
  3083. (goto-char cur)
  3084. nil)))
  3085. (defun gnus-article-hidden-arg ()
  3086. "Return the current prefix arg as a number, or 0 if no prefix."
  3087. (list (if current-prefix-arg
  3088. (prefix-numeric-value current-prefix-arg)
  3089. 0)))
  3090. (defun gnus-article-check-hidden-text (type arg)
  3091. "Return nil if hiding is necessary.
  3092. Arg can be nil or a number. nil and positive means hide, negative
  3093. means show, 0 means toggle."
  3094. (save-excursion
  3095. (save-restriction
  3096. (let ((hide (gnus-article-hidden-text-p type)))
  3097. (cond
  3098. ((or (null arg)
  3099. (> arg 0))
  3100. nil)
  3101. ((< arg 0)
  3102. (gnus-article-show-hidden-text type)
  3103. t)
  3104. (t
  3105. (if (eq hide 'hidden)
  3106. (progn
  3107. (gnus-article-show-hidden-text type)
  3108. t)
  3109. nil)))))))
  3110. (defun gnus-article-hidden-text-p (type)
  3111. "Say whether the current buffer contains hidden text of type TYPE."
  3112. (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
  3113. (while (and pos
  3114. (not (get-text-property pos 'invisible))
  3115. (not (get-text-property pos 'dummy-invisible)))
  3116. (setq pos
  3117. (text-property-any (1+ pos) (point-max) 'article-type type)))
  3118. (if pos
  3119. 'hidden
  3120. nil)))
  3121. (defun gnus-article-show-hidden-text (type &optional _dummy)
  3122. "Show all hidden text of type TYPE.
  3123. Originally it is hide instead of DUMMY."
  3124. (let ((inhibit-read-only t)
  3125. (inhibit-point-motion-hooks t))
  3126. (gnus-remove-text-properties-when
  3127. 'article-type type
  3128. (point-min) (point-max)
  3129. (cons 'article-type (cons type
  3130. gnus-hidden-properties)))
  3131. (gnus-delete-wash-type type)))
  3132. (defconst article-time-units
  3133. `((year . ,(* 365.25 24 60 60))
  3134. (week . ,(* 7 24 60 60))
  3135. (day . ,(* 24 60 60))
  3136. (hour . ,(* 60 60))
  3137. (minute . 60)
  3138. (second . 1))
  3139. "Mapping from time units to seconds.")
  3140. (defun gnus-article-forward-header ()
  3141. "Move point to the start of the next header.
  3142. If the current header is a continuation header, this can be several
  3143. lines forward."
  3144. (let ((ended nil))
  3145. (while (not ended)
  3146. (forward-line 1)
  3147. (if (looking-at "[ \t]+[^ \t]")
  3148. (forward-line 1)
  3149. (setq ended t)))))
  3150. (defun article-treat-date ()
  3151. (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
  3152. (with-current-buffer gnus-summary-buffer
  3153. gnus-article-date-headers)
  3154. gnus-article-date-headers)
  3155. t))
  3156. (defun article-date-ut (&optional type _highlight date-position)
  3157. "Convert DATE date to TYPE in the current article.
  3158. The default type is `ut'. See `gnus-article-date-headers' for
  3159. possible values."
  3160. (interactive (list 'ut t))
  3161. (let* ((case-fold-search t)
  3162. (inhibit-read-only t)
  3163. (inhibit-point-motion-hooks t)
  3164. (visible-date (mail-fetch-field "Date"))
  3165. pos date bface eface)
  3166. (save-excursion
  3167. (if date-position
  3168. (progn
  3169. (goto-char date-position)
  3170. (setq date (get-text-property (point) 'original-date))
  3171. (when (looking-at "[^:]+:[\t ]*")
  3172. (setq bface (get-text-property (match-beginning 0) 'face)
  3173. eface (get-text-property (match-end 0) 'face)))
  3174. (delete-region (point)
  3175. (progn
  3176. (gnus-article-forward-header)
  3177. (point)))
  3178. (article-transform-date date type bface eface))
  3179. (save-restriction
  3180. (widen)
  3181. (goto-char (point-min))
  3182. (while (or (get-text-property (setq pos (point)) 'original-date)
  3183. (and (setq pos (next-single-property-change
  3184. (point) 'original-date))
  3185. (goto-char pos)))
  3186. (narrow-to-region pos (if (search-forward "\n\n" nil t)
  3187. (1+ (match-beginning 0))
  3188. (point-max)))
  3189. (while (setq pos (text-property-not-all pos (point-max)
  3190. 'gnus-date-type nil))
  3191. (setq date (get-text-property pos 'original-date))
  3192. (goto-char pos)
  3193. (when (looking-at "[^:]+:[\t ]*")
  3194. (setq bface (get-text-property (match-beginning 0) 'face)
  3195. eface (get-text-property (match-end 0) 'face)))
  3196. (delete-region pos (or (text-property-any pos (point-max)
  3197. 'gnus-date-type nil)
  3198. (point-max))))
  3199. (unless date ;; the 1st time
  3200. (goto-char (point-min))
  3201. (while (re-search-forward "^Date:[\t ]*" nil t)
  3202. (setq date (get-text-property (match-beginning 0)
  3203. 'original-date)
  3204. bface (get-text-property (match-beginning 0) 'face)
  3205. eface (get-text-property (match-end 0) 'face))
  3206. (delete-region (point-at-bol) (progn
  3207. (gnus-article-forward-header)
  3208. (point)))))
  3209. (when (and (not date)
  3210. visible-date)
  3211. (setq date visible-date))
  3212. (when date
  3213. (article-transform-date date type bface eface))
  3214. (goto-char (point-max))
  3215. (widen)))))))
  3216. (defun article-transform-date (date type bface eface)
  3217. (dolist (this-type (cond
  3218. ((null type)
  3219. (list 'ut))
  3220. ((atom type)
  3221. (list type))
  3222. (t
  3223. type)))
  3224. (goto-char
  3225. (prog1
  3226. (point)
  3227. (add-text-properties
  3228. (point)
  3229. (progn
  3230. (insert (article-make-date-line date (or this-type 'ut)) "\n")
  3231. (point))
  3232. (list 'original-date date 'gnus-date-type this-type))))
  3233. ;; Do highlighting.
  3234. (when (looking-at
  3235. "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
  3236. (put-text-property (match-beginning 1) (match-end 1) 'face bface)
  3237. (when (match-beginning 2)
  3238. (put-text-property (match-beginning 2) (match-end 2) 'face eface))
  3239. (while (and (zerop (forward-line 1))
  3240. (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
  3241. (when (match-beginning 1)
  3242. (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
  3243. (defun article-make-date-line (date type)
  3244. "Return a DATE line of TYPE."
  3245. (unless (memq type '(local ut original user-defined iso8601 lapsed english
  3246. combined-lapsed))
  3247. (error "Unknown conversion type: %s" type))
  3248. (condition-case ()
  3249. (let ((time (ignore-errors (date-to-time date))))
  3250. (cond
  3251. ;; Convert to the local timezone.
  3252. ((eq type 'local)
  3253. (concat "Date: " (message-make-date time)))
  3254. ;; Convert to Universal Time.
  3255. ((eq type 'ut)
  3256. (concat "Date: "
  3257. (substring
  3258. (message-make-date
  3259. (let* ((e (parse-time-string date))
  3260. (tm (apply 'encode-time e))
  3261. (ms (car tm))
  3262. (ls (- (cadr tm) (car (current-time-zone time)))))
  3263. (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
  3264. ((> ls 65535) (list (1+ ms) (- ls 65536)))
  3265. (t (list ms ls)))))
  3266. 0 -5)
  3267. "UT"))
  3268. ;; Get the original date from the article.
  3269. ((eq type 'original)
  3270. (concat "Date: " (if (string-match "\n+$" date)
  3271. (substring date 0 (match-beginning 0))
  3272. date)))
  3273. ;; Let the user define the format.
  3274. ((eq type 'user-defined)
  3275. (let ((format (or (condition-case nil
  3276. (with-current-buffer gnus-summary-buffer
  3277. gnus-article-time-format)
  3278. (error nil))
  3279. gnus-article-time-format)))
  3280. (if (functionp format)
  3281. (funcall format time)
  3282. (concat "Date: " (format-time-string format time)))))
  3283. ;; ISO 8601.
  3284. ((eq type 'iso8601)
  3285. (let ((tz (car (current-time-zone time))))
  3286. (concat
  3287. "Date: "
  3288. (format-time-string "%Y%m%dT%H%M%S" time)
  3289. (format "%s%02d%02d"
  3290. (if (> tz 0) "+" "-") (/ (abs tz) 3600)
  3291. (/ (% (abs tz) 3600) 60)))))
  3292. ;; Do a lapsed format.
  3293. ((eq type 'lapsed)
  3294. (concat "Date: " (article-lapsed-string time)))
  3295. ;; A combined date/lapsed format.
  3296. ((eq type 'combined-lapsed)
  3297. (let ((date-string (article-make-date-line date 'original))
  3298. (segments 3)
  3299. lapsed-string)
  3300. (while (and
  3301. time
  3302. (setq lapsed-string
  3303. (concat " (" (article-lapsed-string time segments) ")"))
  3304. (> (+ (length date-string)
  3305. (length lapsed-string))
  3306. (+ fill-column 6))
  3307. (> segments 0))
  3308. (setq segments (1- segments)))
  3309. (if (> segments 0)
  3310. (concat date-string lapsed-string)
  3311. date-string)))
  3312. ;; Display the date in proper English
  3313. ((eq type 'english)
  3314. (let ((dtime (decode-time time)))
  3315. (concat
  3316. "Date: the "
  3317. (number-to-string (nth 3 dtime))
  3318. (let ((digit (% (nth 3 dtime) 10)))
  3319. (cond
  3320. ((memq (nth 3 dtime) '(11 12 13)) "th")
  3321. ((= digit 1) "st")
  3322. ((= digit 2) "nd")
  3323. ((= digit 3) "rd")
  3324. (t "th")))
  3325. " of "
  3326. (nth (1- (nth 4 dtime)) gnus-english-month-names)
  3327. " "
  3328. (number-to-string (nth 5 dtime))
  3329. " at "
  3330. (format "%02d" (nth 2 dtime))
  3331. ":"
  3332. (format "%02d" (nth 1 dtime)))))))
  3333. (foo
  3334. (format "Date: %s (from Gnus)" date))))
  3335. (defun article-lapsed-string (time &optional max-segments)
  3336. ;; If the date is seriously mangled, the timezone functions are
  3337. ;; liable to bug out, so we ignore all errors.
  3338. (let* ((now (current-time))
  3339. (real-time (subtract-time now time))
  3340. (real-sec (and real-time
  3341. (+ (* (float (car real-time)) 65536)
  3342. (cadr real-time))))
  3343. (sec (and real-time (abs real-sec)))
  3344. (segments 0)
  3345. num prev)
  3346. (unless max-segments
  3347. (setq max-segments (length article-time-units)))
  3348. (cond
  3349. ((null real-time)
  3350. "Unknown")
  3351. ((zerop sec)
  3352. "Now")
  3353. (t
  3354. (concat
  3355. ;; This is a bit convoluted, but basically we go
  3356. ;; through the time units for years, weeks, etc,
  3357. ;; and divide things to see whether that results
  3358. ;; in positive answers.
  3359. (mapconcat
  3360. (lambda (unit)
  3361. (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
  3362. (>= segments max-segments))
  3363. ;; The (remaining) seconds are too few to
  3364. ;; be divided into this time unit.
  3365. ""
  3366. ;; It's big enough, so we output it.
  3367. (setq sec (- sec (* num (cdr unit))))
  3368. (prog1
  3369. (concat (if prev ", " "") (int-to-string
  3370. (floor num))
  3371. " " (symbol-name (car unit))
  3372. (if (> num 1) "s" ""))
  3373. (setq prev t
  3374. segments (1+ segments)))))
  3375. article-time-units "")
  3376. ;; If dates are odd, then it might appear like the
  3377. ;; article was sent in the future.
  3378. (if (> real-sec 0)
  3379. " ago"
  3380. " in the future"))))))
  3381. (defun article-date-local (&optional highlight)
  3382. "Convert the current article date to the local timezone."
  3383. (interactive (list t))
  3384. (article-date-ut 'local highlight))
  3385. (defun article-date-english (&optional highlight)
  3386. "Convert the current article date to something that is proper English."
  3387. (interactive (list t))
  3388. (article-date-ut 'english highlight))
  3389. (defun article-date-original (&optional highlight)
  3390. "Convert the current article date to what it was originally.
  3391. This is only useful if you have used some other date conversion
  3392. function and want to see what the date was before converting."
  3393. (interactive (list t))
  3394. (article-date-ut 'original highlight))
  3395. (defun article-date-lapsed (&optional highlight)
  3396. "Convert the current article date to time lapsed since it was sent."
  3397. (interactive (list t))
  3398. (article-date-ut 'lapsed highlight))
  3399. (defun article-date-combined-lapsed (&optional highlight)
  3400. "Convert the current article date to time lapsed since it was sent."
  3401. (interactive (list t))
  3402. (article-date-ut 'combined-lapsed highlight))
  3403. (defun article-update-date-lapsed ()
  3404. "Function to be run from a timer to update the lapsed time line."
  3405. (save-match-data
  3406. (let ((buffer (current-buffer)))
  3407. (ignore-errors
  3408. (walk-windows
  3409. (lambda (w)
  3410. (set-buffer (window-buffer w))
  3411. (when (derived-mode-p 'gnus-article-mode)
  3412. (let ((old-line (count-lines (point-min) (point)))
  3413. (old-column (- (point) (line-beginning-position)))
  3414. (window-start (window-start w))
  3415. (pos (point-min))
  3416. type next end)
  3417. (while (setq pos (text-property-not-all pos (point-max)
  3418. 'gnus-date-type nil))
  3419. (setq next (or (next-single-property-change pos
  3420. 'gnus-date-type)
  3421. (point-max)))
  3422. (setq type (get-text-property pos 'gnus-date-type))
  3423. (when (memq type '(lapsed combined-lapsed user-defined))
  3424. (article-date-ut type t pos)
  3425. (setq end (or (next-single-property-change pos
  3426. 'gnus-date-type)
  3427. (point-max)))
  3428. (when window-start
  3429. (if (/= window-start next)
  3430. (setq window-start nil)
  3431. (set-window-start w end)))
  3432. (setq next end))
  3433. (setq pos next))
  3434. (goto-char (point-min))
  3435. (when (> old-column 0)
  3436. (setq old-line (1- old-line)))
  3437. (forward-line old-line)
  3438. (end-of-line)
  3439. (when (> (current-column) old-column)
  3440. (beginning-of-line)
  3441. (forward-char old-column)))))
  3442. nil 'visible))
  3443. (set-buffer buffer))))
  3444. (defun gnus-start-date-timer (&optional n)
  3445. "Start a timer to update the Date headers in the article buffers.
  3446. The numerical prefix says how frequently (in seconds) the function
  3447. is to run."
  3448. (interactive "p")
  3449. (unless n
  3450. (setq n 1))
  3451. (gnus-stop-date-timer)
  3452. (setq article-lapsed-timer
  3453. (run-at-time 1 n 'article-update-date-lapsed)))
  3454. (defun gnus-stop-date-timer ()
  3455. "Stop the Date timer."
  3456. (interactive)
  3457. (when article-lapsed-timer
  3458. (nnheader-cancel-timer article-lapsed-timer)
  3459. (setq article-lapsed-timer nil)))
  3460. (defun article-date-user (&optional highlight)
  3461. "Convert the current article date to the user-defined format.
  3462. This format is defined by the `gnus-article-time-format' variable."
  3463. (interactive (list t))
  3464. (article-date-ut 'user highlight))
  3465. (defun article-date-iso8601 (&optional highlight)
  3466. "Convert the current article date to ISO8601."
  3467. (interactive (list t))
  3468. (article-date-ut 'iso8601 highlight))
  3469. (defmacro gnus-article-save-original-date (&rest forms)
  3470. "Save the original date as a text property and evaluate FORMS."
  3471. `(let* ((case-fold-search t)
  3472. (start (progn
  3473. (goto-char (point-min))
  3474. (when (and (re-search-forward "^date:[\t\n ]+" nil t)
  3475. (not (bolp)))
  3476. (match-end 0))))
  3477. (date (when (and start
  3478. (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
  3479. nil t))
  3480. (buffer-substring-no-properties start
  3481. (match-beginning 0)))))
  3482. (goto-char (point-max))
  3483. (skip-chars-backward "\n")
  3484. (put-text-property (point-min) (point) 'original-date date)
  3485. ,@forms
  3486. (goto-char (point-max))
  3487. (skip-chars-backward "\n")
  3488. (put-text-property (point-min) (point) 'original-date date)))
  3489. ;; (defun article-show-all ()
  3490. ;; "Show all hidden text in the article buffer."
  3491. ;; (interactive)
  3492. ;; (save-excursion
  3493. ;; (let ((inhibit-read-only t))
  3494. ;; (gnus-article-unhide-text (point-min) (point-max)))))
  3495. (defun article-remove-leading-whitespace ()
  3496. "Remove excessive whitespace from all headers."
  3497. (interactive)
  3498. (save-excursion
  3499. (save-restriction
  3500. (let ((inhibit-read-only t))
  3501. (article-narrow-to-head)
  3502. (goto-char (point-min))
  3503. (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
  3504. (delete-region (match-beginning 1) (match-end 1)))))))
  3505. (defun article-emphasize (&optional arg)
  3506. "Emphasize text according to `gnus-emphasis-alist'."
  3507. (interactive (gnus-article-hidden-arg))
  3508. (unless (gnus-article-check-hidden-text 'emphasis arg)
  3509. (save-excursion
  3510. (let ((alist (or
  3511. (condition-case nil
  3512. (with-current-buffer gnus-summary-buffer
  3513. gnus-article-emphasis-alist)
  3514. (error))
  3515. gnus-emphasis-alist))
  3516. (inhibit-read-only t)
  3517. (props (append '(article-type emphasis)
  3518. gnus-hidden-properties))
  3519. regexp elem beg invisible visible face)
  3520. (article-goto-body)
  3521. (setq beg (point))
  3522. (while (setq elem (pop alist))
  3523. (goto-char beg)
  3524. (setq regexp (car elem)
  3525. invisible (nth 1 elem)
  3526. visible (nth 2 elem)
  3527. face (nth 3 elem))
  3528. (while (re-search-forward regexp nil t)
  3529. (when (and (match-beginning visible) (match-beginning invisible))
  3530. (gnus-article-hide-text
  3531. (match-beginning invisible) (match-end invisible) props)
  3532. (gnus-article-unhide-text-type
  3533. (match-beginning visible) (match-end visible) 'emphasis)
  3534. (gnus-put-overlay-excluding-newlines
  3535. (match-beginning visible) (match-end visible) 'face face)
  3536. (gnus-add-wash-type 'emphasis)
  3537. (goto-char (match-end invisible)))))))))
  3538. (defun gnus-article-setup-highlight-words (&optional highlight-words)
  3539. "Setup newsgroup emphasis alist."
  3540. (unless gnus-article-emphasis-alist
  3541. (let ((name (and gnus-newsgroup-name
  3542. (gnus-group-real-name gnus-newsgroup-name))))
  3543. (make-local-variable 'gnus-article-emphasis-alist)
  3544. (setq gnus-article-emphasis-alist
  3545. (nconc
  3546. (let ((alist gnus-group-highlight-words-alist) elem highlight)
  3547. (while (setq elem (pop alist))
  3548. (when (and name (string-match (car elem) name))
  3549. (setq alist nil
  3550. highlight (copy-sequence (cdr elem)))))
  3551. highlight)
  3552. (copy-sequence highlight-words)
  3553. (if gnus-newsgroup-name
  3554. (copy-sequence (gnus-group-find-parameter
  3555. gnus-newsgroup-name 'highlight-words t)))
  3556. gnus-emphasis-alist)))))
  3557. (defvar gnus-summary-article-menu)
  3558. (defvar gnus-summary-post-menu)
  3559. ;;; Saving functions.
  3560. (defun gnus-article-save (save-buffer file &optional num)
  3561. "Save the currently selected article."
  3562. (when (or (get gnus-default-article-saver :headers)
  3563. (not gnus-save-all-headers))
  3564. ;; Remove headers according to `gnus-saved-headers' or the value
  3565. ;; of the `:headers' property that the saver function might have.
  3566. (let ((gnus-visible-headers
  3567. (or (symbol-value (get gnus-default-article-saver :headers))
  3568. gnus-saved-headers gnus-visible-headers))
  3569. ;; Ignore group parameter. See `article-hide-headers'.
  3570. (gnus-summary-buffer nil))
  3571. (with-current-buffer save-buffer
  3572. (article-hide-headers 1 t))))
  3573. (save-window-excursion
  3574. (if (not gnus-default-article-saver)
  3575. (error "No default saver is defined")
  3576. ;; !!! Magic! The saving functions all save
  3577. ;; `gnus-save-article-buffer' (or so they think), but we
  3578. ;; bind that variable to our save-buffer.
  3579. (set-buffer gnus-article-buffer)
  3580. (let* ((gnus-save-article-buffer save-buffer)
  3581. (filename
  3582. (cond
  3583. ((not gnus-prompt-before-saving) 'default)
  3584. ((eq gnus-prompt-before-saving 'always) nil)
  3585. (t file)))
  3586. (gnus-number-of-articles-to-be-saved
  3587. (when (eq gnus-prompt-before-saving t)
  3588. num))) ; Magic
  3589. (set-buffer gnus-article-current-summary)
  3590. (funcall gnus-default-article-saver filename)))))
  3591. (defun gnus-read-save-file-name (prompt &optional filename
  3592. function group headers variable
  3593. dir-var)
  3594. (let ((default-name
  3595. (funcall function group headers (symbol-value variable)))
  3596. result)
  3597. (setq result
  3598. (expand-file-name
  3599. (cond
  3600. ((eq filename 'default)
  3601. default-name)
  3602. ((eq filename t)
  3603. default-name)
  3604. (filename filename)
  3605. (t
  3606. (when (symbol-value dir-var)
  3607. (setq default-name (expand-file-name
  3608. (file-name-nondirectory default-name)
  3609. (symbol-value dir-var))))
  3610. (let* ((split-name (gnus-get-split-value gnus-split-methods))
  3611. (prompt
  3612. (format prompt
  3613. (if (and gnus-number-of-articles-to-be-saved
  3614. (> gnus-number-of-articles-to-be-saved 1))
  3615. (format "these %d articles"
  3616. gnus-number-of-articles-to-be-saved)
  3617. "this article")))
  3618. (file
  3619. ;; Let the split methods have their say.
  3620. (cond
  3621. ;; No split name was found.
  3622. ((null split-name)
  3623. (read-file-name
  3624. (concat prompt " (default "
  3625. (file-name-nondirectory default-name) "): ")
  3626. (file-name-directory default-name)
  3627. default-name))
  3628. ;; A single group name is returned.
  3629. ((stringp split-name)
  3630. (setq default-name
  3631. (funcall function split-name headers
  3632. (symbol-value variable)))
  3633. (read-file-name
  3634. (concat prompt " (default "
  3635. (file-name-nondirectory default-name) "): ")
  3636. (file-name-directory default-name)
  3637. default-name))
  3638. ;; A single split name was found
  3639. ((= 1 (length split-name))
  3640. (let* ((name (expand-file-name
  3641. (car split-name)
  3642. gnus-article-save-directory))
  3643. (dir (cond ((file-directory-p name)
  3644. (file-name-as-directory name))
  3645. ((file-exists-p name) name)
  3646. (t gnus-article-save-directory))))
  3647. (read-file-name
  3648. (concat prompt " (default " name "): ")
  3649. dir name)))
  3650. ;; A list of splits was found.
  3651. (t
  3652. (setq split-name (nreverse split-name))
  3653. (let (result)
  3654. (let ((file-name-history
  3655. (nconc split-name file-name-history)))
  3656. (setq result
  3657. (expand-file-name
  3658. (read-file-name
  3659. (concat prompt " (`M-p' for defaults): ")
  3660. gnus-article-save-directory
  3661. (car split-name))
  3662. gnus-article-save-directory)))
  3663. (car (push result file-name-history)))))))
  3664. ;; Create the directory.
  3665. (gnus-make-directory (file-name-directory file))
  3666. ;; If we have read a directory, we append the default file name.
  3667. (when (file-directory-p file)
  3668. (setq file (expand-file-name (file-name-nondirectory
  3669. default-name)
  3670. (file-name-as-directory file))))
  3671. ;; Possibly translate some characters.
  3672. (nnheader-translate-file-chars file))))))
  3673. (gnus-make-directory (file-name-directory result))
  3674. (when variable
  3675. (set variable result))
  3676. (when dir-var
  3677. (set dir-var (file-name-directory result)))
  3678. result))
  3679. (defun gnus-article-archive-name (_group)
  3680. "Return the first instance of an \"Archive-name\" in the current buffer."
  3681. (let ((case-fold-search t))
  3682. (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
  3683. (nnheader-concat gnus-article-save-directory
  3684. (match-string 1)))))
  3685. (defun gnus-article-nndoc-name (group)
  3686. "If GROUP is an nndoc group, return the name of the parent group."
  3687. (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
  3688. (gnus-group-get-parameter group 'save-article-group)))
  3689. (defun gnus-summary-save-in-rmail (&optional filename)
  3690. "Append this article to Rmail file.
  3691. Optional argument FILENAME specifies file name.
  3692. Directory to save to is default to `gnus-article-save-directory'."
  3693. (setq filename (gnus-read-save-file-name
  3694. "Save %s in rmail file" filename
  3695. gnus-rmail-save-name gnus-newsgroup-name
  3696. gnus-current-headers 'gnus-newsgroup-last-rmail))
  3697. (with-current-buffer gnus-save-article-buffer
  3698. (save-excursion
  3699. (save-restriction
  3700. (widen)
  3701. ;; Note that unlike gnus-summary-save-in-mail, there is no
  3702. ;; check to see if filename is Babyl. Rmail in Emacs 23 does
  3703. ;; not use Babyl.
  3704. (gnus-output-to-rmail filename))))
  3705. filename)
  3706. (defun gnus-summary-save-in-mail (&optional filename)
  3707. "Append this article to Unix mail file.
  3708. Optional argument FILENAME specifies file name.
  3709. Directory to save to is default to `gnus-article-save-directory'."
  3710. (setq filename (gnus-read-save-file-name
  3711. "Save %s in Unix mail file" filename
  3712. gnus-mail-save-name gnus-newsgroup-name
  3713. gnus-current-headers 'gnus-newsgroup-last-mail))
  3714. (with-current-buffer gnus-save-article-buffer
  3715. (save-excursion
  3716. (save-restriction
  3717. (widen)
  3718. (if (and (file-readable-p filename)
  3719. (file-regular-p filename)
  3720. (mail-file-babyl-p filename))
  3721. (gnus-output-to-rmail filename)
  3722. (gnus-output-to-mail filename)))))
  3723. filename)
  3724. (put 'gnus-summary-save-in-file :decode t)
  3725. (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
  3726. (defun gnus-summary-save-in-file (&optional filename overwrite)
  3727. "Append this article to file.
  3728. Optional argument FILENAME specifies file name.
  3729. Directory to save to is default to `gnus-article-save-directory'."
  3730. (setq filename (gnus-read-save-file-name
  3731. "Save %s in file" filename
  3732. gnus-file-save-name gnus-newsgroup-name
  3733. gnus-current-headers 'gnus-newsgroup-last-file))
  3734. (with-current-buffer gnus-save-article-buffer
  3735. (save-excursion
  3736. (save-restriction
  3737. (widen)
  3738. (when (and overwrite
  3739. (file-exists-p filename))
  3740. (delete-file filename))
  3741. (gnus-output-to-file filename))))
  3742. filename)
  3743. (put 'gnus-summary-write-to-file :decode t)
  3744. (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
  3745. (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
  3746. (defun gnus-summary-write-to-file (&optional filename)
  3747. "Write this article to a file, overwriting it if the file exists.
  3748. Optional argument FILENAME specifies file name.
  3749. The directory to save in defaults to `gnus-article-save-directory'."
  3750. (setq filename (gnus-read-save-file-name
  3751. "Save %s in file" filename
  3752. gnus-file-save-name gnus-newsgroup-name
  3753. gnus-current-headers nil 'gnus-newsgroup-last-directory))
  3754. (gnus-summary-save-in-file filename t))
  3755. (put 'gnus-summary-save-body-in-file :decode t)
  3756. (defun gnus-summary-save-body-in-file (&optional filename overwrite)
  3757. "Append this article body to a file.
  3758. Optional argument FILENAME specifies file name.
  3759. The directory to save in defaults to `gnus-article-save-directory'."
  3760. (setq filename (gnus-read-save-file-name
  3761. "Save %s body in file" filename
  3762. gnus-file-save-name gnus-newsgroup-name
  3763. gnus-current-headers 'gnus-newsgroup-last-file))
  3764. (with-current-buffer gnus-save-article-buffer
  3765. (save-excursion
  3766. (save-restriction
  3767. (widen)
  3768. (when (article-goto-body)
  3769. (narrow-to-region (point) (point-max)))
  3770. (when (and overwrite
  3771. (file-exists-p filename))
  3772. (delete-file filename))
  3773. (gnus-output-to-file filename))))
  3774. filename)
  3775. (put 'gnus-summary-write-body-to-file :decode t)
  3776. (put 'gnus-summary-write-body-to-file
  3777. :function 'gnus-summary-save-body-in-file)
  3778. (defun gnus-summary-write-body-to-file (&optional filename)
  3779. "Write this article body to a file, overwriting it if the file exists.
  3780. Optional argument FILENAME specifies file name.
  3781. The directory to save in defaults to `gnus-article-save-directory'."
  3782. (setq filename (gnus-read-save-file-name
  3783. "Save %s body in file" filename
  3784. gnus-file-save-name gnus-newsgroup-name
  3785. gnus-current-headers nil 'gnus-newsgroup-last-directory))
  3786. (gnus-summary-save-body-in-file filename t))
  3787. (put 'gnus-summary-save-in-pipe :decode t)
  3788. (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
  3789. (defun gnus-summary-save-in-pipe (&optional command raw)
  3790. "Pipe this article to subprocess COMMAND.
  3791. Valid values for COMMAND include:
  3792. a string
  3793. The executable command name and possibly arguments.
  3794. nil
  3795. You will be prompted for the command in the minibuffer.
  3796. the symbol `default'
  3797. It will be replaced with the command which the variable
  3798. `gnus-summary-pipe-output-default-command' holds or the command
  3799. last used for saving.
  3800. Non-nil value for RAW overrides `:decode' and `:headers' properties
  3801. and the raw article including all headers will be piped."
  3802. (let ((article (gnus-summary-article-number))
  3803. (decode (unless raw
  3804. (get 'gnus-summary-save-in-pipe :decode)))
  3805. save-buffer default)
  3806. (if article
  3807. (if (vectorp (gnus-summary-article-header article))
  3808. (save-current-buffer
  3809. (gnus-summary-select-article decode decode nil article)
  3810. (insert-buffer-substring
  3811. (prog1
  3812. (if decode
  3813. gnus-article-buffer
  3814. gnus-original-article-buffer)
  3815. (setq save-buffer
  3816. (nnheader-set-temp-buffer " *Gnus Save*"))))
  3817. ;; Remove unwanted headers.
  3818. (when (and (not raw)
  3819. (or (get 'gnus-summary-save-in-pipe :headers)
  3820. (not gnus-save-all-headers)))
  3821. (let ((gnus-visible-headers
  3822. (or (symbol-value (get 'gnus-summary-save-in-pipe
  3823. :headers))
  3824. gnus-saved-headers gnus-visible-headers))
  3825. (gnus-summary-buffer nil))
  3826. (article-hide-headers 1 t))))
  3827. (error "%d is not a real article" article))
  3828. (error "No article to pipe"))
  3829. (setq default (or gnus-summary-pipe-output-default-command
  3830. gnus-last-shell-command))
  3831. (unless (stringp command)
  3832. (setq command
  3833. (if (and (eq command 'default) default)
  3834. default
  3835. (gnus-read-shell-command "Shell command on this article: "
  3836. default))))
  3837. (when (string-equal command "")
  3838. (if default
  3839. (setq command default)
  3840. (error "A command is required")))
  3841. (with-current-buffer save-buffer
  3842. (save-restriction
  3843. (widen)
  3844. (shell-command-on-region (point-min) (point-max) command nil)))
  3845. (gnus-kill-buffer save-buffer))
  3846. (setq gnus-summary-pipe-output-default-command command))
  3847. (defun gnus-summary-pipe-to-muttprint (&optional command)
  3848. "Pipe this article to muttprint."
  3849. (unless (stringp command)
  3850. (setq command (read-string
  3851. "Print using command: " gnus-summary-muttprint-program
  3852. nil gnus-summary-muttprint-program)))
  3853. (let ((gnus-summary-pipe-output-default-command
  3854. gnus-summary-pipe-output-default-command))
  3855. (gnus-summary-save-in-pipe command))
  3856. (setq gnus-summary-muttprint-program command))
  3857. ;;; Article file names when saving.
  3858. (defun gnus-capitalize-newsgroup (newsgroup)
  3859. "Capitalize NEWSGROUP name."
  3860. (when (not (zerop (length newsgroup)))
  3861. (concat (char-to-string (upcase (aref newsgroup 0)))
  3862. (substring newsgroup 1))))
  3863. (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
  3864. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3865. If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
  3866. Otherwise, it is like ~/News/news/group/num."
  3867. (let ((default
  3868. (expand-file-name
  3869. (concat (if (gnus-use-long-file-name 'not-save)
  3870. (gnus-capitalize-newsgroup newsgroup)
  3871. (gnus-newsgroup-directory-form newsgroup))
  3872. "/" (int-to-string (mail-header-number headers)))
  3873. gnus-article-save-directory)))
  3874. (if (and last-file
  3875. (string-equal (file-name-directory default)
  3876. (file-name-directory last-file))
  3877. (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  3878. default
  3879. (or last-file default))))
  3880. (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
  3881. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3882. If variable `gnus-use-long-file-name' is non-nil, it is
  3883. ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
  3884. (let ((default
  3885. (expand-file-name
  3886. (concat (if (gnus-use-long-file-name 'not-save)
  3887. newsgroup
  3888. (gnus-newsgroup-directory-form newsgroup))
  3889. "/" (int-to-string (mail-header-number headers)))
  3890. gnus-article-save-directory)))
  3891. (if (and last-file
  3892. (string-equal (file-name-directory default)
  3893. (file-name-directory last-file))
  3894. (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  3895. default
  3896. (or last-file default))))
  3897. (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
  3898. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3899. If variable `gnus-use-long-file-name' is non-nil, it is
  3900. ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
  3901. (or last-file
  3902. (expand-file-name
  3903. (if (gnus-use-long-file-name 'not-save)
  3904. newsgroup
  3905. (file-relative-name
  3906. (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
  3907. default-directory))
  3908. gnus-article-save-directory)))
  3909. (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
  3910. "Generate file name from sender."
  3911. (let ((from (mail-header-from headers)))
  3912. (expand-file-name
  3913. (if (and from (string-match "\\([^ <]+\\)@" from))
  3914. (match-string 1 from)
  3915. "nobody")
  3916. gnus-article-save-directory)))
  3917. (defun article-verify-x-pgp-sig ()
  3918. "Verify X-PGP-Sig."
  3919. ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
  3920. (interactive)
  3921. (if (gnus-buffer-live-p gnus-original-article-buffer)
  3922. (let ((sig (with-current-buffer gnus-original-article-buffer
  3923. (gnus-fetch-field "X-PGP-Sig")))
  3924. items info headers)
  3925. (when (and sig
  3926. mml2015-use
  3927. (mml2015-clear-verify-function))
  3928. (with-temp-buffer
  3929. (insert-buffer-substring gnus-original-article-buffer)
  3930. (setq items (split-string sig))
  3931. (message-narrow-to-head)
  3932. (let ((inhibit-point-motion-hooks t)
  3933. (case-fold-search t))
  3934. ;; Don't verify multiple headers.
  3935. (setq headers (mapconcat (lambda (header)
  3936. (concat header ": "
  3937. (mail-fetch-field header)
  3938. "\n"))
  3939. (split-string (nth 1 items) ",") "")))
  3940. (delete-region (point-min) (point-max))
  3941. (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
  3942. (insert "X-Signed-Headers: " (nth 1 items) "\n")
  3943. (insert headers)
  3944. (widen)
  3945. (forward-line)
  3946. (while (not (eobp))
  3947. (if (looking-at "^-")
  3948. (insert "- "))
  3949. (forward-line))
  3950. (insert "\n-----BEGIN PGP SIGNATURE-----\n")
  3951. (insert "Version: " (car items) "\n\n")
  3952. (insert (mapconcat 'identity (cddr items) "\n"))
  3953. (insert "\n-----END PGP SIGNATURE-----\n")
  3954. (let ((mm-security-handle (list (format "multipart/signed"))))
  3955. (mml2015-clean-buffer)
  3956. (let ((coding-system-for-write (or gnus-newsgroup-charset
  3957. 'iso-8859-1)))
  3958. (funcall (mml2015-clear-verify-function)))
  3959. (setq info
  3960. (or (mm-handle-multipart-ctl-parameter
  3961. mm-security-handle 'gnus-details)
  3962. (mm-handle-multipart-ctl-parameter
  3963. mm-security-handle 'gnus-info)))))
  3964. (when info
  3965. (let ((inhibit-read-only t) bface eface)
  3966. (save-restriction
  3967. (message-narrow-to-head)
  3968. (goto-char (point-max))
  3969. (forward-line -1)
  3970. (setq bface (get-text-property (point-at-bol) 'face)
  3971. eface (get-text-property (1- (point-at-eol)) 'face))
  3972. (message-remove-header "X-Gnus-PGP-Verify")
  3973. (if (re-search-forward "^X-PGP-Sig:" nil t)
  3974. (forward-line)
  3975. (goto-char (point-max)))
  3976. (narrow-to-region (point) (point))
  3977. (insert "X-Gnus-PGP-Verify: " info "\n")
  3978. (goto-char (point-min))
  3979. (forward-line)
  3980. (while (not (eobp))
  3981. (if (not (looking-at "^[ \t]"))
  3982. (insert " "))
  3983. (forward-line))
  3984. ;; Do highlighting.
  3985. (goto-char (point-min))
  3986. (when (looking-at "\\([^:]+\\): *")
  3987. (put-text-property (match-beginning 1) (1+ (match-end 1))
  3988. 'face bface)
  3989. (put-text-property (match-end 0) (point-max)
  3990. 'face eface)))))))))
  3991. (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
  3992. (defun article-verify-cancel-lock ()
  3993. "Verify Cancel-Lock header."
  3994. (interactive)
  3995. (if (gnus-buffer-live-p gnus-original-article-buffer)
  3996. (canlock-verify gnus-original-article-buffer)))
  3997. (eval-and-compile
  3998. (mapc
  3999. (lambda (func)
  4000. (let (afunc gfunc)
  4001. (if (consp func)
  4002. (setq afunc (car func)
  4003. gfunc (cdr func))
  4004. (setq afunc func
  4005. gfunc (intern (format "gnus-%s" func))))
  4006. (defalias gfunc
  4007. (when (fboundp afunc)
  4008. `(lambda (&optional interactive &rest args)
  4009. ,(documentation afunc t)
  4010. (interactive (list t))
  4011. (with-current-buffer gnus-article-buffer
  4012. (if interactive
  4013. (call-interactively ',afunc)
  4014. (apply ',afunc args))))))))
  4015. '(article-hide-headers
  4016. article-verify-x-pgp-sig
  4017. article-verify-cancel-lock
  4018. article-hide-boring-headers
  4019. article-treat-overstrike
  4020. article-treat-ansi-sequences
  4021. article-fill-long-lines
  4022. article-capitalize-sentences
  4023. article-remove-cr
  4024. article-remove-leading-whitespace
  4025. article-display-x-face
  4026. article-display-face
  4027. article-de-quoted-unreadable
  4028. article-de-base64-unreadable
  4029. article-decode-HZ
  4030. article-wash-html
  4031. article-unsplit-urls
  4032. article-hide-list-identifiers
  4033. article-strip-banner
  4034. article-babel
  4035. article-hide-pem
  4036. article-hide-signature
  4037. article-strip-headers-in-body
  4038. article-remove-trailing-blank-lines
  4039. article-strip-leading-blank-lines
  4040. article-strip-multiple-blank-lines
  4041. article-strip-leading-space
  4042. article-strip-trailing-space
  4043. article-strip-blank-lines
  4044. article-strip-all-blank-lines
  4045. article-date-local
  4046. article-date-english
  4047. article-date-iso8601
  4048. article-date-original
  4049. article-treat-date
  4050. article-date-ut
  4051. article-decode-mime-words
  4052. article-decode-charset
  4053. article-decode-encoded-words
  4054. article-date-user
  4055. article-date-lapsed
  4056. article-date-combined-lapsed
  4057. article-emphasize
  4058. article-treat-dumbquotes
  4059. article-treat-non-ascii
  4060. article-normalize-headers
  4061. ;;(article-show-all . gnus-article-show-all-headers)
  4062. )))
  4063. ;;;
  4064. ;;; Gnus article mode
  4065. ;;;
  4066. (put 'gnus-article-mode 'mode-class 'special)
  4067. (set-keymap-parent gnus-article-mode-map widget-keymap)
  4068. (gnus-define-keys gnus-article-mode-map
  4069. " " gnus-article-goto-next-page
  4070. [?\S-\ ] gnus-article-goto-prev-page
  4071. "\177" gnus-article-goto-prev-page
  4072. [delete] gnus-article-goto-prev-page
  4073. "\C-c^" gnus-article-refer-article
  4074. "h" gnus-article-show-summary
  4075. "s" gnus-article-show-summary
  4076. "\C-c\C-m" gnus-article-mail
  4077. "?" gnus-article-describe-briefly
  4078. "<" beginning-of-buffer
  4079. ">" end-of-buffer
  4080. "\C-c\C-i" gnus-info-find-node
  4081. "\C-c\C-b" gnus-bug
  4082. "R" gnus-article-reply-with-original
  4083. "F" gnus-article-followup-with-original
  4084. "\C-hk" gnus-article-describe-key
  4085. "\C-hc" gnus-article-describe-key-briefly
  4086. "\C-hb" gnus-article-describe-bindings
  4087. "e" gnus-article-read-summary-keys
  4088. "\C-d" gnus-article-read-summary-keys
  4089. "\M-*" gnus-article-read-summary-keys
  4090. "\M-#" gnus-article-read-summary-keys
  4091. "\M-^" gnus-article-read-summary-keys
  4092. "\M-g" gnus-article-read-summary-keys)
  4093. (substitute-key-definition
  4094. 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
  4095. (defvar gnus-article-send-map)
  4096. (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
  4097. "W" gnus-article-wide-reply-with-original)
  4098. (if (featurep 'xemacs)
  4099. (set-keymap-default-binding gnus-article-send-map
  4100. 'gnus-article-read-summary-send-keys)
  4101. (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
  4102. (defun gnus-article-make-menu-bar ()
  4103. (unless (boundp 'gnus-article-commands-menu)
  4104. (gnus-summary-make-menu-bar))
  4105. (unless (boundp 'gnus-article-article-menu)
  4106. (easy-menu-define
  4107. gnus-article-article-menu gnus-article-mode-map ""
  4108. '("Article"
  4109. ["Scroll forwards" gnus-article-goto-next-page t]
  4110. ["Scroll backwards" gnus-article-goto-prev-page t]
  4111. ["Show summary" gnus-article-show-summary t]
  4112. ["Fetch Message-ID at point" gnus-article-refer-article t]
  4113. ["Mail to address at point" gnus-article-mail t]
  4114. ["Send a bug report" gnus-bug t]))
  4115. (easy-menu-define
  4116. gnus-article-treatment-menu gnus-article-mode-map ""
  4117. ;; Fixme: this should use :active (and maybe :visible).
  4118. '("Treatment"
  4119. ["Hide headers" gnus-article-hide-headers t]
  4120. ["Hide signature" gnus-article-hide-signature t]
  4121. ["Hide citation" gnus-article-hide-citation t]
  4122. ["Treat overstrike" gnus-article-treat-overstrike t]
  4123. ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
  4124. ["Remove carriage return" gnus-article-remove-cr t]
  4125. ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
  4126. ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
  4127. ["Remove base64" gnus-article-de-base64-unreadable t]
  4128. ["Treat html" gnus-article-wash-html t]
  4129. ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
  4130. ["Decode HZ" gnus-article-decode-HZ t]))
  4131. ;; Note "Commands" menu is defined in gnus-sum.el for consistency
  4132. ;; Note "Post" menu is defined in gnus-sum.el for consistency
  4133. (gnus-run-hooks 'gnus-article-menu-hook)))
  4134. (defvar bookmark-make-record-function)
  4135. (defvar shr-put-image-function)
  4136. (define-derived-mode gnus-article-mode fundamental-mode "Article"
  4137. "Major mode for displaying an article.
  4138. All normal editing commands are switched off.
  4139. The following commands are available in addition to all summary mode
  4140. commands:
  4141. \\<gnus-article-mode-map>
  4142. \\[gnus-article-next-page]\t Scroll the article one page forwards
  4143. \\[gnus-article-prev-page]\t Scroll the article one page backwards
  4144. \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
  4145. \\[gnus-article-show-summary]\t Display the summary buffer
  4146. \\[gnus-article-mail]\t Send a reply to the address near point
  4147. \\[gnus-article-describe-briefly]\t Describe the current mode briefly
  4148. \\[gnus-info-find-node]\t Go to the Gnus info node"
  4149. (gnus-simplify-mode-line)
  4150. (make-local-variable 'minor-mode-alist)
  4151. (when (gnus-visual-p 'article-menu 'menu)
  4152. (gnus-article-make-menu-bar)
  4153. (when gnus-summary-tool-bar-map
  4154. (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
  4155. (gnus-update-format-specifications nil 'article-mode)
  4156. (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
  4157. (set (make-local-variable 'gnus-page-broken) nil)
  4158. (make-local-variable 'gnus-article-current-summary)
  4159. (make-local-variable 'gnus-article-mime-handles)
  4160. (make-local-variable 'gnus-article-decoded-p)
  4161. (make-local-variable 'gnus-article-mime-handle-alist)
  4162. (make-local-variable 'gnus-article-wash-types)
  4163. (make-local-variable 'gnus-article-image-alist)
  4164. (make-local-variable 'gnus-article-charset)
  4165. (make-local-variable 'gnus-article-ignored-charsets)
  4166. (set (make-local-variable 'bookmark-make-record-function)
  4167. 'gnus-summary-bookmark-make-record)
  4168. ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
  4169. ;; face.
  4170. (set (make-local-variable 'nobreak-char-display) nil)
  4171. ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
  4172. (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
  4173. (unless gnus-article-show-cursor
  4174. (setq cursor-in-non-selected-windows nil))
  4175. (gnus-set-default-directory)
  4176. (buffer-disable-undo)
  4177. (setq buffer-read-only t
  4178. show-trailing-whitespace nil)
  4179. (mm-enable-multibyte))
  4180. (defun gnus-article-setup-buffer ()
  4181. "Initialize the article buffer."
  4182. (let* ((name (if gnus-single-article-buffer "*Article*"
  4183. (concat "*Article "
  4184. (gnus-group-decoded-name gnus-newsgroup-name)
  4185. "*")))
  4186. (original
  4187. (progn (string-match "\\*Article" name)
  4188. (concat " *Original Article"
  4189. (substring name (match-end 0))))))
  4190. (setq gnus-article-buffer name)
  4191. (setq gnus-original-article-buffer original)
  4192. (setq gnus-article-mime-handle-alist nil)
  4193. (with-current-buffer gnus-summary-buffer
  4194. ;; This might be a variable local to the summary buffer.
  4195. (unless gnus-single-article-buffer
  4196. (setq gnus-article-buffer name)
  4197. (setq gnus-original-article-buffer original)
  4198. (gnus-set-global-variables)))
  4199. (gnus-article-setup-highlight-words)
  4200. ;; Init original article buffer.
  4201. (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
  4202. (mm-enable-multibyte)
  4203. (setq major-mode 'gnus-original-article-mode)
  4204. (make-local-variable 'gnus-original-article))
  4205. (if (and (get-buffer name)
  4206. (with-current-buffer name
  4207. (if gnus-article-edit-mode
  4208. (if (y-or-n-p "Article mode edit in progress; discard? ")
  4209. (progn
  4210. (set-buffer-modified-p nil)
  4211. (gnus-kill-buffer name)
  4212. (message "")
  4213. nil)
  4214. (error "Action aborted"))
  4215. t)))
  4216. (let ((summary gnus-summary-buffer))
  4217. (with-current-buffer name
  4218. (set (make-local-variable 'gnus-article-edit-mode) nil)
  4219. (gnus-article-stop-animations)
  4220. (when gnus-article-mime-handles
  4221. (mm-destroy-parts gnus-article-mime-handles)
  4222. (setq gnus-article-mime-handles nil))
  4223. ;; Set it to nil in article-buffer!
  4224. (setq gnus-article-mime-handle-alist nil)
  4225. (buffer-disable-undo)
  4226. (setq buffer-read-only t)
  4227. (unless (derived-mode-p 'gnus-article-mode)
  4228. (gnus-article-mode))
  4229. (set (make-local-variable 'gnus-summary-buffer) summary)
  4230. (setq truncate-lines gnus-article-truncate-lines)
  4231. (current-buffer)))
  4232. (let ((summary gnus-summary-buffer))
  4233. (with-current-buffer (gnus-get-buffer-create name)
  4234. (gnus-article-mode)
  4235. (setq truncate-lines gnus-article-truncate-lines)
  4236. (set (make-local-variable 'gnus-summary-buffer) summary)
  4237. (gnus-summary-set-local-parameters gnus-newsgroup-name)
  4238. (when article-lapsed-timer
  4239. (gnus-stop-date-timer))
  4240. (when gnus-article-update-date-headers
  4241. (gnus-start-date-timer gnus-article-update-date-headers))
  4242. (current-buffer))))))
  4243. (defun gnus-article-stop-animations ()
  4244. (dolist (timer (and (boundp 'timer-list)
  4245. timer-list))
  4246. (when (eq (gnus-timer--function timer) 'image-animate-timeout)
  4247. (cancel-timer timer))))
  4248. (defun gnus-stop-downloads ()
  4249. (when (boundp 'url-queue)
  4250. (set (intern "url-queue" obarray) nil)))
  4251. ;; Set article window start at LINE, where LINE is the number of lines
  4252. ;; from the head of the article.
  4253. (defun gnus-article-set-window-start (&optional line)
  4254. (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
  4255. (when article-window
  4256. (set-window-start
  4257. article-window
  4258. (with-current-buffer gnus-article-buffer
  4259. (goto-char (point-min))
  4260. (if (not line)
  4261. (point-min)
  4262. (gnus-message 6 "Moved to bookmark")
  4263. (search-forward "\n\n" nil t)
  4264. (forward-line line)
  4265. (point)))))))
  4266. (defvar gnus-tmp-internal-hook)
  4267. (defun gnus-article-prepare (article &optional all-headers _header)
  4268. "Prepare ARTICLE in article mode buffer.
  4269. ARTICLE should either be an article number or a Message-ID.
  4270. If ARTICLE is an id, HEADER should be the article headers.
  4271. If ALL-HEADERS is non-nil, no headers are hidden."
  4272. (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
  4273. ;; Make sure we start in a summary buffer.
  4274. (unless (derived-mode-p 'gnus-summary-mode)
  4275. (set-buffer gnus-summary-buffer))
  4276. (setq gnus-summary-buffer (current-buffer))
  4277. (let* ((summary-buffer (current-buffer))
  4278. (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
  4279. (group gnus-newsgroup-name)
  4280. result)
  4281. (save-excursion
  4282. (gnus-article-setup-buffer)
  4283. (set-buffer gnus-article-buffer)
  4284. ;; Deactivate active regions.
  4285. (when (and (boundp 'transient-mark-mode)
  4286. transient-mark-mode)
  4287. (setq mark-active nil))
  4288. (if (not (setq result (let ((inhibit-read-only t))
  4289. (gnus-request-article-this-buffer
  4290. article group))))
  4291. ;; There is no such article.
  4292. (save-excursion
  4293. (when (and (numberp article)
  4294. (not (memq article gnus-newsgroup-sparse)))
  4295. (setq gnus-article-current
  4296. (cons gnus-newsgroup-name article))
  4297. (set-buffer gnus-summary-buffer)
  4298. (setq gnus-current-article article)
  4299. (if (and (memq article gnus-newsgroup-undownloaded)
  4300. (not (gnus-online (gnus-find-method-for-group
  4301. gnus-newsgroup-name))))
  4302. (progn
  4303. (gnus-summary-set-agent-mark article)
  4304. (message "Message marked for downloading"))
  4305. (gnus-summary-mark-article article gnus-canceled-mark)
  4306. (unless (memq article gnus-newsgroup-sparse)
  4307. (gnus-error 1 "No such article (may have expired or been canceled)")))))
  4308. (if (or (eq result 'pseudo)
  4309. (eq result 'nneething))
  4310. (progn
  4311. (with-current-buffer summary-buffer
  4312. (push article gnus-newsgroup-history)
  4313. (setq gnus-last-article gnus-current-article
  4314. gnus-current-article 0
  4315. gnus-current-headers nil
  4316. gnus-article-current nil)
  4317. (if (eq result 'nneething)
  4318. (gnus-configure-windows 'summary)
  4319. (gnus-configure-windows 'article))
  4320. (gnus-set-global-variables))
  4321. (let ((gnus-article-mime-handle-alist-1
  4322. gnus-article-mime-handle-alist))
  4323. (gnus-set-mode-line 'article)))
  4324. ;; The result from the `request' was an actual article -
  4325. ;; or at least some text that is now displayed in the
  4326. ;; article buffer.
  4327. (when (and (numberp article)
  4328. (not (eq article gnus-current-article)))
  4329. ;; Seems like a new article has been selected.
  4330. ;; `gnus-current-article' must be an article number.
  4331. (with-current-buffer summary-buffer
  4332. (push article gnus-newsgroup-history)
  4333. (setq gnus-last-article gnus-current-article
  4334. gnus-current-article article
  4335. gnus-current-headers
  4336. (gnus-summary-article-header gnus-current-article)
  4337. gnus-article-current
  4338. (cons gnus-newsgroup-name gnus-current-article))
  4339. (unless (vectorp gnus-current-headers)
  4340. (setq gnus-current-headers nil))
  4341. (gnus-summary-goto-subject gnus-current-article)
  4342. (when (gnus-summary-show-thread)
  4343. ;; If the summary buffer really was folded, the
  4344. ;; previous goto may not actually have gone to
  4345. ;; the right article, but the thread root instead.
  4346. ;; So we go again.
  4347. (gnus-summary-goto-subject gnus-current-article))
  4348. (gnus-run-hooks 'gnus-mark-article-hook)
  4349. (gnus-set-mode-line 'summary)
  4350. (when (gnus-visual-p 'article-highlight 'highlight)
  4351. (gnus-run-hooks 'gnus-visual-mark-article-hook))
  4352. ;; Set the global newsgroup variables here.
  4353. (gnus-set-global-variables)
  4354. (setq gnus-have-all-headers
  4355. (or all-headers gnus-show-all-headers))))
  4356. (save-excursion
  4357. (gnus-configure-windows 'article))
  4358. (when (or (numberp article)
  4359. (stringp article))
  4360. (gnus-article-prepare-display)
  4361. ;; Do page break.
  4362. (goto-char (point-min))
  4363. (when gnus-break-pages
  4364. (gnus-narrow-to-page)))
  4365. (let ((gnus-article-mime-handle-alist-1
  4366. gnus-article-mime-handle-alist))
  4367. (gnus-set-mode-line 'article))
  4368. (article-goto-body)
  4369. (unless (bobp)
  4370. (forward-line -1))
  4371. (set-window-point (get-buffer-window (current-buffer)) (point))
  4372. (gnus-configure-windows 'article)
  4373. (gnus-run-hooks 'gnus-article-prepare-hook)
  4374. t))))))
  4375. (defvar gnus-mime-display-attachment-buttons-in-header)
  4376. ;;;###autoload
  4377. (defun gnus-article-prepare-display ()
  4378. "Make the current buffer look like a nice article."
  4379. ;; Hooks for getting information from the article.
  4380. ;; This hook must be called before being narrowed.
  4381. (let ((gnus-article-buffer (current-buffer))
  4382. buffer-read-only
  4383. (inhibit-read-only t))
  4384. (unless (derived-mode-p 'gnus-article-mode)
  4385. (gnus-article-mode))
  4386. (setq buffer-read-only nil
  4387. gnus-article-wash-types nil
  4388. gnus-article-image-alist nil)
  4389. (gnus-run-hooks 'gnus-tmp-internal-hook)
  4390. (when gnus-display-mime-function
  4391. (funcall gnus-display-mime-function))
  4392. ;; Add attachment buttons to the header.
  4393. (when gnus-mime-display-attachment-buttons-in-header
  4394. (gnus-mime-buttonize-attachments-in-header))))
  4395. ;;;
  4396. ;;; Gnus Sticky Article Mode
  4397. ;;;
  4398. (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
  4399. "Mode for sticky articles."
  4400. ;; Release bindings that won't work.
  4401. (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
  4402. gnus-sticky-article-mode-map)
  4403. (substitute-key-definition 'gnus-article-refer-article 'undefined
  4404. gnus-sticky-article-mode-map)
  4405. (dolist (k '("e" "h" "s" "F" "R"))
  4406. (define-key gnus-sticky-article-mode-map k nil))
  4407. (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
  4408. (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
  4409. (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
  4410. (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
  4411. (defun gnus-sticky-article (arg)
  4412. "Make the current article sticky.
  4413. If a prefix ARG is given, ask for a name for this sticky article buffer."
  4414. (interactive "P")
  4415. (gnus-summary-show-thread)
  4416. (gnus-summary-select-article nil nil 'pseudo)
  4417. (let (new-art-buf-name)
  4418. (gnus-eval-in-buffer-window gnus-article-buffer
  4419. (setq new-art-buf-name
  4420. (concat
  4421. "*Sticky Article: "
  4422. (if arg
  4423. (read-from-minibuffer "Sticky article buffer name: ")
  4424. (gnus-with-article-headers
  4425. (gnus-article-goto-header "subject")
  4426. (setq new-art-buf-name
  4427. (buffer-substring-no-properties
  4428. (line-beginning-position) (line-end-position)))
  4429. (goto-char (point-min))
  4430. (gnus-article-goto-header "from")
  4431. (setq new-art-buf-name
  4432. (concat
  4433. new-art-buf-name ", "
  4434. (buffer-substring-no-properties
  4435. (line-beginning-position) (line-end-position))))
  4436. (goto-char (point-min))
  4437. (gnus-article-goto-header "date")
  4438. (setq new-art-buf-name
  4439. (concat
  4440. new-art-buf-name ", "
  4441. (buffer-substring-no-properties
  4442. (line-beginning-position) (line-end-position))))))
  4443. "*"))
  4444. (if (and (gnus-buffer-live-p new-art-buf-name)
  4445. (with-current-buffer new-art-buf-name
  4446. (derived-mode-p 'gnus-sticky-article-mode)))
  4447. (switch-to-buffer new-art-buf-name)
  4448. (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
  4449. (gnus-sticky-article-mode))
  4450. (setq gnus-article-buffer new-art-buf-name))
  4451. (gnus-summary-recenter)
  4452. (gnus-summary-position-point))
  4453. (defun gnus-kill-sticky-article-buffer (&optional buffer)
  4454. "Kill the given sticky article BUFFER.
  4455. If none is given, assume the current buffer and kill it if it has
  4456. `gnus-sticky-article-mode'."
  4457. (interactive)
  4458. (unless buffer
  4459. (setq buffer (current-buffer)))
  4460. (with-current-buffer buffer
  4461. (when (derived-mode-p 'gnus-sticky-article-mode)
  4462. (gnus-kill-buffer buffer))))
  4463. (defun gnus-kill-sticky-article-buffers (arg)
  4464. "Kill all sticky article buffers.
  4465. If a prefix ARG is given, ask for confirmation."
  4466. (interactive "P")
  4467. (dolist (buf (gnus-buffers))
  4468. (with-current-buffer buf
  4469. (when (derived-mode-p 'gnus-sticky-article-mode)
  4470. (if (not arg)
  4471. (gnus-kill-buffer buf)
  4472. (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
  4473. (gnus-kill-buffer buf)))))))
  4474. ;;;
  4475. ;;; Gnus MIME viewing functions
  4476. ;;;
  4477. (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
  4478. "Format of the MIME buttons.
  4479. Valid specifiers include:
  4480. %t The MIME type
  4481. %T MIME type, along with additional info
  4482. %n The `name' parameter
  4483. %d The description, if any
  4484. %l The length of the encoded part
  4485. %p The part identifier number
  4486. %e Dots if the part isn't displayed
  4487. General format specifiers can also be used. See Info node
  4488. `(gnus)Formatting Variables'.")
  4489. (defvar gnus-tmp-type)
  4490. (defvar gnus-tmp-type-long)
  4491. (defvar gnus-tmp-name)
  4492. (defvar gnus-tmp-description)
  4493. (defvar gnus-tmp-id)
  4494. (defvar gnus-tmp-length)
  4495. (defvar gnus-tmp-dots)
  4496. (defvar gnus-tmp-info)
  4497. (defvar gnus-tmp-pressed-details)
  4498. (defvar gnus-mime-button-line-format-alist
  4499. '((?t gnus-tmp-type ?s)
  4500. (?T gnus-tmp-type-long ?s)
  4501. (?n gnus-tmp-name ?s)
  4502. (?d gnus-tmp-description ?s)
  4503. (?p gnus-tmp-id ?s)
  4504. (?l gnus-tmp-length ?d)
  4505. (?e gnus-tmp-dots ?s)))
  4506. (defvar gnus-mime-button-commands
  4507. '((gnus-article-press-button "\r" "Toggle Display")
  4508. (gnus-mime-view-part "v" "View Interactively...")
  4509. (gnus-mime-view-part-as-type "t" "View As Type...")
  4510. (gnus-mime-view-part-as-charset "C" "View As charset...")
  4511. (gnus-mime-save-part "o" "Save...")
  4512. (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
  4513. (gnus-mime-replace-part "r" "Replace part")
  4514. (gnus-mime-delete-part "d" "Delete part")
  4515. (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
  4516. (gnus-mime-inline-part "i" "View As Text, In This Buffer")
  4517. (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
  4518. (gnus-mime-view-part-externally "e" "View Externally")
  4519. (gnus-mime-print-part "p" "Print")
  4520. (gnus-mime-pipe-part "|" "Pipe To Command...")
  4521. (gnus-mime-action-on-part "." "Take action on the part...")))
  4522. (defun gnus-article-mime-part-status ()
  4523. (if gnus-article-mime-handle-alist-1
  4524. (if (eq 1 (length gnus-article-mime-handle-alist-1))
  4525. " (1 part)"
  4526. (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
  4527. ""))
  4528. (defvar gnus-mime-button-map
  4529. (let ((map (make-sparse-keymap)))
  4530. (define-key map gnus-mouse-2 'gnus-article-push-button)
  4531. (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
  4532. (dolist (c gnus-mime-button-commands)
  4533. (define-key map (cadr c) (car c)))
  4534. map))
  4535. (easy-menu-define
  4536. gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
  4537. `("MIME Part"
  4538. ,@(mapcar (lambda (c)
  4539. (vector (caddr c) (car c) :active t))
  4540. gnus-mime-button-commands)))
  4541. (defvar gnus-url-button-commands
  4542. '((gnus-article-copy-string "u" "Copy URL to kill ring")))
  4543. (defvar gnus-url-button-map
  4544. (let ((map (make-sparse-keymap)))
  4545. (dolist (c gnus-url-button-commands)
  4546. (define-key map (cadr c) (car c)))
  4547. map))
  4548. (easy-menu-define
  4549. gnus-url-button-menu gnus-url-button-map "URL button menu."
  4550. `("Url Button"
  4551. ,@(mapcar (lambda (c)
  4552. (vector (caddr c) (car c) :active t))
  4553. gnus-url-button-commands)))
  4554. (defmacro gnus-bind-mm-vars (&rest body)
  4555. "Bind some mm-* variables and execute BODY."
  4556. `(let (mm-html-inhibit-images
  4557. mm-html-blocked-images
  4558. (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
  4559. (with-current-buffer
  4560. (cond ((derived-mode-p 'gnus-article-mode)
  4561. (if (gnus-buffer-live-p gnus-article-current-summary)
  4562. gnus-article-current-summary
  4563. ;; Maybe we're in a mml-preview buffer
  4564. ;; and no group is selected.
  4565. (current-buffer)))
  4566. ((gnus-buffer-live-p gnus-summary-buffer)
  4567. gnus-summary-buffer)
  4568. (t (current-buffer)))
  4569. (setq mm-html-inhibit-images gnus-inhibit-images
  4570. mm-html-blocked-images (gnus-blocked-images))
  4571. (when (or (not gnus-newsgroup-name)
  4572. (and (stringp gnus-safe-html-newsgroups)
  4573. (string-match gnus-safe-html-newsgroups
  4574. gnus-newsgroup-name))
  4575. (and (consp gnus-safe-html-newsgroups)
  4576. (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
  4577. (setq mm-w3m-safe-url-regexp nil)))
  4578. ,@body))
  4579. (defun gnus-mime-button-menu (event prefix)
  4580. "Construct a context-sensitive menu of MIME commands."
  4581. (interactive "e\nP")
  4582. (save-window-excursion
  4583. (let ((pos (event-start event)))
  4584. (select-window (posn-window pos))
  4585. (goto-char (posn-point pos))
  4586. (gnus-article-check-buffer)
  4587. (popup-menu gnus-mime-button-menu nil prefix))))
  4588. (defun gnus-mime-view-all-parts (&optional handles)
  4589. "View all the MIME parts."
  4590. (interactive)
  4591. (with-current-buffer gnus-article-buffer
  4592. (let ((handles (or handles gnus-article-mime-handles))
  4593. (mail-parse-charset gnus-newsgroup-charset)
  4594. (mail-parse-ignored-charsets
  4595. (with-current-buffer gnus-summary-buffer
  4596. gnus-newsgroup-ignored-charsets)))
  4597. (when handles
  4598. (mm-remove-parts handles)
  4599. (goto-char (point-min))
  4600. (or (search-forward "\n\n") (goto-char (point-max)))
  4601. (let ((inhibit-read-only t))
  4602. (delete-region (point) (point-max))
  4603. (gnus-bind-mm-vars (mm-display-parts handles)))))))
  4604. (defun gnus-article-jump-to-part (n)
  4605. "Jump to MIME part N."
  4606. (interactive "P")
  4607. (let ((parts (with-current-buffer gnus-article-buffer
  4608. (length gnus-article-mime-handle-alist))))
  4609. (when (zerop parts)
  4610. (error "No such part"))
  4611. (pop-to-buffer gnus-article-buffer)
  4612. (or n
  4613. (setq n (if (= parts 1)
  4614. 1
  4615. (read-number (format "Jump to part (1..%s): " parts)))))
  4616. (unless (and (integerp n) (<= n parts) (>= n 1))
  4617. (setq n
  4618. (progn
  4619. (gnus-message 7 "Invalid part `%s', using %s instead."
  4620. n parts)
  4621. parts)))
  4622. (gnus-message 9 "Jumping to part %s." n)
  4623. (cond ((>= gnus-auto-select-part 1)
  4624. (while (and (<= n parts)
  4625. (not (gnus-article-goto-part n)))
  4626. (setq n (1+ n))))
  4627. ((< gnus-auto-select-part 0)
  4628. (while (and (>= n 1)
  4629. (not (gnus-article-goto-part n)))
  4630. (setq n (1- n))))
  4631. (t
  4632. (gnus-article-goto-part n)))))
  4633. (defvar gnus-mime-buttonized-part-id nil
  4634. "ID of a mime part that should be buttonized.
  4635. `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
  4636. (eval-when-compile
  4637. (defsubst gnus-article-edit-part (handles &optional current-id)
  4638. "Edit an article in order to delete a mime part.
  4639. This function is exclusively used by `gnus-mime-save-part-and-strip'
  4640. and `gnus-mime-delete-part', and not provided at run-time normally."
  4641. (gnus-article-edit-article
  4642. `(lambda ()
  4643. (buffer-disable-undo)
  4644. (let ((mail-parse-charset (or gnus-article-charset
  4645. ',gnus-newsgroup-charset))
  4646. (mail-parse-ignored-charsets
  4647. (or gnus-article-ignored-charsets
  4648. ',gnus-newsgroup-ignored-charsets))
  4649. (mbl mml-buffer-list))
  4650. (setq mml-buffer-list nil)
  4651. ;; A new text must be inserted before deleting existing ones
  4652. ;; at the end so as not to move existing markers of which
  4653. ;; the insertion type is t.
  4654. (delete-region
  4655. (point-min)
  4656. (prog1
  4657. (goto-char (point-max))
  4658. (insert-buffer-substring gnus-original-article-buffer)))
  4659. (mime-to-mml ',handles)
  4660. (setq gnus-article-mime-handles nil)
  4661. (let ((mbl1 mml-buffer-list))
  4662. (setq mml-buffer-list mbl)
  4663. (set (make-local-variable 'mml-buffer-list) mbl1))
  4664. (gnus-make-local-hook 'kill-buffer-hook)
  4665. (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
  4666. `(lambda (no-highlight)
  4667. (let ((mail-parse-charset (or gnus-article-charset
  4668. ',gnus-newsgroup-charset))
  4669. (message-options message-options)
  4670. (message-options-set-recipient)
  4671. (mail-parse-ignored-charsets
  4672. (or gnus-article-ignored-charsets
  4673. ',gnus-newsgroup-ignored-charsets)))
  4674. (mml-to-mime)
  4675. (mml-destroy-buffers)
  4676. (remove-hook 'kill-buffer-hook
  4677. 'mml-destroy-buffers t)
  4678. (kill-local-variable 'mml-buffer-list))
  4679. (gnus-summary-edit-article-done
  4680. ,(or (mail-header-references gnus-current-headers) "")
  4681. ,(gnus-group-read-only-p)
  4682. ,gnus-summary-buffer no-highlight))
  4683. t)
  4684. ;; Force buttonizing this part.
  4685. (let ((gnus-mime-buttonized-part-id current-id))
  4686. (gnus-article-edit-done))
  4687. (gnus-configure-windows 'article)
  4688. (sit-for 0)
  4689. (when (and current-id (integerp gnus-auto-select-part))
  4690. (gnus-article-jump-to-part
  4691. (min (max (+ current-id gnus-auto-select-part) 1)
  4692. (with-current-buffer gnus-article-buffer
  4693. (length gnus-article-mime-handle-alist)))))))
  4694. (defun gnus-mime-replace-part (file)
  4695. "Replace MIME part under point with an external body."
  4696. ;; Useful if file has already been saved to disk
  4697. (interactive
  4698. (list
  4699. (read-file-name "Replace MIME part with file: "
  4700. (or mm-default-directory default-directory)
  4701. nil nil)))
  4702. (gnus-mime-save-part-and-strip file))
  4703. (defun gnus-mime-save-part-and-strip (&optional file)
  4704. "Save the MIME part under point then replace it with an external body.
  4705. If FILE is given, use it for the external part."
  4706. (interactive)
  4707. (gnus-article-check-buffer)
  4708. (when (gnus-group-read-only-p)
  4709. (error "The current group does not support deleting of parts"))
  4710. (when (mm-complicated-handles gnus-article-mime-handles)
  4711. (error "\
  4712. The current article has a complicated MIME structure, giving up..."))
  4713. (let* ((data (get-text-property (point) 'gnus-data))
  4714. (id (get-text-property (point) 'gnus-part))
  4715. (handles gnus-article-mime-handles))
  4716. (unless file
  4717. (setq file
  4718. (and data (mm-save-part data "Delete MIME part and save to: "))))
  4719. (when file
  4720. (with-current-buffer (mm-handle-buffer data)
  4721. (erase-buffer)
  4722. (insert "Content-Type: " (mm-handle-media-type data))
  4723. (mml-insert-parameter-string (cdr (mm-handle-type data))
  4724. '(charset))
  4725. ;; Add a filename for the sake of saving the part again.
  4726. (mml-insert-parameter
  4727. (mail-header-encode-parameter "name" (file-name-nondirectory file)))
  4728. (insert "\n")
  4729. (insert "Content-ID: " (message-make-message-id) "\n")
  4730. (insert "Content-Transfer-Encoding: binary\n")
  4731. (insert "\n"))
  4732. (setcdr data
  4733. (cdr (mm-make-handle nil
  4734. `("message/external-body"
  4735. (access-type . "LOCAL-FILE")
  4736. (name . ,file)))))
  4737. ;; (set-buffer gnus-summary-buffer)
  4738. (gnus-article-edit-part handles id))))
  4739. ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
  4740. ;; parts...>') but with stripping would be nice.
  4741. (defun gnus-mime-delete-part ()
  4742. "Delete the MIME part under point.
  4743. Replace it with some information about the removed part."
  4744. (interactive)
  4745. (gnus-article-check-buffer)
  4746. (when (gnus-group-read-only-p)
  4747. (error "The current group does not support deleting of parts"))
  4748. (when (mm-complicated-handles gnus-article-mime-handles)
  4749. (error "\
  4750. The current article has a complicated MIME structure, giving up..."))
  4751. (when (or gnus-expert-user
  4752. (gnus-yes-or-no-p "\
  4753. Deleting parts may malfunction or destroy the article; continue? "))
  4754. (let* ((data (get-text-property (point) 'gnus-data))
  4755. (id (get-text-property (point) 'gnus-part))
  4756. (handles gnus-article-mime-handles)
  4757. (description
  4758. (let ((desc (mm-handle-description data)))
  4759. (when desc
  4760. (mail-decode-encoded-word-string desc))))
  4761. (filename (or (mm-handle-filename data) "(none)"))
  4762. (type (mm-handle-media-type data)))
  4763. (unless data
  4764. (error "No MIME part under point"))
  4765. (with-current-buffer (mm-handle-buffer data)
  4766. (let ((bsize (buffer-size)))
  4767. (erase-buffer)
  4768. (insert
  4769. (concat
  4770. ",----\n"
  4771. "| The following attachment has been deleted:\n"
  4772. "|\n"
  4773. "| Type: " type "\n"
  4774. "| Filename: " filename "\n"
  4775. "| Size (encoded): " (format "%s byte%s\n"
  4776. bsize (if (= bsize 1)
  4777. ""
  4778. "s"))
  4779. (when description
  4780. (concat "| Description: " description "\n"))
  4781. "`----\n"))
  4782. (setcdr data
  4783. (cdr (mm-make-handle
  4784. nil `("text/plain" (charset . gnus-decoded)) nil nil
  4785. (list "attachment")
  4786. (format "Deleted attachment (%s bytes)" bsize))))))
  4787. ;; (set-buffer gnus-summary-buffer)
  4788. (gnus-article-edit-part handles id))))
  4789. (defun gnus-mime-save-part ()
  4790. "Save the MIME part under point."
  4791. (interactive)
  4792. (gnus-article-check-buffer)
  4793. (let ((data (get-text-property (point) 'gnus-data)))
  4794. (when data
  4795. (mm-save-part data))))
  4796. (defun gnus-mime-pipe-part (&optional cmd)
  4797. "Pipe the MIME part under point to a process.
  4798. Use CMD as the process."
  4799. (interactive)
  4800. (gnus-article-check-buffer)
  4801. (let ((data (get-text-property (point) 'gnus-data)))
  4802. (when data
  4803. (mm-pipe-part data cmd))))
  4804. (defun gnus-mime-view-part ()
  4805. "Interactively choose a viewing method for the MIME part under point."
  4806. (interactive)
  4807. (gnus-article-check-buffer)
  4808. (let ((data (get-text-property (point) 'gnus-data)))
  4809. (when data
  4810. (setq gnus-article-mime-handles
  4811. (mm-merge-handles
  4812. gnus-article-mime-handles (setq data (copy-sequence data))))
  4813. (mm-interactively-view-part data))))
  4814. (defun gnus-mime-view-part-as-type-internal ()
  4815. (gnus-article-check-buffer)
  4816. (let* ((handle (get-text-property (point) 'gnus-data))
  4817. (name (or
  4818. ;; Content-Type: foo/bar; name=...
  4819. (mail-content-type-get (mm-handle-type handle) 'name)
  4820. ;; Content-Disposition: attachment; filename=...
  4821. (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
  4822. (def-type (and name (mm-default-file-encoding name))))
  4823. (or (and def-type (cons def-type 0))
  4824. (and handle
  4825. (equal (mm-handle-media-supertype handle) "text")
  4826. '("text/plain" . 0))
  4827. '("application/octet-stream" . 0))))
  4828. (defun gnus-mime-view-part-as-type (&optional mime-type pred)
  4829. "Choose a MIME media type, and view the part as such.
  4830. If non-nil, PRED is a predicate to use during completion to limit the
  4831. available media-types."
  4832. (interactive)
  4833. (unless mime-type
  4834. (setq mime-type
  4835. (let ((default (gnus-mime-view-part-as-type-internal)))
  4836. (gnus-completing-read
  4837. "View as MIME type"
  4838. (if pred
  4839. (gnus-remove-if-not pred (mailcap-mime-types))
  4840. (mailcap-mime-types))
  4841. nil nil nil
  4842. (car default)))))
  4843. (gnus-article-check-buffer)
  4844. (let ((handle (get-text-property (point) 'gnus-data)))
  4845. (when handle
  4846. (when (equal (mm-handle-media-type handle) "message/external-body")
  4847. (unless (mm-handle-cache handle)
  4848. (mm-extern-cache-contents handle))
  4849. (setq handle (mm-handle-cache handle)))
  4850. (setq handle
  4851. (mm-make-handle (mm-handle-buffer handle)
  4852. (cons mime-type (cdr (mm-handle-type handle)))
  4853. (mm-handle-encoding handle)
  4854. (mm-handle-undisplayer handle)
  4855. (mm-handle-disposition handle)
  4856. (mm-handle-description handle)
  4857. nil
  4858. (mm-handle-id handle)))
  4859. (setq gnus-article-mime-handles
  4860. (mm-merge-handles gnus-article-mime-handles handle))
  4861. (when (mm-handle-displayed-p handle)
  4862. (mm-remove-part handle))
  4863. (gnus-mm-display-part handle))))
  4864. (defun gnus-mime-copy-part (&optional handle arg)
  4865. "Put the MIME part under point into a new buffer.
  4866. If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
  4867. are decompressed."
  4868. (interactive (list nil current-prefix-arg))
  4869. (gnus-article-check-buffer)
  4870. (unless handle
  4871. (setq handle (get-text-property (point) 'gnus-data)))
  4872. (when handle
  4873. (let ((filename (mm-handle-filename handle))
  4874. contents dont-decode charset coding-system)
  4875. (mm-with-unibyte-buffer
  4876. (mm-insert-part handle)
  4877. (setq contents (or (condition-case nil
  4878. (mm-decompress-buffer filename nil 'sig)
  4879. (error
  4880. (setq dont-decode t)
  4881. nil))
  4882. (buffer-string))))
  4883. (setq filename (cond (filename (file-name-nondirectory filename))
  4884. (dont-decode "*raw data*")
  4885. (t "*decoded*")))
  4886. (cond
  4887. (dont-decode)
  4888. ((not arg)
  4889. (unless (setq charset (mail-content-type-get
  4890. (mm-handle-type handle) 'charset))
  4891. (unless (setq coding-system (mm-with-unibyte-buffer
  4892. (insert contents)
  4893. (mm-find-buffer-file-coding-system)))
  4894. (setq charset gnus-newsgroup-charset))))
  4895. ((numberp arg)
  4896. (setq charset (or (cdr (assq arg
  4897. gnus-summary-show-article-charset-alist))
  4898. (mm-read-coding-system "Charset: ")))))
  4899. (switch-to-buffer (generate-new-buffer filename))
  4900. (if (or coding-system
  4901. (and charset
  4902. (setq coding-system (mm-charset-to-coding-system
  4903. charset nil t))
  4904. (not (eq coding-system 'ascii))))
  4905. (progn
  4906. (mm-enable-multibyte)
  4907. (insert (mm-decode-coding-string contents coding-system))
  4908. (setq buffer-file-coding-system
  4909. (if (boundp 'last-coding-system-used)
  4910. (symbol-value 'last-coding-system-used)
  4911. coding-system)))
  4912. (mm-disable-multibyte)
  4913. (insert contents)
  4914. (setq buffer-file-coding-system mm-binary-coding-system))
  4915. ;; We do it this way to make `normal-mode' set the appropriate mode.
  4916. (unwind-protect
  4917. (progn
  4918. (setq buffer-file-name (expand-file-name filename))
  4919. (normal-mode))
  4920. (setq buffer-file-name nil))
  4921. (goto-char (point-min)))))
  4922. (defun gnus-mime-print-part (&optional handle filename)
  4923. "Print the MIME part under point."
  4924. (interactive (list nil (ps-print-preprint current-prefix-arg)))
  4925. (gnus-article-check-buffer)
  4926. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  4927. (contents (and handle (mm-get-part handle)))
  4928. (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
  4929. (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
  4930. (when contents
  4931. (if printer
  4932. (unwind-protect
  4933. (progn
  4934. (mm-save-part-to-file handle file)
  4935. (call-process shell-file-name nil
  4936. (generate-new-buffer " *mm*")
  4937. nil
  4938. shell-command-switch
  4939. (mm-mailcap-command
  4940. printer file (mm-handle-type handle))))
  4941. (delete-file file))
  4942. (with-temp-buffer
  4943. (insert contents)
  4944. (gnus-print-buffer))
  4945. (ps-despool filename)))))
  4946. (defun gnus-mime-inline-part (&optional handle arg)
  4947. "Insert the MIME part under point into the current buffer.
  4948. Compressed files like .gz and .bz2 are decompressed."
  4949. (interactive (list nil current-prefix-arg))
  4950. (gnus-article-check-buffer)
  4951. (let* ((inhibit-read-only t)
  4952. (b (point))
  4953. (btn ;; position where the MIME button exists
  4954. (if handle
  4955. (if (eq handle (get-text-property b 'gnus-data))
  4956. b
  4957. (article-goto-body)
  4958. (or (text-property-any (point) (point-max) 'gnus-data handle)
  4959. (text-property-any (point-min) (point) 'gnus-data handle)))
  4960. (setq handle (get-text-property b 'gnus-data))
  4961. b))
  4962. start)
  4963. (when handle
  4964. (when (= b (prog1
  4965. btn
  4966. (setq start (next-single-property-change btn 'gnus-data
  4967. nil (point-max))
  4968. btn (previous-single-property-change start
  4969. 'gnus-data))))
  4970. (setq b btn))
  4971. (if (and (not arg) (mm-handle-undisplayer handle))
  4972. (progn
  4973. (setq b (copy-marker b)
  4974. btn (copy-marker btn))
  4975. (mm-remove-part handle))
  4976. (cond
  4977. ((not arg) nil)
  4978. ((numberp arg)
  4979. (if (mm-handle-undisplayer handle)
  4980. (mm-remove-part handle)))
  4981. ((mm-handle-undisplayer handle)
  4982. (mm-remove-part handle)))
  4983. (goto-char start)
  4984. (unless (bolp)
  4985. ;; This is a header button.
  4986. (forward-line 1))
  4987. (mm-display-inline handle))
  4988. ;; Toggle the button appearance between `[button]...' and `[button]'.
  4989. (when (markerp btn)
  4990. (setq btn (prog1 (marker-position btn)
  4991. (set-marker btn nil))))
  4992. (goto-char btn)
  4993. (let ((displayed-p (mm-handle-displayed-p handle)))
  4994. (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
  4995. (list displayed-p))
  4996. (if (featurep 'emacs)
  4997. (delete-region
  4998. (point)
  4999. (next-single-property-change (point) 'gnus-data nil (point-max)))
  5000. (let* ((end (next-single-property-change (point) 'gnus-data))
  5001. (annots (annotations-at (or end (point-max)))))
  5002. (delete-region (point)
  5003. (if end
  5004. (if annots (1+ end) end)
  5005. (point-max)))
  5006. (dolist (annot annots)
  5007. (set-extent-endpoints annot (point) (point)))))
  5008. (setq start (point))
  5009. (if (search-backward "\n\n" nil t)
  5010. (progn
  5011. (goto-char start)
  5012. (unless (or displayed-p (eolp))
  5013. ;; Add extra newline.
  5014. (insert (propertize (buffer-substring (1- start) start)
  5015. 'gnus-undeletable t))))
  5016. ;; We're in the article header.
  5017. (delete-char -1)
  5018. (dolist (ovl (overlays-in btn (point)))
  5019. (overlay-put ovl 'gnus-button-attachment-extra t)
  5020. (overlay-put ovl 'face nil))
  5021. (save-restriction
  5022. (message-narrow-to-field)
  5023. (let ((gnus-treatment-function-alist
  5024. '((gnus-treat-highlight-headers
  5025. gnus-article-highlight-headers))))
  5026. (gnus-treat-article 'head)))))
  5027. (when (markerp b)
  5028. (setq b (prog1 (marker-position b)
  5029. (set-marker b nil))))
  5030. (goto-char b))))
  5031. (defun gnus-mime-set-charset-parameters (handle charset)
  5032. "Set CHARSET to parameters in HANDLE.
  5033. CHARSET may either be a string or a symbol."
  5034. (unless (stringp charset)
  5035. (setq charset (symbol-name charset)))
  5036. (if (stringp (car handle))
  5037. (dolist (h (cdr handle))
  5038. (gnus-mime-set-charset-parameters h charset))
  5039. (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
  5040. "message/external-body")
  5041. (progn
  5042. (unless (mm-handle-cache handle)
  5043. (mm-extern-cache-contents handle))
  5044. (mm-handle-cache handle))
  5045. handle)))
  5046. (param (assq 'charset (cdr type))))
  5047. (if param
  5048. (setcdr param charset)
  5049. (setcdr type (cons (cons 'charset charset) (cdr type)))))))
  5050. (defun gnus-mime-view-part-as-charset (&optional handle arg)
  5051. "Insert the MIME part under point into the current buffer using the
  5052. specified charset."
  5053. (interactive (list nil current-prefix-arg))
  5054. (gnus-article-check-buffer)
  5055. (let ((handle (or handle (get-text-property (point) 'gnus-data)))
  5056. (fun (get-text-property (point) 'gnus-callback))
  5057. (gnus-newsgroup-ignored-charsets 'gnus-all)
  5058. charset form preferred parts)
  5059. (when handle
  5060. (when (prog1
  5061. (and fun
  5062. (setq charset
  5063. (or (cdr (assq
  5064. arg
  5065. gnus-summary-show-article-charset-alist))
  5066. (mm-read-coding-system "Charset: "))))
  5067. (if (mm-handle-undisplayer handle)
  5068. (mm-remove-part handle)))
  5069. (gnus-mime-set-charset-parameters handle charset)
  5070. (when (and (consp (setq form (cdr-safe fun)))
  5071. (setq form (ignore-errors
  5072. (assq 'gnus-mime-display-alternative form)))
  5073. (setq preferred (caddr form))
  5074. (progn
  5075. (when (eq (car preferred) 'quote)
  5076. (setq preferred (cadr preferred)))
  5077. (not (equal preferred
  5078. (get-text-property (point) 'gnus-data))))
  5079. (setq parts (get-text-property (point) 'gnus-part))
  5080. (setq parts (cdr (assq parts
  5081. gnus-article-mime-handle-alist)))
  5082. (equal (mm-handle-media-type parts) "multipart/alternative")
  5083. (setq parts (reverse (cdr parts))))
  5084. (setcar (cddr form)
  5085. (list 'quote (or (cadr (member preferred parts))
  5086. (car parts)))))
  5087. (funcall fun handle)))))
  5088. (defun gnus-mime-view-part-externally (&optional handle)
  5089. "View the MIME part under point with an external viewer."
  5090. (interactive)
  5091. (gnus-article-check-buffer)
  5092. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  5093. (mm-inlined-types nil)
  5094. (mail-parse-charset gnus-newsgroup-charset)
  5095. (mail-parse-ignored-charsets
  5096. (with-current-buffer gnus-summary-buffer
  5097. gnus-newsgroup-ignored-charsets))
  5098. (type (mm-handle-media-type handle))
  5099. (method (mailcap-mime-info type))
  5100. (mm-enable-external t))
  5101. (if (not (stringp method))
  5102. (gnus-mime-view-part-as-type
  5103. nil (lambda (type) (stringp (mailcap-mime-info type))))
  5104. (when handle
  5105. (mm-display-part handle nil t)))))
  5106. (defun gnus-mime-view-part-internally (&optional handle)
  5107. "View the MIME part under point with an internal viewer.
  5108. If no internal viewer is available, use an external viewer."
  5109. (interactive)
  5110. (gnus-article-check-buffer)
  5111. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  5112. (mm-inlined-types '(".*"))
  5113. (mm-inline-large-images t)
  5114. (mail-parse-charset gnus-newsgroup-charset)
  5115. (mail-parse-ignored-charsets
  5116. (with-current-buffer gnus-summary-buffer
  5117. gnus-newsgroup-ignored-charsets))
  5118. (inhibit-read-only t))
  5119. (if (not (mm-inlinable-p handle))
  5120. (gnus-mime-view-part-as-type
  5121. nil (lambda (type) (mm-inlinable-p handle type)))
  5122. (when handle
  5123. (gnus-bind-mm-vars (mm-display-part handle nil t))))))
  5124. (defun gnus-mime-action-on-part (&optional action)
  5125. "Do something with the MIME attachment at (point)."
  5126. (interactive
  5127. (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
  5128. (gnus-article-check-buffer)
  5129. (let ((action-pair (assoc action gnus-mime-action-alist)))
  5130. (if action-pair
  5131. (funcall (cdr action-pair)))))
  5132. (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
  5133. "Call FUNCTION on MIME part N.
  5134. Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
  5135. If INTERACTIVE, call FUNCTION interactively."
  5136. (let (window frame)
  5137. ;; Check whether the article is displayed.
  5138. (unless (and (gnus-buffer-live-p gnus-article-buffer)
  5139. (setq window (get-buffer-window gnus-article-buffer t))
  5140. (frame-visible-p (setq frame (window-frame window))))
  5141. (error "No article is displayed"))
  5142. (with-current-buffer gnus-article-buffer
  5143. ;; Check whether the article displays the right contents.
  5144. (unless (with-current-buffer gnus-summary-buffer
  5145. (eq gnus-current-article (gnus-summary-article-number)))
  5146. (error "You should select the right article first"))
  5147. (if n
  5148. (setq n (prefix-numeric-value n))
  5149. (let ((pt (point)))
  5150. (setq n (or (get-text-property pt 'gnus-part)
  5151. (and (not (bobp))
  5152. (get-text-property (1- pt) 'gnus-part))
  5153. (get-text-property (prog2
  5154. (forward-line 1)
  5155. (point)
  5156. (goto-char pt))
  5157. 'gnus-part)
  5158. (get-text-property
  5159. (or (and (setq pt (previous-single-property-change
  5160. pt 'gnus-part))
  5161. (1- pt))
  5162. (next-single-property-change (point) 'gnus-part)
  5163. (point))
  5164. 'gnus-part)
  5165. 1))))
  5166. ;; Check whether the specified part exists.
  5167. (when (> n (length gnus-article-mime-handle-alist))
  5168. (error "No such part")))
  5169. (unless
  5170. (progn
  5171. ;; To select the window is needed so that the cursor
  5172. ;; might be visible on the MIME button.
  5173. (select-window (prog1
  5174. window
  5175. (setq window (selected-window))
  5176. ;; Article may be displayed in the other frame.
  5177. (gnus-select-frame-set-input-focus
  5178. (prog1
  5179. frame
  5180. (setq frame (selected-frame))))))
  5181. (when (gnus-article-goto-part n)
  5182. ;; We point the cursor and the arrow at the MIME button
  5183. ;; when the `function' prompt the user for something.
  5184. (unless (and (pos-visible-in-window-p)
  5185. (> (count-lines (point) (window-end))
  5186. (/ (1- (window-height)) 3)))
  5187. (recenter (/ (1- (window-height)) 3)))
  5188. (let ((cursor-in-non-selected-windows t)
  5189. (overlay-arrow-string "=>")
  5190. (overlay-arrow-position (point-marker)))
  5191. (unwind-protect
  5192. (cond
  5193. ((and no-handle interactive)
  5194. (call-interactively function))
  5195. (no-handle
  5196. (funcall function))
  5197. (interactive
  5198. (call-interactively
  5199. function (get-text-property (point) 'gnus-data)))
  5200. (t
  5201. (funcall function
  5202. (get-text-property (point) 'gnus-data))))
  5203. (set-marker overlay-arrow-position nil)
  5204. (unless gnus-auto-select-part
  5205. (gnus-select-frame-set-input-focus frame)
  5206. (select-window window))))
  5207. t))
  5208. (if gnus-inhibit-mime-unbuttonizing
  5209. ;; This is the default though the program shouldn't reach here.
  5210. (error "No such part")
  5211. ;; The part which doesn't have the MIME button is selected.
  5212. ;; So, we display all the buttons and redo it.
  5213. (let ((gnus-inhibit-mime-unbuttonizing t))
  5214. (gnus-summary-show-article)
  5215. (gnus-article-part-wrapper n function no-handle))))))
  5216. (defun gnus-article-pipe-part (n)
  5217. "Pipe MIME part N, which is the numerical prefix."
  5218. (interactive "P")
  5219. (gnus-article-part-wrapper n 'mm-pipe-part))
  5220. (defun gnus-article-save-part (n)
  5221. "Save MIME part N, which is the numerical prefix."
  5222. (interactive "P")
  5223. (gnus-article-part-wrapper n 'mm-save-part))
  5224. (defun gnus-article-interactively-view-part (n)
  5225. "View MIME part N interactively, which is the numerical prefix."
  5226. (interactive "P")
  5227. (gnus-article-part-wrapper n 'mm-interactively-view-part))
  5228. (defun gnus-article-copy-part (n)
  5229. "Copy MIME part N, which is the numerical prefix."
  5230. (interactive "P")
  5231. (gnus-article-part-wrapper n 'gnus-mime-copy-part))
  5232. (defun gnus-article-view-part-as-charset (n)
  5233. "View MIME part N using a specified charset.
  5234. N is the numerical prefix."
  5235. (interactive "P")
  5236. (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
  5237. (defun gnus-article-view-part-externally (n)
  5238. "View MIME part N externally, which is the numerical prefix."
  5239. (interactive "P")
  5240. (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
  5241. (defun gnus-article-inline-part (n)
  5242. "Inline MIME part N, which is the numerical prefix."
  5243. (interactive "P")
  5244. (gnus-article-part-wrapper n 'gnus-mime-inline-part))
  5245. (defun gnus-article-save-part-and-strip (n)
  5246. "Save MIME part N and replace it with an external body.
  5247. N is the numerical prefix."
  5248. (interactive "P")
  5249. (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
  5250. (defun gnus-article-replace-part (n)
  5251. "Replace MIME part N with an external body.
  5252. N is the numerical prefix."
  5253. (interactive "P")
  5254. (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
  5255. (defun gnus-article-delete-part (n)
  5256. "Delete MIME part N and add some information about the removed part.
  5257. N is the numerical prefix."
  5258. (interactive "P")
  5259. (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
  5260. (defun gnus-article-view-part-as-type (n)
  5261. "Choose a MIME media type, and view part N as such.
  5262. N is the numerical prefix."
  5263. (interactive "P")
  5264. (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
  5265. (defun gnus-article-mime-match-handle-first (condition)
  5266. (if condition
  5267. (let (n)
  5268. (dolist (ihandle gnus-article-mime-handle-alist)
  5269. (if (and (cond
  5270. ((functionp condition)
  5271. (funcall condition (cdr ihandle)))
  5272. ((eq condition 'undisplayed)
  5273. (not (or (mm-handle-undisplayer (cdr ihandle))
  5274. (equal (mm-handle-media-type (cdr ihandle))
  5275. "multipart/alternative"))))
  5276. ((eq condition 'undisplayed-alternative)
  5277. (not (mm-handle-undisplayer (cdr ihandle))))
  5278. (t t))
  5279. (gnus-article-goto-part (car ihandle))
  5280. (or (not n) (< (car ihandle) n)))
  5281. (setq n (car ihandle))))
  5282. (or n 1))
  5283. 1))
  5284. (defun gnus-article-view-part (&optional n)
  5285. "View MIME part N, which is the numerical prefix.
  5286. If the part is already shown, hide the part. If N is nil, view
  5287. all parts."
  5288. (interactive "P")
  5289. (with-current-buffer gnus-article-buffer
  5290. (or (numberp n) (setq n (gnus-article-mime-match-handle-first
  5291. gnus-article-mime-match-handle-function)))
  5292. (when (> n (length gnus-article-mime-handle-alist))
  5293. (error "No such part"))
  5294. (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
  5295. (when (gnus-article-goto-part n)
  5296. (if (equal (car handle) "multipart/alternative")
  5297. (progn
  5298. (beginning-of-line) ;; Make it toggle subparts
  5299. (gnus-article-press-button))
  5300. (when (eq (gnus-mm-display-part handle) 'internal)
  5301. (gnus-set-window-start)))))))
  5302. (defsubst gnus-article-mime-total-parts ()
  5303. (if (bufferp (car gnus-article-mime-handles))
  5304. 1 ;; single part
  5305. (1- (length gnus-article-mime-handles))))
  5306. (defun gnus-mm-display-part (handle)
  5307. "Display HANDLE and fix MIME button."
  5308. (let ((id (get-text-property (point) 'gnus-part))
  5309. (point (point))
  5310. (inhibit-read-only t)
  5311. (window (selected-window))
  5312. (mail-parse-charset gnus-newsgroup-charset)
  5313. (mail-parse-ignored-charsets
  5314. (if (gnus-buffer-live-p gnus-summary-buffer)
  5315. (with-current-buffer gnus-summary-buffer
  5316. gnus-newsgroup-ignored-charsets)
  5317. nil))
  5318. start retval)
  5319. (unwind-protect
  5320. (progn
  5321. (let ((win (gnus-get-buffer-window (current-buffer) t)))
  5322. (when win
  5323. (select-window win)
  5324. (goto-char point)))
  5325. (setq start (next-single-property-change point 'gnus-data
  5326. nil (point-max))
  5327. point (previous-single-property-change start 'gnus-data))
  5328. (if (mm-handle-displayed-p handle)
  5329. ;; This will remove the part.
  5330. (setq point (copy-marker point)
  5331. retval (mm-display-part handle))
  5332. (let ((part (or (and (mm-inlinable-p handle)
  5333. (mm-inlined-p handle)
  5334. t)
  5335. (with-temp-buffer
  5336. (gnus-bind-mm-vars
  5337. (setq retval (mm-display-part handle)))
  5338. (unless (zerop (buffer-size))
  5339. (buffer-string))))))
  5340. (goto-char start)
  5341. (unless (bolp)
  5342. ;; This is a header button.
  5343. (forward-line 1))
  5344. (cond ((stringp part)
  5345. (save-restriction
  5346. (narrow-to-region (point)
  5347. (progn
  5348. (insert part)
  5349. (unless (bolp) (insert "\n"))
  5350. (point)))
  5351. (gnus-treat-article nil id
  5352. (gnus-article-mime-total-parts)
  5353. (mm-handle-media-type handle))
  5354. (mm-handle-set-undisplayer
  5355. handle
  5356. `(lambda ()
  5357. (let ((inhibit-read-only t))
  5358. (delete-region ,(copy-marker (point-min) t)
  5359. ,(point-max-marker)))))))
  5360. (part
  5361. (mm-display-inline handle))))))
  5362. (when (markerp point)
  5363. (setq point (prog1 (marker-position point)
  5364. (set-marker point nil))))
  5365. (goto-char point)
  5366. ;; Toggle the button appearance between `[button]...' and `[button]'.
  5367. (let ((displayed-p (mm-handle-displayed-p handle)))
  5368. (gnus-insert-mime-button handle id (list displayed-p))
  5369. (if (featurep 'emacs)
  5370. (delete-region
  5371. (point)
  5372. (next-single-property-change (point) 'gnus-data nil (point-max)))
  5373. (let* ((end (next-single-property-change (point) 'gnus-data))
  5374. (annots (annotations-at (or end (point-max)))))
  5375. (delete-region (point)
  5376. (if end
  5377. (if annots (1+ end) end)
  5378. (point-max)))
  5379. (dolist (annot annots)
  5380. (set-extent-endpoints annot (point) (point)))))
  5381. (setq start (point))
  5382. (if (search-backward "\n\n" nil t)
  5383. (progn
  5384. (goto-char start)
  5385. (unless (or displayed-p (eolp))
  5386. ;; Add extra newline.
  5387. (insert (propertize (buffer-substring (1- start) start)
  5388. 'gnus-undeletable t))))
  5389. ;; We're in the article header.
  5390. (delete-char -1)
  5391. (dolist (ovl (overlays-in point (point)))
  5392. (overlay-put ovl 'gnus-button-attachment-extra t)
  5393. (overlay-put ovl 'face nil))
  5394. (save-restriction
  5395. (message-narrow-to-field)
  5396. (let ((gnus-treatment-function-alist
  5397. '((gnus-treat-highlight-headers
  5398. gnus-article-highlight-headers))))
  5399. (gnus-treat-article 'head)))))
  5400. (goto-char point)
  5401. (if (window-live-p window)
  5402. (select-window window)))
  5403. retval))
  5404. (defun gnus-article-goto-part (n)
  5405. "Go to MIME part N."
  5406. (when gnus-break-pages
  5407. (widen))
  5408. (article-goto-body)
  5409. (prog1
  5410. (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
  5411. ;; There may be header buttons.
  5412. (text-property-any (point-min) (point) 'gnus-part n)))
  5413. part handle end next handles)
  5414. (when start
  5415. (goto-char start)
  5416. (if (setq handle (get-text-property start 'gnus-data))
  5417. start
  5418. ;; Go to the displayed subpart, assuming this is
  5419. ;; multipart/alternative.
  5420. (setq part start
  5421. end (point-at-eol))
  5422. (while (and (not handle)
  5423. part
  5424. (< part end)
  5425. (setq next (text-property-not-all part end
  5426. 'gnus-data nil)))
  5427. (setq part next
  5428. handle (get-text-property part 'gnus-data))
  5429. (push (cons handle part) handles)
  5430. (unless (mm-handle-displayed-p handle)
  5431. (setq handle nil
  5432. part (text-property-any part end 'gnus-data nil))))
  5433. (unless handle
  5434. ;; No subpart is displayed, so we find preferred one.
  5435. (setq part
  5436. (cdr (assq (mm-preferred-alternative
  5437. (nreverse (mapcar 'car handles)))
  5438. handles))))
  5439. (if part
  5440. (goto-char (1+ part))
  5441. start))))
  5442. (when gnus-break-pages
  5443. (gnus-narrow-to-page))))
  5444. (defun gnus-insert-mime-button (handle id &optional displayed)
  5445. (let ((gnus-tmp-name
  5446. (or (mm-handle-filename handle)
  5447. (mail-content-type-get (mm-handle-type handle) 'url)
  5448. ""))
  5449. (gnus-tmp-id id)
  5450. (gnus-tmp-type (mm-handle-media-type handle))
  5451. (gnus-tmp-description (or (mm-handle-description handle) ""))
  5452. (gnus-tmp-dots
  5453. (if (if displayed (car displayed)
  5454. (mm-handle-displayed-p handle))
  5455. "" "..."))
  5456. (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
  5457. (buffer-size)))
  5458. gnus-tmp-type-long b e)
  5459. (when (string-match ".*/" gnus-tmp-name)
  5460. (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
  5461. (setq gnus-tmp-type-long (concat gnus-tmp-type
  5462. (and (not (equal gnus-tmp-name ""))
  5463. (concat "; " gnus-tmp-name))))
  5464. (unless (equal gnus-tmp-description "")
  5465. (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
  5466. (setq b (point))
  5467. (gnus-eval-format
  5468. gnus-mime-button-line-format gnus-mime-button-line-format-alist
  5469. `(keymap ,gnus-mime-button-map
  5470. gnus-callback gnus-mm-display-part
  5471. gnus-part ,gnus-tmp-id
  5472. article-type annotation
  5473. gnus-data ,handle
  5474. rear-nonsticky t))
  5475. (setq e (if (bolp)
  5476. ;; Exclude a newline.
  5477. (1- (point))
  5478. (point)))
  5479. (when gnus-article-button-face
  5480. (overlay-put (make-overlay b e nil t)
  5481. 'face gnus-article-button-face))
  5482. (widget-convert-button
  5483. 'link b e
  5484. :mime-handle handle
  5485. :action 'gnus-widget-press-button
  5486. :button-keymap gnus-mime-button-map
  5487. :help-echo
  5488. (lambda (widget)
  5489. ;; Needed to properly clear the message due to a bug in
  5490. ;; wid-edit (XEmacs only).
  5491. (if (boundp 'help-echo-owns-message)
  5492. (setq help-echo-owns-message t))
  5493. (format
  5494. "%S: %s the MIME part; %S: more options"
  5495. (aref gnus-mouse-2 0)
  5496. (if (mm-handle-displayed-p (widget-get widget :mime-handle))
  5497. "hide" "show")
  5498. (aref gnus-down-mouse-3 0))))))
  5499. (defun gnus-widget-press-button (elems _el)
  5500. (goto-char (widget-get elems :from))
  5501. (gnus-article-press-button))
  5502. (defvar gnus-displaying-mime nil)
  5503. (defun gnus-display-mime (&optional ihandles)
  5504. "Display the MIME parts."
  5505. (save-excursion
  5506. (save-selected-window
  5507. (let ((window (get-buffer-window gnus-article-buffer))
  5508. (point (point)))
  5509. (when window
  5510. (select-window window)
  5511. ;; We have to do this since selecting the window
  5512. ;; may change the point. So we set the window point.
  5513. (set-window-point window point)))
  5514. (let ((handles ihandles)
  5515. (inhibit-read-only t))
  5516. (cond (handles)
  5517. ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
  5518. (when gnus-article-emulate-mime
  5519. (mm-uu-dissect-text-parts handles)))
  5520. (gnus-article-emulate-mime
  5521. (setq handles (mm-uu-dissect))))
  5522. (when (and (not ihandles)
  5523. (not gnus-displaying-mime))
  5524. ;; Top-level call; we clean up.
  5525. (when gnus-article-mime-handles
  5526. (mm-destroy-parts gnus-article-mime-handles)
  5527. (setq gnus-article-mime-handle-alist nil));; A trick.
  5528. (setq gnus-article-mime-handles handles)
  5529. ;; We allow users to glean info from the handles.
  5530. (when gnus-article-mime-part-function
  5531. (gnus-mime-part-function handles)))
  5532. (if (and handles
  5533. (or (not (stringp (car handles)))
  5534. (cdr handles)))
  5535. (progn
  5536. (when (and (not ihandles)
  5537. (not gnus-displaying-mime))
  5538. ;; Clean up for mime parts.
  5539. (article-goto-body)
  5540. (delete-region (point) (point-max)))
  5541. (let ((gnus-displaying-mime t))
  5542. (gnus-mime-display-part handles)))
  5543. (save-restriction
  5544. (article-goto-body)
  5545. (narrow-to-region (point) (point-max))
  5546. (gnus-treat-article nil 1 1 "text/plain")
  5547. (widen)))
  5548. (unless ihandles
  5549. ;; Highlight the headers.
  5550. (save-excursion
  5551. (save-restriction
  5552. (article-goto-body)
  5553. (narrow-to-region (point-min) (point))
  5554. (gnus-article-save-original-date
  5555. (gnus-treat-article 'head)))))))
  5556. ;; Cope with broken MIME messages.
  5557. (goto-char (point-max))
  5558. (unless (bolp)
  5559. (insert "\n"))))
  5560. (defcustom gnus-mime-display-multipart-as-mixed nil
  5561. "Display \"multipart\" parts as \"multipart/mixed\".
  5562. If t, it overrides nil values of
  5563. `gnus-mime-display-multipart-alternative-as-mixed' and
  5564. `gnus-mime-display-multipart-related-as-mixed'."
  5565. :group 'gnus-article-mime
  5566. :type 'boolean)
  5567. (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
  5568. "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
  5569. :version "22.1"
  5570. :group 'gnus-article-mime
  5571. :type 'boolean)
  5572. (defcustom gnus-mime-display-multipart-related-as-mixed nil
  5573. "Display \"multipart/related\" parts as \"multipart/mixed\".
  5574. If displaying \"text/html\" is discouraged \(see
  5575. `mm-discouraged-alternatives') images or other material inside a
  5576. \"multipart/related\" part might be overlooked when this variable is nil."
  5577. :version "22.1"
  5578. :group 'gnus-article-mime
  5579. :type 'boolean)
  5580. (defcustom gnus-mime-display-attachment-buttons-in-header t
  5581. "Add attachment buttons in the end of the header of an article.
  5582. Since MIME attachments tend to be put at the end of an article, we may
  5583. overlook them if there is a huge body. This option offers you a copy
  5584. of all non-inlinable MIME parts as buttons shown in front of an article.
  5585. If nil, don't show those extra buttons."
  5586. :version "25.1"
  5587. :group 'gnus-article-mime
  5588. :type 'boolean)
  5589. (defun gnus-mime-display-part (handle)
  5590. (cond
  5591. ;; Maybe a broken MIME message.
  5592. ((null handle))
  5593. ;; Single part.
  5594. ((not (stringp (car handle)))
  5595. (gnus-mime-display-single handle))
  5596. ;; User-defined multipart
  5597. ((cdr (assoc (car handle) gnus-mime-multipart-functions))
  5598. (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
  5599. handle))
  5600. ;; multipart/alternative
  5601. ((and (equal (car handle) "multipart/alternative")
  5602. (not (or gnus-mime-display-multipart-as-mixed
  5603. gnus-mime-display-multipart-alternative-as-mixed)))
  5604. (let ((id (1+ (length gnus-article-mime-handle-alist))))
  5605. (push (cons id handle) gnus-article-mime-handle-alist)
  5606. (gnus-mime-display-alternative (cdr handle) nil nil id)))
  5607. ;; multipart/related
  5608. ((and (equal (car handle) "multipart/related")
  5609. (not (or gnus-mime-display-multipart-as-mixed
  5610. gnus-mime-display-multipart-related-as-mixed)))
  5611. (gnus-mime-display-part (cadr handle)))
  5612. ((equal (car handle) "multipart/signed")
  5613. (gnus-add-wash-type 'signed)
  5614. (gnus-mime-display-security handle))
  5615. ((equal (car handle) "multipart/encrypted")
  5616. (gnus-add-wash-type 'encrypted)
  5617. (gnus-mime-display-security handle))
  5618. ;; Other multiparts are handled like multipart/mixed.
  5619. (t
  5620. (gnus-mime-display-mixed (cdr handle)))))
  5621. (defun gnus-mime-part-function (handles)
  5622. (if (stringp (car handles))
  5623. (mapcar 'gnus-mime-part-function (cdr handles))
  5624. (funcall gnus-article-mime-part-function handles)))
  5625. (defun gnus-mime-display-mixed (handles)
  5626. (mapcar 'gnus-mime-display-part handles))
  5627. (defun gnus-mime-display-single (handle)
  5628. (let ((type (mm-handle-media-type handle))
  5629. (ignored gnus-ignored-mime-types)
  5630. (not-attachment t)
  5631. display text)
  5632. (catch 'ignored
  5633. (progn
  5634. (while ignored
  5635. (when (string-match (pop ignored) type)
  5636. (throw 'ignored nil)))
  5637. (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
  5638. (with-current-buffer gnus-summary-buffer
  5639. gnus-inhibit-images)
  5640. gnus-inhibit-images)
  5641. (string-match "\\`image/" type)))
  5642. (setq not-attachment
  5643. (and (not (mm-inline-override-p handle))
  5644. (or (not (mm-handle-disposition handle))
  5645. (equal (car (mm-handle-disposition handle))
  5646. "inline")
  5647. (mm-attachment-override-p handle))))
  5648. (mm-automatic-display-p handle)
  5649. (or (and
  5650. (mm-inlinable-p handle)
  5651. (mm-inlined-p handle))
  5652. (mm-automatic-external-display-p type)))
  5653. (setq display t)
  5654. (when (equal (mm-handle-media-supertype handle) "text")
  5655. (setq text t)))
  5656. (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
  5657. beg)
  5658. (unless id
  5659. (setq id (1+ (length gnus-article-mime-handle-alist)))
  5660. (push (cons id handle) gnus-article-mime-handle-alist))
  5661. (when (and display
  5662. (equal (mm-handle-media-supertype handle) "message"))
  5663. (insert-char
  5664. ?\n
  5665. (cond ((not (bolp)) 2)
  5666. ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
  5667. (t 1))))
  5668. (when (or (not display)
  5669. (not (gnus-unbuttonized-mime-type-p type))
  5670. (eq id gnus-mime-buttonized-part-id))
  5671. (gnus-insert-mime-button
  5672. handle id (list (or display (and not-attachment text)))))
  5673. (setq beg (point))
  5674. (cond
  5675. (display
  5676. (let ((mail-parse-charset gnus-newsgroup-charset)
  5677. (mail-parse-ignored-charsets
  5678. (save-excursion (condition-case ()
  5679. (set-buffer gnus-summary-buffer)
  5680. (error))
  5681. gnus-newsgroup-ignored-charsets)))
  5682. (gnus-bind-mm-vars (mm-display-part handle t))))
  5683. ((and text not-attachment)
  5684. (mm-display-inline handle)))
  5685. (goto-char (point-max))
  5686. (if (string-match "\\`image/" type)
  5687. (gnus-article-insert-newline)
  5688. (if (prog1
  5689. (= (skip-chars-backward "\n") -1)
  5690. (unless (eobp) (forward-char 1)))
  5691. (gnus-article-insert-newline)
  5692. (put-text-property (point) (point-max) 'gnus-undeletable t))
  5693. (goto-char (point-max)))
  5694. ;; Do highlighting.
  5695. (save-excursion
  5696. (save-restriction
  5697. (narrow-to-region beg (point))
  5698. (if (eq handle gnus-article-mime-handles)
  5699. ;; The format=flowed case.
  5700. (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
  5701. ;; Don't count signature parts that are never displayed.
  5702. ;; The part number should be re-calculated supposing this
  5703. ;; might be a message/rfc822 part.
  5704. (let (handles)
  5705. (dolist (part gnus-article-mime-handles)
  5706. (unless (or (stringp part)
  5707. (equal (car (mm-handle-type part))
  5708. "application/pgp-signature"))
  5709. (push part handles)))
  5710. (gnus-treat-article
  5711. nil (length (memq handle handles)) (length handles)
  5712. (mm-handle-media-type handle)))))))))))
  5713. (defun gnus-unbuttonized-mime-type-p (type)
  5714. "Say whether TYPE is to be unbuttonized."
  5715. (unless gnus-inhibit-mime-unbuttonizing
  5716. (when (catch 'found
  5717. (let ((types gnus-unbuttonized-mime-types))
  5718. (while types
  5719. (when (string-match (pop types) type)
  5720. (throw 'found t)))))
  5721. (not (catch 'found
  5722. (let ((types gnus-buttonized-mime-types))
  5723. (while types
  5724. (when (string-match (pop types) type)
  5725. (throw 'found t)))))))))
  5726. (defun gnus-article-insert-newline ()
  5727. "Insert a newline, but mark it as undeletable."
  5728. (gnus-put-text-property
  5729. (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
  5730. (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
  5731. (let* ((preferred (or preferred (mm-preferred-alternative handles)))
  5732. (ihandles handles)
  5733. (point (point))
  5734. handle (inhibit-read-only t) from begend not-pref)
  5735. (save-window-excursion
  5736. (save-restriction
  5737. (when ibegend
  5738. (narrow-to-region (car ibegend)
  5739. (or (cdr ibegend)
  5740. (progn
  5741. (goto-char (car ibegend))
  5742. (forward-line 2)
  5743. (point))))
  5744. (delete-region (point-min) (point-max))
  5745. (mm-remove-parts handles))
  5746. (setq begend (list (point-marker)))
  5747. ;; Do the toggle.
  5748. (unless (setq not-pref (cadr (member preferred ihandles)))
  5749. (setq not-pref (car ihandles)))
  5750. (when (or ibegend
  5751. (not preferred)
  5752. (not (gnus-unbuttonized-mime-type-p
  5753. "multipart/alternative")))
  5754. (gnus-add-text-properties
  5755. (setq from (point))
  5756. (progn
  5757. (insert (format "%d. " id))
  5758. (point))
  5759. `(gnus-callback
  5760. (lambda (handles)
  5761. (unless ,(not ibegend)
  5762. (setq gnus-article-mime-handle-alist
  5763. ',gnus-article-mime-handle-alist))
  5764. (gnus-mime-display-alternative
  5765. ',ihandles ',not-pref ',begend ,id))
  5766. keymap ,gnus-mime-button-map
  5767. ,gnus-mouse-face-prop ,gnus-article-mouse-face
  5768. face ,gnus-article-button-face
  5769. gnus-part ,id
  5770. article-type multipart
  5771. rear-nonsticky t))
  5772. (widget-convert-button 'link from (point)
  5773. :action 'gnus-widget-press-button
  5774. :button-keymap gnus-widget-button-keymap)
  5775. ;; Do the handles
  5776. (while (setq handle (pop handles))
  5777. (gnus-add-text-properties
  5778. (setq from (point))
  5779. (progn
  5780. (insert (format "(%c) %-18s"
  5781. (if (equal handle preferred) ?* ? )
  5782. (mm-handle-media-type handle)))
  5783. (point))
  5784. `(gnus-callback
  5785. (lambda (handles)
  5786. (unless ,(not ibegend)
  5787. (setq gnus-article-mime-handle-alist
  5788. ',gnus-article-mime-handle-alist))
  5789. (gnus-mime-display-alternative
  5790. ',ihandles ',handle ',begend ,id))
  5791. keymap ,gnus-mime-button-map
  5792. ,gnus-mouse-face-prop ,gnus-article-mouse-face
  5793. face ,gnus-article-button-face
  5794. gnus-part ,id
  5795. gnus-data ,handle
  5796. rear-nonsticky t))
  5797. (widget-convert-button 'link from (point)
  5798. :action 'gnus-widget-press-button
  5799. :button-keymap gnus-widget-button-keymap)
  5800. (insert " "))
  5801. (insert "\n\n"))
  5802. (when preferred
  5803. (if (stringp (car preferred))
  5804. (gnus-display-mime preferred)
  5805. (let ((mail-parse-charset gnus-newsgroup-charset)
  5806. (mail-parse-ignored-charsets
  5807. (with-current-buffer gnus-summary-buffer
  5808. gnus-newsgroup-ignored-charsets)))
  5809. (gnus-bind-mm-vars (mm-display-part preferred))
  5810. ;; Do highlighting.
  5811. (save-excursion
  5812. (save-restriction
  5813. (narrow-to-region (car begend) (point-max))
  5814. (gnus-treat-article
  5815. nil (length gnus-article-mime-handle-alist)
  5816. (gnus-article-mime-total-parts)
  5817. (mm-handle-media-type preferred))))))
  5818. (goto-char (point-max))
  5819. (setcdr begend (point-marker)))))
  5820. (when ibegend
  5821. (goto-char point)))
  5822. ;; Redraw attachment buttons in the header.
  5823. (when gnus-mime-display-attachment-buttons-in-header
  5824. (gnus-mime-buttonize-attachments-in-header)))
  5825. (defconst gnus-article-wash-status-strings
  5826. (let ((alist '((cite "c" "Possible hidden citation text"
  5827. " " "All citation text visible")
  5828. (headers "h" "Hidden headers"
  5829. " " "All headers visible.")
  5830. (pgp "p" "Encrypted or signed message status hidden"
  5831. " " "No hidden encryption nor digital signature status")
  5832. (signature "s" "Signature has been hidden"
  5833. " " "Signature is visible")
  5834. (overstrike "o" "Overstrike (^H) characters applied"
  5835. " " "No overstrike characters applied")
  5836. (emphasis "e" "/*_Emphasis_*/ characters applied"
  5837. " " "No /*_emphasis_*/ characters applied")))
  5838. result)
  5839. (dolist (entry alist result)
  5840. (let ((key (nth 0 entry))
  5841. (on (copy-sequence (nth 1 entry)))
  5842. (on-help (nth 2 entry))
  5843. (off (copy-sequence (nth 3 entry)))
  5844. (off-help (nth 4 entry)))
  5845. (put-text-property 0 1 'help-echo on-help on)
  5846. (put-text-property 0 1 'help-echo off-help off)
  5847. (push (list key on off) result))))
  5848. "Alist of strings describing wash status in the mode line.
  5849. Each entry has the form (KEY ON OF), where the KEY is a symbol
  5850. representing the particular washing function, ON is the string to use
  5851. in the article mode line when the washing function is active, and OFF
  5852. is the string to use when it is inactive.")
  5853. (defun gnus-article-wash-status-entry (key value)
  5854. (let ((entry (assoc key gnus-article-wash-status-strings)))
  5855. (if value (nth 1 entry) (nth 2 entry))))
  5856. (defun gnus-article-wash-status ()
  5857. "Return a string which display status of article washing."
  5858. (with-current-buffer gnus-article-buffer
  5859. (let ((cite (memq 'cite gnus-article-wash-types))
  5860. (headers (memq 'headers gnus-article-wash-types))
  5861. (boring (memq 'boring-headers gnus-article-wash-types))
  5862. (pgp (memq 'pgp gnus-article-wash-types))
  5863. (pem (memq 'pem gnus-article-wash-types))
  5864. (signed (memq 'signed gnus-article-wash-types))
  5865. (encrypted (memq 'encrypted gnus-article-wash-types))
  5866. (signature (memq 'signature gnus-article-wash-types))
  5867. (overstrike (memq 'overstrike gnus-article-wash-types))
  5868. (emphasis (memq 'emphasis gnus-article-wash-types)))
  5869. (concat
  5870. (gnus-article-wash-status-entry 'cite cite)
  5871. (gnus-article-wash-status-entry 'headers (or headers boring))
  5872. (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
  5873. (gnus-article-wash-status-entry 'signature signature)
  5874. (gnus-article-wash-status-entry 'overstrike overstrike)
  5875. (gnus-article-wash-status-entry 'emphasis emphasis)))))
  5876. (defun gnus-add-wash-type (type)
  5877. "Add a washing of TYPE to the current status."
  5878. (add-to-list 'gnus-article-wash-types type))
  5879. (defun gnus-delete-wash-type (type)
  5880. "Add a washing of TYPE to the current status."
  5881. (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
  5882. (defun gnus-add-image (category image)
  5883. "Add IMAGE of CATEGORY to the list of displayed images."
  5884. (let ((entry (assq category gnus-article-image-alist)))
  5885. (unless entry
  5886. (setq entry (list category))
  5887. (push entry gnus-article-image-alist))
  5888. (nconc entry (list image))))
  5889. (defun gnus-delete-images (category)
  5890. "Delete all images in CATEGORY."
  5891. (let ((entry (assq category gnus-article-image-alist)))
  5892. (dolist (image (cdr entry))
  5893. (gnus-remove-image image category))
  5894. (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
  5895. (gnus-delete-wash-type category)))
  5896. (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
  5897. (defun gnus-article-maybe-hide-headers ()
  5898. "Hide unwanted headers if `gnus-have-all-headers' is nil.
  5899. Provided for backwards compatibility."
  5900. (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
  5901. (not (with-current-buffer gnus-summary-buffer
  5902. gnus-have-all-headers)))
  5903. (not gnus-inhibit-hiding))
  5904. (gnus-article-hide-headers)))
  5905. (declare-function shr-put-image "shr" (data alt &optional flags))
  5906. (defun gnus-shr-put-image (data alt &optional flags)
  5907. "Put image DATA with a string ALT. Enable image to be deleted."
  5908. (let ((image (if flags
  5909. (shr-put-image data (propertize (or alt "*")
  5910. 'gnus-image-category 'shr)
  5911. flags)
  5912. ;; Old `shr-put-image' doesn't take the optional `flags'
  5913. ;; argument.
  5914. (shr-put-image data (propertize (or alt "*")
  5915. 'gnus-image-category 'shr)))))
  5916. (when image
  5917. (gnus-add-image 'shr image))))
  5918. (defun gnus-article-mime-handles (&optional alist id all)
  5919. (if alist
  5920. (let ((i 1) newid flat)
  5921. (dolist (handle alist flat)
  5922. (setq newid (append id (list i))
  5923. i (1+ i))
  5924. (if (stringp (car handle))
  5925. (setq flat (nconc flat (gnus-article-mime-handles
  5926. (cdr handle) newid all)))
  5927. (delq (rassq handle all) all)
  5928. (setq flat (nconc flat (list (cons newid handle)))))))
  5929. (let ((flat (list nil)))
  5930. ;; Assume that elements of `gnus-article-mime-handle-alist'
  5931. ;; are in the decreasing order, but unnumbered subsidiaries
  5932. ;; in each element are in the increasing order.
  5933. (dolist (handle (reverse gnus-article-mime-handle-alist))
  5934. (if (stringp (cadr handle))
  5935. (setq flat (nconc flat (gnus-article-mime-handles
  5936. (cddr handle) (list (car handle)) flat)))
  5937. (delq (rassq (cdr handle) flat) flat)
  5938. (setq flat (nconc flat (list (cons (list (car handle))
  5939. (cdr handle)))))))
  5940. (setq flat (cdr flat))
  5941. (mapc (lambda (handle)
  5942. (if (cdar handle)
  5943. ;; This is a hidden (i.e. unnumbered) handle.
  5944. (progn
  5945. (setcar handle
  5946. (1+ (caar gnus-article-mime-handle-alist)))
  5947. (push handle gnus-article-mime-handle-alist))
  5948. (setcar handle (caar handle))))
  5949. flat)
  5950. flat)))
  5951. (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
  5952. "Show attachments as buttons in the end of the header of an article.
  5953. This function toggles the display when called interactively. Note that
  5954. buttons to be added to the header are only the ones that aren't inlined
  5955. in the body. Use `gnus-header-face-alist' to highlight buttons."
  5956. (interactive (list t))
  5957. (gnus-with-article-buffer
  5958. (let ((case-fold-search t) buttons handle type st)
  5959. (save-excursion
  5960. (save-restriction
  5961. (widen)
  5962. (article-narrow-to-head)
  5963. ;; Header buttons exist?
  5964. (while (and (not buttons)
  5965. (re-search-forward "^attachments?:[\n ]+" nil t))
  5966. (when (get-char-property (match-end 0)
  5967. 'gnus-button-attachment-extra)
  5968. (setq buttons (match-beginning 0))))
  5969. (widen)
  5970. (when buttons
  5971. ;; Delete header buttons.
  5972. (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
  5973. (match-beginning 0)
  5974. (point-max))))
  5975. (unless (and interactive buttons)
  5976. ;; Find buttons.
  5977. (setq buttons nil)
  5978. (dolist (button (gnus-article-mime-handles))
  5979. (setq handle (cdr button)
  5980. type (mm-handle-media-type handle))
  5981. (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
  5982. (with-current-buffer gnus-summary-buffer
  5983. gnus-inhibit-images)
  5984. gnus-inhibit-images)
  5985. (string-match "\\`image/" type))
  5986. (mm-inline-override-p handle)
  5987. (and (mm-handle-disposition handle)
  5988. (not (equal (car (mm-handle-disposition handle))
  5989. "inline"))
  5990. (not (mm-attachment-override-p handle)))
  5991. (not (mm-automatic-display-p handle))
  5992. (not (or (and (mm-inlinable-p handle)
  5993. (mm-inlined-p handle))
  5994. (mm-automatic-external-display-p type))))
  5995. (push button buttons)))
  5996. (when buttons
  5997. ;; Add header buttons.
  5998. (article-goto-body)
  5999. (forward-line -1)
  6000. (narrow-to-region (point) (point))
  6001. (insert "Attachment" (if (cdr buttons) "s" "") ":")
  6002. (dolist (button (nreverse buttons))
  6003. (setq st (point))
  6004. (insert " ")
  6005. (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
  6006. (gnus-insert-mime-button handle (car button))
  6007. (skip-chars-backward "\t\n ")
  6008. (delete-region (point) (point-max))
  6009. (when (> (current-column) (window-width))
  6010. (goto-char st)
  6011. (insert "\n")
  6012. (end-of-line)))
  6013. (insert "\n")
  6014. (dolist (ovl (overlays-in (point-min) (point)))
  6015. (overlay-put ovl 'gnus-button-attachment-extra t)
  6016. (overlay-put ovl 'face nil))
  6017. (let ((gnus-treatment-function-alist
  6018. '((gnus-treat-highlight-headers
  6019. gnus-article-highlight-headers))))
  6020. (gnus-treat-article 'head)))))))))
  6021. ;;; Article savers.
  6022. (defun gnus-output-to-file (file-name)
  6023. "Append the current article to a file named FILE-NAME.
  6024. If `gnus-article-save-coding-system' is non-nil, it is used to encode
  6025. text and used as the value of the coding cookie which is added to the
  6026. top of a file. Otherwise, this function saves a raw article without
  6027. the coding cookie."
  6028. (let* ((artbuf (current-buffer))
  6029. (file-name-coding-system nnmail-pathname-coding-system)
  6030. (coding gnus-article-save-coding-system)
  6031. (coding-system-for-read (if coding
  6032. nil ;; Rely on the coding cookie.
  6033. mm-text-coding-system))
  6034. (coding-system-for-write (or coding
  6035. mm-text-coding-system-for-write
  6036. mm-text-coding-system))
  6037. (exists (file-exists-p file-name)))
  6038. (with-temp-buffer
  6039. (when exists
  6040. (insert-file-contents file-name)
  6041. (goto-char (point-min))
  6042. ;; Remove the existing coding cookie.
  6043. (when (looking-at "X-Gnus-Coding-System: .+\n\n")
  6044. (delete-region (match-beginning 0) (match-end 0))))
  6045. (goto-char (point-max))
  6046. (insert-buffer-substring artbuf)
  6047. ;; Append newline at end of the buffer as separator, and then
  6048. ;; save it to file.
  6049. (goto-char (point-max))
  6050. (insert "\n")
  6051. (when coding
  6052. ;; If the coding system is not suitable to encode the text,
  6053. ;; ask a user for a proper one.
  6054. (when (fboundp 'select-safe-coding-system)
  6055. (setq coding (coding-system-base
  6056. (save-window-excursion
  6057. (select-safe-coding-system (point-min) (point-max)
  6058. coding))))
  6059. (setq coding-system-for-write
  6060. (or (cdr (assq coding '((mule-utf-8 . utf-8))))
  6061. coding)))
  6062. (goto-char (point-min))
  6063. ;; Add the coding cookie.
  6064. (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
  6065. coding-system-for-write)))
  6066. (if exists
  6067. (progn
  6068. (write-region (point-min) (point-max) file-name nil 'no-message)
  6069. (message "Appended to %s" file-name))
  6070. (write-region (point-min) (point-max) file-name))))
  6071. t)
  6072. (defun gnus-narrow-to-page (&optional arg)
  6073. "Narrow the article buffer to a page.
  6074. If given a numerical ARG, move forward ARG pages."
  6075. (interactive "P")
  6076. (setq arg (if arg (prefix-numeric-value arg) 0))
  6077. (with-current-buffer gnus-article-buffer
  6078. (widen)
  6079. ;; Remove any old next/prev buttons.
  6080. (when (gnus-visual-p 'page-marker)
  6081. (let ((inhibit-read-only t))
  6082. (gnus-remove-text-with-property 'gnus-prev)
  6083. (gnus-remove-text-with-property 'gnus-next)))
  6084. (let (st nd pt)
  6085. (when (save-excursion
  6086. (cond ((< arg 0)
  6087. (if (re-search-backward page-delimiter nil 'move (abs arg))
  6088. (prog1
  6089. (setq nd (match-beginning 0)
  6090. pt nd)
  6091. (when (re-search-backward page-delimiter nil t)
  6092. (setq st (match-end 0))))
  6093. (when (re-search-forward page-delimiter nil t)
  6094. (setq nd (match-beginning 0)
  6095. pt (point-min)))))
  6096. ((> arg 0)
  6097. (if (re-search-forward page-delimiter nil 'move arg)
  6098. (prog1
  6099. (setq st (match-end 0)
  6100. pt st)
  6101. (when (re-search-forward page-delimiter nil t)
  6102. (setq nd (match-beginning 0))))
  6103. (when (re-search-backward page-delimiter nil t)
  6104. (setq st (match-end 0)
  6105. pt (point-max)))))
  6106. (t
  6107. (when (re-search-backward page-delimiter nil t)
  6108. (goto-char (setq st (match-end 0))))
  6109. (when (re-search-forward page-delimiter nil t)
  6110. (setq nd (match-beginning 0)))
  6111. (or st nd))))
  6112. (setq gnus-page-broken t)
  6113. (when pt (goto-char pt))
  6114. (narrow-to-region (or st (point-min)) (or nd (point-max)))
  6115. (when (gnus-visual-p 'page-marker)
  6116. (save-excursion
  6117. (when nd
  6118. (goto-char nd)
  6119. (gnus-insert-next-page-button))
  6120. (when st
  6121. (goto-char st)
  6122. (gnus-insert-prev-page-button))))))))
  6123. ;; Article mode commands
  6124. (defun gnus-article-goto-next-page ()
  6125. "Show the next page of the article."
  6126. (interactive)
  6127. (when (gnus-article-next-page)
  6128. (goto-char (point-min))
  6129. (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
  6130. (defun gnus-article-goto-prev-page ()
  6131. "Show the previous page of the article."
  6132. (interactive)
  6133. (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
  6134. (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
  6135. (gnus-article-prev-page nil)))
  6136. ;; This is cleaner but currently breaks `gnus-pick-mode':
  6137. ;;
  6138. ;; (defun gnus-article-goto-next-page ()
  6139. ;; "Show the next page of the article."
  6140. ;; (interactive)
  6141. ;; (gnus-eval-in-buffer-window gnus-summary-buffer
  6142. ;; (gnus-summary-next-page)))
  6143. ;;
  6144. ;; (defun gnus-article-goto-prev-page ()
  6145. ;; "Show the next page of the article."
  6146. ;; (interactive)
  6147. ;; (gnus-eval-in-buffer-window gnus-summary-buffer
  6148. ;; (gnus-summary-prev-page)))
  6149. (defun gnus-article-next-page (&optional lines)
  6150. "Show the next page of the current article.
  6151. If end of article, return non-nil. Otherwise return nil.
  6152. Argument LINES specifies lines to be scrolled up."
  6153. (interactive "p")
  6154. (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
  6155. (if (and (not (and gnus-article-over-scroll
  6156. (> (count-lines (window-start) (point-max))
  6157. (if (featurep 'xemacs)
  6158. (or lines (1- (window-height)))
  6159. (+ (or lines (1- (window-height))) scroll-margin)))))
  6160. (save-excursion
  6161. (end-of-line)
  6162. (and (pos-visible-in-window-p) ;Not continuation line.
  6163. (>= (point) (point-max)))))
  6164. ;; Nothing in this page.
  6165. (if (or (not gnus-page-broken)
  6166. (save-excursion
  6167. (save-restriction
  6168. (widen)
  6169. (forward-line)
  6170. (eobp)))) ;Real end-of-buffer?
  6171. (progn
  6172. (when gnus-article-over-scroll
  6173. (gnus-article-next-page-1 lines))
  6174. t) ;Nothing more.
  6175. (gnus-narrow-to-page 1) ;Go to next page.
  6176. nil)
  6177. ;; More in this page.
  6178. (gnus-article-next-page-1 lines)
  6179. nil))
  6180. (defun gnus-article-beginning-of-window ()
  6181. "Move point to the beginning of the window.
  6182. In Emacs, the point is placed at the line number which `scroll-margin'
  6183. specifies."
  6184. (if (featurep 'xemacs)
  6185. (move-to-window-line 0)
  6186. ;; There is an obscure bug in Emacs that makes it impossible to
  6187. ;; scroll past big pictures in the article buffer. Try to fix
  6188. ;; this by adding a sanity check by counting the lines visible.
  6189. (when (> (count-lines (window-start) (window-end)) 30)
  6190. (move-to-window-line
  6191. (min (max 0 scroll-margin)
  6192. (max 1 (- (window-height)
  6193. (if mode-line-format 1 0)
  6194. (if header-line-format 1 0)
  6195. 2)))))))
  6196. (defvar scroll-in-place)
  6197. (defun gnus-article-next-page-1 (lines)
  6198. (condition-case ()
  6199. (let ((scroll-in-place nil)
  6200. (auto-window-vscroll nil))
  6201. (scroll-up lines))
  6202. (end-of-buffer
  6203. ;; Long lines may cause an end-of-buffer error.
  6204. (goto-char (point-max))))
  6205. (gnus-article-beginning-of-window))
  6206. (defun gnus-article-prev-page (&optional lines)
  6207. "Show previous page of current article.
  6208. Argument LINES specifies lines to be scrolled down."
  6209. (interactive "p")
  6210. (move-to-window-line 0)
  6211. (if (and gnus-page-broken
  6212. (bobp)
  6213. (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
  6214. (progn
  6215. (gnus-narrow-to-page -1) ;Go to previous page.
  6216. (goto-char (point-max))
  6217. (recenter (if gnus-article-over-scroll
  6218. (if lines
  6219. (max (if (featurep 'xemacs)
  6220. lines
  6221. (+ lines scroll-margin))
  6222. 3)
  6223. (- (window-height) 2))
  6224. -1)))
  6225. (prog1
  6226. (condition-case ()
  6227. (let ((scroll-in-place nil))
  6228. (scroll-down lines))
  6229. (beginning-of-buffer
  6230. (goto-char (point-min))))
  6231. (gnus-article-beginning-of-window))))
  6232. (defun gnus-article-only-boring-p ()
  6233. "Decide whether there is only boring text remaining in the article.
  6234. Something \"interesting\" is a word of at least two letters that does
  6235. not have a face in `gnus-article-boring-faces'."
  6236. (when (and gnus-article-skip-boring
  6237. (boundp 'gnus-article-boring-faces)
  6238. (symbol-value 'gnus-article-boring-faces))
  6239. (save-excursion
  6240. (let ((inhibit-point-motion-hooks t))
  6241. (catch 'only-boring
  6242. (while (re-search-forward "\\b\\w\\w" nil t)
  6243. (forward-char -1)
  6244. (when (not (gnus-intersection
  6245. (gnus-faces-at (point))
  6246. (symbol-value 'gnus-article-boring-faces)))
  6247. (throw 'only-boring nil)))
  6248. (throw 'only-boring t))))))
  6249. (defun gnus-article-refer-article ()
  6250. "Read article specified by message-id around point."
  6251. (interactive)
  6252. (save-excursion
  6253. (re-search-backward "[ \t]\\|^" (point-at-bol) t)
  6254. (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
  6255. (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
  6256. (let ((msg-id (concat "<" (match-string 0) ">")))
  6257. (set-buffer gnus-summary-buffer)
  6258. (gnus-summary-refer-article msg-id))
  6259. (error "No references around point"))))
  6260. (defun gnus-article-show-summary ()
  6261. "Reconfigure windows to show summary buffer."
  6262. (interactive)
  6263. (if (not (gnus-buffer-live-p gnus-summary-buffer))
  6264. (error "There is no summary buffer for this article buffer")
  6265. (gnus-article-set-globals)
  6266. (gnus-configure-windows 'article)
  6267. (gnus-summary-goto-subject gnus-current-article)
  6268. (gnus-summary-position-point)))
  6269. (defun gnus-article-describe-briefly ()
  6270. "Describe article mode commands briefly."
  6271. (interactive)
  6272. (gnus-message 6 "%s" (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")))
  6273. (defun gnus-article-check-buffer ()
  6274. "Beep if not in an article buffer."
  6275. (unless (derived-mode-p 'gnus-article-mode)
  6276. (error "Command invoked outside of a Gnus article buffer")))
  6277. (defvar gnus-pick-mode)
  6278. (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
  6279. "Read a summary buffer key sequence and execute it from the article buffer."
  6280. (interactive "P")
  6281. (gnus-article-check-buffer)
  6282. (let ((nosaves
  6283. '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
  6284. "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
  6285. "=" "^" "\M-^" "|"))
  6286. (nosave-but-article
  6287. '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
  6288. "An" "Ap" [?A (meta return)] [?A delete]))
  6289. (nosave-in-article
  6290. '("AS" "\C-d"))
  6291. keys new-sum-point)
  6292. (with-current-buffer gnus-article-current-summary
  6293. (let (gnus-pick-mode)
  6294. (setq unread-command-events (nconc unread-command-events
  6295. (list (or key last-command-event)))
  6296. keys (if (featurep 'xemacs)
  6297. (events-to-keys (read-key-sequence nil t))
  6298. (read-key-sequence nil t)))))
  6299. (message "")
  6300. (cond
  6301. ((eq (aref keys (1- (length keys))) ?\C-h)
  6302. (gnus-article-describe-bindings (substring keys 0 -1)))
  6303. ((or (member keys nosaves)
  6304. (member keys nosave-but-article)
  6305. (member keys nosave-in-article))
  6306. (let (func)
  6307. (save-window-excursion
  6308. (pop-to-buffer gnus-article-current-summary)
  6309. ;; We disable the pick minor mode commands.
  6310. (let (gnus-pick-mode)
  6311. (setq func (key-binding keys t))))
  6312. (if (or (not func)
  6313. (numberp func))
  6314. (ding)
  6315. (unless (member keys nosave-in-article)
  6316. (set-buffer gnus-article-current-summary))
  6317. (when (and (symbolp func)
  6318. (get func 'disabled))
  6319. (error "Function %s disabled" func))
  6320. (call-interactively func)
  6321. (setq new-sum-point (point)))
  6322. (when (member keys nosave-but-article)
  6323. (pop-to-buffer gnus-article-buffer))))
  6324. (t
  6325. ;; These commands should restore window configuration.
  6326. (let ((obuf (current-buffer))
  6327. (owin (current-window-configuration))
  6328. win func in-buffer selected new-sum-start new-sum-hscroll err)
  6329. (cond (not-restore-window
  6330. (pop-to-buffer gnus-article-current-summary)
  6331. (setq win (selected-window)))
  6332. ((setq win (get-buffer-window gnus-article-current-summary))
  6333. (select-window win))
  6334. (t
  6335. (let ((summary-buffer gnus-article-current-summary))
  6336. (gnus-configure-windows 'article)
  6337. (unless (setq win (get-buffer-window summary-buffer 'visible))
  6338. (let ((gnus-buffer-configuration
  6339. '((article ((vertical 1.0
  6340. (summary 0.25 point)
  6341. (article 1.0)))))))
  6342. (gnus-configure-windows 'article))
  6343. (setq win (get-buffer-window summary-buffer 'visible)))
  6344. (gnus-select-frame-set-input-focus (window-frame win))
  6345. (select-window win))))
  6346. (setq in-buffer (current-buffer))
  6347. ;; We disable the pick minor mode commands.
  6348. (setq func (let (gnus-pick-mode)
  6349. (key-binding keys t)))
  6350. (when (get func 'disabled)
  6351. (error "Function %s disabled" func))
  6352. (if (and func
  6353. (functionp func)
  6354. (condition-case code
  6355. (progn
  6356. (call-interactively func)
  6357. t)
  6358. (error
  6359. (setq err code)
  6360. nil)))
  6361. (progn
  6362. (when (eq win (selected-window))
  6363. (setq new-sum-point (point)
  6364. new-sum-start (window-start win)
  6365. new-sum-hscroll (window-hscroll win)))
  6366. (when (or (eq in-buffer (current-buffer))
  6367. (when (eq obuf (current-buffer))
  6368. (set-buffer in-buffer)
  6369. t))
  6370. (setq selected (ignore-errors (gnus-summary-select-article)))
  6371. (set-buffer obuf)
  6372. (unless not-restore-window
  6373. (set-window-configuration owin))
  6374. (when (and (eq selected 'old)
  6375. new-sum-point)
  6376. (set-window-start (get-buffer-window (current-buffer))
  6377. 1)
  6378. (set-window-point (get-buffer-window (current-buffer))
  6379. (if (article-goto-body)
  6380. (1- (point))
  6381. (point))))
  6382. (when (and (not not-restore-window)
  6383. new-sum-point
  6384. (window-live-p win)
  6385. (with-current-buffer (window-buffer win)
  6386. (derived-mode-p 'gnus-summary-mode)))
  6387. (set-window-point win new-sum-point)
  6388. (set-window-start win new-sum-start)
  6389. (set-window-hscroll win new-sum-hscroll))))
  6390. (set-window-configuration owin)
  6391. (if err
  6392. (signal (car err) (cdr err))
  6393. (ding))))))))
  6394. (defun gnus-article-read-summary-send-keys ()
  6395. (interactive)
  6396. (let ((unread-command-events (list (gnus-character-to-event ?S))))
  6397. (gnus-article-read-summary-keys)))
  6398. (defun gnus-article-describe-key (key)
  6399. "Display documentation of the function invoked by KEY.
  6400. KEY is a string or a vector."
  6401. (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
  6402. (read-key-sequence "Describe key: "))))
  6403. (gnus-article-check-buffer)
  6404. (if (memq (key-binding key t) '(gnus-article-read-summary-keys
  6405. gnus-article-read-summary-send-keys))
  6406. (with-current-buffer gnus-article-current-summary
  6407. (setq unread-command-events
  6408. (if (featurep 'xemacs)
  6409. (append key unread-command-events)
  6410. (nconc
  6411. (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
  6412. (list 'meta (- x 128))
  6413. x))
  6414. key)
  6415. unread-command-events)))
  6416. (let ((cursor-in-echo-area t)
  6417. gnus-pick-mode)
  6418. (describe-key (read-key-sequence nil t))))
  6419. (describe-key key)))
  6420. (defun gnus-article-describe-key-briefly (key &optional insert)
  6421. "Display documentation of the function invoked by KEY.
  6422. KEY is a string or a vector."
  6423. (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
  6424. (read-key-sequence "Describe key: "))
  6425. current-prefix-arg))
  6426. (gnus-article-check-buffer)
  6427. (if (memq (key-binding key t) '(gnus-article-read-summary-keys
  6428. gnus-article-read-summary-send-keys))
  6429. (with-current-buffer gnus-article-current-summary
  6430. (setq unread-command-events
  6431. (if (featurep 'xemacs)
  6432. (append key unread-command-events)
  6433. (nconc
  6434. (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
  6435. (list 'meta (- x 128))
  6436. x))
  6437. key)
  6438. unread-command-events)))
  6439. (let ((cursor-in-echo-area t)
  6440. gnus-pick-mode)
  6441. (describe-key-briefly (read-key-sequence nil t) insert)))
  6442. (describe-key-briefly key insert)))
  6443. ;;`gnus-agent-mode' in gnus-agent.el will define it.
  6444. (defvar gnus-agent-summary-mode)
  6445. (defvar gnus-draft-mode)
  6446. (defvar help-xref-stack-item)
  6447. (defvar help-xref-following)
  6448. (defun gnus-article-describe-bindings (&optional prefix)
  6449. "Show a list of all defined keys, and their definitions.
  6450. The optional argument PREFIX, if non-nil, should be a key sequence;
  6451. then we display only bindings that start with that prefix."
  6452. (interactive)
  6453. (gnus-article-check-buffer)
  6454. (let ((keymap (copy-keymap gnus-article-mode-map))
  6455. (map (copy-keymap gnus-article-send-map))
  6456. (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
  6457. parent agent draft)
  6458. (define-key keymap "S" map)
  6459. (define-key map [t] nil)
  6460. (with-current-buffer gnus-article-current-summary
  6461. (set-keymap-parent
  6462. keymap
  6463. (if (setq parent (keymap-parent gnus-article-mode-map))
  6464. (prog1
  6465. (setq parent (copy-keymap parent))
  6466. (set-keymap-parent parent (current-local-map)))
  6467. (current-local-map)))
  6468. (set-keymap-parent map (key-binding "S"))
  6469. (let (key def gnus-pick-mode)
  6470. (while sumkeys
  6471. (setq key (pop sumkeys))
  6472. (cond ((and (vectorp key) (= (length key) 1)
  6473. (consp (setq def (aref key 0)))
  6474. (numberp (car def)) (numberp (cdr def)))
  6475. (when (< (max (car def) (cdr def)) 128)
  6476. (setq sumkeys
  6477. (append (mapcar
  6478. #'vector
  6479. (nreverse (gnus-uncompress-range def)))
  6480. sumkeys))))
  6481. ((setq def (key-binding key))
  6482. (unless (eq def 'undefined)
  6483. (define-key keymap key def))))))
  6484. (when (boundp 'gnus-agent-summary-mode)
  6485. (setq agent gnus-agent-summary-mode))
  6486. (when (boundp 'gnus-draft-mode)
  6487. (setq draft gnus-draft-mode)))
  6488. (with-temp-buffer
  6489. (use-local-map keymap)
  6490. (set (make-local-variable 'gnus-agent-summary-mode) agent)
  6491. (set (make-local-variable 'gnus-draft-mode) draft)
  6492. (describe-bindings prefix))
  6493. (let ((item `((lambda (prefix)
  6494. (with-current-buffer ,(current-buffer)
  6495. (gnus-article-describe-bindings prefix)))
  6496. ,prefix)))
  6497. ;; Loading `help-mode' here is necessary if `describe-bindings'
  6498. ;; is replaced with something, e.g. `helm-descbinds'.
  6499. (require 'help-mode)
  6500. (with-current-buffer (let (help-xref-following) (help-buffer))
  6501. (setq help-xref-stack-item item)))))
  6502. (defun gnus-article-reply-with-original (&optional wide)
  6503. "Start composing a reply mail to the current message.
  6504. The text in the region will be yanked. If the region isn't active,
  6505. the entire article will be yanked."
  6506. (interactive)
  6507. (let ((article (cdr gnus-article-current))
  6508. contents)
  6509. (if (not (gnus-region-active-p))
  6510. (with-current-buffer gnus-summary-buffer
  6511. (gnus-summary-reply (list (list article)) wide))
  6512. (setq contents (buffer-substring (point) (mark t)))
  6513. ;; Deactivate active regions.
  6514. (when (and (boundp 'transient-mark-mode)
  6515. transient-mark-mode)
  6516. (setq mark-active nil))
  6517. (with-current-buffer gnus-summary-buffer
  6518. (gnus-summary-reply
  6519. (list (list article contents)) wide)))))
  6520. (defun gnus-article-wide-reply-with-original ()
  6521. "Start composing a wide reply mail to the current message.
  6522. The text in the region will be yanked. If the region isn't active,
  6523. the entire article will be yanked."
  6524. (interactive)
  6525. (gnus-article-reply-with-original t))
  6526. (defun gnus-article-followup-with-original ()
  6527. "Compose a followup to the current article.
  6528. The text in the region will be yanked. If the region isn't active,
  6529. the entire article will be yanked."
  6530. (interactive)
  6531. (let ((article (cdr gnus-article-current))
  6532. contents)
  6533. (if (not (gnus-region-active-p))
  6534. (with-current-buffer gnus-summary-buffer
  6535. (gnus-summary-followup (list (list article))))
  6536. (setq contents (buffer-substring (point) (mark t)))
  6537. ;; Deactivate active regions.
  6538. (when (and (boundp 'transient-mark-mode)
  6539. transient-mark-mode)
  6540. (setq mark-active nil))
  6541. (with-current-buffer gnus-summary-buffer
  6542. (gnus-summary-followup
  6543. (list (list article contents)))))))
  6544. (defun gnus-article-hide (&optional arg force)
  6545. "Hide all the gruft in the current article.
  6546. This means that signatures, cited text and (some) headers will be
  6547. hidden.
  6548. If given a prefix, show the hidden text instead."
  6549. (interactive (append (gnus-article-hidden-arg) (list 'force)))
  6550. (gnus-article-hide-headers arg)
  6551. (gnus-article-hide-list-identifiers arg)
  6552. (gnus-article-hide-citation-maybe arg force)
  6553. (gnus-article-hide-signature arg))
  6554. (defun gnus-check-group-server ()
  6555. ;; Make sure the connection to the server is alive.
  6556. (unless (gnus-server-opened
  6557. (gnus-find-method-for-group gnus-newsgroup-name))
  6558. (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
  6559. (gnus-request-group gnus-newsgroup-name t)))
  6560. (declare-function nneething-get-file-name "nneething" (id))
  6561. (defun gnus-request-article-this-buffer (article group)
  6562. "Get an article and insert it into this buffer."
  6563. (let (do-update-line sparse-header)
  6564. (prog1
  6565. (save-excursion
  6566. (erase-buffer)
  6567. (gnus-kill-all-overlays)
  6568. (setq group (or group gnus-newsgroup-name))
  6569. ;; Using `gnus-request-article' directly will insert the article into
  6570. ;; `nntp-server-buffer' - so we'll save some time by not having to
  6571. ;; copy it from the server buffer into the article buffer.
  6572. ;; We only request an article by message-id when we do not have the
  6573. ;; headers for it, so we'll have to get those.
  6574. (when (stringp article)
  6575. (gnus-read-header article))
  6576. ;; If the article number is negative, that means that this article
  6577. ;; doesn't belong in this newsgroup (possibly), so we find its
  6578. ;; message-id and request it by id instead of number.
  6579. (when (and (numberp article)
  6580. gnus-summary-buffer
  6581. (get-buffer gnus-summary-buffer)
  6582. (gnus-buffer-exists-p gnus-summary-buffer))
  6583. (with-current-buffer gnus-summary-buffer
  6584. (let ((header (gnus-summary-article-header article)))
  6585. (when (< article 0)
  6586. (cond
  6587. ((memq article gnus-newsgroup-sparse)
  6588. ;; This is a sparse gap article.
  6589. (setq do-update-line article)
  6590. (setq article (mail-header-id header))
  6591. (setq sparse-header (gnus-read-header article))
  6592. (setq gnus-newsgroup-sparse
  6593. (delq article gnus-newsgroup-sparse)))
  6594. ((vectorp header)
  6595. ;; It's a real article.
  6596. (setq article (mail-header-id header)))
  6597. (t
  6598. ;; It is an extracted pseudo-article.
  6599. (setq article 'pseudo)
  6600. (gnus-request-pseudo-article header))))
  6601. (let ((method (gnus-find-method-for-group
  6602. gnus-newsgroup-name)))
  6603. (when (and (eq (car method) 'nneething)
  6604. (vectorp header))
  6605. (let ((dir (nneething-get-file-name
  6606. (mail-header-id header))))
  6607. (when (and (stringp dir)
  6608. (file-directory-p dir))
  6609. (setq article 'nneething)
  6610. (gnus-group-enter-directory dir))))))))
  6611. (cond
  6612. ;; Refuse to select canceled articles.
  6613. ((and (numberp article)
  6614. gnus-summary-buffer
  6615. (get-buffer gnus-summary-buffer)
  6616. (gnus-buffer-exists-p gnus-summary-buffer)
  6617. (eq (cdr (with-current-buffer gnus-summary-buffer
  6618. (assq article gnus-newsgroup-reads)))
  6619. gnus-canceled-mark))
  6620. nil)
  6621. ;; We first check `gnus-original-article-buffer'.
  6622. ((and (get-buffer gnus-original-article-buffer)
  6623. (numberp article)
  6624. (with-current-buffer gnus-original-article-buffer
  6625. (and (equal (car gnus-original-article) group)
  6626. (eq (cdr gnus-original-article) article))))
  6627. ;; `insert-buffer-substring' would incorrectly use the
  6628. ;; equivalent of string-make-multibyte which amount to decoding
  6629. ;; with locale-coding-system, causing failure of
  6630. ;; subsequent decoding.
  6631. (insert (mm-string-to-multibyte
  6632. (with-current-buffer gnus-original-article-buffer
  6633. (buffer-substring (point-min) (point-max)))))
  6634. 'article)
  6635. ;; Check the backlog.
  6636. ((and gnus-keep-backlog
  6637. (gnus-backlog-request-article group article (current-buffer)))
  6638. 'article)
  6639. ;; Check asynchronous pre-fetch.
  6640. ((gnus-async-request-fetched-article group article (current-buffer))
  6641. (gnus-async-prefetch-next group article gnus-summary-buffer)
  6642. (when (and (numberp article) gnus-keep-backlog)
  6643. (gnus-backlog-enter-article group article (current-buffer)))
  6644. 'article)
  6645. ;; Check the cache.
  6646. ((and gnus-use-cache
  6647. (numberp article)
  6648. (gnus-cache-request-article article group))
  6649. 'article)
  6650. ;; Check the agent cache.
  6651. ((gnus-agent-request-article article group)
  6652. 'article)
  6653. ;; Get the article and put into the article buffer.
  6654. ((or (stringp article)
  6655. (numberp article))
  6656. (let ((gnus-override-method gnus-override-method)
  6657. (methods (and (stringp article)
  6658. (with-current-buffer gnus-summary-buffer
  6659. (gnus-refer-article-methods))))
  6660. (backend (car (gnus-find-method-for-group
  6661. gnus-newsgroup-name)))
  6662. result
  6663. (inhibit-read-only t))
  6664. (when (and (null gnus-override-method)
  6665. methods)
  6666. (setq gnus-override-method (pop methods)))
  6667. (while (not result)
  6668. (erase-buffer)
  6669. (gnus-kill-all-overlays)
  6670. (let ((gnus-newsgroup-name group))
  6671. (gnus-check-group-server))
  6672. (cond
  6673. ((gnus-request-article article group (current-buffer))
  6674. (when (numberp article)
  6675. (gnus-async-prefetch-next group article
  6676. gnus-summary-buffer)
  6677. (when gnus-keep-backlog
  6678. (gnus-backlog-enter-article
  6679. group article (current-buffer)))
  6680. (when (and gnus-agent
  6681. (gnus-agent-group-covered-p group))
  6682. (gnus-agent-store-article article group)))
  6683. (setq result 'article))
  6684. (methods
  6685. (setq gnus-override-method (pop methods)))
  6686. ((not (string-match "^400 "
  6687. (nnheader-get-report backend)))
  6688. ;; If we get 400 server disconnect, reconnect and
  6689. ;; retry; otherwise, assume the article has expired.
  6690. (setq result 'done))))
  6691. (and (eq result 'article) 'article)))
  6692. ;; It was a pseudo.
  6693. (t article)))
  6694. ;; Associate this article with the current summary buffer.
  6695. (setq gnus-article-current-summary gnus-summary-buffer)
  6696. ;; Take the article from the original article buffer
  6697. ;; and place it in the buffer it's supposed to be in.
  6698. (when (and (get-buffer gnus-article-buffer)
  6699. (equal (buffer-name (current-buffer))
  6700. (buffer-name (get-buffer gnus-article-buffer))))
  6701. (save-excursion
  6702. (if (get-buffer gnus-original-article-buffer)
  6703. (set-buffer gnus-original-article-buffer)
  6704. (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
  6705. (buffer-disable-undo)
  6706. (setq major-mode 'gnus-original-article-mode)
  6707. (setq buffer-read-only t))
  6708. (let ((inhibit-read-only t))
  6709. (erase-buffer)
  6710. (insert-buffer-substring gnus-article-buffer))
  6711. (setq gnus-original-article (cons group article)))
  6712. ;; Decode charsets.
  6713. (run-hooks 'gnus-article-decode-hook)
  6714. ;; Mark article as decoded or not.
  6715. (setq gnus-article-decoded-p gnus-article-decode-hook))
  6716. ;; Update sparse articles.
  6717. (when (and do-update-line
  6718. (or (numberp article)
  6719. (stringp article)))
  6720. (let ((buf (current-buffer)))
  6721. (set-buffer gnus-summary-buffer)
  6722. (gnus-summary-update-article do-update-line sparse-header)
  6723. (gnus-summary-goto-subject do-update-line nil t)
  6724. (set-window-point (gnus-get-buffer-window (current-buffer) t)
  6725. (point))
  6726. (set-buffer buf))))))
  6727. (defun gnus-block-private-groups (group)
  6728. "Allows images in newsgroups to be shown, blocks images in all
  6729. other groups."
  6730. (if (or (gnus-news-group-p group)
  6731. (gnus-member-of-valid 'global group))
  6732. ;; Block nothing in news groups.
  6733. nil
  6734. ;; Block everything anywhere else.
  6735. "."))
  6736. (defun gnus-blocked-images ()
  6737. (if (functionp gnus-blocked-images)
  6738. (funcall gnus-blocked-images gnus-newsgroup-name)
  6739. gnus-blocked-images))
  6740. ;;;
  6741. ;;; Article editing
  6742. ;;;
  6743. (defcustom gnus-article-edit-mode-hook nil
  6744. "Hook run in article edit mode buffers."
  6745. :group 'gnus-article-various
  6746. :type 'hook)
  6747. (defvar gnus-article-edit-done-function nil)
  6748. (defvar gnus-article-edit-mode-map nil)
  6749. ;; Should we be using derived.el for this?
  6750. (unless gnus-article-edit-mode-map
  6751. (setq gnus-article-edit-mode-map (make-keymap))
  6752. (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
  6753. (gnus-define-keys gnus-article-edit-mode-map
  6754. "\C-c?" describe-mode
  6755. "\C-c\C-c" gnus-article-edit-done
  6756. "\C-c\C-k" gnus-article-edit-exit
  6757. "\C-c\C-f\C-t" message-goto-to
  6758. "\C-c\C-f\C-o" message-goto-from
  6759. "\C-c\C-f\C-b" message-goto-bcc
  6760. ;;"\C-c\C-f\C-w" message-goto-fcc
  6761. "\C-c\C-f\C-c" message-goto-cc
  6762. "\C-c\C-f\C-s" message-goto-subject
  6763. "\C-c\C-f\C-r" message-goto-reply-to
  6764. "\C-c\C-f\C-n" message-goto-newsgroups
  6765. "\C-c\C-f\C-d" message-goto-distribution
  6766. "\C-c\C-f\C-f" message-goto-followup-to
  6767. "\C-c\C-f\C-m" message-goto-mail-followup-to
  6768. "\C-c\C-f\C-k" message-goto-keywords
  6769. "\C-c\C-f\C-u" message-goto-summary
  6770. "\C-c\C-f\C-i" message-insert-or-toggle-importance
  6771. "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
  6772. "\C-c\C-b" message-goto-body
  6773. "\C-c\C-i" message-goto-signature
  6774. "\C-c\C-t" message-insert-to
  6775. "\C-c\C-n" message-insert-newsgroups
  6776. "\C-c\C-o" message-sort-headers
  6777. "\C-c\C-e" message-elide-region
  6778. "\C-c\C-v" message-delete-not-region
  6779. "\C-c\C-z" message-kill-to-signature
  6780. "\M-\r" message-newline-and-reformat
  6781. "\C-c\C-a" mml-attach-file
  6782. "\C-a" message-beginning-of-line
  6783. "\t" message-tab
  6784. "\M-;" comment-region)
  6785. (gnus-define-keys (gnus-article-edit-wash-map
  6786. "\C-c\C-w" gnus-article-edit-mode-map)
  6787. "f" gnus-article-edit-full-stops))
  6788. (easy-menu-define
  6789. gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
  6790. '("Field"
  6791. ["Fetch To" message-insert-to t]
  6792. ["Fetch Newsgroups" message-insert-newsgroups t]
  6793. "----"
  6794. ["To" message-goto-to t]
  6795. ["From" message-goto-from t]
  6796. ["Subject" message-goto-subject t]
  6797. ["Cc" message-goto-cc t]
  6798. ["Reply-To" message-goto-reply-to t]
  6799. ["Summary" message-goto-summary t]
  6800. ["Keywords" message-goto-keywords t]
  6801. ["Newsgroups" message-goto-newsgroups t]
  6802. ["Followup-To" message-goto-followup-to t]
  6803. ["Mail-Followup-To" message-goto-mail-followup-to t]
  6804. ["Distribution" message-goto-distribution t]
  6805. ["Body" message-goto-body t]
  6806. ["Signature" message-goto-signature t]))
  6807. (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
  6808. "Major mode for editing articles.
  6809. This is an extended text-mode.
  6810. \\{gnus-article-edit-mode-map}"
  6811. (make-local-variable 'gnus-article-edit-done-function)
  6812. (make-local-variable 'gnus-prev-winconf)
  6813. (set (make-local-variable 'font-lock-defaults)
  6814. '(message-font-lock-keywords t))
  6815. (set (make-local-variable 'mail-header-separator) "")
  6816. (set (make-local-variable 'gnus-article-edit-mode) t)
  6817. (easy-menu-add message-mode-field-menu message-mode-map)
  6818. (mml-mode)
  6819. (setq buffer-read-only nil)
  6820. (buffer-enable-undo)
  6821. (widen))
  6822. (defun gnus-article-edit (&optional force)
  6823. "Edit the current article.
  6824. This will have permanent effect only in mail groups.
  6825. If FORCE is non-nil, allow editing of articles even in read-only
  6826. groups."
  6827. (interactive "P")
  6828. (when (and (not force)
  6829. (gnus-group-read-only-p))
  6830. (error "The current newsgroup does not support article editing"))
  6831. (gnus-article-date-original)
  6832. (gnus-article-edit-article
  6833. 'ignore
  6834. `(lambda (no-highlight)
  6835. 'ignore
  6836. (gnus-summary-edit-article-done
  6837. ,(or (mail-header-references gnus-current-headers) "")
  6838. ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
  6839. (defun gnus-article-edit-article (start-func exit-func &optional quiet)
  6840. "Start editing the contents of the current article buffer."
  6841. (let ((winconf (current-window-configuration)))
  6842. (set-buffer gnus-article-buffer)
  6843. (let ((message-auto-save-directory
  6844. ;; Don't associate the article buffer with a draft file.
  6845. nil))
  6846. (gnus-article-edit-mode))
  6847. (funcall start-func)
  6848. (set-buffer-modified-p nil)
  6849. (gnus-configure-windows 'edit-article)
  6850. (setq gnus-article-edit-done-function exit-func)
  6851. (setq gnus-prev-winconf winconf)
  6852. (unless quiet
  6853. (gnus-message 6 "C-c C-c to end edits"))))
  6854. (defun gnus-article-edit-done (&optional arg)
  6855. "Update the article edits and exit."
  6856. (interactive "P")
  6857. (let ((func gnus-article-edit-done-function)
  6858. (buf (current-buffer))
  6859. (start (window-start))
  6860. (winconf gnus-prev-winconf))
  6861. (widen) ;; Widen it in case that users narrowed the buffer.
  6862. (funcall func arg)
  6863. (set-buffer buf)
  6864. ;; The cache and backlog have to be flushed somewhat.
  6865. (when gnus-keep-backlog
  6866. (gnus-backlog-remove-article
  6867. (car gnus-article-current) (cdr gnus-article-current)))
  6868. ;; Flush original article as well.
  6869. (gnus-flush-original-article-buffer)
  6870. (when gnus-use-cache
  6871. (gnus-cache-update-article
  6872. (car gnus-article-current) (cdr gnus-article-current)))
  6873. ;; We remove all text props from the article buffer.
  6874. (kill-all-local-variables)
  6875. (set-text-properties (point-min) (point-max) nil)
  6876. (gnus-article-mode)
  6877. (set-window-configuration winconf)
  6878. (set-buffer buf)
  6879. (set-window-start (get-buffer-window buf) start)
  6880. (set-window-point (get-buffer-window buf) (point)))
  6881. (gnus-summary-show-article))
  6882. (defun gnus-flush-original-article-buffer ()
  6883. (when (get-buffer gnus-original-article-buffer)
  6884. (with-current-buffer gnus-original-article-buffer
  6885. (setq gnus-original-article nil))))
  6886. (defun gnus-article-edit-exit ()
  6887. "Exit the article editing without updating."
  6888. (interactive)
  6889. (when (or (not (buffer-modified-p))
  6890. (yes-or-no-p "Article modified; kill anyway? "))
  6891. (let ((curbuf (current-buffer))
  6892. (p (point))
  6893. (window-start (window-start)))
  6894. (erase-buffer)
  6895. (if (gnus-buffer-live-p gnus-original-article-buffer)
  6896. (insert-buffer-substring gnus-original-article-buffer))
  6897. (let ((winconf gnus-prev-winconf))
  6898. (kill-all-local-variables)
  6899. (gnus-article-mode)
  6900. (set-window-configuration winconf)
  6901. ;; Tippy-toe some to make sure that point remains where it was.
  6902. (save-current-buffer
  6903. (set-buffer curbuf)
  6904. (set-window-start (get-buffer-window (current-buffer)) window-start)
  6905. (goto-char p))))
  6906. (gnus-summary-show-article)))
  6907. (defun gnus-article-edit-full-stops ()
  6908. "Interactively repair spacing at end of sentences."
  6909. (interactive)
  6910. (save-excursion
  6911. (goto-char (point-min))
  6912. (search-forward-regexp "^$" nil t)
  6913. (let ((case-fold-search nil))
  6914. (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
  6915. ;;;
  6916. ;;; Article highlights
  6917. ;;;
  6918. ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
  6919. ;;; Internal Variables:
  6920. (defcustom gnus-button-url-regexp
  6921. (concat
  6922. "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
  6923. "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
  6924. "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
  6925. (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
  6926. (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
  6927. (punct "!?:;.,"))
  6928. (concat
  6929. "\\(?:"
  6930. ;; Match paired parentheses, e.g. in Wikipedia URLs:
  6931. ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
  6932. "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
  6933. "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
  6934. "\\|"
  6935. "[" chars punct "]+" "[" chars "]"
  6936. "\\)"))
  6937. (concat ;; XEmacs 21.4 doesn't support POSIX.
  6938. "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
  6939. "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
  6940. "\\)")
  6941. "Regular expression that matches URLs."
  6942. :version "24.4"
  6943. :group 'gnus-article-buttons
  6944. :type 'regexp)
  6945. (defcustom gnus-button-valid-fqdn-regexp
  6946. message-valid-fqdn-regexp
  6947. "Regular expression that matches a valid FQDN."
  6948. :version "22.1"
  6949. :group 'gnus-article-buttons
  6950. :type 'regexp)
  6951. ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
  6952. (defcustom gnus-button-valid-localpart-regexp
  6953. "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
  6954. "Regular expression that matches a localpart of mail addresses or MIDs."
  6955. :version "22.1"
  6956. :group 'gnus-article-buttons
  6957. :type 'regexp)
  6958. (defcustom gnus-button-man-handler 'manual-entry
  6959. "Function to use for displaying man pages.
  6960. The function must take at least one argument with a string naming the
  6961. man page."
  6962. :version "22.1"
  6963. :type '(choice (function-item :tag "Man" manual-entry)
  6964. (function-item :tag "Woman" woman)
  6965. (function :tag "Other"))
  6966. :group 'gnus-article-buttons)
  6967. (defcustom gnus-button-mid-or-mail-regexp
  6968. (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
  6969. gnus-button-valid-fqdn-regexp
  6970. ">?\\)\\b")
  6971. "Regular expression that matches a message ID or a mail address."
  6972. :version "22.1"
  6973. :group 'gnus-article-buttons
  6974. :type 'regexp)
  6975. (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
  6976. "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
  6977. Strings like this can be either a message ID or a mail address. If it is one
  6978. of the symbols `mid' or `mail', Gnus will always assume that the string is a
  6979. message ID or a mail address, respectively. If this variable is set to the
  6980. symbol `ask', always query the user what do do. If it is a function, this
  6981. function will be called with the string as its only argument. The function
  6982. must return `mid', `mail', `invalid' or `ask'."
  6983. :version "22.1"
  6984. :group 'gnus-article-buttons
  6985. :type '(choice (function-item :tag "Heuristic function"
  6986. gnus-button-mid-or-mail-heuristic)
  6987. (const ask)
  6988. (const mid)
  6989. (const mail)))
  6990. (defcustom gnus-button-mid-or-mail-heuristic-alist
  6991. '((-10.0 . ".+\\$.+@")
  6992. (-10.0 . "#")
  6993. (-10.0 . "\\*")
  6994. (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
  6995. (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
  6996. (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
  6997. (-1.0 . "^[^a-z]+@")
  6998. ;;
  6999. (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
  7000. (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
  7001. (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
  7002. (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
  7003. ;;
  7004. (-2.0 . "^[0-9]")
  7005. (-1.0 . "^[0-9][0-9]")
  7006. ;;
  7007. ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
  7008. (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
  7009. ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
  7010. (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
  7011. ;;
  7012. (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
  7013. (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
  7014. ;; "[0-9]{8,}.*\@"
  7015. (-3.0
  7016. . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
  7017. ;; "[0-9]{12,}.*\@"
  7018. ;; compensation for TDMA dated mail addresses:
  7019. (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
  7020. ;;
  7021. (-20.0 . "\\.fsf@") ;; Gnus
  7022. (-20.0 . "^slrn")
  7023. (-20.0 . "^Pine")
  7024. (-20.0 . "^alpine\\.")
  7025. (-20.0 . "_-_") ;; Subject change in thread
  7026. ;;
  7027. (-20.0 . "\\.ln@") ;; leafnode
  7028. (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
  7029. (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
  7030. ;;
  7031. ;; (5.0 . "") ;; $local_part_len <= 7
  7032. (10.0 . "^[^0-9]+@")
  7033. (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
  7034. ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
  7035. (3.0 . "@stud")
  7036. ;;
  7037. (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
  7038. ;;
  7039. (0.5 . "^[A-Z][a-z]")
  7040. (0.5 . "^[A-Z][a-z][a-z]")
  7041. (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
  7042. (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
  7043. "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
  7044. A negative RATE indicates a message IDs, whereas a positive indicates a mail
  7045. address. The REGEXP is processed with `case-fold-search' set to nil."
  7046. :version "22.1"
  7047. :group 'gnus-article-buttons
  7048. :type '(repeat (cons (number :tag "Rate")
  7049. (regexp :tag "Regexp"))))
  7050. (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
  7051. "Guess whether MID-OR-MAIL is a message ID or a mail address.
  7052. Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
  7053. address, `ask' if unsure and `invalid' if the string is invalid."
  7054. (let ((case-fold-search nil)
  7055. (list gnus-button-mid-or-mail-heuristic-alist)
  7056. (result 0) rate regexp lpartlen elem)
  7057. (setq lpartlen
  7058. (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
  7059. (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
  7060. ;; Certain special cases...
  7061. (when (string-match
  7062. (concat
  7063. "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
  7064. "^[0-9]+\\.[0-9]+@compuserve\\|"
  7065. "@public\\.gmane\\.org")
  7066. mid-or-mail)
  7067. (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
  7068. (setq result 'mail))
  7069. (when (string-match "@.*@\\| " mid-or-mail)
  7070. (gnus-message 8 "`%s' is invalid." mid-or-mail)
  7071. (setq result 'invalid))
  7072. ;; Nothing more to do, if result is not a number here...
  7073. (when (numberp result)
  7074. (while list
  7075. (setq elem (car list)
  7076. rate (car elem)
  7077. regexp (cdr elem)
  7078. list (cdr list))
  7079. (when (string-match regexp mid-or-mail)
  7080. (setq result (+ result rate))
  7081. (gnus-message
  7082. 9 "`%s' matched `%s', rate `%s', result `%s'."
  7083. mid-or-mail regexp rate result)))
  7084. (when (<= lpartlen 7)
  7085. (setq result (+ result 5.0))
  7086. (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
  7087. mid-or-mail result))
  7088. (when (>= lpartlen 12)
  7089. (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
  7090. (cond
  7091. ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
  7092. ;; Long local part should contain realname if e-mail address,
  7093. ;; too many digits: message-id.
  7094. ;; $score -= 5.0 + 0.1 * $local_part_len;
  7095. (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
  7096. (setq result (+ result rate))
  7097. (gnus-message
  7098. 9 "Many digits in `%s', rate `%s', result `%s'."
  7099. mid-or-mail rate result))
  7100. ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
  7101. mid-or-mail)
  7102. ;; Too few vowels [^aeiouy]{4,}.*@
  7103. (setq result (+ result -5.0))
  7104. (gnus-message
  7105. 9 "Few vowels in `%s', rate `%s', result `%s'."
  7106. mid-or-mail -5.0 result))
  7107. (t
  7108. (setq result (+ result 5.0))
  7109. (gnus-message
  7110. 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
  7111. (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
  7112. ;; Maybe we should make this a customizable alist: (condition . 'result)
  7113. (cond
  7114. ((symbolp result) result)
  7115. ;; Now convert number into proper results:
  7116. ((< result -10.0) 'mid)
  7117. ((> result 10.0) 'mail)
  7118. (t 'ask))))
  7119. (defun gnus-button-handle-mid-or-mail (mid-or-mail)
  7120. (let* ((pref gnus-button-prefer-mid-or-mail) guessed
  7121. (url-mid (concat "news" ":" mid-or-mail))
  7122. (url-mailto (concat "mailto" ":" mid-or-mail)))
  7123. (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
  7124. (when (fboundp pref)
  7125. (setq guessed
  7126. ;; get rid of surrounding angles...
  7127. (funcall pref
  7128. (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
  7129. (if (or (eq 'mid guessed) (eq 'mail guessed))
  7130. (setq pref guessed)
  7131. (setq pref 'ask)))
  7132. (if (eq pref 'ask)
  7133. (save-window-excursion
  7134. (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
  7135. (setq pref 'mail)
  7136. (setq pref 'mid))))
  7137. (cond ((eq pref 'mid)
  7138. (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
  7139. (gnus-button-handle-news url-mid))
  7140. ((eq pref 'mail)
  7141. (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
  7142. (gnus-url-mailto url-mailto))
  7143. (t (gnus-message 3 "Invalid string.")))))
  7144. (defun gnus-button-handle-custom (fun arg)
  7145. "Call function FUN on argument ARG.
  7146. Both FUN and ARG are supposed to be strings. ARG will be passed
  7147. as a symbol to FUN."
  7148. (funcall (intern fun)
  7149. (if (string-match "^customize-apropos" fun)
  7150. arg
  7151. (intern arg))))
  7152. (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
  7153. (defun gnus-button-handle-describe-function (url)
  7154. "Call `describe-function' when pushing the corresponding URL button."
  7155. (describe-function
  7156. (intern
  7157. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
  7158. (defun gnus-button-handle-describe-variable (url)
  7159. "Call `describe-variable' when pushing the corresponding URL button."
  7160. (describe-variable
  7161. (intern
  7162. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
  7163. (defun gnus-button-handle-symbol (url)
  7164. "Display help on variable or function.
  7165. Calls `describe-variable' or `describe-function'."
  7166. (let ((sym (intern url)))
  7167. (cond
  7168. ((fboundp sym) (describe-function sym))
  7169. ((boundp sym) (describe-variable sym))
  7170. (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
  7171. (defun gnus-button-handle-describe-key (url)
  7172. "Call `describe-key' when pushing the corresponding URL button."
  7173. (let* ((key-string
  7174. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
  7175. (keys (ignore-errors (eval `(kbd ,key-string)))))
  7176. (if keys
  7177. (describe-key keys)
  7178. (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
  7179. (defun gnus-button-handle-apropos (url)
  7180. "Call `apropos' when pushing the corresponding URL button."
  7181. (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  7182. (defun gnus-button-handle-apropos-command (url)
  7183. "Call `apropos' when pushing the corresponding URL button."
  7184. (apropos-command
  7185. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  7186. (defun gnus-button-handle-apropos-variable (url)
  7187. "Call `apropos' when pushing the corresponding URL button."
  7188. (funcall
  7189. (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
  7190. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  7191. (defun gnus-button-handle-apropos-documentation (url)
  7192. "Call `apropos' when pushing the corresponding URL button."
  7193. (funcall
  7194. (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
  7195. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  7196. (defun gnus-button-handle-library (url)
  7197. "Call `locate-library' when pushing the corresponding URL button."
  7198. (gnus-message 9 "url=`%s'" url)
  7199. (let* ((lib (locate-library url))
  7200. (file (gnus-replace-in-string (or lib "") "\\.elc" ".el")))
  7201. (if (not lib)
  7202. (gnus-message 1 "Cannot locale library `%s'." url)
  7203. (find-file-read-only file))))
  7204. (defcustom gnus-button-man-level 5
  7205. "*Integer that says how many man-related buttons Gnus will show.
  7206. The higher the number, the more buttons will appear and the more false
  7207. positives are possible. Note that you can set this variable local to
  7208. specific groups. Setting it higher in Unix groups is probably a good idea.
  7209. See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
  7210. how to set variables in specific groups."
  7211. :version "22.1"
  7212. :group 'gnus-article-buttons
  7213. :link '(custom-manual "(gnus)Group Parameters")
  7214. :type 'integer)
  7215. (defcustom gnus-button-emacs-level 5
  7216. "*Integer that says how many emacs-related buttons Gnus will show.
  7217. The higher the number, the more buttons will appear and the more false
  7218. positives are possible. Note that you can set this variable local to
  7219. specific groups. Setting it higher in Emacs or Gnus related groups is
  7220. probably a good idea. See Info node `(gnus)Group Parameters' and the variable
  7221. `gnus-parameters' on how to set variables in specific groups."
  7222. :version "22.1"
  7223. :group 'gnus-article-buttons
  7224. :link '(custom-manual "(gnus)Group Parameters")
  7225. :type 'integer)
  7226. (defcustom gnus-button-message-level 5
  7227. "*Integer that says how many buttons for news or mail messages will appear.
  7228. The higher the number, the more buttons will appear and the more false
  7229. positives are possible."
  7230. ;; mail addresses, MIDs, URLs for news, ...
  7231. :version "22.1"
  7232. :group 'gnus-article-buttons
  7233. :type 'integer)
  7234. (defcustom gnus-button-browse-level 5
  7235. "*Integer that says how many buttons for browsing will appear.
  7236. The higher the number, the more buttons will appear and the more false
  7237. positives are possible."
  7238. ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
  7239. :version "22.1"
  7240. :group 'gnus-article-buttons
  7241. :type 'integer)
  7242. (defcustom gnus-button-alist
  7243. '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
  7244. 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
  7245. ((concat "\\b\\(nntp\\|news\\):\\("
  7246. gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
  7247. 0 t gnus-button-handle-news 2)
  7248. ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
  7249. 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
  7250. ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
  7251. 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
  7252. ;; RFC 2392 (Don't allow `/' in domain part --> CID)
  7253. ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
  7254. 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
  7255. ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
  7256. 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
  7257. ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
  7258. 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
  7259. ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
  7260. 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
  7261. ;; RFC 2368 (The mailto URL scheme)
  7262. ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
  7263. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  7264. ("\\bmailto:\\([^ \n\t]+\\)"
  7265. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  7266. ;; Info Konqueror style <info:/foo/bar baz>.
  7267. ;; Must come before " Gnus home-grown style".
  7268. ("\\binfo://?\\([^'\">\n\t]+\\)"
  7269. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
  7270. ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
  7271. ("\\binfo://\\([^'\">\n\t ]+\\)"
  7272. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
  7273. ;; Info GNOME style <info:foo#bar_baz>
  7274. ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
  7275. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
  7276. ;; Info KDE style <info:(foo)bar baz>
  7277. ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
  7278. 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
  7279. ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
  7280. (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
  7281. ("\\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,]*\\)\\)?"
  7282. ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
  7283. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
  7284. ;; This is custom
  7285. ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
  7286. (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
  7287. ;; Emacs help commands
  7288. ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7289. ;; regexp doesn't match arguments containing ` '.
  7290. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
  7291. ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7292. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
  7293. ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7294. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
  7295. ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7296. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
  7297. ;; The following entries may lead to many false positives so don't enable
  7298. ;; them by default (use a high button level).
  7299. ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
  7300. ;; Exclude [.?] for URLs in gmane.emacs.cvs
  7301. 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
  7302. ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
  7303. 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
  7304. ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
  7305. 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
  7306. ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
  7307. 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
  7308. ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
  7309. 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
  7310. ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7311. 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
  7312. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7313. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
  7314. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7315. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
  7316. ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
  7317. ;; Unlike the other regexps we really have to require quoting
  7318. ;; here to determine where it ends.
  7319. 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
  7320. ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
  7321. ("<URL: *\\([^\n<>]*\\)>"
  7322. 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
  7323. ;; RFC 2396 (2.4.3., delims) ...
  7324. ("\"URL: *\\([^\n\"]*\\)\""
  7325. 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
  7326. ;; Raw URLs.
  7327. (gnus-button-url-regexp
  7328. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7329. ;; man pages
  7330. ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
  7331. 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
  7332. gnus-button-handle-man 1)
  7333. ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
  7334. ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
  7335. 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
  7336. gnus-button-handle-man 1)
  7337. ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
  7338. ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
  7339. ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
  7340. 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
  7341. ;; Recognizing patches to .el files. This is somewhat obscure,
  7342. ;; but considering the percentage of Gnus users who hack Emacs
  7343. ;; Lisp files...
  7344. ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
  7345. (>= gnus-button-message-level 4) gnus-button-patch 1 2)
  7346. ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
  7347. (>= gnus-button-message-level 4) gnus-button-patch 1 2)
  7348. ;; MID or mail: To avoid too many false positives we don't try to catch
  7349. ;; all kind of allowed MIDs or mail addresses. Domain part must contain
  7350. ;; at least one dot. TLD must contain two or three chars or be a know TLD
  7351. ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
  7352. ;; so that non-ambiguous entries (see above) match first.
  7353. (gnus-button-mid-or-mail-regexp
  7354. 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
  7355. "*Alist of regexps matching buttons in article bodies.
  7356. Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
  7357. REGEXP: is the string (case insensitive) matching text around the button (can
  7358. also be Lisp expression evaluating to a string),
  7359. BUTTON: is the number of the regexp grouping actually matching the button,
  7360. FORM: is a Lisp expression which must eval to true for the button to
  7361. be added,
  7362. CALLBACK: is the function to call when the user push this button, and each
  7363. PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
  7364. CALLBACK can also be a variable, in that case the value of that
  7365. variable it the real callback function."
  7366. :group 'gnus-article-buttons
  7367. :type '(repeat (list (choice regexp variable sexp)
  7368. (integer :tag "Button")
  7369. (sexp :tag "Form")
  7370. (function :tag "Callback")
  7371. (repeat :tag "Par"
  7372. :inline t
  7373. (integer :tag "Regexp group")))))
  7374. (put 'gnus-button-alist 'risky-local-variable t)
  7375. (defcustom gnus-header-button-alist
  7376. '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
  7377. 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
  7378. ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
  7379. 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
  7380. ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
  7381. 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
  7382. ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
  7383. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7384. ("^Subject:" gnus-button-url-regexp
  7385. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7386. ("^[^:]+:" gnus-button-url-regexp
  7387. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7388. ("^OpenPGP:.*url=" gnus-button-url-regexp
  7389. 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
  7390. ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
  7391. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  7392. ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
  7393. 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
  7394. "*Alist of headers and regexps to match buttons in article heads.
  7395. This alist is very similar to `gnus-button-alist', except that each
  7396. alist has an additional HEADER element first in each entry:
  7397. \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
  7398. HEADER is a regexp to match a header. For a fuller explanation, see
  7399. `gnus-button-alist'."
  7400. :group 'gnus-article-buttons
  7401. :group 'gnus-article-headers
  7402. :type '(repeat (list (regexp :tag "Header")
  7403. (choice regexp variable)
  7404. (integer :tag "Button")
  7405. (sexp :tag "Form")
  7406. (function :tag "Callback")
  7407. (repeat :tag "Par"
  7408. :inline t
  7409. (integer :tag "Regexp group")))))
  7410. (put 'gnus-header-button-alist 'risky-local-variable t)
  7411. ;;; Commands:
  7412. (defun gnus-article-push-button (event)
  7413. "Check text under the mouse pointer for a callback function.
  7414. If the text under the mouse pointer has a `gnus-callback' property,
  7415. call it with the value of the `gnus-data' text property."
  7416. (interactive "e")
  7417. (set-buffer (window-buffer (posn-window (event-start event))))
  7418. (let* ((pos (posn-point (event-start event)))
  7419. (data (get-text-property pos 'gnus-data))
  7420. (fun (get-text-property pos 'gnus-callback)))
  7421. (goto-char pos)
  7422. (when fun
  7423. (funcall fun data))))
  7424. (defun gnus-article-press-button ()
  7425. "Check text at point for a callback function.
  7426. If the text at point has a `gnus-callback' property,
  7427. call it with the value of the `gnus-data' text property."
  7428. (interactive)
  7429. (let ((data (get-text-property (point) 'gnus-data))
  7430. (fun (get-text-property (point) 'gnus-callback)))
  7431. (when fun
  7432. (funcall fun data))))
  7433. (defun gnus-article-highlight (&optional force)
  7434. "Highlight current article.
  7435. This function calls `gnus-article-highlight-headers',
  7436. `gnus-article-highlight-citation',
  7437. `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
  7438. do the highlighting. See the documentation for those functions."
  7439. (interactive (list 'force))
  7440. (gnus-article-highlight-headers)
  7441. (gnus-article-highlight-citation force)
  7442. (gnus-article-highlight-signature)
  7443. (gnus-article-add-buttons)
  7444. (gnus-article-add-buttons-to-head))
  7445. (defun gnus-article-highlight-some (&optional _force)
  7446. "Highlight current article.
  7447. This function calls `gnus-article-highlight-headers',
  7448. `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
  7449. do the highlighting. See the documentation for those functions."
  7450. (interactive (list 'force))
  7451. (gnus-article-highlight-headers)
  7452. (gnus-article-highlight-signature)
  7453. (gnus-article-add-buttons))
  7454. (defun gnus-article-highlight-headers ()
  7455. "Highlight article headers as specified by `gnus-header-face-alist'."
  7456. (interactive)
  7457. (gnus-with-article-headers
  7458. (let (regexp header-face field-face from hpoints fpoints)
  7459. (dolist (entry gnus-header-face-alist)
  7460. (goto-char (point-min))
  7461. (setq regexp (concat "^\\("
  7462. (if (string-equal "" (nth 0 entry))
  7463. "[^\t ]"
  7464. (nth 0 entry))
  7465. "\\)")
  7466. header-face (nth 1 entry)
  7467. field-face (nth 2 entry))
  7468. (while (and (re-search-forward regexp nil t)
  7469. (not (eobp)))
  7470. (beginning-of-line)
  7471. (setq from (point))
  7472. (unless (search-forward ":" nil t)
  7473. (forward-char 1))
  7474. (when (and header-face
  7475. (not (memq (point) hpoints)))
  7476. (push (point) hpoints)
  7477. (gnus-put-text-property from (point) 'face header-face))
  7478. (when (and field-face
  7479. (not (memq (setq from (point)) fpoints)))
  7480. (push from fpoints)
  7481. (if (re-search-forward "^[^ \t]" nil t)
  7482. (forward-char -2)
  7483. (goto-char (point-max)))
  7484. (gnus-put-text-property from (point) 'face field-face)))))))
  7485. (defun gnus-article-highlight-signature ()
  7486. "Highlight the signature in an article.
  7487. It does this by highlighting everything after
  7488. `gnus-signature-separator' using the face `gnus-signature'."
  7489. (interactive)
  7490. (gnus-with-article-buffer
  7491. (let ((inhibit-point-motion-hooks t))
  7492. (save-restriction
  7493. (when (and gnus-signature-face
  7494. (gnus-article-narrow-to-signature))
  7495. (overlay-put (make-overlay (point-min) (point-max) nil t)
  7496. 'face gnus-signature-face)
  7497. (widen)
  7498. (gnus-article-search-signature)
  7499. (let ((start (match-beginning 0))
  7500. (end (set-marker (make-marker) (1+ (match-end 0)))))
  7501. (gnus-article-add-button start (1- end) 'gnus-signature-toggle
  7502. end)))))))
  7503. (defun gnus-button-in-region-p (b e prop)
  7504. "Say whether PROP exists in the region."
  7505. (text-property-not-all b e prop nil))
  7506. (defun gnus-article-add-buttons ()
  7507. "Find external references in the article and make buttons of them.
  7508. \"External references\" are things like Message-IDs and URLs, as
  7509. specified by `gnus-button-alist'."
  7510. (interactive)
  7511. (gnus-with-article-buffer
  7512. (let ((inhibit-point-motion-hooks t)
  7513. (case-fold-search t)
  7514. (alist gnus-button-alist)
  7515. beg entry regexp)
  7516. ;; We skip the headers.
  7517. (article-goto-body)
  7518. (setq beg (point))
  7519. (while (setq entry (pop alist))
  7520. (setq regexp (eval (car entry)))
  7521. (goto-char beg)
  7522. (while (re-search-forward regexp nil t)
  7523. (let ((start (match-beginning (nth 1 entry)))
  7524. (end (match-end (nth 1 entry)))
  7525. (from (match-beginning 0)))
  7526. (when (and (eval (nth 2 entry))
  7527. (not (gnus-button-in-region-p
  7528. start end 'gnus-callback)))
  7529. ;; That optional form returned non-nil, so we add the
  7530. ;; button.
  7531. (setq from (set-marker (make-marker) from))
  7532. (unless (and (eq (car entry) 'gnus-button-url-regexp)
  7533. (gnus-article-extend-url-button from start end))
  7534. (gnus-article-add-button start end
  7535. 'gnus-button-push (list from entry))
  7536. (gnus-put-text-property
  7537. start end
  7538. 'gnus-string (buffer-substring-no-properties
  7539. start end))))))))))
  7540. (defun gnus-article-extend-url-button (beg start end)
  7541. "Extend url button if url is folded into two or more lines.
  7542. Return non-nil if button is extended. BEG is a marker that points to
  7543. the beginning position of a text containing url. START and END are
  7544. the endpoints of a url button before it is extended. The concatenated
  7545. url is put as the `gnus-button-url' overlay property on the button."
  7546. (let ((opoint (point))
  7547. (points (list start end))
  7548. url delim regexp)
  7549. (prog1
  7550. (when (and (progn
  7551. (goto-char end)
  7552. (not (looking-at "[\t ]*[\">]")))
  7553. (progn
  7554. (goto-char start)
  7555. (string-match
  7556. "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
  7557. (buffer-substring (point-at-bol) start)))
  7558. (progn
  7559. (setq url (list (buffer-substring start end))
  7560. delim (if (match-beginning 1) ">" "\""))
  7561. (beginning-of-line)
  7562. (setq regexp (concat
  7563. (when (and (looking-at
  7564. message-cite-prefix-regexp)
  7565. (< (match-end 0) start))
  7566. (regexp-quote (match-string 0)))
  7567. "\
  7568. [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
  7569. delim "\\)"))
  7570. (while (progn
  7571. (forward-line 1)
  7572. (and (looking-at regexp)
  7573. (prog1
  7574. (match-beginning 1)
  7575. (push (or (match-string 2)
  7576. (match-string 1))
  7577. url)
  7578. (push (setq end (or (match-end 2)
  7579. (match-end 1)))
  7580. points)
  7581. (push (or (match-beginning 2)
  7582. (match-beginning 1))
  7583. points)))))
  7584. (match-beginning 2)))
  7585. (let (gnus-article-mouse-face widget-mouse-face)
  7586. (while points
  7587. (gnus-article-add-button (pop points) (pop points)
  7588. 'gnus-button-push
  7589. (list beg (assq 'gnus-button-url-regexp
  7590. gnus-button-alist)))))
  7591. (let ((overlay (make-overlay start end)))
  7592. (overlay-put overlay 'evaporate t)
  7593. (overlay-put overlay 'gnus-button-url
  7594. (list (mapconcat 'identity (nreverse url) "")))
  7595. (when gnus-article-mouse-face
  7596. (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
  7597. t)
  7598. (goto-char opoint))))
  7599. ;; Add buttons to the head of an article.
  7600. (defun gnus-article-add-buttons-to-head ()
  7601. "Add buttons to the head of the article."
  7602. (interactive)
  7603. (gnus-with-article-headers
  7604. (let (beg end)
  7605. (dolist (entry gnus-header-button-alist)
  7606. ;; Each alist entry.
  7607. (goto-char (point-min))
  7608. (while (re-search-forward (car entry) nil t)
  7609. ;; Each header matching the entry.
  7610. (setq beg (match-beginning 0))
  7611. (setq end (or (and (re-search-forward "^[^ \t]" nil t)
  7612. (match-beginning 0))
  7613. (point-max)))
  7614. (goto-char beg)
  7615. (while (re-search-forward (eval (nth 1 entry)) end t)
  7616. ;; Each match within a header.
  7617. (let* ((entry (cdr entry))
  7618. (start (match-beginning (nth 1 entry)))
  7619. (end (match-end (nth 1 entry)))
  7620. (form (nth 2 entry)))
  7621. (goto-char (match-end 0))
  7622. (when (eval form)
  7623. (gnus-article-add-button
  7624. start end (nth 3 entry)
  7625. (buffer-substring (match-beginning (nth 4 entry))
  7626. (match-end (nth 4 entry)))))))
  7627. (goto-char end))))))
  7628. ;;; External functions:
  7629. (defun gnus-article-add-button (from to fun &optional data text)
  7630. "Create a button between FROM and TO with callback FUN and data DATA."
  7631. (when gnus-article-button-face
  7632. (overlay-put (make-overlay from to nil t)
  7633. 'face gnus-article-button-face))
  7634. (gnus-add-text-properties
  7635. from to
  7636. (nconc (and gnus-article-mouse-face
  7637. (list gnus-mouse-face-prop gnus-article-mouse-face))
  7638. (list 'gnus-callback fun)
  7639. (and data (list 'gnus-data data))))
  7640. (widget-convert-button 'link from to :action 'gnus-widget-press-button
  7641. :help-echo (or text "Follow the link")
  7642. :keymap gnus-url-button-map
  7643. :button-keymap gnus-widget-button-keymap))
  7644. (defun gnus-article-copy-string ()
  7645. "Copy the string in the button to the kill ring."
  7646. (interactive)
  7647. (gnus-article-check-buffer)
  7648. (let ((data (get-text-property (point) 'gnus-string)))
  7649. (when data
  7650. (with-temp-buffer
  7651. (insert data)
  7652. (copy-region-as-kill (point-min) (point-max))
  7653. (message "Copied %s" data)))))
  7654. ;;; Internal functions:
  7655. (defun gnus-article-set-globals ()
  7656. (with-current-buffer gnus-summary-buffer
  7657. (gnus-set-global-variables)))
  7658. (defun gnus-signature-toggle (end)
  7659. (gnus-with-article-buffer
  7660. (let ((inhibit-point-motion-hooks t))
  7661. (if (text-property-any end (point-max) 'article-type 'signature)
  7662. (progn
  7663. (gnus-delete-wash-type 'signature)
  7664. (gnus-remove-text-properties-when
  7665. 'article-type 'signature end (point-max)
  7666. (cons 'article-type (cons 'signature
  7667. gnus-hidden-properties))))
  7668. (gnus-add-wash-type 'signature)
  7669. (gnus-add-text-properties-when
  7670. 'article-type nil end (point-max)
  7671. (cons 'article-type (cons 'signature
  7672. gnus-hidden-properties)))))
  7673. (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
  7674. (gnus-set-mode-line 'article))))
  7675. (defun gnus-button-push (marker-and-entry)
  7676. ;; Push button starting at MARKER.
  7677. (save-excursion
  7678. (let* ((marker (car marker-and-entry))
  7679. (entry (cadr marker-and-entry))
  7680. (regexp (car entry))
  7681. (inhibit-point-motion-hooks t))
  7682. (goto-char marker)
  7683. ;; This is obviously true, or something bad is happening :)
  7684. ;; But we need it to have the match-data
  7685. (when (looking-at (or (if (symbolp regexp)
  7686. (symbol-value regexp)
  7687. regexp)))
  7688. (let ((fun (nth 3 entry))
  7689. (args (or (and (eq (car entry) 'gnus-button-url-regexp)
  7690. (get-char-property marker 'gnus-button-url))
  7691. (mapcar (lambda (group)
  7692. (let ((string (match-string group)))
  7693. (set-text-properties
  7694. 0 (length string) nil string)
  7695. string))
  7696. (nthcdr 4 entry)))))
  7697. (cond
  7698. ((fboundp fun)
  7699. (apply fun args))
  7700. ((and (boundp fun)
  7701. (fboundp (symbol-value fun)))
  7702. (apply (symbol-value fun) args))
  7703. (t
  7704. (gnus-message 1 "You must define `%S' to use this button"
  7705. (cons fun args)))))))))
  7706. (defun gnus-parse-news-url (url)
  7707. (let (scheme server port group message-id articles)
  7708. (with-temp-buffer
  7709. (insert url)
  7710. (goto-char (point-min))
  7711. (when (looking-at "\\([A-Za-z]+\\):")
  7712. (setq scheme (match-string 1))
  7713. (goto-char (match-end 0)))
  7714. (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
  7715. (setq server (match-string 1))
  7716. (setq port (if (stringp (match-string 3))
  7717. (string-to-number (match-string 3))
  7718. (match-string 3)))
  7719. (goto-char (match-end 0)))
  7720. (cond
  7721. ((looking-at "\\(.*@.*\\)")
  7722. (setq message-id (match-string 1)))
  7723. ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
  7724. (setq group (match-string 1)
  7725. articles (split-string (match-string 2) "-")))
  7726. ((looking-at "\\([^/]+\\)/?")
  7727. (setq group (match-string 1)))
  7728. (t
  7729. (error "Unknown news URL syntax"))))
  7730. (list scheme server port group message-id articles)))
  7731. (defvar nntp-port-number)
  7732. (defun gnus-button-handle-news (url)
  7733. "Fetch a news URL."
  7734. (destructuring-bind (_scheme server port group message-id _articles)
  7735. (gnus-parse-news-url url)
  7736. (cond
  7737. (message-id
  7738. (with-current-buffer gnus-summary-buffer
  7739. (if server
  7740. (let ((gnus-refer-article-method
  7741. (nconc (list (list 'nntp server))
  7742. gnus-refer-article-method))
  7743. (nntp-port-number (or port "nntp")))
  7744. (gnus-message 7 "Fetching %s with %s"
  7745. message-id gnus-refer-article-method)
  7746. (gnus-summary-refer-article message-id))
  7747. (gnus-summary-refer-article message-id))))
  7748. (group
  7749. (gnus-button-fetch-group url)))))
  7750. (defun gnus-button-patch (library line)
  7751. "Visit an Emacs Lisp library LIBRARY on line LINE."
  7752. (interactive)
  7753. (let ((file (locate-library (file-name-nondirectory library))))
  7754. (unless file
  7755. (error "Couldn't find library %s" library))
  7756. (find-file file)
  7757. (goto-char (point-min))
  7758. (forward-line (1- (string-to-number line)))))
  7759. (defun gnus-button-handle-man (url)
  7760. "Fetch a man page."
  7761. (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
  7762. (when (eq gnus-button-man-handler 'woman)
  7763. (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
  7764. (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
  7765. (funcall gnus-button-man-handler url))
  7766. (defun gnus-button-handle-info-url (url)
  7767. "Fetch an info URL."
  7768. (setq url (mm-subst-char-in-string ?+ ?\ url))
  7769. (cond
  7770. ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
  7771. (gnus-info-find-node
  7772. (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
  7773. "Gnus")
  7774. ")" (gnus-url-unhex-string (match-string 2 url)))))
  7775. ((string-match "([^)\"]+)[^\"]+" url)
  7776. (setq url
  7777. (gnus-replace-in-string
  7778. (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
  7779. (gnus-info-find-node url))
  7780. (t (error "Can't parse %s" url))))
  7781. (defun gnus-button-handle-info-url-gnome (url)
  7782. "Fetch GNOME style info URL."
  7783. (setq url (mm-subst-char-in-string ?_ ?\ url))
  7784. (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
  7785. (gnus-info-find-node
  7786. (concat "("
  7787. (gnus-url-unhex-string
  7788. (match-string 1 url))
  7789. ")"
  7790. (or (gnus-url-unhex-string
  7791. (match-string 2 url))
  7792. "Top")))
  7793. (error "Can't parse %s" url)))
  7794. (defun gnus-button-handle-info-url-kde (url)
  7795. "Fetch KDE style info URL."
  7796. (gnus-info-find-node (gnus-url-unhex-string url)))
  7797. ;; (info) will autoload info.el
  7798. (declare-function Info-menu "info" (menu-item &optional fork))
  7799. (declare-function Info-index-next "info" (num))
  7800. (defun gnus-button-handle-info-keystrokes (url)
  7801. "Call `info' when pushing the corresponding URL button."
  7802. ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
  7803. (let (node indx comma)
  7804. (if (string-match
  7805. (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
  7806. "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
  7807. "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
  7808. "\\(?:[ \t\n,]*\\)\\)?")
  7809. url)
  7810. (setq node (match-string 2 url)
  7811. indx (match-string 3 url))
  7812. (error "Can't parse %s" url))
  7813. (info)
  7814. (Info-directory)
  7815. (Info-menu node)
  7816. (when (> (length indx) 0)
  7817. (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
  7818. "\\([ \t\n,]*\\)")
  7819. indx)
  7820. (setq comma (match-string 2 indx))
  7821. (setq indx (match-string 1 indx))
  7822. (Info-index indx)
  7823. (when comma
  7824. (dotimes (i (with-temp-buffer
  7825. (insert comma)
  7826. ;; Note: the XEmacs version of `how-many' takes
  7827. ;; no optional argument.
  7828. (goto-char (point-min))
  7829. (how-many ",")))
  7830. (Info-index-next 1)))
  7831. nil)))
  7832. (autoload 'pgg-snarf-keys-region "pgg")
  7833. ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
  7834. (declare-function pgg-display-output-buffer "pgg" (start end status))
  7835. (defun gnus-button-openpgp (url)
  7836. "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
  7837. (with-temp-buffer
  7838. (mm-url-insert-file-contents-external url)
  7839. (pgg-snarf-keys-region (point-min) (point-max))
  7840. (pgg-display-output-buffer nil nil nil)))
  7841. (defun gnus-button-message-id (message-id)
  7842. "Fetch MESSAGE-ID."
  7843. (with-current-buffer gnus-summary-buffer
  7844. (gnus-summary-refer-article message-id)))
  7845. (defun gnus-button-fetch-group (address &rest _ignore)
  7846. "Fetch GROUP specified by ADDRESS."
  7847. (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
  7848. address)
  7849. ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
  7850. ;; for nntp:// and news://
  7851. (setq address (match-string 3 address)))
  7852. (if (not (string-match "[:/]" address))
  7853. ;; This is just a simple group url.
  7854. (gnus-group-read-ephemeral-group address gnus-select-method)
  7855. (if (not
  7856. (string-match
  7857. "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
  7858. address))
  7859. (error "Can't parse %s" address)
  7860. (gnus-group-read-ephemeral-group
  7861. (match-string 4 address)
  7862. `(nntp ,(match-string 1 address)
  7863. (nntp-address ,(match-string 1 address))
  7864. (nntp-port-number ,(if (match-end 3)
  7865. (match-string 3 address)
  7866. "nntp")))
  7867. nil nil nil
  7868. (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
  7869. (defun gnus-url-parse-query-string (query &optional downcase)
  7870. (let (retval pairs cur key val)
  7871. (setq pairs (split-string query "&"))
  7872. (while pairs
  7873. (setq cur (car pairs)
  7874. pairs (cdr pairs))
  7875. (if (not (string-match "=" cur))
  7876. nil ; Grace
  7877. (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
  7878. val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
  7879. (if downcase
  7880. (setq key (downcase key)))
  7881. (setq cur (assoc key retval))
  7882. (if cur
  7883. (setcdr cur (cons val (cdr cur)))
  7884. (setq retval (cons (list key val) retval)))))
  7885. retval))
  7886. (defun gnus-url-mailto (url)
  7887. ;; Send mail to someone
  7888. (setq url (replace-regexp-in-string "\n" " " url))
  7889. (when (string-match "mailto:/*\\(.*\\)" url)
  7890. (setq url (substring url (match-beginning 1) nil)))
  7891. (let* ((args (gnus-url-parse-query-string
  7892. (if (string-match "^\\?" url)
  7893. (substring url 1)
  7894. (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
  7895. (concat "to=" (match-string 1 url) "&"
  7896. (match-string 2 url))
  7897. (concat "to=" url)))))
  7898. (subject (cdr-safe (assoc "subject" args)))
  7899. func)
  7900. (gnus-msg-mail)
  7901. (while args
  7902. (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
  7903. (if (fboundp func)
  7904. (funcall func)
  7905. (message-position-on-field (caar args)))
  7906. (insert (gnus-replace-in-string
  7907. (mapconcat 'identity (reverse (cdar args)) ", ")
  7908. "\r\n" "\n" t))
  7909. (setq args (cdr args)))
  7910. (if subject
  7911. (message-goto-body)
  7912. (message-goto-subject))))
  7913. (defun gnus-button-embedded-url (address)
  7914. "Activate ADDRESS with `browse-url'."
  7915. (browse-url (gnus-strip-whitespace address)))
  7916. ;;; Next/prev buttons in the article buffer.
  7917. (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
  7918. (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
  7919. (defvar gnus-prev-page-map
  7920. (let ((map (make-sparse-keymap)))
  7921. (define-key map gnus-mouse-2 'gnus-button-prev-page)
  7922. (define-key map "\r" 'gnus-button-prev-page)
  7923. map))
  7924. (defvar gnus-next-page-map
  7925. (let ((map (make-sparse-keymap)))
  7926. (define-key map gnus-mouse-2 'gnus-button-next-page)
  7927. (define-key map "\r" 'gnus-button-next-page)
  7928. map))
  7929. (defun gnus-insert-prev-page-button ()
  7930. (let ((b (point)) e
  7931. (inhibit-read-only t))
  7932. (gnus-eval-format
  7933. gnus-prev-page-line-format nil
  7934. `(keymap ,gnus-prev-page-map
  7935. gnus-prev t
  7936. gnus-callback gnus-article-button-prev-page
  7937. article-type annotation))
  7938. (setq e (if (bolp)
  7939. ;; Exclude a newline.
  7940. (1- (point))
  7941. (point)))
  7942. (when gnus-article-button-face
  7943. (overlay-put (make-overlay b e nil t)
  7944. 'face gnus-article-button-face))
  7945. (widget-convert-button
  7946. 'link b e
  7947. :action 'gnus-button-prev-page
  7948. :button-keymap gnus-prev-page-map)))
  7949. (defun gnus-button-next-page (&optional _args _more-args)
  7950. "Go to the next page."
  7951. (interactive)
  7952. (let ((win (selected-window)))
  7953. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7954. (gnus-article-next-page)
  7955. (select-window win)))
  7956. (defun gnus-button-prev-page (&optional _args _more-args)
  7957. "Go to the prev page."
  7958. (interactive)
  7959. (let ((win (selected-window)))
  7960. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7961. (gnus-article-prev-page)
  7962. (select-window win)))
  7963. (defun gnus-insert-next-page-button ()
  7964. (let ((b (point)) e
  7965. (inhibit-read-only t))
  7966. (gnus-eval-format gnus-next-page-line-format nil
  7967. `(keymap ,gnus-next-page-map
  7968. gnus-next t
  7969. gnus-callback gnus-article-button-next-page
  7970. article-type annotation))
  7971. (setq e (if (bolp)
  7972. ;; Exclude a newline.
  7973. (1- (point))
  7974. (point)))
  7975. (when gnus-article-button-face
  7976. (overlay-put (make-overlay b e nil t)
  7977. 'face gnus-article-button-face))
  7978. (widget-convert-button
  7979. 'link b e
  7980. :action 'gnus-button-next-page
  7981. :button-keymap gnus-next-page-map)))
  7982. (defun gnus-article-button-next-page (_arg)
  7983. "Go to the next page."
  7984. (interactive "P")
  7985. (let ((win (selected-window)))
  7986. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7987. (gnus-article-next-page)
  7988. (select-window win)))
  7989. (defun gnus-article-button-prev-page (_arg)
  7990. "Go to the prev page."
  7991. (interactive "P")
  7992. (let ((win (selected-window)))
  7993. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7994. (gnus-article-prev-page)
  7995. (select-window win)))
  7996. (defvar gnus-decode-header-methods
  7997. '(mail-decode-encoded-word-region)
  7998. "List of methods used to decode headers.
  7999. This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
  8000. is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
  8001. \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
  8002. whose names match REGEXP.
  8003. For example:
  8004. \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
  8005. mail-decode-encoded-word-region
  8006. (\"chinese\" . rfc1843-decode-region))
  8007. ")
  8008. (defvar gnus-decode-header-methods-cache nil)
  8009. (defun gnus-multi-decode-header (start end)
  8010. "Apply the functions from `gnus-encoded-word-methods' that match."
  8011. (unless (and gnus-decode-header-methods-cache
  8012. (eq gnus-newsgroup-name
  8013. (car gnus-decode-header-methods-cache)))
  8014. (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
  8015. (dolist (x gnus-decode-header-methods)
  8016. (if (symbolp x)
  8017. (nconc gnus-decode-header-methods-cache (list x))
  8018. (if (and gnus-newsgroup-name
  8019. (string-match (car x) gnus-newsgroup-name))
  8020. (nconc gnus-decode-header-methods-cache
  8021. (list (cdr x)))))))
  8022. (let ((xlist gnus-decode-header-methods-cache))
  8023. (pop xlist)
  8024. (save-restriction
  8025. (narrow-to-region start end)
  8026. (while xlist
  8027. (funcall (pop xlist) (point-min) (point-max))))))
  8028. ;;;
  8029. ;;; Treatment top-level handling.
  8030. ;;;
  8031. (defvar gnus-inhibit-article-treatments nil)
  8032. ;; Dynamic variables.
  8033. (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
  8034. (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
  8035. (defvar gnus-treat-type)
  8036. (defvar gnus-treat-condition)
  8037. (defvar gnus-treat-length)
  8038. (defun gnus-treat-article (condition
  8039. &optional part-num total type)
  8040. (let ((gnus-treat-condition condition)
  8041. (part-number part-num)
  8042. (total-parts total)
  8043. (gnus-treat-type type)
  8044. (gnus-treat-length (- (point-max) (point-min)))
  8045. (alist gnus-treatment-function-alist)
  8046. (article-goto-body-goes-to-point-min-p t)
  8047. (treated-type
  8048. (or (not type)
  8049. (catch 'found
  8050. (let ((list gnus-article-treat-types))
  8051. (while list
  8052. (when (string-match (pop list) type)
  8053. (throw 'found t)))))))
  8054. (highlightp (gnus-visual-p 'article-highlight 'highlight))
  8055. val)
  8056. (gnus-run-hooks 'gnus-part-display-hook)
  8057. (dolist (elem alist)
  8058. (setq val
  8059. (save-excursion
  8060. (when (gnus-buffer-live-p gnus-summary-buffer)
  8061. (set-buffer gnus-summary-buffer))
  8062. (symbol-value (car elem))))
  8063. (when (and (or (consp val)
  8064. treated-type)
  8065. (or (not gnus-inhibit-article-treatments)
  8066. (eq gnus-treat-condition 'head))
  8067. (gnus-treat-predicate val)
  8068. (or (not (get (car elem) 'highlight))
  8069. highlightp))
  8070. (save-restriction
  8071. (funcall (cadr elem)))))))
  8072. (defun gnus-treat-predicate (val)
  8073. (cond
  8074. ((null val)
  8075. nil)
  8076. (gnus-treat-condition
  8077. (eq gnus-treat-condition val))
  8078. ((and (listp val)
  8079. (stringp (car val)))
  8080. (apply 'gnus-or (mapcar `(lambda (s)
  8081. (string-match s ,(or gnus-newsgroup-name "")))
  8082. val)))
  8083. ((listp val)
  8084. (let ((pred (pop val)))
  8085. (cond
  8086. ((eq pred 'or)
  8087. (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
  8088. ((eq pred 'and)
  8089. (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
  8090. ((eq pred 'not)
  8091. (not (gnus-treat-predicate (car val))))
  8092. ((eq pred 'typep)
  8093. (equal (car val) gnus-treat-type))
  8094. ((functionp pred)
  8095. (funcall pred))
  8096. (t
  8097. (error "%S is not a valid predicate" pred)))))
  8098. ((eq val t)
  8099. t)
  8100. ((eq val 'head)
  8101. nil)
  8102. ((eq val 'first)
  8103. (eq part-number 1))
  8104. ((eq val 'last)
  8105. (eq part-number total-parts))
  8106. ((numberp val)
  8107. (< gnus-treat-length val))
  8108. (t
  8109. (error "%S is not a valid value" val))))
  8110. (defun gnus-article-encrypt-body (protocol &optional n)
  8111. "Encrypt the article body."
  8112. (interactive
  8113. (list
  8114. (or gnus-article-encrypt-protocol
  8115. (gnus-completing-read "Encrypt protocol"
  8116. (mapcar 'car gnus-article-encrypt-protocol-alist)
  8117. t))
  8118. current-prefix-arg))
  8119. ;; User might hit `K E' instead of `K e', so prompt once.
  8120. (when (and gnus-article-encrypt-protocol
  8121. gnus-novice-user)
  8122. (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
  8123. (error "Encrypt aborted")))
  8124. (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
  8125. (unless func
  8126. (error "Can't find the encrypt protocol %s" protocol))
  8127. (if (member gnus-newsgroup-name '("nndraft:delayed"
  8128. "nndraft:drafts"
  8129. "nndraft:queue"))
  8130. (error "Can't encrypt the article in group %s"
  8131. gnus-newsgroup-name))
  8132. (gnus-summary-iterate n
  8133. (with-current-buffer gnus-summary-buffer
  8134. (let ((mail-parse-charset gnus-newsgroup-charset)
  8135. (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
  8136. (summary-buffer gnus-summary-buffer)
  8137. references point)
  8138. (gnus-set-global-variables)
  8139. (when (gnus-group-read-only-p)
  8140. (error "The current newsgroup does not support article encrypt"))
  8141. (gnus-summary-show-article t)
  8142. (setq references
  8143. (or (mail-header-references gnus-current-headers) ""))
  8144. (set-buffer gnus-article-buffer)
  8145. (let* ((inhibit-read-only t)
  8146. (headers
  8147. (mapcar (lambda (field)
  8148. (and (save-restriction
  8149. (message-narrow-to-head)
  8150. (goto-char (point-min))
  8151. (search-forward field nil t))
  8152. (prog2
  8153. (message-narrow-to-field)
  8154. (buffer-string)
  8155. (delete-region (point-min) (point-max))
  8156. (widen))))
  8157. '("Content-Type:" "Content-Transfer-Encoding:"
  8158. "Content-Disposition:"))))
  8159. (message-narrow-to-head)
  8160. (message-remove-header "MIME-Version")
  8161. (goto-char (point-max))
  8162. (setq point (point))
  8163. (insert (apply 'concat headers))
  8164. (widen)
  8165. (narrow-to-region point (point-max))
  8166. (let ((message-options message-options))
  8167. (message-options-set 'message-sender user-mail-address)
  8168. (message-options-set 'message-recipients user-mail-address)
  8169. (message-options-set 'message-sign-encrypt 'not)
  8170. (funcall func))
  8171. (goto-char (point-min))
  8172. (insert "MIME-Version: 1.0\n")
  8173. (widen)
  8174. (gnus-summary-edit-article-done
  8175. references nil summary-buffer t))
  8176. (when gnus-keep-backlog
  8177. (gnus-backlog-remove-article
  8178. (car gnus-article-current) (cdr gnus-article-current)))
  8179. (gnus-flush-original-article-buffer)
  8180. (when gnus-use-cache
  8181. (gnus-cache-update-article
  8182. (car gnus-article-current) (cdr gnus-article-current))))))))
  8183. (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
  8184. "The following specs can be used:
  8185. %t The security MIME type
  8186. %i Additional info
  8187. %d Details
  8188. %D Details if button is pressed")
  8189. (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
  8190. "The following specs can be used:
  8191. %t The security MIME type
  8192. %i Additional info
  8193. %d Details
  8194. %D Details if button is pressed")
  8195. (defvar gnus-mime-security-button-line-format-alist
  8196. '((?t gnus-tmp-type ?s)
  8197. (?i gnus-tmp-info ?s)
  8198. (?d gnus-tmp-details ?s)
  8199. (?D gnus-tmp-pressed-details ?s)))
  8200. (defvar gnus-mime-security-button-commands
  8201. '((gnus-article-press-button "\r" "Show Detail")
  8202. (undefined "v")
  8203. (undefined "t")
  8204. (undefined "C")
  8205. (gnus-mime-security-save-part "o" "Save...")
  8206. (undefined "\C-o")
  8207. (undefined "r")
  8208. (undefined "d")
  8209. (undefined "c")
  8210. (undefined "i")
  8211. (undefined "E")
  8212. (undefined "e")
  8213. (undefined "p")
  8214. (gnus-mime-security-pipe-part "|" "Pipe To Command...")
  8215. (undefined ".")))
  8216. (defvar gnus-mime-security-button-map
  8217. (let ((map (make-sparse-keymap)))
  8218. (define-key map gnus-mouse-2 'gnus-article-push-button)
  8219. (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
  8220. (dolist (c gnus-mime-security-button-commands)
  8221. (define-key map (cadr c) (car c)))
  8222. map))
  8223. (easy-menu-define
  8224. gnus-mime-security-button-menu gnus-mime-security-button-map
  8225. "Security button menu."
  8226. `("Security Part"
  8227. ,@(delq nil
  8228. (mapcar (lambda (c)
  8229. (unless (eq (car c) 'undefined)
  8230. (vector (caddr c) (car c) :active t)))
  8231. gnus-mime-security-button-commands))))
  8232. (defun gnus-mime-security-button-menu (event prefix)
  8233. "Construct a context-sensitive menu of security commands."
  8234. (interactive "e\nP")
  8235. (save-window-excursion
  8236. (let ((pos (event-start event)))
  8237. (select-window (posn-window pos))
  8238. (goto-char (posn-point pos))
  8239. (gnus-article-check-buffer)
  8240. (popup-menu gnus-mime-security-button-menu nil prefix))))
  8241. (defvar gnus-mime-security-details-buffer nil)
  8242. (defvar gnus-mime-security-button-pressed nil)
  8243. (defvar gnus-mime-security-show-details-inline t
  8244. "If non-nil, show details in the article buffer.")
  8245. (defun gnus-mime-security-verify-or-decrypt (handle)
  8246. (mm-remove-parts (cdr handle))
  8247. (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
  8248. point (inhibit-read-only t))
  8249. (if region
  8250. (goto-char (car region)))
  8251. (setq point (point))
  8252. (with-current-buffer (mm-handle-multipart-original-buffer handle)
  8253. (let* ((mm-verify-option 'known)
  8254. (mm-decrypt-option 'known)
  8255. (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
  8256. (unless (eq nparts (cdr handle))
  8257. (mm-destroy-parts (cdr handle))
  8258. (setcdr handle nparts))))
  8259. (gnus-mime-display-security handle)
  8260. (when region
  8261. (delete-region (point) (cdr region))
  8262. (set-marker (car region) nil)
  8263. (set-marker (cdr region) nil))
  8264. (goto-char point)))
  8265. (defun gnus-mime-security-show-details (handle)
  8266. (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
  8267. (if (not details)
  8268. (gnus-message 5 "No details.")
  8269. (if gnus-mime-security-show-details-inline
  8270. (let ((gnus-mime-security-button-pressed
  8271. (not (get-text-property (point) 'gnus-mime-details)))
  8272. (gnus-mime-security-button-line-format
  8273. (get-text-property (point) 'gnus-line-format))
  8274. (inhibit-read-only t))
  8275. (forward-char -1)
  8276. (while (eq (get-text-property (point) 'gnus-line-format)
  8277. gnus-mime-security-button-line-format)
  8278. (forward-char -1))
  8279. (forward-char)
  8280. (save-restriction
  8281. (narrow-to-region (point) (point))
  8282. (gnus-insert-mime-security-button handle))
  8283. (delete-region (point)
  8284. (or (text-property-not-all
  8285. (point) (point-max)
  8286. 'gnus-line-format
  8287. gnus-mime-security-button-line-format)
  8288. (point-max))))
  8289. ;; Not inlined.
  8290. (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
  8291. (with-current-buffer gnus-mime-security-details-buffer
  8292. (erase-buffer)
  8293. t)
  8294. (setq gnus-mime-security-details-buffer
  8295. (gnus-get-buffer-create "*MIME Security Details*")))
  8296. (with-current-buffer gnus-mime-security-details-buffer
  8297. (insert details)
  8298. (goto-char (point-min)))
  8299. (pop-to-buffer gnus-mime-security-details-buffer)))))
  8300. (defun gnus-mime-security-press-button (handle)
  8301. (save-excursion
  8302. (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
  8303. (gnus-mime-security-show-details handle)
  8304. (gnus-mime-security-verify-or-decrypt handle))))
  8305. (defun gnus-insert-mime-security-button (handle &optional _displayed)
  8306. (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
  8307. (gnus-tmp-type
  8308. (concat
  8309. (or (nth 2 (assoc protocol mm-verify-function-alist))
  8310. (nth 2 (assoc protocol mm-decrypt-function-alist))
  8311. "Unknown")
  8312. (if (equal (car handle) "multipart/signed")
  8313. " Signed" " Encrypted")
  8314. " Part"))
  8315. (gnus-tmp-info
  8316. (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
  8317. "Undecided"))
  8318. (gnus-tmp-details
  8319. (mm-handle-multipart-ctl-parameter handle 'gnus-details))
  8320. gnus-tmp-pressed-details
  8321. b e)
  8322. (setq gnus-tmp-details
  8323. (if gnus-tmp-details
  8324. (concat "\n" gnus-tmp-details)
  8325. ""))
  8326. (setq gnus-tmp-pressed-details
  8327. (if gnus-mime-security-button-pressed gnus-tmp-details ""))
  8328. (unless (bolp)
  8329. (insert "\n"))
  8330. (setq b (point))
  8331. (gnus-eval-format
  8332. gnus-mime-security-button-line-format
  8333. gnus-mime-security-button-line-format-alist
  8334. `(keymap ,gnus-mime-security-button-map
  8335. gnus-callback gnus-mime-security-press-button
  8336. gnus-line-format ,gnus-mime-security-button-line-format
  8337. gnus-mime-details ,gnus-mime-security-button-pressed
  8338. article-type annotation
  8339. gnus-data ,handle))
  8340. (setq e (if (bolp)
  8341. ;; Exclude a newline.
  8342. (1- (point))
  8343. (point)))
  8344. (when gnus-article-button-face
  8345. (overlay-put (make-overlay b e nil t)
  8346. 'face gnus-article-button-face))
  8347. (widget-convert-button
  8348. 'link b e
  8349. :mime-handle handle
  8350. :action 'gnus-widget-press-button
  8351. :button-keymap gnus-mime-security-button-map
  8352. :help-echo
  8353. (lambda (_widget)
  8354. ;; Needed to properly clear the message due to a bug in
  8355. ;; wid-edit (XEmacs only).
  8356. (when (boundp 'help-echo-owns-message)
  8357. (setq help-echo-owns-message t))
  8358. (format
  8359. "%S: show detail; %S: more options"
  8360. (aref gnus-mouse-2 0)
  8361. (aref gnus-down-mouse-3 0))))))
  8362. (defun gnus-mime-display-security (handle)
  8363. (save-restriction
  8364. (narrow-to-region (point) (point))
  8365. (unless (gnus-unbuttonized-mime-type-p (car handle))
  8366. (gnus-insert-mime-security-button handle))
  8367. (gnus-mime-display-part (cadr handle))
  8368. (unless (bolp)
  8369. (insert "\n"))
  8370. (unless (gnus-unbuttonized-mime-type-p (car handle))
  8371. (let ((gnus-mime-security-button-line-format
  8372. gnus-mime-security-button-end-line-format))
  8373. (gnus-insert-mime-security-button handle)))
  8374. (mm-set-handle-multipart-parameter
  8375. handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
  8376. (goto-char (point-max))))
  8377. (defun gnus-mime-security-run-function (function)
  8378. "Run FUNCTION with the security part under point."
  8379. (gnus-article-check-buffer)
  8380. (let ((data (get-text-property (point) 'gnus-data))
  8381. buffer handle)
  8382. (when (and (stringp (car-safe data))
  8383. (setq buffer (mm-handle-multipart-original-buffer data))
  8384. (setq handle (cadr data)))
  8385. (if (bufferp (mm-handle-buffer handle))
  8386. (progn
  8387. (setq handle (cons buffer (copy-sequence (cdr handle))))
  8388. (mm-handle-set-undisplayer handle nil))
  8389. (setq handle (mm-make-handle
  8390. buffer
  8391. (mm-handle-multipart-ctl-parameter handle 'protocol)
  8392. nil nil nil nil nil nil)))
  8393. (funcall function handle))))
  8394. (defun gnus-mime-security-save-part ()
  8395. "Save the security part under point."
  8396. (interactive)
  8397. (gnus-mime-security-run-function 'mm-save-part))
  8398. (defun gnus-mime-security-pipe-part ()
  8399. "Pipe the security part under point to a process."
  8400. (interactive)
  8401. (gnus-mime-security-run-function 'mm-pipe-part))
  8402. (gnus-ems-redefine)
  8403. (provide 'gnus-art)
  8404. (run-hooks 'gnus-art-load-hook)
  8405. ;;; gnus-art.el ends here