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