1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
42 (defgroup gnus-article nil
44 :link '(custom-manual "(gnus)The Article Buffer")
47 (defgroup gnus-article-hiding nil
48 "Hiding article parts."
49 :link '(custom-manual "(gnus)Article Hiding")
52 (defgroup gnus-article-highlight nil
53 "Article highlighting."
54 :link '(custom-manual "(gnus)Article Highlighting")
58 (defgroup gnus-article-signature nil
60 :link '(custom-manual "(gnus)Article Signature")
63 (defgroup gnus-article-headers nil
65 :link '(custom-manual "(gnus)Hiding Headers")
68 (defgroup gnus-article-washing nil
69 "Special commands on articles."
70 :link '(custom-manual "(gnus)Article Washing")
73 (defgroup gnus-article-emphasis nil
74 "Fontisizing articles."
75 :link '(custom-manual "(gnus)Article Fontisizing")
78 (defgroup gnus-article-saving nil
80 :link '(custom-manual "(gnus)Saving Articles")
83 (defgroup gnus-article-mime nil
84 "Worshiping the MIME wonder."
85 :link '(custom-manual "(gnus)Using MIME")
88 (defgroup gnus-article-buttons nil
89 "Pushable buttons in the article buffer."
90 :link '(custom-manual "(gnus)Article Buttons")
93 (defgroup gnus-article-various nil
94 "Other article options."
95 :link '(custom-manual "(gnus)Misc Article")
98 (defcustom gnus-ignored-headers
99 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
100 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
101 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
102 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
103 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
104 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
105 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
106 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
107 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
108 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
109 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
110 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
111 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
112 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
113 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
114 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
115 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
116 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
118 "*All headers that start with this regexp will be hidden.
119 This variable can also be a list of regexps of headers to be ignored.
120 If `gnus-visible-headers' is non-nil, this variable will be ignored."
121 :type '(choice :custom-show nil
124 :group 'gnus-article-hiding)
126 (defcustom gnus-visible-headers
127 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
128 "*All headers that do not match this regexp will be hidden.
129 This variable can also be a list of regexp of headers to remain visible.
130 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
131 :type '(repeat :value-to-internal (lambda (widget value)
132 (custom-split-regexp-maybe value))
133 :match (lambda (widget value)
135 (widget-editable-list-match widget value)))
137 :group 'gnus-article-hiding)
139 (defcustom gnus-sorted-header-list
140 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
141 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
142 "*This variable is a list of regular expressions.
143 If it is non-nil, headers that match the regular expressions will
144 be placed first in the article buffer in the sequence specified by
146 :type '(repeat regexp)
147 :group 'gnus-article-hiding)
149 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
150 "Headers that are only to be displayed if they have interesting data.
151 Possible values in this list are `empty', `newsgroups', `followup-to',
152 `reply-to', `date', `long-to', and `many-to'."
153 :type '(set (const :tag "Headers with no content." empty)
154 (const :tag "Newsgroups with only one group." newsgroups)
155 (const :tag "Followup-to identical to newsgroups." followup-to)
156 (const :tag "Reply-to identical to from." reply-to)
157 (const :tag "Date less than four days old." date)
158 (const :tag "Very long To header." long-to)
159 (const :tag "Multiple To headers." many-to))
160 :group 'gnus-article-hiding)
162 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
163 "Regexp matching signature separator.
164 This can also be a list of regexps. In that case, it will be checked
165 from head to tail looking for a separator. Searches will be done from
166 the end of the buffer."
167 :type '(repeat string)
168 :group 'gnus-article-signature)
170 (defcustom gnus-signature-limit nil
171 "Provide a limit to what is considered a signature.
172 If it is a number, no signature may not be longer (in characters) than
173 that number. If it is a floating point number, no signature may be
174 longer (in lines) than that number. If it is a function, the function
175 will be called without any parameters, and if it returns nil, there is
176 no signature in the buffer. If it is a string, it will be used as a
177 regexp. If it matches, the text in question is not a signature."
178 :type '(choice (integer :value 200)
180 (function :value fun)
181 (regexp :value ".*"))
182 :group 'gnus-article-signature)
184 (defcustom gnus-hidden-properties '(invisible t intangible t)
185 "Property list to use for hiding text."
187 :group 'gnus-article-hiding)
189 (defcustom gnus-article-x-face-command
190 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
191 "*String or function to be executed to display an X-Face header.
192 If it is a string, the command will be executed in a sub-shell
193 asynchronously. The compressed face will be piped to this command."
194 :type 'string ;Leave function case to Lisp.
195 :group 'gnus-article-washing)
197 (defcustom gnus-article-x-face-too-ugly nil
198 "Regexp matching posters whose face shouldn't be shown automatically."
199 :type '(choice regexp (const nil))
200 :group 'gnus-article-washing)
202 (defcustom gnus-emphasis-alist
204 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
206 '(("_" "_" underline)
209 ("_/" "/_" underline-italic)
210 ("_\\*" "\\*_" underline-bold)
211 ("\\*/" "/\\*" bold-italic)
212 ("_\\*/" "/\\*_" underline-bold-italic))))
213 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
214 2 3 gnus-emphasis-underline)
218 (format format (car spec) (cadr spec))
219 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
221 "*Alist that says how to fontify certain phrases.
222 Each item looks like this:
224 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
226 The first element is a regular expression to be matched. The second
227 is a number that says what regular expression grouping used to find
228 the entire emphasized word. The third is a number that says what
229 regexp grouping should be displayed and highlighted. The fourth
230 is the face used for highlighting."
231 :type '(repeat (list :value ("" 0 0 default)
233 (integer :tag "Match group")
234 (integer :tag "Emphasize group")
236 :group 'gnus-article-emphasis)
238 (defface gnus-emphasis-bold '((t (:bold t)))
239 "Face used for displaying strong emphasized text (*word*)."
240 :group 'gnus-article-emphasis)
242 (defface gnus-emphasis-italic '((t (:italic t)))
243 "Face used for displaying italic emphasized text (/word/)."
244 :group 'gnus-article-emphasis)
246 (defface gnus-emphasis-underline '((t (:underline t)))
247 "Face used for displaying underlined emphasized text (_word_)."
248 :group 'gnus-article-emphasis)
250 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
251 "Face used for displaying underlined bold emphasized text (_*word*_)."
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
255 "Face used for displaying underlined italic emphasized text (_*word*_)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
259 "Face used for displaying bold italic emphasized text (/*word*/)."
260 :group 'gnus-article-emphasis)
262 (defface gnus-emphasis-underline-bold-italic
263 '((t (:bold t :italic t :underline t)))
264 "Face used for displaying underlined bold italic emphasized text.
265 Esample: (_/*word*/_)."
266 :group 'gnus-article-emphasis)
268 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
269 "Format for display of Date headers in article bodies.
270 See `format-time-string' for the possible values.
272 The variable can also be function, which should return a complete Date
273 header. The function is called with one argument, the time, which can
274 be fed to `format-time-string'."
275 :type '(choice string symbol)
276 :link '(custom-manual "(gnus)Article Date")
277 :group 'gnus-article-washing)
280 (autoload 'mail-extract-address-components "mail-extr"))
282 (defcustom gnus-save-all-headers t
283 "*If non-nil, don't remove any headers before saving."
284 :group 'gnus-article-saving
287 (defcustom gnus-prompt-before-saving 'always
288 "*This variable says how much prompting is to be done when saving articles.
289 If it is nil, no prompting will be done, and the articles will be
290 saved to the default files. If this variable is `always', each and
291 every article that is saved will be preceded by a prompt, even when
292 saving large batches of articles. If this variable is neither nil not
293 `always', there the user will be prompted once for a file name for
294 each invocation of the saving commands."
295 :group 'gnus-article-saving
296 :type '(choice (item always)
297 (item :tag "never" nil)
298 (sexp :tag "once" :format "%t\n" :value t)))
300 (defcustom gnus-saved-headers gnus-visible-headers
301 "Headers to keep if `gnus-save-all-headers' is nil.
302 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
303 If that variable is nil, however, all headers that match this regexp
304 will be kept while the rest will be deleted before saving."
305 :group 'gnus-article-saving
308 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
309 "A function to save articles in your favourite format.
310 The function must be interactively callable (in other words, it must
311 be an Emacs command).
313 Gnus provides the following functions:
315 * gnus-summary-save-in-rmail (Rmail format)
316 * gnus-summary-save-in-mail (Unix mail format)
317 * gnus-summary-save-in-folder (MH folder)
318 * gnus-summary-save-in-file (article format)
319 * gnus-summary-save-in-vm (use VM's folder format)
320 * gnus-summary-write-to-file (article format -- overwrite)."
321 :group 'gnus-article-saving
322 :type '(radio (function-item gnus-summary-save-in-rmail)
323 (function-item gnus-summary-save-in-mail)
324 (function-item gnus-summary-save-in-folder)
325 (function-item gnus-summary-save-in-file)
326 (function-item gnus-summary-save-in-vm)
327 (function-item gnus-summary-write-to-file)))
329 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
330 "A function generating a file name to save articles in Rmail format.
331 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
332 :group 'gnus-article-saving
335 (defcustom gnus-mail-save-name 'gnus-plain-save-name
336 "A function generating a file name to save articles in Unix mail format.
337 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
338 :group 'gnus-article-saving
341 (defcustom gnus-folder-save-name 'gnus-folder-save-name
342 "A function generating a file name to save articles in MH folder.
343 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
344 :group 'gnus-article-saving
347 (defcustom gnus-file-save-name 'gnus-numeric-save-name
348 "A function generating a file name to save articles in article format.
349 The function is called with NEWSGROUP, HEADERS, and optional
351 :group 'gnus-article-saving
354 (defcustom gnus-split-methods
355 '((gnus-article-archive-name)
356 (gnus-article-nndoc-name))
357 "*Variable used to suggest where articles are to be saved.
358 For instance, if you would like to save articles related to Gnus in
359 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
360 you could set this variable to something like:
362 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
363 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
365 This variable is an alist where the where the key is the match and the
366 value is a list of possible files to save in if the match is non-nil.
368 If the match is a string, it is used as a regexp match on the
369 article. If the match is a symbol, that symbol will be funcalled
370 from the buffer of the article to be saved with the newsgroup as the
371 parameter. If it is a list, it will be evaled in the same buffer.
373 If this form or function returns a string, this string will be used as
374 a possible file name; and if it returns a non-nil list, that list will
375 be used as possible file names."
376 :group 'gnus-article-saving
377 :type '(repeat (choice (list :value (fun) function)
378 (cons :value ("" "") regexp (repeat string))
381 (defcustom gnus-page-delimiter "^\^L"
382 "*Regexp describing what to use as article page delimiters.
383 The default value is \"^\^L\", which is a form linefeed at the
384 beginning of a line."
386 :group 'gnus-article-various)
388 (defcustom gnus-article-mode-line-format "Gnus: %g %S"
389 "*The format specification for the article mode line.
390 See `gnus-summary-mode-line-format' for a closer description."
392 :group 'gnus-article-various)
394 (defcustom gnus-article-mode-hook nil
395 "*A hook for Gnus article mode."
397 :group 'gnus-article-various)
399 (defcustom gnus-article-menu-hook nil
400 "*Hook run after the creation of the article mode menu."
402 :group 'gnus-article-various)
404 (defcustom gnus-article-prepare-hook nil
405 "*A hook called after an article has been prepared in the article buffer.
406 If you want to run a special decoding program like nkf, use this hook."
408 :group 'gnus-article-various)
410 (defcustom gnus-article-hide-pgp-hook nil
411 "*A hook called after successfully hiding a PGP signature."
413 :group 'gnus-article-various)
415 (defcustom gnus-article-button-face 'bold
416 "Face used for highlighting buttons in the article buffer.
418 An article button is a piece of text that you can activate by pressing
419 `RET' or `mouse-2' above it."
421 :group 'gnus-article-buttons)
423 (defcustom gnus-article-mouse-face 'highlight
424 "Face used for mouse highlighting in the article buffer.
426 Article buttons will be displayed in this face when the cursor is
429 :group 'gnus-article-buttons)
431 (defcustom gnus-signature-face 'gnus-signature-face
432 "Face used for highlighting a signature in the article buffer.
433 Obsolete; use the face `gnus-signature-face' for customizations instead."
435 :group 'gnus-article-highlight
436 :group 'gnus-article-signature)
438 (defface gnus-signature-face
441 "Face used for highlighting a signature in the article buffer."
442 :group 'gnus-article-highlight
443 :group 'gnus-article-signature)
445 (defface gnus-header-from-face
448 (:foreground "spring green"))
451 (:foreground "red3"))
454 "Face used for displaying from headers."
455 :group 'gnus-article-headers
456 :group 'gnus-article-highlight)
458 (defface gnus-header-subject-face
461 (:foreground "SeaGreen3"))
464 (:foreground "red4"))
466 (:bold t :italic t)))
467 "Face used for displaying subject headers."
468 :group 'gnus-article-headers
469 :group 'gnus-article-highlight)
471 (defface gnus-header-newsgroups-face
474 (:foreground "yellow" :italic t))
477 (:foreground "MidnightBlue" :italic t))
480 "Face used for displaying newsgroups headers."
481 :group 'gnus-article-headers
482 :group 'gnus-article-highlight)
484 (defface gnus-header-name-face
487 (:foreground "SeaGreen"))
490 (:foreground "maroon"))
493 "Face used for displaying header names."
494 :group 'gnus-article-headers
495 :group 'gnus-article-highlight)
497 (defface gnus-header-content-face
500 (:foreground "forest green" :italic t))
503 (:foreground "indianred4" :italic t))
505 (:italic t))) "Face used for displaying header content."
506 :group 'gnus-article-headers
507 :group 'gnus-article-highlight)
509 (defcustom gnus-header-face-alist
510 '(("From" nil gnus-header-from-face)
511 ("Subject" nil gnus-header-subject-face)
512 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
513 ("" gnus-header-name-face gnus-header-content-face))
514 "*Controls highlighting of article header.
516 An alist of the form (HEADER NAME CONTENT).
518 HEADER is a regular expression which should match the name of an
519 header header and NAME and CONTENT are either face names or nil.
521 The name of each header field will be displayed using the face
522 specified by the first element in the list where HEADER match the
523 header name and NAME is non-nil. Similarly, the content will be
524 displayed by the first non-nil matching CONTENT face."
525 :group 'gnus-article-headers
526 :group 'gnus-article-highlight
527 :type '(repeat (list (regexp :tag "Header")
529 (item :tag "skip" nil)
530 (face :value default))
531 (choice :tag "Content"
532 (item :tag "skip" nil)
533 (face :value default)))))
535 (defcustom gnus-article-decode-hook
536 '(article-decode-charset article-decode-encoded-words)
537 "*Hook run to decode charsets in articles."
538 :group 'gnus-article-headers
541 (defcustom gnus-display-mime-function 'gnus-display-mime
542 "Function to display MIME articles."
543 :group 'gnus-article-headers
546 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
547 "Function used to decode headers.")
549 ;;; Internal variables
551 (defvar article-lapsed-timer nil)
552 (defvar gnus-article-current-summary nil)
554 (defvar gnus-article-mode-syntax-table
555 (let ((table (copy-syntax-table text-mode-syntax-table)))
556 (modify-syntax-entry ?- "w" table)
557 (modify-syntax-entry ?> ")" table)
558 (modify-syntax-entry ?< "(" table)
560 "Syntax table used in article mode buffers.
561 Initialized from `text-mode-syntax-table.")
563 (defvar gnus-save-article-buffer nil)
565 (defvar gnus-article-mode-line-format-alist
566 (nconc '((?w (gnus-article-wash-status) ?s))
567 gnus-summary-mode-line-format-alist))
569 (defvar gnus-number-of-articles-to-be-saved nil)
571 (defvar gnus-inhibit-hiding nil)
573 (defsubst gnus-article-hide-text (b e props)
574 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
575 (add-text-properties b e props)
576 (when (memq 'intangible props)
578 (max (1- b) (point-min))
579 b 'intangible (cddr (memq 'intangible props)))))
581 (defsubst gnus-article-unhide-text (b e)
582 "Remove hidden text properties from region between B and E."
583 (remove-text-properties b e gnus-hidden-properties)
584 (when (memq 'intangible gnus-hidden-properties)
585 (put-text-property (max (1- b) (point-min))
588 (defun gnus-article-hide-text-type (b e type)
589 "Hide text of TYPE between B and E."
590 (gnus-article-hide-text
591 b e (cons 'article-type (cons type gnus-hidden-properties))))
593 (defun gnus-article-unhide-text-type (b e type)
594 "Unhide text of TYPE between B and E."
595 (remove-text-properties
596 b e (cons 'article-type (cons type gnus-hidden-properties)))
597 (when (memq 'intangible gnus-hidden-properties)
598 (put-text-property (max (1- b) (point-min))
601 (defun gnus-article-hide-text-of-type (type)
602 "Hide text of TYPE in the current buffer."
604 (let ((b (point-min))
606 (while (setq b (text-property-any b e 'article-type type))
607 (add-text-properties b (incf b) gnus-hidden-properties)))))
609 (defun gnus-article-delete-text-of-type (type)
610 "Delete text of TYPE in the current buffer."
612 (let ((b (point-min)))
613 (while (setq b (text-property-any b (point-max) 'article-type type))
615 b (or (text-property-not-all b (point-max) 'article-type type)
618 (defun gnus-article-delete-invisible-text ()
619 "Delete all invisible text in the current buffer."
621 (let ((b (point-min)))
622 (while (setq b (text-property-any b (point-max) 'invisible t))
624 b (or (text-property-not-all b (point-max) 'invisible t)
627 (defun gnus-article-text-type-exists-p (type)
628 "Say whether any text of type TYPE exists in the buffer."
629 (text-property-any (point-min) (point-max) 'article-type type))
631 (defsubst gnus-article-header-rank ()
632 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
633 (let ((list gnus-sorted-header-list)
636 (when (looking-at (car list))
638 (setq list (cdr list))
642 (defun article-hide-headers (&optional arg delete)
643 "Toggle whether to hide unwanted headers and possibly sort them as well.
644 If given a negative prefix, always show; if given a positive prefix,
646 (interactive (gnus-article-hidden-arg))
648 (if (gnus-article-check-hidden-text 'headers arg)
649 ;; Show boring headers as well.
650 (gnus-article-show-hidden-text 'boring-headers)
651 ;; This function might be inhibited.
652 (unless gnus-inhibit-hiding
655 (let ((buffer-read-only nil)
657 (props (nconc (list 'article-type 'headers)
658 gnus-hidden-properties))
659 (max (1+ (length gnus-sorted-header-list)))
660 (ignored (when (not gnus-visible-headers)
661 (cond ((stringp gnus-ignored-headers)
662 gnus-ignored-headers)
663 ((listp gnus-ignored-headers)
664 (mapconcat 'identity gnus-ignored-headers
667 (cond ((stringp gnus-visible-headers)
668 gnus-visible-headers)
669 ((and gnus-visible-headers
670 (listp gnus-visible-headers))
671 (mapconcat 'identity gnus-visible-headers "\\|"))))
672 (inhibit-point-motion-hooks t)
674 ;; First we narrow to just the headers.
676 (goto-char (point-min))
677 ;; Hide any "From " lines at the beginning of (mail) articles.
678 (while (looking-at "From ")
682 (delete-region (point-min) (point))
683 (gnus-article-hide-text (point-min) (point) props)))
684 ;; Then treat the rest of the header lines.
687 (if (search-forward "\n\n" nil t) ; if there's a body
688 (progn (forward-line -1) (point))
690 ;; Then we use the two regular expressions
691 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
692 ;; select which header lines is to remain visible in the
694 (goto-char (point-min))
695 (while (re-search-forward "^[^ \t]*:" nil t)
697 ;; Mark the rank of the header.
699 (point) (1+ (point)) 'message-rank
700 (if (or (and visible (looking-at visible))
702 (not (looking-at ignored))))
703 (gnus-article-header-rank)
706 (message-sort-headers-1)
707 (when (setq beg (text-property-any
708 (point-min) (point-max) 'message-rank (+ 2 max)))
709 ;; We make the unwanted headers invisible.
711 (delete-region beg (point-max))
712 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
713 (gnus-article-hide-text-type beg (point-max) 'headers))
714 ;; Work around XEmacs lossage.
715 (put-text-property (point-min) beg 'invisible nil))))))))
717 (defun article-hide-boring-headers (&optional arg)
718 "Toggle hiding of headers that aren't very interesting.
719 If given a negative prefix, always show; if given a positive prefix,
721 (interactive (gnus-article-hidden-arg))
722 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
723 (not gnus-show-all-headers))
726 (let ((buffer-read-only nil)
727 (list gnus-boring-article-headers)
728 (inhibit-point-motion-hooks t)
730 (nnheader-narrow-to-headers)
732 (setq elem (pop list))
733 (goto-char (point-min))
735 ;; Hide empty headers.
737 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
739 (gnus-article-hide-text-type
740 (progn (beginning-of-line) (point))
743 (if (re-search-forward "^[^ \t]" nil t)
747 ;; Hide boring Newsgroups header.
748 ((eq elem 'newsgroups)
749 (when (equal (gnus-fetch-field "newsgroups")
750 (gnus-group-real-name
751 (if (boundp 'gnus-newsgroup-name)
754 (gnus-article-hide-header "newsgroups")))
755 ((eq elem 'followup-to)
756 (when (equal (message-fetch-field "followup-to")
757 (message-fetch-field "newsgroups"))
758 (gnus-article-hide-header "followup-to")))
760 (let ((from (message-fetch-field "from"))
761 (reply-to (message-fetch-field "reply-to")))
766 (nth 1 (mail-extract-address-components from))
767 (nth 1 (mail-extract-address-components reply-to)))))
768 (gnus-article-hide-header "reply-to"))))
770 (let ((date (message-fetch-field "date")))
772 (< (days-between (current-time-string) date)
774 (gnus-article-hide-header "date"))))
776 (let ((to (message-fetch-field "to")))
777 (when (> (length to) 1024)
778 (gnus-article-hide-header "to"))))
781 (goto-char (point-min))
782 (while (re-search-forward "^to:" nil t)
783 (setq to-count (1+ to-count)))
785 (while (> to-count 0)
786 (goto-char (point-min))
788 (re-search-forward "^to:" nil nil to-count)
790 (narrow-to-region (point) (point-max))
791 (gnus-article-hide-header "to"))
792 (setq to-count (1- to-count)))))))))))))
794 (defun gnus-article-hide-header (header)
796 (goto-char (point-min))
797 (when (re-search-forward (concat "^" header ":") nil t)
798 (gnus-article-hide-text-type
799 (progn (beginning-of-line) (point))
802 (if (re-search-forward "^[^ \t]" nil t)
807 (defun article-treat-dumbquotes ()
808 "Translate M******** sm*rtq**t*s into proper text."
810 (article-translate-characters "\221\222\223\224" "`'\"\""))
812 (defun article-translate-characters (from to)
813 "Translate all characters in the body of the article according to FROM and TO.
814 FROM is a string of characters to translate from; to is a string of
815 characters to translate to."
817 (goto-char (point-min))
818 (when (search-forward "\n\n" nil t)
819 (let ((buffer-read-only nil)
820 (x (make-string 225 ?x))
822 (while (< (incf i) (length x))
825 (while (< i (length from))
826 (aset x (aref from i) (aref to i))
828 (translate-region (point) (point-max) x)))))
830 (defun article-treat-overstrike ()
831 "Translate overstrikes into bold text."
834 (goto-char (point-min))
835 (when (search-forward "\n\n" nil t)
836 (let ((buffer-read-only nil))
837 (while (search-forward "\b" nil t)
838 (let ((next (following-char))
839 (previous (char-after (- (point) 2))))
840 ;; We do the boldification/underlining by hiding the
841 ;; overstrikes and putting the proper text property
845 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
846 (put-text-property (point) (1+ (point)) 'face 'bold))
848 (gnus-article-hide-text-type
849 (1- (point)) (1+ (point)) 'overstrike)
851 (- (point) 2) (1- (point)) 'face 'underline))
853 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
855 (point) (1+ (point)) 'face 'underline)))))))))
857 (defun article-fill ()
858 "Format too long lines."
861 (let ((buffer-read-only nil))
863 (goto-char (point-min))
864 (search-forward "\n\n" nil t)
866 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
867 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
868 (adaptive-fill-mode t))
870 (and (>= (current-column) (min fill-column (window-width)))
871 (/= (preceding-char) ?:)
872 (fill-paragraph nil))
875 (defun article-remove-cr ()
876 "Remove carriage returns from an article."
879 (let ((buffer-read-only nil))
880 (goto-char (point-min))
881 (while (search-forward "\r" nil t)
882 (replace-match "" t t)))))
884 (defun article-remove-trailing-blank-lines ()
885 "Remove all trailing blank lines from the article."
888 (let ((buffer-read-only nil))
889 (goto-char (point-max))
893 (while (and (not (bobp))
894 (looking-at "^[ \t]*$")
895 (not (gnus-annotation-in-region-p
896 (point) (gnus-point-at-eol))))
901 (defun article-display-x-face (&optional force)
902 "Look for an X-Face header and display it if present."
903 (interactive (list 'force))
905 ;; Delete the old process, if any.
906 (when (process-status "article-x-face")
907 (delete-process "article-x-face"))
908 (let ((inhibit-point-motion-hooks t)
912 (nnheader-narrow-to-headers)
913 (setq from (message-fetch-field "from"))
914 (goto-char (point-min))
915 (while (and gnus-article-x-face-command
918 ;; Check whether this face is censored.
919 (not gnus-article-x-face-too-ugly)
920 (and gnus-article-x-face-too-ugly from
921 (not (string-match gnus-article-x-face-too-ugly
923 ;; Has to be present.
924 (re-search-forward "^X-Face: " nil t))
925 ;; This used to try to do multiple faces (`while' instead of
926 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
927 ;; work (b) it can crash some versions of Emacs (c) are
928 ;; multiple faces really something to encourage?
929 (when (stringp gnus-article-x-face-command)
931 ;; We now have the area of the buffer where the X-Face is stored.
934 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
935 ;; We display the face.
936 (if (symbolp gnus-article-x-face-command)
937 ;; The command is a lisp function, so we call it.
938 (if (gnus-functionp gnus-article-x-face-command)
939 (funcall gnus-article-x-face-command beg end)
940 (error "%s is not a function" gnus-article-x-face-command))
941 ;; The command is a string, so we interpret the command
942 ;; as a, well, command, and fork it off.
943 (let ((process-connection-type nil))
944 (process-kill-without-query
946 "article-x-face" nil shell-file-name shell-command-switch
947 gnus-article-x-face-command))
948 (process-send-region "article-x-face" beg end)
949 (process-send-eof "article-x-face"))))))))))
951 (defun article-decode-mime-words ()
952 "Decode all MIME-encoded words in the article."
955 (set-buffer gnus-article-buffer)
956 (let ((inhibit-point-motion-hooks t)
958 (mail-decode-encoded-word-region (point-min) (point-max)))))
960 (defun article-decode-charset (&optional prompt)
961 "Decode charset-encoded text in the article.
962 If PROMPT (the prefix), prompt for a coding system to use."
966 (message-narrow-to-head)
967 (let* ((inhibit-point-motion-hooks t)
969 (ct (message-fetch-field "Content-Type" t))
970 (cte (message-fetch-field "Content-Transfer-Encoding" t))
971 (ctl (and ct (condition-case ()
972 (mail-header-parse-content-type ct)
976 (mm-read-coding-system "Charset to decode: "))
978 (mail-content-type-get ctl 'charset))
980 (gnus-group-find-parameter
981 gnus-newsgroup-name 'charset))))
983 (goto-char (point-max))
986 (narrow-to-region (point) (point-max))
988 (equal (car ctl) "text/plain"))
990 charset (and cte (intern (downcase
991 (gnus-strip-whitespace cte))))))))))
993 (defun article-decode-encoded-words ()
994 "Remove encoded-word encoding from headers."
995 (let ((inhibit-point-motion-hooks t)
996 (buffer-read-only nil))
998 (message-narrow-to-head)
999 (funcall gnus-decode-header-function (point-min) (point-max)))))
1001 (defun article-de-quoted-unreadable (&optional force)
1002 "Translate a quoted-printable-encoded article.
1003 If FORCE, decode the article whether it is marked as quoted-printable
1005 (interactive (list 'force))
1007 (let ((buffer-read-only nil)
1008 (type (gnus-fetch-field "content-transfer-encoding")))
1010 (and type (string-match "quoted-printable" (downcase type))))
1011 (goto-char (point-min))
1012 (search-forward "\n\n" nil 'move)
1013 (quoted-printable-decode-region (point) (point-max))))))
1015 (defun article-mime-decode-quoted-printable-buffer ()
1016 "Decode Quoted-Printable in the current buffer."
1017 (quoted-printable-decode-region (point-min) (point-max)))
1019 (defun article-hide-pgp (&optional arg)
1020 "Toggle hiding of any PGP headers and signatures in the current article.
1021 If given a negative prefix, always show; if given a positive prefix,
1023 (interactive (gnus-article-hidden-arg))
1024 (unless (gnus-article-check-hidden-text 'pgp arg)
1026 (let ((inhibit-point-motion-hooks t)
1027 buffer-read-only beg end)
1029 (goto-char (point-min))
1030 ;; Hide the "header".
1031 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1032 (delete-region (1+ (match-beginning 0)) (match-end 0))
1034 ;; Hide the actual signature.
1035 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1036 (setq end (1+ (match-beginning 0)))
1039 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1041 ;; Perhaps we shouldn't hide to the end of the buffer
1042 ;; if there is no end to the signature?
1044 ;; Hide "- " PGP quotation markers.
1046 (narrow-to-region beg end)
1047 (goto-char (point-min))
1048 (while (re-search-forward "^- " nil t)
1050 (match-beginning 0) (match-end 0)))
1052 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1054 (defun article-hide-pem (&optional arg)
1055 "Toggle hiding of any PEM headers and signatures in the current article.
1056 If given a negative prefix, always show; if given a positive prefix,
1058 (interactive (gnus-article-hidden-arg))
1059 (unless (gnus-article-check-hidden-text 'pem arg)
1061 (let (buffer-read-only end)
1063 (goto-char (point-min))
1064 ;; hide the horrendously ugly "header".
1065 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1068 (setq end (1+ (match-beginning 0)))
1069 (gnus-article-hide-text-type
1071 (if (search-forward "\n\n" nil t)
1075 ;; hide the trailer as well
1076 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1079 (gnus-article-hide-text-type
1080 (match-beginning 0) (match-end 0) 'pem))))))
1082 (defun article-hide-signature (&optional arg)
1083 "Hide the signature in the current article.
1084 If given a negative prefix, always show; if given a positive prefix,
1086 (interactive (gnus-article-hidden-arg))
1087 (unless (gnus-article-check-hidden-text 'signature arg)
1090 (let ((buffer-read-only nil))
1091 (when (gnus-article-narrow-to-signature)
1092 (gnus-article-hide-text-type
1093 (point-min) (point-max) 'signature)))))))
1095 (defun article-strip-leading-blank-lines ()
1096 "Remove all blank lines from the beginning of the article."
1099 (let ((inhibit-point-motion-hooks t)
1101 (goto-char (point-min))
1102 (when (search-forward "\n\n" nil t)
1103 (while (and (not (eobp))
1104 (looking-at "[ \t]*$"))
1105 (gnus-delete-line))))))
1107 (defun article-strip-multiple-blank-lines ()
1108 "Replace consecutive blank lines with one empty line."
1111 (let ((inhibit-point-motion-hooks t)
1113 ;; First make all blank lines empty.
1114 (goto-char (point-min))
1115 (search-forward "\n\n" nil t)
1116 (while (re-search-forward "^[ \t]+$" nil t)
1117 (unless (gnus-annotation-in-region-p
1118 (match-beginning 0) (match-end 0))
1119 (replace-match "" nil t)))
1120 ;; Then replace multiple empty lines with a single empty line.
1121 (goto-char (point-min))
1122 (search-forward "\n\n" nil t)
1123 (while (re-search-forward "\n\n\n+" nil t)
1124 (unless (gnus-annotation-in-region-p
1125 (match-beginning 0) (match-end 0))
1126 (replace-match "\n\n" t t))))))
1128 (defun article-strip-leading-space ()
1129 "Remove all white space from the beginning of the lines in the article."
1132 (let ((inhibit-point-motion-hooks t)
1134 (goto-char (point-min))
1135 (search-forward "\n\n" nil t)
1136 (while (re-search-forward "^[ \t]+" nil t)
1137 (replace-match "" t t)))))
1139 (defun article-strip-blank-lines ()
1140 "Strip leading, trailing and multiple blank lines."
1142 (article-strip-leading-blank-lines)
1143 (article-remove-trailing-blank-lines)
1144 (article-strip-multiple-blank-lines))
1146 (defun article-strip-all-blank-lines ()
1147 "Strip all blank lines."
1150 (let ((inhibit-point-motion-hooks t)
1152 (goto-char (point-min))
1153 (search-forward "\n\n" nil t)
1154 (while (re-search-forward "^[ \t]*\n" nil t)
1155 (replace-match "" t t)))))
1157 (defvar mime::preview/content-list)
1158 (defvar mime::preview-content-info/point-min)
1159 (defun gnus-article-narrow-to-signature ()
1160 "Narrow to the signature; return t if a signature is found, else nil."
1162 (let ((inhibit-point-motion-hooks t))
1163 (when (and (boundp 'mime::preview/content-list)
1164 mime::preview/content-list)
1165 ;; We have a MIMEish article, so we use the MIME data to narrow.
1166 (let ((pcinfo (car (last mime::preview/content-list))))
1169 (funcall (intern "mime::preview-content-info/point-min") pcinfo)
1172 (when (gnus-article-search-signature)
1174 ;; Check whether we have some limits to what we consider
1175 ;; to be a signature.
1176 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1177 (list gnus-signature-limit)))
1179 (while (setq limit (pop limits))
1180 (if (or (and (integerp limit)
1181 (< (- (point-max) (point)) limit))
1183 (< (count-lines (point) (point-max)) limit))
1184 (and (gnus-functionp limit)
1186 (and (stringp limit)
1187 (not (re-search-forward limit nil t))))
1188 () ; This limit did not succeed.
1192 (narrow-to-region (point) (point-max))
1195 (defun gnus-article-search-signature ()
1196 "Search the current buffer for the signature separator.
1197 Put point at the beginning of the signature separator."
1198 (let ((cur (point)))
1199 (goto-char (point-max))
1200 (if (if (stringp gnus-signature-separator)
1201 (re-search-backward gnus-signature-separator nil t)
1202 (let ((seps gnus-signature-separator))
1204 (not (re-search-backward (car seps) nil t)))
1212 (autoload 'w3-display "w3-parse")
1213 (autoload 'w3-do-setup "w3" "" t)
1214 (autoload 'w3-region "w3-display" "" t))
1216 (defun gnus-article-treat-html ()
1219 (let ((cbuf (current-buffer)))
1220 (set-buffer gnus-article-buffer)
1221 (let (buf buffer-read-only b e)
1223 (goto-char (point-min))
1225 (if (search-forward "\n\n" nil t)
1228 (setq e (point-max)))
1230 (insert-buffer-substring gnus-article-buffer b e)
1232 (save-window-excursion
1233 (w3-region (point-min) (point-max))
1234 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1236 (delete-region (point-min) (point-max))
1239 (goto-char (point-min))
1240 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1241 (set-buffer cbuf))))
1243 (defun gnus-article-hidden-arg ()
1244 "Return the current prefix arg as a number, or 0 if no prefix."
1245 (list (if current-prefix-arg
1246 (prefix-numeric-value current-prefix-arg)
1249 (defun gnus-article-check-hidden-text (type arg)
1250 "Return nil if hiding is necessary.
1251 Arg can be nil or a number. Nil and positive means hide, negative
1252 means show, 0 means toggle."
1256 (let ((hide (gnus-article-hidden-text-p type)))
1262 (gnus-article-show-hidden-text type))
1264 (if (eq hide 'hidden)
1265 (gnus-article-show-hidden-text type)
1268 (defun gnus-article-hidden-text-p (type)
1269 "Say whether the current buffer contains hidden text of type TYPE."
1270 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1272 (not (get-text-property pos 'invisible)))
1274 (text-property-any (1+ pos) (point-max) 'article-type type)))
1279 (defun gnus-article-show-hidden-text (type &optional hide)
1280 "Show all hidden text of type TYPE.
1281 If HIDE, hide the text instead."
1283 (let ((buffer-read-only nil)
1284 (inhibit-point-motion-hooks t)
1287 (while (setq beg (text-property-any end (point-max) 'article-type type))
1290 (text-property-not-all beg (point-max) 'article-type type)
1293 (gnus-article-hide-text beg end gnus-hidden-properties)
1294 (gnus-article-unhide-text beg end))
1298 (defconst article-time-units
1299 `((year . ,(* 365.25 24 60 60))
1300 (week . ,(* 7 24 60 60))
1301 (day . ,(* 24 60 60))
1305 "Mapping from time units to seconds.")
1307 (defun article-date-ut (&optional type highlight header)
1308 "Convert DATE date to universal time in the current article.
1309 If TYPE is `local', convert to local time; if it is `lapsed', output
1310 how much time has lapsed since DATE."
1311 (interactive (list 'ut t))
1312 (let* ((header (or header
1313 (mail-header-date gnus-current-headers)
1314 (message-fetch-field "date")
1316 (date (if (vectorp header) (mail-header-date header)
1318 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1319 (inhibit-point-motion-hooks t)
1320 bface eface newline)
1321 (when (and date (not (string= date "")))
1324 (nnheader-narrow-to-headers)
1325 (let ((buffer-read-only nil))
1326 ;; Delete any old Date headers.
1327 (if (re-search-forward date-regexp nil t)
1329 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1330 eface (get-text-property (1- (gnus-point-at-eol))
1332 (delete-region (progn (beginning-of-line) (point))
1333 (progn (end-of-line) (point)))
1334 (beginning-of-line))
1335 (goto-char (point-max))
1337 (insert (article-make-date-line date type))
1340 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1341 (put-text-property (match-beginning 1) (1+ (match-end 1))
1343 (put-text-property (match-beginning 2) (match-end 2)
1347 (insert "\n"))))))))
1349 (defun article-make-date-line (date type)
1350 "Return a DATE line of TYPE."
1351 (let ((time (condition-case ()
1355 ;; Convert to the local timezone. We have to slap a
1356 ;; `condition-case' round the calls to the timezone
1357 ;; functions since they aren't particularly resistant to
1360 (let ((tz (car (current-time-zone))))
1361 (format "Date: %s %s%04d" (current-time-string time)
1362 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1363 ;; Convert to Universal Time.
1366 (current-time-string
1367 (let* ((e (parse-time-string date))
1368 (tm (apply 'encode-time e))
1370 (ls (- (cadr tm) (car (current-time-zone)))))
1371 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1372 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1375 ;; Get the original date from the article.
1376 ((eq type 'original)
1377 (concat "Date: " (if (string-match "\n+$" date)
1378 (substring date 0 (match-beginning 0))
1380 ;; Let the user define the format.
1382 (if (gnus-functionp gnus-article-time-format)
1383 (funcall gnus-article-time-format time)
1386 (format-time-string gnus-article-time-format time))))
1391 (format-time-string "%Y%M%DT%h%m%s" time)))
1392 ;; Do an X-Sent lapsed format.
1394 ;; If the date is seriously mangled, the timezone functions are
1395 ;; liable to bug out, so we ignore all errors.
1396 (let* ((now (current-time))
1397 (real-time (subtract-time now time))
1398 (real-sec (and real-time
1399 (+ (* (float (car real-time)) 65536)
1401 (sec (and real-time (abs real-sec)))
1411 ;; This is a bit convoluted, but basically we go
1412 ;; through the time units for years, weeks, etc,
1413 ;; and divide things to see whether that results
1414 ;; in positive answers.
1417 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1418 ;; The (remaining) seconds are too few to
1419 ;; be divided into this time unit.
1421 ;; It's big enough, so we output it.
1422 (setq sec (- sec (* num (cdr unit))))
1424 (concat (if prev ", " "") (int-to-string
1426 " " (symbol-name (car unit))
1427 (if (> num 1) "s" ""))
1429 article-time-units "")
1430 ;; If dates are odd, then it might appear like the
1431 ;; article was sent in the future.
1434 " in the future"))))))
1436 (error "Unknown conversion type: %s" type)))))
1438 (defun article-date-local (&optional highlight)
1439 "Convert the current article date to the local timezone."
1440 (interactive (list t))
1441 (article-date-ut 'local highlight))
1443 (defun article-date-original (&optional highlight)
1444 "Convert the current article date to what it was originally.
1445 This is only useful if you have used some other date conversion
1446 function and want to see what the date was before converting."
1447 (interactive (list t))
1448 (article-date-ut 'original highlight))
1450 (defun article-date-lapsed (&optional highlight)
1451 "Convert the current article date to time lapsed since it was sent."
1452 (interactive (list t))
1453 (article-date-ut 'lapsed highlight))
1455 (defun article-update-date-lapsed ()
1456 "Function to be run from a timer to update the lapsed time line."
1457 (let (deactivate-mark)
1460 (when (and (gnus-buffer-live-p gnus-article-buffer)
1461 (get-buffer-window gnus-article-buffer))
1462 (set-buffer gnus-article-buffer)
1463 (goto-char (point-min))
1464 (when (re-search-forward "^X-Sent:" nil t)
1465 (article-date-lapsed t)))))))
1467 (defun gnus-start-date-timer (&optional n)
1468 "Start a timer to update the X-Sent header in the article buffers.
1469 The numerical prefix says how frequently (in seconds) the function
1474 (gnus-stop-date-timer)
1475 (setq article-lapsed-timer
1476 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1478 (defun gnus-stop-date-timer ()
1479 "Stop the X-Sent timer."
1481 (when article-lapsed-timer
1482 (nnheader-cancel-timer article-lapsed-timer)
1483 (setq article-lapsed-timer nil)))
1485 (defun article-date-user (&optional highlight)
1486 "Convert the current article date to the user-defined format.
1487 This format is defined by the `gnus-article-time-format' variable."
1488 (interactive (list t))
1489 (article-date-ut 'user highlight))
1491 (defun article-date-iso8601 (&optional highlight)
1492 "Convert the current article date to ISO8601."
1493 (interactive (list t))
1494 (article-date-ut 'iso8601 highlight))
1496 (defun article-show-all ()
1497 "Show all hidden text in the article buffer."
1500 (let ((buffer-read-only nil))
1501 (gnus-article-unhide-text (point-min) (point-max)))))
1503 (defun article-emphasize (&optional arg)
1504 "Emphasize text according to `gnus-emphasis-alist'."
1505 (interactive (gnus-article-hidden-arg))
1506 (unless (gnus-article-check-hidden-text 'emphasis arg)
1508 (let ((alist gnus-emphasis-alist)
1509 (buffer-read-only nil)
1510 (props (append '(article-type emphasis)
1511 gnus-hidden-properties))
1512 regexp elem beg invisible visible face)
1513 (goto-char (point-min))
1514 (search-forward "\n\n" nil t)
1516 (while (setq elem (pop alist))
1518 (setq regexp (car elem)
1519 invisible (nth 1 elem)
1520 visible (nth 2 elem)
1522 (while (re-search-forward regexp nil t)
1523 (when (and (match-beginning visible) (match-beginning invisible))
1524 (gnus-article-hide-text
1525 (match-beginning invisible) (match-end invisible) props)
1526 (gnus-article-unhide-text-type
1527 (match-beginning visible) (match-end visible) 'emphasis)
1528 (gnus-put-text-property-excluding-newlines
1529 (match-beginning visible) (match-end visible) 'face face)
1530 (goto-char (match-end invisible)))))))))
1532 (defvar gnus-summary-article-menu)
1533 (defvar gnus-summary-post-menu)
1535 ;;; Saving functions.
1537 (defun gnus-article-save (save-buffer file &optional num)
1538 "Save the currently selected article."
1539 (unless gnus-save-all-headers
1540 ;; Remove headers according to `gnus-saved-headers'.
1541 (let ((gnus-visible-headers
1542 (or gnus-saved-headers gnus-visible-headers))
1543 (gnus-article-buffer save-buffer))
1545 (set-buffer save-buffer)
1546 (article-hide-headers 1 t))))
1547 (save-window-excursion
1548 (if (not gnus-default-article-saver)
1549 (error "No default saver is defined")
1550 ;; !!! Magic! The saving functions all save
1551 ;; `gnus-save-article-buffer' (or so they think), but we
1552 ;; bind that variable to our save-buffer.
1553 (set-buffer gnus-article-buffer)
1554 (let* ((gnus-save-article-buffer save-buffer)
1557 ((not gnus-prompt-before-saving) 'default)
1558 ((eq gnus-prompt-before-saving 'always) nil)
1560 (gnus-number-of-articles-to-be-saved
1561 (when (eq gnus-prompt-before-saving t)
1563 (set-buffer gnus-article-current-summary)
1564 (funcall gnus-default-article-saver filename)))))
1566 (defun gnus-read-save-file-name (prompt &optional filename
1567 function group headers variable)
1569 (funcall function group headers (symbol-value variable)))
1574 ((eq filename 'default)
1580 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1583 (if (and gnus-number-of-articles-to-be-saved
1584 (> gnus-number-of-articles-to-be-saved 1))
1585 (format "these %d articles"
1586 gnus-number-of-articles-to-be-saved)
1589 ;; Let the split methods have their say.
1591 ;; No split name was found.
1594 (concat prompt " (default "
1595 (file-name-nondirectory default-name) ") ")
1596 (file-name-directory default-name)
1598 ;; A single group name is returned.
1599 ((stringp split-name)
1601 (funcall function split-name headers
1602 (symbol-value variable)))
1604 (concat prompt " (default "
1605 (file-name-nondirectory default-name) ") ")
1606 (file-name-directory default-name)
1608 ;; A single split name was found
1609 ((= 1 (length split-name))
1610 (let* ((name (expand-file-name
1611 (car split-name) gnus-article-save-directory))
1612 (dir (cond ((file-directory-p name)
1613 (file-name-as-directory name))
1614 ((file-exists-p name) name)
1615 (t gnus-article-save-directory))))
1617 (concat prompt " (default " name ") ")
1619 ;; A list of splits was found.
1621 (setq split-name (nreverse split-name))
1623 (let ((file-name-history
1624 (nconc split-name file-name-history)))
1628 (concat prompt " (`M-p' for defaults) ")
1629 gnus-article-save-directory
1631 gnus-article-save-directory)))
1632 (car (push result file-name-history)))))))
1633 ;; Create the directory.
1634 (gnus-make-directory (file-name-directory file))
1635 ;; If we have read a directory, we append the default file name.
1636 (when (file-directory-p file)
1637 (setq file (concat (file-name-as-directory file)
1638 (file-name-nondirectory default-name))))
1639 ;; Possibly translate some characters.
1640 (nnheader-translate-file-chars file)))))
1641 (gnus-make-directory (file-name-directory result))
1642 (set variable result)))
1644 (defun gnus-article-archive-name (group)
1645 "Return the first instance of an \"Archive-name\" in the current buffer."
1646 (let ((case-fold-search t))
1647 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1648 (nnheader-concat gnus-article-save-directory
1649 (match-string 1)))))
1651 (defun gnus-article-nndoc-name (group)
1652 "If GROUP is an nndoc group, return the name of the parent group."
1653 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1654 (gnus-group-get-parameter group 'save-article-group)))
1656 (defun gnus-summary-save-in-rmail (&optional filename)
1657 "Append this article to Rmail file.
1658 Optional argument FILENAME specifies file name.
1659 Directory to save to is default to `gnus-article-save-directory'."
1660 (setq filename (gnus-read-save-file-name
1661 "Save %s in rmail file:" filename
1662 gnus-rmail-save-name gnus-newsgroup-name
1663 gnus-current-headers 'gnus-newsgroup-last-rmail))
1664 (gnus-eval-in-buffer-window gnus-save-article-buffer
1668 (rmail-output-to-rmail-file filename))))
1671 (defun gnus-summary-save-in-mail (&optional filename)
1672 "Append this article to Unix mail file.
1673 Optional argument FILENAME specifies file name.
1674 Directory to save to is default to `gnus-article-save-directory'."
1675 (setq filename (gnus-read-save-file-name
1676 "Save %s in Unix mail file:" filename
1677 gnus-mail-save-name gnus-newsgroup-name
1678 gnus-current-headers 'gnus-newsgroup-last-mail))
1679 (gnus-eval-in-buffer-window gnus-save-article-buffer
1683 (if (and (file-readable-p filename)
1684 (mail-file-babyl-p filename))
1685 (rmail-output-to-rmail-file filename t)
1686 (gnus-output-to-mail filename)))))
1689 (defun gnus-summary-save-in-file (&optional filename overwrite)
1690 "Append this article to file.
1691 Optional argument FILENAME specifies file name.
1692 Directory to save to is default to `gnus-article-save-directory'."
1693 (setq filename (gnus-read-save-file-name
1694 "Save %s in file:" filename
1695 gnus-file-save-name gnus-newsgroup-name
1696 gnus-current-headers 'gnus-newsgroup-last-file))
1697 (gnus-eval-in-buffer-window gnus-save-article-buffer
1701 (when (and overwrite
1702 (file-exists-p filename))
1703 (delete-file filename))
1704 (gnus-output-to-file filename))))
1707 (defun gnus-summary-write-to-file (&optional filename)
1708 "Write this article to a file.
1709 Optional argument FILENAME specifies file name.
1710 The directory to save in defaults to `gnus-article-save-directory'."
1711 (gnus-summary-save-in-file nil t))
1713 (defun gnus-summary-save-body-in-file (&optional filename)
1714 "Append this article body to a file.
1715 Optional argument FILENAME specifies file name.
1716 The directory to save in defaults to `gnus-article-save-directory'."
1717 (setq filename (gnus-read-save-file-name
1718 "Save %s body in file:" filename
1719 gnus-file-save-name gnus-newsgroup-name
1720 gnus-current-headers 'gnus-newsgroup-last-file))
1721 (gnus-eval-in-buffer-window gnus-save-article-buffer
1725 (goto-char (point-min))
1726 (when (search-forward "\n\n" nil t)
1727 (narrow-to-region (point) (point-max)))
1728 (gnus-output-to-file filename))))
1731 (defun gnus-summary-save-in-pipe (&optional command)
1732 "Pipe this article to subprocess."
1734 (cond ((eq command 'default)
1735 gnus-last-shell-command)
1739 "Shell command on %s: "
1740 (if (and gnus-number-of-articles-to-be-saved
1741 (> gnus-number-of-articles-to-be-saved 1))
1742 (format "these %d articles"
1743 gnus-number-of-articles-to-be-saved)
1745 gnus-last-shell-command))))
1746 (when (string-equal command "")
1747 (setq command gnus-last-shell-command))
1748 (gnus-eval-in-buffer-window gnus-article-buffer
1751 (shell-command-on-region (point-min) (point-max) command nil)))
1752 (setq gnus-last-shell-command command))
1754 ;;; Article file names when saving.
1756 (defun gnus-capitalize-newsgroup (newsgroup)
1757 "Capitalize NEWSGROUP name."
1758 (when (not (zerop (length newsgroup)))
1759 (concat (char-to-string (upcase (aref newsgroup 0)))
1760 (substring newsgroup 1))))
1762 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1763 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1764 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1765 Otherwise, it is like ~/News/news/group/num."
1768 (concat (if (gnus-use-long-file-name 'not-save)
1769 (gnus-capitalize-newsgroup newsgroup)
1770 (gnus-newsgroup-directory-form newsgroup))
1771 "/" (int-to-string (mail-header-number headers)))
1772 gnus-article-save-directory)))
1774 (string-equal (file-name-directory default)
1775 (file-name-directory last-file))
1776 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1778 (or last-file default))))
1780 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1781 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1782 If variable `gnus-use-long-file-name' is non-nil, it is
1783 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1786 (concat (if (gnus-use-long-file-name 'not-save)
1788 (gnus-newsgroup-directory-form newsgroup))
1789 "/" (int-to-string (mail-header-number headers)))
1790 gnus-article-save-directory)))
1792 (string-equal (file-name-directory default)
1793 (file-name-directory last-file))
1794 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1796 (or last-file default))))
1798 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1799 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1800 If variable `gnus-use-long-file-name' is non-nil, it is
1801 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1804 (if (gnus-use-long-file-name 'not-save)
1805 (gnus-capitalize-newsgroup newsgroup)
1806 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1807 gnus-article-save-directory)))
1809 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1810 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1811 If variable `gnus-use-long-file-name' is non-nil, it is
1812 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1815 (if (gnus-use-long-file-name 'not-save)
1817 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1818 gnus-article-save-directory)))
1825 (setq afunc (car func)
1828 gfunc (intern (format "gnus-%s" func))))
1830 (if (not (fboundp afunc))
1832 `(lambda (&optional interactive &rest args)
1833 ,(documentation afunc t)
1834 (interactive (list t))
1836 (set-buffer gnus-article-buffer)
1838 (call-interactively ',afunc)
1839 (apply ',afunc args))))))))
1840 '(article-hide-headers
1841 article-hide-boring-headers
1842 article-treat-overstrike
1843 (article-fill . gnus-article-word-wrap)
1845 article-display-x-face
1846 article-de-quoted-unreadable
1847 article-mime-decode-quoted-printable
1850 article-hide-signature
1851 article-remove-trailing-blank-lines
1852 article-strip-leading-blank-lines
1853 article-strip-multiple-blank-lines
1854 article-strip-leading-space
1855 article-strip-blank-lines
1856 article-strip-all-blank-lines
1858 article-date-iso8601
1859 article-date-original
1861 article-decode-mime-words
1862 article-decode-charset
1863 article-decode-encoded-words
1867 article-treat-dumbquotes
1868 (article-show-all . gnus-article-show-all-headers))))
1871 ;;; Gnus article mode
1874 (put 'gnus-article-mode 'mode-class 'special)
1876 (set-keymap-parent gnus-article-mode-map widget-keymap)
1878 (gnus-define-keys gnus-article-mode-map
1879 " " gnus-article-goto-next-page
1880 "\177" gnus-article-goto-prev-page
1881 [delete] gnus-article-goto-prev-page
1882 "\C-c^" gnus-article-refer-article
1883 "h" gnus-article-show-summary
1884 "s" gnus-article-show-summary
1885 "\C-c\C-m" gnus-article-mail
1886 "?" gnus-article-describe-briefly
1887 "e" gnus-article-edit
1888 "<" beginning-of-buffer
1890 "\C-c\C-i" gnus-info-find-node
1893 gnus-mouse-2 'widget-button-click
1895 "\C-d" gnus-article-read-summary-keys
1896 "\M-*" gnus-article-read-summary-keys
1897 "\M-#" gnus-article-read-summary-keys
1898 "\M-^" gnus-article-read-summary-keys
1899 "\M-g" gnus-article-read-summary-keys)
1901 (substitute-key-definition
1902 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
1904 (defun gnus-article-make-menu-bar ()
1905 (gnus-turn-off-edit-menu 'article)
1906 (unless (boundp 'gnus-article-article-menu)
1908 gnus-article-article-menu gnus-article-mode-map ""
1910 ["Scroll forwards" gnus-article-goto-next-page t]
1911 ["Scroll backwards" gnus-article-goto-prev-page t]
1912 ["Show summary" gnus-article-show-summary t]
1913 ["Fetch Message-ID at point" gnus-article-refer-article t]
1914 ["Mail to address at point" gnus-article-mail t]
1915 ["Send a bug report" gnus-bug t]))
1918 gnus-article-treatment-menu gnus-article-mode-map ""
1920 ["Hide headers" gnus-article-hide-headers t]
1921 ["Hide signature" gnus-article-hide-signature t]
1922 ["Hide citation" gnus-article-hide-citation t]
1923 ["Treat overstrike" gnus-article-treat-overstrike t]
1924 ["Remove carriage return" gnus-article-remove-cr t]
1925 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
1927 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
1929 (when (boundp 'gnus-summary-post-menu)
1930 (define-key gnus-article-mode-map [menu-bar post]
1931 (cons "Post" gnus-summary-post-menu)))
1933 (gnus-run-hooks 'gnus-article-menu-hook)))
1935 (defun gnus-article-mode ()
1936 "Major mode for displaying an article.
1938 All normal editing commands are switched off.
1940 The following commands are available in addition to all summary mode
1942 \\<gnus-article-mode-map>
1943 \\[gnus-article-next-page]\t Scroll the article one page forwards
1944 \\[gnus-article-prev-page]\t Scroll the article one page backwards
1945 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
1946 \\[gnus-article-show-summary]\t Display the summary buffer
1947 \\[gnus-article-mail]\t Send a reply to the address near point
1948 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
1949 \\[gnus-info-find-node]\t Go to the Gnus info node"
1951 (when (gnus-visual-p 'article-menu 'menu)
1952 (gnus-article-make-menu-bar))
1953 (gnus-simplify-mode-line)
1954 (setq mode-name "Article")
1955 (setq major-mode 'gnus-article-mode)
1956 (make-local-variable 'minor-mode-alist)
1957 (use-local-map gnus-article-mode-map)
1958 (gnus-update-format-specifications nil 'article-mode)
1959 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
1960 (make-local-variable 'gnus-page-broken)
1961 (make-local-variable 'gnus-button-marker-list)
1962 (make-local-variable 'gnus-article-current-summary)
1963 (make-local-variable 'gnus-article-mime-handles)
1964 (make-local-variable 'gnus-article-decoded-p)
1965 (gnus-set-default-directory)
1966 (buffer-disable-undo)
1967 (setq buffer-read-only t)
1968 (set-syntax-table gnus-article-mode-syntax-table)
1969 (mm-enable-multibyte)
1970 (gnus-run-hooks 'gnus-article-mode-hook))
1972 (defun gnus-article-setup-buffer ()
1973 "Initialize the article buffer."
1974 (let* ((name (if gnus-single-article-buffer "*Article*"
1975 (concat "*Article " gnus-newsgroup-name "*")))
1977 (progn (string-match "\\*Article" name)
1978 (concat " *Original Article"
1979 (substring name (match-end 0))))))
1980 (setq gnus-article-buffer name)
1981 (setq gnus-original-article-buffer original)
1982 ;; This might be a variable local to the summary buffer.
1983 (unless gnus-single-article-buffer
1985 (set-buffer gnus-summary-buffer)
1986 (setq gnus-article-buffer name)
1987 (setq gnus-original-article-buffer original)
1988 (gnus-set-global-variables)))
1989 ;; Init original article buffer.
1991 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
1992 (mm-enable-multibyte)
1993 (setq major-mode 'gnus-original-article-mode)
1994 (make-local-variable 'gnus-original-article))
1995 (if (get-buffer name)
1998 (buffer-disable-undo)
1999 (setq buffer-read-only t)
2000 (unless (eq major-mode 'gnus-article-mode)
2001 (gnus-article-mode))
2004 (set-buffer (gnus-get-buffer-create name))
2006 (make-local-variable 'gnus-summary-buffer)
2007 (current-buffer)))))
2009 ;; Set article window start at LINE, where LINE is the number of lines
2010 ;; from the head of the article.
2011 (defun gnus-article-set-window-start (&optional line)
2013 (get-buffer-window gnus-article-buffer t)
2015 (set-buffer gnus-article-buffer)
2016 (goto-char (point-min))
2019 (gnus-message 6 "Moved to bookmark")
2020 (search-forward "\n\n" nil t)
2024 (defun gnus-article-prepare (article &optional all-headers header)
2025 "Prepare ARTICLE in article mode buffer.
2026 ARTICLE should either be an article number or a Message-ID.
2027 If ARTICLE is an id, HEADER should be the article headers.
2028 If ALL-HEADERS is non-nil, no headers are hidden."
2030 ;; Make sure we start in a summary buffer.
2031 (unless (eq major-mode 'gnus-summary-mode)
2032 (set-buffer gnus-summary-buffer))
2033 (setq gnus-summary-buffer (current-buffer))
2034 (let* ((gnus-article (if header (mail-header-number header) article))
2035 (summary-buffer (current-buffer))
2036 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2037 (group gnus-newsgroup-name)
2040 (gnus-article-setup-buffer)
2041 (set-buffer gnus-article-buffer)
2042 ;; Deactivate active regions.
2043 (when (and (boundp 'transient-mark-mode)
2044 transient-mark-mode)
2045 (setq mark-active nil))
2046 (if (not (setq result (let ((buffer-read-only nil))
2047 (gnus-request-article-this-buffer
2049 ;; There is no such article.
2051 (when (and (numberp article)
2052 (not (memq article gnus-newsgroup-sparse)))
2053 (setq gnus-article-current
2054 (cons gnus-newsgroup-name article))
2055 (set-buffer gnus-summary-buffer)
2056 (setq gnus-current-article article)
2057 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2059 (gnus-summary-set-agent-mark article)
2060 (message "Message marked for downloading"))
2061 (gnus-summary-mark-article article gnus-canceled-mark)
2062 (unless (memq article gnus-newsgroup-sparse)
2064 "No such article (may have expired or been canceled)")))))
2065 (if (or (eq result 'pseudo)
2066 (eq result 'nneething))
2069 (set-buffer summary-buffer)
2070 (push article gnus-newsgroup-history)
2071 (setq gnus-last-article gnus-current-article
2072 gnus-current-article 0
2073 gnus-current-headers nil
2074 gnus-article-current nil)
2075 (if (eq result 'nneething)
2076 (gnus-configure-windows 'summary)
2077 (gnus-configure-windows 'article))
2078 (gnus-set-global-variables))
2079 (gnus-set-mode-line 'article))
2080 ;; The result from the `request' was an actual article -
2081 ;; or at least some text that is now displayed in the
2083 (when (and (numberp article)
2084 (not (eq article gnus-current-article)))
2085 ;; Seems like a new article has been selected.
2086 ;; `gnus-current-article' must be an article number.
2088 (set-buffer summary-buffer)
2089 (push article gnus-newsgroup-history)
2090 (setq gnus-last-article gnus-current-article
2091 gnus-current-article article
2092 gnus-current-headers
2093 (gnus-summary-article-header gnus-current-article)
2094 gnus-article-current
2095 (cons gnus-newsgroup-name gnus-current-article))
2096 (unless (vectorp gnus-current-headers)
2097 (setq gnus-current-headers nil))
2098 (gnus-summary-goto-subject gnus-current-article)
2099 (when (gnus-summary-show-thread)
2100 ;; If the summary buffer really was folded, the
2101 ;; previous goto may not actually have gone to
2102 ;; the right article, but the thread root instead.
2104 (gnus-summary-goto-subject gnus-current-article))
2105 (gnus-run-hooks 'gnus-mark-article-hook)
2106 (gnus-set-mode-line 'summary)
2107 (when (gnus-visual-p 'article-highlight 'highlight)
2108 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2109 ;; Set the global newsgroup variables here.
2110 ;; Suggested by Jim Sisolak
2111 ;; <sisolak@trans4.neep.wisc.edu>.
2112 (gnus-set-global-variables)
2113 (setq gnus-have-all-headers
2114 (or all-headers gnus-show-all-headers))))
2115 (when (or (numberp article)
2117 (gnus-article-prepare-display)
2119 (goto-char (point-min))
2120 (setq gnus-page-broken
2121 (when gnus-break-pages
2122 (gnus-narrow-to-page)
2124 (gnus-set-mode-line 'article)
2125 (gnus-configure-windows 'article)
2126 (goto-char (point-min))
2127 (search-forward "\n\n" nil t)
2128 (set-window-point (get-buffer-window (current-buffer)) (point))
2131 (defun gnus-article-prepare-display ()
2132 "Make the current buffer look like a nice article."
2133 ;; Hooks for getting information from the article.
2134 ;; This hook must be called before being narrowed.
2135 (let ((gnus-article-buffer (current-buffer))
2137 (unless (eq major-mode 'gnus-article-mode)
2138 (gnus-article-mode))
2139 (gnus-run-hooks 'gnus-tmp-internal-hook)
2140 (gnus-run-hooks 'gnus-article-prepare-hook)
2141 (when gnus-display-mime-function
2142 (let ((url-standalone-mode (not gnus-plugged)))
2143 (funcall gnus-display-mime-function)))
2144 ;; Perform the article display hooks.
2145 (gnus-run-hooks 'gnus-article-display-hook)))
2148 ;;; Gnus MIME viewing functions
2151 (defvar gnus-mime-button-line-format "%{%([%t%d%n]%)%}\n"
2152 "The following specs can be used:
2154 %n The `name' parameter
2155 %d The description, if any
2156 %l The length of the encoded part")
2158 (defvar gnus-mime-button-line-format-alist
2159 '((?t gnus-tmp-type ?s)
2160 (?n gnus-tmp-name ?s)
2161 (?d gnus-tmp-description ?s)
2162 (?l gnus-tmp-length ?d)))
2164 (defvar gnus-mime-button-map nil)
2165 (unless gnus-mime-button-map
2166 (setq gnus-mime-button-map (copy-keymap gnus-article-mode-map))
2167 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2168 (define-key gnus-mime-button-map "\r" 'gnus-article-press-button)
2169 (define-key gnus-mime-button-map "\M-\r" 'gnus-mime-view-part)
2170 (define-key gnus-mime-button-map "v" 'gnus-mime-view-part)
2171 (define-key gnus-mime-button-map "o" 'gnus-mime-save-part)
2172 (define-key gnus-mime-button-map "c" 'gnus-mime-copy-part)
2173 (define-key gnus-mime-button-map "i" 'gnus-mime-inline-part)
2174 (define-key gnus-mime-button-map "|" 'gnus-mime-pipe-part))
2176 (defun gnus-mime-save-part ()
2177 "Save the MIME part under point."
2179 (let ((data (get-text-property (point) 'gnus-data)))
2180 (mm-save-part data)))
2182 (defun gnus-mime-pipe-part ()
2183 "Pipe the MIME part under point to a process."
2185 (let ((data (get-text-property (point) 'gnus-data)))
2186 (mm-pipe-part data)))
2188 (defun gnus-mime-view-part ()
2189 "Interactively choose a view method for the MIME part under point."
2191 (let ((data (get-text-property (point) 'gnus-data))
2192 (url-standalone-mode (not gnus-plugged)))
2193 (mm-interactively-view-part data)))
2195 (defun gnus-mime-copy-part ()
2196 "Put the the MIME part under point into a new buffer."
2198 (let* ((data (get-text-property (point) 'gnus-data))
2199 (contents (mm-get-part data)))
2200 (switch-to-buffer (generate-new-buffer "*decoded*"))
2202 (goto-char (point-min))))
2204 (defun gnus-mime-inline-part ()
2205 "Insert the MIME part under point into the current buffer."
2207 (let* ((data (get-text-property (point) 'gnus-data))
2208 (contents (mm-get-part data))
2209 (url-standalone-mode (not gnus-plugged))
2212 (if (mm-handle-undisplayer data)
2213 (mm-remove-part data)
2215 (mm-insert-inline data contents)
2218 (defun gnus-insert-mime-button (handle)
2219 (let ((gnus-tmp-name (mail-content-type-get (mm-handle-type handle) 'name))
2220 (gnus-tmp-type (car (mm-handle-type handle)))
2221 (gnus-tmp-description (mm-handle-description handle))
2222 (gnus-tmp-length (save-excursion
2223 (set-buffer (mm-handle-buffer handle))
2228 (concat " (" gnus-tmp-name ")")
2230 (setq gnus-tmp-description
2231 (if gnus-tmp-description
2232 (concat " (" gnus-tmp-description ")")
2236 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2237 `(local-map ,gnus-mime-button-map
2238 keymap ,gnus-mime-button-map
2239 gnus-callback mm-display-part
2242 (widget-convert-button 'link b e :action 'gnus-widget-press-button
2243 :button-keymap gnus-widget-button-keymap)))
2245 (defun gnus-widget-press-button (elems el)
2246 (goto-char (widget-get elems :from))
2247 (let ((url-standalone-mode (not gnus-plugged)))
2248 (gnus-article-press-button)))
2250 (defun gnus-display-mime ()
2251 "Insert MIME buttons in the buffer."
2254 (mail-narrow-to-head)
2255 (when (setq ct (mail-fetch-field "content-type"))
2256 (setq ctl (condition-case ()
2257 (mail-header-parse-content-type ct) (error nil)))))
2258 (let* ((handles (mm-dissect-buffer))
2259 handle name type b e)
2260 (mapcar 'mm-destroy-part gnus-article-mime-handles)
2261 (setq gnus-article-mime-handles handles)
2263 (goto-char (point-min))
2264 (search-forward "\n\n" nil t)
2265 (delete-region (point) (point-max))
2266 (if (not (equal (car ctl) "multipart/alternative"))
2267 (while (setq handle (pop handles))
2268 (gnus-insert-mime-button handle)
2270 (when (and (mm-automatic-display-p
2271 (car (mm-handle-type handle)))
2272 (or (not (mm-handle-disposition handle))
2273 (equal (car (mm-handle-disposition handle))
2276 (mm-display-part handle t)
2277 (goto-char (point-max))))
2278 ;; Here we have multipart/alternative
2279 (gnus-mime-display-alternative handles))))))
2281 (defun gnus-mime-display-alternative (handles &optional preferred)
2282 (let* ((preferred (mm-preferred-alternative handles preferred))
2284 handle buffer-read-only)
2285 (goto-char (point-min))
2286 (search-forward "\n\n" nil t)
2287 (delete-region (point) (point-max))
2288 (mapcar 'mm-remove-part gnus-article-mime-handles)
2289 (setq gnus-article-mime-handles handles)
2290 (while (setq handle (pop handles))
2291 (gnus-add-text-properties
2294 (insert (format "[%c] %-18s"
2295 (if (equal handle preferred) ?* ? )
2296 (car (mm-handle-type handle))))
2298 `(local-map ,gnus-mime-button-map
2299 keymap ,gnus-mime-button-map
2302 (gnus-mime-display-alternative
2303 ',ihandles ,(car (mm-handle-type handle))))
2308 (mm-display-part preferred))))
2310 (defun gnus-article-wash-status ()
2311 "Return a string which display status of article washing."
2313 (set-buffer gnus-article-buffer)
2314 (let ((cite (gnus-article-hidden-text-p 'cite))
2315 (headers (gnus-article-hidden-text-p 'headers))
2316 (boring (gnus-article-hidden-text-p 'boring-headers))
2317 (pgp (gnus-article-hidden-text-p 'pgp))
2318 (pem (gnus-article-hidden-text-p 'pem))
2319 (signature (gnus-article-hidden-text-p 'signature))
2320 (overstrike (gnus-article-hidden-text-p 'overstrike))
2321 (emphasis (gnus-article-hidden-text-p 'emphasis)))
2322 (format "%c%c%c%c%c%c%c"
2324 (if (or headers boring) ?h ? )
2325 (if (or pgp pem) ?p ? )
2326 (if signature ?s ? )
2327 (if overstrike ?o ? )
2328 (if emphasis ?e ? )))))
2330 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2332 (defun gnus-article-maybe-hide-headers ()
2333 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2334 Provided for backwards compatibility."
2335 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2337 (gnus-article-hide-headers)))
2341 (defun gnus-output-to-file (file-name)
2342 "Append the current article to a file named FILE-NAME."
2343 (let ((artbuf (current-buffer)))
2345 (insert-buffer-substring artbuf)
2346 ;; Append newline at end of the buffer as separator, and then
2348 (goto-char (point-max))
2350 (append-to-file (point-min) (point-max) file-name)
2353 (defun gnus-narrow-to-page (&optional arg)
2354 "Narrow the article buffer to a page.
2355 If given a numerical ARG, move forward ARG pages."
2357 (setq arg (if arg (prefix-numeric-value arg) 0))
2359 (set-buffer gnus-article-buffer)
2360 (goto-char (point-min))
2362 ;; Remove any old next/prev buttons.
2363 (when (gnus-visual-p 'page-marker)
2364 (let ((buffer-read-only nil))
2365 (gnus-remove-text-with-property 'gnus-prev)
2366 (gnus-remove-text-with-property 'gnus-next)))
2369 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2371 (re-search-forward page-delimiter nil 'move arg)))
2372 (goto-char (match-end 0)))
2375 (if (re-search-forward page-delimiter nil 'move)
2378 (when (and (gnus-visual-p 'page-marker)
2379 (not (= (point-min) 1)))
2381 (goto-char (point-min))
2382 (gnus-insert-prev-page-button)))
2383 (when (and (gnus-visual-p 'page-marker)
2384 (< (+ (point-max) 2) (buffer-size)))
2386 (goto-char (point-max))
2387 (gnus-insert-next-page-button)))))
2389 ;; Article mode commands
2391 (defun gnus-article-goto-next-page ()
2392 "Show the next page of the article."
2394 (when (gnus-article-next-page)
2395 (goto-char (point-min))
2396 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2398 (defun gnus-article-goto-prev-page ()
2399 "Show the next page of the article."
2401 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2402 (gnus-article-prev-page nil)))
2404 (defun gnus-article-next-page (&optional lines)
2405 "Show the next page of the current article.
2406 If end of article, return non-nil. Otherwise return nil.
2407 Argument LINES specifies lines to be scrolled up."
2409 (move-to-window-line -1)
2412 (and (pos-visible-in-window-p) ;Not continuation line.
2414 ;; Nothing in this page.
2415 (if (or (not gnus-page-broken)
2418 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2420 (gnus-narrow-to-page 1) ;Go to next page.
2422 ;; More in this page.
2423 (let ((scroll-in-place nil))
2427 ;; Long lines may cause an end-of-buffer error.
2428 (goto-char (point-max)))))
2429 (move-to-window-line 0)
2432 (defun gnus-article-prev-page (&optional lines)
2433 "Show previous page of current article.
2434 Argument LINES specifies lines to be scrolled down."
2436 (move-to-window-line 0)
2437 (if (and gnus-page-broken
2439 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
2441 (gnus-narrow-to-page -1) ;Go to previous page.
2442 (goto-char (point-max))
2444 (let ((scroll-in-place nil))
2448 (beginning-of-buffer
2449 (goto-char (point-min))))
2450 (move-to-window-line 0)))))
2452 (defun gnus-article-refer-article ()
2453 "Read article specified by message-id around point."
2455 (let ((point (point)))
2456 (search-forward ">" nil t) ;Move point to end of "<....>".
2457 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
2458 (let ((message-id (match-string 1)))
2460 (set-buffer gnus-summary-buffer)
2461 (gnus-summary-refer-article message-id))
2463 (error "No references around point"))))
2465 (defun gnus-article-show-summary ()
2466 "Reconfigure windows to show summary buffer."
2468 (if (not (gnus-buffer-live-p gnus-summary-buffer))
2469 (error "There is no summary buffer for this article buffer")
2470 (gnus-article-set-globals)
2471 (gnus-configure-windows 'article)
2472 (gnus-summary-goto-subject gnus-current-article)
2473 (gnus-summary-position-point)))
2475 (defun gnus-article-describe-briefly ()
2476 "Describe article mode commands briefly."
2479 (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")))
2481 (defun gnus-article-summary-command ()
2482 "Execute the last keystroke in the summary buffer."
2484 (let ((obuf (current-buffer))
2485 (owin (current-window-configuration))
2487 (switch-to-buffer gnus-article-current-summary 'norecord)
2488 (setq func (lookup-key (current-local-map) (this-command-keys)))
2489 (call-interactively func)
2491 (set-window-configuration owin)
2492 (set-window-point (get-buffer-window (current-buffer)) (point))))
2494 (defun gnus-article-summary-command-nosave ()
2495 "Execute the last keystroke in the summary buffer."
2498 (pop-to-buffer gnus-article-current-summary 'norecord)
2499 (setq func (lookup-key (current-local-map) (this-command-keys)))
2500 (call-interactively func)))
2502 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
2503 "Read a summary buffer key sequence and execute it from the article buffer."
2506 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
2507 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
2508 "=" "^" "\M-^" "|"))
2514 '("n" "Gn" "p" "Gp"))
2517 (set-buffer gnus-article-current-summary)
2518 (let (gnus-pick-mode)
2519 (push (or key last-command-event) unread-command-events)
2520 (setq keys (read-key-sequence nil))))
2523 (if (or (member keys nosaves)
2524 (member keys nosave-but-article)
2525 (member keys nosave-in-article))
2527 (save-window-excursion
2528 (pop-to-buffer gnus-article-current-summary 'norecord)
2529 ;; We disable the pick minor mode commands.
2530 (let (gnus-pick-mode)
2531 (setq func (lookup-key (current-local-map) keys))))
2534 (unless (member keys nosave-in-article)
2535 (set-buffer gnus-article-current-summary))
2536 (call-interactively func)
2537 (setq new-sum-point (point)))
2538 (when (member keys nosave-but-article)
2539 (pop-to-buffer gnus-article-buffer 'norecord)))
2540 ;; These commands should restore window configuration.
2541 (let ((obuf (current-buffer))
2542 (owin (current-window-configuration))
2544 (summary gnus-article-current-summary)
2545 func in-buffer selected)
2546 (if not-restore-window
2547 (pop-to-buffer summary 'norecord)
2548 (switch-to-buffer summary 'norecord))
2549 (setq in-buffer (current-buffer))
2550 ;; We disable the pick minor mode commands.
2551 (if (setq func (let (gnus-pick-mode)
2552 (lookup-key (current-local-map) keys)))
2554 (call-interactively func)
2555 (setq new-sum-point (point)))
2557 (when (eq in-buffer (current-buffer))
2558 (setq selected (gnus-summary-select-article))
2560 (unless not-restore-window
2561 (set-window-configuration owin))
2562 (unless (or (not (eq selected 'old)) (member keys up-to-top))
2563 (set-window-point (get-buffer-window (current-buffer))
2565 (let ((win (get-buffer-window gnus-article-current-summary)))
2567 (set-window-point win new-sum-point))))))))
2569 (defun gnus-article-hide (&optional arg force)
2570 "Hide all the gruft in the current article.
2571 This means that PGP stuff, signatures, cited text and (some)
2572 headers will be hidden.
2573 If given a prefix, show the hidden text instead."
2574 (interactive (append (gnus-article-hidden-arg) (list 'force)))
2575 (gnus-article-hide-headers arg)
2576 (gnus-article-hide-pgp arg)
2577 (gnus-article-hide-citation-maybe arg force)
2578 (gnus-article-hide-signature arg))
2580 (defun gnus-article-maybe-highlight ()
2581 "Do some article highlighting if article highlighting is requested."
2582 (when (gnus-visual-p 'article-highlight 'highlight)
2583 (gnus-article-highlight-some)))
2585 (defun gnus-check-group-server ()
2586 ;; Make sure the connection to the server is alive.
2587 (unless (gnus-server-opened
2588 (gnus-find-method-for-group gnus-newsgroup-name))
2589 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
2590 (gnus-request-group gnus-newsgroup-name t)))
2592 (defun gnus-request-article-this-buffer (article group)
2593 "Get an article and insert it into this buffer."
2594 (let (do-update-line sparse-header)
2598 (gnus-kill-all-overlays)
2599 (setq group (or group gnus-newsgroup-name))
2601 ;; Using `gnus-request-article' directly will insert the article into
2602 ;; `nntp-server-buffer' - so we'll save some time by not having to
2603 ;; copy it from the server buffer into the article buffer.
2605 ;; We only request an article by message-id when we do not have the
2606 ;; headers for it, so we'll have to get those.
2607 (when (stringp article)
2608 (let ((gnus-override-method gnus-refer-article-method))
2609 (gnus-read-header article)))
2611 ;; If the article number is negative, that means that this article
2612 ;; doesn't belong in this newsgroup (possibly), so we find its
2613 ;; message-id and request it by id instead of number.
2614 (when (and (numberp article)
2616 (get-buffer gnus-summary-buffer)
2617 (gnus-buffer-exists-p gnus-summary-buffer))
2619 (set-buffer gnus-summary-buffer)
2620 (let ((header (gnus-summary-article-header article)))
2623 ((memq article gnus-newsgroup-sparse)
2624 ;; This is a sparse gap article.
2625 (setq do-update-line article)
2626 (setq article (mail-header-id header))
2627 (let ((gnus-override-method gnus-refer-article-method))
2628 (setq sparse-header (gnus-read-header article)))
2629 (setq gnus-newsgroup-sparse
2630 (delq article gnus-newsgroup-sparse)))
2632 ;; It's a real article.
2633 (setq article (mail-header-id header)))
2635 ;; It is an extracted pseudo-article.
2636 (setq article 'pseudo)
2637 (gnus-request-pseudo-article header))))
2639 (let ((method (gnus-find-method-for-group
2640 gnus-newsgroup-name)))
2641 (when (and (eq (car method) 'nneething)
2644 (file-name-as-directory
2645 (or (cadr (assq 'nneething-address method))
2647 (mail-header-subject header))))
2648 (when (file-directory-p dir)
2649 (setq article 'nneething)
2650 (gnus-group-enter-directory dir))))))))
2653 ;; Refuse to select canceled articles.
2654 ((and (numberp article)
2656 (get-buffer gnus-summary-buffer)
2657 (gnus-buffer-exists-p gnus-summary-buffer)
2658 (eq (cdr (save-excursion
2659 (set-buffer gnus-summary-buffer)
2660 (assq article gnus-newsgroup-reads)))
2661 gnus-canceled-mark))
2663 ;; We first check `gnus-original-article-buffer'.
2664 ((and (get-buffer gnus-original-article-buffer)
2667 (set-buffer gnus-original-article-buffer)
2668 (and (equal (car gnus-original-article) group)
2669 (eq (cdr gnus-original-article) article))))
2670 (insert-buffer-substring gnus-original-article-buffer)
2672 ;; Check the backlog.
2673 ((and gnus-keep-backlog
2674 (gnus-backlog-request-article group article (current-buffer)))
2676 ;; Check asynchronous pre-fetch.
2677 ((gnus-async-request-fetched-article group article (current-buffer))
2678 (gnus-async-prefetch-next group article gnus-summary-buffer)
2679 (when (and (numberp article) gnus-keep-backlog)
2680 (gnus-backlog-enter-article group article (current-buffer)))
2683 ((and gnus-use-cache
2685 (gnus-cache-request-article article group))
2687 ;; Get the article and put into the article buffer.
2688 ((or (stringp article) (numberp article))
2689 (let ((gnus-override-method
2690 (and (stringp article) gnus-refer-article-method))
2691 (buffer-read-only nil))
2693 (gnus-kill-all-overlays)
2694 (gnus-check-group-server)
2695 (when (gnus-request-article article group (current-buffer))
2696 (when (numberp article)
2697 (gnus-async-prefetch-next group article gnus-summary-buffer)
2698 (when gnus-keep-backlog
2699 (gnus-backlog-enter-article
2700 group article (current-buffer))))
2705 ;; Associate this article with the current summary buffer.
2706 (setq gnus-article-current-summary gnus-summary-buffer)
2708 ;; Take the article from the original article buffer
2709 ;; and place it in the buffer it's supposed to be in.
2710 (when (and (get-buffer gnus-article-buffer)
2711 (equal (buffer-name (current-buffer))
2712 (buffer-name (get-buffer gnus-article-buffer))))
2714 (if (get-buffer gnus-original-article-buffer)
2715 (set-buffer gnus-original-article-buffer)
2716 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2717 (buffer-disable-undo)
2718 (setq major-mode 'gnus-original-article-mode)
2719 (setq buffer-read-only t))
2720 (let (buffer-read-only)
2722 (insert-buffer-substring gnus-article-buffer))
2723 (setq gnus-original-article (cons group article)))
2726 (run-hooks 'gnus-article-decode-hook)
2727 ;; Mark article as decoded or not.
2728 (setq gnus-article-decoded-p gnus-article-decode-hook))
2730 ;; Update sparse articles.
2731 (when (and do-update-line
2732 (or (numberp article)
2734 (let ((buf (current-buffer)))
2735 (set-buffer gnus-summary-buffer)
2736 (gnus-summary-update-article do-update-line sparse-header)
2737 (gnus-summary-goto-subject do-update-line nil t)
2738 (set-window-point (get-buffer-window (current-buffer) t)
2740 (set-buffer buf))))))
2746 (defcustom gnus-article-edit-mode-hook nil
2747 "Hook run in article edit mode buffers."
2748 :group 'gnus-article-various
2751 (defvar gnus-article-edit-done-function nil)
2753 (defvar gnus-article-edit-mode-map nil)
2755 (unless gnus-article-edit-mode-map
2756 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map))
2758 (gnus-define-keys gnus-article-edit-mode-map
2759 "\C-c\C-c" gnus-article-edit-done
2760 "\C-c\C-k" gnus-article-edit-exit)
2762 (gnus-define-keys (gnus-article-edit-wash-map
2763 "\C-c\C-w" gnus-article-edit-mode-map)
2764 "f" gnus-article-edit-full-stops))
2766 (defun gnus-article-edit-mode ()
2767 "Major mode for editing articles.
2768 This is an extended text-mode.
2770 \\{gnus-article-edit-mode-map}"
2772 (setq major-mode 'gnus-article-edit-mode)
2773 (setq mode-name "Article Edit")
2774 (use-local-map gnus-article-edit-mode-map)
2775 (make-local-variable 'gnus-article-edit-done-function)
2776 (make-local-variable 'gnus-prev-winconf)
2777 (setq buffer-read-only nil)
2778 (buffer-enable-undo)
2780 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
2782 (defun gnus-article-edit (&optional force)
2783 "Edit the current article.
2784 This will have permanent effect only in mail groups.
2785 If FORCE is non-nil, allow editing of articles even in read-only
2788 (when (and (not force)
2789 (gnus-group-read-only-p))
2790 (error "The current newsgroup does not support article editing"))
2791 (gnus-article-date-original)
2792 (gnus-article-edit-article
2793 `(lambda (no-highlight)
2794 (gnus-summary-edit-article-done
2795 ,(or (mail-header-references gnus-current-headers) "")
2796 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
2798 (defun gnus-article-edit-article (exit-func)
2799 "Start editing the contents of the current article buffer."
2800 (let ((winconf (current-window-configuration)))
2801 (set-buffer gnus-article-buffer)
2802 (gnus-article-edit-mode)
2803 (gnus-article-delete-text-of-type 'annotation)
2804 (gnus-set-text-properties (point-min) (point-max) nil)
2805 (gnus-configure-windows 'edit-article)
2806 (setq gnus-article-edit-done-function exit-func)
2807 (setq gnus-prev-winconf winconf)
2808 (gnus-message 6 "C-c C-c to end edits")))
2810 (defun gnus-article-edit-done (&optional arg)
2811 "Update the article edits and exit."
2816 (goto-char (point-min))
2817 (when (search-forward "\n\n" nil 1)
2818 (let ((lines (count-lines (point) (point-max)))
2819 (length (- (point-max) (point)))
2820 (case-fold-search t)
2821 (body (copy-marker (point))))
2822 (goto-char (point-min))
2823 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
2824 (delete-region (match-beginning 1) (match-end 1))
2825 (insert (number-to-string length)))
2826 (goto-char (point-min))
2827 (when (re-search-forward
2828 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
2829 (delete-region (match-beginning 1) (match-end 1))
2830 (insert (number-to-string length)))
2831 (goto-char (point-min))
2832 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
2833 (delete-region (match-beginning 1) (match-end 1))
2834 (insert (number-to-string lines)))))))
2835 (let ((func gnus-article-edit-done-function)
2836 (buf (current-buffer))
2837 (start (window-start)))
2838 (gnus-article-edit-exit)
2841 (let ((buffer-read-only nil))
2842 (funcall func arg)))
2844 (set-window-start (get-buffer-window buf) start)
2845 (set-window-point (get-buffer-window buf) (point))))
2847 (defun gnus-article-edit-exit ()
2848 "Exit the article editing without updating."
2850 ;; We remove all text props from the article buffer.
2851 (let ((buf (format "%s" (buffer-string)))
2852 (curbuf (current-buffer))
2854 (window-start (window-start)))
2857 (let ((winconf gnus-prev-winconf))
2859 ;; The cache and backlog have to be flushed somewhat.
2860 (when gnus-use-cache
2861 (gnus-cache-update-article
2862 (car gnus-article-current) (cdr gnus-article-current)))
2863 (when gnus-keep-backlog
2864 (gnus-backlog-remove-article
2865 (car gnus-article-current) (cdr gnus-article-current)))
2866 ;; Flush original article as well.
2868 (when (get-buffer gnus-original-article-buffer)
2869 (set-buffer gnus-original-article-buffer)
2870 (setq gnus-original-article nil)))
2871 (set-window-configuration winconf)
2872 ;; Tippy-toe some to make sure that point remains where it was.
2873 (let ((buf (current-buffer)))
2875 (set-window-start (get-buffer-window (current-buffer)) window-start)
2877 (set-buffer buf)))))
2879 (defun gnus-article-edit-full-stops ()
2880 "Interactively repair spacing at end of sentences."
2883 (goto-char (point-min))
2884 (search-forward-regexp "^$" nil t)
2885 (let ((case-fold-search nil))
2886 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
2889 ;;; Article highlights
2892 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
2894 ;;; Internal Variables:
2896 (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\\)"
2897 "Regular expression that matches URLs."
2898 :group 'gnus-article-buttons
2901 (defcustom gnus-button-alist
2902 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" 0 t
2903 gnus-button-message-id 2)
2904 ("\\bnews:\\([^>\n\t ]*@[^>\n\t ]*\\)" 0 t gnus-button-message-id 1)
2905 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
2907 gnus-button-fetch-group 4)
2908 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
2909 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
2910 t gnus-button-message-id 3)
2911 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
2912 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
2913 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
2914 ;; This is how URLs _should_ be embedded in text...
2915 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
2917 (,gnus-button-url-regexp 0 t gnus-button-url 0))
2918 "*Alist of regexps matching buttons in article bodies.
2920 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
2921 REGEXP: is the string matching text around the button,
2922 BUTTON: is the number of the regexp grouping actually matching the button,
2923 FORM: is a lisp expression which must eval to true for the button to
2925 CALLBACK: is the function to call when the user push this button, and each
2926 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
2928 CALLBACK can also be a variable, in that case the value of that
2929 variable it the real callback function."
2930 :group 'gnus-article-buttons
2931 :type '(repeat (list regexp
2932 (integer :tag "Button")
2934 (function :tag "Callback")
2937 (integer :tag "Regexp group")))))
2939 (defcustom gnus-header-button-alist
2940 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
2941 0 t gnus-button-message-id 0)
2942 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
2943 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
2944 0 t gnus-button-mailto 0)
2945 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2946 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2947 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
2948 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
2949 gnus-button-message-id 3))
2950 "*Alist of headers and regexps to match buttons in article heads.
2952 This alist is very similar to `gnus-button-alist', except that each
2953 alist has an additional HEADER element first in each entry:
2955 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
2957 HEADER is a regexp to match a header. For a fuller explanation, see
2958 `gnus-button-alist'."
2959 :group 'gnus-article-buttons
2960 :group 'gnus-article-headers
2961 :type '(repeat (list (regexp :tag "Header")
2963 (integer :tag "Button")
2965 (function :tag "Callback")
2968 (integer :tag "Regexp group")))))
2970 (defvar gnus-button-regexp nil)
2971 (defvar gnus-button-marker-list nil)
2972 ;; Regexp matching any of the regexps from `gnus-button-alist'.
2974 (defvar gnus-button-last nil)
2975 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
2979 (defun gnus-article-push-button (event)
2980 "Check text under the mouse pointer for a callback function.
2981 If the text under the mouse pointer has a `gnus-callback' property,
2982 call it with the value of the `gnus-data' text property."
2984 (set-buffer (window-buffer (posn-window (event-start event))))
2985 (let* ((pos (posn-point (event-start event)))
2986 (data (get-text-property pos 'gnus-data))
2987 (fun (get-text-property pos 'gnus-callback)))
2990 (funcall fun data))))
2992 (defun gnus-article-press-button ()
2993 "Check text at point for a callback function.
2994 If the text at point has a `gnus-callback' property,
2995 call it with the value of the `gnus-data' text property."
2997 (let* ((data (get-text-property (point) 'gnus-data))
2998 (fun (get-text-property (point) 'gnus-callback)))
3000 (funcall fun data))))
3002 (defun gnus-article-highlight (&optional force)
3003 "Highlight current article.
3004 This function calls `gnus-article-highlight-headers',
3005 `gnus-article-highlight-citation',
3006 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3007 do the highlighting. See the documentation for those functions."
3008 (interactive (list 'force))
3009 (gnus-article-highlight-headers)
3010 (gnus-article-highlight-citation force)
3011 (gnus-article-highlight-signature)
3012 (gnus-article-add-buttons force)
3013 (gnus-article-add-buttons-to-head))
3015 (defun gnus-article-highlight-some (&optional force)
3016 "Highlight current article.
3017 This function calls `gnus-article-highlight-headers',
3018 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3019 do the highlighting. See the documentation for those functions."
3020 (interactive (list 'force))
3021 (gnus-article-highlight-headers)
3022 (gnus-article-highlight-signature)
3023 (gnus-article-add-buttons))
3025 (defun gnus-article-highlight-headers ()
3026 "Highlight article headers as specified by `gnus-header-face-alist'."
3029 (set-buffer gnus-article-buffer)
3031 (let ((alist gnus-header-face-alist)
3032 (buffer-read-only nil)
3033 (case-fold-search t)
3034 (inhibit-point-motion-hooks t)
3035 entry regexp header-face field-face from hpoints fpoints)
3036 (message-narrow-to-head)
3037 (while (setq entry (pop alist))
3038 (goto-char (point-min))
3039 (setq regexp (concat "^\\("
3040 (if (string-equal "" (nth 0 entry))
3044 header-face (nth 1 entry)
3045 field-face (nth 2 entry))
3046 (while (and (re-search-forward regexp nil t)
3050 (unless (search-forward ":" nil t)
3052 (when (and header-face
3053 (not (memq (point) hpoints)))
3054 (push (point) hpoints)
3055 (gnus-put-text-property from (point) 'face header-face))
3056 (when (and field-face
3057 (not (memq (setq from (point)) fpoints)))
3059 (if (re-search-forward "^[^ \t]" nil t)
3061 (goto-char (point-max)))
3062 (gnus-put-text-property from (point) 'face field-face))))))))
3064 (defun gnus-article-highlight-signature ()
3065 "Highlight the signature in an article.
3066 It does this by highlighting everything after
3067 `gnus-signature-separator' using `gnus-signature-face'."
3070 (set-buffer gnus-article-buffer)
3071 (let ((buffer-read-only nil)
3072 (inhibit-point-motion-hooks t))
3074 (when (and gnus-signature-face
3075 (gnus-article-narrow-to-signature))
3076 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3077 'face gnus-signature-face)
3079 (gnus-article-search-signature)
3080 (let ((start (match-beginning 0))
3081 (end (set-marker (make-marker) (1+ (match-end 0)))))
3082 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3085 (defun gnus-button-in-region-p (b e prop)
3086 "Say whether PROP exists in the region."
3087 (text-property-not-all b e prop nil))
3089 (defun gnus-article-add-buttons (&optional force)
3090 "Find external references in the article and make buttons of them.
3091 \"External references\" are things like Message-IDs and URLs, as
3092 specified by `gnus-button-alist'."
3093 (interactive (list 'force))
3095 (set-buffer gnus-article-buffer)
3096 (let ((buffer-read-only nil)
3097 (inhibit-point-motion-hooks t)
3098 (case-fold-search t)
3099 (alist gnus-button-alist)
3101 ;; Remove all old markers.
3103 (while (setq marker (pop gnus-button-marker-list))
3105 (when (setq entry (gnus-button-entry))
3106 (put-text-property (match-beginning (nth 1 entry))
3107 (match-end (nth 1 entry))
3108 'gnus-callback nil))
3109 (set-marker marker nil)))
3110 ;; We skip the headers.
3111 (goto-char (point-min))
3112 (unless (search-forward "\n\n" nil t)
3113 (goto-char (point-max)))
3115 (while (setq entry (pop alist))
3116 (setq regexp (car entry))
3118 (while (re-search-forward regexp nil t)
3119 (let* ((start (and entry (match-beginning (nth 1 entry))))
3120 (end (and entry (match-end (nth 1 entry))))
3121 (from (match-beginning 0)))
3122 (when (and (or (eq t (nth 2 entry))
3123 (eval (nth 2 entry)))
3124 (not (gnus-button-in-region-p
3125 start end 'gnus-callback)))
3126 ;; That optional form returned non-nil, so we add the
3128 (gnus-article-add-button
3129 start end 'gnus-button-push
3130 (car (push (set-marker (make-marker) from)
3131 gnus-button-marker-list))))))))))
3133 ;; Add buttons to the head of an article.
3134 (defun gnus-article-add-buttons-to-head ()
3135 "Add buttons to the head of the article."
3138 (set-buffer gnus-article-buffer)
3139 (let ((buffer-read-only nil)
3140 (inhibit-point-motion-hooks t)
3141 (case-fold-search t)
3142 (alist gnus-header-button-alist)
3144 (nnheader-narrow-to-headers)
3146 ;; Each alist entry.
3147 (setq entry (car alist)
3149 (goto-char (point-min))
3150 (while (re-search-forward (car entry) nil t)
3151 ;; Each header matching the entry.
3152 (setq beg (match-beginning 0))
3153 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3154 (match-beginning 0))
3157 (while (re-search-forward (nth 1 entry) end t)
3158 ;; Each match within a header.
3159 (let* ((entry (cdr entry))
3160 (start (match-beginning (nth 1 entry)))
3161 (end (match-end (nth 1 entry)))
3162 (form (nth 2 entry)))
3163 (goto-char (match-end 0))
3165 (gnus-article-add-button
3166 start end (nth 3 entry)
3167 (buffer-substring (match-beginning (nth 4 entry))
3168 (match-end (nth 4 entry)))))))
3172 ;;; External functions:
3174 (defun gnus-article-add-button (from to fun &optional data)
3175 "Create a button between FROM and TO with callback FUN and data DATA."
3176 (when gnus-article-button-face
3177 (gnus-overlay-put (gnus-make-overlay from to)
3178 'face gnus-article-button-face))
3179 (gnus-add-text-properties
3181 (nconc (and gnus-article-mouse-face
3182 (list gnus-mouse-face-prop gnus-article-mouse-face))
3183 (list 'gnus-callback fun)
3184 (and data (list 'gnus-data data))))
3185 (widget-convert-button 'link from to :action 'gnus-widget-press-button
3186 :button-keymap gnus-widget-button-keymap))
3188 ;;; Internal functions:
3190 (defun gnus-article-set-globals ()
3192 (set-buffer gnus-summary-buffer)
3193 (gnus-set-global-variables)))
3195 (defun gnus-signature-toggle (end)
3197 (set-buffer gnus-article-buffer)
3198 (let ((buffer-read-only nil)
3199 (inhibit-point-motion-hooks t))
3200 (if (get-text-property end 'invisible)
3201 (gnus-article-unhide-text end (point-max))
3202 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3204 (defun gnus-button-entry ()
3205 ;; Return the first entry in `gnus-button-alist' matching this place.
3206 (let ((alist gnus-button-alist)
3209 (setq entry (pop alist))
3210 (if (looking-at (car entry))
3215 (defun gnus-button-push (marker)
3216 ;; Push button starting at MARKER.
3218 (set-buffer gnus-article-buffer)
3220 (let* ((entry (gnus-button-entry))
3221 (inhibit-point-motion-hooks t)
3223 (args (mapcar (lambda (group)
3224 (let ((string (match-string group)))
3225 (gnus-set-text-properties
3226 0 (length string) nil string)
3233 (fboundp (symbol-value fun)))
3234 (apply (symbol-value fun) args))
3236 (gnus-message 1 "You must define `%S' to use this button"
3237 (cons fun args)))))))
3239 (defun gnus-button-message-id (message-id)
3242 (set-buffer gnus-summary-buffer)
3243 (gnus-summary-refer-article message-id)))
3245 (defun gnus-button-fetch-group (address)
3246 "Fetch GROUP specified by ADDRESS."
3247 (if (not (string-match "[:/]" address))
3248 ;; This is just a simple group url.
3249 (gnus-group-read-ephemeral-group address gnus-select-method)
3250 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3252 (error "Can't parse %s" address)
3253 (gnus-group-read-ephemeral-group
3254 (match-string 4 address)
3255 `(nntp ,(match-string 1 address)
3256 (nntp-address ,(match-string 1 address))
3257 (nntp-port-number ,(if (match-end 3)
3258 (match-string 3 address)
3261 (defun gnus-url-parse-query-string (query &optional downcase)
3262 (let (retval pairs cur key val)
3263 (setq pairs (split-string query "&"))
3265 (setq cur (car pairs)
3267 (if (not (string-match "=" cur))
3269 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3270 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3272 (setq key (downcase key)))
3273 (setq cur (assoc key retval))
3275 (setcdr cur (cons val (cdr cur)))
3276 (setq retval (cons (list key val) retval)))))
3279 (defun gnus-url-unhex (x)
3286 (defun gnus-url-unhex-string (str &optional allow-newlines)
3287 "Remove %XXX embedded spaces, etc in a url.
3288 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3289 decoding of carriage returns and line feeds in the string, which is normally
3290 forbidden in URL encoding."
3291 (setq str (or str ""))
3293 (case-fold-search t))
3294 (while (string-match "%[0-9a-f][0-9a-f]" str)
3295 (let* ((start (match-beginning 0))
3296 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3298 (gnus-url-unhex (elt str (+ start 2))))))
3300 tmp (substring str 0 start)
3303 (char-to-string code))
3304 ((or (= code ?\n) (= code ?\r))
3306 (t (char-to-string code))))
3307 str (substring str (match-end 0)))))
3308 (setq tmp (concat tmp str))
3311 (defun gnus-url-mailto (url)
3312 ;; Send mail to someone
3313 (when (string-match "mailto:/*\\(.*\\)" url)
3314 (setq url (substring url (match-beginning 1) nil)))
3315 (let (to args subject func)
3316 (if (string-match (regexp-quote "?") url)
3317 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
3318 args (gnus-url-parse-query-string
3319 (substring url (match-end 0) nil) t))
3320 (setq to (gnus-url-unhex-string url)))
3321 (setq args (cons (list "to" to) args)
3322 subject (cdr-safe (assoc "subject" args)))
3325 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
3328 (message-position-on-field (caar args)))
3329 (insert (mapconcat 'identity (cdar args) ", "))
3330 (setq args (cdr args)))
3333 (message-goto-subject))))
3335 (defun gnus-button-mailto (address)
3337 (set-buffer (gnus-copy-article-buffer))
3338 (message-reply address))
3340 (defun gnus-button-reply (address)
3341 ;; Reply to ADDRESS.
3342 (message-reply address))
3344 (defun gnus-button-url (address)
3346 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3347 (if (listp browse-url-browser-function)
3348 (browse-url address)
3349 (funcall browse-url-browser-function address)))
3351 (defun gnus-button-embedded-url (address)
3353 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
3354 (if (listp browse-url-browser-function)
3355 (browse-url (gnus-strip-whitespace address))
3356 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
3358 ;;; Next/prev buttons in the article buffer.
3360 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
3361 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
3363 (defvar gnus-prev-page-map nil)
3364 (unless gnus-prev-page-map
3365 (setq gnus-prev-page-map (make-sparse-keymap))
3366 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
3367 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
3369 (defun gnus-insert-prev-page-button ()
3370 (let ((buffer-read-only nil))
3372 gnus-prev-page-line-format nil
3373 `(gnus-prev t local-map ,gnus-prev-page-map
3374 gnus-callback gnus-article-button-prev-page
3375 gnus-type annotation))))
3377 (defvar gnus-next-page-map nil)
3378 (unless gnus-next-page-map
3379 (setq gnus-next-page-map (make-keymap))
3380 (suppress-keymap gnus-prev-page-map)
3381 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
3382 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
3384 (defun gnus-button-next-page ()
3385 "Go to the next page."
3387 (let ((win (selected-window)))
3388 (select-window (get-buffer-window gnus-article-buffer t))
3389 (gnus-article-next-page)
3390 (select-window win)))
3392 (defun gnus-button-prev-page ()
3393 "Go to the prev page."
3395 (let ((win (selected-window)))
3396 (select-window (get-buffer-window gnus-article-buffer t))
3397 (gnus-article-prev-page)
3398 (select-window win)))
3400 (defun gnus-insert-next-page-button ()
3401 (let ((buffer-read-only nil))
3402 (gnus-eval-format gnus-next-page-line-format nil
3404 t local-map ,gnus-next-page-map
3405 gnus-callback gnus-article-button-next-page
3406 gnus-type annotation))))
3408 (defun gnus-article-button-next-page (arg)
3409 "Go to the next page."
3411 (let ((win (selected-window)))
3412 (select-window (get-buffer-window gnus-article-buffer t))
3413 (gnus-article-next-page)
3414 (select-window win)))
3416 (defun gnus-article-button-prev-page (arg)
3417 "Go to the prev page."
3419 (let ((win (selected-window)))
3420 (select-window (get-buffer-window gnus-article-buffer t))
3421 (gnus-article-prev-page)
3422 (select-window win)))
3428 (run-hooks 'gnus-art-load-hook)
3430 ;;; gnus-art.el ends here