1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
40 (defgroup gnus-article nil
42 :link '(custom-manual "(gnus)The Article Buffer")
45 (defgroup gnus-article-hiding nil
46 "Hiding article parts."
47 :link '(custom-manual "(gnus)Article Hiding")
50 (defgroup gnus-article-highlight nil
51 "Article highlighting."
52 :link '(custom-manual "(gnus)Article Highlighting")
56 (defgroup gnus-article-signature nil
58 :link '(custom-manual "(gnus)Article Signature")
61 (defgroup gnus-article-headers nil
63 :link '(custom-manual "(gnus)Hiding Headers")
66 (defgroup gnus-article-washing nil
67 "Special commands on articles."
68 :link '(custom-manual "(gnus)Article Washing")
71 (defgroup gnus-article-emphasis nil
72 "Fontisizing articles."
73 :link '(custom-manual "(gnus)Article Fontisizing")
76 (defgroup gnus-article-saving nil
78 :link '(custom-manual "(gnus)Saving Articles")
81 (defgroup gnus-article-mime nil
82 "Worshiping the MIME wonder."
83 :link '(custom-manual "(gnus)Using MIME")
86 (defgroup gnus-article-buttons nil
87 "Pushable buttons in the article buffer."
88 :link '(custom-manual "(gnus)Article Buttons")
91 (defgroup gnus-article-various nil
92 "Other article options."
93 :link '(custom-manual "(gnus)Misc Article")
96 (defcustom gnus-ignored-headers
97 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
98 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
99 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
100 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
101 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
102 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
103 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
104 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
105 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
106 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
107 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
108 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
109 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
110 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
111 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
112 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
113 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
114 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
116 "*All headers that start with this regexp will be hidden.
117 This variable can also be a list of regexps of headers to be ignored.
118 If `gnus-visible-headers' is non-nil, this variable will be ignored."
119 :type '(choice :custom-show nil
122 :group 'gnus-article-hiding)
124 (defcustom gnus-visible-headers
125 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
126 "*All headers that do not match this regexp will be hidden.
127 This variable can also be a list of regexp of headers to remain visible.
128 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
129 :type '(repeat :value-to-internal (lambda (widget value)
130 (custom-split-regexp-maybe value))
131 :match (lambda (widget value)
133 (widget-editable-list-match widget value)))
135 :group 'gnus-article-hiding)
137 (defcustom gnus-sorted-header-list
138 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
139 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
140 "*This variable is a list of regular expressions.
141 If it is non-nil, headers that match the regular expressions will
142 be placed first in the article buffer in the sequence specified by
144 :type '(repeat regexp)
145 :group 'gnus-article-hiding)
147 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
148 "Headers that are only to be displayed if they have interesting data.
149 Possible values in this list are `empty', `newsgroups', `followup-to',
150 `reply-to', `date', `long-to', and `many-to'."
151 :type '(set (const :tag "Headers with no content." empty)
152 (const :tag "Newsgroups with only one group." newsgroups)
153 (const :tag "Followup-to identical to newsgroups." followup-to)
154 (const :tag "Reply-to identical to from." reply-to)
155 (const :tag "Date less than four days old." date)
156 (const :tag "Very long To header." long-to)
157 (const :tag "Multiple To headers." many-to))
158 :group 'gnus-article-hiding)
160 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
161 "Regexp matching signature separator.
162 This can also be a list of regexps. In that case, it will be checked
163 from head to tail looking for a separator. Searches will be done from
164 the end of the buffer."
165 :type '(repeat string)
166 :group 'gnus-article-signature)
168 (defcustom gnus-signature-limit nil
169 "Provide a limit to what is considered a signature.
170 If it is a number, no signature may not be longer (in characters) than
171 that number. If it is a floating point number, no signature may be
172 longer (in lines) than that number. If it is a function, the function
173 will be called without any parameters, and if it returns nil, there is
174 no signature in the buffer. If it is a string, it will be used as a
175 regexp. If it matches, the text in question is not a signature."
176 :type '(choice (integer :value 200)
178 (function :value fun)
179 (regexp :value ".*"))
180 :group 'gnus-article-signature)
182 (defcustom gnus-hidden-properties '(invisible t intangible t)
183 "Property list to use for hiding text."
185 :group 'gnus-article-hiding)
187 (defcustom gnus-article-x-face-command
188 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
189 "*String or function to be executed to display an X-Face header.
190 If it is a string, the command will be executed in a sub-shell
191 asynchronously. The compressed face will be piped to this command."
192 :type 'string ;Leave function case to Lisp.
193 :group 'gnus-article-washing)
195 (defcustom gnus-article-x-face-too-ugly nil
196 "Regexp matching posters whose face shouldn't be shown automatically."
197 :type '(choice regexp (const nil))
198 :group 'gnus-article-washing)
200 (defcustom gnus-emphasis-alist
202 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
204 '(("_" "_" underline)
207 ("_/" "/_" underline-italic)
208 ("_\\*" "\\*_" underline-bold)
209 ("\\*/" "/\\*" bold-italic)
210 ("_\\*/" "/\\*_" underline-bold-italic))))
211 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
212 2 3 gnus-emphasis-underline)
216 (format format (car spec) (cadr spec))
217 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
219 "*Alist that says how to fontify certain phrases.
220 Each item looks like this:
222 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
224 The first element is a regular expression to be matched. The second
225 is a number that says what regular expression grouping used to find
226 the entire emphasized word. The third is a number that says what
227 regexp grouping should be displayed and highlighted. The fourth
228 is the face used for highlighting."
229 :type '(repeat (list :value ("" 0 0 default)
231 (integer :tag "Match group")
232 (integer :tag "Emphasize group")
234 :group 'gnus-article-emphasis)
236 (defface gnus-emphasis-bold '((t (:bold t)))
237 "Face used for displaying strong emphasized text (*word*)."
238 :group 'gnus-article-emphasis)
240 (defface gnus-emphasis-italic '((t (:italic t)))
241 "Face used for displaying italic emphasized text (/word/)."
242 :group 'gnus-article-emphasis)
244 (defface gnus-emphasis-underline '((t (:underline t)))
245 "Face used for displaying underlined emphasized text (_word_)."
246 :group 'gnus-article-emphasis)
248 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
249 "Face used for displaying underlined bold emphasized text (_*word*_)."
250 :group 'gnus-article-emphasis)
252 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
253 "Face used for displaying underlined italic emphasized text (_*word*_)."
254 :group 'gnus-article-emphasis)
256 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
257 "Face used for displaying bold italic emphasized text (/*word*/)."
258 :group 'gnus-article-emphasis)
260 (defface gnus-emphasis-underline-bold-italic
261 '((t (:bold t :italic t :underline t)))
262 "Face used for displaying underlined bold italic emphasized text.
263 Esample: (_/*word*/_)."
264 :group 'gnus-article-emphasis)
266 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
267 "Format for display of Date headers in article bodies.
268 See `format-time-string' for the possible values.
270 The variable can also be function, which should return a complete Date
271 header. The function is called with one argument, the time, which can
272 be fed to `format-time-string'."
273 :type '(choice string symbol)
274 :link '(custom-manual "(gnus)Article Date")
275 :group 'gnus-article-washing)
278 (autoload 'mail-extract-address-components "mail-extr"))
280 (defcustom gnus-save-all-headers t
281 "*If non-nil, don't remove any headers before saving."
282 :group 'gnus-article-saving
285 (defcustom gnus-prompt-before-saving 'always
286 "*This variable says how much prompting is to be done when saving articles.
287 If it is nil, no prompting will be done, and the articles will be
288 saved to the default files. If this variable is `always', each and
289 every article that is saved will be preceded by a prompt, even when
290 saving large batches of articles. If this variable is neither nil not
291 `always', there the user will be prompted once for a file name for
292 each invocation of the saving commands."
293 :group 'gnus-article-saving
294 :type '(choice (item always)
295 (item :tag "never" nil)
296 (sexp :tag "once" :format "%t\n" :value t)))
298 (defcustom gnus-saved-headers gnus-visible-headers
299 "Headers to keep if `gnus-save-all-headers' is nil.
300 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
301 If that variable is nil, however, all headers that match this regexp
302 will be kept while the rest will be deleted before saving."
303 :group 'gnus-article-saving
306 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
307 "A function to save articles in your favourite format.
308 The function must be interactively callable (in other words, it must
309 be an Emacs command).
311 Gnus provides the following functions:
313 * gnus-summary-save-in-rmail (Rmail format)
314 * gnus-summary-save-in-mail (Unix mail format)
315 * gnus-summary-save-in-folder (MH folder)
316 * gnus-summary-save-in-file (article format)
317 * gnus-summary-save-in-vm (use VM's folder format)
318 * gnus-summary-write-to-file (article format -- overwrite)."
319 :group 'gnus-article-saving
320 :type '(radio (function-item gnus-summary-save-in-rmail)
321 (function-item gnus-summary-save-in-mail)
322 (function-item gnus-summary-save-in-folder)
323 (function-item gnus-summary-save-in-file)
324 (function-item gnus-summary-save-in-vm)
325 (function-item gnus-summary-write-to-file)))
327 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
328 "A function generating a file name to save articles in Rmail format.
329 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
330 :group 'gnus-article-saving
333 (defcustom gnus-mail-save-name 'gnus-plain-save-name
334 "A function generating a file name to save articles in Unix mail format.
335 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
336 :group 'gnus-article-saving
339 (defcustom gnus-folder-save-name 'gnus-folder-save-name
340 "A function generating a file name to save articles in MH folder.
341 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
342 :group 'gnus-article-saving
345 (defcustom gnus-file-save-name 'gnus-numeric-save-name
346 "A function generating a file name to save articles in article format.
347 The function is called with NEWSGROUP, HEADERS, and optional
349 :group 'gnus-article-saving
352 (defcustom gnus-split-methods
353 '((gnus-article-archive-name)
354 (gnus-article-nndoc-name))
355 "*Variable used to suggest where articles are to be saved.
356 For instance, if you would like to save articles related to Gnus in
357 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
358 you could set this variable to something like:
360 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
361 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
363 This variable is an alist where the where the key is the match and the
364 value is a list of possible files to save in if the match is non-nil.
366 If the match is a string, it is used as a regexp match on the
367 article. If the match is a symbol, that symbol will be funcalled
368 from the buffer of the article to be saved with the newsgroup as the
369 parameter. If it is a list, it will be evaled in the same buffer.
371 If this form or function returns a string, this string will be used as
372 a possible file name; and if it returns a non-nil list, that list will
373 be used as possible file names."
374 :group 'gnus-article-saving
375 :type '(repeat (choice (list :value (fun) function)
376 (cons :value ("" "") regexp (repeat string))
379 (defcustom gnus-strict-mime t
380 "*If nil, MIME-decode even if there is no MIME-Version header."
381 :group 'gnus-article-mime
384 (defcustom gnus-article-display-method-for-mime
385 'gnus-article-display-mime-message
386 "Function to display a MIME message.
387 The function is called from the article buffer."
388 :group 'gnus-article-mime
391 (defcustom gnus-article-display-method-for-encoded-word
392 'gnus-article-display-message-with-encoded-word
393 "*Function to display a message with MIME encoded-words.
394 The function is called from the article buffer."
395 :group 'gnus-article-mime
398 (defcustom gnus-article-display-method-for-traditional
399 'gnus-article-display-traditional-message
400 "*Function to display a traditional message.
401 The function is called from the article buffer."
402 :group 'gnus-article-mime
405 (defcustom gnus-page-delimiter "^\^L"
406 "*Regexp describing what to use as article page delimiters.
407 The default value is \"^\^L\", which is a form linefeed at the
408 beginning of a line."
410 :group 'gnus-article-various)
412 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
413 "*The format specification for the article mode line.
414 See `gnus-summary-mode-line-format' for a closer description."
416 :group 'gnus-article-various)
418 (defcustom gnus-article-mode-hook nil
419 "*A hook for Gnus article mode."
421 :group 'gnus-article-various)
423 (defcustom gnus-article-menu-hook nil
424 "*Hook run after the creation of the article mode menu."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-prepare-hook nil
429 "*A hook called after an article has been prepared in the article buffer.
430 If you want to run a special decoding program like nkf, use this hook."
432 :group 'gnus-article-various)
434 (defcustom gnus-article-hide-pgp-hook nil
435 "*A hook called after successfully hiding a PGP signature."
437 :group 'gnus-article-various)
439 (defcustom gnus-article-button-face 'bold
440 "Face used for highlighting buttons in the article buffer.
442 An article button is a piece of text that you can activate by pressing
443 `RET' or `mouse-2' above it."
445 :group 'gnus-article-buttons)
447 (defcustom gnus-article-mouse-face 'highlight
448 "Face used for mouse highlighting in the article buffer.
450 Article buttons will be displayed in this face when the cursor is
453 :group 'gnus-article-buttons)
455 (defcustom gnus-signature-face 'gnus-signature-face
456 "Face used for highlighting a signature in the article buffer.
457 Obsolete; use the face `gnus-signature-face' for customizations instead."
459 :group 'gnus-article-highlight
460 :group 'gnus-article-signature)
462 (defface gnus-signature-face
465 "Face used for highlighting a signature in the article buffer."
466 :group 'gnus-article-highlight
467 :group 'gnus-article-signature)
469 (defface gnus-header-from-face
472 (:foreground "spring green"))
475 (:foreground "red3"))
478 "Face used for displaying from headers."
479 :group 'gnus-article-headers
480 :group 'gnus-article-highlight)
482 (defface gnus-header-subject-face
485 (:foreground "SeaGreen3"))
488 (:foreground "red4"))
490 (:bold t :italic t)))
491 "Face used for displaying subject headers."
492 :group 'gnus-article-headers
493 :group 'gnus-article-highlight)
495 (defface gnus-header-newsgroups-face
498 (:foreground "yellow" :italic t))
501 (:foreground "MidnightBlue" :italic t))
504 "Face used for displaying newsgroups headers."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight)
508 (defface gnus-header-name-face
511 (:foreground "SeaGreen"))
514 (:foreground "maroon"))
517 "Face used for displaying header names."
518 :group 'gnus-article-headers
519 :group 'gnus-article-highlight)
521 (defface gnus-header-content-face
524 (:foreground "forest green" :italic t))
527 (:foreground "indianred4" :italic t))
529 (:italic t))) "Face used for displaying header content."
530 :group 'gnus-article-headers
531 :group 'gnus-article-highlight)
533 (defcustom gnus-header-face-alist
534 '(("From" nil gnus-header-from-face)
535 ("Subject" nil gnus-header-subject-face)
536 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
537 ("" gnus-header-name-face gnus-header-content-face))
538 "*Controls highlighting of article header.
540 An alist of the form (HEADER NAME CONTENT).
542 HEADER is a regular expression which should match the name of an
543 header header and NAME and CONTENT are either face names or nil.
545 The name of each header field will be displayed using the face
546 specified by the first element in the list where HEADER match the
547 header name and NAME is non-nil. Similarly, the content will be
548 displayed by the first non-nil matching CONTENT face."
549 :group 'gnus-article-headers
550 :group 'gnus-article-highlight
551 :type '(repeat (list (regexp :tag "Header")
553 (item :tag "skip" nil)
554 (face :value default))
555 (choice :tag "Content"
556 (item :tag "skip" nil)
557 (face :value default)))))
559 (defcustom gnus-article-decode-hook nil
560 "*Hook run to decode charsets in articles.")
562 ;;; Internal variables
564 (defvar article-lapsed-timer nil)
565 (defvar gnus-article-current-summary nil)
567 (defvar gnus-article-mode-syntax-table
568 (let ((table (copy-syntax-table text-mode-syntax-table)))
569 (modify-syntax-entry ?- "w" table)
570 (modify-syntax-entry ?> ")" table)
571 (modify-syntax-entry ?< "(" table)
573 "Syntax table used in article mode buffers.
574 Initialized from `text-mode-syntax-table.")
576 (defvar gnus-save-article-buffer nil)
578 (defvar gnus-article-mode-line-format-alist
579 (nconc '((?w (gnus-article-wash-status) ?s))
580 gnus-summary-mode-line-format-alist))
582 (defvar gnus-number-of-articles-to-be-saved nil)
584 (defvar gnus-inhibit-hiding nil)
586 (defsubst gnus-article-hide-text (b e props)
587 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
588 (add-text-properties b e props)
589 (when (memq 'intangible props)
591 (max (1- b) (point-min))
592 b 'intangible (cddr (memq 'intangible props)))))
594 (defsubst gnus-article-unhide-text (b e)
595 "Remove hidden text properties from region between B and E."
596 (remove-text-properties b e 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-type (b e type)
602 "Hide text of TYPE between B and E."
603 (gnus-article-hide-text
604 b e (cons 'article-type (cons type gnus-hidden-properties))))
606 (defun gnus-article-unhide-text-type (b e type)
607 "Unhide text of TYPE between B and E."
608 (remove-text-properties
609 b e (cons 'article-type (cons type gnus-hidden-properties)))
610 (when (memq 'intangible gnus-hidden-properties)
611 (put-text-property (max (1- b) (point-min))
614 (defun gnus-article-hide-text-of-type (type)
615 "Hide text of TYPE in the current buffer."
617 (let ((b (point-min))
619 (while (setq b (text-property-any b e 'article-type type))
620 (add-text-properties b (incf b) gnus-hidden-properties)))))
622 (defun gnus-article-delete-text-of-type (type)
623 "Delete text of TYPE in the current buffer."
625 (let ((b (point-min)))
626 (while (setq b (text-property-any b (point-max) 'article-type type))
628 b (or (text-property-not-all b (point-max) 'article-type type)
631 (defun gnus-article-delete-invisible-text ()
632 "Delete all invisible text in the current buffer."
634 (let ((b (point-min)))
635 (while (setq b (text-property-any b (point-max) 'invisible t))
637 b (or (text-property-not-all b (point-max) 'invisible t)
640 (defun gnus-article-text-type-exists-p (type)
641 "Say whether any text of type TYPE exists in the buffer."
642 (text-property-any (point-min) (point-max) 'article-type type))
644 (defsubst gnus-article-header-rank ()
645 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
646 (let ((list gnus-sorted-header-list)
649 (when (looking-at (car list))
651 (setq list (cdr list))
655 (defun article-hide-headers (&optional arg delete)
656 "Toggle whether to hide unwanted headers and possibly sort them as well.
657 If given a negative prefix, always show; if given a positive prefix,
659 (interactive (gnus-article-hidden-arg))
661 (if (gnus-article-check-hidden-text 'headers arg)
662 ;; Show boring headers as well.
663 (gnus-article-show-hidden-text 'boring-headers)
664 ;; This function might be inhibited.
665 (unless gnus-inhibit-hiding
668 (let ((buffer-read-only nil)
670 (props (nconc (list 'article-type 'headers)
671 gnus-hidden-properties))
672 (max (1+ (length gnus-sorted-header-list)))
673 (ignored (when (not gnus-visible-headers)
674 (cond ((stringp gnus-ignored-headers)
675 gnus-ignored-headers)
676 ((listp gnus-ignored-headers)
677 (mapconcat 'identity gnus-ignored-headers
680 (cond ((stringp gnus-visible-headers)
681 gnus-visible-headers)
682 ((and gnus-visible-headers
683 (listp gnus-visible-headers))
684 (mapconcat 'identity gnus-visible-headers "\\|"))))
685 (inhibit-point-motion-hooks t)
687 ;; First we narrow to just the headers.
689 (goto-char (point-min))
690 ;; Hide any "From " lines at the beginning of (mail) articles.
691 (while (looking-at "From ")
695 (delete-region (point-min) (point))
696 (gnus-article-hide-text (point-min) (point) props)))
697 ;; Then treat the rest of the header lines.
700 (if (search-forward "\n\n" nil t) ; if there's a body
701 (progn (forward-line -1) (point))
703 ;; Then we use the two regular expressions
704 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
705 ;; select which header lines is to remain visible in the
707 (goto-char (point-min))
708 (while (re-search-forward "^[^ \t]*:" nil t)
710 ;; Mark the rank of the header.
712 (point) (1+ (point)) 'message-rank
713 (if (or (and visible (looking-at visible))
715 (not (looking-at ignored))))
716 (gnus-article-header-rank)
719 (message-sort-headers-1)
720 (when (setq beg (text-property-any
721 (point-min) (point-max) 'message-rank (+ 2 max)))
722 ;; We make the unwanted headers invisible.
724 (delete-region beg (point-max))
725 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
726 (gnus-article-hide-text-type beg (point-max) 'headers))
727 ;; Work around XEmacs lossage.
728 (put-text-property (point-min) beg 'invisible nil))))))))
730 (defun article-hide-boring-headers (&optional arg)
731 "Toggle hiding of headers that aren't very interesting.
732 If given a negative prefix, always show; if given a positive prefix,
734 (interactive (gnus-article-hidden-arg))
735 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
736 (not gnus-show-all-headers))
739 (let ((buffer-read-only nil)
740 (list gnus-boring-article-headers)
741 (inhibit-point-motion-hooks t)
743 (nnheader-narrow-to-headers)
745 (setq elem (pop list))
746 (goto-char (point-min))
748 ;; Hide empty headers.
750 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
752 (gnus-article-hide-text-type
753 (progn (beginning-of-line) (point))
756 (if (re-search-forward "^[^ \t]" nil t)
760 ;; Hide boring Newsgroups header.
761 ((eq elem 'newsgroups)
762 (when (equal (gnus-fetch-field "newsgroups")
763 (gnus-group-real-name
764 (if (boundp 'gnus-newsgroup-name)
767 (gnus-article-hide-header "newsgroups")))
768 ((eq elem 'followup-to)
769 (when (equal (message-fetch-field "followup-to")
770 (message-fetch-field "newsgroups"))
771 (gnus-article-hide-header "followup-to")))
773 (let ((from (message-fetch-field "from"))
774 (reply-to (message-fetch-field "reply-to")))
779 (nth 1 (funcall gnus-extract-address-components from))
780 (nth 1 (funcall gnus-extract-address-components reply-to)))))
781 (gnus-article-hide-header "reply-to"))))
783 (let ((date (message-fetch-field "date")))
785 (< (days-between (current-time-string) date)
787 (gnus-article-hide-header "date"))))
789 (let ((to (message-fetch-field "to")))
790 (when (> (length to) 1024)
791 (gnus-article-hide-header "to"))))
794 (goto-char (point-min))
795 (while (re-search-forward "^to:" nil t)
796 (setq to-count (1+ to-count)))
798 (while (> to-count 0)
799 (goto-char (point-min))
801 (re-search-forward "^to:" nil nil to-count)
803 (narrow-to-region (point) (point-max))
804 (gnus-article-hide-header "to"))
805 (setq to-count (1- to-count)))))))))))))
807 (defun gnus-article-hide-header (header)
809 (goto-char (point-min))
810 (when (re-search-forward (concat "^" header ":") nil t)
811 (gnus-article-hide-text-type
812 (progn (beginning-of-line) (point))
815 (if (re-search-forward "^[^ \t]" nil t)
820 (defun article-treat-dumbquotes ()
821 "Translate M******** sm*rtq**t*s into proper text."
823 (article-translate-characters "\221\222\223\224" "`'\"\""))
825 (defun article-translate-characters (from to)
826 "Translate all characters in the body of the article according to FROM and TO.
827 FROM is a string of characters to translate from; to is a string of
828 characters to translate to."
830 (goto-char (point-min))
831 (when (search-forward "\n\n" nil t)
832 (let ((buffer-read-only nil)
833 (x (make-string 225 ?x))
835 (while (< (incf i) (length x))
838 (while (< i (length from))
839 (aset x (aref from i) (aref to i))
841 (translate-region (point) (point-max) x)))))
843 (defun article-treat-overstrike ()
844 "Translate overstrikes into bold text."
847 (goto-char (point-min))
848 (when (search-forward "\n\n" nil t)
849 (let ((buffer-read-only nil))
850 (while (search-forward "\b" nil t)
851 (let ((next (following-char))
852 (previous (char-after (- (point) 2))))
853 ;; We do the boldification/underlining by hiding the
854 ;; overstrikes and putting the proper text property
858 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
859 (put-text-property (point) (1+ (point)) 'face 'bold))
861 (gnus-article-hide-text-type
862 (1- (point)) (1+ (point)) 'overstrike)
864 (- (point) 2) (1- (point)) 'face 'underline))
866 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
868 (point) (1+ (point)) 'face 'underline)))))))))
870 (defun article-fill ()
871 "Format too long lines."
874 (let ((buffer-read-only nil))
876 (goto-char (point-min))
877 (search-forward "\n\n" nil t)
879 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
880 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
881 (adaptive-fill-mode t))
883 (and (>= (current-column) (min fill-column (window-width)))
884 (/= (preceding-char) ?:)
885 (fill-paragraph nil))
888 (defun article-remove-cr ()
889 "Remove carriage returns from an article."
892 (let ((buffer-read-only nil))
893 (goto-char (point-min))
894 (while (search-forward "\r" nil t)
895 (replace-match "" t t)))))
897 (defun article-remove-trailing-blank-lines ()
898 "Remove all trailing blank lines from the article."
901 (let ((buffer-read-only nil))
902 (goto-char (point-max))
906 (while (and (not (bobp))
907 (looking-at "^[ \t]*$"))
912 (defun article-display-x-face (&optional force)
913 "Look for an X-Face header and display it if present."
914 (interactive (list 'force))
916 ;; Delete the old process, if any.
917 (when (process-status "article-x-face")
918 (delete-process "article-x-face"))
919 (let ((inhibit-point-motion-hooks t)
923 (nnheader-narrow-to-headers)
924 (setq from (message-fetch-field "from"))
925 (goto-char (point-min))
926 (while (and gnus-article-x-face-command
929 ;; Check whether this face is censored.
930 (not gnus-article-x-face-too-ugly)
931 (and gnus-article-x-face-too-ugly from
932 (not (string-match gnus-article-x-face-too-ugly
934 ;; Has to be present.
935 (re-search-forward "^X-Face: " nil t))
936 ;; This used to try to do multiple faces (`while' instead of
937 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
938 ;; work (b) it can crash some versions of Emacs (c) are
939 ;; multiple faces really something to encourage?
940 (when (stringp gnus-article-x-face-command)
942 ;; We now have the area of the buffer where the X-Face is stored.
945 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
946 ;; We display the face.
947 (if (symbolp gnus-article-x-face-command)
948 ;; The command is a lisp function, so we call it.
949 (if (gnus-functionp gnus-article-x-face-command)
950 (funcall gnus-article-x-face-command beg end)
951 (error "%s is not a function" gnus-article-x-face-command))
952 ;; The command is a string, so we interpret the command
953 ;; as a, well, command, and fork it off.
954 (let ((process-connection-type nil))
955 (process-kill-without-query
957 "article-x-face" nil shell-file-name shell-command-switch
958 gnus-article-x-face-command))
959 (process-send-region "article-x-face" beg end)
960 (process-send-eof "article-x-face"))))))))))
962 (defun gnus-article-decode-rfc1522 ()
963 "Decode MIME encoded-words in header fields."
964 (let (buffer-read-only)
965 (let ((charset (save-excursion
966 (set-buffer gnus-summary-buffer)
967 default-mime-charset)))
968 (eword-decode-header charset)
971 (defun article-hide-pgp (&optional arg)
972 "Toggle hiding of any PGP headers and signatures in the current article.
973 If given a negative prefix, always show; if given a positive prefix,
975 (interactive (gnus-article-hidden-arg))
976 (unless (gnus-article-check-hidden-text 'pgp arg)
978 (let ((inhibit-point-motion-hooks t)
979 buffer-read-only beg end)
981 (goto-char (point-min))
982 ;; Hide the "header".
983 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
984 (delete-region (1+ (match-beginning 0)) (match-end 0))
986 ;; Hide the actual signature.
987 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
988 (setq end (1+ (match-beginning 0)))
991 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
993 ;; Perhaps we shouldn't hide to the end of the buffer
994 ;; if there is no end to the signature?
996 ;; Hide "- " PGP quotation markers.
998 (narrow-to-region beg end)
999 (goto-char (point-min))
1000 (while (re-search-forward "^- " nil t)
1002 (match-beginning 0) (match-end 0)))
1004 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1006 (defun article-hide-pem (&optional arg)
1007 "Toggle hiding of any PEM headers and signatures in the current article.
1008 If given a negative prefix, always show; if given a positive prefix,
1010 (interactive (gnus-article-hidden-arg))
1011 (unless (gnus-article-check-hidden-text 'pem arg)
1013 (let (buffer-read-only end)
1015 (goto-char (point-min))
1016 ;; hide the horrendously ugly "header".
1017 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1020 (setq end (1+ (match-beginning 0)))
1021 (gnus-article-hide-text-type
1023 (if (search-forward "\n\n" nil t)
1027 ;; hide the trailer as well
1028 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1031 (gnus-article-hide-text-type
1032 (match-beginning 0) (match-end 0) 'pem))))))
1034 (defun article-hide-signature (&optional arg)
1035 "Hide the signature in the current article.
1036 If given a negative prefix, always show; if given a positive prefix,
1038 (interactive (gnus-article-hidden-arg))
1039 (unless (gnus-article-check-hidden-text 'signature arg)
1042 (let ((buffer-read-only nil))
1043 (when (gnus-article-narrow-to-signature)
1044 (gnus-article-hide-text-type
1045 (point-min) (point-max) 'signature)))))))
1047 (defun article-strip-leading-blank-lines ()
1048 "Remove all blank lines from the beginning of the article."
1051 (let ((inhibit-point-motion-hooks t)
1053 (goto-char (point-min))
1054 (when (search-forward "\n\n" nil t)
1055 (while (and (not (eobp))
1056 (looking-at "[ \t]*$"))
1057 (gnus-delete-line))))))
1059 (defun article-strip-multiple-blank-lines ()
1060 "Replace consecutive blank lines with one empty line."
1063 (let ((inhibit-point-motion-hooks t)
1065 ;; First make all blank lines empty.
1066 (goto-char (point-min))
1067 (search-forward "\n\n" nil t)
1068 (while (re-search-forward "^[ \t]+$" nil t)
1069 (replace-match "" nil t))
1070 ;; Then replace multiple empty lines with a single empty line.
1071 (goto-char (point-min))
1072 (search-forward "\n\n" nil t)
1073 (while (re-search-forward "\n\n\n+" nil t)
1074 (replace-match "\n\n" t t)))))
1076 (defun article-strip-leading-space ()
1077 "Remove all white space from the beginning of the lines in the article."
1080 (let ((inhibit-point-motion-hooks t)
1082 (goto-char (point-min))
1083 (search-forward "\n\n" nil t)
1084 (while (re-search-forward "^[ \t]+" nil t)
1085 (replace-match "" t t)))))
1087 (defun article-strip-blank-lines ()
1088 "Strip leading, trailing and multiple blank lines."
1090 (article-strip-leading-blank-lines)
1091 (article-remove-trailing-blank-lines)
1092 (article-strip-multiple-blank-lines))
1094 (defun article-strip-all-blank-lines ()
1095 "Strip all blank lines."
1098 (let ((inhibit-point-motion-hooks t)
1100 (goto-char (point-min))
1101 (search-forward "\n\n" nil t)
1102 (while (re-search-forward "^[ \t]*\n" nil t)
1103 (replace-match "" t t)))))
1105 (defun gnus-article-narrow-to-signature ()
1106 "Narrow to the signature; return t if a signature is found, else nil."
1108 (let ((inhibit-point-motion-hooks t))
1109 (when (gnus-article-search-signature)
1111 ;; Check whether we have some limits to what we consider
1112 ;; to be a signature.
1113 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1114 (list gnus-signature-limit)))
1116 (while (setq limit (pop limits))
1117 (if (or (and (integerp limit)
1118 (< (- (point-max) (point)) limit))
1120 (< (count-lines (point) (point-max)) limit))
1121 (and (gnus-functionp limit)
1123 (and (stringp limit)
1124 (not (re-search-forward limit nil t))))
1125 () ; This limit did not succeed.
1129 (narrow-to-region (point) (point-max))
1132 (defun gnus-article-search-signature ()
1133 "Search the current buffer for the signature separator.
1134 Put point at the beginning of the signature separator."
1135 (let ((cur (point)))
1136 (goto-char (point-max))
1137 (if (if (stringp gnus-signature-separator)
1138 (re-search-backward gnus-signature-separator nil t)
1139 (let ((seps gnus-signature-separator))
1141 (not (re-search-backward (car seps) nil t)))
1149 (autoload 'w3-display "w3-parse")
1150 (autoload 'w3-do-setup "w3" "" t)
1151 (autoload 'w3-region "w3-display" "" t))
1153 (defun gnus-article-treat-html ()
1156 (let ((cbuf (current-buffer)))
1157 (set-buffer gnus-article-buffer)
1158 (let (buf buffer-read-only b e)
1160 (goto-char (point-min))
1162 (if (search-forward "\n\n" nil t)
1165 (setq e (point-max)))
1167 (insert-buffer-substring gnus-article-buffer b e)
1169 (save-window-excursion
1170 (w3-region (point-min) (point-max))
1171 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1173 (delete-region (point-min) (point-max))
1176 (goto-char (point-min))
1177 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1178 (set-buffer cbuf))))
1180 (defun gnus-article-hidden-arg ()
1181 "Return the current prefix arg as a number, or 0 if no prefix."
1182 (list (if current-prefix-arg
1183 (prefix-numeric-value current-prefix-arg)
1186 (defun gnus-article-check-hidden-text (type arg)
1187 "Return nil if hiding is necessary.
1188 Arg can be nil or a number. Nil and positive means hide, negative
1189 means show, 0 means toggle."
1193 (let ((hide (gnus-article-hidden-text-p type)))
1199 (gnus-article-show-hidden-text type))
1201 (if (eq hide 'hidden)
1202 (gnus-article-show-hidden-text type)
1205 (defun gnus-article-hidden-text-p (type)
1206 "Say whether the current buffer contains hidden text of type TYPE."
1207 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1209 (not (get-text-property pos 'invisible)))
1211 (text-property-any (1+ pos) (point-max) 'article-type type)))
1216 (defun gnus-article-show-hidden-text (type &optional hide)
1217 "Show all hidden text of type TYPE.
1218 If HIDE, hide the text instead."
1220 (let ((buffer-read-only nil)
1221 (inhibit-point-motion-hooks t)
1224 (while (setq beg (text-property-any end (point-max) 'article-type type))
1227 (text-property-not-all beg (point-max) 'article-type type)
1230 (gnus-article-hide-text beg end gnus-hidden-properties)
1231 (gnus-article-unhide-text beg end))
1235 (defconst article-time-units
1236 `((year . ,(* 365.25 24 60 60))
1237 (week . ,(* 7 24 60 60))
1238 (day . ,(* 24 60 60))
1242 "Mapping from time units to seconds.")
1244 (defun article-date-ut (&optional type highlight header)
1245 "Convert DATE date to universal time in the current article.
1246 If TYPE is `local', convert to local time; if it is `lapsed', output
1247 how much time has lapsed since DATE."
1248 (interactive (list 'ut t))
1249 (let* ((header (or header
1250 (mail-header-date gnus-current-headers)
1251 (message-fetch-field "date")
1253 (date (if (vectorp header) (mail-header-date header)
1255 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1256 (inhibit-point-motion-hooks t)
1257 bface eface newline)
1258 (when (and date (not (string= date "")))
1261 (nnheader-narrow-to-headers)
1262 (let ((buffer-read-only nil))
1263 ;; Delete any old Date headers.
1264 (if (re-search-forward date-regexp nil t)
1266 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1267 eface (get-text-property (1- (gnus-point-at-eol))
1269 (delete-region (progn (beginning-of-line) (point))
1270 (progn (end-of-line) (point)))
1271 (beginning-of-line))
1272 (goto-char (point-max))
1274 (insert (article-make-date-line date type))
1277 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1278 (put-text-property (match-beginning 1) (1+ (match-end 1))
1280 (put-text-property (match-beginning 2) (match-end 2)
1284 (insert "\n"))))))))
1286 (defun article-make-date-line (date type)
1287 "Return a DATE line of TYPE."
1288 (let ((time (condition-case ()
1292 ;; Convert to the local timezone. We have to slap a
1293 ;; `condition-case' round the calls to the timezone
1294 ;; functions since they aren't particularly resistant to
1297 (concat "Date: " (current-time-string time)))
1298 ;; Convert to Universal Time.
1301 (current-time-string
1302 (let ((e (parse-time-string date)))
1304 (apply 'encode-time e)))))
1305 ;; Get the original date from the article.
1306 ((eq type 'original)
1307 (concat "Date: " date))
1308 ;; Let the user define the format.
1310 (if (gnus-functionp gnus-article-time-format)
1311 (funcall gnus-article-time-format time)
1314 (format-time-string gnus-article-time-format time))))
1319 (format-time-string "%Y%M%DT%h%m%s" time)))
1320 ;; Do an X-Sent lapsed format.
1322 ;; If the date is seriously mangled, the timezone functions are
1323 ;; liable to bug out, so we ignore all errors.
1324 (let* ((now (current-time))
1325 (real-time (subtract-time now time))
1326 (real-sec (and real-time
1327 (+ (* (float (car real-time)) 65536)
1329 (sec (and real-time (abs real-sec)))
1339 ;; This is a bit convoluted, but basically we go
1340 ;; through the time units for years, weeks, etc,
1341 ;; and divide things to see whether that results
1342 ;; in positive answers.
1345 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1346 ;; The (remaining) seconds are too few to
1347 ;; be divided into this time unit.
1349 ;; It's big enough, so we output it.
1350 (setq sec (- sec (* num (cdr unit))))
1352 (concat (if prev ", " "") (int-to-string
1354 " " (symbol-name (car unit))
1355 (if (> num 1) "s" ""))
1357 article-time-units "")
1358 ;; If dates are odd, then it might appear like the
1359 ;; article was sent in the future.
1362 " in the future"))))))
1364 (error "Unknown conversion type: %s" type)))))
1366 (defun article-date-local (&optional highlight)
1367 "Convert the current article date to the local timezone."
1368 (interactive (list t))
1369 (article-date-ut 'local highlight))
1371 (defun article-date-original (&optional highlight)
1372 "Convert the current article date to what it was originally.
1373 This is only useful if you have used some other date conversion
1374 function and want to see what the date was before converting."
1375 (interactive (list t))
1376 (article-date-ut 'original highlight))
1378 (defun article-date-lapsed (&optional highlight)
1379 "Convert the current article date to time lapsed since it was sent."
1380 (interactive (list t))
1381 (article-date-ut 'lapsed highlight))
1383 (defun article-update-date-lapsed ()
1384 "Function to be run from a timer to update the lapsed time line."
1385 (let (deactivate-mark)
1388 (when (gnus-buffer-live-p gnus-article-buffer)
1389 (set-buffer gnus-article-buffer)
1390 (goto-char (point-min))
1391 (when (re-search-forward "^X-Sent:" nil t)
1392 (article-date-lapsed t)))))))
1394 (defun gnus-start-date-timer (&optional n)
1395 "Start a timer to update the X-Sent header in the article buffers.
1396 The numerical prefix says how frequently (in seconds) the function
1401 (gnus-stop-date-timer)
1402 (setq article-lapsed-timer
1403 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1405 (defun gnus-stop-date-timer ()
1406 "Stop the X-Sent timer."
1408 (when article-lapsed-timer
1409 (nnheader-cancel-timer article-lapsed-timer)
1410 (setq article-lapsed-timer nil)))
1412 (defun article-date-user (&optional highlight)
1413 "Convert the current article date to the user-defined format.
1414 This format is defined by the `gnus-article-time-format' variable."
1415 (interactive (list t))
1416 (article-date-ut 'user highlight))
1418 (defun article-date-iso8601 (&optional highlight)
1419 "Convert the current article date to ISO8601."
1420 (interactive (list t))
1421 (article-date-ut 'iso8601 highlight))
1423 (defun article-show-all ()
1424 "Show all hidden text in the article buffer."
1427 (let ((buffer-read-only nil))
1428 (gnus-article-unhide-text (point-min) (point-max)))))
1430 (defun article-emphasize (&optional arg)
1431 "Emphasize text according to `gnus-emphasis-alist'."
1432 (interactive (gnus-article-hidden-arg))
1433 (unless (gnus-article-check-hidden-text 'emphasis arg)
1435 (let ((alist gnus-emphasis-alist)
1436 (buffer-read-only nil)
1437 (props (append '(article-type emphasis)
1438 gnus-hidden-properties))
1439 regexp elem beg invisible visible face)
1440 (goto-char (point-min))
1441 (search-forward "\n\n" nil t)
1443 (while (setq elem (pop alist))
1445 (setq regexp (car elem)
1446 invisible (nth 1 elem)
1447 visible (nth 2 elem)
1449 (while (re-search-forward regexp nil t)
1450 (when (and (match-beginning visible) (match-beginning invisible))
1451 (gnus-article-hide-text
1452 (match-beginning invisible) (match-end invisible) props)
1453 (gnus-article-unhide-text-type
1454 (match-beginning visible) (match-end visible) 'emphasis)
1455 (gnus-put-text-property-excluding-newlines
1456 (match-beginning visible) (match-end visible) 'face face)
1457 (goto-char (match-end invisible)))))))))
1459 (defvar gnus-summary-article-menu)
1460 (defvar gnus-summary-post-menu)
1462 ;;; Saving functions.
1464 (defun gnus-article-save (save-buffer file &optional num)
1465 "Save the currently selected article."
1466 (unless gnus-save-all-headers
1467 ;; Remove headers according to `gnus-saved-headers'.
1468 (let ((gnus-visible-headers
1469 (or gnus-saved-headers gnus-visible-headers))
1470 (gnus-article-buffer save-buffer))
1472 (set-buffer save-buffer)
1473 (article-hide-headers 1 t))))
1474 (save-window-excursion
1475 (if (not gnus-default-article-saver)
1476 (error "No default saver is defined")
1477 ;; !!! Magic! The saving functions all save
1478 ;; `gnus-original-article-buffer' (or so they think), but we
1479 ;; bind that variable to our save-buffer.
1480 (set-buffer gnus-article-buffer)
1481 (let* ((gnus-save-article-buffer save-buffer)
1484 ((not gnus-prompt-before-saving) 'default)
1485 ((eq gnus-prompt-before-saving 'always) nil)
1487 (gnus-number-of-articles-to-be-saved
1488 (when (eq gnus-prompt-before-saving t)
1490 (set-buffer gnus-article-current-summary)
1491 (funcall gnus-default-article-saver filename)))))
1493 (defun gnus-read-save-file-name (prompt &optional filename
1494 function group headers variable)
1496 (funcall function group headers (symbol-value variable)))
1501 ((eq filename 'default)
1507 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1510 (if (and gnus-number-of-articles-to-be-saved
1511 (> gnus-number-of-articles-to-be-saved 1))
1512 (format "these %d articles"
1513 gnus-number-of-articles-to-be-saved)
1516 ;; Let the split methods have their say.
1518 ;; No split name was found.
1521 (concat prompt " (default "
1522 (file-name-nondirectory default-name) ") ")
1523 (file-name-directory default-name)
1525 ;; A single group name is returned.
1526 ((stringp split-name)
1528 (funcall function split-name headers
1529 (symbol-value variable)))
1531 (concat prompt " (default "
1532 (file-name-nondirectory default-name) ") ")
1533 (file-name-directory default-name)
1535 ;; A single split name was found
1536 ((= 1 (length split-name))
1537 (let* ((name (expand-file-name
1538 (car split-name) gnus-article-save-directory))
1539 (dir (cond ((file-directory-p name)
1540 (file-name-as-directory name))
1541 ((file-exists-p name) name)
1542 (t gnus-article-save-directory))))
1544 (concat prompt " (default " name ") ")
1546 ;; A list of splits was found.
1548 (setq split-name (nreverse split-name))
1550 (let ((file-name-history
1551 (nconc split-name file-name-history)))
1555 (concat prompt " (`M-p' for defaults) ")
1556 gnus-article-save-directory
1558 gnus-article-save-directory)))
1559 (car (push result file-name-history)))))))
1560 ;; Create the directory.
1561 (gnus-make-directory (file-name-directory file))
1562 ;; If we have read a directory, we append the default file name.
1563 (when (file-directory-p file)
1564 (setq file (concat (file-name-as-directory file)
1565 (file-name-nondirectory default-name))))
1566 ;; Possibly translate some characters.
1567 (nnheader-translate-file-chars file)))))
1568 (gnus-make-directory (file-name-directory result))
1569 (set variable result)))
1571 (defun gnus-article-archive-name (group)
1572 "Return the first instance of an \"Archive-name\" in the current buffer."
1573 (let ((case-fold-search t))
1574 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1575 (nnheader-concat gnus-article-save-directory
1576 (match-string 1)))))
1578 (defun gnus-article-nndoc-name (group)
1579 "If GROUP is an nndoc group, return the name of the parent group."
1580 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1581 (gnus-group-get-parameter group 'save-article-group)))
1583 (defun gnus-summary-save-in-rmail (&optional filename)
1584 "Append this article to Rmail file.
1585 Optional argument FILENAME specifies file name.
1586 Directory to save to is default to `gnus-article-save-directory'."
1587 (setq filename (gnus-read-save-file-name
1588 "Save %s in rmail file:" filename
1589 gnus-rmail-save-name gnus-newsgroup-name
1590 gnus-current-headers 'gnus-newsgroup-last-rmail))
1591 (gnus-eval-in-buffer-window gnus-save-article-buffer
1595 (rmail-output-to-rmail-file filename))))
1598 (defun gnus-summary-save-in-mail (&optional filename)
1599 "Append this article to Unix mail file.
1600 Optional argument FILENAME specifies file name.
1601 Directory to save to is default to `gnus-article-save-directory'."
1602 (setq filename (gnus-read-save-file-name
1603 "Save %s in Unix mail file:" filename
1604 gnus-mail-save-name gnus-newsgroup-name
1605 gnus-current-headers 'gnus-newsgroup-last-mail))
1606 (gnus-eval-in-buffer-window gnus-save-article-buffer
1610 (if (and (file-readable-p filename)
1611 (mail-file-babyl-p filename))
1612 (rmail-output-to-rmail-file filename t)
1613 (gnus-output-to-mail filename)))))
1616 (defun gnus-summary-save-in-file (&optional filename overwrite)
1617 "Append this article to file.
1618 Optional argument FILENAME specifies file name.
1619 Directory to save to is default to `gnus-article-save-directory'."
1620 (setq filename (gnus-read-save-file-name
1621 "Save %s in file:" filename
1622 gnus-file-save-name gnus-newsgroup-name
1623 gnus-current-headers 'gnus-newsgroup-last-file))
1624 (gnus-eval-in-buffer-window gnus-save-article-buffer
1628 (when (and overwrite
1629 (file-exists-p filename))
1630 (delete-file filename))
1631 (gnus-output-to-file filename))))
1634 (defun gnus-summary-write-to-file (&optional filename)
1635 "Write this article to a file.
1636 Optional argument FILENAME specifies file name.
1637 The directory to save in defaults to `gnus-article-save-directory'."
1638 (gnus-summary-save-in-file nil t))
1640 (defun gnus-summary-save-body-in-file (&optional filename)
1641 "Append this article body to a file.
1642 Optional argument FILENAME specifies file name.
1643 The directory to save in defaults to `gnus-article-save-directory'."
1644 (setq filename (gnus-read-save-file-name
1645 "Save %s body in file:" filename
1646 gnus-file-save-name gnus-newsgroup-name
1647 gnus-current-headers 'gnus-newsgroup-last-file))
1648 (gnus-eval-in-buffer-window gnus-save-article-buffer
1652 (goto-char (point-min))
1653 (when (search-forward "\n\n" nil t)
1654 (narrow-to-region (point) (point-max)))
1655 (gnus-output-to-file filename))))
1658 (defun gnus-summary-save-in-pipe (&optional command)
1659 "Pipe this article to subprocess."
1661 (cond ((eq command 'default)
1662 gnus-last-shell-command)
1666 "Shell command on %s: "
1667 (if (and gnus-number-of-articles-to-be-saved
1668 (> gnus-number-of-articles-to-be-saved 1))
1669 (format "these %d articles"
1670 gnus-number-of-articles-to-be-saved)
1672 gnus-last-shell-command))))
1673 (when (string-equal command "")
1674 (setq command gnus-last-shell-command))
1675 (gnus-eval-in-buffer-window gnus-article-buffer
1678 (shell-command-on-region (point-min) (point-max) command nil)))
1679 (setq gnus-last-shell-command command))
1681 ;;; Article file names when saving.
1683 (defun gnus-capitalize-newsgroup (newsgroup)
1684 "Capitalize NEWSGROUP name."
1685 (when (not (zerop (length newsgroup)))
1686 (concat (char-to-string (upcase (aref newsgroup 0)))
1687 (substring newsgroup 1))))
1689 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1690 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1691 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1692 Otherwise, it is like ~/News/news/group/num."
1695 (concat (if (gnus-use-long-file-name 'not-save)
1696 (gnus-capitalize-newsgroup newsgroup)
1697 (gnus-newsgroup-directory-form newsgroup))
1698 "/" (int-to-string (mail-header-number headers)))
1699 gnus-article-save-directory)))
1701 (string-equal (file-name-directory default)
1702 (file-name-directory last-file))
1703 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1705 (or last-file default))))
1707 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1708 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1709 If variable `gnus-use-long-file-name' is non-nil, it is
1710 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1713 (concat (if (gnus-use-long-file-name 'not-save)
1715 (gnus-newsgroup-directory-form newsgroup))
1716 "/" (int-to-string (mail-header-number headers)))
1717 gnus-article-save-directory)))
1719 (string-equal (file-name-directory default)
1720 (file-name-directory last-file))
1721 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1723 (or last-file default))))
1725 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1726 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1727 If variable `gnus-use-long-file-name' is non-nil, it is
1728 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1731 (if (gnus-use-long-file-name 'not-save)
1732 (gnus-capitalize-newsgroup newsgroup)
1733 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1734 gnus-article-save-directory)))
1736 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1737 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1738 If variable `gnus-use-long-file-name' is non-nil, it is
1739 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1742 (if (gnus-use-long-file-name 'not-save)
1744 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1745 gnus-article-save-directory)))
1752 (setq afunc (car func)
1755 gfunc (intern (format "gnus-%s" func))))
1757 (if (not (fboundp afunc))
1759 `(lambda (&optional interactive &rest args)
1760 ,(documentation afunc t)
1761 (interactive (list t))
1763 (set-buffer gnus-article-buffer)
1765 (call-interactively ',afunc)
1766 (apply ',afunc args))))))))
1767 '(article-hide-headers
1768 article-hide-boring-headers
1769 article-treat-overstrike
1770 (article-fill . gnus-article-word-wrap)
1772 article-display-x-face
1775 article-hide-signature
1776 article-remove-trailing-blank-lines
1777 article-strip-leading-blank-lines
1778 article-strip-multiple-blank-lines
1779 article-strip-leading-space
1780 article-strip-blank-lines
1781 article-strip-all-blank-lines
1783 article-date-iso8601
1784 article-date-original
1786 article-decode-mime-words
1790 article-treat-dumbquotes
1791 (article-show-all . gnus-article-show-all-headers))))
1794 ;;; Gnus article mode
1797 (put 'gnus-article-mode 'mode-class 'special)
1799 (gnus-define-keys gnus-article-mode-map
1800 " " gnus-article-goto-next-page
1801 "\177" gnus-article-goto-prev-page
1802 [delete] gnus-article-goto-prev-page
1803 "\C-c^" gnus-article-refer-article
1804 "h" gnus-article-show-summary
1805 "s" gnus-article-show-summary
1806 "\C-c\C-m" gnus-article-mail
1807 "?" gnus-article-describe-briefly
1808 gnus-mouse-2 gnus-article-push-button
1809 "\r" gnus-article-press-button
1810 "\t" gnus-article-next-button
1811 "\M-\t" gnus-article-prev-button
1812 "e" gnus-article-edit
1813 "<" beginning-of-buffer
1815 "\C-c\C-i" gnus-info-find-node
1818 "\C-d" gnus-article-read-summary-keys
1819 "\M-*" gnus-article-read-summary-keys
1820 "\M-#" gnus-article-read-summary-keys
1821 "\M-^" gnus-article-read-summary-keys
1822 "\M-g" gnus-article-read-summary-keys)
1824 (substitute-key-definition
1825 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1827 (defun gnus-article-make-menu-bar ()
1828 (gnus-turn-off-edit-menu 'article)
1829 (unless (boundp 'gnus-article-article-menu)
1831 gnus-article-article-menu gnus-article-mode-map ""
1833 ["Scroll forwards" gnus-article-goto-next-page t]
1834 ["Scroll backwards" gnus-article-goto-prev-page t]
1835 ["Show summary" gnus-article-show-summary t]
1836 ["Fetch Message-ID at point" gnus-article-refer-article t]
1837 ["Mail to address at point" gnus-article-mail t]
1838 ["Send a bug report" gnus-bug t]))
1841 gnus-article-treatment-menu gnus-article-mode-map ""
1843 ["Hide headers" gnus-article-hide-headers t]
1844 ["Hide signature" gnus-article-hide-signature t]
1845 ["Hide citation" gnus-article-hide-citation t]
1846 ["Treat overstrike" gnus-article-treat-overstrike t]
1847 ["Remove carriage return" gnus-article-remove-cr t]))
1849 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1851 (when (boundp 'gnus-summary-post-menu)
1852 (define-key gnus-article-mode-map [menu-bar post]
1853 (cons "Post" gnus-summary-post-menu)))
1855 (gnus-run-hooks 'gnus-article-menu-hook)))
1857 (defun gnus-article-mode ()
1858 "Major mode for displaying an article.
1860 All normal editing commands are switched off.
1862 The following commands are available in addition to all summary mode
1864 \\<gnus-article-mode-map>
1865 \\[gnus-article-next-page]\t Scroll the article one page forwards
1866 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1867 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1868 \\[gnus-article-show-summary]\t Display the summary buffer
1869 \\[gnus-article-mail]\t Send a reply to the address near point
1870 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1871 \\[gnus-info-find-node]\t Go to the Gnus info node"
1873 (when (gnus-visual-p 'article-menu 'menu)
1874 (gnus-article-make-menu-bar))
1875 (gnus-simplify-mode-line)
1876 (setq mode-name "Article")
1877 (setq major-mode 'gnus-article-mode)
1878 (make-local-variable 'minor-mode-alist)
1879 (unless (assq 'gnus-show-mime minor-mode-alist)
1880 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1881 (use-local-map gnus-article-mode-map)
1882 (gnus-update-format-specifications nil 'article-mode)
1883 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1884 (make-local-variable 'gnus-page-broken)
1885 (make-local-variable 'gnus-button-marker-list)
1886 (make-local-variable 'gnus-article-current-summary)
1887 (gnus-set-default-directory)
1888 (buffer-disable-undo (current-buffer))
1889 (setq buffer-read-only t)
1890 (set-syntax-table gnus-article-mode-syntax-table)
1891 (gnus-run-hooks 'gnus-article-mode-hook))
1893 (defun gnus-article-setup-buffer ()
1894 "Initialize the article buffer."
1895 (let* ((name (if gnus-single-article-buffer "*Article*"
1896 (concat "*Article " gnus-newsgroup-name "*")))
1898 (progn (string-match "\\*Article" name)
1899 (concat " *Original Article"
1900 (substring name (match-end 0))))))
1901 (setq gnus-article-buffer name)
1902 (setq gnus-original-article-buffer original)
1903 ;; This might be a variable local to the summary buffer.
1904 (unless gnus-single-article-buffer
1906 (set-buffer gnus-summary-buffer)
1907 (setq gnus-article-buffer name)
1908 (setq gnus-original-article-buffer original)
1909 (gnus-set-global-variables)))
1910 ;; Init original article buffer.
1912 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1913 (setq major-mode 'gnus-original-article-mode)
1914 (make-local-variable 'gnus-original-article))
1915 (if (get-buffer name)
1918 (buffer-disable-undo (current-buffer))
1919 (setq buffer-read-only t)
1920 (unless (eq major-mode 'gnus-article-mode)
1921 (gnus-article-mode))
1924 (set-buffer (gnus-get-buffer-create name))
1926 (make-local-variable 'gnus-summary-buffer)
1927 (current-buffer)))))
1929 ;; Set article window start at LINE, where LINE is the number of lines
1930 ;; from the head of the article.
1931 (defun gnus-article-set-window-start (&optional line)
1933 (get-buffer-window gnus-article-buffer t)
1935 (set-buffer gnus-article-buffer)
1936 (goto-char (point-min))
1939 (gnus-message 6 "Moved to bookmark")
1940 (search-forward "\n\n" nil t)
1944 ;;; @@ article filters
1947 (defun gnus-article-display-mime-message ()
1948 "Article display method for MIME message."
1949 ;; called from `gnus-original-article-buffer'.
1950 (let ((default-mime-charset (save-excursion
1951 (set-buffer gnus-summary-buffer)
1952 default-mime-charset)))
1953 (mime-display-message mime-message-structure
1954 gnus-article-buffer nil gnus-article-mode-map))
1955 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
1956 (make-local-variable 'mime-button-mother-dispatcher)
1957 (setq mime-button-mother-dispatcher
1958 (function gnus-article-push-button))
1959 (run-hooks 'gnus-mime-article-prepare-hook))
1961 (defun gnus-article-display-traditional-message ()
1962 "Article display method for traditional message."
1963 (set-buffer gnus-article-buffer)
1964 (let (buffer-read-only)
1966 (insert-buffer-substring gnus-original-article-buffer)))
1968 (defun gnus-article-display-message-with-encoded-word ()
1969 "Article display method for message with encoded-words."
1970 (let ((charset (save-excursion
1971 (set-buffer gnus-summary-buffer)
1972 default-mime-charset)))
1973 (gnus-article-display-traditional-message)
1974 (let (buffer-read-only)
1975 (eword-decode-header charset)
1976 (goto-char (point-min))
1977 (if (search-forward "\n\n" nil t)
1978 (decode-mime-charset-region (match-end 0) (point-max) charset)))
1979 (mime-maybe-hide-echo-buffer))
1980 (gnus-run-hooks 'gnus-mime-article-prepare-hook))
1982 (defun gnus-article-prepare (article &optional all-headers header)
1983 "Prepare ARTICLE in article mode buffer.
1984 ARTICLE should either be an article number or a Message-ID.
1985 If ARTICLE is an id, HEADER should be the article headers.
1986 If ALL-HEADERS is non-nil, no headers are hidden."
1988 ;; Make sure we start in a summary buffer.
1989 (unless (eq major-mode 'gnus-summary-mode)
1990 (set-buffer gnus-summary-buffer))
1991 (setq gnus-summary-buffer (current-buffer))
1992 (let* ((gnus-article (if header (mail-header-number header) article))
1993 (summary-buffer (current-buffer))
1994 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
1995 (group gnus-newsgroup-name)
1998 (gnus-article-setup-buffer)
1999 (set-buffer gnus-original-article-buffer)
2000 ;; Deactivate active regions.
2001 (when (and (boundp 'transient-mark-mode)
2002 transient-mark-mode)
2003 (setq mark-active nil))
2004 (if (not (setq result (let ((buffer-read-only nil))
2005 (gnus-request-article-this-buffer
2007 ;; There is no such article.
2009 (when (and (numberp article)
2010 (not (memq article gnus-newsgroup-sparse)))
2011 (setq gnus-article-current
2012 (cons gnus-newsgroup-name article))
2013 (set-buffer gnus-summary-buffer)
2014 (setq gnus-current-article article)
2015 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2017 (gnus-summary-set-agent-mark article)
2018 (message "Message marked for downloading"))
2019 (gnus-summary-mark-article article gnus-canceled-mark)
2020 (unless (memq article gnus-newsgroup-sparse)
2022 "No such article (may have expired or been canceled)")))))
2023 (if (or (eq result 'pseudo)
2024 (eq result 'nneething))
2027 (set-buffer summary-buffer)
2028 (push article gnus-newsgroup-history)
2029 (setq gnus-last-article gnus-current-article
2030 gnus-current-article 0
2031 gnus-current-headers nil
2032 gnus-article-current nil)
2033 (if (eq result 'nneething)
2034 (gnus-configure-windows 'summary)
2035 (gnus-configure-windows 'article))
2036 (gnus-set-global-variables))
2037 (gnus-set-mode-line 'article))
2038 ;; The result from the `request' was an actual article -
2039 ;; or at least some text that is now displayed in the
2041 (when (and (numberp article)
2042 (not (eq article gnus-current-article)))
2043 ;; Seems like a new article has been selected.
2044 ;; `gnus-current-article' must be an article number.
2046 (set-buffer summary-buffer)
2047 (push article gnus-newsgroup-history)
2048 (setq gnus-last-article gnus-current-article
2049 gnus-current-article article
2050 gnus-current-headers
2051 (gnus-summary-article-header gnus-current-article)
2052 gnus-article-current
2053 (cons gnus-newsgroup-name gnus-current-article))
2054 (unless (vectorp gnus-current-headers)
2055 (setq gnus-current-headers nil))
2056 (gnus-summary-goto-subject gnus-current-article)
2057 (when (gnus-summary-show-thread)
2058 ;; If the summary buffer really was folded, the
2059 ;; previous goto may not actually have gone to
2060 ;; the right article, but the thread root instead.
2062 (gnus-summary-goto-subject gnus-current-article))
2063 (gnus-run-hooks 'gnus-mark-article-hook)
2064 (gnus-set-mode-line 'summary)
2065 (when (gnus-visual-p 'article-highlight 'highlight)
2066 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2067 ;; Set the global newsgroup variables here.
2068 ;; Suggested by Jim Sisolak
2069 ;; <sisolak@trans4.neep.wisc.edu>.
2070 (gnus-set-global-variables)
2071 (setq gnus-have-all-headers
2072 (or all-headers gnus-show-all-headers))))
2073 (when (or (numberp article)
2079 (if (or (not gnus-strict-mime)
2080 (mime-fetch-field "MIME-Version"))
2081 gnus-article-display-method-for-mime
2082 gnus-article-display-method-for-encoded-word))
2083 gnus-article-display-method-for-traditional)))
2084 ;; Hooks for getting information from the article.
2085 ;; This hook must be called before being narrowed.
2086 (gnus-run-hooks 'gnus-tmp-internal-hook)
2087 (gnus-run-hooks 'gnus-article-prepare-hook)
2090 ;; Associate this article with the current summary buffer.
2091 (setq gnus-article-current-summary summary-buffer)
2092 ;; Perform the article display hooks.
2093 (gnus-run-hooks 'gnus-article-display-hook))
2095 (goto-char (point-min))
2096 (setq gnus-page-broken
2097 (when gnus-break-pages
2098 (gnus-narrow-to-page)
2100 (gnus-set-mode-line 'article)
2101 (gnus-configure-windows 'article)
2102 (goto-char (point-min))
2103 (search-forward "\n\n" nil t)
2104 (set-window-point (get-buffer-window (current-buffer)) (point))
2107 (defun gnus-article-wash-status ()
2108 "Return a string which display status of article washing."
2110 (set-buffer gnus-article-buffer)
2111 (let ((cite (gnus-article-hidden-text-p 'cite))
2112 (headers (gnus-article-hidden-text-p 'headers))
2113 (boring (gnus-article-hidden-text-p 'boring-headers))
2114 (pgp (gnus-article-hidden-text-p 'pgp))
2115 (pem (gnus-article-hidden-text-p 'pem))
2116 (signature (gnus-article-hidden-text-p 'signature))
2117 (overstrike (gnus-article-hidden-text-p 'overstrike))
2118 (emphasis (gnus-article-hidden-text-p 'emphasis))
2119 (mime gnus-show-mime))
2120 (format "%c%c%c%c%c%c%c"
2122 (if (or headers boring) ?h ? )
2123 (if (or pgp pem) ?p ? )
2124 (if signature ?s ? )
2125 (if overstrike ?o ? )
2127 (if emphasis ?e ? )))))
2129 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2131 (defun gnus-article-maybe-hide-headers ()
2132 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2133 Provided for backwards compatibility."
2134 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2136 (gnus-article-hide-headers)))
2140 (defun gnus-output-to-file (file-name)
2141 "Append the current article to a file named FILE-NAME."
2142 (let ((artbuf (current-buffer)))
2144 (insert-buffer-substring artbuf)
2145 ;; Append newline at end of the buffer as separator, and then
2147 (goto-char (point-max))
2149 (append-to-file (point-min) (point-max) file-name)
2152 (defun gnus-narrow-to-page (&optional arg)
2153 "Narrow the article buffer to a page.
2154 If given a numerical ARG, move forward ARG pages."
2156 (setq arg (if arg (prefix-numeric-value arg) 0))
2158 (set-buffer gnus-article-buffer)
2159 (goto-char (point-min))
2161 ;; Remove any old next/prev buttons.
2162 (when (gnus-visual-p 'page-marker)
2163 (let ((buffer-read-only nil))
2164 (gnus-remove-text-with-property 'gnus-prev)
2165 (gnus-remove-text-with-property 'gnus-next)))
2168 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2170 (re-search-forward page-delimiter nil 'move arg)))
2171 (goto-char (match-end 0)))
2174 (if (re-search-forward page-delimiter nil 'move)
2177 (when (and (gnus-visual-p 'page-marker)
2178 (not (= (point-min) 1)))
2180 (goto-char (point-min))
2181 (gnus-insert-prev-page-button)))
2182 (when (and (gnus-visual-p 'page-marker)
2183 (< (+ (point-max) 2) (buffer-size)))
2185 (goto-char (point-max))
2186 (gnus-insert-next-page-button)))))
2188 ;; Article mode commands
2190 (defun gnus-article-goto-next-page ()
2191 "Show the next page of the article."
2193 (when (gnus-article-next-page)
2194 (goto-char (point-min))
2195 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2197 (defun gnus-article-goto-prev-page ()
2198 "Show the next page of the article."
2200 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2201 (gnus-article-prev-page nil)))
2203 (defun gnus-article-next-page (&optional lines)
2204 "Show the next page of the current article.
2205 If end of article, return non-nil. Otherwise return nil.
2206 Argument LINES specifies lines to be scrolled up."
2208 (move-to-window-line -1)
2211 (and (pos-visible-in-window-p) ;Not continuation line.
2213 ;; Nothing in this page.
2214 (if (or (not gnus-page-broken)
2217 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2219 (gnus-narrow-to-page 1) ;Go to next page.
2221 ;; More in this page.
2222 (let ((scroll-in-place nil))
2226 ;; Long lines may cause an end-of-buffer error.
2227 (goto-char (point-max)))))
2228 (move-to-window-line 0)
2231 (defun gnus-article-prev-page (&optional lines)
2232 "Show previous page of current article.
2233 Argument LINES specifies lines to be scrolled down."
2235 (move-to-window-line 0)
2236 (if (and gnus-page-broken
2238 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2240 (gnus-narrow-to-page -1) ;Go to previous page.
2241 (goto-char (point-max))
2243 (let ((scroll-in-place nil))
2247 (beginning-of-buffer
2248 (goto-char (point-min))))
2249 (move-to-window-line 0)))))
2251 (defun gnus-article-refer-article ()
2252 "Read article specified by message-id around point."
2254 (let ((point (point)))
2255 (search-forward ">" nil t) ;Move point to end of "<....>".
2256 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2257 (let ((message-id (match-string 1)))
2259 (set-buffer gnus-summary-buffer)
2260 (gnus-summary-refer-article message-id))
2262 (error "No references around point"))))
2264 (defun gnus-article-show-summary ()
2265 "Reconfigure windows to show summary buffer."
2267 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2268 (error "There is no summary buffer for this article buffer")
2269 (gnus-article-set-globals)
2270 (gnus-configure-windows 'article)
2271 (gnus-summary-goto-subject gnus-current-article)
2272 (gnus-summary-position-point)))
2274 (defun gnus-article-describe-briefly ()
2275 "Describe article mode commands briefly."
2278 (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")))
2280 (defun gnus-article-summary-command ()
2281 "Execute the last keystroke in the summary buffer."
2283 (let ((obuf (current-buffer))
2284 (owin (current-window-configuration))
2286 (switch-to-buffer gnus-article-current-summary 'norecord)
2287 (setq func (lookup-key (current-local-map) (this-command-keys)))
2288 (call-interactively func)
2290 (set-window-configuration owin)
2291 (set-window-point (get-buffer-window (current-buffer)) (point))))
2293 (defun gnus-article-summary-command-nosave ()
2294 "Execute the last keystroke in the summary buffer."
2297 (pop-to-buffer gnus-article-current-summary 'norecord)
2298 (setq func (lookup-key (current-local-map) (this-command-keys)))
2299 (call-interactively func)))
2301 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2302 "Read a summary buffer key sequence and execute it from the article buffer."
2305 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2306 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2307 "=" "^" "\M-^" "|"))
2313 '("n" "Gn" "p" "Gp"))
2316 (set-buffer gnus-article-current-summary)
2317 (let (gnus-pick-mode)
2318 (push (or key last-command-event) unread-command-events)
2319 (setq keys (read-key-sequence nil))))
2322 (if (or (member keys nosaves)
2323 (member keys nosave-but-article)
2324 (member keys nosave-in-article))
2326 (save-window-excursion
2327 (pop-to-buffer gnus-article-current-summary 'norecord)
2328 ;; We disable the pick minor mode commands.
2329 (let (gnus-pick-mode)
2330 (setq func (lookup-key (current-local-map) keys))))
2333 (unless (member keys nosave-in-article)
2334 (set-buffer gnus-article-current-summary))
2335 (call-interactively func)
2336 (setq new-sum-point (point)))
2337 (when (member keys nosave-but-article)
2338 (pop-to-buffer gnus-article-buffer 'norecord)))
2339 ;; These commands should restore window configuration.
2340 (let ((obuf (current-buffer))
2341 (owin (current-window-configuration))
2343 (summary gnus-article-current-summary)
2344 func in-buffer selected)
2345 (if not-restore-window
2346 (pop-to-buffer summary 'norecord)
2347 (switch-to-buffer summary 'norecord))
2348 (setq in-buffer (current-buffer))
2349 ;; We disable the pick minor mode commands.
2350 (if (setq func (let (gnus-pick-mode)
2351 (lookup-key (current-local-map) keys)))
2353 (call-interactively func)
2354 (setq new-sum-point (point)))
2356 (when (eq in-buffer (current-buffer))
2357 (setq selected (gnus-summary-select-article))
2359 (unless not-restore-window
2360 (set-window-configuration owin))
2361 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2362 (set-window-point (get-buffer-window (current-buffer))
2364 (let ((win (get-buffer-window gnus-article-current-summary)))
2366 (set-window-point win new-sum-point))))))))
2368 (defun gnus-article-hide (&optional arg force)
2369 "Hide all the gruft in the current article.
2370 This means that PGP stuff, signatures, cited text and (some)
2371 headers will be hidden.
2372 If given a prefix, show the hidden text instead."
2373 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2374 (gnus-article-hide-headers arg)
2375 (gnus-article-hide-pgp arg)
2376 (gnus-article-hide-citation-maybe arg force)
2377 (gnus-article-hide-signature arg))
2379 (defun gnus-article-maybe-highlight ()
2380 "Do some article highlighting if article highlighting is requested."
2381 (when (gnus-visual-p 'article-highlight 'highlight)
2382 (gnus-article-highlight-some)))
2384 (defun gnus-check-group-server ()
2385 ;; Make sure the connection to the server is alive.
2386 (unless (gnus-server-opened
2387 (gnus-find-method-for-group gnus-newsgroup-name))
2388 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2389 (gnus-request-group gnus-newsgroup-name t)))
2391 (defun gnus-request-article-this-buffer (article group)
2392 "Get an article and insert it into this buffer."
2393 (let (do-update-line sparse-header)
2397 (gnus-kill-all-overlays)
2398 (setq group (or group gnus-newsgroup-name))
2400 ;; Using `gnus-request-article' directly will insert the article into
2401 ;; `nntp-server-buffer' - so we'll save some time by not having to
2402 ;; copy it from the server buffer into the article buffer.
2404 ;; We only request an article by message-id when we do not have the
2405 ;; headers for it, so we'll have to get those.
2406 (when (stringp article)
2407 (let ((gnus-override-method gnus-refer-article-method))
2408 (gnus-read-header article)))
2410 ;; If the article number is negative, that means that this article
2411 ;; doesn't belong in this newsgroup (possibly), so we find its
2412 ;; message-id and request it by id instead of number.
2413 (when (and (numberp article)
2415 (get-buffer gnus-summary-buffer)
2416 (gnus-buffer-exists-p gnus-summary-buffer))
2418 (set-buffer gnus-summary-buffer)
2419 (let ((header (gnus-summary-article-header article)))
2422 ((memq article gnus-newsgroup-sparse)
2423 ;; This is a sparse gap article.
2424 (setq do-update-line article)
2425 (setq article (mail-header-id header))
2426 (let ((gnus-override-method gnus-refer-article-method))
2427 (setq sparse-header (gnus-read-header article)))
2428 (setq gnus-newsgroup-sparse
2429 (delq article gnus-newsgroup-sparse)))
2431 ;; It's a real article.
2432 (setq article (mail-header-id header)))
2434 ;; It is an extracted pseudo-article.
2435 (setq article 'pseudo)
2436 (gnus-request-pseudo-article header))))
2438 (let ((method (gnus-find-method-for-group
2439 gnus-newsgroup-name)))
2440 (when (and (eq (car method) 'nneething)
2443 (file-name-as-directory
2444 (or (cadr (assq 'nneething-address method))
2446 (mail-header-subject header))))
2447 (when (file-directory-p dir)
2448 (setq article 'nneething)
2449 (gnus-group-enter-directory dir))))))))
2452 ;; Refuse to select canceled articles.
2453 ((and (numberp article)
2455 (get-buffer gnus-summary-buffer)
2456 (gnus-buffer-exists-p gnus-summary-buffer)
2457 (eq (cdr (save-excursion
2458 (set-buffer gnus-summary-buffer)
2459 (assq article gnus-newsgroup-reads)))
2460 gnus-canceled-mark))
2462 ;; Check the backlog.
2463 ((and gnus-keep-backlog
2464 (gnus-backlog-request-article group article (current-buffer)))
2466 ;; Check asynchronous pre-fetch.
2467 ((gnus-async-request-fetched-article group article (current-buffer))
2468 (gnus-async-prefetch-next group article gnus-summary-buffer)
2469 (when (and (numberp article) gnus-keep-backlog)
2470 (gnus-backlog-enter-article group article (current-buffer)))
2473 ((and gnus-use-cache
2475 (gnus-cache-request-article article group))
2477 ;; Get the article and put into the article buffer.
2478 ((or (stringp article) (numberp article))
2479 (let ((gnus-override-method
2480 (and (stringp article) gnus-refer-article-method))
2481 (buffer-read-only nil))
2483 (gnus-kill-all-overlays)
2484 (gnus-check-group-server)
2485 (when (gnus-request-article article group (current-buffer))
2486 (when (numberp article)
2487 (gnus-async-prefetch-next group article gnus-summary-buffer)
2488 (when gnus-keep-backlog
2489 (gnus-backlog-enter-article
2490 group article (current-buffer))))
2495 ;; Associate this article with the current summary buffer.
2496 (setq gnus-article-current-summary gnus-summary-buffer)
2498 ;; Take the article from the original article buffer
2499 ;; and place it in the buffer it's supposed to be in.
2500 (when (and (get-buffer gnus-article-buffer)
2501 (equal (buffer-name (current-buffer))
2502 (buffer-name (get-buffer gnus-article-buffer))))
2504 (if (get-buffer gnus-original-article-buffer)
2505 (set-buffer gnus-original-article-buffer)
2506 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2507 (buffer-disable-undo (current-buffer))
2508 (setq major-mode 'gnus-original-article-mode)
2509 (setq buffer-read-only t))
2510 (let (buffer-read-only)
2512 (insert-buffer-substring gnus-article-buffer))
2513 (setq gnus-original-article (cons group article))))
2516 (run-hooks 'gnus-article-decode-hook)
2518 ;; Update sparse articles.
2519 (when (and do-update-line
2520 (or (numberp article)
2522 (let ((buf (current-buffer)))
2523 (set-buffer gnus-summary-buffer)
2524 (gnus-summary-update-article do-update-line sparse-header)
2525 (gnus-summary-goto-subject do-update-line nil t)
2526 (set-window-point (get-buffer-window (current-buffer) t)
2528 (set-buffer buf))))))
2534 (defcustom gnus-article-edit-mode-hook nil
2535 "Hook run in article edit mode buffers."
2536 :group 'gnus-article-various
2539 (defvar gnus-article-edit-done-function nil)
2541 (defvar gnus-article-edit-mode-map nil)
2543 (unless gnus-article-edit-mode-map
2544 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2546 (gnus-define-keys gnus-article-edit-mode-map
2547 "\C-c\C-c" gnus-article-edit-done
2548 "\C-c\C-k" gnus-article-edit-exit)
2550 (gnus-define-keys (gnus-article-edit-wash-map
2551 "\C-c\C-w" gnus-article-edit-mode-map)
2552 "f" gnus-article-edit-full-stops))
2554 (defun gnus-article-edit-mode ()
2555 "Major mode for editing articles.
2556 This is an extended text-mode.
2558 \\{gnus-article-edit-mode-map}"
2560 (setq major-mode 'gnus-article-edit-mode)
2561 (setq mode-name "Article Edit")
2562 (use-local-map gnus-article-edit-mode-map)
2563 (make-local-variable 'gnus-article-edit-done-function)
2564 (make-local-variable 'gnus-prev-winconf)
2565 (setq buffer-read-only nil)
2566 (buffer-enable-undo)
2568 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2570 (defun gnus-article-edit (&optional force)
2571 "Edit the current article.
2572 This will have permanent effect only in mail groups.
2573 If FORCE is non-nil, allow editing of articles even in read-only
2576 (when (and (not force)
2577 (gnus-group-read-only-p))
2578 (error "The current newsgroup does not support article editing"))
2579 (gnus-article-date-original)
2580 (gnus-article-edit-article
2581 `(lambda (no-highlight)
2582 (gnus-summary-edit-article-done
2583 ,(or (mail-header-references gnus-current-headers) "")
2584 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2586 (defun gnus-article-edit-article (exit-func)
2587 "Start editing the contents of the current article buffer."
2588 (let ((winconf (current-window-configuration)))
2589 (set-buffer gnus-article-buffer)
2590 (gnus-article-edit-mode)
2591 (gnus-article-delete-text-of-type 'annotation)
2592 (gnus-set-text-properties (point-min) (point-max) nil)
2593 (gnus-configure-windows 'edit-article)
2594 (setq gnus-article-edit-done-function exit-func)
2595 (setq gnus-prev-winconf winconf)
2596 (gnus-message 6 "C-c C-c to end edits")))
2598 (defun gnus-article-edit-done (&optional arg)
2599 "Update the article edits and exit."
2604 (goto-char (point-min))
2605 (when (search-forward "\n\n" nil 1)
2606 (let ((lines (count-lines (point) (point-max)))
2607 (length (- (point-max) (point)))
2608 (case-fold-search t)
2609 (body (copy-marker (point))))
2610 (goto-char (point-min))
2611 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2612 (delete-region (match-beginning 1) (match-end 1))
2613 (insert (number-to-string length)))
2614 (goto-char (point-min))
2615 (when (re-search-forward
2616 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2617 (delete-region (match-beginning 1) (match-end 1))
2618 (insert (number-to-string length)))
2619 (goto-char (point-min))
2620 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2621 (delete-region (match-beginning 1) (match-end 1))
2622 (insert (number-to-string lines)))))))
2623 (let ((func gnus-article-edit-done-function)
2624 (buf (current-buffer))
2625 (start (window-start)))
2626 (gnus-article-edit-exit)
2629 (let ((buffer-read-only nil))
2630 (funcall func arg)))
2632 (set-window-start (get-buffer-window buf) start)
2633 (set-window-point (get-buffer-window buf) (point))))
2635 (defun gnus-article-edit-exit ()
2636 "Exit the article editing without updating."
2638 ;; We remove all text props from the article buffer.
2639 (let ((buf (format "%s" (buffer-string)))
2640 (curbuf (current-buffer))
2642 (window-start (window-start)))
2645 (let ((winconf gnus-prev-winconf))
2647 ;; The cache and backlog have to be flushed somewhat.
2648 (when gnus-use-cache
2649 (gnus-cache-update-article
2650 (car gnus-article-current) (cdr gnus-article-current)))
2651 (when gnus-keep-backlog
2652 (gnus-backlog-remove-article
2653 (car gnus-article-current) (cdr gnus-article-current)))
2654 ;; Flush original article as well.
2656 (when (get-buffer gnus-original-article-buffer)
2657 (set-buffer gnus-original-article-buffer)
2658 (setq gnus-original-article nil)))
2659 (set-window-configuration winconf)
2660 ;; Tippy-toe some to make sure that point remains where it was.
2661 (let ((buf (current-buffer)))
2663 (set-window-start (get-buffer-window (current-buffer)) window-start)
2665 (set-buffer buf)))))
2667 (defun gnus-article-edit-full-stops ()
2668 "Interactively repair spacing at end of sentences."
2671 (goto-char (point-min))
2672 (search-forward-regexp "^$" nil t)
2673 (let ((case-fold-search nil))
2674 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2677 ;;; Article highlights
2680 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2682 ;;; Internal Variables:
2684 (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\\)"
2685 "Regular expression that matches URLs."
2686 :group 'gnus-article-buttons
2689 (defcustom gnus-button-alist
2690 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2691 gnus-button-message-id 2)
2692 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2693 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2695 gnus-button-fetch-group 4)
2696 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2697 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2698 t gnus-button-message-id 3)
2699 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2700 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2701 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2702 ;; This is how URLs _should_ be embedded in text...
2703 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2705 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2706 "*Alist of regexps matching buttons in article bodies.
2708 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2709 REGEXP: is the string matching text around the button,
2710 BUTTON: is the number of the regexp grouping actually matching the button,
2711 FORM: is a lisp expression which must eval to true for the button to
2713 CALLBACK: is the function to call when the user push this button, and each
2714 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2716 CALLBACK can also be a variable, in that case the value of that
2717 variable it the real callback function."
2718 :group 'gnus-article-buttons
2719 :type '(repeat (list regexp
2720 (integer :tag "Button")
2722 (function :tag "Callback")
2725 (integer :tag "Regexp group")))))
2727 (defcustom gnus-header-button-alist
2728 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2729 0 t gnus-button-message-id 0)
2730 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2731 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2732 0 t gnus-button-mailto 0)
2733 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2734 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2735 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2736 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2737 gnus-button-message-id 3))
2738 "*Alist of headers and regexps to match buttons in article heads.
2740 This alist is very similar to `gnus-button-alist', except that each
2741 alist has an additional HEADER element first in each entry:
2743 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2745 HEADER is a regexp to match a header. For a fuller explanation, see
2746 `gnus-button-alist'."
2747 :group 'gnus-article-buttons
2748 :group 'gnus-article-headers
2749 :type '(repeat (list (regexp :tag "Header")
2751 (integer :tag "Button")
2753 (function :tag "Callback")
2756 (integer :tag "Regexp group")))))
2758 (defvar gnus-button-regexp nil)
2759 (defvar gnus-button-marker-list nil)
2760 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2762 (defvar gnus-button-last nil)
2763 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2767 (defun gnus-article-push-button (event)
2768 "Check text under the mouse pointer for a callback function.
2769 If the text under the mouse pointer has a `gnus-callback' property,
2770 call it with the value of the `gnus-data' text property."
2772 (set-buffer (window-buffer (posn-window (event-start event))))
2773 (let* ((pos (posn-point (event-start event)))
2774 (data (get-text-property pos 'gnus-data))
2775 (fun (get-text-property pos 'gnus-callback)))
2778 (funcall fun data))))
2780 (defun gnus-article-press-button ()
2781 "Check text at point for a callback function.
2782 If the text at point has a `gnus-callback' property,
2783 call it with the value of the `gnus-data' text property."
2785 (let* ((data (get-text-property (point) 'gnus-data))
2786 (fun (get-text-property (point) 'gnus-callback)))
2788 (funcall fun data))))
2790 (defun gnus-article-prev-button (n)
2791 "Move point to N buttons backward.
2792 If N is negative, move forward instead."
2794 (gnus-article-next-button (- n)))
2796 (defun gnus-article-next-button (n)
2797 "Move point to N buttons forward.
2798 If N is negative, move backward instead."
2800 (let ((function (if (< n 0) 'previous-single-property-change
2801 'next-single-property-change))
2802 (inhibit-point-motion-hooks t)
2804 (limit (if (< n 0) (point-min) (point-max))))
2806 (while (and (not (= limit (point)))
2808 ;; Skip past the current button.
2809 (when (get-text-property (point) 'gnus-callback)
2810 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2811 ;; Go to the next (or previous) button.
2812 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2813 ;; Put point at the start of the button.
2814 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2815 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2816 ;; Skip past intangible buttons.
2817 (when (get-text-property (point) 'intangible)
2821 (gnus-message 5 "No more buttons"))
2824 (defun gnus-article-highlight (&optional force)
2825 "Highlight current article.
2826 This function calls `gnus-article-highlight-headers',
2827 `gnus-article-highlight-citation',
2828 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2829 do the highlighting. See the documentation for those functions."
2830 (interactive (list 'force))
2831 (gnus-article-highlight-headers)
2832 (gnus-article-highlight-citation force)
2833 (gnus-article-highlight-signature)
2834 (gnus-article-add-buttons force)
2835 (gnus-article-add-buttons-to-head))
2837 (defun gnus-article-highlight-some (&optional force)
2838 "Highlight current article.
2839 This function calls `gnus-article-highlight-headers',
2840 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2841 do the highlighting. See the documentation for those functions."
2842 (interactive (list 'force))
2843 (gnus-article-highlight-headers)
2844 (gnus-article-highlight-signature)
2845 (gnus-article-add-buttons))
2847 (defun gnus-article-highlight-headers ()
2848 "Highlight article headers as specified by `gnus-header-face-alist'."
2851 (set-buffer gnus-article-buffer)
2853 (let ((alist gnus-header-face-alist)
2854 (buffer-read-only nil)
2855 (case-fold-search t)
2856 (inhibit-point-motion-hooks t)
2857 entry regexp header-face field-face from hpoints fpoints)
2858 (message-narrow-to-head)
2859 (while (setq entry (pop alist))
2860 (goto-char (point-min))
2861 (setq regexp (concat "^\\("
2862 (if (string-equal "" (nth 0 entry))
2866 header-face (nth 1 entry)
2867 field-face (nth 2 entry))
2868 (while (and (re-search-forward regexp nil t)
2872 (unless (search-forward ":" nil t)
2874 (when (and header-face
2875 (not (memq (point) hpoints)))
2876 (push (point) hpoints)
2877 (gnus-put-text-property from (point) 'face header-face))
2878 (when (and field-face
2879 (not (memq (setq from (point)) fpoints)))
2881 (if (re-search-forward "^[^ \t]" nil t)
2883 (goto-char (point-max)))
2884 (gnus-put-text-property from (point) 'face field-face))))))))
2886 (defun gnus-article-highlight-signature ()
2887 "Highlight the signature in an article.
2888 It does this by highlighting everything after
2889 `gnus-signature-separator' using `gnus-signature-face'."
2892 (set-buffer gnus-article-buffer)
2893 (let ((buffer-read-only nil)
2894 (inhibit-point-motion-hooks t))
2896 (when (and gnus-signature-face
2897 (gnus-article-narrow-to-signature))
2898 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2899 'face gnus-signature-face)
2901 (gnus-article-search-signature)
2902 (let ((start (match-beginning 0))
2903 (end (set-marker (make-marker) (1+ (match-end 0)))))
2904 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2907 (defun gnus-button-in-region-p (b e prop)
2908 "Say whether PROP exists in the region."
2909 (text-property-not-all b e prop nil))
2911 (defun gnus-article-add-buttons (&optional force)
2912 "Find external references in the article and make buttons of them.
2913 \"External references\" are things like Message-IDs and URLs, as
2914 specified by `gnus-button-alist'."
2915 (interactive (list 'force))
2917 (set-buffer gnus-article-buffer)
2918 (let ((buffer-read-only nil)
2919 (inhibit-point-motion-hooks t)
2920 (case-fold-search t)
2921 (alist gnus-button-alist)
2923 ;; Remove all old markers.
2925 (while (setq marker (pop gnus-button-marker-list))
2927 (when (setq entry (gnus-button-entry))
2928 (put-text-property (match-beginning (nth 1 entry))
2929 (match-end (nth 1 entry))
2930 'gnus-callback nil))
2931 (set-marker marker nil)))
2932 ;; We skip the headers.
2933 (goto-char (point-min))
2934 (unless (search-forward "\n\n" nil t)
2935 (goto-char (point-max)))
2937 (while (setq entry (pop alist))
2938 (setq regexp (car entry))
2940 (while (re-search-forward regexp nil t)
2941 (let* ((start (and entry (match-beginning (nth 1 entry))))
2942 (end (and entry (match-end (nth 1 entry))))
2943 (from (match-beginning 0)))
2944 (when (and (or (eq t (nth 2 entry))
2945 (eval (nth 2 entry)))
2946 (not (gnus-button-in-region-p
2947 start end 'gnus-callback)))
2948 ;; That optional form returned non-nil, so we add the
2950 (gnus-article-add-button
2951 start end 'gnus-button-push
2952 (car (push (set-marker (make-marker) from)
2953 gnus-button-marker-list))))))))))
2955 ;; Add buttons to the head of an article.
2956 (defun gnus-article-add-buttons-to-head ()
2957 "Add buttons to the head of the article."
2960 (set-buffer gnus-article-buffer)
2961 (let ((buffer-read-only nil)
2962 (inhibit-point-motion-hooks t)
2963 (case-fold-search t)
2964 (alist gnus-header-button-alist)
2966 (nnheader-narrow-to-headers)
2968 ;; Each alist entry.
2969 (setq entry (car alist)
2971 (goto-char (point-min))
2972 (while (re-search-forward (car entry) nil t)
2973 ;; Each header matching the entry.
2974 (setq beg (match-beginning 0))
2975 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2976 (match-beginning 0))
2979 (while (re-search-forward (nth 1 entry) end t)
2980 ;; Each match within a header.
2981 (let* ((entry (cdr entry))
2982 (start (match-beginning (nth 1 entry)))
2983 (end (match-end (nth 1 entry)))
2984 (form (nth 2 entry)))
2985 (goto-char (match-end 0))
2987 (gnus-article-add-button
2988 start end (nth 3 entry)
2989 (buffer-substring (match-beginning (nth 4 entry))
2990 (match-end (nth 4 entry)))))))
2994 ;;; External functions:
2996 (defun gnus-article-add-button (from to fun &optional data)
2997 "Create a button between FROM and TO with callback FUN and data DATA."
2998 (when gnus-article-button-face
2999 (gnus-overlay-put (gnus-make-overlay from to)
3000 'face gnus-article-button-face))
3001 (gnus-add-text-properties
3003 (nconc (and gnus-article-mouse-face
3004 (list gnus-mouse-face-prop gnus-article-mouse-face))
3005 (list 'gnus-callback fun)
3006 (and data (list 'gnus-data data)))))
3008 ;;; Internal functions:
3010 (defun gnus-article-set-globals ()
3012 (set-buffer gnus-summary-buffer)
3013 (gnus-set-global-variables)))
3015 (defun gnus-signature-toggle (end)
3017 (set-buffer gnus-article-buffer)
3018 (let ((buffer-read-only nil)
3019 (inhibit-point-motion-hooks t))
3020 (if (get-text-property end 'invisible)
3021 (gnus-article-unhide-text end (point-max))
3022 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3024 (defun gnus-button-entry ()
3025 ;; Return the first entry in `gnus-button-alist' matching this place.
3026 (let ((alist gnus-button-alist)
3029 (setq entry (pop alist))
3030 (if (looking-at (car entry))
3035 (defun gnus-button-push (marker)
3036 ;; Push button starting at MARKER.
3038 (set-buffer gnus-article-buffer)
3040 (let* ((entry (gnus-button-entry))
3041 (inhibit-point-motion-hooks t)
3043 (args (mapcar (lambda (group)
3044 (let ((string (match-string group)))
3045 (gnus-set-text-properties
3046 0 (length string) nil string)
3053 (fboundp (symbol-value fun)))
3054 (apply (symbol-value fun) args))
3056 (gnus-message 1 "You must define `%S' to use this button"
3057 (cons fun args)))))))
3059 (defun gnus-button-message-id (message-id)
3062 (set-buffer gnus-summary-buffer)
3063 (gnus-summary-refer-article message-id)))
3065 (defun gnus-button-fetch-group (address)
3066 "Fetch GROUP specified by ADDRESS."
3067 (if (not (string-match "[:/]" address))
3068 ;; This is just a simple group url.
3069 (gnus-group-read-ephemeral-group address gnus-select-method)
3070 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3072 (error "Can't parse %s" address)
3073 (gnus-group-read-ephemeral-group
3074 (match-string 4 address)
3075 `(nntp ,(match-string 1 address)
3076 (nntp-address ,(match-string 1 address))
3077 (nntp-port-number ,(if (match-end 3)
3078 (match-string 3 address)
3081 (defun gnus-url-parse-query-string (query &optional downcase)
3082 (let (retval pairs cur key val)
3083 (setq pairs (split-string query "&"))
3085 (setq cur (car pairs)
3087 (if (not (string-match "=" cur))
3089 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3090 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3092 (setq key (downcase key)))
3093 (setq cur (assoc key retval))
3095 (setcdr cur (cons val (cdr cur)))
3096 (setq retval (cons (list key val) retval)))))
3099 (defun gnus-url-unhex (x)
3106 (defun gnus-url-unhex-string (str &optional allow-newlines)
3107 "Remove %XXX embedded spaces, etc in a url.
3108 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3109 decoding of carriage returns and line feeds in the string, which is normally
3110 forbidden in URL encoding."
3111 (setq str (or str ""))
3113 (case-fold-search t))
3114 (while (string-match "%[0-9a-f][0-9a-f]" str)
3115 (let* ((start (match-beginning 0))
3116 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3118 (gnus-url-unhex (elt str (+ start 2))))))
3120 tmp (substring str 0 start)
3123 (char-to-string code))
3124 ((or (= code ?\n) (= code ?\r))
3126 (t (char-to-string code))))
3127 str (substring str (match-end 0)))))
3128 (setq tmp (concat tmp str))
3131 (defun gnus-url-mailto (url)
3132 ;; Send mail to someone
3133 (when (string-match "mailto:/*\\(.*\\)" url)
3134 (setq url (substring url (match-beginning 1) nil)))
3135 (let (to args subject func)
3136 (if (string-match (regexp-quote "?") url)
3137 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3138 args (gnus-url-parse-query-string
3139 (substring url (match-end 0) nil) t))
3140 (setq to (gnus-url-unhex-string url)))
3141 (setq args (cons (list "to" to) args)
3142 subject (cdr-safe (assoc "subject" args)))
3143 (gnus-setup-message 'reply
3146 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3149 (message-position-on-field (caar args)))
3150 (insert (mapconcat 'identity (cdar args) ", "))
3151 (setq args (cdr args)))
3154 (message-goto-subject)))))
3156 (defun gnus-button-mailto (address)
3158 (set-buffer (gnus-copy-article-buffer))
3159 (gnus-setup-message 'reply
3160 (message-reply address)))
3162 (defun gnus-button-reply (address)
3163 ;; Reply to ADDRESS.
3164 (gnus-setup-message 'reply
3165 (message-reply address)))
3167 (defun gnus-button-url (address)
3169 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3170 (if (listp browse-url-browser-function)
3171 (browse-url address)
3172 (funcall browse-url-browser-function address)))
3174 (defun gnus-button-embedded-url (address)
3176 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3177 (if (listp browse-url-browser-function)
3178 (browse-url (gnus-strip-whitespace address))
3179 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3181 ;;; Next/prev buttons in the article buffer.
3183 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3184 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3186 (defvar gnus-prev-page-map nil)
3187 (unless gnus-prev-page-map
3188 (setq gnus-prev-page-map (make-sparse-keymap))
3189 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3190 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3192 (defun gnus-insert-prev-page-button ()
3193 (let ((buffer-read-only nil))
3195 gnus-prev-page-line-format nil
3196 `(gnus-prev t local-map ,gnus-prev-page-map
3197 gnus-callback gnus-article-button-prev-page
3198 gnus-type annotation))))
3200 (defvar gnus-next-page-map nil)
3201 (unless gnus-next-page-map
3202 (setq gnus-next-page-map (make-keymap))
3203 (suppress-keymap gnus-prev-page-map)
3204 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3205 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3207 (defun gnus-button-next-page ()
3208 "Go to the next page."
3210 (let ((win (selected-window)))
3211 (select-window (get-buffer-window gnus-article-buffer t))
3212 (gnus-article-next-page)
3213 (select-window win)))
3215 (defun gnus-button-prev-page ()
3216 "Go to the prev page."
3218 (let ((win (selected-window)))
3219 (select-window (get-buffer-window gnus-article-buffer t))
3220 (gnus-article-prev-page)
3221 (select-window win)))
3223 (defun gnus-insert-next-page-button ()
3224 (let ((buffer-read-only nil))
3225 (gnus-eval-format gnus-next-page-line-format nil
3227 t local-map ,gnus-next-page-map
3228 gnus-callback gnus-article-button-next-page
3229 gnus-type annotation))))
3231 (defun gnus-article-button-next-page (arg)
3232 "Go to the next page."
3234 (let ((win (selected-window)))
3235 (select-window (get-buffer-window gnus-article-buffer t))
3236 (gnus-article-next-page)
3237 (select-window win)))
3239 (defun gnus-article-button-prev-page (arg)
3240 "Go to the prev page."
3242 (let ((win (selected-window)))
3243 (select-window (get-buffer-window gnus-article-buffer t))
3244 (gnus-article-prev-page)
3245 (select-window win)))
3251 (defun gnus-article-header-presentation-method (entity situation)
3252 (mime-insert-decoded-header entity)
3255 (set-alist 'mime-header-presentation-method-alist
3256 'gnus-original-article-mode
3257 #'gnus-article-header-presentation-method)
3259 (defun gnus-mime-preview-quitting-method ()
3261 (gnus-article-show-summary)
3262 (mime-preview-kill-buffer)
3263 (delete-other-windows)
3264 (gnus-article-show-summary)
3265 (gnus-summary-select-article nil t)
3268 (set-alist 'mime-preview-quitting-method-alist
3269 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
3271 (defun gnus-following-method (buf)
3274 (message-yank-original)
3276 (goto-char (point-min))
3279 (set-alist 'mime-preview-following-method-alist
3280 'gnus-original-article-mode #'gnus-following-method)
3290 (run-hooks 'gnus-art-load-hook)
3292 ;;; gnus-art.el ends here