]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
Allow customising the article mode cursor behavior
[gnu-emacs] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
31
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
45
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
53 (autoload 'url-expand-file-name "url-expand")
54
55 (defgroup gnus-article nil
56 "Article display."
57 :link '(custom-manual "(gnus)Article Buffer")
58 :group 'gnus)
59
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
63 :group 'gnus-article)
64
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
68 :group 'gnus-article)
69
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
73 :group 'gnus-article
74 :group 'gnus-visual)
75
76 (defgroup gnus-article-signature nil
77 "Article signatures."
78 :link '(custom-manual "(gnus)Article Signature")
79 :group 'gnus-article)
80
81 (defgroup gnus-article-headers nil
82 "Article headers."
83 :link '(custom-manual "(gnus)Hiding Headers")
84 :group 'gnus-article)
85
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
89 :group 'gnus-article)
90
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
94 :group 'gnus-article)
95
96 (defgroup gnus-article-saving nil
97 "Saving articles."
98 :link '(custom-manual "(gnus)Saving Articles")
99 :group 'gnus-article)
100
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
105
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
110
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
115
116 (defcustom gnus-ignored-headers
117 (mapcar
118 (lambda (header)
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
165 (repeat regexp))
166 :group 'gnus-article-hiding)
167
168 (defcustom gnus-visible-headers
169 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
173 :type '(choice
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
177 (or (stringp value)
178 (widget-editable-list-match widget value)))
179 regexp)
180 (const :tag "Use gnus-ignored-headers" nil)
181 regexp)
182 :group 'gnus-article-hiding)
183
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
190 this list."
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
193
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
197
198 `empty' Headers with no content.
199 `newsgroups' Newsgroup identical to Gnus group.
200 `to-address' To identical to To-address.
201 `to-list' To identical to To-list.
202 `cc-list' CC identical to To-list.
203 `followup-to' Followup-to identical to Newsgroups.
204 `reply-to' Reply-to identical to From.
205 `date' Date less than four days old.
206 `long-to' To and/or Cc longer than 1024 characters.
207 `many-to' Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
219
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
226 :version "22.1"
227 :type 'boolean
228 :group 'gnus-article-hiding)
229
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
236 (regexp)
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
239
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
248
249 This can also be a list of the above values."
250 :type '(choice (const nil)
251 (integer :value 200)
252 (number :value 4.0)
253 function
254 (regexp :value ".*"))
255 :group 'gnus-article-signature)
256
257 (defcustom gnus-hidden-properties
258 ;; We use to have `intangible' here as well, but Emacs's command loop moves
259 ;; point out of invisible text anyway, so `intangible' is clearly not
260 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
261 '(invisible t)
262 "Property list to use for hiding text."
263 :type 'plist
264 :group 'gnus-article-hiding)
265
266 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
267 ;; frames in a session.
268 (defcustom gnus-article-x-face-command
269 (if (featurep 'xemacs)
270 (if (or (gnus-image-type-available-p 'xface)
271 (gnus-image-type-available-p 'pbm))
272 'gnus-display-x-face-in-from
273 "{ echo \
274 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
275 ; uncompface; } | icontopbm | ee -")
276 (if (gnus-image-type-available-p 'pbm)
277 'gnus-display-x-face-in-from
278 "{ echo \
279 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
280 ; uncompface; } | icontopbm | display -"))
281 "*String or function to be executed to display an X-Face header.
282 If it is a string, the command will be executed in a sub-shell
283 asynchronously. The compressed face will be piped to this command."
284 :type `(choice string
285 (function-item gnus-display-x-face-in-from)
286 function)
287 :version "21.1"
288 :group 'gnus-picon
289 :group 'gnus-article-washing)
290
291 (defcustom gnus-article-x-face-too-ugly nil
292 "Regexp matching posters whose face shouldn't be shown automatically."
293 :type '(choice regexp (const nil))
294 :group 'gnus-article-washing)
295
296 (defcustom gnus-article-banner-alist nil
297 "Banner alist for stripping.
298 For example,
299 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
300 :version "21.1"
301 :type '(repeat (cons symbol regexp))
302 :group 'gnus-article-washing)
303
304 (gnus-define-group-parameter
305 banner
306 :variable-document
307 "Alist of regexps (to match group names) and banner."
308 :variable-group gnus-article-washing
309 :parameter-type
310 '(choice :tag "Banner"
311 :value nil
312 (const :tag "Remove signature" signature)
313 (symbol :tag "Item in `gnus-article-banner-alist'" none)
314 regexp
315 (const :tag "None" nil))
316 :parameter-document
317 "If non-nil, specify how to remove `banners' from articles.
318
319 Symbol `signature' means to remove signatures delimited by
320 `gnus-signature-separator'. Any other symbol is used to look up a
321 regular expression to match the banner in `gnus-article-banner-alist'.
322 A string is used as a regular expression to match the banner
323 directly.")
324
325 (defcustom gnus-article-address-banner-alist nil
326 "Alist of mail addresses and banners.
327 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
328 to match a mail address in the From: header, BANNER is one of a symbol
329 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
330 If ADDRESS matches author's mail address, it will remove things like
331 advertisements. For example:
332
333 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
334 "
335 :type '(repeat
336 (cons
337 (regexp :tag "Address")
338 (choice :tag "Banner" :value nil
339 (const :tag "Remove signature" signature)
340 (symbol :tag "Item in `gnus-article-banner-alist'" none)
341 regexp
342 (const :tag "None" nil))))
343 :version "22.1"
344 :group 'gnus-article-washing)
345
346 (defmacro gnus-emphasis-custom-with-format (&rest body)
347 `(let ((format "\
348 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
349 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
350 ,@body))
351
352 (defun gnus-emphasis-custom-value-to-external (value)
353 (gnus-emphasis-custom-with-format
354 (if (consp (car value))
355 (list (format format (car (car value)) (cdr (car value)))
356 2
357 (if (nth 1 value) 2 3)
358 (nth 2 value))
359 value)))
360
361 (defun gnus-emphasis-custom-value-to-internal (value)
362 (gnus-emphasis-custom-with-format
363 (let ((regexp (concat "\\`"
364 (format (regexp-quote format)
365 "\\([^()]+\\)" "\\([^()]+\\)")
366 "\\'"))
367 pattern)
368 (if (string-match regexp (setq pattern (car value)))
369 (list (cons (match-string 1 pattern) (match-string 2 pattern))
370 (= (nth 2 value) 2)
371 (nth 3 value))
372 value))))
373
374 (defcustom gnus-emphasis-alist
375 (let ((types
376 '(("\\*" "\\*" bold nil 2)
377 ("_" "_" underline)
378 ("/" "/" italic)
379 ("_/" "/_" underline-italic)
380 ("_\\*" "\\*_" underline-bold)
381 ("\\*/" "/\\*" bold-italic)
382 ("_\\*/" "/\\*_" underline-bold-italic))))
383 (nconc
384 (gnus-emphasis-custom-with-format
385 (mapcar (lambda (spec)
386 (list (format format (car spec) (cadr spec))
387 (or (nth 3 spec) 2)
388 (or (nth 4 spec) 3)
389 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
390 types))
391 '(;; I've never seen anyone use this strikethru convention whereas I've
392 ;; several times seen it triggered by normal text. --Stef
393 ;; Miles suggests that this form is sometimes used but for italics,
394 ;; so maybe we should map it to `italic'.
395 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
396 ;; 2 3 gnus-emphasis-strikethru)
397 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
398 2 3 gnus-emphasis-underline))))
399 "*Alist that says how to fontify certain phrases.
400 Each item looks like this:
401
402 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
403
404 The first element is a regular expression to be matched. The second
405 is a number that says what regular expression grouping used to find
406 the entire emphasized word. The third is a number that says what
407 regexp grouping should be displayed and highlighted. The fourth
408 is the face used for highlighting."
409 :type
410 '(repeat
411 (menu-choice
412 :format "%[Customizing Style%]\n%v"
413 :indent 2
414 (group :tag "Default"
415 :value ("" 0 0 default)
416 :value-create
417 (lambda (widget)
418 (let ((value (widget-get
419 (cadr (widget-get (widget-get widget :parent)
420 :args))
421 :value)))
422 (if (not (eq (nth 2 value) 'default))
423 (widget-put
424 widget
425 :value
426 (gnus-emphasis-custom-value-to-external value))))
427 (widget-group-value-create widget))
428 regexp
429 (integer :format "Match group: %v")
430 (integer :format "Emphasize group: %v")
431 face)
432 (group :tag "Simple"
433 :value (("_" . "_") nil default)
434 (cons :format "%v"
435 (regexp :format "Start regexp: %v")
436 (regexp :format "End regexp: %v"))
437 (boolean :format "Show start and end patterns: %[%v%]\n"
438 :on " On " :off " Off ")
439 face)))
440 :get (lambda (symbol)
441 (mapcar 'gnus-emphasis-custom-value-to-internal
442 (default-value symbol)))
443 :set (lambda (symbol value)
444 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
445 value)))
446 :group 'gnus-article-emphasis)
447
448 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
449 "A regexp to describe whitespace which should not be emphasized.
450 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
451 The former avoids underlining of leading and trailing whitespace,
452 and the latter avoids underlining any whitespace at all."
453 :version "21.1"
454 :group 'gnus-article-emphasis
455 :type 'regexp)
456
457 (defface gnus-emphasis-bold '((t (:bold t)))
458 "Face used for displaying strong emphasized text (*word*)."
459 :group 'gnus-article-emphasis)
460
461 (defface gnus-emphasis-italic '((t (:italic t)))
462 "Face used for displaying italic emphasized text (/word/)."
463 :group 'gnus-article-emphasis)
464
465 (defface gnus-emphasis-underline '((t (:underline t)))
466 "Face used for displaying underlined emphasized text (_word_)."
467 :group 'gnus-article-emphasis)
468
469 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
470 "Face used for displaying underlined bold emphasized text (_*word*_)."
471 :group 'gnus-article-emphasis)
472
473 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
474 "Face used for displaying underlined italic emphasized text (_/word/_)."
475 :group 'gnus-article-emphasis)
476
477 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
478 "Face used for displaying bold italic emphasized text (/*word*/)."
479 :group 'gnus-article-emphasis)
480
481 (defface gnus-emphasis-underline-bold-italic
482 '((t (:bold t :italic t :underline t)))
483 "Face used for displaying underlined bold italic emphasized text.
484 Example: (_/*word*/_)."
485 :group 'gnus-article-emphasis)
486
487 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
488 '((t (:strikethru t)))
489 '((t (:strike-through t))))
490 "Face used for displaying strike-through text (-word-)."
491 :group 'gnus-article-emphasis)
492
493 (defface gnus-emphasis-highlight-words
494 '((t (:background "black" :foreground "yellow")))
495 "Face used for displaying highlighted words."
496 :group 'gnus-article-emphasis)
497
498 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
499 "Format for display of Date headers in article bodies.
500 See `format-time-string' for the possible values.
501
502 The variable can also be function, which should return a complete Date
503 header. The function is called with one argument, the time, which can
504 be fed to `format-time-string'."
505 :type '(choice string function)
506 :link '(custom-manual "(gnus)Article Date")
507 :group 'gnus-article-washing)
508
509 (defcustom gnus-save-all-headers t
510 "*If non-nil, don't remove any headers before saving.
511 This will be overridden by the `:headers' property that the symbol of
512 the saver function, which is specified by `gnus-default-article-saver',
513 might have."
514 :group 'gnus-article-saving
515 :type 'boolean)
516
517 (defcustom gnus-prompt-before-saving 'always
518 "*This variable says how much prompting is to be done when saving articles.
519 If it is nil, no prompting will be done, and the articles will be
520 saved to the default files. If this variable is `always', each and
521 every article that is saved will be preceded by a prompt, even when
522 saving large batches of articles. If this variable is neither nil not
523 `always', there the user will be prompted once for a file name for
524 each invocation of the saving commands."
525 :group 'gnus-article-saving
526 :type '(choice (item always)
527 (item :tag "never" nil)
528 (sexp :tag "once" :format "%t\n" :value t)))
529
530 (defcustom gnus-article-show-cursor nil
531 "If non-nil, show the cursor in the Article buffer even when not selected."
532 :version "25.1"
533 :group 'gnus-article
534 :type 'bool)
535
536 (defcustom gnus-saved-headers gnus-visible-headers
537 "Headers to keep if `gnus-save-all-headers' is nil.
538 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
539 If that variable is nil, however, all headers that match this regexp
540 will be kept while the rest will be deleted before saving. This and
541 `gnus-save-all-headers' will be overridden by the `:headers' property
542 that the symbol of the saver function, which is specified by
543 `gnus-default-article-saver', might have."
544 :group 'gnus-article-saving
545 :type 'regexp)
546
547 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
548 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
549 "A function to save articles in your favorite format.
550 The function will be called by way of the `gnus-summary-save-article'
551 command, and friends such as `gnus-summary-save-article-rmail'.
552
553 Gnus provides the following functions:
554
555 * gnus-summary-save-in-rmail (Rmail format)
556 * gnus-summary-save-in-mail (Unix mail format)
557 * gnus-summary-save-in-folder (MH folder)
558 * gnus-summary-save-in-file (article format)
559 * gnus-summary-save-body-in-file (article body)
560 * gnus-summary-save-in-vm (use VM's folder format)
561 * gnus-summary-write-to-file (article format -- overwrite)
562 * gnus-summary-write-body-to-file (article body -- overwrite)
563 * gnus-summary-save-in-pipe (article format)
564
565 The symbol of each function may have the following properties:
566
567 * :decode
568 The value non-nil means save decoded articles. This is meaningful
569 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
570 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
571 `gnus-summary-save-in-pipe'.
572
573 * :function
574 The value specifies an alternative function which appends, not
575 overwrites, articles to a file. This implies that when saving many
576 articles at a time, `gnus-prompt-before-saving' is bound to t and all
577 articles are saved in a single file. This is meaningful only with
578 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
579
580 * :headers
581 The value specifies the symbol of a variable of which the value
582 specifies headers to be saved. If it is omitted,
583 `gnus-save-all-headers' and `gnus-saved-headers' control what
584 headers should be saved."
585 :group 'gnus-article-saving
586 :type '(radio (function-item gnus-summary-save-in-rmail)
587 (function-item gnus-summary-save-in-mail)
588 (function-item gnus-summary-save-in-folder)
589 (function-item gnus-summary-save-in-file)
590 (function-item gnus-summary-save-body-in-file)
591 (function-item gnus-summary-save-in-vm)
592 (function-item gnus-summary-write-to-file)
593 (function-item gnus-summary-write-body-to-file)
594 (function-item gnus-summary-save-in-pipe)
595 (function)))
596
597 (defcustom gnus-article-save-coding-system
598 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
599 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
600 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
601 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
602 "Coding system used to save decoded articles to a file.
603
604 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
605 which can safely encode any characters in text. This is used by the
606 commands including:
607
608 * gnus-summary-save-article-file
609 * gnus-summary-save-article-body-file
610 * gnus-summary-write-article-file
611 * gnus-summary-write-article-body-file
612
613 and the functions to which you may set `gnus-default-article-saver':
614
615 * gnus-summary-save-in-file
616 * gnus-summary-save-body-in-file
617 * gnus-summary-write-to-file
618 * gnus-summary-write-body-to-file
619
620 Those commands and functions save just text displayed in the article
621 buffer to a file if the value of this variable is non-nil. Note that
622 buttonized MIME parts will be lost in a saved file in that case.
623 Otherwise, raw articles will be saved."
624 :group 'gnus-article-saving
625 :type `(choice
626 :format "%{%t%}:\n %[Value Menu%] %v"
627 (const :tag "Save raw articles" nil)
628 ,@(delq nil
629 (mapcar
630 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
631 '((const :tag "UTF-8" utf-8)
632 (const :tag "iso-2022-7bit" iso-2022-7bit)
633 (const :tag "Emacs internal" emacs-mule)
634 (const :tag "escape-quoted" escape-quoted))))
635 (symbol :tag "Coding system")))
636
637 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
638 "A function generating a file name to save articles in Rmail format.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
640 :group 'gnus-article-saving
641 :type 'function)
642
643 (defcustom gnus-mail-save-name 'gnus-plain-save-name
644 "A function generating a file name to save articles in Unix mail format.
645 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
646 :group 'gnus-article-saving
647 :type 'function)
648
649 (defcustom gnus-folder-save-name 'gnus-folder-save-name
650 "A function generating a file name to save articles in MH folder.
651 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
652 :group 'gnus-article-saving
653 :type 'function)
654
655 (defcustom gnus-file-save-name 'gnus-numeric-save-name
656 "A function generating a file name to save articles in article format.
657 The function is called with NEWSGROUP, HEADERS, and optional
658 LAST-FILE."
659 :group 'gnus-article-saving
660 :type 'function)
661
662 (defcustom gnus-split-methods
663 '((gnus-article-archive-name)
664 (gnus-article-nndoc-name))
665 "*Variable used to suggest where articles are to be saved.
666 For instance, if you would like to save articles related to Gnus in
667 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
668 you could set this variable to something like:
669
670 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
671 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
672
673 This variable is an alist where the key is the match and the
674 value is a list of possible files to save in if the match is
675 non-nil.
676
677 If the match is a string, it is used as a regexp match on the
678 article. If the match is a symbol, that symbol will be funcalled
679 from the buffer of the article to be saved with the newsgroup as the
680 parameter. If it is a list, it will be evalled in the same buffer.
681
682 If this form or function returns a string, this string will be used as a
683 possible file name; and if it returns a non-nil list, that list will be
684 used as possible file names."
685 :group 'gnus-article-saving
686 :type '(repeat (choice (list :value (fun) function)
687 (cons :value ("" "") regexp (repeat string))
688 (sexp :value nil))))
689
690 (defcustom gnus-page-delimiter "^\^L"
691 "*Regexp describing what to use as article page delimiters.
692 The default value is \"^\^L\", which is a form linefeed at the
693 beginning of a line."
694 :type 'regexp
695 :group 'gnus-article-various)
696
697 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
698 "*The format specification for the article mode line.
699 See `gnus-summary-mode-line-format' for a closer description.
700
701 The following additional specs are available:
702
703 %w The article washing status.
704 %m The number of MIME parts in the article."
705 :version "24.1"
706 :type 'string
707 :group 'gnus-article-various)
708
709 (defcustom gnus-article-mode-hook nil
710 "*A hook for Gnus article mode."
711 :type 'hook
712 :group 'gnus-article-various)
713
714 (when (featurep 'xemacs)
715 ;; Extracted from gnus-xmas-define in order to preserve user settings
716 (when (fboundp 'turn-off-scroll-in-place)
717 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
718 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
719 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
720
721 (defcustom gnus-article-menu-hook nil
722 "*Hook run after the creation of the article mode menu."
723 :type 'hook
724 :group 'gnus-article-various)
725
726 (defcustom gnus-article-prepare-hook nil
727 "*A hook called after an article has been prepared in the article buffer."
728 :type 'hook
729 :group 'gnus-article-various)
730
731 (defcustom gnus-copy-article-ignored-headers nil
732 "List of headers to be removed when copying an article.
733 Each element is a regular expression."
734 :version "23.1" ;; No Gnus
735 :type '(repeat regexp)
736 :group 'gnus-article-various)
737
738 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
739 "Gnus 5.10 (Emacs 22.1)")
740
741 (defface gnus-button
742 '((t (:weight bold)))
743 "Face used for highlighting a button in the article buffer."
744 :group 'gnus-article-buttons)
745
746 (defcustom gnus-article-button-face 'gnus-button
747 "Face used for highlighting buttons in the article buffer.
748
749 An article button is a piece of text that you can activate by pressing
750 `RET' or `mouse-2' above it."
751 :type 'face
752 :group 'gnus-article-buttons)
753
754 (defcustom gnus-article-mouse-face 'highlight
755 "Face used for mouse highlighting in the article buffer.
756
757 Article buttons will be displayed in this face when the cursor is
758 above them."
759 :type 'face
760 :group 'gnus-article-buttons)
761
762 (defcustom gnus-signature-face 'gnus-signature
763 "Face used for highlighting a signature in the article buffer.
764 Obsolete; use the face `gnus-signature' for customizations instead."
765 :type 'face
766 :group 'gnus-article-highlight
767 :group 'gnus-article-signature)
768
769 (defface gnus-signature
770 '((t
771 (:italic t)))
772 "Face used for highlighting a signature in the article buffer."
773 :group 'gnus-article-highlight
774 :group 'gnus-article-signature)
775 ;; backward-compatibility alias
776 (put 'gnus-signature-face 'face-alias 'gnus-signature)
777 (put 'gnus-signature-face 'obsolete-face "22.1")
778
779 (defface gnus-header-from
780 '((((class color)
781 (background dark))
782 (:foreground "PaleGreen1"))
783 (((class color)
784 (background light))
785 (:foreground "red3"))
786 (t
787 (:italic t)))
788 "Face used for displaying from headers."
789 :group 'gnus-article-headers
790 :group 'gnus-article-highlight)
791 ;; backward-compatibility alias
792 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
793 (put 'gnus-header-from-face 'obsolete-face "22.1")
794
795 (defface gnus-header-subject
796 '((((class color)
797 (background dark))
798 (:foreground "SeaGreen1"))
799 (((class color)
800 (background light))
801 (:foreground "red4"))
802 (t
803 (:bold t :italic t)))
804 "Face used for displaying subject headers."
805 :group 'gnus-article-headers
806 :group 'gnus-article-highlight)
807 ;; backward-compatibility alias
808 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
809 (put 'gnus-header-subject-face 'obsolete-face "22.1")
810
811 (defface gnus-header-newsgroups
812 '((((class color)
813 (background dark))
814 (:foreground "yellow" :italic t))
815 (((class color)
816 (background light))
817 (:foreground "MidnightBlue" :italic t))
818 (t
819 (:italic t)))
820 "Face used for displaying newsgroups headers.
821 In the default setup this face is only used for crossposted
822 articles."
823 :group 'gnus-article-headers
824 :group 'gnus-article-highlight)
825 ;; backward-compatibility alias
826 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
827 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
828
829 (defface gnus-header-name
830 '((((class color)
831 (background dark))
832 (:foreground "SpringGreen2"))
833 (((class color)
834 (background light))
835 (:foreground "maroon"))
836 (t
837 (:bold t)))
838 "Face used for displaying header names."
839 :group 'gnus-article-headers
840 :group 'gnus-article-highlight)
841 ;; backward-compatibility alias
842 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
843 (put 'gnus-header-name-face 'obsolete-face "22.1")
844
845 (defface gnus-header-content
846 '((((class color)
847 (background dark))
848 (:foreground "SpringGreen1" :italic t))
849 (((class color)
850 (background light))
851 (:foreground "indianred4" :italic t))
852 (t
853 (:italic t))) "Face used for displaying header content."
854 :group 'gnus-article-headers
855 :group 'gnus-article-highlight)
856 ;; backward-compatibility alias
857 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
858 (put 'gnus-header-content-face 'obsolete-face "22.1")
859
860 (defcustom gnus-header-face-alist
861 '(("From" nil gnus-header-from)
862 ("Subject" nil gnus-header-subject)
863 ("Newsgroups:.*," nil gnus-header-newsgroups)
864 ("" gnus-header-name gnus-header-content))
865 "*Controls highlighting of article headers.
866
867 An alist of the form (HEADER NAME CONTENT).
868
869 HEADER is a regular expression which should match the name of a
870 header and NAME and CONTENT are either face names or nil.
871
872 The name of each header field will be displayed using the face
873 specified by the first element in the list where HEADER matches
874 the header name and NAME is non-nil. Similarly, the content will
875 be displayed by the first non-nil matching CONTENT face."
876 :group 'gnus-article-headers
877 :group 'gnus-article-highlight
878 :type '(repeat (list (regexp :tag "Header")
879 (choice :tag "Name"
880 (item :tag "skip" nil)
881 (face :value default))
882 (choice :tag "Content"
883 (item :tag "skip" nil)
884 (face :value default)))))
885
886 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
887 '((xface . (:face gnus-x-face)))
888 '((pbm . (:face gnus-x-face))
889 (png . nil)))
890 "Alist of image types and properties applied to Face and X-Face images.
891 Here are examples:
892
893 ;; Specify the altitude of Face images in the From header.
894 \(setq gnus-face-properties-alist
895 \\='((pbm . (:face gnus-x-face :ascent 80))
896 (png . (:ascent 80))))
897
898 ;; Show Face images as pressed buttons.
899 \(setq gnus-face-properties-alist
900 \\='((pbm . (:face gnus-x-face :relief -2))
901 (png . (:relief -2))))
902
903 See the manual for the valid properties for various image types.
904 Currently, `pbm' is used for X-Face images and `png' is used for Face
905 images in Emacs. Only the `:face' property is effective on the `xface'
906 image type in XEmacs if it is built with the libcompface library."
907 :version "23.1" ;; No Gnus
908 :group 'gnus-article-headers
909 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
910
911 (defcustom gnus-article-decode-hook
912 '(article-decode-charset article-decode-encoded-words
913 article-decode-group-name article-decode-idna-rhs)
914 "*Hook run to decode charsets in articles."
915 :group 'gnus-article-headers
916 :type 'hook)
917
918 (defcustom gnus-display-mime-function 'gnus-display-mime
919 "Function to display MIME articles."
920 :group 'gnus-article-mime
921 :type 'function)
922
923 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
924 "Function used to decode headers.")
925
926 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
927 "Function used to decode addresses.")
928
929 (defvar gnus-article-dumbquotes-map
930 '((?\200 "EUR")
931 (?\202 ",")
932 (?\203 "f")
933 (?\204 ",,")
934 (?\205 "...")
935 (?\213 "<")
936 (?\214 "OE")
937 (?\221 "`")
938 (?\222 "'")
939 (?\223 "``")
940 (?\224 "\"")
941 (?\225 "*")
942 (?\226 "-")
943 (?\227 "--")
944 (?\230 "~")
945 (?\231 "(TM)")
946 (?\233 ">")
947 (?\234 "oe")
948 (?\264 "'"))
949 "Table for MS-to-Latin1 translation.")
950
951 (defcustom gnus-ignored-mime-types nil
952 "List of MIME types that should be ignored by Gnus."
953 :version "21.1"
954 :group 'gnus-article-mime
955 :type '(repeat regexp))
956
957 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
958 "List of MIME types that should not be given buttons when rendered inline.
959 See also `gnus-buttonized-mime-types' which may override this variable.
960 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
961 :version "21.1"
962 :group 'gnus-article-mime
963 :type '(repeat regexp))
964
965 (defcustom gnus-buttonized-mime-types nil
966 "List of MIME types that should be given buttons when rendered inline.
967 If set, this variable overrides `gnus-unbuttonized-mime-types'.
968 To see e.g. security buttons you could set this to
969 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
970 this list to display radio buttons that allow you to choose one of two
971 media types those mails include. See also `mm-discouraged-alternatives'.
972 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
973 :version "22.1"
974 :group 'gnus-article-mime
975 :type '(repeat regexp))
976
977 (defcustom gnus-inhibit-mime-unbuttonizing nil
978 "If non-nil, all MIME parts get buttons.
979 When nil (the default value), then some MIME parts do not get buttons,
980 as described by the variables `gnus-buttonized-mime-types' and
981 `gnus-unbuttonized-mime-types'."
982 :version "22.1"
983 :group 'gnus-article-mime
984 :type 'boolean)
985
986 (defcustom gnus-body-boundary-delimiter "_"
987 "String used to delimit header and body.
988 This variable is used by `gnus-article-treat-body-boundary' which can
989 be controlled by `gnus-treat-body-boundary'."
990 :version "22.1"
991 :group 'gnus-article-various
992 :type '(choice (item :tag "None" :value nil)
993 string))
994
995 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
996 "/usr/share/picons")
997 "Defines the location of the faces database.
998 For information on obtaining this database of pretty pictures, please
999 see http://www.cs.indiana.edu/picons/ftp/index.html"
1000 :version "22.1"
1001 :type '(repeat directory)
1002 :link '(url-link :tag "download"
1003 "http://www.cs.indiana.edu/picons/ftp/index.html")
1004 :link '(custom-manual "(gnus)Picons")
1005 :group 'gnus-picon)
1006
1007 (defun gnus-picons-installed-p ()
1008 "Say whether picons are installed on your machine."
1009 (let ((installed nil))
1010 (dolist (database gnus-picon-databases)
1011 (when (file-exists-p database)
1012 (setq installed t)))
1013 installed))
1014
1015 (defcustom gnus-article-mime-part-function nil
1016 "Function called with a MIME handle as the argument.
1017 This is meant for people who want to do something automatic based
1018 on parts -- for instance, adding Vcard info to a database."
1019 :group 'gnus-article-mime
1020 :type '(choice (const nil)
1021 function))
1022
1023 (defcustom gnus-mime-multipart-functions nil
1024 "An alist of MIME types to functions to display them."
1025 :version "21.1"
1026 :group 'gnus-article-mime
1027 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1028
1029 (defcustom gnus-article-date-headers '(combined-lapsed)
1030 "A list of Date header formats to display.
1031 Valid formats are `ut' (universal time), `local' (local time
1032 zone), `english' (readable English), `lapsed' (elapsed time),
1033 `combined-lapsed' (both the original date and the elapsed time),
1034 `original' (the original date header), `iso8601' (ISO8601
1035 format), and `user-defined' (a user-defined format defined by the
1036 `gnus-article-time-format' variable).
1037
1038 You have as many date headers as you want in the article buffer.
1039 Some of these headers are updated automatically. See
1040 `gnus-article-update-date-headers' for details."
1041 :version "24.1"
1042 :group 'gnus-article-headers
1043 :type '(set
1044 (const :tag "Universal time (UT)" ut)
1045 (const :tag "Local time zone" local)
1046 (const :tag "Readable English" english)
1047 (const :tag "Elapsed time" lapsed)
1048 (const :tag "Original and elapsed time" combined-lapsed)
1049 (const :tag "Original date header" original)
1050 (const :tag "ISO8601 format" iso8601)
1051 (const :tag "User-defined" user-defined)))
1052
1053 (defcustom gnus-article-update-date-headers nil
1054 "A number that says how often to update the date header (in seconds).
1055 If nil, don't update it at all."
1056 :version "24.1"
1057 :group 'gnus-article-headers
1058 :type '(choice
1059 (item :tag "Don't update" :value nil)
1060 integer))
1061
1062 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1063 "Function called with a MIME handle as the argument.
1064 This is meant for people who want to view first matched part.
1065 For `undisplayed-alternative' (default), the first undisplayed
1066 part or alternative part is used. For `undisplayed', the first
1067 undisplayed part is used. For a function, the first part which
1068 the function return t is used. For nil, the first part is
1069 used."
1070 :version "21.1"
1071 :group 'gnus-article-mime
1072 :type '(choice
1073 (item :tag "first" :value nil)
1074 (item :tag "undisplayed" :value undisplayed)
1075 (item :tag "undisplayed or alternative"
1076 :value undisplayed-alternative)
1077 (function)))
1078
1079 (defcustom gnus-mime-action-alist
1080 '(("save to file" . gnus-mime-save-part)
1081 ("save and strip" . gnus-mime-save-part-and-strip)
1082 ("replace with file" . gnus-mime-replace-part)
1083 ("delete part" . gnus-mime-delete-part)
1084 ("display as text" . gnus-mime-inline-part)
1085 ("view the part" . gnus-mime-view-part)
1086 ("pipe to command" . gnus-mime-pipe-part)
1087 ("toggle display" . gnus-article-press-button)
1088 ("toggle display" . gnus-article-view-part-as-charset)
1089 ("view as type" . gnus-mime-view-part-as-type)
1090 ("view internally" . gnus-mime-view-part-internally)
1091 ("view externally" . gnus-mime-view-part-externally))
1092 "An alist of actions that run on the MIME attachment."
1093 :group 'gnus-article-mime
1094 :type '(repeat (cons (string :tag "name")
1095 (function))))
1096
1097 (defcustom gnus-auto-select-part 1
1098 "Advance to next MIME part when deleting or stripping parts.
1099
1100 When 0, point will be placed on the same part as before. When
1101 positive (negative), move point forward (backwards) this many
1102 parts. When nil, redisplay article."
1103 :version "23.1" ;; No Gnus
1104 :group 'gnus-article-mime
1105 :type '(choice (const nil :tag "Redisplay article.")
1106 (const 1 :tag "Next part.")
1107 (const 0 :tag "Current part.")
1108 integer))
1109
1110 ;;;
1111 ;;; The treatment variables
1112 ;;;
1113
1114 (defvar gnus-part-display-hook nil
1115 "Hook called on parts that are to receive treatment.")
1116
1117 (defvar gnus-article-treat-custom
1118 '(choice (const :tag "Off" nil)
1119 (const :tag "On" t)
1120 (const :tag "Header" head)
1121 (const :tag "First" first)
1122 (const :tag "Last" last)
1123 (integer :tag "Less")
1124 (repeat :tag "Groups" regexp)
1125 (sexp :tag "Predicate")))
1126
1127 (defvar gnus-article-treat-head-custom
1128 '(choice (const :tag "Off" nil)
1129 (const :tag "Header" head)))
1130
1131 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1132 "text/x-patch" "text/html")
1133 "Part types eligible for treatment.")
1134
1135 (defvar gnus-inhibit-treatment nil
1136 "Whether to inhibit treatment.")
1137
1138 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1139 "Highlight the signature.
1140 Valid values are nil, t, `head', `first', `last', an integer or a
1141 predicate. See Info node `(gnus)Customizing Articles'."
1142 :group 'gnus-article-treat
1143 :link '(custom-manual "(gnus)Customizing Articles")
1144 :type gnus-article-treat-custom)
1145 (put 'gnus-treat-highlight-signature 'highlight t)
1146
1147 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1148 "Add buttons.
1149 Valid values are nil, t, `head', `first', `last', an integer or a
1150 predicate. See Info node `(gnus)Customizing Articles'."
1151 :group 'gnus-article-treat
1152 :link '(custom-manual "(gnus)Customizing Articles")
1153 :type gnus-article-treat-custom)
1154 (put 'gnus-treat-buttonize 'highlight t)
1155
1156 (defcustom gnus-treat-buttonize-head 'head
1157 "Add buttons to the head.
1158 Valid values are nil, t, `head', `first', `last', an integer or a
1159 predicate. See Info node `(gnus)Customizing Articles'."
1160 :group 'gnus-article-treat
1161 :link '(custom-manual "(gnus)Customizing Articles")
1162 :type gnus-article-treat-head-custom)
1163 (put 'gnus-treat-buttonize-head 'highlight t)
1164
1165 (defcustom gnus-treat-date 'head
1166 "Display dates according to the `gnus-article-date-headers' variable.
1167 Valid values are nil, t, `head', `first', `last', an integer or a
1168 predicate. See Info node `(gnus)Customizing Articles'."
1169 :version "24.1"
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-head-custom)
1173
1174 (defcustom gnus-treat-emphasize 50000
1175 "Emphasize text.
1176 Valid values are nil, t, `head', `first', `last', an integer or a
1177 predicate. See Info node `(gnus)Customizing Articles'."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-custom)
1181 (put 'gnus-treat-emphasize 'highlight t)
1182
1183 (defcustom gnus-treat-strip-cr nil
1184 "Remove carriage returns.
1185 Valid values are nil, t, `head', `first', `last', an integer or a
1186 predicate. See Info node `(gnus)Customizing Articles'."
1187 :version "22.1"
1188 :group 'gnus-article-treat
1189 :link '(custom-manual "(gnus)Customizing Articles")
1190 :type gnus-article-treat-custom)
1191
1192 (defcustom gnus-treat-unsplit-urls nil
1193 "Remove newlines from within URLs.
1194 Valid values are nil, t, `head', `first', `last', an integer or a
1195 predicate. See Info node `(gnus)Customizing Articles'."
1196 :version "22.1"
1197 :group 'gnus-article-treat
1198 :link '(custom-manual "(gnus)Customizing Articles")
1199 :type gnus-article-treat-custom)
1200
1201 (defcustom gnus-treat-leading-whitespace nil
1202 "Remove leading whitespace in headers.
1203 Valid values are nil, t, `head', `first', `last', an integer or a
1204 predicate. See Info node `(gnus)Customizing Articles'."
1205 :version "22.1"
1206 :group 'gnus-article-treat
1207 :link '(custom-manual "(gnus)Customizing Articles")
1208 :type gnus-article-treat-custom)
1209
1210 (defcustom gnus-treat-hide-headers 'head
1211 "Hide headers.
1212 Valid values are nil, t, `head', `first', `last', an integer or a
1213 predicate. See Info node `(gnus)Customizing Articles'."
1214 :group 'gnus-article-treat
1215 :link '(custom-manual "(gnus)Customizing Articles")
1216 :type gnus-article-treat-head-custom)
1217
1218 (defcustom gnus-treat-hide-boring-headers nil
1219 "Hide boring headers.
1220 Valid values are nil, t, `head', `first', `last', an integer or a
1221 predicate. See Info node `(gnus)Customizing Articles'."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-head-custom)
1225
1226 (defcustom gnus-treat-hide-signature nil
1227 "Hide the signature.
1228 Valid values are nil, t, `head', `first', `last', an integer or a
1229 predicate. See Info node `(gnus)Customizing Articles'."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1233
1234 (defcustom gnus-treat-fill-article nil
1235 "Fill the article.
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate. See Info node `(gnus)Customizing Articles'."
1238 :group 'gnus-article-treat
1239 :link '(custom-manual "(gnus)Customizing Articles")
1240 :type gnus-article-treat-custom)
1241
1242 (defcustom gnus-treat-hide-citation nil
1243 "Hide cited text.
1244 Valid values are nil, t, `head', `first', `last', an integer or a
1245 predicate. See Info node `(gnus)Customizing Articles'.
1246
1247 See `gnus-article-highlight-citation' for variables used to
1248 control what it hides."
1249 :group 'gnus-article-treat
1250 :link '(custom-manual "(gnus)Customizing Articles")
1251 :type gnus-article-treat-custom)
1252
1253 (defcustom gnus-treat-hide-citation-maybe nil
1254 "Hide cited text according to certain conditions.
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'.
1257
1258 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1259 how to control what it hides."
1260 :group 'gnus-article-treat
1261 :link '(custom-manual "(gnus)Customizing Articles")
1262 :type gnus-article-treat-custom)
1263
1264 (defcustom gnus-treat-strip-list-identifiers 'head
1265 "Strip list identifiers from `gnus-list-identifiers'.
1266 Valid values are nil, t, `head', `first', `last', an integer or a
1267 predicate. See Info node `(gnus)Customizing Articles'."
1268 :version "21.1"
1269 :group 'gnus-article-treat
1270 :link '(custom-manual "(gnus)Customizing Articles")
1271 :type gnus-article-treat-custom)
1272
1273 (gnus-define-group-parameter
1274 list-identifier
1275 :variable-document
1276 "Alist of regexps and correspondent identifiers."
1277 :variable-group gnus-article-washing
1278 :parameter-type
1279 '(choice :tag "Identifier"
1280 :value nil
1281 (symbol :tag "Item in `gnus-list-identifiers'" none)
1282 regexp
1283 (const :tag "None" nil))
1284 :parameter-document
1285 "If non-nil, specify how to remove `identifiers' from articles' subject.
1286
1287 Any symbol is used to look up a regular expression to match the
1288 banner in `gnus-list-identifiers'. A string is used as a regular
1289 expression to match the identifier directly.")
1290
1291 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1292 "Gnus 5.10 (Emacs 22.1)")
1293
1294 (defcustom gnus-treat-strip-pem nil
1295 "Strip PEM signatures.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles'."
1298 :group 'gnus-article-treat
1299 :link '(custom-manual "(gnus)Customizing Articles")
1300 :type gnus-article-treat-custom)
1301
1302 (defcustom gnus-treat-strip-banner t
1303 "Strip banners from articles.
1304 The banner to be stripped is specified in the `banner' group parameter.
1305 Valid values are nil, t, `head', `first', `last', an integer or a
1306 predicate. See Info node `(gnus)Customizing Articles'."
1307 :group 'gnus-article-treat
1308 :link '(custom-manual "(gnus)Customizing Articles")
1309 :type gnus-article-treat-custom)
1310
1311 (defcustom gnus-treat-highlight-headers 'head
1312 "Highlight the headers.
1313 Valid values are nil, t, `head', `first', `last', an integer or a
1314 predicate. See Info node `(gnus)Customizing Articles'."
1315 :group 'gnus-article-treat
1316 :link '(custom-manual "(gnus)Customizing Articles")
1317 :type gnus-article-treat-head-custom)
1318 (put 'gnus-treat-highlight-headers 'highlight t)
1319
1320 (defcustom gnus-treat-highlight-citation t
1321 "Highlight cited text.
1322 Valid values are nil, t, `head', `first', `last', an integer or a
1323 predicate. See Info node `(gnus)Customizing Articles'."
1324 :group 'gnus-article-treat
1325 :link '(custom-manual "(gnus)Customizing Articles")
1326 :type gnus-article-treat-custom)
1327 (put 'gnus-treat-highlight-citation 'highlight t)
1328
1329 (defcustom gnus-treat-strip-headers-in-body t
1330 "Strip the X-No-Archive header line from the beginning of the body.
1331 Valid values are nil, t, `head', `first', `last', an integer or a
1332 predicate. See Info node `(gnus)Customizing Articles'."
1333 :version "21.1"
1334 :group 'gnus-article-treat
1335 :link '(custom-manual "(gnus)Customizing Articles")
1336 :type gnus-article-treat-custom)
1337
1338 (defcustom gnus-treat-strip-trailing-blank-lines nil
1339 "Strip trailing blank lines.
1340 Valid values are nil, t, `head', `first', `last', an integer or a
1341 predicate. See Info node `(gnus)Customizing Articles'.
1342
1343 When set to t, it also strips trailing blanks in all MIME parts.
1344 Consider to use `last' instead."
1345 :group 'gnus-article-treat
1346 :link '(custom-manual "(gnus)Customizing Articles")
1347 :type gnus-article-treat-custom)
1348
1349 (defcustom gnus-treat-strip-leading-blank-lines nil
1350 "Strip leading blank lines.
1351 Valid values are nil, t, `head', `first', `last', an integer or a
1352 predicate. See Info node `(gnus)Customizing Articles'.
1353
1354 When set to t, it also strips trailing blanks in all MIME parts."
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1358
1359 (defcustom gnus-treat-strip-multiple-blank-lines nil
1360 "Strip multiple blank lines.
1361 Valid values are nil, t, `head', `first', `last', an integer or a
1362 predicate. See Info node `(gnus)Customizing Articles'."
1363 :group 'gnus-article-treat
1364 :link '(custom-manual "(gnus)Customizing Articles")
1365 :type gnus-article-treat-custom)
1366
1367 (defcustom gnus-treat-unfold-headers 'head
1368 "Unfold folded header lines.
1369 Valid values are nil, t, `head', `first', `last', an integer or a
1370 predicate. See Info node `(gnus)Customizing Articles'."
1371 :version "22.1"
1372 :group 'gnus-article-treat
1373 :link '(custom-manual "(gnus)Customizing Articles")
1374 :type gnus-article-treat-custom)
1375
1376 (defcustom gnus-article-unfold-long-headers nil
1377 "If non-nil, allow unfolding headers even if the header is long.
1378 If it is a regexp, only long headers matching this regexp are unfolded.
1379 If it is t, all long headers are unfolded.
1380
1381 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1382 :version "23.1" ;; No Gnus
1383 :group 'gnus-article-treat
1384 :type '(choice (const nil)
1385 (const :tag "all" t)
1386 (regexp)))
1387
1388 (defcustom gnus-treat-fold-headers nil
1389 "Fold headers.
1390 Valid values are nil, t, `head', `first', `last', an integer or a
1391 predicate. See Info node `(gnus)Customizing Articles'."
1392 :version "22.1"
1393 :group 'gnus-article-treat
1394 :link '(custom-manual "(gnus)Customizing Articles")
1395 :type gnus-article-treat-custom)
1396
1397 (defcustom gnus-treat-fold-newsgroups 'head
1398 "Fold the Newsgroups and Followup-To headers.
1399 Valid values are nil, t, `head', `first', `last', an integer or a
1400 predicate. See Info node `(gnus)Customizing Articles'."
1401 :version "22.1"
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1405
1406 (defcustom gnus-treat-overstrike t
1407 "Treat overstrike highlighting.
1408 Valid values are nil, t, `head', `first', `last', an integer or a
1409 predicate. See Info node `(gnus)Customizing Articles'."
1410 :group 'gnus-article-treat
1411 :link '(custom-manual "(gnus)Customizing Articles")
1412 :type gnus-article-treat-custom)
1413 (put 'gnus-treat-overstrike 'highlight t)
1414
1415 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1416 "Treat ANSI SGR control sequences.
1417 Valid values are nil, t, `head', `first', `last', an integer or a
1418 predicate. See Info node `(gnus)Customizing Articles'."
1419 :group 'gnus-article-treat
1420 :link '(custom-manual "(gnus)Customizing Articles")
1421 :type gnus-article-treat-custom)
1422
1423 (make-obsolete-variable 'gnus-treat-display-xface
1424 'gnus-treat-display-x-face "Emacs 22.1")
1425
1426 (defcustom gnus-treat-display-x-face
1427 (and (not noninteractive)
1428 (gnus-image-type-available-p 'xbm)
1429 (if (featurep 'xemacs)
1430 (featurep 'xface)
1431 (condition-case nil
1432 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1433 (executable-find "icontopbm"))
1434 ;; shell-command-to-string may signal an error, e.g. if
1435 ;; shell-file-name is not found.
1436 (error nil)))
1437 'head)
1438 "Display X-Face headers.
1439 Valid values are nil and `head'.
1440 See Info node `(gnus)Customizing Articles' and Info node
1441 `(gnus)X-Face' for details."
1442 :group 'gnus-article-treat
1443 :version "21.1"
1444 :link '(custom-manual "(gnus)Customizing Articles")
1445 :link '(custom-manual "(gnus)X-Face")
1446 :type gnus-article-treat-head-custom
1447 :set (lambda (symbol value)
1448 (set-default
1449 symbol
1450 (cond ((or (boundp symbol) (get symbol 'saved-value))
1451 value)
1452 ((boundp 'gnus-treat-display-xface)
1453 (message "\
1454 ** gnus-treat-display-xface is an obsolete variable;\
1455 use gnus-treat-display-x-face instead")
1456 (default-value 'gnus-treat-display-xface))
1457 ((get 'gnus-treat-display-xface 'saved-value)
1458 (message "\
1459 ** gnus-treat-display-xface is an obsolete variable;\
1460 use gnus-treat-display-x-face instead")
1461 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1462 (t
1463 value)))))
1464 (put 'gnus-treat-display-x-face 'highlight t)
1465
1466 (defcustom gnus-treat-display-face
1467 (and (not noninteractive)
1468 (gnus-image-type-available-p 'png)
1469 'head)
1470 "Display Face headers.
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)Face' for details."
1474 :group 'gnus-article-treat
1475 :version "22.1"
1476 :link '(custom-manual "(gnus)Customizing Articles")
1477 :link '(custom-manual "(gnus)X-Face")
1478 :type gnus-article-treat-head-custom)
1479 (put 'gnus-treat-display-face 'highlight t)
1480
1481 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1482 "Display smileys.
1483 Valid values are nil, t, `head', `first', `last', an integer or a
1484 predicate. See Info node `(gnus)Customizing Articles' and Info
1485 node `(gnus)Smileys' for details."
1486 :group 'gnus-article-treat
1487 :version "21.1"
1488 :link '(custom-manual "(gnus)Customizing Articles")
1489 :link '(custom-manual "(gnus)Smileys")
1490 :type gnus-article-treat-custom)
1491 (put 'gnus-treat-display-smileys 'highlight t)
1492
1493 (defcustom gnus-treat-from-picon
1494 (if (and (gnus-image-type-available-p 'xpm)
1495 (gnus-picons-installed-p))
1496 'head nil)
1497 "Display picons in the From header.
1498 Valid values are nil, t, `head', `first', `last', an integer or a
1499 predicate. See Info node `(gnus)Customizing Articles' and Info
1500 node `(gnus)Picons' for details."
1501 :version "22.1"
1502 :group 'gnus-article-treat
1503 :group 'gnus-picon
1504 :link '(custom-manual "(gnus)Customizing Articles")
1505 :link '(custom-manual "(gnus)Picons")
1506 :type gnus-article-treat-head-custom)
1507 (put 'gnus-treat-from-picon 'highlight t)
1508
1509 (defcustom gnus-treat-mail-picon
1510 (if (and (gnus-image-type-available-p 'xpm)
1511 (gnus-picons-installed-p))
1512 'head nil)
1513 "Display picons in To and Cc headers.
1514 Valid values are nil, t, `head', `first', `last', an integer or a
1515 predicate. See Info node `(gnus)Customizing Articles' and Info
1516 node `(gnus)Picons' for details."
1517 :version "22.1"
1518 :group 'gnus-article-treat
1519 :group 'gnus-picon
1520 :link '(custom-manual "(gnus)Customizing Articles")
1521 :link '(custom-manual "(gnus)Picons")
1522 :type gnus-article-treat-head-custom)
1523 (put 'gnus-treat-mail-picon 'highlight t)
1524
1525 (defcustom gnus-treat-newsgroups-picon
1526 (if (and (gnus-image-type-available-p 'xpm)
1527 (gnus-picons-installed-p))
1528 'head nil)
1529 "Display picons in the Newsgroups and Followup-To headers.
1530 Valid values are nil, t, `head', `first', `last', an integer or a
1531 predicate. See Info node `(gnus)Customizing Articles' and Info
1532 node `(gnus)Picons' for details."
1533 :version "22.1"
1534 :group 'gnus-article-treat
1535 :group 'gnus-picon
1536 :link '(custom-manual "(gnus)Customizing Articles")
1537 :link '(custom-manual "(gnus)Picons")
1538 :type gnus-article-treat-head-custom)
1539 (put 'gnus-treat-newsgroups-picon 'highlight t)
1540
1541 (defcustom gnus-treat-from-gravatar nil
1542 "Display gravatars in the From header.
1543 Valid values are nil, t, `head', `first', `last', an integer or a
1544 predicate. See Info node `(gnus)Customizing Articles' and Info
1545 node `(gnus)Gravatars' for details."
1546 :version "24.1"
1547 :group 'gnus-article-treat
1548 :group 'gnus-gravatar
1549 :link '(custom-manual "(gnus)Customizing Articles")
1550 :link '(custom-manual "(gnus)Gravatars")
1551 :type gnus-article-treat-head-custom)
1552 (put 'gnus-treat-from-gravatar 'highlight t)
1553
1554 (defcustom gnus-treat-mail-gravatar nil
1555 "Display gravatars in To and Cc headers.
1556 Valid values are nil, t, `head', `first', `last', an integer or a
1557 predicate. See Info node `(gnus)Customizing Articles' and Info
1558 node `(gnus)Gravatars' for details."
1559 :version "24.1"
1560 :group 'gnus-article-treat
1561 :group 'gnus-gravatar
1562 :link '(custom-manual "(gnus)Customizing Articles")
1563 :link '(custom-manual "(gnus)Gravatars")
1564 :type gnus-article-treat-head-custom)
1565 (put 'gnus-treat-mail-gravatar 'highlight t)
1566
1567 (defcustom gnus-treat-body-boundary
1568 (if (or gnus-treat-newsgroups-picon
1569 gnus-treat-mail-picon
1570 gnus-treat-from-picon
1571 gnus-treat-from-gravatar
1572 gnus-treat-mail-gravatar)
1573 ;; If there's much decoration, the user might prefer a boundary.
1574 'head
1575 nil)
1576 "Draw a boundary at the end of the headers.
1577 Valid values are nil and `head'.
1578 See Info node `(gnus)Customizing Articles' for details."
1579 :version "22.1"
1580 :group 'gnus-article-treat
1581 :link '(custom-manual "(gnus)Customizing Articles")
1582 :type gnus-article-treat-head-custom)
1583
1584 (defcustom gnus-treat-capitalize-sentences nil
1585 "Capitalize sentence-starting words.
1586 Valid values are nil, t, `head', `first', `last', an integer or a
1587 predicate. See Info node `(gnus)Customizing Articles'."
1588 :version "21.1"
1589 :group 'gnus-article-treat
1590 :link '(custom-manual "(gnus)Customizing Articles")
1591 :type gnus-article-treat-custom)
1592
1593 (defcustom gnus-treat-wash-html nil
1594 "Format as HTML.
1595 Valid values are nil, t, `head', `first', `last', an integer or a
1596 predicate. See Info node `(gnus)Customizing Articles'."
1597 :version "22.1"
1598 :group 'gnus-article-treat
1599 :link '(custom-manual "(gnus)Customizing Articles")
1600 :type gnus-article-treat-custom)
1601
1602 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1603 "Fill long lines.
1604 Valid values are nil, t, `head', `first', `last', an integer or a
1605 predicate. See Info node `(gnus)Customizing Articles'."
1606 :version "24.1"
1607 :group 'gnus-article-treat
1608 :link '(custom-manual "(gnus)Customizing Articles")
1609 :type gnus-article-treat-custom)
1610
1611 (defcustom gnus-treat-x-pgp-sig nil
1612 "Verify X-PGP-Sig.
1613 To automatically treat X-PGP-Sig, set it to head.
1614 Valid values are nil, t, `head', `first', `last', an integer or a
1615 predicate. See Info node `(gnus)Customizing Articles'."
1616 :version "22.1"
1617 :group 'gnus-article-treat
1618 :group 'mime-security
1619 :link '(custom-manual "(gnus)Customizing Articles")
1620 :type gnus-article-treat-custom)
1621
1622 (defvar gnus-article-encrypt-protocol-alist
1623 '(("PGP" . mml2015-self-encrypt)))
1624
1625 ;; Set to nil if more than one protocol added to
1626 ;; gnus-article-encrypt-protocol-alist.
1627 (defcustom gnus-article-encrypt-protocol "PGP"
1628 "The protocol used for encrypt articles.
1629 It is a string, such as \"PGP\". If nil, ask user."
1630 :version "22.1"
1631 :type 'string
1632 :group 'mime-security)
1633
1634 (defvar idna-program)
1635
1636 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1637 (condition-case nil
1638 (require 'idna)
1639 (file-error)
1640 (invalid-operation))
1641 idna-program
1642 (executable-find idna-program))
1643 "Whether IDNA decoding of headers is used when viewing messages.
1644 This requires GNU Libidn, and by default only enabled if it is found."
1645 :version "22.1"
1646 :group 'gnus-article-headers
1647 :type 'boolean)
1648
1649 (defcustom gnus-article-over-scroll nil
1650 "If non-nil, allow scrolling the article buffer even when there no more text."
1651 :version "22.1"
1652 :group 'gnus-article
1653 :type 'boolean)
1654
1655 (defcustom gnus-inhibit-images nil
1656 "Non-nil means inhibit displaying of images inline in the article body."
1657 :version "24.1"
1658 :group 'gnus-article
1659 :type 'boolean)
1660
1661 (defcustom gnus-blocked-images 'gnus-block-private-groups
1662 "Images that have URLs matching this regexp will be blocked.
1663 This can also be a function to be evaluated. If so, it will be
1664 called with the group name as the parameter, and should return a
1665 regexp."
1666 :version "24.1"
1667 :group 'gnus-art
1668 :type '(choice (const :tag "Allow all" nil)
1669 (regexp :tag "Regular expression")
1670 (function :tag "Use a function")))
1671
1672 ;;; Internal variables
1673
1674 (defvar gnus-english-month-names
1675 '("January" "February" "March" "April" "May" "June" "July" "August"
1676 "September" "October" "November" "December"))
1677
1678 (defvar article-goto-body-goes-to-point-min-p nil)
1679 (defvar gnus-article-wash-types nil)
1680 (defvar gnus-article-emphasis-alist nil)
1681 (defvar gnus-article-image-alist nil)
1682
1683 (defvar gnus-article-mime-handle-alist-1 nil)
1684 (defvar gnus-treatment-function-alist
1685 '((gnus-treat-strip-cr gnus-article-remove-cr)
1686 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1687 (gnus-treat-strip-banner gnus-article-strip-banner)
1688 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1689 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1690 (gnus-treat-buttonize gnus-article-add-buttons)
1691 (gnus-treat-fill-article gnus-article-fill-cited-article)
1692 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1693 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1694 (gnus-treat-display-x-face gnus-article-display-x-face)
1695 (gnus-treat-display-face gnus-article-display-face)
1696 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1697 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1698 (gnus-treat-hide-signature gnus-article-hide-signature)
1699 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1700 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1701 (gnus-treat-from-picon gnus-treat-from-picon)
1702 (gnus-treat-mail-picon gnus-treat-mail-picon)
1703 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1704 (gnus-treat-strip-pem gnus-article-hide-pem)
1705 (gnus-treat-date gnus-article-treat-date)
1706 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1707 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1708 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1709 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1710 (gnus-treat-strip-trailing-blank-lines
1711 gnus-article-remove-trailing-blank-lines)
1712 (gnus-treat-strip-leading-blank-lines
1713 gnus-article-strip-leading-blank-lines)
1714 (gnus-treat-strip-multiple-blank-lines
1715 gnus-article-strip-multiple-blank-lines)
1716 (gnus-treat-overstrike gnus-article-treat-overstrike)
1717 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1718 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1719 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1720 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1721 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1722 (gnus-treat-display-smileys gnus-treat-smiley)
1723 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1724 (gnus-treat-wash-html gnus-article-wash-html)
1725 (gnus-treat-emphasize gnus-article-emphasize)
1726 (gnus-treat-hide-citation gnus-article-hide-citation)
1727 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1728 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1729 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1730
1731 (defvar gnus-article-mime-handle-alist nil)
1732 (defvar article-lapsed-timer nil)
1733 (defvar gnus-article-current-summary nil)
1734
1735 (defvar gnus-article-mode-syntax-table
1736 (let ((table (copy-syntax-table text-mode-syntax-table)))
1737 ;; This causes the citation match run O(2^n).
1738 ;; (modify-syntax-entry ?- "w" table)
1739 (modify-syntax-entry ?> ")<" table)
1740 (modify-syntax-entry ?< "(>" table)
1741 ;; make M-. in article buffers work for `foo' strings
1742 (modify-syntax-entry ?' " " table)
1743 (modify-syntax-entry ?` " " table)
1744 table)
1745 "Syntax table used in article mode buffers.
1746 Initialized from `text-mode-syntax-table'.")
1747
1748 (defvar gnus-save-article-buffer nil)
1749
1750 (defvar gnus-number-of-articles-to-be-saved nil)
1751
1752 (defvar gnus-inhibit-hiding nil)
1753
1754 (defvar gnus-article-edit-mode nil)
1755
1756 ;;; Macros for dealing with the article buffer.
1757
1758 (defmacro gnus-with-article-headers (&rest forms)
1759 `(with-current-buffer gnus-article-buffer
1760 (save-restriction
1761 (let ((inhibit-read-only t)
1762 (inhibit-point-motion-hooks t)
1763 (case-fold-search t))
1764 (article-narrow-to-head)
1765 ,@forms))))
1766
1767 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1768 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1769
1770 (defmacro gnus-with-article-buffer (&rest forms)
1771 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1772 (with-current-buffer gnus-article-buffer
1773 (let ((inhibit-read-only t))
1774 ,@forms))))
1775
1776 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1777 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1778
1779 (defun gnus-article-goto-header (header)
1780 "Go to HEADER, which is a regular expression."
1781 (re-search-forward (concat "^\\(" header "\\):") nil t))
1782
1783 (defsubst gnus-article-hide-text (b e props)
1784 "Set text PROPS on the B to E region."
1785 (gnus-add-text-properties-when 'article-type nil b e props))
1786
1787 (defsubst gnus-article-unhide-text (b e)
1788 "Remove hidden text properties from region between B and E."
1789 (remove-text-properties b e gnus-hidden-properties))
1790
1791 (defun gnus-article-hide-text-type (b e type)
1792 "Hide text of TYPE between B and E."
1793 (gnus-add-wash-type type)
1794 (gnus-article-hide-text
1795 b e (cons 'article-type (cons type gnus-hidden-properties))))
1796
1797 (defun gnus-article-unhide-text-type (b e type)
1798 "Unhide text of TYPE between B and E."
1799 (gnus-delete-wash-type type)
1800 (remove-text-properties
1801 b e (cons 'article-type (cons type gnus-hidden-properties))))
1802
1803 (defun gnus-article-delete-text-of-type (type)
1804 "Delete text of TYPE in the current buffer."
1805 (save-excursion
1806 (let ((b (point-min)))
1807 (if (eq type 'multipart)
1808 ;; Remove MIME buttons associated with multipart/alternative parts.
1809 (progn
1810 (goto-char b)
1811 (while (if (get-text-property (point) 'gnus-part)
1812 (setq b (point))
1813 (when (setq b (next-single-property-change (point)
1814 'gnus-part))
1815 (goto-char b)
1816 t))
1817 (end-of-line)
1818 (skip-chars-forward "\n")
1819 (when (eq (get-text-property b 'article-type) 'multipart)
1820 (delete-region b (point)))))
1821 (while (setq b (text-property-any b (point-max) 'article-type type))
1822 (delete-region
1823 b (or (text-property-not-all b (point-max) 'article-type type)
1824 (point-max))))))))
1825
1826 (defun gnus-article-delete-invisible-text ()
1827 "Delete all invisible text in the current buffer."
1828 (save-excursion
1829 (let ((b (point-min)))
1830 (while (setq b (text-property-any b (point-max) 'invisible t))
1831 (delete-region
1832 b (or (text-property-not-all b (point-max) 'invisible t)
1833 (point-max)))))))
1834
1835 (defsubst gnus-article-header-rank ()
1836 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1837 (let ((list gnus-sorted-header-list)
1838 (i 1))
1839 (while list
1840 (if (looking-at (car list))
1841 (setq list nil)
1842 (setq list (cdr list))
1843 (incf i)))
1844 i))
1845
1846 (defun article-hide-headers (&optional _arg _delete)
1847 "Hide unwanted headers and possibly sort them as well."
1848 (interactive)
1849 ;; This function might be inhibited.
1850 (unless gnus-inhibit-hiding
1851 (let ((inhibit-read-only t)
1852 (case-fold-search t)
1853 (max (1+ (length gnus-sorted-header-list)))
1854 (inhibit-point-motion-hooks t)
1855 (cur (current-buffer))
1856 ignored visible beg)
1857 (save-excursion
1858 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1859 ;; group parameters, so we should go to the summary buffer.
1860 (when (prog1
1861 (condition-case nil
1862 (progn (set-buffer gnus-summary-buffer) t)
1863 (error nil))
1864 (setq ignored (when (not gnus-visible-headers)
1865 (cond ((stringp gnus-ignored-headers)
1866 gnus-ignored-headers)
1867 ((listp gnus-ignored-headers)
1868 (mapconcat 'identity
1869 gnus-ignored-headers
1870 "\\|"))))
1871 visible (cond ((stringp gnus-visible-headers)
1872 gnus-visible-headers)
1873 ((and gnus-visible-headers
1874 (listp gnus-visible-headers))
1875 (mapconcat 'identity
1876 gnus-visible-headers
1877 "\\|")))))
1878 (set-buffer cur))
1879 (save-restriction
1880 ;; First we narrow to just the headers.
1881 (article-narrow-to-head)
1882 ;; Hide any "From " lines at the beginning of (mail) articles.
1883 (while (looking-at "From ")
1884 (forward-line 1))
1885 (unless (bobp)
1886 (delete-region (point-min) (point)))
1887 ;; Then treat the rest of the header lines.
1888 ;; Then we use the two regular expressions
1889 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1890 ;; select which header lines is to remain visible in the
1891 ;; article buffer.
1892 (while (re-search-forward "^[^ \t:]*:" nil t)
1893 (beginning-of-line)
1894 ;; Mark the rank of the header.
1895 (put-text-property
1896 (point) (1+ (point)) 'message-rank
1897 (if (or (and visible (looking-at visible))
1898 (and ignored
1899 (not (looking-at ignored))))
1900 (gnus-article-header-rank)
1901 (+ 2 max)))
1902 (forward-line 1))
1903 (message-sort-headers-1)
1904 (when (setq beg (text-property-any
1905 (point-min) (point-max) 'message-rank (+ 2 max)))
1906 ;; We delete the unwanted headers.
1907 (gnus-add-wash-type 'headers)
1908 (add-text-properties (point-min) (+ 5 (point-min))
1909 '(article-type headers dummy-invisible t))
1910 (delete-region beg (point-max))))))))
1911
1912 (defun article-hide-boring-headers (&optional arg)
1913 "Toggle hiding of headers that aren't very interesting.
1914 If given a negative prefix, always show; if given a positive prefix,
1915 always hide."
1916 (interactive (gnus-article-hidden-arg))
1917 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1918 (not gnus-show-all-headers))
1919 (save-excursion
1920 (save-restriction
1921 (let ((inhibit-read-only t)
1922 (inhibit-point-motion-hooks t))
1923 (article-narrow-to-head)
1924 (dolist (elem gnus-boring-article-headers)
1925 (goto-char (point-min))
1926 (cond
1927 ;; Hide empty headers.
1928 ((eq elem 'empty)
1929 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1930 (forward-line -1)
1931 (gnus-article-hide-text-type
1932 (point-at-bol)
1933 (progn
1934 (end-of-line)
1935 (if (re-search-forward "^[^ \t]" nil t)
1936 (match-beginning 0)
1937 (point-max)))
1938 'boring-headers)))
1939 ;; Hide boring Newsgroups header.
1940 ((eq elem 'newsgroups)
1941 (when (gnus-string-equal
1942 (gnus-fetch-field "newsgroups")
1943 (gnus-group-real-name
1944 (if (boundp 'gnus-newsgroup-name)
1945 gnus-newsgroup-name
1946 "")))
1947 (gnus-article-hide-header "newsgroups")))
1948 ((eq elem 'to-address)
1949 (let ((to (message-fetch-field "to"))
1950 (to-address
1951 (gnus-parameter-to-address
1952 (if (boundp 'gnus-newsgroup-name)
1953 gnus-newsgroup-name ""))))
1954 (when (and to to-address
1955 (ignore-errors
1956 (gnus-string-equal
1957 ;; only one address in To
1958 (nth 1 (mail-extract-address-components to))
1959 to-address)))
1960 (gnus-article-hide-header "to"))))
1961 ((eq elem 'to-list)
1962 (let ((to (message-fetch-field "to"))
1963 (to-list
1964 (gnus-parameter-to-list
1965 (if (boundp 'gnus-newsgroup-name)
1966 gnus-newsgroup-name ""))))
1967 (when (and to to-list
1968 (ignore-errors
1969 (gnus-string-equal
1970 ;; only one address in To
1971 (nth 1 (mail-extract-address-components to))
1972 to-list)))
1973 (gnus-article-hide-header "to"))))
1974 ((eq elem 'cc-list)
1975 (let ((cc (message-fetch-field "cc"))
1976 (to-list
1977 (gnus-parameter-to-list
1978 (if (boundp 'gnus-newsgroup-name)
1979 gnus-newsgroup-name ""))))
1980 (when (and cc to-list
1981 (ignore-errors
1982 (gnus-string-equal
1983 ;; only one address in CC
1984 (nth 1 (mail-extract-address-components cc))
1985 to-list)))
1986 (gnus-article-hide-header "cc"))))
1987 ((eq elem 'followup-to)
1988 (when (gnus-string-equal
1989 (message-fetch-field "followup-to")
1990 (message-fetch-field "newsgroups"))
1991 (gnus-article-hide-header "followup-to")))
1992 ((eq elem 'reply-to)
1993 (if (gnus-group-find-parameter
1994 gnus-newsgroup-name 'broken-reply-to)
1995 (gnus-article-hide-header "reply-to")
1996 (let ((from (message-fetch-field "from"))
1997 (reply-to (message-fetch-field "reply-to")))
1998 (when
1999 (and
2000 from reply-to
2001 (ignore-errors
2002 (equal
2003 (sort (mapcar
2004 (lambda (x) (downcase (cadr x)))
2005 (mail-extract-address-components from t))
2006 'string<)
2007 (sort (mapcar
2008 (lambda (x) (downcase (cadr x)))
2009 (mail-extract-address-components reply-to t))
2010 'string<))))
2011 (gnus-article-hide-header "reply-to")))))
2012 ((eq elem 'date)
2013 (let ((date (with-current-buffer gnus-original-article-buffer
2014 ;; If date in `gnus-article-buffer' is localized
2015 ;; (`gnus-treat-date-user-defined'),
2016 ;; `days-between' might fail.
2017 (message-fetch-field "date"))))
2018 (when (and date
2019 (< (days-between (current-time-string) date)
2020 4))
2021 (gnus-article-hide-header "date"))))
2022 ((eq elem 'long-to)
2023 (let ((to (message-fetch-field "to"))
2024 (cc (message-fetch-field "cc")))
2025 (when (> (length to) 1024)
2026 (gnus-article-hide-header "to"))
2027 (when (> (length cc) 1024)
2028 (gnus-article-hide-header "cc"))))
2029 ((eq elem 'many-to)
2030 (let ((to-count 0)
2031 (cc-count 0))
2032 (goto-char (point-min))
2033 (while (re-search-forward "^to:" nil t)
2034 (setq to-count (1+ to-count)))
2035 (when (> to-count 1)
2036 (while (> to-count 0)
2037 (goto-char (point-min))
2038 (save-restriction
2039 (re-search-forward "^to:" nil nil to-count)
2040 (forward-line -1)
2041 (narrow-to-region (point) (point-max))
2042 (gnus-article-hide-header "to"))
2043 (setq to-count (1- to-count))))
2044 (goto-char (point-min))
2045 (while (re-search-forward "^cc:" nil t)
2046 (setq cc-count (1+ cc-count)))
2047 (when (> cc-count 1)
2048 (while (> cc-count 0)
2049 (goto-char (point-min))
2050 (save-restriction
2051 (re-search-forward "^cc:" nil nil cc-count)
2052 (forward-line -1)
2053 (narrow-to-region (point) (point-max))
2054 (gnus-article-hide-header "cc"))
2055 (setq cc-count (1- cc-count)))))))))))))
2056
2057 (defun gnus-article-hide-header (header)
2058 (save-excursion
2059 (goto-char (point-min))
2060 (when (re-search-forward (concat "^" header ":") nil t)
2061 (gnus-article-hide-text-type
2062 (point-at-bol)
2063 (progn
2064 (end-of-line)
2065 (if (re-search-forward "^[^ \t]" nil t)
2066 (match-beginning 0)
2067 (point-max)))
2068 'boring-headers))))
2069
2070 (defvar gnus-article-normalized-header-length 40
2071 "Length of normalized headers.")
2072
2073 (defun article-normalize-headers ()
2074 "Make all header lines 40 characters long."
2075 (interactive)
2076 (let ((inhibit-read-only t)
2077 column)
2078 (save-excursion
2079 (save-restriction
2080 (article-narrow-to-head)
2081 (while (not (eobp))
2082 (cond
2083 ((< (setq column (- (point-at-eol) (point)))
2084 gnus-article-normalized-header-length)
2085 (end-of-line)
2086 (insert (make-string
2087 (- gnus-article-normalized-header-length column)
2088 ? )))
2089 ((> column gnus-article-normalized-header-length)
2090 (gnus-put-text-property
2091 (progn
2092 (forward-char gnus-article-normalized-header-length)
2093 (point))
2094 (point-at-eol)
2095 'invisible t))
2096 (t
2097 ;; Do nothing.
2098 ))
2099 (forward-line 1))))))
2100
2101 (defun article-treat-dumbquotes ()
2102 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2103 Note that this function guesses whether a character is a sm*rtq**t* or
2104 not, so it should only be used interactively.
2105
2106 Sm*rtq**t*s are M****s***'s unilateral extension to the
2107 iso-8859-1 character map in an attempt to provide more quoting
2108 characters. If you see something like \\222 or \\264 where
2109 you're expecting some kind of apostrophe or quotation mark, then
2110 try this wash."
2111 (interactive)
2112 (article-translate-strings gnus-article-dumbquotes-map))
2113
2114 (defvar org-entities)
2115
2116 (defun article-treat-non-ascii ()
2117 "Translate many Unicode characters into their ASCII equivalents."
2118 (interactive)
2119 (require 'org-entities)
2120 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2121 (dolist (elem org-entities)
2122 (when (and (listp elem)
2123 (= (length (nth 6 elem)) 1))
2124 (if (featurep 'xemacs)
2125 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2126 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2127 (save-excursion
2128 (when (article-goto-body)
2129 (let ((inhibit-read-only t)
2130 replace props)
2131 (while (not (eobp))
2132 (if (not (setq replace (if (featurep 'xemacs)
2133 (get-char-table (following-char) table)
2134 (aref table (following-char)))))
2135 (forward-char 1)
2136 (if (prog1
2137 (setq props (text-properties-at (point)))
2138 (delete-char 1))
2139 (add-text-properties (point) (progn (insert replace) (point))
2140 props)
2141 (insert replace)))))))))
2142
2143 (defun article-translate-strings (map)
2144 "Translate all string in the body of the article according to MAP.
2145 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2146 (save-excursion
2147 (when (article-goto-body)
2148 (let ((inhibit-read-only t))
2149 (dolist (elem map)
2150 (let ((from (car elem))
2151 (to (cadr elem)))
2152 (save-excursion
2153 (if (stringp from)
2154 (while (search-forward from nil t)
2155 (replace-match to))
2156 (while (not (eobp))
2157 (if (eq (following-char) from)
2158 (progn
2159 (delete-char 1)
2160 (insert to))
2161 (forward-char 1)))))))))))
2162
2163 (defun article-treat-overstrike ()
2164 "Translate overstrikes into bold text."
2165 (interactive)
2166 (save-excursion
2167 (when (article-goto-body)
2168 (let ((inhibit-read-only t))
2169 (while (search-forward "\b" nil t)
2170 (let ((next (char-after))
2171 (previous (char-after (- (point) 2))))
2172 ;; We do the boldification/underlining by hiding the
2173 ;; overstrikes and putting the proper text property
2174 ;; on the letters.
2175 (cond
2176 ((eq next previous)
2177 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2178 (put-text-property (point) (1+ (point)) 'face 'bold))
2179 ((eq next ?_)
2180 (gnus-article-hide-text-type
2181 (1- (point)) (1+ (point)) 'overstrike)
2182 (put-text-property
2183 (- (point) 2) (1- (point)) 'face 'underline))
2184 ((eq previous ?_)
2185 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2186 (put-text-property
2187 (point) (1+ (point)) 'face 'underline)))))))))
2188
2189 (defun article-treat-ansi-sequences ()
2190 "Translate ANSI SGR control sequences into overlays or extents."
2191 (interactive)
2192 (save-excursion
2193 (when (article-goto-body)
2194 (let ((inhibit-read-only t))
2195 (ansi-color-apply-on-region (point) (point-max))))))
2196
2197 (defun gnus-article-treat-unfold-headers ()
2198 "Unfold folded message headers.
2199 Only the headers that fit into the current window width will be
2200 unfolded."
2201 (interactive)
2202 (gnus-with-article-headers
2203 (let (length)
2204 (while (not (eobp))
2205 (save-restriction
2206 (mail-header-narrow-to-field)
2207 (let* ((header (buffer-string))
2208 (unfoldable
2209 (or (equal gnus-article-unfold-long-headers t)
2210 (and (stringp gnus-article-unfold-long-headers)
2211 (string-match gnus-article-unfold-long-headers
2212 header)))))
2213 (with-temp-buffer
2214 (insert header)
2215 (goto-char (point-min))
2216 (while (re-search-forward "\n[\t ]" nil t)
2217 (replace-match " " t t)))
2218 (setq length (- (point-max) (point-min) 1))
2219 (when (or unfoldable
2220 (< length (window-width)))
2221 (while (re-search-forward "\n[\t ]" nil t)
2222 (replace-match " " t t))))
2223 (goto-char (point-max)))))))
2224
2225 (defun gnus-article-treat-fold-headers ()
2226 "Fold message headers."
2227 (interactive)
2228 (gnus-with-article-headers
2229 (while (not (eobp))
2230 (save-restriction
2231 (mail-header-narrow-to-field)
2232 (mail-header-fold-field)
2233 (goto-char (point-max))))))
2234
2235 (defun gnus-treat-smiley ()
2236 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2237 (interactive)
2238 (gnus-with-article-buffer
2239 (if (memq 'smiley gnus-article-wash-types)
2240 (gnus-delete-images 'smiley)
2241 (article-goto-body)
2242 (let ((images (smiley-region (point) (point-max))))
2243 (when images
2244 (gnus-add-wash-type 'smiley)
2245 (dolist (image images)
2246 (gnus-add-image 'smiley image)))))))
2247
2248 (defun gnus-article-remove-images ()
2249 "Remove all images from the article buffer."
2250 (interactive)
2251 (gnus-with-article-buffer
2252 (save-restriction
2253 (widen)
2254 (dolist (elem gnus-article-image-alist)
2255 (gnus-delete-images (car elem))))))
2256
2257 (autoload 'w3m-toggle-inline-images "w3m")
2258
2259 (defun gnus-article-show-images ()
2260 "Show any images that are in the HTML-rendered article buffer.
2261 This only works if the article in question is HTML."
2262 (interactive)
2263 (gnus-with-article-buffer
2264 (save-restriction
2265 (widen)
2266 (if (eq mm-text-html-renderer 'w3m)
2267 (w3m-toggle-inline-images)
2268 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2269 'image-displayer))
2270 (destructuring-bind (start end function) region
2271 (funcall function (get-text-property start 'image-url)
2272 start end)))))))
2273
2274 (defun gnus-article-treat-fold-newsgroups ()
2275 "Unfold folded message headers.
2276 Only the headers that fit into the current window width will be
2277 unfolded."
2278 (interactive)
2279 (gnus-with-article-headers
2280 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2281 (save-restriction
2282 (mail-header-narrow-to-field)
2283 (while (re-search-forward ", *" nil t)
2284 (replace-match ", " t t))
2285 (mail-header-fold-field)
2286 (goto-char (point-max))))))
2287
2288 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2289 "Value of `truncate-lines' in Gnus Article buffer.
2290 Valid values are nil, t, `head', `first', `last', an integer or a
2291 predicate. See Info node `(gnus)Customizing Articles'."
2292 :version "23.1" ;; No Gnus
2293 :group 'gnus-article
2294 ;; :link '(custom-manual "(gnus)Customizing Articles")
2295 :type 'boolean)
2296
2297 (defun gnus-article-toggle-truncate-lines (&optional arg)
2298 "Toggle whether to fold or truncate long lines in article the buffer.
2299 If ARG is non-nil and not a number, toggle
2300 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2301 long lines if and only if arg is positive."
2302 (interactive "P")
2303 (cond
2304 ((and (numberp arg) (> arg 0))
2305 (setq gnus-article-truncate-lines t))
2306 ((numberp arg)
2307 (setq gnus-article-truncate-lines nil))
2308 (arg
2309 (setq gnus-article-truncate-lines
2310 (not gnus-article-truncate-lines))))
2311 (gnus-with-article-buffer
2312 (cond
2313 ((and (numberp arg) (> arg 0))
2314 (setq truncate-lines nil))
2315 ((numberp arg)
2316 (setq truncate-lines t)))
2317 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2318 ;; `toggle-truncate-lines' needs an argument.
2319 (toggle-truncate-lines)))
2320
2321 (defun gnus-article-treat-body-boundary ()
2322 "Place a boundary line at the end of the headers."
2323 (interactive)
2324 (when (and gnus-body-boundary-delimiter
2325 (> (length gnus-body-boundary-delimiter) 0))
2326 (gnus-with-article-headers
2327 (goto-char (point-max))
2328 (let ((start (point)))
2329 (insert "X-Boundary: ")
2330 (gnus-add-text-properties start (point) gnus-hidden-properties)
2331 (insert (let (str (max (window-width)))
2332 (if (featurep 'xemacs)
2333 (setq max (1- max)))
2334 (while (>= max (length str))
2335 (setq str (concat str gnus-body-boundary-delimiter)))
2336 (substring str 0 max))
2337 "\n")
2338 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2339
2340 (defun article-fill-long-lines ()
2341 "Fill lines that are wider than the window width."
2342 (interactive)
2343 (save-excursion
2344 (let ((inhibit-read-only t)
2345 (width (window-width (get-buffer-window (current-buffer)))))
2346 (save-restriction
2347 (article-goto-body)
2348 (let ((adaptive-fill-mode nil)) ;Why? -sm
2349 (while (not (eobp))
2350 (end-of-line)
2351 (when (>= (current-column) (min fill-column width))
2352 (narrow-to-region (min (1+ (point)) (point-max))
2353 (point-at-bol))
2354 (let ((goback (point-marker)))
2355 (fill-paragraph nil)
2356 (goto-char (marker-position goback)))
2357 (widen))
2358 (forward-line 1)))))))
2359
2360 (defun article-capitalize-sentences ()
2361 "Capitalize the first word in each sentence."
2362 (interactive)
2363 (save-excursion
2364 (let ((inhibit-read-only t)
2365 (paragraph-start "^[\n\^L]"))
2366 (article-goto-body)
2367 (while (not (eobp))
2368 (capitalize-word 1)
2369 (forward-sentence)))))
2370
2371 (defun article-remove-cr ()
2372 "Remove trailing CRs and then translate remaining CRs into LFs."
2373 (interactive)
2374 (save-excursion
2375 (let ((inhibit-read-only t))
2376 (goto-char (point-min))
2377 (while (re-search-forward "\r+$" nil t)
2378 (replace-match "" t t))
2379 (goto-char (point-min))
2380 (while (search-forward "\r" nil t)
2381 (replace-match "\n" t t)))))
2382
2383 (defun article-remove-trailing-blank-lines ()
2384 "Remove all trailing blank lines from the article."
2385 (interactive)
2386 (save-excursion
2387 (let ((inhibit-read-only t))
2388 (goto-char (point-max))
2389 (delete-region
2390 (point)
2391 (progn
2392 (while (and (not (bobp))
2393 (looking-at "^[ \t]*$")
2394 (not (gnus-annotation-in-region-p
2395 (point) (point-at-eol))))
2396 (forward-line -1))
2397 (forward-line 1)
2398 (point))))))
2399
2400 (defvar gnus-face-properties-alist)
2401
2402 (defun article-display-face (&optional force)
2403 "Display any Face headers in the header."
2404 (interactive (list 'force))
2405 (let ((wash-face-p buffer-read-only))
2406 (gnus-with-article-headers
2407 ;; When displaying parts, this function can be called several times on
2408 ;; the same article, without any intended toggle semantic (as typing `W
2409 ;; D d' would have). So face deletion must occur only when we come from
2410 ;; an interactive command, that is when the *Article* buffer is
2411 ;; read-only.
2412 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2413 (gnus-delete-images 'face)
2414 (let ((from (message-fetch-field "from"))
2415 faces)
2416 (save-current-buffer
2417 (when (and wash-face-p
2418 (gnus-buffer-live-p gnus-original-article-buffer)
2419 (not (re-search-forward "^Face:[\t ]*" nil t)))
2420 (set-buffer gnus-original-article-buffer))
2421 (save-restriction
2422 (mail-narrow-to-head)
2423 (when (or force
2424 ;; Check whether this face is censored.
2425 (not (and gnus-article-x-face-too-ugly
2426 (or from
2427 (setq from (message-fetch-field "from")))
2428 (string-match gnus-article-x-face-too-ugly
2429 from))))
2430 (while (gnus-article-goto-header "Face")
2431 (push (mail-header-field-value) faces)))))
2432 (when faces
2433 (goto-char (point-min))
2434 (let (png image)
2435 (unless (setq from (gnus-article-goto-header "from"))
2436 (insert "From:")
2437 (setq from (point))
2438 (insert " [no 'from' set]\n"))
2439 (while faces
2440 (when (setq png (gnus-convert-face-to-png (pop faces)))
2441 (setq image
2442 (apply 'gnus-create-image png 'png t
2443 (cdr (assq 'png gnus-face-properties-alist))))
2444 (goto-char from)
2445 (when image
2446 (gnus-add-wash-type 'face)
2447 (gnus-add-image 'face image)
2448 (gnus-put-image image nil 'face)))))))))))
2449
2450 (defun article-display-x-face (&optional force)
2451 "Look for an X-Face header and display it if present."
2452 (interactive (list 'force))
2453 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2454 (gnus-with-article-headers
2455 ;; Delete the old process, if any.
2456 (when (process-status "article-x-face")
2457 (delete-process "article-x-face"))
2458 ;; See the comment in `article-display-face'.
2459 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2460 ;; We have already displayed X-Faces, so we remove them
2461 ;; instead.
2462 (gnus-delete-images 'xface)
2463 ;; Display X-Faces.
2464 (let ((from (message-fetch-field "from"))
2465 x-faces)
2466 (save-current-buffer
2467 (when (and wash-face-p
2468 (gnus-buffer-live-p gnus-original-article-buffer)
2469 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2470 ;; If type `W f', use gnus-original-article-buffer,
2471 ;; otherwise use the current buffer because displaying
2472 ;; RFC822 parts calls this function too.
2473 (set-buffer gnus-original-article-buffer))
2474 (save-restriction
2475 (mail-narrow-to-head)
2476 (and gnus-article-x-face-command
2477 (or force
2478 ;; Check whether this face is censored.
2479 (not (and gnus-article-x-face-too-ugly
2480 (or from
2481 (setq from (message-fetch-field "from")))
2482 (string-match gnus-article-x-face-too-ugly
2483 from))))
2484 (while (gnus-article-goto-header "X-Face")
2485 (push (mail-header-field-value) x-faces)))))
2486 (when x-faces
2487 ;; We display the face.
2488 (cond ((functionp gnus-article-x-face-command)
2489 ;; The command is a lisp function, so we call it.
2490 (mapc gnus-article-x-face-command x-faces))
2491 ((stringp gnus-article-x-face-command)
2492 ;; The command is a string, so we interpret the command
2493 ;; as a, well, command, and fork it off.
2494 (let ((process-connection-type nil))
2495 (gnus-set-process-query-on-exit-flag
2496 (start-process
2497 "article-x-face" nil shell-file-name
2498 shell-command-switch gnus-article-x-face-command)
2499 nil)
2500 ;; Sending multiple EOFs to xv doesn't work,
2501 ;; so we only do a single external face.
2502 (with-temp-buffer
2503 (insert (car x-faces))
2504 (process-send-region "article-x-face"
2505 (point-min) (point-max)))
2506 (process-send-eof "article-x-face")))
2507 (t
2508 (error "`%s' set to `%s' is not a function"
2509 gnus-article-x-face-command
2510 'gnus-article-x-face-command)))))))))
2511
2512 (defun article-decode-mime-words ()
2513 "Decode all MIME-encoded words in the article."
2514 (interactive)
2515 (gnus-with-article-buffer
2516 (let ((inhibit-point-motion-hooks t)
2517 (mail-parse-charset gnus-newsgroup-charset)
2518 (mail-parse-ignored-charsets
2519 (with-current-buffer gnus-summary-buffer
2520 gnus-newsgroup-ignored-charsets)))
2521 (mail-decode-encoded-word-region (point-min) (point-max)))))
2522
2523 (defun article-decode-charset (&optional prompt)
2524 "Decode charset-encoded text in the article.
2525 If PROMPT (the prefix), prompt for a coding system to use."
2526 (interactive "P")
2527 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2528 (inhibit-read-only t)
2529 (mail-parse-charset gnus-newsgroup-charset)
2530 (mail-parse-ignored-charsets
2531 (save-excursion (condition-case nil
2532 (set-buffer gnus-summary-buffer)
2533 (error))
2534 gnus-newsgroup-ignored-charsets))
2535 ct cte ctl charset format)
2536 (save-excursion
2537 (save-restriction
2538 (article-narrow-to-head)
2539 (setq ct (message-fetch-field "Content-Type" t)
2540 cte (message-fetch-field "Content-Transfer-Encoding" t)
2541 ctl (and ct (mail-header-parse-content-type ct))
2542 charset (cond
2543 (prompt
2544 (mm-read-coding-system "Charset to decode: "))
2545 (ctl
2546 (mail-content-type-get ctl 'charset)))
2547 format (and ctl (mail-content-type-get ctl 'format)))
2548 (when cte
2549 (setq cte (mail-header-strip cte)))
2550 (if (and ctl (not (string-match "/" (car ctl))))
2551 (setq ctl nil))
2552 (goto-char (point-max)))
2553 (forward-line 1)
2554 (save-restriction
2555 (narrow-to-region (point) (point-max))
2556 (when (and (eq mail-parse-charset 'gnus-decoded)
2557 (eq (mm-body-7-or-8) '8bit))
2558 ;; The text code could have been decoded.
2559 (setq charset mail-parse-charset))
2560 (when (and (or (not ctl)
2561 (equal (car ctl) "text/plain"))
2562 (not format)) ;; article with format will decode later.
2563 (mm-decode-body
2564 charset (and cte (intern (downcase
2565 (gnus-strip-whitespace cte))))
2566 (car ctl)))))))
2567
2568 (defun article-decode-encoded-words ()
2569 "Remove encoded-word encoding from headers."
2570 (let ((inhibit-point-motion-hooks t)
2571 (mail-parse-charset gnus-newsgroup-charset)
2572 (mail-parse-ignored-charsets
2573 (save-excursion (condition-case nil
2574 (set-buffer gnus-summary-buffer)
2575 (error))
2576 gnus-newsgroup-ignored-charsets))
2577 (inhibit-read-only t)
2578 end start)
2579 (goto-char (point-min))
2580 (when (search-forward "\n\n" nil 'move)
2581 (forward-line -1))
2582 (setq end (point))
2583 (while (not (bobp))
2584 (while (progn
2585 (forward-line -1)
2586 (and (not (bobp))
2587 (memq (char-after) '(?\t ? )))))
2588 (setq start (point))
2589 (if (looking-at "\
2590 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2591 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2592 (funcall gnus-decode-address-function start end)
2593 (funcall gnus-decode-header-function start end))
2594 (goto-char (setq end start)))))
2595
2596 (defun article-decode-group-name ()
2597 "Decode group names in Newsgroups, Followup-To and Xref headers."
2598 (let ((inhibit-point-motion-hooks t)
2599 (inhibit-read-only t)
2600 (method (gnus-find-method-for-group gnus-newsgroup-name))
2601 regexp)
2602 (when (and (or gnus-group-name-charset-method-alist
2603 gnus-group-name-charset-group-alist)
2604 (gnus-buffer-live-p gnus-original-article-buffer))
2605 (save-restriction
2606 (article-narrow-to-head)
2607 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2608 (with-current-buffer gnus-original-article-buffer
2609 (goto-char (point-min)))
2610 (setq regexp (concat "^" header
2611 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2612 (while (re-search-forward regexp nil t)
2613 (replace-match (save-match-data
2614 (gnus-decode-newsgroups
2615 ;; XXX how to use data in article buffer?
2616 (with-current-buffer gnus-original-article-buffer
2617 (re-search-forward regexp nil t)
2618 (match-string 1))
2619 gnus-newsgroup-name method))
2620 t t nil 1))
2621 (goto-char (point-min)))))))
2622
2623 (autoload 'idna-to-unicode "idna")
2624
2625 (defun article-decode-idna-rhs ()
2626 "Decode IDNA strings in RHS in various headers in current buffer.
2627 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2628 Mail-Reply-To: and Mail-Followup-To:."
2629 (when gnus-use-idna
2630 (save-restriction
2631 (let ((inhibit-point-motion-hooks t)
2632 (inhibit-read-only t))
2633 (article-narrow-to-head)
2634 (goto-char (point-min))
2635 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2636 (let (ace unicode)
2637 (when (save-match-data
2638 (and (setq ace (match-string 1))
2639 (save-excursion
2640 (and (re-search-backward "^[^ \t]" nil t)
2641 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2642 (setq unicode (idna-to-unicode ace))))
2643 (unless (string= ace unicode)
2644 (replace-match unicode nil nil nil 1)))))))))
2645
2646 (defun article-de-quoted-unreadable (&optional force read-charset)
2647 "Translate a quoted-printable-encoded article.
2648 If FORCE, decode the article whether it is marked as quoted-printable
2649 or not.
2650 If READ-CHARSET, ask for a coding system."
2651 (interactive (list 'force current-prefix-arg))
2652 (save-excursion
2653 (let ((inhibit-read-only t) type charset)
2654 (if (gnus-buffer-live-p gnus-original-article-buffer)
2655 (with-current-buffer gnus-original-article-buffer
2656 (setq type
2657 (gnus-fetch-field "content-transfer-encoding"))
2658 (let* ((ct (gnus-fetch-field "content-type"))
2659 (ctl (and ct (mail-header-parse-content-type ct))))
2660 (setq charset (and ctl
2661 (mail-content-type-get ctl 'charset)))
2662 (if (stringp charset)
2663 (setq charset (intern (downcase charset)))))))
2664 (if read-charset
2665 (setq charset (mm-read-coding-system "Charset: " charset)))
2666 (unless charset
2667 (setq charset gnus-newsgroup-charset))
2668 (when (or force
2669 (and type (let ((case-fold-search t))
2670 (string-match "quoted-printable" type))))
2671 (article-goto-body)
2672 (quoted-printable-decode-region
2673 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2674
2675 (defun article-de-base64-unreadable (&optional force read-charset)
2676 "Translate a base64 article.
2677 If FORCE, decode the article whether it is marked as base64 not.
2678 If READ-CHARSET, ask for a coding system."
2679 (interactive (list 'force current-prefix-arg))
2680 (save-excursion
2681 (let ((inhibit-read-only t) type charset)
2682 (if (gnus-buffer-live-p gnus-original-article-buffer)
2683 (with-current-buffer gnus-original-article-buffer
2684 (setq type
2685 (gnus-fetch-field "content-transfer-encoding"))
2686 (let* ((ct (gnus-fetch-field "content-type"))
2687 (ctl (and ct (mail-header-parse-content-type ct))))
2688 (setq charset (and ctl
2689 (mail-content-type-get ctl 'charset)))
2690 (if (stringp charset)
2691 (setq charset (intern (downcase charset)))))))
2692 (if read-charset
2693 (setq charset (mm-read-coding-system "Charset: " charset)))
2694 (unless charset
2695 (setq charset gnus-newsgroup-charset))
2696 (when (or force
2697 (and type (let ((case-fold-search t))
2698 (string-match "base64" type))))
2699 (article-goto-body)
2700 (save-restriction
2701 (narrow-to-region (point) (point-max))
2702 (base64-decode-region (point-min) (point-max))
2703 (mm-decode-coding-region
2704 (point-min) (point-max)
2705 (mm-charset-to-coding-system charset nil t)))))))
2706
2707 (eval-when-compile
2708 (require 'rfc1843))
2709
2710 (defun article-decode-HZ ()
2711 "Translate a HZ-encoded article."
2712 (interactive)
2713 (require 'rfc1843)
2714 (save-excursion
2715 (let ((inhibit-read-only t))
2716 (rfc1843-decode-region (point-min) (point-max)))))
2717
2718 (defun article-unsplit-urls ()
2719 "Remove the newlines that some other mailers insert into URLs."
2720 (interactive)
2721 (save-excursion
2722 (let ((inhibit-read-only t))
2723 (goto-char (point-min))
2724 (while (re-search-forward
2725 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2726 (replace-match "\\1\\3" t)))
2727 (when (gmm-called-interactively-p 'any)
2728 (gnus-treat-article nil))))
2729
2730 (defun article-wash-html ()
2731 "Format an HTML article."
2732 (interactive)
2733 (let ((handles nil)
2734 (buffer-read-only nil))
2735 (when (gnus-buffer-live-p gnus-original-article-buffer)
2736 (with-current-buffer gnus-original-article-buffer
2737 (setq handles (mm-dissect-buffer t t))))
2738 (article-goto-body)
2739 (delete-region (point) (point-max))
2740 (mm-enable-multibyte)
2741 (mm-inline-text-html handles)))
2742
2743 (defvar gnus-article-browse-html-temp-list nil
2744 "List of temporary files created by `gnus-article-browse-html-parts'.
2745 Internal variable.")
2746
2747 (defcustom gnus-article-browse-delete-temp 'ask
2748 "What to do with temporary files from `gnus-article-browse-html-parts'.
2749 If nil, don't delete temporary files. If it is t, delete them on
2750 exit from the summary buffer. If it is the symbol `file', query
2751 on each file, if it is `ask' ask once when exiting from the
2752 summary buffer."
2753 :group 'gnus-article
2754 :version "23.1" ;; No Gnus
2755 :type '(choice (const :tag "Don't delete" nil)
2756 (const :tag "Don't ask" t)
2757 (const :tag "Ask" ask)
2758 (const :tag "Ask for each file" file)))
2759
2760 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2761
2762 (defun gnus-article-browse-delete-temp-files (&optional how)
2763 "Delete temp-files created by `gnus-article-browse-html-parts'."
2764 (when (and gnus-article-browse-html-temp-list
2765 (progn
2766 (or how (setq how gnus-article-browse-delete-temp))
2767 (if (eq how 'ask)
2768 (let ((files (length gnus-article-browse-html-temp-list)))
2769 (or (gnus-y-or-n-p
2770 (if (= files 1)
2771 "Delete the temporary HTML file? "
2772 (format "Delete all %s temporary HTML files? "
2773 files)))
2774 (setq gnus-article-browse-html-temp-list nil)))
2775 how)))
2776 (dolist (file gnus-article-browse-html-temp-list)
2777 (cond ((file-directory-p file)
2778 (when (or (not (eq how 'file))
2779 (gnus-y-or-n-p
2780 (gnus-format-message
2781 "Delete temporary HTML file(s) in directory `%s'? "
2782 (file-name-as-directory file))))
2783 (gnus-delete-directory file)))
2784 ((file-exists-p file)
2785 (when (or (not (eq how 'file))
2786 (gnus-y-or-n-p
2787 (format "Delete temporary HTML file `%s'? " file)))
2788 (delete-file file)))))
2789 ;; Also remove file from the list when not deleted or if file doesn't
2790 ;; exist anymore.
2791 (setq gnus-article-browse-html-temp-list nil))
2792 gnus-article-browse-html-temp-list)
2793
2794 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2795 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2796 Return file name relative to the parent of DIRECTORY."
2797 (save-match-data
2798 (let (file afile)
2799 (catch 'found
2800 (dolist (handle handles)
2801 (cond
2802 ((not (listp handle)))
2803 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2804 ;; may create.
2805 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2806 ((equal (mm-handle-media-supertype handle) "multipart")
2807 (when (setq file (gnus-article-browse-html-save-cid-content
2808 cid handle directory))
2809 (throw 'found file)))
2810 ((equal (concat "<" cid ">") (mm-handle-id handle))
2811 (setq file (or (mm-handle-filename handle)
2812 (concat
2813 (make-temp-name "cid")
2814 (car (rassoc (car (mm-handle-type handle))
2815 mailcap-mime-extensions))))
2816 afile (expand-file-name file directory))
2817 (mm-save-part-to-file handle afile)
2818 (throw 'found (concat (file-name-nondirectory
2819 (directory-file-name directory))
2820 "/" file)))))))))
2821
2822 (defun gnus-article-browse-html-parts (list &optional header)
2823 "View all \"text/html\" parts from LIST.
2824 Recurse into multiparts. The optional HEADER that should be a decoded
2825 message header will be added to the bodies of the \"text/html\" parts."
2826 ;; Internal function used by `gnus-article-browse-html-article'.
2827 (let (type file charset content cid-dir tmp-file showed)
2828 ;; Find and show the html-parts.
2829 (dolist (handle list)
2830 ;; If HTML, show it:
2831 (cond ((not (listp handle)))
2832 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2833 (and (equal (car type) "message/external-body")
2834 (or header
2835 (setq file (mm-handle-filename handle)))
2836 (or (mm-handle-cache handle)
2837 (condition-case code
2838 (progn (mm-extern-cache-contents handle) t)
2839 (error
2840 (gnus-message 3 "%s" (error-message-string code))
2841 (when (>= gnus-verbose 3) (sit-for 2))
2842 nil)))
2843 (progn
2844 (setq handle (mm-handle-cache handle)
2845 type (mm-handle-type handle))
2846 (equal (car type) "text/html"))))
2847 (setq charset (mail-content-type-get type 'charset)
2848 content (mm-get-part handle))
2849 (with-temp-buffer
2850 (if (eq charset 'gnus-decoded)
2851 (mm-enable-multibyte)
2852 (mm-disable-multibyte))
2853 (insert content)
2854 ;; resolve cid contents
2855 (let ((case-fold-search t)
2856 st base regexp cid-file)
2857 (goto-char (point-min))
2858 (when (and (re-search-forward "<head[\t\n >]" nil t)
2859 (progn
2860 (setq st (match-end 0))
2861 (re-search-forward "</head[\t\n >]" nil t))
2862 (re-search-backward "<base\
2863 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2864 (setq base (match-string 1))
2865 (replace-match "<!--\\&-->")
2866 (setq st (point))
2867 (dolist (tag '(("a" . "href") ("form" . "action")
2868 ("img" . "src")))
2869 (setq regexp (concat "<" (car tag)
2870 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2871 (cdr tag) "=\"\\([^\"]+\\)"))
2872 (while (re-search-forward regexp nil t)
2873 (insert (prog1
2874 (condition-case nil
2875 (save-match-data
2876 (url-expand-file-name (match-string 1)
2877 base))
2878 (error (match-string 1)))
2879 (delete-region (match-beginning 1)
2880 (match-end 1)))))
2881 (goto-char st)))
2882 (while (re-search-forward "\
2883 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2884 nil t)
2885 (unless cid-dir
2886 (setq cid-dir (mm-make-temp-file "cid" t))
2887 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2888 (setq file nil
2889 content nil)
2890 (when (setq cid-file
2891 (gnus-article-browse-html-save-cid-content
2892 (match-string 2)
2893 (with-current-buffer gnus-article-buffer
2894 gnus-article-mime-handles)
2895 cid-dir))
2896 (replace-match cid-file nil nil nil 1))))
2897 (unless content (setq content (buffer-string))))
2898 (when (or charset header (not file))
2899 (setq tmp-file (mm-make-temp-file
2900 ;; Do we need to care for 8.3 filenames?
2901 "mm-" nil ".html")))
2902 ;; Add a meta html tag to specify charset and a header.
2903 (cond
2904 (header
2905 (let (title eheader body hcharset coding)
2906 (with-temp-buffer
2907 (mm-enable-multibyte)
2908 (setq case-fold-search t)
2909 (insert header "\n")
2910 (setq title (message-fetch-field "subject"))
2911 (goto-char (point-min))
2912 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2913 nil t)
2914 (replace-match (cond ((match-beginning 1) "&lt;")
2915 ((match-beginning 2) "&gt;")
2916 ((match-beginning 3) "&amp;")
2917 (t "<br>\n"))))
2918 (goto-char (point-min))
2919 (while (re-search-forward "^[\t ]+" nil t)
2920 (dotimes (i (prog1
2921 (current-column)
2922 (delete-region (match-beginning 0)
2923 (match-end 0))))
2924 (insert "&nbsp;")))
2925 (goto-char (point-min))
2926 (insert "<div align=\"left\">\n")
2927 (goto-char (point-max))
2928 (insert "</div>\n<hr>\n")
2929 ;; We have to examine charset one by one since
2930 ;; charset specified in parts might be different.
2931 (if (eq charset 'gnus-decoded)
2932 (setq charset 'utf-8
2933 eheader (mm-encode-coding-string (buffer-string)
2934 charset)
2935 title (when title
2936 (mm-encode-coding-string title charset))
2937 body (mm-encode-coding-string content charset))
2938 (setq hcharset (mm-find-mime-charset-region (point-min)
2939 (point-max)))
2940 (cond ((= (length hcharset) 1)
2941 (setq hcharset (car hcharset)
2942 coding (mm-charset-to-coding-system
2943 hcharset nil t)))
2944 ((> (length hcharset) 1)
2945 (setq hcharset 'utf-8
2946 coding hcharset)))
2947 (if coding
2948 (if charset
2949 (progn
2950 (setq body
2951 (mm-charset-to-coding-system charset
2952 nil t))
2953 (if (eq coding body)
2954 (setq eheader (mm-encode-coding-string
2955 (buffer-string) coding)
2956 title (when title
2957 (mm-encode-coding-string
2958 title coding))
2959 body content)
2960 (setq charset 'utf-8
2961 eheader (mm-encode-coding-string
2962 (buffer-string) charset)
2963 title (when title
2964 (mm-encode-coding-string
2965 title charset))
2966 body (mm-encode-coding-string
2967 (mm-decode-coding-string
2968 content body)
2969 charset))))
2970 (setq charset hcharset
2971 eheader (mm-encode-coding-string
2972 (buffer-string) coding)
2973 title (when title
2974 (mm-encode-coding-string
2975 title coding))
2976 body content))
2977 (setq eheader (mm-string-as-unibyte (buffer-string))
2978 body content)))
2979 (erase-buffer)
2980 (mm-disable-multibyte)
2981 (insert body)
2982 (when charset
2983 (mm-add-meta-html-tag handle charset t))
2984 (when title
2985 (goto-char (point-min))
2986 (unless (search-forward "<title>" nil t)
2987 (re-search-forward "<head>\\s-*" nil t)
2988 (insert "<title>" title "</title>\n")))
2989 (goto-char (point-min))
2990 (or (re-search-forward
2991 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2992 (re-search-forward
2993 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2994 (insert eheader)
2995 (mm-write-region (point-min) (point-max)
2996 tmp-file nil nil nil 'binary t))))
2997 (charset
2998 (mm-with-unibyte-buffer
2999 (insert (if (eq charset 'gnus-decoded)
3000 (mm-encode-coding-string content
3001 (setq charset 'utf-8))
3002 content))
3003 (if (or (mm-add-meta-html-tag handle charset)
3004 (not file))
3005 (mm-write-region (point-min) (point-max)
3006 tmp-file nil nil nil 'binary t)
3007 (setq tmp-file nil))))
3008 (tmp-file
3009 (mm-save-part-to-file handle tmp-file)))
3010 (when tmp-file
3011 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3012 (add-hook 'gnus-summary-prepare-exit-hook
3013 'gnus-article-browse-delete-temp-files)
3014 (add-hook 'gnus-exit-gnus-hook
3015 (lambda ()
3016 (gnus-article-browse-delete-temp-files t)))
3017 ;; FIXME: Warn if there's an <img> tag?
3018 (browse-url-of-file (or tmp-file (expand-file-name file)))
3019 (setq showed t))
3020 ;; If multipart, recurse
3021 ((equal (mm-handle-media-supertype handle) "multipart")
3022 (when (gnus-article-browse-html-parts handle header)
3023 (setq showed t)))
3024 ((equal (mm-handle-media-type handle) "message/rfc822")
3025 (mm-with-multibyte-buffer
3026 (mm-insert-part handle)
3027 (setq handle (mm-dissect-buffer t t))
3028 (when (and (bufferp (car handle))
3029 (stringp (car (mm-handle-type handle))))
3030 (setq handle (list handle)))
3031 (when header
3032 (article-decode-encoded-words)
3033 (let ((gnus-visible-headers
3034 (or (get 'gnus-visible-headers 'standard-value)
3035 gnus-visible-headers)))
3036 (article-hide-headers))
3037 (goto-char (point-min))
3038 (search-forward "\n\n" nil 'move)
3039 (skip-chars-backward "\t\n ")
3040 (setq header (buffer-substring (point-min) (point)))))
3041 (when (prog1
3042 (gnus-article-browse-html-parts handle header)
3043 (mm-destroy-parts handle))
3044 (setq showed t)))))
3045 showed))
3046
3047 (defun gnus-article-browse-html-article (&optional arg)
3048 "View \"text/html\" parts of the current article with a WWW browser.
3049 Inline images embedded in a message using the cid scheme, as they are
3050 generally considered to be safe, will be processed properly.
3051 The message header is added to the beginning of every html part unless
3052 the prefix argument ARG is given.
3053
3054 Warning: Spammers use links to images (using the http scheme) in HTML
3055 articles to verify whether you have read the message. As
3056 `gnus-article-browse-html-article' passes the HTML content to the
3057 browser without eliminating these \"web bugs\" you should only
3058 use it for mails from trusted senders.
3059
3060 If you always want to display HTML parts in the browser, set
3061 `mm-text-html-renderer' to nil.
3062
3063 This command creates temporary files to pass HTML contents including
3064 images if any to the browser, and deletes them when exiting the group
3065 \(if you want)."
3066 ;; Cf. `mm-w3m-safe-url-regexp'
3067 (interactive "P")
3068 (if arg
3069 (gnus-summary-show-article)
3070 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3071 gnus-visible-headers))
3072 ;; As we insert a <hr>, there's no need for the body boundary.
3073 (gnus-treat-body-boundary nil))
3074 (gnus-summary-show-article)))
3075 (with-current-buffer gnus-article-buffer
3076 (let ((header (unless arg
3077 (save-restriction
3078 (widen)
3079 (buffer-substring-no-properties
3080 (goto-char (point-min))
3081 (if (search-forward "\n\n" nil t)
3082 (match-beginning 0)
3083 (goto-char (point-max))
3084 (skip-chars-backward "\t\n ")
3085 (point))))))
3086 parts)
3087 (set-buffer gnus-original-article-buffer)
3088 (setq parts (mm-dissect-buffer t t))
3089 ;; If singlepart, enforce a list.
3090 (when (and (bufferp (car parts))
3091 (stringp (car (mm-handle-type parts))))
3092 (setq parts (list parts)))
3093 ;; Process the list
3094 (unless (gnus-article-browse-html-parts parts header)
3095 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3096 (mm-destroy-parts parts)
3097 (unless arg
3098 (gnus-summary-show-article)))))
3099
3100 (defun article-hide-list-identifiers ()
3101 "Remove list identifiers from the Subject header.
3102 The `gnus-list-identifiers' variable specifies what to do."
3103 (interactive)
3104 (let ((inhibit-point-motion-hooks t)
3105 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3106 (inhibit-read-only t))
3107 (when regexp
3108 (save-excursion
3109 (save-restriction
3110 (article-narrow-to-head)
3111 (goto-char (point-min))
3112 (while (re-search-forward
3113 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3114 nil t)
3115 (delete-region (match-beginning 2) (match-end 0))
3116 (beginning-of-line))
3117 (when (re-search-forward
3118 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3119 (delete-region (match-beginning 1) (match-end 1))))))))
3120
3121 (defun article-hide-pem (&optional arg)
3122 "Toggle hiding of any PEM headers and signatures in the current article.
3123 If given a negative prefix, always show; if given a positive prefix,
3124 always hide."
3125 (interactive (gnus-article-hidden-arg))
3126 (unless (gnus-article-check-hidden-text 'pem arg)
3127 (save-excursion
3128 (let ((inhibit-read-only t) end)
3129 (goto-char (point-min))
3130 ;; Hide the horrendously ugly "header".
3131 (when (and (search-forward
3132 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3133 nil t)
3134 (setq end (1+ (match-beginning 0))))
3135 (gnus-add-wash-type 'pem)
3136 (gnus-article-hide-text-type
3137 end
3138 (if (search-forward "\n\n" nil t)
3139 (match-end 0)
3140 (point-max))
3141 'pem)
3142 ;; Hide the trailer as well
3143 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3144 nil t)
3145 (gnus-article-hide-text-type
3146 (match-beginning 0) (match-end 0) 'pem)))))))
3147
3148 (defun article-strip-banner ()
3149 "Strip the banners specified by the `banner' group parameter and by
3150 `gnus-article-address-banner-alist'."
3151 (interactive)
3152 (save-excursion
3153 (save-restriction
3154 (let ((inhibit-point-motion-hooks t))
3155 (when (gnus-parameter-banner gnus-newsgroup-name)
3156 (article-really-strip-banner
3157 (gnus-parameter-banner gnus-newsgroup-name)))
3158 (when gnus-article-address-banner-alist
3159 ;; Note that the From header is decoded here, so it is
3160 ;; required that the *-extract-address-components function
3161 ;; supports non-ASCII text.
3162 (let ((from (save-restriction
3163 (widen)
3164 (article-narrow-to-head)
3165 (mail-fetch-field "from"))))
3166 (when (and from
3167 (setq from
3168 (cadr (funcall gnus-extract-address-components
3169 from))))
3170 (catch 'found
3171 (dolist (pair gnus-article-address-banner-alist)
3172 (when (string-match (car pair) from)
3173 (throw 'found
3174 (article-really-strip-banner (cdr pair)))))))))))))
3175
3176 (defun article-really-strip-banner (banner)
3177 "Strip the banner specified by the argument."
3178 (save-excursion
3179 (save-restriction
3180 (let ((inhibit-point-motion-hooks t)
3181 (gnus-signature-limit nil)
3182 (inhibit-read-only t))
3183 (article-goto-body)
3184 (cond
3185 ((eq banner 'signature)
3186 (when (gnus-article-narrow-to-signature)
3187 (widen)
3188 (forward-line -1)
3189 (delete-region (point) (point-max))))
3190 ((symbolp banner)
3191 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3192 (while (re-search-forward banner nil t)
3193 (delete-region (match-beginning 0) (match-end 0)))))
3194 ((stringp banner)
3195 (while (re-search-forward banner nil t)
3196 (delete-region (match-beginning 0) (match-end 0)))))))))
3197
3198 (defun article-babel ()
3199 "Translate article using an online translation service."
3200 (interactive)
3201 (require 'babel)
3202 (gnus-with-article-buffer
3203 (when (article-goto-body)
3204 (let* ((start (point))
3205 (end (point-max))
3206 (orig (buffer-substring start end))
3207 (trans (babel-as-string orig)))
3208 (save-restriction
3209 (narrow-to-region start end)
3210 (delete-region start end)
3211 (insert trans))))))
3212
3213 (defun article-hide-signature (&optional arg)
3214 "Hide the signature in the current article.
3215 If given a negative prefix, always show; if given a positive prefix,
3216 always hide."
3217 (interactive (gnus-article-hidden-arg))
3218 (unless (gnus-article-check-hidden-text 'signature arg)
3219 (save-excursion
3220 (save-restriction
3221 (let ((inhibit-read-only t))
3222 (when (gnus-article-narrow-to-signature)
3223 (gnus-article-hide-text-type
3224 (point-min) (point-max) 'signature))))))
3225 (gnus-set-mode-line 'article))
3226
3227 (defun article-strip-headers-in-body ()
3228 "Strip offensive headers from bodies."
3229 (interactive)
3230 (save-excursion
3231 (article-goto-body)
3232 (let ((case-fold-search t))
3233 (when (looking-at "x-no-archive:")
3234 (gnus-delete-line)))))
3235
3236 (defun article-strip-leading-blank-lines ()
3237 "Remove all blank lines from the beginning of the article."
3238 (interactive)
3239 (save-excursion
3240 (let ((inhibit-point-motion-hooks t)
3241 (inhibit-read-only t))
3242 (when (article-goto-body)
3243 (while (and (not (eobp))
3244 (looking-at "[ \t]*$"))
3245 (gnus-delete-line))))))
3246
3247 (defun article-narrow-to-head ()
3248 "Narrow the buffer to the head of the message.
3249 Point is left at the beginning of the narrowed-to region."
3250 (narrow-to-region
3251 (goto-char (point-min))
3252 (cond
3253 ;; Absolutely no headers displayed.
3254 ((looking-at "\n")
3255 (point))
3256 ;; Normal headers.
3257 ((search-forward "\n\n" nil 1)
3258 (1- (point)))
3259 ;; Nothing but headers.
3260 (t
3261 (point-max))))
3262 (goto-char (point-min)))
3263
3264 (defun article-goto-body ()
3265 "Place point at the start of the body."
3266 (goto-char (point-min))
3267 (cond
3268 ;; This variable is only bound when dealing with separate
3269 ;; MIME body parts.
3270 (article-goto-body-goes-to-point-min-p
3271 t)
3272 ((search-forward "\n\n" nil t)
3273 t)
3274 (t
3275 (goto-char (point-max))
3276 nil)))
3277
3278 (defun article-strip-multiple-blank-lines ()
3279 "Replace consecutive blank lines with one empty line."
3280 (interactive)
3281 (save-excursion
3282 (let ((inhibit-point-motion-hooks t)
3283 (inhibit-read-only t))
3284 ;; First make all blank lines empty.
3285 (article-goto-body)
3286 (while (re-search-forward "^[ \t]+$" nil t)
3287 (unless (gnus-annotation-in-region-p
3288 (match-beginning 0) (match-end 0))
3289 (replace-match "" nil t)))
3290 ;; Then replace multiple empty lines with a single empty line.
3291 (article-goto-body)
3292 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3293 (unless (gnus-annotation-in-region-p
3294 (match-beginning 0) (match-end 0))
3295 (delete-region (match-beginning 1) (match-end 1)))))))
3296
3297 (defun article-strip-leading-space ()
3298 "Remove all white space from the beginning of the lines in the article."
3299 (interactive)
3300 (save-excursion
3301 (let ((inhibit-point-motion-hooks t)
3302 (inhibit-read-only t))
3303 (article-goto-body)
3304 (while (re-search-forward "^[ \t]+" nil t)
3305 (replace-match "" t t)))))
3306
3307 (defun article-strip-trailing-space ()
3308 "Remove all white space from the end of the lines in the article."
3309 (interactive)
3310 (save-excursion
3311 (let ((inhibit-point-motion-hooks t)
3312 (inhibit-read-only t))
3313 (article-goto-body)
3314 (while (re-search-forward "[ \t]+$" nil t)
3315 (replace-match "" t t)))))
3316
3317 (defun article-strip-blank-lines ()
3318 "Strip leading, trailing and multiple blank lines."
3319 (interactive)
3320 (article-strip-leading-blank-lines)
3321 (article-remove-trailing-blank-lines)
3322 (article-strip-multiple-blank-lines))
3323
3324 (defun article-strip-all-blank-lines ()
3325 "Strip all blank lines."
3326 (interactive)
3327 (save-excursion
3328 (let ((inhibit-point-motion-hooks t)
3329 (inhibit-read-only t))
3330 (article-goto-body)
3331 (while (re-search-forward "^[ \t]*\n" nil t)
3332 (replace-match "" t t)))))
3333
3334 (defun gnus-article-narrow-to-signature ()
3335 "Narrow to the signature; return t if a signature is found, else nil."
3336 (let ((inhibit-point-motion-hooks t))
3337 (when (gnus-article-search-signature)
3338 (forward-line 1)
3339 ;; Check whether we have some limits to what we consider
3340 ;; to be a signature.
3341 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3342 (list gnus-signature-limit)))
3343 limit limited)
3344 (while (setq limit (pop limits))
3345 (if (or (and (integerp limit)
3346 (< (- (point-max) (point)) limit))
3347 (and (floatp limit)
3348 (< (count-lines (point) (point-max)) limit))
3349 (and (functionp limit)
3350 (funcall limit))
3351 (and (stringp limit)
3352 (not (re-search-forward limit nil t))))
3353 () ; This limit did not succeed.
3354 (setq limited t
3355 limits nil)))
3356 (unless limited
3357 (narrow-to-region (point) (point-max))
3358 t)))))
3359
3360 (defun gnus-article-search-signature ()
3361 "Search the current buffer for the signature separator.
3362 Put point at the beginning of the signature separator."
3363 (let ((cur (point)))
3364 (goto-char (point-max))
3365 (if (if (stringp gnus-signature-separator)
3366 (re-search-backward gnus-signature-separator nil t)
3367 (let ((seps gnus-signature-separator))
3368 (while (and seps
3369 (not (re-search-backward (car seps) nil t)))
3370 (pop seps))
3371 seps))
3372 t
3373 (goto-char cur)
3374 nil)))
3375
3376 (defun gnus-article-hidden-arg ()
3377 "Return the current prefix arg as a number, or 0 if no prefix."
3378 (list (if current-prefix-arg
3379 (prefix-numeric-value current-prefix-arg)
3380 0)))
3381
3382 (defun gnus-article-check-hidden-text (type arg)
3383 "Return nil if hiding is necessary.
3384 Arg can be nil or a number. nil and positive means hide, negative
3385 means show, 0 means toggle."
3386 (save-excursion
3387 (save-restriction
3388 (let ((hide (gnus-article-hidden-text-p type)))
3389 (cond
3390 ((or (null arg)
3391 (> arg 0))
3392 nil)
3393 ((< arg 0)
3394 (gnus-article-show-hidden-text type)
3395 t)
3396 (t
3397 (if (eq hide 'hidden)
3398 (progn
3399 (gnus-article-show-hidden-text type)
3400 t)
3401 nil)))))))
3402
3403 (defun gnus-article-hidden-text-p (type)
3404 "Say whether the current buffer contains hidden text of type TYPE."
3405 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3406 (while (and pos
3407 (not (get-text-property pos 'invisible))
3408 (not (get-text-property pos 'dummy-invisible)))
3409 (setq pos
3410 (text-property-any (1+ pos) (point-max) 'article-type type)))
3411 (if pos
3412 'hidden
3413 nil)))
3414
3415 (defun gnus-article-show-hidden-text (type &optional _dummy)
3416 "Show all hidden text of type TYPE.
3417 Originally it is hide instead of DUMMY."
3418 (let ((inhibit-read-only t)
3419 (inhibit-point-motion-hooks t))
3420 (gnus-remove-text-properties-when
3421 'article-type type
3422 (point-min) (point-max)
3423 (cons 'article-type (cons type
3424 gnus-hidden-properties)))
3425 (gnus-delete-wash-type type)))
3426
3427 (defconst article-time-units
3428 `((year . ,(* 365.25 24 60 60))
3429 (week . ,(* 7 24 60 60))
3430 (day . ,(* 24 60 60))
3431 (hour . ,(* 60 60))
3432 (minute . 60)
3433 (second . 1))
3434 "Mapping from time units to seconds.")
3435
3436 (defun gnus-article-forward-header ()
3437 "Move point to the start of the next header.
3438 If the current header is a continuation header, this can be several
3439 lines forward."
3440 (let ((ended nil))
3441 (while (not ended)
3442 (forward-line 1)
3443 (if (looking-at "[ \t]+[^ \t]")
3444 (forward-line 1)
3445 (setq ended t)))))
3446
3447 (defun article-treat-date ()
3448 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3449 (with-current-buffer gnus-summary-buffer
3450 gnus-article-date-headers)
3451 gnus-article-date-headers)
3452 t))
3453
3454 (defun article-date-ut (&optional type _highlight date-position)
3455 "Convert DATE date to TYPE in the current article.
3456 The default type is `ut'. See `gnus-article-date-headers' for
3457 possible values."
3458 (interactive (list 'ut t))
3459 (let* ((case-fold-search t)
3460 (inhibit-read-only t)
3461 (inhibit-point-motion-hooks t)
3462 (visible-date (mail-fetch-field "Date"))
3463 pos date bface eface)
3464 (save-excursion
3465 (if date-position
3466 (progn
3467 (goto-char date-position)
3468 (setq date (get-text-property (point) 'original-date))
3469 (when (looking-at "[^:]+:[\t ]*")
3470 (setq bface (get-text-property (match-beginning 0) 'face)
3471 eface (get-text-property (match-end 0) 'face)))
3472 (delete-region (point)
3473 (progn
3474 (gnus-article-forward-header)
3475 (point)))
3476 (article-transform-date date type bface eface))
3477 (save-restriction
3478 (widen)
3479 (goto-char (point-min))
3480 (while (or (get-text-property (setq pos (point)) 'original-date)
3481 (and (setq pos (next-single-property-change
3482 (point) 'original-date))
3483 (goto-char pos)))
3484 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3485 (1+ (match-beginning 0))
3486 (point-max)))
3487 (while (setq pos (text-property-not-all pos (point-max)
3488 'gnus-date-type nil))
3489 (setq date (get-text-property pos 'original-date))
3490 (goto-char pos)
3491 (when (looking-at "[^:]+:[\t ]*")
3492 (setq bface (get-text-property (match-beginning 0) 'face)
3493 eface (get-text-property (match-end 0) 'face)))
3494 (delete-region pos (or (text-property-any pos (point-max)
3495 'gnus-date-type nil)
3496 (point-max))))
3497 (unless date ;; the 1st time
3498 (goto-char (point-min))
3499 (while (re-search-forward "^Date:[\t ]*" nil t)
3500 (setq date (get-text-property (match-beginning 0)
3501 'original-date)
3502 bface (get-text-property (match-beginning 0) 'face)
3503 eface (get-text-property (match-end 0) 'face))
3504 (delete-region (point-at-bol) (progn
3505 (gnus-article-forward-header)
3506 (point)))))
3507 (when (and (not date)
3508 visible-date)
3509 (setq date visible-date))
3510 (when date
3511 (article-transform-date date type bface eface))
3512 (goto-char (point-max))
3513 (widen)))))))
3514
3515 (defun article-transform-date (date type bface eface)
3516 (dolist (this-type (cond
3517 ((null type)
3518 (list 'ut))
3519 ((atom type)
3520 (list type))
3521 (t
3522 type)))
3523 (goto-char
3524 (prog1
3525 (point)
3526 (add-text-properties
3527 (point)
3528 (progn
3529 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3530 (point))
3531 (list 'original-date date 'gnus-date-type this-type))))
3532 ;; Do highlighting.
3533 (when (looking-at
3534 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3535 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3536 (when (match-beginning 2)
3537 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3538 (while (and (zerop (forward-line 1))
3539 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3540 (when (match-beginning 1)
3541 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3542
3543 (defun article-make-date-line (date type)
3544 "Return a DATE line of TYPE."
3545 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3546 combined-lapsed))
3547 (error "Unknown conversion type: %s" type))
3548 (condition-case ()
3549 (let ((time (ignore-errors (date-to-time date))))
3550 (cond
3551 ;; Convert to the local timezone.
3552 ((eq type 'local)
3553 (concat "Date: " (message-make-date time)))
3554 ;; Convert to Universal Time.
3555 ((eq type 'ut)
3556 (concat "Date: "
3557 (substring
3558 (message-make-date
3559 (let* ((e (parse-time-string date))
3560 (tm (apply 'encode-time e))
3561 (ms (car tm))
3562 (ls (- (cadr tm) (car (current-time-zone time)))))
3563 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3564 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3565 (t (list ms ls)))))
3566 0 -5)
3567 "UT"))
3568 ;; Get the original date from the article.
3569 ((eq type 'original)
3570 (concat "Date: " (if (string-match "\n+$" date)
3571 (substring date 0 (match-beginning 0))
3572 date)))
3573 ;; Let the user define the format.
3574 ((eq type 'user-defined)
3575 (let ((format (or (condition-case nil
3576 (with-current-buffer gnus-summary-buffer
3577 gnus-article-time-format)
3578 (error nil))
3579 gnus-article-time-format)))
3580 (if (functionp format)
3581 (funcall format time)
3582 (concat "Date: " (format-time-string format time)))))
3583 ;; ISO 8601.
3584 ((eq type 'iso8601)
3585 (let ((tz (car (current-time-zone time))))
3586 (concat
3587 "Date: "
3588 (format-time-string "%Y%m%dT%H%M%S" time)
3589 (format "%s%02d%02d"
3590 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3591 (/ (% (abs tz) 3600) 60)))))
3592 ;; Do a lapsed format.
3593 ((eq type 'lapsed)
3594 (concat "Date: " (article-lapsed-string time)))
3595 ;; A combined date/lapsed format.
3596 ((eq type 'combined-lapsed)
3597 (let ((date-string (article-make-date-line date 'original))
3598 (segments 3)
3599 lapsed-string)
3600 (while (and
3601 time
3602 (setq lapsed-string
3603 (concat " (" (article-lapsed-string time segments) ")"))
3604 (> (+ (length date-string)
3605 (length lapsed-string))
3606 (+ fill-column 6))
3607 (> segments 0))
3608 (setq segments (1- segments)))
3609 (if (> segments 0)
3610 (concat date-string lapsed-string)
3611 date-string)))
3612 ;; Display the date in proper English
3613 ((eq type 'english)
3614 (let ((dtime (decode-time time)))
3615 (concat
3616 "Date: the "
3617 (number-to-string (nth 3 dtime))
3618 (let ((digit (% (nth 3 dtime) 10)))
3619 (cond
3620 ((memq (nth 3 dtime) '(11 12 13)) "th")
3621 ((= digit 1) "st")
3622 ((= digit 2) "nd")
3623 ((= digit 3) "rd")
3624 (t "th")))
3625 " of "
3626 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3627 " "
3628 (number-to-string (nth 5 dtime))
3629 " at "
3630 (format "%02d" (nth 2 dtime))
3631 ":"
3632 (format "%02d" (nth 1 dtime)))))))
3633 (foo
3634 (format "Date: %s (from Gnus)" date))))
3635
3636 (defun article-lapsed-string (time &optional max-segments)
3637 ;; If the date is seriously mangled, the timezone functions are
3638 ;; liable to bug out, so we ignore all errors.
3639 (let* ((now (current-time))
3640 (real-time (subtract-time now time))
3641 (real-sec (and real-time
3642 (+ (* (float (car real-time)) 65536)
3643 (cadr real-time))))
3644 (sec (and real-time (abs real-sec)))
3645 (segments 0)
3646 num prev)
3647 (unless max-segments
3648 (setq max-segments (length article-time-units)))
3649 (cond
3650 ((null real-time)
3651 "Unknown")
3652 ((zerop sec)
3653 "Now")
3654 (t
3655 (concat
3656 ;; This is a bit convoluted, but basically we go
3657 ;; through the time units for years, weeks, etc,
3658 ;; and divide things to see whether that results
3659 ;; in positive answers.
3660 (mapconcat
3661 (lambda (unit)
3662 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3663 (>= segments max-segments))
3664 ;; The (remaining) seconds are too few to
3665 ;; be divided into this time unit.
3666 ""
3667 ;; It's big enough, so we output it.
3668 (setq sec (- sec (* num (cdr unit))))
3669 (prog1
3670 (concat (if prev ", " "") (int-to-string
3671 (floor num))
3672 " " (symbol-name (car unit))
3673 (if (> num 1) "s" ""))
3674 (setq prev t
3675 segments (1+ segments)))))
3676 article-time-units "")
3677 ;; If dates are odd, then it might appear like the
3678 ;; article was sent in the future.
3679 (if (> real-sec 0)
3680 " ago"
3681 " in the future"))))))
3682
3683 (defun article-date-local (&optional highlight)
3684 "Convert the current article date to the local timezone."
3685 (interactive (list t))
3686 (article-date-ut 'local highlight))
3687
3688 (defun article-date-english (&optional highlight)
3689 "Convert the current article date to something that is proper English."
3690 (interactive (list t))
3691 (article-date-ut 'english highlight))
3692
3693 (defun article-date-original (&optional highlight)
3694 "Convert the current article date to what it was originally.
3695 This is only useful if you have used some other date conversion
3696 function and want to see what the date was before converting."
3697 (interactive (list t))
3698 (article-date-ut 'original highlight))
3699
3700 (defun article-date-lapsed (&optional highlight)
3701 "Convert the current article date to time lapsed since it was sent."
3702 (interactive (list t))
3703 (article-date-ut 'lapsed highlight))
3704
3705 (defun article-date-combined-lapsed (&optional highlight)
3706 "Convert the current article date to time lapsed since it was sent."
3707 (interactive (list t))
3708 (article-date-ut 'combined-lapsed highlight))
3709
3710 (defun article-update-date-lapsed ()
3711 "Function to be run from a timer to update the lapsed time line."
3712 (save-match-data
3713 (let ((buffer (current-buffer)))
3714 (ignore-errors
3715 (walk-windows
3716 (lambda (w)
3717 (set-buffer (window-buffer w))
3718 (when (derived-mode-p 'gnus-article-mode)
3719 (let ((old-line (count-lines (point-min) (point)))
3720 (old-column (- (point) (line-beginning-position)))
3721 (window-start (window-start w))
3722 (pos (point-min))
3723 type next end)
3724 (while (setq pos (text-property-not-all pos (point-max)
3725 'gnus-date-type nil))
3726 (setq next (or (next-single-property-change pos
3727 'gnus-date-type)
3728 (point-max)))
3729 (setq type (get-text-property pos 'gnus-date-type))
3730 (when (memq type '(lapsed combined-lapsed user-defined))
3731 (article-date-ut type t pos)
3732 (setq end (or (next-single-property-change pos
3733 'gnus-date-type)
3734 (point-max)))
3735 (when window-start
3736 (if (/= window-start next)
3737 (setq window-start nil)
3738 (set-window-start w end)))
3739 (setq next end))
3740 (setq pos next))
3741 (goto-char (point-min))
3742 (when (> old-column 0)
3743 (setq old-line (1- old-line)))
3744 (forward-line old-line)
3745 (end-of-line)
3746 (when (> (current-column) old-column)
3747 (beginning-of-line)
3748 (forward-char old-column)))))
3749 nil 'visible))
3750 (set-buffer buffer))))
3751
3752 (defun gnus-start-date-timer (&optional n)
3753 "Start a timer to update the Date headers in the article buffers.
3754 The numerical prefix says how frequently (in seconds) the function
3755 is to run."
3756 (interactive "p")
3757 (unless n
3758 (setq n 1))
3759 (gnus-stop-date-timer)
3760 (setq article-lapsed-timer
3761 (run-at-time 1 n 'article-update-date-lapsed)))
3762
3763 (defun gnus-stop-date-timer ()
3764 "Stop the Date timer."
3765 (interactive)
3766 (when article-lapsed-timer
3767 (nnheader-cancel-timer article-lapsed-timer)
3768 (setq article-lapsed-timer nil)))
3769
3770 (defun article-date-user (&optional highlight)
3771 "Convert the current article date to the user-defined format.
3772 This format is defined by the `gnus-article-time-format' variable."
3773 (interactive (list t))
3774 (article-date-ut 'user highlight))
3775
3776 (defun article-date-iso8601 (&optional highlight)
3777 "Convert the current article date to ISO8601."
3778 (interactive (list t))
3779 (article-date-ut 'iso8601 highlight))
3780
3781 (defmacro gnus-article-save-original-date (&rest forms)
3782 "Save the original date as a text property and evaluate FORMS."
3783 `(let* ((case-fold-search t)
3784 (start (progn
3785 (goto-char (point-min))
3786 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3787 (not (bolp)))
3788 (match-end 0))))
3789 (date (when (and start
3790 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3791 nil t))
3792 (buffer-substring-no-properties start
3793 (match-beginning 0)))))
3794 (goto-char (point-max))
3795 (skip-chars-backward "\n")
3796 (put-text-property (point-min) (point) 'original-date date)
3797 ,@forms
3798 (goto-char (point-max))
3799 (skip-chars-backward "\n")
3800 (put-text-property (point-min) (point) 'original-date date)))
3801
3802 ;; (defun article-show-all ()
3803 ;; "Show all hidden text in the article buffer."
3804 ;; (interactive)
3805 ;; (save-excursion
3806 ;; (let ((inhibit-read-only t))
3807 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3808
3809 (defun article-remove-leading-whitespace ()
3810 "Remove excessive whitespace from all headers."
3811 (interactive)
3812 (save-excursion
3813 (save-restriction
3814 (let ((inhibit-read-only t))
3815 (article-narrow-to-head)
3816 (goto-char (point-min))
3817 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3818 (delete-region (match-beginning 1) (match-end 1)))))))
3819
3820 (defun article-emphasize (&optional arg)
3821 "Emphasize text according to `gnus-emphasis-alist'."
3822 (interactive (gnus-article-hidden-arg))
3823 (unless (gnus-article-check-hidden-text 'emphasis arg)
3824 (save-excursion
3825 (let ((alist (or
3826 (condition-case nil
3827 (with-current-buffer gnus-summary-buffer
3828 gnus-article-emphasis-alist)
3829 (error))
3830 gnus-emphasis-alist))
3831 (inhibit-read-only t)
3832 (props (append '(article-type emphasis)
3833 gnus-hidden-properties))
3834 regexp elem beg invisible visible face)
3835 (article-goto-body)
3836 (setq beg (point))
3837 (while (setq elem (pop alist))
3838 (goto-char beg)
3839 (setq regexp (car elem)
3840 invisible (nth 1 elem)
3841 visible (nth 2 elem)
3842 face (nth 3 elem))
3843 (while (re-search-forward regexp nil t)
3844 (when (and (match-beginning visible) (match-beginning invisible))
3845 (gnus-article-hide-text
3846 (match-beginning invisible) (match-end invisible) props)
3847 (gnus-article-unhide-text-type
3848 (match-beginning visible) (match-end visible) 'emphasis)
3849 (gnus-put-overlay-excluding-newlines
3850 (match-beginning visible) (match-end visible) 'face face)
3851 (gnus-add-wash-type 'emphasis)
3852 (goto-char (match-end invisible)))))))))
3853
3854 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3855 "Setup newsgroup emphasis alist."
3856 (unless gnus-article-emphasis-alist
3857 (let ((name (and gnus-newsgroup-name
3858 (gnus-group-real-name gnus-newsgroup-name))))
3859 (make-local-variable 'gnus-article-emphasis-alist)
3860 (setq gnus-article-emphasis-alist
3861 (nconc
3862 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3863 (while (setq elem (pop alist))
3864 (when (and name (string-match (car elem) name))
3865 (setq alist nil
3866 highlight (copy-sequence (cdr elem)))))
3867 highlight)
3868 (copy-sequence highlight-words)
3869 (if gnus-newsgroup-name
3870 (copy-sequence (gnus-group-find-parameter
3871 gnus-newsgroup-name 'highlight-words t)))
3872 gnus-emphasis-alist)))))
3873
3874 (defvar gnus-summary-article-menu)
3875 (defvar gnus-summary-post-menu)
3876
3877 ;;; Saving functions.
3878
3879 (defun gnus-article-save (save-buffer file &optional num)
3880 "Save the currently selected article."
3881 (when (or (get gnus-default-article-saver :headers)
3882 (not gnus-save-all-headers))
3883 ;; Remove headers according to `gnus-saved-headers' or the value
3884 ;; of the `:headers' property that the saver function might have.
3885 (let ((gnus-visible-headers
3886 (or (symbol-value (get gnus-default-article-saver :headers))
3887 gnus-saved-headers gnus-visible-headers))
3888 ;; Ignore group parameter. See `article-hide-headers'.
3889 (gnus-summary-buffer nil))
3890 (with-current-buffer save-buffer
3891 (article-hide-headers 1 t))))
3892 (save-window-excursion
3893 (if (not gnus-default-article-saver)
3894 (error "No default saver is defined")
3895 ;; !!! Magic! The saving functions all save
3896 ;; `gnus-save-article-buffer' (or so they think), but we
3897 ;; bind that variable to our save-buffer.
3898 (set-buffer gnus-article-buffer)
3899 (let* ((gnus-save-article-buffer save-buffer)
3900 (filename
3901 (cond
3902 ((not gnus-prompt-before-saving) 'default)
3903 ((eq gnus-prompt-before-saving 'always) nil)
3904 (t file)))
3905 (gnus-number-of-articles-to-be-saved
3906 (when (eq gnus-prompt-before-saving t)
3907 num))) ; Magic
3908 (set-buffer gnus-article-current-summary)
3909 (funcall gnus-default-article-saver filename)))))
3910
3911 (defun gnus-read-save-file-name (prompt &optional filename
3912 function group headers variable
3913 dir-var)
3914 (let ((default-name
3915 (funcall function group headers (symbol-value variable)))
3916 result)
3917 (setq result
3918 (expand-file-name
3919 (cond
3920 ((eq filename 'default)
3921 default-name)
3922 ((eq filename t)
3923 default-name)
3924 (filename filename)
3925 (t
3926 (when (symbol-value dir-var)
3927 (setq default-name (expand-file-name
3928 (file-name-nondirectory default-name)
3929 (symbol-value dir-var))))
3930 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3931 (prompt
3932 (format prompt
3933 (if (and gnus-number-of-articles-to-be-saved
3934 (> gnus-number-of-articles-to-be-saved 1))
3935 (format "these %d articles"
3936 gnus-number-of-articles-to-be-saved)
3937 "this article")))
3938 (file
3939 ;; Let the split methods have their say.
3940 (cond
3941 ;; No split name was found.
3942 ((null split-name)
3943 (read-file-name
3944 (concat prompt " (default "
3945 (file-name-nondirectory default-name) "): ")
3946 (file-name-directory default-name)
3947 default-name))
3948 ;; A single group name is returned.
3949 ((stringp split-name)
3950 (setq default-name
3951 (funcall function split-name headers
3952 (symbol-value variable)))
3953 (read-file-name
3954 (concat prompt " (default "
3955 (file-name-nondirectory default-name) "): ")
3956 (file-name-directory default-name)
3957 default-name))
3958 ;; A single split name was found
3959 ((= 1 (length split-name))
3960 (let* ((name (expand-file-name
3961 (car split-name)
3962 gnus-article-save-directory))
3963 (dir (cond ((file-directory-p name)
3964 (file-name-as-directory name))
3965 ((file-exists-p name) name)
3966 (t gnus-article-save-directory))))
3967 (read-file-name
3968 (concat prompt " (default " name "): ")
3969 dir name)))
3970 ;; A list of splits was found.
3971 (t
3972 (setq split-name (nreverse split-name))
3973 (let (result)
3974 (let ((file-name-history
3975 (nconc split-name file-name-history)))
3976 (setq result
3977 (expand-file-name
3978 (read-file-name
3979 (concat prompt " (`M-p' for defaults): ")
3980 gnus-article-save-directory
3981 (car split-name))
3982 gnus-article-save-directory)))
3983 (car (push result file-name-history)))))))
3984 ;; Create the directory.
3985 (gnus-make-directory (file-name-directory file))
3986 ;; If we have read a directory, we append the default file name.
3987 (when (file-directory-p file)
3988 (setq file (expand-file-name (file-name-nondirectory
3989 default-name)
3990 (file-name-as-directory file))))
3991 ;; Possibly translate some characters.
3992 (nnheader-translate-file-chars file))))))
3993 (gnus-make-directory (file-name-directory result))
3994 (when variable
3995 (set variable result))
3996 (when dir-var
3997 (set dir-var (file-name-directory result)))
3998 result))
3999
4000 (defun gnus-article-archive-name (_group)
4001 "Return the first instance of an \"Archive-name\" in the current buffer."
4002 (let ((case-fold-search t))
4003 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
4004 (nnheader-concat gnus-article-save-directory
4005 (match-string 1)))))
4006
4007 (defun gnus-article-nndoc-name (group)
4008 "If GROUP is an nndoc group, return the name of the parent group."
4009 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4010 (gnus-group-get-parameter group 'save-article-group)))
4011
4012 (defun gnus-summary-save-in-rmail (&optional filename)
4013 "Append this article to Rmail file.
4014 Optional argument FILENAME specifies file name.
4015 Directory to save to is default to `gnus-article-save-directory'."
4016 (setq filename (gnus-read-save-file-name
4017 "Save %s in rmail file" filename
4018 gnus-rmail-save-name gnus-newsgroup-name
4019 gnus-current-headers 'gnus-newsgroup-last-rmail))
4020 (with-current-buffer gnus-save-article-buffer
4021 (save-excursion
4022 (save-restriction
4023 (widen)
4024 ;; Note that unlike gnus-summary-save-in-mail, there is no
4025 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4026 ;; not use Babyl.
4027 (gnus-output-to-rmail filename))))
4028 filename)
4029
4030 (defun gnus-summary-save-in-mail (&optional filename)
4031 "Append this article to Unix mail file.
4032 Optional argument FILENAME specifies file name.
4033 Directory to save to is default to `gnus-article-save-directory'."
4034 (setq filename (gnus-read-save-file-name
4035 "Save %s in Unix mail file" filename
4036 gnus-mail-save-name gnus-newsgroup-name
4037 gnus-current-headers 'gnus-newsgroup-last-mail))
4038 (with-current-buffer gnus-save-article-buffer
4039 (save-excursion
4040 (save-restriction
4041 (widen)
4042 (if (and (file-readable-p filename)
4043 (file-regular-p filename)
4044 (mail-file-babyl-p filename))
4045 (gnus-output-to-rmail filename)
4046 (gnus-output-to-mail filename)))))
4047 filename)
4048
4049 (put 'gnus-summary-save-in-file :decode t)
4050 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4051 (defun gnus-summary-save-in-file (&optional filename overwrite)
4052 "Append this article to file.
4053 Optional argument FILENAME specifies file name.
4054 Directory to save to is default to `gnus-article-save-directory'."
4055 (setq filename (gnus-read-save-file-name
4056 "Save %s in file" filename
4057 gnus-file-save-name gnus-newsgroup-name
4058 gnus-current-headers 'gnus-newsgroup-last-file))
4059 (with-current-buffer gnus-save-article-buffer
4060 (save-excursion
4061 (save-restriction
4062 (widen)
4063 (when (and overwrite
4064 (file-exists-p filename))
4065 (delete-file filename))
4066 (gnus-output-to-file filename))))
4067 filename)
4068
4069 (put 'gnus-summary-write-to-file :decode t)
4070 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4071 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4072 (defun gnus-summary-write-to-file (&optional filename)
4073 "Write this article to a file, overwriting it if the file exists.
4074 Optional argument FILENAME specifies file name.
4075 The directory to save in defaults to `gnus-article-save-directory'."
4076 (setq filename (gnus-read-save-file-name
4077 "Save %s in file" filename
4078 gnus-file-save-name gnus-newsgroup-name
4079 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4080 (gnus-summary-save-in-file filename t))
4081
4082 (put 'gnus-summary-save-body-in-file :decode t)
4083 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4084 "Append this article body to a file.
4085 Optional argument FILENAME specifies file name.
4086 The directory to save in defaults to `gnus-article-save-directory'."
4087 (setq filename (gnus-read-save-file-name
4088 "Save %s body in file" filename
4089 gnus-file-save-name gnus-newsgroup-name
4090 gnus-current-headers 'gnus-newsgroup-last-file))
4091 (with-current-buffer gnus-save-article-buffer
4092 (save-excursion
4093 (save-restriction
4094 (widen)
4095 (when (article-goto-body)
4096 (narrow-to-region (point) (point-max)))
4097 (when (and overwrite
4098 (file-exists-p filename))
4099 (delete-file filename))
4100 (gnus-output-to-file filename))))
4101 filename)
4102
4103 (put 'gnus-summary-write-body-to-file :decode t)
4104 (put 'gnus-summary-write-body-to-file
4105 :function 'gnus-summary-save-body-in-file)
4106 (defun gnus-summary-write-body-to-file (&optional filename)
4107 "Write this article body to a file, overwriting it if the file exists.
4108 Optional argument FILENAME specifies file name.
4109 The directory to save in defaults to `gnus-article-save-directory'."
4110 (setq filename (gnus-read-save-file-name
4111 "Save %s body in file" filename
4112 gnus-file-save-name gnus-newsgroup-name
4113 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4114 (gnus-summary-save-body-in-file filename t))
4115
4116 (put 'gnus-summary-save-in-pipe :decode t)
4117 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4118 (defun gnus-summary-save-in-pipe (&optional command raw)
4119 "Pipe this article to subprocess COMMAND.
4120 Valid values for COMMAND include:
4121 a string
4122 The executable command name and possibly arguments.
4123 nil
4124 You will be prompted for the command in the minibuffer.
4125 the symbol `default'
4126 It will be replaced with the command which the variable
4127 `gnus-summary-pipe-output-default-command' holds or the command
4128 last used for saving.
4129 Non-nil value for RAW overrides `:decode' and `:headers' properties
4130 and the raw article including all headers will be piped."
4131 (let ((article (gnus-summary-article-number))
4132 (decode (unless raw
4133 (get 'gnus-summary-save-in-pipe :decode)))
4134 save-buffer default)
4135 (if article
4136 (if (vectorp (gnus-summary-article-header article))
4137 (save-current-buffer
4138 (gnus-summary-select-article decode decode nil article)
4139 (insert-buffer-substring
4140 (prog1
4141 (if decode
4142 gnus-article-buffer
4143 gnus-original-article-buffer)
4144 (setq save-buffer
4145 (nnheader-set-temp-buffer " *Gnus Save*"))))
4146 ;; Remove unwanted headers.
4147 (when (and (not raw)
4148 (or (get 'gnus-summary-save-in-pipe :headers)
4149 (not gnus-save-all-headers)))
4150 (let ((gnus-visible-headers
4151 (or (symbol-value (get 'gnus-summary-save-in-pipe
4152 :headers))
4153 gnus-saved-headers gnus-visible-headers))
4154 (gnus-summary-buffer nil))
4155 (article-hide-headers 1 t))))
4156 (error "%d is not a real article" article))
4157 (error "No article to pipe"))
4158 (setq default (or gnus-summary-pipe-output-default-command
4159 gnus-last-shell-command))
4160 (unless (stringp command)
4161 (setq command
4162 (if (and (eq command 'default) default)
4163 default
4164 (gnus-read-shell-command "Shell command on this article: "
4165 default))))
4166 (when (string-equal command "")
4167 (if default
4168 (setq command default)
4169 (error "A command is required")))
4170 (with-current-buffer save-buffer
4171 (save-restriction
4172 (widen)
4173 (shell-command-on-region (point-min) (point-max) command nil)))
4174 (gnus-kill-buffer save-buffer))
4175 (setq gnus-summary-pipe-output-default-command command))
4176
4177 (defun gnus-summary-pipe-to-muttprint (&optional command)
4178 "Pipe this article to muttprint."
4179 (unless (stringp command)
4180 (setq command (read-string
4181 "Print using command: " gnus-summary-muttprint-program
4182 nil gnus-summary-muttprint-program)))
4183 (let ((gnus-summary-pipe-output-default-command
4184 gnus-summary-pipe-output-default-command))
4185 (gnus-summary-save-in-pipe command))
4186 (setq gnus-summary-muttprint-program command))
4187
4188 ;;; Article file names when saving.
4189
4190 (defun gnus-capitalize-newsgroup (newsgroup)
4191 "Capitalize NEWSGROUP name."
4192 (when (not (zerop (length newsgroup)))
4193 (concat (char-to-string (upcase (aref newsgroup 0)))
4194 (substring newsgroup 1))))
4195
4196 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4197 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4198 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4199 Otherwise, it is like ~/News/news/group/num."
4200 (let ((default
4201 (expand-file-name
4202 (concat (if (gnus-use-long-file-name 'not-save)
4203 (gnus-capitalize-newsgroup newsgroup)
4204 (gnus-newsgroup-directory-form newsgroup))
4205 "/" (int-to-string (mail-header-number headers)))
4206 gnus-article-save-directory)))
4207 (if (and last-file
4208 (string-equal (file-name-directory default)
4209 (file-name-directory last-file))
4210 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4211 default
4212 (or last-file default))))
4213
4214 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4215 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4216 If variable `gnus-use-long-file-name' is non-nil, it is
4217 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4218 (let ((default
4219 (expand-file-name
4220 (concat (if (gnus-use-long-file-name 'not-save)
4221 newsgroup
4222 (gnus-newsgroup-directory-form newsgroup))
4223 "/" (int-to-string (mail-header-number headers)))
4224 gnus-article-save-directory)))
4225 (if (and last-file
4226 (string-equal (file-name-directory default)
4227 (file-name-directory last-file))
4228 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4229 default
4230 (or last-file default))))
4231
4232 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4233 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4234 If variable `gnus-use-long-file-name' is non-nil, it is
4235 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4236 (or last-file
4237 (expand-file-name
4238 (if (gnus-use-long-file-name 'not-save)
4239 newsgroup
4240 (file-relative-name
4241 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4242 default-directory))
4243 gnus-article-save-directory)))
4244
4245 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4246 "Generate file name from sender."
4247 (let ((from (mail-header-from headers)))
4248 (expand-file-name
4249 (if (and from (string-match "\\([^ <]+\\)@" from))
4250 (match-string 1 from)
4251 "nobody")
4252 gnus-article-save-directory)))
4253
4254 (defun article-verify-x-pgp-sig ()
4255 "Verify X-PGP-Sig."
4256 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4257 (interactive)
4258 (if (gnus-buffer-live-p gnus-original-article-buffer)
4259 (let ((sig (with-current-buffer gnus-original-article-buffer
4260 (gnus-fetch-field "X-PGP-Sig")))
4261 items info headers)
4262 (when (and sig
4263 mml2015-use
4264 (mml2015-clear-verify-function))
4265 (with-temp-buffer
4266 (insert-buffer-substring gnus-original-article-buffer)
4267 (setq items (split-string sig))
4268 (message-narrow-to-head)
4269 (let ((inhibit-point-motion-hooks t)
4270 (case-fold-search t))
4271 ;; Don't verify multiple headers.
4272 (setq headers (mapconcat (lambda (header)
4273 (concat header ": "
4274 (mail-fetch-field header)
4275 "\n"))
4276 (split-string (nth 1 items) ",") "")))
4277 (delete-region (point-min) (point-max))
4278 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4279 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4280 (insert headers)
4281 (widen)
4282 (forward-line)
4283 (while (not (eobp))
4284 (if (looking-at "^-")
4285 (insert "- "))
4286 (forward-line))
4287 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4288 (insert "Version: " (car items) "\n\n")
4289 (insert (mapconcat 'identity (cddr items) "\n"))
4290 (insert "\n-----END PGP SIGNATURE-----\n")
4291 (let ((mm-security-handle (list (format "multipart/signed"))))
4292 (mml2015-clean-buffer)
4293 (let ((coding-system-for-write (or gnus-newsgroup-charset
4294 'iso-8859-1)))
4295 (funcall (mml2015-clear-verify-function)))
4296 (setq info
4297 (or (mm-handle-multipart-ctl-parameter
4298 mm-security-handle 'gnus-details)
4299 (mm-handle-multipart-ctl-parameter
4300 mm-security-handle 'gnus-info)))))
4301 (when info
4302 (let ((inhibit-read-only t) bface eface)
4303 (save-restriction
4304 (message-narrow-to-head)
4305 (goto-char (point-max))
4306 (forward-line -1)
4307 (setq bface (get-text-property (point-at-bol) 'face)
4308 eface (get-text-property (1- (point-at-eol)) 'face))
4309 (message-remove-header "X-Gnus-PGP-Verify")
4310 (if (re-search-forward "^X-PGP-Sig:" nil t)
4311 (forward-line)
4312 (goto-char (point-max)))
4313 (narrow-to-region (point) (point))
4314 (insert "X-Gnus-PGP-Verify: " info "\n")
4315 (goto-char (point-min))
4316 (forward-line)
4317 (while (not (eobp))
4318 (if (not (looking-at "^[ \t]"))
4319 (insert " "))
4320 (forward-line))
4321 ;; Do highlighting.
4322 (goto-char (point-min))
4323 (when (looking-at "\\([^:]+\\): *")
4324 (put-text-property (match-beginning 1) (1+ (match-end 1))
4325 'face bface)
4326 (put-text-property (match-end 0) (point-max)
4327 'face eface)))))))))
4328
4329 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4330
4331 (defun article-verify-cancel-lock ()
4332 "Verify Cancel-Lock header."
4333 (interactive)
4334 (if (gnus-buffer-live-p gnus-original-article-buffer)
4335 (canlock-verify gnus-original-article-buffer)))
4336
4337 (eval-and-compile
4338 (mapc
4339 (lambda (func)
4340 (let (afunc gfunc)
4341 (if (consp func)
4342 (setq afunc (car func)
4343 gfunc (cdr func))
4344 (setq afunc func
4345 gfunc (intern (format "gnus-%s" func))))
4346 (defalias gfunc
4347 (when (fboundp afunc)
4348 `(lambda (&optional interactive &rest args)
4349 ,(documentation afunc t)
4350 (interactive (list t))
4351 (with-current-buffer gnus-article-buffer
4352 (if interactive
4353 (call-interactively ',afunc)
4354 (apply ',afunc args))))))))
4355 '(article-hide-headers
4356 article-verify-x-pgp-sig
4357 article-verify-cancel-lock
4358 article-hide-boring-headers
4359 article-treat-overstrike
4360 article-treat-ansi-sequences
4361 article-fill-long-lines
4362 article-capitalize-sentences
4363 article-remove-cr
4364 article-remove-leading-whitespace
4365 article-display-x-face
4366 article-display-face
4367 article-de-quoted-unreadable
4368 article-de-base64-unreadable
4369 article-decode-HZ
4370 article-wash-html
4371 article-unsplit-urls
4372 article-hide-list-identifiers
4373 article-strip-banner
4374 article-babel
4375 article-hide-pem
4376 article-hide-signature
4377 article-strip-headers-in-body
4378 article-remove-trailing-blank-lines
4379 article-strip-leading-blank-lines
4380 article-strip-multiple-blank-lines
4381 article-strip-leading-space
4382 article-strip-trailing-space
4383 article-strip-blank-lines
4384 article-strip-all-blank-lines
4385 article-date-local
4386 article-date-english
4387 article-date-iso8601
4388 article-date-original
4389 article-treat-date
4390 article-date-ut
4391 article-decode-mime-words
4392 article-decode-charset
4393 article-decode-encoded-words
4394 article-date-user
4395 article-date-lapsed
4396 article-date-combined-lapsed
4397 article-emphasize
4398 article-treat-dumbquotes
4399 article-treat-non-ascii
4400 article-normalize-headers
4401 ;;(article-show-all . gnus-article-show-all-headers)
4402 )))
4403 \f
4404 ;;;
4405 ;;; Gnus article mode
4406 ;;;
4407
4408 (put 'gnus-article-mode 'mode-class 'special)
4409
4410 (set-keymap-parent gnus-article-mode-map widget-keymap)
4411
4412 (gnus-define-keys gnus-article-mode-map
4413 " " gnus-article-goto-next-page
4414 [?\S-\ ] gnus-article-goto-prev-page
4415 "\177" gnus-article-goto-prev-page
4416 [delete] gnus-article-goto-prev-page
4417 "\C-c^" gnus-article-refer-article
4418 "h" gnus-article-show-summary
4419 "s" gnus-article-show-summary
4420 "\C-c\C-m" gnus-article-mail
4421 "?" gnus-article-describe-briefly
4422 "<" beginning-of-buffer
4423 ">" end-of-buffer
4424 "\C-c\C-i" gnus-info-find-node
4425 "\C-c\C-b" gnus-bug
4426 "R" gnus-article-reply-with-original
4427 "F" gnus-article-followup-with-original
4428 "\C-hk" gnus-article-describe-key
4429 "\C-hc" gnus-article-describe-key-briefly
4430 "\C-hb" gnus-article-describe-bindings
4431
4432 "e" gnus-article-read-summary-keys
4433 "\C-d" gnus-article-read-summary-keys
4434 "\M-*" gnus-article-read-summary-keys
4435 "\M-#" gnus-article-read-summary-keys
4436 "\M-^" gnus-article-read-summary-keys
4437 "\M-g" gnus-article-read-summary-keys)
4438
4439 (substitute-key-definition
4440 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4441
4442 (defvar gnus-article-send-map)
4443
4444 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4445 "W" gnus-article-wide-reply-with-original)
4446 (if (featurep 'xemacs)
4447 (set-keymap-default-binding gnus-article-send-map
4448 'gnus-article-read-summary-send-keys)
4449 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4450
4451 (defun gnus-article-make-menu-bar ()
4452 (unless (boundp 'gnus-article-commands-menu)
4453 (gnus-summary-make-menu-bar))
4454 (unless (boundp 'gnus-article-article-menu)
4455 (easy-menu-define
4456 gnus-article-article-menu gnus-article-mode-map ""
4457 '("Article"
4458 ["Scroll forwards" gnus-article-goto-next-page t]
4459 ["Scroll backwards" gnus-article-goto-prev-page t]
4460 ["Show summary" gnus-article-show-summary t]
4461 ["Fetch Message-ID at point" gnus-article-refer-article t]
4462 ["Mail to address at point" gnus-article-mail t]
4463 ["Send a bug report" gnus-bug t]))
4464
4465 (easy-menu-define
4466 gnus-article-treatment-menu gnus-article-mode-map ""
4467 ;; Fixme: this should use :active (and maybe :visible).
4468 '("Treatment"
4469 ["Hide headers" gnus-article-hide-headers t]
4470 ["Hide signature" gnus-article-hide-signature t]
4471 ["Hide citation" gnus-article-hide-citation t]
4472 ["Treat overstrike" gnus-article-treat-overstrike t]
4473 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4474 ["Remove carriage return" gnus-article-remove-cr t]
4475 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4476 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4477 ["Remove base64" gnus-article-de-base64-unreadable t]
4478 ["Treat html" gnus-article-wash-html t]
4479 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4480 ["Decode HZ" gnus-article-decode-HZ t]))
4481
4482 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4483
4484 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4485
4486 (gnus-run-hooks 'gnus-article-menu-hook)))
4487
4488 (defvar bookmark-make-record-function)
4489 (defvar shr-put-image-function)
4490
4491 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4492 "Major mode for displaying an article.
4493
4494 All normal editing commands are switched off.
4495
4496 The following commands are available in addition to all summary mode
4497 commands:
4498 \\<gnus-article-mode-map>
4499 \\[gnus-article-next-page]\t Scroll the article one page forwards
4500 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4501 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4502 \\[gnus-article-show-summary]\t Display the summary buffer
4503 \\[gnus-article-mail]\t Send a reply to the address near point
4504 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4505 \\[gnus-info-find-node]\t Go to the Gnus info node"
4506 (gnus-simplify-mode-line)
4507 (make-local-variable 'minor-mode-alist)
4508 (when (gnus-visual-p 'article-menu 'menu)
4509 (gnus-article-make-menu-bar)
4510 (when gnus-summary-tool-bar-map
4511 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4512 (gnus-update-format-specifications nil 'article-mode)
4513 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4514 (set (make-local-variable 'gnus-page-broken) nil)
4515 (make-local-variable 'gnus-article-current-summary)
4516 (make-local-variable 'gnus-article-mime-handles)
4517 (make-local-variable 'gnus-article-decoded-p)
4518 (make-local-variable 'gnus-article-mime-handle-alist)
4519 (make-local-variable 'gnus-article-wash-types)
4520 (make-local-variable 'gnus-article-image-alist)
4521 (make-local-variable 'gnus-article-charset)
4522 (make-local-variable 'gnus-article-ignored-charsets)
4523 (set (make-local-variable 'bookmark-make-record-function)
4524 'gnus-summary-bookmark-make-record)
4525 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4526 ;; face.
4527 (set (make-local-variable 'nobreak-char-display) nil)
4528 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4529 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4530 (unless gnus-article-show-cursor
4531 (setq cursor-in-non-selected-windows nil))
4532 (gnus-set-default-directory)
4533 (buffer-disable-undo)
4534 (setq buffer-read-only t
4535 show-trailing-whitespace nil)
4536 (mm-enable-multibyte))
4537
4538 (defun gnus-article-setup-buffer ()
4539 "Initialize the article buffer."
4540 (let* ((name (if gnus-single-article-buffer "*Article*"
4541 (concat "*Article "
4542 (gnus-group-decoded-name gnus-newsgroup-name)
4543 "*")))
4544 (original
4545 (progn (string-match "\\*Article" name)
4546 (concat " *Original Article"
4547 (substring name (match-end 0))))))
4548 (setq gnus-article-buffer name)
4549 (setq gnus-original-article-buffer original)
4550 (setq gnus-article-mime-handle-alist nil)
4551 (with-current-buffer gnus-summary-buffer
4552 ;; This might be a variable local to the summary buffer.
4553 (unless gnus-single-article-buffer
4554 (setq gnus-article-buffer name)
4555 (setq gnus-original-article-buffer original)
4556 (gnus-set-global-variables)))
4557 (gnus-article-setup-highlight-words)
4558 ;; Init original article buffer.
4559 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4560 (mm-enable-multibyte)
4561 (setq major-mode 'gnus-original-article-mode)
4562 (make-local-variable 'gnus-original-article))
4563 (if (and (get-buffer name)
4564 (with-current-buffer name
4565 (if gnus-article-edit-mode
4566 (if (y-or-n-p "Article mode edit in progress; discard? ")
4567 (progn
4568 (set-buffer-modified-p nil)
4569 (gnus-kill-buffer name)
4570 (message "")
4571 nil)
4572 (error "Action aborted"))
4573 t)))
4574 (let ((summary gnus-summary-buffer))
4575 (with-current-buffer name
4576 (set (make-local-variable 'gnus-article-edit-mode) nil)
4577 (gnus-article-stop-animations)
4578 (when gnus-article-mime-handles
4579 (mm-destroy-parts gnus-article-mime-handles)
4580 (setq gnus-article-mime-handles nil))
4581 ;; Set it to nil in article-buffer!
4582 (setq gnus-article-mime-handle-alist nil)
4583 (buffer-disable-undo)
4584 (setq buffer-read-only t)
4585 (unless (derived-mode-p 'gnus-article-mode)
4586 (gnus-article-mode))
4587 (set (make-local-variable 'gnus-summary-buffer) summary)
4588 (setq truncate-lines gnus-article-truncate-lines)
4589 (current-buffer)))
4590 (let ((summary gnus-summary-buffer))
4591 (with-current-buffer (gnus-get-buffer-create name)
4592 (gnus-article-mode)
4593 (setq truncate-lines gnus-article-truncate-lines)
4594 (set (make-local-variable 'gnus-summary-buffer) summary)
4595 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4596 (when article-lapsed-timer
4597 (gnus-stop-date-timer))
4598 (when gnus-article-update-date-headers
4599 (gnus-start-date-timer gnus-article-update-date-headers))
4600 (current-buffer))))))
4601
4602 (defun gnus-article-stop-animations ()
4603 (dolist (timer (and (boundp 'timer-list)
4604 timer-list))
4605 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4606 (cancel-timer timer))))
4607
4608 (defun gnus-stop-downloads ()
4609 (when (boundp 'url-queue)
4610 (set (intern "url-queue" obarray) nil)))
4611
4612 ;; Set article window start at LINE, where LINE is the number of lines
4613 ;; from the head of the article.
4614 (defun gnus-article-set-window-start (&optional line)
4615 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4616 (when article-window
4617 (set-window-start
4618 article-window
4619 (with-current-buffer gnus-article-buffer
4620 (goto-char (point-min))
4621 (if (not line)
4622 (point-min)
4623 (gnus-message 6 "Moved to bookmark")
4624 (search-forward "\n\n" nil t)
4625 (forward-line line)
4626 (point)))))))
4627
4628 (defvar gnus-tmp-internal-hook)
4629
4630 (defun gnus-article-prepare (article &optional all-headers _header)
4631 "Prepare ARTICLE in article mode buffer.
4632 ARTICLE should either be an article number or a Message-ID.
4633 If ARTICLE is an id, HEADER should be the article headers.
4634 If ALL-HEADERS is non-nil, no headers are hidden."
4635 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4636 ;; Make sure we start in a summary buffer.
4637 (unless (derived-mode-p 'gnus-summary-mode)
4638 (set-buffer gnus-summary-buffer))
4639 (setq gnus-summary-buffer (current-buffer))
4640 (let* ((summary-buffer (current-buffer))
4641 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4642 (group gnus-newsgroup-name)
4643 result)
4644 (save-excursion
4645 (gnus-article-setup-buffer)
4646 (set-buffer gnus-article-buffer)
4647 ;; Deactivate active regions.
4648 (when (and (boundp 'transient-mark-mode)
4649 transient-mark-mode)
4650 (setq mark-active nil))
4651 (if (not (setq result (let ((inhibit-read-only t))
4652 (gnus-request-article-this-buffer
4653 article group))))
4654 ;; There is no such article.
4655 (save-excursion
4656 (when (and (numberp article)
4657 (not (memq article gnus-newsgroup-sparse)))
4658 (setq gnus-article-current
4659 (cons gnus-newsgroup-name article))
4660 (set-buffer gnus-summary-buffer)
4661 (setq gnus-current-article article)
4662 (if (and (memq article gnus-newsgroup-undownloaded)
4663 (not (gnus-online (gnus-find-method-for-group
4664 gnus-newsgroup-name))))
4665 (progn
4666 (gnus-summary-set-agent-mark article)
4667 (message "Message marked for downloading"))
4668 (gnus-summary-mark-article article gnus-canceled-mark)
4669 (unless (memq article gnus-newsgroup-sparse)
4670 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4671 (if (or (eq result 'pseudo)
4672 (eq result 'nneething))
4673 (progn
4674 (with-current-buffer summary-buffer
4675 (push article gnus-newsgroup-history)
4676 (setq gnus-last-article gnus-current-article
4677 gnus-current-article 0
4678 gnus-current-headers nil
4679 gnus-article-current nil)
4680 (if (eq result 'nneething)
4681 (gnus-configure-windows 'summary)
4682 (gnus-configure-windows 'article))
4683 (gnus-set-global-variables))
4684 (let ((gnus-article-mime-handle-alist-1
4685 gnus-article-mime-handle-alist))
4686 (gnus-set-mode-line 'article)))
4687 ;; The result from the `request' was an actual article -
4688 ;; or at least some text that is now displayed in the
4689 ;; article buffer.
4690 (when (and (numberp article)
4691 (not (eq article gnus-current-article)))
4692 ;; Seems like a new article has been selected.
4693 ;; `gnus-current-article' must be an article number.
4694 (with-current-buffer summary-buffer
4695 (push article gnus-newsgroup-history)
4696 (setq gnus-last-article gnus-current-article
4697 gnus-current-article article
4698 gnus-current-headers
4699 (gnus-summary-article-header gnus-current-article)
4700 gnus-article-current
4701 (cons gnus-newsgroup-name gnus-current-article))
4702 (unless (vectorp gnus-current-headers)
4703 (setq gnus-current-headers nil))
4704 (gnus-summary-goto-subject gnus-current-article)
4705 (when (gnus-summary-show-thread)
4706 ;; If the summary buffer really was folded, the
4707 ;; previous goto may not actually have gone to
4708 ;; the right article, but the thread root instead.
4709 ;; So we go again.
4710 (gnus-summary-goto-subject gnus-current-article))
4711 (gnus-run-hooks 'gnus-mark-article-hook)
4712 (gnus-set-mode-line 'summary)
4713 (when (gnus-visual-p 'article-highlight 'highlight)
4714 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4715 ;; Set the global newsgroup variables here.
4716 (gnus-set-global-variables)
4717 (setq gnus-have-all-headers
4718 (or all-headers gnus-show-all-headers))))
4719 (save-excursion
4720 (gnus-configure-windows 'article))
4721 (when (or (numberp article)
4722 (stringp article))
4723 (gnus-article-prepare-display)
4724 ;; Do page break.
4725 (goto-char (point-min))
4726 (when gnus-break-pages
4727 (gnus-narrow-to-page)))
4728 (let ((gnus-article-mime-handle-alist-1
4729 gnus-article-mime-handle-alist))
4730 (gnus-set-mode-line 'article))
4731 (article-goto-body)
4732 (unless (bobp)
4733 (forward-line -1))
4734 (set-window-point (get-buffer-window (current-buffer)) (point))
4735 (gnus-configure-windows 'article)
4736 (gnus-run-hooks 'gnus-article-prepare-hook)
4737 t))))))
4738
4739 (defvar gnus-mime-display-attachment-buttons-in-header)
4740
4741 ;;;###autoload
4742 (defun gnus-article-prepare-display ()
4743 "Make the current buffer look like a nice article."
4744 ;; Hooks for getting information from the article.
4745 ;; This hook must be called before being narrowed.
4746 (let ((gnus-article-buffer (current-buffer))
4747 buffer-read-only
4748 (inhibit-read-only t))
4749 (unless (derived-mode-p 'gnus-article-mode)
4750 (gnus-article-mode))
4751 (setq buffer-read-only nil
4752 gnus-article-wash-types nil
4753 gnus-article-image-alist nil)
4754 (gnus-run-hooks 'gnus-tmp-internal-hook)
4755 (when gnus-display-mime-function
4756 (funcall gnus-display-mime-function))
4757 ;; Add attachment buttons to the header.
4758 (when gnus-mime-display-attachment-buttons-in-header
4759 (gnus-mime-buttonize-attachments-in-header))))
4760
4761 ;;;
4762 ;;; Gnus Sticky Article Mode
4763 ;;;
4764
4765 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4766 "Mode for sticky articles."
4767 ;; Release bindings that won't work.
4768 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4769 gnus-sticky-article-mode-map)
4770 (substitute-key-definition 'gnus-article-refer-article 'undefined
4771 gnus-sticky-article-mode-map)
4772 (dolist (k '("e" "h" "s" "F" "R"))
4773 (define-key gnus-sticky-article-mode-map k nil))
4774 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4775 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4776 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4777 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4778
4779 (defun gnus-sticky-article (arg)
4780 "Make the current article sticky.
4781 If a prefix ARG is given, ask for a name for this sticky article buffer."
4782 (interactive "P")
4783 (gnus-summary-show-thread)
4784 (gnus-summary-select-article nil nil 'pseudo)
4785 (let (new-art-buf-name)
4786 (gnus-eval-in-buffer-window gnus-article-buffer
4787 (setq new-art-buf-name
4788 (concat
4789 "*Sticky Article: "
4790 (if arg
4791 (read-from-minibuffer "Sticky article buffer name: ")
4792 (gnus-with-article-headers
4793 (gnus-article-goto-header "subject")
4794 (setq new-art-buf-name
4795 (buffer-substring-no-properties
4796 (line-beginning-position) (line-end-position)))
4797 (goto-char (point-min))
4798 (gnus-article-goto-header "from")
4799 (setq new-art-buf-name
4800 (concat
4801 new-art-buf-name ", "
4802 (buffer-substring-no-properties
4803 (line-beginning-position) (line-end-position))))
4804 (goto-char (point-min))
4805 (gnus-article-goto-header "date")
4806 (setq new-art-buf-name
4807 (concat
4808 new-art-buf-name ", "
4809 (buffer-substring-no-properties
4810 (line-beginning-position) (line-end-position))))))
4811 "*"))
4812 (if (and (gnus-buffer-live-p new-art-buf-name)
4813 (with-current-buffer new-art-buf-name
4814 (derived-mode-p 'gnus-sticky-article-mode)))
4815 (switch-to-buffer new-art-buf-name)
4816 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4817 (gnus-sticky-article-mode))
4818 (setq gnus-article-buffer new-art-buf-name))
4819 (gnus-summary-recenter)
4820 (gnus-summary-position-point))
4821
4822 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4823 "Kill the given sticky article BUFFER.
4824 If none is given, assume the current buffer and kill it if it has
4825 `gnus-sticky-article-mode'."
4826 (interactive)
4827 (unless buffer
4828 (setq buffer (current-buffer)))
4829 (with-current-buffer buffer
4830 (when (derived-mode-p 'gnus-sticky-article-mode)
4831 (gnus-kill-buffer buffer))))
4832
4833 (defun gnus-kill-sticky-article-buffers (arg)
4834 "Kill all sticky article buffers.
4835 If a prefix ARG is given, ask for confirmation."
4836 (interactive "P")
4837 (dolist (buf (gnus-buffers))
4838 (with-current-buffer buf
4839 (when (derived-mode-p 'gnus-sticky-article-mode)
4840 (if (not arg)
4841 (gnus-kill-buffer buf)
4842 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4843 (gnus-kill-buffer buf)))))))
4844
4845 ;;;
4846 ;;; Gnus MIME viewing functions
4847 ;;;
4848
4849 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4850 "Format of the MIME buttons.
4851
4852 Valid specifiers include:
4853 %t The MIME type
4854 %T MIME type, along with additional info
4855 %n The `name' parameter
4856 %d The description, if any
4857 %l The length of the encoded part
4858 %p The part identifier number
4859 %e Dots if the part isn't displayed
4860
4861 General format specifiers can also be used. See Info node
4862 `(gnus)Formatting Variables'.")
4863
4864 (defvar gnus-tmp-type)
4865 (defvar gnus-tmp-type-long)
4866 (defvar gnus-tmp-name)
4867 (defvar gnus-tmp-description)
4868 (defvar gnus-tmp-id)
4869 (defvar gnus-tmp-length)
4870 (defvar gnus-tmp-dots)
4871 (defvar gnus-tmp-info)
4872 (defvar gnus-tmp-pressed-details)
4873
4874 (defvar gnus-mime-button-line-format-alist
4875 '((?t gnus-tmp-type ?s)
4876 (?T gnus-tmp-type-long ?s)
4877 (?n gnus-tmp-name ?s)
4878 (?d gnus-tmp-description ?s)
4879 (?p gnus-tmp-id ?s)
4880 (?l gnus-tmp-length ?d)
4881 (?e gnus-tmp-dots ?s)))
4882
4883 (defvar gnus-mime-button-commands
4884 '((gnus-article-press-button "\r" "Toggle Display")
4885 (gnus-mime-view-part "v" "View Interactively...")
4886 (gnus-mime-view-part-as-type "t" "View As Type...")
4887 (gnus-mime-view-part-as-charset "C" "View As charset...")
4888 (gnus-mime-save-part "o" "Save...")
4889 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4890 (gnus-mime-replace-part "r" "Replace part")
4891 (gnus-mime-delete-part "d" "Delete part")
4892 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4893 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4894 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4895 (gnus-mime-view-part-externally "e" "View Externally")
4896 (gnus-mime-print-part "p" "Print")
4897 (gnus-mime-pipe-part "|" "Pipe To Command...")
4898 (gnus-mime-action-on-part "." "Take action on the part...")))
4899
4900 (defun gnus-article-mime-part-status ()
4901 (if gnus-article-mime-handle-alist-1
4902 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4903 " (1 part)"
4904 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4905 ""))
4906
4907 (defvar gnus-mime-button-map
4908 (let ((map (make-sparse-keymap)))
4909 (define-key map gnus-mouse-2 'gnus-article-push-button)
4910 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4911 (dolist (c gnus-mime-button-commands)
4912 (define-key map (cadr c) (car c)))
4913 map))
4914
4915 (easy-menu-define
4916 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4917 `("MIME Part"
4918 ,@(mapcar (lambda (c)
4919 (vector (caddr c) (car c) :active t))
4920 gnus-mime-button-commands)))
4921
4922 (defvar gnus-url-button-commands
4923 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4924
4925 (defvar gnus-url-button-map
4926 (let ((map (make-sparse-keymap)))
4927 (dolist (c gnus-url-button-commands)
4928 (define-key map (cadr c) (car c)))
4929 map))
4930
4931 (easy-menu-define
4932 gnus-url-button-menu gnus-url-button-map "URL button menu."
4933 `("Url Button"
4934 ,@(mapcar (lambda (c)
4935 (vector (caddr c) (car c) :active t))
4936 gnus-url-button-commands)))
4937
4938 (defmacro gnus-bind-mm-vars (&rest body)
4939 "Bind some mm-* variables and execute BODY."
4940 `(let (mm-html-inhibit-images
4941 mm-html-blocked-images
4942 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4943 (with-current-buffer
4944 (cond ((derived-mode-p 'gnus-article-mode)
4945 (if (gnus-buffer-live-p gnus-article-current-summary)
4946 gnus-article-current-summary
4947 ;; Maybe we're in a mml-preview buffer
4948 ;; and no group is selected.
4949 (current-buffer)))
4950 ((gnus-buffer-live-p gnus-summary-buffer)
4951 gnus-summary-buffer)
4952 (t (current-buffer)))
4953 (setq mm-html-inhibit-images gnus-inhibit-images
4954 mm-html-blocked-images (gnus-blocked-images))
4955 (when (or (not gnus-newsgroup-name)
4956 (and (stringp gnus-safe-html-newsgroups)
4957 (string-match gnus-safe-html-newsgroups
4958 gnus-newsgroup-name))
4959 (and (consp gnus-safe-html-newsgroups)
4960 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4961 (setq mm-w3m-safe-url-regexp nil)))
4962 ,@body))
4963
4964 (defun gnus-mime-button-menu (event prefix)
4965 "Construct a context-sensitive menu of MIME commands."
4966 (interactive "e\nP")
4967 (save-window-excursion
4968 (let ((pos (event-start event)))
4969 (select-window (posn-window pos))
4970 (goto-char (posn-point pos))
4971 (gnus-article-check-buffer)
4972 (popup-menu gnus-mime-button-menu nil prefix))))
4973
4974 (defun gnus-mime-view-all-parts (&optional handles)
4975 "View all the MIME parts."
4976 (interactive)
4977 (with-current-buffer gnus-article-buffer
4978 (let ((handles (or handles gnus-article-mime-handles))
4979 (mail-parse-charset gnus-newsgroup-charset)
4980 (mail-parse-ignored-charsets
4981 (with-current-buffer gnus-summary-buffer
4982 gnus-newsgroup-ignored-charsets)))
4983 (when handles
4984 (mm-remove-parts handles)
4985 (goto-char (point-min))
4986 (or (search-forward "\n\n") (goto-char (point-max)))
4987 (let ((inhibit-read-only t))
4988 (delete-region (point) (point-max))
4989 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4990
4991 (defun gnus-article-jump-to-part (n)
4992 "Jump to MIME part N."
4993 (interactive "P")
4994 (let ((parts (with-current-buffer gnus-article-buffer
4995 (length gnus-article-mime-handle-alist))))
4996 (when (zerop parts)
4997 (error "No such part"))
4998 (pop-to-buffer gnus-article-buffer)
4999 (or n
5000 (setq n (if (= parts 1)
5001 1
5002 (read-number (format "Jump to part (1..%s): " parts)))))
5003 (unless (and (integerp n) (<= n parts) (>= n 1))
5004 (setq n
5005 (progn
5006 (gnus-message 7 "Invalid part `%s', using %s instead."
5007 n parts)
5008 parts)))
5009 (gnus-message 9 "Jumping to part %s." n)
5010 (cond ((>= gnus-auto-select-part 1)
5011 (while (and (<= n parts)
5012 (not (gnus-article-goto-part n)))
5013 (setq n (1+ n))))
5014 ((< gnus-auto-select-part 0)
5015 (while (and (>= n 1)
5016 (not (gnus-article-goto-part n)))
5017 (setq n (1- n))))
5018 (t
5019 (gnus-article-goto-part n)))))
5020
5021 (defvar gnus-mime-buttonized-part-id nil
5022 "ID of a mime part that should be buttonized.
5023 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5024
5025 (eval-when-compile
5026 (defsubst gnus-article-edit-part (handles &optional current-id)
5027 "Edit an article in order to delete a mime part.
5028 This function is exclusively used by `gnus-mime-save-part-and-strip'
5029 and `gnus-mime-delete-part', and not provided at run-time normally."
5030 (gnus-article-edit-article
5031 `(lambda ()
5032 (buffer-disable-undo)
5033 (let ((mail-parse-charset (or gnus-article-charset
5034 ',gnus-newsgroup-charset))
5035 (mail-parse-ignored-charsets
5036 (or gnus-article-ignored-charsets
5037 ',gnus-newsgroup-ignored-charsets))
5038 (mbl mml-buffer-list))
5039 (setq mml-buffer-list nil)
5040 ;; A new text must be inserted before deleting existing ones
5041 ;; at the end so as not to move existing markers of which
5042 ;; the insertion type is t.
5043 (delete-region
5044 (point-min)
5045 (prog1
5046 (goto-char (point-max))
5047 (insert-buffer-substring gnus-original-article-buffer)))
5048 (mime-to-mml ',handles)
5049 (setq gnus-article-mime-handles nil)
5050 (let ((mbl1 mml-buffer-list))
5051 (setq mml-buffer-list mbl)
5052 (set (make-local-variable 'mml-buffer-list) mbl1))
5053 (gnus-make-local-hook 'kill-buffer-hook)
5054 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5055 `(lambda (no-highlight)
5056 (let ((mail-parse-charset (or gnus-article-charset
5057 ',gnus-newsgroup-charset))
5058 (message-options message-options)
5059 (message-options-set-recipient)
5060 (mail-parse-ignored-charsets
5061 (or gnus-article-ignored-charsets
5062 ',gnus-newsgroup-ignored-charsets)))
5063 (mml-to-mime)
5064 (mml-destroy-buffers)
5065 (remove-hook 'kill-buffer-hook
5066 'mml-destroy-buffers t)
5067 (kill-local-variable 'mml-buffer-list))
5068 (gnus-summary-edit-article-done
5069 ,(or (mail-header-references gnus-current-headers) "")
5070 ,(gnus-group-read-only-p)
5071 ,gnus-summary-buffer no-highlight))
5072 t)
5073 ;; Force buttonizing this part.
5074 (let ((gnus-mime-buttonized-part-id current-id))
5075 (gnus-article-edit-done))
5076 (gnus-configure-windows 'article)
5077 (sit-for 0)
5078 (when (and current-id (integerp gnus-auto-select-part))
5079 (gnus-article-jump-to-part
5080 (min (max (+ current-id gnus-auto-select-part) 1)
5081 (with-current-buffer gnus-article-buffer
5082 (length gnus-article-mime-handle-alist)))))))
5083
5084 (defun gnus-mime-replace-part (file)
5085 "Replace MIME part under point with an external body."
5086 ;; Useful if file has already been saved to disk
5087 (interactive
5088 (list
5089 (read-file-name "Replace MIME part with file: "
5090 (or mm-default-directory default-directory)
5091 nil nil)))
5092 (gnus-mime-save-part-and-strip file))
5093
5094 (defun gnus-mime-save-part-and-strip (&optional file)
5095 "Save the MIME part under point then replace it with an external body.
5096 If FILE is given, use it for the external part."
5097 (interactive)
5098 (gnus-article-check-buffer)
5099 (when (gnus-group-read-only-p)
5100 (error "The current group does not support deleting of parts"))
5101 (when (mm-complicated-handles gnus-article-mime-handles)
5102 (error "\
5103 The current article has a complicated MIME structure, giving up..."))
5104 (let* ((data (get-text-property (point) 'gnus-data))
5105 (id (get-text-property (point) 'gnus-part))
5106 (handles gnus-article-mime-handles))
5107 (unless file
5108 (setq file
5109 (and data (mm-save-part data "Delete MIME part and save to: "))))
5110 (when file
5111 (with-current-buffer (mm-handle-buffer data)
5112 (erase-buffer)
5113 (insert "Content-Type: " (mm-handle-media-type data))
5114 (mml-insert-parameter-string (cdr (mm-handle-type data))
5115 '(charset))
5116 ;; Add a filename for the sake of saving the part again.
5117 (mml-insert-parameter
5118 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5119 (insert "\n")
5120 (insert "Content-ID: " (message-make-message-id) "\n")
5121 (insert "Content-Transfer-Encoding: binary\n")
5122 (insert "\n"))
5123 (setcdr data
5124 (cdr (mm-make-handle nil
5125 `("message/external-body"
5126 (access-type . "LOCAL-FILE")
5127 (name . ,file)))))
5128 ;; (set-buffer gnus-summary-buffer)
5129 (gnus-article-edit-part handles id))))
5130
5131 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5132 ;; parts...>') but with stripping would be nice.
5133
5134 (defun gnus-mime-delete-part ()
5135 "Delete the MIME part under point.
5136 Replace it with some information about the removed part."
5137 (interactive)
5138 (gnus-article-check-buffer)
5139 (when (gnus-group-read-only-p)
5140 (error "The current group does not support deleting of parts"))
5141 (when (mm-complicated-handles gnus-article-mime-handles)
5142 (error "\
5143 The current article has a complicated MIME structure, giving up..."))
5144 (when (or gnus-expert-user
5145 (gnus-yes-or-no-p "\
5146 Deleting parts may malfunction or destroy the article; continue? "))
5147 (let* ((data (get-text-property (point) 'gnus-data))
5148 (id (get-text-property (point) 'gnus-part))
5149 (handles gnus-article-mime-handles)
5150 (description
5151 (let ((desc (mm-handle-description data)))
5152 (when desc
5153 (mail-decode-encoded-word-string desc))))
5154 (filename (or (mm-handle-filename data) "(none)"))
5155 (type (mm-handle-media-type data)))
5156 (unless data
5157 (error "No MIME part under point"))
5158 (with-current-buffer (mm-handle-buffer data)
5159 (let ((bsize (buffer-size)))
5160 (erase-buffer)
5161 (insert
5162 (concat
5163 ",----\n"
5164 "| The following attachment has been deleted:\n"
5165 "|\n"
5166 "| Type: " type "\n"
5167 "| Filename: " filename "\n"
5168 "| Size (encoded): " (format "%s byte%s\n"
5169 bsize (if (= bsize 1)
5170 ""
5171 "s"))
5172 (when description
5173 (concat "| Description: " description "\n"))
5174 "`----\n"))
5175 (setcdr data
5176 (cdr (mm-make-handle
5177 nil `("text/plain" (charset . gnus-decoded)) nil nil
5178 (list "attachment")
5179 (format "Deleted attachment (%s bytes)" bsize))))))
5180 ;; (set-buffer gnus-summary-buffer)
5181 (gnus-article-edit-part handles id))))
5182
5183 (defun gnus-mime-save-part ()
5184 "Save the MIME part under point."
5185 (interactive)
5186 (gnus-article-check-buffer)
5187 (let ((data (get-text-property (point) 'gnus-data)))
5188 (when data
5189 (mm-save-part data))))
5190
5191 (defun gnus-mime-pipe-part (&optional cmd)
5192 "Pipe the MIME part under point to a process.
5193 Use CMD as the process."
5194 (interactive)
5195 (gnus-article-check-buffer)
5196 (let ((data (get-text-property (point) 'gnus-data)))
5197 (when data
5198 (mm-pipe-part data cmd))))
5199
5200 (defun gnus-mime-view-part ()
5201 "Interactively choose a viewing method for the MIME part under point."
5202 (interactive)
5203 (gnus-article-check-buffer)
5204 (let ((data (get-text-property (point) 'gnus-data)))
5205 (when data
5206 (setq gnus-article-mime-handles
5207 (mm-merge-handles
5208 gnus-article-mime-handles (setq data (copy-sequence data))))
5209 (mm-interactively-view-part data))))
5210
5211 (defun gnus-mime-view-part-as-type-internal ()
5212 (gnus-article-check-buffer)
5213 (let* ((handle (get-text-property (point) 'gnus-data))
5214 (name (or
5215 ;; Content-Type: foo/bar; name=...
5216 (mail-content-type-get (mm-handle-type handle) 'name)
5217 ;; Content-Disposition: attachment; filename=...
5218 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5219 (def-type (and name (mm-default-file-encoding name))))
5220 (or (and def-type (cons def-type 0))
5221 (and handle
5222 (equal (mm-handle-media-supertype handle) "text")
5223 '("text/plain" . 0))
5224 '("application/octet-stream" . 0))))
5225
5226 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5227 "Choose a MIME media type, and view the part as such.
5228 If non-nil, PRED is a predicate to use during completion to limit the
5229 available media-types."
5230 (interactive)
5231 (unless mime-type
5232 (setq mime-type
5233 (let ((default (gnus-mime-view-part-as-type-internal)))
5234 (gnus-completing-read
5235 "View as MIME type"
5236 (if pred
5237 (gnus-remove-if-not pred (mailcap-mime-types))
5238 (mailcap-mime-types))
5239 nil nil nil
5240 (car default)))))
5241 (gnus-article-check-buffer)
5242 (let ((handle (get-text-property (point) 'gnus-data)))
5243 (when handle
5244 (when (equal (mm-handle-media-type handle) "message/external-body")
5245 (unless (mm-handle-cache handle)
5246 (mm-extern-cache-contents handle))
5247 (setq handle (mm-handle-cache handle)))
5248 (setq handle
5249 (mm-make-handle (mm-handle-buffer handle)
5250 (cons mime-type (cdr (mm-handle-type handle)))
5251 (mm-handle-encoding handle)
5252 (mm-handle-undisplayer handle)
5253 (mm-handle-disposition handle)
5254 (mm-handle-description handle)
5255 nil
5256 (mm-handle-id handle)))
5257 (setq gnus-article-mime-handles
5258 (mm-merge-handles gnus-article-mime-handles handle))
5259 (when (mm-handle-displayed-p handle)
5260 (mm-remove-part handle))
5261 (gnus-mm-display-part handle))))
5262
5263 (defun gnus-mime-copy-part (&optional handle arg)
5264 "Put the MIME part under point into a new buffer.
5265 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5266 are decompressed."
5267 (interactive (list nil current-prefix-arg))
5268 (gnus-article-check-buffer)
5269 (unless handle
5270 (setq handle (get-text-property (point) 'gnus-data)))
5271 (when handle
5272 (let ((filename (mm-handle-filename handle))
5273 contents dont-decode charset coding-system)
5274 (mm-with-unibyte-buffer
5275 (mm-insert-part handle)
5276 (setq contents (or (condition-case nil
5277 (mm-decompress-buffer filename nil 'sig)
5278 (error
5279 (setq dont-decode t)
5280 nil))
5281 (buffer-string))))
5282 (setq filename (cond (filename (file-name-nondirectory filename))
5283 (dont-decode "*raw data*")
5284 (t "*decoded*")))
5285 (cond
5286 (dont-decode)
5287 ((not arg)
5288 (unless (setq charset (mail-content-type-get
5289 (mm-handle-type handle) 'charset))
5290 (unless (setq coding-system (mm-with-unibyte-buffer
5291 (insert contents)
5292 (mm-find-buffer-file-coding-system)))
5293 (setq charset gnus-newsgroup-charset))))
5294 ((numberp arg)
5295 (setq charset (or (cdr (assq arg
5296 gnus-summary-show-article-charset-alist))
5297 (mm-read-coding-system "Charset: ")))))
5298 (switch-to-buffer (generate-new-buffer filename))
5299 (if (or coding-system
5300 (and charset
5301 (setq coding-system (mm-charset-to-coding-system
5302 charset nil t))
5303 (not (eq coding-system 'ascii))))
5304 (progn
5305 (mm-enable-multibyte)
5306 (insert (mm-decode-coding-string contents coding-system))
5307 (setq buffer-file-coding-system
5308 (if (boundp 'last-coding-system-used)
5309 (symbol-value 'last-coding-system-used)
5310 coding-system)))
5311 (mm-disable-multibyte)
5312 (insert contents)
5313 (setq buffer-file-coding-system mm-binary-coding-system))
5314 ;; We do it this way to make `normal-mode' set the appropriate mode.
5315 (unwind-protect
5316 (progn
5317 (setq buffer-file-name (expand-file-name filename))
5318 (normal-mode))
5319 (setq buffer-file-name nil))
5320 (goto-char (point-min)))))
5321
5322 (defun gnus-mime-print-part (&optional handle filename)
5323 "Print the MIME part under point."
5324 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5325 (gnus-article-check-buffer)
5326 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5327 (contents (and handle (mm-get-part handle)))
5328 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5329 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5330 (when contents
5331 (if printer
5332 (unwind-protect
5333 (progn
5334 (mm-save-part-to-file handle file)
5335 (call-process shell-file-name nil
5336 (generate-new-buffer " *mm*")
5337 nil
5338 shell-command-switch
5339 (mm-mailcap-command
5340 printer file (mm-handle-type handle))))
5341 (delete-file file))
5342 (with-temp-buffer
5343 (insert contents)
5344 (gnus-print-buffer))
5345 (ps-despool filename)))))
5346
5347 (defun gnus-mime-inline-part (&optional handle arg)
5348 "Insert the MIME part under point into the current buffer.
5349 Compressed files like .gz and .bz2 are decompressed."
5350 (interactive (list nil current-prefix-arg))
5351 (gnus-article-check-buffer)
5352 (let* ((inhibit-read-only t)
5353 (b (point))
5354 (btn ;; position where the MIME button exists
5355 (if handle
5356 (if (eq handle (get-text-property b 'gnus-data))
5357 b
5358 (article-goto-body)
5359 (or (text-property-any (point) (point-max) 'gnus-data handle)
5360 (text-property-any (point-min) (point) 'gnus-data handle)))
5361 (setq handle (get-text-property b 'gnus-data))
5362 b))
5363 start)
5364 (when handle
5365 (when (= b (prog1
5366 btn
5367 (setq start (next-single-property-change btn 'gnus-data
5368 nil (point-max))
5369 btn (previous-single-property-change start
5370 'gnus-data))))
5371 (setq b btn))
5372 (if (and (not arg) (mm-handle-undisplayer handle))
5373 (progn
5374 (setq b (copy-marker b)
5375 btn (copy-marker btn))
5376 (mm-remove-part handle))
5377 (cond
5378 ((not arg) nil)
5379 ((numberp arg)
5380 (if (mm-handle-undisplayer handle)
5381 (mm-remove-part handle)))
5382 ((mm-handle-undisplayer handle)
5383 (mm-remove-part handle)))
5384 (goto-char start)
5385 (unless (bolp)
5386 ;; This is a header button.
5387 (forward-line 1))
5388 (mm-display-inline handle))
5389 ;; Toggle the button appearance between `[button]...' and `[button]'.
5390 (when (markerp btn)
5391 (setq btn (prog1 (marker-position btn)
5392 (set-marker btn nil))))
5393 (goto-char btn)
5394 (let ((displayed-p (mm-handle-displayed-p handle)))
5395 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5396 (list displayed-p))
5397 (if (featurep 'emacs)
5398 (delete-region
5399 (point)
5400 (next-single-property-change (point) 'gnus-data nil (point-max)))
5401 (let* ((end (next-single-property-change (point) 'gnus-data))
5402 (annots (annotations-at (or end (point-max)))))
5403 (delete-region (point)
5404 (if end
5405 (if annots (1+ end) end)
5406 (point-max)))
5407 (dolist (annot annots)
5408 (set-extent-endpoints annot (point) (point)))))
5409 (setq start (point))
5410 (if (search-backward "\n\n" nil t)
5411 (progn
5412 (goto-char start)
5413 (unless (or displayed-p (eolp))
5414 ;; Add extra newline.
5415 (insert (propertize (buffer-substring (1- start) start)
5416 'gnus-undeletable t))))
5417 ;; We're in the article header.
5418 (delete-char -1)
5419 (dolist (ovl (overlays-in btn (point)))
5420 (overlay-put ovl 'gnus-button-attachment-extra t)
5421 (overlay-put ovl 'face nil))
5422 (save-restriction
5423 (message-narrow-to-field)
5424 (let ((gnus-treatment-function-alist
5425 '((gnus-treat-highlight-headers
5426 gnus-article-highlight-headers))))
5427 (gnus-treat-article 'head)))))
5428 (when (markerp b)
5429 (setq b (prog1 (marker-position b)
5430 (set-marker b nil))))
5431 (goto-char b))))
5432
5433 (defun gnus-mime-set-charset-parameters (handle charset)
5434 "Set CHARSET to parameters in HANDLE.
5435 CHARSET may either be a string or a symbol."
5436 (unless (stringp charset)
5437 (setq charset (symbol-name charset)))
5438 (if (stringp (car handle))
5439 (dolist (h (cdr handle))
5440 (gnus-mime-set-charset-parameters h charset))
5441 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5442 "message/external-body")
5443 (progn
5444 (unless (mm-handle-cache handle)
5445 (mm-extern-cache-contents handle))
5446 (mm-handle-cache handle))
5447 handle)))
5448 (param (assq 'charset (cdr type))))
5449 (if param
5450 (setcdr param charset)
5451 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5452
5453 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5454 "Insert the MIME part under point into the current buffer using the
5455 specified charset."
5456 (interactive (list nil current-prefix-arg))
5457 (gnus-article-check-buffer)
5458 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5459 (fun (get-text-property (point) 'gnus-callback))
5460 (gnus-newsgroup-ignored-charsets 'gnus-all)
5461 charset form preferred parts)
5462 (when handle
5463 (when (prog1
5464 (and fun
5465 (setq charset
5466 (or (cdr (assq
5467 arg
5468 gnus-summary-show-article-charset-alist))
5469 (mm-read-coding-system "Charset: "))))
5470 (if (mm-handle-undisplayer handle)
5471 (mm-remove-part handle)))
5472 (gnus-mime-set-charset-parameters handle charset)
5473 (when (and (consp (setq form (cdr-safe fun)))
5474 (setq form (ignore-errors
5475 (assq 'gnus-mime-display-alternative form)))
5476 (setq preferred (caddr form))
5477 (progn
5478 (when (eq (car preferred) 'quote)
5479 (setq preferred (cadr preferred)))
5480 (not (equal preferred
5481 (get-text-property (point) 'gnus-data))))
5482 (setq parts (get-text-property (point) 'gnus-part))
5483 (setq parts (cdr (assq parts
5484 gnus-article-mime-handle-alist)))
5485 (equal (mm-handle-media-type parts) "multipart/alternative")
5486 (setq parts (reverse (cdr parts))))
5487 (setcar (cddr form)
5488 (list 'quote (or (cadr (member preferred parts))
5489 (car parts)))))
5490 (funcall fun handle)))))
5491
5492 (defun gnus-mime-view-part-externally (&optional handle)
5493 "View the MIME part under point with an external viewer."
5494 (interactive)
5495 (gnus-article-check-buffer)
5496 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5497 (mm-inlined-types nil)
5498 (mail-parse-charset gnus-newsgroup-charset)
5499 (mail-parse-ignored-charsets
5500 (with-current-buffer gnus-summary-buffer
5501 gnus-newsgroup-ignored-charsets))
5502 (type (mm-handle-media-type handle))
5503 (method (mailcap-mime-info type))
5504 (mm-enable-external t))
5505 (if (not (stringp method))
5506 (gnus-mime-view-part-as-type
5507 nil (lambda (type) (stringp (mailcap-mime-info type))))
5508 (when handle
5509 (mm-display-part handle nil t)))))
5510
5511 (defun gnus-mime-view-part-internally (&optional handle)
5512 "View the MIME part under point with an internal viewer.
5513 If no internal viewer is available, use an external viewer."
5514 (interactive)
5515 (gnus-article-check-buffer)
5516 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5517 (mm-inlined-types '(".*"))
5518 (mm-inline-large-images t)
5519 (mail-parse-charset gnus-newsgroup-charset)
5520 (mail-parse-ignored-charsets
5521 (with-current-buffer gnus-summary-buffer
5522 gnus-newsgroup-ignored-charsets))
5523 (inhibit-read-only t))
5524 (if (not (mm-inlinable-p handle))
5525 (gnus-mime-view-part-as-type
5526 nil (lambda (type) (mm-inlinable-p handle type)))
5527 (when handle
5528 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5529
5530 (defun gnus-mime-action-on-part (&optional action)
5531 "Do something with the MIME attachment at (point)."
5532 (interactive
5533 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5534 (gnus-article-check-buffer)
5535 (let ((action-pair (assoc action gnus-mime-action-alist)))
5536 (if action-pair
5537 (funcall (cdr action-pair)))))
5538
5539 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5540 "Call FUNCTION on MIME part N.
5541 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5542 If INTERACTIVE, call FUNCTION interactively."
5543 (let (window frame)
5544 ;; Check whether the article is displayed.
5545 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5546 (setq window (get-buffer-window gnus-article-buffer t))
5547 (frame-visible-p (setq frame (window-frame window))))
5548 (error "No article is displayed"))
5549 (with-current-buffer gnus-article-buffer
5550 ;; Check whether the article displays the right contents.
5551 (unless (with-current-buffer gnus-summary-buffer
5552 (eq gnus-current-article (gnus-summary-article-number)))
5553 (error "You should select the right article first"))
5554 (if n
5555 (setq n (prefix-numeric-value n))
5556 (let ((pt (point)))
5557 (setq n (or (get-text-property pt 'gnus-part)
5558 (and (not (bobp))
5559 (get-text-property (1- pt) 'gnus-part))
5560 (get-text-property (prog2
5561 (forward-line 1)
5562 (point)
5563 (goto-char pt))
5564 'gnus-part)
5565 (get-text-property
5566 (or (and (setq pt (previous-single-property-change
5567 pt 'gnus-part))
5568 (1- pt))
5569 (next-single-property-change (point) 'gnus-part)
5570 (point))
5571 'gnus-part)
5572 1))))
5573 ;; Check whether the specified part exists.
5574 (when (> n (length gnus-article-mime-handle-alist))
5575 (error "No such part")))
5576 (unless
5577 (progn
5578 ;; To select the window is needed so that the cursor
5579 ;; might be visible on the MIME button.
5580 (select-window (prog1
5581 window
5582 (setq window (selected-window))
5583 ;; Article may be displayed in the other frame.
5584 (gnus-select-frame-set-input-focus
5585 (prog1
5586 frame
5587 (setq frame (selected-frame))))))
5588 (when (gnus-article-goto-part n)
5589 ;; We point the cursor and the arrow at the MIME button
5590 ;; when the `function' prompt the user for something.
5591 (unless (and (pos-visible-in-window-p)
5592 (> (count-lines (point) (window-end))
5593 (/ (1- (window-height)) 3)))
5594 (recenter (/ (1- (window-height)) 3)))
5595 (let ((cursor-in-non-selected-windows t)
5596 (overlay-arrow-string "=>")
5597 (overlay-arrow-position (point-marker)))
5598 (unwind-protect
5599 (cond
5600 ((and no-handle interactive)
5601 (call-interactively function))
5602 (no-handle
5603 (funcall function))
5604 (interactive
5605 (call-interactively
5606 function (get-text-property (point) 'gnus-data)))
5607 (t
5608 (funcall function
5609 (get-text-property (point) 'gnus-data))))
5610 (set-marker overlay-arrow-position nil)
5611 (unless gnus-auto-select-part
5612 (gnus-select-frame-set-input-focus frame)
5613 (select-window window))))
5614 t))
5615 (if gnus-inhibit-mime-unbuttonizing
5616 ;; This is the default though the program shouldn't reach here.
5617 (error "No such part")
5618 ;; The part which doesn't have the MIME button is selected.
5619 ;; So, we display all the buttons and redo it.
5620 (let ((gnus-inhibit-mime-unbuttonizing t))
5621 (gnus-summary-show-article)
5622 (gnus-article-part-wrapper n function no-handle))))))
5623
5624 (defun gnus-article-pipe-part (n)
5625 "Pipe MIME part N, which is the numerical prefix."
5626 (interactive "P")
5627 (gnus-article-part-wrapper n 'mm-pipe-part))
5628
5629 (defun gnus-article-save-part (n)
5630 "Save MIME part N, which is the numerical prefix."
5631 (interactive "P")
5632 (gnus-article-part-wrapper n 'mm-save-part))
5633
5634 (defun gnus-article-interactively-view-part (n)
5635 "View MIME part N interactively, which is the numerical prefix."
5636 (interactive "P")
5637 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5638
5639 (defun gnus-article-copy-part (n)
5640 "Copy MIME part N, which is the numerical prefix."
5641 (interactive "P")
5642 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5643
5644 (defun gnus-article-view-part-as-charset (n)
5645 "View MIME part N using a specified charset.
5646 N is the numerical prefix."
5647 (interactive "P")
5648 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5649
5650 (defun gnus-article-view-part-externally (n)
5651 "View MIME part N externally, which is the numerical prefix."
5652 (interactive "P")
5653 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5654
5655 (defun gnus-article-inline-part (n)
5656 "Inline MIME part N, which is the numerical prefix."
5657 (interactive "P")
5658 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5659
5660 (defun gnus-article-save-part-and-strip (n)
5661 "Save MIME part N and replace it with an external body.
5662 N is the numerical prefix."
5663 (interactive "P")
5664 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5665
5666 (defun gnus-article-replace-part (n)
5667 "Replace MIME part N with an external body.
5668 N is the numerical prefix."
5669 (interactive "P")
5670 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5671
5672 (defun gnus-article-delete-part (n)
5673 "Delete MIME part N and add some information about the removed part.
5674 N is the numerical prefix."
5675 (interactive "P")
5676 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5677
5678 (defun gnus-article-view-part-as-type (n)
5679 "Choose a MIME media type, and view part N as such.
5680 N is the numerical prefix."
5681 (interactive "P")
5682 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5683
5684 (defun gnus-article-mime-match-handle-first (condition)
5685 (if condition
5686 (let (n)
5687 (dolist (ihandle gnus-article-mime-handle-alist)
5688 (if (and (cond
5689 ((functionp condition)
5690 (funcall condition (cdr ihandle)))
5691 ((eq condition 'undisplayed)
5692 (not (or (mm-handle-undisplayer (cdr ihandle))
5693 (equal (mm-handle-media-type (cdr ihandle))
5694 "multipart/alternative"))))
5695 ((eq condition 'undisplayed-alternative)
5696 (not (mm-handle-undisplayer (cdr ihandle))))
5697 (t t))
5698 (gnus-article-goto-part (car ihandle))
5699 (or (not n) (< (car ihandle) n)))
5700 (setq n (car ihandle))))
5701 (or n 1))
5702 1))
5703
5704 (defun gnus-article-view-part (&optional n)
5705 "View MIME part N, which is the numerical prefix.
5706 If the part is already shown, hide the part. If N is nil, view
5707 all parts."
5708 (interactive "P")
5709 (with-current-buffer gnus-article-buffer
5710 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5711 gnus-article-mime-match-handle-function)))
5712 (when (> n (length gnus-article-mime-handle-alist))
5713 (error "No such part"))
5714 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5715 (when (gnus-article-goto-part n)
5716 (if (equal (car handle) "multipart/alternative")
5717 (progn
5718 (beginning-of-line) ;; Make it toggle subparts
5719 (gnus-article-press-button))
5720 (when (eq (gnus-mm-display-part handle) 'internal)
5721 (gnus-set-window-start)))))))
5722
5723 (defsubst gnus-article-mime-total-parts ()
5724 (if (bufferp (car gnus-article-mime-handles))
5725 1 ;; single part
5726 (1- (length gnus-article-mime-handles))))
5727
5728 (defun gnus-mm-display-part (handle)
5729 "Display HANDLE and fix MIME button."
5730 (let ((id (get-text-property (point) 'gnus-part))
5731 (point (point))
5732 (inhibit-read-only t)
5733 (window (selected-window))
5734 (mail-parse-charset gnus-newsgroup-charset)
5735 (mail-parse-ignored-charsets
5736 (if (gnus-buffer-live-p gnus-summary-buffer)
5737 (with-current-buffer gnus-summary-buffer
5738 gnus-newsgroup-ignored-charsets)
5739 nil))
5740 start retval)
5741 (unwind-protect
5742 (progn
5743 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5744 (when win
5745 (select-window win)
5746 (goto-char point)))
5747 (setq start (next-single-property-change point 'gnus-data
5748 nil (point-max))
5749 point (previous-single-property-change start 'gnus-data))
5750 (if (mm-handle-displayed-p handle)
5751 ;; This will remove the part.
5752 (setq point (copy-marker point)
5753 retval (mm-display-part handle))
5754 (let ((part (or (and (mm-inlinable-p handle)
5755 (mm-inlined-p handle)
5756 t)
5757 (with-temp-buffer
5758 (gnus-bind-mm-vars
5759 (setq retval (mm-display-part handle)))
5760 (unless (zerop (buffer-size))
5761 (buffer-string))))))
5762 (goto-char start)
5763 (unless (bolp)
5764 ;; This is a header button.
5765 (forward-line 1))
5766 (cond ((stringp part)
5767 (save-restriction
5768 (narrow-to-region (point)
5769 (progn
5770 (insert part)
5771 (unless (bolp) (insert "\n"))
5772 (point)))
5773 (gnus-treat-article nil id
5774 (gnus-article-mime-total-parts)
5775 (mm-handle-media-type handle))
5776 (mm-handle-set-undisplayer
5777 handle
5778 `(lambda ()
5779 (let ((inhibit-read-only t))
5780 (delete-region ,(copy-marker (point-min) t)
5781 ,(point-max-marker)))))))
5782 (part
5783 (mm-display-inline handle))))))
5784 (when (markerp point)
5785 (setq point (prog1 (marker-position point)
5786 (set-marker point nil))))
5787 (goto-char point)
5788 ;; Toggle the button appearance between `[button]...' and `[button]'.
5789 (let ((displayed-p (mm-handle-displayed-p handle)))
5790 (gnus-insert-mime-button handle id (list displayed-p))
5791 (if (featurep 'emacs)
5792 (delete-region
5793 (point)
5794 (next-single-property-change (point) 'gnus-data nil (point-max)))
5795 (let* ((end (next-single-property-change (point) 'gnus-data))
5796 (annots (annotations-at (or end (point-max)))))
5797 (delete-region (point)
5798 (if end
5799 (if annots (1+ end) end)
5800 (point-max)))
5801 (dolist (annot annots)
5802 (set-extent-endpoints annot (point) (point)))))
5803 (setq start (point))
5804 (if (search-backward "\n\n" nil t)
5805 (progn
5806 (goto-char start)
5807 (unless (or displayed-p (eolp))
5808 ;; Add extra newline.
5809 (insert (propertize (buffer-substring (1- start) start)
5810 'gnus-undeletable t))))
5811 ;; We're in the article header.
5812 (delete-char -1)
5813 (dolist (ovl (overlays-in point (point)))
5814 (overlay-put ovl 'gnus-button-attachment-extra t)
5815 (overlay-put ovl 'face nil))
5816 (save-restriction
5817 (message-narrow-to-field)
5818 (let ((gnus-treatment-function-alist
5819 '((gnus-treat-highlight-headers
5820 gnus-article-highlight-headers))))
5821 (gnus-treat-article 'head)))))
5822 (goto-char point)
5823 (if (window-live-p window)
5824 (select-window window)))
5825 retval))
5826
5827 (defun gnus-article-goto-part (n)
5828 "Go to MIME part N."
5829 (when gnus-break-pages
5830 (widen))
5831 (article-goto-body)
5832 (prog1
5833 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5834 ;; There may be header buttons.
5835 (text-property-any (point-min) (point) 'gnus-part n)))
5836 part handle end next handles)
5837 (when start
5838 (goto-char start)
5839 (if (setq handle (get-text-property start 'gnus-data))
5840 start
5841 ;; Go to the displayed subpart, assuming this is
5842 ;; multipart/alternative.
5843 (setq part start
5844 end (point-at-eol))
5845 (while (and (not handle)
5846 part
5847 (< part end)
5848 (setq next (text-property-not-all part end
5849 'gnus-data nil)))
5850 (setq part next
5851 handle (get-text-property part 'gnus-data))
5852 (push (cons handle part) handles)
5853 (unless (mm-handle-displayed-p handle)
5854 (setq handle nil
5855 part (text-property-any part end 'gnus-data nil))))
5856 (unless handle
5857 ;; No subpart is displayed, so we find preferred one.
5858 (setq part
5859 (cdr (assq (mm-preferred-alternative
5860 (nreverse (mapcar 'car handles)))
5861 handles))))
5862 (if part
5863 (goto-char (1+ part))
5864 start))))
5865 (when gnus-break-pages
5866 (gnus-narrow-to-page))))
5867
5868 (defun gnus-insert-mime-button (handle id &optional displayed)
5869 (let ((gnus-tmp-name
5870 (or (mm-handle-filename handle)
5871 (mail-content-type-get (mm-handle-type handle) 'url)
5872 ""))
5873 (gnus-tmp-id id)
5874 (gnus-tmp-type (mm-handle-media-type handle))
5875 (gnus-tmp-description (or (mm-handle-description handle) ""))
5876 (gnus-tmp-dots
5877 (if (if displayed (car displayed)
5878 (mm-handle-displayed-p handle))
5879 "" "..."))
5880 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5881 (buffer-size)))
5882 gnus-tmp-type-long b e)
5883 (when (string-match ".*/" gnus-tmp-name)
5884 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5885 (setq gnus-tmp-type-long (concat gnus-tmp-type
5886 (and (not (equal gnus-tmp-name ""))
5887 (concat "; " gnus-tmp-name))))
5888 (unless (equal gnus-tmp-description "")
5889 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5890 (setq b (point))
5891 (gnus-eval-format
5892 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5893 `(keymap ,gnus-mime-button-map
5894 gnus-callback gnus-mm-display-part
5895 gnus-part ,gnus-tmp-id
5896 article-type annotation
5897 gnus-data ,handle
5898 rear-nonsticky t))
5899 (setq e (if (bolp)
5900 ;; Exclude a newline.
5901 (1- (point))
5902 (point)))
5903 (when gnus-article-button-face
5904 (overlay-put (make-overlay b e nil t)
5905 'face gnus-article-button-face))
5906 (widget-convert-button
5907 'link b e
5908 :mime-handle handle
5909 :action 'gnus-widget-press-button
5910 :button-keymap gnus-mime-button-map
5911 :help-echo
5912 (lambda (widget)
5913 ;; Needed to properly clear the message due to a bug in
5914 ;; wid-edit (XEmacs only).
5915 (if (boundp 'help-echo-owns-message)
5916 (setq help-echo-owns-message t))
5917 (format
5918 "%S: %s the MIME part; %S: more options"
5919 (aref gnus-mouse-2 0)
5920 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5921 "hide" "show")
5922 (aref gnus-down-mouse-3 0))))))
5923
5924 (defun gnus-widget-press-button (elems _el)
5925 (goto-char (widget-get elems :from))
5926 (gnus-article-press-button))
5927
5928 (defvar gnus-displaying-mime nil)
5929
5930 (defun gnus-display-mime (&optional ihandles)
5931 "Display the MIME parts."
5932 (save-excursion
5933 (save-selected-window
5934 (let ((window (get-buffer-window gnus-article-buffer))
5935 (point (point)))
5936 (when window
5937 (select-window window)
5938 ;; We have to do this since selecting the window
5939 ;; may change the point. So we set the window point.
5940 (set-window-point window point)))
5941 (let ((handles ihandles)
5942 (inhibit-read-only t))
5943 (cond (handles)
5944 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5945 (when gnus-article-emulate-mime
5946 (mm-uu-dissect-text-parts handles)))
5947 (gnus-article-emulate-mime
5948 (setq handles (mm-uu-dissect))))
5949 (when (and (not ihandles)
5950 (not gnus-displaying-mime))
5951 ;; Top-level call; we clean up.
5952 (when gnus-article-mime-handles
5953 (mm-destroy-parts gnus-article-mime-handles)
5954 (setq gnus-article-mime-handle-alist nil));; A trick.
5955 (setq gnus-article-mime-handles handles)
5956 ;; We allow users to glean info from the handles.
5957 (when gnus-article-mime-part-function
5958 (gnus-mime-part-function handles)))
5959 (if (and handles
5960 (or (not (stringp (car handles)))
5961 (cdr handles)))
5962 (progn
5963 (when (and (not ihandles)
5964 (not gnus-displaying-mime))
5965 ;; Clean up for mime parts.
5966 (article-goto-body)
5967 (delete-region (point) (point-max)))
5968 (let ((gnus-displaying-mime t))
5969 (gnus-mime-display-part handles)))
5970 (save-restriction
5971 (article-goto-body)
5972 (narrow-to-region (point) (point-max))
5973 (gnus-treat-article nil 1 1 "text/plain")
5974 (widen)))
5975 (unless ihandles
5976 ;; Highlight the headers.
5977 (save-excursion
5978 (save-restriction
5979 (article-goto-body)
5980 (narrow-to-region (point-min) (point))
5981 (gnus-article-save-original-date
5982 (gnus-treat-article 'head)))))))
5983 ;; Cope with broken MIME messages.
5984 (goto-char (point-max))
5985 (unless (bolp)
5986 (insert "\n"))))
5987
5988 (defcustom gnus-mime-display-multipart-as-mixed nil
5989 "Display \"multipart\" parts as \"multipart/mixed\".
5990
5991 If t, it overrides nil values of
5992 `gnus-mime-display-multipart-alternative-as-mixed' and
5993 `gnus-mime-display-multipart-related-as-mixed'."
5994 :group 'gnus-article-mime
5995 :type 'boolean)
5996
5997 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5998 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5999 :version "22.1"
6000 :group 'gnus-article-mime
6001 :type 'boolean)
6002
6003 (defcustom gnus-mime-display-multipart-related-as-mixed nil
6004 "Display \"multipart/related\" parts as \"multipart/mixed\".
6005
6006 If displaying \"text/html\" is discouraged \(see
6007 `mm-discouraged-alternatives') images or other material inside a
6008 \"multipart/related\" part might be overlooked when this variable is nil."
6009 :version "22.1"
6010 :group 'gnus-article-mime
6011 :type 'boolean)
6012
6013 (defcustom gnus-mime-display-attachment-buttons-in-header t
6014 "Add attachment buttons in the end of the header of an article.
6015 Since MIME attachments tend to be put at the end of an article, we may
6016 overlook them if there is a huge body. This option offers you a copy
6017 of all non-inlinable MIME parts as buttons shown in front of an article.
6018 If nil, don't show those extra buttons."
6019 :version "25.1"
6020 :group 'gnus-article-mime
6021 :type 'boolean)
6022
6023 (defun gnus-mime-display-part (handle)
6024 (cond
6025 ;; Maybe a broken MIME message.
6026 ((null handle))
6027 ;; Single part.
6028 ((not (stringp (car handle)))
6029 (gnus-mime-display-single handle))
6030 ;; User-defined multipart
6031 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6032 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6033 handle))
6034 ;; multipart/alternative
6035 ((and (equal (car handle) "multipart/alternative")
6036 (not (or gnus-mime-display-multipart-as-mixed
6037 gnus-mime-display-multipart-alternative-as-mixed)))
6038 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6039 (push (cons id handle) gnus-article-mime-handle-alist)
6040 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6041 ;; multipart/related
6042 ((and (equal (car handle) "multipart/related")
6043 (not (or gnus-mime-display-multipart-as-mixed
6044 gnus-mime-display-multipart-related-as-mixed)))
6045 (gnus-mime-display-part (cadr handle)))
6046 ((equal (car handle) "multipart/signed")
6047 (gnus-add-wash-type 'signed)
6048 (gnus-mime-display-security handle))
6049 ((equal (car handle) "multipart/encrypted")
6050 (gnus-add-wash-type 'encrypted)
6051 (gnus-mime-display-security handle))
6052 ;; Other multiparts are handled like multipart/mixed.
6053 (t
6054 (gnus-mime-display-mixed (cdr handle)))))
6055
6056 (defun gnus-mime-part-function (handles)
6057 (if (stringp (car handles))
6058 (mapcar 'gnus-mime-part-function (cdr handles))
6059 (funcall gnus-article-mime-part-function handles)))
6060
6061 (defun gnus-mime-display-mixed (handles)
6062 (mapcar 'gnus-mime-display-part handles))
6063
6064 (defun gnus-mime-display-single (handle)
6065 (let ((type (mm-handle-media-type handle))
6066 (ignored gnus-ignored-mime-types)
6067 (not-attachment t)
6068 display text)
6069 (catch 'ignored
6070 (progn
6071 (while ignored
6072 (when (string-match (pop ignored) type)
6073 (throw 'ignored nil)))
6074 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6075 (with-current-buffer gnus-summary-buffer
6076 gnus-inhibit-images)
6077 gnus-inhibit-images)
6078 (string-match "\\`image/" type)))
6079 (setq not-attachment
6080 (and (not (mm-inline-override-p handle))
6081 (or (not (mm-handle-disposition handle))
6082 (equal (car (mm-handle-disposition handle))
6083 "inline")
6084 (mm-attachment-override-p handle))))
6085 (mm-automatic-display-p handle)
6086 (or (and
6087 (mm-inlinable-p handle)
6088 (mm-inlined-p handle))
6089 (mm-automatic-external-display-p type)))
6090 (setq display t)
6091 (when (equal (mm-handle-media-supertype handle) "text")
6092 (setq text t)))
6093 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6094 beg)
6095 (unless id
6096 (setq id (1+ (length gnus-article-mime-handle-alist)))
6097 (push (cons id handle) gnus-article-mime-handle-alist))
6098 (when (and display
6099 (equal (mm-handle-media-supertype handle) "message"))
6100 (insert-char
6101 ?\n
6102 (cond ((not (bolp)) 2)
6103 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6104 (t 1))))
6105 (when (or (not display)
6106 (not (gnus-unbuttonized-mime-type-p type))
6107 (eq id gnus-mime-buttonized-part-id))
6108 (gnus-insert-mime-button
6109 handle id (list (or display (and not-attachment text)))))
6110 (setq beg (point))
6111 (cond
6112 (display
6113 (let ((mail-parse-charset gnus-newsgroup-charset)
6114 (mail-parse-ignored-charsets
6115 (save-excursion (condition-case ()
6116 (set-buffer gnus-summary-buffer)
6117 (error))
6118 gnus-newsgroup-ignored-charsets)))
6119 (gnus-bind-mm-vars (mm-display-part handle t))))
6120 ((and text not-attachment)
6121 (mm-display-inline handle)))
6122 (goto-char (point-max))
6123 (if (string-match "\\`image/" type)
6124 (gnus-article-insert-newline)
6125 (if (prog1
6126 (= (skip-chars-backward "\n") -1)
6127 (unless (eobp) (forward-char 1)))
6128 (gnus-article-insert-newline)
6129 (put-text-property (point) (point-max) 'gnus-undeletable t))
6130 (goto-char (point-max)))
6131 ;; Do highlighting.
6132 (save-excursion
6133 (save-restriction
6134 (narrow-to-region beg (point))
6135 (if (eq handle gnus-article-mime-handles)
6136 ;; The format=flowed case.
6137 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6138 ;; Don't count signature parts that are never displayed.
6139 ;; The part number should be re-calculated supposing this
6140 ;; might be a message/rfc822 part.
6141 (let (handles)
6142 (dolist (part gnus-article-mime-handles)
6143 (unless (or (stringp part)
6144 (equal (car (mm-handle-type part))
6145 "application/pgp-signature"))
6146 (push part handles)))
6147 (gnus-treat-article
6148 nil (length (memq handle handles)) (length handles)
6149 (mm-handle-media-type handle)))))))))))
6150
6151 (defun gnus-unbuttonized-mime-type-p (type)
6152 "Say whether TYPE is to be unbuttonized."
6153 (unless gnus-inhibit-mime-unbuttonizing
6154 (when (catch 'found
6155 (let ((types gnus-unbuttonized-mime-types))
6156 (while types
6157 (when (string-match (pop types) type)
6158 (throw 'found t)))))
6159 (not (catch 'found
6160 (let ((types gnus-buttonized-mime-types))
6161 (while types
6162 (when (string-match (pop types) type)
6163 (throw 'found t)))))))))
6164
6165 (defun gnus-article-insert-newline ()
6166 "Insert a newline, but mark it as undeletable."
6167 (gnus-put-text-property
6168 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6169
6170 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6171 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6172 (ihandles handles)
6173 (point (point))
6174 handle (inhibit-read-only t) from begend not-pref)
6175 (save-window-excursion
6176 (save-restriction
6177 (when ibegend
6178 (narrow-to-region (car ibegend)
6179 (or (cdr ibegend)
6180 (progn
6181 (goto-char (car ibegend))
6182 (forward-line 2)
6183 (point))))
6184 (delete-region (point-min) (point-max))
6185 (mm-remove-parts handles))
6186 (setq begend (list (point-marker)))
6187 ;; Do the toggle.
6188 (unless (setq not-pref (cadr (member preferred ihandles)))
6189 (setq not-pref (car ihandles)))
6190 (when (or ibegend
6191 (not preferred)
6192 (not (gnus-unbuttonized-mime-type-p
6193 "multipart/alternative")))
6194 (gnus-add-text-properties
6195 (setq from (point))
6196 (progn
6197 (insert (format "%d. " id))
6198 (point))
6199 `(gnus-callback
6200 (lambda (handles)
6201 (unless ,(not ibegend)
6202 (setq gnus-article-mime-handle-alist
6203 ',gnus-article-mime-handle-alist))
6204 (gnus-mime-display-alternative
6205 ',ihandles ',not-pref ',begend ,id))
6206 keymap ,gnus-mime-button-map
6207 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6208 face ,gnus-article-button-face
6209 gnus-part ,id
6210 article-type multipart
6211 rear-nonsticky t))
6212 (widget-convert-button 'link from (point)
6213 :action 'gnus-widget-press-button
6214 :button-keymap gnus-widget-button-keymap)
6215 ;; Do the handles
6216 (while (setq handle (pop handles))
6217 (gnus-add-text-properties
6218 (setq from (point))
6219 (progn
6220 (insert (format "(%c) %-18s"
6221 (if (equal handle preferred) ?* ? )
6222 (mm-handle-media-type handle)))
6223 (point))
6224 `(gnus-callback
6225 (lambda (handles)
6226 (unless ,(not ibegend)
6227 (setq gnus-article-mime-handle-alist
6228 ',gnus-article-mime-handle-alist))
6229 (gnus-mime-display-alternative
6230 ',ihandles ',handle ',begend ,id))
6231 keymap ,gnus-mime-button-map
6232 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6233 face ,gnus-article-button-face
6234 gnus-part ,id
6235 gnus-data ,handle
6236 rear-nonsticky t))
6237 (widget-convert-button 'link from (point)
6238 :action 'gnus-widget-press-button
6239 :button-keymap gnus-widget-button-keymap)
6240 (insert " "))
6241 (insert "\n\n"))
6242 (when preferred
6243 (if (stringp (car preferred))
6244 (gnus-display-mime preferred)
6245 (let ((mail-parse-charset gnus-newsgroup-charset)
6246 (mail-parse-ignored-charsets
6247 (with-current-buffer gnus-summary-buffer
6248 gnus-newsgroup-ignored-charsets)))
6249 (gnus-bind-mm-vars (mm-display-part preferred))
6250 ;; Do highlighting.
6251 (save-excursion
6252 (save-restriction
6253 (narrow-to-region (car begend) (point-max))
6254 (gnus-treat-article
6255 nil (length gnus-article-mime-handle-alist)
6256 (gnus-article-mime-total-parts)
6257 (mm-handle-media-type preferred))))))
6258 (goto-char (point-max))
6259 (setcdr begend (point-marker)))))
6260 (when ibegend
6261 (goto-char point)))
6262 ;; Redraw attachment buttons in the header.
6263 (when gnus-mime-display-attachment-buttons-in-header
6264 (gnus-mime-buttonize-attachments-in-header)))
6265
6266 (defconst gnus-article-wash-status-strings
6267 (let ((alist '((cite "c" "Possible hidden citation text"
6268 " " "All citation text visible")
6269 (headers "h" "Hidden headers"
6270 " " "All headers visible.")
6271 (pgp "p" "Encrypted or signed message status hidden"
6272 " " "No hidden encryption nor digital signature status")
6273 (signature "s" "Signature has been hidden"
6274 " " "Signature is visible")
6275 (overstrike "o" "Overstrike (^H) characters applied"
6276 " " "No overstrike characters applied")
6277 (emphasis "e" "/*_Emphasis_*/ characters applied"
6278 " " "No /*_emphasis_*/ characters applied")))
6279 result)
6280 (dolist (entry alist result)
6281 (let ((key (nth 0 entry))
6282 (on (copy-sequence (nth 1 entry)))
6283 (on-help (nth 2 entry))
6284 (off (copy-sequence (nth 3 entry)))
6285 (off-help (nth 4 entry)))
6286 (put-text-property 0 1 'help-echo on-help on)
6287 (put-text-property 0 1 'help-echo off-help off)
6288 (push (list key on off) result))))
6289 "Alist of strings describing wash status in the mode line.
6290 Each entry has the form (KEY ON OF), where the KEY is a symbol
6291 representing the particular washing function, ON is the string to use
6292 in the article mode line when the washing function is active, and OFF
6293 is the string to use when it is inactive.")
6294
6295 (defun gnus-article-wash-status-entry (key value)
6296 (let ((entry (assoc key gnus-article-wash-status-strings)))
6297 (if value (nth 1 entry) (nth 2 entry))))
6298
6299 (defun gnus-article-wash-status ()
6300 "Return a string which display status of article washing."
6301 (with-current-buffer gnus-article-buffer
6302 (let ((cite (memq 'cite gnus-article-wash-types))
6303 (headers (memq 'headers gnus-article-wash-types))
6304 (boring (memq 'boring-headers gnus-article-wash-types))
6305 (pgp (memq 'pgp gnus-article-wash-types))
6306 (pem (memq 'pem gnus-article-wash-types))
6307 (signed (memq 'signed gnus-article-wash-types))
6308 (encrypted (memq 'encrypted gnus-article-wash-types))
6309 (signature (memq 'signature gnus-article-wash-types))
6310 (overstrike (memq 'overstrike gnus-article-wash-types))
6311 (emphasis (memq 'emphasis gnus-article-wash-types)))
6312 (concat
6313 (gnus-article-wash-status-entry 'cite cite)
6314 (gnus-article-wash-status-entry 'headers (or headers boring))
6315 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6316 (gnus-article-wash-status-entry 'signature signature)
6317 (gnus-article-wash-status-entry 'overstrike overstrike)
6318 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6319
6320 (defun gnus-add-wash-type (type)
6321 "Add a washing of TYPE to the current status."
6322 (add-to-list 'gnus-article-wash-types type))
6323
6324 (defun gnus-delete-wash-type (type)
6325 "Add a washing of TYPE to the current status."
6326 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6327
6328 (defun gnus-add-image (category image)
6329 "Add IMAGE of CATEGORY to the list of displayed images."
6330 (let ((entry (assq category gnus-article-image-alist)))
6331 (unless entry
6332 (setq entry (list category))
6333 (push entry gnus-article-image-alist))
6334 (nconc entry (list image))))
6335
6336 (defun gnus-delete-images (category)
6337 "Delete all images in CATEGORY."
6338 (let ((entry (assq category gnus-article-image-alist)))
6339 (dolist (image (cdr entry))
6340 (gnus-remove-image image category))
6341 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6342 (gnus-delete-wash-type category)))
6343
6344 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6345
6346 (defun gnus-article-maybe-hide-headers ()
6347 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6348 Provided for backwards compatibility."
6349 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6350 (not (with-current-buffer gnus-summary-buffer
6351 gnus-have-all-headers)))
6352 (not gnus-inhibit-hiding))
6353 (gnus-article-hide-headers)))
6354
6355 (declare-function shr-put-image "shr" (data alt &optional flags))
6356
6357 (defun gnus-shr-put-image (data alt &optional flags)
6358 "Put image DATA with a string ALT. Enable image to be deleted."
6359 (let ((image (if flags
6360 (shr-put-image data (propertize (or alt "*")
6361 'gnus-image-category 'shr)
6362 flags)
6363 ;; Old `shr-put-image' doesn't take the optional `flags'
6364 ;; argument.
6365 (shr-put-image data (propertize (or alt "*")
6366 'gnus-image-category 'shr)))))
6367 (when image
6368 (gnus-add-image 'shr image))))
6369
6370 (defun gnus-article-mime-handles (&optional alist id all)
6371 (if alist
6372 (let ((i 1) newid flat)
6373 (dolist (handle alist flat)
6374 (setq newid (append id (list i))
6375 i (1+ i))
6376 (if (stringp (car handle))
6377 (setq flat (nconc flat (gnus-article-mime-handles
6378 (cdr handle) newid all)))
6379 (delq (rassq handle all) all)
6380 (setq flat (nconc flat (list (cons newid handle)))))))
6381 (let ((flat (list nil)))
6382 ;; Assume that elements of `gnus-article-mime-handle-alist'
6383 ;; are in the decreasing order, but unnumbered subsidiaries
6384 ;; in each element are in the increasing order.
6385 (dolist (handle (reverse gnus-article-mime-handle-alist))
6386 (if (stringp (cadr handle))
6387 (setq flat (nconc flat (gnus-article-mime-handles
6388 (cddr handle) (list (car handle)) flat)))
6389 (delq (rassq (cdr handle) flat) flat)
6390 (setq flat (nconc flat (list (cons (list (car handle))
6391 (cdr handle)))))))
6392 (setq flat (cdr flat))
6393 (mapc (lambda (handle)
6394 (if (cdar handle)
6395 ;; This is a hidden (i.e. unnumbered) handle.
6396 (progn
6397 (setcar handle
6398 (1+ (caar gnus-article-mime-handle-alist)))
6399 (push handle gnus-article-mime-handle-alist))
6400 (setcar handle (caar handle))))
6401 flat)
6402 flat)))
6403
6404 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6405 "Show attachments as buttons in the end of the header of an article.
6406 This function toggles the display when called interactively. Note that
6407 buttons to be added to the header are only the ones that aren't inlined
6408 in the body. Use `gnus-header-face-alist' to highlight buttons."
6409 (interactive (list t))
6410 (gnus-with-article-buffer
6411 (let ((case-fold-search t) buttons handle type st)
6412 (save-excursion
6413 (save-restriction
6414 (widen)
6415 (article-narrow-to-head)
6416 ;; Header buttons exist?
6417 (while (and (not buttons)
6418 (re-search-forward "^attachments?:[\n ]+" nil t))
6419 (when (get-char-property (match-end 0)
6420 'gnus-button-attachment-extra)
6421 (setq buttons (match-beginning 0))))
6422 (widen)
6423 (when buttons
6424 ;; Delete header buttons.
6425 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6426 (match-beginning 0)
6427 (point-max))))
6428 (unless (and interactive buttons)
6429 ;; Find buttons.
6430 (setq buttons nil)
6431 (dolist (button (gnus-article-mime-handles))
6432 (setq handle (cdr button)
6433 type (mm-handle-media-type handle))
6434 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6435 (with-current-buffer gnus-summary-buffer
6436 gnus-inhibit-images)
6437 gnus-inhibit-images)
6438 (string-match "\\`image/" type))
6439 (mm-inline-override-p handle)
6440 (and (mm-handle-disposition handle)
6441 (not (equal (car (mm-handle-disposition handle))
6442 "inline"))
6443 (not (mm-attachment-override-p handle)))
6444 (not (mm-automatic-display-p handle))
6445 (not (or (and (mm-inlinable-p handle)
6446 (mm-inlined-p handle))
6447 (mm-automatic-external-display-p type))))
6448 (push button buttons)))
6449 (when buttons
6450 ;; Add header buttons.
6451 (article-goto-body)
6452 (forward-line -1)
6453 (narrow-to-region (point) (point))
6454 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6455 (dolist (button (nreverse buttons))
6456 (setq st (point))
6457 (insert " ")
6458 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6459 (gnus-insert-mime-button handle (car button))
6460 (skip-chars-backward "\t\n ")
6461 (delete-region (point) (point-max))
6462 (when (> (current-column) (window-width))
6463 (goto-char st)
6464 (insert "\n")
6465 (end-of-line)))
6466 (insert "\n")
6467 (dolist (ovl (overlays-in (point-min) (point)))
6468 (overlay-put ovl 'gnus-button-attachment-extra t)
6469 (overlay-put ovl 'face nil))
6470 (let ((gnus-treatment-function-alist
6471 '((gnus-treat-highlight-headers
6472 gnus-article-highlight-headers))))
6473 (gnus-treat-article 'head)))))))))
6474
6475 ;;; Article savers.
6476
6477 (defun gnus-output-to-file (file-name)
6478 "Append the current article to a file named FILE-NAME.
6479 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6480 text and used as the value of the coding cookie which is added to the
6481 top of a file. Otherwise, this function saves a raw article without
6482 the coding cookie."
6483 (let* ((artbuf (current-buffer))
6484 (file-name-coding-system nnmail-pathname-coding-system)
6485 (coding gnus-article-save-coding-system)
6486 (coding-system-for-read (if coding
6487 nil ;; Rely on the coding cookie.
6488 mm-text-coding-system))
6489 (coding-system-for-write (or coding
6490 mm-text-coding-system-for-write
6491 mm-text-coding-system))
6492 (exists (file-exists-p file-name)))
6493 (with-temp-buffer
6494 (when exists
6495 (insert-file-contents file-name)
6496 (goto-char (point-min))
6497 ;; Remove the existing coding cookie.
6498 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6499 (delete-region (match-beginning 0) (match-end 0))))
6500 (goto-char (point-max))
6501 (insert-buffer-substring artbuf)
6502 ;; Append newline at end of the buffer as separator, and then
6503 ;; save it to file.
6504 (goto-char (point-max))
6505 (insert "\n")
6506 (when coding
6507 ;; If the coding system is not suitable to encode the text,
6508 ;; ask a user for a proper one.
6509 (when (fboundp 'select-safe-coding-system)
6510 (setq coding (coding-system-base
6511 (save-window-excursion
6512 (select-safe-coding-system (point-min) (point-max)
6513 coding))))
6514 (setq coding-system-for-write
6515 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6516 coding)))
6517 (goto-char (point-min))
6518 ;; Add the coding cookie.
6519 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6520 coding-system-for-write)))
6521 (if exists
6522 (progn
6523 (write-region (point-min) (point-max) file-name nil 'no-message)
6524 (message "Appended to %s" file-name))
6525 (write-region (point-min) (point-max) file-name))))
6526 t)
6527
6528 (defun gnus-narrow-to-page (&optional arg)
6529 "Narrow the article buffer to a page.
6530 If given a numerical ARG, move forward ARG pages."
6531 (interactive "P")
6532 (setq arg (if arg (prefix-numeric-value arg) 0))
6533 (with-current-buffer gnus-article-buffer
6534 (widen)
6535 ;; Remove any old next/prev buttons.
6536 (when (gnus-visual-p 'page-marker)
6537 (let ((inhibit-read-only t))
6538 (gnus-remove-text-with-property 'gnus-prev)
6539 (gnus-remove-text-with-property 'gnus-next)))
6540 (let (st nd pt)
6541 (when (save-excursion
6542 (cond ((< arg 0)
6543 (if (re-search-backward page-delimiter nil 'move (abs arg))
6544 (prog1
6545 (setq nd (match-beginning 0)
6546 pt nd)
6547 (when (re-search-backward page-delimiter nil t)
6548 (setq st (match-end 0))))
6549 (when (re-search-forward page-delimiter nil t)
6550 (setq nd (match-beginning 0)
6551 pt (point-min)))))
6552 ((> arg 0)
6553 (if (re-search-forward page-delimiter nil 'move arg)
6554 (prog1
6555 (setq st (match-end 0)
6556 pt st)
6557 (when (re-search-forward page-delimiter nil t)
6558 (setq nd (match-beginning 0))))
6559 (when (re-search-backward page-delimiter nil t)
6560 (setq st (match-end 0)
6561 pt (point-max)))))
6562 (t
6563 (when (re-search-backward page-delimiter nil t)
6564 (goto-char (setq st (match-end 0))))
6565 (when (re-search-forward page-delimiter nil t)
6566 (setq nd (match-beginning 0)))
6567 (or st nd))))
6568 (setq gnus-page-broken t)
6569 (when pt (goto-char pt))
6570 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6571 (when (gnus-visual-p 'page-marker)
6572 (save-excursion
6573 (when nd
6574 (goto-char nd)
6575 (gnus-insert-next-page-button))
6576 (when st
6577 (goto-char st)
6578 (gnus-insert-prev-page-button))))))))
6579
6580 ;; Article mode commands
6581
6582 (defun gnus-article-goto-next-page ()
6583 "Show the next page of the article."
6584 (interactive)
6585 (when (gnus-article-next-page)
6586 (goto-char (point-min))
6587 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6588
6589
6590 (defun gnus-article-goto-prev-page ()
6591 "Show the previous page of the article."
6592 (interactive)
6593 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6594 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6595 (gnus-article-prev-page nil)))
6596
6597 ;; This is cleaner but currently breaks `gnus-pick-mode':
6598 ;;
6599 ;; (defun gnus-article-goto-next-page ()
6600 ;; "Show the next page of the article."
6601 ;; (interactive)
6602 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6603 ;; (gnus-summary-next-page)))
6604 ;;
6605 ;; (defun gnus-article-goto-prev-page ()
6606 ;; "Show the next page of the article."
6607 ;; (interactive)
6608 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6609 ;; (gnus-summary-prev-page)))
6610
6611 (defun gnus-article-next-page (&optional lines)
6612 "Show the next page of the current article.
6613 If end of article, return non-nil. Otherwise return nil.
6614 Argument LINES specifies lines to be scrolled up."
6615 (interactive "p")
6616 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6617 (if (and (not (and gnus-article-over-scroll
6618 (> (count-lines (window-start) (point-max))
6619 (if (featurep 'xemacs)
6620 (or lines (1- (window-height)))
6621 (+ (or lines (1- (window-height))) scroll-margin)))))
6622 (save-excursion
6623 (end-of-line)
6624 (and (pos-visible-in-window-p) ;Not continuation line.
6625 (>= (point) (point-max)))))
6626 ;; Nothing in this page.
6627 (if (or (not gnus-page-broken)
6628 (save-excursion
6629 (save-restriction
6630 (widen)
6631 (forward-line)
6632 (eobp)))) ;Real end-of-buffer?
6633 (progn
6634 (when gnus-article-over-scroll
6635 (gnus-article-next-page-1 lines))
6636 t) ;Nothing more.
6637 (gnus-narrow-to-page 1) ;Go to next page.
6638 nil)
6639 ;; More in this page.
6640 (gnus-article-next-page-1 lines)
6641 nil))
6642
6643 (defun gnus-article-beginning-of-window ()
6644 "Move point to the beginning of the window.
6645 In Emacs, the point is placed at the line number which `scroll-margin'
6646 specifies."
6647 (if (featurep 'xemacs)
6648 (move-to-window-line 0)
6649 ;; There is an obscure bug in Emacs that makes it impossible to
6650 ;; scroll past big pictures in the article buffer. Try to fix
6651 ;; this by adding a sanity check by counting the lines visible.
6652 (when (> (count-lines (window-start) (window-end)) 30)
6653 (move-to-window-line
6654 (min (max 0 scroll-margin)
6655 (max 1 (- (window-height)
6656 (if mode-line-format 1 0)
6657 (if header-line-format 1 0)
6658 2)))))))
6659
6660 (defvar scroll-in-place)
6661
6662 (defun gnus-article-next-page-1 (lines)
6663 (condition-case ()
6664 (let ((scroll-in-place nil)
6665 (auto-window-vscroll nil))
6666 (scroll-up lines))
6667 (end-of-buffer
6668 ;; Long lines may cause an end-of-buffer error.
6669 (goto-char (point-max))))
6670 (gnus-article-beginning-of-window))
6671
6672 (defun gnus-article-prev-page (&optional lines)
6673 "Show previous page of current article.
6674 Argument LINES specifies lines to be scrolled down."
6675 (interactive "p")
6676 (move-to-window-line 0)
6677 (if (and gnus-page-broken
6678 (bobp)
6679 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6680 (progn
6681 (gnus-narrow-to-page -1) ;Go to previous page.
6682 (goto-char (point-max))
6683 (recenter (if gnus-article-over-scroll
6684 (if lines
6685 (max (if (featurep 'xemacs)
6686 lines
6687 (+ lines scroll-margin))
6688 3)
6689 (- (window-height) 2))
6690 -1)))
6691 (prog1
6692 (condition-case ()
6693 (let ((scroll-in-place nil))
6694 (scroll-down lines))
6695 (beginning-of-buffer
6696 (goto-char (point-min))))
6697 (gnus-article-beginning-of-window))))
6698
6699 (defun gnus-article-only-boring-p ()
6700 "Decide whether there is only boring text remaining in the article.
6701 Something \"interesting\" is a word of at least two letters that does
6702 not have a face in `gnus-article-boring-faces'."
6703 (when (and gnus-article-skip-boring
6704 (boundp 'gnus-article-boring-faces)
6705 (symbol-value 'gnus-article-boring-faces))
6706 (save-excursion
6707 (let ((inhibit-point-motion-hooks t))
6708 (catch 'only-boring
6709 (while (re-search-forward "\\b\\w\\w" nil t)
6710 (forward-char -1)
6711 (when (not (gnus-intersection
6712 (gnus-faces-at (point))
6713 (symbol-value 'gnus-article-boring-faces)))
6714 (throw 'only-boring nil)))
6715 (throw 'only-boring t))))))
6716
6717 (defun gnus-article-refer-article ()
6718 "Read article specified by message-id around point."
6719 (interactive)
6720 (save-excursion
6721 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6722 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6723 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6724 (let ((msg-id (concat "<" (match-string 0) ">")))
6725 (set-buffer gnus-summary-buffer)
6726 (gnus-summary-refer-article msg-id))
6727 (error "No references around point"))))
6728
6729 (defun gnus-article-show-summary ()
6730 "Reconfigure windows to show summary buffer."
6731 (interactive)
6732 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6733 (error "There is no summary buffer for this article buffer")
6734 (gnus-article-set-globals)
6735 (gnus-configure-windows 'article)
6736 (gnus-summary-goto-subject gnus-current-article)
6737 (gnus-summary-position-point)))
6738
6739 (defun gnus-article-describe-briefly ()
6740 "Describe article mode commands briefly."
6741 (interactive)
6742 (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")))
6743
6744 (defun gnus-article-check-buffer ()
6745 "Beep if not in an article buffer."
6746 (unless (derived-mode-p 'gnus-article-mode)
6747 (error "Command invoked outside of a Gnus article buffer")))
6748
6749 (defvar gnus-pick-mode)
6750
6751 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6752 "Read a summary buffer key sequence and execute it from the article buffer."
6753 (interactive "P")
6754 (gnus-article-check-buffer)
6755 (let ((nosaves
6756 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6757 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6758 "=" "^" "\M-^" "|"))
6759 (nosave-but-article
6760 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6761 "An" "Ap" [?A (meta return)] [?A delete]))
6762 (nosave-in-article
6763 '("AS" "\C-d"))
6764 keys new-sum-point)
6765 (with-current-buffer gnus-article-current-summary
6766 (let (gnus-pick-mode)
6767 (setq unread-command-events (nconc unread-command-events
6768 (list (or key last-command-event)))
6769 keys (if (featurep 'xemacs)
6770 (events-to-keys (read-key-sequence nil t))
6771 (read-key-sequence nil t)))))
6772
6773 (message "")
6774
6775 (cond
6776 ((eq (aref keys (1- (length keys))) ?\C-h)
6777 (gnus-article-describe-bindings (substring keys 0 -1)))
6778 ((or (member keys nosaves)
6779 (member keys nosave-but-article)
6780 (member keys nosave-in-article))
6781 (let (func)
6782 (save-window-excursion
6783 (pop-to-buffer gnus-article-current-summary)
6784 ;; We disable the pick minor mode commands.
6785 (let (gnus-pick-mode)
6786 (setq func (key-binding keys t))))
6787 (if (or (not func)
6788 (numberp func))
6789 (ding)
6790 (unless (member keys nosave-in-article)
6791 (set-buffer gnus-article-current-summary))
6792 (when (and (symbolp func)
6793 (get func 'disabled))
6794 (error "Function %s disabled" func))
6795 (call-interactively func)
6796 (setq new-sum-point (point)))
6797 (when (member keys nosave-but-article)
6798 (pop-to-buffer gnus-article-buffer))))
6799 (t
6800 ;; These commands should restore window configuration.
6801 (let ((obuf (current-buffer))
6802 (owin (current-window-configuration))
6803 win func in-buffer selected new-sum-start new-sum-hscroll err)
6804 (cond (not-restore-window
6805 (pop-to-buffer gnus-article-current-summary)
6806 (setq win (selected-window)))
6807 ((setq win (get-buffer-window gnus-article-current-summary))
6808 (select-window win))
6809 (t
6810 (let ((summary-buffer gnus-article-current-summary))
6811 (gnus-configure-windows 'article)
6812 (unless (setq win (get-buffer-window summary-buffer 'visible))
6813 (let ((gnus-buffer-configuration
6814 '((article ((vertical 1.0
6815 (summary 0.25 point)
6816 (article 1.0)))))))
6817 (gnus-configure-windows 'article))
6818 (setq win (get-buffer-window summary-buffer 'visible)))
6819 (gnus-select-frame-set-input-focus (window-frame win))
6820 (select-window win))))
6821 (setq in-buffer (current-buffer))
6822 ;; We disable the pick minor mode commands.
6823 (setq func (let (gnus-pick-mode)
6824 (key-binding keys t)))
6825 (when (get func 'disabled)
6826 (error "Function %s disabled" func))
6827 (if (and func
6828 (functionp func)
6829 (condition-case code
6830 (progn
6831 (call-interactively func)
6832 t)
6833 (error
6834 (setq err code)
6835 nil)))
6836 (progn
6837 (when (eq win (selected-window))
6838 (setq new-sum-point (point)
6839 new-sum-start (window-start win)
6840 new-sum-hscroll (window-hscroll win)))
6841 (when (or (eq in-buffer (current-buffer))
6842 (when (eq obuf (current-buffer))
6843 (set-buffer in-buffer)
6844 t))
6845 (setq selected (ignore-errors (gnus-summary-select-article)))
6846 (set-buffer obuf)
6847 (unless not-restore-window
6848 (set-window-configuration owin))
6849 (when (and (eq selected 'old)
6850 new-sum-point)
6851 (set-window-start (get-buffer-window (current-buffer))
6852 1)
6853 (set-window-point (get-buffer-window (current-buffer))
6854 (if (article-goto-body)
6855 (1- (point))
6856 (point))))
6857 (when (and (not not-restore-window)
6858 new-sum-point
6859 (window-live-p win)
6860 (with-current-buffer (window-buffer win)
6861 (derived-mode-p 'gnus-summary-mode)))
6862 (set-window-point win new-sum-point)
6863 (set-window-start win new-sum-start)
6864 (set-window-hscroll win new-sum-hscroll))))
6865 (set-window-configuration owin)
6866 (if err
6867 (signal (car err) (cdr err))
6868 (ding))))))))
6869
6870 (defun gnus-article-read-summary-send-keys ()
6871 (interactive)
6872 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6873 (gnus-article-read-summary-keys)))
6874
6875 (defun gnus-article-describe-key (key)
6876 "Display documentation of the function invoked by KEY.
6877 KEY is a string or a vector."
6878 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6879 (read-key-sequence "Describe key: "))))
6880 (gnus-article-check-buffer)
6881 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6882 gnus-article-read-summary-send-keys))
6883 (with-current-buffer gnus-article-current-summary
6884 (setq unread-command-events
6885 (if (featurep 'xemacs)
6886 (append key unread-command-events)
6887 (nconc
6888 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6889 (list 'meta (- x 128))
6890 x))
6891 key)
6892 unread-command-events)))
6893 (let ((cursor-in-echo-area t)
6894 gnus-pick-mode)
6895 (describe-key (read-key-sequence nil t))))
6896 (describe-key key)))
6897
6898 (defun gnus-article-describe-key-briefly (key &optional insert)
6899 "Display documentation of the function invoked by KEY.
6900 KEY is a string or a vector."
6901 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6902 (read-key-sequence "Describe key: "))
6903 current-prefix-arg))
6904 (gnus-article-check-buffer)
6905 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6906 gnus-article-read-summary-send-keys))
6907 (with-current-buffer gnus-article-current-summary
6908 (setq unread-command-events
6909 (if (featurep 'xemacs)
6910 (append key unread-command-events)
6911 (nconc
6912 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6913 (list 'meta (- x 128))
6914 x))
6915 key)
6916 unread-command-events)))
6917 (let ((cursor-in-echo-area t)
6918 gnus-pick-mode)
6919 (describe-key-briefly (read-key-sequence nil t) insert)))
6920 (describe-key-briefly key insert)))
6921
6922 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6923 (defvar gnus-agent-summary-mode)
6924 (defvar gnus-draft-mode)
6925 (defvar help-xref-stack-item)
6926 (defvar help-xref-following)
6927
6928 (defun gnus-article-describe-bindings (&optional prefix)
6929 "Show a list of all defined keys, and their definitions.
6930 The optional argument PREFIX, if non-nil, should be a key sequence;
6931 then we display only bindings that start with that prefix."
6932 (interactive)
6933 (gnus-article-check-buffer)
6934 (let ((keymap (copy-keymap gnus-article-mode-map))
6935 (map (copy-keymap gnus-article-send-map))
6936 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6937 parent agent draft)
6938 (define-key keymap "S" map)
6939 (define-key map [t] nil)
6940 (with-current-buffer gnus-article-current-summary
6941 (set-keymap-parent
6942 keymap
6943 (if (setq parent (keymap-parent gnus-article-mode-map))
6944 (prog1
6945 (setq parent (copy-keymap parent))
6946 (set-keymap-parent parent (current-local-map)))
6947 (current-local-map)))
6948 (set-keymap-parent map (key-binding "S"))
6949 (let (key def gnus-pick-mode)
6950 (while sumkeys
6951 (setq key (pop sumkeys))
6952 (cond ((and (vectorp key) (= (length key) 1)
6953 (consp (setq def (aref key 0)))
6954 (numberp (car def)) (numberp (cdr def)))
6955 (when (< (max (car def) (cdr def)) 128)
6956 (setq sumkeys
6957 (append (mapcar
6958 #'vector
6959 (nreverse (gnus-uncompress-range def)))
6960 sumkeys))))
6961 ((setq def (key-binding key))
6962 (unless (eq def 'undefined)
6963 (define-key keymap key def))))))
6964 (when (boundp 'gnus-agent-summary-mode)
6965 (setq agent gnus-agent-summary-mode))
6966 (when (boundp 'gnus-draft-mode)
6967 (setq draft gnus-draft-mode)))
6968 (with-temp-buffer
6969 (use-local-map keymap)
6970 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6971 (set (make-local-variable 'gnus-draft-mode) draft)
6972 (describe-bindings prefix))
6973 (let ((item `((lambda (prefix)
6974 (with-current-buffer ,(current-buffer)
6975 (gnus-article-describe-bindings prefix)))
6976 ,prefix)))
6977 ;; Loading `help-mode' here is necessary if `describe-bindings'
6978 ;; is replaced with something, e.g. `helm-descbinds'.
6979 (require 'help-mode)
6980 (with-current-buffer (let (help-xref-following) (help-buffer))
6981 (setq help-xref-stack-item item)))))
6982
6983 (defun gnus-article-reply-with-original (&optional wide)
6984 "Start composing a reply mail to the current message.
6985 The text in the region will be yanked. If the region isn't active,
6986 the entire article will be yanked."
6987 (interactive)
6988 (let ((article (cdr gnus-article-current))
6989 contents)
6990 (if (not (gnus-region-active-p))
6991 (with-current-buffer gnus-summary-buffer
6992 (gnus-summary-reply (list (list article)) wide))
6993 (setq contents (buffer-substring (point) (mark t)))
6994 ;; Deactivate active regions.
6995 (when (and (boundp 'transient-mark-mode)
6996 transient-mark-mode)
6997 (setq mark-active nil))
6998 (with-current-buffer gnus-summary-buffer
6999 (gnus-summary-reply
7000 (list (list article contents)) wide)))))
7001
7002 (defun gnus-article-wide-reply-with-original ()
7003 "Start composing a wide reply mail to the current message.
7004 The text in the region will be yanked. If the region isn't active,
7005 the entire article will be yanked."
7006 (interactive)
7007 (gnus-article-reply-with-original t))
7008
7009 (defun gnus-article-followup-with-original ()
7010 "Compose a followup to the current article.
7011 The text in the region will be yanked. If the region isn't active,
7012 the entire article will be yanked."
7013 (interactive)
7014 (let ((article (cdr gnus-article-current))
7015 contents)
7016 (if (not (gnus-region-active-p))
7017 (with-current-buffer gnus-summary-buffer
7018 (gnus-summary-followup (list (list article))))
7019 (setq contents (buffer-substring (point) (mark t)))
7020 ;; Deactivate active regions.
7021 (when (and (boundp 'transient-mark-mode)
7022 transient-mark-mode)
7023 (setq mark-active nil))
7024 (with-current-buffer gnus-summary-buffer
7025 (gnus-summary-followup
7026 (list (list article contents)))))))
7027
7028 (defun gnus-article-hide (&optional arg force)
7029 "Hide all the gruft in the current article.
7030 This means that signatures, cited text and (some) headers will be
7031 hidden.
7032 If given a prefix, show the hidden text instead."
7033 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7034 (gnus-article-hide-headers arg)
7035 (gnus-article-hide-list-identifiers arg)
7036 (gnus-article-hide-citation-maybe arg force)
7037 (gnus-article-hide-signature arg))
7038
7039 (defun gnus-check-group-server ()
7040 ;; Make sure the connection to the server is alive.
7041 (unless (gnus-server-opened
7042 (gnus-find-method-for-group gnus-newsgroup-name))
7043 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7044 (gnus-request-group gnus-newsgroup-name t)))
7045
7046 (declare-function nneething-get-file-name "nneething" (id))
7047
7048 (defun gnus-request-article-this-buffer (article group)
7049 "Get an article and insert it into this buffer."
7050 (let (do-update-line sparse-header)
7051 (prog1
7052 (save-excursion
7053 (erase-buffer)
7054 (gnus-kill-all-overlays)
7055 (setq group (or group gnus-newsgroup-name))
7056
7057 ;; Using `gnus-request-article' directly will insert the article into
7058 ;; `nntp-server-buffer' - so we'll save some time by not having to
7059 ;; copy it from the server buffer into the article buffer.
7060
7061 ;; We only request an article by message-id when we do not have the
7062 ;; headers for it, so we'll have to get those.
7063 (when (stringp article)
7064 (gnus-read-header article))
7065
7066 ;; If the article number is negative, that means that this article
7067 ;; doesn't belong in this newsgroup (possibly), so we find its
7068 ;; message-id and request it by id instead of number.
7069 (when (and (numberp article)
7070 gnus-summary-buffer
7071 (get-buffer gnus-summary-buffer)
7072 (gnus-buffer-exists-p gnus-summary-buffer))
7073 (with-current-buffer gnus-summary-buffer
7074 (let ((header (gnus-summary-article-header article)))
7075 (when (< article 0)
7076 (cond
7077 ((memq article gnus-newsgroup-sparse)
7078 ;; This is a sparse gap article.
7079 (setq do-update-line article)
7080 (setq article (mail-header-id header))
7081 (setq sparse-header (gnus-read-header article))
7082 (setq gnus-newsgroup-sparse
7083 (delq article gnus-newsgroup-sparse)))
7084 ((vectorp header)
7085 ;; It's a real article.
7086 (setq article (mail-header-id header)))
7087 (t
7088 ;; It is an extracted pseudo-article.
7089 (setq article 'pseudo)
7090 (gnus-request-pseudo-article header))))
7091
7092 (let ((method (gnus-find-method-for-group
7093 gnus-newsgroup-name)))
7094 (when (and (eq (car method) 'nneething)
7095 (vectorp header))
7096 (let ((dir (nneething-get-file-name
7097 (mail-header-id header))))
7098 (when (and (stringp dir)
7099 (file-directory-p dir))
7100 (setq article 'nneething)
7101 (gnus-group-enter-directory dir))))))))
7102
7103 (cond
7104 ;; Refuse to select canceled articles.
7105 ((and (numberp article)
7106 gnus-summary-buffer
7107 (get-buffer gnus-summary-buffer)
7108 (gnus-buffer-exists-p gnus-summary-buffer)
7109 (eq (cdr (with-current-buffer gnus-summary-buffer
7110 (assq article gnus-newsgroup-reads)))
7111 gnus-canceled-mark))
7112 nil)
7113 ;; We first check `gnus-original-article-buffer'.
7114 ((and (get-buffer gnus-original-article-buffer)
7115 (numberp article)
7116 (with-current-buffer gnus-original-article-buffer
7117 (and (equal (car gnus-original-article) group)
7118 (eq (cdr gnus-original-article) article))))
7119 ;; `insert-buffer-substring' would incorrectly use the
7120 ;; equivalent of string-make-multibyte which amount to decoding
7121 ;; with locale-coding-system, causing failure of
7122 ;; subsequent decoding.
7123 (insert (mm-string-to-multibyte
7124 (with-current-buffer gnus-original-article-buffer
7125 (buffer-substring (point-min) (point-max)))))
7126 'article)
7127 ;; Check the backlog.
7128 ((and gnus-keep-backlog
7129 (gnus-backlog-request-article group article (current-buffer)))
7130 'article)
7131 ;; Check asynchronous pre-fetch.
7132 ((gnus-async-request-fetched-article group article (current-buffer))
7133 (gnus-async-prefetch-next group article gnus-summary-buffer)
7134 (when (and (numberp article) gnus-keep-backlog)
7135 (gnus-backlog-enter-article group article (current-buffer)))
7136 'article)
7137 ;; Check the cache.
7138 ((and gnus-use-cache
7139 (numberp article)
7140 (gnus-cache-request-article article group))
7141 'article)
7142 ;; Check the agent cache.
7143 ((gnus-agent-request-article article group)
7144 'article)
7145 ;; Get the article and put into the article buffer.
7146 ((or (stringp article)
7147 (numberp article))
7148 (let ((gnus-override-method gnus-override-method)
7149 (methods (and (stringp article)
7150 (with-current-buffer gnus-summary-buffer
7151 (gnus-refer-article-methods))))
7152 (backend (car (gnus-find-method-for-group
7153 gnus-newsgroup-name)))
7154 result
7155 (inhibit-read-only t))
7156 (when (and (null gnus-override-method)
7157 methods)
7158 (setq gnus-override-method (pop methods)))
7159 (while (not result)
7160 (erase-buffer)
7161 (gnus-kill-all-overlays)
7162 (let ((gnus-newsgroup-name group))
7163 (gnus-check-group-server))
7164 (cond
7165 ((gnus-request-article article group (current-buffer))
7166 (when (numberp article)
7167 (gnus-async-prefetch-next group article
7168 gnus-summary-buffer)
7169 (when gnus-keep-backlog
7170 (gnus-backlog-enter-article
7171 group article (current-buffer)))
7172 (when (and gnus-agent
7173 (gnus-agent-group-covered-p group))
7174 (gnus-agent-store-article article group)))
7175 (setq result 'article))
7176 (methods
7177 (setq gnus-override-method (pop methods)))
7178 ((not (string-match "^400 "
7179 (nnheader-get-report backend)))
7180 ;; If we get 400 server disconnect, reconnect and
7181 ;; retry; otherwise, assume the article has expired.
7182 (setq result 'done))))
7183 (and (eq result 'article) 'article)))
7184 ;; It was a pseudo.
7185 (t article)))
7186
7187 ;; Associate this article with the current summary buffer.
7188 (setq gnus-article-current-summary gnus-summary-buffer)
7189
7190 ;; Take the article from the original article buffer
7191 ;; and place it in the buffer it's supposed to be in.
7192 (when (and (get-buffer gnus-article-buffer)
7193 (equal (buffer-name (current-buffer))
7194 (buffer-name (get-buffer gnus-article-buffer))))
7195 (save-excursion
7196 (if (get-buffer gnus-original-article-buffer)
7197 (set-buffer gnus-original-article-buffer)
7198 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7199 (buffer-disable-undo)
7200 (setq major-mode 'gnus-original-article-mode)
7201 (setq buffer-read-only t))
7202 (let ((inhibit-read-only t))
7203 (erase-buffer)
7204 (insert-buffer-substring gnus-article-buffer))
7205 (setq gnus-original-article (cons group article)))
7206
7207 ;; Decode charsets.
7208 (run-hooks 'gnus-article-decode-hook)
7209 ;; Mark article as decoded or not.
7210 (setq gnus-article-decoded-p gnus-article-decode-hook))
7211
7212 ;; Update sparse articles.
7213 (when (and do-update-line
7214 (or (numberp article)
7215 (stringp article)))
7216 (let ((buf (current-buffer)))
7217 (set-buffer gnus-summary-buffer)
7218 (gnus-summary-update-article do-update-line sparse-header)
7219 (gnus-summary-goto-subject do-update-line nil t)
7220 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7221 (point))
7222 (set-buffer buf))))))
7223
7224 (defun gnus-block-private-groups (group)
7225 "Allows images in newsgroups to be shown, blocks images in all
7226 other groups."
7227 (if (or (gnus-news-group-p group)
7228 (gnus-member-of-valid 'global group))
7229 ;; Block nothing in news groups.
7230 nil
7231 ;; Block everything anywhere else.
7232 "."))
7233
7234 (defun gnus-blocked-images ()
7235 (if (functionp gnus-blocked-images)
7236 (funcall gnus-blocked-images gnus-newsgroup-name)
7237 gnus-blocked-images))
7238
7239 ;;;
7240 ;;; Article editing
7241 ;;;
7242
7243 (defcustom gnus-article-edit-mode-hook nil
7244 "Hook run in article edit mode buffers."
7245 :group 'gnus-article-various
7246 :type 'hook)
7247
7248 (defvar gnus-article-edit-done-function nil)
7249
7250 (defvar gnus-article-edit-mode-map nil)
7251
7252 ;; Should we be using derived.el for this?
7253 (unless gnus-article-edit-mode-map
7254 (setq gnus-article-edit-mode-map (make-keymap))
7255 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7256
7257 (gnus-define-keys gnus-article-edit-mode-map
7258 "\C-c?" describe-mode
7259 "\C-c\C-c" gnus-article-edit-done
7260 "\C-c\C-k" gnus-article-edit-exit
7261 "\C-c\C-f\C-t" message-goto-to
7262 "\C-c\C-f\C-o" message-goto-from
7263 "\C-c\C-f\C-b" message-goto-bcc
7264 ;;"\C-c\C-f\C-w" message-goto-fcc
7265 "\C-c\C-f\C-c" message-goto-cc
7266 "\C-c\C-f\C-s" message-goto-subject
7267 "\C-c\C-f\C-r" message-goto-reply-to
7268 "\C-c\C-f\C-n" message-goto-newsgroups
7269 "\C-c\C-f\C-d" message-goto-distribution
7270 "\C-c\C-f\C-f" message-goto-followup-to
7271 "\C-c\C-f\C-m" message-goto-mail-followup-to
7272 "\C-c\C-f\C-k" message-goto-keywords
7273 "\C-c\C-f\C-u" message-goto-summary
7274 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7275 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7276 "\C-c\C-b" message-goto-body
7277 "\C-c\C-i" message-goto-signature
7278
7279 "\C-c\C-t" message-insert-to
7280 "\C-c\C-n" message-insert-newsgroups
7281 "\C-c\C-o" message-sort-headers
7282 "\C-c\C-e" message-elide-region
7283 "\C-c\C-v" message-delete-not-region
7284 "\C-c\C-z" message-kill-to-signature
7285 "\M-\r" message-newline-and-reformat
7286 "\C-c\C-a" mml-attach-file
7287 "\C-a" message-beginning-of-line
7288 "\t" message-tab
7289 "\M-;" comment-region)
7290
7291 (gnus-define-keys (gnus-article-edit-wash-map
7292 "\C-c\C-w" gnus-article-edit-mode-map)
7293 "f" gnus-article-edit-full-stops))
7294
7295 (easy-menu-define
7296 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7297 '("Field"
7298 ["Fetch To" message-insert-to t]
7299 ["Fetch Newsgroups" message-insert-newsgroups t]
7300 "----"
7301 ["To" message-goto-to t]
7302 ["From" message-goto-from t]
7303 ["Subject" message-goto-subject t]
7304 ["Cc" message-goto-cc t]
7305 ["Reply-To" message-goto-reply-to t]
7306 ["Summary" message-goto-summary t]
7307 ["Keywords" message-goto-keywords t]
7308 ["Newsgroups" message-goto-newsgroups t]
7309 ["Followup-To" message-goto-followup-to t]
7310 ["Mail-Followup-To" message-goto-mail-followup-to t]
7311 ["Distribution" message-goto-distribution t]
7312 ["Body" message-goto-body t]
7313 ["Signature" message-goto-signature t]))
7314
7315 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7316 "Major mode for editing articles.
7317 This is an extended text-mode.
7318
7319 \\{gnus-article-edit-mode-map}"
7320 (make-local-variable 'gnus-article-edit-done-function)
7321 (make-local-variable 'gnus-prev-winconf)
7322 (set (make-local-variable 'font-lock-defaults)
7323 '(message-font-lock-keywords t))
7324 (set (make-local-variable 'mail-header-separator) "")
7325 (set (make-local-variable 'gnus-article-edit-mode) t)
7326 (easy-menu-add message-mode-field-menu message-mode-map)
7327 (mml-mode)
7328 (setq buffer-read-only nil)
7329 (buffer-enable-undo)
7330 (widen))
7331
7332 (defun gnus-article-edit (&optional force)
7333 "Edit the current article.
7334 This will have permanent effect only in mail groups.
7335 If FORCE is non-nil, allow editing of articles even in read-only
7336 groups."
7337 (interactive "P")
7338 (when (and (not force)
7339 (gnus-group-read-only-p))
7340 (error "The current newsgroup does not support article editing"))
7341 (gnus-article-date-original)
7342 (gnus-article-edit-article
7343 'ignore
7344 `(lambda (no-highlight)
7345 'ignore
7346 (gnus-summary-edit-article-done
7347 ,(or (mail-header-references gnus-current-headers) "")
7348 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7349
7350 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7351 "Start editing the contents of the current article buffer."
7352 (let ((winconf (current-window-configuration)))
7353 (set-buffer gnus-article-buffer)
7354 (let ((message-auto-save-directory
7355 ;; Don't associate the article buffer with a draft file.
7356 nil))
7357 (gnus-article-edit-mode))
7358 (funcall start-func)
7359 (set-buffer-modified-p nil)
7360 (gnus-configure-windows 'edit-article)
7361 (setq gnus-article-edit-done-function exit-func)
7362 (setq gnus-prev-winconf winconf)
7363 (unless quiet
7364 (gnus-message 6 "C-c C-c to end edits"))))
7365
7366 (defun gnus-article-edit-done (&optional arg)
7367 "Update the article edits and exit."
7368 (interactive "P")
7369 (let ((func gnus-article-edit-done-function)
7370 (buf (current-buffer))
7371 (start (window-start))
7372 (winconf gnus-prev-winconf))
7373 (widen) ;; Widen it in case that users narrowed the buffer.
7374 (funcall func arg)
7375 (set-buffer buf)
7376 ;; The cache and backlog have to be flushed somewhat.
7377 (when gnus-keep-backlog
7378 (gnus-backlog-remove-article
7379 (car gnus-article-current) (cdr gnus-article-current)))
7380 ;; Flush original article as well.
7381 (gnus-flush-original-article-buffer)
7382 (when gnus-use-cache
7383 (gnus-cache-update-article
7384 (car gnus-article-current) (cdr gnus-article-current)))
7385 ;; We remove all text props from the article buffer.
7386 (kill-all-local-variables)
7387 (set-text-properties (point-min) (point-max) nil)
7388 (gnus-article-mode)
7389 (set-window-configuration winconf)
7390 (set-buffer buf)
7391 (set-window-start (get-buffer-window buf) start)
7392 (set-window-point (get-buffer-window buf) (point)))
7393 (gnus-summary-show-article))
7394
7395 (defun gnus-flush-original-article-buffer ()
7396 (when (get-buffer gnus-original-article-buffer)
7397 (with-current-buffer gnus-original-article-buffer
7398 (setq gnus-original-article nil))))
7399
7400 (defun gnus-article-edit-exit ()
7401 "Exit the article editing without updating."
7402 (interactive)
7403 (when (or (not (buffer-modified-p))
7404 (yes-or-no-p "Article modified; kill anyway? "))
7405 (let ((curbuf (current-buffer))
7406 (p (point))
7407 (window-start (window-start)))
7408 (erase-buffer)
7409 (if (gnus-buffer-live-p gnus-original-article-buffer)
7410 (insert-buffer-substring gnus-original-article-buffer))
7411 (let ((winconf gnus-prev-winconf))
7412 (kill-all-local-variables)
7413 (gnus-article-mode)
7414 (set-window-configuration winconf)
7415 ;; Tippy-toe some to make sure that point remains where it was.
7416 (save-current-buffer
7417 (set-buffer curbuf)
7418 (set-window-start (get-buffer-window (current-buffer)) window-start)
7419 (goto-char p))))
7420 (gnus-summary-show-article)))
7421
7422 (defun gnus-article-edit-full-stops ()
7423 "Interactively repair spacing at end of sentences."
7424 (interactive)
7425 (save-excursion
7426 (goto-char (point-min))
7427 (search-forward-regexp "^$" nil t)
7428 (let ((case-fold-search nil))
7429 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7430
7431 ;;;
7432 ;;; Article highlights
7433 ;;;
7434
7435 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7436
7437 ;;; Internal Variables:
7438
7439 (defcustom gnus-button-url-regexp
7440 (concat
7441 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7442 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7443 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7444 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7445 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7446 (punct "!?:;.,"))
7447 (concat
7448 "\\(?:"
7449 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7450 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7451 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7452 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7453 "\\|"
7454 "[" chars punct "]+" "[" chars "]"
7455 "\\)"))
7456 (concat ;; XEmacs 21.4 doesn't support POSIX.
7457 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7458 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7459 "\\)")
7460 "Regular expression that matches URLs."
7461 :version "24.4"
7462 :group 'gnus-article-buttons
7463 :type 'regexp)
7464
7465 (defcustom gnus-button-valid-fqdn-regexp
7466 message-valid-fqdn-regexp
7467 "Regular expression that matches a valid FQDN."
7468 :version "22.1"
7469 :group 'gnus-article-buttons
7470 :type 'regexp)
7471
7472 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7473 (defcustom gnus-button-valid-localpart-regexp
7474 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7475 "Regular expression that matches a localpart of mail addresses or MIDs."
7476 :version "22.1"
7477 :group 'gnus-article-buttons
7478 :type 'regexp)
7479
7480 (defcustom gnus-button-man-handler 'manual-entry
7481 "Function to use for displaying man pages.
7482 The function must take at least one argument with a string naming the
7483 man page."
7484 :version "22.1"
7485 :type '(choice (function-item :tag "Man" manual-entry)
7486 (function-item :tag "Woman" woman)
7487 (function :tag "Other"))
7488 :group 'gnus-article-buttons)
7489
7490 (defcustom gnus-button-mid-or-mail-regexp
7491 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7492 gnus-button-valid-fqdn-regexp
7493 ">?\\)\\b")
7494 "Regular expression that matches a message ID or a mail address."
7495 :version "22.1"
7496 :group 'gnus-article-buttons
7497 :type 'regexp)
7498
7499 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7500 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7501 Strings like this can be either a message ID or a mail address. If it is one
7502 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7503 message ID or a mail address, respectively. If this variable is set to the
7504 symbol `ask', always query the user what do do. If it is a function, this
7505 function will be called with the string as its only argument. The function
7506 must return `mid', `mail', `invalid' or `ask'."
7507 :version "22.1"
7508 :group 'gnus-article-buttons
7509 :type '(choice (function-item :tag "Heuristic function"
7510 gnus-button-mid-or-mail-heuristic)
7511 (const ask)
7512 (const mid)
7513 (const mail)))
7514
7515 (defcustom gnus-button-mid-or-mail-heuristic-alist
7516 '((-10.0 . ".+\\$.+@")
7517 (-10.0 . "#")
7518 (-10.0 . "\\*")
7519 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7520 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7521 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7522 (-1.0 . "^[^a-z]+@")
7523 ;;
7524 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7525 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7526 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7527 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7528 ;;
7529 (-2.0 . "^[0-9]")
7530 (-1.0 . "^[0-9][0-9]")
7531 ;;
7532 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7533 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7534 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7535 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7536 ;;
7537 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7538 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7539 ;; "[0-9]{8,}.*\@"
7540 (-3.0
7541 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7542 ;; "[0-9]{12,}.*\@"
7543 ;; compensation for TDMA dated mail addresses:
7544 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7545 ;;
7546 (-20.0 . "\\.fsf@") ;; Gnus
7547 (-20.0 . "^slrn")
7548 (-20.0 . "^Pine")
7549 (-20.0 . "^alpine\\.")
7550 (-20.0 . "_-_") ;; Subject change in thread
7551 ;;
7552 (-20.0 . "\\.ln@") ;; leafnode
7553 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7554 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7555 ;;
7556 ;; (5.0 . "") ;; $local_part_len <= 7
7557 (10.0 . "^[^0-9]+@")
7558 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7559 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7560 (3.0 . "@stud")
7561 ;;
7562 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7563 ;;
7564 (0.5 . "^[A-Z][a-z]")
7565 (0.5 . "^[A-Z][a-z][a-z]")
7566 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7567 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7568 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7569
7570 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7571 address. The REGEXP is processed with `case-fold-search' set to nil."
7572 :version "22.1"
7573 :group 'gnus-article-buttons
7574 :type '(repeat (cons (number :tag "Rate")
7575 (regexp :tag "Regexp"))))
7576
7577 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7578 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7579 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7580 address, `ask' if unsure and `invalid' if the string is invalid."
7581 (let ((case-fold-search nil)
7582 (list gnus-button-mid-or-mail-heuristic-alist)
7583 (result 0) rate regexp lpartlen elem)
7584 (setq lpartlen
7585 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7586 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7587 ;; Certain special cases...
7588 (when (string-match
7589 (concat
7590 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7591 "^[0-9]+\\.[0-9]+@compuserve\\|"
7592 "@public\\.gmane\\.org")
7593 mid-or-mail)
7594 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7595 (setq result 'mail))
7596 (when (string-match "@.*@\\| " mid-or-mail)
7597 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7598 (setq result 'invalid))
7599 ;; Nothing more to do, if result is not a number here...
7600 (when (numberp result)
7601 (while list
7602 (setq elem (car list)
7603 rate (car elem)
7604 regexp (cdr elem)
7605 list (cdr list))
7606 (when (string-match regexp mid-or-mail)
7607 (setq result (+ result rate))
7608 (gnus-message
7609 9 "`%s' matched `%s', rate `%s', result `%s'."
7610 mid-or-mail regexp rate result)))
7611 (when (<= lpartlen 7)
7612 (setq result (+ result 5.0))
7613 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7614 mid-or-mail result))
7615 (when (>= lpartlen 12)
7616 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7617 (cond
7618 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7619 ;; Long local part should contain realname if e-mail address,
7620 ;; too many digits: message-id.
7621 ;; $score -= 5.0 + 0.1 * $local_part_len;
7622 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7623 (setq result (+ result rate))
7624 (gnus-message
7625 9 "Many digits in `%s', rate `%s', result `%s'."
7626 mid-or-mail rate result))
7627 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7628 mid-or-mail)
7629 ;; Too few vowels [^aeiouy]{4,}.*@
7630 (setq result (+ result -5.0))
7631 (gnus-message
7632 9 "Few vowels in `%s', rate `%s', result `%s'."
7633 mid-or-mail -5.0 result))
7634 (t
7635 (setq result (+ result 5.0))
7636 (gnus-message
7637 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7638 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7639 ;; Maybe we should make this a customizable alist: (condition . 'result)
7640 (cond
7641 ((symbolp result) result)
7642 ;; Now convert number into proper results:
7643 ((< result -10.0) 'mid)
7644 ((> result 10.0) 'mail)
7645 (t 'ask))))
7646
7647 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7648 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7649 (url-mid (concat "news" ":" mid-or-mail))
7650 (url-mailto (concat "mailto" ":" mid-or-mail)))
7651 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7652 (when (fboundp pref)
7653 (setq guessed
7654 ;; get rid of surrounding angles...
7655 (funcall pref
7656 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7657 (if (or (eq 'mid guessed) (eq 'mail guessed))
7658 (setq pref guessed)
7659 (setq pref 'ask)))
7660 (if (eq pref 'ask)
7661 (save-window-excursion
7662 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7663 (setq pref 'mail)
7664 (setq pref 'mid))))
7665 (cond ((eq pref 'mid)
7666 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7667 (gnus-button-handle-news url-mid))
7668 ((eq pref 'mail)
7669 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7670 (gnus-url-mailto url-mailto))
7671 (t (gnus-message 3 "Invalid string.")))))
7672
7673 (defun gnus-button-handle-custom (fun arg)
7674 "Call function FUN on argument ARG.
7675 Both FUN and ARG are supposed to be strings. ARG will be passed
7676 as a symbol to FUN."
7677 (funcall (intern fun)
7678 (if (string-match "^customize-apropos" fun)
7679 arg
7680 (intern arg))))
7681
7682 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7683
7684 (defun gnus-button-handle-describe-function (url)
7685 "Call `describe-function' when pushing the corresponding URL button."
7686 (describe-function
7687 (intern
7688 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7689
7690 (defun gnus-button-handle-describe-variable (url)
7691 "Call `describe-variable' when pushing the corresponding URL button."
7692 (describe-variable
7693 (intern
7694 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7695
7696 (defun gnus-button-handle-symbol (url)
7697 "Display help on variable or function.
7698 Calls `describe-variable' or `describe-function'."
7699 (let ((sym (intern url)))
7700 (cond
7701 ((fboundp sym) (describe-function sym))
7702 ((boundp sym) (describe-variable sym))
7703 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7704
7705 (defun gnus-button-handle-describe-key (url)
7706 "Call `describe-key' when pushing the corresponding URL button."
7707 (let* ((key-string
7708 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7709 (keys (ignore-errors (eval `(kbd ,key-string)))))
7710 (if keys
7711 (describe-key keys)
7712 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7713
7714 (defun gnus-button-handle-apropos (url)
7715 "Call `apropos' when pushing the corresponding URL button."
7716 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7717
7718 (defun gnus-button-handle-apropos-command (url)
7719 "Call `apropos' when pushing the corresponding URL button."
7720 (apropos-command
7721 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7722
7723 (defun gnus-button-handle-apropos-variable (url)
7724 "Call `apropos' when pushing the corresponding URL button."
7725 (funcall
7726 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7727 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7728
7729 (defun gnus-button-handle-apropos-documentation (url)
7730 "Call `apropos' when pushing the corresponding URL button."
7731 (funcall
7732 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7733 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7734
7735 (defun gnus-button-handle-library (url)
7736 "Call `locate-library' when pushing the corresponding URL button."
7737 (gnus-message 9 "url=`%s'" url)
7738 (let* ((lib (locate-library url))
7739 (file (gnus-replace-in-string (or lib "") "\\.elc" ".el")))
7740 (if (not lib)
7741 (gnus-message 1 "Cannot locale library `%s'." url)
7742 (find-file-read-only file))))
7743
7744 (defcustom gnus-button-man-level 5
7745 "*Integer that says how many man-related buttons Gnus will show.
7746 The higher the number, the more buttons will appear and the more false
7747 positives are possible. Note that you can set this variable local to
7748 specific groups. Setting it higher in Unix groups is probably a good idea.
7749 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7750 how to set variables in specific groups."
7751 :version "22.1"
7752 :group 'gnus-article-buttons
7753 :link '(custom-manual "(gnus)Group Parameters")
7754 :type 'integer)
7755
7756 (defcustom gnus-button-emacs-level 5
7757 "*Integer that says how many emacs-related buttons Gnus will show.
7758 The higher the number, the more buttons will appear and the more false
7759 positives are possible. Note that you can set this variable local to
7760 specific groups. Setting it higher in Emacs or Gnus related groups is
7761 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7762 `gnus-parameters' on how to set variables in specific groups."
7763 :version "22.1"
7764 :group 'gnus-article-buttons
7765 :link '(custom-manual "(gnus)Group Parameters")
7766 :type 'integer)
7767
7768 (defcustom gnus-button-message-level 5
7769 "*Integer that says how many buttons for news or mail messages will appear.
7770 The higher the number, the more buttons will appear and the more false
7771 positives are possible."
7772 ;; mail addresses, MIDs, URLs for news, ...
7773 :version "22.1"
7774 :group 'gnus-article-buttons
7775 :type 'integer)
7776
7777 (defcustom gnus-button-browse-level 5
7778 "*Integer that says how many buttons for browsing will appear.
7779 The higher the number, the more buttons will appear and the more false
7780 positives are possible."
7781 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7782 :version "22.1"
7783 :group 'gnus-article-buttons
7784 :type 'integer)
7785
7786 (defcustom gnus-button-alist
7787 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7788 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7789 ((concat "\\b\\(nntp\\|news\\):\\("
7790 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7791 0 t gnus-button-handle-news 2)
7792 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7793 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7794 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7795 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7796 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7797 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7798 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7799 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7800 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7801 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7802 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7803 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7804 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7805 ;; RFC 2368 (The mailto URL scheme)
7806 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7807 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7808 ("\\bmailto:\\([^ \n\t]+\\)"
7809 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7810 ;; Info Konqueror style <info:/foo/bar baz>.
7811 ;; Must come before " Gnus home-grown style".
7812 ("\\binfo://?\\([^'\">\n\t]+\\)"
7813 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7814 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7815 ("\\binfo://\\([^'\">\n\t ]+\\)"
7816 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7817 ;; Info GNOME style <info:foo#bar_baz>
7818 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7819 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7820 ;; Info KDE style <info:(foo)bar baz>
7821 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7822 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7823 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7824 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7825 ("\\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,]*\\)\\)?"
7826 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7827 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7828 ;; This is custom
7829 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7830 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7831 ;; Emacs help commands
7832 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7833 ;; regexp doesn't match arguments containing ` '.
7834 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7835 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7836 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7837 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7838 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7839 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7840 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7841 ;; The following entries may lead to many false positives so don't enable
7842 ;; them by default (use a high button level).
7843 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7844 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7845 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7846 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7847 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7848 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7849 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7850 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7851 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7852 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7853 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7854 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7855 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7856 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7857 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7858 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7859 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7860 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7861 ;; Unlike the other regexps we really have to require quoting
7862 ;; here to determine where it ends.
7863 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7864 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7865 ("<URL: *\\([^\n<>]*\\)>"
7866 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7867 ;; RFC 2396 (2.4.3., delims) ...
7868 ("\"URL: *\\([^\n\"]*\\)\""
7869 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7870 ;; Raw URLs.
7871 (gnus-button-url-regexp
7872 0 (>= gnus-button-browse-level 0) browse-url 0)
7873 ;; man pages
7874 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7875 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7876 gnus-button-handle-man 1)
7877 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7878 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7879 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7880 gnus-button-handle-man 1)
7881 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7882 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7883 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7884 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7885 ;; Recognizing patches to .el files. This is somewhat obscure,
7886 ;; but considering the percentage of Gnus users who hack Emacs
7887 ;; Lisp files...
7888 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7889 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7890 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7891 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7892 ;; MID or mail: To avoid too many false positives we don't try to catch
7893 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7894 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7895 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7896 ;; so that non-ambiguous entries (see above) match first.
7897 (gnus-button-mid-or-mail-regexp
7898 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7899 "*Alist of regexps matching buttons in article bodies.
7900
7901 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7902 REGEXP: is the string (case insensitive) matching text around the button (can
7903 also be Lisp expression evaluating to a string),
7904 BUTTON: is the number of the regexp grouping actually matching the button,
7905 FORM: is a Lisp expression which must eval to true for the button to
7906 be added,
7907 CALLBACK: is the function to call when the user push this button, and each
7908 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7909
7910 CALLBACK can also be a variable, in that case the value of that
7911 variable it the real callback function."
7912 :group 'gnus-article-buttons
7913 :type '(repeat (list (choice regexp variable sexp)
7914 (integer :tag "Button")
7915 (sexp :tag "Form")
7916 (function :tag "Callback")
7917 (repeat :tag "Par"
7918 :inline t
7919 (integer :tag "Regexp group")))))
7920 (put 'gnus-button-alist 'risky-local-variable t)
7921
7922 (defcustom gnus-header-button-alist
7923 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7924 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7925 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7926 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7927 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7928 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7929 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7930 0 (>= gnus-button-browse-level 0) browse-url 0)
7931 ("^Subject:" gnus-button-url-regexp
7932 0 (>= gnus-button-browse-level 0) browse-url 0)
7933 ("^[^:]+:" gnus-button-url-regexp
7934 0 (>= gnus-button-browse-level 0) browse-url 0)
7935 ("^OpenPGP:.*url=" gnus-button-url-regexp
7936 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7937 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7938 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7939 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7940 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7941 "*Alist of headers and regexps to match buttons in article heads.
7942
7943 This alist is very similar to `gnus-button-alist', except that each
7944 alist has an additional HEADER element first in each entry:
7945
7946 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7947
7948 HEADER is a regexp to match a header. For a fuller explanation, see
7949 `gnus-button-alist'."
7950 :group 'gnus-article-buttons
7951 :group 'gnus-article-headers
7952 :type '(repeat (list (regexp :tag "Header")
7953 (choice regexp variable)
7954 (integer :tag "Button")
7955 (sexp :tag "Form")
7956 (function :tag "Callback")
7957 (repeat :tag "Par"
7958 :inline t
7959 (integer :tag "Regexp group")))))
7960 (put 'gnus-header-button-alist 'risky-local-variable t)
7961
7962 ;;; Commands:
7963
7964 (defun gnus-article-push-button (event)
7965 "Check text under the mouse pointer for a callback function.
7966 If the text under the mouse pointer has a `gnus-callback' property,
7967 call it with the value of the `gnus-data' text property."
7968 (interactive "e")
7969 (set-buffer (window-buffer (posn-window (event-start event))))
7970 (let* ((pos (posn-point (event-start event)))
7971 (data (get-text-property pos 'gnus-data))
7972 (fun (get-text-property pos 'gnus-callback)))
7973 (goto-char pos)
7974 (when fun
7975 (funcall fun data))))
7976
7977 (defun gnus-article-press-button ()
7978 "Check text at point for a callback function.
7979 If the text at point has a `gnus-callback' property,
7980 call it with the value of the `gnus-data' text property."
7981 (interactive)
7982 (let ((data (get-text-property (point) 'gnus-data))
7983 (fun (get-text-property (point) 'gnus-callback)))
7984 (when fun
7985 (funcall fun data))))
7986
7987 (defun gnus-article-highlight (&optional force)
7988 "Highlight current article.
7989 This function calls `gnus-article-highlight-headers',
7990 `gnus-article-highlight-citation',
7991 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7992 do the highlighting. See the documentation for those functions."
7993 (interactive (list 'force))
7994 (gnus-article-highlight-headers)
7995 (gnus-article-highlight-citation force)
7996 (gnus-article-highlight-signature)
7997 (gnus-article-add-buttons)
7998 (gnus-article-add-buttons-to-head))
7999
8000 (defun gnus-article-highlight-some (&optional _force)
8001 "Highlight current article.
8002 This function calls `gnus-article-highlight-headers',
8003 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
8004 do the highlighting. See the documentation for those functions."
8005 (interactive (list 'force))
8006 (gnus-article-highlight-headers)
8007 (gnus-article-highlight-signature)
8008 (gnus-article-add-buttons))
8009
8010 (defun gnus-article-highlight-headers ()
8011 "Highlight article headers as specified by `gnus-header-face-alist'."
8012 (interactive)
8013 (gnus-with-article-headers
8014 (let (regexp header-face field-face from hpoints fpoints)
8015 (dolist (entry gnus-header-face-alist)
8016 (goto-char (point-min))
8017 (setq regexp (concat "^\\("
8018 (if (string-equal "" (nth 0 entry))
8019 "[^\t ]"
8020 (nth 0 entry))
8021 "\\)")
8022 header-face (nth 1 entry)
8023 field-face (nth 2 entry))
8024 (while (and (re-search-forward regexp nil t)
8025 (not (eobp)))
8026 (beginning-of-line)
8027 (setq from (point))
8028 (unless (search-forward ":" nil t)
8029 (forward-char 1))
8030 (when (and header-face
8031 (not (memq (point) hpoints)))
8032 (push (point) hpoints)
8033 (gnus-put-text-property from (point) 'face header-face))
8034 (when (and field-face
8035 (not (memq (setq from (point)) fpoints)))
8036 (push from fpoints)
8037 (if (re-search-forward "^[^ \t]" nil t)
8038 (forward-char -2)
8039 (goto-char (point-max)))
8040 (gnus-put-text-property from (point) 'face field-face)))))))
8041
8042 (defun gnus-article-highlight-signature ()
8043 "Highlight the signature in an article.
8044 It does this by highlighting everything after
8045 `gnus-signature-separator' using the face `gnus-signature'."
8046 (interactive)
8047 (gnus-with-article-buffer
8048 (let ((inhibit-point-motion-hooks t))
8049 (save-restriction
8050 (when (and gnus-signature-face
8051 (gnus-article-narrow-to-signature))
8052 (overlay-put (make-overlay (point-min) (point-max) nil t)
8053 'face gnus-signature-face)
8054 (widen)
8055 (gnus-article-search-signature)
8056 (let ((start (match-beginning 0))
8057 (end (set-marker (make-marker) (1+ (match-end 0)))))
8058 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8059 end)))))))
8060
8061 (defun gnus-button-in-region-p (b e prop)
8062 "Say whether PROP exists in the region."
8063 (text-property-not-all b e prop nil))
8064
8065 (defun gnus-article-add-buttons ()
8066 "Find external references in the article and make buttons of them.
8067 \"External references\" are things like Message-IDs and URLs, as
8068 specified by `gnus-button-alist'."
8069 (interactive)
8070 (gnus-with-article-buffer
8071 (let ((inhibit-point-motion-hooks t)
8072 (case-fold-search t)
8073 (alist gnus-button-alist)
8074 beg entry regexp)
8075 ;; We skip the headers.
8076 (article-goto-body)
8077 (setq beg (point))
8078 (while (setq entry (pop alist))
8079 (setq regexp (eval (car entry)))
8080 (goto-char beg)
8081 (while (re-search-forward regexp nil t)
8082 (let ((start (match-beginning (nth 1 entry)))
8083 (end (match-end (nth 1 entry)))
8084 (from (match-beginning 0)))
8085 (when (and (eval (nth 2 entry))
8086 (not (gnus-button-in-region-p
8087 start end 'gnus-callback)))
8088 ;; That optional form returned non-nil, so we add the
8089 ;; button.
8090 (setq from (set-marker (make-marker) from))
8091 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8092 (gnus-article-extend-url-button from start end))
8093 (gnus-article-add-button start end
8094 'gnus-button-push (list from entry))
8095 (gnus-put-text-property
8096 start end
8097 'gnus-string (buffer-substring-no-properties
8098 start end))))))))))
8099
8100 (defun gnus-article-extend-url-button (beg start end)
8101 "Extend url button if url is folded into two or more lines.
8102 Return non-nil if button is extended. BEG is a marker that points to
8103 the beginning position of a text containing url. START and END are
8104 the endpoints of a url button before it is extended. The concatenated
8105 url is put as the `gnus-button-url' overlay property on the button."
8106 (let ((opoint (point))
8107 (points (list start end))
8108 url delim regexp)
8109 (prog1
8110 (when (and (progn
8111 (goto-char end)
8112 (not (looking-at "[\t ]*[\">]")))
8113 (progn
8114 (goto-char start)
8115 (string-match
8116 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8117 (buffer-substring (point-at-bol) start)))
8118 (progn
8119 (setq url (list (buffer-substring start end))
8120 delim (if (match-beginning 1) ">" "\""))
8121 (beginning-of-line)
8122 (setq regexp (concat
8123 (when (and (looking-at
8124 message-cite-prefix-regexp)
8125 (< (match-end 0) start))
8126 (regexp-quote (match-string 0)))
8127 "\
8128 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8129 delim "\\)"))
8130 (while (progn
8131 (forward-line 1)
8132 (and (looking-at regexp)
8133 (prog1
8134 (match-beginning 1)
8135 (push (or (match-string 2)
8136 (match-string 1))
8137 url)
8138 (push (setq end (or (match-end 2)
8139 (match-end 1)))
8140 points)
8141 (push (or (match-beginning 2)
8142 (match-beginning 1))
8143 points)))))
8144 (match-beginning 2)))
8145 (let (gnus-article-mouse-face widget-mouse-face)
8146 (while points
8147 (gnus-article-add-button (pop points) (pop points)
8148 'gnus-button-push
8149 (list beg (assq 'gnus-button-url-regexp
8150 gnus-button-alist)))))
8151 (let ((overlay (make-overlay start end)))
8152 (overlay-put overlay 'evaporate t)
8153 (overlay-put overlay 'gnus-button-url
8154 (list (mapconcat 'identity (nreverse url) "")))
8155 (when gnus-article-mouse-face
8156 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8157 t)
8158 (goto-char opoint))))
8159
8160 ;; Add buttons to the head of an article.
8161 (defun gnus-article-add-buttons-to-head ()
8162 "Add buttons to the head of the article."
8163 (interactive)
8164 (gnus-with-article-headers
8165 (let (beg end)
8166 (dolist (entry gnus-header-button-alist)
8167 ;; Each alist entry.
8168 (goto-char (point-min))
8169 (while (re-search-forward (car entry) nil t)
8170 ;; Each header matching the entry.
8171 (setq beg (match-beginning 0))
8172 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8173 (match-beginning 0))
8174 (point-max)))
8175 (goto-char beg)
8176 (while (re-search-forward (eval (nth 1 entry)) end t)
8177 ;; Each match within a header.
8178 (let* ((entry (cdr entry))
8179 (start (match-beginning (nth 1 entry)))
8180 (end (match-end (nth 1 entry)))
8181 (form (nth 2 entry)))
8182 (goto-char (match-end 0))
8183 (when (eval form)
8184 (gnus-article-add-button
8185 start end (nth 3 entry)
8186 (buffer-substring (match-beginning (nth 4 entry))
8187 (match-end (nth 4 entry)))))))
8188 (goto-char end))))))
8189
8190 ;;; External functions:
8191
8192 (defun gnus-article-add-button (from to fun &optional data text)
8193 "Create a button between FROM and TO with callback FUN and data DATA."
8194 (when gnus-article-button-face
8195 (overlay-put (make-overlay from to nil t)
8196 'face gnus-article-button-face))
8197 (gnus-add-text-properties
8198 from to
8199 (nconc (and gnus-article-mouse-face
8200 (list gnus-mouse-face-prop gnus-article-mouse-face))
8201 (list 'gnus-callback fun)
8202 (and data (list 'gnus-data data))))
8203 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8204 :help-echo (or text "Follow the link")
8205 :keymap gnus-url-button-map
8206 :button-keymap gnus-widget-button-keymap))
8207
8208 (defun gnus-article-copy-string ()
8209 "Copy the string in the button to the kill ring."
8210 (interactive)
8211 (gnus-article-check-buffer)
8212 (let ((data (get-text-property (point) 'gnus-string)))
8213 (when data
8214 (with-temp-buffer
8215 (insert data)
8216 (copy-region-as-kill (point-min) (point-max))
8217 (message "Copied %s" data)))))
8218
8219 ;;; Internal functions:
8220
8221 (defun gnus-article-set-globals ()
8222 (with-current-buffer gnus-summary-buffer
8223 (gnus-set-global-variables)))
8224
8225 (defun gnus-signature-toggle (end)
8226 (gnus-with-article-buffer
8227 (let ((inhibit-point-motion-hooks t))
8228 (if (text-property-any end (point-max) 'article-type 'signature)
8229 (progn
8230 (gnus-delete-wash-type 'signature)
8231 (gnus-remove-text-properties-when
8232 'article-type 'signature end (point-max)
8233 (cons 'article-type (cons 'signature
8234 gnus-hidden-properties))))
8235 (gnus-add-wash-type 'signature)
8236 (gnus-add-text-properties-when
8237 'article-type nil end (point-max)
8238 (cons 'article-type (cons 'signature
8239 gnus-hidden-properties)))))
8240 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8241 (gnus-set-mode-line 'article))))
8242
8243 (defun gnus-button-push (marker-and-entry)
8244 ;; Push button starting at MARKER.
8245 (save-excursion
8246 (let* ((marker (car marker-and-entry))
8247 (entry (cadr marker-and-entry))
8248 (regexp (car entry))
8249 (inhibit-point-motion-hooks t))
8250 (goto-char marker)
8251 ;; This is obviously true, or something bad is happening :)
8252 ;; But we need it to have the match-data
8253 (when (looking-at (or (if (symbolp regexp)
8254 (symbol-value regexp)
8255 regexp)))
8256 (let ((fun (nth 3 entry))
8257 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8258 (get-char-property marker 'gnus-button-url))
8259 (mapcar (lambda (group)
8260 (let ((string (match-string group)))
8261 (set-text-properties
8262 0 (length string) nil string)
8263 string))
8264 (nthcdr 4 entry)))))
8265
8266 (cond
8267 ((fboundp fun)
8268 (apply fun args))
8269 ((and (boundp fun)
8270 (fboundp (symbol-value fun)))
8271 (apply (symbol-value fun) args))
8272 (t
8273 (gnus-message 1 "You must define `%S' to use this button"
8274 (cons fun args)))))))))
8275
8276 (defun gnus-parse-news-url (url)
8277 (let (scheme server port group message-id articles)
8278 (with-temp-buffer
8279 (insert url)
8280 (goto-char (point-min))
8281 (when (looking-at "\\([A-Za-z]+\\):")
8282 (setq scheme (match-string 1))
8283 (goto-char (match-end 0)))
8284 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8285 (setq server (match-string 1))
8286 (setq port (if (stringp (match-string 3))
8287 (string-to-number (match-string 3))
8288 (match-string 3)))
8289 (goto-char (match-end 0)))
8290
8291 (cond
8292 ((looking-at "\\(.*@.*\\)")
8293 (setq message-id (match-string 1)))
8294 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8295 (setq group (match-string 1)
8296 articles (split-string (match-string 2) "-")))
8297 ((looking-at "\\([^/]+\\)/?")
8298 (setq group (match-string 1)))
8299 (t
8300 (error "Unknown news URL syntax"))))
8301 (list scheme server port group message-id articles)))
8302
8303 (defvar nntp-port-number)
8304
8305 (defun gnus-button-handle-news (url)
8306 "Fetch a news URL."
8307 (destructuring-bind (_scheme server port group message-id _articles)
8308 (gnus-parse-news-url url)
8309 (cond
8310 (message-id
8311 (with-current-buffer gnus-summary-buffer
8312 (if server
8313 (let ((gnus-refer-article-method
8314 (nconc (list (list 'nntp server))
8315 gnus-refer-article-method))
8316 (nntp-port-number (or port "nntp")))
8317 (gnus-message 7 "Fetching %s with %s"
8318 message-id gnus-refer-article-method)
8319 (gnus-summary-refer-article message-id))
8320 (gnus-summary-refer-article message-id))))
8321 (group
8322 (gnus-button-fetch-group url)))))
8323
8324 (defun gnus-button-patch (library line)
8325 "Visit an Emacs Lisp library LIBRARY on line LINE."
8326 (interactive)
8327 (let ((file (locate-library (file-name-nondirectory library))))
8328 (unless file
8329 (error "Couldn't find library %s" library))
8330 (find-file file)
8331 (goto-char (point-min))
8332 (forward-line (1- (string-to-number line)))))
8333
8334 (defun gnus-button-handle-man (url)
8335 "Fetch a man page."
8336 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8337 (when (eq gnus-button-man-handler 'woman)
8338 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8339 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8340 (funcall gnus-button-man-handler url))
8341
8342 (defun gnus-button-handle-info-url (url)
8343 "Fetch an info URL."
8344 (setq url (mm-subst-char-in-string ?+ ?\ url))
8345 (cond
8346 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8347 (gnus-info-find-node
8348 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8349 "Gnus")
8350 ")" (gnus-url-unhex-string (match-string 2 url)))))
8351 ((string-match "([^)\"]+)[^\"]+" url)
8352 (setq url
8353 (gnus-replace-in-string
8354 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8355 (gnus-info-find-node url))
8356 (t (error "Can't parse %s" url))))
8357
8358 (defun gnus-button-handle-info-url-gnome (url)
8359 "Fetch GNOME style info URL."
8360 (setq url (mm-subst-char-in-string ?_ ?\ url))
8361 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8362 (gnus-info-find-node
8363 (concat "("
8364 (gnus-url-unhex-string
8365 (match-string 1 url))
8366 ")"
8367 (or (gnus-url-unhex-string
8368 (match-string 2 url))
8369 "Top")))
8370 (error "Can't parse %s" url)))
8371
8372 (defun gnus-button-handle-info-url-kde (url)
8373 "Fetch KDE style info URL."
8374 (gnus-info-find-node (gnus-url-unhex-string url)))
8375
8376 ;; (info) will autoload info.el
8377 (declare-function Info-menu "info" (menu-item &optional fork))
8378 (declare-function Info-index-next "info" (num))
8379
8380 (defun gnus-button-handle-info-keystrokes (url)
8381 "Call `info' when pushing the corresponding URL button."
8382 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8383 (let (node indx comma)
8384 (if (string-match
8385 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8386 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8387 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8388 "\\(?:[ \t\n,]*\\)\\)?")
8389 url)
8390 (setq node (match-string 2 url)
8391 indx (match-string 3 url))
8392 (error "Can't parse %s" url))
8393 (info)
8394 (Info-directory)
8395 (Info-menu node)
8396 (when (> (length indx) 0)
8397 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8398 "\\([ \t\n,]*\\)")
8399 indx)
8400 (setq comma (match-string 2 indx))
8401 (setq indx (match-string 1 indx))
8402 (Info-index indx)
8403 (when comma
8404 (dotimes (i (with-temp-buffer
8405 (insert comma)
8406 ;; Note: the XEmacs version of `how-many' takes
8407 ;; no optional argument.
8408 (goto-char (point-min))
8409 (how-many ",")))
8410 (Info-index-next 1)))
8411 nil)))
8412
8413 (autoload 'pgg-snarf-keys-region "pgg")
8414 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8415 (declare-function pgg-display-output-buffer "pgg" (start end status))
8416
8417 (defun gnus-button-openpgp (url)
8418 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8419 (with-temp-buffer
8420 (mm-url-insert-file-contents-external url)
8421 (pgg-snarf-keys-region (point-min) (point-max))
8422 (pgg-display-output-buffer nil nil nil)))
8423
8424 (defun gnus-button-message-id (message-id)
8425 "Fetch MESSAGE-ID."
8426 (with-current-buffer gnus-summary-buffer
8427 (gnus-summary-refer-article message-id)))
8428
8429 (defun gnus-button-fetch-group (address &rest _ignore)
8430 "Fetch GROUP specified by ADDRESS."
8431 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8432 address)
8433 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8434 ;; for nntp:// and news://
8435 (setq address (match-string 3 address)))
8436 (if (not (string-match "[:/]" address))
8437 ;; This is just a simple group url.
8438 (gnus-group-read-ephemeral-group address gnus-select-method)
8439 (if (not
8440 (string-match
8441 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8442 address))
8443 (error "Can't parse %s" address)
8444 (gnus-group-read-ephemeral-group
8445 (match-string 4 address)
8446 `(nntp ,(match-string 1 address)
8447 (nntp-address ,(match-string 1 address))
8448 (nntp-port-number ,(if (match-end 3)
8449 (match-string 3 address)
8450 "nntp")))
8451 nil nil nil
8452 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8453
8454 (defun gnus-url-parse-query-string (query &optional downcase)
8455 (let (retval pairs cur key val)
8456 (setq pairs (split-string query "&"))
8457 (while pairs
8458 (setq cur (car pairs)
8459 pairs (cdr pairs))
8460 (if (not (string-match "=" cur))
8461 nil ; Grace
8462 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8463 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8464 (if downcase
8465 (setq key (downcase key)))
8466 (setq cur (assoc key retval))
8467 (if cur
8468 (setcdr cur (cons val (cdr cur)))
8469 (setq retval (cons (list key val) retval)))))
8470 retval))
8471
8472 (defun gnus-url-mailto (url)
8473 ;; Send mail to someone
8474 (setq url (replace-regexp-in-string "\n" " " url))
8475 (when (string-match "mailto:/*\\(.*\\)" url)
8476 (setq url (substring url (match-beginning 1) nil)))
8477 (let* ((args (gnus-url-parse-query-string
8478 (if (string-match "^\\?" url)
8479 (substring url 1)
8480 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8481 (concat "to=" (match-string 1 url) "&"
8482 (match-string 2 url))
8483 (concat "to=" url)))))
8484 (subject (cdr-safe (assoc "subject" args)))
8485 func)
8486 (gnus-msg-mail)
8487 (while args
8488 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8489 (if (fboundp func)
8490 (funcall func)
8491 (message-position-on-field (caar args)))
8492 (insert (gnus-replace-in-string
8493 (mapconcat 'identity (reverse (cdar args)) ", ")
8494 "\r\n" "\n" t))
8495 (setq args (cdr args)))
8496 (if subject
8497 (message-goto-body)
8498 (message-goto-subject))))
8499
8500 (defun gnus-button-embedded-url (address)
8501 "Activate ADDRESS with `browse-url'."
8502 (browse-url (gnus-strip-whitespace address)))
8503
8504 ;;; Next/prev buttons in the article buffer.
8505
8506 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8507 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8508
8509 (defvar gnus-prev-page-map
8510 (let ((map (make-sparse-keymap)))
8511 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8512 (define-key map "\r" 'gnus-button-prev-page)
8513 map))
8514
8515 (defvar gnus-next-page-map
8516 (let ((map (make-sparse-keymap)))
8517 (define-key map gnus-mouse-2 'gnus-button-next-page)
8518 (define-key map "\r" 'gnus-button-next-page)
8519 map))
8520
8521 (defun gnus-insert-prev-page-button ()
8522 (let ((b (point)) e
8523 (inhibit-read-only t))
8524 (gnus-eval-format
8525 gnus-prev-page-line-format nil
8526 `(keymap ,gnus-prev-page-map
8527 gnus-prev t
8528 gnus-callback gnus-article-button-prev-page
8529 article-type annotation))
8530 (setq e (if (bolp)
8531 ;; Exclude a newline.
8532 (1- (point))
8533 (point)))
8534 (when gnus-article-button-face
8535 (overlay-put (make-overlay b e nil t)
8536 'face gnus-article-button-face))
8537 (widget-convert-button
8538 'link b e
8539 :action 'gnus-button-prev-page
8540 :button-keymap gnus-prev-page-map)))
8541
8542 (defun gnus-button-next-page (&optional _args _more-args)
8543 "Go to the next page."
8544 (interactive)
8545 (let ((win (selected-window)))
8546 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8547 (gnus-article-next-page)
8548 (select-window win)))
8549
8550 (defun gnus-button-prev-page (&optional _args _more-args)
8551 "Go to the prev page."
8552 (interactive)
8553 (let ((win (selected-window)))
8554 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8555 (gnus-article-prev-page)
8556 (select-window win)))
8557
8558 (defun gnus-insert-next-page-button ()
8559 (let ((b (point)) e
8560 (inhibit-read-only t))
8561 (gnus-eval-format gnus-next-page-line-format nil
8562 `(keymap ,gnus-next-page-map
8563 gnus-next t
8564 gnus-callback gnus-article-button-next-page
8565 article-type annotation))
8566 (setq e (if (bolp)
8567 ;; Exclude a newline.
8568 (1- (point))
8569 (point)))
8570 (when gnus-article-button-face
8571 (overlay-put (make-overlay b e nil t)
8572 'face gnus-article-button-face))
8573 (widget-convert-button
8574 'link b e
8575 :action 'gnus-button-next-page
8576 :button-keymap gnus-next-page-map)))
8577
8578 (defun gnus-article-button-next-page (_arg)
8579 "Go to the next page."
8580 (interactive "P")
8581 (let ((win (selected-window)))
8582 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8583 (gnus-article-next-page)
8584 (select-window win)))
8585
8586 (defun gnus-article-button-prev-page (_arg)
8587 "Go to the prev page."
8588 (interactive "P")
8589 (let ((win (selected-window)))
8590 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8591 (gnus-article-prev-page)
8592 (select-window win)))
8593
8594 (defvar gnus-decode-header-methods
8595 '(mail-decode-encoded-word-region)
8596 "List of methods used to decode headers.
8597
8598 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8599 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8600 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8601 whose names match REGEXP.
8602
8603 For example:
8604 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8605 mail-decode-encoded-word-region
8606 (\"chinese\" . rfc1843-decode-region))
8607 ")
8608
8609 (defvar gnus-decode-header-methods-cache nil)
8610
8611 (defun gnus-multi-decode-header (start end)
8612 "Apply the functions from `gnus-encoded-word-methods' that match."
8613 (unless (and gnus-decode-header-methods-cache
8614 (eq gnus-newsgroup-name
8615 (car gnus-decode-header-methods-cache)))
8616 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8617 (dolist (x gnus-decode-header-methods)
8618 (if (symbolp x)
8619 (nconc gnus-decode-header-methods-cache (list x))
8620 (if (and gnus-newsgroup-name
8621 (string-match (car x) gnus-newsgroup-name))
8622 (nconc gnus-decode-header-methods-cache
8623 (list (cdr x)))))))
8624 (let ((xlist gnus-decode-header-methods-cache))
8625 (pop xlist)
8626 (save-restriction
8627 (narrow-to-region start end)
8628 (while xlist
8629 (funcall (pop xlist) (point-min) (point-max))))))
8630
8631 ;;;
8632 ;;; Treatment top-level handling.
8633 ;;;
8634
8635 (defvar gnus-inhibit-article-treatments nil)
8636
8637 ;; Dynamic variables.
8638 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8639 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8640 (defvar gnus-treat-type)
8641 (defvar gnus-treat-condition)
8642 (defvar gnus-treat-length)
8643
8644 (defun gnus-treat-article (condition
8645 &optional part-num total type)
8646 (let ((gnus-treat-condition condition)
8647 (part-number part-num)
8648 (total-parts total)
8649 (gnus-treat-type type)
8650 (gnus-treat-length (- (point-max) (point-min)))
8651 (alist gnus-treatment-function-alist)
8652 (article-goto-body-goes-to-point-min-p t)
8653 (treated-type
8654 (or (not type)
8655 (catch 'found
8656 (let ((list gnus-article-treat-types))
8657 (while list
8658 (when (string-match (pop list) type)
8659 (throw 'found t)))))))
8660 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8661 val)
8662 (gnus-run-hooks 'gnus-part-display-hook)
8663 (dolist (elem alist)
8664 (setq val
8665 (save-excursion
8666 (when (gnus-buffer-live-p gnus-summary-buffer)
8667 (set-buffer gnus-summary-buffer))
8668 (symbol-value (car elem))))
8669 (when (and (or (consp val)
8670 treated-type)
8671 (or (not gnus-inhibit-article-treatments)
8672 (eq gnus-treat-condition 'head))
8673 (gnus-treat-predicate val)
8674 (or (not (get (car elem) 'highlight))
8675 highlightp))
8676 (save-restriction
8677 (funcall (cadr elem)))))))
8678
8679 (defun gnus-treat-predicate (val)
8680 (cond
8681 ((null val)
8682 nil)
8683 (gnus-treat-condition
8684 (eq gnus-treat-condition val))
8685 ((and (listp val)
8686 (stringp (car val)))
8687 (apply 'gnus-or (mapcar `(lambda (s)
8688 (string-match s ,(or gnus-newsgroup-name "")))
8689 val)))
8690 ((listp val)
8691 (let ((pred (pop val)))
8692 (cond
8693 ((eq pred 'or)
8694 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8695 ((eq pred 'and)
8696 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8697 ((eq pred 'not)
8698 (not (gnus-treat-predicate (car val))))
8699 ((eq pred 'typep)
8700 (equal (car val) gnus-treat-type))
8701 ((functionp pred)
8702 (funcall pred))
8703 (t
8704 (error "%S is not a valid predicate" pred)))))
8705 ((eq val t)
8706 t)
8707 ((eq val 'head)
8708 nil)
8709 ((eq val 'first)
8710 (eq part-number 1))
8711 ((eq val 'last)
8712 (eq part-number total-parts))
8713 ((numberp val)
8714 (< gnus-treat-length val))
8715 (t
8716 (error "%S is not a valid value" val))))
8717
8718 (defun gnus-article-encrypt-body (protocol &optional n)
8719 "Encrypt the article body."
8720 (interactive
8721 (list
8722 (or gnus-article-encrypt-protocol
8723 (gnus-completing-read "Encrypt protocol"
8724 (mapcar 'car gnus-article-encrypt-protocol-alist)
8725 t))
8726 current-prefix-arg))
8727 ;; User might hit `K E' instead of `K e', so prompt once.
8728 (when (and gnus-article-encrypt-protocol
8729 gnus-novice-user)
8730 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8731 (error "Encrypt aborted")))
8732 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8733 (unless func
8734 (error "Can't find the encrypt protocol %s" protocol))
8735 (if (member gnus-newsgroup-name '("nndraft:delayed"
8736 "nndraft:drafts"
8737 "nndraft:queue"))
8738 (error "Can't encrypt the article in group %s"
8739 gnus-newsgroup-name))
8740 (gnus-summary-iterate n
8741 (with-current-buffer gnus-summary-buffer
8742 (let ((mail-parse-charset gnus-newsgroup-charset)
8743 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8744 (summary-buffer gnus-summary-buffer)
8745 references point)
8746 (gnus-set-global-variables)
8747 (when (gnus-group-read-only-p)
8748 (error "The current newsgroup does not support article encrypt"))
8749 (gnus-summary-show-article t)
8750 (setq references
8751 (or (mail-header-references gnus-current-headers) ""))
8752 (set-buffer gnus-article-buffer)
8753 (let* ((inhibit-read-only t)
8754 (headers
8755 (mapcar (lambda (field)
8756 (and (save-restriction
8757 (message-narrow-to-head)
8758 (goto-char (point-min))
8759 (search-forward field nil t))
8760 (prog2
8761 (message-narrow-to-field)
8762 (buffer-string)
8763 (delete-region (point-min) (point-max))
8764 (widen))))
8765 '("Content-Type:" "Content-Transfer-Encoding:"
8766 "Content-Disposition:"))))
8767 (message-narrow-to-head)
8768 (message-remove-header "MIME-Version")
8769 (goto-char (point-max))
8770 (setq point (point))
8771 (insert (apply 'concat headers))
8772 (widen)
8773 (narrow-to-region point (point-max))
8774 (let ((message-options message-options))
8775 (message-options-set 'message-sender user-mail-address)
8776 (message-options-set 'message-recipients user-mail-address)
8777 (message-options-set 'message-sign-encrypt 'not)
8778 (funcall func))
8779 (goto-char (point-min))
8780 (insert "MIME-Version: 1.0\n")
8781 (widen)
8782 (gnus-summary-edit-article-done
8783 references nil summary-buffer t))
8784 (when gnus-keep-backlog
8785 (gnus-backlog-remove-article
8786 (car gnus-article-current) (cdr gnus-article-current)))
8787 (gnus-flush-original-article-buffer)
8788 (when gnus-use-cache
8789 (gnus-cache-update-article
8790 (car gnus-article-current) (cdr gnus-article-current))))))))
8791
8792 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8793 "The following specs can be used:
8794 %t The security MIME type
8795 %i Additional info
8796 %d Details
8797 %D Details if button is pressed")
8798
8799 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8800 "The following specs can be used:
8801 %t The security MIME type
8802 %i Additional info
8803 %d Details
8804 %D Details if button is pressed")
8805
8806 (defvar gnus-mime-security-button-line-format-alist
8807 '((?t gnus-tmp-type ?s)
8808 (?i gnus-tmp-info ?s)
8809 (?d gnus-tmp-details ?s)
8810 (?D gnus-tmp-pressed-details ?s)))
8811
8812 (defvar gnus-mime-security-button-commands
8813 '((gnus-article-press-button "\r" "Show Detail")
8814 (undefined "v")
8815 (undefined "t")
8816 (undefined "C")
8817 (gnus-mime-security-save-part "o" "Save...")
8818 (undefined "\C-o")
8819 (undefined "r")
8820 (undefined "d")
8821 (undefined "c")
8822 (undefined "i")
8823 (undefined "E")
8824 (undefined "e")
8825 (undefined "p")
8826 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8827 (undefined ".")))
8828
8829 (defvar gnus-mime-security-button-map
8830 (let ((map (make-sparse-keymap)))
8831 (define-key map gnus-mouse-2 'gnus-article-push-button)
8832 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8833 (dolist (c gnus-mime-security-button-commands)
8834 (define-key map (cadr c) (car c)))
8835 map))
8836
8837 (easy-menu-define
8838 gnus-mime-security-button-menu gnus-mime-security-button-map
8839 "Security button menu."
8840 `("Security Part"
8841 ,@(delq nil
8842 (mapcar (lambda (c)
8843 (unless (eq (car c) 'undefined)
8844 (vector (caddr c) (car c) :active t)))
8845 gnus-mime-security-button-commands))))
8846
8847 (defun gnus-mime-security-button-menu (event prefix)
8848 "Construct a context-sensitive menu of security commands."
8849 (interactive "e\nP")
8850 (save-window-excursion
8851 (let ((pos (event-start event)))
8852 (select-window (posn-window pos))
8853 (goto-char (posn-point pos))
8854 (gnus-article-check-buffer)
8855 (popup-menu gnus-mime-security-button-menu nil prefix))))
8856
8857 (defvar gnus-mime-security-details-buffer nil)
8858
8859 (defvar gnus-mime-security-button-pressed nil)
8860
8861 (defvar gnus-mime-security-show-details-inline t
8862 "If non-nil, show details in the article buffer.")
8863
8864 (defun gnus-mime-security-verify-or-decrypt (handle)
8865 (mm-remove-parts (cdr handle))
8866 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8867 point (inhibit-read-only t))
8868 (if region
8869 (goto-char (car region)))
8870 (setq point (point))
8871 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8872 (let* ((mm-verify-option 'known)
8873 (mm-decrypt-option 'known)
8874 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8875 (unless (eq nparts (cdr handle))
8876 (mm-destroy-parts (cdr handle))
8877 (setcdr handle nparts))))
8878 (gnus-mime-display-security handle)
8879 (when region
8880 (delete-region (point) (cdr region))
8881 (set-marker (car region) nil)
8882 (set-marker (cdr region) nil))
8883 (goto-char point)))
8884
8885 (defun gnus-mime-security-show-details (handle)
8886 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8887 (if (not details)
8888 (gnus-message 5 "No details.")
8889 (if gnus-mime-security-show-details-inline
8890 (let ((gnus-mime-security-button-pressed
8891 (not (get-text-property (point) 'gnus-mime-details)))
8892 (gnus-mime-security-button-line-format
8893 (get-text-property (point) 'gnus-line-format))
8894 (inhibit-read-only t))
8895 (forward-char -1)
8896 (while (eq (get-text-property (point) 'gnus-line-format)
8897 gnus-mime-security-button-line-format)
8898 (forward-char -1))
8899 (forward-char)
8900 (save-restriction
8901 (narrow-to-region (point) (point))
8902 (gnus-insert-mime-security-button handle))
8903 (delete-region (point)
8904 (or (text-property-not-all
8905 (point) (point-max)
8906 'gnus-line-format
8907 gnus-mime-security-button-line-format)
8908 (point-max))))
8909 ;; Not inlined.
8910 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8911 (with-current-buffer gnus-mime-security-details-buffer
8912 (erase-buffer)
8913 t)
8914 (setq gnus-mime-security-details-buffer
8915 (gnus-get-buffer-create "*MIME Security Details*")))
8916 (with-current-buffer gnus-mime-security-details-buffer
8917 (insert details)
8918 (goto-char (point-min)))
8919 (pop-to-buffer gnus-mime-security-details-buffer)))))
8920
8921 (defun gnus-mime-security-press-button (handle)
8922 (save-excursion
8923 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8924 (gnus-mime-security-show-details handle)
8925 (gnus-mime-security-verify-or-decrypt handle))))
8926
8927 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8928 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8929 (gnus-tmp-type
8930 (concat
8931 (or (nth 2 (assoc protocol mm-verify-function-alist))
8932 (nth 2 (assoc protocol mm-decrypt-function-alist))
8933 "Unknown")
8934 (if (equal (car handle) "multipart/signed")
8935 " Signed" " Encrypted")
8936 " Part"))
8937 (gnus-tmp-info
8938 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8939 "Undecided"))
8940 (gnus-tmp-details
8941 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8942 gnus-tmp-pressed-details
8943 b e)
8944 (setq gnus-tmp-details
8945 (if gnus-tmp-details
8946 (concat "\n" gnus-tmp-details)
8947 ""))
8948 (setq gnus-tmp-pressed-details
8949 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8950 (unless (bolp)
8951 (insert "\n"))
8952 (setq b (point))
8953 (gnus-eval-format
8954 gnus-mime-security-button-line-format
8955 gnus-mime-security-button-line-format-alist
8956 `(keymap ,gnus-mime-security-button-map
8957 gnus-callback gnus-mime-security-press-button
8958 gnus-line-format ,gnus-mime-security-button-line-format
8959 gnus-mime-details ,gnus-mime-security-button-pressed
8960 article-type annotation
8961 gnus-data ,handle))
8962 (setq e (if (bolp)
8963 ;; Exclude a newline.
8964 (1- (point))
8965 (point)))
8966 (when gnus-article-button-face
8967 (overlay-put (make-overlay b e nil t)
8968 'face gnus-article-button-face))
8969 (widget-convert-button
8970 'link b e
8971 :mime-handle handle
8972 :action 'gnus-widget-press-button
8973 :button-keymap gnus-mime-security-button-map
8974 :help-echo
8975 (lambda (_widget)
8976 ;; Needed to properly clear the message due to a bug in
8977 ;; wid-edit (XEmacs only).
8978 (when (boundp 'help-echo-owns-message)
8979 (setq help-echo-owns-message t))
8980 (format
8981 "%S: show detail; %S: more options"
8982 (aref gnus-mouse-2 0)
8983 (aref gnus-down-mouse-3 0))))))
8984
8985 (defun gnus-mime-display-security (handle)
8986 (save-restriction
8987 (narrow-to-region (point) (point))
8988 (unless (gnus-unbuttonized-mime-type-p (car handle))
8989 (gnus-insert-mime-security-button handle))
8990 (gnus-mime-display-part (cadr handle))
8991 (unless (bolp)
8992 (insert "\n"))
8993 (unless (gnus-unbuttonized-mime-type-p (car handle))
8994 (let ((gnus-mime-security-button-line-format
8995 gnus-mime-security-button-end-line-format))
8996 (gnus-insert-mime-security-button handle)))
8997 (mm-set-handle-multipart-parameter
8998 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8999 (goto-char (point-max))))
9000
9001 (defun gnus-mime-security-run-function (function)
9002 "Run FUNCTION with the security part under point."
9003 (gnus-article-check-buffer)
9004 (let ((data (get-text-property (point) 'gnus-data))
9005 buffer handle)
9006 (when (and (stringp (car-safe data))
9007 (setq buffer (mm-handle-multipart-original-buffer data))
9008 (setq handle (cadr data)))
9009 (if (bufferp (mm-handle-buffer handle))
9010 (progn
9011 (setq handle (cons buffer (copy-sequence (cdr handle))))
9012 (mm-handle-set-undisplayer handle nil))
9013 (setq handle (mm-make-handle
9014 buffer
9015 (mm-handle-multipart-ctl-parameter handle 'protocol)
9016 nil nil nil nil nil nil)))
9017 (funcall function handle))))
9018
9019 (defun gnus-mime-security-save-part ()
9020 "Save the security part under point."
9021 (interactive)
9022 (gnus-mime-security-run-function 'mm-save-part))
9023
9024 (defun gnus-mime-security-pipe-part ()
9025 "Pipe the security part under point to a process."
9026 (interactive)
9027 (gnus-mime-security-run-function 'mm-pipe-part))
9028
9029 (gnus-ems-redefine)
9030
9031 (provide 'gnus-art)
9032
9033 (run-hooks 'gnus-art-load-hook)
9034
9035 ;;; gnus-art.el ends here