]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
Escape ` and ' in doc
[gnu-emacs] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2015 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 'sexp
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 (featurep 'xemacs)
270 (if (or (gnus-image-type-available-p 'xface)
271 (gnus-image-type-available-p 'pbm))
272 'gnus-display-x-face-in-from
273 "{ echo \
274 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
275 ; uncompface; } | icontopbm | ee -")
276 (if (gnus-image-type-available-p 'pbm)
277 'gnus-display-x-face-in-from
278 "{ echo \
279 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
280 ; uncompface; } | icontopbm | display -"))
281 "*String or function to be executed to display an X-Face header.
282 If it is a string, the command will be executed in a sub-shell
283 asynchronously. The compressed face will be piped to this command."
284 :type `(choice string
285 (function-item gnus-display-x-face-in-from)
286 function)
287 :version "21.1"
288 :group 'gnus-picon
289 :group 'gnus-article-washing)
290
291 (defcustom gnus-article-x-face-too-ugly nil
292 "Regexp matching posters whose face shouldn't be shown automatically."
293 :type '(choice regexp (const nil))
294 :group 'gnus-article-washing)
295
296 (defcustom gnus-article-banner-alist nil
297 "Banner alist for stripping.
298 For example,
299 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
300 :version "21.1"
301 :type '(repeat (cons symbol regexp))
302 :group 'gnus-article-washing)
303
304 (gnus-define-group-parameter
305 banner
306 :variable-document
307 "Alist of regexps (to match group names) and banner."
308 :variable-group gnus-article-washing
309 :parameter-type
310 '(choice :tag "Banner"
311 :value nil
312 (const :tag "Remove signature" signature)
313 (symbol :tag "Item in `gnus-article-banner-alist'" none)
314 regexp
315 (const :tag "None" nil))
316 :parameter-document
317 "If non-nil, specify how to remove `banners' from articles.
318
319 Symbol `signature' means to remove signatures delimited by
320 `gnus-signature-separator'. Any other symbol is used to look up a
321 regular expression to match the banner in `gnus-article-banner-alist'.
322 A string is used as a regular expression to match the banner
323 directly.")
324
325 (defcustom gnus-article-address-banner-alist nil
326 "Alist of mail addresses and banners.
327 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
328 to match a mail address in the From: header, BANNER is one of a symbol
329 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
330 If ADDRESS matches author's mail address, it will remove things like
331 advertisements. For example:
332
333 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
334 "
335 :type '(repeat
336 (cons
337 (regexp :tag "Address")
338 (choice :tag "Banner" :value nil
339 (const :tag "Remove signature" signature)
340 (symbol :tag "Item in `gnus-article-banner-alist'" none)
341 regexp
342 (const :tag "None" nil))))
343 :version "22.1"
344 :group 'gnus-article-washing)
345
346 (defmacro gnus-emphasis-custom-with-format (&rest body)
347 `(let ((format "\
348 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
349 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
350 ,@body))
351
352 (defun gnus-emphasis-custom-value-to-external (value)
353 (gnus-emphasis-custom-with-format
354 (if (consp (car value))
355 (list (format format (car (car value)) (cdr (car value)))
356 2
357 (if (nth 1 value) 2 3)
358 (nth 2 value))
359 value)))
360
361 (defun gnus-emphasis-custom-value-to-internal (value)
362 (gnus-emphasis-custom-with-format
363 (let ((regexp (concat "\\`"
364 (format (regexp-quote format)
365 "\\([^()]+\\)" "\\([^()]+\\)")
366 "\\'"))
367 pattern)
368 (if (string-match regexp (setq pattern (car value)))
369 (list (cons (match-string 1 pattern) (match-string 2 pattern))
370 (= (nth 2 value) 2)
371 (nth 3 value))
372 value))))
373
374 (defcustom gnus-emphasis-alist
375 (let ((types
376 '(("\\*" "\\*" bold nil 2)
377 ("_" "_" underline)
378 ("/" "/" italic)
379 ("_/" "/_" underline-italic)
380 ("_\\*" "\\*_" underline-bold)
381 ("\\*/" "/\\*" bold-italic)
382 ("_\\*/" "/\\*_" underline-bold-italic))))
383 (nconc
384 (gnus-emphasis-custom-with-format
385 (mapcar (lambda (spec)
386 (list (format format (car spec) (cadr spec))
387 (or (nth 3 spec) 2)
388 (or (nth 4 spec) 3)
389 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
390 types))
391 '(;; I've never seen anyone use this strikethru convention whereas I've
392 ;; several times seen it triggered by normal text. --Stef
393 ;; Miles suggests that this form is sometimes used but for italics,
394 ;; so maybe we should map it to `italic'.
395 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
396 ;; 2 3 gnus-emphasis-strikethru)
397 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
398 2 3 gnus-emphasis-underline))))
399 "*Alist that says how to fontify certain phrases.
400 Each item looks like this:
401
402 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
403
404 The first element is a regular expression to be matched. The second
405 is a number that says what regular expression grouping used to find
406 the entire emphasized word. The third is a number that says what
407 regexp grouping should be displayed and highlighted. The fourth
408 is the face used for highlighting."
409 :type
410 '(repeat
411 (menu-choice
412 :format "%[Customizing Style%]\n%v"
413 :indent 2
414 (group :tag "Default"
415 :value ("" 0 0 default)
416 :value-create
417 (lambda (widget)
418 (let ((value (widget-get
419 (cadr (widget-get (widget-get widget :parent)
420 :args))
421 :value)))
422 (if (not (eq (nth 2 value) 'default))
423 (widget-put
424 widget
425 :value
426 (gnus-emphasis-custom-value-to-external value))))
427 (widget-group-value-create widget))
428 regexp
429 (integer :format "Match group: %v")
430 (integer :format "Emphasize group: %v")
431 face)
432 (group :tag "Simple"
433 :value (("_" . "_") nil default)
434 (cons :format "%v"
435 (regexp :format "Start regexp: %v")
436 (regexp :format "End regexp: %v"))
437 (boolean :format "Show start and end patterns: %[%v%]\n"
438 :on " On " :off " Off ")
439 face)))
440 :get (lambda (symbol)
441 (mapcar 'gnus-emphasis-custom-value-to-internal
442 (default-value symbol)))
443 :set (lambda (symbol value)
444 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
445 value)))
446 :group 'gnus-article-emphasis)
447
448 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
449 "A regexp to describe whitespace which should not be emphasized.
450 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
451 The former avoids underlining of leading and trailing whitespace,
452 and the latter avoids underlining any whitespace at all."
453 :version "21.1"
454 :group 'gnus-article-emphasis
455 :type 'regexp)
456
457 (defface gnus-emphasis-bold '((t (:bold t)))
458 "Face used for displaying strong emphasized text (*word*)."
459 :group 'gnus-article-emphasis)
460
461 (defface gnus-emphasis-italic '((t (:italic t)))
462 "Face used for displaying italic emphasized text (/word/)."
463 :group 'gnus-article-emphasis)
464
465 (defface gnus-emphasis-underline '((t (:underline t)))
466 "Face used for displaying underlined emphasized text (_word_)."
467 :group 'gnus-article-emphasis)
468
469 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
470 "Face used for displaying underlined bold emphasized text (_*word*_)."
471 :group 'gnus-article-emphasis)
472
473 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
474 "Face used for displaying underlined italic emphasized text (_/word/_)."
475 :group 'gnus-article-emphasis)
476
477 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
478 "Face used for displaying bold italic emphasized text (/*word*/)."
479 :group 'gnus-article-emphasis)
480
481 (defface gnus-emphasis-underline-bold-italic
482 '((t (:bold t :italic t :underline t)))
483 "Face used for displaying underlined bold italic emphasized text.
484 Example: (_/*word*/_)."
485 :group 'gnus-article-emphasis)
486
487 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
488 '((t (:strikethru t)))
489 '((t (:strike-through t))))
490 "Face used for displaying strike-through text (-word-)."
491 :group 'gnus-article-emphasis)
492
493 (defface gnus-emphasis-highlight-words
494 '((t (:background "black" :foreground "yellow")))
495 "Face used for displaying highlighted words."
496 :group 'gnus-article-emphasis)
497
498 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
499 "Format for display of Date headers in article bodies.
500 See `format-time-string' for the possible values.
501
502 The variable can also be function, which should return a complete Date
503 header. The function is called with one argument, the time, which can
504 be fed to `format-time-string'."
505 :type '(choice string function)
506 :link '(custom-manual "(gnus)Article Date")
507 :group 'gnus-article-washing)
508
509 (defcustom gnus-save-all-headers t
510 "*If non-nil, don't remove any headers before saving.
511 This will be overridden by the `:headers' property that the symbol of
512 the saver function, which is specified by `gnus-default-article-saver',
513 might have."
514 :group 'gnus-article-saving
515 :type 'boolean)
516
517 (defcustom gnus-prompt-before-saving 'always
518 "*This variable says how much prompting is to be done when saving articles.
519 If it is nil, no prompting will be done, and the articles will be
520 saved to the default files. If this variable is `always', each and
521 every article that is saved will be preceded by a prompt, even when
522 saving large batches of articles. If this variable is neither nil not
523 `always', there the user will be prompted once for a file name for
524 each invocation of the saving commands."
525 :group 'gnus-article-saving
526 :type '(choice (item always)
527 (item :tag "never" nil)
528 (sexp :tag "once" :format "%t\n" :value t)))
529
530 (defcustom gnus-saved-headers gnus-visible-headers
531 "Headers to keep if `gnus-save-all-headers' is nil.
532 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
533 If that variable is nil, however, all headers that match this regexp
534 will be kept while the rest will be deleted before saving. This and
535 `gnus-save-all-headers' will be overridden by the `:headers' property
536 that the symbol of the saver function, which is specified by
537 `gnus-default-article-saver', might have."
538 :group 'gnus-article-saving
539 :type 'regexp)
540
541 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
542 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
543 "A function to save articles in your favorite format.
544 The function will be called by way of the `gnus-summary-save-article'
545 command, and friends such as `gnus-summary-save-article-rmail'.
546
547 Gnus provides the following functions:
548
549 * gnus-summary-save-in-rmail (Rmail format)
550 * gnus-summary-save-in-mail (Unix mail format)
551 * gnus-summary-save-in-folder (MH folder)
552 * gnus-summary-save-in-file (article format)
553 * gnus-summary-save-body-in-file (article body)
554 * gnus-summary-save-in-vm (use VM's folder format)
555 * gnus-summary-write-to-file (article format -- overwrite)
556 * gnus-summary-write-body-to-file (article body -- overwrite)
557 * gnus-summary-save-in-pipe (article format)
558
559 The symbol of each function may have the following properties:
560
561 * :decode
562 The value non-nil means save decoded articles. This is meaningful
563 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
564 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
565 `gnus-summary-save-in-pipe'.
566
567 * :function
568 The value specifies an alternative function which appends, not
569 overwrites, articles to a file. This implies that when saving many
570 articles at a time, `gnus-prompt-before-saving' is bound to t and all
571 articles are saved in a single file. This is meaningful only with
572 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
573
574 * :headers
575 The value specifies the symbol of a variable of which the value
576 specifies headers to be saved. If it is omitted,
577 `gnus-save-all-headers' and `gnus-saved-headers' control what
578 headers should be saved."
579 :group 'gnus-article-saving
580 :type '(radio (function-item gnus-summary-save-in-rmail)
581 (function-item gnus-summary-save-in-mail)
582 (function-item gnus-summary-save-in-folder)
583 (function-item gnus-summary-save-in-file)
584 (function-item gnus-summary-save-body-in-file)
585 (function-item gnus-summary-save-in-vm)
586 (function-item gnus-summary-write-to-file)
587 (function-item gnus-summary-write-body-to-file)
588 (function-item gnus-summary-save-in-pipe)
589 (function)))
590
591 (defcustom gnus-article-save-coding-system
592 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
593 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
594 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
595 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
596 "Coding system used to save decoded articles to a file.
597
598 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
599 which can safely encode any characters in text. This is used by the
600 commands including:
601
602 * gnus-summary-save-article-file
603 * gnus-summary-save-article-body-file
604 * gnus-summary-write-article-file
605 * gnus-summary-write-article-body-file
606
607 and the functions to which you may set `gnus-default-article-saver':
608
609 * gnus-summary-save-in-file
610 * gnus-summary-save-body-in-file
611 * gnus-summary-write-to-file
612 * gnus-summary-write-body-to-file
613
614 Those commands and functions save just text displayed in the article
615 buffer to a file if the value of this variable is non-nil. Note that
616 buttonized MIME parts will be lost in a saved file in that case.
617 Otherwise, raw articles will be saved."
618 :group 'gnus-article-saving
619 :type `(choice
620 :format "%{%t%}:\n %[Value Menu%] %v"
621 (const :tag "Save raw articles" nil)
622 ,@(delq nil
623 (mapcar
624 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
625 '((const :tag "UTF-8" utf-8)
626 (const :tag "iso-2022-7bit" iso-2022-7bit)
627 (const :tag "Emacs internal" emacs-mule)
628 (const :tag "escape-quoted" escape-quoted))))
629 (symbol :tag "Coding system")))
630
631 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
632 "A function generating a file name to save articles in Rmail format.
633 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634 :group 'gnus-article-saving
635 :type 'function)
636
637 (defcustom gnus-mail-save-name 'gnus-plain-save-name
638 "A function generating a file name to save articles in Unix mail format.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
640 :group 'gnus-article-saving
641 :type 'function)
642
643 (defcustom gnus-folder-save-name 'gnus-folder-save-name
644 "A function generating a file name to save articles in MH folder.
645 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
646 :group 'gnus-article-saving
647 :type 'function)
648
649 (defcustom gnus-file-save-name 'gnus-numeric-save-name
650 "A function generating a file name to save articles in article format.
651 The function is called with NEWSGROUP, HEADERS, and optional
652 LAST-FILE."
653 :group 'gnus-article-saving
654 :type 'function)
655
656 (defcustom gnus-split-methods
657 '((gnus-article-archive-name)
658 (gnus-article-nndoc-name))
659 "*Variable used to suggest where articles are to be saved.
660 For instance, if you would like to save articles related to Gnus in
661 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
662 you could set this variable to something like:
663
664 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
665 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
666
667 This variable is an alist where the key is the match and the
668 value is a list of possible files to save in if the match is
669 non-nil.
670
671 If the match is a string, it is used as a regexp match on the
672 article. If the match is a symbol, that symbol will be funcalled
673 from the buffer of the article to be saved with the newsgroup as the
674 parameter. If it is a list, it will be evalled in the same buffer.
675
676 If this form or function returns a string, this string will be used as a
677 possible file name; and if it returns a non-nil list, that list will be
678 used as possible file names."
679 :group 'gnus-article-saving
680 :type '(repeat (choice (list :value (fun) function)
681 (cons :value ("" "") regexp (repeat string))
682 (sexp :value nil))))
683
684 (defcustom gnus-page-delimiter "^\^L"
685 "*Regexp describing what to use as article page delimiters.
686 The default value is \"^\^L\", which is a form linefeed at the
687 beginning of a line."
688 :type 'regexp
689 :group 'gnus-article-various)
690
691 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
692 "*The format specification for the article mode line.
693 See `gnus-summary-mode-line-format' for a closer description.
694
695 The following additional specs are available:
696
697 %w The article washing status.
698 %m The number of MIME parts in the article."
699 :version "24.1"
700 :type 'string
701 :group 'gnus-article-various)
702
703 (defcustom gnus-article-mode-hook nil
704 "*A hook for Gnus article mode."
705 :type 'hook
706 :group 'gnus-article-various)
707
708 (when (featurep 'xemacs)
709 ;; Extracted from gnus-xmas-define in order to preserve user settings
710 (when (fboundp 'turn-off-scroll-in-place)
711 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
712 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
713 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
714
715 (defcustom gnus-article-menu-hook nil
716 "*Hook run after the creation of the article mode menu."
717 :type 'hook
718 :group 'gnus-article-various)
719
720 (defcustom gnus-article-prepare-hook nil
721 "*A hook called after an article has been prepared in the article buffer."
722 :type 'hook
723 :group 'gnus-article-various)
724
725 (defcustom gnus-copy-article-ignored-headers nil
726 "List of headers to be removed when copying an article.
727 Each element is a regular expression."
728 :version "23.1" ;; No Gnus
729 :type '(repeat regexp)
730 :group 'gnus-article-various)
731
732 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
733 "Gnus 5.10 (Emacs 22.1)")
734
735 (defface gnus-button
736 '((t (:weight bold)))
737 "Face used for highlighting a button in the article buffer."
738 :group 'gnus-article-buttons)
739
740 (defcustom gnus-article-button-face 'gnus-button
741 "Face used for highlighting buttons in the article buffer.
742
743 An article button is a piece of text that you can activate by pressing
744 `RET' or `mouse-2' above it."
745 :type 'face
746 :group 'gnus-article-buttons)
747
748 (defcustom gnus-article-mouse-face 'highlight
749 "Face used for mouse highlighting in the article buffer.
750
751 Article buttons will be displayed in this face when the cursor is
752 above them."
753 :type 'face
754 :group 'gnus-article-buttons)
755
756 (defcustom gnus-signature-face 'gnus-signature
757 "Face used for highlighting a signature in the article buffer.
758 Obsolete; use the face `gnus-signature' for customizations instead."
759 :type 'face
760 :group 'gnus-article-highlight
761 :group 'gnus-article-signature)
762
763 (defface gnus-signature
764 '((t
765 (:italic t)))
766 "Face used for highlighting a signature in the article buffer."
767 :group 'gnus-article-highlight
768 :group 'gnus-article-signature)
769 ;; backward-compatibility alias
770 (put 'gnus-signature-face 'face-alias 'gnus-signature)
771 (put 'gnus-signature-face 'obsolete-face "22.1")
772
773 (defface gnus-header-from
774 '((((class color)
775 (background dark))
776 (:foreground "PaleGreen1"))
777 (((class color)
778 (background light))
779 (:foreground "red3"))
780 (t
781 (:italic t)))
782 "Face used for displaying from headers."
783 :group 'gnus-article-headers
784 :group 'gnus-article-highlight)
785 ;; backward-compatibility alias
786 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
787 (put 'gnus-header-from-face 'obsolete-face "22.1")
788
789 (defface gnus-header-subject
790 '((((class color)
791 (background dark))
792 (:foreground "SeaGreen1"))
793 (((class color)
794 (background light))
795 (:foreground "red4"))
796 (t
797 (:bold t :italic t)))
798 "Face used for displaying subject headers."
799 :group 'gnus-article-headers
800 :group 'gnus-article-highlight)
801 ;; backward-compatibility alias
802 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
803 (put 'gnus-header-subject-face 'obsolete-face "22.1")
804
805 (defface gnus-header-newsgroups
806 '((((class color)
807 (background dark))
808 (:foreground "yellow" :italic t))
809 (((class color)
810 (background light))
811 (:foreground "MidnightBlue" :italic t))
812 (t
813 (:italic t)))
814 "Face used for displaying newsgroups headers.
815 In the default setup this face is only used for crossposted
816 articles."
817 :group 'gnus-article-headers
818 :group 'gnus-article-highlight)
819 ;; backward-compatibility alias
820 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
821 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
822
823 (defface gnus-header-name
824 '((((class color)
825 (background dark))
826 (:foreground "SpringGreen2"))
827 (((class color)
828 (background light))
829 (:foreground "maroon"))
830 (t
831 (:bold t)))
832 "Face used for displaying header names."
833 :group 'gnus-article-headers
834 :group 'gnus-article-highlight)
835 ;; backward-compatibility alias
836 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
837 (put 'gnus-header-name-face 'obsolete-face "22.1")
838
839 (defface gnus-header-content
840 '((((class color)
841 (background dark))
842 (:foreground "SpringGreen1" :italic t))
843 (((class color)
844 (background light))
845 (:foreground "indianred4" :italic t))
846 (t
847 (:italic t))) "Face used for displaying header content."
848 :group 'gnus-article-headers
849 :group 'gnus-article-highlight)
850 ;; backward-compatibility alias
851 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
852 (put 'gnus-header-content-face 'obsolete-face "22.1")
853
854 (defcustom gnus-header-face-alist
855 '(("From" nil gnus-header-from)
856 ("Subject" nil gnus-header-subject)
857 ("Newsgroups:.*," nil gnus-header-newsgroups)
858 ("" gnus-header-name gnus-header-content))
859 "*Controls highlighting of article headers.
860
861 An alist of the form (HEADER NAME CONTENT).
862
863 HEADER is a regular expression which should match the name of a
864 header and NAME and CONTENT are either face names or nil.
865
866 The name of each header field will be displayed using the face
867 specified by the first element in the list where HEADER matches
868 the header name and NAME is non-nil. Similarly, the content will
869 be displayed by the first non-nil matching CONTENT face."
870 :group 'gnus-article-headers
871 :group 'gnus-article-highlight
872 :type '(repeat (list (regexp :tag "Header")
873 (choice :tag "Name"
874 (item :tag "skip" nil)
875 (face :value default))
876 (choice :tag "Content"
877 (item :tag "skip" nil)
878 (face :value default)))))
879
880 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
881 '((xface . (:face gnus-x-face)))
882 '((pbm . (:face gnus-x-face))
883 (png . nil)))
884 "Alist of image types and properties applied to Face and X-Face images.
885 Here are examples:
886
887 ;; Specify the altitude of Face images in the From header.
888 \(setq gnus-face-properties-alist
889 \\='((pbm . (:face gnus-x-face :ascent 80))
890 (png . (:ascent 80))))
891
892 ;; Show Face images as pressed buttons.
893 \(setq gnus-face-properties-alist
894 \\='((pbm . (:face gnus-x-face :relief -2))
895 (png . (:relief -2))))
896
897 See the manual for the valid properties for various image types.
898 Currently, `pbm' is used for X-Face images and `png' is used for Face
899 images in Emacs. Only the `:face' property is effective on the `xface'
900 image type in XEmacs if it is built with the libcompface library."
901 :version "23.1" ;; No Gnus
902 :group 'gnus-article-headers
903 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
904
905 (defcustom gnus-article-decode-hook
906 '(article-decode-charset article-decode-encoded-words
907 article-decode-group-name article-decode-idna-rhs)
908 "*Hook run to decode charsets in articles."
909 :group 'gnus-article-headers
910 :type 'hook)
911
912 (defcustom gnus-display-mime-function 'gnus-display-mime
913 "Function to display MIME articles."
914 :group 'gnus-article-mime
915 :type 'function)
916
917 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
918 "Function used to decode headers.")
919
920 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
921 "Function used to decode addresses.")
922
923 (defvar gnus-article-dumbquotes-map
924 '((?\200 "EUR")
925 (?\202 ",")
926 (?\203 "f")
927 (?\204 ",,")
928 (?\205 "...")
929 (?\213 "<")
930 (?\214 "OE")
931 (?\221 "`")
932 (?\222 "'")
933 (?\223 "``")
934 (?\224 "\"")
935 (?\225 "*")
936 (?\226 "-")
937 (?\227 "--")
938 (?\230 "~")
939 (?\231 "(TM)")
940 (?\233 ">")
941 (?\234 "oe")
942 (?\264 "'"))
943 "Table for MS-to-Latin1 translation.")
944
945 (defcustom gnus-ignored-mime-types nil
946 "List of MIME types that should be ignored by Gnus."
947 :version "21.1"
948 :group 'gnus-article-mime
949 :type '(repeat regexp))
950
951 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
952 "List of MIME types that should not be given buttons when rendered inline.
953 See also `gnus-buttonized-mime-types' which may override this variable.
954 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
955 :version "21.1"
956 :group 'gnus-article-mime
957 :type '(repeat regexp))
958
959 (defcustom gnus-buttonized-mime-types nil
960 "List of MIME types that should be given buttons when rendered inline.
961 If set, this variable overrides `gnus-unbuttonized-mime-types'.
962 To see e.g. security buttons you could set this to
963 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
964 this list to display radio buttons that allow you to choose one of two
965 media types those mails include. See also `mm-discouraged-alternatives'.
966 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
967 :version "22.1"
968 :group 'gnus-article-mime
969 :type '(repeat regexp))
970
971 (defcustom gnus-inhibit-mime-unbuttonizing nil
972 "If non-nil, all MIME parts get buttons.
973 When nil (the default value), then some MIME parts do not get buttons,
974 as described by the variables `gnus-buttonized-mime-types' and
975 `gnus-unbuttonized-mime-types'."
976 :version "22.1"
977 :group 'gnus-article-mime
978 :type 'boolean)
979
980 (defcustom gnus-body-boundary-delimiter "_"
981 "String used to delimit header and body.
982 This variable is used by `gnus-article-treat-body-boundary' which can
983 be controlled by `gnus-treat-body-boundary'."
984 :version "22.1"
985 :group 'gnus-article-various
986 :type '(choice (item :tag "None" :value nil)
987 string))
988
989 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
990 "/usr/share/picons")
991 "Defines the location of the faces database.
992 For information on obtaining this database of pretty pictures, please
993 see http://www.cs.indiana.edu/picons/ftp/index.html"
994 :version "22.1"
995 :type '(repeat directory)
996 :link '(url-link :tag "download"
997 "http://www.cs.indiana.edu/picons/ftp/index.html")
998 :link '(custom-manual "(gnus)Picons")
999 :group 'gnus-picon)
1000
1001 (defun gnus-picons-installed-p ()
1002 "Say whether picons are installed on your machine."
1003 (let ((installed nil))
1004 (dolist (database gnus-picon-databases)
1005 (when (file-exists-p database)
1006 (setq installed t)))
1007 installed))
1008
1009 (defcustom gnus-article-mime-part-function nil
1010 "Function called with a MIME handle as the argument.
1011 This is meant for people who want to do something automatic based
1012 on parts -- for instance, adding Vcard info to a database."
1013 :group 'gnus-article-mime
1014 :type '(choice (const nil)
1015 function))
1016
1017 (defcustom gnus-mime-multipart-functions nil
1018 "An alist of MIME types to functions to display them."
1019 :version "21.1"
1020 :group 'gnus-article-mime
1021 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1022
1023 (defcustom gnus-article-date-headers '(combined-lapsed)
1024 "A list of Date header formats to display.
1025 Valid formats are `ut' (universal time), `local' (local time
1026 zone), `english' (readable English), `lapsed' (elapsed time),
1027 `combined-lapsed' (both the original date and the elapsed time),
1028 `original' (the original date header), `iso8601' (ISO8601
1029 format), and `user-defined' (a user-defined format defined by the
1030 `gnus-article-time-format' variable).
1031
1032 You have as many date headers as you want in the article buffer.
1033 Some of these headers are updated automatically. See
1034 `gnus-article-update-date-headers' for details."
1035 :version "24.1"
1036 :group 'gnus-article-headers
1037 :type '(set
1038 (const :tag "Universal time (UT)" ut)
1039 (const :tag "Local time zone" local)
1040 (const :tag "Readable English" english)
1041 (const :tag "Elapsed time" lapsed)
1042 (const :tag "Original and elapsed time" combined-lapsed)
1043 (const :tag "Original date header" original)
1044 (const :tag "ISO8601 format" iso8601)
1045 (const :tag "User-defined" user-defined)))
1046
1047 (defcustom gnus-article-update-date-headers nil
1048 "A number that says how often to update the date header (in seconds).
1049 If nil, don't update it at all."
1050 :version "24.1"
1051 :group 'gnus-article-headers
1052 :type '(choice
1053 (item :tag "Don't update" :value nil)
1054 integer))
1055
1056 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1057 "Function called with a MIME handle as the argument.
1058 This is meant for people who want to view first matched part.
1059 For `undisplayed-alternative' (default), the first undisplayed
1060 part or alternative part is used. For `undisplayed', the first
1061 undisplayed part is used. For a function, the first part which
1062 the function return t is used. For nil, the first part is
1063 used."
1064 :version "21.1"
1065 :group 'gnus-article-mime
1066 :type '(choice
1067 (item :tag "first" :value nil)
1068 (item :tag "undisplayed" :value undisplayed)
1069 (item :tag "undisplayed or alternative"
1070 :value undisplayed-alternative)
1071 (function)))
1072
1073 (defcustom gnus-mime-action-alist
1074 '(("save to file" . gnus-mime-save-part)
1075 ("save and strip" . gnus-mime-save-part-and-strip)
1076 ("replace with file" . gnus-mime-replace-part)
1077 ("delete part" . gnus-mime-delete-part)
1078 ("display as text" . gnus-mime-inline-part)
1079 ("view the part" . gnus-mime-view-part)
1080 ("pipe to command" . gnus-mime-pipe-part)
1081 ("toggle display" . gnus-article-press-button)
1082 ("toggle display" . gnus-article-view-part-as-charset)
1083 ("view as type" . gnus-mime-view-part-as-type)
1084 ("view internally" . gnus-mime-view-part-internally)
1085 ("view externally" . gnus-mime-view-part-externally))
1086 "An alist of actions that run on the MIME attachment."
1087 :group 'gnus-article-mime
1088 :type '(repeat (cons (string :tag "name")
1089 (function))))
1090
1091 (defcustom gnus-auto-select-part 1
1092 "Advance to next MIME part when deleting or stripping parts.
1093
1094 When 0, point will be placed on the same part as before. When
1095 positive (negative), move point forward (backwards) this many
1096 parts. When nil, redisplay article."
1097 :version "23.1" ;; No Gnus
1098 :group 'gnus-article-mime
1099 :type '(choice (const nil :tag "Redisplay article.")
1100 (const 1 :tag "Next part.")
1101 (const 0 :tag "Current part.")
1102 integer))
1103
1104 ;;;
1105 ;;; The treatment variables
1106 ;;;
1107
1108 (defvar gnus-part-display-hook nil
1109 "Hook called on parts that are to receive treatment.")
1110
1111 (defvar gnus-article-treat-custom
1112 '(choice (const :tag "Off" nil)
1113 (const :tag "On" t)
1114 (const :tag "Header" head)
1115 (const :tag "First" first)
1116 (const :tag "Last" last)
1117 (integer :tag "Less")
1118 (repeat :tag "Groups" regexp)
1119 (sexp :tag "Predicate")))
1120
1121 (defvar gnus-article-treat-head-custom
1122 '(choice (const :tag "Off" nil)
1123 (const :tag "Header" head)))
1124
1125 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1126 "text/x-patch" "text/html")
1127 "Part types eligible for treatment.")
1128
1129 (defvar gnus-inhibit-treatment nil
1130 "Whether to inhibit treatment.")
1131
1132 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1133 "Highlight the signature.
1134 Valid values are nil, t, `head', `first', `last', an integer or a
1135 predicate. See Info node `(gnus)Customizing Articles'."
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1139 (put 'gnus-treat-highlight-signature 'highlight t)
1140
1141 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1142 "Add buttons.
1143 Valid values are nil, t, `head', `first', `last', an integer or a
1144 predicate. See Info node `(gnus)Customizing Articles'."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1148 (put 'gnus-treat-buttonize 'highlight t)
1149
1150 (defcustom gnus-treat-buttonize-head 'head
1151 "Add buttons to the head.
1152 Valid values are nil, t, `head', `first', `last', an integer or a
1153 predicate. See Info node `(gnus)Customizing Articles'."
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
1156 :type gnus-article-treat-head-custom)
1157 (put 'gnus-treat-buttonize-head 'highlight t)
1158
1159 (defcustom gnus-treat-date 'head
1160 "Display dates according to the `gnus-article-date-headers' variable.
1161 Valid values are nil, t, `head', `first', `last', an integer or a
1162 predicate. See Info node `(gnus)Customizing Articles'."
1163 :version "24.1"
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-head-custom)
1167
1168 (defcustom gnus-treat-emphasize 50000
1169 "Emphasize text.
1170 Valid values are nil, t, `head', `first', `last', an integer or a
1171 predicate. See Info node `(gnus)Customizing Articles'."
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-custom)
1175 (put 'gnus-treat-emphasize 'highlight t)
1176
1177 (defcustom gnus-treat-strip-cr nil
1178 "Remove carriage returns.
1179 Valid values are nil, t, `head', `first', `last', an integer or a
1180 predicate. See Info node `(gnus)Customizing Articles'."
1181 :version "22.1"
1182 :group 'gnus-article-treat
1183 :link '(custom-manual "(gnus)Customizing Articles")
1184 :type gnus-article-treat-custom)
1185
1186 (defcustom gnus-treat-unsplit-urls nil
1187 "Remove newlines from within URLs.
1188 Valid values are nil, t, `head', `first', `last', an integer or a
1189 predicate. See Info node `(gnus)Customizing Articles'."
1190 :version "22.1"
1191 :group 'gnus-article-treat
1192 :link '(custom-manual "(gnus)Customizing Articles")
1193 :type gnus-article-treat-custom)
1194
1195 (defcustom gnus-treat-leading-whitespace nil
1196 "Remove leading whitespace in headers.
1197 Valid values are nil, t, `head', `first', `last', an integer or a
1198 predicate. See Info node `(gnus)Customizing Articles'."
1199 :version "22.1"
1200 :group 'gnus-article-treat
1201 :link '(custom-manual "(gnus)Customizing Articles")
1202 :type gnus-article-treat-custom)
1203
1204 (defcustom gnus-treat-hide-headers 'head
1205 "Hide headers.
1206 Valid values are nil, t, `head', `first', `last', an integer or a
1207 predicate. See Info node `(gnus)Customizing Articles'."
1208 :group 'gnus-article-treat
1209 :link '(custom-manual "(gnus)Customizing Articles")
1210 :type gnus-article-treat-head-custom)
1211
1212 (defcustom gnus-treat-hide-boring-headers nil
1213 "Hide boring headers.
1214 Valid values are nil, t, `head', `first', `last', an integer or a
1215 predicate. See Info node `(gnus)Customizing Articles'."
1216 :group 'gnus-article-treat
1217 :link '(custom-manual "(gnus)Customizing Articles")
1218 :type gnus-article-treat-head-custom)
1219
1220 (defcustom gnus-treat-hide-signature nil
1221 "Hide the signature.
1222 Valid values are nil, t, `head', `first', `last', an integer or a
1223 predicate. See Info node `(gnus)Customizing Articles'."
1224 :group 'gnus-article-treat
1225 :link '(custom-manual "(gnus)Customizing Articles")
1226 :type gnus-article-treat-custom)
1227
1228 (defcustom gnus-treat-fill-article nil
1229 "Fill the article.
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'."
1232 :group 'gnus-article-treat
1233 :link '(custom-manual "(gnus)Customizing Articles")
1234 :type gnus-article-treat-custom)
1235
1236 (defcustom gnus-treat-hide-citation nil
1237 "Hide cited text.
1238 Valid values are nil, t, `head', `first', `last', an integer or a
1239 predicate. See Info node `(gnus)Customizing Articles'.
1240
1241 See `gnus-article-highlight-citation' for variables used to
1242 control what it hides."
1243 :group 'gnus-article-treat
1244 :link '(custom-manual "(gnus)Customizing Articles")
1245 :type gnus-article-treat-custom)
1246
1247 (defcustom gnus-treat-hide-citation-maybe nil
1248 "Hide cited text according to certain conditions.
1249 Valid values are nil, t, `head', `first', `last', an integer or a
1250 predicate. See Info node `(gnus)Customizing Articles'.
1251
1252 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1253 how to control what it hides."
1254 :group 'gnus-article-treat
1255 :link '(custom-manual "(gnus)Customizing Articles")
1256 :type gnus-article-treat-custom)
1257
1258 (defcustom gnus-treat-strip-list-identifiers 'head
1259 "Strip list identifiers from `gnus-list-identifiers'.
1260 Valid values are nil, t, `head', `first', `last', an integer or a
1261 predicate. See Info node `(gnus)Customizing Articles'."
1262 :version "21.1"
1263 :group 'gnus-article-treat
1264 :link '(custom-manual "(gnus)Customizing Articles")
1265 :type gnus-article-treat-custom)
1266
1267 (gnus-define-group-parameter
1268 list-identifier
1269 :variable-document
1270 "Alist of regexps and correspondent identifiers."
1271 :variable-group gnus-article-washing
1272 :parameter-type
1273 '(choice :tag "Identifier"
1274 :value nil
1275 (symbol :tag "Item in `gnus-list-identifiers'" none)
1276 regexp
1277 (const :tag "None" nil))
1278 :parameter-document
1279 "If non-nil, specify how to remove `identifiers' from articles' subject.
1280
1281 Any symbol is used to look up a regular expression to match the
1282 banner in `gnus-list-identifiers'. A string is used as a regular
1283 expression to match the identifier directly.")
1284
1285 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1286 "Gnus 5.10 (Emacs 22.1)")
1287
1288 (defcustom gnus-treat-strip-pem nil
1289 "Strip PEM signatures.
1290 Valid values are nil, t, `head', `first', `last', an integer or a
1291 predicate. See Info node `(gnus)Customizing Articles'."
1292 :group 'gnus-article-treat
1293 :link '(custom-manual "(gnus)Customizing Articles")
1294 :type gnus-article-treat-custom)
1295
1296 (defcustom gnus-treat-strip-banner t
1297 "Strip banners from articles.
1298 The banner to be stripped is specified in the `banner' group parameter.
1299 Valid values are nil, t, `head', `first', `last', an integer or a
1300 predicate. See Info node `(gnus)Customizing Articles'."
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-custom)
1304
1305 (defcustom gnus-treat-highlight-headers 'head
1306 "Highlight the headers.
1307 Valid values are nil, t, `head', `first', `last', an integer or a
1308 predicate. See Info node `(gnus)Customizing Articles'."
1309 :group 'gnus-article-treat
1310 :link '(custom-manual "(gnus)Customizing Articles")
1311 :type gnus-article-treat-head-custom)
1312 (put 'gnus-treat-highlight-headers 'highlight t)
1313
1314 (defcustom gnus-treat-highlight-citation t
1315 "Highlight cited text.
1316 Valid values are nil, t, `head', `first', `last', an integer or a
1317 predicate. See Info node `(gnus)Customizing Articles'."
1318 :group 'gnus-article-treat
1319 :link '(custom-manual "(gnus)Customizing Articles")
1320 :type gnus-article-treat-custom)
1321 (put 'gnus-treat-highlight-citation 'highlight t)
1322
1323 (defcustom gnus-treat-strip-headers-in-body t
1324 "Strip the X-No-Archive header line from the beginning of the body.
1325 Valid values are nil, t, `head', `first', `last', an integer or a
1326 predicate. See Info node `(gnus)Customizing Articles'."
1327 :version "21.1"
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1331
1332 (defcustom gnus-treat-strip-trailing-blank-lines nil
1333 "Strip trailing blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1336
1337 When set to t, it also strips trailing blanks in all MIME parts.
1338 Consider to use `last' instead."
1339 :group 'gnus-article-treat
1340 :link '(custom-manual "(gnus)Customizing Articles")
1341 :type gnus-article-treat-custom)
1342
1343 (defcustom gnus-treat-strip-leading-blank-lines nil
1344 "Strip leading blank lines.
1345 Valid values are nil, t, `head', `first', `last', an integer or a
1346 predicate. See Info node `(gnus)Customizing Articles'.
1347
1348 When set to t, it also strips trailing blanks in all MIME parts."
1349 :group 'gnus-article-treat
1350 :link '(custom-manual "(gnus)Customizing Articles")
1351 :type gnus-article-treat-custom)
1352
1353 (defcustom gnus-treat-strip-multiple-blank-lines nil
1354 "Strip multiple blank lines.
1355 Valid values are nil, t, `head', `first', `last', an integer or a
1356 predicate. See Info node `(gnus)Customizing Articles'."
1357 :group 'gnus-article-treat
1358 :link '(custom-manual "(gnus)Customizing Articles")
1359 :type gnus-article-treat-custom)
1360
1361 (defcustom gnus-treat-unfold-headers 'head
1362 "Unfold folded header lines.
1363 Valid values are nil, t, `head', `first', `last', an integer or a
1364 predicate. See Info node `(gnus)Customizing Articles'."
1365 :version "22.1"
1366 :group 'gnus-article-treat
1367 :link '(custom-manual "(gnus)Customizing Articles")
1368 :type gnus-article-treat-custom)
1369
1370 (defcustom gnus-article-unfold-long-headers nil
1371 "If non-nil, allow unfolding headers even if the header is long.
1372 If it is a regexp, only long headers matching this regexp are unfolded.
1373 If it is t, all long headers are unfolded.
1374
1375 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1376 :version "23.1" ;; No Gnus
1377 :group 'gnus-article-treat
1378 :type '(choice (const nil)
1379 (const :tag "all" t)
1380 (regexp)))
1381
1382 (defcustom gnus-treat-fold-headers nil
1383 "Fold headers.
1384 Valid values are nil, t, `head', `first', `last', an integer or a
1385 predicate. See Info node `(gnus)Customizing Articles'."
1386 :version "22.1"
1387 :group 'gnus-article-treat
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1390
1391 (defcustom gnus-treat-fold-newsgroups 'head
1392 "Fold the Newsgroups and Followup-To headers.
1393 Valid values are nil, t, `head', `first', `last', an integer or a
1394 predicate. See Info node `(gnus)Customizing Articles'."
1395 :version "22.1"
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
1398 :type gnus-article-treat-custom)
1399
1400 (defcustom gnus-treat-overstrike t
1401 "Treat overstrike highlighting.
1402 Valid values are nil, t, `head', `first', `last', an integer or a
1403 predicate. See Info node `(gnus)Customizing Articles'."
1404 :group 'gnus-article-treat
1405 :link '(custom-manual "(gnus)Customizing Articles")
1406 :type gnus-article-treat-custom)
1407 (put 'gnus-treat-overstrike 'highlight t)
1408
1409 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1410 "Treat ANSI SGR control sequences.
1411 Valid values are nil, t, `head', `first', `last', an integer or a
1412 predicate. See Info node `(gnus)Customizing Articles'."
1413 :group 'gnus-article-treat
1414 :link '(custom-manual "(gnus)Customizing Articles")
1415 :type gnus-article-treat-custom)
1416
1417 (make-obsolete-variable 'gnus-treat-display-xface
1418 'gnus-treat-display-x-face "Emacs 22.1")
1419
1420 (defcustom gnus-treat-display-x-face
1421 (and (not noninteractive)
1422 (gnus-image-type-available-p 'xbm)
1423 (if (featurep 'xemacs)
1424 (featurep 'xface)
1425 (condition-case nil
1426 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1427 (executable-find "icontopbm"))
1428 ;; shell-command-to-string may signal an error, e.g. if
1429 ;; shell-file-name is not found.
1430 (error nil)))
1431 'head)
1432 "Display X-Face headers.
1433 Valid values are nil and `head'.
1434 See Info node `(gnus)Customizing Articles' and Info node
1435 `(gnus)X-Face' for details."
1436 :group 'gnus-article-treat
1437 :version "21.1"
1438 :link '(custom-manual "(gnus)Customizing Articles")
1439 :link '(custom-manual "(gnus)X-Face")
1440 :type gnus-article-treat-head-custom
1441 :set (lambda (symbol value)
1442 (set-default
1443 symbol
1444 (cond ((or (boundp symbol) (get symbol 'saved-value))
1445 value)
1446 ((boundp 'gnus-treat-display-xface)
1447 (message "\
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (default-value 'gnus-treat-display-xface))
1451 ((get 'gnus-treat-display-xface 'saved-value)
1452 (message "\
1453 ** gnus-treat-display-xface is an obsolete variable;\
1454 use gnus-treat-display-x-face instead")
1455 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1456 (t
1457 value)))))
1458 (put 'gnus-treat-display-x-face 'highlight t)
1459
1460 (defcustom gnus-treat-display-face
1461 (and (not noninteractive)
1462 (gnus-image-type-available-p 'png)
1463 'head)
1464 "Display Face headers.
1465 Valid values are nil, t, `head', `first', `last', an integer or a
1466 predicate. See Info node `(gnus)Customizing Articles' and Info
1467 node `(gnus)Face' for details."
1468 :group 'gnus-article-treat
1469 :version "22.1"
1470 :link '(custom-manual "(gnus)Customizing Articles")
1471 :link '(custom-manual "(gnus)X-Face")
1472 :type gnus-article-treat-head-custom)
1473 (put 'gnus-treat-display-face 'highlight t)
1474
1475 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1476 "Display smileys.
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate. See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Smileys' for details."
1480 :group 'gnus-article-treat
1481 :version "21.1"
1482 :link '(custom-manual "(gnus)Customizing Articles")
1483 :link '(custom-manual "(gnus)Smileys")
1484 :type gnus-article-treat-custom)
1485 (put 'gnus-treat-display-smileys 'highlight t)
1486
1487 (defcustom gnus-treat-from-picon
1488 (if (and (gnus-image-type-available-p 'xpm)
1489 (gnus-picons-installed-p))
1490 'head nil)
1491 "Display picons in the From header.
1492 Valid values are nil, t, `head', `first', `last', an integer or a
1493 predicate. See Info node `(gnus)Customizing Articles' and Info
1494 node `(gnus)Picons' for details."
1495 :version "22.1"
1496 :group 'gnus-article-treat
1497 :group 'gnus-picon
1498 :link '(custom-manual "(gnus)Customizing Articles")
1499 :link '(custom-manual "(gnus)Picons")
1500 :type gnus-article-treat-head-custom)
1501 (put 'gnus-treat-from-picon 'highlight t)
1502
1503 (defcustom gnus-treat-mail-picon
1504 (if (and (gnus-image-type-available-p 'xpm)
1505 (gnus-picons-installed-p))
1506 'head nil)
1507 "Display picons in To and Cc headers.
1508 Valid values are nil, t, `head', `first', `last', an integer or a
1509 predicate. See Info node `(gnus)Customizing Articles' and Info
1510 node `(gnus)Picons' for details."
1511 :version "22.1"
1512 :group 'gnus-article-treat
1513 :group 'gnus-picon
1514 :link '(custom-manual "(gnus)Customizing Articles")
1515 :link '(custom-manual "(gnus)Picons")
1516 :type gnus-article-treat-head-custom)
1517 (put 'gnus-treat-mail-picon 'highlight t)
1518
1519 (defcustom gnus-treat-newsgroups-picon
1520 (if (and (gnus-image-type-available-p 'xpm)
1521 (gnus-picons-installed-p))
1522 'head nil)
1523 "Display picons in the Newsgroups and Followup-To headers.
1524 Valid values are nil, t, `head', `first', `last', an integer or a
1525 predicate. See Info node `(gnus)Customizing Articles' and Info
1526 node `(gnus)Picons' for details."
1527 :version "22.1"
1528 :group 'gnus-article-treat
1529 :group 'gnus-picon
1530 :link '(custom-manual "(gnus)Customizing Articles")
1531 :link '(custom-manual "(gnus)Picons")
1532 :type gnus-article-treat-head-custom)
1533 (put 'gnus-treat-newsgroups-picon 'highlight t)
1534
1535 (defcustom gnus-treat-from-gravatar nil
1536 "Display gravatars in the From header.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles' and Info
1539 node `(gnus)Gravatars' for details."
1540 :version "24.1"
1541 :group 'gnus-article-treat
1542 :group 'gnus-gravatar
1543 :link '(custom-manual "(gnus)Customizing Articles")
1544 :link '(custom-manual "(gnus)Gravatars")
1545 :type gnus-article-treat-head-custom)
1546 (put 'gnus-treat-from-gravatar 'highlight t)
1547
1548 (defcustom gnus-treat-mail-gravatar nil
1549 "Display gravatars in To and Cc headers.
1550 Valid values are nil, t, `head', `first', `last', an integer or a
1551 predicate. See Info node `(gnus)Customizing Articles' and Info
1552 node `(gnus)Gravatars' for details."
1553 :version "24.1"
1554 :group 'gnus-article-treat
1555 :group 'gnus-gravatar
1556 :link '(custom-manual "(gnus)Customizing Articles")
1557 :link '(custom-manual "(gnus)Gravatars")
1558 :type gnus-article-treat-head-custom)
1559 (put 'gnus-treat-mail-gravatar 'highlight t)
1560
1561 (defcustom gnus-treat-body-boundary
1562 (if (or gnus-treat-newsgroups-picon
1563 gnus-treat-mail-picon
1564 gnus-treat-from-picon
1565 gnus-treat-from-gravatar
1566 gnus-treat-mail-gravatar)
1567 ;; If there's much decoration, the user might prefer a boundary.
1568 'head
1569 nil)
1570 "Draw a boundary at the end of the headers.
1571 Valid values are nil and `head'.
1572 See Info node `(gnus)Customizing Articles' for details."
1573 :version "22.1"
1574 :group 'gnus-article-treat
1575 :link '(custom-manual "(gnus)Customizing Articles")
1576 :type gnus-article-treat-head-custom)
1577
1578 (defcustom gnus-treat-capitalize-sentences nil
1579 "Capitalize sentence-starting words.
1580 Valid values are nil, t, `head', `first', `last', an integer or a
1581 predicate. See Info node `(gnus)Customizing Articles'."
1582 :version "21.1"
1583 :group 'gnus-article-treat
1584 :link '(custom-manual "(gnus)Customizing Articles")
1585 :type gnus-article-treat-custom)
1586
1587 (defcustom gnus-treat-wash-html nil
1588 "Format as HTML.
1589 Valid values are nil, t, `head', `first', `last', an integer or a
1590 predicate. See Info node `(gnus)Customizing Articles'."
1591 :version "22.1"
1592 :group 'gnus-article-treat
1593 :link '(custom-manual "(gnus)Customizing Articles")
1594 :type gnus-article-treat-custom)
1595
1596 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1597 "Fill long lines.
1598 Valid values are nil, t, `head', `first', `last', an integer or a
1599 predicate. See Info node `(gnus)Customizing Articles'."
1600 :version "24.1"
1601 :group 'gnus-article-treat
1602 :link '(custom-manual "(gnus)Customizing Articles")
1603 :type gnus-article-treat-custom)
1604
1605 (defcustom gnus-treat-x-pgp-sig nil
1606 "Verify X-PGP-Sig.
1607 To automatically treat X-PGP-Sig, set it to head.
1608 Valid values are nil, t, `head', `first', `last', an integer or a
1609 predicate. See Info node `(gnus)Customizing Articles'."
1610 :version "22.1"
1611 :group 'gnus-article-treat
1612 :group 'mime-security
1613 :link '(custom-manual "(gnus)Customizing Articles")
1614 :type gnus-article-treat-custom)
1615
1616 (defvar gnus-article-encrypt-protocol-alist
1617 '(("PGP" . mml2015-self-encrypt)))
1618
1619 ;; Set to nil if more than one protocol added to
1620 ;; gnus-article-encrypt-protocol-alist.
1621 (defcustom gnus-article-encrypt-protocol "PGP"
1622 "The protocol used for encrypt articles.
1623 It is a string, such as \"PGP\". If nil, ask user."
1624 :version "22.1"
1625 :type 'string
1626 :group 'mime-security)
1627
1628 (defvar idna-program)
1629
1630 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1631 (condition-case nil
1632 (require 'idna)
1633 (file-error)
1634 (invalid-operation))
1635 idna-program
1636 (executable-find idna-program))
1637 "Whether IDNA decoding of headers is used when viewing messages.
1638 This requires GNU Libidn, and by default only enabled if it is found."
1639 :version "22.1"
1640 :group 'gnus-article-headers
1641 :type 'boolean)
1642
1643 (defcustom gnus-article-over-scroll nil
1644 "If non-nil, allow scrolling the article buffer even when there no more text."
1645 :version "22.1"
1646 :group 'gnus-article
1647 :type 'boolean)
1648
1649 (defcustom gnus-inhibit-images nil
1650 "Non-nil means inhibit displaying of images inline in the article body."
1651 :version "24.1"
1652 :group 'gnus-article
1653 :type 'boolean)
1654
1655 (defcustom gnus-blocked-images 'gnus-block-private-groups
1656 "Images that have URLs matching this regexp will be blocked.
1657 This can also be a function to be evaluated. If so, it will be
1658 called with the group name as the parameter, and should return a
1659 regexp."
1660 :version "24.1"
1661 :group 'gnus-art
1662 :type '(choice regexp function))
1663
1664 ;;; Internal variables
1665
1666 (defvar gnus-english-month-names
1667 '("January" "February" "March" "April" "May" "June" "July" "August"
1668 "September" "October" "November" "December"))
1669
1670 (defvar article-goto-body-goes-to-point-min-p nil)
1671 (defvar gnus-article-wash-types nil)
1672 (defvar gnus-article-emphasis-alist nil)
1673 (defvar gnus-article-image-alist nil)
1674
1675 (defvar gnus-article-mime-handle-alist-1 nil)
1676 (defvar gnus-treatment-function-alist
1677 '((gnus-treat-strip-cr gnus-article-remove-cr)
1678 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1679 (gnus-treat-strip-banner gnus-article-strip-banner)
1680 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1681 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1682 (gnus-treat-buttonize gnus-article-add-buttons)
1683 (gnus-treat-fill-article gnus-article-fill-cited-article)
1684 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1685 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1686 (gnus-treat-display-x-face gnus-article-display-x-face)
1687 (gnus-treat-display-face gnus-article-display-face)
1688 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1689 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1690 (gnus-treat-hide-signature gnus-article-hide-signature)
1691 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1692 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1693 (gnus-treat-from-picon gnus-treat-from-picon)
1694 (gnus-treat-mail-picon gnus-treat-mail-picon)
1695 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1696 (gnus-treat-strip-pem gnus-article-hide-pem)
1697 (gnus-treat-date gnus-article-treat-date)
1698 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1699 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1700 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1701 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1702 (gnus-treat-strip-trailing-blank-lines
1703 gnus-article-remove-trailing-blank-lines)
1704 (gnus-treat-strip-leading-blank-lines
1705 gnus-article-strip-leading-blank-lines)
1706 (gnus-treat-strip-multiple-blank-lines
1707 gnus-article-strip-multiple-blank-lines)
1708 (gnus-treat-overstrike gnus-article-treat-overstrike)
1709 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1710 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1711 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1712 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1713 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1714 (gnus-treat-display-smileys gnus-treat-smiley)
1715 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1716 (gnus-treat-wash-html gnus-article-wash-html)
1717 (gnus-treat-emphasize gnus-article-emphasize)
1718 (gnus-treat-hide-citation gnus-article-hide-citation)
1719 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1720 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1721 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1722
1723 (defvar gnus-article-mime-handle-alist nil)
1724 (defvar article-lapsed-timer nil)
1725 (defvar gnus-article-current-summary nil)
1726
1727 (defvar gnus-article-mode-syntax-table
1728 (let ((table (copy-syntax-table text-mode-syntax-table)))
1729 ;; This causes the citation match run O(2^n).
1730 ;; (modify-syntax-entry ?- "w" table)
1731 (modify-syntax-entry ?> ")<" table)
1732 (modify-syntax-entry ?< "(>" table)
1733 ;; make M-. in article buffers work for `foo' strings
1734 (modify-syntax-entry ?' " " table)
1735 (modify-syntax-entry ?` " " table)
1736 table)
1737 "Syntax table used in article mode buffers.
1738 Initialized from `text-mode-syntax-table'.")
1739
1740 (defvar gnus-save-article-buffer nil)
1741
1742 (defvar gnus-number-of-articles-to-be-saved nil)
1743
1744 (defvar gnus-inhibit-hiding nil)
1745
1746 (defvar gnus-article-edit-mode nil)
1747
1748 ;;; Macros for dealing with the article buffer.
1749
1750 (defmacro gnus-with-article-headers (&rest forms)
1751 `(with-current-buffer gnus-article-buffer
1752 (save-restriction
1753 (let ((inhibit-read-only t)
1754 (inhibit-point-motion-hooks t)
1755 (case-fold-search t))
1756 (article-narrow-to-head)
1757 ,@forms))))
1758
1759 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1760 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1761
1762 (defmacro gnus-with-article-buffer (&rest forms)
1763 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1764 (with-current-buffer gnus-article-buffer
1765 (let ((inhibit-read-only t))
1766 ,@forms))))
1767
1768 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1769 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1770
1771 (defun gnus-article-goto-header (header)
1772 "Go to HEADER, which is a regular expression."
1773 (re-search-forward (concat "^\\(" header "\\):") nil t))
1774
1775 (defsubst gnus-article-hide-text (b e props)
1776 "Set text PROPS on the B to E region."
1777 (gnus-add-text-properties-when 'article-type nil b e props))
1778
1779 (defsubst gnus-article-unhide-text (b e)
1780 "Remove hidden text properties from region between B and E."
1781 (remove-text-properties b e gnus-hidden-properties))
1782
1783 (defun gnus-article-hide-text-type (b e type)
1784 "Hide text of TYPE between B and E."
1785 (gnus-add-wash-type type)
1786 (gnus-article-hide-text
1787 b e (cons 'article-type (cons type gnus-hidden-properties))))
1788
1789 (defun gnus-article-unhide-text-type (b e type)
1790 "Unhide text of TYPE between B and E."
1791 (gnus-delete-wash-type type)
1792 (remove-text-properties
1793 b e (cons 'article-type (cons type gnus-hidden-properties))))
1794
1795 (defun gnus-article-delete-text-of-type (type)
1796 "Delete text of TYPE in the current buffer."
1797 (save-excursion
1798 (let ((b (point-min)))
1799 (if (eq type 'multipart)
1800 ;; Remove MIME buttons associated with multipart/alternative parts.
1801 (progn
1802 (goto-char b)
1803 (while (if (get-text-property (point) 'gnus-part)
1804 (setq b (point))
1805 (when (setq b (next-single-property-change (point)
1806 'gnus-part))
1807 (goto-char b)
1808 t))
1809 (end-of-line)
1810 (skip-chars-forward "\n")
1811 (when (eq (get-text-property b 'article-type) 'multipart)
1812 (delete-region b (point)))))
1813 (while (setq b (text-property-any b (point-max) 'article-type type))
1814 (delete-region
1815 b (or (text-property-not-all b (point-max) 'article-type type)
1816 (point-max))))))))
1817
1818 (defun gnus-article-delete-invisible-text ()
1819 "Delete all invisible text in the current buffer."
1820 (save-excursion
1821 (let ((b (point-min)))
1822 (while (setq b (text-property-any b (point-max) 'invisible t))
1823 (delete-region
1824 b (or (text-property-not-all b (point-max) 'invisible t)
1825 (point-max)))))))
1826
1827 (defsubst gnus-article-header-rank ()
1828 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1829 (let ((list gnus-sorted-header-list)
1830 (i 1))
1831 (while list
1832 (if (looking-at (car list))
1833 (setq list nil)
1834 (setq list (cdr list))
1835 (incf i)))
1836 i))
1837
1838 (defun article-hide-headers (&optional _arg _delete)
1839 "Hide unwanted headers and possibly sort them as well."
1840 (interactive)
1841 ;; This function might be inhibited.
1842 (unless gnus-inhibit-hiding
1843 (let ((inhibit-read-only t)
1844 (case-fold-search t)
1845 (max (1+ (length gnus-sorted-header-list)))
1846 (inhibit-point-motion-hooks t)
1847 (cur (current-buffer))
1848 ignored visible beg)
1849 (save-excursion
1850 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1851 ;; group parameters, so we should go to the summary buffer.
1852 (when (prog1
1853 (condition-case nil
1854 (progn (set-buffer gnus-summary-buffer) t)
1855 (error nil))
1856 (setq ignored (when (not gnus-visible-headers)
1857 (cond ((stringp gnus-ignored-headers)
1858 gnus-ignored-headers)
1859 ((listp gnus-ignored-headers)
1860 (mapconcat 'identity
1861 gnus-ignored-headers
1862 "\\|"))))
1863 visible (cond ((stringp gnus-visible-headers)
1864 gnus-visible-headers)
1865 ((and gnus-visible-headers
1866 (listp gnus-visible-headers))
1867 (mapconcat 'identity
1868 gnus-visible-headers
1869 "\\|")))))
1870 (set-buffer cur))
1871 (save-restriction
1872 ;; First we narrow to just the headers.
1873 (article-narrow-to-head)
1874 ;; Hide any "From " lines at the beginning of (mail) articles.
1875 (while (looking-at "From ")
1876 (forward-line 1))
1877 (unless (bobp)
1878 (delete-region (point-min) (point)))
1879 ;; Then treat the rest of the header lines.
1880 ;; Then we use the two regular expressions
1881 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1882 ;; select which header lines is to remain visible in the
1883 ;; article buffer.
1884 (while (re-search-forward "^[^ \t:]*:" nil t)
1885 (beginning-of-line)
1886 ;; Mark the rank of the header.
1887 (put-text-property
1888 (point) (1+ (point)) 'message-rank
1889 (if (or (and visible (looking-at visible))
1890 (and ignored
1891 (not (looking-at ignored))))
1892 (gnus-article-header-rank)
1893 (+ 2 max)))
1894 (forward-line 1))
1895 (message-sort-headers-1)
1896 (when (setq beg (text-property-any
1897 (point-min) (point-max) 'message-rank (+ 2 max)))
1898 ;; We delete the unwanted headers.
1899 (gnus-add-wash-type 'headers)
1900 (add-text-properties (point-min) (+ 5 (point-min))
1901 '(article-type headers dummy-invisible t))
1902 (delete-region beg (point-max))))))))
1903
1904 (defun article-hide-boring-headers (&optional arg)
1905 "Toggle hiding of headers that aren't very interesting.
1906 If given a negative prefix, always show; if given a positive prefix,
1907 always hide."
1908 (interactive (gnus-article-hidden-arg))
1909 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1910 (not gnus-show-all-headers))
1911 (save-excursion
1912 (save-restriction
1913 (let ((inhibit-read-only t)
1914 (inhibit-point-motion-hooks t))
1915 (article-narrow-to-head)
1916 (dolist (elem gnus-boring-article-headers)
1917 (goto-char (point-min))
1918 (cond
1919 ;; Hide empty headers.
1920 ((eq elem 'empty)
1921 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1922 (forward-line -1)
1923 (gnus-article-hide-text-type
1924 (point-at-bol)
1925 (progn
1926 (end-of-line)
1927 (if (re-search-forward "^[^ \t]" nil t)
1928 (match-beginning 0)
1929 (point-max)))
1930 'boring-headers)))
1931 ;; Hide boring Newsgroups header.
1932 ((eq elem 'newsgroups)
1933 (when (gnus-string-equal
1934 (gnus-fetch-field "newsgroups")
1935 (gnus-group-real-name
1936 (if (boundp 'gnus-newsgroup-name)
1937 gnus-newsgroup-name
1938 "")))
1939 (gnus-article-hide-header "newsgroups")))
1940 ((eq elem 'to-address)
1941 (let ((to (message-fetch-field "to"))
1942 (to-address
1943 (gnus-parameter-to-address
1944 (if (boundp 'gnus-newsgroup-name)
1945 gnus-newsgroup-name ""))))
1946 (when (and to to-address
1947 (ignore-errors
1948 (gnus-string-equal
1949 ;; only one address in To
1950 (nth 1 (mail-extract-address-components to))
1951 to-address)))
1952 (gnus-article-hide-header "to"))))
1953 ((eq elem 'to-list)
1954 (let ((to (message-fetch-field "to"))
1955 (to-list
1956 (gnus-parameter-to-list
1957 (if (boundp 'gnus-newsgroup-name)
1958 gnus-newsgroup-name ""))))
1959 (when (and to to-list
1960 (ignore-errors
1961 (gnus-string-equal
1962 ;; only one address in To
1963 (nth 1 (mail-extract-address-components to))
1964 to-list)))
1965 (gnus-article-hide-header "to"))))
1966 ((eq elem 'cc-list)
1967 (let ((cc (message-fetch-field "cc"))
1968 (to-list
1969 (gnus-parameter-to-list
1970 (if (boundp 'gnus-newsgroup-name)
1971 gnus-newsgroup-name ""))))
1972 (when (and cc to-list
1973 (ignore-errors
1974 (gnus-string-equal
1975 ;; only one address in CC
1976 (nth 1 (mail-extract-address-components cc))
1977 to-list)))
1978 (gnus-article-hide-header "cc"))))
1979 ((eq elem 'followup-to)
1980 (when (gnus-string-equal
1981 (message-fetch-field "followup-to")
1982 (message-fetch-field "newsgroups"))
1983 (gnus-article-hide-header "followup-to")))
1984 ((eq elem 'reply-to)
1985 (if (gnus-group-find-parameter
1986 gnus-newsgroup-name 'broken-reply-to)
1987 (gnus-article-hide-header "reply-to")
1988 (let ((from (message-fetch-field "from"))
1989 (reply-to (message-fetch-field "reply-to")))
1990 (when
1991 (and
1992 from reply-to
1993 (ignore-errors
1994 (equal
1995 (sort (mapcar
1996 (lambda (x) (downcase (cadr x)))
1997 (mail-extract-address-components from t))
1998 'string<)
1999 (sort (mapcar
2000 (lambda (x) (downcase (cadr x)))
2001 (mail-extract-address-components reply-to t))
2002 'string<))))
2003 (gnus-article-hide-header "reply-to")))))
2004 ((eq elem 'date)
2005 (let ((date (with-current-buffer gnus-original-article-buffer
2006 ;; If date in `gnus-article-buffer' is localized
2007 ;; (`gnus-treat-date-user-defined'),
2008 ;; `days-between' might fail.
2009 (message-fetch-field "date"))))
2010 (when (and date
2011 (< (days-between (current-time-string) date)
2012 4))
2013 (gnus-article-hide-header "date"))))
2014 ((eq elem 'long-to)
2015 (let ((to (message-fetch-field "to"))
2016 (cc (message-fetch-field "cc")))
2017 (when (> (length to) 1024)
2018 (gnus-article-hide-header "to"))
2019 (when (> (length cc) 1024)
2020 (gnus-article-hide-header "cc"))))
2021 ((eq elem 'many-to)
2022 (let ((to-count 0)
2023 (cc-count 0))
2024 (goto-char (point-min))
2025 (while (re-search-forward "^to:" nil t)
2026 (setq to-count (1+ to-count)))
2027 (when (> to-count 1)
2028 (while (> to-count 0)
2029 (goto-char (point-min))
2030 (save-restriction
2031 (re-search-forward "^to:" nil nil to-count)
2032 (forward-line -1)
2033 (narrow-to-region (point) (point-max))
2034 (gnus-article-hide-header "to"))
2035 (setq to-count (1- to-count))))
2036 (goto-char (point-min))
2037 (while (re-search-forward "^cc:" nil t)
2038 (setq cc-count (1+ cc-count)))
2039 (when (> cc-count 1)
2040 (while (> cc-count 0)
2041 (goto-char (point-min))
2042 (save-restriction
2043 (re-search-forward "^cc:" nil nil cc-count)
2044 (forward-line -1)
2045 (narrow-to-region (point) (point-max))
2046 (gnus-article-hide-header "cc"))
2047 (setq cc-count (1- cc-count)))))))))))))
2048
2049 (defun gnus-article-hide-header (header)
2050 (save-excursion
2051 (goto-char (point-min))
2052 (when (re-search-forward (concat "^" header ":") nil t)
2053 (gnus-article-hide-text-type
2054 (point-at-bol)
2055 (progn
2056 (end-of-line)
2057 (if (re-search-forward "^[^ \t]" nil t)
2058 (match-beginning 0)
2059 (point-max)))
2060 'boring-headers))))
2061
2062 (defvar gnus-article-normalized-header-length 40
2063 "Length of normalized headers.")
2064
2065 (defun article-normalize-headers ()
2066 "Make all header lines 40 characters long."
2067 (interactive)
2068 (let ((inhibit-read-only t)
2069 column)
2070 (save-excursion
2071 (save-restriction
2072 (article-narrow-to-head)
2073 (while (not (eobp))
2074 (cond
2075 ((< (setq column (- (point-at-eol) (point)))
2076 gnus-article-normalized-header-length)
2077 (end-of-line)
2078 (insert (make-string
2079 (- gnus-article-normalized-header-length column)
2080 ? )))
2081 ((> column gnus-article-normalized-header-length)
2082 (gnus-put-text-property
2083 (progn
2084 (forward-char gnus-article-normalized-header-length)
2085 (point))
2086 (point-at-eol)
2087 'invisible t))
2088 (t
2089 ;; Do nothing.
2090 ))
2091 (forward-line 1))))))
2092
2093 (defun article-treat-dumbquotes ()
2094 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2095 Note that this function guesses whether a character is a sm*rtq**t* or
2096 not, so it should only be used interactively.
2097
2098 Sm*rtq**t*s are M****s***'s unilateral extension to the
2099 iso-8859-1 character map in an attempt to provide more quoting
2100 characters. If you see something like \\222 or \\264 where
2101 you're expecting some kind of apostrophe or quotation mark, then
2102 try this wash."
2103 (interactive)
2104 (article-translate-strings gnus-article-dumbquotes-map))
2105
2106 (defvar org-entities)
2107
2108 (defun article-treat-non-ascii ()
2109 "Translate many Unicode characters into their ASCII equivalents."
2110 (interactive)
2111 (require 'org-entities)
2112 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2113 (dolist (elem org-entities)
2114 (when (and (listp elem)
2115 (= (length (nth 6 elem)) 1))
2116 (if (featurep 'xemacs)
2117 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2118 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2119 (save-excursion
2120 (when (article-goto-body)
2121 (let ((inhibit-read-only t)
2122 replace props)
2123 (while (not (eobp))
2124 (if (not (setq replace (if (featurep 'xemacs)
2125 (get-char-table (following-char) table)
2126 (aref table (following-char)))))
2127 (forward-char 1)
2128 (if (prog1
2129 (setq props (text-properties-at (point)))
2130 (delete-char 1))
2131 (add-text-properties (point) (progn (insert replace) (point))
2132 props)
2133 (insert replace)))))))))
2134
2135 (defun article-translate-strings (map)
2136 "Translate all string in the body of the article according to MAP.
2137 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2138 (save-excursion
2139 (when (article-goto-body)
2140 (let ((inhibit-read-only t))
2141 (dolist (elem map)
2142 (let ((from (car elem))
2143 (to (cadr elem)))
2144 (save-excursion
2145 (if (stringp from)
2146 (while (search-forward from nil t)
2147 (replace-match to))
2148 (while (not (eobp))
2149 (if (eq (following-char) from)
2150 (progn
2151 (delete-char 1)
2152 (insert to))
2153 (forward-char 1)))))))))))
2154
2155 (defun article-treat-overstrike ()
2156 "Translate overstrikes into bold text."
2157 (interactive)
2158 (save-excursion
2159 (when (article-goto-body)
2160 (let ((inhibit-read-only t))
2161 (while (search-forward "\b" nil t)
2162 (let ((next (char-after))
2163 (previous (char-after (- (point) 2))))
2164 ;; We do the boldification/underlining by hiding the
2165 ;; overstrikes and putting the proper text property
2166 ;; on the letters.
2167 (cond
2168 ((eq next previous)
2169 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2170 (put-text-property (point) (1+ (point)) 'face 'bold))
2171 ((eq next ?_)
2172 (gnus-article-hide-text-type
2173 (1- (point)) (1+ (point)) 'overstrike)
2174 (put-text-property
2175 (- (point) 2) (1- (point)) 'face 'underline))
2176 ((eq previous ?_)
2177 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2178 (put-text-property
2179 (point) (1+ (point)) 'face 'underline)))))))))
2180
2181 (defun article-treat-ansi-sequences ()
2182 "Translate ANSI SGR control sequences into overlays or extents."
2183 (interactive)
2184 (save-excursion
2185 (when (article-goto-body)
2186 (let ((inhibit-read-only t))
2187 (ansi-color-apply-on-region (point) (point-max))))))
2188
2189 (defun gnus-article-treat-unfold-headers ()
2190 "Unfold folded message headers.
2191 Only the headers that fit into the current window width will be
2192 unfolded."
2193 (interactive)
2194 (gnus-with-article-headers
2195 (let (length)
2196 (while (not (eobp))
2197 (save-restriction
2198 (mail-header-narrow-to-field)
2199 (let* ((header (buffer-string))
2200 (unfoldable
2201 (or (equal gnus-article-unfold-long-headers t)
2202 (and (stringp gnus-article-unfold-long-headers)
2203 (string-match gnus-article-unfold-long-headers
2204 header)))))
2205 (with-temp-buffer
2206 (insert header)
2207 (goto-char (point-min))
2208 (while (re-search-forward "\n[\t ]" nil t)
2209 (replace-match " " t t)))
2210 (setq length (- (point-max) (point-min) 1))
2211 (when (or unfoldable
2212 (< length (window-width)))
2213 (while (re-search-forward "\n[\t ]" nil t)
2214 (replace-match " " t t))))
2215 (goto-char (point-max)))))))
2216
2217 (defun gnus-article-treat-fold-headers ()
2218 "Fold message headers."
2219 (interactive)
2220 (gnus-with-article-headers
2221 (while (not (eobp))
2222 (save-restriction
2223 (mail-header-narrow-to-field)
2224 (mail-header-fold-field)
2225 (goto-char (point-max))))))
2226
2227 (defun gnus-treat-smiley ()
2228 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2229 (interactive)
2230 (gnus-with-article-buffer
2231 (if (memq 'smiley gnus-article-wash-types)
2232 (gnus-delete-images 'smiley)
2233 (article-goto-body)
2234 (let ((images (smiley-region (point) (point-max))))
2235 (when images
2236 (gnus-add-wash-type 'smiley)
2237 (dolist (image images)
2238 (gnus-add-image 'smiley image)))))))
2239
2240 (defun gnus-article-remove-images ()
2241 "Remove all images from the article buffer."
2242 (interactive)
2243 (gnus-with-article-buffer
2244 (save-restriction
2245 (widen)
2246 (dolist (elem gnus-article-image-alist)
2247 (gnus-delete-images (car elem))))))
2248
2249 (autoload 'w3m-toggle-inline-images "w3m")
2250
2251 (defun gnus-article-show-images ()
2252 "Show any images that are in the HTML-rendered article buffer.
2253 This only works if the article in question is HTML."
2254 (interactive)
2255 (gnus-with-article-buffer
2256 (save-restriction
2257 (widen)
2258 (if (eq mm-text-html-renderer 'w3m)
2259 (let ((mm-inline-text-html-with-images nil))
2260 (w3m-toggle-inline-images))
2261 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2262 'image-displayer))
2263 (destructuring-bind (start end function) region
2264 (funcall function (get-text-property start 'image-url)
2265 start end)))))))
2266
2267 (defun gnus-article-treat-fold-newsgroups ()
2268 "Unfold folded message headers.
2269 Only the headers that fit into the current window width will be
2270 unfolded."
2271 (interactive)
2272 (gnus-with-article-headers
2273 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2274 (save-restriction
2275 (mail-header-narrow-to-field)
2276 (while (re-search-forward ", *" nil t)
2277 (replace-match ", " t t))
2278 (mail-header-fold-field)
2279 (goto-char (point-max))))))
2280
2281 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2282 "Value of `truncate-lines' in Gnus Article buffer.
2283 Valid values are nil, t, `head', `first', `last', an integer or a
2284 predicate. See Info node `(gnus)Customizing Articles'."
2285 :version "23.1" ;; No Gnus
2286 :group 'gnus-article
2287 ;; :link '(custom-manual "(gnus)Customizing Articles")
2288 :type 'boolean)
2289
2290 (defun gnus-article-toggle-truncate-lines (&optional arg)
2291 "Toggle whether to fold or truncate long lines in article the buffer.
2292 If ARG is non-nil and not a number, toggle
2293 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2294 long lines if and only if arg is positive."
2295 (interactive "P")
2296 (cond
2297 ((and (numberp arg) (> arg 0))
2298 (setq gnus-article-truncate-lines t))
2299 ((numberp arg)
2300 (setq gnus-article-truncate-lines nil))
2301 (arg
2302 (setq gnus-article-truncate-lines
2303 (not gnus-article-truncate-lines))))
2304 (gnus-with-article-buffer
2305 (cond
2306 ((and (numberp arg) (> arg 0))
2307 (setq truncate-lines nil))
2308 ((numberp arg)
2309 (setq truncate-lines t)))
2310 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2311 ;; `toggle-truncate-lines' needs an argument.
2312 (toggle-truncate-lines)))
2313
2314 (defun gnus-article-treat-body-boundary ()
2315 "Place a boundary line at the end of the headers."
2316 (interactive)
2317 (when (and gnus-body-boundary-delimiter
2318 (> (length gnus-body-boundary-delimiter) 0))
2319 (gnus-with-article-headers
2320 (goto-char (point-max))
2321 (let ((start (point)))
2322 (insert "X-Boundary: ")
2323 (gnus-add-text-properties start (point) gnus-hidden-properties)
2324 (insert (let (str (max (window-width)))
2325 (if (featurep 'xemacs)
2326 (setq max (1- max)))
2327 (while (>= max (length str))
2328 (setq str (concat str gnus-body-boundary-delimiter)))
2329 (substring str 0 max))
2330 "\n")
2331 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2332
2333 (defun article-fill-long-lines ()
2334 "Fill lines that are wider than the window width."
2335 (interactive)
2336 (save-excursion
2337 (let ((inhibit-read-only t)
2338 (width (window-width (get-buffer-window (current-buffer)))))
2339 (save-restriction
2340 (article-goto-body)
2341 (let ((adaptive-fill-mode nil)) ;Why? -sm
2342 (while (not (eobp))
2343 (end-of-line)
2344 (when (>= (current-column) (min fill-column width))
2345 (narrow-to-region (min (1+ (point)) (point-max))
2346 (point-at-bol))
2347 (let ((goback (point-marker)))
2348 (fill-paragraph nil)
2349 (goto-char (marker-position goback)))
2350 (widen))
2351 (forward-line 1)))))))
2352
2353 (defun article-capitalize-sentences ()
2354 "Capitalize the first word in each sentence."
2355 (interactive)
2356 (save-excursion
2357 (let ((inhibit-read-only t)
2358 (paragraph-start "^[\n\^L]"))
2359 (article-goto-body)
2360 (while (not (eobp))
2361 (capitalize-word 1)
2362 (forward-sentence)))))
2363
2364 (defun article-remove-cr ()
2365 "Remove trailing CRs and then translate remaining CRs into LFs."
2366 (interactive)
2367 (save-excursion
2368 (let ((inhibit-read-only t))
2369 (goto-char (point-min))
2370 (while (re-search-forward "\r+$" nil t)
2371 (replace-match "" t t))
2372 (goto-char (point-min))
2373 (while (search-forward "\r" nil t)
2374 (replace-match "\n" t t)))))
2375
2376 (defun article-remove-trailing-blank-lines ()
2377 "Remove all trailing blank lines from the article."
2378 (interactive)
2379 (save-excursion
2380 (let ((inhibit-read-only t))
2381 (goto-char (point-max))
2382 (delete-region
2383 (point)
2384 (progn
2385 (while (and (not (bobp))
2386 (looking-at "^[ \t]*$")
2387 (not (gnus-annotation-in-region-p
2388 (point) (point-at-eol))))
2389 (forward-line -1))
2390 (forward-line 1)
2391 (point))))))
2392
2393 (defvar gnus-face-properties-alist)
2394
2395 (defun article-display-face (&optional force)
2396 "Display any Face headers in the header."
2397 (interactive (list 'force))
2398 (let ((wash-face-p buffer-read-only))
2399 (gnus-with-article-headers
2400 ;; When displaying parts, this function can be called several times on
2401 ;; the same article, without any intended toggle semantic (as typing `W
2402 ;; D d' would have). So face deletion must occur only when we come from
2403 ;; an interactive command, that is when the *Article* buffer is
2404 ;; read-only.
2405 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2406 (gnus-delete-images 'face)
2407 (let ((from (message-fetch-field "from"))
2408 faces)
2409 (save-current-buffer
2410 (when (and wash-face-p
2411 (gnus-buffer-live-p gnus-original-article-buffer)
2412 (not (re-search-forward "^Face:[\t ]*" nil t)))
2413 (set-buffer gnus-original-article-buffer))
2414 (save-restriction
2415 (mail-narrow-to-head)
2416 (when (or force
2417 ;; Check whether this face is censored.
2418 (not (and gnus-article-x-face-too-ugly
2419 (or from
2420 (setq from (message-fetch-field "from")))
2421 (string-match gnus-article-x-face-too-ugly
2422 from))))
2423 (while (gnus-article-goto-header "Face")
2424 (push (mail-header-field-value) faces)))))
2425 (when faces
2426 (goto-char (point-min))
2427 (let (png image)
2428 (unless (setq from (gnus-article-goto-header "from"))
2429 (insert "From:")
2430 (setq from (point))
2431 (insert " [no 'from' set]\n"))
2432 (while faces
2433 (when (setq png (gnus-convert-face-to-png (pop faces)))
2434 (setq image
2435 (apply 'gnus-create-image png 'png t
2436 (cdr (assq 'png gnus-face-properties-alist))))
2437 (goto-char from)
2438 (when image
2439 (gnus-add-wash-type 'face)
2440 (gnus-add-image 'face image)
2441 (gnus-put-image image nil 'face)))))))))))
2442
2443 (defun article-display-x-face (&optional force)
2444 "Look for an X-Face header and display it if present."
2445 (interactive (list 'force))
2446 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2447 (gnus-with-article-headers
2448 ;; Delete the old process, if any.
2449 (when (process-status "article-x-face")
2450 (delete-process "article-x-face"))
2451 ;; See the comment in `article-display-face'.
2452 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2453 ;; We have already displayed X-Faces, so we remove them
2454 ;; instead.
2455 (gnus-delete-images 'xface)
2456 ;; Display X-Faces.
2457 (let ((from (message-fetch-field "from"))
2458 x-faces)
2459 (save-current-buffer
2460 (when (and wash-face-p
2461 (gnus-buffer-live-p gnus-original-article-buffer)
2462 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2463 ;; If type `W f', use gnus-original-article-buffer,
2464 ;; otherwise use the current buffer because displaying
2465 ;; RFC822 parts calls this function too.
2466 (set-buffer gnus-original-article-buffer))
2467 (save-restriction
2468 (mail-narrow-to-head)
2469 (and gnus-article-x-face-command
2470 (or force
2471 ;; Check whether this face is censored.
2472 (not (and gnus-article-x-face-too-ugly
2473 (or from
2474 (setq from (message-fetch-field "from")))
2475 (string-match gnus-article-x-face-too-ugly
2476 from))))
2477 (while (gnus-article-goto-header "X-Face")
2478 (push (mail-header-field-value) x-faces)))))
2479 (when x-faces
2480 ;; We display the face.
2481 (cond ((functionp gnus-article-x-face-command)
2482 ;; The command is a lisp function, so we call it.
2483 (mapc gnus-article-x-face-command x-faces))
2484 ((stringp gnus-article-x-face-command)
2485 ;; The command is a string, so we interpret the command
2486 ;; as a, well, command, and fork it off.
2487 (let ((process-connection-type nil))
2488 (gnus-set-process-query-on-exit-flag
2489 (start-process
2490 "article-x-face" nil shell-file-name
2491 shell-command-switch gnus-article-x-face-command)
2492 nil)
2493 ;; Sending multiple EOFs to xv doesn't work,
2494 ;; so we only do a single external face.
2495 (with-temp-buffer
2496 (insert (car x-faces))
2497 (process-send-region "article-x-face"
2498 (point-min) (point-max)))
2499 (process-send-eof "article-x-face")))
2500 (t
2501 (error "`%s' set to `%s' is not a function"
2502 gnus-article-x-face-command
2503 'gnus-article-x-face-command)))))))))
2504
2505 (defun article-decode-mime-words ()
2506 "Decode all MIME-encoded words in the article."
2507 (interactive)
2508 (gnus-with-article-buffer
2509 (let ((inhibit-point-motion-hooks t)
2510 (mail-parse-charset gnus-newsgroup-charset)
2511 (mail-parse-ignored-charsets
2512 (with-current-buffer gnus-summary-buffer
2513 gnus-newsgroup-ignored-charsets)))
2514 (mail-decode-encoded-word-region (point-min) (point-max)))))
2515
2516 (defun article-decode-charset (&optional prompt)
2517 "Decode charset-encoded text in the article.
2518 If PROMPT (the prefix), prompt for a coding system to use."
2519 (interactive "P")
2520 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2521 (inhibit-read-only t)
2522 (mail-parse-charset gnus-newsgroup-charset)
2523 (mail-parse-ignored-charsets
2524 (save-excursion (condition-case nil
2525 (set-buffer gnus-summary-buffer)
2526 (error))
2527 gnus-newsgroup-ignored-charsets))
2528 ct cte ctl charset format)
2529 (save-excursion
2530 (save-restriction
2531 (article-narrow-to-head)
2532 (setq ct (message-fetch-field "Content-Type" t)
2533 cte (message-fetch-field "Content-Transfer-Encoding" t)
2534 ctl (and ct (mail-header-parse-content-type ct))
2535 charset (cond
2536 (prompt
2537 (mm-read-coding-system "Charset to decode: "))
2538 (ctl
2539 (mail-content-type-get ctl 'charset)))
2540 format (and ctl (mail-content-type-get ctl 'format)))
2541 (when cte
2542 (setq cte (mail-header-strip cte)))
2543 (if (and ctl (not (string-match "/" (car ctl))))
2544 (setq ctl nil))
2545 (goto-char (point-max)))
2546 (forward-line 1)
2547 (save-restriction
2548 (narrow-to-region (point) (point-max))
2549 (when (and (eq mail-parse-charset 'gnus-decoded)
2550 (eq (mm-body-7-or-8) '8bit))
2551 ;; The text code could have been decoded.
2552 (setq charset mail-parse-charset))
2553 (when (and (or (not ctl)
2554 (equal (car ctl) "text/plain"))
2555 (not format)) ;; article with format will decode later.
2556 (mm-decode-body
2557 charset (and cte (intern (downcase
2558 (gnus-strip-whitespace cte))))
2559 (car ctl)))))))
2560
2561 (defun article-decode-encoded-words ()
2562 "Remove encoded-word encoding from headers."
2563 (let ((inhibit-point-motion-hooks t)
2564 (mail-parse-charset gnus-newsgroup-charset)
2565 (mail-parse-ignored-charsets
2566 (save-excursion (condition-case nil
2567 (set-buffer gnus-summary-buffer)
2568 (error))
2569 gnus-newsgroup-ignored-charsets))
2570 (inhibit-read-only t)
2571 end start)
2572 (goto-char (point-min))
2573 (when (search-forward "\n\n" nil 'move)
2574 (forward-line -1))
2575 (setq end (point))
2576 (while (not (bobp))
2577 (while (progn
2578 (forward-line -1)
2579 (and (not (bobp))
2580 (memq (char-after) '(?\t ? )))))
2581 (setq start (point))
2582 (if (looking-at "\
2583 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2584 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2585 (funcall gnus-decode-address-function start end)
2586 (funcall gnus-decode-header-function start end))
2587 (goto-char (setq end start)))))
2588
2589 (defun article-decode-group-name ()
2590 "Decode group names in Newsgroups, Followup-To and Xref headers."
2591 (let ((inhibit-point-motion-hooks t)
2592 (inhibit-read-only t)
2593 (method (gnus-find-method-for-group gnus-newsgroup-name))
2594 regexp)
2595 (when (and (or gnus-group-name-charset-method-alist
2596 gnus-group-name-charset-group-alist)
2597 (gnus-buffer-live-p gnus-original-article-buffer))
2598 (save-restriction
2599 (article-narrow-to-head)
2600 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2601 (with-current-buffer gnus-original-article-buffer
2602 (goto-char (point-min)))
2603 (setq regexp (concat "^" header
2604 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2605 (while (re-search-forward regexp nil t)
2606 (replace-match (save-match-data
2607 (gnus-decode-newsgroups
2608 ;; XXX how to use data in article buffer?
2609 (with-current-buffer gnus-original-article-buffer
2610 (re-search-forward regexp nil t)
2611 (match-string 1))
2612 gnus-newsgroup-name method))
2613 t t nil 1))
2614 (goto-char (point-min)))))))
2615
2616 (autoload 'idna-to-unicode "idna")
2617
2618 (defun article-decode-idna-rhs ()
2619 "Decode IDNA strings in RHS in various headers in current buffer.
2620 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2621 Mail-Reply-To: and Mail-Followup-To:."
2622 (when gnus-use-idna
2623 (save-restriction
2624 (let ((inhibit-point-motion-hooks t)
2625 (inhibit-read-only t))
2626 (article-narrow-to-head)
2627 (goto-char (point-min))
2628 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2629 (let (ace unicode)
2630 (when (save-match-data
2631 (and (setq ace (match-string 1))
2632 (save-excursion
2633 (and (re-search-backward "^[^ \t]" nil t)
2634 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2635 (setq unicode (idna-to-unicode ace))))
2636 (unless (string= ace unicode)
2637 (replace-match unicode nil nil nil 1)))))))))
2638
2639 (defun article-de-quoted-unreadable (&optional force read-charset)
2640 "Translate a quoted-printable-encoded article.
2641 If FORCE, decode the article whether it is marked as quoted-printable
2642 or not.
2643 If READ-CHARSET, ask for a coding system."
2644 (interactive (list 'force current-prefix-arg))
2645 (save-excursion
2646 (let ((inhibit-read-only t) type charset)
2647 (if (gnus-buffer-live-p gnus-original-article-buffer)
2648 (with-current-buffer gnus-original-article-buffer
2649 (setq type
2650 (gnus-fetch-field "content-transfer-encoding"))
2651 (let* ((ct (gnus-fetch-field "content-type"))
2652 (ctl (and ct (mail-header-parse-content-type ct))))
2653 (setq charset (and ctl
2654 (mail-content-type-get ctl 'charset)))
2655 (if (stringp charset)
2656 (setq charset (intern (downcase charset)))))))
2657 (if read-charset
2658 (setq charset (mm-read-coding-system "Charset: " charset)))
2659 (unless charset
2660 (setq charset gnus-newsgroup-charset))
2661 (when (or force
2662 (and type (let ((case-fold-search t))
2663 (string-match "quoted-printable" type))))
2664 (article-goto-body)
2665 (quoted-printable-decode-region
2666 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2667
2668 (defun article-de-base64-unreadable (&optional force read-charset)
2669 "Translate a base64 article.
2670 If FORCE, decode the article whether it is marked as base64 not.
2671 If READ-CHARSET, ask for a coding system."
2672 (interactive (list 'force current-prefix-arg))
2673 (save-excursion
2674 (let ((inhibit-read-only t) type charset)
2675 (if (gnus-buffer-live-p gnus-original-article-buffer)
2676 (with-current-buffer gnus-original-article-buffer
2677 (setq type
2678 (gnus-fetch-field "content-transfer-encoding"))
2679 (let* ((ct (gnus-fetch-field "content-type"))
2680 (ctl (and ct (mail-header-parse-content-type ct))))
2681 (setq charset (and ctl
2682 (mail-content-type-get ctl 'charset)))
2683 (if (stringp charset)
2684 (setq charset (intern (downcase charset)))))))
2685 (if read-charset
2686 (setq charset (mm-read-coding-system "Charset: " charset)))
2687 (unless charset
2688 (setq charset gnus-newsgroup-charset))
2689 (when (or force
2690 (and type (let ((case-fold-search t))
2691 (string-match "base64" type))))
2692 (article-goto-body)
2693 (save-restriction
2694 (narrow-to-region (point) (point-max))
2695 (base64-decode-region (point-min) (point-max))
2696 (mm-decode-coding-region
2697 (point-min) (point-max)
2698 (mm-charset-to-coding-system charset nil t)))))))
2699
2700 (eval-when-compile
2701 (require 'rfc1843))
2702
2703 (defun article-decode-HZ ()
2704 "Translate a HZ-encoded article."
2705 (interactive)
2706 (require 'rfc1843)
2707 (save-excursion
2708 (let ((inhibit-read-only t))
2709 (rfc1843-decode-region (point-min) (point-max)))))
2710
2711 (defun article-unsplit-urls ()
2712 "Remove the newlines that some other mailers insert into URLs."
2713 (interactive)
2714 (save-excursion
2715 (let ((inhibit-read-only t))
2716 (goto-char (point-min))
2717 (while (re-search-forward
2718 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2719 (replace-match "\\1\\3" t)))
2720 (when (gmm-called-interactively-p 'any)
2721 (gnus-treat-article nil))))
2722
2723 (defun article-wash-html ()
2724 "Format an HTML article."
2725 (interactive)
2726 (let ((handles nil)
2727 (buffer-read-only nil))
2728 (when (gnus-buffer-live-p gnus-original-article-buffer)
2729 (with-current-buffer gnus-original-article-buffer
2730 (setq handles (mm-dissect-buffer t t))))
2731 (article-goto-body)
2732 (delete-region (point) (point-max))
2733 (mm-enable-multibyte)
2734 (mm-inline-text-html handles)))
2735
2736 (defvar gnus-article-browse-html-temp-list nil
2737 "List of temporary files created by `gnus-article-browse-html-parts'.
2738 Internal variable.")
2739
2740 (defcustom gnus-article-browse-delete-temp 'ask
2741 "What to do with temporary files from `gnus-article-browse-html-parts'.
2742 If nil, don't delete temporary files. If it is t, delete them on
2743 exit from the summary buffer. If it is the symbol `file', query
2744 on each file, if it is `ask' ask once when exiting from the
2745 summary buffer."
2746 :group 'gnus-article
2747 :version "23.1" ;; No Gnus
2748 :type '(choice (const :tag "Don't delete" nil)
2749 (const :tag "Don't ask" t)
2750 (const :tag "Ask" ask)
2751 (const :tag "Ask for each file" file)))
2752
2753 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2754
2755 (defun gnus-article-browse-delete-temp-files (&optional how)
2756 "Delete temp-files created by `gnus-article-browse-html-parts'."
2757 (when (and gnus-article-browse-html-temp-list
2758 (progn
2759 (or how (setq how gnus-article-browse-delete-temp))
2760 (if (eq how 'ask)
2761 (let ((files (length gnus-article-browse-html-temp-list)))
2762 (or (gnus-y-or-n-p
2763 (if (= files 1)
2764 "Delete the temporary HTML file? "
2765 (format "Delete all %s temporary HTML files? "
2766 files)))
2767 (setq gnus-article-browse-html-temp-list nil)))
2768 how)))
2769 (dolist (file gnus-article-browse-html-temp-list)
2770 (cond ((file-directory-p file)
2771 (when (or (not (eq how 'file))
2772 (gnus-y-or-n-p
2773 (gnus-format-message
2774 "Delete temporary HTML file(s) in directory `%s'? "
2775 (file-name-as-directory file))))
2776 (gnus-delete-directory file)))
2777 ((file-exists-p file)
2778 (when (or (not (eq how 'file))
2779 (gnus-y-or-n-p
2780 (format "Delete temporary HTML file `%s'? " file)))
2781 (delete-file file)))))
2782 ;; Also remove file from the list when not deleted or if file doesn't
2783 ;; exist anymore.
2784 (setq gnus-article-browse-html-temp-list nil))
2785 gnus-article-browse-html-temp-list)
2786
2787 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2788 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2789 Return file name relative to the parent of DIRECTORY."
2790 (save-match-data
2791 (let (file afile)
2792 (catch 'found
2793 (dolist (handle handles)
2794 (cond
2795 ((not (listp handle)))
2796 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2797 ;; may create.
2798 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2799 ((equal (mm-handle-media-supertype handle) "multipart")
2800 (when (setq file (gnus-article-browse-html-save-cid-content
2801 cid handle directory))
2802 (throw 'found file)))
2803 ((equal (concat "<" cid ">") (mm-handle-id handle))
2804 (setq file (or (mm-handle-filename handle)
2805 (concat
2806 (make-temp-name "cid")
2807 (car (rassoc (car (mm-handle-type handle))
2808 mailcap-mime-extensions))))
2809 afile (expand-file-name file directory))
2810 (mm-save-part-to-file handle afile)
2811 (throw 'found (concat (file-name-nondirectory
2812 (directory-file-name directory))
2813 "/" file)))))))))
2814
2815 (defun gnus-article-browse-html-parts (list &optional header)
2816 "View all \"text/html\" parts from LIST.
2817 Recurse into multiparts. The optional HEADER that should be a decoded
2818 message header will be added to the bodies of the \"text/html\" parts."
2819 ;; Internal function used by `gnus-article-browse-html-article'.
2820 (let (type file charset content cid-dir tmp-file showed)
2821 ;; Find and show the html-parts.
2822 (dolist (handle list)
2823 ;; If HTML, show it:
2824 (cond ((not (listp handle)))
2825 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2826 (and (equal (car type) "message/external-body")
2827 (or header
2828 (setq file (mm-handle-filename handle)))
2829 (or (mm-handle-cache handle)
2830 (condition-case code
2831 (progn (mm-extern-cache-contents handle) t)
2832 (error
2833 (gnus-message 3 "%s" (error-message-string code))
2834 (when (>= gnus-verbose 3) (sit-for 2))
2835 nil)))
2836 (progn
2837 (setq handle (mm-handle-cache handle)
2838 type (mm-handle-type handle))
2839 (equal (car type) "text/html"))))
2840 (setq charset (mail-content-type-get type 'charset)
2841 content (mm-get-part handle))
2842 (with-temp-buffer
2843 (if (eq charset 'gnus-decoded)
2844 (mm-enable-multibyte)
2845 (mm-disable-multibyte))
2846 (insert content)
2847 ;; resolve cid contents
2848 (let ((case-fold-search t)
2849 st base regexp cid-file)
2850 (goto-char (point-min))
2851 (when (and (re-search-forward "<head[\t\n >]" nil t)
2852 (progn
2853 (setq st (match-end 0))
2854 (re-search-forward "</head[\t\n >]" nil t))
2855 (re-search-backward "<base\
2856 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2857 (setq base (match-string 1))
2858 (replace-match "<!--\\&-->")
2859 (setq st (point))
2860 (dolist (tag '(("a" . "href") ("form" . "action")
2861 ("img" . "src")))
2862 (setq regexp (concat "<" (car tag)
2863 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2864 (cdr tag) "=\"\\([^\"]+\\)"))
2865 (while (re-search-forward regexp nil t)
2866 (insert (prog1
2867 (condition-case nil
2868 (save-match-data
2869 (url-expand-file-name (match-string 1)
2870 base))
2871 (error (match-string 1)))
2872 (delete-region (match-beginning 1)
2873 (match-end 1)))))
2874 (goto-char st)))
2875 (while (re-search-forward "\
2876 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2877 nil t)
2878 (unless cid-dir
2879 (setq cid-dir (mm-make-temp-file "cid" t))
2880 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2881 (setq file nil
2882 content nil)
2883 (when (setq cid-file
2884 (gnus-article-browse-html-save-cid-content
2885 (match-string 2)
2886 (with-current-buffer gnus-article-buffer
2887 gnus-article-mime-handles)
2888 cid-dir))
2889 (replace-match cid-file nil nil nil 1))))
2890 (unless content (setq content (buffer-string))))
2891 (when (or charset header (not file))
2892 (setq tmp-file (mm-make-temp-file
2893 ;; Do we need to care for 8.3 filenames?
2894 "mm-" nil ".html")))
2895 ;; Add a meta html tag to specify charset and a header.
2896 (cond
2897 (header
2898 (let (title eheader body hcharset coding)
2899 (with-temp-buffer
2900 (mm-enable-multibyte)
2901 (setq case-fold-search t)
2902 (insert header "\n")
2903 (setq title (message-fetch-field "subject"))
2904 (goto-char (point-min))
2905 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2906 nil t)
2907 (replace-match (cond ((match-beginning 1) "&lt;")
2908 ((match-beginning 2) "&gt;")
2909 ((match-beginning 3) "&amp;")
2910 (t "<br>\n"))))
2911 (goto-char (point-min))
2912 (while (re-search-forward "^[\t ]+" nil t)
2913 (dotimes (i (prog1
2914 (current-column)
2915 (delete-region (match-beginning 0)
2916 (match-end 0))))
2917 (insert "&nbsp;")))
2918 (goto-char (point-min))
2919 (insert "<div align=\"left\">\n")
2920 (goto-char (point-max))
2921 (insert "</div>\n<hr>\n")
2922 ;; We have to examine charset one by one since
2923 ;; charset specified in parts might be different.
2924 (if (eq charset 'gnus-decoded)
2925 (setq charset 'utf-8
2926 eheader (mm-encode-coding-string (buffer-string)
2927 charset)
2928 title (when title
2929 (mm-encode-coding-string title charset))
2930 body (mm-encode-coding-string content charset))
2931 (setq hcharset (mm-find-mime-charset-region (point-min)
2932 (point-max)))
2933 (cond ((= (length hcharset) 1)
2934 (setq hcharset (car hcharset)
2935 coding (mm-charset-to-coding-system
2936 hcharset nil t)))
2937 ((> (length hcharset) 1)
2938 (setq hcharset 'utf-8
2939 coding hcharset)))
2940 (if coding
2941 (if charset
2942 (progn
2943 (setq body
2944 (mm-charset-to-coding-system charset
2945 nil t))
2946 (if (eq coding body)
2947 (setq eheader (mm-encode-coding-string
2948 (buffer-string) coding)
2949 title (when title
2950 (mm-encode-coding-string
2951 title coding))
2952 body content)
2953 (setq charset 'utf-8
2954 eheader (mm-encode-coding-string
2955 (buffer-string) charset)
2956 title (when title
2957 (mm-encode-coding-string
2958 title charset))
2959 body (mm-encode-coding-string
2960 (mm-decode-coding-string
2961 content body)
2962 charset))))
2963 (setq charset hcharset
2964 eheader (mm-encode-coding-string
2965 (buffer-string) coding)
2966 title (when title
2967 (mm-encode-coding-string
2968 title coding))
2969 body content))
2970 (setq eheader (mm-string-as-unibyte (buffer-string))
2971 body content)))
2972 (erase-buffer)
2973 (mm-disable-multibyte)
2974 (insert body)
2975 (when charset
2976 (mm-add-meta-html-tag handle charset t))
2977 (when title
2978 (goto-char (point-min))
2979 (unless (search-forward "<title>" nil t)
2980 (re-search-forward "<head>\\s-*" nil t)
2981 (insert "<title>" title "</title>\n")))
2982 (goto-char (point-min))
2983 (or (re-search-forward
2984 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2985 (re-search-forward
2986 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2987 (insert eheader)
2988 (mm-write-region (point-min) (point-max)
2989 tmp-file nil nil nil 'binary t))))
2990 (charset
2991 (mm-with-unibyte-buffer
2992 (insert (if (eq charset 'gnus-decoded)
2993 (mm-encode-coding-string content
2994 (setq charset 'utf-8))
2995 content))
2996 (if (or (mm-add-meta-html-tag handle charset)
2997 (not file))
2998 (mm-write-region (point-min) (point-max)
2999 tmp-file nil nil nil 'binary t)
3000 (setq tmp-file nil))))
3001 (tmp-file
3002 (mm-save-part-to-file handle tmp-file)))
3003 (when tmp-file
3004 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3005 (add-hook 'gnus-summary-prepare-exit-hook
3006 'gnus-article-browse-delete-temp-files)
3007 (add-hook 'gnus-exit-gnus-hook
3008 (lambda ()
3009 (gnus-article-browse-delete-temp-files t)))
3010 ;; FIXME: Warn if there's an <img> tag?
3011 (browse-url-of-file (or tmp-file (expand-file-name file)))
3012 (setq showed t))
3013 ;; If multipart, recurse
3014 ((equal (mm-handle-media-supertype handle) "multipart")
3015 (when (gnus-article-browse-html-parts handle header)
3016 (setq showed t)))
3017 ((equal (mm-handle-media-type handle) "message/rfc822")
3018 (mm-with-multibyte-buffer
3019 (mm-insert-part handle)
3020 (setq handle (mm-dissect-buffer t t))
3021 (when (and (bufferp (car handle))
3022 (stringp (car (mm-handle-type handle))))
3023 (setq handle (list handle)))
3024 (when header
3025 (article-decode-encoded-words)
3026 (let ((gnus-visible-headers
3027 (or (get 'gnus-visible-headers 'standard-value)
3028 gnus-visible-headers)))
3029 (article-hide-headers))
3030 (goto-char (point-min))
3031 (search-forward "\n\n" nil 'move)
3032 (skip-chars-backward "\t\n ")
3033 (setq header (buffer-substring (point-min) (point)))))
3034 (when (prog1
3035 (gnus-article-browse-html-parts handle header)
3036 (mm-destroy-parts handle))
3037 (setq showed t)))))
3038 showed))
3039
3040 (defun gnus-article-browse-html-article (&optional arg)
3041 "View \"text/html\" parts of the current article with a WWW browser.
3042 Inline images embedded in a message using the cid scheme, as they are
3043 generally considered to be safe, will be processed properly.
3044 The message header is added to the beginning of every html part unless
3045 the prefix argument ARG is given.
3046
3047 Warning: Spammers use links to images (using the http scheme) in HTML
3048 articles to verify whether you have read the message. As
3049 `gnus-article-browse-html-article' passes the HTML content to the
3050 browser without eliminating these \"web bugs\" you should only
3051 use it for mails from trusted senders.
3052
3053 If you always want to display HTML parts in the browser, set
3054 `mm-text-html-renderer' to nil.
3055
3056 This command creates temporary files to pass HTML contents including
3057 images if any to the browser, and deletes them when exiting the group
3058 \(if you want)."
3059 ;; Cf. `mm-w3m-safe-url-regexp'
3060 (interactive "P")
3061 (if arg
3062 (gnus-summary-show-article)
3063 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3064 gnus-visible-headers))
3065 ;; As we insert a <hr>, there's no need for the body boundary.
3066 (gnus-treat-body-boundary nil))
3067 (gnus-summary-show-article)))
3068 (with-current-buffer gnus-article-buffer
3069 (let ((header (unless arg
3070 (save-restriction
3071 (widen)
3072 (buffer-substring-no-properties
3073 (goto-char (point-min))
3074 (if (search-forward "\n\n" nil t)
3075 (match-beginning 0)
3076 (goto-char (point-max))
3077 (skip-chars-backward "\t\n ")
3078 (point))))))
3079 parts)
3080 (set-buffer gnus-original-article-buffer)
3081 (setq parts (mm-dissect-buffer t t))
3082 ;; If singlepart, enforce a list.
3083 (when (and (bufferp (car parts))
3084 (stringp (car (mm-handle-type parts))))
3085 (setq parts (list parts)))
3086 ;; Process the list
3087 (unless (gnus-article-browse-html-parts parts header)
3088 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3089 (mm-destroy-parts parts)
3090 (unless arg
3091 (gnus-summary-show-article)))))
3092
3093 (defun article-hide-list-identifiers ()
3094 "Remove list identifiers from the Subject header.
3095 The `gnus-list-identifiers' variable specifies what to do."
3096 (interactive)
3097 (let ((inhibit-point-motion-hooks t)
3098 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3099 (inhibit-read-only t))
3100 (when regexp
3101 (save-excursion
3102 (save-restriction
3103 (article-narrow-to-head)
3104 (goto-char (point-min))
3105 (while (re-search-forward
3106 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3107 nil t)
3108 (delete-region (match-beginning 2) (match-end 0))
3109 (beginning-of-line))
3110 (when (re-search-forward
3111 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3112 (delete-region (match-beginning 1) (match-end 1))))))))
3113
3114 (defun article-hide-pem (&optional arg)
3115 "Toggle hiding of any PEM headers and signatures in the current article.
3116 If given a negative prefix, always show; if given a positive prefix,
3117 always hide."
3118 (interactive (gnus-article-hidden-arg))
3119 (unless (gnus-article-check-hidden-text 'pem arg)
3120 (save-excursion
3121 (let ((inhibit-read-only t) end)
3122 (goto-char (point-min))
3123 ;; Hide the horrendously ugly "header".
3124 (when (and (search-forward
3125 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3126 nil t)
3127 (setq end (1+ (match-beginning 0))))
3128 (gnus-add-wash-type 'pem)
3129 (gnus-article-hide-text-type
3130 end
3131 (if (search-forward "\n\n" nil t)
3132 (match-end 0)
3133 (point-max))
3134 'pem)
3135 ;; Hide the trailer as well
3136 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3137 nil t)
3138 (gnus-article-hide-text-type
3139 (match-beginning 0) (match-end 0) 'pem)))))))
3140
3141 (defun article-strip-banner ()
3142 "Strip the banners specified by the `banner' group parameter and by
3143 `gnus-article-address-banner-alist'."
3144 (interactive)
3145 (save-excursion
3146 (save-restriction
3147 (let ((inhibit-point-motion-hooks t))
3148 (when (gnus-parameter-banner gnus-newsgroup-name)
3149 (article-really-strip-banner
3150 (gnus-parameter-banner gnus-newsgroup-name)))
3151 (when gnus-article-address-banner-alist
3152 ;; Note that the From header is decoded here, so it is
3153 ;; required that the *-extract-address-components function
3154 ;; supports non-ASCII text.
3155 (let ((from (save-restriction
3156 (widen)
3157 (article-narrow-to-head)
3158 (mail-fetch-field "from"))))
3159 (when (and from
3160 (setq from
3161 (cadr (funcall gnus-extract-address-components
3162 from))))
3163 (catch 'found
3164 (dolist (pair gnus-article-address-banner-alist)
3165 (when (string-match (car pair) from)
3166 (throw 'found
3167 (article-really-strip-banner (cdr pair)))))))))))))
3168
3169 (defun article-really-strip-banner (banner)
3170 "Strip the banner specified by the argument."
3171 (save-excursion
3172 (save-restriction
3173 (let ((inhibit-point-motion-hooks t)
3174 (gnus-signature-limit nil)
3175 (inhibit-read-only t))
3176 (article-goto-body)
3177 (cond
3178 ((eq banner 'signature)
3179 (when (gnus-article-narrow-to-signature)
3180 (widen)
3181 (forward-line -1)
3182 (delete-region (point) (point-max))))
3183 ((symbolp banner)
3184 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3185 (while (re-search-forward banner nil t)
3186 (delete-region (match-beginning 0) (match-end 0)))))
3187 ((stringp banner)
3188 (while (re-search-forward banner nil t)
3189 (delete-region (match-beginning 0) (match-end 0)))))))))
3190
3191 (defun article-babel ()
3192 "Translate article using an online translation service."
3193 (interactive)
3194 (require 'babel)
3195 (gnus-with-article-buffer
3196 (when (article-goto-body)
3197 (let* ((start (point))
3198 (end (point-max))
3199 (orig (buffer-substring start end))
3200 (trans (babel-as-string orig)))
3201 (save-restriction
3202 (narrow-to-region start end)
3203 (delete-region start end)
3204 (insert trans))))))
3205
3206 (defun article-hide-signature (&optional arg)
3207 "Hide the signature in the current article.
3208 If given a negative prefix, always show; if given a positive prefix,
3209 always hide."
3210 (interactive (gnus-article-hidden-arg))
3211 (unless (gnus-article-check-hidden-text 'signature arg)
3212 (save-excursion
3213 (save-restriction
3214 (let ((inhibit-read-only t))
3215 (when (gnus-article-narrow-to-signature)
3216 (gnus-article-hide-text-type
3217 (point-min) (point-max) 'signature))))))
3218 (gnus-set-mode-line 'article))
3219
3220 (defun article-strip-headers-in-body ()
3221 "Strip offensive headers from bodies."
3222 (interactive)
3223 (save-excursion
3224 (article-goto-body)
3225 (let ((case-fold-search t))
3226 (when (looking-at "x-no-archive:")
3227 (gnus-delete-line)))))
3228
3229 (defun article-strip-leading-blank-lines ()
3230 "Remove all blank lines from the beginning of the article."
3231 (interactive)
3232 (save-excursion
3233 (let ((inhibit-point-motion-hooks t)
3234 (inhibit-read-only t))
3235 (when (article-goto-body)
3236 (while (and (not (eobp))
3237 (looking-at "[ \t]*$"))
3238 (gnus-delete-line))))))
3239
3240 (defun article-narrow-to-head ()
3241 "Narrow the buffer to the head of the message.
3242 Point is left at the beginning of the narrowed-to region."
3243 (narrow-to-region
3244 (goto-char (point-min))
3245 (cond
3246 ;; Absolutely no headers displayed.
3247 ((looking-at "\n")
3248 (point))
3249 ;; Normal headers.
3250 ((search-forward "\n\n" nil 1)
3251 (1- (point)))
3252 ;; Nothing but headers.
3253 (t
3254 (point-max))))
3255 (goto-char (point-min)))
3256
3257 (defun article-goto-body ()
3258 "Place point at the start of the body."
3259 (goto-char (point-min))
3260 (cond
3261 ;; This variable is only bound when dealing with separate
3262 ;; MIME body parts.
3263 (article-goto-body-goes-to-point-min-p
3264 t)
3265 ((search-forward "\n\n" nil t)
3266 t)
3267 (t
3268 (goto-char (point-max))
3269 nil)))
3270
3271 (defun article-strip-multiple-blank-lines ()
3272 "Replace consecutive blank lines with one empty line."
3273 (interactive)
3274 (save-excursion
3275 (let ((inhibit-point-motion-hooks t)
3276 (inhibit-read-only t))
3277 ;; First make all blank lines empty.
3278 (article-goto-body)
3279 (while (re-search-forward "^[ \t]+$" nil t)
3280 (unless (gnus-annotation-in-region-p
3281 (match-beginning 0) (match-end 0))
3282 (replace-match "" nil t)))
3283 ;; Then replace multiple empty lines with a single empty line.
3284 (article-goto-body)
3285 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3286 (unless (gnus-annotation-in-region-p
3287 (match-beginning 0) (match-end 0))
3288 (delete-region (match-beginning 1) (match-end 1)))))))
3289
3290 (defun article-strip-leading-space ()
3291 "Remove all white space from the beginning of the lines in the article."
3292 (interactive)
3293 (save-excursion
3294 (let ((inhibit-point-motion-hooks t)
3295 (inhibit-read-only t))
3296 (article-goto-body)
3297 (while (re-search-forward "^[ \t]+" nil t)
3298 (replace-match "" t t)))))
3299
3300 (defun article-strip-trailing-space ()
3301 "Remove all white space from the end of the lines in the article."
3302 (interactive)
3303 (save-excursion
3304 (let ((inhibit-point-motion-hooks t)
3305 (inhibit-read-only t))
3306 (article-goto-body)
3307 (while (re-search-forward "[ \t]+$" nil t)
3308 (replace-match "" t t)))))
3309
3310 (defun article-strip-blank-lines ()
3311 "Strip leading, trailing and multiple blank lines."
3312 (interactive)
3313 (article-strip-leading-blank-lines)
3314 (article-remove-trailing-blank-lines)
3315 (article-strip-multiple-blank-lines))
3316
3317 (defun article-strip-all-blank-lines ()
3318 "Strip all blank lines."
3319 (interactive)
3320 (save-excursion
3321 (let ((inhibit-point-motion-hooks t)
3322 (inhibit-read-only t))
3323 (article-goto-body)
3324 (while (re-search-forward "^[ \t]*\n" nil t)
3325 (replace-match "" t t)))))
3326
3327 (defun gnus-article-narrow-to-signature ()
3328 "Narrow to the signature; return t if a signature is found, else nil."
3329 (let ((inhibit-point-motion-hooks t))
3330 (when (gnus-article-search-signature)
3331 (forward-line 1)
3332 ;; Check whether we have some limits to what we consider
3333 ;; to be a signature.
3334 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3335 (list gnus-signature-limit)))
3336 limit limited)
3337 (while (setq limit (pop limits))
3338 (if (or (and (integerp limit)
3339 (< (- (point-max) (point)) limit))
3340 (and (floatp limit)
3341 (< (count-lines (point) (point-max)) limit))
3342 (and (functionp limit)
3343 (funcall limit))
3344 (and (stringp limit)
3345 (not (re-search-forward limit nil t))))
3346 () ; This limit did not succeed.
3347 (setq limited t
3348 limits nil)))
3349 (unless limited
3350 (narrow-to-region (point) (point-max))
3351 t)))))
3352
3353 (defun gnus-article-search-signature ()
3354 "Search the current buffer for the signature separator.
3355 Put point at the beginning of the signature separator."
3356 (let ((cur (point)))
3357 (goto-char (point-max))
3358 (if (if (stringp gnus-signature-separator)
3359 (re-search-backward gnus-signature-separator nil t)
3360 (let ((seps gnus-signature-separator))
3361 (while (and seps
3362 (not (re-search-backward (car seps) nil t)))
3363 (pop seps))
3364 seps))
3365 t
3366 (goto-char cur)
3367 nil)))
3368
3369 (defun gnus-article-hidden-arg ()
3370 "Return the current prefix arg as a number, or 0 if no prefix."
3371 (list (if current-prefix-arg
3372 (prefix-numeric-value current-prefix-arg)
3373 0)))
3374
3375 (defun gnus-article-check-hidden-text (type arg)
3376 "Return nil if hiding is necessary.
3377 Arg can be nil or a number. nil and positive means hide, negative
3378 means show, 0 means toggle."
3379 (save-excursion
3380 (save-restriction
3381 (let ((hide (gnus-article-hidden-text-p type)))
3382 (cond
3383 ((or (null arg)
3384 (> arg 0))
3385 nil)
3386 ((< arg 0)
3387 (gnus-article-show-hidden-text type)
3388 t)
3389 (t
3390 (if (eq hide 'hidden)
3391 (progn
3392 (gnus-article-show-hidden-text type)
3393 t)
3394 nil)))))))
3395
3396 (defun gnus-article-hidden-text-p (type)
3397 "Say whether the current buffer contains hidden text of type TYPE."
3398 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3399 (while (and pos
3400 (not (get-text-property pos 'invisible))
3401 (not (get-text-property pos 'dummy-invisible)))
3402 (setq pos
3403 (text-property-any (1+ pos) (point-max) 'article-type type)))
3404 (if pos
3405 'hidden
3406 nil)))
3407
3408 (defun gnus-article-show-hidden-text (type &optional _dummy)
3409 "Show all hidden text of type TYPE.
3410 Originally it is hide instead of DUMMY."
3411 (let ((inhibit-read-only t)
3412 (inhibit-point-motion-hooks t))
3413 (gnus-remove-text-properties-when
3414 'article-type type
3415 (point-min) (point-max)
3416 (cons 'article-type (cons type
3417 gnus-hidden-properties)))
3418 (gnus-delete-wash-type type)))
3419
3420 (defconst article-time-units
3421 `((year . ,(* 365.25 24 60 60))
3422 (week . ,(* 7 24 60 60))
3423 (day . ,(* 24 60 60))
3424 (hour . ,(* 60 60))
3425 (minute . 60)
3426 (second . 1))
3427 "Mapping from time units to seconds.")
3428
3429 (defun gnus-article-forward-header ()
3430 "Move point to the start of the next header.
3431 If the current header is a continuation header, this can be several
3432 lines forward."
3433 (let ((ended nil))
3434 (while (not ended)
3435 (forward-line 1)
3436 (if (looking-at "[ \t]+[^ \t]")
3437 (forward-line 1)
3438 (setq ended t)))))
3439
3440 (defun article-treat-date ()
3441 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3442 (with-current-buffer gnus-summary-buffer
3443 gnus-article-date-headers)
3444 gnus-article-date-headers)
3445 t))
3446
3447 (defun article-date-ut (&optional type _highlight date-position)
3448 "Convert DATE date to TYPE in the current article.
3449 The default type is `ut'. See `gnus-article-date-headers' for
3450 possible values."
3451 (interactive (list 'ut t))
3452 (let* ((case-fold-search t)
3453 (inhibit-read-only t)
3454 (inhibit-point-motion-hooks t)
3455 (visible-date (mail-fetch-field "Date"))
3456 pos date bface eface)
3457 (save-excursion
3458 (if date-position
3459 (progn
3460 (goto-char date-position)
3461 (setq date (get-text-property (point) 'original-date))
3462 (when (looking-at "[^:]+:[\t ]*")
3463 (setq bface (get-text-property (match-beginning 0) 'face)
3464 eface (get-text-property (match-end 0) 'face)))
3465 (delete-region (point)
3466 (progn
3467 (gnus-article-forward-header)
3468 (point)))
3469 (article-transform-date date type bface eface))
3470 (save-restriction
3471 (widen)
3472 (goto-char (point-min))
3473 (while (or (get-text-property (setq pos (point)) 'original-date)
3474 (and (setq pos (next-single-property-change
3475 (point) 'original-date))
3476 (goto-char pos)))
3477 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3478 (1+ (match-beginning 0))
3479 (point-max)))
3480 (while (setq pos (text-property-not-all pos (point-max)
3481 'gnus-date-type nil))
3482 (setq date (get-text-property pos 'original-date))
3483 (goto-char pos)
3484 (when (looking-at "[^:]+:[\t ]*")
3485 (setq bface (get-text-property (match-beginning 0) 'face)
3486 eface (get-text-property (match-end 0) 'face)))
3487 (delete-region pos (or (text-property-any pos (point-max)
3488 'gnus-date-type nil)
3489 (point-max))))
3490 (unless date ;; the 1st time
3491 (goto-char (point-min))
3492 (while (re-search-forward "^Date:[\t ]*" nil t)
3493 (setq date (get-text-property (match-beginning 0)
3494 'original-date)
3495 bface (get-text-property (match-beginning 0) 'face)
3496 eface (get-text-property (match-end 0) 'face))
3497 (delete-region (point-at-bol) (progn
3498 (gnus-article-forward-header)
3499 (point)))))
3500 (when (and (not date)
3501 visible-date)
3502 (setq date visible-date))
3503 (when date
3504 (article-transform-date date type bface eface))
3505 (goto-char (point-max))
3506 (widen)))))))
3507
3508 (defun article-transform-date (date type bface eface)
3509 (dolist (this-type (cond
3510 ((null type)
3511 (list 'ut))
3512 ((atom type)
3513 (list type))
3514 (t
3515 type)))
3516 (goto-char
3517 (prog1
3518 (point)
3519 (add-text-properties
3520 (point)
3521 (progn
3522 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3523 (point))
3524 (list 'original-date date 'gnus-date-type this-type))))
3525 ;; Do highlighting.
3526 (when (looking-at
3527 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3528 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3529 (when (match-beginning 2)
3530 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3531 (while (and (zerop (forward-line 1))
3532 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3533 (when (match-beginning 1)
3534 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3535
3536 (defun article-make-date-line (date type)
3537 "Return a DATE line of TYPE."
3538 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3539 combined-lapsed))
3540 (error "Unknown conversion type: %s" type))
3541 (condition-case ()
3542 (let ((time (ignore-errors (date-to-time date))))
3543 (cond
3544 ;; Convert to the local timezone.
3545 ((eq type 'local)
3546 (concat "Date: " (message-make-date time)))
3547 ;; Convert to Universal Time.
3548 ((eq type 'ut)
3549 (concat "Date: "
3550 (substring
3551 (message-make-date
3552 (let* ((e (parse-time-string date))
3553 (tm (apply 'encode-time e))
3554 (ms (car tm))
3555 (ls (- (cadr tm) (car (current-time-zone time)))))
3556 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3557 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3558 (t (list ms ls)))))
3559 0 -5)
3560 "UT"))
3561 ;; Get the original date from the article.
3562 ((eq type 'original)
3563 (concat "Date: " (if (string-match "\n+$" date)
3564 (substring date 0 (match-beginning 0))
3565 date)))
3566 ;; Let the user define the format.
3567 ((eq type 'user-defined)
3568 (let ((format (or (condition-case nil
3569 (with-current-buffer gnus-summary-buffer
3570 gnus-article-time-format)
3571 (error nil))
3572 gnus-article-time-format)))
3573 (if (functionp format)
3574 (funcall format time)
3575 (concat "Date: " (format-time-string format time)))))
3576 ;; ISO 8601.
3577 ((eq type 'iso8601)
3578 (let ((tz (car (current-time-zone time))))
3579 (concat
3580 "Date: "
3581 (format-time-string "%Y%m%dT%H%M%S" time)
3582 (format "%s%02d%02d"
3583 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3584 (/ (% (abs tz) 3600) 60)))))
3585 ;; Do a lapsed format.
3586 ((eq type 'lapsed)
3587 (concat "Date: " (article-lapsed-string time)))
3588 ;; A combined date/lapsed format.
3589 ((eq type 'combined-lapsed)
3590 (let ((date-string (article-make-date-line date 'original))
3591 (segments 3)
3592 lapsed-string)
3593 (while (and
3594 time
3595 (setq lapsed-string
3596 (concat " (" (article-lapsed-string time segments) ")"))
3597 (> (+ (length date-string)
3598 (length lapsed-string))
3599 (+ fill-column 6))
3600 (> segments 0))
3601 (setq segments (1- segments)))
3602 (if (> segments 0)
3603 (concat date-string lapsed-string)
3604 date-string)))
3605 ;; Display the date in proper English
3606 ((eq type 'english)
3607 (let ((dtime (decode-time time)))
3608 (concat
3609 "Date: the "
3610 (number-to-string (nth 3 dtime))
3611 (let ((digit (% (nth 3 dtime) 10)))
3612 (cond
3613 ((memq (nth 3 dtime) '(11 12 13)) "th")
3614 ((= digit 1) "st")
3615 ((= digit 2) "nd")
3616 ((= digit 3) "rd")
3617 (t "th")))
3618 " of "
3619 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3620 " "
3621 (number-to-string (nth 5 dtime))
3622 " at "
3623 (format "%02d" (nth 2 dtime))
3624 ":"
3625 (format "%02d" (nth 1 dtime)))))))
3626 (foo
3627 (format "Date: %s (from Gnus)" date))))
3628
3629 (defun article-lapsed-string (time &optional max-segments)
3630 ;; If the date is seriously mangled, the timezone functions are
3631 ;; liable to bug out, so we ignore all errors.
3632 (let* ((now (current-time))
3633 (real-time (subtract-time now time))
3634 (real-sec (and real-time
3635 (+ (* (float (car real-time)) 65536)
3636 (cadr real-time))))
3637 (sec (and real-time (abs real-sec)))
3638 (segments 0)
3639 num prev)
3640 (unless max-segments
3641 (setq max-segments (length article-time-units)))
3642 (cond
3643 ((null real-time)
3644 "Unknown")
3645 ((zerop sec)
3646 "Now")
3647 (t
3648 (concat
3649 ;; This is a bit convoluted, but basically we go
3650 ;; through the time units for years, weeks, etc,
3651 ;; and divide things to see whether that results
3652 ;; in positive answers.
3653 (mapconcat
3654 (lambda (unit)
3655 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3656 (>= segments max-segments))
3657 ;; The (remaining) seconds are too few to
3658 ;; be divided into this time unit.
3659 ""
3660 ;; It's big enough, so we output it.
3661 (setq sec (- sec (* num (cdr unit))))
3662 (prog1
3663 (concat (if prev ", " "") (int-to-string
3664 (floor num))
3665 " " (symbol-name (car unit))
3666 (if (> num 1) "s" ""))
3667 (setq prev t
3668 segments (1+ segments)))))
3669 article-time-units "")
3670 ;; If dates are odd, then it might appear like the
3671 ;; article was sent in the future.
3672 (if (> real-sec 0)
3673 " ago"
3674 " in the future"))))))
3675
3676 (defun article-date-local (&optional highlight)
3677 "Convert the current article date to the local timezone."
3678 (interactive (list t))
3679 (article-date-ut 'local highlight))
3680
3681 (defun article-date-english (&optional highlight)
3682 "Convert the current article date to something that is proper English."
3683 (interactive (list t))
3684 (article-date-ut 'english highlight))
3685
3686 (defun article-date-original (&optional highlight)
3687 "Convert the current article date to what it was originally.
3688 This is only useful if you have used some other date conversion
3689 function and want to see what the date was before converting."
3690 (interactive (list t))
3691 (article-date-ut 'original highlight))
3692
3693 (defun article-date-lapsed (&optional highlight)
3694 "Convert the current article date to time lapsed since it was sent."
3695 (interactive (list t))
3696 (article-date-ut 'lapsed highlight))
3697
3698 (defun article-date-combined-lapsed (&optional highlight)
3699 "Convert the current article date to time lapsed since it was sent."
3700 (interactive (list t))
3701 (article-date-ut 'combined-lapsed highlight))
3702
3703 (defun article-update-date-lapsed ()
3704 "Function to be run from a timer to update the lapsed time line."
3705 (save-match-data
3706 (let ((buffer (current-buffer)))
3707 (ignore-errors
3708 (walk-windows
3709 (lambda (w)
3710 (set-buffer (window-buffer w))
3711 (when (derived-mode-p 'gnus-article-mode)
3712 (let ((old-line (count-lines (point-min) (point)))
3713 (old-column (- (point) (line-beginning-position)))
3714 (window-start (window-start w))
3715 (pos (point-min))
3716 type next end)
3717 (while (setq pos (text-property-not-all pos (point-max)
3718 'gnus-date-type nil))
3719 (setq next (or (next-single-property-change pos
3720 'gnus-date-type)
3721 (point-max)))
3722 (setq type (get-text-property pos 'gnus-date-type))
3723 (when (memq type '(lapsed combined-lapsed user-defined))
3724 (article-date-ut type t pos)
3725 (setq end (or (next-single-property-change pos
3726 'gnus-date-type)
3727 (point-max)))
3728 (when window-start
3729 (if (/= window-start next)
3730 (setq window-start nil)
3731 (set-window-start w end)))
3732 (setq next end))
3733 (setq pos next))
3734 (goto-char (point-min))
3735 (when (> old-column 0)
3736 (setq old-line (1- old-line)))
3737 (forward-line old-line)
3738 (end-of-line)
3739 (when (> (current-column) old-column)
3740 (beginning-of-line)
3741 (forward-char old-column)))))
3742 nil 'visible))
3743 (set-buffer buffer))))
3744
3745 (defun gnus-start-date-timer (&optional n)
3746 "Start a timer to update the Date headers in the article buffers.
3747 The numerical prefix says how frequently (in seconds) the function
3748 is to run."
3749 (interactive "p")
3750 (unless n
3751 (setq n 1))
3752 (gnus-stop-date-timer)
3753 (setq article-lapsed-timer
3754 (run-at-time 1 n 'article-update-date-lapsed)))
3755
3756 (defun gnus-stop-date-timer ()
3757 "Stop the Date timer."
3758 (interactive)
3759 (when article-lapsed-timer
3760 (nnheader-cancel-timer article-lapsed-timer)
3761 (setq article-lapsed-timer nil)))
3762
3763 (defun article-date-user (&optional highlight)
3764 "Convert the current article date to the user-defined format.
3765 This format is defined by the `gnus-article-time-format' variable."
3766 (interactive (list t))
3767 (article-date-ut 'user highlight))
3768
3769 (defun article-date-iso8601 (&optional highlight)
3770 "Convert the current article date to ISO8601."
3771 (interactive (list t))
3772 (article-date-ut 'iso8601 highlight))
3773
3774 (defmacro gnus-article-save-original-date (&rest forms)
3775 "Save the original date as a text property and evaluate FORMS."
3776 `(let* ((case-fold-search t)
3777 (start (progn
3778 (goto-char (point-min))
3779 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3780 (not (bolp)))
3781 (match-end 0))))
3782 (date (when (and start
3783 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3784 nil t))
3785 (buffer-substring-no-properties start
3786 (match-beginning 0)))))
3787 (goto-char (point-max))
3788 (skip-chars-backward "\n")
3789 (put-text-property (point-min) (point) 'original-date date)
3790 ,@forms
3791 (goto-char (point-max))
3792 (skip-chars-backward "\n")
3793 (put-text-property (point-min) (point) 'original-date date)))
3794
3795 ;; (defun article-show-all ()
3796 ;; "Show all hidden text in the article buffer."
3797 ;; (interactive)
3798 ;; (save-excursion
3799 ;; (let ((inhibit-read-only t))
3800 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3801
3802 (defun article-remove-leading-whitespace ()
3803 "Remove excessive whitespace from all headers."
3804 (interactive)
3805 (save-excursion
3806 (save-restriction
3807 (let ((inhibit-read-only t))
3808 (article-narrow-to-head)
3809 (goto-char (point-min))
3810 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3811 (delete-region (match-beginning 1) (match-end 1)))))))
3812
3813 (defun article-emphasize (&optional arg)
3814 "Emphasize text according to `gnus-emphasis-alist'."
3815 (interactive (gnus-article-hidden-arg))
3816 (unless (gnus-article-check-hidden-text 'emphasis arg)
3817 (save-excursion
3818 (let ((alist (or
3819 (condition-case nil
3820 (with-current-buffer gnus-summary-buffer
3821 gnus-article-emphasis-alist)
3822 (error))
3823 gnus-emphasis-alist))
3824 (inhibit-read-only t)
3825 (props (append '(article-type emphasis)
3826 gnus-hidden-properties))
3827 regexp elem beg invisible visible face)
3828 (article-goto-body)
3829 (setq beg (point))
3830 (while (setq elem (pop alist))
3831 (goto-char beg)
3832 (setq regexp (car elem)
3833 invisible (nth 1 elem)
3834 visible (nth 2 elem)
3835 face (nth 3 elem))
3836 (while (re-search-forward regexp nil t)
3837 (when (and (match-beginning visible) (match-beginning invisible))
3838 (gnus-article-hide-text
3839 (match-beginning invisible) (match-end invisible) props)
3840 (gnus-article-unhide-text-type
3841 (match-beginning visible) (match-end visible) 'emphasis)
3842 (gnus-put-overlay-excluding-newlines
3843 (match-beginning visible) (match-end visible) 'face face)
3844 (gnus-add-wash-type 'emphasis)
3845 (goto-char (match-end invisible)))))))))
3846
3847 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3848 "Setup newsgroup emphasis alist."
3849 (unless gnus-article-emphasis-alist
3850 (let ((name (and gnus-newsgroup-name
3851 (gnus-group-real-name gnus-newsgroup-name))))
3852 (make-local-variable 'gnus-article-emphasis-alist)
3853 (setq gnus-article-emphasis-alist
3854 (nconc
3855 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3856 (while (setq elem (pop alist))
3857 (when (and name (string-match (car elem) name))
3858 (setq alist nil
3859 highlight (copy-sequence (cdr elem)))))
3860 highlight)
3861 (copy-sequence highlight-words)
3862 (if gnus-newsgroup-name
3863 (copy-sequence (gnus-group-find-parameter
3864 gnus-newsgroup-name 'highlight-words t)))
3865 gnus-emphasis-alist)))))
3866
3867 (defvar gnus-summary-article-menu)
3868 (defvar gnus-summary-post-menu)
3869
3870 ;;; Saving functions.
3871
3872 (defun gnus-article-save (save-buffer file &optional num)
3873 "Save the currently selected article."
3874 (when (or (get gnus-default-article-saver :headers)
3875 (not gnus-save-all-headers))
3876 ;; Remove headers according to `gnus-saved-headers' or the value
3877 ;; of the `:headers' property that the saver function might have.
3878 (let ((gnus-visible-headers
3879 (or (symbol-value (get gnus-default-article-saver :headers))
3880 gnus-saved-headers gnus-visible-headers))
3881 ;; Ignore group parameter. See `article-hide-headers'.
3882 (gnus-summary-buffer nil))
3883 (with-current-buffer save-buffer
3884 (article-hide-headers 1 t))))
3885 (save-window-excursion
3886 (if (not gnus-default-article-saver)
3887 (error "No default saver is defined")
3888 ;; !!! Magic! The saving functions all save
3889 ;; `gnus-save-article-buffer' (or so they think), but we
3890 ;; bind that variable to our save-buffer.
3891 (set-buffer gnus-article-buffer)
3892 (let* ((gnus-save-article-buffer save-buffer)
3893 (filename
3894 (cond
3895 ((not gnus-prompt-before-saving) 'default)
3896 ((eq gnus-prompt-before-saving 'always) nil)
3897 (t file)))
3898 (gnus-number-of-articles-to-be-saved
3899 (when (eq gnus-prompt-before-saving t)
3900 num))) ; Magic
3901 (set-buffer gnus-article-current-summary)
3902 (funcall gnus-default-article-saver filename)))))
3903
3904 (defun gnus-read-save-file-name (prompt &optional filename
3905 function group headers variable
3906 dir-var)
3907 (let ((default-name
3908 (funcall function group headers (symbol-value variable)))
3909 result)
3910 (setq result
3911 (expand-file-name
3912 (cond
3913 ((eq filename 'default)
3914 default-name)
3915 ((eq filename t)
3916 default-name)
3917 (filename filename)
3918 (t
3919 (when (symbol-value dir-var)
3920 (setq default-name (expand-file-name
3921 (file-name-nondirectory default-name)
3922 (symbol-value dir-var))))
3923 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3924 (prompt
3925 (format prompt
3926 (if (and gnus-number-of-articles-to-be-saved
3927 (> gnus-number-of-articles-to-be-saved 1))
3928 (format "these %d articles"
3929 gnus-number-of-articles-to-be-saved)
3930 "this article")))
3931 (file
3932 ;; Let the split methods have their say.
3933 (cond
3934 ;; No split name was found.
3935 ((null split-name)
3936 (read-file-name
3937 (concat prompt " (default "
3938 (file-name-nondirectory default-name) "): ")
3939 (file-name-directory default-name)
3940 default-name))
3941 ;; A single group name is returned.
3942 ((stringp split-name)
3943 (setq default-name
3944 (funcall function split-name headers
3945 (symbol-value variable)))
3946 (read-file-name
3947 (concat prompt " (default "
3948 (file-name-nondirectory default-name) "): ")
3949 (file-name-directory default-name)
3950 default-name))
3951 ;; A single split name was found
3952 ((= 1 (length split-name))
3953 (let* ((name (expand-file-name
3954 (car split-name)
3955 gnus-article-save-directory))
3956 (dir (cond ((file-directory-p name)
3957 (file-name-as-directory name))
3958 ((file-exists-p name) name)
3959 (t gnus-article-save-directory))))
3960 (read-file-name
3961 (concat prompt " (default " name "): ")
3962 dir name)))
3963 ;; A list of splits was found.
3964 (t
3965 (setq split-name (nreverse split-name))
3966 (let (result)
3967 (let ((file-name-history
3968 (nconc split-name file-name-history)))
3969 (setq result
3970 (expand-file-name
3971 (read-file-name
3972 (concat prompt " (`M-p' for defaults): ")
3973 gnus-article-save-directory
3974 (car split-name))
3975 gnus-article-save-directory)))
3976 (car (push result file-name-history)))))))
3977 ;; Create the directory.
3978 (gnus-make-directory (file-name-directory file))
3979 ;; If we have read a directory, we append the default file name.
3980 (when (file-directory-p file)
3981 (setq file (expand-file-name (file-name-nondirectory
3982 default-name)
3983 (file-name-as-directory file))))
3984 ;; Possibly translate some characters.
3985 (nnheader-translate-file-chars file))))))
3986 (gnus-make-directory (file-name-directory result))
3987 (when variable
3988 (set variable result))
3989 (when dir-var
3990 (set dir-var (file-name-directory result)))
3991 result))
3992
3993 (defun gnus-article-archive-name (_group)
3994 "Return the first instance of an \"Archive-name\" in the current buffer."
3995 (let ((case-fold-search t))
3996 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3997 (nnheader-concat gnus-article-save-directory
3998 (match-string 1)))))
3999
4000 (defun gnus-article-nndoc-name (group)
4001 "If GROUP is an nndoc group, return the name of the parent group."
4002 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4003 (gnus-group-get-parameter group 'save-article-group)))
4004
4005 (defun gnus-summary-save-in-rmail (&optional filename)
4006 "Append this article to Rmail file.
4007 Optional argument FILENAME specifies file name.
4008 Directory to save to is default to `gnus-article-save-directory'."
4009 (setq filename (gnus-read-save-file-name
4010 "Save %s in rmail file" filename
4011 gnus-rmail-save-name gnus-newsgroup-name
4012 gnus-current-headers 'gnus-newsgroup-last-rmail))
4013 (with-current-buffer gnus-save-article-buffer
4014 (save-excursion
4015 (save-restriction
4016 (widen)
4017 ;; Note that unlike gnus-summary-save-in-mail, there is no
4018 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4019 ;; not use Babyl.
4020 (gnus-output-to-rmail filename))))
4021 filename)
4022
4023 (defun gnus-summary-save-in-mail (&optional filename)
4024 "Append this article to Unix mail file.
4025 Optional argument FILENAME specifies file name.
4026 Directory to save to is default to `gnus-article-save-directory'."
4027 (setq filename (gnus-read-save-file-name
4028 "Save %s in Unix mail file" filename
4029 gnus-mail-save-name gnus-newsgroup-name
4030 gnus-current-headers 'gnus-newsgroup-last-mail))
4031 (with-current-buffer gnus-save-article-buffer
4032 (save-excursion
4033 (save-restriction
4034 (widen)
4035 (if (and (file-readable-p filename)
4036 (file-regular-p filename)
4037 (mail-file-babyl-p filename))
4038 (gnus-output-to-rmail filename)
4039 (gnus-output-to-mail filename)))))
4040 filename)
4041
4042 (put 'gnus-summary-save-in-file :decode t)
4043 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4044 (defun gnus-summary-save-in-file (&optional filename overwrite)
4045 "Append this article to file.
4046 Optional argument FILENAME specifies file name.
4047 Directory to save to is default to `gnus-article-save-directory'."
4048 (setq filename (gnus-read-save-file-name
4049 "Save %s in file" filename
4050 gnus-file-save-name gnus-newsgroup-name
4051 gnus-current-headers 'gnus-newsgroup-last-file))
4052 (with-current-buffer gnus-save-article-buffer
4053 (save-excursion
4054 (save-restriction
4055 (widen)
4056 (when (and overwrite
4057 (file-exists-p filename))
4058 (delete-file filename))
4059 (gnus-output-to-file filename))))
4060 filename)
4061
4062 (put 'gnus-summary-write-to-file :decode t)
4063 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4064 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4065 (defun gnus-summary-write-to-file (&optional filename)
4066 "Write this article to a file, overwriting it if the file exists.
4067 Optional argument FILENAME specifies file name.
4068 The directory to save in defaults to `gnus-article-save-directory'."
4069 (setq filename (gnus-read-save-file-name
4070 "Save %s in file" filename
4071 gnus-file-save-name gnus-newsgroup-name
4072 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4073 (gnus-summary-save-in-file filename t))
4074
4075 (put 'gnus-summary-save-body-in-file :decode t)
4076 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4077 "Append this article body to a file.
4078 Optional argument FILENAME specifies file name.
4079 The directory to save in defaults to `gnus-article-save-directory'."
4080 (setq filename (gnus-read-save-file-name
4081 "Save %s body in file" filename
4082 gnus-file-save-name gnus-newsgroup-name
4083 gnus-current-headers 'gnus-newsgroup-last-file))
4084 (with-current-buffer gnus-save-article-buffer
4085 (save-excursion
4086 (save-restriction
4087 (widen)
4088 (when (article-goto-body)
4089 (narrow-to-region (point) (point-max)))
4090 (when (and overwrite
4091 (file-exists-p filename))
4092 (delete-file filename))
4093 (gnus-output-to-file filename))))
4094 filename)
4095
4096 (put 'gnus-summary-write-body-to-file :decode t)
4097 (put 'gnus-summary-write-body-to-file
4098 :function 'gnus-summary-save-body-in-file)
4099 (defun gnus-summary-write-body-to-file (&optional filename)
4100 "Write this article body to a file, overwriting it if the file exists.
4101 Optional argument FILENAME specifies file name.
4102 The directory to save in defaults to `gnus-article-save-directory'."
4103 (setq filename (gnus-read-save-file-name
4104 "Save %s body in file" filename
4105 gnus-file-save-name gnus-newsgroup-name
4106 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4107 (gnus-summary-save-body-in-file filename t))
4108
4109 (put 'gnus-summary-save-in-pipe :decode t)
4110 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4111 (defun gnus-summary-save-in-pipe (&optional command raw)
4112 "Pipe this article to subprocess COMMAND.
4113 Valid values for COMMAND include:
4114 a string
4115 The executable command name and possibly arguments.
4116 nil
4117 You will be prompted for the command in the minibuffer.
4118 the symbol `default'
4119 It will be replaced with the command which the variable
4120 `gnus-summary-pipe-output-default-command' holds or the command
4121 last used for saving.
4122 Non-nil value for RAW overrides `:decode' and `:headers' properties
4123 and the raw article including all headers will be piped."
4124 (let ((article (gnus-summary-article-number))
4125 (decode (unless raw
4126 (get 'gnus-summary-save-in-pipe :decode)))
4127 save-buffer default)
4128 (if article
4129 (if (vectorp (gnus-summary-article-header article))
4130 (save-current-buffer
4131 (gnus-summary-select-article decode decode nil article)
4132 (insert-buffer-substring
4133 (prog1
4134 (if decode
4135 gnus-article-buffer
4136 gnus-original-article-buffer)
4137 (setq save-buffer
4138 (nnheader-set-temp-buffer " *Gnus Save*"))))
4139 ;; Remove unwanted headers.
4140 (when (and (not raw)
4141 (or (get 'gnus-summary-save-in-pipe :headers)
4142 (not gnus-save-all-headers)))
4143 (let ((gnus-visible-headers
4144 (or (symbol-value (get 'gnus-summary-save-in-pipe
4145 :headers))
4146 gnus-saved-headers gnus-visible-headers))
4147 (gnus-summary-buffer nil))
4148 (article-hide-headers 1 t))))
4149 (error "%d is not a real article" article))
4150 (error "No article to pipe"))
4151 (setq default (or gnus-summary-pipe-output-default-command
4152 gnus-last-shell-command))
4153 (unless (stringp command)
4154 (setq command
4155 (if (and (eq command 'default) default)
4156 default
4157 (gnus-read-shell-command "Shell command on this article: "
4158 default))))
4159 (when (string-equal command "")
4160 (if default
4161 (setq command default)
4162 (error "A command is required")))
4163 (with-current-buffer save-buffer
4164 (save-restriction
4165 (widen)
4166 (shell-command-on-region (point-min) (point-max) command nil)))
4167 (gnus-kill-buffer save-buffer))
4168 (setq gnus-summary-pipe-output-default-command command))
4169
4170 (defun gnus-summary-pipe-to-muttprint (&optional command)
4171 "Pipe this article to muttprint."
4172 (unless (stringp command)
4173 (setq command (read-string
4174 "Print using command: " gnus-summary-muttprint-program
4175 nil gnus-summary-muttprint-program)))
4176 (let ((gnus-summary-pipe-output-default-command
4177 gnus-summary-pipe-output-default-command))
4178 (gnus-summary-save-in-pipe command))
4179 (setq gnus-summary-muttprint-program command))
4180
4181 ;;; Article file names when saving.
4182
4183 (defun gnus-capitalize-newsgroup (newsgroup)
4184 "Capitalize NEWSGROUP name."
4185 (when (not (zerop (length newsgroup)))
4186 (concat (char-to-string (upcase (aref newsgroup 0)))
4187 (substring newsgroup 1))))
4188
4189 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4190 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4191 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4192 Otherwise, it is like ~/News/news/group/num."
4193 (let ((default
4194 (expand-file-name
4195 (concat (if (gnus-use-long-file-name 'not-save)
4196 (gnus-capitalize-newsgroup newsgroup)
4197 (gnus-newsgroup-directory-form newsgroup))
4198 "/" (int-to-string (mail-header-number headers)))
4199 gnus-article-save-directory)))
4200 (if (and last-file
4201 (string-equal (file-name-directory default)
4202 (file-name-directory last-file))
4203 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4204 default
4205 (or last-file default))))
4206
4207 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4208 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4209 If variable `gnus-use-long-file-name' is non-nil, it is
4210 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4211 (let ((default
4212 (expand-file-name
4213 (concat (if (gnus-use-long-file-name 'not-save)
4214 newsgroup
4215 (gnus-newsgroup-directory-form newsgroup))
4216 "/" (int-to-string (mail-header-number headers)))
4217 gnus-article-save-directory)))
4218 (if (and last-file
4219 (string-equal (file-name-directory default)
4220 (file-name-directory last-file))
4221 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4222 default
4223 (or last-file default))))
4224
4225 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4226 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4227 If variable `gnus-use-long-file-name' is non-nil, it is
4228 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4229 (or last-file
4230 (expand-file-name
4231 (if (gnus-use-long-file-name 'not-save)
4232 newsgroup
4233 (file-relative-name
4234 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4235 default-directory))
4236 gnus-article-save-directory)))
4237
4238 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4239 "Generate file name from sender."
4240 (let ((from (mail-header-from headers)))
4241 (expand-file-name
4242 (if (and from (string-match "\\([^ <]+\\)@" from))
4243 (match-string 1 from)
4244 "nobody")
4245 gnus-article-save-directory)))
4246
4247 (defun article-verify-x-pgp-sig ()
4248 "Verify X-PGP-Sig."
4249 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4250 (interactive)
4251 (if (gnus-buffer-live-p gnus-original-article-buffer)
4252 (let ((sig (with-current-buffer gnus-original-article-buffer
4253 (gnus-fetch-field "X-PGP-Sig")))
4254 items info headers)
4255 (when (and sig
4256 mml2015-use
4257 (mml2015-clear-verify-function))
4258 (with-temp-buffer
4259 (insert-buffer-substring gnus-original-article-buffer)
4260 (setq items (split-string sig))
4261 (message-narrow-to-head)
4262 (let ((inhibit-point-motion-hooks t)
4263 (case-fold-search t))
4264 ;; Don't verify multiple headers.
4265 (setq headers (mapconcat (lambda (header)
4266 (concat header ": "
4267 (mail-fetch-field header)
4268 "\n"))
4269 (split-string (nth 1 items) ",") "")))
4270 (delete-region (point-min) (point-max))
4271 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4272 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4273 (insert headers)
4274 (widen)
4275 (forward-line)
4276 (while (not (eobp))
4277 (if (looking-at "^-")
4278 (insert "- "))
4279 (forward-line))
4280 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4281 (insert "Version: " (car items) "\n\n")
4282 (insert (mapconcat 'identity (cddr items) "\n"))
4283 (insert "\n-----END PGP SIGNATURE-----\n")
4284 (let ((mm-security-handle (list (format "multipart/signed"))))
4285 (mml2015-clean-buffer)
4286 (let ((coding-system-for-write (or gnus-newsgroup-charset
4287 'iso-8859-1)))
4288 (funcall (mml2015-clear-verify-function)))
4289 (setq info
4290 (or (mm-handle-multipart-ctl-parameter
4291 mm-security-handle 'gnus-details)
4292 (mm-handle-multipart-ctl-parameter
4293 mm-security-handle 'gnus-info)))))
4294 (when info
4295 (let ((inhibit-read-only t) bface eface)
4296 (save-restriction
4297 (message-narrow-to-head)
4298 (goto-char (point-max))
4299 (forward-line -1)
4300 (setq bface (get-text-property (point-at-bol) 'face)
4301 eface (get-text-property (1- (point-at-eol)) 'face))
4302 (message-remove-header "X-Gnus-PGP-Verify")
4303 (if (re-search-forward "^X-PGP-Sig:" nil t)
4304 (forward-line)
4305 (goto-char (point-max)))
4306 (narrow-to-region (point) (point))
4307 (insert "X-Gnus-PGP-Verify: " info "\n")
4308 (goto-char (point-min))
4309 (forward-line)
4310 (while (not (eobp))
4311 (if (not (looking-at "^[ \t]"))
4312 (insert " "))
4313 (forward-line))
4314 ;; Do highlighting.
4315 (goto-char (point-min))
4316 (when (looking-at "\\([^:]+\\): *")
4317 (put-text-property (match-beginning 1) (1+ (match-end 1))
4318 'face bface)
4319 (put-text-property (match-end 0) (point-max)
4320 'face eface)))))))))
4321
4322 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4323
4324 (defun article-verify-cancel-lock ()
4325 "Verify Cancel-Lock header."
4326 (interactive)
4327 (if (gnus-buffer-live-p gnus-original-article-buffer)
4328 (canlock-verify gnus-original-article-buffer)))
4329
4330 (eval-and-compile
4331 (mapc
4332 (lambda (func)
4333 (let (afunc gfunc)
4334 (if (consp func)
4335 (setq afunc (car func)
4336 gfunc (cdr func))
4337 (setq afunc func
4338 gfunc (intern (format "gnus-%s" func))))
4339 (defalias gfunc
4340 (when (fboundp afunc)
4341 `(lambda (&optional interactive &rest args)
4342 ,(documentation afunc t)
4343 (interactive (list t))
4344 (with-current-buffer gnus-article-buffer
4345 (if interactive
4346 (call-interactively ',afunc)
4347 (apply ',afunc args))))))))
4348 '(article-hide-headers
4349 article-verify-x-pgp-sig
4350 article-verify-cancel-lock
4351 article-hide-boring-headers
4352 article-treat-overstrike
4353 article-treat-ansi-sequences
4354 article-fill-long-lines
4355 article-capitalize-sentences
4356 article-remove-cr
4357 article-remove-leading-whitespace
4358 article-display-x-face
4359 article-display-face
4360 article-de-quoted-unreadable
4361 article-de-base64-unreadable
4362 article-decode-HZ
4363 article-wash-html
4364 article-unsplit-urls
4365 article-hide-list-identifiers
4366 article-strip-banner
4367 article-babel
4368 article-hide-pem
4369 article-hide-signature
4370 article-strip-headers-in-body
4371 article-remove-trailing-blank-lines
4372 article-strip-leading-blank-lines
4373 article-strip-multiple-blank-lines
4374 article-strip-leading-space
4375 article-strip-trailing-space
4376 article-strip-blank-lines
4377 article-strip-all-blank-lines
4378 article-date-local
4379 article-date-english
4380 article-date-iso8601
4381 article-date-original
4382 article-treat-date
4383 article-date-ut
4384 article-decode-mime-words
4385 article-decode-charset
4386 article-decode-encoded-words
4387 article-date-user
4388 article-date-lapsed
4389 article-date-combined-lapsed
4390 article-emphasize
4391 article-treat-dumbquotes
4392 article-treat-non-ascii
4393 article-normalize-headers
4394 ;;(article-show-all . gnus-article-show-all-headers)
4395 )))
4396 \f
4397 ;;;
4398 ;;; Gnus article mode
4399 ;;;
4400
4401 (put 'gnus-article-mode 'mode-class 'special)
4402
4403 (set-keymap-parent gnus-article-mode-map widget-keymap)
4404
4405 (gnus-define-keys gnus-article-mode-map
4406 " " gnus-article-goto-next-page
4407 [?\S-\ ] gnus-article-goto-prev-page
4408 "\177" gnus-article-goto-prev-page
4409 [delete] gnus-article-goto-prev-page
4410 "\C-c^" gnus-article-refer-article
4411 "h" gnus-article-show-summary
4412 "s" gnus-article-show-summary
4413 "\C-c\C-m" gnus-article-mail
4414 "?" gnus-article-describe-briefly
4415 "<" beginning-of-buffer
4416 ">" end-of-buffer
4417 "\C-c\C-i" gnus-info-find-node
4418 "\C-c\C-b" gnus-bug
4419 "R" gnus-article-reply-with-original
4420 "F" gnus-article-followup-with-original
4421 "\C-hk" gnus-article-describe-key
4422 "\C-hc" gnus-article-describe-key-briefly
4423 "\C-hb" gnus-article-describe-bindings
4424
4425 "e" gnus-article-read-summary-keys
4426 "\C-d" gnus-article-read-summary-keys
4427 "\M-*" gnus-article-read-summary-keys
4428 "\M-#" gnus-article-read-summary-keys
4429 "\M-^" gnus-article-read-summary-keys
4430 "\M-g" gnus-article-read-summary-keys)
4431
4432 (substitute-key-definition
4433 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4434
4435 (defvar gnus-article-send-map)
4436
4437 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4438 "W" gnus-article-wide-reply-with-original)
4439 (if (featurep 'xemacs)
4440 (set-keymap-default-binding gnus-article-send-map
4441 'gnus-article-read-summary-send-keys)
4442 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4443
4444 (defun gnus-article-make-menu-bar ()
4445 (unless (boundp 'gnus-article-commands-menu)
4446 (gnus-summary-make-menu-bar))
4447 (unless (boundp 'gnus-article-article-menu)
4448 (easy-menu-define
4449 gnus-article-article-menu gnus-article-mode-map ""
4450 '("Article"
4451 ["Scroll forwards" gnus-article-goto-next-page t]
4452 ["Scroll backwards" gnus-article-goto-prev-page t]
4453 ["Show summary" gnus-article-show-summary t]
4454 ["Fetch Message-ID at point" gnus-article-refer-article t]
4455 ["Mail to address at point" gnus-article-mail t]
4456 ["Send a bug report" gnus-bug t]))
4457
4458 (easy-menu-define
4459 gnus-article-treatment-menu gnus-article-mode-map ""
4460 ;; Fixme: this should use :active (and maybe :visible).
4461 '("Treatment"
4462 ["Hide headers" gnus-article-hide-headers t]
4463 ["Hide signature" gnus-article-hide-signature t]
4464 ["Hide citation" gnus-article-hide-citation t]
4465 ["Treat overstrike" gnus-article-treat-overstrike t]
4466 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4467 ["Remove carriage return" gnus-article-remove-cr t]
4468 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4469 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4470 ["Remove base64" gnus-article-de-base64-unreadable t]
4471 ["Treat html" gnus-article-wash-html t]
4472 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4473 ["Decode HZ" gnus-article-decode-HZ t]))
4474
4475 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4476
4477 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4478
4479 (gnus-run-hooks 'gnus-article-menu-hook)))
4480
4481 (defvar bookmark-make-record-function)
4482 (defvar shr-put-image-function)
4483
4484 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4485 "Major mode for displaying an article.
4486
4487 All normal editing commands are switched off.
4488
4489 The following commands are available in addition to all summary mode
4490 commands:
4491 \\<gnus-article-mode-map>
4492 \\[gnus-article-next-page]\t Scroll the article one page forwards
4493 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4494 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4495 \\[gnus-article-show-summary]\t Display the summary buffer
4496 \\[gnus-article-mail]\t Send a reply to the address near point
4497 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4498 \\[gnus-info-find-node]\t Go to the Gnus info node"
4499 (gnus-simplify-mode-line)
4500 (make-local-variable 'minor-mode-alist)
4501 (when (gnus-visual-p 'article-menu 'menu)
4502 (gnus-article-make-menu-bar)
4503 (when gnus-summary-tool-bar-map
4504 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4505 (gnus-update-format-specifications nil 'article-mode)
4506 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4507 (set (make-local-variable 'gnus-page-broken) nil)
4508 (make-local-variable 'gnus-article-current-summary)
4509 (make-local-variable 'gnus-article-mime-handles)
4510 (make-local-variable 'gnus-article-decoded-p)
4511 (make-local-variable 'gnus-article-mime-handle-alist)
4512 (make-local-variable 'gnus-article-wash-types)
4513 (make-local-variable 'gnus-article-image-alist)
4514 (make-local-variable 'gnus-article-charset)
4515 (make-local-variable 'gnus-article-ignored-charsets)
4516 (set (make-local-variable 'bookmark-make-record-function)
4517 'gnus-summary-bookmark-make-record)
4518 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4519 ;; face.
4520 (set (make-local-variable 'nobreak-char-display) nil)
4521 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4522 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4523 (setq cursor-in-non-selected-windows nil)
4524 (gnus-set-default-directory)
4525 (buffer-disable-undo)
4526 (setq buffer-read-only t
4527 show-trailing-whitespace nil)
4528 (mm-enable-multibyte))
4529
4530 (defun gnus-article-setup-buffer ()
4531 "Initialize the article buffer."
4532 (let* ((name (if gnus-single-article-buffer "*Article*"
4533 (concat "*Article "
4534 (gnus-group-decoded-name gnus-newsgroup-name)
4535 "*")))
4536 (original
4537 (progn (string-match "\\*Article" name)
4538 (concat " *Original Article"
4539 (substring name (match-end 0))))))
4540 (setq gnus-article-buffer name)
4541 (setq gnus-original-article-buffer original)
4542 (setq gnus-article-mime-handle-alist nil)
4543 (with-current-buffer gnus-summary-buffer
4544 ;; This might be a variable local to the summary buffer.
4545 (unless gnus-single-article-buffer
4546 (setq gnus-article-buffer name)
4547 (setq gnus-original-article-buffer original)
4548 (gnus-set-global-variables)))
4549 (gnus-article-setup-highlight-words)
4550 ;; Init original article buffer.
4551 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4552 (mm-enable-multibyte)
4553 (setq major-mode 'gnus-original-article-mode)
4554 (make-local-variable 'gnus-original-article))
4555 (if (and (get-buffer name)
4556 (with-current-buffer name
4557 (if gnus-article-edit-mode
4558 (if (y-or-n-p "Article mode edit in progress; discard? ")
4559 (progn
4560 (set-buffer-modified-p nil)
4561 (gnus-kill-buffer name)
4562 (message "")
4563 nil)
4564 (error "Action aborted"))
4565 t)))
4566 (let ((summary gnus-summary-buffer))
4567 (with-current-buffer name
4568 (set (make-local-variable 'gnus-article-edit-mode) nil)
4569 (gnus-article-stop-animations)
4570 (when gnus-article-mime-handles
4571 (mm-destroy-parts gnus-article-mime-handles)
4572 (setq gnus-article-mime-handles nil))
4573 ;; Set it to nil in article-buffer!
4574 (setq gnus-article-mime-handle-alist nil)
4575 (buffer-disable-undo)
4576 (setq buffer-read-only t)
4577 (unless (derived-mode-p 'gnus-article-mode)
4578 (gnus-article-mode))
4579 (set (make-local-variable 'gnus-summary-buffer) summary)
4580 (setq truncate-lines gnus-article-truncate-lines)
4581 (current-buffer)))
4582 (let ((summary gnus-summary-buffer))
4583 (with-current-buffer (gnus-get-buffer-create name)
4584 (gnus-article-mode)
4585 (setq truncate-lines gnus-article-truncate-lines)
4586 (set (make-local-variable 'gnus-summary-buffer) summary)
4587 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4588 (when article-lapsed-timer
4589 (gnus-stop-date-timer))
4590 (when gnus-article-update-date-headers
4591 (gnus-start-date-timer gnus-article-update-date-headers))
4592 (current-buffer))))))
4593
4594 (defun gnus-article-stop-animations ()
4595 (dolist (timer (and (boundp 'timer-list)
4596 timer-list))
4597 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4598 (cancel-timer timer))))
4599
4600 (defun gnus-stop-downloads ()
4601 (when (boundp 'url-queue)
4602 (set (intern "url-queue" obarray) nil)))
4603
4604 ;; Set article window start at LINE, where LINE is the number of lines
4605 ;; from the head of the article.
4606 (defun gnus-article-set-window-start (&optional line)
4607 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4608 (when article-window
4609 (set-window-start
4610 article-window
4611 (with-current-buffer gnus-article-buffer
4612 (goto-char (point-min))
4613 (if (not line)
4614 (point-min)
4615 (gnus-message 6 "Moved to bookmark")
4616 (search-forward "\n\n" nil t)
4617 (forward-line line)
4618 (point)))))))
4619
4620 (defvar gnus-tmp-internal-hook)
4621
4622 (defun gnus-article-prepare (article &optional all-headers _header)
4623 "Prepare ARTICLE in article mode buffer.
4624 ARTICLE should either be an article number or a Message-ID.
4625 If ARTICLE is an id, HEADER should be the article headers.
4626 If ALL-HEADERS is non-nil, no headers are hidden."
4627 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4628 ;; Make sure we start in a summary buffer.
4629 (unless (derived-mode-p 'gnus-summary-mode)
4630 (set-buffer gnus-summary-buffer))
4631 (setq gnus-summary-buffer (current-buffer))
4632 (let* ((summary-buffer (current-buffer))
4633 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4634 (group gnus-newsgroup-name)
4635 result)
4636 (save-excursion
4637 (gnus-article-setup-buffer)
4638 (set-buffer gnus-article-buffer)
4639 ;; Deactivate active regions.
4640 (when (and (boundp 'transient-mark-mode)
4641 transient-mark-mode)
4642 (setq mark-active nil))
4643 (if (not (setq result (let ((inhibit-read-only t))
4644 (gnus-request-article-this-buffer
4645 article group))))
4646 ;; There is no such article.
4647 (save-excursion
4648 (when (and (numberp article)
4649 (not (memq article gnus-newsgroup-sparse)))
4650 (setq gnus-article-current
4651 (cons gnus-newsgroup-name article))
4652 (set-buffer gnus-summary-buffer)
4653 (setq gnus-current-article article)
4654 (if (and (memq article gnus-newsgroup-undownloaded)
4655 (not (gnus-online (gnus-find-method-for-group
4656 gnus-newsgroup-name))))
4657 (progn
4658 (gnus-summary-set-agent-mark article)
4659 (message "Message marked for downloading"))
4660 (gnus-summary-mark-article article gnus-canceled-mark)
4661 (unless (memq article gnus-newsgroup-sparse)
4662 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4663 (if (or (eq result 'pseudo)
4664 (eq result 'nneething))
4665 (progn
4666 (with-current-buffer summary-buffer
4667 (push article gnus-newsgroup-history)
4668 (setq gnus-last-article gnus-current-article
4669 gnus-current-article 0
4670 gnus-current-headers nil
4671 gnus-article-current nil)
4672 (if (eq result 'nneething)
4673 (gnus-configure-windows 'summary)
4674 (gnus-configure-windows 'article))
4675 (gnus-set-global-variables))
4676 (let ((gnus-article-mime-handle-alist-1
4677 gnus-article-mime-handle-alist))
4678 (gnus-set-mode-line 'article)))
4679 ;; The result from the `request' was an actual article -
4680 ;; or at least some text that is now displayed in the
4681 ;; article buffer.
4682 (when (and (numberp article)
4683 (not (eq article gnus-current-article)))
4684 ;; Seems like a new article has been selected.
4685 ;; `gnus-current-article' must be an article number.
4686 (with-current-buffer summary-buffer
4687 (push article gnus-newsgroup-history)
4688 (setq gnus-last-article gnus-current-article
4689 gnus-current-article article
4690 gnus-current-headers
4691 (gnus-summary-article-header gnus-current-article)
4692 gnus-article-current
4693 (cons gnus-newsgroup-name gnus-current-article))
4694 (unless (vectorp gnus-current-headers)
4695 (setq gnus-current-headers nil))
4696 (gnus-summary-goto-subject gnus-current-article)
4697 (when (gnus-summary-show-thread)
4698 ;; If the summary buffer really was folded, the
4699 ;; previous goto may not actually have gone to
4700 ;; the right article, but the thread root instead.
4701 ;; So we go again.
4702 (gnus-summary-goto-subject gnus-current-article))
4703 (gnus-run-hooks 'gnus-mark-article-hook)
4704 (gnus-set-mode-line 'summary)
4705 (when (gnus-visual-p 'article-highlight 'highlight)
4706 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4707 ;; Set the global newsgroup variables here.
4708 (gnus-set-global-variables)
4709 (setq gnus-have-all-headers
4710 (or all-headers gnus-show-all-headers))))
4711 (save-excursion
4712 (gnus-configure-windows 'article))
4713 (when (or (numberp article)
4714 (stringp article))
4715 (gnus-article-prepare-display)
4716 ;; Do page break.
4717 (goto-char (point-min))
4718 (when gnus-break-pages
4719 (gnus-narrow-to-page)))
4720 (let ((gnus-article-mime-handle-alist-1
4721 gnus-article-mime-handle-alist))
4722 (gnus-set-mode-line 'article))
4723 (article-goto-body)
4724 (unless (bobp)
4725 (forward-line -1))
4726 (set-window-point (get-buffer-window (current-buffer)) (point))
4727 (gnus-configure-windows 'article)
4728 (gnus-run-hooks 'gnus-article-prepare-hook)
4729 t))))))
4730
4731 (defvar gnus-mime-display-attachment-buttons-in-header)
4732
4733 ;;;###autoload
4734 (defun gnus-article-prepare-display ()
4735 "Make the current buffer look like a nice article."
4736 ;; Hooks for getting information from the article.
4737 ;; This hook must be called before being narrowed.
4738 (let ((gnus-article-buffer (current-buffer))
4739 buffer-read-only
4740 (inhibit-read-only t))
4741 (unless (derived-mode-p 'gnus-article-mode)
4742 (gnus-article-mode))
4743 (setq buffer-read-only nil
4744 gnus-article-wash-types nil
4745 gnus-article-image-alist nil)
4746 (gnus-run-hooks 'gnus-tmp-internal-hook)
4747 (when gnus-display-mime-function
4748 (funcall gnus-display-mime-function))
4749 ;; Add attachment buttons to the header.
4750 (when gnus-mime-display-attachment-buttons-in-header
4751 (gnus-mime-buttonize-attachments-in-header))))
4752
4753 ;;;
4754 ;;; Gnus Sticky Article Mode
4755 ;;;
4756
4757 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4758 "Mode for sticky articles."
4759 ;; Release bindings that won't work.
4760 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4761 gnus-sticky-article-mode-map)
4762 (substitute-key-definition 'gnus-article-refer-article 'undefined
4763 gnus-sticky-article-mode-map)
4764 (dolist (k '("e" "h" "s" "F" "R"))
4765 (define-key gnus-sticky-article-mode-map k nil))
4766 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4767 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4768 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4769 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4770
4771 (defun gnus-sticky-article (arg)
4772 "Make the current article sticky.
4773 If a prefix ARG is given, ask for a name for this sticky article buffer."
4774 (interactive "P")
4775 (gnus-summary-show-thread)
4776 (gnus-summary-select-article nil nil 'pseudo)
4777 (let (new-art-buf-name)
4778 (gnus-eval-in-buffer-window gnus-article-buffer
4779 (setq new-art-buf-name
4780 (concat
4781 "*Sticky Article: "
4782 (if arg
4783 (read-from-minibuffer "Sticky article buffer name: ")
4784 (gnus-with-article-headers
4785 (gnus-article-goto-header "subject")
4786 (setq new-art-buf-name
4787 (buffer-substring-no-properties
4788 (line-beginning-position) (line-end-position)))
4789 (goto-char (point-min))
4790 (gnus-article-goto-header "from")
4791 (setq new-art-buf-name
4792 (concat
4793 new-art-buf-name ", "
4794 (buffer-substring-no-properties
4795 (line-beginning-position) (line-end-position))))
4796 (goto-char (point-min))
4797 (gnus-article-goto-header "date")
4798 (setq new-art-buf-name
4799 (concat
4800 new-art-buf-name ", "
4801 (buffer-substring-no-properties
4802 (line-beginning-position) (line-end-position))))))
4803 "*"))
4804 (if (and (gnus-buffer-live-p new-art-buf-name)
4805 (with-current-buffer new-art-buf-name
4806 (derived-mode-p 'gnus-sticky-article-mode)))
4807 (switch-to-buffer new-art-buf-name)
4808 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4809 (gnus-sticky-article-mode))
4810 (setq gnus-article-buffer new-art-buf-name))
4811 (gnus-summary-recenter)
4812 (gnus-summary-position-point))
4813
4814 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4815 "Kill the given sticky article BUFFER.
4816 If none is given, assume the current buffer and kill it if it has
4817 `gnus-sticky-article-mode'."
4818 (interactive)
4819 (unless buffer
4820 (setq buffer (current-buffer)))
4821 (with-current-buffer buffer
4822 (when (derived-mode-p 'gnus-sticky-article-mode)
4823 (gnus-kill-buffer buffer))))
4824
4825 (defun gnus-kill-sticky-article-buffers (arg)
4826 "Kill all sticky article buffers.
4827 If a prefix ARG is given, ask for confirmation."
4828 (interactive "P")
4829 (dolist (buf (gnus-buffers))
4830 (with-current-buffer buf
4831 (when (derived-mode-p 'gnus-sticky-article-mode)
4832 (if (not arg)
4833 (gnus-kill-buffer buf)
4834 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4835 (gnus-kill-buffer buf)))))))
4836
4837 ;;;
4838 ;;; Gnus MIME viewing functions
4839 ;;;
4840
4841 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4842 "Format of the MIME buttons.
4843
4844 Valid specifiers include:
4845 %t The MIME type
4846 %T MIME type, along with additional info
4847 %n The `name' parameter
4848 %d The description, if any
4849 %l The length of the encoded part
4850 %p The part identifier number
4851 %e Dots if the part isn't displayed
4852
4853 General format specifiers can also be used. See Info node
4854 `(gnus)Formatting Variables'.")
4855
4856 (defvar gnus-tmp-type)
4857 (defvar gnus-tmp-type-long)
4858 (defvar gnus-tmp-name)
4859 (defvar gnus-tmp-description)
4860 (defvar gnus-tmp-id)
4861 (defvar gnus-tmp-length)
4862 (defvar gnus-tmp-dots)
4863 (defvar gnus-tmp-info)
4864 (defvar gnus-tmp-pressed-details)
4865
4866 (defvar gnus-mime-button-line-format-alist
4867 '((?t gnus-tmp-type ?s)
4868 (?T gnus-tmp-type-long ?s)
4869 (?n gnus-tmp-name ?s)
4870 (?d gnus-tmp-description ?s)
4871 (?p gnus-tmp-id ?s)
4872 (?l gnus-tmp-length ?d)
4873 (?e gnus-tmp-dots ?s)))
4874
4875 (defvar gnus-mime-button-commands
4876 '((gnus-article-press-button "\r" "Toggle Display")
4877 (gnus-mime-view-part "v" "View Interactively...")
4878 (gnus-mime-view-part-as-type "t" "View As Type...")
4879 (gnus-mime-view-part-as-charset "C" "View As charset...")
4880 (gnus-mime-save-part "o" "Save...")
4881 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4882 (gnus-mime-replace-part "r" "Replace part")
4883 (gnus-mime-delete-part "d" "Delete part")
4884 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4885 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4886 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4887 (gnus-mime-view-part-externally "e" "View Externally")
4888 (gnus-mime-print-part "p" "Print")
4889 (gnus-mime-pipe-part "|" "Pipe To Command...")
4890 (gnus-mime-action-on-part "." "Take action on the part...")))
4891
4892 (defun gnus-article-mime-part-status ()
4893 (if gnus-article-mime-handle-alist-1
4894 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4895 " (1 part)"
4896 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4897 ""))
4898
4899 (defvar gnus-mime-button-map
4900 (let ((map (make-sparse-keymap)))
4901 (define-key map gnus-mouse-2 'gnus-article-push-button)
4902 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4903 (dolist (c gnus-mime-button-commands)
4904 (define-key map (cadr c) (car c)))
4905 map))
4906
4907 (easy-menu-define
4908 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4909 `("MIME Part"
4910 ,@(mapcar (lambda (c)
4911 (vector (caddr c) (car c) :active t))
4912 gnus-mime-button-commands)))
4913
4914 (defvar gnus-url-button-commands
4915 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4916
4917 (defvar gnus-url-button-map
4918 (let ((map (make-sparse-keymap)))
4919 (dolist (c gnus-url-button-commands)
4920 (define-key map (cadr c) (car c)))
4921 map))
4922
4923 (easy-menu-define
4924 gnus-url-button-menu gnus-url-button-map "URL button menu."
4925 `("Url Button"
4926 ,@(mapcar (lambda (c)
4927 (vector (caddr c) (car c) :active t))
4928 gnus-url-button-commands)))
4929
4930 (defmacro gnus-bind-safe-url-regexp (&rest body)
4931 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4932 `(let ((mm-w3m-safe-url-regexp
4933 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4934 (gnus-buffer-live-p
4935 gnus-article-current-summary))
4936 (with-current-buffer gnus-article-current-summary
4937 gnus-newsgroup-name)
4938 gnus-newsgroup-name)))
4939 (if (cond ((not group)
4940 ;; Maybe we're in a mml-preview buffer
4941 ;; and no group is selected.
4942 t)
4943 ((stringp gnus-safe-html-newsgroups)
4944 (string-match gnus-safe-html-newsgroups group))
4945 ((consp gnus-safe-html-newsgroups)
4946 (member group gnus-safe-html-newsgroups)))
4947 nil
4948 mm-w3m-safe-url-regexp))))
4949 ,@body))
4950
4951 (defun gnus-mime-button-menu (event prefix)
4952 "Construct a context-sensitive menu of MIME commands."
4953 (interactive "e\nP")
4954 (save-window-excursion
4955 (let ((pos (event-start event)))
4956 (select-window (posn-window pos))
4957 (goto-char (posn-point pos))
4958 (gnus-article-check-buffer)
4959 (popup-menu gnus-mime-button-menu nil prefix))))
4960
4961 (defun gnus-mime-view-all-parts (&optional handles)
4962 "View all the MIME parts."
4963 (interactive)
4964 (with-current-buffer gnus-article-buffer
4965 (let ((handles (or handles gnus-article-mime-handles))
4966 (mail-parse-charset gnus-newsgroup-charset)
4967 (mail-parse-ignored-charsets
4968 (with-current-buffer gnus-summary-buffer
4969 gnus-newsgroup-ignored-charsets)))
4970 (when handles
4971 (mm-remove-parts handles)
4972 (goto-char (point-min))
4973 (or (search-forward "\n\n") (goto-char (point-max)))
4974 (let ((inhibit-read-only t))
4975 (delete-region (point) (point-max))
4976 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4977
4978 (defun gnus-article-jump-to-part (n)
4979 "Jump to MIME part N."
4980 (interactive "P")
4981 (let ((parts (with-current-buffer gnus-article-buffer
4982 (length gnus-article-mime-handle-alist))))
4983 (when (zerop parts)
4984 (error "No such part"))
4985 (pop-to-buffer gnus-article-buffer)
4986 (or n
4987 (setq n (if (= parts 1)
4988 1
4989 (read-number (format "Jump to part (1..%s): " parts)))))
4990 (unless (and (integerp n) (<= n parts) (>= n 1))
4991 (setq n
4992 (progn
4993 (gnus-message 7 "Invalid part `%s', using %s instead."
4994 n parts)
4995 parts)))
4996 (gnus-message 9 "Jumping to part %s." n)
4997 (cond ((>= gnus-auto-select-part 1)
4998 (while (and (<= n parts)
4999 (not (gnus-article-goto-part n)))
5000 (setq n (1+ n))))
5001 ((< gnus-auto-select-part 0)
5002 (while (and (>= n 1)
5003 (not (gnus-article-goto-part n)))
5004 (setq n (1- n))))
5005 (t
5006 (gnus-article-goto-part n)))))
5007
5008 (defvar gnus-mime-buttonized-part-id nil
5009 "ID of a mime part that should be buttonized.
5010 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5011
5012 (eval-when-compile
5013 (defsubst gnus-article-edit-part (handles &optional current-id)
5014 "Edit an article in order to delete a mime part.
5015 This function is exclusively used by `gnus-mime-save-part-and-strip'
5016 and `gnus-mime-delete-part', and not provided at run-time normally."
5017 (gnus-article-edit-article
5018 `(lambda ()
5019 (buffer-disable-undo)
5020 (let ((mail-parse-charset (or gnus-article-charset
5021 ',gnus-newsgroup-charset))
5022 (mail-parse-ignored-charsets
5023 (or gnus-article-ignored-charsets
5024 ',gnus-newsgroup-ignored-charsets))
5025 (mbl mml-buffer-list))
5026 (setq mml-buffer-list nil)
5027 ;; A new text must be inserted before deleting existing ones
5028 ;; at the end so as not to move existing markers of which
5029 ;; the insertion type is t.
5030 (delete-region
5031 (point-min)
5032 (prog1
5033 (goto-char (point-max))
5034 (insert-buffer-substring gnus-original-article-buffer)))
5035 (mime-to-mml ',handles)
5036 (setq gnus-article-mime-handles nil)
5037 (let ((mbl1 mml-buffer-list))
5038 (setq mml-buffer-list mbl)
5039 (set (make-local-variable 'mml-buffer-list) mbl1))
5040 (gnus-make-local-hook 'kill-buffer-hook)
5041 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5042 `(lambda (no-highlight)
5043 (let ((mail-parse-charset (or gnus-article-charset
5044 ',gnus-newsgroup-charset))
5045 (message-options message-options)
5046 (message-options-set-recipient)
5047 (mail-parse-ignored-charsets
5048 (or gnus-article-ignored-charsets
5049 ',gnus-newsgroup-ignored-charsets)))
5050 (mml-to-mime)
5051 (mml-destroy-buffers)
5052 (remove-hook 'kill-buffer-hook
5053 'mml-destroy-buffers t)
5054 (kill-local-variable 'mml-buffer-list))
5055 (gnus-summary-edit-article-done
5056 ,(or (mail-header-references gnus-current-headers) "")
5057 ,(gnus-group-read-only-p)
5058 ,gnus-summary-buffer no-highlight))
5059 t)
5060 ;; Force buttonizing this part.
5061 (let ((gnus-mime-buttonized-part-id current-id))
5062 (gnus-article-edit-done))
5063 (gnus-configure-windows 'article)
5064 (sit-for 0)
5065 (when (and current-id (integerp gnus-auto-select-part))
5066 (gnus-article-jump-to-part
5067 (min (max (+ current-id gnus-auto-select-part) 1)
5068 (with-current-buffer gnus-article-buffer
5069 (length gnus-article-mime-handle-alist)))))))
5070
5071 (defun gnus-mime-replace-part (file)
5072 "Replace MIME part under point with an external body."
5073 ;; Useful if file has already been saved to disk
5074 (interactive
5075 (list
5076 (read-file-name "Replace MIME part with file: "
5077 (or mm-default-directory default-directory)
5078 nil nil)))
5079 (gnus-mime-save-part-and-strip file))
5080
5081 (defun gnus-mime-save-part-and-strip (&optional file)
5082 "Save the MIME part under point then replace it with an external body.
5083 If FILE is given, use it for the external part."
5084 (interactive)
5085 (gnus-article-check-buffer)
5086 (when (gnus-group-read-only-p)
5087 (error "The current group does not support deleting of parts"))
5088 (when (mm-complicated-handles gnus-article-mime-handles)
5089 (error "\
5090 The current article has a complicated MIME structure, giving up..."))
5091 (let* ((data (get-text-property (point) 'gnus-data))
5092 (id (get-text-property (point) 'gnus-part))
5093 (handles gnus-article-mime-handles))
5094 (unless file
5095 (setq file
5096 (and data (mm-save-part data "Delete MIME part and save to: "))))
5097 (when file
5098 (with-current-buffer (mm-handle-buffer data)
5099 (erase-buffer)
5100 (insert "Content-Type: " (mm-handle-media-type data))
5101 (mml-insert-parameter-string (cdr (mm-handle-type data))
5102 '(charset))
5103 ;; Add a filename for the sake of saving the part again.
5104 (mml-insert-parameter
5105 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5106 (insert "\n")
5107 (insert "Content-ID: " (message-make-message-id) "\n")
5108 (insert "Content-Transfer-Encoding: binary\n")
5109 (insert "\n"))
5110 (setcdr data
5111 (cdr (mm-make-handle nil
5112 `("message/external-body"
5113 (access-type . "LOCAL-FILE")
5114 (name . ,file)))))
5115 ;; (set-buffer gnus-summary-buffer)
5116 (gnus-article-edit-part handles id))))
5117
5118 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5119 ;; parts...>') but with stripping would be nice.
5120
5121 (defun gnus-mime-delete-part ()
5122 "Delete the MIME part under point.
5123 Replace it with some information about the removed part."
5124 (interactive)
5125 (gnus-article-check-buffer)
5126 (when (gnus-group-read-only-p)
5127 (error "The current group does not support deleting of parts"))
5128 (when (mm-complicated-handles gnus-article-mime-handles)
5129 (error "\
5130 The current article has a complicated MIME structure, giving up..."))
5131 (when (or gnus-expert-user
5132 (gnus-yes-or-no-p "\
5133 Deleting parts may malfunction or destroy the article; continue? "))
5134 (let* ((data (get-text-property (point) 'gnus-data))
5135 (id (get-text-property (point) 'gnus-part))
5136 (handles gnus-article-mime-handles)
5137 (description
5138 (let ((desc (mm-handle-description data)))
5139 (when desc
5140 (mail-decode-encoded-word-string desc))))
5141 (filename (or (mm-handle-filename data) "(none)"))
5142 (type (mm-handle-media-type data)))
5143 (unless data
5144 (error "No MIME part under point"))
5145 (with-current-buffer (mm-handle-buffer data)
5146 (let ((bsize (buffer-size)))
5147 (erase-buffer)
5148 (insert
5149 (concat
5150 ",----\n"
5151 "| The following attachment has been deleted:\n"
5152 "|\n"
5153 "| Type: " type "\n"
5154 "| Filename: " filename "\n"
5155 "| Size (encoded): " (format "%s byte%s\n"
5156 bsize (if (= bsize 1)
5157 ""
5158 "s"))
5159 (when description
5160 (concat "| Description: " description "\n"))
5161 "`----\n"))
5162 (setcdr data
5163 (cdr (mm-make-handle
5164 nil `("text/plain" (charset . gnus-decoded)) nil nil
5165 (list "attachment")
5166 (format "Deleted attachment (%s bytes)" bsize))))))
5167 ;; (set-buffer gnus-summary-buffer)
5168 (gnus-article-edit-part handles id))))
5169
5170 (defun gnus-mime-save-part ()
5171 "Save the MIME part under point."
5172 (interactive)
5173 (gnus-article-check-buffer)
5174 (let ((data (get-text-property (point) 'gnus-data)))
5175 (when data
5176 (mm-save-part data))))
5177
5178 (defun gnus-mime-pipe-part (&optional cmd)
5179 "Pipe the MIME part under point to a process.
5180 Use CMD as the process."
5181 (interactive)
5182 (gnus-article-check-buffer)
5183 (let ((data (get-text-property (point) 'gnus-data)))
5184 (when data
5185 (mm-pipe-part data cmd))))
5186
5187 (defun gnus-mime-view-part ()
5188 "Interactively choose a viewing method for the MIME part under point."
5189 (interactive)
5190 (gnus-article-check-buffer)
5191 (let ((data (get-text-property (point) 'gnus-data)))
5192 (when data
5193 (setq gnus-article-mime-handles
5194 (mm-merge-handles
5195 gnus-article-mime-handles (setq data (copy-sequence data))))
5196 (mm-interactively-view-part data))))
5197
5198 (defun gnus-mime-view-part-as-type-internal ()
5199 (gnus-article-check-buffer)
5200 (let* ((handle (get-text-property (point) 'gnus-data))
5201 (name (or
5202 ;; Content-Type: foo/bar; name=...
5203 (mail-content-type-get (mm-handle-type handle) 'name)
5204 ;; Content-Disposition: attachment; filename=...
5205 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5206 (def-type (and name (mm-default-file-encoding name))))
5207 (or (and def-type (cons def-type 0))
5208 (and handle
5209 (equal (mm-handle-media-supertype handle) "text")
5210 '("text/plain" . 0))
5211 '("application/octet-stream" . 0))))
5212
5213 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5214 "Choose a MIME media type, and view the part as such.
5215 If non-nil, PRED is a predicate to use during completion to limit the
5216 available media-types."
5217 (interactive)
5218 (unless mime-type
5219 (setq mime-type
5220 (let ((default (gnus-mime-view-part-as-type-internal)))
5221 (gnus-completing-read
5222 "View as MIME type"
5223 (if pred
5224 (gnus-remove-if-not pred (mailcap-mime-types))
5225 (mailcap-mime-types))
5226 nil nil nil
5227 (car default)))))
5228 (gnus-article-check-buffer)
5229 (let ((handle (get-text-property (point) 'gnus-data)))
5230 (when handle
5231 (when (equal (mm-handle-media-type handle) "message/external-body")
5232 (unless (mm-handle-cache handle)
5233 (mm-extern-cache-contents handle))
5234 (setq handle (mm-handle-cache handle)))
5235 (setq handle
5236 (mm-make-handle (mm-handle-buffer handle)
5237 (cons mime-type (cdr (mm-handle-type handle)))
5238 (mm-handle-encoding handle)
5239 (mm-handle-undisplayer handle)
5240 (mm-handle-disposition handle)
5241 (mm-handle-description handle)
5242 nil
5243 (mm-handle-id handle)))
5244 (setq gnus-article-mime-handles
5245 (mm-merge-handles gnus-article-mime-handles handle))
5246 (when (mm-handle-displayed-p handle)
5247 (mm-remove-part handle))
5248 (gnus-mm-display-part handle))))
5249
5250 (defun gnus-mime-copy-part (&optional handle arg)
5251 "Put the MIME part under point into a new buffer.
5252 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5253 are decompressed."
5254 (interactive (list nil current-prefix-arg))
5255 (gnus-article-check-buffer)
5256 (unless handle
5257 (setq handle (get-text-property (point) 'gnus-data)))
5258 (when handle
5259 (let ((filename (mm-handle-filename handle))
5260 contents dont-decode charset coding-system)
5261 (mm-with-unibyte-buffer
5262 (mm-insert-part handle)
5263 (setq contents (or (condition-case nil
5264 (mm-decompress-buffer filename nil 'sig)
5265 (error
5266 (setq dont-decode t)
5267 nil))
5268 (buffer-string))))
5269 (setq filename (cond (filename (file-name-nondirectory filename))
5270 (dont-decode "*raw data*")
5271 (t "*decoded*")))
5272 (cond
5273 (dont-decode)
5274 ((not arg)
5275 (unless (setq charset (mail-content-type-get
5276 (mm-handle-type handle) 'charset))
5277 (unless (setq coding-system (mm-with-unibyte-buffer
5278 (insert contents)
5279 (mm-find-buffer-file-coding-system)))
5280 (setq charset gnus-newsgroup-charset))))
5281 ((numberp arg)
5282 (setq charset (or (cdr (assq arg
5283 gnus-summary-show-article-charset-alist))
5284 (mm-read-coding-system "Charset: ")))))
5285 (switch-to-buffer (generate-new-buffer filename))
5286 (if (or coding-system
5287 (and charset
5288 (setq coding-system (mm-charset-to-coding-system
5289 charset nil t))
5290 (not (eq coding-system 'ascii))))
5291 (progn
5292 (mm-enable-multibyte)
5293 (insert (mm-decode-coding-string contents coding-system))
5294 (setq buffer-file-coding-system
5295 (if (boundp 'last-coding-system-used)
5296 (symbol-value 'last-coding-system-used)
5297 coding-system)))
5298 (mm-disable-multibyte)
5299 (insert contents)
5300 (setq buffer-file-coding-system mm-binary-coding-system))
5301 ;; We do it this way to make `normal-mode' set the appropriate mode.
5302 (unwind-protect
5303 (progn
5304 (setq buffer-file-name (expand-file-name filename))
5305 (normal-mode))
5306 (setq buffer-file-name nil))
5307 (goto-char (point-min)))))
5308
5309 (defun gnus-mime-print-part (&optional handle filename)
5310 "Print the MIME part under point."
5311 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5312 (gnus-article-check-buffer)
5313 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5314 (contents (and handle (mm-get-part handle)))
5315 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5316 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5317 (when contents
5318 (if printer
5319 (unwind-protect
5320 (progn
5321 (mm-save-part-to-file handle file)
5322 (call-process shell-file-name nil
5323 (generate-new-buffer " *mm*")
5324 nil
5325 shell-command-switch
5326 (mm-mailcap-command
5327 printer file (mm-handle-type handle))))
5328 (delete-file file))
5329 (with-temp-buffer
5330 (insert contents)
5331 (gnus-print-buffer))
5332 (ps-despool filename)))))
5333
5334 (defun gnus-mime-inline-part (&optional handle arg)
5335 "Insert the MIME part under point into the current buffer.
5336 Compressed files like .gz and .bz2 are decompressed."
5337 (interactive (list nil current-prefix-arg))
5338 (gnus-article-check-buffer)
5339 (let* ((inhibit-read-only t)
5340 (b (point))
5341 (btn ;; position where the MIME button exists
5342 (if handle
5343 (if (eq handle (get-text-property b 'gnus-data))
5344 b
5345 (article-goto-body)
5346 (or (text-property-any (point) (point-max) 'gnus-data handle)
5347 (text-property-any (point-min) (point) 'gnus-data handle)))
5348 (setq handle (get-text-property b 'gnus-data))
5349 b))
5350 start)
5351 (when handle
5352 (when (= b (prog1
5353 btn
5354 (setq start (next-single-property-change btn 'gnus-data
5355 nil (point-max))
5356 btn (previous-single-property-change start
5357 'gnus-data))))
5358 (setq b btn))
5359 (if (and (not arg) (mm-handle-undisplayer handle))
5360 (progn
5361 (setq b (copy-marker b)
5362 btn (copy-marker btn))
5363 (mm-remove-part handle))
5364 (cond
5365 ((not arg) nil)
5366 ((numberp arg)
5367 (if (mm-handle-undisplayer handle)
5368 (mm-remove-part handle)))
5369 ((mm-handle-undisplayer handle)
5370 (mm-remove-part handle)))
5371 (goto-char start)
5372 (unless (bolp)
5373 ;; This is a header button.
5374 (forward-line 1))
5375 (mm-display-inline handle))
5376 ;; Toggle the button appearance between `[button]...' and `[button]'.
5377 (when (markerp btn)
5378 (setq btn (prog1 (marker-position btn)
5379 (set-marker btn nil))))
5380 (goto-char btn)
5381 (let ((displayed-p (mm-handle-displayed-p handle)))
5382 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5383 (list displayed-p))
5384 (if (featurep 'emacs)
5385 (delete-region
5386 (point)
5387 (next-single-property-change (point) 'gnus-data nil (point-max)))
5388 (let* ((end (next-single-property-change (point) 'gnus-data))
5389 (annots (annotations-at (or end (point-max)))))
5390 (delete-region (point)
5391 (if end
5392 (if annots (1+ end) end)
5393 (point-max)))
5394 (dolist (annot annots)
5395 (set-extent-endpoints annot (point) (point)))))
5396 (setq start (point))
5397 (if (search-backward "\n\n" nil t)
5398 (progn
5399 (goto-char start)
5400 (unless (or displayed-p (eolp))
5401 ;; Add extra newline.
5402 (insert (propertize (buffer-substring (1- start) start)
5403 'gnus-undeletable t))))
5404 ;; We're in the article header.
5405 (delete-char -1)
5406 (dolist (ovl (overlays-in btn (point)))
5407 (overlay-put ovl 'gnus-button-attachment-extra t)
5408 (overlay-put ovl 'face nil))
5409 (save-restriction
5410 (message-narrow-to-field)
5411 (let ((gnus-treatment-function-alist
5412 '((gnus-treat-highlight-headers
5413 gnus-article-highlight-headers))))
5414 (gnus-treat-article 'head)))))
5415 (when (markerp b)
5416 (setq b (prog1 (marker-position b)
5417 (set-marker b nil))))
5418 (goto-char b))))
5419
5420 (defun gnus-mime-set-charset-parameters (handle charset)
5421 "Set CHARSET to parameters in HANDLE.
5422 CHARSET may either be a string or a symbol."
5423 (unless (stringp charset)
5424 (setq charset (symbol-name charset)))
5425 (if (stringp (car handle))
5426 (dolist (h (cdr handle))
5427 (gnus-mime-set-charset-parameters h charset))
5428 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5429 "message/external-body")
5430 (progn
5431 (unless (mm-handle-cache handle)
5432 (mm-extern-cache-contents handle))
5433 (mm-handle-cache handle))
5434 handle)))
5435 (param (assq 'charset (cdr type))))
5436 (if param
5437 (setcdr param charset)
5438 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5439
5440 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5441 "Insert the MIME part under point into the current buffer using the
5442 specified charset."
5443 (interactive (list nil current-prefix-arg))
5444 (gnus-article-check-buffer)
5445 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5446 (fun (get-text-property (point) 'gnus-callback))
5447 (gnus-newsgroup-ignored-charsets 'gnus-all)
5448 charset form preferred parts)
5449 (when handle
5450 (when (prog1
5451 (and fun
5452 (setq charset
5453 (or (cdr (assq
5454 arg
5455 gnus-summary-show-article-charset-alist))
5456 (mm-read-coding-system "Charset: "))))
5457 (if (mm-handle-undisplayer handle)
5458 (mm-remove-part handle)))
5459 (gnus-mime-set-charset-parameters handle charset)
5460 (when (and (consp (setq form (cdr-safe fun)))
5461 (setq form (ignore-errors
5462 (assq 'gnus-mime-display-alternative form)))
5463 (setq preferred (caddr form))
5464 (progn
5465 (when (eq (car preferred) 'quote)
5466 (setq preferred (cadr preferred)))
5467 (not (equal preferred
5468 (get-text-property (point) 'gnus-data))))
5469 (setq parts (get-text-property (point) 'gnus-part))
5470 (setq parts (cdr (assq parts
5471 gnus-article-mime-handle-alist)))
5472 (equal (mm-handle-media-type parts) "multipart/alternative")
5473 (setq parts (reverse (cdr parts))))
5474 (setcar (cddr form)
5475 (list 'quote (or (cadr (member preferred parts))
5476 (car parts)))))
5477 (funcall fun handle)))))
5478
5479 (defun gnus-mime-view-part-externally (&optional handle)
5480 "View the MIME part under point with an external viewer."
5481 (interactive)
5482 (gnus-article-check-buffer)
5483 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5484 (mm-inlined-types nil)
5485 (mail-parse-charset gnus-newsgroup-charset)
5486 (mail-parse-ignored-charsets
5487 (with-current-buffer gnus-summary-buffer
5488 gnus-newsgroup-ignored-charsets))
5489 (type (mm-handle-media-type handle))
5490 (method (mailcap-mime-info type))
5491 (mm-enable-external t))
5492 (if (not (stringp method))
5493 (gnus-mime-view-part-as-type
5494 nil (lambda (type) (stringp (mailcap-mime-info type))))
5495 (when handle
5496 (mm-display-part handle nil t)))))
5497
5498 (defun gnus-mime-view-part-internally (&optional handle)
5499 "View the MIME part under point with an internal viewer.
5500 If no internal viewer is available, use an external viewer."
5501 (interactive)
5502 (gnus-article-check-buffer)
5503 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5504 (mm-inlined-types '(".*"))
5505 (mm-inline-large-images t)
5506 (mail-parse-charset gnus-newsgroup-charset)
5507 (mail-parse-ignored-charsets
5508 (with-current-buffer gnus-summary-buffer
5509 gnus-newsgroup-ignored-charsets))
5510 (inhibit-read-only t))
5511 (if (not (mm-inlinable-p handle))
5512 (gnus-mime-view-part-as-type
5513 nil (lambda (type) (mm-inlinable-p handle type)))
5514 (when handle
5515 (gnus-bind-safe-url-regexp
5516 (mm-display-part handle nil t))))))
5517
5518 (defun gnus-mime-action-on-part (&optional action)
5519 "Do something with the MIME attachment at \(point\)."
5520 (interactive
5521 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5522 (gnus-article-check-buffer)
5523 (let ((action-pair (assoc action gnus-mime-action-alist)))
5524 (if action-pair
5525 (funcall (cdr action-pair)))))
5526
5527 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5528 "Call FUNCTION on MIME part N.
5529 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5530 If INTERACTIVE, call FUNCTION interactively."
5531 (let (window frame)
5532 ;; Check whether the article is displayed.
5533 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5534 (setq window (get-buffer-window gnus-article-buffer t))
5535 (frame-visible-p (setq frame (window-frame window))))
5536 (error "No article is displayed"))
5537 (with-current-buffer gnus-article-buffer
5538 ;; Check whether the article displays the right contents.
5539 (unless (with-current-buffer gnus-summary-buffer
5540 (eq gnus-current-article (gnus-summary-article-number)))
5541 (error "You should select the right article first"))
5542 (if n
5543 (setq n (prefix-numeric-value n))
5544 (let ((pt (point)))
5545 (setq n (or (get-text-property pt 'gnus-part)
5546 (and (not (bobp))
5547 (get-text-property (1- pt) 'gnus-part))
5548 (get-text-property (prog2
5549 (forward-line 1)
5550 (point)
5551 (goto-char pt))
5552 'gnus-part)
5553 (get-text-property
5554 (or (and (setq pt (previous-single-property-change
5555 pt 'gnus-part))
5556 (1- pt))
5557 (next-single-property-change (point) 'gnus-part)
5558 (point))
5559 'gnus-part)
5560 1))))
5561 ;; Check whether the specified part exists.
5562 (when (> n (length gnus-article-mime-handle-alist))
5563 (error "No such part")))
5564 (unless
5565 (progn
5566 ;; To select the window is needed so that the cursor
5567 ;; might be visible on the MIME button.
5568 (select-window (prog1
5569 window
5570 (setq window (selected-window))
5571 ;; Article may be displayed in the other frame.
5572 (gnus-select-frame-set-input-focus
5573 (prog1
5574 frame
5575 (setq frame (selected-frame))))))
5576 (when (gnus-article-goto-part n)
5577 ;; We point the cursor and the arrow at the MIME button
5578 ;; when the `function' prompt the user for something.
5579 (unless (and (pos-visible-in-window-p)
5580 (> (count-lines (point) (window-end))
5581 (/ (1- (window-height)) 3)))
5582 (recenter (/ (1- (window-height)) 3)))
5583 (let ((cursor-in-non-selected-windows t)
5584 (overlay-arrow-string "=>")
5585 (overlay-arrow-position (point-marker)))
5586 (unwind-protect
5587 (cond
5588 ((and no-handle interactive)
5589 (call-interactively function))
5590 (no-handle
5591 (funcall function))
5592 (interactive
5593 (call-interactively
5594 function (get-text-property (point) 'gnus-data)))
5595 (t
5596 (funcall function
5597 (get-text-property (point) 'gnus-data))))
5598 (set-marker overlay-arrow-position nil)
5599 (unless gnus-auto-select-part
5600 (gnus-select-frame-set-input-focus frame)
5601 (select-window window))))
5602 t))
5603 (if gnus-inhibit-mime-unbuttonizing
5604 ;; This is the default though the program shouldn't reach here.
5605 (error "No such part")
5606 ;; The part which doesn't have the MIME button is selected.
5607 ;; So, we display all the buttons and redo it.
5608 (let ((gnus-inhibit-mime-unbuttonizing t))
5609 (gnus-summary-show-article)
5610 (gnus-article-part-wrapper n function no-handle))))))
5611
5612 (defun gnus-article-pipe-part (n)
5613 "Pipe MIME part N, which is the numerical prefix."
5614 (interactive "P")
5615 (gnus-article-part-wrapper n 'mm-pipe-part))
5616
5617 (defun gnus-article-save-part (n)
5618 "Save MIME part N, which is the numerical prefix."
5619 (interactive "P")
5620 (gnus-article-part-wrapper n 'mm-save-part))
5621
5622 (defun gnus-article-interactively-view-part (n)
5623 "View MIME part N interactively, which is the numerical prefix."
5624 (interactive "P")
5625 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5626
5627 (defun gnus-article-copy-part (n)
5628 "Copy MIME part N, which is the numerical prefix."
5629 (interactive "P")
5630 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5631
5632 (defun gnus-article-view-part-as-charset (n)
5633 "View MIME part N using a specified charset.
5634 N is the numerical prefix."
5635 (interactive "P")
5636 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5637
5638 (defun gnus-article-view-part-externally (n)
5639 "View MIME part N externally, which is the numerical prefix."
5640 (interactive "P")
5641 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5642
5643 (defun gnus-article-inline-part (n)
5644 "Inline MIME part N, which is the numerical prefix."
5645 (interactive "P")
5646 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5647
5648 (defun gnus-article-save-part-and-strip (n)
5649 "Save MIME part N and replace it with an external body.
5650 N is the numerical prefix."
5651 (interactive "P")
5652 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5653
5654 (defun gnus-article-replace-part (n)
5655 "Replace MIME part N with an external body.
5656 N is the numerical prefix."
5657 (interactive "P")
5658 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5659
5660 (defun gnus-article-delete-part (n)
5661 "Delete MIME part N and add some information about the removed part.
5662 N is the numerical prefix."
5663 (interactive "P")
5664 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5665
5666 (defun gnus-article-view-part-as-type (n)
5667 "Choose a MIME media type, and view part N as such.
5668 N is the numerical prefix."
5669 (interactive "P")
5670 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5671
5672 (defun gnus-article-mime-match-handle-first (condition)
5673 (if condition
5674 (let (n)
5675 (dolist (ihandle gnus-article-mime-handle-alist)
5676 (if (and (cond
5677 ((functionp condition)
5678 (funcall condition (cdr ihandle)))
5679 ((eq condition 'undisplayed)
5680 (not (or (mm-handle-undisplayer (cdr ihandle))
5681 (equal (mm-handle-media-type (cdr ihandle))
5682 "multipart/alternative"))))
5683 ((eq condition 'undisplayed-alternative)
5684 (not (mm-handle-undisplayer (cdr ihandle))))
5685 (t t))
5686 (gnus-article-goto-part (car ihandle))
5687 (or (not n) (< (car ihandle) n)))
5688 (setq n (car ihandle))))
5689 (or n 1))
5690 1))
5691
5692 (defun gnus-article-view-part (&optional n)
5693 "View MIME part N, which is the numerical prefix.
5694 If the part is already shown, hide the part. If N is nil, view
5695 all parts."
5696 (interactive "P")
5697 (with-current-buffer gnus-article-buffer
5698 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5699 gnus-article-mime-match-handle-function)))
5700 (when (> n (length gnus-article-mime-handle-alist))
5701 (error "No such part"))
5702 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5703 (when (gnus-article-goto-part n)
5704 (if (equal (car handle) "multipart/alternative")
5705 (progn
5706 (beginning-of-line) ;; Make it toggle subparts
5707 (gnus-article-press-button))
5708 (when (eq (gnus-mm-display-part handle) 'internal)
5709 (gnus-set-window-start)))))))
5710
5711 (defsubst gnus-article-mime-total-parts ()
5712 (if (bufferp (car gnus-article-mime-handles))
5713 1 ;; single part
5714 (1- (length gnus-article-mime-handles))))
5715
5716 (defun gnus-mm-display-part (handle)
5717 "Display HANDLE and fix MIME button."
5718 (let ((id (get-text-property (point) 'gnus-part))
5719 (point (point))
5720 (inhibit-read-only t)
5721 (window (selected-window))
5722 (mail-parse-charset gnus-newsgroup-charset)
5723 (mail-parse-ignored-charsets
5724 (if (gnus-buffer-live-p gnus-summary-buffer)
5725 (with-current-buffer gnus-summary-buffer
5726 gnus-newsgroup-ignored-charsets)
5727 nil))
5728 start retval)
5729 (unwind-protect
5730 (progn
5731 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5732 (when win
5733 (select-window win)
5734 (goto-char point)))
5735 (setq start (next-single-property-change point 'gnus-data
5736 nil (point-max))
5737 point (previous-single-property-change start 'gnus-data))
5738 (if (mm-handle-displayed-p handle)
5739 ;; This will remove the part.
5740 (setq point (copy-marker point)
5741 retval (mm-display-part handle))
5742 (let ((part (or (and (mm-inlinable-p handle)
5743 (mm-inlined-p handle)
5744 t)
5745 (with-temp-buffer
5746 (gnus-bind-safe-url-regexp
5747 (setq retval (mm-display-part handle)))
5748 (unless (zerop (buffer-size))
5749 (buffer-string))))))
5750 (goto-char start)
5751 (unless (bolp)
5752 ;; This is a header button.
5753 (forward-line 1))
5754 (cond ((stringp part)
5755 (save-restriction
5756 (narrow-to-region (point)
5757 (progn
5758 (insert part)
5759 (unless (bolp) (insert "\n"))
5760 (point)))
5761 (gnus-treat-article nil id
5762 (gnus-article-mime-total-parts)
5763 (mm-handle-media-type handle))
5764 (mm-handle-set-undisplayer
5765 handle
5766 `(lambda ()
5767 (let ((inhibit-read-only t))
5768 (delete-region ,(copy-marker (point-min) t)
5769 ,(point-max-marker)))))))
5770 (part
5771 (mm-display-inline handle))))))
5772 (when (markerp point)
5773 (setq point (prog1 (marker-position point)
5774 (set-marker point nil))))
5775 (goto-char point)
5776 ;; Toggle the button appearance between `[button]...' and `[button]'.
5777 (let ((displayed-p (mm-handle-displayed-p handle)))
5778 (gnus-insert-mime-button handle id (list displayed-p))
5779 (if (featurep 'emacs)
5780 (delete-region
5781 (point)
5782 (next-single-property-change (point) 'gnus-data nil (point-max)))
5783 (let* ((end (next-single-property-change (point) 'gnus-data))
5784 (annots (annotations-at (or end (point-max)))))
5785 (delete-region (point)
5786 (if end
5787 (if annots (1+ end) end)
5788 (point-max)))
5789 (dolist (annot annots)
5790 (set-extent-endpoints annot (point) (point)))))
5791 (setq start (point))
5792 (if (search-backward "\n\n" nil t)
5793 (progn
5794 (goto-char start)
5795 (unless (or displayed-p (eolp))
5796 ;; Add extra newline.
5797 (insert (propertize (buffer-substring (1- start) start)
5798 'gnus-undeletable t))))
5799 ;; We're in the article header.
5800 (delete-char -1)
5801 (dolist (ovl (overlays-in point (point)))
5802 (overlay-put ovl 'gnus-button-attachment-extra t)
5803 (overlay-put ovl 'face nil))
5804 (save-restriction
5805 (message-narrow-to-field)
5806 (let ((gnus-treatment-function-alist
5807 '((gnus-treat-highlight-headers
5808 gnus-article-highlight-headers))))
5809 (gnus-treat-article 'head)))))
5810 (goto-char point)
5811 (if (window-live-p window)
5812 (select-window window)))
5813 retval))
5814
5815 (defun gnus-article-goto-part (n)
5816 "Go to MIME part N."
5817 (when gnus-break-pages
5818 (widen))
5819 (article-goto-body)
5820 (prog1
5821 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5822 ;; There may be header buttons.
5823 (text-property-any (point-min) (point) 'gnus-part n)))
5824 part handle end next handles)
5825 (when start
5826 (goto-char start)
5827 (if (setq handle (get-text-property start 'gnus-data))
5828 start
5829 ;; Go to the displayed subpart, assuming this is
5830 ;; multipart/alternative.
5831 (setq part start
5832 end (point-at-eol))
5833 (while (and (not handle)
5834 part
5835 (< part end)
5836 (setq next (text-property-not-all part end
5837 'gnus-data nil)))
5838 (setq part next
5839 handle (get-text-property part 'gnus-data))
5840 (push (cons handle part) handles)
5841 (unless (mm-handle-displayed-p handle)
5842 (setq handle nil
5843 part (text-property-any part end 'gnus-data nil))))
5844 (unless handle
5845 ;; No subpart is displayed, so we find preferred one.
5846 (setq part
5847 (cdr (assq (mm-preferred-alternative
5848 (nreverse (mapcar 'car handles)))
5849 handles))))
5850 (if part
5851 (goto-char (1+ part))
5852 start))))
5853 (when gnus-break-pages
5854 (gnus-narrow-to-page))))
5855
5856 (defun gnus-insert-mime-button (handle id &optional displayed)
5857 (let ((gnus-tmp-name
5858 (or (mm-handle-filename handle)
5859 (mail-content-type-get (mm-handle-type handle) 'url)
5860 ""))
5861 (gnus-tmp-id id)
5862 (gnus-tmp-type (mm-handle-media-type handle))
5863 (gnus-tmp-description (or (mm-handle-description handle) ""))
5864 (gnus-tmp-dots
5865 (if (if displayed (car displayed)
5866 (mm-handle-displayed-p handle))
5867 "" "..."))
5868 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5869 (buffer-size)))
5870 gnus-tmp-type-long b e)
5871 (when (string-match ".*/" gnus-tmp-name)
5872 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5873 (setq gnus-tmp-type-long (concat gnus-tmp-type
5874 (and (not (equal gnus-tmp-name ""))
5875 (concat "; " gnus-tmp-name))))
5876 (unless (equal gnus-tmp-description "")
5877 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5878 (setq b (point))
5879 (gnus-eval-format
5880 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5881 `(keymap ,gnus-mime-button-map
5882 gnus-callback gnus-mm-display-part
5883 gnus-part ,gnus-tmp-id
5884 article-type annotation
5885 gnus-data ,handle
5886 rear-nonsticky t))
5887 (setq e (if (bolp)
5888 ;; Exclude a newline.
5889 (1- (point))
5890 (point)))
5891 (when gnus-article-button-face
5892 (overlay-put (make-overlay b e nil t)
5893 'face gnus-article-button-face))
5894 (widget-convert-button
5895 'link b e
5896 :mime-handle handle
5897 :action 'gnus-widget-press-button
5898 :button-keymap gnus-mime-button-map
5899 :help-echo
5900 (lambda (widget)
5901 ;; Needed to properly clear the message due to a bug in
5902 ;; wid-edit (XEmacs only).
5903 (if (boundp 'help-echo-owns-message)
5904 (setq help-echo-owns-message t))
5905 (format
5906 "%S: %s the MIME part; %S: more options"
5907 (aref gnus-mouse-2 0)
5908 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5909 "hide" "show")
5910 (aref gnus-down-mouse-3 0))))))
5911
5912 (defun gnus-widget-press-button (elems _el)
5913 (goto-char (widget-get elems :from))
5914 (gnus-article-press-button))
5915
5916 (defvar gnus-displaying-mime nil)
5917
5918 (defun gnus-display-mime (&optional ihandles)
5919 "Display the MIME parts."
5920 (save-excursion
5921 (save-selected-window
5922 (let ((window (get-buffer-window gnus-article-buffer))
5923 (point (point)))
5924 (when window
5925 (select-window window)
5926 ;; We have to do this since selecting the window
5927 ;; may change the point. So we set the window point.
5928 (set-window-point window point)))
5929 (let ((handles ihandles)
5930 (inhibit-read-only t))
5931 (cond (handles)
5932 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5933 (when gnus-article-emulate-mime
5934 (mm-uu-dissect-text-parts handles)))
5935 (gnus-article-emulate-mime
5936 (setq handles (mm-uu-dissect))))
5937 (when (and (not ihandles)
5938 (not gnus-displaying-mime))
5939 ;; Top-level call; we clean up.
5940 (when gnus-article-mime-handles
5941 (mm-destroy-parts gnus-article-mime-handles)
5942 (setq gnus-article-mime-handle-alist nil));; A trick.
5943 (setq gnus-article-mime-handles handles)
5944 ;; We allow users to glean info from the handles.
5945 (when gnus-article-mime-part-function
5946 (gnus-mime-part-function handles)))
5947 (if (and handles
5948 (or (not (stringp (car handles)))
5949 (cdr handles)))
5950 (progn
5951 (when (and (not ihandles)
5952 (not gnus-displaying-mime))
5953 ;; Clean up for mime parts.
5954 (article-goto-body)
5955 (delete-region (point) (point-max)))
5956 (let ((gnus-displaying-mime t))
5957 (gnus-mime-display-part handles)))
5958 (save-restriction
5959 (article-goto-body)
5960 (narrow-to-region (point) (point-max))
5961 (gnus-treat-article nil 1 1 "text/plain")
5962 (widen)))
5963 (unless ihandles
5964 ;; Highlight the headers.
5965 (save-excursion
5966 (save-restriction
5967 (article-goto-body)
5968 (narrow-to-region (point-min) (point))
5969 (gnus-article-save-original-date
5970 (gnus-treat-article 'head)))))))
5971 ;; Cope with broken MIME messages.
5972 (goto-char (point-max))
5973 (unless (bolp)
5974 (insert "\n"))))
5975
5976 (defcustom gnus-mime-display-multipart-as-mixed nil
5977 "Display \"multipart\" parts as \"multipart/mixed\".
5978
5979 If t, it overrides nil values of
5980 `gnus-mime-display-multipart-alternative-as-mixed' and
5981 `gnus-mime-display-multipart-related-as-mixed'."
5982 :group 'gnus-article-mime
5983 :type 'boolean)
5984
5985 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5986 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5987 :version "22.1"
5988 :group 'gnus-article-mime
5989 :type 'boolean)
5990
5991 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5992 "Display \"multipart/related\" parts as \"multipart/mixed\".
5993
5994 If displaying \"text/html\" is discouraged \(see
5995 `mm-discouraged-alternatives'\) images or other material inside a
5996 \"multipart/related\" part might be overlooked when this variable is nil."
5997 :version "22.1"
5998 :group 'gnus-article-mime
5999 :type 'boolean)
6000
6001 (defcustom gnus-mime-display-attachment-buttons-in-header t
6002 "Add attachment buttons in the end of the header of an article.
6003 Since MIME attachments tend to be put at the end of an article, we may
6004 overlook them if there is a huge body. This option offers you a copy
6005 of all non-inlinable MIME parts as buttons shown in front of an article.
6006 If nil, don't show those extra buttons."
6007 :version "25.1"
6008 :group 'gnus-article-mime
6009 :type 'boolean)
6010
6011 (defun gnus-mime-display-part (handle)
6012 (cond
6013 ;; Maybe a broken MIME message.
6014 ((null handle))
6015 ;; Single part.
6016 ((not (stringp (car handle)))
6017 (gnus-mime-display-single handle))
6018 ;; User-defined multipart
6019 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6020 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6021 handle))
6022 ;; multipart/alternative
6023 ((and (equal (car handle) "multipart/alternative")
6024 (not (or gnus-mime-display-multipart-as-mixed
6025 gnus-mime-display-multipart-alternative-as-mixed)))
6026 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6027 (push (cons id handle) gnus-article-mime-handle-alist)
6028 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6029 ;; multipart/related
6030 ((and (equal (car handle) "multipart/related")
6031 (not (or gnus-mime-display-multipart-as-mixed
6032 gnus-mime-display-multipart-related-as-mixed)))
6033 (gnus-mime-display-part (cadr handle)))
6034 ((equal (car handle) "multipart/signed")
6035 (gnus-add-wash-type 'signed)
6036 (gnus-mime-display-security handle))
6037 ((equal (car handle) "multipart/encrypted")
6038 (gnus-add-wash-type 'encrypted)
6039 (gnus-mime-display-security handle))
6040 ;; Other multiparts are handled like multipart/mixed.
6041 (t
6042 (gnus-mime-display-mixed (cdr handle)))))
6043
6044 (defun gnus-mime-part-function (handles)
6045 (if (stringp (car handles))
6046 (mapcar 'gnus-mime-part-function (cdr handles))
6047 (funcall gnus-article-mime-part-function handles)))
6048
6049 (defun gnus-mime-display-mixed (handles)
6050 (mapcar 'gnus-mime-display-part handles))
6051
6052 (defun gnus-mime-display-single (handle)
6053 (let ((type (mm-handle-media-type handle))
6054 (ignored gnus-ignored-mime-types)
6055 (not-attachment t)
6056 display text)
6057 (catch 'ignored
6058 (progn
6059 (while ignored
6060 (when (string-match (pop ignored) type)
6061 (throw 'ignored nil)))
6062 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6063 (with-current-buffer gnus-summary-buffer
6064 gnus-inhibit-images)
6065 gnus-inhibit-images)
6066 (string-match "\\`image/" type)))
6067 (setq not-attachment
6068 (and (not (mm-inline-override-p handle))
6069 (or (not (mm-handle-disposition handle))
6070 (equal (car (mm-handle-disposition handle))
6071 "inline")
6072 (mm-attachment-override-p handle))))
6073 (mm-automatic-display-p handle)
6074 (or (and
6075 (mm-inlinable-p handle)
6076 (mm-inlined-p handle))
6077 (mm-automatic-external-display-p type)))
6078 (setq display t)
6079 (when (equal (mm-handle-media-supertype handle) "text")
6080 (setq text t)))
6081 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6082 beg)
6083 (unless id
6084 (setq id (1+ (length gnus-article-mime-handle-alist)))
6085 (push (cons id handle) gnus-article-mime-handle-alist))
6086 (when (and display
6087 (equal (mm-handle-media-supertype handle) "message"))
6088 (insert-char
6089 ?\n
6090 (cond ((not (bolp)) 2)
6091 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6092 (t 1))))
6093 (when (or (not display)
6094 (not (gnus-unbuttonized-mime-type-p type))
6095 (eq id gnus-mime-buttonized-part-id))
6096 (gnus-insert-mime-button
6097 handle id (list (or display (and not-attachment text)))))
6098 (setq beg (point))
6099 (cond
6100 (display
6101 (let ((mail-parse-charset gnus-newsgroup-charset)
6102 (mail-parse-ignored-charsets
6103 (save-excursion (condition-case ()
6104 (set-buffer gnus-summary-buffer)
6105 (error))
6106 gnus-newsgroup-ignored-charsets)))
6107 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6108 ((and text not-attachment)
6109 (mm-display-inline handle)))
6110 (goto-char (point-max))
6111 (if (string-match "\\`image/" type)
6112 (gnus-article-insert-newline)
6113 (if (prog1
6114 (= (skip-chars-backward "\n") -1)
6115 (unless (eobp) (forward-char 1)))
6116 (gnus-article-insert-newline)
6117 (put-text-property (point) (point-max) 'gnus-undeletable t))
6118 (goto-char (point-max)))
6119 ;; Do highlighting.
6120 (save-excursion
6121 (save-restriction
6122 (narrow-to-region beg (point))
6123 (if (eq handle gnus-article-mime-handles)
6124 ;; The format=flowed case.
6125 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6126 ;; Don't count signature parts that are never displayed.
6127 ;; The part number should be re-calculated supposing this
6128 ;; might be a message/rfc822 part.
6129 (let (handles)
6130 (dolist (part gnus-article-mime-handles)
6131 (unless (or (stringp part)
6132 (equal (car (mm-handle-type part))
6133 "application/pgp-signature"))
6134 (push part handles)))
6135 (gnus-treat-article
6136 nil (length (memq handle handles)) (length handles)
6137 (mm-handle-media-type handle)))))))))))
6138
6139 (defun gnus-unbuttonized-mime-type-p (type)
6140 "Say whether TYPE is to be unbuttonized."
6141 (unless gnus-inhibit-mime-unbuttonizing
6142 (when (catch 'found
6143 (let ((types gnus-unbuttonized-mime-types))
6144 (while types
6145 (when (string-match (pop types) type)
6146 (throw 'found t)))))
6147 (not (catch 'found
6148 (let ((types gnus-buttonized-mime-types))
6149 (while types
6150 (when (string-match (pop types) type)
6151 (throw 'found t)))))))))
6152
6153 (defun gnus-article-insert-newline ()
6154 "Insert a newline, but mark it as undeletable."
6155 (gnus-put-text-property
6156 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6157
6158 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6159 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6160 (ihandles handles)
6161 (point (point))
6162 handle (inhibit-read-only t) from begend not-pref)
6163 (save-window-excursion
6164 (save-restriction
6165 (when ibegend
6166 (narrow-to-region (car ibegend)
6167 (or (cdr ibegend)
6168 (progn
6169 (goto-char (car ibegend))
6170 (forward-line 2)
6171 (point))))
6172 (delete-region (point-min) (point-max))
6173 (mm-remove-parts handles))
6174 (setq begend (list (point-marker)))
6175 ;; Do the toggle.
6176 (unless (setq not-pref (cadr (member preferred ihandles)))
6177 (setq not-pref (car ihandles)))
6178 (when (or ibegend
6179 (not preferred)
6180 (not (gnus-unbuttonized-mime-type-p
6181 "multipart/alternative")))
6182 (gnus-add-text-properties
6183 (setq from (point))
6184 (progn
6185 (insert (format "%d. " id))
6186 (point))
6187 `(gnus-callback
6188 (lambda (handles)
6189 (unless ,(not ibegend)
6190 (setq gnus-article-mime-handle-alist
6191 ',gnus-article-mime-handle-alist))
6192 (gnus-mime-display-alternative
6193 ',ihandles ',not-pref ',begend ,id))
6194 keymap ,gnus-mime-button-map
6195 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6196 face ,gnus-article-button-face
6197 gnus-part ,id
6198 article-type multipart
6199 rear-nonsticky t))
6200 (widget-convert-button 'link from (point)
6201 :action 'gnus-widget-press-button
6202 :button-keymap gnus-widget-button-keymap)
6203 ;; Do the handles
6204 (while (setq handle (pop handles))
6205 (gnus-add-text-properties
6206 (setq from (point))
6207 (progn
6208 (insert (format "(%c) %-18s"
6209 (if (equal handle preferred) ?* ? )
6210 (mm-handle-media-type handle)))
6211 (point))
6212 `(gnus-callback
6213 (lambda (handles)
6214 (unless ,(not ibegend)
6215 (setq gnus-article-mime-handle-alist
6216 ',gnus-article-mime-handle-alist))
6217 (gnus-mime-display-alternative
6218 ',ihandles ',handle ',begend ,id))
6219 keymap ,gnus-mime-button-map
6220 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6221 face ,gnus-article-button-face
6222 gnus-part ,id
6223 gnus-data ,handle
6224 rear-nonsticky t))
6225 (widget-convert-button 'link from (point)
6226 :action 'gnus-widget-press-button
6227 :button-keymap gnus-widget-button-keymap)
6228 (insert " "))
6229 (insert "\n\n"))
6230 (when preferred
6231 (if (stringp (car preferred))
6232 (gnus-display-mime preferred)
6233 (let ((mail-parse-charset gnus-newsgroup-charset)
6234 (mail-parse-ignored-charsets
6235 (with-current-buffer gnus-summary-buffer
6236 gnus-newsgroup-ignored-charsets)))
6237 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6238 ;; Do highlighting.
6239 (save-excursion
6240 (save-restriction
6241 (narrow-to-region (car begend) (point-max))
6242 (gnus-treat-article
6243 nil (length gnus-article-mime-handle-alist)
6244 (gnus-article-mime-total-parts)
6245 (mm-handle-media-type preferred))))))
6246 (goto-char (point-max))
6247 (setcdr begend (point-marker)))))
6248 (when ibegend
6249 (goto-char point)))
6250 ;; Redraw attachment buttons in the header.
6251 (when gnus-mime-display-attachment-buttons-in-header
6252 (gnus-mime-buttonize-attachments-in-header)))
6253
6254 (defconst gnus-article-wash-status-strings
6255 (let ((alist '((cite "c" "Possible hidden citation text"
6256 " " "All citation text visible")
6257 (headers "h" "Hidden headers"
6258 " " "All headers visible.")
6259 (pgp "p" "Encrypted or signed message status hidden"
6260 " " "No hidden encryption nor digital signature status")
6261 (signature "s" "Signature has been hidden"
6262 " " "Signature is visible")
6263 (overstrike "o" "Overstrike (^H) characters applied"
6264 " " "No overstrike characters applied")
6265 (emphasis "e" "/*_Emphasis_*/ characters applied"
6266 " " "No /*_emphasis_*/ characters applied")))
6267 result)
6268 (dolist (entry alist result)
6269 (let ((key (nth 0 entry))
6270 (on (copy-sequence (nth 1 entry)))
6271 (on-help (nth 2 entry))
6272 (off (copy-sequence (nth 3 entry)))
6273 (off-help (nth 4 entry)))
6274 (put-text-property 0 1 'help-echo on-help on)
6275 (put-text-property 0 1 'help-echo off-help off)
6276 (push (list key on off) result))))
6277 "Alist of strings describing wash status in the mode line.
6278 Each entry has the form (KEY ON OF), where the KEY is a symbol
6279 representing the particular washing function, ON is the string to use
6280 in the article mode line when the washing function is active, and OFF
6281 is the string to use when it is inactive.")
6282
6283 (defun gnus-article-wash-status-entry (key value)
6284 (let ((entry (assoc key gnus-article-wash-status-strings)))
6285 (if value (nth 1 entry) (nth 2 entry))))
6286
6287 (defun gnus-article-wash-status ()
6288 "Return a string which display status of article washing."
6289 (with-current-buffer gnus-article-buffer
6290 (let ((cite (memq 'cite gnus-article-wash-types))
6291 (headers (memq 'headers gnus-article-wash-types))
6292 (boring (memq 'boring-headers gnus-article-wash-types))
6293 (pgp (memq 'pgp gnus-article-wash-types))
6294 (pem (memq 'pem gnus-article-wash-types))
6295 (signed (memq 'signed gnus-article-wash-types))
6296 (encrypted (memq 'encrypted gnus-article-wash-types))
6297 (signature (memq 'signature gnus-article-wash-types))
6298 (overstrike (memq 'overstrike gnus-article-wash-types))
6299 (emphasis (memq 'emphasis gnus-article-wash-types)))
6300 (concat
6301 (gnus-article-wash-status-entry 'cite cite)
6302 (gnus-article-wash-status-entry 'headers (or headers boring))
6303 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6304 (gnus-article-wash-status-entry 'signature signature)
6305 (gnus-article-wash-status-entry 'overstrike overstrike)
6306 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6307
6308 (defun gnus-add-wash-type (type)
6309 "Add a washing of TYPE to the current status."
6310 (add-to-list 'gnus-article-wash-types type))
6311
6312 (defun gnus-delete-wash-type (type)
6313 "Add a washing of TYPE to the current status."
6314 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6315
6316 (defun gnus-add-image (category image)
6317 "Add IMAGE of CATEGORY to the list of displayed images."
6318 (let ((entry (assq category gnus-article-image-alist)))
6319 (unless entry
6320 (setq entry (list category))
6321 (push entry gnus-article-image-alist))
6322 (nconc entry (list image))))
6323
6324 (defun gnus-delete-images (category)
6325 "Delete all images in CATEGORY."
6326 (let ((entry (assq category gnus-article-image-alist)))
6327 (dolist (image (cdr entry))
6328 (gnus-remove-image image category))
6329 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6330 (gnus-delete-wash-type category)))
6331
6332 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6333
6334 (defun gnus-article-maybe-hide-headers ()
6335 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6336 Provided for backwards compatibility."
6337 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6338 (not (with-current-buffer gnus-summary-buffer
6339 gnus-have-all-headers)))
6340 (not gnus-inhibit-hiding))
6341 (gnus-article-hide-headers)))
6342
6343 (declare-function shr-put-image "shr" (data alt &optional flags))
6344
6345 (defun gnus-shr-put-image (data alt &optional flags)
6346 "Put image DATA with a string ALT. Enable image to be deleted."
6347 (let ((image (if flags
6348 (shr-put-image data (propertize (or alt "*")
6349 'gnus-image-category 'shr)
6350 flags)
6351 ;; Old `shr-put-image' doesn't take the optional `flags'
6352 ;; argument.
6353 (shr-put-image data (propertize (or alt "*")
6354 'gnus-image-category 'shr)))))
6355 (when image
6356 (gnus-add-image 'shr image))))
6357
6358 (defun gnus-article-mime-handles (&optional alist id all)
6359 (if alist
6360 (let ((i 1) newid flat)
6361 (dolist (handle alist flat)
6362 (setq newid (append id (list i))
6363 i (1+ i))
6364 (if (stringp (car handle))
6365 (setq flat (nconc flat (gnus-article-mime-handles
6366 (cdr handle) newid all)))
6367 (delq (rassq handle all) all)
6368 (setq flat (nconc flat (list (cons newid handle)))))))
6369 (let ((flat (list nil)))
6370 ;; Assume that elements of `gnus-article-mime-handle-alist'
6371 ;; are in the decreasing order, but unnumbered subsidiaries
6372 ;; in each element are in the increasing order.
6373 (dolist (handle (reverse gnus-article-mime-handle-alist))
6374 (if (stringp (cadr handle))
6375 (setq flat (nconc flat (gnus-article-mime-handles
6376 (cddr handle) (list (car handle)) flat)))
6377 (delq (rassq (cdr handle) flat) flat)
6378 (setq flat (nconc flat (list (cons (list (car handle))
6379 (cdr handle)))))))
6380 (setq flat (cdr flat))
6381 (mapc (lambda (handle)
6382 (if (cdar handle)
6383 ;; This is a hidden (i.e. unnumbered) handle.
6384 (progn
6385 (setcar handle
6386 (1+ (caar gnus-article-mime-handle-alist)))
6387 (push handle gnus-article-mime-handle-alist))
6388 (setcar handle (caar handle))))
6389 flat)
6390 flat)))
6391
6392 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6393 "Show attachments as buttons in the end of the header of an article.
6394 This function toggles the display when called interactively. Note that
6395 buttons to be added to the header are only the ones that aren't inlined
6396 in the body. Use `gnus-header-face-alist' to highlight buttons."
6397 (interactive (list t))
6398 (gnus-with-article-buffer
6399 (let ((case-fold-search t) buttons handle type st)
6400 (save-excursion
6401 (save-restriction
6402 (widen)
6403 (article-narrow-to-head)
6404 ;; Header buttons exist?
6405 (while (and (not buttons)
6406 (re-search-forward "^attachments?:[\n ]+" nil t))
6407 (when (get-char-property (match-end 0)
6408 'gnus-button-attachment-extra)
6409 (setq buttons (match-beginning 0))))
6410 (widen)
6411 (when buttons
6412 ;; Delete header buttons.
6413 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6414 (match-beginning 0)
6415 (point-max))))
6416 (unless (and interactive buttons)
6417 ;; Find buttons.
6418 (setq buttons nil)
6419 (dolist (button (gnus-article-mime-handles))
6420 (setq handle (cdr button)
6421 type (mm-handle-media-type handle))
6422 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6423 (with-current-buffer gnus-summary-buffer
6424 gnus-inhibit-images)
6425 gnus-inhibit-images)
6426 (string-match "\\`image/" type))
6427 (mm-inline-override-p handle)
6428 (and (mm-handle-disposition handle)
6429 (not (equal (car (mm-handle-disposition handle))
6430 "inline"))
6431 (not (mm-attachment-override-p handle)))
6432 (not (mm-automatic-display-p handle))
6433 (not (or (and (mm-inlinable-p handle)
6434 (mm-inlined-p handle))
6435 (mm-automatic-external-display-p type))))
6436 (push button buttons)))
6437 (when buttons
6438 ;; Add header buttons.
6439 (article-goto-body)
6440 (forward-line -1)
6441 (narrow-to-region (point) (point))
6442 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6443 (dolist (button (nreverse buttons))
6444 (setq st (point))
6445 (insert " ")
6446 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6447 (gnus-insert-mime-button handle (car button))
6448 (skip-chars-backward "\t\n ")
6449 (delete-region (point) (point-max))
6450 (when (> (current-column) (window-width))
6451 (goto-char st)
6452 (insert "\n")
6453 (end-of-line)))
6454 (insert "\n")
6455 (dolist (ovl (overlays-in (point-min) (point)))
6456 (overlay-put ovl 'gnus-button-attachment-extra t)
6457 (overlay-put ovl 'face nil))
6458 (let ((gnus-treatment-function-alist
6459 '((gnus-treat-highlight-headers
6460 gnus-article-highlight-headers))))
6461 (gnus-treat-article 'head)))))))))
6462
6463 ;;; Article savers.
6464
6465 (defun gnus-output-to-file (file-name)
6466 "Append the current article to a file named FILE-NAME.
6467 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6468 text and used as the value of the coding cookie which is added to the
6469 top of a file. Otherwise, this function saves a raw article without
6470 the coding cookie."
6471 (let* ((artbuf (current-buffer))
6472 (file-name-coding-system nnmail-pathname-coding-system)
6473 (coding gnus-article-save-coding-system)
6474 (coding-system-for-read (if coding
6475 nil ;; Rely on the coding cookie.
6476 mm-text-coding-system))
6477 (coding-system-for-write (or coding
6478 mm-text-coding-system-for-write
6479 mm-text-coding-system))
6480 (exists (file-exists-p file-name)))
6481 (with-temp-buffer
6482 (when exists
6483 (insert-file-contents file-name)
6484 (goto-char (point-min))
6485 ;; Remove the existing coding cookie.
6486 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6487 (delete-region (match-beginning 0) (match-end 0))))
6488 (goto-char (point-max))
6489 (insert-buffer-substring artbuf)
6490 ;; Append newline at end of the buffer as separator, and then
6491 ;; save it to file.
6492 (goto-char (point-max))
6493 (insert "\n")
6494 (when coding
6495 ;; If the coding system is not suitable to encode the text,
6496 ;; ask a user for a proper one.
6497 (when (fboundp 'select-safe-coding-system)
6498 (setq coding (coding-system-base
6499 (save-window-excursion
6500 (select-safe-coding-system (point-min) (point-max)
6501 coding))))
6502 (setq coding-system-for-write
6503 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6504 coding)))
6505 (goto-char (point-min))
6506 ;; Add the coding cookie.
6507 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6508 coding-system-for-write)))
6509 (if exists
6510 (progn
6511 (write-region (point-min) (point-max) file-name nil 'no-message)
6512 (message "Appended to %s" file-name))
6513 (write-region (point-min) (point-max) file-name))))
6514 t)
6515
6516 (defun gnus-narrow-to-page (&optional arg)
6517 "Narrow the article buffer to a page.
6518 If given a numerical ARG, move forward ARG pages."
6519 (interactive "P")
6520 (setq arg (if arg (prefix-numeric-value arg) 0))
6521 (with-current-buffer gnus-article-buffer
6522 (widen)
6523 ;; Remove any old next/prev buttons.
6524 (when (gnus-visual-p 'page-marker)
6525 (let ((inhibit-read-only t))
6526 (gnus-remove-text-with-property 'gnus-prev)
6527 (gnus-remove-text-with-property 'gnus-next)))
6528 (let (st nd pt)
6529 (when (save-excursion
6530 (cond ((< arg 0)
6531 (if (re-search-backward page-delimiter nil 'move (abs arg))
6532 (prog1
6533 (setq nd (match-beginning 0)
6534 pt nd)
6535 (when (re-search-backward page-delimiter nil t)
6536 (setq st (match-end 0))))
6537 (when (re-search-forward page-delimiter nil t)
6538 (setq nd (match-beginning 0)
6539 pt (point-min)))))
6540 ((> arg 0)
6541 (if (re-search-forward page-delimiter nil 'move arg)
6542 (prog1
6543 (setq st (match-end 0)
6544 pt st)
6545 (when (re-search-forward page-delimiter nil t)
6546 (setq nd (match-beginning 0))))
6547 (when (re-search-backward page-delimiter nil t)
6548 (setq st (match-end 0)
6549 pt (point-max)))))
6550 (t
6551 (when (re-search-backward page-delimiter nil t)
6552 (goto-char (setq st (match-end 0))))
6553 (when (re-search-forward page-delimiter nil t)
6554 (setq nd (match-beginning 0)))
6555 (or st nd))))
6556 (setq gnus-page-broken t)
6557 (when pt (goto-char pt))
6558 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6559 (when (gnus-visual-p 'page-marker)
6560 (save-excursion
6561 (when nd
6562 (goto-char nd)
6563 (gnus-insert-next-page-button))
6564 (when st
6565 (goto-char st)
6566 (gnus-insert-prev-page-button))))))))
6567
6568 ;; Article mode commands
6569
6570 (defun gnus-article-goto-next-page ()
6571 "Show the next page of the article."
6572 (interactive)
6573 (when (gnus-article-next-page)
6574 (goto-char (point-min))
6575 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6576
6577
6578 (defun gnus-article-goto-prev-page ()
6579 "Show the previous page of the article."
6580 (interactive)
6581 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6582 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6583 (gnus-article-prev-page nil)))
6584
6585 ;; This is cleaner but currently breaks `gnus-pick-mode':
6586 ;;
6587 ;; (defun gnus-article-goto-next-page ()
6588 ;; "Show the next page of the article."
6589 ;; (interactive)
6590 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6591 ;; (gnus-summary-next-page)))
6592 ;;
6593 ;; (defun gnus-article-goto-prev-page ()
6594 ;; "Show the next page of the article."
6595 ;; (interactive)
6596 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6597 ;; (gnus-summary-prev-page)))
6598
6599 (defun gnus-article-next-page (&optional lines)
6600 "Show the next page of the current article.
6601 If end of article, return non-nil. Otherwise return nil.
6602 Argument LINES specifies lines to be scrolled up."
6603 (interactive "p")
6604 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6605 (if (and (not (and gnus-article-over-scroll
6606 (> (count-lines (window-start) (point-max))
6607 (if (featurep 'xemacs)
6608 (or lines (1- (window-height)))
6609 (+ (or lines (1- (window-height))) scroll-margin)))))
6610 (save-excursion
6611 (end-of-line)
6612 (and (pos-visible-in-window-p) ;Not continuation line.
6613 (>= (point) (point-max)))))
6614 ;; Nothing in this page.
6615 (if (or (not gnus-page-broken)
6616 (save-excursion
6617 (save-restriction
6618 (widen)
6619 (forward-line)
6620 (eobp)))) ;Real end-of-buffer?
6621 (progn
6622 (when gnus-article-over-scroll
6623 (gnus-article-next-page-1 lines))
6624 t) ;Nothing more.
6625 (gnus-narrow-to-page 1) ;Go to next page.
6626 nil)
6627 ;; More in this page.
6628 (gnus-article-next-page-1 lines)
6629 nil))
6630
6631 (defun gnus-article-beginning-of-window ()
6632 "Move point to the beginning of the window.
6633 In Emacs, the point is placed at the line number which `scroll-margin'
6634 specifies."
6635 (if (featurep 'xemacs)
6636 (move-to-window-line 0)
6637 ;; There is an obscure bug in Emacs that makes it impossible to
6638 ;; scroll past big pictures in the article buffer. Try to fix
6639 ;; this by adding a sanity check by counting the lines visible.
6640 (when (> (count-lines (window-start) (window-end)) 30)
6641 (move-to-window-line
6642 (min (max 0 scroll-margin)
6643 (max 1 (- (window-height)
6644 (if mode-line-format 1 0)
6645 (if header-line-format 1 0)
6646 2)))))))
6647
6648 (defvar scroll-in-place)
6649
6650 (defun gnus-article-next-page-1 (lines)
6651 (condition-case ()
6652 (let ((scroll-in-place nil)
6653 (auto-window-vscroll nil))
6654 (scroll-up lines))
6655 (end-of-buffer
6656 ;; Long lines may cause an end-of-buffer error.
6657 (goto-char (point-max))))
6658 (gnus-article-beginning-of-window))
6659
6660 (defun gnus-article-prev-page (&optional lines)
6661 "Show previous page of current article.
6662 Argument LINES specifies lines to be scrolled down."
6663 (interactive "p")
6664 (move-to-window-line 0)
6665 (if (and gnus-page-broken
6666 (bobp)
6667 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6668 (progn
6669 (gnus-narrow-to-page -1) ;Go to previous page.
6670 (goto-char (point-max))
6671 (recenter (if gnus-article-over-scroll
6672 (if lines
6673 (max (if (featurep 'xemacs)
6674 lines
6675 (+ lines scroll-margin))
6676 3)
6677 (- (window-height) 2))
6678 -1)))
6679 (prog1
6680 (condition-case ()
6681 (let ((scroll-in-place nil))
6682 (scroll-down lines))
6683 (beginning-of-buffer
6684 (goto-char (point-min))))
6685 (gnus-article-beginning-of-window))))
6686
6687 (defun gnus-article-only-boring-p ()
6688 "Decide whether there is only boring text remaining in the article.
6689 Something \"interesting\" is a word of at least two letters that does
6690 not have a face in `gnus-article-boring-faces'."
6691 (when (and gnus-article-skip-boring
6692 (boundp 'gnus-article-boring-faces)
6693 (symbol-value 'gnus-article-boring-faces))
6694 (save-excursion
6695 (let ((inhibit-point-motion-hooks t))
6696 (catch 'only-boring
6697 (while (re-search-forward "\\b\\w\\w" nil t)
6698 (forward-char -1)
6699 (when (not (gnus-intersection
6700 (gnus-faces-at (point))
6701 (symbol-value 'gnus-article-boring-faces)))
6702 (throw 'only-boring nil)))
6703 (throw 'only-boring t))))))
6704
6705 (defun gnus-article-refer-article ()
6706 "Read article specified by message-id around point."
6707 (interactive)
6708 (save-excursion
6709 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6710 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6711 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6712 (let ((msg-id (concat "<" (match-string 0) ">")))
6713 (set-buffer gnus-summary-buffer)
6714 (gnus-summary-refer-article msg-id))
6715 (error "No references around point"))))
6716
6717 (defun gnus-article-show-summary ()
6718 "Reconfigure windows to show summary buffer."
6719 (interactive)
6720 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6721 (error "There is no summary buffer for this article buffer")
6722 (gnus-article-set-globals)
6723 (gnus-configure-windows 'article)
6724 (gnus-summary-goto-subject gnus-current-article)
6725 (gnus-summary-position-point)))
6726
6727 (defun gnus-article-describe-briefly ()
6728 "Describe article mode commands briefly."
6729 (interactive)
6730 (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")))
6731
6732 (defun gnus-article-check-buffer ()
6733 "Beep if not in an article buffer."
6734 (unless (derived-mode-p 'gnus-article-mode)
6735 (error "Command invoked outside of a Gnus article buffer")))
6736
6737 (defvar gnus-pick-mode)
6738
6739 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6740 "Read a summary buffer key sequence and execute it from the article buffer."
6741 (interactive "P")
6742 (gnus-article-check-buffer)
6743 (let ((nosaves
6744 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6745 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6746 "=" "^" "\M-^" "|"))
6747 (nosave-but-article
6748 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6749 "An" "Ap" [?A (meta return)] [?A delete]))
6750 (nosave-in-article
6751 '("AS" "\C-d"))
6752 keys new-sum-point)
6753 (with-current-buffer gnus-article-current-summary
6754 (let (gnus-pick-mode)
6755 (setq unread-command-events (nconc unread-command-events
6756 (list (or key last-command-event)))
6757 keys (if (featurep 'xemacs)
6758 (events-to-keys (read-key-sequence nil t))
6759 (read-key-sequence nil t)))))
6760
6761 (message "")
6762
6763 (cond
6764 ((eq (aref keys (1- (length keys))) ?\C-h)
6765 (gnus-article-describe-bindings (substring keys 0 -1)))
6766 ((or (member keys nosaves)
6767 (member keys nosave-but-article)
6768 (member keys nosave-in-article))
6769 (let (func)
6770 (save-window-excursion
6771 (pop-to-buffer gnus-article-current-summary)
6772 ;; We disable the pick minor mode commands.
6773 (let (gnus-pick-mode)
6774 (setq func (key-binding keys t))))
6775 (if (or (not func)
6776 (numberp func))
6777 (ding)
6778 (unless (member keys nosave-in-article)
6779 (set-buffer gnus-article-current-summary))
6780 (when (and (symbolp func)
6781 (get func 'disabled))
6782 (error "Function %s disabled" func))
6783 (call-interactively func)
6784 (setq new-sum-point (point)))
6785 (when (member keys nosave-but-article)
6786 (pop-to-buffer gnus-article-buffer))))
6787 (t
6788 ;; These commands should restore window configuration.
6789 (let ((obuf (current-buffer))
6790 (owin (current-window-configuration))
6791 win func in-buffer selected new-sum-start new-sum-hscroll err)
6792 (cond (not-restore-window
6793 (pop-to-buffer gnus-article-current-summary)
6794 (setq win (selected-window)))
6795 ((setq win (get-buffer-window gnus-article-current-summary))
6796 (select-window win))
6797 (t
6798 (let ((summary-buffer gnus-article-current-summary))
6799 (gnus-configure-windows 'article)
6800 (unless (setq win (get-buffer-window summary-buffer 'visible))
6801 (let ((gnus-buffer-configuration
6802 '((article ((vertical 1.0
6803 (summary 0.25 point)
6804 (article 1.0)))))))
6805 (gnus-configure-windows 'article))
6806 (setq win (get-buffer-window summary-buffer 'visible)))
6807 (gnus-select-frame-set-input-focus (window-frame win))
6808 (select-window win))))
6809 (setq in-buffer (current-buffer))
6810 ;; We disable the pick minor mode commands.
6811 (setq func (let (gnus-pick-mode)
6812 (key-binding keys t)))
6813 (when (get func 'disabled)
6814 (error "Function %s disabled" func))
6815 (if (and func
6816 (functionp func)
6817 (condition-case code
6818 (progn
6819 (call-interactively func)
6820 t)
6821 (error
6822 (setq err code)
6823 nil)))
6824 (progn
6825 (when (eq win (selected-window))
6826 (setq new-sum-point (point)
6827 new-sum-start (window-start win)
6828 new-sum-hscroll (window-hscroll win)))
6829 (when (or (eq in-buffer (current-buffer))
6830 (when (eq obuf (current-buffer))
6831 (set-buffer in-buffer)
6832 t))
6833 (setq selected (ignore-errors (gnus-summary-select-article)))
6834 (set-buffer obuf)
6835 (unless not-restore-window
6836 (set-window-configuration owin))
6837 (when (and (eq selected 'old)
6838 new-sum-point)
6839 (set-window-start (get-buffer-window (current-buffer))
6840 1)
6841 (set-window-point (get-buffer-window (current-buffer))
6842 (if (article-goto-body)
6843 (1- (point))
6844 (point))))
6845 (when (and (not not-restore-window)
6846 new-sum-point
6847 (window-live-p win)
6848 (with-current-buffer (window-buffer win)
6849 (derived-mode-p 'gnus-summary-mode)))
6850 (set-window-point win new-sum-point)
6851 (set-window-start win new-sum-start)
6852 (set-window-hscroll win new-sum-hscroll))))
6853 (set-window-configuration owin)
6854 (if err
6855 (signal (car err) (cdr err))
6856 (ding))))))))
6857
6858 (defun gnus-article-read-summary-send-keys ()
6859 (interactive)
6860 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6861 (gnus-article-read-summary-keys)))
6862
6863 (defun gnus-article-describe-key (key)
6864 "Display documentation of the function invoked by KEY.
6865 KEY is a string or a vector."
6866 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6867 (read-key-sequence "Describe key: "))))
6868 (gnus-article-check-buffer)
6869 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6870 gnus-article-read-summary-send-keys))
6871 (with-current-buffer gnus-article-current-summary
6872 (setq unread-command-events
6873 (if (featurep 'xemacs)
6874 (append key unread-command-events)
6875 (nconc
6876 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6877 (list 'meta (- x 128))
6878 x))
6879 key)
6880 unread-command-events)))
6881 (let ((cursor-in-echo-area t)
6882 gnus-pick-mode)
6883 (describe-key (read-key-sequence nil t))))
6884 (describe-key key)))
6885
6886 (defun gnus-article-describe-key-briefly (key &optional insert)
6887 "Display documentation of the function invoked by KEY.
6888 KEY is a string or a vector."
6889 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6890 (read-key-sequence "Describe key: "))
6891 current-prefix-arg))
6892 (gnus-article-check-buffer)
6893 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6894 gnus-article-read-summary-send-keys))
6895 (with-current-buffer gnus-article-current-summary
6896 (setq unread-command-events
6897 (if (featurep 'xemacs)
6898 (append key unread-command-events)
6899 (nconc
6900 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6901 (list 'meta (- x 128))
6902 x))
6903 key)
6904 unread-command-events)))
6905 (let ((cursor-in-echo-area t)
6906 gnus-pick-mode)
6907 (describe-key-briefly (read-key-sequence nil t) insert)))
6908 (describe-key-briefly key insert)))
6909
6910 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6911 (defvar gnus-agent-summary-mode)
6912 (defvar gnus-draft-mode)
6913 (defvar help-xref-stack-item)
6914 (defvar help-xref-following)
6915
6916 (defun gnus-article-describe-bindings (&optional prefix)
6917 "Show a list of all defined keys, and their definitions.
6918 The optional argument PREFIX, if non-nil, should be a key sequence;
6919 then we display only bindings that start with that prefix."
6920 (interactive)
6921 (gnus-article-check-buffer)
6922 (let ((keymap (copy-keymap gnus-article-mode-map))
6923 (map (copy-keymap gnus-article-send-map))
6924 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6925 parent agent draft)
6926 (define-key keymap "S" map)
6927 (define-key map [t] nil)
6928 (with-current-buffer gnus-article-current-summary
6929 (set-keymap-parent
6930 keymap
6931 (if (setq parent (keymap-parent gnus-article-mode-map))
6932 (prog1
6933 (setq parent (copy-keymap parent))
6934 (set-keymap-parent parent (current-local-map)))
6935 (current-local-map)))
6936 (set-keymap-parent map (key-binding "S"))
6937 (let (key def gnus-pick-mode)
6938 (while sumkeys
6939 (setq key (pop sumkeys))
6940 (cond ((and (vectorp key) (= (length key) 1)
6941 (consp (setq def (aref key 0)))
6942 (numberp (car def)) (numberp (cdr def)))
6943 (when (< (max (car def) (cdr def)) 128)
6944 (setq sumkeys
6945 (append (mapcar
6946 #'vector
6947 (nreverse (gnus-uncompress-range def)))
6948 sumkeys))))
6949 ((setq def (key-binding key))
6950 (unless (eq def 'undefined)
6951 (define-key keymap key def))))))
6952 (when (boundp 'gnus-agent-summary-mode)
6953 (setq agent gnus-agent-summary-mode))
6954 (when (boundp 'gnus-draft-mode)
6955 (setq draft gnus-draft-mode)))
6956 (with-temp-buffer
6957 (use-local-map keymap)
6958 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6959 (set (make-local-variable 'gnus-draft-mode) draft)
6960 (describe-bindings prefix))
6961 (let ((item `((lambda (prefix)
6962 (with-current-buffer ,(current-buffer)
6963 (gnus-article-describe-bindings prefix)))
6964 ,prefix)))
6965 ;; Loading `help-mode' here is necessary if `describe-bindings'
6966 ;; is replaced with something, e.g. `helm-descbinds'.
6967 (require 'help-mode)
6968 (with-current-buffer (let (help-xref-following) (help-buffer))
6969 (setq help-xref-stack-item item)))))
6970
6971 (defun gnus-article-reply-with-original (&optional wide)
6972 "Start composing a reply mail to the current message.
6973 The text in the region will be yanked. If the region isn't active,
6974 the entire article will be yanked."
6975 (interactive)
6976 (let ((article (cdr gnus-article-current))
6977 contents)
6978 (if (not (gnus-region-active-p))
6979 (with-current-buffer gnus-summary-buffer
6980 (gnus-summary-reply (list (list article)) wide))
6981 (setq contents (buffer-substring (point) (mark t)))
6982 ;; Deactivate active regions.
6983 (when (and (boundp 'transient-mark-mode)
6984 transient-mark-mode)
6985 (setq mark-active nil))
6986 (with-current-buffer gnus-summary-buffer
6987 (gnus-summary-reply
6988 (list (list article contents)) wide)))))
6989
6990 (defun gnus-article-wide-reply-with-original ()
6991 "Start composing a wide reply mail to the current message.
6992 The text in the region will be yanked. If the region isn't active,
6993 the entire article will be yanked."
6994 (interactive)
6995 (gnus-article-reply-with-original t))
6996
6997 (defun gnus-article-followup-with-original ()
6998 "Compose a followup to the current article.
6999 The text in the region will be yanked. If the region isn't active,
7000 the entire article will be yanked."
7001 (interactive)
7002 (let ((article (cdr gnus-article-current))
7003 contents)
7004 (if (not (gnus-region-active-p))
7005 (with-current-buffer gnus-summary-buffer
7006 (gnus-summary-followup (list (list article))))
7007 (setq contents (buffer-substring (point) (mark t)))
7008 ;; Deactivate active regions.
7009 (when (and (boundp 'transient-mark-mode)
7010 transient-mark-mode)
7011 (setq mark-active nil))
7012 (with-current-buffer gnus-summary-buffer
7013 (gnus-summary-followup
7014 (list (list article contents)))))))
7015
7016 (defun gnus-article-hide (&optional arg force)
7017 "Hide all the gruft in the current article.
7018 This means that signatures, cited text and (some) headers will be
7019 hidden.
7020 If given a prefix, show the hidden text instead."
7021 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7022 (gnus-article-hide-headers arg)
7023 (gnus-article-hide-list-identifiers arg)
7024 (gnus-article-hide-citation-maybe arg force)
7025 (gnus-article-hide-signature arg))
7026
7027 (defun gnus-check-group-server ()
7028 ;; Make sure the connection to the server is alive.
7029 (unless (gnus-server-opened
7030 (gnus-find-method-for-group gnus-newsgroup-name))
7031 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7032 (gnus-request-group gnus-newsgroup-name t)))
7033
7034 (declare-function nneething-get-file-name "nneething" (id))
7035
7036 (defun gnus-request-article-this-buffer (article group)
7037 "Get an article and insert it into this buffer."
7038 (let (do-update-line sparse-header)
7039 (prog1
7040 (save-excursion
7041 (erase-buffer)
7042 (gnus-kill-all-overlays)
7043 (setq group (or group gnus-newsgroup-name))
7044
7045 ;; Using `gnus-request-article' directly will insert the article into
7046 ;; `nntp-server-buffer' - so we'll save some time by not having to
7047 ;; copy it from the server buffer into the article buffer.
7048
7049 ;; We only request an article by message-id when we do not have the
7050 ;; headers for it, so we'll have to get those.
7051 (when (stringp article)
7052 (gnus-read-header article))
7053
7054 ;; If the article number is negative, that means that this article
7055 ;; doesn't belong in this newsgroup (possibly), so we find its
7056 ;; message-id and request it by id instead of number.
7057 (when (and (numberp article)
7058 gnus-summary-buffer
7059 (get-buffer gnus-summary-buffer)
7060 (gnus-buffer-exists-p gnus-summary-buffer))
7061 (with-current-buffer gnus-summary-buffer
7062 (let ((header (gnus-summary-article-header article)))
7063 (when (< article 0)
7064 (cond
7065 ((memq article gnus-newsgroup-sparse)
7066 ;; This is a sparse gap article.
7067 (setq do-update-line article)
7068 (setq article (mail-header-id header))
7069 (setq sparse-header (gnus-read-header article))
7070 (setq gnus-newsgroup-sparse
7071 (delq article gnus-newsgroup-sparse)))
7072 ((vectorp header)
7073 ;; It's a real article.
7074 (setq article (mail-header-id header)))
7075 (t
7076 ;; It is an extracted pseudo-article.
7077 (setq article 'pseudo)
7078 (gnus-request-pseudo-article header))))
7079
7080 (let ((method (gnus-find-method-for-group
7081 gnus-newsgroup-name)))
7082 (when (and (eq (car method) 'nneething)
7083 (vectorp header))
7084 (let ((dir (nneething-get-file-name
7085 (mail-header-id header))))
7086 (when (and (stringp dir)
7087 (file-directory-p dir))
7088 (setq article 'nneething)
7089 (gnus-group-enter-directory dir))))))))
7090
7091 (cond
7092 ;; Refuse to select canceled articles.
7093 ((and (numberp article)
7094 gnus-summary-buffer
7095 (get-buffer gnus-summary-buffer)
7096 (gnus-buffer-exists-p gnus-summary-buffer)
7097 (eq (cdr (with-current-buffer gnus-summary-buffer
7098 (assq article gnus-newsgroup-reads)))
7099 gnus-canceled-mark))
7100 nil)
7101 ;; We first check `gnus-original-article-buffer'.
7102 ((and (get-buffer gnus-original-article-buffer)
7103 (numberp article)
7104 (with-current-buffer gnus-original-article-buffer
7105 (and (equal (car gnus-original-article) group)
7106 (eq (cdr gnus-original-article) article))))
7107 ;; `insert-buffer-substring' would incorrectly use the
7108 ;; equivalent of string-make-multibyte which amount to decoding
7109 ;; with locale-coding-system, causing failure of
7110 ;; subsequent decoding.
7111 (insert (mm-string-to-multibyte
7112 (with-current-buffer gnus-original-article-buffer
7113 (buffer-substring (point-min) (point-max)))))
7114 'article)
7115 ;; Check the backlog.
7116 ((and gnus-keep-backlog
7117 (gnus-backlog-request-article group article (current-buffer)))
7118 'article)
7119 ;; Check asynchronous pre-fetch.
7120 ((gnus-async-request-fetched-article group article (current-buffer))
7121 (gnus-async-prefetch-next group article gnus-summary-buffer)
7122 (when (and (numberp article) gnus-keep-backlog)
7123 (gnus-backlog-enter-article group article (current-buffer)))
7124 'article)
7125 ;; Check the cache.
7126 ((and gnus-use-cache
7127 (numberp article)
7128 (gnus-cache-request-article article group))
7129 'article)
7130 ;; Check the agent cache.
7131 ((gnus-agent-request-article article group)
7132 'article)
7133 ;; Get the article and put into the article buffer.
7134 ((or (stringp article)
7135 (numberp article))
7136 (let ((gnus-override-method gnus-override-method)
7137 (methods (and (stringp article)
7138 (with-current-buffer gnus-summary-buffer
7139 (gnus-refer-article-methods))))
7140 (backend (car (gnus-find-method-for-group
7141 gnus-newsgroup-name)))
7142 result
7143 (inhibit-read-only t))
7144 (when (and (null gnus-override-method)
7145 methods)
7146 (setq gnus-override-method (pop methods)))
7147 (while (not result)
7148 (erase-buffer)
7149 (gnus-kill-all-overlays)
7150 (let ((gnus-newsgroup-name group))
7151 (gnus-check-group-server))
7152 (cond
7153 ((gnus-request-article article group (current-buffer))
7154 (when (numberp article)
7155 (gnus-async-prefetch-next group article
7156 gnus-summary-buffer)
7157 (when gnus-keep-backlog
7158 (gnus-backlog-enter-article
7159 group article (current-buffer)))
7160 (when (and gnus-agent
7161 (gnus-agent-group-covered-p group))
7162 (gnus-agent-store-article article group)))
7163 (setq result 'article))
7164 (methods
7165 (setq gnus-override-method (pop methods)))
7166 ((not (string-match "^400 "
7167 (nnheader-get-report backend)))
7168 ;; If we get 400 server disconnect, reconnect and
7169 ;; retry; otherwise, assume the article has expired.
7170 (setq result 'done))))
7171 (and (eq result 'article) 'article)))
7172 ;; It was a pseudo.
7173 (t article)))
7174
7175 ;; Associate this article with the current summary buffer.
7176 (setq gnus-article-current-summary gnus-summary-buffer)
7177
7178 ;; Take the article from the original article buffer
7179 ;; and place it in the buffer it's supposed to be in.
7180 (when (and (get-buffer gnus-article-buffer)
7181 (equal (buffer-name (current-buffer))
7182 (buffer-name (get-buffer gnus-article-buffer))))
7183 (save-excursion
7184 (if (get-buffer gnus-original-article-buffer)
7185 (set-buffer gnus-original-article-buffer)
7186 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7187 (buffer-disable-undo)
7188 (setq major-mode 'gnus-original-article-mode)
7189 (setq buffer-read-only t))
7190 (let ((inhibit-read-only t))
7191 (erase-buffer)
7192 (insert-buffer-substring gnus-article-buffer))
7193 (setq gnus-original-article (cons group article)))
7194
7195 ;; Decode charsets.
7196 (run-hooks 'gnus-article-decode-hook)
7197 ;; Mark article as decoded or not.
7198 (setq gnus-article-decoded-p gnus-article-decode-hook))
7199
7200 ;; Update sparse articles.
7201 (when (and do-update-line
7202 (or (numberp article)
7203 (stringp article)))
7204 (let ((buf (current-buffer)))
7205 (set-buffer gnus-summary-buffer)
7206 (gnus-summary-update-article do-update-line sparse-header)
7207 (gnus-summary-goto-subject do-update-line nil t)
7208 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7209 (point))
7210 (set-buffer buf))))))
7211
7212 (defun gnus-block-private-groups (group)
7213 "Allows images in newsgroups to be shown, blocks images in all
7214 other groups."
7215 (if (or (gnus-news-group-p group)
7216 (gnus-member-of-valid 'global group))
7217 ;; Block nothing in news groups.
7218 nil
7219 ;; Block everything anywhere else.
7220 "."))
7221
7222 (defun gnus-blocked-images ()
7223 (if (functionp gnus-blocked-images)
7224 (funcall gnus-blocked-images gnus-newsgroup-name)
7225 gnus-blocked-images))
7226
7227 ;;;
7228 ;;; Article editing
7229 ;;;
7230
7231 (defcustom gnus-article-edit-mode-hook nil
7232 "Hook run in article edit mode buffers."
7233 :group 'gnus-article-various
7234 :type 'hook)
7235
7236 (defvar gnus-article-edit-done-function nil)
7237
7238 (defvar gnus-article-edit-mode-map nil)
7239
7240 ;; Should we be using derived.el for this?
7241 (unless gnus-article-edit-mode-map
7242 (setq gnus-article-edit-mode-map (make-keymap))
7243 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7244
7245 (gnus-define-keys gnus-article-edit-mode-map
7246 "\C-c?" describe-mode
7247 "\C-c\C-c" gnus-article-edit-done
7248 "\C-c\C-k" gnus-article-edit-exit
7249 "\C-c\C-f\C-t" message-goto-to
7250 "\C-c\C-f\C-o" message-goto-from
7251 "\C-c\C-f\C-b" message-goto-bcc
7252 ;;"\C-c\C-f\C-w" message-goto-fcc
7253 "\C-c\C-f\C-c" message-goto-cc
7254 "\C-c\C-f\C-s" message-goto-subject
7255 "\C-c\C-f\C-r" message-goto-reply-to
7256 "\C-c\C-f\C-n" message-goto-newsgroups
7257 "\C-c\C-f\C-d" message-goto-distribution
7258 "\C-c\C-f\C-f" message-goto-followup-to
7259 "\C-c\C-f\C-m" message-goto-mail-followup-to
7260 "\C-c\C-f\C-k" message-goto-keywords
7261 "\C-c\C-f\C-u" message-goto-summary
7262 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7263 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7264 "\C-c\C-b" message-goto-body
7265 "\C-c\C-i" message-goto-signature
7266
7267 "\C-c\C-t" message-insert-to
7268 "\C-c\C-n" message-insert-newsgroups
7269 "\C-c\C-o" message-sort-headers
7270 "\C-c\C-e" message-elide-region
7271 "\C-c\C-v" message-delete-not-region
7272 "\C-c\C-z" message-kill-to-signature
7273 "\M-\r" message-newline-and-reformat
7274 "\C-c\C-a" mml-attach-file
7275 "\C-a" message-beginning-of-line
7276 "\t" message-tab
7277 "\M-;" comment-region)
7278
7279 (gnus-define-keys (gnus-article-edit-wash-map
7280 "\C-c\C-w" gnus-article-edit-mode-map)
7281 "f" gnus-article-edit-full-stops))
7282
7283 (easy-menu-define
7284 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7285 '("Field"
7286 ["Fetch To" message-insert-to t]
7287 ["Fetch Newsgroups" message-insert-newsgroups t]
7288 "----"
7289 ["To" message-goto-to t]
7290 ["From" message-goto-from t]
7291 ["Subject" message-goto-subject t]
7292 ["Cc" message-goto-cc t]
7293 ["Reply-To" message-goto-reply-to t]
7294 ["Summary" message-goto-summary t]
7295 ["Keywords" message-goto-keywords t]
7296 ["Newsgroups" message-goto-newsgroups t]
7297 ["Followup-To" message-goto-followup-to t]
7298 ["Mail-Followup-To" message-goto-mail-followup-to t]
7299 ["Distribution" message-goto-distribution t]
7300 ["Body" message-goto-body t]
7301 ["Signature" message-goto-signature t]))
7302
7303 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7304 "Major mode for editing articles.
7305 This is an extended text-mode.
7306
7307 \\{gnus-article-edit-mode-map}"
7308 (make-local-variable 'gnus-article-edit-done-function)
7309 (make-local-variable 'gnus-prev-winconf)
7310 (set (make-local-variable 'font-lock-defaults)
7311 '(message-font-lock-keywords t))
7312 (set (make-local-variable 'mail-header-separator) "")
7313 (set (make-local-variable 'gnus-article-edit-mode) t)
7314 (easy-menu-add message-mode-field-menu message-mode-map)
7315 (mml-mode)
7316 (setq buffer-read-only nil)
7317 (buffer-enable-undo)
7318 (widen))
7319
7320 (defun gnus-article-edit (&optional force)
7321 "Edit the current article.
7322 This will have permanent effect only in mail groups.
7323 If FORCE is non-nil, allow editing of articles even in read-only
7324 groups."
7325 (interactive "P")
7326 (when (and (not force)
7327 (gnus-group-read-only-p))
7328 (error "The current newsgroup does not support article editing"))
7329 (gnus-article-date-original)
7330 (gnus-article-edit-article
7331 'ignore
7332 `(lambda (no-highlight)
7333 'ignore
7334 (gnus-summary-edit-article-done
7335 ,(or (mail-header-references gnus-current-headers) "")
7336 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7337
7338 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7339 "Start editing the contents of the current article buffer."
7340 (let ((winconf (current-window-configuration)))
7341 (set-buffer gnus-article-buffer)
7342 (let ((message-auto-save-directory
7343 ;; Don't associate the article buffer with a draft file.
7344 nil))
7345 (gnus-article-edit-mode))
7346 (funcall start-func)
7347 (set-buffer-modified-p nil)
7348 (gnus-configure-windows 'edit-article)
7349 (setq gnus-article-edit-done-function exit-func)
7350 (setq gnus-prev-winconf winconf)
7351 (unless quiet
7352 (gnus-message 6 "C-c C-c to end edits"))))
7353
7354 (defun gnus-article-edit-done (&optional arg)
7355 "Update the article edits and exit."
7356 (interactive "P")
7357 (let ((func gnus-article-edit-done-function)
7358 (buf (current-buffer))
7359 (start (window-start))
7360 (winconf gnus-prev-winconf))
7361 (widen) ;; Widen it in case that users narrowed the buffer.
7362 (funcall func arg)
7363 (set-buffer buf)
7364 ;; The cache and backlog have to be flushed somewhat.
7365 (when gnus-keep-backlog
7366 (gnus-backlog-remove-article
7367 (car gnus-article-current) (cdr gnus-article-current)))
7368 ;; Flush original article as well.
7369 (gnus-flush-original-article-buffer)
7370 (when gnus-use-cache
7371 (gnus-cache-update-article
7372 (car gnus-article-current) (cdr gnus-article-current)))
7373 ;; We remove all text props from the article buffer.
7374 (kill-all-local-variables)
7375 (set-text-properties (point-min) (point-max) nil)
7376 (gnus-article-mode)
7377 (set-window-configuration winconf)
7378 (set-buffer buf)
7379 (set-window-start (get-buffer-window buf) start)
7380 (set-window-point (get-buffer-window buf) (point)))
7381 (gnus-summary-show-article))
7382
7383 (defun gnus-flush-original-article-buffer ()
7384 (when (get-buffer gnus-original-article-buffer)
7385 (with-current-buffer gnus-original-article-buffer
7386 (setq gnus-original-article nil))))
7387
7388 (defun gnus-article-edit-exit ()
7389 "Exit the article editing without updating."
7390 (interactive)
7391 (when (or (not (buffer-modified-p))
7392 (yes-or-no-p "Article modified; kill anyway? "))
7393 (let ((curbuf (current-buffer))
7394 (p (point))
7395 (window-start (window-start)))
7396 (erase-buffer)
7397 (if (gnus-buffer-live-p gnus-original-article-buffer)
7398 (insert-buffer-substring gnus-original-article-buffer))
7399 (let ((winconf gnus-prev-winconf))
7400 (kill-all-local-variables)
7401 (gnus-article-mode)
7402 (set-window-configuration winconf)
7403 ;; Tippy-toe some to make sure that point remains where it was.
7404 (save-current-buffer
7405 (set-buffer curbuf)
7406 (set-window-start (get-buffer-window (current-buffer)) window-start)
7407 (goto-char p))))
7408 (gnus-summary-show-article)))
7409
7410 (defun gnus-article-edit-full-stops ()
7411 "Interactively repair spacing at end of sentences."
7412 (interactive)
7413 (save-excursion
7414 (goto-char (point-min))
7415 (search-forward-regexp "^$" nil t)
7416 (let ((case-fold-search nil))
7417 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7418
7419 ;;;
7420 ;;; Article highlights
7421 ;;;
7422
7423 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7424
7425 ;;; Internal Variables:
7426
7427 (defcustom gnus-button-url-regexp
7428 (concat
7429 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7430 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7431 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7432 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7433 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7434 (punct "!?:;.,"))
7435 (concat
7436 "\\(?:"
7437 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7438 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7439 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7440 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7441 "\\|"
7442 "[" chars punct "]+" "[" chars "]"
7443 "\\)"))
7444 (concat ;; XEmacs 21.4 doesn't support POSIX.
7445 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7446 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7447 "\\)")
7448 "Regular expression that matches URLs."
7449 :version "24.4"
7450 :group 'gnus-article-buttons
7451 :type 'regexp)
7452
7453 (defcustom gnus-button-valid-fqdn-regexp
7454 message-valid-fqdn-regexp
7455 "Regular expression that matches a valid FQDN."
7456 :version "22.1"
7457 :group 'gnus-article-buttons
7458 :type 'regexp)
7459
7460 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7461 (defcustom gnus-button-valid-localpart-regexp
7462 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7463 "Regular expression that matches a localpart of mail addresses or MIDs."
7464 :version "22.1"
7465 :group 'gnus-article-buttons
7466 :type 'regexp)
7467
7468 (defcustom gnus-button-man-handler 'manual-entry
7469 "Function to use for displaying man pages.
7470 The function must take at least one argument with a string naming the
7471 man page."
7472 :version "22.1"
7473 :type '(choice (function-item :tag "Man" manual-entry)
7474 (function-item :tag "Woman" woman)
7475 (function :tag "Other"))
7476 :group 'gnus-article-buttons)
7477
7478 (defcustom gnus-button-mid-or-mail-regexp
7479 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7480 gnus-button-valid-fqdn-regexp
7481 ">?\\)\\b")
7482 "Regular expression that matches a message ID or a mail address."
7483 :version "22.1"
7484 :group 'gnus-article-buttons
7485 :type 'regexp)
7486
7487 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7488 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7489 Strings like this can be either a message ID or a mail address. If it is one
7490 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7491 message ID or a mail address, respectively. If this variable is set to the
7492 symbol `ask', always query the user what do do. If it is a function, this
7493 function will be called with the string as its only argument. The function
7494 must return `mid', `mail', `invalid' or `ask'."
7495 :version "22.1"
7496 :group 'gnus-article-buttons
7497 :type '(choice (function-item :tag "Heuristic function"
7498 gnus-button-mid-or-mail-heuristic)
7499 (const ask)
7500 (const mid)
7501 (const mail)))
7502
7503 (defcustom gnus-button-mid-or-mail-heuristic-alist
7504 '((-10.0 . ".+\\$.+@")
7505 (-10.0 . "#")
7506 (-10.0 . "\\*")
7507 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7508 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7509 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7510 (-1.0 . "^[^a-z]+@")
7511 ;;
7512 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7513 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7514 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7515 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7516 ;;
7517 (-2.0 . "^[0-9]")
7518 (-1.0 . "^[0-9][0-9]")
7519 ;;
7520 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7521 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7522 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7523 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7524 ;;
7525 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7526 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7527 ;; "[0-9]{8,}.*\@"
7528 (-3.0
7529 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7530 ;; "[0-9]{12,}.*\@"
7531 ;; compensation for TDMA dated mail addresses:
7532 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7533 ;;
7534 (-20.0 . "\\.fsf@") ;; Gnus
7535 (-20.0 . "^slrn")
7536 (-20.0 . "^Pine")
7537 (-20.0 . "^alpine\\.")
7538 (-20.0 . "_-_") ;; Subject change in thread
7539 ;;
7540 (-20.0 . "\\.ln@") ;; leafnode
7541 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7542 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7543 ;;
7544 ;; (5.0 . "") ;; $local_part_len <= 7
7545 (10.0 . "^[^0-9]+@")
7546 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7547 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7548 (3.0 . "\@stud")
7549 ;;
7550 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7551 ;;
7552 (0.5 . "^[A-Z][a-z]")
7553 (0.5 . "^[A-Z][a-z][a-z]")
7554 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7555 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7556 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7557
7558 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7559 address. The REGEXP is processed with `case-fold-search' set to nil."
7560 :version "22.1"
7561 :group 'gnus-article-buttons
7562 :type '(repeat (cons (number :tag "Rate")
7563 (regexp :tag "Regexp"))))
7564
7565 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7566 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7567 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7568 address, `ask' if unsure and `invalid' if the string is invalid."
7569 (let ((case-fold-search nil)
7570 (list gnus-button-mid-or-mail-heuristic-alist)
7571 (result 0) rate regexp lpartlen elem)
7572 (setq lpartlen
7573 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7574 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7575 ;; Certain special cases...
7576 (when (string-match
7577 (concat
7578 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7579 "^[0-9]+\\.[0-9]+@compuserve\\|"
7580 "@public\\.gmane\\.org")
7581 mid-or-mail)
7582 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7583 (setq result 'mail))
7584 (when (string-match "@.*@\\| " mid-or-mail)
7585 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7586 (setq result 'invalid))
7587 ;; Nothing more to do, if result is not a number here...
7588 (when (numberp result)
7589 (while list
7590 (setq elem (car list)
7591 rate (car elem)
7592 regexp (cdr elem)
7593 list (cdr list))
7594 (when (string-match regexp mid-or-mail)
7595 (setq result (+ result rate))
7596 (gnus-message
7597 9 "`%s' matched `%s', rate `%s', result `%s'."
7598 mid-or-mail regexp rate result)))
7599 (when (<= lpartlen 7)
7600 (setq result (+ result 5.0))
7601 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7602 mid-or-mail result))
7603 (when (>= lpartlen 12)
7604 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7605 (cond
7606 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7607 ;; Long local part should contain realname if e-mail address,
7608 ;; too many digits: message-id.
7609 ;; $score -= 5.0 + 0.1 * $local_part_len;
7610 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7611 (setq result (+ result rate))
7612 (gnus-message
7613 9 "Many digits in `%s', rate `%s', result `%s'."
7614 mid-or-mail rate result))
7615 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7616 mid-or-mail)
7617 ;; Too few vowels [^aeiouy]{4,}.*\@
7618 (setq result (+ result -5.0))
7619 (gnus-message
7620 9 "Few vowels in `%s', rate `%s', result `%s'."
7621 mid-or-mail -5.0 result))
7622 (t
7623 (setq result (+ result 5.0))
7624 (gnus-message
7625 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7626 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7627 ;; Maybe we should make this a customizable alist: (condition . 'result)
7628 (cond
7629 ((symbolp result) result)
7630 ;; Now convert number into proper results:
7631 ((< result -10.0) 'mid)
7632 ((> result 10.0) 'mail)
7633 (t 'ask))))
7634
7635 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7636 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7637 (url-mid (concat "news" ":" mid-or-mail))
7638 (url-mailto (concat "mailto" ":" mid-or-mail)))
7639 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7640 (when (fboundp pref)
7641 (setq guessed
7642 ;; get rid of surrounding angles...
7643 (funcall pref
7644 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7645 (if (or (eq 'mid guessed) (eq 'mail guessed))
7646 (setq pref guessed)
7647 (setq pref 'ask)))
7648 (if (eq pref 'ask)
7649 (save-window-excursion
7650 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7651 (setq pref 'mail)
7652 (setq pref 'mid))))
7653 (cond ((eq pref 'mid)
7654 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7655 (gnus-button-handle-news url-mid))
7656 ((eq pref 'mail)
7657 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7658 (gnus-url-mailto url-mailto))
7659 (t (gnus-message 3 "Invalid string.")))))
7660
7661 (defun gnus-button-handle-custom (fun arg)
7662 "Call function FUN on argument ARG.
7663 Both FUN and ARG are supposed to be strings. ARG will be passed
7664 as a symbol to FUN."
7665 (funcall (intern fun)
7666 (if (string-match "^customize-apropos" fun)
7667 arg
7668 (intern arg))))
7669
7670 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7671
7672 (defun gnus-button-handle-describe-function (url)
7673 "Call `describe-function' when pushing the corresponding URL button."
7674 (describe-function
7675 (intern
7676 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7677
7678 (defun gnus-button-handle-describe-variable (url)
7679 "Call `describe-variable' when pushing the corresponding URL button."
7680 (describe-variable
7681 (intern
7682 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7683
7684 (defun gnus-button-handle-symbol (url)
7685 "Display help on variable or function.
7686 Calls `describe-variable' or `describe-function'."
7687 (let ((sym (intern url)))
7688 (cond
7689 ((fboundp sym) (describe-function sym))
7690 ((boundp sym) (describe-variable sym))
7691 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7692
7693 (defun gnus-button-handle-describe-key (url)
7694 "Call `describe-key' when pushing the corresponding URL button."
7695 (let* ((key-string
7696 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7697 (keys (ignore-errors (eval `(kbd ,key-string)))))
7698 (if keys
7699 (describe-key keys)
7700 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7701
7702 (defun gnus-button-handle-apropos (url)
7703 "Call `apropos' when pushing the corresponding URL button."
7704 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7705
7706 (defun gnus-button-handle-apropos-command (url)
7707 "Call `apropos' when pushing the corresponding URL button."
7708 (apropos-command
7709 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7710
7711 (defun gnus-button-handle-apropos-variable (url)
7712 "Call `apropos' when pushing the corresponding URL button."
7713 (funcall
7714 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7715 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7716
7717 (defun gnus-button-handle-apropos-documentation (url)
7718 "Call `apropos' when pushing the corresponding URL button."
7719 (funcall
7720 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7721 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7722
7723 (defun gnus-button-handle-library (url)
7724 "Call `locate-library' when pushing the corresponding URL button."
7725 (gnus-message 9 "url=`%s'" url)
7726 (let* ((lib (locate-library url))
7727 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7728 (if (not lib)
7729 (gnus-message 1 "Cannot locale library `%s'." url)
7730 (find-file-read-only file))))
7731
7732 (defcustom gnus-button-man-level 5
7733 "*Integer that says how many man-related buttons Gnus will show.
7734 The higher the number, the more buttons will appear and the more false
7735 positives are possible. Note that you can set this variable local to
7736 specific groups. Setting it higher in Unix groups is probably a good idea.
7737 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7738 how to set variables in specific groups."
7739 :version "22.1"
7740 :group 'gnus-article-buttons
7741 :link '(custom-manual "(gnus)Group Parameters")
7742 :type 'integer)
7743
7744 (defcustom gnus-button-emacs-level 5
7745 "*Integer that says how many emacs-related buttons Gnus will show.
7746 The higher the number, the more buttons will appear and the more false
7747 positives are possible. Note that you can set this variable local to
7748 specific groups. Setting it higher in Emacs or Gnus related groups is
7749 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7750 `gnus-parameters' on how to set variables in specific groups."
7751 :version "22.1"
7752 :group 'gnus-article-buttons
7753 :link '(custom-manual "(gnus)Group Parameters")
7754 :type 'integer)
7755
7756 (defcustom gnus-button-message-level 5
7757 "*Integer that says how many buttons for news or mail messages will appear.
7758 The higher the number, the more buttons will appear and the more false
7759 positives are possible."
7760 ;; mail addresses, MIDs, URLs for news, ...
7761 :version "22.1"
7762 :group 'gnus-article-buttons
7763 :type 'integer)
7764
7765 (defcustom gnus-button-browse-level 5
7766 "*Integer that says how many buttons for browsing will appear.
7767 The higher the number, the more buttons will appear and the more false
7768 positives are possible."
7769 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7770 :version "22.1"
7771 :group 'gnus-article-buttons
7772 :type 'integer)
7773
7774 (defcustom gnus-button-alist
7775 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7776 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7777 ((concat "\\b\\(nntp\\|news\\):\\("
7778 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7779 0 t gnus-button-handle-news 2)
7780 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7781 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7782 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7783 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7784 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7785 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7786 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7787 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7788 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7789 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7790 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7791 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7792 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7793 ;; RFC 2368 (The mailto URL scheme)
7794 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7795 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7796 ("\\bmailto:\\([^ \n\t]+\\)"
7797 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7798 ;; Info Konqueror style <info:/foo/bar baz>.
7799 ;; Must come before " Gnus home-grown style".
7800 ("\\binfo://?\\([^'\">\n\t]+\\)"
7801 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7802 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7803 ("\\binfo://\\([^'\">\n\t ]+\\)"
7804 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7805 ;; Info GNOME style <info:foo#bar_baz>
7806 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7807 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7808 ;; Info KDE style <info:(foo)bar baz>
7809 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7810 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7811 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7812 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7813 ("\\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,]*\\)\\)?"
7814 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7815 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7816 ;; This is custom
7817 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7818 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7819 ;; Emacs help commands
7820 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7821 ;; regexp doesn't match arguments containing ` '.
7822 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7823 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7824 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7825 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7826 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7827 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7828 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7829 ;; The following entries may lead to many false positives so don't enable
7830 ;; them by default (use a high button level).
7831 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7832 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7833 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7834 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7835 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7836 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7837 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7838 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7839 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7840 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7841 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7842 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7843 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7844 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7845 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7846 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7847 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7848 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7849 ;; Unlike the other regexps we really have to require quoting
7850 ;; here to determine where it ends.
7851 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7852 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7853 ("<URL: *\\([^\n<>]*\\)>"
7854 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7855 ;; RFC 2396 (2.4.3., delims) ...
7856 ("\"URL: *\\([^\n\"]*\\)\""
7857 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7858 ;; Raw URLs.
7859 (gnus-button-url-regexp
7860 0 (>= gnus-button-browse-level 0) browse-url 0)
7861 ;; man pages
7862 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7863 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7864 gnus-button-handle-man 1)
7865 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7866 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7867 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7868 gnus-button-handle-man 1)
7869 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7870 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7871 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7872 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7873 ;; Recognizing patches to .el files. This is somewhat obscure,
7874 ;; but considering the percentage of Gnus users who hack Emacs
7875 ;; Lisp files...
7876 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7877 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7878 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7879 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7880 ;; MID or mail: To avoid too many false positives we don't try to catch
7881 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7882 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7883 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7884 ;; so that non-ambiguous entries (see above) match first.
7885 (gnus-button-mid-or-mail-regexp
7886 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7887 "*Alist of regexps matching buttons in article bodies.
7888
7889 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7890 REGEXP: is the string (case insensitive) matching text around the button (can
7891 also be Lisp expression evaluating to a string),
7892 BUTTON: is the number of the regexp grouping actually matching the button,
7893 FORM: is a Lisp expression which must eval to true for the button to
7894 be added,
7895 CALLBACK: is the function to call when the user push this button, and each
7896 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7897
7898 CALLBACK can also be a variable, in that case the value of that
7899 variable it the real callback function."
7900 :group 'gnus-article-buttons
7901 :type '(repeat (list (choice regexp variable sexp)
7902 (integer :tag "Button")
7903 (sexp :tag "Form")
7904 (function :tag "Callback")
7905 (repeat :tag "Par"
7906 :inline t
7907 (integer :tag "Regexp group")))))
7908 (put 'gnus-button-alist 'risky-local-variable t)
7909
7910 (defcustom gnus-header-button-alist
7911 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7912 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7913 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7914 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7915 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7916 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7917 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7918 0 (>= gnus-button-browse-level 0) browse-url 0)
7919 ("^Subject:" gnus-button-url-regexp
7920 0 (>= gnus-button-browse-level 0) browse-url 0)
7921 ("^[^:]+:" gnus-button-url-regexp
7922 0 (>= gnus-button-browse-level 0) browse-url 0)
7923 ("^OpenPGP:.*url=" gnus-button-url-regexp
7924 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7925 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7926 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7927 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7928 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7929 "*Alist of headers and regexps to match buttons in article heads.
7930
7931 This alist is very similar to `gnus-button-alist', except that each
7932 alist has an additional HEADER element first in each entry:
7933
7934 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7935
7936 HEADER is a regexp to match a header. For a fuller explanation, see
7937 `gnus-button-alist'."
7938 :group 'gnus-article-buttons
7939 :group 'gnus-article-headers
7940 :type '(repeat (list (regexp :tag "Header")
7941 (choice regexp variable)
7942 (integer :tag "Button")
7943 (sexp :tag "Form")
7944 (function :tag "Callback")
7945 (repeat :tag "Par"
7946 :inline t
7947 (integer :tag "Regexp group")))))
7948 (put 'gnus-header-button-alist 'risky-local-variable t)
7949
7950 ;;; Commands:
7951
7952 (defun gnus-article-push-button (event)
7953 "Check text under the mouse pointer for a callback function.
7954 If the text under the mouse pointer has a `gnus-callback' property,
7955 call it with the value of the `gnus-data' text property."
7956 (interactive "e")
7957 (set-buffer (window-buffer (posn-window (event-start event))))
7958 (let* ((pos (posn-point (event-start event)))
7959 (data (get-text-property pos 'gnus-data))
7960 (fun (get-text-property pos 'gnus-callback)))
7961 (goto-char pos)
7962 (when fun
7963 (funcall fun data))))
7964
7965 (defun gnus-article-press-button ()
7966 "Check text at point for a callback function.
7967 If the text at point has a `gnus-callback' property,
7968 call it with the value of the `gnus-data' text property."
7969 (interactive)
7970 (let ((data (get-text-property (point) 'gnus-data))
7971 (fun (get-text-property (point) 'gnus-callback)))
7972 (when fun
7973 (funcall fun data))))
7974
7975 (defun gnus-article-highlight (&optional force)
7976 "Highlight current article.
7977 This function calls `gnus-article-highlight-headers',
7978 `gnus-article-highlight-citation',
7979 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7980 do the highlighting. See the documentation for those functions."
7981 (interactive (list 'force))
7982 (gnus-article-highlight-headers)
7983 (gnus-article-highlight-citation force)
7984 (gnus-article-highlight-signature)
7985 (gnus-article-add-buttons)
7986 (gnus-article-add-buttons-to-head))
7987
7988 (defun gnus-article-highlight-some (&optional _force)
7989 "Highlight current article.
7990 This function calls `gnus-article-highlight-headers',
7991 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7992 do the highlighting. See the documentation for those functions."
7993 (interactive (list 'force))
7994 (gnus-article-highlight-headers)
7995 (gnus-article-highlight-signature)
7996 (gnus-article-add-buttons))
7997
7998 (defun gnus-article-highlight-headers ()
7999 "Highlight article headers as specified by `gnus-header-face-alist'."
8000 (interactive)
8001 (gnus-with-article-headers
8002 (let (regexp header-face field-face from hpoints fpoints)
8003 (dolist (entry gnus-header-face-alist)
8004 (goto-char (point-min))
8005 (setq regexp (concat "^\\("
8006 (if (string-equal "" (nth 0 entry))
8007 "[^\t ]"
8008 (nth 0 entry))
8009 "\\)")
8010 header-face (nth 1 entry)
8011 field-face (nth 2 entry))
8012 (while (and (re-search-forward regexp nil t)
8013 (not (eobp)))
8014 (beginning-of-line)
8015 (setq from (point))
8016 (unless (search-forward ":" nil t)
8017 (forward-char 1))
8018 (when (and header-face
8019 (not (memq (point) hpoints)))
8020 (push (point) hpoints)
8021 (gnus-put-text-property from (point) 'face header-face))
8022 (when (and field-face
8023 (not (memq (setq from (point)) fpoints)))
8024 (push from fpoints)
8025 (if (re-search-forward "^[^ \t]" nil t)
8026 (forward-char -2)
8027 (goto-char (point-max)))
8028 (gnus-put-text-property from (point) 'face field-face)))))))
8029
8030 (defun gnus-article-highlight-signature ()
8031 "Highlight the signature in an article.
8032 It does this by highlighting everything after
8033 `gnus-signature-separator' using the face `gnus-signature'."
8034 (interactive)
8035 (gnus-with-article-buffer
8036 (let ((inhibit-point-motion-hooks t))
8037 (save-restriction
8038 (when (and gnus-signature-face
8039 (gnus-article-narrow-to-signature))
8040 (overlay-put (make-overlay (point-min) (point-max) nil t)
8041 'face gnus-signature-face)
8042 (widen)
8043 (gnus-article-search-signature)
8044 (let ((start (match-beginning 0))
8045 (end (set-marker (make-marker) (1+ (match-end 0)))))
8046 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8047 end)))))))
8048
8049 (defun gnus-button-in-region-p (b e prop)
8050 "Say whether PROP exists in the region."
8051 (text-property-not-all b e prop nil))
8052
8053 (defun gnus-article-add-buttons ()
8054 "Find external references in the article and make buttons of them.
8055 \"External references\" are things like Message-IDs and URLs, as
8056 specified by `gnus-button-alist'."
8057 (interactive)
8058 (gnus-with-article-buffer
8059 (let ((inhibit-point-motion-hooks t)
8060 (case-fold-search t)
8061 (alist gnus-button-alist)
8062 beg entry regexp)
8063 ;; We skip the headers.
8064 (article-goto-body)
8065 (setq beg (point))
8066 (while (setq entry (pop alist))
8067 (setq regexp (eval (car entry)))
8068 (goto-char beg)
8069 (while (re-search-forward regexp nil t)
8070 (let ((start (match-beginning (nth 1 entry)))
8071 (end (match-end (nth 1 entry)))
8072 (from (match-beginning 0)))
8073 (when (and (eval (nth 2 entry))
8074 (not (gnus-button-in-region-p
8075 start end 'gnus-callback)))
8076 ;; That optional form returned non-nil, so we add the
8077 ;; button.
8078 (setq from (set-marker (make-marker) from))
8079 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8080 (gnus-article-extend-url-button from start end))
8081 (gnus-article-add-button start end
8082 'gnus-button-push (list from entry))
8083 (gnus-put-text-property
8084 start end
8085 'gnus-string (buffer-substring-no-properties
8086 start end))))))))))
8087
8088 (defun gnus-article-extend-url-button (beg start end)
8089 "Extend url button if url is folded into two or more lines.
8090 Return non-nil if button is extended. BEG is a marker that points to
8091 the beginning position of a text containing url. START and END are
8092 the endpoints of a url button before it is extended. The concatenated
8093 url is put as the `gnus-button-url' overlay property on the button."
8094 (let ((opoint (point))
8095 (points (list start end))
8096 url delim regexp)
8097 (prog1
8098 (when (and (progn
8099 (goto-char end)
8100 (not (looking-at "[\t ]*[\">]")))
8101 (progn
8102 (goto-char start)
8103 (string-match
8104 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8105 (buffer-substring (point-at-bol) start)))
8106 (progn
8107 (setq url (list (buffer-substring start end))
8108 delim (if (match-beginning 1) ">" "\""))
8109 (beginning-of-line)
8110 (setq regexp (concat
8111 (when (and (looking-at
8112 message-cite-prefix-regexp)
8113 (< (match-end 0) start))
8114 (regexp-quote (match-string 0)))
8115 "\
8116 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8117 delim "\\)"))
8118 (while (progn
8119 (forward-line 1)
8120 (and (looking-at regexp)
8121 (prog1
8122 (match-beginning 1)
8123 (push (or (match-string 2)
8124 (match-string 1))
8125 url)
8126 (push (setq end (or (match-end 2)
8127 (match-end 1)))
8128 points)
8129 (push (or (match-beginning 2)
8130 (match-beginning 1))
8131 points)))))
8132 (match-beginning 2)))
8133 (let (gnus-article-mouse-face widget-mouse-face)
8134 (while points
8135 (gnus-article-add-button (pop points) (pop points)
8136 'gnus-button-push
8137 (list beg (assq 'gnus-button-url-regexp
8138 gnus-button-alist)))))
8139 (let ((overlay (make-overlay start end)))
8140 (overlay-put overlay 'evaporate t)
8141 (overlay-put overlay 'gnus-button-url
8142 (list (mapconcat 'identity (nreverse url) "")))
8143 (when gnus-article-mouse-face
8144 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8145 t)
8146 (goto-char opoint))))
8147
8148 ;; Add buttons to the head of an article.
8149 (defun gnus-article-add-buttons-to-head ()
8150 "Add buttons to the head of the article."
8151 (interactive)
8152 (gnus-with-article-headers
8153 (let (beg end)
8154 (dolist (entry gnus-header-button-alist)
8155 ;; Each alist entry.
8156 (goto-char (point-min))
8157 (while (re-search-forward (car entry) nil t)
8158 ;; Each header matching the entry.
8159 (setq beg (match-beginning 0))
8160 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8161 (match-beginning 0))
8162 (point-max)))
8163 (goto-char beg)
8164 (while (re-search-forward (eval (nth 1 entry)) end t)
8165 ;; Each match within a header.
8166 (let* ((entry (cdr entry))
8167 (start (match-beginning (nth 1 entry)))
8168 (end (match-end (nth 1 entry)))
8169 (form (nth 2 entry)))
8170 (goto-char (match-end 0))
8171 (when (eval form)
8172 (gnus-article-add-button
8173 start end (nth 3 entry)
8174 (buffer-substring (match-beginning (nth 4 entry))
8175 (match-end (nth 4 entry)))))))
8176 (goto-char end))))))
8177
8178 ;;; External functions:
8179
8180 (defun gnus-article-add-button (from to fun &optional data text)
8181 "Create a button between FROM and TO with callback FUN and data DATA."
8182 (when gnus-article-button-face
8183 (overlay-put (make-overlay from to nil t)
8184 'face gnus-article-button-face))
8185 (gnus-add-text-properties
8186 from to
8187 (nconc (and gnus-article-mouse-face
8188 (list gnus-mouse-face-prop gnus-article-mouse-face))
8189 (list 'gnus-callback fun)
8190 (and data (list 'gnus-data data))))
8191 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8192 :help-echo (or text "Follow the link")
8193 :keymap gnus-url-button-map
8194 :button-keymap gnus-widget-button-keymap))
8195
8196 (defun gnus-article-copy-string ()
8197 "Copy the string in the button to the kill ring."
8198 (interactive)
8199 (gnus-article-check-buffer)
8200 (let ((data (get-text-property (point) 'gnus-string)))
8201 (when data
8202 (with-temp-buffer
8203 (insert data)
8204 (copy-region-as-kill (point-min) (point-max))
8205 (message "Copied %s" data)))))
8206
8207 ;;; Internal functions:
8208
8209 (defun gnus-article-set-globals ()
8210 (with-current-buffer gnus-summary-buffer
8211 (gnus-set-global-variables)))
8212
8213 (defun gnus-signature-toggle (end)
8214 (gnus-with-article-buffer
8215 (let ((inhibit-point-motion-hooks t))
8216 (if (text-property-any end (point-max) 'article-type 'signature)
8217 (progn
8218 (gnus-delete-wash-type 'signature)
8219 (gnus-remove-text-properties-when
8220 'article-type 'signature end (point-max)
8221 (cons 'article-type (cons 'signature
8222 gnus-hidden-properties))))
8223 (gnus-add-wash-type 'signature)
8224 (gnus-add-text-properties-when
8225 'article-type nil end (point-max)
8226 (cons 'article-type (cons 'signature
8227 gnus-hidden-properties)))))
8228 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8229 (gnus-set-mode-line 'article))))
8230
8231 (defun gnus-button-push (marker-and-entry)
8232 ;; Push button starting at MARKER.
8233 (save-excursion
8234 (let* ((marker (car marker-and-entry))
8235 (entry (cadr marker-and-entry))
8236 (regexp (car entry))
8237 (inhibit-point-motion-hooks t))
8238 (goto-char marker)
8239 ;; This is obviously true, or something bad is happening :)
8240 ;; But we need it to have the match-data
8241 (when (looking-at (or (if (symbolp regexp)
8242 (symbol-value regexp)
8243 regexp)))
8244 (let ((fun (nth 3 entry))
8245 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8246 (get-char-property marker 'gnus-button-url))
8247 (mapcar (lambda (group)
8248 (let ((string (match-string group)))
8249 (set-text-properties
8250 0 (length string) nil string)
8251 string))
8252 (nthcdr 4 entry)))))
8253
8254 (cond
8255 ((fboundp fun)
8256 (apply fun args))
8257 ((and (boundp fun)
8258 (fboundp (symbol-value fun)))
8259 (apply (symbol-value fun) args))
8260 (t
8261 (gnus-message 1 "You must define `%S' to use this button"
8262 (cons fun args)))))))))
8263
8264 (defun gnus-parse-news-url (url)
8265 (let (scheme server port group message-id articles)
8266 (with-temp-buffer
8267 (insert url)
8268 (goto-char (point-min))
8269 (when (looking-at "\\([A-Za-z]+\\):")
8270 (setq scheme (match-string 1))
8271 (goto-char (match-end 0)))
8272 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8273 (setq server (match-string 1))
8274 (setq port (if (stringp (match-string 3))
8275 (string-to-number (match-string 3))
8276 (match-string 3)))
8277 (goto-char (match-end 0)))
8278
8279 (cond
8280 ((looking-at "\\(.*@.*\\)")
8281 (setq message-id (match-string 1)))
8282 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8283 (setq group (match-string 1)
8284 articles (split-string (match-string 2) "-")))
8285 ((looking-at "\\([^/]+\\)/?")
8286 (setq group (match-string 1)))
8287 (t
8288 (error "Unknown news URL syntax"))))
8289 (list scheme server port group message-id articles)))
8290
8291 (defvar nntp-port-number)
8292
8293 (defun gnus-button-handle-news (url)
8294 "Fetch a news URL."
8295 (destructuring-bind (_scheme server port group message-id _articles)
8296 (gnus-parse-news-url url)
8297 (cond
8298 (message-id
8299 (with-current-buffer gnus-summary-buffer
8300 (if server
8301 (let ((gnus-refer-article-method
8302 (nconc (list (list 'nntp server))
8303 gnus-refer-article-method))
8304 (nntp-port-number (or port "nntp")))
8305 (gnus-message 7 "Fetching %s with %s"
8306 message-id gnus-refer-article-method)
8307 (gnus-summary-refer-article message-id))
8308 (gnus-summary-refer-article message-id))))
8309 (group
8310 (gnus-button-fetch-group url)))))
8311
8312 (defun gnus-button-patch (library line)
8313 "Visit an Emacs Lisp library LIBRARY on line LINE."
8314 (interactive)
8315 (let ((file (locate-library (file-name-nondirectory library))))
8316 (unless file
8317 (error "Couldn't find library %s" library))
8318 (find-file file)
8319 (goto-char (point-min))
8320 (forward-line (1- (string-to-number line)))))
8321
8322 (defun gnus-button-handle-man (url)
8323 "Fetch a man page."
8324 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8325 (when (eq gnus-button-man-handler 'woman)
8326 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8327 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8328 (funcall gnus-button-man-handler url))
8329
8330 (defun gnus-button-handle-info-url (url)
8331 "Fetch an info URL."
8332 (setq url (mm-subst-char-in-string ?+ ?\ url))
8333 (cond
8334 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8335 (gnus-info-find-node
8336 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8337 "Gnus")
8338 ")" (gnus-url-unhex-string (match-string 2 url)))))
8339 ((string-match "([^)\"]+)[^\"]+" url)
8340 (setq url
8341 (gnus-replace-in-string
8342 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8343 (gnus-info-find-node url))
8344 (t (error "Can't parse %s" url))))
8345
8346 (defun gnus-button-handle-info-url-gnome (url)
8347 "Fetch GNOME style info URL."
8348 (setq url (mm-subst-char-in-string ?_ ?\ url))
8349 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8350 (gnus-info-find-node
8351 (concat "("
8352 (gnus-url-unhex-string
8353 (match-string 1 url))
8354 ")"
8355 (or (gnus-url-unhex-string
8356 (match-string 2 url))
8357 "Top")))
8358 (error "Can't parse %s" url)))
8359
8360 (defun gnus-button-handle-info-url-kde (url)
8361 "Fetch KDE style info URL."
8362 (gnus-info-find-node (gnus-url-unhex-string url)))
8363
8364 ;; (info) will autoload info.el
8365 (declare-function Info-menu "info" (menu-item &optional fork))
8366 (declare-function Info-index-next "info" (num))
8367
8368 (defun gnus-button-handle-info-keystrokes (url)
8369 "Call `info' when pushing the corresponding URL button."
8370 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8371 (let (node indx comma)
8372 (if (string-match
8373 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8374 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8375 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8376 "\\(?:[ \t\n,]*\\)\\)?")
8377 url)
8378 (setq node (match-string 2 url)
8379 indx (match-string 3 url))
8380 (error "Can't parse %s" url))
8381 (info)
8382 (Info-directory)
8383 (Info-menu node)
8384 (when (> (length indx) 0)
8385 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8386 "\\([ \t\n,]*\\)")
8387 indx)
8388 (setq comma (match-string 2 indx))
8389 (setq indx (match-string 1 indx))
8390 (Info-index indx)
8391 (when comma
8392 (dotimes (i (with-temp-buffer
8393 (insert comma)
8394 ;; Note: the XEmacs version of `how-many' takes
8395 ;; no optional argument.
8396 (goto-char (point-min))
8397 (how-many ",")))
8398 (Info-index-next 1)))
8399 nil)))
8400
8401 (autoload 'pgg-snarf-keys-region "pgg")
8402 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8403 (declare-function pgg-display-output-buffer "pgg" (start end status))
8404
8405 (defun gnus-button-openpgp (url)
8406 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8407 (with-temp-buffer
8408 (mm-url-insert-file-contents-external url)
8409 (pgg-snarf-keys-region (point-min) (point-max))
8410 (pgg-display-output-buffer nil nil nil)))
8411
8412 (defun gnus-button-message-id (message-id)
8413 "Fetch MESSAGE-ID."
8414 (with-current-buffer gnus-summary-buffer
8415 (gnus-summary-refer-article message-id)))
8416
8417 (defun gnus-button-fetch-group (address &rest _ignore)
8418 "Fetch GROUP specified by ADDRESS."
8419 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8420 address)
8421 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8422 ;; for nntp:// and news://
8423 (setq address (match-string 3 address)))
8424 (if (not (string-match "[:/]" address))
8425 ;; This is just a simple group url.
8426 (gnus-group-read-ephemeral-group address gnus-select-method)
8427 (if (not
8428 (string-match
8429 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8430 address))
8431 (error "Can't parse %s" address)
8432 (gnus-group-read-ephemeral-group
8433 (match-string 4 address)
8434 `(nntp ,(match-string 1 address)
8435 (nntp-address ,(match-string 1 address))
8436 (nntp-port-number ,(if (match-end 3)
8437 (match-string 3 address)
8438 "nntp")))
8439 nil nil nil
8440 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8441
8442 (defun gnus-url-parse-query-string (query &optional downcase)
8443 (let (retval pairs cur key val)
8444 (setq pairs (split-string query "&"))
8445 (while pairs
8446 (setq cur (car pairs)
8447 pairs (cdr pairs))
8448 (if (not (string-match "=" cur))
8449 nil ; Grace
8450 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8451 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8452 (if downcase
8453 (setq key (downcase key)))
8454 (setq cur (assoc key retval))
8455 (if cur
8456 (setcdr cur (cons val (cdr cur)))
8457 (setq retval (cons (list key val) retval)))))
8458 retval))
8459
8460 (defun gnus-url-mailto (url)
8461 ;; Send mail to someone
8462 (setq url (replace-regexp-in-string "\n" " " url))
8463 (when (string-match "mailto:/*\\(.*\\)" url)
8464 (setq url (substring url (match-beginning 1) nil)))
8465 (let* ((args (gnus-url-parse-query-string
8466 (if (string-match "^\\?" url)
8467 (substring url 1)
8468 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8469 (concat "to=" (match-string 1 url) "&"
8470 (match-string 2 url))
8471 (concat "to=" url)))))
8472 (subject (cdr-safe (assoc "subject" args)))
8473 func)
8474 (gnus-msg-mail)
8475 (while args
8476 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8477 (if (fboundp func)
8478 (funcall func)
8479 (message-position-on-field (caar args)))
8480 (insert (gnus-replace-in-string
8481 (mapconcat 'identity (reverse (cdar args)) ", ")
8482 "\r\n" "\n" t))
8483 (setq args (cdr args)))
8484 (if subject
8485 (message-goto-body)
8486 (message-goto-subject))))
8487
8488 (defun gnus-button-embedded-url (address)
8489 "Activate ADDRESS with `browse-url'."
8490 (browse-url (gnus-strip-whitespace address)))
8491
8492 ;;; Next/prev buttons in the article buffer.
8493
8494 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8495 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8496
8497 (defvar gnus-prev-page-map
8498 (let ((map (make-sparse-keymap)))
8499 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8500 (define-key map "\r" 'gnus-button-prev-page)
8501 map))
8502
8503 (defvar gnus-next-page-map
8504 (let ((map (make-sparse-keymap)))
8505 (define-key map gnus-mouse-2 'gnus-button-next-page)
8506 (define-key map "\r" 'gnus-button-next-page)
8507 map))
8508
8509 (defun gnus-insert-prev-page-button ()
8510 (let ((b (point)) e
8511 (inhibit-read-only t))
8512 (gnus-eval-format
8513 gnus-prev-page-line-format nil
8514 `(keymap ,gnus-prev-page-map
8515 gnus-prev t
8516 gnus-callback gnus-article-button-prev-page
8517 article-type annotation))
8518 (setq e (if (bolp)
8519 ;; Exclude a newline.
8520 (1- (point))
8521 (point)))
8522 (when gnus-article-button-face
8523 (overlay-put (make-overlay b e nil t)
8524 'face gnus-article-button-face))
8525 (widget-convert-button
8526 'link b e
8527 :action 'gnus-button-prev-page
8528 :button-keymap gnus-prev-page-map)))
8529
8530 (defun gnus-button-next-page (&optional _args _more-args)
8531 "Go to the next page."
8532 (interactive)
8533 (let ((win (selected-window)))
8534 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8535 (gnus-article-next-page)
8536 (select-window win)))
8537
8538 (defun gnus-button-prev-page (&optional _args _more-args)
8539 "Go to the prev page."
8540 (interactive)
8541 (let ((win (selected-window)))
8542 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8543 (gnus-article-prev-page)
8544 (select-window win)))
8545
8546 (defun gnus-insert-next-page-button ()
8547 (let ((b (point)) e
8548 (inhibit-read-only t))
8549 (gnus-eval-format gnus-next-page-line-format nil
8550 `(keymap ,gnus-next-page-map
8551 gnus-next t
8552 gnus-callback gnus-article-button-next-page
8553 article-type annotation))
8554 (setq e (if (bolp)
8555 ;; Exclude a newline.
8556 (1- (point))
8557 (point)))
8558 (when gnus-article-button-face
8559 (overlay-put (make-overlay b e nil t)
8560 'face gnus-article-button-face))
8561 (widget-convert-button
8562 'link b e
8563 :action 'gnus-button-next-page
8564 :button-keymap gnus-next-page-map)))
8565
8566 (defun gnus-article-button-next-page (_arg)
8567 "Go to the next page."
8568 (interactive "P")
8569 (let ((win (selected-window)))
8570 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8571 (gnus-article-next-page)
8572 (select-window win)))
8573
8574 (defun gnus-article-button-prev-page (_arg)
8575 "Go to the prev page."
8576 (interactive "P")
8577 (let ((win (selected-window)))
8578 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8579 (gnus-article-prev-page)
8580 (select-window win)))
8581
8582 (defvar gnus-decode-header-methods
8583 '(mail-decode-encoded-word-region)
8584 "List of methods used to decode headers.
8585
8586 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8587 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8588 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8589 whose names match REGEXP.
8590
8591 For example:
8592 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8593 mail-decode-encoded-word-region
8594 (\"chinese\" . rfc1843-decode-region))
8595 ")
8596
8597 (defvar gnus-decode-header-methods-cache nil)
8598
8599 (defun gnus-multi-decode-header (start end)
8600 "Apply the functions from `gnus-encoded-word-methods' that match."
8601 (unless (and gnus-decode-header-methods-cache
8602 (eq gnus-newsgroup-name
8603 (car gnus-decode-header-methods-cache)))
8604 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8605 (dolist (x gnus-decode-header-methods)
8606 (if (symbolp x)
8607 (nconc gnus-decode-header-methods-cache (list x))
8608 (if (and gnus-newsgroup-name
8609 (string-match (car x) gnus-newsgroup-name))
8610 (nconc gnus-decode-header-methods-cache
8611 (list (cdr x)))))))
8612 (let ((xlist gnus-decode-header-methods-cache))
8613 (pop xlist)
8614 (save-restriction
8615 (narrow-to-region start end)
8616 (while xlist
8617 (funcall (pop xlist) (point-min) (point-max))))))
8618
8619 ;;;
8620 ;;; Treatment top-level handling.
8621 ;;;
8622
8623 (defvar gnus-inhibit-article-treatments nil)
8624
8625 ;; Dynamic variables.
8626 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8627 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8628 (defvar gnus-treat-type)
8629 (defvar gnus-treat-condition)
8630 (defvar gnus-treat-length)
8631
8632 (defun gnus-treat-article (condition
8633 &optional part-num total type)
8634 (let ((gnus-treat-condition condition)
8635 (part-number part-num)
8636 (total-parts total)
8637 (gnus-treat-type type)
8638 (gnus-treat-length (- (point-max) (point-min)))
8639 (alist gnus-treatment-function-alist)
8640 (article-goto-body-goes-to-point-min-p t)
8641 (treated-type
8642 (or (not type)
8643 (catch 'found
8644 (let ((list gnus-article-treat-types))
8645 (while list
8646 (when (string-match (pop list) type)
8647 (throw 'found t)))))))
8648 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8649 val)
8650 (gnus-run-hooks 'gnus-part-display-hook)
8651 (dolist (elem alist)
8652 (setq val
8653 (save-excursion
8654 (when (gnus-buffer-live-p gnus-summary-buffer)
8655 (set-buffer gnus-summary-buffer))
8656 (symbol-value (car elem))))
8657 (when (and (or (consp val)
8658 treated-type)
8659 (or (not gnus-inhibit-article-treatments)
8660 (eq gnus-treat-condition 'head))
8661 (gnus-treat-predicate val)
8662 (or (not (get (car elem) 'highlight))
8663 highlightp))
8664 (save-restriction
8665 (funcall (cadr elem)))))))
8666
8667 (defun gnus-treat-predicate (val)
8668 (cond
8669 ((null val)
8670 nil)
8671 (gnus-treat-condition
8672 (eq gnus-treat-condition val))
8673 ((and (listp val)
8674 (stringp (car val)))
8675 (apply 'gnus-or (mapcar `(lambda (s)
8676 (string-match s ,(or gnus-newsgroup-name "")))
8677 val)))
8678 ((listp val)
8679 (let ((pred (pop val)))
8680 (cond
8681 ((eq pred 'or)
8682 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8683 ((eq pred 'and)
8684 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8685 ((eq pred 'not)
8686 (not (gnus-treat-predicate (car val))))
8687 ((eq pred 'typep)
8688 (equal (car val) gnus-treat-type))
8689 ((functionp pred)
8690 (funcall pred))
8691 (t
8692 (error "%S is not a valid predicate" pred)))))
8693 ((eq val t)
8694 t)
8695 ((eq val 'head)
8696 nil)
8697 ((eq val 'first)
8698 (eq part-number 1))
8699 ((eq val 'last)
8700 (eq part-number total-parts))
8701 ((numberp val)
8702 (< gnus-treat-length val))
8703 (t
8704 (error "%S is not a valid value" val))))
8705
8706 (defun gnus-article-encrypt-body (protocol &optional n)
8707 "Encrypt the article body."
8708 (interactive
8709 (list
8710 (or gnus-article-encrypt-protocol
8711 (gnus-completing-read "Encrypt protocol"
8712 (mapcar 'car gnus-article-encrypt-protocol-alist)
8713 t))
8714 current-prefix-arg))
8715 ;; User might hit `K E' instead of `K e', so prompt once.
8716 (when (and gnus-article-encrypt-protocol
8717 gnus-novice-user)
8718 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8719 (error "Encrypt aborted")))
8720 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8721 (unless func
8722 (error "Can't find the encrypt protocol %s" protocol))
8723 (if (member gnus-newsgroup-name '("nndraft:delayed"
8724 "nndraft:drafts"
8725 "nndraft:queue"))
8726 (error "Can't encrypt the article in group %s"
8727 gnus-newsgroup-name))
8728 (gnus-summary-iterate n
8729 (with-current-buffer gnus-summary-buffer
8730 (let ((mail-parse-charset gnus-newsgroup-charset)
8731 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8732 (summary-buffer gnus-summary-buffer)
8733 references point)
8734 (gnus-set-global-variables)
8735 (when (gnus-group-read-only-p)
8736 (error "The current newsgroup does not support article encrypt"))
8737 (gnus-summary-show-article t)
8738 (setq references
8739 (or (mail-header-references gnus-current-headers) ""))
8740 (set-buffer gnus-article-buffer)
8741 (let* ((inhibit-read-only t)
8742 (headers
8743 (mapcar (lambda (field)
8744 (and (save-restriction
8745 (message-narrow-to-head)
8746 (goto-char (point-min))
8747 (search-forward field nil t))
8748 (prog2
8749 (message-narrow-to-field)
8750 (buffer-string)
8751 (delete-region (point-min) (point-max))
8752 (widen))))
8753 '("Content-Type:" "Content-Transfer-Encoding:"
8754 "Content-Disposition:"))))
8755 (message-narrow-to-head)
8756 (message-remove-header "MIME-Version")
8757 (goto-char (point-max))
8758 (setq point (point))
8759 (insert (apply 'concat headers))
8760 (widen)
8761 (narrow-to-region point (point-max))
8762 (let ((message-options message-options))
8763 (message-options-set 'message-sender user-mail-address)
8764 (message-options-set 'message-recipients user-mail-address)
8765 (message-options-set 'message-sign-encrypt 'not)
8766 (funcall func))
8767 (goto-char (point-min))
8768 (insert "MIME-Version: 1.0\n")
8769 (widen)
8770 (gnus-summary-edit-article-done
8771 references nil summary-buffer t))
8772 (when gnus-keep-backlog
8773 (gnus-backlog-remove-article
8774 (car gnus-article-current) (cdr gnus-article-current)))
8775 (gnus-flush-original-article-buffer)
8776 (when gnus-use-cache
8777 (gnus-cache-update-article
8778 (car gnus-article-current) (cdr gnus-article-current))))))))
8779
8780 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8781 "The following specs can be used:
8782 %t The security MIME type
8783 %i Additional info
8784 %d Details
8785 %D Details if button is pressed")
8786
8787 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8788 "The following specs can be used:
8789 %t The security MIME type
8790 %i Additional info
8791 %d Details
8792 %D Details if button is pressed")
8793
8794 (defvar gnus-mime-security-button-line-format-alist
8795 '((?t gnus-tmp-type ?s)
8796 (?i gnus-tmp-info ?s)
8797 (?d gnus-tmp-details ?s)
8798 (?D gnus-tmp-pressed-details ?s)))
8799
8800 (defvar gnus-mime-security-button-commands
8801 '((gnus-article-press-button "\r" "Show Detail")
8802 (undefined "v")
8803 (undefined "t")
8804 (undefined "C")
8805 (gnus-mime-security-save-part "o" "Save...")
8806 (undefined "\C-o")
8807 (undefined "r")
8808 (undefined "d")
8809 (undefined "c")
8810 (undefined "i")
8811 (undefined "E")
8812 (undefined "e")
8813 (undefined "p")
8814 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8815 (undefined ".")))
8816
8817 (defvar gnus-mime-security-button-map
8818 (let ((map (make-sparse-keymap)))
8819 (define-key map gnus-mouse-2 'gnus-article-push-button)
8820 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8821 (dolist (c gnus-mime-security-button-commands)
8822 (define-key map (cadr c) (car c)))
8823 map))
8824
8825 (easy-menu-define
8826 gnus-mime-security-button-menu gnus-mime-security-button-map
8827 "Security button menu."
8828 `("Security Part"
8829 ,@(delq nil
8830 (mapcar (lambda (c)
8831 (unless (eq (car c) 'undefined)
8832 (vector (caddr c) (car c) :active t)))
8833 gnus-mime-security-button-commands))))
8834
8835 (defun gnus-mime-security-button-menu (event prefix)
8836 "Construct a context-sensitive menu of security commands."
8837 (interactive "e\nP")
8838 (save-window-excursion
8839 (let ((pos (event-start event)))
8840 (select-window (posn-window pos))
8841 (goto-char (posn-point pos))
8842 (gnus-article-check-buffer)
8843 (popup-menu gnus-mime-security-button-menu nil prefix))))
8844
8845 (defvar gnus-mime-security-details-buffer nil)
8846
8847 (defvar gnus-mime-security-button-pressed nil)
8848
8849 (defvar gnus-mime-security-show-details-inline t
8850 "If non-nil, show details in the article buffer.")
8851
8852 (defun gnus-mime-security-verify-or-decrypt (handle)
8853 (mm-remove-parts (cdr handle))
8854 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8855 point (inhibit-read-only t))
8856 (if region
8857 (goto-char (car region)))
8858 (setq point (point))
8859 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8860 (let* ((mm-verify-option 'known)
8861 (mm-decrypt-option 'known)
8862 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8863 (unless (eq nparts (cdr handle))
8864 (mm-destroy-parts (cdr handle))
8865 (setcdr handle nparts))))
8866 (gnus-mime-display-security handle)
8867 (when region
8868 (delete-region (point) (cdr region))
8869 (set-marker (car region) nil)
8870 (set-marker (cdr region) nil))
8871 (goto-char point)))
8872
8873 (defun gnus-mime-security-show-details (handle)
8874 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8875 (if (not details)
8876 (gnus-message 5 "No details.")
8877 (if gnus-mime-security-show-details-inline
8878 (let ((gnus-mime-security-button-pressed
8879 (not (get-text-property (point) 'gnus-mime-details)))
8880 (gnus-mime-security-button-line-format
8881 (get-text-property (point) 'gnus-line-format))
8882 (inhibit-read-only t))
8883 (forward-char -1)
8884 (while (eq (get-text-property (point) 'gnus-line-format)
8885 gnus-mime-security-button-line-format)
8886 (forward-char -1))
8887 (forward-char)
8888 (save-restriction
8889 (narrow-to-region (point) (point))
8890 (gnus-insert-mime-security-button handle))
8891 (delete-region (point)
8892 (or (text-property-not-all
8893 (point) (point-max)
8894 'gnus-line-format
8895 gnus-mime-security-button-line-format)
8896 (point-max))))
8897 ;; Not inlined.
8898 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8899 (with-current-buffer gnus-mime-security-details-buffer
8900 (erase-buffer)
8901 t)
8902 (setq gnus-mime-security-details-buffer
8903 (gnus-get-buffer-create "*MIME Security Details*")))
8904 (with-current-buffer gnus-mime-security-details-buffer
8905 (insert details)
8906 (goto-char (point-min)))
8907 (pop-to-buffer gnus-mime-security-details-buffer)))))
8908
8909 (defun gnus-mime-security-press-button (handle)
8910 (save-excursion
8911 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8912 (gnus-mime-security-show-details handle)
8913 (gnus-mime-security-verify-or-decrypt handle))))
8914
8915 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8916 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8917 (gnus-tmp-type
8918 (concat
8919 (or (nth 2 (assoc protocol mm-verify-function-alist))
8920 (nth 2 (assoc protocol mm-decrypt-function-alist))
8921 "Unknown")
8922 (if (equal (car handle) "multipart/signed")
8923 " Signed" " Encrypted")
8924 " Part"))
8925 (gnus-tmp-info
8926 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8927 "Undecided"))
8928 (gnus-tmp-details
8929 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8930 gnus-tmp-pressed-details
8931 b e)
8932 (setq gnus-tmp-details
8933 (if gnus-tmp-details
8934 (concat "\n" gnus-tmp-details)
8935 ""))
8936 (setq gnus-tmp-pressed-details
8937 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8938 (unless (bolp)
8939 (insert "\n"))
8940 (setq b (point))
8941 (gnus-eval-format
8942 gnus-mime-security-button-line-format
8943 gnus-mime-security-button-line-format-alist
8944 `(keymap ,gnus-mime-security-button-map
8945 gnus-callback gnus-mime-security-press-button
8946 gnus-line-format ,gnus-mime-security-button-line-format
8947 gnus-mime-details ,gnus-mime-security-button-pressed
8948 article-type annotation
8949 gnus-data ,handle))
8950 (setq e (if (bolp)
8951 ;; Exclude a newline.
8952 (1- (point))
8953 (point)))
8954 (when gnus-article-button-face
8955 (overlay-put (make-overlay b e nil t)
8956 'face gnus-article-button-face))
8957 (widget-convert-button
8958 'link b e
8959 :mime-handle handle
8960 :action 'gnus-widget-press-button
8961 :button-keymap gnus-mime-security-button-map
8962 :help-echo
8963 (lambda (_widget)
8964 ;; Needed to properly clear the message due to a bug in
8965 ;; wid-edit (XEmacs only).
8966 (when (boundp 'help-echo-owns-message)
8967 (setq help-echo-owns-message t))
8968 (format
8969 "%S: show detail; %S: more options"
8970 (aref gnus-mouse-2 0)
8971 (aref gnus-down-mouse-3 0))))))
8972
8973 (defun gnus-mime-display-security (handle)
8974 (save-restriction
8975 (narrow-to-region (point) (point))
8976 (unless (gnus-unbuttonized-mime-type-p (car handle))
8977 (gnus-insert-mime-security-button handle))
8978 (gnus-mime-display-part (cadr handle))
8979 (unless (bolp)
8980 (insert "\n"))
8981 (unless (gnus-unbuttonized-mime-type-p (car handle))
8982 (let ((gnus-mime-security-button-line-format
8983 gnus-mime-security-button-end-line-format))
8984 (gnus-insert-mime-security-button handle)))
8985 (mm-set-handle-multipart-parameter
8986 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8987 (goto-char (point-max))))
8988
8989 (defun gnus-mime-security-run-function (function)
8990 "Run FUNCTION with the security part under point."
8991 (gnus-article-check-buffer)
8992 (let ((data (get-text-property (point) 'gnus-data))
8993 buffer handle)
8994 (when (and (stringp (car-safe data))
8995 (setq buffer (mm-handle-multipart-original-buffer data))
8996 (setq handle (cadr data)))
8997 (if (bufferp (mm-handle-buffer handle))
8998 (progn
8999 (setq handle (cons buffer (copy-sequence (cdr handle))))
9000 (mm-handle-set-undisplayer handle nil))
9001 (setq handle (mm-make-handle
9002 buffer
9003 (mm-handle-multipart-ctl-parameter handle 'protocol)
9004 nil nil nil nil nil nil)))
9005 (funcall function handle))))
9006
9007 (defun gnus-mime-security-save-part ()
9008 "Save the security part under point."
9009 (interactive)
9010 (gnus-mime-security-run-function 'mm-save-part))
9011
9012 (defun gnus-mime-security-pipe-part ()
9013 "Pipe the security part under point to a process."
9014 (interactive)
9015 (gnus-mime-security-run-function 'mm-pipe-part))
9016
9017 (gnus-ems-redefine)
9018
9019 (provide 'gnus-art)
9020
9021 (run-hooks 'gnus-art-load-hook)
9022
9023 ;;; gnus-art.el ends here