]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
gnus-replace-in-string -> replace-regexp-in-string
[gnu-emacs] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
31
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
45
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
53 (autoload 'url-expand-file-name "url-expand")
54
55 (defgroup gnus-article nil
56 "Article display."
57 :link '(custom-manual "(gnus)Article Buffer")
58 :group 'gnus)
59
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
63 :group 'gnus-article)
64
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
68 :group 'gnus-article)
69
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
73 :group 'gnus-article
74 :group 'gnus-visual)
75
76 (defgroup gnus-article-signature nil
77 "Article signatures."
78 :link '(custom-manual "(gnus)Article Signature")
79 :group 'gnus-article)
80
81 (defgroup gnus-article-headers nil
82 "Article headers."
83 :link '(custom-manual "(gnus)Hiding Headers")
84 :group 'gnus-article)
85
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
89 :group 'gnus-article)
90
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
94 :group 'gnus-article)
95
96 (defgroup gnus-article-saving nil
97 "Saving articles."
98 :link '(custom-manual "(gnus)Saving Articles")
99 :group 'gnus-article)
100
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
105
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
110
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
115
116 (defcustom gnus-ignored-headers
117 (mapcar
118 (lambda (header)
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
165 (repeat regexp))
166 :group 'gnus-article-hiding)
167
168 (defcustom gnus-visible-headers
169 "^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:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
173 :type '(choice
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
177 (or (stringp value)
178 (widget-editable-list-match widget value)))
179 regexp)
180 (const :tag "Use gnus-ignored-headers" nil)
181 regexp)
182 :group 'gnus-article-hiding)
183
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
190 this list."
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
193
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
197
198 `empty' Headers with no content.
199 `newsgroups' Newsgroup identical to Gnus group.
200 `to-address' To identical to To-address.
201 `to-list' To identical to To-list.
202 `cc-list' CC identical to To-list.
203 `followup-to' Followup-to identical to Newsgroups.
204 `reply-to' Reply-to identical to From.
205 `date' Date less than four days old.
206 `long-to' To and/or Cc longer than 1024 characters.
207 `many-to' Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
219
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
226 :version "22.1"
227 :type 'boolean
228 :group 'gnus-article-hiding)
229
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
236 (regexp)
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
239
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
248
249 This can also be a list of the above values."
250 :type '(choice (const nil)
251 (integer :value 200)
252 (number :value 4.0)
253 function
254 (regexp :value ".*"))
255 :group 'gnus-article-signature)
256
257 (defcustom gnus-hidden-properties
258 ;; We use to have `intangible' here as well, but Emacs's command loop moves
259 ;; point out of invisible text anyway, so `intangible' is clearly not
260 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
261 '(invisible t)
262 "Property list to use for hiding text."
263 :type 'plist
264 :group 'gnus-article-hiding)
265
266 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
267 ;; frames in a session.
268 (defcustom gnus-article-x-face-command
269 (if (gnus-image-type-available-p 'pbm)
270 'gnus-display-x-face-in-from
271 "{ echo \
272 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
273 ; uncompface; } | icontopbm | display -")
274 "*String or function to be executed to display an X-Face header.
275 If it is a string, the command will be executed in a sub-shell
276 asynchronously. The compressed face will be piped to this command."
277 :type `(choice string
278 (function-item gnus-display-x-face-in-from)
279 function)
280 :version "21.1"
281 :group 'gnus-picon
282 :group 'gnus-article-washing)
283
284 (defcustom gnus-article-x-face-too-ugly nil
285 "Regexp matching posters whose face shouldn't be shown automatically."
286 :type '(choice regexp (const nil))
287 :group 'gnus-article-washing)
288
289 (defcustom gnus-article-banner-alist nil
290 "Banner alist for stripping.
291 For example,
292 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
293 :version "21.1"
294 :type '(repeat (cons symbol regexp))
295 :group 'gnus-article-washing)
296
297 (gnus-define-group-parameter
298 banner
299 :variable-document
300 "Alist of regexps (to match group names) and banner."
301 :variable-group gnus-article-washing
302 :parameter-type
303 '(choice :tag "Banner"
304 :value nil
305 (const :tag "Remove signature" signature)
306 (symbol :tag "Item in `gnus-article-banner-alist'" none)
307 regexp
308 (const :tag "None" nil))
309 :parameter-document
310 "If non-nil, specify how to remove `banners' from articles.
311
312 Symbol `signature' means to remove signatures delimited by
313 `gnus-signature-separator'. Any other symbol is used to look up a
314 regular expression to match the banner in `gnus-article-banner-alist'.
315 A string is used as a regular expression to match the banner
316 directly.")
317
318 (defcustom gnus-article-address-banner-alist nil
319 "Alist of mail addresses and banners.
320 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
321 to match a mail address in the From: header, BANNER is one of a symbol
322 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
323 If ADDRESS matches author's mail address, it will remove things like
324 advertisements. For example:
325
326 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
327 "
328 :type '(repeat
329 (cons
330 (regexp :tag "Address")
331 (choice :tag "Banner" :value nil
332 (const :tag "Remove signature" signature)
333 (symbol :tag "Item in `gnus-article-banner-alist'" none)
334 regexp
335 (const :tag "None" nil))))
336 :version "22.1"
337 :group 'gnus-article-washing)
338
339 (defmacro gnus-emphasis-custom-with-format (&rest body)
340 `(let ((format "\
341 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
342 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
343 ,@body))
344
345 (defun gnus-emphasis-custom-value-to-external (value)
346 (gnus-emphasis-custom-with-format
347 (if (consp (car value))
348 (list (format format (car (car value)) (cdr (car value)))
349 2
350 (if (nth 1 value) 2 3)
351 (nth 2 value))
352 value)))
353
354 (defun gnus-emphasis-custom-value-to-internal (value)
355 (gnus-emphasis-custom-with-format
356 (let ((regexp (concat "\\`"
357 (format (regexp-quote format)
358 "\\([^()]+\\)" "\\([^()]+\\)")
359 "\\'"))
360 pattern)
361 (if (string-match regexp (setq pattern (car value)))
362 (list (cons (match-string 1 pattern) (match-string 2 pattern))
363 (= (nth 2 value) 2)
364 (nth 3 value))
365 value))))
366
367 (defcustom gnus-emphasis-alist
368 (let ((types
369 '(("\\*" "\\*" bold nil 2)
370 ("_" "_" underline)
371 ("/" "/" italic)
372 ("_/" "/_" underline-italic)
373 ("_\\*" "\\*_" underline-bold)
374 ("\\*/" "/\\*" bold-italic)
375 ("_\\*/" "/\\*_" underline-bold-italic))))
376 (nconc
377 (gnus-emphasis-custom-with-format
378 (mapcar (lambda (spec)
379 (list (format format (car spec) (cadr spec))
380 (or (nth 3 spec) 2)
381 (or (nth 4 spec) 3)
382 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
383 types))
384 '(;; I've never seen anyone use this strikethru convention whereas I've
385 ;; several times seen it triggered by normal text. --Stef
386 ;; Miles suggests that this form is sometimes used but for italics,
387 ;; so maybe we should map it to `italic'.
388 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
389 ;; 2 3 gnus-emphasis-strikethru)
390 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
391 2 3 gnus-emphasis-underline))))
392 "*Alist that says how to fontify certain phrases.
393 Each item looks like this:
394
395 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
396
397 The first element is a regular expression to be matched. The second
398 is a number that says what regular expression grouping used to find
399 the entire emphasized word. The third is a number that says what
400 regexp grouping should be displayed and highlighted. The fourth
401 is the face used for highlighting."
402 :type
403 '(repeat
404 (menu-choice
405 :format "%[Customizing Style%]\n%v"
406 :indent 2
407 (group :tag "Default"
408 :value ("" 0 0 default)
409 :value-create
410 (lambda (widget)
411 (let ((value (widget-get
412 (cadr (widget-get (widget-get widget :parent)
413 :args))
414 :value)))
415 (if (not (eq (nth 2 value) 'default))
416 (widget-put
417 widget
418 :value
419 (gnus-emphasis-custom-value-to-external value))))
420 (widget-group-value-create widget))
421 regexp
422 (integer :format "Match group: %v")
423 (integer :format "Emphasize group: %v")
424 face)
425 (group :tag "Simple"
426 :value (("_" . "_") nil default)
427 (cons :format "%v"
428 (regexp :format "Start regexp: %v")
429 (regexp :format "End regexp: %v"))
430 (boolean :format "Show start and end patterns: %[%v%]\n"
431 :on " On " :off " Off ")
432 face)))
433 :get (lambda (symbol)
434 (mapcar 'gnus-emphasis-custom-value-to-internal
435 (default-value symbol)))
436 :set (lambda (symbol value)
437 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
438 value)))
439 :group 'gnus-article-emphasis)
440
441 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
442 "A regexp to describe whitespace which should not be emphasized.
443 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
444 The former avoids underlining of leading and trailing whitespace,
445 and the latter avoids underlining any whitespace at all."
446 :version "21.1"
447 :group 'gnus-article-emphasis
448 :type 'regexp)
449
450 (defface gnus-emphasis-bold '((t (:bold t)))
451 "Face used for displaying strong emphasized text (*word*)."
452 :group 'gnus-article-emphasis)
453
454 (defface gnus-emphasis-italic '((t (:italic t)))
455 "Face used for displaying italic emphasized text (/word/)."
456 :group 'gnus-article-emphasis)
457
458 (defface gnus-emphasis-underline '((t (:underline t)))
459 "Face used for displaying underlined emphasized text (_word_)."
460 :group 'gnus-article-emphasis)
461
462 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
463 "Face used for displaying underlined bold emphasized text (_*word*_)."
464 :group 'gnus-article-emphasis)
465
466 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
467 "Face used for displaying underlined italic emphasized text (_/word/_)."
468 :group 'gnus-article-emphasis)
469
470 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
471 "Face used for displaying bold italic emphasized text (/*word*/)."
472 :group 'gnus-article-emphasis)
473
474 (defface gnus-emphasis-underline-bold-italic
475 '((t (:bold t :italic t :underline t)))
476 "Face used for displaying underlined bold italic emphasized text.
477 Example: (_/*word*/_)."
478 :group 'gnus-article-emphasis)
479
480 (defface gnus-emphasis-strikethru '((t (:strike-through t)))
481 "Face used for displaying strike-through text (-word-)."
482 :group 'gnus-article-emphasis)
483
484 (defface gnus-emphasis-highlight-words
485 '((t (:background "black" :foreground "yellow")))
486 "Face used for displaying highlighted words."
487 :group 'gnus-article-emphasis)
488
489 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
490 "Format for display of Date headers in article bodies.
491 See `format-time-string' for the possible values.
492
493 The variable can also be function, which should return a complete Date
494 header. The function is called with one argument, the time, which can
495 be fed to `format-time-string'."
496 :type '(choice string function)
497 :link '(custom-manual "(gnus)Article Date")
498 :group 'gnus-article-washing)
499
500 (defcustom gnus-save-all-headers t
501 "*If non-nil, don't remove any headers before saving.
502 This will be overridden by the `:headers' property that the symbol of
503 the saver function, which is specified by `gnus-default-article-saver',
504 might have."
505 :group 'gnus-article-saving
506 :type 'boolean)
507
508 (defcustom gnus-prompt-before-saving 'always
509 "*This variable says how much prompting is to be done when saving articles.
510 If it is nil, no prompting will be done, and the articles will be
511 saved to the default files. If this variable is `always', each and
512 every article that is saved will be preceded by a prompt, even when
513 saving large batches of articles. If this variable is neither nil not
514 `always', there the user will be prompted once for a file name for
515 each invocation of the saving commands."
516 :group 'gnus-article-saving
517 :type '(choice (item always)
518 (item :tag "never" nil)
519 (sexp :tag "once" :format "%t\n" :value t)))
520
521 (defcustom gnus-saved-headers gnus-visible-headers
522 "Headers to keep if `gnus-save-all-headers' is nil.
523 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
524 If that variable is nil, however, all headers that match this regexp
525 will be kept while the rest will be deleted before saving. This and
526 `gnus-save-all-headers' will be overridden by the `:headers' property
527 that the symbol of the saver function, which is specified by
528 `gnus-default-article-saver', might have."
529 :group 'gnus-article-saving
530 :type 'regexp)
531
532 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
533 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
534 "A function to save articles in your favorite format.
535 The function will be called by way of the `gnus-summary-save-article'
536 command, and friends such as `gnus-summary-save-article-rmail'.
537
538 Gnus provides the following functions:
539
540 * gnus-summary-save-in-rmail (Rmail format)
541 * gnus-summary-save-in-mail (Unix mail format)
542 * gnus-summary-save-in-folder (MH folder)
543 * gnus-summary-save-in-file (article format)
544 * gnus-summary-save-body-in-file (article body)
545 * gnus-summary-save-in-vm (use VM's folder format)
546 * gnus-summary-write-to-file (article format -- overwrite)
547 * gnus-summary-write-body-to-file (article body -- overwrite)
548 * gnus-summary-save-in-pipe (article format)
549
550 The symbol of each function may have the following properties:
551
552 * :decode
553 The value non-nil means save decoded articles. This is meaningful
554 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
555 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
556 `gnus-summary-save-in-pipe'.
557
558 * :function
559 The value specifies an alternative function which appends, not
560 overwrites, articles to a file. This implies that when saving many
561 articles at a time, `gnus-prompt-before-saving' is bound to t and all
562 articles are saved in a single file. This is meaningful only with
563 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
564
565 * :headers
566 The value specifies the symbol of a variable of which the value
567 specifies headers to be saved. If it is omitted,
568 `gnus-save-all-headers' and `gnus-saved-headers' control what
569 headers should be saved."
570 :group 'gnus-article-saving
571 :type '(radio (function-item gnus-summary-save-in-rmail)
572 (function-item gnus-summary-save-in-mail)
573 (function-item gnus-summary-save-in-folder)
574 (function-item gnus-summary-save-in-file)
575 (function-item gnus-summary-save-body-in-file)
576 (function-item gnus-summary-save-in-vm)
577 (function-item gnus-summary-write-to-file)
578 (function-item gnus-summary-write-body-to-file)
579 (function-item gnus-summary-save-in-pipe)
580 (function)))
581
582 (defcustom gnus-article-save-coding-system
583 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
584 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
585 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
586 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
587 "Coding system used to save decoded articles to a file.
588
589 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
590 which can safely encode any characters in text. This is used by the
591 commands including:
592
593 * gnus-summary-save-article-file
594 * gnus-summary-save-article-body-file
595 * gnus-summary-write-article-file
596 * gnus-summary-write-article-body-file
597
598 and the functions to which you may set `gnus-default-article-saver':
599
600 * gnus-summary-save-in-file
601 * gnus-summary-save-body-in-file
602 * gnus-summary-write-to-file
603 * gnus-summary-write-body-to-file
604
605 Those commands and functions save just text displayed in the article
606 buffer to a file if the value of this variable is non-nil. Note that
607 buttonized MIME parts will be lost in a saved file in that case.
608 Otherwise, raw articles will be saved."
609 :group 'gnus-article-saving
610 :type `(choice
611 :format "%{%t%}:\n %[Value Menu%] %v"
612 (const :tag "Save raw articles" nil)
613 ,@(delq nil
614 (mapcar
615 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
616 '((const :tag "UTF-8" utf-8)
617 (const :tag "iso-2022-7bit" iso-2022-7bit)
618 (const :tag "Emacs internal" emacs-mule)
619 (const :tag "escape-quoted" escape-quoted))))
620 (symbol :tag "Coding system")))
621
622 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
623 "A function generating a file name to save articles in Rmail format.
624 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
625 :group 'gnus-article-saving
626 :type 'function)
627
628 (defcustom gnus-mail-save-name 'gnus-plain-save-name
629 "A function generating a file name to save articles in Unix mail format.
630 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
631 :group 'gnus-article-saving
632 :type 'function)
633
634 (defcustom gnus-folder-save-name 'gnus-folder-save-name
635 "A function generating a file name to save articles in MH folder.
636 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
637 :group 'gnus-article-saving
638 :type 'function)
639
640 (defcustom gnus-file-save-name 'gnus-numeric-save-name
641 "A function generating a file name to save articles in article format.
642 The function is called with NEWSGROUP, HEADERS, and optional
643 LAST-FILE."
644 :group 'gnus-article-saving
645 :type 'function)
646
647 (defcustom gnus-split-methods
648 '((gnus-article-archive-name)
649 (gnus-article-nndoc-name))
650 "*Variable used to suggest where articles are to be saved.
651 For instance, if you would like to save articles related to Gnus in
652 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
653 you could set this variable to something like:
654
655 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
656 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
657
658 This variable is an alist where the key is the match and the
659 value is a list of possible files to save in if the match is
660 non-nil.
661
662 If the match is a string, it is used as a regexp match on the
663 article. If the match is a symbol, that symbol will be funcalled
664 from the buffer of the article to be saved with the newsgroup as the
665 parameter. If it is a list, it will be evalled in the same buffer.
666
667 If this form or function returns a string, this string will be used as a
668 possible file name; and if it returns a non-nil list, that list will be
669 used as possible file names."
670 :group 'gnus-article-saving
671 :type '(repeat (choice (list :value (fun) function)
672 (cons :value ("" "") regexp (repeat string))
673 (sexp :value nil))))
674
675 (defcustom gnus-page-delimiter "^\^L"
676 "*Regexp describing what to use as article page delimiters.
677 The default value is \"^\^L\", which is a form linefeed at the
678 beginning of a line."
679 :type 'regexp
680 :group 'gnus-article-various)
681
682 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
683 "*The format specification for the article mode line.
684 See `gnus-summary-mode-line-format' for a closer description.
685
686 The following additional specs are available:
687
688 %w The article washing status.
689 %m The number of MIME parts in the article."
690 :version "24.1"
691 :type 'string
692 :group 'gnus-article-various)
693
694 (defcustom gnus-article-mode-hook nil
695 "*A hook for Gnus article mode."
696 :type 'hook
697 :group 'gnus-article-various)
698
699 (defcustom gnus-article-menu-hook nil
700 "*Hook run after the creation of the article mode menu."
701 :type 'hook
702 :group 'gnus-article-various)
703
704 (defcustom gnus-article-prepare-hook nil
705 "*A hook called after an article has been prepared in the article buffer."
706 :type 'hook
707 :group 'gnus-article-various)
708
709 (defcustom gnus-copy-article-ignored-headers nil
710 "List of headers to be removed when copying an article.
711 Each element is a regular expression."
712 :version "23.1" ;; No Gnus
713 :type '(repeat regexp)
714 :group 'gnus-article-various)
715
716 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
717 "Gnus 5.10 (Emacs 22.1)")
718
719 (defface gnus-button
720 '((t (:weight bold)))
721 "Face used for highlighting a button in the article buffer."
722 :group 'gnus-article-buttons)
723
724 (defcustom gnus-article-button-face 'gnus-button
725 "Face used for highlighting buttons in the article buffer.
726
727 An article button is a piece of text that you can activate by pressing
728 `RET' or `mouse-2' above it."
729 :type 'face
730 :group 'gnus-article-buttons)
731
732 (defcustom gnus-article-mouse-face 'highlight
733 "Face used for mouse highlighting in the article buffer.
734
735 Article buttons will be displayed in this face when the cursor is
736 above them."
737 :type 'face
738 :group 'gnus-article-buttons)
739
740 (defcustom gnus-signature-face 'gnus-signature
741 "Face used for highlighting a signature in the article buffer.
742 Obsolete; use the face `gnus-signature' for customizations instead."
743 :type 'face
744 :group 'gnus-article-highlight
745 :group 'gnus-article-signature)
746
747 (defface gnus-signature
748 '((t
749 (:italic t)))
750 "Face used for highlighting a signature in the article buffer."
751 :group 'gnus-article-highlight
752 :group 'gnus-article-signature)
753 ;; backward-compatibility alias
754 (put 'gnus-signature-face 'face-alias 'gnus-signature)
755 (put 'gnus-signature-face 'obsolete-face "22.1")
756
757 (defface gnus-header-from
758 '((((class color)
759 (background dark))
760 (:foreground "PaleGreen1"))
761 (((class color)
762 (background light))
763 (:foreground "red3"))
764 (t
765 (:italic t)))
766 "Face used for displaying from headers."
767 :group 'gnus-article-headers
768 :group 'gnus-article-highlight)
769 ;; backward-compatibility alias
770 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
771 (put 'gnus-header-from-face 'obsolete-face "22.1")
772
773 (defface gnus-header-subject
774 '((((class color)
775 (background dark))
776 (:foreground "SeaGreen1"))
777 (((class color)
778 (background light))
779 (:foreground "red4"))
780 (t
781 (:bold t :italic t)))
782 "Face used for displaying subject headers."
783 :group 'gnus-article-headers
784 :group 'gnus-article-highlight)
785 ;; backward-compatibility alias
786 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
787 (put 'gnus-header-subject-face 'obsolete-face "22.1")
788
789 (defface gnus-header-newsgroups
790 '((((class color)
791 (background dark))
792 (:foreground "yellow" :italic t))
793 (((class color)
794 (background light))
795 (:foreground "MidnightBlue" :italic t))
796 (t
797 (:italic t)))
798 "Face used for displaying newsgroups headers.
799 In the default setup this face is only used for crossposted
800 articles."
801 :group 'gnus-article-headers
802 :group 'gnus-article-highlight)
803 ;; backward-compatibility alias
804 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
805 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
806
807 (defface gnus-header-name
808 '((((class color)
809 (background dark))
810 (:foreground "SpringGreen2"))
811 (((class color)
812 (background light))
813 (:foreground "maroon"))
814 (t
815 (:bold t)))
816 "Face used for displaying header names."
817 :group 'gnus-article-headers
818 :group 'gnus-article-highlight)
819 ;; backward-compatibility alias
820 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
821 (put 'gnus-header-name-face 'obsolete-face "22.1")
822
823 (defface gnus-header-content
824 '((((class color)
825 (background dark))
826 (:foreground "SpringGreen1" :italic t))
827 (((class color)
828 (background light))
829 (:foreground "indianred4" :italic t))
830 (t
831 (:italic t))) "Face used for displaying header content."
832 :group 'gnus-article-headers
833 :group 'gnus-article-highlight)
834 ;; backward-compatibility alias
835 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
836 (put 'gnus-header-content-face 'obsolete-face "22.1")
837
838 (defcustom gnus-header-face-alist
839 '(("From" nil gnus-header-from)
840 ("Subject" nil gnus-header-subject)
841 ("Newsgroups:.*," nil gnus-header-newsgroups)
842 ("" gnus-header-name gnus-header-content))
843 "*Controls highlighting of article headers.
844
845 An alist of the form (HEADER NAME CONTENT).
846
847 HEADER is a regular expression which should match the name of a
848 header and NAME and CONTENT are either face names or nil.
849
850 The name of each header field will be displayed using the face
851 specified by the first element in the list where HEADER matches
852 the header name and NAME is non-nil. Similarly, the content will
853 be displayed by the first non-nil matching CONTENT face."
854 :group 'gnus-article-headers
855 :group 'gnus-article-highlight
856 :type '(repeat (list (regexp :tag "Header")
857 (choice :tag "Name"
858 (item :tag "skip" nil)
859 (face :value default))
860 (choice :tag "Content"
861 (item :tag "skip" nil)
862 (face :value default)))))
863
864 (defcustom gnus-face-properties-alist '((pbm . (:face gnus-x-face))
865 (png . nil))
866 "Alist of image types and properties applied to Face and X-Face images.
867 Here are examples:
868
869 ;; Specify the altitude of Face images in the From header.
870 \(setq gnus-face-properties-alist
871 \\='((pbm . (:face gnus-x-face :ascent 80))
872 (png . (:ascent 80))))
873
874 ;; Show Face images as pressed buttons.
875 \(setq gnus-face-properties-alist
876 \\='((pbm . (:face gnus-x-face :relief -2))
877 (png . (:relief -2))))
878
879 See the manual for the valid properties for various image types.
880 Currently, `pbm' is used for X-Face images and `png' is used for Face
881 images in Emacs."
882 :version "23.1" ;; No Gnus
883 :group 'gnus-article-headers
884 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
885
886 (defcustom gnus-article-decode-hook
887 '(article-decode-charset article-decode-encoded-words
888 article-decode-group-name article-decode-idna-rhs)
889 "*Hook run to decode charsets in articles."
890 :group 'gnus-article-headers
891 :type 'hook)
892
893 (defcustom gnus-display-mime-function 'gnus-display-mime
894 "Function to display MIME articles."
895 :group 'gnus-article-mime
896 :type 'function)
897
898 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
899 "Function used to decode headers.")
900
901 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
902 "Function used to decode addresses.")
903
904 (defvar gnus-article-dumbquotes-map
905 '((?\200 "EUR")
906 (?\202 ",")
907 (?\203 "f")
908 (?\204 ",,")
909 (?\205 "...")
910 (?\213 "<")
911 (?\214 "OE")
912 (?\221 "`")
913 (?\222 "'")
914 (?\223 "``")
915 (?\224 "\"")
916 (?\225 "*")
917 (?\226 "-")
918 (?\227 "--")
919 (?\230 "~")
920 (?\231 "(TM)")
921 (?\233 ">")
922 (?\234 "oe")
923 (?\264 "'"))
924 "Table for MS-to-Latin1 translation.")
925
926 (defcustom gnus-ignored-mime-types nil
927 "List of MIME types that should be ignored by Gnus."
928 :version "21.1"
929 :group 'gnus-article-mime
930 :type '(repeat regexp))
931
932 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
933 "List of MIME types that should not be given buttons when rendered inline.
934 See also `gnus-buttonized-mime-types' which may override this variable.
935 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
936 :version "21.1"
937 :group 'gnus-article-mime
938 :type '(repeat regexp))
939
940 (defcustom gnus-buttonized-mime-types nil
941 "List of MIME types that should be given buttons when rendered inline.
942 If set, this variable overrides `gnus-unbuttonized-mime-types'.
943 To see e.g. security buttons you could set this to
944 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
945 this list to display radio buttons that allow you to choose one of two
946 media types those mails include. See also `mm-discouraged-alternatives'.
947 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
948 :version "22.1"
949 :group 'gnus-article-mime
950 :type '(repeat regexp))
951
952 (defcustom gnus-inhibit-mime-unbuttonizing nil
953 "If non-nil, all MIME parts get buttons.
954 When nil (the default value), then some MIME parts do not get buttons,
955 as described by the variables `gnus-buttonized-mime-types' and
956 `gnus-unbuttonized-mime-types'."
957 :version "22.1"
958 :group 'gnus-article-mime
959 :type 'boolean)
960
961 (defcustom gnus-body-boundary-delimiter "_"
962 "String used to delimit header and body.
963 This variable is used by `gnus-article-treat-body-boundary' which can
964 be controlled by `gnus-treat-body-boundary'."
965 :version "22.1"
966 :group 'gnus-article-various
967 :type '(choice (item :tag "None" :value nil)
968 string))
969
970 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
971 "/usr/share/picons")
972 "Defines the location of the faces database.
973 For information on obtaining this database of pretty pictures, please
974 see http://www.cs.indiana.edu/picons/ftp/index.html"
975 :version "22.1"
976 :type '(repeat directory)
977 :link '(url-link :tag "download"
978 "http://www.cs.indiana.edu/picons/ftp/index.html")
979 :link '(custom-manual "(gnus)Picons")
980 :group 'gnus-picon)
981
982 (defun gnus-picons-installed-p ()
983 "Say whether picons are installed on your machine."
984 (let ((installed nil))
985 (dolist (database gnus-picon-databases)
986 (when (file-exists-p database)
987 (setq installed t)))
988 installed))
989
990 (defcustom gnus-article-mime-part-function nil
991 "Function called with a MIME handle as the argument.
992 This is meant for people who want to do something automatic based
993 on parts -- for instance, adding Vcard info to a database."
994 :group 'gnus-article-mime
995 :type '(choice (const nil)
996 function))
997
998 (defcustom gnus-mime-multipart-functions nil
999 "An alist of MIME types to functions to display them."
1000 :version "21.1"
1001 :group 'gnus-article-mime
1002 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1003
1004 (defcustom gnus-article-date-headers '(combined-lapsed)
1005 "A list of Date header formats to display.
1006 Valid formats are `ut' (universal time), `local' (local time
1007 zone), `english' (readable English), `lapsed' (elapsed time),
1008 `combined-lapsed' (both the original date and the elapsed time),
1009 `original' (the original date header), `iso8601' (ISO8601
1010 format), and `user-defined' (a user-defined format defined by the
1011 `gnus-article-time-format' variable).
1012
1013 You have as many date headers as you want in the article buffer.
1014 Some of these headers are updated automatically. See
1015 `gnus-article-update-date-headers' for details."
1016 :version "24.1"
1017 :group 'gnus-article-headers
1018 :type '(set
1019 (const :tag "Universal time (UT)" ut)
1020 (const :tag "Local time zone" local)
1021 (const :tag "Readable English" english)
1022 (const :tag "Elapsed time" lapsed)
1023 (const :tag "Original and elapsed time" combined-lapsed)
1024 (const :tag "Original date header" original)
1025 (const :tag "ISO8601 format" iso8601)
1026 (const :tag "User-defined" user-defined)))
1027
1028 (defcustom gnus-article-update-date-headers nil
1029 "A number that says how often to update the date header (in seconds).
1030 If nil, don't update it at all."
1031 :version "24.1"
1032 :group 'gnus-article-headers
1033 :type '(choice
1034 (item :tag "Don't update" :value nil)
1035 integer))
1036
1037 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1038 "Function called with a MIME handle as the argument.
1039 This is meant for people who want to view first matched part.
1040 For `undisplayed-alternative' (default), the first undisplayed
1041 part or alternative part is used. For `undisplayed', the first
1042 undisplayed part is used. For a function, the first part which
1043 the function return t is used. For nil, the first part is
1044 used."
1045 :version "21.1"
1046 :group 'gnus-article-mime
1047 :type '(choice
1048 (item :tag "first" :value nil)
1049 (item :tag "undisplayed" :value undisplayed)
1050 (item :tag "undisplayed or alternative"
1051 :value undisplayed-alternative)
1052 (function)))
1053
1054 (defcustom gnus-mime-action-alist
1055 '(("save to file" . gnus-mime-save-part)
1056 ("save and strip" . gnus-mime-save-part-and-strip)
1057 ("replace with file" . gnus-mime-replace-part)
1058 ("delete part" . gnus-mime-delete-part)
1059 ("display as text" . gnus-mime-inline-part)
1060 ("view the part" . gnus-mime-view-part)
1061 ("pipe to command" . gnus-mime-pipe-part)
1062 ("toggle display" . gnus-article-press-button)
1063 ("toggle display" . gnus-article-view-part-as-charset)
1064 ("view as type" . gnus-mime-view-part-as-type)
1065 ("view internally" . gnus-mime-view-part-internally)
1066 ("view externally" . gnus-mime-view-part-externally))
1067 "An alist of actions that run on the MIME attachment."
1068 :group 'gnus-article-mime
1069 :type '(repeat (cons (string :tag "name")
1070 (function))))
1071
1072 (defcustom gnus-auto-select-part 1
1073 "Advance to next MIME part when deleting or stripping parts.
1074
1075 When 0, point will be placed on the same part as before. When
1076 positive (negative), move point forward (backwards) this many
1077 parts. When nil, redisplay article."
1078 :version "23.1" ;; No Gnus
1079 :group 'gnus-article-mime
1080 :type '(choice (const nil :tag "Redisplay article.")
1081 (const 1 :tag "Next part.")
1082 (const 0 :tag "Current part.")
1083 integer))
1084
1085 ;;;
1086 ;;; The treatment variables
1087 ;;;
1088
1089 (defvar gnus-part-display-hook nil
1090 "Hook called on parts that are to receive treatment.")
1091
1092 (defvar gnus-article-treat-custom
1093 '(choice (const :tag "Off" nil)
1094 (const :tag "On" t)
1095 (const :tag "Header" head)
1096 (const :tag "First" first)
1097 (const :tag "Last" last)
1098 (integer :tag "Less")
1099 (repeat :tag "Groups" regexp)
1100 (sexp :tag "Predicate")))
1101
1102 (defvar gnus-article-treat-head-custom
1103 '(choice (const :tag "Off" nil)
1104 (const :tag "Header" head)))
1105
1106 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1107 "text/x-patch" "text/html")
1108 "Part types eligible for treatment.")
1109
1110 (defvar gnus-inhibit-treatment nil
1111 "Whether to inhibit treatment.")
1112
1113 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1114 "Highlight the signature.
1115 Valid values are nil, t, `head', `first', `last', an integer or a
1116 predicate. See Info node `(gnus)Customizing Articles'."
1117 :group 'gnus-article-treat
1118 :link '(custom-manual "(gnus)Customizing Articles")
1119 :type gnus-article-treat-custom)
1120 (put 'gnus-treat-highlight-signature 'highlight t)
1121
1122 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1123 "Add buttons.
1124 Valid values are nil, t, `head', `first', `last', an integer or a
1125 predicate. See Info node `(gnus)Customizing Articles'."
1126 :group 'gnus-article-treat
1127 :link '(custom-manual "(gnus)Customizing Articles")
1128 :type gnus-article-treat-custom)
1129 (put 'gnus-treat-buttonize 'highlight t)
1130
1131 (defcustom gnus-treat-buttonize-head 'head
1132 "Add buttons to the head.
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate. See Info node `(gnus)Customizing Articles'."
1135 :group 'gnus-article-treat
1136 :link '(custom-manual "(gnus)Customizing Articles")
1137 :type gnus-article-treat-head-custom)
1138 (put 'gnus-treat-buttonize-head 'highlight t)
1139
1140 (defcustom gnus-treat-date 'head
1141 "Display dates according to the `gnus-article-date-headers' variable.
1142 Valid values are nil, t, `head', `first', `last', an integer or a
1143 predicate. See Info node `(gnus)Customizing Articles'."
1144 :version "24.1"
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-head-custom)
1148
1149 (defcustom gnus-treat-emphasize 50000
1150 "Emphasize text.
1151 Valid values are nil, t, `head', `first', `last', an integer or a
1152 predicate. See Info node `(gnus)Customizing Articles'."
1153 :group 'gnus-article-treat
1154 :link '(custom-manual "(gnus)Customizing Articles")
1155 :type gnus-article-treat-custom)
1156 (put 'gnus-treat-emphasize 'highlight t)
1157
1158 (defcustom gnus-treat-strip-cr nil
1159 "Remove carriage returns.
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate. See Info node `(gnus)Customizing Articles'."
1162 :version "22.1"
1163 :group 'gnus-article-treat
1164 :link '(custom-manual "(gnus)Customizing Articles")
1165 :type gnus-article-treat-custom)
1166
1167 (defcustom gnus-treat-unsplit-urls nil
1168 "Remove newlines from within URLs.
1169 Valid values are nil, t, `head', `first', `last', an integer or a
1170 predicate. See Info node `(gnus)Customizing Articles'."
1171 :version "22.1"
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-custom)
1175
1176 (defcustom gnus-treat-leading-whitespace nil
1177 "Remove leading whitespace in headers.
1178 Valid values are nil, t, `head', `first', `last', an integer or a
1179 predicate. See Info node `(gnus)Customizing Articles'."
1180 :version "22.1"
1181 :group 'gnus-article-treat
1182 :link '(custom-manual "(gnus)Customizing Articles")
1183 :type gnus-article-treat-custom)
1184
1185 (defcustom gnus-treat-hide-headers 'head
1186 "Hide headers.
1187 Valid values are nil, t, `head', `first', `last', an integer or a
1188 predicate. See Info node `(gnus)Customizing Articles'."
1189 :group 'gnus-article-treat
1190 :link '(custom-manual "(gnus)Customizing Articles")
1191 :type gnus-article-treat-head-custom)
1192
1193 (defcustom gnus-treat-hide-boring-headers nil
1194 "Hide boring headers.
1195 Valid values are nil, t, `head', `first', `last', an integer or a
1196 predicate. See Info node `(gnus)Customizing Articles'."
1197 :group 'gnus-article-treat
1198 :link '(custom-manual "(gnus)Customizing Articles")
1199 :type gnus-article-treat-head-custom)
1200
1201 (defcustom gnus-treat-hide-signature nil
1202 "Hide the signature.
1203 Valid values are nil, t, `head', `first', `last', an integer or a
1204 predicate. See Info node `(gnus)Customizing Articles'."
1205 :group 'gnus-article-treat
1206 :link '(custom-manual "(gnus)Customizing Articles")
1207 :type gnus-article-treat-custom)
1208
1209 (defcustom gnus-treat-fill-article nil
1210 "Fill the article.
1211 Valid values are nil, t, `head', `first', `last', an integer or a
1212 predicate. See Info node `(gnus)Customizing Articles'."
1213 :group 'gnus-article-treat
1214 :link '(custom-manual "(gnus)Customizing Articles")
1215 :type gnus-article-treat-custom)
1216
1217 (defcustom gnus-treat-hide-citation nil
1218 "Hide cited text.
1219 Valid values are nil, t, `head', `first', `last', an integer or a
1220 predicate. See Info node `(gnus)Customizing Articles'.
1221
1222 See `gnus-article-highlight-citation' for variables used to
1223 control what it hides."
1224 :group 'gnus-article-treat
1225 :link '(custom-manual "(gnus)Customizing Articles")
1226 :type gnus-article-treat-custom)
1227
1228 (defcustom gnus-treat-hide-citation-maybe nil
1229 "Hide cited text according to certain conditions.
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'.
1232
1233 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1234 how to control what it hides."
1235 :group 'gnus-article-treat
1236 :link '(custom-manual "(gnus)Customizing Articles")
1237 :type gnus-article-treat-custom)
1238
1239 (defcustom gnus-treat-strip-list-identifiers 'head
1240 "Strip list identifiers from `gnus-list-identifiers'.
1241 Valid values are nil, t, `head', `first', `last', an integer or a
1242 predicate. See Info node `(gnus)Customizing Articles'."
1243 :version "21.1"
1244 :group 'gnus-article-treat
1245 :link '(custom-manual "(gnus)Customizing Articles")
1246 :type gnus-article-treat-custom)
1247
1248 (gnus-define-group-parameter
1249 list-identifier
1250 :variable-document
1251 "Alist of regexps and correspondent identifiers."
1252 :variable-group gnus-article-washing
1253 :parameter-type
1254 '(choice :tag "Identifier"
1255 :value nil
1256 (symbol :tag "Item in `gnus-list-identifiers'" none)
1257 regexp
1258 (const :tag "None" nil))
1259 :parameter-document
1260 "If non-nil, specify how to remove `identifiers' from articles' subject.
1261
1262 Any symbol is used to look up a regular expression to match the
1263 banner in `gnus-list-identifiers'. A string is used as a regular
1264 expression to match the identifier directly.")
1265
1266 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1267 "Gnus 5.10 (Emacs 22.1)")
1268
1269 (defcustom gnus-treat-strip-pem nil
1270 "Strip PEM signatures.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate. See Info node `(gnus)Customizing Articles'."
1273 :group 'gnus-article-treat
1274 :link '(custom-manual "(gnus)Customizing Articles")
1275 :type gnus-article-treat-custom)
1276
1277 (defcustom gnus-treat-strip-banner t
1278 "Strip banners from articles.
1279 The banner to be stripped is specified in the `banner' group parameter.
1280 Valid values are nil, t, `head', `first', `last', an integer or a
1281 predicate. See Info node `(gnus)Customizing Articles'."
1282 :group 'gnus-article-treat
1283 :link '(custom-manual "(gnus)Customizing Articles")
1284 :type gnus-article-treat-custom)
1285
1286 (defcustom gnus-treat-highlight-headers 'head
1287 "Highlight the headers.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-head-custom)
1293 (put 'gnus-treat-highlight-headers 'highlight t)
1294
1295 (defcustom gnus-treat-highlight-citation t
1296 "Highlight cited text.
1297 Valid values are nil, t, `head', `first', `last', an integer or a
1298 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-custom)
1302 (put 'gnus-treat-highlight-citation 'highlight t)
1303
1304 (defcustom gnus-treat-strip-headers-in-body t
1305 "Strip the X-No-Archive header line from the beginning of the body.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate. See Info node `(gnus)Customizing Articles'."
1308 :version "21.1"
1309 :group 'gnus-article-treat
1310 :link '(custom-manual "(gnus)Customizing Articles")
1311 :type gnus-article-treat-custom)
1312
1313 (defcustom gnus-treat-strip-trailing-blank-lines nil
1314 "Strip trailing blank lines.
1315 Valid values are nil, t, `head', `first', `last', an integer or a
1316 predicate. See Info node `(gnus)Customizing Articles'.
1317
1318 When set to t, it also strips trailing blanks in all MIME parts.
1319 Consider to use `last' instead."
1320 :group 'gnus-article-treat
1321 :link '(custom-manual "(gnus)Customizing Articles")
1322 :type gnus-article-treat-custom)
1323
1324 (defcustom gnus-treat-strip-leading-blank-lines nil
1325 "Strip leading blank lines.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'.
1328
1329 When set to t, it also strips trailing blanks in all MIME parts."
1330 :group 'gnus-article-treat
1331 :link '(custom-manual "(gnus)Customizing Articles")
1332 :type gnus-article-treat-custom)
1333
1334 (defcustom gnus-treat-strip-multiple-blank-lines nil
1335 "Strip multiple blank lines.
1336 Valid values are nil, t, `head', `first', `last', an integer or a
1337 predicate. See Info node `(gnus)Customizing Articles'."
1338 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :type gnus-article-treat-custom)
1341
1342 (defcustom gnus-treat-unfold-headers 'head
1343 "Unfold folded header lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate. See Info node `(gnus)Customizing Articles'."
1346 :version "22.1"
1347 :group 'gnus-article-treat
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :type gnus-article-treat-custom)
1350
1351 (defcustom gnus-article-unfold-long-headers nil
1352 "If non-nil, allow unfolding headers even if the header is long.
1353 If it is a regexp, only long headers matching this regexp are unfolded.
1354 If it is t, all long headers are unfolded.
1355
1356 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1357 :version "23.1" ;; No Gnus
1358 :group 'gnus-article-treat
1359 :type '(choice (const nil)
1360 (const :tag "all" t)
1361 (regexp)))
1362
1363 (defcustom gnus-treat-fold-headers nil
1364 "Fold headers.
1365 Valid values are nil, t, `head', `first', `last', an integer or a
1366 predicate. See Info node `(gnus)Customizing Articles'."
1367 :version "22.1"
1368 :group 'gnus-article-treat
1369 :link '(custom-manual "(gnus)Customizing Articles")
1370 :type gnus-article-treat-custom)
1371
1372 (defcustom gnus-treat-fold-newsgroups 'head
1373 "Fold the Newsgroups and Followup-To headers.
1374 Valid values are nil, t, `head', `first', `last', an integer or a
1375 predicate. See Info node `(gnus)Customizing Articles'."
1376 :version "22.1"
1377 :group 'gnus-article-treat
1378 :link '(custom-manual "(gnus)Customizing Articles")
1379 :type gnus-article-treat-custom)
1380
1381 (defcustom gnus-treat-overstrike t
1382 "Treat overstrike highlighting.
1383 Valid values are nil, t, `head', `first', `last', an integer or a
1384 predicate. See Info node `(gnus)Customizing Articles'."
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1388 (put 'gnus-treat-overstrike 'highlight t)
1389
1390 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1391 "Treat ANSI SGR control sequences.
1392 Valid values are nil, t, `head', `first', `last', an integer or a
1393 predicate. See Info node `(gnus)Customizing Articles'."
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1397
1398 (make-obsolete-variable 'gnus-treat-display-xface
1399 'gnus-treat-display-x-face "Emacs 22.1")
1400
1401 (defcustom gnus-treat-display-x-face
1402 (and (not noninteractive)
1403 (gnus-image-type-available-p 'xbm)
1404 (condition-case nil
1405 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1406 (executable-find "icontopbm"))
1407 ;; shell-command-to-string may signal an error, e.g. if
1408 ;; shell-file-name is not found.
1409 (error nil))
1410 'head)
1411 "Display X-Face headers.
1412 Valid values are nil and `head'.
1413 See Info node `(gnus)Customizing Articles' and Info node
1414 `(gnus)X-Face' for details."
1415 :group 'gnus-article-treat
1416 :version "21.1"
1417 :link '(custom-manual "(gnus)Customizing Articles")
1418 :link '(custom-manual "(gnus)X-Face")
1419 :type gnus-article-treat-head-custom
1420 :set (lambda (symbol value)
1421 (set-default
1422 symbol
1423 (cond ((or (boundp symbol) (get symbol 'saved-value))
1424 value)
1425 ((boundp 'gnus-treat-display-xface)
1426 (message "\
1427 ** gnus-treat-display-xface is an obsolete variable;\
1428 use gnus-treat-display-x-face instead")
1429 (default-value 'gnus-treat-display-xface))
1430 ((get 'gnus-treat-display-xface 'saved-value)
1431 (message "\
1432 ** gnus-treat-display-xface is an obsolete variable;\
1433 use gnus-treat-display-x-face instead")
1434 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1435 (t
1436 value)))))
1437 (put 'gnus-treat-display-x-face 'highlight t)
1438
1439 (defcustom gnus-treat-display-face
1440 (and (not noninteractive)
1441 (gnus-image-type-available-p 'png)
1442 'head)
1443 "Display Face headers.
1444 Valid values are nil, t, `head', `first', `last', an integer or a
1445 predicate. See Info node `(gnus)Customizing Articles' and Info
1446 node `(gnus)Face' for details."
1447 :group 'gnus-article-treat
1448 :version "22.1"
1449 :link '(custom-manual "(gnus)Customizing Articles")
1450 :link '(custom-manual "(gnus)X-Face")
1451 :type gnus-article-treat-head-custom)
1452 (put 'gnus-treat-display-face 'highlight t)
1453
1454 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1455 "Display smileys.
1456 Valid values are nil, t, `head', `first', `last', an integer or a
1457 predicate. See Info node `(gnus)Customizing Articles' and Info
1458 node `(gnus)Smileys' for details."
1459 :group 'gnus-article-treat
1460 :version "21.1"
1461 :link '(custom-manual "(gnus)Customizing Articles")
1462 :link '(custom-manual "(gnus)Smileys")
1463 :type gnus-article-treat-custom)
1464 (put 'gnus-treat-display-smileys 'highlight t)
1465
1466 (defcustom gnus-treat-from-picon
1467 (if (and (gnus-image-type-available-p 'xpm)
1468 (gnus-picons-installed-p))
1469 'head nil)
1470 "Display picons in the From header.
1471 Valid values are nil, t, `head', `first', `last', an integer or a
1472 predicate. See Info node `(gnus)Customizing Articles' and Info
1473 node `(gnus)Picons' for details."
1474 :version "22.1"
1475 :group 'gnus-article-treat
1476 :group 'gnus-picon
1477 :link '(custom-manual "(gnus)Customizing Articles")
1478 :link '(custom-manual "(gnus)Picons")
1479 :type gnus-article-treat-head-custom)
1480 (put 'gnus-treat-from-picon 'highlight t)
1481
1482 (defcustom gnus-treat-mail-picon
1483 (if (and (gnus-image-type-available-p 'xpm)
1484 (gnus-picons-installed-p))
1485 'head nil)
1486 "Display picons in To and Cc headers.
1487 Valid values are nil, t, `head', `first', `last', an integer or a
1488 predicate. See Info node `(gnus)Customizing Articles' and Info
1489 node `(gnus)Picons' for details."
1490 :version "22.1"
1491 :group 'gnus-article-treat
1492 :group 'gnus-picon
1493 :link '(custom-manual "(gnus)Customizing Articles")
1494 :link '(custom-manual "(gnus)Picons")
1495 :type gnus-article-treat-head-custom)
1496 (put 'gnus-treat-mail-picon 'highlight t)
1497
1498 (defcustom gnus-treat-newsgroups-picon
1499 (if (and (gnus-image-type-available-p 'xpm)
1500 (gnus-picons-installed-p))
1501 'head nil)
1502 "Display picons in the Newsgroups and Followup-To headers.
1503 Valid values are nil, t, `head', `first', `last', an integer or a
1504 predicate. See Info node `(gnus)Customizing Articles' and Info
1505 node `(gnus)Picons' for details."
1506 :version "22.1"
1507 :group 'gnus-article-treat
1508 :group 'gnus-picon
1509 :link '(custom-manual "(gnus)Customizing Articles")
1510 :link '(custom-manual "(gnus)Picons")
1511 :type gnus-article-treat-head-custom)
1512 (put 'gnus-treat-newsgroups-picon 'highlight t)
1513
1514 (defcustom gnus-treat-from-gravatar nil
1515 "Display gravatars in the From header.
1516 Valid values are nil, t, `head', `first', `last', an integer or a
1517 predicate. See Info node `(gnus)Customizing Articles' and Info
1518 node `(gnus)Gravatars' for details."
1519 :version "24.1"
1520 :group 'gnus-article-treat
1521 :group 'gnus-gravatar
1522 :link '(custom-manual "(gnus)Customizing Articles")
1523 :link '(custom-manual "(gnus)Gravatars")
1524 :type gnus-article-treat-head-custom)
1525 (put 'gnus-treat-from-gravatar 'highlight t)
1526
1527 (defcustom gnus-treat-mail-gravatar nil
1528 "Display gravatars in To and Cc headers.
1529 Valid values are nil, t, `head', `first', `last', an integer or a
1530 predicate. See Info node `(gnus)Customizing Articles' and Info
1531 node `(gnus)Gravatars' for details."
1532 :version "24.1"
1533 :group 'gnus-article-treat
1534 :group 'gnus-gravatar
1535 :link '(custom-manual "(gnus)Customizing Articles")
1536 :link '(custom-manual "(gnus)Gravatars")
1537 :type gnus-article-treat-head-custom)
1538 (put 'gnus-treat-mail-gravatar 'highlight t)
1539
1540 (defcustom gnus-treat-body-boundary
1541 (if (or gnus-treat-newsgroups-picon
1542 gnus-treat-mail-picon
1543 gnus-treat-from-picon
1544 gnus-treat-from-gravatar
1545 gnus-treat-mail-gravatar)
1546 ;; If there's much decoration, the user might prefer a boundary.
1547 'head
1548 nil)
1549 "Draw a boundary at the end of the headers.
1550 Valid values are nil and `head'.
1551 See Info node `(gnus)Customizing Articles' for details."
1552 :version "22.1"
1553 :group 'gnus-article-treat
1554 :link '(custom-manual "(gnus)Customizing Articles")
1555 :type gnus-article-treat-head-custom)
1556
1557 (defcustom gnus-treat-capitalize-sentences nil
1558 "Capitalize sentence-starting words.
1559 Valid values are nil, t, `head', `first', `last', an integer or a
1560 predicate. See Info node `(gnus)Customizing Articles'."
1561 :version "21.1"
1562 :group 'gnus-article-treat
1563 :link '(custom-manual "(gnus)Customizing Articles")
1564 :type gnus-article-treat-custom)
1565
1566 (defcustom gnus-treat-wash-html nil
1567 "Format as HTML.
1568 Valid values are nil, t, `head', `first', `last', an integer or a
1569 predicate. See Info node `(gnus)Customizing Articles'."
1570 :version "22.1"
1571 :group 'gnus-article-treat
1572 :link '(custom-manual "(gnus)Customizing Articles")
1573 :type gnus-article-treat-custom)
1574
1575 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1576 "Fill long lines.
1577 Valid values are nil, t, `head', `first', `last', an integer or a
1578 predicate. See Info node `(gnus)Customizing Articles'."
1579 :version "24.1"
1580 :group 'gnus-article-treat
1581 :link '(custom-manual "(gnus)Customizing Articles")
1582 :type gnus-article-treat-custom)
1583
1584 (defcustom gnus-treat-x-pgp-sig nil
1585 "Verify X-PGP-Sig.
1586 To automatically treat X-PGP-Sig, set it to head.
1587 Valid values are nil, t, `head', `first', `last', an integer or a
1588 predicate. See Info node `(gnus)Customizing Articles'."
1589 :version "22.1"
1590 :group 'gnus-article-treat
1591 :group 'mime-security
1592 :link '(custom-manual "(gnus)Customizing Articles")
1593 :type gnus-article-treat-custom)
1594
1595 (defvar gnus-article-encrypt-protocol-alist
1596 '(("PGP" . mml2015-self-encrypt)))
1597
1598 ;; Set to nil if more than one protocol added to
1599 ;; gnus-article-encrypt-protocol-alist.
1600 (defcustom gnus-article-encrypt-protocol "PGP"
1601 "The protocol used for encrypt articles.
1602 It is a string, such as \"PGP\". If nil, ask user."
1603 :version "22.1"
1604 :type 'string
1605 :group 'mime-security)
1606
1607 (defvar idna-program)
1608
1609 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1610 (condition-case nil
1611 (require 'idna)
1612 (file-error)
1613 (invalid-operation))
1614 idna-program
1615 (executable-find idna-program))
1616 "Whether IDNA decoding of headers is used when viewing messages.
1617 This requires GNU Libidn, and by default only enabled if it is found."
1618 :version "22.1"
1619 :group 'gnus-article-headers
1620 :type 'boolean)
1621
1622 (defcustom gnus-article-over-scroll nil
1623 "If non-nil, allow scrolling the article buffer even when there no more text."
1624 :version "22.1"
1625 :group 'gnus-article
1626 :type 'boolean)
1627
1628 (defcustom gnus-inhibit-images nil
1629 "Non-nil means inhibit displaying of images inline in the article body."
1630 :version "24.1"
1631 :group 'gnus-article
1632 :type 'boolean)
1633
1634 (defcustom gnus-blocked-images 'gnus-block-private-groups
1635 "Images that have URLs matching this regexp will be blocked.
1636 This can also be a function to be evaluated. If so, it will be
1637 called with the group name as the parameter, and should return a
1638 regexp."
1639 :version "24.1"
1640 :group 'gnus-art
1641 :type '(choice (const :tag "Allow all" nil)
1642 (regexp :tag "Regular expression")
1643 (function :tag "Use a function")))
1644
1645 ;;; Internal variables
1646
1647 (defvar gnus-english-month-names
1648 '("January" "February" "March" "April" "May" "June" "July" "August"
1649 "September" "October" "November" "December"))
1650
1651 (defvar article-goto-body-goes-to-point-min-p nil)
1652 (defvar gnus-article-wash-types nil)
1653 (defvar gnus-article-emphasis-alist nil)
1654 (defvar gnus-article-image-alist nil)
1655
1656 (defvar gnus-article-mime-handle-alist-1 nil)
1657 (defvar gnus-treatment-function-alist
1658 '((gnus-treat-strip-cr gnus-article-remove-cr)
1659 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1660 (gnus-treat-strip-banner gnus-article-strip-banner)
1661 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1662 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1663 (gnus-treat-buttonize gnus-article-add-buttons)
1664 (gnus-treat-fill-article gnus-article-fill-cited-article)
1665 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1666 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1667 (gnus-treat-display-x-face gnus-article-display-x-face)
1668 (gnus-treat-display-face gnus-article-display-face)
1669 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1670 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1671 (gnus-treat-hide-signature gnus-article-hide-signature)
1672 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1673 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1674 (gnus-treat-from-picon gnus-treat-from-picon)
1675 (gnus-treat-mail-picon gnus-treat-mail-picon)
1676 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1677 (gnus-treat-strip-pem gnus-article-hide-pem)
1678 (gnus-treat-date gnus-article-treat-date)
1679 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1680 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1681 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1682 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1683 (gnus-treat-strip-trailing-blank-lines
1684 gnus-article-remove-trailing-blank-lines)
1685 (gnus-treat-strip-leading-blank-lines
1686 gnus-article-strip-leading-blank-lines)
1687 (gnus-treat-strip-multiple-blank-lines
1688 gnus-article-strip-multiple-blank-lines)
1689 (gnus-treat-overstrike gnus-article-treat-overstrike)
1690 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1691 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1692 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1693 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1694 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1695 (gnus-treat-display-smileys gnus-treat-smiley)
1696 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1697 (gnus-treat-wash-html gnus-article-wash-html)
1698 (gnus-treat-emphasize gnus-article-emphasize)
1699 (gnus-treat-hide-citation gnus-article-hide-citation)
1700 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1701 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1702 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1703
1704 (defvar gnus-article-mime-handle-alist nil)
1705 (defvar article-lapsed-timer nil)
1706 (defvar gnus-article-current-summary nil)
1707
1708 (defvar gnus-article-mode-syntax-table
1709 (let ((table (copy-syntax-table text-mode-syntax-table)))
1710 ;; This causes the citation match run O(2^n).
1711 ;; (modify-syntax-entry ?- "w" table)
1712 (modify-syntax-entry ?> ")<" table)
1713 (modify-syntax-entry ?< "(>" table)
1714 ;; make M-. in article buffers work for `foo' strings
1715 (modify-syntax-entry ?' " " table)
1716 (modify-syntax-entry ?` " " table)
1717 table)
1718 "Syntax table used in article mode buffers.
1719 Initialized from `text-mode-syntax-table'.")
1720
1721 (defvar gnus-save-article-buffer nil)
1722
1723 (defvar gnus-number-of-articles-to-be-saved nil)
1724
1725 (defvar gnus-inhibit-hiding nil)
1726
1727 (defvar gnus-article-edit-mode nil)
1728
1729 ;;; Macros for dealing with the article buffer.
1730
1731 (defmacro gnus-with-article-headers (&rest forms)
1732 `(with-current-buffer gnus-article-buffer
1733 (save-restriction
1734 (let ((inhibit-read-only t)
1735 (inhibit-point-motion-hooks t)
1736 (case-fold-search t))
1737 (article-narrow-to-head)
1738 ,@forms))))
1739
1740 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1741 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1742
1743 (defmacro gnus-with-article-buffer (&rest forms)
1744 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1745 (with-current-buffer gnus-article-buffer
1746 (let ((inhibit-read-only t))
1747 ,@forms))))
1748
1749 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1750 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1751
1752 (defun gnus-article-goto-header (header)
1753 "Go to HEADER, which is a regular expression."
1754 (re-search-forward (concat "^\\(" header "\\):") nil t))
1755
1756 (defsubst gnus-article-hide-text (b e props)
1757 "Set text PROPS on the B to E region."
1758 (gnus-add-text-properties-when 'article-type nil b e props))
1759
1760 (defsubst gnus-article-unhide-text (b e)
1761 "Remove hidden text properties from region between B and E."
1762 (remove-text-properties b e gnus-hidden-properties))
1763
1764 (defun gnus-article-hide-text-type (b e type)
1765 "Hide text of TYPE between B and E."
1766 (gnus-add-wash-type type)
1767 (gnus-article-hide-text
1768 b e (cons 'article-type (cons type gnus-hidden-properties))))
1769
1770 (defun gnus-article-unhide-text-type (b e type)
1771 "Unhide text of TYPE between B and E."
1772 (gnus-delete-wash-type type)
1773 (remove-text-properties
1774 b e (cons 'article-type (cons type gnus-hidden-properties))))
1775
1776 (defun gnus-article-delete-text-of-type (type)
1777 "Delete text of TYPE in the current buffer."
1778 (save-excursion
1779 (let ((b (point-min)))
1780 (if (eq type 'multipart)
1781 ;; Remove MIME buttons associated with multipart/alternative parts.
1782 (progn
1783 (goto-char b)
1784 (while (if (get-text-property (point) 'gnus-part)
1785 (setq b (point))
1786 (when (setq b (next-single-property-change (point)
1787 'gnus-part))
1788 (goto-char b)
1789 t))
1790 (end-of-line)
1791 (skip-chars-forward "\n")
1792 (when (eq (get-text-property b 'article-type) 'multipart)
1793 (delete-region b (point)))))
1794 (while (setq b (text-property-any b (point-max) 'article-type type))
1795 (delete-region
1796 b (or (text-property-not-all b (point-max) 'article-type type)
1797 (point-max))))))))
1798
1799 (defun gnus-article-delete-invisible-text ()
1800 "Delete all invisible text in the current buffer."
1801 (save-excursion
1802 (let ((b (point-min)))
1803 (while (setq b (text-property-any b (point-max) 'invisible t))
1804 (delete-region
1805 b (or (text-property-not-all b (point-max) 'invisible t)
1806 (point-max)))))))
1807
1808 (defsubst gnus-article-header-rank ()
1809 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1810 (let ((list gnus-sorted-header-list)
1811 (i 1))
1812 (while list
1813 (if (looking-at (car list))
1814 (setq list nil)
1815 (setq list (cdr list))
1816 (incf i)))
1817 i))
1818
1819 (defun article-hide-headers (&optional _arg _delete)
1820 "Hide unwanted headers and possibly sort them as well."
1821 (interactive)
1822 ;; This function might be inhibited.
1823 (unless gnus-inhibit-hiding
1824 (let ((inhibit-read-only t)
1825 (case-fold-search t)
1826 (max (1+ (length gnus-sorted-header-list)))
1827 (inhibit-point-motion-hooks t)
1828 (cur (current-buffer))
1829 ignored visible beg)
1830 (save-excursion
1831 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1832 ;; group parameters, so we should go to the summary buffer.
1833 (when (prog1
1834 (condition-case nil
1835 (progn (set-buffer gnus-summary-buffer) t)
1836 (error nil))
1837 (setq ignored (when (not gnus-visible-headers)
1838 (cond ((stringp gnus-ignored-headers)
1839 gnus-ignored-headers)
1840 ((listp gnus-ignored-headers)
1841 (mapconcat 'identity
1842 gnus-ignored-headers
1843 "\\|"))))
1844 visible (cond ((stringp gnus-visible-headers)
1845 gnus-visible-headers)
1846 ((and gnus-visible-headers
1847 (listp gnus-visible-headers))
1848 (mapconcat 'identity
1849 gnus-visible-headers
1850 "\\|")))))
1851 (set-buffer cur))
1852 (save-restriction
1853 ;; First we narrow to just the headers.
1854 (article-narrow-to-head)
1855 ;; Hide any "From " lines at the beginning of (mail) articles.
1856 (while (looking-at "From ")
1857 (forward-line 1))
1858 (unless (bobp)
1859 (delete-region (point-min) (point)))
1860 ;; Then treat the rest of the header lines.
1861 ;; Then we use the two regular expressions
1862 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1863 ;; select which header lines is to remain visible in the
1864 ;; article buffer.
1865 (while (re-search-forward "^[^ \t:]*:" nil t)
1866 (beginning-of-line)
1867 ;; Mark the rank of the header.
1868 (put-text-property
1869 (point) (1+ (point)) 'message-rank
1870 (if (or (and visible (looking-at visible))
1871 (and ignored
1872 (not (looking-at ignored))))
1873 (gnus-article-header-rank)
1874 (+ 2 max)))
1875 (forward-line 1))
1876 (message-sort-headers-1)
1877 (when (setq beg (text-property-any
1878 (point-min) (point-max) 'message-rank (+ 2 max)))
1879 ;; We delete the unwanted headers.
1880 (gnus-add-wash-type 'headers)
1881 (add-text-properties (point-min) (+ 5 (point-min))
1882 '(article-type headers dummy-invisible t))
1883 (delete-region beg (point-max))))))))
1884
1885 (defun article-hide-boring-headers (&optional arg)
1886 "Toggle hiding of headers that aren't very interesting.
1887 If given a negative prefix, always show; if given a positive prefix,
1888 always hide."
1889 (interactive (gnus-article-hidden-arg))
1890 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1891 (not gnus-show-all-headers))
1892 (save-excursion
1893 (save-restriction
1894 (let ((inhibit-read-only t)
1895 (inhibit-point-motion-hooks t))
1896 (article-narrow-to-head)
1897 (dolist (elem gnus-boring-article-headers)
1898 (goto-char (point-min))
1899 (cond
1900 ;; Hide empty headers.
1901 ((eq elem 'empty)
1902 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1903 (forward-line -1)
1904 (gnus-article-hide-text-type
1905 (point-at-bol)
1906 (progn
1907 (end-of-line)
1908 (if (re-search-forward "^[^ \t]" nil t)
1909 (match-beginning 0)
1910 (point-max)))
1911 'boring-headers)))
1912 ;; Hide boring Newsgroups header.
1913 ((eq elem 'newsgroups)
1914 (when (gnus-string-equal
1915 (gnus-fetch-field "newsgroups")
1916 (gnus-group-real-name
1917 (if (boundp 'gnus-newsgroup-name)
1918 gnus-newsgroup-name
1919 "")))
1920 (gnus-article-hide-header "newsgroups")))
1921 ((eq elem 'to-address)
1922 (let ((to (message-fetch-field "to"))
1923 (to-address
1924 (gnus-parameter-to-address
1925 (if (boundp 'gnus-newsgroup-name)
1926 gnus-newsgroup-name ""))))
1927 (when (and to to-address
1928 (ignore-errors
1929 (gnus-string-equal
1930 ;; only one address in To
1931 (nth 1 (mail-extract-address-components to))
1932 to-address)))
1933 (gnus-article-hide-header "to"))))
1934 ((eq elem 'to-list)
1935 (let ((to (message-fetch-field "to"))
1936 (to-list
1937 (gnus-parameter-to-list
1938 (if (boundp 'gnus-newsgroup-name)
1939 gnus-newsgroup-name ""))))
1940 (when (and to to-list
1941 (ignore-errors
1942 (gnus-string-equal
1943 ;; only one address in To
1944 (nth 1 (mail-extract-address-components to))
1945 to-list)))
1946 (gnus-article-hide-header "to"))))
1947 ((eq elem 'cc-list)
1948 (let ((cc (message-fetch-field "cc"))
1949 (to-list
1950 (gnus-parameter-to-list
1951 (if (boundp 'gnus-newsgroup-name)
1952 gnus-newsgroup-name ""))))
1953 (when (and cc to-list
1954 (ignore-errors
1955 (gnus-string-equal
1956 ;; only one address in CC
1957 (nth 1 (mail-extract-address-components cc))
1958 to-list)))
1959 (gnus-article-hide-header "cc"))))
1960 ((eq elem 'followup-to)
1961 (when (gnus-string-equal
1962 (message-fetch-field "followup-to")
1963 (message-fetch-field "newsgroups"))
1964 (gnus-article-hide-header "followup-to")))
1965 ((eq elem 'reply-to)
1966 (if (gnus-group-find-parameter
1967 gnus-newsgroup-name 'broken-reply-to)
1968 (gnus-article-hide-header "reply-to")
1969 (let ((from (message-fetch-field "from"))
1970 (reply-to (message-fetch-field "reply-to")))
1971 (when
1972 (and
1973 from reply-to
1974 (ignore-errors
1975 (equal
1976 (sort (mapcar
1977 (lambda (x) (downcase (cadr x)))
1978 (mail-extract-address-components from t))
1979 'string<)
1980 (sort (mapcar
1981 (lambda (x) (downcase (cadr x)))
1982 (mail-extract-address-components reply-to t))
1983 'string<))))
1984 (gnus-article-hide-header "reply-to")))))
1985 ((eq elem 'date)
1986 (let ((date (with-current-buffer gnus-original-article-buffer
1987 ;; If date in `gnus-article-buffer' is localized
1988 ;; (`gnus-treat-date-user-defined'),
1989 ;; `days-between' might fail.
1990 (message-fetch-field "date"))))
1991 (when (and date
1992 (< (days-between (current-time-string) date)
1993 4))
1994 (gnus-article-hide-header "date"))))
1995 ((eq elem 'long-to)
1996 (let ((to (message-fetch-field "to"))
1997 (cc (message-fetch-field "cc")))
1998 (when (> (length to) 1024)
1999 (gnus-article-hide-header "to"))
2000 (when (> (length cc) 1024)
2001 (gnus-article-hide-header "cc"))))
2002 ((eq elem 'many-to)
2003 (let ((to-count 0)
2004 (cc-count 0))
2005 (goto-char (point-min))
2006 (while (re-search-forward "^to:" nil t)
2007 (setq to-count (1+ to-count)))
2008 (when (> to-count 1)
2009 (while (> to-count 0)
2010 (goto-char (point-min))
2011 (save-restriction
2012 (re-search-forward "^to:" nil nil to-count)
2013 (forward-line -1)
2014 (narrow-to-region (point) (point-max))
2015 (gnus-article-hide-header "to"))
2016 (setq to-count (1- to-count))))
2017 (goto-char (point-min))
2018 (while (re-search-forward "^cc:" nil t)
2019 (setq cc-count (1+ cc-count)))
2020 (when (> cc-count 1)
2021 (while (> cc-count 0)
2022 (goto-char (point-min))
2023 (save-restriction
2024 (re-search-forward "^cc:" nil nil cc-count)
2025 (forward-line -1)
2026 (narrow-to-region (point) (point-max))
2027 (gnus-article-hide-header "cc"))
2028 (setq cc-count (1- cc-count)))))))))))))
2029
2030 (defun gnus-article-hide-header (header)
2031 (save-excursion
2032 (goto-char (point-min))
2033 (when (re-search-forward (concat "^" header ":") nil t)
2034 (gnus-article-hide-text-type
2035 (point-at-bol)
2036 (progn
2037 (end-of-line)
2038 (if (re-search-forward "^[^ \t]" nil t)
2039 (match-beginning 0)
2040 (point-max)))
2041 'boring-headers))))
2042
2043 (defvar gnus-article-normalized-header-length 40
2044 "Length of normalized headers.")
2045
2046 (defun article-normalize-headers ()
2047 "Make all header lines 40 characters long."
2048 (interactive)
2049 (let ((inhibit-read-only t)
2050 column)
2051 (save-excursion
2052 (save-restriction
2053 (article-narrow-to-head)
2054 (while (not (eobp))
2055 (cond
2056 ((< (setq column (- (point-at-eol) (point)))
2057 gnus-article-normalized-header-length)
2058 (end-of-line)
2059 (insert (make-string
2060 (- gnus-article-normalized-header-length column)
2061 ? )))
2062 ((> column gnus-article-normalized-header-length)
2063 (gnus-put-text-property
2064 (progn
2065 (forward-char gnus-article-normalized-header-length)
2066 (point))
2067 (point-at-eol)
2068 'invisible t))
2069 (t
2070 ;; Do nothing.
2071 ))
2072 (forward-line 1))))))
2073
2074 (defun article-treat-dumbquotes ()
2075 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2076 Note that this function guesses whether a character is a sm*rtq**t* or
2077 not, so it should only be used interactively.
2078
2079 Sm*rtq**t*s are M****s***'s unilateral extension to the
2080 iso-8859-1 character map in an attempt to provide more quoting
2081 characters. If you see something like \\222 or \\264 where
2082 you're expecting some kind of apostrophe or quotation mark, then
2083 try this wash."
2084 (interactive)
2085 (article-translate-strings gnus-article-dumbquotes-map))
2086
2087 (defvar org-entities)
2088
2089 (defun article-treat-non-ascii ()
2090 "Translate many Unicode characters into their ASCII equivalents."
2091 (interactive)
2092 (require 'org-entities)
2093 (let ((table (make-char-table nil)))
2094 (dolist (elem org-entities)
2095 (when (and (listp elem)
2096 (= (length (nth 6 elem)) 1))
2097 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem))))
2098 (save-excursion
2099 (when (article-goto-body)
2100 (let ((inhibit-read-only t)
2101 replace props)
2102 (while (not (eobp))
2103 (if (not (setq replace (aref table (following-char))))
2104 (forward-char 1)
2105 (if (prog1
2106 (setq props (text-properties-at (point)))
2107 (delete-char 1))
2108 (add-text-properties (point) (progn (insert replace) (point))
2109 props)
2110 (insert replace)))))))))
2111
2112 (defun article-translate-strings (map)
2113 "Translate all string in the body of the article according to MAP.
2114 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2115 (save-excursion
2116 (when (article-goto-body)
2117 (let ((inhibit-read-only t))
2118 (dolist (elem map)
2119 (let ((from (car elem))
2120 (to (cadr elem)))
2121 (save-excursion
2122 (if (stringp from)
2123 (while (search-forward from nil t)
2124 (replace-match to))
2125 (while (not (eobp))
2126 (if (eq (following-char) from)
2127 (progn
2128 (delete-char 1)
2129 (insert to))
2130 (forward-char 1)))))))))))
2131
2132 (defun article-treat-overstrike ()
2133 "Translate overstrikes into bold text."
2134 (interactive)
2135 (save-excursion
2136 (when (article-goto-body)
2137 (let ((inhibit-read-only t))
2138 (while (search-forward "\b" nil t)
2139 (let ((next (char-after))
2140 (previous (char-after (- (point) 2))))
2141 ;; We do the boldification/underlining by hiding the
2142 ;; overstrikes and putting the proper text property
2143 ;; on the letters.
2144 (cond
2145 ((eq next previous)
2146 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2147 (put-text-property (point) (1+ (point)) 'face 'bold))
2148 ((eq next ?_)
2149 (gnus-article-hide-text-type
2150 (1- (point)) (1+ (point)) 'overstrike)
2151 (put-text-property
2152 (- (point) 2) (1- (point)) 'face 'underline))
2153 ((eq previous ?_)
2154 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2155 (put-text-property
2156 (point) (1+ (point)) 'face 'underline)))))))))
2157
2158 (defun article-treat-ansi-sequences ()
2159 "Translate ANSI SGR control sequences into overlays or extents."
2160 (interactive)
2161 (save-excursion
2162 (when (article-goto-body)
2163 (let ((inhibit-read-only t))
2164 (ansi-color-apply-on-region (point) (point-max))))))
2165
2166 (defun gnus-article-treat-unfold-headers ()
2167 "Unfold folded message headers.
2168 Only the headers that fit into the current window width will be
2169 unfolded."
2170 (interactive)
2171 (gnus-with-article-headers
2172 (let (length)
2173 (while (not (eobp))
2174 (save-restriction
2175 (mail-header-narrow-to-field)
2176 (let* ((header (buffer-string))
2177 (unfoldable
2178 (or (equal gnus-article-unfold-long-headers t)
2179 (and (stringp gnus-article-unfold-long-headers)
2180 (string-match gnus-article-unfold-long-headers
2181 header)))))
2182 (with-temp-buffer
2183 (insert header)
2184 (goto-char (point-min))
2185 (while (re-search-forward "\n[\t ]" nil t)
2186 (replace-match " " t t)))
2187 (setq length (- (point-max) (point-min) 1))
2188 (when (or unfoldable
2189 (< length (window-width)))
2190 (while (re-search-forward "\n[\t ]" nil t)
2191 (replace-match " " t t))))
2192 (goto-char (point-max)))))))
2193
2194 (defun gnus-article-treat-fold-headers ()
2195 "Fold message headers."
2196 (interactive)
2197 (gnus-with-article-headers
2198 (while (not (eobp))
2199 (save-restriction
2200 (mail-header-narrow-to-field)
2201 (mail-header-fold-field)
2202 (goto-char (point-max))))))
2203
2204 (defun gnus-treat-smiley ()
2205 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2206 (interactive)
2207 (gnus-with-article-buffer
2208 (if (memq 'smiley gnus-article-wash-types)
2209 (gnus-delete-images 'smiley)
2210 (article-goto-body)
2211 (let ((images (smiley-region (point) (point-max))))
2212 (when images
2213 (gnus-add-wash-type 'smiley)
2214 (dolist (image images)
2215 (gnus-add-image 'smiley image)))))))
2216
2217 (defun gnus-article-remove-images ()
2218 "Remove all images from the article buffer."
2219 (interactive)
2220 (gnus-with-article-buffer
2221 (save-restriction
2222 (widen)
2223 (dolist (elem gnus-article-image-alist)
2224 (gnus-delete-images (car elem))))))
2225
2226 (autoload 'w3m-toggle-inline-images "w3m")
2227
2228 (defun gnus-article-show-images ()
2229 "Show any images that are in the HTML-rendered article buffer.
2230 This only works if the article in question is HTML."
2231 (interactive)
2232 (gnus-with-article-buffer
2233 (save-restriction
2234 (widen)
2235 (if (eq mm-text-html-renderer 'w3m)
2236 (w3m-toggle-inline-images)
2237 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2238 'image-displayer))
2239 (destructuring-bind (start end function) region
2240 (funcall function (get-text-property start 'image-url)
2241 start end)))))))
2242
2243 (defun gnus-article-treat-fold-newsgroups ()
2244 "Unfold folded message headers.
2245 Only the headers that fit into the current window width will be
2246 unfolded."
2247 (interactive)
2248 (gnus-with-article-headers
2249 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2250 (save-restriction
2251 (mail-header-narrow-to-field)
2252 (while (re-search-forward ", *" nil t)
2253 (replace-match ", " t t))
2254 (mail-header-fold-field)
2255 (goto-char (point-max))))))
2256
2257 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2258 "Value of `truncate-lines' in Gnus Article buffer.
2259 Valid values are nil, t, `head', `first', `last', an integer or a
2260 predicate. See Info node `(gnus)Customizing Articles'."
2261 :version "23.1" ;; No Gnus
2262 :group 'gnus-article
2263 ;; :link '(custom-manual "(gnus)Customizing Articles")
2264 :type 'boolean)
2265
2266 (defun gnus-article-toggle-truncate-lines (&optional arg)
2267 "Toggle whether to fold or truncate long lines in article the buffer.
2268 If ARG is non-nil and not a number, toggle
2269 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2270 long lines if and only if arg is positive."
2271 (interactive "P")
2272 (cond
2273 ((and (numberp arg) (> arg 0))
2274 (setq gnus-article-truncate-lines t))
2275 ((numberp arg)
2276 (setq gnus-article-truncate-lines nil))
2277 (arg
2278 (setq gnus-article-truncate-lines
2279 (not gnus-article-truncate-lines))))
2280 (gnus-with-article-buffer
2281 (cond
2282 ((and (numberp arg) (> arg 0))
2283 (setq truncate-lines nil))
2284 ((numberp arg)
2285 (setq truncate-lines t)))
2286 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2287 ;; `toggle-truncate-lines' needs an argument.
2288 (toggle-truncate-lines)))
2289
2290 (defun gnus-article-treat-body-boundary ()
2291 "Place a boundary line at the end of the headers."
2292 (interactive)
2293 (when (and gnus-body-boundary-delimiter
2294 (> (length gnus-body-boundary-delimiter) 0))
2295 (gnus-with-article-headers
2296 (goto-char (point-max))
2297 (let ((start (point)))
2298 (insert "X-Boundary: ")
2299 (gnus-add-text-properties start (point) gnus-hidden-properties)
2300 (insert (let (str (max (window-width)))
2301 (while (>= max (length str))
2302 (setq str (concat str gnus-body-boundary-delimiter)))
2303 (substring str 0 max))
2304 "\n")
2305 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2306
2307 (defun article-fill-long-lines ()
2308 "Fill lines that are wider than the window width."
2309 (interactive)
2310 (save-excursion
2311 (let ((inhibit-read-only t)
2312 (width (window-width (get-buffer-window (current-buffer)))))
2313 (save-restriction
2314 (article-goto-body)
2315 (let ((adaptive-fill-mode nil)) ;Why? -sm
2316 (while (not (eobp))
2317 (end-of-line)
2318 (when (>= (current-column) (min fill-column width))
2319 (narrow-to-region (min (1+ (point)) (point-max))
2320 (point-at-bol))
2321 (let ((goback (point-marker)))
2322 (fill-paragraph nil)
2323 (goto-char (marker-position goback)))
2324 (widen))
2325 (forward-line 1)))))))
2326
2327 (defun article-capitalize-sentences ()
2328 "Capitalize the first word in each sentence."
2329 (interactive)
2330 (save-excursion
2331 (let ((inhibit-read-only t)
2332 (paragraph-start "^[\n\^L]"))
2333 (article-goto-body)
2334 (while (not (eobp))
2335 (capitalize-word 1)
2336 (forward-sentence)))))
2337
2338 (defun article-remove-cr ()
2339 "Remove trailing CRs and then translate remaining CRs into LFs."
2340 (interactive)
2341 (save-excursion
2342 (let ((inhibit-read-only t))
2343 (goto-char (point-min))
2344 (while (re-search-forward "\r+$" nil t)
2345 (replace-match "" t t))
2346 (goto-char (point-min))
2347 (while (search-forward "\r" nil t)
2348 (replace-match "\n" t t)))))
2349
2350 (defun article-remove-trailing-blank-lines ()
2351 "Remove all trailing blank lines from the article."
2352 (interactive)
2353 (save-excursion
2354 (let ((inhibit-read-only t))
2355 (goto-char (point-max))
2356 (delete-region
2357 (point)
2358 (progn
2359 (while (and (not (bobp))
2360 (looking-at "^[ \t]*$")
2361 (not (gnus-annotation-in-region-p
2362 (point) (point-at-eol))))
2363 (forward-line -1))
2364 (forward-line 1)
2365 (point))))))
2366
2367 (defvar gnus-face-properties-alist)
2368
2369 (defun article-display-face (&optional force)
2370 "Display any Face headers in the header."
2371 (interactive (list 'force))
2372 (let ((wash-face-p buffer-read-only))
2373 (gnus-with-article-headers
2374 ;; When displaying parts, this function can be called several times on
2375 ;; the same article, without any intended toggle semantic (as typing `W
2376 ;; D d' would have). So face deletion must occur only when we come from
2377 ;; an interactive command, that is when the *Article* buffer is
2378 ;; read-only.
2379 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2380 (gnus-delete-images 'face)
2381 (let ((from (message-fetch-field "from"))
2382 faces)
2383 (save-current-buffer
2384 (when (and wash-face-p
2385 (gnus-buffer-live-p gnus-original-article-buffer)
2386 (not (re-search-forward "^Face:[\t ]*" nil t)))
2387 (set-buffer gnus-original-article-buffer))
2388 (save-restriction
2389 (mail-narrow-to-head)
2390 (when (or force
2391 ;; Check whether this face is censored.
2392 (not (and gnus-article-x-face-too-ugly
2393 (or from
2394 (setq from (message-fetch-field "from")))
2395 (string-match gnus-article-x-face-too-ugly
2396 from))))
2397 (while (gnus-article-goto-header "Face")
2398 (push (mail-header-field-value) faces)))))
2399 (when faces
2400 (goto-char (point-min))
2401 (let (png image)
2402 (unless (setq from (gnus-article-goto-header "from"))
2403 (insert "From:")
2404 (setq from (point))
2405 (insert " [no 'from' set]\n"))
2406 (while faces
2407 (when (setq png (gnus-convert-face-to-png (pop faces)))
2408 (setq image
2409 (apply 'gnus-create-image png 'png t
2410 (cdr (assq 'png gnus-face-properties-alist))))
2411 (goto-char from)
2412 (when image
2413 (gnus-add-wash-type 'face)
2414 (gnus-add-image 'face image)
2415 (gnus-put-image image nil 'face)))))))))))
2416
2417 (defun article-display-x-face (&optional force)
2418 "Look for an X-Face header and display it if present."
2419 (interactive (list 'force))
2420 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2421 (gnus-with-article-headers
2422 ;; Delete the old process, if any.
2423 (when (process-status "article-x-face")
2424 (delete-process "article-x-face"))
2425 ;; See the comment in `article-display-face'.
2426 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2427 ;; We have already displayed X-Faces, so we remove them
2428 ;; instead.
2429 (gnus-delete-images 'xface)
2430 ;; Display X-Faces.
2431 (let ((from (message-fetch-field "from"))
2432 x-faces)
2433 (save-current-buffer
2434 (when (and wash-face-p
2435 (gnus-buffer-live-p gnus-original-article-buffer)
2436 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2437 ;; If type `W f', use gnus-original-article-buffer,
2438 ;; otherwise use the current buffer because displaying
2439 ;; RFC822 parts calls this function too.
2440 (set-buffer gnus-original-article-buffer))
2441 (save-restriction
2442 (mail-narrow-to-head)
2443 (and gnus-article-x-face-command
2444 (or force
2445 ;; Check whether this face is censored.
2446 (not (and gnus-article-x-face-too-ugly
2447 (or from
2448 (setq from (message-fetch-field "from")))
2449 (string-match gnus-article-x-face-too-ugly
2450 from))))
2451 (while (gnus-article-goto-header "X-Face")
2452 (push (mail-header-field-value) x-faces)))))
2453 (when x-faces
2454 ;; We display the face.
2455 (cond ((functionp gnus-article-x-face-command)
2456 ;; The command is a lisp function, so we call it.
2457 (mapc gnus-article-x-face-command x-faces))
2458 ((stringp gnus-article-x-face-command)
2459 ;; The command is a string, so we interpret the command
2460 ;; as a, well, command, and fork it off.
2461 (let ((process-connection-type nil))
2462 (gnus-set-process-query-on-exit-flag
2463 (start-process
2464 "article-x-face" nil shell-file-name
2465 shell-command-switch gnus-article-x-face-command)
2466 nil)
2467 ;; Sending multiple EOFs to xv doesn't work,
2468 ;; so we only do a single external face.
2469 (with-temp-buffer
2470 (insert (car x-faces))
2471 (process-send-region "article-x-face"
2472 (point-min) (point-max)))
2473 (process-send-eof "article-x-face")))
2474 (t
2475 (error "`%s' set to `%s' is not a function"
2476 gnus-article-x-face-command
2477 'gnus-article-x-face-command)))))))))
2478
2479 (defun article-decode-mime-words ()
2480 "Decode all MIME-encoded words in the article."
2481 (interactive)
2482 (gnus-with-article-buffer
2483 (let ((inhibit-point-motion-hooks t)
2484 (mail-parse-charset gnus-newsgroup-charset)
2485 (mail-parse-ignored-charsets
2486 (with-current-buffer gnus-summary-buffer
2487 gnus-newsgroup-ignored-charsets)))
2488 (mail-decode-encoded-word-region (point-min) (point-max)))))
2489
2490 (defun article-decode-charset (&optional prompt)
2491 "Decode charset-encoded text in the article.
2492 If PROMPT (the prefix), prompt for a coding system to use."
2493 (interactive "P")
2494 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2495 (inhibit-read-only t)
2496 (mail-parse-charset gnus-newsgroup-charset)
2497 (mail-parse-ignored-charsets
2498 (save-excursion (condition-case nil
2499 (set-buffer gnus-summary-buffer)
2500 (error))
2501 gnus-newsgroup-ignored-charsets))
2502 ct cte ctl charset format)
2503 (save-excursion
2504 (save-restriction
2505 (article-narrow-to-head)
2506 (setq ct (message-fetch-field "Content-Type" t)
2507 cte (message-fetch-field "Content-Transfer-Encoding" t)
2508 ctl (and ct (mail-header-parse-content-type ct))
2509 charset (cond
2510 (prompt
2511 (mm-read-coding-system "Charset to decode: "))
2512 (ctl
2513 (mail-content-type-get ctl 'charset)))
2514 format (and ctl (mail-content-type-get ctl 'format)))
2515 (when cte
2516 (setq cte (mail-header-strip cte)))
2517 (if (and ctl (not (string-match "/" (car ctl))))
2518 (setq ctl nil))
2519 (goto-char (point-max)))
2520 (forward-line 1)
2521 (save-restriction
2522 (narrow-to-region (point) (point-max))
2523 (when (and (eq mail-parse-charset 'gnus-decoded)
2524 (eq (mm-body-7-or-8) '8bit))
2525 ;; The text code could have been decoded.
2526 (setq charset mail-parse-charset))
2527 (when (and (or (not ctl)
2528 (equal (car ctl) "text/plain"))
2529 (not format)) ;; article with format will decode later.
2530 (mm-decode-body
2531 charset (and cte (intern (downcase
2532 (gnus-strip-whitespace cte))))
2533 (car ctl)))))))
2534
2535 (defun article-decode-encoded-words ()
2536 "Remove encoded-word encoding from headers."
2537 (let ((inhibit-point-motion-hooks t)
2538 (mail-parse-charset gnus-newsgroup-charset)
2539 (mail-parse-ignored-charsets
2540 (save-excursion (condition-case nil
2541 (set-buffer gnus-summary-buffer)
2542 (error))
2543 gnus-newsgroup-ignored-charsets))
2544 (inhibit-read-only t)
2545 end start)
2546 (goto-char (point-min))
2547 (when (search-forward "\n\n" nil 'move)
2548 (forward-line -1))
2549 (setq end (point))
2550 (while (not (bobp))
2551 (while (progn
2552 (forward-line -1)
2553 (and (not (bobp))
2554 (memq (char-after) '(?\t ? )))))
2555 (setq start (point))
2556 (if (looking-at "\
2557 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2558 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2559 (funcall gnus-decode-address-function start end)
2560 (funcall gnus-decode-header-function start end))
2561 (goto-char (setq end start)))))
2562
2563 (defun article-decode-group-name ()
2564 "Decode group names in Newsgroups, Followup-To and Xref headers."
2565 (let ((inhibit-point-motion-hooks t)
2566 (inhibit-read-only t)
2567 (method (gnus-find-method-for-group gnus-newsgroup-name))
2568 regexp)
2569 (when (and (or gnus-group-name-charset-method-alist
2570 gnus-group-name-charset-group-alist)
2571 (gnus-buffer-live-p gnus-original-article-buffer))
2572 (save-restriction
2573 (article-narrow-to-head)
2574 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2575 (with-current-buffer gnus-original-article-buffer
2576 (goto-char (point-min)))
2577 (setq regexp (concat "^" header
2578 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2579 (while (re-search-forward regexp nil t)
2580 (replace-match (save-match-data
2581 (gnus-decode-newsgroups
2582 ;; XXX how to use data in article buffer?
2583 (with-current-buffer gnus-original-article-buffer
2584 (re-search-forward regexp nil t)
2585 (match-string 1))
2586 gnus-newsgroup-name method))
2587 t t nil 1))
2588 (goto-char (point-min)))))))
2589
2590 (autoload 'idna-to-unicode "idna")
2591
2592 (defun article-decode-idna-rhs ()
2593 "Decode IDNA strings in RHS in various headers in current buffer.
2594 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2595 Mail-Reply-To: and Mail-Followup-To:."
2596 (when gnus-use-idna
2597 (save-restriction
2598 (let ((inhibit-point-motion-hooks t)
2599 (inhibit-read-only t))
2600 (article-narrow-to-head)
2601 (goto-char (point-min))
2602 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2603 (let (ace unicode)
2604 (when (save-match-data
2605 (and (setq ace (match-string 1))
2606 (save-excursion
2607 (and (re-search-backward "^[^ \t]" nil t)
2608 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2609 (setq unicode (idna-to-unicode ace))))
2610 (unless (string= ace unicode)
2611 (replace-match unicode nil nil nil 1)))))))))
2612
2613 (defun article-de-quoted-unreadable (&optional force read-charset)
2614 "Translate a quoted-printable-encoded article.
2615 If FORCE, decode the article whether it is marked as quoted-printable
2616 or not.
2617 If READ-CHARSET, ask for a coding system."
2618 (interactive (list 'force current-prefix-arg))
2619 (save-excursion
2620 (let ((inhibit-read-only t) type charset)
2621 (if (gnus-buffer-live-p gnus-original-article-buffer)
2622 (with-current-buffer gnus-original-article-buffer
2623 (setq type
2624 (gnus-fetch-field "content-transfer-encoding"))
2625 (let* ((ct (gnus-fetch-field "content-type"))
2626 (ctl (and ct (mail-header-parse-content-type ct))))
2627 (setq charset (and ctl
2628 (mail-content-type-get ctl 'charset)))
2629 (if (stringp charset)
2630 (setq charset (intern (downcase charset)))))))
2631 (if read-charset
2632 (setq charset (mm-read-coding-system "Charset: " charset)))
2633 (unless charset
2634 (setq charset gnus-newsgroup-charset))
2635 (when (or force
2636 (and type (let ((case-fold-search t))
2637 (string-match "quoted-printable" type))))
2638 (article-goto-body)
2639 (quoted-printable-decode-region
2640 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2641
2642 (defun article-de-base64-unreadable (&optional force read-charset)
2643 "Translate a base64 article.
2644 If FORCE, decode the article whether it is marked as base64 not.
2645 If READ-CHARSET, ask for a coding system."
2646 (interactive (list 'force current-prefix-arg))
2647 (save-excursion
2648 (let ((inhibit-read-only t) type charset)
2649 (if (gnus-buffer-live-p gnus-original-article-buffer)
2650 (with-current-buffer gnus-original-article-buffer
2651 (setq type
2652 (gnus-fetch-field "content-transfer-encoding"))
2653 (let* ((ct (gnus-fetch-field "content-type"))
2654 (ctl (and ct (mail-header-parse-content-type ct))))
2655 (setq charset (and ctl
2656 (mail-content-type-get ctl 'charset)))
2657 (if (stringp charset)
2658 (setq charset (intern (downcase charset)))))))
2659 (if read-charset
2660 (setq charset (mm-read-coding-system "Charset: " charset)))
2661 (unless charset
2662 (setq charset gnus-newsgroup-charset))
2663 (when (or force
2664 (and type (let ((case-fold-search t))
2665 (string-match "base64" type))))
2666 (article-goto-body)
2667 (save-restriction
2668 (narrow-to-region (point) (point-max))
2669 (base64-decode-region (point-min) (point-max))
2670 (mm-decode-coding-region
2671 (point-min) (point-max)
2672 (mm-charset-to-coding-system charset nil t)))))))
2673
2674 (eval-when-compile
2675 (require 'rfc1843))
2676
2677 (defun article-decode-HZ ()
2678 "Translate a HZ-encoded article."
2679 (interactive)
2680 (require 'rfc1843)
2681 (save-excursion
2682 (let ((inhibit-read-only t))
2683 (rfc1843-decode-region (point-min) (point-max)))))
2684
2685 (defun article-unsplit-urls ()
2686 "Remove the newlines that some other mailers insert into URLs."
2687 (interactive)
2688 (save-excursion
2689 (let ((inhibit-read-only t))
2690 (goto-char (point-min))
2691 (while (re-search-forward
2692 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2693 (replace-match "\\1\\3" t)))
2694 (when (called-interactively-p 'any)
2695 (gnus-treat-article nil))))
2696
2697 (defun article-wash-html ()
2698 "Format an HTML article."
2699 (interactive)
2700 (let ((handles nil)
2701 (buffer-read-only nil))
2702 (when (gnus-buffer-live-p gnus-original-article-buffer)
2703 (with-current-buffer gnus-original-article-buffer
2704 (setq handles (mm-dissect-buffer t t))))
2705 (article-goto-body)
2706 (delete-region (point) (point-max))
2707 (mm-enable-multibyte)
2708 (mm-inline-text-html handles)))
2709
2710 (defvar gnus-article-browse-html-temp-list nil
2711 "List of temporary files created by `gnus-article-browse-html-parts'.
2712 Internal variable.")
2713
2714 (defcustom gnus-article-browse-delete-temp 'ask
2715 "What to do with temporary files from `gnus-article-browse-html-parts'.
2716 If nil, don't delete temporary files. If it is t, delete them on
2717 exit from the summary buffer. If it is the symbol `file', query
2718 on each file, if it is `ask' ask once when exiting from the
2719 summary buffer."
2720 :group 'gnus-article
2721 :version "23.1" ;; No Gnus
2722 :type '(choice (const :tag "Don't delete" nil)
2723 (const :tag "Don't ask" t)
2724 (const :tag "Ask" ask)
2725 (const :tag "Ask for each file" file)))
2726
2727 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2728
2729 (defun gnus-article-browse-delete-temp-files (&optional how)
2730 "Delete temp-files created by `gnus-article-browse-html-parts'."
2731 (when (and gnus-article-browse-html-temp-list
2732 (progn
2733 (or how (setq how gnus-article-browse-delete-temp))
2734 (if (eq how 'ask)
2735 (let ((files (length gnus-article-browse-html-temp-list)))
2736 (or (gnus-y-or-n-p
2737 (if (= files 1)
2738 "Delete the temporary HTML file? "
2739 (format "Delete all %s temporary HTML files? "
2740 files)))
2741 (setq gnus-article-browse-html-temp-list nil)))
2742 how)))
2743 (dolist (file gnus-article-browse-html-temp-list)
2744 (cond ((file-directory-p file)
2745 (when (or (not (eq how 'file))
2746 (gnus-y-or-n-p
2747 (gnus-format-message
2748 "Delete temporary HTML file(s) in directory `%s'? "
2749 (file-name-as-directory file))))
2750 (gnus-delete-directory file)))
2751 ((file-exists-p file)
2752 (when (or (not (eq how 'file))
2753 (gnus-y-or-n-p
2754 (format "Delete temporary HTML file `%s'? " file)))
2755 (delete-file file)))))
2756 ;; Also remove file from the list when not deleted or if file doesn't
2757 ;; exist anymore.
2758 (setq gnus-article-browse-html-temp-list nil))
2759 gnus-article-browse-html-temp-list)
2760
2761 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2762 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2763 Return file name relative to the parent of DIRECTORY."
2764 (save-match-data
2765 (let (file afile)
2766 (catch 'found
2767 (dolist (handle handles)
2768 (cond
2769 ((not (listp handle)))
2770 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2771 ;; may create.
2772 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2773 ((equal (mm-handle-media-supertype handle) "multipart")
2774 (when (setq file (gnus-article-browse-html-save-cid-content
2775 cid handle directory))
2776 (throw 'found file)))
2777 ((equal (concat "<" cid ">") (mm-handle-id handle))
2778 (setq file (or (mm-handle-filename handle)
2779 (concat
2780 (make-temp-name "cid")
2781 (car (rassoc (car (mm-handle-type handle))
2782 mailcap-mime-extensions))))
2783 afile (expand-file-name file directory))
2784 (mm-save-part-to-file handle afile)
2785 (throw 'found (concat (file-name-nondirectory
2786 (directory-file-name directory))
2787 "/" file)))))))))
2788
2789 (defun gnus-article-browse-html-parts (list &optional header)
2790 "View all \"text/html\" parts from LIST.
2791 Recurse into multiparts. The optional HEADER that should be a decoded
2792 message header will be added to the bodies of the \"text/html\" parts."
2793 ;; Internal function used by `gnus-article-browse-html-article'.
2794 (let (type file charset content cid-dir tmp-file showed)
2795 ;; Find and show the html-parts.
2796 (dolist (handle list)
2797 ;; If HTML, show it:
2798 (cond ((not (listp handle)))
2799 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2800 (and (equal (car type) "message/external-body")
2801 (or header
2802 (setq file (mm-handle-filename handle)))
2803 (or (mm-handle-cache handle)
2804 (condition-case code
2805 (progn (mm-extern-cache-contents handle) t)
2806 (error
2807 (gnus-message 3 "%s" (error-message-string code))
2808 (when (>= gnus-verbose 3) (sit-for 2))
2809 nil)))
2810 (progn
2811 (setq handle (mm-handle-cache handle)
2812 type (mm-handle-type handle))
2813 (equal (car type) "text/html"))))
2814 (setq charset (mail-content-type-get type 'charset)
2815 content (mm-get-part handle))
2816 (with-temp-buffer
2817 (if (eq charset 'gnus-decoded)
2818 (mm-enable-multibyte)
2819 (mm-disable-multibyte))
2820 (insert content)
2821 ;; resolve cid contents
2822 (let ((case-fold-search t)
2823 st base regexp cid-file)
2824 (goto-char (point-min))
2825 (when (and (re-search-forward "<head[\t\n >]" nil t)
2826 (progn
2827 (setq st (match-end 0))
2828 (re-search-forward "</head[\t\n >]" nil t))
2829 (re-search-backward "<base\
2830 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2831 (setq base (match-string 1))
2832 (replace-match "<!--\\&-->")
2833 (setq st (point))
2834 (dolist (tag '(("a" . "href") ("form" . "action")
2835 ("img" . "src")))
2836 (setq regexp (concat "<" (car tag)
2837 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2838 (cdr tag) "=\"\\([^\"]+\\)"))
2839 (while (re-search-forward regexp nil t)
2840 (insert (prog1
2841 (condition-case nil
2842 (save-match-data
2843 (url-expand-file-name (match-string 1)
2844 base))
2845 (error (match-string 1)))
2846 (delete-region (match-beginning 1)
2847 (match-end 1)))))
2848 (goto-char st)))
2849 (while (re-search-forward "\
2850 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2851 nil t)
2852 (unless cid-dir
2853 (setq cid-dir (mm-make-temp-file "cid" t))
2854 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2855 (setq file nil
2856 content nil)
2857 (when (setq cid-file
2858 (gnus-article-browse-html-save-cid-content
2859 (match-string 2)
2860 (with-current-buffer gnus-article-buffer
2861 gnus-article-mime-handles)
2862 cid-dir))
2863 (replace-match cid-file nil nil nil 1))))
2864 (unless content (setq content (buffer-string))))
2865 (when (or charset header (not file))
2866 (setq tmp-file (mm-make-temp-file
2867 ;; Do we need to care for 8.3 filenames?
2868 "mm-" nil ".html")))
2869 ;; Add a meta html tag to specify charset and a header.
2870 (cond
2871 (header
2872 (let (title eheader body hcharset coding)
2873 (with-temp-buffer
2874 (mm-enable-multibyte)
2875 (setq case-fold-search t)
2876 (insert header "\n")
2877 (setq title (message-fetch-field "subject"))
2878 (goto-char (point-min))
2879 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2880 nil t)
2881 (replace-match (cond ((match-beginning 1) "&lt;")
2882 ((match-beginning 2) "&gt;")
2883 ((match-beginning 3) "&amp;")
2884 (t "<br>\n"))))
2885 (goto-char (point-min))
2886 (while (re-search-forward "^[\t ]+" nil t)
2887 (dotimes (i (prog1
2888 (current-column)
2889 (delete-region (match-beginning 0)
2890 (match-end 0))))
2891 (insert "&nbsp;")))
2892 (goto-char (point-min))
2893 (insert "<div align=\"left\">\n")
2894 (goto-char (point-max))
2895 (insert "</div>\n<hr>\n")
2896 ;; We have to examine charset one by one since
2897 ;; charset specified in parts might be different.
2898 (if (eq charset 'gnus-decoded)
2899 (setq charset 'utf-8
2900 eheader (mm-encode-coding-string (buffer-string)
2901 charset)
2902 title (when title
2903 (mm-encode-coding-string title charset))
2904 body (mm-encode-coding-string content charset))
2905 (setq hcharset (mm-find-mime-charset-region (point-min)
2906 (point-max)))
2907 (cond ((= (length hcharset) 1)
2908 (setq hcharset (car hcharset)
2909 coding (mm-charset-to-coding-system
2910 hcharset nil t)))
2911 ((> (length hcharset) 1)
2912 (setq hcharset 'utf-8
2913 coding hcharset)))
2914 (if coding
2915 (if charset
2916 (progn
2917 (setq body
2918 (mm-charset-to-coding-system charset
2919 nil t))
2920 (if (eq coding body)
2921 (setq eheader (mm-encode-coding-string
2922 (buffer-string) coding)
2923 title (when title
2924 (mm-encode-coding-string
2925 title coding))
2926 body content)
2927 (setq charset 'utf-8
2928 eheader (mm-encode-coding-string
2929 (buffer-string) charset)
2930 title (when title
2931 (mm-encode-coding-string
2932 title charset))
2933 body (mm-encode-coding-string
2934 (mm-decode-coding-string
2935 content body)
2936 charset))))
2937 (setq charset hcharset
2938 eheader (mm-encode-coding-string
2939 (buffer-string) coding)
2940 title (when title
2941 (mm-encode-coding-string
2942 title coding))
2943 body content))
2944 (setq eheader (mm-string-as-unibyte (buffer-string))
2945 body content)))
2946 (erase-buffer)
2947 (mm-disable-multibyte)
2948 (insert body)
2949 (when charset
2950 (mm-add-meta-html-tag handle charset t))
2951 (when title
2952 (goto-char (point-min))
2953 (unless (search-forward "<title>" nil t)
2954 (re-search-forward "<head>\\s-*" nil t)
2955 (insert "<title>" title "</title>\n")))
2956 (goto-char (point-min))
2957 (or (re-search-forward
2958 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2959 (re-search-forward
2960 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2961 (insert eheader)
2962 (mm-write-region (point-min) (point-max)
2963 tmp-file nil nil nil 'binary t))))
2964 (charset
2965 (mm-with-unibyte-buffer
2966 (insert (if (eq charset 'gnus-decoded)
2967 (mm-encode-coding-string content
2968 (setq charset 'utf-8))
2969 content))
2970 (if (or (mm-add-meta-html-tag handle charset)
2971 (not file))
2972 (mm-write-region (point-min) (point-max)
2973 tmp-file nil nil nil 'binary t)
2974 (setq tmp-file nil))))
2975 (tmp-file
2976 (mm-save-part-to-file handle tmp-file)))
2977 (when tmp-file
2978 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2979 (add-hook 'gnus-summary-prepare-exit-hook
2980 'gnus-article-browse-delete-temp-files)
2981 (add-hook 'gnus-exit-gnus-hook
2982 (lambda ()
2983 (gnus-article-browse-delete-temp-files t)))
2984 ;; FIXME: Warn if there's an <img> tag?
2985 (browse-url-of-file (or tmp-file (expand-file-name file)))
2986 (setq showed t))
2987 ;; If multipart, recurse
2988 ((equal (mm-handle-media-supertype handle) "multipart")
2989 (when (gnus-article-browse-html-parts handle header)
2990 (setq showed t)))
2991 ((equal (mm-handle-media-type handle) "message/rfc822")
2992 (mm-with-multibyte-buffer
2993 (mm-insert-part handle)
2994 (setq handle (mm-dissect-buffer t t))
2995 (when (and (bufferp (car handle))
2996 (stringp (car (mm-handle-type handle))))
2997 (setq handle (list handle)))
2998 (when header
2999 (article-decode-encoded-words)
3000 (let ((gnus-visible-headers
3001 (or (get 'gnus-visible-headers 'standard-value)
3002 gnus-visible-headers)))
3003 (article-hide-headers))
3004 (goto-char (point-min))
3005 (search-forward "\n\n" nil 'move)
3006 (skip-chars-backward "\t\n ")
3007 (setq header (buffer-substring (point-min) (point)))))
3008 (when (prog1
3009 (gnus-article-browse-html-parts handle header)
3010 (mm-destroy-parts handle))
3011 (setq showed t)))))
3012 showed))
3013
3014 (defun gnus-article-browse-html-article (&optional arg)
3015 "View \"text/html\" parts of the current article with a WWW browser.
3016 Inline images embedded in a message using the cid scheme, as they are
3017 generally considered to be safe, will be processed properly.
3018 The message header is added to the beginning of every html part unless
3019 the prefix argument ARG is given.
3020
3021 Warning: Spammers use links to images (using the http scheme) in HTML
3022 articles to verify whether you have read the message. As
3023 `gnus-article-browse-html-article' passes the HTML content to the
3024 browser without eliminating these \"web bugs\" you should only
3025 use it for mails from trusted senders.
3026
3027 If you always want to display HTML parts in the browser, set
3028 `mm-text-html-renderer' to nil.
3029
3030 This command creates temporary files to pass HTML contents including
3031 images if any to the browser, and deletes them when exiting the group
3032 \(if you want)."
3033 ;; Cf. `mm-w3m-safe-url-regexp'
3034 (interactive "P")
3035 (if arg
3036 (gnus-summary-show-article)
3037 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3038 gnus-visible-headers))
3039 ;; As we insert a <hr>, there's no need for the body boundary.
3040 (gnus-treat-body-boundary nil))
3041 (gnus-summary-show-article)))
3042 (with-current-buffer gnus-article-buffer
3043 (let ((header (unless arg
3044 (save-restriction
3045 (widen)
3046 (buffer-substring-no-properties
3047 (goto-char (point-min))
3048 (if (search-forward "\n\n" nil t)
3049 (match-beginning 0)
3050 (goto-char (point-max))
3051 (skip-chars-backward "\t\n ")
3052 (point))))))
3053 parts)
3054 (set-buffer gnus-original-article-buffer)
3055 (setq parts (mm-dissect-buffer t t))
3056 ;; If singlepart, enforce a list.
3057 (when (and (bufferp (car parts))
3058 (stringp (car (mm-handle-type parts))))
3059 (setq parts (list parts)))
3060 ;; Process the list
3061 (unless (gnus-article-browse-html-parts parts header)
3062 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3063 (mm-destroy-parts parts)
3064 (unless arg
3065 (gnus-summary-show-article)))))
3066
3067 (defun article-hide-list-identifiers ()
3068 "Remove list identifiers from the Subject header.
3069 The `gnus-list-identifiers' variable specifies what to do."
3070 (interactive)
3071 (let ((inhibit-point-motion-hooks t)
3072 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3073 (inhibit-read-only t))
3074 (when regexp
3075 (save-excursion
3076 (save-restriction
3077 (article-narrow-to-head)
3078 (goto-char (point-min))
3079 (while (re-search-forward
3080 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3081 nil t)
3082 (delete-region (match-beginning 2) (match-end 0))
3083 (beginning-of-line))
3084 (when (re-search-forward
3085 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3086 (delete-region (match-beginning 1) (match-end 1))))))))
3087
3088 (defun article-hide-pem (&optional arg)
3089 "Toggle hiding of any PEM headers and signatures in the current article.
3090 If given a negative prefix, always show; if given a positive prefix,
3091 always hide."
3092 (interactive (gnus-article-hidden-arg))
3093 (unless (gnus-article-check-hidden-text 'pem arg)
3094 (save-excursion
3095 (let ((inhibit-read-only t) end)
3096 (goto-char (point-min))
3097 ;; Hide the horrendously ugly "header".
3098 (when (and (search-forward
3099 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3100 nil t)
3101 (setq end (1+ (match-beginning 0))))
3102 (gnus-add-wash-type 'pem)
3103 (gnus-article-hide-text-type
3104 end
3105 (if (search-forward "\n\n" nil t)
3106 (match-end 0)
3107 (point-max))
3108 'pem)
3109 ;; Hide the trailer as well
3110 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3111 nil t)
3112 (gnus-article-hide-text-type
3113 (match-beginning 0) (match-end 0) 'pem)))))))
3114
3115 (defun article-strip-banner ()
3116 "Strip the banners specified by the `banner' group parameter and by
3117 `gnus-article-address-banner-alist'."
3118 (interactive)
3119 (save-excursion
3120 (save-restriction
3121 (let ((inhibit-point-motion-hooks t))
3122 (when (gnus-parameter-banner gnus-newsgroup-name)
3123 (article-really-strip-banner
3124 (gnus-parameter-banner gnus-newsgroup-name)))
3125 (when gnus-article-address-banner-alist
3126 ;; Note that the From header is decoded here, so it is
3127 ;; required that the *-extract-address-components function
3128 ;; supports non-ASCII text.
3129 (let ((from (save-restriction
3130 (widen)
3131 (article-narrow-to-head)
3132 (mail-fetch-field "from"))))
3133 (when (and from
3134 (setq from
3135 (cadr (funcall gnus-extract-address-components
3136 from))))
3137 (catch 'found
3138 (dolist (pair gnus-article-address-banner-alist)
3139 (when (string-match (car pair) from)
3140 (throw 'found
3141 (article-really-strip-banner (cdr pair)))))))))))))
3142
3143 (defun article-really-strip-banner (banner)
3144 "Strip the banner specified by the argument."
3145 (save-excursion
3146 (save-restriction
3147 (let ((inhibit-point-motion-hooks t)
3148 (gnus-signature-limit nil)
3149 (inhibit-read-only t))
3150 (article-goto-body)
3151 (cond
3152 ((eq banner 'signature)
3153 (when (gnus-article-narrow-to-signature)
3154 (widen)
3155 (forward-line -1)
3156 (delete-region (point) (point-max))))
3157 ((symbolp banner)
3158 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3159 (while (re-search-forward banner nil t)
3160 (delete-region (match-beginning 0) (match-end 0)))))
3161 ((stringp banner)
3162 (while (re-search-forward banner nil t)
3163 (delete-region (match-beginning 0) (match-end 0)))))))))
3164
3165 (defun article-babel ()
3166 "Translate article using an online translation service."
3167 (interactive)
3168 (require 'babel)
3169 (gnus-with-article-buffer
3170 (when (article-goto-body)
3171 (let* ((start (point))
3172 (end (point-max))
3173 (orig (buffer-substring start end))
3174 (trans (babel-as-string orig)))
3175 (save-restriction
3176 (narrow-to-region start end)
3177 (delete-region start end)
3178 (insert trans))))))
3179
3180 (defun article-hide-signature (&optional arg)
3181 "Hide the signature in the current article.
3182 If given a negative prefix, always show; if given a positive prefix,
3183 always hide."
3184 (interactive (gnus-article-hidden-arg))
3185 (unless (gnus-article-check-hidden-text 'signature arg)
3186 (save-excursion
3187 (save-restriction
3188 (let ((inhibit-read-only t))
3189 (when (gnus-article-narrow-to-signature)
3190 (gnus-article-hide-text-type
3191 (point-min) (point-max) 'signature))))))
3192 (gnus-set-mode-line 'article))
3193
3194 (defun article-strip-headers-in-body ()
3195 "Strip offensive headers from bodies."
3196 (interactive)
3197 (save-excursion
3198 (article-goto-body)
3199 (let ((case-fold-search t))
3200 (when (looking-at "x-no-archive:")
3201 (gnus-delete-line)))))
3202
3203 (defun article-strip-leading-blank-lines ()
3204 "Remove all blank lines from the beginning of the article."
3205 (interactive)
3206 (save-excursion
3207 (let ((inhibit-point-motion-hooks t)
3208 (inhibit-read-only t))
3209 (when (article-goto-body)
3210 (while (and (not (eobp))
3211 (looking-at "[ \t]*$"))
3212 (gnus-delete-line))))))
3213
3214 (defun article-narrow-to-head ()
3215 "Narrow the buffer to the head of the message.
3216 Point is left at the beginning of the narrowed-to region."
3217 (narrow-to-region
3218 (goto-char (point-min))
3219 (cond
3220 ;; Absolutely no headers displayed.
3221 ((looking-at "\n")
3222 (point))
3223 ;; Normal headers.
3224 ((search-forward "\n\n" nil 1)
3225 (1- (point)))
3226 ;; Nothing but headers.
3227 (t
3228 (point-max))))
3229 (goto-char (point-min)))
3230
3231 (defun article-goto-body ()
3232 "Place point at the start of the body."
3233 (goto-char (point-min))
3234 (cond
3235 ;; This variable is only bound when dealing with separate
3236 ;; MIME body parts.
3237 (article-goto-body-goes-to-point-min-p
3238 t)
3239 ((search-forward "\n\n" nil t)
3240 t)
3241 (t
3242 (goto-char (point-max))
3243 nil)))
3244
3245 (defun article-strip-multiple-blank-lines ()
3246 "Replace consecutive blank lines with one empty line."
3247 (interactive)
3248 (save-excursion
3249 (let ((inhibit-point-motion-hooks t)
3250 (inhibit-read-only t))
3251 ;; First make all blank lines empty.
3252 (article-goto-body)
3253 (while (re-search-forward "^[ \t]+$" nil t)
3254 (unless (gnus-annotation-in-region-p
3255 (match-beginning 0) (match-end 0))
3256 (replace-match "" nil t)))
3257 ;; Then replace multiple empty lines with a single empty line.
3258 (article-goto-body)
3259 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3260 (unless (gnus-annotation-in-region-p
3261 (match-beginning 0) (match-end 0))
3262 (delete-region (match-beginning 1) (match-end 1)))))))
3263
3264 (defun article-strip-leading-space ()
3265 "Remove all white space from the beginning of the lines in the article."
3266 (interactive)
3267 (save-excursion
3268 (let ((inhibit-point-motion-hooks t)
3269 (inhibit-read-only t))
3270 (article-goto-body)
3271 (while (re-search-forward "^[ \t]+" nil t)
3272 (replace-match "" t t)))))
3273
3274 (defun article-strip-trailing-space ()
3275 "Remove all white space from the end of the lines in the article."
3276 (interactive)
3277 (save-excursion
3278 (let ((inhibit-point-motion-hooks t)
3279 (inhibit-read-only t))
3280 (article-goto-body)
3281 (while (re-search-forward "[ \t]+$" nil t)
3282 (replace-match "" t t)))))
3283
3284 (defun article-strip-blank-lines ()
3285 "Strip leading, trailing and multiple blank lines."
3286 (interactive)
3287 (article-strip-leading-blank-lines)
3288 (article-remove-trailing-blank-lines)
3289 (article-strip-multiple-blank-lines))
3290
3291 (defun article-strip-all-blank-lines ()
3292 "Strip all blank lines."
3293 (interactive)
3294 (save-excursion
3295 (let ((inhibit-point-motion-hooks t)
3296 (inhibit-read-only t))
3297 (article-goto-body)
3298 (while (re-search-forward "^[ \t]*\n" nil t)
3299 (replace-match "" t t)))))
3300
3301 (defun gnus-article-narrow-to-signature ()
3302 "Narrow to the signature; return t if a signature is found, else nil."
3303 (let ((inhibit-point-motion-hooks t))
3304 (when (gnus-article-search-signature)
3305 (forward-line 1)
3306 ;; Check whether we have some limits to what we consider
3307 ;; to be a signature.
3308 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3309 (list gnus-signature-limit)))
3310 limit limited)
3311 (while (setq limit (pop limits))
3312 (if (or (and (integerp limit)
3313 (< (- (point-max) (point)) limit))
3314 (and (floatp limit)
3315 (< (count-lines (point) (point-max)) limit))
3316 (and (functionp limit)
3317 (funcall limit))
3318 (and (stringp limit)
3319 (not (re-search-forward limit nil t))))
3320 () ; This limit did not succeed.
3321 (setq limited t
3322 limits nil)))
3323 (unless limited
3324 (narrow-to-region (point) (point-max))
3325 t)))))
3326
3327 (defun gnus-article-search-signature ()
3328 "Search the current buffer for the signature separator.
3329 Put point at the beginning of the signature separator."
3330 (let ((cur (point)))
3331 (goto-char (point-max))
3332 (if (if (stringp gnus-signature-separator)
3333 (re-search-backward gnus-signature-separator nil t)
3334 (let ((seps gnus-signature-separator))
3335 (while (and seps
3336 (not (re-search-backward (car seps) nil t)))
3337 (pop seps))
3338 seps))
3339 t
3340 (goto-char cur)
3341 nil)))
3342
3343 (defun gnus-article-hidden-arg ()
3344 "Return the current prefix arg as a number, or 0 if no prefix."
3345 (list (if current-prefix-arg
3346 (prefix-numeric-value current-prefix-arg)
3347 0)))
3348
3349 (defun gnus-article-check-hidden-text (type arg)
3350 "Return nil if hiding is necessary.
3351 Arg can be nil or a number. nil and positive means hide, negative
3352 means show, 0 means toggle."
3353 (save-excursion
3354 (save-restriction
3355 (let ((hide (gnus-article-hidden-text-p type)))
3356 (cond
3357 ((or (null arg)
3358 (> arg 0))
3359 nil)
3360 ((< arg 0)
3361 (gnus-article-show-hidden-text type)
3362 t)
3363 (t
3364 (if (eq hide 'hidden)
3365 (progn
3366 (gnus-article-show-hidden-text type)
3367 t)
3368 nil)))))))
3369
3370 (defun gnus-article-hidden-text-p (type)
3371 "Say whether the current buffer contains hidden text of type TYPE."
3372 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3373 (while (and pos
3374 (not (get-text-property pos 'invisible))
3375 (not (get-text-property pos 'dummy-invisible)))
3376 (setq pos
3377 (text-property-any (1+ pos) (point-max) 'article-type type)))
3378 (if pos
3379 'hidden
3380 nil)))
3381
3382 (defun gnus-article-show-hidden-text (type &optional _dummy)
3383 "Show all hidden text of type TYPE.
3384 Originally it is hide instead of DUMMY."
3385 (let ((inhibit-read-only t)
3386 (inhibit-point-motion-hooks t))
3387 (gnus-remove-text-properties-when
3388 'article-type type
3389 (point-min) (point-max)
3390 (cons 'article-type (cons type
3391 gnus-hidden-properties)))
3392 (gnus-delete-wash-type type)))
3393
3394 (defconst article-time-units
3395 `((year . ,(* 365.25 24 60 60))
3396 (week . ,(* 7 24 60 60))
3397 (day . ,(* 24 60 60))
3398 (hour . ,(* 60 60))
3399 (minute . 60)
3400 (second . 1))
3401 "Mapping from time units to seconds.")
3402
3403 (defun gnus-article-forward-header ()
3404 "Move point to the start of the next header.
3405 If the current header is a continuation header, this can be several
3406 lines forward."
3407 (let ((ended nil))
3408 (while (not ended)
3409 (forward-line 1)
3410 (if (looking-at "[ \t]+[^ \t]")
3411 (forward-line 1)
3412 (setq ended t)))))
3413
3414 (defun article-treat-date ()
3415 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3416 (with-current-buffer gnus-summary-buffer
3417 gnus-article-date-headers)
3418 gnus-article-date-headers)
3419 t))
3420
3421 (defun article-date-ut (&optional type _highlight date-position)
3422 "Convert DATE date to TYPE in the current article.
3423 The default type is `ut'. See `gnus-article-date-headers' for
3424 possible values."
3425 (interactive (list 'ut t))
3426 (let* ((case-fold-search t)
3427 (inhibit-read-only t)
3428 (inhibit-point-motion-hooks t)
3429 (visible-date (mail-fetch-field "Date"))
3430 pos date bface eface)
3431 (save-excursion
3432 (if date-position
3433 (progn
3434 (goto-char date-position)
3435 (setq date (get-text-property (point) 'original-date))
3436 (when (looking-at "[^:]+:[\t ]*")
3437 (setq bface (get-text-property (match-beginning 0) 'face)
3438 eface (get-text-property (match-end 0) 'face)))
3439 (delete-region (point)
3440 (progn
3441 (gnus-article-forward-header)
3442 (point)))
3443 (article-transform-date date type bface eface))
3444 (save-restriction
3445 (widen)
3446 (goto-char (point-min))
3447 (while (or (get-text-property (setq pos (point)) 'original-date)
3448 (and (setq pos (next-single-property-change
3449 (point) 'original-date))
3450 (goto-char pos)))
3451 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3452 (1+ (match-beginning 0))
3453 (point-max)))
3454 (while (setq pos (text-property-not-all pos (point-max)
3455 'gnus-date-type nil))
3456 (setq date (get-text-property pos 'original-date))
3457 (goto-char pos)
3458 (when (looking-at "[^:]+:[\t ]*")
3459 (setq bface (get-text-property (match-beginning 0) 'face)
3460 eface (get-text-property (match-end 0) 'face)))
3461 (delete-region pos (or (text-property-any pos (point-max)
3462 'gnus-date-type nil)
3463 (point-max))))
3464 (unless date ;; the 1st time
3465 (goto-char (point-min))
3466 (while (re-search-forward "^Date:[\t ]*" nil t)
3467 (setq date (get-text-property (match-beginning 0)
3468 'original-date)
3469 bface (get-text-property (match-beginning 0) 'face)
3470 eface (get-text-property (match-end 0) 'face))
3471 (delete-region (point-at-bol) (progn
3472 (gnus-article-forward-header)
3473 (point)))))
3474 (when (and (not date)
3475 visible-date)
3476 (setq date visible-date))
3477 (when date
3478 (article-transform-date date type bface eface))
3479 (goto-char (point-max))
3480 (widen)))))))
3481
3482 (defun article-transform-date (date type bface eface)
3483 (dolist (this-type (cond
3484 ((null type)
3485 (list 'ut))
3486 ((atom type)
3487 (list type))
3488 (t
3489 type)))
3490 (goto-char
3491 (prog1
3492 (point)
3493 (add-text-properties
3494 (point)
3495 (progn
3496 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3497 (point))
3498 (list 'original-date date 'gnus-date-type this-type))))
3499 ;; Do highlighting.
3500 (when (looking-at
3501 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3502 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3503 (when (match-beginning 2)
3504 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3505 (while (and (zerop (forward-line 1))
3506 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3507 (when (match-beginning 1)
3508 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3509
3510 (defun article-make-date-line (date type)
3511 "Return a DATE line of TYPE."
3512 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3513 combined-lapsed))
3514 (error "Unknown conversion type: %s" type))
3515 (condition-case ()
3516 (let ((time (ignore-errors (date-to-time date))))
3517 (cond
3518 ;; Convert to the local timezone.
3519 ((eq type 'local)
3520 (concat "Date: " (message-make-date time)))
3521 ;; Convert to Universal Time.
3522 ((eq type 'ut)
3523 (concat "Date: "
3524 (substring
3525 (message-make-date
3526 (let* ((e (parse-time-string date))
3527 (tm (apply 'encode-time e))
3528 (ms (car tm))
3529 (ls (- (cadr tm) (car (current-time-zone time)))))
3530 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3531 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3532 (t (list ms ls)))))
3533 0 -5)
3534 "UT"))
3535 ;; Get the original date from the article.
3536 ((eq type 'original)
3537 (concat "Date: " (if (string-match "\n+$" date)
3538 (substring date 0 (match-beginning 0))
3539 date)))
3540 ;; Let the user define the format.
3541 ((eq type 'user-defined)
3542 (let ((format (or (condition-case nil
3543 (with-current-buffer gnus-summary-buffer
3544 gnus-article-time-format)
3545 (error nil))
3546 gnus-article-time-format)))
3547 (if (functionp format)
3548 (funcall format time)
3549 (concat "Date: " (format-time-string format time)))))
3550 ;; ISO 8601.
3551 ((eq type 'iso8601)
3552 (let ((tz (car (current-time-zone time))))
3553 (concat
3554 "Date: "
3555 (format-time-string "%Y%m%dT%H%M%S" time)
3556 (format "%s%02d%02d"
3557 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3558 (/ (% (abs tz) 3600) 60)))))
3559 ;; Do a lapsed format.
3560 ((eq type 'lapsed)
3561 (concat "Date: " (article-lapsed-string time)))
3562 ;; A combined date/lapsed format.
3563 ((eq type 'combined-lapsed)
3564 (let ((date-string (article-make-date-line date 'original))
3565 (segments 3)
3566 lapsed-string)
3567 (while (and
3568 time
3569 (setq lapsed-string
3570 (concat " (" (article-lapsed-string time segments) ")"))
3571 (> (+ (length date-string)
3572 (length lapsed-string))
3573 (+ fill-column 6))
3574 (> segments 0))
3575 (setq segments (1- segments)))
3576 (if (> segments 0)
3577 (concat date-string lapsed-string)
3578 date-string)))
3579 ;; Display the date in proper English
3580 ((eq type 'english)
3581 (let ((dtime (decode-time time)))
3582 (concat
3583 "Date: the "
3584 (number-to-string (nth 3 dtime))
3585 (let ((digit (% (nth 3 dtime) 10)))
3586 (cond
3587 ((memq (nth 3 dtime) '(11 12 13)) "th")
3588 ((= digit 1) "st")
3589 ((= digit 2) "nd")
3590 ((= digit 3) "rd")
3591 (t "th")))
3592 " of "
3593 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3594 " "
3595 (number-to-string (nth 5 dtime))
3596 " at "
3597 (format "%02d" (nth 2 dtime))
3598 ":"
3599 (format "%02d" (nth 1 dtime)))))))
3600 (foo
3601 (format "Date: %s (from Gnus)" date))))
3602
3603 (defun article-lapsed-string (time &optional max-segments)
3604 ;; If the date is seriously mangled, the timezone functions are
3605 ;; liable to bug out, so we ignore all errors.
3606 (let* ((now (current-time))
3607 (real-time (subtract-time now time))
3608 (real-sec (and real-time
3609 (+ (* (float (car real-time)) 65536)
3610 (cadr real-time))))
3611 (sec (and real-time (abs real-sec)))
3612 (segments 0)
3613 num prev)
3614 (unless max-segments
3615 (setq max-segments (length article-time-units)))
3616 (cond
3617 ((null real-time)
3618 "Unknown")
3619 ((zerop sec)
3620 "Now")
3621 (t
3622 (concat
3623 ;; This is a bit convoluted, but basically we go
3624 ;; through the time units for years, weeks, etc,
3625 ;; and divide things to see whether that results
3626 ;; in positive answers.
3627 (mapconcat
3628 (lambda (unit)
3629 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3630 (>= segments max-segments))
3631 ;; The (remaining) seconds are too few to
3632 ;; be divided into this time unit.
3633 ""
3634 ;; It's big enough, so we output it.
3635 (setq sec (- sec (* num (cdr unit))))
3636 (prog1
3637 (concat (if prev ", " "") (int-to-string
3638 (floor num))
3639 " " (symbol-name (car unit))
3640 (if (> num 1) "s" ""))
3641 (setq prev t
3642 segments (1+ segments)))))
3643 article-time-units "")
3644 ;; If dates are odd, then it might appear like the
3645 ;; article was sent in the future.
3646 (if (> real-sec 0)
3647 " ago"
3648 " in the future"))))))
3649
3650 (defun article-date-local (&optional highlight)
3651 "Convert the current article date to the local timezone."
3652 (interactive (list t))
3653 (article-date-ut 'local highlight))
3654
3655 (defun article-date-english (&optional highlight)
3656 "Convert the current article date to something that is proper English."
3657 (interactive (list t))
3658 (article-date-ut 'english highlight))
3659
3660 (defun article-date-original (&optional highlight)
3661 "Convert the current article date to what it was originally.
3662 This is only useful if you have used some other date conversion
3663 function and want to see what the date was before converting."
3664 (interactive (list t))
3665 (article-date-ut 'original highlight))
3666
3667 (defun article-date-lapsed (&optional highlight)
3668 "Convert the current article date to time lapsed since it was sent."
3669 (interactive (list t))
3670 (article-date-ut 'lapsed highlight))
3671
3672 (defun article-date-combined-lapsed (&optional highlight)
3673 "Convert the current article date to time lapsed since it was sent."
3674 (interactive (list t))
3675 (article-date-ut 'combined-lapsed highlight))
3676
3677 (defun article-update-date-lapsed ()
3678 "Function to be run from a timer to update the lapsed time line."
3679 (save-match-data
3680 (let ((buffer (current-buffer)))
3681 (ignore-errors
3682 (walk-windows
3683 (lambda (w)
3684 (set-buffer (window-buffer w))
3685 (when (derived-mode-p 'gnus-article-mode)
3686 (let ((old-line (count-lines (point-min) (point)))
3687 (old-column (- (point) (line-beginning-position)))
3688 (window-start (window-start w))
3689 (pos (point-min))
3690 type next end)
3691 (while (setq pos (text-property-not-all pos (point-max)
3692 'gnus-date-type nil))
3693 (setq next (or (next-single-property-change pos
3694 'gnus-date-type)
3695 (point-max)))
3696 (setq type (get-text-property pos 'gnus-date-type))
3697 (when (memq type '(lapsed combined-lapsed user-defined))
3698 (article-date-ut type t pos)
3699 (setq end (or (next-single-property-change pos
3700 'gnus-date-type)
3701 (point-max)))
3702 (when window-start
3703 (if (/= window-start next)
3704 (setq window-start nil)
3705 (set-window-start w end)))
3706 (setq next end))
3707 (setq pos next))
3708 (goto-char (point-min))
3709 (when (> old-column 0)
3710 (setq old-line (1- old-line)))
3711 (forward-line old-line)
3712 (end-of-line)
3713 (when (> (current-column) old-column)
3714 (beginning-of-line)
3715 (forward-char old-column)))))
3716 nil 'visible))
3717 (set-buffer buffer))))
3718
3719 (defun gnus-start-date-timer (&optional n)
3720 "Start a timer to update the Date headers in the article buffers.
3721 The numerical prefix says how frequently (in seconds) the function
3722 is to run."
3723 (interactive "p")
3724 (unless n
3725 (setq n 1))
3726 (gnus-stop-date-timer)
3727 (setq article-lapsed-timer
3728 (run-at-time 1 n 'article-update-date-lapsed)))
3729
3730 (defun gnus-stop-date-timer ()
3731 "Stop the Date timer."
3732 (interactive)
3733 (when article-lapsed-timer
3734 (nnheader-cancel-timer article-lapsed-timer)
3735 (setq article-lapsed-timer nil)))
3736
3737 (defun article-date-user (&optional highlight)
3738 "Convert the current article date to the user-defined format.
3739 This format is defined by the `gnus-article-time-format' variable."
3740 (interactive (list t))
3741 (article-date-ut 'user highlight))
3742
3743 (defun article-date-iso8601 (&optional highlight)
3744 "Convert the current article date to ISO8601."
3745 (interactive (list t))
3746 (article-date-ut 'iso8601 highlight))
3747
3748 (defmacro gnus-article-save-original-date (&rest forms)
3749 "Save the original date as a text property and evaluate FORMS."
3750 `(let* ((case-fold-search t)
3751 (start (progn
3752 (goto-char (point-min))
3753 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3754 (not (bolp)))
3755 (match-end 0))))
3756 (date (when (and start
3757 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3758 nil t))
3759 (buffer-substring-no-properties start
3760 (match-beginning 0)))))
3761 (goto-char (point-max))
3762 (skip-chars-backward "\n")
3763 (put-text-property (point-min) (point) 'original-date date)
3764 ,@forms
3765 (goto-char (point-max))
3766 (skip-chars-backward "\n")
3767 (put-text-property (point-min) (point) 'original-date date)))
3768
3769 ;; (defun article-show-all ()
3770 ;; "Show all hidden text in the article buffer."
3771 ;; (interactive)
3772 ;; (save-excursion
3773 ;; (let ((inhibit-read-only t))
3774 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3775
3776 (defun article-remove-leading-whitespace ()
3777 "Remove excessive whitespace from all headers."
3778 (interactive)
3779 (save-excursion
3780 (save-restriction
3781 (let ((inhibit-read-only t))
3782 (article-narrow-to-head)
3783 (goto-char (point-min))
3784 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3785 (delete-region (match-beginning 1) (match-end 1)))))))
3786
3787 (defun article-emphasize (&optional arg)
3788 "Emphasize text according to `gnus-emphasis-alist'."
3789 (interactive (gnus-article-hidden-arg))
3790 (unless (gnus-article-check-hidden-text 'emphasis arg)
3791 (save-excursion
3792 (let ((alist (or
3793 (condition-case nil
3794 (with-current-buffer gnus-summary-buffer
3795 gnus-article-emphasis-alist)
3796 (error))
3797 gnus-emphasis-alist))
3798 (inhibit-read-only t)
3799 (props (append '(article-type emphasis)
3800 gnus-hidden-properties))
3801 regexp elem beg invisible visible face)
3802 (article-goto-body)
3803 (setq beg (point))
3804 (while (setq elem (pop alist))
3805 (goto-char beg)
3806 (setq regexp (car elem)
3807 invisible (nth 1 elem)
3808 visible (nth 2 elem)
3809 face (nth 3 elem))
3810 (while (re-search-forward regexp nil t)
3811 (when (and (match-beginning visible) (match-beginning invisible))
3812 (gnus-article-hide-text
3813 (match-beginning invisible) (match-end invisible) props)
3814 (gnus-article-unhide-text-type
3815 (match-beginning visible) (match-end visible) 'emphasis)
3816 (gnus-put-overlay-excluding-newlines
3817 (match-beginning visible) (match-end visible) 'face face)
3818 (gnus-add-wash-type 'emphasis)
3819 (goto-char (match-end invisible)))))))))
3820
3821 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3822 "Setup newsgroup emphasis alist."
3823 (unless gnus-article-emphasis-alist
3824 (let ((name (and gnus-newsgroup-name
3825 (gnus-group-real-name gnus-newsgroup-name))))
3826 (make-local-variable 'gnus-article-emphasis-alist)
3827 (setq gnus-article-emphasis-alist
3828 (nconc
3829 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3830 (while (setq elem (pop alist))
3831 (when (and name (string-match (car elem) name))
3832 (setq alist nil
3833 highlight (copy-sequence (cdr elem)))))
3834 highlight)
3835 (copy-sequence highlight-words)
3836 (if gnus-newsgroup-name
3837 (copy-sequence (gnus-group-find-parameter
3838 gnus-newsgroup-name 'highlight-words t)))
3839 gnus-emphasis-alist)))))
3840
3841 (defvar gnus-summary-article-menu)
3842 (defvar gnus-summary-post-menu)
3843
3844 ;;; Saving functions.
3845
3846 (defun gnus-article-save (save-buffer file &optional num)
3847 "Save the currently selected article."
3848 (when (or (get gnus-default-article-saver :headers)
3849 (not gnus-save-all-headers))
3850 ;; Remove headers according to `gnus-saved-headers' or the value
3851 ;; of the `:headers' property that the saver function might have.
3852 (let ((gnus-visible-headers
3853 (or (symbol-value (get gnus-default-article-saver :headers))
3854 gnus-saved-headers gnus-visible-headers))
3855 ;; Ignore group parameter. See `article-hide-headers'.
3856 (gnus-summary-buffer nil))
3857 (with-current-buffer save-buffer
3858 (article-hide-headers 1 t))))
3859 (save-window-excursion
3860 (if (not gnus-default-article-saver)
3861 (error "No default saver is defined")
3862 ;; !!! Magic! The saving functions all save
3863 ;; `gnus-save-article-buffer' (or so they think), but we
3864 ;; bind that variable to our save-buffer.
3865 (set-buffer gnus-article-buffer)
3866 (let* ((gnus-save-article-buffer save-buffer)
3867 (filename
3868 (cond
3869 ((not gnus-prompt-before-saving) 'default)
3870 ((eq gnus-prompt-before-saving 'always) nil)
3871 (t file)))
3872 (gnus-number-of-articles-to-be-saved
3873 (when (eq gnus-prompt-before-saving t)
3874 num))) ; Magic
3875 (set-buffer gnus-article-current-summary)
3876 (funcall gnus-default-article-saver filename)))))
3877
3878 (defun gnus-read-save-file-name (prompt &optional filename
3879 function group headers variable
3880 dir-var)
3881 (let ((default-name
3882 (funcall function group headers (symbol-value variable)))
3883 result)
3884 (setq result
3885 (expand-file-name
3886 (cond
3887 ((eq filename 'default)
3888 default-name)
3889 ((eq filename t)
3890 default-name)
3891 (filename filename)
3892 (t
3893 (when (symbol-value dir-var)
3894 (setq default-name (expand-file-name
3895 (file-name-nondirectory default-name)
3896 (symbol-value dir-var))))
3897 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3898 (prompt
3899 (format prompt
3900 (if (and gnus-number-of-articles-to-be-saved
3901 (> gnus-number-of-articles-to-be-saved 1))
3902 (format "these %d articles"
3903 gnus-number-of-articles-to-be-saved)
3904 "this article")))
3905 (file
3906 ;; Let the split methods have their say.
3907 (cond
3908 ;; No split name was found.
3909 ((null split-name)
3910 (read-file-name
3911 (concat prompt " (default "
3912 (file-name-nondirectory default-name) "): ")
3913 (file-name-directory default-name)
3914 default-name))
3915 ;; A single group name is returned.
3916 ((stringp split-name)
3917 (setq default-name
3918 (funcall function split-name headers
3919 (symbol-value variable)))
3920 (read-file-name
3921 (concat prompt " (default "
3922 (file-name-nondirectory default-name) "): ")
3923 (file-name-directory default-name)
3924 default-name))
3925 ;; A single split name was found
3926 ((= 1 (length split-name))
3927 (let* ((name (expand-file-name
3928 (car split-name)
3929 gnus-article-save-directory))
3930 (dir (cond ((file-directory-p name)
3931 (file-name-as-directory name))
3932 ((file-exists-p name) name)
3933 (t gnus-article-save-directory))))
3934 (read-file-name
3935 (concat prompt " (default " name "): ")
3936 dir name)))
3937 ;; A list of splits was found.
3938 (t
3939 (setq split-name (nreverse split-name))
3940 (let (result)
3941 (let ((file-name-history
3942 (nconc split-name file-name-history)))
3943 (setq result
3944 (expand-file-name
3945 (read-file-name
3946 (concat prompt " (`M-p' for defaults): ")
3947 gnus-article-save-directory
3948 (car split-name))
3949 gnus-article-save-directory)))
3950 (car (push result file-name-history)))))))
3951 ;; Create the directory.
3952 (gnus-make-directory (file-name-directory file))
3953 ;; If we have read a directory, we append the default file name.
3954 (when (file-directory-p file)
3955 (setq file (expand-file-name (file-name-nondirectory
3956 default-name)
3957 (file-name-as-directory file))))
3958 ;; Possibly translate some characters.
3959 (nnheader-translate-file-chars file))))))
3960 (gnus-make-directory (file-name-directory result))
3961 (when variable
3962 (set variable result))
3963 (when dir-var
3964 (set dir-var (file-name-directory result)))
3965 result))
3966
3967 (defun gnus-article-archive-name (_group)
3968 "Return the first instance of an \"Archive-name\" in the current buffer."
3969 (let ((case-fold-search t))
3970 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3971 (nnheader-concat gnus-article-save-directory
3972 (match-string 1)))))
3973
3974 (defun gnus-article-nndoc-name (group)
3975 "If GROUP is an nndoc group, return the name of the parent group."
3976 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3977 (gnus-group-get-parameter group 'save-article-group)))
3978
3979 (defun gnus-summary-save-in-rmail (&optional filename)
3980 "Append this article to Rmail file.
3981 Optional argument FILENAME specifies file name.
3982 Directory to save to is default to `gnus-article-save-directory'."
3983 (setq filename (gnus-read-save-file-name
3984 "Save %s in rmail file" filename
3985 gnus-rmail-save-name gnus-newsgroup-name
3986 gnus-current-headers 'gnus-newsgroup-last-rmail))
3987 (with-current-buffer gnus-save-article-buffer
3988 (save-excursion
3989 (save-restriction
3990 (widen)
3991 ;; Note that unlike gnus-summary-save-in-mail, there is no
3992 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3993 ;; not use Babyl.
3994 (gnus-output-to-rmail filename))))
3995 filename)
3996
3997 (defun gnus-summary-save-in-mail (&optional filename)
3998 "Append this article to Unix mail file.
3999 Optional argument FILENAME specifies file name.
4000 Directory to save to is default to `gnus-article-save-directory'."
4001 (setq filename (gnus-read-save-file-name
4002 "Save %s in Unix mail file" filename
4003 gnus-mail-save-name gnus-newsgroup-name
4004 gnus-current-headers 'gnus-newsgroup-last-mail))
4005 (with-current-buffer gnus-save-article-buffer
4006 (save-excursion
4007 (save-restriction
4008 (widen)
4009 (if (and (file-readable-p filename)
4010 (file-regular-p filename)
4011 (mail-file-babyl-p filename))
4012 (gnus-output-to-rmail filename)
4013 (gnus-output-to-mail filename)))))
4014 filename)
4015
4016 (put 'gnus-summary-save-in-file :decode t)
4017 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4018 (defun gnus-summary-save-in-file (&optional filename overwrite)
4019 "Append this article to file.
4020 Optional argument FILENAME specifies file name.
4021 Directory to save to is default to `gnus-article-save-directory'."
4022 (setq filename (gnus-read-save-file-name
4023 "Save %s in file" filename
4024 gnus-file-save-name gnus-newsgroup-name
4025 gnus-current-headers 'gnus-newsgroup-last-file))
4026 (with-current-buffer gnus-save-article-buffer
4027 (save-excursion
4028 (save-restriction
4029 (widen)
4030 (when (and overwrite
4031 (file-exists-p filename))
4032 (delete-file filename))
4033 (gnus-output-to-file filename))))
4034 filename)
4035
4036 (put 'gnus-summary-write-to-file :decode t)
4037 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4038 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4039 (defun gnus-summary-write-to-file (&optional filename)
4040 "Write this article to a file, overwriting it if the file exists.
4041 Optional argument FILENAME specifies file name.
4042 The directory to save in defaults to `gnus-article-save-directory'."
4043 (setq filename (gnus-read-save-file-name
4044 "Save %s in file" filename
4045 gnus-file-save-name gnus-newsgroup-name
4046 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4047 (gnus-summary-save-in-file filename t))
4048
4049 (put 'gnus-summary-save-body-in-file :decode t)
4050 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4051 "Append this article body to a file.
4052 Optional argument FILENAME specifies file name.
4053 The directory to save in defaults to `gnus-article-save-directory'."
4054 (setq filename (gnus-read-save-file-name
4055 "Save %s body in file" filename
4056 gnus-file-save-name gnus-newsgroup-name
4057 gnus-current-headers 'gnus-newsgroup-last-file))
4058 (with-current-buffer gnus-save-article-buffer
4059 (save-excursion
4060 (save-restriction
4061 (widen)
4062 (when (article-goto-body)
4063 (narrow-to-region (point) (point-max)))
4064 (when (and overwrite
4065 (file-exists-p filename))
4066 (delete-file filename))
4067 (gnus-output-to-file filename))))
4068 filename)
4069
4070 (put 'gnus-summary-write-body-to-file :decode t)
4071 (put 'gnus-summary-write-body-to-file
4072 :function 'gnus-summary-save-body-in-file)
4073 (defun gnus-summary-write-body-to-file (&optional filename)
4074 "Write this article body to a file, overwriting it if the file exists.
4075 Optional argument FILENAME specifies file name.
4076 The directory to save in defaults to `gnus-article-save-directory'."
4077 (setq filename (gnus-read-save-file-name
4078 "Save %s body in file" filename
4079 gnus-file-save-name gnus-newsgroup-name
4080 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4081 (gnus-summary-save-body-in-file filename t))
4082
4083 (put 'gnus-summary-save-in-pipe :decode t)
4084 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4085 (defun gnus-summary-save-in-pipe (&optional command raw)
4086 "Pipe this article to subprocess COMMAND.
4087 Valid values for COMMAND include:
4088 a string
4089 The executable command name and possibly arguments.
4090 nil
4091 You will be prompted for the command in the minibuffer.
4092 the symbol `default'
4093 It will be replaced with the command which the variable
4094 `gnus-summary-pipe-output-default-command' holds or the command
4095 last used for saving.
4096 Non-nil value for RAW overrides `:decode' and `:headers' properties
4097 and the raw article including all headers will be piped."
4098 (let ((article (gnus-summary-article-number))
4099 (decode (unless raw
4100 (get 'gnus-summary-save-in-pipe :decode)))
4101 save-buffer default)
4102 (if article
4103 (if (vectorp (gnus-summary-article-header article))
4104 (save-current-buffer
4105 (gnus-summary-select-article decode decode nil article)
4106 (insert-buffer-substring
4107 (prog1
4108 (if decode
4109 gnus-article-buffer
4110 gnus-original-article-buffer)
4111 (setq save-buffer
4112 (nnheader-set-temp-buffer " *Gnus Save*"))))
4113 ;; Remove unwanted headers.
4114 (when (and (not raw)
4115 (or (get 'gnus-summary-save-in-pipe :headers)
4116 (not gnus-save-all-headers)))
4117 (let ((gnus-visible-headers
4118 (or (symbol-value (get 'gnus-summary-save-in-pipe
4119 :headers))
4120 gnus-saved-headers gnus-visible-headers))
4121 (gnus-summary-buffer nil))
4122 (article-hide-headers 1 t))))
4123 (error "%d is not a real article" article))
4124 (error "No article to pipe"))
4125 (setq default (or gnus-summary-pipe-output-default-command
4126 gnus-last-shell-command))
4127 (unless (stringp command)
4128 (setq command
4129 (if (and (eq command 'default) default)
4130 default
4131 (gnus-read-shell-command "Shell command on this article: "
4132 default))))
4133 (when (string-equal command "")
4134 (if default
4135 (setq command default)
4136 (error "A command is required")))
4137 (with-current-buffer save-buffer
4138 (save-restriction
4139 (widen)
4140 (shell-command-on-region (point-min) (point-max) command nil)))
4141 (gnus-kill-buffer save-buffer))
4142 (setq gnus-summary-pipe-output-default-command command))
4143
4144 (defun gnus-summary-pipe-to-muttprint (&optional command)
4145 "Pipe this article to muttprint."
4146 (unless (stringp command)
4147 (setq command (read-string
4148 "Print using command: " gnus-summary-muttprint-program
4149 nil gnus-summary-muttprint-program)))
4150 (let ((gnus-summary-pipe-output-default-command
4151 gnus-summary-pipe-output-default-command))
4152 (gnus-summary-save-in-pipe command))
4153 (setq gnus-summary-muttprint-program command))
4154
4155 ;;; Article file names when saving.
4156
4157 (defun gnus-capitalize-newsgroup (newsgroup)
4158 "Capitalize NEWSGROUP name."
4159 (when (not (zerop (length newsgroup)))
4160 (concat (char-to-string (upcase (aref newsgroup 0)))
4161 (substring newsgroup 1))))
4162
4163 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4164 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4165 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4166 Otherwise, it is like ~/News/news/group/num."
4167 (let ((default
4168 (expand-file-name
4169 (concat (if (gnus-use-long-file-name 'not-save)
4170 (gnus-capitalize-newsgroup newsgroup)
4171 (gnus-newsgroup-directory-form newsgroup))
4172 "/" (int-to-string (mail-header-number headers)))
4173 gnus-article-save-directory)))
4174 (if (and last-file
4175 (string-equal (file-name-directory default)
4176 (file-name-directory last-file))
4177 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4178 default
4179 (or last-file default))))
4180
4181 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4182 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4183 If variable `gnus-use-long-file-name' is non-nil, it is
4184 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4185 (let ((default
4186 (expand-file-name
4187 (concat (if (gnus-use-long-file-name 'not-save)
4188 newsgroup
4189 (gnus-newsgroup-directory-form newsgroup))
4190 "/" (int-to-string (mail-header-number headers)))
4191 gnus-article-save-directory)))
4192 (if (and last-file
4193 (string-equal (file-name-directory default)
4194 (file-name-directory last-file))
4195 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4196 default
4197 (or last-file default))))
4198
4199 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4200 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4201 If variable `gnus-use-long-file-name' is non-nil, it is
4202 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4203 (or last-file
4204 (expand-file-name
4205 (if (gnus-use-long-file-name 'not-save)
4206 newsgroup
4207 (file-relative-name
4208 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4209 default-directory))
4210 gnus-article-save-directory)))
4211
4212 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4213 "Generate file name from sender."
4214 (let ((from (mail-header-from headers)))
4215 (expand-file-name
4216 (if (and from (string-match "\\([^ <]+\\)@" from))
4217 (match-string 1 from)
4218 "nobody")
4219 gnus-article-save-directory)))
4220
4221 (defun article-verify-x-pgp-sig ()
4222 "Verify X-PGP-Sig."
4223 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4224 (interactive)
4225 (if (gnus-buffer-live-p gnus-original-article-buffer)
4226 (let ((sig (with-current-buffer gnus-original-article-buffer
4227 (gnus-fetch-field "X-PGP-Sig")))
4228 items info headers)
4229 (when (and sig
4230 mml2015-use
4231 (mml2015-clear-verify-function))
4232 (with-temp-buffer
4233 (insert-buffer-substring gnus-original-article-buffer)
4234 (setq items (split-string sig))
4235 (message-narrow-to-head)
4236 (let ((inhibit-point-motion-hooks t)
4237 (case-fold-search t))
4238 ;; Don't verify multiple headers.
4239 (setq headers (mapconcat (lambda (header)
4240 (concat header ": "
4241 (mail-fetch-field header)
4242 "\n"))
4243 (split-string (nth 1 items) ",") "")))
4244 (delete-region (point-min) (point-max))
4245 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4246 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4247 (insert headers)
4248 (widen)
4249 (forward-line)
4250 (while (not (eobp))
4251 (if (looking-at "^-")
4252 (insert "- "))
4253 (forward-line))
4254 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4255 (insert "Version: " (car items) "\n\n")
4256 (insert (mapconcat 'identity (cddr items) "\n"))
4257 (insert "\n-----END PGP SIGNATURE-----\n")
4258 (let ((mm-security-handle (list (format "multipart/signed"))))
4259 (mml2015-clean-buffer)
4260 (let ((coding-system-for-write (or gnus-newsgroup-charset
4261 'iso-8859-1)))
4262 (funcall (mml2015-clear-verify-function)))
4263 (setq info
4264 (or (mm-handle-multipart-ctl-parameter
4265 mm-security-handle 'gnus-details)
4266 (mm-handle-multipart-ctl-parameter
4267 mm-security-handle 'gnus-info)))))
4268 (when info
4269 (let ((inhibit-read-only t) bface eface)
4270 (save-restriction
4271 (message-narrow-to-head)
4272 (goto-char (point-max))
4273 (forward-line -1)
4274 (setq bface (get-text-property (point-at-bol) 'face)
4275 eface (get-text-property (1- (point-at-eol)) 'face))
4276 (message-remove-header "X-Gnus-PGP-Verify")
4277 (if (re-search-forward "^X-PGP-Sig:" nil t)
4278 (forward-line)
4279 (goto-char (point-max)))
4280 (narrow-to-region (point) (point))
4281 (insert "X-Gnus-PGP-Verify: " info "\n")
4282 (goto-char (point-min))
4283 (forward-line)
4284 (while (not (eobp))
4285 (if (not (looking-at "^[ \t]"))
4286 (insert " "))
4287 (forward-line))
4288 ;; Do highlighting.
4289 (goto-char (point-min))
4290 (when (looking-at "\\([^:]+\\): *")
4291 (put-text-property (match-beginning 1) (1+ (match-end 1))
4292 'face bface)
4293 (put-text-property (match-end 0) (point-max)
4294 'face eface)))))))))
4295
4296 (defun article-verify-cancel-lock ()
4297 "Verify Cancel-Lock header."
4298 (interactive)
4299 (if (gnus-buffer-live-p gnus-original-article-buffer)
4300 (canlock-verify gnus-original-article-buffer)))
4301
4302 (eval-and-compile
4303 (mapc
4304 (lambda (func)
4305 (let (afunc gfunc)
4306 (if (consp func)
4307 (setq afunc (car func)
4308 gfunc (cdr func))
4309 (setq afunc func
4310 gfunc (intern (format "gnus-%s" func))))
4311 (defalias gfunc
4312 (when (fboundp afunc)
4313 `(lambda (&optional interactive &rest args)
4314 ,(documentation afunc t)
4315 (interactive (list t))
4316 (with-current-buffer gnus-article-buffer
4317 (if interactive
4318 (call-interactively ',afunc)
4319 (apply ',afunc args))))))))
4320 '(article-hide-headers
4321 article-verify-x-pgp-sig
4322 article-verify-cancel-lock
4323 article-hide-boring-headers
4324 article-treat-overstrike
4325 article-treat-ansi-sequences
4326 article-fill-long-lines
4327 article-capitalize-sentences
4328 article-remove-cr
4329 article-remove-leading-whitespace
4330 article-display-x-face
4331 article-display-face
4332 article-de-quoted-unreadable
4333 article-de-base64-unreadable
4334 article-decode-HZ
4335 article-wash-html
4336 article-unsplit-urls
4337 article-hide-list-identifiers
4338 article-strip-banner
4339 article-babel
4340 article-hide-pem
4341 article-hide-signature
4342 article-strip-headers-in-body
4343 article-remove-trailing-blank-lines
4344 article-strip-leading-blank-lines
4345 article-strip-multiple-blank-lines
4346 article-strip-leading-space
4347 article-strip-trailing-space
4348 article-strip-blank-lines
4349 article-strip-all-blank-lines
4350 article-date-local
4351 article-date-english
4352 article-date-iso8601
4353 article-date-original
4354 article-treat-date
4355 article-date-ut
4356 article-decode-mime-words
4357 article-decode-charset
4358 article-decode-encoded-words
4359 article-date-user
4360 article-date-lapsed
4361 article-date-combined-lapsed
4362 article-emphasize
4363 article-treat-dumbquotes
4364 article-treat-non-ascii
4365 article-normalize-headers
4366 ;;(article-show-all . gnus-article-show-all-headers)
4367 )))
4368 \f
4369 ;;;
4370 ;;; Gnus article mode
4371 ;;;
4372
4373 (put 'gnus-article-mode 'mode-class 'special)
4374
4375 (set-keymap-parent gnus-article-mode-map widget-keymap)
4376
4377 (gnus-define-keys gnus-article-mode-map
4378 " " gnus-article-goto-next-page
4379 [?\S-\ ] gnus-article-goto-prev-page
4380 "\177" gnus-article-goto-prev-page
4381 [delete] gnus-article-goto-prev-page
4382 "\C-c^" gnus-article-refer-article
4383 "h" gnus-article-show-summary
4384 "s" gnus-article-show-summary
4385 "\C-c\C-m" gnus-article-mail
4386 "?" gnus-article-describe-briefly
4387 "<" beginning-of-buffer
4388 ">" end-of-buffer
4389 "\C-c\C-i" gnus-info-find-node
4390 "\C-c\C-b" gnus-bug
4391 "R" gnus-article-reply-with-original
4392 "F" gnus-article-followup-with-original
4393 "\C-hk" gnus-article-describe-key
4394 "\C-hc" gnus-article-describe-key-briefly
4395 "\C-hb" gnus-article-describe-bindings
4396
4397 "e" gnus-article-read-summary-keys
4398 "\C-d" gnus-article-read-summary-keys
4399 "\M-*" gnus-article-read-summary-keys
4400 "\M-#" gnus-article-read-summary-keys
4401 "\M-^" gnus-article-read-summary-keys
4402 "\M-g" gnus-article-read-summary-keys)
4403
4404 (substitute-key-definition
4405 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4406
4407 (defvar gnus-article-send-map)
4408 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4409 "W" gnus-article-wide-reply-with-original
4410 [t] 'gnus-article-read-summary-send-keys)
4411
4412 (defun gnus-article-make-menu-bar ()
4413 (unless (boundp 'gnus-article-commands-menu)
4414 (gnus-summary-make-menu-bar))
4415 (unless (boundp 'gnus-article-article-menu)
4416 (easy-menu-define
4417 gnus-article-article-menu gnus-article-mode-map ""
4418 '("Article"
4419 ["Scroll forwards" gnus-article-goto-next-page t]
4420 ["Scroll backwards" gnus-article-goto-prev-page t]
4421 ["Show summary" gnus-article-show-summary t]
4422 ["Fetch Message-ID at point" gnus-article-refer-article t]
4423 ["Mail to address at point" gnus-article-mail t]
4424 ["Send a bug report" gnus-bug t]))
4425
4426 (easy-menu-define
4427 gnus-article-treatment-menu gnus-article-mode-map ""
4428 ;; Fixme: this should use :active (and maybe :visible).
4429 '("Treatment"
4430 ["Hide headers" gnus-article-hide-headers t]
4431 ["Hide signature" gnus-article-hide-signature t]
4432 ["Hide citation" gnus-article-hide-citation t]
4433 ["Treat overstrike" gnus-article-treat-overstrike t]
4434 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4435 ["Remove carriage return" gnus-article-remove-cr t]
4436 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4437 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4438 ["Remove base64" gnus-article-de-base64-unreadable t]
4439 ["Treat html" gnus-article-wash-html t]
4440 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4441 ["Decode HZ" gnus-article-decode-HZ t]))
4442
4443 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4444
4445 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4446
4447 (gnus-run-hooks 'gnus-article-menu-hook)))
4448
4449 (defvar bookmark-make-record-function)
4450 (defvar shr-put-image-function)
4451
4452 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4453 "Major mode for displaying an article.
4454
4455 All normal editing commands are switched off.
4456
4457 The following commands are available in addition to all summary mode
4458 commands:
4459 \\<gnus-article-mode-map>
4460 \\[gnus-article-next-page]\t Scroll the article one page forwards
4461 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4462 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4463 \\[gnus-article-show-summary]\t Display the summary buffer
4464 \\[gnus-article-mail]\t Send a reply to the address near point
4465 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4466 \\[gnus-info-find-node]\t Go to the Gnus info node"
4467 (gnus-simplify-mode-line)
4468 (make-local-variable 'minor-mode-alist)
4469 (when (gnus-visual-p 'article-menu 'menu)
4470 (gnus-article-make-menu-bar)
4471 (when gnus-summary-tool-bar-map
4472 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4473 (gnus-update-format-specifications nil 'article-mode)
4474 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4475 (set (make-local-variable 'gnus-page-broken) nil)
4476 (make-local-variable 'gnus-article-current-summary)
4477 (make-local-variable 'gnus-article-mime-handles)
4478 (make-local-variable 'gnus-article-decoded-p)
4479 (make-local-variable 'gnus-article-mime-handle-alist)
4480 (make-local-variable 'gnus-article-wash-types)
4481 (make-local-variable 'gnus-article-image-alist)
4482 (make-local-variable 'gnus-article-charset)
4483 (make-local-variable 'gnus-article-ignored-charsets)
4484 (set (make-local-variable 'bookmark-make-record-function)
4485 'gnus-summary-bookmark-make-record)
4486 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4487 ;; face.
4488 (set (make-local-variable 'nobreak-char-display) nil)
4489 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4490 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4491 (setq cursor-in-non-selected-windows nil)
4492 (gnus-set-default-directory)
4493 (buffer-disable-undo)
4494 (setq buffer-read-only t
4495 show-trailing-whitespace nil)
4496 (mm-enable-multibyte))
4497
4498 (defun gnus-article-setup-buffer ()
4499 "Initialize the article buffer."
4500 (let* ((name (if gnus-single-article-buffer "*Article*"
4501 (concat "*Article "
4502 (gnus-group-decoded-name gnus-newsgroup-name)
4503 "*")))
4504 (original
4505 (progn (string-match "\\*Article" name)
4506 (concat " *Original Article"
4507 (substring name (match-end 0))))))
4508 (setq gnus-article-buffer name)
4509 (setq gnus-original-article-buffer original)
4510 (setq gnus-article-mime-handle-alist nil)
4511 (with-current-buffer gnus-summary-buffer
4512 ;; This might be a variable local to the summary buffer.
4513 (unless gnus-single-article-buffer
4514 (setq gnus-article-buffer name)
4515 (setq gnus-original-article-buffer original)
4516 (gnus-set-global-variables)))
4517 (gnus-article-setup-highlight-words)
4518 ;; Init original article buffer.
4519 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4520 (mm-enable-multibyte)
4521 (setq major-mode 'gnus-original-article-mode)
4522 (make-local-variable 'gnus-original-article))
4523 (if (and (get-buffer name)
4524 (with-current-buffer name
4525 (if gnus-article-edit-mode
4526 (if (y-or-n-p "Article mode edit in progress; discard? ")
4527 (progn
4528 (set-buffer-modified-p nil)
4529 (gnus-kill-buffer name)
4530 (message "")
4531 nil)
4532 (error "Action aborted"))
4533 t)))
4534 (let ((summary gnus-summary-buffer))
4535 (with-current-buffer name
4536 (set (make-local-variable 'gnus-article-edit-mode) nil)
4537 (gnus-article-stop-animations)
4538 (when gnus-article-mime-handles
4539 (mm-destroy-parts gnus-article-mime-handles)
4540 (setq gnus-article-mime-handles nil))
4541 ;; Set it to nil in article-buffer!
4542 (setq gnus-article-mime-handle-alist nil)
4543 (buffer-disable-undo)
4544 (setq buffer-read-only t)
4545 (unless (derived-mode-p 'gnus-article-mode)
4546 (gnus-article-mode))
4547 (set (make-local-variable 'gnus-summary-buffer) summary)
4548 (setq truncate-lines gnus-article-truncate-lines)
4549 (current-buffer)))
4550 (let ((summary gnus-summary-buffer))
4551 (with-current-buffer (gnus-get-buffer-create name)
4552 (gnus-article-mode)
4553 (setq truncate-lines gnus-article-truncate-lines)
4554 (set (make-local-variable 'gnus-summary-buffer) summary)
4555 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4556 (when article-lapsed-timer
4557 (gnus-stop-date-timer))
4558 (when gnus-article-update-date-headers
4559 (gnus-start-date-timer gnus-article-update-date-headers))
4560 (current-buffer))))))
4561
4562 (defun gnus-article-stop-animations ()
4563 (dolist (timer (and (boundp 'timer-list)
4564 timer-list))
4565 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4566 (cancel-timer timer))))
4567
4568 (defun gnus-stop-downloads ()
4569 (when (boundp 'url-queue)
4570 (set (intern "url-queue" obarray) nil)))
4571
4572 ;; Set article window start at LINE, where LINE is the number of lines
4573 ;; from the head of the article.
4574 (defun gnus-article-set-window-start (&optional line)
4575 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4576 (when article-window
4577 (set-window-start
4578 article-window
4579 (with-current-buffer gnus-article-buffer
4580 (goto-char (point-min))
4581 (if (not line)
4582 (point-min)
4583 (gnus-message 6 "Moved to bookmark")
4584 (search-forward "\n\n" nil t)
4585 (forward-line line)
4586 (point)))))))
4587
4588 (defvar gnus-tmp-internal-hook)
4589
4590 (defun gnus-article-prepare (article &optional all-headers _header)
4591 "Prepare ARTICLE in article mode buffer.
4592 ARTICLE should either be an article number or a Message-ID.
4593 If ARTICLE is an id, HEADER should be the article headers.
4594 If ALL-HEADERS is non-nil, no headers are hidden."
4595 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4596 ;; Make sure we start in a summary buffer.
4597 (unless (derived-mode-p 'gnus-summary-mode)
4598 (set-buffer gnus-summary-buffer))
4599 (setq gnus-summary-buffer (current-buffer))
4600 (let* ((summary-buffer (current-buffer))
4601 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4602 (group gnus-newsgroup-name)
4603 result)
4604 (save-excursion
4605 (gnus-article-setup-buffer)
4606 (set-buffer gnus-article-buffer)
4607 ;; Deactivate active regions.
4608 (when (and (boundp 'transient-mark-mode)
4609 transient-mark-mode)
4610 (setq mark-active nil))
4611 (if (not (setq result (let ((inhibit-read-only t))
4612 (gnus-request-article-this-buffer
4613 article group))))
4614 ;; There is no such article.
4615 (save-excursion
4616 (when (and (numberp article)
4617 (not (memq article gnus-newsgroup-sparse)))
4618 (setq gnus-article-current
4619 (cons gnus-newsgroup-name article))
4620 (set-buffer gnus-summary-buffer)
4621 (setq gnus-current-article article)
4622 (if (and (memq article gnus-newsgroup-undownloaded)
4623 (not (gnus-online (gnus-find-method-for-group
4624 gnus-newsgroup-name))))
4625 (progn
4626 (gnus-summary-set-agent-mark article)
4627 (message "Message marked for downloading"))
4628 (gnus-summary-mark-article article gnus-canceled-mark)
4629 (unless (memq article gnus-newsgroup-sparse)
4630 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4631 (if (or (eq result 'pseudo)
4632 (eq result 'nneething))
4633 (progn
4634 (with-current-buffer summary-buffer
4635 (push article gnus-newsgroup-history)
4636 (setq gnus-last-article gnus-current-article
4637 gnus-current-article 0
4638 gnus-current-headers nil
4639 gnus-article-current nil)
4640 (if (eq result 'nneething)
4641 (gnus-configure-windows 'summary)
4642 (gnus-configure-windows 'article))
4643 (gnus-set-global-variables))
4644 (let ((gnus-article-mime-handle-alist-1
4645 gnus-article-mime-handle-alist))
4646 (gnus-set-mode-line 'article)))
4647 ;; The result from the `request' was an actual article -
4648 ;; or at least some text that is now displayed in the
4649 ;; article buffer.
4650 (when (and (numberp article)
4651 (not (eq article gnus-current-article)))
4652 ;; Seems like a new article has been selected.
4653 ;; `gnus-current-article' must be an article number.
4654 (with-current-buffer summary-buffer
4655 (push article gnus-newsgroup-history)
4656 (setq gnus-last-article gnus-current-article
4657 gnus-current-article article
4658 gnus-current-headers
4659 (gnus-summary-article-header gnus-current-article)
4660 gnus-article-current
4661 (cons gnus-newsgroup-name gnus-current-article))
4662 (unless (vectorp gnus-current-headers)
4663 (setq gnus-current-headers nil))
4664 (gnus-summary-goto-subject gnus-current-article)
4665 (when (gnus-summary-show-thread)
4666 ;; If the summary buffer really was folded, the
4667 ;; previous goto may not actually have gone to
4668 ;; the right article, but the thread root instead.
4669 ;; So we go again.
4670 (gnus-summary-goto-subject gnus-current-article))
4671 (gnus-run-hooks 'gnus-mark-article-hook)
4672 (gnus-set-mode-line 'summary)
4673 (when (gnus-visual-p 'article-highlight 'highlight)
4674 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4675 ;; Set the global newsgroup variables here.
4676 (gnus-set-global-variables)
4677 (setq gnus-have-all-headers
4678 (or all-headers gnus-show-all-headers))))
4679 (save-excursion
4680 (gnus-configure-windows 'article))
4681 (when (or (numberp article)
4682 (stringp article))
4683 (gnus-article-prepare-display)
4684 ;; Do page break.
4685 (goto-char (point-min))
4686 (when gnus-break-pages
4687 (gnus-narrow-to-page)))
4688 (let ((gnus-article-mime-handle-alist-1
4689 gnus-article-mime-handle-alist))
4690 (gnus-set-mode-line 'article))
4691 (article-goto-body)
4692 (unless (bobp)
4693 (forward-line -1))
4694 (set-window-point (get-buffer-window (current-buffer)) (point))
4695 (gnus-configure-windows 'article)
4696 (gnus-run-hooks 'gnus-article-prepare-hook)
4697 t))))))
4698
4699 (defvar gnus-mime-display-attachment-buttons-in-header)
4700
4701 ;;;###autoload
4702 (defun gnus-article-prepare-display ()
4703 "Make the current buffer look like a nice article."
4704 ;; Hooks for getting information from the article.
4705 ;; This hook must be called before being narrowed.
4706 (let ((gnus-article-buffer (current-buffer))
4707 buffer-read-only
4708 (inhibit-read-only t))
4709 (unless (derived-mode-p 'gnus-article-mode)
4710 (gnus-article-mode))
4711 (setq buffer-read-only nil
4712 gnus-article-wash-types nil
4713 gnus-article-image-alist nil)
4714 (gnus-run-hooks 'gnus-tmp-internal-hook)
4715 (when gnus-display-mime-function
4716 (funcall gnus-display-mime-function))
4717 ;; Add attachment buttons to the header.
4718 (when gnus-mime-display-attachment-buttons-in-header
4719 (gnus-mime-buttonize-attachments-in-header))))
4720
4721 ;;;
4722 ;;; Gnus Sticky Article Mode
4723 ;;;
4724
4725 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4726 "Mode for sticky articles."
4727 ;; Release bindings that won't work.
4728 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4729 gnus-sticky-article-mode-map)
4730 (substitute-key-definition 'gnus-article-refer-article 'undefined
4731 gnus-sticky-article-mode-map)
4732 (dolist (k '("e" "h" "s" "F" "R"))
4733 (define-key gnus-sticky-article-mode-map k nil))
4734 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4735 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4736 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4737 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4738
4739 (defun gnus-sticky-article (arg)
4740 "Make the current article sticky.
4741 If a prefix ARG is given, ask for a name for this sticky article buffer."
4742 (interactive "P")
4743 (gnus-summary-show-thread)
4744 (gnus-summary-select-article nil nil 'pseudo)
4745 (let (new-art-buf-name)
4746 (gnus-eval-in-buffer-window gnus-article-buffer
4747 (setq new-art-buf-name
4748 (concat
4749 "*Sticky Article: "
4750 (if arg
4751 (read-from-minibuffer "Sticky article buffer name: ")
4752 (gnus-with-article-headers
4753 (gnus-article-goto-header "subject")
4754 (setq new-art-buf-name
4755 (buffer-substring-no-properties
4756 (line-beginning-position) (line-end-position)))
4757 (goto-char (point-min))
4758 (gnus-article-goto-header "from")
4759 (setq new-art-buf-name
4760 (concat
4761 new-art-buf-name ", "
4762 (buffer-substring-no-properties
4763 (line-beginning-position) (line-end-position))))
4764 (goto-char (point-min))
4765 (gnus-article-goto-header "date")
4766 (setq new-art-buf-name
4767 (concat
4768 new-art-buf-name ", "
4769 (buffer-substring-no-properties
4770 (line-beginning-position) (line-end-position))))))
4771 "*"))
4772 (if (and (gnus-buffer-live-p new-art-buf-name)
4773 (with-current-buffer new-art-buf-name
4774 (derived-mode-p 'gnus-sticky-article-mode)))
4775 (switch-to-buffer new-art-buf-name)
4776 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4777 (gnus-sticky-article-mode))
4778 (setq gnus-article-buffer new-art-buf-name))
4779 (gnus-summary-recenter)
4780 (gnus-summary-position-point))
4781
4782 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4783 "Kill the given sticky article BUFFER.
4784 If none is given, assume the current buffer and kill it if it has
4785 `gnus-sticky-article-mode'."
4786 (interactive)
4787 (unless buffer
4788 (setq buffer (current-buffer)))
4789 (with-current-buffer buffer
4790 (when (derived-mode-p 'gnus-sticky-article-mode)
4791 (gnus-kill-buffer buffer))))
4792
4793 (defun gnus-kill-sticky-article-buffers (arg)
4794 "Kill all sticky article buffers.
4795 If a prefix ARG is given, ask for confirmation."
4796 (interactive "P")
4797 (dolist (buf (gnus-buffers))
4798 (with-current-buffer buf
4799 (when (derived-mode-p 'gnus-sticky-article-mode)
4800 (if (not arg)
4801 (gnus-kill-buffer buf)
4802 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4803 (gnus-kill-buffer buf)))))))
4804
4805 ;;;
4806 ;;; Gnus MIME viewing functions
4807 ;;;
4808
4809 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4810 "Format of the MIME buttons.
4811
4812 Valid specifiers include:
4813 %t The MIME type
4814 %T MIME type, along with additional info
4815 %n The `name' parameter
4816 %d The description, if any
4817 %l The length of the encoded part
4818 %p The part identifier number
4819 %e Dots if the part isn't displayed
4820
4821 General format specifiers can also be used. See Info node
4822 `(gnus)Formatting Variables'.")
4823
4824 (defvar gnus-tmp-type)
4825 (defvar gnus-tmp-type-long)
4826 (defvar gnus-tmp-name)
4827 (defvar gnus-tmp-description)
4828 (defvar gnus-tmp-id)
4829 (defvar gnus-tmp-length)
4830 (defvar gnus-tmp-dots)
4831 (defvar gnus-tmp-info)
4832 (defvar gnus-tmp-pressed-details)
4833
4834 (defvar gnus-mime-button-line-format-alist
4835 '((?t gnus-tmp-type ?s)
4836 (?T gnus-tmp-type-long ?s)
4837 (?n gnus-tmp-name ?s)
4838 (?d gnus-tmp-description ?s)
4839 (?p gnus-tmp-id ?s)
4840 (?l gnus-tmp-length ?d)
4841 (?e gnus-tmp-dots ?s)))
4842
4843 (defvar gnus-mime-button-commands
4844 '((gnus-article-press-button "\r" "Toggle Display")
4845 (gnus-mime-view-part "v" "View Interactively...")
4846 (gnus-mime-view-part-as-type "t" "View As Type...")
4847 (gnus-mime-view-part-as-charset "C" "View As charset...")
4848 (gnus-mime-save-part "o" "Save...")
4849 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4850 (gnus-mime-replace-part "r" "Replace part")
4851 (gnus-mime-delete-part "d" "Delete part")
4852 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4853 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4854 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4855 (gnus-mime-view-part-externally "e" "View Externally")
4856 (gnus-mime-print-part "p" "Print")
4857 (gnus-mime-pipe-part "|" "Pipe To Command...")
4858 (gnus-mime-action-on-part "." "Take action on the part...")))
4859
4860 (defun gnus-article-mime-part-status ()
4861 (if gnus-article-mime-handle-alist-1
4862 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4863 " (1 part)"
4864 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4865 ""))
4866
4867 (defvar gnus-mime-button-map
4868 (let ((map (make-sparse-keymap)))
4869 (define-key map [mouse-2] 'gnus-article-push-button)
4870 (define-key map [down-mouse-3] 'gnus-mime-button-menu)
4871 (dolist (c gnus-mime-button-commands)
4872 (define-key map (cadr c) (car c)))
4873 map))
4874
4875 (easy-menu-define
4876 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4877 `("MIME Part"
4878 ,@(mapcar (lambda (c)
4879 (vector (caddr c) (car c) :active t))
4880 gnus-mime-button-commands)))
4881
4882 (defvar gnus-url-button-commands
4883 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4884
4885 (defvar gnus-url-button-map
4886 (let ((map (make-sparse-keymap)))
4887 (dolist (c gnus-url-button-commands)
4888 (define-key map (cadr c) (car c)))
4889 map))
4890
4891 (easy-menu-define
4892 gnus-url-button-menu gnus-url-button-map "URL button menu."
4893 `("Url Button"
4894 ,@(mapcar (lambda (c)
4895 (vector (caddr c) (car c) :active t))
4896 gnus-url-button-commands)))
4897
4898 (defmacro gnus-bind-mm-vars (&rest body)
4899 "Bind some mm-* variables and execute BODY."
4900 `(let (mm-html-inhibit-images
4901 mm-html-blocked-images
4902 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4903 (with-current-buffer
4904 (cond ((derived-mode-p 'gnus-article-mode)
4905 (if (gnus-buffer-live-p gnus-article-current-summary)
4906 gnus-article-current-summary
4907 ;; Maybe we're in a mml-preview buffer
4908 ;; and no group is selected.
4909 (current-buffer)))
4910 ((gnus-buffer-live-p gnus-summary-buffer)
4911 gnus-summary-buffer)
4912 (t (current-buffer)))
4913 (setq mm-html-inhibit-images gnus-inhibit-images
4914 mm-html-blocked-images (gnus-blocked-images))
4915 (when (or (not gnus-newsgroup-name)
4916 (and (stringp gnus-safe-html-newsgroups)
4917 (string-match gnus-safe-html-newsgroups
4918 gnus-newsgroup-name))
4919 (and (consp gnus-safe-html-newsgroups)
4920 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4921 (setq mm-w3m-safe-url-regexp nil)))
4922 ,@body))
4923
4924 (defun gnus-mime-button-menu (event prefix)
4925 "Construct a context-sensitive menu of MIME commands."
4926 (interactive "e\nP")
4927 (save-window-excursion
4928 (let ((pos (event-start event)))
4929 (select-window (posn-window pos))
4930 (goto-char (posn-point pos))
4931 (gnus-article-check-buffer)
4932 (popup-menu gnus-mime-button-menu nil prefix))))
4933
4934 (defun gnus-mime-view-all-parts (&optional handles)
4935 "View all the MIME parts."
4936 (interactive)
4937 (with-current-buffer gnus-article-buffer
4938 (let ((handles (or handles gnus-article-mime-handles))
4939 (mail-parse-charset gnus-newsgroup-charset)
4940 (mail-parse-ignored-charsets
4941 (with-current-buffer gnus-summary-buffer
4942 gnus-newsgroup-ignored-charsets)))
4943 (when handles
4944 (mm-remove-parts handles)
4945 (goto-char (point-min))
4946 (or (search-forward "\n\n") (goto-char (point-max)))
4947 (let ((inhibit-read-only t))
4948 (delete-region (point) (point-max))
4949 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4950
4951 (defun gnus-article-jump-to-part (n)
4952 "Jump to MIME part N."
4953 (interactive "P")
4954 (let ((parts (with-current-buffer gnus-article-buffer
4955 (length gnus-article-mime-handle-alist))))
4956 (when (zerop parts)
4957 (error "No such part"))
4958 (pop-to-buffer gnus-article-buffer)
4959 (or n
4960 (setq n (if (= parts 1)
4961 1
4962 (read-number (format "Jump to part (1..%s): " parts)))))
4963 (unless (and (integerp n) (<= n parts) (>= n 1))
4964 (setq n
4965 (progn
4966 (gnus-message 7 "Invalid part `%s', using %s instead."
4967 n parts)
4968 parts)))
4969 (gnus-message 9 "Jumping to part %s." n)
4970 (cond ((>= gnus-auto-select-part 1)
4971 (while (and (<= n parts)
4972 (not (gnus-article-goto-part n)))
4973 (setq n (1+ n))))
4974 ((< gnus-auto-select-part 0)
4975 (while (and (>= n 1)
4976 (not (gnus-article-goto-part n)))
4977 (setq n (1- n))))
4978 (t
4979 (gnus-article-goto-part n)))))
4980
4981 (defvar gnus-mime-buttonized-part-id nil
4982 "ID of a mime part that should be buttonized.
4983 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4984
4985 (eval-when-compile
4986 (defsubst gnus-article-edit-part (handles &optional current-id)
4987 "Edit an article in order to delete a mime part.
4988 This function is exclusively used by `gnus-mime-save-part-and-strip'
4989 and `gnus-mime-delete-part', and not provided at run-time normally."
4990 (gnus-article-edit-article
4991 `(lambda ()
4992 (buffer-disable-undo)
4993 (let ((mail-parse-charset (or gnus-article-charset
4994 ',gnus-newsgroup-charset))
4995 (mail-parse-ignored-charsets
4996 (or gnus-article-ignored-charsets
4997 ',gnus-newsgroup-ignored-charsets))
4998 (mbl mml-buffer-list))
4999 (setq mml-buffer-list nil)
5000 ;; A new text must be inserted before deleting existing ones
5001 ;; at the end so as not to move existing markers of which
5002 ;; the insertion type is t.
5003 (delete-region
5004 (point-min)
5005 (prog1
5006 (goto-char (point-max))
5007 (insert-buffer-substring gnus-original-article-buffer)))
5008 (mime-to-mml ',handles)
5009 (setq gnus-article-mime-handles nil)
5010 (let ((mbl1 mml-buffer-list))
5011 (setq mml-buffer-list mbl)
5012 (set (make-local-variable 'mml-buffer-list) mbl1))
5013 (gnus-make-local-hook 'kill-buffer-hook)
5014 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5015 `(lambda (no-highlight)
5016 (let ((mail-parse-charset (or gnus-article-charset
5017 ',gnus-newsgroup-charset))
5018 (message-options message-options)
5019 (message-options-set-recipient)
5020 (mail-parse-ignored-charsets
5021 (or gnus-article-ignored-charsets
5022 ',gnus-newsgroup-ignored-charsets)))
5023 (mml-to-mime)
5024 (mml-destroy-buffers)
5025 (remove-hook 'kill-buffer-hook
5026 'mml-destroy-buffers t)
5027 (kill-local-variable 'mml-buffer-list))
5028 (gnus-summary-edit-article-done
5029 ,(or (mail-header-references gnus-current-headers) "")
5030 ,(gnus-group-read-only-p)
5031 ,gnus-summary-buffer no-highlight))
5032 t)
5033 ;; Force buttonizing this part.
5034 (let ((gnus-mime-buttonized-part-id current-id))
5035 (gnus-article-edit-done))
5036 (gnus-configure-windows 'article)
5037 (sit-for 0)
5038 (when (and current-id (integerp gnus-auto-select-part))
5039 (gnus-article-jump-to-part
5040 (min (max (+ current-id gnus-auto-select-part) 1)
5041 (with-current-buffer gnus-article-buffer
5042 (length gnus-article-mime-handle-alist)))))))
5043
5044 (defun gnus-mime-replace-part (file)
5045 "Replace MIME part under point with an external body."
5046 ;; Useful if file has already been saved to disk
5047 (interactive
5048 (list
5049 (read-file-name "Replace MIME part with file: "
5050 (or mm-default-directory default-directory)
5051 nil nil)))
5052 (gnus-mime-save-part-and-strip file))
5053
5054 (defun gnus-mime-save-part-and-strip (&optional file)
5055 "Save the MIME part under point then replace it with an external body.
5056 If FILE is given, use it for the external part."
5057 (interactive)
5058 (gnus-article-check-buffer)
5059 (when (gnus-group-read-only-p)
5060 (error "The current group does not support deleting of parts"))
5061 (when (mm-complicated-handles gnus-article-mime-handles)
5062 (error "\
5063 The current article has a complicated MIME structure, giving up..."))
5064 (let* ((data (get-text-property (point) 'gnus-data))
5065 (id (get-text-property (point) 'gnus-part))
5066 (handles gnus-article-mime-handles))
5067 (unless file
5068 (setq file
5069 (and data (mm-save-part data "Delete MIME part and save to: "))))
5070 (when file
5071 (with-current-buffer (mm-handle-buffer data)
5072 (erase-buffer)
5073 (insert "Content-Type: " (mm-handle-media-type data))
5074 (mml-insert-parameter-string (cdr (mm-handle-type data))
5075 '(charset))
5076 ;; Add a filename for the sake of saving the part again.
5077 (mml-insert-parameter
5078 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5079 (insert "\n")
5080 (insert "Content-ID: " (message-make-message-id) "\n")
5081 (insert "Content-Transfer-Encoding: binary\n")
5082 (insert "\n"))
5083 (setcdr data
5084 (cdr (mm-make-handle nil
5085 `("message/external-body"
5086 (access-type . "LOCAL-FILE")
5087 (name . ,file)))))
5088 ;; (set-buffer gnus-summary-buffer)
5089 (gnus-article-edit-part handles id))))
5090
5091 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5092 ;; parts...>') but with stripping would be nice.
5093
5094 (defun gnus-mime-delete-part ()
5095 "Delete the MIME part under point.
5096 Replace it with some information about the removed part."
5097 (interactive)
5098 (gnus-article-check-buffer)
5099 (when (gnus-group-read-only-p)
5100 (error "The current group does not support deleting of parts"))
5101 (when (mm-complicated-handles gnus-article-mime-handles)
5102 (error "\
5103 The current article has a complicated MIME structure, giving up..."))
5104 (when (or gnus-expert-user
5105 (gnus-yes-or-no-p "\
5106 Deleting parts may malfunction or destroy the article; continue? "))
5107 (let* ((data (get-text-property (point) 'gnus-data))
5108 (id (get-text-property (point) 'gnus-part))
5109 (handles gnus-article-mime-handles)
5110 (description
5111 (let ((desc (mm-handle-description data)))
5112 (when desc
5113 (mail-decode-encoded-word-string desc))))
5114 (filename (or (mm-handle-filename data) "(none)"))
5115 (type (mm-handle-media-type data)))
5116 (unless data
5117 (error "No MIME part under point"))
5118 (with-current-buffer (mm-handle-buffer data)
5119 (let ((bsize (buffer-size)))
5120 (erase-buffer)
5121 (insert
5122 (concat
5123 ",----\n"
5124 "| The following attachment has been deleted:\n"
5125 "|\n"
5126 "| Type: " type "\n"
5127 "| Filename: " filename "\n"
5128 "| Size (encoded): " (format "%s byte%s\n"
5129 bsize (if (= bsize 1)
5130 ""
5131 "s"))
5132 (when description
5133 (concat "| Description: " description "\n"))
5134 "`----\n"))
5135 (setcdr data
5136 (cdr (mm-make-handle
5137 nil `("text/plain" (charset . gnus-decoded)) nil nil
5138 (list "attachment")
5139 (format "Deleted attachment (%s bytes)" bsize))))))
5140 ;; (set-buffer gnus-summary-buffer)
5141 (gnus-article-edit-part handles id))))
5142
5143 (defun gnus-mime-save-part ()
5144 "Save the MIME part under point."
5145 (interactive)
5146 (gnus-article-check-buffer)
5147 (let ((data (get-text-property (point) 'gnus-data)))
5148 (when data
5149 (mm-save-part data))))
5150
5151 (defun gnus-mime-pipe-part (&optional cmd)
5152 "Pipe the MIME part under point to a process.
5153 Use CMD as the process."
5154 (interactive)
5155 (gnus-article-check-buffer)
5156 (let ((data (get-text-property (point) 'gnus-data)))
5157 (when data
5158 (mm-pipe-part data cmd))))
5159
5160 (defun gnus-mime-view-part ()
5161 "Interactively choose a viewing method for the MIME part under point."
5162 (interactive)
5163 (gnus-article-check-buffer)
5164 (let ((data (get-text-property (point) 'gnus-data)))
5165 (when data
5166 (setq gnus-article-mime-handles
5167 (mm-merge-handles
5168 gnus-article-mime-handles (setq data (copy-sequence data))))
5169 (mm-interactively-view-part data))))
5170
5171 (defun gnus-mime-view-part-as-type-internal ()
5172 (gnus-article-check-buffer)
5173 (let* ((handle (get-text-property (point) 'gnus-data))
5174 (name (or
5175 ;; Content-Type: foo/bar; name=...
5176 (mail-content-type-get (mm-handle-type handle) 'name)
5177 ;; Content-Disposition: attachment; filename=...
5178 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5179 (def-type (and name (mm-default-file-encoding name))))
5180 (or (and def-type (cons def-type 0))
5181 (and handle
5182 (equal (mm-handle-media-supertype handle) "text")
5183 '("text/plain" . 0))
5184 '("application/octet-stream" . 0))))
5185
5186 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5187 "Choose a MIME media type, and view the part as such.
5188 If non-nil, PRED is a predicate to use during completion to limit the
5189 available media-types."
5190 (interactive)
5191 (unless mime-type
5192 (setq mime-type
5193 (let ((default (gnus-mime-view-part-as-type-internal)))
5194 (gnus-completing-read
5195 "View as MIME type"
5196 (if pred
5197 (gnus-remove-if-not pred (mailcap-mime-types))
5198 (mailcap-mime-types))
5199 nil nil nil
5200 (car default)))))
5201 (gnus-article-check-buffer)
5202 (let ((handle (get-text-property (point) 'gnus-data)))
5203 (when handle
5204 (when (equal (mm-handle-media-type handle) "message/external-body")
5205 (unless (mm-handle-cache handle)
5206 (mm-extern-cache-contents handle))
5207 (setq handle (mm-handle-cache handle)))
5208 (setq handle
5209 (mm-make-handle (mm-handle-buffer handle)
5210 (cons mime-type (cdr (mm-handle-type handle)))
5211 (mm-handle-encoding handle)
5212 (mm-handle-undisplayer handle)
5213 (mm-handle-disposition handle)
5214 (mm-handle-description handle)
5215 nil
5216 (mm-handle-id handle)))
5217 (setq gnus-article-mime-handles
5218 (mm-merge-handles gnus-article-mime-handles handle))
5219 (when (mm-handle-displayed-p handle)
5220 (mm-remove-part handle))
5221 (gnus-mm-display-part handle))))
5222
5223 (defun gnus-mime-copy-part (&optional handle arg)
5224 "Put the MIME part under point into a new buffer.
5225 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5226 are decompressed."
5227 (interactive (list nil current-prefix-arg))
5228 (gnus-article-check-buffer)
5229 (unless handle
5230 (setq handle (get-text-property (point) 'gnus-data)))
5231 (when handle
5232 (let ((filename (mm-handle-filename handle))
5233 contents dont-decode charset coding-system)
5234 (mm-with-unibyte-buffer
5235 (mm-insert-part handle)
5236 (setq contents (or (condition-case nil
5237 (mm-decompress-buffer filename nil 'sig)
5238 (error
5239 (setq dont-decode t)
5240 nil))
5241 (buffer-string))))
5242 (setq filename (cond (filename (file-name-nondirectory filename))
5243 (dont-decode "*raw data*")
5244 (t "*decoded*")))
5245 (cond
5246 (dont-decode)
5247 ((not arg)
5248 (unless (setq charset (mail-content-type-get
5249 (mm-handle-type handle) 'charset))
5250 (unless (setq coding-system (mm-with-unibyte-buffer
5251 (insert contents)
5252 (mm-find-buffer-file-coding-system)))
5253 (setq charset gnus-newsgroup-charset))))
5254 ((numberp arg)
5255 (setq charset (or (cdr (assq arg
5256 gnus-summary-show-article-charset-alist))
5257 (mm-read-coding-system "Charset: ")))))
5258 (switch-to-buffer (generate-new-buffer filename))
5259 (if (or coding-system
5260 (and charset
5261 (setq coding-system (mm-charset-to-coding-system
5262 charset nil t))
5263 (not (eq coding-system 'ascii))))
5264 (progn
5265 (mm-enable-multibyte)
5266 (insert (mm-decode-coding-string contents coding-system))
5267 (setq buffer-file-coding-system
5268 (if (boundp 'last-coding-system-used)
5269 (symbol-value 'last-coding-system-used)
5270 coding-system)))
5271 (mm-disable-multibyte)
5272 (insert contents)
5273 (setq buffer-file-coding-system mm-binary-coding-system))
5274 ;; We do it this way to make `normal-mode' set the appropriate mode.
5275 (unwind-protect
5276 (progn
5277 (setq buffer-file-name (expand-file-name filename))
5278 (normal-mode))
5279 (setq buffer-file-name nil))
5280 (goto-char (point-min)))))
5281
5282 (defun gnus-mime-print-part (&optional handle filename)
5283 "Print the MIME part under point."
5284 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5285 (gnus-article-check-buffer)
5286 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5287 (contents (and handle (mm-get-part handle)))
5288 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5289 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5290 (when contents
5291 (if printer
5292 (unwind-protect
5293 (progn
5294 (mm-save-part-to-file handle file)
5295 (call-process shell-file-name nil
5296 (generate-new-buffer " *mm*")
5297 nil
5298 shell-command-switch
5299 (mm-mailcap-command
5300 printer file (mm-handle-type handle))))
5301 (delete-file file))
5302 (with-temp-buffer
5303 (insert contents)
5304 (gnus-print-buffer))
5305 (ps-despool filename)))))
5306
5307 (defun gnus-mime-inline-part (&optional handle arg)
5308 "Insert the MIME part under point into the current buffer.
5309 Compressed files like .gz and .bz2 are decompressed."
5310 (interactive (list nil current-prefix-arg))
5311 (gnus-article-check-buffer)
5312 (let* ((inhibit-read-only t)
5313 (b (point))
5314 (btn ;; position where the MIME button exists
5315 (if handle
5316 (if (eq handle (get-text-property b 'gnus-data))
5317 b
5318 (article-goto-body)
5319 (or (text-property-any (point) (point-max) 'gnus-data handle)
5320 (text-property-any (point-min) (point) 'gnus-data handle)))
5321 (setq handle (get-text-property b 'gnus-data))
5322 b))
5323 start)
5324 (when handle
5325 (when (= b (prog1
5326 btn
5327 (setq start (next-single-property-change btn 'gnus-data
5328 nil (point-max))
5329 btn (previous-single-property-change start
5330 'gnus-data))))
5331 (setq b btn))
5332 (if (and (not arg) (mm-handle-undisplayer handle))
5333 (progn
5334 (setq b (copy-marker b)
5335 btn (copy-marker btn))
5336 (mm-remove-part handle))
5337 (cond
5338 ((not arg) nil)
5339 ((numberp arg)
5340 (if (mm-handle-undisplayer handle)
5341 (mm-remove-part handle)))
5342 ((mm-handle-undisplayer handle)
5343 (mm-remove-part handle)))
5344 (goto-char start)
5345 (unless (bolp)
5346 ;; This is a header button.
5347 (forward-line 1))
5348 (mm-display-inline handle))
5349 ;; Toggle the button appearance between `[button]...' and `[button]'.
5350 (when (markerp btn)
5351 (setq btn (prog1 (marker-position btn)
5352 (set-marker btn nil))))
5353 (goto-char btn)
5354 (let ((displayed-p (mm-handle-displayed-p handle)))
5355 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5356 (list displayed-p))
5357 (if (featurep 'emacs)
5358 (delete-region
5359 (point)
5360 (next-single-property-change (point) 'gnus-data nil (point-max)))
5361 (let* ((end (next-single-property-change (point) 'gnus-data))
5362 (annots (annotations-at (or end (point-max)))))
5363 (delete-region (point)
5364 (if end
5365 (if annots (1+ end) end)
5366 (point-max)))
5367 (dolist (annot annots)
5368 (set-extent-endpoints annot (point) (point)))))
5369 (setq start (point))
5370 (if (search-backward "\n\n" nil t)
5371 (progn
5372 (goto-char start)
5373 (unless (or displayed-p (eolp))
5374 ;; Add extra newline.
5375 (insert (propertize (buffer-substring (1- start) start)
5376 'gnus-undeletable t))))
5377 ;; We're in the article header.
5378 (delete-char -1)
5379 (dolist (ovl (overlays-in btn (point)))
5380 (overlay-put ovl 'gnus-button-attachment-extra t)
5381 (overlay-put ovl 'face nil))
5382 (save-restriction
5383 (message-narrow-to-field)
5384 (let ((gnus-treatment-function-alist
5385 '((gnus-treat-highlight-headers
5386 gnus-article-highlight-headers))))
5387 (gnus-treat-article 'head)))))
5388 (when (markerp b)
5389 (setq b (prog1 (marker-position b)
5390 (set-marker b nil))))
5391 (goto-char b))))
5392
5393 (defun gnus-mime-set-charset-parameters (handle charset)
5394 "Set CHARSET to parameters in HANDLE.
5395 CHARSET may either be a string or a symbol."
5396 (unless (stringp charset)
5397 (setq charset (symbol-name charset)))
5398 (if (stringp (car handle))
5399 (dolist (h (cdr handle))
5400 (gnus-mime-set-charset-parameters h charset))
5401 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5402 "message/external-body")
5403 (progn
5404 (unless (mm-handle-cache handle)
5405 (mm-extern-cache-contents handle))
5406 (mm-handle-cache handle))
5407 handle)))
5408 (param (assq 'charset (cdr type))))
5409 (if param
5410 (setcdr param charset)
5411 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5412
5413 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5414 "Insert the MIME part under point into the current buffer using the
5415 specified charset."
5416 (interactive (list nil current-prefix-arg))
5417 (gnus-article-check-buffer)
5418 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5419 (fun (get-text-property (point) 'gnus-callback))
5420 (gnus-newsgroup-ignored-charsets 'gnus-all)
5421 charset form preferred parts)
5422 (when handle
5423 (when (prog1
5424 (and fun
5425 (setq charset
5426 (or (cdr (assq
5427 arg
5428 gnus-summary-show-article-charset-alist))
5429 (mm-read-coding-system "Charset: "))))
5430 (if (mm-handle-undisplayer handle)
5431 (mm-remove-part handle)))
5432 (gnus-mime-set-charset-parameters handle charset)
5433 (when (and (consp (setq form (cdr-safe fun)))
5434 (setq form (ignore-errors
5435 (assq 'gnus-mime-display-alternative form)))
5436 (setq preferred (caddr form))
5437 (progn
5438 (when (eq (car preferred) 'quote)
5439 (setq preferred (cadr preferred)))
5440 (not (equal preferred
5441 (get-text-property (point) 'gnus-data))))
5442 (setq parts (get-text-property (point) 'gnus-part))
5443 (setq parts (cdr (assq parts
5444 gnus-article-mime-handle-alist)))
5445 (equal (mm-handle-media-type parts) "multipart/alternative")
5446 (setq parts (reverse (cdr parts))))
5447 (setcar (cddr form)
5448 (list 'quote (or (cadr (member preferred parts))
5449 (car parts)))))
5450 (funcall fun handle)))))
5451
5452 (defun gnus-mime-view-part-externally (&optional handle)
5453 "View the MIME part under point with an external viewer."
5454 (interactive)
5455 (gnus-article-check-buffer)
5456 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5457 (mm-inlined-types nil)
5458 (mail-parse-charset gnus-newsgroup-charset)
5459 (mail-parse-ignored-charsets
5460 (with-current-buffer gnus-summary-buffer
5461 gnus-newsgroup-ignored-charsets))
5462 (type (mm-handle-media-type handle))
5463 (method (mailcap-mime-info type))
5464 (mm-enable-external t))
5465 (if (not (stringp method))
5466 (gnus-mime-view-part-as-type
5467 nil (lambda (type) (stringp (mailcap-mime-info type))))
5468 (when handle
5469 (mm-display-part handle nil t)))))
5470
5471 (defun gnus-mime-view-part-internally (&optional handle)
5472 "View the MIME part under point with an internal viewer.
5473 If no internal viewer is available, use an external viewer."
5474 (interactive)
5475 (gnus-article-check-buffer)
5476 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5477 (mm-inlined-types '(".*"))
5478 (mm-inline-large-images t)
5479 (mail-parse-charset gnus-newsgroup-charset)
5480 (mail-parse-ignored-charsets
5481 (with-current-buffer gnus-summary-buffer
5482 gnus-newsgroup-ignored-charsets))
5483 (inhibit-read-only t))
5484 (if (not (mm-inlinable-p handle))
5485 (gnus-mime-view-part-as-type
5486 nil (lambda (type) (mm-inlinable-p handle type)))
5487 (when handle
5488 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5489
5490 (defun gnus-mime-action-on-part (&optional action)
5491 "Do something with the MIME attachment at (point)."
5492 (interactive
5493 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5494 (gnus-article-check-buffer)
5495 (let ((action-pair (assoc action gnus-mime-action-alist)))
5496 (if action-pair
5497 (funcall (cdr action-pair)))))
5498
5499 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5500 "Call FUNCTION on MIME part N.
5501 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5502 If INTERACTIVE, call FUNCTION interactively."
5503 (let (window frame)
5504 ;; Check whether the article is displayed.
5505 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5506 (setq window (get-buffer-window gnus-article-buffer t))
5507 (frame-visible-p (setq frame (window-frame window))))
5508 (error "No article is displayed"))
5509 (with-current-buffer gnus-article-buffer
5510 ;; Check whether the article displays the right contents.
5511 (unless (with-current-buffer gnus-summary-buffer
5512 (eq gnus-current-article (gnus-summary-article-number)))
5513 (error "You should select the right article first"))
5514 (if n
5515 (setq n (prefix-numeric-value n))
5516 (let ((pt (point)))
5517 (setq n (or (get-text-property pt 'gnus-part)
5518 (and (not (bobp))
5519 (get-text-property (1- pt) 'gnus-part))
5520 (get-text-property (prog2
5521 (forward-line 1)
5522 (point)
5523 (goto-char pt))
5524 'gnus-part)
5525 (get-text-property
5526 (or (and (setq pt (previous-single-property-change
5527 pt 'gnus-part))
5528 (1- pt))
5529 (next-single-property-change (point) 'gnus-part)
5530 (point))
5531 'gnus-part)
5532 1))))
5533 ;; Check whether the specified part exists.
5534 (when (> n (length gnus-article-mime-handle-alist))
5535 (error "No such part")))
5536 (unless
5537 (progn
5538 ;; To select the window is needed so that the cursor
5539 ;; might be visible on the MIME button.
5540 (select-window (prog1
5541 window
5542 (setq window (selected-window))
5543 ;; Article may be displayed in the other frame.
5544 (gnus-select-frame-set-input-focus
5545 (prog1
5546 frame
5547 (setq frame (selected-frame))))))
5548 (when (gnus-article-goto-part n)
5549 ;; We point the cursor and the arrow at the MIME button
5550 ;; when the `function' prompt the user for something.
5551 (unless (and (pos-visible-in-window-p)
5552 (> (count-lines (point) (window-end))
5553 (/ (1- (window-height)) 3)))
5554 (recenter (/ (1- (window-height)) 3)))
5555 (let ((cursor-in-non-selected-windows t)
5556 (overlay-arrow-string "=>")
5557 (overlay-arrow-position (point-marker)))
5558 (unwind-protect
5559 (cond
5560 ((and no-handle interactive)
5561 (call-interactively function))
5562 (no-handle
5563 (funcall function))
5564 (interactive
5565 (call-interactively
5566 function (get-text-property (point) 'gnus-data)))
5567 (t
5568 (funcall function
5569 (get-text-property (point) 'gnus-data))))
5570 (set-marker overlay-arrow-position nil)
5571 (unless gnus-auto-select-part
5572 (gnus-select-frame-set-input-focus frame)
5573 (select-window window))))
5574 t))
5575 (if gnus-inhibit-mime-unbuttonizing
5576 ;; This is the default though the program shouldn't reach here.
5577 (error "No such part")
5578 ;; The part which doesn't have the MIME button is selected.
5579 ;; So, we display all the buttons and redo it.
5580 (let ((gnus-inhibit-mime-unbuttonizing t))
5581 (gnus-summary-show-article)
5582 (gnus-article-part-wrapper n function no-handle))))))
5583
5584 (defun gnus-article-pipe-part (n)
5585 "Pipe MIME part N, which is the numerical prefix."
5586 (interactive "P")
5587 (gnus-article-part-wrapper n 'mm-pipe-part))
5588
5589 (defun gnus-article-save-part (n)
5590 "Save MIME part N, which is the numerical prefix."
5591 (interactive "P")
5592 (gnus-article-part-wrapper n 'mm-save-part))
5593
5594 (defun gnus-article-interactively-view-part (n)
5595 "View MIME part N interactively, which is the numerical prefix."
5596 (interactive "P")
5597 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5598
5599 (defun gnus-article-copy-part (n)
5600 "Copy MIME part N, which is the numerical prefix."
5601 (interactive "P")
5602 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5603
5604 (defun gnus-article-view-part-as-charset (n)
5605 "View MIME part N using a specified charset.
5606 N is the numerical prefix."
5607 (interactive "P")
5608 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5609
5610 (defun gnus-article-view-part-externally (n)
5611 "View MIME part N externally, which is the numerical prefix."
5612 (interactive "P")
5613 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5614
5615 (defun gnus-article-inline-part (n)
5616 "Inline MIME part N, which is the numerical prefix."
5617 (interactive "P")
5618 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5619
5620 (defun gnus-article-save-part-and-strip (n)
5621 "Save MIME part N and replace it with an external body.
5622 N is the numerical prefix."
5623 (interactive "P")
5624 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5625
5626 (defun gnus-article-replace-part (n)
5627 "Replace MIME part N with an external body.
5628 N is the numerical prefix."
5629 (interactive "P")
5630 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5631
5632 (defun gnus-article-delete-part (n)
5633 "Delete MIME part N and add some information about the removed part.
5634 N is the numerical prefix."
5635 (interactive "P")
5636 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5637
5638 (defun gnus-article-view-part-as-type (n)
5639 "Choose a MIME media type, and view part N as such.
5640 N is the numerical prefix."
5641 (interactive "P")
5642 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5643
5644 (defun gnus-article-mime-match-handle-first (condition)
5645 (if condition
5646 (let (n)
5647 (dolist (ihandle gnus-article-mime-handle-alist)
5648 (if (and (cond
5649 ((functionp condition)
5650 (funcall condition (cdr ihandle)))
5651 ((eq condition 'undisplayed)
5652 (not (or (mm-handle-undisplayer (cdr ihandle))
5653 (equal (mm-handle-media-type (cdr ihandle))
5654 "multipart/alternative"))))
5655 ((eq condition 'undisplayed-alternative)
5656 (not (mm-handle-undisplayer (cdr ihandle))))
5657 (t t))
5658 (gnus-article-goto-part (car ihandle))
5659 (or (not n) (< (car ihandle) n)))
5660 (setq n (car ihandle))))
5661 (or n 1))
5662 1))
5663
5664 (defun gnus-article-view-part (&optional n)
5665 "View MIME part N, which is the numerical prefix.
5666 If the part is already shown, hide the part. If N is nil, view
5667 all parts."
5668 (interactive "P")
5669 (with-current-buffer gnus-article-buffer
5670 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5671 gnus-article-mime-match-handle-function)))
5672 (when (> n (length gnus-article-mime-handle-alist))
5673 (error "No such part"))
5674 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5675 (when (gnus-article-goto-part n)
5676 (if (equal (car handle) "multipart/alternative")
5677 (progn
5678 (beginning-of-line) ;; Make it toggle subparts
5679 (gnus-article-press-button))
5680 (when (eq (gnus-mm-display-part handle) 'internal)
5681 (gnus-set-window-start)))))))
5682
5683 (defsubst gnus-article-mime-total-parts ()
5684 (if (bufferp (car gnus-article-mime-handles))
5685 1 ;; single part
5686 (1- (length gnus-article-mime-handles))))
5687
5688 (defun gnus-mm-display-part (handle)
5689 "Display HANDLE and fix MIME button."
5690 (let ((id (get-text-property (point) 'gnus-part))
5691 (point (point))
5692 (inhibit-read-only t)
5693 (window (selected-window))
5694 (mail-parse-charset gnus-newsgroup-charset)
5695 (mail-parse-ignored-charsets
5696 (if (gnus-buffer-live-p gnus-summary-buffer)
5697 (with-current-buffer gnus-summary-buffer
5698 gnus-newsgroup-ignored-charsets)
5699 nil))
5700 start retval)
5701 (unwind-protect
5702 (progn
5703 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5704 (when win
5705 (select-window win)
5706 (goto-char point)))
5707 (setq start (next-single-property-change point 'gnus-data
5708 nil (point-max))
5709 point (previous-single-property-change start 'gnus-data))
5710 (if (mm-handle-displayed-p handle)
5711 ;; This will remove the part.
5712 (setq point (copy-marker point)
5713 retval (mm-display-part handle))
5714 (let ((part (or (and (mm-inlinable-p handle)
5715 (mm-inlined-p handle)
5716 t)
5717 (with-temp-buffer
5718 (gnus-bind-mm-vars
5719 (setq retval (mm-display-part handle)))
5720 (unless (zerop (buffer-size))
5721 (buffer-string))))))
5722 (goto-char start)
5723 (unless (bolp)
5724 ;; This is a header button.
5725 (forward-line 1))
5726 (cond ((stringp part)
5727 (save-restriction
5728 (narrow-to-region (point)
5729 (progn
5730 (insert part)
5731 (unless (bolp) (insert "\n"))
5732 (point)))
5733 (gnus-treat-article nil id
5734 (gnus-article-mime-total-parts)
5735 (mm-handle-media-type handle))
5736 (mm-handle-set-undisplayer
5737 handle
5738 `(lambda ()
5739 (let ((inhibit-read-only t))
5740 (delete-region ,(copy-marker (point-min) t)
5741 ,(point-max-marker)))))))
5742 (part
5743 (mm-display-inline handle))))))
5744 (when (markerp point)
5745 (setq point (prog1 (marker-position point)
5746 (set-marker point nil))))
5747 (goto-char point)
5748 ;; Toggle the button appearance between `[button]...' and `[button]'.
5749 (let ((displayed-p (mm-handle-displayed-p handle)))
5750 (gnus-insert-mime-button handle id (list displayed-p))
5751 (if (featurep 'emacs)
5752 (delete-region
5753 (point)
5754 (next-single-property-change (point) 'gnus-data nil (point-max)))
5755 (let* ((end (next-single-property-change (point) 'gnus-data))
5756 (annots (annotations-at (or end (point-max)))))
5757 (delete-region (point)
5758 (if end
5759 (if annots (1+ end) end)
5760 (point-max)))
5761 (dolist (annot annots)
5762 (set-extent-endpoints annot (point) (point)))))
5763 (setq start (point))
5764 (if (search-backward "\n\n" nil t)
5765 (progn
5766 (goto-char start)
5767 (unless (or displayed-p (eolp))
5768 ;; Add extra newline.
5769 (insert (propertize (buffer-substring (1- start) start)
5770 'gnus-undeletable t))))
5771 ;; We're in the article header.
5772 (delete-char -1)
5773 (dolist (ovl (overlays-in point (point)))
5774 (overlay-put ovl 'gnus-button-attachment-extra t)
5775 (overlay-put ovl 'face nil))
5776 (save-restriction
5777 (message-narrow-to-field)
5778 (let ((gnus-treatment-function-alist
5779 '((gnus-treat-highlight-headers
5780 gnus-article-highlight-headers))))
5781 (gnus-treat-article 'head)))))
5782 (goto-char point)
5783 (if (window-live-p window)
5784 (select-window window)))
5785 retval))
5786
5787 (defun gnus-article-goto-part (n)
5788 "Go to MIME part N."
5789 (when gnus-break-pages
5790 (widen))
5791 (article-goto-body)
5792 (prog1
5793 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5794 ;; There may be header buttons.
5795 (text-property-any (point-min) (point) 'gnus-part n)))
5796 part handle end next handles)
5797 (when start
5798 (goto-char start)
5799 (if (setq handle (get-text-property start 'gnus-data))
5800 start
5801 ;; Go to the displayed subpart, assuming this is
5802 ;; multipart/alternative.
5803 (setq part start
5804 end (point-at-eol))
5805 (while (and (not handle)
5806 part
5807 (< part end)
5808 (setq next (text-property-not-all part end
5809 'gnus-data nil)))
5810 (setq part next
5811 handle (get-text-property part 'gnus-data))
5812 (push (cons handle part) handles)
5813 (unless (mm-handle-displayed-p handle)
5814 (setq handle nil
5815 part (text-property-any part end 'gnus-data nil))))
5816 (unless handle
5817 ;; No subpart is displayed, so we find preferred one.
5818 (setq part
5819 (cdr (assq (mm-preferred-alternative
5820 (nreverse (mapcar 'car handles)))
5821 handles))))
5822 (if part
5823 (goto-char (1+ part))
5824 start))))
5825 (when gnus-break-pages
5826 (gnus-narrow-to-page))))
5827
5828 (defun gnus-insert-mime-button (handle id &optional displayed)
5829 (let ((gnus-tmp-name
5830 (or (mm-handle-filename handle)
5831 (mail-content-type-get (mm-handle-type handle) 'url)
5832 ""))
5833 (gnus-tmp-id id)
5834 (gnus-tmp-type (mm-handle-media-type handle))
5835 (gnus-tmp-description (or (mm-handle-description handle) ""))
5836 (gnus-tmp-dots
5837 (if (if displayed (car displayed)
5838 (mm-handle-displayed-p handle))
5839 "" "..."))
5840 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5841 (buffer-size)))
5842 gnus-tmp-type-long b e)
5843 (when (string-match ".*/" gnus-tmp-name)
5844 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5845 (setq gnus-tmp-type-long (concat gnus-tmp-type
5846 (and (not (equal gnus-tmp-name ""))
5847 (concat "; " gnus-tmp-name))))
5848 (unless (equal gnus-tmp-description "")
5849 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5850 (setq b (point))
5851 (gnus-eval-format
5852 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5853 `(keymap ,gnus-mime-button-map
5854 gnus-callback gnus-mm-display-part
5855 gnus-part ,gnus-tmp-id
5856 article-type annotation
5857 gnus-data ,handle
5858 rear-nonsticky t))
5859 (setq e (if (bolp)
5860 ;; Exclude a newline.
5861 (1- (point))
5862 (point)))
5863 (when gnus-article-button-face
5864 (overlay-put (make-overlay b e nil t)
5865 'face gnus-article-button-face))
5866 (widget-convert-button
5867 'link b e
5868 :mime-handle handle
5869 :action 'gnus-widget-press-button
5870 :button-keymap gnus-mime-button-map
5871 :help-echo
5872 (lambda (widget)
5873 (format
5874 "%S: %s the MIME part; %S: more options"
5875 'mouse-2
5876 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5877 "hide" "show")
5878 'down-mouse-3)))))
5879
5880 (defun gnus-widget-press-button (elems _el)
5881 (goto-char (widget-get elems :from))
5882 (gnus-article-press-button))
5883
5884 (defvar gnus-displaying-mime nil)
5885
5886 (defun gnus-display-mime (&optional ihandles)
5887 "Display the MIME parts."
5888 (save-excursion
5889 (save-selected-window
5890 (let ((window (get-buffer-window gnus-article-buffer))
5891 (point (point)))
5892 (when window
5893 (select-window window)
5894 ;; We have to do this since selecting the window
5895 ;; may change the point. So we set the window point.
5896 (set-window-point window point)))
5897 (let ((handles ihandles)
5898 (inhibit-read-only t))
5899 (cond (handles)
5900 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5901 (when gnus-article-emulate-mime
5902 (mm-uu-dissect-text-parts handles)))
5903 (gnus-article-emulate-mime
5904 (setq handles (mm-uu-dissect))))
5905 (when (and (not ihandles)
5906 (not gnus-displaying-mime))
5907 ;; Top-level call; we clean up.
5908 (when gnus-article-mime-handles
5909 (mm-destroy-parts gnus-article-mime-handles)
5910 (setq gnus-article-mime-handle-alist nil));; A trick.
5911 (setq gnus-article-mime-handles handles)
5912 ;; We allow users to glean info from the handles.
5913 (when gnus-article-mime-part-function
5914 (gnus-mime-part-function handles)))
5915 (if (and handles
5916 (or (not (stringp (car handles)))
5917 (cdr handles)))
5918 (progn
5919 (when (and (not ihandles)
5920 (not gnus-displaying-mime))
5921 ;; Clean up for mime parts.
5922 (article-goto-body)
5923 (delete-region (point) (point-max)))
5924 (let ((gnus-displaying-mime t))
5925 (gnus-mime-display-part handles)))
5926 (save-restriction
5927 (article-goto-body)
5928 (narrow-to-region (point) (point-max))
5929 (gnus-treat-article nil 1 1 "text/plain")
5930 (widen)))
5931 (unless ihandles
5932 ;; Highlight the headers.
5933 (save-excursion
5934 (save-restriction
5935 (article-goto-body)
5936 (narrow-to-region (point-min) (point))
5937 (gnus-article-save-original-date
5938 (gnus-treat-article 'head)))))))
5939 ;; Cope with broken MIME messages.
5940 (goto-char (point-max))
5941 (unless (bolp)
5942 (insert "\n"))))
5943
5944 (defcustom gnus-mime-display-multipart-as-mixed nil
5945 "Display \"multipart\" parts as \"multipart/mixed\".
5946
5947 If t, it overrides nil values of
5948 `gnus-mime-display-multipart-alternative-as-mixed' and
5949 `gnus-mime-display-multipart-related-as-mixed'."
5950 :group 'gnus-article-mime
5951 :type 'boolean)
5952
5953 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5954 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5955 :version "22.1"
5956 :group 'gnus-article-mime
5957 :type 'boolean)
5958
5959 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5960 "Display \"multipart/related\" parts as \"multipart/mixed\".
5961
5962 If displaying \"text/html\" is discouraged \(see
5963 `mm-discouraged-alternatives') images or other material inside a
5964 \"multipart/related\" part might be overlooked when this variable is nil."
5965 :version "22.1"
5966 :group 'gnus-article-mime
5967 :type 'boolean)
5968
5969 (defcustom gnus-mime-display-attachment-buttons-in-header t
5970 "Add attachment buttons in the end of the header of an article.
5971 Since MIME attachments tend to be put at the end of an article, we may
5972 overlook them if there is a huge body. This option offers you a copy
5973 of all non-inlinable MIME parts as buttons shown in front of an article.
5974 If nil, don't show those extra buttons."
5975 :version "25.1"
5976 :group 'gnus-article-mime
5977 :type 'boolean)
5978
5979 (defun gnus-mime-display-part (handle)
5980 (cond
5981 ;; Maybe a broken MIME message.
5982 ((null handle))
5983 ;; Single part.
5984 ((not (stringp (car handle)))
5985 (gnus-mime-display-single handle))
5986 ;; User-defined multipart
5987 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5988 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5989 handle))
5990 ;; multipart/alternative
5991 ((and (equal (car handle) "multipart/alternative")
5992 (not (or gnus-mime-display-multipart-as-mixed
5993 gnus-mime-display-multipart-alternative-as-mixed)))
5994 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5995 (push (cons id handle) gnus-article-mime-handle-alist)
5996 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5997 ;; multipart/related
5998 ((and (equal (car handle) "multipart/related")
5999 (not (or gnus-mime-display-multipart-as-mixed
6000 gnus-mime-display-multipart-related-as-mixed)))
6001 (gnus-mime-display-part (cadr handle)))
6002 ((equal (car handle) "multipart/signed")
6003 (gnus-add-wash-type 'signed)
6004 (gnus-mime-display-security handle))
6005 ((equal (car handle) "multipart/encrypted")
6006 (gnus-add-wash-type 'encrypted)
6007 (gnus-mime-display-security handle))
6008 ;; Other multiparts are handled like multipart/mixed.
6009 (t
6010 (gnus-mime-display-mixed (cdr handle)))))
6011
6012 (defun gnus-mime-part-function (handles)
6013 (if (stringp (car handles))
6014 (mapcar 'gnus-mime-part-function (cdr handles))
6015 (funcall gnus-article-mime-part-function handles)))
6016
6017 (defun gnus-mime-display-mixed (handles)
6018 (mapcar 'gnus-mime-display-part handles))
6019
6020 (defun gnus-mime-display-single (handle)
6021 (let ((type (mm-handle-media-type handle))
6022 (ignored gnus-ignored-mime-types)
6023 (not-attachment t)
6024 display text)
6025 (catch 'ignored
6026 (progn
6027 (while ignored
6028 (when (string-match (pop ignored) type)
6029 (throw 'ignored nil)))
6030 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6031 (with-current-buffer gnus-summary-buffer
6032 gnus-inhibit-images)
6033 gnus-inhibit-images)
6034 (string-match "\\`image/" type)))
6035 (setq not-attachment
6036 (and (not (mm-inline-override-p handle))
6037 (or (not (mm-handle-disposition handle))
6038 (equal (car (mm-handle-disposition handle))
6039 "inline")
6040 (mm-attachment-override-p handle))))
6041 (mm-automatic-display-p handle)
6042 (or (and
6043 (mm-inlinable-p handle)
6044 (mm-inlined-p handle))
6045 (mm-automatic-external-display-p type)))
6046 (setq display t)
6047 (when (equal (mm-handle-media-supertype handle) "text")
6048 (setq text t)))
6049 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6050 beg)
6051 (unless id
6052 (setq id (1+ (length gnus-article-mime-handle-alist)))
6053 (push (cons id handle) gnus-article-mime-handle-alist))
6054 (when (and display
6055 (equal (mm-handle-media-supertype handle) "message"))
6056 (insert-char
6057 ?\n
6058 (cond ((not (bolp)) 2)
6059 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6060 (t 1))))
6061 (when (or (not display)
6062 (not (gnus-unbuttonized-mime-type-p type))
6063 (eq id gnus-mime-buttonized-part-id))
6064 (gnus-insert-mime-button
6065 handle id (list (or display (and not-attachment text)))))
6066 (setq beg (point))
6067 (cond
6068 (display
6069 (let ((mail-parse-charset gnus-newsgroup-charset)
6070 (mail-parse-ignored-charsets
6071 (save-excursion (condition-case ()
6072 (set-buffer gnus-summary-buffer)
6073 (error))
6074 gnus-newsgroup-ignored-charsets)))
6075 (gnus-bind-mm-vars (mm-display-part handle t))))
6076 ((and text not-attachment)
6077 (mm-display-inline handle)))
6078 (goto-char (point-max))
6079 (if (string-match "\\`image/" type)
6080 (gnus-article-insert-newline)
6081 (if (prog1
6082 (= (skip-chars-backward "\n") -1)
6083 (unless (eobp) (forward-char 1)))
6084 (gnus-article-insert-newline)
6085 (put-text-property (point) (point-max) 'gnus-undeletable t))
6086 (goto-char (point-max)))
6087 ;; Do highlighting.
6088 (save-excursion
6089 (save-restriction
6090 (narrow-to-region beg (point))
6091 (if (eq handle gnus-article-mime-handles)
6092 ;; The format=flowed case.
6093 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6094 ;; Don't count signature parts that are never displayed.
6095 ;; The part number should be re-calculated supposing this
6096 ;; might be a message/rfc822 part.
6097 (let (handles)
6098 (dolist (part gnus-article-mime-handles)
6099 (unless (or (stringp part)
6100 (equal (car (mm-handle-type part))
6101 "application/pgp-signature"))
6102 (push part handles)))
6103 (gnus-treat-article
6104 nil (length (memq handle handles)) (length handles)
6105 (mm-handle-media-type handle)))))))))))
6106
6107 (defun gnus-unbuttonized-mime-type-p (type)
6108 "Say whether TYPE is to be unbuttonized."
6109 (unless gnus-inhibit-mime-unbuttonizing
6110 (when (catch 'found
6111 (let ((types gnus-unbuttonized-mime-types))
6112 (while types
6113 (when (string-match (pop types) type)
6114 (throw 'found t)))))
6115 (not (catch 'found
6116 (let ((types gnus-buttonized-mime-types))
6117 (while types
6118 (when (string-match (pop types) type)
6119 (throw 'found t)))))))))
6120
6121 (defun gnus-article-insert-newline ()
6122 "Insert a newline, but mark it as undeletable."
6123 (gnus-put-text-property
6124 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6125
6126 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6127 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6128 (ihandles handles)
6129 (point (point))
6130 handle (inhibit-read-only t) from begend not-pref)
6131 (save-window-excursion
6132 (save-restriction
6133 (when ibegend
6134 (narrow-to-region (car ibegend)
6135 (or (cdr ibegend)
6136 (progn
6137 (goto-char (car ibegend))
6138 (forward-line 2)
6139 (point))))
6140 (delete-region (point-min) (point-max))
6141 (mm-remove-parts handles))
6142 (setq begend (list (point-marker)))
6143 ;; Do the toggle.
6144 (unless (setq not-pref (cadr (member preferred ihandles)))
6145 (setq not-pref (car ihandles)))
6146 (when (or ibegend
6147 (not preferred)
6148 (not (gnus-unbuttonized-mime-type-p
6149 "multipart/alternative")))
6150 (gnus-add-text-properties
6151 (setq from (point))
6152 (progn
6153 (insert (format "%d. " id))
6154 (point))
6155 `(gnus-callback
6156 (lambda (handles)
6157 (unless ,(not ibegend)
6158 (setq gnus-article-mime-handle-alist
6159 ',gnus-article-mime-handle-alist))
6160 (gnus-mime-display-alternative
6161 ',ihandles ',not-pref ',begend ,id))
6162 keymap ,gnus-mime-button-map
6163 mouse-face ,gnus-article-mouse-face
6164 face ,gnus-article-button-face
6165 gnus-part ,id
6166 article-type multipart
6167 rear-nonsticky t))
6168 (widget-convert-button 'link from (point)
6169 :action 'gnus-widget-press-button)
6170 ;; Do the handles
6171 (while (setq handle (pop handles))
6172 (gnus-add-text-properties
6173 (setq from (point))
6174 (progn
6175 (insert (format "(%c) %-18s"
6176 (if (equal handle preferred) ?* ? )
6177 (mm-handle-media-type handle)))
6178 (point))
6179 `(gnus-callback
6180 (lambda (handles)
6181 (unless ,(not ibegend)
6182 (setq gnus-article-mime-handle-alist
6183 ',gnus-article-mime-handle-alist))
6184 (gnus-mime-display-alternative
6185 ',ihandles ',handle ',begend ,id))
6186 keymap ,gnus-mime-button-map
6187 mouse-face ,gnus-article-mouse-face
6188 face ,gnus-article-button-face
6189 gnus-part ,id
6190 gnus-data ,handle
6191 rear-nonsticky t))
6192 (widget-convert-button 'link from (point)
6193 :action 'gnus-widget-press-button)
6194 (insert " "))
6195 (insert "\n\n"))
6196 (when preferred
6197 (if (stringp (car preferred))
6198 (gnus-display-mime preferred)
6199 (let ((mail-parse-charset gnus-newsgroup-charset)
6200 (mail-parse-ignored-charsets
6201 (with-current-buffer gnus-summary-buffer
6202 gnus-newsgroup-ignored-charsets)))
6203 (gnus-bind-mm-vars (mm-display-part preferred))
6204 ;; Do highlighting.
6205 (save-excursion
6206 (save-restriction
6207 (narrow-to-region (car begend) (point-max))
6208 (gnus-treat-article
6209 nil (length gnus-article-mime-handle-alist)
6210 (gnus-article-mime-total-parts)
6211 (mm-handle-media-type preferred))))))
6212 (goto-char (point-max))
6213 (setcdr begend (point-marker)))))
6214 (when ibegend
6215 (goto-char point)))
6216 ;; Redraw attachment buttons in the header.
6217 (when gnus-mime-display-attachment-buttons-in-header
6218 (gnus-mime-buttonize-attachments-in-header)))
6219
6220 (defconst gnus-article-wash-status-strings
6221 (let ((alist '((cite "c" "Possible hidden citation text"
6222 " " "All citation text visible")
6223 (headers "h" "Hidden headers"
6224 " " "All headers visible.")
6225 (pgp "p" "Encrypted or signed message status hidden"
6226 " " "No hidden encryption nor digital signature status")
6227 (signature "s" "Signature has been hidden"
6228 " " "Signature is visible")
6229 (overstrike "o" "Overstrike (^H) characters applied"
6230 " " "No overstrike characters applied")
6231 (emphasis "e" "/*_Emphasis_*/ characters applied"
6232 " " "No /*_emphasis_*/ characters applied")))
6233 result)
6234 (dolist (entry alist result)
6235 (let ((key (nth 0 entry))
6236 (on (copy-sequence (nth 1 entry)))
6237 (on-help (nth 2 entry))
6238 (off (copy-sequence (nth 3 entry)))
6239 (off-help (nth 4 entry)))
6240 (put-text-property 0 1 'help-echo on-help on)
6241 (put-text-property 0 1 'help-echo off-help off)
6242 (push (list key on off) result))))
6243 "Alist of strings describing wash status in the mode line.
6244 Each entry has the form (KEY ON OF), where the KEY is a symbol
6245 representing the particular washing function, ON is the string to use
6246 in the article mode line when the washing function is active, and OFF
6247 is the string to use when it is inactive.")
6248
6249 (defun gnus-article-wash-status-entry (key value)
6250 (let ((entry (assoc key gnus-article-wash-status-strings)))
6251 (if value (nth 1 entry) (nth 2 entry))))
6252
6253 (defun gnus-article-wash-status ()
6254 "Return a string which display status of article washing."
6255 (with-current-buffer gnus-article-buffer
6256 (let ((cite (memq 'cite gnus-article-wash-types))
6257 (headers (memq 'headers gnus-article-wash-types))
6258 (boring (memq 'boring-headers gnus-article-wash-types))
6259 (pgp (memq 'pgp gnus-article-wash-types))
6260 (pem (memq 'pem gnus-article-wash-types))
6261 (signed (memq 'signed gnus-article-wash-types))
6262 (encrypted (memq 'encrypted gnus-article-wash-types))
6263 (signature (memq 'signature gnus-article-wash-types))
6264 (overstrike (memq 'overstrike gnus-article-wash-types))
6265 (emphasis (memq 'emphasis gnus-article-wash-types)))
6266 (concat
6267 (gnus-article-wash-status-entry 'cite cite)
6268 (gnus-article-wash-status-entry 'headers (or headers boring))
6269 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6270 (gnus-article-wash-status-entry 'signature signature)
6271 (gnus-article-wash-status-entry 'overstrike overstrike)
6272 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6273
6274 (defun gnus-add-wash-type (type)
6275 "Add a washing of TYPE to the current status."
6276 (add-to-list 'gnus-article-wash-types type))
6277
6278 (defun gnus-delete-wash-type (type)
6279 "Add a washing of TYPE to the current status."
6280 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6281
6282 (defun gnus-add-image (category image)
6283 "Add IMAGE of CATEGORY to the list of displayed images."
6284 (let ((entry (assq category gnus-article-image-alist)))
6285 (unless entry
6286 (setq entry (list category))
6287 (push entry gnus-article-image-alist))
6288 (nconc entry (list image))))
6289
6290 (defun gnus-delete-images (category)
6291 "Delete all images in CATEGORY."
6292 (let ((entry (assq category gnus-article-image-alist)))
6293 (dolist (image (cdr entry))
6294 (gnus-remove-image image category))
6295 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6296 (gnus-delete-wash-type category)))
6297
6298 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6299
6300 (defun gnus-article-maybe-hide-headers ()
6301 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6302 Provided for backwards compatibility."
6303 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6304 (not (with-current-buffer gnus-summary-buffer
6305 gnus-have-all-headers)))
6306 (not gnus-inhibit-hiding))
6307 (gnus-article-hide-headers)))
6308
6309 (declare-function shr-put-image "shr" (data alt &optional flags))
6310
6311 (defun gnus-shr-put-image (data alt &optional flags)
6312 "Put image DATA with a string ALT. Enable image to be deleted."
6313 (let ((image (if flags
6314 (shr-put-image data (propertize (or alt "*")
6315 'gnus-image-category 'shr)
6316 flags)
6317 ;; Old `shr-put-image' doesn't take the optional `flags'
6318 ;; argument.
6319 (shr-put-image data (propertize (or alt "*")
6320 'gnus-image-category 'shr)))))
6321 (when image
6322 (gnus-add-image 'shr image))))
6323
6324 (defun gnus-article-mime-handles (&optional alist id all)
6325 (if alist
6326 (let ((i 1) newid flat)
6327 (dolist (handle alist flat)
6328 (setq newid (append id (list i))
6329 i (1+ i))
6330 (if (stringp (car handle))
6331 (setq flat (nconc flat (gnus-article-mime-handles
6332 (cdr handle) newid all)))
6333 (delq (rassq handle all) all)
6334 (setq flat (nconc flat (list (cons newid handle)))))))
6335 (let ((flat (list nil)))
6336 ;; Assume that elements of `gnus-article-mime-handle-alist'
6337 ;; are in the decreasing order, but unnumbered subsidiaries
6338 ;; in each element are in the increasing order.
6339 (dolist (handle (reverse gnus-article-mime-handle-alist))
6340 (if (stringp (cadr handle))
6341 (setq flat (nconc flat (gnus-article-mime-handles
6342 (cddr handle) (list (car handle)) flat)))
6343 (delq (rassq (cdr handle) flat) flat)
6344 (setq flat (nconc flat (list (cons (list (car handle))
6345 (cdr handle)))))))
6346 (setq flat (cdr flat))
6347 (mapc (lambda (handle)
6348 (if (cdar handle)
6349 ;; This is a hidden (i.e. unnumbered) handle.
6350 (progn
6351 (setcar handle
6352 (1+ (caar gnus-article-mime-handle-alist)))
6353 (push handle gnus-article-mime-handle-alist))
6354 (setcar handle (caar handle))))
6355 flat)
6356 flat)))
6357
6358 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6359 "Show attachments as buttons in the end of the header of an article.
6360 This function toggles the display when called interactively. Note that
6361 buttons to be added to the header are only the ones that aren't inlined
6362 in the body. Use `gnus-header-face-alist' to highlight buttons."
6363 (interactive (list t))
6364 (gnus-with-article-buffer
6365 (let ((case-fold-search t) buttons handle type st)
6366 (save-excursion
6367 (save-restriction
6368 (widen)
6369 (article-narrow-to-head)
6370 ;; Header buttons exist?
6371 (while (and (not buttons)
6372 (re-search-forward "^attachments?:[\n ]+" nil t))
6373 (when (get-char-property (match-end 0)
6374 'gnus-button-attachment-extra)
6375 (setq buttons (match-beginning 0))))
6376 (widen)
6377 (when buttons
6378 ;; Delete header buttons.
6379 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6380 (match-beginning 0)
6381 (point-max))))
6382 (unless (and interactive buttons)
6383 ;; Find buttons.
6384 (setq buttons nil)
6385 (dolist (button (gnus-article-mime-handles))
6386 (setq handle (cdr button)
6387 type (mm-handle-media-type handle))
6388 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6389 (with-current-buffer gnus-summary-buffer
6390 gnus-inhibit-images)
6391 gnus-inhibit-images)
6392 (string-match "\\`image/" type))
6393 (mm-inline-override-p handle)
6394 (and (mm-handle-disposition handle)
6395 (not (equal (car (mm-handle-disposition handle))
6396 "inline"))
6397 (not (mm-attachment-override-p handle)))
6398 (not (mm-automatic-display-p handle))
6399 (not (or (and (mm-inlinable-p handle)
6400 (mm-inlined-p handle))
6401 (mm-automatic-external-display-p type))))
6402 (push button buttons)))
6403 (when buttons
6404 ;; Add header buttons.
6405 (article-goto-body)
6406 (forward-line -1)
6407 (narrow-to-region (point) (point))
6408 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6409 (dolist (button (nreverse buttons))
6410 (setq st (point))
6411 (insert " ")
6412 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6413 (gnus-insert-mime-button handle (car button))
6414 (skip-chars-backward "\t\n ")
6415 (delete-region (point) (point-max))
6416 (when (> (current-column) (window-width))
6417 (goto-char st)
6418 (insert "\n")
6419 (end-of-line)))
6420 (insert "\n")
6421 (dolist (ovl (overlays-in (point-min) (point)))
6422 (overlay-put ovl 'gnus-button-attachment-extra t)
6423 (overlay-put ovl 'face nil))
6424 (let ((gnus-treatment-function-alist
6425 '((gnus-treat-highlight-headers
6426 gnus-article-highlight-headers))))
6427 (gnus-treat-article 'head)))))))))
6428
6429 ;;; Article savers.
6430
6431 (defun gnus-output-to-file (file-name)
6432 "Append the current article to a file named FILE-NAME.
6433 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6434 text and used as the value of the coding cookie which is added to the
6435 top of a file. Otherwise, this function saves a raw article without
6436 the coding cookie."
6437 (let* ((artbuf (current-buffer))
6438 (file-name-coding-system nnmail-pathname-coding-system)
6439 (coding gnus-article-save-coding-system)
6440 (coding-system-for-read (if coding
6441 nil ;; Rely on the coding cookie.
6442 mm-text-coding-system))
6443 (coding-system-for-write (or coding
6444 mm-text-coding-system-for-write
6445 mm-text-coding-system))
6446 (exists (file-exists-p file-name)))
6447 (with-temp-buffer
6448 (when exists
6449 (insert-file-contents file-name)
6450 (goto-char (point-min))
6451 ;; Remove the existing coding cookie.
6452 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6453 (delete-region (match-beginning 0) (match-end 0))))
6454 (goto-char (point-max))
6455 (insert-buffer-substring artbuf)
6456 ;; Append newline at end of the buffer as separator, and then
6457 ;; save it to file.
6458 (goto-char (point-max))
6459 (insert "\n")
6460 (when coding
6461 ;; If the coding system is not suitable to encode the text,
6462 ;; ask a user for a proper one.
6463 (when (fboundp 'select-safe-coding-system)
6464 (setq coding (coding-system-base
6465 (save-window-excursion
6466 (select-safe-coding-system (point-min) (point-max)
6467 coding))))
6468 (setq coding-system-for-write
6469 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6470 coding)))
6471 (goto-char (point-min))
6472 ;; Add the coding cookie.
6473 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6474 coding-system-for-write)))
6475 (if exists
6476 (progn
6477 (write-region (point-min) (point-max) file-name nil 'no-message)
6478 (message "Appended to %s" file-name))
6479 (write-region (point-min) (point-max) file-name))))
6480 t)
6481
6482 (defun gnus-narrow-to-page (&optional arg)
6483 "Narrow the article buffer to a page.
6484 If given a numerical ARG, move forward ARG pages."
6485 (interactive "P")
6486 (setq arg (if arg (prefix-numeric-value arg) 0))
6487 (with-current-buffer gnus-article-buffer
6488 (widen)
6489 ;; Remove any old next/prev buttons.
6490 (when (gnus-visual-p 'page-marker)
6491 (let ((inhibit-read-only t))
6492 (gnus-remove-text-with-property 'gnus-prev)
6493 (gnus-remove-text-with-property 'gnus-next)))
6494 (let (st nd pt)
6495 (when (save-excursion
6496 (cond ((< arg 0)
6497 (if (re-search-backward page-delimiter nil 'move (abs arg))
6498 (prog1
6499 (setq nd (match-beginning 0)
6500 pt nd)
6501 (when (re-search-backward page-delimiter nil t)
6502 (setq st (match-end 0))))
6503 (when (re-search-forward page-delimiter nil t)
6504 (setq nd (match-beginning 0)
6505 pt (point-min)))))
6506 ((> arg 0)
6507 (if (re-search-forward page-delimiter nil 'move arg)
6508 (prog1
6509 (setq st (match-end 0)
6510 pt st)
6511 (when (re-search-forward page-delimiter nil t)
6512 (setq nd (match-beginning 0))))
6513 (when (re-search-backward page-delimiter nil t)
6514 (setq st (match-end 0)
6515 pt (point-max)))))
6516 (t
6517 (when (re-search-backward page-delimiter nil t)
6518 (goto-char (setq st (match-end 0))))
6519 (when (re-search-forward page-delimiter nil t)
6520 (setq nd (match-beginning 0)))
6521 (or st nd))))
6522 (setq gnus-page-broken t)
6523 (when pt (goto-char pt))
6524 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6525 (when (gnus-visual-p 'page-marker)
6526 (save-excursion
6527 (when nd
6528 (goto-char nd)
6529 (gnus-insert-next-page-button))
6530 (when st
6531 (goto-char st)
6532 (gnus-insert-prev-page-button))))))))
6533
6534 ;; Article mode commands
6535
6536 (defun gnus-article-goto-next-page ()
6537 "Show the next page of the article."
6538 (interactive)
6539 (when (gnus-article-next-page)
6540 (goto-char (point-min))
6541 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6542
6543
6544 (defun gnus-article-goto-prev-page ()
6545 "Show the previous page of the article."
6546 (interactive)
6547 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6548 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6549 (gnus-article-prev-page nil)))
6550
6551 ;; This is cleaner but currently breaks `gnus-pick-mode':
6552 ;;
6553 ;; (defun gnus-article-goto-next-page ()
6554 ;; "Show the next page of the article."
6555 ;; (interactive)
6556 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6557 ;; (gnus-summary-next-page)))
6558 ;;
6559 ;; (defun gnus-article-goto-prev-page ()
6560 ;; "Show the next page of the article."
6561 ;; (interactive)
6562 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6563 ;; (gnus-summary-prev-page)))
6564
6565 (defun gnus-article-next-page (&optional lines)
6566 "Show the next page of the current article.
6567 If end of article, return non-nil. Otherwise return nil.
6568 Argument LINES specifies lines to be scrolled up."
6569 (interactive "p")
6570 (move-to-window-line (- -1 scroll-margin))
6571 (if (and (not (and gnus-article-over-scroll
6572 (> (count-lines (window-start) (point-max))
6573 (+ (or lines (1- (window-height))) scroll-margin))))
6574 (save-excursion
6575 (end-of-line)
6576 (and (pos-visible-in-window-p) ;Not continuation line.
6577 (>= (point) (point-max)))))
6578 ;; Nothing in this page.
6579 (if (or (not gnus-page-broken)
6580 (save-excursion
6581 (save-restriction
6582 (widen)
6583 (forward-line)
6584 (eobp)))) ;Real end-of-buffer?
6585 (progn
6586 (when gnus-article-over-scroll
6587 (gnus-article-next-page-1 lines))
6588 t) ;Nothing more.
6589 (gnus-narrow-to-page 1) ;Go to next page.
6590 nil)
6591 ;; More in this page.
6592 (gnus-article-next-page-1 lines)
6593 nil))
6594
6595 (defun gnus-article-beginning-of-window ()
6596 "Move point to the beginning of the window.
6597 In Emacs, the point is placed at the line number which `scroll-margin'
6598 specifies."
6599 ;; There is an obscure bug in Emacs that makes it impossible to
6600 ;; scroll past big pictures in the article buffer. Try to fix
6601 ;; this by adding a sanity check by counting the lines visible.
6602 (when (> (count-lines (window-start) (window-end)) 30)
6603 (move-to-window-line
6604 (min (max 0 scroll-margin)
6605 (max 1 (- (window-height)
6606 (if mode-line-format 1 0)
6607 (if header-line-format 1 0)
6608 2))))))
6609
6610 (defvar scroll-in-place)
6611
6612 (defun gnus-article-next-page-1 (lines)
6613 (condition-case ()
6614 (let ((scroll-in-place nil)
6615 (auto-window-vscroll nil))
6616 (scroll-up lines))
6617 (end-of-buffer
6618 ;; Long lines may cause an end-of-buffer error.
6619 (goto-char (point-max))))
6620 (gnus-article-beginning-of-window))
6621
6622 (defun gnus-article-prev-page (&optional lines)
6623 "Show previous page of current article.
6624 Argument LINES specifies lines to be scrolled down."
6625 (interactive "p")
6626 (move-to-window-line 0)
6627 (if (and gnus-page-broken
6628 (bobp)
6629 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6630 (progn
6631 (gnus-narrow-to-page -1) ;Go to previous page.
6632 (goto-char (point-max))
6633 (recenter (if gnus-article-over-scroll
6634 (if lines
6635 (max (+ lines scroll-margin) 3)
6636 (- (window-height) 2))
6637 -1)))
6638 (prog1
6639 (condition-case ()
6640 (let ((scroll-in-place nil))
6641 (scroll-down lines))
6642 (beginning-of-buffer
6643 (goto-char (point-min))))
6644 (gnus-article-beginning-of-window))))
6645
6646 (defun gnus-article-only-boring-p ()
6647 "Decide whether there is only boring text remaining in the article.
6648 Something \"interesting\" is a word of at least two letters that does
6649 not have a face in `gnus-article-boring-faces'."
6650 (when (and gnus-article-skip-boring
6651 (boundp 'gnus-article-boring-faces)
6652 (symbol-value 'gnus-article-boring-faces))
6653 (save-excursion
6654 (let ((inhibit-point-motion-hooks t))
6655 (catch 'only-boring
6656 (while (re-search-forward "\\b\\w\\w" nil t)
6657 (forward-char -1)
6658 (when (not (gnus-intersection
6659 (gnus-faces-at (point))
6660 (symbol-value 'gnus-article-boring-faces)))
6661 (throw 'only-boring nil)))
6662 (throw 'only-boring t))))))
6663
6664 (defun gnus-article-refer-article ()
6665 "Read article specified by message-id around point."
6666 (interactive)
6667 (save-excursion
6668 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6669 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6670 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6671 (let ((msg-id (concat "<" (match-string 0) ">")))
6672 (set-buffer gnus-summary-buffer)
6673 (gnus-summary-refer-article msg-id))
6674 (error "No references around point"))))
6675
6676 (defun gnus-article-show-summary ()
6677 "Reconfigure windows to show summary buffer."
6678 (interactive)
6679 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6680 (error "There is no summary buffer for this article buffer")
6681 (gnus-article-set-globals)
6682 (gnus-configure-windows 'article)
6683 (gnus-summary-goto-subject gnus-current-article)
6684 (gnus-summary-position-point)))
6685
6686 (defun gnus-article-describe-briefly ()
6687 "Describe article mode commands briefly."
6688 (interactive)
6689 (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")))
6690
6691 (defun gnus-article-check-buffer ()
6692 "Beep if not in an article buffer."
6693 (unless (derived-mode-p 'gnus-article-mode)
6694 (error "Command invoked outside of a Gnus article buffer")))
6695
6696 (defvar gnus-pick-mode)
6697
6698 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6699 "Read a summary buffer key sequence and execute it from the article buffer."
6700 (interactive "P")
6701 (gnus-article-check-buffer)
6702 (let ((nosaves
6703 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6704 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6705 "=" "^" "\M-^" "|"))
6706 (nosave-but-article
6707 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6708 "An" "Ap" [?A (meta return)] [?A delete]))
6709 (nosave-in-article
6710 '("AS" "\C-d"))
6711 keys new-sum-point)
6712 (with-current-buffer gnus-article-current-summary
6713 (let (gnus-pick-mode)
6714 (setq unread-command-events (nconc unread-command-events
6715 (list (or key last-command-event)))
6716 keys (read-key-sequence nil t))))
6717
6718 (message "")
6719
6720 (cond
6721 ((eq (aref keys (1- (length keys))) ?\C-h)
6722 (gnus-article-describe-bindings (substring keys 0 -1)))
6723 ((or (member keys nosaves)
6724 (member keys nosave-but-article)
6725 (member keys nosave-in-article))
6726 (let (func)
6727 (save-window-excursion
6728 (pop-to-buffer gnus-article-current-summary)
6729 ;; We disable the pick minor mode commands.
6730 (let (gnus-pick-mode)
6731 (setq func (key-binding keys t))))
6732 (if (or (not func)
6733 (numberp func))
6734 (ding)
6735 (unless (member keys nosave-in-article)
6736 (set-buffer gnus-article-current-summary))
6737 (when (and (symbolp func)
6738 (get func 'disabled))
6739 (error "Function %s disabled" func))
6740 (call-interactively func)
6741 (setq new-sum-point (point)))
6742 (when (member keys nosave-but-article)
6743 (pop-to-buffer gnus-article-buffer))))
6744 (t
6745 ;; These commands should restore window configuration.
6746 (let ((obuf (current-buffer))
6747 (owin (current-window-configuration))
6748 win func in-buffer selected new-sum-start new-sum-hscroll err)
6749 (cond (not-restore-window
6750 (pop-to-buffer gnus-article-current-summary)
6751 (setq win (selected-window)))
6752 ((setq win (get-buffer-window gnus-article-current-summary))
6753 (select-window win))
6754 (t
6755 (let ((summary-buffer gnus-article-current-summary))
6756 (gnus-configure-windows 'article)
6757 (unless (setq win (get-buffer-window summary-buffer 'visible))
6758 (let ((gnus-buffer-configuration
6759 '((article ((vertical 1.0
6760 (summary 0.25 point)
6761 (article 1.0)))))))
6762 (gnus-configure-windows 'article))
6763 (setq win (get-buffer-window summary-buffer 'visible)))
6764 (gnus-select-frame-set-input-focus (window-frame win))
6765 (select-window win))))
6766 (setq in-buffer (current-buffer))
6767 ;; We disable the pick minor mode commands.
6768 (setq func (let (gnus-pick-mode)
6769 (key-binding keys t)))
6770 (when (get func 'disabled)
6771 (error "Function %s disabled" func))
6772 (if (and func
6773 (functionp func)
6774 (condition-case code
6775 (progn
6776 (call-interactively func)
6777 t)
6778 (error
6779 (setq err code)
6780 nil)))
6781 (progn
6782 (when (eq win (selected-window))
6783 (setq new-sum-point (point)
6784 new-sum-start (window-start win)
6785 new-sum-hscroll (window-hscroll win)))
6786 (when (or (eq in-buffer (current-buffer))
6787 (when (eq obuf (current-buffer))
6788 (set-buffer in-buffer)
6789 t))
6790 (setq selected (ignore-errors (gnus-summary-select-article)))
6791 (set-buffer obuf)
6792 (unless not-restore-window
6793 (set-window-configuration owin))
6794 (when (and (eq selected 'old)
6795 new-sum-point)
6796 (set-window-start (get-buffer-window (current-buffer))
6797 1)
6798 (set-window-point (get-buffer-window (current-buffer))
6799 (if (article-goto-body)
6800 (1- (point))
6801 (point))))
6802 (when (and (not not-restore-window)
6803 new-sum-point
6804 (window-live-p win)
6805 (with-current-buffer (window-buffer win)
6806 (derived-mode-p 'gnus-summary-mode)))
6807 (set-window-point win new-sum-point)
6808 (set-window-start win new-sum-start)
6809 (set-window-hscroll win new-sum-hscroll))))
6810 (set-window-configuration owin)
6811 (if err
6812 (signal (car err) (cdr err))
6813 (ding))))))))
6814
6815 (defun gnus-article-read-summary-send-keys ()
6816 (interactive)
6817 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6818 (gnus-article-read-summary-keys)))
6819
6820 (defun gnus-article-describe-key (key)
6821 "Display documentation of the function invoked by KEY.
6822 KEY is a string or a vector."
6823 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6824 (read-key-sequence "Describe key: "))))
6825 (gnus-article-check-buffer)
6826 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6827 gnus-article-read-summary-send-keys))
6828 (with-current-buffer gnus-article-current-summary
6829 (setq unread-command-events
6830 (nconc
6831 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6832 (list 'meta (- x 128))
6833 x))
6834 key)
6835 unread-command-events))
6836 (let ((cursor-in-echo-area t)
6837 gnus-pick-mode)
6838 (describe-key (read-key-sequence nil t))))
6839 (describe-key key)))
6840
6841 (defun gnus-article-describe-key-briefly (key &optional insert)
6842 "Display documentation of the function invoked by KEY.
6843 KEY is a string or a vector."
6844 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6845 (read-key-sequence "Describe key: "))
6846 current-prefix-arg))
6847 (gnus-article-check-buffer)
6848 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6849 gnus-article-read-summary-send-keys))
6850 (with-current-buffer gnus-article-current-summary
6851 (setq unread-command-events
6852 (nconc
6853 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6854 (list 'meta (- x 128))
6855 x))
6856 key)
6857 unread-command-events))
6858 (let ((cursor-in-echo-area t)
6859 gnus-pick-mode)
6860 (describe-key-briefly (read-key-sequence nil t) insert)))
6861 (describe-key-briefly key insert)))
6862
6863 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6864 (defvar gnus-agent-summary-mode)
6865 (defvar gnus-draft-mode)
6866 (defvar help-xref-stack-item)
6867 (defvar help-xref-following)
6868
6869 (defun gnus-article-describe-bindings (&optional prefix)
6870 "Show a list of all defined keys, and their definitions.
6871 The optional argument PREFIX, if non-nil, should be a key sequence;
6872 then we display only bindings that start with that prefix."
6873 (interactive)
6874 (gnus-article-check-buffer)
6875 (let ((keymap (copy-keymap gnus-article-mode-map))
6876 (map (copy-keymap gnus-article-send-map))
6877 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6878 parent agent draft)
6879 (define-key keymap "S" map)
6880 (define-key map [t] nil)
6881 (with-current-buffer gnus-article-current-summary
6882 (set-keymap-parent
6883 keymap
6884 (if (setq parent (keymap-parent gnus-article-mode-map))
6885 (prog1
6886 (setq parent (copy-keymap parent))
6887 (set-keymap-parent parent (current-local-map)))
6888 (current-local-map)))
6889 (set-keymap-parent map (key-binding "S"))
6890 (let (key def gnus-pick-mode)
6891 (while sumkeys
6892 (setq key (pop sumkeys))
6893 (cond ((and (vectorp key) (= (length key) 1)
6894 (consp (setq def (aref key 0)))
6895 (numberp (car def)) (numberp (cdr def)))
6896 (when (< (max (car def) (cdr def)) 128)
6897 (setq sumkeys
6898 (append (mapcar
6899 #'vector
6900 (nreverse (gnus-uncompress-range def)))
6901 sumkeys))))
6902 ((setq def (key-binding key))
6903 (unless (eq def 'undefined)
6904 (define-key keymap key def))))))
6905 (when (boundp 'gnus-agent-summary-mode)
6906 (setq agent gnus-agent-summary-mode))
6907 (when (boundp 'gnus-draft-mode)
6908 (setq draft gnus-draft-mode)))
6909 (with-temp-buffer
6910 (use-local-map keymap)
6911 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6912 (set (make-local-variable 'gnus-draft-mode) draft)
6913 (describe-bindings prefix))
6914 (let ((item `((lambda (prefix)
6915 (with-current-buffer ,(current-buffer)
6916 (gnus-article-describe-bindings prefix)))
6917 ,prefix)))
6918 ;; Loading `help-mode' here is necessary if `describe-bindings'
6919 ;; is replaced with something, e.g. `helm-descbinds'.
6920 (require 'help-mode)
6921 (with-current-buffer (let (help-xref-following) (help-buffer))
6922 (setq help-xref-stack-item item)))))
6923
6924 (defun gnus-article-reply-with-original (&optional wide)
6925 "Start composing a reply mail to the current message.
6926 The text in the region will be yanked. If the region isn't active,
6927 the entire article will be yanked."
6928 (interactive)
6929 (let ((article (cdr gnus-article-current))
6930 contents)
6931 (if (not (and transient-mark-mode mark-active))
6932 (with-current-buffer gnus-summary-buffer
6933 (gnus-summary-reply (list (list article)) wide))
6934 (setq contents (buffer-substring (point) (mark t)))
6935 ;; Deactivate active regions.
6936 (when (and (boundp 'transient-mark-mode)
6937 transient-mark-mode)
6938 (setq mark-active nil))
6939 (with-current-buffer gnus-summary-buffer
6940 (gnus-summary-reply
6941 (list (list article contents)) wide)))))
6942
6943 (defun gnus-article-wide-reply-with-original ()
6944 "Start composing a wide reply mail to the current message.
6945 The text in the region will be yanked. If the region isn't active,
6946 the entire article will be yanked."
6947 (interactive)
6948 (gnus-article-reply-with-original t))
6949
6950 (defun gnus-article-followup-with-original ()
6951 "Compose a followup to the current article.
6952 The text in the region will be yanked. If the region isn't active,
6953 the entire article will be yanked."
6954 (interactive)
6955 (let ((article (cdr gnus-article-current))
6956 contents)
6957 (if (not (and transient-mark-mode mark-active))
6958 (with-current-buffer gnus-summary-buffer
6959 (gnus-summary-followup (list (list article))))
6960 (setq contents (buffer-substring (point) (mark t)))
6961 ;; Deactivate active regions.
6962 (when (and (boundp 'transient-mark-mode)
6963 transient-mark-mode)
6964 (setq mark-active nil))
6965 (with-current-buffer gnus-summary-buffer
6966 (gnus-summary-followup
6967 (list (list article contents)))))))
6968
6969 (defun gnus-article-hide (&optional arg force)
6970 "Hide all the gruft in the current article.
6971 This means that signatures, cited text and (some) headers will be
6972 hidden.
6973 If given a prefix, show the hidden text instead."
6974 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6975 (gnus-article-hide-headers arg)
6976 (gnus-article-hide-list-identifiers arg)
6977 (gnus-article-hide-citation-maybe arg force)
6978 (gnus-article-hide-signature arg))
6979
6980 (defun gnus-check-group-server ()
6981 ;; Make sure the connection to the server is alive.
6982 (unless (gnus-server-opened
6983 (gnus-find-method-for-group gnus-newsgroup-name))
6984 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6985 (gnus-request-group gnus-newsgroup-name t)))
6986
6987 (declare-function nneething-get-file-name "nneething" (id))
6988
6989 (defun gnus-request-article-this-buffer (article group)
6990 "Get an article and insert it into this buffer."
6991 (let (do-update-line sparse-header)
6992 (prog1
6993 (save-excursion
6994 (erase-buffer)
6995 (gnus-kill-all-overlays)
6996 (setq group (or group gnus-newsgroup-name))
6997
6998 ;; Using `gnus-request-article' directly will insert the article into
6999 ;; `nntp-server-buffer' - so we'll save some time by not having to
7000 ;; copy it from the server buffer into the article buffer.
7001
7002 ;; We only request an article by message-id when we do not have the
7003 ;; headers for it, so we'll have to get those.
7004 (when (stringp article)
7005 (gnus-read-header article))
7006
7007 ;; If the article number is negative, that means that this article
7008 ;; doesn't belong in this newsgroup (possibly), so we find its
7009 ;; message-id and request it by id instead of number.
7010 (when (and (numberp article)
7011 gnus-summary-buffer
7012 (get-buffer gnus-summary-buffer)
7013 (gnus-buffer-exists-p gnus-summary-buffer))
7014 (with-current-buffer gnus-summary-buffer
7015 (let ((header (gnus-summary-article-header article)))
7016 (when (< article 0)
7017 (cond
7018 ((memq article gnus-newsgroup-sparse)
7019 ;; This is a sparse gap article.
7020 (setq do-update-line article)
7021 (setq article (mail-header-id header))
7022 (setq sparse-header (gnus-read-header article))
7023 (setq gnus-newsgroup-sparse
7024 (delq article gnus-newsgroup-sparse)))
7025 ((vectorp header)
7026 ;; It's a real article.
7027 (setq article (mail-header-id header)))
7028 (t
7029 ;; It is an extracted pseudo-article.
7030 (setq article 'pseudo)
7031 (gnus-request-pseudo-article header))))
7032
7033 (let ((method (gnus-find-method-for-group
7034 gnus-newsgroup-name)))
7035 (when (and (eq (car method) 'nneething)
7036 (vectorp header))
7037 (let ((dir (nneething-get-file-name
7038 (mail-header-id header))))
7039 (when (and (stringp dir)
7040 (file-directory-p dir))
7041 (setq article 'nneething)
7042 (gnus-group-enter-directory dir))))))))
7043
7044 (cond
7045 ;; Refuse to select canceled articles.
7046 ((and (numberp article)
7047 gnus-summary-buffer
7048 (get-buffer gnus-summary-buffer)
7049 (gnus-buffer-exists-p gnus-summary-buffer)
7050 (eq (cdr (with-current-buffer gnus-summary-buffer
7051 (assq article gnus-newsgroup-reads)))
7052 gnus-canceled-mark))
7053 nil)
7054 ;; We first check `gnus-original-article-buffer'.
7055 ((and (get-buffer gnus-original-article-buffer)
7056 (numberp article)
7057 (with-current-buffer gnus-original-article-buffer
7058 (and (equal (car gnus-original-article) group)
7059 (eq (cdr gnus-original-article) article))))
7060 ;; `insert-buffer-substring' would incorrectly use the
7061 ;; equivalent of string-make-multibyte which amount to decoding
7062 ;; with locale-coding-system, causing failure of
7063 ;; subsequent decoding.
7064 (insert (mm-string-to-multibyte
7065 (with-current-buffer gnus-original-article-buffer
7066 (buffer-substring (point-min) (point-max)))))
7067 'article)
7068 ;; Check the backlog.
7069 ((and gnus-keep-backlog
7070 (gnus-backlog-request-article group article (current-buffer)))
7071 'article)
7072 ;; Check asynchronous pre-fetch.
7073 ((gnus-async-request-fetched-article group article (current-buffer))
7074 (gnus-async-prefetch-next group article gnus-summary-buffer)
7075 (when (and (numberp article) gnus-keep-backlog)
7076 (gnus-backlog-enter-article group article (current-buffer)))
7077 'article)
7078 ;; Check the cache.
7079 ((and gnus-use-cache
7080 (numberp article)
7081 (gnus-cache-request-article article group))
7082 'article)
7083 ;; Check the agent cache.
7084 ((gnus-agent-request-article article group)
7085 'article)
7086 ;; Get the article and put into the article buffer.
7087 ((or (stringp article)
7088 (numberp article))
7089 (let ((gnus-override-method gnus-override-method)
7090 (methods (and (stringp article)
7091 (with-current-buffer gnus-summary-buffer
7092 (gnus-refer-article-methods))))
7093 (backend (car (gnus-find-method-for-group
7094 gnus-newsgroup-name)))
7095 result
7096 (inhibit-read-only t))
7097 (when (and (null gnus-override-method)
7098 methods)
7099 (setq gnus-override-method (pop methods)))
7100 (while (not result)
7101 (erase-buffer)
7102 (gnus-kill-all-overlays)
7103 (let ((gnus-newsgroup-name group))
7104 (gnus-check-group-server))
7105 (cond
7106 ((gnus-request-article article group (current-buffer))
7107 (when (numberp article)
7108 (gnus-async-prefetch-next group article
7109 gnus-summary-buffer)
7110 (when gnus-keep-backlog
7111 (gnus-backlog-enter-article
7112 group article (current-buffer)))
7113 (when (and gnus-agent
7114 (gnus-agent-group-covered-p group))
7115 (gnus-agent-store-article article group)))
7116 (setq result 'article))
7117 (methods
7118 (setq gnus-override-method (pop methods)))
7119 ((not (string-match "^400 "
7120 (nnheader-get-report backend)))
7121 ;; If we get 400 server disconnect, reconnect and
7122 ;; retry; otherwise, assume the article has expired.
7123 (setq result 'done))))
7124 (and (eq result 'article) 'article)))
7125 ;; It was a pseudo.
7126 (t article)))
7127
7128 ;; Associate this article with the current summary buffer.
7129 (setq gnus-article-current-summary gnus-summary-buffer)
7130
7131 ;; Take the article from the original article buffer
7132 ;; and place it in the buffer it's supposed to be in.
7133 (when (and (get-buffer gnus-article-buffer)
7134 (equal (buffer-name (current-buffer))
7135 (buffer-name (get-buffer gnus-article-buffer))))
7136 (save-excursion
7137 (if (get-buffer gnus-original-article-buffer)
7138 (set-buffer gnus-original-article-buffer)
7139 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7140 (buffer-disable-undo)
7141 (setq major-mode 'gnus-original-article-mode)
7142 (setq buffer-read-only t))
7143 (let ((inhibit-read-only t))
7144 (erase-buffer)
7145 (insert-buffer-substring gnus-article-buffer))
7146 (setq gnus-original-article (cons group article)))
7147
7148 ;; Decode charsets.
7149 (run-hooks 'gnus-article-decode-hook)
7150 ;; Mark article as decoded or not.
7151 (setq gnus-article-decoded-p gnus-article-decode-hook))
7152
7153 ;; Update sparse articles.
7154 (when (and do-update-line
7155 (or (numberp article)
7156 (stringp article)))
7157 (let ((buf (current-buffer)))
7158 (set-buffer gnus-summary-buffer)
7159 (gnus-summary-update-article do-update-line sparse-header)
7160 (gnus-summary-goto-subject do-update-line nil t)
7161 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7162 (point))
7163 (set-buffer buf))))))
7164
7165 (defun gnus-block-private-groups (group)
7166 "Allows images in newsgroups to be shown, blocks images in all
7167 other groups."
7168 (if (or (gnus-news-group-p group)
7169 (gnus-member-of-valid 'global group))
7170 ;; Block nothing in news groups.
7171 nil
7172 ;; Block everything anywhere else.
7173 "."))
7174
7175 (defun gnus-blocked-images ()
7176 (if (functionp gnus-blocked-images)
7177 (funcall gnus-blocked-images gnus-newsgroup-name)
7178 gnus-blocked-images))
7179
7180 ;;;
7181 ;;; Article editing
7182 ;;;
7183
7184 (defcustom gnus-article-edit-mode-hook nil
7185 "Hook run in article edit mode buffers."
7186 :group 'gnus-article-various
7187 :type 'hook)
7188
7189 (defvar gnus-article-edit-done-function nil)
7190
7191 (defvar gnus-article-edit-mode-map nil)
7192
7193 ;; Should we be using derived.el for this?
7194 (unless gnus-article-edit-mode-map
7195 (setq gnus-article-edit-mode-map (make-keymap))
7196 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7197
7198 (gnus-define-keys gnus-article-edit-mode-map
7199 "\C-c?" describe-mode
7200 "\C-c\C-c" gnus-article-edit-done
7201 "\C-c\C-k" gnus-article-edit-exit
7202 "\C-c\C-f\C-t" message-goto-to
7203 "\C-c\C-f\C-o" message-goto-from
7204 "\C-c\C-f\C-b" message-goto-bcc
7205 ;;"\C-c\C-f\C-w" message-goto-fcc
7206 "\C-c\C-f\C-c" message-goto-cc
7207 "\C-c\C-f\C-s" message-goto-subject
7208 "\C-c\C-f\C-r" message-goto-reply-to
7209 "\C-c\C-f\C-n" message-goto-newsgroups
7210 "\C-c\C-f\C-d" message-goto-distribution
7211 "\C-c\C-f\C-f" message-goto-followup-to
7212 "\C-c\C-f\C-m" message-goto-mail-followup-to
7213 "\C-c\C-f\C-k" message-goto-keywords
7214 "\C-c\C-f\C-u" message-goto-summary
7215 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7216 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7217 "\C-c\C-b" message-goto-body
7218 "\C-c\C-i" message-goto-signature
7219
7220 "\C-c\C-t" message-insert-to
7221 "\C-c\C-n" message-insert-newsgroups
7222 "\C-c\C-o" message-sort-headers
7223 "\C-c\C-e" message-elide-region
7224 "\C-c\C-v" message-delete-not-region
7225 "\C-c\C-z" message-kill-to-signature
7226 "\M-\r" message-newline-and-reformat
7227 "\C-c\C-a" mml-attach-file
7228 "\C-a" message-beginning-of-line
7229 "\t" message-tab
7230 "\M-;" comment-region)
7231
7232 (gnus-define-keys (gnus-article-edit-wash-map
7233 "\C-c\C-w" gnus-article-edit-mode-map)
7234 "f" gnus-article-edit-full-stops))
7235
7236 (easy-menu-define
7237 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7238 '("Field"
7239 ["Fetch To" message-insert-to t]
7240 ["Fetch Newsgroups" message-insert-newsgroups t]
7241 "----"
7242 ["To" message-goto-to t]
7243 ["From" message-goto-from t]
7244 ["Subject" message-goto-subject t]
7245 ["Cc" message-goto-cc t]
7246 ["Reply-To" message-goto-reply-to t]
7247 ["Summary" message-goto-summary t]
7248 ["Keywords" message-goto-keywords t]
7249 ["Newsgroups" message-goto-newsgroups t]
7250 ["Followup-To" message-goto-followup-to t]
7251 ["Mail-Followup-To" message-goto-mail-followup-to t]
7252 ["Distribution" message-goto-distribution t]
7253 ["Body" message-goto-body t]
7254 ["Signature" message-goto-signature t]))
7255
7256 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7257 "Major mode for editing articles.
7258 This is an extended text-mode.
7259
7260 \\{gnus-article-edit-mode-map}"
7261 (make-local-variable 'gnus-article-edit-done-function)
7262 (make-local-variable 'gnus-prev-winconf)
7263 (set (make-local-variable 'font-lock-defaults)
7264 '(message-font-lock-keywords t))
7265 (set (make-local-variable 'mail-header-separator) "")
7266 (set (make-local-variable 'gnus-article-edit-mode) t)
7267 (easy-menu-add message-mode-field-menu message-mode-map)
7268 (mml-mode)
7269 (setq buffer-read-only nil)
7270 (buffer-enable-undo)
7271 (widen))
7272
7273 (defun gnus-article-edit (&optional force)
7274 "Edit the current article.
7275 This will have permanent effect only in mail groups.
7276 If FORCE is non-nil, allow editing of articles even in read-only
7277 groups."
7278 (interactive "P")
7279 (when (and (not force)
7280 (gnus-group-read-only-p))
7281 (error "The current newsgroup does not support article editing"))
7282 (gnus-article-date-original)
7283 (gnus-article-edit-article
7284 'ignore
7285 `(lambda (no-highlight)
7286 'ignore
7287 (gnus-summary-edit-article-done
7288 ,(or (mail-header-references gnus-current-headers) "")
7289 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7290
7291 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7292 "Start editing the contents of the current article buffer."
7293 (let ((winconf (current-window-configuration)))
7294 (set-buffer gnus-article-buffer)
7295 (let ((message-auto-save-directory
7296 ;; Don't associate the article buffer with a draft file.
7297 nil))
7298 (gnus-article-edit-mode))
7299 (funcall start-func)
7300 (set-buffer-modified-p nil)
7301 (gnus-configure-windows 'edit-article)
7302 (setq gnus-article-edit-done-function exit-func)
7303 (setq gnus-prev-winconf winconf)
7304 (unless quiet
7305 (gnus-message 6 "C-c C-c to end edits"))))
7306
7307 (defun gnus-article-edit-done (&optional arg)
7308 "Update the article edits and exit."
7309 (interactive "P")
7310 (let ((func gnus-article-edit-done-function)
7311 (buf (current-buffer))
7312 (start (window-start))
7313 (winconf gnus-prev-winconf))
7314 (widen) ;; Widen it in case that users narrowed the buffer.
7315 (funcall func arg)
7316 (set-buffer buf)
7317 ;; The cache and backlog have to be flushed somewhat.
7318 (when gnus-keep-backlog
7319 (gnus-backlog-remove-article
7320 (car gnus-article-current) (cdr gnus-article-current)))
7321 ;; Flush original article as well.
7322 (gnus-flush-original-article-buffer)
7323 (when gnus-use-cache
7324 (gnus-cache-update-article
7325 (car gnus-article-current) (cdr gnus-article-current)))
7326 ;; We remove all text props from the article buffer.
7327 (kill-all-local-variables)
7328 (set-text-properties (point-min) (point-max) nil)
7329 (gnus-article-mode)
7330 (set-window-configuration winconf)
7331 (set-buffer buf)
7332 (set-window-start (get-buffer-window buf) start)
7333 (set-window-point (get-buffer-window buf) (point)))
7334 (gnus-summary-show-article))
7335
7336 (defun gnus-flush-original-article-buffer ()
7337 (when (get-buffer gnus-original-article-buffer)
7338 (with-current-buffer gnus-original-article-buffer
7339 (setq gnus-original-article nil))))
7340
7341 (defun gnus-article-edit-exit ()
7342 "Exit the article editing without updating."
7343 (interactive)
7344 (when (or (not (buffer-modified-p))
7345 (yes-or-no-p "Article modified; kill anyway? "))
7346 (let ((curbuf (current-buffer))
7347 (p (point))
7348 (window-start (window-start)))
7349 (erase-buffer)
7350 (if (gnus-buffer-live-p gnus-original-article-buffer)
7351 (insert-buffer-substring gnus-original-article-buffer))
7352 (let ((winconf gnus-prev-winconf))
7353 (kill-all-local-variables)
7354 (gnus-article-mode)
7355 (set-window-configuration winconf)
7356 ;; Tippy-toe some to make sure that point remains where it was.
7357 (save-current-buffer
7358 (set-buffer curbuf)
7359 (set-window-start (get-buffer-window (current-buffer)) window-start)
7360 (goto-char p))))
7361 (gnus-summary-show-article)))
7362
7363 (defun gnus-article-edit-full-stops ()
7364 "Interactively repair spacing at end of sentences."
7365 (interactive)
7366 (save-excursion
7367 (goto-char (point-min))
7368 (search-forward-regexp "^$" nil t)
7369 (let ((case-fold-search nil))
7370 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7371
7372 ;;;
7373 ;;; Article highlights
7374 ;;;
7375
7376 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7377
7378 ;;; Internal Variables:
7379
7380 (defcustom gnus-button-url-regexp
7381 (concat
7382 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7383 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7384 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7385 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7386 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7387 (punct "!?:;.,"))
7388 (concat
7389 "\\(?:"
7390 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7391 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7392 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7393 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7394 "\\|"
7395 "[" chars punct "]+" "[" chars "]"
7396 "\\)"))
7397 (concat ;; XEmacs 21.4 doesn't support POSIX.
7398 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7399 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7400 "\\)")
7401 "Regular expression that matches URLs."
7402 :version "24.4"
7403 :group 'gnus-article-buttons
7404 :type 'regexp)
7405
7406 (defcustom gnus-button-valid-fqdn-regexp "\\([-A-Za-z0-9]+\\.\\)+[A-Za-z]+"
7407 "Regular expression that matches a valid FQDN."
7408 :version "25.2"
7409 :group 'gnus-article-buttons
7410 :type 'regexp)
7411
7412 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7413 (defcustom gnus-button-valid-localpart-regexp
7414 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7415 "Regular expression that matches a localpart of mail addresses or MIDs."
7416 :version "22.1"
7417 :group 'gnus-article-buttons
7418 :type 'regexp)
7419
7420 (defcustom gnus-button-man-handler 'manual-entry
7421 "Function to use for displaying man pages.
7422 The function must take at least one argument with a string naming the
7423 man page."
7424 :version "22.1"
7425 :type '(choice (function-item :tag "Man" manual-entry)
7426 (function-item :tag "Woman" woman)
7427 (function :tag "Other"))
7428 :group 'gnus-article-buttons)
7429
7430 (defcustom gnus-button-mid-or-mail-regexp
7431 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7432 gnus-button-valid-fqdn-regexp
7433 ">?\\)\\b")
7434 "Regular expression that matches a message ID or a mail address."
7435 :version "22.1"
7436 :group 'gnus-article-buttons
7437 :type 'regexp)
7438
7439 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7440 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7441 Strings like this can be either a message ID or a mail address. If it is one
7442 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7443 message ID or a mail address, respectively. If this variable is set to the
7444 symbol `ask', always query the user what do do. If it is a function, this
7445 function will be called with the string as its only argument. The function
7446 must return `mid', `mail', `invalid' or `ask'."
7447 :version "22.1"
7448 :group 'gnus-article-buttons
7449 :type '(choice (function-item :tag "Heuristic function"
7450 gnus-button-mid-or-mail-heuristic)
7451 (const ask)
7452 (const mid)
7453 (const mail)))
7454
7455 (defcustom gnus-button-mid-or-mail-heuristic-alist
7456 '((-10.0 . ".+\\$.+@")
7457 (-10.0 . "#")
7458 (-10.0 . "\\*")
7459 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7460 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7461 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7462 (-1.0 . "^[^a-z]+@")
7463 ;;
7464 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7465 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7466 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7467 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7468 ;;
7469 (-2.0 . "^[0-9]")
7470 (-1.0 . "^[0-9][0-9]")
7471 ;;
7472 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7473 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7474 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7475 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7476 ;;
7477 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7478 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7479 ;; "[0-9]{8,}.*\@"
7480 (-3.0
7481 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7482 ;; "[0-9]{12,}.*\@"
7483 ;; compensation for TDMA dated mail addresses:
7484 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7485 ;;
7486 (-20.0 . "\\.fsf@") ;; Gnus
7487 (-20.0 . "^slrn")
7488 (-20.0 . "^Pine")
7489 (-20.0 . "^alpine\\.")
7490 (-20.0 . "_-_") ;; Subject change in thread
7491 ;;
7492 (-20.0 . "\\.ln@") ;; leafnode
7493 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7494 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7495 ;;
7496 ;; (5.0 . "") ;; $local_part_len <= 7
7497 (10.0 . "^[^0-9]+@")
7498 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7499 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7500 (3.0 . "@stud")
7501 ;;
7502 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7503 ;;
7504 (0.5 . "^[A-Z][a-z]")
7505 (0.5 . "^[A-Z][a-z][a-z]")
7506 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7507 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7508 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7509
7510 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7511 address. The REGEXP is processed with `case-fold-search' set to nil."
7512 :version "22.1"
7513 :group 'gnus-article-buttons
7514 :type '(repeat (cons (number :tag "Rate")
7515 (regexp :tag "Regexp"))))
7516
7517 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7518 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7519 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7520 address, `ask' if unsure and `invalid' if the string is invalid."
7521 (let ((case-fold-search nil)
7522 (list gnus-button-mid-or-mail-heuristic-alist)
7523 (result 0) rate regexp lpartlen elem)
7524 (setq lpartlen
7525 (length (replace-regexp-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7526 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7527 ;; Certain special cases...
7528 (when (string-match
7529 (concat
7530 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7531 "^[0-9]+\\.[0-9]+@compuserve\\|"
7532 "@public\\.gmane\\.org")
7533 mid-or-mail)
7534 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7535 (setq result 'mail))
7536 (when (string-match "@.*@\\| " mid-or-mail)
7537 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7538 (setq result 'invalid))
7539 ;; Nothing more to do, if result is not a number here...
7540 (when (numberp result)
7541 (while list
7542 (setq elem (car list)
7543 rate (car elem)
7544 regexp (cdr elem)
7545 list (cdr list))
7546 (when (string-match regexp mid-or-mail)
7547 (setq result (+ result rate))
7548 (gnus-message
7549 9 "`%s' matched `%s', rate `%s', result `%s'."
7550 mid-or-mail regexp rate result)))
7551 (when (<= lpartlen 7)
7552 (setq result (+ result 5.0))
7553 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7554 mid-or-mail result))
7555 (when (>= lpartlen 12)
7556 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7557 (cond
7558 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7559 ;; Long local part should contain realname if e-mail address,
7560 ;; too many digits: message-id.
7561 ;; $score -= 5.0 + 0.1 * $local_part_len;
7562 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7563 (setq result (+ result rate))
7564 (gnus-message
7565 9 "Many digits in `%s', rate `%s', result `%s'."
7566 mid-or-mail rate result))
7567 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7568 mid-or-mail)
7569 ;; Too few vowels [^aeiouy]{4,}.*@
7570 (setq result (+ result -5.0))
7571 (gnus-message
7572 9 "Few vowels in `%s', rate `%s', result `%s'."
7573 mid-or-mail -5.0 result))
7574 (t
7575 (setq result (+ result 5.0))
7576 (gnus-message
7577 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7578 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7579 ;; Maybe we should make this a customizable alist: (condition . 'result)
7580 (cond
7581 ((symbolp result) result)
7582 ;; Now convert number into proper results:
7583 ((< result -10.0) 'mid)
7584 ((> result 10.0) 'mail)
7585 (t 'ask))))
7586
7587 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7588 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7589 (url-mid (concat "news" ":" mid-or-mail))
7590 (url-mailto (concat "mailto" ":" mid-or-mail)))
7591 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7592 (when (fboundp pref)
7593 (setq guessed
7594 ;; get rid of surrounding angles...
7595 (funcall pref
7596 (replace-regexp-in-string mid-or-mail "^<\\|>$" "")))
7597 (if (or (eq 'mid guessed) (eq 'mail guessed))
7598 (setq pref guessed)
7599 (setq pref 'ask)))
7600 (if (eq pref 'ask)
7601 (save-window-excursion
7602 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7603 (setq pref 'mail)
7604 (setq pref 'mid))))
7605 (cond ((eq pref 'mid)
7606 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7607 (gnus-button-handle-news url-mid))
7608 ((eq pref 'mail)
7609 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7610 (gnus-url-mailto url-mailto))
7611 (t (gnus-message 3 "Invalid string.")))))
7612
7613 (defun gnus-button-handle-custom (fun arg)
7614 "Call function FUN on argument ARG.
7615 Both FUN and ARG are supposed to be strings. ARG will be passed
7616 as a symbol to FUN."
7617 (funcall (intern fun)
7618 (if (string-match "^customize-apropos" fun)
7619 arg
7620 (intern arg))))
7621
7622 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7623
7624 (defun gnus-button-handle-describe-function (url)
7625 "Call `describe-function' when pushing the corresponding URL button."
7626 (describe-function
7627 (intern
7628 (replace-regexp-in-string url gnus-button-handle-describe-prefix ""))))
7629
7630 (defun gnus-button-handle-describe-variable (url)
7631 "Call `describe-variable' when pushing the corresponding URL button."
7632 (describe-variable
7633 (intern
7634 (replace-regexp-in-string url gnus-button-handle-describe-prefix ""))))
7635
7636 (defun gnus-button-handle-symbol (url)
7637 "Display help on variable or function.
7638 Calls `describe-variable' or `describe-function'."
7639 (let ((sym (intern url)))
7640 (cond
7641 ((fboundp sym) (describe-function sym))
7642 ((boundp sym) (describe-variable sym))
7643 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7644
7645 (defun gnus-button-handle-describe-key (url)
7646 "Call `describe-key' when pushing the corresponding URL button."
7647 (let* ((key-string
7648 (replace-regexp-in-string url gnus-button-handle-describe-prefix ""))
7649 (keys (ignore-errors (eval `(kbd ,key-string)))))
7650 (if keys
7651 (describe-key keys)
7652 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7653
7654 (defun gnus-button-handle-apropos (url)
7655 "Call `apropos' when pushing the corresponding URL button."
7656 (apropos (replace-regexp-in-string
7657 url gnus-button-handle-describe-prefix "")))
7658
7659 (defun gnus-button-handle-apropos-command (url)
7660 "Call `apropos' when pushing the corresponding URL button."
7661 (apropos-command
7662 (replace-regexp-in-string url gnus-button-handle-describe-prefix "")))
7663
7664 (defun gnus-button-handle-apropos-variable (url)
7665 "Call `apropos' when pushing the corresponding URL button."
7666 (funcall
7667 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7668 (replace-regexp-in-string url gnus-button-handle-describe-prefix "")))
7669
7670 (defun gnus-button-handle-apropos-documentation (url)
7671 "Call `apropos' when pushing the corresponding URL button."
7672 (funcall
7673 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7674 (replace-regexp-in-string url gnus-button-handle-describe-prefix "")))
7675
7676 (defun gnus-button-handle-library (url)
7677 "Call `locate-library' when pushing the corresponding URL button."
7678 (gnus-message 9 "url=`%s'" url)
7679 (let* ((lib (locate-library url))
7680 (file (replace-regexp-in-string (or lib "") "\\.elc" ".el")))
7681 (if (not lib)
7682 (gnus-message 1 "Cannot locale library `%s'." url)
7683 (find-file-read-only file))))
7684
7685 (defcustom gnus-button-man-level 5
7686 "*Integer that says how many man-related buttons Gnus will show.
7687 The higher the number, the more buttons will appear and the more false
7688 positives are possible. Note that you can set this variable local to
7689 specific groups. Setting it higher in Unix groups is probably a good idea.
7690 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7691 how to set variables in specific groups."
7692 :version "22.1"
7693 :group 'gnus-article-buttons
7694 :link '(custom-manual "(gnus)Group Parameters")
7695 :type 'integer)
7696
7697 (defcustom gnus-button-emacs-level 5
7698 "*Integer that says how many emacs-related buttons Gnus will show.
7699 The higher the number, the more buttons will appear and the more false
7700 positives are possible. Note that you can set this variable local to
7701 specific groups. Setting it higher in Emacs or Gnus related groups is
7702 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7703 `gnus-parameters' on how to set variables in specific groups."
7704 :version "22.1"
7705 :group 'gnus-article-buttons
7706 :link '(custom-manual "(gnus)Group Parameters")
7707 :type 'integer)
7708
7709 (defcustom gnus-button-message-level 5
7710 "*Integer that says how many buttons for news or mail messages will appear.
7711 The higher the number, the more buttons will appear and the more false
7712 positives are possible."
7713 ;; mail addresses, MIDs, URLs for news, ...
7714 :version "22.1"
7715 :group 'gnus-article-buttons
7716 :type 'integer)
7717
7718 (defcustom gnus-button-browse-level 5
7719 "*Integer that says how many buttons for browsing will appear.
7720 The higher the number, the more buttons will appear and the more false
7721 positives are possible."
7722 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7723 :version "22.1"
7724 :group 'gnus-article-buttons
7725 :type 'integer)
7726
7727 (defcustom gnus-button-alist
7728 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7729 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7730 ((concat "\\b\\(nntp\\|news\\):\\("
7731 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7732 0 t gnus-button-handle-news 2)
7733 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7734 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7735 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7736 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7737 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7738 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7739 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7740 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7741 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7742 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7743 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7744 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7745 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7746 ;; RFC 2368 (The mailto URL scheme)
7747 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7748 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7749 ("\\bmailto:\\([^ \n\t]+\\)"
7750 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7751 ;; Info Konqueror style <info:/foo/bar baz>.
7752 ;; Must come before " Gnus home-grown style".
7753 ("\\binfo://?\\([^'\">\n\t]+\\)"
7754 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7755 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7756 ("\\binfo://\\([^'\">\n\t ]+\\)"
7757 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7758 ;; Info GNOME style <info:foo#bar_baz>
7759 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7760 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7761 ;; Info KDE style <info:(foo)bar baz>
7762 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7763 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7764 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7765 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7766 ("\\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,]*\\)\\)?"
7767 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7768 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7769 ;; This is custom
7770 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7771 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7772 ;; Emacs help commands
7773 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7774 ;; regexp doesn't match arguments containing ` '.
7775 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7776 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7777 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7778 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7779 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7780 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7781 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7782 ;; The following entries may lead to many false positives so don't enable
7783 ;; them by default (use a high button level).
7784 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7785 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7786 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7787 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7788 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7789 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7790 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7791 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7792 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7793 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7794 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7795 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7796 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7797 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7798 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7799 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7800 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7801 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7802 ;; Unlike the other regexps we really have to require quoting
7803 ;; here to determine where it ends.
7804 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7805 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7806 ("<URL: *\\([^\n<>]*\\)>"
7807 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7808 ;; RFC 2396 (2.4.3., delims) ...
7809 ("\"URL: *\\([^\n\"]*\\)\""
7810 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7811 ;; Raw URLs.
7812 (gnus-button-url-regexp
7813 0 (>= gnus-button-browse-level 0) browse-url 0)
7814 ;; man pages
7815 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7816 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7817 gnus-button-handle-man 1)
7818 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7819 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7820 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7821 gnus-button-handle-man 1)
7822 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7823 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7824 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7825 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7826 ;; Recognizing patches to .el files. This is somewhat obscure,
7827 ;; but considering the percentage of Gnus users who hack Emacs
7828 ;; Lisp files...
7829 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7830 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7831 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7832 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7833 ;; MID or mail: To avoid too many false positives we don't try to catch
7834 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7835 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7836 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7837 ;; so that non-ambiguous entries (see above) match first.
7838 (gnus-button-mid-or-mail-regexp
7839 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7840 "*Alist of regexps matching buttons in article bodies.
7841
7842 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7843 REGEXP: is the string (case insensitive) matching text around the button (can
7844 also be Lisp expression evaluating to a string),
7845 BUTTON: is the number of the regexp grouping actually matching the button,
7846 FORM: is a Lisp expression which must eval to true for the button to
7847 be added,
7848 CALLBACK: is the function to call when the user push this button, and each
7849 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7850
7851 CALLBACK can also be a variable, in that case the value of that
7852 variable it the real callback function."
7853 :group 'gnus-article-buttons
7854 :type '(repeat (list (choice regexp variable sexp)
7855 (integer :tag "Button")
7856 (sexp :tag "Form")
7857 (function :tag "Callback")
7858 (repeat :tag "Par"
7859 :inline t
7860 (integer :tag "Regexp group")))))
7861 (put 'gnus-button-alist 'risky-local-variable t)
7862
7863 (defcustom gnus-header-button-alist
7864 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7865 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7866 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7867 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7868 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7869 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7870 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7871 0 (>= gnus-button-browse-level 0) browse-url 0)
7872 ("^Subject:" gnus-button-url-regexp
7873 0 (>= gnus-button-browse-level 0) browse-url 0)
7874 ("^[^:]+:" gnus-button-url-regexp
7875 0 (>= gnus-button-browse-level 0) browse-url 0)
7876 ("^OpenPGP:.*url=" gnus-button-url-regexp
7877 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7878 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7879 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7880 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7881 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7882 "*Alist of headers and regexps to match buttons in article heads.
7883
7884 This alist is very similar to `gnus-button-alist', except that each
7885 alist has an additional HEADER element first in each entry:
7886
7887 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7888
7889 HEADER is a regexp to match a header. For a fuller explanation, see
7890 `gnus-button-alist'."
7891 :group 'gnus-article-buttons
7892 :group 'gnus-article-headers
7893 :type '(repeat (list (regexp :tag "Header")
7894 (choice regexp variable)
7895 (integer :tag "Button")
7896 (sexp :tag "Form")
7897 (function :tag "Callback")
7898 (repeat :tag "Par"
7899 :inline t
7900 (integer :tag "Regexp group")))))
7901 (put 'gnus-header-button-alist 'risky-local-variable t)
7902
7903 ;;; Commands:
7904
7905 (defun gnus-article-push-button (event)
7906 "Check text under the mouse pointer for a callback function.
7907 If the text under the mouse pointer has a `gnus-callback' property,
7908 call it with the value of the `gnus-data' text property."
7909 (interactive "e")
7910 (set-buffer (window-buffer (posn-window (event-start event))))
7911 (let* ((pos (posn-point (event-start event)))
7912 (data (get-text-property pos 'gnus-data))
7913 (fun (get-text-property pos 'gnus-callback)))
7914 (goto-char pos)
7915 (when fun
7916 (funcall fun data))))
7917
7918 (defun gnus-article-press-button ()
7919 "Check text at point for a callback function.
7920 If the text at point has a `gnus-callback' property,
7921 call it with the value of the `gnus-data' text property."
7922 (interactive)
7923 (let ((data (get-text-property (point) 'gnus-data))
7924 (fun (get-text-property (point) 'gnus-callback)))
7925 (when fun
7926 (funcall fun data))))
7927
7928 (defun gnus-article-highlight (&optional force)
7929 "Highlight current article.
7930 This function calls `gnus-article-highlight-headers',
7931 `gnus-article-highlight-citation',
7932 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7933 do the highlighting. See the documentation for those functions."
7934 (interactive (list 'force))
7935 (gnus-article-highlight-headers)
7936 (gnus-article-highlight-citation force)
7937 (gnus-article-highlight-signature)
7938 (gnus-article-add-buttons)
7939 (gnus-article-add-buttons-to-head))
7940
7941 (defun gnus-article-highlight-some (&optional _force)
7942 "Highlight current article.
7943 This function calls `gnus-article-highlight-headers',
7944 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7945 do the highlighting. See the documentation for those functions."
7946 (interactive (list 'force))
7947 (gnus-article-highlight-headers)
7948 (gnus-article-highlight-signature)
7949 (gnus-article-add-buttons))
7950
7951 (defun gnus-article-highlight-headers ()
7952 "Highlight article headers as specified by `gnus-header-face-alist'."
7953 (interactive)
7954 (gnus-with-article-headers
7955 (let (regexp header-face field-face from hpoints fpoints)
7956 (dolist (entry gnus-header-face-alist)
7957 (goto-char (point-min))
7958 (setq regexp (concat "^\\("
7959 (if (string-equal "" (nth 0 entry))
7960 "[^\t ]"
7961 (nth 0 entry))
7962 "\\)")
7963 header-face (nth 1 entry)
7964 field-face (nth 2 entry))
7965 (while (and (re-search-forward regexp nil t)
7966 (not (eobp)))
7967 (beginning-of-line)
7968 (setq from (point))
7969 (unless (search-forward ":" nil t)
7970 (forward-char 1))
7971 (when (and header-face
7972 (not (memq (point) hpoints)))
7973 (push (point) hpoints)
7974 (gnus-put-text-property from (point) 'face header-face))
7975 (when (and field-face
7976 (not (memq (setq from (point)) fpoints)))
7977 (push from fpoints)
7978 (if (re-search-forward "^[^ \t]" nil t)
7979 (forward-char -2)
7980 (goto-char (point-max)))
7981 (gnus-put-text-property from (point) 'face field-face)))))))
7982
7983 (defun gnus-article-highlight-signature ()
7984 "Highlight the signature in an article.
7985 It does this by highlighting everything after
7986 `gnus-signature-separator' using the face `gnus-signature'."
7987 (interactive)
7988 (gnus-with-article-buffer
7989 (let ((inhibit-point-motion-hooks t))
7990 (save-restriction
7991 (when (and gnus-signature-face
7992 (gnus-article-narrow-to-signature))
7993 (overlay-put (make-overlay (point-min) (point-max) nil t)
7994 'face gnus-signature-face)
7995 (widen)
7996 (gnus-article-search-signature)
7997 (let ((start (match-beginning 0))
7998 (end (set-marker (make-marker) (1+ (match-end 0)))))
7999 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8000 end)))))))
8001
8002 (defun gnus-button-in-region-p (b e prop)
8003 "Say whether PROP exists in the region."
8004 (text-property-not-all b e prop nil))
8005
8006 (defun gnus-article-add-buttons ()
8007 "Find external references in the article and make buttons of them.
8008 \"External references\" are things like Message-IDs and URLs, as
8009 specified by `gnus-button-alist'."
8010 (interactive)
8011 (gnus-with-article-buffer
8012 (let ((inhibit-point-motion-hooks t)
8013 (case-fold-search t)
8014 (alist gnus-button-alist)
8015 beg entry regexp)
8016 ;; We skip the headers.
8017 (article-goto-body)
8018 (setq beg (point))
8019 (while (setq entry (pop alist))
8020 (setq regexp (eval (car entry)))
8021 (goto-char beg)
8022 (while (re-search-forward regexp nil t)
8023 (let ((start (match-beginning (nth 1 entry)))
8024 (end (match-end (nth 1 entry)))
8025 (from (match-beginning 0)))
8026 (when (and (eval (nth 2 entry))
8027 (not (gnus-button-in-region-p
8028 start end 'gnus-callback)))
8029 ;; That optional form returned non-nil, so we add the
8030 ;; button.
8031 (setq from (set-marker (make-marker) from))
8032 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8033 (gnus-article-extend-url-button from start end))
8034 (gnus-article-add-button start end
8035 'gnus-button-push (list from entry))
8036 (gnus-put-text-property
8037 start end
8038 'gnus-string (buffer-substring-no-properties
8039 start end))))))))))
8040
8041 (defun gnus-article-extend-url-button (beg start end)
8042 "Extend url button if url is folded into two or more lines.
8043 Return non-nil if button is extended. BEG is a marker that points to
8044 the beginning position of a text containing url. START and END are
8045 the endpoints of a url button before it is extended. The concatenated
8046 url is put as the `gnus-button-url' overlay property on the button."
8047 (let ((opoint (point))
8048 (points (list start end))
8049 url delim regexp)
8050 (prog1
8051 (when (and (progn
8052 (goto-char end)
8053 (not (looking-at "[\t ]*[\">]")))
8054 (progn
8055 (goto-char start)
8056 (string-match
8057 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8058 (buffer-substring (point-at-bol) start)))
8059 (progn
8060 (setq url (list (buffer-substring start end))
8061 delim (if (match-beginning 1) ">" "\""))
8062 (beginning-of-line)
8063 (setq regexp (concat
8064 (when (and (looking-at
8065 message-cite-prefix-regexp)
8066 (< (match-end 0) start))
8067 (regexp-quote (match-string 0)))
8068 "\
8069 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8070 delim "\\)"))
8071 (while (progn
8072 (forward-line 1)
8073 (and (looking-at regexp)
8074 (prog1
8075 (match-beginning 1)
8076 (push (or (match-string 2)
8077 (match-string 1))
8078 url)
8079 (push (setq end (or (match-end 2)
8080 (match-end 1)))
8081 points)
8082 (push (or (match-beginning 2)
8083 (match-beginning 1))
8084 points)))))
8085 (match-beginning 2)))
8086 (let (gnus-article-mouse-face widget-mouse-face)
8087 (while points
8088 (gnus-article-add-button (pop points) (pop points)
8089 'gnus-button-push
8090 (list beg (assq 'gnus-button-url-regexp
8091 gnus-button-alist)))))
8092 (let ((overlay (make-overlay start end)))
8093 (overlay-put overlay 'evaporate t)
8094 (overlay-put overlay 'gnus-button-url
8095 (list (mapconcat 'identity (nreverse url) "")))
8096 (when gnus-article-mouse-face
8097 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8098 t)
8099 (goto-char opoint))))
8100
8101 ;; Add buttons to the head of an article.
8102 (defun gnus-article-add-buttons-to-head ()
8103 "Add buttons to the head of the article."
8104 (interactive)
8105 (gnus-with-article-headers
8106 (let (beg end)
8107 (dolist (entry gnus-header-button-alist)
8108 ;; Each alist entry.
8109 (goto-char (point-min))
8110 (while (re-search-forward (car entry) nil t)
8111 ;; Each header matching the entry.
8112 (setq beg (match-beginning 0))
8113 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8114 (match-beginning 0))
8115 (point-max)))
8116 (goto-char beg)
8117 (while (re-search-forward (eval (nth 1 entry)) end t)
8118 ;; Each match within a header.
8119 (let* ((entry (cdr entry))
8120 (start (match-beginning (nth 1 entry)))
8121 (end (match-end (nth 1 entry)))
8122 (form (nth 2 entry)))
8123 (goto-char (match-end 0))
8124 (when (eval form)
8125 (gnus-article-add-button
8126 start end (nth 3 entry)
8127 (buffer-substring (match-beginning (nth 4 entry))
8128 (match-end (nth 4 entry)))))))
8129 (goto-char end))))))
8130
8131 ;;; External functions:
8132
8133 (defun gnus-article-add-button (from to fun &optional data text)
8134 "Create a button between FROM and TO with callback FUN and data DATA."
8135 (when gnus-article-button-face
8136 (overlay-put (make-overlay from to nil t)
8137 'face gnus-article-button-face))
8138 (gnus-add-text-properties
8139 from to
8140 (nconc (and gnus-article-mouse-face
8141 (list 'mouse-face gnus-article-mouse-face))
8142 (list 'gnus-callback fun)
8143 (and data (list 'gnus-data data))))
8144 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8145 :help-echo (or text "Follow the link")
8146 :keymap gnus-url-button-map))
8147
8148 (defun gnus-article-copy-string ()
8149 "Copy the string in the button to the kill ring."
8150 (interactive)
8151 (gnus-article-check-buffer)
8152 (let ((data (get-text-property (point) 'gnus-string)))
8153 (when data
8154 (with-temp-buffer
8155 (insert data)
8156 (copy-region-as-kill (point-min) (point-max))
8157 (message "Copied %s" data)))))
8158
8159 ;;; Internal functions:
8160
8161 (defun gnus-article-set-globals ()
8162 (with-current-buffer gnus-summary-buffer
8163 (gnus-set-global-variables)))
8164
8165 (defun gnus-signature-toggle (end)
8166 (gnus-with-article-buffer
8167 (let ((inhibit-point-motion-hooks t))
8168 (if (text-property-any end (point-max) 'article-type 'signature)
8169 (progn
8170 (gnus-delete-wash-type 'signature)
8171 (gnus-remove-text-properties-when
8172 'article-type 'signature end (point-max)
8173 (cons 'article-type (cons 'signature
8174 gnus-hidden-properties))))
8175 (gnus-add-wash-type 'signature)
8176 (gnus-add-text-properties-when
8177 'article-type nil end (point-max)
8178 (cons 'article-type (cons 'signature
8179 gnus-hidden-properties)))))
8180 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8181 (gnus-set-mode-line 'article))))
8182
8183 (defun gnus-button-push (marker-and-entry)
8184 ;; Push button starting at MARKER.
8185 (save-excursion
8186 (let* ((marker (car marker-and-entry))
8187 (entry (cadr marker-and-entry))
8188 (regexp (car entry))
8189 (inhibit-point-motion-hooks t))
8190 (goto-char marker)
8191 ;; This is obviously true, or something bad is happening :)
8192 ;; But we need it to have the match-data
8193 (when (looking-at (or (if (symbolp regexp)
8194 (symbol-value regexp)
8195 regexp)))
8196 (let ((fun (nth 3 entry))
8197 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8198 (get-char-property marker 'gnus-button-url))
8199 (mapcar (lambda (group)
8200 (let ((string (match-string group)))
8201 (set-text-properties
8202 0 (length string) nil string)
8203 string))
8204 (nthcdr 4 entry)))))
8205
8206 (cond
8207 ((fboundp fun)
8208 (apply fun args))
8209 ((and (boundp fun)
8210 (fboundp (symbol-value fun)))
8211 (apply (symbol-value fun) args))
8212 (t
8213 (gnus-message 1 "You must define `%S' to use this button"
8214 (cons fun args)))))))))
8215
8216 (defun gnus-parse-news-url (url)
8217 (let (scheme server port group message-id articles)
8218 (with-temp-buffer
8219 (insert url)
8220 (goto-char (point-min))
8221 (when (looking-at "\\([A-Za-z]+\\):")
8222 (setq scheme (match-string 1))
8223 (goto-char (match-end 0)))
8224 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8225 (setq server (match-string 1))
8226 (setq port (if (stringp (match-string 3))
8227 (string-to-number (match-string 3))
8228 (match-string 3)))
8229 (goto-char (match-end 0)))
8230
8231 (cond
8232 ((looking-at "\\(.*@.*\\)")
8233 (setq message-id (match-string 1)))
8234 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8235 (setq group (match-string 1)
8236 articles (split-string (match-string 2) "-")))
8237 ((looking-at "\\([^/]+\\)/?")
8238 (setq group (match-string 1)))
8239 (t
8240 (error "Unknown news URL syntax"))))
8241 (list scheme server port group message-id articles)))
8242
8243 (defvar nntp-port-number)
8244
8245 (defun gnus-button-handle-news (url)
8246 "Fetch a news URL."
8247 (destructuring-bind (_scheme server port group message-id _articles)
8248 (gnus-parse-news-url url)
8249 (cond
8250 (message-id
8251 (with-current-buffer gnus-summary-buffer
8252 (if server
8253 (let ((gnus-refer-article-method
8254 (nconc (list (list 'nntp server))
8255 gnus-refer-article-method))
8256 (nntp-port-number (or port "nntp")))
8257 (gnus-message 7 "Fetching %s with %s"
8258 message-id gnus-refer-article-method)
8259 (gnus-summary-refer-article message-id))
8260 (gnus-summary-refer-article message-id))))
8261 (group
8262 (gnus-button-fetch-group url)))))
8263
8264 (defun gnus-button-patch (library line)
8265 "Visit an Emacs Lisp library LIBRARY on line LINE."
8266 (interactive)
8267 (let ((file (locate-library (file-name-nondirectory library))))
8268 (unless file
8269 (error "Couldn't find library %s" library))
8270 (find-file file)
8271 (goto-char (point-min))
8272 (forward-line (1- (string-to-number line)))))
8273
8274 (defun gnus-button-handle-man (url)
8275 "Fetch a man page."
8276 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8277 (when (eq gnus-button-man-handler 'woman)
8278 (setq url (replace-regexp-in-string url "([1-9][X1a-z]*).*\\'" "")))
8279 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8280 (funcall gnus-button-man-handler url))
8281
8282 (defun gnus-button-handle-info-url (url)
8283 "Fetch an info URL."
8284 (setq url (mm-subst-char-in-string ?+ ?\ url))
8285 (cond
8286 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8287 (gnus-info-find-node
8288 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8289 "Gnus")
8290 ")" (gnus-url-unhex-string (match-string 2 url)))))
8291 ((string-match "([^)\"]+)[^\"]+" url)
8292 (setq url
8293 (replace-regexp-in-string
8294 (replace-regexp-in-string url "[\n\t ]+" " ") "\"" ""))
8295 (gnus-info-find-node url))
8296 (t (error "Can't parse %s" url))))
8297
8298 (defun gnus-button-handle-info-url-gnome (url)
8299 "Fetch GNOME style info URL."
8300 (setq url (mm-subst-char-in-string ?_ ?\ url))
8301 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8302 (gnus-info-find-node
8303 (concat "("
8304 (gnus-url-unhex-string
8305 (match-string 1 url))
8306 ")"
8307 (or (gnus-url-unhex-string
8308 (match-string 2 url))
8309 "Top")))
8310 (error "Can't parse %s" url)))
8311
8312 (defun gnus-button-handle-info-url-kde (url)
8313 "Fetch KDE style info URL."
8314 (gnus-info-find-node (gnus-url-unhex-string url)))
8315
8316 ;; (info) will autoload info.el
8317 (declare-function Info-menu "info" (menu-item &optional fork))
8318 (declare-function Info-index-next "info" (num))
8319
8320 (defun gnus-button-handle-info-keystrokes (url)
8321 "Call `info' when pushing the corresponding URL button."
8322 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8323 (let (node indx comma)
8324 (if (string-match
8325 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8326 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8327 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8328 "\\(?:[ \t\n,]*\\)\\)?")
8329 url)
8330 (setq node (match-string 2 url)
8331 indx (match-string 3 url))
8332 (error "Can't parse %s" url))
8333 (info)
8334 (Info-directory)
8335 (Info-menu node)
8336 (when (> (length indx) 0)
8337 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8338 "\\([ \t\n,]*\\)")
8339 indx)
8340 (setq comma (match-string 2 indx))
8341 (setq indx (match-string 1 indx))
8342 (Info-index indx)
8343 (when comma
8344 (dotimes (i (with-temp-buffer
8345 (insert comma)
8346 ;; Note: the XEmacs version of `how-many' takes
8347 ;; no optional argument.
8348 (goto-char (point-min))
8349 (how-many ",")))
8350 (Info-index-next 1)))
8351 nil)))
8352
8353 (autoload 'pgg-snarf-keys-region "pgg")
8354 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8355 (declare-function pgg-display-output-buffer "pgg" (start end status))
8356
8357 (defun gnus-button-openpgp (url)
8358 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8359 (with-temp-buffer
8360 (mm-url-insert-file-contents-external url)
8361 (pgg-snarf-keys-region (point-min) (point-max))
8362 (pgg-display-output-buffer nil nil nil)))
8363
8364 (defun gnus-button-message-id (message-id)
8365 "Fetch MESSAGE-ID."
8366 (with-current-buffer gnus-summary-buffer
8367 (gnus-summary-refer-article message-id)))
8368
8369 (defun gnus-button-fetch-group (address &rest _ignore)
8370 "Fetch GROUP specified by ADDRESS."
8371 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8372 address)
8373 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8374 ;; for nntp:// and news://
8375 (setq address (match-string 3 address)))
8376 (if (not (string-match "[:/]" address))
8377 ;; This is just a simple group url.
8378 (gnus-group-read-ephemeral-group address gnus-select-method)
8379 (if (not
8380 (string-match
8381 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8382 address))
8383 (error "Can't parse %s" address)
8384 (gnus-group-read-ephemeral-group
8385 (match-string 4 address)
8386 `(nntp ,(match-string 1 address)
8387 (nntp-address ,(match-string 1 address))
8388 (nntp-port-number ,(if (match-end 3)
8389 (match-string 3 address)
8390 "nntp")))
8391 nil nil nil
8392 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8393
8394 (defun gnus-url-parse-query-string (query &optional downcase)
8395 (let (retval pairs cur key val)
8396 (setq pairs (split-string query "&"))
8397 (while pairs
8398 (setq cur (car pairs)
8399 pairs (cdr pairs))
8400 (if (not (string-match "=" cur))
8401 nil ; Grace
8402 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8403 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8404 (if downcase
8405 (setq key (downcase key)))
8406 (setq cur (assoc key retval))
8407 (if cur
8408 (setcdr cur (cons val (cdr cur)))
8409 (setq retval (cons (list key val) retval)))))
8410 retval))
8411
8412 (defun gnus-url-mailto (url)
8413 ;; Send mail to someone
8414 (setq url (replace-regexp-in-string "\n" " " url))
8415 (when (string-match "mailto:/*\\(.*\\)" url)
8416 (setq url (substring url (match-beginning 1) nil)))
8417 (let* ((args (gnus-url-parse-query-string
8418 (if (string-match "^\\?" url)
8419 (substring url 1)
8420 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8421 (concat "to=" (match-string 1 url) "&"
8422 (match-string 2 url))
8423 (concat "to=" url)))))
8424 (subject (cdr-safe (assoc "subject" args)))
8425 func)
8426 (gnus-msg-mail)
8427 (while args
8428 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8429 (if (fboundp func)
8430 (funcall func)
8431 (message-position-on-field (caar args)))
8432 (insert (replace-regexp-in-string
8433 (mapconcat 'identity (reverse (cdar args)) ", ")
8434 "\r\n" "\n" t))
8435 (setq args (cdr args)))
8436 (if subject
8437 (message-goto-body)
8438 (message-goto-subject))))
8439
8440 (defun gnus-button-embedded-url (address)
8441 "Activate ADDRESS with `browse-url'."
8442 (browse-url (gnus-strip-whitespace address)))
8443
8444 ;;; Next/prev buttons in the article buffer.
8445
8446 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8447 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8448
8449 (defvar gnus-prev-page-map
8450 (let ((map (make-sparse-keymap)))
8451 (define-key map [mouse-2] 'gnus-button-prev-page)
8452 (define-key map "\r" 'gnus-button-prev-page)
8453 map))
8454
8455 (defvar gnus-next-page-map
8456 (let ((map (make-sparse-keymap)))
8457 (define-key map [mouse-2] 'gnus-button-next-page)
8458 (define-key map "\r" 'gnus-button-next-page)
8459 map))
8460
8461 (defun gnus-insert-prev-page-button ()
8462 (let ((b (point)) e
8463 (inhibit-read-only t))
8464 (gnus-eval-format
8465 gnus-prev-page-line-format nil
8466 `(keymap ,gnus-prev-page-map
8467 gnus-prev t
8468 gnus-callback gnus-article-button-prev-page
8469 article-type annotation))
8470 (setq e (if (bolp)
8471 ;; Exclude a newline.
8472 (1- (point))
8473 (point)))
8474 (when gnus-article-button-face
8475 (overlay-put (make-overlay b e nil t)
8476 'face gnus-article-button-face))
8477 (widget-convert-button
8478 'link b e
8479 :action 'gnus-button-prev-page
8480 :button-keymap gnus-prev-page-map)))
8481
8482 (defun gnus-button-next-page (&optional _args _more-args)
8483 "Go to the next page."
8484 (interactive)
8485 (let ((win (selected-window)))
8486 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8487 (gnus-article-next-page)
8488 (select-window win)))
8489
8490 (defun gnus-button-prev-page (&optional _args _more-args)
8491 "Go to the prev page."
8492 (interactive)
8493 (let ((win (selected-window)))
8494 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8495 (gnus-article-prev-page)
8496 (select-window win)))
8497
8498 (defun gnus-insert-next-page-button ()
8499 (let ((b (point)) e
8500 (inhibit-read-only t))
8501 (gnus-eval-format gnus-next-page-line-format nil
8502 `(keymap ,gnus-next-page-map
8503 gnus-next t
8504 gnus-callback gnus-article-button-next-page
8505 article-type annotation))
8506 (setq e (if (bolp)
8507 ;; Exclude a newline.
8508 (1- (point))
8509 (point)))
8510 (when gnus-article-button-face
8511 (overlay-put (make-overlay b e nil t)
8512 'face gnus-article-button-face))
8513 (widget-convert-button
8514 'link b e
8515 :action 'gnus-button-next-page
8516 :button-keymap gnus-next-page-map)))
8517
8518 (defun gnus-article-button-next-page (_arg)
8519 "Go to the next page."
8520 (interactive "P")
8521 (let ((win (selected-window)))
8522 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8523 (gnus-article-next-page)
8524 (select-window win)))
8525
8526 (defun gnus-article-button-prev-page (_arg)
8527 "Go to the prev page."
8528 (interactive "P")
8529 (let ((win (selected-window)))
8530 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8531 (gnus-article-prev-page)
8532 (select-window win)))
8533
8534 (defvar gnus-decode-header-methods
8535 '(mail-decode-encoded-word-region)
8536 "List of methods used to decode headers.
8537
8538 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8539 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8540 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8541 whose names match REGEXP.
8542
8543 For example:
8544 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8545 mail-decode-encoded-word-region
8546 (\"chinese\" . rfc1843-decode-region))
8547 ")
8548
8549 (defvar gnus-decode-header-methods-cache nil)
8550
8551 (defun gnus-multi-decode-header (start end)
8552 "Apply the functions from `gnus-encoded-word-methods' that match."
8553 (unless (and gnus-decode-header-methods-cache
8554 (eq gnus-newsgroup-name
8555 (car gnus-decode-header-methods-cache)))
8556 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8557 (dolist (x gnus-decode-header-methods)
8558 (if (symbolp x)
8559 (nconc gnus-decode-header-methods-cache (list x))
8560 (if (and gnus-newsgroup-name
8561 (string-match (car x) gnus-newsgroup-name))
8562 (nconc gnus-decode-header-methods-cache
8563 (list (cdr x)))))))
8564 (let ((xlist gnus-decode-header-methods-cache))
8565 (pop xlist)
8566 (save-restriction
8567 (narrow-to-region start end)
8568 (while xlist
8569 (funcall (pop xlist) (point-min) (point-max))))))
8570
8571 ;;;
8572 ;;; Treatment top-level handling.
8573 ;;;
8574
8575 (defvar gnus-inhibit-article-treatments nil)
8576
8577 ;; Dynamic variables.
8578 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8579 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8580 (defvar gnus-treat-type)
8581 (defvar gnus-treat-condition)
8582 (defvar gnus-treat-length)
8583
8584 (defun gnus-treat-article (condition
8585 &optional part-num total type)
8586 (let ((gnus-treat-condition condition)
8587 (part-number part-num)
8588 (total-parts total)
8589 (gnus-treat-type type)
8590 (gnus-treat-length (- (point-max) (point-min)))
8591 (alist gnus-treatment-function-alist)
8592 (article-goto-body-goes-to-point-min-p t)
8593 (treated-type
8594 (or (not type)
8595 (catch 'found
8596 (let ((list gnus-article-treat-types))
8597 (while list
8598 (when (string-match (pop list) type)
8599 (throw 'found t)))))))
8600 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8601 val)
8602 (gnus-run-hooks 'gnus-part-display-hook)
8603 (dolist (elem alist)
8604 (setq val
8605 (save-excursion
8606 (when (gnus-buffer-live-p gnus-summary-buffer)
8607 (set-buffer gnus-summary-buffer))
8608 (symbol-value (car elem))))
8609 (when (and (or (consp val)
8610 treated-type)
8611 (or (not gnus-inhibit-article-treatments)
8612 (eq gnus-treat-condition 'head))
8613 (gnus-treat-predicate val)
8614 (or (not (get (car elem) 'highlight))
8615 highlightp))
8616 (save-restriction
8617 (funcall (cadr elem)))))))
8618
8619 (defun gnus-treat-predicate (val)
8620 (cond
8621 ((null val)
8622 nil)
8623 (gnus-treat-condition
8624 (eq gnus-treat-condition val))
8625 ((and (listp val)
8626 (stringp (car val)))
8627 (apply 'gnus-or (mapcar `(lambda (s)
8628 (string-match s ,(or gnus-newsgroup-name "")))
8629 val)))
8630 ((listp val)
8631 (let ((pred (pop val)))
8632 (cond
8633 ((eq pred 'or)
8634 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8635 ((eq pred 'and)
8636 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8637 ((eq pred 'not)
8638 (not (gnus-treat-predicate (car val))))
8639 ((eq pred 'typep)
8640 (equal (car val) gnus-treat-type))
8641 ((functionp pred)
8642 (funcall pred))
8643 (t
8644 (error "%S is not a valid predicate" pred)))))
8645 ((eq val t)
8646 t)
8647 ((eq val 'head)
8648 nil)
8649 ((eq val 'first)
8650 (eq part-number 1))
8651 ((eq val 'last)
8652 (eq part-number total-parts))
8653 ((numberp val)
8654 (< gnus-treat-length val))
8655 (t
8656 (error "%S is not a valid value" val))))
8657
8658 (defun gnus-article-encrypt-body (protocol &optional n)
8659 "Encrypt the article body."
8660 (interactive
8661 (list
8662 (or gnus-article-encrypt-protocol
8663 (gnus-completing-read "Encrypt protocol"
8664 (mapcar 'car gnus-article-encrypt-protocol-alist)
8665 t))
8666 current-prefix-arg))
8667 ;; User might hit `K E' instead of `K e', so prompt once.
8668 (when (and gnus-article-encrypt-protocol
8669 gnus-novice-user)
8670 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8671 (error "Encrypt aborted")))
8672 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8673 (unless func
8674 (error "Can't find the encrypt protocol %s" protocol))
8675 (if (member gnus-newsgroup-name '("nndraft:delayed"
8676 "nndraft:drafts"
8677 "nndraft:queue"))
8678 (error "Can't encrypt the article in group %s"
8679 gnus-newsgroup-name))
8680 (gnus-summary-iterate n
8681 (with-current-buffer gnus-summary-buffer
8682 (let ((mail-parse-charset gnus-newsgroup-charset)
8683 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8684 (summary-buffer gnus-summary-buffer)
8685 references point)
8686 (gnus-set-global-variables)
8687 (when (gnus-group-read-only-p)
8688 (error "The current newsgroup does not support article encrypt"))
8689 (gnus-summary-show-article t)
8690 (setq references
8691 (or (mail-header-references gnus-current-headers) ""))
8692 (set-buffer gnus-article-buffer)
8693 (let* ((inhibit-read-only t)
8694 (headers
8695 (mapcar (lambda (field)
8696 (and (save-restriction
8697 (message-narrow-to-head)
8698 (goto-char (point-min))
8699 (search-forward field nil t))
8700 (prog2
8701 (message-narrow-to-field)
8702 (buffer-string)
8703 (delete-region (point-min) (point-max))
8704 (widen))))
8705 '("Content-Type:" "Content-Transfer-Encoding:"
8706 "Content-Disposition:"))))
8707 (message-narrow-to-head)
8708 (message-remove-header "MIME-Version")
8709 (goto-char (point-max))
8710 (setq point (point))
8711 (insert (apply 'concat headers))
8712 (widen)
8713 (narrow-to-region point (point-max))
8714 (let ((message-options message-options))
8715 (message-options-set 'message-sender user-mail-address)
8716 (message-options-set 'message-recipients user-mail-address)
8717 (message-options-set 'message-sign-encrypt 'not)
8718 (funcall func))
8719 (goto-char (point-min))
8720 (insert "MIME-Version: 1.0\n")
8721 (widen)
8722 (gnus-summary-edit-article-done
8723 references nil summary-buffer t))
8724 (when gnus-keep-backlog
8725 (gnus-backlog-remove-article
8726 (car gnus-article-current) (cdr gnus-article-current)))
8727 (gnus-flush-original-article-buffer)
8728 (when gnus-use-cache
8729 (gnus-cache-update-article
8730 (car gnus-article-current) (cdr gnus-article-current))))))))
8731
8732 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8733 "The following specs can be used:
8734 %t The security MIME type
8735 %i Additional info
8736 %d Details
8737 %D Details if button is pressed")
8738
8739 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8740 "The following specs can be used:
8741 %t The security MIME type
8742 %i Additional info
8743 %d Details
8744 %D Details if button is pressed")
8745
8746 (defvar gnus-mime-security-button-line-format-alist
8747 '((?t gnus-tmp-type ?s)
8748 (?i gnus-tmp-info ?s)
8749 (?d gnus-tmp-details ?s)
8750 (?D gnus-tmp-pressed-details ?s)))
8751
8752 (defvar gnus-mime-security-button-commands
8753 '((gnus-article-press-button "\r" "Show Detail")
8754 (undefined "v")
8755 (undefined "t")
8756 (undefined "C")
8757 (gnus-mime-security-save-part "o" "Save...")
8758 (undefined "\C-o")
8759 (undefined "r")
8760 (undefined "d")
8761 (undefined "c")
8762 (undefined "i")
8763 (undefined "E")
8764 (undefined "e")
8765 (undefined "p")
8766 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8767 (undefined ".")))
8768
8769 (defvar gnus-mime-security-button-map
8770 (let ((map (make-sparse-keymap)))
8771 (define-key map [mouse-2] 'gnus-article-push-button)
8772 (define-key map [down-mouse-3] 'gnus-mime-security-button-menu)
8773 (dolist (c gnus-mime-security-button-commands)
8774 (define-key map (cadr c) (car c)))
8775 map))
8776
8777 (easy-menu-define
8778 gnus-mime-security-button-menu gnus-mime-security-button-map
8779 "Security button menu."
8780 `("Security Part"
8781 ,@(delq nil
8782 (mapcar (lambda (c)
8783 (unless (eq (car c) 'undefined)
8784 (vector (caddr c) (car c) :active t)))
8785 gnus-mime-security-button-commands))))
8786
8787 (defun gnus-mime-security-button-menu (event prefix)
8788 "Construct a context-sensitive menu of security commands."
8789 (interactive "e\nP")
8790 (save-window-excursion
8791 (let ((pos (event-start event)))
8792 (select-window (posn-window pos))
8793 (goto-char (posn-point pos))
8794 (gnus-article-check-buffer)
8795 (popup-menu gnus-mime-security-button-menu nil prefix))))
8796
8797 (defvar gnus-mime-security-details-buffer nil)
8798
8799 (defvar gnus-mime-security-button-pressed nil)
8800
8801 (defvar gnus-mime-security-show-details-inline t
8802 "If non-nil, show details in the article buffer.")
8803
8804 (defun gnus-mime-security-verify-or-decrypt (handle)
8805 (mm-remove-parts (cdr handle))
8806 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8807 point (inhibit-read-only t))
8808 (if region
8809 (goto-char (car region)))
8810 (setq point (point))
8811 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8812 (let* ((mm-verify-option 'known)
8813 (mm-decrypt-option 'known)
8814 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8815 (unless (eq nparts (cdr handle))
8816 (mm-destroy-parts (cdr handle))
8817 (setcdr handle nparts))))
8818 (gnus-mime-display-security handle)
8819 (when region
8820 (delete-region (point) (cdr region))
8821 (set-marker (car region) nil)
8822 (set-marker (cdr region) nil))
8823 (goto-char point)))
8824
8825 (defun gnus-mime-security-show-details (handle)
8826 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8827 (if (not details)
8828 (gnus-message 5 "No details.")
8829 (if gnus-mime-security-show-details-inline
8830 (let ((gnus-mime-security-button-pressed
8831 (not (get-text-property (point) 'gnus-mime-details)))
8832 (gnus-mime-security-button-line-format
8833 (get-text-property (point) 'gnus-line-format))
8834 (inhibit-read-only t))
8835 (forward-char -1)
8836 (while (eq (get-text-property (point) 'gnus-line-format)
8837 gnus-mime-security-button-line-format)
8838 (forward-char -1))
8839 (forward-char)
8840 (save-restriction
8841 (narrow-to-region (point) (point))
8842 (gnus-insert-mime-security-button handle))
8843 (delete-region (point)
8844 (or (text-property-not-all
8845 (point) (point-max)
8846 'gnus-line-format
8847 gnus-mime-security-button-line-format)
8848 (point-max))))
8849 ;; Not inlined.
8850 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8851 (with-current-buffer gnus-mime-security-details-buffer
8852 (erase-buffer)
8853 t)
8854 (setq gnus-mime-security-details-buffer
8855 (gnus-get-buffer-create "*MIME Security Details*")))
8856 (with-current-buffer gnus-mime-security-details-buffer
8857 (insert details)
8858 (goto-char (point-min)))
8859 (pop-to-buffer gnus-mime-security-details-buffer)))))
8860
8861 (defun gnus-mime-security-press-button (handle)
8862 (save-excursion
8863 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8864 (gnus-mime-security-show-details handle)
8865 (gnus-mime-security-verify-or-decrypt handle))))
8866
8867 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8868 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8869 (gnus-tmp-type
8870 (concat
8871 (or (nth 2 (assoc protocol mm-verify-function-alist))
8872 (nth 2 (assoc protocol mm-decrypt-function-alist))
8873 "Unknown")
8874 (if (equal (car handle) "multipart/signed")
8875 " Signed" " Encrypted")
8876 " Part"))
8877 (gnus-tmp-info
8878 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8879 "Undecided"))
8880 (gnus-tmp-details
8881 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8882 gnus-tmp-pressed-details
8883 b e)
8884 (setq gnus-tmp-details
8885 (if gnus-tmp-details
8886 (concat "\n" gnus-tmp-details)
8887 ""))
8888 (setq gnus-tmp-pressed-details
8889 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8890 (unless (bolp)
8891 (insert "\n"))
8892 (setq b (point))
8893 (gnus-eval-format
8894 gnus-mime-security-button-line-format
8895 gnus-mime-security-button-line-format-alist
8896 `(keymap ,gnus-mime-security-button-map
8897 gnus-callback gnus-mime-security-press-button
8898 gnus-line-format ,gnus-mime-security-button-line-format
8899 gnus-mime-details ,gnus-mime-security-button-pressed
8900 article-type annotation
8901 gnus-data ,handle))
8902 (setq e (if (bolp)
8903 ;; Exclude a newline.
8904 (1- (point))
8905 (point)))
8906 (when gnus-article-button-face
8907 (overlay-put (make-overlay b e nil t)
8908 'face gnus-article-button-face))
8909 (widget-convert-button
8910 'link b e
8911 :mime-handle handle
8912 :action 'gnus-widget-press-button
8913 :button-keymap gnus-mime-security-button-map
8914 :help-echo
8915 (lambda (_widget)
8916 (format
8917 "%S: show detail; %S: more options"
8918 'mouse-2
8919 'down-mouse-3)))))
8920
8921 (defun gnus-mime-display-security (handle)
8922 (save-restriction
8923 (narrow-to-region (point) (point))
8924 (unless (gnus-unbuttonized-mime-type-p (car handle))
8925 (gnus-insert-mime-security-button handle))
8926 (gnus-mime-display-part (cadr handle))
8927 (unless (bolp)
8928 (insert "\n"))
8929 (unless (gnus-unbuttonized-mime-type-p (car handle))
8930 (let ((gnus-mime-security-button-line-format
8931 gnus-mime-security-button-end-line-format))
8932 (gnus-insert-mime-security-button handle)))
8933 (mm-set-handle-multipart-parameter
8934 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8935 (goto-char (point-max))))
8936
8937 (defun gnus-mime-security-run-function (function)
8938 "Run FUNCTION with the security part under point."
8939 (gnus-article-check-buffer)
8940 (let ((data (get-text-property (point) 'gnus-data))
8941 buffer handle)
8942 (when (and (stringp (car-safe data))
8943 (setq buffer (mm-handle-multipart-original-buffer data))
8944 (setq handle (cadr data)))
8945 (if (bufferp (mm-handle-buffer handle))
8946 (progn
8947 (setq handle (cons buffer (copy-sequence (cdr handle))))
8948 (mm-handle-set-undisplayer handle nil))
8949 (setq handle (mm-make-handle
8950 buffer
8951 (mm-handle-multipart-ctl-parameter handle 'protocol)
8952 nil nil nil nil nil nil)))
8953 (funcall function handle))))
8954
8955 (defun gnus-mime-security-save-part ()
8956 "Save the security part under point."
8957 (interactive)
8958 (gnus-mime-security-run-function 'mm-save-part))
8959
8960 (defun gnus-mime-security-pipe-part ()
8961 "Pipe the security part under point to a process."
8962 (interactive)
8963 (gnus-mime-security-run-function 'mm-pipe-part))
8964
8965 (provide 'gnus-art)
8966
8967 (run-hooks 'gnus-art-load-hook)
8968
8969 ;;; gnus-art.el ends here