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%m"
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-mime
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."
596 :group 'gnus-article-mime
597 :type '(repeat regexp))
599 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
600 "List of MIME types that should not be given buttons when rendered."
601 :group 'gnus-article-mime
602 :type '(repeat regexp))
604 (defcustom gnus-treat-body-highlight-signature t
605 "Highlight the signature."
607 :type '(choice (const :tag "Off" nil)
609 (const :tag "Last" last)
610 (integer :tag "Less")
611 (sexp :tag "Predicate")))
613 (defcustom gnus-article-mime-part-function nil
614 "Function called with a MIME handle as the argument."
615 :group 'gnus-article-mime
618 ;;; Internal variables
620 (defvar gnus-article-mime-handle-alist-1 nil)
621 (defvar gnus-treatment-function-alist
622 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
625 (defvar gnus-article-mime-handle-alist nil)
626 (defvar article-lapsed-timer nil)
627 (defvar gnus-article-current-summary nil)
629 (defvar gnus-article-mode-syntax-table
630 (let ((table (copy-syntax-table text-mode-syntax-table)))
631 (modify-syntax-entry ?- "w" table)
632 (modify-syntax-entry ?> ")" table)
633 (modify-syntax-entry ?< "(" table)
635 "Syntax table used in article mode buffers.
636 Initialized from `text-mode-syntax-table.")
638 (defvar gnus-save-article-buffer nil)
640 (defvar gnus-article-mode-line-format-alist
641 (nconc '((?w (gnus-article-wash-status) ?s)
642 (?m (gnus-article-mime-part-status) ?s))
643 gnus-summary-mode-line-format-alist))
645 (defvar gnus-number-of-articles-to-be-saved nil)
647 (defvar gnus-inhibit-hiding nil)
649 (defsubst gnus-article-hide-text (b e props)
650 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
651 (add-text-properties b e props)
652 (when (memq 'intangible props)
654 (max (1- b) (point-min))
655 b 'intangible (cddr (memq 'intangible props)))))
657 (defsubst gnus-article-unhide-text (b e)
658 "Remove hidden text properties from region between B and E."
659 (remove-text-properties b e gnus-hidden-properties)
660 (when (memq 'intangible gnus-hidden-properties)
661 (put-text-property (max (1- b) (point-min))
664 (defun gnus-article-hide-text-type (b e type)
665 "Hide text of TYPE between B and E."
666 (gnus-article-hide-text
667 b e (cons 'article-type (cons type gnus-hidden-properties))))
669 (defun gnus-article-unhide-text-type (b e type)
670 "Unhide text of TYPE between B and E."
671 (remove-text-properties
672 b e (cons 'article-type (cons type gnus-hidden-properties)))
673 (when (memq 'intangible gnus-hidden-properties)
674 (put-text-property (max (1- b) (point-min))
677 (defun gnus-article-hide-text-of-type (type)
678 "Hide text of TYPE in the current buffer."
680 (let ((b (point-min))
682 (while (setq b (text-property-any b e 'article-type type))
683 (add-text-properties b (incf b) gnus-hidden-properties)))))
685 (defun gnus-article-delete-text-of-type (type)
686 "Delete text of TYPE in the current buffer."
688 (let ((b (point-min)))
689 (while (setq b (text-property-any b (point-max) 'article-type type))
691 b (or (text-property-not-all b (point-max) 'article-type type)
694 (defun gnus-article-delete-invisible-text ()
695 "Delete all invisible text in the current buffer."
697 (let ((b (point-min)))
698 (while (setq b (text-property-any b (point-max) 'invisible t))
700 b (or (text-property-not-all b (point-max) 'invisible t)
703 (defun gnus-article-text-type-exists-p (type)
704 "Say whether any text of type TYPE exists in the buffer."
705 (text-property-any (point-min) (point-max) 'article-type type))
707 (defsubst gnus-article-header-rank ()
708 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
709 (let ((list gnus-sorted-header-list)
712 (when (looking-at (car list))
714 (setq list (cdr list))
718 (defun article-hide-headers (&optional arg delete)
719 "Toggle whether to hide unwanted headers and possibly sort them as well.
720 If given a negative prefix, always show; if given a positive prefix,
722 (interactive (gnus-article-hidden-arg))
724 (if (gnus-article-check-hidden-text 'headers arg)
725 ;; Show boring headers as well.
726 (gnus-article-show-hidden-text 'boring-headers)
727 ;; This function might be inhibited.
728 (unless gnus-inhibit-hiding
731 (let ((buffer-read-only nil)
733 (props (nconc (list 'article-type 'headers)
734 gnus-hidden-properties))
735 (max (1+ (length gnus-sorted-header-list)))
736 (ignored (when (not gnus-visible-headers)
737 (cond ((stringp gnus-ignored-headers)
738 gnus-ignored-headers)
739 ((listp gnus-ignored-headers)
740 (mapconcat 'identity gnus-ignored-headers
743 (cond ((stringp gnus-visible-headers)
744 gnus-visible-headers)
745 ((and gnus-visible-headers
746 (listp gnus-visible-headers))
747 (mapconcat 'identity gnus-visible-headers "\\|"))))
748 (inhibit-point-motion-hooks t)
750 ;; First we narrow to just the headers.
752 (goto-char (point-min))
753 ;; Hide any "From " lines at the beginning of (mail) articles.
754 (while (looking-at "From ")
758 (delete-region (point-min) (point))
759 (gnus-article-hide-text (point-min) (point) props)))
760 ;; Then treat the rest of the header lines.
763 (if (search-forward "\n\n" nil t) ; if there's a body
764 (progn (forward-line -1) (point))
766 ;; Then we use the two regular expressions
767 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
768 ;; select which header lines is to remain visible in the
770 (goto-char (point-min))
771 (while (re-search-forward "^[^ \t]*:" nil t)
773 ;; Mark the rank of the header.
775 (point) (1+ (point)) 'message-rank
776 (if (or (and visible (looking-at visible))
778 (not (looking-at ignored))))
779 (gnus-article-header-rank)
782 (message-sort-headers-1)
783 (when (setq beg (text-property-any
784 (point-min) (point-max) 'message-rank (+ 2 max)))
785 ;; We make the unwanted headers invisible.
787 (delete-region beg (point-max))
788 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
789 (gnus-article-hide-text-type beg (point-max) 'headers))
790 ;; Work around XEmacs lossage.
791 (put-text-property (point-min) beg 'invisible nil))))))))
793 (defun article-hide-boring-headers (&optional arg)
794 "Toggle hiding of headers that aren't very interesting.
795 If given a negative prefix, always show; if given a positive prefix,
797 (interactive (gnus-article-hidden-arg))
798 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
799 (not gnus-show-all-headers))
802 (let ((buffer-read-only nil)
803 (list gnus-boring-article-headers)
804 (inhibit-point-motion-hooks t)
806 (nnheader-narrow-to-headers)
808 (setq elem (pop list))
809 (goto-char (point-min))
811 ;; Hide empty headers.
813 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
815 (gnus-article-hide-text-type
816 (progn (beginning-of-line) (point))
819 (if (re-search-forward "^[^ \t]" nil t)
823 ;; Hide boring Newsgroups header.
824 ((eq elem 'newsgroups)
825 (when (equal (gnus-fetch-field "newsgroups")
826 (gnus-group-real-name
827 (if (boundp 'gnus-newsgroup-name)
830 (gnus-article-hide-header "newsgroups")))
831 ((eq elem 'followup-to)
832 (when (equal (message-fetch-field "followup-to")
833 (message-fetch-field "newsgroups"))
834 (gnus-article-hide-header "followup-to")))
836 (let ((from (message-fetch-field "from"))
837 (reply-to (message-fetch-field "reply-to")))
842 (nth 1 (funcall gnus-extract-address-components from))
843 (nth 1 (funcall gnus-extract-address-components reply-to)))))
844 (gnus-article-hide-header "reply-to"))))
846 (let ((date (message-fetch-field "date")))
848 (< (days-between (current-time-string) date)
850 (gnus-article-hide-header "date"))))
852 (let ((to (message-fetch-field "to")))
853 (when (> (length to) 1024)
854 (gnus-article-hide-header "to"))))
857 (goto-char (point-min))
858 (while (re-search-forward "^to:" nil t)
859 (setq to-count (1+ to-count)))
861 (while (> to-count 0)
862 (goto-char (point-min))
864 (re-search-forward "^to:" nil nil to-count)
866 (narrow-to-region (point) (point-max))
867 (gnus-article-hide-header "to"))
868 (setq to-count (1- to-count)))))))))))))
870 (defun gnus-article-hide-header (header)
872 (goto-char (point-min))
873 (when (re-search-forward (concat "^" header ":") nil t)
874 (gnus-article-hide-text-type
875 (progn (beginning-of-line) (point))
878 (if (re-search-forward "^[^ \t]" nil t)
883 (defun article-treat-dumbquotes ()
884 "Translate M******** sm*rtq**t*s into proper text."
886 (article-translate-strings gnus-article-dumbquotes-map))
888 (defun article-translate-characters (from to)
889 "Translate all characters in the body of the article according to FROM and TO.
890 FROM is a string of characters to translate from; to is a string of
891 characters to translate to."
893 (when (article-goto-body)
894 (let ((buffer-read-only nil)
895 (x (make-string 225 ?x))
897 (while (< (incf i) (length x))
900 (while (< i (length from))
901 (aset x (aref from i) (aref to i))
903 (translate-region (point) (point-max) x)))))
905 (defun article-translate-strings (map)
906 "Translate all string in the body of the article according to MAP.
907 MAP is an alist where the elements are on the form (\"from\" \"to\")."
909 (when (article-goto-body)
910 (let ((buffer-read-only nil)
912 (while (setq elem (pop map))
914 (while (search-forward (car elem) nil t)
915 (replace-match (cadr elem)))))))))
917 (defun article-treat-overstrike ()
918 "Translate overstrikes into bold text."
921 (when (article-goto-body)
922 (let ((buffer-read-only nil))
923 (while (search-forward "\b" nil t)
924 (let ((next (char-after))
925 (previous (char-after (- (point) 2))))
926 ;; We do the boldification/underlining by hiding the
927 ;; overstrikes and putting the proper text property
931 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
932 (put-text-property (point) (1+ (point)) 'face 'bold))
934 (gnus-article-hide-text-type
935 (1- (point)) (1+ (point)) 'overstrike)
937 (- (point) 2) (1- (point)) 'face 'underline))
939 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
941 (point) (1+ (point)) 'face 'underline)))))))))
943 (defun article-fill ()
944 "Format too long lines."
947 (let ((buffer-read-only nil))
951 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
952 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
953 (adaptive-fill-mode t))
955 (and (>= (current-column) (min fill-column (window-width)))
956 (/= (preceding-char) ?:)
957 (fill-paragraph nil))
960 (defun article-remove-cr ()
961 "Translate CRLF pairs into LF, and then CR into LF.."
964 (let ((buffer-read-only nil))
965 (goto-char (point-min))
966 (while (search-forward "\r$" nil t)
967 (replace-match "" t t))
968 (goto-char (point-min))
969 (while (search-forward "\r" nil t)
970 (replace-match "\n" t t)))))
972 (defun article-remove-trailing-blank-lines ()
973 "Remove all trailing blank lines from the article."
976 (let ((buffer-read-only nil))
977 (goto-char (point-max))
981 (while (and (not (bobp))
982 (looking-at "^[ \t]*$")
983 (not (gnus-annotation-in-region-p
984 (point) (gnus-point-at-eol))))
989 (defun article-display-x-face (&optional force)
990 "Look for an X-Face header and display it if present."
991 (interactive (list 'force))
993 ;; Delete the old process, if any.
994 (when (process-status "article-x-face")
995 (delete-process "article-x-face"))
996 (let ((inhibit-point-motion-hooks t)
1000 (nnheader-narrow-to-headers)
1001 (setq from (message-fetch-field "from"))
1002 (goto-char (point-min))
1003 (while (and gnus-article-x-face-command
1006 ;; Check whether this face is censored.
1007 (not gnus-article-x-face-too-ugly)
1008 (and gnus-article-x-face-too-ugly from
1009 (not (string-match gnus-article-x-face-too-ugly
1011 ;; Has to be present.
1012 (re-search-forward "^X-Face: " nil t))
1013 ;; This used to try to do multiple faces (`while' instead of
1014 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1015 ;; work (b) it can crash some versions of Emacs (c) are
1016 ;; multiple faces really something to encourage?
1017 (when (stringp gnus-article-x-face-command)
1019 ;; We now have the area of the buffer where the X-Face is stored.
1022 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1023 ;; We display the face.
1024 (if (symbolp gnus-article-x-face-command)
1025 ;; The command is a lisp function, so we call it.
1026 (if (gnus-functionp gnus-article-x-face-command)
1027 (funcall gnus-article-x-face-command beg end)
1028 (error "%s is not a function" gnus-article-x-face-command))
1029 ;; The command is a string, so we interpret the command
1030 ;; as a, well, command, and fork it off.
1031 (let ((process-connection-type nil))
1032 (process-kill-without-query
1034 "article-x-face" nil shell-file-name shell-command-switch
1035 gnus-article-x-face-command))
1036 (process-send-region "article-x-face" beg end)
1037 (process-send-eof "article-x-face"))))))))))
1039 (defun article-decode-mime-words ()
1040 "Decode all MIME-encoded words in the article."
1043 (set-buffer gnus-article-buffer)
1044 (let ((inhibit-point-motion-hooks t)
1046 (rfc2047-default-charset gnus-newsgroup-default-charset)
1047 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1048 (mail-decode-encoded-word-region (point-min) (point-max)))))
1050 (defun article-decode-charset (&optional prompt)
1051 "Decode charset-encoded text in the article.
1052 If PROMPT (the prefix), prompt for a coding system to use."
1056 (message-narrow-to-head)
1057 (let* ((inhibit-point-motion-hooks t)
1058 (case-fold-search t)
1059 (ct (message-fetch-field "Content-Type" t))
1060 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1061 (ctl (and ct (condition-case ()
1062 (mail-header-parse-content-type ct)
1066 (mm-read-coding-system "Charset to decode: "))
1068 (mail-content-type-get ctl 'charset))))
1069 (rfc2047-default-charset gnus-newsgroup-default-charset)
1070 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1072 (goto-char (point-max))
1075 (narrow-to-region (point) (point-max))
1076 (when (and (or (not ctl)
1077 (equal (car ctl) "text/plain"))
1080 charset (and cte (intern (downcase
1081 (gnus-strip-whitespace cte))))
1084 (defun article-decode-encoded-words ()
1085 "Remove encoded-word encoding from headers."
1086 (let (buffer-read-only)
1087 (let ((charset (save-excursion
1088 (set-buffer gnus-summary-buffer)
1089 default-mime-charset)))
1090 (mime-decode-header-in-buffer charset)
1093 (defun article-de-quoted-unreadable (&optional force)
1094 "Translate a quoted-printable-encoded article.
1095 If FORCE, decode the article whether it is marked as quoted-printable
1097 (interactive (list 'force))
1099 (let ((buffer-read-only nil)
1100 (type (gnus-fetch-field "content-transfer-encoding"))
1102 (or gnus-newsgroup-default-charset mm-default-coding-system))
1103 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1105 (and type (string-match "quoted-printable" (downcase type))))
1108 (narrow-to-region (point) (point-max))
1109 (quoted-printable-decode-region (point-min) (point-max))
1111 (mm-decode-body charset)))))))
1113 (defun article-hide-pgp (&optional arg)
1114 "Toggle hiding of any PGP headers and signatures in the current article.
1115 If given a negative prefix, always show; if given a positive prefix,
1117 (interactive (gnus-article-hidden-arg))
1118 (unless (gnus-article-check-hidden-text 'pgp arg)
1120 (let ((inhibit-point-motion-hooks t)
1121 buffer-read-only beg end)
1123 (goto-char (point-min))
1124 ;; Hide the "header".
1125 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1126 (delete-region (1+ (match-beginning 0)) (match-end 0))
1127 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1128 (when (looking-at "Hash:.*$")
1129 (delete-region (point) (1+ (gnus-point-at-eol))))
1131 ;; Hide the actual signature.
1132 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1133 (setq end (1+ (match-beginning 0)))
1136 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1138 ;; Perhaps we shouldn't hide to the end of the buffer
1139 ;; if there is no end to the signature?
1141 ;; Hide "- " PGP quotation markers.
1143 (narrow-to-region beg end)
1144 (goto-char (point-min))
1145 (while (re-search-forward "^- " nil t)
1147 (match-beginning 0) (match-end 0)))
1149 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1151 (defun article-hide-pem (&optional arg)
1152 "Toggle hiding of any PEM headers and signatures in the current article.
1153 If given a negative prefix, always show; if given a positive prefix,
1155 (interactive (gnus-article-hidden-arg))
1156 (unless (gnus-article-check-hidden-text 'pem arg)
1158 (let (buffer-read-only end)
1160 (goto-char (point-min))
1161 ;; hide the horrendously ugly "header".
1162 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1165 (setq end (1+ (match-beginning 0)))
1166 (gnus-article-hide-text-type
1168 (if (search-forward "\n\n" nil t)
1172 ;; hide the trailer as well
1173 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1176 (gnus-article-hide-text-type
1177 (match-beginning 0) (match-end 0) 'pem))))))
1179 (defun article-hide-signature (&optional arg)
1180 "Hide the signature in the current article.
1181 If given a negative prefix, always show; if given a positive prefix,
1183 (interactive (gnus-article-hidden-arg))
1184 (unless (gnus-article-check-hidden-text 'signature arg)
1187 (let ((buffer-read-only nil))
1188 (when (gnus-article-narrow-to-signature)
1189 (gnus-article-hide-text-type
1190 (point-min) (point-max) 'signature)))))))
1192 (defun article-strip-leading-blank-lines ()
1193 "Remove all blank lines from the beginning of the article."
1196 (let ((inhibit-point-motion-hooks t)
1198 (when (article-goto-body)
1199 (while (and (not (eobp))
1200 (looking-at "[ \t]*$"))
1201 (gnus-delete-line))))))
1203 (defun article-goto-body ()
1204 "Place point at the start of the body."
1205 (goto-char (point-min))
1206 (if (search-forward "\n\n" nil t)
1208 (goto-char (point-max))
1211 (defun article-strip-multiple-blank-lines ()
1212 "Replace consecutive blank lines with one empty line."
1215 (let ((inhibit-point-motion-hooks t)
1217 ;; First make all blank lines empty.
1219 (while (re-search-forward "^[ \t]+$" nil t)
1220 (unless (gnus-annotation-in-region-p
1221 (match-beginning 0) (match-end 0))
1222 (replace-match "" nil t)))
1223 ;; Then replace multiple empty lines with a single empty line.
1225 (while (re-search-forward "\n\n\n+" nil t)
1226 (unless (gnus-annotation-in-region-p
1227 (match-beginning 0) (match-end 0))
1228 (replace-match "\n\n" t t))))))
1230 (defun article-strip-leading-space ()
1231 "Remove all white space from the beginning of the lines in the article."
1234 (let ((inhibit-point-motion-hooks t)
1237 (while (re-search-forward "^[ \t]+" nil t)
1238 (replace-match "" t t)))))
1240 (defun article-strip-blank-lines ()
1241 "Strip leading, trailing and multiple blank lines."
1243 (article-strip-leading-blank-lines)
1244 (article-remove-trailing-blank-lines)
1245 (article-strip-multiple-blank-lines))
1247 (defun article-strip-all-blank-lines ()
1248 "Strip all blank lines."
1251 (let ((inhibit-point-motion-hooks t)
1254 (while (re-search-forward "^[ \t]*\n" nil t)
1255 (replace-match "" t t)))))
1257 (defun gnus-article-narrow-to-signature ()
1258 "Narrow to the signature; return t if a signature is found, else nil."
1260 (let ((inhibit-point-motion-hooks t))
1261 (when (gnus-article-search-signature)
1263 ;; Check whether we have some limits to what we consider
1264 ;; to be a signature.
1265 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1266 (list gnus-signature-limit)))
1268 (while (setq limit (pop limits))
1269 (if (or (and (integerp limit)
1270 (< (- (point-max) (point)) limit))
1272 (< (count-lines (point) (point-max)) limit))
1273 (and (gnus-functionp limit)
1275 (and (stringp limit)
1276 (not (re-search-forward limit nil t))))
1277 () ; This limit did not succeed.
1281 (narrow-to-region (point) (point-max))
1284 (defun gnus-article-search-signature ()
1285 "Search the current buffer for the signature separator.
1286 Put point at the beginning of the signature separator."
1287 (let ((cur (point)))
1288 (goto-char (point-max))
1289 (if (if (stringp gnus-signature-separator)
1290 (re-search-backward gnus-signature-separator nil t)
1291 (let ((seps gnus-signature-separator))
1293 (not (re-search-backward (car seps) nil t)))
1301 (autoload 'w3-display "w3-parse")
1302 (autoload 'w3-do-setup "w3" "" t)
1303 (autoload 'w3-region "w3-display" "" t))
1305 (defun gnus-article-treat-html ()
1308 (let ((cbuf (current-buffer)))
1309 (set-buffer gnus-article-buffer)
1310 (let (buf buffer-read-only b e)
1312 (goto-char (point-min))
1314 (if (search-forward "\n\n" nil t)
1317 (setq e (point-max)))
1319 (insert-buffer-substring gnus-article-buffer b e)
1321 (save-window-excursion
1322 (w3-region (point-min) (point-max))
1323 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1325 (delete-region (point-min) (point-max))
1328 (goto-char (point-min))
1329 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1330 (set-buffer cbuf))))
1332 (defun gnus-article-hidden-arg ()
1333 "Return the current prefix arg as a number, or 0 if no prefix."
1334 (list (if current-prefix-arg
1335 (prefix-numeric-value current-prefix-arg)
1338 (defun gnus-article-check-hidden-text (type arg)
1339 "Return nil if hiding is necessary.
1340 Arg can be nil or a number. Nil and positive means hide, negative
1341 means show, 0 means toggle."
1345 (let ((hide (gnus-article-hidden-text-p type)))
1351 (gnus-article-show-hidden-text type))
1353 (if (eq hide 'hidden)
1354 (gnus-article-show-hidden-text type)
1357 (defun gnus-article-hidden-text-p (type)
1358 "Say whether the current buffer contains hidden text of type TYPE."
1359 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1361 (not (get-text-property pos 'invisible)))
1363 (text-property-any (1+ pos) (point-max) 'article-type type)))
1368 (defun gnus-article-show-hidden-text (type &optional hide)
1369 "Show all hidden text of type TYPE.
1370 If HIDE, hide the text instead."
1372 (let ((buffer-read-only nil)
1373 (inhibit-point-motion-hooks t)
1376 (while (setq beg (text-property-any end (point-max) 'article-type type))
1379 (text-property-not-all beg (point-max) 'article-type type)
1382 (gnus-article-hide-text beg end gnus-hidden-properties)
1383 (gnus-article-unhide-text beg end))
1387 (defconst article-time-units
1388 `((year . ,(* 365.25 24 60 60))
1389 (week . ,(* 7 24 60 60))
1390 (day . ,(* 24 60 60))
1394 "Mapping from time units to seconds.")
1396 (defun article-date-ut (&optional type highlight header)
1397 "Convert DATE date to universal time in the current article.
1398 If TYPE is `local', convert to local time; if it is `lapsed', output
1399 how much time has lapsed since DATE."
1400 (interactive (list 'ut t))
1401 (let* ((header (or header
1402 (mail-header-date gnus-current-headers)
1403 (message-fetch-field "date")
1405 (date (if (vectorp header) (mail-header-date header)
1407 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1408 (inhibit-point-motion-hooks t)
1409 bface eface newline)
1410 (when (and date (not (string= date "")))
1413 (nnheader-narrow-to-headers)
1414 (let ((buffer-read-only nil))
1415 ;; Delete any old Date headers.
1416 (if (re-search-forward date-regexp nil t)
1418 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1419 eface (get-text-property (1- (gnus-point-at-eol))
1421 (delete-region (progn (beginning-of-line) (point))
1422 (progn (end-of-line) (point)))
1423 (beginning-of-line))
1424 (goto-char (point-max))
1426 (insert (article-make-date-line date type))
1429 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1430 (put-text-property (match-beginning 1) (1+ (match-end 1))
1432 (put-text-property (match-beginning 2) (match-end 2)
1436 (insert "\n"))))))))
1438 (defun article-make-date-line (date type)
1439 "Return a DATE line of TYPE."
1440 (let ((time (condition-case ()
1444 ;; Convert to the local timezone. We have to slap a
1445 ;; `condition-case' round the calls to the timezone
1446 ;; functions since they aren't particularly resistant to
1449 (let ((tz (car (current-time-zone))))
1450 (format "Date: %s %s%04d" (current-time-string time)
1451 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1452 ;; Convert to Universal Time.
1455 (current-time-string
1456 (let* ((e (parse-time-string date))
1457 (tm (apply 'encode-time e))
1459 (ls (- (cadr tm) (car (current-time-zone)))))
1460 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1461 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1464 ;; Get the original date from the article.
1465 ((eq type 'original)
1466 (concat "Date: " (if (string-match "\n+$" date)
1467 (substring date 0 (match-beginning 0))
1469 ;; Let the user define the format.
1471 (if (gnus-functionp gnus-article-time-format)
1472 (funcall gnus-article-time-format time)
1475 (format-time-string gnus-article-time-format time))))
1480 (format-time-string "%Y%M%DT%h%m%s" time)))
1481 ;; Do an X-Sent lapsed format.
1483 ;; If the date is seriously mangled, the timezone functions are
1484 ;; liable to bug out, so we ignore all errors.
1485 (let* ((now (current-time))
1486 (real-time (subtract-time now time))
1487 (real-sec (and real-time
1488 (+ (* (float (car real-time)) 65536)
1490 (sec (and real-time (abs real-sec)))
1500 ;; This is a bit convoluted, but basically we go
1501 ;; through the time units for years, weeks, etc,
1502 ;; and divide things to see whether that results
1503 ;; in positive answers.
1506 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1507 ;; The (remaining) seconds are too few to
1508 ;; be divided into this time unit.
1510 ;; It's big enough, so we output it.
1511 (setq sec (- sec (* num (cdr unit))))
1513 (concat (if prev ", " "") (int-to-string
1515 " " (symbol-name (car unit))
1516 (if (> num 1) "s" ""))
1518 article-time-units "")
1519 ;; If dates are odd, then it might appear like the
1520 ;; article was sent in the future.
1523 " in the future"))))))
1525 (error "Unknown conversion type: %s" type)))))
1527 (defun article-date-local (&optional highlight)
1528 "Convert the current article date to the local timezone."
1529 (interactive (list t))
1530 (article-date-ut 'local highlight))
1532 (defun article-date-original (&optional highlight)
1533 "Convert the current article date to what it was originally.
1534 This is only useful if you have used some other date conversion
1535 function and want to see what the date was before converting."
1536 (interactive (list t))
1537 (article-date-ut 'original highlight))
1539 (defun article-date-lapsed (&optional highlight)
1540 "Convert the current article date to time lapsed since it was sent."
1541 (interactive (list t))
1542 (article-date-ut 'lapsed highlight))
1544 (defun article-update-date-lapsed ()
1545 "Function to be run from a timer to update the lapsed time line."
1546 (let (deactivate-mark)
1551 (set-buffer (window-buffer w))
1552 (when (eq major-mode 'gnus-article-mode)
1553 (goto-char (point-min))
1554 (when (re-search-forward "^X-Sent:" nil t)
1555 (article-date-lapsed t)))))))))
1557 (defun gnus-start-date-timer (&optional n)
1558 "Start a timer to update the X-Sent header in the article buffers.
1559 The numerical prefix says how frequently (in seconds) the function
1564 (gnus-stop-date-timer)
1565 (setq article-lapsed-timer
1566 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1568 (defun gnus-stop-date-timer ()
1569 "Stop the X-Sent timer."
1571 (when article-lapsed-timer
1572 (nnheader-cancel-timer article-lapsed-timer)
1573 (setq article-lapsed-timer nil)))
1575 (defun article-date-user (&optional highlight)
1576 "Convert the current article date to the user-defined format.
1577 This format is defined by the `gnus-article-time-format' variable."
1578 (interactive (list t))
1579 (article-date-ut 'user highlight))
1581 (defun article-date-iso8601 (&optional highlight)
1582 "Convert the current article date to ISO8601."
1583 (interactive (list t))
1584 (article-date-ut 'iso8601 highlight))
1586 (defun article-show-all ()
1587 "Show all hidden text in the article buffer."
1590 (let ((buffer-read-only nil))
1591 (gnus-article-unhide-text (point-min) (point-max)))))
1593 (defun article-emphasize (&optional arg)
1594 "Emphasize text according to `gnus-emphasis-alist'."
1595 (interactive (gnus-article-hidden-arg))
1596 (unless (gnus-article-check-hidden-text 'emphasis arg)
1598 (let ((alist gnus-emphasis-alist)
1599 (buffer-read-only nil)
1600 (props (append '(article-type emphasis)
1601 gnus-hidden-properties))
1602 regexp elem beg invisible visible face)
1605 (while (setq elem (pop alist))
1607 (setq regexp (car elem)
1608 invisible (nth 1 elem)
1609 visible (nth 2 elem)
1611 (while (re-search-forward regexp nil t)
1612 (when (and (match-beginning visible) (match-beginning invisible))
1613 (gnus-article-hide-text
1614 (match-beginning invisible) (match-end invisible) props)
1615 (gnus-article-unhide-text-type
1616 (match-beginning visible) (match-end visible) 'emphasis)
1617 (gnus-put-text-property-excluding-newlines
1618 (match-beginning visible) (match-end visible) 'face face)
1619 (goto-char (match-end invisible)))))))))
1621 (defvar gnus-summary-article-menu)
1622 (defvar gnus-summary-post-menu)
1624 ;;; Saving functions.
1626 (defun gnus-article-save (save-buffer file &optional num)
1627 "Save the currently selected article."
1628 (unless gnus-save-all-headers
1629 ;; Remove headers according to `gnus-saved-headers'.
1630 (let ((gnus-visible-headers
1631 (or gnus-saved-headers gnus-visible-headers))
1632 (gnus-article-buffer save-buffer))
1634 (set-buffer save-buffer)
1635 (article-hide-headers 1 t))))
1636 (save-window-excursion
1637 (if (not gnus-default-article-saver)
1638 (error "No default saver is defined")
1639 ;; !!! Magic! The saving functions all save
1640 ;; `gnus-save-article-buffer' (or so they think), but we
1641 ;; bind that variable to our save-buffer.
1642 (set-buffer gnus-article-buffer)
1643 (let* ((gnus-save-article-buffer save-buffer)
1646 ((not gnus-prompt-before-saving) 'default)
1647 ((eq gnus-prompt-before-saving 'always) nil)
1649 (gnus-number-of-articles-to-be-saved
1650 (when (eq gnus-prompt-before-saving t)
1652 (set-buffer gnus-article-current-summary)
1653 (funcall gnus-default-article-saver filename)))))
1655 (defun gnus-read-save-file-name (prompt &optional filename
1656 function group headers variable)
1658 (funcall function group headers (symbol-value variable)))
1663 ((eq filename 'default)
1669 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1672 (if (and gnus-number-of-articles-to-be-saved
1673 (> gnus-number-of-articles-to-be-saved 1))
1674 (format "these %d articles"
1675 gnus-number-of-articles-to-be-saved)
1678 ;; Let the split methods have their say.
1680 ;; No split name was found.
1683 (concat prompt " (default "
1684 (file-name-nondirectory default-name) ") ")
1685 (file-name-directory default-name)
1687 ;; A single group name is returned.
1688 ((stringp split-name)
1690 (funcall function split-name headers
1691 (symbol-value variable)))
1693 (concat prompt " (default "
1694 (file-name-nondirectory default-name) ") ")
1695 (file-name-directory default-name)
1697 ;; A single split name was found
1698 ((= 1 (length split-name))
1699 (let* ((name (expand-file-name
1700 (car split-name) gnus-article-save-directory))
1701 (dir (cond ((file-directory-p name)
1702 (file-name-as-directory name))
1703 ((file-exists-p name) name)
1704 (t gnus-article-save-directory))))
1706 (concat prompt " (default " name ") ")
1708 ;; A list of splits was found.
1710 (setq split-name (nreverse split-name))
1712 (let ((file-name-history
1713 (nconc split-name file-name-history)))
1717 (concat prompt " (`M-p' for defaults) ")
1718 gnus-article-save-directory
1720 gnus-article-save-directory)))
1721 (car (push result file-name-history)))))))
1722 ;; Create the directory.
1723 (gnus-make-directory (file-name-directory file))
1724 ;; If we have read a directory, we append the default file name.
1725 (when (file-directory-p file)
1726 (setq file (concat (file-name-as-directory file)
1727 (file-name-nondirectory default-name))))
1728 ;; Possibly translate some characters.
1729 (nnheader-translate-file-chars file)))))
1730 (gnus-make-directory (file-name-directory result))
1731 (set variable result)))
1733 (defun gnus-article-archive-name (group)
1734 "Return the first instance of an \"Archive-name\" in the current buffer."
1735 (let ((case-fold-search t))
1736 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1737 (nnheader-concat gnus-article-save-directory
1738 (match-string 1)))))
1740 (defun gnus-article-nndoc-name (group)
1741 "If GROUP is an nndoc group, return the name of the parent group."
1742 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1743 (gnus-group-get-parameter group 'save-article-group)))
1745 (defun gnus-summary-save-in-rmail (&optional filename)
1746 "Append this article to Rmail file.
1747 Optional argument FILENAME specifies file name.
1748 Directory to save to is default to `gnus-article-save-directory'."
1749 (setq filename (gnus-read-save-file-name
1750 "Save %s in rmail file:" filename
1751 gnus-rmail-save-name gnus-newsgroup-name
1752 gnus-current-headers 'gnus-newsgroup-last-rmail))
1753 (gnus-eval-in-buffer-window gnus-save-article-buffer
1757 (gnus-output-to-rmail filename))))
1760 (defun gnus-summary-save-in-mail (&optional filename)
1761 "Append this article to Unix mail file.
1762 Optional argument FILENAME specifies file name.
1763 Directory to save to is default to `gnus-article-save-directory'."
1764 (setq filename (gnus-read-save-file-name
1765 "Save %s in Unix mail file:" filename
1766 gnus-mail-save-name gnus-newsgroup-name
1767 gnus-current-headers 'gnus-newsgroup-last-mail))
1768 (gnus-eval-in-buffer-window gnus-save-article-buffer
1772 (if (and (file-readable-p filename)
1773 (mail-file-babyl-p filename))
1774 (rmail-output-to-rmail-file filename t)
1775 (gnus-output-to-mail filename)))))
1778 (defun gnus-summary-save-in-file (&optional filename overwrite)
1779 "Append this article to file.
1780 Optional argument FILENAME specifies file name.
1781 Directory to save to is default to `gnus-article-save-directory'."
1782 (setq filename (gnus-read-save-file-name
1783 "Save %s in file:" filename
1784 gnus-file-save-name gnus-newsgroup-name
1785 gnus-current-headers 'gnus-newsgroup-last-file))
1786 (gnus-eval-in-buffer-window gnus-save-article-buffer
1790 (when (and overwrite
1791 (file-exists-p filename))
1792 (delete-file filename))
1793 (gnus-output-to-file filename))))
1796 (defun gnus-summary-write-to-file (&optional filename)
1797 "Write this article to a file.
1798 Optional argument FILENAME specifies file name.
1799 The directory to save in defaults to `gnus-article-save-directory'."
1800 (gnus-summary-save-in-file nil t))
1802 (defun gnus-summary-save-body-in-file (&optional filename)
1803 "Append this article body to a file.
1804 Optional argument FILENAME specifies file name.
1805 The directory to save in defaults to `gnus-article-save-directory'."
1806 (setq filename (gnus-read-save-file-name
1807 "Save %s body in file:" filename
1808 gnus-file-save-name gnus-newsgroup-name
1809 gnus-current-headers 'gnus-newsgroup-last-file))
1810 (gnus-eval-in-buffer-window gnus-save-article-buffer
1814 (when (article-goto-body)
1815 (narrow-to-region (point) (point-max)))
1816 (gnus-output-to-file filename))))
1819 (defun gnus-summary-save-in-pipe (&optional command)
1820 "Pipe this article to subprocess."
1822 (cond ((and (eq command 'default)
1823 gnus-last-shell-command)
1824 gnus-last-shell-command)
1828 "Shell command on %s: "
1829 (if (and gnus-number-of-articles-to-be-saved
1830 (> gnus-number-of-articles-to-be-saved 1))
1831 (format "these %d articles"
1832 gnus-number-of-articles-to-be-saved)
1834 gnus-last-shell-command))))
1835 (when (string-equal command "")
1836 (setq command gnus-last-shell-command))
1837 (gnus-eval-in-buffer-window gnus-article-buffer
1840 (shell-command-on-region (point-min) (point-max) command nil)))
1841 (setq gnus-last-shell-command command))
1843 ;;; Article file names when saving.
1845 (defun gnus-capitalize-newsgroup (newsgroup)
1846 "Capitalize NEWSGROUP name."
1847 (when (not (zerop (length newsgroup)))
1848 (concat (char-to-string (upcase (aref newsgroup 0)))
1849 (substring newsgroup 1))))
1851 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1852 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1853 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1854 Otherwise, it is like ~/News/news/group/num."
1857 (concat (if (gnus-use-long-file-name 'not-save)
1858 (gnus-capitalize-newsgroup newsgroup)
1859 (gnus-newsgroup-directory-form newsgroup))
1860 "/" (int-to-string (mail-header-number headers)))
1861 gnus-article-save-directory)))
1863 (string-equal (file-name-directory default)
1864 (file-name-directory last-file))
1865 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1867 (or last-file default))))
1869 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1870 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1871 If variable `gnus-use-long-file-name' is non-nil, it is
1872 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1875 (concat (if (gnus-use-long-file-name 'not-save)
1877 (gnus-newsgroup-directory-form newsgroup))
1878 "/" (int-to-string (mail-header-number headers)))
1879 gnus-article-save-directory)))
1881 (string-equal (file-name-directory default)
1882 (file-name-directory last-file))
1883 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1885 (or last-file default))))
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)
1894 (gnus-capitalize-newsgroup newsgroup)
1895 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1896 gnus-article-save-directory)))
1898 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1899 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1900 If variable `gnus-use-long-file-name' is non-nil, it is
1901 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1904 (if (gnus-use-long-file-name 'not-save)
1906 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1907 gnus-article-save-directory)))
1914 (setq afunc (car func)
1917 gfunc (intern (format "gnus-%s" func))))
1919 (if (not (fboundp afunc))
1921 `(lambda (&optional interactive &rest args)
1922 ,(documentation afunc t)
1923 (interactive (list t))
1925 (set-buffer gnus-article-buffer)
1927 (call-interactively ',afunc)
1928 (apply ',afunc args))))))))
1929 '(article-hide-headers
1930 article-hide-boring-headers
1931 article-treat-overstrike
1932 (article-fill . gnus-article-word-wrap)
1934 article-display-x-face
1937 article-hide-signature
1938 article-remove-trailing-blank-lines
1939 article-strip-leading-blank-lines
1940 article-strip-multiple-blank-lines
1941 article-strip-leading-space
1942 article-strip-blank-lines
1943 article-strip-all-blank-lines
1945 article-date-iso8601
1946 article-date-original
1951 article-treat-dumbquotes
1952 (article-show-all . gnus-article-show-all-headers))))
1955 ;;; Gnus article mode
1958 (put 'gnus-article-mode 'mode-class 'special)
1960 (gnus-define-keys gnus-article-mode-map
1961 " " gnus-article-goto-next-page
1962 "\177" gnus-article-goto-prev-page
1963 [delete] gnus-article-goto-prev-page
1964 "\C-c^" gnus-article-refer-article
1965 "h" gnus-article-show-summary
1966 "s" gnus-article-show-summary
1967 "\C-c\C-m" gnus-article-mail
1968 "?" gnus-article-describe-briefly
1969 gnus-mouse-2 gnus-article-push-button
1970 "\r" gnus-article-press-button
1971 "\t" gnus-article-next-button
1972 "\M-\t" gnus-article-prev-button
1973 "e" gnus-article-edit
1974 "<" beginning-of-buffer
1976 "\C-c\C-i" gnus-info-find-node
1979 "\C-d" gnus-article-read-summary-keys
1980 "\M-*" gnus-article-read-summary-keys
1981 "\M-#" gnus-article-read-summary-keys
1982 "\M-^" gnus-article-read-summary-keys
1983 "\M-g" gnus-article-read-summary-keys)
1985 (substitute-key-definition
1986 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1988 (defun gnus-article-make-menu-bar ()
1989 (gnus-turn-off-edit-menu 'article)
1990 (unless (boundp 'gnus-article-article-menu)
1992 gnus-article-article-menu gnus-article-mode-map ""
1994 ["Scroll forwards" gnus-article-goto-next-page t]
1995 ["Scroll backwards" gnus-article-goto-prev-page t]
1996 ["Show summary" gnus-article-show-summary t]
1997 ["Fetch Message-ID at point" gnus-article-refer-article t]
1998 ["Mail to address at point" gnus-article-mail t]
1999 ["Send a bug report" gnus-bug t]))
2002 gnus-article-treatment-menu gnus-article-mode-map ""
2004 ["Hide headers" gnus-article-hide-headers t]
2005 ["Hide signature" gnus-article-hide-signature t]
2006 ["Hide citation" gnus-article-hide-citation t]
2007 ["Treat overstrike" gnus-article-treat-overstrike t]
2008 ["Remove carriage return" gnus-article-remove-cr t]))
2010 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2012 (when (boundp 'gnus-summary-post-menu)
2013 (define-key gnus-article-mode-map [menu-bar post]
2014 (cons "Post" gnus-summary-post-menu)))
2016 (gnus-run-hooks 'gnus-article-menu-hook)))
2018 (defun gnus-article-mode ()
2019 "Major mode for displaying an article.
2021 All normal editing commands are switched off.
2023 The following commands are available in addition to all summary mode
2025 \\<gnus-article-mode-map>
2026 \\[gnus-article-next-page]\t Scroll the article one page forwards
2027 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2028 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2029 \\[gnus-article-show-summary]\t Display the summary buffer
2030 \\[gnus-article-mail]\t Send a reply to the address near point
2031 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2032 \\[gnus-info-find-node]\t Go to the Gnus info node"
2034 (when (gnus-visual-p 'article-menu 'menu)
2035 (gnus-article-make-menu-bar))
2036 (gnus-simplify-mode-line)
2037 (setq mode-name "Article")
2038 (setq major-mode 'gnus-article-mode)
2039 (make-local-variable 'minor-mode-alist)
2040 (unless (assq 'gnus-show-mime minor-mode-alist)
2041 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2042 (use-local-map gnus-article-mode-map)
2043 (gnus-update-format-specifications nil 'article-mode)
2044 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2045 (make-local-variable 'gnus-page-broken)
2046 (make-local-variable 'gnus-button-marker-list)
2047 (make-local-variable 'gnus-article-current-summary)
2048 (gnus-set-default-directory)
2049 (buffer-disable-undo)
2050 (setq buffer-read-only t)
2051 (set-syntax-table gnus-article-mode-syntax-table)
2052 (gnus-run-hooks 'gnus-article-mode-hook))
2054 (defun gnus-article-setup-buffer ()
2055 "Initialize the article buffer."
2056 (let* ((name (if gnus-single-article-buffer "*Article*"
2057 (concat "*Article " gnus-newsgroup-name "*")))
2059 (progn (string-match "\\*Article" name)
2060 (concat " *Original Article"
2061 (substring name (match-end 0))))))
2062 (setq gnus-article-buffer name)
2063 (setq gnus-original-article-buffer original)
2064 ;; This might be a variable local to the summary buffer.
2065 (unless gnus-single-article-buffer
2067 (set-buffer gnus-summary-buffer)
2068 (setq gnus-article-buffer name)
2069 (setq gnus-original-article-buffer original)
2070 (gnus-set-global-variables)))
2071 ;; Init original article buffer.
2073 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2074 (setq major-mode 'gnus-original-article-mode)
2075 (make-local-variable 'gnus-original-article))
2076 (if (get-buffer name)
2079 (buffer-disable-undo)
2080 (setq buffer-read-only t)
2081 (unless (eq major-mode 'gnus-article-mode)
2082 (gnus-article-mode))
2085 (set-buffer (gnus-get-buffer-create name))
2087 (make-local-variable 'gnus-summary-buffer)
2088 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2089 (current-buffer)))))
2091 ;; Set article window start at LINE, where LINE is the number of lines
2092 ;; from the head of the article.
2093 (defun gnus-article-set-window-start (&optional line)
2095 (get-buffer-window gnus-article-buffer t)
2097 (set-buffer gnus-article-buffer)
2098 (goto-char (point-min))
2101 (gnus-message 6 "Moved to bookmark")
2102 (search-forward "\n\n" nil t)
2106 ;;; @@ article filters
2109 (defun gnus-article-display-mime-message ()
2110 "Article display method for MIME message."
2111 ;; called from `gnus-original-article-buffer'.
2112 (let ((charset (with-current-buffer gnus-summary-buffer
2113 default-mime-charset)))
2114 (make-local-variable 'default-mime-charset)
2115 (setq default-mime-charset charset)
2116 (mime-display-message mime-message-structure
2117 gnus-article-buffer nil gnus-article-mode-map)
2118 (make-local-variable 'default-mime-charset)
2119 (setq default-mime-charset charset)
2121 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2122 (make-local-variable 'mime-button-mother-dispatcher)
2123 (setq mime-button-mother-dispatcher
2124 (function gnus-article-push-button))
2125 (run-hooks 'gnus-mime-article-prepare-hook))
2127 (defun gnus-article-display-traditional-message ()
2128 "Article display method for traditional message."
2129 (set-buffer gnus-article-buffer)
2130 (let (buffer-read-only)
2132 (insert-buffer-substring gnus-original-article-buffer)))
2134 (defun gnus-article-make-full-mail-header (&optional number charset)
2135 "Create a new mail header structure in a raw article buffer."
2136 (unless (and number charset)
2137 (save-current-buffer
2138 (set-buffer gnus-summary-buffer)
2140 (setq number (or (cdr gnus-article-current) 0)))
2142 (setq charset (or default-mime-charset 'x-ctext)))))
2143 (goto-char (point-min))
2144 (let ((header-end (if (search-forward "\n\n" nil t)
2146 (goto-char (point-max))))
2147 (chars (- (point-max) (point)))
2148 (lines (count-lines (point) (point-max)))
2149 (default-mime-charset charset)
2151 (narrow-to-region (point-min) header-end)
2152 (setq xref (std11-fetch-field "xref"))
2154 (make-full-mail-header
2156 (std11-fetch-field "subject")
2157 (std11-fetch-field "from")
2158 (std11-fetch-field "date")
2159 (std11-fetch-field "message-id")
2160 (std11-fetch-field "references")
2163 (when xref (concat "Xref: " xref)))
2166 (defun gnus-article-prepare (article &optional all-headers header)
2167 "Prepare ARTICLE in article mode buffer.
2168 ARTICLE should either be an article number or a Message-ID.
2169 If ARTICLE is an id, HEADER should be the article headers.
2170 If ALL-HEADERS is non-nil, no headers are hidden."
2172 ;; Make sure we start in a summary buffer.
2173 (unless (eq major-mode 'gnus-summary-mode)
2174 (set-buffer gnus-summary-buffer))
2175 (setq gnus-summary-buffer (current-buffer))
2176 (let* ((gnus-article (if header (mail-header-number header) article))
2177 (summary-buffer (current-buffer))
2178 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2179 (group gnus-newsgroup-name)
2182 (gnus-article-setup-buffer)
2183 (set-buffer gnus-original-article-buffer)
2184 ;; Deactivate active regions.
2185 (when (and (boundp 'transient-mark-mode)
2186 transient-mark-mode)
2187 (setq mark-active nil))
2188 (if (not (setq result (let ((buffer-read-only nil))
2189 (gnus-request-article-this-buffer
2191 ;; There is no such article.
2193 (when (and (numberp article)
2194 (not (memq article gnus-newsgroup-sparse)))
2195 (setq gnus-article-current
2196 (cons gnus-newsgroup-name article))
2197 (set-buffer gnus-summary-buffer)
2198 (setq gnus-current-article article)
2199 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2201 (gnus-summary-set-agent-mark article)
2202 (message "Message marked for downloading"))
2203 (gnus-summary-mark-article article gnus-canceled-mark)
2204 (unless (memq article gnus-newsgroup-sparse)
2206 "No such article (may have expired or been canceled)")))))
2207 (if (or (eq result 'pseudo)
2208 (eq result 'nneething))
2211 (set-buffer summary-buffer)
2212 (push article gnus-newsgroup-history)
2213 (setq gnus-last-article gnus-current-article
2214 gnus-current-article 0
2215 gnus-current-headers nil
2216 gnus-article-current nil)
2217 (if (eq result 'nneething)
2218 (gnus-configure-windows 'summary)
2219 (gnus-configure-windows 'article))
2220 (gnus-set-global-variables))
2221 (let ((gnus-article-mime-handle-alist-1
2222 gnus-article-mime-handle-alist))
2223 (gnus-set-mode-line 'article)))
2224 ;; The result from the `request' was an actual article -
2225 ;; or at least some text that is now displayed in the
2227 (when (and (numberp article)
2228 (not (eq article gnus-current-article)))
2229 ;; Seems like a new article has been selected.
2230 ;; `gnus-current-article' must be an article number.
2232 (set-buffer summary-buffer)
2233 (push article gnus-newsgroup-history)
2234 (setq gnus-last-article gnus-current-article
2235 gnus-current-article article
2236 gnus-current-headers
2237 (gnus-summary-article-header gnus-current-article)
2238 gnus-article-current
2239 (cons gnus-newsgroup-name gnus-current-article))
2240 (unless (vectorp gnus-current-headers)
2241 (setq gnus-current-headers nil))
2242 (gnus-summary-goto-subject gnus-current-article)
2243 (when (gnus-summary-show-thread)
2244 ;; If the summary buffer really was folded, the
2245 ;; previous goto may not actually have gone to
2246 ;; the right article, but the thread root instead.
2248 (gnus-summary-goto-subject gnus-current-article))
2249 (gnus-run-hooks 'gnus-mark-article-hook)
2250 (gnus-set-mode-line 'summary)
2251 (when (gnus-visual-p 'article-highlight 'highlight)
2252 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2253 ;; Set the global newsgroup variables here.
2254 ;; Suggested by Jim Sisolak
2255 ;; <sisolak@trans4.neep.wisc.edu>.
2256 (gnus-set-global-variables)
2257 (setq gnus-have-all-headers
2258 (or all-headers gnus-show-all-headers))))
2259 (when (or (numberp article)
2261 (gnus-article-prepare-display)
2263 (goto-char (point-min))
2264 (setq gnus-page-broken
2265 (when gnus-break-pages
2266 (gnus-narrow-to-page)
2268 (let ((gnus-article-mime-handle-alist-1
2269 gnus-article-mime-handle-alist))
2270 (gnus-set-mode-line 'article))
2271 (gnus-configure-windows 'article)
2273 (set-window-point (get-buffer-window (current-buffer)) (point))
2276 (defun gnus-article-prepare-display ()
2277 "Make the current buffer look like a nice article."
2281 (setq mime-message-structure gnus-current-headers)
2282 gnus-article-display-method-for-mime)
2283 gnus-article-display-method-for-traditional)))
2284 (gnus-run-hooks 'gnus-tmp-internal-hook)
2285 (gnus-run-hooks 'gnus-article-prepare-hook)
2288 ;; Associate this article with the current summary buffer.
2289 (setq gnus-article-current-summary (current-buffer))
2290 ;; Perform the article display hooks.
2291 (gnus-run-hooks 'gnus-article-display-hook)))
2294 ;;; Gnus MIME viewing functions
2297 (defvar gnus-mime-button-line-format "%{%([%p. %t%d%n]%)%}%e\n"
2298 "The following specs can be used:
2300 %n The `name' parameter
2301 %d The description, if any
2302 %l The length of the encoded part
2303 %p The part identifier
2304 %e Dots if the part isn't displayed")
2306 (defvar gnus-mime-button-line-format-alist
2307 '((?t gnus-tmp-type ?s)
2308 (?n gnus-tmp-name ?s)
2309 (?d gnus-tmp-description ?s)
2311 (?l gnus-tmp-length ?d)
2312 (?e gnus-tmp-dots ?s)))
2314 (defvar gnus-mime-button-commands
2315 '((gnus-article-press-button "\r" "Toggle Display")
2316 ;(gnus-mime-view-part "\M-\r" "View Interactively...")
2317 (gnus-mime-view-part "v" "View Interactively...")
2318 (gnus-mime-save-part "o" "Save...")
2319 (gnus-mime-copy-part "c" "View In Buffer")
2320 (gnus-mime-inline-part "i" "View Inline")
2321 (gnus-mime-externalize-part "e" "View Externally")
2322 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2324 (defun gnus-article-mime-part-status ()
2325 (if gnus-article-mime-handle-alist-1
2326 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2329 (defvar gnus-mime-button-map nil)
2330 (unless gnus-mime-button-map
2331 (setq gnus-mime-button-map (make-sparse-keymap))
2332 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2333 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2334 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2336 (define-key gnus-mime-button-map (cadr c) (car c)))
2337 gnus-mime-button-commands))
2339 (defun gnus-mime-button-menu (event)
2340 "Construct a context-sensitive menu of MIME commands."
2342 (gnus-article-check-buffer)
2343 (let ((response (x-popup-menu
2345 ("" ,@(mapcar (lambda (c)
2346 (cons (caddr c) (car c)))
2347 gnus-mime-button-commands)))))
2348 (pos (event-start event)))
2350 (set-buffer (window-buffer (posn-window pos)))
2351 (goto-char (posn-point pos))
2352 (funcall response))))
2354 (defun gnus-mime-view-all-parts ()
2355 "View all the MIME parts."
2357 (gnus-article-check-buffer)
2358 (let ((handles gnus-article-mime-handles)
2359 (rfc2047-default-charset gnus-newsgroup-default-charset)
2360 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2362 (mm-display-part (pop handles)))))
2364 (defun gnus-mime-save-part ()
2365 "Save the MIME part under point."
2367 (gnus-article-check-buffer)
2368 (let ((data (get-text-property (point) 'gnus-data)))
2369 (mm-save-part data)))
2371 (defun gnus-mime-pipe-part ()
2372 "Pipe the MIME part under point to a process."
2374 (gnus-article-check-buffer)
2375 (let ((data (get-text-property (point) 'gnus-data)))
2376 (mm-pipe-part data)))
2378 (defun gnus-mime-view-part ()
2379 "Interactively choose a view method for the MIME part under point."
2381 (gnus-article-check-buffer)
2382 (let ((data (get-text-property (point) 'gnus-data))
2383 (url-standalone-mode (not gnus-plugged)))
2384 (mm-interactively-view-part data)))
2386 (defun gnus-mime-copy-part (&optional handle)
2387 "Put the the MIME part under point into a new buffer."
2389 (gnus-article-check-buffer)
2390 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2391 (contents (mm-get-part handle))
2392 (buffer (generate-new-buffer
2393 (file-name-nondirectory
2395 (mail-content-type-get (mm-handle-type handle) 'name)
2396 (mail-content-type-get (mm-handle-type handle)
2399 (switch-to-buffer buffer)
2402 (goto-char (point-min))))
2404 (defun gnus-mime-inline-part (&optional charset)
2405 "Insert the MIME part under point into the current buffer."
2406 (interactive "P") ; For compatibility reasons we are not using "z".
2407 (gnus-article-check-buffer)
2408 (let* ((data (get-text-property (point) 'gnus-data))
2409 (contents (mm-get-part data))
2410 (url-standalone-mode (not gnus-plugged))
2413 (if (mm-handle-undisplayer data)
2414 (mm-remove-part data)
2417 (unless (symbolp charset)
2418 (setq charset (mm-read-coding-system "Charset: ")))
2419 (setq contents (mm-decode-coding-string contents charset)))
2420 (mm-insert-inline data contents)
2423 (defun gnus-mime-externalize-part (&optional handle)
2424 "Insert the MIME part under point into the current buffer."
2426 (gnus-article-check-buffer)
2427 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2428 (url-standalone-mode (not gnus-plugged))
2429 (mm-user-display-methods nil)
2430 (rfc2047-default-charset gnus-newsgroup-default-charset)
2431 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2432 (if (mm-handle-undisplayer handle)
2433 (mm-remove-part handle)
2434 (mm-display-part handle))))
2436 (defun gnus-article-part-wrapper (n function)
2437 (save-current-buffer
2438 (set-buffer gnus-article-buffer)
2439 (when (> n (length gnus-article-mime-handle-alist))
2440 (error "No such part"))
2441 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2442 (funcall function handle))))
2444 (defun gnus-article-pipe-part (n)
2445 "Pipe MIME part N, which is the numerical prefix."
2447 (gnus-article-part-wrapper n 'mm-pipe-part))
2449 (defun gnus-article-save-part (n)
2450 "Save MIME part N, which is the numerical prefix."
2452 (gnus-article-part-wrapper n 'mm-save-part))
2454 (defun gnus-article-interactively-view-part (n)
2455 "Pipe MIME part N, which is the numerical prefix."
2457 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2459 (defun gnus-article-copy-part (n)
2460 "Pipe MIME part N, which is the numerical prefix."
2462 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2464 (defun gnus-article-externalize-part (n)
2465 "Pipe MIME part N, which is the numerical prefix."
2467 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2469 (defun gnus-article-view-part (n)
2470 "View MIME part N, which is the numerical prefix."
2472 (save-current-buffer
2473 (set-buffer gnus-article-buffer)
2474 (when (> n (length gnus-article-mime-handle-alist))
2475 (error "No such part"))
2476 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2477 (when (gnus-article-goto-part n)
2478 (if (equal (car handle) "multipart/alternative")
2479 (gnus-article-press-button)
2480 (when (eq (gnus-mm-display-part handle) 'internal)
2481 (gnus-set-window-start)))))))
2483 (defun gnus-mm-display-part (handle)
2484 "Display HANDLE and fix MIME button."
2485 (let ((id (get-text-property (point) 'gnus-part))
2488 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2489 (gnus-insert-mime-button
2490 handle id (list (not (mm-handle-displayed-p handle))))
2492 (let ((window (selected-window))
2493 (rfc2047-default-charset gnus-newsgroup-default-charset)
2494 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2497 (let ((win (get-buffer-window (current-buffer) t)))
2499 (select-window win))
2502 (mm-display-part handle))
2503 (select-window window))))
2504 (goto-char point))))
2506 (defun gnus-article-goto-part (n)
2507 "Go to MIME part N."
2508 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2510 (goto-char point))))
2512 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2513 (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2514 (gnus-tmp-type (car (mm-handle-type handle)))
2515 (gnus-tmp-description (mm-handle-description handle))
2517 (if (if displayed (car displayed)
2518 (mm-handle-displayed-p handle))
2520 (gnus-tmp-length (save-excursion
2521 (set-buffer (mm-handle-buffer handle))
2526 (concat " (" gnus-tmp-name ")")
2528 (setq gnus-tmp-description
2529 (if gnus-tmp-description
2530 (concat " (" gnus-tmp-description ")")
2536 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2537 `(local-map ,gnus-mime-button-map
2538 keymap ,gnus-mime-button-map
2539 gnus-callback gnus-mm-display-part
2540 gnus-part ,gnus-tmp-id
2541 article-type annotation
2544 (widget-convert-button 'link b e :action 'gnus-widget-press-button
2545 :button-keymap gnus-mime-button-map)))
2547 (defun gnus-widget-press-button (elems el)
2548 (goto-char (widget-get elems :from))
2549 (let ((url-standalone-mode (not gnus-plugged)))
2550 (gnus-article-press-button)))
2552 (defun gnus-display-mime (&optional ihandles)
2553 "Insert MIME buttons in the buffer."
2554 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2555 handle name type b e display)
2557 ;; Top-level call; we clean up.
2558 (mm-destroy-parts gnus-article-mime-handles)
2559 (setq gnus-article-mime-handles handles
2560 gnus-article-mime-handle-alist nil)
2561 ;; We allow users to glean info from the handles.
2562 (when gnus-article-mime-part-function
2563 (gnus-mime-part-function handles)))
2565 (or (not (stringp (car handles)))
2568 ;; Clean up for mime parts.
2570 (delete-region (point) (point-max)))
2571 (if (stringp (car handles))
2572 (if (equal (car handles) "multipart/alternative")
2573 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2574 (push (cons id handles) gnus-article-mime-handle-alist)
2575 (gnus-mime-display-alternative (cdr handles) nil nil id))
2576 (gnus-mime-display-mixed (cdr handles)))
2577 (gnus-mime-display-single handles)))))
2579 (defun gnus-mime-part-function (handles)
2580 (if (stringp (car handles))
2581 (mapcar 'gnus-mime-part-function (cdr handles))
2582 (funcall gnus-article-mime-part-function handles)))
2584 (defun gnus-mime-display-mixed (handles)
2586 (while (setq handle (pop handles))
2587 (if (stringp (car handle))
2588 (if (equal (car handle) "multipart/alternative")
2589 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2590 (push (cons id handle) gnus-article-mime-handle-alist)
2591 (gnus-mime-display-alternative (cdr handle) nil nil id))
2592 (gnus-mime-display-mixed (cdr handle)))
2593 (gnus-mime-display-single handle)))))
2595 (defun gnus-mime-display-single (handle)
2596 (let ((type (car (mm-handle-type handle)))
2597 (ignored gnus-ignored-mime-types)
2603 (when (string-match (pop ignored) type)
2604 (throw 'ignored nil)))
2605 (if (and (mm-automatic-display-p type)
2606 (mm-inlinable-part-p type)
2607 (setq not-attachment
2608 (or (not (mm-handle-disposition handle))
2609 (equal (car (mm-handle-disposition handle))
2612 (when (equal (car (split-string type "/"))
2615 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2616 (push (cons id handle) gnus-article-mime-handle-alist)
2617 (when (or (not display)
2618 (not (gnus-unbuttonized-mime-type-p type)))
2619 (gnus-article-insert-newline)
2620 (gnus-insert-mime-button
2621 handle id (list (or display
2622 (and (not not-attachment) text))))
2623 (gnus-article-insert-newline)))
2624 (gnus-article-insert-newline)
2628 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2629 (mm-charset-iso-8859-1-forced
2630 gnus-newsgroup-iso-8859-1-forced))
2631 (mm-display-part handle t))
2632 (goto-char (point-max)))
2633 ((and text not-attachment)
2635 (gnus-article-insert-newline)
2636 (mm-insert-inline handle (mm-get-part handle))
2637 (goto-char (point-max))))))))
2639 (defun gnus-unbuttonized-mime-type-p (type)
2640 "Say whether TYPE is to be unbuttonized."
2642 (let ((types gnus-unbuttonized-mime-types))
2644 (when (string-match (pop types) type)
2645 (throw 'found t))))))
2647 (defun gnus-article-insert-newline ()
2648 "Insert a newline, but mark it as undeletable."
2649 (gnus-put-text-property
2650 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2652 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2653 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2656 handle buffer-read-only from props begend not-pref)
2657 (save-window-excursion
2660 (narrow-to-region (car ibegend)
2663 (goto-char (car ibegend))
2666 (delete-region (point-min) (point-max))
2667 (mm-remove-parts handles))
2668 (setq begend (list (point-marker)))
2670 (unless (setq not-pref (cadr (member preferred ihandles)))
2671 (setq not-pref (car ihandles)))
2673 (not (gnus-unbuttonized-mime-type-p
2674 "multipart/alternative")))
2675 (gnus-add-text-properties
2678 (insert (format "%d. " id))
2682 (unless ,(not ibegend)
2683 (setq gnus-article-mime-handle-alist
2684 ',gnus-article-mime-handle-alist))
2685 (gnus-mime-display-alternative
2686 ',ihandles ',not-pref ',begend ,id))
2687 local-map ,gnus-mime-button-map
2688 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2689 face ,gnus-article-button-face
2690 keymap ,gnus-mime-button-map
2693 (widget-convert-button 'link from (point)
2694 :action 'gnus-widget-press-button
2695 :button-keymap gnus-widget-button-keymap)
2697 (while (setq handle (pop handles))
2698 (gnus-add-text-properties
2701 (insert (format "[%c] %-18s"
2702 (if (equal handle preferred) ?* ? )
2703 (if (stringp (car handle))
2705 (car (mm-handle-type handle)))))
2709 (unless ,(not ibegend)
2710 (setq gnus-article-mime-handle-alist
2711 ',gnus-article-mime-handle-alist))
2712 (gnus-mime-display-alternative
2713 ',ihandles ',handle ',begend ,id))
2714 local-map ,gnus-mime-button-map
2715 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2716 face ,gnus-article-button-face
2717 keymap ,gnus-mime-button-map
2720 (widget-convert-button 'link from (point)
2721 :action 'gnus-widget-press-button
2722 :button-keymap gnus-widget-button-keymap)
2726 (if (stringp (car preferred))
2727 (gnus-display-mime preferred)
2728 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2729 (mm-charset-iso-8859-1-forced
2730 gnus-newsgroup-iso-8859-1-forced))
2731 (mm-display-part preferred)))
2732 (goto-char (point-max))
2733 (setcdr begend (point-marker)))))
2735 (goto-char point))))
2737 (defun gnus-article-wash-status ()
2738 "Return a string which display status of article washing."
2740 (set-buffer gnus-article-buffer)
2741 (let ((cite (gnus-article-hidden-text-p 'cite))
2742 (headers (gnus-article-hidden-text-p 'headers))
2743 (boring (gnus-article-hidden-text-p 'boring-headers))
2744 (pgp (gnus-article-hidden-text-p 'pgp))
2745 (pem (gnus-article-hidden-text-p 'pem))
2746 (signature (gnus-article-hidden-text-p 'signature))
2747 (overstrike (gnus-article-hidden-text-p 'overstrike))
2748 (emphasis (gnus-article-hidden-text-p 'emphasis))
2749 (mime gnus-show-mime))
2750 (format "%c%c%c%c%c%c%c"
2752 (if (or headers boring) ?h ? )
2753 (if (or pgp pem) ?p ? )
2754 (if signature ?s ? )
2755 (if overstrike ?o ? )
2757 (if emphasis ?e ? )))))
2759 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2761 (defun gnus-article-maybe-hide-headers ()
2762 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2763 Provided for backwards compatibility."
2764 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2766 (gnus-article-hide-headers)))
2770 (defun gnus-output-to-file (file-name)
2771 "Append the current article to a file named FILE-NAME."
2772 (let ((artbuf (current-buffer)))
2774 (insert-buffer-substring artbuf)
2775 ;; Append newline at end of the buffer as separator, and then
2777 (goto-char (point-max))
2779 (append-to-file (point-min) (point-max) file-name)
2782 (defun gnus-narrow-to-page (&optional arg)
2783 "Narrow the article buffer to a page.
2784 If given a numerical ARG, move forward ARG pages."
2786 (setq arg (if arg (prefix-numeric-value arg) 0))
2788 (set-buffer gnus-article-buffer)
2789 (goto-char (point-min))
2791 ;; Remove any old next/prev buttons.
2792 (when (gnus-visual-p 'page-marker)
2793 (let ((buffer-read-only nil))
2794 (gnus-remove-text-with-property 'gnus-prev)
2795 (gnus-remove-text-with-property 'gnus-next)))
2798 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2800 (re-search-forward page-delimiter nil 'move arg)))
2801 (goto-char (match-end 0)))
2804 (if (re-search-forward page-delimiter nil 'move)
2807 (when (and (gnus-visual-p 'page-marker)
2808 (not (= (point-min) 1)))
2810 (goto-char (point-min))
2811 (gnus-insert-prev-page-button)))
2812 (when (and (gnus-visual-p 'page-marker)
2813 (< (+ (point-max) 2) (buffer-size)))
2815 (goto-char (point-max))
2816 (gnus-insert-next-page-button)))))
2818 ;; Article mode commands
2820 (defun gnus-article-goto-next-page ()
2821 "Show the next page of the article."
2823 (when (gnus-article-next-page)
2824 (goto-char (point-min))
2825 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2827 (defun gnus-article-goto-prev-page ()
2828 "Show the next page of the article."
2830 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2831 (gnus-article-prev-page nil)))
2833 (defun gnus-article-next-page (&optional lines)
2834 "Show the next page of the current article.
2835 If end of article, return non-nil. Otherwise return nil.
2836 Argument LINES specifies lines to be scrolled up."
2838 (move-to-window-line -1)
2841 (and (pos-visible-in-window-p) ;Not continuation line.
2843 ;; Nothing in this page.
2844 (if (or (not gnus-page-broken)
2847 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2849 (gnus-narrow-to-page 1) ;Go to next page.
2851 ;; More in this page.
2852 (let ((scroll-in-place nil))
2856 ;; Long lines may cause an end-of-buffer error.
2857 (goto-char (point-max)))))
2858 (move-to-window-line 0)
2861 (defun gnus-article-prev-page (&optional lines)
2862 "Show previous page of current article.
2863 Argument LINES specifies lines to be scrolled down."
2865 (move-to-window-line 0)
2866 (if (and gnus-page-broken
2868 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2870 (gnus-narrow-to-page -1) ;Go to previous page.
2871 (goto-char (point-max))
2873 (let ((scroll-in-place nil))
2877 (beginning-of-buffer
2878 (goto-char (point-min))))
2879 (move-to-window-line 0)))))
2881 (defun gnus-article-refer-article ()
2882 "Read article specified by message-id around point."
2884 (let ((point (point)))
2885 (search-forward ">" nil t) ;Move point to end of "<....>".
2886 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2887 (let ((message-id (match-string 1)))
2889 (set-buffer gnus-summary-buffer)
2890 (gnus-summary-refer-article message-id))
2892 (error "No references around point"))))
2894 (defun gnus-article-show-summary ()
2895 "Reconfigure windows to show summary buffer."
2897 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2898 (error "There is no summary buffer for this article buffer")
2899 (gnus-article-set-globals)
2900 (gnus-configure-windows 'article)
2901 (gnus-summary-goto-subject gnus-current-article)
2902 (gnus-summary-position-point)))
2904 (defun gnus-article-describe-briefly ()
2905 "Describe article mode commands briefly."
2908 (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")))
2910 (defun gnus-article-summary-command ()
2911 "Execute the last keystroke in the summary buffer."
2913 (let ((obuf (current-buffer))
2914 (owin (current-window-configuration))
2916 (switch-to-buffer gnus-article-current-summary 'norecord)
2917 (setq func (lookup-key (current-local-map) (this-command-keys)))
2918 (call-interactively func)
2920 (set-window-configuration owin)
2921 (set-window-point (get-buffer-window (current-buffer)) (point))))
2923 (defun gnus-article-summary-command-nosave ()
2924 "Execute the last keystroke in the summary buffer."
2927 (pop-to-buffer gnus-article-current-summary 'norecord)
2928 (setq func (lookup-key (current-local-map) (this-command-keys)))
2929 (call-interactively func)))
2931 (defun gnus-article-check-buffer ()
2932 "Beep if not in an article buffer."
2933 (unless (equal major-mode 'gnus-article-mode)
2934 (error "Command invoked outside of a Gnus article buffer")))
2936 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2937 "Read a summary buffer key sequence and execute it from the article buffer."
2939 (gnus-article-check-buffer)
2941 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2942 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2943 "=" "^" "\M-^" "|"))
2949 '("n" "Gn" "p" "Gp"))
2952 (set-buffer gnus-article-current-summary)
2953 (let (gnus-pick-mode)
2954 (push (or key last-command-event) unread-command-events)
2955 (setq keys (read-key-sequence nil))))
2958 (if (or (member keys nosaves)
2959 (member keys nosave-but-article)
2960 (member keys nosave-in-article))
2962 (save-window-excursion
2963 (pop-to-buffer gnus-article-current-summary 'norecord)
2964 ;; We disable the pick minor mode commands.
2965 (let (gnus-pick-mode)
2966 (setq func (lookup-key (current-local-map) keys))))
2969 (unless (member keys nosave-in-article)
2970 (set-buffer gnus-article-current-summary))
2971 (call-interactively func)
2972 (setq new-sum-point (point)))
2973 (when (member keys nosave-but-article)
2974 (pop-to-buffer gnus-article-buffer 'norecord)))
2975 ;; These commands should restore window configuration.
2976 (let ((obuf (current-buffer))
2977 (owin (current-window-configuration))
2979 (summary gnus-article-current-summary)
2980 func in-buffer selected)
2981 (if not-restore-window
2982 (pop-to-buffer summary 'norecord)
2983 (switch-to-buffer summary 'norecord))
2984 (setq in-buffer (current-buffer))
2985 ;; We disable the pick minor mode commands.
2986 (if (setq func (let (gnus-pick-mode)
2987 (lookup-key (current-local-map) keys)))
2989 (call-interactively func)
2990 (setq new-sum-point (point)))
2992 (when (eq in-buffer (current-buffer))
2993 (setq selected (gnus-summary-select-article))
2995 (unless not-restore-window
2996 (set-window-configuration owin))
2997 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2998 (set-window-point (get-buffer-window (current-buffer))
3000 (let ((win (get-buffer-window gnus-article-current-summary)))
3002 (set-window-point win new-sum-point))))))))
3004 (defun gnus-article-hide (&optional arg force)
3005 "Hide all the gruft in the current article.
3006 This means that PGP stuff, signatures, cited text and (some)
3007 headers will be hidden.
3008 If given a prefix, show the hidden text instead."
3009 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3010 (gnus-article-hide-headers arg)
3011 (gnus-article-hide-pgp arg)
3012 (gnus-article-hide-citation-maybe arg force)
3013 (gnus-article-hide-signature arg))
3015 (defun gnus-article-maybe-highlight ()
3016 "Do some article highlighting if article highlighting is requested."
3017 (when (gnus-visual-p 'article-highlight 'highlight)
3018 (gnus-article-highlight-some)))
3020 (defun gnus-check-group-server ()
3021 ;; Make sure the connection to the server is alive.
3022 (unless (gnus-server-opened
3023 (gnus-find-method-for-group gnus-newsgroup-name))
3024 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3025 (gnus-request-group gnus-newsgroup-name t)))
3027 (defun gnus-request-article-this-buffer (article group)
3028 "Get an article and insert it into this buffer."
3029 (let (do-update-line sparse-header)
3033 (gnus-kill-all-overlays)
3034 (setq group (or group gnus-newsgroup-name))
3036 ;; Using `gnus-request-article' directly will insert the article into
3037 ;; `nntp-server-buffer' - so we'll save some time by not having to
3038 ;; copy it from the server buffer into the article buffer.
3040 ;; We only request an article by message-id when we do not have the
3041 ;; headers for it, so we'll have to get those.
3042 (when (stringp article)
3043 (let ((gnus-override-method gnus-refer-article-method))
3044 (gnus-read-header article)))
3046 ;; If the article number is negative, that means that this article
3047 ;; doesn't belong in this newsgroup (possibly), so we find its
3048 ;; message-id and request it by id instead of number.
3049 (when (and (numberp article)
3051 (get-buffer gnus-summary-buffer)
3052 (gnus-buffer-exists-p gnus-summary-buffer))
3054 (set-buffer gnus-summary-buffer)
3055 (let ((header (gnus-summary-article-header article)))
3058 ((memq article gnus-newsgroup-sparse)
3059 ;; This is a sparse gap article.
3060 (setq do-update-line article)
3061 (setq article (mail-header-id header))
3062 (let ((gnus-override-method gnus-refer-article-method))
3063 (setq sparse-header (gnus-read-header article)))
3064 (setq gnus-newsgroup-sparse
3065 (delq article gnus-newsgroup-sparse)))
3067 ;; It's a real article.
3068 (setq article (mail-header-id header)))
3070 ;; It is an extracted pseudo-article.
3071 (setq article 'pseudo)
3072 (gnus-request-pseudo-article header))))
3074 (let ((method (gnus-find-method-for-group
3075 gnus-newsgroup-name)))
3076 (when (and (eq (car method) 'nneething)
3079 (file-name-as-directory
3080 (or (cadr (assq 'nneething-address method))
3082 (mail-header-subject header))))
3083 (when (file-directory-p dir)
3084 (setq article 'nneething)
3085 (gnus-group-enter-directory dir))))))))
3088 ;; Refuse to select canceled articles.
3089 ((and (numberp article)
3091 (get-buffer gnus-summary-buffer)
3092 (gnus-buffer-exists-p gnus-summary-buffer)
3093 (eq (cdr (save-excursion
3094 (set-buffer gnus-summary-buffer)
3095 (assq article gnus-newsgroup-reads)))
3096 gnus-canceled-mark))
3098 ;; Check the backlog.
3099 ((and gnus-keep-backlog
3100 (gnus-backlog-request-article group article (current-buffer)))
3102 ;; Check asynchronous pre-fetch.
3103 ((gnus-async-request-fetched-article group article (current-buffer))
3104 (gnus-async-prefetch-next group article gnus-summary-buffer)
3105 (when (and (numberp article) gnus-keep-backlog)
3106 (gnus-backlog-enter-article group article (current-buffer)))
3109 ((and gnus-use-cache
3111 (gnus-cache-request-article article group))
3113 ;; Get the article and put into the article buffer.
3114 ((or (stringp article) (numberp article))
3115 (let ((gnus-override-method
3116 (and (stringp article) gnus-refer-article-method))
3117 (buffer-read-only nil))
3119 (gnus-kill-all-overlays)
3120 (gnus-check-group-server)
3121 (when (gnus-request-article article group (current-buffer))
3122 (when (numberp article)
3123 (gnus-async-prefetch-next group article gnus-summary-buffer)
3124 (when gnus-keep-backlog
3125 (gnus-backlog-enter-article
3126 group article (current-buffer))))
3131 ;; Associate this article with the current summary buffer.
3132 (setq gnus-article-current-summary gnus-summary-buffer)
3134 ;; Take the article from the original article buffer
3135 ;; and place it in the buffer it's supposed to be in.
3136 (when (and (get-buffer gnus-article-buffer)
3137 (equal (buffer-name (current-buffer))
3138 (buffer-name (get-buffer gnus-article-buffer))))
3140 (if (get-buffer gnus-original-article-buffer)
3141 (set-buffer gnus-original-article-buffer)
3142 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3143 (buffer-disable-undo)
3144 (setq major-mode 'gnus-original-article-mode)
3145 (setq buffer-read-only t))
3146 (let (buffer-read-only)
3148 (insert-buffer-substring gnus-article-buffer))
3149 (setq gnus-original-article (cons group article)))
3152 (run-hooks 'gnus-article-decode-hook)
3153 ;; Mark article as decoded or not.
3154 (setq gnus-article-decoded-p gnus-article-decode-hook))
3156 ;; Update sparse articles.
3157 (when (and do-update-line
3158 (or (numberp article)
3160 (let ((buf (current-buffer)))
3161 (set-buffer gnus-summary-buffer)
3162 (gnus-summary-update-article do-update-line sparse-header)
3163 (gnus-summary-goto-subject do-update-line nil t)
3164 (set-window-point (get-buffer-window (current-buffer) t)
3166 (set-buffer buf))))))
3172 (defcustom gnus-article-edit-mode-hook nil
3173 "Hook run in article edit mode buffers."
3174 :group 'gnus-article-various
3177 (defcustom gnus-article-edit-article-setup-function
3178 'gnus-article-mime-edit-article-setup
3179 "Function called to setup an editing article buffer."
3180 :group 'gnus-article-various
3183 (defvar gnus-article-edit-done-function nil)
3185 (defvar gnus-article-edit-mode-map nil)
3187 ;; Should we be using derived.el for this?
3188 (unless gnus-article-edit-mode-map
3189 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3190 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3192 (gnus-define-keys gnus-article-edit-mode-map
3193 "\C-c\C-c" gnus-article-edit-done
3194 "\C-c\C-k" gnus-article-edit-exit)
3196 (gnus-define-keys (gnus-article-edit-wash-map
3197 "\C-c\C-w" gnus-article-edit-mode-map)
3198 "f" gnus-article-edit-full-stops))
3200 (defun gnus-article-edit-mode ()
3201 "Major mode for editing articles.
3202 This is an extended text-mode.
3204 \\{gnus-article-edit-mode-map}"
3206 (setq major-mode 'gnus-article-edit-mode)
3207 (setq mode-name "Article Edit")
3208 (use-local-map gnus-article-edit-mode-map)
3209 (make-local-variable 'gnus-article-edit-done-function)
3210 (make-local-variable 'gnus-prev-winconf)
3211 (setq buffer-read-only nil)
3212 (buffer-enable-undo)
3214 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3216 (defun gnus-article-edit (&optional force)
3217 "Edit the current article.
3218 This will have permanent effect only in mail groups.
3219 If FORCE is non-nil, allow editing of articles even in read-only
3222 (when (and (not force)
3223 (gnus-group-read-only-p))
3224 (error "The current newsgroup does not support article editing"))
3225 (gnus-article-date-original)
3226 (gnus-article-edit-article
3227 `(lambda (no-highlight)
3228 (gnus-summary-edit-article-done
3229 ,(or (mail-header-references gnus-current-headers) "")
3230 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3232 (defun gnus-article-edit-article (exit-func)
3233 "Start editing the contents of the current article buffer."
3234 (let ((winconf (current-window-configuration)))
3235 (set-buffer gnus-article-buffer)
3236 (gnus-article-edit-mode)
3237 (gnus-article-delete-text-of-type 'annotation)
3238 (gnus-set-text-properties (point-min) (point-max) nil)
3239 (gnus-configure-windows 'edit-article)
3240 (setq gnus-article-edit-done-function exit-func)
3241 (setq gnus-prev-winconf winconf)
3242 (when gnus-article-edit-article-setup-function
3243 (funcall gnus-article-edit-article-setup-function))
3244 (gnus-message 6 "C-c C-c to end edits")))
3246 (defun gnus-article-edit-done (&optional arg)
3247 "Update the article edits and exit."
3252 (when (article-goto-body)
3253 (let ((lines (count-lines (point) (point-max)))
3254 (length (- (point-max) (point)))
3255 (case-fold-search t)
3256 (body (copy-marker (point))))
3257 (goto-char (point-min))
3258 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3259 (delete-region (match-beginning 1) (match-end 1))
3260 (insert (number-to-string length)))
3261 (goto-char (point-min))
3262 (when (re-search-forward
3263 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3264 (delete-region (match-beginning 1) (match-end 1))
3265 (insert (number-to-string length)))
3266 (goto-char (point-min))
3267 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3268 (delete-region (match-beginning 1) (match-end 1))
3269 (insert (number-to-string lines)))))))
3270 (let ((func gnus-article-edit-done-function)
3271 (buf (current-buffer))
3272 (start (window-start)))
3273 (remove-hook 'gnus-article-mode-hook
3274 'gnus-article-mime-edit-article-unwind)
3275 (gnus-article-edit-exit)
3278 (let ((buffer-read-only nil))
3280 ;; The cache and backlog have to be flushed somewhat.
3281 (when gnus-keep-backlog
3282 (gnus-backlog-remove-article
3283 (car gnus-article-current) (cdr gnus-article-current)))
3284 ;; Flush original article as well.
3286 (when (get-buffer gnus-original-article-buffer)
3287 (set-buffer gnus-original-article-buffer)
3288 (setq gnus-original-article nil)))
3289 (when gnus-use-cache
3290 (gnus-cache-update-article
3291 (car gnus-article-current) (cdr gnus-article-current))))
3293 (set-window-start (get-buffer-window buf) start)
3294 (set-window-point (get-buffer-window buf) (point))))
3296 (defun gnus-article-edit-exit ()
3297 "Exit the article editing without updating."
3299 ;; We remove all text props from the article buffer.
3300 (let ((buf (format "%s" (buffer-string)))
3301 (curbuf (current-buffer))
3303 (window-start (window-start)))
3306 (let ((winconf gnus-prev-winconf))
3308 (set-window-configuration winconf)
3309 ;; Tippy-toe some to make sure that point remains where it was.
3310 (save-current-buffer
3312 (set-window-start (get-buffer-window (current-buffer)) window-start)
3315 (defun gnus-article-edit-full-stops ()
3316 "Interactively repair spacing at end of sentences."
3319 (goto-char (point-min))
3320 (search-forward-regexp "^$" nil t)
3321 (let ((case-fold-search nil))
3322 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3325 ;;; Article editing with MIME-Edit
3328 (defcustom gnus-article-mime-edit-article-setup-hook nil
3329 "Hook run after setting up a MIME editing article buffer."
3330 :group 'gnus-article-various
3333 (defun gnus-article-mime-edit-article-unwind ()
3334 "Unwind `gnus-article-buffer' if article editing was given up."
3335 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3336 (when mime-edit-mode-flag
3337 (mime-edit-exit 'nomime 'no-error)
3339 (when (featurep 'font-lock)
3340 (setq font-lock-defaults nil)
3341 (font-lock-mode 0)))
3343 (defun gnus-article-mime-edit-article-setup ()
3344 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3345 after replacing with the original article."
3346 (setq gnus-show-mime t)
3347 (setq gnus-article-edit-done-function
3348 `(lambda (&rest args)
3349 (when mime-edit-mode-flag
3352 (goto-char (point-min))
3353 (let (case-fold-search)
3354 (when (re-search-forward
3355 (format "^%s$" (regexp-quote mail-header-separator))
3357 (replace-match "")))
3358 (when (featurep 'font-lock)
3359 (setq font-lock-defaults nil)
3361 (apply ,gnus-article-edit-done-function args)
3362 (set-buffer gnus-original-article-buffer)
3364 (insert-buffer gnus-article-buffer)
3365 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3366 (gnus-article-prepare-display)))
3367 (substitute-key-definition
3368 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3369 gnus-article-edit-mode-map)
3371 (insert-buffer gnus-original-article-buffer)
3373 (when (featurep 'font-lock)
3374 (set (make-local-variable 'font-lock-defaults)
3375 '(message-font-lock-keywords t))
3376 (font-lock-set-defaults)
3377 (turn-on-font-lock))
3378 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3379 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3381 (defun gnus-article-mime-edit-exit ()
3382 "Exit the article MIME editing without updating."
3384 (let ((winconf gnus-prev-winconf)
3386 (when mime-edit-mode-flag
3389 (goto-char (point-min))
3390 (let (case-fold-search)
3391 (when (re-search-forward
3392 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3393 (replace-match "")))
3394 (when (featurep 'font-lock)
3395 (setq font-lock-defaults nil)
3397 ;; We remove all text props from the article buffer.
3398 (setq buf (format "%s" (buffer-string)))
3399 (set-buffer (get-buffer-create gnus-original-article-buffer))
3402 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3403 (gnus-article-prepare-display)
3404 (set-window-configuration winconf)))
3407 ;;; Article highlights
3410 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3412 ;;; Internal Variables:
3414 (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\\)"
3415 "Regular expression that matches URLs."
3416 :group 'gnus-article-buttons
3419 (defcustom gnus-button-alist
3420 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3421 0 t gnus-button-message-id 2)
3422 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3423 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3425 gnus-button-fetch-group 4)
3426 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3427 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3428 t gnus-button-message-id 3)
3429 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3430 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3431 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3432 ;; This is how URLs _should_ be embedded in text...
3433 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3435 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3436 "*Alist of regexps matching buttons in article bodies.
3438 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3439 REGEXP: is the string matching text around the button,
3440 BUTTON: is the number of the regexp grouping actually matching the button,
3441 FORM: is a lisp expression which must eval to true for the button to
3443 CALLBACK: is the function to call when the user push this button, and each
3444 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3446 CALLBACK can also be a variable, in that case the value of that
3447 variable it the real callback function."
3448 :group 'gnus-article-buttons
3449 :type '(repeat (list regexp
3450 (integer :tag "Button")
3452 (function :tag "Callback")
3455 (integer :tag "Regexp group")))))
3457 (defcustom gnus-header-button-alist
3458 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3459 0 t gnus-button-message-id 0)
3460 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3461 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3462 0 t gnus-button-mailto 0)
3463 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3464 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3465 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3466 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3467 gnus-button-message-id 3))
3468 "*Alist of headers and regexps to match buttons in article heads.
3470 This alist is very similar to `gnus-button-alist', except that each
3471 alist has an additional HEADER element first in each entry:
3473 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3475 HEADER is a regexp to match a header. For a fuller explanation, see
3476 `gnus-button-alist'."
3477 :group 'gnus-article-buttons
3478 :group 'gnus-article-headers
3479 :type '(repeat (list (regexp :tag "Header")
3481 (integer :tag "Button")
3483 (function :tag "Callback")
3486 (integer :tag "Regexp group")))))
3488 (defvar gnus-button-regexp nil)
3489 (defvar gnus-button-marker-list nil)
3490 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3492 (defvar gnus-button-last nil)
3493 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3497 (defun gnus-article-push-button (event)
3498 "Check text under the mouse pointer for a callback function.
3499 If the text under the mouse pointer has a `gnus-callback' property,
3500 call it with the value of the `gnus-data' text property."
3502 (set-buffer (window-buffer (posn-window (event-start event))))
3503 (let* ((pos (posn-point (event-start event)))
3504 (data (get-text-property pos 'gnus-data))
3505 (fun (get-text-property pos 'gnus-callback)))
3508 (funcall fun data))))
3510 (defun gnus-article-press-button ()
3511 "Check text at point for a callback function.
3512 If the text at point has a `gnus-callback' property,
3513 call it with the value of the `gnus-data' text property."
3515 (let* ((data (get-text-property (point) 'gnus-data))
3516 (fun (get-text-property (point) 'gnus-callback)))
3518 (funcall fun data))))
3520 (defun gnus-article-prev-button (n)
3521 "Move point to N buttons backward.
3522 If N is negative, move forward instead."
3524 (gnus-article-next-button (- n)))
3526 (defun gnus-article-next-button (n)
3527 "Move point to N buttons forward.
3528 If N is negative, move backward instead."
3530 (let ((function (if (< n 0) 'previous-single-property-change
3531 'next-single-property-change))
3532 (inhibit-point-motion-hooks t)
3534 (limit (if (< n 0) (point-min) (point-max))))
3536 (while (and (not (= limit (point)))
3538 ;; Skip past the current button.
3539 (when (get-text-property (point) 'gnus-callback)
3540 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3541 ;; Go to the next (or previous) button.
3542 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
3543 ;; Put point at the start of the button.
3544 (when (and backward (not (get-text-property (point) 'gnus-callback)))
3545 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3546 ;; Skip past intangible buttons.
3547 (when (get-text-property (point) 'intangible)
3551 (gnus-message 5 "No more buttons"))
3554 (defun gnus-article-highlight (&optional force)
3555 "Highlight current article.
3556 This function calls `gnus-article-highlight-headers',
3557 `gnus-article-highlight-citation',
3558 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3559 do the highlighting. See the documentation for those functions."
3560 (interactive (list 'force))
3561 (gnus-article-highlight-headers)
3562 (gnus-article-highlight-citation force)
3563 (gnus-article-highlight-signature)
3564 (gnus-article-add-buttons force)
3565 (gnus-article-add-buttons-to-head))
3567 (defun gnus-article-highlight-some (&optional force)
3568 "Highlight current article.
3569 This function calls `gnus-article-highlight-headers',
3570 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3571 do the highlighting. See the documentation for those functions."
3572 (interactive (list 'force))
3573 (gnus-article-highlight-headers)
3574 (gnus-article-highlight-signature)
3575 (gnus-article-add-buttons))
3577 (defun gnus-article-highlight-headers ()
3578 "Highlight article headers as specified by `gnus-header-face-alist'."
3581 (set-buffer gnus-article-buffer)
3583 (let ((alist gnus-header-face-alist)
3584 (buffer-read-only nil)
3585 (case-fold-search t)
3586 (inhibit-point-motion-hooks t)
3587 entry regexp header-face field-face from hpoints fpoints)
3588 (message-narrow-to-head)
3589 (while (setq entry (pop alist))
3590 (goto-char (point-min))
3591 (setq regexp (concat "^\\("
3592 (if (string-equal "" (nth 0 entry))
3596 header-face (nth 1 entry)
3597 field-face (nth 2 entry))
3598 (while (and (re-search-forward regexp nil t)
3602 (unless (search-forward ":" nil t)
3604 (when (and header-face
3605 (not (memq (point) hpoints)))
3606 (push (point) hpoints)
3607 (gnus-put-text-property from (point) 'face header-face))
3608 (when (and field-face
3609 (not (memq (setq from (point)) fpoints)))
3611 (if (re-search-forward "^[^ \t]" nil t)
3613 (goto-char (point-max)))
3614 (gnus-put-text-property from (point) 'face field-face))))))))
3616 (defun gnus-article-highlight-signature ()
3617 "Highlight the signature in an article.
3618 It does this by highlighting everything after
3619 `gnus-signature-separator' using `gnus-signature-face'."
3622 (set-buffer gnus-article-buffer)
3623 (let ((buffer-read-only nil)
3624 (inhibit-point-motion-hooks t))
3626 (when (and gnus-signature-face
3627 (gnus-article-narrow-to-signature))
3628 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3629 'face gnus-signature-face)
3631 (gnus-article-search-signature)
3632 (let ((start (match-beginning 0))
3633 (end (set-marker (make-marker) (1+ (match-end 0)))))
3634 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3637 (defun gnus-button-in-region-p (b e prop)
3638 "Say whether PROP exists in the region."
3639 (text-property-not-all b e prop nil))
3641 (defun gnus-article-add-buttons (&optional force)
3642 "Find external references in the article and make buttons of them.
3643 \"External references\" are things like Message-IDs and URLs, as
3644 specified by `gnus-button-alist'."
3645 (interactive (list 'force))
3647 (set-buffer gnus-article-buffer)
3648 (let ((buffer-read-only nil)
3649 (inhibit-point-motion-hooks t)
3650 (case-fold-search t)
3651 (alist gnus-button-alist)
3653 ;; Remove all old markers.
3655 (while (setq marker (pop gnus-button-marker-list))
3657 (when (setq entry (gnus-button-entry))
3658 (put-text-property (match-beginning (nth 1 entry))
3659 (match-end (nth 1 entry))
3660 'gnus-callback nil))
3661 (set-marker marker nil)))
3662 ;; We skip the headers.
3665 (while (setq entry (pop alist))
3666 (setq regexp (car entry))
3668 (while (re-search-forward regexp nil t)
3669 (let* ((start (and entry (match-beginning (nth 1 entry))))
3670 (end (and entry (match-end (nth 1 entry))))
3671 (from (match-beginning 0)))
3672 (when (and (or (eq t (nth 2 entry))
3673 (eval (nth 2 entry)))
3674 (not (gnus-button-in-region-p
3675 start end 'gnus-callback)))
3676 ;; That optional form returned non-nil, so we add the
3678 (gnus-article-add-button
3679 start end 'gnus-button-push
3680 (car (push (set-marker (make-marker) from)
3681 gnus-button-marker-list))))))))))
3683 ;; Add buttons to the head of an article.
3684 (defun gnus-article-add-buttons-to-head ()
3685 "Add buttons to the head of the article."
3688 (set-buffer gnus-article-buffer)
3689 (let ((buffer-read-only nil)
3690 (inhibit-point-motion-hooks t)
3691 (case-fold-search t)
3692 (alist gnus-header-button-alist)
3694 (nnheader-narrow-to-headers)
3696 ;; Each alist entry.
3697 (setq entry (car alist)
3699 (goto-char (point-min))
3700 (while (re-search-forward (car entry) nil t)
3701 ;; Each header matching the entry.
3702 (setq beg (match-beginning 0))
3703 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3704 (match-beginning 0))
3707 (while (re-search-forward (nth 1 entry) end t)
3708 ;; Each match within a header.
3709 (let* ((entry (cdr entry))
3710 (start (match-beginning (nth 1 entry)))
3711 (end (match-end (nth 1 entry)))
3712 (form (nth 2 entry)))
3713 (goto-char (match-end 0))
3715 (gnus-article-add-button
3716 start end (nth 3 entry)
3717 (buffer-substring (match-beginning (nth 4 entry))
3718 (match-end (nth 4 entry)))))))
3722 ;;; External functions:
3724 (defun gnus-article-add-button (from to fun &optional data)
3725 "Create a button between FROM and TO with callback FUN and data DATA."
3726 (when gnus-article-button-face
3727 (gnus-overlay-put (gnus-make-overlay from to)
3728 'face gnus-article-button-face))
3729 (gnus-add-text-properties
3731 (nconc (and gnus-article-mouse-face
3732 (list gnus-mouse-face-prop gnus-article-mouse-face))
3733 (list 'gnus-callback fun)
3734 (and data (list 'gnus-data data)))))
3736 ;;; Internal functions:
3738 (defun gnus-article-set-globals ()
3740 (set-buffer gnus-summary-buffer)
3741 (gnus-set-global-variables)))
3743 (defun gnus-signature-toggle (end)
3745 (set-buffer gnus-article-buffer)
3746 (let ((buffer-read-only nil)
3747 (inhibit-point-motion-hooks t))
3748 (if (get-text-property end 'invisible)
3749 (gnus-article-unhide-text end (point-max))
3750 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3752 (defun gnus-button-entry ()
3753 ;; Return the first entry in `gnus-button-alist' matching this place.
3754 (let ((alist gnus-button-alist)
3757 (setq entry (pop alist))
3758 (if (looking-at (car entry))
3763 (defun gnus-button-push (marker)
3764 ;; Push button starting at MARKER.
3767 (let* ((entry (gnus-button-entry))
3768 (inhibit-point-motion-hooks t)
3770 (args (mapcar (lambda (group)
3771 (let ((string (match-string group)))
3772 (gnus-set-text-properties
3773 0 (length string) nil string)
3780 (fboundp (symbol-value fun)))
3781 (apply (symbol-value fun) args))
3783 (gnus-message 1 "You must define `%S' to use this button"
3784 (cons fun args)))))))
3786 (defun gnus-button-message-id (message-id)
3789 (set-buffer gnus-summary-buffer)
3790 (gnus-summary-refer-article message-id)))
3792 (defun gnus-button-fetch-group (address)
3793 "Fetch GROUP specified by ADDRESS."
3794 (if (not (string-match "[:/]" address))
3795 ;; This is just a simple group url.
3796 (gnus-group-read-ephemeral-group address gnus-select-method)
3797 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3799 (error "Can't parse %s" address)
3800 (gnus-group-read-ephemeral-group
3801 (match-string 4 address)
3802 `(nntp ,(match-string 1 address)
3803 (nntp-address ,(match-string 1 address))
3804 (nntp-port-number ,(if (match-end 3)
3805 (match-string 3 address)
3808 (defun gnus-url-parse-query-string (query &optional downcase)
3809 (let (retval pairs cur key val)
3810 (setq pairs (split-string query "&"))
3812 (setq cur (car pairs)
3814 (if (not (string-match "=" cur))
3816 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3817 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3819 (setq key (downcase key)))
3820 (setq cur (assoc key retval))
3822 (setcdr cur (cons val (cdr cur)))
3823 (setq retval (cons (list key val) retval)))))
3826 (defun gnus-url-unhex (x)
3833 (defun gnus-url-unhex-string (str &optional allow-newlines)
3834 "Remove %XXX embedded spaces, etc in a url.
3835 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3836 decoding of carriage returns and line feeds in the string, which is normally
3837 forbidden in URL encoding."
3838 (setq str (or str ""))
3840 (case-fold-search t))
3841 (while (string-match "%[0-9a-f][0-9a-f]" str)
3842 (let* ((start (match-beginning 0))
3843 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3845 (gnus-url-unhex (elt str (+ start 2))))))
3847 tmp (substring str 0 start)
3850 (char-to-string code))
3851 ((or (= code ?\n) (= code ?\r))
3853 (t (char-to-string code))))
3854 str (substring str (match-end 0)))))
3855 (setq tmp (concat tmp str))
3858 (defun gnus-url-mailto (url)
3859 ;; Send mail to someone
3860 (when (string-match "mailto:/*\\(.*\\)" url)
3861 (setq url (substring url (match-beginning 1) nil)))
3862 (let (to args subject func)
3863 (if (string-match (regexp-quote "?") url)
3864 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3865 args (gnus-url-parse-query-string
3866 (substring url (match-end 0) nil) t))
3867 (setq to (gnus-url-unhex-string url)))
3868 (setq args (cons (list "to" to) args)
3869 subject (cdr-safe (assoc "subject" args)))
3870 (gnus-setup-message 'reply
3873 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3876 (message-position-on-field (caar args)))
3877 (insert (mapconcat 'identity (cdar args) ", "))
3878 (setq args (cdr args)))
3881 (message-goto-subject)))))
3883 (defun gnus-button-mailto (address)
3885 (set-buffer (gnus-copy-article-buffer))
3886 (gnus-setup-message 'reply
3887 (message-reply address)))
3889 (defun gnus-button-reply (address)
3890 ;; Reply to ADDRESS.
3891 (gnus-setup-message 'reply
3892 (message-reply address)))
3894 (defun gnus-button-url (address)
3896 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3897 (if (listp browse-url-browser-function)
3898 (browse-url address)
3899 (funcall browse-url-browser-function address)))
3901 (defun gnus-button-embedded-url (address)
3903 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3904 (if (listp browse-url-browser-function)
3905 (browse-url (gnus-strip-whitespace address))
3906 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3908 ;;; Next/prev buttons in the article buffer.
3910 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3911 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3913 (defvar gnus-prev-page-map nil)
3914 (unless gnus-prev-page-map
3915 (setq gnus-prev-page-map (make-sparse-keymap))
3916 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3917 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3919 (defun gnus-insert-prev-page-button ()
3920 (let ((buffer-read-only nil))
3922 gnus-prev-page-line-format nil
3923 `(gnus-prev t local-map ,gnus-prev-page-map
3924 gnus-callback gnus-article-button-prev-page
3925 article-type annotation))))
3927 (defvar gnus-next-page-map nil)
3928 (unless gnus-next-page-map
3929 (setq gnus-next-page-map (make-keymap))
3930 (suppress-keymap gnus-prev-page-map)
3931 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3932 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3934 (defun gnus-button-next-page ()
3935 "Go to the next page."
3937 (let ((win (selected-window)))
3938 (select-window (get-buffer-window gnus-article-buffer t))
3939 (gnus-article-next-page)
3940 (select-window win)))
3942 (defun gnus-button-prev-page ()
3943 "Go to the prev page."
3945 (let ((win (selected-window)))
3946 (select-window (get-buffer-window gnus-article-buffer t))
3947 (gnus-article-prev-page)
3948 (select-window win)))
3950 (defun gnus-insert-next-page-button ()
3951 (let ((buffer-read-only nil))
3952 (gnus-eval-format gnus-next-page-line-format nil
3954 t local-map ,gnus-next-page-map
3955 gnus-callback gnus-article-button-next-page
3956 article-type annotation))))
3958 (defun gnus-article-button-next-page (arg)
3959 "Go to the next page."
3961 (let ((win (selected-window)))
3962 (select-window (get-buffer-window gnus-article-buffer t))
3963 (gnus-article-next-page)
3964 (select-window win)))
3966 (defun gnus-article-button-prev-page (arg)
3967 "Go to the prev page."
3969 (let ((win (selected-window)))
3970 (select-window (get-buffer-window gnus-article-buffer t))
3971 (gnus-article-prev-page)
3972 (select-window win)))
3974 (defvar gnus-decode-header-methods
3975 '(mail-decode-encoded-word-region)
3976 "List of methods used to decode headers
3978 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
3979 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
3980 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
3981 whose names match REGEXP.
3984 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
3985 mail-decode-encoded-word-region
3986 (\"chinese\" . rfc1843-decode-region))
3989 (defvar gnus-decode-header-methods-cache nil)
3991 (defun gnus-multi-decode-header (start end)
3992 "Apply the functions from `gnus-encoded-word-methods' that match."
3993 (unless (and gnus-decode-header-methods-cache
3994 (eq gnus-newsgroup-name
3995 (car gnus-decode-header-methods-cache)))
3996 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
3999 (nconc gnus-decode-header-methods-cache (list x))
4000 (if (and gnus-newsgroup-name
4001 (string-match (car x) gnus-newsgroup-name))
4002 (nconc gnus-decode-header-methods-cache
4004 gnus-decode-header-methods))
4005 (let ((xlist gnus-decode-header-methods-cache))
4008 (narrow-to-region start end)
4010 (funcall (pop xlist) (point-min) (point-max))))))
4016 (defun gnus-article-header-presentation-method (entity situation)
4017 (mime-insert-header entity)
4020 (set-alist 'mime-header-presentation-method-alist
4021 'gnus-original-article-mode
4022 #'gnus-article-header-presentation-method)
4024 (defun gnus-mime-preview-quitting-method ()
4026 (gnus-article-show-summary)
4027 (mime-preview-kill-buffer)
4028 (delete-other-windows)
4029 (gnus-article-show-summary)
4030 (gnus-summary-select-article nil t)
4033 (set-alist 'mime-preview-quitting-method-alist
4034 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
4036 (defun gnus-following-method (buf)
4039 (message-yank-original)
4041 (goto-char (point-min))
4044 (set-alist 'mime-preview-following-method-alist
4045 'gnus-original-article-mode #'gnus-following-method)
4055 (run-hooks 'gnus-art-load-hook)
4057 ;;; gnus-art.el ends here