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