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