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