1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
38 (defgroup gnus-article nil
40 :link '(custom-manual "(gnus)The Article Buffer")
43 (defgroup gnus-article-hiding nil
44 "Hiding article parts."
45 :link '(custom-manual "(gnus)Article Hiding")
48 (defgroup gnus-article-highlight nil
49 "Article highlighting."
50 :link '(custom-manual "(gnus)Article Highlighting")
54 (defgroup gnus-article-signature nil
56 :link '(custom-manual "(gnus)Article Signature")
59 (defgroup gnus-article-headers nil
61 :link '(custom-manual "(gnus)Hiding Headers")
64 (defgroup gnus-article-washing nil
65 "Special commands on articles."
66 :link '(custom-manual "(gnus)Article Washing")
69 (defgroup gnus-article-emphasis nil
70 "Fontisizing articles."
71 :link '(custom-manual "(gnus)Article Fontisizing")
74 (defgroup gnus-article-saving nil
76 :link '(custom-manual "(gnus)Saving Articles")
79 (defgroup gnus-article-mime nil
80 "Worshiping the MIME wonder."
81 :link '(custom-manual "(gnus)Using MIME")
84 (defgroup gnus-article-buttons nil
85 "Pushable buttons in the article buffer."
86 :link '(custom-manual "(gnus)Article Buttons")
89 (defgroup gnus-article-various nil
90 "Other article options."
91 :link '(custom-manual "(gnus)Misc Article")
94 (defcustom gnus-ignored-headers
95 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
96 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
97 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
98 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
99 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
100 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
101 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
102 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
103 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
104 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
105 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
106 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
107 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
108 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
109 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
110 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
111 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
112 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
114 "*All headers that start with this regexp will be hidden.
115 This variable can also be a list of regexps of headers to be ignored.
116 If `gnus-visible-headers' is non-nil, this variable will be ignored."
117 :type '(choice :custom-show nil
120 :group 'gnus-article-hiding)
122 (defcustom gnus-visible-headers
123 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
124 "*All headers that do not match this regexp will be hidden.
125 This variable can also be a list of regexp of headers to remain visible.
126 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
127 :type '(repeat :value-to-internal (lambda (widget value)
128 (custom-split-regexp-maybe value))
129 :match (lambda (widget value)
131 (widget-editable-list-match widget value)))
133 :group 'gnus-article-hiding)
135 (defcustom gnus-sorted-header-list
136 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
137 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
138 "*This variable is a list of regular expressions.
139 If it is non-nil, headers that match the regular expressions will
140 be placed first in the article buffer in the sequence specified by
142 :type '(repeat regexp)
143 :group 'gnus-article-hiding)
145 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
146 "Headers that are only to be displayed if they have interesting data.
147 Possible values in this list are `empty', `newsgroups', `followup-to',
148 `reply-to', `date', `long-to', and `many-to'."
149 :type '(set (const :tag "Headers with no content." empty)
150 (const :tag "Newsgroups with only one group." newsgroups)
151 (const :tag "Followup-to identical to newsgroups." followup-to)
152 (const :tag "Reply-to identical to from." reply-to)
153 (const :tag "Date less than four days old." date)
154 (const :tag "Very long To header." long-to)
155 (const :tag "Multiple To headers." many-to))
156 :group 'gnus-article-hiding)
158 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
159 "Regexp matching signature separator.
160 This can also be a list of regexps. In that case, it will be checked
161 from head to tail looking for a separator. Searches will be done from
162 the end of the buffer."
163 :type '(repeat string)
164 :group 'gnus-article-signature)
166 (defcustom gnus-signature-limit nil
167 "Provide a limit to what is considered a signature.
168 If it is a number, no signature may not be longer (in characters) than
169 that number. If it is a floating point number, no signature may be
170 longer (in lines) than that number. If it is a function, the function
171 will be called without any parameters, and if it returns nil, there is
172 no signature in the buffer. If it is a string, it will be used as a
173 regexp. If it matches, the text in question is not a signature."
174 :type '(choice (integer :value 200)
176 (function :value fun)
177 (regexp :value ".*"))
178 :group 'gnus-article-signature)
180 (defcustom gnus-hidden-properties '(invisible t intangible t)
181 "Property list to use for hiding text."
183 :group 'gnus-article-hiding)
185 (defcustom gnus-article-x-face-command
186 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
187 "*String or function to be executed to display an X-Face header.
188 If it is a string, the command will be executed in a sub-shell
189 asynchronously. The compressed face will be piped to this command."
190 :type 'string ;Leave function case to Lisp.
191 :group 'gnus-article-washing)
193 (defcustom gnus-article-x-face-too-ugly nil
194 "Regexp matching posters whose face shouldn't be shown automatically."
195 :type '(choice regexp (const nil))
196 :group 'gnus-article-washing)
198 (defcustom gnus-emphasis-alist
200 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
202 '(("_" "_" underline)
205 ("_/" "/_" underline-italic)
206 ("_\\*" "\\*_" underline-bold)
207 ("\\*/" "/\\*" bold-italic)
208 ("_\\*/" "/\\*_" underline-bold-italic))))
209 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
210 2 3 gnus-emphasis-underline)
214 (format format (car spec) (cadr spec))
215 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
217 "*Alist that says how to fontify certain phrases.
218 Each item looks like this:
220 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
222 The first element is a regular expression to be matched. The second
223 is a number that says what regular expression grouping used to find
224 the entire emphasized word. The third is a number that says what
225 regexp grouping should be displayed and highlighted. The fourth
226 is the face used for highlighting."
227 :type '(repeat (list :value ("" 0 0 default)
229 (integer :tag "Match group")
230 (integer :tag "Emphasize group")
232 :group 'gnus-article-emphasis)
234 (defface gnus-emphasis-bold '((t (:bold t)))
235 "Face used for displaying strong emphasized text (*word*)."
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-italic '((t (:italic t)))
239 "Face used for displaying italic emphasized text (/word/)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-underline '((t (:underline t)))
243 "Face used for displaying underlined emphasized text (_word_)."
244 :group 'gnus-article-emphasis)
246 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
247 "Face used for displaying underlined bold emphasized text (_*word*_)."
248 :group 'gnus-article-emphasis)
250 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
251 "Face used for displaying underlined italic emphasized text (_*word*_)."
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
255 "Face used for displaying bold italic emphasized text (/*word*/)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-underline-bold-italic
259 '((t (:bold t :italic t :underline t)))
260 "Face used for displaying underlined bold italic emphasized text.
261 Esample: (_/*word*/_)."
262 :group 'gnus-article-emphasis)
264 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
265 "Format for display of Date headers in article bodies.
266 See `format-time-string' for the possible values.
268 The variable can also be function, which should return a complete Date
269 header. The function is called with one argument, the time, which can
270 be fed to `format-time-string'."
271 :type '(choice string symbol)
272 :link '(custom-manual "(gnus)Article Date")
273 :group 'gnus-article-washing)
276 (autoload 'timezone-make-date-arpa-standard "timezone")
277 (autoload 'mail-extract-address-components "mail-extr"))
279 (defcustom gnus-save-all-headers t
280 "*If non-nil, don't remove any headers before saving."
281 :group 'gnus-article-saving
284 (defcustom gnus-prompt-before-saving 'always
285 "*This variable says how much prompting is to be done when saving articles.
286 If it is nil, no prompting will be done, and the articles will be
287 saved to the default files. If this variable is `always', each and
288 every article that is saved will be preceded by a prompt, even when
289 saving large batches of articles. If this variable is neither nil not
290 `always', there the user will be prompted once for a file name for
291 each invocation of the saving commands."
292 :group 'gnus-article-saving
293 :type '(choice (item always)
294 (item :tag "never" nil)
295 (sexp :tag "once" :format "%t\n" :value t)))
297 (defcustom gnus-saved-headers gnus-visible-headers
298 "Headers to keep if `gnus-save-all-headers' is nil.
299 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
300 If that variable is nil, however, all headers that match this regexp
301 will be kept while the rest will be deleted before saving."
302 :group 'gnus-article-saving
305 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
306 "A function to save articles in your favourite format.
307 The function must be interactively callable (in other words, it must
308 be an Emacs command).
310 Gnus provides the following functions:
312 * gnus-summary-save-in-rmail (Rmail format)
313 * gnus-summary-save-in-mail (Unix mail format)
314 * gnus-summary-save-in-folder (MH folder)
315 * gnus-summary-save-in-file (article format)
316 * gnus-summary-save-in-vm (use VM's folder format)
317 * gnus-summary-write-to-file (article format -- overwrite)."
318 :group 'gnus-article-saving
319 :type '(radio (function-item gnus-summary-save-in-rmail)
320 (function-item gnus-summary-save-in-mail)
321 (function-item gnus-summary-save-in-folder)
322 (function-item gnus-summary-save-in-file)
323 (function-item gnus-summary-save-in-vm)
324 (function-item gnus-summary-write-to-file)))
326 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
327 "A function generating a file name to save articles in Rmail format.
328 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
329 :group 'gnus-article-saving
332 (defcustom gnus-mail-save-name 'gnus-plain-save-name
333 "A function generating a file name to save articles in Unix mail format.
334 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
335 :group 'gnus-article-saving
338 (defcustom gnus-folder-save-name 'gnus-folder-save-name
339 "A function generating a file name to save articles in MH folder.
340 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
341 :group 'gnus-article-saving
344 (defcustom gnus-file-save-name 'gnus-numeric-save-name
345 "A function generating a file name to save articles in article format.
346 The function is called with NEWSGROUP, HEADERS, and optional
348 :group 'gnus-article-saving
351 (defcustom gnus-split-methods
352 '((gnus-article-archive-name)
353 (gnus-article-nndoc-name))
354 "*Variable used to suggest where articles are to be saved.
355 For instance, if you would like to save articles related to Gnus in
356 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
357 you could set this variable to something like:
359 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
360 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
362 This variable is an alist where the where the key is the match and the
363 value is a list of possible files to save in if the match is non-nil.
365 If the match is a string, it is used as a regexp match on the
366 article. If the match is a symbol, that symbol will be funcalled
367 from the buffer of the article to be saved with the newsgroup as the
368 parameter. If it is a list, it will be evaled in the same buffer.
370 If this form or function returns a string, this string will be used as
371 a possible file name; and if it returns a non-nil list, that list will
372 be used as possible file names."
373 :group 'gnus-article-saving
374 :type '(repeat (choice (list :value (fun) function)
375 (cons :value ("" "") regexp (repeat string))
378 (defcustom gnus-strict-mime t
379 "*If nil, MIME-decode even if there is no Mime-Version header."
380 :group 'gnus-article-mime
383 (defcustom gnus-show-mime-method 'metamail-buffer
384 "Function to process a MIME message.
385 The function is called from the article buffer."
386 :group 'gnus-article-mime
389 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable
390 "*Function to decode MIME encoded words.
391 The function is called from the article buffer."
392 :group 'gnus-article-mime
395 (defcustom gnus-page-delimiter "^\^L"
396 "*Regexp describing what to use as article page delimiters.
397 The default value is \"^\^L\", which is a form linefeed at the
398 beginning of a line."
400 :group 'gnus-article-various)
402 (defcustom gnus-article-mode-line-format "Gnus: %%b %S"
403 "*The format specification for the article mode line.
404 See `gnus-summary-mode-line-format' for a closer description."
406 :group 'gnus-article-various)
408 (defcustom gnus-article-mode-hook nil
409 "*A hook for Gnus article mode."
411 :group 'gnus-article-various)
413 (defcustom gnus-article-menu-hook nil
414 "*Hook run after the creation of the article mode menu."
416 :group 'gnus-article-various)
418 (defcustom gnus-article-prepare-hook nil
419 "*A hook called after an article has been prepared in the article buffer.
420 If you want to run a special decoding program like nkf, use this hook."
422 :group 'gnus-article-various)
424 (defcustom gnus-article-hide-pgp-hook nil
425 "*A hook called after successfully hiding a PGP signature."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-button-face 'bold
430 "Face used for highlighting buttons in the article buffer.
432 An article button is a piece of text that you can activate by pressing
433 `RET' or `mouse-2' above it."
435 :group 'gnus-article-buttons)
437 (defcustom gnus-article-mouse-face 'highlight
438 "Face used for mouse highlighting in the article buffer.
440 Article buttons will be displayed in this face when the cursor is
443 :group 'gnus-article-buttons)
445 (defcustom gnus-signature-face 'gnus-signature-face
446 "Face used for highlighting a signature in the article buffer.
447 Obsolete; use the face `gnus-signature-face' for customizations instead."
449 :group 'gnus-article-highlight
450 :group 'gnus-article-signature)
452 (defface gnus-signature-face
455 "Face used for highlighting a signature in the article buffer."
456 :group 'gnus-article-highlight
457 :group 'gnus-article-signature)
459 (defface gnus-header-from-face
462 (:foreground "spring green"))
465 (:foreground "red3"))
468 "Face used for displaying from headers."
469 :group 'gnus-article-headers
470 :group 'gnus-article-highlight)
472 (defface gnus-header-subject-face
475 (:foreground "SeaGreen3"))
478 (:foreground "red4"))
480 (:bold t :italic t)))
481 "Face used for displaying subject headers."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-newsgroups-face
488 (:foreground "yellow" :italic t))
491 (:foreground "MidnightBlue" :italic t))
494 "Face used for displaying newsgroups headers."
495 :group 'gnus-article-headers
496 :group 'gnus-article-highlight)
498 (defface gnus-header-name-face
501 (:foreground "SeaGreen"))
504 (:foreground "maroon"))
507 "Face used for displaying header names."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-content-face
514 (:foreground "forest green" :italic t))
517 (:foreground "indianred4" :italic t))
519 (:italic t))) "Face used for displaying header content."
520 :group 'gnus-article-headers
521 :group 'gnus-article-highlight)
523 (defcustom gnus-header-face-alist
524 '(("From" nil gnus-header-from-face)
525 ("Subject" nil gnus-header-subject-face)
526 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
527 ("" gnus-header-name-face gnus-header-content-face))
528 "*Controls highlighting of article header.
530 An alist of the form (HEADER NAME CONTENT).
532 HEADER is a regular expression which should match the name of an
533 header header and NAME and CONTENT are either face names or nil.
535 The name of each header field will be displayed using the face
536 specified by the first element in the list where HEADER match the
537 header name and NAME is non-nil. Similarly, the content will be
538 displayed by the first non-nil matching CONTENT face."
539 :group 'gnus-article-headers
540 :group 'gnus-article-highlight
541 :type '(repeat (list (regexp :tag "Header")
543 (item :tag "skip" nil)
544 (face :value default))
545 (choice :tag "Content"
546 (item :tag "skip" nil)
547 (face :value default)))))
549 ;;; Internal variables
551 (defvar article-lapsed-timer nil)
552 (defvar gnus-article-current-summary nil)
554 (defvar gnus-article-mode-syntax-table
555 (let ((table (copy-syntax-table text-mode-syntax-table)))
556 (modify-syntax-entry ?- "w" table)
557 (modify-syntax-entry ?> ")" table)
558 (modify-syntax-entry ?< "(" table)
560 "Syntax table used in article mode buffers.
561 Initialized from `text-mode-syntax-table.")
563 (defvar gnus-save-article-buffer nil)
565 (defvar gnus-article-mode-line-format-alist
566 (nconc '((?w (gnus-article-wash-status) ?s))
567 gnus-summary-mode-line-format-alist))
569 (defvar gnus-number-of-articles-to-be-saved nil)
571 (defvar gnus-inhibit-hiding nil)
573 (defsubst gnus-article-hide-text (b e props)
574 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
575 (add-text-properties b e props)
576 (when (memq 'intangible props)
578 (max (1- b) (point-min))
579 b 'intangible (cddr (memq 'intangible props)))))
581 (defsubst gnus-article-unhide-text (b e)
582 "Remove hidden text properties from region between B and E."
583 (remove-text-properties b e gnus-hidden-properties)
584 (when (memq 'intangible gnus-hidden-properties)
585 (put-text-property (max (1- b) (point-min))
588 (defun gnus-article-hide-text-type (b e type)
589 "Hide text of TYPE between B and E."
590 (gnus-article-hide-text
591 b e (cons 'article-type (cons type gnus-hidden-properties))))
593 (defun gnus-article-unhide-text-type (b e type)
594 "Unhide text of TYPE between B and E."
595 (remove-text-properties
596 b e (cons 'article-type (cons type gnus-hidden-properties)))
597 (when (memq 'intangible gnus-hidden-properties)
598 (put-text-property (max (1- b) (point-min))
601 (defun gnus-article-hide-text-of-type (type)
602 "Hide text of TYPE in the current buffer."
604 (let ((b (point-min))
606 (while (setq b (text-property-any b e 'article-type type))
607 (add-text-properties b (incf b) gnus-hidden-properties)))))
609 (defun gnus-article-delete-text-of-type (type)
610 "Delete text of TYPE in the current buffer."
612 (let ((b (point-min)))
613 (while (setq b (text-property-any b (point-max) 'article-type type))
615 b (or (text-property-not-all b (point-max) 'article-type type)
618 (defun gnus-article-delete-invisible-text ()
619 "Delete all invisible text in the current buffer."
621 (let ((b (point-min)))
622 (while (setq b (text-property-any b (point-max) 'invisible t))
624 b (or (text-property-not-all b (point-max) 'invisible t)
627 (defun gnus-article-text-type-exists-p (type)
628 "Say whether any text of type TYPE exists in the buffer."
629 (text-property-any (point-min) (point-max) 'article-type type))
631 (defsubst gnus-article-header-rank ()
632 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
633 (let ((list gnus-sorted-header-list)
636 (when (looking-at (car list))
638 (setq list (cdr list))
642 (defun article-hide-headers (&optional arg delete)
643 "Toggle whether to hide unwanted headers and possibly sort them as well.
644 If given a negative prefix, always show; if given a positive prefix,
646 (interactive (gnus-article-hidden-arg))
648 (if (gnus-article-check-hidden-text 'headers arg)
649 ;; Show boring headers as well.
650 (gnus-article-show-hidden-text 'boring-headers)
651 ;; This function might be inhibited.
652 (unless gnus-inhibit-hiding
655 (let ((buffer-read-only nil)
657 (props (nconc (list 'article-type 'headers)
658 gnus-hidden-properties))
659 (max (1+ (length gnus-sorted-header-list)))
660 (ignored (when (not gnus-visible-headers)
661 (cond ((stringp gnus-ignored-headers)
662 gnus-ignored-headers)
663 ((listp gnus-ignored-headers)
664 (mapconcat 'identity gnus-ignored-headers
667 (cond ((stringp gnus-visible-headers)
668 gnus-visible-headers)
669 ((and gnus-visible-headers
670 (listp gnus-visible-headers))
671 (mapconcat 'identity gnus-visible-headers "\\|"))))
672 (inhibit-point-motion-hooks t)
674 ;; First we narrow to just the headers.
676 (goto-char (point-min))
677 ;; Hide any "From " lines at the beginning of (mail) articles.
678 (while (looking-at "From ")
682 (delete-region (point-min) (point))
683 (gnus-article-hide-text (point-min) (point) props)))
684 ;; Then treat the rest of the header lines.
687 (if (search-forward "\n\n" nil t) ; if there's a body
688 (progn (forward-line -1) (point))
690 ;; Then we use the two regular expressions
691 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
692 ;; select which header lines is to remain visible in the
694 (goto-char (point-min))
695 (while (re-search-forward "^[^ \t]*:" nil t)
697 ;; Mark the rank of the header.
699 (point) (1+ (point)) 'message-rank
700 (if (or (and visible (looking-at visible))
702 (not (looking-at ignored))))
703 (gnus-article-header-rank)
706 (message-sort-headers-1)
707 (when (setq beg (text-property-any
708 (point-min) (point-max) 'message-rank (+ 2 max)))
709 ;; We make the unwanted headers invisible.
711 (delete-region beg (point-max))
712 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
713 (gnus-article-hide-text-type beg (point-max) 'headers))
714 ;; Work around XEmacs lossage.
715 (put-text-property (point-min) beg 'invisible nil))))))))
717 (defun article-hide-boring-headers (&optional arg)
718 "Toggle hiding of headers that aren't very interesting.
719 If given a negative prefix, always show; if given a positive prefix,
721 (interactive (gnus-article-hidden-arg))
722 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
723 (not gnus-show-all-headers))
726 (let ((buffer-read-only nil)
727 (list gnus-boring-article-headers)
728 (inhibit-point-motion-hooks t)
730 (nnheader-narrow-to-headers)
732 (setq elem (pop list))
733 (goto-char (point-min))
735 ;; Hide empty headers.
737 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
739 (gnus-article-hide-text-type
740 (progn (beginning-of-line) (point))
743 (if (re-search-forward "^[^ \t]" nil t)
747 ;; Hide boring Newsgroups header.
748 ((eq elem 'newsgroups)
749 (when (equal (gnus-fetch-field "newsgroups")
750 (gnus-group-real-name
751 (if (boundp 'gnus-newsgroup-name)
754 (gnus-article-hide-header "newsgroups")))
755 ((eq elem 'followup-to)
756 (when (equal (message-fetch-field "followup-to")
757 (message-fetch-field "newsgroups"))
758 (gnus-article-hide-header "followup-to")))
760 (let ((from (message-fetch-field "from"))
761 (reply-to (message-fetch-field "reply-to")))
766 (nth 1 (mail-extract-address-components from))
767 (nth 1 (mail-extract-address-components reply-to)))))
768 (gnus-article-hide-header "reply-to"))))
770 (let ((date (message-fetch-field "date")))
772 (< (gnus-days-between (current-time-string) date)
774 (gnus-article-hide-header "date"))))
776 (let ((to (message-fetch-field "to")))
777 (when (> (length to) 1024)
778 (gnus-article-hide-header "to"))))
781 (goto-char (point-min))
782 (while (re-search-forward "^to:" nil t)
783 (setq to-count (1+ to-count)))
785 (while (> to-count 0)
786 (goto-char (point-min))
788 (re-search-forward "^to:" nil nil to-count)
790 (narrow-to-region (point) (point-max))
791 (gnus-article-hide-header "to"))
792 (setq to-count (1- to-count)))))))))))))
794 (defun gnus-article-hide-header (header)
796 (goto-char (point-min))
797 (when (re-search-forward (concat "^" header ":") nil t)
798 (gnus-article-hide-text-type
799 (progn (beginning-of-line) (point))
802 (if (re-search-forward "^[^ \t]" nil t)
807 (defun article-treat-dumbquotes ()
808 "Translate M******** sm*rtq**t*s into proper text."
810 (article-translate-characters "\221\222\223\223" "`'\"\""))
812 (defun article-translate-characters (from to)
813 "Translate all characters in the body of the article according to FROM and TO.
814 FROM is a string of characters to translate from; to is a string of
815 characters to translate to."
817 (goto-char (point-min))
818 (when (search-forward "\n\n" nil t)
819 (let ((buffer-read-only nil)
820 (x (make-string 225 ?x))
822 (while (< (incf i) (length x))
825 (while (< i (length from))
826 (aset x (aref from i) (aref to i))
828 (translate-region (point) (point-max) x)))))
830 (defun article-treat-overstrike ()
831 "Translate overstrikes into bold text."
834 (goto-char (point-min))
835 (when (search-forward "\n\n" nil t)
836 (let ((buffer-read-only nil))
837 (while (search-forward "\b" nil t)
838 (let ((next (following-char))
839 (previous (char-after (- (point) 2))))
840 ;; We do the boldification/underlining by hiding the
841 ;; overstrikes and putting the proper text property
845 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
846 (put-text-property (point) (1+ (point)) 'face 'bold))
848 (gnus-article-hide-text-type
849 (1- (point)) (1+ (point)) 'overstrike)
851 (- (point) 2) (1- (point)) 'face 'underline))
853 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
855 (point) (1+ (point)) 'face 'underline)))))))))
857 (defun article-fill ()
858 "Format too long lines."
861 (let ((buffer-read-only nil))
863 (goto-char (point-min))
864 (search-forward "\n\n" nil t)
866 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
867 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
868 (adaptive-fill-mode t))
870 (and (>= (current-column) (min fill-column (window-width)))
871 (/= (preceding-char) ?:)
872 (fill-paragraph nil))
875 (defun article-remove-cr ()
876 "Remove carriage returns from an article."
879 (let ((buffer-read-only nil))
880 (goto-char (point-min))
881 (while (search-forward "\r" nil t)
882 (replace-match "" t t)))))
884 (defun article-remove-trailing-blank-lines ()
885 "Remove all trailing blank lines from the article."
888 (let ((buffer-read-only nil))
889 (goto-char (point-max))
893 (while (and (not (bobp))
894 (looking-at "^[ \t]*$"))
899 (defun article-display-x-face (&optional force)
900 "Look for an X-Face header and display it if present."
901 (interactive (list 'force))
903 ;; Delete the old process, if any.
904 (when (process-status "article-x-face")
905 (delete-process "article-x-face"))
906 (let ((inhibit-point-motion-hooks t)
910 (nnheader-narrow-to-headers)
911 (setq from (message-fetch-field "from"))
912 (goto-char (point-min))
913 (while (and gnus-article-x-face-command
916 ;; Check whether this face is censored.
917 (not gnus-article-x-face-too-ugly)
918 (and gnus-article-x-face-too-ugly from
919 (not (string-match gnus-article-x-face-too-ugly
921 ;; Has to be present.
922 (re-search-forward "^X-Face: " nil t))
923 ;; This used to try to do multiple faces (`while' instead of
924 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
925 ;; work (b) it can crash some versions of Emacs (c) are
926 ;; multiple faces really something to encourage?
927 (when (stringp gnus-article-x-face-command)
929 ;; We now have the area of the buffer where the X-Face is stored.
932 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
933 ;; We display the face.
934 (if (symbolp gnus-article-x-face-command)
935 ;; The command is a lisp function, so we call it.
936 (if (gnus-functionp gnus-article-x-face-command)
937 (funcall gnus-article-x-face-command beg end)
938 (error "%s is not a function" gnus-article-x-face-command))
939 ;; The command is a string, so we interpret the command
940 ;; as a, well, command, and fork it off.
941 (let ((process-connection-type nil))
942 (process-kill-without-query
944 "article-x-face" nil shell-file-name shell-command-switch
945 gnus-article-x-face-command))
946 (process-send-region "article-x-face" beg end)
947 (process-send-eof "article-x-face"))))))))))
949 (defun gnus-article-decode-mime-words ()
950 "Decode all MIME-encoded words in the article."
953 (set-buffer gnus-article-buffer)
954 (let ((inhibit-point-motion-hooks t)
956 (rfc2047-decode-region (point-min) (point-max)))))
958 (defun gnus-article-decode-charset ()
959 "Decode charset-encoded text in the article."
961 (when (featurep 'mule)
963 (set-buffer gnus-article-buffer)
964 (let* ((inhibit-point-motion-hooks t)
965 (ct (message-fetch-field "Content-Type"))
966 (charset (and ct (mm-content-type-charset ct)))
967 mule-charset buffer-read-only)
969 (goto-char (point-min))
970 (search-forward "\n\n" nil 'move)
971 (narrow-to-region (point) (point-max))
973 (setq mule-charset (mm-charset-to-coding-system charset))
974 (not (mm-coding-system-equal
975 buffer-file-coding-system mule-charset)))
976 (mm-decode-body (mm-charset-to-coding-system charset))))))))
978 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
979 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
980 (defun article-decode-rfc1522 ()
981 "Remove QP encoding from headers."
982 (let ((inhibit-point-motion-hooks t)
983 (buffer-read-only nil))
985 (message-narrow-to-head)
986 (rfc2047-decode-region (point-min) (point-max)))))
988 (defun article-de-quoted-unreadable (&optional force)
989 "Translate a quoted-printable-encoded article.
990 If FORCE, decode the article whether it is marked as quoted-printable
992 (interactive (list 'force))
994 (let ((buffer-read-only nil)
995 (type (gnus-fetch-field "content-transfer-encoding")))
996 (gnus-article-decode-rfc1522)
998 (and type (string-match "quoted-printable" (downcase type))))
999 (goto-char (point-min))
1000 (search-forward "\n\n" nil 'move)
1001 (quoted-printable-decode-region (point) (point-max))))))
1003 (defun article-mime-decode-quoted-printable-buffer ()
1004 "Decode Quoted-Printable in the current buffer."
1005 (quoted-printable-decode-region (point-min) (point-max)))
1007 (defun article-hide-pgp (&optional arg)
1008 "Toggle hiding of any PGP headers and signatures in the current article.
1009 If given a negative prefix, always show; if given a positive prefix,
1011 (interactive (gnus-article-hidden-arg))
1012 (unless (gnus-article-check-hidden-text 'pgp arg)
1014 (let ((inhibit-point-motion-hooks t)
1015 buffer-read-only beg end)
1017 (goto-char (point-min))
1018 ;; Hide the "header".
1019 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1020 (delete-region (1+ (match-beginning 0)) (match-end 0))
1022 ;; Hide the actual signature.
1023 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1024 (setq end (1+ (match-beginning 0)))
1027 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1029 ;; Perhaps we shouldn't hide to the end of the buffer
1030 ;; if there is no end to the signature?
1032 ;; Hide "- " PGP quotation markers.
1034 (narrow-to-region beg end)
1035 (goto-char (point-min))
1036 (while (re-search-forward "^- " nil t)
1038 (match-beginning 0) (match-end 0)))
1040 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1042 (defun article-hide-pem (&optional arg)
1043 "Toggle hiding of any PEM headers and signatures in the current article.
1044 If given a negative prefix, always show; if given a positive prefix,
1046 (interactive (gnus-article-hidden-arg))
1047 (unless (gnus-article-check-hidden-text 'pem arg)
1049 (let (buffer-read-only end)
1051 (goto-char (point-min))
1052 ;; hide the horrendously ugly "header".
1053 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1056 (setq end (1+ (match-beginning 0)))
1057 (gnus-article-hide-text-type
1059 (if (search-forward "\n\n" nil t)
1063 ;; hide the trailer as well
1064 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1067 (gnus-article-hide-text-type
1068 (match-beginning 0) (match-end 0) 'pem))))))
1070 (defun article-hide-signature (&optional arg)
1071 "Hide the signature in the current article.
1072 If given a negative prefix, always show; if given a positive prefix,
1074 (interactive (gnus-article-hidden-arg))
1075 (unless (gnus-article-check-hidden-text 'signature arg)
1078 (let ((buffer-read-only nil))
1079 (when (gnus-article-narrow-to-signature)
1080 (gnus-article-hide-text-type
1081 (point-min) (point-max) 'signature)))))))
1083 (defun article-strip-leading-blank-lines ()
1084 "Remove all blank lines from the beginning of the article."
1087 (let ((inhibit-point-motion-hooks t)
1089 (goto-char (point-min))
1090 (when (search-forward "\n\n" nil t)
1091 (while (and (not (eobp))
1092 (looking-at "[ \t]*$"))
1093 (gnus-delete-line))))))
1095 (defun article-strip-multiple-blank-lines ()
1096 "Replace consecutive blank lines with one empty line."
1099 (let ((inhibit-point-motion-hooks t)
1101 ;; First make all blank lines empty.
1102 (goto-char (point-min))
1103 (search-forward "\n\n" nil t)
1104 (while (re-search-forward "^[ \t]+$" nil t)
1105 (replace-match "" nil t))
1106 ;; Then replace multiple empty lines with a single empty line.
1107 (goto-char (point-min))
1108 (search-forward "\n\n" nil t)
1109 (while (re-search-forward "\n\n\n+" nil t)
1110 (replace-match "\n\n" t t)))))
1112 (defun article-strip-leading-space ()
1113 "Remove all white space from the beginning of the lines in the article."
1116 (let ((inhibit-point-motion-hooks t)
1118 (goto-char (point-min))
1119 (search-forward "\n\n" nil t)
1120 (while (re-search-forward "^[ \t]+" nil t)
1121 (replace-match "" t t)))))
1123 (defun article-strip-blank-lines ()
1124 "Strip leading, trailing and multiple blank lines."
1126 (article-strip-leading-blank-lines)
1127 (article-remove-trailing-blank-lines)
1128 (article-strip-multiple-blank-lines))
1130 (defun article-strip-all-blank-lines ()
1131 "Strip all blank lines."
1134 (let ((inhibit-point-motion-hooks t)
1136 (goto-char (point-min))
1137 (search-forward "\n\n" nil t)
1138 (while (re-search-forward "^[ \t]*\n" nil t)
1139 (replace-match "" t t)))))
1141 (defvar mime::preview/content-list)
1142 (defvar mime::preview-content-info/point-min)
1143 (defun gnus-article-narrow-to-signature ()
1144 "Narrow to the signature; return t if a signature is found, else nil."
1146 (let ((inhibit-point-motion-hooks t))
1147 (when (and (boundp 'mime::preview/content-list)
1148 mime::preview/content-list)
1149 ;; We have a MIMEish article, so we use the MIME data to narrow.
1150 (let ((pcinfo (car (last mime::preview/content-list))))
1153 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1156 (when (gnus-article-search-signature)
1158 ;; Check whether we have some limits to what we consider
1159 ;; to be a signature.
1160 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1161 (list gnus-signature-limit)))
1163 (while (setq limit (pop limits))
1164 (if (or (and (integerp limit)
1165 (< (- (point-max) (point)) limit))
1167 (< (count-lines (point) (point-max)) limit))
1168 (and (gnus-functionp limit)
1170 (and (stringp limit)
1171 (not (re-search-forward limit nil t))))
1172 () ; This limit did not succeed.
1176 (narrow-to-region (point) (point-max))
1179 (defun gnus-article-search-signature ()
1180 "Search the current buffer for the signature separator.
1181 Put point at the beginning of the signature separator."
1182 (let ((cur (point)))
1183 (goto-char (point-max))
1184 (if (if (stringp gnus-signature-separator)
1185 (re-search-backward gnus-signature-separator nil t)
1186 (let ((seps gnus-signature-separator))
1188 (not (re-search-backward (car seps) nil t)))
1196 (autoload 'w3-display "w3-parse")
1197 (autoload 'w3-do-setup "w3" "" t)
1198 (autoload 'w3-region "w3-display" "" t))
1200 (defun gnus-article-treat-html ()
1203 (let ((cbuf (current-buffer)))
1204 (set-buffer gnus-article-buffer)
1205 (let (buf buffer-read-only b e)
1207 (goto-char (point-min))
1209 (if (search-forward "\n\n" nil t)
1212 (setq e (point-max)))
1214 (insert-buffer-substring gnus-article-buffer b e)
1216 (save-window-excursion
1217 (w3-region (point-min) (point-max))
1218 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1220 (delete-region (point-min) (point-max))
1223 (goto-char (point-min))
1224 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1225 (set-buffer cbuf))))
1227 (defun gnus-article-hidden-arg ()
1228 "Return the current prefix arg as a number, or 0 if no prefix."
1229 (list (if current-prefix-arg
1230 (prefix-numeric-value current-prefix-arg)
1233 (defun gnus-article-check-hidden-text (type arg)
1234 "Return nil if hiding is necessary.
1235 Arg can be nil or a number. Nil and positive means hide, negative
1236 means show, 0 means toggle."
1240 (let ((hide (gnus-article-hidden-text-p type)))
1246 (gnus-article-show-hidden-text type))
1248 (if (eq hide 'hidden)
1249 (gnus-article-show-hidden-text type)
1252 (defun gnus-article-hidden-text-p (type)
1253 "Say whether the current buffer contains hidden text of type TYPE."
1254 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1256 (not (get-text-property pos 'invisible)))
1258 (text-property-any (1+ pos) (point-max) 'article-type type)))
1263 (defun gnus-article-show-hidden-text (type &optional hide)
1264 "Show all hidden text of type TYPE.
1265 If HIDE, hide the text instead."
1267 (let ((buffer-read-only nil)
1268 (inhibit-point-motion-hooks t)
1271 (while (setq beg (text-property-any end (point-max) 'article-type type))
1274 (text-property-not-all beg (point-max) 'article-type type)
1277 (gnus-article-hide-text beg end gnus-hidden-properties)
1278 (gnus-article-unhide-text beg end))
1282 (defconst article-time-units
1283 `((year . ,(* 365.25 24 60 60))
1284 (week . ,(* 7 24 60 60))
1285 (day . ,(* 24 60 60))
1289 "Mapping from time units to seconds.")
1291 (defun article-date-ut (&optional type highlight header)
1292 "Convert DATE date to universal time in the current article.
1293 If TYPE is `local', convert to local time; if it is `lapsed', output
1294 how much time has lapsed since DATE."
1295 (interactive (list 'ut t))
1296 (let* ((header (or header
1297 (mail-header-date gnus-current-headers)
1298 (message-fetch-field "date")
1300 (date (if (vectorp header) (mail-header-date header)
1302 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1303 (inhibit-point-motion-hooks t)
1304 bface eface newline)
1305 (when (and date (not (string= date "")))
1308 (nnheader-narrow-to-headers)
1309 (let ((buffer-read-only nil))
1310 ;; Delete any old Date headers.
1311 (if (re-search-forward date-regexp nil t)
1313 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1314 eface (get-text-property (1- (gnus-point-at-eol))
1316 (delete-region (progn (beginning-of-line) (point))
1317 (progn (end-of-line) (point)))
1318 (beginning-of-line))
1319 (goto-char (point-max))
1321 (insert (article-make-date-line date type))
1324 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1325 (put-text-property (match-beginning 1) (1+ (match-end 1))
1327 (put-text-property (match-beginning 2) (match-end 2)
1331 (insert "\n"))))))))
1333 (defun article-make-date-line (date type)
1334 "Return a DATE line of TYPE."
1336 ;; Convert to the local timezone. We have to slap a
1337 ;; `condition-case' round the calls to the timezone
1338 ;; functions since they aren't particularly resistant to
1341 (concat "Date: " (condition-case ()
1342 (timezone-make-date-arpa-standard date)
1344 ;; Convert to Universal Time.
1348 (timezone-make-date-arpa-standard date nil "UT")
1350 ;; Get the original date from the article.
1351 ((eq type 'original)
1352 (concat "Date: " date))
1353 ;; Let the user define the format.
1355 (if (gnus-functionp gnus-article-time-format)
1357 gnus-article-time-format
1360 (timezone-make-date-arpa-standard
1364 (format-time-string gnus-article-time-format
1367 (timezone-make-date-arpa-standard
1368 date nil "UT")))))))
1373 (format-time-string "%Y%M%DT%h%m%s"
1376 (timezone-make-date-arpa-standard
1378 ;; Do an X-Sent lapsed format.
1380 ;; If the date is seriously mangled, the timezone functions are
1381 ;; liable to bug out, so we ignore all errors.
1382 (let* ((now (current-time))
1387 (timezone-make-date-arpa-standard
1388 (current-time-string now)
1389 (current-time-zone now) "UT"))
1391 (timezone-make-date-arpa-standard
1393 (real-sec (and real-time
1394 (+ (* (float (car real-time)) 65536)
1396 (sec (and real-time (abs real-sec)))
1406 ;; This is a bit convoluted, but basically we go
1407 ;; through the time units for years, weeks, etc,
1408 ;; and divide things to see whether that results
1409 ;; in positive answers.
1412 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1413 ;; The (remaining) seconds are too few to
1414 ;; be divided into this time unit.
1416 ;; It's big enough, so we output it.
1417 (setq sec (- sec (* num (cdr unit))))
1419 (concat (if prev ", " "") (int-to-string
1421 " " (symbol-name (car unit))
1422 (if (> num 1) "s" ""))
1424 article-time-units "")
1425 ;; If dates are odd, then it might appear like the
1426 ;; article was sent in the future.
1429 " in the future"))))))
1431 (error "Unknown conversion type: %s" type))))
1433 (defun article-date-local (&optional highlight)
1434 "Convert the current article date to the local timezone."
1435 (interactive (list t))
1436 (article-date-ut 'local highlight))
1438 (defun article-date-original (&optional highlight)
1439 "Convert the current article date to what it was originally.
1440 This is only useful if you have used some other date conversion
1441 function and want to see what the date was before converting."
1442 (interactive (list t))
1443 (article-date-ut 'original highlight))
1445 (defun article-date-lapsed (&optional highlight)
1446 "Convert the current article date to time lapsed since it was sent."
1447 (interactive (list t))
1448 (article-date-ut 'lapsed highlight))
1450 (defun article-update-date-lapsed ()
1451 "Function to be run from a timer to update the lapsed time line."
1452 (let (deactivate-mark)
1455 (when (gnus-buffer-live-p gnus-article-buffer)
1456 (set-buffer gnus-article-buffer)
1457 (goto-char (point-min))
1458 (when (re-search-forward "^X-Sent:" nil t)
1459 (article-date-lapsed t)))))))
1461 (defun gnus-start-date-timer (&optional n)
1462 "Start a timer to update the X-Sent header in the article buffers.
1463 The numerical prefix says how frequently (in seconds) the function
1468 (gnus-stop-date-timer)
1469 (setq article-lapsed-timer
1470 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1472 (defun gnus-stop-date-timer ()
1473 "Stop the X-Sent timer."
1475 (when article-lapsed-timer
1476 (nnheader-cancel-timer article-lapsed-timer)
1477 (setq article-lapsed-timer nil)))
1479 (defun article-date-user (&optional highlight)
1480 "Convert the current article date to the user-defined format.
1481 This format is defined by the `gnus-article-time-format' variable."
1482 (interactive (list t))
1483 (article-date-ut 'user highlight))
1485 (defun article-date-iso8601 (&optional highlight)
1486 "Convert the current article date to ISO8601."
1487 (interactive (list t))
1488 (article-date-ut 'iso8601 highlight))
1490 (defun article-show-all ()
1491 "Show all hidden text in the article buffer."
1494 (let ((buffer-read-only nil))
1495 (gnus-article-unhide-text (point-min) (point-max)))))
1497 (defun article-emphasize (&optional arg)
1498 "Emphasize text according to `gnus-emphasis-alist'."
1499 (interactive (gnus-article-hidden-arg))
1500 (unless (gnus-article-check-hidden-text 'emphasis arg)
1502 (let ((alist gnus-emphasis-alist)
1503 (buffer-read-only nil)
1504 (props (append '(article-type emphasis)
1505 gnus-hidden-properties))
1506 regexp elem beg invisible visible face)
1507 (goto-char (point-min))
1508 (search-forward "\n\n" nil t)
1510 (while (setq elem (pop alist))
1512 (setq regexp (car elem)
1513 invisible (nth 1 elem)
1514 visible (nth 2 elem)
1516 (while (re-search-forward regexp nil t)
1517 (when (and (match-beginning visible) (match-beginning invisible))
1518 (gnus-article-hide-text
1519 (match-beginning invisible) (match-end invisible) props)
1520 (gnus-article-unhide-text-type
1521 (match-beginning visible) (match-end visible) 'emphasis)
1522 (gnus-put-text-property-excluding-newlines
1523 (match-beginning visible) (match-end visible) 'face face)
1524 (goto-char (match-end invisible)))))))))
1526 (defvar gnus-summary-article-menu)
1527 (defvar gnus-summary-post-menu)
1529 ;;; Saving functions.
1531 (defun gnus-article-save (save-buffer file &optional num)
1532 "Save the currently selected article."
1533 (unless gnus-save-all-headers
1534 ;; Remove headers according to `gnus-saved-headers'.
1535 (let ((gnus-visible-headers
1536 (or gnus-saved-headers gnus-visible-headers))
1537 (gnus-article-buffer save-buffer))
1539 (set-buffer save-buffer)
1540 (article-hide-headers 1 t))))
1541 (save-window-excursion
1542 (if (not gnus-default-article-saver)
1543 (error "No default saver is defined")
1544 ;; !!! Magic! The saving functions all save
1545 ;; `gnus-original-article-buffer' (or so they think), but we
1546 ;; bind that variable to our save-buffer.
1547 (set-buffer gnus-article-buffer)
1548 (let* ((gnus-save-article-buffer save-buffer)
1551 ((not gnus-prompt-before-saving) 'default)
1552 ((eq gnus-prompt-before-saving 'always) nil)
1554 (gnus-number-of-articles-to-be-saved
1555 (when (eq gnus-prompt-before-saving t)
1557 (set-buffer gnus-article-current-summary)
1558 (funcall gnus-default-article-saver filename)))))
1560 (defun gnus-read-save-file-name (prompt &optional filename
1561 function group headers variable)
1563 (funcall function group headers (symbol-value variable)))
1568 ((eq filename 'default)
1574 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1577 (if (and gnus-number-of-articles-to-be-saved
1578 (> gnus-number-of-articles-to-be-saved 1))
1579 (format "these %d articles"
1580 gnus-number-of-articles-to-be-saved)
1583 ;; Let the split methods have their say.
1585 ;; No split name was found.
1588 (concat prompt " (default "
1589 (file-name-nondirectory default-name) ") ")
1590 (file-name-directory default-name)
1592 ;; A single group name is returned.
1593 ((stringp split-name)
1595 (funcall function split-name headers
1596 (symbol-value variable)))
1598 (concat prompt " (default "
1599 (file-name-nondirectory default-name) ") ")
1600 (file-name-directory default-name)
1602 ;; A single split name was found
1603 ((= 1 (length split-name))
1604 (let* ((name (expand-file-name
1605 (car split-name) gnus-article-save-directory))
1606 (dir (cond ((file-directory-p name)
1607 (file-name-as-directory name))
1608 ((file-exists-p name) name)
1609 (t gnus-article-save-directory))))
1611 (concat prompt " (default " name ") ")
1613 ;; A list of splits was found.
1615 (setq split-name (nreverse split-name))
1617 (let ((file-name-history
1618 (nconc split-name file-name-history)))
1622 (concat prompt " (`M-p' for defaults) ")
1623 gnus-article-save-directory
1625 gnus-article-save-directory)))
1626 (car (push result file-name-history)))))))
1627 ;; Create the directory.
1628 (gnus-make-directory (file-name-directory file))
1629 ;; If we have read a directory, we append the default file name.
1630 (when (file-directory-p file)
1631 (setq file (concat (file-name-as-directory file)
1632 (file-name-nondirectory default-name))))
1633 ;; Possibly translate some characters.
1634 (nnheader-translate-file-chars file)))))
1635 (gnus-make-directory (file-name-directory result))
1636 (set variable result)))
1638 (defun gnus-article-archive-name (group)
1639 "Return the first instance of an \"Archive-name\" in the current buffer."
1640 (let ((case-fold-search t))
1641 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1642 (nnheader-concat gnus-article-save-directory
1643 (match-string 1)))))
1645 (defun gnus-article-nndoc-name (group)
1646 "If GROUP is an nndoc group, return the name of the parent group."
1647 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1648 (gnus-group-get-parameter group 'save-article-group)))
1650 (defun gnus-summary-save-in-rmail (&optional filename)
1651 "Append this article to Rmail file.
1652 Optional argument FILENAME specifies file name.
1653 Directory to save to is default to `gnus-article-save-directory'."
1654 (setq filename (gnus-read-save-file-name
1655 "Save %s in rmail file:" filename
1656 gnus-rmail-save-name gnus-newsgroup-name
1657 gnus-current-headers 'gnus-newsgroup-last-rmail))
1658 (gnus-eval-in-buffer-window gnus-save-article-buffer
1662 (gnus-output-to-rmail filename))))
1665 (defun gnus-summary-save-in-mail (&optional filename)
1666 "Append this article to Unix mail file.
1667 Optional argument FILENAME specifies file name.
1668 Directory to save to is default to `gnus-article-save-directory'."
1669 (setq filename (gnus-read-save-file-name
1670 "Save %s in Unix mail file:" filename
1671 gnus-mail-save-name gnus-newsgroup-name
1672 gnus-current-headers 'gnus-newsgroup-last-mail))
1673 (gnus-eval-in-buffer-window gnus-save-article-buffer
1677 (if (and (file-readable-p filename)
1678 (mail-file-babyl-p filename))
1679 (gnus-output-to-rmail filename t)
1680 (gnus-output-to-mail filename)))))
1683 (defun gnus-summary-save-in-file (&optional filename overwrite)
1684 "Append this article to file.
1685 Optional argument FILENAME specifies file name.
1686 Directory to save to is default to `gnus-article-save-directory'."
1687 (setq filename (gnus-read-save-file-name
1688 "Save %s in file:" filename
1689 gnus-file-save-name gnus-newsgroup-name
1690 gnus-current-headers 'gnus-newsgroup-last-file))
1691 (gnus-eval-in-buffer-window gnus-save-article-buffer
1695 (when (and overwrite
1696 (file-exists-p filename))
1697 (delete-file filename))
1698 (gnus-output-to-file filename))))
1701 (defun gnus-summary-write-to-file (&optional filename)
1702 "Write this article to a file.
1703 Optional argument FILENAME specifies file name.
1704 The directory to save in defaults to `gnus-article-save-directory'."
1705 (gnus-summary-save-in-file nil t))
1707 (defun gnus-summary-save-body-in-file (&optional filename)
1708 "Append this article body to a file.
1709 Optional argument FILENAME specifies file name.
1710 The directory to save in defaults to `gnus-article-save-directory'."
1711 (setq filename (gnus-read-save-file-name
1712 "Save %s body in file:" filename
1713 gnus-file-save-name gnus-newsgroup-name
1714 gnus-current-headers 'gnus-newsgroup-last-file))
1715 (gnus-eval-in-buffer-window gnus-save-article-buffer
1719 (goto-char (point-min))
1720 (when (search-forward "\n\n" nil t)
1721 (narrow-to-region (point) (point-max)))
1722 (gnus-output-to-file filename))))
1725 (defun gnus-summary-save-in-pipe (&optional command)
1726 "Pipe this article to subprocess."
1728 (cond ((eq command 'default)
1729 gnus-last-shell-command)
1733 "Shell command on %s: "
1734 (if (and gnus-number-of-articles-to-be-saved
1735 (> gnus-number-of-articles-to-be-saved 1))
1736 (format "these %d articles"
1737 gnus-number-of-articles-to-be-saved)
1739 gnus-last-shell-command))))
1740 (when (string-equal command "")
1741 (setq command gnus-last-shell-command))
1742 (gnus-eval-in-buffer-window gnus-article-buffer
1745 (shell-command-on-region (point-min) (point-max) command nil)))
1746 (setq gnus-last-shell-command command))
1748 ;;; Article file names when saving.
1750 (defun gnus-capitalize-newsgroup (newsgroup)
1751 "Capitalize NEWSGROUP name."
1752 (when (not (zerop (length newsgroup)))
1753 (concat (char-to-string (upcase (aref newsgroup 0)))
1754 (substring newsgroup 1))))
1756 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1757 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1758 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1759 Otherwise, it is like ~/News/news/group/num."
1762 (concat (if (gnus-use-long-file-name 'not-save)
1763 (gnus-capitalize-newsgroup newsgroup)
1764 (gnus-newsgroup-directory-form newsgroup))
1765 "/" (int-to-string (mail-header-number headers)))
1766 gnus-article-save-directory)))
1768 (string-equal (file-name-directory default)
1769 (file-name-directory last-file))
1770 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1772 (or last-file default))))
1774 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1775 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1776 If variable `gnus-use-long-file-name' is non-nil, it is
1777 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1780 (concat (if (gnus-use-long-file-name 'not-save)
1782 (gnus-newsgroup-directory-form newsgroup))
1783 "/" (int-to-string (mail-header-number headers)))
1784 gnus-article-save-directory)))
1786 (string-equal (file-name-directory default)
1787 (file-name-directory last-file))
1788 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1790 (or last-file default))))
1792 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1793 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1794 If variable `gnus-use-long-file-name' is non-nil, it is
1795 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1798 (if (gnus-use-long-file-name 'not-save)
1799 (gnus-capitalize-newsgroup newsgroup)
1800 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1801 gnus-article-save-directory)))
1803 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1804 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1805 If variable `gnus-use-long-file-name' is non-nil, it is
1806 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1809 (if (gnus-use-long-file-name 'not-save)
1811 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1812 gnus-article-save-directory)))
1819 (setq afunc (car func)
1822 gfunc (intern (format "gnus-%s" func))))
1824 (if (not (fboundp afunc))
1826 `(lambda (&optional interactive &rest args)
1827 ,(documentation afunc t)
1828 (interactive (list t))
1830 (set-buffer gnus-article-buffer)
1832 (call-interactively ',afunc)
1833 (apply ',afunc args))))))))
1834 '(article-hide-headers
1835 article-hide-boring-headers
1836 article-treat-overstrike
1837 (article-fill . gnus-article-word-wrap)
1839 article-display-x-face
1840 article-de-quoted-unreadable
1841 article-mime-decode-quoted-printable
1844 article-hide-signature
1845 article-remove-trailing-blank-lines
1846 article-strip-leading-blank-lines
1847 article-strip-multiple-blank-lines
1848 article-strip-leading-space
1849 article-strip-blank-lines
1850 article-strip-all-blank-lines
1852 article-date-iso8601
1853 article-date-original
1858 article-treat-dumbquotes
1859 (article-show-all . gnus-article-show-all-headers))))
1862 ;;; Gnus article mode
1865 (put 'gnus-article-mode 'mode-class 'special)
1867 (gnus-define-keys gnus-article-mode-map
1868 " " gnus-article-goto-next-page
1869 "\177" gnus-article-goto-prev-page
1870 [delete] gnus-article-goto-prev-page
1871 "\C-c^" gnus-article-refer-article
1872 "h" gnus-article-show-summary
1873 "s" gnus-article-show-summary
1874 "\C-c\C-m" gnus-article-mail
1875 "?" gnus-article-describe-briefly
1876 gnus-mouse-2 gnus-article-push-button
1877 "\r" gnus-article-press-button
1878 "\t" gnus-article-next-button
1879 "\M-\t" gnus-article-prev-button
1880 "e" gnus-article-edit
1881 "<" beginning-of-buffer
1883 "\C-c\C-i" gnus-info-find-node
1886 "\C-d" gnus-article-read-summary-keys
1887 "\M-*" gnus-article-read-summary-keys
1888 "\M-#" gnus-article-read-summary-keys
1889 "\M-^" gnus-article-read-summary-keys
1890 "\M-g" gnus-article-read-summary-keys)
1892 (substitute-key-definition
1893 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1895 (defun gnus-article-make-menu-bar ()
1896 (gnus-turn-off-edit-menu 'article)
1897 (unless (boundp 'gnus-article-article-menu)
1899 gnus-article-article-menu gnus-article-mode-map ""
1901 ["Scroll forwards" gnus-article-goto-next-page t]
1902 ["Scroll backwards" gnus-article-goto-prev-page t]
1903 ["Show summary" gnus-article-show-summary t]
1904 ["Fetch Message-ID at point" gnus-article-refer-article t]
1905 ["Mail to address at point" gnus-article-mail t]
1906 ["Send a bug report" gnus-bug t]))
1909 gnus-article-treatment-menu gnus-article-mode-map ""
1911 ["Hide headers" gnus-article-hide-headers t]
1912 ["Hide signature" gnus-article-hide-signature t]
1913 ["Hide citation" gnus-article-hide-citation t]
1914 ["Treat overstrike" gnus-article-treat-overstrike t]
1915 ["Remove carriage return" gnus-article-remove-cr t]
1916 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1918 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1920 (when (boundp 'gnus-summary-post-menu)
1921 (define-key gnus-article-mode-map [menu-bar post]
1922 (cons "Post" gnus-summary-post-menu)))
1924 (gnus-run-hooks 'gnus-article-menu-hook)))
1926 (defun gnus-article-mode ()
1927 "Major mode for displaying an article.
1929 All normal editing commands are switched off.
1931 The following commands are available in addition to all summary mode
1933 \\<gnus-article-mode-map>
1934 \\[gnus-article-next-page]\t Scroll the article one page forwards
1935 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1936 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1937 \\[gnus-article-show-summary]\t Display the summary buffer
1938 \\[gnus-article-mail]\t Send a reply to the address near point
1939 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1940 \\[gnus-info-find-node]\t Go to the Gnus info node"
1942 (when (gnus-visual-p 'article-menu 'menu)
1943 (gnus-article-make-menu-bar))
1944 (gnus-simplify-mode-line)
1945 (setq mode-name "Article")
1946 (setq major-mode 'gnus-article-mode)
1947 (make-local-variable 'minor-mode-alist)
1948 (unless (assq 'gnus-show-mime minor-mode-alist)
1949 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1950 (use-local-map gnus-article-mode-map)
1951 (gnus-update-format-specifications nil 'article-mode)
1952 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1953 (make-local-variable 'gnus-page-broken)
1954 (make-local-variable 'gnus-button-marker-list)
1955 (make-local-variable 'gnus-article-current-summary)
1956 (gnus-set-default-directory)
1957 (buffer-disable-undo (current-buffer))
1958 (setq buffer-read-only t)
1959 (set-syntax-table gnus-article-mode-syntax-table)
1960 (mm-enable-multibyte)
1961 (gnus-run-hooks 'gnus-article-mode-hook))
1963 (defun gnus-article-setup-buffer ()
1964 "Initialize the article buffer."
1965 (let* ((name (if gnus-single-article-buffer "*Article*"
1966 (concat "*Article " gnus-newsgroup-name "*")))
1968 (progn (string-match "\\*Article" name)
1969 (concat " *Original Article"
1970 (substring name (match-end 0))))))
1971 (setq gnus-article-buffer name)
1972 (setq gnus-original-article-buffer original)
1973 ;; This might be a variable local to the summary buffer.
1974 (unless gnus-single-article-buffer
1976 (set-buffer gnus-summary-buffer)
1977 (setq gnus-article-buffer name)
1978 (setq gnus-original-article-buffer original)
1979 (gnus-set-global-variables)))
1980 ;; Init original article buffer.
1982 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1983 (buffer-disable-undo (current-buffer))
1984 (setq major-mode 'gnus-original-article-mode)
1985 (make-local-variable 'gnus-original-article))
1986 (if (get-buffer name)
1989 (buffer-disable-undo (current-buffer))
1990 (setq buffer-read-only t)
1991 (unless (eq major-mode 'gnus-article-mode)
1992 (gnus-article-mode))
1995 (set-buffer (gnus-get-buffer-create name))
1997 (make-local-variable 'gnus-summary-buffer)
1998 (current-buffer)))))
2000 ;; Set article window start at LINE, where LINE is the number of lines
2001 ;; from the head of the article.
2002 (defun gnus-article-set-window-start (&optional line)
2004 (get-buffer-window gnus-article-buffer t)
2006 (set-buffer gnus-article-buffer)
2007 (goto-char (point-min))
2010 (gnus-message 6 "Moved to bookmark")
2011 (search-forward "\n\n" nil t)
2015 (defun gnus-article-prepare (article &optional all-headers header)
2016 "Prepare ARTICLE in article mode buffer.
2017 ARTICLE should either be an article number or a Message-ID.
2018 If ARTICLE is an id, HEADER should be the article headers.
2019 If ALL-HEADERS is non-nil, no headers are hidden."
2021 ;; Make sure we start in a summary buffer.
2022 (unless (eq major-mode 'gnus-summary-mode)
2023 (set-buffer gnus-summary-buffer))
2024 (setq gnus-summary-buffer (current-buffer))
2025 (let* ((gnus-article (if header (mail-header-number header) article))
2026 (summary-buffer (current-buffer))
2027 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2028 (group gnus-newsgroup-name)
2031 (gnus-article-setup-buffer)
2032 (set-buffer gnus-article-buffer)
2033 ;; Deactivate active regions.
2034 (when (and (boundp 'transient-mark-mode)
2035 transient-mark-mode)
2036 (setq mark-active nil))
2037 (if (not (setq result (let ((buffer-read-only nil))
2038 (gnus-request-article-this-buffer
2040 ;; There is no such article.
2042 (when (and (numberp article)
2043 (not (memq article gnus-newsgroup-sparse)))
2044 (setq gnus-article-current
2045 (cons gnus-newsgroup-name article))
2046 (set-buffer gnus-summary-buffer)
2047 (setq gnus-current-article article)
2048 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2050 (gnus-summary-set-agent-mark article)
2051 (message "Message marked for downloading"))
2052 (gnus-summary-mark-article article gnus-canceled-mark)
2053 (unless (memq article gnus-newsgroup-sparse)
2055 "No such article (may have expired or been canceled)")))))
2056 (if (or (eq result 'pseudo)
2057 (eq result 'nneething))
2060 (set-buffer summary-buffer)
2061 (push article gnus-newsgroup-history)
2062 (setq gnus-last-article gnus-current-article
2063 gnus-current-article 0
2064 gnus-current-headers nil
2065 gnus-article-current nil)
2066 (if (eq result 'nneething)
2067 (gnus-configure-windows 'summary)
2068 (gnus-configure-windows 'article))
2069 (gnus-set-global-variables))
2070 (gnus-set-mode-line 'article))
2071 ;; The result from the `request' was an actual article -
2072 ;; or at least some text that is now displayed in the
2074 (when (and (numberp article)
2075 (not (eq article gnus-current-article)))
2076 ;; Seems like a new article has been selected.
2077 ;; `gnus-current-article' must be an article number.
2079 (set-buffer summary-buffer)
2080 (push article gnus-newsgroup-history)
2081 (setq gnus-last-article gnus-current-article
2082 gnus-current-article article
2083 gnus-current-headers
2084 (gnus-summary-article-header gnus-current-article)
2085 gnus-article-current
2086 (cons gnus-newsgroup-name gnus-current-article))
2087 (unless (vectorp gnus-current-headers)
2088 (setq gnus-current-headers nil))
2089 (gnus-summary-goto-subject gnus-current-article)
2090 (when (gnus-summary-show-thread)
2091 ;; If the summary buffer really was folded, the
2092 ;; previous goto may not actually have gone to
2093 ;; the right article, but the thread root instead.
2095 (gnus-summary-goto-subject gnus-current-article))
2096 (gnus-run-hooks 'gnus-mark-article-hook)
2097 (gnus-set-mode-line 'summary)
2098 (when (gnus-visual-p 'article-highlight 'highlight)
2099 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2100 ;; Set the global newsgroup variables here.
2101 ;; Suggested by Jim Sisolak
2102 ;; <sisolak@trans4.neep.wisc.edu>.
2103 (gnus-set-global-variables)
2104 (setq gnus-have-all-headers
2105 (or all-headers gnus-show-all-headers))))
2106 (when (or (numberp article)
2108 ;; Hooks for getting information from the article.
2109 ;; This hook must be called before being narrowed.
2110 (let (buffer-read-only)
2111 (gnus-run-hooks 'gnus-tmp-internal-hook)
2112 (gnus-run-hooks 'gnus-article-prepare-hook)
2113 ;; Decode MIME message.
2114 (when gnus-show-mime
2115 (if (or (not gnus-strict-mime)
2116 (gnus-fetch-field "Mime-Version"))
2117 (let ((coding-system-for-write 'binary)
2118 (coding-system-for-read 'binary))
2119 (funcall gnus-show-mime-method))
2120 (funcall gnus-decode-encoded-word-method)))
2121 ;; Perform the article display hooks.
2122 (gnus-run-hooks 'gnus-article-display-hook))
2124 (goto-char (point-min))
2125 (setq gnus-page-broken
2126 (when gnus-break-pages
2127 (gnus-narrow-to-page)
2129 (gnus-set-mode-line 'article)
2130 (gnus-configure-windows 'article)
2131 (goto-char (point-min))
2132 (search-forward "\n\n" nil t)
2133 (set-window-point (get-buffer-window (current-buffer)) (point))
2136 (defun gnus-article-wash-status ()
2137 "Return a string which display status of article washing."
2139 (set-buffer gnus-article-buffer)
2140 (let ((cite (gnus-article-hidden-text-p 'cite))
2141 (headers (gnus-article-hidden-text-p 'headers))
2142 (boring (gnus-article-hidden-text-p 'boring-headers))
2143 (pgp (gnus-article-hidden-text-p 'pgp))
2144 (pem (gnus-article-hidden-text-p 'pem))
2145 (signature (gnus-article-hidden-text-p 'signature))
2146 (overstrike (gnus-article-hidden-text-p 'overstrike))
2147 (emphasis (gnus-article-hidden-text-p 'emphasis))
2148 (mime gnus-show-mime))
2149 (format "%c%c%c%c%c%c%c"
2151 (if (or headers boring) ?h ? )
2152 (if (or pgp pem) ?p ? )
2153 (if signature ?s ? )
2154 (if overstrike ?o ? )
2156 (if emphasis ?e ? )))))
2158 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2160 (defun gnus-article-maybe-hide-headers ()
2161 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2162 Provided for backwards compatibility."
2163 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2165 (gnus-article-hide-headers)))
2169 (defun gnus-output-to-file (file-name)
2170 "Append the current article to a file named FILE-NAME."
2171 (let ((artbuf (current-buffer)))
2173 (insert-buffer-substring artbuf)
2174 ;; Append newline at end of the buffer as separator, and then
2176 (goto-char (point-max))
2178 (append-to-file (point-min) (point-max) file-name)
2181 (defun gnus-narrow-to-page (&optional arg)
2182 "Narrow the article buffer to a page.
2183 If given a numerical ARG, move forward ARG pages."
2185 (setq arg (if arg (prefix-numeric-value arg) 0))
2187 (set-buffer gnus-article-buffer)
2188 (goto-char (point-min))
2190 ;; Remove any old next/prev buttons.
2191 (when (gnus-visual-p 'page-marker)
2192 (let ((buffer-read-only nil))
2193 (gnus-remove-text-with-property 'gnus-prev)
2194 (gnus-remove-text-with-property 'gnus-next)))
2197 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2199 (re-search-forward page-delimiter nil 'move arg)))
2200 (goto-char (match-end 0)))
2203 (if (re-search-forward page-delimiter nil 'move)
2206 (when (and (gnus-visual-p 'page-marker)
2207 (not (= (point-min) 1)))
2209 (goto-char (point-min))
2210 (gnus-insert-prev-page-button)))
2211 (when (and (gnus-visual-p 'page-marker)
2212 (< (+ (point-max) 2) (buffer-size)))
2214 (goto-char (point-max))
2215 (gnus-insert-next-page-button)))))
2217 ;; Article mode commands
2219 (defun gnus-article-goto-next-page ()
2220 "Show the next page of the article."
2222 (when (gnus-article-next-page)
2223 (goto-char (point-min))
2224 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2226 (defun gnus-article-goto-prev-page ()
2227 "Show the next page of the article."
2229 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2230 (gnus-article-prev-page nil)))
2232 (defun gnus-article-next-page (&optional lines)
2233 "Show the next page of the current article.
2234 If end of article, return non-nil. Otherwise return nil.
2235 Argument LINES specifies lines to be scrolled up."
2237 (move-to-window-line -1)
2240 (and (pos-visible-in-window-p) ;Not continuation line.
2242 ;; Nothing in this page.
2243 (if (or (not gnus-page-broken)
2246 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2248 (gnus-narrow-to-page 1) ;Go to next page.
2250 ;; More in this page.
2251 (let ((scroll-in-place nil))
2255 ;; Long lines may cause an end-of-buffer error.
2256 (goto-char (point-max)))))
2257 (move-to-window-line 0)
2260 (defun gnus-article-prev-page (&optional lines)
2261 "Show previous page of current article.
2262 Argument LINES specifies lines to be scrolled down."
2264 (move-to-window-line 0)
2265 (if (and gnus-page-broken
2267 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2269 (gnus-narrow-to-page -1) ;Go to previous page.
2270 (goto-char (point-max))
2272 (let ((scroll-in-place nil))
2276 (beginning-of-buffer
2277 (goto-char (point-min))))
2278 (move-to-window-line 0)))))
2280 (defun gnus-article-refer-article ()
2281 "Read article specified by message-id around point."
2283 (let ((point (point)))
2284 (search-forward ">" nil t) ;Move point to end of "<....>".
2285 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2286 (let ((message-id (match-string 1)))
2288 (set-buffer gnus-summary-buffer)
2289 (gnus-summary-refer-article message-id))
2291 (error "No references around point"))))
2293 (defun gnus-article-show-summary ()
2294 "Reconfigure windows to show summary buffer."
2296 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2297 (error "There is no summary buffer for this article buffer")
2298 (gnus-article-set-globals)
2299 (gnus-configure-windows 'article)
2300 (gnus-summary-goto-subject gnus-current-article)
2301 (gnus-summary-position-point)))
2303 (defun gnus-article-describe-briefly ()
2304 "Describe article mode commands briefly."
2307 (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")))
2309 (defun gnus-article-summary-command ()
2310 "Execute the last keystroke in the summary buffer."
2312 (let ((obuf (current-buffer))
2313 (owin (current-window-configuration))
2315 (switch-to-buffer gnus-article-current-summary 'norecord)
2316 (setq func (lookup-key (current-local-map) (this-command-keys)))
2317 (call-interactively func)
2319 (set-window-configuration owin)
2320 (set-window-point (get-buffer-window (current-buffer)) (point))))
2322 (defun gnus-article-summary-command-nosave ()
2323 "Execute the last keystroke in the summary buffer."
2326 (pop-to-buffer gnus-article-current-summary 'norecord)
2327 (setq func (lookup-key (current-local-map) (this-command-keys)))
2328 (call-interactively func)))
2330 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2331 "Read a summary buffer key sequence and execute it from the article buffer."
2334 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2335 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2336 "=" "^" "\M-^" "|"))
2342 '("n" "Gn" "p" "Gp"))
2345 (set-buffer gnus-article-current-summary)
2346 (let (gnus-pick-mode)
2347 (push (or key last-command-event) unread-command-events)
2348 (setq keys (read-key-sequence nil))))
2351 (if (or (member keys nosaves)
2352 (member keys nosave-but-article)
2353 (member keys nosave-in-article))
2355 (save-window-excursion
2356 (pop-to-buffer gnus-article-current-summary 'norecord)
2357 ;; We disable the pick minor mode commands.
2358 (let (gnus-pick-mode)
2359 (setq func (lookup-key (current-local-map) keys))))
2362 (unless (member keys nosave-in-article)
2363 (set-buffer gnus-article-current-summary))
2364 (call-interactively func)
2365 (setq new-sum-point (point)))
2366 (when (member keys nosave-but-article)
2367 (pop-to-buffer gnus-article-buffer 'norecord)))
2368 ;; These commands should restore window configuration.
2369 (let ((obuf (current-buffer))
2370 (owin (current-window-configuration))
2372 (summary gnus-article-current-summary)
2373 func in-buffer selected)
2374 (if not-restore-window
2375 (pop-to-buffer summary 'norecord)
2376 (switch-to-buffer summary 'norecord))
2377 (setq in-buffer (current-buffer))
2378 ;; We disable the pick minor mode commands.
2379 (if (setq func (let (gnus-pick-mode)
2380 (lookup-key (current-local-map) keys)))
2382 (call-interactively func)
2383 (setq new-sum-point (point)))
2385 (when (eq in-buffer (current-buffer))
2386 (setq selected (gnus-summary-select-article))
2388 (unless not-restore-window
2389 (set-window-configuration owin))
2390 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2391 (set-window-point (get-buffer-window (current-buffer))
2393 (let ((win (get-buffer-window gnus-article-current-summary)))
2395 (set-window-point win new-sum-point))))))))
2397 (defun gnus-article-hide (&optional arg force)
2398 "Hide all the gruft in the current article.
2399 This means that PGP stuff, signatures, cited text and (some)
2400 headers will be hidden.
2401 If given a prefix, show the hidden text instead."
2402 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2403 (gnus-article-hide-headers arg)
2404 (gnus-article-hide-pgp arg)
2405 (gnus-article-hide-citation-maybe arg force)
2406 (gnus-article-hide-signature arg))
2408 (defun gnus-article-maybe-highlight ()
2409 "Do some article highlighting if article highlighting is requested."
2410 (when (gnus-visual-p 'article-highlight 'highlight)
2411 (gnus-article-highlight-some)))
2413 (defun gnus-check-group-server ()
2414 ;; Make sure the connection to the server is alive.
2415 (unless (gnus-server-opened
2416 (gnus-find-method-for-group gnus-newsgroup-name))
2417 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2418 (gnus-request-group gnus-newsgroup-name t)))
2420 (defun gnus-request-article-this-buffer (article group)
2421 "Get an article and insert it into this buffer."
2422 (let (do-update-line sparse-header)
2426 (gnus-kill-all-overlays)
2427 (setq group (or group gnus-newsgroup-name))
2429 ;; Using `gnus-request-article' directly will insert the article into
2430 ;; `nntp-server-buffer' - so we'll save some time by not having to
2431 ;; copy it from the server buffer into the article buffer.
2433 ;; We only request an article by message-id when we do not have the
2434 ;; headers for it, so we'll have to get those.
2435 (when (stringp article)
2436 (let ((gnus-override-method gnus-refer-article-method))
2437 (gnus-read-header article)))
2439 ;; If the article number is negative, that means that this article
2440 ;; doesn't belong in this newsgroup (possibly), so we find its
2441 ;; message-id and request it by id instead of number.
2442 (when (and (numberp article)
2444 (get-buffer gnus-summary-buffer)
2445 (gnus-buffer-exists-p gnus-summary-buffer))
2447 (set-buffer gnus-summary-buffer)
2448 (let ((header (gnus-summary-article-header article)))
2451 ((memq article gnus-newsgroup-sparse)
2452 ;; This is a sparse gap article.
2453 (setq do-update-line article)
2454 (setq article (mail-header-id header))
2455 (let ((gnus-override-method gnus-refer-article-method))
2456 (setq sparse-header (gnus-read-header article)))
2457 (setq gnus-newsgroup-sparse
2458 (delq article gnus-newsgroup-sparse)))
2460 ;; It's a real article.
2461 (setq article (mail-header-id header)))
2463 ;; It is an extracted pseudo-article.
2464 (setq article 'pseudo)
2465 (gnus-request-pseudo-article header))))
2467 (let ((method (gnus-find-method-for-group
2468 gnus-newsgroup-name)))
2469 (when (and (eq (car method) 'nneething)
2472 (file-name-as-directory
2473 (or (cadr (assq 'nneething-address method))
2475 (mail-header-subject header))))
2476 (when (file-directory-p dir)
2477 (setq article 'nneething)
2478 (gnus-group-enter-directory dir))))))))
2481 ;; Refuse to select canceled articles.
2482 ((and (numberp article)
2484 (get-buffer gnus-summary-buffer)
2485 (gnus-buffer-exists-p gnus-summary-buffer)
2486 (eq (cdr (save-excursion
2487 (set-buffer gnus-summary-buffer)
2488 (assq article gnus-newsgroup-reads)))
2489 gnus-canceled-mark))
2491 ;; We first check `gnus-original-article-buffer'.
2492 ((and (get-buffer gnus-original-article-buffer)
2495 (set-buffer gnus-original-article-buffer)
2496 (and (equal (car gnus-original-article) group)
2497 (eq (cdr gnus-original-article) article))))
2498 (insert-buffer-substring gnus-original-article-buffer)
2500 ;; Check the backlog.
2501 ((and gnus-keep-backlog
2502 (gnus-backlog-request-article group article (current-buffer)))
2504 ;; Check asynchronous pre-fetch.
2505 ((gnus-async-request-fetched-article group article (current-buffer))
2506 (gnus-async-prefetch-next group article gnus-summary-buffer)
2507 (when (and (numberp article) gnus-keep-backlog)
2508 (gnus-backlog-enter-article group article (current-buffer)))
2511 ((and gnus-use-cache
2513 (gnus-cache-request-article article group))
2515 ;; Get the article and put into the article buffer.
2516 ((or (stringp article) (numberp article))
2517 (let ((gnus-override-method
2518 (and (stringp article) gnus-refer-article-method))
2519 (buffer-read-only nil))
2521 (gnus-kill-all-overlays)
2522 (gnus-check-group-server)
2523 (when (gnus-request-article article group (current-buffer))
2524 (when (numberp article)
2525 (gnus-async-prefetch-next group article gnus-summary-buffer)
2526 (when gnus-keep-backlog
2527 (gnus-backlog-enter-article
2528 group article (current-buffer))))
2533 ;; Associate this article with the current summary buffer.
2534 (setq gnus-article-current-summary gnus-summary-buffer)
2536 ;; Take the article from the original article buffer
2537 ;; and place it in the buffer it's supposed to be in.
2538 (when (and (get-buffer gnus-article-buffer)
2539 (equal (buffer-name (current-buffer))
2540 (buffer-name (get-buffer gnus-article-buffer))))
2542 (if (get-buffer gnus-original-article-buffer)
2543 (set-buffer gnus-original-article-buffer)
2544 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2545 (buffer-disable-undo (current-buffer))
2546 (setq major-mode 'gnus-original-article-mode)
2547 (setq buffer-read-only t))
2548 (let (buffer-read-only)
2550 (insert-buffer-substring gnus-article-buffer))
2551 (setq gnus-original-article (cons group article))))
2553 ;; Update sparse articles.
2554 (when (and do-update-line
2555 (or (numberp article)
2557 (let ((buf (current-buffer)))
2558 (set-buffer gnus-summary-buffer)
2559 (gnus-summary-update-article do-update-line sparse-header)
2560 (gnus-summary-goto-subject do-update-line nil t)
2561 (set-window-point (get-buffer-window (current-buffer) t)
2563 (set-buffer buf))))))
2569 (defcustom gnus-article-edit-mode-hook nil
2570 "Hook run in article edit mode buffers."
2571 :group 'gnus-article-various
2574 (defvar gnus-article-edit-done-function nil)
2576 (defvar gnus-article-edit-mode-map nil)
2578 (unless gnus-article-edit-mode-map
2579 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2581 (gnus-define-keys gnus-article-edit-mode-map
2582 "\C-c\C-c" gnus-article-edit-done
2583 "\C-c\C-k" gnus-article-edit-exit)
2585 (gnus-define-keys (gnus-article-edit-wash-map
2586 "\C-c\C-w" gnus-article-edit-mode-map)
2587 "f" gnus-article-edit-full-stops))
2589 (defun gnus-article-edit-mode ()
2590 "Major mode for editing articles.
2591 This is an extended text-mode.
2593 \\{gnus-article-edit-mode-map}"
2595 (setq major-mode 'gnus-article-edit-mode)
2596 (setq mode-name "Article Edit")
2597 (use-local-map gnus-article-edit-mode-map)
2598 (make-local-variable 'gnus-article-edit-done-function)
2599 (make-local-variable 'gnus-prev-winconf)
2600 (setq buffer-read-only nil)
2601 (buffer-enable-undo)
2603 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2605 (defun gnus-article-edit (&optional force)
2606 "Edit the current article.
2607 This will have permanent effect only in mail groups.
2608 If FORCE is non-nil, allow editing of articles even in read-only
2611 (when (and (not force)
2612 (gnus-group-read-only-p))
2613 (error "The current newsgroup does not support article editing"))
2614 (gnus-article-date-original)
2615 (gnus-article-edit-article
2616 `(lambda (no-highlight)
2617 (gnus-summary-edit-article-done
2618 ,(or (mail-header-references gnus-current-headers) "")
2619 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2621 (defun gnus-article-edit-article (exit-func)
2622 "Start editing the contents of the current article buffer."
2623 (let ((winconf (current-window-configuration)))
2624 (set-buffer gnus-article-buffer)
2625 (gnus-article-edit-mode)
2626 (gnus-article-delete-text-of-type 'annotation)
2627 (gnus-set-text-properties (point-min) (point-max) nil)
2628 (gnus-configure-windows 'edit-article)
2629 (setq gnus-article-edit-done-function exit-func)
2630 (setq gnus-prev-winconf winconf)
2631 (gnus-message 6 "C-c C-c to end edits")))
2633 (defun gnus-article-edit-done (&optional arg)
2634 "Update the article edits and exit."
2639 (goto-char (point-min))
2640 (when (search-forward "\n\n" nil 1)
2641 (let ((lines (count-lines (point) (point-max)))
2642 (length (- (point-max) (point)))
2643 (case-fold-search t)
2644 (body (copy-marker (point))))
2645 (goto-char (point-min))
2646 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2647 (delete-region (match-beginning 1) (match-end 1))
2648 (insert (number-to-string length)))
2649 (goto-char (point-min))
2650 (when (re-search-forward
2651 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2652 (delete-region (match-beginning 1) (match-end 1))
2653 (insert (number-to-string length)))
2654 (goto-char (point-min))
2655 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2656 (delete-region (match-beginning 1) (match-end 1))
2657 (insert (number-to-string lines)))))))
2658 (let ((func gnus-article-edit-done-function)
2659 (buf (current-buffer))
2660 (start (window-start)))
2661 (gnus-article-edit-exit)
2664 (let ((buffer-read-only nil))
2665 (funcall func arg)))
2667 (set-window-start (get-buffer-window buf) start)
2668 (set-window-point (get-buffer-window buf) (point))))
2670 (defun gnus-article-edit-exit ()
2671 "Exit the article editing without updating."
2673 ;; We remove all text props from the article buffer.
2674 (let ((buf (format "%s" (buffer-string)))
2675 (curbuf (current-buffer))
2677 (window-start (window-start)))
2680 (let ((winconf gnus-prev-winconf))
2682 ;; The cache and backlog have to be flushed somewhat.
2683 (when gnus-use-cache
2684 (gnus-cache-update-article
2685 (car gnus-article-current) (cdr gnus-article-current)))
2686 (when gnus-keep-backlog
2687 (gnus-backlog-remove-article
2688 (car gnus-article-current) (cdr gnus-article-current)))
2689 ;; Flush original article as well.
2691 (when (get-buffer gnus-original-article-buffer)
2692 (set-buffer gnus-original-article-buffer)
2693 (setq gnus-original-article nil)))
2694 (set-window-configuration winconf)
2695 ;; Tippy-toe some to make sure that point remains where it was.
2696 (let ((buf (current-buffer)))
2698 (set-window-start (get-buffer-window (current-buffer)) window-start)
2700 (set-buffer buf)))))
2702 (defun gnus-article-edit-full-stops ()
2703 "Interactively repair spacing at end of sentences."
2706 (goto-char (point-min))
2707 (search-forward-regexp "^$" nil t)
2708 (let ((case-fold-search nil))
2709 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2712 ;;; Article highlights
2715 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2717 ;;; Internal Variables:
2719 (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\\)"
2720 "Regular expression that matches URLs."
2721 :group 'gnus-article-buttons
2724 (defcustom gnus-button-alist
2725 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2726 gnus-button-message-id 2)
2727 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2728 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2730 gnus-button-fetch-group 4)
2731 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2732 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2733 t gnus-button-message-id 3)
2734 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2735 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2736 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2737 ;; This is how URLs _should_ be embedded in text...
2738 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2740 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2741 "*Alist of regexps matching buttons in article bodies.
2743 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2744 REGEXP: is the string matching text around the button,
2745 BUTTON: is the number of the regexp grouping actually matching the button,
2746 FORM: is a lisp expression which must eval to true for the button to
2748 CALLBACK: is the function to call when the user push this button, and each
2749 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2751 CALLBACK can also be a variable, in that case the value of that
2752 variable it the real callback function."
2753 :group 'gnus-article-buttons
2754 :type '(repeat (list regexp
2755 (integer :tag "Button")
2757 (function :tag "Callback")
2760 (integer :tag "Regexp group")))))
2762 (defcustom gnus-header-button-alist
2763 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2764 0 t gnus-button-message-id 0)
2765 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2766 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2767 0 t gnus-button-mailto 0)
2768 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2769 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2770 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2771 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2772 gnus-button-message-id 3))
2773 "*Alist of headers and regexps to match buttons in article heads.
2775 This alist is very similar to `gnus-button-alist', except that each
2776 alist has an additional HEADER element first in each entry:
2778 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2780 HEADER is a regexp to match a header. For a fuller explanation, see
2781 `gnus-button-alist'."
2782 :group 'gnus-article-buttons
2783 :group 'gnus-article-headers
2784 :type '(repeat (list (regexp :tag "Header")
2786 (integer :tag "Button")
2788 (function :tag "Callback")
2791 (integer :tag "Regexp group")))))
2793 (defvar gnus-button-regexp nil)
2794 (defvar gnus-button-marker-list nil)
2795 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2797 (defvar gnus-button-last nil)
2798 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2802 (defun gnus-article-push-button (event)
2803 "Check text under the mouse pointer for a callback function.
2804 If the text under the mouse pointer has a `gnus-callback' property,
2805 call it with the value of the `gnus-data' text property."
2807 (set-buffer (window-buffer (posn-window (event-start event))))
2808 (let* ((pos (posn-point (event-start event)))
2809 (data (get-text-property pos 'gnus-data))
2810 (fun (get-text-property pos 'gnus-callback)))
2813 (funcall fun data))))
2815 (defun gnus-article-press-button ()
2816 "Check text at point for a callback function.
2817 If the text at point has a `gnus-callback' property,
2818 call it with the value of the `gnus-data' text property."
2820 (let* ((data (get-text-property (point) 'gnus-data))
2821 (fun (get-text-property (point) 'gnus-callback)))
2823 (funcall fun data))))
2825 (defun gnus-article-prev-button (n)
2826 "Move point to N buttons backward.
2827 If N is negative, move forward instead."
2829 (gnus-article-next-button (- n)))
2831 (defun gnus-article-next-button (n)
2832 "Move point to N buttons forward.
2833 If N is negative, move backward instead."
2835 (let ((function (if (< n 0) 'previous-single-property-change
2836 'next-single-property-change))
2837 (inhibit-point-motion-hooks t)
2839 (limit (if (< n 0) (point-min) (point-max))))
2841 (while (and (not (= limit (point)))
2843 ;; Skip past the current button.
2844 (when (get-text-property (point) 'gnus-callback)
2845 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2846 ;; Go to the next (or previous) button.
2847 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2848 ;; Put point at the start of the button.
2849 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2850 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2851 ;; Skip past intangible buttons.
2852 (when (get-text-property (point) 'intangible)
2856 (gnus-message 5 "No more buttons"))
2859 (defun gnus-article-highlight (&optional force)
2860 "Highlight current article.
2861 This function calls `gnus-article-highlight-headers',
2862 `gnus-article-highlight-citation',
2863 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2864 do the highlighting. See the documentation for those functions."
2865 (interactive (list 'force))
2866 (gnus-article-highlight-headers)
2867 (gnus-article-highlight-citation force)
2868 (gnus-article-highlight-signature)
2869 (gnus-article-add-buttons force)
2870 (gnus-article-add-buttons-to-head))
2872 (defun gnus-article-highlight-some (&optional force)
2873 "Highlight current article.
2874 This function calls `gnus-article-highlight-headers',
2875 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2876 do the highlighting. See the documentation for those functions."
2877 (interactive (list 'force))
2878 (gnus-article-highlight-headers)
2879 (gnus-article-highlight-signature)
2880 (gnus-article-add-buttons))
2882 (defun gnus-article-highlight-headers ()
2883 "Highlight article headers as specified by `gnus-header-face-alist'."
2886 (set-buffer gnus-article-buffer)
2888 (let ((alist gnus-header-face-alist)
2889 (buffer-read-only nil)
2890 (case-fold-search t)
2891 (inhibit-point-motion-hooks t)
2892 entry regexp header-face field-face from hpoints fpoints)
2893 (message-narrow-to-head)
2894 (while (setq entry (pop alist))
2895 (goto-char (point-min))
2896 (setq regexp (concat "^\\("
2897 (if (string-equal "" (nth 0 entry))
2901 header-face (nth 1 entry)
2902 field-face (nth 2 entry))
2903 (while (and (re-search-forward regexp nil t)
2907 (unless (search-forward ":" nil t)
2909 (when (and header-face
2910 (not (memq (point) hpoints)))
2911 (push (point) hpoints)
2912 (gnus-put-text-property from (point) 'face header-face))
2913 (when (and field-face
2914 (not (memq (setq from (point)) fpoints)))
2916 (if (re-search-forward "^[^ \t]" nil t)
2918 (goto-char (point-max)))
2919 (gnus-put-text-property from (point) 'face field-face))))))))
2921 (defun gnus-article-highlight-signature ()
2922 "Highlight the signature in an article.
2923 It does this by highlighting everything after
2924 `gnus-signature-separator' using `gnus-signature-face'."
2927 (set-buffer gnus-article-buffer)
2928 (let ((buffer-read-only nil)
2929 (inhibit-point-motion-hooks t))
2931 (when (and gnus-signature-face
2932 (gnus-article-narrow-to-signature))
2933 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2934 'face gnus-signature-face)
2936 (gnus-article-search-signature)
2937 (let ((start (match-beginning 0))
2938 (end (set-marker (make-marker) (1+ (match-end 0)))))
2939 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2942 (defun gnus-button-in-region-p (b e prop)
2943 "Say whether PROP exists in the region."
2944 (text-property-not-all b e prop nil))
2946 (defun gnus-article-add-buttons (&optional force)
2947 "Find external references in the article and make buttons of them.
2948 \"External references\" are things like Message-IDs and URLs, as
2949 specified by `gnus-button-alist'."
2950 (interactive (list 'force))
2952 (set-buffer gnus-article-buffer)
2953 (let ((buffer-read-only nil)
2954 (inhibit-point-motion-hooks t)
2955 (case-fold-search t)
2956 (alist gnus-button-alist)
2958 ;; Remove all old markers.
2960 (while (setq marker (pop gnus-button-marker-list))
2962 (when (setq entry (gnus-button-entry))
2963 (put-text-property (match-beginning (nth 1 entry))
2964 (match-end (nth 1 entry))
2965 'gnus-callback nil))
2966 (set-marker marker nil)))
2967 ;; We skip the headers.
2968 (goto-char (point-min))
2969 (unless (search-forward "\n\n" nil t)
2970 (goto-char (point-max)))
2972 (while (setq entry (pop alist))
2973 (setq regexp (car entry))
2975 (while (re-search-forward regexp nil t)
2976 (let* ((start (and entry (match-beginning (nth 1 entry))))
2977 (end (and entry (match-end (nth 1 entry))))
2978 (from (match-beginning 0)))
2979 (when (and (or (eq t (nth 2 entry))
2980 (eval (nth 2 entry)))
2981 (not (gnus-button-in-region-p
2982 start end 'gnus-callback)))
2983 ;; That optional form returned non-nil, so we add the
2985 (gnus-article-add-button
2986 start end 'gnus-button-push
2987 (car (push (set-marker (make-marker) from)
2988 gnus-button-marker-list))))))))))
2990 ;; Add buttons to the head of an article.
2991 (defun gnus-article-add-buttons-to-head ()
2992 "Add buttons to the head of the article."
2995 (set-buffer gnus-article-buffer)
2996 (let ((buffer-read-only nil)
2997 (inhibit-point-motion-hooks t)
2998 (case-fold-search t)
2999 (alist gnus-header-button-alist)
3001 (nnheader-narrow-to-headers)
3003 ;; Each alist entry.
3004 (setq entry (car alist)
3006 (goto-char (point-min))
3007 (while (re-search-forward (car entry) nil t)
3008 ;; Each header matching the entry.
3009 (setq beg (match-beginning 0))
3010 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3011 (match-beginning 0))
3014 (while (re-search-forward (nth 1 entry) end t)
3015 ;; Each match within a header.
3016 (let* ((entry (cdr entry))
3017 (start (match-beginning (nth 1 entry)))
3018 (end (match-end (nth 1 entry)))
3019 (form (nth 2 entry)))
3020 (goto-char (match-end 0))
3022 (gnus-article-add-button
3023 start end (nth 3 entry)
3024 (buffer-substring (match-beginning (nth 4 entry))
3025 (match-end (nth 4 entry)))))))
3029 ;;; External functions:
3031 (defun gnus-article-add-button (from to fun &optional data)
3032 "Create a button between FROM and TO with callback FUN and data DATA."
3033 (when gnus-article-button-face
3034 (gnus-overlay-put (gnus-make-overlay from to)
3035 'face gnus-article-button-face))
3036 (gnus-add-text-properties
3038 (nconc (and gnus-article-mouse-face
3039 (list gnus-mouse-face-prop gnus-article-mouse-face))
3040 (list 'gnus-callback fun)
3041 (and data (list 'gnus-data data)))))
3043 ;;; Internal functions:
3045 (defun gnus-article-set-globals ()
3047 (set-buffer gnus-summary-buffer)
3048 (gnus-set-global-variables)))
3050 (defun gnus-signature-toggle (end)
3052 (set-buffer gnus-article-buffer)
3053 (let ((buffer-read-only nil)
3054 (inhibit-point-motion-hooks t))
3055 (if (get-text-property end 'invisible)
3056 (gnus-article-unhide-text end (point-max))
3057 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3059 (defun gnus-button-entry ()
3060 ;; Return the first entry in `gnus-button-alist' matching this place.
3061 (let ((alist gnus-button-alist)
3064 (setq entry (pop alist))
3065 (if (looking-at (car entry))
3070 (defun gnus-button-push (marker)
3071 ;; Push button starting at MARKER.
3073 (set-buffer gnus-article-buffer)
3075 (let* ((entry (gnus-button-entry))
3076 (inhibit-point-motion-hooks t)
3078 (args (mapcar (lambda (group)
3079 (let ((string (match-string group)))
3080 (gnus-set-text-properties
3081 0 (length string) nil string)
3088 (fboundp (symbol-value fun)))
3089 (apply (symbol-value fun) args))
3091 (gnus-message 1 "You must define `%S' to use this button"
3092 (cons fun args)))))))
3094 (defun gnus-button-message-id (message-id)
3097 (set-buffer gnus-summary-buffer)
3098 (gnus-summary-refer-article message-id)))
3100 (defun gnus-button-fetch-group (address)
3101 "Fetch GROUP specified by ADDRESS."
3102 (if (not (string-match "[:/]" address))
3103 ;; This is just a simple group url.
3104 (gnus-group-read-ephemeral-group address gnus-select-method)
3105 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3107 (error "Can't parse %s" address)
3108 (gnus-group-read-ephemeral-group
3109 (match-string 4 address)
3110 `(nntp ,(match-string 1 address)
3111 (nntp-address ,(match-string 1 address))
3112 (nntp-port-number ,(if (match-end 3)
3113 (match-string 3 address)
3116 (defun gnus-url-parse-query-string (query &optional downcase)
3117 (let (retval pairs cur key val)
3118 (setq pairs (split-string query "&"))
3120 (setq cur (car pairs)
3122 (if (not (string-match "=" cur))
3124 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3125 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3127 (setq key (downcase key)))
3128 (setq cur (assoc key retval))
3130 (setcdr cur (cons val (cdr cur)))
3131 (setq retval (cons (list key val) retval)))))
3134 (defun gnus-url-unhex (x)
3141 (defun gnus-url-unhex-string (str &optional allow-newlines)
3142 "Remove %XXX embedded spaces, etc in a url.
3143 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3144 decoding of carriage returns and line feeds in the string, which is normally
3145 forbidden in URL encoding."
3146 (setq str (or str ""))
3148 (case-fold-search t))
3149 (while (string-match "%[0-9a-f][0-9a-f]" str)
3150 (let* ((start (match-beginning 0))
3151 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3153 (gnus-url-unhex (elt str (+ start 2))))))
3155 tmp (substring str 0 start)
3158 (char-to-string code))
3159 ((or (= code ?\n) (= code ?\r))
3161 (t (char-to-string code))))
3162 str (substring str (match-end 0)))))
3163 (setq tmp (concat tmp str))
3166 (defun gnus-url-mailto (url)
3167 ;; Send mail to someone
3168 (when (string-match "mailto:/*\\(.*\\)" url)
3169 (setq url (substring url (match-beginning 1) nil)))
3170 (let (to args subject func)
3171 (if (string-match (regexp-quote "?") url)
3172 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3173 args (gnus-url-parse-query-string
3174 (substring url (match-end 0) nil) t))
3175 (setq to (gnus-url-unhex-string url)))
3176 (setq args (cons (list "to" to) args)
3177 subject (cdr-safe (assoc "subject" args)))
3180 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3183 (message-position-on-field (caar args)))
3184 (insert (mapconcat 'identity (cdar args) ", "))
3185 (setq args (cdr args)))
3188 (message-goto-subject))))
3190 (defun gnus-button-mailto (address)
3192 (set-buffer (gnus-copy-article-buffer))
3193 (message-reply address))
3195 (defun gnus-button-reply (address)
3196 ;; Reply to ADDRESS.
3197 (message-reply address))
3199 (defun gnus-button-url (address)
3201 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3202 (if (listp browse-url-browser-function)
3203 (browse-url address)
3204 (funcall browse-url-browser-function address)))
3206 (defun gnus-button-embedded-url (address)
3208 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3209 (if (listp browse-url-browser-function)
3210 (browse-url (gnus-strip-whitespace address))
3211 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3213 ;;; Next/prev buttons in the article buffer.
3215 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3216 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3218 (defvar gnus-prev-page-map nil)
3219 (unless gnus-prev-page-map
3220 (setq gnus-prev-page-map (make-sparse-keymap))
3221 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3222 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3224 (defun gnus-insert-prev-page-button ()
3225 (let ((buffer-read-only nil))
3227 gnus-prev-page-line-format nil
3228 `(gnus-prev t local-map ,gnus-prev-page-map
3229 gnus-callback gnus-article-button-prev-page
3230 gnus-type annotation))))
3232 (defvar gnus-next-page-map nil)
3233 (unless gnus-next-page-map
3234 (setq gnus-next-page-map (make-keymap))
3235 (suppress-keymap gnus-prev-page-map)
3236 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3237 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3239 (defun gnus-button-next-page ()
3240 "Go to the next page."
3242 (let ((win (selected-window)))
3243 (select-window (get-buffer-window gnus-article-buffer t))
3244 (gnus-article-next-page)
3245 (select-window win)))
3247 (defun gnus-button-prev-page ()
3248 "Go to the prev page."
3250 (let ((win (selected-window)))
3251 (select-window (get-buffer-window gnus-article-buffer t))
3252 (gnus-article-prev-page)
3253 (select-window win)))
3255 (defun gnus-insert-next-page-button ()
3256 (let ((buffer-read-only nil))
3257 (gnus-eval-format gnus-next-page-line-format nil
3259 t local-map ,gnus-next-page-map
3260 gnus-callback gnus-article-button-next-page
3261 gnus-type annotation))))
3263 (defun gnus-article-button-next-page (arg)
3264 "Go to the next page."
3266 (let ((win (selected-window)))
3267 (select-window (get-buffer-window gnus-article-buffer t))
3268 (gnus-article-next-page)
3269 (select-window win)))
3271 (defun gnus-article-button-prev-page (arg)
3272 "Go to the prev page."
3274 (let ((win (selected-window)))
3275 (select-window (get-buffer-window gnus-article-buffer t))
3276 (gnus-article-prev-page)
3277 (select-window win)))
3283 (run-hooks 'gnus-art-load-hook)
3285 ;;; gnus-art.el ends here