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