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