1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
62 (defgroup gnus-article-signature nil
64 :link '(custom-manual "(gnus)Article Signature")
67 (defgroup gnus-article-headers nil
69 :link '(custom-manual "(gnus)Hiding Headers")
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
82 (defgroup gnus-article-saving nil
84 :link '(custom-manual "(gnus)Saving Articles")
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
102 (defcustom gnus-ignored-headers
103 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
104 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
105 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
106 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
107 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
108 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
109 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
110 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
111 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
112 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
113 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
114 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
115 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
116 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
117 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
120 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
121 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
122 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
123 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
124 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
125 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
126 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
127 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
128 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
129 "^X-Received:" "^Content-length:" "X-precedence:")
130 "*All headers that start with this regexp will be hidden.
131 This variable can also be a list of regexps of headers to be ignored.
132 If `gnus-visible-headers' is non-nil, this variable will be ignored."
133 :type '(choice :custom-show nil
136 :group 'gnus-article-hiding)
138 (defcustom gnus-visible-headers
139 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
140 "*All headers that do not match this regexp will be hidden.
141 This variable can also be a list of regexp of headers to remain visible.
142 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
143 :type '(repeat :value-to-internal (lambda (widget value)
144 (custom-split-regexp-maybe value))
145 :match (lambda (widget value)
147 (widget-editable-list-match widget value)))
149 :group 'gnus-article-hiding)
151 (defcustom gnus-sorted-header-list
152 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
153 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
154 "*This variable is a list of regular expressions.
155 If it is non-nil, headers that match the regular expressions will
156 be placed first in the article buffer in the sequence specified by
158 :type '(repeat regexp)
159 :group 'gnus-article-hiding)
161 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
162 "Headers that are only to be displayed if they have interesting data.
163 Possible values in this list are `empty', `newsgroups', `followup-to',
164 `reply-to', `date', `long-to', and `many-to'."
165 :type '(set (const :tag "Headers with no content." empty)
166 (const :tag "Newsgroups with only one group." newsgroups)
167 (const :tag "Followup-to identical to newsgroups." followup-to)
168 (const :tag "Reply-to identical to from." reply-to)
169 (const :tag "Date less than four days old." date)
170 (const :tag "Very long To and/or Cc header." long-to)
171 (const :tag "Multiple To and/or Cc headers." many-to))
172 :group 'gnus-article-hiding)
174 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
175 "Regexp matching signature separator.
176 This can also be a list of regexps. In that case, it will be checked
177 from head to tail looking for a separator. Searches will be done from
178 the end of the buffer."
179 :type '(repeat string)
180 :group 'gnus-article-signature)
182 (defcustom gnus-signature-limit nil
183 "Provide a limit to what is considered a signature.
184 If it is a number, no signature may not be longer (in characters) than
185 that number. If it is a floating point number, no signature may be
186 longer (in lines) than that number. If it is a function, the function
187 will be called without any parameters, and if it returns nil, there is
188 no signature in the buffer. If it is a string, it will be used as a
189 regexp. If it matches, the text in question is not a signature."
190 :type '(choice (integer :value 200)
192 (function :value fun)
193 (regexp :value ".*"))
194 :group 'gnus-article-signature)
196 (defcustom gnus-hidden-properties '(invisible t intangible t)
197 "Property list to use for hiding text."
199 :group 'gnus-article-hiding)
201 (defcustom gnus-article-x-face-command
202 (if (and (fboundp 'image-type-available-p)
203 (or (image-type-available-p 'xpm)
204 (image-type-available-p 'xbm)))
205 'gnus-article-display-xface
206 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -")
207 "*String or function to be executed to display an X-Face header.
208 If it is a string, the command will be executed in a sub-shell
209 asynchronously. The compressed face will be piped to this command."
210 :type '(choice string
211 (function-item gnus-article-display-xface)
213 :group 'gnus-article-washing)
215 (defcustom gnus-article-x-face-too-ugly nil
216 "Regexp matching posters whose face shouldn't be shown automatically."
217 :type '(choice regexp (const nil))
218 :group 'gnus-article-washing)
220 (defcustom gnus-emphasis-alist
222 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
224 '(("_" "_" underline)
227 ("_/" "/_" underline-italic)
228 ("_\\*" "\\*_" underline-bold)
229 ("\\*/" "/\\*" bold-italic)
230 ("_\\*/" "/\\*_" underline-bold-italic))))
231 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
232 2 3 gnus-emphasis-underline)
236 (format format (car spec) (cadr spec))
237 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
239 "*Alist that says how to fontify certain phrases.
240 Each item looks like this:
242 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
244 The first element is a regular expression to be matched. The second
245 is a number that says what regular expression grouping used to find
246 the entire emphasized word. The third is a number that says what
247 regexp grouping should be displayed and highlighted. The fourth
248 is the face used for highlighting."
249 :type '(repeat (list :value ("" 0 0 default)
251 (integer :tag "Match group")
252 (integer :tag "Emphasize group")
254 :group 'gnus-article-emphasis)
256 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
257 "A regexp to describe whitespace which should not be emphasized.
258 Typical values are \"^[ \t]+\\|[ \t]*\n\" and \"[ \t]+\\|[ \t]*\n\".
259 The former avoids underlining of leading and trailing whitespace,
260 and the latter avoids underlining any whitespace at all."
261 :group 'gnus-article-emphasis
264 (defface gnus-emphasis-bold '((t (:bold t)))
265 "Face used for displaying strong emphasized text (*word*)."
266 :group 'gnus-article-emphasis)
268 (defface gnus-emphasis-italic '((t (:italic t)))
269 "Face used for displaying italic emphasized text (/word/)."
270 :group 'gnus-article-emphasis)
272 (defface gnus-emphasis-underline '((t (:underline t)))
273 "Face used for displaying underlined emphasized text (_word_)."
274 :group 'gnus-article-emphasis)
276 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
277 "Face used for displaying underlined bold emphasized text (_*word*_)."
278 :group 'gnus-article-emphasis)
280 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
281 "Face used for displaying underlined italic emphasized text (_/word/_)."
282 :group 'gnus-article-emphasis)
284 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
285 "Face used for displaying bold italic emphasized text (/*word*/)."
286 :group 'gnus-article-emphasis)
288 (defface gnus-emphasis-underline-bold-italic
289 '((t (:bold t :italic t :underline t)))
290 "Face used for displaying underlined bold italic emphasized text.
291 Esample: (_/*word*/_)."
292 :group 'gnus-article-emphasis)
294 (defface gnus-emphasis-highlight-words
295 '((t (:background "black" :foreground "yellow")))
296 "Face used for displaying highlighted words."
297 :group 'gnus-article-emphasis)
299 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
300 "Format for display of Date headers in article bodies.
301 See `format-time-string' for the possible values.
303 The variable can also be function, which should return a complete Date
304 header. The function is called with one argument, the time, which can
305 be fed to `format-time-string'."
306 :type '(choice string symbol)
307 :link '(custom-manual "(gnus)Article Date")
308 :group 'gnus-article-washing)
311 (autoload 'mail-extract-address-components "mail-extr"))
313 (defcustom gnus-save-all-headers t
314 "*If non-nil, don't remove any headers before saving."
315 :group 'gnus-article-saving
318 (defcustom gnus-prompt-before-saving 'always
319 "*This variable says how much prompting is to be done when saving articles.
320 If it is nil, no prompting will be done, and the articles will be
321 saved to the default files. If this variable is `always', each and
322 every article that is saved will be preceded by a prompt, even when
323 saving large batches of articles. If this variable is neither nil not
324 `always', there the user will be prompted once for a file name for
325 each invocation of the saving commands."
326 :group 'gnus-article-saving
327 :type '(choice (item always)
328 (item :tag "never" nil)
329 (sexp :tag "once" :format "%t\n" :value t)))
331 (defcustom gnus-saved-headers gnus-visible-headers
332 "Headers to keep if `gnus-save-all-headers' is nil.
333 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
334 If that variable is nil, however, all headers that match this regexp
335 will be kept while the rest will be deleted before saving."
336 :group 'gnus-article-saving
339 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
340 "A function to save articles in your favourite format.
341 The function must be interactively callable (in other words, it must
342 be an Emacs command).
344 Gnus provides the following functions:
346 * gnus-summary-save-in-rmail (Rmail format)
347 * gnus-summary-save-in-mail (Unix mail format)
348 * gnus-summary-save-in-folder (MH folder)
349 * gnus-summary-save-in-file (article format)
350 * gnus-summary-save-in-vm (use VM's folder format)
351 * gnus-summary-write-to-file (article format -- overwrite)."
352 :group 'gnus-article-saving
353 :type '(radio (function-item gnus-summary-save-in-rmail)
354 (function-item gnus-summary-save-in-mail)
355 (function-item gnus-summary-save-in-folder)
356 (function-item gnus-summary-save-in-file)
357 (function-item gnus-summary-save-in-vm)
358 (function-item gnus-summary-write-to-file)))
360 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
361 "A function generating a file name to save articles in Rmail format.
362 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
363 :group 'gnus-article-saving
366 (defcustom gnus-mail-save-name 'gnus-plain-save-name
367 "A function generating a file name to save articles in Unix mail format.
368 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
369 :group 'gnus-article-saving
372 (defcustom gnus-folder-save-name 'gnus-folder-save-name
373 "A function generating a file name to save articles in MH folder.
374 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
375 :group 'gnus-article-saving
378 (defcustom gnus-file-save-name 'gnus-numeric-save-name
379 "A function generating a file name to save articles in article format.
380 The function is called with NEWSGROUP, HEADERS, and optional
382 :group 'gnus-article-saving
385 (defcustom gnus-split-methods
386 '((gnus-article-archive-name)
387 (gnus-article-nndoc-name))
388 "*Variable used to suggest where articles are to be saved.
389 For instance, if you would like to save articles related to Gnus in
390 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
391 you could set this variable to something like:
393 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
394 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
396 This variable is an alist where the where the key is the match and the
397 value is a list of possible files to save in if the match is non-nil.
399 If the match is a string, it is used as a regexp match on the
400 article. If the match is a symbol, that symbol will be funcalled
401 from the buffer of the article to be saved with the newsgroup as the
402 parameter. If it is a list, it will be evaled in the same buffer.
404 If this form or function returns a string, this string will be used as
405 a possible file name; and if it returns a non-nil list, that list will
406 be used as possible file names."
407 :group 'gnus-article-saving
408 :type '(repeat (choice (list :value (fun) function)
409 (cons :value ("" "") regexp (repeat string))
412 (defcustom gnus-page-delimiter "^\^L"
413 "*Regexp describing what to use as article page delimiters.
414 The default value is \"^\^L\", which is a form linefeed at the
415 beginning of a line."
417 :group 'gnus-article-various)
419 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
420 "*The format specification for the article mode line.
421 See `gnus-summary-mode-line-format' for a closer description.
423 The following additional specs are available:
425 %w The article washing status.
426 %m The number of MIME parts in the article."
428 :group 'gnus-article-various)
430 (defcustom gnus-article-mode-hook nil
431 "*A hook for Gnus article mode."
433 :group 'gnus-article-various)
435 (defcustom gnus-article-menu-hook nil
436 "*Hook run after the creation of the article mode menu."
438 :group 'gnus-article-various)
440 (defcustom gnus-article-prepare-hook nil
441 "*A hook called after an article has been prepared in the article buffer."
443 :group 'gnus-article-various)
445 (defcustom gnus-article-hide-pgp-hook nil
446 "*A hook called after successfully hiding a PGP signature."
448 :group 'gnus-article-various)
450 (defcustom gnus-article-button-face 'bold
451 "Face used for highlighting buttons in the article buffer.
453 An article button is a piece of text that you can activate by pressing
454 `RET' or `mouse-2' above it."
456 :group 'gnus-article-buttons)
458 (defcustom gnus-article-mouse-face 'highlight
459 "Face used for mouse highlighting in the article buffer.
461 Article buttons will be displayed in this face when the cursor is
464 :group 'gnus-article-buttons)
466 (defcustom gnus-signature-face 'gnus-signature-face
467 "Face used for highlighting a signature in the article buffer.
468 Obsolete; use the face `gnus-signature-face' for customizations instead."
470 :group 'gnus-article-highlight
471 :group 'gnus-article-signature)
473 (defface gnus-signature-face
476 "Face used for highlighting a signature in the article buffer."
477 :group 'gnus-article-highlight
478 :group 'gnus-article-signature)
480 (defface gnus-header-from-face
483 (:foreground "spring green"))
486 (:foreground "red3"))
489 "Face used for displaying from headers."
490 :group 'gnus-article-headers
491 :group 'gnus-article-highlight)
493 (defface gnus-header-subject-face
496 (:foreground "SeaGreen3"))
499 (:foreground "red4"))
501 (:bold t :italic t)))
502 "Face used for displaying subject headers."
503 :group 'gnus-article-headers
504 :group 'gnus-article-highlight)
506 (defface gnus-header-newsgroups-face
509 (:foreground "yellow" :italic t))
512 (:foreground "MidnightBlue" :italic t))
515 "Face used for displaying newsgroups headers."
516 :group 'gnus-article-headers
517 :group 'gnus-article-highlight)
519 (defface gnus-header-name-face
522 (:foreground "SeaGreen"))
525 (:foreground "maroon"))
528 "Face used for displaying header names."
529 :group 'gnus-article-headers
530 :group 'gnus-article-highlight)
532 (defface gnus-header-content-face
535 (:foreground "forest green" :italic t))
538 (:foreground "indianred4" :italic t))
540 (:italic t))) "Face used for displaying header content."
541 :group 'gnus-article-headers
542 :group 'gnus-article-highlight)
544 (defcustom gnus-header-face-alist
545 '(("From" nil gnus-header-from-face)
546 ("Subject" nil gnus-header-subject-face)
547 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
548 ("" gnus-header-name-face gnus-header-content-face))
549 "*Controls highlighting of article header.
551 An alist of the form (HEADER NAME CONTENT).
553 HEADER is a regular expression which should match the name of an
554 header header and NAME and CONTENT are either face names or nil.
556 The name of each header field will be displayed using the face
557 specified by the first element in the list where HEADER match the
558 header name and NAME is non-nil. Similarly, the content will be
559 displayed by the first non-nil matching CONTENT face."
560 :group 'gnus-article-headers
561 :group 'gnus-article-highlight
562 :type '(repeat (list (regexp :tag "Header")
564 (item :tag "skip" nil)
565 (face :value default))
566 (choice :tag "Content"
567 (item :tag "skip" nil)
568 (face :value default)))))
570 (defcustom gnus-article-decode-hook
571 '(article-decode-charset article-decode-encoded-words)
572 "*Hook run to decode charsets in articles."
573 :group 'gnus-article-headers
576 (defcustom gnus-display-mime-function 'gnus-display-mime
577 "Function to display MIME articles."
578 :group 'gnus-article-mime
581 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
582 "Function used to decode headers.")
584 (defvar gnus-article-dumbquotes-map
602 "Table for MS-to-Latin1 translation.")
604 (defcustom gnus-ignored-mime-types nil
605 "List of MIME types that should be ignored by Gnus."
606 :group 'gnus-article-mime
607 :type '(repeat regexp))
609 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
610 "List of MIME types that should not be given buttons when rendered inline."
611 :group 'gnus-article-mime
612 :type '(repeat regexp))
614 (defcustom gnus-article-mime-part-function nil
615 "Function called with a MIME handle as the argument.
616 This is meant for people who want to do something automatic based
617 on parts -- for instance, adding Vcard info to a database."
618 :group 'gnus-article-mime
621 (defcustom gnus-mime-multipart-functions nil
622 "An alist of MIME types to functions to display them.")
624 (defcustom gnus-article-date-lapsed-new-header nil
625 "Whether the X-Sent and Date headers can coexist.
626 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
627 either replace the old \"Date:\" header (if this variable is nil), or
628 be added below it (otherwise)."
629 :group 'gnus-article-headers
632 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
633 "Function called with a MIME handle as the argument.
634 This is meant for people who want to view first matched part.
635 For `undisplayed-alternative' (default), the first undisplayed
636 part or alternative part is used. For `undisplayed', the first
637 undisplayed part is used. For a function, the first part which
638 the function return `t' is used. For `nil', the first part is
640 :group 'gnus-article-mime
642 (item :tag "first" :value nil)
643 (item :tag "undisplayed" :value undisplayed)
644 (item :tag "undisplayed or alternative"
645 :value undisplayed-alternative)
649 ;;; The treatment variables
652 (defvar gnus-part-display-hook nil
653 "Hook called on parts that are to receive treatment.")
655 (defvar gnus-article-treat-custom
656 '(choice (const :tag "Off" nil)
658 (const :tag "Header" head)
659 (const :tag "Last" last)
660 (integer :tag "Less")
661 (repeat :tag "Groups" regexp)
662 (sexp :tag "Predicate")))
664 (defvar gnus-article-treat-head-custom
665 '(choice (const :tag "Off" nil)
666 (const :tag "Header" head)))
668 (defvar gnus-article-treat-types '("text/plain")
671 (defvar gnus-inhibit-treatment nil
672 "Whether to inhibit treatment.")
674 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
675 "Highlight the signature.
676 Valid values are nil, t, `head', `last', an integer or a predicate.
677 See the manual for details."
678 :group 'gnus-article-treat
679 :type gnus-article-treat-custom)
680 (put 'gnus-treat-highlight-signature 'highlight t)
682 (defcustom gnus-treat-buttonize 100000
684 Valid values are nil, t, `head', `last', an integer or a predicate.
685 See the manual for details."
686 :group 'gnus-article-treat
687 :type gnus-article-treat-custom)
688 (put 'gnus-treat-buttonize 'highlight t)
690 (defcustom gnus-treat-buttonize-head 'head
691 "Add buttons to the head.
692 Valid values are nil, t, `head', `last', an integer or a predicate.
693 See the manual for details."
694 :group 'gnus-article-treat
695 :type gnus-article-treat-head-custom)
696 (put 'gnus-treat-buttonize-head 'highlight t)
698 (defcustom gnus-treat-emphasize 50000
700 Valid values are nil, t, `head', `last', an integer or a predicate.
701 See the manual for details."
702 :group 'gnus-article-treat
703 :type gnus-article-treat-custom)
704 (put 'gnus-treat-emphasize 'highlight t)
706 (defcustom gnus-treat-strip-cr nil
707 "Remove carriage returns.
708 Valid values are nil, t, `head', `last', an integer or a predicate.
709 See the manual for details."
710 :group 'gnus-article-treat
711 :type gnus-article-treat-custom)
713 (defcustom gnus-treat-hide-headers 'head
715 Valid values are nil, t, `head', `last', an integer or a predicate.
716 See the manual for details."
717 :group 'gnus-article-treat
718 :type gnus-article-treat-head-custom)
720 (defcustom gnus-treat-hide-boring-headers nil
721 "Hide boring headers.
722 Valid values are nil, t, `head', `last', an integer or a predicate.
723 See the manual for details."
724 :group 'gnus-article-treat
725 :type gnus-article-treat-head-custom)
727 (defcustom gnus-treat-hide-signature nil
729 Valid values are nil, t, `head', `last', an integer or a predicate.
730 See the manual for details."
731 :group 'gnus-article-treat
732 :type gnus-article-treat-custom)
734 (defcustom gnus-treat-fill-article nil
736 Valid values are nil, t, `head', `last', an integer or a predicate.
737 See the manual for details."
738 :group 'gnus-article-treat
739 :type gnus-article-treat-custom)
741 (defcustom gnus-treat-hide-citation nil
743 Valid values are nil, t, `head', `last', an integer or a predicate.
744 See the manual for details."
745 :group 'gnus-article-treat
746 :type gnus-article-treat-custom)
748 (defcustom gnus-treat-strip-list-identifiers 'head
749 "Strip list identifiers from `gnus-list-identifiers`.
750 Valid values are nil, t, `head', `last', an integer or a predicate.
751 See the manual for details."
752 :group 'gnus-article-treat
753 :type gnus-article-treat-custom)
755 (defcustom gnus-treat-strip-pgp t
756 "Strip PGP signatures.
757 Valid values are nil, t, `head', `last', an integer or a predicate.
758 See the manual for details."
759 :group 'gnus-article-treat
760 :type gnus-article-treat-custom)
762 (defcustom gnus-treat-strip-pem nil
763 "Strip PEM signatures.
764 Valid values are nil, t, `head', `last', an integer or a predicate.
765 See the manual for details."
766 :group 'gnus-article-treat
767 :type gnus-article-treat-custom)
769 (defcustom gnus-treat-strip-banner t
770 "Strip banners from articles.
771 The banner to be stripped is specified in the `banner' group parameter.
772 Valid values are nil, t, `head', `last', an integer or a predicate.
773 See the manual for details."
774 :group 'gnus-article-treat
775 :type gnus-article-treat-custom)
777 (defcustom gnus-treat-highlight-headers 'head
778 "Highlight the headers.
779 Valid values are nil, t, `head', `last', an integer or a predicate.
780 See the manual for details."
781 :group 'gnus-article-treat
782 :type gnus-article-treat-head-custom)
783 (put 'gnus-treat-highlight-headers 'highlight t)
785 (defcustom gnus-treat-highlight-citation t
786 "Highlight cited text.
787 Valid values are nil, t, `head', `last', an integer or a predicate.
788 See the manual for details."
789 :group 'gnus-article-treat
790 :type gnus-article-treat-custom)
791 (put 'gnus-treat-highlight-citation 'highlight t)
793 (defcustom gnus-treat-date-ut nil
794 "Display the Date in UT (GMT).
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-head-custom)
800 (defcustom gnus-treat-date-local nil
801 "Display the Date in the local timezone.
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-head-custom)
807 (defcustom gnus-treat-date-lapsed nil
808 "Display the Date header in a way that says how much time has elapsed.
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-head-custom)
814 (defcustom gnus-treat-date-original nil
815 "Display the date in the original timezone.
816 Valid values are nil, t, `head', `last', an integer or a predicate.
817 See the manual for details."
818 :group 'gnus-article-treat
819 :type gnus-article-treat-head-custom)
821 (defcustom gnus-treat-date-iso8601 nil
822 "Display the date in the ISO8601 format.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-head-custom)
828 (defcustom gnus-treat-date-user-defined nil
829 "Display the date in a user-defined format.
830 The format is defined by the `gnus-article-time-format' variable.
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833 :group 'gnus-article-treat
834 :type gnus-article-treat-head-custom)
836 (defcustom gnus-treat-strip-headers-in-body t
837 "Strip the X-No-Archive header line from the beginning of the body.
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840 :group 'gnus-article-treat
841 :type gnus-article-treat-custom)
843 (defcustom gnus-treat-strip-trailing-blank-lines nil
844 "Strip trailing blank lines.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-custom)
850 (defcustom gnus-treat-strip-leading-blank-lines nil
851 "Strip leading blank lines.
852 Valid values are nil, t, `head', `last', an integer or a predicate.
853 See the manual for details."
854 :group 'gnus-article-treat
855 :type gnus-article-treat-custom)
857 (defcustom gnus-treat-strip-multiple-blank-lines nil
858 "Strip multiple blank lines.
859 Valid values are nil, t, `head', `last', an integer or a predicate.
860 See the manual for details."
861 :group 'gnus-article-treat
862 :type gnus-article-treat-custom)
864 (defcustom gnus-treat-overstrike t
865 "Treat overstrike highlighting.
866 Valid values are nil, t, `head', `last', an integer or a predicate.
867 See the manual for details."
868 :group 'gnus-article-treat
869 :type gnus-article-treat-custom)
870 (put 'gnus-treat-overstrike 'highlight t)
872 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
874 "Display X-Face headers.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-head-custom)
879 (put 'gnus-treat-display-xface 'highlight t)
881 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
885 Valid values are nil, t, `head', `last', an integer or a predicate.
886 See the manual for details."
887 :group 'gnus-article-treat
888 :type gnus-article-treat-custom)
889 (put 'gnus-treat-display-smileys 'highlight t)
891 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
893 Valid values are nil, t, `head', `last', an integer or a predicate.
894 See the manual for details."
895 :group 'gnus-article-treat
896 :type gnus-article-treat-head-custom)
897 (put 'gnus-treat-display-picons 'highlight t)
899 (defcustom gnus-treat-capitalize-sentences nil
900 "Capitalize sentence-starting words.
901 Valid values are nil, t, `head', `last', an integer or a predicate.
902 See the manual for details."
903 :group 'gnus-article-treat
904 :type gnus-article-treat-custom)
906 (defcustom gnus-treat-fill-long-lines nil
908 Valid values are nil, t, `head', `last', an integer or a predicate.
909 See the manual for details."
910 :group 'gnus-article-treat
911 :type gnus-article-treat-custom)
913 (defcustom gnus-treat-play-sounds nil
915 Valid values are nil, t, `head', `last', an integer or a predicate.
916 See the manual for details."
917 :group 'gnus-article-treat
918 :type gnus-article-treat-custom)
920 (defcustom gnus-treat-translate nil
921 "Translate articles from one language to another.
922 Valid values are nil, t, `head', `last', an integer or a predicate.
923 See the manual for details."
924 :group 'gnus-article-treat
925 :type gnus-article-treat-custom)
927 ;;; Internal variables
929 (defvar article-goto-body-goes-to-point-min-p nil)
930 (defvar gnus-article-wash-types nil)
931 (defvar gnus-article-emphasis-alist nil)
933 (defvar gnus-article-mime-handle-alist-1 nil)
934 (defvar gnus-treatment-function-alist
935 '((gnus-treat-strip-banner gnus-article-strip-banner)
936 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
937 (gnus-treat-highlight-signature gnus-article-highlight-signature)
938 (gnus-treat-buttonize gnus-article-add-buttons)
939 (gnus-treat-fill-article gnus-article-fill-cited-article)
940 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
941 (gnus-treat-strip-cr gnus-article-remove-cr)
942 (gnus-treat-emphasize gnus-article-emphasize)
943 (gnus-treat-display-xface gnus-article-display-x-face)
944 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
945 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
946 (gnus-treat-hide-signature gnus-article-hide-signature)
947 (gnus-treat-hide-citation gnus-article-hide-citation)
948 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
949 (gnus-treat-strip-pgp gnus-article-hide-pgp)
950 (gnus-treat-strip-pem gnus-article-hide-pem)
951 (gnus-treat-highlight-headers gnus-article-highlight-headers)
952 (gnus-treat-highlight-citation gnus-article-highlight-citation)
953 (gnus-treat-highlight-signature gnus-article-highlight-signature)
954 (gnus-treat-date-ut gnus-article-date-ut)
955 (gnus-treat-date-local gnus-article-date-local)
956 (gnus-treat-date-lapsed gnus-article-date-lapsed)
957 (gnus-treat-date-original gnus-article-date-original)
958 (gnus-treat-date-user-defined gnus-article-date-user)
959 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
960 (gnus-treat-strip-trailing-blank-lines
961 gnus-article-remove-trailing-blank-lines)
962 (gnus-treat-strip-leading-blank-lines
963 gnus-article-strip-leading-blank-lines)
964 (gnus-treat-strip-multiple-blank-lines
965 gnus-article-strip-multiple-blank-lines)
966 (gnus-treat-overstrike gnus-article-treat-overstrike)
967 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
968 (gnus-treat-display-smileys gnus-smiley-display)
969 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
970 (gnus-treat-display-picons gnus-article-display-picons)
971 (gnus-treat-play-sounds gnus-earcon-display)))
973 (defvar gnus-article-mime-handle-alist nil)
974 (defvar article-lapsed-timer nil)
975 (defvar gnus-article-current-summary nil)
977 (defvar gnus-article-mode-syntax-table
978 (let ((table (copy-syntax-table text-mode-syntax-table)))
979 (modify-syntax-entry ?- "w" table)
980 (modify-syntax-entry ?> ")" table)
981 (modify-syntax-entry ?< "(" table)
983 "Syntax table used in article mode buffers.
984 Initialized from `text-mode-syntax-table.")
986 (defvar gnus-save-article-buffer nil)
988 (defvar gnus-article-mode-line-format-alist
989 (nconc '((?w (gnus-article-wash-status) ?s)
990 (?m (gnus-article-mime-part-status) ?s))
991 gnus-summary-mode-line-format-alist))
993 (defvar gnus-number-of-articles-to-be-saved nil)
995 (defvar gnus-inhibit-hiding nil)
997 (defsubst gnus-article-hide-text (b e props)
998 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
999 (add-text-properties b e props)
1000 (when (memq 'intangible props)
1002 (max (1- b) (point-min))
1003 b 'intangible (cddr (memq 'intangible props)))))
1004 (defsubst gnus-article-unhide-text (b e)
1005 "Remove hidden text properties from region between B and E."
1006 (remove-text-properties b e gnus-hidden-properties)
1007 (when (memq 'intangible gnus-hidden-properties)
1008 (put-text-property (max (1- b) (point-min))
1009 b 'intangible nil)))
1011 (defun gnus-article-hide-text-type (b e type)
1012 "Hide text of TYPE between B and E."
1013 (push type gnus-article-wash-types)
1014 (gnus-article-hide-text
1015 b e (cons 'article-type (cons type gnus-hidden-properties))))
1017 (defun gnus-article-unhide-text-type (b e type)
1018 "Unhide text of TYPE between B and E."
1019 (setq gnus-article-wash-types
1020 (delq type gnus-article-wash-types))
1021 (remove-text-properties
1022 b e (cons 'article-type (cons type gnus-hidden-properties)))
1023 (when (memq 'intangible gnus-hidden-properties)
1024 (put-text-property (max (1- b) (point-min))
1025 b 'intangible nil)))
1027 (defun gnus-article-hide-text-of-type (type)
1028 "Hide text of TYPE in the current buffer."
1030 (let ((b (point-min))
1032 (while (setq b (text-property-any b e 'article-type type))
1033 (add-text-properties b (incf b) gnus-hidden-properties)))))
1035 (defun gnus-article-delete-text-of-type (type)
1036 "Delete text of TYPE in the current buffer."
1038 (let ((b (point-min)))
1039 (while (setq b (text-property-any b (point-max) 'article-type type))
1041 b (or (text-property-not-all b (point-max) 'article-type type)
1044 (defun gnus-article-delete-invisible-text ()
1045 "Delete all invisible text in the current buffer."
1047 (let ((b (point-min)))
1048 (while (setq b (text-property-any b (point-max) 'invisible t))
1050 b (or (text-property-not-all b (point-max) 'invisible t)
1053 (defun gnus-article-text-type-exists-p (type)
1054 "Say whether any text of type TYPE exists in the buffer."
1055 (text-property-any (point-min) (point-max) 'article-type type))
1057 (defsubst gnus-article-header-rank ()
1058 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1059 (let ((list gnus-sorted-header-list)
1062 (when (looking-at (car list))
1064 (setq list (cdr list))
1068 (defun article-hide-headers (&optional arg delete)
1069 "Hide unwanted headers and possibly sort them as well."
1071 ;; This function might be inhibited.
1072 (unless gnus-inhibit-hiding
1075 (let ((buffer-read-only nil)
1076 (case-fold-search t)
1077 (max (1+ (length gnus-sorted-header-list)))
1078 (ignored (when (not gnus-visible-headers)
1079 (cond ((stringp gnus-ignored-headers)
1080 gnus-ignored-headers)
1081 ((listp gnus-ignored-headers)
1082 (mapconcat 'identity gnus-ignored-headers
1085 (cond ((stringp gnus-visible-headers)
1086 gnus-visible-headers)
1087 ((and gnus-visible-headers
1088 (listp gnus-visible-headers))
1089 (mapconcat 'identity gnus-visible-headers "\\|"))))
1090 (inhibit-point-motion-hooks t)
1092 ;; First we narrow to just the headers.
1093 (article-narrow-to-head)
1094 ;; Hide any "From " lines at the beginning of (mail) articles.
1095 (while (looking-at "From ")
1098 (delete-region (point-min) (point)))
1099 ;; Then treat the rest of the header lines.
1100 ;; Then we use the two regular expressions
1101 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1102 ;; select which header lines is to remain visible in the
1104 (while (re-search-forward "^[^ \t]*:" nil t)
1106 ;; Mark the rank of the header.
1108 (point) (1+ (point)) 'message-rank
1109 (if (or (and visible (looking-at visible))
1111 (not (looking-at ignored))))
1112 (gnus-article-header-rank)
1115 (message-sort-headers-1)
1116 (when (setq beg (text-property-any
1117 (point-min) (point-max) 'message-rank (+ 2 max)))
1118 ;; We delete the unwanted headers.
1119 (push 'headers gnus-article-wash-types)
1120 (add-text-properties (point-min) (+ 5 (point-min))
1121 '(article-type headers dummy-invisible t))
1122 (delete-region beg (point-max))))))))
1124 (defun article-hide-boring-headers (&optional arg)
1125 "Toggle hiding of headers that aren't very interesting.
1126 If given a negative prefix, always show; if given a positive prefix,
1128 (interactive (gnus-article-hidden-arg))
1129 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1130 (not gnus-show-all-headers))
1133 (let ((buffer-read-only nil)
1134 (list gnus-boring-article-headers)
1135 (inhibit-point-motion-hooks t)
1137 (article-narrow-to-head)
1139 (setq elem (pop list))
1140 (goto-char (point-min))
1142 ;; Hide empty headers.
1144 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1146 (gnus-article-hide-text-type
1147 (progn (beginning-of-line) (point))
1150 (if (re-search-forward "^[^ \t]" nil t)
1154 ;; Hide boring Newsgroups header.
1155 ((eq elem 'newsgroups)
1156 (when (equal (gnus-fetch-field "newsgroups")
1157 (gnus-group-real-name
1158 (if (boundp 'gnus-newsgroup-name)
1161 (gnus-article-hide-header "newsgroups")))
1162 ((eq elem 'followup-to)
1163 (when (equal (message-fetch-field "followup-to")
1164 (message-fetch-field "newsgroups"))
1165 (gnus-article-hide-header "followup-to")))
1166 ((eq elem 'reply-to)
1167 (let ((from (message-fetch-field "from"))
1168 (reply-to (message-fetch-field "reply-to")))
1173 (nth 1 (mail-extract-address-components from))
1174 (nth 1 (mail-extract-address-components reply-to)))))
1175 (gnus-article-hide-header "reply-to"))))
1177 (let ((date (message-fetch-field "date")))
1179 (< (days-between (current-time-string) date)
1181 (gnus-article-hide-header "date"))))
1183 (let ((to (message-fetch-field "to"))
1184 (cc (message-fetch-field "cc")))
1185 (when (> (length to) 1024)
1186 (gnus-article-hide-header "to"))
1187 (when (> (length cc) 1024)
1188 (gnus-article-hide-header "cc"))))
1192 (goto-char (point-min))
1193 (while (re-search-forward "^to:" nil t)
1194 (setq to-count (1+ to-count)))
1195 (when (> to-count 1)
1196 (while (> to-count 0)
1197 (goto-char (point-min))
1199 (re-search-forward "^to:" nil nil to-count)
1201 (narrow-to-region (point) (point-max))
1202 (gnus-article-hide-header "to"))
1203 (setq to-count (1- to-count))))
1204 (goto-char (point-min))
1205 (while (re-search-forward "^cc:" nil t)
1206 (setq cc-count (1+ cc-count)))
1207 (when (> cc-count 1)
1208 (while (> cc-count 0)
1209 (goto-char (point-min))
1211 (re-search-forward "^cc:" nil nil cc-count)
1213 (narrow-to-region (point) (point-max))
1214 (gnus-article-hide-header "cc"))
1215 (setq cc-count (1- cc-count)))))))))))))
1217 (defun gnus-article-hide-header (header)
1219 (goto-char (point-min))
1220 (when (re-search-forward (concat "^" header ":") nil t)
1221 (gnus-article-hide-text-type
1222 (progn (beginning-of-line) (point))
1225 (if (re-search-forward "^[^ \t]" nil t)
1230 (defvar gnus-article-normalized-header-length 40
1231 "Length of normalized headers.")
1233 (defun article-normalize-headers ()
1234 "Make all header lines 40 characters long."
1236 (let ((buffer-read-only nil)
1240 (article-narrow-to-head)
1243 ((< (setq column (- (gnus-point-at-eol) (point)))
1244 gnus-article-normalized-header-length)
1246 (insert (make-string
1247 (- gnus-article-normalized-header-length column)
1249 ((> column gnus-article-normalized-header-length)
1250 (gnus-put-text-property
1252 (forward-char gnus-article-normalized-header-length)
1259 (forward-line 1))))))
1261 (defun article-treat-dumbquotes ()
1262 "Translate M******** sm*rtq**t*s into proper text.
1263 Note that this function guesses whether a character is a sm*rtq**t* or
1264 not, so it should only be used interactively."
1266 (article-translate-strings gnus-article-dumbquotes-map))
1268 (defun article-translate-characters (from to)
1269 "Translate all characters in the body of the article according to FROM and TO.
1270 FROM is a string of characters to translate from; to is a string of
1271 characters to translate to."
1273 (when (article-goto-body)
1274 (let ((buffer-read-only nil)
1275 (x (make-string 225 ?x))
1277 (while (< (incf i) (length x))
1280 (while (< i (length from))
1281 (aset x (aref from i) (aref to i))
1283 (translate-region (point) (point-max) x)))))
1285 (defun article-translate-strings (map)
1286 "Translate all string in the body of the article according to MAP.
1287 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1289 (when (article-goto-body)
1290 (let ((buffer-read-only nil)
1292 (while (setq elem (pop map))
1294 (while (search-forward (car elem) nil t)
1295 (replace-match (cadr elem)))))))))
1297 (defun article-treat-overstrike ()
1298 "Translate overstrikes into bold text."
1301 (when (article-goto-body)
1302 (let ((buffer-read-only nil))
1303 (while (search-forward "\b" nil t)
1304 (let ((next (char-after))
1305 (previous (char-after (- (point) 2))))
1306 ;; We do the boldification/underlining by hiding the
1307 ;; overstrikes and putting the proper text property
1311 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1312 (put-text-property (point) (1+ (point)) 'face 'bold))
1314 (gnus-article-hide-text-type
1315 (1- (point)) (1+ (point)) 'overstrike)
1317 (- (point) 2) (1- (point)) 'face 'underline))
1319 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1321 (point) (1+ (point)) 'face 'underline)))))))))
1323 (defun article-fill-long-lines ()
1324 "Fill lines that are wider than the window width."
1327 (let ((buffer-read-only nil)
1328 (width (window-width (get-buffer-window (current-buffer)))))
1331 (let ((adaptive-fill-mode nil))
1334 (when (>= (current-column) (min fill-column width))
1335 (narrow-to-region (point) (gnus-point-at-bol))
1336 (fill-paragraph nil)
1337 (goto-char (point-max))
1339 (forward-line 1)))))))
1341 (defun article-capitalize-sentences ()
1342 "Capitalize the first word in each sentence."
1345 (let ((buffer-read-only nil)
1346 (paragraph-start "^[\n\^L]"))
1350 (forward-sentence)))))
1352 (defun article-remove-cr ()
1353 "Remove trailing CRs and then translate remaining CRs into LFs."
1356 (let ((buffer-read-only nil))
1357 (goto-char (point-min))
1358 (while (re-search-forward "\r+$" nil t)
1359 (replace-match "" t t))
1360 (goto-char (point-min))
1361 (while (search-forward "\r" nil t)
1362 (replace-match "\n" t t)))))
1364 (defun article-remove-trailing-blank-lines ()
1365 "Remove all trailing blank lines from the article."
1368 (let ((buffer-read-only nil))
1369 (goto-char (point-max))
1373 (while (and (not (bobp))
1374 (looking-at "^[ \t]*$")
1375 (not (gnus-annotation-in-region-p
1376 (point) (gnus-point-at-eol))))
1381 (defun article-display-x-face (&optional force)
1382 "Look for an X-Face header and display it if present."
1383 (interactive (list 'force))
1385 ;; Delete the old process, if any.
1386 (when (process-status "article-x-face")
1387 (delete-process "article-x-face"))
1388 (let ((inhibit-point-motion-hooks t)
1389 (case-fold-search t)
1392 (article-narrow-to-head)
1393 (goto-char (point-min))
1394 (setq from (message-fetch-field "from"))
1395 (goto-char (point-min))
1396 (while (and gnus-article-x-face-command
1399 ;; Check whether this face is censored.
1400 (not gnus-article-x-face-too-ugly)
1401 (and gnus-article-x-face-too-ugly from
1402 (not (string-match gnus-article-x-face-too-ugly
1404 ;; Has to be present.
1405 (re-search-forward "^X-Face: " nil t))
1406 ;; This used to try to do multiple faces (`while' instead of
1407 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1408 ;; work (b) it can crash some versions of Emacs (c) are
1409 ;; multiple faces really something to encourage?
1410 (when (stringp gnus-article-x-face-command)
1412 ;; We now have the area of the buffer where the X-Face is stored.
1415 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1416 ;; We display the face.
1417 (if (symbolp gnus-article-x-face-command)
1418 ;; The command is a lisp function, so we call it.
1419 (if (gnus-functionp gnus-article-x-face-command)
1420 (funcall gnus-article-x-face-command beg end)
1421 (error "%s is not a function" gnus-article-x-face-command))
1422 ;; The command is a string, so we interpret the command
1423 ;; as a, well, command, and fork it off.
1424 (let ((process-connection-type nil))
1425 (process-kill-without-query
1427 "article-x-face" nil shell-file-name shell-command-switch
1428 gnus-article-x-face-command))
1429 (process-send-region "article-x-face" beg end)
1430 (process-send-eof "article-x-face"))))))))))
1432 (defun article-decode-mime-words ()
1433 "Decode all MIME-encoded words in the article."
1436 (set-buffer gnus-article-buffer)
1437 (let ((inhibit-point-motion-hooks t)
1439 (mail-parse-charset gnus-newsgroup-charset)
1440 (mail-parse-ignored-charsets
1441 (save-excursion (set-buffer gnus-summary-buffer)
1442 gnus-newsgroup-ignored-charsets)))
1443 (mail-decode-encoded-word-region (point-min) (point-max)))))
1445 (defun article-decode-charset (&optional prompt)
1446 "Decode charset-encoded text in the article.
1447 If PROMPT (the prefix), prompt for a coding system to use."
1449 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1451 (mail-parse-charset gnus-newsgroup-charset)
1452 (mail-parse-ignored-charsets
1453 (save-excursion (condition-case nil
1454 (set-buffer gnus-summary-buffer)
1456 gnus-newsgroup-ignored-charsets))
1457 ct cte ctl charset format)
1460 (article-narrow-to-head)
1461 (setq ct (message-fetch-field "Content-Type" t)
1462 cte (message-fetch-field "Content-Transfer-Encoding" t)
1463 ctl (and ct (ignore-errors
1464 (mail-header-parse-content-type ct)))
1467 (mm-read-coding-system "Charset to decode: "))
1469 (mail-content-type-get ctl 'charset)))
1470 format (and ctl (mail-content-type-get ctl 'format)))
1472 (setq cte (mail-header-strip cte)))
1473 (if (and ctl (not (string-match "/" (car ctl))))
1475 (goto-char (point-max)))
1478 (narrow-to-region (point) (point-max))
1479 (when (and (or (not ctl)
1480 (equal (car ctl) "text/plain"))
1481 (not format)) ;; article with format will decode later.
1483 charset (and cte (intern (downcase
1484 (gnus-strip-whitespace cte))))
1487 (defun article-decode-encoded-words ()
1488 "Remove encoded-word encoding from headers."
1489 (let ((inhibit-point-motion-hooks t)
1490 (mail-parse-charset gnus-newsgroup-charset)
1491 (mail-parse-ignored-charsets
1492 (save-excursion (condition-case nil
1493 (set-buffer gnus-summary-buffer)
1495 gnus-newsgroup-ignored-charsets))
1498 (article-narrow-to-head)
1499 (funcall gnus-decode-header-function (point-min) (point-max)))))
1501 (defun article-de-quoted-unreadable (&optional force)
1502 "Translate a quoted-printable-encoded article.
1503 If FORCE, decode the article whether it is marked as quoted-printable
1505 (interactive (list 'force))
1507 (let ((buffer-read-only nil)
1508 (type (gnus-fetch-field "content-transfer-encoding"))
1509 (charset gnus-newsgroup-charset))
1511 (and type (string-match "quoted-printable" (downcase type))))
1513 (quoted-printable-decode-region (point) (point-max) charset)))))
1515 (defun article-de-base64-unreadable (&optional force)
1516 "Translate a base64 article.
1517 If FORCE, decode the article whether it is marked as base64 not."
1518 (interactive (list 'force))
1520 (let ((buffer-read-only nil)
1521 (type (gnus-fetch-field "content-transfer-encoding"))
1522 (charset gnus-newsgroup-charset))
1524 (and type (string-match "quoted-printable" (downcase type))))
1527 (narrow-to-region (point) (point-max))
1528 (base64-decode-region (point-min) (point-max))
1529 (if (mm-coding-system-p charset)
1530 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1535 (defun article-decode-HZ ()
1536 "Translate a HZ-encoded article."
1540 (let ((buffer-read-only nil))
1541 (rfc1843-decode-region (point-min) (point-max)))))
1543 (defun article-wash-html ()
1544 "Format an html article."
1547 (let ((buffer-read-only nil)
1548 (charset gnus-newsgroup-charset))
1550 (save-window-excursion
1552 (narrow-to-region (point) (point-max))
1554 (let ((w3-strict-width (window-width))
1555 (url-standalone-mode t))
1557 (w3-region (point-min) (point-max))
1560 (defun article-hide-list-identifiers ()
1561 "Remove list identifies from the Subject header.
1562 The `gnus-list-identifiers' variable specifies what to do."
1566 (let ((inhibit-point-motion-hooks t)
1568 (article-narrow-to-head)
1569 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1570 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1572 (goto-char (point-min))
1573 (when (re-search-forward
1574 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1575 " *\\)\\)+\\(Re: +\\)?\\)")
1577 (let ((s (or (match-string 3) (match-string 5))))
1578 (delete-region (match-beginning 1) (match-end 1))
1580 (goto-char (match-beginning 1))
1583 (defun article-hide-pgp ()
1584 "Remove any PGP headers and signatures in the current article."
1588 (let ((inhibit-point-motion-hooks t)
1589 buffer-read-only beg end)
1591 ;; Hide the "header".
1592 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1593 (push 'pgp gnus-article-wash-types)
1594 (delete-region (match-beginning 0) (match-end 0))
1595 ;; Remove armor headers (rfc2440 6.2)
1596 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1599 ;; Hide the actual signature.
1600 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1601 (setq end (1+ (match-beginning 0)))
1604 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1606 ;; Perhaps we shouldn't hide to the end of the buffer
1607 ;; if there is no end to the signature?
1609 ;; Hide "- " PGP quotation markers.
1611 (narrow-to-region beg end)
1612 (goto-char (point-min))
1613 (while (re-search-forward "^- " nil t)
1615 (match-beginning 0) (match-end 0)))
1617 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1619 (defun article-hide-pem (&optional arg)
1620 "Toggle hiding of any PEM headers and signatures in the current article.
1621 If given a negative prefix, always show; if given a positive prefix,
1623 (interactive (gnus-article-hidden-arg))
1624 (unless (gnus-article-check-hidden-text 'pem arg)
1626 (let (buffer-read-only end)
1627 (goto-char (point-min))
1628 ;; Hide the horrendously ugly "header".
1629 (when (and (search-forward
1630 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1632 (setq end (1+ (match-beginning 0))))
1633 (push 'pem gnus-article-wash-types)
1634 (gnus-article-hide-text-type
1636 (if (search-forward "\n\n" nil t)
1640 ;; Hide the trailer as well
1641 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1643 (gnus-article-hide-text-type
1644 (match-beginning 0) (match-end 0) 'pem)))))))
1646 (defun article-strip-banner ()
1647 "Strip the banner specified by the `banner' group parameter."
1651 (let ((inhibit-point-motion-hooks t)
1652 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1653 (gnus-signature-limit nil)
1654 buffer-read-only beg end)
1658 ((eq banner 'signature)
1659 (when (gnus-article-narrow-to-signature)
1662 (delete-region (point) (point-max))))
1664 (while (re-search-forward banner nil t)
1665 (delete-region (match-beginning 0) (match-end 0))))))))))
1667 (defun article-babel ()
1668 "Translate article using an online translation service."
1672 (set-buffer gnus-article-buffer)
1673 (when (article-goto-body)
1674 (let* ((buffer-read-only nil)
1677 (orig (buffer-substring start end))
1678 (trans (babel-as-string orig)))
1680 (narrow-to-region start end)
1681 (delete-region start end)
1684 (defun article-hide-signature (&optional arg)
1685 "Hide the signature in the current article.
1686 If given a negative prefix, always show; if given a positive prefix,
1688 (interactive (gnus-article-hidden-arg))
1689 (unless (gnus-article-check-hidden-text 'signature arg)
1692 (let ((buffer-read-only nil))
1693 (when (gnus-article-narrow-to-signature)
1694 (gnus-article-hide-text-type
1695 (point-min) (point-max) 'signature)))))))
1697 (defun article-strip-headers-in-body ()
1698 "Strip offensive headers from bodies."
1702 (let ((case-fold-search t))
1703 (when (looking-at "x-no-archive:")
1704 (gnus-delete-line)))))
1706 (defun article-strip-leading-blank-lines ()
1707 "Remove all blank lines from the beginning of the article."
1710 (let ((inhibit-point-motion-hooks t)
1712 (when (article-goto-body)
1713 (while (and (not (eobp))
1714 (looking-at "[ \t]*$"))
1715 (gnus-delete-line))))))
1717 (defun article-narrow-to-head ()
1718 "Narrow the buffer to the head of the message.
1719 Point is left at the beginning of the narrowed-to region."
1721 (goto-char (point-min))
1722 (if (search-forward "\n\n" nil 1)
1725 (goto-char (point-min)))
1727 (defun article-goto-body ()
1728 "Place point at the start of the body."
1729 (goto-char (point-min))
1731 ;; This variable is only bound when dealing with separate
1733 (article-goto-body-goes-to-point-min-p
1735 ((search-forward "\n\n" nil t)
1738 (goto-char (point-max))
1741 (defun article-strip-multiple-blank-lines ()
1742 "Replace consecutive blank lines with one empty line."
1745 (let ((inhibit-point-motion-hooks t)
1747 ;; First make all blank lines empty.
1749 (while (re-search-forward "^[ \t]+$" nil t)
1750 (unless (gnus-annotation-in-region-p
1751 (match-beginning 0) (match-end 0))
1752 (replace-match "" nil t)))
1753 ;; Then replace multiple empty lines with a single empty line.
1755 (while (re-search-forward "\n\n\n+" nil t)
1756 (unless (gnus-annotation-in-region-p
1757 (match-beginning 0) (match-end 0))
1758 (replace-match "\n\n" t t))))))
1760 (defun article-strip-leading-space ()
1761 "Remove all white space from the beginning of the lines in the article."
1764 (let ((inhibit-point-motion-hooks t)
1767 (while (re-search-forward "^[ \t]+" nil t)
1768 (replace-match "" t t)))))
1770 (defun article-strip-trailing-space ()
1771 "Remove all white space from the end of the lines in the article."
1774 (let ((inhibit-point-motion-hooks t)
1777 (while (re-search-forward "[ \t]+$" nil t)
1778 (replace-match "" t t)))))
1780 (defun article-strip-blank-lines ()
1781 "Strip leading, trailing and multiple blank lines."
1783 (article-strip-leading-blank-lines)
1784 (article-remove-trailing-blank-lines)
1785 (article-strip-multiple-blank-lines))
1787 (defun article-strip-all-blank-lines ()
1788 "Strip all blank lines."
1791 (let ((inhibit-point-motion-hooks t)
1794 (while (re-search-forward "^[ \t]*\n" nil t)
1795 (replace-match "" t t)))))
1797 (defun gnus-article-narrow-to-signature ()
1798 "Narrow to the signature; return t if a signature is found, else nil."
1799 (let ((inhibit-point-motion-hooks t))
1800 (when (gnus-article-search-signature)
1802 ;; Check whether we have some limits to what we consider
1803 ;; to be a signature.
1804 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1805 (list gnus-signature-limit)))
1807 (while (setq limit (pop limits))
1808 (if (or (and (integerp limit)
1809 (< (- (point-max) (point)) limit))
1811 (< (count-lines (point) (point-max)) limit))
1812 (and (gnus-functionp limit)
1814 (and (stringp limit)
1815 (not (re-search-forward limit nil t))))
1816 () ; This limit did not succeed.
1820 (narrow-to-region (point) (point-max))
1823 (defun gnus-article-search-signature ()
1824 "Search the current buffer for the signature separator.
1825 Put point at the beginning of the signature separator."
1826 (let ((cur (point)))
1827 (goto-char (point-max))
1828 (if (if (stringp gnus-signature-separator)
1829 (re-search-backward gnus-signature-separator nil t)
1830 (let ((seps gnus-signature-separator))
1832 (not (re-search-backward (car seps) nil t)))
1839 (defun gnus-article-hidden-arg ()
1840 "Return the current prefix arg as a number, or 0 if no prefix."
1841 (list (if current-prefix-arg
1842 (prefix-numeric-value current-prefix-arg)
1845 (defun gnus-article-check-hidden-text (type arg)
1846 "Return nil if hiding is necessary.
1847 Arg can be nil or a number. Nil and positive means hide, negative
1848 means show, 0 means toggle."
1851 (let ((hide (gnus-article-hidden-text-p type)))
1857 (gnus-article-show-hidden-text type))
1859 (if (eq hide 'hidden)
1860 (gnus-article-show-hidden-text type)
1863 (defun gnus-article-hidden-text-p (type)
1864 "Say whether the current buffer contains hidden text of type TYPE."
1865 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1867 (not (get-text-property pos 'invisible))
1868 (not (get-text-property pos 'dummy-invisible)))
1870 (text-property-any (1+ pos) (point-max) 'article-type type)))
1875 (defun gnus-article-show-hidden-text (type &optional hide)
1876 "Show all hidden text of type TYPE.
1877 If HIDE, hide the text instead."
1879 (let ((buffer-read-only nil)
1880 (inhibit-point-motion-hooks t)
1883 (while (setq beg (text-property-any end (point-max) 'article-type type))
1886 (text-property-not-all beg (point-max) 'article-type type)
1889 (gnus-article-hide-text beg end gnus-hidden-properties)
1890 (gnus-article-unhide-text beg end))
1894 (defconst article-time-units
1895 `((year . ,(* 365.25 24 60 60))
1896 (week . ,(* 7 24 60 60))
1897 (day . ,(* 24 60 60))
1901 "Mapping from time units to seconds.")
1903 (defun article-date-ut (&optional type highlight header)
1904 "Convert DATE date to universal time in the current article.
1905 If TYPE is `local', convert to local time; if it is `lapsed', output
1906 how much time has lapsed since DATE. For `lapsed', the value of
1907 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1908 should replace the \"Date:\" one, or should be added below it."
1909 (interactive (list 'ut t))
1910 (let* ((header (or header
1911 (message-fetch-field "date")
1913 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1916 ((not gnus-article-date-lapsed-new-header)
1922 (date (if (vectorp header) (mail-header-date header)
1924 (inhibit-point-motion-hooks t)
1929 (article-narrow-to-head)
1930 (when (re-search-forward tdate-regexp nil t)
1931 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1932 date (or (get-text-property (gnus-point-at-bol)
1935 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1937 (when (and date (not (string= date "")))
1938 (goto-char (point-min))
1939 (let ((buffer-read-only nil))
1940 ;; Delete any old Date headers.
1941 (while (re-search-forward date-regexp nil t)
1943 (delete-region (progn (beginning-of-line) (point))
1944 (progn (forward-line 1) (point)))
1945 (delete-region (progn (beginning-of-line) (point))
1946 (progn (end-of-line) (point)))
1947 (setq pos (point))))
1948 (when (and (not pos) (re-search-forward tdate-regexp nil t))
1950 (if pos (goto-char pos))
1951 (insert (article-make-date-line date (or type 'ut)))
1957 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1958 (put-text-property (match-beginning 1) (1+ (match-end 1))
1959 'original-date date)
1960 (put-text-property (match-beginning 1) (1+ (match-end 1))
1962 (put-text-property (match-beginning 2) (match-end 2)
1965 (defun article-make-date-line (date type)
1966 "Return a DATE line of TYPE."
1967 (let ((time (condition-case ()
1971 ;; Convert to the local timezone. We have to slap a
1972 ;; `condition-case' round the calls to the timezone
1973 ;; functions since they aren't particularly resistant to
1976 (let ((tz (car (current-time-zone time))))
1977 (format "Date: %s %s%02d%02d" (current-time-string time)
1978 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1979 (/ (% (abs tz) 3600) 60))))
1980 ;; Convert to Universal Time.
1983 (current-time-string
1984 (let* ((e (parse-time-string date))
1985 (tm (apply 'encode-time e))
1987 (ls (- (cadr tm) (car (current-time-zone time)))))
1988 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1989 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1992 ;; Get the original date from the article.
1993 ((eq type 'original)
1994 (concat "Date: " (if (string-match "\n+$" date)
1995 (substring date 0 (match-beginning 0))
1997 ;; Let the user define the format.
1999 (if (gnus-functionp gnus-article-time-format)
2000 (funcall gnus-article-time-format time)
2003 (format-time-string gnus-article-time-format time))))
2006 (let ((tz (car (current-time-zone time))))
2009 (format-time-string "%Y%m%dT%H%M%S" time)
2010 (format "%s%02d%02d"
2011 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2012 (/ (% (abs tz) 3600) 60)))))
2013 ;; Do an X-Sent lapsed format.
2015 ;; If the date is seriously mangled, the timezone functions are
2016 ;; liable to bug out, so we ignore all errors.
2017 (let* ((now (current-time))
2018 (real-time (subtract-time now time))
2019 (real-sec (and real-time
2020 (+ (* (float (car real-time)) 65536)
2022 (sec (and real-time (abs real-sec)))
2032 ;; This is a bit convoluted, but basically we go
2033 ;; through the time units for years, weeks, etc,
2034 ;; and divide things to see whether that results
2035 ;; in positive answers.
2038 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2039 ;; The (remaining) seconds are too few to
2040 ;; be divided into this time unit.
2042 ;; It's big enough, so we output it.
2043 (setq sec (- sec (* num (cdr unit))))
2045 (concat (if prev ", " "") (int-to-string
2047 " " (symbol-name (car unit))
2048 (if (> num 1) "s" ""))
2050 article-time-units "")
2051 ;; If dates are odd, then it might appear like the
2052 ;; article was sent in the future.
2055 " in the future"))))))
2057 (error "Unknown conversion type: %s" type)))))
2059 (defun article-date-local (&optional highlight)
2060 "Convert the current article date to the local timezone."
2061 (interactive (list t))
2062 (article-date-ut 'local highlight))
2064 (defun article-date-original (&optional highlight)
2065 "Convert the current article date to what it was originally.
2066 This is only useful if you have used some other date conversion
2067 function and want to see what the date was before converting."
2068 (interactive (list t))
2069 (article-date-ut 'original highlight))
2071 (defun article-date-lapsed (&optional highlight)
2072 "Convert the current article date to time lapsed since it was sent."
2073 (interactive (list t))
2074 (article-date-ut 'lapsed highlight))
2076 (defun article-update-date-lapsed ()
2077 "Function to be run from a timer to update the lapsed time line."
2078 (let (deactivate-mark)
2083 (set-buffer (window-buffer w))
2084 (when (eq major-mode 'gnus-article-mode)
2085 (goto-char (point-min))
2086 (when (re-search-forward "^X-Sent:" nil t)
2087 (article-date-lapsed t))))
2090 (defun gnus-start-date-timer (&optional n)
2091 "Start a timer to update the X-Sent header in the article buffers.
2092 The numerical prefix says how frequently (in seconds) the function
2097 (gnus-stop-date-timer)
2098 (setq article-lapsed-timer
2099 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2101 (defun gnus-stop-date-timer ()
2102 "Stop the X-Sent timer."
2104 (when article-lapsed-timer
2105 (nnheader-cancel-timer article-lapsed-timer)
2106 (setq article-lapsed-timer nil)))
2108 (defun article-date-user (&optional highlight)
2109 "Convert the current article date to the user-defined format.
2110 This format is defined by the `gnus-article-time-format' variable."
2111 (interactive (list t))
2112 (article-date-ut 'user highlight))
2114 (defun article-date-iso8601 (&optional highlight)
2115 "Convert the current article date to ISO8601."
2116 (interactive (list t))
2117 (article-date-ut 'iso8601 highlight))
2119 (defun article-show-all ()
2120 "Show all hidden text in the article buffer."
2123 (let ((buffer-read-only nil))
2124 (gnus-article-unhide-text (point-min) (point-max)))))
2126 (defun article-emphasize (&optional arg)
2127 "Emphasize text according to `gnus-emphasis-alist'."
2128 (interactive (gnus-article-hidden-arg))
2129 (unless (gnus-article-check-hidden-text 'emphasis arg)
2133 (with-current-buffer gnus-summary-buffer
2134 gnus-article-emphasis-alist)
2136 gnus-emphasis-alist))
2137 (buffer-read-only nil)
2138 (props (append '(article-type emphasis)
2139 gnus-hidden-properties))
2140 regexp elem beg invisible visible face)
2143 (while (setq elem (pop alist))
2145 (setq regexp (car elem)
2146 invisible (nth 1 elem)
2147 visible (nth 2 elem)
2149 (while (re-search-forward regexp nil t)
2150 (when (and (match-beginning visible) (match-beginning invisible))
2151 (push 'emphasis gnus-article-wash-types)
2152 (gnus-article-hide-text
2153 (match-beginning invisible) (match-end invisible) props)
2154 (gnus-article-unhide-text-type
2155 (match-beginning visible) (match-end visible) 'emphasis)
2156 (gnus-put-text-property-excluding-newlines
2157 (match-beginning visible) (match-end visible) 'face face)
2158 (goto-char (match-end invisible)))))))))
2160 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2161 "Setup newsgroup emphasis alist."
2162 (unless gnus-article-emphasis-alist
2163 (let ((name (and gnus-newsgroup-name
2164 (gnus-group-real-name gnus-newsgroup-name))))
2165 (make-local-variable 'gnus-article-emphasis-alist)
2166 (setq gnus-article-emphasis-alist
2168 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2169 (while (setq elem (pop alist))
2170 (when (and name (string-match (car elem) name))
2172 highlight (copy-sequence (cdr elem)))))
2174 (copy-sequence highlight-words)
2175 (if gnus-newsgroup-name
2176 (copy-sequence (gnus-group-find-parameter
2177 gnus-newsgroup-name 'highlight-words t)))
2178 gnus-emphasis-alist)))))
2180 (defvar gnus-summary-article-menu)
2181 (defvar gnus-summary-post-menu)
2183 ;;; Saving functions.
2185 (defun gnus-article-save (save-buffer file &optional num)
2186 "Save the currently selected article."
2187 (unless gnus-save-all-headers
2188 ;; Remove headers according to `gnus-saved-headers'.
2189 (let ((gnus-visible-headers
2190 (or gnus-saved-headers gnus-visible-headers))
2191 (gnus-article-buffer save-buffer))
2193 (set-buffer save-buffer)
2194 (article-hide-headers 1 t))))
2195 (save-window-excursion
2196 (if (not gnus-default-article-saver)
2197 (error "No default saver is defined")
2198 ;; !!! Magic! The saving functions all save
2199 ;; `gnus-save-article-buffer' (or so they think), but we
2200 ;; bind that variable to our save-buffer.
2201 (set-buffer gnus-article-buffer)
2202 (let* ((gnus-save-article-buffer save-buffer)
2205 ((not gnus-prompt-before-saving) 'default)
2206 ((eq gnus-prompt-before-saving 'always) nil)
2208 (gnus-number-of-articles-to-be-saved
2209 (when (eq gnus-prompt-before-saving t)
2211 (set-buffer gnus-article-current-summary)
2212 (funcall gnus-default-article-saver filename)))))
2214 (defun gnus-read-save-file-name (prompt &optional filename
2215 function group headers variable)
2217 (funcall function group headers (symbol-value variable)))
2222 ((eq filename 'default)
2228 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2231 (if (and gnus-number-of-articles-to-be-saved
2232 (> gnus-number-of-articles-to-be-saved 1))
2233 (format "these %d articles"
2234 gnus-number-of-articles-to-be-saved)
2237 ;; Let the split methods have their say.
2239 ;; No split name was found.
2242 (concat prompt " (default "
2243 (file-name-nondirectory default-name) ") ")
2244 (file-name-directory default-name)
2246 ;; A single group name is returned.
2247 ((stringp split-name)
2249 (funcall function split-name headers
2250 (symbol-value variable)))
2252 (concat prompt " (default "
2253 (file-name-nondirectory default-name) ") ")
2254 (file-name-directory default-name)
2256 ;; A single split name was found
2257 ((= 1 (length split-name))
2258 (let* ((name (expand-file-name
2259 (car split-name) gnus-article-save-directory))
2260 (dir (cond ((file-directory-p name)
2261 (file-name-as-directory name))
2262 ((file-exists-p name) name)
2263 (t gnus-article-save-directory))))
2265 (concat prompt " (default " name ") ")
2267 ;; A list of splits was found.
2269 (setq split-name (nreverse split-name))
2271 (let ((file-name-history
2272 (nconc split-name file-name-history)))
2276 (concat prompt " (`M-p' for defaults) ")
2277 gnus-article-save-directory
2279 gnus-article-save-directory)))
2280 (car (push result file-name-history)))))))
2281 ;; Create the directory.
2282 (gnus-make-directory (file-name-directory file))
2283 ;; If we have read a directory, we append the default file name.
2284 (when (file-directory-p file)
2285 (setq file (concat (file-name-as-directory file)
2286 (file-name-nondirectory default-name))))
2287 ;; Possibly translate some characters.
2288 (nnheader-translate-file-chars file)))))
2289 (gnus-make-directory (file-name-directory result))
2290 (set variable result)))
2292 (defun gnus-article-archive-name (group)
2293 "Return the first instance of an \"Archive-name\" in the current buffer."
2294 (let ((case-fold-search t))
2295 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2296 (nnheader-concat gnus-article-save-directory
2297 (match-string 1)))))
2299 (defun gnus-article-nndoc-name (group)
2300 "If GROUP is an nndoc group, return the name of the parent group."
2301 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2302 (gnus-group-get-parameter group 'save-article-group)))
2304 (defun gnus-summary-save-in-rmail (&optional filename)
2305 "Append this article to Rmail file.
2306 Optional argument FILENAME specifies file name.
2307 Directory to save to is default to `gnus-article-save-directory'."
2308 (setq filename (gnus-read-save-file-name
2309 "Save %s in rmail file:" filename
2310 gnus-rmail-save-name gnus-newsgroup-name
2311 gnus-current-headers 'gnus-newsgroup-last-rmail))
2312 (gnus-eval-in-buffer-window gnus-save-article-buffer
2316 (gnus-output-to-rmail filename))))
2319 (defun gnus-summary-save-in-mail (&optional filename)
2320 "Append this article to Unix mail file.
2321 Optional argument FILENAME specifies file name.
2322 Directory to save to is default to `gnus-article-save-directory'."
2323 (setq filename (gnus-read-save-file-name
2324 "Save %s in Unix mail file:" filename
2325 gnus-mail-save-name gnus-newsgroup-name
2326 gnus-current-headers 'gnus-newsgroup-last-mail))
2327 (gnus-eval-in-buffer-window gnus-save-article-buffer
2331 (if (and (file-readable-p filename)
2332 (mail-file-babyl-p filename))
2333 (rmail-output-to-rmail-file filename t)
2334 (gnus-output-to-mail filename)))))
2337 (defun gnus-summary-save-in-file (&optional filename overwrite)
2338 "Append this article to file.
2339 Optional argument FILENAME specifies file name.
2340 Directory to save to is default to `gnus-article-save-directory'."
2341 (setq filename (gnus-read-save-file-name
2342 "Save %s in file:" filename
2343 gnus-file-save-name gnus-newsgroup-name
2344 gnus-current-headers 'gnus-newsgroup-last-file))
2345 (gnus-eval-in-buffer-window gnus-save-article-buffer
2349 (when (and overwrite
2350 (file-exists-p filename))
2351 (delete-file filename))
2352 (gnus-output-to-file filename))))
2355 (defun gnus-summary-write-to-file (&optional filename)
2356 "Write this article to a file.
2357 Optional argument FILENAME specifies file name.
2358 The directory to save in defaults to `gnus-article-save-directory'."
2359 (gnus-summary-save-in-file nil t))
2361 (defun gnus-summary-save-body-in-file (&optional filename)
2362 "Append this article body to a file.
2363 Optional argument FILENAME specifies file name.
2364 The directory to save in defaults to `gnus-article-save-directory'."
2365 (setq filename (gnus-read-save-file-name
2366 "Save %s body in file:" filename
2367 gnus-file-save-name gnus-newsgroup-name
2368 gnus-current-headers 'gnus-newsgroup-last-file))
2369 (gnus-eval-in-buffer-window gnus-save-article-buffer
2373 (when (article-goto-body)
2374 (narrow-to-region (point) (point-max)))
2375 (gnus-output-to-file filename))))
2378 (defun gnus-summary-save-in-pipe (&optional command)
2379 "Pipe this article to subprocess."
2381 (cond ((and (eq command 'default)
2382 gnus-last-shell-command)
2383 gnus-last-shell-command)
2387 "Shell command on %s: "
2388 (if (and gnus-number-of-articles-to-be-saved
2389 (> gnus-number-of-articles-to-be-saved 1))
2390 (format "these %d articles"
2391 gnus-number-of-articles-to-be-saved)
2393 gnus-last-shell-command))))
2394 (when (string-equal command "")
2395 (setq command gnus-last-shell-command))
2396 (gnus-eval-in-buffer-window gnus-article-buffer
2399 (shell-command-on-region (point-min) (point-max) command nil)))
2400 (setq gnus-last-shell-command command))
2402 ;;; Article file names when saving.
2404 (defun gnus-capitalize-newsgroup (newsgroup)
2405 "Capitalize NEWSGROUP name."
2406 (when (not (zerop (length newsgroup)))
2407 (concat (char-to-string (upcase (aref newsgroup 0)))
2408 (substring newsgroup 1))))
2410 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2411 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2412 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2413 Otherwise, it is like ~/News/news/group/num."
2416 (concat (if (gnus-use-long-file-name 'not-save)
2417 (gnus-capitalize-newsgroup newsgroup)
2418 (gnus-newsgroup-directory-form newsgroup))
2419 "/" (int-to-string (mail-header-number headers)))
2420 gnus-article-save-directory)))
2422 (string-equal (file-name-directory default)
2423 (file-name-directory last-file))
2424 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2426 (or last-file default))))
2428 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2429 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2430 If variable `gnus-use-long-file-name' is non-nil, it is
2431 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2434 (concat (if (gnus-use-long-file-name 'not-save)
2436 (gnus-newsgroup-directory-form newsgroup))
2437 "/" (int-to-string (mail-header-number headers)))
2438 gnus-article-save-directory)))
2440 (string-equal (file-name-directory default)
2441 (file-name-directory last-file))
2442 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2444 (or last-file default))))
2446 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2447 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2448 If variable `gnus-use-long-file-name' is non-nil, it is
2449 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2452 (if (gnus-use-long-file-name 'not-save)
2453 (gnus-capitalize-newsgroup newsgroup)
2454 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2455 gnus-article-save-directory)))
2457 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2458 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2459 If variable `gnus-use-long-file-name' is non-nil, it is
2460 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2463 (if (gnus-use-long-file-name 'not-save)
2465 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2466 gnus-article-save-directory)))
2473 (setq afunc (car func)
2476 gfunc (intern (format "gnus-%s" func))))
2478 (if (not (fboundp afunc))
2480 `(lambda (&optional interactive &rest args)
2481 ,(documentation afunc t)
2482 (interactive (list t))
2484 (set-buffer gnus-article-buffer)
2486 (call-interactively ',afunc)
2487 (apply ',afunc args))))))))
2488 '(article-hide-headers
2489 article-hide-boring-headers
2490 article-treat-overstrike
2491 article-fill-long-lines
2492 article-capitalize-sentences
2494 article-display-x-face
2495 article-de-quoted-unreadable
2496 article-de-base64-unreadable
2499 article-mime-decode-quoted-printable
2500 article-hide-list-identifiers
2502 article-strip-banner
2505 article-hide-signature
2506 article-strip-headers-in-body
2507 article-remove-trailing-blank-lines
2508 article-strip-leading-blank-lines
2509 article-strip-multiple-blank-lines
2510 article-strip-leading-space
2511 article-strip-trailing-space
2512 article-strip-blank-lines
2513 article-strip-all-blank-lines
2515 article-date-iso8601
2516 article-date-original
2518 article-decode-mime-words
2519 article-decode-charset
2520 article-decode-encoded-words
2524 article-treat-dumbquotes
2525 article-normalize-headers
2526 (article-show-all . gnus-article-show-all-headers))))
2529 ;;; Gnus article mode
2532 (put 'gnus-article-mode 'mode-class 'special)
2534 (set-keymap-parent gnus-article-mode-map widget-keymap)
2536 (gnus-define-keys gnus-article-mode-map
2537 " " gnus-article-goto-next-page
2538 "\177" gnus-article-goto-prev-page
2539 [delete] gnus-article-goto-prev-page
2540 [backspace] gnus-article-goto-prev-page
2541 "\C-c^" gnus-article-refer-article
2542 "h" gnus-article-show-summary
2543 "s" gnus-article-show-summary
2544 "\C-c\C-m" gnus-article-mail
2545 "?" gnus-article-describe-briefly
2546 "e" gnus-summary-edit-article
2547 "<" beginning-of-buffer
2549 "\C-c\C-i" gnus-info-find-node
2552 "\C-d" gnus-article-read-summary-keys
2553 "\M-*" gnus-article-read-summary-keys
2554 "\M-#" gnus-article-read-summary-keys
2555 "\M-^" gnus-article-read-summary-keys
2556 "\M-g" gnus-article-read-summary-keys)
2558 (substitute-key-definition
2559 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2561 (defun gnus-article-make-menu-bar ()
2562 (gnus-turn-off-edit-menu 'article)
2563 (unless (boundp 'gnus-article-article-menu)
2565 gnus-article-article-menu gnus-article-mode-map ""
2567 ["Scroll forwards" gnus-article-goto-next-page t]
2568 ["Scroll backwards" gnus-article-goto-prev-page t]
2569 ["Show summary" gnus-article-show-summary t]
2570 ["Fetch Message-ID at point" gnus-article-refer-article t]
2571 ["Mail to address at point" gnus-article-mail t]
2572 ["Send a bug report" gnus-bug t]))
2575 gnus-article-treatment-menu gnus-article-mode-map ""
2577 ["Hide headers" gnus-article-hide-headers t]
2578 ["Hide signature" gnus-article-hide-signature t]
2579 ["Hide citation" gnus-article-hide-citation t]
2580 ["Treat overstrike" gnus-article-treat-overstrike t]
2581 ["Remove carriage return" gnus-article-remove-cr t]
2582 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2583 ["Remove base64" gnus-article-de-base64-unreadable t]
2584 ["Treat html" gnus-article-wash-html t]
2585 ["Decode HZ" gnus-article-decode-HZ t]))
2587 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2589 (when (boundp 'gnus-summary-post-menu)
2590 (define-key gnus-article-mode-map [menu-bar post]
2591 (cons "Post" gnus-summary-post-menu)))
2593 (gnus-run-hooks 'gnus-article-menu-hook)))
2595 (defun gnus-article-mode ()
2596 "Major mode for displaying an article.
2598 All normal editing commands are switched off.
2600 The following commands are available in addition to all summary mode
2602 \\<gnus-article-mode-map>
2603 \\[gnus-article-next-page]\t Scroll the article one page forwards
2604 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2605 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2606 \\[gnus-article-show-summary]\t Display the summary buffer
2607 \\[gnus-article-mail]\t Send a reply to the address near point
2608 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2609 \\[gnus-info-find-node]\t Go to the Gnus info node"
2611 (when (gnus-visual-p 'article-menu 'menu)
2612 (gnus-article-make-menu-bar))
2613 (gnus-simplify-mode-line)
2614 (setq mode-name "Article")
2615 (setq major-mode 'gnus-article-mode)
2616 (make-local-variable 'minor-mode-alist)
2617 (use-local-map gnus-article-mode-map)
2618 (gnus-update-format-specifications nil 'article-mode)
2619 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2620 (make-local-variable 'gnus-page-broken)
2621 (make-local-variable 'gnus-button-marker-list)
2622 (make-local-variable 'gnus-article-current-summary)
2623 (make-local-variable 'gnus-article-mime-handles)
2624 (make-local-variable 'gnus-article-decoded-p)
2625 (make-local-variable 'gnus-article-mime-handle-alist)
2626 (make-local-variable 'gnus-article-wash-types)
2627 (gnus-set-default-directory)
2628 (buffer-disable-undo)
2629 (setq buffer-read-only t)
2630 (set-syntax-table gnus-article-mode-syntax-table)
2631 (mm-enable-multibyte)
2632 (gnus-run-hooks 'gnus-article-mode-hook))
2634 (defun gnus-article-setup-buffer ()
2635 "Initialize the article buffer."
2636 (let* ((name (if gnus-single-article-buffer "*Article*"
2637 (concat "*Article " gnus-newsgroup-name "*")))
2639 (progn (string-match "\\*Article" name)
2640 (concat " *Original Article"
2641 (substring name (match-end 0))))))
2642 (setq gnus-article-buffer name)
2643 (setq gnus-original-article-buffer original)
2644 (setq gnus-article-mime-handle-alist nil)
2645 ;; This might be a variable local to the summary buffer.
2646 (unless gnus-single-article-buffer
2648 (set-buffer gnus-summary-buffer)
2649 (setq gnus-article-buffer name)
2650 (setq gnus-original-article-buffer original)
2651 (gnus-set-global-variables)))
2652 (gnus-article-setup-highlight-words)
2653 ;; Init original article buffer.
2655 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2656 (mm-enable-multibyte)
2657 (setq major-mode 'gnus-original-article-mode)
2658 (make-local-variable 'gnus-original-article))
2659 (if (get-buffer name)
2662 (when gnus-article-mime-handles
2663 (mm-destroy-parts gnus-article-mime-handles))
2664 (buffer-disable-undo)
2665 (setq buffer-read-only t)
2666 (unless (eq major-mode 'gnus-article-mode)
2667 (gnus-article-mode))
2670 (set-buffer (gnus-get-buffer-create name))
2672 (make-local-variable 'gnus-summary-buffer)
2673 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2674 (current-buffer)))))
2676 ;; Set article window start at LINE, where LINE is the number of lines
2677 ;; from the head of the article.
2678 (defun gnus-article-set-window-start (&optional line)
2680 (get-buffer-window gnus-article-buffer t)
2682 (set-buffer gnus-article-buffer)
2683 (goto-char (point-min))
2686 (gnus-message 6 "Moved to bookmark")
2687 (search-forward "\n\n" nil t)
2691 (defun gnus-article-prepare (article &optional all-headers header)
2692 "Prepare ARTICLE in article mode buffer.
2693 ARTICLE should either be an article number or a Message-ID.
2694 If ARTICLE is an id, HEADER should be the article headers.
2695 If ALL-HEADERS is non-nil, no headers are hidden."
2697 ;; Make sure we start in a summary buffer.
2698 (unless (eq major-mode 'gnus-summary-mode)
2699 (set-buffer gnus-summary-buffer))
2700 (setq gnus-summary-buffer (current-buffer))
2701 (let* ((gnus-article (if header (mail-header-number header) article))
2702 (summary-buffer (current-buffer))
2703 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2704 (group gnus-newsgroup-name)
2707 (gnus-article-setup-buffer)
2708 (set-buffer gnus-article-buffer)
2709 ;; Deactivate active regions.
2710 (when (and (boundp 'transient-mark-mode)
2711 transient-mark-mode)
2712 (setq mark-active nil))
2713 (if (not (setq result (let ((buffer-read-only nil))
2714 (gnus-request-article-this-buffer
2716 ;; There is no such article.
2718 (when (and (numberp article)
2719 (not (memq article gnus-newsgroup-sparse)))
2720 (setq gnus-article-current
2721 (cons gnus-newsgroup-name article))
2722 (set-buffer gnus-summary-buffer)
2723 (setq gnus-current-article article)
2724 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2726 (gnus-summary-set-agent-mark article)
2727 (message "Message marked for downloading"))
2728 (gnus-summary-mark-article article gnus-canceled-mark)
2729 (unless (memq article gnus-newsgroup-sparse)
2730 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2731 (if (or (eq result 'pseudo)
2732 (eq result 'nneething))
2735 (set-buffer summary-buffer)
2736 (push article gnus-newsgroup-history)
2737 (setq gnus-last-article gnus-current-article
2738 gnus-current-article 0
2739 gnus-current-headers nil
2740 gnus-article-current nil)
2741 (if (eq result 'nneething)
2742 (gnus-configure-windows 'summary)
2743 (gnus-configure-windows 'article))
2744 (gnus-set-global-variables))
2745 (let ((gnus-article-mime-handle-alist-1
2746 gnus-article-mime-handle-alist))
2747 (gnus-set-mode-line 'article)))
2748 ;; The result from the `request' was an actual article -
2749 ;; or at least some text that is now displayed in the
2751 (when (and (numberp article)
2752 (not (eq article gnus-current-article)))
2753 ;; Seems like a new article has been selected.
2754 ;; `gnus-current-article' must be an article number.
2756 (set-buffer summary-buffer)
2757 (push article gnus-newsgroup-history)
2758 (setq gnus-last-article gnus-current-article
2759 gnus-current-article article
2760 gnus-current-headers
2761 (gnus-summary-article-header gnus-current-article)
2762 gnus-article-current
2763 (cons gnus-newsgroup-name gnus-current-article))
2764 (unless (vectorp gnus-current-headers)
2765 (setq gnus-current-headers nil))
2766 (gnus-summary-goto-subject gnus-current-article)
2767 (when (gnus-summary-show-thread)
2768 ;; If the summary buffer really was folded, the
2769 ;; previous goto may not actually have gone to
2770 ;; the right article, but the thread root instead.
2772 (gnus-summary-goto-subject gnus-current-article))
2773 (gnus-run-hooks 'gnus-mark-article-hook)
2774 (gnus-set-mode-line 'summary)
2775 (when (gnus-visual-p 'article-highlight 'highlight)
2776 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2777 ;; Set the global newsgroup variables here.
2778 (gnus-set-global-variables)
2779 (setq gnus-have-all-headers
2780 (or all-headers gnus-show-all-headers))))
2781 (when (or (numberp article)
2783 (gnus-article-prepare-display)
2785 (goto-char (point-min))
2786 (setq gnus-page-broken
2787 (when gnus-break-pages
2788 (gnus-narrow-to-page)
2790 (let ((gnus-article-mime-handle-alist-1
2791 gnus-article-mime-handle-alist))
2792 (gnus-set-mode-line 'article))
2794 (set-window-point (get-buffer-window (current-buffer)) (point))
2795 (gnus-configure-windows 'article)
2799 (defun gnus-article-prepare-display ()
2800 "Make the current buffer look like a nice article."
2801 ;; Hooks for getting information from the article.
2802 ;; This hook must be called before being narrowed.
2803 (let ((gnus-article-buffer (current-buffer))
2805 (unless (eq major-mode 'gnus-article-mode)
2806 (gnus-article-mode))
2807 (setq buffer-read-only nil
2808 gnus-article-wash-types nil)
2809 (gnus-run-hooks 'gnus-tmp-internal-hook)
2810 (when gnus-display-mime-function
2811 (funcall gnus-display-mime-function))
2812 (gnus-run-hooks 'gnus-article-prepare-hook)))
2815 ;;; Gnus MIME viewing functions
2818 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2819 "The following specs can be used:
2821 %T MIME type, along with additional info
2822 %n The `name' parameter
2823 %d The description, if any
2824 %l The length of the encoded part
2825 %p The part identifier number
2826 %e Dots if the part isn't displayed")
2828 (defvar gnus-mime-button-line-format-alist
2829 '((?t gnus-tmp-type ?s)
2830 (?T gnus-tmp-type-long ?s)
2831 (?n gnus-tmp-name ?s)
2832 (?d gnus-tmp-description ?s)
2834 (?l gnus-tmp-length ?d)
2835 (?e gnus-tmp-dots ?s)))
2837 (defvar gnus-mime-button-commands
2838 '((gnus-article-press-button "\r" "Toggle Display")
2839 (gnus-mime-view-part "v" "View Interactively...")
2840 (gnus-mime-view-part-as-type "t" "View As Type...")
2841 (gnus-mime-save-part "o" "Save...")
2842 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2843 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2844 (gnus-mime-internalize-part "E" "View Internally")
2845 (gnus-mime-externalize-part "e" "View Externally")
2846 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2848 (defun gnus-article-mime-part-status ()
2849 (if gnus-article-mime-handle-alist-1
2850 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2853 (defvar gnus-mime-button-map nil)
2854 (unless gnus-mime-button-map
2855 (setq gnus-mime-button-map (make-sparse-keymap))
2856 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2857 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2858 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2860 (define-key gnus-mime-button-map (cadr c) (car c)))
2861 gnus-mime-button-commands))
2863 (defun gnus-mime-button-menu (event)
2864 "Construct a context-sensitive menu of MIME commands."
2867 (let ((pos (event-start event)))
2868 (set-buffer (window-buffer (posn-window pos)))
2869 (goto-char (posn-point pos))
2870 (gnus-article-check-buffer)
2871 (let ((response (x-popup-menu
2873 ("" ,@(mapcar (lambda (c)
2874 (cons (caddr c) (car c)))
2875 gnus-mime-button-commands))))))
2877 (call-interactively response))))))
2879 (defun gnus-mime-view-all-parts (&optional handles)
2880 "View all the MIME parts."
2882 (save-current-buffer
2883 (set-buffer gnus-article-buffer)
2884 (let ((handles (or handles gnus-article-mime-handles))
2885 (mail-parse-charset gnus-newsgroup-charset)
2886 (mail-parse-ignored-charsets
2887 (save-excursion (set-buffer gnus-summary-buffer)
2888 gnus-newsgroup-ignored-charsets)))
2889 (if (stringp (car handles))
2890 (gnus-mime-view-all-parts (cdr handles))
2891 (mapcar 'mm-display-part handles)))))
2893 (defun gnus-mime-save-part ()
2894 "Save the MIME part under point."
2896 (gnus-article-check-buffer)
2897 (let ((data (get-text-property (point) 'gnus-data)))
2898 (mm-save-part data)))
2900 (defun gnus-mime-pipe-part ()
2901 "Pipe the MIME part under point to a process."
2903 (gnus-article-check-buffer)
2904 (let ((data (get-text-property (point) 'gnus-data)))
2905 (mm-pipe-part data)))
2907 (defun gnus-mime-view-part ()
2908 "Interactively choose a viewing method for the MIME part under point."
2910 (gnus-article-check-buffer)
2911 (let ((data (get-text-property (point) 'gnus-data)))
2912 (mm-interactively-view-part data)))
2914 (defun gnus-mime-view-part-as-type-internal ()
2915 (gnus-article-check-buffer)
2916 (let* ((name (mail-content-type-get
2917 (mm-handle-type (get-text-property (point) 'gnus-data))
2919 (def-type (and name (mm-default-file-encoding name))))
2920 (and def-type (cons def-type 0))))
2922 (defun gnus-mime-view-part-as-type (mime-type)
2923 "Choose a MIME media type, and view the part as such."
2925 (list (completing-read
2926 "View as MIME type: "
2927 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
2929 (gnus-mime-view-part-as-type-internal))))
2930 (gnus-article-check-buffer)
2931 (let ((handle (get-text-property (point) 'gnus-data)))
2932 (gnus-mm-display-part
2933 (mm-make-handle (mm-handle-buffer handle)
2934 (cons mime-type (cdr (mm-handle-type handle)))
2935 (mm-handle-encoding handle)
2936 (mm-handle-undisplayer handle)
2937 (mm-handle-disposition handle)
2938 (mm-handle-description handle)
2939 (mm-handle-cache handle)
2940 (mm-handle-id handle)))))
2942 (defun gnus-mime-copy-part (&optional handle)
2943 "Put the the MIME part under point into a new buffer."
2945 (gnus-article-check-buffer)
2946 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2947 (contents (mm-get-part handle))|
2948 (base (file-name-nondirectory
2950 (mail-content-type-get (mm-handle-type handle) 'name)
2951 (mail-content-type-get (mm-handle-type handle)
2954 (buffer (generate-new-buffer base)))
2955 (switch-to-buffer buffer)
2957 ;; We do it this way to make `normal-mode' set the appropriate mode.
2960 (setq buffer-file-name (expand-file-name base))
2962 (setq buffer-file-name nil))
2963 (goto-char (point-min))))
2965 (defun gnus-mime-inline-part (&optional handle)
2966 "Insert the MIME part under point into the current buffer."
2968 (gnus-article-check-buffer)
2969 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2973 (if (mm-handle-undisplayer handle)
2974 (mm-remove-part handle)
2975 (setq contents (mm-get-part handle))
2977 (mm-insert-inline handle contents)
2980 (defun gnus-mime-externalize-part (&optional handle)
2981 "View the MIME part under point with an external viewer."
2983 (gnus-article-check-buffer)
2984 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2985 (mm-user-display-methods nil)
2986 (mm-inline-large-images nil)
2987 (mail-parse-charset gnus-newsgroup-charset)
2988 (mail-parse-ignored-charsets
2989 (save-excursion (set-buffer gnus-summary-buffer)
2990 gnus-newsgroup-ignored-charsets)))
2991 (if (mm-handle-undisplayer handle)
2992 (mm-remove-part handle)
2993 (mm-display-part handle))))
2995 (defun gnus-mime-internalize-part (&optional handle)
2996 "View the MIME part under point with an internal viewer.
2997 In no internal viewer is available, use an external viewer."
2999 (gnus-article-check-buffer)
3000 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3001 (mm-inlined-types '(".*"))
3002 (mm-inline-large-images t)
3003 (mail-parse-charset gnus-newsgroup-charset)
3004 (mail-parse-ignored-charsets
3005 (save-excursion (set-buffer gnus-summary-buffer)
3006 gnus-newsgroup-ignored-charsets)))
3007 (if (mm-handle-undisplayer handle)
3008 (mm-remove-part handle)
3009 (mm-display-part handle))))
3011 (defun gnus-article-part-wrapper (n function)
3012 (save-current-buffer
3013 (set-buffer gnus-article-buffer)
3014 (when (> n (length gnus-article-mime-handle-alist))
3015 (error "No such part"))
3016 (gnus-article-goto-part n)
3017 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3018 (funcall function handle))))
3020 (defun gnus-article-pipe-part (n)
3021 "Pipe MIME part N, which is the numerical prefix."
3023 (gnus-article-part-wrapper n 'mm-pipe-part))
3025 (defun gnus-article-save-part (n)
3026 "Save MIME part N, which is the numerical prefix."
3028 (gnus-article-part-wrapper n 'mm-save-part))
3030 (defun gnus-article-interactively-view-part (n)
3031 "View MIME part N interactively, which is the numerical prefix."
3033 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3035 (defun gnus-article-copy-part (n)
3036 "Copy MIME part N, which is the numerical prefix."
3038 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3040 (defun gnus-article-externalize-part (n)
3041 "View MIME part N externally, which is the numerical prefix."
3043 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3045 (defun gnus-article-inline-part (n)
3046 "Inline MIME part N, which is the numerical prefix."
3048 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3050 (defun gnus-article-mime-match-handle-first (condition)
3052 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3053 (while (setq ihandle (pop alist))
3055 ((functionp condition)
3056 (funcall condition (cdr ihandle)))
3057 ((eq condition 'undisplayed)
3058 (not (or (mm-handle-undisplayer (cdr ihandle))
3059 (equal (mm-handle-media-type (cdr ihandle))
3060 "multipart/alternative"))))
3061 ((eq condition 'undisplayed-alternative)
3062 (not (mm-handle-undisplayer (cdr ihandle))))
3064 (gnus-article-goto-part (car ihandle))
3065 (or (not n) (< (car ihandle) n)))
3066 (setq n (car ihandle))))
3070 (defun gnus-article-view-part (&optional n)
3071 "View MIME part N, which is the numerical prefix."
3073 (save-current-buffer
3074 (set-buffer gnus-article-buffer)
3075 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3076 gnus-article-mime-match-handle-function)))
3077 (when (> n (length gnus-article-mime-handle-alist))
3078 (error "No such part"))
3079 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3080 (when (gnus-article-goto-part n)
3081 (if (equal (car handle) "multipart/alternative")
3082 (gnus-article-press-button)
3083 (when (eq (gnus-mm-display-part handle) 'internal)
3084 (gnus-set-window-start)))))))
3086 (defun gnus-mm-display-part (handle)
3087 "Display HANDLE and fix MIME button."
3088 (let ((id (get-text-property (point) 'gnus-part))
3093 (let ((window (selected-window))
3094 (mail-parse-charset gnus-newsgroup-charset)
3095 (mail-parse-ignored-charsets
3096 (save-excursion (set-buffer gnus-summary-buffer)
3097 gnus-newsgroup-ignored-charsets)))
3100 (let ((win (get-buffer-window (current-buffer) t))
3103 (select-window win))
3106 (if (mm-handle-displayed-p handle)
3107 ;; This will remove the part.
3108 (mm-display-part handle)
3110 (narrow-to-region (point) (1+ (point)))
3111 (mm-display-part handle)
3112 ;; We narrow to the part itself and
3113 ;; then call the treatment functions.
3114 (goto-char (point-min))
3116 (narrow-to-region (point) (point-max))
3119 (1- (length gnus-article-mime-handles))
3120 (mm-handle-media-type handle)))))
3121 (select-window window))))
3123 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3124 (gnus-insert-mime-button
3125 handle id (list (mm-handle-displayed-p handle)))
3126 (goto-char point))))
3128 (defun gnus-article-goto-part (n)
3129 "Go to MIME part N."
3130 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3132 (goto-char point))))
3134 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3135 (let ((gnus-tmp-name
3136 (or (mail-content-type-get (mm-handle-type handle)
3138 (mail-content-type-get (mm-handle-disposition handle)
3141 (gnus-tmp-type (mm-handle-media-type handle))
3142 (gnus-tmp-description
3143 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3146 (if (if displayed (car displayed)
3147 (mm-handle-displayed-p handle))
3149 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3151 gnus-tmp-type-long b e)
3152 (when (string-match ".*/" gnus-tmp-name)
3153 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3154 (setq gnus-tmp-type-long (concat gnus-tmp-type
3155 (and (not (equal gnus-tmp-name ""))
3156 (concat "; " gnus-tmp-name))))
3157 (or (equal gnus-tmp-description "")
3158 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3163 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3164 `(local-map ,gnus-mime-button-map
3165 keymap ,gnus-mime-button-map
3166 gnus-callback gnus-mm-display-part
3167 gnus-part ,gnus-tmp-id
3168 article-type annotation
3171 (widget-convert-button 'link b e
3173 :action 'gnus-widget-press-button
3174 :button-keymap gnus-mime-button-map
3177 ;; Needed to properly clear the message
3178 ;; due to a bug in wid-edit
3179 (setq help-echo-owns-message t)
3181 "Click to %s the MIME part; %s for more options"
3182 (if (mm-handle-displayed-p
3183 (widget-get widget :mime-handle))
3185 (if gnus-xemacs "button3" "mouse-3"))))))
3187 (defun gnus-widget-press-button (elems el)
3188 (goto-char (widget-get elems :from))
3189 (gnus-article-press-button))
3191 (defvar gnus-displaying-mime nil)
3193 (defun gnus-display-mime (&optional ihandles)
3194 "Display the MIME parts."
3196 (save-selected-window
3197 (let ((window (get-buffer-window gnus-article-buffer))
3200 (select-window window)
3201 ;; We have to do this since selecting the window
3202 ;; may change the point. So we set the window point.
3203 (set-window-point window point)))
3204 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3205 buffer-read-only handle name type b e display)
3206 (when (and (not ihandles)
3207 (not gnus-displaying-mime))
3208 ;; Top-level call; we clean up.
3209 (when gnus-article-mime-handles
3210 (mm-destroy-parts gnus-article-mime-handles)
3211 (setq gnus-article-mime-handle-alist nil));; A trick.
3212 (setq gnus-article-mime-handles handles)
3213 ;; We allow users to glean info from the handles.
3214 (when gnus-article-mime-part-function
3215 (gnus-mime-part-function handles)))
3217 (or (not (stringp (car handles)))
3220 (when (and (not ihandles)
3221 (not gnus-displaying-mime))
3222 ;; Clean up for mime parts.
3224 (delete-region (point) (point-max)))
3225 (let ((gnus-displaying-mime t))
3226 (gnus-mime-display-part handles)))
3229 (narrow-to-region (point) (point-max))
3230 (gnus-treat-article nil 1 1)
3233 ;; Highlight the headers.
3237 (narrow-to-region (point-min) (point))
3238 (gnus-treat-article 'head))))))))
3240 (defvar gnus-mime-display-multipart-as-mixed nil)
3242 (defun gnus-mime-display-part (handle)
3245 ((not (stringp (car handle)))
3246 (gnus-mime-display-single handle))
3247 ;; User-defined multipart
3248 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3249 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3251 ;; multipart/alternative
3252 ((and (equal (car handle) "multipart/alternative")
3253 (not gnus-mime-display-multipart-as-mixed))
3254 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3255 (push (cons id handle) gnus-article-mime-handle-alist)
3256 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3257 ;; multipart/related
3258 ((and (equal (car handle) "multipart/related")
3259 (not gnus-mime-display-multipart-as-mixed))
3260 ;;;!!!We should find the start part, but we just default
3261 ;;;!!!to the first part.
3262 (gnus-mime-display-part (cadr handle)))
3263 ;; Other multiparts are handled like multipart/mixed.
3265 (gnus-mime-display-mixed (cdr handle)))))
3267 (defun gnus-mime-part-function (handles)
3268 (if (stringp (car handles))
3269 (mapcar 'gnus-mime-part-function (cdr handles))
3270 (funcall gnus-article-mime-part-function handles)))
3272 (defun gnus-mime-display-mixed (handles)
3273 (mapcar 'gnus-mime-display-part handles))
3275 (defun gnus-mime-display-single (handle)
3276 (let ((type (mm-handle-media-type handle))
3277 (ignored gnus-ignored-mime-types)
3284 (when (string-match (pop ignored) type)
3285 (throw 'ignored nil)))
3286 (if (and (setq not-attachment
3287 (and (not (mm-inline-override-p handle))
3288 (or (not (mm-handle-disposition handle))
3289 (equal (car (mm-handle-disposition handle))
3291 (mm-attachment-override-p handle))))
3292 (mm-automatic-display-p handle)
3293 (or (mm-inlined-p handle)
3294 (mm-automatic-external-display-p type)))
3296 (when (equal (mm-handle-media-supertype handle) "text")
3298 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3299 (push (cons id handle) gnus-article-mime-handle-alist)
3300 (when (or (not display)
3301 (not (gnus-unbuttonized-mime-type-p type)))
3302 ;(gnus-article-insert-newline)
3303 (gnus-insert-mime-button
3304 handle id (list (or display (and not-attachment text))))
3305 (gnus-article-insert-newline)
3306 ;(gnus-article-insert-newline)
3308 (let ((beg (point)))
3314 (let ((mail-parse-charset gnus-newsgroup-charset)
3315 (mail-parse-ignored-charsets
3316 (save-excursion (condition-case ()
3317 (set-buffer gnus-summary-buffer)
3319 gnus-newsgroup-ignored-charsets)))
3320 (mm-display-part handle t))
3321 (goto-char (point-max)))
3322 ((and text not-attachment)
3326 (gnus-article-insert-newline)
3327 (mm-insert-inline handle (mm-get-part handle))
3328 (goto-char (point-max))))
3332 (narrow-to-region beg (point))
3334 nil (length gnus-article-mime-handle-alist)
3335 (1- (length gnus-article-mime-handles))
3336 (mm-handle-media-type handle)))))))))
3338 (defun gnus-unbuttonized-mime-type-p (type)
3339 "Say whether TYPE is to be unbuttonized."
3340 (unless gnus-inhibit-mime-unbuttonizing
3342 (let ((types gnus-unbuttonized-mime-types))
3344 (when (string-match (pop types) type)
3345 (throw 'found t)))))))
3347 (defun gnus-article-insert-newline ()
3348 "Insert a newline, but mark it as undeletable."
3349 (gnus-put-text-property
3350 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3352 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3353 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3356 handle buffer-read-only from props begend not-pref)
3357 (save-window-excursion
3360 (narrow-to-region (car ibegend)
3363 (goto-char (car ibegend))
3366 (delete-region (point-min) (point-max))
3367 (mm-remove-parts handles))
3368 (setq begend (list (point-marker)))
3370 (unless (setq not-pref (cadr (member preferred ihandles)))
3371 (setq not-pref (car ihandles)))
3373 (not (gnus-unbuttonized-mime-type-p
3374 "multipart/alternative")))
3375 (gnus-add-text-properties
3378 (insert (format "%d. " id))
3382 (unless ,(not ibegend)
3383 (setq gnus-article-mime-handle-alist
3384 ',gnus-article-mime-handle-alist))
3385 (gnus-mime-display-alternative
3386 ',ihandles ',not-pref ',begend ,id))
3387 local-map ,gnus-mime-button-map
3388 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3389 face ,gnus-article-button-face
3390 keymap ,gnus-mime-button-map
3393 (widget-convert-button 'link from (point)
3394 :action 'gnus-widget-press-button
3395 :button-keymap gnus-widget-button-keymap)
3397 (while (setq handle (pop handles))
3398 (gnus-add-text-properties
3401 (insert (format "(%c) %-18s"
3402 (if (equal handle preferred) ?* ? )
3403 (mm-handle-media-type handle)))
3407 (unless ,(not ibegend)
3408 (setq gnus-article-mime-handle-alist
3409 ',gnus-article-mime-handle-alist))
3410 (gnus-mime-display-alternative
3411 ',ihandles ',handle ',begend ,id))
3412 local-map ,gnus-mime-button-map
3413 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3414 face ,gnus-article-button-face
3415 keymap ,gnus-mime-button-map
3418 (widget-convert-button 'link from (point)
3419 :action 'gnus-widget-press-button
3420 :button-keymap gnus-widget-button-keymap)
3424 (if (stringp (car preferred))
3425 (gnus-display-mime preferred)
3426 (let ((mail-parse-charset gnus-newsgroup-charset)
3427 (mail-parse-ignored-charsets
3428 (save-excursion (set-buffer gnus-summary-buffer)
3429 gnus-newsgroup-ignored-charsets)))
3430 (mm-display-part preferred)
3434 (narrow-to-region (car begend) (point-max))
3436 nil (length gnus-article-mime-handle-alist)
3437 (1- (length gnus-article-mime-handles))
3438 (mm-handle-media-type handle))))))
3439 (goto-char (point-max))
3440 (setcdr begend (point-marker)))))
3442 (goto-char point))))
3444 (defun gnus-article-wash-status ()
3445 "Return a string which display status of article washing."
3447 (set-buffer gnus-article-buffer)
3448 (let ((cite (memq 'cite gnus-article-wash-types))
3449 (headers (memq 'headers gnus-article-wash-types))
3450 (boring (memq 'boring-headers gnus-article-wash-types))
3451 (pgp (memq 'pgp gnus-article-wash-types))
3452 (pem (memq 'pem gnus-article-wash-types))
3453 (signature (memq 'signature gnus-article-wash-types))
3454 (overstrike (memq 'overstrike gnus-article-wash-types))
3455 (emphasis (memq 'emphasis gnus-article-wash-types)))
3456 (format "%c%c%c%c%c%c"
3458 (if (or headers boring) ?h ? )
3459 (if (or pgp pem) ?p ? )
3460 (if signature ?s ? )
3461 (if overstrike ?o ? )
3462 (if emphasis ?e ? )))))
3464 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3466 (defun gnus-article-maybe-hide-headers ()
3467 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3468 Provided for backwards compatibility."
3469 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3470 (not (save-excursion (set-buffer gnus-summary-buffer)
3471 gnus-have-all-headers)))
3472 (not gnus-inhibit-hiding))
3473 (gnus-article-hide-headers)))
3477 (defun gnus-output-to-file (file-name)
3478 "Append the current article to a file named FILE-NAME."
3479 (let ((artbuf (current-buffer)))
3481 (insert-buffer-substring artbuf)
3482 ;; Append newline at end of the buffer as separator, and then
3484 (goto-char (point-max))
3486 (mm-append-to-file (point-min) (point-max) file-name)
3489 (defun gnus-narrow-to-page (&optional arg)
3490 "Narrow the article buffer to a page.
3491 If given a numerical ARG, move forward ARG pages."
3493 (setq arg (if arg (prefix-numeric-value arg) 0))
3495 (set-buffer gnus-article-buffer)
3496 (goto-char (point-min))
3498 ;; Remove any old next/prev buttons.
3499 (when (gnus-visual-p 'page-marker)
3500 (let ((buffer-read-only nil))
3501 (gnus-remove-text-with-property 'gnus-prev)
3502 (gnus-remove-text-with-property 'gnus-next)))
3505 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3507 (re-search-forward page-delimiter nil 'move arg)))
3508 (goto-char (match-end 0)))
3511 (if (re-search-forward page-delimiter nil 'move)
3514 (when (and (gnus-visual-p 'page-marker)
3515 (not (= (point-min) 1)))
3517 (goto-char (point-min))
3518 (gnus-insert-prev-page-button)))
3519 (when (and (gnus-visual-p 'page-marker)
3520 (< (+ (point-max) 2) (buffer-size)))
3522 (goto-char (point-max))
3523 (gnus-insert-next-page-button)))))
3525 ;; Article mode commands
3527 (defun gnus-article-goto-next-page ()
3528 "Show the next page of the article."
3530 (when (gnus-article-next-page)
3531 (goto-char (point-min))
3532 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3534 (defun gnus-article-goto-prev-page ()
3535 "Show the next page of the article."
3537 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3538 (gnus-article-prev-page nil)))
3540 (defun gnus-article-next-page (&optional lines)
3541 "Show the next page of the current article.
3542 If end of article, return non-nil. Otherwise return nil.
3543 Argument LINES specifies lines to be scrolled up."
3545 (move-to-window-line -1)
3548 (and (pos-visible-in-window-p) ;Not continuation line.
3550 ;; Nothing in this page.
3551 (if (or (not gnus-page-broken)
3554 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3556 (gnus-narrow-to-page 1) ;Go to next page.
3558 ;; More in this page.
3559 (let ((scroll-in-place nil))
3563 ;; Long lines may cause an end-of-buffer error.
3564 (goto-char (point-max)))))
3565 (move-to-window-line 0)
3568 (defun gnus-article-prev-page (&optional lines)
3569 "Show previous page of current article.
3570 Argument LINES specifies lines to be scrolled down."
3572 (move-to-window-line 0)
3573 (if (and gnus-page-broken
3575 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3577 (gnus-narrow-to-page -1) ;Go to previous page.
3578 (goto-char (point-max))
3580 (let ((scroll-in-place nil))
3584 (beginning-of-buffer
3585 (goto-char (point-min))))
3586 (move-to-window-line 0)))))
3588 (defun gnus-article-refer-article ()
3589 "Read article specified by message-id around point."
3591 (let ((point (point)))
3592 (search-forward ">" nil t) ;Move point to end of "<....>".
3593 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3594 (let ((message-id (match-string 1)))
3596 (set-buffer gnus-summary-buffer)
3597 (gnus-summary-refer-article message-id))
3599 (error "No references around point"))))
3601 (defun gnus-article-show-summary ()
3602 "Reconfigure windows to show summary buffer."
3604 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3605 (error "There is no summary buffer for this article buffer")
3606 (gnus-article-set-globals)
3607 (gnus-configure-windows 'article)
3608 (gnus-summary-goto-subject gnus-current-article)
3609 (gnus-summary-position-point)))
3611 (defun gnus-article-describe-briefly ()
3612 "Describe article mode commands briefly."
3614 (gnus-message 6 (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")))
3616 (defun gnus-article-summary-command ()
3617 "Execute the last keystroke in the summary buffer."
3619 (let ((obuf (current-buffer))
3620 (owin (current-window-configuration))
3622 (switch-to-buffer gnus-article-current-summary 'norecord)
3623 (setq func (lookup-key (current-local-map) (this-command-keys)))
3624 (call-interactively func)
3626 (set-window-configuration owin)
3627 (set-window-point (get-buffer-window (current-buffer)) (point))))
3629 (defun gnus-article-summary-command-nosave ()
3630 "Execute the last keystroke in the summary buffer."
3633 (pop-to-buffer gnus-article-current-summary 'norecord)
3634 (setq func (lookup-key (current-local-map) (this-command-keys)))
3635 (call-interactively func)))
3637 (defun gnus-article-check-buffer ()
3638 "Beep if not in an article buffer."
3639 (unless (equal major-mode 'gnus-article-mode)
3640 (error "Command invoked outside of a Gnus article buffer")))
3642 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3643 "Read a summary buffer key sequence and execute it from the article buffer."
3645 (gnus-article-check-buffer)
3647 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3648 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3649 "=" "^" "\M-^" "|"))
3655 '("n" "Gn" "p" "Gp"))
3658 (set-buffer gnus-article-current-summary)
3659 (let (gnus-pick-mode)
3660 (push (or key last-command-event) unread-command-events)
3661 (setq keys (if gnus-xemacs
3662 (events-to-keys (read-key-sequence nil))
3663 (read-key-sequence nil)))))
3667 (if (or (member keys nosaves)
3668 (member keys nosave-but-article)
3669 (member keys nosave-in-article))
3671 (save-window-excursion
3672 (pop-to-buffer gnus-article-current-summary 'norecord)
3673 ;; We disable the pick minor mode commands.
3674 (let (gnus-pick-mode)
3675 (setq func (lookup-key (current-local-map) keys))))
3679 (unless (member keys nosave-in-article)
3680 (set-buffer gnus-article-current-summary))
3681 (call-interactively func)
3682 (setq new-sum-point (point)))
3683 (when (member keys nosave-but-article)
3684 (pop-to-buffer gnus-article-buffer 'norecord)))
3685 ;; These commands should restore window configuration.
3686 (let ((obuf (current-buffer))
3687 (owin (current-window-configuration))
3689 (summary gnus-article-current-summary)
3690 func in-buffer selected)
3691 (if not-restore-window
3692 (pop-to-buffer summary 'norecord)
3693 (switch-to-buffer summary 'norecord))
3694 (setq in-buffer (current-buffer))
3695 ;; We disable the pick minor mode commands.
3696 (if (setq func (let (gnus-pick-mode)
3697 (lookup-key (current-local-map) keys)))
3699 (call-interactively func)
3700 (setq new-sum-point (point)))
3702 (when (eq in-buffer (current-buffer))
3703 (setq selected (gnus-summary-select-article))
3705 (unless not-restore-window
3706 (set-window-configuration owin))
3707 (when (eq selected 'old)
3709 (set-window-start (get-buffer-window (current-buffer))
3711 (set-window-point (get-buffer-window (current-buffer))
3713 (let ((win (get-buffer-window gnus-article-current-summary)))
3715 (set-window-point win new-sum-point))))))))
3717 (defun gnus-article-hide (&optional arg force)
3718 "Hide all the gruft in the current article.
3719 This means that PGP stuff, signatures, cited text and (some)
3720 headers will be hidden.
3721 If given a prefix, show the hidden text instead."
3722 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3723 (gnus-article-hide-headers arg)
3724 (gnus-article-hide-list-identifiers arg)
3725 (gnus-article-hide-pgp arg)
3726 (gnus-article-hide-citation-maybe arg force)
3727 (gnus-article-hide-signature arg))
3729 (defun gnus-article-maybe-highlight ()
3730 "Do some article highlighting if article highlighting is requested."
3731 (when (gnus-visual-p 'article-highlight 'highlight)
3732 (gnus-article-highlight-some)))
3734 (defun gnus-check-group-server ()
3735 ;; Make sure the connection to the server is alive.
3736 (unless (gnus-server-opened
3737 (gnus-find-method-for-group gnus-newsgroup-name))
3738 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3739 (gnus-request-group gnus-newsgroup-name t)))
3741 (defun gnus-request-article-this-buffer (article group)
3742 "Get an article and insert it into this buffer."
3743 (let (do-update-line sparse-header)
3747 (gnus-kill-all-overlays)
3748 (setq group (or group gnus-newsgroup-name))
3750 ;; Using `gnus-request-article' directly will insert the article into
3751 ;; `nntp-server-buffer' - so we'll save some time by not having to
3752 ;; copy it from the server buffer into the article buffer.
3754 ;; We only request an article by message-id when we do not have the
3755 ;; headers for it, so we'll have to get those.
3756 (when (stringp article)
3757 (gnus-read-header article))
3759 ;; If the article number is negative, that means that this article
3760 ;; doesn't belong in this newsgroup (possibly), so we find its
3761 ;; message-id and request it by id instead of number.
3762 (when (and (numberp article)
3764 (get-buffer gnus-summary-buffer)
3765 (gnus-buffer-exists-p gnus-summary-buffer))
3767 (set-buffer gnus-summary-buffer)
3768 (let ((header (gnus-summary-article-header article)))
3771 ((memq article gnus-newsgroup-sparse)
3772 ;; This is a sparse gap article.
3773 (setq do-update-line article)
3774 (setq article (mail-header-id header))
3775 (setq sparse-header (gnus-read-header article))
3776 (setq gnus-newsgroup-sparse
3777 (delq article gnus-newsgroup-sparse)))
3779 ;; It's a real article.
3780 (setq article (mail-header-id header)))
3782 ;; It is an extracted pseudo-article.
3783 (setq article 'pseudo)
3784 (gnus-request-pseudo-article header))))
3786 (let ((method (gnus-find-method-for-group
3787 gnus-newsgroup-name)))
3788 (when (and (eq (car method) 'nneething)
3791 (file-name-as-directory
3792 (or (cadr (assq 'nneething-address method))
3794 (mail-header-subject header))))
3795 (when (file-directory-p dir)
3796 (setq article 'nneething)
3797 (gnus-group-enter-directory dir))))))))
3800 ;; Refuse to select canceled articles.
3801 ((and (numberp article)
3803 (get-buffer gnus-summary-buffer)
3804 (gnus-buffer-exists-p gnus-summary-buffer)
3805 (eq (cdr (save-excursion
3806 (set-buffer gnus-summary-buffer)
3807 (assq article gnus-newsgroup-reads)))
3808 gnus-canceled-mark))
3810 ;; We first check `gnus-original-article-buffer'.
3811 ((and (get-buffer gnus-original-article-buffer)
3814 (set-buffer gnus-original-article-buffer)
3815 (and (equal (car gnus-original-article) group)
3816 (eq (cdr gnus-original-article) article))))
3817 (insert-buffer-substring gnus-original-article-buffer)
3819 ;; Check the backlog.
3820 ((and gnus-keep-backlog
3821 (gnus-backlog-request-article group article (current-buffer)))
3823 ;; Check asynchronous pre-fetch.
3824 ((gnus-async-request-fetched-article group article (current-buffer))
3825 (gnus-async-prefetch-next group article gnus-summary-buffer)
3826 (when (and (numberp article) gnus-keep-backlog)
3827 (gnus-backlog-enter-article group article (current-buffer)))
3830 ((and gnus-use-cache
3832 (gnus-cache-request-article article group))
3834 ;; Get the article and put into the article buffer.
3835 ((or (stringp article)
3837 (let ((gnus-override-method gnus-override-method)
3838 (methods (and (stringp article)
3839 gnus-refer-article-method))
3841 (buffer-read-only nil))
3846 (when (and (null gnus-override-method)
3848 (setq gnus-override-method (pop methods)))
3850 (when (eq gnus-override-method 'current)
3851 (setq gnus-override-method gnus-current-select-method))
3853 (gnus-kill-all-overlays)
3854 (let ((gnus-newsgroup-name group))
3855 (gnus-check-group-server))
3856 (when (gnus-request-article article group (current-buffer))
3857 (when (numberp article)
3858 (gnus-async-prefetch-next group article
3859 gnus-summary-buffer)
3860 (when gnus-keep-backlog
3861 (gnus-backlog-enter-article
3862 group article (current-buffer))))
3863 (setq result 'article))
3866 (setq gnus-override-method (pop methods))
3867 (setq result 'done))))
3868 (and (eq result 'article) 'article)))
3872 ;; Associate this article with the current summary buffer.
3873 (setq gnus-article-current-summary gnus-summary-buffer)
3875 ;; Take the article from the original article buffer
3876 ;; and place it in the buffer it's supposed to be in.
3877 (when (and (get-buffer gnus-article-buffer)
3878 (equal (buffer-name (current-buffer))
3879 (buffer-name (get-buffer gnus-article-buffer))))
3881 (if (get-buffer gnus-original-article-buffer)
3882 (set-buffer gnus-original-article-buffer)
3883 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3884 (buffer-disable-undo)
3885 (setq major-mode 'gnus-original-article-mode)
3886 (setq buffer-read-only t))
3887 (let (buffer-read-only)
3889 (insert-buffer-substring gnus-article-buffer))
3890 (setq gnus-original-article (cons group article)))
3893 (run-hooks 'gnus-article-decode-hook)
3894 ;; Mark article as decoded or not.
3895 (setq gnus-article-decoded-p gnus-article-decode-hook))
3897 ;; Update sparse articles.
3898 (when (and do-update-line
3899 (or (numberp article)
3901 (let ((buf (current-buffer)))
3902 (set-buffer gnus-summary-buffer)
3903 (gnus-summary-update-article do-update-line sparse-header)
3904 (gnus-summary-goto-subject do-update-line nil t)
3905 (set-window-point (get-buffer-window (current-buffer) t)
3907 (set-buffer buf))))))
3913 (defcustom gnus-article-edit-mode-hook nil
3914 "Hook run in article edit mode buffers."
3915 :group 'gnus-article-various
3918 (defvar gnus-article-edit-done-function nil)
3920 (defvar gnus-article-edit-mode-map nil)
3922 ;; Should we be using derived.el for this?
3923 (unless gnus-article-edit-mode-map
3924 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3925 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3927 (gnus-define-keys gnus-article-edit-mode-map
3928 "\C-c\C-c" gnus-article-edit-done
3929 "\C-c\C-k" gnus-article-edit-exit)
3931 (gnus-define-keys (gnus-article-edit-wash-map
3932 "\C-c\C-w" gnus-article-edit-mode-map)
3933 "f" gnus-article-edit-full-stops))
3935 (defun gnus-article-edit-mode ()
3936 "Major mode for editing articles.
3937 This is an extended text-mode.
3939 \\{gnus-article-edit-mode-map}"
3941 (setq major-mode 'gnus-article-edit-mode)
3942 (setq mode-name "Article Edit")
3943 (use-local-map gnus-article-edit-mode-map)
3944 (make-local-variable 'gnus-article-edit-done-function)
3945 (make-local-variable 'gnus-prev-winconf)
3946 (setq buffer-read-only nil)
3947 (buffer-enable-undo)
3949 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3951 (defun gnus-article-edit (&optional force)
3952 "Edit the current article.
3953 This will have permanent effect only in mail groups.
3954 If FORCE is non-nil, allow editing of articles even in read-only
3957 (when (and (not force)
3958 (gnus-group-read-only-p))
3959 (error "The current newsgroup does not support article editing"))
3960 (gnus-article-date-original)
3961 (gnus-article-edit-article
3963 `(lambda (no-highlight)
3965 (gnus-summary-edit-article-done
3966 ,(or (mail-header-references gnus-current-headers) "")
3967 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3969 (defun gnus-article-edit-article (start-func exit-func)
3970 "Start editing the contents of the current article buffer."
3971 (let ((winconf (current-window-configuration)))
3972 (set-buffer gnus-article-buffer)
3973 (gnus-article-edit-mode)
3974 (funcall start-func)
3975 (gnus-configure-windows 'edit-article)
3976 (setq gnus-article-edit-done-function exit-func)
3977 (setq gnus-prev-winconf winconf)
3978 (gnus-message 6 "C-c C-c to end edits")))
3980 (defun gnus-article-edit-done (&optional arg)
3981 "Update the article edits and exit."
3986 (when (article-goto-body)
3987 (let ((lines (count-lines (point) (point-max)))
3988 (length (- (point-max) (point)))
3989 (case-fold-search t)
3990 (body (copy-marker (point))))
3991 (goto-char (point-min))
3992 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3993 (delete-region (match-beginning 1) (match-end 1))
3994 (insert (number-to-string length)))
3995 (goto-char (point-min))
3996 (when (re-search-forward
3997 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3998 (delete-region (match-beginning 1) (match-end 1))
3999 (insert (number-to-string length)))
4000 (goto-char (point-min))
4001 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4002 (delete-region (match-beginning 1) (match-end 1))
4003 (insert (number-to-string lines)))))))
4004 (let ((func gnus-article-edit-done-function)
4005 (buf (current-buffer))
4006 (start (window-start)))
4007 (gnus-article-edit-exit)
4010 (let ((buffer-read-only nil))
4012 ;; The cache and backlog have to be flushed somewhat.
4013 (when gnus-keep-backlog
4014 (gnus-backlog-remove-article
4015 (car gnus-article-current) (cdr gnus-article-current)))
4016 ;; Flush original article as well.
4018 (when (get-buffer gnus-original-article-buffer)
4019 (set-buffer gnus-original-article-buffer)
4020 (setq gnus-original-article nil)))
4021 (when gnus-use-cache
4022 (gnus-cache-update-article
4023 (car gnus-article-current) (cdr gnus-article-current))))
4025 (set-window-start (get-buffer-window buf) start)
4026 (set-window-point (get-buffer-window buf) (point))))
4028 (defun gnus-article-edit-exit ()
4029 "Exit the article editing without updating."
4031 ;; We remove all text props from the article buffer.
4032 (let ((buf (format "%s" (buffer-string)))
4033 (curbuf (current-buffer))
4035 (window-start (window-start)))
4038 (let ((winconf gnus-prev-winconf))
4040 (set-window-configuration winconf)
4041 ;; Tippy-toe some to make sure that point remains where it was.
4042 (save-current-buffer
4044 (set-window-start (get-buffer-window (current-buffer)) window-start)
4047 (defun gnus-article-edit-full-stops ()
4048 "Interactively repair spacing at end of sentences."
4051 (goto-char (point-min))
4052 (search-forward-regexp "^$" nil t)
4053 (let ((case-fold-search nil))
4054 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4057 ;;; Article highlights
4060 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4062 ;;; Internal Variables:
4064 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(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\\)\\)"
4065 "Regular expression that matches URLs."
4066 :group 'gnus-article-buttons
4069 (defcustom gnus-button-alist
4070 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4071 0 t gnus-button-message-id 2)
4072 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4073 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4075 gnus-button-fetch-group 4)
4076 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4077 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4078 t gnus-button-message-id 3)
4079 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4080 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4081 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4082 ;; This is how URLs _should_ be embedded in text...
4083 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4085 (,gnus-button-url-regexp 0 t browse-url 0))
4086 "*Alist of regexps matching buttons in article bodies.
4088 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4089 REGEXP: is the string matching text around the button,
4090 BUTTON: is the number of the regexp grouping actually matching the button,
4091 FORM: is a lisp expression which must eval to true for the button to
4093 CALLBACK: is the function to call when the user push this button, and each
4094 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4096 CALLBACK can also be a variable, in that case the value of that
4097 variable it the real callback function."
4098 :group 'gnus-article-buttons
4099 :type '(repeat (list regexp
4100 (integer :tag "Button")
4102 (function :tag "Callback")
4105 (integer :tag "Regexp group")))))
4107 (defcustom gnus-header-button-alist
4108 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4109 0 t gnus-button-message-id 0)
4110 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4111 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4112 0 t gnus-button-mailto 0)
4113 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4114 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4115 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4116 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4117 gnus-button-message-id 3))
4118 "*Alist of headers and regexps to match buttons in article heads.
4120 This alist is very similar to `gnus-button-alist', except that each
4121 alist has an additional HEADER element first in each entry:
4123 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4125 HEADER is a regexp to match a header. For a fuller explanation, see
4126 `gnus-button-alist'."
4127 :group 'gnus-article-buttons
4128 :group 'gnus-article-headers
4129 :type '(repeat (list (regexp :tag "Header")
4131 (integer :tag "Button")
4133 (function :tag "Callback")
4136 (integer :tag "Regexp group")))))
4138 (defvar gnus-button-regexp nil)
4139 (defvar gnus-button-marker-list nil)
4140 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4142 (defvar gnus-button-last nil)
4143 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4147 (defun gnus-article-push-button (event)
4148 "Check text under the mouse pointer for a callback function.
4149 If the text under the mouse pointer has a `gnus-callback' property,
4150 call it with the value of the `gnus-data' text property."
4152 (set-buffer (window-buffer (posn-window (event-start event))))
4153 (let* ((pos (posn-point (event-start event)))
4154 (data (get-text-property pos 'gnus-data))
4155 (fun (get-text-property pos 'gnus-callback)))
4158 (funcall fun data))))
4160 (defun gnus-article-press-button ()
4161 "Check text at point for a callback function.
4162 If the text at point has a `gnus-callback' property,
4163 call it with the value of the `gnus-data' text property."
4165 (let* ((data (get-text-property (point) 'gnus-data))
4166 (fun (get-text-property (point) 'gnus-callback)))
4168 (funcall fun data))))
4170 (defun gnus-article-highlight (&optional force)
4171 "Highlight current article.
4172 This function calls `gnus-article-highlight-headers',
4173 `gnus-article-highlight-citation',
4174 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4175 do the highlighting. See the documentation for those functions."
4176 (interactive (list 'force))
4177 (gnus-article-highlight-headers)
4178 (gnus-article-highlight-citation force)
4179 (gnus-article-highlight-signature)
4180 (gnus-article-add-buttons force)
4181 (gnus-article-add-buttons-to-head))
4183 (defun gnus-article-highlight-some (&optional force)
4184 "Highlight current article.
4185 This function calls `gnus-article-highlight-headers',
4186 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4187 do the highlighting. See the documentation for those functions."
4188 (interactive (list 'force))
4189 (gnus-article-highlight-headers)
4190 (gnus-article-highlight-signature)
4191 (gnus-article-add-buttons))
4193 (defun gnus-article-highlight-headers ()
4194 "Highlight article headers as specified by `gnus-header-face-alist'."
4197 (set-buffer gnus-article-buffer)
4199 (let ((alist gnus-header-face-alist)
4200 (buffer-read-only nil)
4201 (case-fold-search t)
4202 (inhibit-point-motion-hooks t)
4203 entry regexp header-face field-face from hpoints fpoints)
4204 (article-narrow-to-head)
4205 (while (setq entry (pop alist))
4206 (goto-char (point-min))
4207 (setq regexp (concat "^\\("
4208 (if (string-equal "" (nth 0 entry))
4212 header-face (nth 1 entry)
4213 field-face (nth 2 entry))
4214 (while (and (re-search-forward regexp nil t)
4218 (unless (search-forward ":" nil t)
4220 (when (and header-face
4221 (not (memq (point) hpoints)))
4222 (push (point) hpoints)
4223 (gnus-put-text-property from (point) 'face header-face))
4224 (when (and field-face
4225 (not (memq (setq from (point)) fpoints)))
4227 (if (re-search-forward "^[^ \t]" nil t)
4229 (goto-char (point-max)))
4230 (gnus-put-text-property from (point) 'face field-face))))))))
4232 (defun gnus-article-highlight-signature ()
4233 "Highlight the signature in an article.
4234 It does this by highlighting everything after
4235 `gnus-signature-separator' using `gnus-signature-face'."
4238 (set-buffer gnus-article-buffer)
4239 (let ((buffer-read-only nil)
4240 (inhibit-point-motion-hooks t))
4242 (when (and gnus-signature-face
4243 (gnus-article-narrow-to-signature))
4244 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4245 'face gnus-signature-face)
4247 (gnus-article-search-signature)
4248 (let ((start (match-beginning 0))
4249 (end (set-marker (make-marker) (1+ (match-end 0)))))
4250 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4253 (defun gnus-button-in-region-p (b e prop)
4254 "Say whether PROP exists in the region."
4255 (text-property-not-all b e prop nil))
4257 (defun gnus-article-add-buttons (&optional force)
4258 "Find external references in the article and make buttons of them.
4259 \"External references\" are things like Message-IDs and URLs, as
4260 specified by `gnus-button-alist'."
4261 (interactive (list 'force))
4263 (set-buffer gnus-article-buffer)
4264 (let ((buffer-read-only nil)
4265 (inhibit-point-motion-hooks t)
4266 (case-fold-search t)
4267 (alist gnus-button-alist)
4269 ;; Remove all old markers.
4270 (let (marker entry new-list)
4271 (while (setq marker (pop gnus-button-marker-list))
4272 (if (or (< marker (point-min)) (>= marker (point-max)))
4273 (push marker new-list)
4275 (when (setq entry (gnus-button-entry))
4276 (put-text-property (match-beginning (nth 1 entry))
4277 (match-end (nth 1 entry))
4278 'gnus-callback nil))
4279 (set-marker marker nil)))
4280 (setq gnus-button-marker-list new-list))
4281 ;; We skip the headers.
4284 (while (setq entry (pop alist))
4285 (setq regexp (car entry))
4287 (while (re-search-forward regexp nil t)
4288 (let* ((start (and entry (match-beginning (nth 1 entry))))
4289 (end (and entry (match-end (nth 1 entry))))
4290 (from (match-beginning 0)))
4291 (when (and (or (eq t (nth 2 entry))
4292 (eval (nth 2 entry)))
4293 (not (gnus-button-in-region-p
4294 start end 'gnus-callback)))
4295 ;; That optional form returned non-nil, so we add the
4297 (gnus-article-add-button
4298 start end 'gnus-button-push
4299 (car (push (set-marker (make-marker) from)
4300 gnus-button-marker-list))))))))))
4302 ;; Add buttons to the head of an article.
4303 (defun gnus-article-add-buttons-to-head ()
4304 "Add buttons to the head of the article."
4307 (set-buffer gnus-article-buffer)
4309 (let ((buffer-read-only nil)
4310 (inhibit-point-motion-hooks t)
4311 (case-fold-search t)
4312 (alist gnus-header-button-alist)
4314 (article-narrow-to-head)
4316 ;; Each alist entry.
4317 (setq entry (car alist)
4319 (goto-char (point-min))
4320 (while (re-search-forward (car entry) nil t)
4321 ;; Each header matching the entry.
4322 (setq beg (match-beginning 0))
4323 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4324 (match-beginning 0))
4327 (while (re-search-forward (nth 1 entry) end t)
4328 ;; Each match within a header.
4329 (let* ((entry (cdr entry))
4330 (start (match-beginning (nth 1 entry)))
4331 (end (match-end (nth 1 entry)))
4332 (form (nth 2 entry)))
4333 (goto-char (match-end 0))
4335 (gnus-article-add-button
4336 start end (nth 3 entry)
4337 (buffer-substring (match-beginning (nth 4 entry))
4338 (match-end (nth 4 entry)))))))
4339 (goto-char end)))))))
4341 ;;; External functions:
4343 (defun gnus-article-add-button (from to fun &optional data)
4344 "Create a button between FROM and TO with callback FUN and data DATA."
4345 (when gnus-article-button-face
4346 (gnus-overlay-put (gnus-make-overlay from to)
4347 'face gnus-article-button-face))
4348 (gnus-add-text-properties
4350 (nconc (and gnus-article-mouse-face
4351 (list gnus-mouse-face-prop gnus-article-mouse-face))
4352 (list 'gnus-callback fun)
4353 (and data (list 'gnus-data data))))
4354 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4355 :button-keymap gnus-widget-button-keymap))
4357 ;;; Internal functions:
4359 (defun gnus-article-set-globals ()
4361 (set-buffer gnus-summary-buffer)
4362 (gnus-set-global-variables)))
4364 (defun gnus-signature-toggle (end)
4366 (set-buffer gnus-article-buffer)
4367 (let ((buffer-read-only nil)
4368 (inhibit-point-motion-hooks t))
4369 (if (get-text-property end 'invisible)
4370 (gnus-article-unhide-text end (point-max))
4371 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4373 (defun gnus-button-entry ()
4374 ;; Return the first entry in `gnus-button-alist' matching this place.
4375 (let ((alist gnus-button-alist)
4378 (setq entry (pop alist))
4379 (if (looking-at (car entry))
4384 (defun gnus-button-push (marker)
4385 ;; Push button starting at MARKER.
4388 (let* ((entry (gnus-button-entry))
4389 (inhibit-point-motion-hooks t)
4391 (args (mapcar (lambda (group)
4392 (let ((string (match-string group)))
4393 (gnus-set-text-properties
4394 0 (length string) nil string)
4401 (fboundp (symbol-value fun)))
4402 (apply (symbol-value fun) args))
4404 (gnus-message 1 "You must define `%S' to use this button"
4405 (cons fun args)))))))
4407 (defun gnus-button-message-id (message-id)
4410 (set-buffer gnus-summary-buffer)
4411 (gnus-summary-refer-article message-id)))
4413 (defun gnus-button-fetch-group (address)
4414 "Fetch GROUP specified by ADDRESS."
4415 (if (not (string-match "[:/]" address))
4416 ;; This is just a simple group url.
4417 (gnus-group-read-ephemeral-group address gnus-select-method)
4418 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4420 (error "Can't parse %s" address)
4421 (gnus-group-read-ephemeral-group
4422 (match-string 4 address)
4423 `(nntp ,(match-string 1 address)
4424 (nntp-address ,(match-string 1 address))
4425 (nntp-port-number ,(if (match-end 3)
4426 (match-string 3 address)
4429 (defun gnus-url-parse-query-string (query &optional downcase)
4430 (let (retval pairs cur key val)
4431 (setq pairs (split-string query "&"))
4433 (setq cur (car pairs)
4435 (if (not (string-match "=" cur))
4437 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4438 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4440 (setq key (downcase key)))
4441 (setq cur (assoc key retval))
4443 (setcdr cur (cons val (cdr cur)))
4444 (setq retval (cons (list key val) retval)))))
4447 (defun gnus-url-unhex (x)
4454 (defun gnus-url-unhex-string (str &optional allow-newlines)
4455 "Remove %XXX embedded spaces, etc in a url.
4456 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4457 decoding of carriage returns and line feeds in the string, which is normally
4458 forbidden in URL encoding."
4459 (setq str (or str ""))
4461 (case-fold-search t))
4462 (while (string-match "%[0-9a-f][0-9a-f]" str)
4463 (let* ((start (match-beginning 0))
4464 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4466 (gnus-url-unhex (elt str (+ start 2))))))
4468 tmp (substring str 0 start)
4471 (char-to-string code))
4472 ((or (= code ?\n) (= code ?\r))
4474 (t (char-to-string code))))
4475 str (substring str (match-end 0)))))
4476 (setq tmp (concat tmp str))
4479 (defun gnus-url-mailto (url)
4480 ;; Send mail to someone
4481 (when (string-match "mailto:/*\\(.*\\)" url)
4482 (setq url (substring url (match-beginning 1) nil)))
4483 (let (to args subject func)
4484 (if (string-match (regexp-quote "?") url)
4485 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4486 args (gnus-url-parse-query-string
4487 (substring url (match-end 0) nil) t))
4488 (setq to (gnus-url-unhex-string url)))
4489 (setq args (cons (list "to" to) args)
4490 subject (cdr-safe (assoc "subject" args)))
4493 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4496 (message-position-on-field (caar args)))
4497 (insert (mapconcat 'identity (cdar args) ", "))
4498 (setq args (cdr args)))
4501 (message-goto-subject))))
4503 (defun gnus-button-mailto (address)
4505 (set-buffer (gnus-copy-article-buffer))
4506 (message-reply address))
4508 (defun gnus-button-reply (address)
4509 ;; Reply to ADDRESS.
4510 (message-reply address))
4512 (defun gnus-button-embedded-url (address)
4514 (browse-url (gnus-strip-whitespace address)))
4516 ;;; Next/prev buttons in the article buffer.
4518 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4519 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4521 (defvar gnus-prev-page-map nil)
4522 (unless gnus-prev-page-map
4523 (setq gnus-prev-page-map (make-sparse-keymap))
4524 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4525 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4527 (defun gnus-insert-prev-page-button ()
4528 (let ((buffer-read-only nil))
4530 gnus-prev-page-line-format nil
4531 `(gnus-prev t local-map ,gnus-prev-page-map
4532 gnus-callback gnus-article-button-prev-page
4533 article-type annotation))))
4535 (defvar gnus-next-page-map nil)
4536 (unless gnus-next-page-map
4537 (setq gnus-next-page-map (make-keymap))
4538 (suppress-keymap gnus-prev-page-map)
4539 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4540 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4542 (defun gnus-button-next-page ()
4543 "Go to the next page."
4545 (let ((win (selected-window)))
4546 (select-window (get-buffer-window gnus-article-buffer t))
4547 (gnus-article-next-page)
4548 (select-window win)))
4550 (defun gnus-button-prev-page ()
4551 "Go to the prev page."
4553 (let ((win (selected-window)))
4554 (select-window (get-buffer-window gnus-article-buffer t))
4555 (gnus-article-prev-page)
4556 (select-window win)))
4558 (defun gnus-insert-next-page-button ()
4559 (let ((buffer-read-only nil))
4560 (gnus-eval-format gnus-next-page-line-format nil
4562 t local-map ,gnus-next-page-map
4563 gnus-callback gnus-article-button-next-page
4564 article-type annotation))))
4566 (defun gnus-article-button-next-page (arg)
4567 "Go to the next page."
4569 (let ((win (selected-window)))
4570 (select-window (get-buffer-window gnus-article-buffer t))
4571 (gnus-article-next-page)
4572 (select-window win)))
4574 (defun gnus-article-button-prev-page (arg)
4575 "Go to the prev page."
4577 (let ((win (selected-window)))
4578 (select-window (get-buffer-window gnus-article-buffer t))
4579 (gnus-article-prev-page)
4580 (select-window win)))
4582 (defvar gnus-decode-header-methods
4583 '(mail-decode-encoded-word-region)
4584 "List of methods used to decode headers.
4586 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4587 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4588 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4589 whose names match REGEXP.
4592 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4593 mail-decode-encoded-word-region
4594 (\"chinese\" . rfc1843-decode-region))
4597 (defvar gnus-decode-header-methods-cache nil)
4599 (defun gnus-multi-decode-header (start end)
4600 "Apply the functions from `gnus-encoded-word-methods' that match."
4601 (unless (and gnus-decode-header-methods-cache
4602 (eq gnus-newsgroup-name
4603 (car gnus-decode-header-methods-cache)))
4604 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4607 (nconc gnus-decode-header-methods-cache (list x))
4608 (if (and gnus-newsgroup-name
4609 (string-match (car x) gnus-newsgroup-name))
4610 (nconc gnus-decode-header-methods-cache
4612 gnus-decode-header-methods))
4613 (let ((xlist gnus-decode-header-methods-cache))
4616 (narrow-to-region start end)
4618 (funcall (pop xlist) (point-min) (point-max))))))
4621 ;;; Treatment top-level handling.
4624 (defun gnus-treat-article (condition &optional part-number total-parts type)
4625 (let ((length (- (point-max) (point-min)))
4626 (alist gnus-treatment-function-alist)
4627 (article-goto-body-goes-to-point-min-p t)
4631 (let ((list gnus-article-treat-types))
4633 (when (string-match (pop list) type)
4634 (throw 'found t)))))))
4635 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4637 (gnus-run-hooks 'gnus-part-display-hook)
4638 (while (setq elem (pop alist))
4641 (if (gnus-buffer-live-p gnus-summary-buffer)
4642 (set-buffer gnus-summary-buffer))
4643 (symbol-value (car elem))))
4644 (when (and (or (consp val)
4646 (gnus-treat-predicate val)
4647 (or (not (get (car elem) 'highlight))
4650 (funcall (cadr elem)))))))
4652 ;; Dynamic variables.
4653 (defvar part-number)
4654 (defvar total-parts)
4658 (defun gnus-treat-predicate (val)
4663 (stringp (car val)))
4664 (apply 'gnus-or (mapcar `(lambda (s)
4665 (string-match s ,(or gnus-newsgroup-name "")))
4668 (let ((pred (pop val)))
4671 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4673 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4675 (not (gnus-treat-predicate (car val))))
4677 (equal (car val) type))
4679 (error "%S is not a valid predicate" pred)))))
4687 (eq part-number total-parts))
4691 (error "%S is not a valid value" val))))
4697 (run-hooks 'gnus-art-load-hook)
4699 ;;; gnus-art.el ends here