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))
37 (defgroup gnus-article nil
39 :link '(custom-manual "(gnus)The Article Buffer")
42 (defgroup gnus-article-hiding nil
43 "Hiding article parts."
44 :link '(custom-manual "(gnus)Article Hiding")
47 (defgroup gnus-article-highlight nil
48 "Article highlighting."
49 :link '(custom-manual "(gnus)Article Highlighting")
53 (defgroup gnus-article-signature nil
55 :link '(custom-manual "(gnus)Article Signature")
58 (defgroup gnus-article-headers nil
60 :link '(custom-manual "(gnus)Hiding Headers")
63 (defgroup gnus-article-washing nil
64 "Special commands on articles."
65 :link '(custom-manual "(gnus)Article Washing")
68 (defgroup gnus-article-emphasis nil
69 "Fontisizing articles."
70 :link '(custom-manual "(gnus)Article Fontisizing")
73 (defgroup gnus-article-saving nil
75 :link '(custom-manual "(gnus)Saving Articles")
78 (defgroup gnus-article-mime nil
79 "Worshiping the MIME wonder."
80 :link '(custom-manual "(gnus)Using MIME")
83 (defgroup gnus-article-buttons nil
84 "Pushable buttons in the article buffer."
85 :link '(custom-manual "(gnus)Article Buttons")
88 (defgroup gnus-article-various nil
89 "Other article options."
90 :link '(custom-manual "(gnus)Misc Article")
93 (defcustom gnus-ignored-headers
94 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
95 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
96 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
97 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
98 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
99 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
100 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
101 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
102 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
103 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
104 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
105 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
106 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
107 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
108 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
109 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
110 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
111 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
113 "*All headers that start with this regexp will be hidden.
114 This variable can also be a list of regexps of headers to be ignored.
115 If `gnus-visible-headers' is non-nil, this variable will be ignored."
116 :type '(choice :custom-show nil
119 :group 'gnus-article-hiding)
121 (defcustom gnus-visible-headers
122 "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:"
123 "*All headers that do not match this regexp will be hidden.
124 This variable can also be a list of regexp of headers to remain visible.
125 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
126 :type '(repeat :value-to-internal (lambda (widget value)
127 (custom-split-regexp-maybe value))
128 :match (lambda (widget value)
130 (widget-editable-list-match widget value)))
132 :group 'gnus-article-hiding)
134 (defcustom gnus-sorted-header-list
135 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
136 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
137 "*This variable is a list of regular expressions.
138 If it is non-nil, headers that match the regular expressions will
139 be placed first in the article buffer in the sequence specified by
141 :type '(repeat regexp)
142 :group 'gnus-article-hiding)
144 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
145 "Headers that are only to be displayed if they have interesting data.
146 Possible values in this list are `empty', `newsgroups', `followup-to',
147 `reply-to', `date', `long-to', and `many-to'."
148 :type '(set (const :tag "Headers with no content." empty)
149 (const :tag "Newsgroups with only one group." newsgroups)
150 (const :tag "Followup-to identical to newsgroups." followup-to)
151 (const :tag "Reply-to identical to from." reply-to)
152 (const :tag "Date less than four days old." date)
153 (const :tag "Very long To header." long-to)
154 (const :tag "Multiple To headers." many-to))
155 :group 'gnus-article-hiding)
157 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
158 "Regexp matching signature separator.
159 This can also be a list of regexps. In that case, it will be checked
160 from head to tail looking for a separator. Searches will be done from
161 the end of the buffer."
162 :type '(repeat string)
163 :group 'gnus-article-signature)
165 (defcustom gnus-signature-limit nil
166 "Provide a limit to what is considered a signature.
167 If it is a number, no signature may not be longer (in characters) than
168 that number. If it is a floating point number, no signature may be
169 longer (in lines) than that number. If it is a function, the function
170 will be called without any parameters, and if it returns nil, there is
171 no signature in the buffer. If it is a string, it will be used as a
172 regexp. If it matches, the text in question is not a signature."
173 :type '(choice (integer :value 200)
175 (function :value fun)
176 (regexp :value ".*"))
177 :group 'gnus-article-signature)
179 (defcustom gnus-hidden-properties '(invisible t intangible t)
180 "Property list to use for hiding text."
182 :group 'gnus-article-hiding)
184 (defcustom gnus-article-x-face-command
185 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
186 "*String or function to be executed to display an X-Face header.
187 If it is a string, the command will be executed in a sub-shell
188 asynchronously. The compressed face will be piped to this command."
189 :type 'string ;Leave function case to Lisp.
190 :group 'gnus-article-washing)
192 (defcustom gnus-article-x-face-too-ugly nil
193 "Regexp matching posters whose face shouldn't be shown automatically."
194 :type '(choice regexp (const nil))
195 :group 'gnus-article-washing)
197 (defcustom gnus-emphasis-alist
199 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
201 '(("_" "_" underline)
204 ("_/" "/_" underline-italic)
205 ("_\\*" "\\*_" underline-bold)
206 ("\\*/" "/\\*" bold-italic)
207 ("_\\*/" "/\\*_" underline-bold-italic))))
208 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
209 2 3 gnus-emphasis-underline)
213 (format format (car spec) (cadr spec))
214 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
216 "*Alist that says how to fontify certain phrases.
217 Each item looks like this:
219 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
221 The first element is a regular expression to be matched. The second
222 is a number that says what regular expression grouping used to find
223 the entire emphasized word. The third is a number that says what
224 regexp grouping should be displayed and highlighted. The fourth
225 is the face used for highlighting."
226 :type '(repeat (list :value ("" 0 0 default)
228 (integer :tag "Match group")
229 (integer :tag "Emphasize group")
231 :group 'gnus-article-emphasis)
233 (defface gnus-emphasis-bold '((t (:bold t)))
234 "Face used for displaying strong emphasized text (*word*)."
235 :group 'gnus-article-emphasis)
237 (defface gnus-emphasis-italic '((t (:italic t)))
238 "Face used for displaying italic emphasized text (/word/)."
239 :group 'gnus-article-emphasis)
241 (defface gnus-emphasis-underline '((t (:underline t)))
242 "Face used for displaying underlined emphasized text (_word_)."
243 :group 'gnus-article-emphasis)
245 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
246 "Face used for displaying underlined bold emphasized text (_*word*_)."
247 :group 'gnus-article-emphasis)
249 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
250 "Face used for displaying underlined italic emphasized text (_*word*_)."
251 :group 'gnus-article-emphasis)
253 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
254 "Face used for displaying bold italic emphasized text (/*word*/)."
255 :group 'gnus-article-emphasis)
257 (defface gnus-emphasis-underline-bold-italic
258 '((t (:bold t :italic t :underline t)))
259 "Face used for displaying underlined bold italic emphasized text.
260 Esample: (_/*word*/_)."
261 :group 'gnus-article-emphasis)
263 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
264 "Format for display of Date headers in article bodies.
265 See `format-time-string' for the possible values.
267 The variable can also be function, which should return a complete Date
268 header. The function is called with one argument, the time, which can
269 be fed to `format-time-string'."
270 :type '(choice string symbol)
271 :link '(custom-manual "(gnus)Article Date")
272 :group 'gnus-article-washing)
275 (autoload 'hexl-hex-string-to-integer "hexl")
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-hack-decode-rfc1522 ()
950 "Emergency hack function for avoiding problems when decoding."
951 (let ((buffer-read-only nil))
952 (goto-char (point-min))
953 ;; Remove encoded TABs.
954 (while (search-forward "=09" nil t)
955 (replace-match " " t t))
956 ;; Remove encoded newlines.
957 (goto-char (point-min))
958 (while (search-forward "=10" nil t)
959 (replace-match " " t t))))
961 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522)
962 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522)
963 (defun article-decode-rfc1522 ()
964 "Hack to remove QP encoding from headers."
965 (let ((case-fold-search t)
966 (inhibit-point-motion-hooks t)
967 (buffer-read-only nil)
971 (goto-char (point-min))
972 (or (search-forward "\n\n" nil t) (point-max)))
973 (goto-char (point-min))
974 (while (re-search-forward
975 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
976 (setq string (match-string 1))
978 (narrow-to-region (match-beginning 0) (match-end 0))
979 (delete-region (point-min) (point-max))
981 (article-mime-decode-quoted-printable
982 (goto-char (point-min)) (point-max))
983 (subst-char-in-region (point-min) (point-max) ?_ ? )
984 (goto-char (point-max)))
985 (goto-char (point-min))))))
987 (defun article-de-quoted-unreadable (&optional force)
988 "Do a naive translation of a quoted-printable-encoded article.
989 This is in no way, shape or form meant as a replacement for real MIME
990 processing, but is simply a stop-gap measure until MIME support is
992 If FORCE, decode the article whether it is marked as quoted-printable
994 (interactive (list 'force))
996 (let ((case-fold-search t)
997 (buffer-read-only nil)
998 (type (gnus-fetch-field "content-transfer-encoding")))
999 (gnus-article-decode-rfc1522)
1001 (and type (string-match "quoted-printable" (downcase type))))
1002 (goto-char (point-min))
1003 (search-forward "\n\n" nil 'move)
1004 (article-mime-decode-quoted-printable (point) (point-max))))))
1006 (defun article-mime-decode-quoted-printable-buffer ()
1007 "Decode Quoted-Printable in the current buffer."
1008 (article-mime-decode-quoted-printable (point-min) (point-max)))
1010 (defun article-mime-decode-quoted-printable (from to)
1011 "Decode Quoted-Printable in the region between FROM and TO."
1014 (while (search-forward "=" to t)
1015 (cond ((eq (following-char) ?\n)
1018 ((looking-at "[0-9A-F][0-9A-F]")
1019 (subst-char-in-region
1020 (1- (point)) (point) ?=
1021 (hexl-hex-string-to-integer
1022 (buffer-substring (point) (+ 2 (point)))))
1026 ((gnus-message 3 "Malformed MIME quoted-printable message")))))
1028 (defun article-hide-pgp (&optional arg)
1029 "Toggle hiding of any PGP headers and signatures in the current article.
1030 If given a negative prefix, always show; if given a positive prefix,
1032 (interactive (gnus-article-hidden-arg))
1033 (unless (gnus-article-check-hidden-text 'pgp arg)
1035 (let ((inhibit-point-motion-hooks t)
1036 buffer-read-only beg end)
1038 (goto-char (point-min))
1039 ;; Hide the "header".
1040 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1041 (delete-region (1+ (match-beginning 0)) (match-end 0))
1043 ;; Hide the actual signature.
1044 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1045 (setq end (1+ (match-beginning 0)))
1048 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1050 ;; Perhaps we shouldn't hide to the end of the buffer
1051 ;; if there is no end to the signature?
1053 ;; Hide "- " PGP quotation markers.
1055 (narrow-to-region beg end)
1056 (goto-char (point-min))
1057 (while (re-search-forward "^- " nil t)
1059 (match-beginning 0) (match-end 0)))
1061 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1063 (defun article-hide-pem (&optional arg)
1064 "Toggle hiding of any PEM headers and signatures in the current article.
1065 If given a negative prefix, always show; if given a positive prefix,
1067 (interactive (gnus-article-hidden-arg))
1068 (unless (gnus-article-check-hidden-text 'pem arg)
1070 (let (buffer-read-only end)
1072 (goto-char (point-min))
1073 ;; hide the horrendously ugly "header".
1074 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1077 (setq end (1+ (match-beginning 0)))
1078 (gnus-article-hide-text-type
1080 (if (search-forward "\n\n" nil t)
1084 ;; hide the trailer as well
1085 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1088 (gnus-article-hide-text-type
1089 (match-beginning 0) (match-end 0) 'pem))))))
1091 (defun article-hide-signature (&optional arg)
1092 "Hide the signature in the current article.
1093 If given a negative prefix, always show; if given a positive prefix,
1095 (interactive (gnus-article-hidden-arg))
1096 (unless (gnus-article-check-hidden-text 'signature arg)
1099 (let ((buffer-read-only nil))
1100 (when (gnus-article-narrow-to-signature)
1101 (gnus-article-hide-text-type
1102 (point-min) (point-max) 'signature)))))))
1104 (defun article-strip-leading-blank-lines ()
1105 "Remove all blank lines from the beginning of the article."
1108 (let ((inhibit-point-motion-hooks t)
1110 (goto-char (point-min))
1111 (when (search-forward "\n\n" nil t)
1112 (while (and (not (eobp))
1113 (looking-at "[ \t]*$"))
1114 (gnus-delete-line))))))
1116 (defun article-strip-multiple-blank-lines ()
1117 "Replace consecutive blank lines with one empty line."
1120 (let ((inhibit-point-motion-hooks t)
1122 ;; First make all blank lines empty.
1123 (goto-char (point-min))
1124 (search-forward "\n\n" nil t)
1125 (while (re-search-forward "^[ \t]+$" nil t)
1126 (replace-match "" nil t))
1127 ;; Then replace multiple empty lines with a single empty line.
1128 (goto-char (point-min))
1129 (search-forward "\n\n" nil t)
1130 (while (re-search-forward "\n\n\n+" nil t)
1131 (replace-match "\n\n" t t)))))
1133 (defun article-strip-leading-space ()
1134 "Remove all white space from the beginning of the lines in the article."
1137 (let ((inhibit-point-motion-hooks t)
1139 (goto-char (point-min))
1140 (search-forward "\n\n" nil t)
1141 (while (re-search-forward "^[ \t]+" nil t)
1142 (replace-match "" t t)))))
1144 (defun article-strip-blank-lines ()
1145 "Strip leading, trailing and multiple blank lines."
1147 (article-strip-leading-blank-lines)
1148 (article-remove-trailing-blank-lines)
1149 (article-strip-multiple-blank-lines))
1151 (defun article-strip-all-blank-lines ()
1152 "Strip all blank lines."
1155 (let ((inhibit-point-motion-hooks t)
1157 (goto-char (point-min))
1158 (search-forward "\n\n" nil t)
1159 (while (re-search-forward "^[ \t]*\n" nil t)
1160 (replace-match "" t t)))))
1162 (defvar mime::preview/content-list)
1163 (defvar mime::preview-content-info/point-min)
1164 (defun gnus-article-narrow-to-signature ()
1165 "Narrow to the signature; return t if a signature is found, else nil."
1167 (let ((inhibit-point-motion-hooks t))
1168 (when (and (boundp 'mime::preview/content-list)
1169 mime::preview/content-list)
1170 ;; We have a MIMEish article, so we use the MIME data to narrow.
1171 (let ((pcinfo (car (last mime::preview/content-list))))
1174 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1177 (when (gnus-article-search-signature)
1179 ;; Check whether we have some limits to what we consider
1180 ;; to be a signature.
1181 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1182 (list gnus-signature-limit)))
1184 (while (setq limit (pop limits))
1185 (if (or (and (integerp limit)
1186 (< (- (point-max) (point)) limit))
1188 (< (count-lines (point) (point-max)) limit))
1189 (and (gnus-functionp limit)
1191 (and (stringp limit)
1192 (not (re-search-forward limit nil t))))
1193 () ; This limit did not succeed.
1197 (narrow-to-region (point) (point-max))
1200 (defun gnus-article-search-signature ()
1201 "Search the current buffer for the signature separator.
1202 Put point at the beginning of the signature separator."
1203 (let ((cur (point)))
1204 (goto-char (point-max))
1205 (if (if (stringp gnus-signature-separator)
1206 (re-search-backward gnus-signature-separator nil t)
1207 (let ((seps gnus-signature-separator))
1209 (not (re-search-backward (car seps) nil t)))
1217 (autoload 'w3-display "w3-parse")
1218 (autoload 'w3-do-setup "w3" "" t)
1219 (autoload 'w3-region "w3-display" "" t))
1221 (defun gnus-article-treat-html ()
1224 (let ((cbuf (current-buffer)))
1225 (set-buffer gnus-article-buffer)
1226 (let (buf buffer-read-only b e)
1228 (goto-char (point-min))
1230 (if (search-forward "\n\n" nil t)
1233 (setq e (point-max)))
1234 (nnheader-temp-write nil
1235 (insert-buffer-substring gnus-article-buffer b e)
1237 (save-window-excursion
1238 (w3-region (point-min) (point-max))
1239 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1241 (delete-region (point-min) (point-max))
1244 (goto-char (point-min))
1245 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1246 (set-buffer cbuf))))
1248 (defun gnus-article-hidden-arg ()
1249 "Return the current prefix arg as a number, or 0 if no prefix."
1250 (list (if current-prefix-arg
1251 (prefix-numeric-value current-prefix-arg)
1254 (defun gnus-article-check-hidden-text (type arg)
1255 "Return nil if hiding is necessary.
1256 Arg can be nil or a number. Nil and positive means hide, negative
1257 means show, 0 means toggle."
1261 (let ((hide (gnus-article-hidden-text-p type)))
1267 (gnus-article-show-hidden-text type))
1269 (if (eq hide 'hidden)
1270 (gnus-article-show-hidden-text type)
1273 (defun gnus-article-hidden-text-p (type)
1274 "Say whether the current buffer contains hidden text of type TYPE."
1275 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1277 (not (get-text-property pos 'invisible)))
1279 (text-property-any (1+ pos) (point-max) 'article-type type)))
1284 (defun gnus-article-show-hidden-text (type &optional hide)
1285 "Show all hidden text of type TYPE.
1286 If HIDE, hide the text instead."
1288 (let ((buffer-read-only nil)
1289 (inhibit-point-motion-hooks t)
1292 (while (setq beg (text-property-any end (point-max) 'article-type type))
1295 (text-property-not-all beg (point-max) 'article-type type)
1298 (gnus-article-hide-text beg end gnus-hidden-properties)
1299 (gnus-article-unhide-text beg end))
1303 (defconst article-time-units
1304 `((year . ,(* 365.25 24 60 60))
1305 (week . ,(* 7 24 60 60))
1306 (day . ,(* 24 60 60))
1310 "Mapping from time units to seconds.")
1312 (defun article-date-ut (&optional type highlight header)
1313 "Convert DATE date to universal time in the current article.
1314 If TYPE is `local', convert to local time; if it is `lapsed', output
1315 how much time has lapsed since DATE."
1316 (interactive (list 'ut t))
1317 (let* ((header (or header
1318 (mail-header-date gnus-current-headers)
1319 (message-fetch-field "date")
1321 (date (if (vectorp header) (mail-header-date header)
1323 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1324 (inhibit-point-motion-hooks t)
1325 bface eface newline)
1326 (when (and date (not (string= date "")))
1329 (nnheader-narrow-to-headers)
1330 (let ((buffer-read-only nil))
1331 ;; Delete any old Date headers.
1332 (if (re-search-forward date-regexp nil t)
1334 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1335 eface (get-text-property (1- (gnus-point-at-eol))
1337 (delete-region (progn (beginning-of-line) (point))
1338 (progn (end-of-line) (point)))
1339 (beginning-of-line))
1340 (goto-char (point-max))
1342 (insert (article-make-date-line date type))
1345 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1346 (put-text-property (match-beginning 1) (1+ (match-end 1))
1348 (put-text-property (match-beginning 2) (match-end 2)
1352 (insert "\n"))))))))
1354 (defun article-make-date-line (date type)
1355 "Return a DATE line of TYPE."
1357 ;; Convert to the local timezone. We have to slap a
1358 ;; `condition-case' round the calls to the timezone
1359 ;; functions since they aren't particularly resistant to
1362 (concat "Date: " (condition-case ()
1363 (timezone-make-date-arpa-standard date)
1365 ;; Convert to Universal Time.
1369 (timezone-make-date-arpa-standard date nil "UT")
1371 ;; Get the original date from the article.
1372 ((eq type 'original)
1373 (concat "Date: " date))
1374 ;; Let the user define the format.
1376 (if (gnus-functionp gnus-article-time-format)
1378 gnus-article-time-format
1381 (timezone-make-date-arpa-standard
1385 (format-time-string gnus-article-time-format
1388 (timezone-make-date-arpa-standard
1389 date nil "UT")))))))
1394 (format-time-string "%Y%M%DT%h%m%s"
1397 (timezone-make-date-arpa-standard
1399 ;; Do an X-Sent lapsed format.
1401 ;; If the date is seriously mangled, the timezone functions are
1402 ;; liable to bug out, so we ignore all errors.
1403 (let* ((now (current-time))
1408 (timezone-make-date-arpa-standard
1409 (current-time-string now)
1410 (current-time-zone now) "UT"))
1412 (timezone-make-date-arpa-standard
1414 (real-sec (and real-time
1415 (+ (* (float (car real-time)) 65536)
1417 (sec (and real-time (abs real-sec)))
1427 ;; This is a bit convoluted, but basically we go
1428 ;; through the time units for years, weeks, etc,
1429 ;; and divide things to see whether that results
1430 ;; in positive answers.
1433 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1434 ;; The (remaining) seconds are too few to
1435 ;; be divided into this time unit.
1437 ;; It's big enough, so we output it.
1438 (setq sec (- sec (* num (cdr unit))))
1440 (concat (if prev ", " "") (int-to-string
1442 " " (symbol-name (car unit))
1443 (if (> num 1) "s" ""))
1445 article-time-units "")
1446 ;; If dates are odd, then it might appear like the
1447 ;; article was sent in the future.
1450 " in the future"))))))
1452 (error "Unknown conversion type: %s" type))))
1454 (defun article-date-local (&optional highlight)
1455 "Convert the current article date to the local timezone."
1456 (interactive (list t))
1457 (article-date-ut 'local highlight))
1459 (defun article-date-original (&optional highlight)
1460 "Convert the current article date to what it was originally.
1461 This is only useful if you have used some other date conversion
1462 function and want to see what the date was before converting."
1463 (interactive (list t))
1464 (article-date-ut 'original highlight))
1466 (defun article-date-lapsed (&optional highlight)
1467 "Convert the current article date to time lapsed since it was sent."
1468 (interactive (list t))
1469 (article-date-ut 'lapsed highlight))
1471 (defun article-update-date-lapsed ()
1472 "Function to be run from a timer to update the lapsed time line."
1473 (let (deactivate-mark)
1476 (when (gnus-buffer-live-p gnus-article-buffer)
1477 (set-buffer gnus-article-buffer)
1478 (goto-char (point-min))
1479 (when (re-search-forward "^X-Sent:" nil t)
1480 (article-date-lapsed t)))))))
1482 (defun gnus-start-date-timer (&optional n)
1483 "Start a timer to update the X-Sent header in the article buffers.
1484 The numerical prefix says how frequently (in seconds) the function
1489 (gnus-stop-date-timer)
1490 (setq article-lapsed-timer
1491 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1493 (defun gnus-stop-date-timer ()
1494 "Stop the X-Sent timer."
1496 (when article-lapsed-timer
1497 (nnheader-cancel-timer article-lapsed-timer)
1498 (setq article-lapsed-timer nil)))
1500 (defun article-date-user (&optional highlight)
1501 "Convert the current article date to the user-defined format.
1502 This format is defined by the `gnus-article-time-format' variable."
1503 (interactive (list t))
1504 (article-date-ut 'user highlight))
1506 (defun article-date-iso8601 (&optional highlight)
1507 "Convert the current article date to ISO8601."
1508 (interactive (list t))
1509 (article-date-ut 'iso8601 highlight))
1511 (defun article-show-all ()
1512 "Show all hidden text in the article buffer."
1515 (let ((buffer-read-only nil))
1516 (gnus-article-unhide-text (point-min) (point-max)))))
1518 (defun article-emphasize (&optional arg)
1519 "Emphasize text according to `gnus-emphasis-alist'."
1520 (interactive (gnus-article-hidden-arg))
1521 (unless (gnus-article-check-hidden-text 'emphasis arg)
1523 (let ((alist gnus-emphasis-alist)
1524 (buffer-read-only nil)
1525 (props (append '(article-type emphasis)
1526 gnus-hidden-properties))
1527 regexp elem beg invisible visible face)
1528 (goto-char (point-min))
1529 (search-forward "\n\n" nil t)
1531 (while (setq elem (pop alist))
1533 (setq regexp (car elem)
1534 invisible (nth 1 elem)
1535 visible (nth 2 elem)
1537 (while (re-search-forward regexp nil t)
1538 (when (and (match-beginning visible) (match-beginning invisible))
1539 (gnus-article-hide-text
1540 (match-beginning invisible) (match-end invisible) props)
1541 (gnus-article-unhide-text-type
1542 (match-beginning visible) (match-end visible) 'emphasis)
1543 (gnus-put-text-property-excluding-newlines
1544 (match-beginning visible) (match-end visible) 'face face)
1545 (goto-char (match-end invisible)))))))))
1547 (defvar gnus-summary-article-menu)
1548 (defvar gnus-summary-post-menu)
1550 ;;; Saving functions.
1552 (defun gnus-article-save (save-buffer file &optional num)
1553 "Save the currently selected article."
1554 (unless gnus-save-all-headers
1555 ;; Remove headers according to `gnus-saved-headers'.
1556 (let ((gnus-visible-headers
1557 (or gnus-saved-headers gnus-visible-headers))
1558 (gnus-article-buffer save-buffer))
1560 (set-buffer save-buffer)
1561 (article-hide-headers 1 t))))
1562 (save-window-excursion
1563 (if (not gnus-default-article-saver)
1564 (error "No default saver is defined")
1565 ;; !!! Magic! The saving functions all save
1566 ;; `gnus-original-article-buffer' (or so they think), but we
1567 ;; bind that variable to our save-buffer.
1568 (set-buffer gnus-article-buffer)
1569 (let* ((gnus-save-article-buffer save-buffer)
1572 ((not gnus-prompt-before-saving) 'default)
1573 ((eq gnus-prompt-before-saving 'always) nil)
1575 (gnus-number-of-articles-to-be-saved
1576 (when (eq gnus-prompt-before-saving t)
1578 (set-buffer gnus-article-current-summary)
1579 (funcall gnus-default-article-saver filename)))))
1581 (defun gnus-read-save-file-name (prompt &optional filename
1582 function group headers variable)
1584 (funcall function group headers (symbol-value variable)))
1589 ((eq filename 'default)
1595 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1598 (if (and gnus-number-of-articles-to-be-saved
1599 (> gnus-number-of-articles-to-be-saved 1))
1600 (format "these %d articles"
1601 gnus-number-of-articles-to-be-saved)
1604 ;; Let the split methods have their say.
1606 ;; No split name was found.
1609 (concat prompt " (default "
1610 (file-name-nondirectory default-name) ") ")
1611 (file-name-directory default-name)
1613 ;; A single group name is returned.
1614 ((stringp split-name)
1616 (funcall function split-name headers
1617 (symbol-value variable)))
1619 (concat prompt " (default "
1620 (file-name-nondirectory default-name) ") ")
1621 (file-name-directory default-name)
1623 ;; A single split name was found
1624 ((= 1 (length split-name))
1625 (let* ((name (expand-file-name
1626 (car split-name) gnus-article-save-directory))
1627 (dir (cond ((file-directory-p name)
1628 (file-name-as-directory name))
1629 ((file-exists-p name) name)
1630 (t gnus-article-save-directory))))
1632 (concat prompt " (default " name ") ")
1634 ;; A list of splits was found.
1636 (setq split-name (nreverse split-name))
1638 (let ((file-name-history
1639 (nconc split-name file-name-history)))
1643 (concat prompt " (`M-p' for defaults) ")
1644 gnus-article-save-directory
1646 gnus-article-save-directory)))
1647 (car (push result file-name-history)))))))
1648 ;; Create the directory.
1649 (gnus-make-directory (file-name-directory file))
1650 ;; If we have read a directory, we append the default file name.
1651 (when (file-directory-p file)
1652 (setq file (concat (file-name-as-directory file)
1653 (file-name-nondirectory default-name))))
1654 ;; Possibly translate some characters.
1655 (nnheader-translate-file-chars file)))))
1656 (gnus-make-directory (file-name-directory result))
1657 (set variable result)))
1659 (defun gnus-article-archive-name (group)
1660 "Return the first instance of an \"Archive-name\" in the current buffer."
1661 (let ((case-fold-search t))
1662 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1663 (nnheader-concat gnus-article-save-directory
1664 (match-string 1)))))
1666 (defun gnus-article-nndoc-name (group)
1667 "If GROUP is an nndoc group, return the name of the parent group."
1668 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1669 (gnus-group-get-parameter group 'save-article-group)))
1671 (defun gnus-summary-save-in-rmail (&optional filename)
1672 "Append this article to Rmail file.
1673 Optional argument FILENAME specifies file name.
1674 Directory to save to is default to `gnus-article-save-directory'."
1675 (setq filename (gnus-read-save-file-name
1676 "Save %s in rmail file:" filename
1677 gnus-rmail-save-name gnus-newsgroup-name
1678 gnus-current-headers 'gnus-newsgroup-last-rmail))
1679 (gnus-eval-in-buffer-window gnus-save-article-buffer
1683 (gnus-output-to-rmail filename))))
1686 (defun gnus-summary-save-in-mail (&optional filename)
1687 "Append this article to Unix mail file.
1688 Optional argument FILENAME specifies file name.
1689 Directory to save to is default to `gnus-article-save-directory'."
1690 (setq filename (gnus-read-save-file-name
1691 "Save %s in Unix mail file:" filename
1692 gnus-mail-save-name gnus-newsgroup-name
1693 gnus-current-headers 'gnus-newsgroup-last-mail))
1694 (gnus-eval-in-buffer-window gnus-save-article-buffer
1698 (if (and (file-readable-p filename)
1699 (mail-file-babyl-p filename))
1700 (gnus-output-to-rmail filename t)
1701 (gnus-output-to-mail filename)))))
1704 (defun gnus-summary-save-in-file (&optional filename overwrite)
1705 "Append this article to file.
1706 Optional argument FILENAME specifies file name.
1707 Directory to save to is default to `gnus-article-save-directory'."
1708 (setq filename (gnus-read-save-file-name
1709 "Save %s in file:" filename
1710 gnus-file-save-name gnus-newsgroup-name
1711 gnus-current-headers 'gnus-newsgroup-last-file))
1712 (gnus-eval-in-buffer-window gnus-save-article-buffer
1716 (when (and overwrite
1717 (file-exists-p filename))
1718 (delete-file filename))
1719 (gnus-output-to-file filename))))
1722 (defun gnus-summary-write-to-file (&optional filename)
1723 "Write this article to a file.
1724 Optional argument FILENAME specifies file name.
1725 The directory to save in defaults to `gnus-article-save-directory'."
1726 (gnus-summary-save-in-file nil t))
1728 (defun gnus-summary-save-body-in-file (&optional filename)
1729 "Append this article body to a file.
1730 Optional argument FILENAME specifies file name.
1731 The directory to save in defaults to `gnus-article-save-directory'."
1732 (setq filename (gnus-read-save-file-name
1733 "Save %s body in file:" filename
1734 gnus-file-save-name gnus-newsgroup-name
1735 gnus-current-headers 'gnus-newsgroup-last-file))
1736 (gnus-eval-in-buffer-window gnus-save-article-buffer
1740 (goto-char (point-min))
1741 (when (search-forward "\n\n" nil t)
1742 (narrow-to-region (point) (point-max)))
1743 (gnus-output-to-file filename))))
1746 (defun gnus-summary-save-in-pipe (&optional command)
1747 "Pipe this article to subprocess."
1749 (cond ((eq command 'default)
1750 gnus-last-shell-command)
1754 "Shell command on %s: "
1755 (if (and gnus-number-of-articles-to-be-saved
1756 (> gnus-number-of-articles-to-be-saved 1))
1757 (format "these %d articles"
1758 gnus-number-of-articles-to-be-saved)
1760 gnus-last-shell-command))))
1761 (when (string-equal command "")
1762 (setq command gnus-last-shell-command))
1763 (gnus-eval-in-buffer-window gnus-article-buffer
1766 (shell-command-on-region (point-min) (point-max) command nil)))
1767 (setq gnus-last-shell-command command))
1769 ;;; Article file names when saving.
1771 (defun gnus-capitalize-newsgroup (newsgroup)
1772 "Capitalize NEWSGROUP name."
1773 (when (not (zerop (length newsgroup)))
1774 (concat (char-to-string (upcase (aref newsgroup 0)))
1775 (substring newsgroup 1))))
1777 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1778 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1779 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1780 Otherwise, it is like ~/News/news/group/num."
1783 (concat (if (gnus-use-long-file-name 'not-save)
1784 (gnus-capitalize-newsgroup newsgroup)
1785 (gnus-newsgroup-directory-form newsgroup))
1786 "/" (int-to-string (mail-header-number headers)))
1787 gnus-article-save-directory)))
1789 (string-equal (file-name-directory default)
1790 (file-name-directory last-file))
1791 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1793 (or last-file default))))
1795 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1796 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1797 If variable `gnus-use-long-file-name' is non-nil, it is
1798 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1801 (concat (if (gnus-use-long-file-name 'not-save)
1803 (gnus-newsgroup-directory-form newsgroup))
1804 "/" (int-to-string (mail-header-number headers)))
1805 gnus-article-save-directory)))
1807 (string-equal (file-name-directory default)
1808 (file-name-directory last-file))
1809 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1811 (or last-file default))))
1813 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1814 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1815 If variable `gnus-use-long-file-name' is non-nil, it is
1816 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1819 (if (gnus-use-long-file-name 'not-save)
1820 (gnus-capitalize-newsgroup newsgroup)
1821 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1822 gnus-article-save-directory)))
1824 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1825 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1826 If variable `gnus-use-long-file-name' is non-nil, it is
1827 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1830 (if (gnus-use-long-file-name 'not-save)
1832 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1833 gnus-article-save-directory)))
1840 (setq afunc (car func)
1843 gfunc (intern (format "gnus-%s" func))))
1845 (if (not (fboundp afunc))
1847 `(lambda (&optional interactive &rest args)
1848 ,(documentation afunc t)
1849 (interactive (list t))
1851 (set-buffer gnus-article-buffer)
1853 (call-interactively ',afunc)
1854 (apply ',afunc args))))))))
1855 '(article-hide-headers
1856 article-hide-boring-headers
1857 article-treat-overstrike
1858 (article-fill . gnus-article-word-wrap)
1860 article-display-x-face
1861 article-de-quoted-unreadable
1862 article-mime-decode-quoted-printable
1865 article-hide-signature
1866 article-remove-trailing-blank-lines
1867 article-strip-leading-blank-lines
1868 article-strip-multiple-blank-lines
1869 article-strip-leading-space
1870 article-strip-blank-lines
1871 article-strip-all-blank-lines
1873 article-date-iso8601
1874 article-date-original
1879 article-treat-dumbquotes
1880 (article-show-all . gnus-article-show-all-headers))))
1883 ;;; Gnus article mode
1886 (put 'gnus-article-mode 'mode-class 'special)
1888 (gnus-define-keys gnus-article-mode-map
1889 " " gnus-article-goto-next-page
1890 "\177" gnus-article-goto-prev-page
1891 [delete] gnus-article-goto-prev-page
1892 "\C-c^" gnus-article-refer-article
1893 "h" gnus-article-show-summary
1894 "s" gnus-article-show-summary
1895 "\C-c\C-m" gnus-article-mail
1896 "?" gnus-article-describe-briefly
1897 gnus-mouse-2 gnus-article-push-button
1898 "\r" gnus-article-press-button
1899 "\t" gnus-article-next-button
1900 "\M-\t" gnus-article-prev-button
1901 "e" gnus-article-edit
1902 "<" beginning-of-buffer
1904 "\C-c\C-i" gnus-info-find-node
1907 "\C-d" gnus-article-read-summary-keys
1908 "\M-*" gnus-article-read-summary-keys
1909 "\M-#" gnus-article-read-summary-keys
1910 "\M-^" gnus-article-read-summary-keys
1911 "\M-g" gnus-article-read-summary-keys)
1913 (substitute-key-definition
1914 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1916 (defun gnus-article-make-menu-bar ()
1917 (gnus-turn-off-edit-menu 'article)
1918 (unless (boundp 'gnus-article-article-menu)
1920 gnus-article-article-menu gnus-article-mode-map ""
1922 ["Scroll forwards" gnus-article-goto-next-page t]
1923 ["Scroll backwards" gnus-article-goto-prev-page t]
1924 ["Show summary" gnus-article-show-summary t]
1925 ["Fetch Message-ID at point" gnus-article-refer-article t]
1926 ["Mail to address at point" gnus-article-mail t]
1927 ["Send a bug report" gnus-bug t]))
1930 gnus-article-treatment-menu gnus-article-mode-map ""
1932 ["Hide headers" gnus-article-hide-headers t]
1933 ["Hide signature" gnus-article-hide-signature t]
1934 ["Hide citation" gnus-article-hide-citation t]
1935 ["Treat overstrike" gnus-article-treat-overstrike t]
1936 ["Remove carriage return" gnus-article-remove-cr t]
1937 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1939 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1941 (when (boundp 'gnus-summary-post-menu)
1942 (define-key gnus-article-mode-map [menu-bar post]
1943 (cons "Post" gnus-summary-post-menu)))
1945 (gnus-run-hooks 'gnus-article-menu-hook)))
1947 (defun gnus-article-mode ()
1948 "Major mode for displaying an article.
1950 All normal editing commands are switched off.
1952 The following commands are available in addition to all summary mode
1954 \\<gnus-article-mode-map>
1955 \\[gnus-article-next-page]\t Scroll the article one page forwards
1956 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1957 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1958 \\[gnus-article-show-summary]\t Display the summary buffer
1959 \\[gnus-article-mail]\t Send a reply to the address near point
1960 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1961 \\[gnus-info-find-node]\t Go to the Gnus info node"
1963 (when (gnus-visual-p 'article-menu 'menu)
1964 (gnus-article-make-menu-bar))
1965 (gnus-simplify-mode-line)
1966 (setq mode-name "Article")
1967 (setq major-mode 'gnus-article-mode)
1968 (make-local-variable 'minor-mode-alist)
1969 (unless (assq 'gnus-show-mime minor-mode-alist)
1970 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1971 (use-local-map gnus-article-mode-map)
1972 (gnus-update-format-specifications nil 'article-mode)
1973 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1974 (make-local-variable 'gnus-page-broken)
1975 (make-local-variable 'gnus-button-marker-list)
1976 (make-local-variable 'gnus-article-current-summary)
1977 (gnus-set-default-directory)
1978 (buffer-disable-undo (current-buffer))
1979 (setq buffer-read-only t)
1980 (set-syntax-table gnus-article-mode-syntax-table)
1981 (gnus-run-hooks 'gnus-article-mode-hook))
1983 (defun gnus-article-setup-buffer ()
1984 "Initialize the article buffer."
1985 (let* ((name (if gnus-single-article-buffer "*Article*"
1986 (concat "*Article " gnus-newsgroup-name "*")))
1988 (progn (string-match "\\*Article" name)
1989 (concat " *Original Article"
1990 (substring name (match-end 0))))))
1991 (setq gnus-article-buffer name)
1992 (setq gnus-original-article-buffer original)
1993 ;; This might be a variable local to the summary buffer.
1994 (unless gnus-single-article-buffer
1996 (set-buffer gnus-summary-buffer)
1997 (setq gnus-article-buffer name)
1998 (setq gnus-original-article-buffer original)
1999 (gnus-set-global-variables)))
2000 ;; Init original article buffer.
2002 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2003 (buffer-disable-undo (current-buffer))
2004 (setq major-mode 'gnus-original-article-mode)
2005 (make-local-variable 'gnus-original-article))
2006 (if (get-buffer name)
2009 (buffer-disable-undo (current-buffer))
2010 (setq buffer-read-only t)
2011 (unless (eq major-mode 'gnus-article-mode)
2012 (gnus-article-mode))
2015 (set-buffer (gnus-get-buffer-create name))
2017 (make-local-variable 'gnus-summary-buffer)
2018 (current-buffer)))))
2020 ;; Set article window start at LINE, where LINE is the number of lines
2021 ;; from the head of the article.
2022 (defun gnus-article-set-window-start (&optional line)
2024 (get-buffer-window gnus-article-buffer t)
2026 (set-buffer gnus-article-buffer)
2027 (goto-char (point-min))
2030 (gnus-message 6 "Moved to bookmark")
2031 (search-forward "\n\n" nil t)
2035 (defun gnus-article-prepare (article &optional all-headers header)
2036 "Prepare ARTICLE in article mode buffer.
2037 ARTICLE should either be an article number or a Message-ID.
2038 If ARTICLE is an id, HEADER should be the article headers.
2039 If ALL-HEADERS is non-nil, no headers are hidden."
2041 ;; Make sure we start in a summary buffer.
2042 (unless (eq major-mode 'gnus-summary-mode)
2043 (set-buffer gnus-summary-buffer))
2044 (setq gnus-summary-buffer (current-buffer))
2045 (let* ((gnus-article (if header (mail-header-number header) article))
2046 (summary-buffer (current-buffer))
2047 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2048 (group gnus-newsgroup-name)
2051 (gnus-article-setup-buffer)
2052 (set-buffer gnus-article-buffer)
2053 ;; Deactivate active regions.
2054 (when (and (boundp 'transient-mark-mode)
2055 transient-mark-mode)
2056 (setq mark-active nil))
2057 (if (not (setq result (let ((buffer-read-only nil))
2058 (gnus-request-article-this-buffer
2060 ;; There is no such article.
2062 (when (and (numberp article)
2063 (not (memq article gnus-newsgroup-sparse)))
2064 (setq gnus-article-current
2065 (cons gnus-newsgroup-name article))
2066 (set-buffer gnus-summary-buffer)
2067 (setq gnus-current-article article)
2068 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2070 (gnus-summary-set-agent-mark article)
2071 (message "Message marked for downloading"))
2072 (gnus-summary-mark-article article gnus-canceled-mark)
2073 (unless (memq article gnus-newsgroup-sparse)
2075 "No such article (may have expired or been canceled)")))))
2076 (if (or (eq result 'pseudo)
2077 (eq result 'nneething))
2080 (set-buffer summary-buffer)
2081 (push article gnus-newsgroup-history)
2082 (setq gnus-last-article gnus-current-article
2083 gnus-current-article 0
2084 gnus-current-headers nil
2085 gnus-article-current nil)
2086 (if (eq result 'nneething)
2087 (gnus-configure-windows 'summary)
2088 (gnus-configure-windows 'article))
2089 (gnus-set-global-variables))
2090 (gnus-set-mode-line 'article))
2091 ;; The result from the `request' was an actual article -
2092 ;; or at least some text that is now displayed in the
2094 (when (and (numberp article)
2095 (not (eq article gnus-current-article)))
2096 ;; Seems like a new article has been selected.
2097 ;; `gnus-current-article' must be an article number.
2099 (set-buffer summary-buffer)
2100 (push article gnus-newsgroup-history)
2101 (setq gnus-last-article gnus-current-article
2102 gnus-current-article article
2103 gnus-current-headers
2104 (gnus-summary-article-header gnus-current-article)
2105 gnus-article-current
2106 (cons gnus-newsgroup-name gnus-current-article))
2107 (unless (vectorp gnus-current-headers)
2108 (setq gnus-current-headers nil))
2109 (gnus-summary-goto-subject gnus-current-article)
2110 (when (gnus-summary-show-thread)
2111 ;; If the summary buffer really was folded, the
2112 ;; previous goto may not actually have gone to
2113 ;; the right article, but the thread root instead.
2115 (gnus-summary-goto-subject gnus-current-article))
2116 (gnus-run-hooks 'gnus-mark-article-hook)
2117 (gnus-set-mode-line 'summary)
2118 (when (gnus-visual-p 'article-highlight 'highlight)
2119 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2120 ;; Set the global newsgroup variables here.
2121 ;; Suggested by Jim Sisolak
2122 ;; <sisolak@trans4.neep.wisc.edu>.
2123 (gnus-set-global-variables)
2124 (setq gnus-have-all-headers
2125 (or all-headers gnus-show-all-headers))))
2126 (when (or (numberp article)
2128 ;; Hooks for getting information from the article.
2129 ;; This hook must be called before being narrowed.
2130 (let (buffer-read-only)
2131 (gnus-run-hooks 'gnus-tmp-internal-hook)
2132 (gnus-run-hooks 'gnus-article-prepare-hook)
2133 ;; Decode MIME message.
2134 (when gnus-show-mime
2135 (if (or (not gnus-strict-mime)
2136 (gnus-fetch-field "Mime-Version"))
2137 (let ((coding-system-for-write 'binary)
2138 (coding-system-for-read 'binary))
2139 (funcall gnus-show-mime-method))
2140 (funcall gnus-decode-encoded-word-method)))
2141 ;; Perform the article display hooks.
2142 (gnus-run-hooks 'gnus-article-display-hook))
2144 (goto-char (point-min))
2145 (setq gnus-page-broken
2146 (when gnus-break-pages
2147 (gnus-narrow-to-page)
2149 (gnus-set-mode-line 'article)
2150 (gnus-configure-windows 'article)
2151 (goto-char (point-min))
2152 (search-forward "\n\n" nil t)
2153 (set-window-point (get-buffer-window (current-buffer)) (point))
2156 (defun gnus-article-wash-status ()
2157 "Return a string which display status of article washing."
2159 (set-buffer gnus-article-buffer)
2160 (let ((cite (gnus-article-hidden-text-p 'cite))
2161 (headers (gnus-article-hidden-text-p 'headers))
2162 (boring (gnus-article-hidden-text-p 'boring-headers))
2163 (pgp (gnus-article-hidden-text-p 'pgp))
2164 (pem (gnus-article-hidden-text-p 'pem))
2165 (signature (gnus-article-hidden-text-p 'signature))
2166 (overstrike (gnus-article-hidden-text-p 'overstrike))
2167 (emphasis (gnus-article-hidden-text-p 'emphasis))
2168 (mime gnus-show-mime))
2169 (format "%c%c%c%c%c%c%c"
2171 (if (or headers boring) ?h ? )
2172 (if (or pgp pem) ?p ? )
2173 (if signature ?s ? )
2174 (if overstrike ?o ? )
2176 (if emphasis ?e ? )))))
2178 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2180 (defun gnus-article-maybe-hide-headers ()
2181 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2182 Provided for backwards compatibility."
2183 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2185 (gnus-article-hide-headers)))
2189 (defun gnus-output-to-file (file-name)
2190 "Append the current article to a file named FILE-NAME."
2191 (let ((artbuf (current-buffer)))
2192 (nnheader-temp-write nil
2193 (insert-buffer-substring artbuf)
2194 ;; Append newline at end of the buffer as separator, and then
2196 (goto-char (point-max))
2198 (append-to-file (point-min) (point-max) file-name)
2201 (defun gnus-narrow-to-page (&optional arg)
2202 "Narrow the article buffer to a page.
2203 If given a numerical ARG, move forward ARG pages."
2205 (setq arg (if arg (prefix-numeric-value arg) 0))
2207 (set-buffer gnus-article-buffer)
2208 (goto-char (point-min))
2210 ;; Remove any old next/prev buttons.
2211 (when (gnus-visual-p 'page-marker)
2212 (let ((buffer-read-only nil))
2213 (gnus-remove-text-with-property 'gnus-prev)
2214 (gnus-remove-text-with-property 'gnus-next)))
2217 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2219 (re-search-forward page-delimiter nil 'move arg)))
2220 (goto-char (match-end 0)))
2223 (if (re-search-forward page-delimiter nil 'move)
2226 (when (and (gnus-visual-p 'page-marker)
2227 (not (= (point-min) 1)))
2229 (goto-char (point-min))
2230 (gnus-insert-prev-page-button)))
2231 (when (and (gnus-visual-p 'page-marker)
2232 (< (+ (point-max) 2) (buffer-size)))
2234 (goto-char (point-max))
2235 (gnus-insert-next-page-button)))))
2237 ;; Article mode commands
2239 (defun gnus-article-goto-next-page ()
2240 "Show the next page of the article."
2242 (when (gnus-article-next-page)
2243 (goto-char (point-min))
2244 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2246 (defun gnus-article-goto-prev-page ()
2247 "Show the next page of the article."
2249 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2250 (gnus-article-prev-page nil)))
2252 (defun gnus-article-next-page (&optional lines)
2253 "Show the next page of the current article.
2254 If end of article, return non-nil. Otherwise return nil.
2255 Argument LINES specifies lines to be scrolled up."
2257 (move-to-window-line -1)
2260 (and (pos-visible-in-window-p) ;Not continuation line.
2262 ;; Nothing in this page.
2263 (if (or (not gnus-page-broken)
2266 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2268 (gnus-narrow-to-page 1) ;Go to next page.
2270 ;; More in this page.
2271 (let ((scroll-in-place nil))
2275 ;; Long lines may cause an end-of-buffer error.
2276 (goto-char (point-max)))))
2277 (move-to-window-line 0)
2280 (defun gnus-article-prev-page (&optional lines)
2281 "Show previous page of current article.
2282 Argument LINES specifies lines to be scrolled down."
2284 (move-to-window-line 0)
2285 (if (and gnus-page-broken
2287 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2289 (gnus-narrow-to-page -1) ;Go to previous page.
2290 (goto-char (point-max))
2292 (let ((scroll-in-place nil))
2296 (beginning-of-buffer
2297 (goto-char (point-min))))
2298 (move-to-window-line 0)))))
2300 (defun gnus-article-refer-article ()
2301 "Read article specified by message-id around point."
2303 (let ((point (point)))
2304 (search-forward ">" nil t) ;Move point to end of "<....>".
2305 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2306 (let ((message-id (match-string 1)))
2308 (set-buffer gnus-summary-buffer)
2309 (gnus-summary-refer-article message-id))
2311 (error "No references around point"))))
2313 (defun gnus-article-show-summary ()
2314 "Reconfigure windows to show summary buffer."
2316 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2317 (error "There is no summary buffer for this article buffer")
2318 (gnus-article-set-globals)
2319 (gnus-configure-windows 'article)
2320 (gnus-summary-goto-subject gnus-current-article)
2321 (gnus-summary-position-point)))
2323 (defun gnus-article-describe-briefly ()
2324 "Describe article mode commands briefly."
2327 (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")))
2329 (defun gnus-article-summary-command ()
2330 "Execute the last keystroke in the summary buffer."
2332 (let ((obuf (current-buffer))
2333 (owin (current-window-configuration))
2335 (switch-to-buffer gnus-article-current-summary 'norecord)
2336 (setq func (lookup-key (current-local-map) (this-command-keys)))
2337 (call-interactively func)
2339 (set-window-configuration owin)
2340 (set-window-point (get-buffer-window (current-buffer)) (point))))
2342 (defun gnus-article-summary-command-nosave ()
2343 "Execute the last keystroke in the summary buffer."
2346 (pop-to-buffer gnus-article-current-summary 'norecord)
2347 (setq func (lookup-key (current-local-map) (this-command-keys)))
2348 (call-interactively func)))
2350 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2351 "Read a summary buffer key sequence and execute it from the article buffer."
2354 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2355 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2356 "=" "^" "\M-^" "|"))
2362 '("n" "Gn" "p" "Gp"))
2365 (set-buffer gnus-article-current-summary)
2366 (let (gnus-pick-mode)
2367 (push (or key last-command-event) unread-command-events)
2368 (setq keys (read-key-sequence nil))))
2371 (if (or (member keys nosaves)
2372 (member keys nosave-but-article)
2373 (member keys nosave-in-article))
2375 (save-window-excursion
2376 (pop-to-buffer gnus-article-current-summary 'norecord)
2377 ;; We disable the pick minor mode commands.
2378 (let (gnus-pick-mode)
2379 (setq func (lookup-key (current-local-map) keys))))
2382 (unless (member keys nosave-in-article)
2383 (set-buffer gnus-article-current-summary))
2384 (call-interactively func)
2385 (setq new-sum-point (point)))
2386 (when (member keys nosave-but-article)
2387 (pop-to-buffer gnus-article-buffer 'norecord)))
2388 ;; These commands should restore window configuration.
2389 (let ((obuf (current-buffer))
2390 (owin (current-window-configuration))
2392 (summary gnus-article-current-summary)
2393 func in-buffer selected)
2394 (if not-restore-window
2395 (pop-to-buffer summary 'norecord)
2396 (switch-to-buffer summary 'norecord))
2397 (setq in-buffer (current-buffer))
2398 ;; We disable the pick minor mode commands.
2399 (if (setq func (let (gnus-pick-mode)
2400 (lookup-key (current-local-map) keys)))
2402 (call-interactively func)
2403 (setq new-sum-point (point)))
2405 (when (eq in-buffer (current-buffer))
2406 (setq selected (gnus-summary-select-article))
2408 (unless not-restore-window
2409 (set-window-configuration owin))
2410 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2411 (set-window-point (get-buffer-window (current-buffer))
2413 (let ((win (get-buffer-window gnus-article-current-summary)))
2415 (set-window-point win new-sum-point))))))))
2417 (defun gnus-article-hide (&optional arg force)
2418 "Hide all the gruft in the current article.
2419 This means that PGP stuff, signatures, cited text and (some)
2420 headers will be hidden.
2421 If given a prefix, show the hidden text instead."
2422 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2423 (gnus-article-hide-headers arg)
2424 (gnus-article-hide-pgp arg)
2425 (gnus-article-hide-citation-maybe arg force)
2426 (gnus-article-hide-signature arg))
2428 (defun gnus-article-maybe-highlight ()
2429 "Do some article highlighting if article highlighting is requested."
2430 (when (gnus-visual-p 'article-highlight 'highlight)
2431 (gnus-article-highlight-some)))
2433 (defun gnus-check-group-server ()
2434 ;; Make sure the connection to the server is alive.
2435 (unless (gnus-server-opened
2436 (gnus-find-method-for-group gnus-newsgroup-name))
2437 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2438 (gnus-request-group gnus-newsgroup-name t)))
2440 (defun gnus-request-article-this-buffer (article group)
2441 "Get an article and insert it into this buffer."
2442 (let (do-update-line sparse-header)
2446 (gnus-kill-all-overlays)
2447 (setq group (or group gnus-newsgroup-name))
2449 ;; Using `gnus-request-article' directly will insert the article into
2450 ;; `nntp-server-buffer' - so we'll save some time by not having to
2451 ;; copy it from the server buffer into the article buffer.
2453 ;; We only request an article by message-id when we do not have the
2454 ;; headers for it, so we'll have to get those.
2455 (when (stringp article)
2456 (let ((gnus-override-method gnus-refer-article-method))
2457 (gnus-read-header article)))
2459 ;; If the article number is negative, that means that this article
2460 ;; doesn't belong in this newsgroup (possibly), so we find its
2461 ;; message-id and request it by id instead of number.
2462 (when (and (numberp article)
2464 (get-buffer gnus-summary-buffer)
2465 (gnus-buffer-exists-p gnus-summary-buffer))
2467 (set-buffer gnus-summary-buffer)
2468 (let ((header (gnus-summary-article-header article)))
2471 ((memq article gnus-newsgroup-sparse)
2472 ;; This is a sparse gap article.
2473 (setq do-update-line article)
2474 (setq article (mail-header-id header))
2475 (let ((gnus-override-method gnus-refer-article-method))
2476 (setq sparse-header (gnus-read-header article)))
2477 (setq gnus-newsgroup-sparse
2478 (delq article gnus-newsgroup-sparse)))
2480 ;; It's a real article.
2481 (setq article (mail-header-id header)))
2483 ;; It is an extracted pseudo-article.
2484 (setq article 'pseudo)
2485 (gnus-request-pseudo-article header))))
2487 (let ((method (gnus-find-method-for-group
2488 gnus-newsgroup-name)))
2489 (when (and (eq (car method) 'nneething)
2492 (file-name-as-directory
2493 (or (cadr (assq 'nneething-address method))
2495 (mail-header-subject header))))
2496 (when (file-directory-p dir)
2497 (setq article 'nneething)
2498 (gnus-group-enter-directory dir))))))))
2501 ;; Refuse to select canceled articles.
2502 ((and (numberp article)
2504 (get-buffer gnus-summary-buffer)
2505 (gnus-buffer-exists-p gnus-summary-buffer)
2506 (eq (cdr (save-excursion
2507 (set-buffer gnus-summary-buffer)
2508 (assq article gnus-newsgroup-reads)))
2509 gnus-canceled-mark))
2511 ;; We first check `gnus-original-article-buffer'.
2512 ((and (get-buffer gnus-original-article-buffer)
2515 (set-buffer gnus-original-article-buffer)
2516 (and (equal (car gnus-original-article) group)
2517 (eq (cdr gnus-original-article) article))))
2518 (insert-buffer-substring gnus-original-article-buffer)
2520 ;; Check the backlog.
2521 ((and gnus-keep-backlog
2522 (gnus-backlog-request-article group article (current-buffer)))
2524 ;; Check asynchronous pre-fetch.
2525 ((gnus-async-request-fetched-article group article (current-buffer))
2526 (gnus-async-prefetch-next group article gnus-summary-buffer)
2527 (when (and (numberp article) gnus-keep-backlog)
2528 (gnus-backlog-enter-article group article (current-buffer)))
2531 ((and gnus-use-cache
2533 (gnus-cache-request-article article group))
2535 ;; Get the article and put into the article buffer.
2536 ((or (stringp article) (numberp article))
2537 (let ((gnus-override-method
2538 (and (stringp article) gnus-refer-article-method))
2539 (buffer-read-only nil))
2541 (gnus-kill-all-overlays)
2542 (gnus-check-group-server)
2543 (when (gnus-request-article article group (current-buffer))
2544 (when (numberp article)
2545 (gnus-async-prefetch-next group article gnus-summary-buffer)
2546 (when gnus-keep-backlog
2547 (gnus-backlog-enter-article
2548 group article (current-buffer))))
2553 ;; Associate this article with the current summary buffer.
2554 (setq gnus-article-current-summary gnus-summary-buffer)
2556 ;; Take the article from the original article buffer
2557 ;; and place it in the buffer it's supposed to be in.
2558 (when (and (get-buffer gnus-article-buffer)
2559 (equal (buffer-name (current-buffer))
2560 (buffer-name (get-buffer gnus-article-buffer))))
2562 (if (get-buffer gnus-original-article-buffer)
2563 (set-buffer gnus-original-article-buffer)
2564 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2565 (buffer-disable-undo (current-buffer))
2566 (setq major-mode 'gnus-original-article-mode)
2567 (setq buffer-read-only t))
2568 (let (buffer-read-only)
2570 (insert-buffer-substring gnus-article-buffer))
2571 (setq gnus-original-article (cons group article))))
2573 ;; Update sparse articles.
2574 (when (and do-update-line
2575 (or (numberp article)
2577 (let ((buf (current-buffer)))
2578 (set-buffer gnus-summary-buffer)
2579 (gnus-summary-update-article do-update-line sparse-header)
2580 (gnus-summary-goto-subject do-update-line nil t)
2581 (set-window-point (get-buffer-window (current-buffer) t)
2583 (set-buffer buf))))))
2589 (defcustom gnus-article-edit-mode-hook nil
2590 "Hook run in article edit mode buffers."
2591 :group 'gnus-article-various
2594 (defvar gnus-article-edit-done-function nil)
2596 (defvar gnus-article-edit-mode-map nil)
2598 (unless gnus-article-edit-mode-map
2599 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2601 (gnus-define-keys gnus-article-edit-mode-map
2602 "\C-c\C-c" gnus-article-edit-done
2603 "\C-c\C-k" gnus-article-edit-exit)
2605 (gnus-define-keys (gnus-article-edit-wash-map
2606 "\C-c\C-w" gnus-article-edit-mode-map)
2607 "f" gnus-article-edit-full-stops))
2609 (defun gnus-article-edit-mode ()
2610 "Major mode for editing articles.
2611 This is an extended text-mode.
2613 \\{gnus-article-edit-mode-map}"
2615 (setq major-mode 'gnus-article-edit-mode)
2616 (setq mode-name "Article Edit")
2617 (use-local-map gnus-article-edit-mode-map)
2618 (make-local-variable 'gnus-article-edit-done-function)
2619 (make-local-variable 'gnus-prev-winconf)
2620 (setq buffer-read-only nil)
2621 (buffer-enable-undo)
2623 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2625 (defun gnus-article-edit (&optional force)
2626 "Edit the current article.
2627 This will have permanent effect only in mail groups.
2628 If FORCE is non-nil, allow editing of articles even in read-only
2631 (when (and (not force)
2632 (gnus-group-read-only-p))
2633 (error "The current newsgroup does not support article editing"))
2634 (gnus-article-date-original)
2635 (gnus-article-edit-article
2636 `(lambda (no-highlight)
2637 (gnus-summary-edit-article-done
2638 ,(or (mail-header-references gnus-current-headers) "")
2639 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2641 (defun gnus-article-edit-article (exit-func)
2642 "Start editing the contents of the current article buffer."
2643 (let ((winconf (current-window-configuration)))
2644 (set-buffer gnus-article-buffer)
2645 (gnus-article-edit-mode)
2646 (gnus-article-delete-text-of-type 'annotation)
2647 (gnus-set-text-properties (point-min) (point-max) nil)
2648 (gnus-configure-windows 'edit-article)
2649 (setq gnus-article-edit-done-function exit-func)
2650 (setq gnus-prev-winconf winconf)
2651 (gnus-message 6 "C-c C-c to end edits")))
2653 (defun gnus-article-edit-done (&optional arg)
2654 "Update the article edits and exit."
2659 (goto-char (point-min))
2660 (when (search-forward "\n\n" nil 1)
2661 (let ((lines (count-lines (point) (point-max)))
2662 (length (- (point-max) (point)))
2663 (case-fold-search t)
2664 (body (copy-marker (point))))
2665 (goto-char (point-min))
2666 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2667 (delete-region (match-beginning 1) (match-end 1))
2668 (insert (number-to-string length)))
2669 (goto-char (point-min))
2670 (when (re-search-forward
2671 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2672 (delete-region (match-beginning 1) (match-end 1))
2673 (insert (number-to-string length)))
2674 (goto-char (point-min))
2675 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2676 (delete-region (match-beginning 1) (match-end 1))
2677 (insert (number-to-string lines)))))))
2678 (let ((func gnus-article-edit-done-function)
2679 (buf (current-buffer))
2680 (start (window-start)))
2681 (gnus-article-edit-exit)
2684 (let ((buffer-read-only nil))
2685 (funcall func arg)))
2687 (set-window-start (get-buffer-window buf) start)
2688 (set-window-point (get-buffer-window buf) (point))))
2690 (defun gnus-article-edit-exit ()
2691 "Exit the article editing without updating."
2693 ;; We remove all text props from the article buffer.
2694 (let ((buf (format "%s" (buffer-string)))
2695 (curbuf (current-buffer))
2697 (window-start (window-start)))
2700 (let ((winconf gnus-prev-winconf))
2702 ;; The cache and backlog have to be flushed somewhat.
2703 (when gnus-use-cache
2704 (gnus-cache-update-article
2705 (car gnus-article-current) (cdr gnus-article-current)))
2706 (when gnus-keep-backlog
2707 (gnus-backlog-remove-article
2708 (car gnus-article-current) (cdr gnus-article-current)))
2709 ;; Flush original article as well.
2711 (when (get-buffer gnus-original-article-buffer)
2712 (set-buffer gnus-original-article-buffer)
2713 (setq gnus-original-article nil)))
2714 (set-window-configuration winconf)
2715 ;; Tippy-toe some to make sure that point remains where it was.
2716 (let ((buf (current-buffer)))
2718 (set-window-start (get-buffer-window (current-buffer)) window-start)
2720 (set-buffer buf)))))
2722 (defun gnus-article-edit-full-stops ()
2723 "Interactively repair spacing at end of sentences."
2726 (goto-char (point-min))
2727 (search-forward-regexp "^$" nil t)
2728 (let ((case-fold-search nil))
2729 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2732 ;;; Article highlights
2735 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2737 ;;; Internal Variables:
2739 (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\\)"
2740 "Regular expression that matches URLs."
2741 :group 'gnus-article-buttons
2744 (defcustom gnus-button-alist
2745 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2746 gnus-button-message-id 2)
2747 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2748 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2750 gnus-button-fetch-group 4)
2751 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2752 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2753 t gnus-button-message-id 3)
2754 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2755 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2756 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2757 ;; This is how URLs _should_ be embedded in text...
2758 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2760 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2761 "*Alist of regexps matching buttons in article bodies.
2763 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2764 REGEXP: is the string matching text around the button,
2765 BUTTON: is the number of the regexp grouping actually matching the button,
2766 FORM: is a lisp expression which must eval to true for the button to
2768 CALLBACK: is the function to call when the user push this button, and each
2769 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2771 CALLBACK can also be a variable, in that case the value of that
2772 variable it the real callback function."
2773 :group 'gnus-article-buttons
2774 :type '(repeat (list regexp
2775 (integer :tag "Button")
2777 (function :tag "Callback")
2780 (integer :tag "Regexp group")))))
2782 (defcustom gnus-header-button-alist
2783 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2784 0 t gnus-button-message-id 0)
2785 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2786 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2787 0 t gnus-button-mailto 0)
2788 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2789 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2790 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2791 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2792 gnus-button-message-id 3))
2793 "*Alist of headers and regexps to match buttons in article heads.
2795 This alist is very similar to `gnus-button-alist', except that each
2796 alist has an additional HEADER element first in each entry:
2798 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2800 HEADER is a regexp to match a header. For a fuller explanation, see
2801 `gnus-button-alist'."
2802 :group 'gnus-article-buttons
2803 :group 'gnus-article-headers
2804 :type '(repeat (list (regexp :tag "Header")
2806 (integer :tag "Button")
2808 (function :tag "Callback")
2811 (integer :tag "Regexp group")))))
2813 (defvar gnus-button-regexp nil)
2814 (defvar gnus-button-marker-list nil)
2815 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2817 (defvar gnus-button-last nil)
2818 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2822 (defun gnus-article-push-button (event)
2823 "Check text under the mouse pointer for a callback function.
2824 If the text under the mouse pointer has a `gnus-callback' property,
2825 call it with the value of the `gnus-data' text property."
2827 (set-buffer (window-buffer (posn-window (event-start event))))
2828 (let* ((pos (posn-point (event-start event)))
2829 (data (get-text-property pos 'gnus-data))
2830 (fun (get-text-property pos 'gnus-callback)))
2833 (funcall fun data))))
2835 (defun gnus-article-press-button ()
2836 "Check text at point for a callback function.
2837 If the text at point has a `gnus-callback' property,
2838 call it with the value of the `gnus-data' text property."
2840 (let* ((data (get-text-property (point) 'gnus-data))
2841 (fun (get-text-property (point) 'gnus-callback)))
2843 (funcall fun data))))
2845 (defun gnus-article-prev-button (n)
2846 "Move point to N buttons backward.
2847 If N is negative, move forward instead."
2849 (gnus-article-next-button (- n)))
2851 (defun gnus-article-next-button (n)
2852 "Move point to N buttons forward.
2853 If N is negative, move backward instead."
2855 (let ((function (if (< n 0) 'previous-single-property-change
2856 'next-single-property-change))
2857 (inhibit-point-motion-hooks t)
2859 (limit (if (< n 0) (point-min) (point-max))))
2861 (while (and (not (= limit (point)))
2863 ;; Skip past the current button.
2864 (when (get-text-property (point) 'gnus-callback)
2865 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2866 ;; Go to the next (or previous) button.
2867 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2868 ;; Put point at the start of the button.
2869 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2870 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2871 ;; Skip past intangible buttons.
2872 (when (get-text-property (point) 'intangible)
2876 (gnus-message 5 "No more buttons"))
2879 (defun gnus-article-highlight (&optional force)
2880 "Highlight current article.
2881 This function calls `gnus-article-highlight-headers',
2882 `gnus-article-highlight-citation',
2883 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2884 do the highlighting. See the documentation for those functions."
2885 (interactive (list 'force))
2886 (gnus-article-highlight-headers)
2887 (gnus-article-highlight-citation force)
2888 (gnus-article-highlight-signature)
2889 (gnus-article-add-buttons force)
2890 (gnus-article-add-buttons-to-head))
2892 (defun gnus-article-highlight-some (&optional force)
2893 "Highlight current article.
2894 This function calls `gnus-article-highlight-headers',
2895 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2896 do the highlighting. See the documentation for those functions."
2897 (interactive (list 'force))
2898 (gnus-article-highlight-headers)
2899 (gnus-article-highlight-signature)
2900 (gnus-article-add-buttons))
2902 (defun gnus-article-highlight-headers ()
2903 "Highlight article headers as specified by `gnus-header-face-alist'."
2906 (set-buffer gnus-article-buffer)
2908 (let ((alist gnus-header-face-alist)
2909 (buffer-read-only nil)
2910 (case-fold-search t)
2911 (inhibit-point-motion-hooks t)
2912 entry regexp header-face field-face from hpoints fpoints)
2913 (message-narrow-to-head)
2914 (while (setq entry (pop alist))
2915 (goto-char (point-min))
2916 (setq regexp (concat "^\\("
2917 (if (string-equal "" (nth 0 entry))
2921 header-face (nth 1 entry)
2922 field-face (nth 2 entry))
2923 (while (and (re-search-forward regexp nil t)
2927 (unless (search-forward ":" nil t)
2929 (when (and header-face
2930 (not (memq (point) hpoints)))
2931 (push (point) hpoints)
2932 (gnus-put-text-property from (point) 'face header-face))
2933 (when (and field-face
2934 (not (memq (setq from (point)) fpoints)))
2936 (if (re-search-forward "^[^ \t]" nil t)
2938 (goto-char (point-max)))
2939 (gnus-put-text-property from (point) 'face field-face))))))))
2941 (defun gnus-article-highlight-signature ()
2942 "Highlight the signature in an article.
2943 It does this by highlighting everything after
2944 `gnus-signature-separator' using `gnus-signature-face'."
2947 (set-buffer gnus-article-buffer)
2948 (let ((buffer-read-only nil)
2949 (inhibit-point-motion-hooks t))
2951 (when (and gnus-signature-face
2952 (gnus-article-narrow-to-signature))
2953 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2954 'face gnus-signature-face)
2956 (gnus-article-search-signature)
2957 (let ((start (match-beginning 0))
2958 (end (set-marker (make-marker) (1+ (match-end 0)))))
2959 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2962 (defun gnus-button-in-region-p (b e prop)
2963 "Say whether PROP exists in the region."
2964 (text-property-not-all b e prop nil))
2966 (defun gnus-article-add-buttons (&optional force)
2967 "Find external references in the article and make buttons of them.
2968 \"External references\" are things like Message-IDs and URLs, as
2969 specified by `gnus-button-alist'."
2970 (interactive (list 'force))
2972 (set-buffer gnus-article-buffer)
2973 (let ((buffer-read-only nil)
2974 (inhibit-point-motion-hooks t)
2975 (case-fold-search t)
2976 (alist gnus-button-alist)
2978 ;; Remove all old markers.
2980 (while (setq marker (pop gnus-button-marker-list))
2982 (when (setq entry (gnus-button-entry))
2983 (put-text-property (match-beginning (nth 1 entry))
2984 (match-end (nth 1 entry))
2985 'gnus-callback nil))
2986 (set-marker marker nil)))
2987 ;; We skip the headers.
2988 (goto-char (point-min))
2989 (unless (search-forward "\n\n" nil t)
2990 (goto-char (point-max)))
2992 (while (setq entry (pop alist))
2993 (setq regexp (car entry))
2995 (while (re-search-forward regexp nil t)
2996 (let* ((start (and entry (match-beginning (nth 1 entry))))
2997 (end (and entry (match-end (nth 1 entry))))
2998 (from (match-beginning 0)))
2999 (when (and (or (eq t (nth 2 entry))
3000 (eval (nth 2 entry)))
3001 (not (gnus-button-in-region-p
3002 start end 'gnus-callback)))
3003 ;; That optional form returned non-nil, so we add the
3005 (gnus-article-add-button
3006 start end 'gnus-button-push
3007 (car (push (set-marker (make-marker) from)
3008 gnus-button-marker-list))))))))))
3010 ;; Add buttons to the head of an article.
3011 (defun gnus-article-add-buttons-to-head ()
3012 "Add buttons to the head of the article."
3015 (set-buffer gnus-article-buffer)
3016 (let ((buffer-read-only nil)
3017 (inhibit-point-motion-hooks t)
3018 (case-fold-search t)
3019 (alist gnus-header-button-alist)
3021 (nnheader-narrow-to-headers)
3023 ;; Each alist entry.
3024 (setq entry (car alist)
3026 (goto-char (point-min))
3027 (while (re-search-forward (car entry) nil t)
3028 ;; Each header matching the entry.
3029 (setq beg (match-beginning 0))
3030 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3031 (match-beginning 0))
3034 (while (re-search-forward (nth 1 entry) end t)
3035 ;; Each match within a header.
3036 (let* ((entry (cdr entry))
3037 (start (match-beginning (nth 1 entry)))
3038 (end (match-end (nth 1 entry)))
3039 (form (nth 2 entry)))
3040 (goto-char (match-end 0))
3042 (gnus-article-add-button
3043 start end (nth 3 entry)
3044 (buffer-substring (match-beginning (nth 4 entry))
3045 (match-end (nth 4 entry)))))))
3049 ;;; External functions:
3051 (defun gnus-article-add-button (from to fun &optional data)
3052 "Create a button between FROM and TO with callback FUN and data DATA."
3053 (when gnus-article-button-face
3054 (gnus-overlay-put (gnus-make-overlay from to)
3055 'face gnus-article-button-face))
3056 (gnus-add-text-properties
3058 (nconc (and gnus-article-mouse-face
3059 (list gnus-mouse-face-prop gnus-article-mouse-face))
3060 (list 'gnus-callback fun)
3061 (and data (list 'gnus-data data)))))
3063 ;;; Internal functions:
3065 (defun gnus-article-set-globals ()
3067 (set-buffer gnus-summary-buffer)
3068 (gnus-set-global-variables)))
3070 (defun gnus-signature-toggle (end)
3072 (set-buffer gnus-article-buffer)
3073 (let ((buffer-read-only nil)
3074 (inhibit-point-motion-hooks t))
3075 (if (get-text-property end 'invisible)
3076 (gnus-article-unhide-text end (point-max))
3077 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3079 (defun gnus-button-entry ()
3080 ;; Return the first entry in `gnus-button-alist' matching this place.
3081 (let ((alist gnus-button-alist)
3084 (setq entry (pop alist))
3085 (if (looking-at (car entry))
3090 (defun gnus-button-push (marker)
3091 ;; Push button starting at MARKER.
3093 (set-buffer gnus-article-buffer)
3095 (let* ((entry (gnus-button-entry))
3096 (inhibit-point-motion-hooks t)
3098 (args (mapcar (lambda (group)
3099 (let ((string (match-string group)))
3100 (gnus-set-text-properties
3101 0 (length string) nil string)
3108 (fboundp (symbol-value fun)))
3109 (apply (symbol-value fun) args))
3111 (gnus-message 1 "You must define `%S' to use this button"
3112 (cons fun args)))))))
3114 (defun gnus-button-message-id (message-id)
3117 (set-buffer gnus-summary-buffer)
3118 (gnus-summary-refer-article message-id)))
3120 (defun gnus-button-fetch-group (address)
3121 "Fetch GROUP specified by ADDRESS."
3122 (if (not (string-match "[:/]" address))
3123 ;; This is just a simple group url.
3124 (gnus-group-read-ephemeral-group address gnus-select-method)
3125 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3127 (error "Can't parse %s" address)
3128 (gnus-group-read-ephemeral-group
3129 (match-string 4 address)
3130 `(nntp ,(match-string 1 address)
3131 (nntp-address ,(match-string 1 address))
3132 (nntp-port-number ,(if (match-end 3)
3133 (match-string 3 address)
3136 (defun gnus-url-parse-query-string (query &optional downcase)
3137 (let (retval pairs cur key val)
3138 (setq pairs (gnus-split-string query "&"))
3140 (setq cur (car pairs)
3142 (if (not (string-match "=" cur))
3144 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3145 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3147 (setq key (downcase key)))
3148 (setq cur (assoc key retval))
3150 (setcdr cur (cons val (cdr cur)))
3151 (setq retval (cons (list key val) retval)))))
3154 (defun gnus-url-unhex (x)
3161 (defun gnus-url-unhex-string (str &optional allow-newlines)
3162 "Remove %XXX embedded spaces, etc in a url.
3163 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3164 decoding of carriage returns and line feeds in the string, which is normally
3165 forbidden in URL encoding."
3166 (setq str (or str ""))
3168 (case-fold-search t))
3169 (while (string-match "%[0-9a-f][0-9a-f]" str)
3170 (let* ((start (match-beginning 0))
3171 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3173 (gnus-url-unhex (elt str (+ start 2))))))
3175 tmp (substring str 0 start)
3178 (char-to-string code))
3179 ((or (= code ?\n) (= code ?\r))
3181 (t (char-to-string code))))
3182 str (substring str (match-end 0)))))
3183 (setq tmp (concat tmp str))
3186 (defun gnus-url-mailto (url)
3187 ;; Send mail to someone
3188 (when (string-match "mailto:/*\\(.*\\)" url)
3189 (setq url (substring url (match-beginning 1) nil)))
3190 (let (to args subject func)
3191 (if (string-match (regexp-quote "?") url)
3192 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3193 args (gnus-url-parse-query-string
3194 (substring url (match-end 0) nil) t))
3195 (setq to (gnus-url-unhex-string url)))
3196 (setq args (cons (list "to" to) args)
3197 subject (cdr-safe (assoc "subject" args)))
3200 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3203 (message-position-on-field (caar args)))
3204 (insert (mapconcat 'identity (cdar args) ", "))
3205 (setq args (cdr args)))
3208 (message-goto-subject))))
3210 (defun gnus-button-mailto (address)
3212 (set-buffer (gnus-copy-article-buffer))
3213 (message-reply address))
3215 (defun gnus-button-reply (address)
3216 ;; Reply to ADDRESS.
3217 (message-reply address))
3219 (defun gnus-button-url (address)
3221 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3222 (if (listp browse-url-browser-function)
3223 (browse-url address)
3224 (funcall browse-url-browser-function address)))
3226 (defun gnus-button-embedded-url (address)
3228 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3229 (if (listp browse-url-browser-function)
3230 (browse-url (gnus-strip-whitespace address))
3231 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3233 ;;; Next/prev buttons in the article buffer.
3235 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3236 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3238 (defvar gnus-prev-page-map nil)
3239 (unless gnus-prev-page-map
3240 (setq gnus-prev-page-map (make-sparse-keymap))
3241 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3242 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3244 (defun gnus-insert-prev-page-button ()
3245 (let ((buffer-read-only nil))
3247 gnus-prev-page-line-format nil
3248 `(gnus-prev t local-map ,gnus-prev-page-map
3249 gnus-callback gnus-article-button-prev-page
3250 gnus-type annotation))))
3252 (defvar gnus-next-page-map nil)
3253 (unless gnus-next-page-map
3254 (setq gnus-next-page-map (make-keymap))
3255 (suppress-keymap gnus-prev-page-map)
3256 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3257 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3259 (defun gnus-button-next-page ()
3260 "Go to the next page."
3262 (let ((win (selected-window)))
3263 (select-window (get-buffer-window gnus-article-buffer t))
3264 (gnus-article-next-page)
3265 (select-window win)))
3267 (defun gnus-button-prev-page ()
3268 "Go to the prev page."
3270 (let ((win (selected-window)))
3271 (select-window (get-buffer-window gnus-article-buffer t))
3272 (gnus-article-prev-page)
3273 (select-window win)))
3275 (defun gnus-insert-next-page-button ()
3276 (let ((buffer-read-only nil))
3277 (gnus-eval-format gnus-next-page-line-format nil
3279 t local-map ,gnus-next-page-map
3280 gnus-callback gnus-article-button-next-page
3281 gnus-type annotation))))
3283 (defun gnus-article-button-next-page (arg)
3284 "Go to the next page."
3286 (let ((win (selected-window)))
3287 (select-window (get-buffer-window gnus-article-buffer t))
3288 (gnus-article-next-page)
3289 (select-window win)))
3291 (defun gnus-article-button-prev-page (arg)
3292 "Go to the prev page."
3294 (let ((win (selected-window)))
3295 (select-window (get-buffer-window gnus-article-buffer t))
3296 (gnus-article-prev-page)
3297 (select-window win)))
3303 (run-hooks 'gnus-art-load-hook)
3305 ;;; gnus-art.el ends here