1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
41 ;; Avoid byte-compile warnings.
43 (defvar gnus-article-decoded-p)
44 (defvar gnus-article-mime-handles)
53 (defgroup gnus-article nil
55 :link '(custom-manual "(gnus)The Article Buffer")
58 (defgroup gnus-article-hiding nil
59 "Hiding article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
63 (defgroup gnus-article-highlight nil
64 "Article highlighting."
65 :link '(custom-manual "(gnus)Article Highlighting")
69 (defgroup gnus-article-signature nil
71 :link '(custom-manual "(gnus)Article Signature")
74 (defgroup gnus-article-headers nil
76 :link '(custom-manual "(gnus)Hiding Headers")
79 (defgroup gnus-article-washing nil
80 "Special commands on articles."
81 :link '(custom-manual "(gnus)Article Washing")
84 (defgroup gnus-article-emphasis nil
85 "Fontisizing articles."
86 :link '(custom-manual "(gnus)Article Fontisizing")
89 (defgroup gnus-article-saving nil
91 :link '(custom-manual "(gnus)Saving Articles")
94 (defgroup gnus-article-mime nil
95 "Worshiping the MIME wonder."
96 :link '(custom-manual "(gnus)Using MIME")
99 (defgroup gnus-article-buttons nil
100 "Pushable buttons in the article buffer."
101 :link '(custom-manual "(gnus)Article Buttons")
102 :group 'gnus-article)
104 (defgroup gnus-article-various nil
105 "Other article options."
106 :link '(custom-manual "(gnus)Misc Article")
107 :group 'gnus-article)
109 (defcustom gnus-ignored-headers
110 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
111 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
112 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
113 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
114 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
115 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
116 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
117 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
118 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
119 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
120 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
121 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
122 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
123 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
124 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
125 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
126 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
127 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
129 "*All headers that start with this regexp will be hidden.
130 This variable can also be a list of regexps of headers to be ignored.
131 If `gnus-visible-headers' is non-nil, this variable will be ignored."
132 :type '(choice :custom-show nil
135 :group 'gnus-article-hiding)
137 (defcustom gnus-visible-headers
138 "From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|X-Sent:"
139 "*All headers that do not match this regexp will be hidden.
140 This variable can also be a list of regexp of headers to remain visible.
141 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
142 :type '(repeat :value-to-internal (lambda (widget value)
143 (custom-split-regexp-maybe value))
144 :match (lambda (widget value)
146 (widget-editable-list-match widget value)))
148 :group 'gnus-article-hiding)
150 (defcustom gnus-sorted-header-list
151 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
152 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
153 "*This variable is a list of regular expressions.
154 If it is non-nil, headers that match the regular expressions will
155 be placed first in the article buffer in the sequence specified by
157 :type '(repeat regexp)
158 :group 'gnus-article-hiding)
160 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
161 "Headers that are only to be displayed if they have interesting data.
162 Possible values in this list are `empty', `newsgroups', `followup-to',
163 `reply-to', `date', `long-to', and `many-to'."
164 :type '(set (const :tag "Headers with no content." empty)
165 (const :tag "Newsgroups with only one group." newsgroups)
166 (const :tag "Followup-to identical to newsgroups." followup-to)
167 (const :tag "Reply-to identical to from." reply-to)
168 (const :tag "Date less than four days old." date)
169 (const :tag "Very long To header." long-to)
170 (const :tag "Multiple To headers." many-to))
171 :group 'gnus-article-hiding)
173 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
174 "Regexp matching signature separator.
175 This can also be a list of regexps. In that case, it will be checked
176 from head to tail looking for a separator. Searches will be done from
177 the end of the buffer."
178 :type '(repeat string)
179 :group 'gnus-article-signature)
181 (defcustom gnus-signature-limit nil
182 "Provide a limit to what is considered a signature.
183 If it is a number, no signature may not be longer (in characters) than
184 that number. If it is a floating point number, no signature may be
185 longer (in lines) than that number. If it is a function, the function
186 will be called without any parameters, and if it returns nil, there is
187 no signature in the buffer. If it is a string, it will be used as a
188 regexp. If it matches, the text in question is not a signature."
189 :type '(choice (integer :value 200)
191 (function :value fun)
192 (regexp :value ".*"))
193 :group 'gnus-article-signature)
195 (defcustom gnus-hidden-properties '(invisible t intangible t)
196 "Property list to use for hiding text."
198 :group 'gnus-article-hiding)
200 (defcustom gnus-article-x-face-command
201 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
202 "*String or function to be executed to display an X-Face header.
203 If it is a string, the command will be executed in a sub-shell
204 asynchronously. The compressed face will be piped to this command."
205 :type 'string ;Leave function case to Lisp.
206 :group 'gnus-article-washing)
208 (defcustom gnus-article-x-face-too-ugly nil
209 "Regexp matching posters whose face shouldn't be shown automatically."
210 :type '(choice regexp (const nil))
211 :group 'gnus-article-washing)
213 (defcustom gnus-emphasis-alist
215 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
217 '(("_" "_" underline)
220 ("_/" "/_" underline-italic)
221 ("_\\*" "\\*_" underline-bold)
222 ("\\*/" "/\\*" bold-italic)
223 ("_\\*/" "/\\*_" underline-bold-italic))))
224 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
225 2 3 gnus-emphasis-underline)
229 (format format (car spec) (cadr spec))
230 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
232 "*Alist that says how to fontify certain phrases.
233 Each item looks like this:
235 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
237 The first element is a regular expression to be matched. The second
238 is a number that says what regular expression grouping used to find
239 the entire emphasized word. The third is a number that says what
240 regexp grouping should be displayed and highlighted. The fourth
241 is the face used for highlighting."
242 :type '(repeat (list :value ("" 0 0 default)
244 (integer :tag "Match group")
245 (integer :tag "Emphasize group")
247 :group 'gnus-article-emphasis)
249 (defface gnus-emphasis-bold '((t (:bold t)))
250 "Face used for displaying strong emphasized text (*word*)."
251 :group 'gnus-article-emphasis)
253 (defface gnus-emphasis-italic '((t (:italic t)))
254 "Face used for displaying italic emphasized text (/word/)."
255 :group 'gnus-article-emphasis)
257 (defface gnus-emphasis-underline '((t (:underline t)))
258 "Face used for displaying underlined emphasized text (_word_)."
259 :group 'gnus-article-emphasis)
261 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
262 "Face used for displaying underlined bold emphasized text (_*word*_)."
263 :group 'gnus-article-emphasis)
265 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
266 "Face used for displaying underlined italic emphasized text (_*word*_)."
267 :group 'gnus-article-emphasis)
269 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
270 "Face used for displaying bold italic emphasized text (/*word*/)."
271 :group 'gnus-article-emphasis)
273 (defface gnus-emphasis-underline-bold-italic
274 '((t (:bold t :italic t :underline t)))
275 "Face used for displaying underlined bold italic emphasized text.
276 Esample: (_/*word*/_)."
277 :group 'gnus-article-emphasis)
279 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
280 "Format for display of Date headers in article bodies.
281 See `format-time-string' for the possible values.
283 The variable can also be function, which should return a complete Date
284 header. The function is called with one argument, the time, which can
285 be fed to `format-time-string'."
286 :type '(choice string symbol)
287 :link '(custom-manual "(gnus)Article Date")
288 :group 'gnus-article-washing)
291 (autoload 'mail-extract-address-components "mail-extr"))
293 (defcustom gnus-save-all-headers t
294 "*If non-nil, don't remove any headers before saving."
295 :group 'gnus-article-saving
298 (defcustom gnus-prompt-before-saving 'always
299 "*This variable says how much prompting is to be done when saving articles.
300 If it is nil, no prompting will be done, and the articles will be
301 saved to the default files. If this variable is `always', each and
302 every article that is saved will be preceded by a prompt, even when
303 saving large batches of articles. If this variable is neither nil not
304 `always', there the user will be prompted once for a file name for
305 each invocation of the saving commands."
306 :group 'gnus-article-saving
307 :type '(choice (item always)
308 (item :tag "never" nil)
309 (sexp :tag "once" :format "%t\n" :value t)))
311 (defcustom gnus-saved-headers gnus-visible-headers
312 "Headers to keep if `gnus-save-all-headers' is nil.
313 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
314 If that variable is nil, however, all headers that match this regexp
315 will be kept while the rest will be deleted before saving."
316 :group 'gnus-article-saving
319 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
320 "A function to save articles in your favourite format.
321 The function must be interactively callable (in other words, it must
322 be an Emacs command).
324 Gnus provides the following functions:
326 * gnus-summary-save-in-rmail (Rmail format)
327 * gnus-summary-save-in-mail (Unix mail format)
328 * gnus-summary-save-in-folder (MH folder)
329 * gnus-summary-save-in-file (article format)
330 * gnus-summary-save-in-vm (use VM's folder format)
331 * gnus-summary-write-to-file (article format -- overwrite)."
332 :group 'gnus-article-saving
333 :type '(radio (function-item gnus-summary-save-in-rmail)
334 (function-item gnus-summary-save-in-mail)
335 (function-item gnus-summary-save-in-folder)
336 (function-item gnus-summary-save-in-file)
337 (function-item gnus-summary-save-in-vm)
338 (function-item gnus-summary-write-to-file)))
340 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
341 "A function generating a file name to save articles in Rmail format.
342 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
343 :group 'gnus-article-saving
346 (defcustom gnus-mail-save-name 'gnus-plain-save-name
347 "A function generating a file name to save articles in Unix mail format.
348 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
349 :group 'gnus-article-saving
352 (defcustom gnus-folder-save-name 'gnus-folder-save-name
353 "A function generating a file name to save articles in MH folder.
354 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
355 :group 'gnus-article-saving
358 (defcustom gnus-file-save-name 'gnus-numeric-save-name
359 "A function generating a file name to save articles in article format.
360 The function is called with NEWSGROUP, HEADERS, and optional
362 :group 'gnus-article-saving
365 (defcustom gnus-split-methods
366 '((gnus-article-archive-name)
367 (gnus-article-nndoc-name))
368 "*Variable used to suggest where articles are to be saved.
369 For instance, if you would like to save articles related to Gnus in
370 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
371 you could set this variable to something like:
373 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
374 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
376 This variable is an alist where the where the key is the match and the
377 value is a list of possible files to save in if the match is non-nil.
379 If the match is a string, it is used as a regexp match on the
380 article. If the match is a symbol, that symbol will be funcalled
381 from the buffer of the article to be saved with the newsgroup as the
382 parameter. If it is a list, it will be evaled in the same buffer.
384 If this form or function returns a string, this string will be used as
385 a possible file name; and if it returns a non-nil list, that list will
386 be used as possible file names."
387 :group 'gnus-article-saving
388 :type '(repeat (choice (list :value (fun) function)
389 (cons :value ("" "") regexp (repeat string))
392 (defcustom gnus-article-display-method-for-mime
393 'gnus-article-display-mime-message
394 "Function to display a MIME message.
395 The function is called from the article buffer."
396 :group 'gnus-article-mime
399 (defcustom gnus-article-display-method-for-traditional
400 'gnus-article-display-traditional-message
401 "*Function to display a traditional message.
402 The function is called from the article buffer."
403 :group 'gnus-article-mime
406 (defcustom gnus-page-delimiter "^\^L"
407 "*Regexp describing what to use as article page delimiters.
408 The default value is \"^\^L\", which is a form linefeed at the
409 beginning of a line."
411 :group 'gnus-article-various)
413 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
414 "*The format specification for the article mode line.
415 See `gnus-summary-mode-line-format' for a closer description.
417 The following additional specs are available:
419 %w The article washing status.
420 %m The number of MIME parts in the article."
422 :group 'gnus-article-various)
424 (defcustom gnus-article-mode-hook nil
425 "*A hook for Gnus article mode."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-menu-hook nil
430 "*Hook run after the creation of the article mode menu."
432 :group 'gnus-article-various)
434 (defcustom gnus-article-prepare-hook nil
435 "*A hook called after an article has been prepared in the article buffer.
436 If you want to run a special decoding program like nkf, use this hook."
438 :group 'gnus-article-various)
440 (defcustom gnus-article-hide-pgp-hook nil
441 "*A hook called after successfully hiding a PGP signature."
443 :group 'gnus-article-various)
445 (defcustom gnus-article-button-face 'bold
446 "Face used for highlighting buttons in the article buffer.
448 An article button is a piece of text that you can activate by pressing
449 `RET' or `mouse-2' above it."
451 :group 'gnus-article-buttons)
453 (defcustom gnus-article-mouse-face 'highlight
454 "Face used for mouse highlighting in the article buffer.
456 Article buttons will be displayed in this face when the cursor is
459 :group 'gnus-article-buttons)
461 (defcustom gnus-signature-face 'gnus-signature-face
462 "Face used for highlighting a signature in the article buffer.
463 Obsolete; use the face `gnus-signature-face' for customizations instead."
465 :group 'gnus-article-highlight
466 :group 'gnus-article-signature)
468 (defface gnus-signature-face
471 "Face used for highlighting a signature in the article buffer."
472 :group 'gnus-article-highlight
473 :group 'gnus-article-signature)
475 (defface gnus-header-from-face
478 (:foreground "spring green"))
481 (:foreground "red3"))
484 "Face used for displaying from headers."
485 :group 'gnus-article-headers
486 :group 'gnus-article-highlight)
488 (defface gnus-header-subject-face
491 (:foreground "SeaGreen3"))
494 (:foreground "red4"))
496 (:bold t :italic t)))
497 "Face used for displaying subject headers."
498 :group 'gnus-article-headers
499 :group 'gnus-article-highlight)
501 (defface gnus-header-newsgroups-face
504 (:foreground "yellow" :italic t))
507 (:foreground "MidnightBlue" :italic t))
510 "Face used for displaying newsgroups headers."
511 :group 'gnus-article-headers
512 :group 'gnus-article-highlight)
514 (defface gnus-header-name-face
517 (:foreground "SeaGreen"))
520 (:foreground "maroon"))
523 "Face used for displaying header names."
524 :group 'gnus-article-headers
525 :group 'gnus-article-highlight)
527 (defface gnus-header-content-face
530 (:foreground "forest green" :italic t))
533 (:foreground "indianred4" :italic t))
535 (:italic t))) "Face used for displaying header content."
536 :group 'gnus-article-headers
537 :group 'gnus-article-highlight)
539 (defcustom gnus-header-face-alist
540 '(("From" nil gnus-header-from-face)
541 ("Subject" nil gnus-header-subject-face)
542 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
543 ("" gnus-header-name-face gnus-header-content-face))
544 "*Controls highlighting of article header.
546 An alist of the form (HEADER NAME CONTENT).
548 HEADER is a regular expression which should match the name of an
549 header header and NAME and CONTENT are either face names or nil.
551 The name of each header field will be displayed using the face
552 specified by the first element in the list where HEADER match the
553 header name and NAME is non-nil. Similarly, the content will be
554 displayed by the first non-nil matching CONTENT face."
555 :group 'gnus-article-headers
556 :group 'gnus-article-highlight
557 :type '(repeat (list (regexp :tag "Header")
559 (item :tag "skip" nil)
560 (face :value default))
561 (choice :tag "Content"
562 (item :tag "skip" nil)
563 (face :value default)))))
565 (defcustom gnus-article-decode-hook nil
566 "*Hook run to decode charsets in articles."
567 :group 'gnus-article-headers
570 (defcustom gnus-display-mime-function 'gnus-display-mime
571 "Function to display MIME articles."
572 :group 'gnus-article-mime
575 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
576 "Function used to decode headers.")
578 (defvar gnus-article-dumbquotes-map
597 "Table for MS-to-Latin1 translation.")
599 (defcustom gnus-ignored-mime-types nil
600 "List of MIME types that should be ignored by Gnus."
601 :group 'gnus-article-mime
602 :type '(repeat regexp))
604 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
605 "List of MIME types that should not be given buttons when rendered."
606 :group 'gnus-article-mime
607 :type '(repeat regexp))
609 (defcustom gnus-treat-body-highlight-signature t
610 "Highlight the signature."
612 :type '(choice (const :tag "Off" nil)
614 (const :tag "Last" last)
615 (integer :tag "Less")
616 (sexp :tag "Predicate")))
618 (defcustom gnus-article-mime-part-function nil
619 "Function called with a MIME handle as the argument."
620 :group 'gnus-article-mime
623 ;;; Internal variables
625 (defvar gnus-article-mime-handle-alist-1 nil)
626 (defvar gnus-treatment-function-alist
627 '((gnus-treat-body-highlight-signature gnus-article-highlight-signature nil)
630 (defvar gnus-article-mime-handle-alist nil)
631 (defvar article-lapsed-timer nil)
632 (defvar gnus-article-current-summary nil)
634 (defvar gnus-article-mode-syntax-table
635 (let ((table (copy-syntax-table text-mode-syntax-table)))
636 (modify-syntax-entry ?- "w" table)
637 (modify-syntax-entry ?> ")" table)
638 (modify-syntax-entry ?< "(" table)
640 "Syntax table used in article mode buffers.
641 Initialized from `text-mode-syntax-table.")
643 (defvar gnus-save-article-buffer nil)
645 (defvar gnus-article-mode-line-format-alist
646 (nconc '((?w (gnus-article-wash-status) ?s)
647 (?m (gnus-article-mime-part-status) ?s))
648 gnus-summary-mode-line-format-alist))
650 (defvar gnus-number-of-articles-to-be-saved nil)
652 (defvar gnus-inhibit-hiding nil)
654 (defsubst gnus-article-hide-text (b e props)
655 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
656 (add-text-properties b e props)
657 (when (memq 'intangible props)
659 (max (1- b) (point-min))
660 b 'intangible (cddr (memq 'intangible props)))))
662 (defmacro gnus-with-article (article &rest forms)
663 "Select ARTICLE and perform FORMS in the original article buffer.
664 Then replace the article with the result."
666 ;; We don't want the article to be marked as read.
667 (let (gnus-mark-article-hook)
668 (gnus-summary-select-article t t nil ,article))
669 (set-buffer gnus-original-article-buffer)
671 (if (not (gnus-check-backend-function
672 'request-replace-article (car gnus-article-current)))
673 (gnus-message 5 "Read-only group; not replacing")
674 (unless (gnus-request-replace-article
675 ,article (car gnus-article-current)
677 (error "Couldn't replace article")))
678 ;; The cache and backlog have to be flushed somewhat.
679 (when gnus-keep-backlog
680 (gnus-backlog-remove-article
681 (car gnus-article-current) (cdr gnus-article-current)))
683 (gnus-cache-update-article
684 (car gnus-article-current) (cdr gnus-article-current)))))
686 (put 'gnus-with-article 'lisp-indent-function 1)
687 (put 'gnus-with-article 'edebug-form-spec '(form body))
689 (defsubst gnus-article-unhide-text (b e)
690 "Remove hidden text properties from region between B and E."
691 (remove-text-properties b e gnus-hidden-properties)
692 (when (memq 'intangible gnus-hidden-properties)
693 (put-text-property (max (1- b) (point-min))
696 (defun gnus-article-hide-text-type (b e type)
697 "Hide text of TYPE between B and E."
698 (gnus-article-hide-text
699 b e (cons 'article-type (cons type gnus-hidden-properties))))
701 (defun gnus-article-unhide-text-type (b e type)
702 "Unhide text of TYPE between B and E."
703 (remove-text-properties
704 b e (cons 'article-type (cons type gnus-hidden-properties)))
705 (when (memq 'intangible gnus-hidden-properties)
706 (put-text-property (max (1- b) (point-min))
709 (defun gnus-article-hide-text-of-type (type)
710 "Hide text of TYPE in the current buffer."
712 (let ((b (point-min))
714 (while (setq b (text-property-any b e 'article-type type))
715 (add-text-properties b (incf b) gnus-hidden-properties)))))
717 (defun gnus-article-delete-text-of-type (type)
718 "Delete text of TYPE in the current buffer."
720 (let ((b (point-min)))
721 (while (setq b (text-property-any b (point-max) 'article-type type))
723 b (or (text-property-not-all b (point-max) 'article-type type)
726 (defun gnus-article-delete-invisible-text ()
727 "Delete all invisible text in the current buffer."
729 (let ((b (point-min)))
730 (while (setq b (text-property-any b (point-max) 'invisible t))
732 b (or (text-property-not-all b (point-max) 'invisible t)
735 (defun gnus-article-text-type-exists-p (type)
736 "Say whether any text of type TYPE exists in the buffer."
737 (text-property-any (point-min) (point-max) 'article-type type))
739 (defsubst gnus-article-header-rank ()
740 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
741 (let ((list gnus-sorted-header-list)
744 (when (looking-at (car list))
746 (setq list (cdr list))
750 (defun article-hide-headers (&optional arg delete)
751 "Toggle whether to hide unwanted headers and possibly sort them as well.
752 If given a negative prefix, always show; if given a positive prefix,
754 (interactive (gnus-article-hidden-arg))
756 (if (gnus-article-check-hidden-text 'headers arg)
757 ;; Show boring headers as well.
758 (gnus-article-show-hidden-text 'boring-headers)
759 ;; This function might be inhibited.
760 (unless gnus-inhibit-hiding
763 (let ((buffer-read-only nil)
765 (props (nconc (list 'article-type 'headers)
766 gnus-hidden-properties))
767 (max (1+ (length gnus-sorted-header-list)))
768 (ignored (when (not gnus-visible-headers)
769 (cond ((stringp gnus-ignored-headers)
770 gnus-ignored-headers)
771 ((listp gnus-ignored-headers)
772 (mapconcat 'identity gnus-ignored-headers
775 (cond ((stringp gnus-visible-headers)
776 gnus-visible-headers)
777 ((and gnus-visible-headers
778 (listp gnus-visible-headers))
779 (mapconcat 'identity gnus-visible-headers "\\|"))))
780 (inhibit-point-motion-hooks t)
782 ;; First we narrow to just the headers.
784 (goto-char (point-min))
785 ;; Hide any "From " lines at the beginning of (mail) articles.
786 (while (looking-at "From ")
790 (delete-region (point-min) (point))
791 (gnus-article-hide-text (point-min) (point) props)))
792 ;; Then treat the rest of the header lines.
795 (if (search-forward "\n\n" nil t) ; if there's a body
796 (progn (forward-line -1) (point))
798 ;; Then we use the two regular expressions
799 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
800 ;; select which header lines is to remain visible in the
802 (goto-char (point-min))
803 (while (re-search-forward "^[^ \t]*:" nil t)
805 ;; Mark the rank of the header.
807 (point) (1+ (point)) 'message-rank
808 (if (or (and visible (looking-at visible))
810 (not (looking-at ignored))))
811 (gnus-article-header-rank)
814 (message-sort-headers-1)
815 (when (setq beg (text-property-any
816 (point-min) (point-max) 'message-rank (+ 2 max)))
817 ;; We make the unwanted headers invisible.
819 (delete-region beg (point-max))
820 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
821 (gnus-article-hide-text-type beg (point-max) 'headers))
822 ;; Work around XEmacs lossage.
823 (put-text-property (point-min) beg 'invisible nil))))))))
825 (defun article-hide-boring-headers (&optional arg)
826 "Toggle hiding of headers that aren't very interesting.
827 If given a negative prefix, always show; if given a positive prefix,
829 (interactive (gnus-article-hidden-arg))
830 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
831 (not gnus-show-all-headers))
834 (let ((buffer-read-only nil)
835 (list gnus-boring-article-headers)
836 (inhibit-point-motion-hooks t)
838 (nnheader-narrow-to-headers)
840 (setq elem (pop list))
841 (goto-char (point-min))
843 ;; Hide empty headers.
845 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
847 (gnus-article-hide-text-type
848 (progn (beginning-of-line) (point))
851 (if (re-search-forward "^[^ \t]" nil t)
855 ;; Hide boring Newsgroups header.
856 ((eq elem 'newsgroups)
857 (when (equal (gnus-fetch-field "newsgroups")
858 (gnus-group-real-name
859 (if (boundp 'gnus-newsgroup-name)
862 (gnus-article-hide-header "newsgroups")))
863 ((eq elem 'followup-to)
864 (when (equal (message-fetch-field "followup-to")
865 (message-fetch-field "newsgroups"))
866 (gnus-article-hide-header "followup-to")))
868 (let ((from (message-fetch-field "from"))
869 (reply-to (message-fetch-field "reply-to")))
874 (nth 1 (funcall gnus-extract-address-components from))
875 (nth 1 (funcall gnus-extract-address-components reply-to)))))
876 (gnus-article-hide-header "reply-to"))))
878 (let ((date (message-fetch-field "date")))
880 (< (days-between (current-time-string) date)
882 (gnus-article-hide-header "date"))))
884 (let ((to (message-fetch-field "to")))
885 (when (> (length to) 1024)
886 (gnus-article-hide-header "to"))))
889 (goto-char (point-min))
890 (while (re-search-forward "^to:" nil t)
891 (setq to-count (1+ to-count)))
893 (while (> to-count 0)
894 (goto-char (point-min))
896 (re-search-forward "^to:" nil nil to-count)
898 (narrow-to-region (point) (point-max))
899 (gnus-article-hide-header "to"))
900 (setq to-count (1- to-count)))))))))))))
902 (defun gnus-article-hide-header (header)
904 (goto-char (point-min))
905 (when (re-search-forward (concat "^" header ":") nil t)
906 (gnus-article-hide-text-type
907 (progn (beginning-of-line) (point))
910 (if (re-search-forward "^[^ \t]" nil t)
915 (defvar gnus-article-normalized-header-length 40
916 "Length of normalized headers.")
918 (defun article-normalize-headers ()
919 "Make all header lines 40 characters long."
921 (let ((buffer-read-only nil)
925 (message-narrow-to-head)
928 ((< (setq column (- (gnus-point-at-eol) (point)))
929 gnus-article-normalized-header-length)
932 (- gnus-article-normalized-header-length column)
934 ((> column gnus-article-normalized-header-length)
935 (gnus-put-text-property
937 (forward-char gnus-article-normalized-header-length)
944 (forward-line 1))))))
946 (defun article-treat-dumbquotes ()
947 "Translate M******** sm*rtq**t*s into proper text."
949 (article-translate-strings gnus-article-dumbquotes-map))
951 (defun article-translate-characters (from to)
952 "Translate all characters in the body of the article according to FROM and TO.
953 FROM is a string of characters to translate from; to is a string of
954 characters to translate to."
956 (when (article-goto-body)
957 (let ((buffer-read-only nil)
958 (x (make-string 225 ?x))
960 (while (< (incf i) (length x))
963 (while (< i (length from))
964 (aset x (aref from i) (aref to i))
966 (translate-region (point) (point-max) x)))))
968 (defun article-translate-strings (map)
969 "Translate all string in the body of the article according to MAP.
970 MAP is an alist where the elements are on the form (\"from\" \"to\")."
972 (when (article-goto-body)
973 (let ((buffer-read-only nil)
975 (while (setq elem (pop map))
977 (while (search-forward (car elem) nil t)
978 (replace-match (cadr elem)))))))))
980 (defun article-treat-overstrike ()
981 "Translate overstrikes into bold text."
984 (when (article-goto-body)
985 (let ((buffer-read-only nil))
986 (while (search-forward "\b" nil t)
987 (let ((next (char-after))
988 (previous (char-after (- (point) 2))))
989 ;; We do the boldification/underlining by hiding the
990 ;; overstrikes and putting the proper text property
994 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
995 (put-text-property (point) (1+ (point)) 'face 'bold))
997 (gnus-article-hide-text-type
998 (1- (point)) (1+ (point)) 'overstrike)
1000 (- (point) 2) (1- (point)) 'face 'underline))
1002 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1004 (point) (1+ (point)) 'face 'underline)))))))))
1006 (defun article-fill ()
1007 "Format too long lines."
1010 (let ((buffer-read-only nil))
1014 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
1015 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
1016 (adaptive-fill-mode t))
1018 (and (>= (current-column) (min fill-column (window-width)))
1019 (/= (preceding-char) ?:)
1020 (fill-paragraph nil))
1021 (end-of-line 2))))))
1023 (defun article-remove-cr ()
1024 "Translate CRLF pairs into LF, and then CR into LF.."
1027 (let ((buffer-read-only nil))
1028 (goto-char (point-min))
1029 (while (search-forward "\r$" nil t)
1030 (replace-match "" t t))
1031 (goto-char (point-min))
1032 (while (search-forward "\r" nil t)
1033 (replace-match "\n" t t)))))
1035 (defun article-remove-trailing-blank-lines ()
1036 "Remove all trailing blank lines from the article."
1039 (let ((buffer-read-only nil))
1040 (goto-char (point-max))
1044 (while (and (not (bobp))
1045 (looking-at "^[ \t]*$")
1046 (not (gnus-annotation-in-region-p
1047 (point) (gnus-point-at-eol))))
1052 (defun article-display-x-face (&optional force)
1053 "Look for an X-Face header and display it if present."
1054 (interactive (list 'force))
1056 ;; Delete the old process, if any.
1057 (when (process-status "article-x-face")
1058 (delete-process "article-x-face"))
1059 (let ((inhibit-point-motion-hooks t)
1060 (case-fold-search t)
1063 (nnheader-narrow-to-headers)
1064 (setq from (message-fetch-field "from"))
1065 (goto-char (point-min))
1066 (while (and gnus-article-x-face-command
1069 ;; Check whether this face is censored.
1070 (not gnus-article-x-face-too-ugly)
1071 (and gnus-article-x-face-too-ugly from
1072 (not (string-match gnus-article-x-face-too-ugly
1074 ;; Has to be present.
1075 (re-search-forward "^X-Face: " nil t))
1076 ;; This used to try to do multiple faces (`while' instead of
1077 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1078 ;; work (b) it can crash some versions of Emacs (c) are
1079 ;; multiple faces really something to encourage?
1080 (when (stringp gnus-article-x-face-command)
1082 ;; We now have the area of the buffer where the X-Face is stored.
1085 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1086 ;; We display the face.
1087 (if (symbolp gnus-article-x-face-command)
1088 ;; The command is a lisp function, so we call it.
1089 (if (gnus-functionp gnus-article-x-face-command)
1090 (funcall gnus-article-x-face-command beg end)
1091 (error "%s is not a function" gnus-article-x-face-command))
1092 ;; The command is a string, so we interpret the command
1093 ;; as a, well, command, and fork it off.
1094 (let ((process-connection-type nil))
1095 (process-kill-without-query
1097 "article-x-face" nil shell-file-name shell-command-switch
1098 gnus-article-x-face-command))
1099 (process-send-region "article-x-face" beg end)
1100 (process-send-eof "article-x-face"))))))))))
1102 (defun article-decode-mime-words ()
1103 "Decode all MIME-encoded words in the article."
1106 (set-buffer gnus-article-buffer)
1107 (let ((inhibit-point-motion-hooks t)
1109 (rfc2047-default-charset gnus-newsgroup-default-charset)
1110 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1111 (mail-decode-encoded-word-region (point-min) (point-max)))))
1113 (defun article-decode-charset (&optional prompt)
1114 "Decode charset-encoded text in the article.
1115 If PROMPT (the prefix), prompt for a coding system to use."
1119 (message-narrow-to-head)
1120 (let* ((inhibit-point-motion-hooks t)
1121 (case-fold-search t)
1122 (ct (message-fetch-field "Content-Type" t))
1123 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1124 (ctl (and ct (condition-case ()
1125 (mail-header-parse-content-type ct)
1129 (mm-read-coding-system "Charset to decode: "))
1131 (mail-content-type-get ctl 'charset))))
1132 (rfc2047-default-charset gnus-newsgroup-default-charset)
1133 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced)
1135 (goto-char (point-max))
1138 (narrow-to-region (point) (point-max))
1139 (when (and (or (not ctl)
1140 (equal (car ctl) "text/plain"))
1143 charset (and cte (intern (downcase
1144 (gnus-strip-whitespace cte))))
1147 (defun article-decode-encoded-words ()
1148 "Remove encoded-word encoding from headers."
1149 (let (buffer-read-only)
1150 (let ((charset (save-excursion
1151 (set-buffer gnus-summary-buffer)
1152 default-mime-charset)))
1153 (mime-decode-header-in-buffer charset)
1156 (defun article-de-quoted-unreadable (&optional force)
1157 "Translate a quoted-printable-encoded article.
1158 If FORCE, decode the article whether it is marked as quoted-printable
1160 (interactive (list 'force))
1162 (let ((buffer-read-only nil)
1163 (type (gnus-fetch-field "content-transfer-encoding"))
1165 (or gnus-newsgroup-default-charset mm-default-coding-system))
1166 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
1168 (and type (string-match "quoted-printable" (downcase type))))
1171 (narrow-to-region (point) (point-max))
1172 (quoted-printable-decode-region (point-min) (point-max))
1174 (mm-decode-body charset)))))))
1176 (defun article-hide-pgp (&optional arg)
1177 "Toggle hiding of any PGP headers and signatures in the current article.
1178 If given a negative prefix, always show; if given a positive prefix,
1180 (interactive (gnus-article-hidden-arg))
1181 (unless (gnus-article-check-hidden-text 'pgp arg)
1183 (let ((inhibit-point-motion-hooks t)
1184 buffer-read-only beg end)
1186 (goto-char (point-min))
1187 ;; Hide the "header".
1188 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1189 (delete-region (1+ (match-beginning 0)) (match-end 0))
1190 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1191 (when (looking-at "Hash:.*$")
1192 (delete-region (point) (1+ (gnus-point-at-eol))))
1194 ;; Hide the actual signature.
1195 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1196 (setq end (1+ (match-beginning 0)))
1199 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1201 ;; Perhaps we shouldn't hide to the end of the buffer
1202 ;; if there is no end to the signature?
1204 ;; Hide "- " PGP quotation markers.
1206 (narrow-to-region beg end)
1207 (goto-char (point-min))
1208 (while (re-search-forward "^- " nil t)
1210 (match-beginning 0) (match-end 0)))
1212 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1214 (defun article-hide-pem (&optional arg)
1215 "Toggle hiding of any PEM headers and signatures in the current article.
1216 If given a negative prefix, always show; if given a positive prefix,
1218 (interactive (gnus-article-hidden-arg))
1219 (unless (gnus-article-check-hidden-text 'pem arg)
1221 (let (buffer-read-only end)
1223 (goto-char (point-min))
1224 ;; hide the horrendously ugly "header".
1225 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1228 (setq end (1+ (match-beginning 0)))
1229 (gnus-article-hide-text-type
1231 (if (search-forward "\n\n" nil t)
1235 ;; hide the trailer as well
1236 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1239 (gnus-article-hide-text-type
1240 (match-beginning 0) (match-end 0) 'pem))))))
1242 (defun article-hide-signature (&optional arg)
1243 "Hide the signature in the current article.
1244 If given a negative prefix, always show; if given a positive prefix,
1246 (interactive (gnus-article-hidden-arg))
1247 (unless (gnus-article-check-hidden-text 'signature arg)
1250 (let ((buffer-read-only nil))
1251 (when (gnus-article-narrow-to-signature)
1252 (gnus-article-hide-text-type
1253 (point-min) (point-max) 'signature)))))))
1255 (defun article-strip-leading-blank-lines ()
1256 "Remove all blank lines from the beginning of the article."
1259 (let ((inhibit-point-motion-hooks t)
1261 (when (article-goto-body)
1262 (while (and (not (eobp))
1263 (looking-at "[ \t]*$"))
1264 (gnus-delete-line))))))
1266 (defun article-goto-body ()
1267 "Place point at the start of the body."
1268 (goto-char (point-min))
1269 (if (search-forward "\n\n" nil t)
1271 (goto-char (point-max))
1274 (defun article-strip-multiple-blank-lines ()
1275 "Replace consecutive blank lines with one empty line."
1278 (let ((inhibit-point-motion-hooks t)
1280 ;; First make all blank lines empty.
1282 (while (re-search-forward "^[ \t]+$" nil t)
1283 (unless (gnus-annotation-in-region-p
1284 (match-beginning 0) (match-end 0))
1285 (replace-match "" nil t)))
1286 ;; Then replace multiple empty lines with a single empty line.
1288 (while (re-search-forward "\n\n\n+" nil t)
1289 (unless (gnus-annotation-in-region-p
1290 (match-beginning 0) (match-end 0))
1291 (replace-match "\n\n" t t))))))
1293 (defun article-strip-leading-space ()
1294 "Remove all white space from the beginning of the lines in the article."
1297 (let ((inhibit-point-motion-hooks t)
1300 (while (re-search-forward "^[ \t]+" nil t)
1301 (replace-match "" t t)))))
1303 (defun article-strip-trailing-space ()
1304 "Remove all white space from the end of the lines in the article."
1307 (let ((inhibit-point-motion-hooks t)
1310 (while (re-search-forward "[ \t]+$" nil t)
1311 (replace-match "" t t)))))
1313 (defun article-strip-blank-lines ()
1314 "Strip leading, trailing and multiple blank lines."
1316 (article-strip-leading-blank-lines)
1317 (article-remove-trailing-blank-lines)
1318 (article-strip-multiple-blank-lines))
1320 (defun article-strip-all-blank-lines ()
1321 "Strip all blank lines."
1324 (let ((inhibit-point-motion-hooks t)
1327 (while (re-search-forward "^[ \t]*\n" nil t)
1328 (replace-match "" t t)))))
1330 (defun gnus-article-narrow-to-signature ()
1331 "Narrow to the signature; return t if a signature is found, else nil."
1333 (let ((inhibit-point-motion-hooks t))
1334 (when (gnus-article-search-signature)
1336 ;; Check whether we have some limits to what we consider
1337 ;; to be a signature.
1338 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1339 (list gnus-signature-limit)))
1341 (while (setq limit (pop limits))
1342 (if (or (and (integerp limit)
1343 (< (- (point-max) (point)) limit))
1345 (< (count-lines (point) (point-max)) limit))
1346 (and (gnus-functionp limit)
1348 (and (stringp limit)
1349 (not (re-search-forward limit nil t))))
1350 () ; This limit did not succeed.
1354 (narrow-to-region (point) (point-max))
1357 (defun gnus-article-search-signature ()
1358 "Search the current buffer for the signature separator.
1359 Put point at the beginning of the signature separator."
1360 (let ((cur (point)))
1361 (goto-char (point-max))
1362 (if (if (stringp gnus-signature-separator)
1363 (re-search-backward gnus-signature-separator nil t)
1364 (let ((seps gnus-signature-separator))
1366 (not (re-search-backward (car seps) nil t)))
1374 (autoload 'w3-display "w3-parse")
1375 (autoload 'w3-do-setup "w3" "" t)
1376 (autoload 'w3-region "w3-display" "" t))
1378 (defun gnus-article-treat-html ()
1381 (let ((cbuf (current-buffer)))
1382 (set-buffer gnus-article-buffer)
1383 (let (buf buffer-read-only b e)
1385 (goto-char (point-min))
1387 (if (search-forward "\n\n" nil t)
1390 (setq e (point-max)))
1392 (insert-buffer-substring gnus-article-buffer b e)
1394 (save-window-excursion
1395 (w3-region (point-min) (point-max))
1396 (setq buf (buffer-substring-no-properties (point-min) (point-max)))))
1398 (delete-region (point-min) (point-max))
1401 (goto-char (point-min))
1402 (set-window-start (get-buffer-window (current-buffer)) (point-min))
1403 (set-buffer cbuf))))
1405 (defun gnus-article-hidden-arg ()
1406 "Return the current prefix arg as a number, or 0 if no prefix."
1407 (list (if current-prefix-arg
1408 (prefix-numeric-value current-prefix-arg)
1411 (defun gnus-article-check-hidden-text (type arg)
1412 "Return nil if hiding is necessary.
1413 Arg can be nil or a number. Nil and positive means hide, negative
1414 means show, 0 means toggle."
1418 (let ((hide (gnus-article-hidden-text-p type)))
1424 (gnus-article-show-hidden-text type))
1426 (if (eq hide 'hidden)
1427 (gnus-article-show-hidden-text type)
1430 (defun gnus-article-hidden-text-p (type)
1431 "Say whether the current buffer contains hidden text of type TYPE."
1432 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1434 (not (get-text-property pos 'invisible)))
1436 (text-property-any (1+ pos) (point-max) 'article-type type)))
1441 (defun gnus-article-show-hidden-text (type &optional hide)
1442 "Show all hidden text of type TYPE.
1443 If HIDE, hide the text instead."
1445 (let ((buffer-read-only nil)
1446 (inhibit-point-motion-hooks t)
1449 (while (setq beg (text-property-any end (point-max) 'article-type type))
1452 (text-property-not-all beg (point-max) 'article-type type)
1455 (gnus-article-hide-text beg end gnus-hidden-properties)
1456 (gnus-article-unhide-text beg end))
1460 (defconst article-time-units
1461 `((year . ,(* 365.25 24 60 60))
1462 (week . ,(* 7 24 60 60))
1463 (day . ,(* 24 60 60))
1467 "Mapping from time units to seconds.")
1469 (defun article-date-ut (&optional type highlight header)
1470 "Convert DATE date to universal time in the current article.
1471 If TYPE is `local', convert to local time; if it is `lapsed', output
1472 how much time has lapsed since DATE."
1473 (interactive (list 'ut t))
1474 (let* ((header (or header
1475 (mail-header-date gnus-current-headers)
1476 (message-fetch-field "date")
1478 (date (if (vectorp header) (mail-header-date header)
1480 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1481 (inhibit-point-motion-hooks t)
1482 bface eface newline)
1483 (when (and date (not (string= date "")))
1486 (nnheader-narrow-to-headers)
1487 (let ((buffer-read-only nil))
1488 ;; Delete any old Date headers.
1489 (if (re-search-forward date-regexp nil t)
1491 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1492 eface (get-text-property (1- (gnus-point-at-eol))
1494 (delete-region (progn (beginning-of-line) (point))
1495 (progn (end-of-line) (point)))
1496 (beginning-of-line))
1497 (goto-char (point-max))
1499 (insert (article-make-date-line date type))
1502 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1503 (put-text-property (match-beginning 1) (1+ (match-end 1))
1505 (put-text-property (match-beginning 2) (match-end 2)
1509 (insert "\n"))))))))
1511 (defun article-make-date-line (date type)
1512 "Return a DATE line of TYPE."
1513 (let ((time (condition-case ()
1517 ;; Convert to the local timezone. We have to slap a
1518 ;; `condition-case' round the calls to the timezone
1519 ;; functions since they aren't particularly resistant to
1522 (let ((tz (car (current-time-zone))))
1523 (format "Date: %s %s%04d" (current-time-string time)
1524 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1525 ;; Convert to Universal Time.
1528 (current-time-string
1529 (let* ((e (parse-time-string date))
1530 (tm (apply 'encode-time e))
1532 (ls (- (cadr tm) (car (current-time-zone)))))
1533 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1534 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1537 ;; Get the original date from the article.
1538 ((eq type 'original)
1539 (concat "Date: " (if (string-match "\n+$" date)
1540 (substring date 0 (match-beginning 0))
1542 ;; Let the user define the format.
1544 (if (gnus-functionp gnus-article-time-format)
1545 (funcall gnus-article-time-format time)
1548 (format-time-string gnus-article-time-format time))))
1553 (format-time-string "%Y%M%DT%h%m%s" time)))
1554 ;; Do an X-Sent lapsed format.
1556 ;; If the date is seriously mangled, the timezone functions are
1557 ;; liable to bug out, so we ignore all errors.
1558 (let* ((now (current-time))
1559 (real-time (subtract-time now time))
1560 (real-sec (and real-time
1561 (+ (* (float (car real-time)) 65536)
1563 (sec (and real-time (abs real-sec)))
1573 ;; This is a bit convoluted, but basically we go
1574 ;; through the time units for years, weeks, etc,
1575 ;; and divide things to see whether that results
1576 ;; in positive answers.
1579 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1580 ;; The (remaining) seconds are too few to
1581 ;; be divided into this time unit.
1583 ;; It's big enough, so we output it.
1584 (setq sec (- sec (* num (cdr unit))))
1586 (concat (if prev ", " "") (int-to-string
1588 " " (symbol-name (car unit))
1589 (if (> num 1) "s" ""))
1591 article-time-units "")
1592 ;; If dates are odd, then it might appear like the
1593 ;; article was sent in the future.
1596 " in the future"))))))
1598 (error "Unknown conversion type: %s" type)))))
1600 (defun article-date-local (&optional highlight)
1601 "Convert the current article date to the local timezone."
1602 (interactive (list t))
1603 (article-date-ut 'local highlight))
1605 (defun article-date-original (&optional highlight)
1606 "Convert the current article date to what it was originally.
1607 This is only useful if you have used some other date conversion
1608 function and want to see what the date was before converting."
1609 (interactive (list t))
1610 (article-date-ut 'original highlight))
1612 (defun article-date-lapsed (&optional highlight)
1613 "Convert the current article date to time lapsed since it was sent."
1614 (interactive (list t))
1615 (article-date-ut 'lapsed highlight))
1617 (defun article-update-date-lapsed ()
1618 "Function to be run from a timer to update the lapsed time line."
1619 (let (deactivate-mark)
1624 (set-buffer (window-buffer w))
1625 (when (eq major-mode 'gnus-article-mode)
1626 (goto-char (point-min))
1627 (when (re-search-forward "^X-Sent:" nil t)
1628 (article-date-lapsed t)))))))))
1630 (defun gnus-start-date-timer (&optional n)
1631 "Start a timer to update the X-Sent header in the article buffers.
1632 The numerical prefix says how frequently (in seconds) the function
1637 (gnus-stop-date-timer)
1638 (setq article-lapsed-timer
1639 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1641 (defun gnus-stop-date-timer ()
1642 "Stop the X-Sent timer."
1644 (when article-lapsed-timer
1645 (nnheader-cancel-timer article-lapsed-timer)
1646 (setq article-lapsed-timer nil)))
1648 (defun article-date-user (&optional highlight)
1649 "Convert the current article date to the user-defined format.
1650 This format is defined by the `gnus-article-time-format' variable."
1651 (interactive (list t))
1652 (article-date-ut 'user highlight))
1654 (defun article-date-iso8601 (&optional highlight)
1655 "Convert the current article date to ISO8601."
1656 (interactive (list t))
1657 (article-date-ut 'iso8601 highlight))
1659 (defun article-show-all ()
1660 "Show all hidden text in the article buffer."
1663 (let ((buffer-read-only nil))
1664 (gnus-article-unhide-text (point-min) (point-max)))))
1666 (defun article-emphasize (&optional arg)
1667 "Emphasize text according to `gnus-emphasis-alist'."
1668 (interactive (gnus-article-hidden-arg))
1669 (unless (gnus-article-check-hidden-text 'emphasis arg)
1671 (let ((alist gnus-emphasis-alist)
1672 (buffer-read-only nil)
1673 (props (append '(article-type emphasis)
1674 gnus-hidden-properties))
1675 regexp elem beg invisible visible face)
1678 (while (setq elem (pop alist))
1680 (setq regexp (car elem)
1681 invisible (nth 1 elem)
1682 visible (nth 2 elem)
1684 (while (re-search-forward regexp nil t)
1685 (when (and (match-beginning visible) (match-beginning invisible))
1686 (gnus-article-hide-text
1687 (match-beginning invisible) (match-end invisible) props)
1688 (gnus-article-unhide-text-type
1689 (match-beginning visible) (match-end visible) 'emphasis)
1690 (gnus-put-text-property-excluding-newlines
1691 (match-beginning visible) (match-end visible) 'face face)
1692 (goto-char (match-end invisible)))))))))
1694 (defvar gnus-summary-article-menu)
1695 (defvar gnus-summary-post-menu)
1697 ;;; Saving functions.
1699 (defun gnus-article-save (save-buffer file &optional num)
1700 "Save the currently selected article."
1701 (unless gnus-save-all-headers
1702 ;; Remove headers according to `gnus-saved-headers'.
1703 (let ((gnus-visible-headers
1704 (or gnus-saved-headers gnus-visible-headers))
1705 (gnus-article-buffer save-buffer))
1707 (set-buffer save-buffer)
1708 (article-hide-headers 1 t))))
1709 (save-window-excursion
1710 (if (not gnus-default-article-saver)
1711 (error "No default saver is defined")
1712 ;; !!! Magic! The saving functions all save
1713 ;; `gnus-save-article-buffer' (or so they think), but we
1714 ;; bind that variable to our save-buffer.
1715 (set-buffer gnus-article-buffer)
1716 (let* ((gnus-save-article-buffer save-buffer)
1719 ((not gnus-prompt-before-saving) 'default)
1720 ((eq gnus-prompt-before-saving 'always) nil)
1722 (gnus-number-of-articles-to-be-saved
1723 (when (eq gnus-prompt-before-saving t)
1725 (set-buffer gnus-article-current-summary)
1726 (funcall gnus-default-article-saver filename)))))
1728 (defun gnus-read-save-file-name (prompt &optional filename
1729 function group headers variable)
1731 (funcall function group headers (symbol-value variable)))
1736 ((eq filename 'default)
1742 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1745 (if (and gnus-number-of-articles-to-be-saved
1746 (> gnus-number-of-articles-to-be-saved 1))
1747 (format "these %d articles"
1748 gnus-number-of-articles-to-be-saved)
1751 ;; Let the split methods have their say.
1753 ;; No split name was found.
1756 (concat prompt " (default "
1757 (file-name-nondirectory default-name) ") ")
1758 (file-name-directory default-name)
1760 ;; A single group name is returned.
1761 ((stringp split-name)
1763 (funcall function split-name headers
1764 (symbol-value variable)))
1766 (concat prompt " (default "
1767 (file-name-nondirectory default-name) ") ")
1768 (file-name-directory default-name)
1770 ;; A single split name was found
1771 ((= 1 (length split-name))
1772 (let* ((name (expand-file-name
1773 (car split-name) gnus-article-save-directory))
1774 (dir (cond ((file-directory-p name)
1775 (file-name-as-directory name))
1776 ((file-exists-p name) name)
1777 (t gnus-article-save-directory))))
1779 (concat prompt " (default " name ") ")
1781 ;; A list of splits was found.
1783 (setq split-name (nreverse split-name))
1785 (let ((file-name-history
1786 (nconc split-name file-name-history)))
1790 (concat prompt " (`M-p' for defaults) ")
1791 gnus-article-save-directory
1793 gnus-article-save-directory)))
1794 (car (push result file-name-history)))))))
1795 ;; Create the directory.
1796 (gnus-make-directory (file-name-directory file))
1797 ;; If we have read a directory, we append the default file name.
1798 (when (file-directory-p file)
1799 (setq file (concat (file-name-as-directory file)
1800 (file-name-nondirectory default-name))))
1801 ;; Possibly translate some characters.
1802 (nnheader-translate-file-chars file)))))
1803 (gnus-make-directory (file-name-directory result))
1804 (set variable result)))
1806 (defun gnus-article-archive-name (group)
1807 "Return the first instance of an \"Archive-name\" in the current buffer."
1808 (let ((case-fold-search t))
1809 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
1810 (nnheader-concat gnus-article-save-directory
1811 (match-string 1)))))
1813 (defun gnus-article-nndoc-name (group)
1814 "If GROUP is an nndoc group, return the name of the parent group."
1815 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
1816 (gnus-group-get-parameter group 'save-article-group)))
1818 (defun gnus-summary-save-in-rmail (&optional filename)
1819 "Append this article to Rmail file.
1820 Optional argument FILENAME specifies file name.
1821 Directory to save to is default to `gnus-article-save-directory'."
1822 (setq filename (gnus-read-save-file-name
1823 "Save %s in rmail file:" filename
1824 gnus-rmail-save-name gnus-newsgroup-name
1825 gnus-current-headers 'gnus-newsgroup-last-rmail))
1826 (gnus-eval-in-buffer-window gnus-save-article-buffer
1830 (gnus-output-to-rmail filename))))
1833 (defun gnus-summary-save-in-mail (&optional filename)
1834 "Append this article to Unix mail file.
1835 Optional argument FILENAME specifies file name.
1836 Directory to save to is default to `gnus-article-save-directory'."
1837 (setq filename (gnus-read-save-file-name
1838 "Save %s in Unix mail file:" filename
1839 gnus-mail-save-name gnus-newsgroup-name
1840 gnus-current-headers 'gnus-newsgroup-last-mail))
1841 (gnus-eval-in-buffer-window gnus-save-article-buffer
1845 (if (and (file-readable-p filename)
1846 (mail-file-babyl-p filename))
1847 (rmail-output-to-rmail-file filename t)
1848 (gnus-output-to-mail filename)))))
1851 (defun gnus-summary-save-in-file (&optional filename overwrite)
1852 "Append this article to file.
1853 Optional argument FILENAME specifies file name.
1854 Directory to save to is default to `gnus-article-save-directory'."
1855 (setq filename (gnus-read-save-file-name
1856 "Save %s in file:" filename
1857 gnus-file-save-name gnus-newsgroup-name
1858 gnus-current-headers 'gnus-newsgroup-last-file))
1859 (gnus-eval-in-buffer-window gnus-save-article-buffer
1863 (when (and overwrite
1864 (file-exists-p filename))
1865 (delete-file filename))
1866 (gnus-output-to-file filename))))
1869 (defun gnus-summary-write-to-file (&optional filename)
1870 "Write this article to a file.
1871 Optional argument FILENAME specifies file name.
1872 The directory to save in defaults to `gnus-article-save-directory'."
1873 (gnus-summary-save-in-file nil t))
1875 (defun gnus-summary-save-body-in-file (&optional filename)
1876 "Append this article body to a file.
1877 Optional argument FILENAME specifies file name.
1878 The directory to save in defaults to `gnus-article-save-directory'."
1879 (setq filename (gnus-read-save-file-name
1880 "Save %s body in file:" filename
1881 gnus-file-save-name gnus-newsgroup-name
1882 gnus-current-headers 'gnus-newsgroup-last-file))
1883 (gnus-eval-in-buffer-window gnus-save-article-buffer
1887 (when (article-goto-body)
1888 (narrow-to-region (point) (point-max)))
1889 (gnus-output-to-file filename))))
1892 (defun gnus-summary-save-in-pipe (&optional command)
1893 "Pipe this article to subprocess."
1895 (cond ((and (eq command 'default)
1896 gnus-last-shell-command)
1897 gnus-last-shell-command)
1901 "Shell command on %s: "
1902 (if (and gnus-number-of-articles-to-be-saved
1903 (> gnus-number-of-articles-to-be-saved 1))
1904 (format "these %d articles"
1905 gnus-number-of-articles-to-be-saved)
1907 gnus-last-shell-command))))
1908 (when (string-equal command "")
1909 (setq command gnus-last-shell-command))
1910 (gnus-eval-in-buffer-window gnus-article-buffer
1913 (shell-command-on-region (point-min) (point-max) command nil)))
1914 (setq gnus-last-shell-command command))
1916 ;;; Article file names when saving.
1918 (defun gnus-capitalize-newsgroup (newsgroup)
1919 "Capitalize NEWSGROUP name."
1920 (when (not (zerop (length newsgroup)))
1921 (concat (char-to-string (upcase (aref newsgroup 0)))
1922 (substring newsgroup 1))))
1924 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
1925 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1926 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
1927 Otherwise, it is like ~/News/news/group/num."
1930 (concat (if (gnus-use-long-file-name 'not-save)
1931 (gnus-capitalize-newsgroup newsgroup)
1932 (gnus-newsgroup-directory-form newsgroup))
1933 "/" (int-to-string (mail-header-number headers)))
1934 gnus-article-save-directory)))
1936 (string-equal (file-name-directory default)
1937 (file-name-directory last-file))
1938 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1940 (or last-file default))))
1942 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
1943 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1944 If variable `gnus-use-long-file-name' is non-nil, it is
1945 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
1948 (concat (if (gnus-use-long-file-name 'not-save)
1950 (gnus-newsgroup-directory-form newsgroup))
1951 "/" (int-to-string (mail-header-number headers)))
1952 gnus-article-save-directory)))
1954 (string-equal (file-name-directory default)
1955 (file-name-directory last-file))
1956 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
1958 (or last-file default))))
1960 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
1961 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1962 If variable `gnus-use-long-file-name' is non-nil, it is
1963 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
1966 (if (gnus-use-long-file-name 'not-save)
1967 (gnus-capitalize-newsgroup newsgroup)
1968 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1969 gnus-article-save-directory)))
1971 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
1972 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
1973 If variable `gnus-use-long-file-name' is non-nil, it is
1974 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
1977 (if (gnus-use-long-file-name 'not-save)
1979 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
1980 gnus-article-save-directory)))
1987 (setq afunc (car func)
1990 gfunc (intern (format "gnus-%s" func))))
1992 (if (not (fboundp afunc))
1994 `(lambda (&optional interactive &rest args)
1995 ,(documentation afunc t)
1996 (interactive (list t))
1998 (set-buffer gnus-article-buffer)
2000 (call-interactively ',afunc)
2001 (apply ',afunc args))))))))
2002 '(article-hide-headers
2003 article-hide-boring-headers
2004 article-treat-overstrike
2005 (article-fill . gnus-article-word-wrap)
2007 article-display-x-face
2008 article-de-quoted-unreadable
2009 article-mime-decode-quoted-printable
2012 article-hide-signature
2013 article-remove-trailing-blank-lines
2014 article-strip-leading-blank-lines
2015 article-strip-multiple-blank-lines
2016 article-strip-leading-space
2017 article-strip-trailing-space
2018 article-strip-blank-lines
2019 article-strip-all-blank-lines
2021 article-date-iso8601
2022 article-date-original
2024 article-decode-mime-words
2025 article-decode-charset
2026 article-decode-encoded-words
2030 article-treat-dumbquotes
2031 article-normalize-headers
2032 (article-show-all . gnus-article-show-all-headers))))
2035 ;;; Gnus article mode
2038 (put 'gnus-article-mode 'mode-class 'special)
2040 (gnus-define-keys gnus-article-mode-map
2041 " " gnus-article-goto-next-page
2042 "\177" gnus-article-goto-prev-page
2043 [delete] gnus-article-goto-prev-page
2044 "\C-c^" gnus-article-refer-article
2045 "h" gnus-article-show-summary
2046 "s" gnus-article-show-summary
2047 "\C-c\C-m" gnus-article-mail
2048 "?" gnus-article-describe-briefly
2049 gnus-mouse-2 gnus-article-push-button
2050 "\r" gnus-article-press-button
2051 "\t" gnus-article-next-button
2052 "\M-\t" gnus-article-prev-button
2053 "e" gnus-article-edit
2054 "<" beginning-of-buffer
2056 "\C-c\C-i" gnus-info-find-node
2059 "\C-d" gnus-article-read-summary-keys
2060 "\M-*" gnus-article-read-summary-keys
2061 "\M-#" gnus-article-read-summary-keys
2062 "\M-^" gnus-article-read-summary-keys
2063 "\M-g" gnus-article-read-summary-keys)
2065 (substitute-key-definition
2066 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2068 (defun gnus-article-make-menu-bar ()
2069 (gnus-turn-off-edit-menu 'article)
2070 (unless (boundp 'gnus-article-article-menu)
2072 gnus-article-article-menu gnus-article-mode-map ""
2074 ["Scroll forwards" gnus-article-goto-next-page t]
2075 ["Scroll backwards" gnus-article-goto-prev-page t]
2076 ["Show summary" gnus-article-show-summary t]
2077 ["Fetch Message-ID at point" gnus-article-refer-article t]
2078 ["Mail to address at point" gnus-article-mail t]
2079 ["Send a bug report" gnus-bug t]))
2082 gnus-article-treatment-menu gnus-article-mode-map ""
2084 ["Hide headers" gnus-article-hide-headers t]
2085 ["Hide signature" gnus-article-hide-signature t]
2086 ["Hide citation" gnus-article-hide-citation t]
2087 ["Treat overstrike" gnus-article-treat-overstrike t]
2088 ["Remove carriage return" gnus-article-remove-cr t]))
2090 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2092 (when (boundp 'gnus-summary-post-menu)
2093 (define-key gnus-article-mode-map [menu-bar post]
2094 (cons "Post" gnus-summary-post-menu)))
2096 (gnus-run-hooks 'gnus-article-menu-hook)))
2098 (defun gnus-article-mode ()
2099 "Major mode for displaying an article.
2101 All normal editing commands are switched off.
2103 The following commands are available in addition to all summary mode
2105 \\<gnus-article-mode-map>
2106 \\[gnus-article-next-page]\t Scroll the article one page forwards
2107 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2108 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2109 \\[gnus-article-show-summary]\t Display the summary buffer
2110 \\[gnus-article-mail]\t Send a reply to the address near point
2111 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2112 \\[gnus-info-find-node]\t Go to the Gnus info node"
2114 (when (gnus-visual-p 'article-menu 'menu)
2115 (gnus-article-make-menu-bar))
2116 (gnus-simplify-mode-line)
2117 (setq mode-name "Article")
2118 (setq major-mode 'gnus-article-mode)
2119 (make-local-variable 'minor-mode-alist)
2120 (unless (assq 'gnus-show-mime minor-mode-alist)
2121 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2122 (use-local-map gnus-article-mode-map)
2123 (gnus-update-format-specifications nil 'article-mode)
2124 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2125 (make-local-variable 'gnus-page-broken)
2126 (make-local-variable 'gnus-button-marker-list)
2127 (make-local-variable 'gnus-article-current-summary)
2128 (make-local-variable 'gnus-article-mime-handles)
2129 (make-local-variable 'gnus-article-decoded-p)
2130 (make-local-variable 'gnus-article-mime-handle-alist)
2131 (gnus-set-default-directory)
2132 (buffer-disable-undo)
2133 (setq buffer-read-only t)
2134 (set-syntax-table gnus-article-mode-syntax-table)
2135 (gnus-run-hooks 'gnus-article-mode-hook))
2137 (defun gnus-article-setup-buffer ()
2138 "Initialize the article buffer."
2139 (let* ((name (if gnus-single-article-buffer "*Article*"
2140 (concat "*Article " gnus-newsgroup-name "*")))
2142 (progn (string-match "\\*Article" name)
2143 (concat " *Original Article"
2144 (substring name (match-end 0))))))
2145 (setq gnus-article-buffer name)
2146 (setq gnus-original-article-buffer original)
2147 (setq gnus-article-mime-handle-alist nil)
2148 ;; This might be a variable local to the summary buffer.
2149 (unless gnus-single-article-buffer
2151 (set-buffer gnus-summary-buffer)
2152 (setq gnus-article-buffer name)
2153 (setq gnus-original-article-buffer original)
2154 (gnus-set-global-variables)))
2155 ;; Init original article buffer.
2157 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2158 (setq major-mode 'gnus-original-article-mode)
2159 (make-local-variable 'gnus-original-article))
2160 (if (get-buffer name)
2163 (buffer-disable-undo)
2164 (setq buffer-read-only t)
2165 (unless (eq major-mode 'gnus-article-mode)
2166 (gnus-article-mode))
2169 (set-buffer (gnus-get-buffer-create name))
2171 (make-local-variable 'gnus-summary-buffer)
2172 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2173 (current-buffer)))))
2175 ;; Set article window start at LINE, where LINE is the number of lines
2176 ;; from the head of the article.
2177 (defun gnus-article-set-window-start (&optional line)
2179 (get-buffer-window gnus-article-buffer t)
2181 (set-buffer gnus-article-buffer)
2182 (goto-char (point-min))
2185 (gnus-message 6 "Moved to bookmark")
2186 (search-forward "\n\n" nil t)
2190 ;;; @@ article filters
2193 (defun gnus-article-display-mime-message ()
2194 "Article display method for MIME message."
2195 ;; called from `gnus-original-article-buffer'.
2196 (let ((charset (with-current-buffer gnus-summary-buffer
2197 default-mime-charset)))
2198 (make-local-variable 'default-mime-charset)
2199 (setq default-mime-charset charset)
2200 (mime-display-message mime-message-structure
2201 gnus-article-buffer nil gnus-article-mode-map)
2202 (make-local-variable 'default-mime-charset)
2203 (setq default-mime-charset charset)
2205 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2206 (make-local-variable 'mime-button-mother-dispatcher)
2207 (setq mime-button-mother-dispatcher
2208 (function gnus-article-push-button))
2209 (run-hooks 'gnus-mime-article-prepare-hook))
2211 (defun gnus-article-display-traditional-message ()
2212 "Article display method for traditional message."
2213 (set-buffer gnus-article-buffer)
2214 (let (buffer-read-only)
2216 (insert-buffer-substring gnus-original-article-buffer)))
2218 (defun gnus-article-make-full-mail-header (&optional number charset)
2219 "Create a new mail header structure in a raw article buffer."
2220 (unless (and number charset)
2221 (save-current-buffer
2222 (set-buffer gnus-summary-buffer)
2224 (setq number (or (cdr gnus-article-current) 0)))
2226 (setq charset (or default-mime-charset 'x-ctext)))))
2227 (goto-char (point-min))
2228 (let ((header-end (if (search-forward "\n\n" nil t)
2230 (goto-char (point-max))))
2231 (chars (- (point-max) (point)))
2232 (lines (count-lines (point) (point-max)))
2233 (default-mime-charset charset)
2235 (narrow-to-region (point-min) header-end)
2236 (setq xref (std11-fetch-field "xref"))
2238 (make-full-mail-header
2240 (std11-fetch-field "subject")
2241 (std11-fetch-field "from")
2242 (std11-fetch-field "date")
2243 (std11-fetch-field "message-id")
2244 (std11-fetch-field "references")
2247 (when xref (concat "Xref: " xref)))
2250 (defun gnus-article-prepare (article &optional all-headers header)
2251 "Prepare ARTICLE in article mode buffer.
2252 ARTICLE should either be an article number or a Message-ID.
2253 If ARTICLE is an id, HEADER should be the article headers.
2254 If ALL-HEADERS is non-nil, no headers are hidden."
2256 ;; Make sure we start in a summary buffer.
2257 (unless (eq major-mode 'gnus-summary-mode)
2258 (set-buffer gnus-summary-buffer))
2259 (setq gnus-summary-buffer (current-buffer))
2260 (let* ((gnus-article (if header (mail-header-number header) article))
2261 (summary-buffer (current-buffer))
2262 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2263 (group gnus-newsgroup-name)
2266 (gnus-article-setup-buffer)
2267 (set-buffer gnus-original-article-buffer)
2268 ;; Deactivate active regions.
2269 (when (and (boundp 'transient-mark-mode)
2270 transient-mark-mode)
2271 (setq mark-active nil))
2272 (if (not (setq result (let ((buffer-read-only nil))
2273 (gnus-request-article-this-buffer
2275 ;; There is no such article.
2277 (when (and (numberp article)
2278 (not (memq article gnus-newsgroup-sparse)))
2279 (setq gnus-article-current
2280 (cons gnus-newsgroup-name article))
2281 (set-buffer gnus-summary-buffer)
2282 (setq gnus-current-article article)
2283 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2285 (gnus-summary-set-agent-mark article)
2286 (message "Message marked for downloading"))
2287 (gnus-summary-mark-article article gnus-canceled-mark)
2288 (unless (memq article gnus-newsgroup-sparse)
2290 "No such article (may have expired or been canceled)")))))
2291 (if (or (eq result 'pseudo)
2292 (eq result 'nneething))
2295 (set-buffer summary-buffer)
2296 (push article gnus-newsgroup-history)
2297 (setq gnus-last-article gnus-current-article
2298 gnus-current-article 0
2299 gnus-current-headers nil
2300 gnus-article-current nil)
2301 (if (eq result 'nneething)
2302 (gnus-configure-windows 'summary)
2303 (gnus-configure-windows 'article))
2304 (gnus-set-global-variables))
2305 (let ((gnus-article-mime-handle-alist-1
2306 gnus-article-mime-handle-alist))
2307 (gnus-set-mode-line 'article)))
2308 ;; The result from the `request' was an actual article -
2309 ;; or at least some text that is now displayed in the
2311 (when (and (numberp article)
2312 (not (eq article gnus-current-article)))
2313 ;; Seems like a new article has been selected.
2314 ;; `gnus-current-article' must be an article number.
2316 (set-buffer summary-buffer)
2317 (push article gnus-newsgroup-history)
2318 (setq gnus-last-article gnus-current-article
2319 gnus-current-article article
2320 gnus-current-headers
2321 (gnus-summary-article-header gnus-current-article)
2322 gnus-article-current
2323 (cons gnus-newsgroup-name gnus-current-article))
2324 (unless (vectorp gnus-current-headers)
2325 (setq gnus-current-headers nil))
2326 (gnus-summary-goto-subject gnus-current-article)
2327 (when (gnus-summary-show-thread)
2328 ;; If the summary buffer really was folded, the
2329 ;; previous goto may not actually have gone to
2330 ;; the right article, but the thread root instead.
2332 (gnus-summary-goto-subject gnus-current-article))
2333 (gnus-run-hooks 'gnus-mark-article-hook)
2334 (gnus-set-mode-line 'summary)
2335 (when (gnus-visual-p 'article-highlight 'highlight)
2336 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2337 ;; Set the global newsgroup variables here.
2338 ;; Suggested by Jim Sisolak
2339 ;; <sisolak@trans4.neep.wisc.edu>.
2340 (gnus-set-global-variables)
2341 (setq gnus-have-all-headers
2342 (or all-headers gnus-show-all-headers))))
2343 (when (or (numberp article)
2345 (gnus-article-prepare-display)
2347 (goto-char (point-min))
2348 (setq gnus-page-broken
2349 (when gnus-break-pages
2350 (gnus-narrow-to-page)
2352 (let ((gnus-article-mime-handle-alist-1
2353 gnus-article-mime-handle-alist))
2354 (gnus-set-mode-line 'article))
2355 (gnus-configure-windows 'article)
2357 (set-window-point (get-buffer-window (current-buffer)) (point))
2360 (defun gnus-article-prepare-display ()
2361 "Make the current buffer look like a nice article."
2365 (setq mime-message-structure gnus-current-headers)
2366 gnus-article-display-method-for-mime)
2367 gnus-article-display-method-for-traditional)))
2368 (gnus-run-hooks 'gnus-tmp-internal-hook)
2369 (gnus-run-hooks 'gnus-article-prepare-hook)
2372 ;; Associate this article with the current summary buffer.
2373 (setq gnus-article-current-summary (current-buffer))
2374 ;; Perform the article display hooks.
2375 (gnus-run-hooks 'gnus-article-display-hook)))
2378 ;;; Gnus MIME viewing functions
2381 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2382 "The following specs can be used:
2384 %T MIME type, along with additional info
2385 %n The `name' parameter
2386 %d The description, if any
2387 %l The length of the encoded part
2388 %p The part identifier number
2389 %e Dots if the part isn't displayed")
2391 (defvar gnus-mime-button-line-format-alist
2392 '((?t gnus-tmp-type ?s)
2393 (?T gnus-tmp-type-long ?s)
2394 (?n gnus-tmp-name ?s)
2395 (?d gnus-tmp-description ?s)
2397 (?l gnus-tmp-length ?d)
2398 (?e gnus-tmp-dots ?s)))
2400 (defvar gnus-mime-button-commands
2401 '((gnus-article-press-button "\r" "Toggle Display")
2402 (gnus-mime-view-part "v" "View Interactively...")
2403 (gnus-mime-save-part "o" "Save...")
2404 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2405 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2406 (gnus-mime-internalize-part "E" "View Internally")
2407 (gnus-mime-externalize-part "e" "View Externally")
2408 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2410 (defun gnus-article-mime-part-status ()
2411 (if gnus-article-mime-handle-alist-1
2412 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2415 (defvar gnus-mime-button-map nil)
2416 (unless gnus-mime-button-map
2417 (setq gnus-mime-button-map (make-sparse-keymap))
2418 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2419 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2420 (define-key gnus-mime-button-map gnus-mouse-3 'gnus-mime-button-menu)
2422 (define-key gnus-mime-button-map (cadr c) (car c)))
2423 gnus-mime-button-commands))
2425 (defun gnus-mime-button-menu (event)
2426 "Construct a context-sensitive menu of MIME commands."
2428 (gnus-article-check-buffer)
2429 (let ((response (x-popup-menu
2431 ("" ,@(mapcar (lambda (c)
2432 (cons (caddr c) (car c)))
2433 gnus-mime-button-commands)))))
2434 (pos (event-start event)))
2436 (set-buffer (window-buffer (posn-window pos)))
2437 (goto-char (posn-point pos))
2438 (funcall response))))
2440 (defun gnus-mime-view-all-parts (&optional handles)
2441 "View all the MIME parts."
2443 (save-current-buffer
2444 (set-buffer gnus-article-buffer)
2445 (let ((handles (or handles gnus-article-mime-handles))
2446 (rfc2047-default-charset gnus-newsgroup-default-charset)
2447 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2448 (if (stringp (car handles))
2449 (gnus-mime-view-all-parts (cdr handles))
2450 (mapcar 'mm-display-part handles)))))
2452 (defun gnus-mime-save-part ()
2453 "Save the MIME part under point."
2455 (gnus-article-check-buffer)
2456 (let ((data (get-text-property (point) 'gnus-data)))
2457 (mm-save-part data)))
2459 (defun gnus-mime-pipe-part ()
2460 "Pipe the MIME part under point to a process."
2462 (gnus-article-check-buffer)
2463 (let ((data (get-text-property (point) 'gnus-data)))
2464 (mm-pipe-part data)))
2466 (defun gnus-mime-view-part ()
2467 "Interactively choose a view method for the MIME part under point."
2469 (gnus-article-check-buffer)
2470 (let ((data (get-text-property (point) 'gnus-data))
2471 (url-standalone-mode (not gnus-plugged)))
2472 (mm-interactively-view-part data)))
2474 (defun gnus-mime-copy-part (&optional handle)
2475 "Put the the MIME part under point into a new buffer."
2477 (gnus-article-check-buffer)
2478 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2479 (contents (mm-get-part handle))|
2480 (base (file-name-nondirectory
2482 (mail-content-type-get (mm-handle-type handle) 'name)
2483 (mail-content-type-get (mm-handle-type handle)
2486 (buffer (generate-new-buffer base)))
2487 (switch-to-buffer buffer)
2489 ;; We do it this way to make `normal-mode' set the appropriate mode.
2492 (setq buffer-file-name (expand-file-name base))
2494 (setq buffer-file-name nil))
2495 (goto-char (point-min))))
2497 (defun gnus-mime-inline-part (&optional charset)
2498 "Insert the MIME part under point into the current buffer."
2499 (interactive "P") ; For compatibility reasons we are not using "z".
2500 (gnus-article-check-buffer)
2501 (let* ((data (get-text-property (point) 'gnus-data))
2503 (url-standalone-mode (not gnus-plugged))
2506 (if (mm-handle-undisplayer data)
2507 (mm-remove-part data)
2508 (setq contents (mm-get-part data))
2511 (unless (symbolp charset)
2512 (setq charset (mm-read-coding-system "Charset: ")))
2513 (setq contents (mm-decode-coding-string contents charset)))
2514 (mm-insert-inline data contents)
2517 (defun gnus-mime-externalize-part (&optional handle)
2518 "View the MIME part under point with an external viewer."
2520 (gnus-article-check-buffer)
2521 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2522 (url-standalone-mode (not gnus-plugged))
2523 (mm-user-display-methods nil)
2524 (mm-all-images-fit t)
2525 (rfc2047-default-charset gnus-newsgroup-default-charset)
2526 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2527 (if (mm-handle-undisplayer handle)
2528 (mm-remove-part handle)
2529 (mm-display-part handle))))
2531 (defun gnus-mime-internalize-part (&optional handle)
2532 "View the MIME part under point with an internal viewer."
2534 (gnus-article-check-buffer)
2535 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2536 (url-standalone-mode (not gnus-plugged))
2537 (mm-user-display-methods '((".*" . inline)))
2538 (mm-all-images-fit t)
2539 (rfc2047-default-charset gnus-newsgroup-default-charset)
2540 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2541 (if (mm-handle-undisplayer handle)
2542 (mm-remove-part handle)
2543 (mm-display-part handle))))
2545 (defun gnus-article-part-wrapper (n function)
2546 (save-current-buffer
2547 (set-buffer gnus-article-buffer)
2548 (when (> n (length gnus-article-mime-handle-alist))
2549 (error "No such part"))
2550 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2551 (funcall function handle))))
2553 (defun gnus-article-pipe-part (n)
2554 "Pipe MIME part N, which is the numerical prefix."
2556 (gnus-article-part-wrapper n 'mm-pipe-part))
2558 (defun gnus-article-save-part (n)
2559 "Save MIME part N, which is the numerical prefix."
2561 (gnus-article-part-wrapper n 'mm-save-part))
2563 (defun gnus-article-interactively-view-part (n)
2564 "Pipe MIME part N, which is the numerical prefix."
2566 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2568 (defun gnus-article-copy-part (n)
2569 "Pipe MIME part N, which is the numerical prefix."
2571 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2573 (defun gnus-article-externalize-part (n)
2574 "Pipe MIME part N, which is the numerical prefix."
2576 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2578 (defun gnus-article-view-part (n)
2579 "View MIME part N, which is the numerical prefix."
2581 (save-current-buffer
2582 (set-buffer gnus-article-buffer)
2583 (when (> n (length gnus-article-mime-handle-alist))
2584 (error "No such part"))
2585 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2586 (when (gnus-article-goto-part n)
2587 (if (equal (car handle) "multipart/alternative")
2588 (gnus-article-press-button)
2589 (when (eq (gnus-mm-display-part handle) 'internal)
2590 (gnus-set-window-start)))))))
2592 (defun gnus-mm-display-part (handle)
2593 "Display HANDLE and fix MIME button."
2594 (let ((id (get-text-property (point) 'gnus-part))
2597 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2598 (gnus-insert-mime-button
2599 handle id (list (not (mm-handle-displayed-p handle))))
2601 (let ((window (selected-window))
2602 (rfc2047-default-charset gnus-newsgroup-default-charset)
2603 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
2606 (let ((win (get-buffer-window (current-buffer) t)))
2608 (select-window win))
2611 (mm-display-part handle))
2612 (select-window window))))
2613 (goto-char point))))
2615 (defun gnus-article-goto-part (n)
2616 "Go to MIME part N."
2617 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2619 (goto-char point))))
2621 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2622 (let ((gnus-tmp-name
2623 (or (mail-content-type-get (mm-handle-type handle)
2625 (mail-content-type-get (mm-handle-disposition handle)
2628 (gnus-tmp-type (car (mm-handle-type handle)))
2629 (gnus-tmp-description (or (mm-handle-description handle)
2632 (if (if displayed (car displayed)
2633 (mm-handle-displayed-p handle))
2635 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2637 gnus-tmp-type-long b e)
2638 (setq gnus-tmp-type-long (concat gnus-tmp-type
2639 (and (not (equal gnus-tmp-name ""))
2640 (concat "; " gnus-tmp-name))))
2641 (or (equal gnus-tmp-description "")
2642 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2647 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2648 `(local-map ,gnus-mime-button-map
2649 keymap ,gnus-mime-button-map
2650 gnus-callback gnus-mm-display-part
2651 gnus-part ,gnus-tmp-id
2652 article-type annotation
2655 (widget-convert-button 'link b e
2657 :action 'gnus-widget-press-button
2658 :button-keymap gnus-mime-button-map
2661 ;; Needed to properly clear the message
2662 ;; due to a bug in wid-edit
2663 (setq help-echo-owns-message t)
2665 "Click to %s the MIME part; %s for more options"
2666 (if (mm-handle-displayed-p
2667 (widget-get widget :mime-handle))
2669 (if gnus-xemacs "button3" "mouse-3"))))))
2671 (defun gnus-widget-press-button (elems el)
2672 (goto-char (widget-get elems :from))
2673 (let ((url-standalone-mode (not gnus-plugged)))
2674 (gnus-article-press-button)))
2676 (defun gnus-display-mime (&optional ihandles)
2677 "Insert MIME buttons in the buffer."
2679 (save-selected-window
2680 (let ((window (get-buffer-window gnus-article-buffer))
2683 (select-window window)
2684 ;; We have to do this since selecting the window
2685 ;; may change the point. So we set the window point.
2686 (set-window-point window point)))
2687 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2688 handle name type b e display)
2690 ;; Top-level call; we clean up.
2691 (mm-destroy-parts gnus-article-mime-handles)
2692 (setq gnus-article-mime-handles handles
2693 gnus-article-mime-handle-alist nil)
2694 ;; We allow users to glean info from the handles.
2695 (when gnus-article-mime-part-function
2696 (gnus-mime-part-function handles)))
2698 (or (not (stringp (car handles)))
2701 ;; Clean up for mime parts.
2703 (delete-region (point) (point-max)))
2704 (gnus-mime-display-part handles))))))
2706 (defun gnus-mime-display-part (handle)
2709 ((not (stringp (car handle)))
2710 (gnus-mime-display-single handle))
2711 ;; multipart/alternative
2712 ((equal (car handle) "multipart/alternative")
2713 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2714 (push (cons id handle) gnus-article-mime-handle-alist)
2715 (gnus-mime-display-alternative (cdr handle) nil nil id)))
2716 ;; multipart/related
2717 ((equal (car handle) "multipart/related")
2718 ;;;!!!We should find the start part, but we just default
2719 ;;;!!!to the first part.
2720 (gnus-mime-display-part (cadr handle)))
2721 ;; Other multiparts are handled like multipart/mixed.
2723 (gnus-mime-display-mixed (cdr handle)))))
2725 (defun gnus-mime-part-function (handles)
2726 (if (stringp (car handles))
2727 (mapcar 'gnus-mime-part-function (cdr handles))
2728 (funcall gnus-article-mime-part-function handles)))
2730 (defun gnus-mime-display-mixed (handles)
2731 (mapcar 'gnus-mime-display-part handles))
2733 (defun gnus-mime-display-single (handle)
2734 (let ((type (car (mm-handle-type handle)))
2735 (ignored gnus-ignored-mime-types)
2742 (when (string-match (pop ignored) type)
2743 (throw 'ignored nil)))
2744 (if (and (setq not-attachment
2745 (or (not (mm-handle-disposition handle))
2746 (equal (car (mm-handle-disposition handle))
2748 (mm-automatic-display-p type)
2749 (or (mm-inlinable-part-p type)
2750 (mm-automatic-external-display-p type)))
2752 (when (equal (car (split-string type "/"))
2755 (let ((id (1+ (length gnus-article-mime-handle-alist))))
2756 (push (cons id handle) gnus-article-mime-handle-alist)
2757 (when (or (not display)
2758 (not (gnus-unbuttonized-mime-type-p type)))
2759 (gnus-article-insert-newline)
2760 (gnus-insert-mime-button
2761 handle id (list (or display
2762 (and not-attachment text))))
2763 (gnus-article-insert-newline)
2764 (gnus-article-insert-newline)
2770 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2771 (mm-charset-iso-8859-1-forced
2772 gnus-newsgroup-iso-8859-1-forced))
2773 (mm-display-part handle t))
2774 (goto-char (point-max)))
2775 ((and text not-attachment)
2778 (gnus-article-insert-newline)
2779 (mm-insert-inline handle (mm-get-part handle))
2780 (goto-char (point-max))))))))
2782 (defun gnus-unbuttonized-mime-type-p (type)
2783 "Say whether TYPE is to be unbuttonized."
2784 (unless gnus-inhibit-mime-unbuttonizing
2786 (let ((types gnus-unbuttonized-mime-types))
2788 (when (string-match (pop types) type)
2789 (throw 'found t)))))))
2791 (defun gnus-article-insert-newline ()
2792 "Insert a newline, but mark it as undeletable."
2793 (gnus-put-text-property
2794 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
2796 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
2797 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
2800 handle buffer-read-only from props begend not-pref)
2801 (save-window-excursion
2804 (narrow-to-region (car ibegend)
2807 (goto-char (car ibegend))
2810 (delete-region (point-min) (point-max))
2811 (mm-remove-parts handles))
2812 (setq begend (list (point-marker)))
2814 (unless (setq not-pref (cadr (member preferred ihandles)))
2815 (setq not-pref (car ihandles)))
2817 (not (gnus-unbuttonized-mime-type-p
2818 "multipart/alternative")))
2819 (gnus-add-text-properties
2822 (insert (format "%d. " id))
2826 (unless ,(not ibegend)
2827 (setq gnus-article-mime-handle-alist
2828 ',gnus-article-mime-handle-alist))
2829 (gnus-mime-display-alternative
2830 ',ihandles ',not-pref ',begend ,id))
2831 local-map ,gnus-mime-button-map
2832 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2833 face ,gnus-article-button-face
2834 keymap ,gnus-mime-button-map
2837 (widget-convert-button 'link from (point)
2838 :action 'gnus-widget-press-button
2839 :button-keymap gnus-widget-button-keymap)
2841 (while (setq handle (pop handles))
2842 (gnus-add-text-properties
2845 (insert (format "(%c) %-18s"
2846 (if (equal handle preferred) ?* ? )
2847 (if (stringp (car handle))
2849 (car (mm-handle-type handle)))))
2853 (unless ,(not ibegend)
2854 (setq gnus-article-mime-handle-alist
2855 ',gnus-article-mime-handle-alist))
2856 (gnus-mime-display-alternative
2857 ',ihandles ',handle ',begend ,id))
2858 local-map ,gnus-mime-button-map
2859 ,gnus-mouse-face-prop ,gnus-article-mouse-face
2860 face ,gnus-article-button-face
2861 keymap ,gnus-mime-button-map
2864 (widget-convert-button 'link from (point)
2865 :action 'gnus-widget-press-button
2866 :button-keymap gnus-widget-button-keymap)
2870 (if (stringp (car preferred))
2871 (gnus-display-mime preferred)
2872 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
2873 (mm-charset-iso-8859-1-forced
2874 gnus-newsgroup-iso-8859-1-forced))
2875 (mm-display-part preferred)))
2876 (goto-char (point-max))
2877 (setcdr begend (point-marker)))))
2879 (goto-char point))))
2881 (defun gnus-article-wash-status ()
2882 "Return a string which display status of article washing."
2884 (set-buffer gnus-article-buffer)
2885 (let ((cite (gnus-article-hidden-text-p 'cite))
2886 (headers (gnus-article-hidden-text-p 'headers))
2887 (boring (gnus-article-hidden-text-p 'boring-headers))
2888 (pgp (gnus-article-hidden-text-p 'pgp))
2889 (pem (gnus-article-hidden-text-p 'pem))
2890 (signature (gnus-article-hidden-text-p 'signature))
2891 (overstrike (gnus-article-hidden-text-p 'overstrike))
2892 (emphasis (gnus-article-hidden-text-p 'emphasis))
2893 (mime gnus-show-mime))
2894 (format "%c%c%c%c%c%c%c"
2896 (if (or headers boring) ?h ? )
2897 (if (or pgp pem) ?p ? )
2898 (if signature ?s ? )
2899 (if overstrike ?o ? )
2901 (if emphasis ?e ? )))))
2903 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
2905 (defun gnus-article-maybe-hide-headers ()
2906 "Hide unwanted headers if `gnus-have-all-headers' is nil.
2907 Provided for backwards compatibility."
2908 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
2910 (gnus-article-hide-headers)))
2914 (defun gnus-output-to-file (file-name)
2915 "Append the current article to a file named FILE-NAME."
2916 (let ((artbuf (current-buffer)))
2918 (insert-buffer-substring artbuf)
2919 ;; Append newline at end of the buffer as separator, and then
2921 (goto-char (point-max))
2923 (append-to-file (point-min) (point-max) file-name)
2926 (defun gnus-narrow-to-page (&optional arg)
2927 "Narrow the article buffer to a page.
2928 If given a numerical ARG, move forward ARG pages."
2930 (setq arg (if arg (prefix-numeric-value arg) 0))
2932 (set-buffer gnus-article-buffer)
2933 (goto-char (point-min))
2935 ;; Remove any old next/prev buttons.
2936 (when (gnus-visual-p 'page-marker)
2937 (let ((buffer-read-only nil))
2938 (gnus-remove-text-with-property 'gnus-prev)
2939 (gnus-remove-text-with-property 'gnus-next)))
2942 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
2944 (re-search-forward page-delimiter nil 'move arg)))
2945 (goto-char (match-end 0)))
2948 (if (re-search-forward page-delimiter nil 'move)
2951 (when (and (gnus-visual-p 'page-marker)
2952 (not (= (point-min) 1)))
2954 (goto-char (point-min))
2955 (gnus-insert-prev-page-button)))
2956 (when (and (gnus-visual-p 'page-marker)
2957 (< (+ (point-max) 2) (buffer-size)))
2959 (goto-char (point-max))
2960 (gnus-insert-next-page-button)))))
2962 ;; Article mode commands
2964 (defun gnus-article-goto-next-page ()
2965 "Show the next page of the article."
2967 (when (gnus-article-next-page)
2968 (goto-char (point-min))
2969 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
2971 (defun gnus-article-goto-prev-page ()
2972 "Show the next page of the article."
2974 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
2975 (gnus-article-prev-page nil)))
2977 (defun gnus-article-next-page (&optional lines)
2978 "Show the next page of the current article.
2979 If end of article, return non-nil. Otherwise return nil.
2980 Argument LINES specifies lines to be scrolled up."
2982 (move-to-window-line -1)
2985 (and (pos-visible-in-window-p) ;Not continuation line.
2987 ;; Nothing in this page.
2988 (if (or (not gnus-page-broken)
2991 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
2993 (gnus-narrow-to-page 1) ;Go to next page.
2995 ;; More in this page.
2996 (let ((scroll-in-place nil))
3000 ;; Long lines may cause an end-of-buffer error.
3001 (goto-char (point-max)))))
3002 (move-to-window-line 0)
3005 (defun gnus-article-prev-page (&optional lines)
3006 "Show previous page of current article.
3007 Argument LINES specifies lines to be scrolled down."
3009 (move-to-window-line 0)
3010 (if (and gnus-page-broken
3012 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3014 (gnus-narrow-to-page -1) ;Go to previous page.
3015 (goto-char (point-max))
3017 (let ((scroll-in-place nil))
3021 (beginning-of-buffer
3022 (goto-char (point-min))))
3023 (move-to-window-line 0)))))
3025 (defun gnus-article-refer-article ()
3026 "Read article specified by message-id around point."
3028 (let ((point (point)))
3029 (search-forward ">" nil t) ;Move point to end of "<....>".
3030 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3031 (let ((message-id (match-string 1)))
3033 (set-buffer gnus-summary-buffer)
3034 (gnus-summary-refer-article message-id))
3036 (error "No references around point"))))
3038 (defun gnus-article-show-summary ()
3039 "Reconfigure windows to show summary buffer."
3041 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3042 (error "There is no summary buffer for this article buffer")
3043 (gnus-article-set-globals)
3044 (gnus-configure-windows 'article)
3045 (gnus-summary-goto-subject gnus-current-article)
3046 (gnus-summary-position-point)))
3048 (defun gnus-article-describe-briefly ()
3049 "Describe article mode commands briefly."
3052 (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")))
3054 (defun gnus-article-summary-command ()
3055 "Execute the last keystroke in the summary buffer."
3057 (let ((obuf (current-buffer))
3058 (owin (current-window-configuration))
3060 (switch-to-buffer gnus-article-current-summary 'norecord)
3061 (setq func (lookup-key (current-local-map) (this-command-keys)))
3062 (call-interactively func)
3064 (set-window-configuration owin)
3065 (set-window-point (get-buffer-window (current-buffer)) (point))))
3067 (defun gnus-article-summary-command-nosave ()
3068 "Execute the last keystroke in the summary buffer."
3071 (pop-to-buffer gnus-article-current-summary 'norecord)
3072 (setq func (lookup-key (current-local-map) (this-command-keys)))
3073 (call-interactively func)))
3075 (defun gnus-article-check-buffer ()
3076 "Beep if not in an article buffer."
3077 (unless (equal major-mode 'gnus-article-mode)
3078 (error "Command invoked outside of a Gnus article buffer")))
3080 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3081 "Read a summary buffer key sequence and execute it from the article buffer."
3083 (gnus-article-check-buffer)
3085 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3086 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3087 "=" "^" "\M-^" "|"))
3093 '("n" "Gn" "p" "Gp"))
3096 (set-buffer gnus-article-current-summary)
3097 (let (gnus-pick-mode)
3098 (push (or key last-command-event) unread-command-events)
3099 (setq keys (read-key-sequence nil))))
3102 (if (or (member keys nosaves)
3103 (member keys nosave-but-article)
3104 (member keys nosave-in-article))
3106 (save-window-excursion
3107 (pop-to-buffer gnus-article-current-summary 'norecord)
3108 ;; We disable the pick minor mode commands.
3109 (let (gnus-pick-mode)
3110 (setq func (lookup-key (current-local-map) keys))))
3113 (unless (member keys nosave-in-article)
3114 (set-buffer gnus-article-current-summary))
3115 (call-interactively func)
3116 (setq new-sum-point (point)))
3117 (when (member keys nosave-but-article)
3118 (pop-to-buffer gnus-article-buffer 'norecord)))
3119 ;; These commands should restore window configuration.
3120 (let ((obuf (current-buffer))
3121 (owin (current-window-configuration))
3123 (summary gnus-article-current-summary)
3124 func in-buffer selected)
3125 (if not-restore-window
3126 (pop-to-buffer summary 'norecord)
3127 (switch-to-buffer summary 'norecord))
3128 (setq in-buffer (current-buffer))
3129 ;; We disable the pick minor mode commands.
3130 (if (setq func (let (gnus-pick-mode)
3131 (lookup-key (current-local-map) keys)))
3133 (call-interactively func)
3134 (setq new-sum-point (point)))
3136 (when (eq in-buffer (current-buffer))
3137 (setq selected (gnus-summary-select-article))
3139 (unless not-restore-window
3140 (set-window-configuration owin))
3141 (unless (or (not (eq selected 'old)) (member keys up-to-top))
3142 (set-window-point (get-buffer-window (current-buffer))
3144 (let ((win (get-buffer-window gnus-article-current-summary)))
3146 (set-window-point win new-sum-point))))))))
3148 (defun gnus-article-hide (&optional arg force)
3149 "Hide all the gruft in the current article.
3150 This means that PGP stuff, signatures, cited text and (some)
3151 headers will be hidden.
3152 If given a prefix, show the hidden text instead."
3153 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3154 (gnus-article-hide-headers arg)
3155 (gnus-article-hide-pgp arg)
3156 (gnus-article-hide-citation-maybe arg force)
3157 (gnus-article-hide-signature arg))
3159 (defun gnus-article-maybe-highlight ()
3160 "Do some article highlighting if article highlighting is requested."
3161 (when (gnus-visual-p 'article-highlight 'highlight)
3162 (gnus-article-highlight-some)))
3164 (defun gnus-check-group-server ()
3165 ;; Make sure the connection to the server is alive.
3166 (unless (gnus-server-opened
3167 (gnus-find-method-for-group gnus-newsgroup-name))
3168 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3169 (gnus-request-group gnus-newsgroup-name t)))
3171 (defun gnus-request-article-this-buffer (article group)
3172 "Get an article and insert it into this buffer."
3173 (let (do-update-line sparse-header)
3177 (gnus-kill-all-overlays)
3178 (setq group (or group gnus-newsgroup-name))
3180 ;; Using `gnus-request-article' directly will insert the article into
3181 ;; `nntp-server-buffer' - so we'll save some time by not having to
3182 ;; copy it from the server buffer into the article buffer.
3184 ;; We only request an article by message-id when we do not have the
3185 ;; headers for it, so we'll have to get those.
3186 (when (stringp article)
3187 (let ((gnus-override-method gnus-refer-article-method))
3188 (gnus-read-header article)))
3190 ;; If the article number is negative, that means that this article
3191 ;; doesn't belong in this newsgroup (possibly), so we find its
3192 ;; message-id and request it by id instead of number.
3193 (when (and (numberp article)
3195 (get-buffer gnus-summary-buffer)
3196 (gnus-buffer-exists-p gnus-summary-buffer))
3198 (set-buffer gnus-summary-buffer)
3199 (let ((header (gnus-summary-article-header article)))
3202 ((memq article gnus-newsgroup-sparse)
3203 ;; This is a sparse gap article.
3204 (setq do-update-line article)
3205 (setq article (mail-header-id header))
3206 (let ((gnus-override-method gnus-refer-article-method))
3207 (setq sparse-header (gnus-read-header article)))
3208 (setq gnus-newsgroup-sparse
3209 (delq article gnus-newsgroup-sparse)))
3211 ;; It's a real article.
3212 (setq article (mail-header-id header)))
3214 ;; It is an extracted pseudo-article.
3215 (setq article 'pseudo)
3216 (gnus-request-pseudo-article header))))
3218 (let ((method (gnus-find-method-for-group
3219 gnus-newsgroup-name)))
3220 (when (and (eq (car method) 'nneething)
3223 (file-name-as-directory
3224 (or (cadr (assq 'nneething-address method))
3226 (mail-header-subject header))))
3227 (when (file-directory-p dir)
3228 (setq article 'nneething)
3229 (gnus-group-enter-directory dir))))))))
3232 ;; Refuse to select canceled articles.
3233 ((and (numberp article)
3235 (get-buffer gnus-summary-buffer)
3236 (gnus-buffer-exists-p gnus-summary-buffer)
3237 (eq (cdr (save-excursion
3238 (set-buffer gnus-summary-buffer)
3239 (assq article gnus-newsgroup-reads)))
3240 gnus-canceled-mark))
3242 ;; Check the backlog.
3243 ((and gnus-keep-backlog
3244 (gnus-backlog-request-article group article (current-buffer)))
3246 ;; Check asynchronous pre-fetch.
3247 ((gnus-async-request-fetched-article group article (current-buffer))
3248 (gnus-async-prefetch-next group article gnus-summary-buffer)
3249 (when (and (numberp article) gnus-keep-backlog)
3250 (gnus-backlog-enter-article group article (current-buffer)))
3253 ((and gnus-use-cache
3255 (gnus-cache-request-article article group))
3257 ;; Get the article and put into the article buffer.
3258 ((or (stringp article) (numberp article))
3259 (let ((gnus-override-method
3260 (and (stringp article) gnus-refer-article-method))
3261 (buffer-read-only nil))
3263 (gnus-kill-all-overlays)
3264 (gnus-check-group-server)
3265 (when (gnus-request-article article group (current-buffer))
3266 (when (numberp article)
3267 (gnus-async-prefetch-next group article gnus-summary-buffer)
3268 (when gnus-keep-backlog
3269 (gnus-backlog-enter-article
3270 group article (current-buffer))))
3275 ;; Associate this article with the current summary buffer.
3276 (setq gnus-article-current-summary gnus-summary-buffer)
3278 ;; Take the article from the original article buffer
3279 ;; and place it in the buffer it's supposed to be in.
3280 (when (and (get-buffer gnus-article-buffer)
3281 (equal (buffer-name (current-buffer))
3282 (buffer-name (get-buffer gnus-article-buffer))))
3284 (if (get-buffer gnus-original-article-buffer)
3285 (set-buffer gnus-original-article-buffer)
3286 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3287 (buffer-disable-undo)
3288 (setq major-mode 'gnus-original-article-mode)
3289 (setq buffer-read-only t))
3290 (let (buffer-read-only)
3292 (insert-buffer-substring gnus-article-buffer))
3293 (setq gnus-original-article (cons group article)))
3296 (run-hooks 'gnus-article-decode-hook)
3297 ;; Mark article as decoded or not.
3298 (setq gnus-article-decoded-p gnus-article-decode-hook))
3300 ;; Update sparse articles.
3301 (when (and do-update-line
3302 (or (numberp article)
3304 (let ((buf (current-buffer)))
3305 (set-buffer gnus-summary-buffer)
3306 (gnus-summary-update-article do-update-line sparse-header)
3307 (gnus-summary-goto-subject do-update-line nil t)
3308 (set-window-point (get-buffer-window (current-buffer) t)
3310 (set-buffer buf))))))
3316 (defcustom gnus-article-edit-mode-hook nil
3317 "Hook run in article edit mode buffers."
3318 :group 'gnus-article-various
3321 (defcustom gnus-article-edit-article-setup-function
3322 'gnus-article-mime-edit-article-setup
3323 "Function called to setup an editing article buffer."
3324 :group 'gnus-article-various
3327 (defvar gnus-article-edit-done-function nil)
3329 (defvar gnus-article-edit-mode-map nil)
3331 ;; Should we be using derived.el for this?
3332 (unless gnus-article-edit-mode-map
3333 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3334 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3336 (gnus-define-keys gnus-article-edit-mode-map
3337 "\C-c\C-c" gnus-article-edit-done
3338 "\C-c\C-k" gnus-article-edit-exit)
3340 (gnus-define-keys (gnus-article-edit-wash-map
3341 "\C-c\C-w" gnus-article-edit-mode-map)
3342 "f" gnus-article-edit-full-stops))
3344 (defun gnus-article-edit-mode ()
3345 "Major mode for editing articles.
3346 This is an extended text-mode.
3348 \\{gnus-article-edit-mode-map}"
3350 (setq major-mode 'gnus-article-edit-mode)
3351 (setq mode-name "Article Edit")
3352 (use-local-map gnus-article-edit-mode-map)
3353 (make-local-variable 'gnus-article-edit-done-function)
3354 (make-local-variable 'gnus-prev-winconf)
3355 (setq buffer-read-only nil)
3356 (buffer-enable-undo)
3358 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3360 (defun gnus-article-edit (&optional force)
3361 "Edit the current article.
3362 This will have permanent effect only in mail groups.
3363 If FORCE is non-nil, allow editing of articles even in read-only
3366 (when (and (not force)
3367 (gnus-group-read-only-p))
3368 (error "The current newsgroup does not support article editing"))
3369 (gnus-article-date-original)
3370 (gnus-article-edit-article
3371 `(lambda (no-highlight)
3372 (gnus-summary-edit-article-done
3373 ,(or (mail-header-references gnus-current-headers) "")
3374 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3376 (defun gnus-article-edit-article (exit-func)
3377 "Start editing the contents of the current article buffer."
3378 (let ((winconf (current-window-configuration)))
3379 (set-buffer gnus-article-buffer)
3380 (gnus-article-edit-mode)
3381 (gnus-article-delete-text-of-type 'annotation)
3382 (gnus-set-text-properties (point-min) (point-max) nil)
3383 (gnus-configure-windows 'edit-article)
3384 (setq gnus-article-edit-done-function exit-func)
3385 (setq gnus-prev-winconf winconf)
3386 (when gnus-article-edit-article-setup-function
3387 (funcall gnus-article-edit-article-setup-function))
3388 (gnus-message 6 "C-c C-c to end edits")))
3390 (defun gnus-article-edit-done (&optional arg)
3391 "Update the article edits and exit."
3396 (when (article-goto-body)
3397 (let ((lines (count-lines (point) (point-max)))
3398 (length (- (point-max) (point)))
3399 (case-fold-search t)
3400 (body (copy-marker (point))))
3401 (goto-char (point-min))
3402 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3403 (delete-region (match-beginning 1) (match-end 1))
3404 (insert (number-to-string length)))
3405 (goto-char (point-min))
3406 (when (re-search-forward
3407 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3408 (delete-region (match-beginning 1) (match-end 1))
3409 (insert (number-to-string length)))
3410 (goto-char (point-min))
3411 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3412 (delete-region (match-beginning 1) (match-end 1))
3413 (insert (number-to-string lines)))))))
3414 (let ((func gnus-article-edit-done-function)
3415 (buf (current-buffer))
3416 (start (window-start)))
3417 (remove-hook 'gnus-article-mode-hook
3418 'gnus-article-mime-edit-article-unwind)
3419 (gnus-article-edit-exit)
3422 (let ((buffer-read-only nil))
3424 ;; The cache and backlog have to be flushed somewhat.
3425 (when gnus-keep-backlog
3426 (gnus-backlog-remove-article
3427 (car gnus-article-current) (cdr gnus-article-current)))
3428 ;; Flush original article as well.
3430 (when (get-buffer gnus-original-article-buffer)
3431 (set-buffer gnus-original-article-buffer)
3432 (setq gnus-original-article nil)))
3433 (when gnus-use-cache
3434 (gnus-cache-update-article
3435 (car gnus-article-current) (cdr gnus-article-current))))
3437 (set-window-start (get-buffer-window buf) start)
3438 (set-window-point (get-buffer-window buf) (point))))
3440 (defun gnus-article-edit-exit ()
3441 "Exit the article editing without updating."
3443 ;; We remove all text props from the article buffer.
3444 (let ((buf (format "%s" (buffer-string)))
3445 (curbuf (current-buffer))
3447 (window-start (window-start)))
3450 (let ((winconf gnus-prev-winconf))
3452 (set-window-configuration winconf)
3453 ;; Tippy-toe some to make sure that point remains where it was.
3454 (save-current-buffer
3456 (set-window-start (get-buffer-window (current-buffer)) window-start)
3459 (defun gnus-article-edit-full-stops ()
3460 "Interactively repair spacing at end of sentences."
3463 (goto-char (point-min))
3464 (search-forward-regexp "^$" nil t)
3465 (let ((case-fold-search nil))
3466 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3469 ;;; Article editing with MIME-Edit
3472 (defcustom gnus-article-mime-edit-article-setup-hook nil
3473 "Hook run after setting up a MIME editing article buffer."
3474 :group 'gnus-article-various
3477 (defun gnus-article-mime-edit-article-unwind ()
3478 "Unwind `gnus-article-buffer' if article editing was given up."
3479 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3480 (when mime-edit-mode-flag
3481 (mime-edit-exit 'nomime 'no-error)
3483 (when (featurep 'font-lock)
3484 (setq font-lock-defaults nil)
3485 (font-lock-mode 0)))
3487 (defun gnus-article-mime-edit-article-setup ()
3488 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3489 after replacing with the original article."
3490 (setq gnus-show-mime t)
3491 (setq gnus-article-edit-done-function
3492 `(lambda (&rest args)
3493 (when mime-edit-mode-flag
3496 (goto-char (point-min))
3497 (let (case-fold-search)
3498 (when (re-search-forward
3499 (format "^%s$" (regexp-quote mail-header-separator))
3501 (replace-match "")))
3502 (when (featurep 'font-lock)
3503 (setq font-lock-defaults nil)
3505 (apply ,gnus-article-edit-done-function args)
3506 (set-buffer gnus-original-article-buffer)
3508 (insert-buffer gnus-article-buffer)
3509 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3510 (gnus-article-prepare-display)))
3511 (substitute-key-definition
3512 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3513 gnus-article-edit-mode-map)
3515 (insert-buffer gnus-original-article-buffer)
3517 (when (featurep 'font-lock)
3518 (set (make-local-variable 'font-lock-defaults)
3519 '(message-font-lock-keywords t))
3520 (font-lock-set-defaults)
3521 (turn-on-font-lock))
3522 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3523 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3525 (defun gnus-article-mime-edit-exit ()
3526 "Exit the article MIME editing without updating."
3528 (let ((winconf gnus-prev-winconf)
3530 (when mime-edit-mode-flag
3533 (goto-char (point-min))
3534 (let (case-fold-search)
3535 (when (re-search-forward
3536 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3537 (replace-match "")))
3538 (when (featurep 'font-lock)
3539 (setq font-lock-defaults nil)
3541 ;; We remove all text props from the article buffer.
3542 (setq buf (format "%s" (buffer-string)))
3543 (set-buffer (get-buffer-create gnus-original-article-buffer))
3546 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3547 (gnus-article-prepare-display)
3548 (set-window-configuration winconf)))
3551 ;;; Article highlights
3554 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3556 ;;; Internal Variables:
3558 (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\\)"
3559 "Regular expression that matches URLs."
3560 :group 'gnus-article-buttons
3563 (defcustom gnus-button-alist
3564 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3565 0 t gnus-button-message-id 2)
3566 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3567 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3569 gnus-button-fetch-group 4)
3570 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3571 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3572 t gnus-button-message-id 3)
3573 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3574 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3575 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3576 ;; This is how URLs _should_ be embedded in text...
3577 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3579 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3580 "*Alist of regexps matching buttons in article bodies.
3582 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3583 REGEXP: is the string matching text around the button,
3584 BUTTON: is the number of the regexp grouping actually matching the button,
3585 FORM: is a lisp expression which must eval to true for the button to
3587 CALLBACK: is the function to call when the user push this button, and each
3588 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3590 CALLBACK can also be a variable, in that case the value of that
3591 variable it the real callback function."
3592 :group 'gnus-article-buttons
3593 :type '(repeat (list regexp
3594 (integer :tag "Button")
3596 (function :tag "Callback")
3599 (integer :tag "Regexp group")))))
3601 (defcustom gnus-header-button-alist
3602 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3603 0 t gnus-button-message-id 0)
3604 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3605 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3606 0 t gnus-button-mailto 0)
3607 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3608 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3609 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3610 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3611 gnus-button-message-id 3))
3612 "*Alist of headers and regexps to match buttons in article heads.
3614 This alist is very similar to `gnus-button-alist', except that each
3615 alist has an additional HEADER element first in each entry:
3617 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3619 HEADER is a regexp to match a header. For a fuller explanation, see
3620 `gnus-button-alist'."
3621 :group 'gnus-article-buttons
3622 :group 'gnus-article-headers
3623 :type '(repeat (list (regexp :tag "Header")
3625 (integer :tag "Button")
3627 (function :tag "Callback")
3630 (integer :tag "Regexp group")))))
3632 (defvar gnus-button-regexp nil)
3633 (defvar gnus-button-marker-list nil)
3634 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3636 (defvar gnus-button-last nil)
3637 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3641 (defun gnus-article-push-button (event)
3642 "Check text under the mouse pointer for a callback function.
3643 If the text under the mouse pointer has a `gnus-callback' property,
3644 call it with the value of the `gnus-data' text property."
3646 (set-buffer (window-buffer (posn-window (event-start event))))
3647 (let* ((pos (posn-point (event-start event)))
3648 (data (get-text-property pos 'gnus-data))
3649 (fun (get-text-property pos 'gnus-callback)))
3652 (funcall fun data))))
3654 (defun gnus-article-press-button ()
3655 "Check text at point for a callback function.
3656 If the text at point has a `gnus-callback' property,
3657 call it with the value of the `gnus-data' text property."
3659 (let* ((data (get-text-property (point) 'gnus-data))
3660 (fun (get-text-property (point) 'gnus-callback)))
3662 (funcall fun data))))
3664 (defun gnus-article-prev-button (n)
3665 "Move point to N buttons backward.
3666 If N is negative, move forward instead."
3668 (gnus-article-next-button (- n)))
3670 (defun gnus-article-next-button (n)
3671 "Move point to N buttons forward.
3672 If N is negative, move backward instead."
3674 (let ((function (if (< n 0) 'previous-single-property-change
3675 'next-single-property-change))
3676 (inhibit-point-motion-hooks t)
3678 (limit (if (< n 0) (point-min) (point-max))))
3680 (while (and (not (= limit (point)))
3682 ;; Skip past the current button.
3683 (when (get-text-property (point) 'gnus-callback)
3684 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3685 ;; Go to the next (or previous) button.
3686 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
3687 ;; Put point at the start of the button.
3688 (when (and backward (not (get-text-property (point) 'gnus-callback)))
3689 (goto-char (funcall function (point) 'gnus-callback nil limit)))
3690 ;; Skip past intangible buttons.
3691 (when (get-text-property (point) 'intangible)
3695 (gnus-message 5 "No more buttons"))
3698 (defun gnus-article-highlight (&optional force)
3699 "Highlight current article.
3700 This function calls `gnus-article-highlight-headers',
3701 `gnus-article-highlight-citation',
3702 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3703 do the highlighting. See the documentation for those functions."
3704 (interactive (list 'force))
3705 (gnus-article-highlight-headers)
3706 (gnus-article-highlight-citation force)
3707 (gnus-article-highlight-signature)
3708 (gnus-article-add-buttons force)
3709 (gnus-article-add-buttons-to-head))
3711 (defun gnus-article-highlight-some (&optional force)
3712 "Highlight current article.
3713 This function calls `gnus-article-highlight-headers',
3714 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3715 do the highlighting. See the documentation for those functions."
3716 (interactive (list 'force))
3717 (gnus-article-highlight-headers)
3718 (gnus-article-highlight-signature)
3719 (gnus-article-add-buttons))
3721 (defun gnus-article-highlight-headers ()
3722 "Highlight article headers as specified by `gnus-header-face-alist'."
3725 (set-buffer gnus-article-buffer)
3727 (let ((alist gnus-header-face-alist)
3728 (buffer-read-only nil)
3729 (case-fold-search t)
3730 (inhibit-point-motion-hooks t)
3731 entry regexp header-face field-face from hpoints fpoints)
3732 (message-narrow-to-head)
3733 (while (setq entry (pop alist))
3734 (goto-char (point-min))
3735 (setq regexp (concat "^\\("
3736 (if (string-equal "" (nth 0 entry))
3740 header-face (nth 1 entry)
3741 field-face (nth 2 entry))
3742 (while (and (re-search-forward regexp nil t)
3746 (unless (search-forward ":" nil t)
3748 (when (and header-face
3749 (not (memq (point) hpoints)))
3750 (push (point) hpoints)
3751 (gnus-put-text-property from (point) 'face header-face))
3752 (when (and field-face
3753 (not (memq (setq from (point)) fpoints)))
3755 (if (re-search-forward "^[^ \t]" nil t)
3757 (goto-char (point-max)))
3758 (gnus-put-text-property from (point) 'face field-face))))))))
3760 (defun gnus-article-highlight-signature ()
3761 "Highlight the signature in an article.
3762 It does this by highlighting everything after
3763 `gnus-signature-separator' using `gnus-signature-face'."
3766 (set-buffer gnus-article-buffer)
3767 (let ((buffer-read-only nil)
3768 (inhibit-point-motion-hooks t))
3770 (when (and gnus-signature-face
3771 (gnus-article-narrow-to-signature))
3772 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
3773 'face gnus-signature-face)
3775 (gnus-article-search-signature)
3776 (let ((start (match-beginning 0))
3777 (end (set-marker (make-marker) (1+ (match-end 0)))))
3778 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
3781 (defun gnus-button-in-region-p (b e prop)
3782 "Say whether PROP exists in the region."
3783 (text-property-not-all b e prop nil))
3785 (defun gnus-article-add-buttons (&optional force)
3786 "Find external references in the article and make buttons of them.
3787 \"External references\" are things like Message-IDs and URLs, as
3788 specified by `gnus-button-alist'."
3789 (interactive (list 'force))
3791 (set-buffer gnus-article-buffer)
3792 (let ((buffer-read-only nil)
3793 (inhibit-point-motion-hooks t)
3794 (case-fold-search t)
3795 (alist gnus-button-alist)
3797 ;; Remove all old markers.
3799 (while (setq marker (pop gnus-button-marker-list))
3801 (when (setq entry (gnus-button-entry))
3802 (put-text-property (match-beginning (nth 1 entry))
3803 (match-end (nth 1 entry))
3804 'gnus-callback nil))
3805 (set-marker marker nil)))
3806 ;; We skip the headers.
3809 (while (setq entry (pop alist))
3810 (setq regexp (car entry))
3812 (while (re-search-forward regexp nil t)
3813 (let* ((start (and entry (match-beginning (nth 1 entry))))
3814 (end (and entry (match-end (nth 1 entry))))
3815 (from (match-beginning 0)))
3816 (when (and (or (eq t (nth 2 entry))
3817 (eval (nth 2 entry)))
3818 (not (gnus-button-in-region-p
3819 start end 'gnus-callback)))
3820 ;; That optional form returned non-nil, so we add the
3822 (gnus-article-add-button
3823 start end 'gnus-button-push
3824 (car (push (set-marker (make-marker) from)
3825 gnus-button-marker-list))))))))))
3827 ;; Add buttons to the head of an article.
3828 (defun gnus-article-add-buttons-to-head ()
3829 "Add buttons to the head of the article."
3832 (set-buffer gnus-article-buffer)
3833 (let ((buffer-read-only nil)
3834 (inhibit-point-motion-hooks t)
3835 (case-fold-search t)
3836 (alist gnus-header-button-alist)
3838 (nnheader-narrow-to-headers)
3840 ;; Each alist entry.
3841 (setq entry (car alist)
3843 (goto-char (point-min))
3844 (while (re-search-forward (car entry) nil t)
3845 ;; Each header matching the entry.
3846 (setq beg (match-beginning 0))
3847 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
3848 (match-beginning 0))
3851 (while (re-search-forward (nth 1 entry) end t)
3852 ;; Each match within a header.
3853 (let* ((entry (cdr entry))
3854 (start (match-beginning (nth 1 entry)))
3855 (end (match-end (nth 1 entry)))
3856 (form (nth 2 entry)))
3857 (goto-char (match-end 0))
3859 (gnus-article-add-button
3860 start end (nth 3 entry)
3861 (buffer-substring (match-beginning (nth 4 entry))
3862 (match-end (nth 4 entry)))))))
3866 ;;; External functions:
3868 (defun gnus-article-add-button (from to fun &optional data)
3869 "Create a button between FROM and TO with callback FUN and data DATA."
3870 (when gnus-article-button-face
3871 (gnus-overlay-put (gnus-make-overlay from to)
3872 'face gnus-article-button-face))
3873 (gnus-add-text-properties
3875 (nconc (and gnus-article-mouse-face
3876 (list gnus-mouse-face-prop gnus-article-mouse-face))
3877 (list 'gnus-callback fun)
3878 (and data (list 'gnus-data data)))))
3880 ;;; Internal functions:
3882 (defun gnus-article-set-globals ()
3884 (set-buffer gnus-summary-buffer)
3885 (gnus-set-global-variables)))
3887 (defun gnus-signature-toggle (end)
3889 (set-buffer gnus-article-buffer)
3890 (let ((buffer-read-only nil)
3891 (inhibit-point-motion-hooks t))
3892 (if (get-text-property end 'invisible)
3893 (gnus-article-unhide-text end (point-max))
3894 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
3896 (defun gnus-button-entry ()
3897 ;; Return the first entry in `gnus-button-alist' matching this place.
3898 (let ((alist gnus-button-alist)
3901 (setq entry (pop alist))
3902 (if (looking-at (car entry))
3907 (defun gnus-button-push (marker)
3908 ;; Push button starting at MARKER.
3911 (let* ((entry (gnus-button-entry))
3912 (inhibit-point-motion-hooks t)
3914 (args (mapcar (lambda (group)
3915 (let ((string (match-string group)))
3916 (gnus-set-text-properties
3917 0 (length string) nil string)
3924 (fboundp (symbol-value fun)))
3925 (apply (symbol-value fun) args))
3927 (gnus-message 1 "You must define `%S' to use this button"
3928 (cons fun args)))))))
3930 (defun gnus-button-message-id (message-id)
3933 (set-buffer gnus-summary-buffer)
3934 (gnus-summary-refer-article message-id)))
3936 (defun gnus-button-fetch-group (address)
3937 "Fetch GROUP specified by ADDRESS."
3938 (if (not (string-match "[:/]" address))
3939 ;; This is just a simple group url.
3940 (gnus-group-read-ephemeral-group address gnus-select-method)
3941 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
3943 (error "Can't parse %s" address)
3944 (gnus-group-read-ephemeral-group
3945 (match-string 4 address)
3946 `(nntp ,(match-string 1 address)
3947 (nntp-address ,(match-string 1 address))
3948 (nntp-port-number ,(if (match-end 3)
3949 (match-string 3 address)
3952 (defun gnus-url-parse-query-string (query &optional downcase)
3953 (let (retval pairs cur key val)
3954 (setq pairs (split-string query "&"))
3956 (setq cur (car pairs)
3958 (if (not (string-match "=" cur))
3960 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
3961 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
3963 (setq key (downcase key)))
3964 (setq cur (assoc key retval))
3966 (setcdr cur (cons val (cdr cur)))
3967 (setq retval (cons (list key val) retval)))))
3970 (defun gnus-url-unhex (x)
3977 (defun gnus-url-unhex-string (str &optional allow-newlines)
3978 "Remove %XXX embedded spaces, etc in a url.
3979 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
3980 decoding of carriage returns and line feeds in the string, which is normally
3981 forbidden in URL encoding."
3982 (setq str (or str ""))
3984 (case-fold-search t))
3985 (while (string-match "%[0-9a-f][0-9a-f]" str)
3986 (let* ((start (match-beginning 0))
3987 (ch1 (gnus-url-unhex (elt str (+ start 1))))
3989 (gnus-url-unhex (elt str (+ start 2))))))
3991 tmp (substring str 0 start)
3994 (char-to-string code))
3995 ((or (= code ?\n) (= code ?\r))
3997 (t (char-to-string code))))
3998 str (substring str (match-end 0)))))
3999 (setq tmp (concat tmp str))
4002 (defun gnus-url-mailto (url)
4003 ;; Send mail to someone
4004 (when (string-match "mailto:/*\\(.*\\)" url)
4005 (setq url (substring url (match-beginning 1) nil)))
4006 (let (to args subject func)
4007 (if (string-match (regexp-quote "?") url)
4008 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4009 args (gnus-url-parse-query-string
4010 (substring url (match-end 0) nil) t))
4011 (setq to (gnus-url-unhex-string url)))
4012 (setq args (cons (list "to" to) args)
4013 subject (cdr-safe (assoc "subject" args)))
4014 (gnus-setup-message 'reply
4017 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4020 (message-position-on-field (caar args)))
4021 (insert (mapconcat 'identity (cdar args) ", "))
4022 (setq args (cdr args)))
4025 (message-goto-subject)))))
4027 (defun gnus-button-mailto (address)
4029 (set-buffer (gnus-copy-article-buffer))
4030 (gnus-setup-message 'reply
4031 (message-reply address)))
4033 (defun gnus-button-reply (address)
4034 ;; Reply to ADDRESS.
4035 (gnus-setup-message 'reply
4036 (message-reply address)))
4038 (defun gnus-button-url (address)
4040 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4041 (if (listp browse-url-browser-function)
4042 (browse-url address)
4043 (funcall browse-url-browser-function address)))
4045 (defun gnus-button-embedded-url (address)
4047 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4048 (if (listp browse-url-browser-function)
4049 (browse-url (gnus-strip-whitespace address))
4050 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4052 ;;; Next/prev buttons in the article buffer.
4054 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4055 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4057 (defvar gnus-prev-page-map nil)
4058 (unless gnus-prev-page-map
4059 (setq gnus-prev-page-map (make-sparse-keymap))
4060 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4061 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4063 (defun gnus-insert-prev-page-button ()
4064 (let ((buffer-read-only nil))
4066 gnus-prev-page-line-format nil
4067 `(gnus-prev t local-map ,gnus-prev-page-map
4068 gnus-callback gnus-article-button-prev-page
4069 article-type annotation))))
4071 (defvar gnus-next-page-map nil)
4072 (unless gnus-next-page-map
4073 (setq gnus-next-page-map (make-keymap))
4074 (suppress-keymap gnus-prev-page-map)
4075 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4076 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4078 (defun gnus-button-next-page ()
4079 "Go to the next page."
4081 (let ((win (selected-window)))
4082 (select-window (get-buffer-window gnus-article-buffer t))
4083 (gnus-article-next-page)
4084 (select-window win)))
4086 (defun gnus-button-prev-page ()
4087 "Go to the prev page."
4089 (let ((win (selected-window)))
4090 (select-window (get-buffer-window gnus-article-buffer t))
4091 (gnus-article-prev-page)
4092 (select-window win)))
4094 (defun gnus-insert-next-page-button ()
4095 (let ((buffer-read-only nil))
4096 (gnus-eval-format gnus-next-page-line-format nil
4098 t local-map ,gnus-next-page-map
4099 gnus-callback gnus-article-button-next-page
4100 article-type annotation))))
4102 (defun gnus-article-button-next-page (arg)
4103 "Go to the next page."
4105 (let ((win (selected-window)))
4106 (select-window (get-buffer-window gnus-article-buffer t))
4107 (gnus-article-next-page)
4108 (select-window win)))
4110 (defun gnus-article-button-prev-page (arg)
4111 "Go to the prev page."
4113 (let ((win (selected-window)))
4114 (select-window (get-buffer-window gnus-article-buffer t))
4115 (gnus-article-prev-page)
4116 (select-window win)))
4118 (defvar gnus-decode-header-methods
4119 '(gnus-decode-with-mail-decode-encoded-word-region)
4120 "List of methods used to decode headers.
4122 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4123 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4124 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4125 whose names match REGEXP.
4128 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4129 mail-decode-encoded-word-region
4130 (\"chinese\" . rfc1843-decode-region))
4133 (defvar gnus-decode-header-methods-cache nil)
4135 (defun gnus-decode-with-mail-decode-encoded-word-region (start end)
4136 (let ((rfc2047-default-charset gnus-newsgroup-default-charset)
4137 (mm-charset-iso-8859-1-forced gnus-newsgroup-iso-8859-1-forced))
4138 (mail-decode-encoded-word-region start end)))
4140 (defun gnus-multi-decode-header (start end)
4141 "Apply the functions from `gnus-encoded-word-methods' that match."
4142 (unless (and gnus-decode-header-methods-cache
4143 (eq gnus-newsgroup-name
4144 (car gnus-decode-header-methods-cache)))
4145 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4148 (nconc gnus-decode-header-methods-cache (list x))
4149 (if (and gnus-newsgroup-name
4150 (string-match (car x) gnus-newsgroup-name))
4151 (nconc gnus-decode-header-methods-cache
4153 gnus-decode-header-methods))
4154 (let ((xlist gnus-decode-header-methods-cache))
4157 (narrow-to-region start end)
4159 (funcall (pop xlist) (point-min) (point-max))))))
4165 (defun gnus-article-header-presentation-method (entity situation)
4166 (mime-insert-header entity)
4169 (set-alist 'mime-header-presentation-method-alist
4170 'gnus-original-article-mode
4171 #'gnus-article-header-presentation-method)
4173 (defun gnus-mime-preview-quitting-method ()
4175 (gnus-article-show-summary)
4176 (mime-preview-kill-buffer)
4177 (delete-other-windows)
4178 (gnus-article-show-summary)
4179 (gnus-summary-select-article nil t)
4182 (set-alist 'mime-preview-quitting-method-alist
4183 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
4185 (defun gnus-following-method (buf)
4188 (message-yank-original)
4190 (goto-char (point-min))
4193 (set-alist 'mime-preview-following-method-alist
4194 'gnus-original-article-mode #'gnus-following-method)
4204 (run-hooks 'gnus-art-load-hook)
4206 ;;; gnus-art.el ends here