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