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 (let ((tz (car (current-time-zone))))
1298 (format "Date: %s %s%04d" (current-time-string time)
1299 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1300 ;; Convert to Universal Time.
1303 (current-time-string
1304 (let* ((e (parse-time-string date))
1305 (tm (apply 'encode-time e))
1307 (ls (- (cadr tm) (car (current-time-zone)))))
1308 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1309 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1312 ;; Get the original date from the article.
1313 ((eq type 'original)
1314 (concat "Date: " (if (string-match "\n+$" date)
1315 (substring date 0 (match-beginning 0))
1317 ;; Let the user define the format.
1319 (if (gnus-functionp gnus-article-time-format)
1320 (funcall gnus-article-time-format time)
1323 (format-time-string gnus-article-time-format time))))
1328 (format-time-string "%Y%M%DT%h%m%s" time)))
1329 ;; Do an X-Sent lapsed format.
1331 ;; If the date is seriously mangled, the timezone functions are
1332 ;; liable to bug out, so we ignore all errors.
1333 (let* ((now (current-time))
1334 (real-time (subtract-time now time))
1335 (real-sec (and real-time
1336 (+ (* (float (car real-time)) 65536)
1338 (sec (and real-time (abs real-sec)))
1348 ;; This is a bit convoluted, but basically we go
1349 ;; through the time units for years, weeks, etc,
1350 ;; and divide things to see whether that results
1351 ;; in positive answers.
1354 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1355 ;; The (remaining) seconds are too few to
1356 ;; be divided into this time unit.
1358 ;; It's big enough, so we output it.
1359 (setq sec (- sec (* num (cdr unit))))
1361 (concat (if prev ", " "") (int-to-string
1363 " " (symbol-name (car unit))
1364 (if (> num 1) "s" ""))
1366 article-time-units "")
1367 ;; If dates are odd, then it might appear like the
1368 ;; article was sent in the future.
1371 " in the future"))))))
1373 (error "Unknown conversion type: %s" type)))))
1375 (defun article-date-local (&optional highlight)
1376 "Convert the current article date to the local timezone."
1377 (interactive (list t))
1378 (article-date-ut 'local highlight))
1380 (defun article-date-original (&optional highlight)
1381 "Convert the current article date to what it was originally.
1382 This is only useful if you have used some other date conversion
1383 function and want to see what the date was before converting."
1384 (interactive (list t))
1385 (article-date-ut 'original highlight))
1387 (defun article-date-lapsed (&optional highlight)
1388 "Convert the current article date to time lapsed since it was sent."
1389 (interactive (list t))
1390 (article-date-ut 'lapsed highlight))
1392 (defun article-update-date-lapsed ()
1393 "Function to be run from a timer to update the lapsed time line."
1394 (let (deactivate-mark)
1397 (when (gnus-buffer-live-p gnus-article-buffer)
1398 (set-buffer gnus-article-buffer)
1399 (goto-char (point-min))
1400 (when (re-search-forward "^X-Sent:" nil t)
1401 (article-date-lapsed t)))))))
1403 (defun gnus-start-date-timer (&optional n)
1404 "Start a timer to update the X-Sent header in the article buffers.
1405 The numerical prefix says how frequently (in seconds) the function
1410 (gnus-stop-date-timer)
1411 (setq article-lapsed-timer
1412 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1414 (defun gnus-stop-date-timer ()
1415 "Stop the X-Sent timer."
1417 (when article-lapsed-timer
1418 (nnheader-cancel-timer article-lapsed-timer)
1419 (setq article-lapsed-timer nil)))
1421 (defun article-date-user (&optional highlight)
1422 "Convert the current article date to the user-defined format.
1423 This format is defined by the `gnus-article-time-format' variable."
1424 (interactive (list t))
1425 (article-date-ut 'user highlight))
1427 (defun article-date-iso8601 (&optional highlight)
1428 "Convert the current article date to ISO8601."
1429 (interactive (list t))
1430 (article-date-ut 'iso8601 highlight))
1432 (defun article-show-all ()
1433 "Show all hidden text in the article buffer."
1436 (let ((buffer-read-only nil))
1437 (gnus-article-unhide-text (point-min) (point-max)))))
1439 (defun article-emphasize (&optional arg)
1440 "Emphasize text according to `gnus-emphasis-alist'."
1441 (interactive (gnus-article-hidden-arg))
1442 (unless (gnus-article-check-hidden-text 'emphasis arg)
1444 (let ((alist gnus-emphasis-alist)
1445 (buffer-read-only nil)
1446 (props (append '(article-type emphasis)
1447 gnus-hidden-properties))
1448 regexp elem beg invisible visible face)
1449 (goto-char (point-min))
1450 (search-forward "\n\n" nil t)
1452 (while (setq elem (pop alist))
1454 (setq regexp (car elem)
1455 invisible (nth 1 elem)
1456 visible (nth 2 elem)
1458 (while (re-search-forward regexp nil t)
1459 (when (and (match-beginning visible) (match-beginning invisible))
1460 (gnus-article-hide-text
1461 (match-beginning invisible) (match-end invisible) props)
1462 (gnus-article-unhide-text-type
1463 (match-beginning visible) (match-end visible) 'emphasis)
1464 (gnus-put-text-property-excluding-newlines
1465 (match-beginning visible) (match-end visible) 'face face)
1466 (goto-char (match-end invisible)))))))))
1468 (defvar gnus-summary-article-menu)
1469 (defvar gnus-summary-post-menu)
1471 ;;; Saving functions.
1473 (defun gnus-article-save (save-buffer file &optional num)
1474 "Save the currently selected article."
1475 (unless gnus-save-all-headers
1476 ;; Remove headers according to `gnus-saved-headers'.
1477 (let ((gnus-visible-headers
1478 (or gnus-saved-headers gnus-visible-headers))
1479 (gnus-article-buffer save-buffer))
1481 (set-buffer save-buffer)
1482 (article-hide-headers 1 t))))
1483 (save-window-excursion
1484 (if (not gnus-default-article-saver)
1485 (error "No default saver is defined")
1486 ;; !!! Magic! The saving functions all save
1487 ;; `gnus-original-article-buffer' (or so they think), but we
1488 ;; bind that variable to our save-buffer.
1489 (set-buffer gnus-article-buffer)
1490 (let* ((gnus-save-article-buffer save-buffer)
1493 ((not gnus-prompt-before-saving) 'default)
1494 ((eq gnus-prompt-before-saving 'always) nil)
1496 (gnus-number-of-articles-to-be-saved
1497 (when (eq gnus-prompt-before-saving t)
1499 (set-buffer gnus-article-current-summary)
1500 (funcall gnus-default-article-saver filename)))))
1502 (defun gnus-read-save-file-name (prompt &optional filename
1503 function group headers variable)
1505 (funcall function group headers (symbol-value variable)))
1510 ((eq filename 'default)
1516 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1519 (if (and gnus-number-of-articles-to-be-saved
1520 (> gnus-number-of-articles-to-be-saved 1))
1521 (format "these %d articles"
1522 gnus-number-of-articles-to-be-saved)
1525 ;; Let the split methods have their say.
1527 ;; No split name was found.
1530 (concat prompt " (default "
1531 (file-name-nondirectory default-name) ") ")
1532 (file-name-directory default-name)
1534 ;; A single group name is returned.
1535 ((stringp split-name)
1537 (funcall function split-name headers
1538 (symbol-value variable)))
1540 (concat prompt " (default "
1541 (file-name-nondirectory default-name) ") ")
1542 (file-name-directory default-name)
1544 ;; A single split name was found
1545 ((= 1 (length split-name))
1546 (let* ((name (expand-file-name
1547 (car split-name) gnus-article-save-directory))
1548 (dir (cond ((file-directory-p name)
1549 (file-name-as-directory name))
1550 ((file-exists-p name) name)
1551 (t gnus-article-save-directory))))
1553 (concat prompt " (default " name ") ")
1555 ;; A list of splits was found.
1557 (setq split-name (nreverse split-name))
1559 (let ((file-name-history
1560 (nconc split-name file-name-history)))
1564 (concat prompt " (`M-p' for defaults) ")
1565 gnus-article-save-directory
1567 gnus-article-save-directory)))
1568 (car (push result file-name-history)))))))
1569 ;; Create the directory.
1570 (gnus-make-directory (file-name-directory file))
1571 ;; If we have read a directory, we append the default file name.
1572 (when (file-directory-p file)
1573 (setq file (concat (file-name-as-directory file)
1574 (file-name-nondirectory default-name))))
1575 ;; Possibly translate some characters.
1576 (nnheader-translate-file-chars file)))))
1577 (gnus-make-directory (file-name-directory result))
1578 (set variable result)))
1580 (defun gnus-article-archive-name (group)
1581 "Return the first instance of an \"Archive-name\" in the current buffer."
1582 (let ((case-fold-search t))
1583 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1584 (nnheader-concat gnus-article-save-directory
1585 (match-string 1)))))
1587 (defun gnus-article-nndoc-name (group)
1588 "If GROUP is an nndoc group, return the name of the parent group."
1589 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1590 (gnus-group-get-parameter group 'save-article-group)))
1592 (defun gnus-summary-save-in-rmail (&optional filename)
1593 "Append this article to Rmail file.
1594 Optional argument FILENAME specifies file name.
1595 Directory to save to is default to `gnus-article-save-directory'."
1596 (setq filename (gnus-read-save-file-name
1597 "Save %s in rmail file:" filename
1598 gnus-rmail-save-name gnus-newsgroup-name
1599 gnus-current-headers 'gnus-newsgroup-last-rmail))
1600 (gnus-eval-in-buffer-window gnus-save-article-buffer
1604 (rmail-output-to-rmail-file filename))))
1607 (defun gnus-summary-save-in-mail (&optional filename)
1608 "Append this article to Unix mail file.
1609 Optional argument FILENAME specifies file name.
1610 Directory to save to is default to `gnus-article-save-directory'."
1611 (setq filename (gnus-read-save-file-name
1612 "Save %s in Unix mail file:" filename
1613 gnus-mail-save-name gnus-newsgroup-name
1614 gnus-current-headers 'gnus-newsgroup-last-mail))
1615 (gnus-eval-in-buffer-window gnus-save-article-buffer
1619 (if (and (file-readable-p filename)
1620 (mail-file-babyl-p filename))
1621 (rmail-output-to-rmail-file filename t)
1622 (gnus-output-to-mail filename)))))
1625 (defun gnus-summary-save-in-file (&optional filename overwrite)
1626 "Append this article to file.
1627 Optional argument FILENAME specifies file name.
1628 Directory to save to is default to `gnus-article-save-directory'."
1629 (setq filename (gnus-read-save-file-name
1630 "Save %s in file:" filename
1631 gnus-file-save-name gnus-newsgroup-name
1632 gnus-current-headers 'gnus-newsgroup-last-file))
1633 (gnus-eval-in-buffer-window gnus-save-article-buffer
1637 (when (and overwrite
1638 (file-exists-p filename))
1639 (delete-file filename))
1640 (gnus-output-to-file filename))))
1643 (defun gnus-summary-write-to-file (&optional filename)
1644 "Write this article to a file.
1645 Optional argument FILENAME specifies file name.
1646 The directory to save in defaults to `gnus-article-save-directory'."
1647 (gnus-summary-save-in-file nil t))
1649 (defun gnus-summary-save-body-in-file (&optional filename)
1650 "Append this article body to a file.
1651 Optional argument FILENAME specifies file name.
1652 The directory to save in defaults to `gnus-article-save-directory'."
1653 (setq filename (gnus-read-save-file-name
1654 "Save %s body in file:" filename
1655 gnus-file-save-name gnus-newsgroup-name
1656 gnus-current-headers 'gnus-newsgroup-last-file))
1657 (gnus-eval-in-buffer-window gnus-save-article-buffer
1661 (goto-char (point-min))
1662 (when (search-forward "\n\n" nil t)
1663 (narrow-to-region (point) (point-max)))
1664 (gnus-output-to-file filename))))
1667 (defun gnus-summary-save-in-pipe (&optional command)
1668 "Pipe this article to subprocess."
1670 (cond ((eq command 'default)
1671 gnus-last-shell-command)
1675 "Shell command on %s: "
1676 (if (and gnus-number-of-articles-to-be-saved
1677 (> gnus-number-of-articles-to-be-saved 1))
1678 (format "these %d articles"
1679 gnus-number-of-articles-to-be-saved)
1681 gnus-last-shell-command))))
1682 (when (string-equal command "")
1683 (setq command gnus-last-shell-command))
1684 (gnus-eval-in-buffer-window gnus-article-buffer
1687 (shell-command-on-region (point-min) (point-max) command nil)))
1688 (setq gnus-last-shell-command command))
1690 ;;; Article file names when saving.
1692 (defun gnus-capitalize-newsgroup (newsgroup)
1693 "Capitalize NEWSGROUP name."
1694 (when (not (zerop (length newsgroup)))
1695 (concat (char-to-string (upcase (aref newsgroup 0)))
1696 (substring newsgroup 1))))
1698 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1699 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1700 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1701 Otherwise, it is like ~/News/news/group/num."
1704 (concat (if (gnus-use-long-file-name 'not-save)
1705 (gnus-capitalize-newsgroup newsgroup)
1706 (gnus-newsgroup-directory-form newsgroup))
1707 "/" (int-to-string (mail-header-number headers)))
1708 gnus-article-save-directory)))
1710 (string-equal (file-name-directory default)
1711 (file-name-directory last-file))
1712 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1714 (or last-file default))))
1716 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1717 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1718 If variable `gnus-use-long-file-name' is non-nil, it is
1719 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1722 (concat (if (gnus-use-long-file-name 'not-save)
1724 (gnus-newsgroup-directory-form newsgroup))
1725 "/" (int-to-string (mail-header-number headers)))
1726 gnus-article-save-directory)))
1728 (string-equal (file-name-directory default)
1729 (file-name-directory last-file))
1730 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1732 (or last-file default))))
1734 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1735 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1736 If variable `gnus-use-long-file-name' is non-nil, it is
1737 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1740 (if (gnus-use-long-file-name 'not-save)
1741 (gnus-capitalize-newsgroup newsgroup)
1742 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1743 gnus-article-save-directory)))
1745 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1746 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1747 If variable `gnus-use-long-file-name' is non-nil, it is
1748 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1751 (if (gnus-use-long-file-name 'not-save)
1753 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1754 gnus-article-save-directory)))
1761 (setq afunc (car func)
1764 gfunc (intern (format "gnus-%s" func))))
1766 (if (not (fboundp afunc))
1768 `(lambda (&optional interactive &rest args)
1769 ,(documentation afunc t)
1770 (interactive (list t))
1772 (set-buffer gnus-article-buffer)
1774 (call-interactively ',afunc)
1775 (apply ',afunc args))))))))
1776 '(article-hide-headers
1777 article-hide-boring-headers
1778 article-treat-overstrike
1779 (article-fill . gnus-article-word-wrap)
1781 article-display-x-face
1784 article-hide-signature
1785 article-remove-trailing-blank-lines
1786 article-strip-leading-blank-lines
1787 article-strip-multiple-blank-lines
1788 article-strip-leading-space
1789 article-strip-blank-lines
1790 article-strip-all-blank-lines
1792 article-date-iso8601
1793 article-date-original
1798 article-treat-dumbquotes
1799 (article-show-all . gnus-article-show-all-headers))))
1802 ;;; Gnus article mode
1805 (put 'gnus-article-mode 'mode-class 'special)
1807 (gnus-define-keys gnus-article-mode-map
1808 " " gnus-article-goto-next-page
1809 "\177" gnus-article-goto-prev-page
1810 [delete] gnus-article-goto-prev-page
1811 "\C-c^" gnus-article-refer-article
1812 "h" gnus-article-show-summary
1813 "s" gnus-article-show-summary
1814 "\C-c\C-m" gnus-article-mail
1815 "?" gnus-article-describe-briefly
1816 gnus-mouse-2 gnus-article-push-button
1817 "\r" gnus-article-press-button
1818 "\t" gnus-article-next-button
1819 "\M-\t" gnus-article-prev-button
1820 "e" gnus-article-edit
1821 "<" beginning-of-buffer
1823 "\C-c\C-i" gnus-info-find-node
1826 "\C-d" gnus-article-read-summary-keys
1827 "\M-*" gnus-article-read-summary-keys
1828 "\M-#" gnus-article-read-summary-keys
1829 "\M-^" gnus-article-read-summary-keys
1830 "\M-g" gnus-article-read-summary-keys)
1832 (substitute-key-definition
1833 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1835 (defun gnus-article-make-menu-bar ()
1836 (gnus-turn-off-edit-menu 'article)
1837 (unless (boundp 'gnus-article-article-menu)
1839 gnus-article-article-menu gnus-article-mode-map ""
1841 ["Scroll forwards" gnus-article-goto-next-page t]
1842 ["Scroll backwards" gnus-article-goto-prev-page t]
1843 ["Show summary" gnus-article-show-summary t]
1844 ["Fetch Message-ID at point" gnus-article-refer-article t]
1845 ["Mail to address at point" gnus-article-mail t]
1846 ["Send a bug report" gnus-bug t]))
1849 gnus-article-treatment-menu gnus-article-mode-map ""
1851 ["Hide headers" gnus-article-hide-headers t]
1852 ["Hide signature" gnus-article-hide-signature t]
1853 ["Hide citation" gnus-article-hide-citation t]
1854 ["Treat overstrike" gnus-article-treat-overstrike t]
1855 ["Remove carriage return" gnus-article-remove-cr t]))
1857 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1859 (when (boundp 'gnus-summary-post-menu)
1860 (define-key gnus-article-mode-map [menu-bar post]
1861 (cons "Post" gnus-summary-post-menu)))
1863 (gnus-run-hooks 'gnus-article-menu-hook)))
1865 (defun gnus-article-mode ()
1866 "Major mode for displaying an article.
1868 All normal editing commands are switched off.
1870 The following commands are available in addition to all summary mode
1872 \\<gnus-article-mode-map>
1873 \\[gnus-article-next-page]\t Scroll the article one page forwards
1874 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1875 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1876 \\[gnus-article-show-summary]\t Display the summary buffer
1877 \\[gnus-article-mail]\t Send a reply to the address near point
1878 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1879 \\[gnus-info-find-node]\t Go to the Gnus info node"
1881 (when (gnus-visual-p 'article-menu 'menu)
1882 (gnus-article-make-menu-bar))
1883 (gnus-simplify-mode-line)
1884 (setq mode-name "Article")
1885 (setq major-mode 'gnus-article-mode)
1886 (make-local-variable 'minor-mode-alist)
1887 (unless (assq 'gnus-show-mime minor-mode-alist)
1888 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
1889 (use-local-map gnus-article-mode-map)
1890 (gnus-update-format-specifications nil 'article-mode)
1891 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1892 (make-local-variable 'gnus-page-broken)
1893 (make-local-variable 'gnus-button-marker-list)
1894 (make-local-variable 'gnus-article-current-summary)
1895 (gnus-set-default-directory)
1896 (buffer-disable-undo (current-buffer))
1897 (setq buffer-read-only t)
1898 (set-syntax-table gnus-article-mode-syntax-table)
1899 (gnus-run-hooks 'gnus-article-mode-hook))
1901 (defun gnus-article-setup-buffer ()
1902 "Initialize the article buffer."
1903 (let* ((name (if gnus-single-article-buffer "*Article*"
1904 (concat "*Article " gnus-newsgroup-name "*")))
1906 (progn (string-match "\\*Article" name)
1907 (concat " *Original Article"
1908 (substring name (match-end 0))))))
1909 (setq gnus-article-buffer name)
1910 (setq gnus-original-article-buffer original)
1911 ;; This might be a variable local to the summary buffer.
1912 (unless gnus-single-article-buffer
1914 (set-buffer gnus-summary-buffer)
1915 (setq gnus-article-buffer name)
1916 (setq gnus-original-article-buffer original)
1917 (gnus-set-global-variables)))
1918 ;; Init original article buffer.
1920 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1921 (setq major-mode 'gnus-original-article-mode)
1922 (make-local-variable 'gnus-original-article))
1923 (if (get-buffer name)
1926 (buffer-disable-undo (current-buffer))
1927 (setq buffer-read-only t)
1928 (unless (eq major-mode 'gnus-article-mode)
1929 (gnus-article-mode))
1932 (set-buffer (gnus-get-buffer-create name))
1934 (make-local-variable 'gnus-summary-buffer)
1935 (current-buffer)))))
1937 ;; Set article window start at LINE, where LINE is the number of lines
1938 ;; from the head of the article.
1939 (defun gnus-article-set-window-start (&optional line)
1941 (get-buffer-window gnus-article-buffer t)
1943 (set-buffer gnus-article-buffer)
1944 (goto-char (point-min))
1947 (gnus-message 6 "Moved to bookmark")
1948 (search-forward "\n\n" nil t)
1952 ;;; @@ article filters
1955 (defun gnus-article-display-mime-message ()
1956 "Article display method for MIME message."
1957 ;; called from `gnus-original-article-buffer'.
1958 (let ((default-mime-charset (save-excursion
1959 (set-buffer gnus-summary-buffer)
1960 default-mime-charset)))
1961 (mime-display-message mime-message-structure
1962 gnus-article-buffer nil gnus-article-mode-map))
1963 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
1964 (make-local-variable 'mime-button-mother-dispatcher)
1965 (setq mime-button-mother-dispatcher
1966 (function gnus-article-push-button))
1967 (run-hooks 'gnus-mime-article-prepare-hook))
1969 (defun gnus-article-display-traditional-message ()
1970 "Article display method for traditional message."
1971 (set-buffer gnus-article-buffer)
1972 (let (buffer-read-only)
1974 (insert-buffer-substring gnus-original-article-buffer)))
1976 (defun gnus-article-display-message-with-encoded-word ()
1977 "Article display method for message with encoded-words."
1978 (let ((charset (save-excursion
1979 (set-buffer gnus-summary-buffer)
1980 default-mime-charset)))
1981 (gnus-article-display-traditional-message)
1982 (let (buffer-read-only)
1983 (eword-decode-header charset)
1984 (goto-char (point-min))
1985 (if (search-forward "\n\n" nil t)
1986 (decode-mime-charset-region (match-end 0) (point-max) charset)))
1987 (mime-maybe-hide-echo-buffer))
1988 (gnus-run-hooks 'gnus-mime-article-prepare-hook))
1990 (defun gnus-article-prepare (article &optional all-headers header)
1991 "Prepare ARTICLE in article mode buffer.
1992 ARTICLE should either be an article number or a Message-ID.
1993 If ARTICLE is an id, HEADER should be the article headers.
1994 If ALL-HEADERS is non-nil, no headers are hidden."
1996 ;; Make sure we start in a summary buffer.
1997 (unless (eq major-mode 'gnus-summary-mode)
1998 (set-buffer gnus-summary-buffer))
1999 (setq gnus-summary-buffer (current-buffer))
2000 (let* ((gnus-article (if header (mail-header-number header) article))
2001 (summary-buffer (current-buffer))
2002 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2003 (group gnus-newsgroup-name)
2006 (gnus-article-setup-buffer)
2007 (set-buffer gnus-original-article-buffer)
2008 ;; Deactivate active regions.
2009 (when (and (boundp 'transient-mark-mode)
2010 transient-mark-mode)
2011 (setq mark-active nil))
2012 (if (not (setq result (let ((buffer-read-only nil))
2013 (gnus-request-article-this-buffer
2015 ;; There is no such article.
2017 (when (and (numberp article)
2018 (not (memq article gnus-newsgroup-sparse)))
2019 (setq gnus-article-current
2020 (cons gnus-newsgroup-name article))
2021 (set-buffer gnus-summary-buffer)
2022 (setq gnus-current-article article)
2023 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2025 (gnus-summary-set-agent-mark article)
2026 (message "Message marked for downloading"))
2027 (gnus-summary-mark-article article gnus-canceled-mark)
2028 (unless (memq article gnus-newsgroup-sparse)
2030 "No such article (may have expired or been canceled)")))))
2031 (if (or (eq result 'pseudo)
2032 (eq result 'nneething))
2035 (set-buffer summary-buffer)
2036 (push article gnus-newsgroup-history)
2037 (setq gnus-last-article gnus-current-article
2038 gnus-current-article 0
2039 gnus-current-headers nil
2040 gnus-article-current nil)
2041 (if (eq result 'nneething)
2042 (gnus-configure-windows 'summary)
2043 (gnus-configure-windows 'article))
2044 (gnus-set-global-variables))
2045 (gnus-set-mode-line 'article))
2046 ;; The result from the `request' was an actual article -
2047 ;; or at least some text that is now displayed in the
2049 (when (and (numberp article)
2050 (not (eq article gnus-current-article)))
2051 ;; Seems like a new article has been selected.
2052 ;; `gnus-current-article' must be an article number.
2054 (set-buffer summary-buffer)
2055 (push article gnus-newsgroup-history)
2056 (setq gnus-last-article gnus-current-article
2057 gnus-current-article article
2058 gnus-current-headers
2059 (gnus-summary-article-header gnus-current-article)
2060 gnus-article-current
2061 (cons gnus-newsgroup-name gnus-current-article))
2062 (unless (vectorp gnus-current-headers)
2063 (setq gnus-current-headers nil))
2064 (gnus-summary-goto-subject gnus-current-article)
2065 (when (gnus-summary-show-thread)
2066 ;; If the summary buffer really was folded, the
2067 ;; previous goto may not actually have gone to
2068 ;; the right article, but the thread root instead.
2070 (gnus-summary-goto-subject gnus-current-article))
2071 (gnus-run-hooks 'gnus-mark-article-hook)
2072 (gnus-set-mode-line 'summary)
2073 (when (gnus-visual-p 'article-highlight 'highlight)
2074 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2075 ;; Set the global newsgroup variables here.
2076 ;; Suggested by Jim Sisolak
2077 ;; <sisolak@trans4.neep.wisc.edu>.
2078 (gnus-set-global-variables)
2079 (setq gnus-have-all-headers
2080 (or all-headers gnus-show-all-headers))))
2081 (when (or (numberp article)
2087 (if (or (not gnus-strict-mime)
2088 (mime-fetch-field "MIME-Version"))
2089 gnus-article-display-method-for-mime
2090 gnus-article-display-method-for-encoded-word))
2091 gnus-article-display-method-for-traditional)))
2092 ;; Hooks for getting information from the article.
2093 ;; This hook must be called before being narrowed.
2094 (gnus-run-hooks 'gnus-tmp-internal-hook)
2095 (gnus-run-hooks 'gnus-article-prepare-hook)
2098 ;; Associate this article with the current summary buffer.
2099 (setq gnus-article-current-summary summary-buffer)
2100 ;; Perform the article display hooks.
2101 (gnus-run-hooks 'gnus-article-display-hook))
2103 (goto-char (point-min))
2104 (setq gnus-page-broken
2105 (when gnus-break-pages
2106 (gnus-narrow-to-page)
2108 (gnus-set-mode-line 'article)
2109 (gnus-configure-windows 'article)
2110 (goto-char (point-min))
2111 (search-forward "\n\n" nil t)
2112 (set-window-point (get-buffer-window (current-buffer)) (point))
2115 (defun gnus-article-wash-status ()
2116 "Return a string which display status of article washing."
2118 (set-buffer gnus-article-buffer)
2119 (let ((cite (gnus-article-hidden-text-p 'cite))
2120 (headers (gnus-article-hidden-text-p 'headers))
2121 (boring (gnus-article-hidden-text-p 'boring-headers))
2122 (pgp (gnus-article-hidden-text-p 'pgp))
2123 (pem (gnus-article-hidden-text-p 'pem))
2124 (signature (gnus-article-hidden-text-p 'signature))
2125 (overstrike (gnus-article-hidden-text-p 'overstrike))
2126 (emphasis (gnus-article-hidden-text-p 'emphasis))
2127 (mime gnus-show-mime))
2128 (format "%c%c%c%c%c%c%c"
2130 (if (or headers boring) ?h ? )
2131 (if (or pgp pem) ?p ? )
2132 (if signature ?s ? )
2133 (if overstrike ?o ? )
2135 (if emphasis ?e ? )))))
2137 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2139 (defun gnus-article-maybe-hide-headers ()
2140 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2141 Provided for backwards compatibility."
2142 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2144 (gnus-article-hide-headers)))
2148 (defun gnus-output-to-file (file-name)
2149 "Append the current article to a file named FILE-NAME."
2150 (let ((artbuf (current-buffer)))
2152 (insert-buffer-substring artbuf)
2153 ;; Append newline at end of the buffer as separator, and then
2155 (goto-char (point-max))
2157 (append-to-file (point-min) (point-max) file-name)
2160 (defun gnus-narrow-to-page (&optional arg)
2161 "Narrow the article buffer to a page.
2162 If given a numerical ARG, move forward ARG pages."
2164 (setq arg (if arg (prefix-numeric-value arg) 0))
2166 (set-buffer gnus-article-buffer)
2167 (goto-char (point-min))
2169 ;; Remove any old next/prev buttons.
2170 (when (gnus-visual-p 'page-marker)
2171 (let ((buffer-read-only nil))
2172 (gnus-remove-text-with-property 'gnus-prev)
2173 (gnus-remove-text-with-property 'gnus-next)))
2176 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2178 (re-search-forward page-delimiter nil 'move arg)))
2179 (goto-char (match-end 0)))
2182 (if (re-search-forward page-delimiter nil 'move)
2185 (when (and (gnus-visual-p 'page-marker)
2186 (not (= (point-min) 1)))
2188 (goto-char (point-min))
2189 (gnus-insert-prev-page-button)))
2190 (when (and (gnus-visual-p 'page-marker)
2191 (< (+ (point-max) 2) (buffer-size)))
2193 (goto-char (point-max))
2194 (gnus-insert-next-page-button)))))
2196 ;; Article mode commands
2198 (defun gnus-article-goto-next-page ()
2199 "Show the next page of the article."
2201 (when (gnus-article-next-page)
2202 (goto-char (point-min))
2203 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2205 (defun gnus-article-goto-prev-page ()
2206 "Show the next page of the article."
2208 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2209 (gnus-article-prev-page nil)))
2211 (defun gnus-article-next-page (&optional lines)
2212 "Show the next page of the current article.
2213 If end of article, return non-nil. Otherwise return nil.
2214 Argument LINES specifies lines to be scrolled up."
2216 (move-to-window-line -1)
2219 (and (pos-visible-in-window-p) ;Not continuation line.
2221 ;; Nothing in this page.
2222 (if (or (not gnus-page-broken)
2225 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2227 (gnus-narrow-to-page 1) ;Go to next page.
2229 ;; More in this page.
2230 (let ((scroll-in-place nil))
2234 ;; Long lines may cause an end-of-buffer error.
2235 (goto-char (point-max)))))
2236 (move-to-window-line 0)
2239 (defun gnus-article-prev-page (&optional lines)
2240 "Show previous page of current article.
2241 Argument LINES specifies lines to be scrolled down."
2243 (move-to-window-line 0)
2244 (if (and gnus-page-broken
2246 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2248 (gnus-narrow-to-page -1) ;Go to previous page.
2249 (goto-char (point-max))
2251 (let ((scroll-in-place nil))
2255 (beginning-of-buffer
2256 (goto-char (point-min))))
2257 (move-to-window-line 0)))))
2259 (defun gnus-article-refer-article ()
2260 "Read article specified by message-id around point."
2262 (let ((point (point)))
2263 (search-forward ">" nil t) ;Move point to end of "<....>".
2264 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2265 (let ((message-id (match-string 1)))
2267 (set-buffer gnus-summary-buffer)
2268 (gnus-summary-refer-article message-id))
2270 (error "No references around point"))))
2272 (defun gnus-article-show-summary ()
2273 "Reconfigure windows to show summary buffer."
2275 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2276 (error "There is no summary buffer for this article buffer")
2277 (gnus-article-set-globals)
2278 (gnus-configure-windows 'article)
2279 (gnus-summary-goto-subject gnus-current-article)
2280 (gnus-summary-position-point)))
2282 (defun gnus-article-describe-briefly ()
2283 "Describe article mode commands briefly."
2286 (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")))
2288 (defun gnus-article-summary-command ()
2289 "Execute the last keystroke in the summary buffer."
2291 (let ((obuf (current-buffer))
2292 (owin (current-window-configuration))
2294 (switch-to-buffer gnus-article-current-summary 'norecord)
2295 (setq func (lookup-key (current-local-map) (this-command-keys)))
2296 (call-interactively func)
2298 (set-window-configuration owin)
2299 (set-window-point (get-buffer-window (current-buffer)) (point))))
2301 (defun gnus-article-summary-command-nosave ()
2302 "Execute the last keystroke in the summary buffer."
2305 (pop-to-buffer gnus-article-current-summary 'norecord)
2306 (setq func (lookup-key (current-local-map) (this-command-keys)))
2307 (call-interactively func)))
2309 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2310 "Read a summary buffer key sequence and execute it from the article buffer."
2313 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2314 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2315 "=" "^" "\M-^" "|"))
2321 '("n" "Gn" "p" "Gp"))
2324 (set-buffer gnus-article-current-summary)
2325 (let (gnus-pick-mode)
2326 (push (or key last-command-event) unread-command-events)
2327 (setq keys (read-key-sequence nil))))
2330 (if (or (member keys nosaves)
2331 (member keys nosave-but-article)
2332 (member keys nosave-in-article))
2334 (save-window-excursion
2335 (pop-to-buffer gnus-article-current-summary 'norecord)
2336 ;; We disable the pick minor mode commands.
2337 (let (gnus-pick-mode)
2338 (setq func (lookup-key (current-local-map) keys))))
2341 (unless (member keys nosave-in-article)
2342 (set-buffer gnus-article-current-summary))
2343 (call-interactively func)
2344 (setq new-sum-point (point)))
2345 (when (member keys nosave-but-article)
2346 (pop-to-buffer gnus-article-buffer 'norecord)))
2347 ;; These commands should restore window configuration.
2348 (let ((obuf (current-buffer))
2349 (owin (current-window-configuration))
2351 (summary gnus-article-current-summary)
2352 func in-buffer selected)
2353 (if not-restore-window
2354 (pop-to-buffer summary 'norecord)
2355 (switch-to-buffer summary 'norecord))
2356 (setq in-buffer (current-buffer))
2357 ;; We disable the pick minor mode commands.
2358 (if (setq func (let (gnus-pick-mode)
2359 (lookup-key (current-local-map) keys)))
2361 (call-interactively func)
2362 (setq new-sum-point (point)))
2364 (when (eq in-buffer (current-buffer))
2365 (setq selected (gnus-summary-select-article))
2367 (unless not-restore-window
2368 (set-window-configuration owin))
2369 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2370 (set-window-point (get-buffer-window (current-buffer))
2372 (let ((win (get-buffer-window gnus-article-current-summary)))
2374 (set-window-point win new-sum-point))))))))
2376 (defun gnus-article-hide (&optional arg force)
2377 "Hide all the gruft in the current article.
2378 This means that PGP stuff, signatures, cited text and (some)
2379 headers will be hidden.
2380 If given a prefix, show the hidden text instead."
2381 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2382 (gnus-article-hide-headers arg)
2383 (gnus-article-hide-pgp arg)
2384 (gnus-article-hide-citation-maybe arg force)
2385 (gnus-article-hide-signature arg))
2387 (defun gnus-article-maybe-highlight ()
2388 "Do some article highlighting if article highlighting is requested."
2389 (when (gnus-visual-p 'article-highlight 'highlight)
2390 (gnus-article-highlight-some)))
2392 (defun gnus-check-group-server ()
2393 ;; Make sure the connection to the server is alive.
2394 (unless (gnus-server-opened
2395 (gnus-find-method-for-group gnus-newsgroup-name))
2396 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2397 (gnus-request-group gnus-newsgroup-name t)))
2399 (defun gnus-request-article-this-buffer (article group)
2400 "Get an article and insert it into this buffer."
2401 (let (do-update-line sparse-header)
2405 (gnus-kill-all-overlays)
2406 (setq group (or group gnus-newsgroup-name))
2408 ;; Using `gnus-request-article' directly will insert the article into
2409 ;; `nntp-server-buffer' - so we'll save some time by not having to
2410 ;; copy it from the server buffer into the article buffer.
2412 ;; We only request an article by message-id when we do not have the
2413 ;; headers for it, so we'll have to get those.
2414 (when (stringp article)
2415 (let ((gnus-override-method gnus-refer-article-method))
2416 (gnus-read-header article)))
2418 ;; If the article number is negative, that means that this article
2419 ;; doesn't belong in this newsgroup (possibly), so we find its
2420 ;; message-id and request it by id instead of number.
2421 (when (and (numberp article)
2423 (get-buffer gnus-summary-buffer)
2424 (gnus-buffer-exists-p gnus-summary-buffer))
2426 (set-buffer gnus-summary-buffer)
2427 (let ((header (gnus-summary-article-header article)))
2430 ((memq article gnus-newsgroup-sparse)
2431 ;; This is a sparse gap article.
2432 (setq do-update-line article)
2433 (setq article (mail-header-id header))
2434 (let ((gnus-override-method gnus-refer-article-method))
2435 (setq sparse-header (gnus-read-header article)))
2436 (setq gnus-newsgroup-sparse
2437 (delq article gnus-newsgroup-sparse)))
2439 ;; It's a real article.
2440 (setq article (mail-header-id header)))
2442 ;; It is an extracted pseudo-article.
2443 (setq article 'pseudo)
2444 (gnus-request-pseudo-article header))))
2446 (let ((method (gnus-find-method-for-group
2447 gnus-newsgroup-name)))
2448 (when (and (eq (car method) 'nneething)
2451 (file-name-as-directory
2452 (or (cadr (assq 'nneething-address method))
2454 (mail-header-subject header))))
2455 (when (file-directory-p dir)
2456 (setq article 'nneething)
2457 (gnus-group-enter-directory dir))))))))
2460 ;; Refuse to select canceled articles.
2461 ((and (numberp article)
2463 (get-buffer gnus-summary-buffer)
2464 (gnus-buffer-exists-p gnus-summary-buffer)
2465 (eq (cdr (save-excursion
2466 (set-buffer gnus-summary-buffer)
2467 (assq article gnus-newsgroup-reads)))
2468 gnus-canceled-mark))
2470 ;; Check the backlog.
2471 ((and gnus-keep-backlog
2472 (gnus-backlog-request-article group article (current-buffer)))
2474 ;; Check asynchronous pre-fetch.
2475 ((gnus-async-request-fetched-article group article (current-buffer))
2476 (gnus-async-prefetch-next group article gnus-summary-buffer)
2477 (when (and (numberp article) gnus-keep-backlog)
2478 (gnus-backlog-enter-article group article (current-buffer)))
2481 ((and gnus-use-cache
2483 (gnus-cache-request-article article group))
2485 ;; Get the article and put into the article buffer.
2486 ((or (stringp article) (numberp article))
2487 (let ((gnus-override-method
2488 (and (stringp article) gnus-refer-article-method))
2489 (buffer-read-only nil))
2491 (gnus-kill-all-overlays)
2492 (gnus-check-group-server)
2493 (when (gnus-request-article article group (current-buffer))
2494 (when (numberp article)
2495 (gnus-async-prefetch-next group article gnus-summary-buffer)
2496 (when gnus-keep-backlog
2497 (gnus-backlog-enter-article
2498 group article (current-buffer))))
2503 ;; Associate this article with the current summary buffer.
2504 (setq gnus-article-current-summary gnus-summary-buffer)
2506 ;; Take the article from the original article buffer
2507 ;; and place it in the buffer it's supposed to be in.
2508 (when (and (get-buffer gnus-article-buffer)
2509 (equal (buffer-name (current-buffer))
2510 (buffer-name (get-buffer gnus-article-buffer))))
2512 (if (get-buffer gnus-original-article-buffer)
2513 (set-buffer gnus-original-article-buffer)
2514 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2515 (buffer-disable-undo (current-buffer))
2516 (setq major-mode 'gnus-original-article-mode)
2517 (setq buffer-read-only t))
2518 (let (buffer-read-only)
2520 (insert-buffer-substring gnus-article-buffer))
2521 (setq gnus-original-article (cons group article))))
2524 (run-hooks 'gnus-article-decode-hook)
2526 ;; Update sparse articles.
2527 (when (and do-update-line
2528 (or (numberp article)
2530 (let ((buf (current-buffer)))
2531 (set-buffer gnus-summary-buffer)
2532 (gnus-summary-update-article do-update-line sparse-header)
2533 (gnus-summary-goto-subject do-update-line nil t)
2534 (set-window-point (get-buffer-window (current-buffer) t)
2536 (set-buffer buf))))))
2542 (defcustom gnus-article-edit-mode-hook nil
2543 "Hook run in article edit mode buffers."
2544 :group 'gnus-article-various
2547 (defvar gnus-article-edit-done-function nil)
2549 (defvar gnus-article-edit-mode-map nil)
2551 (unless gnus-article-edit-mode-map
2552 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2554 (gnus-define-keys gnus-article-edit-mode-map
2555 "\C-c\C-c" gnus-article-edit-done
2556 "\C-c\C-k" gnus-article-edit-exit)
2558 (gnus-define-keys (gnus-article-edit-wash-map
2559 "\C-c\C-w" gnus-article-edit-mode-map)
2560 "f" gnus-article-edit-full-stops))
2562 (defun gnus-article-edit-mode ()
2563 "Major mode for editing articles.
2564 This is an extended text-mode.
2566 \\{gnus-article-edit-mode-map}"
2568 (setq major-mode 'gnus-article-edit-mode)
2569 (setq mode-name "Article Edit")
2570 (use-local-map gnus-article-edit-mode-map)
2571 (make-local-variable 'gnus-article-edit-done-function)
2572 (make-local-variable 'gnus-prev-winconf)
2573 (setq buffer-read-only nil)
2574 (buffer-enable-undo)
2576 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2578 (defun gnus-article-edit (&optional force)
2579 "Edit the current article.
2580 This will have permanent effect only in mail groups.
2581 If FORCE is non-nil, allow editing of articles even in read-only
2584 (when (and (not force)
2585 (gnus-group-read-only-p))
2586 (error "The current newsgroup does not support article editing"))
2587 (gnus-article-date-original)
2588 (gnus-article-edit-article
2589 `(lambda (no-highlight)
2590 (gnus-summary-edit-article-done
2591 ,(or (mail-header-references gnus-current-headers) "")
2592 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2594 (defun gnus-article-edit-article (exit-func)
2595 "Start editing the contents of the current article buffer."
2596 (let ((winconf (current-window-configuration)))
2597 (set-buffer gnus-article-buffer)
2598 (gnus-article-edit-mode)
2599 (gnus-article-delete-text-of-type 'annotation)
2600 (gnus-set-text-properties (point-min) (point-max) nil)
2601 (gnus-configure-windows 'edit-article)
2602 (setq gnus-article-edit-done-function exit-func)
2603 (setq gnus-prev-winconf winconf)
2604 (gnus-message 6 "C-c C-c to end edits")))
2606 (defun gnus-article-edit-done (&optional arg)
2607 "Update the article edits and exit."
2612 (goto-char (point-min))
2613 (when (search-forward "\n\n" nil 1)
2614 (let ((lines (count-lines (point) (point-max)))
2615 (length (- (point-max) (point)))
2616 (case-fold-search t)
2617 (body (copy-marker (point))))
2618 (goto-char (point-min))
2619 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2620 (delete-region (match-beginning 1) (match-end 1))
2621 (insert (number-to-string length)))
2622 (goto-char (point-min))
2623 (when (re-search-forward
2624 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2625 (delete-region (match-beginning 1) (match-end 1))
2626 (insert (number-to-string length)))
2627 (goto-char (point-min))
2628 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2629 (delete-region (match-beginning 1) (match-end 1))
2630 (insert (number-to-string lines)))))))
2631 (let ((func gnus-article-edit-done-function)
2632 (buf (current-buffer))
2633 (start (window-start)))
2634 (gnus-article-edit-exit)
2637 (let ((buffer-read-only nil))
2638 (funcall func arg)))
2640 (set-window-start (get-buffer-window buf) start)
2641 (set-window-point (get-buffer-window buf) (point))))
2643 (defun gnus-article-edit-exit ()
2644 "Exit the article editing without updating."
2646 ;; We remove all text props from the article buffer.
2647 (let ((buf (format "%s" (buffer-string)))
2648 (curbuf (current-buffer))
2650 (window-start (window-start)))
2653 (let ((winconf gnus-prev-winconf))
2655 ;; The cache and backlog have to be flushed somewhat.
2656 (when gnus-use-cache
2657 (gnus-cache-update-article
2658 (car gnus-article-current) (cdr gnus-article-current)))
2659 (when gnus-keep-backlog
2660 (gnus-backlog-remove-article
2661 (car gnus-article-current) (cdr gnus-article-current)))
2662 ;; Flush original article as well.
2664 (when (get-buffer gnus-original-article-buffer)
2665 (set-buffer gnus-original-article-buffer)
2666 (setq gnus-original-article nil)))
2667 (set-window-configuration winconf)
2668 ;; Tippy-toe some to make sure that point remains where it was.
2669 (let ((buf (current-buffer)))
2671 (set-window-start (get-buffer-window (current-buffer)) window-start)
2673 (set-buffer buf)))))
2675 (defun gnus-article-edit-full-stops ()
2676 "Interactively repair spacing at end of sentences."
2679 (goto-char (point-min))
2680 (search-forward-regexp "^$" nil t)
2681 (let ((case-fold-search nil))
2682 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2685 ;;; Article highlights
2688 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2690 ;;; Internal Variables:
2692 (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\\)"
2693 "Regular expression that matches URLs."
2694 :group 'gnus-article-buttons
2697 (defcustom gnus-button-alist
2698 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2699 gnus-button-message-id 2)
2700 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2701 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2703 gnus-button-fetch-group 4)
2704 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2705 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2706 t gnus-button-message-id 3)
2707 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2708 ("mailto:\\([a-zA-Z.-@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2709 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2710 ;; This is how URLs _should_ be embedded in text...
2711 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2713 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2714 "*Alist of regexps matching buttons in article bodies.
2716 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2717 REGEXP: is the string matching text around the button,
2718 BUTTON: is the number of the regexp grouping actually matching the button,
2719 FORM: is a lisp expression which must eval to true for the button to
2721 CALLBACK: is the function to call when the user push this button, and each
2722 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2724 CALLBACK can also be a variable, in that case the value of that
2725 variable it the real callback function."
2726 :group 'gnus-article-buttons
2727 :type '(repeat (list regexp
2728 (integer :tag "Button")
2730 (function :tag "Callback")
2733 (integer :tag "Regexp group")))))
2735 (defcustom gnus-header-button-alist
2736 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2737 0 t gnus-button-message-id 0)
2738 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2739 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2740 0 t gnus-button-mailto 0)
2741 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2742 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2743 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2744 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2745 gnus-button-message-id 3))
2746 "*Alist of headers and regexps to match buttons in article heads.
2748 This alist is very similar to `gnus-button-alist', except that each
2749 alist has an additional HEADER element first in each entry:
2751 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2753 HEADER is a regexp to match a header. For a fuller explanation, see
2754 `gnus-button-alist'."
2755 :group 'gnus-article-buttons
2756 :group 'gnus-article-headers
2757 :type '(repeat (list (regexp :tag "Header")
2759 (integer :tag "Button")
2761 (function :tag "Callback")
2764 (integer :tag "Regexp group")))))
2766 (defvar gnus-button-regexp nil)
2767 (defvar gnus-button-marker-list nil)
2768 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2770 (defvar gnus-button-last nil)
2771 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2775 (defun gnus-article-push-button (event)
2776 "Check text under the mouse pointer for a callback function.
2777 If the text under the mouse pointer has a `gnus-callback' property,
2778 call it with the value of the `gnus-data' text property."
2780 (set-buffer (window-buffer (posn-window (event-start event))))
2781 (let* ((pos (posn-point (event-start event)))
2782 (data (get-text-property pos 'gnus-data))
2783 (fun (get-text-property pos 'gnus-callback)))
2786 (funcall fun data))))
2788 (defun gnus-article-press-button ()
2789 "Check text at point for a callback function.
2790 If the text at point has a `gnus-callback' property,
2791 call it with the value of the `gnus-data' text property."
2793 (let* ((data (get-text-property (point) 'gnus-data))
2794 (fun (get-text-property (point) 'gnus-callback)))
2796 (funcall fun data))))
2798 (defun gnus-article-prev-button (n)
2799 "Move point to N buttons backward.
2800 If N is negative, move forward instead."
2802 (gnus-article-next-button (- n)))
2804 (defun gnus-article-next-button (n)
2805 "Move point to N buttons forward.
2806 If N is negative, move backward instead."
2808 (let ((function (if (< n 0) 'previous-single-property-change
2809 'next-single-property-change))
2810 (inhibit-point-motion-hooks t)
2812 (limit (if (< n 0) (point-min) (point-max))))
2814 (while (and (not (= limit (point)))
2816 ;; Skip past the current button.
2817 (when (get-text-property (point) 'gnus-callback)
2818 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2819 ;; Go to the next (or previous) button.
2820 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
2821 ;; Put point at the start of the button.
2822 (when (and backward (not (get-text-property (point) 'gnus-callback)))
2823 (goto-char (funcall function (point) 'gnus-callback nil limit)))
2824 ;; Skip past intangible buttons.
2825 (when (get-text-property (point) 'intangible)
2829 (gnus-message 5 "No more buttons"))
2832 (defun gnus-article-highlight (&optional force)
2833 "Highlight current article.
2834 This function calls `gnus-article-highlight-headers',
2835 `gnus-article-highlight-citation',
2836 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2837 do the highlighting. See the documentation for those functions."
2838 (interactive (list 'force))
2839 (gnus-article-highlight-headers)
2840 (gnus-article-highlight-citation force)
2841 (gnus-article-highlight-signature)
2842 (gnus-article-add-buttons force)
2843 (gnus-article-add-buttons-to-head))
2845 (defun gnus-article-highlight-some (&optional force)
2846 "Highlight current article.
2847 This function calls `gnus-article-highlight-headers',
2848 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
2849 do the highlighting. See the documentation for those functions."
2850 (interactive (list 'force))
2851 (gnus-article-highlight-headers)
2852 (gnus-article-highlight-signature)
2853 (gnus-article-add-buttons))
2855 (defun gnus-article-highlight-headers ()
2856 "Highlight article headers as specified by `gnus-header-face-alist'."
2859 (set-buffer gnus-article-buffer)
2861 (let ((alist gnus-header-face-alist)
2862 (buffer-read-only nil)
2863 (case-fold-search t)
2864 (inhibit-point-motion-hooks t)
2865 entry regexp header-face field-face from hpoints fpoints)
2866 (message-narrow-to-head)
2867 (while (setq entry (pop alist))
2868 (goto-char (point-min))
2869 (setq regexp (concat "^\\("
2870 (if (string-equal "" (nth 0 entry))
2874 header-face (nth 1 entry)
2875 field-face (nth 2 entry))
2876 (while (and (re-search-forward regexp nil t)
2880 (unless (search-forward ":" nil t)
2882 (when (and header-face
2883 (not (memq (point) hpoints)))
2884 (push (point) hpoints)
2885 (gnus-put-text-property from (point) 'face header-face))
2886 (when (and field-face
2887 (not (memq (setq from (point)) fpoints)))
2889 (if (re-search-forward "^[^ \t]" nil t)
2891 (goto-char (point-max)))
2892 (gnus-put-text-property from (point) 'face field-face))))))))
2894 (defun gnus-article-highlight-signature ()
2895 "Highlight the signature in an article.
2896 It does this by highlighting everything after
2897 `gnus-signature-separator' using `gnus-signature-face'."
2900 (set-buffer gnus-article-buffer)
2901 (let ((buffer-read-only nil)
2902 (inhibit-point-motion-hooks t))
2904 (when (and gnus-signature-face
2905 (gnus-article-narrow-to-signature))
2906 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
2907 'face gnus-signature-face)
2909 (gnus-article-search-signature)
2910 (let ((start (match-beginning 0))
2911 (end (set-marker (make-marker) (1+ (match-end 0)))))
2912 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
2915 (defun gnus-button-in-region-p (b e prop)
2916 "Say whether PROP exists in the region."
2917 (text-property-not-all b e prop nil))
2919 (defun gnus-article-add-buttons (&optional force)
2920 "Find external references in the article and make buttons of them.
2921 \"External references\" are things like Message-IDs and URLs, as
2922 specified by `gnus-button-alist'."
2923 (interactive (list 'force))
2925 (set-buffer gnus-article-buffer)
2926 (let ((buffer-read-only nil)
2927 (inhibit-point-motion-hooks t)
2928 (case-fold-search t)
2929 (alist gnus-button-alist)
2931 ;; Remove all old markers.
2933 (while (setq marker (pop gnus-button-marker-list))
2935 (when (setq entry (gnus-button-entry))
2936 (put-text-property (match-beginning (nth 1 entry))
2937 (match-end (nth 1 entry))
2938 'gnus-callback nil))
2939 (set-marker marker nil)))
2940 ;; We skip the headers.
2941 (goto-char (point-min))
2942 (unless (search-forward "\n\n" nil t)
2943 (goto-char (point-max)))
2945 (while (setq entry (pop alist))
2946 (setq regexp (car entry))
2948 (while (re-search-forward regexp nil t)
2949 (let* ((start (and entry (match-beginning (nth 1 entry))))
2950 (end (and entry (match-end (nth 1 entry))))
2951 (from (match-beginning 0)))
2952 (when (and (or (eq t (nth 2 entry))
2953 (eval (nth 2 entry)))
2954 (not (gnus-button-in-region-p
2955 start end 'gnus-callback)))
2956 ;; That optional form returned non-nil, so we add the
2958 (gnus-article-add-button
2959 start end 'gnus-button-push
2960 (car (push (set-marker (make-marker) from)
2961 gnus-button-marker-list))))))))))
2963 ;; Add buttons to the head of an article.
2964 (defun gnus-article-add-buttons-to-head ()
2965 "Add buttons to the head of the article."
2968 (set-buffer gnus-article-buffer)
2969 (let ((buffer-read-only nil)
2970 (inhibit-point-motion-hooks t)
2971 (case-fold-search t)
2972 (alist gnus-header-button-alist)
2974 (nnheader-narrow-to-headers)
2976 ;; Each alist entry.
2977 (setq entry (car alist)
2979 (goto-char (point-min))
2980 (while (re-search-forward (car entry) nil t)
2981 ;; Each header matching the entry.
2982 (setq beg (match-beginning 0))
2983 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
2984 (match-beginning 0))
2987 (while (re-search-forward (nth 1 entry) end t)
2988 ;; Each match within a header.
2989 (let* ((entry (cdr entry))
2990 (start (match-beginning (nth 1 entry)))
2991 (end (match-end (nth 1 entry)))
2992 (form (nth 2 entry)))
2993 (goto-char (match-end 0))
2995 (gnus-article-add-button
2996 start end (nth 3 entry)
2997 (buffer-substring (match-beginning (nth 4 entry))
2998 (match-end (nth 4 entry)))))))
3002 ;;; External functions:
3004 (defun gnus-article-add-button (from to fun &optional data)
3005 "Create a button between FROM and TO with callback FUN and data DATA."
3006 (when gnus-article-button-face
3007 (gnus-overlay-put (gnus-make-overlay from to)
3008 'face gnus-article-button-face))
3009 (gnus-add-text-properties
3011 (nconc (and gnus-article-mouse-face
3012 (list gnus-mouse-face-prop gnus-article-mouse-face))
3013 (list 'gnus-callback fun)
3014 (and data (list 'gnus-data data)))))
3016 ;;; Internal functions:
3018 (defun gnus-article-set-globals ()
3020 (set-buffer gnus-summary-buffer)
3021 (gnus-set-global-variables)))
3023 (defun gnus-signature-toggle (end)
3025 (set-buffer gnus-article-buffer)
3026 (let ((buffer-read-only nil)
3027 (inhibit-point-motion-hooks t))
3028 (if (get-text-property end 'invisible)
3029 (gnus-article-unhide-text end (point-max))
3030 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3032 (defun gnus-button-entry ()
3033 ;; Return the first entry in `gnus-button-alist' matching this place.
3034 (let ((alist gnus-button-alist)
3037 (setq entry (pop alist))
3038 (if (looking-at (car entry))
3043 (defun gnus-button-push (marker)
3044 ;; Push button starting at MARKER.
3046 (set-buffer gnus-article-buffer)
3048 (let* ((entry (gnus-button-entry))
3049 (inhibit-point-motion-hooks t)
3051 (args (mapcar (lambda (group)
3052 (let ((string (match-string group)))
3053 (gnus-set-text-properties
3054 0 (length string) nil string)
3061 (fboundp (symbol-value fun)))
3062 (apply (symbol-value fun) args))
3064 (gnus-message 1 "You must define `%S' to use this button"
3065 (cons fun args)))))))
3067 (defun gnus-button-message-id (message-id)
3070 (set-buffer gnus-summary-buffer)
3071 (gnus-summary-refer-article message-id)))
3073 (defun gnus-button-fetch-group (address)
3074 "Fetch GROUP specified by ADDRESS."
3075 (if (not (string-match "[:/]" address))
3076 ;; This is just a simple group url.
3077 (gnus-group-read-ephemeral-group address gnus-select-method)
3078 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3080 (error "Can't parse %s" address)
3081 (gnus-group-read-ephemeral-group
3082 (match-string 4 address)
3083 `(nntp ,(match-string 1 address)
3084 (nntp-address ,(match-string 1 address))
3085 (nntp-port-number ,(if (match-end 3)
3086 (match-string 3 address)
3089 (defun gnus-url-parse-query-string (query &optional downcase)
3090 (let (retval pairs cur key val)
3091 (setq pairs (split-string query "&"))
3093 (setq cur (car pairs)
3095 (if (not (string-match "=" cur))
3097 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3098 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3100 (setq key (downcase key)))
3101 (setq cur (assoc key retval))
3103 (setcdr cur (cons val (cdr cur)))
3104 (setq retval (cons (list key val) retval)))))
3107 (defun gnus-url-unhex (x)
3114 (defun gnus-url-unhex-string (str &optional allow-newlines)
3115 "Remove %XXX embedded spaces, etc in a url.
3116 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3117 decoding of carriage returns and line feeds in the string, which is normally
3118 forbidden in URL encoding."
3119 (setq str (or str ""))
3121 (case-fold-search t))
3122 (while (string-match "%[0-9a-f][0-9a-f]" str)
3123 (let* ((start (match-beginning 0))
3124 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3126 (gnus-url-unhex (elt str (+ start 2))))))
3128 tmp (substring str 0 start)
3131 (char-to-string code))
3132 ((or (= code ?\n) (= code ?\r))
3134 (t (char-to-string code))))
3135 str (substring str (match-end 0)))))
3136 (setq tmp (concat tmp str))
3139 (defun gnus-url-mailto (url)
3140 ;; Send mail to someone
3141 (when (string-match "mailto:/*\\(.*\\)" url)
3142 (setq url (substring url (match-beginning 1) nil)))
3143 (let (to args subject func)
3144 (if (string-match (regexp-quote "?") url)
3145 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3146 args (gnus-url-parse-query-string
3147 (substring url (match-end 0) nil) t))
3148 (setq to (gnus-url-unhex-string url)))
3149 (setq args (cons (list "to" to) args)
3150 subject (cdr-safe (assoc "subject" args)))
3151 (gnus-setup-message 'reply
3154 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3157 (message-position-on-field (caar args)))
3158 (insert (mapconcat 'identity (cdar args) ", "))
3159 (setq args (cdr args)))
3162 (message-goto-subject)))))
3164 (defun gnus-button-mailto (address)
3166 (set-buffer (gnus-copy-article-buffer))
3167 (gnus-setup-message 'reply
3168 (message-reply address)))
3170 (defun gnus-button-reply (address)
3171 ;; Reply to ADDRESS.
3172 (gnus-setup-message 'reply
3173 (message-reply address)))
3175 (defun gnus-button-url (address)
3177 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3178 (if (listp browse-url-browser-function)
3179 (browse-url address)
3180 (funcall browse-url-browser-function address)))
3182 (defun gnus-button-embedded-url (address)
3184 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3185 (if (listp browse-url-browser-function)
3186 (browse-url (gnus-strip-whitespace address))
3187 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3189 ;;; Next/prev buttons in the article buffer.
3191 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3192 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3194 (defvar gnus-prev-page-map nil)
3195 (unless gnus-prev-page-map
3196 (setq gnus-prev-page-map (make-sparse-keymap))
3197 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3198 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3200 (defun gnus-insert-prev-page-button ()
3201 (let ((buffer-read-only nil))
3203 gnus-prev-page-line-format nil
3204 `(gnus-prev t local-map ,gnus-prev-page-map
3205 gnus-callback gnus-article-button-prev-page
3206 gnus-type annotation))))
3208 (defvar gnus-next-page-map nil)
3209 (unless gnus-next-page-map
3210 (setq gnus-next-page-map (make-keymap))
3211 (suppress-keymap gnus-prev-page-map)
3212 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3213 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3215 (defun gnus-button-next-page ()
3216 "Go to the next page."
3218 (let ((win (selected-window)))
3219 (select-window (get-buffer-window gnus-article-buffer t))
3220 (gnus-article-next-page)
3221 (select-window win)))
3223 (defun gnus-button-prev-page ()
3224 "Go to the prev page."
3226 (let ((win (selected-window)))
3227 (select-window (get-buffer-window gnus-article-buffer t))
3228 (gnus-article-prev-page)
3229 (select-window win)))
3231 (defun gnus-insert-next-page-button ()
3232 (let ((buffer-read-only nil))
3233 (gnus-eval-format gnus-next-page-line-format nil
3235 t local-map ,gnus-next-page-map
3236 gnus-callback gnus-article-button-next-page
3237 gnus-type annotation))))
3239 (defun gnus-article-button-next-page (arg)
3240 "Go to the next page."
3242 (let ((win (selected-window)))
3243 (select-window (get-buffer-window gnus-article-buffer t))
3244 (gnus-article-next-page)
3245 (select-window win)))
3247 (defun gnus-article-button-prev-page (arg)
3248 "Go to the prev page."
3250 (let ((win (selected-window)))
3251 (select-window (get-buffer-window gnus-article-buffer t))
3252 (gnus-article-prev-page)
3253 (select-window win)))
3259 (defun gnus-article-header-presentation-method (entity situation)
3260 (mime-insert-decoded-header entity)
3263 (set-alist 'mime-header-presentation-method-alist
3264 'gnus-original-article-mode
3265 #'gnus-article-header-presentation-method)
3267 (defun gnus-mime-preview-quitting-method ()
3269 (gnus-article-show-summary)
3270 (mime-preview-kill-buffer)
3271 (delete-other-windows)
3272 (gnus-article-show-summary)
3273 (gnus-summary-select-article nil t)
3276 (set-alist 'mime-preview-quitting-method-alist
3277 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
3279 (defun gnus-following-method (buf)
3282 (message-yank-original)
3284 (goto-char (point-min))
3287 (set-alist 'mime-preview-following-method-alist
3288 'gnus-original-article-mode #'gnus-following-method)
3298 (run-hooks 'gnus-art-load-hook)
3300 ;;; gnus-art.el ends here