1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
41 ;; Avoid byte-compile warnings.
43 (defvar gnus-article-decoded-p)
44 (defvar gnus-article-mime-handles)
53 (defgroup gnus-article nil
55 :link '(custom-manual "(gnus)The Article Buffer")
58 (defgroup gnus-article-hiding nil
59 "Hiding article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
63 (defgroup gnus-article-highlight nil
64 "Article highlighting."
65 :link '(custom-manual "(gnus)Article Highlighting")
69 (defgroup gnus-article-signature nil
71 :link '(custom-manual "(gnus)Article Signature")
74 (defgroup gnus-article-headers nil
76 :link '(custom-manual "(gnus)Hiding Headers")
79 (defgroup gnus-article-washing nil
80 "Special commands on articles."
81 :link '(custom-manual "(gnus)Article Washing")
84 (defgroup gnus-article-emphasis nil
85 "Fontisizing articles."
86 :link '(custom-manual "(gnus)Article Fontisizing")
89 (defgroup gnus-article-saving nil
91 :link '(custom-manual "(gnus)Saving Articles")
94 (defgroup gnus-article-mime nil
95 "Worshiping the MIME wonder."
96 :link '(custom-manual "(gnus)Using MIME")
99 (defgroup gnus-article-buttons nil
100 "Pushable buttons in the article buffer."
101 :link '(custom-manual "(gnus)Article Buttons")
102 :group 'gnus-article)
104 (defgroup gnus-article-various nil
105 "Other article options."
106 :link '(custom-manual "(gnus)Misc Article")
107 :group 'gnus-article)
109 (defcustom gnus-ignored-headers
110 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
111 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
112 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
113 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
114 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
115 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
116 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
117 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
118 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
119 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
120 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
121 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
122 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
123 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
124 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
125 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
126 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
127 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
129 "*All headers that start with this regexp will be hidden.
130 This variable can also be a list of regexps of headers to be ignored.
131 If `gnus-visible-headers' is non-nil, this variable will be ignored."
132 :type '(choice :custom-show nil
135 :group 'gnus-article-hiding)
137 (defcustom gnus-visible-headers
138 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
139 "*All headers that do not match this regexp will be hidden.
140 This variable can also be a list of regexp of headers to remain visible.
141 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
142 :type '(repeat :value-to-internal (lambda (widget value)
143 (custom-split-regexp-maybe value))
144 :match (lambda (widget value)
146 (widget-editable-list-match widget value)))
148 :group 'gnus-article-hiding)
150 (defcustom gnus-sorted-header-list
151 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
152 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
153 "*This variable is a list of regular expressions.
154 If it is non-nil, headers that match the regular expressions will
155 be placed first in the article buffer in the sequence specified by
157 :type '(repeat regexp)
158 :group 'gnus-article-hiding)
160 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
161 "Headers that are only to be displayed if they have interesting data.
162 Possible values in this list are `empty', `newsgroups', `followup-to',
163 `reply-to', `date', `long-to', and `many-to'."
164 :type '(set (const :tag "Headers with no content." empty)
165 (const :tag "Newsgroups with only one group." newsgroups)
166 (const :tag "Followup-to identical to newsgroups." followup-to)
167 (const :tag "Reply-to identical to from." reply-to)
168 (const :tag "Date less than four days old." date)
169 (const :tag "Very long To header." long-to)
170 (const :tag "Multiple To headers." many-to))
171 :group 'gnus-article-hiding)
173 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
174 "Regexp matching signature separator.
175 This can also be a list of regexps. In that case, it will be checked
176 from head to tail looking for a separator. Searches will be done from
177 the end of the buffer."
178 :type '(repeat string)
179 :group 'gnus-article-signature)
181 (defcustom gnus-signature-limit nil
182 "Provide a limit to what is considered a signature.
183 If it is a number, no signature may not be longer (in characters) than
184 that number. If it is a floating point number, no signature may be
185 longer (in lines) than that number. If it is a function, the function
186 will be called without any parameters, and if it returns nil, there is
187 no signature in the buffer. If it is a string, it will be used as a
188 regexp. If it matches, the text in question is not a signature."
189 :type '(choice (integer :value 200)
191 (function :value fun)
192 (regexp :value ".*"))
193 :group 'gnus-article-signature)
195 (defcustom gnus-hidden-properties '(invisible t intangible t)
196 "Property list to use for hiding text."
198 :group 'gnus-article-hiding)
200 (defcustom gnus-article-x-face-command
201 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
202 "*String or function to be executed to display an X-Face header.
203 If it is a string, the command will be executed in a sub-shell
204 asynchronously. The compressed face will be piped to this command."
205 :type 'string ;Leave function case to Lisp.
206 :group 'gnus-article-washing)
208 (defcustom gnus-article-x-face-too-ugly nil
209 "Regexp matching posters whose face shouldn't be shown automatically."
210 :type '(choice regexp (const nil))
211 :group 'gnus-article-washing)
213 (defcustom gnus-emphasis-alist
215 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
217 '(("_" "_" underline)
220 ("_/" "/_" underline-italic)
221 ("_\\*" "\\*_" underline-bold)
222 ("\\*/" "/\\*" bold-italic)
223 ("_\\*/" "/\\*_" underline-bold-italic))))
224 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
225 2 3 gnus-emphasis-underline)
229 (format format (car spec) (cadr spec))
230 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
232 "*Alist that says how to fontify certain phrases.
233 Each item looks like this:
235 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
237 The first element is a regular expression to be matched. The second
238 is a number that says what regular expression grouping used to find
239 the entire emphasized word. The third is a number that says what
240 regexp grouping should be displayed and highlighted. The fourth
241 is the face used for highlighting."
242 :type '(repeat (list :value ("" 0 0 default)
244 (integer :tag "Match group")
245 (integer :tag "Emphasize group")
247 :group 'gnus-article-emphasis)
249 (defface gnus-emphasis-bold '((t (:bold t)))
250 "Face used for displaying strong emphasized text (*word*)."
251 :group 'gnus-article-emphasis)
253 (defface gnus-emphasis-italic '((t (:italic t)))
254 "Face used for displaying italic emphasized text (/word/)."
255 :group 'gnus-article-emphasis)
257 (defface gnus-emphasis-underline '((t (:underline t)))
258 "Face used for displaying underlined emphasized text (_word_)."
259 :group 'gnus-article-emphasis)
261 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
262 "Face used for displaying underlined bold emphasized text (_*word*_)."
263 :group 'gnus-article-emphasis)
265 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
266 "Face used for displaying underlined italic emphasized text (_*word*_)."
267 :group 'gnus-article-emphasis)
269 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
270 "Face used for displaying bold italic emphasized text (/*word*/)."
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-underline-bold-italic
274 '((t (:bold t :italic t :underline t)))
275 "Face used for displaying underlined bold italic emphasized text.
276 Esample: (_/*word*/_)."
277 :group 'gnus-article-emphasis)
279 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
280 "Format for display of Date headers in article bodies.
281 See `format-time-string' for the possible values.
283 The variable can also be function, which should return a complete Date
284 header. The function is called with one argument, the time, which can
285 be fed to `format-time-string'."
286 :type '(choice string symbol)
287 :link '(custom-manual "(gnus)Article Date")
288 :group 'gnus-article-washing)
291 (autoload 'mail-extract-address-components "mail-extr"))
293 (defcustom gnus-save-all-headers t
294 "*If non-nil, don't remove any headers before saving."
295 :group 'gnus-article-saving
298 (defcustom gnus-prompt-before-saving 'always
299 "*This variable says how much prompting is to be done when saving articles.
300 If it is nil, no prompting will be done, and the articles will be
301 saved to the default files. If this variable is `always', each and
302 every article that is saved will be preceded by a prompt, even when
303 saving large batches of articles. If this variable is neither nil not
304 `always', there the user will be prompted once for a file name for
305 each invocation of the saving commands."
306 :group 'gnus-article-saving
307 :type '(choice (item always)
308 (item :tag "never" nil)
309 (sexp :tag "once" :format "%t\n" :value t)))
311 (defcustom gnus-saved-headers gnus-visible-headers
312 "Headers to keep if `gnus-save-all-headers' is nil.
313 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
314 If that variable is nil, however, all headers that match this regexp
315 will be kept while the rest will be deleted before saving."
316 :group 'gnus-article-saving
319 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
320 "A function to save articles in your favourite format.
321 The function must be interactively callable (in other words, it must
322 be an Emacs command).
324 Gnus provides the following functions:
326 * gnus-summary-save-in-rmail (Rmail format)
327 * gnus-summary-save-in-mail (Unix mail format)
328 * gnus-summary-save-in-folder (MH folder)
329 * gnus-summary-save-in-file (article format)
330 * gnus-summary-save-in-vm (use VM's folder format)
331 * gnus-summary-write-to-file (article format -- overwrite)."
332 :group 'gnus-article-saving
333 :type '(radio (function-item gnus-summary-save-in-rmail)
334 (function-item gnus-summary-save-in-mail)
335 (function-item gnus-summary-save-in-folder)
336 (function-item gnus-summary-save-in-file)
337 (function-item gnus-summary-save-in-vm)
338 (function-item gnus-summary-write-to-file)))
340 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
341 "A function generating a file name to save articles in Rmail format.
342 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
343 :group 'gnus-article-saving
346 (defcustom gnus-mail-save-name 'gnus-plain-save-name
347 "A function generating a file name to save articles in Unix mail format.
348 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
349 :group 'gnus-article-saving
352 (defcustom gnus-folder-save-name 'gnus-folder-save-name
353 "A function generating a file name to save articles in MH folder.
354 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
355 :group 'gnus-article-saving
358 (defcustom gnus-file-save-name 'gnus-numeric-save-name
359 "A function generating a file name to save articles in article format.
360 The function is called with NEWSGROUP, HEADERS, and optional
362 :group 'gnus-article-saving
365 (defcustom gnus-split-methods
366 '((gnus-article-archive-name)
367 (gnus-article-nndoc-name))
368 "*Variable used to suggest where articles are to be saved.
369 For instance, if you would like to save articles related to Gnus in
370 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
371 you could set this variable to something like:
373 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
374 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
376 This variable is an alist where the where the key is the match and the
377 value is a list of possible files to save in if the match is non-nil.
379 If the match is a string, it is used as a regexp match on the
380 article. If the match is a symbol, that symbol will be funcalled
381 from the buffer of the article to be saved with the newsgroup as the
382 parameter. If it is a list, it will be evaled in the same buffer.
384 If this form or function returns a string, this string will be used as
385 a possible file name; and if it returns a non-nil list, that list will
386 be used as possible file names."
387 :group 'gnus-article-saving
388 :type '(repeat (choice (list :value (fun) function)
389 (cons :value ("" "") regexp (repeat string))
392 (defcustom gnus-article-display-method-for-mime
393 'gnus-article-display-mime-message
394 "Function to display a MIME message.
395 The function is called from the article buffer."
396 :group 'gnus-article-mime
399 (defcustom gnus-article-display-method-for-traditional
400 'gnus-article-display-traditional-message
401 "*Function to display a traditional message.
402 The function is called from the article buffer."
403 :group 'gnus-article-mime
406 (defcustom gnus-page-delimiter "^\^L"
407 "*Regexp describing what to use as article page delimiters.
408 The default value is \"^\^L\", which is a form linefeed at the
409 beginning of a line."
411 :group 'gnus-article-various)
413 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
414 "*The format specification for the article mode line.
415 See `gnus-summary-mode-line-format' for a closer description."
417 :group 'gnus-article-various)
419 (defcustom gnus-article-mode-hook nil
420 "*A hook for Gnus article mode."
422 :group 'gnus-article-various)
424 (defcustom gnus-article-menu-hook nil
425 "*Hook run after the creation of the article mode menu."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-prepare-hook nil
430 "*A hook called after an article has been prepared in the article buffer.
431 If you want to run a special decoding program like nkf, use this hook."
433 :group 'gnus-article-various)
435 (defcustom gnus-article-hide-pgp-hook nil
436 "*A hook called after successfully hiding a PGP signature."
438 :group 'gnus-article-various)
440 (defcustom gnus-article-button-face 'bold
441 "Face used for highlighting buttons in the article buffer.
443 An article button is a piece of text that you can activate by pressing
444 `RET' or `mouse-2' above it."
446 :group 'gnus-article-buttons)
448 (defcustom gnus-article-mouse-face 'highlight
449 "Face used for mouse highlighting in the article buffer.
451 Article buttons will be displayed in this face when the cursor is
454 :group 'gnus-article-buttons)
456 (defcustom gnus-signature-face 'gnus-signature-face
457 "Face used for highlighting a signature in the article buffer.
458 Obsolete; use the face `gnus-signature-face' for customizations instead."
460 :group 'gnus-article-highlight
461 :group 'gnus-article-signature)
463 (defface gnus-signature-face
466 "Face used for highlighting a signature in the article buffer."
467 :group 'gnus-article-highlight
468 :group 'gnus-article-signature)
470 (defface gnus-header-from-face
473 (:foreground "spring green"))
476 (:foreground "red3"))
479 "Face used for displaying from headers."
480 :group 'gnus-article-headers
481 :group 'gnus-article-highlight)
483 (defface gnus-header-subject-face
486 (:foreground "SeaGreen3"))
489 (:foreground "red4"))
491 (:bold t :italic t)))
492 "Face used for displaying subject headers."
493 :group 'gnus-article-headers
494 :group 'gnus-article-highlight)
496 (defface gnus-header-newsgroups-face
499 (:foreground "yellow" :italic t))
502 (:foreground "MidnightBlue" :italic t))
505 "Face used for displaying newsgroups headers."
506 :group 'gnus-article-headers
507 :group 'gnus-article-highlight)
509 (defface gnus-header-name-face
512 (:foreground "SeaGreen"))
515 (:foreground "maroon"))
518 "Face used for displaying header names."
519 :group 'gnus-article-headers
520 :group 'gnus-article-highlight)
522 (defface gnus-header-content-face
525 (:foreground "forest green" :italic t))
528 (:foreground "indianred4" :italic t))
530 (:italic t))) "Face used for displaying header content."
531 :group 'gnus-article-headers
532 :group 'gnus-article-highlight)
534 (defcustom gnus-header-face-alist
535 '(("From" nil gnus-header-from-face)
536 ("Subject" nil gnus-header-subject-face)
537 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
538 ("" gnus-header-name-face gnus-header-content-face))
539 "*Controls highlighting of article header.
541 An alist of the form (HEADER NAME CONTENT).
543 HEADER is a regular expression which should match the name of an
544 header header and NAME and CONTENT are either face names or nil.
546 The name of each header field will be displayed using the face
547 specified by the first element in the list where HEADER match the
548 header name and NAME is non-nil. Similarly, the content will be
549 displayed by the first non-nil matching CONTENT face."
550 :group 'gnus-article-headers
551 :group 'gnus-article-highlight
552 :type '(repeat (list (regexp :tag "Header")
554 (item :tag "skip" nil)
555 (face :value default))
556 (choice :tag "Content"
557 (item :tag "skip" nil)
558 (face :value default)))))
560 (defcustom gnus-article-decode-hook nil
561 "*Hook run to decode charsets in articles."
562 :group 'gnus-article-headers
565 (defcustom gnus-display-mime-function 'gnus-display-mime
566 "Function to display MIME articles."
567 :group 'gnus-article-headers
570 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
571 "Function used to decode headers.")
573 (defvar gnus-article-dumbquotes-map
592 "Table for MS-to-Latin1 translation.")
594 (defcustom gnus-ignored-mime-types nil
595 "List of MIME types that should be ignored by Gnus."
597 :type '(repeat regexp))
599 (defcustom gnus-treat-body-highlight-signature t
600 "Highlight the signature."
602 :type '(choice (const :tag "Off" nil)
604 (const :tag "Last" last)
605 (integer :tag "Less")
606 (sexp :tag "Predicate")))
608 ;;; Internal variables
610 (defvar gnus-treatment-function-alist
611 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
614 (defvar gnus-article-mime-handle-alist nil)
615 (defvar article-lapsed-timer nil)
616 (defvar gnus-article-current-summary nil)
618 (defvar gnus-article-mode-syntax-table
619 (let ((table (copy-syntax-table text-mode-syntax-table)))
620 (modify-syntax-entry ?- "w" table)
621 (modify-syntax-entry ?> ")" table)
622 (modify-syntax-entry ?< "(" table)
624 "Syntax table used in article mode buffers.
625 Initialized from `text-mode-syntax-table.")
627 (defvar gnus-save-article-buffer nil)
629 (defvar gnus-article-mode-line-format-alist
630 (nconc '((?w (gnus-article-wash-status) ?s))
631 gnus-summary-mode-line-format-alist))
633 (defvar gnus-number-of-articles-to-be-saved nil)
635 (defvar gnus-inhibit-hiding nil)
637 (defsubst gnus-article-hide-text (b e props)
638 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
639 (add-text-properties b e props)
640 (when (memq 'intangible props)
642 (max (1- b) (point-min))
643 b 'intangible (cddr (memq 'intangible props)))))
645 (defsubst gnus-article-unhide-text (b e)
646 "Remove hidden text properties from region between B and E."
647 (remove-text-properties b e gnus-hidden-properties)
648 (when (memq 'intangible gnus-hidden-properties)
649 (put-text-property (max (1- b) (point-min))
652 (defun gnus-article-hide-text-type (b e type)
653 "Hide text of TYPE between B and E."
654 (gnus-article-hide-text
655 b e (cons 'article-type (cons type gnus-hidden-properties))))
657 (defun gnus-article-unhide-text-type (b e type)
658 "Unhide text of TYPE between B and E."
659 (remove-text-properties
660 b e (cons 'article-type (cons type gnus-hidden-properties)))
661 (when (memq 'intangible gnus-hidden-properties)
662 (put-text-property (max (1- b) (point-min))
665 (defun gnus-article-hide-text-of-type (type)
666 "Hide text of TYPE in the current buffer."
668 (let ((b (point-min))
670 (while (setq b (text-property-any b e 'article-type type))
671 (add-text-properties b (incf b) gnus-hidden-properties)))))
673 (defun gnus-article-delete-text-of-type (type)
674 "Delete text of TYPE in the current buffer."
676 (let ((b (point-min)))
677 (while (setq b (text-property-any b (point-max) 'article-type type))
679 b (or (text-property-not-all b (point-max) 'article-type type)
682 (defun gnus-article-delete-invisible-text ()
683 "Delete all invisible text in the current buffer."
685 (let ((b (point-min)))
686 (while (setq b (text-property-any b (point-max) 'invisible t))
688 b (or (text-property-not-all b (point-max) 'invisible t)
691 (defun gnus-article-text-type-exists-p (type)
692 "Say whether any text of type TYPE exists in the buffer."
693 (text-property-any (point-min) (point-max) 'article-type type))
695 (defsubst gnus-article-header-rank ()
696 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
697 (let ((list gnus-sorted-header-list)
700 (when (looking-at (car list))
702 (setq list (cdr list))
706 (defun article-hide-headers (&optional arg delete)
707 "Toggle whether to hide unwanted headers and possibly sort them as well.
708 If given a negative prefix, always show; if given a positive prefix,
710 (interactive (gnus-article-hidden-arg))
712 (if (gnus-article-check-hidden-text 'headers arg)
713 ;; Show boring headers as well.
714 (gnus-article-show-hidden-text 'boring-headers)
715 ;; This function might be inhibited.
716 (unless gnus-inhibit-hiding
719 (let ((buffer-read-only nil)
721 (props (nconc (list 'article-type 'headers)
722 gnus-hidden-properties))
723 (max (1+ (length gnus-sorted-header-list)))
724 (ignored (when (not gnus-visible-headers)
725 (cond ((stringp gnus-ignored-headers)
726 gnus-ignored-headers)
727 ((listp gnus-ignored-headers)
728 (mapconcat 'identity gnus-ignored-headers
731 (cond ((stringp gnus-visible-headers)
732 gnus-visible-headers)
733 ((and gnus-visible-headers
734 (listp gnus-visible-headers))
735 (mapconcat 'identity gnus-visible-headers "\\|"))))
736 (inhibit-point-motion-hooks t)
738 ;; First we narrow to just the headers.
740 (goto-char (point-min))
741 ;; Hide any "From " lines at the beginning of (mail) articles.
742 (while (looking-at "From ")
746 (delete-region (point-min) (point))
747 (gnus-article-hide-text (point-min) (point) props)))
748 ;; Then treat the rest of the header lines.
751 (if (search-forward "\n\n" nil t) ; if there's a body
752 (progn (forward-line -1) (point))
754 ;; Then we use the two regular expressions
755 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
756 ;; select which header lines is to remain visible in the
758 (goto-char (point-min))
759 (while (re-search-forward "^[^ \t]*:" nil t)
761 ;; Mark the rank of the header.
763 (point) (1+ (point)) 'message-rank
764 (if (or (and visible (looking-at visible))
766 (not (looking-at ignored))))
767 (gnus-article-header-rank)
770 (message-sort-headers-1)
771 (when (setq beg (text-property-any
772 (point-min) (point-max) 'message-rank (+ 2 max)))
773 ;; We make the unwanted headers invisible.
775 (delete-region beg (point-max))
776 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
777 (gnus-article-hide-text-type beg (point-max) 'headers))
778 ;; Work around XEmacs lossage.
779 (put-text-property (point-min) beg 'invisible nil))))))))
781 (defun article-hide-boring-headers (&optional arg)
782 "Toggle hiding of headers that aren't very interesting.
783 If given a negative prefix, always show; if given a positive prefix,
785 (interactive (gnus-article-hidden-arg))
786 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
787 (not gnus-show-all-headers))
790 (let ((buffer-read-only nil)
791 (list gnus-boring-article-headers)
792 (inhibit-point-motion-hooks t)
794 (nnheader-narrow-to-headers)
796 (setq elem (pop list))
797 (goto-char (point-min))
799 ;; Hide empty headers.
801 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
803 (gnus-article-hide-text-type
804 (progn (beginning-of-line) (point))
807 (if (re-search-forward "^[^ \t]" nil t)
811 ;; Hide boring Newsgroups header.
812 ((eq elem 'newsgroups)
813 (when (equal (gnus-fetch-field "newsgroups")
814 (gnus-group-real-name
815 (if (boundp 'gnus-newsgroup-name)
818 (gnus-article-hide-header "newsgroups")))
819 ((eq elem 'followup-to)
820 (when (equal (message-fetch-field "followup-to")
821 (message-fetch-field "newsgroups"))
822 (gnus-article-hide-header "followup-to")))
824 (let ((from (message-fetch-field "from"))
825 (reply-to (message-fetch-field "reply-to")))
830 (nth 1 (funcall gnus-extract-address-components from))
831 (nth 1 (funcall gnus-extract-address-components reply-to)))))
832 (gnus-article-hide-header "reply-to"))))
834 (let ((date (message-fetch-field "date")))
836 (< (days-between (current-time-string) date)
838 (gnus-article-hide-header "date"))))
840 (let ((to (message-fetch-field "to")))
841 (when (> (length to) 1024)
842 (gnus-article-hide-header "to"))))
845 (goto-char (point-min))
846 (while (re-search-forward "^to:" nil t)
847 (setq to-count (1+ to-count)))
849 (while (> to-count 0)
850 (goto-char (point-min))
852 (re-search-forward "^to:" nil nil to-count)
854 (narrow-to-region (point) (point-max))
855 (gnus-article-hide-header "to"))
856 (setq to-count (1- to-count)))))))))))))
858 (defun gnus-article-hide-header (header)
860 (goto-char (point-min))
861 (when (re-search-forward (concat "^" header ":") nil t)
862 (gnus-article-hide-text-type
863 (progn (beginning-of-line) (point))
866 (if (re-search-forward "^[^ \t]" nil t)
871 (defun article-treat-dumbquotes ()
872 "Translate M******** sm*rtq**t*s into proper text."
874 (article-translate-strings gnus-article-dumbquotes-map))
876 (defun article-translate-characters (from to)
877 "Translate all characters in the body of the article according to FROM and TO.
878 FROM is a string of characters to translate from; to is a string of
879 characters to translate to."
881 (goto-char (point-min))
882 (when (search-forward "\n\n" nil t)
883 (let ((buffer-read-only nil)
884 (x (make-string 225 ?x))
886 (while (< (incf i) (length x))
889 (while (< i (length from))
890 (aset x (aref from i) (aref to i))
892 (translate-region (point) (point-max) x)))))
894 (defun article-translate-strings (map)
895 "Translate all string in the body of the article according to MAP.
896 MAP is an alist where the elements are on the form (\"from\" \"to\")."
898 (goto-char (point-min))
899 (when (search-forward "\n\n" nil t)
900 (let ((buffer-read-only nil)
902 (while (setq elem (pop map))
904 (while (search-forward (car elem) nil t)
905 (replace-match (cadr elem)))))))))
907 (defun article-treat-overstrike ()
908 "Translate overstrikes into bold text."
911 (goto-char (point-min))
912 (when (search-forward "\n\n" nil t)
913 (let ((buffer-read-only nil))
914 (while (search-forward "\b" nil t)
915 (let ((next (char-after))
916 (previous (char-after (- (point) 2))))
917 ;; We do the boldification/underlining by hiding the
918 ;; overstrikes and putting the proper text property
922 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
923 (put-text-property (point) (1+ (point)) 'face 'bold))
925 (gnus-article-hide-text-type
926 (1- (point)) (1+ (point)) 'overstrike)
928 (- (point) 2) (1- (point)) 'face 'underline))
930 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
932 (point) (1+ (point)) 'face 'underline)))))))))
934 (defun article-fill ()
935 "Format too long lines."
938 (let ((buffer-read-only nil))
940 (goto-char (point-min))
941 (search-forward "\n\n" nil t)
943 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
944 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
945 (adaptive-fill-mode t))
947 (and (>= (current-column) (min fill-column (window-width)))
948 (/= (preceding-char) ?:)
949 (fill-paragraph nil))
952 (defun article-remove-cr ()
953 "Translate CRLF pairs into LF, and then CR into LF.."
956 (let ((buffer-read-only nil))
957 (goto-char (point-min))
958 (while (search-forward "\r$" nil t)
959 (replace-match "" t t))
960 (goto-char (point-min))
961 (while (search-forward "\r" nil t)
962 (replace-match "\n" t t)))))
964 (defun article-remove-trailing-blank-lines ()
965 "Remove all trailing blank lines from the article."
968 (let ((buffer-read-only nil))
969 (goto-char (point-max))
973 (while (and (not (bobp))
974 (looking-at "^[ \t]*$")
975 (not (gnus-annotation-in-region-p
976 (point) (gnus-point-at-eol))))
981 (defun article-display-x-face (&optional force)
982 "Look for an X-Face header and display it if present."
983 (interactive (list 'force))
985 ;; Delete the old process, if any.
986 (when (process-status "article-x-face")
987 (delete-process "article-x-face"))
988 (let ((inhibit-point-motion-hooks t)
992 (nnheader-narrow-to-headers)
993 (setq from (message-fetch-field "from"))
994 (goto-char (point-min))
995 (while (and gnus-article-x-face-command
998 ;; Check whether this face is censored.
999 (not gnus-article-x-face-too-ugly)
1000 (and gnus-article-x-face-too-ugly from
1001 (not (string-match gnus-article-x-face-too-ugly
1003 ;; Has to be present.
1004 (re-search-forward "^X-Face: " nil t))
1005 ;; This used to try to do multiple faces (`while' instead of
1006 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1007 ;; work (b) it can crash some versions of Emacs (c) are
1008 ;; multiple faces really something to encourage?
1009 (when (stringp gnus-article-x-face-command)
1011 ;; We now have the area of the buffer where the X-Face is stored.
1014 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1015 ;; We display the face.
1016 (if (symbolp gnus-article-x-face-command)
1017 ;; The command is a lisp function, so we call it.
1018 (if (gnus-functionp gnus-article-x-face-command)
1019 (funcall gnus-article-x-face-command beg end)
1020 (error "%s is not a function" gnus-article-x-face-command))
1021 ;; The command is a string, so we interpret the command
1022 ;; as a, well, command, and fork it off.
1023 (let ((process-connection-type nil))
1024 (process-kill-without-query
1026 "article-x-face" nil shell-file-name shell-command-switch
1027 gnus-article-x-face-command))
1028 (process-send-region "article-x-face" beg end)
1029 (process-send-eof "article-x-face"))))))))))
1031 (defun article-decode-mime-words ()
1032 "Decode all MIME-encoded words in the article."
1035 (set-buffer gnus-article-buffer)
1036 (let ((inhibit-point-motion-hooks t)
1038 (mail-decode-encoded-word-region (point-min) (point-max)))))
1040 (defun article-decode-charset (&optional prompt)
1041 "Decode charset-encoded text in the article.
1042 If PROMPT (the prefix), prompt for a coding system to use."
1046 (message-narrow-to-head)
1047 (let* ((inhibit-point-motion-hooks t)
1048 (case-fold-search t)
1049 (ct (message-fetch-field "Content-Type" t))
1050 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1051 (ctl (and ct (condition-case ()
1052 (mail-header-parse-content-type ct)
1056 (mm-read-coding-system "Charset to decode: "))
1058 (mail-content-type-get ctl 'charset))
1059 (gnus-newsgroup-name
1060 (gnus-group-find-parameter
1061 gnus-newsgroup-name 'charset))))
1064 (setq charset (downcase charset)))
1065 (goto-char (point-max))
1068 (narrow-to-region (point) (point-max))
1070 (equal (car ctl) "text/plain"))
1072 charset (and cte (intern (downcase
1073 (gnus-strip-whitespace cte))))
1076 (defun article-decode-encoded-words ()
1077 "Remove encoded-word encoding from headers."
1078 (let (buffer-read-only)
1079 (let ((charset (save-excursion
1080 (set-buffer gnus-summary-buffer)
1081 default-mime-charset)))
1082 (eword-decode-header charset)
1085 (defun article-de-quoted-unreadable (&optional force)
1086 "Translate a quoted-printable-encoded article.
1087 If FORCE, decode the article whether it is marked as quoted-printable
1089 (interactive (list 'force))
1091 (let ((buffer-read-only nil)
1092 (type (gnus-fetch-field "content-transfer-encoding")))
1094 (and type (string-match "quoted-printable" (downcase type))))
1095 (goto-char (point-min))
1096 (search-forward "\n\n" nil 'move)
1098 (narrow-to-region (point) (point-max))
1099 (quoted-printable-decode-region (point-min) (point-max))
1100 (when mm-default-coding-system
1101 (mm-decode-body mm-default-coding-system)))))))
1103 (defun article-hide-pgp (&optional arg)
1104 "Toggle hiding of any PGP headers and signatures in the current article.
1105 If given a negative prefix, always show; if given a positive prefix,
1107 (interactive (gnus-article-hidden-arg))
1108 (unless (gnus-article-check-hidden-text 'pgp arg)
1110 (let ((inhibit-point-motion-hooks t)
1111 buffer-read-only beg end)
1113 (goto-char (point-min))
1114 ;; Hide the "header".
1115 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1116 (delete-region (1+ (match-beginning 0)) (match-end 0))
1117 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1118 (when (looking-at "Hash:.*$")
1119 (delete-region (point) (1+ (gnus-point-at-eol))))
1121 ;; Hide the actual signature.
1122 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1123 (setq end (1+ (match-beginning 0)))
1126 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1128 ;; Perhaps we shouldn't hide to the end of the buffer
1129 ;; if there is no end to the signature?
1131 ;; Hide "- " PGP quotation markers.
1133 (narrow-to-region beg end)
1134 (goto-char (point-min))
1135 (while (re-search-forward "^- " nil t)
1137 (match-beginning 0) (match-end 0)))
1139 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1141 (defun article-hide-pem (&optional arg)
1142 "Toggle hiding of any PEM headers and signatures in the current article.
1143 If given a negative prefix, always show; if given a positive prefix,
1145 (interactive (gnus-article-hidden-arg))
1146 (unless (gnus-article-check-hidden-text 'pem arg)
1148 (let (buffer-read-only end)
1150 (goto-char (point-min))
1151 ;; hide the horrendously ugly "header".
1152 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1155 (setq end (1+ (match-beginning 0)))
1156 (gnus-article-hide-text-type
1158 (if (search-forward "\n\n" nil t)
1162 ;; hide the trailer as well
1163 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1166 (gnus-article-hide-text-type
1167 (match-beginning 0) (match-end 0) 'pem))))))
1169 (defun article-hide-signature (&optional arg)
1170 "Hide the signature in the current article.
1171 If given a negative prefix, always show; if given a positive prefix,
1173 (interactive (gnus-article-hidden-arg))
1174 (unless (gnus-article-check-hidden-text 'signature arg)
1177 (let ((buffer-read-only nil))
1178 (when (gnus-article-narrow-to-signature)
1179 (gnus-article-hide-text-type
1180 (point-min) (point-max) 'signature)))))))
1182 (defun article-strip-leading-blank-lines ()
1183 "Remove all blank lines from the beginning of the article."
1186 (let ((inhibit-point-motion-hooks t)
1188 (goto-char (point-min))
1189 (when (search-forward "\n\n" nil t)
1190 (while (and (not (eobp))
1191 (looking-at "[ \t]*$"))
1192 (gnus-delete-line))))))
1194 (defun article-strip-multiple-blank-lines ()
1195 "Replace consecutive blank lines with one empty line."
1198 (let ((inhibit-point-motion-hooks t)
1200 ;; First make all blank lines empty.
1201 (goto-char (point-min))
1202 (search-forward "\n\n" nil t)
1203 (while (re-search-forward "^[ \t]+$" nil t)
1204 (unless (gnus-annotation-in-region-p
1205 (match-beginning 0) (match-end 0))
1206 (replace-match "" nil t)))
1207 ;; Then replace multiple empty lines with a single empty line.
1208 (goto-char (point-min))
1209 (search-forward "\n\n" nil t)
1210 (while (re-search-forward "\n\n\n+" nil t)
1211 (unless (gnus-annotation-in-region-p
1212 (match-beginning 0) (match-end 0))
1213 (replace-match "\n\n" t t))))))
1215 (defun article-strip-leading-space ()
1216 "Remove all white space from the beginning of the lines in the article."
1219 (let ((inhibit-point-motion-hooks t)
1221 (goto-char (point-min))
1222 (search-forward "\n\n" nil t)
1223 (while (re-search-forward "^[ \t]+" nil t)
1224 (replace-match "" t t)))))
1226 (defun article-strip-blank-lines ()
1227 "Strip leading, trailing and multiple blank lines."
1229 (article-strip-leading-blank-lines)
1230 (article-remove-trailing-blank-lines)
1231 (article-strip-multiple-blank-lines))
1233 (defun article-strip-all-blank-lines ()
1234 "Strip all blank lines."
1237 (let ((inhibit-point-motion-hooks t)
1239 (goto-char (point-min))
1240 (search-forward "\n\n" nil t)
1241 (while (re-search-forward "^[ \t]*\n" nil t)
1242 (replace-match "" t t)))))
1244 (defun gnus-article-narrow-to-signature ()
1245 "Narrow to the signature; return t if a signature is found, else nil."
1247 (let ((inhibit-point-motion-hooks t))
1248 (when (gnus-article-search-signature)
1250 ;; Check whether we have some limits to what we consider
1251 ;; to be a signature.
1252 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1253 (list gnus-signature-limit)))
1255 (while (setq limit (pop limits))
1256 (if (or (and (integerp limit)
1257 (< (- (point-max) (point)) limit))
1259 (< (count-lines (point) (point-max)) limit))
1260 (and (gnus-functionp limit)
1262 (and (stringp limit)
1263 (not (re-search-forward limit nil t))))
1264 () ; This limit did not succeed.
1268 (narrow-to-region (point) (point-max))
1271 (defun gnus-article-search-signature ()
1272 "Search the current buffer for the signature separator.
1273 Put point at the beginning of the signature separator."
1274 (let ((cur (point)))
1275 (goto-char (point-max))
1276 (if (if (stringp gnus-signature-separator)
1277 (re-search-backward gnus-signature-separator nil t)
1278 (let ((seps gnus-signature-separator))
1280 (not (re-search-backward (car seps) nil t)))
1288 (autoload 'w3-display "w3-parse")
1289 (autoload 'w3-do-setup "w3" "" t)
1290 (autoload 'w3-region "w3-display" "" t))
1292 (defun gnus-article-treat-html ()
1295 (let ((cbuf (current-buffer)))
1296 (set-buffer gnus-article-buffer)
1297 (let (buf buffer-read-only b e)
1299 (goto-char (point-min))
1301 (if (search-forward "\n\n" nil t)
1304 (setq e (point-max)))
1306 (insert-buffer-substring gnus-article-buffer b e)
1308 (save-window-excursion
1309 (w3-region (point-min) (point-max))
1310 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1312 (delete-region (point-min) (point-max))
1315 (goto-char (point-min))
1316 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1317 (set-buffer cbuf))))
1319 (defun gnus-article-hidden-arg ()
1320 "Return the current prefix arg as a number, or 0 if no prefix."
1321 (list (if current-prefix-arg
1322 (prefix-numeric-value current-prefix-arg)
1325 (defun gnus-article-check-hidden-text (type arg)
1326 "Return nil if hiding is necessary.
1327 Arg can be nil or a number. Nil and positive means hide, negative
1328 means show, 0 means toggle."
1332 (let ((hide (gnus-article-hidden-text-p type)))
1338 (gnus-article-show-hidden-text type))
1340 (if (eq hide 'hidden)
1341 (gnus-article-show-hidden-text type)
1344 (defun gnus-article-hidden-text-p (type)
1345 "Say whether the current buffer contains hidden text of type TYPE."
1346 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1348 (not (get-text-property pos 'invisible)))
1350 (text-property-any (1+ pos) (point-max) 'article-type type)))
1355 (defun gnus-article-show-hidden-text (type &optional hide)
1356 "Show all hidden text of type TYPE.
1357 If HIDE, hide the text instead."
1359 (let ((buffer-read-only nil)
1360 (inhibit-point-motion-hooks t)
1363 (while (setq beg (text-property-any end (point-max) 'article-type type))
1366 (text-property-not-all beg (point-max) 'article-type type)
1369 (gnus-article-hide-text beg end gnus-hidden-properties)
1370 (gnus-article-unhide-text beg end))
1374 (defconst article-time-units
1375 `((year . ,(* 365.25 24 60 60))
1376 (week . ,(* 7 24 60 60))
1377 (day . ,(* 24 60 60))
1381 "Mapping from time units to seconds.")
1383 (defun article-date-ut (&optional type highlight header)
1384 "Convert DATE date to universal time in the current article.
1385 If TYPE is `local', convert to local time; if it is `lapsed', output
1386 how much time has lapsed since DATE."
1387 (interactive (list 'ut t))
1388 (let* ((header (or header
1389 (mail-header-date gnus-current-headers)
1390 (message-fetch-field "date")
1392 (date (if (vectorp header) (mail-header-date header)
1394 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1395 (inhibit-point-motion-hooks t)
1396 bface eface newline)
1397 (when (and date (not (string= date "")))
1400 (nnheader-narrow-to-headers)
1401 (let ((buffer-read-only nil))
1402 ;; Delete any old Date headers.
1403 (if (re-search-forward date-regexp nil t)
1405 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1406 eface (get-text-property (1- (gnus-point-at-eol))
1408 (delete-region (progn (beginning-of-line) (point))
1409 (progn (end-of-line) (point)))
1410 (beginning-of-line))
1411 (goto-char (point-max))
1413 (insert (article-make-date-line date type))
1416 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1417 (put-text-property (match-beginning 1) (1+ (match-end 1))
1419 (put-text-property (match-beginning 2) (match-end 2)
1423 (insert "\n"))))))))
1425 (defun article-make-date-line (date type)
1426 "Return a DATE line of TYPE."
1427 (let ((time (condition-case ()
1431 ;; Convert to the local timezone. We have to slap a
1432 ;; `condition-case' round the calls to the timezone
1433 ;; functions since they aren't particularly resistant to
1436 (let ((tz (car (current-time-zone))))
1437 (format "Date: %s %s%04d" (current-time-string time)
1438 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1439 ;; Convert to Universal Time.
1442 (current-time-string
1443 (let* ((e (parse-time-string date))
1444 (tm (apply 'encode-time e))
1446 (ls (- (cadr tm) (car (current-time-zone)))))
1447 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1448 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1451 ;; Get the original date from the article.
1452 ((eq type 'original)
1453 (concat "Date: " (if (string-match "\n+$" date)
1454 (substring date 0 (match-beginning 0))
1456 ;; Let the user define the format.
1458 (if (gnus-functionp gnus-article-time-format)
1459 (funcall gnus-article-time-format time)
1462 (format-time-string gnus-article-time-format time))))
1467 (format-time-string "%Y%M%DT%h%m%s" time)))
1468 ;; Do an X-Sent lapsed format.
1470 ;; If the date is seriously mangled, the timezone functions are
1471 ;; liable to bug out, so we ignore all errors.
1472 (let* ((now (current-time))
1473 (real-time (subtract-time now time))
1474 (real-sec (and real-time
1475 (+ (* (float (car real-time)) 65536)
1477 (sec (and real-time (abs real-sec)))
1487 ;; This is a bit convoluted, but basically we go
1488 ;; through the time units for years, weeks, etc,
1489 ;; and divide things to see whether that results
1490 ;; in positive answers.
1493 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1494 ;; The (remaining) seconds are too few to
1495 ;; be divided into this time unit.
1497 ;; It's big enough, so we output it.
1498 (setq sec (- sec (* num (cdr unit))))
1500 (concat (if prev ", " "") (int-to-string
1502 " " (symbol-name (car unit))
1503 (if (> num 1) "s" ""))
1505 article-time-units "")
1506 ;; If dates are odd, then it might appear like the
1507 ;; article was sent in the future.
1510 " in the future"))))))
1512 (error "Unknown conversion type: %s" type)))))
1514 (defun article-date-local (&optional highlight)
1515 "Convert the current article date to the local timezone."
1516 (interactive (list t))
1517 (article-date-ut 'local highlight))
1519 (defun article-date-original (&optional highlight)
1520 "Convert the current article date to what it was originally.
1521 This is only useful if you have used some other date conversion
1522 function and want to see what the date was before converting."
1523 (interactive (list t))
1524 (article-date-ut 'original highlight))
1526 (defun article-date-lapsed (&optional highlight)
1527 "Convert the current article date to time lapsed since it was sent."
1528 (interactive (list t))
1529 (article-date-ut 'lapsed highlight))
1531 (defun article-update-date-lapsed ()
1532 "Function to be run from a timer to update the lapsed time line."
1533 (let (deactivate-mark)
1538 (set-buffer (window-buffer w))
1539 (when (eq major-mode 'gnus-article-mode)
1540 (goto-char (point-min))
1541 (when (re-search-forward "^X-Sent:" nil t)
1542 (article-date-lapsed t)))))))))
1544 (defun gnus-start-date-timer (&optional n)
1545 "Start a timer to update the X-Sent header in the article buffers.
1546 The numerical prefix says how frequently (in seconds) the function
1551 (gnus-stop-date-timer)
1552 (setq article-lapsed-timer
1553 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1555 (defun gnus-stop-date-timer ()
1556 "Stop the X-Sent timer."
1558 (when article-lapsed-timer
1559 (nnheader-cancel-timer article-lapsed-timer)
1560 (setq article-lapsed-timer nil)))
1562 (defun article-date-user (&optional highlight)
1563 "Convert the current article date to the user-defined format.
1564 This format is defined by the `gnus-article-time-format' variable."
1565 (interactive (list t))
1566 (article-date-ut 'user highlight))
1568 (defun article-date-iso8601 (&optional highlight)
1569 "Convert the current article date to ISO8601."
1570 (interactive (list t))
1571 (article-date-ut 'iso8601 highlight))
1573 (defun article-show-all ()
1574 "Show all hidden text in the article buffer."
1577 (let ((buffer-read-only nil))
1578 (gnus-article-unhide-text (point-min) (point-max)))))
1580 (defun article-emphasize (&optional arg)
1581 "Emphasize text according to `gnus-emphasis-alist'."
1582 (interactive (gnus-article-hidden-arg))
1583 (unless (gnus-article-check-hidden-text 'emphasis arg)
1585 (let ((alist gnus-emphasis-alist)
1586 (buffer-read-only nil)
1587 (props (append '(article-type emphasis)
1588 gnus-hidden-properties))
1589 regexp elem beg invisible visible face)
1590 (goto-char (point-min))
1591 (search-forward "\n\n" nil t)
1593 (while (setq elem (pop alist))
1595 (setq regexp (car elem)
1596 invisible (nth 1 elem)
1597 visible (nth 2 elem)
1599 (while (re-search-forward regexp nil t)
1600 (when (and (match-beginning visible) (match-beginning invisible))
1601 (gnus-article-hide-text
1602 (match-beginning invisible) (match-end invisible) props)
1603 (gnus-article-unhide-text-type
1604 (match-beginning visible) (match-end visible) 'emphasis)
1605 (gnus-put-text-property-excluding-newlines
1606 (match-beginning visible) (match-end visible) 'face face)
1607 (goto-char (match-end invisible)))))))))
1609 (defvar gnus-summary-article-menu)
1610 (defvar gnus-summary-post-menu)
1612 ;;; Saving functions.
1614 (defun gnus-article-save (save-buffer file &optional num)
1615 "Save the currently selected article."
1616 (unless gnus-save-all-headers
1617 ;; Remove headers according to `gnus-saved-headers'.
1618 (let ((gnus-visible-headers
1619 (or gnus-saved-headers gnus-visible-headers))
1620 (gnus-article-buffer save-buffer))
1622 (set-buffer save-buffer)
1623 (article-hide-headers 1 t))))
1624 (save-window-excursion
1625 (if (not gnus-default-article-saver)
1626 (error "No default saver is defined")
1627 ;; !!! Magic! The saving functions all save
1628 ;; `gnus-save-article-buffer' (or so they think), but we
1629 ;; bind that variable to our save-buffer.
1630 (set-buffer gnus-article-buffer)
1631 (let* ((gnus-save-article-buffer save-buffer)
1634 ((not gnus-prompt-before-saving) 'default)
1635 ((eq gnus-prompt-before-saving 'always) nil)
1637 (gnus-number-of-articles-to-be-saved
1638 (when (eq gnus-prompt-before-saving t)
1640 (set-buffer gnus-article-current-summary)
1641 (funcall gnus-default-article-saver filename)))))
1643 (defun gnus-read-save-file-name (prompt &optional filename
1644 function group headers variable)
1646 (funcall function group headers (symbol-value variable)))
1651 ((eq filename 'default)
1657 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1660 (if (and gnus-number-of-articles-to-be-saved
1661 (> gnus-number-of-articles-to-be-saved 1))
1662 (format "these %d articles"
1663 gnus-number-of-articles-to-be-saved)
1666 ;; Let the split methods have their say.
1668 ;; No split name was found.
1671 (concat prompt " (default "
1672 (file-name-nondirectory default-name) ") ")
1673 (file-name-directory default-name)
1675 ;; A single group name is returned.
1676 ((stringp split-name)
1678 (funcall function split-name headers
1679 (symbol-value variable)))
1681 (concat prompt " (default "
1682 (file-name-nondirectory default-name) ") ")
1683 (file-name-directory default-name)
1685 ;; A single split name was found
1686 ((= 1 (length split-name))
1687 (let* ((name (expand-file-name
1688 (car split-name) gnus-article-save-directory))
1689 (dir (cond ((file-directory-p name)
1690 (file-name-as-directory name))
1691 ((file-exists-p name) name)
1692 (t gnus-article-save-directory))))
1694 (concat prompt " (default " name ") ")
1696 ;; A list of splits was found.
1698 (setq split-name (nreverse split-name))
1700 (let ((file-name-history
1701 (nconc split-name file-name-history)))
1705 (concat prompt " (`M-p' for defaults) ")
1706 gnus-article-save-directory
1708 gnus-article-save-directory)))
1709 (car (push result file-name-history)))))))
1710 ;; Create the directory.
1711 (gnus-make-directory (file-name-directory file))
1712 ;; If we have read a directory, we append the default file name.
1713 (when (file-directory-p file)
1714 (setq file (concat (file-name-as-directory file)
1715 (file-name-nondirectory default-name))))
1716 ;; Possibly translate some characters.
1717 (nnheader-translate-file-chars file)))))
1718 (gnus-make-directory (file-name-directory result))
1719 (set variable result)))
1721 (defun gnus-article-archive-name (group)
1722 "Return the first instance of an \"Archive-name\" in the current buffer."
1723 (let ((case-fold-search t))
1724 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1725 (nnheader-concat gnus-article-save-directory
1726 (match-string 1)))))
1728 (defun gnus-article-nndoc-name (group)
1729 "If GROUP is an nndoc group, return the name of the parent group."
1730 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1731 (gnus-group-get-parameter group 'save-article-group)))
1733 (defun gnus-summary-save-in-rmail (&optional filename)
1734 "Append this article to Rmail file.
1735 Optional argument FILENAME specifies file name.
1736 Directory to save to is default to `gnus-article-save-directory'."
1737 (setq filename (gnus-read-save-file-name
1738 "Save %s in rmail file:" filename
1739 gnus-rmail-save-name gnus-newsgroup-name
1740 gnus-current-headers 'gnus-newsgroup-last-rmail))
1741 (gnus-eval-in-buffer-window gnus-save-article-buffer
1745 (gnus-output-to-rmail filename))))
1748 (defun gnus-summary-save-in-mail (&optional filename)
1749 "Append this article to Unix mail file.
1750 Optional argument FILENAME specifies file name.
1751 Directory to save to is default to `gnus-article-save-directory'."
1752 (setq filename (gnus-read-save-file-name
1753 "Save %s in Unix mail file:" filename
1754 gnus-mail-save-name gnus-newsgroup-name
1755 gnus-current-headers 'gnus-newsgroup-last-mail))
1756 (gnus-eval-in-buffer-window gnus-save-article-buffer
1760 (if (and (file-readable-p filename)
1761 (mail-file-babyl-p filename))
1762 (rmail-output-to-rmail-file filename t)
1763 (gnus-output-to-mail filename)))))
1766 (defun gnus-summary-save-in-file (&optional filename overwrite)
1767 "Append this article to file.
1768 Optional argument FILENAME specifies file name.
1769 Directory to save to is default to `gnus-article-save-directory'."
1770 (setq filename (gnus-read-save-file-name
1771 "Save %s in file:" filename
1772 gnus-file-save-name gnus-newsgroup-name
1773 gnus-current-headers 'gnus-newsgroup-last-file))
1774 (gnus-eval-in-buffer-window gnus-save-article-buffer
1778 (when (and overwrite
1779 (file-exists-p filename))
1780 (delete-file filename))
1781 (gnus-output-to-file filename))))
1784 (defun gnus-summary-write-to-file (&optional filename)
1785 "Write this article to a file.
1786 Optional argument FILENAME specifies file name.
1787 The directory to save in defaults to `gnus-article-save-directory'."
1788 (gnus-summary-save-in-file nil t))
1790 (defun gnus-summary-save-body-in-file (&optional filename)
1791 "Append this article body to a file.
1792 Optional argument FILENAME specifies file name.
1793 The directory to save in defaults to `gnus-article-save-directory'."
1794 (setq filename (gnus-read-save-file-name
1795 "Save %s body in file:" filename
1796 gnus-file-save-name gnus-newsgroup-name
1797 gnus-current-headers 'gnus-newsgroup-last-file))
1798 (gnus-eval-in-buffer-window gnus-save-article-buffer
1802 (goto-char (point-min))
1803 (when (search-forward "\n\n" nil t)
1804 (narrow-to-region (point) (point-max)))
1805 (gnus-output-to-file filename))))
1808 (defun gnus-summary-save-in-pipe (&optional command)
1809 "Pipe this article to subprocess."
1811 (cond ((and (eq command 'default)
1812 gnus-last-shell-command)
1813 gnus-last-shell-command)
1817 "Shell command on %s: "
1818 (if (and gnus-number-of-articles-to-be-saved
1819 (> gnus-number-of-articles-to-be-saved 1))
1820 (format "these %d articles"
1821 gnus-number-of-articles-to-be-saved)
1823 gnus-last-shell-command))))
1824 (when (string-equal command "")
1825 (setq command gnus-last-shell-command))
1826 (gnus-eval-in-buffer-window gnus-article-buffer
1829 (shell-command-on-region (point-min) (point-max) command nil)))
1830 (setq gnus-last-shell-command command))
1832 ;;; Article file names when saving.
1834 (defun gnus-capitalize-newsgroup (newsgroup)
1835 "Capitalize NEWSGROUP name."
1836 (when (not (zerop (length newsgroup)))
1837 (concat (char-to-string (upcase (aref newsgroup 0)))
1838 (substring newsgroup 1))))
1840 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1841 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1842 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1843 Otherwise, it is like ~/News/news/group/num."
1846 (concat (if (gnus-use-long-file-name 'not-save)
1847 (gnus-capitalize-newsgroup newsgroup)
1848 (gnus-newsgroup-directory-form newsgroup))
1849 "/" (int-to-string (mail-header-number headers)))
1850 gnus-article-save-directory)))
1852 (string-equal (file-name-directory default)
1853 (file-name-directory last-file))
1854 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1856 (or last-file default))))
1858 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1859 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1860 If variable `gnus-use-long-file-name' is non-nil, it is
1861 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1864 (concat (if (gnus-use-long-file-name 'not-save)
1866 (gnus-newsgroup-directory-form newsgroup))
1867 "/" (int-to-string (mail-header-number headers)))
1868 gnus-article-save-directory)))
1870 (string-equal (file-name-directory default)
1871 (file-name-directory last-file))
1872 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1874 (or last-file default))))
1876 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1877 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1878 If variable `gnus-use-long-file-name' is non-nil, it is
1879 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1882 (if (gnus-use-long-file-name 'not-save)
1883 (gnus-capitalize-newsgroup newsgroup)
1884 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1885 gnus-article-save-directory)))
1887 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1888 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1889 If variable `gnus-use-long-file-name' is non-nil, it is
1890 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1893 (if (gnus-use-long-file-name 'not-save)
1895 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1896 gnus-article-save-directory)))
1903 (setq afunc (car func)
1906 gfunc (intern (format "gnus-%s" func))))
1908 (if (not (fboundp afunc))
1910 `(lambda (&optional interactive &rest args)
1911 ,(documentation afunc t)
1912 (interactive (list t))
1914 (set-buffer gnus-article-buffer)
1916 (call-interactively ',afunc)
1917 (apply ',afunc args))))))))
1918 '(article-hide-headers
1919 article-hide-boring-headers
1920 article-treat-overstrike
1921 (article-fill . gnus-article-word-wrap)
1923 article-display-x-face
1926 article-hide-signature
1927 article-remove-trailing-blank-lines
1928 article-strip-leading-blank-lines
1929 article-strip-multiple-blank-lines
1930 article-strip-leading-space
1931 article-strip-blank-lines
1932 article-strip-all-blank-lines
1934 article-date-iso8601
1935 article-date-original
1940 article-treat-dumbquotes
1941 (article-show-all . gnus-article-show-all-headers))))
1944 ;;; Gnus article mode
1947 (put 'gnus-article-mode 'mode-class 'special)
1949 (gnus-define-keys gnus-article-mode-map
1950 " " gnus-article-goto-next-page
1951 "\177" gnus-article-goto-prev-page
1952 [delete] gnus-article-goto-prev-page
1953 "\C-c^" gnus-article-refer-article
1954 "h" gnus-article-show-summary
1955 "s" gnus-article-show-summary
1956 "\C-c\C-m" gnus-article-mail
1957 "?" gnus-article-describe-briefly
1958 gnus-mouse-2 gnus-article-push-button
1959 "\r" gnus-article-press-button
1960 "\t" gnus-article-next-button
1961 "\M-\t" gnus-article-prev-button
1962 "e" gnus-article-edit
1963 "<" beginning-of-buffer
1965 "\C-c\C-i" gnus-info-find-node
1968 "\C-d" gnus-article-read-summary-keys
1969 "\M-*" gnus-article-read-summary-keys
1970 "\M-#" gnus-article-read-summary-keys
1971 "\M-^" gnus-article-read-summary-keys
1972 "\M-g" gnus-article-read-summary-keys)
1974 (substitute-key-definition
1975 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1977 (defun gnus-article-make-menu-bar ()
1978 (gnus-turn-off-edit-menu 'article)
1979 (unless (boundp 'gnus-article-article-menu)
1981 gnus-article-article-menu gnus-article-mode-map ""
1983 ["Scroll forwards" gnus-article-goto-next-page t]
1984 ["Scroll backwards" gnus-article-goto-prev-page t]
1985 ["Show summary" gnus-article-show-summary t]
1986 ["Fetch Message-ID at point" gnus-article-refer-article t]
1987 ["Mail to address at point" gnus-article-mail t]
1988 ["Send a bug report" gnus-bug t]))
1991 gnus-article-treatment-menu gnus-article-mode-map ""
1993 ["Hide headers" gnus-article-hide-headers t]
1994 ["Hide signature" gnus-article-hide-signature t]
1995 ["Hide citation" gnus-article-hide-citation t]
1996 ["Treat overstrike" gnus-article-treat-overstrike t]
1997 ["Remove carriage return" gnus-article-remove-cr t]))
1999 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2001 (when (boundp 'gnus-summary-post-menu)
2002 (define-key gnus-article-mode-map [menu-bar post]
2003 (cons "Post" gnus-summary-post-menu)))
2005 (gnus-run-hooks 'gnus-article-menu-hook)))
2007 (defun gnus-article-mode ()
2008 "Major mode for displaying an article.
2010 All normal editing commands are switched off.
2012 The following commands are available in addition to all summary mode
2014 \\<gnus-article-mode-map>
2015 \\[gnus-article-next-page]\t Scroll the article one page forwards
2016 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2017 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2018 \\[gnus-article-show-summary]\t Display the summary buffer
2019 \\[gnus-article-mail]\t Send a reply to the address near point
2020 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2021 \\[gnus-info-find-node]\t Go to the Gnus info node"
2023 (when (gnus-visual-p 'article-menu 'menu)
2024 (gnus-article-make-menu-bar))
2025 (gnus-simplify-mode-line)
2026 (setq mode-name "Article")
2027 (setq major-mode 'gnus-article-mode)
2028 (make-local-variable 'minor-mode-alist)
2029 (unless (assq 'gnus-show-mime minor-mode-alist)
2030 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2031 (use-local-map gnus-article-mode-map)
2032 (gnus-update-format-specifications nil 'article-mode)
2033 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2034 (make-local-variable 'gnus-page-broken)
2035 (make-local-variable 'gnus-button-marker-list)
2036 (make-local-variable 'gnus-article-current-summary)
2037 (gnus-set-default-directory)
2038 (buffer-disable-undo)
2039 (setq buffer-read-only t)
2040 (set-syntax-table gnus-article-mode-syntax-table)
2041 (gnus-run-hooks 'gnus-article-mode-hook))
2043 (defun gnus-article-setup-buffer ()
2044 "Initialize the article buffer."
2045 (let* ((name (if gnus-single-article-buffer "*Article*"
2046 (concat "*Article " gnus-newsgroup-name "*")))
2048 (progn (string-match "\\*Article" name)
2049 (concat " *Original Article"
2050 (substring name (match-end 0))))))
2051 (setq gnus-article-buffer name)
2052 (setq gnus-original-article-buffer original)
2053 ;; This might be a variable local to the summary buffer.
2054 (unless gnus-single-article-buffer
2056 (set-buffer gnus-summary-buffer)
2057 (setq gnus-article-buffer name)
2058 (setq gnus-original-article-buffer original)
2059 (gnus-set-global-variables)))
2060 ;; Init original article buffer.
2062 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2063 (setq major-mode 'gnus-original-article-mode)
2064 (make-local-variable 'gnus-original-article))
2065 (if (get-buffer name)
2068 (buffer-disable-undo)
2069 (setq buffer-read-only t)
2070 (unless (eq major-mode 'gnus-article-mode)
2071 (gnus-article-mode))
2074 (set-buffer (gnus-get-buffer-create name))
2076 (make-local-variable 'gnus-summary-buffer)
2077 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2078 (current-buffer)))))
2080 ;; Set article window start at LINE, where LINE is the number of lines
2081 ;; from the head of the article.
2082 (defun gnus-article-set-window-start (&optional line)
2084 (get-buffer-window gnus-article-buffer t)
2086 (set-buffer gnus-article-buffer)
2087 (goto-char (point-min))
2090 (gnus-message 6 "Moved to bookmark")
2091 (search-forward "\n\n" nil t)
2095 ;;; @@ article filters
2098 (defun gnus-article-display-mime-message ()
2099 "Article display method for MIME message."
2100 ;; called from `gnus-original-article-buffer'.
2101 (let ((charset (with-current-buffer gnus-summary-buffer
2102 default-mime-charset)))
2103 (make-local-variable 'default-mime-charset)
2104 (setq default-mime-charset charset)
2105 (mime-display-message mime-message-structure
2106 gnus-article-buffer nil gnus-article-mode-map)
2107 (make-local-variable 'default-mime-charset)
2108 (setq default-mime-charset charset)
2110 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2111 (make-local-variable 'mime-button-mother-dispatcher)
2112 (setq mime-button-mother-dispatcher
2113 (function gnus-article-push-button))
2114 (run-hooks 'gnus-mime-article-prepare-hook))
2116 (defun gnus-article-display-traditional-message ()
2117 "Article display method for traditional message."
2118 (set-buffer gnus-article-buffer)
2119 (let (buffer-read-only)
2121 (insert-buffer-substring gnus-original-article-buffer)))
2123 (defun gnus-article-make-full-mail-header (&optional number charset)
2124 "Create a new mail header structure in a raw article buffer."
2125 (unless (and number charset)
2126 (save-current-buffer
2127 (set-buffer gnus-summary-buffer)
2129 (setq number (or (cdr gnus-article-current) 0)))
2131 (setq charset (or default-mime-charset 'x-ctext)))))
2132 (goto-char (point-min))
2133 (let ((header-end (if (search-forward "\n\n" nil t)
2135 (goto-char (point-max))))
2136 (chars (- (point-max) (point)))
2137 (lines (count-lines (point) (point-max)))
2138 (default-mime-charset charset)
2140 (narrow-to-region (point-min) header-end)
2141 (setq xref (std11-fetch-field "xref"))
2143 (make-full-mail-header
2145 (std11-fetch-field "subject")
2146 (std11-fetch-field "from")
2147 (std11-fetch-field "date")
2148 (std11-fetch-field "message-id")
2149 (std11-fetch-field "references")
2152 (when xref (concat "Xref: " xref)))
2155 (defun gnus-article-prepare (article &optional all-headers header)
2156 "Prepare ARTICLE in article mode buffer.
2157 ARTICLE should either be an article number or a Message-ID.
2158 If ARTICLE is an id, HEADER should be the article headers.
2159 If ALL-HEADERS is non-nil, no headers are hidden."
2161 ;; Make sure we start in a summary buffer.
2162 (unless (eq major-mode 'gnus-summary-mode)
2163 (set-buffer gnus-summary-buffer))
2164 (setq gnus-summary-buffer (current-buffer))
2165 (let* ((gnus-article (if header (mail-header-number header) article))
2166 (summary-buffer (current-buffer))
2167 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2168 (group gnus-newsgroup-name)
2171 (gnus-article-setup-buffer)
2172 (set-buffer gnus-original-article-buffer)
2173 ;; Deactivate active regions.
2174 (when (and (boundp 'transient-mark-mode)
2175 transient-mark-mode)
2176 (setq mark-active nil))
2177 (if (not (setq result (let ((buffer-read-only nil))
2178 (gnus-request-article-this-buffer
2180 ;; There is no such article.
2182 (when (and (numberp article)
2183 (not (memq article gnus-newsgroup-sparse)))
2184 (setq gnus-article-current
2185 (cons gnus-newsgroup-name article))
2186 (set-buffer gnus-summary-buffer)
2187 (setq gnus-current-article article)
2188 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2190 (gnus-summary-set-agent-mark article)
2191 (message "Message marked for downloading"))
2192 (gnus-summary-mark-article article gnus-canceled-mark)
2193 (unless (memq article gnus-newsgroup-sparse)
2195 "No such article (may have expired or been canceled)")))))
2196 (if (or (eq result 'pseudo)
2197 (eq result 'nneething))
2200 (set-buffer summary-buffer)
2201 (push article gnus-newsgroup-history)
2202 (setq gnus-last-article gnus-current-article
2203 gnus-current-article 0
2204 gnus-current-headers nil
2205 gnus-article-current nil)
2206 (if (eq result 'nneething)
2207 (gnus-configure-windows 'summary)
2208 (gnus-configure-windows 'article))
2209 (gnus-set-global-variables))
2210 (gnus-set-mode-line 'article))
2211 ;; The result from the `request' was an actual article -
2212 ;; or at least some text that is now displayed in the
2214 (when (and (numberp article)
2215 (not (eq article gnus-current-article)))
2216 ;; Seems like a new article has been selected.
2217 ;; `gnus-current-article' must be an article number.
2219 (set-buffer summary-buffer)
2220 (push article gnus-newsgroup-history)
2221 (setq gnus-last-article gnus-current-article
2222 gnus-current-article article
2223 gnus-current-headers
2224 (gnus-summary-article-header gnus-current-article)
2225 gnus-article-current
2226 (cons gnus-newsgroup-name gnus-current-article))
2227 (unless (vectorp gnus-current-headers)
2228 (setq gnus-current-headers nil))
2229 (gnus-summary-goto-subject gnus-current-article)
2230 (when (gnus-summary-show-thread)
2231 ;; If the summary buffer really was folded, the
2232 ;; previous goto may not actually have gone to
2233 ;; the right article, but the thread root instead.
2235 (gnus-summary-goto-subject gnus-current-article))
2236 (gnus-run-hooks 'gnus-mark-article-hook)
2237 (gnus-set-mode-line 'summary)
2238 (when (gnus-visual-p 'article-highlight 'highlight)
2239 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2240 ;; Set the global newsgroup variables here.
2241 ;; Suggested by Jim Sisolak
2242 ;; <sisolak@trans4.neep.wisc.edu>.
2243 (gnus-set-global-variables)
2244 (setq gnus-have-all-headers
2245 (or all-headers gnus-show-all-headers))))
2246 (when (or (numberp article)
2248 (gnus-article-prepare-display)
2250 (goto-char (point-min))
2251 (setq gnus-page-broken
2252 (when gnus-break-pages
2253 (gnus-narrow-to-page)
2255 (gnus-set-mode-line 'article)
2256 (gnus-configure-windows 'article)
2257 (goto-char (point-min))
2258 (search-forward "\n\n" nil t)
2259 (set-window-point (get-buffer-window (current-buffer)) (point))
2262 (defun gnus-article-prepare-display ()
2263 "Make the current buffer look like a nice article."
2267 (setq mime-message-structure gnus-current-headers)
2268 gnus-article-display-method-for-mime)
2269 gnus-article-display-method-for-traditional)))
2270 (gnus-run-hooks 'gnus-tmp-internal-hook)
2271 (gnus-run-hooks 'gnus-article-prepare-hook)
2274 ;; Associate this article with the current summary buffer.
2275 (setq gnus-article-current-summary (current-buffer))
2276 ;; Perform the article display hooks.
2277 (gnus-run-hooks 'gnus-article-display-hook)))
2280 ;;; Gnus MIME viewing functions
2283 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2284 "The following specs can be used:
2286 %n The `name' parameter
2287 %d The description, if any
2288 %l The length of the encoded part
2289 %p The part identifier
2290 %e Dots if the part isn't displayed")
2292 (defvar gnus-mime-button-line-format-alist
2293 '((?t gnus-tmp-type ?s)
2294 (?n gnus-tmp-name ?s)
2295 (?d gnus-tmp-description ?s)
2297 (?l gnus-tmp-length ?d)
2298 (?e gnus-tmp-dots ?s)))
2300 (defvar gnus-mime-button-commands
2301 '((gnus-article-press-button "\r" "Toggle Display")
2302 ;(gnus-mime-view-part "\M-\r" "View Interactively...")
2303 (gnus-mime-view-part "v" "View Interactively...")
2304 (gnus-mime-save-part "o" "Save...")
2305 (gnus-mime-copy-part "c" "View In Buffer")
2306 (gnus-mime-inline-part "i" "View Inline")
2307 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2309 (defvar gnus-mime-button-map nil)
2310 (unless gnus-mime-button-map
2311 (setq gnus-mime-button-map (make-sparse-keymap))
2312 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2313 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2314 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2316 (define-key gnus-mime-button-map (cadr c) (car c)))
2317 gnus-mime-button-commands))
2319 (defun gnus-mime-button-menu (event)
2320 "Construct a context-sensitive menu of MIME commands."
2322 (let ((response (x-popup-menu
2324 ("" ,@(mapcar (lambda (c)
2325 (cons (caddr c) (car c)))
2326 gnus-mime-button-commands)))))
2327 (pos (event-start event)))
2329 (set-buffer (window-buffer (posn-window pos)))
2330 (goto-char (posn-point pos))
2331 (funcall response))))
2333 (defun gnus-mime-view-all-parts ()
2334 "View all the MIME parts."
2336 (let ((handles gnus-article-mime-handles))
2338 (mm-display-part (pop handles)))))
2340 (defun gnus-mime-save-part ()
2341 "Save the MIME part under point."
2343 (let ((data (get-text-property (point) 'gnus-data)))
2344 (mm-save-part data)))
2346 (defun gnus-mime-pipe-part ()
2347 "Pipe the MIME part under point to a process."
2349 (let ((data (get-text-property (point) 'gnus-data)))
2350 (mm-pipe-part data)))
2352 (defun gnus-mime-view-part ()
2353 "Interactively choose a view method for the MIME part under point."
2355 (let ((data (get-text-property (point) 'gnus-data))
2356 (url-standalone-mode (not gnus-plugged)))
2357 (mm-interactively-view-part data)))
2359 (defun gnus-mime-copy-part ()
2360 "Put the the MIME part under point into a new buffer."
2362 (let* ((handle (get-text-property (point) 'gnus-data))
2363 (contents (mm-get-part handle))
2364 (buffer (generate-new-buffer
2365 (file-name-nondirectory
2367 (mail-content-type-get (mm-handle-type handle) 'name)
2368 (mail-content-type-get (mm-handle-type handle)
2371 (switch-to-buffer buffer)
2374 (goto-char (point-min))))
2376 (defun gnus-mime-inline-part ()
2377 "Insert the MIME part under point into the current buffer."
2379 (let* ((data (get-text-property (point) 'gnus-data))
2380 (contents (mm-get-part data))
2381 (url-standalone-mode (not gnus-plugged))
2384 (if (mm-handle-undisplayer data)
2385 (mm-remove-part data)
2387 (mm-insert-inline data contents)
2390 (defun gnus-article-view-part (n)
2391 "View MIME part N, which is the numerical prefix."
2393 (save-current-buffer
2394 (set-buffer gnus-article-buffer)
2395 (when (> n (length gnus-article-mime-handle-alist))
2396 (error "No such part"))
2397 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2398 (gnus-article-goto-part n)
2399 (if (equal (car handle) "multipart/alternative")
2400 (gnus-article-press-button)
2401 (when (eq (gnus-mm-display-part handle) 'internal)
2402 (gnus-set-window-start))))))
2404 (defun gnus-mm-display-part (handle)
2405 "Display HANDLE and fix MIME button."
2406 (let ((id (get-text-property (point) 'gnus-part))
2409 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2410 (gnus-insert-mime-button
2411 handle id (list (not (mm-handle-displayed-p handle))))
2413 (mm-display-part handle)
2414 (goto-char point))))
2416 (defun gnus-article-goto-part (n)
2417 "Go to MIME part N."
2418 (goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
2420 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2421 (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2422 (gnus-tmp-type (car (mm-handle-type handle)))
2423 (gnus-tmp-description (mm-handle-description handle))
2425 (if (if displayed (car displayed)
2426 (mm-handle-displayed-p handle))
2428 (gnus-tmp-length (save-excursion
2429 (set-buffer (mm-handle-buffer handle))
2434 (concat " (" gnus-tmp-name ")")
2436 (setq gnus-tmp-description
2437 (if gnus-tmp-description
2438 (concat " (" gnus-tmp-description ")")
2442 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2443 `(local-map ,gnus-mime-button-map
2444 keymap ,gnus-mime-button-map
2445 gnus-callback gnus-mm-display-part
2446 gnus-part ,gnus-tmp-id
2447 article-type annotation
2450 (widget-convert-button 'link b e :action 'gnus-widget-press-button
2451 :button-keymap gnus-mime-button-map)))
2453 (defun gnus-widget-press-button (elems el)
2454 (goto-char (widget-get elems :from))
2455 (let ((url-standalone-mode (not gnus-plugged)))
2456 (gnus-article-press-button)))
2458 (defun gnus-display-mime (&optional ihandles)
2459 "Insert MIME buttons in the buffer."
2460 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2461 handle name type b e display)
2464 ;; Top-level call; we clean up.
2465 (mm-destroy-parts gnus-article-mime-handles)
2466 (setq gnus-article-mime-handles handles
2467 gnus-article-mime-handle-alist nil)
2468 (goto-char (point-min))
2469 (search-forward "\n\n" nil t)
2470 (delete-region (point) (point-max)))
2471 (if (stringp (car handles))
2472 (if (equal (car handles) "multipart/alternative")
2473 (gnus-mime-display-alternative (cdr handles))
2474 (gnus-mime-display-mixed (cdr handles)))
2475 (gnus-mime-display-single handles)))))
2477 (defun gnus-mime-display-mixed (handles)
2479 (while (setq handle (pop handles))
2480 (if (stringp (car handle))
2481 (if (equal (car handle) "multipart/alternative")
2482 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2483 (push (cons id handle) gnus-article-mime-handle-alist)
2484 (gnus-mime-display-alternative (cdr handle) nil nil id))
2485 (gnus-mime-display-mixed (cdr handle)))
2486 (gnus-mime-display-single handle)))))
2488 (defun gnus-mime-display-single (handle)
2489 (let ((type (car (mm-handle-type handle)))
2490 (ignored gnus-ignored-mime-types)
2495 (when (string-match (pop ignored) type)
2496 (throw 'ignored nil)))
2497 (if (and (mm-automatic-display-p type)
2498 (mm-inlinable-part-p type)
2499 (or (not (mm-handle-disposition handle))
2500 (equal (car (mm-handle-disposition handle))
2503 (when (equal (car (split-string type "/"))
2506 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2507 (push (cons id handle) gnus-article-mime-handle-alist)
2508 (gnus-insert-mime-button handle id (list (or display text))))
2513 (mm-display-part handle t)
2514 (goto-char (point-max)))
2518 (mm-insert-inline handle (mm-get-part handle))
2519 (goto-char (point-max))))))))
2521 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2522 (let* ((preferred (mm-preferred-alternative handles preferred))
2525 handle buffer-read-only from props begend not-pref)
2528 (narrow-to-region (car ibegend) (cdr ibegend))
2529 (delete-region (point-min) (point-max))
2530 (mm-remove-parts handles))
2531 (setq begend (list (point-marker)))
2533 (unless (setq not-pref (cadr (member preferred ihandles)))
2534 (setq not-pref (car ihandles)))
2535 (gnus-add-text-properties
2538 (insert (format "%d. " id))
2542 (gnus-mime-display-alternative
2543 ',ihandles ,(if (stringp (car not-pref))
2545 (car (mm-handle-type not-pref)))
2547 local-map ,gnus-mime-button-map
2548 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2549 face ,gnus-article-button-face
2550 keymap ,gnus-mime-button-map
2553 (widget-convert-button 'link from (point)
2554 :action 'gnus-widget-press-button
2555 :button-keymap gnus-widget-button-keymap)
2557 (while (setq handle (pop handles))
2558 (gnus-add-text-properties
2561 (insert (format "[%c] %-18s"
2562 (if (equal handle preferred) ?* ? )
2563 (if (stringp (car handle))
2565 (car (mm-handle-type handle)))))
2569 (gnus-mime-display-alternative
2570 ',ihandles ,(if (stringp (car handle))
2572 (car (mm-handle-type handle)))
2574 local-map ,gnus-mime-button-map
2575 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2576 face ,gnus-article-button-face
2577 keymap ,gnus-mime-button-map
2580 (widget-convert-button 'link from (point)
2581 :action 'gnus-widget-press-button
2582 :button-keymap gnus-widget-button-keymap)
2586 (if (stringp (car preferred))
2587 (gnus-display-mime preferred)
2588 (mm-display-part preferred)
2589 (goto-char (point-max))
2590 (setcdr begend (point-marker)))))
2592 (goto-char point))))
2594 (defun gnus-article-wash-status ()
2595 "Return a string which display status of article washing."
2597 (set-buffer gnus-article-buffer)
2598 (let ((cite (gnus-article-hidden-text-p 'cite))
2599 (headers (gnus-article-hidden-text-p 'headers))
2600 (boring (gnus-article-hidden-text-p 'boring-headers))
2601 (pgp (gnus-article-hidden-text-p 'pgp))
2602 (pem (gnus-article-hidden-text-p 'pem))
2603 (signature (gnus-article-hidden-text-p 'signature))
2604 (overstrike (gnus-article-hidden-text-p 'overstrike))
2605 (emphasis (gnus-article-hidden-text-p 'emphasis))
2606 (mime gnus-show-mime))
2607 (format "%c%c%c%c%c%c%c"
2609 (if (or headers boring) ?h ? )
2610 (if (or pgp pem) ?p ? )
2611 (if signature ?s ? )
2612 (if overstrike ?o ? )
2614 (if emphasis ?e ? )))))
2616 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2618 (defun gnus-article-maybe-hide-headers ()
2619 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2620 Provided for backwards compatibility."
2621 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2623 (gnus-article-hide-headers)))
2627 (defun gnus-output-to-file (file-name)
2628 "Append the current article to a file named FILE-NAME."
2629 (let ((artbuf (current-buffer)))
2631 (insert-buffer-substring artbuf)
2632 ;; Append newline at end of the buffer as separator, and then
2634 (goto-char (point-max))
2636 (append-to-file (point-min) (point-max) file-name)
2639 (defun gnus-narrow-to-page (&optional arg)
2640 "Narrow the article buffer to a page.
2641 If given a numerical ARG, move forward ARG pages."
2643 (setq arg (if arg (prefix-numeric-value arg) 0))
2645 (set-buffer gnus-article-buffer)
2646 (goto-char (point-min))
2648 ;; Remove any old next/prev buttons.
2649 (when (gnus-visual-p 'page-marker)
2650 (let ((buffer-read-only nil))
2651 (gnus-remove-text-with-property 'gnus-prev)
2652 (gnus-remove-text-with-property 'gnus-next)))
2655 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2657 (re-search-forward page-delimiter nil 'move arg)))
2658 (goto-char (match-end 0)))
2661 (if (re-search-forward page-delimiter nil 'move)
2664 (when (and (gnus-visual-p 'page-marker)
2665 (not (= (point-min) 1)))
2667 (goto-char (point-min))
2668 (gnus-insert-prev-page-button)))
2669 (when (and (gnus-visual-p 'page-marker)
2670 (< (+ (point-max) 2) (buffer-size)))
2672 (goto-char (point-max))
2673 (gnus-insert-next-page-button)))))
2675 ;; Article mode commands
2677 (defun gnus-article-goto-next-page ()
2678 "Show the next page of the article."
2680 (when (gnus-article-next-page)
2681 (goto-char (point-min))
2682 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2684 (defun gnus-article-goto-prev-page ()
2685 "Show the next page of the article."
2687 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2688 (gnus-article-prev-page nil)))
2690 (defun gnus-article-next-page (&optional lines)
2691 "Show the next page of the current article.
2692 If end of article, return non-nil. Otherwise return nil.
2693 Argument LINES specifies lines to be scrolled up."
2695 (move-to-window-line -1)
2698 (and (pos-visible-in-window-p) ;Not continuation line.
2700 ;; Nothing in this page.
2701 (if (or (not gnus-page-broken)
2704 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2706 (gnus-narrow-to-page 1) ;Go to next page.
2708 ;; More in this page.
2709 (let ((scroll-in-place nil))
2713 ;; Long lines may cause an end-of-buffer error.
2714 (goto-char (point-max)))))
2715 (move-to-window-line 0)
2718 (defun gnus-article-prev-page (&optional lines)
2719 "Show previous page of current article.
2720 Argument LINES specifies lines to be scrolled down."
2722 (move-to-window-line 0)
2723 (if (and gnus-page-broken
2725 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2727 (gnus-narrow-to-page -1) ;Go to previous page.
2728 (goto-char (point-max))
2730 (let ((scroll-in-place nil))
2734 (beginning-of-buffer
2735 (goto-char (point-min))))
2736 (move-to-window-line 0)))))
2738 (defun gnus-article-refer-article ()
2739 "Read article specified by message-id around point."
2741 (let ((point (point)))
2742 (search-forward ">" nil t) ;Move point to end of "<....>".
2743 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2744 (let ((message-id (match-string 1)))
2746 (set-buffer gnus-summary-buffer)
2747 (gnus-summary-refer-article message-id))
2749 (error "No references around point"))))
2751 (defun gnus-article-show-summary ()
2752 "Reconfigure windows to show summary buffer."
2754 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2755 (error "There is no summary buffer for this article buffer")
2756 (gnus-article-set-globals)
2757 (gnus-configure-windows 'article)
2758 (gnus-summary-goto-subject gnus-current-article)
2759 (gnus-summary-position-point)))
2761 (defun gnus-article-describe-briefly ()
2762 "Describe article mode commands briefly."
2765 (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")))
2767 (defun gnus-article-summary-command ()
2768 "Execute the last keystroke in the summary buffer."
2770 (let ((obuf (current-buffer))
2771 (owin (current-window-configuration))
2773 (switch-to-buffer gnus-article-current-summary 'norecord)
2774 (setq func (lookup-key (current-local-map) (this-command-keys)))
2775 (call-interactively func)
2777 (set-window-configuration owin)
2778 (set-window-point (get-buffer-window (current-buffer)) (point))))
2780 (defun gnus-article-summary-command-nosave ()
2781 "Execute the last keystroke in the summary buffer."
2784 (pop-to-buffer gnus-article-current-summary 'norecord)
2785 (setq func (lookup-key (current-local-map) (this-command-keys)))
2786 (call-interactively func)))
2788 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2789 "Read a summary buffer key sequence and execute it from the article buffer."
2792 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2793 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2794 "=" "^" "\M-^" "|"))
2800 '("n" "Gn" "p" "Gp"))
2803 (set-buffer gnus-article-current-summary)
2804 (let (gnus-pick-mode)
2805 (push (or key last-command-event) unread-command-events)
2806 (setq keys (read-key-sequence nil))))
2809 (if (or (member keys nosaves)
2810 (member keys nosave-but-article)
2811 (member keys nosave-in-article))
2813 (save-window-excursion
2814 (pop-to-buffer gnus-article-current-summary 'norecord)
2815 ;; We disable the pick minor mode commands.
2816 (let (gnus-pick-mode)
2817 (setq func (lookup-key (current-local-map) keys))))
2820 (unless (member keys nosave-in-article)
2821 (set-buffer gnus-article-current-summary))
2822 (call-interactively func)
2823 (setq new-sum-point (point)))
2824 (when (member keys nosave-but-article)
2825 (pop-to-buffer gnus-article-buffer 'norecord)))
2826 ;; These commands should restore window configuration.
2827 (let ((obuf (current-buffer))
2828 (owin (current-window-configuration))
2830 (summary gnus-article-current-summary)
2831 func in-buffer selected)
2832 (if not-restore-window
2833 (pop-to-buffer summary 'norecord)
2834 (switch-to-buffer summary 'norecord))
2835 (setq in-buffer (current-buffer))
2836 ;; We disable the pick minor mode commands.
2837 (if (setq func (let (gnus-pick-mode)
2838 (lookup-key (current-local-map) keys)))
2840 (call-interactively func)
2841 (setq new-sum-point (point)))
2843 (when (eq in-buffer (current-buffer))
2844 (setq selected (gnus-summary-select-article))
2846 (unless not-restore-window
2847 (set-window-configuration owin))
2848 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2849 (set-window-point (get-buffer-window (current-buffer))
2851 (let ((win (get-buffer-window gnus-article-current-summary)))
2853 (set-window-point win new-sum-point))))))))
2855 (defun gnus-article-hide (&optional arg force)
2856 "Hide all the gruft in the current article.
2857 This means that PGP stuff, signatures, cited text and (some)
2858 headers will be hidden.
2859 If given a prefix, show the hidden text instead."
2860 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2861 (gnus-article-hide-headers arg)
2862 (gnus-article-hide-pgp arg)
2863 (gnus-article-hide-citation-maybe arg force)
2864 (gnus-article-hide-signature arg))
2866 (defun gnus-article-maybe-highlight ()
2867 "Do some article highlighting if article highlighting is requested."
2868 (when (gnus-visual-p 'article-highlight 'highlight)
2869 (gnus-article-highlight-some)))
2871 (defun gnus-check-group-server ()
2872 ;; Make sure the connection to the server is alive.
2873 (unless (gnus-server-opened
2874 (gnus-find-method-for-group gnus-newsgroup-name))
2875 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2876 (gnus-request-group gnus-newsgroup-name t)))
2878 (defun gnus-request-article-this-buffer (article group)
2879 "Get an article and insert it into this buffer."
2880 (let (do-update-line sparse-header)
2884 (gnus-kill-all-overlays)
2885 (setq group (or group gnus-newsgroup-name))
2887 ;; Using `gnus-request-article' directly will insert the article into
2888 ;; `nntp-server-buffer' - so we'll save some time by not having to
2889 ;; copy it from the server buffer into the article buffer.
2891 ;; We only request an article by message-id when we do not have the
2892 ;; headers for it, so we'll have to get those.
2893 (when (stringp article)
2894 (let ((gnus-override-method gnus-refer-article-method))
2895 (gnus-read-header article)))
2897 ;; If the article number is negative, that means that this article
2898 ;; doesn't belong in this newsgroup (possibly), so we find its
2899 ;; message-id and request it by id instead of number.
2900 (when (and (numberp article)
2902 (get-buffer gnus-summary-buffer)
2903 (gnus-buffer-exists-p gnus-summary-buffer))
2905 (set-buffer gnus-summary-buffer)
2906 (let ((header (gnus-summary-article-header article)))
2909 ((memq article gnus-newsgroup-sparse)
2910 ;; This is a sparse gap article.
2911 (setq do-update-line article)
2912 (setq article (mail-header-id header))
2913 (let ((gnus-override-method gnus-refer-article-method))
2914 (setq sparse-header (gnus-read-header article)))
2915 (setq gnus-newsgroup-sparse
2916 (delq article gnus-newsgroup-sparse)))
2918 ;; It's a real article.
2919 (setq article (mail-header-id header)))
2921 ;; It is an extracted pseudo-article.
2922 (setq article 'pseudo)
2923 (gnus-request-pseudo-article header))))
2925 (let ((method (gnus-find-method-for-group
2926 gnus-newsgroup-name)))
2927 (when (and (eq (car method) 'nneething)
2930 (file-name-as-directory
2931 (or (cadr (assq 'nneething-address method))
2933 (mail-header-subject header))))
2934 (when (file-directory-p dir)
2935 (setq article 'nneething)
2936 (gnus-group-enter-directory dir))))))))
2939 ;; Refuse to select canceled articles.
2940 ((and (numberp article)
2942 (get-buffer gnus-summary-buffer)
2943 (gnus-buffer-exists-p gnus-summary-buffer)
2944 (eq (cdr (save-excursion
2945 (set-buffer gnus-summary-buffer)
2946 (assq article gnus-newsgroup-reads)))
2947 gnus-canceled-mark))
2949 ;; Check the backlog.
2950 ((and gnus-keep-backlog
2951 (gnus-backlog-request-article group article (current-buffer)))
2953 ;; Check asynchronous pre-fetch.
2954 ((gnus-async-request-fetched-article group article (current-buffer))
2955 (gnus-async-prefetch-next group article gnus-summary-buffer)
2956 (when (and (numberp article) gnus-keep-backlog)
2957 (gnus-backlog-enter-article group article (current-buffer)))
2960 ((and gnus-use-cache
2962 (gnus-cache-request-article article group))
2964 ;; Get the article and put into the article buffer.
2965 ((or (stringp article) (numberp article))
2966 (let ((gnus-override-method
2967 (and (stringp article) gnus-refer-article-method))
2968 (buffer-read-only nil))
2970 (gnus-kill-all-overlays)
2971 (gnus-check-group-server)
2972 (when (gnus-request-article article group (current-buffer))
2973 (when (numberp article)
2974 (gnus-async-prefetch-next group article gnus-summary-buffer)
2975 (when gnus-keep-backlog
2976 (gnus-backlog-enter-article
2977 group article (current-buffer))))
2982 ;; Associate this article with the current summary buffer.
2983 (setq gnus-article-current-summary gnus-summary-buffer)
2985 ;; Take the article from the original article buffer
2986 ;; and place it in the buffer it's supposed to be in.
2987 (when (and (get-buffer gnus-article-buffer)
2988 (equal (buffer-name (current-buffer))
2989 (buffer-name (get-buffer gnus-article-buffer))))
2991 (if (get-buffer gnus-original-article-buffer)
2992 (set-buffer gnus-original-article-buffer)
2993 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2994 (buffer-disable-undo)
2995 (setq major-mode 'gnus-original-article-mode)
2996 (setq buffer-read-only t))
2997 (let (buffer-read-only)
2999 (insert-buffer-substring gnus-article-buffer))
3000 (setq gnus-original-article (cons group article)))
3003 (run-hooks 'gnus-article-decode-hook)
3004 ;; Mark article as decoded or not.
3005 (setq gnus-article-decoded-p gnus-article-decode-hook))
3007 ;; Update sparse articles.
3008 (when (and do-update-line
3009 (or (numberp article)
3011 (let ((buf (current-buffer)))
3012 (set-buffer gnus-summary-buffer)
3013 (gnus-summary-update-article do-update-line sparse-header)
3014 (gnus-summary-goto-subject do-update-line nil t)
3015 (set-window-point (get-buffer-window (current-buffer) t)
3017 (set-buffer buf))))))
3023 (defcustom gnus-article-edit-mode-hook nil
3024 "Hook run in article edit mode buffers."
3025 :group 'gnus-article-various
3028 (defcustom gnus-article-edit-article-setup-function
3029 'gnus-article-mime-edit-article-setup
3030 "Function called to setup an editing article buffer."
3031 :group 'gnus-article-various
3034 (defvar gnus-article-edit-done-function nil)
3036 (defvar gnus-article-edit-mode-map nil)
3038 ;; Should we be using derived.el for this?
3039 (unless gnus-article-edit-mode-map
3040 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3041 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3043 (gnus-define-keys gnus-article-edit-mode-map
3044 "\C-c\C-c" gnus-article-edit-done
3045 "\C-c\C-k" gnus-article-edit-exit)
3047 (gnus-define-keys (gnus-article-edit-wash-map
3048 "\C-c\C-w" gnus-article-edit-mode-map)
3049 "f" gnus-article-edit-full-stops))
3051 (defun gnus-article-edit-mode ()
3052 "Major mode for editing articles.
3053 This is an extended text-mode.
3055 \\{gnus-article-edit-mode-map}"
3057 (setq major-mode 'gnus-article-edit-mode)
3058 (setq mode-name "Article Edit")
3059 (use-local-map gnus-article-edit-mode-map)
3060 (make-local-variable 'gnus-article-edit-done-function)
3061 (make-local-variable 'gnus-prev-winconf)
3062 (setq buffer-read-only nil)
3063 (buffer-enable-undo)
3065 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3067 (defun gnus-article-edit (&optional force)
3068 "Edit the current article.
3069 This will have permanent effect only in mail groups.
3070 If FORCE is non-nil, allow editing of articles even in read-only
3073 (when (and (not force)
3074 (gnus-group-read-only-p))
3075 (error "The current newsgroup does not support article editing"))
3076 (gnus-article-date-original)
3077 (gnus-article-edit-article
3078 `(lambda (no-highlight)
3079 (gnus-summary-edit-article-done
3080 ,(or (mail-header-references gnus-current-headers) "")
3081 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3083 (defun gnus-article-edit-article (exit-func)
3084 "Start editing the contents of the current article buffer."
3085 (let ((winconf (current-window-configuration)))
3086 (set-buffer gnus-article-buffer)
3087 (gnus-article-edit-mode)
3088 (gnus-article-delete-text-of-type 'annotation)
3089 (gnus-set-text-properties (point-min) (point-max) nil)
3090 (gnus-configure-windows 'edit-article)
3091 (setq gnus-article-edit-done-function exit-func)
3092 (setq gnus-prev-winconf winconf)
3093 (when gnus-article-edit-article-setup-function
3094 (funcall gnus-article-edit-article-setup-function))
3095 (gnus-message 6 "C-c C-c to end edits")))
3097 (defun gnus-article-edit-done (&optional arg)
3098 "Update the article edits and exit."
3103 (goto-char (point-min))
3104 (when (search-forward "\n\n" nil 1)
3105 (let ((lines (count-lines (point) (point-max)))
3106 (length (- (point-max) (point)))
3107 (case-fold-search t)
3108 (body (copy-marker (point))))
3109 (goto-char (point-min))
3110 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3111 (delete-region (match-beginning 1) (match-end 1))
3112 (insert (number-to-string length)))
3113 (goto-char (point-min))
3114 (when (re-search-forward
3115 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3116 (delete-region (match-beginning 1) (match-end 1))
3117 (insert (number-to-string length)))
3118 (goto-char (point-min))
3119 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3120 (delete-region (match-beginning 1) (match-end 1))
3121 (insert (number-to-string lines)))))))
3122 (let ((func gnus-article-edit-done-function)
3123 (buf (current-buffer))
3124 (start (window-start)))
3125 (remove-hook 'gnus-article-mode-hook
3126 'gnus-article-mime-edit-article-unwind)
3127 (gnus-article-edit-exit)
3130 (let ((buffer-read-only nil))
3132 ;; The cache and backlog have to be flushed somewhat.
3133 (when gnus-keep-backlog
3134 (gnus-backlog-remove-article
3135 (car gnus-article-current) (cdr gnus-article-current)))
3136 ;; Flush original article as well.
3138 (when (get-buffer gnus-original-article-buffer)
3139 (set-buffer gnus-original-article-buffer)
3140 (setq gnus-original-article nil)))
3141 (when gnus-use-cache
3142 (gnus-cache-update-article
3143 (car gnus-article-current) (cdr gnus-article-current))))
3145 (set-window-start (get-buffer-window buf) start)
3146 (set-window-point (get-buffer-window buf) (point))))
3148 (defun gnus-article-edit-exit ()
3149 "Exit the article editing without updating."
3151 ;; We remove all text props from the article buffer.
3152 (let ((buf (format "%s" (buffer-string)))
3153 (curbuf (current-buffer))
3155 (window-start (window-start)))
3158 (let ((winconf gnus-prev-winconf))
3160 (set-window-configuration winconf)
3161 ;; Tippy-toe some to make sure that point remains where it was.
3162 (save-current-buffer
3164 (set-window-start (get-buffer-window (current-buffer)) window-start)
3167 (defun gnus-article-edit-full-stops ()
3168 "Interactively repair spacing at end of sentences."
3171 (goto-char (point-min))
3172 (search-forward-regexp "^$" nil t)
3173 (let ((case-fold-search nil))
3174 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3177 ;;; Article editing with MIME-Edit
3180 (defcustom gnus-article-mime-edit-article-setup-hook nil
3181 "Hook run after setting up a MIME editing article buffer."
3182 :group 'gnus-article-various
3185 (defun gnus-article-mime-edit-article-unwind ()
3186 "Unwind `gnus-article-buffer' if article editing was given up."
3187 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3188 (when mime-edit-mode-flag
3189 (mime-edit-exit 'nomime 'no-error)
3191 (when (featurep 'font-lock)
3192 (setq font-lock-defaults nil)
3193 (font-lock-mode 0)))
3195 (defun gnus-article-mime-edit-article-setup ()
3196 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3197 after replacing with the original article."
3198 (setq gnus-show-mime t)
3199 (setq gnus-article-edit-done-function
3200 `(lambda (&rest args)
3201 (when mime-edit-mode-flag
3204 (goto-char (point-min))
3205 (let (case-fold-search)
3206 (when (re-search-forward
3207 (format "^%s$" (regexp-quote mail-header-separator))
3209 (replace-match "")))
3210 (when (featurep 'font-lock)
3211 (setq font-lock-defaults nil)
3213 (apply ,gnus-article-edit-done-function args)
3214 (set-buffer gnus-original-article-buffer)
3216 (insert-buffer gnus-article-buffer)
3217 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3218 (gnus-article-prepare-display)))
3219 (substitute-key-definition
3220 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3221 gnus-article-edit-mode-map)
3223 (insert-buffer gnus-original-article-buffer)
3225 (when (featurep 'font-lock)
3226 (set (make-local-variable 'font-lock-defaults)
3227 '(message-font-lock-keywords t))
3228 (font-lock-set-defaults)
3229 (turn-on-font-lock))
3230 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3231 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3233 (defun gnus-article-mime-edit-exit ()
3234 "Exit the article MIME editing without updating."
3236 (let ((winconf gnus-prev-winconf)
3238 (when mime-edit-mode-flag
3241 (goto-char (point-min))
3242 (let (case-fold-search)
3243 (when (re-search-forward
3244 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3245 (replace-match "")))
3246 (when (featurep 'font-lock)
3247 (setq font-lock-defaults nil)
3249 ;; We remove all text props from the article buffer.
3250 (setq buf (format "%s" (buffer-string)))
3251 (set-buffer (get-buffer-create gnus-original-article-buffer))
3254 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3255 (gnus-article-prepare-display)
3256 (set-window-configuration winconf)))
3259 ;;; Article highlights
3262 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3264 ;;; Internal Variables:
3266 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)"
3267 "Regular expression that matches URLs."
3268 :group 'gnus-article-buttons
3271 (defcustom gnus-button-alist
3272 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
3273 gnus-button-message-id 2)
3274 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
3275 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3277 gnus-button-fetch-group 4)
3278 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3279 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3280 t gnus-button-message-id 3)
3281 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3282 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3283 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3284 ;; This is how URLs _should_ be embedded in text...
3285 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3287 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3288 "*Alist of regexps matching buttons in article bodies.
3290 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3291 REGEXP: is the string matching text around the button,
3292 BUTTON: is the number of the regexp grouping actually matching the button,
3293 FORM: is a lisp expression which must eval to true for the button to
3295 CALLBACK: is the function to call when the user push this button, and each
3296 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3298 CALLBACK can also be a variable, in that case the value of that
3299 variable it the real callback function."
3300 :group 'gnus-article-buttons
3301 :type '(repeat (list regexp
3302 (integer :tag "Button")
3304 (function :tag "Callback")
3307 (integer :tag "Regexp group")))))
3309 (defcustom gnus-header-button-alist
3310 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3311 0 t gnus-button-message-id 0)
3312 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3313 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3314 0 t gnus-button-mailto 0)
3315 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3316 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3317 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3318 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3319 gnus-button-message-id 3))
3320 "*Alist of headers and regexps to match buttons in article heads.
3322 This alist is very similar to `gnus-button-alist', except that each
3323 alist has an additional HEADER element first in each entry:
3325 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3327 HEADER is a regexp to match a header. For a fuller explanation, see
3328 `gnus-button-alist'."
3329 :group 'gnus-article-buttons
3330 :group 'gnus-article-headers
3331 :type '(repeat (list (regexp :tag "Header")
3333 (integer :tag "Button")
3335 (function :tag "Callback")
3338 (integer :tag "Regexp group")))))
3340 (defvar gnus-button-regexp nil)
3341 (defvar gnus-button-marker-list nil)
3342 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3344 (defvar gnus-button-last nil)
3345 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3349 (defun gnus-article-push-button (event)
3350 "Check text under the mouse pointer for a callback function.
3351 If the text under the mouse pointer has a `gnus-callback' property,
3352 call it with the value of the `gnus-data' text property."
3354 (set-buffer (window-buffer (posn-window (event-start event))))
3355 (let* ((pos (posn-point (event-start event)))
3356 (data (get-text-property pos 'gnus-data))
3357 (fun (get-text-property pos 'gnus-callback)))
3360 (funcall fun data))))
3362 (defun gnus-article-press-button ()
3363 "Check text at point for a callback function.
3364 If the text at point has a `gnus-callback' property,
3365 call it with the value of the `gnus-data' text property."
3367 (let* ((data (get-text-property (point) 'gnus-data))
3368 (fun (get-text-property (point) 'gnus-callback)))
3370 (funcall fun data))))
3372 (defun gnus-article-prev-button (n)
3373 "Move point to N buttons backward.
3374 If N is negative, move forward instead."
3376 (gnus-article-next-button (- n)))
3378 (defun gnus-article-next-button (n)
3379 "Move point to N buttons forward.
3380 If N is negative, move backward instead."
3382 (let ((function (if (< n 0) 'previous-single-property-change
3383 'next-single-property-change))
3384 (inhibit-point-motion-hooks t)
3386 (limit (if (< n 0) (point-min) (point-max))))
3388 (while (and (not (= limit (point)))
3390 ;; Skip past the current button.
3391 (when (get-text-property (point) 'gnus-callback)
3392 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3393 ;; Go to the next (or previous) button.
3394 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
3395 ;; Put point at the start of the button.
3396 (when (and backward (not (get-text-property (point) 'gnus-callback)))
3397 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3398 ;; Skip past intangible buttons.
3399 (when (get-text-property (point) 'intangible)
3403 (gnus-message 5 "No more buttons"))
3406 (defun gnus-article-highlight (&optional force)
3407 "Highlight current article.
3408 This function calls `gnus-article-highlight-headers',
3409 `gnus-article-highlight-citation',
3410 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3411 do the highlighting. See the documentation for those functions."
3412 (interactive (list 'force))
3413 (gnus-article-highlight-headers)
3414 (gnus-article-highlight-citation force)
3415 (gnus-article-highlight-signature)
3416 (gnus-article-add-buttons force)
3417 (gnus-article-add-buttons-to-head))
3419 (defun gnus-article-highlight-some (&optional force)
3420 "Highlight current article.
3421 This function calls `gnus-article-highlight-headers',
3422 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3423 do the highlighting. See the documentation for those functions."
3424 (interactive (list 'force))
3425 (gnus-article-highlight-headers)
3426 (gnus-article-highlight-signature)
3427 (gnus-article-add-buttons))
3429 (defun gnus-article-highlight-headers ()
3430 "Highlight article headers as specified by `gnus-header-face-alist'."
3433 (set-buffer gnus-article-buffer)
3435 (let ((alist gnus-header-face-alist)
3436 (buffer-read-only nil)
3437 (case-fold-search t)
3438 (inhibit-point-motion-hooks t)
3439 entry regexp header-face field-face from hpoints fpoints)
3440 (message-narrow-to-head)
3441 (while (setq entry (pop alist))
3442 (goto-char (point-min))
3443 (setq regexp (concat "^\\("
3444 (if (string-equal "" (nth 0 entry))
3448 header-face (nth 1 entry)
3449 field-face (nth 2 entry))
3450 (while (and (re-search-forward regexp nil t)
3454 (unless (search-forward ":" nil t)
3456 (when (and header-face
3457 (not (memq (point) hpoints)))
3458 (push (point) hpoints)
3459 (gnus-put-text-property from (point) 'face header-face))
3460 (when (and field-face
3461 (not (memq (setq from (point)) fpoints)))
3463 (if (re-search-forward "^[^ \t]" nil t)
3465 (goto-char (point-max)))
3466 (gnus-put-text-property from (point) 'face field-face))))))))
3468 (defun gnus-article-highlight-signature ()
3469 "Highlight the signature in an article.
3470 It does this by highlighting everything after
3471 `gnus-signature-separator' using `gnus-signature-face'."
3474 (set-buffer gnus-article-buffer)
3475 (let ((buffer-read-only nil)
3476 (inhibit-point-motion-hooks t))
3478 (when (and gnus-signature-face
3479 (gnus-article-narrow-to-signature))
3480 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3481 'face gnus-signature-face)
3483 (gnus-article-search-signature)
3484 (let ((start (match-beginning 0))
3485 (end (set-marker (make-marker) (1+ (match-end 0)))))
3486 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3489 (defun gnus-button-in-region-p (b e prop)
3490 "Say whether PROP exists in the region."
3491 (text-property-not-all b e prop nil))
3493 (defun gnus-article-add-buttons (&optional force)
3494 "Find external references in the article and make buttons of them.
3495 \"External references\" are things like Message-IDs and URLs, as
3496 specified by `gnus-button-alist'."
3497 (interactive (list 'force))
3499 (set-buffer gnus-article-buffer)
3500 (let ((buffer-read-only nil)
3501 (inhibit-point-motion-hooks t)
3502 (case-fold-search t)
3503 (alist gnus-button-alist)
3505 ;; Remove all old markers.
3507 (while (setq marker (pop gnus-button-marker-list))
3509 (when (setq entry (gnus-button-entry))
3510 (put-text-property (match-beginning (nth 1 entry))
3511 (match-end (nth 1 entry))
3512 'gnus-callback nil))
3513 (set-marker marker nil)))
3514 ;; We skip the headers.
3515 (goto-char (point-min))
3516 (unless (search-forward "\n\n" nil t)
3517 (goto-char (point-max)))
3519 (while (setq entry (pop alist))
3520 (setq regexp (car entry))
3522 (while (re-search-forward regexp nil t)
3523 (let* ((start (and entry (match-beginning (nth 1 entry))))
3524 (end (and entry (match-end (nth 1 entry))))
3525 (from (match-beginning 0)))
3526 (when (and (or (eq t (nth 2 entry))
3527 (eval (nth 2 entry)))
3528 (not (gnus-button-in-region-p
3529 start end 'gnus-callback)))
3530 ;; That optional form returned non-nil, so we add the
3532 (gnus-article-add-button
3533 start end 'gnus-button-push
3534 (car (push (set-marker (make-marker) from)
3535 gnus-button-marker-list))))))))))
3537 ;; Add buttons to the head of an article.
3538 (defun gnus-article-add-buttons-to-head ()
3539 "Add buttons to the head of the article."
3542 (set-buffer gnus-article-buffer)
3543 (let ((buffer-read-only nil)
3544 (inhibit-point-motion-hooks t)
3545 (case-fold-search t)
3546 (alist gnus-header-button-alist)
3548 (nnheader-narrow-to-headers)
3550 ;; Each alist entry.
3551 (setq entry (car alist)
3553 (goto-char (point-min))
3554 (while (re-search-forward (car entry) nil t)
3555 ;; Each header matching the entry.
3556 (setq beg (match-beginning 0))
3557 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3558 (match-beginning 0))
3561 (while (re-search-forward (nth 1 entry) end t)
3562 ;; Each match within a header.
3563 (let* ((entry (cdr entry))
3564 (start (match-beginning (nth 1 entry)))
3565 (end (match-end (nth 1 entry)))
3566 (form (nth 2 entry)))
3567 (goto-char (match-end 0))
3569 (gnus-article-add-button
3570 start end (nth 3 entry)
3571 (buffer-substring (match-beginning (nth 4 entry))
3572 (match-end (nth 4 entry)))))))
3576 ;;; External functions:
3578 (defun gnus-article-add-button (from to fun &optional data)
3579 "Create a button between FROM and TO with callback FUN and data DATA."
3580 (when gnus-article-button-face
3581 (gnus-overlay-put (gnus-make-overlay from to)
3582 'face gnus-article-button-face))
3583 (gnus-add-text-properties
3585 (nconc (and gnus-article-mouse-face
3586 (list gnus-mouse-face-prop gnus-article-mouse-face))
3587 (list 'gnus-callback fun)
3588 (and data (list 'gnus-data data)))))
3590 ;;; Internal functions:
3592 (defun gnus-article-set-globals ()
3594 (set-buffer gnus-summary-buffer)
3595 (gnus-set-global-variables)))
3597 (defun gnus-signature-toggle (end)
3599 (set-buffer gnus-article-buffer)
3600 (let ((buffer-read-only nil)
3601 (inhibit-point-motion-hooks t))
3602 (if (get-text-property end 'invisible)
3603 (gnus-article-unhide-text end (point-max))
3604 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3606 (defun gnus-button-entry ()
3607 ;; Return the first entry in `gnus-button-alist' matching this place.
3608 (let ((alist gnus-button-alist)
3611 (setq entry (pop alist))
3612 (if (looking-at (car entry))
3617 (defun gnus-button-push (marker)
3618 ;; Push button starting at MARKER.
3621 (let* ((entry (gnus-button-entry))
3622 (inhibit-point-motion-hooks t)
3624 (args (mapcar (lambda (group)
3625 (let ((string (match-string group)))
3626 (gnus-set-text-properties
3627 0 (length string) nil string)
3634 (fboundp (symbol-value fun)))
3635 (apply (symbol-value fun) args))
3637 (gnus-message 1 "You must define `%S' to use this button"
3638 (cons fun args)))))))
3640 (defun gnus-button-message-id (message-id)
3643 (set-buffer gnus-summary-buffer)
3644 (gnus-summary-refer-article message-id)))
3646 (defun gnus-button-fetch-group (address)
3647 "Fetch GROUP specified by ADDRESS."
3648 (if (not (string-match "[:/]" address))
3649 ;; This is just a simple group url.
3650 (gnus-group-read-ephemeral-group address gnus-select-method)
3651 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3653 (error "Can't parse %s" address)
3654 (gnus-group-read-ephemeral-group
3655 (match-string 4 address)
3656 `(nntp ,(match-string 1 address)
3657 (nntp-address ,(match-string 1 address))
3658 (nntp-port-number ,(if (match-end 3)
3659 (match-string 3 address)
3662 (defun gnus-url-parse-query-string (query &optional downcase)
3663 (let (retval pairs cur key val)
3664 (setq pairs (split-string query "&"))
3666 (setq cur (car pairs)
3668 (if (not (string-match "=" cur))
3670 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3671 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3673 (setq key (downcase key)))
3674 (setq cur (assoc key retval))
3676 (setcdr cur (cons val (cdr cur)))
3677 (setq retval (cons (list key val) retval)))))
3680 (defun gnus-url-unhex (x)
3687 (defun gnus-url-unhex-string (str &optional allow-newlines)
3688 "Remove %XXX embedded spaces, etc in a url.
3689 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3690 decoding of carriage returns and line feeds in the string, which is normally
3691 forbidden in URL encoding."
3692 (setq str (or str ""))
3694 (case-fold-search t))
3695 (while (string-match "%[0-9a-f][0-9a-f]" str)
3696 (let* ((start (match-beginning 0))
3697 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3699 (gnus-url-unhex (elt str (+ start 2))))))
3701 tmp (substring str 0 start)
3704 (char-to-string code))
3705 ((or (= code ?\n) (= code ?\r))
3707 (t (char-to-string code))))
3708 str (substring str (match-end 0)))))
3709 (setq tmp (concat tmp str))
3712 (defun gnus-url-mailto (url)
3713 ;; Send mail to someone
3714 (when (string-match "mailto:/*\\(.*\\)" url)
3715 (setq url (substring url (match-beginning 1) nil)))
3716 (let (to args subject func)
3717 (if (string-match (regexp-quote "?") url)
3718 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3719 args (gnus-url-parse-query-string
3720 (substring url (match-end 0) nil) t))
3721 (setq to (gnus-url-unhex-string url)))
3722 (setq args (cons (list "to" to) args)
3723 subject (cdr-safe (assoc "subject" args)))
3724 (gnus-setup-message 'reply
3727 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3730 (message-position-on-field (caar args)))
3731 (insert (mapconcat 'identity (cdar args) ", "))
3732 (setq args (cdr args)))
3735 (message-goto-subject)))))
3737 (defun gnus-button-mailto (address)
3739 (set-buffer (gnus-copy-article-buffer))
3740 (gnus-setup-message 'reply
3741 (message-reply address)))
3743 (defun gnus-button-reply (address)
3744 ;; Reply to ADDRESS.
3745 (gnus-setup-message 'reply
3746 (message-reply address)))
3748 (defun gnus-button-url (address)
3750 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3751 (if (listp browse-url-browser-function)
3752 (browse-url address)
3753 (funcall browse-url-browser-function address)))
3755 (defun gnus-button-embedded-url (address)
3757 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3758 (if (listp browse-url-browser-function)
3759 (browse-url (gnus-strip-whitespace address))
3760 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3762 ;;; Next/prev buttons in the article buffer.
3764 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3765 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3767 (defvar gnus-prev-page-map nil)
3768 (unless gnus-prev-page-map
3769 (setq gnus-prev-page-map (make-sparse-keymap))
3770 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3771 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3773 (defun gnus-insert-prev-page-button ()
3774 (let ((buffer-read-only nil))
3776 gnus-prev-page-line-format nil
3777 `(gnus-prev t local-map ,gnus-prev-page-map
3778 gnus-callback gnus-article-button-prev-page
3779 article-type annotation))))
3781 (defvar gnus-next-page-map nil)
3782 (unless gnus-next-page-map
3783 (setq gnus-next-page-map (make-keymap))
3784 (suppress-keymap gnus-prev-page-map)
3785 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3786 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3788 (defun gnus-button-next-page ()
3789 "Go to the next page."
3791 (let ((win (selected-window)))
3792 (select-window (get-buffer-window gnus-article-buffer t))
3793 (gnus-article-next-page)
3794 (select-window win)))
3796 (defun gnus-button-prev-page ()
3797 "Go to the prev page."
3799 (let ((win (selected-window)))
3800 (select-window (get-buffer-window gnus-article-buffer t))
3801 (gnus-article-prev-page)
3802 (select-window win)))
3804 (defun gnus-insert-next-page-button ()
3805 (let ((buffer-read-only nil))
3806 (gnus-eval-format gnus-next-page-line-format nil
3808 t local-map ,gnus-next-page-map
3809 gnus-callback gnus-article-button-next-page
3810 article-type annotation))))
3812 (defun gnus-article-button-next-page (arg)
3813 "Go to the next page."
3815 (let ((win (selected-window)))
3816 (select-window (get-buffer-window gnus-article-buffer t))
3817 (gnus-article-next-page)
3818 (select-window win)))
3820 (defun gnus-article-button-prev-page (arg)
3821 "Go to the prev page."
3823 (let ((win (selected-window)))
3824 (select-window (get-buffer-window gnus-article-buffer t))
3825 (gnus-article-prev-page)
3826 (select-window win)))
3828 (defvar gnus-decode-header-methods
3829 '(mail-decode-encoded-word-region)
3830 "List of methods used to decode headers
3832 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
3833 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
3834 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
3835 whose names match REGEXP.
3838 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
3839 mail-decode-encoded-word-region
3840 (\"chinese\" . rfc1843-decode-region))
3843 (defvar gnus-decode-header-methods-cache nil)
3845 (defun gnus-multi-decode-header (start end)
3846 "Apply the functions from `gnus-encoded-word-methods' that match."
3847 (unless (and gnus-decode-header-methods-cache
3848 (eq gnus-newsgroup-name
3849 (car gnus-decode-header-methods-cache)))
3850 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
3853 (nconc gnus-decode-header-methods-cache (list x))
3854 (if (and gnus-newsgroup-name
3855 (string-match (car x) gnus-newsgroup-name))
3856 (nconc gnus-decode-header-methods-cache
3858 gnus-decode-header-methods))
3859 (let ((xlist gnus-decode-header-methods-cache))
3862 (narrow-to-region start end)
3864 (funcall (pop xlist) (point-min) (point-max))))))
3870 (defun gnus-article-header-presentation-method (entity situation)
3871 (mime-insert-decoded-header entity)
3874 (set-alist 'mime-header-presentation-method-alist
3875 'gnus-original-article-mode
3876 #'gnus-article-header-presentation-method)
3878 (defun gnus-mime-preview-quitting-method ()
3880 (gnus-article-show-summary)
3881 (mime-preview-kill-buffer)
3882 (delete-other-windows)
3883 (gnus-article-show-summary)
3884 (gnus-summary-select-article nil t)
3887 (set-alist 'mime-preview-quitting-method-alist
3888 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
3890 (defun gnus-following-method (buf)
3893 (message-yank-original)
3895 (goto-char (point-min))
3898 (set-alist 'mime-preview-following-method-alist
3899 'gnus-original-article-mode #'gnus-following-method)
3909 (run-hooks 'gnus-art-load-hook)
3911 ;;; gnus-art.el ends here