87bd950c2f31c5c360a8e7f1ae3f8f48432dd029
[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               ;; We display the face.
1663               (if (symbolp gnus-article-x-face-command)
1664                   ;; The command is a lisp function, so we call it.
1665                   (if (gnus-functionp gnus-article-x-face-command)
1666                       (funcall gnus-article-x-face-command beg end)
1667                     (error "%s is not a function" gnus-article-x-face-command))
1668                 ;; The command is a string, so we interpret the command
1669                 ;; as a, well, command, and fork it off.
1670                 (let ((process-connection-type nil))
1671                   (process-kill-without-query
1672                    (start-process
1673                     "article-x-face" nil shell-file-name shell-command-switch
1674                     gnus-article-x-face-command))
1675                   (process-send-region "article-x-face" beg end)
1676                   (process-send-eof "article-x-face"))))))))))
1677
1678 (defun article-decode-mime-words ()
1679   "Decode all MIME-encoded words in the article."
1680   (interactive)
1681   (save-excursion
1682     (set-buffer gnus-article-buffer)
1683     (let ((inhibit-point-motion-hooks t)
1684           buffer-read-only
1685           (mail-parse-charset gnus-newsgroup-charset)
1686           (mail-parse-ignored-charsets
1687            (save-excursion (set-buffer gnus-summary-buffer)
1688                            gnus-newsgroup-ignored-charsets)))
1689       (mail-decode-encoded-word-region (point-min) (point-max)))))
1690
1691 (defun article-decode-charset (&optional prompt)
1692   "Decode charset-encoded text in the article.
1693 If PROMPT (the prefix), prompt for a coding system to use."
1694   (interactive "P")
1695   (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1696         buffer-read-only
1697         (mail-parse-charset gnus-newsgroup-charset)
1698         (mail-parse-ignored-charsets
1699          (save-excursion (condition-case nil
1700                              (set-buffer gnus-summary-buffer)
1701                            (error))
1702                          gnus-newsgroup-ignored-charsets))
1703         ct cte ctl charset format)
1704   (save-excursion
1705     (save-restriction
1706       (article-narrow-to-head)
1707       (setq ct (message-fetch-field "Content-Type" t)
1708             cte (message-fetch-field "Content-Transfer-Encoding" t)
1709             ctl (and ct (ignore-errors
1710                           (mail-header-parse-content-type ct)))
1711             charset (cond
1712                      (prompt
1713                       (mm-read-coding-system "Charset to decode: "))
1714                      (ctl
1715                       (mail-content-type-get ctl 'charset)))
1716             format (and ctl (mail-content-type-get ctl 'format)))
1717       (when cte
1718         (setq cte (mail-header-strip cte)))
1719       (if (and ctl (not (string-match "/" (car ctl))))
1720           (setq ctl nil))
1721       (goto-char (point-max)))
1722     (forward-line 1)
1723     (save-restriction
1724       (narrow-to-region (point) (point-max))
1725       (when (and (eq mail-parse-charset 'gnus-decoded)
1726                  (eq (mm-body-7-or-8) '8bit))
1727         ;; The text code could have been decoded.
1728         (setq charset mail-parse-charset))
1729       (when (and (or (not ctl)
1730                      (equal (car ctl) "text/plain"))
1731                  (not format)) ;; article with format will decode later.
1732         (mm-decode-body
1733          charset (and cte (intern (downcase
1734                                    (gnus-strip-whitespace cte))))
1735          (car ctl)))))))
1736
1737 (defun article-decode-encoded-words ()
1738   "Remove encoded-word encoding from headers."
1739   (let ((inhibit-point-motion-hooks t)
1740         (mail-parse-charset gnus-newsgroup-charset)
1741         (mail-parse-ignored-charsets
1742          (save-excursion (condition-case nil
1743                              (set-buffer gnus-summary-buffer)
1744                            (error))
1745                          gnus-newsgroup-ignored-charsets))
1746         buffer-read-only)
1747     (save-restriction
1748       (article-narrow-to-head)
1749       (funcall gnus-decode-header-function (point-min) (point-max)))))
1750
1751 (defun article-decode-group-name ()
1752   "Decode group names in `Newsgroups:'."
1753   (let ((inhibit-point-motion-hooks t)
1754         buffer-read-only
1755         (method (gnus-find-method-for-group gnus-newsgroup-name)))
1756     (when (and (or gnus-group-name-charset-method-alist
1757                    gnus-group-name-charset-group-alist)
1758                (gnus-buffer-live-p gnus-original-article-buffer))
1759       (when (nnmail-fetch-field "Newsgroups")
1760         (nnheader-replace-header "Newsgroups"
1761                                  (gnus-decode-newsgroups
1762                                   (with-current-buffer
1763                                       gnus-original-article-buffer
1764                                     (nnmail-fetch-field "Newsgroups"))
1765                                   gnus-newsgroup-name method)))
1766       (when (nnmail-fetch-field "Followup-To")
1767         (nnheader-replace-header "Followup-To"
1768                                  (gnus-decode-newsgroups
1769                                   (with-current-buffer
1770                                       gnus-original-article-buffer
1771                                     (nnmail-fetch-field "Followup-To"))
1772                                   gnus-newsgroup-name method))))))
1773
1774 (defun article-de-quoted-unreadable (&optional force read-charset)
1775   "Translate a quoted-printable-encoded article.
1776 If FORCE, decode the article whether it is marked as quoted-printable
1777 or not.
1778 If READ-CHARSET, ask for a coding system."
1779   (interactive (list 'force current-prefix-arg))
1780   (save-excursion
1781     (let ((buffer-read-only nil) type charset)
1782       (if (gnus-buffer-live-p gnus-original-article-buffer)
1783           (with-current-buffer gnus-original-article-buffer
1784             (setq type
1785                   (gnus-fetch-field "content-transfer-encoding"))
1786             (let* ((ct (gnus-fetch-field "content-type"))
1787                    (ctl (and ct
1788                              (ignore-errors
1789                                (mail-header-parse-content-type ct)))))
1790               (setq charset (and ctl
1791                                  (mail-content-type-get ctl 'charset)))
1792               (if (stringp charset)
1793                   (setq charset (intern (downcase charset)))))))
1794       (if read-charset
1795           (setq charset (mm-read-coding-system "Charset: " charset)))
1796       (unless charset
1797         (setq charset gnus-newsgroup-charset))
1798       (when (or force
1799                 (and type (let ((case-fold-search t))
1800                             (string-match "quoted-printable" type))))
1801         (article-goto-body)
1802         (quoted-printable-decode-region
1803          (point) (point-max) (mm-charset-to-coding-system charset))))))
1804
1805 (defun article-de-base64-unreadable (&optional force read-charset)
1806   "Translate a base64 article.
1807 If FORCE, decode the article whether it is marked as base64 not.
1808 If READ-CHARSET, ask for a coding system."
1809   (interactive (list 'force current-prefix-arg))
1810   (save-excursion
1811     (let ((buffer-read-only nil) type charset)
1812       (if (gnus-buffer-live-p gnus-original-article-buffer)
1813           (with-current-buffer gnus-original-article-buffer
1814             (setq type
1815                   (gnus-fetch-field "content-transfer-encoding"))
1816             (let* ((ct (gnus-fetch-field "content-type"))
1817                    (ctl (and ct
1818                              (ignore-errors
1819                                (mail-header-parse-content-type ct)))))
1820               (setq charset (and ctl
1821                                  (mail-content-type-get ctl 'charset)))
1822               (if (stringp charset)
1823                   (setq charset (intern (downcase charset)))))))
1824       (if read-charset
1825           (setq charset (mm-read-coding-system "Charset: " charset)))
1826       (unless charset
1827         (setq charset gnus-newsgroup-charset))
1828       (when (or force
1829                 (and type (let ((case-fold-search t))
1830                             (string-match "base64" type))))
1831         (article-goto-body)
1832         (save-restriction
1833           (narrow-to-region (point) (point-max))
1834           (base64-decode-region (point-min) (point-max))
1835           (mm-decode-coding-region
1836            (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1837
1838 (eval-when-compile
1839   (require 'rfc1843))
1840
1841 (defun article-decode-HZ ()
1842   "Translate a HZ-encoded article."
1843   (interactive)
1844   (require 'rfc1843)
1845   (save-excursion
1846     (let ((buffer-read-only nil))
1847       (rfc1843-decode-region (point-min) (point-max)))))
1848
1849 (defun article-wash-html (&optional read-charset)
1850   "Format an html article.
1851 If READ-CHARSET, ask for a coding system."
1852   (interactive "P")
1853   (save-excursion
1854     (let ((buffer-read-only nil)
1855           charset)
1856       (if (gnus-buffer-live-p gnus-original-article-buffer)
1857           (with-current-buffer gnus-original-article-buffer
1858             (let* ((ct (gnus-fetch-field "content-type"))
1859                    (ctl (and ct
1860                              (ignore-errors
1861                                (mail-header-parse-content-type ct)))))
1862               (setq charset (and ctl
1863                                  (mail-content-type-get ctl 'charset)))
1864               (if (stringp charset)
1865                   (setq charset (intern (downcase charset)))))))
1866       (if read-charset
1867           (setq charset (mm-read-coding-system "Charset: " charset)))
1868       (unless charset
1869         (setq charset gnus-newsgroup-charset))
1870       (article-goto-body)
1871       (save-window-excursion
1872         (save-restriction
1873           (narrow-to-region (point) (point-max))
1874           (mm-setup-w3)
1875           (let ((w3-strict-width (window-width))
1876                 (url-standalone-mode t))
1877             (condition-case var
1878                 (w3-region (point-min) (point-max))
1879               (error))))))))
1880
1881 (defun article-hide-list-identifiers ()
1882   "Remove list identifies from the Subject header.
1883 The `gnus-list-identifiers' variable specifies what to do."
1884   (interactive)
1885   (let ((inhibit-point-motion-hooks t)
1886         (regexp (if (consp gnus-list-identifiers)
1887                     (mapconcat 'identity gnus-list-identifiers " *\\|")
1888                   gnus-list-identifiers))
1889         buffer-read-only)
1890     (when regexp
1891       (save-excursion
1892         (save-restriction
1893           (article-narrow-to-head)
1894           (goto-char (point-min))
1895           (while (re-search-forward
1896                   (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
1897                   nil t)
1898             (delete-region (match-beginning 2) (match-end 0))
1899             (beginning-of-line))
1900           (when (re-search-forward
1901                  "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
1902             (delete-region (match-beginning 1) (match-end 1))))))))
1903
1904 (defun article-hide-pgp ()
1905   "Remove any PGP headers and signatures in the current article."
1906   (interactive)
1907   (save-excursion
1908     (save-restriction
1909       (let ((inhibit-point-motion-hooks t)
1910             buffer-read-only beg end)
1911         (article-goto-body)
1912         ;; Hide the "header".
1913         (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1914           (push 'pgp gnus-article-wash-types)
1915           (delete-region (match-beginning 0) (match-end 0))
1916           ;; Remove armor headers (rfc2440 6.2)
1917           (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1918                                      (point)))
1919           (setq beg (point))
1920           ;; Hide the actual signature.
1921           (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1922                (setq end (1+ (match-beginning 0)))
1923                (delete-region
1924                 end
1925                 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1926                     (match-end 0)
1927                   ;; Perhaps we shouldn't hide to the end of the buffer
1928                   ;; if there is no end to the signature?
1929                   (point-max))))
1930           ;; Hide "- " PGP quotation markers.
1931           (when (and beg end)
1932             (narrow-to-region beg end)
1933             (goto-char (point-min))
1934             (while (re-search-forward "^- " nil t)
1935               (delete-region
1936                (match-beginning 0) (match-end 0)))
1937             (widen))
1938           (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1939
1940 (defun article-hide-pem (&optional arg)
1941   "Toggle hiding of any PEM headers and signatures in the current article.
1942 If given a negative prefix, always show; if given a positive prefix,
1943 always hide."
1944   (interactive (gnus-article-hidden-arg))
1945   (unless (gnus-article-check-hidden-text 'pem arg)
1946     (save-excursion
1947       (let (buffer-read-only end)
1948         (goto-char (point-min))
1949         ;; Hide the horrendously ugly "header".
1950         (when (and (search-forward
1951                     "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1952                     nil t)
1953                    (setq end (1+ (match-beginning 0))))
1954           (push 'pem gnus-article-wash-types)
1955           (gnus-article-hide-text-type
1956            end
1957            (if (search-forward "\n\n" nil t)
1958                (match-end 0)
1959              (point-max))
1960            'pem)
1961           ;; Hide the trailer as well
1962           (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1963                                 nil t)
1964             (gnus-article-hide-text-type
1965              (match-beginning 0) (match-end 0) 'pem)))))))
1966
1967 (defun article-strip-banner ()
1968   "Strip the banner specified by the `banner' group parameter."
1969   (interactive)
1970   (save-excursion
1971     (save-restriction
1972       (let ((inhibit-point-motion-hooks t)
1973             (banner (gnus-parameter-banner gnus-newsgroup-name))
1974             (gnus-signature-limit nil)
1975             buffer-read-only beg end)
1976         (when banner
1977           (article-goto-body)
1978           (cond
1979            ((eq banner 'signature)
1980             (when (gnus-article-narrow-to-signature)
1981               (widen)
1982               (forward-line -1)
1983               (delete-region (point) (point-max))))
1984            ((symbolp banner)
1985             (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1986                 (while (re-search-forward banner nil t)
1987                   (delete-region (match-beginning 0) (match-end 0)))))
1988            ((stringp banner)
1989             (while (re-search-forward banner nil t)
1990               (delete-region (match-beginning 0) (match-end 0))))))))))
1991
1992 (defun article-babel ()
1993   "Translate article using an online translation service."
1994   (interactive)
1995   (require 'babel)
1996   (save-excursion
1997     (set-buffer gnus-article-buffer)
1998     (when (article-goto-body)
1999       (let* ((buffer-read-only nil)
2000              (start (point))
2001              (end (point-max))
2002              (orig (buffer-substring start end))
2003              (trans (babel-as-string orig)))
2004         (save-restriction
2005           (narrow-to-region start end)
2006           (delete-region start end)
2007           (insert trans))))))
2008
2009 (defun article-hide-signature (&optional arg)
2010   "Hide the signature in the current article.
2011 If given a negative prefix, always show; if given a positive prefix,
2012 always hide."
2013   (interactive (gnus-article-hidden-arg))
2014   (unless (gnus-article-check-hidden-text 'signature arg)
2015     (save-excursion
2016       (save-restriction
2017         (let ((buffer-read-only nil))
2018           (when (gnus-article-narrow-to-signature)
2019             (gnus-article-hide-text-type
2020              (point-min) (point-max) 'signature)))))))
2021
2022 (defun article-strip-headers-in-body ()
2023   "Strip offensive headers from bodies."
2024   (interactive)
2025   (save-excursion
2026     (article-goto-body)
2027     (let ((case-fold-search t))
2028       (when (looking-at "x-no-archive:")
2029         (gnus-delete-line)))))
2030
2031 (defun article-strip-leading-blank-lines ()
2032   "Remove all blank lines from the beginning of the article."
2033   (interactive)
2034   (save-excursion
2035     (let ((inhibit-point-motion-hooks t)
2036           buffer-read-only)
2037       (when (article-goto-body)
2038         (while (and (not (eobp))
2039                     (looking-at "[ \t]*$"))
2040           (gnus-delete-line))))))
2041
2042 (defun article-narrow-to-head ()
2043   "Narrow the buffer to the head of the message.
2044 Point is left at the beginning of the narrowed-to region."
2045   (narrow-to-region
2046    (goto-char (point-min))
2047    (if (search-forward "\n\n" nil 1)
2048        (1- (point))
2049      (point-max)))
2050   (goto-char (point-min)))
2051
2052 (defun article-goto-body ()
2053   "Place point at the start of the body."
2054   (goto-char (point-min))
2055   (cond
2056    ;; This variable is only bound when dealing with separate
2057    ;; MIME body parts.
2058    (article-goto-body-goes-to-point-min-p
2059     t)
2060    ((search-forward "\n\n" nil t)
2061     t)
2062    (t
2063     (goto-char (point-max))
2064     nil)))
2065
2066 (defun article-strip-multiple-blank-lines ()
2067   "Replace consecutive blank lines with one empty line."
2068   (interactive)
2069   (save-excursion
2070     (let ((inhibit-point-motion-hooks t)
2071           buffer-read-only)
2072       ;; First make all blank lines empty.
2073       (article-goto-body)
2074       (while (re-search-forward "^[ \t]+$" nil t)
2075         (unless (gnus-annotation-in-region-p
2076                  (match-beginning 0) (match-end 0))
2077           (replace-match "" nil t)))
2078       ;; Then replace multiple empty lines with a single empty line.
2079       (article-goto-body)
2080       (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2081         (unless (gnus-annotation-in-region-p
2082                  (match-beginning 0) (match-end 0))
2083           (delete-region (match-beginning 1) (match-end 1)))))))
2084
2085 (defun article-strip-leading-space ()
2086   "Remove all white space from the beginning of the lines in the article."
2087   (interactive)
2088   (save-excursion
2089     (let ((inhibit-point-motion-hooks t)
2090           buffer-read-only)
2091       (article-goto-body)
2092       (while (re-search-forward "^[ \t]+" nil t)
2093         (replace-match "" t t)))))
2094
2095 (defun article-strip-trailing-space ()
2096   "Remove all white space from the end of the lines in the article."
2097   (interactive)
2098   (save-excursion
2099     (let ((inhibit-point-motion-hooks t)
2100           buffer-read-only)
2101       (article-goto-body)
2102       (while (re-search-forward "[ \t]+$" nil t)
2103         (replace-match "" t t)))))
2104
2105 (defun article-strip-blank-lines ()
2106   "Strip leading, trailing and multiple blank lines."
2107   (interactive)
2108   (article-strip-leading-blank-lines)
2109   (article-remove-trailing-blank-lines)
2110   (article-strip-multiple-blank-lines))
2111
2112 (defun article-strip-all-blank-lines ()
2113   "Strip all blank lines."
2114   (interactive)
2115   (save-excursion
2116     (let ((inhibit-point-motion-hooks t)
2117           buffer-read-only)
2118       (article-goto-body)
2119       (while (re-search-forward "^[ \t]*\n" nil t)
2120         (replace-match "" t t)))))
2121
2122 (defun gnus-article-narrow-to-signature ()
2123   "Narrow to the signature; return t if a signature is found, else nil."
2124   (let ((inhibit-point-motion-hooks t))
2125     (when (gnus-article-search-signature)
2126       (forward-line 1)
2127       ;; Check whether we have some limits to what we consider
2128       ;; to be a signature.
2129       (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2130                       (list gnus-signature-limit)))
2131             limit limited)
2132         (while (setq limit (pop limits))
2133           (if (or (and (integerp limit)
2134                        (< (- (point-max) (point)) limit))
2135                   (and (floatp limit)
2136                        (< (count-lines (point) (point-max)) limit))
2137                   (and (gnus-functionp limit)
2138                        (funcall limit))
2139                   (and (stringp limit)
2140                        (not (re-search-forward limit nil t))))
2141               ()                        ; This limit did not succeed.
2142             (setq limited t
2143                   limits nil)))
2144         (unless limited
2145           (narrow-to-region (point) (point-max))
2146           t)))))
2147
2148 (defun gnus-article-search-signature ()
2149   "Search the current buffer for the signature separator.
2150 Put point at the beginning of the signature separator."
2151   (let ((cur (point)))
2152     (goto-char (point-max))
2153     (if (if (stringp gnus-signature-separator)
2154             (re-search-backward gnus-signature-separator nil t)
2155           (let ((seps gnus-signature-separator))
2156             (while (and seps
2157                         (not (re-search-backward (car seps) nil t)))
2158               (pop seps))
2159             seps))
2160         t
2161       (goto-char cur)
2162       nil)))
2163
2164 (defun gnus-article-hidden-arg ()
2165   "Return the current prefix arg as a number, or 0 if no prefix."
2166   (list (if current-prefix-arg
2167             (prefix-numeric-value current-prefix-arg)
2168           0)))
2169
2170 (defun gnus-article-check-hidden-text (type arg)
2171   "Return nil if hiding is necessary.
2172 Arg can be nil or a number.  Nil and positive means hide, negative
2173 means show, 0 means toggle."
2174   (save-excursion
2175     (save-restriction
2176       (let ((hide (gnus-article-hidden-text-p type)))
2177         (cond
2178          ((or (null arg)
2179               (> arg 0))
2180           nil)
2181          ((< arg 0)
2182           (gnus-article-show-hidden-text type)
2183           t)
2184          (t
2185           (if (eq hide 'hidden)
2186               (progn
2187                 (gnus-article-show-hidden-text type)
2188                 t)
2189             nil)))))))
2190
2191 (defun gnus-article-hidden-text-p (type)
2192   "Say whether the current buffer contains hidden text of type TYPE."
2193   (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2194     (while (and pos
2195                 (not (get-text-property pos 'invisible))
2196                 (not (get-text-property pos 'dummy-invisible)))
2197       (setq pos
2198             (text-property-any (1+ pos) (point-max) 'article-type type)))
2199     (if pos
2200         'hidden
2201       nil)))
2202
2203 (defun gnus-article-show-hidden-text (type &optional dummy)
2204   "Show all hidden text of type TYPE.
2205 Originally it is hide instead of DUMMY."
2206   (let ((buffer-read-only nil)
2207         (inhibit-point-motion-hooks t))
2208     (gnus-remove-text-properties-when
2209      'article-type type
2210      (point-min) (point-max)
2211      (cons 'article-type (cons type
2212                                gnus-hidden-properties)))))
2213
2214 (defconst article-time-units
2215   `((year . ,(* 365.25 24 60 60))
2216     (week . ,(* 7 24 60 60))
2217     (day . ,(* 24 60 60))
2218     (hour . ,(* 60 60))
2219     (minute . 60)
2220     (second . 1))
2221   "Mapping from time units to seconds.")
2222
2223 (defun article-date-ut (&optional type highlight header)
2224   "Convert DATE date to universal time in the current article.
2225 If TYPE is `local', convert to local time; if it is `lapsed', output
2226 how much time has lapsed since DATE.  For `lapsed', the value of
2227 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2228 should replace the \"Date:\" one, or should be added below it."
2229   (interactive (list 'ut t))
2230   (let* ((header (or header
2231                      (message-fetch-field "date")
2232                      ""))
2233          (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2234          (date-regexp
2235           (cond
2236            ((not gnus-article-date-lapsed-new-header)
2237             tdate-regexp)
2238            ((eq type 'lapsed)
2239             "^X-Sent:[ \t]")
2240            (t
2241             "^Date:[ \t]")))
2242          (date (if (vectorp header) (mail-header-date header)
2243                  header))
2244          (inhibit-point-motion-hooks t)
2245          pos
2246          bface eface)
2247     (save-excursion
2248       (save-restriction
2249         (article-narrow-to-head)
2250         (when (re-search-forward tdate-regexp nil t)
2251           (setq bface (get-text-property (gnus-point-at-bol) 'face)
2252                 date (or (get-text-property (gnus-point-at-bol)
2253                                             'original-date)
2254                          date)
2255                 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2256           (forward-line 1))
2257         (when (and date (not (string= date "")))
2258           (goto-char (point-min))
2259           (let ((buffer-read-only nil))
2260             ;; Delete any old Date headers.
2261             (while (re-search-forward date-regexp nil t)
2262               (if pos
2263                   (delete-region (progn (beginning-of-line) (point))
2264                                  (progn (forward-line 1) (point)))
2265                 (delete-region (progn (beginning-of-line) (point))
2266                                (progn (end-of-line) (point)))
2267                 (setq pos (point))))
2268             (when (and (not pos) (re-search-forward tdate-regexp nil t))
2269               (forward-line 1))
2270             (if pos (goto-char pos))
2271             (insert (article-make-date-line date (or type 'ut)))
2272             (when (not pos)
2273               (insert "\n")
2274               (forward-line -1))
2275             ;; Do highlighting.
2276             (beginning-of-line)
2277             (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2278               (put-text-property (match-beginning 1) (1+ (match-end 1))
2279                                  'original-date date)
2280               (put-text-property (match-beginning 1) (1+ (match-end 1))
2281                                  'face bface)
2282               (put-text-property (match-beginning 2) (match-end 2)
2283                                  'face eface))))))))
2284
2285 (defun article-make-date-line (date type)
2286   "Return a DATE line of TYPE."
2287   (unless (memq type '(local ut original user iso8601 lapsed english))
2288     (error "Unknown conversion type: %s" type))
2289   (condition-case ()
2290       (let ((time (date-to-time date)))
2291         (cond
2292          ;; Convert to the local timezone.
2293          ((eq type 'local)
2294           (let ((tz (car (current-time-zone time))))
2295             (format "Date: %s %s%02d%02d" (current-time-string time)
2296                     (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2297                     (/ (% (abs tz) 3600) 60))))
2298          ;; Convert to Universal Time.
2299          ((eq type 'ut)
2300           (concat "Date: "
2301                   (current-time-string
2302                    (let* ((e (parse-time-string date))
2303                           (tm (apply 'encode-time e))
2304                           (ms (car tm))
2305                           (ls (- (cadr tm) (car (current-time-zone time)))))
2306                      (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2307                            ((> ls 65535) (list (1+ ms) (- ls 65536)))
2308                            (t (list ms ls)))))
2309                   " UT"))
2310          ;; Get the original date from the article.
2311          ((eq type 'original)
2312           (concat "Date: " (if (string-match "\n+$" date)
2313                                (substring date 0 (match-beginning 0))
2314                              date)))
2315          ;; Let the user define the format.
2316          ((eq type 'user)
2317           (if (gnus-functionp gnus-article-time-format)
2318               (funcall gnus-article-time-format time)
2319             (concat
2320              "Date: "
2321              (format-time-string gnus-article-time-format time))))
2322          ;; ISO 8601.
2323          ((eq type 'iso8601)
2324           (let ((tz (car (current-time-zone time))))
2325             (concat
2326              "Date: "
2327              (format-time-string "%Y%m%dT%H%M%S" time)
2328              (format "%s%02d%02d"
2329                      (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2330                      (/ (% (abs tz) 3600) 60)))))
2331          ;; Do an X-Sent lapsed format.
2332          ((eq type 'lapsed)
2333           ;; If the date is seriously mangled, the timezone functions are
2334           ;; liable to bug out, so we ignore all errors.
2335           (let* ((now (current-time))
2336                  (real-time (subtract-time now time))
2337                  (real-sec (and real-time
2338                                 (+ (* (float (car real-time)) 65536)
2339                                    (cadr real-time))))
2340                  (sec (and real-time (abs real-sec)))
2341                  num prev)
2342             (cond
2343              ((null real-time)
2344               "X-Sent: Unknown")
2345              ((zerop sec)
2346               "X-Sent: Now")
2347              (t
2348               (concat
2349                "X-Sent: "
2350                ;; This is a bit convoluted, but basically we go
2351                ;; through the time units for years, weeks, etc,
2352                ;; and divide things to see whether that results
2353                ;; in positive answers.
2354                (mapconcat
2355                 (lambda (unit)
2356                   (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2357                       ;; The (remaining) seconds are too few to
2358                       ;; be divided into this time unit.
2359                       ""
2360                     ;; It's big enough, so we output it.
2361                     (setq sec (- sec (* num (cdr unit))))
2362                     (prog1
2363                         (concat (if prev ", " "") (int-to-string
2364                                                    (floor num))
2365                                 " " (symbol-name (car unit))
2366                                 (if (> num 1) "s" ""))
2367                       (setq prev t))))
2368                 article-time-units "")
2369                ;; If dates are odd, then it might appear like the
2370                ;; article was sent in the future.
2371                (if (> real-sec 0)
2372                    " ago"
2373                  " in the future"))))))
2374          ;; Display the date in proper English
2375          ((eq type 'english)
2376           (let ((dtime (decode-time time)))
2377             (concat
2378              "Date: the "
2379              (number-to-string (nth 3 dtime))
2380              (let ((digit (% (nth 3 dtime) 10)))
2381                (cond
2382                 ((memq (nth 3 dtime) '(11 12 13)) "th")
2383                 ((= digit 1) "st")
2384                 ((= digit 2) "nd")
2385                 ((= digit 3) "rd")
2386                 (t "th")))
2387              " of "
2388              (nth (1- (nth 4 dtime)) gnus-english-month-names)
2389              " "
2390              (number-to-string (nth 5 dtime))
2391              " at "
2392              (format "%02d" (nth 2 dtime))
2393              ":"
2394              (format "%02d" (nth 1 dtime)))))))
2395         (error
2396          (format "Date: %s (from Oort)" date))))
2397
2398 (defun article-date-local (&optional highlight)
2399   "Convert the current article date to the local timezone."
2400   (interactive (list t))
2401   (article-date-ut 'local highlight))
2402
2403 (defun article-date-english (&optional highlight)
2404   "Convert the current article date to something that is proper English."
2405   (interactive (list t))
2406   (article-date-ut 'english highlight))
2407
2408 (defun article-date-original (&optional highlight)
2409   "Convert the current article date to what it was originally.
2410 This is only useful if you have used some other date conversion
2411 function and want to see what the date was before converting."
2412   (interactive (list t))
2413   (article-date-ut 'original highlight))
2414
2415 (defun article-date-lapsed (&optional highlight)
2416   "Convert the current article date to time lapsed since it was sent."
2417   (interactive (list t))
2418   (article-date-ut 'lapsed highlight))
2419
2420 (defun article-update-date-lapsed ()
2421   "Function to be run from a timer to update the lapsed time line."
2422   (let (deactivate-mark)
2423     (save-excursion
2424       (ignore-errors
2425         (walk-windows
2426          (lambda (w)
2427            (set-buffer (window-buffer w))
2428            (when (eq major-mode 'gnus-article-mode)
2429              (goto-char (point-min))
2430              (when (re-search-forward "^X-Sent:" nil t)
2431                (article-date-lapsed t))))
2432          nil 'visible)))))
2433
2434 (defun gnus-start-date-timer (&optional n)
2435   "Start a timer to update the X-Sent header in the article buffers.
2436 The numerical prefix says how frequently (in seconds) the function
2437 is to run."
2438   (interactive "p")
2439   (unless n
2440     (setq n 1))
2441   (gnus-stop-date-timer)
2442   (setq article-lapsed-timer
2443         (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2444
2445 (defun gnus-stop-date-timer ()
2446   "Stop the X-Sent timer."
2447   (interactive)
2448   (when article-lapsed-timer
2449     (nnheader-cancel-timer article-lapsed-timer)
2450     (setq article-lapsed-timer nil)))
2451
2452 (defun article-date-user (&optional highlight)
2453   "Convert the current article date to the user-defined format.
2454 This format is defined by the `gnus-article-time-format' variable."
2455   (interactive (list t))
2456   (article-date-ut 'user highlight))
2457
2458 (defun article-date-iso8601 (&optional highlight)
2459   "Convert the current article date to ISO8601."
2460   (interactive (list t))
2461   (article-date-ut 'iso8601 highlight))
2462
2463 (defun article-show-all ()
2464   "Show all hidden text in the article buffer."
2465   (interactive)
2466   (save-excursion
2467     (let ((buffer-read-only nil))
2468       (gnus-article-unhide-text (point-min) (point-max)))))
2469
2470 (defun article-remove-leading-whitespace ()
2471   "Remove excessive whitespace from all headers."
2472   (interactive)
2473   (save-excursion
2474     (save-restriction
2475       (let ((buffer-read-only nil))
2476         (article-narrow-to-head)
2477         (goto-char (point-min))
2478         (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2479           (delete-region (match-beginning 1) (match-end 1)))))))
2480
2481 (defun article-emphasize (&optional arg)
2482   "Emphasize text according to `gnus-emphasis-alist'."
2483   (interactive (gnus-article-hidden-arg))
2484   (unless (gnus-article-check-hidden-text 'emphasis arg)
2485     (save-excursion
2486       (let ((alist (or
2487                     (condition-case nil
2488                         (with-current-buffer gnus-summary-buffer
2489                           gnus-article-emphasis-alist)
2490                       (error))
2491                     gnus-emphasis-alist))
2492             (buffer-read-only nil)
2493             (props (append '(article-type emphasis)
2494                            gnus-hidden-properties))
2495             regexp elem beg invisible visible face)
2496         (article-goto-body)
2497         (setq beg (point))
2498         (while (setq elem (pop alist))
2499           (goto-char beg)
2500           (setq regexp (car elem)
2501                 invisible (nth 1 elem)
2502                 visible (nth 2 elem)
2503                 face (nth 3 elem))
2504           (while (re-search-forward regexp nil t)
2505             (when (and (match-beginning visible) (match-beginning invisible))
2506               (gnus-article-hide-text
2507                (match-beginning invisible) (match-end invisible) props)
2508               (gnus-article-unhide-text-type
2509                (match-beginning visible) (match-end visible) 'emphasis)
2510               (gnus-put-text-property-excluding-newlines
2511                (match-beginning visible) (match-end visible) 'face face)
2512               (push 'emphasis gnus-article-wash-types)
2513               (goto-char (match-end invisible)))))))))
2514
2515 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2516   "Setup newsgroup emphasis alist."
2517   (unless gnus-article-emphasis-alist
2518     (let ((name (and gnus-newsgroup-name
2519                      (gnus-group-real-name gnus-newsgroup-name))))
2520       (make-local-variable 'gnus-article-emphasis-alist)
2521       (setq gnus-article-emphasis-alist
2522             (nconc
2523              (let ((alist gnus-group-highlight-words-alist) elem highlight)
2524                (while (setq elem (pop alist))
2525                  (when (and name (string-match (car elem) name))
2526                    (setq alist nil
2527                          highlight (copy-sequence (cdr elem)))))
2528                highlight)
2529              (copy-sequence highlight-words)
2530              (if gnus-newsgroup-name
2531                  (copy-sequence (gnus-group-find-parameter
2532                                  gnus-newsgroup-name 'highlight-words t)))
2533              gnus-emphasis-alist)))))
2534
2535 (eval-when-compile
2536   (defvar gnus-summary-article-menu)
2537   (defvar gnus-summary-post-menu))
2538
2539 ;;; Saving functions.
2540
2541 (defun gnus-article-save (save-buffer file &optional num)
2542   "Save the currently selected article."
2543   (unless gnus-save-all-headers
2544     ;; Remove headers according to `gnus-saved-headers'.
2545     (let ((gnus-visible-headers
2546            (or gnus-saved-headers gnus-visible-headers))
2547           (gnus-article-buffer save-buffer))
2548       (save-excursion
2549         (set-buffer save-buffer)
2550         (article-hide-headers 1 t))))
2551   (save-window-excursion
2552     (if (not gnus-default-article-saver)
2553         (error "No default saver is defined")
2554       ;; !!! Magic!  The saving functions all save
2555       ;; `gnus-save-article-buffer' (or so they think), but we
2556       ;; bind that variable to our save-buffer.
2557       (set-buffer gnus-article-buffer)
2558       (let* ((gnus-save-article-buffer save-buffer)
2559              (filename
2560               (cond
2561                ((not gnus-prompt-before-saving) 'default)
2562                ((eq gnus-prompt-before-saving 'always) nil)
2563                (t file)))
2564              (gnus-number-of-articles-to-be-saved
2565               (when (eq gnus-prompt-before-saving t)
2566                 num)))                  ; Magic
2567         (set-buffer gnus-article-current-summary)
2568         (funcall gnus-default-article-saver filename)))))
2569
2570 (defun gnus-read-save-file-name (prompt &optional filename
2571                                         function group headers variable)
2572   (let ((default-name
2573           (funcall function group headers (symbol-value variable)))
2574         result)
2575     (setq result
2576           (expand-file-name
2577            (cond
2578             ((eq filename 'default)
2579              default-name)
2580             ((eq filename t)
2581              default-name)
2582             (filename filename)
2583             (t
2584              (let* ((split-name (gnus-get-split-value gnus-split-methods))
2585                     (prompt
2586                      (format prompt
2587                              (if (and gnus-number-of-articles-to-be-saved
2588                                       (> gnus-number-of-articles-to-be-saved 1))
2589                                  (format "these %d articles"
2590                                          gnus-number-of-articles-to-be-saved)
2591                                "this article")))
2592                     (file
2593                      ;; Let the split methods have their say.
2594                      (cond
2595                       ;; No split name was found.
2596                       ((null split-name)
2597                        (read-file-name
2598                         (concat prompt " (default "
2599                                 (file-name-nondirectory default-name) ") ")
2600                         (file-name-directory default-name)
2601                         default-name))
2602                       ;; A single group name is returned.
2603                       ((stringp split-name)
2604                        (setq default-name
2605                              (funcall function split-name headers
2606                                       (symbol-value variable)))
2607                        (read-file-name
2608                         (concat prompt " (default "
2609                                 (file-name-nondirectory default-name) ") ")
2610                         (file-name-directory default-name)
2611                         default-name))
2612                       ;; A single split name was found
2613                       ((= 1 (length split-name))
2614                        (let* ((name (expand-file-name
2615                                      (car split-name)
2616                                      gnus-article-save-directory))
2617                               (dir (cond ((file-directory-p name)
2618                                           (file-name-as-directory name))
2619                                          ((file-exists-p name) name)
2620                                          (t gnus-article-save-directory))))
2621                          (read-file-name
2622                           (concat prompt " (default " name ") ")
2623                           dir name)))
2624                       ;; A list of splits was found.
2625                       (t
2626                        (setq split-name (nreverse split-name))
2627                        (let (result)
2628                          (let ((file-name-history
2629                                 (nconc split-name file-name-history)))
2630                            (setq result
2631                                  (expand-file-name
2632                                   (read-file-name
2633                                    (concat prompt " (`M-p' for defaults) ")
2634                                    gnus-article-save-directory
2635                                    (car split-name))
2636                                   gnus-article-save-directory)))
2637                          (car (push result file-name-history)))))))
2638                ;; Create the directory.
2639                (gnus-make-directory (file-name-directory file))
2640       ;; If we have read a directory, we append the default file name.
2641                (when (file-directory-p file)
2642                  (setq file (expand-file-name (file-name-nondirectory
2643                                                default-name)
2644                                               (file-name-as-directory file))))
2645                ;; Possibly translate some characters.
2646                (nnheader-translate-file-chars file))))))
2647     (gnus-make-directory (file-name-directory result))
2648     (set variable result)))
2649
2650 (defun gnus-article-archive-name (group)
2651   "Return the first instance of an \"Archive-name\" in the current buffer."
2652   (let ((case-fold-search t))
2653     (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2654       (nnheader-concat gnus-article-save-directory
2655                        (match-string 1)))))
2656
2657 (defun gnus-article-nndoc-name (group)
2658   "If GROUP is an nndoc group, return the name of the parent group."
2659   (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2660     (gnus-group-get-parameter group 'save-article-group)))
2661
2662 (defun gnus-summary-save-in-rmail (&optional filename)
2663   "Append this article to Rmail file.
2664 Optional argument FILENAME specifies file name.
2665 Directory to save to is default to `gnus-article-save-directory'."
2666   (setq filename (gnus-read-save-file-name
2667                   "Save %s in rmail file:" filename
2668                   gnus-rmail-save-name gnus-newsgroup-name
2669                   gnus-current-headers 'gnus-newsgroup-last-rmail))
2670   (gnus-eval-in-buffer-window gnus-save-article-buffer
2671     (save-excursion
2672       (save-restriction
2673         (widen)
2674         (gnus-output-to-rmail filename))))
2675   filename)
2676
2677 (defun gnus-summary-save-in-mail (&optional filename)
2678   "Append this article to Unix mail file.
2679 Optional argument FILENAME specifies file name.
2680 Directory to save to is default to `gnus-article-save-directory'."
2681   (setq filename (gnus-read-save-file-name
2682                   "Save %s in Unix mail file:" filename
2683                   gnus-mail-save-name gnus-newsgroup-name
2684                   gnus-current-headers 'gnus-newsgroup-last-mail))
2685   (gnus-eval-in-buffer-window gnus-save-article-buffer
2686     (save-excursion
2687       (save-restriction
2688         (widen)
2689         (if (and (file-readable-p filename)
2690                  (mail-file-babyl-p filename))
2691             (rmail-output-to-rmail-file filename t)
2692           (gnus-output-to-mail filename)))))
2693   filename)
2694
2695 (defun gnus-summary-save-in-file (&optional filename overwrite)
2696   "Append this article to file.
2697 Optional argument FILENAME specifies file name.
2698 Directory to save to is default to `gnus-article-save-directory'."
2699   (setq filename (gnus-read-save-file-name
2700                   "Save %s in file:" filename
2701                   gnus-file-save-name gnus-newsgroup-name
2702                   gnus-current-headers 'gnus-newsgroup-last-file))
2703   (gnus-eval-in-buffer-window gnus-save-article-buffer
2704     (save-excursion
2705       (save-restriction
2706         (widen)
2707         (when (and overwrite
2708                    (file-exists-p filename))
2709           (delete-file filename))
2710         (gnus-output-to-file filename))))
2711   filename)
2712
2713 (defun gnus-summary-write-to-file (&optional filename)
2714   "Write this article to a file.
2715 Optional argument FILENAME specifies file name.
2716 The directory to save in defaults to `gnus-article-save-directory'."
2717   (gnus-summary-save-in-file nil t))
2718
2719 (defun gnus-summary-save-body-in-file (&optional filename)
2720   "Append this article body to a file.
2721 Optional argument FILENAME specifies file name.
2722 The directory to save in defaults to `gnus-article-save-directory'."
2723   (setq filename (gnus-read-save-file-name
2724                   "Save %s body in file:" filename
2725                   gnus-file-save-name gnus-newsgroup-name
2726                   gnus-current-headers 'gnus-newsgroup-last-file))
2727   (gnus-eval-in-buffer-window gnus-save-article-buffer
2728     (save-excursion
2729       (save-restriction
2730         (widen)
2731         (when (article-goto-body)
2732           (narrow-to-region (point) (point-max)))
2733         (gnus-output-to-file filename))))
2734   filename)
2735
2736 (defun gnus-summary-save-in-pipe (&optional command)
2737   "Pipe this article to subprocess."
2738   (setq command
2739         (cond ((and (eq command 'default)
2740                     gnus-last-shell-command)
2741                gnus-last-shell-command)
2742               ((stringp command)
2743                command)
2744               (t (read-string
2745                   (format
2746                    "Shell command on %s: "
2747                    (if (and gnus-number-of-articles-to-be-saved
2748                             (> gnus-number-of-articles-to-be-saved 1))
2749                        (format "these %d articles"
2750                                gnus-number-of-articles-to-be-saved)
2751                      "this article"))
2752                   gnus-last-shell-command))))
2753   (when (string-equal command "")
2754     (if gnus-last-shell-command
2755         (setq command gnus-last-shell-command)
2756       (error "A command is required")))
2757   (gnus-eval-in-buffer-window gnus-article-buffer
2758     (save-restriction
2759       (widen)
2760       (shell-command-on-region (point-min) (point-max) command nil)))
2761   (setq gnus-last-shell-command command))
2762
2763 ;;; Article file names when saving.
2764
2765 (defun gnus-capitalize-newsgroup (newsgroup)
2766   "Capitalize NEWSGROUP name."
2767   (when (not (zerop (length newsgroup)))
2768     (concat (char-to-string (upcase (aref newsgroup 0)))
2769             (substring newsgroup 1))))
2770
2771 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2772   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2773 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2774 Otherwise, it is like ~/News/news/group/num."
2775   (let ((default
2776           (expand-file-name
2777            (concat (if (gnus-use-long-file-name 'not-save)
2778                        (gnus-capitalize-newsgroup newsgroup)
2779                      (gnus-newsgroup-directory-form newsgroup))
2780                    "/" (int-to-string (mail-header-number headers)))
2781            gnus-article-save-directory)))
2782     (if (and last-file
2783              (string-equal (file-name-directory default)
2784                            (file-name-directory last-file))
2785              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2786         default
2787       (or last-file default))))
2788
2789 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2790   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2791 If variable `gnus-use-long-file-name' is non-nil, it is
2792 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
2793   (let ((default
2794           (expand-file-name
2795            (concat (if (gnus-use-long-file-name 'not-save)
2796                        newsgroup
2797                      (gnus-newsgroup-directory-form newsgroup))
2798                    "/" (int-to-string (mail-header-number headers)))
2799            gnus-article-save-directory)))
2800     (if (and last-file
2801              (string-equal (file-name-directory default)
2802                            (file-name-directory last-file))
2803              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2804         default
2805       (or last-file default))))
2806
2807 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2808   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2809 If variable `gnus-use-long-file-name' is non-nil, it is
2810 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
2811   (or last-file
2812       (expand-file-name
2813        (if (gnus-use-long-file-name 'not-save)
2814            newsgroup
2815          (file-relative-name
2816           (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2817           default-directory))
2818        gnus-article-save-directory)))
2819
2820 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2821   "Generate file name from sender."
2822   (let ((from (mail-header-from headers)))
2823     (expand-file-name
2824      (if (and from (string-match "\\([^ <]+\\)@" from))
2825          (match-string 1 from)
2826        "nobody")
2827      gnus-article-save-directory)))
2828
2829 (defun article-verify-x-pgp-sig ()
2830   "Verify X-PGP-Sig."
2831   (interactive)
2832   (if (gnus-buffer-live-p gnus-original-article-buffer)
2833       (let ((sig (with-current-buffer gnus-original-article-buffer
2834                    (gnus-fetch-field "X-PGP-Sig")))
2835             items info headers)
2836         (when (and sig
2837                    mml2015-use
2838                    (mml2015-clear-verify-function))
2839           (with-temp-buffer
2840             (insert-buffer gnus-original-article-buffer)
2841             (setq items (split-string sig))
2842             (message-narrow-to-head)
2843             (let ((inhibit-point-motion-hooks t)
2844                   (case-fold-search t))
2845               ;; Don't verify multiple headers.
2846               (setq headers (mapconcat (lambda (header)
2847                                          (concat header ": "
2848                                                  (mail-fetch-field header) "\n"))
2849                                        (split-string (nth 1 items) ",") "")))
2850             (delete-region (point-min) (point-max))
2851             (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2852             (insert "X-Signed-Headers: " (nth 1 items) "\n")
2853             (insert headers)
2854             (widen)
2855             (forward-line)
2856             (while (not (eobp))
2857               (if (looking-at "^-")
2858                   (insert "- "))
2859               (forward-line))
2860             (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2861             (insert "Version: " (car items) "\n\n")
2862             (insert (mapconcat 'identity (cddr items) "\n"))
2863             (insert "\n-----END PGP SIGNATURE-----\n")
2864             (let ((mm-security-handle (list (format "multipart/signed"))))
2865               (mml2015-clean-buffer)
2866               (let ((coding-system-for-write (or gnus-newsgroup-charset
2867                                                  'iso-8859-1)))
2868                 (funcall (mml2015-clear-verify-function)))
2869               (setq info
2870                     (or (mm-handle-multipart-ctl-parameter
2871                          mm-security-handle 'gnus-details)
2872                         (mm-handle-multipart-ctl-parameter
2873                          mm-security-handle 'gnus-info)))))
2874           (when info
2875             (let (buffer-read-only bface eface)
2876               (save-restriction
2877                 (message-narrow-to-head)
2878                 (goto-char (point-max))
2879                 (forward-line -1)
2880                 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2881                       eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2882                 (message-remove-header "X-Gnus-PGP-Verify")
2883                 (if (re-search-forward "^X-PGP-Sig:" nil t)
2884                     (forward-line)
2885                   (goto-char (point-max)))
2886                 (narrow-to-region (point) (point))
2887                 (insert "X-Gnus-PGP-Verify: " info "\n")
2888                 (goto-char (point-min))
2889                 (forward-line)
2890                 (while (not (eobp))
2891                   (if (not (looking-at "^[ \t]"))
2892                       (insert " "))
2893                   (forward-line))
2894                 ;; Do highlighting.
2895                 (goto-char (point-min))
2896                 (when (looking-at "\\([^:]+\\): *")
2897                   (put-text-property (match-beginning 1) (1+ (match-end 1))
2898                                      'face bface)
2899                   (put-text-property (match-end 0) (point-max)
2900                                      'face eface)))))))))
2901
2902 (autoload 'canlock-verify "canlock")
2903
2904 (defun article-verify-cancel-lock ()
2905   "Verify Cancel-Lock header."
2906   (interactive)
2907   (if (gnus-buffer-live-p gnus-original-article-buffer)
2908       (canlock-verify gnus-original-article-buffer)))
2909
2910 (eval-and-compile
2911   (mapcar
2912    (lambda (func)
2913      (let (afunc gfunc)
2914        (if (consp func)
2915            (setq afunc (car func)
2916                  gfunc (cdr func))
2917          (setq afunc func
2918                gfunc (intern (format "gnus-%s" func))))
2919        (defalias gfunc
2920          (if (fboundp afunc)
2921            `(lambda (&optional interactive &rest args)
2922               ,(documentation afunc t)
2923               (interactive (list t))
2924               (save-excursion
2925                 (set-buffer gnus-article-buffer)
2926                 (if interactive
2927                     (call-interactively ',afunc)
2928                   (apply ',afunc args))))))))
2929    '(article-hide-headers
2930      article-verify-x-pgp-sig
2931      article-verify-cancel-lock
2932      article-hide-boring-headers
2933      article-treat-overstrike
2934      article-fill-long-lines
2935      article-capitalize-sentences
2936      article-remove-cr
2937      article-remove-leading-whitespace
2938      article-display-x-face
2939      article-de-quoted-unreadable
2940      article-de-base64-unreadable
2941      article-decode-HZ
2942      article-wash-html
2943      article-hide-list-identifiers
2944      article-hide-pgp
2945      article-strip-banner
2946      article-babel
2947      article-hide-pem
2948      article-hide-signature
2949      article-strip-headers-in-body
2950      article-remove-trailing-blank-lines
2951      article-strip-leading-blank-lines
2952      article-strip-multiple-blank-lines
2953      article-strip-leading-space
2954      article-strip-trailing-space
2955      article-strip-blank-lines
2956      article-strip-all-blank-lines
2957      article-replace-with-quoted-text
2958      article-date-local
2959      article-date-english
2960      article-date-iso8601
2961      article-date-original
2962      article-date-ut
2963      article-decode-mime-words
2964      article-decode-charset
2965      article-decode-encoded-words
2966      article-date-user
2967      article-date-lapsed
2968      article-emphasize
2969      article-treat-dumbquotes
2970      article-normalize-headers
2971      (article-show-all . gnus-article-show-all-headers))))
2972 \f
2973 ;;;
2974 ;;; Gnus article mode
2975 ;;;
2976
2977 (put 'gnus-article-mode 'mode-class 'special)
2978
2979 (set-keymap-parent gnus-article-mode-map widget-keymap)
2980
2981 (gnus-define-keys gnus-article-mode-map
2982   " " gnus-article-goto-next-page
2983   "\177" gnus-article-goto-prev-page
2984   [delete] gnus-article-goto-prev-page
2985   [backspace] gnus-article-goto-prev-page
2986   "\C-c^" gnus-article-refer-article
2987   "h" gnus-article-show-summary
2988   "s" gnus-article-show-summary
2989   "\C-c\C-m" gnus-article-mail
2990   "?" gnus-article-describe-briefly
2991   "e" gnus-summary-edit-article
2992   "<" beginning-of-buffer
2993   ">" end-of-buffer
2994   "\C-c\C-i" gnus-info-find-node
2995   "\C-c\C-b" gnus-bug
2996   "\C-hk" gnus-article-describe-key
2997   "\C-hc" gnus-article-describe-key-briefly
2998
2999   "\C-d" gnus-article-read-summary-keys
3000   "\M-*" gnus-article-read-summary-keys
3001   "\M-#" gnus-article-read-summary-keys
3002   "\M-^" gnus-article-read-summary-keys
3003   "\M-g" gnus-article-read-summary-keys)
3004
3005 (substitute-key-definition
3006  'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3007
3008 (defun gnus-article-make-menu-bar ()
3009   (unless (boundp 'gnus-article-commands-menu)
3010     (gnus-summary-make-menu-bar))
3011   (gnus-turn-off-edit-menu 'article)
3012   (unless (boundp 'gnus-article-article-menu)
3013     (easy-menu-define
3014      gnus-article-article-menu gnus-article-mode-map ""
3015      '("Article"
3016        ["Scroll forwards" gnus-article-goto-next-page t]
3017        ["Scroll backwards" gnus-article-goto-prev-page t]
3018        ["Show summary" gnus-article-show-summary t]
3019        ["Fetch Message-ID at point" gnus-article-refer-article t]
3020        ["Mail to address at point" gnus-article-mail t]
3021        ["Send a bug report" gnus-bug t]))
3022
3023     (easy-menu-define
3024      gnus-article-treatment-menu gnus-article-mode-map ""
3025      ;; Fixme: this should use :active (and maybe :visible).
3026      '("Treatment"
3027        ["Hide headers" gnus-article-hide-headers t]
3028        ["Hide signature" gnus-article-hide-signature t]
3029        ["Hide citation" gnus-article-hide-citation t]
3030        ["Treat overstrike" gnus-article-treat-overstrike t]
3031        ["Remove carriage return" gnus-article-remove-cr t]
3032        ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3033        ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3034        ["Remove base64" gnus-article-de-base64-unreadable t]
3035        ["Treat html" gnus-article-wash-html t]
3036        ["Decode HZ" gnus-article-decode-HZ t]))
3037
3038     ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3039
3040     ;; Note "Post" menu is defined in gnus-sum.el for consistency
3041
3042     (gnus-run-hooks 'gnus-article-menu-hook)))
3043
3044 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3045 ;; Summary.
3046
3047 (defun gnus-article-mode ()
3048   "Major mode for displaying an article.
3049
3050 All normal editing commands are switched off.
3051
3052 The following commands are available in addition to all summary mode
3053 commands:
3054 \\<gnus-article-mode-map>
3055 \\[gnus-article-next-page]\t Scroll the article one page forwards
3056 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3057 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3058 \\[gnus-article-show-summary]\t Display the summary buffer
3059 \\[gnus-article-mail]\t Send a reply to the address near point
3060 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3061 \\[gnus-info-find-node]\t Go to the Gnus info node"
3062   (interactive)
3063   (gnus-simplify-mode-line)
3064   (setq mode-name "Article")
3065   (setq major-mode 'gnus-article-mode)
3066   (make-local-variable 'minor-mode-alist)
3067   (use-local-map gnus-article-mode-map)
3068   (when (gnus-visual-p 'article-menu 'menu)
3069     (gnus-article-make-menu-bar))
3070   (gnus-update-format-specifications nil 'article-mode)
3071   (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3072   (make-local-variable 'gnus-page-broken)
3073   (make-local-variable 'gnus-button-marker-list)
3074   (make-local-variable 'gnus-article-current-summary)
3075   (make-local-variable 'gnus-article-mime-handles)
3076   (make-local-variable 'gnus-article-decoded-p)
3077   (make-local-variable 'gnus-article-mime-handle-alist)
3078   (make-local-variable 'gnus-article-wash-types)
3079   (make-local-variable 'gnus-article-charset)
3080   (make-local-variable 'gnus-article-ignored-charsets)
3081   (gnus-set-default-directory)
3082   (buffer-disable-undo)
3083   (setq buffer-read-only t)
3084   (set-syntax-table gnus-article-mode-syntax-table)
3085   (mm-enable-multibyte)
3086   (gnus-run-hooks 'gnus-article-mode-hook))
3087
3088 (defun gnus-article-setup-buffer ()
3089   "Initialize the article buffer."
3090   (let* ((name (if gnus-single-article-buffer "*Article*"
3091                  (concat "*Article " gnus-newsgroup-name "*")))
3092          (original
3093           (progn (string-match "\\*Article" name)
3094                  (concat " *Original Article"
3095                          (substring name (match-end 0))))))
3096     (setq gnus-article-buffer name)
3097     (setq gnus-original-article-buffer original)
3098     (setq gnus-article-mime-handle-alist nil)
3099     ;; This might be a variable local to the summary buffer.
3100     (unless gnus-single-article-buffer
3101       (save-excursion
3102         (set-buffer gnus-summary-buffer)
3103         (setq gnus-article-buffer name)
3104         (setq gnus-original-article-buffer original)
3105         (gnus-set-global-variables)))
3106     (gnus-article-setup-highlight-words)
3107     ;; Init original article buffer.
3108     (save-excursion
3109       (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3110       (mm-enable-multibyte)
3111       (setq major-mode 'gnus-original-article-mode)
3112       (make-local-variable 'gnus-original-article))
3113     (if (get-buffer name)
3114         (save-excursion
3115           (set-buffer name)
3116           (when gnus-article-mime-handles
3117             (mm-destroy-parts gnus-article-mime-handles)
3118             (setq gnus-article-mime-handles nil))
3119           ;; Set it to nil in article-buffer!
3120           (setq gnus-article-mime-handle-alist nil)
3121           (buffer-disable-undo)
3122           (setq buffer-read-only t)
3123           (unless (eq major-mode 'gnus-article-mode)
3124             (gnus-article-mode))
3125           (current-buffer))
3126       (save-excursion
3127         (set-buffer (gnus-get-buffer-create name))
3128         (gnus-article-mode)
3129         (make-local-variable 'gnus-summary-buffer)
3130         (gnus-summary-set-local-parameters gnus-newsgroup-name)
3131         (current-buffer)))))
3132
3133 ;; Set article window start at LINE, where LINE is the number of lines
3134 ;; from the head of the article.
3135 (defun gnus-article-set-window-start (&optional line)
3136   (set-window-start
3137    (get-buffer-window gnus-article-buffer t)
3138    (save-excursion
3139      (set-buffer gnus-article-buffer)
3140      (goto-char (point-min))
3141      (if (not line)
3142          (point-min)
3143        (gnus-message 6 "Moved to bookmark")
3144        (search-forward "\n\n" nil t)
3145        (forward-line line)
3146        (point)))))
3147
3148 (defun gnus-article-prepare (article &optional all-headers header)
3149   "Prepare ARTICLE in article mode buffer.
3150 ARTICLE should either be an article number or a Message-ID.
3151 If ARTICLE is an id, HEADER should be the article headers.
3152 If ALL-HEADERS is non-nil, no headers are hidden."
3153   (save-excursion
3154     ;; Make sure we start in a summary buffer.
3155     (unless (eq major-mode 'gnus-summary-mode)
3156       (set-buffer gnus-summary-buffer))
3157     (setq gnus-summary-buffer (current-buffer))
3158     (let* ((gnus-article (if header (mail-header-number header) article))
3159            (summary-buffer (current-buffer))
3160            (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3161            (group gnus-newsgroup-name)
3162            result)
3163       (save-excursion
3164         (gnus-article-setup-buffer)
3165         (set-buffer gnus-article-buffer)
3166         ;; Deactivate active regions.
3167         (when (and (boundp 'transient-mark-mode)
3168                    transient-mark-mode)
3169           (setq mark-active nil))
3170         (if (not (setq result (let ((buffer-read-only nil))
3171                                 (gnus-request-article-this-buffer
3172                                  article group))))
3173             ;; There is no such article.
3174             (save-excursion
3175               (when (and (numberp article)
3176                          (not (memq article gnus-newsgroup-sparse)))
3177                 (setq gnus-article-current
3178                       (cons gnus-newsgroup-name article))
3179                 (set-buffer gnus-summary-buffer)
3180                 (setq gnus-current-article article)
3181                 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3182                     (progn
3183                       (gnus-summary-set-agent-mark article)
3184                       (message "Message marked for downloading"))
3185                   (gnus-summary-mark-article article gnus-canceled-mark)
3186                   (unless (memq article gnus-newsgroup-sparse)
3187                     (gnus-error 1 "No such article (may have expired or been canceled)")))))
3188           (if (or (eq result 'pseudo)
3189                   (eq result 'nneething))
3190               (progn
3191                 (save-excursion
3192                   (set-buffer summary-buffer)
3193                   (push article gnus-newsgroup-history)
3194                   (setq gnus-last-article gnus-current-article
3195                         gnus-current-article 0
3196                         gnus-current-headers nil
3197                         gnus-article-current nil)
3198                   (if (eq result 'nneething)
3199                       (gnus-configure-windows 'summary)
3200                     (gnus-configure-windows 'article))
3201                   (gnus-set-global-variables))
3202                 (let ((gnus-article-mime-handle-alist-1
3203                        gnus-article-mime-handle-alist))
3204                   (gnus-set-mode-line 'article)))
3205             ;; The result from the `request' was an actual article -
3206             ;; or at least some text that is now displayed in the
3207             ;; article buffer.
3208             (when (and (numberp article)
3209                        (not (eq article gnus-current-article)))
3210               ;; Seems like a new article has been selected.
3211               ;; `gnus-current-article' must be an article number.
3212               (save-excursion
3213                 (set-buffer summary-buffer)
3214                 (push article gnus-newsgroup-history)
3215                 (setq gnus-last-article gnus-current-article
3216                       gnus-current-article article
3217                       gnus-current-headers
3218                       (gnus-summary-article-header gnus-current-article)
3219                       gnus-article-current
3220                       (cons gnus-newsgroup-name gnus-current-article))
3221                 (unless (vectorp gnus-current-headers)
3222                   (setq gnus-current-headers nil))
3223                 (gnus-summary-goto-subject gnus-current-article)
3224                 (when (gnus-summary-show-thread)
3225                   ;; If the summary buffer really was folded, the
3226                   ;; previous goto may not actually have gone to
3227                   ;; the right article, but the thread root instead.
3228                   ;; So we go again.
3229                   (gnus-summary-goto-subject gnus-current-article))
3230                 (gnus-run-hooks 'gnus-mark-article-hook)
3231                 (gnus-set-mode-line 'summary)
3232                 (when (gnus-visual-p 'article-highlight 'highlight)
3233                   (gnus-run-hooks 'gnus-visual-mark-article-hook))
3234                 ;; Set the global newsgroup variables here.
3235                 (gnus-set-global-variables)
3236                 (setq gnus-have-all-headers
3237                       (or all-headers gnus-show-all-headers))))
3238             (save-excursion
3239               (gnus-configure-windows 'article))
3240             (when (or (numberp article)
3241                       (stringp article))
3242               (gnus-article-prepare-display)
3243               ;; Do page break.
3244               (goto-char (point-min))
3245               (setq gnus-page-broken
3246                     (when gnus-break-pages
3247                       (gnus-narrow-to-page)
3248                       t)))
3249             (let ((gnus-article-mime-handle-alist-1
3250                    gnus-article-mime-handle-alist))
3251               (gnus-set-mode-line 'article))
3252             (article-goto-body)
3253             (set-window-point (get-buffer-window (current-buffer)) (point))
3254             (gnus-configure-windows 'article)
3255             t))))))
3256
3257 ;;;###autoload
3258 (defun gnus-article-prepare-display ()
3259   "Make the current buffer look like a nice article."
3260   ;; Hooks for getting information from the article.
3261   ;; This hook must be called before being narrowed.
3262   (let ((gnus-article-buffer (current-buffer))
3263         buffer-read-only)
3264     (unless (eq major-mode 'gnus-article-mode)
3265       (gnus-article-mode))
3266     (setq buffer-read-only nil
3267           gnus-article-wash-types nil)
3268     (gnus-run-hooks 'gnus-tmp-internal-hook)
3269     (when gnus-display-mime-function
3270       (funcall gnus-display-mime-function))
3271     (gnus-run-hooks 'gnus-article-prepare-hook)))
3272
3273 ;;;
3274 ;;; Gnus MIME viewing functions
3275 ;;;
3276
3277 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3278   "The following specs can be used:
3279 %t  The MIME type
3280 %T  MIME type, along with additional info
3281 %n  The `name' parameter
3282 %d  The description, if any
3283 %l  The length of the encoded part
3284 %p  The part identifier number
3285 %e  Dots if the part isn't displayed")
3286
3287 (defvar gnus-mime-button-line-format-alist
3288   '((?t gnus-tmp-type ?s)
3289     (?T gnus-tmp-type-long ?s)
3290     (?n gnus-tmp-name ?s)
3291     (?d gnus-tmp-description ?s)
3292     (?p gnus-tmp-id ?s)
3293     (?l gnus-tmp-length ?d)
3294     (?e gnus-tmp-dots ?s)))
3295
3296 (defvar gnus-mime-button-commands
3297   '((gnus-article-press-button "\r" "Toggle Display")
3298     (gnus-mime-view-part "v" "View Interactively...")
3299     (gnus-mime-view-part-as-type "t" "View As Type...")
3300     (gnus-mime-view-part-as-charset "C" "View As charset...")
3301     (gnus-mime-save-part "o" "Save...")
3302     (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3303     (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3304     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3305     (gnus-mime-internalize-part "E" "View Internally")
3306     (gnus-mime-externalize-part "e" "View Externally")
3307     (gnus-mime-pipe-part "|" "Pipe To Command...")
3308     (gnus-mime-action-on-part "." "Take action on the part")))
3309
3310 (defun gnus-article-mime-part-status ()
3311   (if gnus-article-mime-handle-alist-1
3312       (if (eq 1 (length gnus-article-mime-handle-alist-1))
3313           " (1 part)"
3314         (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3315     ""))
3316
3317 (defvar gnus-mime-button-map
3318   (let ((map (make-sparse-keymap)))
3319     (unless (>= (string-to-number emacs-version) 21)
3320       ;; XEmacs doesn't care.
3321       (set-keymap-parent map gnus-article-mode-map))
3322     (define-key map gnus-mouse-2 'gnus-article-push-button)
3323     (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3324     (dolist (c gnus-mime-button-commands)
3325       (define-key map (cadr c) (car c)))
3326     map))
3327
3328 (defun gnus-mime-button-menu (event)
3329   "Construct a context-sensitive menu of MIME commands."
3330   (interactive "e")
3331   (save-window-excursion
3332     (let ((pos (event-start event)))
3333       (select-window (posn-window pos))
3334       (goto-char (posn-point pos))
3335       (gnus-article-check-buffer)
3336       (let ((response (x-popup-menu
3337                        t `("MIME Part"
3338                            ("" ,@(mapcar (lambda (c)
3339                                            (cons (caddr c) (car c)))
3340                                          gnus-mime-button-commands))))))
3341         (if response
3342             (call-interactively response))))))
3343
3344 (defun gnus-mime-view-all-parts (&optional handles)
3345   "View all the MIME parts."
3346   (interactive)
3347   (save-current-buffer
3348     (set-buffer gnus-article-buffer)
3349     (let ((handles (or handles gnus-article-mime-handles))
3350           (mail-parse-charset gnus-newsgroup-charset)
3351           (mail-parse-ignored-charsets
3352            (with-current-buffer gnus-summary-buffer
3353              gnus-newsgroup-ignored-charsets)))
3354       (when handles
3355         (mm-remove-parts handles)
3356         (goto-char (point-min))
3357         (or (search-forward "\n\n") (goto-char (point-max)))
3358         (let (buffer-read-only)
3359           (delete-region (point) (point-max))
3360           (mm-display-parts handles))))))
3361
3362 (defun gnus-mime-save-part-and-strip ()
3363   "Save the MIME part under point then replace it with an external body."
3364   (interactive)
3365   (gnus-article-check-buffer)
3366   (let* ((data (get-text-property (point) 'gnus-data))
3367          file param
3368          (handles gnus-article-mime-handles))
3369     (if (mm-multiple-handles gnus-article-mime-handles)
3370         (error "This function is not implemented"))
3371     (setq file (and data (mm-save-part data)))
3372     (when file
3373       (with-current-buffer (mm-handle-buffer data)
3374         (erase-buffer)
3375         (insert "Content-Type: " (mm-handle-media-type data))
3376         (mml-insert-parameter-string (cdr (mm-handle-type data))
3377                                      '(charset))
3378         (insert "\n")
3379         (insert "Content-ID: " (message-make-message-id) "\n")
3380         (insert "Content-Transfer-Encoding: binary\n")
3381         (insert "\n"))
3382       (setcdr data
3383               (cdr (mm-make-handle nil
3384                                    `("message/external-body"
3385                                      (access-type . "LOCAL-FILE")
3386                                      (name . ,file)))))
3387       (set-buffer gnus-summary-buffer)
3388       (gnus-article-edit-article
3389        `(lambda ()
3390            (erase-buffer)
3391            (let ((mail-parse-charset (or gnus-article-charset
3392                                          ',gnus-newsgroup-charset))
3393                  (mail-parse-ignored-charsets
3394                   (or gnus-article-ignored-charsets
3395                       ',gnus-newsgroup-ignored-charsets))
3396                  (mbl mml-buffer-list))
3397              (setq mml-buffer-list nil)
3398              (insert-buffer gnus-original-article-buffer)
3399              (mime-to-mml ',handles)
3400              (setq gnus-article-mime-handles nil)
3401              (let ((mbl1 mml-buffer-list))
3402                (setq mml-buffer-list mbl)
3403                (set (make-local-variable 'mml-buffer-list) mbl1))
3404              ;; LOCAL argument of add-hook differs between GNU Emacs
3405              ;; and XEmacs. make-local-hook makes sure they are local.
3406              (make-local-hook 'kill-buffer-hook)
3407              (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3408        `(lambda (no-highlight)
3409           (let ((mail-parse-charset (or gnus-article-charset
3410                                         ',gnus-newsgroup-charset))
3411                 (message-options message-options)
3412                 (message-options-set-recipient)
3413                 (mail-parse-ignored-charsets
3414                  (or gnus-article-ignored-charsets
3415                      ',gnus-newsgroup-ignored-charsets)))
3416            (mml-to-mime)
3417            (mml-destroy-buffers)
3418            (remove-hook 'kill-buffer-hook
3419                         'mml-destroy-buffers t)
3420            (kill-local-variable 'mml-buffer-list))
3421           (gnus-summary-edit-article-done
3422            ,(or (mail-header-references gnus-current-headers) "")
3423            ,(gnus-group-read-only-p)
3424            ,gnus-summary-buffer no-highlight))))))
3425
3426 (defun gnus-mime-save-part ()
3427   "Save the MIME part under point."
3428   (interactive)
3429   (gnus-article-check-buffer)
3430   (let ((data (get-text-property (point) 'gnus-data)))
3431     (when data
3432       (mm-save-part data))))
3433
3434 (defun gnus-mime-pipe-part ()
3435   "Pipe the MIME part under point to a process."
3436   (interactive)
3437   (gnus-article-check-buffer)
3438   (let ((data (get-text-property (point) 'gnus-data)))
3439     (when data
3440       (mm-pipe-part data))))
3441
3442 (defun gnus-mime-view-part ()
3443   "Interactively choose a viewing method for the MIME part under point."
3444   (interactive)
3445   (gnus-article-check-buffer)
3446   (let ((data (get-text-property (point) 'gnus-data)))
3447     (when data
3448       (setq gnus-article-mime-handles
3449             (mm-merge-handles
3450              gnus-article-mime-handles (setq data (copy-sequence data))))
3451       (mm-interactively-view-part data))))
3452
3453 (defun gnus-mime-view-part-as-type-internal ()
3454   (gnus-article-check-buffer)
3455   (let* ((name (mail-content-type-get
3456                 (mm-handle-type (get-text-property (point) 'gnus-data))
3457                 'name))
3458          (def-type (and name (mm-default-file-encoding name))))
3459     (and def-type (cons def-type 0))))
3460
3461 (defun gnus-mime-view-part-as-type (&optional mime-type)
3462   "Choose a MIME media type, and view the part as such."
3463   (interactive)
3464   (unless mime-type
3465     (setq mime-type (completing-read
3466                      "View as MIME type: "
3467                      (mapcar #'list (mailcap-mime-types))
3468                      nil nil
3469                      (gnus-mime-view-part-as-type-internal))))
3470   (gnus-article-check-buffer)
3471   (let ((handle (get-text-property (point) 'gnus-data)))
3472     (when handle
3473       (setq handle
3474             (mm-make-handle (mm-handle-buffer handle)
3475                             (cons mime-type (cdr (mm-handle-type handle)))
3476                             (mm-handle-encoding handle)
3477                             (mm-handle-undisplayer handle)
3478                             (mm-handle-disposition handle)
3479                             (mm-handle-description handle)
3480                             nil
3481                             (mm-handle-id handle)))
3482       (setq gnus-article-mime-handles
3483             (mm-merge-handles gnus-article-mime-handles handle))
3484       (gnus-mm-display-part handle))))
3485
3486 (defun gnus-mime-copy-part (&optional handle)
3487   "Put the the MIME part under point into a new buffer."
3488   (interactive)
3489   (gnus-article-check-buffer)
3490   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3491          (contents (and handle (mm-get-part handle)))
3492          (base (and handle
3493                     (file-name-nondirectory
3494                      (or
3495                       (mail-content-type-get (mm-handle-type handle) 'name)
3496                       (mail-content-type-get (mm-handle-type handle)
3497                                              'filename)
3498                       "*decoded*"))))
3499          (buffer (and base (generate-new-buffer base))))
3500     (when contents
3501       (switch-to-buffer buffer)
3502       (insert contents)
3503       ;; We do it this way to make `normal-mode' set the appropriate mode.
3504       (unwind-protect
3505           (progn
3506             (setq buffer-file-name (expand-file-name base))
3507             (normal-mode))
3508         (setq buffer-file-name nil))
3509       (goto-char (point-min)))))
3510
3511 (defun gnus-mime-inline-part (&optional handle arg)
3512   "Insert the MIME part under point into the current buffer."
3513   (interactive (list nil current-prefix-arg))
3514   (gnus-article-check-buffer)
3515   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3516          contents charset
3517          (b (point))
3518          buffer-read-only)
3519     (when handle
3520       (if (and (not arg) (mm-handle-undisplayer handle))
3521           (mm-remove-part handle)
3522         (setq contents (mm-get-part handle))
3523         (cond
3524          ((not arg)
3525           (setq charset (or (mail-content-type-get
3526                              (mm-handle-type handle) 'charset)
3527                             gnus-newsgroup-charset)))
3528          ((numberp arg)
3529           (if (mm-handle-undisplayer handle)
3530               (mm-remove-part handle))
3531           (setq charset
3532                 (or (cdr (assq arg
3533                                gnus-summary-show-article-charset-alist))
3534                     (mm-read-coding-system "Charset: ")))))
3535         (forward-line 2)
3536         (mm-insert-inline handle
3537                           (if (and charset
3538                                    (setq charset (mm-charset-to-coding-system
3539                                                   charset))
3540                                    (not (eq charset 'ascii)))
3541                               (mm-decode-coding-string contents charset)
3542                             contents))
3543         (goto-char b)))))
3544
3545 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3546   "Insert the MIME part under point into the current buffer using the
3547 specified charset."
3548   (interactive (list nil current-prefix-arg))
3549   (gnus-article-check-buffer)
3550   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3551          contents charset
3552          (b (point))
3553          buffer-read-only)
3554     (when handle
3555       (if (mm-handle-undisplayer handle)
3556           (mm-remove-part handle))
3557       (let ((gnus-newsgroup-charset
3558              (or (cdr (assq arg
3559                             gnus-summary-show-article-charset-alist))
3560                  (mm-read-coding-system "Charset: ")))
3561           (gnus-newsgroup-ignored-charsets 'gnus-all))
3562         (gnus-article-press-button)))))
3563
3564 (defun gnus-mime-externalize-part (&optional handle)
3565   "View the MIME part under point with an external viewer."
3566   (interactive)
3567   (gnus-article-check-buffer)
3568   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3569          (mm-user-display-methods nil)
3570          (mm-inlined-types nil)
3571          (mail-parse-charset gnus-newsgroup-charset)
3572          (mail-parse-ignored-charsets
3573           (save-excursion (set-buffer gnus-summary-buffer)
3574                           gnus-newsgroup-ignored-charsets)))
3575     (when handle
3576       (if (mm-handle-undisplayer handle)
3577           (mm-remove-part handle)
3578         (mm-display-part handle)))))
3579
3580 (defun gnus-mime-internalize-part (&optional handle)
3581   "View the MIME part under point with an internal viewer.
3582 If no internal viewer is available, use an external viewer."
3583   (interactive)
3584   (gnus-article-check-buffer)
3585   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3586          (mm-inlined-types '(".*"))
3587          (mm-inline-large-images t)
3588          (mail-parse-charset gnus-newsgroup-charset)
3589          (mail-parse-ignored-charsets
3590           (save-excursion (set-buffer gnus-summary-buffer)
3591                           gnus-newsgroup-ignored-charsets)))
3592     (when handle
3593       (if (mm-handle-undisplayer handle)
3594           (mm-remove-part handle)
3595         (mm-display-part handle)))))
3596
3597 (defun gnus-mime-action-on-part (&optional action)
3598   "Do something with the MIME attachment at \(point\)."
3599   (interactive
3600    (list (completing-read "Action: " gnus-mime-action-alist)))
3601   (gnus-article-check-buffer)
3602   (let ((action-pair (assoc action gnus-mime-action-alist)))
3603     (if action-pair
3604         (funcall (cdr action-pair)))))
3605
3606 (defun gnus-article-part-wrapper (n function)
3607   (save-current-buffer
3608     (set-buffer gnus-article-buffer)
3609     (when (> n (length gnus-article-mime-handle-alist))
3610       (error "No such part"))
3611     (gnus-article-goto-part n)
3612     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3613       (funcall function handle))))
3614
3615 (defun gnus-article-pipe-part (n)
3616   "Pipe MIME part N, which is the numerical prefix."
3617   (interactive "p")
3618   (gnus-article-part-wrapper n 'mm-pipe-part))
3619
3620 (defun gnus-article-save-part (n)
3621   "Save MIME part N, which is the numerical prefix."
3622   (interactive "p")
3623   (gnus-article-part-wrapper n 'mm-save-part))
3624
3625 (defun gnus-article-interactively-view-part (n)
3626   "View MIME part N interactively, which is the numerical prefix."
3627   (interactive "p")
3628   (gnus-article-part-wrapper n 'mm-interactively-view-part))
3629
3630 (defun gnus-article-copy-part (n)
3631   "Copy MIME part N, which is the numerical prefix."
3632   (interactive "p")
3633   (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3634
3635 (defun gnus-article-view-part-as-charset (n)
3636   "Copy MIME part N, which is the numerical prefix."
3637   (interactive "p")
3638   (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3639
3640 (defun gnus-article-externalize-part (n)
3641   "View MIME part N externally, which is the numerical prefix."
3642   (interactive "p")
3643   (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3644
3645 (defun gnus-article-inline-part (n)
3646   "Inline MIME part N, which is the numerical prefix."
3647   (interactive "p")
3648   (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3649
3650 (defun gnus-article-mime-match-handle-first (condition)
3651   (if condition
3652       (let ((alist gnus-article-mime-handle-alist) ihandle n)
3653         (while (setq ihandle (pop alist))
3654           (if (and (cond
3655                     ((functionp condition)
3656                      (funcall condition (cdr ihandle)))
3657                     ((eq condition 'undisplayed)
3658                      (not (or (mm-handle-undisplayer (cdr ihandle))
3659                               (equal (mm-handle-media-type (cdr ihandle))
3660                                      "multipart/alternative"))))
3661                     ((eq condition 'undisplayed-alternative)
3662                      (not (mm-handle-undisplayer (cdr ihandle))))
3663                     (t t))
3664                    (gnus-article-goto-part (car ihandle))
3665                    (or (not n) (< (car ihandle) n)))
3666               (setq n (car ihandle))))
3667         (or n 1))
3668     1))
3669
3670 (defun gnus-article-view-part (&optional n)
3671   "View MIME part N, which is the numerical prefix."
3672   (interactive "P")
3673   (save-current-buffer
3674     (set-buffer gnus-article-buffer)
3675     (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3676                              gnus-article-mime-match-handle-function)))
3677     (when (> n (length gnus-article-mime-handle-alist))
3678       (error "No such part"))
3679     (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3680       (when (gnus-article-goto-part n)
3681         (if (equal (car handle) "multipart/alternative")
3682             (gnus-article-press-button)
3683           (when (eq (gnus-mm-display-part handle) 'internal)
3684             (gnus-set-window-start)))))))
3685
3686 (defsubst gnus-article-mime-total-parts ()
3687   (if (bufferp (car gnus-article-mime-handles))
3688       1 ;; single part
3689     (1- (length gnus-article-mime-handles))))
3690
3691 (defun gnus-mm-display-part (handle)
3692   "Display HANDLE and fix MIME button."
3693   (let ((id (get-text-property (point) 'gnus-part))
3694         (point (point))
3695         buffer-read-only)
3696     (forward-line 1)
3697     (prog1
3698         (let ((window (selected-window))
3699               (mail-parse-charset gnus-newsgroup-charset)
3700               (mail-parse-ignored-charsets
3701                (save-excursion (set-buffer gnus-summary-buffer)
3702                                gnus-newsgroup-ignored-charsets)))
3703           (save-excursion
3704             (unwind-protect
3705                 (let ((win (get-buffer-window (current-buffer) t))
3706                       (beg (point)))
3707                   (when win
3708                     (select-window win))
3709                   (goto-char point)
3710                   (forward-line)
3711                   (if (mm-handle-displayed-p handle)
3712                       ;; This will remove the part.
3713                       (mm-display-part handle)
3714                     (save-restriction
3715                       (narrow-to-region (point) 
3716                                         (if (eobp) (point) (1+ (point))))
3717                       (mm-display-part handle)
3718                       ;; We narrow to the part itself and
3719                       ;; then call the treatment functions.
3720                       (goto-char (point-min))
3721                       (forward-line 1)
3722                       (narrow-to-region (point) (point-max))
3723                       (gnus-treat-article
3724                        nil id
3725                        (gnus-article-mime-total-parts)
3726                        (mm-handle-media-type handle)))))
3727               (if (window-live-p window)
3728                   (select-window window)))))
3729       (goto-char point)
3730       (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3731       (gnus-insert-mime-button
3732        handle id (list (mm-handle-displayed-p handle)))
3733       (goto-char point))))
3734
3735 (defun gnus-article-goto-part (n)
3736   "Go to MIME part N."
3737   (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3738     (when point
3739       (goto-char point))))
3740
3741 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3742   (let ((gnus-tmp-name
3743          (or (mail-content-type-get (mm-handle-type handle) 'name)
3744              (mail-content-type-get (mm-handle-disposition handle) 'filename)
3745              (mail-content-type-get (mm-handle-type handle) 'url)
3746              ""))
3747         (gnus-tmp-type (mm-handle-media-type handle))
3748         (gnus-tmp-description
3749          (mail-decode-encoded-word-string (or (mm-handle-description handle)
3750                                               "")))
3751         (gnus-tmp-dots
3752          (if (if displayed (car displayed)
3753                (mm-handle-displayed-p handle))
3754              "" "..."))
3755         (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3756                            (buffer-size)))
3757         gnus-tmp-type-long b e)
3758     (when (string-match ".*/" gnus-tmp-name)
3759       (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3760     (setq gnus-tmp-type-long (concat gnus-tmp-type
3761                                      (and (not (equal gnus-tmp-name ""))
3762                                           (concat "; " gnus-tmp-name))))
3763     (unless (equal gnus-tmp-description "")
3764       (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3765     (unless (bolp)
3766       (insert "\n"))
3767     (setq b (point))
3768     (gnus-eval-format
3769      gnus-mime-button-line-format gnus-mime-button-line-format-alist
3770      `(keymap ,gnus-mime-button-map
3771               ,@(if (>= (string-to-number emacs-version) 21)
3772                     nil
3773                   (list 'local-map gnus-mime-button-map))
3774               gnus-callback gnus-mm-display-part
3775               gnus-part ,gnus-tmp-id
3776               article-type annotation
3777               gnus-data ,handle))
3778     (setq e (point))
3779     (widget-convert-button
3780      'link b e
3781      :mime-handle handle
3782      :action 'gnus-widget-press-button
3783      :button-keymap gnus-mime-button-map
3784      :help-echo
3785      (lambda (widget/window &optional overlay pos)
3786        ;; Needed to properly clear the message due to a bug in
3787        ;; wid-edit (XEmacs only).
3788        (if (boundp 'help-echo-owns-message)
3789            (setq help-echo-owns-message t))
3790        (format
3791         "%S: %s the MIME part; %S: more options"
3792         (aref gnus-mouse-2 0)
3793         ;; XEmacs will get a single widget arg; Emacs 21 will get
3794         ;; window, overlay, position.
3795         (if (mm-handle-displayed-p
3796              (if overlay
3797                  (with-current-buffer (gnus-overlay-buffer overlay)
3798                    (widget-get (widget-at (gnus-overlay-start overlay))
3799                                :mime-handle))
3800                (widget-get widget/window :mime-handle)))
3801             "hide" "show")
3802         (aref gnus-down-mouse-3 0))))))
3803
3804 (defun gnus-widget-press-button (elems el)
3805   (goto-char (widget-get elems :from))
3806   (gnus-article-press-button))
3807
3808 (defvar gnus-displaying-mime nil)
3809
3810 (defun gnus-display-mime (&optional ihandles)
3811   "Display the MIME parts."
3812   (save-excursion
3813     (save-selected-window
3814       (let ((window (get-buffer-window gnus-article-buffer))
3815             (point (point)))
3816         (when window
3817           (select-window window)
3818           ;; We have to do this since selecting the window
3819           ;; may change the point.  So we set the window point.
3820           (set-window-point window point)))
3821       (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3822              buffer-read-only handle name type b e display)
3823         (when (and (not ihandles)
3824                    (not gnus-displaying-mime))
3825           ;; Top-level call; we clean up.
3826           (when gnus-article-mime-handles
3827             (mm-destroy-parts gnus-article-mime-handles)
3828             (setq gnus-article-mime-handle-alist nil));; A trick.
3829           (setq gnus-article-mime-handles handles)
3830           ;; We allow users to glean info from the handles.
3831           (when gnus-article-mime-part-function
3832             (gnus-mime-part-function handles)))
3833         (if (and handles
3834                  (or (not (stringp (car handles)))
3835                      (cdr handles)))
3836             (progn
3837               (when (and (not ihandles)
3838                          (not gnus-displaying-mime))
3839                 ;; Clean up for mime parts.
3840                 (article-goto-body)
3841                 (delete-region (point) (point-max)))
3842               (let ((gnus-displaying-mime t))
3843                 (gnus-mime-display-part handles)))
3844           (save-restriction
3845             (article-goto-body)
3846             (narrow-to-region (point) (point-max))
3847             (gnus-treat-article nil 1 1)
3848             (widen)))
3849         (unless ihandles
3850           ;; Highlight the headers.
3851           (save-excursion
3852             (save-restriction
3853               (article-goto-body)
3854               (narrow-to-region (point-min) (point))
3855               (gnus-treat-article 'head))))))))
3856
3857 (defvar gnus-mime-display-multipart-as-mixed nil)
3858 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
3859 (defvar gnus-mime-display-multipart-related-as-mixed nil)
3860
3861 (defun gnus-mime-display-part (handle)
3862   (cond
3863    ;; Single part.
3864    ((not (stringp (car handle)))
3865     (gnus-mime-display-single handle))
3866    ;; User-defined multipart
3867    ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3868     (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3869              handle))
3870    ;; multipart/alternative
3871    ((and (equal (car handle) "multipart/alternative")
3872          (not (or gnus-mime-display-multipart-as-mixed
3873                   gnus-mime-display-multipart-alternative-as-mixed)))
3874     (let ((id (1+ (length gnus-article-mime-handle-alist))))
3875       (push (cons id handle) gnus-article-mime-handle-alist)
3876       (gnus-mime-display-alternative (cdr handle) nil nil id)))
3877    ;; multipart/related
3878    ((and (equal (car handle) "multipart/related")
3879          (not (or gnus-mime-display-multipart-as-mixed
3880                   gnus-mime-display-multipart-related-as-mixed)))
3881     ;;;!!!We should find the start part, but we just default
3882     ;;;!!!to the first part.
3883     ;;(gnus-mime-display-part (cadr handle))
3884     ;;;!!! Most multipart/related is an HTML message plus images.
3885     ;;;!!! Unfortunately we are unable to let W3 display those
3886     ;;;!!! included images, so we just display it as a mixed multipart.
3887     ;;(gnus-mime-display-mixed (cdr handle))
3888     ;;;!!! No, w3 can display everything just fine.
3889     (gnus-mime-display-part (cadr handle)))
3890    ((equal (car handle) "multipart/signed")
3891     (or (memq 'signed gnus-article-wash-types)
3892         (push 'signed gnus-article-wash-types))
3893     (gnus-mime-display-security handle))
3894    ((equal (car handle) "multipart/encrypted")
3895     (or (memq 'encrypted gnus-article-wash-types)
3896         (push 'encrypted gnus-article-wash-types))
3897     (gnus-mime-display-security handle))
3898    ;; Other multiparts are handled like multipart/mixed.
3899    (t
3900     (gnus-mime-display-mixed (cdr handle)))))
3901
3902 (defun gnus-mime-part-function (handles)
3903   (if (stringp (car handles))
3904       (mapcar 'gnus-mime-part-function (cdr handles))
3905     (funcall gnus-article-mime-part-function handles)))
3906
3907 (defun gnus-mime-display-mixed (handles)
3908   (mapcar 'gnus-mime-display-part handles))
3909
3910 (defun gnus-mime-display-single (handle)
3911   (let ((type (mm-handle-media-type handle))
3912         (ignored gnus-ignored-mime-types)
3913         (not-attachment t)
3914         (move nil)
3915         display text)
3916     (catch 'ignored
3917       (progn
3918         (while ignored
3919           (when (string-match (pop ignored) type)
3920             (throw 'ignored nil)))
3921         (if (and (setq not-attachment
3922                        (and (not (mm-inline-override-p handle))
3923                             (or (not (mm-handle-disposition handle))
3924                                 (equal (car (mm-handle-disposition handle))
3925                                        "inline")
3926                                 (mm-attachment-override-p handle))))
3927                  (mm-automatic-display-p handle)
3928                  (or (and
3929                       (mm-inlinable-p handle)
3930                       (mm-inlined-p handle))
3931                      (mm-automatic-external-display-p type)))
3932             (setq display t)
3933           (when (equal (mm-handle-media-supertype handle) "text")
3934             (setq text t)))
3935         (let ((id (1+ (length gnus-article-mime-handle-alist)))
3936               beg)
3937           (push (cons id handle) gnus-article-mime-handle-alist)
3938           (when (or (not display)
3939                     (not (gnus-unbuttonized-mime-type-p type)))
3940             ;(gnus-article-insert-newline)
3941             (gnus-insert-mime-button
3942              handle id (list (or display (and not-attachment text))))
3943             (gnus-article-insert-newline)
3944             ;(gnus-article-insert-newline)
3945             ;; Remember modify the number of forward lines.
3946             (setq move t))
3947           (setq beg (point))
3948           (cond
3949            (display
3950             (when move
3951               (forward-line -1)
3952               (setq beg (point)))
3953             (let ((mail-parse-charset gnus-newsgroup-charset)
3954                   (mail-parse-ignored-charsets
3955                    (save-excursion (condition-case ()
3956                                        (set-buffer gnus-summary-buffer)
3957                                      (error))
3958                                    gnus-newsgroup-ignored-charsets)))
3959               (mm-display-part handle t))
3960             (goto-char (point-max)))
3961            ((and text not-attachment)
3962             (when move
3963               (forward-line -1)
3964               (setq beg (point)))
3965             (gnus-article-insert-newline)
3966             (mm-insert-inline handle (mm-get-part handle))
3967             (goto-char (point-max))))
3968           ;; Do highlighting.
3969           (save-excursion
3970             (save-restriction
3971               (narrow-to-region beg (point))
3972               (gnus-treat-article
3973                nil id
3974                (gnus-article-mime-total-parts)
3975                (mm-handle-media-type handle)))))))))
3976
3977 (defun gnus-unbuttonized-mime-type-p (type)
3978   "Say whether TYPE is to be unbuttonized."
3979   (unless gnus-inhibit-mime-unbuttonizing
3980     (when (catch 'found
3981             (let ((types gnus-unbuttonized-mime-types))
3982               (while types
3983                 (when (string-match (pop types) type)
3984                   (throw 'found t)))))
3985       (not (catch 'found
3986              (let ((types gnus-buttonized-mime-types))
3987                (while types
3988                  (when (string-match (pop types) type)
3989                    (throw 'found t)))))))))
3990
3991 (defun gnus-article-insert-newline ()
3992   "Insert a newline, but mark it as undeletable."
3993   (gnus-put-text-property
3994    (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3995
3996 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3997   (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3998          (ihandles handles)
3999          (point (point))
4000          handle buffer-read-only from props begend not-pref)
4001     (save-window-excursion
4002       (save-restriction
4003         (when ibegend
4004           (narrow-to-region (car ibegend)
4005                             (or (cdr ibegend)
4006                                 (progn
4007                                   (goto-char (car ibegend))
4008                                   (forward-line 2)
4009                                   (point))))
4010           (delete-region (point-min) (point-max))
4011           (mm-remove-parts handles))
4012         (setq begend (list (point-marker)))
4013         ;; Do the toggle.
4014         (unless (setq not-pref (cadr (member preferred ihandles)))
4015           (setq not-pref (car ihandles)))
4016         (when (or ibegend
4017                   (not preferred)
4018                   (not (gnus-unbuttonized-mime-type-p
4019                         "multipart/alternative")))
4020           (gnus-add-text-properties
4021            (setq from (point))
4022            (progn
4023              (insert (format "%d.  " id))
4024              (point))
4025            `(gnus-callback
4026              (lambda (handles)
4027                (unless ,(not ibegend)
4028                  (setq gnus-article-mime-handle-alist
4029                        ',gnus-article-mime-handle-alist))
4030                (gnus-mime-display-alternative
4031                 ',ihandles ',not-pref ',begend ,id))
4032              ,@(if (>= (string-to-number emacs-version) 21)
4033                    nil ;; XEmacs doesn't care
4034                  (list 'local-map gnus-mime-button-map))
4035              ,gnus-mouse-face-prop ,gnus-article-mouse-face
4036              face ,gnus-article-button-face
4037              keymap ,gnus-mime-button-map
4038              gnus-part ,id
4039              gnus-data ,handle))
4040           (widget-convert-button 'link from (point)
4041                                  :action 'gnus-widget-press-button
4042                                  :button-keymap gnus-widget-button-keymap)
4043           ;; Do the handles
4044           (while (setq handle (pop handles))
4045             (gnus-add-text-properties
4046              (setq from (point))
4047              (progn
4048                (insert (format "(%c) %-18s"
4049                                (if (equal handle preferred) ?* ? )
4050                                (mm-handle-media-type handle)))
4051                (point))
4052              `(gnus-callback
4053                (lambda (handles)
4054                  (unless ,(not ibegend)
4055                    (setq gnus-article-mime-handle-alist
4056                          ',gnus-article-mime-handle-alist))
4057                  (gnus-mime-display-alternative
4058                   ',ihandles ',handle ',begend ,id))
4059                ,@(if (>= (string-to-number emacs-version) 21)
4060                      nil ;; XEmacs doesn't care
4061                    (list 'local-map gnus-mime-button-map))
4062                ,gnus-mouse-face-prop ,gnus-article-mouse-face
4063                face ,gnus-article-button-face
4064                keymap ,gnus-mime-button-map
4065                gnus-part ,id
4066                gnus-data ,handle))
4067             (widget-convert-button 'link from (point)
4068                                    :action 'gnus-widget-press-button
4069                                    :button-keymap gnus-widget-button-keymap)
4070             (insert "  "))
4071           (insert "\n\n"))
4072         (when preferred
4073           (if (stringp (car preferred))
4074               (gnus-display-mime preferred)
4075             (let ((mail-parse-charset gnus-newsgroup-charset)
4076                   (mail-parse-ignored-charsets
4077                    (save-excursion (set-buffer gnus-summary-buffer)
4078                                    gnus-newsgroup-ignored-charsets)))
4079               (mm-display-part preferred)
4080               ;; Do highlighting.
4081               (save-excursion
4082                 (save-restriction
4083                   (narrow-to-region (car begend) (point-max))
4084                   (gnus-treat-article
4085                    nil (length gnus-article-mime-handle-alist)
4086                    (gnus-article-mime-total-parts)
4087                    (mm-handle-media-type handle))))))
4088           (goto-char (point-max))
4089           (setcdr begend (point-marker)))))
4090     (when ibegend
4091       (goto-char point))))
4092
4093 (defun gnus-article-wash-status ()
4094   "Return a string which display status of article washing."
4095   (save-excursion
4096     (set-buffer gnus-article-buffer)
4097     (let ((cite (memq 'cite gnus-article-wash-types))
4098           (headers (memq 'headers gnus-article-wash-types))
4099           (boring (memq 'boring-headers gnus-article-wash-types))
4100           (pgp (memq 'pgp gnus-article-wash-types))
4101           (pem (memq 'pem gnus-article-wash-types))
4102           (signed (memq 'signed gnus-article-wash-types))
4103           (encrypted (memq 'encrypted gnus-article-wash-types))
4104           (signature (memq 'signature gnus-article-wash-types))
4105           (overstrike (memq 'overstrike gnus-article-wash-types))
4106           (emphasis (memq 'emphasis gnus-article-wash-types)))
4107       (format "%c%c%c%c%c%c"
4108               (if cite ?c ? )
4109               (if (or headers boring) ?h ? )
4110               (if (or pgp pem signed encrypted) ?p ? )
4111               (if signature ?s ? )
4112               (if overstrike ?o ? )
4113               (if emphasis ?e ? )))))
4114
4115 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4116
4117 (defun gnus-article-maybe-hide-headers ()
4118   "Hide unwanted headers if `gnus-have-all-headers' is nil.
4119 Provided for backwards compatibility."
4120   (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4121                  (not (save-excursion (set-buffer gnus-summary-buffer)
4122                                       gnus-have-all-headers)))
4123              (not gnus-inhibit-hiding))
4124     (gnus-article-hide-headers)))
4125
4126 ;;; Article savers.
4127
4128 (defun gnus-output-to-file (file-name)
4129   "Append the current article to a file named FILE-NAME."
4130   (let ((artbuf (current-buffer)))
4131     (with-temp-buffer
4132       (insert-buffer-substring artbuf)
4133       ;; Append newline at end of the buffer as separator, and then
4134       ;; save it to file.
4135       (goto-char (point-max))
4136       (insert "\n")
4137       (let ((file-name-coding-system nnmail-pathname-coding-system))
4138         (mm-append-to-file (point-min) (point-max) file-name))
4139       t)))
4140
4141 (defun gnus-narrow-to-page (&optional arg)
4142   "Narrow the article buffer to a page.
4143 If given a numerical ARG, move forward ARG pages."
4144   (interactive "P")
4145   (setq arg (if arg (prefix-numeric-value arg) 0))
4146   (save-excursion
4147     (set-buffer gnus-article-buffer)
4148     (goto-char (point-min))
4149     (widen)
4150     ;; Remove any old next/prev buttons.
4151     (when (gnus-visual-p 'page-marker)
4152       (let ((buffer-read-only nil))
4153         (gnus-remove-text-with-property 'gnus-prev)
4154         (gnus-remove-text-with-property 'gnus-next)))
4155     (when
4156         (cond ((< arg 0)
4157                (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4158               ((> arg 0)
4159                (re-search-forward page-delimiter nil 'move arg)))
4160       (goto-char (match-end 0)))
4161     (narrow-to-region
4162      (point)
4163      (if (re-search-forward page-delimiter nil 'move)
4164          (match-beginning 0)
4165        (point)))
4166     (when (and (gnus-visual-p 'page-marker)
4167                (not (= (point-min) 1)))
4168       (save-excursion
4169         (goto-char (point-min))
4170         (gnus-insert-prev-page-button)))
4171     (when (and (gnus-visual-p 'page-marker)
4172                (< (+ (point-max) 2) (buffer-size)))
4173       (save-excursion
4174         (goto-char (point-max))
4175         (gnus-insert-next-page-button)))))
4176
4177 ;; Article mode commands
4178
4179 (defun gnus-article-goto-next-page ()
4180   "Show the next page of the article."
4181   (interactive)
4182   (when (gnus-article-next-page)
4183     (goto-char (point-min))
4184     (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4185
4186 (defun gnus-article-goto-prev-page ()
4187   "Show the next page of the article."
4188   (interactive)
4189   (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4190     (gnus-article-prev-page nil)))
4191
4192 (defun gnus-article-next-page (&optional lines)
4193   "Show the next page of the current article.
4194 If end of article, return non-nil.  Otherwise return nil.
4195 Argument LINES specifies lines to be scrolled up."
4196   (interactive "p")
4197   (move-to-window-line -1)
4198   (if (save-excursion
4199         (end-of-line)
4200         (and (pos-visible-in-window-p)  ;Not continuation line.
4201              (eobp)))
4202       ;; Nothing in this page.
4203       (if (or (not gnus-page-broken)
4204               (save-excursion
4205                 (save-restriction
4206                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4207           t                             ;Nothing more.
4208         (gnus-narrow-to-page 1)         ;Go to next page.
4209         nil)
4210     ;; More in this page.
4211     (let ((scroll-in-place nil))
4212       (condition-case ()
4213           (scroll-up lines)
4214         (end-of-buffer
4215          ;; Long lines may cause an end-of-buffer error.
4216          (goto-char (point-max)))))
4217     (move-to-window-line 0)
4218     nil))
4219
4220 (defun gnus-article-prev-page (&optional lines)
4221   "Show previous page of current article.
4222 Argument LINES specifies lines to be scrolled down."
4223   (interactive "p")
4224   (move-to-window-line 0)
4225   (if (and gnus-page-broken
4226            (bobp)
4227            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4228       (progn
4229         (gnus-narrow-to-page -1)        ;Go to previous page.
4230         (goto-char (point-max))
4231         (recenter -1))
4232     (let ((scroll-in-place nil))
4233       (prog1
4234           (condition-case ()
4235               (scroll-down lines)
4236             (beginning-of-buffer
4237              (goto-char (point-min))))
4238         (move-to-window-line 0)))))
4239
4240 (defun gnus-article-refer-article ()
4241   "Read article specified by message-id around point."
4242   (interactive)
4243   (let ((point (point)))
4244     (search-forward ">" nil t)          ;Move point to end of "<....>".
4245     (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4246         (let ((message-id (match-string 1)))
4247           (goto-char point)
4248           (set-buffer gnus-summary-buffer)
4249           (gnus-summary-refer-article message-id))
4250       (goto-char (point))
4251       (error "No references around point"))))
4252
4253 (defun gnus-article-show-summary ()
4254   "Reconfigure windows to show summary buffer."
4255   (interactive)
4256   (if (not (gnus-buffer-live-p gnus-summary-buffer))
4257       (error "There is no summary buffer for this article buffer")
4258     (gnus-article-set-globals)
4259     (gnus-configure-windows 'article)
4260     (gnus-summary-goto-subject gnus-current-article)
4261     (gnus-summary-position-point)))
4262
4263 (defun gnus-article-describe-briefly ()
4264   "Describe article mode commands briefly."
4265   (interactive)
4266   (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")))
4267
4268 (defun gnus-article-summary-command ()
4269   "Execute the last keystroke in the summary buffer."
4270   (interactive)
4271   (let ((obuf (current-buffer))
4272         (owin (current-window-configuration))
4273         func)
4274     (switch-to-buffer gnus-article-current-summary 'norecord)
4275     (setq func (lookup-key (current-local-map) (this-command-keys)))
4276     (call-interactively func)
4277     (set-buffer obuf)
4278     (set-window-configuration owin)
4279     (set-window-point (get-buffer-window (current-buffer)) (point))))
4280
4281 (defun gnus-article-summary-command-nosave ()
4282   "Execute the last keystroke in the summary buffer."
4283   (interactive)
4284   (let (func)
4285     (pop-to-buffer gnus-article-current-summary 'norecord)
4286     (setq func (lookup-key (current-local-map) (this-command-keys)))
4287     (call-interactively func)))
4288
4289 (defun gnus-article-check-buffer ()
4290   "Beep if not in an article buffer."
4291   (unless (equal major-mode 'gnus-article-mode)
4292     (error "Command invoked outside of a Gnus article buffer")))
4293
4294 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4295   "Read a summary buffer key sequence and execute it from the article buffer."
4296   (interactive "P")
4297   (gnus-article-check-buffer)
4298   (let ((nosaves
4299          '("q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
4300            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4301            "=" "^" "\M-^" "|"))
4302         (nosave-but-article
4303          '("A\r"))
4304         (nosave-in-article
4305          '("\C-d"))
4306         (up-to-top
4307          '("n" "Gn" "p" "Gp"))
4308         keys new-sum-point)
4309     (save-excursion
4310       (set-buffer gnus-article-current-summary)
4311       (let (gnus-pick-mode)
4312         (push (or key last-command-event) unread-command-events)
4313         (setq keys (if (featurep 'xemacs)
4314                        (events-to-keys (read-key-sequence nil))
4315                      (read-key-sequence nil)))))
4316
4317     (message "")
4318
4319     (if (or (member keys nosaves)
4320             (member keys nosave-but-article)
4321             (member keys nosave-in-article))
4322         (let (func)
4323           (save-window-excursion
4324             (pop-to-buffer gnus-article-current-summary 'norecord)
4325             ;; We disable the pick minor mode commands.
4326             (let (gnus-pick-mode)
4327               (setq func (lookup-key (current-local-map) keys))))
4328           (if (or (not func)
4329                   (numberp func))
4330               (ding)
4331             (unless (member keys nosave-in-article)
4332               (set-buffer gnus-article-current-summary))
4333             (call-interactively func)
4334             (setq new-sum-point (point)))
4335           (when (member keys nosave-but-article)
4336             (pop-to-buffer gnus-article-buffer 'norecord)))
4337       ;; These commands should restore window configuration.
4338       (let ((obuf (current-buffer))
4339             (owin (current-window-configuration))
4340             (opoint (point))
4341             (summary gnus-article-current-summary)
4342             func in-buffer selected)
4343         (if not-restore-window
4344             (pop-to-buffer summary 'norecord)
4345           (switch-to-buffer summary 'norecord))
4346         (setq in-buffer (current-buffer))
4347         ;; We disable the pick minor mode commands.
4348         (if (and (setq func (let (gnus-pick-mode)
4349                               (lookup-key (current-local-map) keys)))
4350                  (functionp func))
4351             (progn
4352               (call-interactively func)
4353               (setq new-sum-point (point))
4354               (when (eq in-buffer (current-buffer))
4355                 (setq selected (gnus-summary-select-article))
4356                 (set-buffer obuf)
4357                 (unless not-restore-window
4358                   (set-window-configuration owin))
4359                 (when (eq selected 'old)
4360                   (article-goto-body)
4361                   (set-window-start (get-buffer-window (current-buffer))
4362                                     1)
4363                   (set-window-point (get-buffer-window (current-buffer))
4364                                     (point)))
4365                 (let ((win (get-buffer-window gnus-article-current-summary)))
4366                   (when win
4367                     (set-window-point win new-sum-point))))    )
4368           (switch-to-buffer gnus-article-buffer)
4369           (ding))))))
4370
4371 (defun gnus-article-describe-key (key)
4372   "Display documentation of the function invoked by KEY.  KEY is a string."
4373   (interactive "kDescribe key: ")
4374   (gnus-article-check-buffer)
4375   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4376       (save-excursion
4377         (set-buffer gnus-article-current-summary)
4378         (let (gnus-pick-mode)
4379           (if (featurep 'xemacs)
4380               (progn
4381                 (push (elt key 0) unread-command-events)
4382                 (setq key (events-to-keys
4383                            (read-key-sequence "Describe key: "))))
4384             (setq unread-command-events
4385                   (mapcar
4386                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4387                    (string-to-list key)))
4388             (setq key (read-key-sequence "Describe key: "))))
4389         (describe-key key))
4390     (describe-key key)))
4391
4392 (defun gnus-article-describe-key-briefly (key &optional insert)
4393   "Display documentation of the function invoked by KEY.  KEY is a string."
4394   (interactive "kDescribe key: \nP")
4395   (gnus-article-check-buffer)
4396   (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4397       (save-excursion
4398         (set-buffer gnus-article-current-summary)
4399         (let (gnus-pick-mode)
4400           (if (featurep 'xemacs)
4401               (progn
4402                 (push (elt key 0) unread-command-events)
4403                 (setq key (events-to-keys
4404                            (read-key-sequence "Describe key: "))))
4405             (setq unread-command-events
4406                   (mapcar
4407                    (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4408                    (string-to-list key)))
4409             (setq key (read-key-sequence "Describe key: "))))
4410         (describe-key-briefly key insert))
4411     (describe-key-briefly key insert)))
4412
4413 (defun gnus-article-hide (&optional arg force)
4414   "Hide all the gruft in the current article.
4415 This means that PGP stuff, signatures, cited text and (some)
4416 headers will be hidden.
4417 If given a prefix, show the hidden text instead."
4418   (interactive (append (gnus-article-hidden-arg) (list 'force)))
4419   (gnus-article-hide-headers arg)
4420   (gnus-article-hide-list-identifiers arg)
4421   (gnus-article-hide-pgp arg)
4422   (gnus-article-hide-citation-maybe arg force)
4423   (gnus-article-hide-signature arg))
4424
4425 (defun gnus-article-maybe-highlight ()
4426   "Do some article highlighting if article highlighting is requested."
4427   (when (gnus-visual-p 'article-highlight 'highlight)
4428     (gnus-article-highlight-some)))
4429
4430 (defun gnus-check-group-server ()
4431   ;; Make sure the connection to the server is alive.
4432   (unless (gnus-server-opened
4433            (gnus-find-method-for-group gnus-newsgroup-name))
4434     (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4435     (gnus-request-group gnus-newsgroup-name t)))
4436
4437 (defun gnus-request-article-this-buffer (article group)
4438   "Get an article and insert it into this buffer."
4439   (let (do-update-line sparse-header)
4440     (prog1
4441         (save-excursion
4442           (erase-buffer)
4443           (gnus-kill-all-overlays)
4444           (setq group (or group gnus-newsgroup-name))
4445
4446           ;; Using `gnus-request-article' directly will insert the article into
4447           ;; `nntp-server-buffer' - so we'll save some time by not having to
4448           ;; copy it from the server buffer into the article buffer.
4449
4450           ;; We only request an article by message-id when we do not have the
4451           ;; headers for it, so we'll have to get those.
4452           (when (stringp article)
4453             (gnus-read-header article))
4454
4455           ;; If the article number is negative, that means that this article
4456           ;; doesn't belong in this newsgroup (possibly), so we find its
4457           ;; message-id and request it by id instead of number.
4458           (when (and (numberp article)
4459                      gnus-summary-buffer
4460                      (get-buffer gnus-summary-buffer)
4461                      (gnus-buffer-exists-p gnus-summary-buffer))
4462             (save-excursion
4463               (set-buffer gnus-summary-buffer)
4464               (let ((header (gnus-summary-article-header article)))
4465                 (when (< article 0)
4466                   (cond
4467                    ((memq article gnus-newsgroup-sparse)
4468                     ;; This is a sparse gap article.
4469                     (setq do-update-line article)
4470                     (setq article (mail-header-id header))
4471                     (setq sparse-header (gnus-read-header article))
4472                     (setq gnus-newsgroup-sparse
4473                           (delq article gnus-newsgroup-sparse)))
4474                    ((vectorp header)
4475                     ;; It's a real article.
4476                     (setq article (mail-header-id header)))
4477                    (t
4478                     ;; It is an extracted pseudo-article.
4479                     (setq article 'pseudo)
4480                     (gnus-request-pseudo-article header))))
4481
4482                 (let ((method (gnus-find-method-for-group
4483                                gnus-newsgroup-name)))
4484                   (when (and (eq (car method) 'nneething)
4485                              (vectorp header))
4486                     (let ((dir (expand-file-name
4487                                 (mail-header-subject header)
4488                                 (file-name-as-directory
4489                                  (or (cadr (assq 'nneething-address method))
4490                                      (nth 1 method))))))
4491                       (when (file-directory-p dir)
4492                         (setq article 'nneething)
4493                         (gnus-group-enter-directory dir))))))))
4494
4495           (cond
4496            ;; Refuse to select canceled articles.
4497            ((and (numberp article)
4498                  gnus-summary-buffer
4499                  (get-buffer gnus-summary-buffer)
4500                  (gnus-buffer-exists-p gnus-summary-buffer)
4501                  (eq (cdr (save-excursion
4502                             (set-buffer gnus-summary-buffer)
4503                             (assq article gnus-newsgroup-reads)))
4504                      gnus-canceled-mark))
4505             nil)
4506            ;; We first check `gnus-original-article-buffer'.
4507            ((and (get-buffer gnus-original-article-buffer)
4508                  (numberp article)
4509                  (save-excursion
4510                    (set-buffer gnus-original-article-buffer)
4511                    (and (equal (car gnus-original-article) group)
4512                         (eq (cdr gnus-original-article) article))))
4513             (insert-buffer-substring gnus-original-article-buffer)
4514             'article)
4515            ;; Check the backlog.
4516            ((and gnus-keep-backlog
4517                  (gnus-backlog-request-article group article (current-buffer)))
4518             'article)
4519            ;; Check asynchronous pre-fetch.
4520            ((gnus-async-request-fetched-article group article (current-buffer))
4521             (gnus-async-prefetch-next group article gnus-summary-buffer)
4522             (when (and (numberp article) gnus-keep-backlog)
4523               (gnus-backlog-enter-article group article (current-buffer)))
4524             'article)
4525            ;; Check the cache.
4526            ((and gnus-use-cache
4527                  (numberp article)
4528                  (gnus-cache-request-article article group))
4529             'article)
4530            ;; Get the article and put into the article buffer.
4531            ((or (stringp article)
4532                 (numberp article))
4533             (let ((gnus-override-method gnus-override-method)
4534                   (methods (and (stringp article)
4535                                 gnus-refer-article-method))
4536                   result
4537                   (buffer-read-only nil))
4538               (if (or (not (listp methods))
4539                       (and (symbolp (car methods))
4540                            (assq (car methods) nnoo-definition-alist)))
4541                   (setq methods (list methods)))
4542               (when (and (null gnus-override-method)
4543                          methods)
4544                 (setq gnus-override-method (pop methods)))
4545               (while (not result)
4546                 (when (eq gnus-override-method 'current)
4547                   (setq gnus-override-method
4548                         (with-current-buffer gnus-summary-buffer
4549                           gnus-current-select-method)))
4550                 (erase-buffer)
4551                 (gnus-kill-all-overlays)
4552                 (let ((gnus-newsgroup-name group))
4553                   (gnus-check-group-server))
4554                 (when (gnus-request-article article group (current-buffer))
4555                   (when (numberp article)
4556                     (gnus-async-prefetch-next group article
4557                                               gnus-summary-buffer)
4558                     (when gnus-keep-backlog
4559                       (gnus-backlog-enter-article
4560                        group article (current-buffer))))
4561                   (setq result 'article))
4562                 (if (not result)
4563                     (if methods
4564                         (setq gnus-override-method (pop methods))
4565                       (setq result 'done))))
4566               (and (eq result 'article) 'article)))
4567            ;; It was a pseudo.
4568            (t article)))
4569
4570       ;; Associate this article with the current summary buffer.
4571       (setq gnus-article-current-summary gnus-summary-buffer)
4572
4573       ;; Take the article from the original article buffer
4574       ;; and place it in the buffer it's supposed to be in.
4575       (when (and (get-buffer gnus-article-buffer)
4576                  (equal (buffer-name (current-buffer))
4577                         (buffer-name (get-buffer gnus-article-buffer))))
4578         (save-excursion
4579           (if (get-buffer gnus-original-article-buffer)
4580               (set-buffer gnus-original-article-buffer)
4581             (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4582             (buffer-disable-undo)
4583             (setq major-mode 'gnus-original-article-mode)
4584             (setq buffer-read-only t))
4585           (let (buffer-read-only)
4586             (erase-buffer)
4587             (insert-buffer-substring gnus-article-buffer))
4588           (setq gnus-original-article (cons group article)))
4589
4590         ;; Decode charsets.
4591         (run-hooks 'gnus-article-decode-hook)
4592         ;; Mark article as decoded or not.
4593         (setq gnus-article-decoded-p gnus-article-decode-hook))
4594
4595       ;; Update sparse articles.
4596       (when (and do-update-line
4597                  (or (numberp article)
4598                      (stringp article)))
4599         (let ((buf (current-buffer)))
4600           (set-buffer gnus-summary-buffer)
4601           (gnus-summary-update-article do-update-line sparse-header)
4602           (gnus-summary-goto-subject do-update-line nil t)
4603           (set-window-point (get-buffer-window (current-buffer) t)
4604                             (point))
4605           (set-buffer buf))))))
4606
4607 ;;;
4608 ;;; Article editing
4609 ;;;
4610
4611 (defcustom gnus-article-edit-mode-hook nil
4612   "Hook run in article edit mode buffers."
4613   :group 'gnus-article-various
4614   :type 'hook)
4615
4616 (defvar gnus-article-edit-done-function nil)
4617
4618 (defvar gnus-article-edit-mode-map nil)
4619
4620 ;; Should we be using derived.el for this?
4621 (unless gnus-article-edit-mode-map
4622   (setq gnus-article-edit-mode-map (make-sparse-keymap))
4623   (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4624
4625   (gnus-define-keys gnus-article-edit-mode-map
4626     "\C-c\C-c" gnus-article-edit-done
4627     "\C-c\C-k" gnus-article-edit-exit)
4628
4629   (gnus-define-keys (gnus-article-edit-wash-map
4630                      "\C-c\C-w" gnus-article-edit-mode-map)
4631     "f" gnus-article-edit-full-stops))
4632
4633 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
4634   "Major mode for editing articles.
4635 This is an extended text-mode.
4636
4637 \\{gnus-article-edit-mode-map}"
4638   (make-local-variable 'gnus-article-edit-done-function)
4639   (make-local-variable 'gnus-prev-winconf)
4640   (set (make-local-variable 'font-lock-defaults)
4641        '(message-font-lock-keywords t))
4642   (setq buffer-read-only nil)
4643   (buffer-enable-undo)
4644   (widen))
4645
4646 (defun gnus-article-edit (&optional force)
4647   "Edit the current article.
4648 This will have permanent effect only in mail groups.
4649 If FORCE is non-nil, allow editing of articles even in read-only
4650 groups."
4651   (interactive "P")
4652   (when (and (not force)
4653              (gnus-group-read-only-p))
4654     (error "The current newsgroup does not support article editing"))
4655   (gnus-article-date-original)
4656   (gnus-article-edit-article
4657    'ignore
4658    `(lambda (no-highlight)
4659       'ignore
4660       (gnus-summary-edit-article-done
4661        ,(or (mail-header-references gnus-current-headers) "")
4662        ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4663
4664 (defun gnus-article-edit-article (start-func exit-func)
4665   "Start editing the contents of the current article buffer."
4666   (let ((winconf (current-window-configuration)))
4667     (set-buffer gnus-article-buffer)
4668     (gnus-article-edit-mode)
4669     (funcall start-func)
4670     (set-buffer-modified-p nil)
4671     (gnus-configure-windows 'edit-article)
4672     (setq gnus-article-edit-done-function exit-func)
4673     (setq gnus-prev-winconf winconf)
4674     (gnus-message 6 "C-c C-c to end edits")))
4675
4676 (defun gnus-article-edit-done (&optional arg)
4677   "Update the article edits and exit."
4678   (interactive "P")
4679   (let ((func gnus-article-edit-done-function)
4680         (buf (current-buffer))
4681         (start (window-start)))
4682     ;; We remove all text props from the article buffer.
4683     (let ((content
4684            (buffer-substring-no-properties (point-min) (point-max)))
4685           (p (point)))
4686       (erase-buffer)
4687       (insert content)
4688       (let ((winconf gnus-prev-winconf))
4689         (gnus-article-mode)
4690         (set-window-configuration winconf)
4691         ;; Tippy-toe some to make sure that point remains where it was.
4692         (save-current-buffer
4693           (set-buffer buf)
4694           (set-window-start (get-buffer-window (current-buffer)) start)
4695           (goto-char p))))
4696     (save-excursion
4697       (set-buffer buf)
4698       (let ((buffer-read-only nil))
4699         (funcall func arg))
4700       ;; The cache and backlog have to be flushed somewhat.
4701       (when gnus-keep-backlog
4702         (gnus-backlog-remove-article
4703          (car gnus-article-current) (cdr gnus-article-current)))
4704       ;; Flush original article as well.
4705       (save-excursion
4706         (when (get-buffer gnus-original-article-buffer)
4707           (set-buffer gnus-original-article-buffer)
4708           (setq gnus-original-article nil)))
4709       (when gnus-use-cache
4710         (gnus-cache-update-article
4711          (car gnus-article-current) (cdr gnus-article-current))))
4712     (set-buffer buf)
4713     (set-window-start (get-buffer-window buf) start)
4714     (set-window-point (get-buffer-window buf) (point))))
4715
4716 (defun gnus-article-edit-exit ()
4717   "Exit the article editing without updating."
4718   (interactive)
4719   (when (or (not (buffer-modified-p))
4720             (yes-or-no-p "Article modified; kill anyway? "))
4721     (let ((curbuf (current-buffer))
4722           (p (point))
4723           (window-start (window-start)))
4724       (erase-buffer)
4725       (if (gnus-buffer-live-p gnus-original-article-buffer)
4726           (insert-buffer gnus-original-article-buffer))
4727       (let ((winconf gnus-prev-winconf))
4728         (gnus-article-mode)
4729         (set-window-configuration winconf)
4730         ;; Tippy-toe some to make sure that point remains where it was.
4731         (save-current-buffer
4732           (set-buffer curbuf)
4733           (set-window-start (get-buffer-window (current-buffer)) window-start)
4734           (goto-char p))))))
4735
4736 (defun gnus-article-edit-full-stops ()
4737   "Interactively repair spacing at end of sentences."
4738   (interactive)
4739   (save-excursion
4740     (goto-char (point-min))
4741     (search-forward-regexp "^$" nil t)
4742     (let ((case-fold-search nil))
4743       (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4744
4745 ;;;
4746 ;;; Article highlights
4747 ;;;
4748
4749 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4750
4751 ;;; Internal Variables:
4752
4753 (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\\)\\)"
4754   "Regular expression that matches URLs."
4755   :group 'gnus-article-buttons
4756   :type 'regexp)
4757
4758 (defcustom gnus-button-alist
4759   `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4760      0 t gnus-button-handle-news 3)
4761     ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
4762      gnus-button-handle-news 2)
4763     ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4764      1 t
4765      gnus-button-fetch-group 4)
4766     ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4767     ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4768      t gnus-button-message-id 3)
4769     ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4770     ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
4771     ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4772     ;; This is info
4773     ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
4774      gnus-button-handle-info 2)
4775     ;; This is how URLs _should_ be embedded in text...
4776     ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4777     ;; Raw URLs.
4778     (,gnus-button-url-regexp 0 t browse-url 0))
4779   "*Alist of regexps matching buttons in article bodies.
4780
4781 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4782 REGEXP: is the string matching text around the button,
4783 BUTTON: is the number of the regexp grouping actually matching the button,
4784 FORM: is a lisp expression which must eval to true for the button to
4785 be added,
4786 CALLBACK: is the function to call when the user push this button, and each
4787 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4788
4789 CALLBACK can also be a variable, in that case the value of that
4790 variable it the real callback function."
4791   :group 'gnus-article-buttons
4792   :type '(repeat (list regexp
4793                        (integer :tag "Button")
4794                        (sexp :tag "Form")
4795                        (function :tag "Callback")
4796                        (repeat :tag "Par"
4797                                :inline t
4798                                (integer :tag "Regexp group")))))
4799
4800 (defcustom gnus-header-button-alist
4801   `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
4802      0 t gnus-button-message-id 0)
4803     ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4804     ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4805      0 t gnus-button-mailto 0)
4806     ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4807     ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4808     ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4809     ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4810      gnus-button-message-id 3))
4811   "*Alist of headers and regexps to match buttons in article heads.
4812
4813 This alist is very similar to `gnus-button-alist', except that each
4814 alist has an additional HEADER element first in each entry:
4815
4816 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4817
4818 HEADER is a regexp to match a header.  For a fuller explanation, see
4819 `gnus-button-alist'."
4820   :group 'gnus-article-buttons
4821   :group 'gnus-article-headers
4822   :type '(repeat (list (regexp :tag "Header")
4823                        regexp
4824                        (integer :tag "Button")
4825                        (sexp :tag "Form")
4826                        (function :tag "Callback")
4827                        (repeat :tag "Par"
4828                                :inline t
4829                                (integer :tag "Regexp group")))))
4830
4831 (defvar gnus-button-regexp nil)
4832 (defvar gnus-button-marker-list nil)
4833 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4834
4835 (defvar gnus-button-last nil)
4836 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4837
4838 ;;; Commands:
4839
4840 (defun gnus-article-push-button (event)
4841   "Check text under the mouse pointer for a callback function.
4842 If the text under the mouse pointer has a `gnus-callback' property,
4843 call it with the value of the `gnus-data' text property."
4844   (interactive "e")
4845   (set-buffer (window-buffer (posn-window (event-start event))))
4846   (let* ((pos (posn-point (event-start event)))
4847          (data (get-text-property pos 'gnus-data))
4848          (fun (get-text-property pos 'gnus-callback)))
4849     (goto-char pos)
4850     (when fun
4851       (funcall fun data))))
4852
4853 (defun gnus-article-press-button ()
4854   "Check text at point for a callback function.
4855 If the text at point has a `gnus-callback' property,
4856 call it with the value of the `gnus-data' text property."
4857   (interactive)
4858   (let* ((data (get-text-property (point) 'gnus-data))
4859          (fun (get-text-property (point) 'gnus-callback)))
4860     (when fun
4861       (funcall fun data))))
4862
4863 (defun gnus-article-highlight (&optional force)
4864   "Highlight current article.
4865 This function calls `gnus-article-highlight-headers',
4866 `gnus-article-highlight-citation',
4867 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4868 do the highlighting.  See the documentation for those functions."
4869   (interactive (list 'force))
4870   (gnus-article-highlight-headers)
4871   (gnus-article-highlight-citation force)
4872   (gnus-article-highlight-signature)
4873   (gnus-article-add-buttons force)
4874   (gnus-article-add-buttons-to-head))
4875
4876 (defun gnus-article-highlight-some (&optional force)
4877   "Highlight current article.
4878 This function calls `gnus-article-highlight-headers',
4879 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4880 do the highlighting.  See the documentation for those functions."
4881   (interactive (list 'force))
4882   (gnus-article-highlight-headers)
4883   (gnus-article-highlight-signature)
4884   (gnus-article-add-buttons))
4885
4886 (defun gnus-article-highlight-headers ()
4887   "Highlight article headers as specified by `gnus-header-face-alist'."
4888   (interactive)
4889   (save-excursion
4890     (set-buffer gnus-article-buffer)
4891     (save-restriction
4892       (let ((alist gnus-header-face-alist)
4893             (buffer-read-only nil)
4894             (case-fold-search t)
4895             (inhibit-point-motion-hooks t)
4896             entry regexp header-face field-face from hpoints fpoints)
4897         (article-narrow-to-head)
4898         (while (setq entry (pop alist))
4899           (goto-char (point-min))
4900           (setq regexp (concat "^\\("
4901                                (if (string-equal "" (nth 0 entry))
4902                                    "[^\t ]"
4903                                  (nth 0 entry))
4904                                "\\)")
4905                 header-face (nth 1 entry)
4906                 field-face (nth 2 entry))
4907           (while (and (re-search-forward regexp nil t)
4908                       (not (eobp)))
4909             (beginning-of-line)
4910             (setq from (point))
4911             (unless (search-forward ":" nil t)
4912               (forward-char 1))
4913             (when (and header-face
4914                        (not (memq (point) hpoints)))
4915               (push (point) hpoints)
4916               (gnus-put-text-property from (point) 'face header-face))
4917             (when (and field-face
4918                        (not (memq (setq from (point)) fpoints)))
4919               (push from fpoints)
4920               (if (re-search-forward "^[^ \t]" nil t)
4921                   (forward-char -2)
4922                 (goto-char (point-max)))
4923               (gnus-put-text-property from (point) 'face field-face))))))))
4924
4925 (defun gnus-article-highlight-signature ()
4926   "Highlight the signature in an article.
4927 It does this by highlighting everything after
4928 `gnus-signature-separator' using `gnus-signature-face'."
4929   (interactive)
4930   (save-excursion
4931     (set-buffer gnus-article-buffer)
4932     (let ((buffer-read-only nil)
4933           (inhibit-point-motion-hooks t))
4934       (save-restriction
4935         (when (and gnus-signature-face
4936                    (gnus-article-narrow-to-signature))
4937           (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4938                             'face gnus-signature-face)
4939           (widen)
4940           (gnus-article-search-signature)
4941           (let ((start (match-beginning 0))
4942                 (end (set-marker (make-marker) (1+ (match-end 0)))))
4943             (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4944                                      end)))))))
4945
4946 (defun gnus-button-in-region-p (b e prop)
4947   "Say whether PROP exists in the region."
4948   (text-property-not-all b e prop nil))
4949
4950 (defun gnus-article-add-buttons (&optional force)
4951   "Find external references in the article and make buttons of them.
4952 \"External references\" are things like Message-IDs and URLs, as
4953 specified by `gnus-button-alist'."
4954   (interactive (list 'force))
4955   (save-excursion
4956     (set-buffer gnus-article-buffer)
4957     (let ((buffer-read-only nil)
4958           (inhibit-point-motion-hooks t)
4959           (case-fold-search t)
4960           (alist gnus-button-alist)
4961           beg entry regexp)
4962       ;; Remove all old markers.
4963       (let (marker entry new-list)
4964         (while (setq marker (pop gnus-button-marker-list))
4965           (if (or (< marker (point-min)) (>= marker (point-max)))
4966               (push marker new-list)
4967             (goto-char marker)
4968             (when (setq entry (gnus-button-entry))
4969               (put-text-property (match-beginning (nth 1 entry))
4970                                  (match-end (nth 1 entry))
4971                                  'gnus-callback nil))
4972             (set-marker marker nil)))
4973         (setq gnus-button-marker-list new-list))
4974       ;; We skip the headers.
4975       (article-goto-body)
4976       (setq beg (point))
4977       (while (setq entry (pop alist))
4978         (setq regexp (car entry))
4979         (goto-char beg)
4980         (while (re-search-forward regexp nil t)
4981           (let* ((start (and entry (match-beginning (nth 1 entry))))
4982                  (end (and entry (match-end (nth 1 entry))))
4983                  (from (match-beginning 0)))
4984             (when (and (or (eq t (nth 2 entry))
4985                            (eval (nth 2 entry)))
4986                        (not (gnus-button-in-region-p
4987                              start end 'gnus-callback)))
4988               ;; That optional form returned non-nil, so we add the
4989               ;; button.
4990               (gnus-article-add-button
4991                start end 'gnus-button-push
4992                (car (push (set-marker (make-marker) from)
4993                           gnus-button-marker-list))))))))))
4994
4995 ;; Add buttons to the head of an article.
4996 (defun gnus-article-add-buttons-to-head ()
4997   "Add buttons to the head of the article."
4998   (interactive)
4999   (save-excursion
5000     (set-buffer gnus-article-buffer)
5001     (save-restriction
5002       (let ((buffer-read-only nil)
5003             (inhibit-point-motion-hooks t)
5004             (case-fold-search t)
5005             (alist gnus-header-button-alist)
5006             entry beg end)
5007         (article-narrow-to-head)
5008         (while alist
5009           ;; Each alist entry.
5010           (setq entry (car alist)
5011                 alist (cdr alist))
5012           (goto-char (point-min))
5013           (while (re-search-forward (car entry) nil t)
5014             ;; Each header matching the entry.
5015             (setq beg (match-beginning 0))
5016             (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5017                                (match-beginning 0))
5018                           (point-max)))
5019             (goto-char beg)
5020             (while (re-search-forward (nth 1 entry) end t)
5021               ;; Each match within a header.
5022               (let* ((entry (cdr entry))
5023                      (start (match-beginning (nth 1 entry)))
5024                      (end (match-end (nth 1 entry)))
5025                      (form (nth 2 entry)))
5026                 (goto-char (match-end 0))
5027                 (when (eval form)
5028                   (gnus-article-add-button
5029                    start end (nth 3 entry)
5030                    (buffer-substring (match-beginning (nth 4 entry))
5031                                      (match-end (nth 4 entry)))))))
5032             (goto-char end)))))))
5033
5034 ;;; External functions:
5035
5036 (defun gnus-article-add-button (from to fun &optional data)
5037   "Create a button between FROM and TO with callback FUN and data DATA."
5038   (when gnus-article-button-face
5039     (gnus-overlay-put (gnus-make-overlay from to)
5040                       'face gnus-article-button-face))
5041   (gnus-add-text-properties
5042    from to
5043    (nconc (and gnus-article-mouse-face
5044                (list gnus-mouse-face-prop gnus-article-mouse-face))
5045           (list 'gnus-callback fun)
5046           (and data (list 'gnus-data data))))
5047   (widget-convert-button 'link from to :action 'gnus-widget-press-button
5048                          :button-keymap gnus-widget-button-keymap))
5049
5050 ;;; Internal functions:
5051
5052 (defun gnus-article-set-globals ()
5053   (save-excursion
5054     (set-buffer gnus-summary-buffer)
5055     (gnus-set-global-variables)))
5056
5057 (defun gnus-signature-toggle (end)
5058   (save-excursion
5059     (set-buffer gnus-article-buffer)
5060     (let ((buffer-read-only nil)
5061           (inhibit-point-motion-hooks t))
5062       (if (text-property-any end (point-max) 'article-type 'signature)
5063           (progn
5064             (setq gnus-article-wash-types
5065                   (delq 'signature gnus-article-wash-types))
5066             (gnus-remove-text-properties-when
5067              'article-type 'signature end (point-max)
5068              (cons 'article-type (cons 'signature
5069                                        gnus-hidden-properties))))
5070         (or (memq 'signature gnus-article-wash-types)
5071             (push 'signature gnus-article-wash-types))
5072         (gnus-add-text-properties-when
5073          'article-type nil end (point-max)
5074          (cons 'article-type (cons 'signature
5075                                    gnus-hidden-properties)))))
5076     (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5077       (gnus-set-mode-line 'article))))
5078
5079 (defun gnus-button-entry ()
5080   ;; Return the first entry in `gnus-button-alist' matching this place.
5081   (let ((alist gnus-button-alist)
5082         (entry nil))
5083     (while alist
5084       (setq entry (pop alist))
5085       (if (looking-at (car entry))
5086           (setq alist nil)
5087         (setq entry nil)))
5088     entry))
5089
5090 (defun gnus-button-push (marker)
5091   ;; Push button starting at MARKER.
5092   (save-excursion
5093     (goto-char marker)
5094     (let* ((entry (gnus-button-entry))
5095            (inhibit-point-motion-hooks t)
5096            (fun (nth 3 entry))
5097            (args (mapcar (lambda (group)
5098                            (let ((string (match-string group)))
5099                              (gnus-set-text-properties
5100                               0 (length string) nil string)
5101                              string))
5102                          (nthcdr 4 entry))))
5103       (cond
5104        ((fboundp fun)
5105         (apply fun args))
5106        ((and (boundp fun)
5107              (fboundp (symbol-value fun)))
5108         (apply (symbol-value fun) args))
5109        (t
5110         (gnus-message 1 "You must define `%S' to use this button"
5111                       (cons fun args)))))))
5112
5113 (defun gnus-parse-news-url (url)
5114   (let (scheme server group message-id articles)
5115     (with-temp-buffer
5116       (insert url)
5117       (goto-char (point-min))
5118       (when (looking-at "\\([A-Za-z]+\\):")
5119         (setq scheme (match-string 1))
5120         (goto-char (match-end 0)))
5121       (when (looking-at "//\\([^/]+\\)/")
5122         (setq server (match-string 1))
5123         (goto-char (match-end 0)))
5124
5125       (cond
5126        ((looking-at "\\(.*@.*\\)")
5127         (setq message-id (match-string 1)))
5128        ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
5129         (setq group (match-string 1)
5130               articles (split-string (match-string 2) "-")))
5131        ((looking-at "\\([^/]+\\)/?")
5132         (setq group (match-string 1)))
5133        (t
5134         (error "Unknown news URL syntax"))))
5135     (list scheme server group message-id articles)))
5136
5137 (defun gnus-button-handle-news (url)
5138   "Fetch a news URL."
5139   (destructuring-bind (scheme server group message-id articles)
5140       (gnus-parse-news-url url)
5141     (cond
5142      (message-id
5143       (save-excursion
5144         (set-buffer gnus-summary-buffer)
5145         (if server
5146             (let ((gnus-refer-article-method (list (list 'nntp server))))
5147               (gnus-summary-refer-article message-id))
5148           (gnus-summary-refer-article message-id))))
5149      (group
5150       (gnus-button-fetch-group url)))))
5151
5152 (defun gnus-button-handle-info (url)
5153   "Fetch an info URL."
5154   (if (string-match 
5155        "^\\([^:/]+\\)?/\\(.*\\)"
5156        url)
5157       (gnus-info-find-node
5158        (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
5159                        "Gnus") 
5160                ")" 
5161                (gnus-url-unhex-string (match-string 2 url))))
5162     (error "Can't parse %s" url)))
5163
5164 (defun gnus-button-message-id (message-id)
5165   "Fetch MESSAGE-ID."
5166   (save-excursion
5167     (set-buffer gnus-summary-buffer)
5168     (gnus-summary-refer-article message-id)))
5169
5170 (defun gnus-button-fetch-group (address)
5171   "Fetch GROUP specified by ADDRESS."
5172   (if (not (string-match "[:/]" address))
5173       ;; This is just a simple group url.
5174       (gnus-group-read-ephemeral-group address gnus-select-method)
5175     (if (not 
5176          (string-match 
5177           "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
5178           address))
5179         (error "Can't parse %s" address)
5180       (gnus-group-read-ephemeral-group
5181        (match-string 4 address)
5182        `(nntp ,(match-string 1 address)
5183               (nntp-address ,(match-string 1 address))
5184               (nntp-port-number ,(if (match-end 3)
5185                                      (match-string 3 address)
5186                                    "nntp")))
5187        nil nil nil
5188        (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
5189
5190 (defun gnus-url-parse-query-string (query &optional downcase)
5191   (let (retval pairs cur key val)
5192     (setq pairs (split-string query "&"))
5193     (while pairs
5194       (setq cur (car pairs)
5195             pairs (cdr pairs))
5196       (if (not (string-match "=" cur))
5197           nil                           ; Grace
5198         (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5199               val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5200         (if downcase
5201             (setq key (downcase key)))
5202         (setq cur (assoc key retval))
5203         (if cur
5204             (setcdr cur (cons val (cdr cur)))
5205           (setq retval (cons (list key val) retval)))))
5206     retval))
5207
5208 (defun gnus-url-unhex (x)
5209   (if (> x ?9)
5210       (if (>= x ?a)
5211           (+ 10 (- x ?a))
5212         (+ 10 (- x ?A)))
5213     (- x ?0)))
5214
5215 (defun gnus-url-unhex-string (str &optional allow-newlines)
5216   "Remove %XXX embedded spaces, etc in a url.
5217 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5218 decoding of carriage returns and line feeds in the string, which is normally
5219 forbidden in URL encoding."
5220   (setq str (or (mm-subst-char-in-string ?+ ?  str) ""))
5221   (let ((tmp "")
5222         (case-fold-search t))
5223     (while (string-match "%[0-9a-f][0-9a-f]" str)
5224       (let* ((start (match-beginning 0))
5225              (ch1 (gnus-url-unhex (elt str (+ start 1))))
5226              (code (+ (* 16 ch1)
5227                       (gnus-url-unhex (elt str (+ start 2))))))
5228         (setq tmp (concat
5229                    tmp (substring str 0 start)
5230                    (cond
5231                     (allow-newlines
5232                      (char-to-string code))
5233                     ((or (= code ?\n) (= code ?\r))
5234                      " ")
5235                     (t (char-to-string code))))
5236               str (substring str (match-end 0)))))
5237     (setq tmp (concat tmp str))
5238     tmp))
5239
5240 (defun gnus-url-mailto (url)
5241   ;; Send mail to someone
5242   (when (string-match "mailto:/*\\(.*\\)" url)
5243     (setq url (substring url (match-beginning 1) nil)))
5244   (let (to args subject func)
5245     (if (string-match (regexp-quote "?") url)
5246         (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5247               args (gnus-url-parse-query-string
5248                     (substring url (match-end 0) nil) t))
5249       (setq to (gnus-url-unhex-string url)))
5250     (setq args (cons (list "to" to) args)
5251           subject (cdr-safe (assoc "subject" args)))
5252     (gnus-msg-mail)
5253     (while args
5254       (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5255       (if (fboundp func)
5256           (funcall func)
5257         (message-position-on-field (caar args)))
5258       (insert (mapconcat 'identity (cdar args) ", "))
5259       (setq args (cdr args)))
5260     (if subject
5261         (message-goto-body)
5262       (message-goto-subject))))
5263
5264 (defun gnus-button-embedded-url (address)
5265   "Activate ADDRESS with `browse-url'."
5266   (browse-url (gnus-strip-whitespace address)))
5267
5268 ;;; Next/prev buttons in the article buffer.
5269
5270 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5271 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5272
5273 (defvar gnus-prev-page-map nil)
5274 (unless gnus-prev-page-map
5275   (setq gnus-prev-page-map (make-sparse-keymap))
5276   (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5277   (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5278
5279 (defun gnus-insert-prev-page-button ()
5280   (let ((buffer-read-only nil))
5281     (gnus-eval-format
5282      gnus-prev-page-line-format nil
5283      `(gnus-prev t local-map ,gnus-prev-page-map
5284                  gnus-callback gnus-article-button-prev-page
5285                  article-type annotation))))
5286
5287 (defvar gnus-next-page-map nil)
5288 (unless gnus-next-page-map
5289   (setq gnus-next-page-map (make-keymap))
5290   (suppress-keymap gnus-prev-page-map)
5291   (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5292   (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5293
5294 (defun gnus-button-next-page ()
5295   "Go to the next page."
5296   (interactive)
5297   (let ((win (selected-window)))
5298     (select-window (get-buffer-window gnus-article-buffer t))
5299     (gnus-article-next-page)
5300     (select-window win)))
5301
5302 (defun gnus-button-prev-page ()
5303   "Go to the prev page."
5304   (interactive)
5305   (let ((win (selected-window)))
5306     (select-window (get-buffer-window gnus-article-buffer t))
5307     (gnus-article-prev-page)
5308     (select-window win)))
5309
5310 (defun gnus-insert-next-page-button ()
5311   (let ((buffer-read-only nil))
5312     (gnus-eval-format gnus-next-page-line-format nil
5313                       `(gnus-next
5314                         t local-map ,gnus-next-page-map
5315                         gnus-callback gnus-article-button-next-page
5316                         article-type annotation))))
5317
5318 (defun gnus-article-button-next-page (arg)
5319   "Go to the next page."
5320   (interactive "P")
5321   (let ((win (selected-window)))
5322     (select-window (get-buffer-window gnus-article-buffer t))
5323     (gnus-article-next-page)
5324     (select-window win)))
5325
5326 (defun gnus-article-button-prev-page (arg)
5327   "Go to the prev page."
5328   (interactive "P")
5329   (let ((win (selected-window)))
5330     (select-window (get-buffer-window gnus-article-buffer t))
5331     (gnus-article-prev-page)
5332     (select-window win)))
5333
5334 (defvar gnus-decode-header-methods
5335   '(mail-decode-encoded-word-region)
5336   "List of methods used to decode headers.
5337
5338 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
5339 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
5340 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5341 whose names match REGEXP.
5342
5343 For example:
5344 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5345  mail-decode-encoded-word-region
5346  (\"chinese\" . rfc1843-decode-region))
5347 ")
5348
5349 (defvar gnus-decode-header-methods-cache nil)
5350
5351 (defun gnus-multi-decode-header (start end)
5352   "Apply the functions from `gnus-encoded-word-methods' that match."
5353   (unless (and gnus-decode-header-methods-cache
5354                (eq gnus-newsgroup-name
5355                    (car gnus-decode-header-methods-cache)))
5356     (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5357     (mapcar (lambda (x)
5358               (if (symbolp x)
5359                   (nconc gnus-decode-header-methods-cache (list x))
5360                 (if (and gnus-newsgroup-name
5361                          (string-match (car x) gnus-newsgroup-name))
5362                     (nconc gnus-decode-header-methods-cache
5363                            (list (cdr x))))))
5364           gnus-decode-header-methods))
5365   (let ((xlist gnus-decode-header-methods-cache))
5366     (pop xlist)
5367     (save-restriction
5368       (narrow-to-region start end)
5369       (while xlist
5370         (funcall (pop xlist) (point-min) (point-max))))))
5371
5372 ;;;
5373 ;;; Treatment top-level handling.
5374 ;;;
5375
5376 (defun gnus-treat-article (condition &optional part-number total-parts type)
5377   (let ((length (- (point-max) (point-min)))
5378         (alist gnus-treatment-function-alist)
5379         (article-goto-body-goes-to-point-min-p t)
5380         (treated-type
5381          (or (not type)
5382              (catch 'found
5383                (let ((list gnus-article-treat-types))
5384                  (while list
5385                    (when (string-match (pop list) type)
5386                      (throw 'found t)))))))
5387         (highlightp (gnus-visual-p 'article-highlight 'highlight))
5388         val elem)
5389     (gnus-run-hooks 'gnus-part-display-hook)
5390     (while (setq elem (pop alist))
5391       (setq val
5392             (save-excursion
5393               (if (gnus-buffer-live-p gnus-summary-buffer)
5394                   (set-buffer gnus-summary-buffer))
5395               (symbol-value (car elem))))
5396       (when (and (or (consp val)
5397                      treated-type)
5398                  (gnus-treat-predicate val)
5399                  (or (not (get (car elem) 'highlight))
5400                      highlightp))
5401         (save-restriction
5402           (funcall (cadr elem)))))))
5403
5404 ;; Dynamic variables.
5405 (eval-when-compile
5406   (defvar part-number)
5407   (defvar total-parts)
5408   (defvar type)
5409   (defvar condition)
5410   (defvar length))
5411
5412 (defun gnus-treat-predicate (val)
5413   (cond
5414    ((null val)
5415     nil)
5416    ((and (listp val)
5417          (stringp (car val)))
5418     (apply 'gnus-or (mapcar `(lambda (s)
5419                                (string-match s ,(or gnus-newsgroup-name "")))
5420                             val)))
5421    ((listp val)
5422     (let ((pred (pop val)))
5423       (cond
5424        ((eq pred 'or)
5425         (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5426        ((eq pred 'and)
5427         (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5428        ((eq pred 'not)
5429         (not (gnus-treat-predicate (car val))))
5430        ((eq pred 'typep)
5431         (equal (car val) type))
5432        (t
5433         (error "%S is not a valid predicate" pred)))))
5434    (condition
5435     (eq condition val))
5436    ((eq val t)
5437     t)
5438    ((eq val 'head)
5439     nil)
5440    ((eq val 'last)
5441     (eq part-number total-parts))
5442    ((numberp val)
5443     (< length val))
5444    (t
5445     (error "%S is not a valid value" val))))
5446
5447 (defun gnus-article-encrypt-body (protocol &optional n)
5448   "Encrypt the article body."
5449   (interactive
5450    (list
5451     (or gnus-article-encrypt-protocol
5452         (completing-read "Encrypt protocol: "
5453                          gnus-article-encrypt-protocol-alist
5454                          nil t))
5455     current-prefix-arg))
5456   (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5457     (unless func
5458       (error (format "Can't find the encrypt protocol %s" protocol)))
5459     (if (equal gnus-newsgroup-name "nndraft:drafts")
5460         (error "Can't encrypt the article in group nndraft:drafts"))
5461     (if (equal gnus-newsgroup-name "nndraft:queue")
5462         (error "Don't encrypt the article in group nndraft:queue"))
5463     (gnus-summary-iterate n
5464       (save-excursion
5465         (set-buffer gnus-summary-buffer)
5466         (let ((mail-parse-charset gnus-newsgroup-charset)
5467               (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5468               (summary-buffer gnus-summary-buffer)
5469               references point)
5470           (gnus-set-global-variables)
5471           (when (gnus-group-read-only-p)
5472             (error "The current newsgroup does not support article encrypt"))
5473           (gnus-summary-show-article t)
5474           (setq references
5475               (or (mail-header-references gnus-current-headers) ""))
5476           (set-buffer gnus-article-buffer)
5477           (let* ((buffer-read-only nil)
5478                  (headers
5479                   (mapcar (lambda (field)
5480                             (and (save-restriction
5481                                    (message-narrow-to-head)
5482                                    (goto-char (point-min))
5483                                    (search-forward field nil t))
5484                                  (prog2
5485                                      (message-narrow-to-field)
5486                                      (buffer-substring (point-min) (point-max))
5487                                    (delete-region (point-min) (point-max))
5488                                    (widen))))
5489                           '("Content-Type:" "Content-Transfer-Encoding:"
5490                             "Content-Disposition:"))))
5491             (message-narrow-to-head)
5492             (message-remove-header "MIME-Version")
5493             (goto-char (point-max))
5494             (setq point (point))
5495             (insert (apply 'concat headers))
5496             (widen)
5497             (narrow-to-region point (point-max))
5498             (let ((message-options message-options))
5499               (message-options-set 'message-sender user-mail-address)
5500               (message-options-set 'message-recipients user-mail-address)
5501               (message-options-set 'message-sign-encrypt 'not)
5502               (funcall func))
5503             (goto-char (point-min))
5504             (insert "MIME-Version: 1.0\n")
5505             (widen)
5506             (gnus-summary-edit-article-done
5507              references nil summary-buffer t))
5508           (when gnus-keep-backlog
5509             (gnus-backlog-remove-article
5510              (car gnus-article-current) (cdr gnus-article-current)))
5511           (save-excursion
5512             (when (get-buffer gnus-original-article-buffer)
5513               (set-buffer gnus-original-article-buffer)
5514               (setq gnus-original-article nil)))
5515           (when gnus-use-cache
5516             (gnus-cache-update-article
5517              (car gnus-article-current) (cdr gnus-article-current))))))))
5518
5519 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5520   "The following specs can be used:
5521 %t  The security MIME type
5522 %i  Additional info
5523 %d  Details
5524 %D  Details if button is pressed")
5525
5526 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5527   "The following specs can be used:
5528 %t  The security MIME type
5529 %i  Additional info
5530 %d  Details
5531 %D  Details if button is pressed")
5532
5533 (defvar gnus-mime-security-button-line-format-alist
5534   '((?t gnus-tmp-type ?s)
5535     (?i gnus-tmp-info ?s)
5536     (?d gnus-tmp-details ?s)
5537     (?D gnus-tmp-pressed-details ?s)))
5538
5539 (defvar gnus-mime-security-button-map
5540   (let ((map (make-sparse-keymap)))
5541     (unless (>= (string-to-number emacs-version) 21)
5542       (set-keymap-parent map gnus-article-mode-map))
5543     (define-key map gnus-mouse-2 'gnus-article-push-button)
5544     (define-key map "\r" 'gnus-article-press-button)
5545     map))
5546
5547 (defvar gnus-mime-security-details-buffer nil)
5548
5549 (defvar gnus-mime-security-button-pressed nil)
5550
5551 (defvar gnus-mime-security-show-details-inline t
5552   "If non-nil, show details in the article buffer.")
5553
5554 (defun gnus-mime-security-verify-or-decrypt (handle)
5555   (mm-remove-parts (cdr handle))
5556   (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5557         point buffer-read-only)
5558     (if region
5559         (goto-char (car region)))
5560     (save-restriction
5561       (narrow-to-region (point) (point))
5562       (with-current-buffer (mm-handle-multipart-original-buffer handle)
5563         (let* ((mm-verify-option 'known)
5564                (mm-decrypt-option 'known)
5565                (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5566           (unless (eq nparts (cdr handle))
5567             (mm-destroy-parts (cdr handle))
5568             (setcdr handle nparts))))
5569       (setq point (point))
5570       (gnus-mime-display-security handle)
5571       (goto-char (point-max)))
5572     (when region
5573       (delete-region (point) (cdr region))
5574       (set-marker (car region) nil)
5575       (set-marker (cdr region) nil))
5576     (goto-char point)))
5577
5578 (defun gnus-mime-security-show-details (handle)
5579   (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5580     (if details
5581         (if gnus-mime-security-show-details-inline
5582             (let ((gnus-mime-security-button-pressed t)
5583                   (gnus-mime-security-button-line-format
5584                    (get-text-property (point) 'gnus-line-format))
5585                 buffer-read-only)
5586               (forward-char -1)
5587               (while (eq (get-text-property (point) 'gnus-line-format)
5588                          gnus-mime-security-button-line-format)
5589                 (forward-char -1))
5590               (forward-char)
5591               (save-restriction
5592                 (narrow-to-region (point) (point))
5593                 (gnus-insert-mime-security-button handle))
5594               (delete-region (point)
5595                              (or (text-property-not-all
5596                                   (point) (point-max)
5597                                   'gnus-line-format
5598                                   gnus-mime-security-button-line-format)
5599                                  (point-max))))
5600           (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5601               (with-current-buffer gnus-mime-security-details-buffer
5602                 (erase-buffer)
5603                 t)
5604             (setq gnus-mime-security-details-buffer
5605                   (gnus-get-buffer-create "*MIME Security Details*")))
5606           (with-current-buffer gnus-mime-security-details-buffer
5607             (insert details)
5608             (goto-char (point-min)))
5609           (pop-to-buffer gnus-mime-security-details-buffer))
5610       (gnus-message 5 "No details."))))
5611
5612 (defun gnus-mime-security-press-button (handle)
5613   (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5614       (gnus-mime-security-show-details handle)
5615     (gnus-mime-security-verify-or-decrypt handle)))
5616
5617 (defun gnus-insert-mime-security-button (handle &optional displayed)
5618   (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5619          (gnus-tmp-type
5620           (concat
5621            (or (nth 2 (assoc protocol mm-verify-function-alist))
5622                (nth 2 (assoc protocol mm-decrypt-function-alist))
5623                "Unknown")
5624            (if (equal (car handle) "multipart/signed")
5625                " Signed" " Encrypted")
5626            " Part"))
5627          (gnus-tmp-info
5628           (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5629               "Undecided"))
5630          (gnus-tmp-details
5631           (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5632          gnus-tmp-pressed-details
5633          b e)
5634     (setq gnus-tmp-details
5635           (if gnus-tmp-details
5636               (concat "\n" gnus-tmp-details) ""))
5637     (setq gnus-tmp-pressed-details
5638           (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5639     (unless (bolp)
5640       (insert "\n"))
5641     (setq b (point))
5642     (gnus-eval-format
5643      gnus-mime-security-button-line-format
5644      gnus-mime-security-button-line-format-alist
5645      `(keymap ,gnus-mime-security-button-map
5646               ,@(if (>= (string-to-number emacs-version) 21)
5647                     nil ;; XEmacs doesn't care
5648                   (list 'local-map gnus-mime-security-button-map))
5649               gnus-callback gnus-mime-security-press-button
5650               gnus-line-format ,gnus-mime-security-button-line-format
5651               article-type annotation
5652               gnus-data ,handle))
5653     (setq e (point))
5654     (widget-convert-button
5655      'link b e
5656      :mime-handle handle
5657      :action 'gnus-widget-press-button
5658      :button-keymap gnus-mime-security-button-map
5659      :help-echo
5660      (lambda (widget/window &optional overlay pos)
5661        ;; Needed to properly clear the message due to a bug in
5662        ;; wid-edit (XEmacs only).
5663        (if (boundp 'help-echo-owns-message)
5664            (setq help-echo-owns-message t))
5665        (format
5666         "%S: show detail"
5667         (aref gnus-mouse-2 0))))))
5668
5669 (defun gnus-mime-display-security (handle)
5670   (save-restriction
5671     (narrow-to-region (point) (point))
5672     (unless (gnus-unbuttonized-mime-type-p (car handle))
5673       (gnus-insert-mime-security-button handle))
5674     (gnus-mime-display-mixed (cdr handle))
5675     (unless (bolp)
5676       (insert "\n"))
5677     (unless (gnus-unbuttonized-mime-type-p (car handle))
5678       (let ((gnus-mime-security-button-line-format
5679              gnus-mime-security-button-end-line-format))
5680         (gnus-insert-mime-security-button handle)))
5681     (mm-set-handle-multipart-parameter
5682      handle 'gnus-region
5683      (cons (set-marker (make-marker) (point-min))
5684            (set-marker (make-marker) (point-max))))))
5685
5686 (gnus-ems-redefine)
5687
5688 (provide 'gnus-art)
5689
5690 (run-hooks 'gnus-art-load-hook)
5691
5692 ;;; gnus-art.el ends here