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