Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-615
[bpt/emacs.git] / lisp / gnus / gnus-art.el
CommitLineData
eec82323 1;;; gnus-art.el --- article mode commands for Gnus
e84b4b86
TTN
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4;; 2005 Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
eec82323
LMI
25
26;;; Commentary:
27
28;;; Code:
29
23f87bed
MB
30(eval-when-compile
31 (require 'cl)
9e36e870
JB
32 (defvar tool-bar-map)
33 (defvar w3m-minor-mode-map))
5ab7173c 34
eec82323
LMI
35(require 'gnus)
36(require 'gnus-sum)
37(require 'gnus-spec)
38(require 'gnus-int)
23f87bed 39(require 'gnus-win)
16409b0b
GM
40(require 'mm-bodies)
41(require 'mail-parse)
42(require 'mm-decode)
43(require 'mm-view)
44(require 'wid-edit)
45(require 'mm-uu)
23f87bed
MB
46(require 'message)
47
48(autoload 'gnus-msg-mail "gnus-msg" nil t)
49(autoload 'gnus-button-mailto "gnus-msg")
50(autoload 'gnus-button-reply "gnus-msg" nil t)
498063ec 51(autoload 'parse-time-string "parse-time" nil nil)
eec82323
LMI
52
53(defgroup gnus-article nil
54 "Article display."
23f87bed 55 :link '(custom-manual "(gnus)Article Buffer")
eec82323
LMI
56 :group 'gnus)
57
16409b0b
GM
58(defgroup gnus-article-treat nil
59 "Treating article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
61 :group 'gnus-article)
62
eec82323
LMI
63(defgroup gnus-article-hiding nil
64 "Hiding article parts."
65 :link '(custom-manual "(gnus)Article Hiding")
66 :group 'gnus-article)
67
68(defgroup gnus-article-highlight nil
69 "Article highlighting."
70 :link '(custom-manual "(gnus)Article Highlighting")
71 :group 'gnus-article
72 :group 'gnus-visual)
73
74(defgroup gnus-article-signature nil
75 "Article signatures."
76 :link '(custom-manual "(gnus)Article Signature")
77 :group 'gnus-article)
78
79(defgroup gnus-article-headers nil
80 "Article headers."
81 :link '(custom-manual "(gnus)Hiding Headers")
82 :group 'gnus-article)
83
84(defgroup gnus-article-washing nil
85 "Special commands on articles."
86 :link '(custom-manual "(gnus)Article Washing")
87 :group 'gnus-article)
88
89(defgroup gnus-article-emphasis nil
90 "Fontisizing articles."
91 :link '(custom-manual "(gnus)Article Fontisizing")
92 :group 'gnus-article)
93
94(defgroup gnus-article-saving nil
95 "Saving articles."
96 :link '(custom-manual "(gnus)Saving Articles")
97 :group 'gnus-article)
98
99(defgroup gnus-article-mime nil
100 "Worshiping the MIME wonder."
101 :link '(custom-manual "(gnus)Using MIME")
102 :group 'gnus-article)
103
104(defgroup gnus-article-buttons nil
105 "Pushable buttons in the article buffer."
106 :link '(custom-manual "(gnus)Article Buttons")
107 :group 'gnus-article)
108
109(defgroup gnus-article-various nil
110 "Other article options."
111 :link '(custom-manual "(gnus)Misc Article")
112 :group 'gnus-article)
113
114(defcustom gnus-ignored-headers
23f87bed
MB
115 (mapcar
116 (lambda (header)
117 (concat "^" header ":"))
118 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
119 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
120 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
121 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
122 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
123 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
124 "X-Attribution" "X-Originating-IP" "Delivered-To"
125 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
126 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
127 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
128 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
129 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
130 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
131 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
132 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
133 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
134 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
135 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
136 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
137 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
138 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
139 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
140 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
141 "List-[A-Za-z]+" "X-Listprocessor-Version"
142 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
143 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
144 "X-Received" "Content-length" "X-precedence"
145 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
146 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
147 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
148 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
149 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
150 "X-Content-length" "X-Posting-Agent" "Original-Received"
151 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
152 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
153 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
154 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
155 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
6748645f 156 "*All headers that start with this regexp will be hidden.
eec82323
LMI
157This variable can also be a list of regexps of headers to be ignored.
158If `gnus-visible-headers' is non-nil, this variable will be ignored."
159 :type '(choice :custom-show nil
160 regexp
161 (repeat regexp))
162 :group 'gnus-article-hiding)
163
164(defcustom gnus-visible-headers
23f87bed 165 "^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:\\|^X-Sent:"
6748645f 166 "*All headers that do not match this regexp will be hidden.
eec82323
LMI
167This variable can also be a list of regexp of headers to remain visible.
168If this variable is non-nil, `gnus-ignored-headers' will be ignored."
169 :type '(repeat :value-to-internal (lambda (widget value)
170 (custom-split-regexp-maybe value))
171 :match (lambda (widget value)
172 (or (stringp value)
173 (widget-editable-list-match widget value)))
174 regexp)
175 :group 'gnus-article-hiding)
176
177(defcustom gnus-sorted-header-list
178 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
179 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
6748645f 180 "*This variable is a list of regular expressions.
eec82323
LMI
181If it is non-nil, headers that match the regular expressions will
182be placed first in the article buffer in the sequence specified by
183this list."
184 :type '(repeat regexp)
185 :group 'gnus-article-hiding)
186
187(defcustom gnus-boring-article-headers '(empty followup-to reply-to)
188 "Headers that are only to be displayed if they have interesting data.
23f87bed
MB
189Possible values in this list are:
190
191 'empty Headers with no content.
192 'newsgroups Newsgroup identical to Gnus group.
193 'to-address To identical to To-address.
194 'to-list To identical to To-list.
195 'cc-list CC identical to To-list.
196 'followup-to Followup-to identical to Newsgroups.
197 'reply-to Reply-to identical to From.
198 'date Date less than four days old.
199 'long-to To and/or Cc longer than 1024 characters.
200 'many-to Multiple To and/or Cc."
eec82323 201 :type '(set (const :tag "Headers with no content." empty)
23f87bed
MB
202 (const :tag "Newsgroups identical to Gnus group." newsgroups)
203 (const :tag "To identical to To-address." to-address)
204 (const :tag "To identical to To-list." to-list)
205 (const :tag "CC identical to To-list." cc-list)
206 (const :tag "Followup-to identical to Newsgroups." followup-to)
207 (const :tag "Reply-to identical to From." reply-to)
6748645f 208 (const :tag "Date less than four days old." date)
23f87bed 209 (const :tag "To and/or Cc longer than 1024 characters." long-to)
16409b0b 210 (const :tag "Multiple To and/or Cc headers." many-to))
eec82323
LMI
211 :group 'gnus-article-hiding)
212
23f87bed
MB
213(defcustom gnus-article-skip-boring nil
214 "Skip over text that is not worth reading.
215By default, if you set this t, then Gnus will display citations and
216signatures, but will never scroll down to show you a page consisting
217only of boring text. Boring text is controlled by
218`gnus-article-boring-faces'."
bf247b6e 219 :version "22.1"
23f87bed
MB
220 :type 'boolean
221 :group 'gnus-article-hiding)
222
eec82323
LMI
223(defcustom gnus-signature-separator '("^-- $" "^-- *$")
224 "Regexp matching signature separator.
225This can also be a list of regexps. In that case, it will be checked
226from head to tail looking for a separator. Searches will be done from
227the end of the buffer."
228 :type '(repeat string)
229 :group 'gnus-article-signature)
230
231(defcustom gnus-signature-limit nil
16409b0b 232 "Provide a limit to what is considered a signature.
eec82323
LMI
233If it is a number, no signature may not be longer (in characters) than
234that number. If it is a floating point number, no signature may be
235longer (in lines) than that number. If it is a function, the function
236will be called without any parameters, and if it returns nil, there is
237no signature in the buffer. If it is a string, it will be used as a
238regexp. If it matches, the text in question is not a signature."
4a2358e9
MB
239 :type '(choice (const nil)
240 (integer :value 200)
6748645f
LMI
241 (number :value 4.0)
242 (function :value fun)
243 (regexp :value ".*"))
eec82323
LMI
244 :group 'gnus-article-signature)
245
246(defcustom gnus-hidden-properties '(invisible t intangible t)
247 "Property list to use for hiding text."
248 :type 'sexp
249 :group 'gnus-article-hiding)
250
23f87bed
MB
251;; Fixme: This isn't the right thing for mixed graphical and non-graphical
252;; frames in a session.
eec82323 253(defcustom gnus-article-x-face-command
23f87bed
MB
254 (if (featurep 'xemacs)
255 (if (or (gnus-image-type-available-p 'xface)
256 (gnus-image-type-available-p 'pbm))
257 'gnus-display-x-face-in-from
258 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
259 (if (gnus-image-type-available-p 'pbm)
260 'gnus-display-x-face-in-from
e0bad764
DL
261 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
262display -"))
6748645f 263 "*String or function to be executed to display an X-Face header.
eec82323
LMI
264If it is a string, the command will be executed in a sub-shell
265asynchronously. The compressed face will be piped to this command."
23f87bed
MB
266 :type `(choice string
267 (function-item gnus-display-x-face-in-from)
16409b0b 268 function)
b5a206e7 269 :version "21.1"
23f87bed 270 :group 'gnus-picon
eec82323
LMI
271 :group 'gnus-article-washing)
272
273(defcustom gnus-article-x-face-too-ugly nil
274 "Regexp matching posters whose face shouldn't be shown automatically."
4bb6a3a6 275 :type '(choice regexp (const nil))
eec82323
LMI
276 :group 'gnus-article-washing)
277
e0bad764
DL
278(defcustom gnus-article-banner-alist nil
279 "Banner alist for stripping.
a1506d29 280For example,
23f87bed 281 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
fc2c2db8 282 :version "21.1"
e0bad764
DL
283 :type '(repeat (cons symbol regexp))
284 :group 'gnus-article-washing)
285
23f87bed
MB
286(gnus-define-group-parameter
287 banner
288 :variable-document
289 "Alist of regexps (to match group names) and banner."
290 :variable-group gnus-article-washing
291 :parameter-type
292 '(choice :tag "Banner"
293 :value nil
294 (const :tag "Remove signature" signature)
295 (symbol :tag "Item in `gnus-article-banner-alist'" none)
296 regexp
297 (const :tag "None" nil))
298 :parameter-document
299 "If non-nil, specify how to remove `banners' from articles.
300
301Symbol `signature' means to remove signatures delimited by
302`gnus-signature-separator'. Any other symbol is used to look up a
303regular expression to match the banner in `gnus-article-banner-alist'.
304A string is used as a regular expression to match the banner
305directly.")
306
307(defcustom gnus-article-address-banner-alist nil
308 "Alist of mail addresses and banners.
309Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
310to match a mail address in the From: header, BANNER is one of a symbol
311`signature', an item in `gnus-article-banner-alist', a regexp and nil.
312If ADDRESS matches author's mail address, it will remove things like
313advertisements. For example:
314
315\((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
316"
317 :type '(repeat
318 (cons
319 (regexp :tag "Address")
320 (choice :tag "Banner" :value nil
321 (const :tag "Remove signature" signature)
322 (symbol :tag "Item in `gnus-article-banner-alist'" none)
323 regexp
324 (const :tag "None" nil))))
bf247b6e 325 :version "22.1"
23f87bed
MB
326 :group 'gnus-article-washing)
327
ae465fa7
MB
328(defmacro gnus-emphasis-custom-with-format (&rest body)
329 `(let ((format "\
330\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
331\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
332 ,@body))
333
334(defun gnus-emphasis-custom-value-to-external (value)
335 (gnus-emphasis-custom-with-format
336 (if (consp (car value))
337 (list (format format (car (car value)) (cdr (car value)))
338 2
339 (if (nth 1 value) 2 3)
340 (nth 2 value))
341 value)))
342
343(defun gnus-emphasis-custom-value-to-internal (value)
344 (gnus-emphasis-custom-with-format
345 (let ((regexp (concat "\\`"
346 (format (regexp-quote format)
347 "\\([^()]+\\)" "\\([^()]+\\)")
348 "\\'"))
349 pattern)
350 (if (string-match regexp (setq pattern (car value)))
351 (list (cons (match-string 1 pattern) (match-string 2 pattern))
352 (= (nth 2 value) 2)
353 (nth 3 value))
354 value))))
355
eec82323 356(defcustom gnus-emphasis-alist
ae465fa7
MB
357 (let ((types
358 '(("\\*" "\\*" bold nil 2)
23f87bed 359 ("_" "_" underline)
eec82323 360 ("/" "/" italic)
eec82323
LMI
361 ("_/" "/_" underline-italic)
362 ("_\\*" "\\*_" underline-bold)
363 ("\\*/" "/\\*" bold-italic)
364 ("_\\*/" "/\\*_" underline-bold-italic))))
ae465fa7
MB
365 (nconc
366 (gnus-emphasis-custom-with-format
367 (mapcar (lambda (spec)
368 (list (format format (car spec) (cadr spec))
369 (or (nth 3 spec) 2)
370 (or (nth 4 spec) 3)
371 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
372 types))
95f75c75
SM
373 '(;; I've never seen anyone use this strikethru convention whereas I've
374 ;; several times seen it triggered by normal text. --Stef
375 ;; Miles suggests that this form is sometimes used but for italics,
376 ;; so maybe we should map it to `italic'.
377 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
378 ;; 2 3 gnus-emphasis-strikethru)
ae465fa7
MB
379 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
380 2 3 gnus-emphasis-underline))))
6748645f 381 "*Alist that says how to fontify certain phrases.
eec82323
LMI
382Each item looks like this:
383
384 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
385
386The first element is a regular expression to be matched. The second
387is a number that says what regular expression grouping used to find
388the entire emphasized word. The third is a number that says what
389regexp grouping should be displayed and highlighted. The fourth
390is the face used for highlighting."
ae465fa7
MB
391 :type
392 '(repeat
393 (menu-choice
394 :format "%[Customizing Style%]\n%v"
395 :indent 2
396 (group :tag "Default"
397 :value ("" 0 0 default)
398 :value-create
399 (lambda (widget)
400 (let ((value (widget-get
401 (cadr (widget-get (widget-get widget :parent)
402 :args))
403 :value)))
404 (if (not (eq (nth 2 value) 'default))
405 (widget-put
406 widget
407 :value
408 (gnus-emphasis-custom-value-to-external value))))
409 (widget-group-value-create widget))
ad136a7c
MB
410 regexp
411 (integer :format "Match group: %v")
412 (integer :format "Emphasize group: %v")
ae465fa7
MB
413 face)
414 (group :tag "Simple"
415 :value (("_" . "_") nil default)
416 (cons :format "%v"
ad136a7c
MB
417 (regexp :format "Start regexp: %v")
418 (regexp :format "End regexp: %v"))
ae465fa7
MB
419 (boolean :format "Show start and end patterns: %[%v%]\n"
420 :on " On " :off " Off ")
421 face)))
422 :get (lambda (symbol)
423 (mapcar 'gnus-emphasis-custom-value-to-internal
424 (default-value symbol)))
425 :set (lambda (symbol value)
426 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
427 value)))
eec82323
LMI
428 :group 'gnus-article-emphasis)
429
16409b0b
GM
430(defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
431 "A regexp to describe whitespace which should not be emphasized.
432Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
433The former avoids underlining of leading and trailing whitespace,
434and the latter avoids underlining any whitespace at all."
fc2c2db8 435 :version "21.1"
16409b0b
GM
436 :group 'gnus-article-emphasis
437 :type 'regexp)
438
23f87bed 439(defface gnus-emphasis-bold '((t (:bold t)))
eec82323
LMI
440 "Face used for displaying strong emphasized text (*word*)."
441 :group 'gnus-article-emphasis)
442
23f87bed 443(defface gnus-emphasis-italic '((t (:italic t)))
eec82323
LMI
444 "Face used for displaying italic emphasized text (/word/)."
445 :group 'gnus-article-emphasis)
446
447(defface gnus-emphasis-underline '((t (:underline t)))
448 "Face used for displaying underlined emphasized text (_word_)."
449 :group 'gnus-article-emphasis)
450
23f87bed 451(defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
eec82323
LMI
452 "Face used for displaying underlined bold emphasized text (_*word*_)."
453 :group 'gnus-article-emphasis)
454
23f87bed 455(defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
8de38c21 456 "Face used for displaying underlined italic emphasized text (_/word/_)."
eec82323
LMI
457 :group 'gnus-article-emphasis)
458
23f87bed 459(defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
eec82323
LMI
460 "Face used for displaying bold italic emphasized text (/*word*/)."
461 :group 'gnus-article-emphasis)
462
463(defface gnus-emphasis-underline-bold-italic
23f87bed 464 '((t (:bold t :italic t :underline t)))
eec82323 465 "Face used for displaying underlined bold italic emphasized text.
8f688cb0 466Example: (_/*word*/_)."
eec82323
LMI
467 :group 'gnus-article-emphasis)
468
23f87bed
MB
469(defface gnus-emphasis-strikethru (if (featurep 'xemacs)
470 '((t (:strikethru t)))
471 '((t (:strike-through t))))
472 "Face used for displaying strike-through text (-word-)."
473 :group 'gnus-article-emphasis)
474
16409b0b
GM
475(defface gnus-emphasis-highlight-words
476 '((t (:background "black" :foreground "yellow")))
477 "Face used for displaying highlighted words."
478 :group 'gnus-article-emphasis)
479
eec82323
LMI
480(defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
481 "Format for display of Date headers in article bodies.
6748645f
LMI
482See `format-time-string' for the possible values.
483
484The variable can also be function, which should return a complete Date
485header. The function is called with one argument, the time, which can
486be fed to `format-time-string'."
487 :type '(choice string symbol)
eec82323
LMI
488 :link '(custom-manual "(gnus)Article Date")
489 :group 'gnus-article-washing)
490
eec82323
LMI
491(defcustom gnus-save-all-headers t
492 "*If non-nil, don't remove any headers before saving."
493 :group 'gnus-article-saving
494 :type 'boolean)
495
496(defcustom gnus-prompt-before-saving 'always
497 "*This variable says how much prompting is to be done when saving articles.
498If it is nil, no prompting will be done, and the articles will be
499saved to the default files. If this variable is `always', each and
500every article that is saved will be preceded by a prompt, even when
501saving large batches of articles. If this variable is neither nil not
502`always', there the user will be prompted once for a file name for
503each invocation of the saving commands."
504 :group 'gnus-article-saving
505 :type '(choice (item always)
506 (item :tag "never" nil)
6748645f 507 (sexp :tag "once" :format "%t\n" :value t)))
eec82323
LMI
508
509(defcustom gnus-saved-headers gnus-visible-headers
510 "Headers to keep if `gnus-save-all-headers' is nil.
511If `gnus-save-all-headers' is non-nil, this variable will be ignored.
512If that variable is nil, however, all headers that match this regexp
513will be kept while the rest will be deleted before saving."
514 :group 'gnus-article-saving
4bb6a3a6 515 :type 'regexp)
eec82323
LMI
516
517(defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
518 "A function to save articles in your favourite format.
519The function must be interactively callable (in other words, it must
520be an Emacs command).
521
522Gnus provides the following functions:
523
524* gnus-summary-save-in-rmail (Rmail format)
525* gnus-summary-save-in-mail (Unix mail format)
526* gnus-summary-save-in-folder (MH folder)
527* gnus-summary-save-in-file (article format)
23f87bed 528* gnus-summary-save-body-in-file (article body)
eec82323
LMI
529* gnus-summary-save-in-vm (use VM's folder format)
530* gnus-summary-write-to-file (article format -- overwrite)."
531 :group 'gnus-article-saving
532 :type '(radio (function-item gnus-summary-save-in-rmail)
533 (function-item gnus-summary-save-in-mail)
534 (function-item gnus-summary-save-in-folder)
535 (function-item gnus-summary-save-in-file)
23f87bed 536 (function-item gnus-summary-save-body-in-file)
eec82323
LMI
537 (function-item gnus-summary-save-in-vm)
538 (function-item gnus-summary-write-to-file)))
539
540(defcustom gnus-rmail-save-name 'gnus-plain-save-name
541 "A function generating a file name to save articles in Rmail format.
542The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
543 :group 'gnus-article-saving
544 :type 'function)
545
546(defcustom gnus-mail-save-name 'gnus-plain-save-name
547 "A function generating a file name to save articles in Unix mail format.
548The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
549 :group 'gnus-article-saving
550 :type 'function)
551
552(defcustom gnus-folder-save-name 'gnus-folder-save-name
553 "A function generating a file name to save articles in MH folder.
554The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
555 :group 'gnus-article-saving
556 :type 'function)
557
558(defcustom gnus-file-save-name 'gnus-numeric-save-name
559 "A function generating a file name to save articles in article format.
560The function is called with NEWSGROUP, HEADERS, and optional
561LAST-FILE."
562 :group 'gnus-article-saving
563 :type 'function)
564
565(defcustom gnus-split-methods
566 '((gnus-article-archive-name)
567 (gnus-article-nndoc-name))
6748645f 568 "*Variable used to suggest where articles are to be saved.
eec82323
LMI
569For instance, if you would like to save articles related to Gnus in
570the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
571you could set this variable to something like:
572
573 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
574 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
575
576This variable is an alist where the where the key is the match and the
577value is a list of possible files to save in if the match is non-nil.
578
579If the match is a string, it is used as a regexp match on the
580article. If the match is a symbol, that symbol will be funcalled
581from the buffer of the article to be saved with the newsgroup as the
582parameter. If it is a list, it will be evaled in the same buffer.
583
584If this form or function returns a string, this string will be used as
585a possible file name; and if it returns a non-nil list, that list will
586be used as possible file names."
587 :group 'gnus-article-saving
6748645f
LMI
588 :type '(repeat (choice (list :value (fun) function)
589 (cons :value ("" "") regexp (repeat string))
590 (sexp :value nil))))
eec82323 591
eec82323
LMI
592(defcustom gnus-page-delimiter "^\^L"
593 "*Regexp describing what to use as article page delimiters.
594The default value is \"^\^L\", which is a form linefeed at the
595beginning of a line."
596 :type 'regexp
597 :group 'gnus-article-various)
598
16409b0b 599(defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
eec82323 600 "*The format specification for the article mode line.
16409b0b
GM
601See `gnus-summary-mode-line-format' for a closer description.
602
603The following additional specs are available:
604
605%w The article washing status.
606%m The number of MIME parts in the article."
eec82323
LMI
607 :type 'string
608 :group 'gnus-article-various)
609
610(defcustom gnus-article-mode-hook nil
611 "*A hook for Gnus article mode."
612 :type 'hook
613 :group 'gnus-article-various)
614
23f87bed
MB
615(when (featurep 'xemacs)
616 ;; Extracted from gnus-xmas-define in order to preserve user settings
617 (when (fboundp 'turn-off-scroll-in-place)
618 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
619 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
620 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
621
eec82323
LMI
622(defcustom gnus-article-menu-hook nil
623 "*Hook run after the creation of the article mode menu."
624 :type 'hook
625 :group 'gnus-article-various)
626
627(defcustom gnus-article-prepare-hook nil
16409b0b 628 "*A hook called after an article has been prepared in the article buffer."
eec82323
LMI
629 :type 'hook
630 :group 'gnus-article-various)
631
23f87bed
MB
632(make-obsolete-variable 'gnus-article-hide-pgp-hook
633 "This variable is obsolete in Gnus 5.10.")
a8151ef7 634
eec82323
LMI
635(defcustom gnus-article-button-face 'bold
636 "Face used for highlighting buttons in the article buffer.
637
638An article button is a piece of text that you can activate by pressing
639`RET' or `mouse-2' above it."
640 :type 'face
641 :group 'gnus-article-buttons)
642
643(defcustom gnus-article-mouse-face 'highlight
644 "Face used for mouse highlighting in the article buffer.
645
646Article buttons will be displayed in this face when the cursor is
647above them."
648 :type 'face
649 :group 'gnus-article-buttons)
650
0f49874b 651(defcustom gnus-signature-face 'gnus-signature
a8151ef7 652 "Face used for highlighting a signature in the article buffer.
0f49874b 653Obsolete; use the face `gnus-signature' for customizations instead."
eec82323
LMI
654 :type 'face
655 :group 'gnus-article-highlight
656 :group 'gnus-article-signature)
657
0f49874b 658(defface gnus-signature
f59a3415 659 '((t
23f87bed 660 (:italic t)))
a8151ef7
LMI
661 "Face used for highlighting a signature in the article buffer."
662 :group 'gnus-article-highlight
663 :group 'gnus-article-signature)
0f49874b
MB
664;; backward-compatibility alias
665(put 'gnus-signature-face 'face-alias 'gnus-signature)
a8151ef7 666
0f49874b 667(defface gnus-header-from
eec82323
LMI
668 '((((class color)
669 (background dark))
6748645f 670 (:foreground "spring green"))
eec82323
LMI
671 (((class color)
672 (background light))
6748645f 673 (:foreground "red3"))
eec82323 674 (t
23f87bed 675 (:italic t)))
eec82323
LMI
676 "Face used for displaying from headers."
677 :group 'gnus-article-headers
678 :group 'gnus-article-highlight)
0f49874b
MB
679;; backward-compatibility alias
680(put 'gnus-header-from-face 'face-alias 'gnus-header-from)
eec82323 681
0f49874b 682(defface gnus-header-subject
eec82323
LMI
683 '((((class color)
684 (background dark))
6748645f 685 (:foreground "SeaGreen3"))
eec82323
LMI
686 (((class color)
687 (background light))
6748645f 688 (:foreground "red4"))
eec82323 689 (t
23f87bed 690 (:bold t :italic t)))
eec82323
LMI
691 "Face used for displaying subject headers."
692 :group 'gnus-article-headers
693 :group 'gnus-article-highlight)
0f49874b
MB
694;; backward-compatibility alias
695(put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
eec82323 696
0f49874b 697(defface gnus-header-newsgroups
eec82323
LMI
698 '((((class color)
699 (background dark))
23f87bed 700 (:foreground "yellow" :italic t))
eec82323
LMI
701 (((class color)
702 (background light))
23f87bed 703 (:foreground "MidnightBlue" :italic t))
eec82323 704 (t
23f87bed
MB
705 (:italic t)))
706 "Face used for displaying newsgroups headers.
707In the default setup this face is only used for crossposted
708articles."
eec82323
LMI
709 :group 'gnus-article-headers
710 :group 'gnus-article-highlight)
0f49874b
MB
711;; backward-compatibility alias
712(put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
eec82323 713
0f49874b 714(defface gnus-header-name
eec82323
LMI
715 '((((class color)
716 (background dark))
717 (:foreground "SeaGreen"))
718 (((class color)
719 (background light))
720 (:foreground "maroon"))
721 (t
23f87bed 722 (:bold t)))
eec82323
LMI
723 "Face used for displaying header names."
724 :group 'gnus-article-headers
725 :group 'gnus-article-highlight)
0f49874b
MB
726;; backward-compatibility alias
727(put 'gnus-header-name-face 'face-alias 'gnus-header-name)
eec82323 728
0f49874b 729(defface gnus-header-content
eec82323
LMI
730 '((((class color)
731 (background dark))
23f87bed 732 (:foreground "forest green" :italic t))
eec82323
LMI
733 (((class color)
734 (background light))
23f87bed 735 (:foreground "indianred4" :italic t))
eec82323 736 (t
23f87bed 737 (:italic t))) "Face used for displaying header content."
eec82323
LMI
738 :group 'gnus-article-headers
739 :group 'gnus-article-highlight)
0f49874b
MB
740;; backward-compatibility alias
741(put 'gnus-header-content-face 'face-alias 'gnus-header-content)
eec82323
LMI
742
743(defcustom gnus-header-face-alist
0f49874b
MB
744 '(("From" nil gnus-header-from)
745 ("Subject" nil gnus-header-subject)
746 ("Newsgroups:.*," nil gnus-header-newsgroups)
747 ("" gnus-header-name gnus-header-content))
23f87bed 748 "*Controls highlighting of article headers.
eec82323
LMI
749
750An alist of the form (HEADER NAME CONTENT).
751
23f87bed
MB
752HEADER is a regular expression which should match the name of a
753header and NAME and CONTENT are either face names or nil.
eec82323
LMI
754
755The name of each header field will be displayed using the face
23f87bed
MB
756specified by the first element in the list where HEADER matches
757the header name and NAME is non-nil. Similarly, the content will
758be displayed by the first non-nil matching CONTENT face."
eec82323
LMI
759 :group 'gnus-article-headers
760 :group 'gnus-article-highlight
761 :type '(repeat (list (regexp :tag "Header")
762 (choice :tag "Name"
763 (item :tag "skip" nil)
764 (face :value default))
765 (choice :tag "Content"
766 (item :tag "skip" nil)
767 (face :value default)))))
768
16409b0b 769(defcustom gnus-article-decode-hook
23f87bed
MB
770 '(article-decode-charset article-decode-encoded-words
771 article-decode-group-name article-decode-idna-rhs)
16409b0b
GM
772 "*Hook run to decode charsets in articles."
773 :group 'gnus-article-headers
774 :type 'hook)
775
776(defcustom gnus-display-mime-function 'gnus-display-mime
777 "Function to display MIME articles."
778 :group 'gnus-article-mime
779 :type 'function)
780
781(defvar gnus-decode-header-function 'mail-decode-encoded-word-region
782 "Function used to decode headers.")
783
784(defvar gnus-article-dumbquotes-map
23f87bed
MB
785 '(("\200" "EUR")
786 ("\202" ",")
16409b0b
GM
787 ("\203" "f")
788 ("\204" ",,")
789 ("\205" "...")
790 ("\213" "<")
791 ("\214" "OE")
792 ("\221" "`")
793 ("\222" "'")
794 ("\223" "``")
795 ("\224" "\"")
796 ("\225" "*")
e0bad764
DL
797 ("\226" "-")
798 ("\227" "--")
23f87bed 799 ("\230" "~")
16409b0b
GM
800 ("\231" "(TM)")
801 ("\233" ">")
802 ("\234" "oe")
803 ("\264" "'"))
804 "Table for MS-to-Latin1 translation.")
805
806(defcustom gnus-ignored-mime-types nil
807 "List of MIME types that should be ignored by Gnus."
fc2c2db8 808 :version "21.1"
16409b0b
GM
809 :group 'gnus-article-mime
810 :type '(repeat regexp))
811
812(defcustom gnus-unbuttonized-mime-types '(".*/.*")
23f87bed
MB
813 "List of MIME types that should not be given buttons when rendered inline.
814See also `gnus-buttonized-mime-types' which may override this variable.
815This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
816 :version "21.1"
817 :group 'gnus-article-mime
818 :type '(repeat regexp))
819
820(defcustom gnus-buttonized-mime-types nil
821 "List of MIME types that should be given buttons when rendered inline.
822If set, this variable overrides `gnus-unbuttonized-mime-types'.
823To see e.g. security buttons you could set this to
824`(\"multipart/signed\")'.
825This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
bf247b6e 826 :version "22.1"
16409b0b
GM
827 :group 'gnus-article-mime
828 :type '(repeat regexp))
829
23f87bed
MB
830(defcustom gnus-inhibit-mime-unbuttonizing nil
831 "If non-nil, all MIME parts get buttons.
832When nil (the default value), then some MIME parts do not get buttons,
833as described by the variables `gnus-buttonized-mime-types' and
834`gnus-unbuttonized-mime-types'."
bf247b6e 835 :version "22.1"
d0859c9a 836 :group 'gnus-article-mime
23f87bed
MB
837 :type 'boolean)
838
839(defcustom gnus-body-boundary-delimiter "_"
840 "String used to delimit header and body.
841This variable is used by `gnus-article-treat-body-boundary' which can
842be controlled by `gnus-treat-body-boundary'."
bf247b6e 843 :version "22.1"
23f87bed
MB
844 :group 'gnus-article-various
845 :type '(choice (item :tag "None" :value nil)
846 string))
847
97f78c9b
MB
848(defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
849 "/usr/share/picons")
23f87bed
MB
850 "Defines the location of the faces database.
851For information on obtaining this database of pretty pictures, please
852see http://www.cs.indiana.edu/picons/ftp/index.html"
bf247b6e 853 :version "22.1"
23f87bed
MB
854 :type '(repeat directory)
855 :link '(url-link :tag "download"
856 "http://www.cs.indiana.edu/picons/ftp/index.html")
857 :link '(custom-manual "(gnus)Picons")
858 :group 'gnus-picon)
859
860(defun gnus-picons-installed-p ()
861 "Say whether picons are installed on your machine."
862 (let ((installed nil))
863 (dolist (database gnus-picon-databases)
864 (when (file-exists-p database)
865 (setq installed t)))
866 installed))
867
16409b0b
GM
868(defcustom gnus-article-mime-part-function nil
869 "Function called with a MIME handle as the argument.
870This is meant for people who want to do something automatic based
871on parts -- for instance, adding Vcard info to a database."
872 :group 'gnus-article-mime
4a2358e9
MB
873 :type '(choice (const nil)
874 function))
16409b0b
GM
875
876(defcustom gnus-mime-multipart-functions nil
fc2c2db8
DL
877 "An alist of MIME types to functions to display them."
878 :version "21.1"
879 :group 'gnus-article-mime
880 :type 'alist)
16409b0b
GM
881
882(defcustom gnus-article-date-lapsed-new-header nil
883 "Whether the X-Sent and Date headers can coexist.
884When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
885either replace the old \"Date:\" header (if this variable is nil), or
886be added below it (otherwise)."
fc2c2db8 887 :version "21.1"
16409b0b
GM
888 :group 'gnus-article-headers
889 :type 'boolean)
890
891(defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
892 "Function called with a MIME handle as the argument.
893This is meant for people who want to view first matched part.
a1506d29
JB
894For `undisplayed-alternative' (default), the first undisplayed
895part or alternative part is used. For `undisplayed', the first
896undisplayed part is used. For a function, the first part which
f20b2f5c 897the function return t is used. For nil, the first part is
16409b0b 898used."
fc2c2db8 899 :version "21.1"
16409b0b 900 :group 'gnus-article-mime
a1506d29 901 :type '(choice
16409b0b
GM
902 (item :tag "first" :value nil)
903 (item :tag "undisplayed" :value undisplayed)
a1506d29 904 (item :tag "undisplayed or alternative"
16409b0b
GM
905 :value undisplayed-alternative)
906 (function)))
907
e0bad764
DL
908(defcustom gnus-mime-action-alist
909 '(("save to file" . gnus-mime-save-part)
23f87bed
MB
910 ("save and strip" . gnus-mime-save-part-and-strip)
911 ("delete part" . gnus-mime-delete-part)
e0bad764
DL
912 ("display as text" . gnus-mime-inline-part)
913 ("view the part" . gnus-mime-view-part)
914 ("pipe to command" . gnus-mime-pipe-part)
915 ("toggle display" . gnus-article-press-button)
23f87bed 916 ("toggle display" . gnus-article-view-part-as-charset)
e0bad764 917 ("view as type" . gnus-mime-view-part-as-type)
23f87bed
MB
918 ("view internally" . gnus-mime-view-part-internally)
919 ("view externally" . gnus-mime-view-part-externally))
e0bad764
DL
920 "An alist of actions that run on the MIME attachment."
921 :group 'gnus-article-mime
922 :type '(repeat (cons (string :tag "name")
923 (function))))
924
16409b0b
GM
925;;;
926;;; The treatment variables
927;;;
928
929(defvar gnus-part-display-hook nil
930 "Hook called on parts that are to receive treatment.")
931
932(defvar gnus-article-treat-custom
933 '(choice (const :tag "Off" nil)
934 (const :tag "On" t)
935 (const :tag "Header" head)
936 (const :tag "Last" last)
937 (integer :tag "Less")
938 (repeat :tag "Groups" regexp)
939 (sexp :tag "Predicate")))
940
941(defvar gnus-article-treat-head-custom
942 '(choice (const :tag "Off" nil)
943 (const :tag "Header" head)))
944
945(defvar gnus-article-treat-types '("text/plain")
946 "Parts to treat.")
947
948(defvar gnus-inhibit-treatment nil
949 "Whether to inhibit treatment.")
950
23f87bed 951(defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
16409b0b
GM
952 "Highlight the signature.
953Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 954See Info node `(gnus)Customizing Articles'."
16409b0b 955 :group 'gnus-article-treat
23f87bed 956 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
957 :type gnus-article-treat-custom)
958(put 'gnus-treat-highlight-signature 'highlight t)
959
960(defcustom gnus-treat-buttonize 100000
961 "Add buttons.
962Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 963See Info node `(gnus)Customizing Articles'."
16409b0b 964 :group 'gnus-article-treat
23f87bed 965 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
966 :type gnus-article-treat-custom)
967(put 'gnus-treat-buttonize 'highlight t)
968
969(defcustom gnus-treat-buttonize-head 'head
970 "Add buttons to the head.
971Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 972See Info node `(gnus)Customizing Articles' for details."
16409b0b 973 :group 'gnus-article-treat
23f87bed 974 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
975 :type gnus-article-treat-head-custom)
976(put 'gnus-treat-buttonize-head 'highlight t)
977
a1506d29 978(defcustom gnus-treat-emphasize
74dd1b0d
SZ
979 (and (or window-system
980 (featurep 'xemacs)
981 (>= (string-to-number emacs-version) 21))
982 50000)
16409b0b
GM
983 "Emphasize text.
984Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 985See Info node `(gnus)Customizing Articles' for details."
16409b0b 986 :group 'gnus-article-treat
23f87bed 987 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
988 :type gnus-article-treat-custom)
989(put 'gnus-treat-emphasize 'highlight t)
990
991(defcustom gnus-treat-strip-cr nil
992 "Remove carriage returns.
993Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 994See Info node `(gnus)Customizing Articles' for details."
bf247b6e 995 :version "22.1"
16409b0b 996 :group 'gnus-article-treat
23f87bed
MB
997 :link '(custom-manual "(gnus)Customizing Articles")
998 :type gnus-article-treat-custom)
999
1000(defcustom gnus-treat-unsplit-urls nil
1001 "Remove newlines from within URLs.
1002Valid values are nil, t, `head', `last', an integer or a predicate.
1003See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1004 :version "22.1"
23f87bed
MB
1005 :group 'gnus-article-treat
1006 :link '(custom-manual "(gnus)Customizing Articles")
1007 :type gnus-article-treat-custom)
1008
1009(defcustom gnus-treat-leading-whitespace nil
1010 "Remove leading whitespace in headers.
1011Valid values are nil, t, `head', `last', an integer or a predicate.
1012See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1013 :version "22.1"
23f87bed
MB
1014 :group 'gnus-article-treat
1015 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1016 :type gnus-article-treat-custom)
1017
1018(defcustom gnus-treat-hide-headers 'head
1019 "Hide headers.
1020Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1021See Info node `(gnus)Customizing Articles' for details."
16409b0b 1022 :group 'gnus-article-treat
23f87bed 1023 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1024 :type gnus-article-treat-head-custom)
1025
1026(defcustom gnus-treat-hide-boring-headers nil
1027 "Hide boring headers.
1028Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1029See Info node `(gnus)Customizing Articles' for details."
16409b0b 1030 :group 'gnus-article-treat
23f87bed 1031 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1032 :type gnus-article-treat-head-custom)
1033
1034(defcustom gnus-treat-hide-signature nil
1035 "Hide the signature.
1036Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1037See Info node `(gnus)Customizing Articles' for details."
16409b0b 1038 :group 'gnus-article-treat
23f87bed 1039 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1040 :type gnus-article-treat-custom)
1041
1042(defcustom gnus-treat-fill-article nil
1043 "Fill the article.
1044Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1045See Info node `(gnus)Customizing Articles' for details."
16409b0b 1046 :group 'gnus-article-treat
23f87bed 1047 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1048 :type gnus-article-treat-custom)
1049
1050(defcustom gnus-treat-hide-citation nil
1051 "Hide cited text.
1052Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1053See Info node `(gnus)Customizing Articles' for details."
16409b0b 1054 :group 'gnus-article-treat
23f87bed 1055 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1056 :type gnus-article-treat-custom)
1057
e0bad764
DL
1058(defcustom gnus-treat-hide-citation-maybe nil
1059 "Hide cited text.
1060Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1061See Info node `(gnus)Customizing Articles' for details."
e0bad764 1062 :group 'gnus-article-treat
23f87bed 1063 :link '(custom-manual "(gnus)Customizing Articles")
e0bad764
DL
1064 :type gnus-article-treat-custom)
1065
16409b0b
GM
1066(defcustom gnus-treat-strip-list-identifiers 'head
1067 "Strip list identifiers from `gnus-list-identifiers`.
1068Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1069See Info node `(gnus)Customizing Articles' for details."
fc2c2db8 1070 :version "21.1"
16409b0b 1071 :group 'gnus-article-treat
23f87bed 1072 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1073 :type gnus-article-treat-custom)
1074
23f87bed
MB
1075(make-obsolete-variable 'gnus-treat-strip-pgp
1076 "This option is obsolete in Gnus 5.10.")
16409b0b
GM
1077
1078(defcustom gnus-treat-strip-pem nil
1079 "Strip PEM signatures.
1080Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1081See Info node `(gnus)Customizing Articles' for details."
16409b0b 1082 :group 'gnus-article-treat
23f87bed 1083 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1084 :type gnus-article-treat-custom)
1085
1086(defcustom gnus-treat-strip-banner t
1087 "Strip banners from articles.
1088The banner to be stripped is specified in the `banner' group parameter.
1089Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1090See Info node `(gnus)Customizing Articles' for details."
16409b0b 1091 :group 'gnus-article-treat
23f87bed 1092 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1093 :type gnus-article-treat-custom)
1094
1095(defcustom gnus-treat-highlight-headers 'head
1096 "Highlight the headers.
1097Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1098See Info node `(gnus)Customizing Articles' for details."
16409b0b 1099 :group 'gnus-article-treat
23f87bed 1100 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1101 :type gnus-article-treat-head-custom)
1102(put 'gnus-treat-highlight-headers 'highlight t)
1103
1104(defcustom gnus-treat-highlight-citation t
1105 "Highlight cited text.
1106Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1107See Info node `(gnus)Customizing Articles' for details."
16409b0b 1108 :group 'gnus-article-treat
23f87bed 1109 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1110 :type gnus-article-treat-custom)
1111(put 'gnus-treat-highlight-citation 'highlight t)
1112
1113(defcustom gnus-treat-date-ut nil
1114 "Display the Date in UT (GMT).
1115Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1116See Info node `(gnus)Customizing Articles' for details."
16409b0b 1117 :group 'gnus-article-treat
23f87bed 1118 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1119 :type gnus-article-treat-head-custom)
1120
1121(defcustom gnus-treat-date-local nil
1122 "Display the Date in the local timezone.
1123Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed
MB
1124See Info node `(gnus)Customizing Articles' for details."
1125 :group 'gnus-article-treat
1126 :link '(custom-manual "(gnus)Customizing Articles")
1127 :type gnus-article-treat-head-custom)
1128
1129(defcustom gnus-treat-date-english nil
1130 "Display the Date in a format that can be read aloud in English.
1131Valid values are nil, t, `head', `last', an integer or a predicate.
1132See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1133 :version "22.1"
16409b0b 1134 :group 'gnus-article-treat
23f87bed 1135 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1136 :type gnus-article-treat-head-custom)
1137
1138(defcustom gnus-treat-date-lapsed nil
1139 "Display the Date header in a way that says how much time has elapsed.
1140Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1141See Info node `(gnus)Customizing Articles' for details."
16409b0b 1142 :group 'gnus-article-treat
23f87bed 1143 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1144 :type gnus-article-treat-head-custom)
1145
1146(defcustom gnus-treat-date-original nil
1147 "Display the date in the original timezone.
1148Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1149See Info node `(gnus)Customizing Articles' for details."
16409b0b 1150 :group 'gnus-article-treat
23f87bed 1151 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1152 :type gnus-article-treat-head-custom)
1153
1154(defcustom gnus-treat-date-iso8601 nil
1155 "Display the date in the ISO8601 format.
1156Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1157See Info node `(gnus)Customizing Articles' for details."
fc2c2db8 1158 :version "21.1"
16409b0b 1159 :group 'gnus-article-treat
23f87bed 1160 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1161 :type gnus-article-treat-head-custom)
1162
1163(defcustom gnus-treat-date-user-defined nil
1164 "Display the date in a user-defined format.
1165The format is defined by the `gnus-article-time-format' variable.
1166Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1167See Info node `(gnus)Customizing Articles' for details."
16409b0b 1168 :group 'gnus-article-treat
23f87bed 1169 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1170 :type gnus-article-treat-head-custom)
1171
1172(defcustom gnus-treat-strip-headers-in-body t
1173 "Strip the X-No-Archive header line from the beginning of the body.
1174Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1175See Info node `(gnus)Customizing Articles' for details."
fc2c2db8 1176 :version "21.1"
16409b0b 1177 :group 'gnus-article-treat
23f87bed 1178 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1179 :type gnus-article-treat-custom)
1180
1181(defcustom gnus-treat-strip-trailing-blank-lines nil
1182 "Strip trailing blank lines.
1183Valid values are nil, t, `head', `last', an integer or a predicate.
292f71fe
MB
1184See Info node `(gnus)Customizing Articles' for details.
1185
1186When set to t, it also strips trailing blanks in all MIME parts.
1187Consider to use `last' instead."
16409b0b 1188 :group 'gnus-article-treat
23f87bed 1189 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1190 :type gnus-article-treat-custom)
1191
1192(defcustom gnus-treat-strip-leading-blank-lines nil
1193 "Strip leading blank lines.
1194Valid values are nil, t, `head', `last', an integer or a predicate.
292f71fe
MB
1195See Info node `(gnus)Customizing Articles' for details.
1196
1197When set to t, it also strips trailing blanks in all MIME parts."
16409b0b 1198 :group 'gnus-article-treat
23f87bed 1199 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1200 :type gnus-article-treat-custom)
1201
1202(defcustom gnus-treat-strip-multiple-blank-lines nil
1203 "Strip multiple blank lines.
1204Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1205See Info node `(gnus)Customizing Articles' for details."
16409b0b 1206 :group 'gnus-article-treat
23f87bed
MB
1207 :link '(custom-manual "(gnus)Customizing Articles")
1208 :type gnus-article-treat-custom)
1209
1210(defcustom gnus-treat-unfold-headers 'head
1211 "Unfold folded header lines.
1212Valid values are nil, t, `head', `last', an integer or a predicate.
1213See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1214 :version "22.1"
23f87bed
MB
1215 :group 'gnus-article-treat
1216 :link '(custom-manual "(gnus)Customizing Articles")
1217 :type gnus-article-treat-custom)
1218
1219(defcustom gnus-treat-fold-headers nil
1220 "Fold headers.
1221Valid values are nil, t, `head', `last', an integer or a predicate.
1222See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1223 :version "22.1"
23f87bed
MB
1224 :group 'gnus-article-treat
1225 :link '(custom-manual "(gnus)Customizing Articles")
1226 :type gnus-article-treat-custom)
1227
1228(defcustom gnus-treat-fold-newsgroups 'head
1229 "Fold the Newsgroups and Followup-To headers.
1230Valid values are nil, t, `head', `last', an integer or a predicate.
1231See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1232 :version "22.1"
23f87bed
MB
1233 :group 'gnus-article-treat
1234 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1235 :type gnus-article-treat-custom)
1236
1237(defcustom gnus-treat-overstrike t
1238 "Treat overstrike highlighting.
1239Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1240See Info node `(gnus)Customizing Articles' for details."
16409b0b 1241 :group 'gnus-article-treat
23f87bed 1242 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1243 :type gnus-article-treat-custom)
1244(put 'gnus-treat-overstrike 'highlight t)
1245
23f87bed
MB
1246(make-obsolete-variable 'gnus-treat-display-xface
1247 'gnus-treat-display-x-face)
1248
1249(defcustom gnus-treat-display-x-face
1250 (and (not noninteractive)
1251 (or (and (fboundp 'image-type-available-p)
e0bad764 1252 (image-type-available-p 'xbm)
23f87bed
MB
1253 (string-match "^0x" (shell-command-to-string "uncompface"))
1254 (executable-find "icontopbm"))
1255 (and (featurep 'xemacs)
1256 (featurep 'xface)))
8b93df01 1257 'head)
16409b0b
GM
1258 "Display X-Face headers.
1259Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed
MB
1260See Info node `(gnus)Customizing Articles' and Info node
1261`(gnus)X-Face' for details."
1262 :group 'gnus-article-treat
1263 :version "21.1"
1264 :link '(custom-manual "(gnus)Customizing Articles")
1265 :link '(custom-manual "(gnus)X-Face")
1266 :type gnus-article-treat-head-custom
1267 :set (lambda (symbol value)
1268 (set-default
1269 symbol
1270 (cond ((or (boundp symbol) (get symbol 'saved-value))
1271 value)
1272 ((boundp 'gnus-treat-display-xface)
1273 (message "\
1274** gnus-treat-display-xface is an obsolete variable;\
1275 use gnus-treat-display-x-face instead")
1276 (default-value 'gnus-treat-display-xface))
1277 ((get 'gnus-treat-display-xface 'saved-value)
1278 (message "\
1279** gnus-treat-display-xface is an obsolete variable;\
1280 use gnus-treat-display-x-face instead")
1281 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1282 (t
1283 value)))))
1284(put 'gnus-treat-display-x-face 'highlight t)
1285
1286(defcustom gnus-treat-display-face
1287 (and (not noninteractive)
1288 (or (and (fboundp 'image-type-available-p)
1289 (image-type-available-p 'png))
1290 (and (featurep 'xemacs)
1291 (featurep 'png)))
1292 'head)
1293 "Display Face headers.
1294Valid values are nil, t, `head', `last', an integer or a predicate.
1295See Info node `(gnus)Customizing Articles' and Info node
1296`(gnus)X-Face' for details."
16409b0b 1297 :group 'gnus-article-treat
bf247b6e 1298 :version "22.1"
23f87bed
MB
1299 :link '(custom-manual "(gnus)Customizing Articles")
1300 :link '(custom-manual "(gnus)X-Face")
16409b0b 1301 :type gnus-article-treat-head-custom)
23f87bed 1302(put 'gnus-treat-display-face 'highlight t)
16409b0b 1303
a1506d29 1304(defcustom gnus-treat-display-smileys
e0bad764
DL
1305 (if (or (and (featurep 'xemacs)
1306 (featurep 'xpm))
1307 (and (fboundp 'image-type-available-p)
1308 (image-type-available-p 'pbm)))
1309 t nil)
16409b0b
GM
1310 "Display smileys.
1311Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed
MB
1312See Info node `(gnus)Customizing Articles' and Info node
1313`(gnus)Smileys' for details."
16409b0b 1314 :group 'gnus-article-treat
b5a206e7 1315 :version "21.1"
23f87bed
MB
1316 :link '(custom-manual "(gnus)Customizing Articles")
1317 :link '(custom-manual "(gnus)Smileys")
16409b0b
GM
1318 :type gnus-article-treat-custom)
1319(put 'gnus-treat-display-smileys 'highlight t)
1320
23f87bed
MB
1321(defcustom gnus-treat-from-picon
1322 (if (and (gnus-image-type-available-p 'xpm)
1323 (gnus-picons-installed-p))
1324 'head nil)
1325 "Display picons in the From header.
16409b0b 1326Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed
MB
1327See Info node `(gnus)Customizing Articles' and Info node
1328`(gnus)Picons' for details."
bf247b6e 1329 :version "22.1"
16409b0b 1330 :group 'gnus-article-treat
23f87bed
MB
1331 :group 'gnus-picon
1332 :link '(custom-manual "(gnus)Customizing Articles")
1333 :link '(custom-manual "(gnus)Picons")
1334 :type gnus-article-treat-head-custom)
1335(put 'gnus-treat-from-picon 'highlight t)
1336
1337(defcustom gnus-treat-mail-picon
1338 (if (and (gnus-image-type-available-p 'xpm)
1339 (gnus-picons-installed-p))
1340 'head nil)
1341 "Display picons in To and Cc headers.
1342Valid values are nil, t, `head', `last', an integer or a predicate.
1343See Info node `(gnus)Customizing Articles' and Info node
1344`(gnus)Picons' for details."
bf247b6e 1345 :version "22.1"
23f87bed
MB
1346 :group 'gnus-article-treat
1347 :group 'gnus-picon
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :link '(custom-manual "(gnus)Picons")
1350 :type gnus-article-treat-head-custom)
1351(put 'gnus-treat-mail-picon 'highlight t)
1352
1353(defcustom gnus-treat-newsgroups-picon
1354 (if (and (gnus-image-type-available-p 'xpm)
1355 (gnus-picons-installed-p))
1356 'head nil)
1357 "Display picons in the Newsgroups and Followup-To headers.
1358Valid values are nil, t, `head', `last', an integer or a predicate.
1359See Info node `(gnus)Customizing Articles' and Info node
1360`(gnus)Picons' for details."
bf247b6e 1361 :version "22.1"
23f87bed
MB
1362 :group 'gnus-article-treat
1363 :group 'gnus-picon
1364 :link '(custom-manual "(gnus)Customizing Articles")
1365 :link '(custom-manual "(gnus)Picons")
1366 :type gnus-article-treat-head-custom)
1367(put 'gnus-treat-newsgroups-picon 'highlight t)
1368
1369(defcustom gnus-treat-body-boundary
1370 (if (or gnus-treat-newsgroups-picon
1371 gnus-treat-mail-picon
1372 gnus-treat-from-picon)
1373 'head nil)
1374 "Draw a boundary at the end of the headers.
1375Valid values are nil and `head'.
1376See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1377 :version "22.1"
23f87bed
MB
1378 :group 'gnus-article-treat
1379 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b 1380 :type gnus-article-treat-head-custom)
16409b0b
GM
1381
1382(defcustom gnus-treat-capitalize-sentences nil
1383 "Capitalize sentence-starting words.
1384Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1385See Info node `(gnus)Customizing Articles' for details."
fc2c2db8 1386 :version "21.1"
16409b0b 1387 :group 'gnus-article-treat
23f87bed
MB
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1390
1391(defcustom gnus-treat-wash-html nil
1392 "Format as HTML.
1393Valid values are nil, t, `head', `last', an integer or a predicate.
1394See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1395 :version "22.1"
23f87bed
MB
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1398 :type gnus-article-treat-custom)
1399
1400(defcustom gnus-treat-fill-long-lines nil
1401 "Fill long lines.
1402Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1403See Info node `(gnus)Customizing Articles' for details."
16409b0b 1404 :group 'gnus-article-treat
23f87bed 1405 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1406 :type gnus-article-treat-custom)
1407
1408(defcustom gnus-treat-play-sounds nil
1409 "Play sounds.
1410Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1411See Info node `(gnus)Customizing Articles' for details."
fc2c2db8 1412 :version "21.1"
16409b0b 1413 :group 'gnus-article-treat
23f87bed 1414 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1415 :type gnus-article-treat-custom)
1416
1417(defcustom gnus-treat-translate nil
1418 "Translate articles from one language to another.
1419Valid values are nil, t, `head', `last', an integer or a predicate.
23f87bed 1420See Info node `(gnus)Customizing Articles' for details."
fc2c2db8 1421 :version "21.1"
16409b0b 1422 :group 'gnus-article-treat
23f87bed 1423 :link '(custom-manual "(gnus)Customizing Articles")
16409b0b
GM
1424 :type gnus-article-treat-custom)
1425
23f87bed
MB
1426(defcustom gnus-treat-x-pgp-sig nil
1427 "Verify X-PGP-Sig.
1428To automatically treat X-PGP-Sig, set it to head.
1429Valid values are nil, t, `head', `last', an integer or a predicate.
1430See Info node `(gnus)Customizing Articles' for details."
bf247b6e 1431 :version "22.1"
23f87bed
MB
1432 :group 'gnus-article-treat
1433 :group 'mime-security
1434 :link '(custom-manual "(gnus)Customizing Articles")
1435 :type gnus-article-treat-custom)
1436
1437(defvar gnus-article-encrypt-protocol-alist
1438 '(("PGP" . mml2015-self-encrypt)))
1439
1440;; Set to nil if more than one protocol added to
1441;; gnus-article-encrypt-protocol-alist.
1442(defcustom gnus-article-encrypt-protocol "PGP"
1443 "The protocol used for encrypt articles.
1444It is a string, such as \"PGP\". If nil, ask user."
bf247b6e 1445 :version "22.1"
23f87bed
MB
1446 :type 'string
1447 :group 'mime-security)
1448
1449(defvar gnus-article-wash-function nil
1450 "Function used for converting HTML into text.")
1451
1452(defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1453 (mm-coding-system-p 'utf-8)
1454 (executable-find idna-program))
1455 "Whether IDNA decoding of headers is used when viewing messages.
1456This requires GNU Libidn, and by default only enabled if it is found."
bf247b6e 1457 :version "22.1"
23f87bed
MB
1458 :group 'gnus-article-headers
1459 :type 'boolean)
1460
1461(defcustom gnus-article-over-scroll nil
1462 "If non-nil, allow scrolling the article buffer even when there no more text."
bf247b6e 1463 :version "22.1"
23f87bed
MB
1464 :group 'gnus-article
1465 :type 'boolean)
1466
eec82323
LMI
1467;;; Internal variables
1468
23f87bed
MB
1469(defvar gnus-english-month-names
1470 '("January" "February" "March" "April" "May" "June" "July" "August"
1471 "September" "October" "November" "December"))
1472
16409b0b
GM
1473(defvar article-goto-body-goes-to-point-min-p nil)
1474(defvar gnus-article-wash-types nil)
1475(defvar gnus-article-emphasis-alist nil)
23f87bed 1476(defvar gnus-article-image-alist nil)
16409b0b
GM
1477
1478(defvar gnus-article-mime-handle-alist-1 nil)
1479(defvar gnus-treatment-function-alist
23f87bed
MB
1480 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1481 (gnus-treat-strip-banner gnus-article-strip-banner)
16409b0b
GM
1482 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1483 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1484 (gnus-treat-buttonize gnus-article-add-buttons)
1485 (gnus-treat-fill-article gnus-article-fill-cited-article)
1486 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1487 (gnus-treat-strip-cr gnus-article-remove-cr)
23f87bed
MB
1488 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1489 (gnus-treat-date-ut gnus-article-date-ut)
1490 (gnus-treat-date-local gnus-article-date-local)
1491 (gnus-treat-date-english gnus-article-date-english)
23f87bed
MB
1492 (gnus-treat-date-original gnus-article-date-original)
1493 (gnus-treat-date-user-defined gnus-article-date-user)
1494 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
f3f01d5d 1495 (gnus-treat-date-lapsed gnus-article-date-lapsed)
23f87bed
MB
1496 (gnus-treat-display-x-face gnus-article-display-x-face)
1497 (gnus-treat-display-face gnus-article-display-face)
16409b0b
GM
1498 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1499 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1500 (gnus-treat-hide-signature gnus-article-hide-signature)
16409b0b 1501 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
23f87bed 1502 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
16409b0b 1503 (gnus-treat-strip-pem gnus-article-hide-pem)
23f87bed
MB
1504 (gnus-treat-from-picon gnus-treat-from-picon)
1505 (gnus-treat-mail-picon gnus-treat-mail-picon)
1506 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
16409b0b 1507 (gnus-treat-highlight-headers gnus-article-highlight-headers)
16409b0b 1508 (gnus-treat-highlight-signature gnus-article-highlight-signature)
16409b0b
GM
1509 (gnus-treat-strip-trailing-blank-lines
1510 gnus-article-remove-trailing-blank-lines)
1511 (gnus-treat-strip-leading-blank-lines
1512 gnus-article-strip-leading-blank-lines)
1513 (gnus-treat-strip-multiple-blank-lines
1514 gnus-article-strip-multiple-blank-lines)
1515 (gnus-treat-overstrike gnus-article-treat-overstrike)
23f87bed
MB
1516 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1517 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1518 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
16409b0b 1519 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
23f87bed 1520 (gnus-treat-display-smileys gnus-treat-smiley)
16409b0b 1521 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
23f87bed
MB
1522 (gnus-treat-wash-html gnus-article-wash-html)
1523 (gnus-treat-emphasize gnus-article-emphasize)
1524 (gnus-treat-hide-citation gnus-article-hide-citation)
1525 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1526 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1527 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
16409b0b
GM
1528 (gnus-treat-play-sounds gnus-earcon-display)))
1529
1530(defvar gnus-article-mime-handle-alist nil)
6748645f
LMI
1531(defvar article-lapsed-timer nil)
1532(defvar gnus-article-current-summary nil)
1533
eec82323
LMI
1534(defvar gnus-article-mode-syntax-table
1535 (let ((table (copy-syntax-table text-mode-syntax-table)))
23f87bed
MB
1536 ;; This causes the citation match run O(2^n).
1537 ;; (modify-syntax-entry ?- "w" table)
1538 (modify-syntax-entry ?> ")<" table)
1539 (modify-syntax-entry ?< "(>" table)
1540 ;; make M-. in article buffers work for `foo' strings
1541 (modify-syntax-entry ?' " " table)
1542 (modify-syntax-entry ?` " " table)
eec82323
LMI
1543 table)
1544 "Syntax table used in article mode buffers.
1545Initialized from `text-mode-syntax-table.")
1546
1547(defvar gnus-save-article-buffer nil)
1548
1549(defvar gnus-article-mode-line-format-alist
16409b0b
GM
1550 (nconc '((?w (gnus-article-wash-status) ?s)
1551 (?m (gnus-article-mime-part-status) ?s))
6748645f 1552 gnus-summary-mode-line-format-alist))
eec82323
LMI
1553
1554(defvar gnus-number-of-articles-to-be-saved nil)
1555
1556(defvar gnus-inhibit-hiding nil)
1557
c1d7d285
MB
1558(defvar gnus-article-edit-mode nil)
1559
23f87bed
MB
1560;;; Macros for dealing with the article buffer.
1561
1562(defmacro gnus-with-article-headers (&rest forms)
1563 `(save-excursion
1564 (set-buffer gnus-article-buffer)
1565 (save-restriction
1566 (let ((inhibit-read-only t)
1567 (inhibit-point-motion-hooks t)
1568 (case-fold-search t))
1569 (article-narrow-to-head)
1570 ,@forms))))
1571
1572(put 'gnus-with-article-headers 'lisp-indent-function 0)
1573(put 'gnus-with-article-headers 'edebug-form-spec '(body))
1574
1575(defmacro gnus-with-article-buffer (&rest forms)
1576 `(save-excursion
1577 (set-buffer gnus-article-buffer)
1578 (let ((inhibit-read-only t))
1579 ,@forms)))
1580
1581(put 'gnus-with-article-buffer 'lisp-indent-function 0)
1582(put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1583
1584(defun gnus-article-goto-header (header)
1585 "Go to HEADER, which is a regular expression."
1586 (re-search-forward (concat "^\\(" header "\\):") nil t))
1587
eec82323
LMI
1588(defsubst gnus-article-hide-text (b e props)
1589 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
520aa572 1590 (gnus-add-text-properties-when 'article-type nil b e props)
eec82323
LMI
1591 (when (memq 'intangible props)
1592 (put-text-property
1593 (max (1- b) (point-min))
1594 b 'intangible (cddr (memq 'intangible props)))))
520aa572 1595
eec82323
LMI
1596(defsubst gnus-article-unhide-text (b e)
1597 "Remove hidden text properties from region between B and E."
1598 (remove-text-properties b e gnus-hidden-properties)
1599 (when (memq 'intangible gnus-hidden-properties)
1600 (put-text-property (max (1- b) (point-min))
1601 b 'intangible nil)))
1602
1603(defun gnus-article-hide-text-type (b e type)
1604 "Hide text of TYPE between B and E."
23f87bed 1605 (gnus-add-wash-type type)
eec82323
LMI
1606 (gnus-article-hide-text
1607 b e (cons 'article-type (cons type gnus-hidden-properties))))
1608
1609(defun gnus-article-unhide-text-type (b e type)
6748645f 1610 "Unhide text of TYPE between B and E."
23f87bed 1611 (gnus-delete-wash-type type)
eec82323
LMI
1612 (remove-text-properties
1613 b e (cons 'article-type (cons type gnus-hidden-properties)))
1614 (when (memq 'intangible gnus-hidden-properties)
1615 (put-text-property (max (1- b) (point-min))
1616 b 'intangible nil)))
1617
1618(defun gnus-article-hide-text-of-type (type)
1619 "Hide text of TYPE in the current buffer."
1620 (save-excursion
1621 (let ((b (point-min))
1622 (e (point-max)))
1623 (while (setq b (text-property-any b e 'article-type type))
1624 (add-text-properties b (incf b) gnus-hidden-properties)))))
1625
1626(defun gnus-article-delete-text-of-type (type)
1627 "Delete text of TYPE in the current buffer."
1628 (save-excursion
a8151ef7
LMI
1629 (let ((b (point-min)))
1630 (while (setq b (text-property-any b (point-max) 'article-type type))
1631 (delete-region
1632 b (or (text-property-not-all b (point-max) 'article-type type)
1633 (point-max)))))))
eec82323
LMI
1634
1635(defun gnus-article-delete-invisible-text ()
1636 "Delete all invisible text in the current buffer."
1637 (save-excursion
a8151ef7
LMI
1638 (let ((b (point-min)))
1639 (while (setq b (text-property-any b (point-max) 'invisible t))
1640 (delete-region
1641 b (or (text-property-not-all b (point-max) 'invisible t)
1642 (point-max)))))))
eec82323
LMI
1643
1644(defun gnus-article-text-type-exists-p (type)
1645 "Say whether any text of type TYPE exists in the buffer."
1646 (text-property-any (point-min) (point-max) 'article-type type))
1647
1648(defsubst gnus-article-header-rank ()
1649 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1650 (let ((list gnus-sorted-header-list)
23f87bed 1651 (i 1))
eec82323 1652 (while list
23f87bed
MB
1653 (if (looking-at (car list))
1654 (setq list nil)
1655 (setq list (cdr list))
1656 (incf i)))
1657 i))
eec82323
LMI
1658
1659(defun article-hide-headers (&optional arg delete)
16409b0b
GM
1660 "Hide unwanted headers and possibly sort them as well."
1661 (interactive)
1662 ;; This function might be inhibited.
1663 (unless gnus-inhibit-hiding
23f87bed
MB
1664 (let ((inhibit-read-only nil)
1665 (case-fold-search t)
1666 (max (1+ (length gnus-sorted-header-list)))
1667 (inhibit-point-motion-hooks t)
1668 (cur (current-buffer))
1669 ignored visible beg)
1670 (save-excursion
1671 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1672 ;; group parameters, so we should go to the summary buffer.
1673 (when (prog1
1674 (condition-case nil
1675 (progn (set-buffer gnus-summary-buffer) t)
1676 (error nil))
1677 (setq ignored (when (not gnus-visible-headers)
1678 (cond ((stringp gnus-ignored-headers)
1679 gnus-ignored-headers)
1680 ((listp gnus-ignored-headers)
1681 (mapconcat 'identity
1682 gnus-ignored-headers
1683 "\\|"))))
1684 visible (cond ((stringp gnus-visible-headers)
1685 gnus-visible-headers)
1686 ((and gnus-visible-headers
1687 (listp gnus-visible-headers))
1688 (mapconcat 'identity
1689 gnus-visible-headers
1690 "\\|")))))
1691 (set-buffer cur))
1692 (save-restriction
16409b0b
GM
1693 ;; First we narrow to just the headers.
1694 (article-narrow-to-head)
1695 ;; Hide any "From " lines at the beginning of (mail) articles.
1696 (while (looking-at "From ")
1697 (forward-line 1))
1698 (unless (bobp)
1699 (delete-region (point-min) (point)))
1700 ;; Then treat the rest of the header lines.
1701 ;; Then we use the two regular expressions
1702 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1703 ;; select which header lines is to remain visible in the
1704 ;; article buffer.
23f87bed 1705 (while (re-search-forward "^[^ \t:]*:" nil t)
16409b0b
GM
1706 (beginning-of-line)
1707 ;; Mark the rank of the header.
1708 (put-text-property
1709 (point) (1+ (point)) 'message-rank
1710 (if (or (and visible (looking-at visible))
1711 (and ignored
1712 (not (looking-at ignored))))
1713 (gnus-article-header-rank)
1714 (+ 2 max)))
1715 (forward-line 1))
1716 (message-sort-headers-1)
1717 (when (setq beg (text-property-any
1718 (point-min) (point-max) 'message-rank (+ 2 max)))
1719 ;; We delete the unwanted headers.
23f87bed 1720 (gnus-add-wash-type 'headers)
16409b0b
GM
1721 (add-text-properties (point-min) (+ 5 (point-min))
1722 '(article-type headers dummy-invisible t))
1723 (delete-region beg (point-max))))))))
eec82323
LMI
1724
1725(defun article-hide-boring-headers (&optional arg)
1726 "Toggle hiding of headers that aren't very interesting.
1727If given a negative prefix, always show; if given a positive prefix,
1728always hide."
1729 (interactive (gnus-article-hidden-arg))
1730 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1731 (not gnus-show-all-headers))
1732 (save-excursion
1733 (save-restriction
4e7d0221 1734 (let ((inhibit-read-only t)
eec82323
LMI
1735 (list gnus-boring-article-headers)
1736 (inhibit-point-motion-hooks t)
1737 elem)
16409b0b 1738 (article-narrow-to-head)
eec82323
LMI
1739 (while list
1740 (setq elem (pop list))
1741 (goto-char (point-min))
1742 (cond
1743 ;; Hide empty headers.
1744 ((eq elem 'empty)
16409b0b 1745 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
eec82323
LMI
1746 (forward-line -1)
1747 (gnus-article-hide-text-type
23f87bed 1748 (gnus-point-at-bol)
eec82323
LMI
1749 (progn
1750 (end-of-line)
1751 (if (re-search-forward "^[^ \t]" nil t)
1752 (match-beginning 0)
1753 (point-max)))
1754 'boring-headers)))
1755 ;; Hide boring Newsgroups header.
1756 ((eq elem 'newsgroups)
23f87bed
MB
1757 (when (gnus-string-equal
1758 (gnus-fetch-field "newsgroups")
1759 (gnus-group-real-name
1760 (if (boundp 'gnus-newsgroup-name)
1761 gnus-newsgroup-name
1762 "")))
eec82323 1763 (gnus-article-hide-header "newsgroups")))
23f87bed
MB
1764 ((eq elem 'to-address)
1765 (let ((to (message-fetch-field "to"))
1766 (to-address
1767 (gnus-parameter-to-address
1768 (if (boundp 'gnus-newsgroup-name)
1769 gnus-newsgroup-name ""))))
1770 (when (and to to-address
1771 (ignore-errors
1772 (gnus-string-equal
1773 ;; only one address in To
1774 (nth 1 (mail-extract-address-components to))
1775 to-address)))
1776 (gnus-article-hide-header "to"))))
1777 ((eq elem 'to-list)
1778 (let ((to (message-fetch-field "to"))
1779 (to-list
1780 (gnus-parameter-to-list
1781 (if (boundp 'gnus-newsgroup-name)
1782 gnus-newsgroup-name ""))))
1783 (when (and to to-list
1784 (ignore-errors
1785 (gnus-string-equal
1786 ;; only one address in To
1787 (nth 1 (mail-extract-address-components to))
1788 to-list)))
1789 (gnus-article-hide-header "to"))))
1790 ((eq elem 'cc-list)
1791 (let ((cc (message-fetch-field "cc"))
1792 (to-list
1793 (gnus-parameter-to-list
1794 (if (boundp 'gnus-newsgroup-name)
1795 gnus-newsgroup-name ""))))
1796 (when (and cc to-list
1797 (ignore-errors
1798 (gnus-string-equal
1799 ;; only one address in CC
1800 (nth 1 (mail-extract-address-components cc))
1801 to-list)))
1802 (gnus-article-hide-header "cc"))))
eec82323 1803 ((eq elem 'followup-to)
23f87bed
MB
1804 (when (gnus-string-equal
1805 (message-fetch-field "followup-to")
1806 (message-fetch-field "newsgroups"))
eec82323
LMI
1807 (gnus-article-hide-header "followup-to")))
1808 ((eq elem 'reply-to)
23f87bed
MB
1809 (if (gnus-group-find-parameter
1810 gnus-newsgroup-name 'broken-reply-to)
1811 (gnus-article-hide-header "reply-to")
1812 (let ((from (message-fetch-field "from"))
1813 (reply-to (message-fetch-field "reply-to")))
1814 (when
1815 (and
eec82323
LMI
1816 from reply-to
1817 (ignore-errors
1818 (equal
23f87bed
MB
1819 (sort (mapcar
1820 (lambda (x) (downcase (cadr x)))
1821 (mail-extract-address-components from t))
1822 'string<)
1823 (sort (mapcar
1824 (lambda (x) (downcase (cadr x)))
1825 (mail-extract-address-components reply-to t))
1826 'string<))))
1827 (gnus-article-hide-header "reply-to")))))
eec82323
LMI
1828 ((eq elem 'date)
1829 (let ((date (message-fetch-field "date")))
1830 (when (and date
16409b0b 1831 (< (days-between (current-time-string) date)
eec82323 1832 4))
6748645f
LMI
1833 (gnus-article-hide-header "date"))))
1834 ((eq elem 'long-to)
16409b0b
GM
1835 (let ((to (message-fetch-field "to"))
1836 (cc (message-fetch-field "cc")))
6748645f 1837 (when (> (length to) 1024)
16409b0b
GM
1838 (gnus-article-hide-header "to"))
1839 (when (> (length cc) 1024)
1840 (gnus-article-hide-header "cc"))))
6748645f 1841 ((eq elem 'many-to)
16409b0b
GM
1842 (let ((to-count 0)
1843 (cc-count 0))
6748645f
LMI
1844 (goto-char (point-min))
1845 (while (re-search-forward "^to:" nil t)
1846 (setq to-count (1+ to-count)))
1847 (when (> to-count 1)
1848 (while (> to-count 0)
1849 (goto-char (point-min))
1850 (save-restriction
1851 (re-search-forward "^to:" nil nil to-count)
1852 (forward-line -1)
1853 (narrow-to-region (point) (point-max))
1854 (gnus-article-hide-header "to"))
16409b0b
GM
1855 (setq to-count (1- to-count))))
1856 (goto-char (point-min))
1857 (while (re-search-forward "^cc:" nil t)
1858 (setq cc-count (1+ cc-count)))
1859 (when (> cc-count 1)
1860 (while (> cc-count 0)
1861 (goto-char (point-min))
1862 (save-restriction
1863 (re-search-forward "^cc:" nil nil cc-count)
1864 (forward-line -1)
1865 (narrow-to-region (point) (point-max))
1866 (gnus-article-hide-header "cc"))
1867 (setq cc-count (1- cc-count)))))))))))))
eec82323
LMI
1868
1869(defun gnus-article-hide-header (header)
1870 (save-excursion
1871 (goto-char (point-min))
1872 (when (re-search-forward (concat "^" header ":") nil t)
1873 (gnus-article-hide-text-type
23f87bed 1874 (gnus-point-at-bol)
eec82323
LMI
1875 (progn
1876 (end-of-line)
1877 (if (re-search-forward "^[^ \t]" nil t)
1878 (match-beginning 0)
1879 (point-max)))
1880 'boring-headers))))
1881
16409b0b
GM
1882(defvar gnus-article-normalized-header-length 40
1883 "Length of normalized headers.")
1884
1885(defun article-normalize-headers ()
1886 "Make all header lines 40 characters long."
1887 (interactive)
4e7d0221 1888 (let ((inhibit-read-only t)
16409b0b
GM
1889 column)
1890 (save-excursion
1891 (save-restriction
1892 (article-narrow-to-head)
1893 (while (not (eobp))
1894 (cond
1895 ((< (setq column (- (gnus-point-at-eol) (point)))
1896 gnus-article-normalized-header-length)
1897 (end-of-line)
1898 (insert (make-string
1899 (- gnus-article-normalized-header-length column)
1900 ? )))
1901 ((> column gnus-article-normalized-header-length)
1902 (gnus-put-text-property
1903 (progn
1904 (forward-char gnus-article-normalized-header-length)
1905 (point))
1906 (gnus-point-at-eol)
1907 'invisible t))
1908 (t
1909 ;; Do nothing.
1910 ))
1911 (forward-line 1))))))
1912
6748645f 1913(defun article-treat-dumbquotes ()
23f87bed 1914 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
16409b0b 1915Note that this function guesses whether a character is a sm*rtq**t* or
74dd1b0d
SZ
1916not, so it should only be used interactively.
1917
23f87bed
MB
1918Sm*rtq**t*s are M****s***'s unilateral extension to the
1919iso-8859-1 character map in an attempt to provide more quoting
1920characters. If you see something like \\222 or \\264 where
1921you're expecting some kind of apostrophe or quotation mark, then
1922try this wash."
6748645f 1923 (interactive)
16409b0b 1924 (article-translate-strings gnus-article-dumbquotes-map))
6748645f
LMI
1925
1926(defun article-translate-characters (from to)
1927 "Translate all characters in the body of the article according to FROM and TO.
1928FROM is a string of characters to translate from; to is a string of
1929characters to translate to."
1930 (save-excursion
16409b0b 1931 (when (article-goto-body)
4e7d0221 1932 (let ((inhibit-read-only t)
6748645f
LMI
1933 (x (make-string 225 ?x))
1934 (i -1))
1935 (while (< (incf i) (length x))
1936 (aset x i i))
1937 (setq i 0)
1938 (while (< i (length from))
1939 (aset x (aref from i) (aref to i))
1940 (incf i))
1941 (translate-region (point) (point-max) x)))))
1942
16409b0b
GM
1943(defun article-translate-strings (map)
1944 "Translate all string in the body of the article according to MAP.
1945MAP is an alist where the elements are on the form (\"from\" \"to\")."
1946 (save-excursion
1947 (when (article-goto-body)
4e7d0221 1948 (let ((inhibit-read-only t)
16409b0b
GM
1949 elem)
1950 (while (setq elem (pop map))
1951 (save-excursion
1952 (while (search-forward (car elem) nil t)
1953 (replace-match (cadr elem)))))))))
1954
eec82323
LMI
1955(defun article-treat-overstrike ()
1956 "Translate overstrikes into bold text."
1957 (interactive)
1958 (save-excursion
16409b0b 1959 (when (article-goto-body)
4e7d0221 1960 (let ((inhibit-read-only t))
eec82323 1961 (while (search-forward "\b" nil t)
16409b0b 1962 (let ((next (char-after))
eec82323
LMI
1963 (previous (char-after (- (point) 2))))
1964 ;; We do the boldification/underlining by hiding the
1965 ;; overstrikes and putting the proper text property
1966 ;; on the letters.
1967 (cond
1968 ((eq next previous)
1969 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1970 (put-text-property (point) (1+ (point)) 'face 'bold))
1971 ((eq next ?_)
1972 (gnus-article-hide-text-type
1973 (1- (point)) (1+ (point)) 'overstrike)
1974 (put-text-property
1975 (- (point) 2) (1- (point)) 'face 'underline))
1976 ((eq previous ?_)
1977 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1978 (put-text-property
1979 (point) (1+ (point)) 'face 'underline)))))))))
1980
23f87bed
MB
1981(defun gnus-article-treat-unfold-headers ()
1982 "Unfold folded message headers.
1983Only the headers that fit into the current window width will be
1984unfolded."
1985 (interactive)
1986 (gnus-with-article-headers
1987 (let (length)
1988 (while (not (eobp))
1989 (save-restriction
1990 (mail-header-narrow-to-field)
1991 (let ((header (buffer-string)))
1992 (with-temp-buffer
1993 (insert header)
1994 (goto-char (point-min))
1995 (while (re-search-forward "\n[\t ]" nil t)
1996 (replace-match " " t t)))
1997 (setq length (- (point-max) (point-min) 1)))
1998 (when (< length (window-width))
1999 (while (re-search-forward "\n[\t ]" nil t)
2000 (replace-match " " t t)))
2001 (goto-char (point-max)))))))
2002
2003(defun gnus-article-treat-fold-headers ()
2004 "Fold message headers."
2005 (interactive)
2006 (gnus-with-article-headers
2007 (while (not (eobp))
2008 (save-restriction
2009 (mail-header-narrow-to-field)
2010 (mail-header-fold-field)
2011 (goto-char (point-max))))))
2012
2013(defun gnus-treat-smiley ()
2014 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2015 (interactive)
2016 (gnus-with-article-buffer
2017 (if (memq 'smiley gnus-article-wash-types)
2018 (gnus-delete-images 'smiley)
2019 (article-goto-body)
2020 (let ((images (smiley-region (point) (point-max))))
2021 (when images
2022 (gnus-add-wash-type 'smiley)
2023 (dolist (image images)
2024 (gnus-add-image 'smiley image)))))))
2025
2026(defun gnus-article-remove-images ()
2027 "Remove all images from the article buffer."
2028 (interactive)
2029 (gnus-with-article-buffer
2030 (dolist (elem gnus-article-image-alist)
2031 (gnus-delete-images (car elem)))))
2032
2033(defun gnus-article-treat-fold-newsgroups ()
2034 "Unfold folded message headers.
2035Only the headers that fit into the current window width will be
2036unfolded."
2037 (interactive)
2038 (gnus-with-article-headers
2039 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2040 (save-restriction
2041 (mail-header-narrow-to-field)
2042 (while (re-search-forward ", *" nil t)
2043 (replace-match ", " t t))
2044 (mail-header-fold-field)
2045 (goto-char (point-max))))))
2046
2047(defun gnus-article-treat-body-boundary ()
2048 "Place a boundary line at the end of the headers."
2049 (interactive)
2050 (when (and gnus-body-boundary-delimiter
2051 (> (length gnus-body-boundary-delimiter) 0))
2052 (gnus-with-article-headers
2053 (goto-char (point-max))
2054 (let ((start (point)))
2055 (insert "X-Boundary: ")
2056 (gnus-add-text-properties start (point) '(invisible t intangible t))
2057 (insert (let (str)
2058 (while (>= (1- (window-width)) (length str))
2059 (setq str (concat str gnus-body-boundary-delimiter)))
2060 (substring str 0 (1- (window-width))))
2061 "\n")
2062 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2063
16409b0b
GM
2064(defun article-fill-long-lines ()
2065 "Fill lines that are wider than the window width."
eec82323
LMI
2066 (interactive)
2067 (save-excursion
4e7d0221 2068 (let ((inhibit-read-only t)
16409b0b
GM
2069 (width (window-width (get-buffer-window (current-buffer)))))
2070 (save-restriction
2071 (article-goto-body)
80b47379 2072 (let ((adaptive-fill-mode nil)) ;Why? -sm
16409b0b
GM
2073 (while (not (eobp))
2074 (end-of-line)
2075 (when (>= (current-column) (min fill-column width))
23f87bed
MB
2076 (narrow-to-region (min (1+ (point)) (point-max))
2077 (gnus-point-at-bol))
2078 (let ((goback (point-marker)))
2079 (fill-paragraph nil)
2080 (goto-char (marker-position goback)))
16409b0b
GM
2081 (widen))
2082 (forward-line 1)))))))
2083
2084(defun article-capitalize-sentences ()
2085 "Capitalize the first word in each sentence."
2086 (interactive)
2087 (save-excursion
4e7d0221 2088 (let ((inhibit-read-only t)
16409b0b
GM
2089 (paragraph-start "^[\n\^L]"))
2090 (article-goto-body)
2091 (while (not (eobp))
2092 (capitalize-word 1)
2093 (forward-sentence)))))
eec82323
LMI
2094
2095(defun article-remove-cr ()
16409b0b 2096 "Remove trailing CRs and then translate remaining CRs into LFs."
eec82323
LMI
2097 (interactive)
2098 (save-excursion
4e7d0221 2099 (let ((inhibit-read-only t))
eec82323 2100 (goto-char (point-min))
16409b0b
GM
2101 (while (re-search-forward "\r+$" nil t)
2102 (replace-match "" t t))
2103 (goto-char (point-min))
eec82323 2104 (while (search-forward "\r" nil t)
16409b0b 2105 (replace-match "\n" t t)))))
eec82323
LMI
2106
2107(defun article-remove-trailing-blank-lines ()
2108 "Remove all trailing blank lines from the article."
2109 (interactive)
2110 (save-excursion
4e7d0221 2111 (let ((inhibit-read-only t))
eec82323
LMI
2112 (goto-char (point-max))
2113 (delete-region
2114 (point)
2115 (progn
2116 (while (and (not (bobp))
16409b0b
GM
2117 (looking-at "^[ \t]*$")
2118 (not (gnus-annotation-in-region-p
2119 (point) (gnus-point-at-eol))))
eec82323
LMI
2120 (forward-line -1))
2121 (forward-line 1)
2122 (point))))))
2123
23f87bed
MB
2124(defun article-display-face ()
2125 "Display any Face headers in the header."
2126 (interactive)
2127 (let ((wash-face-p buffer-read-only))
2128 (gnus-with-article-headers
2129 ;; When displaying parts, this function can be called several times on
2130 ;; the same article, without any intended toggle semantic (as typing `W
2131 ;; D d' would have). So face deletion must occur only when we come from
2132 ;; an interactive command, that is when the *Article* buffer is
2133 ;; read-only.
2134 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2135 (gnus-delete-images 'face)
7d0c69be
MB
2136 (let (face faces from)
2137 (save-current-buffer
23f87bed 2138 (when (and wash-face-p
7d0c69be
MB
2139 (gnus-buffer-live-p gnus-original-article-buffer)
2140 (not (re-search-forward "^Face:[\t ]*" nil t)))
23f87bed
MB
2141 (set-buffer gnus-original-article-buffer))
2142 (save-restriction
2143 (mail-narrow-to-head)
2144 (while (gnus-article-goto-header "Face")
2145 (push (mail-header-field-value) faces))))
d6697c02 2146 (when faces
7d0c69be
MB
2147 (goto-char (point-min))
2148 (let ((from (gnus-article-goto-header "from"))
2149 png image)
2150 (unless from
2151 (insert "From:")
2152 (setq from (point))
2153 (insert "[no `from' set]\n"))
2154 (while faces
2155 (when (setq png (gnus-convert-face-to-png (pop faces)))
d6697c02
MB
2156 (setq image (gnus-create-image png 'png t))
2157 (goto-char from)
2158 (gnus-add-wash-type 'face)
2159 (gnus-add-image 'face image)
2160 (gnus-put-image image nil 'face))))))))))
23f87bed 2161
eec82323
LMI
2162(defun article-display-x-face (&optional force)
2163 "Look for an X-Face header and display it if present."
2164 (interactive (list 'force))
23f87bed
MB
2165 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2166 (gnus-with-article-headers
2167 ;; Delete the old process, if any.
2168 (when (process-status "article-x-face")
2169 (delete-process "article-x-face"))
2170 ;; See the comment in `article-display-face'.
2171 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2172 ;; We have already displayed X-Faces, so we remove them
2173 ;; instead.
2174 (gnus-delete-images 'xface)
2175 ;; Display X-Faces.
2176 (let (x-faces from face)
7d0c69be 2177 (save-current-buffer
23f87bed 2178 (when (and wash-face-p
7d0c69be
MB
2179 (gnus-buffer-live-p gnus-original-article-buffer)
2180 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
23f87bed
MB
2181 ;; If type `W f', use gnus-original-article-buffer,
2182 ;; otherwise use the current buffer because displaying
2183 ;; RFC822 parts calls this function too.
2184 (set-buffer gnus-original-article-buffer))
2185 (save-restriction
2186 (mail-narrow-to-head)
2187 (while (gnus-article-goto-header "X-Face")
2188 (push (mail-header-field-value) x-faces))
2189 (setq from (message-fetch-field "from"))))
2190 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2191 ;; single external face.
2192 (when (stringp gnus-article-x-face-command)
2193 (setq x-faces (list (car x-faces))))
7d0c69be
MB
2194 (when (and x-faces
2195 gnus-article-x-face-command
2196 (or force
2197 ;; Check whether this face is censored.
2198 (not gnus-article-x-face-too-ugly)
2199 (and from
2200 (not (string-match gnus-article-x-face-too-ugly
2201 from)))))
2202 (while (setq face (pop x-faces))
2203 ;; We display the face.
2204 (cond ((stringp gnus-article-x-face-command)
2205 ;; The command is a string, so we interpret the command
2206 ;; as a, well, command, and fork it off.
2207 (let ((process-connection-type nil))
2208 (gnus-set-process-query-on-exit-flag
2209 (start-process
2210 "article-x-face" nil shell-file-name
2211 shell-command-switch gnus-article-x-face-command)
2212 nil)
2213 (with-temp-buffer
2214 (insert face)
2215 (process-send-region "article-x-face"
2216 (point-min) (point-max)))
2217 (process-send-eof "article-x-face")))
2218 ((functionp gnus-article-x-face-command)
2219 ;; The command is a lisp function, so we call it.
2220 (funcall gnus-article-x-face-command face))
2221 (t
2222 (error "%s is not a function"
2223 gnus-article-x-face-command))))))))))
a8151ef7 2224
16409b0b
GM
2225(defun article-decode-mime-words ()
2226 "Decode all MIME-encoded words in the article."
2227 (interactive)
2228 (save-excursion
2229 (set-buffer gnus-article-buffer)
2230 (let ((inhibit-point-motion-hooks t)
23f87bed 2231 (inhibit-read-only t)
16409b0b 2232 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2233 (mail-parse-ignored-charsets
16409b0b
GM
2234 (save-excursion (set-buffer gnus-summary-buffer)
2235 gnus-newsgroup-ignored-charsets)))
2236 (mail-decode-encoded-word-region (point-min) (point-max)))))
2237
2238(defun article-decode-charset (&optional prompt)
2239 "Decode charset-encoded text in the article.
2240If PROMPT (the prefix), prompt for a coding system to use."
2241 (interactive "P")
2242 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
23f87bed 2243 (inhibit-read-only t)
16409b0b 2244 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2245 (mail-parse-ignored-charsets
16409b0b
GM
2246 (save-excursion (condition-case nil
2247 (set-buffer gnus-summary-buffer)
2248 (error))
2249 gnus-newsgroup-ignored-charsets))
2250 ct cte ctl charset format)
2251 (save-excursion
eec82323 2252 (save-restriction
16409b0b
GM
2253 (article-narrow-to-head)
2254 (setq ct (message-fetch-field "Content-Type" t)
2255 cte (message-fetch-field "Content-Transfer-Encoding" t)
2256 ctl (and ct (ignore-errors
2257 (mail-header-parse-content-type ct)))
2258 charset (cond
2259 (prompt
2260 (mm-read-coding-system "Charset to decode: "))
2261 (ctl
2262 (mail-content-type-get ctl 'charset)))
2263 format (and ctl (mail-content-type-get ctl 'format)))
2264 (when cte
2265 (setq cte (mail-header-strip cte)))
a1506d29 2266 (if (and ctl (not (string-match "/" (car ctl))))
16409b0b
GM
2267 (setq ctl nil))
2268 (goto-char (point-max)))
2269 (forward-line 1)
2270 (save-restriction
2271 (narrow-to-region (point) (point-max))
2272 (when (and (eq mail-parse-charset 'gnus-decoded)
2273 (eq (mm-body-7-or-8) '8bit))
2274 ;; The text code could have been decoded.
2275 (setq charset mail-parse-charset))
2276 (when (and (or (not ctl)
2277 (equal (car ctl) "text/plain"))
2278 (not format)) ;; article with format will decode later.
2279 (mm-decode-body
2280 charset (and cte (intern (downcase
2281 (gnus-strip-whitespace cte))))
2282 (car ctl)))))))
2283
2284(defun article-decode-encoded-words ()
2285 "Remove encoded-word encoding from headers."
2286 (let ((inhibit-point-motion-hooks t)
2287 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 2288 (mail-parse-ignored-charsets
16409b0b
GM
2289 (save-excursion (condition-case nil
2290 (set-buffer gnus-summary-buffer)
2291 (error))
2292 gnus-newsgroup-ignored-charsets))
23f87bed 2293 (inhibit-read-only t))
16409b0b
GM
2294 (save-restriction
2295 (article-narrow-to-head)
2296 (funcall gnus-decode-header-function (point-min) (point-max)))))
eec82323 2297
23f87bed
MB
2298(defun article-decode-group-name ()
2299 "Decode group names in `Newsgroups:'."
2300 (let ((inhibit-point-motion-hooks t)
2301 (inhibit-read-only t)
2302 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2303 (when (and (or gnus-group-name-charset-method-alist
2304 gnus-group-name-charset-group-alist)
2305 (gnus-buffer-live-p gnus-original-article-buffer))
2306 (save-restriction
2307 (article-narrow-to-head)
2308 (with-current-buffer gnus-original-article-buffer
2309 (goto-char (point-min)))
2310 (while (re-search-forward
2311 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2312 (replace-match (save-match-data
2313 (gnus-decode-newsgroups
2314 ;; XXX how to use data in article buffer?
2315 (with-current-buffer gnus-original-article-buffer
2316 (re-search-forward
2317 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2318 nil t)
2319 (match-string 1))
2320 gnus-newsgroup-name method))
2321 t t nil 1))
2322 (goto-char (point-min))
2323 (with-current-buffer gnus-original-article-buffer
2324 (goto-char (point-min)))
2325 (while (re-search-forward
2326 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2327 (replace-match (save-match-data
2328 (gnus-decode-newsgroups
2329 ;; XXX how to use data in article buffer?
2330 (with-current-buffer gnus-original-article-buffer
2331 (re-search-forward
2332 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2333 nil t)
2334 (match-string 1))
2335 gnus-newsgroup-name method))
2336 t t nil 1))))))
2337
2338(autoload 'idna-to-unicode "idna")
2339
2340(defun article-decode-idna-rhs ()
53cfefc8
MB
2341 "Decode IDNA strings in RHS in various headers in current buffer.
2342The following headers are decoded: From:, To:, Cc:, Reply-To:,
2343Mail-Reply-To: and Mail-Followup-To:."
23f87bed
MB
2344 (when gnus-use-idna
2345 (save-restriction
2346 (let ((inhibit-point-motion-hooks t)
2347 (inhibit-read-only t))
2348 (article-narrow-to-head)
2349 (goto-char (point-min))
53cfefc8 2350 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
23f87bed
MB
2351 (let (ace unicode)
2352 (when (save-match-data
2353 (and (setq ace (match-string 1))
2354 (save-excursion
2355 (and (re-search-backward "^[^ \t]" nil t)
53cfefc8 2356 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
23f87bed
MB
2357 (setq unicode (idna-to-unicode ace))))
2358 (unless (string= ace unicode)
2359 (replace-match unicode nil nil nil 1)))))))))
2360
2361(defun article-de-quoted-unreadable (&optional force read-charset)
16409b0b 2362 "Translate a quoted-printable-encoded article.
eec82323 2363If FORCE, decode the article whether it is marked as quoted-printable
23f87bed
MB
2364or not.
2365If READ-CHARSET, ask for a coding system."
2366 (interactive (list 'force current-prefix-arg))
eec82323 2367 (save-excursion
4e7d0221 2368 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2369 (if (gnus-buffer-live-p gnus-original-article-buffer)
2370 (with-current-buffer gnus-original-article-buffer
2371 (setq type
2372 (gnus-fetch-field "content-transfer-encoding"))
2373 (let* ((ct (gnus-fetch-field "content-type"))
a1506d29 2374 (ctl (and ct
8b93df01
DL
2375 (ignore-errors
2376 (mail-header-parse-content-type ct)))))
2377 (setq charset (and ctl
2378 (mail-content-type-get ctl 'charset)))
2379 (if (stringp charset)
2380 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2381 (if read-charset
2382 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2383 (unless charset
8b93df01 2384 (setq charset gnus-newsgroup-charset))
eec82323 2385 (when (or force
eb806ef3
DL
2386 (and type (let ((case-fold-search t))
2387 (string-match "quoted-printable" type))))
16409b0b 2388 (article-goto-body)
eb806ef3
DL
2389 (quoted-printable-decode-region
2390 (point) (point-max) (mm-charset-to-coding-system charset))))))
16409b0b 2391
23f87bed 2392(defun article-de-base64-unreadable (&optional force read-charset)
16409b0b 2393 "Translate a base64 article.
23f87bed
MB
2394If FORCE, decode the article whether it is marked as base64 not.
2395If READ-CHARSET, ask for a coding system."
2396 (interactive (list 'force current-prefix-arg))
16409b0b 2397 (save-excursion
4e7d0221 2398 (let ((inhibit-read-only t) type charset)
8b93df01
DL
2399 (if (gnus-buffer-live-p gnus-original-article-buffer)
2400 (with-current-buffer gnus-original-article-buffer
2401 (setq type
2402 (gnus-fetch-field "content-transfer-encoding"))
2403 (let* ((ct (gnus-fetch-field "content-type"))
a1506d29 2404 (ctl (and ct
8b93df01
DL
2405 (ignore-errors
2406 (mail-header-parse-content-type ct)))))
2407 (setq charset (and ctl
2408 (mail-content-type-get ctl 'charset)))
2409 (if (stringp charset)
2410 (setq charset (intern (downcase charset)))))))
23f87bed
MB
2411 (if read-charset
2412 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2413 (unless charset
8b93df01 2414 (setq charset gnus-newsgroup-charset))
16409b0b 2415 (when (or force
eb806ef3
DL
2416 (and type (let ((case-fold-search t))
2417 (string-match "base64" type))))
16409b0b
GM
2418 (article-goto-body)
2419 (save-restriction
2420 (narrow-to-region (point) (point-max))
2421 (base64-decode-region (point-min) (point-max))
eb806ef3
DL
2422 (mm-decode-coding-region
2423 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
16409b0b
GM
2424
2425(eval-when-compile
2426 (require 'rfc1843))
2427
2428(defun article-decode-HZ ()
2429 "Translate a HZ-encoded article."
2430 (interactive)
2431 (require 'rfc1843)
2432 (save-excursion
4e7d0221 2433 (let ((inhibit-read-only t))
16409b0b
GM
2434 (rfc1843-decode-region (point-min) (point-max)))))
2435
23f87bed
MB
2436(defun article-unsplit-urls ()
2437 "Remove the newlines that some other mailers insert into URLs."
16409b0b 2438 (interactive)
23f87bed
MB
2439 (save-excursion
2440 (let ((inhibit-read-only t))
2441 (goto-char (point-min))
2442 (while (re-search-forward
97f78c9b 2443 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
23f87bed
MB
2444 (replace-match "\\1\\3" t)))
2445 (when (interactive-p)
2446 (gnus-treat-article nil))))
2447
2448
2449(defun article-wash-html (&optional read-charset)
2450 "Format an HTML article.
2451If READ-CHARSET, ask for a coding system."
2452 (interactive "P")
16409b0b 2453 (save-excursion
4e7d0221 2454 (let ((inhibit-read-only t)
8b93df01 2455 charset)
23f87bed
MB
2456 (when (gnus-buffer-live-p gnus-original-article-buffer)
2457 (with-current-buffer gnus-original-article-buffer
2458 (let* ((ct (gnus-fetch-field "content-type"))
2459 (ctl (and ct
2460 (ignore-errors
2461 (mail-header-parse-content-type ct)))))
2462 (setq charset (and ctl
2463 (mail-content-type-get ctl 'charset)))
2464 (when (stringp charset)
2465 (setq charset (intern (downcase charset)))))))
2466 (when read-charset
2467 (setq charset (mm-read-coding-system "Charset: " charset)))
a1506d29 2468 (unless charset
8b93df01 2469 (setq charset gnus-newsgroup-charset))
16409b0b
GM
2470 (article-goto-body)
2471 (save-window-excursion
2472 (save-restriction
2473 (narrow-to-region (point) (point-max))
23f87bed
MB
2474 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2475 (entry (assq func mm-text-html-washer-alist)))
2476 (when entry
2477 (setq func (cdr entry)))
2478 (cond
2479 ((functionp func)
2480 (funcall func))
2481 (t
2482 (apply (car func) (cdr func))))))))))
2483
2484(defun gnus-article-wash-html-with-w3 ()
2485 "Wash the current buffer with w3."
2486 (mm-setup-w3)
2487 (let ((w3-strict-width (window-width))
2488 (url-standalone-mode t)
2489 (url-gateway-unplugged t)
2490 (w3-honor-stylesheets nil))
2491 (condition-case ()
2492 (w3-region (point-min) (point-max))
2493 (error))))
2494
2495(defun gnus-article-wash-html-with-w3m ()
2496 "Wash the current buffer with emacs-w3m."
2497 (mm-setup-w3m)
2498 (save-restriction
2499 (narrow-to-region (point) (point-max))
2500 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2501 w3m-force-redisplay)
2502 (w3m-region (point-min) (point-max)))
2503 (when (and mm-inline-text-html-with-w3m-keymap
2504 (boundp 'w3m-minor-mode-map)
2505 w3m-minor-mode-map)
2506 (add-text-properties
2507 (point-min) (point-max)
2508 (list 'keymap w3m-minor-mode-map
2509 ;; Put the mark meaning this part was rendered by emacs-w3m.
2510 'mm-inline-text-html-with-w3m t)))))
16409b0b
GM
2511
2512(defun article-hide-list-identifiers ()
2513 "Remove list identifies from the Subject header.
2514The `gnus-list-identifiers' variable specifies what to do."
2515 (interactive)
23f87bed
MB
2516 (let ((inhibit-point-motion-hooks t)
2517 (regexp (if (consp gnus-list-identifiers)
2518 (mapconcat 'identity gnus-list-identifiers " *\\|")
2519 gnus-list-identifiers))
2520 (inhibit-read-only t))
2521 (when regexp
2522 (save-excursion
2523 (save-restriction
2524 (article-narrow-to-head)
2525 (goto-char (point-min))
2526 (while (re-search-forward
2527 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2528 nil t)
2529 (delete-region (match-beginning 2) (match-end 0))
2530 (beginning-of-line))
2531 (when (re-search-forward
2532 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2533 (delete-region (match-beginning 1) (match-end 1))))))))
eec82323
LMI
2534
2535(defun article-hide-pem (&optional arg)
2536 "Toggle hiding of any PEM headers and signatures in the current article.
2537If given a negative prefix, always show; if given a positive prefix,
2538always hide."
2539 (interactive (gnus-article-hidden-arg))
2540 (unless (gnus-article-check-hidden-text 'pem arg)
2541 (save-excursion
23f87bed 2542 (let ((inhibit-read-only t) end)
eec82323 2543 (goto-char (point-min))
16409b0b
GM
2544 ;; Hide the horrendously ugly "header".
2545 (when (and (search-forward
2546 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2547 nil t)
2548 (setq end (1+ (match-beginning 0))))
23f87bed 2549 (gnus-add-wash-type 'pem)
16409b0b
GM
2550 (gnus-article-hide-text-type
2551 end
2552 (if (search-forward "\n\n" nil t)
2553 (match-end 0)
2554 (point-max))
2555 'pem)
2556 ;; Hide the trailer as well
2557 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2558 nil t)
2559 (gnus-article-hide-text-type
2560 (match-beginning 0) (match-end 0) 'pem)))))))
2561
2562(defun article-strip-banner ()
23f87bed
MB
2563 "Strip the banners specified by the `banner' group parameter and by
2564`gnus-article-address-banner-alist'."
16409b0b 2565 (interactive)
23f87bed
MB
2566 (save-excursion
2567 (save-restriction
2568 (let ((inhibit-point-motion-hooks t))
2569 (when (gnus-parameter-banner gnus-newsgroup-name)
2570 (article-really-strip-banner
2571 (gnus-parameter-banner gnus-newsgroup-name)))
2572 (when gnus-article-address-banner-alist
2573 (article-really-strip-banner
2574 (let ((from (save-restriction
2575 (widen)
2576 (article-narrow-to-head)
2577 (mail-fetch-field "from"))))
2578 (when (and from
2579 (setq from
2580 (caar (mail-header-parse-addresses from))))
2581 (catch 'found
2582 (dolist (pair gnus-article-address-banner-alist)
2583 (when (string-match (car pair) from)
2584 (throw 'found (cdr pair)))))))))))))
2585
2586(defun article-really-strip-banner (banner)
2587 "Strip the banner specified by the argument."
16409b0b
GM
2588 (save-excursion
2589 (save-restriction
2590 (let ((inhibit-point-motion-hooks t)
16409b0b 2591 (gnus-signature-limit nil)
23f87bed
MB
2592 (inhibit-read-only t))
2593 (article-goto-body)
2594 (cond
2595 ((eq banner 'signature)
2596 (when (gnus-article-narrow-to-signature)
2597 (widen)
2598 (forward-line -1)
2599 (delete-region (point) (point-max))))
2600 ((symbolp banner)
2601 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2602 (while (re-search-forward banner nil t)
2603 (delete-region (match-beginning 0) (match-end 0)))))
2604 ((stringp banner)
2605 (while (re-search-forward banner nil t)
2606 (delete-region (match-beginning 0) (match-end 0)))))))))
16409b0b
GM
2607
2608(defun article-babel ()
2609 "Translate article using an online translation service."
2610 (interactive)
2611 (require 'babel)
2612 (save-excursion
2613 (set-buffer gnus-article-buffer)
2614 (when (article-goto-body)
4e7d0221 2615 (let* ((inhibit-read-only t)
16409b0b
GM
2616 (start (point))
2617 (end (point-max))
2618 (orig (buffer-substring start end))
23f87bed 2619 (trans (babel-as-string orig)))
16409b0b
GM
2620 (save-restriction
2621 (narrow-to-region start end)
2622 (delete-region start end)
23f87bed 2623 (insert trans))))))
eec82323
LMI
2624
2625(defun article-hide-signature (&optional arg)
2626 "Hide the signature in the current article.
2627If given a negative prefix, always show; if given a positive prefix,
2628always hide."
2629 (interactive (gnus-article-hidden-arg))
2630 (unless (gnus-article-check-hidden-text 'signature arg)
2631 (save-excursion
2632 (save-restriction
4e7d0221 2633 (let ((inhibit-read-only t))
eec82323
LMI
2634 (when (gnus-article-narrow-to-signature)
2635 (gnus-article-hide-text-type
23f87bed
MB
2636 (point-min) (point-max) 'signature))))))
2637 (gnus-set-mode-line 'article))
eec82323 2638
16409b0b
GM
2639(defun article-strip-headers-in-body ()
2640 "Strip offensive headers from bodies."
2641 (interactive)
2642 (save-excursion
2643 (article-goto-body)
2644 (let ((case-fold-search t))
2645 (when (looking-at "x-no-archive:")
2646 (gnus-delete-line)))))
2647
eec82323
LMI
2648(defun article-strip-leading-blank-lines ()
2649 "Remove all blank lines from the beginning of the article."
2650 (interactive)
2651 (save-excursion
2652 (let ((inhibit-point-motion-hooks t)
23f87bed 2653 (inhibit-read-only t))
16409b0b 2654 (when (article-goto-body)
eec82323
LMI
2655 (while (and (not (eobp))
2656 (looking-at "[ \t]*$"))
2657 (gnus-delete-line))))))
2658
16409b0b
GM
2659(defun article-narrow-to-head ()
2660 "Narrow the buffer to the head of the message.
2661Point is left at the beginning of the narrowed-to region."
2662 (narrow-to-region
2663 (goto-char (point-min))
2664 (if (search-forward "\n\n" nil 1)
2665 (1- (point))
2666 (point-max)))
2667 (goto-char (point-min)))
2668
2669(defun article-goto-body ()
2670 "Place point at the start of the body."
2671 (goto-char (point-min))
2672 (cond
2673 ;; This variable is only bound when dealing with separate
2674 ;; MIME body parts.
2675 (article-goto-body-goes-to-point-min-p
2676 t)
2677 ((search-forward "\n\n" nil t)
2678 t)
2679 (t
2680 (goto-char (point-max))
2681 nil)))
2682
eec82323
LMI
2683(defun article-strip-multiple-blank-lines ()
2684 "Replace consecutive blank lines with one empty line."
2685 (interactive)
2686 (save-excursion
2687 (let ((inhibit-point-motion-hooks t)
23f87bed 2688 (inhibit-read-only t))
eec82323 2689 ;; First make all blank lines empty.
16409b0b 2690 (article-goto-body)
eec82323 2691 (while (re-search-forward "^[ \t]+$" nil t)
16409b0b
GM
2692 (unless (gnus-annotation-in-region-p
2693 (match-beginning 0) (match-end 0))
2694 (replace-match "" nil t)))
eec82323 2695 ;; Then replace multiple empty lines with a single empty line.
16409b0b 2696 (article-goto-body)
23f87bed 2697 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
16409b0b
GM
2698 (unless (gnus-annotation-in-region-p
2699 (match-beginning 0) (match-end 0))
23f87bed 2700 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
2701
2702(defun article-strip-leading-space ()
2703 "Remove all white space from the beginning of the lines in the article."
2704 (interactive)
2705 (save-excursion
2706 (let ((inhibit-point-motion-hooks t)
23f87bed 2707 (inhibit-read-only t))
16409b0b 2708 (article-goto-body)
eec82323
LMI
2709 (while (re-search-forward "^[ \t]+" nil t)
2710 (replace-match "" t t)))))
2711
16409b0b
GM
2712(defun article-strip-trailing-space ()
2713 "Remove all white space from the end of the lines in the article."
2714 (interactive)
2715 (save-excursion
2716 (let ((inhibit-point-motion-hooks t)
23f87bed 2717 (inhibit-read-only t))
16409b0b
GM
2718 (article-goto-body)
2719 (while (re-search-forward "[ \t]+$" nil t)
2720 (replace-match "" t t)))))
2721
eec82323
LMI
2722(defun article-strip-blank-lines ()
2723 "Strip leading, trailing and multiple blank lines."
2724 (interactive)
2725 (article-strip-leading-blank-lines)
2726 (article-remove-trailing-blank-lines)
2727 (article-strip-multiple-blank-lines))
2728
6748645f
LMI
2729(defun article-strip-all-blank-lines ()
2730 "Strip all blank lines."
2731 (interactive)
2732 (save-excursion
2733 (let ((inhibit-point-motion-hooks t)
23f87bed 2734 (inhibit-read-only t))
16409b0b 2735 (article-goto-body)
6748645f
LMI
2736 (while (re-search-forward "^[ \t]*\n" nil t)
2737 (replace-match "" t t)))))
2738
eec82323
LMI
2739(defun gnus-article-narrow-to-signature ()
2740 "Narrow to the signature; return t if a signature is found, else nil."
6748645f 2741 (let ((inhibit-point-motion-hooks t))
6748645f
LMI
2742 (when (gnus-article-search-signature)
2743 (forward-line 1)
2744 ;; Check whether we have some limits to what we consider
2745 ;; to be a signature.
2746 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2747 (list gnus-signature-limit)))
2748 limit limited)
2749 (while (setq limit (pop limits))
2750 (if (or (and (integerp limit)
2751 (< (- (point-max) (point)) limit))
2752 (and (floatp limit)
2753 (< (count-lines (point) (point-max)) limit))
23f87bed 2754 (and (functionp limit)
6748645f
LMI
2755 (funcall limit))
2756 (and (stringp limit)
2757 (not (re-search-forward limit nil t))))
2758 () ; This limit did not succeed.
2759 (setq limited t
2760 limits nil)))
2761 (unless limited
2762 (narrow-to-region (point) (point-max))
2763 t)))))
eec82323
LMI
2764
2765(defun gnus-article-search-signature ()
2766 "Search the current buffer for the signature separator.
2767Put point at the beginning of the signature separator."
2768 (let ((cur (point)))
2769 (goto-char (point-max))
2770 (if (if (stringp gnus-signature-separator)
2771 (re-search-backward gnus-signature-separator nil t)
2772 (let ((seps gnus-signature-separator))
2773 (while (and seps
2774 (not (re-search-backward (car seps) nil t)))
2775 (pop seps))
2776 seps))
2777 t
2778 (goto-char cur)
2779 nil)))
2780
eec82323
LMI
2781(defun gnus-article-hidden-arg ()
2782 "Return the current prefix arg as a number, or 0 if no prefix."
2783 (list (if current-prefix-arg
2784 (prefix-numeric-value current-prefix-arg)
2785 0)))
2786
2787(defun gnus-article-check-hidden-text (type arg)
2788 "Return nil if hiding is necessary.
f0529b5b 2789Arg can be nil or a number. nil and positive means hide, negative
eec82323
LMI
2790means show, 0 means toggle."
2791 (save-excursion
2792 (save-restriction
eec82323
LMI
2793 (let ((hide (gnus-article-hidden-text-p type)))
2794 (cond
2795 ((or (null arg)
2796 (> arg 0))
2797 nil)
2798 ((< arg 0)
4481aa98
SZ
2799 (gnus-article-show-hidden-text type)
2800 t)
eec82323
LMI
2801 (t
2802 (if (eq hide 'hidden)
4481aa98
SZ
2803 (progn
2804 (gnus-article-show-hidden-text type)
2805 t)
eec82323
LMI
2806 nil)))))))
2807
2808(defun gnus-article-hidden-text-p (type)
2809 "Say whether the current buffer contains hidden text of type TYPE."
6748645f 2810 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
eec82323 2811 (while (and pos
16409b0b
GM
2812 (not (get-text-property pos 'invisible))
2813 (not (get-text-property pos 'dummy-invisible)))
eec82323
LMI
2814 (setq pos
2815 (text-property-any (1+ pos) (point-max) 'article-type type)))
2816 (if pos
2817 'hidden
16409b0b 2818 nil)))
eec82323 2819
520aa572 2820(defun gnus-article-show-hidden-text (type &optional dummy)
eec82323 2821 "Show all hidden text of type TYPE.
520aa572 2822Originally it is hide instead of DUMMY."
4e7d0221 2823 (let ((inhibit-read-only t)
520aa572 2824 (inhibit-point-motion-hooks t))
a1506d29 2825 (gnus-remove-text-properties-when
520aa572 2826 'article-type type
a1506d29 2827 (point-min) (point-max)
520aa572 2828 (cons 'article-type (cons type
23f87bed
MB
2829 gnus-hidden-properties)))
2830 (gnus-delete-wash-type type)))
eec82323
LMI
2831
2832(defconst article-time-units
2833 `((year . ,(* 365.25 24 60 60))
2834 (week . ,(* 7 24 60 60))
2835 (day . ,(* 24 60 60))
2836 (hour . ,(* 60 60))
2837 (minute . 60)
2838 (second . 1))
2839 "Mapping from time units to seconds.")
2840
23f87bed
MB
2841(defun gnus-article-forward-header ()
2842 "Move point to the start of the next header.
2843If the current header is a continuation header, this can be several
2844lines forward."
2845 (let ((ended nil))
2846 (while (not ended)
2847 (forward-line 1)
2848 (if (looking-at "[ \t]+[^ \t]")
2849 (forward-line 1)
2850 (setq ended t)))))
2851
31640842 2852(defun article-date-ut (&optional type highlight)
eec82323
LMI
2853 "Convert DATE date to universal time in the current article.
2854If TYPE is `local', convert to local time; if it is `lapsed', output
16409b0b
GM
2855how much time has lapsed since DATE. For `lapsed', the value of
2856`gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2857should replace the \"Date:\" one, or should be added below it."
eec82323 2858 (interactive (list 'ut t))
31640842
MB
2859 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2860 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
2861 tdate-regexp)
2862 ((eq type 'lapsed)
2863 "^X-Sent:[ \t]")
2864 (article-lapsed-timer
2865 "^Date:[ \t]")
2866 (t
2867 tdate-regexp)))
2868 (case-fold-search t)
2869 (inhibit-read-only t)
eec82323 2870 (inhibit-point-motion-hooks t)
31640842 2871 pos date bface eface)
16409b0b
GM
2872 (save-excursion
2873 (save-restriction
31640842
MB
2874 (widen)
2875 (goto-char (point-min))
2876 (while (or (setq date (get-text-property (setq pos (point))
2877 'original-date))
2878 (when (setq pos (next-single-property-change
2879 (point) 'original-date))
2880 (setq date (get-text-property pos 'original-date))
2881 t))
2882 (narrow-to-region pos (or (text-property-any pos (point-max)
2883 'original-date nil)
2884 (point-max)))
16409b0b 2885 (goto-char (point-min))
31640842
MB
2886 (when (re-search-forward tdate-regexp nil t)
2887 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2888 eface (get-text-property (1- (gnus-point-at-eol)) 'face)))
2889 (goto-char (point-min))
2890 (setq pos nil)
2891 ;; Delete any old Date headers.
2892 (while (re-search-forward date-regexp nil t)
2893 (if pos
2894 (delete-region (gnus-point-at-bol)
2895 (progn
2896 (gnus-article-forward-header)
2897 (point)))
2898 (delete-region (gnus-point-at-bol)
2899 (progn
2900 (gnus-article-forward-header)
2901 (forward-char -1)
2902 (point)))
2903 (setq pos (point))))
2904 (when (and (not pos)
2905 (re-search-forward tdate-regexp nil t))
2906 (forward-line 1))
2907 (gnus-goto-char pos)
2908 (insert (article-make-date-line date (or type 'ut)))
2909 (unless pos
2910 (insert "\n")
2911 (forward-line -1))
2912 ;; Do highlighting.
2913 (beginning-of-line)
2914 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2915 (put-text-property (match-beginning 1) (1+ (match-end 1))
2916 'face bface)
2917 (put-text-property (match-beginning 2) (match-end 2)
2918 'face eface))
2919 (put-text-property (point-min) (1- (point-max)) 'original-date date)
2920 (goto-char (point-max))
2921 (widen))))))
eec82323
LMI
2922
2923(defun article-make-date-line (date type)
2924 "Return a DATE line of TYPE."
23f87bed
MB
2925 (unless (memq type '(local ut original user iso8601 lapsed english))
2926 (error "Unknown conversion type: %s" type))
2927 (condition-case ()
2928 (let ((time (date-to-time date)))
16409b0b 2929 (cond
23f87bed
MB
2930 ;; Convert to the local timezone.
2931 ((eq type 'local)
2932 (let ((tz (car (current-time-zone time))))
2933 (format "Date: %s %s%02d%02d" (current-time-string time)
2934 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2935 (/ (% (abs tz) 3600) 60))))
2936 ;; Convert to Universal Time.
2937 ((eq type 'ut)
2938 (concat "Date: "
2939 (current-time-string
2940 (let* ((e (parse-time-string date))
2941 (tm (apply 'encode-time e))
2942 (ms (car tm))
2943 (ls (- (cadr tm) (car (current-time-zone time)))))
2944 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2945 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2946 (t (list ms ls)))))
2947 " UT"))
2948 ;; Get the original date from the article.
2949 ((eq type 'original)
2950 (concat "Date: " (if (string-match "\n+$" date)
2951 (substring date 0 (match-beginning 0))
2952 date)))
2953 ;; Let the user define the format.
2954 ((eq type 'user)
2955 (let ((format (or (condition-case nil
2956 (with-current-buffer gnus-summary-buffer
2957 gnus-article-time-format)
2958 (error nil))
2959 gnus-article-time-format)))
2960 (if (functionp format)
2961 (funcall format time)
2962 (concat "Date: " (format-time-string format time)))))
2963 ;; ISO 8601.
2964 ((eq type 'iso8601)
2965 (let ((tz (car (current-time-zone time))))
2966 (concat
2967 "Date: "
2968 (format-time-string "%Y%m%dT%H%M%S" time)
2969 (format "%s%02d%02d"
2970 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2971 (/ (% (abs tz) 3600) 60)))))
2972 ;; Do an X-Sent lapsed format.
2973 ((eq type 'lapsed)
2974 ;; If the date is seriously mangled, the timezone functions are
2975 ;; liable to bug out, so we ignore all errors.
2976 (let* ((now (current-time))
2977 (real-time (subtract-time now time))
2978 (real-sec (and real-time
2979 (+ (* (float (car real-time)) 65536)
2980 (cadr real-time))))
2981 (sec (and real-time (abs real-sec)))
2982 num prev)
2983 (cond
2984 ((null real-time)
2985 "X-Sent: Unknown")
2986 ((zerop sec)
2987 "X-Sent: Now")
2988 (t
2989 (concat
2990 "X-Sent: "
2991 ;; This is a bit convoluted, but basically we go
2992 ;; through the time units for years, weeks, etc,
2993 ;; and divide things to see whether that results
2994 ;; in positive answers.
2995 (mapconcat
2996 (lambda (unit)
2997 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2998 ;; The (remaining) seconds are too few to
2999 ;; be divided into this time unit.
3000 ""
3001 ;; It's big enough, so we output it.
3002 (setq sec (- sec (* num (cdr unit))))
3003 (prog1
3004 (concat (if prev ", " "") (int-to-string
3005 (floor num))
3006 " " (symbol-name (car unit))
3007 (if (> num 1) "s" ""))
3008 (setq prev t))))
3009 article-time-units "")
3010 ;; If dates are odd, then it might appear like the
3011 ;; article was sent in the future.
3012 (if (> real-sec 0)
3013 " ago"
3014 " in the future"))))))
3015 ;; Display the date in proper English
3016 ((eq type 'english)
3017 (let ((dtime (decode-time time)))
3018 (concat
3019 "Date: the "
3020 (number-to-string (nth 3 dtime))
3021 (let ((digit (% (nth 3 dtime) 10)))
3022 (cond
3023 ((memq (nth 3 dtime) '(11 12 13)) "th")
3024 ((= digit 1) "st")
3025 ((= digit 2) "nd")
3026 ((= digit 3) "rd")
3027 (t "th")))
3028 " of "
3029 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3030 " "
3031 (number-to-string (nth 5 dtime))
3032 " at "
3033 (format "%02d" (nth 2 dtime))
3034 ":"
3035 (format "%02d" (nth 1 dtime)))))))
3036 (error
3037 (format "Date: %s (from Gnus)" date))))
eec82323
LMI
3038
3039(defun article-date-local (&optional highlight)
3040 "Convert the current article date to the local timezone."
3041 (interactive (list t))
3042 (article-date-ut 'local highlight))
3043
23f87bed
MB
3044(defun article-date-english (&optional highlight)
3045 "Convert the current article date to something that is proper English."
3046 (interactive (list t))
3047 (article-date-ut 'english highlight))
3048
eec82323
LMI
3049(defun article-date-original (&optional highlight)
3050 "Convert the current article date to what it was originally.
3051This is only useful if you have used some other date conversion
3052function and want to see what the date was before converting."
3053 (interactive (list t))
3054 (article-date-ut 'original highlight))
3055
3056(defun article-date-lapsed (&optional highlight)
3057 "Convert the current article date to time lapsed since it was sent."
3058 (interactive (list t))
3059 (article-date-ut 'lapsed highlight))
3060
6748645f
LMI
3061(defun article-update-date-lapsed ()
3062 "Function to be run from a timer to update the lapsed time line."
e0a8aa09
LT
3063 (save-match-data
3064 (let (deactivate-mark)
3065 (save-excursion
3066 (ignore-errors
3067 (walk-windows
3068 (lambda (w)
3069 (set-buffer (window-buffer w))
3070 (when (eq major-mode 'gnus-article-mode)
3071 (let ((mark (point-marker)))
3072 (goto-char (point-min))
3073 (when (re-search-forward "^X-Sent:" nil t)
3074 (article-date-lapsed t))
3075 (goto-char (marker-position mark))
3076 (move-marker mark nil))))
3077 nil 'visible))))))
6748645f
LMI
3078
3079(defun gnus-start-date-timer (&optional n)
3080 "Start a timer to update the X-Sent header in the article buffers.
3081The numerical prefix says how frequently (in seconds) the function
3082is to run."
3083 (interactive "p")
3084 (unless n
3085 (setq n 1))
3086 (gnus-stop-date-timer)
3087 (setq article-lapsed-timer
3088 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
3089
3090(defun gnus-stop-date-timer ()
3091 "Stop the X-Sent timer."
3092 (interactive)
3093 (when article-lapsed-timer
3094 (nnheader-cancel-timer article-lapsed-timer)
3095 (setq article-lapsed-timer nil)))
3096
eec82323
LMI
3097(defun article-date-user (&optional highlight)
3098 "Convert the current article date to the user-defined format.
3099This format is defined by the `gnus-article-time-format' variable."
3100 (interactive (list t))
3101 (article-date-ut 'user highlight))
3102
6748645f
LMI
3103(defun article-date-iso8601 (&optional highlight)
3104 "Convert the current article date to ISO8601."
3105 (interactive (list t))
3106 (article-date-ut 'iso8601 highlight))
3107
31640842
MB
3108(defmacro gnus-article-save-original-date (&rest forms)
3109 "Save the original date as a text property and evaluate FORMS."
3110 `(let* ((case-fold-search t)
3111 (start (progn
3112 (goto-char (point-min))
3113 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3114 (not (bolp)))
3115 (match-end 0))))
3116 (date (when (and start
3117 (re-search-forward "[\t ]*\n\\([^\t ]\\|\\'\\)"
3118 nil t))
3119 (buffer-substring-no-properties start
3120 (match-beginning 0)))))
3121 (goto-char (point-max))
3122 (skip-chars-backward "\n")
3123 (put-text-property (point-min) (point) 'original-date date)
3124 ,@forms
3125 (goto-char (point-max))
3126 (skip-chars-backward "\n")
3127 (put-text-property (point-min) (point) 'original-date date)))
3128
23f87bed
MB
3129;; (defun article-show-all ()
3130;; "Show all hidden text in the article buffer."
3131;; (interactive)
3132;; (save-excursion
3133;; (let ((inhibit-read-only t))
3134;; (gnus-article-unhide-text (point-min) (point-max)))))
3135
3136(defun article-remove-leading-whitespace ()
3137 "Remove excessive whitespace from all headers."
eec82323
LMI
3138 (interactive)
3139 (save-excursion
23f87bed
MB
3140 (save-restriction
3141 (let ((inhibit-read-only t))
3142 (article-narrow-to-head)
3143 (goto-char (point-min))
3144 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3145 (delete-region (match-beginning 1) (match-end 1)))))))
eec82323
LMI
3146
3147(defun article-emphasize (&optional arg)
3148 "Emphasize text according to `gnus-emphasis-alist'."
3149 (interactive (gnus-article-hidden-arg))
3150 (unless (gnus-article-check-hidden-text 'emphasis arg)
3151 (save-excursion
a1506d29 3152 (let ((alist (or
16409b0b 3153 (condition-case nil
a1506d29
JB
3154 (with-current-buffer gnus-summary-buffer
3155 gnus-article-emphasis-alist)
16409b0b
GM
3156 (error))
3157 gnus-emphasis-alist))
4e7d0221 3158 (inhibit-read-only t)
eec82323
LMI
3159 (props (append '(article-type emphasis)
3160 gnus-hidden-properties))
3161 regexp elem beg invisible visible face)
16409b0b 3162 (article-goto-body)
eec82323
LMI
3163 (setq beg (point))
3164 (while (setq elem (pop alist))
3165 (goto-char beg)
3166 (setq regexp (car elem)
3167 invisible (nth 1 elem)
3168 visible (nth 2 elem)
3169 face (nth 3 elem))
3170 (while (re-search-forward regexp nil t)
23f87bed
MB
3171 (when (and (match-beginning visible) (match-beginning invisible))
3172 (gnus-article-hide-text
3173 (match-beginning invisible) (match-end invisible) props)
3174 (gnus-article-unhide-text-type
3175 (match-beginning visible) (match-end visible) 'emphasis)
3176 (gnus-put-overlay-excluding-newlines
3177 (match-beginning visible) (match-end visible) 'face face)
3178 (gnus-add-wash-type 'emphasis)
3179 (goto-char (match-end invisible)))))))))
eec82323 3180
16409b0b
GM
3181(defun gnus-article-setup-highlight-words (&optional highlight-words)
3182 "Setup newsgroup emphasis alist."
3183 (unless gnus-article-emphasis-alist
3184 (let ((name (and gnus-newsgroup-name
3185 (gnus-group-real-name gnus-newsgroup-name))))
3186 (make-local-variable 'gnus-article-emphasis-alist)
a1506d29
JB
3187 (setq gnus-article-emphasis-alist
3188 (nconc
16409b0b
GM
3189 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3190 (while (setq elem (pop alist))
3191 (when (and name (string-match (car elem) name))
3192 (setq alist nil
3193 highlight (copy-sequence (cdr elem)))))
3194 highlight)
3195 (copy-sequence highlight-words)
3196 (if gnus-newsgroup-name
a1506d29 3197 (copy-sequence (gnus-group-find-parameter
16409b0b
GM
3198 gnus-newsgroup-name 'highlight-words t)))
3199 gnus-emphasis-alist)))))
3200
1653df0f
SZ
3201(eval-when-compile
3202 (defvar gnus-summary-article-menu)
3203 (defvar gnus-summary-post-menu))
eec82323
LMI
3204
3205;;; Saving functions.
3206
3207(defun gnus-article-save (save-buffer file &optional num)
3208 "Save the currently selected article."
3209 (unless gnus-save-all-headers
3210 ;; Remove headers according to `gnus-saved-headers'.
3211 (let ((gnus-visible-headers
3212 (or gnus-saved-headers gnus-visible-headers))
3213 (gnus-article-buffer save-buffer))
6748645f
LMI
3214 (save-excursion
3215 (set-buffer save-buffer)
3216 (article-hide-headers 1 t))))
eec82323
LMI
3217 (save-window-excursion
3218 (if (not gnus-default-article-saver)
a8151ef7 3219 (error "No default saver is defined")
eec82323 3220 ;; !!! Magic! The saving functions all save
16409b0b 3221 ;; `gnus-save-article-buffer' (or so they think), but we
eec82323
LMI
3222 ;; bind that variable to our save-buffer.
3223 (set-buffer gnus-article-buffer)
3224 (let* ((gnus-save-article-buffer save-buffer)
3225 (filename
3226 (cond
3227 ((not gnus-prompt-before-saving) 'default)
3228 ((eq gnus-prompt-before-saving 'always) nil)
3229 (t file)))
3230 (gnus-number-of-articles-to-be-saved
3231 (when (eq gnus-prompt-before-saving t)
3232 num))) ; Magic
6748645f 3233 (set-buffer gnus-article-current-summary)
eec82323
LMI
3234 (funcall gnus-default-article-saver filename)))))
3235
3236(defun gnus-read-save-file-name (prompt &optional filename
3237 function group headers variable)
3238 (let ((default-name
3239 (funcall function group headers (symbol-value variable)))
3240 result)
4325195c 3241 (setq result
a1506d29 3242 (expand-file-name
4325195c
DL
3243 (cond
3244 ((eq filename 'default)
3245 default-name)
3246 ((eq filename t)
3247 default-name)
3248 (filename filename)
3249 (t
3250 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3251 (prompt
3252 (format prompt
3253 (if (and gnus-number-of-articles-to-be-saved
3254 (> gnus-number-of-articles-to-be-saved 1))
3255 (format "these %d articles"
3256 gnus-number-of-articles-to-be-saved)
3257 "this article")))
3258 (file
3259 ;; Let the split methods have their say.
3260 (cond
3261 ;; No split name was found.
3262 ((null split-name)
3263 (read-file-name
3264 (concat prompt " (default "
81df110a 3265 (file-name-nondirectory default-name) "): ")
4325195c
DL
3266 (file-name-directory default-name)
3267 default-name))
3268 ;; A single group name is returned.
3269 ((stringp split-name)
3270 (setq default-name
3271 (funcall function split-name headers
3272 (symbol-value variable)))
3273 (read-file-name
3274 (concat prompt " (default "
81df110a 3275 (file-name-nondirectory default-name) "): ")
4325195c
DL
3276 (file-name-directory default-name)
3277 default-name))
3278 ;; A single split name was found
3279 ((= 1 (length split-name))
3280 (let* ((name (expand-file-name
23f87bed
MB
3281 (car split-name)
3282 gnus-article-save-directory))
4325195c
DL
3283 (dir (cond ((file-directory-p name)
3284 (file-name-as-directory name))
3285 ((file-exists-p name) name)
3286 (t gnus-article-save-directory))))
3287 (read-file-name
81df110a 3288 (concat prompt " (default " name "): ")
4325195c
DL
3289 dir name)))
3290 ;; A list of splits was found.
3291 (t
3292 (setq split-name (nreverse split-name))
3293 (let (result)
3294 (let ((file-name-history
3295 (nconc split-name file-name-history)))
3296 (setq result
3297 (expand-file-name
3298 (read-file-name
81df110a 3299 (concat prompt " (`M-p' for defaults): ")
4325195c
DL
3300 gnus-article-save-directory
3301 (car split-name))
3302 gnus-article-save-directory)))
3303 (car (push result file-name-history)))))))
3304 ;; Create the directory.
3305 (gnus-make-directory (file-name-directory file))
23f87bed 3306 ;; If we have read a directory, we append the default file name.
4325195c 3307 (when (file-directory-p file)
23f87bed
MB
3308 (setq file (expand-file-name (file-name-nondirectory
3309 default-name)
4325195c
DL
3310 (file-name-as-directory file))))
3311 ;; Possibly translate some characters.
3312 (nnheader-translate-file-chars file))))))
eec82323
LMI
3313 (gnus-make-directory (file-name-directory result))
3314 (set variable result)))
3315
3316(defun gnus-article-archive-name (group)
3317 "Return the first instance of an \"Archive-name\" in the current buffer."
3318 (let ((case-fold-search t))
3319 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3320 (nnheader-concat gnus-article-save-directory
3321 (match-string 1)))))
3322
3323(defun gnus-article-nndoc-name (group)
3324 "If GROUP is an nndoc group, return the name of the parent group."
3325 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3326 (gnus-group-get-parameter group 'save-article-group)))
3327
3328(defun gnus-summary-save-in-rmail (&optional filename)
3329 "Append this article to Rmail file.
3330Optional argument FILENAME specifies file name.
3331Directory to save to is default to `gnus-article-save-directory'."
eec82323 3332 (setq filename (gnus-read-save-file-name
81df110a 3333 "Save %s in rmail file" filename
eec82323
LMI
3334 gnus-rmail-save-name gnus-newsgroup-name
3335 gnus-current-headers 'gnus-newsgroup-last-rmail))
3336 (gnus-eval-in-buffer-window gnus-save-article-buffer
3337 (save-excursion
3338 (save-restriction
3339 (widen)
6748645f
LMI
3340 (gnus-output-to-rmail filename))))
3341 filename)
eec82323
LMI
3342
3343(defun gnus-summary-save-in-mail (&optional filename)
3344 "Append this article to Unix mail file.
3345Optional argument FILENAME specifies file name.
3346Directory to save to is default to `gnus-article-save-directory'."
eec82323 3347 (setq filename (gnus-read-save-file-name
81df110a 3348 "Save %s in Unix mail file" filename
eec82323
LMI
3349 gnus-mail-save-name gnus-newsgroup-name
3350 gnus-current-headers 'gnus-newsgroup-last-mail))
3351 (gnus-eval-in-buffer-window gnus-save-article-buffer
3352 (save-excursion
3353 (save-restriction
3354 (widen)
3355 (if (and (file-readable-p filename)
23f87bed 3356 (file-regular-p filename)
eec82323 3357 (mail-file-babyl-p filename))
16409b0b 3358 (rmail-output-to-rmail-file filename t)
6748645f
LMI
3359 (gnus-output-to-mail filename)))))
3360 filename)
eec82323
LMI
3361
3362(defun gnus-summary-save-in-file (&optional filename overwrite)
3363 "Append this article to file.
3364Optional argument FILENAME specifies file name.
3365Directory to save to is default to `gnus-article-save-directory'."
eec82323 3366 (setq filename (gnus-read-save-file-name
81df110a 3367 "Save %s in file" filename
eec82323
LMI
3368 gnus-file-save-name gnus-newsgroup-name
3369 gnus-current-headers 'gnus-newsgroup-last-file))
3370 (gnus-eval-in-buffer-window gnus-save-article-buffer
3371 (save-excursion
3372 (save-restriction
3373 (widen)
3374 (when (and overwrite
3375 (file-exists-p filename))
3376 (delete-file filename))
6748645f
LMI
3377 (gnus-output-to-file filename))))
3378 filename)
eec82323
LMI
3379
3380(defun gnus-summary-write-to-file (&optional filename)
23f87bed 3381 "Write this article to a file, overwriting it if the file exists.
eec82323
LMI
3382Optional argument FILENAME specifies file name.
3383The directory to save in defaults to `gnus-article-save-directory'."
eec82323
LMI
3384 (gnus-summary-save-in-file nil t))
3385
3386(defun gnus-summary-save-body-in-file (&optional filename)
3387 "Append this article body to a file.
3388Optional argument FILENAME specifies file name.
3389The directory to save in defaults to `gnus-article-save-directory'."
eec82323 3390 (setq filename (gnus-read-save-file-name
81df110a 3391 "Save %s body in file" filename
eec82323
LMI
3392 gnus-file-save-name gnus-newsgroup-name
3393 gnus-current-headers 'gnus-newsgroup-last-file))
3394 (gnus-eval-in-buffer-window gnus-save-article-buffer
3395 (save-excursion
3396 (save-restriction
3397 (widen)
16409b0b 3398 (when (article-goto-body)
eec82323 3399 (narrow-to-region (point) (point-max)))
6748645f
LMI
3400 (gnus-output-to-file filename))))
3401 filename)
eec82323
LMI
3402
3403(defun gnus-summary-save-in-pipe (&optional command)
3404 "Pipe this article to subprocess."
eec82323 3405 (setq command
16409b0b
GM
3406 (cond ((and (eq command 'default)
3407 gnus-last-shell-command)
eec82323 3408 gnus-last-shell-command)
676a7cc9
SZ
3409 ((stringp command)
3410 command)
eec82323
LMI
3411 (t (read-string
3412 (format
3413 "Shell command on %s: "
3414 (if (and gnus-number-of-articles-to-be-saved
3415 (> gnus-number-of-articles-to-be-saved 1))
3416 (format "these %d articles"
3417 gnus-number-of-articles-to-be-saved)
3418 "this article"))
3419 gnus-last-shell-command))))
3420 (when (string-equal command "")
676a7cc9
SZ
3421 (if gnus-last-shell-command
3422 (setq command gnus-last-shell-command)
715a2ca2 3423 (error "A command is required")))
eec82323
LMI
3424 (gnus-eval-in-buffer-window gnus-article-buffer
3425 (save-restriction
3426 (widen)
3427 (shell-command-on-region (point-min) (point-max) command nil)))
3428 (setq gnus-last-shell-command command))
3429
23f87bed
MB
3430(defmacro gnus-read-string (prompt &optional initial-contents history
3431 default-value)
3432 "Like `read-string' but allow for older XEmacsen that don't have the 5th arg."
3433 (if (and (featurep 'xemacs)
3434 (< emacs-minor-version 2))
3435 `(read-string ,prompt ,initial-contents ,history)
3436 `(read-string ,prompt ,initial-contents ,history ,default-value)))
3437
3438(defun gnus-summary-pipe-to-muttprint (&optional command)
3439 "Pipe this article to muttprint."
3440 (setq command (gnus-read-string
3441 "Print using command: " gnus-summary-muttprint-program
3442 nil gnus-summary-muttprint-program))
3443 (gnus-summary-save-in-pipe command))
3444
eec82323
LMI
3445;;; Article file names when saving.
3446
3447(defun gnus-capitalize-newsgroup (newsgroup)
3448 "Capitalize NEWSGROUP name."
3449 (when (not (zerop (length newsgroup)))
3450 (concat (char-to-string (upcase (aref newsgroup 0)))
3451 (substring newsgroup 1))))
3452
3453(defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3454 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3455If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3456Otherwise, it is like ~/News/news/group/num."
3457 (let ((default
3458 (expand-file-name
3459 (concat (if (gnus-use-long-file-name 'not-save)
3460 (gnus-capitalize-newsgroup newsgroup)
3461 (gnus-newsgroup-directory-form newsgroup))
3462 "/" (int-to-string (mail-header-number headers)))
3463 gnus-article-save-directory)))
3464 (if (and last-file
3465 (string-equal (file-name-directory default)
3466 (file-name-directory last-file))
3467 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3468 default
3469 (or last-file default))))
3470
3471(defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3472 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3473If variable `gnus-use-long-file-name' is non-nil, it is
3474~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3475 (let ((default
3476 (expand-file-name
3477 (concat (if (gnus-use-long-file-name 'not-save)
3478 newsgroup
3479 (gnus-newsgroup-directory-form newsgroup))
3480 "/" (int-to-string (mail-header-number headers)))
3481 gnus-article-save-directory)))
3482 (if (and last-file
3483 (string-equal (file-name-directory default)
3484 (file-name-directory last-file))
3485 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3486 default
3487 (or last-file default))))
3488
eec82323
LMI
3489(defun gnus-plain-save-name (newsgroup headers &optional last-file)
3490 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3491If variable `gnus-use-long-file-name' is non-nil, it is
3492~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3493 (or last-file
3494 (expand-file-name
3495 (if (gnus-use-long-file-name 'not-save)
3496 newsgroup
23f87bed
MB
3497 (file-relative-name
3498 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3499 default-directory))
eec82323
LMI
3500 gnus-article-save-directory)))
3501
23f87bed
MB
3502(defun gnus-sender-save-name (newsgroup headers &optional last-file)
3503 "Generate file name from sender."
3504 (let ((from (mail-header-from headers)))
3505 (expand-file-name
3506 (if (and from (string-match "\\([^ <]+\\)@" from))
3507 (match-string 1 from)
3508 "nobody")
3509 gnus-article-save-directory)))
3510
3511(defun article-verify-x-pgp-sig ()
3512 "Verify X-PGP-Sig."
3513 (interactive)
3514 (if (gnus-buffer-live-p gnus-original-article-buffer)
3515 (let ((sig (with-current-buffer gnus-original-article-buffer
3516 (gnus-fetch-field "X-PGP-Sig")))
3517 items info headers)
3518 (when (and sig
3519 mml2015-use
3520 (mml2015-clear-verify-function))
3521 (with-temp-buffer
3522 (insert-buffer-substring gnus-original-article-buffer)
3523 (setq items (split-string sig))
3524 (message-narrow-to-head)
3525 (let ((inhibit-point-motion-hooks t)
3526 (case-fold-search t))
3527 ;; Don't verify multiple headers.
3528 (setq headers (mapconcat (lambda (header)
3529 (concat header ": "
3530 (mail-fetch-field header)
3531 "\n"))
3532 (split-string (nth 1 items) ",") "")))
3533 (delete-region (point-min) (point-max))
3534 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3535 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3536 (insert headers)
3537 (widen)
3538 (forward-line)
3539 (while (not (eobp))
3540 (if (looking-at "^-")
3541 (insert "- "))
3542 (forward-line))
3543 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3544 (insert "Version: " (car items) "\n\n")
3545 (insert (mapconcat 'identity (cddr items) "\n"))
3546 (insert "\n-----END PGP SIGNATURE-----\n")
3547 (let ((mm-security-handle (list (format "multipart/signed"))))
3548 (mml2015-clean-buffer)
3549 (let ((coding-system-for-write (or gnus-newsgroup-charset
3550 'iso-8859-1)))
3551 (funcall (mml2015-clear-verify-function)))
3552 (setq info
3553 (or (mm-handle-multipart-ctl-parameter
3554 mm-security-handle 'gnus-details)
3555 (mm-handle-multipart-ctl-parameter
3556 mm-security-handle 'gnus-info)))))
3557 (when info
3558 (let ((inhibit-read-only t) bface eface)
3559 (save-restriction
3560 (message-narrow-to-head)
3561 (goto-char (point-max))
3562 (forward-line -1)
3563 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3564 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3565 (message-remove-header "X-Gnus-PGP-Verify")
3566 (if (re-search-forward "^X-PGP-Sig:" nil t)
3567 (forward-line)
3568 (goto-char (point-max)))
3569 (narrow-to-region (point) (point))
3570 (insert "X-Gnus-PGP-Verify: " info "\n")
3571 (goto-char (point-min))
3572 (forward-line)
3573 (while (not (eobp))
3574 (if (not (looking-at "^[ \t]"))
3575 (insert " "))
3576 (forward-line))
3577 ;; Do highlighting.
3578 (goto-char (point-min))
3579 (when (looking-at "\\([^:]+\\): *")
3580 (put-text-property (match-beginning 1) (1+ (match-end 1))
3581 'face bface)
3582 (put-text-property (match-end 0) (point-max)
3583 'face eface)))))))))
3584
3585(defun article-verify-cancel-lock ()
3586 "Verify Cancel-Lock header."
3587 (interactive)
3588 (if (gnus-buffer-live-p gnus-original-article-buffer)
3589 (canlock-verify gnus-original-article-buffer)))
3590
eec82323
LMI
3591(eval-and-compile
3592 (mapcar
3593 (lambda (func)
3594 (let (afunc gfunc)
3595 (if (consp func)
3596 (setq afunc (car func)
3597 gfunc (cdr func))
3598 (setq afunc func
3599 gfunc (intern (format "gnus-%s" func))))
16409b0b 3600 (defalias gfunc
23f87bed 3601 (when (fboundp afunc)
16409b0b
GM
3602 `(lambda (&optional interactive &rest args)
3603 ,(documentation afunc t)
3604 (interactive (list t))
3605 (save-excursion
3606 (set-buffer gnus-article-buffer)
3607 (if interactive
3608 (call-interactively ',afunc)
3609 (apply ',afunc args))))))))
eec82323 3610 '(article-hide-headers
23f87bed
MB
3611 article-verify-x-pgp-sig
3612 article-verify-cancel-lock
eec82323
LMI
3613 article-hide-boring-headers
3614 article-treat-overstrike
16409b0b
GM
3615 article-fill-long-lines
3616 article-capitalize-sentences
eec82323 3617 article-remove-cr
23f87bed 3618 article-remove-leading-whitespace
eec82323 3619 article-display-x-face
23f87bed 3620 article-display-face
eec82323 3621 article-de-quoted-unreadable
16409b0b
GM
3622 article-de-base64-unreadable
3623 article-decode-HZ
3624 article-wash-html
23f87bed 3625 article-unsplit-urls
16409b0b 3626 article-hide-list-identifiers
16409b0b
GM
3627 article-strip-banner
3628 article-babel
eec82323
LMI
3629 article-hide-pem
3630 article-hide-signature
16409b0b 3631 article-strip-headers-in-body
eec82323
LMI
3632 article-remove-trailing-blank-lines
3633 article-strip-leading-blank-lines
3634 article-strip-multiple-blank-lines
3635 article-strip-leading-space
16409b0b 3636 article-strip-trailing-space
eec82323 3637 article-strip-blank-lines
6748645f 3638 article-strip-all-blank-lines
eec82323 3639 article-date-local
23f87bed 3640 article-date-english
6748645f 3641 article-date-iso8601
eec82323
LMI
3642 article-date-original
3643 article-date-ut
16409b0b
GM
3644 article-decode-mime-words
3645 article-decode-charset
3646 article-decode-encoded-words
eec82323
LMI
3647 article-date-user
3648 article-date-lapsed
3649 article-emphasize
6748645f 3650 article-treat-dumbquotes
16409b0b 3651 article-normalize-headers
23f87bed
MB
3652;; (article-show-all . gnus-article-show-all-headers)
3653 )))
eec82323
LMI
3654\f
3655;;;
3656;;; Gnus article mode
3657;;;
3658
3659(put 'gnus-article-mode 'mode-class 'special)
3660
16409b0b
GM
3661(set-keymap-parent gnus-article-mode-map widget-keymap)
3662
a8151ef7
LMI
3663(gnus-define-keys gnus-article-mode-map
3664 " " gnus-article-goto-next-page
3665 "\177" gnus-article-goto-prev-page
3666 [delete] gnus-article-goto-prev-page
16409b0b 3667 [backspace] gnus-article-goto-prev-page
a8151ef7
LMI
3668 "\C-c^" gnus-article-refer-article
3669 "h" gnus-article-show-summary
3670 "s" gnus-article-show-summary
3671 "\C-c\C-m" gnus-article-mail
3672 "?" gnus-article-describe-briefly
16409b0b 3673 "e" gnus-summary-edit-article
a8151ef7
LMI
3674 "<" beginning-of-buffer
3675 ">" end-of-buffer
3676 "\C-c\C-i" gnus-info-find-node
3677 "\C-c\C-b" gnus-bug
23f87bed
MB
3678 "R" gnus-article-reply-with-original
3679 "F" gnus-article-followup-with-original
520aa572
SZ
3680 "\C-hk" gnus-article-describe-key
3681 "\C-hc" gnus-article-describe-key-briefly
a8151ef7
LMI
3682
3683 "\C-d" gnus-article-read-summary-keys
3684 "\M-*" gnus-article-read-summary-keys
3685 "\M-#" gnus-article-read-summary-keys
3686 "\M-^" gnus-article-read-summary-keys
3687 "\M-g" gnus-article-read-summary-keys)
3688
3689(substitute-key-definition
3690 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
eec82323
LMI
3691
3692(defun gnus-article-make-menu-bar ()
23f87bed
MB
3693 (unless (boundp 'gnus-article-commands-menu)
3694 (gnus-summary-make-menu-bar))
eec82323
LMI
3695 (gnus-turn-off-edit-menu 'article)
3696 (unless (boundp 'gnus-article-article-menu)
3697 (easy-menu-define
3698 gnus-article-article-menu gnus-article-mode-map ""
3699 '("Article"
3700 ["Scroll forwards" gnus-article-goto-next-page t]
3701 ["Scroll backwards" gnus-article-goto-prev-page t]
3702 ["Show summary" gnus-article-show-summary t]
3703 ["Fetch Message-ID at point" gnus-article-refer-article t]
6748645f
LMI
3704 ["Mail to address at point" gnus-article-mail t]
3705 ["Send a bug report" gnus-bug t]))
eec82323
LMI
3706
3707 (easy-menu-define
3708 gnus-article-treatment-menu gnus-article-mode-map ""
bb367cba 3709 ;; Fixme: this should use :active (and maybe :visible).
eec82323
LMI
3710 '("Treatment"
3711 ["Hide headers" gnus-article-hide-headers t]
3712 ["Hide signature" gnus-article-hide-signature t]
3713 ["Hide citation" gnus-article-hide-citation t]
3714 ["Treat overstrike" gnus-article-treat-overstrike t]
3715 ["Remove carriage return" gnus-article-remove-cr t]
23f87bed 3716 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
16409b0b
GM
3717 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3718 ["Remove base64" gnus-article-de-base64-unreadable t]
3719 ["Treat html" gnus-article-wash-html t]
23f87bed 3720 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
16409b0b 3721 ["Decode HZ" gnus-article-decode-HZ t]))
eec82323 3722
6748645f 3723 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
eec82323 3724
23f87bed 3725 ;; Note "Post" menu is defined in gnus-sum.el for consistency
eec82323 3726
6748645f 3727 (gnus-run-hooks 'gnus-article-menu-hook)))
eec82323
LMI
3728
3729(defun gnus-article-mode ()
3730 "Major mode for displaying an article.
3731
3732All normal editing commands are switched off.
3733
3734The following commands are available in addition to all summary mode
3735commands:
3736\\<gnus-article-mode-map>
3737\\[gnus-article-next-page]\t Scroll the article one page forwards
3738\\[gnus-article-prev-page]\t Scroll the article one page backwards
3739\\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3740\\[gnus-article-show-summary]\t Display the summary buffer
3741\\[gnus-article-mail]\t Send a reply to the address near point
3742\\[gnus-article-describe-briefly]\t Describe the current mode briefly
3743\\[gnus-info-find-node]\t Go to the Gnus info node"
3744 (interactive)
0eb586fc 3745 (kill-all-local-variables)
eec82323
LMI
3746 (gnus-simplify-mode-line)
3747 (setq mode-name "Article")
3748 (setq major-mode 'gnus-article-mode)
3749 (make-local-variable 'minor-mode-alist)
eec82323 3750 (use-local-map gnus-article-mode-map)
1653df0f 3751 (when (gnus-visual-p 'article-menu 'menu)
23f87bed
MB
3752 (gnus-article-make-menu-bar)
3753 (when gnus-summary-tool-bar-map
3754 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
eec82323
LMI
3755 (gnus-update-format-specifications nil 'article-mode)
3756 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
23f87bed 3757 (set (make-local-variable 'gnus-page-broken) nil)
6748645f
LMI
3758 (make-local-variable 'gnus-button-marker-list)
3759 (make-local-variable 'gnus-article-current-summary)
16409b0b
GM
3760 (make-local-variable 'gnus-article-mime-handles)
3761 (make-local-variable 'gnus-article-decoded-p)
3762 (make-local-variable 'gnus-article-mime-handle-alist)
3763 (make-local-variable 'gnus-article-wash-types)
23f87bed
MB
3764 (make-local-variable 'gnus-article-image-alist)
3765 (make-local-variable 'gnus-article-charset)
3766 (make-local-variable 'gnus-article-ignored-charsets)
f429956a 3767 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
fc1c32c1 3768 (set (make-local-variable 'nobreak-char-display) nil)
eec82323 3769 (gnus-set-default-directory)
16409b0b 3770 (buffer-disable-undo)
eec82323
LMI
3771 (setq buffer-read-only t)
3772 (set-syntax-table gnus-article-mode-syntax-table)
16409b0b 3773 (mm-enable-multibyte)
cfcd5c91 3774 (gnus-run-mode-hooks 'gnus-article-mode-hook))
eec82323
LMI
3775
3776(defun gnus-article-setup-buffer ()
3777 "Initialize the article buffer."
3778 (let* ((name (if gnus-single-article-buffer "*Article*"
3779 (concat "*Article " gnus-newsgroup-name "*")))
3780 (original
3781 (progn (string-match "\\*Article" name)
3782 (concat " *Original Article"
3783 (substring name (match-end 0))))))
3784 (setq gnus-article-buffer name)
3785 (setq gnus-original-article-buffer original)
16409b0b 3786 (setq gnus-article-mime-handle-alist nil)
eec82323
LMI
3787 ;; This might be a variable local to the summary buffer.
3788 (unless gnus-single-article-buffer
3789 (save-excursion
3790 (set-buffer gnus-summary-buffer)
3791 (setq gnus-article-buffer name)
3792 (setq gnus-original-article-buffer original)
3793 (gnus-set-global-variables)))
16409b0b 3794 (gnus-article-setup-highlight-words)
eec82323
LMI
3795 ;; Init original article buffer.
3796 (save-excursion
6748645f 3797 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 3798 (mm-enable-multibyte)
eec82323 3799 (setq major-mode 'gnus-original-article-mode)
eec82323 3800 (make-local-variable 'gnus-original-article))
aba1948a
MB
3801 (if (and (get-buffer name)
3802 (with-current-buffer name
3803 (if gnus-article-edit-mode
3804 (if (y-or-n-p "Article mode edit in progress; discard? ")
3805 (progn
3806 (set-buffer-modified-p nil)
3807 (gnus-kill-buffer name)
3808 (message "")
3809 nil)
3810 (error "Action aborted"))
3811 t)))
eec82323
LMI
3812 (save-excursion
3813 (set-buffer name)
23f87bed 3814 (set (make-local-variable 'gnus-article-edit-mode) nil)
16409b0b
GM
3815 (when gnus-article-mime-handles
3816 (mm-destroy-parts gnus-article-mime-handles)
3817 (setq gnus-article-mime-handles nil))
3818 ;; Set it to nil in article-buffer!
a1506d29 3819 (setq gnus-article-mime-handle-alist nil)
16409b0b 3820 (buffer-disable-undo)
eec82323 3821 (setq buffer-read-only t)
23f87bed
MB
3822 ;; This list just keeps growing if we don't reset it.
3823 (setq gnus-button-marker-list nil)
eec82323
LMI
3824 (unless (eq major-mode 'gnus-article-mode)
3825 (gnus-article-mode))
3826 (current-buffer))
3827 (save-excursion
6748645f 3828 (set-buffer (gnus-get-buffer-create name))
eec82323
LMI
3829 (gnus-article-mode)
3830 (make-local-variable 'gnus-summary-buffer)
16409b0b 3831 (gnus-summary-set-local-parameters gnus-newsgroup-name)
eec82323
LMI
3832 (current-buffer)))))
3833
3834;; Set article window start at LINE, where LINE is the number of lines
3835;; from the head of the article.
3836(defun gnus-article-set-window-start (&optional line)
3837 (set-window-start
23f87bed 3838 (gnus-get-buffer-window gnus-article-buffer t)
eec82323
LMI
3839 (save-excursion
3840 (set-buffer gnus-article-buffer)
3841 (goto-char (point-min))
3842 (if (not line)
3843 (point-min)
3844 (gnus-message 6 "Moved to bookmark")
3845 (search-forward "\n\n" nil t)
3846 (forward-line line)
3847 (point)))))
3848
3849(defun gnus-article-prepare (article &optional all-headers header)
3850 "Prepare ARTICLE in article mode buffer.
3851ARTICLE should either be an article number or a Message-ID.
3852If ARTICLE is an id, HEADER should be the article headers.
3853If ALL-HEADERS is non-nil, no headers are hidden."
3854 (save-excursion
3855 ;; Make sure we start in a summary buffer.
3856 (unless (eq major-mode 'gnus-summary-mode)
3857 (set-buffer gnus-summary-buffer))
3858 (setq gnus-summary-buffer (current-buffer))
eec82323
LMI
3859 (let* ((gnus-article (if header (mail-header-number header) article))
3860 (summary-buffer (current-buffer))
6748645f 3861 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
eec82323
LMI
3862 (group gnus-newsgroup-name)
3863 result)
3864 (save-excursion
3865 (gnus-article-setup-buffer)
3866 (set-buffer gnus-article-buffer)
3867 ;; Deactivate active regions.
3868 (when (and (boundp 'transient-mark-mode)
3869 transient-mark-mode)
3870 (setq mark-active nil))
4e7d0221 3871 (if (not (setq result (let ((inhibit-read-only t))
eec82323
LMI
3872 (gnus-request-article-this-buffer
3873 article group))))
3874 ;; There is no such article.
3875 (save-excursion
3876 (when (and (numberp article)
3877 (not (memq article gnus-newsgroup-sparse)))
3878 (setq gnus-article-current
3879 (cons gnus-newsgroup-name article))
3880 (set-buffer gnus-summary-buffer)
3881 (setq gnus-current-article article)
23f87bed
MB
3882 (if (and (memq article gnus-newsgroup-undownloaded)
3883 (not (gnus-online (gnus-find-method-for-group
3884 gnus-newsgroup-name))))
6748645f
LMI
3885 (progn
3886 (gnus-summary-set-agent-mark article)
3887 (message "Message marked for downloading"))
3888 (gnus-summary-mark-article article gnus-canceled-mark)
3889 (unless (memq article gnus-newsgroup-sparse)
16409b0b 3890 (gnus-error 1 "No such article (may have expired or been canceled)")))))
6748645f
LMI
3891 (if (or (eq result 'pseudo)
3892 (eq result 'nneething))
eec82323
LMI
3893 (progn
3894 (save-excursion
3895 (set-buffer summary-buffer)
6748645f 3896 (push article gnus-newsgroup-history)
eec82323 3897 (setq gnus-last-article gnus-current-article
eec82323
LMI
3898 gnus-current-article 0
3899 gnus-current-headers nil
3900 gnus-article-current nil)
3901 (if (eq result 'nneething)
3902 (gnus-configure-windows 'summary)
3903 (gnus-configure-windows 'article))
3904 (gnus-set-global-variables))
16409b0b
GM
3905 (let ((gnus-article-mime-handle-alist-1
3906 gnus-article-mime-handle-alist))
3907 (gnus-set-mode-line 'article)))
eec82323
LMI
3908 ;; The result from the `request' was an actual article -
3909 ;; or at least some text that is now displayed in the
3910 ;; article buffer.
3911 (when (and (numberp article)
3912 (not (eq article gnus-current-article)))
3913 ;; Seems like a new article has been selected.
3914 ;; `gnus-current-article' must be an article number.
3915 (save-excursion
3916 (set-buffer summary-buffer)
6748645f 3917 (push article gnus-newsgroup-history)
eec82323 3918 (setq gnus-last-article gnus-current-article
eec82323
LMI
3919 gnus-current-article article
3920 gnus-current-headers
3921 (gnus-summary-article-header gnus-current-article)
3922 gnus-article-current
3923 (cons gnus-newsgroup-name gnus-current-article))
3924 (unless (vectorp gnus-current-headers)
3925 (setq gnus-current-headers nil))
6748645f
LMI
3926 (gnus-summary-goto-subject gnus-current-article)
3927 (when (gnus-summary-show-thread)
3928 ;; If the summary buffer really was folded, the
3929 ;; previous goto may not actually have gone to
3930 ;; the right article, but the thread root instead.
3931 ;; So we go again.
3932 (gnus-summary-goto-subject gnus-current-article))
3933 (gnus-run-hooks 'gnus-mark-article-hook)
eec82323
LMI
3934 (gnus-set-mode-line 'summary)
3935 (when (gnus-visual-p 'article-highlight 'highlight)
6748645f 3936 (gnus-run-hooks 'gnus-visual-mark-article-hook))
eec82323 3937 ;; Set the global newsgroup variables here.
eec82323
LMI
3938 (gnus-set-global-variables)
3939 (setq gnus-have-all-headers
6748645f 3940 (or all-headers gnus-show-all-headers))))
e0bad764
DL
3941 (save-excursion
3942 (gnus-configure-windows 'article))
eec82323
LMI
3943 (when (or (numberp article)
3944 (stringp article))
16409b0b 3945 (gnus-article-prepare-display)
eec82323
LMI
3946 ;; Do page break.
3947 (goto-char (point-min))
23f87bed
MB
3948 (when gnus-break-pages
3949 (gnus-narrow-to-page)))
16409b0b
GM
3950 (let ((gnus-article-mime-handle-alist-1
3951 gnus-article-mime-handle-alist))
3952 (gnus-set-mode-line 'article))
3953 (article-goto-body)
23f87bed
MB
3954 (unless (bobp)
3955 (forward-line -1))
6748645f 3956 (set-window-point (get-buffer-window (current-buffer)) (point))
16409b0b 3957 (gnus-configure-windows 'article)
eec82323
LMI
3958 t))))))
3959
16409b0b
GM
3960;;;###autoload
3961(defun gnus-article-prepare-display ()
3962 "Make the current buffer look like a nice article."
3963 ;; Hooks for getting information from the article.
3964 ;; This hook must be called before being narrowed.
3965 (let ((gnus-article-buffer (current-buffer))
23f87bed
MB
3966 buffer-read-only
3967 (inhibit-read-only t))
16409b0b
GM
3968 (unless (eq major-mode 'gnus-article-mode)
3969 (gnus-article-mode))
3970 (setq buffer-read-only nil
23f87bed
MB
3971 gnus-article-wash-types nil
3972 gnus-article-image-alist nil)
16409b0b
GM
3973 (gnus-run-hooks 'gnus-tmp-internal-hook)
3974 (when gnus-display-mime-function
3975 (funcall gnus-display-mime-function))
3976 (gnus-run-hooks 'gnus-article-prepare-hook)))
3977
3978;;;
3979;;; Gnus MIME viewing functions
3980;;;
3981
3982(defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
23f87bed
MB
3983 "Format of the MIME buttons.
3984
3985Valid specifiers include:
16409b0b
GM
3986%t The MIME type
3987%T MIME type, along with additional info
3988%n The `name' parameter
3989%d The description, if any
3990%l The length of the encoded part
3991%p The part identifier number
23f87bed
MB
3992%e Dots if the part isn't displayed
3993
3994General format specifiers can also be used. See Info node
3995`(gnus)Formatting Variables'.")
16409b0b
GM
3996
3997(defvar gnus-mime-button-line-format-alist
3998 '((?t gnus-tmp-type ?s)
3999 (?T gnus-tmp-type-long ?s)
4000 (?n gnus-tmp-name ?s)
4001 (?d gnus-tmp-description ?s)
4002 (?p gnus-tmp-id ?s)
4003 (?l gnus-tmp-length ?d)
4004 (?e gnus-tmp-dots ?s)))
4005
4006(defvar gnus-mime-button-commands
4007 '((gnus-article-press-button "\r" "Toggle Display")
4008 (gnus-mime-view-part "v" "View Interactively...")
4009 (gnus-mime-view-part-as-type "t" "View As Type...")
23f87bed 4010 (gnus-mime-view-part-as-charset "C" "View As charset...")
16409b0b 4011 (gnus-mime-save-part "o" "Save...")
23f87bed
MB
4012 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4013 (gnus-mime-delete-part "d" "Delete part")
16409b0b
GM
4014 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4015 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
23f87bed
MB
4016 (gnus-mime-view-part-internally "E" "View Internally")
4017 (gnus-mime-view-part-externally "e" "View Externally")
4018 (gnus-mime-print-part "p" "Print")
e0bad764 4019 (gnus-mime-pipe-part "|" "Pipe To Command...")
23f87bed 4020 (gnus-mime-action-on-part "." "Take action on the part...")))
16409b0b
GM
4021
4022(defun gnus-article-mime-part-status ()
4023 (if gnus-article-mime-handle-alist-1
23f87bed
MB
4024 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4025 " (1 part)"
4026 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
16409b0b
GM
4027 ""))
4028
4029(defvar gnus-mime-button-map
4030 (let ((map (make-sparse-keymap)))
23f87bed
MB
4031 (unless (>= (string-to-number emacs-version) 21)
4032 ;; XEmacs doesn't care.
4033 (set-keymap-parent map gnus-article-mode-map))
16409b0b
GM
4034 (define-key map gnus-mouse-2 'gnus-article-push-button)
4035 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4036 (dolist (c gnus-mime-button-commands)
4037 (define-key map (cadr c) (car c)))
4038 map))
4039
23f87bed
MB
4040(easy-menu-define
4041 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4042 `("MIME Part"
4043 ,@(mapcar (lambda (c)
4044 (vector (caddr c) (car c) :enable t))
4045 gnus-mime-button-commands)))
4046
4047(eval-when-compile
4048 (define-compiler-macro popup-menu (&whole form
4049 menu &optional position prefix)
4050 (if (and (fboundp 'popup-menu)
4051 (not (memq 'popup-menu (assoc "lmenu" load-history))))
4052 form
4053 ;; Gnus is probably running under Emacs 20.
4054 `(let* ((menu (cdr ,menu))
4055 (response (x-popup-menu
4056 t (list (car menu)
4057 (cons "" (mapcar (lambda (c)
4058 (cons (caddr c) (car c)))
4059 (cdr menu)))))))
4060 (if response
4061 (call-interactively (nth 3 (assq response menu))))))))
4062
4063(defun gnus-mime-button-menu (event prefix)
4064 "Construct a context-sensitive menu of MIME commands."
4065 (interactive "e\nP")
4066 (save-window-excursion
4067 (let ((pos (event-start event)))
4068 (select-window (posn-window pos))
4069 (goto-char (posn-point pos))
4070 (gnus-article-check-buffer)
4071 (popup-menu gnus-mime-button-menu nil prefix))))
16409b0b
GM
4072
4073(defun gnus-mime-view-all-parts (&optional handles)
4074 "View all the MIME parts."
4075 (interactive)
4076 (save-current-buffer
4077 (set-buffer gnus-article-buffer)
4078 (let ((handles (or handles gnus-article-mime-handles))
4079 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4080 (mail-parse-ignored-charsets
23f87bed
MB
4081 (with-current-buffer gnus-summary-buffer
4082 gnus-newsgroup-ignored-charsets)))
4083 (when handles
4084 (mm-remove-parts handles)
4085 (goto-char (point-min))
4086 (or (search-forward "\n\n") (goto-char (point-max)))
4087 (let ((inhibit-read-only t))
4088 (delete-region (point) (point-max))
4089 (mm-display-parts handles))))))
4090
4091(defun gnus-mime-save-part-and-strip ()
4092 "Save the MIME part under point then replace it with an external body."
4093 (interactive)
4094 (gnus-article-check-buffer)
4095 (when (gnus-group-read-only-p)
4096 (error "The current group does not support deleting of parts"))
4097 (when (mm-complicated-handles gnus-article-mime-handles)
4098 (error "\
4099The current article has a complicated MIME structure, giving up..."))
4100 (when (gnus-yes-or-no-p "\
4101Deleting parts may malfunction or destroy the article; continue? ")
4102 (let* ((data (get-text-property (point) 'gnus-data))
4103 file param
4104 (handles gnus-article-mime-handles))
4105 (setq file (and data (mm-save-part data)))
4106 (when file
4107 (with-current-buffer (mm-handle-buffer data)
4108 (erase-buffer)
4109 (insert "Content-Type: " (mm-handle-media-type data))
4110 (mml-insert-parameter-string (cdr (mm-handle-type data))
4111 '(charset))
4112 (insert "\n")
4113 (insert "Content-ID: " (message-make-message-id) "\n")
4114 (insert "Content-Transfer-Encoding: binary\n")
4115 (insert "\n"))
4116 (setcdr data
4117 (cdr (mm-make-handle nil
4118 `("message/external-body"
4119 (access-type . "LOCAL-FILE")
4120 (name . ,file)))))
4121 (set-buffer gnus-summary-buffer)
4122 (gnus-article-edit-article
4123 `(lambda ()
4124 (erase-buffer)
4125 (let ((mail-parse-charset (or gnus-article-charset
4126 ',gnus-newsgroup-charset))
4127 (mail-parse-ignored-charsets
4128 (or gnus-article-ignored-charsets
4129 ',gnus-newsgroup-ignored-charsets))
4130 (mbl mml-buffer-list))
4131 (setq mml-buffer-list nil)
d8a88581 4132 (insert-buffer-substring gnus-original-article-buffer)
23f87bed
MB
4133 (mime-to-mml ',handles)
4134 (setq gnus-article-mime-handles nil)
4135 (let ((mbl1 mml-buffer-list))
4136 (setq mml-buffer-list mbl)
4137 (set (make-local-variable 'mml-buffer-list) mbl1))
4138 (gnus-make-local-hook 'kill-buffer-hook)
4139 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4140 `(lambda (no-highlight)
4141 (let ((mail-parse-charset (or gnus-article-charset
4142 ',gnus-newsgroup-charset))
4143 (message-options message-options)
4144 (message-options-set-recipient)
4145 (mail-parse-ignored-charsets
4146 (or gnus-article-ignored-charsets
4147 ',gnus-newsgroup-ignored-charsets)))
4148 (mml-to-mime)
4149 (mml-destroy-buffers)
4150 (remove-hook 'kill-buffer-hook
4151 'mml-destroy-buffers t)
4152 (kill-local-variable 'mml-buffer-list))
4153 (gnus-summary-edit-article-done
4154 ,(or (mail-header-references gnus-current-headers) "")
4155 ,(gnus-group-read-only-p)
4156 ,gnus-summary-buffer no-highlight)))))))
4157
4158(defun gnus-mime-delete-part ()
4159 "Delete the MIME part under point.
4160Replace it with some information about the removed part."
4161 (interactive)
4162 (gnus-article-check-buffer)
4163 (when (gnus-group-read-only-p)
4164 (error "The current group does not support deleting of parts"))
4165 (when (mm-complicated-handles gnus-article-mime-handles)
4166 (error "\
4167The current article has a complicated MIME structure, giving up..."))
4168 (when (gnus-yes-or-no-p "\
4169Deleting parts may malfunction or destroy the article; continue? ")
4170 (let* ((data (get-text-property (point) 'gnus-data))
4171 (handles gnus-article-mime-handles)
4172 (none "(none)")
4173 (description
4174 (or
4175 (mail-decode-encoded-word-string (or (mm-handle-description data)
4176 none))))
4177 (filename
4178 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4179 none))
4180 (type (mm-handle-media-type data)))
4181 (unless data
4182 (error "No MIME part under point"))
4183 (with-current-buffer (mm-handle-buffer data)
4184 (let ((bsize (format "%s" (buffer-size))))
4185 (erase-buffer)
4186 (insert
4187 (concat
4188 ",----\n"
4189 "| The following attachment has been deleted:\n"
4190 "|\n"
4191 "| Type: " type "\n"
4192 "| Filename: " filename "\n"
4193 "| Size (encoded): " bsize " Byte\n"
4194 "| Description: " description "\n"
4195 "`----\n"))
4196 (setcdr data
4197 (cdr (mm-make-handle
4198 nil `("text/plain") nil nil
4199 (list "attachment")
4200 (format "Deleted attachment (%s bytes)" bsize))))))
4201 (set-buffer gnus-summary-buffer)
4202 ;; FIXME: maybe some of the following code (borrowed from
4203 ;; `gnus-mime-save-part-and-strip') isn't necessary?
4204 (gnus-article-edit-article
4205 `(lambda ()
4206 (erase-buffer)
4207 (let ((mail-parse-charset (or gnus-article-charset
4208 ',gnus-newsgroup-charset))
4209 (mail-parse-ignored-charsets
4210 (or gnus-article-ignored-charsets
4211 ',gnus-newsgroup-ignored-charsets))
4212 (mbl mml-buffer-list))
4213 (setq mml-buffer-list nil)
d8a88581 4214 (insert-buffer-substring gnus-original-article-buffer)
23f87bed
MB
4215 (mime-to-mml ',handles)
4216 (setq gnus-article-mime-handles nil)
4217 (let ((mbl1 mml-buffer-list))
4218 (setq mml-buffer-list mbl)
4219 (set (make-local-variable 'mml-buffer-list) mbl1))
4220 (gnus-make-local-hook 'kill-buffer-hook)
4221 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4222 `(lambda (no-highlight)
4223 (let ((mail-parse-charset (or gnus-article-charset
4224 ',gnus-newsgroup-charset))
4225 (message-options message-options)
4226 (message-options-set-recipient)
4227 (mail-parse-ignored-charsets
4228 (or gnus-article-ignored-charsets
4229 ',gnus-newsgroup-ignored-charsets)))
4230 (mml-to-mime)
4231 (mml-destroy-buffers)
4232 (remove-hook 'kill-buffer-hook
4233 'mml-destroy-buffers t)
4234 (kill-local-variable 'mml-buffer-list))
4235 (gnus-summary-edit-article-done
4236 ,(or (mail-header-references gnus-current-headers) "")
4237 ,(gnus-group-read-only-p)
4238 ,gnus-summary-buffer no-highlight)))))
4239 ;; Not in `gnus-mime-save-part-and-strip':
4240 (gnus-article-edit-done)
4241 (gnus-summary-expand-window)
4242 (gnus-summary-show-article))
16409b0b
GM
4243
4244(defun gnus-mime-save-part ()
4245 "Save the MIME part under point."
4246 (interactive)
4247 (gnus-article-check-buffer)
4248 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4249 (when data
4250 (mm-save-part data))))
16409b0b
GM
4251
4252(defun gnus-mime-pipe-part ()
4253 "Pipe the MIME part under point to a process."
4254 (interactive)
4255 (gnus-article-check-buffer)
4256 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4257 (when data
4258 (mm-pipe-part data))))
16409b0b
GM
4259
4260(defun gnus-mime-view-part ()
4261 "Interactively choose a viewing method for the MIME part under point."
4262 (interactive)
4263 (gnus-article-check-buffer)
4264 (let ((data (get-text-property (point) 'gnus-data)))
23f87bed
MB
4265 (when data
4266 (setq gnus-article-mime-handles
4267 (mm-merge-handles
4268 gnus-article-mime-handles (setq data (copy-sequence data))))
4269 (mm-interactively-view-part data))))
16409b0b
GM
4270
4271(defun gnus-mime-view-part-as-type-internal ()
4272 (gnus-article-check-buffer)
4273 (let* ((name (mail-content-type-get
4274 (mm-handle-type (get-text-property (point) 'gnus-data))
4275 'name))
4276 (def-type (and name (mm-default-file-encoding name))))
4277 (and def-type (cons def-type 0))))
4278
23f87bed 4279(defun gnus-mime-view-part-as-type (&optional mime-type)
16409b0b 4280 "Choose a MIME media type, and view the part as such."
23f87bed
MB
4281 (interactive)
4282 (unless mime-type
4283 (setq mime-type (completing-read
4284 "View as MIME type: "
4285 (mapcar #'list (mailcap-mime-types))
4286 nil nil
4287 (gnus-mime-view-part-as-type-internal))))
16409b0b
GM
4288 (gnus-article-check-buffer)
4289 (let ((handle (get-text-property (point) 'gnus-data)))
23f87bed
MB
4290 (when handle
4291 (setq handle
4292 (mm-make-handle (mm-handle-buffer handle)
4293 (cons mime-type (cdr (mm-handle-type handle)))
4294 (mm-handle-encoding handle)
4295 (mm-handle-undisplayer handle)
4296 (mm-handle-disposition handle)
4297 (mm-handle-description handle)
4298 nil
4299 (mm-handle-id handle)))
4300 (setq gnus-article-mime-handles
4301 (mm-merge-handles gnus-article-mime-handles handle))
4302 (gnus-mm-display-part handle))))
4303
4304(eval-when-compile
4305 (require 'jka-compr))
4306
4307;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4308;; emacs can do that itself.
4309;;
4310(defun gnus-mime-jka-compr-maybe-uncompress ()
4311 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4312The uncompress method used is derived from `buffer-file-name'."
4313 (when (and (fboundp 'jka-compr-installed-p)
4314 (jka-compr-installed-p))
4315 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4316 (when info
4317 (let ((basename (file-name-nondirectory buffer-file-name))
4318 (args (jka-compr-info-uncompress-args info))
4319 (prog (jka-compr-info-uncompress-program info))
4320 (message (jka-compr-info-uncompress-message info))
4321 (err-file (jka-compr-make-temp-name)))
4322 (if message
4323 (message "%s %s..." message basename))
4324 (unwind-protect
4325 (unless (memq (apply 'call-process-region
4326 (point-min) (point-max)
4327 prog
4328 t (list t err-file) nil
4329 args)
4330 jka-compr-acceptable-retval-list)
4331 (jka-compr-error prog args basename message err-file))
4332 (jka-compr-delete-temp-file err-file)))))))
16409b0b
GM
4333
4334(defun gnus-mime-copy-part (&optional handle)
23f87bed
MB
4335 "Put the MIME part under point into a new buffer.
4336If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4337are decompressed."
16409b0b
GM
4338 (interactive)
4339 (gnus-article-check-buffer)
4340 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
23f87bed
MB
4341 (contents (and handle (mm-get-part handle)))
4342 (base (and handle
4343 (file-name-nondirectory
4344 (or
4345 (mail-content-type-get (mm-handle-type handle) 'name)
4346 (mail-content-type-get (mm-handle-disposition handle)
4347 'filename)
4348 "*decoded*"))))
4349 (buffer (and base (generate-new-buffer base))))
4350 (when contents
4351 (switch-to-buffer buffer)
4352 (insert contents)
4353 ;; We do it this way to make `normal-mode' set the appropriate mode.
4354 (unwind-protect
4355 (progn
4356 (setq buffer-file-name (expand-file-name base))
4357 (gnus-mime-jka-compr-maybe-uncompress)
4358 (normal-mode))
4359 (setq buffer-file-name nil))
4360 (goto-char (point-min)))))
4361
4362(defun gnus-mime-print-part (&optional handle filename)
4363 "Print the MIME part under point."
4364 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4365 (gnus-article-check-buffer)
4366 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4367 (contents (and handle (mm-get-part handle)))
4368 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4369 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4370 (when contents
4371 (if printer
4372 (unwind-protect
4373 (progn
4374 (mm-save-part-to-file handle file)
4375 (call-process shell-file-name nil
4376 (generate-new-buffer " *mm*")
4377 nil
4378 shell-command-switch
4379 (mm-mailcap-command
4380 printer file (mm-handle-type handle))))
4381 (delete-file file))
4382 (with-temp-buffer
4383 (insert contents)
4384 (gnus-print-buffer))
4385 (ps-despool filename)))))
16409b0b 4386
e0bad764 4387(defun gnus-mime-inline-part (&optional handle arg)
16409b0b 4388 "Insert the MIME part under point into the current buffer."
e0bad764 4389 (interactive (list nil current-prefix-arg))
16409b0b
GM
4390 (gnus-article-check-buffer)
4391 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
e0bad764 4392 contents charset
16409b0b 4393 (b (point))
23f87bed
MB
4394 (inhibit-read-only t))
4395 (when handle
4396 (if (and (not arg) (mm-handle-undisplayer handle))
4397 (mm-remove-part handle)
4398 (setq contents (mm-get-part handle))
4399 (cond
4400 ((not arg)
4401 (setq charset (or (mail-content-type-get
4402 (mm-handle-type handle) 'charset)
4403 gnus-newsgroup-charset)))
4404 ((numberp arg)
4405 (if (mm-handle-undisplayer handle)
4406 (mm-remove-part handle))
4407 (setq charset
4408 (or (cdr (assq arg
4409 gnus-summary-show-article-charset-alist))
56c30d72
MB
4410 (mm-read-coding-system "Charset: "))))
4411 (t
4412 (if (mm-handle-undisplayer handle)
850c333d 4413 (mm-remove-part handle))))
23f87bed 4414 (forward-line 2)
850c333d
MB
4415 (mm-insert-inline
4416 handle
4417 (if (and charset
4418 (setq charset (mm-charset-to-coding-system
4419 charset))
4420 (not (eq charset 'ascii)))
4421 (mm-decode-coding-string contents charset)
4422 (mm-string-to-multibyte contents)))
23f87bed
MB
4423 (goto-char b)))))
4424
4425(defun gnus-mime-view-part-as-charset (&optional handle arg)
4426 "Insert the MIME part under point into the current buffer using the
4427specified charset."
4428 (interactive (list nil current-prefix-arg))
4429 (gnus-article-check-buffer)
4430 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4431 contents charset
4432 (b (point))
4433 (inhibit-read-only t))
4434 (when handle
4435 (if (mm-handle-undisplayer handle)
4436 (mm-remove-part handle))
4437 (let ((gnus-newsgroup-charset
4438 (or (cdr (assq arg
4439 gnus-summary-show-article-charset-alist))
4440 (mm-read-coding-system "Charset: ")))
4441 (gnus-newsgroup-ignored-charsets 'gnus-all))
4442 (gnus-article-press-button)))))
4443
4444(defun gnus-mime-view-part-externally (&optional handle)
16409b0b
GM
4445 "View the MIME part under point with an external viewer."
4446 (interactive)
4447 (gnus-article-check-buffer)
4448 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4449 (mm-user-display-methods nil)
4450 (mm-inlined-types nil)
4451 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4452 (mail-parse-ignored-charsets
16409b0b
GM
4453 (save-excursion (set-buffer gnus-summary-buffer)
4454 gnus-newsgroup-ignored-charsets)))
23f87bed
MB
4455 (when handle
4456 (if (mm-handle-undisplayer handle)
4457 (mm-remove-part handle)
4458 (mm-display-part handle)))))
16409b0b 4459
23f87bed 4460(defun gnus-mime-view-part-internally (&optional handle)
16409b0b 4461 "View the MIME part under point with an internal viewer.
23f87bed 4462If no internal viewer is available, use an external viewer."
16409b0b
GM
4463 (interactive)
4464 (gnus-article-check-buffer)
4465 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4466 (mm-inlined-types '(".*"))
4467 (mm-inline-large-images t)
4468 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4469 (mail-parse-ignored-charsets
16409b0b 4470 (save-excursion (set-buffer gnus-summary-buffer)
23f87bed
MB
4471 gnus-newsgroup-ignored-charsets))
4472 (inhibit-read-only t))
4473 (when handle
4474 (if (mm-handle-undisplayer handle)
4475 (mm-remove-part handle)
4476 (mm-display-part handle)))))
16409b0b 4477
e0bad764
DL
4478(defun gnus-mime-action-on-part (&optional action)
4479 "Do something with the MIME attachment at \(point\)."
4480 (interactive
23f87bed 4481 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
e0bad764
DL
4482 (gnus-article-check-buffer)
4483 (let ((action-pair (assoc action gnus-mime-action-alist)))
4484 (if action-pair
4485 (funcall (cdr action-pair)))))
4486
16409b0b
GM
4487(defun gnus-article-part-wrapper (n function)
4488 (save-current-buffer
4489 (set-buffer gnus-article-buffer)
4490 (when (> n (length gnus-article-mime-handle-alist))
4491 (error "No such part"))
4492 (gnus-article-goto-part n)
4493 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4494 (funcall function handle))))
4495
4496(defun gnus-article-pipe-part (n)
4497 "Pipe MIME part N, which is the numerical prefix."
4498 (interactive "p")
4499 (gnus-article-part-wrapper n 'mm-pipe-part))
4500
4501(defun gnus-article-save-part (n)
4502 "Save MIME part N, which is the numerical prefix."
4503 (interactive "p")
4504 (gnus-article-part-wrapper n 'mm-save-part))
4505
4506(defun gnus-article-interactively-view-part (n)
4507 "View MIME part N interactively, which is the numerical prefix."
4508 (interactive "p")
4509 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4510
4511(defun gnus-article-copy-part (n)
4512 "Copy MIME part N, which is the numerical prefix."
4513 (interactive "p")
4514 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4515
23f87bed
MB
4516(defun gnus-article-view-part-as-charset (n)
4517 "View MIME part N using a specified charset.
4518N is the numerical prefix."
4519 (interactive "p")
4520 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4521
4522(defun gnus-article-view-part-externally (n)
16409b0b
GM
4523 "View MIME part N externally, which is the numerical prefix."
4524 (interactive "p")
23f87bed 4525 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
16409b0b
GM
4526
4527(defun gnus-article-inline-part (n)
4528 "Inline MIME part N, which is the numerical prefix."
4529 (interactive "p")
4530 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4531
4532(defun gnus-article-mime-match-handle-first (condition)
4533 (if condition
4534 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4535 (while (setq ihandle (pop alist))
a1506d29 4536 (if (and (cond
16409b0b
GM
4537 ((functionp condition)
4538 (funcall condition (cdr ihandle)))
a1506d29 4539 ((eq condition 'undisplayed)
16409b0b
GM
4540 (not (or (mm-handle-undisplayer (cdr ihandle))
4541 (equal (mm-handle-media-type (cdr ihandle))
4542 "multipart/alternative"))))
4543 ((eq condition 'undisplayed-alternative)
4544 (not (mm-handle-undisplayer (cdr ihandle))))
4545 (t t))
4546 (gnus-article-goto-part (car ihandle))
4547 (or (not n) (< (car ihandle) n)))
4548 (setq n (car ihandle))))
4549 (or n 1))
4550 1))
4551
4552(defun gnus-article-view-part (&optional n)
4553 "View MIME part N, which is the numerical prefix."
4554 (interactive "P")
4555 (save-current-buffer
4556 (set-buffer gnus-article-buffer)
a1506d29 4557 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
16409b0b
GM
4558 gnus-article-mime-match-handle-function)))
4559 (when (> n (length gnus-article-mime-handle-alist))
4560 (error "No such part"))
4561 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4562 (when (gnus-article-goto-part n)
4563 (if (equal (car handle) "multipart/alternative")
4564 (gnus-article-press-button)
4565 (when (eq (gnus-mm-display-part handle) 'internal)
4566 (gnus-set-window-start)))))))
4567
e0bad764
DL
4568(defsubst gnus-article-mime-total-parts ()
4569 (if (bufferp (car gnus-article-mime-handles))
4570 1 ;; single part
4571 (1- (length gnus-article-mime-handles))))
4572
16409b0b
GM
4573(defun gnus-mm-display-part (handle)
4574 "Display HANDLE and fix MIME button."
4575 (let ((id (get-text-property (point) 'gnus-part))
4576 (point (point))
23f87bed 4577 (inhibit-read-only t))
16409b0b
GM
4578 (forward-line 1)
4579 (prog1
4580 (let ((window (selected-window))
4581 (mail-parse-charset gnus-newsgroup-charset)
a1506d29 4582 (mail-parse-ignored-charsets
23f87bed
MB
4583 (if (gnus-buffer-live-p gnus-summary-buffer)
4584 (save-excursion
4585 (set-buffer gnus-summary-buffer)
4586 gnus-newsgroup-ignored-charsets)
4587 nil)))
16409b0b
GM
4588 (save-excursion
4589 (unwind-protect
23f87bed 4590 (let ((win (gnus-get-buffer-window (current-buffer) t))
16409b0b
GM
4591 (beg (point)))
4592 (when win
4593 (select-window win))
4594 (goto-char point)
4595 (forward-line)
4596 (if (mm-handle-displayed-p handle)
4597 ;; This will remove the part.
4598 (mm-display-part handle)
4599 (save-restriction
23f87bed
MB
4600 (narrow-to-region (point)
4601 (if (eobp) (point) (1+ (point))))
16409b0b
GM
4602 (mm-display-part handle)
4603 ;; We narrow to the part itself and
4604 ;; then call the treatment functions.
4605 (goto-char (point-min))
4606 (forward-line 1)
4607 (narrow-to-region (point) (point-max))
4608 (gnus-treat-article
4609 nil id
e0bad764 4610 (gnus-article-mime-total-parts)
16409b0b 4611 (mm-handle-media-type handle)))))
23f87bed
MB
4612 (if (window-live-p window)
4613 (select-window window)))))
16409b0b 4614 (goto-char point)
23f87bed 4615 (gnus-delete-line)
16409b0b
GM
4616 (gnus-insert-mime-button
4617 handle id (list (mm-handle-displayed-p handle)))
4618 (goto-char point))))
4619
4620(defun gnus-article-goto-part (n)
4621 "Go to MIME part N."
23f87bed 4622 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
16409b0b
GM
4623
4624(defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4625 (let ((gnus-tmp-name
23f87bed
MB
4626 (or (mail-content-type-get (mm-handle-type handle) 'name)
4627 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4628 (mail-content-type-get (mm-handle-type handle) 'url)
16409b0b
GM
4629 ""))
4630 (gnus-tmp-type (mm-handle-media-type handle))
4631 (gnus-tmp-description
4632 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4633 "")))
4634 (gnus-tmp-dots
4635 (if (if displayed (car displayed)
4636 (mm-handle-displayed-p handle))
4637 "" "..."))
4638 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4639 (buffer-size)))
4640 gnus-tmp-type-long b e)
4641 (when (string-match ".*/" gnus-tmp-name)
4642 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4643 (setq gnus-tmp-type-long (concat gnus-tmp-type
4644 (and (not (equal gnus-tmp-name ""))
4645 (concat "; " gnus-tmp-name))))
23f87bed
MB
4646 (unless (equal gnus-tmp-description "")
4647 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
16409b0b
GM
4648 (unless (bolp)
4649 (insert "\n"))
4650 (setq b (point))
4651 (gnus-eval-format
4652 gnus-mime-button-line-format gnus-mime-button-line-format-alist
23f87bed
MB
4653 `(,@(gnus-local-map-property gnus-mime-button-map)
4654 gnus-callback gnus-mm-display-part
4655 gnus-part ,gnus-tmp-id
4656 article-type annotation
4657 gnus-data ,handle))
4658 (setq e (if (bolp)
4659 ;; Exclude a newline.
4660 (1- (point))
4661 (point)))
16409b0b
GM
4662 (widget-convert-button
4663 'link b e
4664 :mime-handle handle
4665 :action 'gnus-widget-press-button
4666 :button-keymap gnus-mime-button-map
4667 :help-echo
4668 (lambda (widget/window &optional overlay pos)
4669 ;; Needed to properly clear the message due to a bug in
4670 ;; wid-edit (XEmacs only).
4671 (if (boundp 'help-echo-owns-message)
4672 (setq help-echo-owns-message t))
4673 (format
4674 "%S: %s the MIME part; %S: more options"
4675 (aref gnus-mouse-2 0)
4676 ;; XEmacs will get a single widget arg; Emacs 21 will get
4677 ;; window, overlay, position.
4678 (if (mm-handle-displayed-p
4679 (if overlay
e0bad764
DL
4680 (with-current-buffer (gnus-overlay-buffer overlay)
4681 (widget-get (widget-at (gnus-overlay-start overlay))
16409b0b
GM
4682 :mime-handle))
4683 (widget-get widget/window :mime-handle)))
4684 "hide" "show")
4685 (aref gnus-down-mouse-3 0))))))
4686
4687(defun gnus-widget-press-button (elems el)
4688 (goto-char (widget-get elems :from))
4689 (gnus-article-press-button))
4690
4691(defvar gnus-displaying-mime nil)
4692
4693(defun gnus-display-mime (&optional ihandles)
4694 "Display the MIME parts."
4695 (save-excursion
4696 (save-selected-window
4697 (let ((window (get-buffer-window gnus-article-buffer))
4698 (point (point)))
4699 (when window
4700 (select-window window)
4701 ;; We have to do this since selecting the window
4702 ;; may change the point. So we set the window point.
4703 (set-window-point window point)))
23f87bed
MB
4704 (let* ((handles (or ihandles
4705 (mm-dissect-buffer nil gnus-article-loose-mime)
4706 (and gnus-article-emulate-mime
4707 (mm-uu-dissect))))
4708 (inhibit-read-only t) handle name type b e display)
16409b0b
GM
4709 (when (and (not ihandles)
4710 (not gnus-displaying-mime))
4711 ;; Top-level call; we clean up.
4712 (when gnus-article-mime-handles
4713 (mm-destroy-parts gnus-article-mime-handles)
4714 (setq gnus-article-mime-handle-alist nil));; A trick.
4715 (setq gnus-article-mime-handles handles)
4716 ;; We allow users to glean info from the handles.
4717 (when gnus-article-mime-part-function
4718 (gnus-mime-part-function handles)))
4719 (if (and handles
4720 (or (not (stringp (car handles)))
4721 (cdr handles)))
4722 (progn
4723 (when (and (not ihandles)
4724 (not gnus-displaying-mime))
4725 ;; Clean up for mime parts.
4726 (article-goto-body)
4727 (delete-region (point) (point-max)))
4728 (let ((gnus-displaying-mime t))
4729 (gnus-mime-display-part handles)))
4730 (save-restriction
4731 (article-goto-body)
4732 (narrow-to-region (point) (point-max))
4733 (gnus-treat-article nil 1 1)
4734 (widen)))
4735 (unless ihandles
4736 ;; Highlight the headers.
4737 (save-excursion
4738 (save-restriction
4739 (article-goto-body)
4740 (narrow-to-region (point-min) (point))
31640842
MB
4741 (gnus-article-save-original-date
4742 (gnus-treat-article 'head)))))))))
16409b0b 4743
23f87bed
MB
4744(defcustom gnus-mime-display-multipart-as-mixed nil
4745 "Display \"multipart\" parts as \"multipart/mixed\".
4746
4747If t, it overrides nil values of
4748`gnus-mime-display-multipart-alternative-as-mixed' and
4749`gnus-mime-display-multipart-related-as-mixed'."
4750 :group 'gnus-article-mime
4751 :type 'boolean)
4752
4753(defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4754 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
bf247b6e 4755 :version "22.1"
23f87bed
MB
4756 :group 'gnus-article-mime
4757 :type 'boolean)
4758
4759(defcustom gnus-mime-display-multipart-related-as-mixed nil
4760 "Display \"multipart/related\" parts as \"multipart/mixed\".
4761
4762If displaying \"text/html\" is discouraged \(see
4763`mm-discouraged-alternatives'\) images or other material inside a
4764\"multipart/related\" part might be overlooked when this variable is nil."
bf247b6e 4765 :version "22.1"
23f87bed
MB
4766 :group 'gnus-article-mime
4767 :type 'boolean)
16409b0b
GM
4768
4769(defun gnus-mime-display-part (handle)
4770 (cond
430d3ed7
MB
4771 ;; Maybe a broken MIME message.
4772 ((null handle))
16409b0b
GM
4773 ;; Single part.
4774 ((not (stringp (car handle)))
4775 (gnus-mime-display-single handle))
4776 ;; User-defined multipart
4777 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4778 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4779 handle))
4780 ;; multipart/alternative
4781 ((and (equal (car handle) "multipart/alternative")
23f87bed
MB
4782 (not (or gnus-mime-display-multipart-as-mixed
4783 gnus-mime-display-multipart-alternative-as-mixed)))
16409b0b
GM
4784 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4785 (push (cons id handle) gnus-article-mime-handle-alist)
4786 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4787 ;; multipart/related
4788 ((and (equal (car handle) "multipart/related")
23f87bed
MB
4789 (not (or gnus-mime-display-multipart-as-mixed
4790 gnus-mime-display-multipart-related-as-mixed)))
16409b0b
GM
4791 ;;;!!!We should find the start part, but we just default
4792 ;;;!!!to the first part.
23f87bed
MB
4793 ;;(gnus-mime-display-part (cadr handle))
4794 ;;;!!! Most multipart/related is an HTML message plus images.
4795 ;;;!!! Unfortunately we are unable to let W3 display those
4796 ;;;!!! included images, so we just display it as a mixed multipart.
4797 ;;(gnus-mime-display-mixed (cdr handle))
4798 ;;;!!! No, w3 can display everything just fine.
16409b0b 4799 (gnus-mime-display-part (cadr handle)))
23f87bed
MB
4800 ((equal (car handle) "multipart/signed")
4801 (gnus-add-wash-type 'signed)
4802 (gnus-mime-display-security handle))
4803 ((equal (car handle) "multipart/encrypted")
4804 (gnus-add-wash-type 'encrypted)
4805 (gnus-mime-display-security handle))
16409b0b
GM
4806 ;; Other multiparts are handled like multipart/mixed.
4807 (t
4808 (gnus-mime-display-mixed (cdr handle)))))
4809
4810(defun gnus-mime-part-function (handles)
4811 (if (stringp (car handles))
4812 (mapcar 'gnus-mime-part-function (cdr handles))
4813 (funcall gnus-article-mime-part-function handles)))
4814
4815(defun gnus-mime-display-mixed (handles)
4816 (mapcar 'gnus-mime-display-part handles))
4817
4818(defun gnus-mime-display-single (handle)
4819 (let ((type (mm-handle-media-type handle))
4820 (ignored gnus-ignored-mime-types)
4821 (not-attachment t)
4822 (move nil)
4823 display text)
4824 (catch 'ignored
4825 (progn
4826 (while ignored
4827 (when (string-match (pop ignored) type)
4828 (throw 'ignored nil)))
4829 (if (and (setq not-attachment
4830 (and (not (mm-inline-override-p handle))
4831 (or (not (mm-handle-disposition handle))
4832 (equal (car (mm-handle-disposition handle))
4833 "inline")
4834 (mm-attachment-override-p handle))))
4835 (mm-automatic-display-p handle)
23f87bed
MB
4836 (or (and
4837 (mm-inlinable-p handle)
4838 (mm-inlined-p handle))
16409b0b
GM
4839 (mm-automatic-external-display-p type)))
4840 (setq display t)
4841 (when (equal (mm-handle-media-supertype handle) "text")
4842 (setq text t)))
e0bad764
DL
4843 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4844 beg)
16409b0b
GM
4845 (push (cons id handle) gnus-article-mime-handle-alist)
4846 (when (or (not display)
4847 (not (gnus-unbuttonized-mime-type-p type)))
4848 ;(gnus-article-insert-newline)
4849 (gnus-insert-mime-button
4850 handle id (list (or display (and not-attachment text))))
4851 (gnus-article-insert-newline)
4852 ;(gnus-article-insert-newline)
23f87bed 4853 ;; Remember modify the number of forward lines.
e0bad764
DL
4854 (setq move t))
4855 (setq beg (point))
16409b0b
GM
4856 (cond
4857 (display
4858 (when move
23f87bed 4859 (forward-line -1)
16409b0b
GM
4860 (setq beg (point)))
4861 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 4862 (mail-parse-ignored-charsets
16409b0b
GM
4863 (save-excursion (condition-case ()
4864 (set-buffer gnus-summary-buffer)
4865 (error))
4866 gnus-newsgroup-ignored-charsets)))
4867 (mm-display-part handle t))
4868 (goto-char (point-max)))
4869 ((and text not-attachment)
4870 (when move
23f87bed 4871 (forward-line -1)
16409b0b
GM
4872 (setq beg (point)))
4873 (gnus-article-insert-newline)
53cfefc8
MB
4874 (mm-insert-inline
4875 handle
4876 (let ((charset (mail-content-type-get (mm-handle-type handle)
4877 'charset)))
4878 (cond ((not charset)
4879 (mm-string-as-multibyte (mm-get-part handle)))
4880 ((eq charset 'gnus-decoded)
4881 (with-current-buffer (mm-handle-buffer handle)
4882 (buffer-string)))
4883 (t
4884 (mm-decode-string (mm-get-part handle) charset)))))
16409b0b
GM
4885 (goto-char (point-max))))
4886 ;; Do highlighting.
4887 (save-excursion
4888 (save-restriction
4889 (narrow-to-region beg (point))
4890 (gnus-treat-article
a1506d29 4891 nil id
e0bad764 4892 (gnus-article-mime-total-parts)
16409b0b
GM
4893 (mm-handle-media-type handle)))))))))
4894
4895(defun gnus-unbuttonized-mime-type-p (type)
4896 "Say whether TYPE is to be unbuttonized."
4897 (unless gnus-inhibit-mime-unbuttonizing
23f87bed
MB
4898 (when (catch 'found
4899 (let ((types gnus-unbuttonized-mime-types))
4900 (while types
4901 (when (string-match (pop types) type)
4902 (throw 'found t)))))
4903 (not (catch 'found
4904 (let ((types gnus-buttonized-mime-types))
4905 (while types
4906 (when (string-match (pop types) type)
4907 (throw 'found t)))))))))
16409b0b
GM
4908
4909(defun gnus-article-insert-newline ()
4910 "Insert a newline, but mark it as undeletable."
4911 (gnus-put-text-property
4912 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4913
4914(defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4915 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4916 (ihandles handles)
4917 (point (point))
23f87bed 4918 handle (inhibit-read-only t) from props begend not-pref)
16409b0b
GM
4919 (save-window-excursion
4920 (save-restriction
4921 (when ibegend
4922 (narrow-to-region (car ibegend)
4923 (or (cdr ibegend)
4924 (progn
4925 (goto-char (car ibegend))
4926 (forward-line 2)
4927 (point))))
4928 (delete-region (point-min) (point-max))
4929 (mm-remove-parts handles))
4930 (setq begend (list (point-marker)))
4931 ;; Do the toggle.
4932 (unless (setq not-pref (cadr (member preferred ihandles)))
4933 (setq not-pref (car ihandles)))
4934 (when (or ibegend
23f87bed 4935 (not preferred)
16409b0b
GM
4936 (not (gnus-unbuttonized-mime-type-p
4937 "multipart/alternative")))
4938 (gnus-add-text-properties
4939 (setq from (point))
4940 (progn
4941 (insert (format "%d. " id))
4942 (point))
4943 `(gnus-callback
4944 (lambda (handles)
4945 (unless ,(not ibegend)
4946 (setq gnus-article-mime-handle-alist
4947 ',gnus-article-mime-handle-alist))
4948 (gnus-mime-display-alternative
4949 ',ihandles ',not-pref ',begend ,id))
23f87bed 4950 ,@(gnus-local-map-property gnus-mime-button-map)
16409b0b
GM
4951 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4952 face ,gnus-article-button-face
16409b0b
GM
4953 gnus-part ,id
4954 gnus-data ,handle))
4955 (widget-convert-button 'link from (point)
4956 :action 'gnus-widget-press-button
4957 :button-keymap gnus-widget-button-keymap)
4958 ;; Do the handles
4959 (while (setq handle (pop handles))
4960 (gnus-add-text-properties
4961 (setq from (point))
4962 (progn
4963 (insert (format "(%c) %-18s"
4964 (if (equal handle preferred) ?* ? )
4965 (mm-handle-media-type handle)))
4966 (point))
4967 `(gnus-callback
4968 (lambda (handles)
4969 (unless ,(not ibegend)
4970 (setq gnus-article-mime-handle-alist
4971 ',gnus-article-mime-handle-alist))
4972 (gnus-mime-display-alternative
4973 ',ihandles ',handle ',begend ,id))
23f87bed 4974 ,@(gnus-local-map-property gnus-mime-button-map)
16409b0b
GM
4975 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4976 face ,gnus-article-button-face
16409b0b
GM
4977 gnus-part ,id
4978 gnus-data ,handle))
4979 (widget-convert-button 'link from (point)
4980 :action 'gnus-widget-press-button
4981 :button-keymap gnus-widget-button-keymap)
4982 (insert " "))
4983 (insert "\n\n"))
4984 (when preferred
4985 (if (stringp (car preferred))
4986 (gnus-display-mime preferred)
4987 (let ((mail-parse-charset gnus-newsgroup-charset)
a1506d29 4988 (mail-parse-ignored-charsets
16409b0b
GM
4989 (save-excursion (set-buffer gnus-summary-buffer)
4990 gnus-newsgroup-ignored-charsets)))
4991 (mm-display-part preferred)
4992 ;; Do highlighting.
4993 (save-excursion
4994 (save-restriction
4995 (narrow-to-region (car begend) (point-max))
4996 (gnus-treat-article
4997 nil (length gnus-article-mime-handle-alist)
e0bad764 4998 (gnus-article-mime-total-parts)
16409b0b
GM
4999 (mm-handle-media-type handle))))))
5000 (goto-char (point-max))
5001 (setcdr begend (point-marker)))))
5002 (when ibegend
5003 (goto-char point))))
5004
23f87bed
MB
5005(defconst gnus-article-wash-status-strings
5006 (let ((alist '((cite "c" "Possible hidden citation text"
5007 " " "All citation text visible")
5008 (headers "h" "Hidden headers"
5009 " " "All headers visible.")
5010 (pgp "p" "Encrypted or signed message status hidden"
5011 " " "No hidden encryption nor digital signature status")
5012 (signature "s" "Signature has been hidden"
5013 " " "Signature is visible")
5014 (overstrike "o" "Overstrike (^H) characters applied"
5015 " " "No overstrike characters applied")
5016 (emphasis "e" "/*_Emphasis_*/ characters applied"
5017 " " "No /*_emphasis_*/ characters applied")))
5018 result)
5019 (dolist (entry alist result)
5020 (let ((key (nth 0 entry))
5021 (on (copy-sequence (nth 1 entry)))
5022 (on-help (nth 2 entry))
5023 (off (copy-sequence (nth 3 entry)))
5024 (off-help (nth 4 entry)))
5025 (put-text-property 0 1 'help-echo on-help on)
5026 (put-text-property 0 1 'help-echo off-help off)
5027 (push (list key on off) result))))
5028 "Alist of strings describing wash status in the mode line.
5029Each entry has the form (KEY ON OF), where the KEY is a symbol
5030representing the particular washing function, ON is the string to use
5031in the article mode line when the washing function is active, and OFF
5032is the string to use when it is inactive.")
5033
5034(defun gnus-article-wash-status-entry (key value)
5035 (let ((entry (assoc key gnus-article-wash-status-strings)))
5036 (if value (nth 1 entry) (nth 2 entry))))
5037
eec82323
LMI
5038(defun gnus-article-wash-status ()
5039 "Return a string which display status of article washing."
5040 (save-excursion
5041 (set-buffer gnus-article-buffer)
16409b0b
GM
5042 (let ((cite (memq 'cite gnus-article-wash-types))
5043 (headers (memq 'headers gnus-article-wash-types))
5044 (boring (memq 'boring-headers gnus-article-wash-types))
5045 (pgp (memq 'pgp gnus-article-wash-types))
5046 (pem (memq 'pem gnus-article-wash-types))
23f87bed
MB
5047 (signed (memq 'signed gnus-article-wash-types))
5048 (encrypted (memq 'encrypted gnus-article-wash-types))
16409b0b
GM
5049 (signature (memq 'signature gnus-article-wash-types))
5050 (overstrike (memq 'overstrike gnus-article-wash-types))
5051 (emphasis (memq 'emphasis gnus-article-wash-types)))
23f87bed
MB
5052 (concat
5053 (gnus-article-wash-status-entry 'cite cite)
5054 (gnus-article-wash-status-entry 'headers (or headers boring))
5055 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5056 (gnus-article-wash-status-entry 'signature signature)
5057 (gnus-article-wash-status-entry 'overstrike overstrike)
5058 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5059
5060(defun gnus-add-wash-type (type)
5061 "Add a washing of TYPE to the current status."
5062 (add-to-list 'gnus-article-wash-types type))
5063
5064(defun gnus-delete-wash-type (type)
5065 "Add a washing of TYPE to the current status."
5066 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5067
5068(defun gnus-add-image (category image)
5069 "Add IMAGE of CATEGORY to the list of displayed images."
5070 (let ((entry (assq category gnus-article-image-alist)))
5071 (unless entry
5072 (setq entry (list category))
5073 (push entry gnus-article-image-alist))
5074 (nconc entry (list image))))
5075
5076(defun gnus-delete-images (category)
5077 "Delete all images in CATEGORY."
5078 (let ((entry (assq category gnus-article-image-alist)))
5079 (dolist (image (cdr entry))
5080 (gnus-remove-image image category))
5081 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5082 (gnus-delete-wash-type category)))
eec82323 5083
16409b0b 5084(defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6748645f
LMI
5085
5086(defun gnus-article-maybe-hide-headers ()
eec82323
LMI
5087 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5088Provided for backwards compatibility."
16409b0b
GM
5089 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5090 (not (save-excursion (set-buffer gnus-summary-buffer)
5091 gnus-have-all-headers)))
5092 (not gnus-inhibit-hiding))
5093 (gnus-article-hide-headers)))
eec82323
LMI
5094
5095;;; Article savers.
5096
5097(defun gnus-output-to-file (file-name)
5098 "Append the current article to a file named FILE-NAME."
5099 (let ((artbuf (current-buffer)))
16409b0b 5100 (with-temp-buffer
eec82323
LMI
5101 (insert-buffer-substring artbuf)
5102 ;; Append newline at end of the buffer as separator, and then
5103 ;; save it to file.
5104 (goto-char (point-max))
5105 (insert "\n")
47e77e9f
SZ
5106 (let ((file-name-coding-system nnmail-pathname-coding-system))
5107 (mm-append-to-file (point-min) (point-max) file-name))
a8151ef7 5108 t)))
eec82323
LMI
5109
5110(defun gnus-narrow-to-page (&optional arg)
5111 "Narrow the article buffer to a page.
5112If given a numerical ARG, move forward ARG pages."
5113 (interactive "P")
5114 (setq arg (if arg (prefix-numeric-value arg) 0))
5115 (save-excursion
5116 (set-buffer gnus-article-buffer)
5117 (goto-char (point-min))
5118 (widen)
5119 ;; Remove any old next/prev buttons.
5120 (when (gnus-visual-p 'page-marker)
4e7d0221 5121 (let ((inhibit-read-only t))
eec82323
LMI
5122 (gnus-remove-text-with-property 'gnus-prev)
5123 (gnus-remove-text-with-property 'gnus-next)))
23f87bed 5124 (if
eec82323
LMI
5125 (cond ((< arg 0)
5126 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5127 ((> arg 0)
5128 (re-search-forward page-delimiter nil 'move arg)))
23f87bed 5129 (goto-char (match-end 0))
eec82323
LMI
5130 (save-excursion
5131 (goto-char (point-min))
23f87bed
MB
5132 (setq gnus-page-broken
5133 (and (re-search-forward page-delimiter nil t) t))))
5134 (when gnus-page-broken
5135 (narrow-to-region
5136 (point)
5137 (if (re-search-forward page-delimiter nil 'move)
5138 (match-beginning 0)
5139 (point)))
5140 (when (and (gnus-visual-p 'page-marker)
5141 (> (point-min) (save-restriction (widen) (point-min))))
5142 (save-excursion
5143 (goto-char (point-min))
5144 (gnus-insert-prev-page-button)))
5145 (when (and (gnus-visual-p 'page-marker)
45893b95 5146 (< (point-max) (save-restriction (widen) (point-max))))
23f87bed
MB
5147 (save-excursion
5148 (goto-char (point-max))
5149 (gnus-insert-next-page-button))))))
eec82323
LMI
5150
5151;; Article mode commands
5152
5153(defun gnus-article-goto-next-page ()
5154 "Show the next page of the article."
5155 (interactive)
5156 (when (gnus-article-next-page)
5157 (goto-char (point-min))
5158 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5159
23f87bed 5160
eec82323 5161(defun gnus-article-goto-prev-page ()
23f87bed 5162 "Show the previous page of the article."
eec82323 5163 (interactive)
23f87bed
MB
5164 (if (bobp)
5165 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
eec82323
LMI
5166 (gnus-article-prev-page nil)))
5167
23f87bed
MB
5168;; This is cleaner but currently breaks `gnus-pick-mode':
5169;;
5170;; (defun gnus-article-goto-next-page ()
5171;; "Show the next page of the article."
5172;; (interactive)
5173;; (gnus-eval-in-buffer-window gnus-summary-buffer
5174;; (gnus-summary-next-page)))
5175;;
5176;; (defun gnus-article-goto-prev-page ()
5177;; "Show the next page of the article."
5178;; (interactive)
5179;; (gnus-eval-in-buffer-window gnus-summary-buffer
5180;; (gnus-summary-prev-page)))
5181
eec82323
LMI
5182(defun gnus-article-next-page (&optional lines)
5183 "Show the next page of the current article.
5184If end of article, return non-nil. Otherwise return nil.
5185Argument LINES specifies lines to be scrolled up."
5186 (interactive "p")
d8a88581 5187 (move-to-window-line -1)
eec82323
LMI
5188 (if (save-excursion
5189 (end-of-line)
5190 (and (pos-visible-in-window-p) ;Not continuation line.
23f87bed 5191 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
eec82323
LMI
5192 ;; Nothing in this page.
5193 (if (or (not gnus-page-broken)
5194 (save-excursion
5195 (save-restriction
23f87bed
MB
5196 (widen)
5197 (forward-line)
5198 (eobp)))) ;Real end-of-buffer?
5199 (progn
5200 (when gnus-article-over-scroll
5201 (gnus-article-next-page-1 lines))
5202 t) ;Nothing more.
eec82323
LMI
5203 (gnus-narrow-to-page 1) ;Go to next page.
5204 nil)
5205 ;; More in this page.
23f87bed 5206 (gnus-article-next-page-1 lines)
eec82323
LMI
5207 nil))
5208
d8a88581
MB
5209(defmacro gnus-article-beginning-of-window ()
5210 "Move point to the beginning of the window.
5211In Emacs, the point is placed at the line number which `scroll-margin'
5212specifies."
5213 (if (featurep 'xemacs)
5214 '(move-to-window-line 0)
5215 '(move-to-window-line
5216 (min (max 0 scroll-margin)
5217 (max 1 (- (window-height)
5218 (if mode-line-format 1 0)
5219 (if (and (boundp 'header-line-format)
5220 (symbol-value 'header-line-format))
5221 1 0)))))))
5222
23f87bed 5223(defun gnus-article-next-page-1 (lines)
4b91459a
MB
5224 (when (and (not (featurep 'xemacs))
5225 (numberp lines)
5226 (> lines 0)
5227 (numberp (symbol-value 'scroll-margin))
5228 (> (symbol-value 'scroll-margin) 0))
5229 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5230 ;; too many number of lines if `scroll-margin' is set as two or greater.
5231 (setq lines (min lines
5232 (max 0 (- (count-lines (window-start) (point-max))
5233 (symbol-value 'scroll-margin))))))
5234 (condition-case ()
5235 (let ((scroll-in-place nil))
5236 (scroll-up lines))
5237 (end-of-buffer
5238 ;; Long lines may cause an end-of-buffer error.
5239 (goto-char (point-max))))
5240 (gnus-article-beginning-of-window))
23f87bed 5241
eec82323
LMI
5242(defun gnus-article-prev-page (&optional lines)
5243 "Show previous page of current article.
5244Argument LINES specifies lines to be scrolled down."
5245 (interactive "p")
d8a88581 5246 (move-to-window-line 0)
eec82323
LMI
5247 (if (and gnus-page-broken
5248 (bobp)
5249 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5250 (progn
5251 (gnus-narrow-to-page -1) ;Go to previous page.
5252 (goto-char (point-max))
5253 (recenter -1))
c03ac728
MB
5254 (prog1
5255 (condition-case ()
5256 (let ((scroll-in-place nil))
5257 (scroll-down lines))
5258 (beginning-of-buffer
5259 (goto-char (point-min))))
5260 (gnus-article-beginning-of-window))))
eec82323 5261
23f87bed
MB
5262(defun gnus-article-only-boring-p ()
5263 "Decide whether there is only boring text remaining in the article.
5264Something \"interesting\" is a word of at least two letters that does
5265not have a face in `gnus-article-boring-faces'."
5266 (when (and gnus-article-skip-boring
5267 (boundp 'gnus-article-boring-faces)
5268 (symbol-value 'gnus-article-boring-faces))
5269 (save-excursion
5270 (catch 'only-boring
5271 (while (re-search-forward "\\b\\w\\w" nil t)
5272 (forward-char -1)
5273 (when (not (gnus-intersection
5274 (gnus-faces-at (point))
5275 (symbol-value 'gnus-article-boring-faces)))
5276 (throw 'only-boring nil)))
5277 (throw 'only-boring t)))))
5278
eec82323
LMI
5279(defun gnus-article-refer-article ()
5280 "Read article specified by message-id around point."
5281 (interactive)
23f87bed
MB
5282 (save-excursion
5283 (re-search-backward "[ \t]\\|^" (gnus-point-at-bol) t)
5284 (re-search-forward "<?news:<?\\|<" (gnus-point-at-eol) t)
5285 (if (re-search-forward "[^@ ]+@[^ \t>]+" (gnus-point-at-eol) t)
5286 (let ((msg-id (concat "<" (match-string 0) ">")))
eec82323 5287 (set-buffer gnus-summary-buffer)
23f87bed 5288 (gnus-summary-refer-article msg-id))
eec82323
LMI
5289 (error "No references around point"))))
5290
5291(defun gnus-article-show-summary ()
5292 "Reconfigure windows to show summary buffer."
5293 (interactive)
5294 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5295 (error "There is no summary buffer for this article buffer")
a8151ef7 5296 (gnus-article-set-globals)
eec82323 5297 (gnus-configure-windows 'article)
6748645f
LMI
5298 (gnus-summary-goto-subject gnus-current-article)
5299 (gnus-summary-position-point)))
eec82323
LMI
5300
5301(defun gnus-article-describe-briefly ()
5302 "Describe article mode commands briefly."
5303 (interactive)
16409b0b 5304 (gnus-message 6 (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")))
eec82323
LMI
5305
5306(defun gnus-article-summary-command ()
5307 "Execute the last keystroke in the summary buffer."
5308 (interactive)
5309 (let ((obuf (current-buffer))
5310 (owin (current-window-configuration))
5311 func)
6748645f 5312 (switch-to-buffer gnus-article-current-summary 'norecord)
eec82323
LMI
5313 (setq func (lookup-key (current-local-map) (this-command-keys)))
5314 (call-interactively func)
5315 (set-buffer obuf)
5316 (set-window-configuration owin)
5317 (set-window-point (get-buffer-window (current-buffer)) (point))))
5318
5319(defun gnus-article-summary-command-nosave ()
5320 "Execute the last keystroke in the summary buffer."
5321 (interactive)
5322 (let (func)
6748645f 5323 (pop-to-buffer gnus-article-current-summary 'norecord)
eec82323
LMI
5324 (setq func (lookup-key (current-local-map) (this-command-keys)))
5325 (call-interactively func)))
5326
16409b0b
GM
5327(defun gnus-article-check-buffer ()
5328 "Beep if not in an article buffer."
5329 (unless (equal major-mode 'gnus-article-mode)
5330 (error "Command invoked outside of a Gnus article buffer")))
5331
eec82323
LMI
5332(defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5333 "Read a summary buffer key sequence and execute it from the article buffer."
5334 (interactive "P")
16409b0b 5335 (gnus-article-check-buffer)
eec82323 5336 (let ((nosaves
23f87bed
MB
5337 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5338 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5339 "=" "^" "\M-^" "|"))
5340 (nosave-but-article
5341 '("A\r"))
5342 (nosave-in-article
5343 '("\C-d"))
5344 (up-to-top
5345 '("n" "Gn" "p" "Gp"))
5346 keys new-sum-point)
eec82323 5347 (save-excursion
6748645f 5348 (set-buffer gnus-article-current-summary)
eec82323 5349 (let (gnus-pick-mode)
23f87bed
MB
5350 (push (or key last-command-event) unread-command-events)
5351 (setq keys (if (featurep 'xemacs)
16409b0b
GM
5352 (events-to-keys (read-key-sequence nil))
5353 (read-key-sequence nil)))))
a1506d29 5354
eec82323
LMI
5355 (message "")
5356
5357 (if (or (member keys nosaves)
23f87bed
MB
5358 (member keys nosave-but-article)
5359 (member keys nosave-in-article))
5360 (let (func)
5361 (save-window-excursion
5362 (pop-to-buffer gnus-article-current-summary 'norecord)
5363 ;; We disable the pick minor mode commands.
5364 (let (gnus-pick-mode)
5365 (setq func (lookup-key (current-local-map) keys))))
5366 (if (or (not func)
16409b0b 5367 (numberp func))
23f87bed
MB
5368 (ding)
5369 (unless (member keys nosave-in-article)
5370 (set-buffer gnus-article-current-summary))
5371 (call-interactively func)
5372 (setq new-sum-point (point)))
5373 (when (member keys nosave-but-article)
5374 (pop-to-buffer gnus-article-buffer 'norecord)))
eec82323
LMI
5375 ;; These commands should restore window configuration.
5376 (let ((obuf (current-buffer))
23f87bed
MB
5377 (owin (current-window-configuration))
5378 (opoint (point))
5379 win func in-buffer selected new-sum-start new-sum-hscroll)
5380 (cond (not-restore-window
5381 (pop-to-buffer gnus-article-current-summary 'norecord))
5382 ((setq win (get-buffer-window gnus-article-current-summary))
5383 (select-window win))
5384 (t
5385 (switch-to-buffer gnus-article-current-summary 'norecord)))
5386 (setq in-buffer (current-buffer))
5387 ;; We disable the pick minor mode commands.
5388 (if (and (setq func (let (gnus-pick-mode)
520aa572
SZ
5389 (lookup-key (current-local-map) keys)))
5390 (functionp func))
23f87bed
MB
5391 (progn
5392 (call-interactively func)
5393 (when (eq win (selected-window))
5394 (setq new-sum-point (point)
5395 new-sum-start (window-start win)
9a89f5b0 5396 new-sum-hscroll (window-hscroll win)))
520aa572
SZ
5397 (when (eq in-buffer (current-buffer))
5398 (setq selected (gnus-summary-select-article))
5399 (set-buffer obuf)
5400 (unless not-restore-window
5401 (set-window-configuration owin))
5402 (when (eq selected 'old)
5403 (article-goto-body)
5404 (set-window-start (get-buffer-window (current-buffer))
5405 1)
5406 (set-window-point (get-buffer-window (current-buffer))
5407 (point)))
23f87bed
MB
5408 (when (and (not not-restore-window)
5409 new-sum-point)
5410 (set-window-point win new-sum-point)
5411 (set-window-start win new-sum-start)
9a89f5b0 5412 (set-window-hscroll win new-sum-hscroll))))
23f87bed
MB
5413 (set-window-configuration owin)
5414 (ding))))))
520aa572
SZ
5415
5416(defun gnus-article-describe-key (key)
5417 "Display documentation of the function invoked by KEY. KEY is a string."
5418 (interactive "kDescribe key: ")
5419 (gnus-article-check-buffer)
5420 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5421 (save-excursion
5422 (set-buffer gnus-article-current-summary)
5423 (let (gnus-pick-mode)
23f87bed
MB
5424 (if (featurep 'xemacs)
5425 (progn
5426 (push (elt key 0) unread-command-events)
5427 (setq key (events-to-keys
5428 (read-key-sequence "Describe key: "))))
5429 (setq unread-command-events
5430 (mapcar
5431 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5432 (string-to-list key)))
5433 (setq key (read-key-sequence "Describe key: "))))
520aa572
SZ
5434 (describe-key key))
5435 (describe-key key)))
5436
5437(defun gnus-article-describe-key-briefly (key &optional insert)
5438 "Display documentation of the function invoked by KEY. KEY is a string."
5439 (interactive "kDescribe key: \nP")
5440 (gnus-article-check-buffer)
5441 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5442 (save-excursion
5443 (set-buffer gnus-article-current-summary)
5444 (let (gnus-pick-mode)
23f87bed
MB
5445 (if (featurep 'xemacs)
5446 (progn
5447 (push (elt key 0) unread-command-events)
5448 (setq key (events-to-keys
5449 (read-key-sequence "Describe key: "))))
5450 (setq unread-command-events
5451 (mapcar
5452 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5453 (string-to-list key)))
5454 (setq key (read-key-sequence "Describe key: "))))
520aa572
SZ
5455 (describe-key-briefly key insert))
5456 (describe-key-briefly key insert)))
eec82323 5457
23f87bed
MB
5458(defun gnus-article-reply-with-original (&optional wide)
5459 "Start composing a reply mail to the current message.
5460The text in the region will be yanked. If the region isn't active,
5461the entire article will be yanked."
5462 (interactive "P")
5463 (let ((article (cdr gnus-article-current))
5464 contents)
5465 (if (not (gnus-mark-active-p))
5466 (with-current-buffer gnus-summary-buffer
5467 (gnus-summary-reply (list (list article)) wide))
5468 (setq contents (buffer-substring (point) (mark t)))
5469 ;; Deactivate active regions.
5470 (when (and (boundp 'transient-mark-mode)
5471 transient-mark-mode)
5472 (setq mark-active nil))
5473 (with-current-buffer gnus-summary-buffer
5474 (gnus-summary-reply
5475 (list (list article contents)) wide)))))
5476
5477(defun gnus-article-followup-with-original ()
5478 "Compose a followup to the current article.
5479The text in the region will be yanked. If the region isn't active,
5480the entire article will be yanked."
5481 (interactive)
5482 (let ((article (cdr gnus-article-current))
5483 contents)
5484 (if (not (gnus-mark-active-p))
5485 (with-current-buffer gnus-summary-buffer
5486 (gnus-summary-followup (list (list article))))
5487 (setq contents (buffer-substring (point) (mark t)))
5488 ;; Deactivate active regions.
5489 (when (and (boundp 'transient-mark-mode)
5490 transient-mark-mode)
5491 (setq mark-active nil))
5492 (with-current-buffer gnus-summary-buffer
5493 (gnus-summary-followup
5494 (list (list article contents)))))))
5495
eec82323
LMI
5496(defun gnus-article-hide (&optional arg force)
5497 "Hide all the gruft in the current article.
23f87bed
MB
5498This means that signatures, cited text and (some) headers will be
5499hidden.
eec82323 5500If given a prefix, show the hidden text instead."
6748645f 5501 (interactive (append (gnus-article-hidden-arg) (list 'force)))
eec82323 5502 (gnus-article-hide-headers arg)
16409b0b 5503 (gnus-article-hide-list-identifiers arg)
eec82323
LMI
5504 (gnus-article-hide-citation-maybe arg force)
5505 (gnus-article-hide-signature arg))
5506
5507(defun gnus-article-maybe-highlight ()
6748645f 5508 "Do some article highlighting if article highlighting is requested."
eec82323
LMI
5509 (when (gnus-visual-p 'article-highlight 'highlight)
5510 (gnus-article-highlight-some)))
5511
6748645f
LMI
5512(defun gnus-check-group-server ()
5513 ;; Make sure the connection to the server is alive.
5514 (unless (gnus-server-opened
5515 (gnus-find-method-for-group gnus-newsgroup-name))
5516 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5517 (gnus-request-group gnus-newsgroup-name t)))
5518
23f87bed
MB
5519(eval-when-compile
5520 (autoload 'nneething-get-file-name "nneething"))
5521
eec82323
LMI
5522(defun gnus-request-article-this-buffer (article group)
5523 "Get an article and insert it into this buffer."
6748645f 5524 (let (do-update-line sparse-header)
eec82323
LMI
5525 (prog1
5526 (save-excursion
5527 (erase-buffer)
5528 (gnus-kill-all-overlays)
5529 (setq group (or group gnus-newsgroup-name))
5530
eec82323
LMI
5531 ;; Using `gnus-request-article' directly will insert the article into
5532 ;; `nntp-server-buffer' - so we'll save some time by not having to
5533 ;; copy it from the server buffer into the article buffer.
5534
5535 ;; We only request an article by message-id when we do not have the
5536 ;; headers for it, so we'll have to get those.
5537 (when (stringp article)
16409b0b 5538 (gnus-read-header article))
eec82323
LMI
5539
5540 ;; If the article number is negative, that means that this article
5541 ;; doesn't belong in this newsgroup (possibly), so we find its
5542 ;; message-id and request it by id instead of number.
5543 (when (and (numberp article)
5544 gnus-summary-buffer
5545 (get-buffer gnus-summary-buffer)
6748645f 5546 (gnus-buffer-exists-p gnus-summary-buffer))
eec82323
LMI
5547 (save-excursion
5548 (set-buffer gnus-summary-buffer)
5549 (let ((header (gnus-summary-article-header article)))
5550 (when (< article 0)
5551 (cond
5552 ((memq article gnus-newsgroup-sparse)
5553 ;; This is a sparse gap article.
5554 (setq do-update-line article)
5555 (setq article (mail-header-id header))
16409b0b 5556 (setq sparse-header (gnus-read-header article))
eec82323
LMI
5557 (setq gnus-newsgroup-sparse
5558 (delq article gnus-newsgroup-sparse)))
5559 ((vectorp header)
5560 ;; It's a real article.
5561 (setq article (mail-header-id header)))
5562 (t
5563 ;; It is an extracted pseudo-article.
5564 (setq article 'pseudo)
5565 (gnus-request-pseudo-article header))))
5566
5567 (let ((method (gnus-find-method-for-group
5568 gnus-newsgroup-name)))
6748645f
LMI
5569 (when (and (eq (car method) 'nneething)
5570 (vectorp header))
23f87bed
MB
5571 (let ((dir (nneething-get-file-name
5572 (mail-header-id header))))
5573 (when (and (stringp dir)
5574 (file-directory-p dir))
eec82323
LMI
5575 (setq article 'nneething)
5576 (gnus-group-enter-directory dir))))))))
5577
5578 (cond
5579 ;; Refuse to select canceled articles.
5580 ((and (numberp article)
5581 gnus-summary-buffer
5582 (get-buffer gnus-summary-buffer)
6748645f 5583 (gnus-buffer-exists-p gnus-summary-buffer)
eec82323
LMI
5584 (eq (cdr (save-excursion
5585 (set-buffer gnus-summary-buffer)
5586 (assq article gnus-newsgroup-reads)))
5587 gnus-canceled-mark))
5588 nil)
5589 ;; We first check `gnus-original-article-buffer'.
5590 ((and (get-buffer gnus-original-article-buffer)
5591 (numberp article)
5592 (save-excursion
5593 (set-buffer gnus-original-article-buffer)
5594 (and (equal (car gnus-original-article) group)
5595 (eq (cdr gnus-original-article) article))))
5596 (insert-buffer-substring gnus-original-article-buffer)
5597 'article)
5598 ;; Check the backlog.
5599 ((and gnus-keep-backlog
5600 (gnus-backlog-request-article group article (current-buffer)))
5601 'article)
5602 ;; Check asynchronous pre-fetch.
5603 ((gnus-async-request-fetched-article group article (current-buffer))
5604 (gnus-async-prefetch-next group article gnus-summary-buffer)
6748645f
LMI
5605 (when (and (numberp article) gnus-keep-backlog)
5606 (gnus-backlog-enter-article group article (current-buffer)))
eec82323
LMI
5607 'article)
5608 ;; Check the cache.
5609 ((and gnus-use-cache
5610 (numberp article)
5611 (gnus-cache-request-article article group))
5612 'article)
23f87bed
MB
5613 ;; Check the agent cache.
5614 ((gnus-agent-request-article article group)
5615 'article)
eec82323 5616 ;; Get the article and put into the article buffer.
16409b0b
GM
5617 ((or (stringp article)
5618 (numberp article))
5619 (let ((gnus-override-method gnus-override-method)
a1506d29 5620 (methods (and (stringp article)
16409b0b 5621 gnus-refer-article-method))
23f87bed
MB
5622 (backend (car (gnus-find-method-for-group
5623 gnus-newsgroup-name)))
16409b0b 5624 result
4e7d0221 5625 (inhibit-read-only t))
e0bad764
DL
5626 (if (or (not (listp methods))
5627 (and (symbolp (car methods))
5628 (assq (car methods) nnoo-definition-alist)))
5629 (setq methods (list methods)))
16409b0b
GM
5630 (when (and (null gnus-override-method)
5631 methods)
5632 (setq gnus-override-method (pop methods)))
5633 (while (not result)
5634 (when (eq gnus-override-method 'current)
c55f89a5
GM
5635 (setq gnus-override-method
5636 (with-current-buffer gnus-summary-buffer
5637 gnus-current-select-method)))
16409b0b
GM
5638 (erase-buffer)
5639 (gnus-kill-all-overlays)
5640 (let ((gnus-newsgroup-name group))
5641 (gnus-check-group-server))
23f87bed
MB
5642 (cond
5643 ((gnus-request-article article group (current-buffer))
16409b0b 5644 (when (numberp article)
a1506d29 5645 (gnus-async-prefetch-next group article
16409b0b
GM
5646 gnus-summary-buffer)
5647 (when gnus-keep-backlog
5648 (gnus-backlog-enter-article
5649 group article (current-buffer))))
5650 (setq result 'article))
23f87bed
MB
5651 (methods
5652 (setq gnus-override-method (pop methods)))
5653 ((not (string-match "^400 "
5654 (nnheader-get-report backend)))
5655 ;; If we get 400 server disconnect, reconnect and
5656 ;; retry; otherwise, assume the article has expired.
5657 (setq result 'done))))
16409b0b 5658 (and (eq result 'article) 'article)))
eec82323
LMI
5659 ;; It was a pseudo.
5660 (t article)))
5661
6748645f
LMI
5662 ;; Associate this article with the current summary buffer.
5663 (setq gnus-article-current-summary gnus-summary-buffer)
5664
eec82323
LMI
5665 ;; Take the article from the original article buffer
5666 ;; and place it in the buffer it's supposed to be in.
5667 (when (and (get-buffer gnus-article-buffer)
eec82323
LMI
5668 (equal (buffer-name (current-buffer))
5669 (buffer-name (get-buffer gnus-article-buffer))))
5670 (save-excursion
5671 (if (get-buffer gnus-original-article-buffer)
6748645f
LMI
5672 (set-buffer gnus-original-article-buffer)
5673 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
16409b0b 5674 (buffer-disable-undo)
eec82323 5675 (setq major-mode 'gnus-original-article-mode)
6748645f 5676 (setq buffer-read-only t))
23f87bed 5677 (let ((inhibit-read-only t))
eec82323
LMI
5678 (erase-buffer)
5679 (insert-buffer-substring gnus-article-buffer))
16409b0b
GM
5680 (setq gnus-original-article (cons group article)))
5681
5682 ;; Decode charsets.
5683 (run-hooks 'gnus-article-decode-hook)
5684 ;; Mark article as decoded or not.
5685 (setq gnus-article-decoded-p gnus-article-decode-hook))
eec82323
LMI
5686
5687 ;; Update sparse articles.
5688 (when (and do-update-line
5689 (or (numberp article)
5690 (stringp article)))
5691 (let ((buf (current-buffer)))
5692 (set-buffer gnus-summary-buffer)
6748645f 5693 (gnus-summary-update-article do-update-line sparse-header)
eec82323 5694 (gnus-summary-goto-subject do-update-line nil t)
23f87bed 5695 (set-window-point (gnus-get-buffer-window (current-buffer) t)
eec82323
LMI
5696 (point))
5697 (set-buffer buf))))))
5698
5699;;;
5700;;; Article editing
5701;;;
5702
5703(defcustom gnus-article-edit-mode-hook nil
5704 "Hook run in article edit mode buffers."
5705 :group 'gnus-article-various
5706 :type 'hook)
5707
5708(defvar gnus-article-edit-done-function nil)
5709
5710(defvar gnus-article-edit-mode-map nil)
23f87bed 5711(defvar gnus-article-edit-mode nil)
eec82323 5712
16409b0b 5713;; Should we be using derived.el for this?
eec82323 5714(unless gnus-article-edit-mode-map
23f87bed 5715 (setq gnus-article-edit-mode-map (make-keymap))
16409b0b 5716 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
eec82323
LMI
5717
5718 (gnus-define-keys gnus-article-edit-mode-map
23f87bed 5719 "\C-c?" describe-mode
eec82323 5720 "\C-c\C-c" gnus-article-edit-done
23f87bed
MB
5721 "\C-c\C-k" gnus-article-edit-exit
5722 "\C-c\C-f\C-t" message-goto-to
5723 "\C-c\C-f\C-o" message-goto-from
5724 "\C-c\C-f\C-b" message-goto-bcc
5725 ;;"\C-c\C-f\C-w" message-goto-fcc
5726 "\C-c\C-f\C-c" message-goto-cc
5727 "\C-c\C-f\C-s" message-goto-subject
5728 "\C-c\C-f\C-r" message-goto-reply-to
5729 "\C-c\C-f\C-n" message-goto-newsgroups
5730 "\C-c\C-f\C-d" message-goto-distribution
5731 "\C-c\C-f\C-f" message-goto-followup-to
5732 "\C-c\C-f\C-m" message-goto-mail-followup-to
5733 "\C-c\C-f\C-k" message-goto-keywords
5734 "\C-c\C-f\C-u" message-goto-summary
5735 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5736 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5737 "\C-c\C-b" message-goto-body
5738 "\C-c\C-i" message-goto-signature
5739
5740 "\C-c\C-t" message-insert-to
5741 "\C-c\C-n" message-insert-newsgroups
5742 "\C-c\C-o" message-sort-headers
5743 "\C-c\C-e" message-elide-region
5744 "\C-c\C-v" message-delete-not-region
5745 "\C-c\C-z" message-kill-to-signature
5746 "\M-\r" message-newline-and-reformat
5747 "\C-c\C-a" mml-attach-file
5748 "\C-a" message-beginning-of-line
5749 "\t" message-tab
5750 "\M-;" comment-region)
eec82323
LMI
5751
5752 (gnus-define-keys (gnus-article-edit-wash-map
5753 "\C-c\C-w" gnus-article-edit-mode-map)
5754 "f" gnus-article-edit-full-stops))
5755
23f87bed
MB
5756(easy-menu-define
5757 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5758 '("Field"
5759 ["Fetch To" message-insert-to t]
5760 ["Fetch Newsgroups" message-insert-newsgroups t]
5761 "----"
5762 ["To" message-goto-to t]
5763 ["From" message-goto-from t]
5764 ["Subject" message-goto-subject t]
5765 ["Cc" message-goto-cc t]
5766 ["Reply-To" message-goto-reply-to t]
5767 ["Summary" message-goto-summary t]
5768 ["Keywords" message-goto-keywords t]
5769 ["Newsgroups" message-goto-newsgroups t]
5770 ["Followup-To" message-goto-followup-to t]
5771 ["Mail-Followup-To" message-goto-mail-followup-to t]
5772 ["Distribution" message-goto-distribution t]
5773 ["Body" message-goto-body t]
5774 ["Signature" message-goto-signature t]))
5775
4e7d0221 5776(define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
eec82323
LMI
5777 "Major mode for editing articles.
5778This is an extended text-mode.
5779
5780\\{gnus-article-edit-mode-map}"
eec82323
LMI
5781 (make-local-variable 'gnus-article-edit-done-function)
5782 (make-local-variable 'gnus-prev-winconf)
80b47379
SZ
5783 (set (make-local-variable 'font-lock-defaults)
5784 '(message-font-lock-keywords t))
23f87bed
MB
5785 (set (make-local-variable 'mail-header-separator) "")
5786 (set (make-local-variable 'gnus-article-edit-mode) t)
5787 (easy-menu-add message-mode-field-menu message-mode-map)
5788 (mml-mode)
eec82323
LMI
5789 (setq buffer-read-only nil)
5790 (buffer-enable-undo)
80b47379 5791 (widen))
eec82323
LMI
5792
5793(defun gnus-article-edit (&optional force)
5794 "Edit the current article.
5795This will have permanent effect only in mail groups.
5796If FORCE is non-nil, allow editing of articles even in read-only
5797groups."
5798 (interactive "P")
5799 (when (and (not force)
5800 (gnus-group-read-only-p))
a8151ef7 5801 (error "The current newsgroup does not support article editing"))
6748645f 5802 (gnus-article-date-original)
eec82323 5803 (gnus-article-edit-article
16409b0b 5804 'ignore
6748645f 5805 `(lambda (no-highlight)
16409b0b 5806 'ignore
eec82323
LMI
5807 (gnus-summary-edit-article-done
5808 ,(or (mail-header-references gnus-current-headers) "")
6748645f 5809 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
eec82323 5810
16409b0b 5811(defun gnus-article-edit-article (start-func exit-func)
eec82323
LMI
5812 "Start editing the contents of the current article buffer."
5813 (let ((winconf (current-window-configuration)))
5814 (set-buffer gnus-article-buffer)
0683d241
MB
5815 (let ((message-auto-save-directory
5816 ;; Don't associate the article buffer with a draft file.
5817 nil))
5818 (gnus-article-edit-mode))
16409b0b 5819 (funcall start-func)
23f87bed 5820 (set-buffer-modified-p nil)
eec82323
LMI
5821 (gnus-configure-windows 'edit-article)
5822 (setq gnus-article-edit-done-function exit-func)
5823 (setq gnus-prev-winconf winconf)
5824 (gnus-message 6 "C-c C-c to end edits")))
5825
6748645f 5826(defun gnus-article-edit-done (&optional arg)
eec82323 5827 "Update the article edits and exit."
6748645f 5828 (interactive "P")
eec82323
LMI
5829 (let ((func gnus-article-edit-done-function)
5830 (buf (current-buffer))
23f87bed
MB
5831 (start (window-start))
5832 (p (point))
5833 (winconf gnus-prev-winconf))
5834 (widen) ;; Widen it in case that users narrowed the buffer.
5835 (funcall func arg)
5836 (set-buffer buf)
5837 ;; The cache and backlog have to be flushed somewhat.
5838 (when gnus-keep-backlog
5839 (gnus-backlog-remove-article
5840 (car gnus-article-current) (cdr gnus-article-current)))
5841 ;; Flush original article as well.
eec82323 5842 (save-excursion
23f87bed
MB
5843 (when (get-buffer gnus-original-article-buffer)
5844 (set-buffer gnus-original-article-buffer)
5845 (setq gnus-original-article nil)))
5846 (when gnus-use-cache
5847 (gnus-cache-update-article
5848 (car gnus-article-current) (cdr gnus-article-current)))
5849 ;; We remove all text props from the article buffer.
5850 (kill-all-local-variables)
5851 (gnus-set-text-properties (point-min) (point-max) nil)
5852 (gnus-article-mode)
5853 (set-window-configuration winconf)
eec82323
LMI
5854 (set-buffer buf)
5855 (set-window-start (get-buffer-window buf) start)
23f87bed
MB
5856 (set-window-point (get-buffer-window buf) (point)))
5857 (gnus-summary-show-article))
eec82323
LMI
5858
5859(defun gnus-article-edit-exit ()
5860 "Exit the article editing without updating."
5861 (interactive)
23f87bed
MB
5862 (when (or (not (buffer-modified-p))
5863 (yes-or-no-p "Article modified; kill anyway? "))
5864 (let ((curbuf (current-buffer))
5865 (p (point))
5866 (window-start (window-start)))
5867 (erase-buffer)
5868 (if (gnus-buffer-live-p gnus-original-article-buffer)
d8a88581 5869 (insert-buffer-substring gnus-original-article-buffer))
23f87bed
MB
5870 (let ((winconf gnus-prev-winconf))
5871 (kill-all-local-variables)
5872 (gnus-article-mode)
5873 (set-window-configuration winconf)
5874 ;; Tippy-toe some to make sure that point remains where it was.
5875 (save-current-buffer
5876 (set-buffer curbuf)
5877 (set-window-start (get-buffer-window (current-buffer)) window-start)
5878 (goto-char p))))
5879 (gnus-summary-show-article)))
eec82323
LMI
5880
5881(defun gnus-article-edit-full-stops ()
5882 "Interactively repair spacing at end of sentences."
5883 (interactive)
5884 (save-excursion
5885 (goto-char (point-min))
5886 (search-forward-regexp "^$" nil t)
5887 (let ((case-fold-search nil))
5888 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5889
5890;;;
5891;;; Article highlights
5892;;;
5893
5894;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5895
5896;;; Internal Variables:
5897
a1506d29 5898(defcustom gnus-button-url-regexp
0076a86e 5899 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
23f87bed
MB
5900 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)"
5901 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)\\)")
eec82323
LMI
5902 "Regular expression that matches URLs."
5903 :group 'gnus-article-buttons
5904 :type 'regexp)
5905
23f87bed
MB
5906(defcustom gnus-button-valid-fqdn-regexp
5907 message-valid-fqdn-regexp
5908 "Regular expression that matches a valid FQDN."
bf247b6e 5909 :version "22.1"
23f87bed
MB
5910 :group 'gnus-article-buttons
5911 :type 'regexp)
5912
97f78c9b
MB
5913;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
5914(defcustom gnus-button-valid-localpart-regexp
5915 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*"
5916 "Regular expression that matches a localpart of mail addresses or MIDs."
5917 :version "22.1"
5918 :group 'gnus-article-buttons
5919 :type 'regexp)
5920
23f87bed
MB
5921(defcustom gnus-button-man-handler 'manual-entry
5922 "Function to use for displaying man pages.
5923The function must take at least one argument with a string naming the
5924man page."
bf247b6e 5925 :version "22.1"
23f87bed
MB
5926 :type '(choice (function-item :tag "Man" manual-entry)
5927 (function-item :tag "Woman" woman)
5928 (function :tag "Other"))
5929 :group 'gnus-article-buttons)
5930
5931(defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5932 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5933If the default site is too slow, try to find a CTAN mirror, see
5934<URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
5935the variable `gnus-button-handle-ctan'."
bf247b6e 5936 :version "22.1"
23f87bed
MB
5937 :group 'gnus-article-buttons
5938 :link '(custom-manual "(gnus)Group Parameters")
5939 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5940 (const "http://tug.ctan.org/tex-archive/")
5941 (const "http://www.dante.de/CTAN/")
5942 (string :tag "Other")))
5943
5944(defcustom gnus-button-ctan-handler 'browse-url
5945 "Function to use for displaying CTAN links.
5946The function must take one argument, the string naming the URL."
bf247b6e 5947 :version "22.1"
23f87bed
MB
5948 :type '(choice (function-item :tag "Browse Url" browse-url)
5949 (function :tag "Other"))
5950 :group 'gnus-article-buttons)
5951
5952(defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5953 "Bogus strings removed from CTAN URLs."
bf247b6e 5954 :version "22.1"
23f87bed
MB
5955 :group 'gnus-article-buttons
5956 :type '(choice (const "^/?tex-archive/\\|/")
5957 (regexp :tag "Other")))
5958
5959(defcustom gnus-button-ctan-directory-regexp
97f78c9b
MB
5960 (regexp-opt
5961 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
5962 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
5963 "languages" "macros" "nonfree" "obsolete" "support" "systems"
5964 "tds" "tools" "usergrps" "web") t)
23f87bed
MB
5965 "Regular expression for ctan directories.
5966It should match all directories in the top level of `gnus-ctan-url'."
bf247b6e 5967 :version "22.1"
23f87bed
MB
5968 :group 'gnus-article-buttons
5969 :type 'regexp)
5970
5971(defcustom gnus-button-mid-or-mail-regexp
97f78c9b 5972 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
23f87bed
MB
5973 gnus-button-valid-fqdn-regexp
5974 ">?\\)\\b")
5975 "Regular expression that matches a message ID or a mail address."
bf247b6e 5976 :version "22.1"
23f87bed
MB
5977 :group 'gnus-article-buttons
5978 :type 'regexp)
5979
5980(defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
5981 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
5982Strings like this can be either a message ID or a mail address. If it is one
5983of the symbols `mid' or `mail', Gnus will always assume that the string is a
5984message ID or a mail address, respectively. If this variable is set to the
5985symbol `ask', always query the user what do do. If it is a function, this
5986function will be called with the string as it's only argument. The function
5987must return `mid', `mail', `invalid' or `ask'."
bf247b6e 5988 :version "22.1"
23f87bed
MB
5989 :group 'gnus-article-buttons
5990 :type '(choice (function-item :tag "Heuristic function"
5991 gnus-button-mid-or-mail-heuristic)
5992 (const ask)
5993 (const mid)
5994 (const mail)))
5995
5996(defcustom gnus-button-mid-or-mail-heuristic-alist
5997 '((-10.0 . ".+\\$.+@")
5998 (-10.0 . "#")
5999 (-10.0 . "\\*")
6000 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6001 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6002 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6003 (-1.0 . "^[^a-z]+@")
6004 ;;
6005 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6006 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6007 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6008 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6009 ;;
6010 (-2.0 . "^[0-9]")
6011 (-1.0 . "^[0-9][0-9]")
6012 ;;
6013 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6014 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6015 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6016 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6017 ;;
6018 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6019 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6020 ;; "[0-9]{8,}.*\@"
6021 (-3.0
6022 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6023 ;; "[0-9]{12,}.*\@"
6024 ;; compensation for TDMA dated mail addresses:
6025 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6026 ;;
6027 (-20.0 . "\\.fsf@") ;; Gnus
6028 (-20.0 . "^slrn")
6029 (-20.0 . "^Pine")
6030 (-20.0 . "_-_") ;; Subject change in thread
6031 ;;
6032 (-20.0 . "\\.ln@") ;; leafnode
6033 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6034 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6035 ;;
6036 ;; (5.0 . "") ;; $local_part_len <= 7
6037 (10.0 . "^[^0-9]+@")
6038 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6039 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6040 (3.0 . "\@stud")
6041 ;;
6042 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6043 ;;
6044 (0.5 . "^[A-Z][a-z]")
6045 (0.5 . "^[A-Z][a-z][a-z]")
6046 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6047 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6048 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6049
6050A negative RATE indicates a message IDs, whereas a positive indicates a mail
6051address. The REGEXP is processed with `case-fold-search' set to nil."
bf247b6e 6052 :version "22.1"
23f87bed
MB
6053 :group 'gnus-article-buttons
6054 :type '(repeat (cons (number :tag "Rate")
6055 (regexp :tag "Regexp"))))
6056
6057(defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6058 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6059Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6060address, `ask' if unsure and `invalid' if the string is invalid."
6061 (let ((case-fold-search nil)
6062 (list gnus-button-mid-or-mail-heuristic-alist)
6063 (result 0) rate regexp lpartlen elem)
6064 (setq lpartlen
6065 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6066 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6067 ;; Certain special cases...
6068 (when (string-match
6069 (concat
6070 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6071 "^[0-9]+\\.[0-9]+@compuserve\\|"
6072 "@public\\.gmane\\.org")
6073 mid-or-mail)
6074 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6075 (setq result 'mail))
6076 (when (string-match "@.*@\\| " mid-or-mail)
6077 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6078 (setq result 'invalid))
6079 ;; Nothing more to do, if result is not a number here...
6080 (when (numberp result)
6081 (while list
6082 (setq elem (car list)
6083 rate (car elem)
6084 regexp (cdr elem)
6085 list (cdr list))
6086 (when (string-match regexp mid-or-mail)
6087 (setq result (+ result rate))
6088 (gnus-message
6089 9 "`%s' matched `%s', rate `%s', result `%s'."
6090 mid-or-mail regexp rate result)))
6091 (when (<= lpartlen 7)
6092 (setq result (+ result 5.0))
6093 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6094 mid-or-mail result))
6095 (when (>= lpartlen 12)
6096 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6097 (cond
6098 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6099 ;; Long local part should contain realname if e-mail address,
6100 ;; too many digits: message-id.
6101 ;; $score -= 5.0 + 0.1 * $local_part_len;
6102 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6103 (setq result (+ result rate))
6104 (gnus-message
6105 9 "Many digits in `%s', rate `%s', result `%s'."
6106 mid-or-mail rate result))
6107 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6108 mid-or-mail)
6109 ;; Too few vowels [^aeiouy]{4,}.*\@
6110 (setq result (+ result -5.0))
6111 (gnus-message
6112 9 "Few vowels in `%s', rate `%s', result `%s'."
6113 mid-or-mail -5.0 result))
6114 (t
6115 (setq result (+ result 5.0))
6116 (gnus-message
6117 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6118 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6119 ;; Maybe we should make this a customizable alist: (condition . 'result)
6120 (cond
6121 ((symbolp result) result)
6122 ;; Now convert number into proper results:
6123 ((< result -10.0) 'mid)
6124 ((> result 10.0) 'mail)
6125 (t 'ask))))
6126
6127(defun gnus-button-handle-mid-or-mail (mid-or-mail)
6128 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6129 (url-mid (concat "news" ":" mid-or-mail))
6130 (url-mailto (concat "mailto" ":" mid-or-mail)))
6131 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6132 (when (fboundp pref)
6133 (setq guessed
6134 ;; get rid of surrounding angles...
6135 (funcall pref
6136 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6137 (if (or (eq 'mid guessed) (eq 'mail guessed))
6138 (setq pref guessed)
6139 (setq pref 'ask)))
6140 (if (eq pref 'ask)
6141 (save-window-excursion
6142 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6143 (setq pref 'mail)
6144 (setq pref 'mid))))
6145 (cond ((eq pref 'mid)
6146 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6147 (gnus-button-handle-news url-mid))
6148 ((eq pref 'mail)
6149 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6150 (gnus-url-mailto url-mailto))
6151 (t (gnus-message 3 "Invalid string.")))))
6152
6153(defun gnus-button-handle-custom (url)
6154 "Follow a Custom URL."
6155 (customize-apropos (gnus-url-unhex-string url)))
6156
6157(defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6158
6159;; FIXME: Maybe we should merge some of the functions that do quite similar
6160;; stuff?
6161
6162(defun gnus-button-handle-describe-function (url)
6163 "Call `describe-function' when pushing the corresponding URL button."
6164 (describe-function
6165 (intern
6166 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6167
6168(defun gnus-button-handle-describe-variable (url)
6169 "Call `describe-variable' when pushing the corresponding URL button."
6170 (describe-variable
6171 (intern
6172 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6173
6174(defun gnus-button-handle-symbol (url)
6175"Display help on variable or function.
6176Calls `describe-variable' or `describe-function'."
6177 (let ((sym (intern url)))
6178 (cond
6179 ((fboundp sym) (describe-function sym))
6180 ((boundp sym) (describe-variable sym))
6181 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6182
6183(defun gnus-button-handle-describe-key (url)
6184 "Call `describe-key' when pushing the corresponding URL button."
6185 (let* ((key-string
6186 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6187 (keys (ignore-errors (eval `(kbd ,key-string)))))
6188 (if keys
6189 (describe-key keys)
6190 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6191
6192(defun gnus-button-handle-apropos (url)
6193 "Call `apropos' when pushing the corresponding URL button."
6194 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6195
6196(defun gnus-button-handle-apropos-command (url)
6197 "Call `apropos' when pushing the corresponding URL button."
6198 (apropos-command
6199 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6200
6201(defun gnus-button-handle-apropos-variable (url)
6202 "Call `apropos' when pushing the corresponding URL button."
6203 (funcall
6204 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6205 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6206
6207(defun gnus-button-handle-apropos-documentation (url)
6208 "Call `apropos' when pushing the corresponding URL button."
6209 (funcall
6210 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6211 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6212
6213(defun gnus-button-handle-library (url)
6214 "Call `locate-library' when pushing the corresponding URL button."
6215 (gnus-message 9 "url=`%s'" url)
6216 (let* ((lib (locate-library url))
6217 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6218 (if (not lib)
6219 (gnus-message 1 "Cannot locale library `%s'." url)
6220 (find-file-read-only file))))
6221
6222(defun gnus-button-handle-ctan (url)
6223 "Call `browse-url' when pushing a CTAN URL button."
6224 (funcall
6225 gnus-button-ctan-handler
6226 (concat
6227 gnus-ctan-url
6228 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6229
6230(defcustom gnus-button-tex-level 5
6231 "*Integer that says how many TeX-related buttons Gnus will show.
6232The higher the number, the more buttons will appear and the more false
6233positives are possible. Note that you can set this variable local to
6234specific groups. Setting it higher in TeX groups is probably a good idea.
6235See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6236how to set variables in specific groups."
bf247b6e 6237 :version "22.1"
23f87bed
MB
6238 :group 'gnus-article-buttons
6239 :link '(custom-manual "(gnus)Group Parameters")
6240 :type 'integer)
6241
6242(defcustom gnus-button-man-level 5
6243 "*Integer that says how many man-related buttons Gnus will show.
6244The higher the number, the more buttons will appear and the more false
6245positives are possible. Note that you can set this variable local to
6246specific groups. Setting it higher in Unix groups is probably a good idea.
6247See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6248how to set variables in specific groups."
bf247b6e 6249 :version "22.1"
23f87bed
MB
6250 :group 'gnus-article-buttons
6251 :link '(custom-manual "(gnus)Group Parameters")
6252 :type 'integer)
6253
6254(defcustom gnus-button-emacs-level 5
6255 "*Integer that says how many emacs-related buttons Gnus will show.
6256The higher the number, the more buttons will appear and the more false
6257positives are possible. Note that you can set this variable local to
6258specific groups. Setting it higher in Emacs or Gnus related groups is
6259probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6260`gnus-parameters' on how to set variables in specific groups."
bf247b6e 6261 :version "22.1"
23f87bed
MB
6262 :group 'gnus-article-buttons
6263 :link '(custom-manual "(gnus)Group Parameters")
6264 :type 'integer)
6265
6266(defcustom gnus-button-message-level 5
6267 "*Integer that says how many buttons for news or mail messages will appear.
6268The higher the number, the more buttons will appear and the more false
6269positives are possible."
6270 ;; mail addresses, MIDs, URLs for news, ...
bf247b6e 6271 :version "22.1"
23f87bed
MB
6272 :group 'gnus-article-buttons
6273 :type 'integer)
6274
6275(defcustom gnus-button-browse-level 5
6276 "*Integer that says how many buttons for browsing will appear.
6277The higher the number, the more buttons will appear and the more false
6278positives are possible."
6279 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
bf247b6e 6280 :version "22.1"
23f87bed
MB
6281 :group 'gnus-article-buttons
6282 :type 'integer)
6283
eec82323 6284(defcustom gnus-button-alist
23f87bed
MB
6285 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6286 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
97f78c9b
MB
6287 ((concat "\\b\\(nntp\\|news\\):\\("
6288 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6289 0 t gnus-button-handle-news 2)
23f87bed
MB
6290 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6291 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6292 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6293 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6294 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6295 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6296 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6297 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6298 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6299 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6300 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6301 ;; RFC 2368 (The mailto URL scheme)
531e5812 6302 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
6303 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6304 ("\\bmailto:\\([^ \n\t]+\\)"
6305 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6306 ;; CTAN
6307 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6308 gnus-button-ctan-directory-regexp
6309 "[^][>)!;:,'\n\t ]+\\)")
6310 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6311 ((concat "\\btex-archive/\\("
6312 gnus-button-ctan-directory-regexp
6313 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6314 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6315 ((concat
6316 "\\b\\("
6317 gnus-button-ctan-directory-regexp
6318 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6319 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6320 ;; This is info (home-grown style) <info://foo/bar+baz>
6321 ("\\binfo://\\([^'\">\n\t ]+\\)"
6322 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6323 ;; Info GNOME style <info:foo#bar_baz>
6324 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6325 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6326 ;; Info KDE style <info:(foo)bar baz>
6327 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6328 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6329 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6330 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6331 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6332 ;; Info links like `C-h i d m CC Mode RET'
6333 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6334 ;; This is custom
6335 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6336 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6337 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6338 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6339 ;; Emacs help commands
6340 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6341 ;; regexp doesn't match arguments containing ` '.
6342 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6343 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6344 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6345 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6346 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6347 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6348 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6349 ;; The following entries may lead to many false positives so don't enable
531e5812
MB
6350 ;; them by default (use a high button level).
6351 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6352 ;; Exclude [.?] for URLs in gmane.emacs.cvs
23f87bed
MB
6353 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6354 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6355 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6356 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6357 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6358 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6359 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6360 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6361 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6362 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6363 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6364 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6365 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6366 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6367 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6368 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6369 ;; Unlike the other regexps we really have to require quoting
6370 ;; here to determine where it ends.
6371 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6372 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6373 ("<URL: *\\([^<>]*\\)>"
6374 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6375 ;; RFC 2396 (2.4.3., delims) ...
6376 ("\"URL: *\\([^\"]*\\)\""
6377 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6378 ;; RFC 2396 (2.4.3., delims) ...
6379 ("\"URL: *\\([^\"]*\\)\""
6380 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
eec82323 6381 ;; Raw URLs.
23f87bed
MB
6382 (gnus-button-url-regexp
6383 0 (>= gnus-button-browse-level 0) browse-url 0)
6384 ;; man pages
531e5812 6385 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
23f87bed
MB
6386 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6387 gnus-button-handle-man 1)
6388 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
531e5812 6389 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
23f87bed
MB
6390 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6391 gnus-button-handle-man 1)
6392 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6393 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
531e5812 6394 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
23f87bed
MB
6395 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6396 ;; MID or mail: To avoid too many false positives we don't try to catch
6397 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6398 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6399 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6400 ;; so that non-ambiguous entries (see above) match first.
6401 (gnus-button-mid-or-mail-regexp
6402 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6748645f 6403 "*Alist of regexps matching buttons in article bodies.
eec82323
LMI
6404
6405Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
23f87bed
MB
6406REGEXP: is the string (case insensitive) matching text around the button (can
6407also be Lisp expression evaluating to a string),
eec82323 6408BUTTON: is the number of the regexp grouping actually matching the button,
4e7d0221 6409FORM: is a Lisp expression which must eval to true for the button to
eec82323
LMI
6410be added,
6411CALLBACK: is the function to call when the user push this button, and each
6412PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6413
6414CALLBACK can also be a variable, in that case the value of that
6415variable it the real callback function."
6416 :group 'gnus-article-buttons
23f87bed 6417 :type '(repeat (list (choice regexp variable sexp)
eec82323
LMI
6418 (integer :tag "Button")
6419 (sexp :tag "Form")
6420 (function :tag "Callback")
6421 (repeat :tag "Par"
6422 :inline t
6423 (integer :tag "Regexp group")))))
6424
6425(defcustom gnus-header-button-alist
23f87bed
MB
6426 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6427 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6428 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6429 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
eec82323 6430 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
fa9a04e1 6431 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
23f87bed
MB
6432 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6433 0 (>= gnus-button-browse-level 0) browse-url 0)
6434 ("^Subject:" gnus-button-url-regexp
6435 0 (>= gnus-button-browse-level 0) browse-url 0)
6436 ("^[^:]+:" gnus-button-url-regexp
6437 0 (>= gnus-button-browse-level 0) browse-url 0)
531e5812 6438 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
23f87bed
MB
6439 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6440 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6441 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6748645f 6442 "*Alist of headers and regexps to match buttons in article heads.
eec82323
LMI
6443
6444This alist is very similar to `gnus-button-alist', except that each
6445alist has an additional HEADER element first in each entry:
6446
6447\(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6448
6449HEADER is a regexp to match a header. For a fuller explanation, see
6450`gnus-button-alist'."
6451 :group 'gnus-article-buttons
6452 :group 'gnus-article-headers
6453 :type '(repeat (list (regexp :tag "Header")
23f87bed 6454 (choice regexp variable)
eec82323
LMI
6455 (integer :tag "Button")
6456 (sexp :tag "Form")
6457 (function :tag "Callback")
6458 (repeat :tag "Par"
6459 :inline t
6460 (integer :tag "Regexp group")))))
6461
6462(defvar gnus-button-regexp nil)
6463(defvar gnus-button-marker-list nil)
6464;; Regexp matching any of the regexps from `gnus-button-alist'.
6465
6466(defvar gnus-button-last nil)
6467;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
6468
6469;;; Commands:
6470
6471(defun gnus-article-push-button (event)
6472 "Check text under the mouse pointer for a callback function.
6473If the text under the mouse pointer has a `gnus-callback' property,
6474call it with the value of the `gnus-data' text property."
6475 (interactive "e")
6476 (set-buffer (window-buffer (posn-window (event-start event))))
6477 (let* ((pos (posn-point (event-start event)))
23f87bed 6478 (data (get-text-property pos 'gnus-data))
eec82323 6479 (fun (get-text-property pos 'gnus-callback)))
6748645f 6480 (goto-char pos)
eec82323
LMI
6481 (when fun
6482 (funcall fun data))))
6483
6484(defun gnus-article-press-button ()
6485 "Check text at point for a callback function.
6486If the text at point has a `gnus-callback' property,
6487call it with the value of the `gnus-data' text property."
6488 (interactive)
23f87bed
MB
6489 (let ((data (get-text-property (point) 'gnus-data))
6490 (fun (get-text-property (point) 'gnus-callback)))
eec82323
LMI
6491 (when fun
6492 (funcall fun data))))
6493
eec82323
LMI
6494(defun gnus-article-highlight (&optional force)
6495 "Highlight current article.
6496This function calls `gnus-article-highlight-headers',
6497`gnus-article-highlight-citation',
6498`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6499do the highlighting. See the documentation for those functions."
6500 (interactive (list 'force))
6501 (gnus-article-highlight-headers)
6502 (gnus-article-highlight-citation force)
6503 (gnus-article-highlight-signature)
6504 (gnus-article-add-buttons force)
6505 (gnus-article-add-buttons-to-head))
6506
6507(defun gnus-article-highlight-some (&optional force)
6508 "Highlight current article.
6509This function calls `gnus-article-highlight-headers',
6510`gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6511do the highlighting. See the documentation for those functions."
6512 (interactive (list 'force))
6513 (gnus-article-highlight-headers)
6514 (gnus-article-highlight-signature)
6515 (gnus-article-add-buttons))
6516
6517(defun gnus-article-highlight-headers ()
6518 "Highlight article headers as specified by `gnus-header-face-alist'."
6519 (interactive)
6520 (save-excursion
6521 (set-buffer gnus-article-buffer)
6522 (save-restriction
6523 (let ((alist gnus-header-face-alist)
4e7d0221 6524 (inhibit-read-only t)
eec82323
LMI
6525 (case-fold-search t)
6526 (inhibit-point-motion-hooks t)
6527 entry regexp header-face field-face from hpoints fpoints)
16409b0b 6528 (article-narrow-to-head)
eec82323
LMI
6529 (while (setq entry (pop alist))
6530 (goto-char (point-min))
6531 (setq regexp (concat "^\\("
6532 (if (string-equal "" (nth 0 entry))
6533 "[^\t ]"
6534 (nth 0 entry))
6535 "\\)")
6536 header-face (nth 1 entry)
6537 field-face (nth 2 entry))
6538 (while (and (re-search-forward regexp nil t)
6539 (not (eobp)))
6540 (beginning-of-line)
6541 (setq from (point))
6542 (unless (search-forward ":" nil t)
6543 (forward-char 1))
6544 (when (and header-face
6545 (not (memq (point) hpoints)))
6546 (push (point) hpoints)
6547 (gnus-put-text-property from (point) 'face header-face))
6548 (when (and field-face
6549 (not (memq (setq from (point)) fpoints)))
6550 (push from fpoints)
6551 (if (re-search-forward "^[^ \t]" nil t)
6552 (forward-char -2)
6553 (goto-char (point-max)))
6554 (gnus-put-text-property from (point) 'face field-face))))))))
6555
6556(defun gnus-article-highlight-signature ()
6557 "Highlight the signature in an article.
6558It does this by highlighting everything after
0f49874b 6559`gnus-signature-separator' using the face `gnus-signature'."
eec82323
LMI
6560 (interactive)
6561 (save-excursion
6562 (set-buffer gnus-article-buffer)
4e7d0221 6563 (let ((inhibit-read-only t)
eec82323
LMI
6564 (inhibit-point-motion-hooks t))
6565 (save-restriction
6566 (when (and gnus-signature-face
6567 (gnus-article-narrow-to-signature))
6568 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6569 'face gnus-signature-face)
6570 (widen)
6571 (gnus-article-search-signature)
6572 (let ((start (match-beginning 0))
6573 (end (set-marker (make-marker) (1+ (match-end 0)))))
6574 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6575 end)))))))
6576
6577(defun gnus-button-in-region-p (b e prop)
6578 "Say whether PROP exists in the region."
6579 (text-property-not-all b e prop nil))
6580
6581(defun gnus-article-add-buttons (&optional force)
6582 "Find external references in the article and make buttons of them.
6583\"External references\" are things like Message-IDs and URLs, as
6584specified by `gnus-button-alist'."
6585 (interactive (list 'force))
6586 (save-excursion
6587 (set-buffer gnus-article-buffer)
4e7d0221 6588 (let ((inhibit-read-only t)
eec82323
LMI
6589 (inhibit-point-motion-hooks t)
6590 (case-fold-search t)
6591 (alist gnus-button-alist)
6592 beg entry regexp)
6593 ;; Remove all old markers.
16409b0b 6594 (let (marker entry new-list)
eec82323 6595 (while (setq marker (pop gnus-button-marker-list))
16409b0b
GM
6596 (if (or (< marker (point-min)) (>= marker (point-max)))
6597 (push marker new-list)
6598 (goto-char marker)
6599 (when (setq entry (gnus-button-entry))
6600 (put-text-property (match-beginning (nth 1 entry))
6601 (match-end (nth 1 entry))
6602 'gnus-callback nil))
6603 (set-marker marker nil)))
6604 (setq gnus-button-marker-list new-list))
eec82323 6605 ;; We skip the headers.
16409b0b 6606 (article-goto-body)
eec82323
LMI
6607 (setq beg (point))
6608 (while (setq entry (pop alist))
23f87bed 6609 (setq regexp (eval (car entry)))
eec82323
LMI
6610 (goto-char beg)
6611 (while (re-search-forward regexp nil t)
6612 (let* ((start (and entry (match-beginning (nth 1 entry))))
6613 (end (and entry (match-end (nth 1 entry))))
6614 (from (match-beginning 0)))
6615 (when (and (or (eq t (nth 2 entry))
6616 (eval (nth 2 entry)))
6617 (not (gnus-button-in-region-p
6618 start end 'gnus-callback)))
6619 ;; That optional form returned non-nil, so we add the
6620 ;; button.
6621 (gnus-article-add-button
6622 start end 'gnus-button-push
6623 (car (push (set-marker (make-marker) from)
6624 gnus-button-marker-list))))))))))
6625
6626;; Add buttons to the head of an article.
6627(defun gnus-article-add-buttons-to-head ()
6628 "Add buttons to the head of the article."
6629 (interactive)
6630 (save-excursion
6631 (set-buffer gnus-article-buffer)
16409b0b 6632 (save-restriction
4e7d0221 6633 (let ((inhibit-read-only t)
16409b0b
GM
6634 (inhibit-point-motion-hooks t)
6635 (case-fold-search t)
6636 (alist gnus-header-button-alist)
6637 entry beg end)
6638 (article-narrow-to-head)
6639 (while alist
6640 ;; Each alist entry.
6641 (setq entry (car alist)
6642 alist (cdr alist))
6643 (goto-char (point-min))
6644 (while (re-search-forward (car entry) nil t)
6645 ;; Each header matching the entry.
6646 (setq beg (match-beginning 0))
6647 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6648 (match-beginning 0))
6649 (point-max)))
6650 (goto-char beg)
23f87bed 6651 (while (re-search-forward (eval (nth 1 entry)) end t)
16409b0b
GM
6652 ;; Each match within a header.
6653 (let* ((entry (cdr entry))
6654 (start (match-beginning (nth 1 entry)))
6655 (end (match-end (nth 1 entry)))
6656 (form (nth 2 entry)))
6657 (goto-char (match-end 0))
6658 (when (eval form)
6659 (gnus-article-add-button
6660 start end (nth 3 entry)
6661 (buffer-substring (match-beginning (nth 4 entry))
6662 (match-end (nth 4 entry)))))))
6663 (goto-char end)))))))
eec82323
LMI
6664
6665;;; External functions:
6666
6667(defun gnus-article-add-button (from to fun &optional data)
6668 "Create a button between FROM and TO with callback FUN and data DATA."
6669 (when gnus-article-button-face
6670 (gnus-overlay-put (gnus-make-overlay from to)
6671 'face gnus-article-button-face))
6672 (gnus-add-text-properties
6673 from to
6674 (nconc (and gnus-article-mouse-face
6675 (list gnus-mouse-face-prop gnus-article-mouse-face))
6676 (list 'gnus-callback fun)
16409b0b
GM
6677 (and data (list 'gnus-data data))))
6678 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6679 :button-keymap gnus-widget-button-keymap))
eec82323
LMI
6680
6681;;; Internal functions:
6682
a8151ef7
LMI
6683(defun gnus-article-set-globals ()
6684 (save-excursion
6685 (set-buffer gnus-summary-buffer)
6686 (gnus-set-global-variables)))
6687
eec82323
LMI
6688(defun gnus-signature-toggle (end)
6689 (save-excursion
6690 (set-buffer gnus-article-buffer)
4e7d0221 6691 (let ((inhibit-read-only t)
eec82323 6692 (inhibit-point-motion-hooks t))
520aa572 6693 (if (text-property-any end (point-max) 'article-type 'signature)
23f87bed
MB
6694 (progn
6695 (gnus-delete-wash-type 'signature)
6696 (gnus-remove-text-properties-when
6697 'article-type 'signature end (point-max)
6698 (cons 'article-type (cons 'signature
6699 gnus-hidden-properties))))
6700 (gnus-add-wash-type 'signature)
520aa572
SZ
6701 (gnus-add-text-properties-when
6702 'article-type nil end (point-max)
6703 (cons 'article-type (cons 'signature
23f87bed
MB
6704 gnus-hidden-properties)))))
6705 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6706 (gnus-set-mode-line 'article))))
eec82323
LMI
6707
6708(defun gnus-button-entry ()
6709 ;; Return the first entry in `gnus-button-alist' matching this place.
6710 (let ((alist gnus-button-alist)
6711 (entry nil))
6712 (while alist
6713 (setq entry (pop alist))
23f87bed 6714 (if (looking-at (eval (car entry)))
eec82323
LMI
6715 (setq alist nil)
6716 (setq entry nil)))
6717 entry))
6718
6719(defun gnus-button-push (marker)
6720 ;; Push button starting at MARKER.
6721 (save-excursion
eec82323
LMI
6722 (goto-char marker)
6723 (let* ((entry (gnus-button-entry))
6724 (inhibit-point-motion-hooks t)
6725 (fun (nth 3 entry))
6726 (args (mapcar (lambda (group)
6727 (let ((string (match-string group)))
6728 (gnus-set-text-properties
6729 0 (length string) nil string)
6730 string))
6731 (nthcdr 4 entry))))
6732 (cond
6733 ((fboundp fun)
6734 (apply fun args))
6735 ((and (boundp fun)
6736 (fboundp (symbol-value fun)))
6737 (apply (symbol-value fun) args))
6738 (t
6739 (gnus-message 1 "You must define `%S' to use this button"
6740 (cons fun args)))))))
6741
23f87bed 6742(defun gnus-parse-news-url (url)
82a8ad04 6743 (let (scheme server port group message-id articles)
23f87bed
MB
6744 (with-temp-buffer
6745 (insert url)
6746 (goto-char (point-min))
6747 (when (looking-at "\\([A-Za-z]+\\):")
6748 (setq scheme (match-string 1))
6749 (goto-char (match-end 0)))
82a8ad04 6750 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
23f87bed 6751 (setq server (match-string 1))
82a8ad04
MB
6752 (setq port (if (stringp (match-string 3))
6753 (string-to-number (match-string 3))
6754 (match-string 3)))
23f87bed
MB
6755 (goto-char (match-end 0)))
6756
6757 (cond
6758 ((looking-at "\\(.*@.*\\)")
6759 (setq message-id (match-string 1)))
6760 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6761 (setq group (match-string 1)
6762 articles (split-string (match-string 2) "-")))
6763 ((looking-at "\\([^/]+\\)/?")
6764 (setq group (match-string 1)))
6765 (t
6766 (error "Unknown news URL syntax"))))
82a8ad04 6767 (list scheme server port group message-id articles)))
23f87bed
MB
6768
6769(defun gnus-button-handle-news (url)
6770 "Fetch a news URL."
82a8ad04 6771 (destructuring-bind (scheme server port group message-id articles)
23f87bed
MB
6772 (gnus-parse-news-url url)
6773 (cond
6774 (message-id
6775 (save-excursion
6776 (set-buffer gnus-summary-buffer)
6777 (if server
ff4d3926
MB
6778 (let ((gnus-refer-article-method
6779 (nconc (list (list 'nntp server))
6780 gnus-refer-article-method))
82a8ad04 6781 (nntp-port-number (or port "nntp")))
ff4d3926
MB
6782 (gnus-message 7 "Fetching %s with %s"
6783 message-id gnus-refer-article-method)
23f87bed
MB
6784 (gnus-summary-refer-article message-id))
6785 (gnus-summary-refer-article message-id))))
6786 (group
6787 (gnus-button-fetch-group url)))))
6788
6789(defun gnus-button-handle-man (url)
6790 "Fetch a man page."
531e5812
MB
6791 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6792 (when (eq gnus-button-man-handler 'woman)
6793 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6794 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
23f87bed
MB
6795 (funcall gnus-button-man-handler url))
6796
6797(defun gnus-button-handle-info-url (url)
6798 "Fetch an info URL."
6799 (setq url (mm-subst-char-in-string ?+ ?\ url))
6800 (cond
6801 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6802 (gnus-info-find-node
6803 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6804 "Gnus")
6805 ")" (gnus-url-unhex-string (match-string 2 url)))))
6806 ((string-match "([^)\"]+)[^\"]+" url)
6807 (setq url
6808 (gnus-replace-in-string
6809 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6810 (gnus-info-find-node url))
6811 (t (error "Can't parse %s" url))))
6812
6813(defun gnus-button-handle-info-url-gnome (url)
6814 "Fetch GNOME style info URL."
6815 (setq url (mm-subst-char-in-string ?_ ?\ url))
6816 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
6817 (gnus-info-find-node
6818 (concat "("
bf247b6e 6819 (gnus-url-unhex-string
23f87bed
MB
6820 (match-string 1 url))
6821 ")"
bf247b6e 6822 (or (gnus-url-unhex-string
23f87bed
MB
6823 (match-string 2 url))
6824 "Top")))
6825 (error "Can't parse %s" url)))
6826
6827(defun gnus-button-handle-info-url-kde (url)
6828 "Fetch KDE style info URL."
6829 (gnus-info-find-node (gnus-url-unhex-string url)))
6830
6831(defun gnus-button-handle-info-keystrokes (url)
6832 "Call `info' when pushing the corresponding URL button."
6833 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6834 (info)
6835 (Info-directory)
6836 (Info-menu url))
6837
eec82323
LMI
6838(defun gnus-button-message-id (message-id)
6839 "Fetch MESSAGE-ID."
6840 (save-excursion
6841 (set-buffer gnus-summary-buffer)
6842 (gnus-summary-refer-article message-id)))
6843
6844(defun gnus-button-fetch-group (address)
6845 "Fetch GROUP specified by ADDRESS."
6846 (if (not (string-match "[:/]" address))
6847 ;; This is just a simple group url.
6848 (gnus-group-read-ephemeral-group address gnus-select-method)
23f87bed
MB
6849 (if (not
6850 (string-match
6851 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6852 address))
eec82323
LMI
6853 (error "Can't parse %s" address)
6854 (gnus-group-read-ephemeral-group
6855 (match-string 4 address)
6856 `(nntp ,(match-string 1 address)
6857 (nntp-address ,(match-string 1 address))
6858 (nntp-port-number ,(if (match-end 3)
6859 (match-string 3 address)
23f87bed
MB
6860 "nntp")))
6861 nil nil nil
e9bd5782 6862 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
eec82323 6863
eec82323
LMI
6864(defun gnus-url-parse-query-string (query &optional downcase)
6865 (let (retval pairs cur key val)
16409b0b 6866 (setq pairs (split-string query "&"))
eec82323
LMI
6867 (while pairs
6868 (setq cur (car pairs)
23f87bed 6869 pairs (cdr pairs))
eec82323 6870 (if (not (string-match "=" cur))
23f87bed
MB
6871 nil ; Grace
6872 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6873 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6874 (if downcase
6875 (setq key (downcase key)))
6876 (setq cur (assoc key retval))
6877 (if cur
6878 (setcdr cur (cons val (cdr cur)))
6879 (setq retval (cons (list key val) retval)))))
eec82323
LMI
6880 retval))
6881
eec82323
LMI
6882(defun gnus-url-mailto (url)
6883 ;; Send mail to someone
6884 (when (string-match "mailto:/*\\(.*\\)" url)
6885 (setq url (substring url (match-beginning 1) nil)))
6748645f 6886 (let (to args subject func)
23f87bed
MB
6887 (setq args (gnus-url-parse-query-string
6888 (if (string-match "^\\?" url)
6889 (substring url 1)
6890 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
6891 (concat "to=" (match-string 1 url) "&"
6892 (match-string 2 url))
6893 (concat "to=" url)))
6894 t)
6895 subject (cdr-safe (assoc "subject" args)))
6896 (gnus-msg-mail)
eec82323
LMI
6897 (while args
6898 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6899 (if (fboundp func)
23f87bed
MB
6900 (funcall func)
6901 (message-position-on-field (caar args)))
6902 (insert (gnus-replace-in-string
6903 (mapconcat 'identity (reverse (cdar args)) ", ")
6904 "\r\n" "\n" t))
eec82323
LMI
6905 (setq args (cdr args)))
6906 (if subject
23f87bed 6907 (message-goto-body)
eec82323
LMI
6908 (message-goto-subject))))
6909
eec82323 6910(defun gnus-button-embedded-url (address)
e0bad764 6911 "Activate ADDRESS with `browse-url'."
1b978bfc 6912 (browse-url (gnus-strip-whitespace address)))
eec82323
LMI
6913
6914;;; Next/prev buttons in the article buffer.
6915
6916(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6917(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6918
23f87bed
MB
6919(defvar gnus-prev-page-map
6920 (let ((map (make-sparse-keymap)))
6921 (unless (>= emacs-major-version 21)
6922 ;; XEmacs doesn't care.
6923 (set-keymap-parent map gnus-article-mode-map))
6924 (define-key map gnus-mouse-2 'gnus-button-prev-page)
6925 (define-key map "\r" 'gnus-button-prev-page)
6926 map))
6927
6928(defvar gnus-next-page-map
6929 (let ((map (make-sparse-keymap)))
6930 (unless (>= emacs-major-version 21)
6931 ;; XEmacs doesn't care.
6932 (set-keymap-parent map gnus-article-mode-map))
6933 (define-key map gnus-mouse-2 'gnus-button-next-page)
6934 (define-key map "\r" 'gnus-button-next-page)
6935 map))
eec82323
LMI
6936
6937(defun gnus-insert-prev-page-button ()
23f87bed
MB
6938 (let ((b (point))
6939 (inhibit-read-only t))
eec82323
LMI
6940 (gnus-eval-format
6941 gnus-prev-page-line-format nil
23f87bed
MB
6942 `(,@(gnus-local-map-property gnus-prev-page-map)
6943 gnus-prev t
6944 gnus-callback gnus-article-button-prev-page
6945 article-type annotation))
6946 (widget-convert-button
6947 'link b (if (bolp)
6948 ;; Exclude a newline.
6949 (1- (point))
6950 (point))
6951 :action 'gnus-button-prev-page
6952 :button-keymap gnus-prev-page-map)))
6953
6954(defun gnus-button-next-page (&optional args more-args)
eec82323
LMI
6955 "Go to the next page."
6956 (interactive)
6957 (let ((win (selected-window)))
23f87bed 6958 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
6959 (gnus-article-next-page)
6960 (select-window win)))
6961
23f87bed 6962(defun gnus-button-prev-page (&optional args more-args)
eec82323
LMI
6963 "Go to the prev page."
6964 (interactive)
6965 (let ((win (selected-window)))
23f87bed 6966 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
6967 (gnus-article-prev-page)
6968 (select-window win)))
6969
6970(defun gnus-insert-next-page-button ()
23f87bed
MB
6971 (let ((b (point))
6972 (inhibit-read-only t))
eec82323 6973 (gnus-eval-format gnus-next-page-line-format nil
23f87bed
MB
6974 `(,@(gnus-local-map-property gnus-next-page-map)
6975 gnus-next t
6976 gnus-callback gnus-article-button-next-page
6977 article-type annotation))
6978 (widget-convert-button
6979 'link b (if (bolp)
6980 ;; Exclude a newline.
6981 (1- (point))
6982 (point))
6983 :action 'gnus-button-next-page
6984 :button-keymap gnus-next-page-map)))
eec82323
LMI
6985
6986(defun gnus-article-button-next-page (arg)
6987 "Go to the next page."
6988 (interactive "P")
6989 (let ((win (selected-window)))
23f87bed 6990 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
6991 (gnus-article-next-page)
6992 (select-window win)))
6993
6994(defun gnus-article-button-prev-page (arg)
6995 "Go to the prev page."
6996 (interactive "P")
6997 (let ((win (selected-window)))
23f87bed 6998 (select-window (gnus-get-buffer-window gnus-article-buffer t))
eec82323
LMI
6999 (gnus-article-prev-page)
7000 (select-window win)))
7001
16409b0b
GM
7002(defvar gnus-decode-header-methods
7003 '(mail-decode-encoded-word-region)
7004 "List of methods used to decode headers.
7005
7006This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4e7d0221 7007is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
23f87bed 7008\(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
16409b0b
GM
7009whose names match REGEXP.
7010
7011For example:
8f688cb0 7012\((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
16409b0b
GM
7013 mail-decode-encoded-word-region
7014 (\"chinese\" . rfc1843-decode-region))
7015")
7016
7017(defvar gnus-decode-header-methods-cache nil)
7018
7019(defun gnus-multi-decode-header (start end)
7020 "Apply the functions from `gnus-encoded-word-methods' that match."
7021 (unless (and gnus-decode-header-methods-cache
7022 (eq gnus-newsgroup-name
7023 (car gnus-decode-header-methods-cache)))
7024 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7025 (mapcar (lambda (x)
7026 (if (symbolp x)
7027 (nconc gnus-decode-header-methods-cache (list x))
7028 (if (and gnus-newsgroup-name
7029 (string-match (car x) gnus-newsgroup-name))
7030 (nconc gnus-decode-header-methods-cache
7031 (list (cdr x))))))
7032 gnus-decode-header-methods))
7033 (let ((xlist gnus-decode-header-methods-cache))
7034 (pop xlist)
7035 (save-restriction
7036 (narrow-to-region start end)
7037 (while xlist
7038 (funcall (pop xlist) (point-min) (point-max))))))
7039
7040;;;
7041;;; Treatment top-level handling.
7042;;;
7043
7044(defun gnus-treat-article (condition &optional part-number total-parts type)
7045 (let ((length (- (point-max) (point-min)))
7046 (alist gnus-treatment-function-alist)
7047 (article-goto-body-goes-to-point-min-p t)
7048 (treated-type
7049 (or (not type)
7050 (catch 'found
7051 (let ((list gnus-article-treat-types))
7052 (while list
7053 (when (string-match (pop list) type)
7054 (throw 'found t)))))))
7055 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7056 val elem)
7057 (gnus-run-hooks 'gnus-part-display-hook)
23f87bed 7058 (dolist (elem alist)
16409b0b
GM
7059 (setq val
7060 (save-excursion
23f87bed
MB
7061 (when (gnus-buffer-live-p gnus-summary-buffer)
7062 (set-buffer gnus-summary-buffer))
16409b0b
GM
7063 (symbol-value (car elem))))
7064 (when (and (or (consp val)
7065 treated-type)
7066 (gnus-treat-predicate val)
7067 (or (not (get (car elem) 'highlight))
7068 highlightp))
7069 (save-restriction
7070 (funcall (cadr elem)))))))
7071
7072;; Dynamic variables.
e0bad764
DL
7073(eval-when-compile
7074 (defvar part-number)
7075 (defvar total-parts)
7076 (defvar type)
7077 (defvar condition)
7078 (defvar length))
7079
16409b0b
GM
7080(defun gnus-treat-predicate (val)
7081 (cond
7082 ((null val)
7083 nil)
23f87bed
MB
7084 (condition
7085 (eq condition val))
16409b0b
GM
7086 ((and (listp val)
7087 (stringp (car val)))
7088 (apply 'gnus-or (mapcar `(lambda (s)
7089 (string-match s ,(or gnus-newsgroup-name "")))
7090 val)))
7091 ((listp val)
7092 (let ((pred (pop val)))
7093 (cond
7094 ((eq pred 'or)
7095 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7096 ((eq pred 'and)
7097 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7098 ((eq pred 'not)
7099 (not (gnus-treat-predicate (car val))))
7100 ((eq pred 'typep)
7101 (equal (car val) type))
7102 (t
7103 (error "%S is not a valid predicate" pred)))))
16409b0b
GM
7104 ((eq val t)
7105 t)
7106 ((eq val 'head)
7107 nil)
7108 ((eq val 'last)
7109 (eq part-number total-parts))
7110 ((numberp val)
7111 (< length val))
7112 (t
7113 (error "%S is not a valid value" val))))
7114
23f87bed
MB
7115(defun gnus-article-encrypt-body (protocol &optional n)
7116 "Encrypt the article body."
7117 (interactive
7118 (list
7119 (or gnus-article-encrypt-protocol
7120 (completing-read "Encrypt protocol: "
7121 gnus-article-encrypt-protocol-alist
7122 nil t))
7123 current-prefix-arg))
7124 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7125 (unless func
998a5a95 7126 (error "Can't find the encrypt protocol %s" protocol))
23f87bed
MB
7127 (if (member gnus-newsgroup-name '("nndraft:delayed"
7128 "nndraft:drafts"
7129 "nndraft:queue"))
7130 (error "Can't encrypt the article in group %s"
7131 gnus-newsgroup-name))
7132 (gnus-summary-iterate n
7133 (save-excursion
7134 (set-buffer gnus-summary-buffer)
7135 (let ((mail-parse-charset gnus-newsgroup-charset)
7136 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7137 (summary-buffer gnus-summary-buffer)
7138 references point)
7139 (gnus-set-global-variables)
7140 (when (gnus-group-read-only-p)
7141 (error "The current newsgroup does not support article encrypt"))
7142 (gnus-summary-show-article t)
7143 (setq references
7144 (or (mail-header-references gnus-current-headers) ""))
7145 (set-buffer gnus-article-buffer)
7146 (let* ((inhibit-read-only t)
7147 (headers
7148 (mapcar (lambda (field)
7149 (and (save-restriction
7150 (message-narrow-to-head)
7151 (goto-char (point-min))
7152 (search-forward field nil t))
7153 (prog2
7154 (message-narrow-to-field)
7155 (buffer-string)
7156 (delete-region (point-min) (point-max))
7157 (widen))))
7158 '("Content-Type:" "Content-Transfer-Encoding:"
7159 "Content-Disposition:"))))
7160 (message-narrow-to-head)
7161 (message-remove-header "MIME-Version")
7162 (goto-char (point-max))
7163 (setq point (point))
7164 (insert (apply 'concat headers))
7165 (widen)
7166 (narrow-to-region point (point-max))
7167 (let ((message-options message-options))
7168 (message-options-set 'message-sender user-mail-address)
7169 (message-options-set 'message-recipients user-mail-address)
7170 (message-options-set 'message-sign-encrypt 'not)
7171 (funcall func))
7172 (goto-char (point-min))
7173 (insert "MIME-Version: 1.0\n")
7174 (widen)
7175 (gnus-summary-edit-article-done
7176 references nil summary-buffer t))
7177 (when gnus-keep-backlog
7178 (gnus-backlog-remove-article
7179 (car gnus-article-current) (cdr gnus-article-current)))
7180 (save-excursion
7181 (when (get-buffer gnus-original-article-buffer)
7182 (set-buffer gnus-original-article-buffer)
7183 (setq gnus-original-article nil)))
7184 (when gnus-use-cache
7185 (gnus-cache-update-article
7186 (car gnus-article-current) (cdr gnus-article-current))))))))
7187
7188(defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7189 "The following specs can be used:
7190%t The security MIME type
7191%i Additional info
7192%d Details
7193%D Details if button is pressed")
7194
7195(defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7196 "The following specs can be used:
7197%t The security MIME type
7198%i Additional info
7199%d Details
7200%D Details if button is pressed")
7201
7202(defvar gnus-mime-security-button-line-format-alist
7203 '((?t gnus-tmp-type ?s)
7204 (?i gnus-tmp-info ?s)
7205 (?d gnus-tmp-details ?s)
7206 (?D gnus-tmp-pressed-details ?s)))
7207
7208(defvar gnus-mime-security-button-map
7209 (let ((map (make-sparse-keymap)))
7210 (unless (>= (string-to-number emacs-version) 21)
7211 (set-keymap-parent map gnus-article-mode-map))
7212 (define-key map gnus-mouse-2 'gnus-article-push-button)
7213 (define-key map "\r" 'gnus-article-press-button)
7214 map))
7215
7216(defvar gnus-mime-security-details-buffer nil)
7217
7218(defvar gnus-mime-security-button-pressed nil)
7219
7220(defvar gnus-mime-security-show-details-inline t
7221 "If non-nil, show details in the article buffer.")
7222
7223(defun gnus-mime-security-verify-or-decrypt (handle)
7224 (mm-remove-parts (cdr handle))
7225 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7226 point (inhibit-read-only t))
7227 (if region
7228 (goto-char (car region)))
7229 (save-restriction
7230 (narrow-to-region (point) (point))
7231 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7232 (let* ((mm-verify-option 'known)
7233 (mm-decrypt-option 'known)
7234 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7235 (unless (eq nparts (cdr handle))
7236 (mm-destroy-parts (cdr handle))
7237 (setcdr handle nparts))))
7238 (setq point (point))
7239 (gnus-mime-display-security handle)
7240 (goto-char (point-max)))
7241 (when region
7242 (delete-region (point) (cdr region))
7243 (set-marker (car region) nil)
7244 (set-marker (cdr region) nil))
7245 (goto-char point)))
7246
7247(defun gnus-mime-security-show-details (handle)
7248 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7249 (if (not details)
7250 (gnus-message 5 "No details.")
7251 (if gnus-mime-security-show-details-inline
7252 (let ((gnus-mime-security-button-pressed
7253 (not (get-text-property (point) 'gnus-mime-details)))
7254 (gnus-mime-security-button-line-format
7255 (get-text-property (point) 'gnus-line-format))
7256 (inhibit-read-only t))
7257 (forward-char -1)
7258 (while (eq (get-text-property (point) 'gnus-line-format)
7259 gnus-mime-security-button-line-format)
7260 (forward-char -1))
7261 (forward-char)
7262 (save-restriction
7263 (narrow-to-region (point) (point))
7264 (gnus-insert-mime-security-button handle))
7265 (delete-region (point)
7266 (or (text-property-not-all
7267 (point) (point-max)
7268 'gnus-line-format
7269 gnus-mime-security-button-line-format)
7270 (point-max))))
7271 ;; Not inlined.
7272 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7273 (with-current-buffer gnus-mime-security-details-buffer
7274 (erase-buffer)
7275 t)
7276 (setq gnus-mime-security-details-buffer
7277 (gnus-get-buffer-create "*MIME Security Details*")))
7278 (with-current-buffer gnus-mime-security-details-buffer
7279 (insert details)
7280 (goto-char (point-min)))
7281 (pop-to-buffer gnus-mime-security-details-buffer)))))
7282
7283(defun gnus-mime-security-press-button (handle)
7284 (save-excursion
7285 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7286 (gnus-mime-security-show-details handle)
7287 (gnus-mime-security-verify-or-decrypt handle))))
7288
7289(defun gnus-insert-mime-security-button (handle &optional displayed)
7290 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7291 (gnus-tmp-type
7292 (concat
7293 (or (nth 2 (assoc protocol mm-verify-function-alist))
7294 (nth 2 (assoc protocol mm-decrypt-function-alist))
7295 "Unknown")
7296 (if (equal (car handle) "multipart/signed")
7297 " Signed" " Encrypted")
7298 " Part"))
7299 (gnus-tmp-info
7300 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7301 "Undecided"))
7302 (gnus-tmp-details
7303 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7304 gnus-tmp-pressed-details
7305 b e)
7306 (setq gnus-tmp-details
7307 (if gnus-tmp-details
7308 (concat "\n" gnus-tmp-details)
7309 ""))
7310 (setq gnus-tmp-pressed-details
7311 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7312 (unless (bolp)
7313 (insert "\n"))
7314 (setq b (point))
7315 (gnus-eval-format
7316 gnus-mime-security-button-line-format
7317 gnus-mime-security-button-line-format-alist
7318 `(,@(gnus-local-map-property gnus-mime-security-button-map)
7319 gnus-callback gnus-mime-security-press-button
7320 gnus-line-format ,gnus-mime-security-button-line-format
7321 gnus-mime-details ,gnus-mime-security-button-pressed
7322 article-type annotation
7323 gnus-data ,handle))
7324 (setq e (if (bolp)
7325 ;; Exclude a newline.
7326 (1- (point))
7327 (point)))
7328 (widget-convert-button
7329 'link b e
7330 :mime-handle handle
7331 :action 'gnus-widget-press-button
7332 :button-keymap gnus-mime-security-button-map
7333 :help-echo
7334 (lambda (widget/window &optional overlay pos)
7335 ;; Needed to properly clear the message due to a bug in
7336 ;; wid-edit (XEmacs only).
7337 (when (boundp 'help-echo-owns-message)
7338 (setq help-echo-owns-message t))
7339 (format
7340 "%S: show detail"
7341 (aref gnus-mouse-2 0))))))
7342
7343(defun gnus-mime-display-security (handle)
7344 (save-restriction
7345 (narrow-to-region (point) (point))
7346 (unless (gnus-unbuttonized-mime-type-p (car handle))
7347 (gnus-insert-mime-security-button handle))
7348 (gnus-mime-display-mixed (cdr handle))
7349 (unless (bolp)
7350 (insert "\n"))
7351 (unless (gnus-unbuttonized-mime-type-p (car handle))
7352 (let ((gnus-mime-security-button-line-format
7353 gnus-mime-security-button-end-line-format))
7354 (gnus-insert-mime-security-button handle)))
7355 (mm-set-handle-multipart-parameter
7356 handle 'gnus-region
7357 (cons (set-marker (make-marker) (point-min))
7358 (set-marker (make-marker) (point-max))))))
7359
eec82323
LMI
7360(gnus-ems-redefine)
7361
7362(provide 'gnus-art)
7363
7364(run-hooks 'gnus-art-load-hook)
7365
ab5796a9 7366;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
eec82323 7367;;; gnus-art.el ends here