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