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 ;; Fixme: This isn't the right thing for mixed graphical and and
202 ;; non-graphical frames in a session.
203 ;; gnus-xmas.el overrides this for XEmacs.
204 (defcustom gnus-article-x-face-command
205 (if (and (fboundp 'image-type-available-p)
206 (image-type-available-p 'xbm))
207 'gnus-article-display-xface
208 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -")
209 "*String or function to be executed to display an X-Face header.
210 If it is a string, the command will be executed in a sub-shell
211 asynchronously. The compressed face will be piped to this command."
212 :type '(choice string
213 (function-item gnus-article-display-xface)
215 :group 'gnus-article-washing)
217 (defcustom gnus-article-x-face-too-ugly nil
218 "Regexp matching posters whose face shouldn't be shown automatically."
219 :type '(choice regexp (const nil))
220 :group 'gnus-article-washing)
222 (defcustom gnus-article-banner-alist nil
223 "Banner alist for stripping.
225 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
226 :type '(repeat (cons symbol regexp))
227 :group 'gnus-article-washing)
229 (defcustom gnus-emphasis-alist
231 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
233 '(("_" "_" underline)
236 ("_/" "/_" underline-italic)
237 ("_\\*" "\\*_" underline-bold)
238 ("\\*/" "/\\*" bold-italic)
239 ("_\\*/" "/\\*_" underline-bold-italic))))
240 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
241 2 3 gnus-emphasis-underline)
245 (format format (car spec) (cadr spec))
246 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
248 "*Alist that says how to fontify certain phrases.
249 Each item looks like this:
251 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
253 The first element is a regular expression to be matched. The second
254 is a number that says what regular expression grouping used to find
255 the entire emphasized word. The third is a number that says what
256 regexp grouping should be displayed and highlighted. The fourth
257 is the face used for highlighting."
258 :type '(repeat (list :value ("" 0 0 default)
260 (integer :tag "Match group")
261 (integer :tag "Emphasize group")
263 :group 'gnus-article-emphasis)
265 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
266 "A regexp to describe whitespace which should not be emphasized.
267 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
268 The former avoids underlining of leading and trailing whitespace,
269 and the latter avoids underlining any whitespace at all."
270 :group 'gnus-article-emphasis
273 (defface gnus-emphasis-bold '((t (:bold t)))
274 "Face used for displaying strong emphasized text (*word*)."
275 :group 'gnus-article-emphasis)
277 (defface gnus-emphasis-italic '((t (:italic t)))
278 "Face used for displaying italic emphasized text (/word/)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-underline '((t (:underline t)))
282 "Face used for displaying underlined emphasized text (_word_)."
283 :group 'gnus-article-emphasis)
285 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
286 "Face used for displaying underlined bold emphasized text (_*word*_)."
287 :group 'gnus-article-emphasis)
289 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
290 "Face used for displaying underlined italic emphasized text (_/word/_)."
291 :group 'gnus-article-emphasis)
293 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
294 "Face used for displaying bold italic emphasized text (/*word*/)."
295 :group 'gnus-article-emphasis)
297 (defface gnus-emphasis-underline-bold-italic
298 '((t (:bold t :italic t :underline t)))
299 "Face used for displaying underlined bold italic emphasized text.
300 Esample: (_/*word*/_)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-highlight-words
304 '((t (:background "black" :foreground "yellow")))
305 "Face used for displaying highlighted words."
306 :group 'gnus-article-emphasis)
308 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
309 "Format for display of Date headers in article bodies.
310 See `format-time-string' for the possible values.
312 The variable can also be function, which should return a complete Date
313 header. The function is called with one argument, the time, which can
314 be fed to `format-time-string'."
315 :type '(choice string symbol)
316 :link '(custom-manual "(gnus)Article Date")
317 :group 'gnus-article-washing)
320 (autoload 'mail-extract-address-components "mail-extr"))
322 (defcustom gnus-save-all-headers t
323 "*If non-nil, don't remove any headers before saving."
324 :group 'gnus-article-saving
327 (defcustom gnus-prompt-before-saving 'always
328 "*This variable says how much prompting is to be done when saving articles.
329 If it is nil, no prompting will be done, and the articles will be
330 saved to the default files. If this variable is `always', each and
331 every article that is saved will be preceded by a prompt, even when
332 saving large batches of articles. If this variable is neither nil not
333 `always', there the user will be prompted once for a file name for
334 each invocation of the saving commands."
335 :group 'gnus-article-saving
336 :type '(choice (item always)
337 (item :tag "never" nil)
338 (sexp :tag "once" :format "%t\n" :value t)))
340 (defcustom gnus-saved-headers gnus-visible-headers
341 "Headers to keep if `gnus-save-all-headers' is nil.
342 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
343 If that variable is nil, however, all headers that match this regexp
344 will be kept while the rest will be deleted before saving."
345 :group 'gnus-article-saving
348 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
349 "A function to save articles in your favourite format.
350 The function must be interactively callable (in other words, it must
351 be an Emacs command).
353 Gnus provides the following functions:
355 * gnus-summary-save-in-rmail (Rmail format)
356 * gnus-summary-save-in-mail (Unix mail format)
357 * gnus-summary-save-in-folder (MH folder)
358 * gnus-summary-save-in-file (article format)
359 * gnus-summary-save-in-vm (use VM's folder format)
360 * gnus-summary-write-to-file (article format -- overwrite)."
361 :group 'gnus-article-saving
362 :type '(radio (function-item gnus-summary-save-in-rmail)
363 (function-item gnus-summary-save-in-mail)
364 (function-item gnus-summary-save-in-folder)
365 (function-item gnus-summary-save-in-file)
366 (function-item gnus-summary-save-in-vm)
367 (function-item gnus-summary-write-to-file)))
369 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
370 "A function generating a file name to save articles in Rmail format.
371 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
372 :group 'gnus-article-saving
375 (defcustom gnus-mail-save-name 'gnus-plain-save-name
376 "A function generating a file name to save articles in Unix mail format.
377 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
378 :group 'gnus-article-saving
381 (defcustom gnus-folder-save-name 'gnus-folder-save-name
382 "A function generating a file name to save articles in MH folder.
383 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
384 :group 'gnus-article-saving
387 (defcustom gnus-file-save-name 'gnus-numeric-save-name
388 "A function generating a file name to save articles in article format.
389 The function is called with NEWSGROUP, HEADERS, and optional
391 :group 'gnus-article-saving
394 (defcustom gnus-split-methods
395 '((gnus-article-archive-name)
396 (gnus-article-nndoc-name))
397 "*Variable used to suggest where articles are to be saved.
398 For instance, if you would like to save articles related to Gnus in
399 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
400 you could set this variable to something like:
402 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
403 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
405 This variable is an alist where the where the key is the match and the
406 value is a list of possible files to save in if the match is non-nil.
408 If the match is a string, it is used as a regexp match on the
409 article. If the match is a symbol, that symbol will be funcalled
410 from the buffer of the article to be saved with the newsgroup as the
411 parameter. If it is a list, it will be evaled in the same buffer.
413 If this form or function returns a string, this string will be used as
414 a possible file name; and if it returns a non-nil list, that list will
415 be used as possible file names."
416 :group 'gnus-article-saving
417 :type '(repeat (choice (list :value (fun) function)
418 (cons :value ("" "") regexp (repeat string))
421 (defcustom gnus-page-delimiter "^\^L"
422 "*Regexp describing what to use as article page delimiters.
423 The default value is \"^\^L\", which is a form linefeed at the
424 beginning of a line."
426 :group 'gnus-article-various)
428 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
429 "*The format specification for the article mode line.
430 See `gnus-summary-mode-line-format' for a closer description.
432 The following additional specs are available:
434 %w The article washing status.
435 %m The number of MIME parts in the article."
437 :group 'gnus-article-various)
439 (defcustom gnus-article-mode-hook nil
440 "*A hook for Gnus article mode."
442 :group 'gnus-article-various)
444 (defcustom gnus-article-menu-hook nil
445 "*Hook run after the creation of the article mode menu."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-prepare-hook nil
450 "*A hook called after an article has been prepared in the article buffer."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-hide-pgp-hook nil
455 "*A hook called after successfully hiding a PGP signature."
457 :group 'gnus-article-various)
459 (defcustom gnus-article-button-face 'bold
460 "Face used for highlighting buttons in the article buffer.
462 An article button is a piece of text that you can activate by pressing
463 `RET' or `mouse-2' above it."
465 :group 'gnus-article-buttons)
467 (defcustom gnus-article-mouse-face 'highlight
468 "Face used for mouse highlighting in the article buffer.
470 Article buttons will be displayed in this face when the cursor is
473 :group 'gnus-article-buttons)
475 (defcustom gnus-signature-face 'gnus-signature-face
476 "Face used for highlighting a signature in the article buffer.
477 Obsolete; use the face `gnus-signature-face' for customizations instead."
479 :group 'gnus-article-highlight
480 :group 'gnus-article-signature)
482 (defface gnus-signature-face
485 "Face used for highlighting a signature in the article buffer."
486 :group 'gnus-article-highlight
487 :group 'gnus-article-signature)
489 (defface gnus-header-from-face
492 (:foreground "spring green"))
495 (:foreground "red3"))
498 "Face used for displaying from headers."
499 :group 'gnus-article-headers
500 :group 'gnus-article-highlight)
502 (defface gnus-header-subject-face
505 (:foreground "SeaGreen3"))
508 (:foreground "red4"))
510 (:bold t :italic t)))
511 "Face used for displaying subject headers."
512 :group 'gnus-article-headers
513 :group 'gnus-article-highlight)
515 (defface gnus-header-newsgroups-face
518 (:foreground "yellow" :italic t))
521 (:foreground "MidnightBlue" :italic t))
524 "Face used for displaying newsgroups headers."
525 :group 'gnus-article-headers
526 :group 'gnus-article-highlight)
528 (defface gnus-header-name-face
531 (:foreground "SeaGreen"))
534 (:foreground "maroon"))
537 "Face used for displaying header names."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight)
541 (defface gnus-header-content-face
544 (:foreground "forest green" :italic t))
547 (:foreground "indianred4" :italic t))
549 (:italic t))) "Face used for displaying header content."
550 :group 'gnus-article-headers
551 :group 'gnus-article-highlight)
553 (defcustom gnus-header-face-alist
554 '(("From" nil gnus-header-from-face)
555 ("Subject" nil gnus-header-subject-face)
556 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
557 ("" gnus-header-name-face gnus-header-content-face))
558 "*Controls highlighting of article header.
560 An alist of the form (HEADER NAME CONTENT).
562 HEADER is a regular expression which should match the name of an
563 header header and NAME and CONTENT are either face names or nil.
565 The name of each header field will be displayed using the face
566 specified by the first element in the list where HEADER match the
567 header name and NAME is non-nil. Similarly, the content will be
568 displayed by the first non-nil matching CONTENT face."
569 :group 'gnus-article-headers
570 :group 'gnus-article-highlight
571 :type '(repeat (list (regexp :tag "Header")
573 (item :tag "skip" nil)
574 (face :value default))
575 (choice :tag "Content"
576 (item :tag "skip" nil)
577 (face :value default)))))
579 (defcustom gnus-article-decode-hook
580 '(article-decode-charset article-decode-encoded-words)
581 "*Hook run to decode charsets in articles."
582 :group 'gnus-article-headers
585 (defcustom gnus-display-mime-function 'gnus-display-mime
586 "Function to display MIME articles."
587 :group 'gnus-article-mime
590 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
591 "Function used to decode headers.")
593 (defvar gnus-article-dumbquotes-map
611 "Table for MS-to-Latin1 translation.")
613 (defcustom gnus-ignored-mime-types nil
614 "List of MIME types that should be ignored by Gnus."
615 :group 'gnus-article-mime
616 :type '(repeat regexp))
618 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
619 "List of MIME types that should not be given buttons when rendered inline."
620 :group 'gnus-article-mime
621 :type '(repeat regexp))
623 (defcustom gnus-article-mime-part-function nil
624 "Function called with a MIME handle as the argument.
625 This is meant for people who want to do something automatic based
626 on parts -- for instance, adding Vcard info to a database."
627 :group 'gnus-article-mime
630 (defcustom gnus-mime-multipart-functions nil
631 "An alist of MIME types to functions to display them.")
633 (defcustom gnus-article-date-lapsed-new-header nil
634 "Whether the X-Sent and Date headers can coexist.
635 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
636 either replace the old \"Date:\" header (if this variable is nil), or
637 be added below it (otherwise)."
638 :group 'gnus-article-headers
641 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
642 "Function called with a MIME handle as the argument.
643 This is meant for people who want to view first matched part.
644 For `undisplayed-alternative' (default), the first undisplayed
645 part or alternative part is used. For `undisplayed', the first
646 undisplayed part is used. For a function, the first part which
647 the function return `t' is used. For `nil', the first part is
649 :group 'gnus-article-mime
651 (item :tag "first" :value nil)
652 (item :tag "undisplayed" :value undisplayed)
653 (item :tag "undisplayed or alternative"
654 :value undisplayed-alternative)
658 ;;; The treatment variables
661 (defvar gnus-part-display-hook nil
662 "Hook called on parts that are to receive treatment.")
664 (defvar gnus-article-treat-custom
665 '(choice (const :tag "Off" nil)
667 (const :tag "Header" head)
668 (const :tag "Last" last)
669 (integer :tag "Less")
670 (repeat :tag "Groups" regexp)
671 (sexp :tag "Predicate")))
673 (defvar gnus-article-treat-head-custom
674 '(choice (const :tag "Off" nil)
675 (const :tag "Header" head)))
677 (defvar gnus-article-treat-types '("text/plain")
680 (defvar gnus-inhibit-treatment nil
681 "Whether to inhibit treatment.")
683 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
684 "Highlight the signature.
685 Valid values are nil, t, `head', `last', an integer or a predicate.
686 See the manual for details."
687 :group 'gnus-article-treat
688 :type gnus-article-treat-custom)
689 (put 'gnus-treat-highlight-signature 'highlight t)
691 (defcustom gnus-treat-buttonize 100000
693 Valid values are nil, t, `head', `last', an integer or a predicate.
694 See the manual for details."
695 :group 'gnus-article-treat
696 :type gnus-article-treat-custom)
697 (put 'gnus-treat-buttonize 'highlight t)
699 (defcustom gnus-treat-buttonize-head 'head
700 "Add buttons to the head.
701 Valid values are nil, t, `head', `last', an integer or a predicate.
702 See the manual for details."
703 :group 'gnus-article-treat
704 :type gnus-article-treat-head-custom)
705 (put 'gnus-treat-buttonize-head 'highlight t)
707 (defcustom gnus-treat-emphasize 50000
709 Valid values are nil, t, `head', `last', an integer or a predicate.
710 See the manual for details."
711 :group 'gnus-article-treat
712 :type gnus-article-treat-custom)
713 (put 'gnus-treat-emphasize 'highlight t)
715 (defcustom gnus-treat-strip-cr nil
716 "Remove carriage returns.
717 Valid values are nil, t, `head', `last', an integer or a predicate.
718 See the manual for details."
719 :group 'gnus-article-treat
720 :type gnus-article-treat-custom)
722 (defcustom gnus-treat-hide-headers 'head
724 Valid values are nil, t, `head', `last', an integer or a predicate.
725 See the manual for details."
726 :group 'gnus-article-treat
727 :type gnus-article-treat-head-custom)
729 (defcustom gnus-treat-hide-boring-headers nil
730 "Hide boring headers.
731 Valid values are nil, t, `head', `last', an integer or a predicate.
732 See the manual for details."
733 :group 'gnus-article-treat
734 :type gnus-article-treat-head-custom)
736 (defcustom gnus-treat-hide-signature nil
738 Valid values are nil, t, `head', `last', an integer or a predicate.
739 See the manual for details."
740 :group 'gnus-article-treat
741 :type gnus-article-treat-custom)
743 (defcustom gnus-treat-fill-article nil
745 Valid values are nil, t, `head', `last', an integer or a predicate.
746 See the manual for details."
747 :group 'gnus-article-treat
748 :type gnus-article-treat-custom)
750 (defcustom gnus-treat-hide-citation nil
752 Valid values are nil, t, `head', `last', an integer or a predicate.
753 See the manual for details."
754 :group 'gnus-article-treat
755 :type gnus-article-treat-custom)
757 (defcustom gnus-treat-strip-list-identifiers 'head
758 "Strip list identifiers from `gnus-list-identifiers`.
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-custom)
764 (defcustom gnus-treat-strip-pgp t
765 "Strip PGP signatures.
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-custom)
771 (defcustom gnus-treat-strip-pem nil
772 "Strip PEM signatures.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-custom)
778 (defcustom gnus-treat-strip-banner t
779 "Strip banners from articles.
780 The banner to be stripped is specified in the `banner' group parameter.
781 Valid values are nil, t, `head', `last', an integer or a predicate.
782 See the manual for details."
783 :group 'gnus-article-treat
784 :type gnus-article-treat-custom)
786 (defcustom gnus-treat-highlight-headers 'head
787 "Highlight the headers.
788 Valid values are nil, t, `head', `last', an integer or a predicate.
789 See the manual for details."
790 :group 'gnus-article-treat
791 :type gnus-article-treat-head-custom)
792 (put 'gnus-treat-highlight-headers 'highlight t)
794 (defcustom gnus-treat-highlight-citation t
795 "Highlight cited text.
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-custom)
800 (put 'gnus-treat-highlight-citation 'highlight t)
802 (defcustom gnus-treat-date-ut nil
803 "Display the Date in UT (GMT).
804 Valid values are nil, t, `head', `last', an integer or a predicate.
805 See the manual for details."
806 :group 'gnus-article-treat
807 :type gnus-article-treat-head-custom)
809 (defcustom gnus-treat-date-local nil
810 "Display the Date in the local timezone.
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-head-custom)
816 (defcustom gnus-treat-date-lapsed nil
817 "Display the Date header in a way that says how much time has elapsed.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-head-custom)
823 (defcustom gnus-treat-date-original nil
824 "Display the date in the original timezone.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-head-custom)
830 (defcustom gnus-treat-date-iso8601 nil
831 "Display the date in the ISO8601 format.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-head-custom)
837 (defcustom gnus-treat-date-user-defined nil
838 "Display the date in a user-defined format.
839 The format is defined by the `gnus-article-time-format' variable.
840 Valid values are nil, t, `head', `last', an integer or a predicate.
841 See the manual for details."
842 :group 'gnus-article-treat
843 :type gnus-article-treat-head-custom)
845 (defcustom gnus-treat-strip-headers-in-body t
846 "Strip the X-No-Archive header line from the beginning of the body.
847 Valid values are nil, t, `head', `last', an integer or a predicate.
848 See the manual for details."
849 :group 'gnus-article-treat
850 :type gnus-article-treat-custom)
852 (defcustom gnus-treat-strip-trailing-blank-lines nil
853 "Strip trailing blank lines.
854 Valid values are nil, t, `head', `last', an integer or a predicate.
855 See the manual for details."
856 :group 'gnus-article-treat
857 :type gnus-article-treat-custom)
859 (defcustom gnus-treat-strip-leading-blank-lines nil
860 "Strip leading blank lines.
861 Valid values are nil, t, `head', `last', an integer or a predicate.
862 See the manual for details."
863 :group 'gnus-article-treat
864 :type gnus-article-treat-custom)
866 (defcustom gnus-treat-strip-multiple-blank-lines nil
867 "Strip multiple blank lines.
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-custom)
873 (defcustom gnus-treat-overstrike t
874 "Treat overstrike highlighting.
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-custom)
879 (put 'gnus-treat-overstrike 'highlight t)
881 (defcustom gnus-treat-display-xface
882 (and (or (and (fboundp 'image-type-available-p)
883 (image-type-available-p 'xbm))
884 (and gnus-xemacs (featurep 'xface)))
886 "Display X-Face headers.
887 Valid values are nil, t, `head', `last', an integer or a predicate.
888 See the manual for details."
889 :group 'gnus-article-treat
890 :type gnus-article-treat-head-custom)
891 (put 'gnus-treat-display-xface 'highlight t)
893 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
897 Valid values are nil, t, `head', `last', an integer or a predicate.
898 See the manual for details."
899 :group 'gnus-article-treat
900 :type gnus-article-treat-custom)
901 (put 'gnus-treat-display-smileys 'highlight t)
903 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See the manual for details."
907 :group 'gnus-article-treat
908 :type gnus-article-treat-head-custom)
909 (put 'gnus-treat-display-picons 'highlight t)
911 (defcustom gnus-treat-capitalize-sentences nil
912 "Capitalize sentence-starting words.
913 Valid values are nil, t, `head', `last', an integer or a predicate.
914 See the manual for details."
915 :group 'gnus-article-treat
916 :type gnus-article-treat-custom)
918 (defcustom gnus-treat-fill-long-lines nil
920 Valid values are nil, t, `head', `last', an integer or a predicate.
921 See the manual for details."
922 :group 'gnus-article-treat
923 :type gnus-article-treat-custom)
925 (defcustom gnus-treat-play-sounds nil
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See the manual for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-custom)
932 (defcustom gnus-treat-translate nil
933 "Translate articles from one language to another.
934 Valid values are nil, t, `head', `last', an integer or a predicate.
935 See the manual for details."
936 :group 'gnus-article-treat
937 :type gnus-article-treat-custom)
939 ;;; Internal variables
941 (defvar article-goto-body-goes-to-point-min-p nil)
942 (defvar gnus-article-wash-types nil)
943 (defvar gnus-article-emphasis-alist nil)
945 (defvar gnus-article-mime-handle-alist-1 nil)
946 (defvar gnus-treatment-function-alist
947 '((gnus-treat-strip-banner gnus-article-strip-banner)
948 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
949 (gnus-treat-highlight-signature gnus-article-highlight-signature)
950 (gnus-treat-buttonize gnus-article-add-buttons)
951 (gnus-treat-fill-article gnus-article-fill-cited-article)
952 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
953 (gnus-treat-strip-cr gnus-article-remove-cr)
954 (gnus-treat-emphasize gnus-article-emphasize)
955 (gnus-treat-display-xface gnus-article-display-x-face)
956 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
957 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
958 (gnus-treat-hide-signature gnus-article-hide-signature)
959 (gnus-treat-hide-citation gnus-article-hide-citation)
960 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
961 (gnus-treat-strip-pgp gnus-article-hide-pgp)
962 (gnus-treat-strip-pem gnus-article-hide-pem)
963 (gnus-treat-highlight-headers gnus-article-highlight-headers)
964 (gnus-treat-highlight-citation gnus-article-highlight-citation)
965 (gnus-treat-highlight-signature gnus-article-highlight-signature)
966 (gnus-treat-date-ut gnus-article-date-ut)
967 (gnus-treat-date-local gnus-article-date-local)
968 (gnus-treat-date-lapsed gnus-article-date-lapsed)
969 (gnus-treat-date-original gnus-article-date-original)
970 (gnus-treat-date-user-defined gnus-article-date-user)
971 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
972 (gnus-treat-strip-trailing-blank-lines
973 gnus-article-remove-trailing-blank-lines)
974 (gnus-treat-strip-leading-blank-lines
975 gnus-article-strip-leading-blank-lines)
976 (gnus-treat-strip-multiple-blank-lines
977 gnus-article-strip-multiple-blank-lines)
978 (gnus-treat-overstrike gnus-article-treat-overstrike)
979 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
980 (gnus-treat-display-smileys gnus-smiley-display)
981 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
982 (gnus-treat-display-picons gnus-article-display-picons)
983 (gnus-treat-play-sounds gnus-earcon-display)))
985 (defvar gnus-article-mime-handle-alist nil)
986 (defvar article-lapsed-timer nil)
987 (defvar gnus-article-current-summary nil)
989 (defvar gnus-article-mode-syntax-table
990 (let ((table (copy-syntax-table text-mode-syntax-table)))
991 (modify-syntax-entry ?- "w" table)
992 (modify-syntax-entry ?> ")" table)
993 (modify-syntax-entry ?< "(" table)
995 "Syntax table used in article mode buffers.
996 Initialized from `text-mode-syntax-table.")
998 (defvar gnus-save-article-buffer nil)
1000 (defvar gnus-article-mode-line-format-alist
1001 (nconc '((?w (gnus-article-wash-status) ?s)
1002 (?m (gnus-article-mime-part-status) ?s))
1003 gnus-summary-mode-line-format-alist))
1005 (defvar gnus-number-of-articles-to-be-saved nil)
1007 (defvar gnus-inhibit-hiding nil)
1009 (defsubst gnus-article-hide-text (b e props)
1010 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1011 (add-text-properties b e props)
1012 (when (memq 'intangible props)
1014 (max (1- b) (point-min))
1015 b 'intangible (cddr (memq 'intangible props)))))
1016 (defsubst gnus-article-unhide-text (b e)
1017 "Remove hidden text properties from region between B and E."
1018 (remove-text-properties b e gnus-hidden-properties)
1019 (when (memq 'intangible gnus-hidden-properties)
1020 (put-text-property (max (1- b) (point-min))
1021 b 'intangible nil)))
1023 (defun gnus-article-hide-text-type (b e type)
1024 "Hide text of TYPE between B and E."
1025 (push type gnus-article-wash-types)
1026 (gnus-article-hide-text
1027 b e (cons 'article-type (cons type gnus-hidden-properties))))
1029 (defun gnus-article-unhide-text-type (b e type)
1030 "Unhide text of TYPE between B and E."
1031 (setq gnus-article-wash-types
1032 (delq type gnus-article-wash-types))
1033 (remove-text-properties
1034 b e (cons 'article-type (cons type gnus-hidden-properties)))
1035 (when (memq 'intangible gnus-hidden-properties)
1036 (put-text-property (max (1- b) (point-min))
1037 b 'intangible nil)))
1039 (defun gnus-article-hide-text-of-type (type)
1040 "Hide text of TYPE in the current buffer."
1042 (let ((b (point-min))
1044 (while (setq b (text-property-any b e 'article-type type))
1045 (add-text-properties b (incf b) gnus-hidden-properties)))))
1047 (defun gnus-article-delete-text-of-type (type)
1048 "Delete text of TYPE in the current buffer."
1050 (let ((b (point-min)))
1051 (while (setq b (text-property-any b (point-max) 'article-type type))
1053 b (or (text-property-not-all b (point-max) 'article-type type)
1056 (defun gnus-article-delete-invisible-text ()
1057 "Delete all invisible text in the current buffer."
1059 (let ((b (point-min)))
1060 (while (setq b (text-property-any b (point-max) 'invisible t))
1062 b (or (text-property-not-all b (point-max) 'invisible t)
1065 (defun gnus-article-text-type-exists-p (type)
1066 "Say whether any text of type TYPE exists in the buffer."
1067 (text-property-any (point-min) (point-max) 'article-type type))
1069 (defsubst gnus-article-header-rank ()
1070 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1071 (let ((list gnus-sorted-header-list)
1074 (when (looking-at (car list))
1076 (setq list (cdr list))
1080 (defun article-hide-headers (&optional arg delete)
1081 "Hide unwanted headers and possibly sort them as well."
1083 ;; This function might be inhibited.
1084 (unless gnus-inhibit-hiding
1087 (let ((buffer-read-only nil)
1088 (case-fold-search t)
1089 (max (1+ (length gnus-sorted-header-list)))
1090 (ignored (when (not gnus-visible-headers)
1091 (cond ((stringp gnus-ignored-headers)
1092 gnus-ignored-headers)
1093 ((listp gnus-ignored-headers)
1094 (mapconcat 'identity gnus-ignored-headers
1097 (cond ((stringp gnus-visible-headers)
1098 gnus-visible-headers)
1099 ((and gnus-visible-headers
1100 (listp gnus-visible-headers))
1101 (mapconcat 'identity gnus-visible-headers "\\|"))))
1102 (inhibit-point-motion-hooks t)
1104 ;; First we narrow to just the headers.
1105 (article-narrow-to-head)
1106 ;; Hide any "From " lines at the beginning of (mail) articles.
1107 (while (looking-at "From ")
1110 (delete-region (point-min) (point)))
1111 ;; Then treat the rest of the header lines.
1112 ;; Then we use the two regular expressions
1113 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1114 ;; select which header lines is to remain visible in the
1116 (while (re-search-forward "^[^ \t]*:" nil t)
1118 ;; Mark the rank of the header.
1120 (point) (1+ (point)) 'message-rank
1121 (if (or (and visible (looking-at visible))
1123 (not (looking-at ignored))))
1124 (gnus-article-header-rank)
1127 (message-sort-headers-1)
1128 (when (setq beg (text-property-any
1129 (point-min) (point-max) 'message-rank (+ 2 max)))
1130 ;; We delete the unwanted headers.
1131 (push 'headers gnus-article-wash-types)
1132 (add-text-properties (point-min) (+ 5 (point-min))
1133 '(article-type headers dummy-invisible t))
1134 (delete-region beg (point-max))))))))
1136 (defun article-hide-boring-headers (&optional arg)
1137 "Toggle hiding of headers that aren't very interesting.
1138 If given a negative prefix, always show; if given a positive prefix,
1140 (interactive (gnus-article-hidden-arg))
1141 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1142 (not gnus-show-all-headers))
1145 (let ((buffer-read-only nil)
1146 (list gnus-boring-article-headers)
1147 (inhibit-point-motion-hooks t)
1149 (article-narrow-to-head)
1151 (setq elem (pop list))
1152 (goto-char (point-min))
1154 ;; Hide empty headers.
1156 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1158 (gnus-article-hide-text-type
1159 (progn (beginning-of-line) (point))
1162 (if (re-search-forward "^[^ \t]" nil t)
1166 ;; Hide boring Newsgroups header.
1167 ((eq elem 'newsgroups)
1168 (when (equal (gnus-fetch-field "newsgroups")
1169 (gnus-group-real-name
1170 (if (boundp 'gnus-newsgroup-name)
1173 (gnus-article-hide-header "newsgroups")))
1174 ((eq elem 'followup-to)
1175 (when (equal (message-fetch-field "followup-to")
1176 (message-fetch-field "newsgroups"))
1177 (gnus-article-hide-header "followup-to")))
1178 ((eq elem 'reply-to)
1179 (let ((from (message-fetch-field "from"))
1180 (reply-to (message-fetch-field "reply-to")))
1185 (nth 1 (mail-extract-address-components from))
1186 (nth 1 (mail-extract-address-components reply-to)))))
1187 (gnus-article-hide-header "reply-to"))))
1189 (let ((date (message-fetch-field "date")))
1191 (< (days-between (current-time-string) date)
1193 (gnus-article-hide-header "date"))))
1195 (let ((to (message-fetch-field "to"))
1196 (cc (message-fetch-field "cc")))
1197 (when (> (length to) 1024)
1198 (gnus-article-hide-header "to"))
1199 (when (> (length cc) 1024)
1200 (gnus-article-hide-header "cc"))))
1204 (goto-char (point-min))
1205 (while (re-search-forward "^to:" nil t)
1206 (setq to-count (1+ to-count)))
1207 (when (> to-count 1)
1208 (while (> to-count 0)
1209 (goto-char (point-min))
1211 (re-search-forward "^to:" nil nil to-count)
1213 (narrow-to-region (point) (point-max))
1214 (gnus-article-hide-header "to"))
1215 (setq to-count (1- to-count))))
1216 (goto-char (point-min))
1217 (while (re-search-forward "^cc:" nil t)
1218 (setq cc-count (1+ cc-count)))
1219 (when (> cc-count 1)
1220 (while (> cc-count 0)
1221 (goto-char (point-min))
1223 (re-search-forward "^cc:" nil nil cc-count)
1225 (narrow-to-region (point) (point-max))
1226 (gnus-article-hide-header "cc"))
1227 (setq cc-count (1- cc-count)))))))))))))
1229 (defun gnus-article-hide-header (header)
1231 (goto-char (point-min))
1232 (when (re-search-forward (concat "^" header ":") nil t)
1233 (gnus-article-hide-text-type
1234 (progn (beginning-of-line) (point))
1237 (if (re-search-forward "^[^ \t]" nil t)
1242 (defvar gnus-article-normalized-header-length 40
1243 "Length of normalized headers.")
1245 (defun article-normalize-headers ()
1246 "Make all header lines 40 characters long."
1248 (let ((buffer-read-only nil)
1252 (article-narrow-to-head)
1255 ((< (setq column (- (gnus-point-at-eol) (point)))
1256 gnus-article-normalized-header-length)
1258 (insert (make-string
1259 (- gnus-article-normalized-header-length column)
1261 ((> column gnus-article-normalized-header-length)
1262 (gnus-put-text-property
1264 (forward-char gnus-article-normalized-header-length)
1271 (forward-line 1))))))
1273 (defun article-treat-dumbquotes ()
1274 "Translate M******** sm*rtq**t*s into proper text.
1275 Note that this function guesses whether a character is a sm*rtq**t* or
1276 not, so it should only be used interactively."
1278 (article-translate-strings gnus-article-dumbquotes-map))
1280 (defun article-translate-characters (from to)
1281 "Translate all characters in the body of the article according to FROM and TO.
1282 FROM is a string of characters to translate from; to is a string of
1283 characters to translate to."
1285 (when (article-goto-body)
1286 (let ((buffer-read-only nil)
1287 (x (make-string 225 ?x))
1289 (while (< (incf i) (length x))
1292 (while (< i (length from))
1293 (aset x (aref from i) (aref to i))
1295 (translate-region (point) (point-max) x)))))
1297 (defun article-translate-strings (map)
1298 "Translate all string in the body of the article according to MAP.
1299 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1301 (when (article-goto-body)
1302 (let ((buffer-read-only nil)
1304 (while (setq elem (pop map))
1306 (while (search-forward (car elem) nil t)
1307 (replace-match (cadr elem)))))))))
1309 (defun article-treat-overstrike ()
1310 "Translate overstrikes into bold text."
1313 (when (article-goto-body)
1314 (let ((buffer-read-only nil))
1315 (while (search-forward "\b" nil t)
1316 (let ((next (char-after))
1317 (previous (char-after (- (point) 2))))
1318 ;; We do the boldification/underlining by hiding the
1319 ;; overstrikes and putting the proper text property
1323 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1324 (put-text-property (point) (1+ (point)) 'face 'bold))
1326 (gnus-article-hide-text-type
1327 (1- (point)) (1+ (point)) 'overstrike)
1329 (- (point) 2) (1- (point)) 'face 'underline))
1331 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1333 (point) (1+ (point)) 'face 'underline)))))))))
1335 (defun article-fill-long-lines ()
1336 "Fill lines that are wider than the window width."
1339 (let ((buffer-read-only nil)
1340 (width (window-width (get-buffer-window (current-buffer)))))
1343 (let ((adaptive-fill-mode nil))
1346 (when (>= (current-column) (min fill-column width))
1347 (narrow-to-region (point) (gnus-point-at-bol))
1348 (fill-paragraph nil)
1349 (goto-char (point-max))
1351 (forward-line 1)))))))
1353 (defun article-capitalize-sentences ()
1354 "Capitalize the first word in each sentence."
1357 (let ((buffer-read-only nil)
1358 (paragraph-start "^[\n\^L]"))
1362 (forward-sentence)))))
1364 (defun article-remove-cr ()
1365 "Remove trailing CRs and then translate remaining CRs into LFs."
1368 (let ((buffer-read-only nil))
1369 (goto-char (point-min))
1370 (while (re-search-forward "\r+$" nil t)
1371 (replace-match "" t t))
1372 (goto-char (point-min))
1373 (while (search-forward "\r" nil t)
1374 (replace-match "\n" t t)))))
1376 (defun article-remove-trailing-blank-lines ()
1377 "Remove all trailing blank lines from the article."
1380 (let ((buffer-read-only nil))
1381 (goto-char (point-max))
1385 (while (and (not (bobp))
1386 (looking-at "^[ \t]*$")
1387 (not (gnus-annotation-in-region-p
1388 (point) (gnus-point-at-eol))))
1393 (defun article-display-x-face (&optional force)
1394 "Look for an X-Face header and display it if present."
1395 (interactive (list 'force))
1397 ;; Delete the old process, if any.
1398 (when (process-status "article-x-face")
1399 (delete-process "article-x-face"))
1400 (let ((inhibit-point-motion-hooks t)
1401 (case-fold-search t)
1404 (article-narrow-to-head)
1405 (goto-char (point-min))
1406 (setq from (message-fetch-field "from"))
1407 (goto-char (point-min))
1408 (while (and gnus-article-x-face-command
1411 ;; Check whether this face is censored.
1412 (not gnus-article-x-face-too-ugly)
1413 (and gnus-article-x-face-too-ugly from
1414 (not (string-match gnus-article-x-face-too-ugly
1416 ;; Has to be present.
1417 (re-search-forward "^X-Face: " nil t))
1418 ;; This used to try to do multiple faces (`while' instead of
1419 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1420 ;; work (b) it can crash some versions of Emacs (c) are
1421 ;; multiple faces really something to encourage?
1422 (when (stringp gnus-article-x-face-command)
1424 ;; We now have the area of the buffer where the X-Face is stored.
1427 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1428 ;; We display the face.
1429 (if (symbolp gnus-article-x-face-command)
1430 ;; The command is a lisp function, so we call it.
1431 (if (gnus-functionp gnus-article-x-face-command)
1432 (funcall gnus-article-x-face-command beg end)
1433 (error "%s is not a function" gnus-article-x-face-command))
1434 ;; The command is a string, so we interpret the command
1435 ;; as a, well, command, and fork it off.
1436 (let ((process-connection-type nil))
1437 (process-kill-without-query
1439 "article-x-face" nil shell-file-name shell-command-switch
1440 gnus-article-x-face-command))
1441 (process-send-region "article-x-face" beg end)
1442 (process-send-eof "article-x-face"))))))))))
1444 (defun article-decode-mime-words ()
1445 "Decode all MIME-encoded words in the article."
1448 (set-buffer gnus-article-buffer)
1449 (let ((inhibit-point-motion-hooks t)
1451 (mail-parse-charset gnus-newsgroup-charset)
1452 (mail-parse-ignored-charsets
1453 (save-excursion (set-buffer gnus-summary-buffer)
1454 gnus-newsgroup-ignored-charsets)))
1455 (mail-decode-encoded-word-region (point-min) (point-max)))))
1457 (defun article-decode-charset (&optional prompt)
1458 "Decode charset-encoded text in the article.
1459 If PROMPT (the prefix), prompt for a coding system to use."
1461 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1463 (mail-parse-charset gnus-newsgroup-charset)
1464 (mail-parse-ignored-charsets
1465 (save-excursion (condition-case nil
1466 (set-buffer gnus-summary-buffer)
1468 gnus-newsgroup-ignored-charsets))
1469 ct cte ctl charset format)
1472 (article-narrow-to-head)
1473 (setq ct (message-fetch-field "Content-Type" t)
1474 cte (message-fetch-field "Content-Transfer-Encoding" t)
1475 ctl (and ct (ignore-errors
1476 (mail-header-parse-content-type ct)))
1479 (mm-read-coding-system "Charset to decode: "))
1481 (mail-content-type-get ctl 'charset)))
1482 format (and ctl (mail-content-type-get ctl 'format)))
1484 (setq cte (mail-header-strip cte)))
1485 (if (and ctl (not (string-match "/" (car ctl))))
1487 (goto-char (point-max)))
1490 (narrow-to-region (point) (point-max))
1491 (when (and (eq mail-parse-charset 'gnus-decoded)
1492 (eq (mm-body-7-or-8) '8bit))
1493 ;; The text code could have been decoded.
1494 (setq charset mail-parse-charset))
1495 (when (and (or (not ctl)
1496 (equal (car ctl) "text/plain"))
1497 (not format)) ;; article with format will decode later.
1499 charset (and cte (intern (downcase
1500 (gnus-strip-whitespace cte))))
1503 (defun article-decode-encoded-words ()
1504 "Remove encoded-word encoding from headers."
1505 (let ((inhibit-point-motion-hooks t)
1506 (mail-parse-charset gnus-newsgroup-charset)
1507 (mail-parse-ignored-charsets
1508 (save-excursion (condition-case nil
1509 (set-buffer gnus-summary-buffer)
1511 gnus-newsgroup-ignored-charsets))
1514 (article-narrow-to-head)
1515 (funcall gnus-decode-header-function (point-min) (point-max)))))
1517 (defun article-de-quoted-unreadable (&optional force)
1518 "Translate a quoted-printable-encoded article.
1519 If FORCE, decode the article whether it is marked as quoted-printable
1521 (interactive (list 'force))
1523 (let ((buffer-read-only nil) type charset)
1524 (if (gnus-buffer-live-p gnus-original-article-buffer)
1525 (with-current-buffer gnus-original-article-buffer
1527 (gnus-fetch-field "content-transfer-encoding"))
1528 (let* ((ct (gnus-fetch-field "content-type"))
1531 (mail-header-parse-content-type ct)))))
1532 (setq charset (and ctl
1533 (mail-content-type-get ctl 'charset)))
1534 (if (stringp charset)
1535 (setq charset (intern (downcase charset)))))))
1537 (setq charset gnus-newsgroup-charset))
1539 (and type (string-match "quoted-printable" (downcase type))))
1541 (quoted-printable-decode-region (point) (point-max) charset)))))
1543 (defun article-de-base64-unreadable (&optional force)
1544 "Translate a base64 article.
1545 If FORCE, decode the article whether it is marked as base64 not."
1546 (interactive (list 'force))
1548 (let ((buffer-read-only nil) type charset)
1549 (if (gnus-buffer-live-p gnus-original-article-buffer)
1550 (with-current-buffer gnus-original-article-buffer
1552 (gnus-fetch-field "content-transfer-encoding"))
1553 (let* ((ct (gnus-fetch-field "content-type"))
1556 (mail-header-parse-content-type ct)))))
1557 (setq charset (and ctl
1558 (mail-content-type-get ctl 'charset)))
1559 (if (stringp charset)
1560 (setq charset (intern (downcase charset)))))))
1562 (setq charset gnus-newsgroup-charset))
1564 (and type (string-match "base64" (downcase type))))
1567 (narrow-to-region (point) (point-max))
1568 (base64-decode-region (point-min) (point-max))
1569 (if (mm-coding-system-p charset)
1570 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1575 (defun article-decode-HZ ()
1576 "Translate a HZ-encoded article."
1580 (let ((buffer-read-only nil))
1581 (rfc1843-decode-region (point-min) (point-max)))))
1583 (defun article-wash-html ()
1584 "Format an html article."
1587 (let ((buffer-read-only nil)
1589 (if (gnus-buffer-live-p gnus-original-article-buffer)
1590 (with-current-buffer gnus-original-article-buffer
1591 (let* ((ct (gnus-fetch-field "content-type"))
1594 (mail-header-parse-content-type ct)))))
1595 (setq charset (and ctl
1596 (mail-content-type-get ctl 'charset)))
1597 (if (stringp charset)
1598 (setq charset (intern (downcase charset)))))))
1600 (setq charset gnus-newsgroup-charset))
1602 (save-window-excursion
1604 (narrow-to-region (point) (point-max))
1606 (let ((w3-strict-width (window-width))
1607 (url-standalone-mode t))
1609 (w3-region (point-min) (point-max))
1612 (defun article-hide-list-identifiers ()
1613 "Remove list identifies from the Subject header.
1614 The `gnus-list-identifiers' variable specifies what to do."
1618 (let ((inhibit-point-motion-hooks t)
1620 (article-narrow-to-head)
1621 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1622 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1624 (goto-char (point-min))
1625 (when (re-search-forward
1626 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1627 " *\\)\\)+\\(Re: +\\)?\\)")
1629 (let ((s (or (match-string 3) (match-string 5))))
1630 (delete-region (match-beginning 1) (match-end 1))
1632 (goto-char (match-beginning 1))
1635 (defun article-hide-pgp ()
1636 "Remove any PGP headers and signatures in the current article."
1640 (let ((inhibit-point-motion-hooks t)
1641 buffer-read-only beg end)
1643 ;; Hide the "header".
1644 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1645 (push 'pgp gnus-article-wash-types)
1646 (delete-region (match-beginning 0) (match-end 0))
1647 ;; Remove armor headers (rfc2440 6.2)
1648 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1651 ;; Hide the actual signature.
1652 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1653 (setq end (1+ (match-beginning 0)))
1656 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1658 ;; Perhaps we shouldn't hide to the end of the buffer
1659 ;; if there is no end to the signature?
1661 ;; Hide "- " PGP quotation markers.
1663 (narrow-to-region beg end)
1664 (goto-char (point-min))
1665 (while (re-search-forward "^- " nil t)
1667 (match-beginning 0) (match-end 0)))
1669 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1671 (defun article-hide-pem (&optional arg)
1672 "Toggle hiding of any PEM headers and signatures in the current article.
1673 If given a negative prefix, always show; if given a positive prefix,
1675 (interactive (gnus-article-hidden-arg))
1676 (unless (gnus-article-check-hidden-text 'pem arg)
1678 (let (buffer-read-only end)
1679 (goto-char (point-min))
1680 ;; Hide the horrendously ugly "header".
1681 (when (and (search-forward
1682 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1684 (setq end (1+ (match-beginning 0))))
1685 (push 'pem gnus-article-wash-types)
1686 (gnus-article-hide-text-type
1688 (if (search-forward "\n\n" nil t)
1692 ;; Hide the trailer as well
1693 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1695 (gnus-article-hide-text-type
1696 (match-beginning 0) (match-end 0) 'pem)))))))
1698 (defun article-strip-banner ()
1699 "Strip the banner specified by the `banner' group parameter."
1703 (let ((inhibit-point-motion-hooks t)
1704 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1705 (gnus-signature-limit nil)
1706 buffer-read-only beg end)
1710 ((eq banner 'signature)
1711 (when (gnus-article-narrow-to-signature)
1714 (delete-region (point) (point-max))))
1716 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1717 (while (re-search-forward banner nil t)
1718 (delete-region (match-beginning 0) (match-end 0)))))
1720 (while (re-search-forward banner nil t)
1721 (delete-region (match-beginning 0) (match-end 0))))))))))
1723 (defun article-babel ()
1724 "Translate article using an online translation service."
1728 (set-buffer gnus-article-buffer)
1729 (when (article-goto-body)
1730 (let* ((buffer-read-only nil)
1733 (orig (buffer-substring start end))
1734 (trans (babel-as-string orig)))
1736 (narrow-to-region start end)
1737 (delete-region start end)
1740 (defun article-hide-signature (&optional arg)
1741 "Hide the signature in the current article.
1742 If given a negative prefix, always show; if given a positive prefix,
1744 (interactive (gnus-article-hidden-arg))
1745 (unless (gnus-article-check-hidden-text 'signature arg)
1748 (let ((buffer-read-only nil))
1749 (when (gnus-article-narrow-to-signature)
1750 (gnus-article-hide-text-type
1751 (point-min) (point-max) 'signature)))))))
1753 (defun article-strip-headers-in-body ()
1754 "Strip offensive headers from bodies."
1758 (let ((case-fold-search t))
1759 (when (looking-at "x-no-archive:")
1760 (gnus-delete-line)))))
1762 (defun article-strip-leading-blank-lines ()
1763 "Remove all blank lines from the beginning of the article."
1766 (let ((inhibit-point-motion-hooks t)
1768 (when (article-goto-body)
1769 (while (and (not (eobp))
1770 (looking-at "[ \t]*$"))
1771 (gnus-delete-line))))))
1773 (defun article-narrow-to-head ()
1774 "Narrow the buffer to the head of the message.
1775 Point is left at the beginning of the narrowed-to region."
1777 (goto-char (point-min))
1778 (if (search-forward "\n\n" nil 1)
1781 (goto-char (point-min)))
1783 (defun article-goto-body ()
1784 "Place point at the start of the body."
1785 (goto-char (point-min))
1787 ;; This variable is only bound when dealing with separate
1789 (article-goto-body-goes-to-point-min-p
1791 ((search-forward "\n\n" nil t)
1794 (goto-char (point-max))
1797 (defun article-strip-multiple-blank-lines ()
1798 "Replace consecutive blank lines with one empty line."
1801 (let ((inhibit-point-motion-hooks t)
1803 ;; First make all blank lines empty.
1805 (while (re-search-forward "^[ \t]+$" nil t)
1806 (unless (gnus-annotation-in-region-p
1807 (match-beginning 0) (match-end 0))
1808 (replace-match "" nil t)))
1809 ;; Then replace multiple empty lines with a single empty line.
1811 (while (re-search-forward "\n\n\n+" nil t)
1812 (unless (gnus-annotation-in-region-p
1813 (match-beginning 0) (match-end 0))
1814 (replace-match "\n\n" t t))))))
1816 (defun article-strip-leading-space ()
1817 "Remove all white space from the beginning of the lines in the article."
1820 (let ((inhibit-point-motion-hooks t)
1823 (while (re-search-forward "^[ \t]+" nil t)
1824 (replace-match "" t t)))))
1826 (defun article-strip-trailing-space ()
1827 "Remove all white space from the end of the lines in the article."
1830 (let ((inhibit-point-motion-hooks t)
1833 (while (re-search-forward "[ \t]+$" nil t)
1834 (replace-match "" t t)))))
1836 (defun article-strip-blank-lines ()
1837 "Strip leading, trailing and multiple blank lines."
1839 (article-strip-leading-blank-lines)
1840 (article-remove-trailing-blank-lines)
1841 (article-strip-multiple-blank-lines))
1843 (defun article-strip-all-blank-lines ()
1844 "Strip all blank lines."
1847 (let ((inhibit-point-motion-hooks t)
1850 (while (re-search-forward "^[ \t]*\n" nil t)
1851 (replace-match "" t t)))))
1853 (defun gnus-article-narrow-to-signature ()
1854 "Narrow to the signature; return t if a signature is found, else nil."
1855 (let ((inhibit-point-motion-hooks t))
1856 (when (gnus-article-search-signature)
1858 ;; Check whether we have some limits to what we consider
1859 ;; to be a signature.
1860 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1861 (list gnus-signature-limit)))
1863 (while (setq limit (pop limits))
1864 (if (or (and (integerp limit)
1865 (< (- (point-max) (point)) limit))
1867 (< (count-lines (point) (point-max)) limit))
1868 (and (gnus-functionp limit)
1870 (and (stringp limit)
1871 (not (re-search-forward limit nil t))))
1872 () ; This limit did not succeed.
1876 (narrow-to-region (point) (point-max))
1879 (defun gnus-article-search-signature ()
1880 "Search the current buffer for the signature separator.
1881 Put point at the beginning of the signature separator."
1882 (let ((cur (point)))
1883 (goto-char (point-max))
1884 (if (if (stringp gnus-signature-separator)
1885 (re-search-backward gnus-signature-separator nil t)
1886 (let ((seps gnus-signature-separator))
1888 (not (re-search-backward (car seps) nil t)))
1895 (defun gnus-article-hidden-arg ()
1896 "Return the current prefix arg as a number, or 0 if no prefix."
1897 (list (if current-prefix-arg
1898 (prefix-numeric-value current-prefix-arg)
1901 (defun gnus-article-check-hidden-text (type arg)
1902 "Return nil if hiding is necessary.
1903 Arg can be nil or a number. Nil and positive means hide, negative
1904 means show, 0 means toggle."
1907 (let ((hide (gnus-article-hidden-text-p type)))
1913 (gnus-article-show-hidden-text type))
1915 (if (eq hide 'hidden)
1916 (gnus-article-show-hidden-text type)
1919 (defun gnus-article-hidden-text-p (type)
1920 "Say whether the current buffer contains hidden text of type TYPE."
1921 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1923 (not (get-text-property pos 'invisible))
1924 (not (get-text-property pos 'dummy-invisible)))
1926 (text-property-any (1+ pos) (point-max) 'article-type type)))
1931 (defun gnus-article-show-hidden-text (type &optional hide)
1932 "Show all hidden text of type TYPE.
1933 If HIDE, hide the text instead."
1935 (let ((buffer-read-only nil)
1936 (inhibit-point-motion-hooks t)
1939 (while (setq beg (text-property-any end (point-max) 'article-type type))
1942 (text-property-not-all beg (point-max) 'article-type type)
1945 (gnus-article-hide-text beg end gnus-hidden-properties)
1946 (gnus-article-unhide-text beg end))
1950 (defconst article-time-units
1951 `((year . ,(* 365.25 24 60 60))
1952 (week . ,(* 7 24 60 60))
1953 (day . ,(* 24 60 60))
1957 "Mapping from time units to seconds.")
1959 (defun article-date-ut (&optional type highlight header)
1960 "Convert DATE date to universal time in the current article.
1961 If TYPE is `local', convert to local time; if it is `lapsed', output
1962 how much time has lapsed since DATE. For `lapsed', the value of
1963 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1964 should replace the \"Date:\" one, or should be added below it."
1965 (interactive (list 'ut t))
1966 (let* ((header (or header
1967 (message-fetch-field "date")
1969 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1972 ((not gnus-article-date-lapsed-new-header)
1978 (date (if (vectorp header) (mail-header-date header)
1980 (inhibit-point-motion-hooks t)
1985 (article-narrow-to-head)
1986 (when (re-search-forward tdate-regexp nil t)
1987 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1988 date (or (get-text-property (gnus-point-at-bol)
1991 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1993 (when (and date (not (string= date "")))
1994 (goto-char (point-min))
1995 (let ((buffer-read-only nil))
1996 ;; Delete any old Date headers.
1997 (while (re-search-forward date-regexp nil t)
1999 (delete-region (progn (beginning-of-line) (point))
2000 (progn (forward-line 1) (point)))
2001 (delete-region (progn (beginning-of-line) (point))
2002 (progn (end-of-line) (point)))
2003 (setq pos (point))))
2004 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2006 (if pos (goto-char pos))
2007 (insert (article-make-date-line date (or type 'ut)))
2013 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2014 (put-text-property (match-beginning 1) (1+ (match-end 1))
2015 'original-date date)
2016 (put-text-property (match-beginning 1) (1+ (match-end 1))
2018 (put-text-property (match-beginning 2) (match-end 2)
2021 (defun article-make-date-line (date type)
2022 "Return a DATE line of TYPE."
2023 (let ((time (condition-case ()
2027 ;; Convert to the local timezone. We have to slap a
2028 ;; `condition-case' round the calls to the timezone
2029 ;; functions since they aren't particularly resistant to
2032 (let ((tz (car (current-time-zone time))))
2033 (format "Date: %s %s%02d%02d" (current-time-string time)
2034 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2035 (/ (% (abs tz) 3600) 60))))
2036 ;; Convert to Universal Time.
2039 (current-time-string
2040 (let* ((e (parse-time-string date))
2041 (tm (apply 'encode-time e))
2043 (ls (- (cadr tm) (car (current-time-zone time)))))
2044 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2045 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2048 ;; Get the original date from the article.
2049 ((eq type 'original)
2050 (concat "Date: " (if (string-match "\n+$" date)
2051 (substring date 0 (match-beginning 0))
2053 ;; Let the user define the format.
2055 (if (gnus-functionp gnus-article-time-format)
2056 (funcall gnus-article-time-format time)
2059 (format-time-string gnus-article-time-format time))))
2062 (let ((tz (car (current-time-zone time))))
2065 (format-time-string "%Y%m%dT%H%M%S" time)
2066 (format "%s%02d%02d"
2067 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2068 (/ (% (abs tz) 3600) 60)))))
2069 ;; Do an X-Sent lapsed format.
2071 ;; If the date is seriously mangled, the timezone functions are
2072 ;; liable to bug out, so we ignore all errors.
2073 (let* ((now (current-time))
2074 (real-time (subtract-time now time))
2075 (real-sec (and real-time
2076 (+ (* (float (car real-time)) 65536)
2078 (sec (and real-time (abs real-sec)))
2088 ;; This is a bit convoluted, but basically we go
2089 ;; through the time units for years, weeks, etc,
2090 ;; and divide things to see whether that results
2091 ;; in positive answers.
2094 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2095 ;; The (remaining) seconds are too few to
2096 ;; be divided into this time unit.
2098 ;; It's big enough, so we output it.
2099 (setq sec (- sec (* num (cdr unit))))
2101 (concat (if prev ", " "") (int-to-string
2103 " " (symbol-name (car unit))
2104 (if (> num 1) "s" ""))
2106 article-time-units "")
2107 ;; If dates are odd, then it might appear like the
2108 ;; article was sent in the future.
2111 " in the future"))))))
2113 (error "Unknown conversion type: %s" type)))))
2115 (defun article-date-local (&optional highlight)
2116 "Convert the current article date to the local timezone."
2117 (interactive (list t))
2118 (article-date-ut 'local highlight))
2120 (defun article-date-original (&optional highlight)
2121 "Convert the current article date to what it was originally.
2122 This is only useful if you have used some other date conversion
2123 function and want to see what the date was before converting."
2124 (interactive (list t))
2125 (article-date-ut 'original highlight))
2127 (defun article-date-lapsed (&optional highlight)
2128 "Convert the current article date to time lapsed since it was sent."
2129 (interactive (list t))
2130 (article-date-ut 'lapsed highlight))
2132 (defun article-update-date-lapsed ()
2133 "Function to be run from a timer to update the lapsed time line."
2134 (let (deactivate-mark)
2139 (set-buffer (window-buffer w))
2140 (when (eq major-mode 'gnus-article-mode)
2141 (goto-char (point-min))
2142 (when (re-search-forward "^X-Sent:" nil t)
2143 (article-date-lapsed t))))
2146 (defun gnus-start-date-timer (&optional n)
2147 "Start a timer to update the X-Sent header in the article buffers.
2148 The numerical prefix says how frequently (in seconds) the function
2153 (gnus-stop-date-timer)
2154 (setq article-lapsed-timer
2155 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2157 (defun gnus-stop-date-timer ()
2158 "Stop the X-Sent timer."
2160 (when article-lapsed-timer
2161 (nnheader-cancel-timer article-lapsed-timer)
2162 (setq article-lapsed-timer nil)))
2164 (defun article-date-user (&optional highlight)
2165 "Convert the current article date to the user-defined format.
2166 This format is defined by the `gnus-article-time-format' variable."
2167 (interactive (list t))
2168 (article-date-ut 'user highlight))
2170 (defun article-date-iso8601 (&optional highlight)
2171 "Convert the current article date to ISO8601."
2172 (interactive (list t))
2173 (article-date-ut 'iso8601 highlight))
2175 (defun article-show-all ()
2176 "Show all hidden text in the article buffer."
2179 (let ((buffer-read-only nil))
2180 (gnus-article-unhide-text (point-min) (point-max)))))
2182 (defun article-emphasize (&optional arg)
2183 "Emphasize text according to `gnus-emphasis-alist'."
2184 (interactive (gnus-article-hidden-arg))
2185 (unless (gnus-article-check-hidden-text 'emphasis arg)
2189 (with-current-buffer gnus-summary-buffer
2190 gnus-article-emphasis-alist)
2192 gnus-emphasis-alist))
2193 (buffer-read-only nil)
2194 (props (append '(article-type emphasis)
2195 gnus-hidden-properties))
2196 regexp elem beg invisible visible face)
2199 (while (setq elem (pop alist))
2201 (setq regexp (car elem)
2202 invisible (nth 1 elem)
2203 visible (nth 2 elem)
2205 (while (re-search-forward regexp nil t)
2206 (when (and (match-beginning visible) (match-beginning invisible))
2207 (push 'emphasis gnus-article-wash-types)
2208 (gnus-article-hide-text
2209 (match-beginning invisible) (match-end invisible) props)
2210 (gnus-article-unhide-text-type
2211 (match-beginning visible) (match-end visible) 'emphasis)
2212 (gnus-put-text-property-excluding-newlines
2213 (match-beginning visible) (match-end visible) 'face face)
2214 (goto-char (match-end invisible)))))))))
2216 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2217 "Setup newsgroup emphasis alist."
2218 (unless gnus-article-emphasis-alist
2219 (let ((name (and gnus-newsgroup-name
2220 (gnus-group-real-name gnus-newsgroup-name))))
2221 (make-local-variable 'gnus-article-emphasis-alist)
2222 (setq gnus-article-emphasis-alist
2224 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2225 (while (setq elem (pop alist))
2226 (when (and name (string-match (car elem) name))
2228 highlight (copy-sequence (cdr elem)))))
2230 (copy-sequence highlight-words)
2231 (if gnus-newsgroup-name
2232 (copy-sequence (gnus-group-find-parameter
2233 gnus-newsgroup-name 'highlight-words t)))
2234 gnus-emphasis-alist)))))
2236 (defvar gnus-summary-article-menu)
2237 (defvar gnus-summary-post-menu)
2239 ;;; Saving functions.
2241 (defun gnus-article-save (save-buffer file &optional num)
2242 "Save the currently selected article."
2243 (unless gnus-save-all-headers
2244 ;; Remove headers according to `gnus-saved-headers'.
2245 (let ((gnus-visible-headers
2246 (or gnus-saved-headers gnus-visible-headers))
2247 (gnus-article-buffer save-buffer))
2249 (set-buffer save-buffer)
2250 (article-hide-headers 1 t))))
2251 (save-window-excursion
2252 (if (not gnus-default-article-saver)
2253 (error "No default saver is defined")
2254 ;; !!! Magic! The saving functions all save
2255 ;; `gnus-save-article-buffer' (or so they think), but we
2256 ;; bind that variable to our save-buffer.
2257 (set-buffer gnus-article-buffer)
2258 (let* ((gnus-save-article-buffer save-buffer)
2261 ((not gnus-prompt-before-saving) 'default)
2262 ((eq gnus-prompt-before-saving 'always) nil)
2264 (gnus-number-of-articles-to-be-saved
2265 (when (eq gnus-prompt-before-saving t)
2267 (set-buffer gnus-article-current-summary)
2268 (funcall gnus-default-article-saver filename)))))
2270 (defun gnus-read-save-file-name (prompt &optional filename
2271 function group headers variable)
2273 (funcall function group headers (symbol-value variable)))
2278 ((eq filename 'default)
2284 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2287 (if (and gnus-number-of-articles-to-be-saved
2288 (> gnus-number-of-articles-to-be-saved 1))
2289 (format "these %d articles"
2290 gnus-number-of-articles-to-be-saved)
2293 ;; Let the split methods have their say.
2295 ;; No split name was found.
2298 (concat prompt " (default "
2299 (file-name-nondirectory default-name) ") ")
2300 (file-name-directory default-name)
2302 ;; A single group name is returned.
2303 ((stringp split-name)
2305 (funcall function split-name headers
2306 (symbol-value variable)))
2308 (concat prompt " (default "
2309 (file-name-nondirectory default-name) ") ")
2310 (file-name-directory default-name)
2312 ;; A single split name was found
2313 ((= 1 (length split-name))
2314 (let* ((name (expand-file-name
2315 (car split-name) gnus-article-save-directory))
2316 (dir (cond ((file-directory-p name)
2317 (file-name-as-directory name))
2318 ((file-exists-p name) name)
2319 (t gnus-article-save-directory))))
2321 (concat prompt " (default " name ") ")
2323 ;; A list of splits was found.
2325 (setq split-name (nreverse split-name))
2327 (let ((file-name-history
2328 (nconc split-name file-name-history)))
2332 (concat prompt " (`M-p' for defaults) ")
2333 gnus-article-save-directory
2335 gnus-article-save-directory)))
2336 (car (push result file-name-history)))))))
2337 ;; Create the directory.
2338 (gnus-make-directory (file-name-directory file))
2339 ;; If we have read a directory, we append the default file name.
2340 (when (file-directory-p file)
2341 (setq file (expand-file-name (file-name-nondirectory default-name)
2342 (file-name-as-directory file))))
2343 ;; Possibly translate some characters.
2344 (nnheader-translate-file-chars file))))))
2345 (gnus-make-directory (file-name-directory result))
2346 (set variable result)))
2348 (defun gnus-article-archive-name (group)
2349 "Return the first instance of an \"Archive-name\" in the current buffer."
2350 (let ((case-fold-search t))
2351 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2352 (nnheader-concat gnus-article-save-directory
2353 (match-string 1)))))
2355 (defun gnus-article-nndoc-name (group)
2356 "If GROUP is an nndoc group, return the name of the parent group."
2357 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2358 (gnus-group-get-parameter group 'save-article-group)))
2360 (defun gnus-summary-save-in-rmail (&optional filename)
2361 "Append this article to Rmail file.
2362 Optional argument FILENAME specifies file name.
2363 Directory to save to is default to `gnus-article-save-directory'."
2364 (setq filename (gnus-read-save-file-name
2365 "Save %s in rmail file:" filename
2366 gnus-rmail-save-name gnus-newsgroup-name
2367 gnus-current-headers 'gnus-newsgroup-last-rmail))
2368 (gnus-eval-in-buffer-window gnus-save-article-buffer
2372 (gnus-output-to-rmail filename))))
2375 (defun gnus-summary-save-in-mail (&optional filename)
2376 "Append this article to Unix mail file.
2377 Optional argument FILENAME specifies file name.
2378 Directory to save to is default to `gnus-article-save-directory'."
2379 (setq filename (gnus-read-save-file-name
2380 "Save %s in Unix mail file:" filename
2381 gnus-mail-save-name gnus-newsgroup-name
2382 gnus-current-headers 'gnus-newsgroup-last-mail))
2383 (gnus-eval-in-buffer-window gnus-save-article-buffer
2387 (if (and (file-readable-p filename)
2388 (mail-file-babyl-p filename))
2389 (rmail-output-to-rmail-file filename t)
2390 (gnus-output-to-mail filename)))))
2393 (defun gnus-summary-save-in-file (&optional filename overwrite)
2394 "Append this article to file.
2395 Optional argument FILENAME specifies file name.
2396 Directory to save to is default to `gnus-article-save-directory'."
2397 (setq filename (gnus-read-save-file-name
2398 "Save %s in file:" filename
2399 gnus-file-save-name gnus-newsgroup-name
2400 gnus-current-headers 'gnus-newsgroup-last-file))
2401 (gnus-eval-in-buffer-window gnus-save-article-buffer
2405 (when (and overwrite
2406 (file-exists-p filename))
2407 (delete-file filename))
2408 (gnus-output-to-file filename))))
2411 (defun gnus-summary-write-to-file (&optional filename)
2412 "Write this article to a file.
2413 Optional argument FILENAME specifies file name.
2414 The directory to save in defaults to `gnus-article-save-directory'."
2415 (gnus-summary-save-in-file nil t))
2417 (defun gnus-summary-save-body-in-file (&optional filename)
2418 "Append this article body to a file.
2419 Optional argument FILENAME specifies file name.
2420 The directory to save in defaults to `gnus-article-save-directory'."
2421 (setq filename (gnus-read-save-file-name
2422 "Save %s body in file:" filename
2423 gnus-file-save-name gnus-newsgroup-name
2424 gnus-current-headers 'gnus-newsgroup-last-file))
2425 (gnus-eval-in-buffer-window gnus-save-article-buffer
2429 (when (article-goto-body)
2430 (narrow-to-region (point) (point-max)))
2431 (gnus-output-to-file filename))))
2434 (defun gnus-summary-save-in-pipe (&optional command)
2435 "Pipe this article to subprocess."
2437 (cond ((and (eq command 'default)
2438 gnus-last-shell-command)
2439 gnus-last-shell-command)
2443 "Shell command on %s: "
2444 (if (and gnus-number-of-articles-to-be-saved
2445 (> gnus-number-of-articles-to-be-saved 1))
2446 (format "these %d articles"
2447 gnus-number-of-articles-to-be-saved)
2449 gnus-last-shell-command))))
2450 (when (string-equal command "")
2451 (setq command gnus-last-shell-command))
2452 (gnus-eval-in-buffer-window gnus-article-buffer
2455 (shell-command-on-region (point-min) (point-max) command nil)))
2456 (setq gnus-last-shell-command command))
2458 ;;; Article file names when saving.
2460 (defun gnus-capitalize-newsgroup (newsgroup)
2461 "Capitalize NEWSGROUP name."
2462 (when (not (zerop (length newsgroup)))
2463 (concat (char-to-string (upcase (aref newsgroup 0)))
2464 (substring newsgroup 1))))
2466 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2467 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2468 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2469 Otherwise, it is like ~/News/news/group/num."
2472 (concat (if (gnus-use-long-file-name 'not-save)
2473 (gnus-capitalize-newsgroup newsgroup)
2474 (gnus-newsgroup-directory-form newsgroup))
2475 "/" (int-to-string (mail-header-number headers)))
2476 gnus-article-save-directory)))
2478 (string-equal (file-name-directory default)
2479 (file-name-directory last-file))
2480 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2482 (or last-file default))))
2484 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2485 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2486 If variable `gnus-use-long-file-name' is non-nil, it is
2487 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2490 (concat (if (gnus-use-long-file-name 'not-save)
2492 (gnus-newsgroup-directory-form newsgroup))
2493 "/" (int-to-string (mail-header-number headers)))
2494 gnus-article-save-directory)))
2496 (string-equal (file-name-directory default)
2497 (file-name-directory last-file))
2498 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2500 (or last-file default))))
2502 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2503 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2504 If variable `gnus-use-long-file-name' is non-nil, it is
2505 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2508 (if (gnus-use-long-file-name 'not-save)
2510 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2511 gnus-article-save-directory)))
2518 (setq afunc (car func)
2521 gfunc (intern (format "gnus-%s" func))))
2524 `(lambda (&optional interactive &rest args)
2525 ,(documentation afunc t)
2526 (interactive (list t))
2528 (set-buffer gnus-article-buffer)
2530 (call-interactively ',afunc)
2531 (apply ',afunc args))))))))
2532 '(article-hide-headers
2533 article-hide-boring-headers
2534 article-treat-overstrike
2535 article-fill-long-lines
2536 article-capitalize-sentences
2538 article-display-x-face
2539 article-de-quoted-unreadable
2540 article-de-base64-unreadable
2543 article-hide-list-identifiers
2545 article-strip-banner
2548 article-hide-signature
2549 article-strip-headers-in-body
2550 article-remove-trailing-blank-lines
2551 article-strip-leading-blank-lines
2552 article-strip-multiple-blank-lines
2553 article-strip-leading-space
2554 article-strip-trailing-space
2555 article-strip-blank-lines
2556 article-strip-all-blank-lines
2558 article-date-iso8601
2559 article-date-original
2561 article-decode-mime-words
2562 article-decode-charset
2563 article-decode-encoded-words
2567 article-treat-dumbquotes
2568 article-normalize-headers
2569 (article-show-all . gnus-article-show-all-headers))))
2572 ;;; Gnus article mode
2575 (put 'gnus-article-mode 'mode-class 'special)
2577 (set-keymap-parent gnus-article-mode-map widget-keymap)
2579 (gnus-define-keys gnus-article-mode-map
2580 " " gnus-article-goto-next-page
2581 "\177" gnus-article-goto-prev-page
2582 [delete] gnus-article-goto-prev-page
2583 [backspace] gnus-article-goto-prev-page
2584 "\C-c^" gnus-article-refer-article
2585 "h" gnus-article-show-summary
2586 "s" gnus-article-show-summary
2587 "\C-c\C-m" gnus-article-mail
2588 "?" gnus-article-describe-briefly
2589 "e" gnus-summary-edit-article
2590 "<" beginning-of-buffer
2592 "\C-c\C-i" gnus-info-find-node
2595 "\C-d" gnus-article-read-summary-keys
2596 "\M-*" gnus-article-read-summary-keys
2597 "\M-#" gnus-article-read-summary-keys
2598 "\M-^" gnus-article-read-summary-keys
2599 "\M-g" gnus-article-read-summary-keys)
2601 (substitute-key-definition
2602 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2604 (defun gnus-article-make-menu-bar ()
2605 (gnus-turn-off-edit-menu 'article)
2606 (unless (boundp 'gnus-article-article-menu)
2608 gnus-article-article-menu gnus-article-mode-map ""
2610 ["Scroll forwards" gnus-article-goto-next-page t]
2611 ["Scroll backwards" gnus-article-goto-prev-page t]
2612 ["Show summary" gnus-article-show-summary t]
2613 ["Fetch Message-ID at point" gnus-article-refer-article t]
2614 ["Mail to address at point" gnus-article-mail t]
2615 ["Send a bug report" gnus-bug t]))
2618 gnus-article-treatment-menu gnus-article-mode-map ""
2620 ["Hide headers" gnus-article-hide-headers t]
2621 ["Hide signature" gnus-article-hide-signature t]
2622 ["Hide citation" gnus-article-hide-citation t]
2623 ["Treat overstrike" gnus-article-treat-overstrike t]
2624 ["Remove carriage return" gnus-article-remove-cr t]
2625 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2626 ["Remove base64" gnus-article-de-base64-unreadable t]
2627 ["Treat html" gnus-article-wash-html t]
2628 ["Decode HZ" gnus-article-decode-HZ t]))
2630 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2632 (when (boundp 'gnus-summary-post-menu)
2633 (define-key gnus-article-mode-map [menu-bar post]
2634 (cons "Post" gnus-summary-post-menu)))
2636 (gnus-run-hooks 'gnus-article-menu-hook)))
2638 (defun gnus-article-mode ()
2639 "Major mode for displaying an article.
2641 All normal editing commands are switched off.
2643 The following commands are available in addition to all summary mode
2645 \\<gnus-article-mode-map>
2646 \\[gnus-article-next-page]\t Scroll the article one page forwards
2647 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2648 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2649 \\[gnus-article-show-summary]\t Display the summary buffer
2650 \\[gnus-article-mail]\t Send a reply to the address near point
2651 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2652 \\[gnus-info-find-node]\t Go to the Gnus info node"
2654 (when (gnus-visual-p 'article-menu 'menu)
2655 (gnus-article-make-menu-bar))
2656 (gnus-simplify-mode-line)
2657 (setq mode-name "Article")
2658 (setq major-mode 'gnus-article-mode)
2659 (make-local-variable 'minor-mode-alist)
2660 (use-local-map gnus-article-mode-map)
2661 (gnus-update-format-specifications nil 'article-mode)
2662 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2663 (make-local-variable 'gnus-page-broken)
2664 (make-local-variable 'gnus-button-marker-list)
2665 (make-local-variable 'gnus-article-current-summary)
2666 (make-local-variable 'gnus-article-mime-handles)
2667 (make-local-variable 'gnus-article-decoded-p)
2668 (make-local-variable 'gnus-article-mime-handle-alist)
2669 (make-local-variable 'gnus-article-wash-types)
2670 (gnus-set-default-directory)
2671 (buffer-disable-undo)
2672 (setq buffer-read-only t)
2673 (set-syntax-table gnus-article-mode-syntax-table)
2674 (mm-enable-multibyte)
2675 (gnus-run-hooks 'gnus-article-mode-hook))
2677 (defun gnus-article-setup-buffer ()
2678 "Initialize the article buffer."
2679 (let* ((name (if gnus-single-article-buffer "*Article*"
2680 (concat "*Article " gnus-newsgroup-name "*")))
2682 (progn (string-match "\\*Article" name)
2683 (concat " *Original Article"
2684 (substring name (match-end 0))))))
2685 (setq gnus-article-buffer name)
2686 (setq gnus-original-article-buffer original)
2687 (setq gnus-article-mime-handle-alist nil)
2688 ;; This might be a variable local to the summary buffer.
2689 (unless gnus-single-article-buffer
2691 (set-buffer gnus-summary-buffer)
2692 (setq gnus-article-buffer name)
2693 (setq gnus-original-article-buffer original)
2694 (gnus-set-global-variables)))
2695 (gnus-article-setup-highlight-words)
2696 ;; Init original article buffer.
2698 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2699 (mm-enable-multibyte)
2700 (setq major-mode 'gnus-original-article-mode)
2701 (make-local-variable 'gnus-original-article))
2702 (if (get-buffer name)
2705 (when gnus-article-mime-handles
2706 (mm-destroy-parts gnus-article-mime-handles)
2707 (setq gnus-article-mime-handles nil))
2708 ;; Set it to nil in article-buffer!
2709 (setq gnus-article-mime-handle-alist nil)
2710 (buffer-disable-undo)
2711 (setq buffer-read-only t)
2712 (unless (eq major-mode 'gnus-article-mode)
2713 (gnus-article-mode))
2716 (set-buffer (gnus-get-buffer-create name))
2718 (make-local-variable 'gnus-summary-buffer)
2719 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2720 (current-buffer)))))
2722 ;; Set article window start at LINE, where LINE is the number of lines
2723 ;; from the head of the article.
2724 (defun gnus-article-set-window-start (&optional line)
2726 (get-buffer-window gnus-article-buffer t)
2728 (set-buffer gnus-article-buffer)
2729 (goto-char (point-min))
2732 (gnus-message 6 "Moved to bookmark")
2733 (search-forward "\n\n" nil t)
2737 (defun gnus-article-prepare (article &optional all-headers header)
2738 "Prepare ARTICLE in article mode buffer.
2739 ARTICLE should either be an article number or a Message-ID.
2740 If ARTICLE is an id, HEADER should be the article headers.
2741 If ALL-HEADERS is non-nil, no headers are hidden."
2743 ;; Make sure we start in a summary buffer.
2744 (unless (eq major-mode 'gnus-summary-mode)
2745 (set-buffer gnus-summary-buffer))
2746 (setq gnus-summary-buffer (current-buffer))
2747 (let* ((gnus-article (if header (mail-header-number header) article))
2748 (summary-buffer (current-buffer))
2749 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2750 (group gnus-newsgroup-name)
2753 (gnus-article-setup-buffer)
2754 (set-buffer gnus-article-buffer)
2755 ;; Deactivate active regions.
2756 (when (and (boundp 'transient-mark-mode)
2757 transient-mark-mode)
2758 (setq mark-active nil))
2759 (if (not (setq result (let ((buffer-read-only nil))
2760 (gnus-request-article-this-buffer
2762 ;; There is no such article.
2764 (when (and (numberp article)
2765 (not (memq article gnus-newsgroup-sparse)))
2766 (setq gnus-article-current
2767 (cons gnus-newsgroup-name article))
2768 (set-buffer gnus-summary-buffer)
2769 (setq gnus-current-article article)
2770 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2772 (gnus-summary-set-agent-mark article)
2773 (message "Message marked for downloading"))
2774 (gnus-summary-mark-article article gnus-canceled-mark)
2775 (unless (memq article gnus-newsgroup-sparse)
2776 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2777 (if (or (eq result 'pseudo)
2778 (eq result 'nneething))
2781 (set-buffer summary-buffer)
2782 (push article gnus-newsgroup-history)
2783 (setq gnus-last-article gnus-current-article
2784 gnus-current-article 0
2785 gnus-current-headers nil
2786 gnus-article-current nil)
2787 (if (eq result 'nneething)
2788 (gnus-configure-windows 'summary)
2789 (gnus-configure-windows 'article))
2790 (gnus-set-global-variables))
2791 (let ((gnus-article-mime-handle-alist-1
2792 gnus-article-mime-handle-alist))
2793 (gnus-set-mode-line 'article)))
2794 ;; The result from the `request' was an actual article -
2795 ;; or at least some text that is now displayed in the
2797 (when (and (numberp article)
2798 (not (eq article gnus-current-article)))
2799 ;; Seems like a new article has been selected.
2800 ;; `gnus-current-article' must be an article number.
2802 (set-buffer summary-buffer)
2803 (push article gnus-newsgroup-history)
2804 (setq gnus-last-article gnus-current-article
2805 gnus-current-article article
2806 gnus-current-headers
2807 (gnus-summary-article-header gnus-current-article)
2808 gnus-article-current
2809 (cons gnus-newsgroup-name gnus-current-article))
2810 (unless (vectorp gnus-current-headers)
2811 (setq gnus-current-headers nil))
2812 (gnus-summary-goto-subject gnus-current-article)
2813 (when (gnus-summary-show-thread)
2814 ;; If the summary buffer really was folded, the
2815 ;; previous goto may not actually have gone to
2816 ;; the right article, but the thread root instead.
2818 (gnus-summary-goto-subject gnus-current-article))
2819 (gnus-run-hooks 'gnus-mark-article-hook)
2820 (gnus-set-mode-line 'summary)
2821 (when (gnus-visual-p 'article-highlight 'highlight)
2822 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2823 ;; Set the global newsgroup variables here.
2824 (gnus-set-global-variables)
2825 (setq gnus-have-all-headers
2826 (or all-headers gnus-show-all-headers))))
2827 (when (or (numberp article)
2829 (gnus-article-prepare-display)
2831 (goto-char (point-min))
2832 (setq gnus-page-broken
2833 (when gnus-break-pages
2834 (gnus-narrow-to-page)
2836 (let ((gnus-article-mime-handle-alist-1
2837 gnus-article-mime-handle-alist))
2838 (gnus-set-mode-line 'article))
2840 (set-window-point (get-buffer-window (current-buffer)) (point))
2841 (gnus-configure-windows 'article)
2845 (defun gnus-article-prepare-display ()
2846 "Make the current buffer look like a nice article."
2847 ;; Hooks for getting information from the article.
2848 ;; This hook must be called before being narrowed.
2849 (let ((gnus-article-buffer (current-buffer))
2851 (unless (eq major-mode 'gnus-article-mode)
2852 (gnus-article-mode))
2853 (setq buffer-read-only nil
2854 gnus-article-wash-types nil)
2855 (gnus-run-hooks 'gnus-tmp-internal-hook)
2856 (when gnus-display-mime-function
2857 (funcall gnus-display-mime-function))
2858 (gnus-run-hooks 'gnus-article-prepare-hook)))
2861 ;;; Gnus MIME viewing functions
2864 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2865 "The following specs can be used:
2867 %T MIME type, along with additional info
2868 %n The `name' parameter
2869 %d The description, if any
2870 %l The length of the encoded part
2871 %p The part identifier number
2872 %e Dots if the part isn't displayed")
2874 (defvar gnus-mime-button-line-format-alist
2875 '((?t gnus-tmp-type ?s)
2876 (?T gnus-tmp-type-long ?s)
2877 (?n gnus-tmp-name ?s)
2878 (?d gnus-tmp-description ?s)
2880 (?l gnus-tmp-length ?d)
2881 (?e gnus-tmp-dots ?s)))
2883 (defvar gnus-mime-button-commands
2884 '((gnus-article-press-button "\r" "Toggle Display")
2885 (gnus-mime-view-part "v" "View Interactively...")
2886 (gnus-mime-view-part-as-type "t" "View As Type...")
2887 (gnus-mime-save-part "o" "Save...")
2888 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2889 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2890 (gnus-mime-internalize-part "E" "View Internally")
2891 (gnus-mime-externalize-part "e" "View Externally")
2892 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2894 (defun gnus-article-mime-part-status ()
2895 (if gnus-article-mime-handle-alist-1
2896 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2899 (defvar gnus-mime-button-map
2900 (let ((map (make-sparse-keymap)))
2901 (set-keymap-parent map gnus-article-mode-map)
2902 (define-key map gnus-mouse-2 'gnus-article-push-button)
2903 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2904 (dolist (c gnus-mime-button-commands)
2905 (define-key map (cadr c) (car c)))
2908 (defun gnus-mime-button-menu (event)
2909 "Construct a context-sensitive menu of MIME commands."
2912 (let ((pos (event-start event)))
2913 (set-buffer (window-buffer (posn-window pos)))
2914 (goto-char (posn-point pos))
2915 (gnus-article-check-buffer)
2916 (let ((response (x-popup-menu
2918 ("" ,@(mapcar (lambda (c)
2919 (cons (caddr c) (car c)))
2920 gnus-mime-button-commands))))))
2922 (call-interactively response))))))
2924 (defun gnus-mime-view-all-parts (&optional handles)
2925 "View all the MIME parts."
2927 (save-current-buffer
2928 (set-buffer gnus-article-buffer)
2929 (let ((handles (or handles gnus-article-mime-handles))
2930 (mail-parse-charset gnus-newsgroup-charset)
2931 (mail-parse-ignored-charsets
2932 (save-excursion (set-buffer gnus-summary-buffer)
2933 gnus-newsgroup-ignored-charsets)))
2934 (if (stringp (car handles))
2935 (gnus-mime-view-all-parts (cdr handles))
2936 (mapcar 'mm-display-part handles)))))
2938 (defun gnus-mime-save-part ()
2939 "Save the MIME part under point."
2941 (gnus-article-check-buffer)
2942 (let ((data (get-text-property (point) 'gnus-data)))
2943 (mm-save-part data)))
2945 (defun gnus-mime-pipe-part ()
2946 "Pipe the MIME part under point to a process."
2948 (gnus-article-check-buffer)
2949 (let ((data (get-text-property (point) 'gnus-data)))
2950 (mm-pipe-part data)))
2952 (defun gnus-mime-view-part ()
2953 "Interactively choose a viewing method for the MIME part under point."
2955 (gnus-article-check-buffer)
2956 (let ((data (get-text-property (point) 'gnus-data)))
2957 (mm-interactively-view-part data)))
2959 (defun gnus-mime-view-part-as-type-internal ()
2960 (gnus-article-check-buffer)
2961 (let* ((name (mail-content-type-get
2962 (mm-handle-type (get-text-property (point) 'gnus-data))
2964 (def-type (and name (mm-default-file-encoding name))))
2965 (and def-type (cons def-type 0))))
2967 (defun gnus-mime-view-part-as-type (mime-type)
2968 "Choose a MIME media type, and view the part as such."
2970 (list (completing-read
2971 "View as MIME type: "
2972 (mapcar #'list (mailcap-mime-types))
2974 (gnus-mime-view-part-as-type-internal))))
2975 (gnus-article-check-buffer)
2976 (let ((handle (get-text-property (point) 'gnus-data)))
2977 (gnus-mm-display-part
2978 (mm-make-handle (mm-handle-buffer handle)
2979 (cons mime-type (cdr (mm-handle-type handle)))
2980 (mm-handle-encoding handle)
2981 (mm-handle-undisplayer handle)
2982 (mm-handle-disposition handle)
2983 (mm-handle-description handle)
2984 (mm-handle-cache handle)
2985 (mm-handle-id handle)))))
2987 (defun gnus-mime-copy-part (&optional handle)
2988 "Put the the MIME part under point into a new buffer."
2990 (gnus-article-check-buffer)
2991 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2992 (contents (mm-get-part handle))|
2993 (base (file-name-nondirectory
2995 (mail-content-type-get (mm-handle-type handle) 'name)
2996 (mail-content-type-get (mm-handle-type handle)
2999 (buffer (generate-new-buffer base)))
3000 (switch-to-buffer buffer)
3002 ;; We do it this way to make `normal-mode' set the appropriate mode.
3005 (setq buffer-file-name (expand-file-name base))
3007 (setq buffer-file-name nil))
3008 (goto-char (point-min))))
3010 (defun gnus-mime-inline-part (&optional handle)
3011 "Insert the MIME part under point into the current buffer."
3013 (gnus-article-check-buffer)
3014 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3018 (if (mm-handle-undisplayer handle)
3019 (mm-remove-part handle)
3020 (setq contents (mm-get-part handle))
3022 ((not current-prefix-arg)
3023 (setq charset (or (mail-content-type-get
3024 (mm-handle-type handle) 'charset)
3025 gnus-newsgroup-charset)))
3026 ((numberp current-prefix-arg)
3028 (or (cdr (assq current-prefix-arg
3029 gnus-summary-show-article-charset-alist))
3030 (read-coding-system "Charset: ")))))
3032 (mm-insert-inline handle (if charset
3033 (mm-decode-coding-string contents charset)
3037 (defun gnus-mime-externalize-part (&optional handle)
3038 "View the MIME part under point with an external viewer."
3040 (gnus-article-check-buffer)
3041 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3042 (mm-user-display-methods nil)
3043 (mm-inlined-types nil)
3044 (mail-parse-charset gnus-newsgroup-charset)
3045 (mail-parse-ignored-charsets
3046 (save-excursion (set-buffer gnus-summary-buffer)
3047 gnus-newsgroup-ignored-charsets)))
3048 (if (mm-handle-undisplayer handle)
3049 (mm-remove-part handle)
3050 (mm-display-part handle))))
3052 (defun gnus-mime-internalize-part (&optional handle)
3053 "View the MIME part under point with an internal viewer.
3054 In no internal viewer is available, use an external viewer."
3056 (gnus-article-check-buffer)
3057 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3058 (mm-inlined-types '(".*"))
3059 (mm-inline-large-images t)
3060 (mail-parse-charset gnus-newsgroup-charset)
3061 (mail-parse-ignored-charsets
3062 (save-excursion (set-buffer gnus-summary-buffer)
3063 gnus-newsgroup-ignored-charsets)))
3064 (if (mm-handle-undisplayer handle)
3065 (mm-remove-part handle)
3066 (mm-display-part handle))))
3068 (defun gnus-article-part-wrapper (n function)
3069 (save-current-buffer
3070 (set-buffer gnus-article-buffer)
3071 (when (> n (length gnus-article-mime-handle-alist))
3072 (error "No such part"))
3073 (gnus-article-goto-part n)
3074 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3075 (funcall function handle))))
3077 (defun gnus-article-pipe-part (n)
3078 "Pipe MIME part N, which is the numerical prefix."
3080 (gnus-article-part-wrapper n 'mm-pipe-part))
3082 (defun gnus-article-save-part (n)
3083 "Save MIME part N, which is the numerical prefix."
3085 (gnus-article-part-wrapper n 'mm-save-part))
3087 (defun gnus-article-interactively-view-part (n)
3088 "View MIME part N interactively, which is the numerical prefix."
3090 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3092 (defun gnus-article-copy-part (n)
3093 "Copy MIME part N, which is the numerical prefix."
3095 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3097 (defun gnus-article-externalize-part (n)
3098 "View MIME part N externally, which is the numerical prefix."
3100 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3102 (defun gnus-article-inline-part (n)
3103 "Inline MIME part N, which is the numerical prefix."
3105 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3107 (defun gnus-article-mime-match-handle-first (condition)
3109 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3110 (while (setq ihandle (pop alist))
3112 ((functionp condition)
3113 (funcall condition (cdr ihandle)))
3114 ((eq condition 'undisplayed)
3115 (not (or (mm-handle-undisplayer (cdr ihandle))
3116 (equal (mm-handle-media-type (cdr ihandle))
3117 "multipart/alternative"))))
3118 ((eq condition 'undisplayed-alternative)
3119 (not (mm-handle-undisplayer (cdr ihandle))))
3121 (gnus-article-goto-part (car ihandle))
3122 (or (not n) (< (car ihandle) n)))
3123 (setq n (car ihandle))))
3127 (defun gnus-article-view-part (&optional n)
3128 "View MIME part N, which is the numerical prefix."
3130 (save-current-buffer
3131 (set-buffer gnus-article-buffer)
3132 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3133 gnus-article-mime-match-handle-function)))
3134 (when (> n (length gnus-article-mime-handle-alist))
3135 (error "No such part"))
3136 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3137 (when (gnus-article-goto-part n)
3138 (if (equal (car handle) "multipart/alternative")
3139 (gnus-article-press-button)
3140 (when (eq (gnus-mm-display-part handle) 'internal)
3141 (gnus-set-window-start)))))))
3143 (defun gnus-mm-display-part (handle)
3144 "Display HANDLE and fix MIME button."
3145 (let ((id (get-text-property (point) 'gnus-part))
3150 (let ((window (selected-window))
3151 (mail-parse-charset gnus-newsgroup-charset)
3152 (mail-parse-ignored-charsets
3153 (save-excursion (set-buffer gnus-summary-buffer)
3154 gnus-newsgroup-ignored-charsets)))
3157 (let ((win (get-buffer-window (current-buffer) t))
3160 (select-window win))
3163 (if (mm-handle-displayed-p handle)
3164 ;; This will remove the part.
3165 (mm-display-part handle)
3167 (narrow-to-region (point) (1+ (point)))
3168 (mm-display-part handle)
3169 ;; We narrow to the part itself and
3170 ;; then call the treatment functions.
3171 (goto-char (point-min))
3173 (narrow-to-region (point) (point-max))
3176 (1- (length gnus-article-mime-handles))
3177 (mm-handle-media-type handle)))))
3178 (select-window window))))
3180 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3181 (gnus-insert-mime-button
3182 handle id (list (mm-handle-displayed-p handle)))
3183 (goto-char point))))
3185 (defun gnus-article-goto-part (n)
3186 "Go to MIME part N."
3187 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3189 (goto-char point))))
3191 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3192 (let ((gnus-tmp-name
3193 (or (mail-content-type-get (mm-handle-type handle)
3195 (mail-content-type-get (mm-handle-disposition handle)
3198 (gnus-tmp-type (mm-handle-media-type handle))
3199 (gnus-tmp-description
3200 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3203 (if (if displayed (car displayed)
3204 (mm-handle-displayed-p handle))
3206 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3208 gnus-tmp-type-long b e)
3209 (when (string-match ".*/" gnus-tmp-name)
3210 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3211 (setq gnus-tmp-type-long (concat gnus-tmp-type
3212 (and (not (equal gnus-tmp-name ""))
3213 (concat "; " gnus-tmp-name))))
3214 (or (equal gnus-tmp-description "")
3215 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3220 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3221 `(local-map ,gnus-mime-button-map
3222 keymap ,gnus-mime-button-map
3223 gnus-callback gnus-mm-display-part
3224 gnus-part ,gnus-tmp-id
3225 article-type annotation
3228 (widget-convert-button
3231 :action 'gnus-widget-press-button
3232 :button-keymap gnus-mime-button-map
3234 (lambda (widget/window &optional overlay pos)
3235 ;; Needed to properly clear the message due to a bug in
3236 ;; wid-edit (XEmacs only).
3237 (if (boundp 'help-echo-owns-message)
3238 (setq help-echo-owns-message t))
3240 "%S: %s the MIME part; %S: more options"
3241 (aref gnus-mouse-2 0)
3242 ;; XEmacs will get a single widget arg; Emacs 21 will get
3243 ;; window, overlay, position.
3244 (if (mm-handle-displayed-p
3246 (with-current-buffer (overlay-buffer overlay)
3247 (widget-get (widget-at (overlay-start overlay))
3249 (widget-get widget/window :mime-handle)))
3251 (aref gnus-down-mouse-3 0))))))
3253 (defun gnus-widget-press-button (elems el)
3254 (goto-char (widget-get elems :from))
3255 (gnus-article-press-button))
3257 (defvar gnus-displaying-mime nil)
3259 (defun gnus-display-mime (&optional ihandles)
3260 "Display the MIME parts."
3262 (save-selected-window
3263 (let ((window (get-buffer-window gnus-article-buffer))
3266 (select-window window)
3267 ;; We have to do this since selecting the window
3268 ;; may change the point. So we set the window point.
3269 (set-window-point window point)))
3270 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3271 buffer-read-only handle name type b e display)
3272 (when (and (not ihandles)
3273 (not gnus-displaying-mime))
3274 ;; Top-level call; we clean up.
3275 (when gnus-article-mime-handles
3276 (mm-destroy-parts gnus-article-mime-handles)
3277 (setq gnus-article-mime-handle-alist nil));; A trick.
3278 (setq gnus-article-mime-handles handles)
3279 ;; We allow users to glean info from the handles.
3280 (when gnus-article-mime-part-function
3281 (gnus-mime-part-function handles)))
3283 (or (not (stringp (car handles)))
3286 (when (and (not ihandles)
3287 (not gnus-displaying-mime))
3288 ;; Clean up for mime parts.
3290 (delete-region (point) (point-max)))
3291 (let ((gnus-displaying-mime t))
3292 (gnus-mime-display-part handles)))
3295 (narrow-to-region (point) (point-max))
3296 (gnus-treat-article nil 1 1)
3299 ;; Highlight the headers.
3303 (narrow-to-region (point-min) (point))
3304 (gnus-treat-article 'head))))))))
3306 (defvar gnus-mime-display-multipart-as-mixed nil)
3308 (defun gnus-mime-display-part (handle)
3311 ((not (stringp (car handle)))
3312 (gnus-mime-display-single handle))
3313 ;; User-defined multipart
3314 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3315 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3317 ;; multipart/alternative
3318 ((and (equal (car handle) "multipart/alternative")
3319 (not gnus-mime-display-multipart-as-mixed))
3320 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3321 (push (cons id handle) gnus-article-mime-handle-alist)
3322 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3323 ;; multipart/related
3324 ((and (equal (car handle) "multipart/related")
3325 (not gnus-mime-display-multipart-as-mixed))
3326 ;;;!!!We should find the start part, but we just default
3327 ;;;!!!to the first part.
3328 (gnus-mime-display-part (cadr handle)))
3329 ;; Other multiparts are handled like multipart/mixed.
3331 (gnus-mime-display-mixed (cdr handle)))))
3333 (defun gnus-mime-part-function (handles)
3334 (if (stringp (car handles))
3335 (mapcar 'gnus-mime-part-function (cdr handles))
3336 (funcall gnus-article-mime-part-function handles)))
3338 (defun gnus-mime-display-mixed (handles)
3339 (mapcar 'gnus-mime-display-part handles))
3341 (defun gnus-mime-display-single (handle)
3342 (let ((type (mm-handle-media-type handle))
3343 (ignored gnus-ignored-mime-types)
3350 (when (string-match (pop ignored) type)
3351 (throw 'ignored nil)))
3352 (if (and (setq not-attachment
3353 (and (not (mm-inline-override-p handle))
3354 (or (not (mm-handle-disposition handle))
3355 (equal (car (mm-handle-disposition handle))
3357 (mm-attachment-override-p handle))))
3358 (mm-automatic-display-p handle)
3359 (or (mm-inlined-p handle)
3360 (mm-automatic-external-display-p type)))
3362 (when (equal (mm-handle-media-supertype handle) "text")
3364 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3365 (push (cons id handle) gnus-article-mime-handle-alist)
3366 (when (or (not display)
3367 (not (gnus-unbuttonized-mime-type-p type)))
3368 ;(gnus-article-insert-newline)
3369 (gnus-insert-mime-button
3370 handle id (list (or display (and not-attachment text))))
3371 (gnus-article-insert-newline)
3372 ;(gnus-article-insert-newline)
3374 (let ((beg (point)))
3380 (let ((mail-parse-charset gnus-newsgroup-charset)
3381 (mail-parse-ignored-charsets
3382 (save-excursion (condition-case ()
3383 (set-buffer gnus-summary-buffer)
3385 gnus-newsgroup-ignored-charsets)))
3386 (mm-display-part handle t))
3387 (goto-char (point-max)))
3388 ((and text not-attachment)
3392 (gnus-article-insert-newline)
3393 (mm-insert-inline handle (mm-get-part handle))
3394 (goto-char (point-max))))
3398 (narrow-to-region beg (point))
3400 nil (length gnus-article-mime-handle-alist)
3401 (1- (length gnus-article-mime-handles))
3402 (mm-handle-media-type handle)))))))))
3404 (defun gnus-unbuttonized-mime-type-p (type)
3405 "Say whether TYPE is to be unbuttonized."
3406 (unless gnus-inhibit-mime-unbuttonizing
3408 (let ((types gnus-unbuttonized-mime-types))
3410 (when (string-match (pop types) type)
3411 (throw 'found t)))))))
3413 (defun gnus-article-insert-newline ()
3414 "Insert a newline, but mark it as undeletable."
3415 (gnus-put-text-property
3416 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3418 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3419 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3422 handle buffer-read-only from props begend not-pref)
3423 (save-window-excursion
3426 (narrow-to-region (car ibegend)
3429 (goto-char (car ibegend))
3432 (delete-region (point-min) (point-max))
3433 (mm-remove-parts handles))
3434 (setq begend (list (point-marker)))
3436 (unless (setq not-pref (cadr (member preferred ihandles)))
3437 (setq not-pref (car ihandles)))
3439 (not (gnus-unbuttonized-mime-type-p
3440 "multipart/alternative")))
3441 (gnus-add-text-properties
3444 (insert (format "%d. " id))
3448 (unless ,(not ibegend)
3449 (setq gnus-article-mime-handle-alist
3450 ',gnus-article-mime-handle-alist))
3451 (gnus-mime-display-alternative
3452 ',ihandles ',not-pref ',begend ,id))
3453 local-map ,gnus-mime-button-map
3454 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3455 face ,gnus-article-button-face
3456 keymap ,gnus-mime-button-map
3459 (widget-convert-button 'link from (point)
3460 :action 'gnus-widget-press-button
3461 :button-keymap gnus-widget-button-keymap)
3463 (while (setq handle (pop handles))
3464 (gnus-add-text-properties
3467 (insert (format "(%c) %-18s"
3468 (if (equal handle preferred) ?* ? )
3469 (mm-handle-media-type handle)))
3473 (unless ,(not ibegend)
3474 (setq gnus-article-mime-handle-alist
3475 ',gnus-article-mime-handle-alist))
3476 (gnus-mime-display-alternative
3477 ',ihandles ',handle ',begend ,id))
3478 local-map ,gnus-mime-button-map
3479 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3480 face ,gnus-article-button-face
3481 keymap ,gnus-mime-button-map
3484 (widget-convert-button 'link from (point)
3485 :action 'gnus-widget-press-button
3486 :button-keymap gnus-widget-button-keymap)
3490 (if (stringp (car preferred))
3491 (gnus-display-mime preferred)
3492 (let ((mail-parse-charset gnus-newsgroup-charset)
3493 (mail-parse-ignored-charsets
3494 (save-excursion (set-buffer gnus-summary-buffer)
3495 gnus-newsgroup-ignored-charsets)))
3496 (mm-display-part preferred)
3500 (narrow-to-region (car begend) (point-max))
3502 nil (length gnus-article-mime-handle-alist)
3503 (1- (length gnus-article-mime-handles))
3504 (mm-handle-media-type handle))))))
3505 (goto-char (point-max))
3506 (setcdr begend (point-marker)))))
3508 (goto-char point))))
3510 (defun gnus-article-wash-status ()
3511 "Return a string which display status of article washing."
3513 (set-buffer gnus-article-buffer)
3514 (let ((cite (memq 'cite gnus-article-wash-types))
3515 (headers (memq 'headers gnus-article-wash-types))
3516 (boring (memq 'boring-headers gnus-article-wash-types))
3517 (pgp (memq 'pgp gnus-article-wash-types))
3518 (pem (memq 'pem gnus-article-wash-types))
3519 (signature (memq 'signature gnus-article-wash-types))
3520 (overstrike (memq 'overstrike gnus-article-wash-types))
3521 (emphasis (memq 'emphasis gnus-article-wash-types)))
3522 (format "%c%c%c%c%c%c"
3524 (if (or headers boring) ?h ? )
3525 (if (or pgp pem) ?p ? )
3526 (if signature ?s ? )
3527 (if overstrike ?o ? )
3528 (if emphasis ?e ? )))))
3530 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3532 (defun gnus-article-maybe-hide-headers ()
3533 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3534 Provided for backwards compatibility."
3535 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3536 (not (save-excursion (set-buffer gnus-summary-buffer)
3537 gnus-have-all-headers)))
3538 (not gnus-inhibit-hiding))
3539 (gnus-article-hide-headers)))
3543 (defun gnus-output-to-file (file-name)
3544 "Append the current article to a file named FILE-NAME."
3545 (let ((artbuf (current-buffer)))
3547 (insert-buffer-substring artbuf)
3548 ;; Append newline at end of the buffer as separator, and then
3550 (goto-char (point-max))
3552 (mm-append-to-file (point-min) (point-max) file-name)
3555 (defun gnus-narrow-to-page (&optional arg)
3556 "Narrow the article buffer to a page.
3557 If given a numerical ARG, move forward ARG pages."
3559 (setq arg (if arg (prefix-numeric-value arg) 0))
3561 (set-buffer gnus-article-buffer)
3562 (goto-char (point-min))
3564 ;; Remove any old next/prev buttons.
3565 (when (gnus-visual-p 'page-marker)
3566 (let ((buffer-read-only nil))
3567 (gnus-remove-text-with-property 'gnus-prev)
3568 (gnus-remove-text-with-property 'gnus-next)))
3571 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3573 (re-search-forward page-delimiter nil 'move arg)))
3574 (goto-char (match-end 0)))
3577 (if (re-search-forward page-delimiter nil 'move)
3580 (when (and (gnus-visual-p 'page-marker)
3581 (not (= (point-min) 1)))
3583 (goto-char (point-min))
3584 (gnus-insert-prev-page-button)))
3585 (when (and (gnus-visual-p 'page-marker)
3586 (< (+ (point-max) 2) (buffer-size)))
3588 (goto-char (point-max))
3589 (gnus-insert-next-page-button)))))
3591 ;; Article mode commands
3593 (defun gnus-article-goto-next-page ()
3594 "Show the next page of the article."
3596 (when (gnus-article-next-page)
3597 (goto-char (point-min))
3598 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3600 (defun gnus-article-goto-prev-page ()
3601 "Show the next page of the article."
3603 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3604 (gnus-article-prev-page nil)))
3606 (defun gnus-article-next-page (&optional lines)
3607 "Show the next page of the current article.
3608 If end of article, return non-nil. Otherwise return nil.
3609 Argument LINES specifies lines to be scrolled up."
3611 (move-to-window-line -1)
3614 (and (pos-visible-in-window-p) ;Not continuation line.
3616 ;; Nothing in this page.
3617 (if (or (not gnus-page-broken)
3620 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3622 (gnus-narrow-to-page 1) ;Go to next page.
3624 ;; More in this page.
3625 (let ((scroll-in-place nil))
3629 ;; Long lines may cause an end-of-buffer error.
3630 (goto-char (point-max)))))
3631 (move-to-window-line 0)
3634 (defun gnus-article-prev-page (&optional lines)
3635 "Show previous page of current article.
3636 Argument LINES specifies lines to be scrolled down."
3638 (move-to-window-line 0)
3639 (if (and gnus-page-broken
3641 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3643 (gnus-narrow-to-page -1) ;Go to previous page.
3644 (goto-char (point-max))
3646 (let ((scroll-in-place nil))
3650 (beginning-of-buffer
3651 (goto-char (point-min))))
3652 (move-to-window-line 0)))))
3654 (defun gnus-article-refer-article ()
3655 "Read article specified by message-id around point."
3657 (let ((point (point)))
3658 (search-forward ">" nil t) ;Move point to end of "<....>".
3659 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3660 (let ((message-id (match-string 1)))
3662 (set-buffer gnus-summary-buffer)
3663 (gnus-summary-refer-article message-id))
3665 (error "No references around point"))))
3667 (defun gnus-article-show-summary ()
3668 "Reconfigure windows to show summary buffer."
3670 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3671 (error "There is no summary buffer for this article buffer")
3672 (gnus-article-set-globals)
3673 (gnus-configure-windows 'article)
3674 (gnus-summary-goto-subject gnus-current-article)
3675 (gnus-summary-position-point)))
3677 (defun gnus-article-describe-briefly ()
3678 "Describe article mode commands briefly."
3680 (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")))
3682 (defun gnus-article-summary-command ()
3683 "Execute the last keystroke in the summary buffer."
3685 (let ((obuf (current-buffer))
3686 (owin (current-window-configuration))
3688 (switch-to-buffer gnus-article-current-summary 'norecord)
3689 (setq func (lookup-key (current-local-map) (this-command-keys)))
3690 (call-interactively func)
3692 (set-window-configuration owin)
3693 (set-window-point (get-buffer-window (current-buffer)) (point))))
3695 (defun gnus-article-summary-command-nosave ()
3696 "Execute the last keystroke in the summary buffer."
3699 (pop-to-buffer gnus-article-current-summary 'norecord)
3700 (setq func (lookup-key (current-local-map) (this-command-keys)))
3701 (call-interactively func)))
3703 (defun gnus-article-check-buffer ()
3704 "Beep if not in an article buffer."
3705 (unless (equal major-mode 'gnus-article-mode)
3706 (error "Command invoked outside of a Gnus article buffer")))
3708 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3709 "Read a summary buffer key sequence and execute it from the article buffer."
3711 (gnus-article-check-buffer)
3713 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3714 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3715 "=" "^" "\M-^" "|"))
3721 '("n" "Gn" "p" "Gp"))
3724 (set-buffer gnus-article-current-summary)
3725 (let (gnus-pick-mode)
3726 (push (or key last-command-event) unread-command-events)
3727 (setq keys (if gnus-xemacs
3728 (events-to-keys (read-key-sequence nil))
3729 (read-key-sequence nil)))))
3733 (if (or (member keys nosaves)
3734 (member keys nosave-but-article)
3735 (member keys nosave-in-article))
3737 (save-window-excursion
3738 (pop-to-buffer gnus-article-current-summary 'norecord)
3739 ;; We disable the pick minor mode commands.
3740 (let (gnus-pick-mode)
3741 (setq func (lookup-key (current-local-map) keys))))
3745 (unless (member keys nosave-in-article)
3746 (set-buffer gnus-article-current-summary))
3747 (call-interactively func)
3748 (setq new-sum-point (point)))
3749 (when (member keys nosave-but-article)
3750 (pop-to-buffer gnus-article-buffer 'norecord)))
3751 ;; These commands should restore window configuration.
3752 (let ((obuf (current-buffer))
3753 (owin (current-window-configuration))
3755 (summary gnus-article-current-summary)
3756 func in-buffer selected)
3757 (if not-restore-window
3758 (pop-to-buffer summary 'norecord)
3759 (switch-to-buffer summary 'norecord))
3760 (setq in-buffer (current-buffer))
3761 ;; We disable the pick minor mode commands.
3762 (if (setq func (let (gnus-pick-mode)
3763 (lookup-key (current-local-map) keys)))
3765 (call-interactively func)
3766 (setq new-sum-point (point)))
3768 (when (eq in-buffer (current-buffer))
3769 (setq selected (gnus-summary-select-article))
3771 (unless not-restore-window
3772 (set-window-configuration owin))
3773 (when (eq selected 'old)
3775 (set-window-start (get-buffer-window (current-buffer))
3777 (set-window-point (get-buffer-window (current-buffer))
3779 (let ((win (get-buffer-window gnus-article-current-summary)))
3781 (set-window-point win new-sum-point))))))))
3783 (defun gnus-article-hide (&optional arg force)
3784 "Hide all the gruft in the current article.
3785 This means that PGP stuff, signatures, cited text and (some)
3786 headers will be hidden.
3787 If given a prefix, show the hidden text instead."
3788 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3789 (gnus-article-hide-headers arg)
3790 (gnus-article-hide-list-identifiers arg)
3791 (gnus-article-hide-pgp arg)
3792 (gnus-article-hide-citation-maybe arg force)
3793 (gnus-article-hide-signature arg))
3795 (defun gnus-article-maybe-highlight ()
3796 "Do some article highlighting if article highlighting is requested."
3797 (when (gnus-visual-p 'article-highlight 'highlight)
3798 (gnus-article-highlight-some)))
3800 (defun gnus-check-group-server ()
3801 ;; Make sure the connection to the server is alive.
3802 (unless (gnus-server-opened
3803 (gnus-find-method-for-group gnus-newsgroup-name))
3804 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3805 (gnus-request-group gnus-newsgroup-name t)))
3807 (defun gnus-request-article-this-buffer (article group)
3808 "Get an article and insert it into this buffer."
3809 (let (do-update-line sparse-header)
3813 (gnus-kill-all-overlays)
3814 (setq group (or group gnus-newsgroup-name))
3816 ;; Using `gnus-request-article' directly will insert the article into
3817 ;; `nntp-server-buffer' - so we'll save some time by not having to
3818 ;; copy it from the server buffer into the article buffer.
3820 ;; We only request an article by message-id when we do not have the
3821 ;; headers for it, so we'll have to get those.
3822 (when (stringp article)
3823 (gnus-read-header article))
3825 ;; If the article number is negative, that means that this article
3826 ;; doesn't belong in this newsgroup (possibly), so we find its
3827 ;; message-id and request it by id instead of number.
3828 (when (and (numberp article)
3830 (get-buffer gnus-summary-buffer)
3831 (gnus-buffer-exists-p gnus-summary-buffer))
3833 (set-buffer gnus-summary-buffer)
3834 (let ((header (gnus-summary-article-header article)))
3837 ((memq article gnus-newsgroup-sparse)
3838 ;; This is a sparse gap article.
3839 (setq do-update-line article)
3840 (setq article (mail-header-id header))
3841 (setq sparse-header (gnus-read-header article))
3842 (setq gnus-newsgroup-sparse
3843 (delq article gnus-newsgroup-sparse)))
3845 ;; It's a real article.
3846 (setq article (mail-header-id header)))
3848 ;; It is an extracted pseudo-article.
3849 (setq article 'pseudo)
3850 (gnus-request-pseudo-article header))))
3852 (let ((method (gnus-find-method-for-group
3853 gnus-newsgroup-name)))
3854 (when (and (eq (car method) 'nneething)
3856 (let ((dir (expand-file-name
3857 (mail-header-subject header)
3858 (file-name-as-directory
3859 (or (cadr (assq 'nneething-address method))
3861 (when (file-directory-p dir)
3862 (setq article 'nneething)
3863 (gnus-group-enter-directory dir))))))))
3866 ;; Refuse to select canceled articles.
3867 ((and (numberp article)
3869 (get-buffer gnus-summary-buffer)
3870 (gnus-buffer-exists-p gnus-summary-buffer)
3871 (eq (cdr (save-excursion
3872 (set-buffer gnus-summary-buffer)
3873 (assq article gnus-newsgroup-reads)))
3874 gnus-canceled-mark))
3876 ;; We first check `gnus-original-article-buffer'.
3877 ((and (get-buffer gnus-original-article-buffer)
3880 (set-buffer gnus-original-article-buffer)
3881 (and (equal (car gnus-original-article) group)
3882 (eq (cdr gnus-original-article) article))))
3883 (insert-buffer-substring gnus-original-article-buffer)
3885 ;; Check the backlog.
3886 ((and gnus-keep-backlog
3887 (gnus-backlog-request-article group article (current-buffer)))
3889 ;; Check asynchronous pre-fetch.
3890 ((gnus-async-request-fetched-article group article (current-buffer))
3891 (gnus-async-prefetch-next group article gnus-summary-buffer)
3892 (when (and (numberp article) gnus-keep-backlog)
3893 (gnus-backlog-enter-article group article (current-buffer)))
3896 ((and gnus-use-cache
3898 (gnus-cache-request-article article group))
3900 ;; Get the article and put into the article buffer.
3901 ((or (stringp article)
3903 (let ((gnus-override-method gnus-override-method)
3904 (methods (and (stringp article)
3905 gnus-refer-article-method))
3907 (buffer-read-only nil))
3912 (when (and (null gnus-override-method)
3914 (setq gnus-override-method (pop methods)))
3916 (when (eq gnus-override-method 'current)
3917 (setq gnus-override-method gnus-current-select-method))
3919 (gnus-kill-all-overlays)
3920 (let ((gnus-newsgroup-name group))
3921 (gnus-check-group-server))
3922 (when (gnus-request-article article group (current-buffer))
3923 (when (numberp article)
3924 (gnus-async-prefetch-next group article
3925 gnus-summary-buffer)
3926 (when gnus-keep-backlog
3927 (gnus-backlog-enter-article
3928 group article (current-buffer))))
3929 (setq result 'article))
3932 (setq gnus-override-method (pop methods))
3933 (setq result 'done))))
3934 (and (eq result 'article) 'article)))
3938 ;; Associate this article with the current summary buffer.
3939 (setq gnus-article-current-summary gnus-summary-buffer)
3941 ;; Take the article from the original article buffer
3942 ;; and place it in the buffer it's supposed to be in.
3943 (when (and (get-buffer gnus-article-buffer)
3944 (equal (buffer-name (current-buffer))
3945 (buffer-name (get-buffer gnus-article-buffer))))
3947 (if (get-buffer gnus-original-article-buffer)
3948 (set-buffer gnus-original-article-buffer)
3949 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3950 (buffer-disable-undo)
3951 (setq major-mode 'gnus-original-article-mode)
3952 (setq buffer-read-only t))
3953 (let (buffer-read-only)
3955 (insert-buffer-substring gnus-article-buffer))
3956 (setq gnus-original-article (cons group article)))
3959 (run-hooks 'gnus-article-decode-hook)
3960 ;; Mark article as decoded or not.
3961 (setq gnus-article-decoded-p gnus-article-decode-hook))
3963 ;; Update sparse articles.
3964 (when (and do-update-line
3965 (or (numberp article)
3967 (let ((buf (current-buffer)))
3968 (set-buffer gnus-summary-buffer)
3969 (gnus-summary-update-article do-update-line sparse-header)
3970 (gnus-summary-goto-subject do-update-line nil t)
3971 (set-window-point (get-buffer-window (current-buffer) t)
3973 (set-buffer buf))))))
3979 (defcustom gnus-article-edit-mode-hook nil
3980 "Hook run in article edit mode buffers."
3981 :group 'gnus-article-various
3984 (defvar gnus-article-edit-done-function nil)
3986 (defvar gnus-article-edit-mode-map nil)
3988 ;; Should we be using derived.el for this?
3989 (unless gnus-article-edit-mode-map
3990 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3991 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3993 (gnus-define-keys gnus-article-edit-mode-map
3994 "\C-c\C-c" gnus-article-edit-done
3995 "\C-c\C-k" gnus-article-edit-exit)
3997 (gnus-define-keys (gnus-article-edit-wash-map
3998 "\C-c\C-w" gnus-article-edit-mode-map)
3999 "f" gnus-article-edit-full-stops))
4001 (defun gnus-article-edit-mode ()
4002 "Major mode for editing articles.
4003 This is an extended text-mode.
4005 \\{gnus-article-edit-mode-map}"
4007 (setq major-mode 'gnus-article-edit-mode)
4008 (setq mode-name "Article Edit")
4009 (use-local-map gnus-article-edit-mode-map)
4010 (make-local-variable 'gnus-article-edit-done-function)
4011 (make-local-variable 'gnus-prev-winconf)
4012 (setq buffer-read-only nil)
4013 (buffer-enable-undo)
4015 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4017 (defun gnus-article-edit (&optional force)
4018 "Edit the current article.
4019 This will have permanent effect only in mail groups.
4020 If FORCE is non-nil, allow editing of articles even in read-only
4023 (when (and (not force)
4024 (gnus-group-read-only-p))
4025 (error "The current newsgroup does not support article editing"))
4026 (gnus-article-date-original)
4027 (gnus-article-edit-article
4029 `(lambda (no-highlight)
4031 (gnus-summary-edit-article-done
4032 ,(or (mail-header-references gnus-current-headers) "")
4033 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4035 (defun gnus-article-edit-article (start-func exit-func)
4036 "Start editing the contents of the current article buffer."
4037 (let ((winconf (current-window-configuration)))
4038 (set-buffer gnus-article-buffer)
4039 (gnus-article-edit-mode)
4040 (funcall start-func)
4041 (gnus-configure-windows 'edit-article)
4042 (setq gnus-article-edit-done-function exit-func)
4043 (setq gnus-prev-winconf winconf)
4044 (gnus-message 6 "C-c C-c to end edits")))
4046 (defun gnus-article-edit-done (&optional arg)
4047 "Update the article edits and exit."
4052 (when (article-goto-body)
4053 (let ((lines (count-lines (point) (point-max)))
4054 (length (- (point-max) (point)))
4055 (case-fold-search t)
4056 (body (copy-marker (point))))
4057 (goto-char (point-min))
4058 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4059 (delete-region (match-beginning 1) (match-end 1))
4060 (insert (number-to-string length)))
4061 (goto-char (point-min))
4062 (when (re-search-forward
4063 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4064 (delete-region (match-beginning 1) (match-end 1))
4065 (insert (number-to-string length)))
4066 (goto-char (point-min))
4067 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4068 (delete-region (match-beginning 1) (match-end 1))
4069 (insert (number-to-string lines)))))))
4070 (let ((func gnus-article-edit-done-function)
4071 (buf (current-buffer))
4072 (start (window-start)))
4073 (gnus-article-edit-exit)
4076 (let ((buffer-read-only nil))
4078 ;; The cache and backlog have to be flushed somewhat.
4079 (when gnus-keep-backlog
4080 (gnus-backlog-remove-article
4081 (car gnus-article-current) (cdr gnus-article-current)))
4082 ;; Flush original article as well.
4084 (when (get-buffer gnus-original-article-buffer)
4085 (set-buffer gnus-original-article-buffer)
4086 (setq gnus-original-article nil)))
4087 (when gnus-use-cache
4088 (gnus-cache-update-article
4089 (car gnus-article-current) (cdr gnus-article-current))))
4091 (set-window-start (get-buffer-window buf) start)
4092 (set-window-point (get-buffer-window buf) (point))))
4094 (defun gnus-article-edit-exit ()
4095 "Exit the article editing without updating."
4097 ;; We remove all text props from the article buffer.
4098 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4099 (curbuf (current-buffer))
4101 (window-start (window-start)))
4104 (let ((winconf gnus-prev-winconf))
4106 (set-window-configuration winconf)
4107 ;; Tippy-toe some to make sure that point remains where it was.
4108 (save-current-buffer
4110 (set-window-start (get-buffer-window (current-buffer)) window-start)
4113 (defun gnus-article-edit-full-stops ()
4114 "Interactively repair spacing at end of sentences."
4117 (goto-char (point-min))
4118 (search-forward-regexp "^$" nil t)
4119 (let ((case-fold-search nil))
4120 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4123 ;;; Article highlights
4126 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4128 ;;; Internal Variables:
4130 (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\\)\\)"
4131 "Regular expression that matches URLs."
4132 :group 'gnus-article-buttons
4135 (defcustom gnus-button-alist
4136 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4137 0 t gnus-button-message-id 2)
4138 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4139 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4141 gnus-button-fetch-group 4)
4142 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4143 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4144 t gnus-button-message-id 3)
4145 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4146 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4147 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4148 ;; This is how URLs _should_ be embedded in text...
4149 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4151 (,gnus-button-url-regexp 0 t browse-url 0))
4152 "*Alist of regexps matching buttons in article bodies.
4154 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4155 REGEXP: is the string matching text around the button,
4156 BUTTON: is the number of the regexp grouping actually matching the button,
4157 FORM: is a lisp expression which must eval to true for the button to
4159 CALLBACK: is the function to call when the user push this button, and each
4160 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4162 CALLBACK can also be a variable, in that case the value of that
4163 variable it the real callback function."
4164 :group 'gnus-article-buttons
4165 :type '(repeat (list regexp
4166 (integer :tag "Button")
4168 (function :tag "Callback")
4171 (integer :tag "Regexp group")))))
4173 (defcustom gnus-header-button-alist
4174 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4175 0 t gnus-button-message-id 0)
4176 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4177 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4178 0 t gnus-button-mailto 0)
4179 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4180 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4181 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4182 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4183 gnus-button-message-id 3))
4184 "*Alist of headers and regexps to match buttons in article heads.
4186 This alist is very similar to `gnus-button-alist', except that each
4187 alist has an additional HEADER element first in each entry:
4189 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4191 HEADER is a regexp to match a header. For a fuller explanation, see
4192 `gnus-button-alist'."
4193 :group 'gnus-article-buttons
4194 :group 'gnus-article-headers
4195 :type '(repeat (list (regexp :tag "Header")
4197 (integer :tag "Button")
4199 (function :tag "Callback")
4202 (integer :tag "Regexp group")))))
4204 (defvar gnus-button-regexp nil)
4205 (defvar gnus-button-marker-list nil)
4206 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4208 (defvar gnus-button-last nil)
4209 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4213 (defun gnus-article-push-button (event)
4214 "Check text under the mouse pointer for a callback function.
4215 If the text under the mouse pointer has a `gnus-callback' property,
4216 call it with the value of the `gnus-data' text property."
4218 (set-buffer (window-buffer (posn-window (event-start event))))
4219 (let* ((pos (posn-point (event-start event)))
4220 (data (get-text-property pos 'gnus-data))
4221 (fun (get-text-property pos 'gnus-callback)))
4224 (funcall fun data))))
4226 (defun gnus-article-press-button ()
4227 "Check text at point for a callback function.
4228 If the text at point has a `gnus-callback' property,
4229 call it with the value of the `gnus-data' text property."
4231 (let* ((data (get-text-property (point) 'gnus-data))
4232 (fun (get-text-property (point) 'gnus-callback)))
4234 (funcall fun data))))
4236 (defun gnus-article-highlight (&optional force)
4237 "Highlight current article.
4238 This function calls `gnus-article-highlight-headers',
4239 `gnus-article-highlight-citation',
4240 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4241 do the highlighting. See the documentation for those functions."
4242 (interactive (list 'force))
4243 (gnus-article-highlight-headers)
4244 (gnus-article-highlight-citation force)
4245 (gnus-article-highlight-signature)
4246 (gnus-article-add-buttons force)
4247 (gnus-article-add-buttons-to-head))
4249 (defun gnus-article-highlight-some (&optional force)
4250 "Highlight current article.
4251 This function calls `gnus-article-highlight-headers',
4252 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4253 do the highlighting. See the documentation for those functions."
4254 (interactive (list 'force))
4255 (gnus-article-highlight-headers)
4256 (gnus-article-highlight-signature)
4257 (gnus-article-add-buttons))
4259 (defun gnus-article-highlight-headers ()
4260 "Highlight article headers as specified by `gnus-header-face-alist'."
4263 (set-buffer gnus-article-buffer)
4265 (let ((alist gnus-header-face-alist)
4266 (buffer-read-only nil)
4267 (case-fold-search t)
4268 (inhibit-point-motion-hooks t)
4269 entry regexp header-face field-face from hpoints fpoints)
4270 (article-narrow-to-head)
4271 (while (setq entry (pop alist))
4272 (goto-char (point-min))
4273 (setq regexp (concat "^\\("
4274 (if (string-equal "" (nth 0 entry))
4278 header-face (nth 1 entry)
4279 field-face (nth 2 entry))
4280 (while (and (re-search-forward regexp nil t)
4284 (unless (search-forward ":" nil t)
4286 (when (and header-face
4287 (not (memq (point) hpoints)))
4288 (push (point) hpoints)
4289 (gnus-put-text-property from (point) 'face header-face))
4290 (when (and field-face
4291 (not (memq (setq from (point)) fpoints)))
4293 (if (re-search-forward "^[^ \t]" nil t)
4295 (goto-char (point-max)))
4296 (gnus-put-text-property from (point) 'face field-face))))))))
4298 (defun gnus-article-highlight-signature ()
4299 "Highlight the signature in an article.
4300 It does this by highlighting everything after
4301 `gnus-signature-separator' using `gnus-signature-face'."
4304 (set-buffer gnus-article-buffer)
4305 (let ((buffer-read-only nil)
4306 (inhibit-point-motion-hooks t))
4308 (when (and gnus-signature-face
4309 (gnus-article-narrow-to-signature))
4310 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4311 'face gnus-signature-face)
4313 (gnus-article-search-signature)
4314 (let ((start (match-beginning 0))
4315 (end (set-marker (make-marker) (1+ (match-end 0)))))
4316 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4319 (defun gnus-button-in-region-p (b e prop)
4320 "Say whether PROP exists in the region."
4321 (text-property-not-all b e prop nil))
4323 (defun gnus-article-add-buttons (&optional force)
4324 "Find external references in the article and make buttons of them.
4325 \"External references\" are things like Message-IDs and URLs, as
4326 specified by `gnus-button-alist'."
4327 (interactive (list 'force))
4329 (set-buffer gnus-article-buffer)
4330 (let ((buffer-read-only nil)
4331 (inhibit-point-motion-hooks t)
4332 (case-fold-search t)
4333 (alist gnus-button-alist)
4335 ;; Remove all old markers.
4336 (let (marker entry new-list)
4337 (while (setq marker (pop gnus-button-marker-list))
4338 (if (or (< marker (point-min)) (>= marker (point-max)))
4339 (push marker new-list)
4341 (when (setq entry (gnus-button-entry))
4342 (put-text-property (match-beginning (nth 1 entry))
4343 (match-end (nth 1 entry))
4344 'gnus-callback nil))
4345 (set-marker marker nil)))
4346 (setq gnus-button-marker-list new-list))
4347 ;; We skip the headers.
4350 (while (setq entry (pop alist))
4351 (setq regexp (car entry))
4353 (while (re-search-forward regexp nil t)
4354 (let* ((start (and entry (match-beginning (nth 1 entry))))
4355 (end (and entry (match-end (nth 1 entry))))
4356 (from (match-beginning 0)))
4357 (when (and (or (eq t (nth 2 entry))
4358 (eval (nth 2 entry)))
4359 (not (gnus-button-in-region-p
4360 start end 'gnus-callback)))
4361 ;; That optional form returned non-nil, so we add the
4363 (gnus-article-add-button
4364 start end 'gnus-button-push
4365 (car (push (set-marker (make-marker) from)
4366 gnus-button-marker-list))))))))))
4368 ;; Add buttons to the head of an article.
4369 (defun gnus-article-add-buttons-to-head ()
4370 "Add buttons to the head of the article."
4373 (set-buffer gnus-article-buffer)
4375 (let ((buffer-read-only nil)
4376 (inhibit-point-motion-hooks t)
4377 (case-fold-search t)
4378 (alist gnus-header-button-alist)
4380 (article-narrow-to-head)
4382 ;; Each alist entry.
4383 (setq entry (car alist)
4385 (goto-char (point-min))
4386 (while (re-search-forward (car entry) nil t)
4387 ;; Each header matching the entry.
4388 (setq beg (match-beginning 0))
4389 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4390 (match-beginning 0))
4393 (while (re-search-forward (nth 1 entry) end t)
4394 ;; Each match within a header.
4395 (let* ((entry (cdr entry))
4396 (start (match-beginning (nth 1 entry)))
4397 (end (match-end (nth 1 entry)))
4398 (form (nth 2 entry)))
4399 (goto-char (match-end 0))
4401 (gnus-article-add-button
4402 start end (nth 3 entry)
4403 (buffer-substring (match-beginning (nth 4 entry))
4404 (match-end (nth 4 entry)))))))
4405 (goto-char end)))))))
4407 ;;; External functions:
4409 (defun gnus-article-add-button (from to fun &optional data)
4410 "Create a button between FROM and TO with callback FUN and data DATA."
4411 (when gnus-article-button-face
4412 (gnus-overlay-put (gnus-make-overlay from to)
4413 'face gnus-article-button-face))
4414 (gnus-add-text-properties
4416 (nconc (and gnus-article-mouse-face
4417 (list gnus-mouse-face-prop gnus-article-mouse-face))
4418 (list 'gnus-callback fun)
4419 (and data (list 'gnus-data data))))
4420 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4421 :button-keymap gnus-widget-button-keymap))
4423 ;;; Internal functions:
4425 (defun gnus-article-set-globals ()
4427 (set-buffer gnus-summary-buffer)
4428 (gnus-set-global-variables)))
4430 (defun gnus-signature-toggle (end)
4432 (set-buffer gnus-article-buffer)
4433 (let ((buffer-read-only nil)
4434 (inhibit-point-motion-hooks t))
4435 (if (get-text-property end 'invisible)
4436 (gnus-article-unhide-text end (point-max))
4437 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4439 (defun gnus-button-entry ()
4440 ;; Return the first entry in `gnus-button-alist' matching this place.
4441 (let ((alist gnus-button-alist)
4444 (setq entry (pop alist))
4445 (if (looking-at (car entry))
4450 (defun gnus-button-push (marker)
4451 ;; Push button starting at MARKER.
4454 (let* ((entry (gnus-button-entry))
4455 (inhibit-point-motion-hooks t)
4457 (args (mapcar (lambda (group)
4458 (let ((string (match-string group)))
4459 (gnus-set-text-properties
4460 0 (length string) nil string)
4467 (fboundp (symbol-value fun)))
4468 (apply (symbol-value fun) args))
4470 (gnus-message 1 "You must define `%S' to use this button"
4471 (cons fun args)))))))
4473 (defun gnus-button-message-id (message-id)
4476 (set-buffer gnus-summary-buffer)
4477 (gnus-summary-refer-article message-id)))
4479 (defun gnus-button-fetch-group (address)
4480 "Fetch GROUP specified by ADDRESS."
4481 (if (not (string-match "[:/]" address))
4482 ;; This is just a simple group url.
4483 (gnus-group-read-ephemeral-group address gnus-select-method)
4484 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4486 (error "Can't parse %s" address)
4487 (gnus-group-read-ephemeral-group
4488 (match-string 4 address)
4489 `(nntp ,(match-string 1 address)
4490 (nntp-address ,(match-string 1 address))
4491 (nntp-port-number ,(if (match-end 3)
4492 (match-string 3 address)
4495 (defun gnus-url-parse-query-string (query &optional downcase)
4496 (let (retval pairs cur key val)
4497 (setq pairs (split-string query "&"))
4499 (setq cur (car pairs)
4501 (if (not (string-match "=" cur))
4503 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4504 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4506 (setq key (downcase key)))
4507 (setq cur (assoc key retval))
4509 (setcdr cur (cons val (cdr cur)))
4510 (setq retval (cons (list key val) retval)))))
4513 (defun gnus-url-unhex (x)
4520 (defun gnus-url-unhex-string (str &optional allow-newlines)
4521 "Remove %XXX embedded spaces, etc in a url.
4522 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4523 decoding of carriage returns and line feeds in the string, which is normally
4524 forbidden in URL encoding."
4525 (setq str (or str ""))
4527 (case-fold-search t))
4528 (while (string-match "%[0-9a-f][0-9a-f]" str)
4529 (let* ((start (match-beginning 0))
4530 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4532 (gnus-url-unhex (elt str (+ start 2))))))
4534 tmp (substring str 0 start)
4537 (char-to-string code))
4538 ((or (= code ?\n) (= code ?\r))
4540 (t (char-to-string code))))
4541 str (substring str (match-end 0)))))
4542 (setq tmp (concat tmp str))
4545 (defun gnus-url-mailto (url)
4546 ;; Send mail to someone
4547 (when (string-match "mailto:/*\\(.*\\)" url)
4548 (setq url (substring url (match-beginning 1) nil)))
4549 (let (to args subject func)
4550 (if (string-match (regexp-quote "?") url)
4551 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4552 args (gnus-url-parse-query-string
4553 (substring url (match-end 0) nil) t))
4554 (setq to (gnus-url-unhex-string url)))
4555 (setq args (cons (list "to" to) args)
4556 subject (cdr-safe (assoc "subject" args)))
4559 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4562 (message-position-on-field (caar args)))
4563 (insert (mapconcat 'identity (cdar args) ", "))
4564 (setq args (cdr args)))
4567 (message-goto-subject))))
4569 (defun gnus-button-mailto (address)
4571 (set-buffer (gnus-copy-article-buffer))
4572 (message-reply address))
4574 (defun gnus-button-reply (address)
4575 ;; Reply to ADDRESS.
4576 (message-reply address))
4578 (defun gnus-button-embedded-url (address)
4580 (browse-url (gnus-strip-whitespace address)))
4582 ;;; Next/prev buttons in the article buffer.
4584 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4585 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4587 (defvar gnus-prev-page-map nil)
4588 (unless gnus-prev-page-map
4589 (setq gnus-prev-page-map (make-sparse-keymap))
4590 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4591 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4593 (defun gnus-insert-prev-page-button ()
4594 (let ((buffer-read-only nil))
4596 gnus-prev-page-line-format nil
4597 `(gnus-prev t local-map ,gnus-prev-page-map
4598 gnus-callback gnus-article-button-prev-page
4599 article-type annotation))))
4601 (defvar gnus-next-page-map nil)
4602 (unless gnus-next-page-map
4603 (setq gnus-next-page-map (make-keymap))
4604 (suppress-keymap gnus-prev-page-map)
4605 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4606 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4608 (defun gnus-button-next-page ()
4609 "Go to the next page."
4611 (let ((win (selected-window)))
4612 (select-window (get-buffer-window gnus-article-buffer t))
4613 (gnus-article-next-page)
4614 (select-window win)))
4616 (defun gnus-button-prev-page ()
4617 "Go to the prev page."
4619 (let ((win (selected-window)))
4620 (select-window (get-buffer-window gnus-article-buffer t))
4621 (gnus-article-prev-page)
4622 (select-window win)))
4624 (defun gnus-insert-next-page-button ()
4625 (let ((buffer-read-only nil))
4626 (gnus-eval-format gnus-next-page-line-format nil
4628 t local-map ,gnus-next-page-map
4629 gnus-callback gnus-article-button-next-page
4630 article-type annotation))))
4632 (defun gnus-article-button-next-page (arg)
4633 "Go to the next page."
4635 (let ((win (selected-window)))
4636 (select-window (get-buffer-window gnus-article-buffer t))
4637 (gnus-article-next-page)
4638 (select-window win)))
4640 (defun gnus-article-button-prev-page (arg)
4641 "Go to the prev page."
4643 (let ((win (selected-window)))
4644 (select-window (get-buffer-window gnus-article-buffer t))
4645 (gnus-article-prev-page)
4646 (select-window win)))
4648 (defvar gnus-decode-header-methods
4649 '(mail-decode-encoded-word-region)
4650 "List of methods used to decode headers.
4652 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4653 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4654 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4655 whose names match REGEXP.
4658 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4659 mail-decode-encoded-word-region
4660 (\"chinese\" . rfc1843-decode-region))
4663 (defvar gnus-decode-header-methods-cache nil)
4665 (defun gnus-multi-decode-header (start end)
4666 "Apply the functions from `gnus-encoded-word-methods' that match."
4667 (unless (and gnus-decode-header-methods-cache
4668 (eq gnus-newsgroup-name
4669 (car gnus-decode-header-methods-cache)))
4670 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4673 (nconc gnus-decode-header-methods-cache (list x))
4674 (if (and gnus-newsgroup-name
4675 (string-match (car x) gnus-newsgroup-name))
4676 (nconc gnus-decode-header-methods-cache
4678 gnus-decode-header-methods))
4679 (let ((xlist gnus-decode-header-methods-cache))
4682 (narrow-to-region start end)
4684 (funcall (pop xlist) (point-min) (point-max))))))
4687 ;;; Treatment top-level handling.
4690 (defun gnus-treat-article (condition &optional part-number total-parts type)
4691 (let ((length (- (point-max) (point-min)))
4692 (alist gnus-treatment-function-alist)
4693 (article-goto-body-goes-to-point-min-p t)
4697 (let ((list gnus-article-treat-types))
4699 (when (string-match (pop list) type)
4700 (throw 'found t)))))))
4701 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4703 (gnus-run-hooks 'gnus-part-display-hook)
4704 (while (setq elem (pop alist))
4707 (if (gnus-buffer-live-p gnus-summary-buffer)
4708 (set-buffer gnus-summary-buffer))
4709 (symbol-value (car elem))))
4710 (when (and (or (consp val)
4712 (gnus-treat-predicate val)
4713 (or (not (get (car elem) 'highlight))
4716 (funcall (cadr elem)))))))
4718 ;; Dynamic variables.
4719 (defvar part-number)
4720 (defvar total-parts)
4724 (defun gnus-treat-predicate (val)
4729 (stringp (car val)))
4730 (apply 'gnus-or (mapcar `(lambda (s)
4731 (string-match s ,(or gnus-newsgroup-name "")))
4734 (let ((pred (pop val)))
4737 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4739 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4741 (not (gnus-treat-predicate (car val))))
4743 (equal (car val) type))
4745 (error "%S is not a valid predicate" pred)))))
4753 (eq part-number total-parts))
4757 (error "%S is not a valid value" val))))
4763 (run-hooks 'gnus-art-load-hook)
4765 ;;; gnus-art.el ends here