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