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