]> 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 (gnus-image-type-available-p 'pbm)
270 'gnus-display-x-face-in-from
271 "{ echo \
272 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
273 ; uncompface; } | icontopbm | display -")
274 "*String or function to be executed to display an X-Face header.
275 If it is a string, the command will be executed in a sub-shell
276 asynchronously. The compressed face will be piped to this command."
277 :type `(choice string
278 (function-item gnus-display-x-face-in-from)
279 function)
280 :version "21.1"
281 :group 'gnus-picon
282 :group 'gnus-article-washing)
283
284 (defcustom gnus-article-x-face-too-ugly nil
285 "Regexp matching posters whose face shouldn't be shown automatically."
286 :type '(choice regexp (const nil))
287 :group 'gnus-article-washing)
288
289 (defcustom gnus-article-banner-alist nil
290 "Banner alist for stripping.
291 For example,
292 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
293 :version "21.1"
294 :type '(repeat (cons symbol regexp))
295 :group 'gnus-article-washing)
296
297 (gnus-define-group-parameter
298 banner
299 :variable-document
300 "Alist of regexps (to match group names) and banner."
301 :variable-group gnus-article-washing
302 :parameter-type
303 '(choice :tag "Banner"
304 :value nil
305 (const :tag "Remove signature" signature)
306 (symbol :tag "Item in `gnus-article-banner-alist'" none)
307 regexp
308 (const :tag "None" nil))
309 :parameter-document
310 "If non-nil, specify how to remove `banners' from articles.
311
312 Symbol `signature' means to remove signatures delimited by
313 `gnus-signature-separator'. Any other symbol is used to look up a
314 regular expression to match the banner in `gnus-article-banner-alist'.
315 A string is used as a regular expression to match the banner
316 directly.")
317
318 (defcustom gnus-article-address-banner-alist nil
319 "Alist of mail addresses and banners.
320 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
321 to match a mail address in the From: header, BANNER is one of a symbol
322 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
323 If ADDRESS matches author's mail address, it will remove things like
324 advertisements. For example:
325
326 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
327 "
328 :type '(repeat
329 (cons
330 (regexp :tag "Address")
331 (choice :tag "Banner" :value nil
332 (const :tag "Remove signature" signature)
333 (symbol :tag "Item in `gnus-article-banner-alist'" none)
334 regexp
335 (const :tag "None" nil))))
336 :version "22.1"
337 :group 'gnus-article-washing)
338
339 (defmacro gnus-emphasis-custom-with-format (&rest body)
340 `(let ((format "\
341 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
342 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
343 ,@body))
344
345 (defun gnus-emphasis-custom-value-to-external (value)
346 (gnus-emphasis-custom-with-format
347 (if (consp (car value))
348 (list (format format (car (car value)) (cdr (car value)))
349 2
350 (if (nth 1 value) 2 3)
351 (nth 2 value))
352 value)))
353
354 (defun gnus-emphasis-custom-value-to-internal (value)
355 (gnus-emphasis-custom-with-format
356 (let ((regexp (concat "\\`"
357 (format (regexp-quote format)
358 "\\([^()]+\\)" "\\([^()]+\\)")
359 "\\'"))
360 pattern)
361 (if (string-match regexp (setq pattern (car value)))
362 (list (cons (match-string 1 pattern) (match-string 2 pattern))
363 (= (nth 2 value) 2)
364 (nth 3 value))
365 value))))
366
367 (defcustom gnus-emphasis-alist
368 (let ((types
369 '(("\\*" "\\*" bold nil 2)
370 ("_" "_" underline)
371 ("/" "/" italic)
372 ("_/" "/_" underline-italic)
373 ("_\\*" "\\*_" underline-bold)
374 ("\\*/" "/\\*" bold-italic)
375 ("_\\*/" "/\\*_" underline-bold-italic))))
376 (nconc
377 (gnus-emphasis-custom-with-format
378 (mapcar (lambda (spec)
379 (list (format format (car spec) (cadr spec))
380 (or (nth 3 spec) 2)
381 (or (nth 4 spec) 3)
382 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
383 types))
384 '(;; I've never seen anyone use this strikethru convention whereas I've
385 ;; several times seen it triggered by normal text. --Stef
386 ;; Miles suggests that this form is sometimes used but for italics,
387 ;; so maybe we should map it to `italic'.
388 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
389 ;; 2 3 gnus-emphasis-strikethru)
390 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
391 2 3 gnus-emphasis-underline))))
392 "*Alist that says how to fontify certain phrases.
393 Each item looks like this:
394
395 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
396
397 The first element is a regular expression to be matched. The second
398 is a number that says what regular expression grouping used to find
399 the entire emphasized word. The third is a number that says what
400 regexp grouping should be displayed and highlighted. The fourth
401 is the face used for highlighting."
402 :type
403 '(repeat
404 (menu-choice
405 :format "%[Customizing Style%]\n%v"
406 :indent 2
407 (group :tag "Default"
408 :value ("" 0 0 default)
409 :value-create
410 (lambda (widget)
411 (let ((value (widget-get
412 (cadr (widget-get (widget-get widget :parent)
413 :args))
414 :value)))
415 (if (not (eq (nth 2 value) 'default))
416 (widget-put
417 widget
418 :value
419 (gnus-emphasis-custom-value-to-external value))))
420 (widget-group-value-create widget))
421 regexp
422 (integer :format "Match group: %v")
423 (integer :format "Emphasize group: %v")
424 face)
425 (group :tag "Simple"
426 :value (("_" . "_") nil default)
427 (cons :format "%v"
428 (regexp :format "Start regexp: %v")
429 (regexp :format "End regexp: %v"))
430 (boolean :format "Show start and end patterns: %[%v%]\n"
431 :on " On " :off " Off ")
432 face)))
433 :get (lambda (symbol)
434 (mapcar 'gnus-emphasis-custom-value-to-internal
435 (default-value symbol)))
436 :set (lambda (symbol value)
437 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
438 value)))
439 :group 'gnus-article-emphasis)
440
441 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
442 "A regexp to describe whitespace which should not be emphasized.
443 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
444 The former avoids underlining of leading and trailing whitespace,
445 and the latter avoids underlining any whitespace at all."
446 :version "21.1"
447 :group 'gnus-article-emphasis
448 :type 'regexp)
449
450 (defface gnus-emphasis-bold '((t (:bold t)))
451 "Face used for displaying strong emphasized text (*word*)."
452 :group 'gnus-article-emphasis)
453
454 (defface gnus-emphasis-italic '((t (:italic t)))
455 "Face used for displaying italic emphasized text (/word/)."
456 :group 'gnus-article-emphasis)
457
458 (defface gnus-emphasis-underline '((t (:underline t)))
459 "Face used for displaying underlined emphasized text (_word_)."
460 :group 'gnus-article-emphasis)
461
462 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
463 "Face used for displaying underlined bold emphasized text (_*word*_)."
464 :group 'gnus-article-emphasis)
465
466 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
467 "Face used for displaying underlined italic emphasized text (_/word/_)."
468 :group 'gnus-article-emphasis)
469
470 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
471 "Face used for displaying bold italic emphasized text (/*word*/)."
472 :group 'gnus-article-emphasis)
473
474 (defface gnus-emphasis-underline-bold-italic
475 '((t (:bold t :italic t :underline t)))
476 "Face used for displaying underlined bold italic emphasized text.
477 Example: (_/*word*/_)."
478 :group 'gnus-article-emphasis)
479
480 (defface gnus-emphasis-strikethru '((t (:strike-through t)))
481 "Face used for displaying strike-through text (-word-)."
482 :group 'gnus-article-emphasis)
483
484 (defface gnus-emphasis-highlight-words
485 '((t (:background "black" :foreground "yellow")))
486 "Face used for displaying highlighted words."
487 :group 'gnus-article-emphasis)
488
489 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
490 "Format for display of Date headers in article bodies.
491 See `format-time-string' for the possible values.
492
493 The variable can also be function, which should return a complete Date
494 header. The function is called with one argument, the time, which can
495 be fed to `format-time-string'."
496 :type '(choice string function)
497 :link '(custom-manual "(gnus)Article Date")
498 :group 'gnus-article-washing)
499
500 (defcustom gnus-save-all-headers t
501 "*If non-nil, don't remove any headers before saving.
502 This will be overridden by the `:headers' property that the symbol of
503 the saver function, which is specified by `gnus-default-article-saver',
504 might have."
505 :group 'gnus-article-saving
506 :type 'boolean)
507
508 (defcustom gnus-prompt-before-saving 'always
509 "*This variable says how much prompting is to be done when saving articles.
510 If it is nil, no prompting will be done, and the articles will be
511 saved to the default files. If this variable is `always', each and
512 every article that is saved will be preceded by a prompt, even when
513 saving large batches of articles. If this variable is neither nil not
514 `always', there the user will be prompted once for a file name for
515 each invocation of the saving commands."
516 :group 'gnus-article-saving
517 :type '(choice (item always)
518 (item :tag "never" nil)
519 (sexp :tag "once" :format "%t\n" :value t)))
520
521 (defcustom gnus-article-show-cursor nil
522 "If non-nil, show the cursor in the Article buffer even when not selected."
523 :version "25.1"
524 :group 'gnus-article
525 :type 'bool)
526
527 (defcustom gnus-saved-headers gnus-visible-headers
528 "Headers to keep if `gnus-save-all-headers' is nil.
529 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
530 If that variable is nil, however, all headers that match this regexp
531 will be kept while the rest will be deleted before saving. This and
532 `gnus-save-all-headers' will be overridden by the `:headers' property
533 that the symbol of the saver function, which is specified by
534 `gnus-default-article-saver', might have."
535 :group 'gnus-article-saving
536 :type 'regexp)
537
538 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
539 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
540 "A function to save articles in your favorite format.
541 The function will be called by way of the `gnus-summary-save-article'
542 command, and friends such as `gnus-summary-save-article-rmail'.
543
544 Gnus provides the following functions:
545
546 * gnus-summary-save-in-rmail (Rmail format)
547 * gnus-summary-save-in-mail (Unix mail format)
548 * gnus-summary-save-in-folder (MH folder)
549 * gnus-summary-save-in-file (article format)
550 * gnus-summary-save-body-in-file (article body)
551 * gnus-summary-save-in-vm (use VM's folder format)
552 * gnus-summary-write-to-file (article format -- overwrite)
553 * gnus-summary-write-body-to-file (article body -- overwrite)
554 * gnus-summary-save-in-pipe (article format)
555
556 The symbol of each function may have the following properties:
557
558 * :decode
559 The value non-nil means save decoded articles. This is meaningful
560 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
561 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
562 `gnus-summary-save-in-pipe'.
563
564 * :function
565 The value specifies an alternative function which appends, not
566 overwrites, articles to a file. This implies that when saving many
567 articles at a time, `gnus-prompt-before-saving' is bound to t and all
568 articles are saved in a single file. This is meaningful only with
569 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
570
571 * :headers
572 The value specifies the symbol of a variable of which the value
573 specifies headers to be saved. If it is omitted,
574 `gnus-save-all-headers' and `gnus-saved-headers' control what
575 headers should be saved."
576 :group 'gnus-article-saving
577 :type '(radio (function-item gnus-summary-save-in-rmail)
578 (function-item gnus-summary-save-in-mail)
579 (function-item gnus-summary-save-in-folder)
580 (function-item gnus-summary-save-in-file)
581 (function-item gnus-summary-save-body-in-file)
582 (function-item gnus-summary-save-in-vm)
583 (function-item gnus-summary-write-to-file)
584 (function-item gnus-summary-write-body-to-file)
585 (function-item gnus-summary-save-in-pipe)
586 (function)))
587
588 (defcustom gnus-article-save-coding-system
589 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
590 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
591 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
592 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
593 "Coding system used to save decoded articles to a file.
594
595 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
596 which can safely encode any characters in text. This is used by the
597 commands including:
598
599 * gnus-summary-save-article-file
600 * gnus-summary-save-article-body-file
601 * gnus-summary-write-article-file
602 * gnus-summary-write-article-body-file
603
604 and the functions to which you may set `gnus-default-article-saver':
605
606 * gnus-summary-save-in-file
607 * gnus-summary-save-body-in-file
608 * gnus-summary-write-to-file
609 * gnus-summary-write-body-to-file
610
611 Those commands and functions save just text displayed in the article
612 buffer to a file if the value of this variable is non-nil. Note that
613 buttonized MIME parts will be lost in a saved file in that case.
614 Otherwise, raw articles will be saved."
615 :group 'gnus-article-saving
616 :type `(choice
617 :format "%{%t%}:\n %[Value Menu%] %v"
618 (const :tag "Save raw articles" nil)
619 ,@(delq nil
620 (mapcar
621 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
622 '((const :tag "UTF-8" utf-8)
623 (const :tag "iso-2022-7bit" iso-2022-7bit)
624 (const :tag "Emacs internal" emacs-mule)
625 (const :tag "escape-quoted" escape-quoted))))
626 (symbol :tag "Coding system")))
627
628 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
629 "A function generating a file name to save articles in Rmail format.
630 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
631 :group 'gnus-article-saving
632 :type 'function)
633
634 (defcustom gnus-mail-save-name 'gnus-plain-save-name
635 "A function generating a file name to save articles in Unix mail format.
636 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
637 :group 'gnus-article-saving
638 :type 'function)
639
640 (defcustom gnus-folder-save-name 'gnus-folder-save-name
641 "A function generating a file name to save articles in MH folder.
642 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
643 :group 'gnus-article-saving
644 :type 'function)
645
646 (defcustom gnus-file-save-name 'gnus-numeric-save-name
647 "A function generating a file name to save articles in article format.
648 The function is called with NEWSGROUP, HEADERS, and optional
649 LAST-FILE."
650 :group 'gnus-article-saving
651 :type 'function)
652
653 (defcustom gnus-split-methods
654 '((gnus-article-archive-name)
655 (gnus-article-nndoc-name))
656 "*Variable used to suggest where articles are to be saved.
657 For instance, if you would like to save articles related to Gnus in
658 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
659 you could set this variable to something like:
660
661 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
662 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
663
664 This variable is an alist where the key is the match and the
665 value is a list of possible files to save in if the match is
666 non-nil.
667
668 If the match is a string, it is used as a regexp match on the
669 article. If the match is a symbol, that symbol will be funcalled
670 from the buffer of the article to be saved with the newsgroup as the
671 parameter. If it is a list, it will be evalled in the same buffer.
672
673 If this form or function returns a string, this string will be used as a
674 possible file name; and if it returns a non-nil list, that list will be
675 used as possible file names."
676 :group 'gnus-article-saving
677 :type '(repeat (choice (list :value (fun) function)
678 (cons :value ("" "") regexp (repeat string))
679 (sexp :value nil))))
680
681 (defcustom gnus-page-delimiter "^\^L"
682 "*Regexp describing what to use as article page delimiters.
683 The default value is \"^\^L\", which is a form linefeed at the
684 beginning of a line."
685 :type 'regexp
686 :group 'gnus-article-various)
687
688 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
689 "*The format specification for the article mode line.
690 See `gnus-summary-mode-line-format' for a closer description.
691
692 The following additional specs are available:
693
694 %w The article washing status.
695 %m The number of MIME parts in the article."
696 :version "24.1"
697 :type 'string
698 :group 'gnus-article-various)
699
700 (defcustom gnus-article-mode-hook nil
701 "*A hook for Gnus article mode."
702 :type 'hook
703 :group 'gnus-article-various)
704
705 (defcustom gnus-article-menu-hook nil
706 "*Hook run after the creation of the article mode menu."
707 :type 'hook
708 :group 'gnus-article-various)
709
710 (defcustom gnus-article-prepare-hook nil
711 "*A hook called after an article has been prepared in the article buffer."
712 :type 'hook
713 :group 'gnus-article-various)
714
715 (defcustom gnus-copy-article-ignored-headers nil
716 "List of headers to be removed when copying an article.
717 Each element is a regular expression."
718 :version "23.1" ;; No Gnus
719 :type '(repeat regexp)
720 :group 'gnus-article-various)
721
722 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
723 "Gnus 5.10 (Emacs 22.1)")
724
725 (defface gnus-button
726 '((t (:weight bold)))
727 "Face used for highlighting a button in the article buffer."
728 :group 'gnus-article-buttons)
729
730 (defcustom gnus-article-button-face 'gnus-button
731 "Face used for highlighting buttons in the article buffer.
732
733 An article button is a piece of text that you can activate by pressing
734 `RET' or `mouse-2' above it."
735 :type 'face
736 :group 'gnus-article-buttons)
737
738 (defcustom gnus-article-mouse-face 'highlight
739 "Face used for mouse highlighting in the article buffer.
740
741 Article buttons will be displayed in this face when the cursor is
742 above them."
743 :type 'face
744 :group 'gnus-article-buttons)
745
746 (defcustom gnus-signature-face 'gnus-signature
747 "Face used for highlighting a signature in the article buffer.
748 Obsolete; use the face `gnus-signature' for customizations instead."
749 :type 'face
750 :group 'gnus-article-highlight
751 :group 'gnus-article-signature)
752
753 (defface gnus-signature
754 '((t
755 (:italic t)))
756 "Face used for highlighting a signature in the article buffer."
757 :group 'gnus-article-highlight
758 :group 'gnus-article-signature)
759 ;; backward-compatibility alias
760 (put 'gnus-signature-face 'face-alias 'gnus-signature)
761 (put 'gnus-signature-face 'obsolete-face "22.1")
762
763 (defface gnus-header-from
764 '((((class color)
765 (background dark))
766 (:foreground "PaleGreen1"))
767 (((class color)
768 (background light))
769 (:foreground "red3"))
770 (t
771 (:italic t)))
772 "Face used for displaying from headers."
773 :group 'gnus-article-headers
774 :group 'gnus-article-highlight)
775 ;; backward-compatibility alias
776 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
777 (put 'gnus-header-from-face 'obsolete-face "22.1")
778
779 (defface gnus-header-subject
780 '((((class color)
781 (background dark))
782 (:foreground "SeaGreen1"))
783 (((class color)
784 (background light))
785 (:foreground "red4"))
786 (t
787 (:bold t :italic t)))
788 "Face used for displaying subject headers."
789 :group 'gnus-article-headers
790 :group 'gnus-article-highlight)
791 ;; backward-compatibility alias
792 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
793 (put 'gnus-header-subject-face 'obsolete-face "22.1")
794
795 (defface gnus-header-newsgroups
796 '((((class color)
797 (background dark))
798 (:foreground "yellow" :italic t))
799 (((class color)
800 (background light))
801 (:foreground "MidnightBlue" :italic t))
802 (t
803 (:italic t)))
804 "Face used for displaying newsgroups headers.
805 In the default setup this face is only used for crossposted
806 articles."
807 :group 'gnus-article-headers
808 :group 'gnus-article-highlight)
809 ;; backward-compatibility alias
810 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
811 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
812
813 (defface gnus-header-name
814 '((((class color)
815 (background dark))
816 (:foreground "SpringGreen2"))
817 (((class color)
818 (background light))
819 (:foreground "maroon"))
820 (t
821 (:bold t)))
822 "Face used for displaying header names."
823 :group 'gnus-article-headers
824 :group 'gnus-article-highlight)
825 ;; backward-compatibility alias
826 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
827 (put 'gnus-header-name-face 'obsolete-face "22.1")
828
829 (defface gnus-header-content
830 '((((class color)
831 (background dark))
832 (:foreground "SpringGreen1" :italic t))
833 (((class color)
834 (background light))
835 (:foreground "indianred4" :italic t))
836 (t
837 (:italic t))) "Face used for displaying header content."
838 :group 'gnus-article-headers
839 :group 'gnus-article-highlight)
840 ;; backward-compatibility alias
841 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
842 (put 'gnus-header-content-face 'obsolete-face "22.1")
843
844 (defcustom gnus-header-face-alist
845 '(("From" nil gnus-header-from)
846 ("Subject" nil gnus-header-subject)
847 ("Newsgroups:.*," nil gnus-header-newsgroups)
848 ("" gnus-header-name gnus-header-content))
849 "*Controls highlighting of article headers.
850
851 An alist of the form (HEADER NAME CONTENT).
852
853 HEADER is a regular expression which should match the name of a
854 header and NAME and CONTENT are either face names or nil.
855
856 The name of each header field will be displayed using the face
857 specified by the first element in the list where HEADER matches
858 the header name and NAME is non-nil. Similarly, the content will
859 be displayed by the first non-nil matching CONTENT face."
860 :group 'gnus-article-headers
861 :group 'gnus-article-highlight
862 :type '(repeat (list (regexp :tag "Header")
863 (choice :tag "Name"
864 (item :tag "skip" nil)
865 (face :value default))
866 (choice :tag "Content"
867 (item :tag "skip" nil)
868 (face :value default)))))
869
870 (defcustom gnus-face-properties-alist '((pbm . (:face gnus-x-face))
871 (png . nil))
872 "Alist of image types and properties applied to Face and X-Face images.
873 Here are examples:
874
875 ;; Specify the altitude of Face images in the From header.
876 \(setq gnus-face-properties-alist
877 \\='((pbm . (:face gnus-x-face :ascent 80))
878 (png . (:ascent 80))))
879
880 ;; Show Face images as pressed buttons.
881 \(setq gnus-face-properties-alist
882 \\='((pbm . (:face gnus-x-face :relief -2))
883 (png . (:relief -2))))
884
885 See the manual for the valid properties for various image types.
886 Currently, `pbm' is used for X-Face images and `png' is used for Face
887 images in Emacs."
888 :version "23.1" ;; No Gnus
889 :group 'gnus-article-headers
890 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
891
892 (defcustom gnus-article-decode-hook
893 '(article-decode-charset article-decode-encoded-words
894 article-decode-group-name article-decode-idna-rhs)
895 "*Hook run to decode charsets in articles."
896 :group 'gnus-article-headers
897 :type 'hook)
898
899 (defcustom gnus-display-mime-function 'gnus-display-mime
900 "Function to display MIME articles."
901 :group 'gnus-article-mime
902 :type 'function)
903
904 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
905 "Function used to decode headers.")
906
907 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
908 "Function used to decode addresses.")
909
910 (defvar gnus-article-dumbquotes-map
911 '((?\200 "EUR")
912 (?\202 ",")
913 (?\203 "f")
914 (?\204 ",,")
915 (?\205 "...")
916 (?\213 "<")
917 (?\214 "OE")
918 (?\221 "`")
919 (?\222 "'")
920 (?\223 "``")
921 (?\224 "\"")
922 (?\225 "*")
923 (?\226 "-")
924 (?\227 "--")
925 (?\230 "~")
926 (?\231 "(TM)")
927 (?\233 ">")
928 (?\234 "oe")
929 (?\264 "'"))
930 "Table for MS-to-Latin1 translation.")
931
932 (defcustom gnus-ignored-mime-types nil
933 "List of MIME types that should be ignored by Gnus."
934 :version "21.1"
935 :group 'gnus-article-mime
936 :type '(repeat regexp))
937
938 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
939 "List of MIME types that should not be given buttons when rendered inline.
940 See also `gnus-buttonized-mime-types' which may override this variable.
941 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
942 :version "21.1"
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
945
946 (defcustom gnus-buttonized-mime-types nil
947 "List of MIME types that should be given buttons when rendered inline.
948 If set, this variable overrides `gnus-unbuttonized-mime-types'.
949 To see e.g. security buttons you could set this to
950 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
951 this list to display radio buttons that allow you to choose one of two
952 media types those mails include. See also `mm-discouraged-alternatives'.
953 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
954 :version "22.1"
955 :group 'gnus-article-mime
956 :type '(repeat regexp))
957
958 (defcustom gnus-inhibit-mime-unbuttonizing nil
959 "If non-nil, all MIME parts get buttons.
960 When nil (the default value), then some MIME parts do not get buttons,
961 as described by the variables `gnus-buttonized-mime-types' and
962 `gnus-unbuttonized-mime-types'."
963 :version "22.1"
964 :group 'gnus-article-mime
965 :type 'boolean)
966
967 (defcustom gnus-body-boundary-delimiter "_"
968 "String used to delimit header and body.
969 This variable is used by `gnus-article-treat-body-boundary' which can
970 be controlled by `gnus-treat-body-boundary'."
971 :version "22.1"
972 :group 'gnus-article-various
973 :type '(choice (item :tag "None" :value nil)
974 string))
975
976 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
977 "/usr/share/picons")
978 "Defines the location of the faces database.
979 For information on obtaining this database of pretty pictures, please
980 see http://www.cs.indiana.edu/picons/ftp/index.html"
981 :version "22.1"
982 :type '(repeat directory)
983 :link '(url-link :tag "download"
984 "http://www.cs.indiana.edu/picons/ftp/index.html")
985 :link '(custom-manual "(gnus)Picons")
986 :group 'gnus-picon)
987
988 (defun gnus-picons-installed-p ()
989 "Say whether picons are installed on your machine."
990 (let ((installed nil))
991 (dolist (database gnus-picon-databases)
992 (when (file-exists-p database)
993 (setq installed t)))
994 installed))
995
996 (defcustom gnus-article-mime-part-function nil
997 "Function called with a MIME handle as the argument.
998 This is meant for people who want to do something automatic based
999 on parts -- for instance, adding Vcard info to a database."
1000 :group 'gnus-article-mime
1001 :type '(choice (const nil)
1002 function))
1003
1004 (defcustom gnus-mime-multipart-functions nil
1005 "An alist of MIME types to functions to display them."
1006 :version "21.1"
1007 :group 'gnus-article-mime
1008 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1009
1010 (defcustom gnus-article-date-headers '(combined-lapsed)
1011 "A list of Date header formats to display.
1012 Valid formats are `ut' (universal time), `local' (local time
1013 zone), `english' (readable English), `lapsed' (elapsed time),
1014 `combined-lapsed' (both the original date and the elapsed time),
1015 `original' (the original date header), `iso8601' (ISO8601
1016 format), and `user-defined' (a user-defined format defined by the
1017 `gnus-article-time-format' variable).
1018
1019 You have as many date headers as you want in the article buffer.
1020 Some of these headers are updated automatically. See
1021 `gnus-article-update-date-headers' for details."
1022 :version "24.1"
1023 :group 'gnus-article-headers
1024 :type '(set
1025 (const :tag "Universal time (UT)" ut)
1026 (const :tag "Local time zone" local)
1027 (const :tag "Readable English" english)
1028 (const :tag "Elapsed time" lapsed)
1029 (const :tag "Original and elapsed time" combined-lapsed)
1030 (const :tag "Original date header" original)
1031 (const :tag "ISO8601 format" iso8601)
1032 (const :tag "User-defined" user-defined)))
1033
1034 (defcustom gnus-article-update-date-headers nil
1035 "A number that says how often to update the date header (in seconds).
1036 If nil, don't update it at all."
1037 :version "24.1"
1038 :group 'gnus-article-headers
1039 :type '(choice
1040 (item :tag "Don't update" :value nil)
1041 integer))
1042
1043 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1044 "Function called with a MIME handle as the argument.
1045 This is meant for people who want to view first matched part.
1046 For `undisplayed-alternative' (default), the first undisplayed
1047 part or alternative part is used. For `undisplayed', the first
1048 undisplayed part is used. For a function, the first part which
1049 the function return t is used. For nil, the first part is
1050 used."
1051 :version "21.1"
1052 :group 'gnus-article-mime
1053 :type '(choice
1054 (item :tag "first" :value nil)
1055 (item :tag "undisplayed" :value undisplayed)
1056 (item :tag "undisplayed or alternative"
1057 :value undisplayed-alternative)
1058 (function)))
1059
1060 (defcustom gnus-mime-action-alist
1061 '(("save to file" . gnus-mime-save-part)
1062 ("save and strip" . gnus-mime-save-part-and-strip)
1063 ("replace with file" . gnus-mime-replace-part)
1064 ("delete part" . gnus-mime-delete-part)
1065 ("display as text" . gnus-mime-inline-part)
1066 ("view the part" . gnus-mime-view-part)
1067 ("pipe to command" . gnus-mime-pipe-part)
1068 ("toggle display" . gnus-article-press-button)
1069 ("toggle display" . gnus-article-view-part-as-charset)
1070 ("view as type" . gnus-mime-view-part-as-type)
1071 ("view internally" . gnus-mime-view-part-internally)
1072 ("view externally" . gnus-mime-view-part-externally))
1073 "An alist of actions that run on the MIME attachment."
1074 :group 'gnus-article-mime
1075 :type '(repeat (cons (string :tag "name")
1076 (function))))
1077
1078 (defcustom gnus-auto-select-part 1
1079 "Advance to next MIME part when deleting or stripping parts.
1080
1081 When 0, point will be placed on the same part as before. When
1082 positive (negative), move point forward (backwards) this many
1083 parts. When nil, redisplay article."
1084 :version "23.1" ;; No Gnus
1085 :group 'gnus-article-mime
1086 :type '(choice (const nil :tag "Redisplay article.")
1087 (const 1 :tag "Next part.")
1088 (const 0 :tag "Current part.")
1089 integer))
1090
1091 ;;;
1092 ;;; The treatment variables
1093 ;;;
1094
1095 (defvar gnus-part-display-hook nil
1096 "Hook called on parts that are to receive treatment.")
1097
1098 (defvar gnus-article-treat-custom
1099 '(choice (const :tag "Off" nil)
1100 (const :tag "On" t)
1101 (const :tag "Header" head)
1102 (const :tag "First" first)
1103 (const :tag "Last" last)
1104 (integer :tag "Less")
1105 (repeat :tag "Groups" regexp)
1106 (sexp :tag "Predicate")))
1107
1108 (defvar gnus-article-treat-head-custom
1109 '(choice (const :tag "Off" nil)
1110 (const :tag "Header" head)))
1111
1112 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1113 "text/x-patch" "text/html")
1114 "Part types eligible for treatment.")
1115
1116 (defvar gnus-inhibit-treatment nil
1117 "Whether to inhibit treatment.")
1118
1119 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1120 "Highlight the signature.
1121 Valid values are nil, t, `head', `first', `last', an integer or a
1122 predicate. See Info node `(gnus)Customizing Articles'."
1123 :group 'gnus-article-treat
1124 :link '(custom-manual "(gnus)Customizing Articles")
1125 :type gnus-article-treat-custom)
1126 (put 'gnus-treat-highlight-signature 'highlight t)
1127
1128 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1129 "Add buttons.
1130 Valid values are nil, t, `head', `first', `last', an integer or a
1131 predicate. See Info node `(gnus)Customizing Articles'."
1132 :group 'gnus-article-treat
1133 :link '(custom-manual "(gnus)Customizing Articles")
1134 :type gnus-article-treat-custom)
1135 (put 'gnus-treat-buttonize 'highlight t)
1136
1137 (defcustom gnus-treat-buttonize-head 'head
1138 "Add buttons to the head.
1139 Valid values are nil, t, `head', `first', `last', an integer or a
1140 predicate. See Info node `(gnus)Customizing Articles'."
1141 :group 'gnus-article-treat
1142 :link '(custom-manual "(gnus)Customizing Articles")
1143 :type gnus-article-treat-head-custom)
1144 (put 'gnus-treat-buttonize-head 'highlight t)
1145
1146 (defcustom gnus-treat-date 'head
1147 "Display dates according to the `gnus-article-date-headers' variable.
1148 Valid values are nil, t, `head', `first', `last', an integer or a
1149 predicate. See Info node `(gnus)Customizing Articles'."
1150 :version "24.1"
1151 :group 'gnus-article-treat
1152 :link '(custom-manual "(gnus)Customizing Articles")
1153 :type gnus-article-treat-head-custom)
1154
1155 (defcustom gnus-treat-emphasize 50000
1156 "Emphasize text.
1157 Valid values are nil, t, `head', `first', `last', an integer or a
1158 predicate. See Info node `(gnus)Customizing Articles'."
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-custom)
1162 (put 'gnus-treat-emphasize 'highlight t)
1163
1164 (defcustom gnus-treat-strip-cr nil
1165 "Remove carriage returns.
1166 Valid values are nil, t, `head', `first', `last', an integer or a
1167 predicate. See Info node `(gnus)Customizing Articles'."
1168 :version "22.1"
1169 :group 'gnus-article-treat
1170 :link '(custom-manual "(gnus)Customizing Articles")
1171 :type gnus-article-treat-custom)
1172
1173 (defcustom gnus-treat-unsplit-urls nil
1174 "Remove newlines from within URLs.
1175 Valid values are nil, t, `head', `first', `last', an integer or a
1176 predicate. See Info node `(gnus)Customizing Articles'."
1177 :version "22.1"
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-custom)
1181
1182 (defcustom gnus-treat-leading-whitespace nil
1183 "Remove leading whitespace in headers.
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate. See Info node `(gnus)Customizing Articles'."
1186 :version "22.1"
1187 :group 'gnus-article-treat
1188 :link '(custom-manual "(gnus)Customizing Articles")
1189 :type gnus-article-treat-custom)
1190
1191 (defcustom gnus-treat-hide-headers 'head
1192 "Hide headers.
1193 Valid values are nil, t, `head', `first', `last', an integer or a
1194 predicate. See Info node `(gnus)Customizing Articles'."
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-head-custom)
1198
1199 (defcustom gnus-treat-hide-boring-headers nil
1200 "Hide boring headers.
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-head-custom)
1206
1207 (defcustom gnus-treat-hide-signature nil
1208 "Hide the signature.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-custom)
1214
1215 (defcustom gnus-treat-fill-article nil
1216 "Fill the article.
1217 Valid values are nil, t, `head', `first', `last', an integer or a
1218 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1222
1223 (defcustom gnus-treat-hide-citation nil
1224 "Hide cited text.
1225 Valid values are nil, t, `head', `first', `last', an integer or a
1226 predicate. See Info node `(gnus)Customizing Articles'.
1227
1228 See `gnus-article-highlight-citation' for variables used to
1229 control what it hides."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1233
1234 (defcustom gnus-treat-hide-citation-maybe nil
1235 "Hide cited text according to certain conditions.
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate. See Info node `(gnus)Customizing Articles'.
1238
1239 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1240 how to control what it hides."
1241 :group 'gnus-article-treat
1242 :link '(custom-manual "(gnus)Customizing Articles")
1243 :type gnus-article-treat-custom)
1244
1245 (defcustom gnus-treat-strip-list-identifiers 'head
1246 "Strip list identifiers from `gnus-list-identifiers'.
1247 Valid values are nil, t, `head', `first', `last', an integer or a
1248 predicate. See Info node `(gnus)Customizing Articles'."
1249 :version "21.1"
1250 :group 'gnus-article-treat
1251 :link '(custom-manual "(gnus)Customizing Articles")
1252 :type gnus-article-treat-custom)
1253
1254 (gnus-define-group-parameter
1255 list-identifier
1256 :variable-document
1257 "Alist of regexps and correspondent identifiers."
1258 :variable-group gnus-article-washing
1259 :parameter-type
1260 '(choice :tag "Identifier"
1261 :value nil
1262 (symbol :tag "Item in `gnus-list-identifiers'" none)
1263 regexp
1264 (const :tag "None" nil))
1265 :parameter-document
1266 "If non-nil, specify how to remove `identifiers' from articles' subject.
1267
1268 Any symbol is used to look up a regular expression to match the
1269 banner in `gnus-list-identifiers'. A string is used as a regular
1270 expression to match the identifier directly.")
1271
1272 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1273 "Gnus 5.10 (Emacs 22.1)")
1274
1275 (defcustom gnus-treat-strip-pem nil
1276 "Strip PEM signatures.
1277 Valid values are nil, t, `head', `first', `last', an integer or a
1278 predicate. See Info node `(gnus)Customizing Articles'."
1279 :group 'gnus-article-treat
1280 :link '(custom-manual "(gnus)Customizing Articles")
1281 :type gnus-article-treat-custom)
1282
1283 (defcustom gnus-treat-strip-banner t
1284 "Strip banners from articles.
1285 The banner to be stripped is specified in the `banner' group parameter.
1286 Valid values are nil, t, `head', `first', `last', an integer or a
1287 predicate. See Info node `(gnus)Customizing Articles'."
1288 :group 'gnus-article-treat
1289 :link '(custom-manual "(gnus)Customizing Articles")
1290 :type gnus-article-treat-custom)
1291
1292 (defcustom gnus-treat-highlight-headers 'head
1293 "Highlight the headers.
1294 Valid values are nil, t, `head', `first', `last', an integer or a
1295 predicate. See Info node `(gnus)Customizing Articles'."
1296 :group 'gnus-article-treat
1297 :link '(custom-manual "(gnus)Customizing Articles")
1298 :type gnus-article-treat-head-custom)
1299 (put 'gnus-treat-highlight-headers 'highlight t)
1300
1301 (defcustom gnus-treat-highlight-citation t
1302 "Highlight cited text.
1303 Valid values are nil, t, `head', `first', `last', an integer or a
1304 predicate. See Info node `(gnus)Customizing Articles'."
1305 :group 'gnus-article-treat
1306 :link '(custom-manual "(gnus)Customizing Articles")
1307 :type gnus-article-treat-custom)
1308 (put 'gnus-treat-highlight-citation 'highlight t)
1309
1310 (defcustom gnus-treat-strip-headers-in-body t
1311 "Strip the X-No-Archive header line from the beginning of the body.
1312 Valid values are nil, t, `head', `first', `last', an integer or a
1313 predicate. See Info node `(gnus)Customizing Articles'."
1314 :version "21.1"
1315 :group 'gnus-article-treat
1316 :link '(custom-manual "(gnus)Customizing Articles")
1317 :type gnus-article-treat-custom)
1318
1319 (defcustom gnus-treat-strip-trailing-blank-lines nil
1320 "Strip trailing blank lines.
1321 Valid values are nil, t, `head', `first', `last', an integer or a
1322 predicate. See Info node `(gnus)Customizing Articles'.
1323
1324 When set to t, it also strips trailing blanks in all MIME parts.
1325 Consider to use `last' instead."
1326 :group 'gnus-article-treat
1327 :link '(custom-manual "(gnus)Customizing Articles")
1328 :type gnus-article-treat-custom)
1329
1330 (defcustom gnus-treat-strip-leading-blank-lines nil
1331 "Strip leading blank lines.
1332 Valid values are nil, t, `head', `first', `last', an integer or a
1333 predicate. See Info node `(gnus)Customizing Articles'.
1334
1335 When set to t, it also strips trailing blanks in all MIME parts."
1336 :group 'gnus-article-treat
1337 :link '(custom-manual "(gnus)Customizing Articles")
1338 :type gnus-article-treat-custom)
1339
1340 (defcustom gnus-treat-strip-multiple-blank-lines nil
1341 "Strip multiple blank lines.
1342 Valid values are nil, t, `head', `first', `last', an integer or a
1343 predicate. See Info node `(gnus)Customizing Articles'."
1344 :group 'gnus-article-treat
1345 :link '(custom-manual "(gnus)Customizing Articles")
1346 :type gnus-article-treat-custom)
1347
1348 (defcustom gnus-treat-unfold-headers 'head
1349 "Unfold folded header lines.
1350 Valid values are nil, t, `head', `first', `last', an integer or a
1351 predicate. See Info node `(gnus)Customizing Articles'."
1352 :version "22.1"
1353 :group 'gnus-article-treat
1354 :link '(custom-manual "(gnus)Customizing Articles")
1355 :type gnus-article-treat-custom)
1356
1357 (defcustom gnus-article-unfold-long-headers nil
1358 "If non-nil, allow unfolding headers even if the header is long.
1359 If it is a regexp, only long headers matching this regexp are unfolded.
1360 If it is t, all long headers are unfolded.
1361
1362 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1363 :version "23.1" ;; No Gnus
1364 :group 'gnus-article-treat
1365 :type '(choice (const nil)
1366 (const :tag "all" t)
1367 (regexp)))
1368
1369 (defcustom gnus-treat-fold-headers nil
1370 "Fold headers.
1371 Valid values are nil, t, `head', `first', `last', an integer or a
1372 predicate. See Info node `(gnus)Customizing Articles'."
1373 :version "22.1"
1374 :group 'gnus-article-treat
1375 :link '(custom-manual "(gnus)Customizing Articles")
1376 :type gnus-article-treat-custom)
1377
1378 (defcustom gnus-treat-fold-newsgroups 'head
1379 "Fold the Newsgroups and Followup-To headers.
1380 Valid values are nil, t, `head', `first', `last', an integer or a
1381 predicate. See Info node `(gnus)Customizing Articles'."
1382 :version "22.1"
1383 :group 'gnus-article-treat
1384 :link '(custom-manual "(gnus)Customizing Articles")
1385 :type gnus-article-treat-custom)
1386
1387 (defcustom gnus-treat-overstrike t
1388 "Treat overstrike highlighting.
1389 Valid values are nil, t, `head', `first', `last', an integer or a
1390 predicate. See Info node `(gnus)Customizing Articles'."
1391 :group 'gnus-article-treat
1392 :link '(custom-manual "(gnus)Customizing Articles")
1393 :type gnus-article-treat-custom)
1394 (put 'gnus-treat-overstrike 'highlight t)
1395
1396 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1397 "Treat ANSI SGR control sequences.
1398 Valid values are nil, t, `head', `first', `last', an integer or a
1399 predicate. See Info node `(gnus)Customizing Articles'."
1400 :group 'gnus-article-treat
1401 :link '(custom-manual "(gnus)Customizing Articles")
1402 :type gnus-article-treat-custom)
1403
1404 (make-obsolete-variable 'gnus-treat-display-xface
1405 'gnus-treat-display-x-face "Emacs 22.1")
1406
1407 (defcustom gnus-treat-display-x-face
1408 (and (not noninteractive)
1409 (gnus-image-type-available-p 'xbm)
1410 (condition-case nil
1411 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1412 (executable-find "icontopbm"))
1413 ;; shell-command-to-string may signal an error, e.g. if
1414 ;; shell-file-name is not found.
1415 (error nil))
1416 'head)
1417 "Display X-Face headers.
1418 Valid values are nil and `head'.
1419 See Info node `(gnus)Customizing Articles' and Info node
1420 `(gnus)X-Face' for details."
1421 :group 'gnus-article-treat
1422 :version "21.1"
1423 :link '(custom-manual "(gnus)Customizing Articles")
1424 :link '(custom-manual "(gnus)X-Face")
1425 :type gnus-article-treat-head-custom
1426 :set (lambda (symbol value)
1427 (set-default
1428 symbol
1429 (cond ((or (boundp symbol) (get symbol 'saved-value))
1430 value)
1431 ((boundp 'gnus-treat-display-xface)
1432 (message "\
1433 ** gnus-treat-display-xface is an obsolete variable;\
1434 use gnus-treat-display-x-face instead")
1435 (default-value 'gnus-treat-display-xface))
1436 ((get 'gnus-treat-display-xface 'saved-value)
1437 (message "\
1438 ** gnus-treat-display-xface is an obsolete variable;\
1439 use gnus-treat-display-x-face instead")
1440 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1441 (t
1442 value)))))
1443 (put 'gnus-treat-display-x-face 'highlight t)
1444
1445 (defcustom gnus-treat-display-face
1446 (and (not noninteractive)
1447 (gnus-image-type-available-p 'png)
1448 'head)
1449 "Display Face headers.
1450 Valid values are nil, t, `head', `first', `last', an integer or a
1451 predicate. See Info node `(gnus)Customizing Articles' and Info
1452 node `(gnus)Face' for details."
1453 :group 'gnus-article-treat
1454 :version "22.1"
1455 :link '(custom-manual "(gnus)Customizing Articles")
1456 :link '(custom-manual "(gnus)X-Face")
1457 :type gnus-article-treat-head-custom)
1458 (put 'gnus-treat-display-face 'highlight t)
1459
1460 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1461 "Display smileys.
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate. See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Smileys' for details."
1465 :group 'gnus-article-treat
1466 :version "21.1"
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :link '(custom-manual "(gnus)Smileys")
1469 :type gnus-article-treat-custom)
1470 (put 'gnus-treat-display-smileys 'highlight t)
1471
1472 (defcustom gnus-treat-from-picon
1473 (if (and (gnus-image-type-available-p 'xpm)
1474 (gnus-picons-installed-p))
1475 'head nil)
1476 "Display picons in the From header.
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)Picons' for details."
1480 :version "22.1"
1481 :group 'gnus-article-treat
1482 :group 'gnus-picon
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Picons")
1485 :type gnus-article-treat-head-custom)
1486 (put 'gnus-treat-from-picon 'highlight t)
1487
1488 (defcustom gnus-treat-mail-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1491 'head nil)
1492 "Display picons in To and Cc headers.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496 :version "22.1"
1497 :group 'gnus-article-treat
1498 :group 'gnus-picon
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-mail-picon 'highlight t)
1503
1504 (defcustom gnus-treat-newsgroups-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1507 'head nil)
1508 "Display picons in the Newsgroups and Followup-To headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512 :version "22.1"
1513 :group 'gnus-article-treat
1514 :group 'gnus-picon
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-newsgroups-picon 'highlight t)
1519
1520 (defcustom gnus-treat-from-gravatar nil
1521 "Display gravatars in the From header.
1522 Valid values are nil, t, `head', `first', `last', an integer or a
1523 predicate. See Info node `(gnus)Customizing Articles' and Info
1524 node `(gnus)Gravatars' for details."
1525 :version "24.1"
1526 :group 'gnus-article-treat
1527 :group 'gnus-gravatar
1528 :link '(custom-manual "(gnus)Customizing Articles")
1529 :link '(custom-manual "(gnus)Gravatars")
1530 :type gnus-article-treat-head-custom)
1531 (put 'gnus-treat-from-gravatar 'highlight t)
1532
1533 (defcustom gnus-treat-mail-gravatar nil
1534 "Display gravatars in To and Cc headers.
1535 Valid values are nil, t, `head', `first', `last', an integer or a
1536 predicate. See Info node `(gnus)Customizing Articles' and Info
1537 node `(gnus)Gravatars' for details."
1538 :version "24.1"
1539 :group 'gnus-article-treat
1540 :group 'gnus-gravatar
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :link '(custom-manual "(gnus)Gravatars")
1543 :type gnus-article-treat-head-custom)
1544 (put 'gnus-treat-mail-gravatar 'highlight t)
1545
1546 (defcustom gnus-treat-body-boundary
1547 (if (or gnus-treat-newsgroups-picon
1548 gnus-treat-mail-picon
1549 gnus-treat-from-picon
1550 gnus-treat-from-gravatar
1551 gnus-treat-mail-gravatar)
1552 ;; If there's much decoration, the user might prefer a boundary.
1553 'head
1554 nil)
1555 "Draw a boundary at the end of the headers.
1556 Valid values are nil and `head'.
1557 See Info node `(gnus)Customizing Articles' for details."
1558 :version "22.1"
1559 :group 'gnus-article-treat
1560 :link '(custom-manual "(gnus)Customizing Articles")
1561 :type gnus-article-treat-head-custom)
1562
1563 (defcustom gnus-treat-capitalize-sentences nil
1564 "Capitalize sentence-starting words.
1565 Valid values are nil, t, `head', `first', `last', an integer or a
1566 predicate. See Info node `(gnus)Customizing Articles'."
1567 :version "21.1"
1568 :group 'gnus-article-treat
1569 :link '(custom-manual "(gnus)Customizing Articles")
1570 :type gnus-article-treat-custom)
1571
1572 (defcustom gnus-treat-wash-html nil
1573 "Format as HTML.
1574 Valid values are nil, t, `head', `first', `last', an integer or a
1575 predicate. See Info node `(gnus)Customizing Articles'."
1576 :version "22.1"
1577 :group 'gnus-article-treat
1578 :link '(custom-manual "(gnus)Customizing Articles")
1579 :type gnus-article-treat-custom)
1580
1581 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1582 "Fill long lines.
1583 Valid values are nil, t, `head', `first', `last', an integer or a
1584 predicate. See Info node `(gnus)Customizing Articles'."
1585 :version "24.1"
1586 :group 'gnus-article-treat
1587 :link '(custom-manual "(gnus)Customizing Articles")
1588 :type gnus-article-treat-custom)
1589
1590 (defcustom gnus-treat-x-pgp-sig nil
1591 "Verify X-PGP-Sig.
1592 To automatically treat X-PGP-Sig, set it to head.
1593 Valid values are nil, t, `head', `first', `last', an integer or a
1594 predicate. See Info node `(gnus)Customizing Articles'."
1595 :version "22.1"
1596 :group 'gnus-article-treat
1597 :group 'mime-security
1598 :link '(custom-manual "(gnus)Customizing Articles")
1599 :type gnus-article-treat-custom)
1600
1601 (defvar gnus-article-encrypt-protocol-alist
1602 '(("PGP" . mml2015-self-encrypt)))
1603
1604 ;; Set to nil if more than one protocol added to
1605 ;; gnus-article-encrypt-protocol-alist.
1606 (defcustom gnus-article-encrypt-protocol "PGP"
1607 "The protocol used for encrypt articles.
1608 It is a string, such as \"PGP\". If nil, ask user."
1609 :version "22.1"
1610 :type 'string
1611 :group 'mime-security)
1612
1613 (defvar idna-program)
1614
1615 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1616 (condition-case nil
1617 (require 'idna)
1618 (file-error)
1619 (invalid-operation))
1620 idna-program
1621 (executable-find idna-program))
1622 "Whether IDNA decoding of headers is used when viewing messages.
1623 This requires GNU Libidn, and by default only enabled if it is found."
1624 :version "22.1"
1625 :group 'gnus-article-headers
1626 :type 'boolean)
1627
1628 (defcustom gnus-article-over-scroll nil
1629 "If non-nil, allow scrolling the article buffer even when there no more text."
1630 :version "22.1"
1631 :group 'gnus-article
1632 :type 'boolean)
1633
1634 (defcustom gnus-inhibit-images nil
1635 "Non-nil means inhibit displaying of images inline in the article body."
1636 :version "24.1"
1637 :group 'gnus-article
1638 :type 'boolean)
1639
1640 (defcustom gnus-blocked-images 'gnus-block-private-groups
1641 "Images that have URLs matching this regexp will be blocked.
1642 This can also be a function to be evaluated. If so, it will be
1643 called with the group name as the parameter, and should return a
1644 regexp."
1645 :version "24.1"
1646 :group 'gnus-art
1647 :type '(choice (const :tag "Allow all" nil)
1648 (regexp :tag "Regular expression")
1649 (function :tag "Use a function")))
1650
1651 ;;; Internal variables
1652
1653 (defvar gnus-english-month-names
1654 '("January" "February" "March" "April" "May" "June" "July" "August"
1655 "September" "October" "November" "December"))
1656
1657 (defvar article-goto-body-goes-to-point-min-p nil)
1658 (defvar gnus-article-wash-types nil)
1659 (defvar gnus-article-emphasis-alist nil)
1660 (defvar gnus-article-image-alist nil)
1661
1662 (defvar gnus-article-mime-handle-alist-1 nil)
1663 (defvar gnus-treatment-function-alist
1664 '((gnus-treat-strip-cr gnus-article-remove-cr)
1665 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1666 (gnus-treat-strip-banner gnus-article-strip-banner)
1667 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1668 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1669 (gnus-treat-buttonize gnus-article-add-buttons)
1670 (gnus-treat-fill-article gnus-article-fill-cited-article)
1671 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1672 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1673 (gnus-treat-display-x-face gnus-article-display-x-face)
1674 (gnus-treat-display-face gnus-article-display-face)
1675 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1676 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1677 (gnus-treat-hide-signature gnus-article-hide-signature)
1678 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1679 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1680 (gnus-treat-from-picon gnus-treat-from-picon)
1681 (gnus-treat-mail-picon gnus-treat-mail-picon)
1682 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1683 (gnus-treat-strip-pem gnus-article-hide-pem)
1684 (gnus-treat-date gnus-article-treat-date)
1685 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1686 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1687 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1688 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1689 (gnus-treat-strip-trailing-blank-lines
1690 gnus-article-remove-trailing-blank-lines)
1691 (gnus-treat-strip-leading-blank-lines
1692 gnus-article-strip-leading-blank-lines)
1693 (gnus-treat-strip-multiple-blank-lines
1694 gnus-article-strip-multiple-blank-lines)
1695 (gnus-treat-overstrike gnus-article-treat-overstrike)
1696 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1697 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1698 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1699 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1700 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1701 (gnus-treat-display-smileys gnus-treat-smiley)
1702 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1703 (gnus-treat-wash-html gnus-article-wash-html)
1704 (gnus-treat-emphasize gnus-article-emphasize)
1705 (gnus-treat-hide-citation gnus-article-hide-citation)
1706 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1707 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1708 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1709
1710 (defvar gnus-article-mime-handle-alist nil)
1711 (defvar article-lapsed-timer nil)
1712 (defvar gnus-article-current-summary nil)
1713
1714 (defvar gnus-article-mode-syntax-table
1715 (let ((table (copy-syntax-table text-mode-syntax-table)))
1716 ;; This causes the citation match run O(2^n).
1717 ;; (modify-syntax-entry ?- "w" table)
1718 (modify-syntax-entry ?> ")<" table)
1719 (modify-syntax-entry ?< "(>" table)
1720 ;; make M-. in article buffers work for `foo' strings
1721 (modify-syntax-entry ?' " " table)
1722 (modify-syntax-entry ?` " " table)
1723 table)
1724 "Syntax table used in article mode buffers.
1725 Initialized from `text-mode-syntax-table'.")
1726
1727 (defvar gnus-save-article-buffer nil)
1728
1729 (defvar gnus-number-of-articles-to-be-saved nil)
1730
1731 (defvar gnus-inhibit-hiding nil)
1732
1733 (defvar gnus-article-edit-mode nil)
1734
1735 ;;; Macros for dealing with the article buffer.
1736
1737 (defmacro gnus-with-article-headers (&rest forms)
1738 `(with-current-buffer gnus-article-buffer
1739 (save-restriction
1740 (let ((inhibit-read-only t)
1741 (inhibit-point-motion-hooks t)
1742 (case-fold-search t))
1743 (article-narrow-to-head)
1744 ,@forms))))
1745
1746 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1747 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1748
1749 (defmacro gnus-with-article-buffer (&rest forms)
1750 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1751 (with-current-buffer gnus-article-buffer
1752 (let ((inhibit-read-only t))
1753 ,@forms))))
1754
1755 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1756 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1757
1758 (defun gnus-article-goto-header (header)
1759 "Go to HEADER, which is a regular expression."
1760 (re-search-forward (concat "^\\(" header "\\):") nil t))
1761
1762 (defsubst gnus-article-hide-text (b e props)
1763 "Set text PROPS on the B to E region."
1764 (gnus-add-text-properties-when 'article-type nil b e props))
1765
1766 (defsubst gnus-article-unhide-text (b e)
1767 "Remove hidden text properties from region between B and E."
1768 (remove-text-properties b e gnus-hidden-properties))
1769
1770 (defun gnus-article-hide-text-type (b e type)
1771 "Hide text of TYPE between B and E."
1772 (gnus-add-wash-type type)
1773 (gnus-article-hide-text
1774 b e (cons 'article-type (cons type gnus-hidden-properties))))
1775
1776 (defun gnus-article-unhide-text-type (b e type)
1777 "Unhide text of TYPE between B and E."
1778 (gnus-delete-wash-type type)
1779 (remove-text-properties
1780 b e (cons 'article-type (cons type gnus-hidden-properties))))
1781
1782 (defun gnus-article-delete-text-of-type (type)
1783 "Delete text of TYPE in the current buffer."
1784 (save-excursion
1785 (let ((b (point-min)))
1786 (if (eq type 'multipart)
1787 ;; Remove MIME buttons associated with multipart/alternative parts.
1788 (progn
1789 (goto-char b)
1790 (while (if (get-text-property (point) 'gnus-part)
1791 (setq b (point))
1792 (when (setq b (next-single-property-change (point)
1793 'gnus-part))
1794 (goto-char b)
1795 t))
1796 (end-of-line)
1797 (skip-chars-forward "\n")
1798 (when (eq (get-text-property b 'article-type) 'multipart)
1799 (delete-region b (point)))))
1800 (while (setq b (text-property-any b (point-max) 'article-type type))
1801 (delete-region
1802 b (or (text-property-not-all b (point-max) 'article-type type)
1803 (point-max))))))))
1804
1805 (defun gnus-article-delete-invisible-text ()
1806 "Delete all invisible text in the current buffer."
1807 (save-excursion
1808 (let ((b (point-min)))
1809 (while (setq b (text-property-any b (point-max) 'invisible t))
1810 (delete-region
1811 b (or (text-property-not-all b (point-max) 'invisible t)
1812 (point-max)))))))
1813
1814 (defsubst gnus-article-header-rank ()
1815 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1816 (let ((list gnus-sorted-header-list)
1817 (i 1))
1818 (while list
1819 (if (looking-at (car list))
1820 (setq list nil)
1821 (setq list (cdr list))
1822 (incf i)))
1823 i))
1824
1825 (defun article-hide-headers (&optional _arg _delete)
1826 "Hide unwanted headers and possibly sort them as well."
1827 (interactive)
1828 ;; This function might be inhibited.
1829 (unless gnus-inhibit-hiding
1830 (let ((inhibit-read-only t)
1831 (case-fold-search t)
1832 (max (1+ (length gnus-sorted-header-list)))
1833 (inhibit-point-motion-hooks t)
1834 (cur (current-buffer))
1835 ignored visible beg)
1836 (save-excursion
1837 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1838 ;; group parameters, so we should go to the summary buffer.
1839 (when (prog1
1840 (condition-case nil
1841 (progn (set-buffer gnus-summary-buffer) t)
1842 (error nil))
1843 (setq ignored (when (not gnus-visible-headers)
1844 (cond ((stringp gnus-ignored-headers)
1845 gnus-ignored-headers)
1846 ((listp gnus-ignored-headers)
1847 (mapconcat 'identity
1848 gnus-ignored-headers
1849 "\\|"))))
1850 visible (cond ((stringp gnus-visible-headers)
1851 gnus-visible-headers)
1852 ((and gnus-visible-headers
1853 (listp gnus-visible-headers))
1854 (mapconcat 'identity
1855 gnus-visible-headers
1856 "\\|")))))
1857 (set-buffer cur))
1858 (save-restriction
1859 ;; First we narrow to just the headers.
1860 (article-narrow-to-head)
1861 ;; Hide any "From " lines at the beginning of (mail) articles.
1862 (while (looking-at "From ")
1863 (forward-line 1))
1864 (unless (bobp)
1865 (delete-region (point-min) (point)))
1866 ;; Then treat the rest of the header lines.
1867 ;; Then we use the two regular expressions
1868 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1869 ;; select which header lines is to remain visible in the
1870 ;; article buffer.
1871 (while (re-search-forward "^[^ \t:]*:" nil t)
1872 (beginning-of-line)
1873 ;; Mark the rank of the header.
1874 (put-text-property
1875 (point) (1+ (point)) 'message-rank
1876 (if (or (and visible (looking-at visible))
1877 (and ignored
1878 (not (looking-at ignored))))
1879 (gnus-article-header-rank)
1880 (+ 2 max)))
1881 (forward-line 1))
1882 (message-sort-headers-1)
1883 (when (setq beg (text-property-any
1884 (point-min) (point-max) 'message-rank (+ 2 max)))
1885 ;; We delete the unwanted headers.
1886 (gnus-add-wash-type 'headers)
1887 (add-text-properties (point-min) (+ 5 (point-min))
1888 '(article-type headers dummy-invisible t))
1889 (delete-region beg (point-max))))))))
1890
1891 (defun article-hide-boring-headers (&optional arg)
1892 "Toggle hiding of headers that aren't very interesting.
1893 If given a negative prefix, always show; if given a positive prefix,
1894 always hide."
1895 (interactive (gnus-article-hidden-arg))
1896 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1897 (not gnus-show-all-headers))
1898 (save-excursion
1899 (save-restriction
1900 (let ((inhibit-read-only t)
1901 (inhibit-point-motion-hooks t))
1902 (article-narrow-to-head)
1903 (dolist (elem gnus-boring-article-headers)
1904 (goto-char (point-min))
1905 (cond
1906 ;; Hide empty headers.
1907 ((eq elem 'empty)
1908 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1909 (forward-line -1)
1910 (gnus-article-hide-text-type
1911 (point-at-bol)
1912 (progn
1913 (end-of-line)
1914 (if (re-search-forward "^[^ \t]" nil t)
1915 (match-beginning 0)
1916 (point-max)))
1917 'boring-headers)))
1918 ;; Hide boring Newsgroups header.
1919 ((eq elem 'newsgroups)
1920 (when (gnus-string-equal
1921 (gnus-fetch-field "newsgroups")
1922 (gnus-group-real-name
1923 (if (boundp 'gnus-newsgroup-name)
1924 gnus-newsgroup-name
1925 "")))
1926 (gnus-article-hide-header "newsgroups")))
1927 ((eq elem 'to-address)
1928 (let ((to (message-fetch-field "to"))
1929 (to-address
1930 (gnus-parameter-to-address
1931 (if (boundp 'gnus-newsgroup-name)
1932 gnus-newsgroup-name ""))))
1933 (when (and to to-address
1934 (ignore-errors
1935 (gnus-string-equal
1936 ;; only one address in To
1937 (nth 1 (mail-extract-address-components to))
1938 to-address)))
1939 (gnus-article-hide-header "to"))))
1940 ((eq elem 'to-list)
1941 (let ((to (message-fetch-field "to"))
1942 (to-list
1943 (gnus-parameter-to-list
1944 (if (boundp 'gnus-newsgroup-name)
1945 gnus-newsgroup-name ""))))
1946 (when (and to to-list
1947 (ignore-errors
1948 (gnus-string-equal
1949 ;; only one address in To
1950 (nth 1 (mail-extract-address-components to))
1951 to-list)))
1952 (gnus-article-hide-header "to"))))
1953 ((eq elem 'cc-list)
1954 (let ((cc (message-fetch-field "cc"))
1955 (to-list
1956 (gnus-parameter-to-list
1957 (if (boundp 'gnus-newsgroup-name)
1958 gnus-newsgroup-name ""))))
1959 (when (and cc to-list
1960 (ignore-errors
1961 (gnus-string-equal
1962 ;; only one address in CC
1963 (nth 1 (mail-extract-address-components cc))
1964 to-list)))
1965 (gnus-article-hide-header "cc"))))
1966 ((eq elem 'followup-to)
1967 (when (gnus-string-equal
1968 (message-fetch-field "followup-to")
1969 (message-fetch-field "newsgroups"))
1970 (gnus-article-hide-header "followup-to")))
1971 ((eq elem 'reply-to)
1972 (if (gnus-group-find-parameter
1973 gnus-newsgroup-name 'broken-reply-to)
1974 (gnus-article-hide-header "reply-to")
1975 (let ((from (message-fetch-field "from"))
1976 (reply-to (message-fetch-field "reply-to")))
1977 (when
1978 (and
1979 from reply-to
1980 (ignore-errors
1981 (equal
1982 (sort (mapcar
1983 (lambda (x) (downcase (cadr x)))
1984 (mail-extract-address-components from t))
1985 'string<)
1986 (sort (mapcar
1987 (lambda (x) (downcase (cadr x)))
1988 (mail-extract-address-components reply-to t))
1989 'string<))))
1990 (gnus-article-hide-header "reply-to")))))
1991 ((eq elem 'date)
1992 (let ((date (with-current-buffer gnus-original-article-buffer
1993 ;; If date in `gnus-article-buffer' is localized
1994 ;; (`gnus-treat-date-user-defined'),
1995 ;; `days-between' might fail.
1996 (message-fetch-field "date"))))
1997 (when (and date
1998 (< (days-between (current-time-string) date)
1999 4))
2000 (gnus-article-hide-header "date"))))
2001 ((eq elem 'long-to)
2002 (let ((to (message-fetch-field "to"))
2003 (cc (message-fetch-field "cc")))
2004 (when (> (length to) 1024)
2005 (gnus-article-hide-header "to"))
2006 (when (> (length cc) 1024)
2007 (gnus-article-hide-header "cc"))))
2008 ((eq elem 'many-to)
2009 (let ((to-count 0)
2010 (cc-count 0))
2011 (goto-char (point-min))
2012 (while (re-search-forward "^to:" nil t)
2013 (setq to-count (1+ to-count)))
2014 (when (> to-count 1)
2015 (while (> to-count 0)
2016 (goto-char (point-min))
2017 (save-restriction
2018 (re-search-forward "^to:" nil nil to-count)
2019 (forward-line -1)
2020 (narrow-to-region (point) (point-max))
2021 (gnus-article-hide-header "to"))
2022 (setq to-count (1- to-count))))
2023 (goto-char (point-min))
2024 (while (re-search-forward "^cc:" nil t)
2025 (setq cc-count (1+ cc-count)))
2026 (when (> cc-count 1)
2027 (while (> cc-count 0)
2028 (goto-char (point-min))
2029 (save-restriction
2030 (re-search-forward "^cc:" nil nil cc-count)
2031 (forward-line -1)
2032 (narrow-to-region (point) (point-max))
2033 (gnus-article-hide-header "cc"))
2034 (setq cc-count (1- cc-count)))))))))))))
2035
2036 (defun gnus-article-hide-header (header)
2037 (save-excursion
2038 (goto-char (point-min))
2039 (when (re-search-forward (concat "^" header ":") nil t)
2040 (gnus-article-hide-text-type
2041 (point-at-bol)
2042 (progn
2043 (end-of-line)
2044 (if (re-search-forward "^[^ \t]" nil t)
2045 (match-beginning 0)
2046 (point-max)))
2047 'boring-headers))))
2048
2049 (defvar gnus-article-normalized-header-length 40
2050 "Length of normalized headers.")
2051
2052 (defun article-normalize-headers ()
2053 "Make all header lines 40 characters long."
2054 (interactive)
2055 (let ((inhibit-read-only t)
2056 column)
2057 (save-excursion
2058 (save-restriction
2059 (article-narrow-to-head)
2060 (while (not (eobp))
2061 (cond
2062 ((< (setq column (- (point-at-eol) (point)))
2063 gnus-article-normalized-header-length)
2064 (end-of-line)
2065 (insert (make-string
2066 (- gnus-article-normalized-header-length column)
2067 ? )))
2068 ((> column gnus-article-normalized-header-length)
2069 (put-text-property
2070 (progn
2071 (forward-char gnus-article-normalized-header-length)
2072 (point))
2073 (point-at-eol)
2074 'invisible t))
2075 (t
2076 ;; Do nothing.
2077 ))
2078 (forward-line 1))))))
2079
2080 (defun article-treat-dumbquotes ()
2081 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2082 Note that this function guesses whether a character is a sm*rtq**t* or
2083 not, so it should only be used interactively.
2084
2085 Sm*rtq**t*s are M****s***'s unilateral extension to the
2086 iso-8859-1 character map in an attempt to provide more quoting
2087 characters. If you see something like \\222 or \\264 where
2088 you're expecting some kind of apostrophe or quotation mark, then
2089 try this wash."
2090 (interactive)
2091 (article-translate-strings gnus-article-dumbquotes-map))
2092
2093 (defvar org-entities)
2094
2095 (defun article-treat-non-ascii ()
2096 "Translate many Unicode characters into their ASCII equivalents."
2097 (interactive)
2098 (require 'org-entities)
2099 (let ((table (make-char-table nil)))
2100 (dolist (elem org-entities)
2101 (when (and (listp elem)
2102 (= (length (nth 6 elem)) 1))
2103 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem))))
2104 (save-excursion
2105 (when (article-goto-body)
2106 (let ((inhibit-read-only t)
2107 replace props)
2108 (while (not (eobp))
2109 (if (not (setq replace (aref table (following-char))))
2110 (forward-char 1)
2111 (if (prog1
2112 (setq props (text-properties-at (point)))
2113 (delete-char 1))
2114 (add-text-properties (point) (progn (insert replace) (point))
2115 props)
2116 (insert replace)))))))))
2117
2118 (defun article-translate-strings (map)
2119 "Translate all string in the body of the article according to MAP.
2120 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2121 (save-excursion
2122 (when (article-goto-body)
2123 (let ((inhibit-read-only t))
2124 (dolist (elem map)
2125 (let ((from (car elem))
2126 (to (cadr elem)))
2127 (save-excursion
2128 (if (stringp from)
2129 (while (search-forward from nil t)
2130 (replace-match to))
2131 (while (not (eobp))
2132 (if (eq (following-char) from)
2133 (progn
2134 (delete-char 1)
2135 (insert to))
2136 (forward-char 1)))))))))))
2137
2138 (defun article-treat-overstrike ()
2139 "Translate overstrikes into bold text."
2140 (interactive)
2141 (save-excursion
2142 (when (article-goto-body)
2143 (let ((inhibit-read-only t))
2144 (while (search-forward "\b" nil t)
2145 (let ((next (char-after))
2146 (previous (char-after (- (point) 2))))
2147 ;; We do the boldification/underlining by hiding the
2148 ;; overstrikes and putting the proper text property
2149 ;; on the letters.
2150 (cond
2151 ((eq next previous)
2152 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2153 (put-text-property (point) (1+ (point)) 'face 'bold))
2154 ((eq next ?_)
2155 (gnus-article-hide-text-type
2156 (1- (point)) (1+ (point)) 'overstrike)
2157 (put-text-property
2158 (- (point) 2) (1- (point)) 'face 'underline))
2159 ((eq previous ?_)
2160 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2161 (put-text-property
2162 (point) (1+ (point)) 'face 'underline)))))))))
2163
2164 (defun article-treat-ansi-sequences ()
2165 "Translate ANSI SGR control sequences into overlays or extents."
2166 (interactive)
2167 (save-excursion
2168 (when (article-goto-body)
2169 (let ((inhibit-read-only t))
2170 (ansi-color-apply-on-region (point) (point-max))))))
2171
2172 (defun gnus-article-treat-unfold-headers ()
2173 "Unfold folded message headers.
2174 Only the headers that fit into the current window width will be
2175 unfolded."
2176 (interactive)
2177 (gnus-with-article-headers
2178 (let (length)
2179 (while (not (eobp))
2180 (save-restriction
2181 (mail-header-narrow-to-field)
2182 (let* ((header (buffer-string))
2183 (unfoldable
2184 (or (equal gnus-article-unfold-long-headers t)
2185 (and (stringp gnus-article-unfold-long-headers)
2186 (string-match gnus-article-unfold-long-headers
2187 header)))))
2188 (with-temp-buffer
2189 (insert header)
2190 (goto-char (point-min))
2191 (while (re-search-forward "\n[\t ]" nil t)
2192 (replace-match " " t t)))
2193 (setq length (- (point-max) (point-min) 1))
2194 (when (or unfoldable
2195 (< length (window-width)))
2196 (while (re-search-forward "\n[\t ]" nil t)
2197 (replace-match " " t t))))
2198 (goto-char (point-max)))))))
2199
2200 (defun gnus-article-treat-fold-headers ()
2201 "Fold message headers."
2202 (interactive)
2203 (gnus-with-article-headers
2204 (while (not (eobp))
2205 (save-restriction
2206 (mail-header-narrow-to-field)
2207 (mail-header-fold-field)
2208 (goto-char (point-max))))))
2209
2210 (defun gnus-treat-smiley ()
2211 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2212 (interactive)
2213 (gnus-with-article-buffer
2214 (if (memq 'smiley gnus-article-wash-types)
2215 (gnus-delete-images 'smiley)
2216 (article-goto-body)
2217 (let ((images (smiley-region (point) (point-max))))
2218 (when images
2219 (gnus-add-wash-type 'smiley)
2220 (dolist (image images)
2221 (gnus-add-image 'smiley image)))))))
2222
2223 (defun gnus-article-remove-images ()
2224 "Remove all images from the article buffer."
2225 (interactive)
2226 (gnus-with-article-buffer
2227 (save-restriction
2228 (widen)
2229 (dolist (elem gnus-article-image-alist)
2230 (gnus-delete-images (car elem))))))
2231
2232 (autoload 'w3m-toggle-inline-images "w3m")
2233
2234 (defun gnus-article-show-images ()
2235 "Show any images that are in the HTML-rendered article buffer.
2236 This only works if the article in question is HTML."
2237 (interactive)
2238 (gnus-with-article-buffer
2239 (save-restriction
2240 (widen)
2241 (if (eq mm-text-html-renderer 'w3m)
2242 (w3m-toggle-inline-images)
2243 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2244 'image-displayer))
2245 (destructuring-bind (start end function) region
2246 (funcall function (get-text-property start 'image-url)
2247 start end)))))))
2248
2249 (defun gnus-article-treat-fold-newsgroups ()
2250 "Unfold folded message headers.
2251 Only the headers that fit into the current window width will be
2252 unfolded."
2253 (interactive)
2254 (gnus-with-article-headers
2255 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2256 (save-restriction
2257 (mail-header-narrow-to-field)
2258 (while (re-search-forward ", *" nil t)
2259 (replace-match ", " t t))
2260 (mail-header-fold-field)
2261 (goto-char (point-max))))))
2262
2263 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2264 "Value of `truncate-lines' in Gnus Article buffer.
2265 Valid values are nil, t, `head', `first', `last', an integer or a
2266 predicate. See Info node `(gnus)Customizing Articles'."
2267 :version "23.1" ;; No Gnus
2268 :group 'gnus-article
2269 ;; :link '(custom-manual "(gnus)Customizing Articles")
2270 :type 'boolean)
2271
2272 (defun gnus-article-toggle-truncate-lines (&optional arg)
2273 "Toggle whether to fold or truncate long lines in article the buffer.
2274 If ARG is non-nil and not a number, toggle
2275 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2276 long lines if and only if arg is positive."
2277 (interactive "P")
2278 (cond
2279 ((and (numberp arg) (> arg 0))
2280 (setq gnus-article-truncate-lines t))
2281 ((numberp arg)
2282 (setq gnus-article-truncate-lines nil))
2283 (arg
2284 (setq gnus-article-truncate-lines
2285 (not gnus-article-truncate-lines))))
2286 (gnus-with-article-buffer
2287 (cond
2288 ((and (numberp arg) (> arg 0))
2289 (setq truncate-lines nil))
2290 ((numberp arg)
2291 (setq truncate-lines t)))
2292 (toggle-truncate-lines)))
2293
2294 (defun gnus-article-treat-body-boundary ()
2295 "Place a boundary line at the end of the headers."
2296 (interactive)
2297 (when (and gnus-body-boundary-delimiter
2298 (> (length gnus-body-boundary-delimiter) 0))
2299 (gnus-with-article-headers
2300 (goto-char (point-max))
2301 (let ((start (point)))
2302 (insert "X-Boundary: ")
2303 (add-text-properties start (point) gnus-hidden-properties)
2304 (insert (let (str (max (window-width)))
2305 (while (>= max (length str))
2306 (setq str (concat str gnus-body-boundary-delimiter)))
2307 (substring str 0 max))
2308 "\n")
2309 (put-text-property start (point) 'gnus-decoration 'header)))))
2310
2311 (defun article-fill-long-lines ()
2312 "Fill lines that are wider than the window width."
2313 (interactive)
2314 (save-excursion
2315 (let ((inhibit-read-only t)
2316 (width (window-width (get-buffer-window (current-buffer)))))
2317 (save-restriction
2318 (article-goto-body)
2319 (let ((adaptive-fill-mode nil)) ;Why? -sm
2320 (while (not (eobp))
2321 (end-of-line)
2322 (when (>= (current-column) (min fill-column width))
2323 (narrow-to-region (min (1+ (point)) (point-max))
2324 (point-at-bol))
2325 (let ((goback (point-marker)))
2326 (fill-paragraph nil)
2327 (goto-char (marker-position goback)))
2328 (widen))
2329 (forward-line 1)))))))
2330
2331 (defun article-capitalize-sentences ()
2332 "Capitalize the first word in each sentence."
2333 (interactive)
2334 (save-excursion
2335 (let ((inhibit-read-only t)
2336 (paragraph-start "^[\n\^L]"))
2337 (article-goto-body)
2338 (while (not (eobp))
2339 (capitalize-word 1)
2340 (forward-sentence)))))
2341
2342 (defun article-remove-cr ()
2343 "Remove trailing CRs and then translate remaining CRs into LFs."
2344 (interactive)
2345 (save-excursion
2346 (let ((inhibit-read-only t))
2347 (goto-char (point-min))
2348 (while (re-search-forward "\r+$" nil t)
2349 (replace-match "" t t))
2350 (goto-char (point-min))
2351 (while (search-forward "\r" nil t)
2352 (replace-match "\n" t t)))))
2353
2354 (defun article-remove-trailing-blank-lines ()
2355 "Remove all trailing blank lines from the article."
2356 (interactive)
2357 (save-excursion
2358 (let ((inhibit-read-only t))
2359 (goto-char (point-max))
2360 (delete-region
2361 (point)
2362 (progn
2363 (while (and (not (bobp))
2364 (looking-at "^[ \t]*$")
2365 (not (gnus-annotation-in-region-p
2366 (point) (point-at-eol))))
2367 (forward-line -1))
2368 (forward-line 1)
2369 (point))))))
2370
2371 (defvar gnus-face-properties-alist)
2372
2373 (defun article-display-face (&optional force)
2374 "Display any Face headers in the header."
2375 (interactive (list 'force))
2376 (let ((wash-face-p buffer-read-only))
2377 (gnus-with-article-headers
2378 ;; When displaying parts, this function can be called several times on
2379 ;; the same article, without any intended toggle semantic (as typing `W
2380 ;; D d' would have). So face deletion must occur only when we come from
2381 ;; an interactive command, that is when the *Article* buffer is
2382 ;; read-only.
2383 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2384 (gnus-delete-images 'face)
2385 (let ((from (message-fetch-field "from"))
2386 faces)
2387 (save-current-buffer
2388 (when (and wash-face-p
2389 (gnus-buffer-live-p gnus-original-article-buffer)
2390 (not (re-search-forward "^Face:[\t ]*" nil t)))
2391 (set-buffer gnus-original-article-buffer))
2392 (save-restriction
2393 (mail-narrow-to-head)
2394 (when (or force
2395 ;; Check whether this face is censored.
2396 (not (and gnus-article-x-face-too-ugly
2397 (or from
2398 (setq from (message-fetch-field "from")))
2399 (string-match gnus-article-x-face-too-ugly
2400 from))))
2401 (while (gnus-article-goto-header "Face")
2402 (push (mail-header-field-value) faces)))))
2403 (when faces
2404 (goto-char (point-min))
2405 (let (png image)
2406 (unless (setq from (gnus-article-goto-header "from"))
2407 (insert "From:")
2408 (setq from (point))
2409 (insert " [no 'from' set]\n"))
2410 (while faces
2411 (when (setq png (gnus-convert-face-to-png (pop faces)))
2412 (setq image
2413 (apply 'gnus-create-image png 'png t
2414 (cdr (assq 'png gnus-face-properties-alist))))
2415 (goto-char from)
2416 (when image
2417 (gnus-add-wash-type 'face)
2418 (gnus-add-image 'face image)
2419 (gnus-put-image image nil 'face)))))))))))
2420
2421 (defun article-display-x-face (&optional force)
2422 "Look for an X-Face header and display it if present."
2423 (interactive (list 'force))
2424 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2425 (gnus-with-article-headers
2426 ;; Delete the old process, if any.
2427 (when (process-status "article-x-face")
2428 (delete-process "article-x-face"))
2429 ;; See the comment in `article-display-face'.
2430 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2431 ;; We have already displayed X-Faces, so we remove them
2432 ;; instead.
2433 (gnus-delete-images 'xface)
2434 ;; Display X-Faces.
2435 (let ((from (message-fetch-field "from"))
2436 x-faces)
2437 (save-current-buffer
2438 (when (and wash-face-p
2439 (gnus-buffer-live-p gnus-original-article-buffer)
2440 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2441 ;; If type `W f', use gnus-original-article-buffer,
2442 ;; otherwise use the current buffer because displaying
2443 ;; RFC822 parts calls this function too.
2444 (set-buffer gnus-original-article-buffer))
2445 (save-restriction
2446 (mail-narrow-to-head)
2447 (and gnus-article-x-face-command
2448 (or force
2449 ;; Check whether this face is censored.
2450 (not (and gnus-article-x-face-too-ugly
2451 (or from
2452 (setq from (message-fetch-field "from")))
2453 (string-match gnus-article-x-face-too-ugly
2454 from))))
2455 (while (gnus-article-goto-header "X-Face")
2456 (push (mail-header-field-value) x-faces)))))
2457 (when x-faces
2458 ;; We display the face.
2459 (cond ((functionp gnus-article-x-face-command)
2460 ;; The command is a lisp function, so we call it.
2461 (mapc gnus-article-x-face-command x-faces))
2462 ((stringp gnus-article-x-face-command)
2463 ;; The command is a string, so we interpret the command
2464 ;; as a, well, command, and fork it off.
2465 (let ((process-connection-type nil))
2466 (set-process-query-on-exit-flag
2467 (start-process
2468 "article-x-face" nil shell-file-name
2469 shell-command-switch gnus-article-x-face-command)
2470 nil)
2471 ;; Sending multiple EOFs to xv doesn't work,
2472 ;; so we only do a single external face.
2473 (with-temp-buffer
2474 (insert (car x-faces))
2475 (process-send-region "article-x-face"
2476 (point-min) (point-max)))
2477 (process-send-eof "article-x-face")))
2478 (t
2479 (error "`%s' set to `%s' is not a function"
2480 gnus-article-x-face-command
2481 'gnus-article-x-face-command)))))))))
2482
2483 (defun article-decode-mime-words ()
2484 "Decode all MIME-encoded words in the article."
2485 (interactive)
2486 (gnus-with-article-buffer
2487 (let ((inhibit-point-motion-hooks t)
2488 (mail-parse-charset gnus-newsgroup-charset)
2489 (mail-parse-ignored-charsets
2490 (with-current-buffer gnus-summary-buffer
2491 gnus-newsgroup-ignored-charsets)))
2492 (mail-decode-encoded-word-region (point-min) (point-max)))))
2493
2494 (defun article-decode-charset (&optional prompt)
2495 "Decode charset-encoded text in the article.
2496 If PROMPT (the prefix), prompt for a coding system to use."
2497 (interactive "P")
2498 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2499 (inhibit-read-only t)
2500 (mail-parse-charset gnus-newsgroup-charset)
2501 (mail-parse-ignored-charsets
2502 (save-excursion (condition-case nil
2503 (set-buffer gnus-summary-buffer)
2504 (error))
2505 gnus-newsgroup-ignored-charsets))
2506 ct cte ctl charset format)
2507 (save-excursion
2508 (save-restriction
2509 (article-narrow-to-head)
2510 (setq ct (message-fetch-field "Content-Type" t)
2511 cte (message-fetch-field "Content-Transfer-Encoding" t)
2512 ctl (and ct (mail-header-parse-content-type ct))
2513 charset (cond
2514 (prompt
2515 (read-coding-system "Charset to decode: "))
2516 (ctl
2517 (mail-content-type-get ctl 'charset)))
2518 format (and ctl (mail-content-type-get ctl 'format)))
2519 (when cte
2520 (setq cte (mail-header-strip cte)))
2521 (if (and ctl (not (string-match "/" (car ctl))))
2522 (setq ctl nil))
2523 (goto-char (point-max)))
2524 (forward-line 1)
2525 (save-restriction
2526 (narrow-to-region (point) (point-max))
2527 (when (and (eq mail-parse-charset 'gnus-decoded)
2528 (eq (mm-body-7-or-8) '8bit))
2529 ;; The text code could have been decoded.
2530 (setq charset mail-parse-charset))
2531 (when (and (or (not ctl)
2532 (equal (car ctl) "text/plain"))
2533 (not format)) ;; article with format will decode later.
2534 (mm-decode-body
2535 charset (and cte (intern (downcase
2536 (gnus-strip-whitespace cte))))
2537 (car ctl)))))))
2538
2539 (defun article-decode-encoded-words ()
2540 "Remove encoded-word encoding from headers."
2541 (let ((inhibit-point-motion-hooks t)
2542 (mail-parse-charset gnus-newsgroup-charset)
2543 (mail-parse-ignored-charsets
2544 (save-excursion (condition-case nil
2545 (set-buffer gnus-summary-buffer)
2546 (error))
2547 gnus-newsgroup-ignored-charsets))
2548 (inhibit-read-only t)
2549 end start)
2550 (goto-char (point-min))
2551 (when (search-forward "\n\n" nil 'move)
2552 (forward-line -1))
2553 (setq end (point))
2554 (while (not (bobp))
2555 (while (progn
2556 (forward-line -1)
2557 (and (not (bobp))
2558 (memq (char-after) '(?\t ? )))))
2559 (setq start (point))
2560 (if (looking-at "\
2561 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2562 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2563 (funcall gnus-decode-address-function start end)
2564 (funcall gnus-decode-header-function start end))
2565 (goto-char (setq end start)))))
2566
2567 (defun article-decode-group-name ()
2568 "Decode group names in Newsgroups, Followup-To and Xref headers."
2569 (let ((inhibit-point-motion-hooks t)
2570 (inhibit-read-only t)
2571 (method (gnus-find-method-for-group gnus-newsgroup-name))
2572 regexp)
2573 (when (and (or gnus-group-name-charset-method-alist
2574 gnus-group-name-charset-group-alist)
2575 (gnus-buffer-live-p gnus-original-article-buffer))
2576 (save-restriction
2577 (article-narrow-to-head)
2578 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2579 (with-current-buffer gnus-original-article-buffer
2580 (goto-char (point-min)))
2581 (setq regexp (concat "^" header
2582 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2583 (while (re-search-forward regexp nil t)
2584 (replace-match (save-match-data
2585 (gnus-decode-newsgroups
2586 ;; XXX how to use data in article buffer?
2587 (with-current-buffer gnus-original-article-buffer
2588 (re-search-forward regexp nil t)
2589 (match-string 1))
2590 gnus-newsgroup-name method))
2591 t t nil 1))
2592 (goto-char (point-min)))))))
2593
2594 (autoload 'idna-to-unicode "idna")
2595
2596 (defun article-decode-idna-rhs ()
2597 "Decode IDNA strings in RHS in various headers in current buffer.
2598 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2599 Mail-Reply-To: and Mail-Followup-To:."
2600 (when gnus-use-idna
2601 (save-restriction
2602 (let ((inhibit-point-motion-hooks t)
2603 (inhibit-read-only t))
2604 (article-narrow-to-head)
2605 (goto-char (point-min))
2606 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2607 (let (ace unicode)
2608 (when (save-match-data
2609 (and (setq ace (match-string 1))
2610 (save-excursion
2611 (and (re-search-backward "^[^ \t]" nil t)
2612 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2613 (setq unicode (idna-to-unicode ace))))
2614 (unless (string= ace unicode)
2615 (replace-match unicode nil nil nil 1)))))))))
2616
2617 (defun article-de-quoted-unreadable (&optional force read-charset)
2618 "Translate a quoted-printable-encoded article.
2619 If FORCE, decode the article whether it is marked as quoted-printable
2620 or not.
2621 If READ-CHARSET, ask for a coding system."
2622 (interactive (list 'force current-prefix-arg))
2623 (save-excursion
2624 (let ((inhibit-read-only t) type charset)
2625 (if (gnus-buffer-live-p gnus-original-article-buffer)
2626 (with-current-buffer gnus-original-article-buffer
2627 (setq type
2628 (gnus-fetch-field "content-transfer-encoding"))
2629 (let* ((ct (gnus-fetch-field "content-type"))
2630 (ctl (and ct (mail-header-parse-content-type ct))))
2631 (setq charset (and ctl
2632 (mail-content-type-get ctl 'charset)))
2633 (if (stringp charset)
2634 (setq charset (intern (downcase charset)))))))
2635 (if read-charset
2636 (setq charset (read-coding-system "Charset: " charset)))
2637 (unless charset
2638 (setq charset gnus-newsgroup-charset))
2639 (when (or force
2640 (and type (let ((case-fold-search t))
2641 (string-match "quoted-printable" type))))
2642 (article-goto-body)
2643 (quoted-printable-decode-region
2644 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2645
2646 (defun article-de-base64-unreadable (&optional force read-charset)
2647 "Translate a base64 article.
2648 If FORCE, decode the article whether it is marked as base64 not.
2649 If READ-CHARSET, ask for a coding system."
2650 (interactive (list 'force current-prefix-arg))
2651 (save-excursion
2652 (let ((inhibit-read-only t) type charset)
2653 (if (gnus-buffer-live-p gnus-original-article-buffer)
2654 (with-current-buffer gnus-original-article-buffer
2655 (setq type
2656 (gnus-fetch-field "content-transfer-encoding"))
2657 (let* ((ct (gnus-fetch-field "content-type"))
2658 (ctl (and ct (mail-header-parse-content-type ct))))
2659 (setq charset (and ctl
2660 (mail-content-type-get ctl 'charset)))
2661 (if (stringp charset)
2662 (setq charset (intern (downcase charset)))))))
2663 (if read-charset
2664 (setq charset (read-coding-system "Charset: " charset)))
2665 (unless charset
2666 (setq charset gnus-newsgroup-charset))
2667 (when (or force
2668 (and type (let ((case-fold-search t))
2669 (string-match "base64" type))))
2670 (article-goto-body)
2671 (save-restriction
2672 (narrow-to-region (point) (point-max))
2673 (base64-decode-region (point-min) (point-max))
2674 (decode-coding-region
2675 (point-min) (point-max)
2676 (mm-charset-to-coding-system charset nil t)))))))
2677
2678 (declare-function rfc1843-decode-region "rfc1843" (from to))
2679
2680 (defun article-decode-HZ ()
2681 "Translate a HZ-encoded article."
2682 (interactive)
2683 (require 'rfc1843)
2684 (save-excursion
2685 (let ((inhibit-read-only t))
2686 (rfc1843-decode-region (point-min) (point-max)))))
2687
2688 (defun article-unsplit-urls ()
2689 "Remove the newlines that some other mailers insert into URLs."
2690 (interactive)
2691 (save-excursion
2692 (let ((inhibit-read-only t))
2693 (goto-char (point-min))
2694 (while (re-search-forward
2695 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2696 (replace-match "\\1\\3" t)))
2697 (when (called-interactively-p 'any)
2698 (gnus-treat-article nil))))
2699
2700 (defun article-wash-html ()
2701 "Format an HTML article."
2702 (interactive)
2703 (let ((handles nil)
2704 (buffer-read-only nil))
2705 (when (gnus-buffer-live-p gnus-original-article-buffer)
2706 (with-current-buffer gnus-original-article-buffer
2707 (setq handles (mm-dissect-buffer t t))))
2708 (article-goto-body)
2709 (delete-region (point) (point-max))
2710 (mm-enable-multibyte)
2711 (mm-inline-text-html handles)))
2712
2713 (defvar gnus-article-browse-html-temp-list nil
2714 "List of temporary files created by `gnus-article-browse-html-parts'.
2715 Internal variable.")
2716
2717 (defcustom gnus-article-browse-delete-temp 'ask
2718 "What to do with temporary files from `gnus-article-browse-html-parts'.
2719 If nil, don't delete temporary files. If it is t, delete them on
2720 exit from the summary buffer. If it is the symbol `file', query
2721 on each file, if it is `ask' ask once when exiting from the
2722 summary buffer."
2723 :group 'gnus-article
2724 :version "23.1" ;; No Gnus
2725 :type '(choice (const :tag "Don't delete" nil)
2726 (const :tag "Don't ask" t)
2727 (const :tag "Ask" ask)
2728 (const :tag "Ask for each file" file)))
2729
2730 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2731
2732 (defun gnus-article-browse-delete-temp-files (&optional how)
2733 "Delete temp-files created by `gnus-article-browse-html-parts'."
2734 (when (and gnus-article-browse-html-temp-list
2735 (progn
2736 (or how (setq how gnus-article-browse-delete-temp))
2737 (if (eq how 'ask)
2738 (let ((files (length gnus-article-browse-html-temp-list)))
2739 (or (gnus-y-or-n-p
2740 (if (= files 1)
2741 "Delete the temporary HTML file? "
2742 (format "Delete all %s temporary HTML files? "
2743 files)))
2744 (setq gnus-article-browse-html-temp-list nil)))
2745 how)))
2746 (dolist (file gnus-article-browse-html-temp-list)
2747 (cond ((file-directory-p file)
2748 (when (or (not (eq how 'file))
2749 (gnus-y-or-n-p
2750 (format-message
2751 "Delete temporary HTML file(s) in directory `%s'? "
2752 (file-name-as-directory file))))
2753 (gnus-delete-directory file)))
2754 ((file-exists-p file)
2755 (when (or (not (eq how 'file))
2756 (gnus-y-or-n-p
2757 (format "Delete temporary HTML file `%s'? " file)))
2758 (delete-file file)))))
2759 ;; Also remove file from the list when not deleted or if file doesn't
2760 ;; exist anymore.
2761 (setq gnus-article-browse-html-temp-list nil))
2762 gnus-article-browse-html-temp-list)
2763
2764 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2765 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2766 Return file name relative to the parent of DIRECTORY."
2767 (save-match-data
2768 (let (file afile)
2769 (catch 'found
2770 (dolist (handle handles)
2771 (cond
2772 ((not (listp handle)))
2773 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2774 ;; may create.
2775 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2776 ((equal (mm-handle-media-supertype handle) "multipart")
2777 (when (setq file (gnus-article-browse-html-save-cid-content
2778 cid handle directory))
2779 (throw 'found file)))
2780 ((equal (concat "<" cid ">") (mm-handle-id handle))
2781 (setq file (or (mm-handle-filename handle)
2782 (concat
2783 (make-temp-name "cid")
2784 (car (rassoc (car (mm-handle-type handle))
2785 mailcap-mime-extensions))))
2786 afile (expand-file-name file directory))
2787 (mm-save-part-to-file handle afile)
2788 (throw 'found (concat (file-name-nondirectory
2789 (directory-file-name directory))
2790 "/" file)))))))))
2791
2792 (defun gnus-article-browse-html-parts (list &optional header)
2793 "View all \"text/html\" parts from LIST.
2794 Recurse into multiparts. The optional HEADER that should be a decoded
2795 message header will be added to the bodies of the \"text/html\" parts."
2796 ;; Internal function used by `gnus-article-browse-html-article'.
2797 (let (type file charset content cid-dir tmp-file showed)
2798 ;; Find and show the html-parts.
2799 (dolist (handle list)
2800 ;; If HTML, show it:
2801 (cond ((not (listp handle)))
2802 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2803 (and (equal (car type) "message/external-body")
2804 (or header
2805 (setq file (mm-handle-filename handle)))
2806 (or (mm-handle-cache handle)
2807 (condition-case code
2808 (progn (mm-extern-cache-contents handle) t)
2809 (error
2810 (gnus-message 3 "%s" (error-message-string code))
2811 (when (>= gnus-verbose 3) (sit-for 2))
2812 nil)))
2813 (progn
2814 (setq handle (mm-handle-cache handle)
2815 type (mm-handle-type handle))
2816 (equal (car type) "text/html"))))
2817 (setq charset (mail-content-type-get type 'charset)
2818 content (mm-get-part handle))
2819 (with-temp-buffer
2820 (if (eq charset 'gnus-decoded)
2821 (mm-enable-multibyte)
2822 (mm-disable-multibyte))
2823 (insert content)
2824 ;; resolve cid contents
2825 (let ((case-fold-search t)
2826 st base regexp cid-file)
2827 (goto-char (point-min))
2828 (when (and (re-search-forward "<head[\t\n >]" nil t)
2829 (progn
2830 (setq st (match-end 0))
2831 (re-search-forward "</head[\t\n >]" nil t))
2832 (re-search-backward "<base\
2833 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2834 (setq base (match-string 1))
2835 (replace-match "<!--\\&-->")
2836 (setq st (point))
2837 (dolist (tag '(("a" . "href") ("form" . "action")
2838 ("img" . "src")))
2839 (setq regexp (concat "<" (car tag)
2840 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2841 (cdr tag) "=\"\\([^\"]+\\)"))
2842 (while (re-search-forward regexp nil t)
2843 (insert (prog1
2844 (condition-case nil
2845 (save-match-data
2846 (url-expand-file-name (match-string 1)
2847 base))
2848 (error (match-string 1)))
2849 (delete-region (match-beginning 1)
2850 (match-end 1)))))
2851 (goto-char st)))
2852 (while (re-search-forward "\
2853 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2854 nil t)
2855 (unless cid-dir
2856 (setq cid-dir (make-temp-file "cid" t))
2857 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2858 (setq file nil
2859 content nil)
2860 (when (setq cid-file
2861 (gnus-article-browse-html-save-cid-content
2862 (match-string 2)
2863 (with-current-buffer gnus-article-buffer
2864 gnus-article-mime-handles)
2865 cid-dir))
2866 (replace-match cid-file nil nil nil 1))))
2867 (unless content (setq content (buffer-string))))
2868 (when (or charset header (not file))
2869 (setq tmp-file (make-temp-file
2870 ;; Do we need to care for 8.3 filenames?
2871 "mm-" nil ".html")))
2872 ;; Add a meta html tag to specify charset and a header.
2873 (cond
2874 (header
2875 (let (title eheader body hcharset coding)
2876 (with-temp-buffer
2877 (mm-enable-multibyte)
2878 (setq case-fold-search t)
2879 (insert header "\n")
2880 (setq title (message-fetch-field "subject"))
2881 (goto-char (point-min))
2882 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2883 nil t)
2884 (replace-match (cond ((match-beginning 1) "&lt;")
2885 ((match-beginning 2) "&gt;")
2886 ((match-beginning 3) "&amp;")
2887 (t "<br>\n"))))
2888 (goto-char (point-min))
2889 (while (re-search-forward "^[\t ]+" nil t)
2890 (dotimes (i (prog1
2891 (current-column)
2892 (delete-region (match-beginning 0)
2893 (match-end 0))))
2894 (insert "&nbsp;")))
2895 (goto-char (point-min))
2896 (insert "<div align=\"left\">\n")
2897 (goto-char (point-max))
2898 (insert "</div>\n<hr>\n")
2899 ;; We have to examine charset one by one since
2900 ;; charset specified in parts might be different.
2901 (if (eq charset 'gnus-decoded)
2902 (setq charset 'utf-8
2903 eheader (encode-coding-string (buffer-string)
2904 charset)
2905 title (when title
2906 (encode-coding-string title charset))
2907 body (encode-coding-string content charset))
2908 (setq hcharset (mm-find-mime-charset-region (point-min)
2909 (point-max)))
2910 (cond ((= (length hcharset) 1)
2911 (setq hcharset (car hcharset)
2912 coding (mm-charset-to-coding-system
2913 hcharset nil t)))
2914 ((> (length hcharset) 1)
2915 (setq hcharset 'utf-8
2916 coding hcharset)))
2917 (if coding
2918 (if charset
2919 (progn
2920 (setq body
2921 (mm-charset-to-coding-system charset
2922 nil t))
2923 (if (eq coding body)
2924 (setq eheader (encode-coding-string
2925 (buffer-string) coding)
2926 title (when title
2927 (encode-coding-string
2928 title coding))
2929 body content)
2930 (setq charset 'utf-8
2931 eheader (encode-coding-string
2932 (buffer-string) charset)
2933 title (when title
2934 (encode-coding-string
2935 title charset))
2936 body (encode-coding-string
2937 (decode-coding-string
2938 content body)
2939 charset))))
2940 (setq charset hcharset
2941 eheader (encode-coding-string
2942 (buffer-string) coding)
2943 title (when title
2944 (encode-coding-string
2945 title coding))
2946 body content))
2947 (setq eheader (string-as-unibyte (buffer-string))
2948 body content)))
2949 (erase-buffer)
2950 (mm-disable-multibyte)
2951 (insert body)
2952 (when charset
2953 (mm-add-meta-html-tag handle charset t))
2954 (when title
2955 (goto-char (point-min))
2956 (unless (search-forward "<title>" nil t)
2957 (re-search-forward "<head>\\s-*" nil t)
2958 (insert "<title>" title "</title>\n")))
2959 (goto-char (point-min))
2960 (or (re-search-forward
2961 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2962 (re-search-forward
2963 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2964 (insert eheader)
2965 (mm-write-region (point-min) (point-max)
2966 tmp-file nil nil nil 'binary t))))
2967 (charset
2968 (mm-with-unibyte-buffer
2969 (insert (if (eq charset 'gnus-decoded)
2970 (encode-coding-string content
2971 (setq charset 'utf-8))
2972 content))
2973 (if (or (mm-add-meta-html-tag handle charset)
2974 (not file))
2975 (mm-write-region (point-min) (point-max)
2976 tmp-file nil nil nil 'binary t)
2977 (setq tmp-file nil))))
2978 (tmp-file
2979 (mm-save-part-to-file handle tmp-file)))
2980 (when tmp-file
2981 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2982 (add-hook 'gnus-summary-prepare-exit-hook
2983 'gnus-article-browse-delete-temp-files)
2984 (add-hook 'gnus-exit-gnus-hook
2985 (lambda ()
2986 (gnus-article-browse-delete-temp-files t)))
2987 ;; FIXME: Warn if there's an <img> tag?
2988 (browse-url-of-file (or tmp-file (expand-file-name file)))
2989 (setq showed t))
2990 ;; If multipart, recurse
2991 ((equal (mm-handle-media-supertype handle) "multipart")
2992 (when (gnus-article-browse-html-parts handle header)
2993 (setq showed t)))
2994 ((equal (mm-handle-media-type handle) "message/rfc822")
2995 (mm-with-multibyte-buffer
2996 (mm-insert-part handle)
2997 (setq handle (mm-dissect-buffer t t))
2998 (when (and (bufferp (car handle))
2999 (stringp (car (mm-handle-type handle))))
3000 (setq handle (list handle)))
3001 (when header
3002 (article-decode-encoded-words)
3003 (let ((gnus-visible-headers
3004 (or (get 'gnus-visible-headers 'standard-value)
3005 gnus-visible-headers)))
3006 (article-hide-headers))
3007 (goto-char (point-min))
3008 (search-forward "\n\n" nil 'move)
3009 (skip-chars-backward "\t\n ")
3010 (setq header (buffer-substring (point-min) (point)))))
3011 (when (prog1
3012 (gnus-article-browse-html-parts handle header)
3013 (mm-destroy-parts handle))
3014 (setq showed t)))))
3015 showed))
3016
3017 (defun gnus-article-browse-html-article (&optional arg)
3018 "View \"text/html\" parts of the current article with a WWW browser.
3019 Inline images embedded in a message using the cid scheme, as they are
3020 generally considered to be safe, will be processed properly.
3021 The message header is added to the beginning of every html part unless
3022 the prefix argument ARG is given.
3023
3024 Warning: Spammers use links to images (using the http scheme) in HTML
3025 articles to verify whether you have read the message. As
3026 `gnus-article-browse-html-article' passes the HTML content to the
3027 browser without eliminating these \"web bugs\" you should only
3028 use it for mails from trusted senders.
3029
3030 If you always want to display HTML parts in the browser, set
3031 `mm-text-html-renderer' to nil.
3032
3033 This command creates temporary files to pass HTML contents including
3034 images if any to the browser, and deletes them when exiting the group
3035 \(if you want)."
3036 ;; Cf. `mm-w3m-safe-url-regexp'
3037 (interactive "P")
3038 (if arg
3039 (gnus-summary-show-article)
3040 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3041 gnus-visible-headers))
3042 ;; As we insert a <hr>, there's no need for the body boundary.
3043 (gnus-treat-body-boundary nil))
3044 (gnus-summary-show-article)))
3045 (with-current-buffer gnus-article-buffer
3046 (let ((header (unless arg
3047 (save-restriction
3048 (widen)
3049 (buffer-substring-no-properties
3050 (goto-char (point-min))
3051 (if (search-forward "\n\n" nil t)
3052 (match-beginning 0)
3053 (goto-char (point-max))
3054 (skip-chars-backward "\t\n ")
3055 (point))))))
3056 parts)
3057 (set-buffer gnus-original-article-buffer)
3058 (setq parts (mm-dissect-buffer t t))
3059 ;; If singlepart, enforce a list.
3060 (when (and (bufferp (car parts))
3061 (stringp (car (mm-handle-type parts))))
3062 (setq parts (list parts)))
3063 ;; Process the list
3064 (unless (gnus-article-browse-html-parts parts header)
3065 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3066 (mm-destroy-parts parts)
3067 (unless arg
3068 (gnus-summary-show-article)))))
3069
3070 (defun article-hide-list-identifiers ()
3071 "Remove list identifiers from the Subject header.
3072 The `gnus-list-identifiers' variable specifies what to do."
3073 (interactive)
3074 (let ((inhibit-point-motion-hooks t)
3075 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3076 (inhibit-read-only t))
3077 (when regexp
3078 (save-excursion
3079 (save-restriction
3080 (article-narrow-to-head)
3081 (goto-char (point-min))
3082 (while (re-search-forward
3083 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3084 nil t)
3085 (delete-region (match-beginning 2) (match-end 0))
3086 (beginning-of-line))
3087 (when (re-search-forward
3088 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3089 (delete-region (match-beginning 1) (match-end 1))))))))
3090
3091 (defun article-hide-pem (&optional arg)
3092 "Toggle hiding of any PEM headers and signatures in the current article.
3093 If given a negative prefix, always show; if given a positive prefix,
3094 always hide."
3095 (interactive (gnus-article-hidden-arg))
3096 (unless (gnus-article-check-hidden-text 'pem arg)
3097 (save-excursion
3098 (let ((inhibit-read-only t) end)
3099 (goto-char (point-min))
3100 ;; Hide the horrendously ugly "header".
3101 (when (and (search-forward
3102 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3103 nil t)
3104 (setq end (1+ (match-beginning 0))))
3105 (gnus-add-wash-type 'pem)
3106 (gnus-article-hide-text-type
3107 end
3108 (if (search-forward "\n\n" nil t)
3109 (match-end 0)
3110 (point-max))
3111 'pem)
3112 ;; Hide the trailer as well
3113 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3114 nil t)
3115 (gnus-article-hide-text-type
3116 (match-beginning 0) (match-end 0) 'pem)))))))
3117
3118 (defun article-strip-banner ()
3119 "Strip the banners specified by the `banner' group parameter and by
3120 `gnus-article-address-banner-alist'."
3121 (interactive)
3122 (save-excursion
3123 (save-restriction
3124 (let ((inhibit-point-motion-hooks t))
3125 (when (gnus-parameter-banner gnus-newsgroup-name)
3126 (article-really-strip-banner
3127 (gnus-parameter-banner gnus-newsgroup-name)))
3128 (when gnus-article-address-banner-alist
3129 ;; Note that the From header is decoded here, so it is
3130 ;; required that the *-extract-address-components function
3131 ;; supports non-ASCII text.
3132 (let ((from (save-restriction
3133 (widen)
3134 (article-narrow-to-head)
3135 (mail-fetch-field "from"))))
3136 (when (and from
3137 (setq from
3138 (cadr (funcall gnus-extract-address-components
3139 from))))
3140 (catch 'found
3141 (dolist (pair gnus-article-address-banner-alist)
3142 (when (string-match (car pair) from)
3143 (throw 'found
3144 (article-really-strip-banner (cdr pair)))))))))))))
3145
3146 (defun article-really-strip-banner (banner)
3147 "Strip the banner specified by the argument."
3148 (save-excursion
3149 (save-restriction
3150 (let ((inhibit-point-motion-hooks t)
3151 (gnus-signature-limit nil)
3152 (inhibit-read-only t))
3153 (article-goto-body)
3154 (cond
3155 ((eq banner 'signature)
3156 (when (gnus-article-narrow-to-signature)
3157 (widen)
3158 (forward-line -1)
3159 (delete-region (point) (point-max))))
3160 ((symbolp banner)
3161 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3162 (while (re-search-forward banner nil t)
3163 (delete-region (match-beginning 0) (match-end 0)))))
3164 ((stringp banner)
3165 (while (re-search-forward banner nil t)
3166 (delete-region (match-beginning 0) (match-end 0)))))))))
3167
3168 (defun article-babel ()
3169 "Translate article using an online translation service."
3170 (interactive)
3171 (require 'babel)
3172 (gnus-with-article-buffer
3173 (when (article-goto-body)
3174 (let* ((start (point))
3175 (end (point-max))
3176 (orig (buffer-substring start end))
3177 (trans (babel-as-string orig)))
3178 (save-restriction
3179 (narrow-to-region start end)
3180 (delete-region start end)
3181 (insert trans))))))
3182
3183 (defun article-hide-signature (&optional arg)
3184 "Hide the signature in the current article.
3185 If given a negative prefix, always show; if given a positive prefix,
3186 always hide."
3187 (interactive (gnus-article-hidden-arg))
3188 (unless (gnus-article-check-hidden-text 'signature arg)
3189 (save-excursion
3190 (save-restriction
3191 (let ((inhibit-read-only t))
3192 (when (gnus-article-narrow-to-signature)
3193 (gnus-article-hide-text-type
3194 (point-min) (point-max) 'signature))))))
3195 (gnus-set-mode-line 'article))
3196
3197 (defun article-strip-headers-in-body ()
3198 "Strip offensive headers from bodies."
3199 (interactive)
3200 (save-excursion
3201 (article-goto-body)
3202 (let ((case-fold-search t))
3203 (when (looking-at "x-no-archive:")
3204 (gnus-delete-line)))))
3205
3206 (defun article-strip-leading-blank-lines ()
3207 "Remove all blank lines from the beginning of the article."
3208 (interactive)
3209 (save-excursion
3210 (let ((inhibit-point-motion-hooks t)
3211 (inhibit-read-only t))
3212 (when (article-goto-body)
3213 (while (and (not (eobp))
3214 (looking-at "[ \t]*$"))
3215 (gnus-delete-line))))))
3216
3217 (defun article-narrow-to-head ()
3218 "Narrow the buffer to the head of the message.
3219 Point is left at the beginning of the narrowed-to region."
3220 (narrow-to-region
3221 (goto-char (point-min))
3222 (cond
3223 ;; Absolutely no headers displayed.
3224 ((looking-at "\n")
3225 (point))
3226 ;; Normal headers.
3227 ((search-forward "\n\n" nil 1)
3228 (1- (point)))
3229 ;; Nothing but headers.
3230 (t
3231 (point-max))))
3232 (goto-char (point-min)))
3233
3234 (defun article-goto-body ()
3235 "Place point at the start of the body."
3236 (goto-char (point-min))
3237 (cond
3238 ;; This variable is only bound when dealing with separate
3239 ;; MIME body parts.
3240 (article-goto-body-goes-to-point-min-p
3241 t)
3242 ((search-forward "\n\n" nil t)
3243 t)
3244 (t
3245 (goto-char (point-max))
3246 nil)))
3247
3248 (defun article-strip-multiple-blank-lines ()
3249 "Replace consecutive blank lines with one empty line."
3250 (interactive)
3251 (save-excursion
3252 (let ((inhibit-point-motion-hooks t)
3253 (inhibit-read-only t))
3254 ;; First make all blank lines empty.
3255 (article-goto-body)
3256 (while (re-search-forward "^[ \t]+$" nil t)
3257 (unless (gnus-annotation-in-region-p
3258 (match-beginning 0) (match-end 0))
3259 (replace-match "" nil t)))
3260 ;; Then replace multiple empty lines with a single empty line.
3261 (article-goto-body)
3262 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3263 (unless (gnus-annotation-in-region-p
3264 (match-beginning 0) (match-end 0))
3265 (delete-region (match-beginning 1) (match-end 1)))))))
3266
3267 (defun article-strip-leading-space ()
3268 "Remove all white space from the beginning of the lines in the article."
3269 (interactive)
3270 (save-excursion
3271 (let ((inhibit-point-motion-hooks t)
3272 (inhibit-read-only t))
3273 (article-goto-body)
3274 (while (re-search-forward "^[ \t]+" nil t)
3275 (replace-match "" t t)))))
3276
3277 (defun article-strip-trailing-space ()
3278 "Remove all white space from the end of the lines in the article."
3279 (interactive)
3280 (save-excursion
3281 (let ((inhibit-point-motion-hooks t)
3282 (inhibit-read-only t))
3283 (article-goto-body)
3284 (while (re-search-forward "[ \t]+$" nil t)
3285 (replace-match "" t t)))))
3286
3287 (defun article-strip-blank-lines ()
3288 "Strip leading, trailing and multiple blank lines."
3289 (interactive)
3290 (article-strip-leading-blank-lines)
3291 (article-remove-trailing-blank-lines)
3292 (article-strip-multiple-blank-lines))
3293
3294 (defun article-strip-all-blank-lines ()
3295 "Strip all blank lines."
3296 (interactive)
3297 (save-excursion
3298 (let ((inhibit-point-motion-hooks t)
3299 (inhibit-read-only t))
3300 (article-goto-body)
3301 (while (re-search-forward "^[ \t]*\n" nil t)
3302 (replace-match "" t t)))))
3303
3304 (defun gnus-article-narrow-to-signature ()
3305 "Narrow to the signature; return t if a signature is found, else nil."
3306 (let ((inhibit-point-motion-hooks t))
3307 (when (gnus-article-search-signature)
3308 (forward-line 1)
3309 ;; Check whether we have some limits to what we consider
3310 ;; to be a signature.
3311 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3312 (list gnus-signature-limit)))
3313 limit limited)
3314 (while (setq limit (pop limits))
3315 (if (or (and (integerp limit)
3316 (< (- (point-max) (point)) limit))
3317 (and (floatp limit)
3318 (< (count-lines (point) (point-max)) limit))
3319 (and (functionp limit)
3320 (funcall limit))
3321 (and (stringp limit)
3322 (not (re-search-forward limit nil t))))
3323 () ; This limit did not succeed.
3324 (setq limited t
3325 limits nil)))
3326 (unless limited
3327 (narrow-to-region (point) (point-max))
3328 t)))))
3329
3330 (defun gnus-article-search-signature ()
3331 "Search the current buffer for the signature separator.
3332 Put point at the beginning of the signature separator."
3333 (let ((cur (point)))
3334 (goto-char (point-max))
3335 (if (if (stringp gnus-signature-separator)
3336 (re-search-backward gnus-signature-separator nil t)
3337 (let ((seps gnus-signature-separator))
3338 (while (and seps
3339 (not (re-search-backward (car seps) nil t)))
3340 (pop seps))
3341 seps))
3342 t
3343 (goto-char cur)
3344 nil)))
3345
3346 (defun gnus-article-hidden-arg ()
3347 "Return the current prefix arg as a number, or 0 if no prefix."
3348 (list (if current-prefix-arg
3349 (prefix-numeric-value current-prefix-arg)
3350 0)))
3351
3352 (defun gnus-article-check-hidden-text (type arg)
3353 "Return nil if hiding is necessary.
3354 Arg can be nil or a number. nil and positive means hide, negative
3355 means show, 0 means toggle."
3356 (save-excursion
3357 (save-restriction
3358 (let ((hide (gnus-article-hidden-text-p type)))
3359 (cond
3360 ((or (null arg)
3361 (> arg 0))
3362 nil)
3363 ((< arg 0)
3364 (gnus-article-show-hidden-text type)
3365 t)
3366 (t
3367 (if (eq hide 'hidden)
3368 (progn
3369 (gnus-article-show-hidden-text type)
3370 t)
3371 nil)))))))
3372
3373 (defun gnus-article-hidden-text-p (type)
3374 "Say whether the current buffer contains hidden text of type TYPE."
3375 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3376 (while (and pos
3377 (not (get-text-property pos 'invisible))
3378 (not (get-text-property pos 'dummy-invisible)))
3379 (setq pos
3380 (text-property-any (1+ pos) (point-max) 'article-type type)))
3381 (if pos
3382 'hidden
3383 nil)))
3384
3385 (defun gnus-article-show-hidden-text (type &optional _dummy)
3386 "Show all hidden text of type TYPE.
3387 Originally it is hide instead of DUMMY."
3388 (let ((inhibit-read-only t)
3389 (inhibit-point-motion-hooks t))
3390 (gnus-remove-text-properties-when
3391 'article-type type
3392 (point-min) (point-max)
3393 (cons 'article-type (cons type
3394 gnus-hidden-properties)))
3395 (gnus-delete-wash-type type)))
3396
3397 (defconst article-time-units
3398 `((year . ,(* 365.25 24 60 60))
3399 (week . ,(* 7 24 60 60))
3400 (day . ,(* 24 60 60))
3401 (hour . ,(* 60 60))
3402 (minute . 60)
3403 (second . 1))
3404 "Mapping from time units to seconds.")
3405
3406 (defun gnus-article-forward-header ()
3407 "Move point to the start of the next header.
3408 If the current header is a continuation header, this can be several
3409 lines forward."
3410 (let ((ended nil))
3411 (while (not ended)
3412 (forward-line 1)
3413 (if (looking-at "[ \t]+[^ \t]")
3414 (forward-line 1)
3415 (setq ended t)))))
3416
3417 (defun article-treat-date ()
3418 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3419 (with-current-buffer gnus-summary-buffer
3420 gnus-article-date-headers)
3421 gnus-article-date-headers)
3422 t))
3423
3424 (defun article-date-ut (&optional type _highlight date-position)
3425 "Convert DATE date to TYPE in the current article.
3426 The default type is `ut'. See `gnus-article-date-headers' for
3427 possible values."
3428 (interactive (list 'ut t))
3429 (let* ((case-fold-search t)
3430 (inhibit-read-only t)
3431 (inhibit-point-motion-hooks t)
3432 (visible-date (mail-fetch-field "Date"))
3433 pos date bface eface)
3434 (save-excursion
3435 (if date-position
3436 (progn
3437 (goto-char date-position)
3438 (setq date (get-text-property (point) 'original-date))
3439 (when (looking-at "[^:]+:[\t ]*")
3440 (setq bface (get-text-property (match-beginning 0) 'face)
3441 eface (get-text-property (match-end 0) 'face)))
3442 (delete-region (point)
3443 (progn
3444 (gnus-article-forward-header)
3445 (point)))
3446 (article-transform-date date type bface eface))
3447 (save-restriction
3448 (widen)
3449 (goto-char (point-min))
3450 (while (or (get-text-property (setq pos (point)) 'original-date)
3451 (and (setq pos (next-single-property-change
3452 (point) 'original-date))
3453 (goto-char pos)))
3454 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3455 (1+ (match-beginning 0))
3456 (point-max)))
3457 (while (setq pos (text-property-not-all pos (point-max)
3458 'gnus-date-type nil))
3459 (setq date (get-text-property pos 'original-date))
3460 (goto-char pos)
3461 (when (looking-at "[^:]+:[\t ]*")
3462 (setq bface (get-text-property (match-beginning 0) 'face)
3463 eface (get-text-property (match-end 0) 'face)))
3464 (delete-region pos (or (text-property-any pos (point-max)
3465 'gnus-date-type nil)
3466 (point-max))))
3467 (unless date ;; the 1st time
3468 (goto-char (point-min))
3469 (while (re-search-forward "^Date:[\t ]*" nil t)
3470 (setq date (get-text-property (match-beginning 0)
3471 'original-date)
3472 bface (get-text-property (match-beginning 0) 'face)
3473 eface (get-text-property (match-end 0) 'face))
3474 (delete-region (point-at-bol) (progn
3475 (gnus-article-forward-header)
3476 (point)))))
3477 (when (and (not date)
3478 visible-date)
3479 (setq date visible-date))
3480 (when date
3481 (article-transform-date date type bface eface))
3482 (goto-char (point-max))
3483 (widen)))))))
3484
3485 (defun article-transform-date (date type bface eface)
3486 (dolist (this-type (cond
3487 ((null type)
3488 (list 'ut))
3489 ((atom type)
3490 (list type))
3491 (t
3492 type)))
3493 (goto-char
3494 (prog1
3495 (point)
3496 (add-text-properties
3497 (point)
3498 (progn
3499 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3500 (point))
3501 (list 'original-date date 'gnus-date-type this-type))))
3502 ;; Do highlighting.
3503 (when (looking-at
3504 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3505 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3506 (when (match-beginning 2)
3507 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3508 (while (and (zerop (forward-line 1))
3509 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3510 (when (match-beginning 1)
3511 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3512
3513 (defun article-make-date-line (date type)
3514 "Return a DATE line of TYPE."
3515 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3516 combined-lapsed))
3517 (error "Unknown conversion type: %s" type))
3518 (condition-case ()
3519 (let ((time (ignore-errors (date-to-time date))))
3520 (cond
3521 ;; Convert to the local timezone.
3522 ((eq type 'local)
3523 (concat "Date: " (message-make-date time)))
3524 ;; Convert to Universal Time.
3525 ((eq type 'ut)
3526 (concat "Date: "
3527 (substring
3528 (message-make-date
3529 (let* ((e (parse-time-string date))
3530 (tm (apply 'encode-time e))
3531 (ms (car tm))
3532 (ls (- (cadr tm) (car (current-time-zone time)))))
3533 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3534 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3535 (t (list ms ls)))))
3536 0 -5)
3537 "UT"))
3538 ;; Get the original date from the article.
3539 ((eq type 'original)
3540 (concat "Date: " (if (string-match "\n+$" date)
3541 (substring date 0 (match-beginning 0))
3542 date)))
3543 ;; Let the user define the format.
3544 ((eq type 'user-defined)
3545 (let ((format (or (condition-case nil
3546 (with-current-buffer gnus-summary-buffer
3547 gnus-article-time-format)
3548 (error nil))
3549 gnus-article-time-format)))
3550 (if (functionp format)
3551 (funcall format time)
3552 (concat "Date: " (format-time-string format time)))))
3553 ;; ISO 8601.
3554 ((eq type 'iso8601)
3555 (let ((tz (car (current-time-zone time))))
3556 (concat
3557 "Date: "
3558 (format-time-string "%Y%m%dT%H%M%S" time)
3559 (format "%s%02d%02d"
3560 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3561 (/ (% (abs tz) 3600) 60)))))
3562 ;; Do a lapsed format.
3563 ((eq type 'lapsed)
3564 (concat "Date: " (article-lapsed-string time)))
3565 ;; A combined date/lapsed format.
3566 ((eq type 'combined-lapsed)
3567 (let ((date-string (article-make-date-line date 'original))
3568 (segments 3)
3569 lapsed-string)
3570 (while (and
3571 time
3572 (setq lapsed-string
3573 (concat " (" (article-lapsed-string time segments) ")"))
3574 (> (+ (length date-string)
3575 (length lapsed-string))
3576 (+ fill-column 6))
3577 (> segments 0))
3578 (setq segments (1- segments)))
3579 (if (> segments 0)
3580 (concat date-string lapsed-string)
3581 date-string)))
3582 ;; Display the date in proper English
3583 ((eq type 'english)
3584 (let ((dtime (decode-time time)))
3585 (concat
3586 "Date: the "
3587 (number-to-string (nth 3 dtime))
3588 (let ((digit (% (nth 3 dtime) 10)))
3589 (cond
3590 ((memq (nth 3 dtime) '(11 12 13)) "th")
3591 ((= digit 1) "st")
3592 ((= digit 2) "nd")
3593 ((= digit 3) "rd")
3594 (t "th")))
3595 " of "
3596 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3597 " "
3598 (number-to-string (nth 5 dtime))
3599 " at "
3600 (format "%02d" (nth 2 dtime))
3601 ":"
3602 (format "%02d" (nth 1 dtime)))))))
3603 (foo
3604 (format "Date: %s (from Gnus)" date))))
3605
3606 (defun article-lapsed-string (time &optional max-segments)
3607 ;; If the date is seriously mangled, the timezone functions are
3608 ;; liable to bug out, so we ignore all errors.
3609 (let* ((now (current-time))
3610 (real-time (subtract-time now time))
3611 (real-sec (and real-time
3612 (+ (* (float (car real-time)) 65536)
3613 (cadr real-time))))
3614 (sec (and real-time (abs real-sec)))
3615 (segments 0)
3616 num prev)
3617 (unless max-segments
3618 (setq max-segments (length article-time-units)))
3619 (cond
3620 ((null real-time)
3621 "Unknown")
3622 ((zerop sec)
3623 "Now")
3624 (t
3625 (concat
3626 ;; This is a bit convoluted, but basically we go
3627 ;; through the time units for years, weeks, etc,
3628 ;; and divide things to see whether that results
3629 ;; in positive answers.
3630 (mapconcat
3631 (lambda (unit)
3632 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3633 (>= segments max-segments))
3634 ;; The (remaining) seconds are too few to
3635 ;; be divided into this time unit.
3636 ""
3637 ;; It's big enough, so we output it.
3638 (setq sec (- sec (* num (cdr unit))))
3639 (prog1
3640 (concat (if prev ", " "") (int-to-string
3641 (floor num))
3642 " " (symbol-name (car unit))
3643 (if (> num 1) "s" ""))
3644 (setq prev t
3645 segments (1+ segments)))))
3646 article-time-units "")
3647 ;; If dates are odd, then it might appear like the
3648 ;; article was sent in the future.
3649 (if (> real-sec 0)
3650 " ago"
3651 " in the future"))))))
3652
3653 (defun article-date-local (&optional highlight)
3654 "Convert the current article date to the local timezone."
3655 (interactive (list t))
3656 (article-date-ut 'local highlight))
3657
3658 (defun article-date-english (&optional highlight)
3659 "Convert the current article date to something that is proper English."
3660 (interactive (list t))
3661 (article-date-ut 'english highlight))
3662
3663 (defun article-date-original (&optional highlight)
3664 "Convert the current article date to what it was originally.
3665 This is only useful if you have used some other date conversion
3666 function and want to see what the date was before converting."
3667 (interactive (list t))
3668 (article-date-ut 'original highlight))
3669
3670 (defun article-date-lapsed (&optional highlight)
3671 "Convert the current article date to time lapsed since it was sent."
3672 (interactive (list t))
3673 (article-date-ut 'lapsed highlight))
3674
3675 (defun article-date-combined-lapsed (&optional highlight)
3676 "Convert the current article date to time lapsed since it was sent."
3677 (interactive (list t))
3678 (article-date-ut 'combined-lapsed highlight))
3679
3680 (defun article-update-date-lapsed ()
3681 "Function to be run from a timer to update the lapsed time line."
3682 (save-match-data
3683 (let ((buffer (current-buffer)))
3684 (ignore-errors
3685 (walk-windows
3686 (lambda (w)
3687 (set-buffer (window-buffer w))
3688 (when (derived-mode-p 'gnus-article-mode)
3689 (let ((old-line (count-lines (point-min) (point)))
3690 (old-column (- (point) (line-beginning-position)))
3691 (window-start (window-start w))
3692 (pos (point-min))
3693 type next end)
3694 (while (setq pos (text-property-not-all pos (point-max)
3695 'gnus-date-type nil))
3696 (setq next (or (next-single-property-change pos
3697 'gnus-date-type)
3698 (point-max)))
3699 (setq type (get-text-property pos 'gnus-date-type))
3700 (when (memq type '(lapsed combined-lapsed user-defined))
3701 (article-date-ut type t pos)
3702 (setq end (or (next-single-property-change pos
3703 'gnus-date-type)
3704 (point-max)))
3705 (when window-start
3706 (if (/= window-start next)
3707 (setq window-start nil)
3708 (set-window-start w end)))
3709 (setq next end))
3710 (setq pos next))
3711 (goto-char (point-min))
3712 (when (> old-column 0)
3713 (setq old-line (1- old-line)))
3714 (forward-line old-line)
3715 (end-of-line)
3716 (when (> (current-column) old-column)
3717 (beginning-of-line)
3718 (forward-char old-column)))))
3719 nil 'visible))
3720 (set-buffer buffer))))
3721
3722 (defun gnus-start-date-timer (&optional n)
3723 "Start a timer to update the Date headers in the article buffers.
3724 The numerical prefix says how frequently (in seconds) the function
3725 is to run."
3726 (interactive "p")
3727 (unless n
3728 (setq n 1))
3729 (gnus-stop-date-timer)
3730 (setq article-lapsed-timer
3731 (run-at-time 1 n 'article-update-date-lapsed)))
3732
3733 (defun gnus-stop-date-timer ()
3734 "Stop the Date timer."
3735 (interactive)
3736 (when article-lapsed-timer
3737 (nnheader-cancel-timer article-lapsed-timer)
3738 (setq article-lapsed-timer nil)))
3739
3740 (defun article-date-user (&optional highlight)
3741 "Convert the current article date to the user-defined format.
3742 This format is defined by the `gnus-article-time-format' variable."
3743 (interactive (list t))
3744 (article-date-ut 'user highlight))
3745
3746 (defun article-date-iso8601 (&optional highlight)
3747 "Convert the current article date to ISO8601."
3748 (interactive (list t))
3749 (article-date-ut 'iso8601 highlight))
3750
3751 (defmacro gnus-article-save-original-date (&rest forms)
3752 "Save the original date as a text property and evaluate FORMS."
3753 `(let* ((case-fold-search t)
3754 (start (progn
3755 (goto-char (point-min))
3756 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3757 (not (bolp)))
3758 (match-end 0))))
3759 (date (when (and start
3760 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3761 nil t))
3762 (buffer-substring-no-properties start
3763 (match-beginning 0)))))
3764 (goto-char (point-max))
3765 (skip-chars-backward "\n")
3766 (put-text-property (point-min) (point) 'original-date date)
3767 ,@forms
3768 (goto-char (point-max))
3769 (skip-chars-backward "\n")
3770 (put-text-property (point-min) (point) 'original-date date)))
3771
3772 ;; (defun article-show-all ()
3773 ;; "Show all hidden text in the article buffer."
3774 ;; (interactive)
3775 ;; (save-excursion
3776 ;; (let ((inhibit-read-only t))
3777 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3778
3779 (defun article-remove-leading-whitespace ()
3780 "Remove excessive whitespace from all headers."
3781 (interactive)
3782 (save-excursion
3783 (save-restriction
3784 (let ((inhibit-read-only t))
3785 (article-narrow-to-head)
3786 (goto-char (point-min))
3787 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3788 (delete-region (match-beginning 1) (match-end 1)))))))
3789
3790 (defun article-emphasize (&optional arg)
3791 "Emphasize text according to `gnus-emphasis-alist'."
3792 (interactive (gnus-article-hidden-arg))
3793 (unless (gnus-article-check-hidden-text 'emphasis arg)
3794 (save-excursion
3795 (let ((alist (or
3796 (condition-case nil
3797 (with-current-buffer gnus-summary-buffer
3798 gnus-article-emphasis-alist)
3799 (error))
3800 gnus-emphasis-alist))
3801 (inhibit-read-only t)
3802 (props (append '(article-type emphasis)
3803 gnus-hidden-properties))
3804 regexp elem beg invisible visible face)
3805 (article-goto-body)
3806 (setq beg (point))
3807 (while (setq elem (pop alist))
3808 (goto-char beg)
3809 (setq regexp (car elem)
3810 invisible (nth 1 elem)
3811 visible (nth 2 elem)
3812 face (nth 3 elem))
3813 (while (re-search-forward regexp nil t)
3814 (when (and (match-beginning visible) (match-beginning invisible))
3815 (gnus-article-hide-text
3816 (match-beginning invisible) (match-end invisible) props)
3817 (gnus-article-unhide-text-type
3818 (match-beginning visible) (match-end visible) 'emphasis)
3819 (gnus-put-overlay-excluding-newlines
3820 (match-beginning visible) (match-end visible) 'face face)
3821 (gnus-add-wash-type 'emphasis)
3822 (goto-char (match-end invisible)))))))))
3823
3824 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3825 "Setup newsgroup emphasis alist."
3826 (unless gnus-article-emphasis-alist
3827 (let ((name (and gnus-newsgroup-name
3828 (gnus-group-real-name gnus-newsgroup-name))))
3829 (make-local-variable 'gnus-article-emphasis-alist)
3830 (setq gnus-article-emphasis-alist
3831 (nconc
3832 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3833 (while (setq elem (pop alist))
3834 (when (and name (string-match (car elem) name))
3835 (setq alist nil
3836 highlight (copy-sequence (cdr elem)))))
3837 highlight)
3838 (copy-sequence highlight-words)
3839 (if gnus-newsgroup-name
3840 (copy-sequence (gnus-group-find-parameter
3841 gnus-newsgroup-name 'highlight-words t)))
3842 gnus-emphasis-alist)))))
3843
3844 (defvar gnus-summary-article-menu)
3845 (defvar gnus-summary-post-menu)
3846
3847 ;;; Saving functions.
3848
3849 (defun gnus-article-save (save-buffer file &optional num)
3850 "Save the currently selected article."
3851 (when (or (get gnus-default-article-saver :headers)
3852 (not gnus-save-all-headers))
3853 ;; Remove headers according to `gnus-saved-headers' or the value
3854 ;; of the `:headers' property that the saver function might have.
3855 (let ((gnus-visible-headers
3856 (or (symbol-value (get gnus-default-article-saver :headers))
3857 gnus-saved-headers gnus-visible-headers))
3858 ;; Ignore group parameter. See `article-hide-headers'.
3859 (gnus-summary-buffer nil))
3860 (with-current-buffer save-buffer
3861 (article-hide-headers 1 t))))
3862 (save-window-excursion
3863 (if (not gnus-default-article-saver)
3864 (error "No default saver is defined")
3865 ;; !!! Magic! The saving functions all save
3866 ;; `gnus-save-article-buffer' (or so they think), but we
3867 ;; bind that variable to our save-buffer.
3868 (set-buffer gnus-article-buffer)
3869 (let* ((gnus-save-article-buffer save-buffer)
3870 (filename
3871 (cond
3872 ((not gnus-prompt-before-saving) 'default)
3873 ((eq gnus-prompt-before-saving 'always) nil)
3874 (t file)))
3875 (gnus-number-of-articles-to-be-saved
3876 (when (eq gnus-prompt-before-saving t)
3877 num))) ; Magic
3878 (set-buffer gnus-article-current-summary)
3879 (funcall gnus-default-article-saver filename)))))
3880
3881 (defun gnus-read-save-file-name (prompt &optional filename
3882 function group headers variable
3883 dir-var)
3884 (let ((default-name
3885 (funcall function group headers (symbol-value variable)))
3886 result)
3887 (setq result
3888 (expand-file-name
3889 (cond
3890 ((eq filename 'default)
3891 default-name)
3892 ((eq filename t)
3893 default-name)
3894 (filename filename)
3895 (t
3896 (when (symbol-value dir-var)
3897 (setq default-name (expand-file-name
3898 (file-name-nondirectory default-name)
3899 (symbol-value dir-var))))
3900 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3901 (prompt
3902 (format prompt
3903 (if (and gnus-number-of-articles-to-be-saved
3904 (> gnus-number-of-articles-to-be-saved 1))
3905 (format "these %d articles"
3906 gnus-number-of-articles-to-be-saved)
3907 "this article")))
3908 (file
3909 ;; Let the split methods have their say.
3910 (cond
3911 ;; No split name was found.
3912 ((null split-name)
3913 (read-file-name
3914 (concat prompt " (default "
3915 (file-name-nondirectory default-name) "): ")
3916 (file-name-directory default-name)
3917 default-name))
3918 ;; A single group name is returned.
3919 ((stringp split-name)
3920 (setq default-name
3921 (funcall function split-name headers
3922 (symbol-value variable)))
3923 (read-file-name
3924 (concat prompt " (default "
3925 (file-name-nondirectory default-name) "): ")
3926 (file-name-directory default-name)
3927 default-name))
3928 ;; A single split name was found
3929 ((= 1 (length split-name))
3930 (let* ((name (expand-file-name
3931 (car split-name)
3932 gnus-article-save-directory))
3933 (dir (cond ((file-directory-p name)
3934 (file-name-as-directory name))
3935 ((file-exists-p name) name)
3936 (t gnus-article-save-directory))))
3937 (read-file-name
3938 (concat prompt " (default " name "): ")
3939 dir name)))
3940 ;; A list of splits was found.
3941 (t
3942 (setq split-name (nreverse split-name))
3943 (let (result)
3944 (let ((file-name-history
3945 (nconc split-name file-name-history)))
3946 (setq result
3947 (expand-file-name
3948 (read-file-name
3949 (concat prompt " (`M-p' for defaults): ")
3950 gnus-article-save-directory
3951 (car split-name))
3952 gnus-article-save-directory)))
3953 (car (push result file-name-history)))))))
3954 ;; Create the directory.
3955 (gnus-make-directory (file-name-directory file))
3956 ;; If we have read a directory, we append the default file name.
3957 (when (file-directory-p file)
3958 (setq file (expand-file-name (file-name-nondirectory
3959 default-name)
3960 (file-name-as-directory file))))
3961 ;; Possibly translate some characters.
3962 (nnheader-translate-file-chars file))))))
3963 (gnus-make-directory (file-name-directory result))
3964 (when variable
3965 (set variable result))
3966 (when dir-var
3967 (set dir-var (file-name-directory result)))
3968 result))
3969
3970 (defun gnus-article-archive-name (_group)
3971 "Return the first instance of an \"Archive-name\" in the current buffer."
3972 (let ((case-fold-search t))
3973 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3974 (nnheader-concat gnus-article-save-directory
3975 (match-string 1)))))
3976
3977 (defun gnus-article-nndoc-name (group)
3978 "If GROUP is an nndoc group, return the name of the parent group."
3979 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3980 (gnus-group-get-parameter group 'save-article-group)))
3981
3982 (defun gnus-summary-save-in-rmail (&optional filename)
3983 "Append this article to Rmail file.
3984 Optional argument FILENAME specifies file name.
3985 Directory to save to is default to `gnus-article-save-directory'."
3986 (setq filename (gnus-read-save-file-name
3987 "Save %s in rmail file" filename
3988 gnus-rmail-save-name gnus-newsgroup-name
3989 gnus-current-headers 'gnus-newsgroup-last-rmail))
3990 (with-current-buffer gnus-save-article-buffer
3991 (save-excursion
3992 (save-restriction
3993 (widen)
3994 ;; Note that unlike gnus-summary-save-in-mail, there is no
3995 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3996 ;; not use Babyl.
3997 (gnus-output-to-rmail filename))))
3998 filename)
3999
4000 (defun gnus-summary-save-in-mail (&optional filename)
4001 "Append this article to Unix mail file.
4002 Optional argument FILENAME specifies file name.
4003 Directory to save to is default to `gnus-article-save-directory'."
4004 (setq filename (gnus-read-save-file-name
4005 "Save %s in Unix mail file" filename
4006 gnus-mail-save-name gnus-newsgroup-name
4007 gnus-current-headers 'gnus-newsgroup-last-mail))
4008 (with-current-buffer gnus-save-article-buffer
4009 (save-excursion
4010 (save-restriction
4011 (widen)
4012 (if (and (file-readable-p filename)
4013 (file-regular-p filename)
4014 (mail-file-babyl-p filename))
4015 (gnus-output-to-rmail filename)
4016 (gnus-output-to-mail filename)))))
4017 filename)
4018
4019 (put 'gnus-summary-save-in-file :decode t)
4020 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4021 (defun gnus-summary-save-in-file (&optional filename overwrite)
4022 "Append this article to file.
4023 Optional argument FILENAME specifies file name.
4024 Directory to save to is default to `gnus-article-save-directory'."
4025 (setq filename (gnus-read-save-file-name
4026 "Save %s in file" filename
4027 gnus-file-save-name gnus-newsgroup-name
4028 gnus-current-headers 'gnus-newsgroup-last-file))
4029 (with-current-buffer gnus-save-article-buffer
4030 (save-excursion
4031 (save-restriction
4032 (widen)
4033 (when (and overwrite
4034 (file-exists-p filename))
4035 (delete-file filename))
4036 (gnus-output-to-file filename))))
4037 filename)
4038
4039 (put 'gnus-summary-write-to-file :decode t)
4040 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4041 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4042 (defun gnus-summary-write-to-file (&optional filename)
4043 "Write this article to a file, overwriting it if the file exists.
4044 Optional argument FILENAME specifies file name.
4045 The directory to save in defaults to `gnus-article-save-directory'."
4046 (setq filename (gnus-read-save-file-name
4047 "Save %s in file" filename
4048 gnus-file-save-name gnus-newsgroup-name
4049 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4050 (gnus-summary-save-in-file filename t))
4051
4052 (put 'gnus-summary-save-body-in-file :decode t)
4053 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4054 "Append this article body to a file.
4055 Optional argument FILENAME specifies file name.
4056 The directory to save in defaults to `gnus-article-save-directory'."
4057 (setq filename (gnus-read-save-file-name
4058 "Save %s body in file" filename
4059 gnus-file-save-name gnus-newsgroup-name
4060 gnus-current-headers 'gnus-newsgroup-last-file))
4061 (with-current-buffer gnus-save-article-buffer
4062 (save-excursion
4063 (save-restriction
4064 (widen)
4065 (when (article-goto-body)
4066 (narrow-to-region (point) (point-max)))
4067 (when (and overwrite
4068 (file-exists-p filename))
4069 (delete-file filename))
4070 (gnus-output-to-file filename))))
4071 filename)
4072
4073 (put 'gnus-summary-write-body-to-file :decode t)
4074 (put 'gnus-summary-write-body-to-file
4075 :function 'gnus-summary-save-body-in-file)
4076 (defun gnus-summary-write-body-to-file (&optional filename)
4077 "Write this article body to a file, overwriting it if the file exists.
4078 Optional argument FILENAME specifies file name.
4079 The directory to save in defaults to `gnus-article-save-directory'."
4080 (setq filename (gnus-read-save-file-name
4081 "Save %s body in file" filename
4082 gnus-file-save-name gnus-newsgroup-name
4083 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4084 (gnus-summary-save-body-in-file filename t))
4085
4086 (put 'gnus-summary-save-in-pipe :decode t)
4087 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4088 (defun gnus-summary-save-in-pipe (&optional command raw)
4089 "Pipe this article to subprocess COMMAND.
4090 Valid values for COMMAND include:
4091 a string
4092 The executable command name and possibly arguments.
4093 nil
4094 You will be prompted for the command in the minibuffer.
4095 the symbol `default'
4096 It will be replaced with the command which the variable
4097 `gnus-summary-pipe-output-default-command' holds or the command
4098 last used for saving.
4099 Non-nil value for RAW overrides `:decode' and `:headers' properties
4100 and the raw article including all headers will be piped."
4101 (let ((article (gnus-summary-article-number))
4102 (decode (unless raw
4103 (get 'gnus-summary-save-in-pipe :decode)))
4104 save-buffer default)
4105 (if article
4106 (if (vectorp (gnus-summary-article-header article))
4107 (save-current-buffer
4108 (gnus-summary-select-article decode decode nil article)
4109 (insert-buffer-substring
4110 (prog1
4111 (if decode
4112 gnus-article-buffer
4113 gnus-original-article-buffer)
4114 (setq save-buffer
4115 (nnheader-set-temp-buffer " *Gnus Save*"))))
4116 ;; Remove unwanted headers.
4117 (when (and (not raw)
4118 (or (get 'gnus-summary-save-in-pipe :headers)
4119 (not gnus-save-all-headers)))
4120 (let ((gnus-visible-headers
4121 (or (symbol-value (get 'gnus-summary-save-in-pipe
4122 :headers))
4123 gnus-saved-headers gnus-visible-headers))
4124 (gnus-summary-buffer nil))
4125 (article-hide-headers 1 t))))
4126 (error "%d is not a real article" article))
4127 (error "No article to pipe"))
4128 (setq default (or gnus-summary-pipe-output-default-command
4129 gnus-last-shell-command))
4130 (unless (stringp command)
4131 (setq command
4132 (if (and (eq command 'default) default)
4133 default
4134 (read-shell-command "Shell command on this article: " default))))
4135 (when (string-equal command "")
4136 (if default
4137 (setq command default)
4138 (error "A command is required")))
4139 (with-current-buffer save-buffer
4140 (save-restriction
4141 (widen)
4142 (shell-command-on-region (point-min) (point-max) command nil)))
4143 (gnus-kill-buffer save-buffer))
4144 (setq gnus-summary-pipe-output-default-command command))
4145
4146 (defun gnus-summary-pipe-to-muttprint (&optional command)
4147 "Pipe this article to muttprint."
4148 (unless (stringp command)
4149 (setq command (read-string
4150 "Print using command: " gnus-summary-muttprint-program
4151 nil gnus-summary-muttprint-program)))
4152 (let ((gnus-summary-pipe-output-default-command
4153 gnus-summary-pipe-output-default-command))
4154 (gnus-summary-save-in-pipe command))
4155 (setq gnus-summary-muttprint-program command))
4156
4157 ;;; Article file names when saving.
4158
4159 (defun gnus-capitalize-newsgroup (newsgroup)
4160 "Capitalize NEWSGROUP name."
4161 (when (not (zerop (length newsgroup)))
4162 (concat (char-to-string (upcase (aref newsgroup 0)))
4163 (substring newsgroup 1))))
4164
4165 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4166 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4167 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4168 Otherwise, it is like ~/News/news/group/num."
4169 (let ((default
4170 (expand-file-name
4171 (concat (if (gnus-use-long-file-name 'not-save)
4172 (gnus-capitalize-newsgroup newsgroup)
4173 (gnus-newsgroup-directory-form newsgroup))
4174 "/" (int-to-string (mail-header-number headers)))
4175 gnus-article-save-directory)))
4176 (if (and last-file
4177 (string-equal (file-name-directory default)
4178 (file-name-directory last-file))
4179 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4180 default
4181 (or last-file default))))
4182
4183 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4184 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4185 If variable `gnus-use-long-file-name' is non-nil, it is
4186 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4187 (let ((default
4188 (expand-file-name
4189 (concat (if (gnus-use-long-file-name 'not-save)
4190 newsgroup
4191 (gnus-newsgroup-directory-form newsgroup))
4192 "/" (int-to-string (mail-header-number headers)))
4193 gnus-article-save-directory)))
4194 (if (and last-file
4195 (string-equal (file-name-directory default)
4196 (file-name-directory last-file))
4197 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4198 default
4199 (or last-file default))))
4200
4201 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4202 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4203 If variable `gnus-use-long-file-name' is non-nil, it is
4204 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4205 (or last-file
4206 (expand-file-name
4207 (if (gnus-use-long-file-name 'not-save)
4208 newsgroup
4209 (file-relative-name
4210 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4211 default-directory))
4212 gnus-article-save-directory)))
4213
4214 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4215 "Generate file name from sender."
4216 (let ((from (mail-header-from headers)))
4217 (expand-file-name
4218 (if (and from (string-match "\\([^ <]+\\)@" from))
4219 (match-string 1 from)
4220 "nobody")
4221 gnus-article-save-directory)))
4222
4223 (defun article-verify-x-pgp-sig ()
4224 "Verify X-PGP-Sig."
4225 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4226 (interactive)
4227 (if (gnus-buffer-live-p gnus-original-article-buffer)
4228 (let ((sig (with-current-buffer gnus-original-article-buffer
4229 (gnus-fetch-field "X-PGP-Sig")))
4230 items info headers)
4231 (when (and sig
4232 mml2015-use
4233 (mml2015-clear-verify-function))
4234 (with-temp-buffer
4235 (insert-buffer-substring gnus-original-article-buffer)
4236 (setq items (split-string sig))
4237 (message-narrow-to-head)
4238 (let ((inhibit-point-motion-hooks t)
4239 (case-fold-search t))
4240 ;; Don't verify multiple headers.
4241 (setq headers (mapconcat (lambda (header)
4242 (concat header ": "
4243 (mail-fetch-field header)
4244 "\n"))
4245 (split-string (nth 1 items) ",") "")))
4246 (delete-region (point-min) (point-max))
4247 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4248 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4249 (insert headers)
4250 (widen)
4251 (forward-line)
4252 (while (not (eobp))
4253 (if (looking-at "^-")
4254 (insert "- "))
4255 (forward-line))
4256 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4257 (insert "Version: " (car items) "\n\n")
4258 (insert (mapconcat 'identity (cddr items) "\n"))
4259 (insert "\n-----END PGP SIGNATURE-----\n")
4260 (let ((mm-security-handle (list (format "multipart/signed"))))
4261 (mml2015-clean-buffer)
4262 (let ((coding-system-for-write (or gnus-newsgroup-charset
4263 'iso-8859-1)))
4264 (funcall (mml2015-clear-verify-function)))
4265 (setq info
4266 (or (mm-handle-multipart-ctl-parameter
4267 mm-security-handle 'gnus-details)
4268 (mm-handle-multipart-ctl-parameter
4269 mm-security-handle 'gnus-info)))))
4270 (when info
4271 (let ((inhibit-read-only t) bface eface)
4272 (save-restriction
4273 (message-narrow-to-head)
4274 (goto-char (point-max))
4275 (forward-line -1)
4276 (setq bface (get-text-property (point-at-bol) 'face)
4277 eface (get-text-property (1- (point-at-eol)) 'face))
4278 (message-remove-header "X-Gnus-PGP-Verify")
4279 (if (re-search-forward "^X-PGP-Sig:" nil t)
4280 (forward-line)
4281 (goto-char (point-max)))
4282 (narrow-to-region (point) (point))
4283 (insert "X-Gnus-PGP-Verify: " info "\n")
4284 (goto-char (point-min))
4285 (forward-line)
4286 (while (not (eobp))
4287 (if (not (looking-at "^[ \t]"))
4288 (insert " "))
4289 (forward-line))
4290 ;; Do highlighting.
4291 (goto-char (point-min))
4292 (when (looking-at "\\([^:]+\\): *")
4293 (put-text-property (match-beginning 1) (1+ (match-end 1))
4294 'face bface)
4295 (put-text-property (match-end 0) (point-max)
4296 'face eface)))))))))
4297
4298 (defun article-verify-cancel-lock ()
4299 "Verify Cancel-Lock header."
4300 (interactive)
4301 (if (gnus-buffer-live-p gnus-original-article-buffer)
4302 (canlock-verify gnus-original-article-buffer)))
4303
4304 (eval-and-compile
4305 (mapc
4306 (lambda (func)
4307 (let (afunc gfunc)
4308 (if (consp func)
4309 (setq afunc (car func)
4310 gfunc (cdr func))
4311 (setq afunc func
4312 gfunc (intern (format "gnus-%s" func))))
4313 (defalias gfunc
4314 (when (fboundp afunc)
4315 `(lambda (&optional interactive &rest args)
4316 ,(documentation afunc t)
4317 (interactive (list t))
4318 (with-current-buffer gnus-article-buffer
4319 (if interactive
4320 (call-interactively ',afunc)
4321 (apply ',afunc args))))))))
4322 '(article-hide-headers
4323 article-verify-x-pgp-sig
4324 article-verify-cancel-lock
4325 article-hide-boring-headers
4326 article-treat-overstrike
4327 article-treat-ansi-sequences
4328 article-fill-long-lines
4329 article-capitalize-sentences
4330 article-remove-cr
4331 article-remove-leading-whitespace
4332 article-display-x-face
4333 article-display-face
4334 article-de-quoted-unreadable
4335 article-de-base64-unreadable
4336 article-decode-HZ
4337 article-wash-html
4338 article-unsplit-urls
4339 article-hide-list-identifiers
4340 article-strip-banner
4341 article-babel
4342 article-hide-pem
4343 article-hide-signature
4344 article-strip-headers-in-body
4345 article-remove-trailing-blank-lines
4346 article-strip-leading-blank-lines
4347 article-strip-multiple-blank-lines
4348 article-strip-leading-space
4349 article-strip-trailing-space
4350 article-strip-blank-lines
4351 article-strip-all-blank-lines
4352 article-date-local
4353 article-date-english
4354 article-date-iso8601
4355 article-date-original
4356 article-treat-date
4357 article-date-ut
4358 article-decode-mime-words
4359 article-decode-charset
4360 article-decode-encoded-words
4361 article-date-user
4362 article-date-lapsed
4363 article-date-combined-lapsed
4364 article-emphasize
4365 article-treat-dumbquotes
4366 article-treat-non-ascii
4367 article-normalize-headers
4368 ;;(article-show-all . gnus-article-show-all-headers)
4369 )))
4370 \f
4371 ;;;
4372 ;;; Gnus article mode
4373 ;;;
4374
4375 (put 'gnus-article-mode 'mode-class 'special)
4376
4377 (set-keymap-parent gnus-article-mode-map widget-keymap)
4378
4379 (gnus-define-keys gnus-article-mode-map
4380 " " gnus-article-goto-next-page
4381 [?\S-\ ] gnus-article-goto-prev-page
4382 "\177" gnus-article-goto-prev-page
4383 [delete] gnus-article-goto-prev-page
4384 "\C-c^" gnus-article-refer-article
4385 "h" gnus-article-show-summary
4386 "s" gnus-article-show-summary
4387 "\C-c\C-m" gnus-article-mail
4388 "?" gnus-article-describe-briefly
4389 "<" beginning-of-buffer
4390 ">" end-of-buffer
4391 "\C-c\C-i" gnus-info-find-node
4392 "\C-c\C-b" gnus-bug
4393 "R" gnus-article-reply-with-original
4394 "F" gnus-article-followup-with-original
4395 "\C-hk" gnus-article-describe-key
4396 "\C-hc" gnus-article-describe-key-briefly
4397 "\C-hb" gnus-article-describe-bindings
4398
4399 "e" gnus-article-read-summary-keys
4400 "\C-d" gnus-article-read-summary-keys
4401 "\M-*" gnus-article-read-summary-keys
4402 "\M-#" gnus-article-read-summary-keys
4403 "\M-^" gnus-article-read-summary-keys
4404 "\M-g" gnus-article-read-summary-keys)
4405
4406 (substitute-key-definition
4407 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4408
4409 (defvar gnus-article-send-map)
4410 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4411 "W" gnus-article-wide-reply-with-original
4412 [t] 'gnus-article-read-summary-send-keys)
4413
4414 (defun gnus-article-make-menu-bar ()
4415 (unless (boundp 'gnus-article-commands-menu)
4416 (gnus-summary-make-menu-bar))
4417 (unless (boundp 'gnus-article-article-menu)
4418 (easy-menu-define
4419 gnus-article-article-menu gnus-article-mode-map ""
4420 '("Article"
4421 ["Scroll forwards" gnus-article-goto-next-page t]
4422 ["Scroll backwards" gnus-article-goto-prev-page t]
4423 ["Show summary" gnus-article-show-summary t]
4424 ["Fetch Message-ID at point" gnus-article-refer-article t]
4425 ["Mail to address at point" gnus-article-mail t]
4426 ["Send a bug report" gnus-bug t]))
4427
4428 (easy-menu-define
4429 gnus-article-treatment-menu gnus-article-mode-map ""
4430 ;; Fixme: this should use :active (and maybe :visible).
4431 '("Treatment"
4432 ["Hide headers" gnus-article-hide-headers t]
4433 ["Hide signature" gnus-article-hide-signature t]
4434 ["Hide citation" gnus-article-hide-citation t]
4435 ["Treat overstrike" gnus-article-treat-overstrike t]
4436 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4437 ["Remove carriage return" gnus-article-remove-cr t]
4438 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4439 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4440 ["Remove base64" gnus-article-de-base64-unreadable t]
4441 ["Treat html" gnus-article-wash-html t]
4442 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4443 ["Decode HZ" gnus-article-decode-HZ t]))
4444
4445 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4446
4447 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4448
4449 (gnus-run-hooks 'gnus-article-menu-hook)))
4450
4451 (defvar bookmark-make-record-function)
4452 (defvar shr-put-image-function)
4453
4454 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4455 "Major mode for displaying an article.
4456
4457 All normal editing commands are switched off.
4458
4459 The following commands are available in addition to all summary mode
4460 commands:
4461 \\<gnus-article-mode-map>
4462 \\[gnus-article-next-page]\t Scroll the article one page forwards
4463 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4464 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4465 \\[gnus-article-show-summary]\t Display the summary buffer
4466 \\[gnus-article-mail]\t Send a reply to the address near point
4467 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4468 \\[gnus-info-find-node]\t Go to the Gnus info node"
4469 (gnus-simplify-mode-line)
4470 (make-local-variable 'minor-mode-alist)
4471 (when (gnus-visual-p 'article-menu 'menu)
4472 (gnus-article-make-menu-bar)
4473 (when gnus-summary-tool-bar-map
4474 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4475 (gnus-update-format-specifications nil 'article-mode)
4476 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4477 (set (make-local-variable 'gnus-page-broken) nil)
4478 (make-local-variable 'gnus-article-current-summary)
4479 (make-local-variable 'gnus-article-mime-handles)
4480 (make-local-variable 'gnus-article-decoded-p)
4481 (make-local-variable 'gnus-article-mime-handle-alist)
4482 (make-local-variable 'gnus-article-wash-types)
4483 (make-local-variable 'gnus-article-image-alist)
4484 (make-local-variable 'gnus-article-charset)
4485 (make-local-variable 'gnus-article-ignored-charsets)
4486 (set (make-local-variable 'bookmark-make-record-function)
4487 'gnus-summary-bookmark-make-record)
4488 ;; Prevent Emacs from displaying non-break space with
4489 ;; `nobreak-space' face.
4490 (set (make-local-variable 'nobreak-char-display) nil)
4491 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4492 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4493 (unless gnus-article-show-cursor
4494 (setq cursor-in-non-selected-windows nil))
4495 (gnus-set-default-directory)
4496 (buffer-disable-undo)
4497 (setq buffer-read-only t
4498 show-trailing-whitespace nil)
4499 (mm-enable-multibyte))
4500
4501 (defun gnus-article-setup-buffer ()
4502 "Initialize the article buffer."
4503 (let* ((name (if gnus-single-article-buffer "*Article*"
4504 (concat "*Article "
4505 (gnus-group-decoded-name gnus-newsgroup-name)
4506 "*")))
4507 (original
4508 (progn (string-match "\\*Article" name)
4509 (concat " *Original Article"
4510 (substring name (match-end 0))))))
4511 (setq gnus-article-buffer name)
4512 (setq gnus-original-article-buffer original)
4513 (setq gnus-article-mime-handle-alist nil)
4514 (with-current-buffer gnus-summary-buffer
4515 ;; This might be a variable local to the summary buffer.
4516 (unless gnus-single-article-buffer
4517 (setq gnus-article-buffer name)
4518 (setq gnus-original-article-buffer original)
4519 (gnus-set-global-variables)))
4520 (gnus-article-setup-highlight-words)
4521 ;; Init original article buffer.
4522 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4523 (mm-enable-multibyte)
4524 (setq major-mode 'gnus-original-article-mode)
4525 (make-local-variable 'gnus-original-article))
4526 (if (and (get-buffer name)
4527 (with-current-buffer name
4528 (if gnus-article-edit-mode
4529 (if (y-or-n-p "Article mode edit in progress; discard? ")
4530 (progn
4531 (set-buffer-modified-p nil)
4532 (gnus-kill-buffer name)
4533 (message "")
4534 nil)
4535 (error "Action aborted"))
4536 t)))
4537 (let ((summary gnus-summary-buffer))
4538 (with-current-buffer name
4539 (set (make-local-variable 'gnus-article-edit-mode) nil)
4540 (gnus-article-stop-animations)
4541 (when gnus-article-mime-handles
4542 (mm-destroy-parts gnus-article-mime-handles)
4543 (setq gnus-article-mime-handles nil))
4544 ;; Set it to nil in article-buffer!
4545 (setq gnus-article-mime-handle-alist nil)
4546 (buffer-disable-undo)
4547 (setq buffer-read-only t)
4548 (unless (derived-mode-p 'gnus-article-mode)
4549 (gnus-article-mode))
4550 (set (make-local-variable 'gnus-summary-buffer) summary)
4551 (setq truncate-lines gnus-article-truncate-lines)
4552 (current-buffer)))
4553 (let ((summary gnus-summary-buffer))
4554 (with-current-buffer (gnus-get-buffer-create name)
4555 (gnus-article-mode)
4556 (setq truncate-lines gnus-article-truncate-lines)
4557 (set (make-local-variable 'gnus-summary-buffer) summary)
4558 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4559 (when article-lapsed-timer
4560 (gnus-stop-date-timer))
4561 (when gnus-article-update-date-headers
4562 (gnus-start-date-timer gnus-article-update-date-headers))
4563 (current-buffer))))))
4564
4565 (defun gnus-article-stop-animations ()
4566 (dolist (timer (and (boundp 'timer-list)
4567 timer-list))
4568 (when (eq (timer--function timer) 'image-animate-timeout)
4569 (cancel-timer timer))))
4570
4571 (defun gnus-stop-downloads ()
4572 (when (boundp 'url-queue)
4573 (set (intern "url-queue" obarray) nil)))
4574
4575 ;; Set article window start at LINE, where LINE is the number of lines
4576 ;; from the head of the article.
4577 (defun gnus-article-set-window-start (&optional line)
4578 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4579 (when article-window
4580 (set-window-start
4581 article-window
4582 (with-current-buffer gnus-article-buffer
4583 (goto-char (point-min))
4584 (if (not line)
4585 (point-min)
4586 (gnus-message 6 "Moved to bookmark")
4587 (search-forward "\n\n" nil t)
4588 (forward-line line)
4589 (point)))))))
4590
4591 (defvar gnus-tmp-internal-hook)
4592
4593 (defun gnus-article-prepare (article &optional all-headers _header)
4594 "Prepare ARTICLE in article mode buffer.
4595 ARTICLE should either be an article number or a Message-ID.
4596 If ARTICLE is an id, HEADER should be the article headers.
4597 If ALL-HEADERS is non-nil, no headers are hidden."
4598 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4599 ;; Make sure we start in a summary buffer.
4600 (unless (derived-mode-p 'gnus-summary-mode)
4601 (set-buffer gnus-summary-buffer))
4602 (setq gnus-summary-buffer (current-buffer))
4603 (let* ((summary-buffer (current-buffer))
4604 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4605 (group gnus-newsgroup-name)
4606 result)
4607 (save-excursion
4608 (gnus-article-setup-buffer)
4609 (set-buffer gnus-article-buffer)
4610 ;; Deactivate active regions.
4611 (when transient-mark-mode
4612 (setq mark-active nil))
4613 (if (not (setq result (let ((inhibit-read-only t))
4614 (gnus-request-article-this-buffer
4615 article group))))
4616 ;; There is no such article.
4617 (save-excursion
4618 (when (and (numberp article)
4619 (not (memq article gnus-newsgroup-sparse)))
4620 (setq gnus-article-current
4621 (cons gnus-newsgroup-name article))
4622 (set-buffer gnus-summary-buffer)
4623 (setq gnus-current-article article)
4624 (if (and (memq article gnus-newsgroup-undownloaded)
4625 (not (gnus-online (gnus-find-method-for-group
4626 gnus-newsgroup-name))))
4627 (progn
4628 (gnus-summary-set-agent-mark article)
4629 (message "Message marked for downloading"))
4630 (gnus-summary-mark-article article gnus-canceled-mark)
4631 (unless (memq article gnus-newsgroup-sparse)
4632 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4633 (if (or (eq result 'pseudo)
4634 (eq result 'nneething))
4635 (progn
4636 (with-current-buffer summary-buffer
4637 (push article gnus-newsgroup-history)
4638 (setq gnus-last-article gnus-current-article
4639 gnus-current-article 0
4640 gnus-current-headers nil
4641 gnus-article-current nil)
4642 (if (eq result 'nneething)
4643 (gnus-configure-windows 'summary)
4644 (gnus-configure-windows 'article))
4645 (gnus-set-global-variables))
4646 (let ((gnus-article-mime-handle-alist-1
4647 gnus-article-mime-handle-alist))
4648 (gnus-set-mode-line 'article)))
4649 ;; The result from the `request' was an actual article -
4650 ;; or at least some text that is now displayed in the
4651 ;; article buffer.
4652 (when (and (numberp article)
4653 (not (eq article gnus-current-article)))
4654 ;; Seems like a new article has been selected.
4655 ;; `gnus-current-article' must be an article number.
4656 (with-current-buffer summary-buffer
4657 (push article gnus-newsgroup-history)
4658 (setq gnus-last-article gnus-current-article
4659 gnus-current-article article
4660 gnus-current-headers
4661 (gnus-summary-article-header gnus-current-article)
4662 gnus-article-current
4663 (cons gnus-newsgroup-name gnus-current-article))
4664 (unless (vectorp gnus-current-headers)
4665 (setq gnus-current-headers nil))
4666 (gnus-summary-goto-subject gnus-current-article)
4667 (when (gnus-summary-show-thread)
4668 ;; If the summary buffer really was folded, the
4669 ;; previous goto may not actually have gone to
4670 ;; the right article, but the thread root instead.
4671 ;; So we go again.
4672 (gnus-summary-goto-subject gnus-current-article))
4673 (gnus-run-hooks 'gnus-mark-article-hook)
4674 (gnus-set-mode-line 'summary)
4675 (when (gnus-visual-p 'article-highlight 'highlight)
4676 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4677 ;; Set the global newsgroup variables here.
4678 (gnus-set-global-variables)
4679 (setq gnus-have-all-headers
4680 (or all-headers gnus-show-all-headers))))
4681 (save-excursion
4682 (gnus-configure-windows 'article))
4683 (when (or (numberp article)
4684 (stringp article))
4685 (gnus-article-prepare-display)
4686 ;; Do page break.
4687 (goto-char (point-min))
4688 (when gnus-break-pages
4689 (gnus-narrow-to-page)))
4690 (let ((gnus-article-mime-handle-alist-1
4691 gnus-article-mime-handle-alist))
4692 (gnus-set-mode-line 'article))
4693 (article-goto-body)
4694 (unless (bobp)
4695 (forward-line -1))
4696 (set-window-point (get-buffer-window (current-buffer)) (point))
4697 (gnus-configure-windows 'article)
4698 (gnus-run-hooks 'gnus-article-prepare-hook)
4699 t))))))
4700
4701 (defvar gnus-mime-display-attachment-buttons-in-header)
4702
4703 ;;;###autoload
4704 (defun gnus-article-prepare-display ()
4705 "Make the current buffer look like a nice article."
4706 ;; Hooks for getting information from the article.
4707 ;; This hook must be called before being narrowed.
4708 (let ((gnus-article-buffer (current-buffer))
4709 buffer-read-only
4710 (inhibit-read-only t))
4711 (unless (derived-mode-p 'gnus-article-mode)
4712 (gnus-article-mode))
4713 (setq buffer-read-only nil
4714 gnus-article-wash-types nil
4715 gnus-article-image-alist nil)
4716 (gnus-run-hooks 'gnus-tmp-internal-hook)
4717 (when gnus-display-mime-function
4718 (funcall gnus-display-mime-function))
4719 ;; Add attachment buttons to the header.
4720 (when gnus-mime-display-attachment-buttons-in-header
4721 (gnus-mime-buttonize-attachments-in-header))))
4722
4723 ;;;
4724 ;;; Gnus Sticky Article Mode
4725 ;;;
4726
4727 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4728 "Mode for sticky articles."
4729 ;; Release bindings that won't work.
4730 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4731 gnus-sticky-article-mode-map)
4732 (substitute-key-definition 'gnus-article-refer-article 'undefined
4733 gnus-sticky-article-mode-map)
4734 (dolist (k '("e" "h" "s" "F" "R"))
4735 (define-key gnus-sticky-article-mode-map k nil))
4736 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4737 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4738 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4739 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4740
4741 (defun gnus-sticky-article (arg)
4742 "Make the current article sticky.
4743 If a prefix ARG is given, ask for a name for this sticky article buffer."
4744 (interactive "P")
4745 (gnus-summary-show-thread)
4746 (gnus-summary-select-article nil nil 'pseudo)
4747 (let (new-art-buf-name)
4748 (gnus-eval-in-buffer-window gnus-article-buffer
4749 (setq new-art-buf-name
4750 (concat
4751 "*Sticky Article: "
4752 (if arg
4753 (read-from-minibuffer "Sticky article buffer name: ")
4754 (gnus-with-article-headers
4755 (gnus-article-goto-header "subject")
4756 (setq new-art-buf-name
4757 (buffer-substring-no-properties
4758 (line-beginning-position) (line-end-position)))
4759 (goto-char (point-min))
4760 (gnus-article-goto-header "from")
4761 (setq new-art-buf-name
4762 (concat
4763 new-art-buf-name ", "
4764 (buffer-substring-no-properties
4765 (line-beginning-position) (line-end-position))))
4766 (goto-char (point-min))
4767 (gnus-article-goto-header "date")
4768 (setq new-art-buf-name
4769 (concat
4770 new-art-buf-name ", "
4771 (buffer-substring-no-properties
4772 (line-beginning-position) (line-end-position))))))
4773 "*"))
4774 (if (and (gnus-buffer-live-p new-art-buf-name)
4775 (with-current-buffer new-art-buf-name
4776 (derived-mode-p 'gnus-sticky-article-mode)))
4777 (switch-to-buffer new-art-buf-name)
4778 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4779 (gnus-sticky-article-mode))
4780 (setq gnus-article-buffer new-art-buf-name))
4781 (gnus-summary-recenter)
4782 (gnus-summary-position-point))
4783
4784 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4785 "Kill the given sticky article BUFFER.
4786 If none is given, assume the current buffer and kill it if it has
4787 `gnus-sticky-article-mode'."
4788 (interactive)
4789 (unless buffer
4790 (setq buffer (current-buffer)))
4791 (with-current-buffer buffer
4792 (when (derived-mode-p 'gnus-sticky-article-mode)
4793 (gnus-kill-buffer buffer))))
4794
4795 (defun gnus-kill-sticky-article-buffers (arg)
4796 "Kill all sticky article buffers.
4797 If a prefix ARG is given, ask for confirmation."
4798 (interactive "P")
4799 (dolist (buf (gnus-buffers))
4800 (with-current-buffer buf
4801 (when (derived-mode-p 'gnus-sticky-article-mode)
4802 (if (not arg)
4803 (gnus-kill-buffer buf)
4804 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4805 (gnus-kill-buffer buf)))))))
4806
4807 ;;;
4808 ;;; Gnus MIME viewing functions
4809 ;;;
4810
4811 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4812 "Format of the MIME buttons.
4813
4814 Valid specifiers include:
4815 %t The MIME type
4816 %T MIME type, along with additional info
4817 %n The `name' parameter
4818 %d The description, if any
4819 %l The length of the encoded part
4820 %p The part identifier number
4821 %e Dots if the part isn't displayed
4822
4823 General format specifiers can also be used. See Info node
4824 `(gnus)Formatting Variables'.")
4825
4826 (defvar gnus-tmp-type)
4827 (defvar gnus-tmp-type-long)
4828 (defvar gnus-tmp-name)
4829 (defvar gnus-tmp-description)
4830 (defvar gnus-tmp-id)
4831 (defvar gnus-tmp-length)
4832 (defvar gnus-tmp-dots)
4833 (defvar gnus-tmp-info)
4834 (defvar gnus-tmp-pressed-details)
4835
4836 (defvar gnus-mime-button-line-format-alist
4837 '((?t gnus-tmp-type ?s)
4838 (?T gnus-tmp-type-long ?s)
4839 (?n gnus-tmp-name ?s)
4840 (?d gnus-tmp-description ?s)
4841 (?p gnus-tmp-id ?s)
4842 (?l gnus-tmp-length ?d)
4843 (?e gnus-tmp-dots ?s)))
4844
4845 (defvar gnus-mime-button-commands
4846 '((gnus-article-press-button "\r" "Toggle Display")
4847 (gnus-mime-view-part "v" "View Interactively...")
4848 (gnus-mime-view-part-as-type "t" "View As Type...")
4849 (gnus-mime-view-part-as-charset "C" "View As charset...")
4850 (gnus-mime-save-part "o" "Save...")
4851 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4852 (gnus-mime-replace-part "r" "Replace part")
4853 (gnus-mime-delete-part "d" "Delete part")
4854 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4855 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4856 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4857 (gnus-mime-view-part-externally "e" "View Externally")
4858 (gnus-mime-print-part "p" "Print")
4859 (gnus-mime-pipe-part "|" "Pipe To Command...")
4860 (gnus-mime-action-on-part "." "Take action on the part...")))
4861
4862 (defun gnus-article-mime-part-status ()
4863 (if gnus-article-mime-handle-alist-1
4864 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4865 " (1 part)"
4866 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4867 ""))
4868
4869 (defvar gnus-mime-button-map
4870 (let ((map (make-sparse-keymap)))
4871 (define-key map [mouse-2] 'gnus-article-push-button)
4872 (define-key map [down-mouse-3] 'gnus-mime-button-menu)
4873 (dolist (c gnus-mime-button-commands)
4874 (define-key map (cadr c) (car c)))
4875 map))
4876
4877 (easy-menu-define
4878 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4879 `("MIME Part"
4880 ,@(mapcar (lambda (c)
4881 (vector (caddr c) (car c) :active t))
4882 gnus-mime-button-commands)))
4883
4884 (defvar gnus-url-button-commands
4885 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4886
4887 (defvar gnus-url-button-map
4888 (let ((map (make-sparse-keymap)))
4889 (dolist (c gnus-url-button-commands)
4890 (define-key map (cadr c) (car c)))
4891 map))
4892
4893 (easy-menu-define
4894 gnus-url-button-menu gnus-url-button-map "URL button menu."
4895 `("Url Button"
4896 ,@(mapcar (lambda (c)
4897 (vector (caddr c) (car c) :active t))
4898 gnus-url-button-commands)))
4899
4900 (defmacro gnus-bind-mm-vars (&rest body)
4901 "Bind some mm-* variables and execute BODY."
4902 `(let (mm-html-inhibit-images
4903 mm-html-blocked-images
4904 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4905 (with-current-buffer
4906 (cond ((derived-mode-p 'gnus-article-mode)
4907 (if (gnus-buffer-live-p gnus-article-current-summary)
4908 gnus-article-current-summary
4909 ;; Maybe we're in a mml-preview buffer
4910 ;; and no group is selected.
4911 (current-buffer)))
4912 ((gnus-buffer-live-p gnus-summary-buffer)
4913 gnus-summary-buffer)
4914 (t (current-buffer)))
4915 (setq mm-html-inhibit-images gnus-inhibit-images
4916 mm-html-blocked-images (gnus-blocked-images))
4917 (when (or (not gnus-newsgroup-name)
4918 (and (stringp gnus-safe-html-newsgroups)
4919 (string-match gnus-safe-html-newsgroups
4920 gnus-newsgroup-name))
4921 (and (consp gnus-safe-html-newsgroups)
4922 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4923 (setq mm-w3m-safe-url-regexp nil)))
4924 ,@body))
4925
4926 (defun gnus-mime-button-menu (event prefix)
4927 "Construct a context-sensitive menu of MIME commands."
4928 (interactive "e\nP")
4929 (save-window-excursion
4930 (let ((pos (event-start event)))
4931 (select-window (posn-window pos))
4932 (goto-char (posn-point pos))
4933 (gnus-article-check-buffer)
4934 (popup-menu gnus-mime-button-menu nil prefix))))
4935
4936 (defun gnus-mime-view-all-parts (&optional handles)
4937 "View all the MIME parts."
4938 (interactive)
4939 (with-current-buffer gnus-article-buffer
4940 (let ((handles (or handles gnus-article-mime-handles))
4941 (mail-parse-charset gnus-newsgroup-charset)
4942 (mail-parse-ignored-charsets
4943 (with-current-buffer gnus-summary-buffer
4944 gnus-newsgroup-ignored-charsets)))
4945 (when handles
4946 (mm-remove-parts handles)
4947 (goto-char (point-min))
4948 (or (search-forward "\n\n") (goto-char (point-max)))
4949 (let ((inhibit-read-only t))
4950 (delete-region (point) (point-max))
4951 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4952
4953 (defun gnus-article-jump-to-part (n)
4954 "Jump to MIME part N."
4955 (interactive "P")
4956 (let ((parts (with-current-buffer gnus-article-buffer
4957 (length gnus-article-mime-handle-alist))))
4958 (when (zerop parts)
4959 (error "No such part"))
4960 (pop-to-buffer gnus-article-buffer)
4961 (or n
4962 (setq n (if (= parts 1)
4963 1
4964 (read-number (format "Jump to part (1..%s): " parts)))))
4965 (unless (and (integerp n) (<= n parts) (>= n 1))
4966 (setq n
4967 (progn
4968 (gnus-message 7 "Invalid part `%s', using %s instead."
4969 n parts)
4970 parts)))
4971 (gnus-message 9 "Jumping to part %s." n)
4972 (cond ((>= gnus-auto-select-part 1)
4973 (while (and (<= n parts)
4974 (not (gnus-article-goto-part n)))
4975 (setq n (1+ n))))
4976 ((< gnus-auto-select-part 0)
4977 (while (and (>= n 1)
4978 (not (gnus-article-goto-part n)))
4979 (setq n (1- n))))
4980 (t
4981 (gnus-article-goto-part n)))))
4982
4983 (defvar gnus-mime-buttonized-part-id nil
4984 "ID of a mime part that should be buttonized.
4985 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4986
4987 (eval-when-compile
4988 (defsubst gnus-article-edit-part (handles &optional current-id)
4989 "Edit an article in order to delete a mime part.
4990 This function is exclusively used by `gnus-mime-save-part-and-strip'
4991 and `gnus-mime-delete-part', and not provided at run-time normally."
4992 (gnus-article-edit-article
4993 `(lambda ()
4994 (buffer-disable-undo)
4995 (let ((mail-parse-charset (or gnus-article-charset
4996 ',gnus-newsgroup-charset))
4997 (mail-parse-ignored-charsets
4998 (or gnus-article-ignored-charsets
4999 ',gnus-newsgroup-ignored-charsets))
5000 (mbl mml-buffer-list))
5001 (setq mml-buffer-list nil)
5002 ;; A new text must be inserted before deleting existing ones
5003 ;; at the end so as not to move existing markers of which
5004 ;; the insertion type is t.
5005 (delete-region
5006 (point-min)
5007 (prog1
5008 (goto-char (point-max))
5009 (insert-buffer-substring gnus-original-article-buffer)))
5010 (mime-to-mml ',handles)
5011 (setq gnus-article-mime-handles nil)
5012 (let ((mbl1 mml-buffer-list))
5013 (setq mml-buffer-list mbl)
5014 (set (make-local-variable 'mml-buffer-list) mbl1))
5015 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5016 `(lambda (no-highlight)
5017 (let ((mail-parse-charset (or gnus-article-charset
5018 ',gnus-newsgroup-charset))
5019 (message-options message-options)
5020 (message-options-set-recipient)
5021 (mail-parse-ignored-charsets
5022 (or gnus-article-ignored-charsets
5023 ',gnus-newsgroup-ignored-charsets)))
5024 (mml-to-mime)
5025 (mml-destroy-buffers)
5026 (remove-hook 'kill-buffer-hook
5027 'mml-destroy-buffers t)
5028 (kill-local-variable 'mml-buffer-list))
5029 (gnus-summary-edit-article-done
5030 ,(or (mail-header-references gnus-current-headers) "")
5031 ,(gnus-group-read-only-p)
5032 ,gnus-summary-buffer no-highlight))
5033 t)
5034 ;; Force buttonizing this part.
5035 (let ((gnus-mime-buttonized-part-id current-id))
5036 (gnus-article-edit-done))
5037 (gnus-configure-windows 'article)
5038 (sit-for 0)
5039 (when (and current-id (integerp gnus-auto-select-part))
5040 (gnus-article-jump-to-part
5041 (min (max (+ current-id gnus-auto-select-part) 1)
5042 (with-current-buffer gnus-article-buffer
5043 (length gnus-article-mime-handle-alist)))))))
5044
5045 (defun gnus-mime-replace-part (file)
5046 "Replace MIME part under point with an external body."
5047 ;; Useful if file has already been saved to disk
5048 (interactive
5049 (list
5050 (read-file-name "Replace MIME part with file: "
5051 (or mm-default-directory default-directory)
5052 nil nil)))
5053 (gnus-mime-save-part-and-strip file))
5054
5055 (defun gnus-mime-save-part-and-strip (&optional file)
5056 "Save the MIME part under point then replace it with an external body.
5057 If FILE is given, use it for the external part."
5058 (interactive)
5059 (gnus-article-check-buffer)
5060 (when (gnus-group-read-only-p)
5061 (error "The current group does not support deleting of parts"))
5062 (when (mm-complicated-handles gnus-article-mime-handles)
5063 (error "\
5064 The current article has a complicated MIME structure, giving up..."))
5065 (let* ((data (get-text-property (point) 'gnus-data))
5066 (id (get-text-property (point) 'gnus-part))
5067 (handles gnus-article-mime-handles))
5068 (unless file
5069 (setq file
5070 (and data (mm-save-part data "Delete MIME part and save to: "))))
5071 (when file
5072 (with-current-buffer (mm-handle-buffer data)
5073 (erase-buffer)
5074 (insert "Content-Type: " (mm-handle-media-type data))
5075 (mml-insert-parameter-string (cdr (mm-handle-type data))
5076 '(charset))
5077 ;; Add a filename for the sake of saving the part again.
5078 (mml-insert-parameter
5079 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5080 (insert "\n")
5081 (insert "Content-ID: " (message-make-message-id) "\n")
5082 (insert "Content-Transfer-Encoding: binary\n")
5083 (insert "\n"))
5084 (setcdr data
5085 (cdr (mm-make-handle nil
5086 `("message/external-body"
5087 (access-type . "LOCAL-FILE")
5088 (name . ,file)))))
5089 ;; (set-buffer gnus-summary-buffer)
5090 (gnus-article-edit-part handles id))))
5091
5092 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5093 ;; parts...>') but with stripping would be nice.
5094
5095 (defun gnus-mime-delete-part ()
5096 "Delete the MIME part under point.
5097 Replace it with some information about the removed part."
5098 (interactive)
5099 (gnus-article-check-buffer)
5100 (when (gnus-group-read-only-p)
5101 (error "The current group does not support deleting of parts"))
5102 (when (mm-complicated-handles gnus-article-mime-handles)
5103 (error "\
5104 The current article has a complicated MIME structure, giving up..."))
5105 (when (or gnus-expert-user
5106 (gnus-yes-or-no-p "\
5107 Deleting parts may malfunction or destroy the article; continue? "))
5108 (let* ((data (get-text-property (point) 'gnus-data))
5109 (id (get-text-property (point) 'gnus-part))
5110 (handles gnus-article-mime-handles)
5111 (description
5112 (let ((desc (mm-handle-description data)))
5113 (when desc
5114 (mail-decode-encoded-word-string desc))))
5115 (filename (or (mm-handle-filename data) "(none)"))
5116 (type (mm-handle-media-type data)))
5117 (unless data
5118 (error "No MIME part under point"))
5119 (with-current-buffer (mm-handle-buffer data)
5120 (let ((bsize (buffer-size)))
5121 (erase-buffer)
5122 (insert
5123 (concat
5124 ",----\n"
5125 "| The following attachment has been deleted:\n"
5126 "|\n"
5127 "| Type: " type "\n"
5128 "| Filename: " filename "\n"
5129 "| Size (encoded): " (format "%s byte%s\n"
5130 bsize (if (= bsize 1)
5131 ""
5132 "s"))
5133 (when description
5134 (concat "| Description: " description "\n"))
5135 "`----\n"))
5136 (setcdr data
5137 (cdr (mm-make-handle
5138 nil `("text/plain" (charset . gnus-decoded)) nil nil
5139 (list "attachment")
5140 (format "Deleted attachment (%s bytes)" bsize))))))
5141 ;; (set-buffer gnus-summary-buffer)
5142 (gnus-article-edit-part handles id))))
5143
5144 (defun gnus-mime-save-part ()
5145 "Save the MIME part under point."
5146 (interactive)
5147 (gnus-article-check-buffer)
5148 (let ((data (get-text-property (point) 'gnus-data)))
5149 (when data
5150 (mm-save-part data))))
5151
5152 (defun gnus-mime-pipe-part (&optional cmd)
5153 "Pipe the MIME part under point to a process.
5154 Use CMD as the process."
5155 (interactive)
5156 (gnus-article-check-buffer)
5157 (let ((data (get-text-property (point) 'gnus-data)))
5158 (when data
5159 (mm-pipe-part data cmd))))
5160
5161 (defun gnus-mime-view-part ()
5162 "Interactively choose a viewing method for the MIME part under point."
5163 (interactive)
5164 (gnus-article-check-buffer)
5165 (let ((data (get-text-property (point) 'gnus-data)))
5166 (when data
5167 (setq gnus-article-mime-handles
5168 (mm-merge-handles
5169 gnus-article-mime-handles (setq data (copy-sequence data))))
5170 (mm-interactively-view-part data))))
5171
5172 (defun gnus-mime-view-part-as-type-internal ()
5173 (gnus-article-check-buffer)
5174 (let* ((handle (get-text-property (point) 'gnus-data))
5175 (name (or
5176 ;; Content-Type: foo/bar; name=...
5177 (mail-content-type-get (mm-handle-type handle) 'name)
5178 ;; Content-Disposition: attachment; filename=...
5179 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5180 (def-type (and name (mm-default-file-encoding name))))
5181 (or (and def-type (cons def-type 0))
5182 (and handle
5183 (equal (mm-handle-media-supertype handle) "text")
5184 '("text/plain" . 0))
5185 '("application/octet-stream" . 0))))
5186
5187 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5188 "Choose a MIME media type, and view the part as such.
5189 If non-nil, PRED is a predicate to use during completion to limit the
5190 available media-types."
5191 (interactive)
5192 (unless mime-type
5193 (setq mime-type
5194 (let ((default (gnus-mime-view-part-as-type-internal)))
5195 (gnus-completing-read
5196 "View as MIME type"
5197 (if pred
5198 (gnus-remove-if-not pred (mailcap-mime-types))
5199 (mailcap-mime-types))
5200 nil nil nil
5201 (car default)))))
5202 (gnus-article-check-buffer)
5203 (let ((handle (get-text-property (point) 'gnus-data)))
5204 (when handle
5205 (when (equal (mm-handle-media-type handle) "message/external-body")
5206 (unless (mm-handle-cache handle)
5207 (mm-extern-cache-contents handle))
5208 (setq handle (mm-handle-cache handle)))
5209 (setq handle
5210 (mm-make-handle (mm-handle-buffer handle)
5211 (cons mime-type (cdr (mm-handle-type handle)))
5212 (mm-handle-encoding handle)
5213 (mm-handle-undisplayer handle)
5214 (mm-handle-disposition handle)
5215 (mm-handle-description handle)
5216 nil
5217 (mm-handle-id handle)))
5218 (setq gnus-article-mime-handles
5219 (mm-merge-handles gnus-article-mime-handles handle))
5220 (when (mm-handle-displayed-p handle)
5221 (mm-remove-part handle))
5222 (gnus-mm-display-part handle))))
5223
5224 (defun gnus-mime-copy-part (&optional handle arg)
5225 "Put the MIME part under point into a new buffer.
5226 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5227 are decompressed."
5228 (interactive (list nil current-prefix-arg))
5229 (gnus-article-check-buffer)
5230 (unless handle
5231 (setq handle (get-text-property (point) 'gnus-data)))
5232 (when handle
5233 (let ((filename (mm-handle-filename handle))
5234 contents dont-decode charset coding-system)
5235 (mm-with-unibyte-buffer
5236 (mm-insert-part handle)
5237 (setq contents (or (condition-case nil
5238 (mm-decompress-buffer filename nil 'sig)
5239 (error
5240 (setq dont-decode t)
5241 nil))
5242 (buffer-string))))
5243 (setq filename (cond (filename (file-name-nondirectory filename))
5244 (dont-decode "*raw data*")
5245 (t "*decoded*")))
5246 (cond
5247 (dont-decode)
5248 ((not arg)
5249 (unless (setq charset (mail-content-type-get
5250 (mm-handle-type handle) 'charset))
5251 (unless (setq coding-system (mm-with-unibyte-buffer
5252 (insert contents)
5253 (mm-find-buffer-file-coding-system)))
5254 (setq charset gnus-newsgroup-charset))))
5255 ((numberp arg)
5256 (setq charset (or (cdr (assq arg
5257 gnus-summary-show-article-charset-alist))
5258 (read-coding-system "Charset: ")))))
5259 (switch-to-buffer (generate-new-buffer filename))
5260 (if (or coding-system
5261 (and charset
5262 (setq coding-system (mm-charset-to-coding-system
5263 charset nil t))
5264 (not (eq coding-system 'ascii))))
5265 (progn
5266 (mm-enable-multibyte)
5267 (insert (decode-coding-string contents coding-system))
5268 (setq buffer-file-coding-system last-coding-system-used))
5269 (mm-disable-multibyte)
5270 (insert contents)
5271 (setq buffer-file-coding-system mm-binary-coding-system))
5272 ;; We do it this way to make `normal-mode' set the appropriate mode.
5273 (unwind-protect
5274 (progn
5275 (setq buffer-file-name (expand-file-name filename))
5276 (normal-mode))
5277 (setq buffer-file-name nil))
5278 (goto-char (point-min)))))
5279
5280 (defun gnus-mime-print-part (&optional handle filename)
5281 "Print the MIME part under point."
5282 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5283 (gnus-article-check-buffer)
5284 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5285 (contents (and handle (mm-get-part handle)))
5286 (file (make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5287 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5288 (when contents
5289 (if printer
5290 (unwind-protect
5291 (progn
5292 (mm-save-part-to-file handle file)
5293 (call-process shell-file-name nil
5294 (generate-new-buffer " *mm*")
5295 nil
5296 shell-command-switch
5297 (mm-mailcap-command
5298 printer file (mm-handle-type handle))))
5299 (delete-file file))
5300 (with-temp-buffer
5301 (insert contents)
5302 (gnus-print-buffer))
5303 (ps-despool filename)))))
5304
5305 (defun gnus-mime-inline-part (&optional handle arg)
5306 "Insert the MIME part under point into the current buffer.
5307 Compressed files like .gz and .bz2 are decompressed."
5308 (interactive (list nil current-prefix-arg))
5309 (gnus-article-check-buffer)
5310 (let* ((inhibit-read-only t)
5311 (b (point))
5312 (btn ;; position where the MIME button exists
5313 (if handle
5314 (if (eq handle (get-text-property b 'gnus-data))
5315 b
5316 (article-goto-body)
5317 (or (text-property-any (point) (point-max) 'gnus-data handle)
5318 (text-property-any (point-min) (point) 'gnus-data handle)))
5319 (setq handle (get-text-property b 'gnus-data))
5320 b))
5321 start)
5322 (when handle
5323 (when (= b (prog1
5324 btn
5325 (setq start (next-single-property-change btn 'gnus-data
5326 nil (point-max))
5327 btn (previous-single-property-change start
5328 'gnus-data))))
5329 (setq b btn))
5330 (if (and (not arg) (mm-handle-undisplayer handle))
5331 (progn
5332 (setq b (copy-marker b)
5333 btn (copy-marker btn))
5334 (mm-remove-part handle))
5335 (cond
5336 ((not arg) nil)
5337 ((numberp arg)
5338 (if (mm-handle-undisplayer handle)
5339 (mm-remove-part handle)))
5340 ((mm-handle-undisplayer handle)
5341 (mm-remove-part handle)))
5342 (goto-char start)
5343 (unless (bolp)
5344 ;; This is a header button.
5345 (forward-line 1))
5346 (mm-display-inline handle))
5347 ;; Toggle the button appearance between `[button]...' and `[button]'.
5348 (when (markerp btn)
5349 (setq btn (prog1 (marker-position btn)
5350 (set-marker btn nil))))
5351 (goto-char btn)
5352 (let ((displayed-p (mm-handle-displayed-p handle)))
5353 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5354 (list displayed-p))
5355 (delete-region
5356 (point)
5357 (next-single-property-change (point) 'gnus-data nil (point-max)))
5358 (setq start (point))
5359 (if (search-backward "\n\n" nil t)
5360 (progn
5361 (goto-char start)
5362 (unless (or displayed-p (eolp))
5363 ;; Add extra newline.
5364 (insert (propertize (buffer-substring (1- start) start)
5365 'gnus-undeletable t))))
5366 ;; We're in the article header.
5367 (delete-char -1)
5368 (dolist (ovl (overlays-in btn (point)))
5369 (overlay-put ovl 'gnus-button-attachment-extra t)
5370 (overlay-put ovl 'face nil))
5371 (save-restriction
5372 (message-narrow-to-field)
5373 (let ((gnus-treatment-function-alist
5374 '((gnus-treat-highlight-headers
5375 gnus-article-highlight-headers))))
5376 (gnus-treat-article 'head)))))
5377 (when (markerp b)
5378 (setq b (prog1 (marker-position b)
5379 (set-marker b nil))))
5380 (goto-char b))))
5381
5382 (defun gnus-mime-set-charset-parameters (handle charset)
5383 "Set CHARSET to parameters in HANDLE.
5384 CHARSET may either be a string or a symbol."
5385 (unless (stringp charset)
5386 (setq charset (symbol-name charset)))
5387 (if (stringp (car handle))
5388 (dolist (h (cdr handle))
5389 (gnus-mime-set-charset-parameters h charset))
5390 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5391 "message/external-body")
5392 (progn
5393 (unless (mm-handle-cache handle)
5394 (mm-extern-cache-contents handle))
5395 (mm-handle-cache handle))
5396 handle)))
5397 (param (assq 'charset (cdr type))))
5398 (if param
5399 (setcdr param charset)
5400 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5401
5402 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5403 "Insert the MIME part under point into the current buffer using the
5404 specified charset."
5405 (interactive (list nil current-prefix-arg))
5406 (gnus-article-check-buffer)
5407 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5408 (fun (get-text-property (point) 'gnus-callback))
5409 (gnus-newsgroup-ignored-charsets 'gnus-all)
5410 charset form preferred parts)
5411 (when handle
5412 (when (prog1
5413 (and fun
5414 (setq charset
5415 (or (cdr (assq
5416 arg
5417 gnus-summary-show-article-charset-alist))
5418 (read-coding-system "Charset: "))))
5419 (if (mm-handle-undisplayer handle)
5420 (mm-remove-part handle)))
5421 (gnus-mime-set-charset-parameters handle charset)
5422 (when (and (consp (setq form (cdr-safe fun)))
5423 (setq form (ignore-errors
5424 (assq 'gnus-mime-display-alternative form)))
5425 (setq preferred (caddr form))
5426 (progn
5427 (when (eq (car preferred) 'quote)
5428 (setq preferred (cadr preferred)))
5429 (not (equal preferred
5430 (get-text-property (point) 'gnus-data))))
5431 (setq parts (get-text-property (point) 'gnus-part))
5432 (setq parts (cdr (assq parts
5433 gnus-article-mime-handle-alist)))
5434 (equal (mm-handle-media-type parts) "multipart/alternative")
5435 (setq parts (reverse (cdr parts))))
5436 (setcar (cddr form)
5437 (list 'quote (or (cadr (member preferred parts))
5438 (car parts)))))
5439 (funcall fun handle)))))
5440
5441 (defun gnus-mime-view-part-externally (&optional handle)
5442 "View the MIME part under point with an external viewer."
5443 (interactive)
5444 (gnus-article-check-buffer)
5445 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5446 (mm-inlined-types nil)
5447 (mail-parse-charset gnus-newsgroup-charset)
5448 (mail-parse-ignored-charsets
5449 (with-current-buffer gnus-summary-buffer
5450 gnus-newsgroup-ignored-charsets))
5451 (type (mm-handle-media-type handle))
5452 (method (mailcap-mime-info type))
5453 (mm-enable-external t))
5454 (if (not (stringp method))
5455 (gnus-mime-view-part-as-type
5456 nil (lambda (type) (stringp (mailcap-mime-info type))))
5457 (when handle
5458 (mm-display-part handle nil t)))))
5459
5460 (defun gnus-mime-view-part-internally (&optional handle)
5461 "View the MIME part under point with an internal viewer.
5462 If no internal viewer is available, use an external viewer."
5463 (interactive)
5464 (gnus-article-check-buffer)
5465 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5466 (mm-inlined-types '(".*"))
5467 (mm-inline-large-images t)
5468 (mail-parse-charset gnus-newsgroup-charset)
5469 (mail-parse-ignored-charsets
5470 (with-current-buffer gnus-summary-buffer
5471 gnus-newsgroup-ignored-charsets))
5472 (inhibit-read-only t))
5473 (if (not (mm-inlinable-p handle))
5474 (gnus-mime-view-part-as-type
5475 nil (lambda (type) (mm-inlinable-p handle type)))
5476 (when handle
5477 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5478
5479 (defun gnus-mime-action-on-part (&optional action)
5480 "Do something with the MIME attachment at (point)."
5481 (interactive
5482 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5483 (gnus-article-check-buffer)
5484 (let ((action-pair (assoc action gnus-mime-action-alist)))
5485 (if action-pair
5486 (funcall (cdr action-pair)))))
5487
5488 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5489 "Call FUNCTION on MIME part N.
5490 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5491 If INTERACTIVE, call FUNCTION interactively."
5492 (let (window frame)
5493 ;; Check whether the article is displayed.
5494 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5495 (setq window (get-buffer-window gnus-article-buffer t))
5496 (frame-visible-p (setq frame (window-frame window))))
5497 (error "No article is displayed"))
5498 (with-current-buffer gnus-article-buffer
5499 ;; Check whether the article displays the right contents.
5500 (unless (with-current-buffer gnus-summary-buffer
5501 (eq gnus-current-article (gnus-summary-article-number)))
5502 (error "You should select the right article first"))
5503 (if n
5504 (setq n (prefix-numeric-value n))
5505 (let ((pt (point)))
5506 (setq n (or (get-text-property pt 'gnus-part)
5507 (and (not (bobp))
5508 (get-text-property (1- pt) 'gnus-part))
5509 (get-text-property (prog2
5510 (forward-line 1)
5511 (point)
5512 (goto-char pt))
5513 'gnus-part)
5514 (get-text-property
5515 (or (and (setq pt (previous-single-property-change
5516 pt 'gnus-part))
5517 (1- pt))
5518 (next-single-property-change (point) 'gnus-part)
5519 (point))
5520 'gnus-part)
5521 1))))
5522 ;; Check whether the specified part exists.
5523 (when (> n (length gnus-article-mime-handle-alist))
5524 (error "No such part")))
5525 (unless
5526 (progn
5527 ;; To select the window is needed so that the cursor
5528 ;; might be visible on the MIME button.
5529 (select-window (prog1
5530 window
5531 (setq window (selected-window))
5532 ;; Article may be displayed in the other frame.
5533 (select-frame-set-input-focus
5534 (prog1
5535 frame
5536 (setq frame (selected-frame))))))
5537 (when (gnus-article-goto-part n)
5538 ;; We point the cursor and the arrow at the MIME button
5539 ;; when the `function' prompt the user for something.
5540 (unless (and (pos-visible-in-window-p)
5541 (> (count-lines (point) (window-end))
5542 (/ (1- (window-height)) 3)))
5543 (recenter (/ (1- (window-height)) 3)))
5544 (let ((cursor-in-non-selected-windows t)
5545 (overlay-arrow-string "=>")
5546 (overlay-arrow-position (point-marker)))
5547 (unwind-protect
5548 (cond
5549 ((and no-handle interactive)
5550 (call-interactively function))
5551 (no-handle
5552 (funcall function))
5553 (interactive
5554 (call-interactively
5555 function (get-text-property (point) 'gnus-data)))
5556 (t
5557 (funcall function
5558 (get-text-property (point) 'gnus-data))))
5559 (set-marker overlay-arrow-position nil)
5560 (unless gnus-auto-select-part
5561 (select-frame-set-input-focus frame)
5562 (select-window window))))
5563 t))
5564 (if gnus-inhibit-mime-unbuttonizing
5565 ;; This is the default though the program shouldn't reach here.
5566 (error "No such part")
5567 ;; The part which doesn't have the MIME button is selected.
5568 ;; So, we display all the buttons and redo it.
5569 (let ((gnus-inhibit-mime-unbuttonizing t))
5570 (gnus-summary-show-article)
5571 (gnus-article-part-wrapper n function no-handle))))))
5572
5573 (defun gnus-article-pipe-part (n)
5574 "Pipe MIME part N, which is the numerical prefix."
5575 (interactive "P")
5576 (gnus-article-part-wrapper n 'mm-pipe-part))
5577
5578 (defun gnus-article-save-part (n)
5579 "Save MIME part N, which is the numerical prefix."
5580 (interactive "P")
5581 (gnus-article-part-wrapper n 'mm-save-part))
5582
5583 (defun gnus-article-interactively-view-part (n)
5584 "View MIME part N interactively, which is the numerical prefix."
5585 (interactive "P")
5586 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5587
5588 (defun gnus-article-copy-part (n)
5589 "Copy MIME part N, which is the numerical prefix."
5590 (interactive "P")
5591 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5592
5593 (defun gnus-article-view-part-as-charset (n)
5594 "View MIME part N using a specified charset.
5595 N is the numerical prefix."
5596 (interactive "P")
5597 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5598
5599 (defun gnus-article-view-part-externally (n)
5600 "View MIME part N externally, which is the numerical prefix."
5601 (interactive "P")
5602 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5603
5604 (defun gnus-article-inline-part (n)
5605 "Inline MIME part N, which is the numerical prefix."
5606 (interactive "P")
5607 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5608
5609 (defun gnus-article-save-part-and-strip (n)
5610 "Save MIME part N and replace it with an external body.
5611 N is the numerical prefix."
5612 (interactive "P")
5613 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5614
5615 (defun gnus-article-replace-part (n)
5616 "Replace MIME part N with an external body.
5617 N is the numerical prefix."
5618 (interactive "P")
5619 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5620
5621 (defun gnus-article-delete-part (n)
5622 "Delete MIME part N and add some information about the removed part.
5623 N is the numerical prefix."
5624 (interactive "P")
5625 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5626
5627 (defun gnus-article-view-part-as-type (n)
5628 "Choose a MIME media type, and view part N as such.
5629 N is the numerical prefix."
5630 (interactive "P")
5631 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5632
5633 (defun gnus-article-mime-match-handle-first (condition)
5634 (if condition
5635 (let (n)
5636 (dolist (ihandle gnus-article-mime-handle-alist)
5637 (if (and (cond
5638 ((functionp condition)
5639 (funcall condition (cdr ihandle)))
5640 ((eq condition 'undisplayed)
5641 (not (or (mm-handle-undisplayer (cdr ihandle))
5642 (equal (mm-handle-media-type (cdr ihandle))
5643 "multipart/alternative"))))
5644 ((eq condition 'undisplayed-alternative)
5645 (not (mm-handle-undisplayer (cdr ihandle))))
5646 (t t))
5647 (gnus-article-goto-part (car ihandle))
5648 (or (not n) (< (car ihandle) n)))
5649 (setq n (car ihandle))))
5650 (or n 1))
5651 1))
5652
5653 (defun gnus-article-view-part (&optional n)
5654 "View MIME part N, which is the numerical prefix.
5655 If the part is already shown, hide the part. If N is nil, view
5656 all parts."
5657 (interactive "P")
5658 (with-current-buffer gnus-article-buffer
5659 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5660 gnus-article-mime-match-handle-function)))
5661 (when (> n (length gnus-article-mime-handle-alist))
5662 (error "No such part"))
5663 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5664 (when (gnus-article-goto-part n)
5665 (if (equal (car handle) "multipart/alternative")
5666 (progn
5667 (beginning-of-line) ;; Make it toggle subparts
5668 (gnus-article-press-button))
5669 (when (eq (gnus-mm-display-part handle) 'internal)
5670 (gnus-set-window-start)))))))
5671
5672 (defsubst gnus-article-mime-total-parts ()
5673 (if (bufferp (car gnus-article-mime-handles))
5674 1 ;; single part
5675 (1- (length gnus-article-mime-handles))))
5676
5677 (defun gnus-mm-display-part (handle)
5678 "Display HANDLE and fix MIME button."
5679 (let ((id (get-text-property (point) 'gnus-part))
5680 (point (point))
5681 (inhibit-read-only t)
5682 (window (selected-window))
5683 (mail-parse-charset gnus-newsgroup-charset)
5684 (mail-parse-ignored-charsets
5685 (if (gnus-buffer-live-p gnus-summary-buffer)
5686 (with-current-buffer gnus-summary-buffer
5687 gnus-newsgroup-ignored-charsets)
5688 nil))
5689 start retval)
5690 (unwind-protect
5691 (progn
5692 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5693 (when win
5694 (select-window win)
5695 (goto-char point)))
5696 (setq start (next-single-property-change point 'gnus-data
5697 nil (point-max))
5698 point (previous-single-property-change start 'gnus-data))
5699 (if (mm-handle-displayed-p handle)
5700 ;; This will remove the part.
5701 (setq point (copy-marker point)
5702 retval (mm-display-part handle))
5703 (let ((part (or (and (mm-inlinable-p handle)
5704 (mm-inlined-p handle)
5705 t)
5706 (with-temp-buffer
5707 (gnus-bind-mm-vars
5708 (setq retval (mm-display-part handle)))
5709 (unless (zerop (buffer-size))
5710 (buffer-string))))))
5711 (goto-char start)
5712 (unless (bolp)
5713 ;; This is a header button.
5714 (forward-line 1))
5715 (cond ((stringp part)
5716 (save-restriction
5717 (narrow-to-region (point)
5718 (progn
5719 (insert part)
5720 (unless (bolp) (insert "\n"))
5721 (point)))
5722 (gnus-treat-article nil id
5723 (gnus-article-mime-total-parts)
5724 (mm-handle-media-type handle))
5725 (mm-handle-set-undisplayer
5726 handle
5727 `(lambda ()
5728 (let ((inhibit-read-only t))
5729 (delete-region ,(copy-marker (point-min) t)
5730 ,(point-max-marker)))))))
5731 (part
5732 (mm-display-inline handle))))))
5733 (when (markerp point)
5734 (setq point (prog1 (marker-position point)
5735 (set-marker point nil))))
5736 (goto-char point)
5737 ;; Toggle the button appearance between `[button]...' and `[button]'.
5738 (let ((displayed-p (mm-handle-displayed-p handle)))
5739 (gnus-insert-mime-button handle id (list displayed-p))
5740 (delete-region
5741 (point)
5742 (next-single-property-change (point) 'gnus-data nil (point-max)))
5743 (setq start (point))
5744 (if (search-backward "\n\n" nil t)
5745 (progn
5746 (goto-char start)
5747 (unless (or displayed-p (eolp))
5748 ;; Add extra newline.
5749 (insert (propertize (buffer-substring (1- start) start)
5750 'gnus-undeletable t))))
5751 ;; We're in the article header.
5752 (delete-char -1)
5753 (dolist (ovl (overlays-in point (point)))
5754 (overlay-put ovl 'gnus-button-attachment-extra t)
5755 (overlay-put ovl 'face nil))
5756 (save-restriction
5757 (message-narrow-to-field)
5758 (let ((gnus-treatment-function-alist
5759 '((gnus-treat-highlight-headers
5760 gnus-article-highlight-headers))))
5761 (gnus-treat-article 'head)))))
5762 (goto-char point)
5763 (if (window-live-p window)
5764 (select-window window)))
5765 retval))
5766
5767 (defun gnus-article-goto-part (n)
5768 "Go to MIME part N."
5769 (when gnus-break-pages
5770 (widen))
5771 (article-goto-body)
5772 (prog1
5773 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5774 ;; There may be header buttons.
5775 (text-property-any (point-min) (point) 'gnus-part n)))
5776 part handle end next handles)
5777 (when start
5778 (goto-char start)
5779 (if (setq handle (get-text-property start 'gnus-data))
5780 start
5781 ;; Go to the displayed subpart, assuming this is
5782 ;; multipart/alternative.
5783 (setq part start
5784 end (point-at-eol))
5785 (while (and (not handle)
5786 part
5787 (< part end)
5788 (setq next (text-property-not-all part end
5789 'gnus-data nil)))
5790 (setq part next
5791 handle (get-text-property part 'gnus-data))
5792 (push (cons handle part) handles)
5793 (unless (mm-handle-displayed-p handle)
5794 (setq handle nil
5795 part (text-property-any part end 'gnus-data nil))))
5796 (unless handle
5797 ;; No subpart is displayed, so we find preferred one.
5798 (setq part
5799 (cdr (assq (mm-preferred-alternative
5800 (nreverse (mapcar 'car handles)))
5801 handles))))
5802 (if part
5803 (goto-char (1+ part))
5804 start))))
5805 (when gnus-break-pages
5806 (gnus-narrow-to-page))))
5807
5808 (defun gnus-insert-mime-button (handle id &optional displayed)
5809 (let ((gnus-tmp-name
5810 (or (mm-handle-filename handle)
5811 (mail-content-type-get (mm-handle-type handle) 'url)
5812 ""))
5813 (gnus-tmp-id id)
5814 (gnus-tmp-type (mm-handle-media-type handle))
5815 (gnus-tmp-description (or (mm-handle-description handle) ""))
5816 (gnus-tmp-dots
5817 (if (if displayed (car displayed)
5818 (mm-handle-displayed-p handle))
5819 "" "..."))
5820 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5821 (buffer-size)))
5822 gnus-tmp-type-long b e)
5823 (when (string-match ".*/" gnus-tmp-name)
5824 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5825 (setq gnus-tmp-type-long (concat gnus-tmp-type
5826 (and (not (equal gnus-tmp-name ""))
5827 (concat "; " gnus-tmp-name))))
5828 (unless (equal gnus-tmp-description "")
5829 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5830 (setq b (point))
5831 (gnus-eval-format
5832 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5833 `(keymap ,gnus-mime-button-map
5834 gnus-callback gnus-mm-display-part
5835 gnus-part ,gnus-tmp-id
5836 article-type annotation
5837 gnus-data ,handle
5838 rear-nonsticky t))
5839 (setq e (if (bolp)
5840 ;; Exclude a newline.
5841 (1- (point))
5842 (point)))
5843 (when gnus-article-button-face
5844 (overlay-put (make-overlay b e nil t)
5845 'face gnus-article-button-face))
5846 (widget-convert-button
5847 'link b e
5848 :mime-handle handle
5849 :action 'gnus-widget-press-button
5850 :button-keymap gnus-mime-button-map
5851 :help-echo
5852 (lambda (widget)
5853 (format
5854 "%S: %s the MIME part; %S: more options"
5855 'mouse-2
5856 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5857 "hide" "show")
5858 'down-mouse-3)))))
5859
5860 (defun gnus-widget-press-button (elems _el)
5861 (goto-char (widget-get elems :from))
5862 (gnus-article-press-button))
5863
5864 (defvar gnus-displaying-mime nil)
5865
5866 (defun gnus-display-mime (&optional ihandles)
5867 "Display the MIME parts."
5868 (save-excursion
5869 (save-selected-window
5870 (let ((window (get-buffer-window gnus-article-buffer))
5871 (point (point)))
5872 (when window
5873 (select-window window)
5874 ;; We have to do this since selecting the window
5875 ;; may change the point. So we set the window point.
5876 (set-window-point window point)))
5877 (let ((handles ihandles)
5878 (inhibit-read-only t))
5879 (cond (handles)
5880 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5881 (when gnus-article-emulate-mime
5882 (mm-uu-dissect-text-parts handles)))
5883 (gnus-article-emulate-mime
5884 (setq handles (mm-uu-dissect))))
5885 (when (and (not ihandles)
5886 (not gnus-displaying-mime))
5887 ;; Top-level call; we clean up.
5888 (when gnus-article-mime-handles
5889 (mm-destroy-parts gnus-article-mime-handles)
5890 (setq gnus-article-mime-handle-alist nil));; A trick.
5891 (setq gnus-article-mime-handles handles)
5892 ;; We allow users to glean info from the handles.
5893 (when gnus-article-mime-part-function
5894 (gnus-mime-part-function handles)))
5895 (if (and handles
5896 (or (not (stringp (car handles)))
5897 (cdr handles)))
5898 (progn
5899 (when (and (not ihandles)
5900 (not gnus-displaying-mime))
5901 ;; Clean up for mime parts.
5902 (article-goto-body)
5903 (delete-region (point) (point-max)))
5904 (let ((gnus-displaying-mime t))
5905 (gnus-mime-display-part handles)))
5906 (save-restriction
5907 (article-goto-body)
5908 (narrow-to-region (point) (point-max))
5909 (gnus-treat-article nil 1 1 "text/plain")
5910 (widen)))
5911 (unless ihandles
5912 ;; Highlight the headers.
5913 (save-excursion
5914 (save-restriction
5915 (article-goto-body)
5916 (narrow-to-region (point-min) (point))
5917 (gnus-article-save-original-date
5918 (gnus-treat-article 'head)))))))
5919 ;; Cope with broken MIME messages.
5920 (goto-char (point-max))
5921 (unless (bolp)
5922 (insert "\n"))))
5923
5924 (defcustom gnus-mime-display-multipart-as-mixed nil
5925 "Display \"multipart\" parts as \"multipart/mixed\".
5926
5927 If t, it overrides nil values of
5928 `gnus-mime-display-multipart-alternative-as-mixed' and
5929 `gnus-mime-display-multipart-related-as-mixed'."
5930 :group 'gnus-article-mime
5931 :type 'boolean)
5932
5933 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5934 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5935 :version "22.1"
5936 :group 'gnus-article-mime
5937 :type 'boolean)
5938
5939 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5940 "Display \"multipart/related\" parts as \"multipart/mixed\".
5941
5942 If displaying \"text/html\" is discouraged \(see
5943 `mm-discouraged-alternatives') images or other material inside a
5944 \"multipart/related\" part might be overlooked when this variable is nil."
5945 :version "22.1"
5946 :group 'gnus-article-mime
5947 :type 'boolean)
5948
5949 (defcustom gnus-mime-display-attachment-buttons-in-header t
5950 "Add attachment buttons in the end of the header of an article.
5951 Since MIME attachments tend to be put at the end of an article, we may
5952 overlook them if there is a huge body. This option offers you a copy
5953 of all non-inlinable MIME parts as buttons shown in front of an article.
5954 If nil, don't show those extra buttons."
5955 :version "25.1"
5956 :group 'gnus-article-mime
5957 :type 'boolean)
5958
5959 (defun gnus-mime-display-part (handle)
5960 (cond
5961 ;; Maybe a broken MIME message.
5962 ((null handle))
5963 ;; Single part.
5964 ((not (stringp (car handle)))
5965 (gnus-mime-display-single handle))
5966 ;; User-defined multipart
5967 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5968 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5969 handle))
5970 ;; multipart/alternative
5971 ((and (equal (car handle) "multipart/alternative")
5972 (not (or gnus-mime-display-multipart-as-mixed
5973 gnus-mime-display-multipart-alternative-as-mixed)))
5974 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5975 (push (cons id handle) gnus-article-mime-handle-alist)
5976 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5977 ;; multipart/related
5978 ((and (equal (car handle) "multipart/related")
5979 (not (or gnus-mime-display-multipart-as-mixed
5980 gnus-mime-display-multipart-related-as-mixed)))
5981 (gnus-mime-display-part (cadr handle)))
5982 ((equal (car handle) "multipart/signed")
5983 (gnus-add-wash-type 'signed)
5984 (gnus-mime-display-security handle))
5985 ((equal (car handle) "multipart/encrypted")
5986 (gnus-add-wash-type 'encrypted)
5987 (gnus-mime-display-security handle))
5988 ;; Other multiparts are handled like multipart/mixed.
5989 (t
5990 (gnus-mime-display-mixed (cdr handle)))))
5991
5992 (defun gnus-mime-part-function (handles)
5993 (if (stringp (car handles))
5994 (mapcar 'gnus-mime-part-function (cdr handles))
5995 (funcall gnus-article-mime-part-function handles)))
5996
5997 (defun gnus-mime-display-mixed (handles)
5998 (mapcar 'gnus-mime-display-part handles))
5999
6000 (defun gnus-mime-display-single (handle)
6001 (let ((type (mm-handle-media-type handle))
6002 (ignored gnus-ignored-mime-types)
6003 (not-attachment t)
6004 display text)
6005 (catch 'ignored
6006 (progn
6007 (while ignored
6008 (when (string-match (pop ignored) type)
6009 (throw 'ignored nil)))
6010 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6011 (with-current-buffer gnus-summary-buffer
6012 gnus-inhibit-images)
6013 gnus-inhibit-images)
6014 (string-match "\\`image/" type)))
6015 (setq not-attachment
6016 (and (not (mm-inline-override-p handle))
6017 (or (not (mm-handle-disposition handle))
6018 (equal (car (mm-handle-disposition handle))
6019 "inline")
6020 (mm-attachment-override-p handle))))
6021 (mm-automatic-display-p handle)
6022 (or (and
6023 (mm-inlinable-p handle)
6024 (mm-inlined-p handle))
6025 (mm-automatic-external-display-p type)))
6026 (setq display t)
6027 (when (equal (mm-handle-media-supertype handle) "text")
6028 (setq text t)))
6029 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6030 beg)
6031 (unless id
6032 (setq id (1+ (length gnus-article-mime-handle-alist)))
6033 (push (cons id handle) gnus-article-mime-handle-alist))
6034 (when (and display
6035 (equal (mm-handle-media-supertype handle) "message"))
6036 (insert-char
6037 ?\n
6038 (cond ((not (bolp)) 2)
6039 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6040 (t 1))))
6041 (when (or (not display)
6042 (not (gnus-unbuttonized-mime-type-p type))
6043 (eq id gnus-mime-buttonized-part-id))
6044 (gnus-insert-mime-button
6045 handle id (list (or display (and not-attachment text)))))
6046 (setq beg (point))
6047 (cond
6048 (display
6049 (let ((mail-parse-charset gnus-newsgroup-charset)
6050 (mail-parse-ignored-charsets
6051 (save-excursion (condition-case ()
6052 (set-buffer gnus-summary-buffer)
6053 (error))
6054 gnus-newsgroup-ignored-charsets)))
6055 (gnus-bind-mm-vars (mm-display-part handle t))))
6056 ((and text not-attachment)
6057 (mm-display-inline handle)))
6058 (goto-char (point-max))
6059 (if (string-match "\\`image/" type)
6060 (gnus-article-insert-newline)
6061 (if (prog1
6062 (= (skip-chars-backward "\n") -1)
6063 (unless (eobp) (forward-char 1)))
6064 (gnus-article-insert-newline)
6065 (put-text-property (point) (point-max) 'gnus-undeletable t))
6066 (goto-char (point-max)))
6067 ;; Do highlighting.
6068 (save-excursion
6069 (save-restriction
6070 (narrow-to-region beg (point))
6071 (if (eq handle gnus-article-mime-handles)
6072 ;; The format=flowed case.
6073 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6074 ;; Don't count signature parts that are never displayed.
6075 ;; The part number should be re-calculated supposing this
6076 ;; might be a message/rfc822 part.
6077 (let (handles)
6078 (dolist (part gnus-article-mime-handles)
6079 (unless (or (stringp part)
6080 (equal (car (mm-handle-type part))
6081 "application/pgp-signature"))
6082 (push part handles)))
6083 (gnus-treat-article
6084 nil (length (memq handle handles)) (length handles)
6085 (mm-handle-media-type handle)))))))))))
6086
6087 (defun gnus-unbuttonized-mime-type-p (type)
6088 "Say whether TYPE is to be unbuttonized."
6089 (unless gnus-inhibit-mime-unbuttonizing
6090 (when (catch 'found
6091 (let ((types gnus-unbuttonized-mime-types))
6092 (while types
6093 (when (string-match (pop types) type)
6094 (throw 'found t)))))
6095 (not (catch 'found
6096 (let ((types gnus-buttonized-mime-types))
6097 (while types
6098 (when (string-match (pop types) type)
6099 (throw 'found t)))))))))
6100
6101 (defun gnus-article-insert-newline ()
6102 "Insert a newline, but mark it as undeletable."
6103 (put-text-property (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6104
6105 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6106 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6107 (ihandles handles)
6108 (point (point))
6109 handle (inhibit-read-only t) from begend not-pref)
6110 (save-window-excursion
6111 (save-restriction
6112 (when ibegend
6113 (narrow-to-region (car ibegend)
6114 (or (cdr ibegend)
6115 (progn
6116 (goto-char (car ibegend))
6117 (forward-line 2)
6118 (point))))
6119 (delete-region (point-min) (point-max))
6120 (mm-remove-parts handles))
6121 (setq begend (list (point-marker)))
6122 ;; Do the toggle.
6123 (unless (setq not-pref (cadr (member preferred ihandles)))
6124 (setq not-pref (car ihandles)))
6125 (when (or ibegend
6126 (not preferred)
6127 (not (gnus-unbuttonized-mime-type-p
6128 "multipart/alternative")))
6129 (add-text-properties
6130 (setq from (point))
6131 (progn
6132 (insert (format "%d. " id))
6133 (point))
6134 `(gnus-callback
6135 (lambda (handles)
6136 (unless ,(not ibegend)
6137 (setq gnus-article-mime-handle-alist
6138 ',gnus-article-mime-handle-alist))
6139 (gnus-mime-display-alternative
6140 ',ihandles ',not-pref ',begend ,id))
6141 keymap ,gnus-mime-button-map
6142 mouse-face ,gnus-article-mouse-face
6143 face ,gnus-article-button-face
6144 gnus-part ,id
6145 article-type multipart
6146 rear-nonsticky t))
6147 (widget-convert-button 'link from (point)
6148 :action 'gnus-widget-press-button)
6149 ;; Do the handles
6150 (while (setq handle (pop handles))
6151 (add-text-properties
6152 (setq from (point))
6153 (progn
6154 (insert (format "(%c) %-18s"
6155 (if (equal handle preferred) ?* ? )
6156 (mm-handle-media-type handle)))
6157 (point))
6158 `(gnus-callback
6159 (lambda (handles)
6160 (unless ,(not ibegend)
6161 (setq gnus-article-mime-handle-alist
6162 ',gnus-article-mime-handle-alist))
6163 (gnus-mime-display-alternative
6164 ',ihandles ',handle ',begend ,id))
6165 keymap ,gnus-mime-button-map
6166 mouse-face ,gnus-article-mouse-face
6167 face ,gnus-article-button-face
6168 gnus-part ,id
6169 gnus-data ,handle
6170 rear-nonsticky t))
6171 (widget-convert-button 'link from (point)
6172 :action 'gnus-widget-press-button)
6173 (insert " "))
6174 (insert "\n\n"))
6175 (when preferred
6176 (if (stringp (car preferred))
6177 (gnus-display-mime preferred)
6178 (let ((mail-parse-charset gnus-newsgroup-charset)
6179 (mail-parse-ignored-charsets
6180 (with-current-buffer gnus-summary-buffer
6181 gnus-newsgroup-ignored-charsets)))
6182 (gnus-bind-mm-vars (mm-display-part preferred))
6183 ;; Do highlighting.
6184 (save-excursion
6185 (save-restriction
6186 (narrow-to-region (car begend) (point-max))
6187 (gnus-treat-article
6188 nil (length gnus-article-mime-handle-alist)
6189 (gnus-article-mime-total-parts)
6190 (mm-handle-media-type preferred))))))
6191 (goto-char (point-max))
6192 (setcdr begend (point-marker)))))
6193 (when ibegend
6194 (goto-char point)))
6195 ;; Redraw attachment buttons in the header.
6196 (when gnus-mime-display-attachment-buttons-in-header
6197 (gnus-mime-buttonize-attachments-in-header)))
6198
6199 (defconst gnus-article-wash-status-strings
6200 (let ((alist '((cite "c" "Possible hidden citation text"
6201 " " "All citation text visible")
6202 (headers "h" "Hidden headers"
6203 " " "All headers visible.")
6204 (pgp "p" "Encrypted or signed message status hidden"
6205 " " "No hidden encryption nor digital signature status")
6206 (signature "s" "Signature has been hidden"
6207 " " "Signature is visible")
6208 (overstrike "o" "Overstrike (^H) characters applied"
6209 " " "No overstrike characters applied")
6210 (emphasis "e" "/*_Emphasis_*/ characters applied"
6211 " " "No /*_emphasis_*/ characters applied")))
6212 result)
6213 (dolist (entry alist result)
6214 (let ((key (nth 0 entry))
6215 (on (copy-sequence (nth 1 entry)))
6216 (on-help (nth 2 entry))
6217 (off (copy-sequence (nth 3 entry)))
6218 (off-help (nth 4 entry)))
6219 (put-text-property 0 1 'help-echo on-help on)
6220 (put-text-property 0 1 'help-echo off-help off)
6221 (push (list key on off) result))))
6222 "Alist of strings describing wash status in the mode line.
6223 Each entry has the form (KEY ON OF), where the KEY is a symbol
6224 representing the particular washing function, ON is the string to use
6225 in the article mode line when the washing function is active, and OFF
6226 is the string to use when it is inactive.")
6227
6228 (defun gnus-article-wash-status-entry (key value)
6229 (let ((entry (assoc key gnus-article-wash-status-strings)))
6230 (if value (nth 1 entry) (nth 2 entry))))
6231
6232 (defun gnus-article-wash-status ()
6233 "Return a string which display status of article washing."
6234 (with-current-buffer gnus-article-buffer
6235 (let ((cite (memq 'cite gnus-article-wash-types))
6236 (headers (memq 'headers gnus-article-wash-types))
6237 (boring (memq 'boring-headers gnus-article-wash-types))
6238 (pgp (memq 'pgp gnus-article-wash-types))
6239 (pem (memq 'pem gnus-article-wash-types))
6240 (signed (memq 'signed gnus-article-wash-types))
6241 (encrypted (memq 'encrypted gnus-article-wash-types))
6242 (signature (memq 'signature gnus-article-wash-types))
6243 (overstrike (memq 'overstrike gnus-article-wash-types))
6244 (emphasis (memq 'emphasis gnus-article-wash-types)))
6245 (concat
6246 (gnus-article-wash-status-entry 'cite cite)
6247 (gnus-article-wash-status-entry 'headers (or headers boring))
6248 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6249 (gnus-article-wash-status-entry 'signature signature)
6250 (gnus-article-wash-status-entry 'overstrike overstrike)
6251 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6252
6253 (defun gnus-add-wash-type (type)
6254 "Add a washing of TYPE to the current status."
6255 (add-to-list 'gnus-article-wash-types type))
6256
6257 (defun gnus-delete-wash-type (type)
6258 "Add a washing of TYPE to the current status."
6259 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6260
6261 (defun gnus-add-image (category image)
6262 "Add IMAGE of CATEGORY to the list of displayed images."
6263 (let ((entry (assq category gnus-article-image-alist)))
6264 (unless entry
6265 (setq entry (list category))
6266 (push entry gnus-article-image-alist))
6267 (nconc entry (list image))))
6268
6269 (defun gnus-delete-images (category)
6270 "Delete all images in CATEGORY."
6271 (let ((entry (assq category gnus-article-image-alist)))
6272 (dolist (image (cdr entry))
6273 (gnus-remove-image image category))
6274 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6275 (gnus-delete-wash-type category)))
6276
6277 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6278
6279 (defun gnus-article-maybe-hide-headers ()
6280 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6281 Provided for backwards compatibility."
6282 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6283 (not (with-current-buffer gnus-summary-buffer
6284 gnus-have-all-headers)))
6285 (not gnus-inhibit-hiding))
6286 (article-hide-headers)))
6287
6288 (declare-function shr-put-image "shr" (data alt &optional flags))
6289
6290 (defun gnus-shr-put-image (data alt &optional flags)
6291 "Put image DATA with a string ALT. Enable image to be deleted."
6292 (let ((image (if flags
6293 (shr-put-image data (propertize (or alt "*")
6294 'gnus-image-category 'shr)
6295 flags)
6296 ;; Old `shr-put-image' doesn't take the optional `flags'
6297 ;; argument.
6298 (shr-put-image data (propertize (or alt "*")
6299 'gnus-image-category 'shr)))))
6300 (when image
6301 (gnus-add-image 'shr image))))
6302
6303 (defun gnus-article-mime-handles (&optional alist id all)
6304 (if alist
6305 (let ((i 1) newid flat)
6306 (dolist (handle alist flat)
6307 (setq newid (append id (list i))
6308 i (1+ i))
6309 (if (stringp (car handle))
6310 (setq flat (nconc flat (gnus-article-mime-handles
6311 (cdr handle) newid all)))
6312 (delq (rassq handle all) all)
6313 (setq flat (nconc flat (list (cons newid handle)))))))
6314 (let ((flat (list nil)))
6315 ;; Assume that elements of `gnus-article-mime-handle-alist'
6316 ;; are in the decreasing order, but unnumbered subsidiaries
6317 ;; in each element are in the increasing order.
6318 (dolist (handle (reverse gnus-article-mime-handle-alist))
6319 (if (stringp (cadr handle))
6320 (setq flat (nconc flat (gnus-article-mime-handles
6321 (cddr handle) (list (car handle)) flat)))
6322 (delq (rassq (cdr handle) flat) flat)
6323 (setq flat (nconc flat (list (cons (list (car handle))
6324 (cdr handle)))))))
6325 (setq flat (cdr flat))
6326 (mapc (lambda (handle)
6327 (if (cdar handle)
6328 ;; This is a hidden (i.e. unnumbered) handle.
6329 (progn
6330 (setcar handle
6331 (1+ (caar gnus-article-mime-handle-alist)))
6332 (push handle gnus-article-mime-handle-alist))
6333 (setcar handle (caar handle))))
6334 flat)
6335 flat)))
6336
6337 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6338 "Show attachments as buttons in the end of the header of an article.
6339 This function toggles the display when called interactively. Note that
6340 buttons to be added to the header are only the ones that aren't inlined
6341 in the body. Use `gnus-header-face-alist' to highlight buttons."
6342 (interactive (list t))
6343 (gnus-with-article-buffer
6344 (let ((case-fold-search t) buttons handle type st)
6345 (save-excursion
6346 (save-restriction
6347 (widen)
6348 (article-narrow-to-head)
6349 ;; Header buttons exist?
6350 (while (and (not buttons)
6351 (re-search-forward "^attachments?:[\n ]+" nil t))
6352 (when (get-char-property (match-end 0)
6353 'gnus-button-attachment-extra)
6354 (setq buttons (match-beginning 0))))
6355 (widen)
6356 (when buttons
6357 ;; Delete header buttons.
6358 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6359 (match-beginning 0)
6360 (point-max))))
6361 (unless (and interactive buttons)
6362 ;; Find buttons.
6363 (setq buttons nil)
6364 (dolist (button (gnus-article-mime-handles))
6365 (setq handle (cdr button)
6366 type (mm-handle-media-type handle))
6367 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6368 (with-current-buffer gnus-summary-buffer
6369 gnus-inhibit-images)
6370 gnus-inhibit-images)
6371 (string-match "\\`image/" type))
6372 (mm-inline-override-p handle)
6373 (and (mm-handle-disposition handle)
6374 (not (equal (car (mm-handle-disposition handle))
6375 "inline"))
6376 (not (mm-attachment-override-p handle)))
6377 (not (mm-automatic-display-p handle))
6378 (not (or (and (mm-inlinable-p handle)
6379 (mm-inlined-p handle))
6380 (mm-automatic-external-display-p type))))
6381 (push button buttons)))
6382 (when buttons
6383 ;; Add header buttons.
6384 (article-goto-body)
6385 (forward-line -1)
6386 (narrow-to-region (point) (point))
6387 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6388 (dolist (button (nreverse buttons))
6389 (setq st (point))
6390 (insert " ")
6391 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6392 (gnus-insert-mime-button handle (car button))
6393 (skip-chars-backward "\t\n ")
6394 (delete-region (point) (point-max))
6395 (when (> (current-column) (window-width))
6396 (goto-char st)
6397 (insert "\n")
6398 (end-of-line)))
6399 (insert "\n")
6400 (dolist (ovl (overlays-in (point-min) (point)))
6401 (overlay-put ovl 'gnus-button-attachment-extra t)
6402 (overlay-put ovl 'face nil))
6403 (let ((gnus-treatment-function-alist
6404 '((gnus-treat-highlight-headers
6405 gnus-article-highlight-headers))))
6406 (gnus-treat-article 'head)))))))))
6407
6408 ;;; Article savers.
6409
6410 (defun gnus-output-to-file (file-name)
6411 "Append the current article to a file named FILE-NAME.
6412 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6413 text and used as the value of the coding cookie which is added to the
6414 top of a file. Otherwise, this function saves a raw article without
6415 the coding cookie."
6416 (let* ((artbuf (current-buffer))
6417 (file-name-coding-system nnmail-pathname-coding-system)
6418 (coding gnus-article-save-coding-system)
6419 (coding-system-for-read (if coding
6420 nil ;; Rely on the coding cookie.
6421 mm-text-coding-system))
6422 (coding-system-for-write (or coding
6423 mm-text-coding-system-for-write
6424 mm-text-coding-system))
6425 (exists (file-exists-p file-name)))
6426 (with-temp-buffer
6427 (when exists
6428 (insert-file-contents file-name)
6429 (goto-char (point-min))
6430 ;; Remove the existing coding cookie.
6431 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6432 (delete-region (match-beginning 0) (match-end 0))))
6433 (goto-char (point-max))
6434 (insert-buffer-substring artbuf)
6435 ;; Append newline at end of the buffer as separator, and then
6436 ;; save it to file.
6437 (goto-char (point-max))
6438 (insert "\n")
6439 (when coding
6440 ;; If the coding system is not suitable to encode the text,
6441 ;; ask a user for a proper one.
6442 (setq coding (coding-system-base
6443 (save-window-excursion
6444 (select-safe-coding-system (point-min) (point-max)
6445 coding))))
6446 (setq coding-system-for-write
6447 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6448 coding))
6449 (goto-char (point-min))
6450 ;; Add the coding cookie.
6451 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6452 coding-system-for-write)))
6453 (if exists
6454 (progn
6455 (write-region (point-min) (point-max) file-name nil 'no-message)
6456 (message "Appended to %s" file-name))
6457 (write-region (point-min) (point-max) file-name))))
6458 t)
6459
6460 (defun gnus-narrow-to-page (&optional arg)
6461 "Narrow the article buffer to a page.
6462 If given a numerical ARG, move forward ARG pages."
6463 (interactive "P")
6464 (setq arg (if arg (prefix-numeric-value arg) 0))
6465 (with-current-buffer gnus-article-buffer
6466 (widen)
6467 ;; Remove any old next/prev buttons.
6468 (when (gnus-visual-p 'page-marker)
6469 (let ((inhibit-read-only t))
6470 (gnus-remove-text-with-property 'gnus-prev)
6471 (gnus-remove-text-with-property 'gnus-next)))
6472 (let (st nd pt)
6473 (when (save-excursion
6474 (cond ((< arg 0)
6475 (if (re-search-backward page-delimiter nil 'move (abs arg))
6476 (prog1
6477 (setq nd (match-beginning 0)
6478 pt nd)
6479 (when (re-search-backward page-delimiter nil t)
6480 (setq st (match-end 0))))
6481 (when (re-search-forward page-delimiter nil t)
6482 (setq nd (match-beginning 0)
6483 pt (point-min)))))
6484 ((> arg 0)
6485 (if (re-search-forward page-delimiter nil 'move arg)
6486 (prog1
6487 (setq st (match-end 0)
6488 pt st)
6489 (when (re-search-forward page-delimiter nil t)
6490 (setq nd (match-beginning 0))))
6491 (when (re-search-backward page-delimiter nil t)
6492 (setq st (match-end 0)
6493 pt (point-max)))))
6494 (t
6495 (when (re-search-backward page-delimiter nil t)
6496 (goto-char (setq st (match-end 0))))
6497 (when (re-search-forward page-delimiter nil t)
6498 (setq nd (match-beginning 0)))
6499 (or st nd))))
6500 (setq gnus-page-broken t)
6501 (when pt (goto-char pt))
6502 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6503 (when (gnus-visual-p 'page-marker)
6504 (save-excursion
6505 (when nd
6506 (goto-char nd)
6507 (gnus-insert-next-page-button))
6508 (when st
6509 (goto-char st)
6510 (gnus-insert-prev-page-button))))))))
6511
6512 ;; Article mode commands
6513
6514 (defun gnus-article-goto-next-page ()
6515 "Show the next page of the article."
6516 (interactive)
6517 (when (gnus-article-next-page)
6518 (goto-char (point-min))
6519 (gnus-article-read-summary-keys nil ?n)))
6520
6521
6522 (defun gnus-article-goto-prev-page ()
6523 "Show the previous page of the article."
6524 (interactive)
6525 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6526 (gnus-article-read-summary-keys nil ?p)
6527 (gnus-article-prev-page nil)))
6528
6529 ;; This is cleaner but currently breaks `gnus-pick-mode':
6530 ;;
6531 ;; (defun gnus-article-goto-next-page ()
6532 ;; "Show the next page of the article."
6533 ;; (interactive)
6534 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6535 ;; (gnus-summary-next-page)))
6536 ;;
6537 ;; (defun gnus-article-goto-prev-page ()
6538 ;; "Show the next page of the article."
6539 ;; (interactive)
6540 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6541 ;; (gnus-summary-prev-page)))
6542
6543 (defun gnus-article-next-page (&optional lines)
6544 "Show the next page of the current article.
6545 If end of article, return non-nil. Otherwise return nil.
6546 Argument LINES specifies lines to be scrolled up."
6547 (interactive "p")
6548 (move-to-window-line (- -1 scroll-margin))
6549 (if (and (not (and gnus-article-over-scroll
6550 (> (count-lines (window-start) (point-max))
6551 (+ (or lines (1- (window-height))) scroll-margin))))
6552 (save-excursion
6553 (end-of-line)
6554 (and (pos-visible-in-window-p) ;Not continuation line.
6555 (>= (point) (point-max)))))
6556 ;; Nothing in this page.
6557 (if (or (not gnus-page-broken)
6558 (save-excursion
6559 (save-restriction
6560 (widen)
6561 (forward-line)
6562 (eobp)))) ;Real end-of-buffer?
6563 (progn
6564 (when gnus-article-over-scroll
6565 (gnus-article-next-page-1 lines))
6566 t) ;Nothing more.
6567 (gnus-narrow-to-page 1) ;Go to next page.
6568 nil)
6569 ;; More in this page.
6570 (gnus-article-next-page-1 lines)
6571 nil))
6572
6573 (defun gnus-article-beginning-of-window ()
6574 "Move point to the beginning of the window.
6575 The point is placed at the line number which `scroll-margin'
6576 specifies."
6577 ;; There is an obscure bug in Emacs that makes it impossible to
6578 ;; scroll past big pictures in the article buffer. Try to fix
6579 ;; this by adding a sanity check by counting the lines visible.
6580 (when (> (count-lines (window-start) (window-end)) 30)
6581 (move-to-window-line
6582 (min (max 0 scroll-margin)
6583 (max 1 (- (window-height)
6584 (if mode-line-format 1 0)
6585 (if header-line-format 1 0)
6586 2))))))
6587
6588 (defvar scroll-in-place)
6589
6590 (defun gnus-article-next-page-1 (lines)
6591 (condition-case ()
6592 (let ((scroll-in-place nil)
6593 (auto-window-vscroll nil))
6594 (scroll-up lines))
6595 (end-of-buffer
6596 ;; Long lines may cause an end-of-buffer error.
6597 (goto-char (point-max))))
6598 (gnus-article-beginning-of-window))
6599
6600 (defun gnus-article-prev-page (&optional lines)
6601 "Show previous page of current article.
6602 Argument LINES specifies lines to be scrolled down."
6603 (interactive "p")
6604 (move-to-window-line 0)
6605 (if (and gnus-page-broken
6606 (bobp)
6607 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6608 (progn
6609 (gnus-narrow-to-page -1) ;Go to previous page.
6610 (goto-char (point-max))
6611 (recenter (if gnus-article-over-scroll
6612 (if lines
6613 (max (+ lines scroll-margin) 3)
6614 (- (window-height) 2))
6615 -1)))
6616 (prog1
6617 (condition-case ()
6618 (let ((scroll-in-place nil))
6619 (scroll-down lines))
6620 (beginning-of-buffer
6621 (goto-char (point-min))))
6622 (gnus-article-beginning-of-window))))
6623
6624 (defun gnus-article-only-boring-p ()
6625 "Decide whether there is only boring text remaining in the article.
6626 Something \"interesting\" is a word of at least two letters that does
6627 not have a face in `gnus-article-boring-faces'."
6628 (when (and gnus-article-skip-boring
6629 (boundp 'gnus-article-boring-faces)
6630 (symbol-value 'gnus-article-boring-faces))
6631 (save-excursion
6632 (let ((inhibit-point-motion-hooks t))
6633 (catch 'only-boring
6634 (while (re-search-forward "\\b\\w\\w" nil t)
6635 (forward-char -1)
6636 (when (not (gnus-intersection
6637 (gnus-faces-at (point))
6638 (symbol-value 'gnus-article-boring-faces)))
6639 (throw 'only-boring nil)))
6640 (throw 'only-boring t))))))
6641
6642 (defun gnus-article-refer-article ()
6643 "Read article specified by message-id around point."
6644 (interactive)
6645 (save-excursion
6646 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6647 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6648 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6649 (let ((msg-id (concat "<" (match-string 0) ">")))
6650 (set-buffer gnus-summary-buffer)
6651 (gnus-summary-refer-article msg-id))
6652 (error "No references around point"))))
6653
6654 (defun gnus-article-show-summary ()
6655 "Reconfigure windows to show summary buffer."
6656 (interactive)
6657 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6658 (error "There is no summary buffer for this article buffer")
6659 (gnus-article-set-globals)
6660 (gnus-configure-windows 'article)
6661 (gnus-summary-goto-subject gnus-current-article)
6662 (gnus-summary-position-point)))
6663
6664 (defun gnus-article-describe-briefly ()
6665 "Describe article mode commands briefly."
6666 (interactive)
6667 (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")))
6668
6669 (defun gnus-article-check-buffer ()
6670 "Beep if not in an article buffer."
6671 (unless (derived-mode-p 'gnus-article-mode)
6672 (error "Command invoked outside of a Gnus article buffer")))
6673
6674 (defvar gnus-pick-mode)
6675
6676 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6677 "Read a summary buffer key sequence and execute it from the article buffer."
6678 (interactive "P")
6679 (gnus-article-check-buffer)
6680 (let ((nosaves
6681 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6682 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6683 "=" "^" "\M-^" "|"))
6684 (nosave-but-article
6685 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6686 "An" "Ap" [?A (meta return)] [?A delete]))
6687 (nosave-in-article
6688 '("AS" "\C-d"))
6689 keys new-sum-point)
6690 (with-current-buffer gnus-article-current-summary
6691 (let (gnus-pick-mode)
6692 (setq unread-command-events (nconc unread-command-events
6693 (list (or key last-command-event)))
6694 keys (read-key-sequence nil t))))
6695
6696 (message "")
6697
6698 (cond
6699 ((eq (aref keys (1- (length keys))) ?\C-h)
6700 (gnus-article-describe-bindings (substring keys 0 -1)))
6701 ((or (member keys nosaves)
6702 (member keys nosave-but-article)
6703 (member keys nosave-in-article))
6704 (let (func)
6705 (save-window-excursion
6706 (pop-to-buffer gnus-article-current-summary)
6707 ;; We disable the pick minor mode commands.
6708 (let (gnus-pick-mode)
6709 (setq func (key-binding keys t))))
6710 (if (or (not func)
6711 (numberp func))
6712 (ding)
6713 (unless (member keys nosave-in-article)
6714 (set-buffer gnus-article-current-summary))
6715 (when (and (symbolp func)
6716 (get func 'disabled))
6717 (error "Function %s disabled" func))
6718 (call-interactively func)
6719 (setq new-sum-point (point)))
6720 (when (member keys nosave-but-article)
6721 (pop-to-buffer gnus-article-buffer))))
6722 (t
6723 ;; These commands should restore window configuration.
6724 (let ((obuf (current-buffer))
6725 (owin (current-window-configuration))
6726 win func in-buffer selected new-sum-start new-sum-hscroll err)
6727 (cond (not-restore-window
6728 (pop-to-buffer gnus-article-current-summary)
6729 (setq win (selected-window)))
6730 ((setq win (get-buffer-window gnus-article-current-summary))
6731 (select-window win))
6732 (t
6733 (let ((summary-buffer gnus-article-current-summary))
6734 (gnus-configure-windows 'article)
6735 (unless (setq win (get-buffer-window summary-buffer 'visible))
6736 (let ((gnus-buffer-configuration
6737 '((article ((vertical 1.0
6738 (summary 0.25 point)
6739 (article 1.0)))))))
6740 (gnus-configure-windows 'article))
6741 (setq win (get-buffer-window summary-buffer 'visible)))
6742 (select-frame-set-input-focus (window-frame win))
6743 (select-window win))))
6744 (setq in-buffer (current-buffer))
6745 ;; We disable the pick minor mode commands.
6746 (setq func (let (gnus-pick-mode)
6747 (key-binding keys t)))
6748 (when (get func 'disabled)
6749 (error "Function %s disabled" func))
6750 (if (and func
6751 (functionp func)
6752 (condition-case code
6753 (progn
6754 (call-interactively func)
6755 t)
6756 (error
6757 (setq err code)
6758 nil)))
6759 (progn
6760 (when (eq win (selected-window))
6761 (setq new-sum-point (point)
6762 new-sum-start (window-start win)
6763 new-sum-hscroll (window-hscroll win)))
6764 (when (or (eq in-buffer (current-buffer))
6765 (when (eq obuf (current-buffer))
6766 (set-buffer in-buffer)
6767 t))
6768 (setq selected (ignore-errors (gnus-summary-select-article)))
6769 (set-buffer obuf)
6770 (unless not-restore-window
6771 (set-window-configuration owin))
6772 (when (and (eq selected 'old)
6773 new-sum-point)
6774 (set-window-start (get-buffer-window (current-buffer))
6775 1)
6776 (set-window-point (get-buffer-window (current-buffer))
6777 (if (article-goto-body)
6778 (1- (point))
6779 (point))))
6780 (when (and (not not-restore-window)
6781 new-sum-point
6782 (window-live-p win)
6783 (with-current-buffer (window-buffer win)
6784 (derived-mode-p 'gnus-summary-mode)))
6785 (set-window-point win new-sum-point)
6786 (set-window-start win new-sum-start)
6787 (set-window-hscroll win new-sum-hscroll))))
6788 (set-window-configuration owin)
6789 (if err
6790 (signal (car err) (cdr err))
6791 (ding))))))))
6792
6793 (defun gnus-article-read-summary-send-keys ()
6794 (interactive)
6795 (let ((unread-command-events (list ?S)))
6796 (gnus-article-read-summary-keys)))
6797
6798 (defun gnus-article-describe-key (key)
6799 "Display documentation of the function invoked by KEY.
6800 KEY is a string or a vector."
6801 (interactive (list (let ((cursor-in-echo-area t))
6802 (read-key-sequence "Describe key: "))))
6803 (gnus-article-check-buffer)
6804 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6805 gnus-article-read-summary-send-keys))
6806 (with-current-buffer gnus-article-current-summary
6807 (setq unread-command-events
6808 (nconc
6809 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6810 (list 'meta (- x 128))
6811 x))
6812 key)
6813 unread-command-events))
6814 (let ((cursor-in-echo-area t)
6815 gnus-pick-mode)
6816 (describe-key (read-key-sequence nil t))))
6817 (describe-key key)))
6818
6819 (defun gnus-article-describe-key-briefly (key &optional insert)
6820 "Display documentation of the function invoked by KEY.
6821 KEY is a string or a vector."
6822 (interactive (list (let ((cursor-in-echo-area t))
6823 (read-key-sequence "Describe key: "))
6824 current-prefix-arg))
6825 (gnus-article-check-buffer)
6826 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6827 gnus-article-read-summary-send-keys))
6828 (with-current-buffer gnus-article-current-summary
6829 (setq unread-command-events
6830 (nconc
6831 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6832 (list 'meta (- x 128))
6833 x))
6834 key)
6835 unread-command-events))
6836 (let ((cursor-in-echo-area t)
6837 gnus-pick-mode)
6838 (describe-key-briefly (read-key-sequence nil t) insert)))
6839 (describe-key-briefly key insert)))
6840
6841 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6842 (defvar gnus-agent-summary-mode)
6843 (defvar gnus-draft-mode)
6844 (defvar help-xref-stack-item)
6845 (defvar help-xref-following)
6846
6847 (defun gnus-article-describe-bindings (&optional prefix)
6848 "Show a list of all defined keys, and their definitions.
6849 The optional argument PREFIX, if non-nil, should be a key sequence;
6850 then we display only bindings that start with that prefix."
6851 (interactive)
6852 (gnus-article-check-buffer)
6853 (let ((keymap (copy-keymap gnus-article-mode-map))
6854 (map (copy-keymap gnus-article-send-map))
6855 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6856 parent agent draft)
6857 (define-key keymap "S" map)
6858 (define-key map [t] nil)
6859 (with-current-buffer gnus-article-current-summary
6860 (set-keymap-parent
6861 keymap
6862 (if (setq parent (keymap-parent gnus-article-mode-map))
6863 (prog1
6864 (setq parent (copy-keymap parent))
6865 (set-keymap-parent parent (current-local-map)))
6866 (current-local-map)))
6867 (set-keymap-parent map (key-binding "S"))
6868 (let (key def gnus-pick-mode)
6869 (while sumkeys
6870 (setq key (pop sumkeys))
6871 (cond ((and (vectorp key) (= (length key) 1)
6872 (consp (setq def (aref key 0)))
6873 (numberp (car def)) (numberp (cdr def)))
6874 (when (< (max (car def) (cdr def)) 128)
6875 (setq sumkeys
6876 (append (mapcar
6877 #'vector
6878 (nreverse (gnus-uncompress-range def)))
6879 sumkeys))))
6880 ((setq def (key-binding key))
6881 (unless (eq def 'undefined)
6882 (define-key keymap key def))))))
6883 (when (boundp 'gnus-agent-summary-mode)
6884 (setq agent gnus-agent-summary-mode))
6885 (when (boundp 'gnus-draft-mode)
6886 (setq draft gnus-draft-mode)))
6887 (with-temp-buffer
6888 (use-local-map keymap)
6889 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6890 (set (make-local-variable 'gnus-draft-mode) draft)
6891 (describe-bindings prefix))
6892 (let ((item `((lambda (prefix)
6893 (with-current-buffer ,(current-buffer)
6894 (gnus-article-describe-bindings prefix)))
6895 ,prefix)))
6896 ;; Loading `help-mode' here is necessary if `describe-bindings'
6897 ;; is replaced with something, e.g. `helm-descbinds'.
6898 (require 'help-mode)
6899 (with-current-buffer (let (help-xref-following) (help-buffer))
6900 (setq help-xref-stack-item item)))))
6901
6902 (defun gnus-article-reply-with-original (&optional wide)
6903 "Start composing a reply mail to the current message.
6904 The text in the region will be yanked. If the region isn't active,
6905 the entire article will be yanked."
6906 (interactive)
6907 (let ((article (cdr gnus-article-current))
6908 contents)
6909 (if (not (and transient-mark-mode mark-active))
6910 (with-current-buffer gnus-summary-buffer
6911 (gnus-summary-reply (list (list article)) wide))
6912 (setq contents (buffer-substring (point) (mark t)))
6913 ;; Deactivate active regions.
6914 (when transient-mark-mode
6915 (setq mark-active nil))
6916 (with-current-buffer gnus-summary-buffer
6917 (gnus-summary-reply
6918 (list (list article contents)) wide)))))
6919
6920 (defun gnus-article-wide-reply-with-original ()
6921 "Start composing a wide reply mail to the current message.
6922 The text in the region will be yanked. If the region isn't active,
6923 the entire article will be yanked."
6924 (interactive)
6925 (gnus-article-reply-with-original t))
6926
6927 (defun gnus-article-followup-with-original ()
6928 "Compose a followup to the current article.
6929 The text in the region will be yanked. If the region isn't active,
6930 the entire article will be yanked."
6931 (interactive)
6932 (let ((article (cdr gnus-article-current))
6933 contents)
6934 (if (not (and transient-mark-mode mark-active))
6935 (with-current-buffer gnus-summary-buffer
6936 (gnus-summary-followup (list (list article))))
6937 (setq contents (buffer-substring (point) (mark t)))
6938 ;; Deactivate active regions.
6939 (when transient-mark-mode
6940 (setq mark-active nil))
6941 (with-current-buffer gnus-summary-buffer
6942 (gnus-summary-followup
6943 (list (list article contents)))))))
6944
6945 (defun gnus-article-hide (&optional arg force)
6946 "Hide all the gruft in the current article.
6947 This means that signatures, cited text and (some) headers will be
6948 hidden.
6949 If given a prefix, show the hidden text instead."
6950 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6951 (gnus-with-article-buffer
6952 (article-hide-headers arg)
6953 (article-hide-list-identifiers)
6954 (gnus-article-hide-citation-maybe arg force)
6955 (article-hide-signature arg)))
6956
6957 (defun gnus-check-group-server ()
6958 ;; Make sure the connection to the server is alive.
6959 (unless (gnus-server-opened
6960 (gnus-find-method-for-group gnus-newsgroup-name))
6961 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6962 (gnus-request-group gnus-newsgroup-name t)))
6963
6964 (declare-function nneething-get-file-name "nneething" (id))
6965
6966 (defun gnus-request-article-this-buffer (article group)
6967 "Get an article and insert it into this buffer."
6968 (let (do-update-line sparse-header)
6969 (prog1
6970 (save-excursion
6971 (erase-buffer)
6972 (gnus-kill-all-overlays)
6973 (setq group (or group gnus-newsgroup-name))
6974
6975 ;; Using `gnus-request-article' directly will insert the article into
6976 ;; `nntp-server-buffer' - so we'll save some time by not having to
6977 ;; copy it from the server buffer into the article buffer.
6978
6979 ;; We only request an article by message-id when we do not have the
6980 ;; headers for it, so we'll have to get those.
6981 (when (stringp article)
6982 (gnus-read-header article))
6983
6984 ;; If the article number is negative, that means that this article
6985 ;; doesn't belong in this newsgroup (possibly), so we find its
6986 ;; message-id and request it by id instead of number.
6987 (when (and (numberp article)
6988 gnus-summary-buffer
6989 (get-buffer gnus-summary-buffer)
6990 (gnus-buffer-exists-p gnus-summary-buffer))
6991 (with-current-buffer gnus-summary-buffer
6992 (let ((header (gnus-summary-article-header article)))
6993 (when (< article 0)
6994 (cond
6995 ((memq article gnus-newsgroup-sparse)
6996 ;; This is a sparse gap article.
6997 (setq do-update-line article)
6998 (setq article (mail-header-id header))
6999 (setq sparse-header (gnus-read-header article))
7000 (setq gnus-newsgroup-sparse
7001 (delq article gnus-newsgroup-sparse)))
7002 ((vectorp header)
7003 ;; It's a real article.
7004 (setq article (mail-header-id header)))
7005 (t
7006 ;; It is an extracted pseudo-article.
7007 (setq article 'pseudo)
7008 (gnus-request-pseudo-article header))))
7009
7010 (let ((method (gnus-find-method-for-group
7011 gnus-newsgroup-name)))
7012 (when (and (eq (car method) 'nneething)
7013 (vectorp header))
7014 (let ((dir (nneething-get-file-name
7015 (mail-header-id header))))
7016 (when (and (stringp dir)
7017 (file-directory-p dir))
7018 (setq article 'nneething)
7019 (gnus-group-enter-directory dir))))))))
7020
7021 (cond
7022 ;; Refuse to select canceled articles.
7023 ((and (numberp article)
7024 gnus-summary-buffer
7025 (get-buffer gnus-summary-buffer)
7026 (gnus-buffer-exists-p gnus-summary-buffer)
7027 (eq (cdr (with-current-buffer gnus-summary-buffer
7028 (assq article gnus-newsgroup-reads)))
7029 gnus-canceled-mark))
7030 nil)
7031 ;; We first check `gnus-original-article-buffer'.
7032 ((and (get-buffer gnus-original-article-buffer)
7033 (numberp article)
7034 (with-current-buffer gnus-original-article-buffer
7035 (and (equal (car gnus-original-article) group)
7036 (eq (cdr gnus-original-article) article))))
7037 ;; `insert-buffer-substring' would incorrectly use the
7038 ;; equivalent of string-make-multibyte which amount to decoding
7039 ;; with locale-coding-system, causing failure of
7040 ;; subsequent decoding.
7041 (insert (string-to-multibyte
7042 (with-current-buffer gnus-original-article-buffer
7043 (buffer-substring (point-min) (point-max)))))
7044 'article)
7045 ;; Check the backlog.
7046 ((and gnus-keep-backlog
7047 (gnus-backlog-request-article group article (current-buffer)))
7048 'article)
7049 ;; Check asynchronous pre-fetch.
7050 ((gnus-async-request-fetched-article group article (current-buffer))
7051 (gnus-async-prefetch-next group article gnus-summary-buffer)
7052 (when (and (numberp article) gnus-keep-backlog)
7053 (gnus-backlog-enter-article group article (current-buffer)))
7054 'article)
7055 ;; Check the cache.
7056 ((and gnus-use-cache
7057 (numberp article)
7058 (gnus-cache-request-article article group))
7059 'article)
7060 ;; Check the agent cache.
7061 ((gnus-agent-request-article article group)
7062 'article)
7063 ;; Get the article and put into the article buffer.
7064 ((or (stringp article)
7065 (numberp article))
7066 (let ((gnus-override-method gnus-override-method)
7067 (methods (and (stringp article)
7068 (with-current-buffer gnus-summary-buffer
7069 (gnus-refer-article-methods))))
7070 (backend (car (gnus-find-method-for-group
7071 gnus-newsgroup-name)))
7072 result
7073 (inhibit-read-only t))
7074 (when (and (null gnus-override-method)
7075 methods)
7076 (setq gnus-override-method (pop methods)))
7077 (while (not result)
7078 (erase-buffer)
7079 (gnus-kill-all-overlays)
7080 (let ((gnus-newsgroup-name group))
7081 (gnus-check-group-server))
7082 (cond
7083 ((gnus-request-article article group (current-buffer))
7084 (when (numberp article)
7085 (gnus-async-prefetch-next group article
7086 gnus-summary-buffer)
7087 (when gnus-keep-backlog
7088 (gnus-backlog-enter-article
7089 group article (current-buffer)))
7090 (when (and gnus-agent
7091 (gnus-agent-group-covered-p group))
7092 (gnus-agent-store-article article group)))
7093 (setq result 'article))
7094 (methods
7095 (setq gnus-override-method (pop methods)))
7096 ((not (string-match "^400 "
7097 (nnheader-get-report backend)))
7098 ;; If we get 400 server disconnect, reconnect and
7099 ;; retry; otherwise, assume the article has expired.
7100 (setq result 'done))))
7101 (and (eq result 'article) 'article)))
7102 ;; It was a pseudo.
7103 (t article)))
7104
7105 ;; Associate this article with the current summary buffer.
7106 (setq gnus-article-current-summary gnus-summary-buffer)
7107
7108 ;; Take the article from the original article buffer
7109 ;; and place it in the buffer it's supposed to be in.
7110 (when (and (get-buffer gnus-article-buffer)
7111 (equal (buffer-name (current-buffer))
7112 (buffer-name (get-buffer gnus-article-buffer))))
7113 (save-excursion
7114 (if (get-buffer gnus-original-article-buffer)
7115 (set-buffer gnus-original-article-buffer)
7116 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7117 (buffer-disable-undo)
7118 (setq major-mode 'gnus-original-article-mode)
7119 (setq buffer-read-only t))
7120 (let ((inhibit-read-only t))
7121 (erase-buffer)
7122 (insert-buffer-substring gnus-article-buffer))
7123 (setq gnus-original-article (cons group article)))
7124
7125 ;; Decode charsets.
7126 (run-hooks 'gnus-article-decode-hook)
7127 ;; Mark article as decoded or not.
7128 (setq gnus-article-decoded-p gnus-article-decode-hook))
7129
7130 ;; Update sparse articles.
7131 (when (and do-update-line
7132 (or (numberp article)
7133 (stringp article)))
7134 (let ((buf (current-buffer)))
7135 (set-buffer gnus-summary-buffer)
7136 (gnus-summary-update-article do-update-line sparse-header)
7137 (gnus-summary-goto-subject do-update-line nil t)
7138 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7139 (point))
7140 (set-buffer buf))))))
7141
7142 (defun gnus-block-private-groups (group)
7143 "Allows images in newsgroups to be shown, blocks images in all
7144 other groups."
7145 (if (or (gnus-news-group-p group)
7146 (gnus-member-of-valid 'global group))
7147 ;; Block nothing in news groups.
7148 nil
7149 ;; Block everything anywhere else.
7150 "."))
7151
7152 (defun gnus-blocked-images ()
7153 (if (functionp gnus-blocked-images)
7154 (funcall gnus-blocked-images gnus-newsgroup-name)
7155 gnus-blocked-images))
7156
7157 ;;;
7158 ;;; Article editing
7159 ;;;
7160
7161 (defcustom gnus-article-edit-mode-hook nil
7162 "Hook run in article edit mode buffers."
7163 :group 'gnus-article-various
7164 :type 'hook)
7165
7166 (defvar gnus-article-edit-done-function nil)
7167
7168 (defvar gnus-article-edit-mode-map nil)
7169
7170 ;; Should we be using derived.el for this?
7171 (unless gnus-article-edit-mode-map
7172 (setq gnus-article-edit-mode-map (make-keymap))
7173 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7174
7175 (gnus-define-keys gnus-article-edit-mode-map
7176 "\C-c?" describe-mode
7177 "\C-c\C-c" gnus-article-edit-done
7178 "\C-c\C-k" gnus-article-edit-exit
7179 "\C-c\C-f\C-t" message-goto-to
7180 "\C-c\C-f\C-o" message-goto-from
7181 "\C-c\C-f\C-b" message-goto-bcc
7182 ;;"\C-c\C-f\C-w" message-goto-fcc
7183 "\C-c\C-f\C-c" message-goto-cc
7184 "\C-c\C-f\C-s" message-goto-subject
7185 "\C-c\C-f\C-r" message-goto-reply-to
7186 "\C-c\C-f\C-n" message-goto-newsgroups
7187 "\C-c\C-f\C-d" message-goto-distribution
7188 "\C-c\C-f\C-f" message-goto-followup-to
7189 "\C-c\C-f\C-m" message-goto-mail-followup-to
7190 "\C-c\C-f\C-k" message-goto-keywords
7191 "\C-c\C-f\C-u" message-goto-summary
7192 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7193 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7194 "\C-c\C-b" message-goto-body
7195 "\C-c\C-i" message-goto-signature
7196
7197 "\C-c\C-t" message-insert-to
7198 "\C-c\C-n" message-insert-newsgroups
7199 "\C-c\C-o" message-sort-headers
7200 "\C-c\C-e" message-elide-region
7201 "\C-c\C-v" message-delete-not-region
7202 "\C-c\C-z" message-kill-to-signature
7203 "\M-\r" message-newline-and-reformat
7204 "\C-c\C-a" mml-attach-file
7205 "\C-a" message-beginning-of-line
7206 "\t" message-tab
7207 "\M-;" comment-region)
7208
7209 (gnus-define-keys (gnus-article-edit-wash-map
7210 "\C-c\C-w" gnus-article-edit-mode-map)
7211 "f" gnus-article-edit-full-stops))
7212
7213 (easy-menu-define
7214 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7215 '("Field"
7216 ["Fetch To" message-insert-to t]
7217 ["Fetch Newsgroups" message-insert-newsgroups t]
7218 "----"
7219 ["To" message-goto-to t]
7220 ["From" message-goto-from t]
7221 ["Subject" message-goto-subject t]
7222 ["Cc" message-goto-cc t]
7223 ["Reply-To" message-goto-reply-to t]
7224 ["Summary" message-goto-summary t]
7225 ["Keywords" message-goto-keywords t]
7226 ["Newsgroups" message-goto-newsgroups t]
7227 ["Followup-To" message-goto-followup-to t]
7228 ["Mail-Followup-To" message-goto-mail-followup-to t]
7229 ["Distribution" message-goto-distribution t]
7230 ["Body" message-goto-body t]
7231 ["Signature" message-goto-signature t]))
7232
7233 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7234 "Major mode for editing articles.
7235 This is an extended text-mode.
7236
7237 \\{gnus-article-edit-mode-map}"
7238 (make-local-variable 'gnus-article-edit-done-function)
7239 (make-local-variable 'gnus-prev-winconf)
7240 (set (make-local-variable 'font-lock-defaults)
7241 '(message-font-lock-keywords t))
7242 (set (make-local-variable 'mail-header-separator) "")
7243 (set (make-local-variable 'gnus-article-edit-mode) t)
7244 (easy-menu-add message-mode-field-menu message-mode-map)
7245 (mml-mode)
7246 (setq buffer-read-only nil)
7247 (buffer-enable-undo)
7248 (widen))
7249
7250 (defun gnus-article-edit (&optional force)
7251 "Edit the current article.
7252 This will have permanent effect only in mail groups.
7253 If FORCE is non-nil, allow editing of articles even in read-only
7254 groups."
7255 (interactive "P")
7256 (when (and (not force)
7257 (gnus-group-read-only-p))
7258 (error "The current newsgroup does not support article editing"))
7259 (gnus-with-article-buffer
7260 (article-date-original))
7261 (gnus-article-edit-article
7262 'ignore
7263 `(lambda (no-highlight)
7264 'ignore
7265 (gnus-summary-edit-article-done
7266 ,(or (mail-header-references gnus-current-headers) "")
7267 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7268
7269 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7270 "Start editing the contents of the current article buffer."
7271 (let ((winconf (current-window-configuration)))
7272 (set-buffer gnus-article-buffer)
7273 (let ((message-auto-save-directory
7274 ;; Don't associate the article buffer with a draft file.
7275 nil))
7276 (gnus-article-edit-mode))
7277 (funcall start-func)
7278 (set-buffer-modified-p nil)
7279 (gnus-configure-windows 'edit-article)
7280 (setq gnus-article-edit-done-function exit-func)
7281 (setq gnus-prev-winconf winconf)
7282 (unless quiet
7283 (gnus-message 6 "C-c C-c to end edits"))))
7284
7285 (defun gnus-article-edit-done (&optional arg)
7286 "Update the article edits and exit."
7287 (interactive "P")
7288 (let ((func gnus-article-edit-done-function)
7289 (buf (current-buffer))
7290 (start (window-start))
7291 (winconf gnus-prev-winconf))
7292 (widen) ;; Widen it in case that users narrowed the buffer.
7293 (funcall func arg)
7294 (set-buffer buf)
7295 ;; The cache and backlog have to be flushed somewhat.
7296 (when gnus-keep-backlog
7297 (gnus-backlog-remove-article
7298 (car gnus-article-current) (cdr gnus-article-current)))
7299 ;; Flush original article as well.
7300 (gnus-flush-original-article-buffer)
7301 (when gnus-use-cache
7302 (gnus-cache-update-article
7303 (car gnus-article-current) (cdr gnus-article-current)))
7304 ;; We remove all text props from the article buffer.
7305 (kill-all-local-variables)
7306 (set-text-properties (point-min) (point-max) nil)
7307 (gnus-article-mode)
7308 (set-window-configuration winconf)
7309 (set-buffer buf)
7310 (set-window-start (get-buffer-window buf) start)
7311 (set-window-point (get-buffer-window buf) (point)))
7312 (gnus-summary-show-article))
7313
7314 (defun gnus-flush-original-article-buffer ()
7315 (when (get-buffer gnus-original-article-buffer)
7316 (with-current-buffer gnus-original-article-buffer
7317 (setq gnus-original-article nil))))
7318
7319 (defun gnus-article-edit-exit ()
7320 "Exit the article editing without updating."
7321 (interactive)
7322 (when (or (not (buffer-modified-p))
7323 (yes-or-no-p "Article modified; kill anyway? "))
7324 (let ((curbuf (current-buffer))
7325 (p (point))
7326 (window-start (window-start)))
7327 (erase-buffer)
7328 (if (gnus-buffer-live-p gnus-original-article-buffer)
7329 (insert-buffer-substring gnus-original-article-buffer))
7330 (let ((winconf gnus-prev-winconf))
7331 (kill-all-local-variables)
7332 (gnus-article-mode)
7333 (set-window-configuration winconf)
7334 ;; Tippy-toe some to make sure that point remains where it was.
7335 (save-current-buffer
7336 (set-buffer curbuf)
7337 (set-window-start (get-buffer-window (current-buffer)) window-start)
7338 (goto-char p))))
7339 (gnus-summary-show-article)))
7340
7341 (defun gnus-article-edit-full-stops ()
7342 "Interactively repair spacing at end of sentences."
7343 (interactive)
7344 (save-excursion
7345 (goto-char (point-min))
7346 (search-forward-regexp "^$" nil t)
7347 (let ((case-fold-search nil))
7348 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7349
7350 ;;;
7351 ;;; Article highlights
7352 ;;;
7353
7354 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7355
7356 ;;; Internal Variables:
7357
7358 (defcustom gnus-button-url-regexp
7359 (concat
7360 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7361 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7362 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7363 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7364 (punct "!?:;.,"))
7365 (concat
7366 "\\(?:"
7367 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7368 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7369 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7370 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7371 "\\|"
7372 "[" chars punct "]+" "[" chars "]"
7373 "\\)"))
7374 "\\)")
7375 "Regular expression that matches URLs."
7376 :version "24.4"
7377 :group 'gnus-article-buttons
7378 :type 'regexp)
7379
7380 (defcustom gnus-button-valid-fqdn-regexp "\\([-A-Za-z0-9]+\\.\\)+[A-Za-z]+"
7381 "Regular expression that matches a valid FQDN."
7382 :version "25.2"
7383 :group 'gnus-article-buttons
7384 :type 'regexp)
7385
7386 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7387 (defcustom gnus-button-valid-localpart-regexp
7388 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7389 "Regular expression that matches a localpart of mail addresses or MIDs."
7390 :version "22.1"
7391 :group 'gnus-article-buttons
7392 :type 'regexp)
7393
7394 (defcustom gnus-button-man-handler 'manual-entry
7395 "Function to use for displaying man pages.
7396 The function must take at least one argument with a string naming the
7397 man page."
7398 :version "22.1"
7399 :type '(choice (function-item :tag "Man" manual-entry)
7400 (function-item :tag "Woman" woman)
7401 (function :tag "Other"))
7402 :group 'gnus-article-buttons)
7403
7404 (defcustom gnus-button-mid-or-mail-regexp
7405 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7406 gnus-button-valid-fqdn-regexp
7407 ">?\\)\\b")
7408 "Regular expression that matches a message ID or a mail address."
7409 :version "22.1"
7410 :group 'gnus-article-buttons
7411 :type 'regexp)
7412
7413 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7414 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7415 Strings like this can be either a message ID or a mail address. If it is one
7416 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7417 message ID or a mail address, respectively. If this variable is set to the
7418 symbol `ask', always query the user what do do. If it is a function, this
7419 function will be called with the string as its only argument. The function
7420 must return `mid', `mail', `invalid' or `ask'."
7421 :version "22.1"
7422 :group 'gnus-article-buttons
7423 :type '(choice (function-item :tag "Heuristic function"
7424 gnus-button-mid-or-mail-heuristic)
7425 (const ask)
7426 (const mid)
7427 (const mail)))
7428
7429 (defcustom gnus-button-mid-or-mail-heuristic-alist
7430 '((-10.0 . ".+\\$.+@")
7431 (-10.0 . "#")
7432 (-10.0 . "\\*")
7433 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7434 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7435 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7436 (-1.0 . "^[^a-z]+@")
7437 ;;
7438 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7439 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7440 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7441 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7442 ;;
7443 (-2.0 . "^[0-9]")
7444 (-1.0 . "^[0-9][0-9]")
7445 ;;
7446 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7447 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7448 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7449 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7450 ;;
7451 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7452 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7453 ;; "[0-9]{8,}.*\@"
7454 (-3.0
7455 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7456 ;; "[0-9]{12,}.*\@"
7457 ;; compensation for TDMA dated mail addresses:
7458 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7459 ;;
7460 (-20.0 . "\\.fsf@") ;; Gnus
7461 (-20.0 . "^slrn")
7462 (-20.0 . "^Pine")
7463 (-20.0 . "^alpine\\.")
7464 (-20.0 . "_-_") ;; Subject change in thread
7465 ;;
7466 (-20.0 . "\\.ln@") ;; leafnode
7467 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7468 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7469 ;;
7470 ;; (5.0 . "") ;; $local_part_len <= 7
7471 (10.0 . "^[^0-9]+@")
7472 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7473 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7474 (3.0 . "@stud")
7475 ;;
7476 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7477 ;;
7478 (0.5 . "^[A-Z][a-z]")
7479 (0.5 . "^[A-Z][a-z][a-z]")
7480 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7481 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7482 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7483
7484 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7485 address. The REGEXP is processed with `case-fold-search' set to nil."
7486 :version "22.1"
7487 :group 'gnus-article-buttons
7488 :type '(repeat (cons (number :tag "Rate")
7489 (regexp :tag "Regexp"))))
7490
7491 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7492 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7493 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7494 address, `ask' if unsure and `invalid' if the string is invalid."
7495 (let ((case-fold-search nil)
7496 (list gnus-button-mid-or-mail-heuristic-alist)
7497 (result 0) rate regexp lpartlen elem)
7498 (setq lpartlen
7499 (length (replace-regexp-in-string "^\\(.*\\)@.*$" "\\1" mid-or-mail)))
7500 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7501 ;; Certain special cases...
7502 (when (string-match
7503 (concat
7504 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7505 "^[0-9]+\\.[0-9]+@compuserve\\|"
7506 "@public\\.gmane\\.org")
7507 mid-or-mail)
7508 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7509 (setq result 'mail))
7510 (when (string-match "@.*@\\| " mid-or-mail)
7511 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7512 (setq result 'invalid))
7513 ;; Nothing more to do, if result is not a number here...
7514 (when (numberp result)
7515 (while list
7516 (setq elem (car list)
7517 rate (car elem)
7518 regexp (cdr elem)
7519 list (cdr list))
7520 (when (string-match regexp mid-or-mail)
7521 (setq result (+ result rate))
7522 (gnus-message
7523 9 "`%s' matched `%s', rate `%s', result `%s'."
7524 mid-or-mail regexp rate result)))
7525 (when (<= lpartlen 7)
7526 (setq result (+ result 5.0))
7527 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7528 mid-or-mail result))
7529 (when (>= lpartlen 12)
7530 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7531 (cond
7532 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7533 ;; Long local part should contain realname if e-mail address,
7534 ;; too many digits: message-id.
7535 ;; $score -= 5.0 + 0.1 * $local_part_len;
7536 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7537 (setq result (+ result rate))
7538 (gnus-message
7539 9 "Many digits in `%s', rate `%s', result `%s'."
7540 mid-or-mail rate result))
7541 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7542 mid-or-mail)
7543 ;; Too few vowels [^aeiouy]{4,}.*@
7544 (setq result (+ result -5.0))
7545 (gnus-message
7546 9 "Few vowels in `%s', rate `%s', result `%s'."
7547 mid-or-mail -5.0 result))
7548 (t
7549 (setq result (+ result 5.0))
7550 (gnus-message
7551 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7552 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7553 ;; Maybe we should make this a customizable alist: (condition . 'result)
7554 (cond
7555 ((symbolp result) result)
7556 ;; Now convert number into proper results:
7557 ((< result -10.0) 'mid)
7558 ((> result 10.0) 'mail)
7559 (t 'ask))))
7560
7561 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7562 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7563 (url-mid (concat "news" ":" mid-or-mail))
7564 (url-mailto (concat "mailto" ":" mid-or-mail)))
7565 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7566 (when (fboundp pref)
7567 (setq guessed
7568 ;; get rid of surrounding angles...
7569 (funcall pref
7570 (replace-regexp-in-string "^<\\|>$" "" mid-or-mail)))
7571 (if (or (eq 'mid guessed) (eq 'mail guessed))
7572 (setq pref guessed)
7573 (setq pref 'ask)))
7574 (if (eq pref 'ask)
7575 (save-window-excursion
7576 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7577 (setq pref 'mail)
7578 (setq pref 'mid))))
7579 (cond ((eq pref 'mid)
7580 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7581 (gnus-button-handle-news url-mid))
7582 ((eq pref 'mail)
7583 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7584 (gnus-url-mailto url-mailto))
7585 (t (gnus-message 3 "Invalid string.")))))
7586
7587 (defun gnus-button-handle-custom (fun arg)
7588 "Call function FUN on argument ARG.
7589 Both FUN and ARG are supposed to be strings. ARG will be passed
7590 as a symbol to FUN."
7591 (funcall (intern fun)
7592 (if (string-match "^customize-apropos" fun)
7593 arg
7594 (intern arg))))
7595
7596 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7597
7598 (defun gnus-button-handle-describe-function (url)
7599 "Call `describe-function' when pushing the corresponding URL button."
7600 (describe-function
7601 (intern
7602 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7603
7604 (defun gnus-button-handle-describe-variable (url)
7605 "Call `describe-variable' when pushing the corresponding URL button."
7606 (describe-variable
7607 (intern
7608 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7609
7610 (defun gnus-button-handle-symbol (url)
7611 "Display help on variable or function.
7612 Calls `describe-variable' or `describe-function'."
7613 (let ((sym (intern url)))
7614 (cond
7615 ((fboundp sym) (describe-function sym))
7616 ((boundp sym) (describe-variable sym))
7617 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7618
7619 (defun gnus-button-handle-describe-key (url)
7620 "Call `describe-key' when pushing the corresponding URL button."
7621 (let* ((key-string
7622 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))
7623 (keys (ignore-errors (eval `(kbd ,key-string)))))
7624 (if keys
7625 (describe-key keys)
7626 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7627
7628 (defun gnus-button-handle-apropos (url)
7629 "Call `apropos' when pushing the corresponding URL button."
7630 (apropos (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7631
7632 (defun gnus-button-handle-apropos-command (url)
7633 "Call `apropos' when pushing the corresponding URL button."
7634 (apropos-command
7635 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7636
7637 (defun gnus-button-handle-apropos-variable (url)
7638 "Call `apropos' when pushing the corresponding URL button."
7639 (apropos-variable
7640 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7641
7642 (defun gnus-button-handle-apropos-documentation (url)
7643 "Call `apropos' when pushing the corresponding URL button."
7644 (apropos-documentation
7645 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7646
7647 (defun gnus-button-handle-library (url)
7648 "Call `locate-library' when pushing the corresponding URL button."
7649 (gnus-message 9 "url=`%s'" url)
7650 (let* ((lib (locate-library url))
7651 (file (replace-regexp-in-string "\\.elc" ".el" (or lib ""))))
7652 (if (not lib)
7653 (gnus-message 1 "Cannot locale library `%s'." url)
7654 (find-file-read-only file))))
7655
7656 (defcustom gnus-button-man-level 5
7657 "*Integer that says how many man-related buttons Gnus will show.
7658 The higher the number, the more buttons will appear and the more false
7659 positives are possible. Note that you can set this variable local to
7660 specific groups. Setting it higher in Unix groups is probably a good idea.
7661 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7662 how to set variables in specific groups."
7663 :version "22.1"
7664 :group 'gnus-article-buttons
7665 :link '(custom-manual "(gnus)Group Parameters")
7666 :type 'integer)
7667
7668 (defcustom gnus-button-emacs-level 5
7669 "*Integer that says how many emacs-related buttons Gnus will show.
7670 The higher the number, the more buttons will appear and the more false
7671 positives are possible. Note that you can set this variable local to
7672 specific groups. Setting it higher in Emacs or Gnus related groups is
7673 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7674 `gnus-parameters' on how to set variables in specific groups."
7675 :version "22.1"
7676 :group 'gnus-article-buttons
7677 :link '(custom-manual "(gnus)Group Parameters")
7678 :type 'integer)
7679
7680 (defcustom gnus-button-message-level 5
7681 "*Integer that says how many buttons for news or mail messages will appear.
7682 The higher the number, the more buttons will appear and the more false
7683 positives are possible."
7684 ;; mail addresses, MIDs, URLs for news, ...
7685 :version "22.1"
7686 :group 'gnus-article-buttons
7687 :type 'integer)
7688
7689 (defcustom gnus-button-browse-level 5
7690 "*Integer that says how many buttons for browsing will appear.
7691 The higher the number, the more buttons will appear and the more false
7692 positives are possible."
7693 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7694 :version "22.1"
7695 :group 'gnus-article-buttons
7696 :type 'integer)
7697
7698 (defcustom gnus-button-alist
7699 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7700 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7701 ((concat "\\b\\(nntp\\|news\\):\\("
7702 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7703 0 t gnus-button-handle-news 2)
7704 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7705 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7706 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7707 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7708 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7709 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7710 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7711 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7712 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7713 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7714 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7715 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7716 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7717 ;; RFC 2368 (The mailto URL scheme)
7718 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7719 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7720 ("\\bmailto:\\([^ \n\t]+\\)"
7721 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7722 ;; Info Konqueror style <info:/foo/bar baz>.
7723 ;; Must come before " Gnus home-grown style".
7724 ("\\binfo://?\\([^'\">\n\t]+\\)"
7725 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7726 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7727 ("\\binfo://\\([^'\">\n\t ]+\\)"
7728 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7729 ;; Info GNOME style <info:foo#bar_baz>
7730 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7731 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7732 ;; Info KDE style <info:(foo)bar baz>
7733 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7734 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7735 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7736 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7737 ("\\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,]*\\)\\)?"
7738 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7739 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7740 ;; This is custom
7741 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7742 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7743 ;; Emacs help commands
7744 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7745 ;; regexp doesn't match arguments containing ` '.
7746 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7747 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7748 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7749 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7750 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7751 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7752 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7753 ;; The following entries may lead to many false positives so don't enable
7754 ;; them by default (use a high button level).
7755 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7756 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7757 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7758 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7759 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7760 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7761 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7762 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7763 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7764 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7765 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7766 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7767 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7768 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7769 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7770 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7771 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7772 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7773 ;; Unlike the other regexps we really have to require quoting
7774 ;; here to determine where it ends.
7775 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7776 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7777 ("<URL: *\\([^\n<>]*\\)>"
7778 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7779 ;; RFC 2396 (2.4.3., delims) ...
7780 ("\"URL: *\\([^\n\"]*\\)\""
7781 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7782 ;; Raw URLs.
7783 (gnus-button-url-regexp
7784 0 (>= gnus-button-browse-level 0) browse-url 0)
7785 ;; man pages
7786 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7787 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7788 gnus-button-handle-man 1)
7789 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7790 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7791 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7792 gnus-button-handle-man 1)
7793 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7794 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7795 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7796 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7797 ;; Recognizing patches to .el files. This is somewhat obscure,
7798 ;; but considering the percentage of Gnus users who hack Emacs
7799 ;; Lisp files...
7800 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7801 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7802 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7803 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7804 ;; MID or mail: To avoid too many false positives we don't try to catch
7805 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7806 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7807 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7808 ;; so that non-ambiguous entries (see above) match first.
7809 (gnus-button-mid-or-mail-regexp
7810 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7811 "*Alist of regexps matching buttons in article bodies.
7812
7813 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7814 REGEXP: is the string (case insensitive) matching text around the button (can
7815 also be Lisp expression evaluating to a string),
7816 BUTTON: is the number of the regexp grouping actually matching the button,
7817 FORM: is a Lisp expression which must eval to true for the button to
7818 be added,
7819 CALLBACK: is the function to call when the user push this button, and each
7820 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7821
7822 CALLBACK can also be a variable, in that case the value of that
7823 variable it the real callback function."
7824 :group 'gnus-article-buttons
7825 :type '(repeat (list (choice regexp variable sexp)
7826 (integer :tag "Button")
7827 (sexp :tag "Form")
7828 (function :tag "Callback")
7829 (repeat :tag "Par"
7830 :inline t
7831 (integer :tag "Regexp group")))))
7832 (put 'gnus-button-alist 'risky-local-variable t)
7833
7834 (defcustom gnus-header-button-alist
7835 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7836 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7837 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7838 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7839 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7840 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7841 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7842 0 (>= gnus-button-browse-level 0) browse-url 0)
7843 ("^Subject:" gnus-button-url-regexp
7844 0 (>= gnus-button-browse-level 0) browse-url 0)
7845 ("^[^:]+:" gnus-button-url-regexp
7846 0 (>= gnus-button-browse-level 0) browse-url 0)
7847 ("^OpenPGP:.*url=" gnus-button-url-regexp
7848 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7849 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7850 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7851 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7852 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7853 "*Alist of headers and regexps to match buttons in article heads.
7854
7855 This alist is very similar to `gnus-button-alist', except that each
7856 alist has an additional HEADER element first in each entry:
7857
7858 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7859
7860 HEADER is a regexp to match a header. For a fuller explanation, see
7861 `gnus-button-alist'."
7862 :group 'gnus-article-buttons
7863 :group 'gnus-article-headers
7864 :type '(repeat (list (regexp :tag "Header")
7865 (choice regexp variable)
7866 (integer :tag "Button")
7867 (sexp :tag "Form")
7868 (function :tag "Callback")
7869 (repeat :tag "Par"
7870 :inline t
7871 (integer :tag "Regexp group")))))
7872 (put 'gnus-header-button-alist 'risky-local-variable t)
7873
7874 ;;; Commands:
7875
7876 (defun gnus-article-push-button (event)
7877 "Check text under the mouse pointer for a callback function.
7878 If the text under the mouse pointer has a `gnus-callback' property,
7879 call it with the value of the `gnus-data' text property."
7880 (interactive "e")
7881 (set-buffer (window-buffer (posn-window (event-start event))))
7882 (let* ((pos (posn-point (event-start event)))
7883 (data (get-text-property pos 'gnus-data))
7884 (fun (get-text-property pos 'gnus-callback)))
7885 (goto-char pos)
7886 (when fun
7887 (funcall fun data))))
7888
7889 (defun gnus-article-press-button ()
7890 "Check text at point for a callback function.
7891 If the text at point has a `gnus-callback' property,
7892 call it with the value of the `gnus-data' text property."
7893 (interactive)
7894 (let ((data (get-text-property (point) 'gnus-data))
7895 (fun (get-text-property (point) 'gnus-callback)))
7896 (when fun
7897 (funcall fun data))))
7898
7899 (defun gnus-article-highlight (&optional force)
7900 "Highlight current article.
7901 This function calls `gnus-article-highlight-headers',
7902 `gnus-article-highlight-citation',
7903 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7904 do the highlighting. See the documentation for those functions."
7905 (interactive (list 'force))
7906 (gnus-article-highlight-headers)
7907 (gnus-article-highlight-citation force)
7908 (gnus-article-highlight-signature)
7909 (gnus-article-add-buttons)
7910 (gnus-article-add-buttons-to-head))
7911
7912 (defun gnus-article-highlight-some (&optional _force)
7913 "Highlight current article.
7914 This function calls `gnus-article-highlight-headers',
7915 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7916 do the highlighting. See the documentation for those functions."
7917 (interactive (list 'force))
7918 (gnus-article-highlight-headers)
7919 (gnus-article-highlight-signature)
7920 (gnus-article-add-buttons))
7921
7922 (defun gnus-article-highlight-headers ()
7923 "Highlight article headers as specified by `gnus-header-face-alist'."
7924 (interactive)
7925 (gnus-with-article-headers
7926 (let (regexp header-face field-face from hpoints fpoints)
7927 (dolist (entry gnus-header-face-alist)
7928 (goto-char (point-min))
7929 (setq regexp (concat "^\\("
7930 (if (string-equal "" (nth 0 entry))
7931 "[^\t ]"
7932 (nth 0 entry))
7933 "\\)")
7934 header-face (nth 1 entry)
7935 field-face (nth 2 entry))
7936 (while (and (re-search-forward regexp nil t)
7937 (not (eobp)))
7938 (beginning-of-line)
7939 (setq from (point))
7940 (unless (search-forward ":" nil t)
7941 (forward-char 1))
7942 (when (and header-face
7943 (not (memq (point) hpoints)))
7944 (push (point) hpoints)
7945 (put-text-property from (point) 'face header-face))
7946 (when (and field-face
7947 (not (memq (setq from (point)) fpoints)))
7948 (push from fpoints)
7949 (if (re-search-forward "^[^ \t]" nil t)
7950 (forward-char -2)
7951 (goto-char (point-max)))
7952 (put-text-property from (point) 'face field-face)))))))
7953
7954 (defun gnus-article-highlight-signature ()
7955 "Highlight the signature in an article.
7956 It does this by highlighting everything after
7957 `gnus-signature-separator' using the face `gnus-signature'."
7958 (interactive)
7959 (gnus-with-article-buffer
7960 (let ((inhibit-point-motion-hooks t))
7961 (save-restriction
7962 (when (and gnus-signature-face
7963 (gnus-article-narrow-to-signature))
7964 (overlay-put (make-overlay (point-min) (point-max) nil t)
7965 'face gnus-signature-face)
7966 (widen)
7967 (gnus-article-search-signature)
7968 (let ((start (match-beginning 0))
7969 (end (set-marker (make-marker) (1+ (match-end 0)))))
7970 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7971 end)))))))
7972
7973 (defun gnus-button-in-region-p (b e prop)
7974 "Say whether PROP exists in the region."
7975 (text-property-not-all b e prop nil))
7976
7977 (defun gnus-article-add-buttons ()
7978 "Find external references in the article and make buttons of them.
7979 \"External references\" are things like Message-IDs and URLs, as
7980 specified by `gnus-button-alist'."
7981 (interactive)
7982 (gnus-with-article-buffer
7983 (let ((inhibit-point-motion-hooks t)
7984 (case-fold-search t)
7985 (alist gnus-button-alist)
7986 beg entry regexp)
7987 ;; We skip the headers.
7988 (article-goto-body)
7989 (setq beg (point))
7990 (while (setq entry (pop alist))
7991 (setq regexp (eval (car entry)))
7992 (goto-char beg)
7993 (while (re-search-forward regexp nil t)
7994 (let ((start (match-beginning (nth 1 entry)))
7995 (end (match-end (nth 1 entry)))
7996 (from (match-beginning 0)))
7997 (when (and (eval (nth 2 entry))
7998 (not (gnus-button-in-region-p
7999 start end 'gnus-callback)))
8000 ;; That optional form returned non-nil, so we add the
8001 ;; button.
8002 (setq from (set-marker (make-marker) from))
8003 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8004 (gnus-article-extend-url-button from start end))
8005 (gnus-article-add-button start end
8006 'gnus-button-push (list from entry))
8007 (put-text-property
8008 start end
8009 'gnus-string (buffer-substring-no-properties
8010 start end))))))))))
8011
8012 (defun gnus-article-extend-url-button (beg start end)
8013 "Extend url button if url is folded into two or more lines.
8014 Return non-nil if button is extended. BEG is a marker that points to
8015 the beginning position of a text containing url. START and END are
8016 the endpoints of a url button before it is extended. The concatenated
8017 url is put as the `gnus-button-url' overlay property on the button."
8018 (let ((opoint (point))
8019 (points (list start end))
8020 url delim regexp)
8021 (prog1
8022 (when (and (progn
8023 (goto-char end)
8024 (not (looking-at "[\t ]*[\">]")))
8025 (progn
8026 (goto-char start)
8027 (string-match
8028 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8029 (buffer-substring (point-at-bol) start)))
8030 (progn
8031 (setq url (list (buffer-substring start end))
8032 delim (if (match-beginning 1) ">" "\""))
8033 (beginning-of-line)
8034 (setq regexp (concat
8035 (when (and (looking-at
8036 message-cite-prefix-regexp)
8037 (< (match-end 0) start))
8038 (regexp-quote (match-string 0)))
8039 "\
8040 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8041 delim "\\)"))
8042 (while (progn
8043 (forward-line 1)
8044 (and (looking-at regexp)
8045 (prog1
8046 (match-beginning 1)
8047 (push (or (match-string 2)
8048 (match-string 1))
8049 url)
8050 (push (setq end (or (match-end 2)
8051 (match-end 1)))
8052 points)
8053 (push (or (match-beginning 2)
8054 (match-beginning 1))
8055 points)))))
8056 (match-beginning 2)))
8057 (let (gnus-article-mouse-face widget-mouse-face)
8058 (while points
8059 (gnus-article-add-button (pop points) (pop points)
8060 'gnus-button-push
8061 (list beg (assq 'gnus-button-url-regexp
8062 gnus-button-alist)))))
8063 (let ((overlay (make-overlay start end)))
8064 (overlay-put overlay 'evaporate t)
8065 (overlay-put overlay 'gnus-button-url
8066 (list (mapconcat 'identity (nreverse url) "")))
8067 (when gnus-article-mouse-face
8068 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8069 t)
8070 (goto-char opoint))))
8071
8072 ;; Add buttons to the head of an article.
8073 (defun gnus-article-add-buttons-to-head ()
8074 "Add buttons to the head of the article."
8075 (interactive)
8076 (gnus-with-article-headers
8077 (let (beg end)
8078 (dolist (entry gnus-header-button-alist)
8079 ;; Each alist entry.
8080 (goto-char (point-min))
8081 (while (re-search-forward (car entry) nil t)
8082 ;; Each header matching the entry.
8083 (setq beg (match-beginning 0))
8084 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8085 (match-beginning 0))
8086 (point-max)))
8087 (goto-char beg)
8088 (while (re-search-forward (eval (nth 1 entry)) end t)
8089 ;; Each match within a header.
8090 (let* ((entry (cdr entry))
8091 (start (match-beginning (nth 1 entry)))
8092 (end (match-end (nth 1 entry)))
8093 (form (nth 2 entry)))
8094 (goto-char (match-end 0))
8095 (when (eval form)
8096 (gnus-article-add-button
8097 start end (nth 3 entry)
8098 (buffer-substring (match-beginning (nth 4 entry))
8099 (match-end (nth 4 entry)))))))
8100 (goto-char end))))))
8101
8102 ;;; External functions:
8103
8104 (defun gnus-article-add-button (from to fun &optional data text)
8105 "Create a button between FROM and TO with callback FUN and data DATA."
8106 (when gnus-article-button-face
8107 (overlay-put (make-overlay from to nil t)
8108 'face gnus-article-button-face))
8109 (add-text-properties
8110 from to
8111 (nconc (and gnus-article-mouse-face
8112 (list 'mouse-face gnus-article-mouse-face))
8113 (list 'gnus-callback fun)
8114 (and data (list 'gnus-data data))))
8115 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8116 :help-echo (or text "Follow the link")
8117 :keymap gnus-url-button-map))
8118
8119 (defun gnus-article-copy-string ()
8120 "Copy the string in the button to the kill ring."
8121 (interactive)
8122 (gnus-article-check-buffer)
8123 (let ((data (get-text-property (point) 'gnus-string)))
8124 (when data
8125 (with-temp-buffer
8126 (insert data)
8127 (copy-region-as-kill (point-min) (point-max))
8128 (message "Copied %s" data)))))
8129
8130 ;;; Internal functions:
8131
8132 (defun gnus-article-set-globals ()
8133 (with-current-buffer gnus-summary-buffer
8134 (gnus-set-global-variables)))
8135
8136 (defun gnus-signature-toggle (end)
8137 (gnus-with-article-buffer
8138 (let ((inhibit-point-motion-hooks t))
8139 (if (text-property-any end (point-max) 'article-type 'signature)
8140 (progn
8141 (gnus-delete-wash-type 'signature)
8142 (gnus-remove-text-properties-when
8143 'article-type 'signature end (point-max)
8144 (cons 'article-type (cons 'signature
8145 gnus-hidden-properties))))
8146 (gnus-add-wash-type 'signature)
8147 (gnus-add-text-properties-when
8148 'article-type nil end (point-max)
8149 (cons 'article-type (cons 'signature
8150 gnus-hidden-properties)))))
8151 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8152 (gnus-set-mode-line 'article))))
8153
8154 (defun gnus-button-push (marker-and-entry)
8155 ;; Push button starting at MARKER.
8156 (save-excursion
8157 (let* ((marker (car marker-and-entry))
8158 (entry (cadr marker-and-entry))
8159 (regexp (car entry))
8160 (inhibit-point-motion-hooks t))
8161 (goto-char marker)
8162 ;; This is obviously true, or something bad is happening :)
8163 ;; But we need it to have the match-data
8164 (when (looking-at (or (if (symbolp regexp)
8165 (symbol-value regexp)
8166 regexp)))
8167 (let ((fun (nth 3 entry))
8168 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8169 (get-char-property marker 'gnus-button-url))
8170 (mapcar (lambda (group)
8171 (let ((string (match-string group)))
8172 (set-text-properties
8173 0 (length string) nil string)
8174 string))
8175 (nthcdr 4 entry)))))
8176
8177 (cond
8178 ((fboundp fun)
8179 (apply fun args))
8180 ((and (boundp fun)
8181 (fboundp (symbol-value fun)))
8182 (apply (symbol-value fun) args))
8183 (t
8184 (gnus-message 1 "You must define `%S' to use this button"
8185 (cons fun args)))))))))
8186
8187 (defun gnus-parse-news-url (url)
8188 (let (scheme server port group message-id articles)
8189 (with-temp-buffer
8190 (insert url)
8191 (goto-char (point-min))
8192 (when (looking-at "\\([A-Za-z]+\\):")
8193 (setq scheme (match-string 1))
8194 (goto-char (match-end 0)))
8195 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8196 (setq server (match-string 1))
8197 (setq port (if (stringp (match-string 3))
8198 (string-to-number (match-string 3))
8199 (match-string 3)))
8200 (goto-char (match-end 0)))
8201
8202 (cond
8203 ((looking-at "\\(.*@.*\\)")
8204 (setq message-id (match-string 1)))
8205 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8206 (setq group (match-string 1)
8207 articles (split-string (match-string 2) "-")))
8208 ((looking-at "\\([^/]+\\)/?")
8209 (setq group (match-string 1)))
8210 (t
8211 (error "Unknown news URL syntax"))))
8212 (list scheme server port group message-id articles)))
8213
8214 (defvar nntp-port-number)
8215
8216 (defun gnus-button-handle-news (url)
8217 "Fetch a news URL."
8218 (destructuring-bind (_scheme server port group message-id _articles)
8219 (gnus-parse-news-url url)
8220 (cond
8221 (message-id
8222 (with-current-buffer gnus-summary-buffer
8223 (if server
8224 (let ((gnus-refer-article-method
8225 (nconc (list (list 'nntp server))
8226 gnus-refer-article-method))
8227 (nntp-port-number (or port "nntp")))
8228 (gnus-message 7 "Fetching %s with %s"
8229 message-id gnus-refer-article-method)
8230 (gnus-summary-refer-article message-id))
8231 (gnus-summary-refer-article message-id))))
8232 (group
8233 (gnus-button-fetch-group url)))))
8234
8235 (defun gnus-button-patch (library line)
8236 "Visit an Emacs Lisp library LIBRARY on line LINE."
8237 (interactive)
8238 (let ((file (locate-library (file-name-nondirectory library))))
8239 (unless file
8240 (error "Couldn't find library %s" library))
8241 (find-file file)
8242 (goto-char (point-min))
8243 (forward-line (1- (string-to-number line)))))
8244
8245 (defun gnus-button-handle-man (url)
8246 "Fetch a man page."
8247 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8248 (when (eq gnus-button-man-handler 'woman)
8249 (setq url (replace-regexp-in-string "([1-9][X1a-z]*).*\\'" "" url)))
8250 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8251 (funcall gnus-button-man-handler url))
8252
8253 (defun gnus-button-handle-info-url (url)
8254 "Fetch an info URL."
8255 (setq url (subst-char-in-string ?+ ?\ url))
8256 (cond
8257 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8258 (gnus-info-find-node
8259 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8260 "Gnus")
8261 ")" (gnus-url-unhex-string (match-string 2 url)))))
8262 ((string-match "([^)\"]+)[^\"]+" url)
8263 (setq url
8264 (replace-regexp-in-string
8265 "\"" "" (replace-regexp-in-string "[\n\t ]+" " " url)))
8266 (gnus-info-find-node url))
8267 (t (error "Can't parse %s" url))))
8268
8269 (defun gnus-button-handle-info-url-gnome (url)
8270 "Fetch GNOME style info URL."
8271 (setq url (subst-char-in-string ?_ ?\ url))
8272 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8273 (gnus-info-find-node
8274 (concat "("
8275 (gnus-url-unhex-string
8276 (match-string 1 url))
8277 ")"
8278 (or (gnus-url-unhex-string
8279 (match-string 2 url))
8280 "Top")))
8281 (error "Can't parse %s" url)))
8282
8283 (defun gnus-button-handle-info-url-kde (url)
8284 "Fetch KDE style info URL."
8285 (gnus-info-find-node (gnus-url-unhex-string url)))
8286
8287 ;; (info) will autoload info.el
8288 (declare-function Info-menu "info" (menu-item &optional fork))
8289 (declare-function Info-index-next "info" (num))
8290
8291 (defun gnus-button-handle-info-keystrokes (url)
8292 "Call `info' when pushing the corresponding URL button."
8293 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8294 (let (node indx comma)
8295 (if (string-match
8296 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8297 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8298 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8299 "\\(?:[ \t\n,]*\\)\\)?")
8300 url)
8301 (setq node (match-string 2 url)
8302 indx (match-string 3 url))
8303 (error "Can't parse %s" url))
8304 (info)
8305 (Info-directory)
8306 (Info-menu node)
8307 (when (> (length indx) 0)
8308 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8309 "\\([ \t\n,]*\\)")
8310 indx)
8311 (setq comma (match-string 2 indx))
8312 (setq indx (match-string 1 indx))
8313 (Info-index indx)
8314 (when comma
8315 (dotimes (i (with-temp-buffer
8316 (insert comma)
8317 ;; Note: the XEmacs version of `how-many' takes
8318 ;; no optional argument.
8319 (goto-char (point-min))
8320 (how-many ",")))
8321 (Info-index-next 1)))
8322 nil)))
8323
8324 (autoload 'pgg-snarf-keys-region "pgg")
8325 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8326 (declare-function pgg-display-output-buffer "pgg" (start end status))
8327
8328 (defun gnus-button-openpgp (url)
8329 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8330 (with-temp-buffer
8331 (mm-url-insert-file-contents-external url)
8332 (pgg-snarf-keys-region (point-min) (point-max))
8333 (pgg-display-output-buffer nil nil nil)))
8334
8335 (defun gnus-button-message-id (message-id)
8336 "Fetch MESSAGE-ID."
8337 (with-current-buffer gnus-summary-buffer
8338 (gnus-summary-refer-article message-id)))
8339
8340 (defun gnus-button-fetch-group (address &rest _ignore)
8341 "Fetch GROUP specified by ADDRESS."
8342 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8343 address)
8344 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8345 ;; for nntp:// and news://
8346 (setq address (match-string 3 address)))
8347 (if (not (string-match "[:/]" address))
8348 ;; This is just a simple group url.
8349 (gnus-group-read-ephemeral-group address gnus-select-method)
8350 (if (not
8351 (string-match
8352 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8353 address))
8354 (error "Can't parse %s" address)
8355 (gnus-group-read-ephemeral-group
8356 (match-string 4 address)
8357 `(nntp ,(match-string 1 address)
8358 (nntp-address ,(match-string 1 address))
8359 (nntp-port-number ,(if (match-end 3)
8360 (match-string 3 address)
8361 "nntp")))
8362 nil nil nil
8363 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8364
8365 (defun gnus-url-parse-query-string (query &optional downcase)
8366 (let (retval pairs cur key val)
8367 (setq pairs (split-string query "&"))
8368 (while pairs
8369 (setq cur (car pairs)
8370 pairs (cdr pairs))
8371 (if (not (string-match "=" cur))
8372 nil ; Grace
8373 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8374 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8375 (if downcase
8376 (setq key (downcase key)))
8377 (setq cur (assoc key retval))
8378 (if cur
8379 (setcdr cur (cons val (cdr cur)))
8380 (setq retval (cons (list key val) retval)))))
8381 retval))
8382
8383 (defun gnus-url-mailto (url)
8384 ;; Send mail to someone
8385 (setq url (replace-regexp-in-string "\n" " " url))
8386 (when (string-match "mailto:/*\\(.*\\)" url)
8387 (setq url (substring url (match-beginning 1) nil)))
8388 (let* ((args (gnus-url-parse-query-string
8389 (if (string-match "^\\?" url)
8390 (substring url 1)
8391 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8392 (concat "to=" (match-string 1 url) "&"
8393 (match-string 2 url))
8394 (concat "to=" url)))))
8395 (subject (cdr-safe (assoc "subject" args)))
8396 func)
8397 (gnus-msg-mail)
8398 (while args
8399 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8400 (if (fboundp func)
8401 (funcall func)
8402 (message-position-on-field (caar args)))
8403 (insert (replace-regexp-in-string
8404 "\r\n" "\n"
8405 (mapconcat 'identity (reverse (cdar args)) ", ") nil t))
8406 (setq args (cdr args)))
8407 (if subject
8408 (message-goto-body)
8409 (message-goto-subject))))
8410
8411 (defun gnus-button-embedded-url (address)
8412 "Activate ADDRESS with `browse-url'."
8413 (browse-url (gnus-strip-whitespace address)))
8414
8415 ;;; Next/prev buttons in the article buffer.
8416
8417 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8418 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8419
8420 (defvar gnus-prev-page-map
8421 (let ((map (make-sparse-keymap)))
8422 (define-key map [mouse-2] 'gnus-button-prev-page)
8423 (define-key map "\r" 'gnus-button-prev-page)
8424 map))
8425
8426 (defvar gnus-next-page-map
8427 (let ((map (make-sparse-keymap)))
8428 (define-key map [mouse-2] 'gnus-button-next-page)
8429 (define-key map "\r" 'gnus-button-next-page)
8430 map))
8431
8432 (defun gnus-insert-prev-page-button ()
8433 (let ((b (point)) e
8434 (inhibit-read-only t))
8435 (gnus-eval-format
8436 gnus-prev-page-line-format nil
8437 `(keymap ,gnus-prev-page-map
8438 gnus-prev t
8439 gnus-callback gnus-article-button-prev-page
8440 article-type annotation))
8441 (setq e (if (bolp)
8442 ;; Exclude a newline.
8443 (1- (point))
8444 (point)))
8445 (when gnus-article-button-face
8446 (overlay-put (make-overlay b e nil t)
8447 'face gnus-article-button-face))
8448 (widget-convert-button
8449 'link b e
8450 :action 'gnus-button-prev-page
8451 :button-keymap gnus-prev-page-map)))
8452
8453 (defun gnus-button-next-page (&optional _args _more-args)
8454 "Go to the next page."
8455 (interactive)
8456 (let ((win (selected-window)))
8457 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8458 (gnus-article-next-page)
8459 (select-window win)))
8460
8461 (defun gnus-button-prev-page (&optional _args _more-args)
8462 "Go to the prev page."
8463 (interactive)
8464 (let ((win (selected-window)))
8465 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8466 (gnus-article-prev-page)
8467 (select-window win)))
8468
8469 (defun gnus-insert-next-page-button ()
8470 (let ((b (point)) e
8471 (inhibit-read-only t))
8472 (gnus-eval-format gnus-next-page-line-format nil
8473 `(keymap ,gnus-next-page-map
8474 gnus-next t
8475 gnus-callback gnus-article-button-next-page
8476 article-type annotation))
8477 (setq e (if (bolp)
8478 ;; Exclude a newline.
8479 (1- (point))
8480 (point)))
8481 (when gnus-article-button-face
8482 (overlay-put (make-overlay b e nil t)
8483 'face gnus-article-button-face))
8484 (widget-convert-button
8485 'link b e
8486 :action 'gnus-button-next-page
8487 :button-keymap gnus-next-page-map)))
8488
8489 (defun gnus-article-button-next-page (_arg)
8490 "Go to the next page."
8491 (interactive "P")
8492 (let ((win (selected-window)))
8493 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8494 (gnus-article-next-page)
8495 (select-window win)))
8496
8497 (defun gnus-article-button-prev-page (_arg)
8498 "Go to the prev page."
8499 (interactive "P")
8500 (let ((win (selected-window)))
8501 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8502 (gnus-article-prev-page)
8503 (select-window win)))
8504
8505 (defvar gnus-decode-header-methods
8506 '(mail-decode-encoded-word-region)
8507 "List of methods used to decode headers.
8508
8509 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8510 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8511 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8512 whose names match REGEXP.
8513
8514 For example:
8515 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8516 mail-decode-encoded-word-region
8517 (\"chinese\" . rfc1843-decode-region))
8518 ")
8519
8520 (defvar gnus-decode-header-methods-cache nil)
8521
8522 (defun gnus-multi-decode-header (start end)
8523 "Apply the functions from `gnus-encoded-word-methods' that match."
8524 (unless (and gnus-decode-header-methods-cache
8525 (eq gnus-newsgroup-name
8526 (car gnus-decode-header-methods-cache)))
8527 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8528 (dolist (x gnus-decode-header-methods)
8529 (if (symbolp x)
8530 (nconc gnus-decode-header-methods-cache (list x))
8531 (if (and gnus-newsgroup-name
8532 (string-match (car x) gnus-newsgroup-name))
8533 (nconc gnus-decode-header-methods-cache
8534 (list (cdr x)))))))
8535 (let ((xlist gnus-decode-header-methods-cache))
8536 (pop xlist)
8537 (save-restriction
8538 (narrow-to-region start end)
8539 (while xlist
8540 (funcall (pop xlist) (point-min) (point-max))))))
8541
8542 ;;;
8543 ;;; Treatment top-level handling.
8544 ;;;
8545
8546 (defvar gnus-inhibit-article-treatments nil)
8547
8548 ;; Dynamic variables.
8549 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8550 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8551 (defvar gnus-treat-type)
8552 (defvar gnus-treat-condition)
8553 (defvar gnus-treat-length)
8554
8555 (defun gnus-treat-article (condition
8556 &optional part-num total type)
8557 (let ((gnus-treat-condition condition)
8558 (part-number part-num)
8559 (total-parts total)
8560 (gnus-treat-type type)
8561 (gnus-treat-length (- (point-max) (point-min)))
8562 (alist gnus-treatment-function-alist)
8563 (article-goto-body-goes-to-point-min-p t)
8564 (treated-type
8565 (or (not type)
8566 (catch 'found
8567 (let ((list gnus-article-treat-types))
8568 (while list
8569 (when (string-match (pop list) type)
8570 (throw 'found t)))))))
8571 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8572 val)
8573 (gnus-run-hooks 'gnus-part-display-hook)
8574 (dolist (elem alist)
8575 (setq val
8576 (save-excursion
8577 (when (gnus-buffer-live-p gnus-summary-buffer)
8578 (set-buffer gnus-summary-buffer))
8579 (symbol-value (car elem))))
8580 (when (and (or (consp val)
8581 treated-type)
8582 (or (not gnus-inhibit-article-treatments)
8583 (eq gnus-treat-condition 'head))
8584 (gnus-treat-predicate val)
8585 (or (not (get (car elem) 'highlight))
8586 highlightp))
8587 (save-restriction
8588 (funcall (cadr elem)))))))
8589
8590 (defun gnus-treat-predicate (val)
8591 (cond
8592 ((null val)
8593 nil)
8594 (gnus-treat-condition
8595 (eq gnus-treat-condition val))
8596 ((and (listp val)
8597 (stringp (car val)))
8598 (apply 'gnus-or (mapcar `(lambda (s)
8599 (string-match s ,(or gnus-newsgroup-name "")))
8600 val)))
8601 ((listp val)
8602 (let ((pred (pop val)))
8603 (cond
8604 ((eq pred 'or)
8605 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8606 ((eq pred 'and)
8607 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8608 ((eq pred 'not)
8609 (not (gnus-treat-predicate (car val))))
8610 ((eq pred 'typep)
8611 (equal (car val) gnus-treat-type))
8612 ((functionp pred)
8613 (funcall pred))
8614 (t
8615 (error "%S is not a valid predicate" pred)))))
8616 ((eq val t)
8617 t)
8618 ((eq val 'head)
8619 nil)
8620 ((eq val 'first)
8621 (eq part-number 1))
8622 ((eq val 'last)
8623 (eq part-number total-parts))
8624 ((numberp val)
8625 (< gnus-treat-length val))
8626 (t
8627 (error "%S is not a valid value" val))))
8628
8629 (defun gnus-article-encrypt-body (protocol &optional n)
8630 "Encrypt the article body."
8631 (interactive
8632 (list
8633 (or gnus-article-encrypt-protocol
8634 (gnus-completing-read "Encrypt protocol"
8635 (mapcar 'car gnus-article-encrypt-protocol-alist)
8636 t))
8637 current-prefix-arg))
8638 ;; User might hit `K E' instead of `K e', so prompt once.
8639 (when (and gnus-article-encrypt-protocol
8640 gnus-novice-user)
8641 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8642 (error "Encrypt aborted")))
8643 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8644 (unless func
8645 (error "Can't find the encrypt protocol %s" protocol))
8646 (if (member gnus-newsgroup-name '("nndraft:delayed"
8647 "nndraft:drafts"
8648 "nndraft:queue"))
8649 (error "Can't encrypt the article in group %s"
8650 gnus-newsgroup-name))
8651 (gnus-summary-iterate n
8652 (with-current-buffer gnus-summary-buffer
8653 (let ((mail-parse-charset gnus-newsgroup-charset)
8654 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8655 (summary-buffer gnus-summary-buffer)
8656 references point)
8657 (gnus-set-global-variables)
8658 (when (gnus-group-read-only-p)
8659 (error "The current newsgroup does not support article encrypt"))
8660 (gnus-summary-show-article t)
8661 (setq references
8662 (or (mail-header-references gnus-current-headers) ""))
8663 (set-buffer gnus-article-buffer)
8664 (let* ((inhibit-read-only t)
8665 (headers
8666 (mapcar (lambda (field)
8667 (and (save-restriction
8668 (message-narrow-to-head)
8669 (goto-char (point-min))
8670 (search-forward field nil t))
8671 (prog2
8672 (message-narrow-to-field)
8673 (buffer-string)
8674 (delete-region (point-min) (point-max))
8675 (widen))))
8676 '("Content-Type:" "Content-Transfer-Encoding:"
8677 "Content-Disposition:"))))
8678 (message-narrow-to-head)
8679 (message-remove-header "MIME-Version")
8680 (goto-char (point-max))
8681 (setq point (point))
8682 (insert (apply 'concat headers))
8683 (widen)
8684 (narrow-to-region point (point-max))
8685 (let ((message-options message-options))
8686 (message-options-set 'message-sender user-mail-address)
8687 (message-options-set 'message-recipients user-mail-address)
8688 (message-options-set 'message-sign-encrypt 'not)
8689 (funcall func))
8690 (goto-char (point-min))
8691 (insert "MIME-Version: 1.0\n")
8692 (widen)
8693 (gnus-summary-edit-article-done
8694 references nil summary-buffer t))
8695 (when gnus-keep-backlog
8696 (gnus-backlog-remove-article
8697 (car gnus-article-current) (cdr gnus-article-current)))
8698 (gnus-flush-original-article-buffer)
8699 (when gnus-use-cache
8700 (gnus-cache-update-article
8701 (car gnus-article-current) (cdr gnus-article-current))))))))
8702
8703 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8704 "The following specs can be used:
8705 %t The security MIME type
8706 %i Additional info
8707 %d Details
8708 %D Details if button is pressed")
8709
8710 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8711 "The following specs can be used:
8712 %t The security MIME type
8713 %i Additional info
8714 %d Details
8715 %D Details if button is pressed")
8716
8717 (defvar gnus-mime-security-button-line-format-alist
8718 '((?t gnus-tmp-type ?s)
8719 (?i gnus-tmp-info ?s)
8720 (?d gnus-tmp-details ?s)
8721 (?D gnus-tmp-pressed-details ?s)))
8722
8723 (defvar gnus-mime-security-button-commands
8724 '((gnus-article-press-button "\r" "Show Detail")
8725 (undefined "v")
8726 (undefined "t")
8727 (undefined "C")
8728 (gnus-mime-security-save-part "o" "Save...")
8729 (undefined "\C-o")
8730 (undefined "r")
8731 (undefined "d")
8732 (undefined "c")
8733 (undefined "i")
8734 (undefined "E")
8735 (undefined "e")
8736 (undefined "p")
8737 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8738 (undefined ".")))
8739
8740 (defvar gnus-mime-security-button-map
8741 (let ((map (make-sparse-keymap)))
8742 (define-key map [mouse-2] 'gnus-article-push-button)
8743 (define-key map [down-mouse-3] 'gnus-mime-security-button-menu)
8744 (dolist (c gnus-mime-security-button-commands)
8745 (define-key map (cadr c) (car c)))
8746 map))
8747
8748 (easy-menu-define
8749 gnus-mime-security-button-menu gnus-mime-security-button-map
8750 "Security button menu."
8751 `("Security Part"
8752 ,@(delq nil
8753 (mapcar (lambda (c)
8754 (unless (eq (car c) 'undefined)
8755 (vector (caddr c) (car c) :active t)))
8756 gnus-mime-security-button-commands))))
8757
8758 (defun gnus-mime-security-button-menu (event prefix)
8759 "Construct a context-sensitive menu of security commands."
8760 (interactive "e\nP")
8761 (save-window-excursion
8762 (let ((pos (event-start event)))
8763 (select-window (posn-window pos))
8764 (goto-char (posn-point pos))
8765 (gnus-article-check-buffer)
8766 (popup-menu gnus-mime-security-button-menu nil prefix))))
8767
8768 (defvar gnus-mime-security-details-buffer nil)
8769
8770 (defvar gnus-mime-security-button-pressed nil)
8771
8772 (defvar gnus-mime-security-show-details-inline t
8773 "If non-nil, show details in the article buffer.")
8774
8775 (defun gnus-mime-security-verify-or-decrypt (handle)
8776 (mm-remove-parts (cdr handle))
8777 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8778 point (inhibit-read-only t))
8779 (if region
8780 (goto-char (car region)))
8781 (setq point (point))
8782 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8783 (let* ((mm-verify-option 'known)
8784 (mm-decrypt-option 'known)
8785 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8786 (unless (eq nparts (cdr handle))
8787 (mm-destroy-parts (cdr handle))
8788 (setcdr handle nparts))))
8789 (gnus-mime-display-security handle)
8790 (when region
8791 (delete-region (point) (cdr region))
8792 (set-marker (car region) nil)
8793 (set-marker (cdr region) nil))
8794 (goto-char point)))
8795
8796 (defun gnus-mime-security-show-details (handle)
8797 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8798 (if (not details)
8799 (gnus-message 5 "No details.")
8800 (if gnus-mime-security-show-details-inline
8801 (let ((gnus-mime-security-button-pressed
8802 (not (get-text-property (point) 'gnus-mime-details)))
8803 (gnus-mime-security-button-line-format
8804 (get-text-property (point) 'gnus-line-format))
8805 (inhibit-read-only t))
8806 (forward-char -1)
8807 (while (eq (get-text-property (point) 'gnus-line-format)
8808 gnus-mime-security-button-line-format)
8809 (forward-char -1))
8810 (forward-char)
8811 (save-restriction
8812 (narrow-to-region (point) (point))
8813 (gnus-insert-mime-security-button handle))
8814 (delete-region (point)
8815 (or (text-property-not-all
8816 (point) (point-max)
8817 'gnus-line-format
8818 gnus-mime-security-button-line-format)
8819 (point-max))))
8820 ;; Not inlined.
8821 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8822 (with-current-buffer gnus-mime-security-details-buffer
8823 (erase-buffer)
8824 t)
8825 (setq gnus-mime-security-details-buffer
8826 (gnus-get-buffer-create "*MIME Security Details*")))
8827 (with-current-buffer gnus-mime-security-details-buffer
8828 (insert details)
8829 (goto-char (point-min)))
8830 (pop-to-buffer gnus-mime-security-details-buffer)))))
8831
8832 (defun gnus-mime-security-press-button (handle)
8833 (save-excursion
8834 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8835 (gnus-mime-security-show-details handle)
8836 (gnus-mime-security-verify-or-decrypt handle))))
8837
8838 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8839 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8840 (gnus-tmp-type
8841 (concat
8842 (or (nth 2 (assoc protocol mm-verify-function-alist))
8843 (nth 2 (assoc protocol mm-decrypt-function-alist))
8844 "Unknown")
8845 (if (equal (car handle) "multipart/signed")
8846 " Signed" " Encrypted")
8847 " Part"))
8848 (gnus-tmp-info
8849 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8850 "Undecided"))
8851 (gnus-tmp-details
8852 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8853 gnus-tmp-pressed-details
8854 b e)
8855 (setq gnus-tmp-details
8856 (if gnus-tmp-details
8857 (concat "\n" gnus-tmp-details)
8858 ""))
8859 (setq gnus-tmp-pressed-details
8860 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8861 (unless (bolp)
8862 (insert "\n"))
8863 (setq b (point))
8864 (gnus-eval-format
8865 gnus-mime-security-button-line-format
8866 gnus-mime-security-button-line-format-alist
8867 `(keymap ,gnus-mime-security-button-map
8868 gnus-callback gnus-mime-security-press-button
8869 gnus-line-format ,gnus-mime-security-button-line-format
8870 gnus-mime-details ,gnus-mime-security-button-pressed
8871 article-type annotation
8872 gnus-data ,handle))
8873 (setq e (if (bolp)
8874 ;; Exclude a newline.
8875 (1- (point))
8876 (point)))
8877 (when gnus-article-button-face
8878 (overlay-put (make-overlay b e nil t)
8879 'face gnus-article-button-face))
8880 (widget-convert-button
8881 'link b e
8882 :mime-handle handle
8883 :action 'gnus-widget-press-button
8884 :button-keymap gnus-mime-security-button-map
8885 :help-echo
8886 (lambda (_widget)
8887 (format
8888 "%S: show detail; %S: more options"
8889 'mouse-2
8890 'down-mouse-3)))))
8891
8892 (defun gnus-mime-display-security (handle)
8893 (save-restriction
8894 (narrow-to-region (point) (point))
8895 (unless (gnus-unbuttonized-mime-type-p (car handle))
8896 (gnus-insert-mime-security-button handle))
8897 (gnus-mime-display-part (cadr handle))
8898 (unless (bolp)
8899 (insert "\n"))
8900 (unless (gnus-unbuttonized-mime-type-p (car handle))
8901 (let ((gnus-mime-security-button-line-format
8902 gnus-mime-security-button-end-line-format))
8903 (gnus-insert-mime-security-button handle)))
8904 (mm-set-handle-multipart-parameter
8905 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8906 (goto-char (point-max))))
8907
8908 (defun gnus-mime-security-run-function (function)
8909 "Run FUNCTION with the security part under point."
8910 (gnus-article-check-buffer)
8911 (let ((data (get-text-property (point) 'gnus-data))
8912 buffer handle)
8913 (when (and (stringp (car-safe data))
8914 (setq buffer (mm-handle-multipart-original-buffer data))
8915 (setq handle (cadr data)))
8916 (if (bufferp (mm-handle-buffer handle))
8917 (progn
8918 (setq handle (cons buffer (copy-sequence (cdr handle))))
8919 (mm-handle-set-undisplayer handle nil))
8920 (setq handle (mm-make-handle
8921 buffer
8922 (mm-handle-multipart-ctl-parameter handle 'protocol)
8923 nil nil nil nil nil nil)))
8924 (funcall function handle))))
8925
8926 (defun gnus-mime-security-save-part ()
8927 "Save the security part under point."
8928 (interactive)
8929 (gnus-mime-security-run-function 'mm-save-part))
8930
8931 (defun gnus-mime-security-pipe-part ()
8932 "Pipe the security part under point to a process."
8933 (interactive)
8934 (gnus-mime-security-run-function 'mm-pipe-part))
8935
8936 (provide 'gnus-art)
8937
8938 (run-hooks 'gnus-art-load-hook)
8939
8940 ;;; gnus-art.el ends here