]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
079d16b3e159b4685de1cfe0267f51d144ae1cc9
[gnu-emacs] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
31
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
45
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
53 (autoload 'url-expand-file-name "url-expand")
54
55 (defgroup gnus-article nil
56 "Article display."
57 :link '(custom-manual "(gnus)Article Buffer")
58 :group 'gnus)
59
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
63 :group 'gnus-article)
64
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
68 :group 'gnus-article)
69
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
73 :group 'gnus-article
74 :group 'gnus-visual)
75
76 (defgroup gnus-article-signature nil
77 "Article signatures."
78 :link '(custom-manual "(gnus)Article Signature")
79 :group 'gnus-article)
80
81 (defgroup gnus-article-headers nil
82 "Article headers."
83 :link '(custom-manual "(gnus)Hiding Headers")
84 :group 'gnus-article)
85
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
89 :group 'gnus-article)
90
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
94 :group 'gnus-article)
95
96 (defgroup gnus-article-saving nil
97 "Saving articles."
98 :link '(custom-manual "(gnus)Saving Articles")
99 :group 'gnus-article)
100
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
105
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
110
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
115
116 (defcustom gnus-ignored-headers
117 (mapcar
118 (lambda (header)
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
165 (repeat regexp))
166 :group 'gnus-article-hiding)
167
168 (defcustom gnus-visible-headers
169 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
173 :type '(choice
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
177 (or (stringp value)
178 (widget-editable-list-match widget value)))
179 regexp)
180 (const :tag "Use gnus-ignored-headers" nil)
181 regexp)
182 :group 'gnus-article-hiding)
183
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
190 this list."
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
193
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
197
198 `empty' Headers with no content.
199 `newsgroups' Newsgroup identical to Gnus group.
200 `to-address' To identical to To-address.
201 `to-list' To identical to To-list.
202 `cc-list' CC identical to To-list.
203 `followup-to' Followup-to identical to Newsgroups.
204 `reply-to' Reply-to identical to From.
205 `date' Date less than four days old.
206 `long-to' To and/or Cc longer than 1024 characters.
207 `many-to' Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
219
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
226 :version "22.1"
227 :type 'boolean
228 :group 'gnus-article-hiding)
229
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
236 (regexp)
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
239
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
248
249 This can also be a list of the above values."
250 :type '(choice (const nil)
251 (integer :value 200)
252 (number :value 4.0)
253 function
254 (regexp :value ".*"))
255 :group 'gnus-article-signature)
256
257 (defcustom gnus-hidden-properties
258 ;; We use to have `intangible' here as well, but Emacs's command loop moves
259 ;; point out of invisible text anyway, so `intangible' is clearly not
260 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
261 '(invisible t)
262 "Property list to use for hiding text."
263 :type 'plist
264 :group 'gnus-article-hiding)
265
266 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
267 ;; frames in a session.
268 (defcustom gnus-article-x-face-command
269 (if (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 (const :tag "Allow all" nil)
1663 (regexp :tag "Regular expression")
1664 (function :tag "Use a function")))
1665
1666 ;;; Internal variables
1667
1668 (defvar gnus-english-month-names
1669 '("January" "February" "March" "April" "May" "June" "July" "August"
1670 "September" "October" "November" "December"))
1671
1672 (defvar article-goto-body-goes-to-point-min-p nil)
1673 (defvar gnus-article-wash-types nil)
1674 (defvar gnus-article-emphasis-alist nil)
1675 (defvar gnus-article-image-alist nil)
1676
1677 (defvar gnus-article-mime-handle-alist-1 nil)
1678 (defvar gnus-treatment-function-alist
1679 '((gnus-treat-strip-cr gnus-article-remove-cr)
1680 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1681 (gnus-treat-strip-banner gnus-article-strip-banner)
1682 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1683 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1684 (gnus-treat-buttonize gnus-article-add-buttons)
1685 (gnus-treat-fill-article gnus-article-fill-cited-article)
1686 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1687 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1688 (gnus-treat-display-x-face gnus-article-display-x-face)
1689 (gnus-treat-display-face gnus-article-display-face)
1690 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1691 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1692 (gnus-treat-hide-signature gnus-article-hide-signature)
1693 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1694 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1695 (gnus-treat-from-picon gnus-treat-from-picon)
1696 (gnus-treat-mail-picon gnus-treat-mail-picon)
1697 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1698 (gnus-treat-strip-pem gnus-article-hide-pem)
1699 (gnus-treat-date gnus-article-treat-date)
1700 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1701 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1702 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1703 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1704 (gnus-treat-strip-trailing-blank-lines
1705 gnus-article-remove-trailing-blank-lines)
1706 (gnus-treat-strip-leading-blank-lines
1707 gnus-article-strip-leading-blank-lines)
1708 (gnus-treat-strip-multiple-blank-lines
1709 gnus-article-strip-multiple-blank-lines)
1710 (gnus-treat-overstrike gnus-article-treat-overstrike)
1711 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1712 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1713 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1714 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1715 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1716 (gnus-treat-display-smileys gnus-treat-smiley)
1717 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1718 (gnus-treat-wash-html gnus-article-wash-html)
1719 (gnus-treat-emphasize gnus-article-emphasize)
1720 (gnus-treat-hide-citation gnus-article-hide-citation)
1721 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1722 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1723 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1724
1725 (defvar gnus-article-mime-handle-alist nil)
1726 (defvar article-lapsed-timer nil)
1727 (defvar gnus-article-current-summary nil)
1728
1729 (defvar gnus-article-mode-syntax-table
1730 (let ((table (copy-syntax-table text-mode-syntax-table)))
1731 ;; This causes the citation match run O(2^n).
1732 ;; (modify-syntax-entry ?- "w" table)
1733 (modify-syntax-entry ?> ")<" table)
1734 (modify-syntax-entry ?< "(>" table)
1735 ;; make M-. in article buffers work for `foo' strings
1736 (modify-syntax-entry ?' " " table)
1737 (modify-syntax-entry ?` " " table)
1738 table)
1739 "Syntax table used in article mode buffers.
1740 Initialized from `text-mode-syntax-table'.")
1741
1742 (defvar gnus-save-article-buffer nil)
1743
1744 (defvar gnus-number-of-articles-to-be-saved nil)
1745
1746 (defvar gnus-inhibit-hiding nil)
1747
1748 (defvar gnus-article-edit-mode nil)
1749
1750 ;;; Macros for dealing with the article buffer.
1751
1752 (defmacro gnus-with-article-headers (&rest forms)
1753 `(with-current-buffer gnus-article-buffer
1754 (save-restriction
1755 (let ((inhibit-read-only t)
1756 (inhibit-point-motion-hooks t)
1757 (case-fold-search t))
1758 (article-narrow-to-head)
1759 ,@forms))))
1760
1761 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1762 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1763
1764 (defmacro gnus-with-article-buffer (&rest forms)
1765 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1766 (with-current-buffer gnus-article-buffer
1767 (let ((inhibit-read-only t))
1768 ,@forms))))
1769
1770 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1771 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1772
1773 (defun gnus-article-goto-header (header)
1774 "Go to HEADER, which is a regular expression."
1775 (re-search-forward (concat "^\\(" header "\\):") nil t))
1776
1777 (defsubst gnus-article-hide-text (b e props)
1778 "Set text PROPS on the B to E region."
1779 (gnus-add-text-properties-when 'article-type nil b e props))
1780
1781 (defsubst gnus-article-unhide-text (b e)
1782 "Remove hidden text properties from region between B and E."
1783 (remove-text-properties b e gnus-hidden-properties))
1784
1785 (defun gnus-article-hide-text-type (b e type)
1786 "Hide text of TYPE between B and E."
1787 (gnus-add-wash-type type)
1788 (gnus-article-hide-text
1789 b e (cons 'article-type (cons type gnus-hidden-properties))))
1790
1791 (defun gnus-article-unhide-text-type (b e type)
1792 "Unhide text of TYPE between B and E."
1793 (gnus-delete-wash-type type)
1794 (remove-text-properties
1795 b e (cons 'article-type (cons type gnus-hidden-properties))))
1796
1797 (defun gnus-article-delete-text-of-type (type)
1798 "Delete text of TYPE in the current buffer."
1799 (save-excursion
1800 (let ((b (point-min)))
1801 (if (eq type 'multipart)
1802 ;; Remove MIME buttons associated with multipart/alternative parts.
1803 (progn
1804 (goto-char b)
1805 (while (if (get-text-property (point) 'gnus-part)
1806 (setq b (point))
1807 (when (setq b (next-single-property-change (point)
1808 'gnus-part))
1809 (goto-char b)
1810 t))
1811 (end-of-line)
1812 (skip-chars-forward "\n")
1813 (when (eq (get-text-property b 'article-type) 'multipart)
1814 (delete-region b (point)))))
1815 (while (setq b (text-property-any b (point-max) 'article-type type))
1816 (delete-region
1817 b (or (text-property-not-all b (point-max) 'article-type type)
1818 (point-max))))))))
1819
1820 (defun gnus-article-delete-invisible-text ()
1821 "Delete all invisible text in the current buffer."
1822 (save-excursion
1823 (let ((b (point-min)))
1824 (while (setq b (text-property-any b (point-max) 'invisible t))
1825 (delete-region
1826 b (or (text-property-not-all b (point-max) 'invisible t)
1827 (point-max)))))))
1828
1829 (defsubst gnus-article-header-rank ()
1830 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1831 (let ((list gnus-sorted-header-list)
1832 (i 1))
1833 (while list
1834 (if (looking-at (car list))
1835 (setq list nil)
1836 (setq list (cdr list))
1837 (incf i)))
1838 i))
1839
1840 (defun article-hide-headers (&optional _arg _delete)
1841 "Hide unwanted headers and possibly sort them as well."
1842 (interactive)
1843 ;; This function might be inhibited.
1844 (unless gnus-inhibit-hiding
1845 (let ((inhibit-read-only t)
1846 (case-fold-search t)
1847 (max (1+ (length gnus-sorted-header-list)))
1848 (inhibit-point-motion-hooks t)
1849 (cur (current-buffer))
1850 ignored visible beg)
1851 (save-excursion
1852 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1853 ;; group parameters, so we should go to the summary buffer.
1854 (when (prog1
1855 (condition-case nil
1856 (progn (set-buffer gnus-summary-buffer) t)
1857 (error nil))
1858 (setq ignored (when (not gnus-visible-headers)
1859 (cond ((stringp gnus-ignored-headers)
1860 gnus-ignored-headers)
1861 ((listp gnus-ignored-headers)
1862 (mapconcat 'identity
1863 gnus-ignored-headers
1864 "\\|"))))
1865 visible (cond ((stringp gnus-visible-headers)
1866 gnus-visible-headers)
1867 ((and gnus-visible-headers
1868 (listp gnus-visible-headers))
1869 (mapconcat 'identity
1870 gnus-visible-headers
1871 "\\|")))))
1872 (set-buffer cur))
1873 (save-restriction
1874 ;; First we narrow to just the headers.
1875 (article-narrow-to-head)
1876 ;; Hide any "From " lines at the beginning of (mail) articles.
1877 (while (looking-at "From ")
1878 (forward-line 1))
1879 (unless (bobp)
1880 (delete-region (point-min) (point)))
1881 ;; Then treat the rest of the header lines.
1882 ;; Then we use the two regular expressions
1883 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1884 ;; select which header lines is to remain visible in the
1885 ;; article buffer.
1886 (while (re-search-forward "^[^ \t:]*:" nil t)
1887 (beginning-of-line)
1888 ;; Mark the rank of the header.
1889 (put-text-property
1890 (point) (1+ (point)) 'message-rank
1891 (if (or (and visible (looking-at visible))
1892 (and ignored
1893 (not (looking-at ignored))))
1894 (gnus-article-header-rank)
1895 (+ 2 max)))
1896 (forward-line 1))
1897 (message-sort-headers-1)
1898 (when (setq beg (text-property-any
1899 (point-min) (point-max) 'message-rank (+ 2 max)))
1900 ;; We delete the unwanted headers.
1901 (gnus-add-wash-type 'headers)
1902 (add-text-properties (point-min) (+ 5 (point-min))
1903 '(article-type headers dummy-invisible t))
1904 (delete-region beg (point-max))))))))
1905
1906 (defun article-hide-boring-headers (&optional arg)
1907 "Toggle hiding of headers that aren't very interesting.
1908 If given a negative prefix, always show; if given a positive prefix,
1909 always hide."
1910 (interactive (gnus-article-hidden-arg))
1911 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1912 (not gnus-show-all-headers))
1913 (save-excursion
1914 (save-restriction
1915 (let ((inhibit-read-only t)
1916 (inhibit-point-motion-hooks t))
1917 (article-narrow-to-head)
1918 (dolist (elem gnus-boring-article-headers)
1919 (goto-char (point-min))
1920 (cond
1921 ;; Hide empty headers.
1922 ((eq elem 'empty)
1923 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1924 (forward-line -1)
1925 (gnus-article-hide-text-type
1926 (point-at-bol)
1927 (progn
1928 (end-of-line)
1929 (if (re-search-forward "^[^ \t]" nil t)
1930 (match-beginning 0)
1931 (point-max)))
1932 'boring-headers)))
1933 ;; Hide boring Newsgroups header.
1934 ((eq elem 'newsgroups)
1935 (when (gnus-string-equal
1936 (gnus-fetch-field "newsgroups")
1937 (gnus-group-real-name
1938 (if (boundp 'gnus-newsgroup-name)
1939 gnus-newsgroup-name
1940 "")))
1941 (gnus-article-hide-header "newsgroups")))
1942 ((eq elem 'to-address)
1943 (let ((to (message-fetch-field "to"))
1944 (to-address
1945 (gnus-parameter-to-address
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-address
1949 (ignore-errors
1950 (gnus-string-equal
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1953 to-address)))
1954 (gnus-article-hide-header "to"))))
1955 ((eq elem 'to-list)
1956 (let ((to (message-fetch-field "to"))
1957 (to-list
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and to to-list
1962 (ignore-errors
1963 (gnus-string-equal
1964 ;; only one address in To
1965 (nth 1 (mail-extract-address-components to))
1966 to-list)))
1967 (gnus-article-hide-header "to"))))
1968 ((eq elem 'cc-list)
1969 (let ((cc (message-fetch-field "cc"))
1970 (to-list
1971 (gnus-parameter-to-list
1972 (if (boundp 'gnus-newsgroup-name)
1973 gnus-newsgroup-name ""))))
1974 (when (and cc to-list
1975 (ignore-errors
1976 (gnus-string-equal
1977 ;; only one address in CC
1978 (nth 1 (mail-extract-address-components cc))
1979 to-list)))
1980 (gnus-article-hide-header "cc"))))
1981 ((eq elem 'followup-to)
1982 (when (gnus-string-equal
1983 (message-fetch-field "followup-to")
1984 (message-fetch-field "newsgroups"))
1985 (gnus-article-hide-header "followup-to")))
1986 ((eq elem 'reply-to)
1987 (if (gnus-group-find-parameter
1988 gnus-newsgroup-name 'broken-reply-to)
1989 (gnus-article-hide-header "reply-to")
1990 (let ((from (message-fetch-field "from"))
1991 (reply-to (message-fetch-field "reply-to")))
1992 (when
1993 (and
1994 from reply-to
1995 (ignore-errors
1996 (equal
1997 (sort (mapcar
1998 (lambda (x) (downcase (cadr x)))
1999 (mail-extract-address-components from t))
2000 'string<)
2001 (sort (mapcar
2002 (lambda (x) (downcase (cadr x)))
2003 (mail-extract-address-components reply-to t))
2004 'string<))))
2005 (gnus-article-hide-header "reply-to")))))
2006 ((eq elem 'date)
2007 (let ((date (with-current-buffer gnus-original-article-buffer
2008 ;; If date in `gnus-article-buffer' is localized
2009 ;; (`gnus-treat-date-user-defined'),
2010 ;; `days-between' might fail.
2011 (message-fetch-field "date"))))
2012 (when (and date
2013 (< (days-between (current-time-string) date)
2014 4))
2015 (gnus-article-hide-header "date"))))
2016 ((eq elem 'long-to)
2017 (let ((to (message-fetch-field "to"))
2018 (cc (message-fetch-field "cc")))
2019 (when (> (length to) 1024)
2020 (gnus-article-hide-header "to"))
2021 (when (> (length cc) 1024)
2022 (gnus-article-hide-header "cc"))))
2023 ((eq elem 'many-to)
2024 (let ((to-count 0)
2025 (cc-count 0))
2026 (goto-char (point-min))
2027 (while (re-search-forward "^to:" nil t)
2028 (setq to-count (1+ to-count)))
2029 (when (> to-count 1)
2030 (while (> to-count 0)
2031 (goto-char (point-min))
2032 (save-restriction
2033 (re-search-forward "^to:" nil nil to-count)
2034 (forward-line -1)
2035 (narrow-to-region (point) (point-max))
2036 (gnus-article-hide-header "to"))
2037 (setq to-count (1- to-count))))
2038 (goto-char (point-min))
2039 (while (re-search-forward "^cc:" nil t)
2040 (setq cc-count (1+ cc-count)))
2041 (when (> cc-count 1)
2042 (while (> cc-count 0)
2043 (goto-char (point-min))
2044 (save-restriction
2045 (re-search-forward "^cc:" nil nil cc-count)
2046 (forward-line -1)
2047 (narrow-to-region (point) (point-max))
2048 (gnus-article-hide-header "cc"))
2049 (setq cc-count (1- cc-count)))))))))))))
2050
2051 (defun gnus-article-hide-header (header)
2052 (save-excursion
2053 (goto-char (point-min))
2054 (when (re-search-forward (concat "^" header ":") nil t)
2055 (gnus-article-hide-text-type
2056 (point-at-bol)
2057 (progn
2058 (end-of-line)
2059 (if (re-search-forward "^[^ \t]" nil t)
2060 (match-beginning 0)
2061 (point-max)))
2062 'boring-headers))))
2063
2064 (defvar gnus-article-normalized-header-length 40
2065 "Length of normalized headers.")
2066
2067 (defun article-normalize-headers ()
2068 "Make all header lines 40 characters long."
2069 (interactive)
2070 (let ((inhibit-read-only t)
2071 column)
2072 (save-excursion
2073 (save-restriction
2074 (article-narrow-to-head)
2075 (while (not (eobp))
2076 (cond
2077 ((< (setq column (- (point-at-eol) (point)))
2078 gnus-article-normalized-header-length)
2079 (end-of-line)
2080 (insert (make-string
2081 (- gnus-article-normalized-header-length column)
2082 ? )))
2083 ((> column gnus-article-normalized-header-length)
2084 (gnus-put-text-property
2085 (progn
2086 (forward-char gnus-article-normalized-header-length)
2087 (point))
2088 (point-at-eol)
2089 'invisible t))
2090 (t
2091 ;; Do nothing.
2092 ))
2093 (forward-line 1))))))
2094
2095 (defun article-treat-dumbquotes ()
2096 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2097 Note that this function guesses whether a character is a sm*rtq**t* or
2098 not, so it should only be used interactively.
2099
2100 Sm*rtq**t*s are M****s***'s unilateral extension to the
2101 iso-8859-1 character map in an attempt to provide more quoting
2102 characters. If you see something like \\222 or \\264 where
2103 you're expecting some kind of apostrophe or quotation mark, then
2104 try this wash."
2105 (interactive)
2106 (article-translate-strings gnus-article-dumbquotes-map))
2107
2108 (defvar org-entities)
2109
2110 (defun article-treat-non-ascii ()
2111 "Translate many Unicode characters into their ASCII equivalents."
2112 (interactive)
2113 (require 'org-entities)
2114 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2115 (dolist (elem org-entities)
2116 (when (and (listp elem)
2117 (= (length (nth 6 elem)) 1))
2118 (if (featurep 'xemacs)
2119 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2120 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2121 (save-excursion
2122 (when (article-goto-body)
2123 (let ((inhibit-read-only t)
2124 replace props)
2125 (while (not (eobp))
2126 (if (not (setq replace (if (featurep 'xemacs)
2127 (get-char-table (following-char) table)
2128 (aref table (following-char)))))
2129 (forward-char 1)
2130 (if (prog1
2131 (setq props (text-properties-at (point)))
2132 (delete-char 1))
2133 (add-text-properties (point) (progn (insert replace) (point))
2134 props)
2135 (insert replace)))))))))
2136
2137 (defun article-translate-strings (map)
2138 "Translate all string in the body of the article according to MAP.
2139 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2140 (save-excursion
2141 (when (article-goto-body)
2142 (let ((inhibit-read-only t))
2143 (dolist (elem map)
2144 (let ((from (car elem))
2145 (to (cadr elem)))
2146 (save-excursion
2147 (if (stringp from)
2148 (while (search-forward from nil t)
2149 (replace-match to))
2150 (while (not (eobp))
2151 (if (eq (following-char) from)
2152 (progn
2153 (delete-char 1)
2154 (insert to))
2155 (forward-char 1)))))))))))
2156
2157 (defun article-treat-overstrike ()
2158 "Translate overstrikes into bold text."
2159 (interactive)
2160 (save-excursion
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (while (search-forward "\b" nil t)
2164 (let ((next (char-after))
2165 (previous (char-after (- (point) 2))))
2166 ;; We do the boldification/underlining by hiding the
2167 ;; overstrikes and putting the proper text property
2168 ;; on the letters.
2169 (cond
2170 ((eq next previous)
2171 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2172 (put-text-property (point) (1+ (point)) 'face 'bold))
2173 ((eq next ?_)
2174 (gnus-article-hide-text-type
2175 (1- (point)) (1+ (point)) 'overstrike)
2176 (put-text-property
2177 (- (point) 2) (1- (point)) 'face 'underline))
2178 ((eq previous ?_)
2179 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2180 (put-text-property
2181 (point) (1+ (point)) 'face 'underline)))))))))
2182
2183 (defun article-treat-ansi-sequences ()
2184 "Translate ANSI SGR control sequences into overlays or extents."
2185 (interactive)
2186 (save-excursion
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (ansi-color-apply-on-region (point) (point-max))))))
2190
2191 (defun gnus-article-treat-unfold-headers ()
2192 "Unfold folded message headers.
2193 Only the headers that fit into the current window width will be
2194 unfolded."
2195 (interactive)
2196 (gnus-with-article-headers
2197 (let (length)
2198 (while (not (eobp))
2199 (save-restriction
2200 (mail-header-narrow-to-field)
2201 (let* ((header (buffer-string))
2202 (unfoldable
2203 (or (equal gnus-article-unfold-long-headers t)
2204 (and (stringp gnus-article-unfold-long-headers)
2205 (string-match gnus-article-unfold-long-headers
2206 header)))))
2207 (with-temp-buffer
2208 (insert header)
2209 (goto-char (point-min))
2210 (while (re-search-forward "\n[\t ]" nil t)
2211 (replace-match " " t t)))
2212 (setq length (- (point-max) (point-min) 1))
2213 (when (or unfoldable
2214 (< length (window-width)))
2215 (while (re-search-forward "\n[\t ]" nil t)
2216 (replace-match " " t t))))
2217 (goto-char (point-max)))))))
2218
2219 (defun gnus-article-treat-fold-headers ()
2220 "Fold message headers."
2221 (interactive)
2222 (gnus-with-article-headers
2223 (while (not (eobp))
2224 (save-restriction
2225 (mail-header-narrow-to-field)
2226 (mail-header-fold-field)
2227 (goto-char (point-max))))))
2228
2229 (defun gnus-treat-smiley ()
2230 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2231 (interactive)
2232 (gnus-with-article-buffer
2233 (if (memq 'smiley gnus-article-wash-types)
2234 (gnus-delete-images 'smiley)
2235 (article-goto-body)
2236 (let ((images (smiley-region (point) (point-max))))
2237 (when images
2238 (gnus-add-wash-type 'smiley)
2239 (dolist (image images)
2240 (gnus-add-image 'smiley image)))))))
2241
2242 (defun gnus-article-remove-images ()
2243 "Remove all images from the article buffer."
2244 (interactive)
2245 (gnus-with-article-buffer
2246 (save-restriction
2247 (widen)
2248 (dolist (elem gnus-article-image-alist)
2249 (gnus-delete-images (car elem))))))
2250
2251 (autoload 'w3m-toggle-inline-images "w3m")
2252
2253 (defun gnus-article-show-images ()
2254 "Show any images that are in the HTML-rendered article buffer.
2255 This only works if the article in question is HTML."
2256 (interactive)
2257 (gnus-with-article-buffer
2258 (save-restriction
2259 (widen)
2260 (if (eq mm-text-html-renderer 'w3m)
2261 (w3m-toggle-inline-images)
2262 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2263 'image-displayer))
2264 (destructuring-bind (start end function) region
2265 (funcall function (get-text-property start 'image-url)
2266 start end)))))))
2267
2268 (defun gnus-article-treat-fold-newsgroups ()
2269 "Unfold folded message headers.
2270 Only the headers that fit into the current window width will be
2271 unfolded."
2272 (interactive)
2273 (gnus-with-article-headers
2274 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2275 (save-restriction
2276 (mail-header-narrow-to-field)
2277 (while (re-search-forward ", *" nil t)
2278 (replace-match ", " t t))
2279 (mail-header-fold-field)
2280 (goto-char (point-max))))))
2281
2282 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2283 "Value of `truncate-lines' in Gnus Article buffer.
2284 Valid values are nil, t, `head', `first', `last', an integer or a
2285 predicate. See Info node `(gnus)Customizing Articles'."
2286 :version "23.1" ;; No Gnus
2287 :group 'gnus-article
2288 ;; :link '(custom-manual "(gnus)Customizing Articles")
2289 :type 'boolean)
2290
2291 (defun gnus-article-toggle-truncate-lines (&optional arg)
2292 "Toggle whether to fold or truncate long lines in article the buffer.
2293 If ARG is non-nil and not a number, toggle
2294 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2295 long lines if and only if arg is positive."
2296 (interactive "P")
2297 (cond
2298 ((and (numberp arg) (> arg 0))
2299 (setq gnus-article-truncate-lines t))
2300 ((numberp arg)
2301 (setq gnus-article-truncate-lines nil))
2302 (arg
2303 (setq gnus-article-truncate-lines
2304 (not gnus-article-truncate-lines))))
2305 (gnus-with-article-buffer
2306 (cond
2307 ((and (numberp arg) (> arg 0))
2308 (setq truncate-lines nil))
2309 ((numberp arg)
2310 (setq truncate-lines t)))
2311 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2312 ;; `toggle-truncate-lines' needs an argument.
2313 (toggle-truncate-lines)))
2314
2315 (defun gnus-article-treat-body-boundary ()
2316 "Place a boundary line at the end of the headers."
2317 (interactive)
2318 (when (and gnus-body-boundary-delimiter
2319 (> (length gnus-body-boundary-delimiter) 0))
2320 (gnus-with-article-headers
2321 (goto-char (point-max))
2322 (let ((start (point)))
2323 (insert "X-Boundary: ")
2324 (gnus-add-text-properties start (point) gnus-hidden-properties)
2325 (insert (let (str (max (window-width)))
2326 (if (featurep 'xemacs)
2327 (setq max (1- max)))
2328 (while (>= max (length str))
2329 (setq str (concat str gnus-body-boundary-delimiter)))
2330 (substring str 0 max))
2331 "\n")
2332 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2333
2334 (defun article-fill-long-lines ()
2335 "Fill lines that are wider than the window width."
2336 (interactive)
2337 (save-excursion
2338 (let ((inhibit-read-only t)
2339 (width (window-width (get-buffer-window (current-buffer)))))
2340 (save-restriction
2341 (article-goto-body)
2342 (let ((adaptive-fill-mode nil)) ;Why? -sm
2343 (while (not (eobp))
2344 (end-of-line)
2345 (when (>= (current-column) (min fill-column width))
2346 (narrow-to-region (min (1+ (point)) (point-max))
2347 (point-at-bol))
2348 (let ((goback (point-marker)))
2349 (fill-paragraph nil)
2350 (goto-char (marker-position goback)))
2351 (widen))
2352 (forward-line 1)))))))
2353
2354 (defun article-capitalize-sentences ()
2355 "Capitalize the first word in each sentence."
2356 (interactive)
2357 (save-excursion
2358 (let ((inhibit-read-only t)
2359 (paragraph-start "^[\n\^L]"))
2360 (article-goto-body)
2361 (while (not (eobp))
2362 (capitalize-word 1)
2363 (forward-sentence)))))
2364
2365 (defun article-remove-cr ()
2366 "Remove trailing CRs and then translate remaining CRs into LFs."
2367 (interactive)
2368 (save-excursion
2369 (let ((inhibit-read-only t))
2370 (goto-char (point-min))
2371 (while (re-search-forward "\r+$" nil t)
2372 (replace-match "" t t))
2373 (goto-char (point-min))
2374 (while (search-forward "\r" nil t)
2375 (replace-match "\n" t t)))))
2376
2377 (defun article-remove-trailing-blank-lines ()
2378 "Remove all trailing blank lines from the article."
2379 (interactive)
2380 (save-excursion
2381 (let ((inhibit-read-only t))
2382 (goto-char (point-max))
2383 (delete-region
2384 (point)
2385 (progn
2386 (while (and (not (bobp))
2387 (looking-at "^[ \t]*$")
2388 (not (gnus-annotation-in-region-p
2389 (point) (point-at-eol))))
2390 (forward-line -1))
2391 (forward-line 1)
2392 (point))))))
2393
2394 (defvar gnus-face-properties-alist)
2395
2396 (defun article-display-face (&optional force)
2397 "Display any Face headers in the header."
2398 (interactive (list 'force))
2399 (let ((wash-face-p buffer-read-only))
2400 (gnus-with-article-headers
2401 ;; When displaying parts, this function can be called several times on
2402 ;; the same article, without any intended toggle semantic (as typing `W
2403 ;; D d' would have). So face deletion must occur only when we come from
2404 ;; an interactive command, that is when the *Article* buffer is
2405 ;; read-only.
2406 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2407 (gnus-delete-images 'face)
2408 (let ((from (message-fetch-field "from"))
2409 faces)
2410 (save-current-buffer
2411 (when (and wash-face-p
2412 (gnus-buffer-live-p gnus-original-article-buffer)
2413 (not (re-search-forward "^Face:[\t ]*" nil t)))
2414 (set-buffer gnus-original-article-buffer))
2415 (save-restriction
2416 (mail-narrow-to-head)
2417 (when (or force
2418 ;; Check whether this face is censored.
2419 (not (and gnus-article-x-face-too-ugly
2420 (or from
2421 (setq from (message-fetch-field "from")))
2422 (string-match gnus-article-x-face-too-ugly
2423 from))))
2424 (while (gnus-article-goto-header "Face")
2425 (push (mail-header-field-value) faces)))))
2426 (when faces
2427 (goto-char (point-min))
2428 (let (png image)
2429 (unless (setq from (gnus-article-goto-header "from"))
2430 (insert "From:")
2431 (setq from (point))
2432 (insert " [no 'from' set]\n"))
2433 (while faces
2434 (when (setq png (gnus-convert-face-to-png (pop faces)))
2435 (setq image
2436 (apply 'gnus-create-image png 'png t
2437 (cdr (assq 'png gnus-face-properties-alist))))
2438 (goto-char from)
2439 (when image
2440 (gnus-add-wash-type 'face)
2441 (gnus-add-image 'face image)
2442 (gnus-put-image image nil 'face)))))))))))
2443
2444 (defun article-display-x-face (&optional force)
2445 "Look for an X-Face header and display it if present."
2446 (interactive (list 'force))
2447 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2448 (gnus-with-article-headers
2449 ;; Delete the old process, if any.
2450 (when (process-status "article-x-face")
2451 (delete-process "article-x-face"))
2452 ;; See the comment in `article-display-face'.
2453 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2454 ;; We have already displayed X-Faces, so we remove them
2455 ;; instead.
2456 (gnus-delete-images 'xface)
2457 ;; Display X-Faces.
2458 (let ((from (message-fetch-field "from"))
2459 x-faces)
2460 (save-current-buffer
2461 (when (and wash-face-p
2462 (gnus-buffer-live-p gnus-original-article-buffer)
2463 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2464 ;; If type `W f', use gnus-original-article-buffer,
2465 ;; otherwise use the current buffer because displaying
2466 ;; RFC822 parts calls this function too.
2467 (set-buffer gnus-original-article-buffer))
2468 (save-restriction
2469 (mail-narrow-to-head)
2470 (and gnus-article-x-face-command
2471 (or force
2472 ;; Check whether this face is censored.
2473 (not (and gnus-article-x-face-too-ugly
2474 (or from
2475 (setq from (message-fetch-field "from")))
2476 (string-match gnus-article-x-face-too-ugly
2477 from))))
2478 (while (gnus-article-goto-header "X-Face")
2479 (push (mail-header-field-value) x-faces)))))
2480 (when x-faces
2481 ;; We display the face.
2482 (cond ((functionp gnus-article-x-face-command)
2483 ;; The command is a lisp function, so we call it.
2484 (mapc gnus-article-x-face-command x-faces))
2485 ((stringp gnus-article-x-face-command)
2486 ;; The command is a string, so we interpret the command
2487 ;; as a, well, command, and fork it off.
2488 (let ((process-connection-type nil))
2489 (gnus-set-process-query-on-exit-flag
2490 (start-process
2491 "article-x-face" nil shell-file-name
2492 shell-command-switch gnus-article-x-face-command)
2493 nil)
2494 ;; Sending multiple EOFs to xv doesn't work,
2495 ;; so we only do a single external face.
2496 (with-temp-buffer
2497 (insert (car x-faces))
2498 (process-send-region "article-x-face"
2499 (point-min) (point-max)))
2500 (process-send-eof "article-x-face")))
2501 (t
2502 (error "`%s' set to `%s' is not a function"
2503 gnus-article-x-face-command
2504 'gnus-article-x-face-command)))))))))
2505
2506 (defun article-decode-mime-words ()
2507 "Decode all MIME-encoded words in the article."
2508 (interactive)
2509 (gnus-with-article-buffer
2510 (let ((inhibit-point-motion-hooks t)
2511 (mail-parse-charset gnus-newsgroup-charset)
2512 (mail-parse-ignored-charsets
2513 (with-current-buffer gnus-summary-buffer
2514 gnus-newsgroup-ignored-charsets)))
2515 (mail-decode-encoded-word-region (point-min) (point-max)))))
2516
2517 (defun article-decode-charset (&optional prompt)
2518 "Decode charset-encoded text in the article.
2519 If PROMPT (the prefix), prompt for a coding system to use."
2520 (interactive "P")
2521 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2522 (inhibit-read-only t)
2523 (mail-parse-charset gnus-newsgroup-charset)
2524 (mail-parse-ignored-charsets
2525 (save-excursion (condition-case nil
2526 (set-buffer gnus-summary-buffer)
2527 (error))
2528 gnus-newsgroup-ignored-charsets))
2529 ct cte ctl charset format)
2530 (save-excursion
2531 (save-restriction
2532 (article-narrow-to-head)
2533 (setq ct (message-fetch-field "Content-Type" t)
2534 cte (message-fetch-field "Content-Transfer-Encoding" t)
2535 ctl (and ct (mail-header-parse-content-type ct))
2536 charset (cond
2537 (prompt
2538 (mm-read-coding-system "Charset to decode: "))
2539 (ctl
2540 (mail-content-type-get ctl 'charset)))
2541 format (and ctl (mail-content-type-get ctl 'format)))
2542 (when cte
2543 (setq cte (mail-header-strip cte)))
2544 (if (and ctl (not (string-match "/" (car ctl))))
2545 (setq ctl nil))
2546 (goto-char (point-max)))
2547 (forward-line 1)
2548 (save-restriction
2549 (narrow-to-region (point) (point-max))
2550 (when (and (eq mail-parse-charset 'gnus-decoded)
2551 (eq (mm-body-7-or-8) '8bit))
2552 ;; The text code could have been decoded.
2553 (setq charset mail-parse-charset))
2554 (when (and (or (not ctl)
2555 (equal (car ctl) "text/plain"))
2556 (not format)) ;; article with format will decode later.
2557 (mm-decode-body
2558 charset (and cte (intern (downcase
2559 (gnus-strip-whitespace cte))))
2560 (car ctl)))))))
2561
2562 (defun article-decode-encoded-words ()
2563 "Remove encoded-word encoding from headers."
2564 (let ((inhibit-point-motion-hooks t)
2565 (mail-parse-charset gnus-newsgroup-charset)
2566 (mail-parse-ignored-charsets
2567 (save-excursion (condition-case nil
2568 (set-buffer gnus-summary-buffer)
2569 (error))
2570 gnus-newsgroup-ignored-charsets))
2571 (inhibit-read-only t)
2572 end start)
2573 (goto-char (point-min))
2574 (when (search-forward "\n\n" nil 'move)
2575 (forward-line -1))
2576 (setq end (point))
2577 (while (not (bobp))
2578 (while (progn
2579 (forward-line -1)
2580 (and (not (bobp))
2581 (memq (char-after) '(?\t ? )))))
2582 (setq start (point))
2583 (if (looking-at "\
2584 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2585 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2586 (funcall gnus-decode-address-function start end)
2587 (funcall gnus-decode-header-function start end))
2588 (goto-char (setq end start)))))
2589
2590 (defun article-decode-group-name ()
2591 "Decode group names in Newsgroups, Followup-To and Xref headers."
2592 (let ((inhibit-point-motion-hooks t)
2593 (inhibit-read-only t)
2594 (method (gnus-find-method-for-group gnus-newsgroup-name))
2595 regexp)
2596 (when (and (or gnus-group-name-charset-method-alist
2597 gnus-group-name-charset-group-alist)
2598 (gnus-buffer-live-p gnus-original-article-buffer))
2599 (save-restriction
2600 (article-narrow-to-head)
2601 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2602 (with-current-buffer gnus-original-article-buffer
2603 (goto-char (point-min)))
2604 (setq regexp (concat "^" header
2605 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2606 (while (re-search-forward regexp nil t)
2607 (replace-match (save-match-data
2608 (gnus-decode-newsgroups
2609 ;; XXX how to use data in article buffer?
2610 (with-current-buffer gnus-original-article-buffer
2611 (re-search-forward regexp nil t)
2612 (match-string 1))
2613 gnus-newsgroup-name method))
2614 t t nil 1))
2615 (goto-char (point-min)))))))
2616
2617 (autoload 'idna-to-unicode "idna")
2618
2619 (defun article-decode-idna-rhs ()
2620 "Decode IDNA strings in RHS in various headers in current buffer.
2621 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2622 Mail-Reply-To: and Mail-Followup-To:."
2623 (when gnus-use-idna
2624 (save-restriction
2625 (let ((inhibit-point-motion-hooks t)
2626 (inhibit-read-only t))
2627 (article-narrow-to-head)
2628 (goto-char (point-min))
2629 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2630 (let (ace unicode)
2631 (when (save-match-data
2632 (and (setq ace (match-string 1))
2633 (save-excursion
2634 (and (re-search-backward "^[^ \t]" nil t)
2635 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2636 (setq unicode (idna-to-unicode ace))))
2637 (unless (string= ace unicode)
2638 (replace-match unicode nil nil nil 1)))))))))
2639
2640 (defun article-de-quoted-unreadable (&optional force read-charset)
2641 "Translate a quoted-printable-encoded article.
2642 If FORCE, decode the article whether it is marked as quoted-printable
2643 or not.
2644 If READ-CHARSET, ask for a coding system."
2645 (interactive (list 'force current-prefix-arg))
2646 (save-excursion
2647 (let ((inhibit-read-only t) type charset)
2648 (if (gnus-buffer-live-p gnus-original-article-buffer)
2649 (with-current-buffer gnus-original-article-buffer
2650 (setq type
2651 (gnus-fetch-field "content-transfer-encoding"))
2652 (let* ((ct (gnus-fetch-field "content-type"))
2653 (ctl (and ct (mail-header-parse-content-type ct))))
2654 (setq charset (and ctl
2655 (mail-content-type-get ctl 'charset)))
2656 (if (stringp charset)
2657 (setq charset (intern (downcase charset)))))))
2658 (if read-charset
2659 (setq charset (mm-read-coding-system "Charset: " charset)))
2660 (unless charset
2661 (setq charset gnus-newsgroup-charset))
2662 (when (or force
2663 (and type (let ((case-fold-search t))
2664 (string-match "quoted-printable" type))))
2665 (article-goto-body)
2666 (quoted-printable-decode-region
2667 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2668
2669 (defun article-de-base64-unreadable (&optional force read-charset)
2670 "Translate a base64 article.
2671 If FORCE, decode the article whether it is marked as base64 not.
2672 If READ-CHARSET, ask for a coding system."
2673 (interactive (list 'force current-prefix-arg))
2674 (save-excursion
2675 (let ((inhibit-read-only t) type charset)
2676 (if (gnus-buffer-live-p gnus-original-article-buffer)
2677 (with-current-buffer gnus-original-article-buffer
2678 (setq type
2679 (gnus-fetch-field "content-transfer-encoding"))
2680 (let* ((ct (gnus-fetch-field "content-type"))
2681 (ctl (and ct (mail-header-parse-content-type ct))))
2682 (setq charset (and ctl
2683 (mail-content-type-get ctl 'charset)))
2684 (if (stringp charset)
2685 (setq charset (intern (downcase charset)))))))
2686 (if read-charset
2687 (setq charset (mm-read-coding-system "Charset: " charset)))
2688 (unless charset
2689 (setq charset gnus-newsgroup-charset))
2690 (when (or force
2691 (and type (let ((case-fold-search t))
2692 (string-match "base64" type))))
2693 (article-goto-body)
2694 (save-restriction
2695 (narrow-to-region (point) (point-max))
2696 (base64-decode-region (point-min) (point-max))
2697 (mm-decode-coding-region
2698 (point-min) (point-max)
2699 (mm-charset-to-coding-system charset nil t)))))))
2700
2701 (eval-when-compile
2702 (require 'rfc1843))
2703
2704 (defun article-decode-HZ ()
2705 "Translate a HZ-encoded article."
2706 (interactive)
2707 (require 'rfc1843)
2708 (save-excursion
2709 (let ((inhibit-read-only t))
2710 (rfc1843-decode-region (point-min) (point-max)))))
2711
2712 (defun article-unsplit-urls ()
2713 "Remove the newlines that some other mailers insert into URLs."
2714 (interactive)
2715 (save-excursion
2716 (let ((inhibit-read-only t))
2717 (goto-char (point-min))
2718 (while (re-search-forward
2719 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2720 (replace-match "\\1\\3" t)))
2721 (when (gmm-called-interactively-p 'any)
2722 (gnus-treat-article nil))))
2723
2724 (defun article-wash-html ()
2725 "Format an HTML article."
2726 (interactive)
2727 (let ((handles nil)
2728 (buffer-read-only nil))
2729 (when (gnus-buffer-live-p gnus-original-article-buffer)
2730 (with-current-buffer gnus-original-article-buffer
2731 (setq handles (mm-dissect-buffer t t))))
2732 (article-goto-body)
2733 (delete-region (point) (point-max))
2734 (mm-enable-multibyte)
2735 (mm-inline-text-html handles)))
2736
2737 (defvar gnus-article-browse-html-temp-list nil
2738 "List of temporary files created by `gnus-article-browse-html-parts'.
2739 Internal variable.")
2740
2741 (defcustom gnus-article-browse-delete-temp 'ask
2742 "What to do with temporary files from `gnus-article-browse-html-parts'.
2743 If nil, don't delete temporary files. If it is t, delete them on
2744 exit from the summary buffer. If it is the symbol `file', query
2745 on each file, if it is `ask' ask once when exiting from the
2746 summary buffer."
2747 :group 'gnus-article
2748 :version "23.1" ;; No Gnus
2749 :type '(choice (const :tag "Don't delete" nil)
2750 (const :tag "Don't ask" t)
2751 (const :tag "Ask" ask)
2752 (const :tag "Ask for each file" file)))
2753
2754 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2755
2756 (defun gnus-article-browse-delete-temp-files (&optional how)
2757 "Delete temp-files created by `gnus-article-browse-html-parts'."
2758 (when (and gnus-article-browse-html-temp-list
2759 (progn
2760 (or how (setq how gnus-article-browse-delete-temp))
2761 (if (eq how 'ask)
2762 (let ((files (length gnus-article-browse-html-temp-list)))
2763 (or (gnus-y-or-n-p
2764 (if (= files 1)
2765 "Delete the temporary HTML file? "
2766 (format "Delete all %s temporary HTML files? "
2767 files)))
2768 (setq gnus-article-browse-html-temp-list nil)))
2769 how)))
2770 (dolist (file gnus-article-browse-html-temp-list)
2771 (cond ((file-directory-p file)
2772 (when (or (not (eq how 'file))
2773 (gnus-y-or-n-p
2774 (gnus-format-message
2775 "Delete temporary HTML file(s) in directory `%s'? "
2776 (file-name-as-directory file))))
2777 (gnus-delete-directory file)))
2778 ((file-exists-p file)
2779 (when (or (not (eq how 'file))
2780 (gnus-y-or-n-p
2781 (format "Delete temporary HTML file `%s'? " file)))
2782 (delete-file file)))))
2783 ;; Also remove file from the list when not deleted or if file doesn't
2784 ;; exist anymore.
2785 (setq gnus-article-browse-html-temp-list nil))
2786 gnus-article-browse-html-temp-list)
2787
2788 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2789 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2790 Return file name relative to the parent of DIRECTORY."
2791 (save-match-data
2792 (let (file afile)
2793 (catch 'found
2794 (dolist (handle handles)
2795 (cond
2796 ((not (listp handle)))
2797 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2798 ;; may create.
2799 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2800 ((equal (mm-handle-media-supertype handle) "multipart")
2801 (when (setq file (gnus-article-browse-html-save-cid-content
2802 cid handle directory))
2803 (throw 'found file)))
2804 ((equal (concat "<" cid ">") (mm-handle-id handle))
2805 (setq file (or (mm-handle-filename handle)
2806 (concat
2807 (make-temp-name "cid")
2808 (car (rassoc (car (mm-handle-type handle))
2809 mailcap-mime-extensions))))
2810 afile (expand-file-name file directory))
2811 (mm-save-part-to-file handle afile)
2812 (throw 'found (concat (file-name-nondirectory
2813 (directory-file-name directory))
2814 "/" file)))))))))
2815
2816 (defun gnus-article-browse-html-parts (list &optional header)
2817 "View all \"text/html\" parts from LIST.
2818 Recurse into multiparts. The optional HEADER that should be a decoded
2819 message header will be added to the bodies of the \"text/html\" parts."
2820 ;; Internal function used by `gnus-article-browse-html-article'.
2821 (let (type file charset content cid-dir tmp-file showed)
2822 ;; Find and show the html-parts.
2823 (dolist (handle list)
2824 ;; If HTML, show it:
2825 (cond ((not (listp handle)))
2826 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2827 (and (equal (car type) "message/external-body")
2828 (or header
2829 (setq file (mm-handle-filename handle)))
2830 (or (mm-handle-cache handle)
2831 (condition-case code
2832 (progn (mm-extern-cache-contents handle) t)
2833 (error
2834 (gnus-message 3 "%s" (error-message-string code))
2835 (when (>= gnus-verbose 3) (sit-for 2))
2836 nil)))
2837 (progn
2838 (setq handle (mm-handle-cache handle)
2839 type (mm-handle-type handle))
2840 (equal (car type) "text/html"))))
2841 (setq charset (mail-content-type-get type 'charset)
2842 content (mm-get-part handle))
2843 (with-temp-buffer
2844 (if (eq charset 'gnus-decoded)
2845 (mm-enable-multibyte)
2846 (mm-disable-multibyte))
2847 (insert content)
2848 ;; resolve cid contents
2849 (let ((case-fold-search t)
2850 st base regexp cid-file)
2851 (goto-char (point-min))
2852 (when (and (re-search-forward "<head[\t\n >]" nil t)
2853 (progn
2854 (setq st (match-end 0))
2855 (re-search-forward "</head[\t\n >]" nil t))
2856 (re-search-backward "<base\
2857 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2858 (setq base (match-string 1))
2859 (replace-match "<!--\\&-->")
2860 (setq st (point))
2861 (dolist (tag '(("a" . "href") ("form" . "action")
2862 ("img" . "src")))
2863 (setq regexp (concat "<" (car tag)
2864 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2865 (cdr tag) "=\"\\([^\"]+\\)"))
2866 (while (re-search-forward regexp nil t)
2867 (insert (prog1
2868 (condition-case nil
2869 (save-match-data
2870 (url-expand-file-name (match-string 1)
2871 base))
2872 (error (match-string 1)))
2873 (delete-region (match-beginning 1)
2874 (match-end 1)))))
2875 (goto-char st)))
2876 (while (re-search-forward "\
2877 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2878 nil t)
2879 (unless cid-dir
2880 (setq cid-dir (mm-make-temp-file "cid" t))
2881 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2882 (setq file nil
2883 content nil)
2884 (when (setq cid-file
2885 (gnus-article-browse-html-save-cid-content
2886 (match-string 2)
2887 (with-current-buffer gnus-article-buffer
2888 gnus-article-mime-handles)
2889 cid-dir))
2890 (replace-match cid-file nil nil nil 1))))
2891 (unless content (setq content (buffer-string))))
2892 (when (or charset header (not file))
2893 (setq tmp-file (mm-make-temp-file
2894 ;; Do we need to care for 8.3 filenames?
2895 "mm-" nil ".html")))
2896 ;; Add a meta html tag to specify charset and a header.
2897 (cond
2898 (header
2899 (let (title eheader body hcharset coding)
2900 (with-temp-buffer
2901 (mm-enable-multibyte)
2902 (setq case-fold-search t)
2903 (insert header "\n")
2904 (setq title (message-fetch-field "subject"))
2905 (goto-char (point-min))
2906 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2907 nil t)
2908 (replace-match (cond ((match-beginning 1) "&lt;")
2909 ((match-beginning 2) "&gt;")
2910 ((match-beginning 3) "&amp;")
2911 (t "<br>\n"))))
2912 (goto-char (point-min))
2913 (while (re-search-forward "^[\t ]+" nil t)
2914 (dotimes (i (prog1
2915 (current-column)
2916 (delete-region (match-beginning 0)
2917 (match-end 0))))
2918 (insert "&nbsp;")))
2919 (goto-char (point-min))
2920 (insert "<div align=\"left\">\n")
2921 (goto-char (point-max))
2922 (insert "</div>\n<hr>\n")
2923 ;; We have to examine charset one by one since
2924 ;; charset specified in parts might be different.
2925 (if (eq charset 'gnus-decoded)
2926 (setq charset 'utf-8
2927 eheader (mm-encode-coding-string (buffer-string)
2928 charset)
2929 title (when title
2930 (mm-encode-coding-string title charset))
2931 body (mm-encode-coding-string content charset))
2932 (setq hcharset (mm-find-mime-charset-region (point-min)
2933 (point-max)))
2934 (cond ((= (length hcharset) 1)
2935 (setq hcharset (car hcharset)
2936 coding (mm-charset-to-coding-system
2937 hcharset nil t)))
2938 ((> (length hcharset) 1)
2939 (setq hcharset 'utf-8
2940 coding hcharset)))
2941 (if coding
2942 (if charset
2943 (progn
2944 (setq body
2945 (mm-charset-to-coding-system charset
2946 nil t))
2947 (if (eq coding body)
2948 (setq eheader (mm-encode-coding-string
2949 (buffer-string) coding)
2950 title (when title
2951 (mm-encode-coding-string
2952 title coding))
2953 body content)
2954 (setq charset 'utf-8
2955 eheader (mm-encode-coding-string
2956 (buffer-string) charset)
2957 title (when title
2958 (mm-encode-coding-string
2959 title charset))
2960 body (mm-encode-coding-string
2961 (mm-decode-coding-string
2962 content body)
2963 charset))))
2964 (setq charset hcharset
2965 eheader (mm-encode-coding-string
2966 (buffer-string) coding)
2967 title (when title
2968 (mm-encode-coding-string
2969 title coding))
2970 body content))
2971 (setq eheader (mm-string-as-unibyte (buffer-string))
2972 body content)))
2973 (erase-buffer)
2974 (mm-disable-multibyte)
2975 (insert body)
2976 (when charset
2977 (mm-add-meta-html-tag handle charset t))
2978 (when title
2979 (goto-char (point-min))
2980 (unless (search-forward "<title>" nil t)
2981 (re-search-forward "<head>\\s-*" nil t)
2982 (insert "<title>" title "</title>\n")))
2983 (goto-char (point-min))
2984 (or (re-search-forward
2985 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2986 (re-search-forward
2987 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2988 (insert eheader)
2989 (mm-write-region (point-min) (point-max)
2990 tmp-file nil nil nil 'binary t))))
2991 (charset
2992 (mm-with-unibyte-buffer
2993 (insert (if (eq charset 'gnus-decoded)
2994 (mm-encode-coding-string content
2995 (setq charset 'utf-8))
2996 content))
2997 (if (or (mm-add-meta-html-tag handle charset)
2998 (not file))
2999 (mm-write-region (point-min) (point-max)
3000 tmp-file nil nil nil 'binary t)
3001 (setq tmp-file nil))))
3002 (tmp-file
3003 (mm-save-part-to-file handle tmp-file)))
3004 (when tmp-file
3005 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3006 (add-hook 'gnus-summary-prepare-exit-hook
3007 'gnus-article-browse-delete-temp-files)
3008 (add-hook 'gnus-exit-gnus-hook
3009 (lambda ()
3010 (gnus-article-browse-delete-temp-files t)))
3011 ;; FIXME: Warn if there's an <img> tag?
3012 (browse-url-of-file (or tmp-file (expand-file-name file)))
3013 (setq showed t))
3014 ;; If multipart, recurse
3015 ((equal (mm-handle-media-supertype handle) "multipart")
3016 (when (gnus-article-browse-html-parts handle header)
3017 (setq showed t)))
3018 ((equal (mm-handle-media-type handle) "message/rfc822")
3019 (mm-with-multibyte-buffer
3020 (mm-insert-part handle)
3021 (setq handle (mm-dissect-buffer t t))
3022 (when (and (bufferp (car handle))
3023 (stringp (car (mm-handle-type handle))))
3024 (setq handle (list handle)))
3025 (when header
3026 (article-decode-encoded-words)
3027 (let ((gnus-visible-headers
3028 (or (get 'gnus-visible-headers 'standard-value)
3029 gnus-visible-headers)))
3030 (article-hide-headers))
3031 (goto-char (point-min))
3032 (search-forward "\n\n" nil 'move)
3033 (skip-chars-backward "\t\n ")
3034 (setq header (buffer-substring (point-min) (point)))))
3035 (when (prog1
3036 (gnus-article-browse-html-parts handle header)
3037 (mm-destroy-parts handle))
3038 (setq showed t)))))
3039 showed))
3040
3041 (defun gnus-article-browse-html-article (&optional arg)
3042 "View \"text/html\" parts of the current article with a WWW browser.
3043 Inline images embedded in a message using the cid scheme, as they are
3044 generally considered to be safe, will be processed properly.
3045 The message header is added to the beginning of every html part unless
3046 the prefix argument ARG is given.
3047
3048 Warning: Spammers use links to images (using the http scheme) in HTML
3049 articles to verify whether you have read the message. As
3050 `gnus-article-browse-html-article' passes the HTML content to the
3051 browser without eliminating these \"web bugs\" you should only
3052 use it for mails from trusted senders.
3053
3054 If you always want to display HTML parts in the browser, set
3055 `mm-text-html-renderer' to nil.
3056
3057 This command creates temporary files to pass HTML contents including
3058 images if any to the browser, and deletes them when exiting the group
3059 \(if you want)."
3060 ;; Cf. `mm-w3m-safe-url-regexp'
3061 (interactive "P")
3062 (if arg
3063 (gnus-summary-show-article)
3064 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3065 gnus-visible-headers))
3066 ;; As we insert a <hr>, there's no need for the body boundary.
3067 (gnus-treat-body-boundary nil))
3068 (gnus-summary-show-article)))
3069 (with-current-buffer gnus-article-buffer
3070 (let ((header (unless arg
3071 (save-restriction
3072 (widen)
3073 (buffer-substring-no-properties
3074 (goto-char (point-min))
3075 (if (search-forward "\n\n" nil t)
3076 (match-beginning 0)
3077 (goto-char (point-max))
3078 (skip-chars-backward "\t\n ")
3079 (point))))))
3080 parts)
3081 (set-buffer gnus-original-article-buffer)
3082 (setq parts (mm-dissect-buffer t t))
3083 ;; If singlepart, enforce a list.
3084 (when (and (bufferp (car parts))
3085 (stringp (car (mm-handle-type parts))))
3086 (setq parts (list parts)))
3087 ;; Process the list
3088 (unless (gnus-article-browse-html-parts parts header)
3089 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3090 (mm-destroy-parts parts)
3091 (unless arg
3092 (gnus-summary-show-article)))))
3093
3094 (defun article-hide-list-identifiers ()
3095 "Remove list identifiers from the Subject header.
3096 The `gnus-list-identifiers' variable specifies what to do."
3097 (interactive)
3098 (let ((inhibit-point-motion-hooks t)
3099 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3100 (inhibit-read-only t))
3101 (when regexp
3102 (save-excursion
3103 (save-restriction
3104 (article-narrow-to-head)
3105 (goto-char (point-min))
3106 (while (re-search-forward
3107 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3108 nil t)
3109 (delete-region (match-beginning 2) (match-end 0))
3110 (beginning-of-line))
3111 (when (re-search-forward
3112 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3113 (delete-region (match-beginning 1) (match-end 1))))))))
3114
3115 (defun article-hide-pem (&optional arg)
3116 "Toggle hiding of any PEM headers and signatures in the current article.
3117 If given a negative prefix, always show; if given a positive prefix,
3118 always hide."
3119 (interactive (gnus-article-hidden-arg))
3120 (unless (gnus-article-check-hidden-text 'pem arg)
3121 (save-excursion
3122 (let ((inhibit-read-only t) end)
3123 (goto-char (point-min))
3124 ;; Hide the horrendously ugly "header".
3125 (when (and (search-forward
3126 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3127 nil t)
3128 (setq end (1+ (match-beginning 0))))
3129 (gnus-add-wash-type 'pem)
3130 (gnus-article-hide-text-type
3131 end
3132 (if (search-forward "\n\n" nil t)
3133 (match-end 0)
3134 (point-max))
3135 'pem)
3136 ;; Hide the trailer as well
3137 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3138 nil t)
3139 (gnus-article-hide-text-type
3140 (match-beginning 0) (match-end 0) 'pem)))))))
3141
3142 (defun article-strip-banner ()
3143 "Strip the banners specified by the `banner' group parameter and by
3144 `gnus-article-address-banner-alist'."
3145 (interactive)
3146 (save-excursion
3147 (save-restriction
3148 (let ((inhibit-point-motion-hooks t))
3149 (when (gnus-parameter-banner gnus-newsgroup-name)
3150 (article-really-strip-banner
3151 (gnus-parameter-banner gnus-newsgroup-name)))
3152 (when gnus-article-address-banner-alist
3153 ;; Note that the From header is decoded here, so it is
3154 ;; required that the *-extract-address-components function
3155 ;; supports non-ASCII text.
3156 (let ((from (save-restriction
3157 (widen)
3158 (article-narrow-to-head)
3159 (mail-fetch-field "from"))))
3160 (when (and from
3161 (setq from
3162 (cadr (funcall gnus-extract-address-components
3163 from))))
3164 (catch 'found
3165 (dolist (pair gnus-article-address-banner-alist)
3166 (when (string-match (car pair) from)
3167 (throw 'found
3168 (article-really-strip-banner (cdr pair)))))))))))))
3169
3170 (defun article-really-strip-banner (banner)
3171 "Strip the banner specified by the argument."
3172 (save-excursion
3173 (save-restriction
3174 (let ((inhibit-point-motion-hooks t)
3175 (gnus-signature-limit nil)
3176 (inhibit-read-only t))
3177 (article-goto-body)
3178 (cond
3179 ((eq banner 'signature)
3180 (when (gnus-article-narrow-to-signature)
3181 (widen)
3182 (forward-line -1)
3183 (delete-region (point) (point-max))))
3184 ((symbolp banner)
3185 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3186 (while (re-search-forward banner nil t)
3187 (delete-region (match-beginning 0) (match-end 0)))))
3188 ((stringp banner)
3189 (while (re-search-forward banner nil t)
3190 (delete-region (match-beginning 0) (match-end 0)))))))))
3191
3192 (defun article-babel ()
3193 "Translate article using an online translation service."
3194 (interactive)
3195 (require 'babel)
3196 (gnus-with-article-buffer
3197 (when (article-goto-body)
3198 (let* ((start (point))
3199 (end (point-max))
3200 (orig (buffer-substring start end))
3201 (trans (babel-as-string orig)))
3202 (save-restriction
3203 (narrow-to-region start end)
3204 (delete-region start end)
3205 (insert trans))))))
3206
3207 (defun article-hide-signature (&optional arg)
3208 "Hide the signature in the current article.
3209 If given a negative prefix, always show; if given a positive prefix,
3210 always hide."
3211 (interactive (gnus-article-hidden-arg))
3212 (unless (gnus-article-check-hidden-text 'signature arg)
3213 (save-excursion
3214 (save-restriction
3215 (let ((inhibit-read-only t))
3216 (when (gnus-article-narrow-to-signature)
3217 (gnus-article-hide-text-type
3218 (point-min) (point-max) 'signature))))))
3219 (gnus-set-mode-line 'article))
3220
3221 (defun article-strip-headers-in-body ()
3222 "Strip offensive headers from bodies."
3223 (interactive)
3224 (save-excursion
3225 (article-goto-body)
3226 (let ((case-fold-search t))
3227 (when (looking-at "x-no-archive:")
3228 (gnus-delete-line)))))
3229
3230 (defun article-strip-leading-blank-lines ()
3231 "Remove all blank lines from the beginning of the article."
3232 (interactive)
3233 (save-excursion
3234 (let ((inhibit-point-motion-hooks t)
3235 (inhibit-read-only t))
3236 (when (article-goto-body)
3237 (while (and (not (eobp))
3238 (looking-at "[ \t]*$"))
3239 (gnus-delete-line))))))
3240
3241 (defun article-narrow-to-head ()
3242 "Narrow the buffer to the head of the message.
3243 Point is left at the beginning of the narrowed-to region."
3244 (narrow-to-region
3245 (goto-char (point-min))
3246 (cond
3247 ;; Absolutely no headers displayed.
3248 ((looking-at "\n")
3249 (point))
3250 ;; Normal headers.
3251 ((search-forward "\n\n" nil 1)
3252 (1- (point)))
3253 ;; Nothing but headers.
3254 (t
3255 (point-max))))
3256 (goto-char (point-min)))
3257
3258 (defun article-goto-body ()
3259 "Place point at the start of the body."
3260 (goto-char (point-min))
3261 (cond
3262 ;; This variable is only bound when dealing with separate
3263 ;; MIME body parts.
3264 (article-goto-body-goes-to-point-min-p
3265 t)
3266 ((search-forward "\n\n" nil t)
3267 t)
3268 (t
3269 (goto-char (point-max))
3270 nil)))
3271
3272 (defun article-strip-multiple-blank-lines ()
3273 "Replace consecutive blank lines with one empty line."
3274 (interactive)
3275 (save-excursion
3276 (let ((inhibit-point-motion-hooks t)
3277 (inhibit-read-only t))
3278 ;; First make all blank lines empty.
3279 (article-goto-body)
3280 (while (re-search-forward "^[ \t]+$" nil t)
3281 (unless (gnus-annotation-in-region-p
3282 (match-beginning 0) (match-end 0))
3283 (replace-match "" nil t)))
3284 ;; Then replace multiple empty lines with a single empty line.
3285 (article-goto-body)
3286 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3287 (unless (gnus-annotation-in-region-p
3288 (match-beginning 0) (match-end 0))
3289 (delete-region (match-beginning 1) (match-end 1)))))))
3290
3291 (defun article-strip-leading-space ()
3292 "Remove all white space from the beginning of the lines in the article."
3293 (interactive)
3294 (save-excursion
3295 (let ((inhibit-point-motion-hooks t)
3296 (inhibit-read-only t))
3297 (article-goto-body)
3298 (while (re-search-forward "^[ \t]+" nil t)
3299 (replace-match "" t t)))))
3300
3301 (defun article-strip-trailing-space ()
3302 "Remove all white space from the end of the lines in the article."
3303 (interactive)
3304 (save-excursion
3305 (let ((inhibit-point-motion-hooks t)
3306 (inhibit-read-only t))
3307 (article-goto-body)
3308 (while (re-search-forward "[ \t]+$" nil t)
3309 (replace-match "" t t)))))
3310
3311 (defun article-strip-blank-lines ()
3312 "Strip leading, trailing and multiple blank lines."
3313 (interactive)
3314 (article-strip-leading-blank-lines)
3315 (article-remove-trailing-blank-lines)
3316 (article-strip-multiple-blank-lines))
3317
3318 (defun article-strip-all-blank-lines ()
3319 "Strip all blank lines."
3320 (interactive)
3321 (save-excursion
3322 (let ((inhibit-point-motion-hooks t)
3323 (inhibit-read-only t))
3324 (article-goto-body)
3325 (while (re-search-forward "^[ \t]*\n" nil t)
3326 (replace-match "" t t)))))
3327
3328 (defun gnus-article-narrow-to-signature ()
3329 "Narrow to the signature; return t if a signature is found, else nil."
3330 (let ((inhibit-point-motion-hooks t))
3331 (when (gnus-article-search-signature)
3332 (forward-line 1)
3333 ;; Check whether we have some limits to what we consider
3334 ;; to be a signature.
3335 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3336 (list gnus-signature-limit)))
3337 limit limited)
3338 (while (setq limit (pop limits))
3339 (if (or (and (integerp limit)
3340 (< (- (point-max) (point)) limit))
3341 (and (floatp limit)
3342 (< (count-lines (point) (point-max)) limit))
3343 (and (functionp limit)
3344 (funcall limit))
3345 (and (stringp limit)
3346 (not (re-search-forward limit nil t))))
3347 () ; This limit did not succeed.
3348 (setq limited t
3349 limits nil)))
3350 (unless limited
3351 (narrow-to-region (point) (point-max))
3352 t)))))
3353
3354 (defun gnus-article-search-signature ()
3355 "Search the current buffer for the signature separator.
3356 Put point at the beginning of the signature separator."
3357 (let ((cur (point)))
3358 (goto-char (point-max))
3359 (if (if (stringp gnus-signature-separator)
3360 (re-search-backward gnus-signature-separator nil t)
3361 (let ((seps gnus-signature-separator))
3362 (while (and seps
3363 (not (re-search-backward (car seps) nil t)))
3364 (pop seps))
3365 seps))
3366 t
3367 (goto-char cur)
3368 nil)))
3369
3370 (defun gnus-article-hidden-arg ()
3371 "Return the current prefix arg as a number, or 0 if no prefix."
3372 (list (if current-prefix-arg
3373 (prefix-numeric-value current-prefix-arg)
3374 0)))
3375
3376 (defun gnus-article-check-hidden-text (type arg)
3377 "Return nil if hiding is necessary.
3378 Arg can be nil or a number. nil and positive means hide, negative
3379 means show, 0 means toggle."
3380 (save-excursion
3381 (save-restriction
3382 (let ((hide (gnus-article-hidden-text-p type)))
3383 (cond
3384 ((or (null arg)
3385 (> arg 0))
3386 nil)
3387 ((< arg 0)
3388 (gnus-article-show-hidden-text type)
3389 t)
3390 (t
3391 (if (eq hide 'hidden)
3392 (progn
3393 (gnus-article-show-hidden-text type)
3394 t)
3395 nil)))))))
3396
3397 (defun gnus-article-hidden-text-p (type)
3398 "Say whether the current buffer contains hidden text of type TYPE."
3399 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3400 (while (and pos
3401 (not (get-text-property pos 'invisible))
3402 (not (get-text-property pos 'dummy-invisible)))
3403 (setq pos
3404 (text-property-any (1+ pos) (point-max) 'article-type type)))
3405 (if pos
3406 'hidden
3407 nil)))
3408
3409 (defun gnus-article-show-hidden-text (type &optional _dummy)
3410 "Show all hidden text of type TYPE.
3411 Originally it is hide instead of DUMMY."
3412 (let ((inhibit-read-only t)
3413 (inhibit-point-motion-hooks t))
3414 (gnus-remove-text-properties-when
3415 'article-type type
3416 (point-min) (point-max)
3417 (cons 'article-type (cons type
3418 gnus-hidden-properties)))
3419 (gnus-delete-wash-type type)))
3420
3421 (defconst article-time-units
3422 `((year . ,(* 365.25 24 60 60))
3423 (week . ,(* 7 24 60 60))
3424 (day . ,(* 24 60 60))
3425 (hour . ,(* 60 60))
3426 (minute . 60)
3427 (second . 1))
3428 "Mapping from time units to seconds.")
3429
3430 (defun gnus-article-forward-header ()
3431 "Move point to the start of the next header.
3432 If the current header is a continuation header, this can be several
3433 lines forward."
3434 (let ((ended nil))
3435 (while (not ended)
3436 (forward-line 1)
3437 (if (looking-at "[ \t]+[^ \t]")
3438 (forward-line 1)
3439 (setq ended t)))))
3440
3441 (defun article-treat-date ()
3442 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3443 (with-current-buffer gnus-summary-buffer
3444 gnus-article-date-headers)
3445 gnus-article-date-headers)
3446 t))
3447
3448 (defun article-date-ut (&optional type _highlight date-position)
3449 "Convert DATE date to TYPE in the current article.
3450 The default type is `ut'. See `gnus-article-date-headers' for
3451 possible values."
3452 (interactive (list 'ut t))
3453 (let* ((case-fold-search t)
3454 (inhibit-read-only t)
3455 (inhibit-point-motion-hooks t)
3456 (visible-date (mail-fetch-field "Date"))
3457 pos date bface eface)
3458 (save-excursion
3459 (if date-position
3460 (progn
3461 (goto-char date-position)
3462 (setq date (get-text-property (point) 'original-date))
3463 (when (looking-at "[^:]+:[\t ]*")
3464 (setq bface (get-text-property (match-beginning 0) 'face)
3465 eface (get-text-property (match-end 0) 'face)))
3466 (delete-region (point)
3467 (progn
3468 (gnus-article-forward-header)
3469 (point)))
3470 (article-transform-date date type bface eface))
3471 (save-restriction
3472 (widen)
3473 (goto-char (point-min))
3474 (while (or (get-text-property (setq pos (point)) 'original-date)
3475 (and (setq pos (next-single-property-change
3476 (point) 'original-date))
3477 (goto-char pos)))
3478 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3479 (1+ (match-beginning 0))
3480 (point-max)))
3481 (while (setq pos (text-property-not-all pos (point-max)
3482 'gnus-date-type nil))
3483 (setq date (get-text-property pos 'original-date))
3484 (goto-char pos)
3485 (when (looking-at "[^:]+:[\t ]*")
3486 (setq bface (get-text-property (match-beginning 0) 'face)
3487 eface (get-text-property (match-end 0) 'face)))
3488 (delete-region pos (or (text-property-any pos (point-max)
3489 'gnus-date-type nil)
3490 (point-max))))
3491 (unless date ;; the 1st time
3492 (goto-char (point-min))
3493 (while (re-search-forward "^Date:[\t ]*" nil t)
3494 (setq date (get-text-property (match-beginning 0)
3495 'original-date)
3496 bface (get-text-property (match-beginning 0) 'face)
3497 eface (get-text-property (match-end 0) 'face))
3498 (delete-region (point-at-bol) (progn
3499 (gnus-article-forward-header)
3500 (point)))))
3501 (when (and (not date)
3502 visible-date)
3503 (setq date visible-date))
3504 (when date
3505 (article-transform-date date type bface eface))
3506 (goto-char (point-max))
3507 (widen)))))))
3508
3509 (defun article-transform-date (date type bface eface)
3510 (dolist (this-type (cond
3511 ((null type)
3512 (list 'ut))
3513 ((atom type)
3514 (list type))
3515 (t
3516 type)))
3517 (goto-char
3518 (prog1
3519 (point)
3520 (add-text-properties
3521 (point)
3522 (progn
3523 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3524 (point))
3525 (list 'original-date date 'gnus-date-type this-type))))
3526 ;; Do highlighting.
3527 (when (looking-at
3528 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3529 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3530 (when (match-beginning 2)
3531 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3532 (while (and (zerop (forward-line 1))
3533 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3534 (when (match-beginning 1)
3535 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3536
3537 (defun article-make-date-line (date type)
3538 "Return a DATE line of TYPE."
3539 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3540 combined-lapsed))
3541 (error "Unknown conversion type: %s" type))
3542 (condition-case ()
3543 (let ((time (ignore-errors (date-to-time date))))
3544 (cond
3545 ;; Convert to the local timezone.
3546 ((eq type 'local)
3547 (concat "Date: " (message-make-date time)))
3548 ;; Convert to Universal Time.
3549 ((eq type 'ut)
3550 (concat "Date: "
3551 (substring
3552 (message-make-date
3553 (let* ((e (parse-time-string date))
3554 (tm (apply 'encode-time e))
3555 (ms (car tm))
3556 (ls (- (cadr tm) (car (current-time-zone time)))))
3557 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3558 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3559 (t (list ms ls)))))
3560 0 -5)
3561 "UT"))
3562 ;; Get the original date from the article.
3563 ((eq type 'original)
3564 (concat "Date: " (if (string-match "\n+$" date)
3565 (substring date 0 (match-beginning 0))
3566 date)))
3567 ;; Let the user define the format.
3568 ((eq type 'user-defined)
3569 (let ((format (or (condition-case nil
3570 (with-current-buffer gnus-summary-buffer
3571 gnus-article-time-format)
3572 (error nil))
3573 gnus-article-time-format)))
3574 (if (functionp format)
3575 (funcall format time)
3576 (concat "Date: " (format-time-string format time)))))
3577 ;; ISO 8601.
3578 ((eq type 'iso8601)
3579 (let ((tz (car (current-time-zone time))))
3580 (concat
3581 "Date: "
3582 (format-time-string "%Y%m%dT%H%M%S" time)
3583 (format "%s%02d%02d"
3584 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3585 (/ (% (abs tz) 3600) 60)))))
3586 ;; Do a lapsed format.
3587 ((eq type 'lapsed)
3588 (concat "Date: " (article-lapsed-string time)))
3589 ;; A combined date/lapsed format.
3590 ((eq type 'combined-lapsed)
3591 (let ((date-string (article-make-date-line date 'original))
3592 (segments 3)
3593 lapsed-string)
3594 (while (and
3595 time
3596 (setq lapsed-string
3597 (concat " (" (article-lapsed-string time segments) ")"))
3598 (> (+ (length date-string)
3599 (length lapsed-string))
3600 (+ fill-column 6))
3601 (> segments 0))
3602 (setq segments (1- segments)))
3603 (if (> segments 0)
3604 (concat date-string lapsed-string)
3605 date-string)))
3606 ;; Display the date in proper English
3607 ((eq type 'english)
3608 (let ((dtime (decode-time time)))
3609 (concat
3610 "Date: the "
3611 (number-to-string (nth 3 dtime))
3612 (let ((digit (% (nth 3 dtime) 10)))
3613 (cond
3614 ((memq (nth 3 dtime) '(11 12 13)) "th")
3615 ((= digit 1) "st")
3616 ((= digit 2) "nd")
3617 ((= digit 3) "rd")
3618 (t "th")))
3619 " of "
3620 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3621 " "
3622 (number-to-string (nth 5 dtime))
3623 " at "
3624 (format "%02d" (nth 2 dtime))
3625 ":"
3626 (format "%02d" (nth 1 dtime)))))))
3627 (foo
3628 (format "Date: %s (from Gnus)" date))))
3629
3630 (defun article-lapsed-string (time &optional max-segments)
3631 ;; If the date is seriously mangled, the timezone functions are
3632 ;; liable to bug out, so we ignore all errors.
3633 (let* ((now (current-time))
3634 (real-time (subtract-time now time))
3635 (real-sec (and real-time
3636 (+ (* (float (car real-time)) 65536)
3637 (cadr real-time))))
3638 (sec (and real-time (abs real-sec)))
3639 (segments 0)
3640 num prev)
3641 (unless max-segments
3642 (setq max-segments (length article-time-units)))
3643 (cond
3644 ((null real-time)
3645 "Unknown")
3646 ((zerop sec)
3647 "Now")
3648 (t
3649 (concat
3650 ;; This is a bit convoluted, but basically we go
3651 ;; through the time units for years, weeks, etc,
3652 ;; and divide things to see whether that results
3653 ;; in positive answers.
3654 (mapconcat
3655 (lambda (unit)
3656 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3657 (>= segments max-segments))
3658 ;; The (remaining) seconds are too few to
3659 ;; be divided into this time unit.
3660 ""
3661 ;; It's big enough, so we output it.
3662 (setq sec (- sec (* num (cdr unit))))
3663 (prog1
3664 (concat (if prev ", " "") (int-to-string
3665 (floor num))
3666 " " (symbol-name (car unit))
3667 (if (> num 1) "s" ""))
3668 (setq prev t
3669 segments (1+ segments)))))
3670 article-time-units "")
3671 ;; If dates are odd, then it might appear like the
3672 ;; article was sent in the future.
3673 (if (> real-sec 0)
3674 " ago"
3675 " in the future"))))))
3676
3677 (defun article-date-local (&optional highlight)
3678 "Convert the current article date to the local timezone."
3679 (interactive (list t))
3680 (article-date-ut 'local highlight))
3681
3682 (defun article-date-english (&optional highlight)
3683 "Convert the current article date to something that is proper English."
3684 (interactive (list t))
3685 (article-date-ut 'english highlight))
3686
3687 (defun article-date-original (&optional highlight)
3688 "Convert the current article date to what it was originally.
3689 This is only useful if you have used some other date conversion
3690 function and want to see what the date was before converting."
3691 (interactive (list t))
3692 (article-date-ut 'original highlight))
3693
3694 (defun article-date-lapsed (&optional highlight)
3695 "Convert the current article date to time lapsed since it was sent."
3696 (interactive (list t))
3697 (article-date-ut 'lapsed highlight))
3698
3699 (defun article-date-combined-lapsed (&optional highlight)
3700 "Convert the current article date to time lapsed since it was sent."
3701 (interactive (list t))
3702 (article-date-ut 'combined-lapsed highlight))
3703
3704 (defun article-update-date-lapsed ()
3705 "Function to be run from a timer to update the lapsed time line."
3706 (save-match-data
3707 (let ((buffer (current-buffer)))
3708 (ignore-errors
3709 (walk-windows
3710 (lambda (w)
3711 (set-buffer (window-buffer w))
3712 (when (derived-mode-p 'gnus-article-mode)
3713 (let ((old-line (count-lines (point-min) (point)))
3714 (old-column (- (point) (line-beginning-position)))
3715 (window-start (window-start w))
3716 (pos (point-min))
3717 type next end)
3718 (while (setq pos (text-property-not-all pos (point-max)
3719 'gnus-date-type nil))
3720 (setq next (or (next-single-property-change pos
3721 'gnus-date-type)
3722 (point-max)))
3723 (setq type (get-text-property pos 'gnus-date-type))
3724 (when (memq type '(lapsed combined-lapsed user-defined))
3725 (article-date-ut type t pos)
3726 (setq end (or (next-single-property-change pos
3727 'gnus-date-type)
3728 (point-max)))
3729 (when window-start
3730 (if (/= window-start next)
3731 (setq window-start nil)
3732 (set-window-start w end)))
3733 (setq next end))
3734 (setq pos next))
3735 (goto-char (point-min))
3736 (when (> old-column 0)
3737 (setq old-line (1- old-line)))
3738 (forward-line old-line)
3739 (end-of-line)
3740 (when (> (current-column) old-column)
3741 (beginning-of-line)
3742 (forward-char old-column)))))
3743 nil 'visible))
3744 (set-buffer buffer))))
3745
3746 (defun gnus-start-date-timer (&optional n)
3747 "Start a timer to update the Date headers in the article buffers.
3748 The numerical prefix says how frequently (in seconds) the function
3749 is to run."
3750 (interactive "p")
3751 (unless n
3752 (setq n 1))
3753 (gnus-stop-date-timer)
3754 (setq article-lapsed-timer
3755 (run-at-time 1 n 'article-update-date-lapsed)))
3756
3757 (defun gnus-stop-date-timer ()
3758 "Stop the Date timer."
3759 (interactive)
3760 (when article-lapsed-timer
3761 (nnheader-cancel-timer article-lapsed-timer)
3762 (setq article-lapsed-timer nil)))
3763
3764 (defun article-date-user (&optional highlight)
3765 "Convert the current article date to the user-defined format.
3766 This format is defined by the `gnus-article-time-format' variable."
3767 (interactive (list t))
3768 (article-date-ut 'user highlight))
3769
3770 (defun article-date-iso8601 (&optional highlight)
3771 "Convert the current article date to ISO8601."
3772 (interactive (list t))
3773 (article-date-ut 'iso8601 highlight))
3774
3775 (defmacro gnus-article-save-original-date (&rest forms)
3776 "Save the original date as a text property and evaluate FORMS."
3777 `(let* ((case-fold-search t)
3778 (start (progn
3779 (goto-char (point-min))
3780 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3781 (not (bolp)))
3782 (match-end 0))))
3783 (date (when (and start
3784 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3785 nil t))
3786 (buffer-substring-no-properties start
3787 (match-beginning 0)))))
3788 (goto-char (point-max))
3789 (skip-chars-backward "\n")
3790 (put-text-property (point-min) (point) 'original-date date)
3791 ,@forms
3792 (goto-char (point-max))
3793 (skip-chars-backward "\n")
3794 (put-text-property (point-min) (point) 'original-date date)))
3795
3796 ;; (defun article-show-all ()
3797 ;; "Show all hidden text in the article buffer."
3798 ;; (interactive)
3799 ;; (save-excursion
3800 ;; (let ((inhibit-read-only t))
3801 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3802
3803 (defun article-remove-leading-whitespace ()
3804 "Remove excessive whitespace from all headers."
3805 (interactive)
3806 (save-excursion
3807 (save-restriction
3808 (let ((inhibit-read-only t))
3809 (article-narrow-to-head)
3810 (goto-char (point-min))
3811 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3812 (delete-region (match-beginning 1) (match-end 1)))))))
3813
3814 (defun article-emphasize (&optional arg)
3815 "Emphasize text according to `gnus-emphasis-alist'."
3816 (interactive (gnus-article-hidden-arg))
3817 (unless (gnus-article-check-hidden-text 'emphasis arg)
3818 (save-excursion
3819 (let ((alist (or
3820 (condition-case nil
3821 (with-current-buffer gnus-summary-buffer
3822 gnus-article-emphasis-alist)
3823 (error))
3824 gnus-emphasis-alist))
3825 (inhibit-read-only t)
3826 (props (append '(article-type emphasis)
3827 gnus-hidden-properties))
3828 regexp elem beg invisible visible face)
3829 (article-goto-body)
3830 (setq beg (point))
3831 (while (setq elem (pop alist))
3832 (goto-char beg)
3833 (setq regexp (car elem)
3834 invisible (nth 1 elem)
3835 visible (nth 2 elem)
3836 face (nth 3 elem))
3837 (while (re-search-forward regexp nil t)
3838 (when (and (match-beginning visible) (match-beginning invisible))
3839 (gnus-article-hide-text
3840 (match-beginning invisible) (match-end invisible) props)
3841 (gnus-article-unhide-text-type
3842 (match-beginning visible) (match-end visible) 'emphasis)
3843 (gnus-put-overlay-excluding-newlines
3844 (match-beginning visible) (match-end visible) 'face face)
3845 (gnus-add-wash-type 'emphasis)
3846 (goto-char (match-end invisible)))))))))
3847
3848 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3849 "Setup newsgroup emphasis alist."
3850 (unless gnus-article-emphasis-alist
3851 (let ((name (and gnus-newsgroup-name
3852 (gnus-group-real-name gnus-newsgroup-name))))
3853 (make-local-variable 'gnus-article-emphasis-alist)
3854 (setq gnus-article-emphasis-alist
3855 (nconc
3856 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3857 (while (setq elem (pop alist))
3858 (when (and name (string-match (car elem) name))
3859 (setq alist nil
3860 highlight (copy-sequence (cdr elem)))))
3861 highlight)
3862 (copy-sequence highlight-words)
3863 (if gnus-newsgroup-name
3864 (copy-sequence (gnus-group-find-parameter
3865 gnus-newsgroup-name 'highlight-words t)))
3866 gnus-emphasis-alist)))))
3867
3868 (defvar gnus-summary-article-menu)
3869 (defvar gnus-summary-post-menu)
3870
3871 ;;; Saving functions.
3872
3873 (defun gnus-article-save (save-buffer file &optional num)
3874 "Save the currently selected article."
3875 (when (or (get gnus-default-article-saver :headers)
3876 (not gnus-save-all-headers))
3877 ;; Remove headers according to `gnus-saved-headers' or the value
3878 ;; of the `:headers' property that the saver function might have.
3879 (let ((gnus-visible-headers
3880 (or (symbol-value (get gnus-default-article-saver :headers))
3881 gnus-saved-headers gnus-visible-headers))
3882 ;; Ignore group parameter. See `article-hide-headers'.
3883 (gnus-summary-buffer nil))
3884 (with-current-buffer save-buffer
3885 (article-hide-headers 1 t))))
3886 (save-window-excursion
3887 (if (not gnus-default-article-saver)
3888 (error "No default saver is defined")
3889 ;; !!! Magic! The saving functions all save
3890 ;; `gnus-save-article-buffer' (or so they think), but we
3891 ;; bind that variable to our save-buffer.
3892 (set-buffer gnus-article-buffer)
3893 (let* ((gnus-save-article-buffer save-buffer)
3894 (filename
3895 (cond
3896 ((not gnus-prompt-before-saving) 'default)
3897 ((eq gnus-prompt-before-saving 'always) nil)
3898 (t file)))
3899 (gnus-number-of-articles-to-be-saved
3900 (when (eq gnus-prompt-before-saving t)
3901 num))) ; Magic
3902 (set-buffer gnus-article-current-summary)
3903 (funcall gnus-default-article-saver filename)))))
3904
3905 (defun gnus-read-save-file-name (prompt &optional filename
3906 function group headers variable
3907 dir-var)
3908 (let ((default-name
3909 (funcall function group headers (symbol-value variable)))
3910 result)
3911 (setq result
3912 (expand-file-name
3913 (cond
3914 ((eq filename 'default)
3915 default-name)
3916 ((eq filename t)
3917 default-name)
3918 (filename filename)
3919 (t
3920 (when (symbol-value dir-var)
3921 (setq default-name (expand-file-name
3922 (file-name-nondirectory default-name)
3923 (symbol-value dir-var))))
3924 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3925 (prompt
3926 (format prompt
3927 (if (and gnus-number-of-articles-to-be-saved
3928 (> gnus-number-of-articles-to-be-saved 1))
3929 (format "these %d articles"
3930 gnus-number-of-articles-to-be-saved)
3931 "this article")))
3932 (file
3933 ;; Let the split methods have their say.
3934 (cond
3935 ;; No split name was found.
3936 ((null split-name)
3937 (read-file-name
3938 (concat prompt " (default "
3939 (file-name-nondirectory default-name) "): ")
3940 (file-name-directory default-name)
3941 default-name))
3942 ;; A single group name is returned.
3943 ((stringp split-name)
3944 (setq default-name
3945 (funcall function split-name headers
3946 (symbol-value variable)))
3947 (read-file-name
3948 (concat prompt " (default "
3949 (file-name-nondirectory default-name) "): ")
3950 (file-name-directory default-name)
3951 default-name))
3952 ;; A single split name was found
3953 ((= 1 (length split-name))
3954 (let* ((name (expand-file-name
3955 (car split-name)
3956 gnus-article-save-directory))
3957 (dir (cond ((file-directory-p name)
3958 (file-name-as-directory name))
3959 ((file-exists-p name) name)
3960 (t gnus-article-save-directory))))
3961 (read-file-name
3962 (concat prompt " (default " name "): ")
3963 dir name)))
3964 ;; A list of splits was found.
3965 (t
3966 (setq split-name (nreverse split-name))
3967 (let (result)
3968 (let ((file-name-history
3969 (nconc split-name file-name-history)))
3970 (setq result
3971 (expand-file-name
3972 (read-file-name
3973 (concat prompt " (`M-p' for defaults): ")
3974 gnus-article-save-directory
3975 (car split-name))
3976 gnus-article-save-directory)))
3977 (car (push result file-name-history)))))))
3978 ;; Create the directory.
3979 (gnus-make-directory (file-name-directory file))
3980 ;; If we have read a directory, we append the default file name.
3981 (when (file-directory-p file)
3982 (setq file (expand-file-name (file-name-nondirectory
3983 default-name)
3984 (file-name-as-directory file))))
3985 ;; Possibly translate some characters.
3986 (nnheader-translate-file-chars file))))))
3987 (gnus-make-directory (file-name-directory result))
3988 (when variable
3989 (set variable result))
3990 (when dir-var
3991 (set dir-var (file-name-directory result)))
3992 result))
3993
3994 (defun gnus-article-archive-name (_group)
3995 "Return the first instance of an \"Archive-name\" in the current buffer."
3996 (let ((case-fold-search t))
3997 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3998 (nnheader-concat gnus-article-save-directory
3999 (match-string 1)))))
4000
4001 (defun gnus-article-nndoc-name (group)
4002 "If GROUP is an nndoc group, return the name of the parent group."
4003 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4004 (gnus-group-get-parameter group 'save-article-group)))
4005
4006 (defun gnus-summary-save-in-rmail (&optional filename)
4007 "Append this article to Rmail file.
4008 Optional argument FILENAME specifies file name.
4009 Directory to save to is default to `gnus-article-save-directory'."
4010 (setq filename (gnus-read-save-file-name
4011 "Save %s in rmail file" filename
4012 gnus-rmail-save-name gnus-newsgroup-name
4013 gnus-current-headers 'gnus-newsgroup-last-rmail))
4014 (with-current-buffer gnus-save-article-buffer
4015 (save-excursion
4016 (save-restriction
4017 (widen)
4018 ;; Note that unlike gnus-summary-save-in-mail, there is no
4019 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4020 ;; not use Babyl.
4021 (gnus-output-to-rmail filename))))
4022 filename)
4023
4024 (defun gnus-summary-save-in-mail (&optional filename)
4025 "Append this article to Unix mail file.
4026 Optional argument FILENAME specifies file name.
4027 Directory to save to is default to `gnus-article-save-directory'."
4028 (setq filename (gnus-read-save-file-name
4029 "Save %s in Unix mail file" filename
4030 gnus-mail-save-name gnus-newsgroup-name
4031 gnus-current-headers 'gnus-newsgroup-last-mail))
4032 (with-current-buffer gnus-save-article-buffer
4033 (save-excursion
4034 (save-restriction
4035 (widen)
4036 (if (and (file-readable-p filename)
4037 (file-regular-p filename)
4038 (mail-file-babyl-p filename))
4039 (gnus-output-to-rmail filename)
4040 (gnus-output-to-mail filename)))))
4041 filename)
4042
4043 (put 'gnus-summary-save-in-file :decode t)
4044 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4045 (defun gnus-summary-save-in-file (&optional filename overwrite)
4046 "Append this article to file.
4047 Optional argument FILENAME specifies file name.
4048 Directory to save to is default to `gnus-article-save-directory'."
4049 (setq filename (gnus-read-save-file-name
4050 "Save %s in file" filename
4051 gnus-file-save-name gnus-newsgroup-name
4052 gnus-current-headers 'gnus-newsgroup-last-file))
4053 (with-current-buffer gnus-save-article-buffer
4054 (save-excursion
4055 (save-restriction
4056 (widen)
4057 (when (and overwrite
4058 (file-exists-p filename))
4059 (delete-file filename))
4060 (gnus-output-to-file filename))))
4061 filename)
4062
4063 (put 'gnus-summary-write-to-file :decode t)
4064 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4065 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4066 (defun gnus-summary-write-to-file (&optional filename)
4067 "Write this article to a file, overwriting it if the file exists.
4068 Optional argument FILENAME specifies file name.
4069 The directory to save in defaults to `gnus-article-save-directory'."
4070 (setq filename (gnus-read-save-file-name
4071 "Save %s in file" filename
4072 gnus-file-save-name gnus-newsgroup-name
4073 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4074 (gnus-summary-save-in-file filename t))
4075
4076 (put 'gnus-summary-save-body-in-file :decode t)
4077 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4078 "Append this article body to a file.
4079 Optional argument FILENAME specifies file name.
4080 The directory to save in defaults to `gnus-article-save-directory'."
4081 (setq filename (gnus-read-save-file-name
4082 "Save %s body in file" filename
4083 gnus-file-save-name gnus-newsgroup-name
4084 gnus-current-headers 'gnus-newsgroup-last-file))
4085 (with-current-buffer gnus-save-article-buffer
4086 (save-excursion
4087 (save-restriction
4088 (widen)
4089 (when (article-goto-body)
4090 (narrow-to-region (point) (point-max)))
4091 (when (and overwrite
4092 (file-exists-p filename))
4093 (delete-file filename))
4094 (gnus-output-to-file filename))))
4095 filename)
4096
4097 (put 'gnus-summary-write-body-to-file :decode t)
4098 (put 'gnus-summary-write-body-to-file
4099 :function 'gnus-summary-save-body-in-file)
4100 (defun gnus-summary-write-body-to-file (&optional filename)
4101 "Write this article body to a file, overwriting it if the file exists.
4102 Optional argument FILENAME specifies file name.
4103 The directory to save in defaults to `gnus-article-save-directory'."
4104 (setq filename (gnus-read-save-file-name
4105 "Save %s body in file" filename
4106 gnus-file-save-name gnus-newsgroup-name
4107 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4108 (gnus-summary-save-body-in-file filename t))
4109
4110 (put 'gnus-summary-save-in-pipe :decode t)
4111 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4112 (defun gnus-summary-save-in-pipe (&optional command raw)
4113 "Pipe this article to subprocess COMMAND.
4114 Valid values for COMMAND include:
4115 a string
4116 The executable command name and possibly arguments.
4117 nil
4118 You will be prompted for the command in the minibuffer.
4119 the symbol `default'
4120 It will be replaced with the command which the variable
4121 `gnus-summary-pipe-output-default-command' holds or the command
4122 last used for saving.
4123 Non-nil value for RAW overrides `:decode' and `:headers' properties
4124 and the raw article including all headers will be piped."
4125 (let ((article (gnus-summary-article-number))
4126 (decode (unless raw
4127 (get 'gnus-summary-save-in-pipe :decode)))
4128 save-buffer default)
4129 (if article
4130 (if (vectorp (gnus-summary-article-header article))
4131 (save-current-buffer
4132 (gnus-summary-select-article decode decode nil article)
4133 (insert-buffer-substring
4134 (prog1
4135 (if decode
4136 gnus-article-buffer
4137 gnus-original-article-buffer)
4138 (setq save-buffer
4139 (nnheader-set-temp-buffer " *Gnus Save*"))))
4140 ;; Remove unwanted headers.
4141 (when (and (not raw)
4142 (or (get 'gnus-summary-save-in-pipe :headers)
4143 (not gnus-save-all-headers)))
4144 (let ((gnus-visible-headers
4145 (or (symbol-value (get 'gnus-summary-save-in-pipe
4146 :headers))
4147 gnus-saved-headers gnus-visible-headers))
4148 (gnus-summary-buffer nil))
4149 (article-hide-headers 1 t))))
4150 (error "%d is not a real article" article))
4151 (error "No article to pipe"))
4152 (setq default (or gnus-summary-pipe-output-default-command
4153 gnus-last-shell-command))
4154 (unless (stringp command)
4155 (setq command
4156 (if (and (eq command 'default) default)
4157 default
4158 (gnus-read-shell-command "Shell command on this article: "
4159 default))))
4160 (when (string-equal command "")
4161 (if default
4162 (setq command default)
4163 (error "A command is required")))
4164 (with-current-buffer save-buffer
4165 (save-restriction
4166 (widen)
4167 (shell-command-on-region (point-min) (point-max) command nil)))
4168 (gnus-kill-buffer save-buffer))
4169 (setq gnus-summary-pipe-output-default-command command))
4170
4171 (defun gnus-summary-pipe-to-muttprint (&optional command)
4172 "Pipe this article to muttprint."
4173 (unless (stringp command)
4174 (setq command (read-string
4175 "Print using command: " gnus-summary-muttprint-program
4176 nil gnus-summary-muttprint-program)))
4177 (let ((gnus-summary-pipe-output-default-command
4178 gnus-summary-pipe-output-default-command))
4179 (gnus-summary-save-in-pipe command))
4180 (setq gnus-summary-muttprint-program command))
4181
4182 ;;; Article file names when saving.
4183
4184 (defun gnus-capitalize-newsgroup (newsgroup)
4185 "Capitalize NEWSGROUP name."
4186 (when (not (zerop (length newsgroup)))
4187 (concat (char-to-string (upcase (aref newsgroup 0)))
4188 (substring newsgroup 1))))
4189
4190 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4191 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4192 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4193 Otherwise, it is like ~/News/news/group/num."
4194 (let ((default
4195 (expand-file-name
4196 (concat (if (gnus-use-long-file-name 'not-save)
4197 (gnus-capitalize-newsgroup newsgroup)
4198 (gnus-newsgroup-directory-form newsgroup))
4199 "/" (int-to-string (mail-header-number headers)))
4200 gnus-article-save-directory)))
4201 (if (and last-file
4202 (string-equal (file-name-directory default)
4203 (file-name-directory last-file))
4204 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4205 default
4206 (or last-file default))))
4207
4208 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4209 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4210 If variable `gnus-use-long-file-name' is non-nil, it is
4211 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4212 (let ((default
4213 (expand-file-name
4214 (concat (if (gnus-use-long-file-name 'not-save)
4215 newsgroup
4216 (gnus-newsgroup-directory-form newsgroup))
4217 "/" (int-to-string (mail-header-number headers)))
4218 gnus-article-save-directory)))
4219 (if (and last-file
4220 (string-equal (file-name-directory default)
4221 (file-name-directory last-file))
4222 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4223 default
4224 (or last-file default))))
4225
4226 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4227 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4228 If variable `gnus-use-long-file-name' is non-nil, it is
4229 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4230 (or last-file
4231 (expand-file-name
4232 (if (gnus-use-long-file-name 'not-save)
4233 newsgroup
4234 (file-relative-name
4235 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4236 default-directory))
4237 gnus-article-save-directory)))
4238
4239 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4240 "Generate file name from sender."
4241 (let ((from (mail-header-from headers)))
4242 (expand-file-name
4243 (if (and from (string-match "\\([^ <]+\\)@" from))
4244 (match-string 1 from)
4245 "nobody")
4246 gnus-article-save-directory)))
4247
4248 (defun article-verify-x-pgp-sig ()
4249 "Verify X-PGP-Sig."
4250 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4251 (interactive)
4252 (if (gnus-buffer-live-p gnus-original-article-buffer)
4253 (let ((sig (with-current-buffer gnus-original-article-buffer
4254 (gnus-fetch-field "X-PGP-Sig")))
4255 items info headers)
4256 (when (and sig
4257 mml2015-use
4258 (mml2015-clear-verify-function))
4259 (with-temp-buffer
4260 (insert-buffer-substring gnus-original-article-buffer)
4261 (setq items (split-string sig))
4262 (message-narrow-to-head)
4263 (let ((inhibit-point-motion-hooks t)
4264 (case-fold-search t))
4265 ;; Don't verify multiple headers.
4266 (setq headers (mapconcat (lambda (header)
4267 (concat header ": "
4268 (mail-fetch-field header)
4269 "\n"))
4270 (split-string (nth 1 items) ",") "")))
4271 (delete-region (point-min) (point-max))
4272 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4273 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4274 (insert headers)
4275 (widen)
4276 (forward-line)
4277 (while (not (eobp))
4278 (if (looking-at "^-")
4279 (insert "- "))
4280 (forward-line))
4281 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4282 (insert "Version: " (car items) "\n\n")
4283 (insert (mapconcat 'identity (cddr items) "\n"))
4284 (insert "\n-----END PGP SIGNATURE-----\n")
4285 (let ((mm-security-handle (list (format "multipart/signed"))))
4286 (mml2015-clean-buffer)
4287 (let ((coding-system-for-write (or gnus-newsgroup-charset
4288 'iso-8859-1)))
4289 (funcall (mml2015-clear-verify-function)))
4290 (setq info
4291 (or (mm-handle-multipart-ctl-parameter
4292 mm-security-handle 'gnus-details)
4293 (mm-handle-multipart-ctl-parameter
4294 mm-security-handle 'gnus-info)))))
4295 (when info
4296 (let ((inhibit-read-only t) bface eface)
4297 (save-restriction
4298 (message-narrow-to-head)
4299 (goto-char (point-max))
4300 (forward-line -1)
4301 (setq bface (get-text-property (point-at-bol) 'face)
4302 eface (get-text-property (1- (point-at-eol)) 'face))
4303 (message-remove-header "X-Gnus-PGP-Verify")
4304 (if (re-search-forward "^X-PGP-Sig:" nil t)
4305 (forward-line)
4306 (goto-char (point-max)))
4307 (narrow-to-region (point) (point))
4308 (insert "X-Gnus-PGP-Verify: " info "\n")
4309 (goto-char (point-min))
4310 (forward-line)
4311 (while (not (eobp))
4312 (if (not (looking-at "^[ \t]"))
4313 (insert " "))
4314 (forward-line))
4315 ;; Do highlighting.
4316 (goto-char (point-min))
4317 (when (looking-at "\\([^:]+\\): *")
4318 (put-text-property (match-beginning 1) (1+ (match-end 1))
4319 'face bface)
4320 (put-text-property (match-end 0) (point-max)
4321 'face eface)))))))))
4322
4323 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4324
4325 (defun article-verify-cancel-lock ()
4326 "Verify Cancel-Lock header."
4327 (interactive)
4328 (if (gnus-buffer-live-p gnus-original-article-buffer)
4329 (canlock-verify gnus-original-article-buffer)))
4330
4331 (eval-and-compile
4332 (mapc
4333 (lambda (func)
4334 (let (afunc gfunc)
4335 (if (consp func)
4336 (setq afunc (car func)
4337 gfunc (cdr func))
4338 (setq afunc func
4339 gfunc (intern (format "gnus-%s" func))))
4340 (defalias gfunc
4341 (when (fboundp afunc)
4342 `(lambda (&optional interactive &rest args)
4343 ,(documentation afunc t)
4344 (interactive (list t))
4345 (with-current-buffer gnus-article-buffer
4346 (if interactive
4347 (call-interactively ',afunc)
4348 (apply ',afunc args))))))))
4349 '(article-hide-headers
4350 article-verify-x-pgp-sig
4351 article-verify-cancel-lock
4352 article-hide-boring-headers
4353 article-treat-overstrike
4354 article-treat-ansi-sequences
4355 article-fill-long-lines
4356 article-capitalize-sentences
4357 article-remove-cr
4358 article-remove-leading-whitespace
4359 article-display-x-face
4360 article-display-face
4361 article-de-quoted-unreadable
4362 article-de-base64-unreadable
4363 article-decode-HZ
4364 article-wash-html
4365 article-unsplit-urls
4366 article-hide-list-identifiers
4367 article-strip-banner
4368 article-babel
4369 article-hide-pem
4370 article-hide-signature
4371 article-strip-headers-in-body
4372 article-remove-trailing-blank-lines
4373 article-strip-leading-blank-lines
4374 article-strip-multiple-blank-lines
4375 article-strip-leading-space
4376 article-strip-trailing-space
4377 article-strip-blank-lines
4378 article-strip-all-blank-lines
4379 article-date-local
4380 article-date-english
4381 article-date-iso8601
4382 article-date-original
4383 article-treat-date
4384 article-date-ut
4385 article-decode-mime-words
4386 article-decode-charset
4387 article-decode-encoded-words
4388 article-date-user
4389 article-date-lapsed
4390 article-date-combined-lapsed
4391 article-emphasize
4392 article-treat-dumbquotes
4393 article-treat-non-ascii
4394 article-normalize-headers
4395 ;;(article-show-all . gnus-article-show-all-headers)
4396 )))
4397 \f
4398 ;;;
4399 ;;; Gnus article mode
4400 ;;;
4401
4402 (put 'gnus-article-mode 'mode-class 'special)
4403
4404 (set-keymap-parent gnus-article-mode-map widget-keymap)
4405
4406 (gnus-define-keys gnus-article-mode-map
4407 " " gnus-article-goto-next-page
4408 [?\S-\ ] gnus-article-goto-prev-page
4409 "\177" gnus-article-goto-prev-page
4410 [delete] gnus-article-goto-prev-page
4411 "\C-c^" gnus-article-refer-article
4412 "h" gnus-article-show-summary
4413 "s" gnus-article-show-summary
4414 "\C-c\C-m" gnus-article-mail
4415 "?" gnus-article-describe-briefly
4416 "<" beginning-of-buffer
4417 ">" end-of-buffer
4418 "\C-c\C-i" gnus-info-find-node
4419 "\C-c\C-b" gnus-bug
4420 "R" gnus-article-reply-with-original
4421 "F" gnus-article-followup-with-original
4422 "\C-hk" gnus-article-describe-key
4423 "\C-hc" gnus-article-describe-key-briefly
4424 "\C-hb" gnus-article-describe-bindings
4425
4426 "e" gnus-article-read-summary-keys
4427 "\C-d" gnus-article-read-summary-keys
4428 "\M-*" gnus-article-read-summary-keys
4429 "\M-#" gnus-article-read-summary-keys
4430 "\M-^" gnus-article-read-summary-keys
4431 "\M-g" gnus-article-read-summary-keys)
4432
4433 (substitute-key-definition
4434 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4435
4436 (defvar gnus-article-send-map)
4437
4438 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4439 "W" gnus-article-wide-reply-with-original)
4440 (if (featurep 'xemacs)
4441 (set-keymap-default-binding gnus-article-send-map
4442 'gnus-article-read-summary-send-keys)
4443 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4444
4445 (defun gnus-article-make-menu-bar ()
4446 (unless (boundp 'gnus-article-commands-menu)
4447 (gnus-summary-make-menu-bar))
4448 (unless (boundp 'gnus-article-article-menu)
4449 (easy-menu-define
4450 gnus-article-article-menu gnus-article-mode-map ""
4451 '("Article"
4452 ["Scroll forwards" gnus-article-goto-next-page t]
4453 ["Scroll backwards" gnus-article-goto-prev-page t]
4454 ["Show summary" gnus-article-show-summary t]
4455 ["Fetch Message-ID at point" gnus-article-refer-article t]
4456 ["Mail to address at point" gnus-article-mail t]
4457 ["Send a bug report" gnus-bug t]))
4458
4459 (easy-menu-define
4460 gnus-article-treatment-menu gnus-article-mode-map ""
4461 ;; Fixme: this should use :active (and maybe :visible).
4462 '("Treatment"
4463 ["Hide headers" gnus-article-hide-headers t]
4464 ["Hide signature" gnus-article-hide-signature t]
4465 ["Hide citation" gnus-article-hide-citation t]
4466 ["Treat overstrike" gnus-article-treat-overstrike t]
4467 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4468 ["Remove carriage return" gnus-article-remove-cr t]
4469 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4470 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4471 ["Remove base64" gnus-article-de-base64-unreadable t]
4472 ["Treat html" gnus-article-wash-html t]
4473 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4474 ["Decode HZ" gnus-article-decode-HZ t]))
4475
4476 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4477
4478 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4479
4480 (gnus-run-hooks 'gnus-article-menu-hook)))
4481
4482 (defvar bookmark-make-record-function)
4483 (defvar shr-put-image-function)
4484
4485 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4486 "Major mode for displaying an article.
4487
4488 All normal editing commands are switched off.
4489
4490 The following commands are available in addition to all summary mode
4491 commands:
4492 \\<gnus-article-mode-map>
4493 \\[gnus-article-next-page]\t Scroll the article one page forwards
4494 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4495 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4496 \\[gnus-article-show-summary]\t Display the summary buffer
4497 \\[gnus-article-mail]\t Send a reply to the address near point
4498 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4499 \\[gnus-info-find-node]\t Go to the Gnus info node"
4500 (gnus-simplify-mode-line)
4501 (make-local-variable 'minor-mode-alist)
4502 (when (gnus-visual-p 'article-menu 'menu)
4503 (gnus-article-make-menu-bar)
4504 (when gnus-summary-tool-bar-map
4505 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4506 (gnus-update-format-specifications nil 'article-mode)
4507 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4508 (set (make-local-variable 'gnus-page-broken) nil)
4509 (make-local-variable 'gnus-article-current-summary)
4510 (make-local-variable 'gnus-article-mime-handles)
4511 (make-local-variable 'gnus-article-decoded-p)
4512 (make-local-variable 'gnus-article-mime-handle-alist)
4513 (make-local-variable 'gnus-article-wash-types)
4514 (make-local-variable 'gnus-article-image-alist)
4515 (make-local-variable 'gnus-article-charset)
4516 (make-local-variable 'gnus-article-ignored-charsets)
4517 (set (make-local-variable 'bookmark-make-record-function)
4518 'gnus-summary-bookmark-make-record)
4519 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4520 ;; face.
4521 (set (make-local-variable 'nobreak-char-display) nil)
4522 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4523 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4524 (setq cursor-in-non-selected-windows nil)
4525 (gnus-set-default-directory)
4526 (buffer-disable-undo)
4527 (setq buffer-read-only t
4528 show-trailing-whitespace nil)
4529 (mm-enable-multibyte))
4530
4531 (defun gnus-article-setup-buffer ()
4532 "Initialize the article buffer."
4533 (let* ((name (if gnus-single-article-buffer "*Article*"
4534 (concat "*Article "
4535 (gnus-group-decoded-name gnus-newsgroup-name)
4536 "*")))
4537 (original
4538 (progn (string-match "\\*Article" name)
4539 (concat " *Original Article"
4540 (substring name (match-end 0))))))
4541 (setq gnus-article-buffer name)
4542 (setq gnus-original-article-buffer original)
4543 (setq gnus-article-mime-handle-alist nil)
4544 (with-current-buffer gnus-summary-buffer
4545 ;; This might be a variable local to the summary buffer.
4546 (unless gnus-single-article-buffer
4547 (setq gnus-article-buffer name)
4548 (setq gnus-original-article-buffer original)
4549 (gnus-set-global-variables)))
4550 (gnus-article-setup-highlight-words)
4551 ;; Init original article buffer.
4552 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4553 (mm-enable-multibyte)
4554 (setq major-mode 'gnus-original-article-mode)
4555 (make-local-variable 'gnus-original-article))
4556 (if (and (get-buffer name)
4557 (with-current-buffer name
4558 (if gnus-article-edit-mode
4559 (if (y-or-n-p "Article mode edit in progress; discard? ")
4560 (progn
4561 (set-buffer-modified-p nil)
4562 (gnus-kill-buffer name)
4563 (message "")
4564 nil)
4565 (error "Action aborted"))
4566 t)))
4567 (let ((summary gnus-summary-buffer))
4568 (with-current-buffer name
4569 (set (make-local-variable 'gnus-article-edit-mode) nil)
4570 (gnus-article-stop-animations)
4571 (when gnus-article-mime-handles
4572 (mm-destroy-parts gnus-article-mime-handles)
4573 (setq gnus-article-mime-handles nil))
4574 ;; Set it to nil in article-buffer!
4575 (setq gnus-article-mime-handle-alist nil)
4576 (buffer-disable-undo)
4577 (setq buffer-read-only t)
4578 (unless (derived-mode-p 'gnus-article-mode)
4579 (gnus-article-mode))
4580 (set (make-local-variable 'gnus-summary-buffer) summary)
4581 (setq truncate-lines gnus-article-truncate-lines)
4582 (current-buffer)))
4583 (let ((summary gnus-summary-buffer))
4584 (with-current-buffer (gnus-get-buffer-create name)
4585 (gnus-article-mode)
4586 (setq truncate-lines gnus-article-truncate-lines)
4587 (set (make-local-variable 'gnus-summary-buffer) summary)
4588 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4589 (when article-lapsed-timer
4590 (gnus-stop-date-timer))
4591 (when gnus-article-update-date-headers
4592 (gnus-start-date-timer gnus-article-update-date-headers))
4593 (current-buffer))))))
4594
4595 (defun gnus-article-stop-animations ()
4596 (dolist (timer (and (boundp 'timer-list)
4597 timer-list))
4598 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4599 (cancel-timer timer))))
4600
4601 (defun gnus-stop-downloads ()
4602 (when (boundp 'url-queue)
4603 (set (intern "url-queue" obarray) nil)))
4604
4605 ;; Set article window start at LINE, where LINE is the number of lines
4606 ;; from the head of the article.
4607 (defun gnus-article-set-window-start (&optional line)
4608 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4609 (when article-window
4610 (set-window-start
4611 article-window
4612 (with-current-buffer gnus-article-buffer
4613 (goto-char (point-min))
4614 (if (not line)
4615 (point-min)
4616 (gnus-message 6 "Moved to bookmark")
4617 (search-forward "\n\n" nil t)
4618 (forward-line line)
4619 (point)))))))
4620
4621 (defvar gnus-tmp-internal-hook)
4622
4623 (defun gnus-article-prepare (article &optional all-headers _header)
4624 "Prepare ARTICLE in article mode buffer.
4625 ARTICLE should either be an article number or a Message-ID.
4626 If ARTICLE is an id, HEADER should be the article headers.
4627 If ALL-HEADERS is non-nil, no headers are hidden."
4628 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4629 ;; Make sure we start in a summary buffer.
4630 (unless (derived-mode-p 'gnus-summary-mode)
4631 (set-buffer gnus-summary-buffer))
4632 (setq gnus-summary-buffer (current-buffer))
4633 (let* ((summary-buffer (current-buffer))
4634 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4635 (group gnus-newsgroup-name)
4636 result)
4637 (save-excursion
4638 (gnus-article-setup-buffer)
4639 (set-buffer gnus-article-buffer)
4640 ;; Deactivate active regions.
4641 (when (and (boundp 'transient-mark-mode)
4642 transient-mark-mode)
4643 (setq mark-active nil))
4644 (if (not (setq result (let ((inhibit-read-only t))
4645 (gnus-request-article-this-buffer
4646 article group))))
4647 ;; There is no such article.
4648 (save-excursion
4649 (when (and (numberp article)
4650 (not (memq article gnus-newsgroup-sparse)))
4651 (setq gnus-article-current
4652 (cons gnus-newsgroup-name article))
4653 (set-buffer gnus-summary-buffer)
4654 (setq gnus-current-article article)
4655 (if (and (memq article gnus-newsgroup-undownloaded)
4656 (not (gnus-online (gnus-find-method-for-group
4657 gnus-newsgroup-name))))
4658 (progn
4659 (gnus-summary-set-agent-mark article)
4660 (message "Message marked for downloading"))
4661 (gnus-summary-mark-article article gnus-canceled-mark)
4662 (unless (memq article gnus-newsgroup-sparse)
4663 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4664 (if (or (eq result 'pseudo)
4665 (eq result 'nneething))
4666 (progn
4667 (with-current-buffer summary-buffer
4668 (push article gnus-newsgroup-history)
4669 (setq gnus-last-article gnus-current-article
4670 gnus-current-article 0
4671 gnus-current-headers nil
4672 gnus-article-current nil)
4673 (if (eq result 'nneething)
4674 (gnus-configure-windows 'summary)
4675 (gnus-configure-windows 'article))
4676 (gnus-set-global-variables))
4677 (let ((gnus-article-mime-handle-alist-1
4678 gnus-article-mime-handle-alist))
4679 (gnus-set-mode-line 'article)))
4680 ;; The result from the `request' was an actual article -
4681 ;; or at least some text that is now displayed in the
4682 ;; article buffer.
4683 (when (and (numberp article)
4684 (not (eq article gnus-current-article)))
4685 ;; Seems like a new article has been selected.
4686 ;; `gnus-current-article' must be an article number.
4687 (with-current-buffer summary-buffer
4688 (push article gnus-newsgroup-history)
4689 (setq gnus-last-article gnus-current-article
4690 gnus-current-article article
4691 gnus-current-headers
4692 (gnus-summary-article-header gnus-current-article)
4693 gnus-article-current
4694 (cons gnus-newsgroup-name gnus-current-article))
4695 (unless (vectorp gnus-current-headers)
4696 (setq gnus-current-headers nil))
4697 (gnus-summary-goto-subject gnus-current-article)
4698 (when (gnus-summary-show-thread)
4699 ;; If the summary buffer really was folded, the
4700 ;; previous goto may not actually have gone to
4701 ;; the right article, but the thread root instead.
4702 ;; So we go again.
4703 (gnus-summary-goto-subject gnus-current-article))
4704 (gnus-run-hooks 'gnus-mark-article-hook)
4705 (gnus-set-mode-line 'summary)
4706 (when (gnus-visual-p 'article-highlight 'highlight)
4707 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4708 ;; Set the global newsgroup variables here.
4709 (gnus-set-global-variables)
4710 (setq gnus-have-all-headers
4711 (or all-headers gnus-show-all-headers))))
4712 (save-excursion
4713 (gnus-configure-windows 'article))
4714 (when (or (numberp article)
4715 (stringp article))
4716 (gnus-article-prepare-display)
4717 ;; Do page break.
4718 (goto-char (point-min))
4719 (when gnus-break-pages
4720 (gnus-narrow-to-page)))
4721 (let ((gnus-article-mime-handle-alist-1
4722 gnus-article-mime-handle-alist))
4723 (gnus-set-mode-line 'article))
4724 (article-goto-body)
4725 (unless (bobp)
4726 (forward-line -1))
4727 (set-window-point (get-buffer-window (current-buffer)) (point))
4728 (gnus-configure-windows 'article)
4729 (gnus-run-hooks 'gnus-article-prepare-hook)
4730 t))))))
4731
4732 (defvar gnus-mime-display-attachment-buttons-in-header)
4733
4734 ;;;###autoload
4735 (defun gnus-article-prepare-display ()
4736 "Make the current buffer look like a nice article."
4737 ;; Hooks for getting information from the article.
4738 ;; This hook must be called before being narrowed.
4739 (let ((gnus-article-buffer (current-buffer))
4740 buffer-read-only
4741 (inhibit-read-only t))
4742 (unless (derived-mode-p 'gnus-article-mode)
4743 (gnus-article-mode))
4744 (setq buffer-read-only nil
4745 gnus-article-wash-types nil
4746 gnus-article-image-alist nil)
4747 (gnus-run-hooks 'gnus-tmp-internal-hook)
4748 (when gnus-display-mime-function
4749 (funcall gnus-display-mime-function))
4750 ;; Add attachment buttons to the header.
4751 (when gnus-mime-display-attachment-buttons-in-header
4752 (gnus-mime-buttonize-attachments-in-header))))
4753
4754 ;;;
4755 ;;; Gnus Sticky Article Mode
4756 ;;;
4757
4758 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4759 "Mode for sticky articles."
4760 ;; Release bindings that won't work.
4761 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4762 gnus-sticky-article-mode-map)
4763 (substitute-key-definition 'gnus-article-refer-article 'undefined
4764 gnus-sticky-article-mode-map)
4765 (dolist (k '("e" "h" "s" "F" "R"))
4766 (define-key gnus-sticky-article-mode-map k nil))
4767 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4768 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4769 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4770 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4771
4772 (defun gnus-sticky-article (arg)
4773 "Make the current article sticky.
4774 If a prefix ARG is given, ask for a name for this sticky article buffer."
4775 (interactive "P")
4776 (gnus-summary-show-thread)
4777 (gnus-summary-select-article nil nil 'pseudo)
4778 (let (new-art-buf-name)
4779 (gnus-eval-in-buffer-window gnus-article-buffer
4780 (setq new-art-buf-name
4781 (concat
4782 "*Sticky Article: "
4783 (if arg
4784 (read-from-minibuffer "Sticky article buffer name: ")
4785 (gnus-with-article-headers
4786 (gnus-article-goto-header "subject")
4787 (setq new-art-buf-name
4788 (buffer-substring-no-properties
4789 (line-beginning-position) (line-end-position)))
4790 (goto-char (point-min))
4791 (gnus-article-goto-header "from")
4792 (setq new-art-buf-name
4793 (concat
4794 new-art-buf-name ", "
4795 (buffer-substring-no-properties
4796 (line-beginning-position) (line-end-position))))
4797 (goto-char (point-min))
4798 (gnus-article-goto-header "date")
4799 (setq new-art-buf-name
4800 (concat
4801 new-art-buf-name ", "
4802 (buffer-substring-no-properties
4803 (line-beginning-position) (line-end-position))))))
4804 "*"))
4805 (if (and (gnus-buffer-live-p new-art-buf-name)
4806 (with-current-buffer new-art-buf-name
4807 (derived-mode-p 'gnus-sticky-article-mode)))
4808 (switch-to-buffer new-art-buf-name)
4809 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4810 (gnus-sticky-article-mode))
4811 (setq gnus-article-buffer new-art-buf-name))
4812 (gnus-summary-recenter)
4813 (gnus-summary-position-point))
4814
4815 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4816 "Kill the given sticky article BUFFER.
4817 If none is given, assume the current buffer and kill it if it has
4818 `gnus-sticky-article-mode'."
4819 (interactive)
4820 (unless buffer
4821 (setq buffer (current-buffer)))
4822 (with-current-buffer buffer
4823 (when (derived-mode-p 'gnus-sticky-article-mode)
4824 (gnus-kill-buffer buffer))))
4825
4826 (defun gnus-kill-sticky-article-buffers (arg)
4827 "Kill all sticky article buffers.
4828 If a prefix ARG is given, ask for confirmation."
4829 (interactive "P")
4830 (dolist (buf (gnus-buffers))
4831 (with-current-buffer buf
4832 (when (derived-mode-p 'gnus-sticky-article-mode)
4833 (if (not arg)
4834 (gnus-kill-buffer buf)
4835 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4836 (gnus-kill-buffer buf)))))))
4837
4838 ;;;
4839 ;;; Gnus MIME viewing functions
4840 ;;;
4841
4842 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4843 "Format of the MIME buttons.
4844
4845 Valid specifiers include:
4846 %t The MIME type
4847 %T MIME type, along with additional info
4848 %n The `name' parameter
4849 %d The description, if any
4850 %l The length of the encoded part
4851 %p The part identifier number
4852 %e Dots if the part isn't displayed
4853
4854 General format specifiers can also be used. See Info node
4855 `(gnus)Formatting Variables'.")
4856
4857 (defvar gnus-tmp-type)
4858 (defvar gnus-tmp-type-long)
4859 (defvar gnus-tmp-name)
4860 (defvar gnus-tmp-description)
4861 (defvar gnus-tmp-id)
4862 (defvar gnus-tmp-length)
4863 (defvar gnus-tmp-dots)
4864 (defvar gnus-tmp-info)
4865 (defvar gnus-tmp-pressed-details)
4866
4867 (defvar gnus-mime-button-line-format-alist
4868 '((?t gnus-tmp-type ?s)
4869 (?T gnus-tmp-type-long ?s)
4870 (?n gnus-tmp-name ?s)
4871 (?d gnus-tmp-description ?s)
4872 (?p gnus-tmp-id ?s)
4873 (?l gnus-tmp-length ?d)
4874 (?e gnus-tmp-dots ?s)))
4875
4876 (defvar gnus-mime-button-commands
4877 '((gnus-article-press-button "\r" "Toggle Display")
4878 (gnus-mime-view-part "v" "View Interactively...")
4879 (gnus-mime-view-part-as-type "t" "View As Type...")
4880 (gnus-mime-view-part-as-charset "C" "View As charset...")
4881 (gnus-mime-save-part "o" "Save...")
4882 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4883 (gnus-mime-replace-part "r" "Replace part")
4884 (gnus-mime-delete-part "d" "Delete part")
4885 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4886 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4887 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4888 (gnus-mime-view-part-externally "e" "View Externally")
4889 (gnus-mime-print-part "p" "Print")
4890 (gnus-mime-pipe-part "|" "Pipe To Command...")
4891 (gnus-mime-action-on-part "." "Take action on the part...")))
4892
4893 (defun gnus-article-mime-part-status ()
4894 (if gnus-article-mime-handle-alist-1
4895 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4896 " (1 part)"
4897 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4898 ""))
4899
4900 (defvar gnus-mime-button-map
4901 (let ((map (make-sparse-keymap)))
4902 (define-key map gnus-mouse-2 'gnus-article-push-button)
4903 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4904 (dolist (c gnus-mime-button-commands)
4905 (define-key map (cadr c) (car c)))
4906 map))
4907
4908 (easy-menu-define
4909 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4910 `("MIME Part"
4911 ,@(mapcar (lambda (c)
4912 (vector (caddr c) (car c) :active t))
4913 gnus-mime-button-commands)))
4914
4915 (defvar gnus-url-button-commands
4916 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4917
4918 (defvar gnus-url-button-map
4919 (let ((map (make-sparse-keymap)))
4920 (dolist (c gnus-url-button-commands)
4921 (define-key map (cadr c) (car c)))
4922 map))
4923
4924 (easy-menu-define
4925 gnus-url-button-menu gnus-url-button-map "URL button menu."
4926 `("Url Button"
4927 ,@(mapcar (lambda (c)
4928 (vector (caddr c) (car c) :active t))
4929 gnus-url-button-commands)))
4930
4931 (defmacro gnus-bind-mm-vars (&rest body)
4932 "Bind some mm-* variables and execute BODY."
4933 `(let (mm-html-inhibit-images
4934 mm-html-blocked-images
4935 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4936 (with-current-buffer
4937 (cond ((derived-mode-p 'gnus-article-mode)
4938 (if (gnus-buffer-live-p gnus-article-current-summary)
4939 gnus-article-current-summary
4940 ;; Maybe we're in a mml-preview buffer
4941 ;; and no group is selected.
4942 (current-buffer)))
4943 ((gnus-buffer-live-p gnus-summary-buffer)
4944 gnus-summary-buffer)
4945 (t (current-buffer)))
4946 (setq mm-html-inhibit-images gnus-inhibit-images
4947 mm-html-blocked-images (gnus-blocked-images))
4948 (when (or (not gnus-newsgroup-name)
4949 (and (stringp gnus-safe-html-newsgroups)
4950 (string-match gnus-safe-html-newsgroups
4951 gnus-newsgroup-name))
4952 (and (consp gnus-safe-html-newsgroups)
4953 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4954 (setq mm-w3m-safe-url-regexp nil)))
4955 ,@body))
4956
4957 (defun gnus-mime-button-menu (event prefix)
4958 "Construct a context-sensitive menu of MIME commands."
4959 (interactive "e\nP")
4960 (save-window-excursion
4961 (let ((pos (event-start event)))
4962 (select-window (posn-window pos))
4963 (goto-char (posn-point pos))
4964 (gnus-article-check-buffer)
4965 (popup-menu gnus-mime-button-menu nil prefix))))
4966
4967 (defun gnus-mime-view-all-parts (&optional handles)
4968 "View all the MIME parts."
4969 (interactive)
4970 (with-current-buffer gnus-article-buffer
4971 (let ((handles (or handles gnus-article-mime-handles))
4972 (mail-parse-charset gnus-newsgroup-charset)
4973 (mail-parse-ignored-charsets
4974 (with-current-buffer gnus-summary-buffer
4975 gnus-newsgroup-ignored-charsets)))
4976 (when handles
4977 (mm-remove-parts handles)
4978 (goto-char (point-min))
4979 (or (search-forward "\n\n") (goto-char (point-max)))
4980 (let ((inhibit-read-only t))
4981 (delete-region (point) (point-max))
4982 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4983
4984 (defun gnus-article-jump-to-part (n)
4985 "Jump to MIME part N."
4986 (interactive "P")
4987 (let ((parts (with-current-buffer gnus-article-buffer
4988 (length gnus-article-mime-handle-alist))))
4989 (when (zerop parts)
4990 (error "No such part"))
4991 (pop-to-buffer gnus-article-buffer)
4992 (or n
4993 (setq n (if (= parts 1)
4994 1
4995 (read-number (format "Jump to part (1..%s): " parts)))))
4996 (unless (and (integerp n) (<= n parts) (>= n 1))
4997 (setq n
4998 (progn
4999 (gnus-message 7 "Invalid part `%s', using %s instead."
5000 n parts)
5001 parts)))
5002 (gnus-message 9 "Jumping to part %s." n)
5003 (cond ((>= gnus-auto-select-part 1)
5004 (while (and (<= n parts)
5005 (not (gnus-article-goto-part n)))
5006 (setq n (1+ n))))
5007 ((< gnus-auto-select-part 0)
5008 (while (and (>= n 1)
5009 (not (gnus-article-goto-part n)))
5010 (setq n (1- n))))
5011 (t
5012 (gnus-article-goto-part n)))))
5013
5014 (defvar gnus-mime-buttonized-part-id nil
5015 "ID of a mime part that should be buttonized.
5016 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5017
5018 (eval-when-compile
5019 (defsubst gnus-article-edit-part (handles &optional current-id)
5020 "Edit an article in order to delete a mime part.
5021 This function is exclusively used by `gnus-mime-save-part-and-strip'
5022 and `gnus-mime-delete-part', and not provided at run-time normally."
5023 (gnus-article-edit-article
5024 `(lambda ()
5025 (buffer-disable-undo)
5026 (let ((mail-parse-charset (or gnus-article-charset
5027 ',gnus-newsgroup-charset))
5028 (mail-parse-ignored-charsets
5029 (or gnus-article-ignored-charsets
5030 ',gnus-newsgroup-ignored-charsets))
5031 (mbl mml-buffer-list))
5032 (setq mml-buffer-list nil)
5033 ;; A new text must be inserted before deleting existing ones
5034 ;; at the end so as not to move existing markers of which
5035 ;; the insertion type is t.
5036 (delete-region
5037 (point-min)
5038 (prog1
5039 (goto-char (point-max))
5040 (insert-buffer-substring gnus-original-article-buffer)))
5041 (mime-to-mml ',handles)
5042 (setq gnus-article-mime-handles nil)
5043 (let ((mbl1 mml-buffer-list))
5044 (setq mml-buffer-list mbl)
5045 (set (make-local-variable 'mml-buffer-list) mbl1))
5046 (gnus-make-local-hook 'kill-buffer-hook)
5047 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5048 `(lambda (no-highlight)
5049 (let ((mail-parse-charset (or gnus-article-charset
5050 ',gnus-newsgroup-charset))
5051 (message-options message-options)
5052 (message-options-set-recipient)
5053 (mail-parse-ignored-charsets
5054 (or gnus-article-ignored-charsets
5055 ',gnus-newsgroup-ignored-charsets)))
5056 (mml-to-mime)
5057 (mml-destroy-buffers)
5058 (remove-hook 'kill-buffer-hook
5059 'mml-destroy-buffers t)
5060 (kill-local-variable 'mml-buffer-list))
5061 (gnus-summary-edit-article-done
5062 ,(or (mail-header-references gnus-current-headers) "")
5063 ,(gnus-group-read-only-p)
5064 ,gnus-summary-buffer no-highlight))
5065 t)
5066 ;; Force buttonizing this part.
5067 (let ((gnus-mime-buttonized-part-id current-id))
5068 (gnus-article-edit-done))
5069 (gnus-configure-windows 'article)
5070 (sit-for 0)
5071 (when (and current-id (integerp gnus-auto-select-part))
5072 (gnus-article-jump-to-part
5073 (min (max (+ current-id gnus-auto-select-part) 1)
5074 (with-current-buffer gnus-article-buffer
5075 (length gnus-article-mime-handle-alist)))))))
5076
5077 (defun gnus-mime-replace-part (file)
5078 "Replace MIME part under point with an external body."
5079 ;; Useful if file has already been saved to disk
5080 (interactive
5081 (list
5082 (read-file-name "Replace MIME part with file: "
5083 (or mm-default-directory default-directory)
5084 nil nil)))
5085 (gnus-mime-save-part-and-strip file))
5086
5087 (defun gnus-mime-save-part-and-strip (&optional file)
5088 "Save the MIME part under point then replace it with an external body.
5089 If FILE is given, use it for the external part."
5090 (interactive)
5091 (gnus-article-check-buffer)
5092 (when (gnus-group-read-only-p)
5093 (error "The current group does not support deleting of parts"))
5094 (when (mm-complicated-handles gnus-article-mime-handles)
5095 (error "\
5096 The current article has a complicated MIME structure, giving up..."))
5097 (let* ((data (get-text-property (point) 'gnus-data))
5098 (id (get-text-property (point) 'gnus-part))
5099 (handles gnus-article-mime-handles))
5100 (unless file
5101 (setq file
5102 (and data (mm-save-part data "Delete MIME part and save to: "))))
5103 (when file
5104 (with-current-buffer (mm-handle-buffer data)
5105 (erase-buffer)
5106 (insert "Content-Type: " (mm-handle-media-type data))
5107 (mml-insert-parameter-string (cdr (mm-handle-type data))
5108 '(charset))
5109 ;; Add a filename for the sake of saving the part again.
5110 (mml-insert-parameter
5111 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5112 (insert "\n")
5113 (insert "Content-ID: " (message-make-message-id) "\n")
5114 (insert "Content-Transfer-Encoding: binary\n")
5115 (insert "\n"))
5116 (setcdr data
5117 (cdr (mm-make-handle nil
5118 `("message/external-body"
5119 (access-type . "LOCAL-FILE")
5120 (name . ,file)))))
5121 ;; (set-buffer gnus-summary-buffer)
5122 (gnus-article-edit-part handles id))))
5123
5124 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5125 ;; parts...>') but with stripping would be nice.
5126
5127 (defun gnus-mime-delete-part ()
5128 "Delete the MIME part under point.
5129 Replace it with some information about the removed part."
5130 (interactive)
5131 (gnus-article-check-buffer)
5132 (when (gnus-group-read-only-p)
5133 (error "The current group does not support deleting of parts"))
5134 (when (mm-complicated-handles gnus-article-mime-handles)
5135 (error "\
5136 The current article has a complicated MIME structure, giving up..."))
5137 (when (or gnus-expert-user
5138 (gnus-yes-or-no-p "\
5139 Deleting parts may malfunction or destroy the article; continue? "))
5140 (let* ((data (get-text-property (point) 'gnus-data))
5141 (id (get-text-property (point) 'gnus-part))
5142 (handles gnus-article-mime-handles)
5143 (description
5144 (let ((desc (mm-handle-description data)))
5145 (when desc
5146 (mail-decode-encoded-word-string desc))))
5147 (filename (or (mm-handle-filename data) "(none)"))
5148 (type (mm-handle-media-type data)))
5149 (unless data
5150 (error "No MIME part under point"))
5151 (with-current-buffer (mm-handle-buffer data)
5152 (let ((bsize (buffer-size)))
5153 (erase-buffer)
5154 (insert
5155 (concat
5156 ",----\n"
5157 "| The following attachment has been deleted:\n"
5158 "|\n"
5159 "| Type: " type "\n"
5160 "| Filename: " filename "\n"
5161 "| Size (encoded): " (format "%s byte%s\n"
5162 bsize (if (= bsize 1)
5163 ""
5164 "s"))
5165 (when description
5166 (concat "| Description: " description "\n"))
5167 "`----\n"))
5168 (setcdr data
5169 (cdr (mm-make-handle
5170 nil `("text/plain" (charset . gnus-decoded)) nil nil
5171 (list "attachment")
5172 (format "Deleted attachment (%s bytes)" bsize))))))
5173 ;; (set-buffer gnus-summary-buffer)
5174 (gnus-article-edit-part handles id))))
5175
5176 (defun gnus-mime-save-part ()
5177 "Save the MIME part under point."
5178 (interactive)
5179 (gnus-article-check-buffer)
5180 (let ((data (get-text-property (point) 'gnus-data)))
5181 (when data
5182 (mm-save-part data))))
5183
5184 (defun gnus-mime-pipe-part (&optional cmd)
5185 "Pipe the MIME part under point to a process.
5186 Use CMD as the process."
5187 (interactive)
5188 (gnus-article-check-buffer)
5189 (let ((data (get-text-property (point) 'gnus-data)))
5190 (when data
5191 (mm-pipe-part data cmd))))
5192
5193 (defun gnus-mime-view-part ()
5194 "Interactively choose a viewing method for the MIME part under point."
5195 (interactive)
5196 (gnus-article-check-buffer)
5197 (let ((data (get-text-property (point) 'gnus-data)))
5198 (when data
5199 (setq gnus-article-mime-handles
5200 (mm-merge-handles
5201 gnus-article-mime-handles (setq data (copy-sequence data))))
5202 (mm-interactively-view-part data))))
5203
5204 (defun gnus-mime-view-part-as-type-internal ()
5205 (gnus-article-check-buffer)
5206 (let* ((handle (get-text-property (point) 'gnus-data))
5207 (name (or
5208 ;; Content-Type: foo/bar; name=...
5209 (mail-content-type-get (mm-handle-type handle) 'name)
5210 ;; Content-Disposition: attachment; filename=...
5211 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5212 (def-type (and name (mm-default-file-encoding name))))
5213 (or (and def-type (cons def-type 0))
5214 (and handle
5215 (equal (mm-handle-media-supertype handle) "text")
5216 '("text/plain" . 0))
5217 '("application/octet-stream" . 0))))
5218
5219 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5220 "Choose a MIME media type, and view the part as such.
5221 If non-nil, PRED is a predicate to use during completion to limit the
5222 available media-types."
5223 (interactive)
5224 (unless mime-type
5225 (setq mime-type
5226 (let ((default (gnus-mime-view-part-as-type-internal)))
5227 (gnus-completing-read
5228 "View as MIME type"
5229 (if pred
5230 (gnus-remove-if-not pred (mailcap-mime-types))
5231 (mailcap-mime-types))
5232 nil nil nil
5233 (car default)))))
5234 (gnus-article-check-buffer)
5235 (let ((handle (get-text-property (point) 'gnus-data)))
5236 (when handle
5237 (when (equal (mm-handle-media-type handle) "message/external-body")
5238 (unless (mm-handle-cache handle)
5239 (mm-extern-cache-contents handle))
5240 (setq handle (mm-handle-cache handle)))
5241 (setq handle
5242 (mm-make-handle (mm-handle-buffer handle)
5243 (cons mime-type (cdr (mm-handle-type handle)))
5244 (mm-handle-encoding handle)
5245 (mm-handle-undisplayer handle)
5246 (mm-handle-disposition handle)
5247 (mm-handle-description handle)
5248 nil
5249 (mm-handle-id handle)))
5250 (setq gnus-article-mime-handles
5251 (mm-merge-handles gnus-article-mime-handles handle))
5252 (when (mm-handle-displayed-p handle)
5253 (mm-remove-part handle))
5254 (gnus-mm-display-part handle))))
5255
5256 (defun gnus-mime-copy-part (&optional handle arg)
5257 "Put the MIME part under point into a new buffer.
5258 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5259 are decompressed."
5260 (interactive (list nil current-prefix-arg))
5261 (gnus-article-check-buffer)
5262 (unless handle
5263 (setq handle (get-text-property (point) 'gnus-data)))
5264 (when handle
5265 (let ((filename (mm-handle-filename handle))
5266 contents dont-decode charset coding-system)
5267 (mm-with-unibyte-buffer
5268 (mm-insert-part handle)
5269 (setq contents (or (condition-case nil
5270 (mm-decompress-buffer filename nil 'sig)
5271 (error
5272 (setq dont-decode t)
5273 nil))
5274 (buffer-string))))
5275 (setq filename (cond (filename (file-name-nondirectory filename))
5276 (dont-decode "*raw data*")
5277 (t "*decoded*")))
5278 (cond
5279 (dont-decode)
5280 ((not arg)
5281 (unless (setq charset (mail-content-type-get
5282 (mm-handle-type handle) 'charset))
5283 (unless (setq coding-system (mm-with-unibyte-buffer
5284 (insert contents)
5285 (mm-find-buffer-file-coding-system)))
5286 (setq charset gnus-newsgroup-charset))))
5287 ((numberp arg)
5288 (setq charset (or (cdr (assq arg
5289 gnus-summary-show-article-charset-alist))
5290 (mm-read-coding-system "Charset: ")))))
5291 (switch-to-buffer (generate-new-buffer filename))
5292 (if (or coding-system
5293 (and charset
5294 (setq coding-system (mm-charset-to-coding-system
5295 charset nil t))
5296 (not (eq coding-system 'ascii))))
5297 (progn
5298 (mm-enable-multibyte)
5299 (insert (mm-decode-coding-string contents coding-system))
5300 (setq buffer-file-coding-system
5301 (if (boundp 'last-coding-system-used)
5302 (symbol-value 'last-coding-system-used)
5303 coding-system)))
5304 (mm-disable-multibyte)
5305 (insert contents)
5306 (setq buffer-file-coding-system mm-binary-coding-system))
5307 ;; We do it this way to make `normal-mode' set the appropriate mode.
5308 (unwind-protect
5309 (progn
5310 (setq buffer-file-name (expand-file-name filename))
5311 (normal-mode))
5312 (setq buffer-file-name nil))
5313 (goto-char (point-min)))))
5314
5315 (defun gnus-mime-print-part (&optional handle filename)
5316 "Print the MIME part under point."
5317 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5318 (gnus-article-check-buffer)
5319 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5320 (contents (and handle (mm-get-part handle)))
5321 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5322 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5323 (when contents
5324 (if printer
5325 (unwind-protect
5326 (progn
5327 (mm-save-part-to-file handle file)
5328 (call-process shell-file-name nil
5329 (generate-new-buffer " *mm*")
5330 nil
5331 shell-command-switch
5332 (mm-mailcap-command
5333 printer file (mm-handle-type handle))))
5334 (delete-file file))
5335 (with-temp-buffer
5336 (insert contents)
5337 (gnus-print-buffer))
5338 (ps-despool filename)))))
5339
5340 (defun gnus-mime-inline-part (&optional handle arg)
5341 "Insert the MIME part under point into the current buffer.
5342 Compressed files like .gz and .bz2 are decompressed."
5343 (interactive (list nil current-prefix-arg))
5344 (gnus-article-check-buffer)
5345 (let* ((inhibit-read-only t)
5346 (b (point))
5347 (btn ;; position where the MIME button exists
5348 (if handle
5349 (if (eq handle (get-text-property b 'gnus-data))
5350 b
5351 (article-goto-body)
5352 (or (text-property-any (point) (point-max) 'gnus-data handle)
5353 (text-property-any (point-min) (point) 'gnus-data handle)))
5354 (setq handle (get-text-property b 'gnus-data))
5355 b))
5356 start)
5357 (when handle
5358 (when (= b (prog1
5359 btn
5360 (setq start (next-single-property-change btn 'gnus-data
5361 nil (point-max))
5362 btn (previous-single-property-change start
5363 'gnus-data))))
5364 (setq b btn))
5365 (if (and (not arg) (mm-handle-undisplayer handle))
5366 (progn
5367 (setq b (copy-marker b)
5368 btn (copy-marker btn))
5369 (mm-remove-part handle))
5370 (cond
5371 ((not arg) nil)
5372 ((numberp arg)
5373 (if (mm-handle-undisplayer handle)
5374 (mm-remove-part handle)))
5375 ((mm-handle-undisplayer handle)
5376 (mm-remove-part handle)))
5377 (goto-char start)
5378 (unless (bolp)
5379 ;; This is a header button.
5380 (forward-line 1))
5381 (mm-display-inline handle))
5382 ;; Toggle the button appearance between `[button]...' and `[button]'.
5383 (when (markerp btn)
5384 (setq btn (prog1 (marker-position btn)
5385 (set-marker btn nil))))
5386 (goto-char btn)
5387 (let ((displayed-p (mm-handle-displayed-p handle)))
5388 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5389 (list displayed-p))
5390 (if (featurep 'emacs)
5391 (delete-region
5392 (point)
5393 (next-single-property-change (point) 'gnus-data nil (point-max)))
5394 (let* ((end (next-single-property-change (point) 'gnus-data))
5395 (annots (annotations-at (or end (point-max)))))
5396 (delete-region (point)
5397 (if end
5398 (if annots (1+ end) end)
5399 (point-max)))
5400 (dolist (annot annots)
5401 (set-extent-endpoints annot (point) (point)))))
5402 (setq start (point))
5403 (if (search-backward "\n\n" nil t)
5404 (progn
5405 (goto-char start)
5406 (unless (or displayed-p (eolp))
5407 ;; Add extra newline.
5408 (insert (propertize (buffer-substring (1- start) start)
5409 'gnus-undeletable t))))
5410 ;; We're in the article header.
5411 (delete-char -1)
5412 (dolist (ovl (overlays-in btn (point)))
5413 (overlay-put ovl 'gnus-button-attachment-extra t)
5414 (overlay-put ovl 'face nil))
5415 (save-restriction
5416 (message-narrow-to-field)
5417 (let ((gnus-treatment-function-alist
5418 '((gnus-treat-highlight-headers
5419 gnus-article-highlight-headers))))
5420 (gnus-treat-article 'head)))))
5421 (when (markerp b)
5422 (setq b (prog1 (marker-position b)
5423 (set-marker b nil))))
5424 (goto-char b))))
5425
5426 (defun gnus-mime-set-charset-parameters (handle charset)
5427 "Set CHARSET to parameters in HANDLE.
5428 CHARSET may either be a string or a symbol."
5429 (unless (stringp charset)
5430 (setq charset (symbol-name charset)))
5431 (if (stringp (car handle))
5432 (dolist (h (cdr handle))
5433 (gnus-mime-set-charset-parameters h charset))
5434 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5435 "message/external-body")
5436 (progn
5437 (unless (mm-handle-cache handle)
5438 (mm-extern-cache-contents handle))
5439 (mm-handle-cache handle))
5440 handle)))
5441 (param (assq 'charset (cdr type))))
5442 (if param
5443 (setcdr param charset)
5444 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5445
5446 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5447 "Insert the MIME part under point into the current buffer using the
5448 specified charset."
5449 (interactive (list nil current-prefix-arg))
5450 (gnus-article-check-buffer)
5451 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5452 (fun (get-text-property (point) 'gnus-callback))
5453 (gnus-newsgroup-ignored-charsets 'gnus-all)
5454 charset form preferred parts)
5455 (when handle
5456 (when (prog1
5457 (and fun
5458 (setq charset
5459 (or (cdr (assq
5460 arg
5461 gnus-summary-show-article-charset-alist))
5462 (mm-read-coding-system "Charset: "))))
5463 (if (mm-handle-undisplayer handle)
5464 (mm-remove-part handle)))
5465 (gnus-mime-set-charset-parameters handle charset)
5466 (when (and (consp (setq form (cdr-safe fun)))
5467 (setq form (ignore-errors
5468 (assq 'gnus-mime-display-alternative form)))
5469 (setq preferred (caddr form))
5470 (progn
5471 (when (eq (car preferred) 'quote)
5472 (setq preferred (cadr preferred)))
5473 (not (equal preferred
5474 (get-text-property (point) 'gnus-data))))
5475 (setq parts (get-text-property (point) 'gnus-part))
5476 (setq parts (cdr (assq parts
5477 gnus-article-mime-handle-alist)))
5478 (equal (mm-handle-media-type parts) "multipart/alternative")
5479 (setq parts (reverse (cdr parts))))
5480 (setcar (cddr form)
5481 (list 'quote (or (cadr (member preferred parts))
5482 (car parts)))))
5483 (funcall fun handle)))))
5484
5485 (defun gnus-mime-view-part-externally (&optional handle)
5486 "View the MIME part under point with an external viewer."
5487 (interactive)
5488 (gnus-article-check-buffer)
5489 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5490 (mm-inlined-types nil)
5491 (mail-parse-charset gnus-newsgroup-charset)
5492 (mail-parse-ignored-charsets
5493 (with-current-buffer gnus-summary-buffer
5494 gnus-newsgroup-ignored-charsets))
5495 (type (mm-handle-media-type handle))
5496 (method (mailcap-mime-info type))
5497 (mm-enable-external t))
5498 (if (not (stringp method))
5499 (gnus-mime-view-part-as-type
5500 nil (lambda (type) (stringp (mailcap-mime-info type))))
5501 (when handle
5502 (mm-display-part handle nil t)))))
5503
5504 (defun gnus-mime-view-part-internally (&optional handle)
5505 "View the MIME part under point with an internal viewer.
5506 If no internal viewer is available, use an external viewer."
5507 (interactive)
5508 (gnus-article-check-buffer)
5509 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5510 (mm-inlined-types '(".*"))
5511 (mm-inline-large-images t)
5512 (mail-parse-charset gnus-newsgroup-charset)
5513 (mail-parse-ignored-charsets
5514 (with-current-buffer gnus-summary-buffer
5515 gnus-newsgroup-ignored-charsets))
5516 (inhibit-read-only t))
5517 (if (not (mm-inlinable-p handle))
5518 (gnus-mime-view-part-as-type
5519 nil (lambda (type) (mm-inlinable-p handle type)))
5520 (when handle
5521 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5522
5523 (defun gnus-mime-action-on-part (&optional action)
5524 "Do something with the MIME attachment at (point)."
5525 (interactive
5526 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5527 (gnus-article-check-buffer)
5528 (let ((action-pair (assoc action gnus-mime-action-alist)))
5529 (if action-pair
5530 (funcall (cdr action-pair)))))
5531
5532 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5533 "Call FUNCTION on MIME part N.
5534 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5535 If INTERACTIVE, call FUNCTION interactively."
5536 (let (window frame)
5537 ;; Check whether the article is displayed.
5538 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5539 (setq window (get-buffer-window gnus-article-buffer t))
5540 (frame-visible-p (setq frame (window-frame window))))
5541 (error "No article is displayed"))
5542 (with-current-buffer gnus-article-buffer
5543 ;; Check whether the article displays the right contents.
5544 (unless (with-current-buffer gnus-summary-buffer
5545 (eq gnus-current-article (gnus-summary-article-number)))
5546 (error "You should select the right article first"))
5547 (if n
5548 (setq n (prefix-numeric-value n))
5549 (let ((pt (point)))
5550 (setq n (or (get-text-property pt 'gnus-part)
5551 (and (not (bobp))
5552 (get-text-property (1- pt) 'gnus-part))
5553 (get-text-property (prog2
5554 (forward-line 1)
5555 (point)
5556 (goto-char pt))
5557 'gnus-part)
5558 (get-text-property
5559 (or (and (setq pt (previous-single-property-change
5560 pt 'gnus-part))
5561 (1- pt))
5562 (next-single-property-change (point) 'gnus-part)
5563 (point))
5564 'gnus-part)
5565 1))))
5566 ;; Check whether the specified part exists.
5567 (when (> n (length gnus-article-mime-handle-alist))
5568 (error "No such part")))
5569 (unless
5570 (progn
5571 ;; To select the window is needed so that the cursor
5572 ;; might be visible on the MIME button.
5573 (select-window (prog1
5574 window
5575 (setq window (selected-window))
5576 ;; Article may be displayed in the other frame.
5577 (gnus-select-frame-set-input-focus
5578 (prog1
5579 frame
5580 (setq frame (selected-frame))))))
5581 (when (gnus-article-goto-part n)
5582 ;; We point the cursor and the arrow at the MIME button
5583 ;; when the `function' prompt the user for something.
5584 (unless (and (pos-visible-in-window-p)
5585 (> (count-lines (point) (window-end))
5586 (/ (1- (window-height)) 3)))
5587 (recenter (/ (1- (window-height)) 3)))
5588 (let ((cursor-in-non-selected-windows t)
5589 (overlay-arrow-string "=>")
5590 (overlay-arrow-position (point-marker)))
5591 (unwind-protect
5592 (cond
5593 ((and no-handle interactive)
5594 (call-interactively function))
5595 (no-handle
5596 (funcall function))
5597 (interactive
5598 (call-interactively
5599 function (get-text-property (point) 'gnus-data)))
5600 (t
5601 (funcall function
5602 (get-text-property (point) 'gnus-data))))
5603 (set-marker overlay-arrow-position nil)
5604 (unless gnus-auto-select-part
5605 (gnus-select-frame-set-input-focus frame)
5606 (select-window window))))
5607 t))
5608 (if gnus-inhibit-mime-unbuttonizing
5609 ;; This is the default though the program shouldn't reach here.
5610 (error "No such part")
5611 ;; The part which doesn't have the MIME button is selected.
5612 ;; So, we display all the buttons and redo it.
5613 (let ((gnus-inhibit-mime-unbuttonizing t))
5614 (gnus-summary-show-article)
5615 (gnus-article-part-wrapper n function no-handle))))))
5616
5617 (defun gnus-article-pipe-part (n)
5618 "Pipe MIME part N, which is the numerical prefix."
5619 (interactive "P")
5620 (gnus-article-part-wrapper n 'mm-pipe-part))
5621
5622 (defun gnus-article-save-part (n)
5623 "Save MIME part N, which is the numerical prefix."
5624 (interactive "P")
5625 (gnus-article-part-wrapper n 'mm-save-part))
5626
5627 (defun gnus-article-interactively-view-part (n)
5628 "View MIME part N interactively, which is the numerical prefix."
5629 (interactive "P")
5630 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5631
5632 (defun gnus-article-copy-part (n)
5633 "Copy MIME part N, which is the numerical prefix."
5634 (interactive "P")
5635 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5636
5637 (defun gnus-article-view-part-as-charset (n)
5638 "View MIME part N using a specified charset.
5639 N is the numerical prefix."
5640 (interactive "P")
5641 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5642
5643 (defun gnus-article-view-part-externally (n)
5644 "View MIME part N externally, which is the numerical prefix."
5645 (interactive "P")
5646 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5647
5648 (defun gnus-article-inline-part (n)
5649 "Inline MIME part N, which is the numerical prefix."
5650 (interactive "P")
5651 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5652
5653 (defun gnus-article-save-part-and-strip (n)
5654 "Save MIME part N and replace it with an external body.
5655 N is the numerical prefix."
5656 (interactive "P")
5657 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5658
5659 (defun gnus-article-replace-part (n)
5660 "Replace MIME part N with an external body.
5661 N is the numerical prefix."
5662 (interactive "P")
5663 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5664
5665 (defun gnus-article-delete-part (n)
5666 "Delete MIME part N and add some information about the removed part.
5667 N is the numerical prefix."
5668 (interactive "P")
5669 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5670
5671 (defun gnus-article-view-part-as-type (n)
5672 "Choose a MIME media type, and view part N as such.
5673 N is the numerical prefix."
5674 (interactive "P")
5675 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5676
5677 (defun gnus-article-mime-match-handle-first (condition)
5678 (if condition
5679 (let (n)
5680 (dolist (ihandle gnus-article-mime-handle-alist)
5681 (if (and (cond
5682 ((functionp condition)
5683 (funcall condition (cdr ihandle)))
5684 ((eq condition 'undisplayed)
5685 (not (or (mm-handle-undisplayer (cdr ihandle))
5686 (equal (mm-handle-media-type (cdr ihandle))
5687 "multipart/alternative"))))
5688 ((eq condition 'undisplayed-alternative)
5689 (not (mm-handle-undisplayer (cdr ihandle))))
5690 (t t))
5691 (gnus-article-goto-part (car ihandle))
5692 (or (not n) (< (car ihandle) n)))
5693 (setq n (car ihandle))))
5694 (or n 1))
5695 1))
5696
5697 (defun gnus-article-view-part (&optional n)
5698 "View MIME part N, which is the numerical prefix.
5699 If the part is already shown, hide the part. If N is nil, view
5700 all parts."
5701 (interactive "P")
5702 (with-current-buffer gnus-article-buffer
5703 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5704 gnus-article-mime-match-handle-function)))
5705 (when (> n (length gnus-article-mime-handle-alist))
5706 (error "No such part"))
5707 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5708 (when (gnus-article-goto-part n)
5709 (if (equal (car handle) "multipart/alternative")
5710 (progn
5711 (beginning-of-line) ;; Make it toggle subparts
5712 (gnus-article-press-button))
5713 (when (eq (gnus-mm-display-part handle) 'internal)
5714 (gnus-set-window-start)))))))
5715
5716 (defsubst gnus-article-mime-total-parts ()
5717 (if (bufferp (car gnus-article-mime-handles))
5718 1 ;; single part
5719 (1- (length gnus-article-mime-handles))))
5720
5721 (defun gnus-mm-display-part (handle)
5722 "Display HANDLE and fix MIME button."
5723 (let ((id (get-text-property (point) 'gnus-part))
5724 (point (point))
5725 (inhibit-read-only t)
5726 (window (selected-window))
5727 (mail-parse-charset gnus-newsgroup-charset)
5728 (mail-parse-ignored-charsets
5729 (if (gnus-buffer-live-p gnus-summary-buffer)
5730 (with-current-buffer gnus-summary-buffer
5731 gnus-newsgroup-ignored-charsets)
5732 nil))
5733 start retval)
5734 (unwind-protect
5735 (progn
5736 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5737 (when win
5738 (select-window win)
5739 (goto-char point)))
5740 (setq start (next-single-property-change point 'gnus-data
5741 nil (point-max))
5742 point (previous-single-property-change start 'gnus-data))
5743 (if (mm-handle-displayed-p handle)
5744 ;; This will remove the part.
5745 (setq point (copy-marker point)
5746 retval (mm-display-part handle))
5747 (let ((part (or (and (mm-inlinable-p handle)
5748 (mm-inlined-p handle)
5749 t)
5750 (with-temp-buffer
5751 (gnus-bind-mm-vars
5752 (setq retval (mm-display-part handle)))
5753 (unless (zerop (buffer-size))
5754 (buffer-string))))))
5755 (goto-char start)
5756 (unless (bolp)
5757 ;; This is a header button.
5758 (forward-line 1))
5759 (cond ((stringp part)
5760 (save-restriction
5761 (narrow-to-region (point)
5762 (progn
5763 (insert part)
5764 (unless (bolp) (insert "\n"))
5765 (point)))
5766 (gnus-treat-article nil id
5767 (gnus-article-mime-total-parts)
5768 (mm-handle-media-type handle))
5769 (mm-handle-set-undisplayer
5770 handle
5771 `(lambda ()
5772 (let ((inhibit-read-only t))
5773 (delete-region ,(copy-marker (point-min) t)
5774 ,(point-max-marker)))))))
5775 (part
5776 (mm-display-inline handle))))))
5777 (when (markerp point)
5778 (setq point (prog1 (marker-position point)
5779 (set-marker point nil))))
5780 (goto-char point)
5781 ;; Toggle the button appearance between `[button]...' and `[button]'.
5782 (let ((displayed-p (mm-handle-displayed-p handle)))
5783 (gnus-insert-mime-button handle id (list displayed-p))
5784 (if (featurep 'emacs)
5785 (delete-region
5786 (point)
5787 (next-single-property-change (point) 'gnus-data nil (point-max)))
5788 (let* ((end (next-single-property-change (point) 'gnus-data))
5789 (annots (annotations-at (or end (point-max)))))
5790 (delete-region (point)
5791 (if end
5792 (if annots (1+ end) end)
5793 (point-max)))
5794 (dolist (annot annots)
5795 (set-extent-endpoints annot (point) (point)))))
5796 (setq start (point))
5797 (if (search-backward "\n\n" nil t)
5798 (progn
5799 (goto-char start)
5800 (unless (or displayed-p (eolp))
5801 ;; Add extra newline.
5802 (insert (propertize (buffer-substring (1- start) start)
5803 'gnus-undeletable t))))
5804 ;; We're in the article header.
5805 (delete-char -1)
5806 (dolist (ovl (overlays-in point (point)))
5807 (overlay-put ovl 'gnus-button-attachment-extra t)
5808 (overlay-put ovl 'face nil))
5809 (save-restriction
5810 (message-narrow-to-field)
5811 (let ((gnus-treatment-function-alist
5812 '((gnus-treat-highlight-headers
5813 gnus-article-highlight-headers))))
5814 (gnus-treat-article 'head)))))
5815 (goto-char point)
5816 (if (window-live-p window)
5817 (select-window window)))
5818 retval))
5819
5820 (defun gnus-article-goto-part (n)
5821 "Go to MIME part N."
5822 (when gnus-break-pages
5823 (widen))
5824 (article-goto-body)
5825 (prog1
5826 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5827 ;; There may be header buttons.
5828 (text-property-any (point-min) (point) 'gnus-part n)))
5829 part handle end next handles)
5830 (when start
5831 (goto-char start)
5832 (if (setq handle (get-text-property start 'gnus-data))
5833 start
5834 ;; Go to the displayed subpart, assuming this is
5835 ;; multipart/alternative.
5836 (setq part start
5837 end (point-at-eol))
5838 (while (and (not handle)
5839 part
5840 (< part end)
5841 (setq next (text-property-not-all part end
5842 'gnus-data nil)))
5843 (setq part next
5844 handle (get-text-property part 'gnus-data))
5845 (push (cons handle part) handles)
5846 (unless (mm-handle-displayed-p handle)
5847 (setq handle nil
5848 part (text-property-any part end 'gnus-data nil))))
5849 (unless handle
5850 ;; No subpart is displayed, so we find preferred one.
5851 (setq part
5852 (cdr (assq (mm-preferred-alternative
5853 (nreverse (mapcar 'car handles)))
5854 handles))))
5855 (if part
5856 (goto-char (1+ part))
5857 start))))
5858 (when gnus-break-pages
5859 (gnus-narrow-to-page))))
5860
5861 (defun gnus-insert-mime-button (handle id &optional displayed)
5862 (let ((gnus-tmp-name
5863 (or (mm-handle-filename handle)
5864 (mail-content-type-get (mm-handle-type handle) 'url)
5865 ""))
5866 (gnus-tmp-id id)
5867 (gnus-tmp-type (mm-handle-media-type handle))
5868 (gnus-tmp-description (or (mm-handle-description handle) ""))
5869 (gnus-tmp-dots
5870 (if (if displayed (car displayed)
5871 (mm-handle-displayed-p handle))
5872 "" "..."))
5873 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5874 (buffer-size)))
5875 gnus-tmp-type-long b e)
5876 (when (string-match ".*/" gnus-tmp-name)
5877 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5878 (setq gnus-tmp-type-long (concat gnus-tmp-type
5879 (and (not (equal gnus-tmp-name ""))
5880 (concat "; " gnus-tmp-name))))
5881 (unless (equal gnus-tmp-description "")
5882 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5883 (setq b (point))
5884 (gnus-eval-format
5885 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5886 `(keymap ,gnus-mime-button-map
5887 gnus-callback gnus-mm-display-part
5888 gnus-part ,gnus-tmp-id
5889 article-type annotation
5890 gnus-data ,handle
5891 rear-nonsticky t))
5892 (setq e (if (bolp)
5893 ;; Exclude a newline.
5894 (1- (point))
5895 (point)))
5896 (when gnus-article-button-face
5897 (overlay-put (make-overlay b e nil t)
5898 'face gnus-article-button-face))
5899 (widget-convert-button
5900 'link b e
5901 :mime-handle handle
5902 :action 'gnus-widget-press-button
5903 :button-keymap gnus-mime-button-map
5904 :help-echo
5905 (lambda (widget)
5906 ;; Needed to properly clear the message due to a bug in
5907 ;; wid-edit (XEmacs only).
5908 (if (boundp 'help-echo-owns-message)
5909 (setq help-echo-owns-message t))
5910 (format
5911 "%S: %s the MIME part; %S: more options"
5912 (aref gnus-mouse-2 0)
5913 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5914 "hide" "show")
5915 (aref gnus-down-mouse-3 0))))))
5916
5917 (defun gnus-widget-press-button (elems _el)
5918 (goto-char (widget-get elems :from))
5919 (gnus-article-press-button))
5920
5921 (defvar gnus-displaying-mime nil)
5922
5923 (defun gnus-display-mime (&optional ihandles)
5924 "Display the MIME parts."
5925 (save-excursion
5926 (save-selected-window
5927 (let ((window (get-buffer-window gnus-article-buffer))
5928 (point (point)))
5929 (when window
5930 (select-window window)
5931 ;; We have to do this since selecting the window
5932 ;; may change the point. So we set the window point.
5933 (set-window-point window point)))
5934 (let ((handles ihandles)
5935 (inhibit-read-only t))
5936 (cond (handles)
5937 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5938 (when gnus-article-emulate-mime
5939 (mm-uu-dissect-text-parts handles)))
5940 (gnus-article-emulate-mime
5941 (setq handles (mm-uu-dissect))))
5942 (when (and (not ihandles)
5943 (not gnus-displaying-mime))
5944 ;; Top-level call; we clean up.
5945 (when gnus-article-mime-handles
5946 (mm-destroy-parts gnus-article-mime-handles)
5947 (setq gnus-article-mime-handle-alist nil));; A trick.
5948 (setq gnus-article-mime-handles handles)
5949 ;; We allow users to glean info from the handles.
5950 (when gnus-article-mime-part-function
5951 (gnus-mime-part-function handles)))
5952 (if (and handles
5953 (or (not (stringp (car handles)))
5954 (cdr handles)))
5955 (progn
5956 (when (and (not ihandles)
5957 (not gnus-displaying-mime))
5958 ;; Clean up for mime parts.
5959 (article-goto-body)
5960 (delete-region (point) (point-max)))
5961 (let ((gnus-displaying-mime t))
5962 (gnus-mime-display-part handles)))
5963 (save-restriction
5964 (article-goto-body)
5965 (narrow-to-region (point) (point-max))
5966 (gnus-treat-article nil 1 1 "text/plain")
5967 (widen)))
5968 (unless ihandles
5969 ;; Highlight the headers.
5970 (save-excursion
5971 (save-restriction
5972 (article-goto-body)
5973 (narrow-to-region (point-min) (point))
5974 (gnus-article-save-original-date
5975 (gnus-treat-article 'head)))))))
5976 ;; Cope with broken MIME messages.
5977 (goto-char (point-max))
5978 (unless (bolp)
5979 (insert "\n"))))
5980
5981 (defcustom gnus-mime-display-multipart-as-mixed nil
5982 "Display \"multipart\" parts as \"multipart/mixed\".
5983
5984 If t, it overrides nil values of
5985 `gnus-mime-display-multipart-alternative-as-mixed' and
5986 `gnus-mime-display-multipart-related-as-mixed'."
5987 :group 'gnus-article-mime
5988 :type 'boolean)
5989
5990 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5991 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5992 :version "22.1"
5993 :group 'gnus-article-mime
5994 :type 'boolean)
5995
5996 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5997 "Display \"multipart/related\" parts as \"multipart/mixed\".
5998
5999 If displaying \"text/html\" is discouraged \(see
6000 `mm-discouraged-alternatives') images or other material inside a
6001 \"multipart/related\" part might be overlooked when this variable is nil."
6002 :version "22.1"
6003 :group 'gnus-article-mime
6004 :type 'boolean)
6005
6006 (defcustom gnus-mime-display-attachment-buttons-in-header t
6007 "Add attachment buttons in the end of the header of an article.
6008 Since MIME attachments tend to be put at the end of an article, we may
6009 overlook them if there is a huge body. This option offers you a copy
6010 of all non-inlinable MIME parts as buttons shown in front of an article.
6011 If nil, don't show those extra buttons."
6012 :version "25.1"
6013 :group 'gnus-article-mime
6014 :type 'boolean)
6015
6016 (defun gnus-mime-display-part (handle)
6017 (cond
6018 ;; Maybe a broken MIME message.
6019 ((null handle))
6020 ;; Single part.
6021 ((not (stringp (car handle)))
6022 (gnus-mime-display-single handle))
6023 ;; User-defined multipart
6024 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6025 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6026 handle))
6027 ;; multipart/alternative
6028 ((and (equal (car handle) "multipart/alternative")
6029 (not (or gnus-mime-display-multipart-as-mixed
6030 gnus-mime-display-multipart-alternative-as-mixed)))
6031 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6032 (push (cons id handle) gnus-article-mime-handle-alist)
6033 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6034 ;; multipart/related
6035 ((and (equal (car handle) "multipart/related")
6036 (not (or gnus-mime-display-multipart-as-mixed
6037 gnus-mime-display-multipart-related-as-mixed)))
6038 (gnus-mime-display-part (cadr handle)))
6039 ((equal (car handle) "multipart/signed")
6040 (gnus-add-wash-type 'signed)
6041 (gnus-mime-display-security handle))
6042 ((equal (car handle) "multipart/encrypted")
6043 (gnus-add-wash-type 'encrypted)
6044 (gnus-mime-display-security handle))
6045 ;; Other multiparts are handled like multipart/mixed.
6046 (t
6047 (gnus-mime-display-mixed (cdr handle)))))
6048
6049 (defun gnus-mime-part-function (handles)
6050 (if (stringp (car handles))
6051 (mapcar 'gnus-mime-part-function (cdr handles))
6052 (funcall gnus-article-mime-part-function handles)))
6053
6054 (defun gnus-mime-display-mixed (handles)
6055 (mapcar 'gnus-mime-display-part handles))
6056
6057 (defun gnus-mime-display-single (handle)
6058 (let ((type (mm-handle-media-type handle))
6059 (ignored gnus-ignored-mime-types)
6060 (not-attachment t)
6061 display text)
6062 (catch 'ignored
6063 (progn
6064 (while ignored
6065 (when (string-match (pop ignored) type)
6066 (throw 'ignored nil)))
6067 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6068 (with-current-buffer gnus-summary-buffer
6069 gnus-inhibit-images)
6070 gnus-inhibit-images)
6071 (string-match "\\`image/" type)))
6072 (setq not-attachment
6073 (and (not (mm-inline-override-p handle))
6074 (or (not (mm-handle-disposition handle))
6075 (equal (car (mm-handle-disposition handle))
6076 "inline")
6077 (mm-attachment-override-p handle))))
6078 (mm-automatic-display-p handle)
6079 (or (and
6080 (mm-inlinable-p handle)
6081 (mm-inlined-p handle))
6082 (mm-automatic-external-display-p type)))
6083 (setq display t)
6084 (when (equal (mm-handle-media-supertype handle) "text")
6085 (setq text t)))
6086 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6087 beg)
6088 (unless id
6089 (setq id (1+ (length gnus-article-mime-handle-alist)))
6090 (push (cons id handle) gnus-article-mime-handle-alist))
6091 (when (and display
6092 (equal (mm-handle-media-supertype handle) "message"))
6093 (insert-char
6094 ?\n
6095 (cond ((not (bolp)) 2)
6096 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6097 (t 1))))
6098 (when (or (not display)
6099 (not (gnus-unbuttonized-mime-type-p type))
6100 (eq id gnus-mime-buttonized-part-id))
6101 (gnus-insert-mime-button
6102 handle id (list (or display (and not-attachment text)))))
6103 (setq beg (point))
6104 (cond
6105 (display
6106 (let ((mail-parse-charset gnus-newsgroup-charset)
6107 (mail-parse-ignored-charsets
6108 (save-excursion (condition-case ()
6109 (set-buffer gnus-summary-buffer)
6110 (error))
6111 gnus-newsgroup-ignored-charsets)))
6112 (gnus-bind-mm-vars (mm-display-part handle t))))
6113 ((and text not-attachment)
6114 (mm-display-inline handle)))
6115 (goto-char (point-max))
6116 (if (string-match "\\`image/" type)
6117 (gnus-article-insert-newline)
6118 (if (prog1
6119 (= (skip-chars-backward "\n") -1)
6120 (unless (eobp) (forward-char 1)))
6121 (gnus-article-insert-newline)
6122 (put-text-property (point) (point-max) 'gnus-undeletable t))
6123 (goto-char (point-max)))
6124 ;; Do highlighting.
6125 (save-excursion
6126 (save-restriction
6127 (narrow-to-region beg (point))
6128 (if (eq handle gnus-article-mime-handles)
6129 ;; The format=flowed case.
6130 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6131 ;; Don't count signature parts that are never displayed.
6132 ;; The part number should be re-calculated supposing this
6133 ;; might be a message/rfc822 part.
6134 (let (handles)
6135 (dolist (part gnus-article-mime-handles)
6136 (unless (or (stringp part)
6137 (equal (car (mm-handle-type part))
6138 "application/pgp-signature"))
6139 (push part handles)))
6140 (gnus-treat-article
6141 nil (length (memq handle handles)) (length handles)
6142 (mm-handle-media-type handle)))))))))))
6143
6144 (defun gnus-unbuttonized-mime-type-p (type)
6145 "Say whether TYPE is to be unbuttonized."
6146 (unless gnus-inhibit-mime-unbuttonizing
6147 (when (catch 'found
6148 (let ((types gnus-unbuttonized-mime-types))
6149 (while types
6150 (when (string-match (pop types) type)
6151 (throw 'found t)))))
6152 (not (catch 'found
6153 (let ((types gnus-buttonized-mime-types))
6154 (while types
6155 (when (string-match (pop types) type)
6156 (throw 'found t)))))))))
6157
6158 (defun gnus-article-insert-newline ()
6159 "Insert a newline, but mark it as undeletable."
6160 (gnus-put-text-property
6161 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6162
6163 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6164 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6165 (ihandles handles)
6166 (point (point))
6167 handle (inhibit-read-only t) from begend not-pref)
6168 (save-window-excursion
6169 (save-restriction
6170 (when ibegend
6171 (narrow-to-region (car ibegend)
6172 (or (cdr ibegend)
6173 (progn
6174 (goto-char (car ibegend))
6175 (forward-line 2)
6176 (point))))
6177 (delete-region (point-min) (point-max))
6178 (mm-remove-parts handles))
6179 (setq begend (list (point-marker)))
6180 ;; Do the toggle.
6181 (unless (setq not-pref (cadr (member preferred ihandles)))
6182 (setq not-pref (car ihandles)))
6183 (when (or ibegend
6184 (not preferred)
6185 (not (gnus-unbuttonized-mime-type-p
6186 "multipart/alternative")))
6187 (gnus-add-text-properties
6188 (setq from (point))
6189 (progn
6190 (insert (format "%d. " id))
6191 (point))
6192 `(gnus-callback
6193 (lambda (handles)
6194 (unless ,(not ibegend)
6195 (setq gnus-article-mime-handle-alist
6196 ',gnus-article-mime-handle-alist))
6197 (gnus-mime-display-alternative
6198 ',ihandles ',not-pref ',begend ,id))
6199 keymap ,gnus-mime-button-map
6200 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6201 face ,gnus-article-button-face
6202 gnus-part ,id
6203 article-type multipart
6204 rear-nonsticky t))
6205 (widget-convert-button 'link from (point)
6206 :action 'gnus-widget-press-button
6207 :button-keymap gnus-widget-button-keymap)
6208 ;; Do the handles
6209 (while (setq handle (pop handles))
6210 (gnus-add-text-properties
6211 (setq from (point))
6212 (progn
6213 (insert (format "(%c) %-18s"
6214 (if (equal handle preferred) ?* ? )
6215 (mm-handle-media-type handle)))
6216 (point))
6217 `(gnus-callback
6218 (lambda (handles)
6219 (unless ,(not ibegend)
6220 (setq gnus-article-mime-handle-alist
6221 ',gnus-article-mime-handle-alist))
6222 (gnus-mime-display-alternative
6223 ',ihandles ',handle ',begend ,id))
6224 keymap ,gnus-mime-button-map
6225 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6226 face ,gnus-article-button-face
6227 gnus-part ,id
6228 gnus-data ,handle
6229 rear-nonsticky t))
6230 (widget-convert-button 'link from (point)
6231 :action 'gnus-widget-press-button
6232 :button-keymap gnus-widget-button-keymap)
6233 (insert " "))
6234 (insert "\n\n"))
6235 (when preferred
6236 (if (stringp (car preferred))
6237 (gnus-display-mime preferred)
6238 (let ((mail-parse-charset gnus-newsgroup-charset)
6239 (mail-parse-ignored-charsets
6240 (with-current-buffer gnus-summary-buffer
6241 gnus-newsgroup-ignored-charsets)))
6242 (gnus-bind-mm-vars (mm-display-part preferred))
6243 ;; Do highlighting.
6244 (save-excursion
6245 (save-restriction
6246 (narrow-to-region (car begend) (point-max))
6247 (gnus-treat-article
6248 nil (length gnus-article-mime-handle-alist)
6249 (gnus-article-mime-total-parts)
6250 (mm-handle-media-type preferred))))))
6251 (goto-char (point-max))
6252 (setcdr begend (point-marker)))))
6253 (when ibegend
6254 (goto-char point)))
6255 ;; Redraw attachment buttons in the header.
6256 (when gnus-mime-display-attachment-buttons-in-header
6257 (gnus-mime-buttonize-attachments-in-header)))
6258
6259 (defconst gnus-article-wash-status-strings
6260 (let ((alist '((cite "c" "Possible hidden citation text"
6261 " " "All citation text visible")
6262 (headers "h" "Hidden headers"
6263 " " "All headers visible.")
6264 (pgp "p" "Encrypted or signed message status hidden"
6265 " " "No hidden encryption nor digital signature status")
6266 (signature "s" "Signature has been hidden"
6267 " " "Signature is visible")
6268 (overstrike "o" "Overstrike (^H) characters applied"
6269 " " "No overstrike characters applied")
6270 (emphasis "e" "/*_Emphasis_*/ characters applied"
6271 " " "No /*_emphasis_*/ characters applied")))
6272 result)
6273 (dolist (entry alist result)
6274 (let ((key (nth 0 entry))
6275 (on (copy-sequence (nth 1 entry)))
6276 (on-help (nth 2 entry))
6277 (off (copy-sequence (nth 3 entry)))
6278 (off-help (nth 4 entry)))
6279 (put-text-property 0 1 'help-echo on-help on)
6280 (put-text-property 0 1 'help-echo off-help off)
6281 (push (list key on off) result))))
6282 "Alist of strings describing wash status in the mode line.
6283 Each entry has the form (KEY ON OF), where the KEY is a symbol
6284 representing the particular washing function, ON is the string to use
6285 in the article mode line when the washing function is active, and OFF
6286 is the string to use when it is inactive.")
6287
6288 (defun gnus-article-wash-status-entry (key value)
6289 (let ((entry (assoc key gnus-article-wash-status-strings)))
6290 (if value (nth 1 entry) (nth 2 entry))))
6291
6292 (defun gnus-article-wash-status ()
6293 "Return a string which display status of article washing."
6294 (with-current-buffer gnus-article-buffer
6295 (let ((cite (memq 'cite gnus-article-wash-types))
6296 (headers (memq 'headers gnus-article-wash-types))
6297 (boring (memq 'boring-headers gnus-article-wash-types))
6298 (pgp (memq 'pgp gnus-article-wash-types))
6299 (pem (memq 'pem gnus-article-wash-types))
6300 (signed (memq 'signed gnus-article-wash-types))
6301 (encrypted (memq 'encrypted gnus-article-wash-types))
6302 (signature (memq 'signature gnus-article-wash-types))
6303 (overstrike (memq 'overstrike gnus-article-wash-types))
6304 (emphasis (memq 'emphasis gnus-article-wash-types)))
6305 (concat
6306 (gnus-article-wash-status-entry 'cite cite)
6307 (gnus-article-wash-status-entry 'headers (or headers boring))
6308 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6309 (gnus-article-wash-status-entry 'signature signature)
6310 (gnus-article-wash-status-entry 'overstrike overstrike)
6311 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6312
6313 (defun gnus-add-wash-type (type)
6314 "Add a washing of TYPE to the current status."
6315 (add-to-list 'gnus-article-wash-types type))
6316
6317 (defun gnus-delete-wash-type (type)
6318 "Add a washing of TYPE to the current status."
6319 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6320
6321 (defun gnus-add-image (category image)
6322 "Add IMAGE of CATEGORY to the list of displayed images."
6323 (let ((entry (assq category gnus-article-image-alist)))
6324 (unless entry
6325 (setq entry (list category))
6326 (push entry gnus-article-image-alist))
6327 (nconc entry (list image))))
6328
6329 (defun gnus-delete-images (category)
6330 "Delete all images in CATEGORY."
6331 (let ((entry (assq category gnus-article-image-alist)))
6332 (dolist (image (cdr entry))
6333 (gnus-remove-image image category))
6334 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6335 (gnus-delete-wash-type category)))
6336
6337 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6338
6339 (defun gnus-article-maybe-hide-headers ()
6340 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6341 Provided for backwards compatibility."
6342 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6343 (not (with-current-buffer gnus-summary-buffer
6344 gnus-have-all-headers)))
6345 (not gnus-inhibit-hiding))
6346 (gnus-article-hide-headers)))
6347
6348 (declare-function shr-put-image "shr" (data alt &optional flags))
6349
6350 (defun gnus-shr-put-image (data alt &optional flags)
6351 "Put image DATA with a string ALT. Enable image to be deleted."
6352 (let ((image (if flags
6353 (shr-put-image data (propertize (or alt "*")
6354 'gnus-image-category 'shr)
6355 flags)
6356 ;; Old `shr-put-image' doesn't take the optional `flags'
6357 ;; argument.
6358 (shr-put-image data (propertize (or alt "*")
6359 'gnus-image-category 'shr)))))
6360 (when image
6361 (gnus-add-image 'shr image))))
6362
6363 (defun gnus-article-mime-handles (&optional alist id all)
6364 (if alist
6365 (let ((i 1) newid flat)
6366 (dolist (handle alist flat)
6367 (setq newid (append id (list i))
6368 i (1+ i))
6369 (if (stringp (car handle))
6370 (setq flat (nconc flat (gnus-article-mime-handles
6371 (cdr handle) newid all)))
6372 (delq (rassq handle all) all)
6373 (setq flat (nconc flat (list (cons newid handle)))))))
6374 (let ((flat (list nil)))
6375 ;; Assume that elements of `gnus-article-mime-handle-alist'
6376 ;; are in the decreasing order, but unnumbered subsidiaries
6377 ;; in each element are in the increasing order.
6378 (dolist (handle (reverse gnus-article-mime-handle-alist))
6379 (if (stringp (cadr handle))
6380 (setq flat (nconc flat (gnus-article-mime-handles
6381 (cddr handle) (list (car handle)) flat)))
6382 (delq (rassq (cdr handle) flat) flat)
6383 (setq flat (nconc flat (list (cons (list (car handle))
6384 (cdr handle)))))))
6385 (setq flat (cdr flat))
6386 (mapc (lambda (handle)
6387 (if (cdar handle)
6388 ;; This is a hidden (i.e. unnumbered) handle.
6389 (progn
6390 (setcar handle
6391 (1+ (caar gnus-article-mime-handle-alist)))
6392 (push handle gnus-article-mime-handle-alist))
6393 (setcar handle (caar handle))))
6394 flat)
6395 flat)))
6396
6397 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6398 "Show attachments as buttons in the end of the header of an article.
6399 This function toggles the display when called interactively. Note that
6400 buttons to be added to the header are only the ones that aren't inlined
6401 in the body. Use `gnus-header-face-alist' to highlight buttons."
6402 (interactive (list t))
6403 (gnus-with-article-buffer
6404 (let ((case-fold-search t) buttons handle type st)
6405 (save-excursion
6406 (save-restriction
6407 (widen)
6408 (article-narrow-to-head)
6409 ;; Header buttons exist?
6410 (while (and (not buttons)
6411 (re-search-forward "^attachments?:[\n ]+" nil t))
6412 (when (get-char-property (match-end 0)
6413 'gnus-button-attachment-extra)
6414 (setq buttons (match-beginning 0))))
6415 (widen)
6416 (when buttons
6417 ;; Delete header buttons.
6418 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6419 (match-beginning 0)
6420 (point-max))))
6421 (unless (and interactive buttons)
6422 ;; Find buttons.
6423 (setq buttons nil)
6424 (dolist (button (gnus-article-mime-handles))
6425 (setq handle (cdr button)
6426 type (mm-handle-media-type handle))
6427 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6428 (with-current-buffer gnus-summary-buffer
6429 gnus-inhibit-images)
6430 gnus-inhibit-images)
6431 (string-match "\\`image/" type))
6432 (mm-inline-override-p handle)
6433 (and (mm-handle-disposition handle)
6434 (not (equal (car (mm-handle-disposition handle))
6435 "inline"))
6436 (not (mm-attachment-override-p handle)))
6437 (not (mm-automatic-display-p handle))
6438 (not (or (and (mm-inlinable-p handle)
6439 (mm-inlined-p handle))
6440 (mm-automatic-external-display-p type))))
6441 (push button buttons)))
6442 (when buttons
6443 ;; Add header buttons.
6444 (article-goto-body)
6445 (forward-line -1)
6446 (narrow-to-region (point) (point))
6447 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6448 (dolist (button (nreverse buttons))
6449 (setq st (point))
6450 (insert " ")
6451 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6452 (gnus-insert-mime-button handle (car button))
6453 (skip-chars-backward "\t\n ")
6454 (delete-region (point) (point-max))
6455 (when (> (current-column) (window-width))
6456 (goto-char st)
6457 (insert "\n")
6458 (end-of-line)))
6459 (insert "\n")
6460 (dolist (ovl (overlays-in (point-min) (point)))
6461 (overlay-put ovl 'gnus-button-attachment-extra t)
6462 (overlay-put ovl 'face nil))
6463 (let ((gnus-treatment-function-alist
6464 '((gnus-treat-highlight-headers
6465 gnus-article-highlight-headers))))
6466 (gnus-treat-article 'head)))))))))
6467
6468 ;;; Article savers.
6469
6470 (defun gnus-output-to-file (file-name)
6471 "Append the current article to a file named FILE-NAME.
6472 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6473 text and used as the value of the coding cookie which is added to the
6474 top of a file. Otherwise, this function saves a raw article without
6475 the coding cookie."
6476 (let* ((artbuf (current-buffer))
6477 (file-name-coding-system nnmail-pathname-coding-system)
6478 (coding gnus-article-save-coding-system)
6479 (coding-system-for-read (if coding
6480 nil ;; Rely on the coding cookie.
6481 mm-text-coding-system))
6482 (coding-system-for-write (or coding
6483 mm-text-coding-system-for-write
6484 mm-text-coding-system))
6485 (exists (file-exists-p file-name)))
6486 (with-temp-buffer
6487 (when exists
6488 (insert-file-contents file-name)
6489 (goto-char (point-min))
6490 ;; Remove the existing coding cookie.
6491 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6492 (delete-region (match-beginning 0) (match-end 0))))
6493 (goto-char (point-max))
6494 (insert-buffer-substring artbuf)
6495 ;; Append newline at end of the buffer as separator, and then
6496 ;; save it to file.
6497 (goto-char (point-max))
6498 (insert "\n")
6499 (when coding
6500 ;; If the coding system is not suitable to encode the text,
6501 ;; ask a user for a proper one.
6502 (when (fboundp 'select-safe-coding-system)
6503 (setq coding (coding-system-base
6504 (save-window-excursion
6505 (select-safe-coding-system (point-min) (point-max)
6506 coding))))
6507 (setq coding-system-for-write
6508 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6509 coding)))
6510 (goto-char (point-min))
6511 ;; Add the coding cookie.
6512 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6513 coding-system-for-write)))
6514 (if exists
6515 (progn
6516 (write-region (point-min) (point-max) file-name nil 'no-message)
6517 (message "Appended to %s" file-name))
6518 (write-region (point-min) (point-max) file-name))))
6519 t)
6520
6521 (defun gnus-narrow-to-page (&optional arg)
6522 "Narrow the article buffer to a page.
6523 If given a numerical ARG, move forward ARG pages."
6524 (interactive "P")
6525 (setq arg (if arg (prefix-numeric-value arg) 0))
6526 (with-current-buffer gnus-article-buffer
6527 (widen)
6528 ;; Remove any old next/prev buttons.
6529 (when (gnus-visual-p 'page-marker)
6530 (let ((inhibit-read-only t))
6531 (gnus-remove-text-with-property 'gnus-prev)
6532 (gnus-remove-text-with-property 'gnus-next)))
6533 (let (st nd pt)
6534 (when (save-excursion
6535 (cond ((< arg 0)
6536 (if (re-search-backward page-delimiter nil 'move (abs arg))
6537 (prog1
6538 (setq nd (match-beginning 0)
6539 pt nd)
6540 (when (re-search-backward page-delimiter nil t)
6541 (setq st (match-end 0))))
6542 (when (re-search-forward page-delimiter nil t)
6543 (setq nd (match-beginning 0)
6544 pt (point-min)))))
6545 ((> arg 0)
6546 (if (re-search-forward page-delimiter nil 'move arg)
6547 (prog1
6548 (setq st (match-end 0)
6549 pt st)
6550 (when (re-search-forward page-delimiter nil t)
6551 (setq nd (match-beginning 0))))
6552 (when (re-search-backward page-delimiter nil t)
6553 (setq st (match-end 0)
6554 pt (point-max)))))
6555 (t
6556 (when (re-search-backward page-delimiter nil t)
6557 (goto-char (setq st (match-end 0))))
6558 (when (re-search-forward page-delimiter nil t)
6559 (setq nd (match-beginning 0)))
6560 (or st nd))))
6561 (setq gnus-page-broken t)
6562 (when pt (goto-char pt))
6563 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6564 (when (gnus-visual-p 'page-marker)
6565 (save-excursion
6566 (when nd
6567 (goto-char nd)
6568 (gnus-insert-next-page-button))
6569 (when st
6570 (goto-char st)
6571 (gnus-insert-prev-page-button))))))))
6572
6573 ;; Article mode commands
6574
6575 (defun gnus-article-goto-next-page ()
6576 "Show the next page of the article."
6577 (interactive)
6578 (when (gnus-article-next-page)
6579 (goto-char (point-min))
6580 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6581
6582
6583 (defun gnus-article-goto-prev-page ()
6584 "Show the previous page of the article."
6585 (interactive)
6586 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6587 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6588 (gnus-article-prev-page nil)))
6589
6590 ;; This is cleaner but currently breaks `gnus-pick-mode':
6591 ;;
6592 ;; (defun gnus-article-goto-next-page ()
6593 ;; "Show the next page of the article."
6594 ;; (interactive)
6595 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6596 ;; (gnus-summary-next-page)))
6597 ;;
6598 ;; (defun gnus-article-goto-prev-page ()
6599 ;; "Show the next page of the article."
6600 ;; (interactive)
6601 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6602 ;; (gnus-summary-prev-page)))
6603
6604 (defun gnus-article-next-page (&optional lines)
6605 "Show the next page of the current article.
6606 If end of article, return non-nil. Otherwise return nil.
6607 Argument LINES specifies lines to be scrolled up."
6608 (interactive "p")
6609 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6610 (if (and (not (and gnus-article-over-scroll
6611 (> (count-lines (window-start) (point-max))
6612 (if (featurep 'xemacs)
6613 (or lines (1- (window-height)))
6614 (+ (or lines (1- (window-height))) scroll-margin)))))
6615 (save-excursion
6616 (end-of-line)
6617 (and (pos-visible-in-window-p) ;Not continuation line.
6618 (>= (point) (point-max)))))
6619 ;; Nothing in this page.
6620 (if (or (not gnus-page-broken)
6621 (save-excursion
6622 (save-restriction
6623 (widen)
6624 (forward-line)
6625 (eobp)))) ;Real end-of-buffer?
6626 (progn
6627 (when gnus-article-over-scroll
6628 (gnus-article-next-page-1 lines))
6629 t) ;Nothing more.
6630 (gnus-narrow-to-page 1) ;Go to next page.
6631 nil)
6632 ;; More in this page.
6633 (gnus-article-next-page-1 lines)
6634 nil))
6635
6636 (defun gnus-article-beginning-of-window ()
6637 "Move point to the beginning of the window.
6638 In Emacs, the point is placed at the line number which `scroll-margin'
6639 specifies."
6640 (if (featurep 'xemacs)
6641 (move-to-window-line 0)
6642 ;; There is an obscure bug in Emacs that makes it impossible to
6643 ;; scroll past big pictures in the article buffer. Try to fix
6644 ;; this by adding a sanity check by counting the lines visible.
6645 (when (> (count-lines (window-start) (window-end)) 30)
6646 (move-to-window-line
6647 (min (max 0 scroll-margin)
6648 (max 1 (- (window-height)
6649 (if mode-line-format 1 0)
6650 (if header-line-format 1 0)
6651 2)))))))
6652
6653 (defvar scroll-in-place)
6654
6655 (defun gnus-article-next-page-1 (lines)
6656 (condition-case ()
6657 (let ((scroll-in-place nil)
6658 (auto-window-vscroll nil))
6659 (scroll-up lines))
6660 (end-of-buffer
6661 ;; Long lines may cause an end-of-buffer error.
6662 (goto-char (point-max))))
6663 (gnus-article-beginning-of-window))
6664
6665 (defun gnus-article-prev-page (&optional lines)
6666 "Show previous page of current article.
6667 Argument LINES specifies lines to be scrolled down."
6668 (interactive "p")
6669 (move-to-window-line 0)
6670 (if (and gnus-page-broken
6671 (bobp)
6672 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6673 (progn
6674 (gnus-narrow-to-page -1) ;Go to previous page.
6675 (goto-char (point-max))
6676 (recenter (if gnus-article-over-scroll
6677 (if lines
6678 (max (if (featurep 'xemacs)
6679 lines
6680 (+ lines scroll-margin))
6681 3)
6682 (- (window-height) 2))
6683 -1)))
6684 (prog1
6685 (condition-case ()
6686 (let ((scroll-in-place nil))
6687 (scroll-down lines))
6688 (beginning-of-buffer
6689 (goto-char (point-min))))
6690 (gnus-article-beginning-of-window))))
6691
6692 (defun gnus-article-only-boring-p ()
6693 "Decide whether there is only boring text remaining in the article.
6694 Something \"interesting\" is a word of at least two letters that does
6695 not have a face in `gnus-article-boring-faces'."
6696 (when (and gnus-article-skip-boring
6697 (boundp 'gnus-article-boring-faces)
6698 (symbol-value 'gnus-article-boring-faces))
6699 (save-excursion
6700 (let ((inhibit-point-motion-hooks t))
6701 (catch 'only-boring
6702 (while (re-search-forward "\\b\\w\\w" nil t)
6703 (forward-char -1)
6704 (when (not (gnus-intersection
6705 (gnus-faces-at (point))
6706 (symbol-value 'gnus-article-boring-faces)))
6707 (throw 'only-boring nil)))
6708 (throw 'only-boring t))))))
6709
6710 (defun gnus-article-refer-article ()
6711 "Read article specified by message-id around point."
6712 (interactive)
6713 (save-excursion
6714 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6715 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6716 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6717 (let ((msg-id (concat "<" (match-string 0) ">")))
6718 (set-buffer gnus-summary-buffer)
6719 (gnus-summary-refer-article msg-id))
6720 (error "No references around point"))))
6721
6722 (defun gnus-article-show-summary ()
6723 "Reconfigure windows to show summary buffer."
6724 (interactive)
6725 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6726 (error "There is no summary buffer for this article buffer")
6727 (gnus-article-set-globals)
6728 (gnus-configure-windows 'article)
6729 (gnus-summary-goto-subject gnus-current-article)
6730 (gnus-summary-position-point)))
6731
6732 (defun gnus-article-describe-briefly ()
6733 "Describe article mode commands briefly."
6734 (interactive)
6735 (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")))
6736
6737 (defun gnus-article-check-buffer ()
6738 "Beep if not in an article buffer."
6739 (unless (derived-mode-p 'gnus-article-mode)
6740 (error "Command invoked outside of a Gnus article buffer")))
6741
6742 (defvar gnus-pick-mode)
6743
6744 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6745 "Read a summary buffer key sequence and execute it from the article buffer."
6746 (interactive "P")
6747 (gnus-article-check-buffer)
6748 (let ((nosaves
6749 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6750 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6751 "=" "^" "\M-^" "|"))
6752 (nosave-but-article
6753 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6754 "An" "Ap" [?A (meta return)] [?A delete]))
6755 (nosave-in-article
6756 '("AS" "\C-d"))
6757 keys new-sum-point)
6758 (with-current-buffer gnus-article-current-summary
6759 (let (gnus-pick-mode)
6760 (setq unread-command-events (nconc unread-command-events
6761 (list (or key last-command-event)))
6762 keys (if (featurep 'xemacs)
6763 (events-to-keys (read-key-sequence nil t))
6764 (read-key-sequence nil t)))))
6765
6766 (message "")
6767
6768 (cond
6769 ((eq (aref keys (1- (length keys))) ?\C-h)
6770 (gnus-article-describe-bindings (substring keys 0 -1)))
6771 ((or (member keys nosaves)
6772 (member keys nosave-but-article)
6773 (member keys nosave-in-article))
6774 (let (func)
6775 (save-window-excursion
6776 (pop-to-buffer gnus-article-current-summary)
6777 ;; We disable the pick minor mode commands.
6778 (let (gnus-pick-mode)
6779 (setq func (key-binding keys t))))
6780 (if (or (not func)
6781 (numberp func))
6782 (ding)
6783 (unless (member keys nosave-in-article)
6784 (set-buffer gnus-article-current-summary))
6785 (when (and (symbolp func)
6786 (get func 'disabled))
6787 (error "Function %s disabled" func))
6788 (call-interactively func)
6789 (setq new-sum-point (point)))
6790 (when (member keys nosave-but-article)
6791 (pop-to-buffer gnus-article-buffer))))
6792 (t
6793 ;; These commands should restore window configuration.
6794 (let ((obuf (current-buffer))
6795 (owin (current-window-configuration))
6796 win func in-buffer selected new-sum-start new-sum-hscroll err)
6797 (cond (not-restore-window
6798 (pop-to-buffer gnus-article-current-summary)
6799 (setq win (selected-window)))
6800 ((setq win (get-buffer-window gnus-article-current-summary))
6801 (select-window win))
6802 (t
6803 (let ((summary-buffer gnus-article-current-summary))
6804 (gnus-configure-windows 'article)
6805 (unless (setq win (get-buffer-window summary-buffer 'visible))
6806 (let ((gnus-buffer-configuration
6807 '((article ((vertical 1.0
6808 (summary 0.25 point)
6809 (article 1.0)))))))
6810 (gnus-configure-windows 'article))
6811 (setq win (get-buffer-window summary-buffer 'visible)))
6812 (gnus-select-frame-set-input-focus (window-frame win))
6813 (select-window win))))
6814 (setq in-buffer (current-buffer))
6815 ;; We disable the pick minor mode commands.
6816 (setq func (let (gnus-pick-mode)
6817 (key-binding keys t)))
6818 (when (get func 'disabled)
6819 (error "Function %s disabled" func))
6820 (if (and func
6821 (functionp func)
6822 (condition-case code
6823 (progn
6824 (call-interactively func)
6825 t)
6826 (error
6827 (setq err code)
6828 nil)))
6829 (progn
6830 (when (eq win (selected-window))
6831 (setq new-sum-point (point)
6832 new-sum-start (window-start win)
6833 new-sum-hscroll (window-hscroll win)))
6834 (when (or (eq in-buffer (current-buffer))
6835 (when (eq obuf (current-buffer))
6836 (set-buffer in-buffer)
6837 t))
6838 (setq selected (ignore-errors (gnus-summary-select-article)))
6839 (set-buffer obuf)
6840 (unless not-restore-window
6841 (set-window-configuration owin))
6842 (when (and (eq selected 'old)
6843 new-sum-point)
6844 (set-window-start (get-buffer-window (current-buffer))
6845 1)
6846 (set-window-point (get-buffer-window (current-buffer))
6847 (if (article-goto-body)
6848 (1- (point))
6849 (point))))
6850 (when (and (not not-restore-window)
6851 new-sum-point
6852 (window-live-p win)
6853 (with-current-buffer (window-buffer win)
6854 (derived-mode-p 'gnus-summary-mode)))
6855 (set-window-point win new-sum-point)
6856 (set-window-start win new-sum-start)
6857 (set-window-hscroll win new-sum-hscroll))))
6858 (set-window-configuration owin)
6859 (if err
6860 (signal (car err) (cdr err))
6861 (ding))))))))
6862
6863 (defun gnus-article-read-summary-send-keys ()
6864 (interactive)
6865 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6866 (gnus-article-read-summary-keys)))
6867
6868 (defun gnus-article-describe-key (key)
6869 "Display documentation of the function invoked by KEY.
6870 KEY is a string or a vector."
6871 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6872 (read-key-sequence "Describe key: "))))
6873 (gnus-article-check-buffer)
6874 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6875 gnus-article-read-summary-send-keys))
6876 (with-current-buffer gnus-article-current-summary
6877 (setq unread-command-events
6878 (if (featurep 'xemacs)
6879 (append key unread-command-events)
6880 (nconc
6881 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6882 (list 'meta (- x 128))
6883 x))
6884 key)
6885 unread-command-events)))
6886 (let ((cursor-in-echo-area t)
6887 gnus-pick-mode)
6888 (describe-key (read-key-sequence nil t))))
6889 (describe-key key)))
6890
6891 (defun gnus-article-describe-key-briefly (key &optional insert)
6892 "Display documentation of the function invoked by KEY.
6893 KEY is a string or a vector."
6894 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6895 (read-key-sequence "Describe key: "))
6896 current-prefix-arg))
6897 (gnus-article-check-buffer)
6898 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6899 gnus-article-read-summary-send-keys))
6900 (with-current-buffer gnus-article-current-summary
6901 (setq unread-command-events
6902 (if (featurep 'xemacs)
6903 (append key unread-command-events)
6904 (nconc
6905 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6906 (list 'meta (- x 128))
6907 x))
6908 key)
6909 unread-command-events)))
6910 (let ((cursor-in-echo-area t)
6911 gnus-pick-mode)
6912 (describe-key-briefly (read-key-sequence nil t) insert)))
6913 (describe-key-briefly key insert)))
6914
6915 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6916 (defvar gnus-agent-summary-mode)
6917 (defvar gnus-draft-mode)
6918 (defvar help-xref-stack-item)
6919 (defvar help-xref-following)
6920
6921 (defun gnus-article-describe-bindings (&optional prefix)
6922 "Show a list of all defined keys, and their definitions.
6923 The optional argument PREFIX, if non-nil, should be a key sequence;
6924 then we display only bindings that start with that prefix."
6925 (interactive)
6926 (gnus-article-check-buffer)
6927 (let ((keymap (copy-keymap gnus-article-mode-map))
6928 (map (copy-keymap gnus-article-send-map))
6929 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6930 parent agent draft)
6931 (define-key keymap "S" map)
6932 (define-key map [t] nil)
6933 (with-current-buffer gnus-article-current-summary
6934 (set-keymap-parent
6935 keymap
6936 (if (setq parent (keymap-parent gnus-article-mode-map))
6937 (prog1
6938 (setq parent (copy-keymap parent))
6939 (set-keymap-parent parent (current-local-map)))
6940 (current-local-map)))
6941 (set-keymap-parent map (key-binding "S"))
6942 (let (key def gnus-pick-mode)
6943 (while sumkeys
6944 (setq key (pop sumkeys))
6945 (cond ((and (vectorp key) (= (length key) 1)
6946 (consp (setq def (aref key 0)))
6947 (numberp (car def)) (numberp (cdr def)))
6948 (when (< (max (car def) (cdr def)) 128)
6949 (setq sumkeys
6950 (append (mapcar
6951 #'vector
6952 (nreverse (gnus-uncompress-range def)))
6953 sumkeys))))
6954 ((setq def (key-binding key))
6955 (unless (eq def 'undefined)
6956 (define-key keymap key def))))))
6957 (when (boundp 'gnus-agent-summary-mode)
6958 (setq agent gnus-agent-summary-mode))
6959 (when (boundp 'gnus-draft-mode)
6960 (setq draft gnus-draft-mode)))
6961 (with-temp-buffer
6962 (use-local-map keymap)
6963 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6964 (set (make-local-variable 'gnus-draft-mode) draft)
6965 (describe-bindings prefix))
6966 (let ((item `((lambda (prefix)
6967 (with-current-buffer ,(current-buffer)
6968 (gnus-article-describe-bindings prefix)))
6969 ,prefix)))
6970 ;; Loading `help-mode' here is necessary if `describe-bindings'
6971 ;; is replaced with something, e.g. `helm-descbinds'.
6972 (require 'help-mode)
6973 (with-current-buffer (let (help-xref-following) (help-buffer))
6974 (setq help-xref-stack-item item)))))
6975
6976 (defun gnus-article-reply-with-original (&optional wide)
6977 "Start composing a reply mail to the current message.
6978 The text in the region will be yanked. If the region isn't active,
6979 the entire article will be yanked."
6980 (interactive)
6981 (let ((article (cdr gnus-article-current))
6982 contents)
6983 (if (not (gnus-region-active-p))
6984 (with-current-buffer gnus-summary-buffer
6985 (gnus-summary-reply (list (list article)) wide))
6986 (setq contents (buffer-substring (point) (mark t)))
6987 ;; Deactivate active regions.
6988 (when (and (boundp 'transient-mark-mode)
6989 transient-mark-mode)
6990 (setq mark-active nil))
6991 (with-current-buffer gnus-summary-buffer
6992 (gnus-summary-reply
6993 (list (list article contents)) wide)))))
6994
6995 (defun gnus-article-wide-reply-with-original ()
6996 "Start composing a wide reply mail to the current message.
6997 The text in the region will be yanked. If the region isn't active,
6998 the entire article will be yanked."
6999 (interactive)
7000 (gnus-article-reply-with-original t))
7001
7002 (defun gnus-article-followup-with-original ()
7003 "Compose a followup to the current article.
7004 The text in the region will be yanked. If the region isn't active,
7005 the entire article will be yanked."
7006 (interactive)
7007 (let ((article (cdr gnus-article-current))
7008 contents)
7009 (if (not (gnus-region-active-p))
7010 (with-current-buffer gnus-summary-buffer
7011 (gnus-summary-followup (list (list article))))
7012 (setq contents (buffer-substring (point) (mark t)))
7013 ;; Deactivate active regions.
7014 (when (and (boundp 'transient-mark-mode)
7015 transient-mark-mode)
7016 (setq mark-active nil))
7017 (with-current-buffer gnus-summary-buffer
7018 (gnus-summary-followup
7019 (list (list article contents)))))))
7020
7021 (defun gnus-article-hide (&optional arg force)
7022 "Hide all the gruft in the current article.
7023 This means that signatures, cited text and (some) headers will be
7024 hidden.
7025 If given a prefix, show the hidden text instead."
7026 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7027 (gnus-article-hide-headers arg)
7028 (gnus-article-hide-list-identifiers arg)
7029 (gnus-article-hide-citation-maybe arg force)
7030 (gnus-article-hide-signature arg))
7031
7032 (defun gnus-check-group-server ()
7033 ;; Make sure the connection to the server is alive.
7034 (unless (gnus-server-opened
7035 (gnus-find-method-for-group gnus-newsgroup-name))
7036 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7037 (gnus-request-group gnus-newsgroup-name t)))
7038
7039 (declare-function nneething-get-file-name "nneething" (id))
7040
7041 (defun gnus-request-article-this-buffer (article group)
7042 "Get an article and insert it into this buffer."
7043 (let (do-update-line sparse-header)
7044 (prog1
7045 (save-excursion
7046 (erase-buffer)
7047 (gnus-kill-all-overlays)
7048 (setq group (or group gnus-newsgroup-name))
7049
7050 ;; Using `gnus-request-article' directly will insert the article into
7051 ;; `nntp-server-buffer' - so we'll save some time by not having to
7052 ;; copy it from the server buffer into the article buffer.
7053
7054 ;; We only request an article by message-id when we do not have the
7055 ;; headers for it, so we'll have to get those.
7056 (when (stringp article)
7057 (gnus-read-header article))
7058
7059 ;; If the article number is negative, that means that this article
7060 ;; doesn't belong in this newsgroup (possibly), so we find its
7061 ;; message-id and request it by id instead of number.
7062 (when (and (numberp article)
7063 gnus-summary-buffer
7064 (get-buffer gnus-summary-buffer)
7065 (gnus-buffer-exists-p gnus-summary-buffer))
7066 (with-current-buffer gnus-summary-buffer
7067 (let ((header (gnus-summary-article-header article)))
7068 (when (< article 0)
7069 (cond
7070 ((memq article gnus-newsgroup-sparse)
7071 ;; This is a sparse gap article.
7072 (setq do-update-line article)
7073 (setq article (mail-header-id header))
7074 (setq sparse-header (gnus-read-header article))
7075 (setq gnus-newsgroup-sparse
7076 (delq article gnus-newsgroup-sparse)))
7077 ((vectorp header)
7078 ;; It's a real article.
7079 (setq article (mail-header-id header)))
7080 (t
7081 ;; It is an extracted pseudo-article.
7082 (setq article 'pseudo)
7083 (gnus-request-pseudo-article header))))
7084
7085 (let ((method (gnus-find-method-for-group
7086 gnus-newsgroup-name)))
7087 (when (and (eq (car method) 'nneething)
7088 (vectorp header))
7089 (let ((dir (nneething-get-file-name
7090 (mail-header-id header))))
7091 (when (and (stringp dir)
7092 (file-directory-p dir))
7093 (setq article 'nneething)
7094 (gnus-group-enter-directory dir))))))))
7095
7096 (cond
7097 ;; Refuse to select canceled articles.
7098 ((and (numberp article)
7099 gnus-summary-buffer
7100 (get-buffer gnus-summary-buffer)
7101 (gnus-buffer-exists-p gnus-summary-buffer)
7102 (eq (cdr (with-current-buffer gnus-summary-buffer
7103 (assq article gnus-newsgroup-reads)))
7104 gnus-canceled-mark))
7105 nil)
7106 ;; We first check `gnus-original-article-buffer'.
7107 ((and (get-buffer gnus-original-article-buffer)
7108 (numberp article)
7109 (with-current-buffer gnus-original-article-buffer
7110 (and (equal (car gnus-original-article) group)
7111 (eq (cdr gnus-original-article) article))))
7112 ;; `insert-buffer-substring' would incorrectly use the
7113 ;; equivalent of string-make-multibyte which amount to decoding
7114 ;; with locale-coding-system, causing failure of
7115 ;; subsequent decoding.
7116 (insert (mm-string-to-multibyte
7117 (with-current-buffer gnus-original-article-buffer
7118 (buffer-substring (point-min) (point-max)))))
7119 'article)
7120 ;; Check the backlog.
7121 ((and gnus-keep-backlog
7122 (gnus-backlog-request-article group article (current-buffer)))
7123 'article)
7124 ;; Check asynchronous pre-fetch.
7125 ((gnus-async-request-fetched-article group article (current-buffer))
7126 (gnus-async-prefetch-next group article gnus-summary-buffer)
7127 (when (and (numberp article) gnus-keep-backlog)
7128 (gnus-backlog-enter-article group article (current-buffer)))
7129 'article)
7130 ;; Check the cache.
7131 ((and gnus-use-cache
7132 (numberp article)
7133 (gnus-cache-request-article article group))
7134 'article)
7135 ;; Check the agent cache.
7136 ((gnus-agent-request-article article group)
7137 'article)
7138 ;; Get the article and put into the article buffer.
7139 ((or (stringp article)
7140 (numberp article))
7141 (let ((gnus-override-method gnus-override-method)
7142 (methods (and (stringp article)
7143 (with-current-buffer gnus-summary-buffer
7144 (gnus-refer-article-methods))))
7145 (backend (car (gnus-find-method-for-group
7146 gnus-newsgroup-name)))
7147 result
7148 (inhibit-read-only t))
7149 (when (and (null gnus-override-method)
7150 methods)
7151 (setq gnus-override-method (pop methods)))
7152 (while (not result)
7153 (erase-buffer)
7154 (gnus-kill-all-overlays)
7155 (let ((gnus-newsgroup-name group))
7156 (gnus-check-group-server))
7157 (cond
7158 ((gnus-request-article article group (current-buffer))
7159 (when (numberp article)
7160 (gnus-async-prefetch-next group article
7161 gnus-summary-buffer)
7162 (when gnus-keep-backlog
7163 (gnus-backlog-enter-article
7164 group article (current-buffer)))
7165 (when (and gnus-agent
7166 (gnus-agent-group-covered-p group))
7167 (gnus-agent-store-article article group)))
7168 (setq result 'article))
7169 (methods
7170 (setq gnus-override-method (pop methods)))
7171 ((not (string-match "^400 "
7172 (nnheader-get-report backend)))
7173 ;; If we get 400 server disconnect, reconnect and
7174 ;; retry; otherwise, assume the article has expired.
7175 (setq result 'done))))
7176 (and (eq result 'article) 'article)))
7177 ;; It was a pseudo.
7178 (t article)))
7179
7180 ;; Associate this article with the current summary buffer.
7181 (setq gnus-article-current-summary gnus-summary-buffer)
7182
7183 ;; Take the article from the original article buffer
7184 ;; and place it in the buffer it's supposed to be in.
7185 (when (and (get-buffer gnus-article-buffer)
7186 (equal (buffer-name (current-buffer))
7187 (buffer-name (get-buffer gnus-article-buffer))))
7188 (save-excursion
7189 (if (get-buffer gnus-original-article-buffer)
7190 (set-buffer gnus-original-article-buffer)
7191 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7192 (buffer-disable-undo)
7193 (setq major-mode 'gnus-original-article-mode)
7194 (setq buffer-read-only t))
7195 (let ((inhibit-read-only t))
7196 (erase-buffer)
7197 (insert-buffer-substring gnus-article-buffer))
7198 (setq gnus-original-article (cons group article)))
7199
7200 ;; Decode charsets.
7201 (run-hooks 'gnus-article-decode-hook)
7202 ;; Mark article as decoded or not.
7203 (setq gnus-article-decoded-p gnus-article-decode-hook))
7204
7205 ;; Update sparse articles.
7206 (when (and do-update-line
7207 (or (numberp article)
7208 (stringp article)))
7209 (let ((buf (current-buffer)))
7210 (set-buffer gnus-summary-buffer)
7211 (gnus-summary-update-article do-update-line sparse-header)
7212 (gnus-summary-goto-subject do-update-line nil t)
7213 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7214 (point))
7215 (set-buffer buf))))))
7216
7217 (defun gnus-block-private-groups (group)
7218 "Allows images in newsgroups to be shown, blocks images in all
7219 other groups."
7220 (if (or (gnus-news-group-p group)
7221 (gnus-member-of-valid 'global group))
7222 ;; Block nothing in news groups.
7223 nil
7224 ;; Block everything anywhere else.
7225 "."))
7226
7227 (defun gnus-blocked-images ()
7228 (if (functionp gnus-blocked-images)
7229 (funcall gnus-blocked-images gnus-newsgroup-name)
7230 gnus-blocked-images))
7231
7232 ;;;
7233 ;;; Article editing
7234 ;;;
7235
7236 (defcustom gnus-article-edit-mode-hook nil
7237 "Hook run in article edit mode buffers."
7238 :group 'gnus-article-various
7239 :type 'hook)
7240
7241 (defvar gnus-article-edit-done-function nil)
7242
7243 (defvar gnus-article-edit-mode-map nil)
7244
7245 ;; Should we be using derived.el for this?
7246 (unless gnus-article-edit-mode-map
7247 (setq gnus-article-edit-mode-map (make-keymap))
7248 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7249
7250 (gnus-define-keys gnus-article-edit-mode-map
7251 "\C-c?" describe-mode
7252 "\C-c\C-c" gnus-article-edit-done
7253 "\C-c\C-k" gnus-article-edit-exit
7254 "\C-c\C-f\C-t" message-goto-to
7255 "\C-c\C-f\C-o" message-goto-from
7256 "\C-c\C-f\C-b" message-goto-bcc
7257 ;;"\C-c\C-f\C-w" message-goto-fcc
7258 "\C-c\C-f\C-c" message-goto-cc
7259 "\C-c\C-f\C-s" message-goto-subject
7260 "\C-c\C-f\C-r" message-goto-reply-to
7261 "\C-c\C-f\C-n" message-goto-newsgroups
7262 "\C-c\C-f\C-d" message-goto-distribution
7263 "\C-c\C-f\C-f" message-goto-followup-to
7264 "\C-c\C-f\C-m" message-goto-mail-followup-to
7265 "\C-c\C-f\C-k" message-goto-keywords
7266 "\C-c\C-f\C-u" message-goto-summary
7267 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7268 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7269 "\C-c\C-b" message-goto-body
7270 "\C-c\C-i" message-goto-signature
7271
7272 "\C-c\C-t" message-insert-to
7273 "\C-c\C-n" message-insert-newsgroups
7274 "\C-c\C-o" message-sort-headers
7275 "\C-c\C-e" message-elide-region
7276 "\C-c\C-v" message-delete-not-region
7277 "\C-c\C-z" message-kill-to-signature
7278 "\M-\r" message-newline-and-reformat
7279 "\C-c\C-a" mml-attach-file
7280 "\C-a" message-beginning-of-line
7281 "\t" message-tab
7282 "\M-;" comment-region)
7283
7284 (gnus-define-keys (gnus-article-edit-wash-map
7285 "\C-c\C-w" gnus-article-edit-mode-map)
7286 "f" gnus-article-edit-full-stops))
7287
7288 (easy-menu-define
7289 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7290 '("Field"
7291 ["Fetch To" message-insert-to t]
7292 ["Fetch Newsgroups" message-insert-newsgroups t]
7293 "----"
7294 ["To" message-goto-to t]
7295 ["From" message-goto-from t]
7296 ["Subject" message-goto-subject t]
7297 ["Cc" message-goto-cc t]
7298 ["Reply-To" message-goto-reply-to t]
7299 ["Summary" message-goto-summary t]
7300 ["Keywords" message-goto-keywords t]
7301 ["Newsgroups" message-goto-newsgroups t]
7302 ["Followup-To" message-goto-followup-to t]
7303 ["Mail-Followup-To" message-goto-mail-followup-to t]
7304 ["Distribution" message-goto-distribution t]
7305 ["Body" message-goto-body t]
7306 ["Signature" message-goto-signature t]))
7307
7308 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7309 "Major mode for editing articles.
7310 This is an extended text-mode.
7311
7312 \\{gnus-article-edit-mode-map}"
7313 (make-local-variable 'gnus-article-edit-done-function)
7314 (make-local-variable 'gnus-prev-winconf)
7315 (set (make-local-variable 'font-lock-defaults)
7316 '(message-font-lock-keywords t))
7317 (set (make-local-variable 'mail-header-separator) "")
7318 (set (make-local-variable 'gnus-article-edit-mode) t)
7319 (easy-menu-add message-mode-field-menu message-mode-map)
7320 (mml-mode)
7321 (setq buffer-read-only nil)
7322 (buffer-enable-undo)
7323 (widen))
7324
7325 (defun gnus-article-edit (&optional force)
7326 "Edit the current article.
7327 This will have permanent effect only in mail groups.
7328 If FORCE is non-nil, allow editing of articles even in read-only
7329 groups."
7330 (interactive "P")
7331 (when (and (not force)
7332 (gnus-group-read-only-p))
7333 (error "The current newsgroup does not support article editing"))
7334 (gnus-article-date-original)
7335 (gnus-article-edit-article
7336 'ignore
7337 `(lambda (no-highlight)
7338 'ignore
7339 (gnus-summary-edit-article-done
7340 ,(or (mail-header-references gnus-current-headers) "")
7341 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7342
7343 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7344 "Start editing the contents of the current article buffer."
7345 (let ((winconf (current-window-configuration)))
7346 (set-buffer gnus-article-buffer)
7347 (let ((message-auto-save-directory
7348 ;; Don't associate the article buffer with a draft file.
7349 nil))
7350 (gnus-article-edit-mode))
7351 (funcall start-func)
7352 (set-buffer-modified-p nil)
7353 (gnus-configure-windows 'edit-article)
7354 (setq gnus-article-edit-done-function exit-func)
7355 (setq gnus-prev-winconf winconf)
7356 (unless quiet
7357 (gnus-message 6 "C-c C-c to end edits"))))
7358
7359 (defun gnus-article-edit-done (&optional arg)
7360 "Update the article edits and exit."
7361 (interactive "P")
7362 (let ((func gnus-article-edit-done-function)
7363 (buf (current-buffer))
7364 (start (window-start))
7365 (winconf gnus-prev-winconf))
7366 (widen) ;; Widen it in case that users narrowed the buffer.
7367 (funcall func arg)
7368 (set-buffer buf)
7369 ;; The cache and backlog have to be flushed somewhat.
7370 (when gnus-keep-backlog
7371 (gnus-backlog-remove-article
7372 (car gnus-article-current) (cdr gnus-article-current)))
7373 ;; Flush original article as well.
7374 (gnus-flush-original-article-buffer)
7375 (when gnus-use-cache
7376 (gnus-cache-update-article
7377 (car gnus-article-current) (cdr gnus-article-current)))
7378 ;; We remove all text props from the article buffer.
7379 (kill-all-local-variables)
7380 (set-text-properties (point-min) (point-max) nil)
7381 (gnus-article-mode)
7382 (set-window-configuration winconf)
7383 (set-buffer buf)
7384 (set-window-start (get-buffer-window buf) start)
7385 (set-window-point (get-buffer-window buf) (point)))
7386 (gnus-summary-show-article))
7387
7388 (defun gnus-flush-original-article-buffer ()
7389 (when (get-buffer gnus-original-article-buffer)
7390 (with-current-buffer gnus-original-article-buffer
7391 (setq gnus-original-article nil))))
7392
7393 (defun gnus-article-edit-exit ()
7394 "Exit the article editing without updating."
7395 (interactive)
7396 (when (or (not (buffer-modified-p))
7397 (yes-or-no-p "Article modified; kill anyway? "))
7398 (let ((curbuf (current-buffer))
7399 (p (point))
7400 (window-start (window-start)))
7401 (erase-buffer)
7402 (if (gnus-buffer-live-p gnus-original-article-buffer)
7403 (insert-buffer-substring gnus-original-article-buffer))
7404 (let ((winconf gnus-prev-winconf))
7405 (kill-all-local-variables)
7406 (gnus-article-mode)
7407 (set-window-configuration winconf)
7408 ;; Tippy-toe some to make sure that point remains where it was.
7409 (save-current-buffer
7410 (set-buffer curbuf)
7411 (set-window-start (get-buffer-window (current-buffer)) window-start)
7412 (goto-char p))))
7413 (gnus-summary-show-article)))
7414
7415 (defun gnus-article-edit-full-stops ()
7416 "Interactively repair spacing at end of sentences."
7417 (interactive)
7418 (save-excursion
7419 (goto-char (point-min))
7420 (search-forward-regexp "^$" nil t)
7421 (let ((case-fold-search nil))
7422 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7423
7424 ;;;
7425 ;;; Article highlights
7426 ;;;
7427
7428 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7429
7430 ;;; Internal Variables:
7431
7432 (defcustom gnus-button-url-regexp
7433 (concat
7434 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7435 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7436 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7437 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7438 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7439 (punct "!?:;.,"))
7440 (concat
7441 "\\(?:"
7442 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7443 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7444 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7445 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7446 "\\|"
7447 "[" chars punct "]+" "[" chars "]"
7448 "\\)"))
7449 (concat ;; XEmacs 21.4 doesn't support POSIX.
7450 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7451 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7452 "\\)")
7453 "Regular expression that matches URLs."
7454 :version "24.4"
7455 :group 'gnus-article-buttons
7456 :type 'regexp)
7457
7458 (defcustom gnus-button-valid-fqdn-regexp
7459 message-valid-fqdn-regexp
7460 "Regular expression that matches a valid FQDN."
7461 :version "22.1"
7462 :group 'gnus-article-buttons
7463 :type 'regexp)
7464
7465 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7466 (defcustom gnus-button-valid-localpart-regexp
7467 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7468 "Regular expression that matches a localpart of mail addresses or MIDs."
7469 :version "22.1"
7470 :group 'gnus-article-buttons
7471 :type 'regexp)
7472
7473 (defcustom gnus-button-man-handler 'manual-entry
7474 "Function to use for displaying man pages.
7475 The function must take at least one argument with a string naming the
7476 man page."
7477 :version "22.1"
7478 :type '(choice (function-item :tag "Man" manual-entry)
7479 (function-item :tag "Woman" woman)
7480 (function :tag "Other"))
7481 :group 'gnus-article-buttons)
7482
7483 (defcustom gnus-button-mid-or-mail-regexp
7484 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7485 gnus-button-valid-fqdn-regexp
7486 ">?\\)\\b")
7487 "Regular expression that matches a message ID or a mail address."
7488 :version "22.1"
7489 :group 'gnus-article-buttons
7490 :type 'regexp)
7491
7492 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7493 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7494 Strings like this can be either a message ID or a mail address. If it is one
7495 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7496 message ID or a mail address, respectively. If this variable is set to the
7497 symbol `ask', always query the user what do do. If it is a function, this
7498 function will be called with the string as its only argument. The function
7499 must return `mid', `mail', `invalid' or `ask'."
7500 :version "22.1"
7501 :group 'gnus-article-buttons
7502 :type '(choice (function-item :tag "Heuristic function"
7503 gnus-button-mid-or-mail-heuristic)
7504 (const ask)
7505 (const mid)
7506 (const mail)))
7507
7508 (defcustom gnus-button-mid-or-mail-heuristic-alist
7509 '((-10.0 . ".+\\$.+@")
7510 (-10.0 . "#")
7511 (-10.0 . "\\*")
7512 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7513 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7514 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7515 (-1.0 . "^[^a-z]+@")
7516 ;;
7517 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7518 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7519 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7520 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7521 ;;
7522 (-2.0 . "^[0-9]")
7523 (-1.0 . "^[0-9][0-9]")
7524 ;;
7525 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7526 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7527 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7528 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7529 ;;
7530 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7531 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7532 ;; "[0-9]{8,}.*\@"
7533 (-3.0
7534 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7535 ;; "[0-9]{12,}.*\@"
7536 ;; compensation for TDMA dated mail addresses:
7537 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7538 ;;
7539 (-20.0 . "\\.fsf@") ;; Gnus
7540 (-20.0 . "^slrn")
7541 (-20.0 . "^Pine")
7542 (-20.0 . "^alpine\\.")
7543 (-20.0 . "_-_") ;; Subject change in thread
7544 ;;
7545 (-20.0 . "\\.ln@") ;; leafnode
7546 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7547 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7548 ;;
7549 ;; (5.0 . "") ;; $local_part_len <= 7
7550 (10.0 . "^[^0-9]+@")
7551 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7552 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7553 (3.0 . "@stud")
7554 ;;
7555 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7556 ;;
7557 (0.5 . "^[A-Z][a-z]")
7558 (0.5 . "^[A-Z][a-z][a-z]")
7559 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7560 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7561 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7562
7563 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7564 address. The REGEXP is processed with `case-fold-search' set to nil."
7565 :version "22.1"
7566 :group 'gnus-article-buttons
7567 :type '(repeat (cons (number :tag "Rate")
7568 (regexp :tag "Regexp"))))
7569
7570 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7571 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7572 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7573 address, `ask' if unsure and `invalid' if the string is invalid."
7574 (let ((case-fold-search nil)
7575 (list gnus-button-mid-or-mail-heuristic-alist)
7576 (result 0) rate regexp lpartlen elem)
7577 (setq lpartlen
7578 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7579 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7580 ;; Certain special cases...
7581 (when (string-match
7582 (concat
7583 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7584 "^[0-9]+\\.[0-9]+@compuserve\\|"
7585 "@public\\.gmane\\.org")
7586 mid-or-mail)
7587 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7588 (setq result 'mail))
7589 (when (string-match "@.*@\\| " mid-or-mail)
7590 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7591 (setq result 'invalid))
7592 ;; Nothing more to do, if result is not a number here...
7593 (when (numberp result)
7594 (while list
7595 (setq elem (car list)
7596 rate (car elem)
7597 regexp (cdr elem)
7598 list (cdr list))
7599 (when (string-match regexp mid-or-mail)
7600 (setq result (+ result rate))
7601 (gnus-message
7602 9 "`%s' matched `%s', rate `%s', result `%s'."
7603 mid-or-mail regexp rate result)))
7604 (when (<= lpartlen 7)
7605 (setq result (+ result 5.0))
7606 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7607 mid-or-mail result))
7608 (when (>= lpartlen 12)
7609 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7610 (cond
7611 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7612 ;; Long local part should contain realname if e-mail address,
7613 ;; too many digits: message-id.
7614 ;; $score -= 5.0 + 0.1 * $local_part_len;
7615 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7616 (setq result (+ result rate))
7617 (gnus-message
7618 9 "Many digits in `%s', rate `%s', result `%s'."
7619 mid-or-mail rate result))
7620 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7621 mid-or-mail)
7622 ;; Too few vowels [^aeiouy]{4,}.*@
7623 (setq result (+ result -5.0))
7624 (gnus-message
7625 9 "Few vowels in `%s', rate `%s', result `%s'."
7626 mid-or-mail -5.0 result))
7627 (t
7628 (setq result (+ result 5.0))
7629 (gnus-message
7630 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7631 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7632 ;; Maybe we should make this a customizable alist: (condition . 'result)
7633 (cond
7634 ((symbolp result) result)
7635 ;; Now convert number into proper results:
7636 ((< result -10.0) 'mid)
7637 ((> result 10.0) 'mail)
7638 (t 'ask))))
7639
7640 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7641 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7642 (url-mid (concat "news" ":" mid-or-mail))
7643 (url-mailto (concat "mailto" ":" mid-or-mail)))
7644 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7645 (when (fboundp pref)
7646 (setq guessed
7647 ;; get rid of surrounding angles...
7648 (funcall pref
7649 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7650 (if (or (eq 'mid guessed) (eq 'mail guessed))
7651 (setq pref guessed)
7652 (setq pref 'ask)))
7653 (if (eq pref 'ask)
7654 (save-window-excursion
7655 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7656 (setq pref 'mail)
7657 (setq pref 'mid))))
7658 (cond ((eq pref 'mid)
7659 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7660 (gnus-button-handle-news url-mid))
7661 ((eq pref 'mail)
7662 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7663 (gnus-url-mailto url-mailto))
7664 (t (gnus-message 3 "Invalid string.")))))
7665
7666 (defun gnus-button-handle-custom (fun arg)
7667 "Call function FUN on argument ARG.
7668 Both FUN and ARG are supposed to be strings. ARG will be passed
7669 as a symbol to FUN."
7670 (funcall (intern fun)
7671 (if (string-match "^customize-apropos" fun)
7672 arg
7673 (intern arg))))
7674
7675 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7676
7677 (defun gnus-button-handle-describe-function (url)
7678 "Call `describe-function' when pushing the corresponding URL button."
7679 (describe-function
7680 (intern
7681 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7682
7683 (defun gnus-button-handle-describe-variable (url)
7684 "Call `describe-variable' when pushing the corresponding URL button."
7685 (describe-variable
7686 (intern
7687 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7688
7689 (defun gnus-button-handle-symbol (url)
7690 "Display help on variable or function.
7691 Calls `describe-variable' or `describe-function'."
7692 (let ((sym (intern url)))
7693 (cond
7694 ((fboundp sym) (describe-function sym))
7695 ((boundp sym) (describe-variable sym))
7696 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7697
7698 (defun gnus-button-handle-describe-key (url)
7699 "Call `describe-key' when pushing the corresponding URL button."
7700 (let* ((key-string
7701 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7702 (keys (ignore-errors (eval `(kbd ,key-string)))))
7703 (if keys
7704 (describe-key keys)
7705 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7706
7707 (defun gnus-button-handle-apropos (url)
7708 "Call `apropos' when pushing the corresponding URL button."
7709 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7710
7711 (defun gnus-button-handle-apropos-command (url)
7712 "Call `apropos' when pushing the corresponding URL button."
7713 (apropos-command
7714 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7715
7716 (defun gnus-button-handle-apropos-variable (url)
7717 "Call `apropos' when pushing the corresponding URL button."
7718 (funcall
7719 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7720 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7721
7722 (defun gnus-button-handle-apropos-documentation (url)
7723 "Call `apropos' when pushing the corresponding URL button."
7724 (funcall
7725 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7726 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7727
7728 (defun gnus-button-handle-library (url)
7729 "Call `locate-library' when pushing the corresponding URL button."
7730 (gnus-message 9 "url=`%s'" url)
7731 (let* ((lib (locate-library url))
7732 (file (gnus-replace-in-string (or lib "") "\\.elc" ".el")))
7733 (if (not lib)
7734 (gnus-message 1 "Cannot locale library `%s'." url)
7735 (find-file-read-only file))))
7736
7737 (defcustom gnus-button-man-level 5
7738 "*Integer that says how many man-related buttons Gnus will show.
7739 The higher the number, the more buttons will appear and the more false
7740 positives are possible. Note that you can set this variable local to
7741 specific groups. Setting it higher in Unix groups is probably a good idea.
7742 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7743 how to set variables in specific groups."
7744 :version "22.1"
7745 :group 'gnus-article-buttons
7746 :link '(custom-manual "(gnus)Group Parameters")
7747 :type 'integer)
7748
7749 (defcustom gnus-button-emacs-level 5
7750 "*Integer that says how many emacs-related buttons Gnus will show.
7751 The higher the number, the more buttons will appear and the more false
7752 positives are possible. Note that you can set this variable local to
7753 specific groups. Setting it higher in Emacs or Gnus related groups is
7754 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7755 `gnus-parameters' on how to set variables in specific groups."
7756 :version "22.1"
7757 :group 'gnus-article-buttons
7758 :link '(custom-manual "(gnus)Group Parameters")
7759 :type 'integer)
7760
7761 (defcustom gnus-button-message-level 5
7762 "*Integer that says how many buttons for news or mail messages will appear.
7763 The higher the number, the more buttons will appear and the more false
7764 positives are possible."
7765 ;; mail addresses, MIDs, URLs for news, ...
7766 :version "22.1"
7767 :group 'gnus-article-buttons
7768 :type 'integer)
7769
7770 (defcustom gnus-button-browse-level 5
7771 "*Integer that says how many buttons for browsing will appear.
7772 The higher the number, the more buttons will appear and the more false
7773 positives are possible."
7774 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7775 :version "22.1"
7776 :group 'gnus-article-buttons
7777 :type 'integer)
7778
7779 (defcustom gnus-button-alist
7780 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7781 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7782 ((concat "\\b\\(nntp\\|news\\):\\("
7783 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7784 0 t gnus-button-handle-news 2)
7785 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7786 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7787 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7788 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7789 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7790 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7791 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7792 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7793 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7794 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7795 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7796 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7797 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7798 ;; RFC 2368 (The mailto URL scheme)
7799 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7800 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7801 ("\\bmailto:\\([^ \n\t]+\\)"
7802 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7803 ;; Info Konqueror style <info:/foo/bar baz>.
7804 ;; Must come before " Gnus home-grown style".
7805 ("\\binfo://?\\([^'\">\n\t]+\\)"
7806 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7807 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7808 ("\\binfo://\\([^'\">\n\t ]+\\)"
7809 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7810 ;; Info GNOME style <info:foo#bar_baz>
7811 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7812 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7813 ;; Info KDE style <info:(foo)bar baz>
7814 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7815 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7816 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7817 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7818 ("\\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,]*\\)\\)?"
7819 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7820 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7821 ;; This is custom
7822 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7823 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7824 ;; Emacs help commands
7825 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7826 ;; regexp doesn't match arguments containing ` '.
7827 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7828 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7829 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7830 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7831 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7832 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7833 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7834 ;; The following entries may lead to many false positives so don't enable
7835 ;; them by default (use a high button level).
7836 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7837 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7838 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7839 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7840 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7841 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7842 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7843 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7844 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7845 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7846 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7847 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7848 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7849 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7850 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7851 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7852 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7853 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7854 ;; Unlike the other regexps we really have to require quoting
7855 ;; here to determine where it ends.
7856 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7857 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7858 ("<URL: *\\([^\n<>]*\\)>"
7859 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7860 ;; RFC 2396 (2.4.3., delims) ...
7861 ("\"URL: *\\([^\n\"]*\\)\""
7862 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7863 ;; Raw URLs.
7864 (gnus-button-url-regexp
7865 0 (>= gnus-button-browse-level 0) browse-url 0)
7866 ;; man pages
7867 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7868 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7869 gnus-button-handle-man 1)
7870 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7871 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7872 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7873 gnus-button-handle-man 1)
7874 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7875 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7876 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7877 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7878 ;; Recognizing patches to .el files. This is somewhat obscure,
7879 ;; but considering the percentage of Gnus users who hack Emacs
7880 ;; Lisp files...
7881 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7882 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7883 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7884 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7885 ;; MID or mail: To avoid too many false positives we don't try to catch
7886 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7887 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7888 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7889 ;; so that non-ambiguous entries (see above) match first.
7890 (gnus-button-mid-or-mail-regexp
7891 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7892 "*Alist of regexps matching buttons in article bodies.
7893
7894 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7895 REGEXP: is the string (case insensitive) matching text around the button (can
7896 also be Lisp expression evaluating to a string),
7897 BUTTON: is the number of the regexp grouping actually matching the button,
7898 FORM: is a Lisp expression which must eval to true for the button to
7899 be added,
7900 CALLBACK: is the function to call when the user push this button, and each
7901 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7902
7903 CALLBACK can also be a variable, in that case the value of that
7904 variable it the real callback function."
7905 :group 'gnus-article-buttons
7906 :type '(repeat (list (choice regexp variable sexp)
7907 (integer :tag "Button")
7908 (sexp :tag "Form")
7909 (function :tag "Callback")
7910 (repeat :tag "Par"
7911 :inline t
7912 (integer :tag "Regexp group")))))
7913 (put 'gnus-button-alist 'risky-local-variable t)
7914
7915 (defcustom gnus-header-button-alist
7916 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7917 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7918 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7919 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7920 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7921 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7922 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7923 0 (>= gnus-button-browse-level 0) browse-url 0)
7924 ("^Subject:" gnus-button-url-regexp
7925 0 (>= gnus-button-browse-level 0) browse-url 0)
7926 ("^[^:]+:" gnus-button-url-regexp
7927 0 (>= gnus-button-browse-level 0) browse-url 0)
7928 ("^OpenPGP:.*url=" gnus-button-url-regexp
7929 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7930 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7931 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7932 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7933 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7934 "*Alist of headers and regexps to match buttons in article heads.
7935
7936 This alist is very similar to `gnus-button-alist', except that each
7937 alist has an additional HEADER element first in each entry:
7938
7939 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7940
7941 HEADER is a regexp to match a header. For a fuller explanation, see
7942 `gnus-button-alist'."
7943 :group 'gnus-article-buttons
7944 :group 'gnus-article-headers
7945 :type '(repeat (list (regexp :tag "Header")
7946 (choice regexp variable)
7947 (integer :tag "Button")
7948 (sexp :tag "Form")
7949 (function :tag "Callback")
7950 (repeat :tag "Par"
7951 :inline t
7952 (integer :tag "Regexp group")))))
7953 (put 'gnus-header-button-alist 'risky-local-variable t)
7954
7955 ;;; Commands:
7956
7957 (defun gnus-article-push-button (event)
7958 "Check text under the mouse pointer for a callback function.
7959 If the text under the mouse pointer has a `gnus-callback' property,
7960 call it with the value of the `gnus-data' text property."
7961 (interactive "e")
7962 (set-buffer (window-buffer (posn-window (event-start event))))
7963 (let* ((pos (posn-point (event-start event)))
7964 (data (get-text-property pos 'gnus-data))
7965 (fun (get-text-property pos 'gnus-callback)))
7966 (goto-char pos)
7967 (when fun
7968 (funcall fun data))))
7969
7970 (defun gnus-article-press-button ()
7971 "Check text at point for a callback function.
7972 If the text at point has a `gnus-callback' property,
7973 call it with the value of the `gnus-data' text property."
7974 (interactive)
7975 (let ((data (get-text-property (point) 'gnus-data))
7976 (fun (get-text-property (point) 'gnus-callback)))
7977 (when fun
7978 (funcall fun data))))
7979
7980 (defun gnus-article-highlight (&optional force)
7981 "Highlight current article.
7982 This function calls `gnus-article-highlight-headers',
7983 `gnus-article-highlight-citation',
7984 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7985 do the highlighting. See the documentation for those functions."
7986 (interactive (list 'force))
7987 (gnus-article-highlight-headers)
7988 (gnus-article-highlight-citation force)
7989 (gnus-article-highlight-signature)
7990 (gnus-article-add-buttons)
7991 (gnus-article-add-buttons-to-head))
7992
7993 (defun gnus-article-highlight-some (&optional _force)
7994 "Highlight current article.
7995 This function calls `gnus-article-highlight-headers',
7996 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7997 do the highlighting. See the documentation for those functions."
7998 (interactive (list 'force))
7999 (gnus-article-highlight-headers)
8000 (gnus-article-highlight-signature)
8001 (gnus-article-add-buttons))
8002
8003 (defun gnus-article-highlight-headers ()
8004 "Highlight article headers as specified by `gnus-header-face-alist'."
8005 (interactive)
8006 (gnus-with-article-headers
8007 (let (regexp header-face field-face from hpoints fpoints)
8008 (dolist (entry gnus-header-face-alist)
8009 (goto-char (point-min))
8010 (setq regexp (concat "^\\("
8011 (if (string-equal "" (nth 0 entry))
8012 "[^\t ]"
8013 (nth 0 entry))
8014 "\\)")
8015 header-face (nth 1 entry)
8016 field-face (nth 2 entry))
8017 (while (and (re-search-forward regexp nil t)
8018 (not (eobp)))
8019 (beginning-of-line)
8020 (setq from (point))
8021 (unless (search-forward ":" nil t)
8022 (forward-char 1))
8023 (when (and header-face
8024 (not (memq (point) hpoints)))
8025 (push (point) hpoints)
8026 (gnus-put-text-property from (point) 'face header-face))
8027 (when (and field-face
8028 (not (memq (setq from (point)) fpoints)))
8029 (push from fpoints)
8030 (if (re-search-forward "^[^ \t]" nil t)
8031 (forward-char -2)
8032 (goto-char (point-max)))
8033 (gnus-put-text-property from (point) 'face field-face)))))))
8034
8035 (defun gnus-article-highlight-signature ()
8036 "Highlight the signature in an article.
8037 It does this by highlighting everything after
8038 `gnus-signature-separator' using the face `gnus-signature'."
8039 (interactive)
8040 (gnus-with-article-buffer
8041 (let ((inhibit-point-motion-hooks t))
8042 (save-restriction
8043 (when (and gnus-signature-face
8044 (gnus-article-narrow-to-signature))
8045 (overlay-put (make-overlay (point-min) (point-max) nil t)
8046 'face gnus-signature-face)
8047 (widen)
8048 (gnus-article-search-signature)
8049 (let ((start (match-beginning 0))
8050 (end (set-marker (make-marker) (1+ (match-end 0)))))
8051 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8052 end)))))))
8053
8054 (defun gnus-button-in-region-p (b e prop)
8055 "Say whether PROP exists in the region."
8056 (text-property-not-all b e prop nil))
8057
8058 (defun gnus-article-add-buttons ()
8059 "Find external references in the article and make buttons of them.
8060 \"External references\" are things like Message-IDs and URLs, as
8061 specified by `gnus-button-alist'."
8062 (interactive)
8063 (gnus-with-article-buffer
8064 (let ((inhibit-point-motion-hooks t)
8065 (case-fold-search t)
8066 (alist gnus-button-alist)
8067 beg entry regexp)
8068 ;; We skip the headers.
8069 (article-goto-body)
8070 (setq beg (point))
8071 (while (setq entry (pop alist))
8072 (setq regexp (eval (car entry)))
8073 (goto-char beg)
8074 (while (re-search-forward regexp nil t)
8075 (let ((start (match-beginning (nth 1 entry)))
8076 (end (match-end (nth 1 entry)))
8077 (from (match-beginning 0)))
8078 (when (and (eval (nth 2 entry))
8079 (not (gnus-button-in-region-p
8080 start end 'gnus-callback)))
8081 ;; That optional form returned non-nil, so we add the
8082 ;; button.
8083 (setq from (set-marker (make-marker) from))
8084 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8085 (gnus-article-extend-url-button from start end))
8086 (gnus-article-add-button start end
8087 'gnus-button-push (list from entry))
8088 (gnus-put-text-property
8089 start end
8090 'gnus-string (buffer-substring-no-properties
8091 start end))))))))))
8092
8093 (defun gnus-article-extend-url-button (beg start end)
8094 "Extend url button if url is folded into two or more lines.
8095 Return non-nil if button is extended. BEG is a marker that points to
8096 the beginning position of a text containing url. START and END are
8097 the endpoints of a url button before it is extended. The concatenated
8098 url is put as the `gnus-button-url' overlay property on the button."
8099 (let ((opoint (point))
8100 (points (list start end))
8101 url delim regexp)
8102 (prog1
8103 (when (and (progn
8104 (goto-char end)
8105 (not (looking-at "[\t ]*[\">]")))
8106 (progn
8107 (goto-char start)
8108 (string-match
8109 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8110 (buffer-substring (point-at-bol) start)))
8111 (progn
8112 (setq url (list (buffer-substring start end))
8113 delim (if (match-beginning 1) ">" "\""))
8114 (beginning-of-line)
8115 (setq regexp (concat
8116 (when (and (looking-at
8117 message-cite-prefix-regexp)
8118 (< (match-end 0) start))
8119 (regexp-quote (match-string 0)))
8120 "\
8121 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8122 delim "\\)"))
8123 (while (progn
8124 (forward-line 1)
8125 (and (looking-at regexp)
8126 (prog1
8127 (match-beginning 1)
8128 (push (or (match-string 2)
8129 (match-string 1))
8130 url)
8131 (push (setq end (or (match-end 2)
8132 (match-end 1)))
8133 points)
8134 (push (or (match-beginning 2)
8135 (match-beginning 1))
8136 points)))))
8137 (match-beginning 2)))
8138 (let (gnus-article-mouse-face widget-mouse-face)
8139 (while points
8140 (gnus-article-add-button (pop points) (pop points)
8141 'gnus-button-push
8142 (list beg (assq 'gnus-button-url-regexp
8143 gnus-button-alist)))))
8144 (let ((overlay (make-overlay start end)))
8145 (overlay-put overlay 'evaporate t)
8146 (overlay-put overlay 'gnus-button-url
8147 (list (mapconcat 'identity (nreverse url) "")))
8148 (when gnus-article-mouse-face
8149 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8150 t)
8151 (goto-char opoint))))
8152
8153 ;; Add buttons to the head of an article.
8154 (defun gnus-article-add-buttons-to-head ()
8155 "Add buttons to the head of the article."
8156 (interactive)
8157 (gnus-with-article-headers
8158 (let (beg end)
8159 (dolist (entry gnus-header-button-alist)
8160 ;; Each alist entry.
8161 (goto-char (point-min))
8162 (while (re-search-forward (car entry) nil t)
8163 ;; Each header matching the entry.
8164 (setq beg (match-beginning 0))
8165 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8166 (match-beginning 0))
8167 (point-max)))
8168 (goto-char beg)
8169 (while (re-search-forward (eval (nth 1 entry)) end t)
8170 ;; Each match within a header.
8171 (let* ((entry (cdr entry))
8172 (start (match-beginning (nth 1 entry)))
8173 (end (match-end (nth 1 entry)))
8174 (form (nth 2 entry)))
8175 (goto-char (match-end 0))
8176 (when (eval form)
8177 (gnus-article-add-button
8178 start end (nth 3 entry)
8179 (buffer-substring (match-beginning (nth 4 entry))
8180 (match-end (nth 4 entry)))))))
8181 (goto-char end))))))
8182
8183 ;;; External functions:
8184
8185 (defun gnus-article-add-button (from to fun &optional data text)
8186 "Create a button between FROM and TO with callback FUN and data DATA."
8187 (when gnus-article-button-face
8188 (overlay-put (make-overlay from to nil t)
8189 'face gnus-article-button-face))
8190 (gnus-add-text-properties
8191 from to
8192 (nconc (and gnus-article-mouse-face
8193 (list gnus-mouse-face-prop gnus-article-mouse-face))
8194 (list 'gnus-callback fun)
8195 (and data (list 'gnus-data data))))
8196 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8197 :help-echo (or text "Follow the link")
8198 :keymap gnus-url-button-map
8199 :button-keymap gnus-widget-button-keymap))
8200
8201 (defun gnus-article-copy-string ()
8202 "Copy the string in the button to the kill ring."
8203 (interactive)
8204 (gnus-article-check-buffer)
8205 (let ((data (get-text-property (point) 'gnus-string)))
8206 (when data
8207 (with-temp-buffer
8208 (insert data)
8209 (copy-region-as-kill (point-min) (point-max))
8210 (message "Copied %s" data)))))
8211
8212 ;;; Internal functions:
8213
8214 (defun gnus-article-set-globals ()
8215 (with-current-buffer gnus-summary-buffer
8216 (gnus-set-global-variables)))
8217
8218 (defun gnus-signature-toggle (end)
8219 (gnus-with-article-buffer
8220 (let ((inhibit-point-motion-hooks t))
8221 (if (text-property-any end (point-max) 'article-type 'signature)
8222 (progn
8223 (gnus-delete-wash-type 'signature)
8224 (gnus-remove-text-properties-when
8225 'article-type 'signature end (point-max)
8226 (cons 'article-type (cons 'signature
8227 gnus-hidden-properties))))
8228 (gnus-add-wash-type 'signature)
8229 (gnus-add-text-properties-when
8230 'article-type nil end (point-max)
8231 (cons 'article-type (cons 'signature
8232 gnus-hidden-properties)))))
8233 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8234 (gnus-set-mode-line 'article))))
8235
8236 (defun gnus-button-push (marker-and-entry)
8237 ;; Push button starting at MARKER.
8238 (save-excursion
8239 (let* ((marker (car marker-and-entry))
8240 (entry (cadr marker-and-entry))
8241 (regexp (car entry))
8242 (inhibit-point-motion-hooks t))
8243 (goto-char marker)
8244 ;; This is obviously true, or something bad is happening :)
8245 ;; But we need it to have the match-data
8246 (when (looking-at (or (if (symbolp regexp)
8247 (symbol-value regexp)
8248 regexp)))
8249 (let ((fun (nth 3 entry))
8250 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8251 (get-char-property marker 'gnus-button-url))
8252 (mapcar (lambda (group)
8253 (let ((string (match-string group)))
8254 (set-text-properties
8255 0 (length string) nil string)
8256 string))
8257 (nthcdr 4 entry)))))
8258
8259 (cond
8260 ((fboundp fun)
8261 (apply fun args))
8262 ((and (boundp fun)
8263 (fboundp (symbol-value fun)))
8264 (apply (symbol-value fun) args))
8265 (t
8266 (gnus-message 1 "You must define `%S' to use this button"
8267 (cons fun args)))))))))
8268
8269 (defun gnus-parse-news-url (url)
8270 (let (scheme server port group message-id articles)
8271 (with-temp-buffer
8272 (insert url)
8273 (goto-char (point-min))
8274 (when (looking-at "\\([A-Za-z]+\\):")
8275 (setq scheme (match-string 1))
8276 (goto-char (match-end 0)))
8277 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8278 (setq server (match-string 1))
8279 (setq port (if (stringp (match-string 3))
8280 (string-to-number (match-string 3))
8281 (match-string 3)))
8282 (goto-char (match-end 0)))
8283
8284 (cond
8285 ((looking-at "\\(.*@.*\\)")
8286 (setq message-id (match-string 1)))
8287 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8288 (setq group (match-string 1)
8289 articles (split-string (match-string 2) "-")))
8290 ((looking-at "\\([^/]+\\)/?")
8291 (setq group (match-string 1)))
8292 (t
8293 (error "Unknown news URL syntax"))))
8294 (list scheme server port group message-id articles)))
8295
8296 (defvar nntp-port-number)
8297
8298 (defun gnus-button-handle-news (url)
8299 "Fetch a news URL."
8300 (destructuring-bind (_scheme server port group message-id _articles)
8301 (gnus-parse-news-url url)
8302 (cond
8303 (message-id
8304 (with-current-buffer gnus-summary-buffer
8305 (if server
8306 (let ((gnus-refer-article-method
8307 (nconc (list (list 'nntp server))
8308 gnus-refer-article-method))
8309 (nntp-port-number (or port "nntp")))
8310 (gnus-message 7 "Fetching %s with %s"
8311 message-id gnus-refer-article-method)
8312 (gnus-summary-refer-article message-id))
8313 (gnus-summary-refer-article message-id))))
8314 (group
8315 (gnus-button-fetch-group url)))))
8316
8317 (defun gnus-button-patch (library line)
8318 "Visit an Emacs Lisp library LIBRARY on line LINE."
8319 (interactive)
8320 (let ((file (locate-library (file-name-nondirectory library))))
8321 (unless file
8322 (error "Couldn't find library %s" library))
8323 (find-file file)
8324 (goto-char (point-min))
8325 (forward-line (1- (string-to-number line)))))
8326
8327 (defun gnus-button-handle-man (url)
8328 "Fetch a man page."
8329 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8330 (when (eq gnus-button-man-handler 'woman)
8331 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8332 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8333 (funcall gnus-button-man-handler url))
8334
8335 (defun gnus-button-handle-info-url (url)
8336 "Fetch an info URL."
8337 (setq url (mm-subst-char-in-string ?+ ?\ url))
8338 (cond
8339 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8340 (gnus-info-find-node
8341 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8342 "Gnus")
8343 ")" (gnus-url-unhex-string (match-string 2 url)))))
8344 ((string-match "([^)\"]+)[^\"]+" url)
8345 (setq url
8346 (gnus-replace-in-string
8347 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8348 (gnus-info-find-node url))
8349 (t (error "Can't parse %s" url))))
8350
8351 (defun gnus-button-handle-info-url-gnome (url)
8352 "Fetch GNOME style info URL."
8353 (setq url (mm-subst-char-in-string ?_ ?\ url))
8354 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8355 (gnus-info-find-node
8356 (concat "("
8357 (gnus-url-unhex-string
8358 (match-string 1 url))
8359 ")"
8360 (or (gnus-url-unhex-string
8361 (match-string 2 url))
8362 "Top")))
8363 (error "Can't parse %s" url)))
8364
8365 (defun gnus-button-handle-info-url-kde (url)
8366 "Fetch KDE style info URL."
8367 (gnus-info-find-node (gnus-url-unhex-string url)))
8368
8369 ;; (info) will autoload info.el
8370 (declare-function Info-menu "info" (menu-item &optional fork))
8371 (declare-function Info-index-next "info" (num))
8372
8373 (defun gnus-button-handle-info-keystrokes (url)
8374 "Call `info' when pushing the corresponding URL button."
8375 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8376 (let (node indx comma)
8377 (if (string-match
8378 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8379 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8380 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8381 "\\(?:[ \t\n,]*\\)\\)?")
8382 url)
8383 (setq node (match-string 2 url)
8384 indx (match-string 3 url))
8385 (error "Can't parse %s" url))
8386 (info)
8387 (Info-directory)
8388 (Info-menu node)
8389 (when (> (length indx) 0)
8390 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8391 "\\([ \t\n,]*\\)")
8392 indx)
8393 (setq comma (match-string 2 indx))
8394 (setq indx (match-string 1 indx))
8395 (Info-index indx)
8396 (when comma
8397 (dotimes (i (with-temp-buffer
8398 (insert comma)
8399 ;; Note: the XEmacs version of `how-many' takes
8400 ;; no optional argument.
8401 (goto-char (point-min))
8402 (how-many ",")))
8403 (Info-index-next 1)))
8404 nil)))
8405
8406 (autoload 'pgg-snarf-keys-region "pgg")
8407 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8408 (declare-function pgg-display-output-buffer "pgg" (start end status))
8409
8410 (defun gnus-button-openpgp (url)
8411 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8412 (with-temp-buffer
8413 (mm-url-insert-file-contents-external url)
8414 (pgg-snarf-keys-region (point-min) (point-max))
8415 (pgg-display-output-buffer nil nil nil)))
8416
8417 (defun gnus-button-message-id (message-id)
8418 "Fetch MESSAGE-ID."
8419 (with-current-buffer gnus-summary-buffer
8420 (gnus-summary-refer-article message-id)))
8421
8422 (defun gnus-button-fetch-group (address &rest _ignore)
8423 "Fetch GROUP specified by ADDRESS."
8424 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8425 address)
8426 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8427 ;; for nntp:// and news://
8428 (setq address (match-string 3 address)))
8429 (if (not (string-match "[:/]" address))
8430 ;; This is just a simple group url.
8431 (gnus-group-read-ephemeral-group address gnus-select-method)
8432 (if (not
8433 (string-match
8434 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8435 address))
8436 (error "Can't parse %s" address)
8437 (gnus-group-read-ephemeral-group
8438 (match-string 4 address)
8439 `(nntp ,(match-string 1 address)
8440 (nntp-address ,(match-string 1 address))
8441 (nntp-port-number ,(if (match-end 3)
8442 (match-string 3 address)
8443 "nntp")))
8444 nil nil nil
8445 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8446
8447 (defun gnus-url-parse-query-string (query &optional downcase)
8448 (let (retval pairs cur key val)
8449 (setq pairs (split-string query "&"))
8450 (while pairs
8451 (setq cur (car pairs)
8452 pairs (cdr pairs))
8453 (if (not (string-match "=" cur))
8454 nil ; Grace
8455 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8456 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8457 (if downcase
8458 (setq key (downcase key)))
8459 (setq cur (assoc key retval))
8460 (if cur
8461 (setcdr cur (cons val (cdr cur)))
8462 (setq retval (cons (list key val) retval)))))
8463 retval))
8464
8465 (defun gnus-url-mailto (url)
8466 ;; Send mail to someone
8467 (setq url (replace-regexp-in-string "\n" " " url))
8468 (when (string-match "mailto:/*\\(.*\\)" url)
8469 (setq url (substring url (match-beginning 1) nil)))
8470 (let* ((args (gnus-url-parse-query-string
8471 (if (string-match "^\\?" url)
8472 (substring url 1)
8473 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8474 (concat "to=" (match-string 1 url) "&"
8475 (match-string 2 url))
8476 (concat "to=" url)))))
8477 (subject (cdr-safe (assoc "subject" args)))
8478 func)
8479 (gnus-msg-mail)
8480 (while args
8481 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8482 (if (fboundp func)
8483 (funcall func)
8484 (message-position-on-field (caar args)))
8485 (insert (gnus-replace-in-string
8486 (mapconcat 'identity (reverse (cdar args)) ", ")
8487 "\r\n" "\n" t))
8488 (setq args (cdr args)))
8489 (if subject
8490 (message-goto-body)
8491 (message-goto-subject))))
8492
8493 (defun gnus-button-embedded-url (address)
8494 "Activate ADDRESS with `browse-url'."
8495 (browse-url (gnus-strip-whitespace address)))
8496
8497 ;;; Next/prev buttons in the article buffer.
8498
8499 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8500 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8501
8502 (defvar gnus-prev-page-map
8503 (let ((map (make-sparse-keymap)))
8504 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8505 (define-key map "\r" 'gnus-button-prev-page)
8506 map))
8507
8508 (defvar gnus-next-page-map
8509 (let ((map (make-sparse-keymap)))
8510 (define-key map gnus-mouse-2 'gnus-button-next-page)
8511 (define-key map "\r" 'gnus-button-next-page)
8512 map))
8513
8514 (defun gnus-insert-prev-page-button ()
8515 (let ((b (point)) e
8516 (inhibit-read-only t))
8517 (gnus-eval-format
8518 gnus-prev-page-line-format nil
8519 `(keymap ,gnus-prev-page-map
8520 gnus-prev t
8521 gnus-callback gnus-article-button-prev-page
8522 article-type annotation))
8523 (setq e (if (bolp)
8524 ;; Exclude a newline.
8525 (1- (point))
8526 (point)))
8527 (when gnus-article-button-face
8528 (overlay-put (make-overlay b e nil t)
8529 'face gnus-article-button-face))
8530 (widget-convert-button
8531 'link b e
8532 :action 'gnus-button-prev-page
8533 :button-keymap gnus-prev-page-map)))
8534
8535 (defun gnus-button-next-page (&optional _args _more-args)
8536 "Go to the next page."
8537 (interactive)
8538 (let ((win (selected-window)))
8539 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8540 (gnus-article-next-page)
8541 (select-window win)))
8542
8543 (defun gnus-button-prev-page (&optional _args _more-args)
8544 "Go to the prev page."
8545 (interactive)
8546 (let ((win (selected-window)))
8547 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8548 (gnus-article-prev-page)
8549 (select-window win)))
8550
8551 (defun gnus-insert-next-page-button ()
8552 (let ((b (point)) e
8553 (inhibit-read-only t))
8554 (gnus-eval-format gnus-next-page-line-format nil
8555 `(keymap ,gnus-next-page-map
8556 gnus-next t
8557 gnus-callback gnus-article-button-next-page
8558 article-type annotation))
8559 (setq e (if (bolp)
8560 ;; Exclude a newline.
8561 (1- (point))
8562 (point)))
8563 (when gnus-article-button-face
8564 (overlay-put (make-overlay b e nil t)
8565 'face gnus-article-button-face))
8566 (widget-convert-button
8567 'link b e
8568 :action 'gnus-button-next-page
8569 :button-keymap gnus-next-page-map)))
8570
8571 (defun gnus-article-button-next-page (_arg)
8572 "Go to the next page."
8573 (interactive "P")
8574 (let ((win (selected-window)))
8575 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8576 (gnus-article-next-page)
8577 (select-window win)))
8578
8579 (defun gnus-article-button-prev-page (_arg)
8580 "Go to the prev page."
8581 (interactive "P")
8582 (let ((win (selected-window)))
8583 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8584 (gnus-article-prev-page)
8585 (select-window win)))
8586
8587 (defvar gnus-decode-header-methods
8588 '(mail-decode-encoded-word-region)
8589 "List of methods used to decode headers.
8590
8591 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8592 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8593 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8594 whose names match REGEXP.
8595
8596 For example:
8597 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8598 mail-decode-encoded-word-region
8599 (\"chinese\" . rfc1843-decode-region))
8600 ")
8601
8602 (defvar gnus-decode-header-methods-cache nil)
8603
8604 (defun gnus-multi-decode-header (start end)
8605 "Apply the functions from `gnus-encoded-word-methods' that match."
8606 (unless (and gnus-decode-header-methods-cache
8607 (eq gnus-newsgroup-name
8608 (car gnus-decode-header-methods-cache)))
8609 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8610 (dolist (x gnus-decode-header-methods)
8611 (if (symbolp x)
8612 (nconc gnus-decode-header-methods-cache (list x))
8613 (if (and gnus-newsgroup-name
8614 (string-match (car x) gnus-newsgroup-name))
8615 (nconc gnus-decode-header-methods-cache
8616 (list (cdr x)))))))
8617 (let ((xlist gnus-decode-header-methods-cache))
8618 (pop xlist)
8619 (save-restriction
8620 (narrow-to-region start end)
8621 (while xlist
8622 (funcall (pop xlist) (point-min) (point-max))))))
8623
8624 ;;;
8625 ;;; Treatment top-level handling.
8626 ;;;
8627
8628 (defvar gnus-inhibit-article-treatments nil)
8629
8630 ;; Dynamic variables.
8631 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8632 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8633 (defvar gnus-treat-type)
8634 (defvar gnus-treat-condition)
8635 (defvar gnus-treat-length)
8636
8637 (defun gnus-treat-article (condition
8638 &optional part-num total type)
8639 (let ((gnus-treat-condition condition)
8640 (part-number part-num)
8641 (total-parts total)
8642 (gnus-treat-type type)
8643 (gnus-treat-length (- (point-max) (point-min)))
8644 (alist gnus-treatment-function-alist)
8645 (article-goto-body-goes-to-point-min-p t)
8646 (treated-type
8647 (or (not type)
8648 (catch 'found
8649 (let ((list gnus-article-treat-types))
8650 (while list
8651 (when (string-match (pop list) type)
8652 (throw 'found t)))))))
8653 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8654 val)
8655 (gnus-run-hooks 'gnus-part-display-hook)
8656 (dolist (elem alist)
8657 (setq val
8658 (save-excursion
8659 (when (gnus-buffer-live-p gnus-summary-buffer)
8660 (set-buffer gnus-summary-buffer))
8661 (symbol-value (car elem))))
8662 (when (and (or (consp val)
8663 treated-type)
8664 (or (not gnus-inhibit-article-treatments)
8665 (eq gnus-treat-condition 'head))
8666 (gnus-treat-predicate val)
8667 (or (not (get (car elem) 'highlight))
8668 highlightp))
8669 (save-restriction
8670 (funcall (cadr elem)))))))
8671
8672 (defun gnus-treat-predicate (val)
8673 (cond
8674 ((null val)
8675 nil)
8676 (gnus-treat-condition
8677 (eq gnus-treat-condition val))
8678 ((and (listp val)
8679 (stringp (car val)))
8680 (apply 'gnus-or (mapcar `(lambda (s)
8681 (string-match s ,(or gnus-newsgroup-name "")))
8682 val)))
8683 ((listp val)
8684 (let ((pred (pop val)))
8685 (cond
8686 ((eq pred 'or)
8687 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8688 ((eq pred 'and)
8689 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8690 ((eq pred 'not)
8691 (not (gnus-treat-predicate (car val))))
8692 ((eq pred 'typep)
8693 (equal (car val) gnus-treat-type))
8694 ((functionp pred)
8695 (funcall pred))
8696 (t
8697 (error "%S is not a valid predicate" pred)))))
8698 ((eq val t)
8699 t)
8700 ((eq val 'head)
8701 nil)
8702 ((eq val 'first)
8703 (eq part-number 1))
8704 ((eq val 'last)
8705 (eq part-number total-parts))
8706 ((numberp val)
8707 (< gnus-treat-length val))
8708 (t
8709 (error "%S is not a valid value" val))))
8710
8711 (defun gnus-article-encrypt-body (protocol &optional n)
8712 "Encrypt the article body."
8713 (interactive
8714 (list
8715 (or gnus-article-encrypt-protocol
8716 (gnus-completing-read "Encrypt protocol"
8717 (mapcar 'car gnus-article-encrypt-protocol-alist)
8718 t))
8719 current-prefix-arg))
8720 ;; User might hit `K E' instead of `K e', so prompt once.
8721 (when (and gnus-article-encrypt-protocol
8722 gnus-novice-user)
8723 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8724 (error "Encrypt aborted")))
8725 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8726 (unless func
8727 (error "Can't find the encrypt protocol %s" protocol))
8728 (if (member gnus-newsgroup-name '("nndraft:delayed"
8729 "nndraft:drafts"
8730 "nndraft:queue"))
8731 (error "Can't encrypt the article in group %s"
8732 gnus-newsgroup-name))
8733 (gnus-summary-iterate n
8734 (with-current-buffer gnus-summary-buffer
8735 (let ((mail-parse-charset gnus-newsgroup-charset)
8736 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8737 (summary-buffer gnus-summary-buffer)
8738 references point)
8739 (gnus-set-global-variables)
8740 (when (gnus-group-read-only-p)
8741 (error "The current newsgroup does not support article encrypt"))
8742 (gnus-summary-show-article t)
8743 (setq references
8744 (or (mail-header-references gnus-current-headers) ""))
8745 (set-buffer gnus-article-buffer)
8746 (let* ((inhibit-read-only t)
8747 (headers
8748 (mapcar (lambda (field)
8749 (and (save-restriction
8750 (message-narrow-to-head)
8751 (goto-char (point-min))
8752 (search-forward field nil t))
8753 (prog2
8754 (message-narrow-to-field)
8755 (buffer-string)
8756 (delete-region (point-min) (point-max))
8757 (widen))))
8758 '("Content-Type:" "Content-Transfer-Encoding:"
8759 "Content-Disposition:"))))
8760 (message-narrow-to-head)
8761 (message-remove-header "MIME-Version")
8762 (goto-char (point-max))
8763 (setq point (point))
8764 (insert (apply 'concat headers))
8765 (widen)
8766 (narrow-to-region point (point-max))
8767 (let ((message-options message-options))
8768 (message-options-set 'message-sender user-mail-address)
8769 (message-options-set 'message-recipients user-mail-address)
8770 (message-options-set 'message-sign-encrypt 'not)
8771 (funcall func))
8772 (goto-char (point-min))
8773 (insert "MIME-Version: 1.0\n")
8774 (widen)
8775 (gnus-summary-edit-article-done
8776 references nil summary-buffer t))
8777 (when gnus-keep-backlog
8778 (gnus-backlog-remove-article
8779 (car gnus-article-current) (cdr gnus-article-current)))
8780 (gnus-flush-original-article-buffer)
8781 (when gnus-use-cache
8782 (gnus-cache-update-article
8783 (car gnus-article-current) (cdr gnus-article-current))))))))
8784
8785 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8786 "The following specs can be used:
8787 %t The security MIME type
8788 %i Additional info
8789 %d Details
8790 %D Details if button is pressed")
8791
8792 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8793 "The following specs can be used:
8794 %t The security MIME type
8795 %i Additional info
8796 %d Details
8797 %D Details if button is pressed")
8798
8799 (defvar gnus-mime-security-button-line-format-alist
8800 '((?t gnus-tmp-type ?s)
8801 (?i gnus-tmp-info ?s)
8802 (?d gnus-tmp-details ?s)
8803 (?D gnus-tmp-pressed-details ?s)))
8804
8805 (defvar gnus-mime-security-button-commands
8806 '((gnus-article-press-button "\r" "Show Detail")
8807 (undefined "v")
8808 (undefined "t")
8809 (undefined "C")
8810 (gnus-mime-security-save-part "o" "Save...")
8811 (undefined "\C-o")
8812 (undefined "r")
8813 (undefined "d")
8814 (undefined "c")
8815 (undefined "i")
8816 (undefined "E")
8817 (undefined "e")
8818 (undefined "p")
8819 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8820 (undefined ".")))
8821
8822 (defvar gnus-mime-security-button-map
8823 (let ((map (make-sparse-keymap)))
8824 (define-key map gnus-mouse-2 'gnus-article-push-button)
8825 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8826 (dolist (c gnus-mime-security-button-commands)
8827 (define-key map (cadr c) (car c)))
8828 map))
8829
8830 (easy-menu-define
8831 gnus-mime-security-button-menu gnus-mime-security-button-map
8832 "Security button menu."
8833 `("Security Part"
8834 ,@(delq nil
8835 (mapcar (lambda (c)
8836 (unless (eq (car c) 'undefined)
8837 (vector (caddr c) (car c) :active t)))
8838 gnus-mime-security-button-commands))))
8839
8840 (defun gnus-mime-security-button-menu (event prefix)
8841 "Construct a context-sensitive menu of security commands."
8842 (interactive "e\nP")
8843 (save-window-excursion
8844 (let ((pos (event-start event)))
8845 (select-window (posn-window pos))
8846 (goto-char (posn-point pos))
8847 (gnus-article-check-buffer)
8848 (popup-menu gnus-mime-security-button-menu nil prefix))))
8849
8850 (defvar gnus-mime-security-details-buffer nil)
8851
8852 (defvar gnus-mime-security-button-pressed nil)
8853
8854 (defvar gnus-mime-security-show-details-inline t
8855 "If non-nil, show details in the article buffer.")
8856
8857 (defun gnus-mime-security-verify-or-decrypt (handle)
8858 (mm-remove-parts (cdr handle))
8859 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8860 point (inhibit-read-only t))
8861 (if region
8862 (goto-char (car region)))
8863 (setq point (point))
8864 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8865 (let* ((mm-verify-option 'known)
8866 (mm-decrypt-option 'known)
8867 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8868 (unless (eq nparts (cdr handle))
8869 (mm-destroy-parts (cdr handle))
8870 (setcdr handle nparts))))
8871 (gnus-mime-display-security handle)
8872 (when region
8873 (delete-region (point) (cdr region))
8874 (set-marker (car region) nil)
8875 (set-marker (cdr region) nil))
8876 (goto-char point)))
8877
8878 (defun gnus-mime-security-show-details (handle)
8879 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8880 (if (not details)
8881 (gnus-message 5 "No details.")
8882 (if gnus-mime-security-show-details-inline
8883 (let ((gnus-mime-security-button-pressed
8884 (not (get-text-property (point) 'gnus-mime-details)))
8885 (gnus-mime-security-button-line-format
8886 (get-text-property (point) 'gnus-line-format))
8887 (inhibit-read-only t))
8888 (forward-char -1)
8889 (while (eq (get-text-property (point) 'gnus-line-format)
8890 gnus-mime-security-button-line-format)
8891 (forward-char -1))
8892 (forward-char)
8893 (save-restriction
8894 (narrow-to-region (point) (point))
8895 (gnus-insert-mime-security-button handle))
8896 (delete-region (point)
8897 (or (text-property-not-all
8898 (point) (point-max)
8899 'gnus-line-format
8900 gnus-mime-security-button-line-format)
8901 (point-max))))
8902 ;; Not inlined.
8903 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8904 (with-current-buffer gnus-mime-security-details-buffer
8905 (erase-buffer)
8906 t)
8907 (setq gnus-mime-security-details-buffer
8908 (gnus-get-buffer-create "*MIME Security Details*")))
8909 (with-current-buffer gnus-mime-security-details-buffer
8910 (insert details)
8911 (goto-char (point-min)))
8912 (pop-to-buffer gnus-mime-security-details-buffer)))))
8913
8914 (defun gnus-mime-security-press-button (handle)
8915 (save-excursion
8916 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8917 (gnus-mime-security-show-details handle)
8918 (gnus-mime-security-verify-or-decrypt handle))))
8919
8920 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8921 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8922 (gnus-tmp-type
8923 (concat
8924 (or (nth 2 (assoc protocol mm-verify-function-alist))
8925 (nth 2 (assoc protocol mm-decrypt-function-alist))
8926 "Unknown")
8927 (if (equal (car handle) "multipart/signed")
8928 " Signed" " Encrypted")
8929 " Part"))
8930 (gnus-tmp-info
8931 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8932 "Undecided"))
8933 (gnus-tmp-details
8934 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8935 gnus-tmp-pressed-details
8936 b e)
8937 (setq gnus-tmp-details
8938 (if gnus-tmp-details
8939 (concat "\n" gnus-tmp-details)
8940 ""))
8941 (setq gnus-tmp-pressed-details
8942 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8943 (unless (bolp)
8944 (insert "\n"))
8945 (setq b (point))
8946 (gnus-eval-format
8947 gnus-mime-security-button-line-format
8948 gnus-mime-security-button-line-format-alist
8949 `(keymap ,gnus-mime-security-button-map
8950 gnus-callback gnus-mime-security-press-button
8951 gnus-line-format ,gnus-mime-security-button-line-format
8952 gnus-mime-details ,gnus-mime-security-button-pressed
8953 article-type annotation
8954 gnus-data ,handle))
8955 (setq e (if (bolp)
8956 ;; Exclude a newline.
8957 (1- (point))
8958 (point)))
8959 (when gnus-article-button-face
8960 (overlay-put (make-overlay b e nil t)
8961 'face gnus-article-button-face))
8962 (widget-convert-button
8963 'link b e
8964 :mime-handle handle
8965 :action 'gnus-widget-press-button
8966 :button-keymap gnus-mime-security-button-map
8967 :help-echo
8968 (lambda (_widget)
8969 ;; Needed to properly clear the message due to a bug in
8970 ;; wid-edit (XEmacs only).
8971 (when (boundp 'help-echo-owns-message)
8972 (setq help-echo-owns-message t))
8973 (format
8974 "%S: show detail; %S: more options"
8975 (aref gnus-mouse-2 0)
8976 (aref gnus-down-mouse-3 0))))))
8977
8978 (defun gnus-mime-display-security (handle)
8979 (save-restriction
8980 (narrow-to-region (point) (point))
8981 (unless (gnus-unbuttonized-mime-type-p (car handle))
8982 (gnus-insert-mime-security-button handle))
8983 (gnus-mime-display-part (cadr handle))
8984 (unless (bolp)
8985 (insert "\n"))
8986 (unless (gnus-unbuttonized-mime-type-p (car handle))
8987 (let ((gnus-mime-security-button-line-format
8988 gnus-mime-security-button-end-line-format))
8989 (gnus-insert-mime-security-button handle)))
8990 (mm-set-handle-multipart-parameter
8991 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8992 (goto-char (point-max))))
8993
8994 (defun gnus-mime-security-run-function (function)
8995 "Run FUNCTION with the security part under point."
8996 (gnus-article-check-buffer)
8997 (let ((data (get-text-property (point) 'gnus-data))
8998 buffer handle)
8999 (when (and (stringp (car-safe data))
9000 (setq buffer (mm-handle-multipart-original-buffer data))
9001 (setq handle (cadr data)))
9002 (if (bufferp (mm-handle-buffer handle))
9003 (progn
9004 (setq handle (cons buffer (copy-sequence (cdr handle))))
9005 (mm-handle-set-undisplayer handle nil))
9006 (setq handle (mm-make-handle
9007 buffer
9008 (mm-handle-multipart-ctl-parameter handle 'protocol)
9009 nil nil nil nil nil nil)))
9010 (funcall function handle))))
9011
9012 (defun gnus-mime-security-save-part ()
9013 "Save the security part under point."
9014 (interactive)
9015 (gnus-mime-security-run-function 'mm-save-part))
9016
9017 (defun gnus-mime-security-pipe-part ()
9018 "Pipe the security part under point to a process."
9019 (interactive)
9020 (gnus-mime-security-run-function 'mm-pipe-part))
9021
9022 (gnus-ems-redefine)
9023
9024 (provide 'gnus-art)
9025
9026 (run-hooks 'gnus-art-load-hook)
9027
9028 ;;; gnus-art.el ends here