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