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-emphasis-alist
224 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
226 '(("_" "_" underline)
229 ("_/" "/_" underline-italic)
230 ("_\\*" "\\*_" underline-bold)
231 ("\\*/" "/\\*" bold-italic)
232 ("_\\*/" "/\\*_" underline-bold-italic))))
233 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
234 2 3 gnus-emphasis-underline)
238 (format format (car spec) (cadr spec))
239 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
241 "*Alist that says how to fontify certain phrases.
242 Each item looks like this:
244 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
246 The first element is a regular expression to be matched. The second
247 is a number that says what regular expression grouping used to find
248 the entire emphasized word. The third is a number that says what
249 regexp grouping should be displayed and highlighted. The fourth
250 is the face used for highlighting."
251 :type '(repeat (list :value ("" 0 0 default)
253 (integer :tag "Match group")
254 (integer :tag "Emphasize group")
256 :group 'gnus-article-emphasis)
258 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
259 "A regexp to describe whitespace which should not be emphasized.
260 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
261 The former avoids underlining of leading and trailing whitespace,
262 and the latter avoids underlining any whitespace at all."
263 :group 'gnus-article-emphasis
266 (defface gnus-emphasis-bold '((t (:bold t)))
267 "Face used for displaying strong emphasized text (*word*)."
268 :group 'gnus-article-emphasis)
270 (defface gnus-emphasis-italic '((t (:italic t)))
271 "Face used for displaying italic emphasized text (/word/)."
272 :group 'gnus-article-emphasis)
274 (defface gnus-emphasis-underline '((t (:underline t)))
275 "Face used for displaying underlined emphasized text (_word_)."
276 :group 'gnus-article-emphasis)
278 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
279 "Face used for displaying underlined bold emphasized text (_*word*_)."
280 :group 'gnus-article-emphasis)
282 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
283 "Face used for displaying underlined italic emphasized text (_/word/_)."
284 :group 'gnus-article-emphasis)
286 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
287 "Face used for displaying bold italic emphasized text (/*word*/)."
288 :group 'gnus-article-emphasis)
290 (defface gnus-emphasis-underline-bold-italic
291 '((t (:bold t :italic t :underline t)))
292 "Face used for displaying underlined bold italic emphasized text.
293 Esample: (_/*word*/_)."
294 :group 'gnus-article-emphasis)
296 (defface gnus-emphasis-highlight-words
297 '((t (:background "black" :foreground "yellow")))
298 "Face used for displaying highlighted words."
299 :group 'gnus-article-emphasis)
301 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
302 "Format for display of Date headers in article bodies.
303 See `format-time-string' for the possible values.
305 The variable can also be function, which should return a complete Date
306 header. The function is called with one argument, the time, which can
307 be fed to `format-time-string'."
308 :type '(choice string symbol)
309 :link '(custom-manual "(gnus)Article Date")
310 :group 'gnus-article-washing)
313 (autoload 'mail-extract-address-components "mail-extr"))
315 (defcustom gnus-save-all-headers t
316 "*If non-nil, don't remove any headers before saving."
317 :group 'gnus-article-saving
320 (defcustom gnus-prompt-before-saving 'always
321 "*This variable says how much prompting is to be done when saving articles.
322 If it is nil, no prompting will be done, and the articles will be
323 saved to the default files. If this variable is `always', each and
324 every article that is saved will be preceded by a prompt, even when
325 saving large batches of articles. If this variable is neither nil not
326 `always', there the user will be prompted once for a file name for
327 each invocation of the saving commands."
328 :group 'gnus-article-saving
329 :type '(choice (item always)
330 (item :tag "never" nil)
331 (sexp :tag "once" :format "%t\n" :value t)))
333 (defcustom gnus-saved-headers gnus-visible-headers
334 "Headers to keep if `gnus-save-all-headers' is nil.
335 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
336 If that variable is nil, however, all headers that match this regexp
337 will be kept while the rest will be deleted before saving."
338 :group 'gnus-article-saving
341 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
342 "A function to save articles in your favourite format.
343 The function must be interactively callable (in other words, it must
344 be an Emacs command).
346 Gnus provides the following functions:
348 * gnus-summary-save-in-rmail (Rmail format)
349 * gnus-summary-save-in-mail (Unix mail format)
350 * gnus-summary-save-in-folder (MH folder)
351 * gnus-summary-save-in-file (article format)
352 * gnus-summary-save-in-vm (use VM's folder format)
353 * gnus-summary-write-to-file (article format -- overwrite)."
354 :group 'gnus-article-saving
355 :type '(radio (function-item gnus-summary-save-in-rmail)
356 (function-item gnus-summary-save-in-mail)
357 (function-item gnus-summary-save-in-folder)
358 (function-item gnus-summary-save-in-file)
359 (function-item gnus-summary-save-in-vm)
360 (function-item gnus-summary-write-to-file)))
362 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
363 "A function generating a file name to save articles in Rmail format.
364 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
365 :group 'gnus-article-saving
368 (defcustom gnus-mail-save-name 'gnus-plain-save-name
369 "A function generating a file name to save articles in Unix mail format.
370 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
371 :group 'gnus-article-saving
374 (defcustom gnus-folder-save-name 'gnus-folder-save-name
375 "A function generating a file name to save articles in MH folder.
376 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
377 :group 'gnus-article-saving
380 (defcustom gnus-file-save-name 'gnus-numeric-save-name
381 "A function generating a file name to save articles in article format.
382 The function is called with NEWSGROUP, HEADERS, and optional
384 :group 'gnus-article-saving
387 (defcustom gnus-split-methods
388 '((gnus-article-archive-name)
389 (gnus-article-nndoc-name))
390 "*Variable used to suggest where articles are to be saved.
391 For instance, if you would like to save articles related to Gnus in
392 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
393 you could set this variable to something like:
395 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
396 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
398 This variable is an alist where the where the key is the match and the
399 value is a list of possible files to save in if the match is non-nil.
401 If the match is a string, it is used as a regexp match on the
402 article. If the match is a symbol, that symbol will be funcalled
403 from the buffer of the article to be saved with the newsgroup as the
404 parameter. If it is a list, it will be evaled in the same buffer.
406 If this form or function returns a string, this string will be used as
407 a possible file name; and if it returns a non-nil list, that list will
408 be used as possible file names."
409 :group 'gnus-article-saving
410 :type '(repeat (choice (list :value (fun) function)
411 (cons :value ("" "") regexp (repeat string))
414 (defcustom gnus-page-delimiter "^\^L"
415 "*Regexp describing what to use as article page delimiters.
416 The default value is \"^\^L\", which is a form linefeed at the
417 beginning of a line."
419 :group 'gnus-article-various)
421 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
422 "*The format specification for the article mode line.
423 See `gnus-summary-mode-line-format' for a closer description.
425 The following additional specs are available:
427 %w The article washing status.
428 %m The number of MIME parts in the article."
430 :group 'gnus-article-various)
432 (defcustom gnus-article-mode-hook nil
433 "*A hook for Gnus article mode."
435 :group 'gnus-article-various)
437 (defcustom gnus-article-menu-hook nil
438 "*Hook run after the creation of the article mode menu."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-prepare-hook nil
443 "*A hook called after an article has been prepared in the article buffer."
445 :group 'gnus-article-various)
447 (defcustom gnus-article-hide-pgp-hook nil
448 "*A hook called after successfully hiding a PGP signature."
450 :group 'gnus-article-various)
452 (defcustom gnus-article-button-face 'bold
453 "Face used for highlighting buttons in the article buffer.
455 An article button is a piece of text that you can activate by pressing
456 `RET' or `mouse-2' above it."
458 :group 'gnus-article-buttons)
460 (defcustom gnus-article-mouse-face 'highlight
461 "Face used for mouse highlighting in the article buffer.
463 Article buttons will be displayed in this face when the cursor is
466 :group 'gnus-article-buttons)
468 (defcustom gnus-signature-face 'gnus-signature-face
469 "Face used for highlighting a signature in the article buffer.
470 Obsolete; use the face `gnus-signature-face' for customizations instead."
472 :group 'gnus-article-highlight
473 :group 'gnus-article-signature)
475 (defface gnus-signature-face
478 "Face used for highlighting a signature in the article buffer."
479 :group 'gnus-article-highlight
480 :group 'gnus-article-signature)
482 (defface gnus-header-from-face
485 (:foreground "spring green"))
488 (:foreground "red3"))
491 "Face used for displaying from headers."
492 :group 'gnus-article-headers
493 :group 'gnus-article-highlight)
495 (defface gnus-header-subject-face
498 (:foreground "SeaGreen3"))
501 (:foreground "red4"))
503 (:bold t :italic t)))
504 "Face used for displaying subject headers."
505 :group 'gnus-article-headers
506 :group 'gnus-article-highlight)
508 (defface gnus-header-newsgroups-face
511 (:foreground "yellow" :italic t))
514 (:foreground "MidnightBlue" :italic t))
517 "Face used for displaying newsgroups headers."
518 :group 'gnus-article-headers
519 :group 'gnus-article-highlight)
521 (defface gnus-header-name-face
524 (:foreground "SeaGreen"))
527 (:foreground "maroon"))
530 "Face used for displaying header names."
531 :group 'gnus-article-headers
532 :group 'gnus-article-highlight)
534 (defface gnus-header-content-face
537 (:foreground "forest green" :italic t))
540 (:foreground "indianred4" :italic t))
542 (:italic t))) "Face used for displaying header content."
543 :group 'gnus-article-headers
544 :group 'gnus-article-highlight)
546 (defcustom gnus-header-face-alist
547 '(("From" nil gnus-header-from-face)
548 ("Subject" nil gnus-header-subject-face)
549 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
550 ("" gnus-header-name-face gnus-header-content-face))
551 "*Controls highlighting of article header.
553 An alist of the form (HEADER NAME CONTENT).
555 HEADER is a regular expression which should match the name of an
556 header header and NAME and CONTENT are either face names or nil.
558 The name of each header field will be displayed using the face
559 specified by the first element in the list where HEADER match the
560 header name and NAME is non-nil. Similarly, the content will be
561 displayed by the first non-nil matching CONTENT face."
562 :group 'gnus-article-headers
563 :group 'gnus-article-highlight
564 :type '(repeat (list (regexp :tag "Header")
566 (item :tag "skip" nil)
567 (face :value default))
568 (choice :tag "Content"
569 (item :tag "skip" nil)
570 (face :value default)))))
572 (defcustom gnus-article-decode-hook
573 '(article-decode-charset article-decode-encoded-words)
574 "*Hook run to decode charsets in articles."
575 :group 'gnus-article-headers
578 (defcustom gnus-display-mime-function 'gnus-display-mime
579 "Function to display MIME articles."
580 :group 'gnus-article-mime
583 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
584 "Function used to decode headers.")
586 (defvar gnus-article-dumbquotes-map
604 "Table for MS-to-Latin1 translation.")
606 (defcustom gnus-ignored-mime-types nil
607 "List of MIME types that should be ignored by Gnus."
608 :group 'gnus-article-mime
609 :type '(repeat regexp))
611 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
612 "List of MIME types that should not be given buttons when rendered inline."
613 :group 'gnus-article-mime
614 :type '(repeat regexp))
616 (defcustom gnus-article-mime-part-function nil
617 "Function called with a MIME handle as the argument.
618 This is meant for people who want to do something automatic based
619 on parts -- for instance, adding Vcard info to a database."
620 :group 'gnus-article-mime
623 (defcustom gnus-mime-multipart-functions nil
624 "An alist of MIME types to functions to display them.")
626 (defcustom gnus-article-date-lapsed-new-header nil
627 "Whether the X-Sent and Date headers can coexist.
628 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
629 either replace the old \"Date:\" header (if this variable is nil), or
630 be added below it (otherwise)."
631 :group 'gnus-article-headers
634 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
635 "Function called with a MIME handle as the argument.
636 This is meant for people who want to view first matched part.
637 For `undisplayed-alternative' (default), the first undisplayed
638 part or alternative part is used. For `undisplayed', the first
639 undisplayed part is used. For a function, the first part which
640 the function return `t' is used. For `nil', the first part is
642 :group 'gnus-article-mime
644 (item :tag "first" :value nil)
645 (item :tag "undisplayed" :value undisplayed)
646 (item :tag "undisplayed or alternative"
647 :value undisplayed-alternative)
651 ;;; The treatment variables
654 (defvar gnus-part-display-hook nil
655 "Hook called on parts that are to receive treatment.")
657 (defvar gnus-article-treat-custom
658 '(choice (const :tag "Off" nil)
660 (const :tag "Header" head)
661 (const :tag "Last" last)
662 (integer :tag "Less")
663 (repeat :tag "Groups" regexp)
664 (sexp :tag "Predicate")))
666 (defvar gnus-article-treat-head-custom
667 '(choice (const :tag "Off" nil)
668 (const :tag "Header" head)))
670 (defvar gnus-article-treat-types '("text/plain")
673 (defvar gnus-inhibit-treatment nil
674 "Whether to inhibit treatment.")
676 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
677 "Highlight the signature.
678 Valid values are nil, t, `head', `last', an integer or a predicate.
679 See the manual for details."
680 :group 'gnus-article-treat
681 :type gnus-article-treat-custom)
682 (put 'gnus-treat-highlight-signature 'highlight t)
684 (defcustom gnus-treat-buttonize 100000
686 Valid values are nil, t, `head', `last', an integer or a predicate.
687 See the manual for details."
688 :group 'gnus-article-treat
689 :type gnus-article-treat-custom)
690 (put 'gnus-treat-buttonize 'highlight t)
692 (defcustom gnus-treat-buttonize-head 'head
693 "Add buttons to the head.
694 Valid values are nil, t, `head', `last', an integer or a predicate.
695 See the manual for details."
696 :group 'gnus-article-treat
697 :type gnus-article-treat-head-custom)
698 (put 'gnus-treat-buttonize-head 'highlight t)
700 (defcustom gnus-treat-emphasize 50000
702 Valid values are nil, t, `head', `last', an integer or a predicate.
703 See the manual for details."
704 :group 'gnus-article-treat
705 :type gnus-article-treat-custom)
706 (put 'gnus-treat-emphasize 'highlight t)
708 (defcustom gnus-treat-strip-cr nil
709 "Remove carriage returns.
710 Valid values are nil, t, `head', `last', an integer or a predicate.
711 See the manual for details."
712 :group 'gnus-article-treat
713 :type gnus-article-treat-custom)
715 (defcustom gnus-treat-hide-headers 'head
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-head-custom)
722 (defcustom gnus-treat-hide-boring-headers nil
723 "Hide boring headers.
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-signature nil
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-custom)
736 (defcustom gnus-treat-fill-article 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-hide-citation 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-strip-list-identifiers 'head
751 "Strip list identifiers from `gnus-list-identifiers`.
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-pgp t
758 "Strip PGP signatures.
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-pem nil
765 "Strip PEM 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-banner t
772 "Strip banners from articles.
773 The banner to be stripped is specified in the `banner' group parameter.
774 Valid values are nil, t, `head', `last', an integer or a predicate.
775 See the manual for details."
776 :group 'gnus-article-treat
777 :type gnus-article-treat-custom)
779 (defcustom gnus-treat-highlight-headers 'head
780 "Highlight the headers.
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-head-custom)
785 (put 'gnus-treat-highlight-headers 'highlight t)
787 (defcustom gnus-treat-highlight-citation t
788 "Highlight cited text.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
793 (put 'gnus-treat-highlight-citation 'highlight t)
795 (defcustom gnus-treat-date-ut nil
796 "Display the Date in UT (GMT).
797 Valid values are nil, t, `head', `last', an integer or a predicate.
798 See the manual for details."
799 :group 'gnus-article-treat
800 :type gnus-article-treat-head-custom)
802 (defcustom gnus-treat-date-local nil
803 "Display the Date in the local timezone.
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-lapsed nil
810 "Display the Date header in a way that says how much time has elapsed.
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-original nil
817 "Display the date in the original timezone.
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-iso8601 nil
824 "Display the date in the ISO8601 format.
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-user-defined nil
831 "Display the date in a user-defined format.
832 The format is defined by the `gnus-article-time-format' variable.
833 Valid values are nil, t, `head', `last', an integer or a predicate.
834 See the manual for details."
835 :group 'gnus-article-treat
836 :type gnus-article-treat-head-custom)
838 (defcustom gnus-treat-strip-headers-in-body t
839 "Strip the X-No-Archive header line from the beginning of the body.
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-custom)
845 (defcustom gnus-treat-strip-trailing-blank-lines nil
846 "Strip trailing blank lines.
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-leading-blank-lines nil
853 "Strip leading 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-multiple-blank-lines nil
860 "Strip multiple 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-overstrike t
867 "Treat overstrike highlighting.
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)
872 (put 'gnus-treat-overstrike 'highlight t)
874 (defcustom gnus-treat-display-xface
875 (and (or (and (fboundp 'image-type-available-p)
876 (image-type-available-p 'xbm))
877 (and gnus-xemacs (featurep 'xface)))
879 "Display X-Face headers.
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882 :group 'gnus-article-treat
883 :type gnus-article-treat-head-custom)
884 (put 'gnus-treat-display-xface 'highlight t)
886 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
890 Valid values are nil, t, `head', `last', an integer or a predicate.
891 See the manual for details."
892 :group 'gnus-article-treat
893 :type gnus-article-treat-custom)
894 (put 'gnus-treat-display-smileys 'highlight t)
896 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-head-custom)
902 (put 'gnus-treat-display-picons 'highlight t)
904 (defcustom gnus-treat-capitalize-sentences nil
905 "Capitalize sentence-starting words.
906 Valid values are nil, t, `head', `last', an integer or a predicate.
907 See the manual for details."
908 :group 'gnus-article-treat
909 :type gnus-article-treat-custom)
911 (defcustom gnus-treat-fill-long-lines nil
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-play-sounds 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-translate nil
926 "Translate articles from one language to another.
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 ;;; Internal variables
934 (defvar article-goto-body-goes-to-point-min-p nil)
935 (defvar gnus-article-wash-types nil)
936 (defvar gnus-article-emphasis-alist nil)
938 (defvar gnus-article-mime-handle-alist-1 nil)
939 (defvar gnus-treatment-function-alist
940 '((gnus-treat-strip-banner gnus-article-strip-banner)
941 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
942 (gnus-treat-highlight-signature gnus-article-highlight-signature)
943 (gnus-treat-buttonize gnus-article-add-buttons)
944 (gnus-treat-fill-article gnus-article-fill-cited-article)
945 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
946 (gnus-treat-strip-cr gnus-article-remove-cr)
947 (gnus-treat-emphasize gnus-article-emphasize)
948 (gnus-treat-display-xface gnus-article-display-x-face)
949 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
950 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
951 (gnus-treat-hide-signature gnus-article-hide-signature)
952 (gnus-treat-hide-citation gnus-article-hide-citation)
953 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
954 (gnus-treat-strip-pgp gnus-article-hide-pgp)
955 (gnus-treat-strip-pem gnus-article-hide-pem)
956 (gnus-treat-highlight-headers gnus-article-highlight-headers)
957 (gnus-treat-highlight-citation gnus-article-highlight-citation)
958 (gnus-treat-highlight-signature gnus-article-highlight-signature)
959 (gnus-treat-date-ut gnus-article-date-ut)
960 (gnus-treat-date-local gnus-article-date-local)
961 (gnus-treat-date-lapsed gnus-article-date-lapsed)
962 (gnus-treat-date-original gnus-article-date-original)
963 (gnus-treat-date-user-defined gnus-article-date-user)
964 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
965 (gnus-treat-strip-trailing-blank-lines
966 gnus-article-remove-trailing-blank-lines)
967 (gnus-treat-strip-leading-blank-lines
968 gnus-article-strip-leading-blank-lines)
969 (gnus-treat-strip-multiple-blank-lines
970 gnus-article-strip-multiple-blank-lines)
971 (gnus-treat-overstrike gnus-article-treat-overstrike)
972 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
973 (gnus-treat-display-smileys gnus-smiley-display)
974 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
975 (gnus-treat-display-picons gnus-article-display-picons)
976 (gnus-treat-play-sounds gnus-earcon-display)))
978 (defvar gnus-article-mime-handle-alist nil)
979 (defvar article-lapsed-timer nil)
980 (defvar gnus-article-current-summary nil)
982 (defvar gnus-article-mode-syntax-table
983 (let ((table (copy-syntax-table text-mode-syntax-table)))
984 (modify-syntax-entry ?- "w" table)
985 (modify-syntax-entry ?> ")" table)
986 (modify-syntax-entry ?< "(" table)
988 "Syntax table used in article mode buffers.
989 Initialized from `text-mode-syntax-table.")
991 (defvar gnus-save-article-buffer nil)
993 (defvar gnus-article-mode-line-format-alist
994 (nconc '((?w (gnus-article-wash-status) ?s)
995 (?m (gnus-article-mime-part-status) ?s))
996 gnus-summary-mode-line-format-alist))
998 (defvar gnus-number-of-articles-to-be-saved nil)
1000 (defvar gnus-inhibit-hiding nil)
1002 (defsubst gnus-article-hide-text (b e props)
1003 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1004 (add-text-properties b e props)
1005 (when (memq 'intangible props)
1007 (max (1- b) (point-min))
1008 b 'intangible (cddr (memq 'intangible props)))))
1009 (defsubst gnus-article-unhide-text (b e)
1010 "Remove hidden text properties from region between B and E."
1011 (remove-text-properties b e gnus-hidden-properties)
1012 (when (memq 'intangible gnus-hidden-properties)
1013 (put-text-property (max (1- b) (point-min))
1014 b 'intangible nil)))
1016 (defun gnus-article-hide-text-type (b e type)
1017 "Hide text of TYPE between B and E."
1018 (push type gnus-article-wash-types)
1019 (gnus-article-hide-text
1020 b e (cons 'article-type (cons type gnus-hidden-properties))))
1022 (defun gnus-article-unhide-text-type (b e type)
1023 "Unhide text of TYPE between B and E."
1024 (setq gnus-article-wash-types
1025 (delq type gnus-article-wash-types))
1026 (remove-text-properties
1027 b e (cons 'article-type (cons type gnus-hidden-properties)))
1028 (when (memq 'intangible gnus-hidden-properties)
1029 (put-text-property (max (1- b) (point-min))
1030 b 'intangible nil)))
1032 (defun gnus-article-hide-text-of-type (type)
1033 "Hide text of TYPE in the current buffer."
1035 (let ((b (point-min))
1037 (while (setq b (text-property-any b e 'article-type type))
1038 (add-text-properties b (incf b) gnus-hidden-properties)))))
1040 (defun gnus-article-delete-text-of-type (type)
1041 "Delete text of TYPE in the current buffer."
1043 (let ((b (point-min)))
1044 (while (setq b (text-property-any b (point-max) 'article-type type))
1046 b (or (text-property-not-all b (point-max) 'article-type type)
1049 (defun gnus-article-delete-invisible-text ()
1050 "Delete all invisible text in the current buffer."
1052 (let ((b (point-min)))
1053 (while (setq b (text-property-any b (point-max) 'invisible t))
1055 b (or (text-property-not-all b (point-max) 'invisible t)
1058 (defun gnus-article-text-type-exists-p (type)
1059 "Say whether any text of type TYPE exists in the buffer."
1060 (text-property-any (point-min) (point-max) 'article-type type))
1062 (defsubst gnus-article-header-rank ()
1063 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1064 (let ((list gnus-sorted-header-list)
1067 (when (looking-at (car list))
1069 (setq list (cdr list))
1073 (defun article-hide-headers (&optional arg delete)
1074 "Hide unwanted headers and possibly sort them as well."
1076 ;; This function might be inhibited.
1077 (unless gnus-inhibit-hiding
1080 (let ((buffer-read-only nil)
1081 (case-fold-search t)
1082 (max (1+ (length gnus-sorted-header-list)))
1083 (ignored (when (not gnus-visible-headers)
1084 (cond ((stringp gnus-ignored-headers)
1085 gnus-ignored-headers)
1086 ((listp gnus-ignored-headers)
1087 (mapconcat 'identity gnus-ignored-headers
1090 (cond ((stringp gnus-visible-headers)
1091 gnus-visible-headers)
1092 ((and gnus-visible-headers
1093 (listp gnus-visible-headers))
1094 (mapconcat 'identity gnus-visible-headers "\\|"))))
1095 (inhibit-point-motion-hooks t)
1097 ;; First we narrow to just the headers.
1098 (article-narrow-to-head)
1099 ;; Hide any "From " lines at the beginning of (mail) articles.
1100 (while (looking-at "From ")
1103 (delete-region (point-min) (point)))
1104 ;; Then treat the rest of the header lines.
1105 ;; Then we use the two regular expressions
1106 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1107 ;; select which header lines is to remain visible in the
1109 (while (re-search-forward "^[^ \t]*:" nil t)
1111 ;; Mark the rank of the header.
1113 (point) (1+ (point)) 'message-rank
1114 (if (or (and visible (looking-at visible))
1116 (not (looking-at ignored))))
1117 (gnus-article-header-rank)
1120 (message-sort-headers-1)
1121 (when (setq beg (text-property-any
1122 (point-min) (point-max) 'message-rank (+ 2 max)))
1123 ;; We delete the unwanted headers.
1124 (push 'headers gnus-article-wash-types)
1125 (add-text-properties (point-min) (+ 5 (point-min))
1126 '(article-type headers dummy-invisible t))
1127 (delete-region beg (point-max))))))))
1129 (defun article-hide-boring-headers (&optional arg)
1130 "Toggle hiding of headers that aren't very interesting.
1131 If given a negative prefix, always show; if given a positive prefix,
1133 (interactive (gnus-article-hidden-arg))
1134 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1135 (not gnus-show-all-headers))
1138 (let ((buffer-read-only nil)
1139 (list gnus-boring-article-headers)
1140 (inhibit-point-motion-hooks t)
1142 (article-narrow-to-head)
1144 (setq elem (pop list))
1145 (goto-char (point-min))
1147 ;; Hide empty headers.
1149 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1151 (gnus-article-hide-text-type
1152 (progn (beginning-of-line) (point))
1155 (if (re-search-forward "^[^ \t]" nil t)
1159 ;; Hide boring Newsgroups header.
1160 ((eq elem 'newsgroups)
1161 (when (equal (gnus-fetch-field "newsgroups")
1162 (gnus-group-real-name
1163 (if (boundp 'gnus-newsgroup-name)
1166 (gnus-article-hide-header "newsgroups")))
1167 ((eq elem 'followup-to)
1168 (when (equal (message-fetch-field "followup-to")
1169 (message-fetch-field "newsgroups"))
1170 (gnus-article-hide-header "followup-to")))
1171 ((eq elem 'reply-to)
1172 (let ((from (message-fetch-field "from"))
1173 (reply-to (message-fetch-field "reply-to")))
1178 (nth 1 (mail-extract-address-components from))
1179 (nth 1 (mail-extract-address-components reply-to)))))
1180 (gnus-article-hide-header "reply-to"))))
1182 (let ((date (message-fetch-field "date")))
1184 (< (days-between (current-time-string) date)
1186 (gnus-article-hide-header "date"))))
1188 (let ((to (message-fetch-field "to"))
1189 (cc (message-fetch-field "cc")))
1190 (when (> (length to) 1024)
1191 (gnus-article-hide-header "to"))
1192 (when (> (length cc) 1024)
1193 (gnus-article-hide-header "cc"))))
1197 (goto-char (point-min))
1198 (while (re-search-forward "^to:" nil t)
1199 (setq to-count (1+ to-count)))
1200 (when (> to-count 1)
1201 (while (> to-count 0)
1202 (goto-char (point-min))
1204 (re-search-forward "^to:" nil nil to-count)
1206 (narrow-to-region (point) (point-max))
1207 (gnus-article-hide-header "to"))
1208 (setq to-count (1- to-count))))
1209 (goto-char (point-min))
1210 (while (re-search-forward "^cc:" nil t)
1211 (setq cc-count (1+ cc-count)))
1212 (when (> cc-count 1)
1213 (while (> cc-count 0)
1214 (goto-char (point-min))
1216 (re-search-forward "^cc:" nil nil cc-count)
1218 (narrow-to-region (point) (point-max))
1219 (gnus-article-hide-header "cc"))
1220 (setq cc-count (1- cc-count)))))))))))))
1222 (defun gnus-article-hide-header (header)
1224 (goto-char (point-min))
1225 (when (re-search-forward (concat "^" header ":") nil t)
1226 (gnus-article-hide-text-type
1227 (progn (beginning-of-line) (point))
1230 (if (re-search-forward "^[^ \t]" nil t)
1235 (defvar gnus-article-normalized-header-length 40
1236 "Length of normalized headers.")
1238 (defun article-normalize-headers ()
1239 "Make all header lines 40 characters long."
1241 (let ((buffer-read-only nil)
1245 (article-narrow-to-head)
1248 ((< (setq column (- (gnus-point-at-eol) (point)))
1249 gnus-article-normalized-header-length)
1251 (insert (make-string
1252 (- gnus-article-normalized-header-length column)
1254 ((> column gnus-article-normalized-header-length)
1255 (gnus-put-text-property
1257 (forward-char gnus-article-normalized-header-length)
1264 (forward-line 1))))))
1266 (defun article-treat-dumbquotes ()
1267 "Translate M******** sm*rtq**t*s into proper text.
1268 Note that this function guesses whether a character is a sm*rtq**t* or
1269 not, so it should only be used interactively."
1271 (article-translate-strings gnus-article-dumbquotes-map))
1273 (defun article-translate-characters (from to)
1274 "Translate all characters in the body of the article according to FROM and TO.
1275 FROM is a string of characters to translate from; to is a string of
1276 characters to translate to."
1278 (when (article-goto-body)
1279 (let ((buffer-read-only nil)
1280 (x (make-string 225 ?x))
1282 (while (< (incf i) (length x))
1285 (while (< i (length from))
1286 (aset x (aref from i) (aref to i))
1288 (translate-region (point) (point-max) x)))))
1290 (defun article-translate-strings (map)
1291 "Translate all string in the body of the article according to MAP.
1292 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1294 (when (article-goto-body)
1295 (let ((buffer-read-only nil)
1297 (while (setq elem (pop map))
1299 (while (search-forward (car elem) nil t)
1300 (replace-match (cadr elem)))))))))
1302 (defun article-treat-overstrike ()
1303 "Translate overstrikes into bold text."
1306 (when (article-goto-body)
1307 (let ((buffer-read-only nil))
1308 (while (search-forward "\b" nil t)
1309 (let ((next (char-after))
1310 (previous (char-after (- (point) 2))))
1311 ;; We do the boldification/underlining by hiding the
1312 ;; overstrikes and putting the proper text property
1316 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1317 (put-text-property (point) (1+ (point)) 'face 'bold))
1319 (gnus-article-hide-text-type
1320 (1- (point)) (1+ (point)) 'overstrike)
1322 (- (point) 2) (1- (point)) 'face 'underline))
1324 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1326 (point) (1+ (point)) 'face 'underline)))))))))
1328 (defun article-fill-long-lines ()
1329 "Fill lines that are wider than the window width."
1332 (let ((buffer-read-only nil)
1333 (width (window-width (get-buffer-window (current-buffer)))))
1336 (let ((adaptive-fill-mode nil))
1339 (when (>= (current-column) (min fill-column width))
1340 (narrow-to-region (point) (gnus-point-at-bol))
1341 (fill-paragraph nil)
1342 (goto-char (point-max))
1344 (forward-line 1)))))))
1346 (defun article-capitalize-sentences ()
1347 "Capitalize the first word in each sentence."
1350 (let ((buffer-read-only nil)
1351 (paragraph-start "^[\n\^L]"))
1355 (forward-sentence)))))
1357 (defun article-remove-cr ()
1358 "Remove trailing CRs and then translate remaining CRs into LFs."
1361 (let ((buffer-read-only nil))
1362 (goto-char (point-min))
1363 (while (re-search-forward "\r+$" nil t)
1364 (replace-match "" t t))
1365 (goto-char (point-min))
1366 (while (search-forward "\r" nil t)
1367 (replace-match "\n" t t)))))
1369 (defun article-remove-trailing-blank-lines ()
1370 "Remove all trailing blank lines from the article."
1373 (let ((buffer-read-only nil))
1374 (goto-char (point-max))
1378 (while (and (not (bobp))
1379 (looking-at "^[ \t]*$")
1380 (not (gnus-annotation-in-region-p
1381 (point) (gnus-point-at-eol))))
1386 (defun article-display-x-face (&optional force)
1387 "Look for an X-Face header and display it if present."
1388 (interactive (list 'force))
1390 ;; Delete the old process, if any.
1391 (when (process-status "article-x-face")
1392 (delete-process "article-x-face"))
1393 (let ((inhibit-point-motion-hooks t)
1394 (case-fold-search t)
1397 (article-narrow-to-head)
1398 (goto-char (point-min))
1399 (setq from (message-fetch-field "from"))
1400 (goto-char (point-min))
1401 (while (and gnus-article-x-face-command
1404 ;; Check whether this face is censored.
1405 (not gnus-article-x-face-too-ugly)
1406 (and gnus-article-x-face-too-ugly from
1407 (not (string-match gnus-article-x-face-too-ugly
1409 ;; Has to be present.
1410 (re-search-forward "^X-Face: " nil t))
1411 ;; This used to try to do multiple faces (`while' instead of
1412 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1413 ;; work (b) it can crash some versions of Emacs (c) are
1414 ;; multiple faces really something to encourage?
1415 (when (stringp gnus-article-x-face-command)
1417 ;; We now have the area of the buffer where the X-Face is stored.
1420 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1421 ;; We display the face.
1422 (if (symbolp gnus-article-x-face-command)
1423 ;; The command is a lisp function, so we call it.
1424 (if (gnus-functionp gnus-article-x-face-command)
1425 (funcall gnus-article-x-face-command beg end)
1426 (error "%s is not a function" gnus-article-x-face-command))
1427 ;; The command is a string, so we interpret the command
1428 ;; as a, well, command, and fork it off.
1429 (let ((process-connection-type nil))
1430 (process-kill-without-query
1432 "article-x-face" nil shell-file-name shell-command-switch
1433 gnus-article-x-face-command))
1434 (process-send-region "article-x-face" beg end)
1435 (process-send-eof "article-x-face"))))))))))
1437 (defun article-decode-mime-words ()
1438 "Decode all MIME-encoded words in the article."
1441 (set-buffer gnus-article-buffer)
1442 (let ((inhibit-point-motion-hooks t)
1444 (mail-parse-charset gnus-newsgroup-charset)
1445 (mail-parse-ignored-charsets
1446 (save-excursion (set-buffer gnus-summary-buffer)
1447 gnus-newsgroup-ignored-charsets)))
1448 (mail-decode-encoded-word-region (point-min) (point-max)))))
1450 (defun article-decode-charset (&optional prompt)
1451 "Decode charset-encoded text in the article.
1452 If PROMPT (the prefix), prompt for a coding system to use."
1454 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1456 (mail-parse-charset gnus-newsgroup-charset)
1457 (mail-parse-ignored-charsets
1458 (save-excursion (condition-case nil
1459 (set-buffer gnus-summary-buffer)
1461 gnus-newsgroup-ignored-charsets))
1462 ct cte ctl charset format)
1465 (article-narrow-to-head)
1466 (setq ct (message-fetch-field "Content-Type" t)
1467 cte (message-fetch-field "Content-Transfer-Encoding" t)
1468 ctl (and ct (ignore-errors
1469 (mail-header-parse-content-type ct)))
1472 (mm-read-coding-system "Charset to decode: "))
1474 (mail-content-type-get ctl 'charset)))
1475 format (and ctl (mail-content-type-get ctl 'format)))
1477 (setq cte (mail-header-strip cte)))
1478 (if (and ctl (not (string-match "/" (car ctl))))
1480 (goto-char (point-max)))
1483 (narrow-to-region (point) (point-max))
1484 (when (and (eq mail-parse-charset 'gnus-decoded)
1485 (eq (mm-body-7-or-8) '8bit))
1486 ;; The text code could have been decoded.
1487 (setq charset mail-parse-charset))
1488 (when (and (or (not ctl)
1489 (equal (car ctl) "text/plain"))
1490 (not format)) ;; article with format will decode later.
1492 charset (and cte (intern (downcase
1493 (gnus-strip-whitespace cte))))
1496 (defun article-decode-encoded-words ()
1497 "Remove encoded-word encoding from headers."
1498 (let ((inhibit-point-motion-hooks t)
1499 (mail-parse-charset gnus-newsgroup-charset)
1500 (mail-parse-ignored-charsets
1501 (save-excursion (condition-case nil
1502 (set-buffer gnus-summary-buffer)
1504 gnus-newsgroup-ignored-charsets))
1507 (article-narrow-to-head)
1508 (funcall gnus-decode-header-function (point-min) (point-max)))))
1510 (defun article-de-quoted-unreadable (&optional force)
1511 "Translate a quoted-printable-encoded article.
1512 If FORCE, decode the article whether it is marked as quoted-printable
1514 (interactive (list 'force))
1516 (let ((buffer-read-only nil) type charset)
1517 (if (gnus-buffer-live-p gnus-original-article-buffer)
1518 (with-current-buffer gnus-original-article-buffer
1520 (gnus-fetch-field "content-transfer-encoding"))
1521 (let* ((ct (gnus-fetch-field "content-type"))
1524 (mail-header-parse-content-type ct)))))
1525 (setq charset (and ctl
1526 (mail-content-type-get ctl 'charset)))
1527 (if (stringp charset)
1528 (setq charset (intern (downcase charset)))))))
1530 (setq charset gnus-newsgroup-charset))
1532 (and type (string-match "quoted-printable" (downcase type))))
1534 (quoted-printable-decode-region (point) (point-max) charset)))))
1536 (defun article-de-base64-unreadable (&optional force)
1537 "Translate a base64 article.
1538 If FORCE, decode the article whether it is marked as base64 not."
1539 (interactive (list 'force))
1541 (let ((buffer-read-only nil) type charset)
1542 (if (gnus-buffer-live-p gnus-original-article-buffer)
1543 (with-current-buffer gnus-original-article-buffer
1545 (gnus-fetch-field "content-transfer-encoding"))
1546 (let* ((ct (gnus-fetch-field "content-type"))
1549 (mail-header-parse-content-type ct)))))
1550 (setq charset (and ctl
1551 (mail-content-type-get ctl 'charset)))
1552 (if (stringp charset)
1553 (setq charset (intern (downcase charset)))))))
1555 (setq charset gnus-newsgroup-charset))
1557 (and type (string-match "base64" (downcase type))))
1560 (narrow-to-region (point) (point-max))
1561 (base64-decode-region (point-min) (point-max))
1562 (if (mm-coding-system-p charset)
1563 (mm-decode-coding-region (point-min) (point-max) charset)))))))
1568 (defun article-decode-HZ ()
1569 "Translate a HZ-encoded article."
1573 (let ((buffer-read-only nil))
1574 (rfc1843-decode-region (point-min) (point-max)))))
1576 (defun article-wash-html ()
1577 "Format an html article."
1580 (let ((buffer-read-only nil)
1582 (if (gnus-buffer-live-p gnus-original-article-buffer)
1583 (with-current-buffer gnus-original-article-buffer
1584 (let* ((ct (gnus-fetch-field "content-type"))
1587 (mail-header-parse-content-type ct)))))
1588 (setq charset (and ctl
1589 (mail-content-type-get ctl 'charset)))
1590 (if (stringp charset)
1591 (setq charset (intern (downcase charset)))))))
1593 (setq charset gnus-newsgroup-charset))
1595 (save-window-excursion
1597 (narrow-to-region (point) (point-max))
1599 (let ((w3-strict-width (window-width))
1600 (url-standalone-mode t))
1602 (w3-region (point-min) (point-max))
1605 (defun article-hide-list-identifiers ()
1606 "Remove list identifies from the Subject header.
1607 The `gnus-list-identifiers' variable specifies what to do."
1611 (let ((inhibit-point-motion-hooks t)
1613 (article-narrow-to-head)
1614 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1615 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1617 (goto-char (point-min))
1618 (when (re-search-forward
1619 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1620 " *\\)\\)+\\(Re: +\\)?\\)")
1622 (let ((s (or (match-string 3) (match-string 5))))
1623 (delete-region (match-beginning 1) (match-end 1))
1625 (goto-char (match-beginning 1))
1628 (defun article-hide-pgp ()
1629 "Remove any PGP headers and signatures in the current article."
1633 (let ((inhibit-point-motion-hooks t)
1634 buffer-read-only beg end)
1636 ;; Hide the "header".
1637 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1638 (push 'pgp gnus-article-wash-types)
1639 (delete-region (match-beginning 0) (match-end 0))
1640 ;; Remove armor headers (rfc2440 6.2)
1641 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1644 ;; Hide the actual signature.
1645 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1646 (setq end (1+ (match-beginning 0)))
1649 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1651 ;; Perhaps we shouldn't hide to the end of the buffer
1652 ;; if there is no end to the signature?
1654 ;; Hide "- " PGP quotation markers.
1656 (narrow-to-region beg end)
1657 (goto-char (point-min))
1658 (while (re-search-forward "^- " nil t)
1660 (match-beginning 0) (match-end 0)))
1662 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1664 (defun article-hide-pem (&optional arg)
1665 "Toggle hiding of any PEM headers and signatures in the current article.
1666 If given a negative prefix, always show; if given a positive prefix,
1668 (interactive (gnus-article-hidden-arg))
1669 (unless (gnus-article-check-hidden-text 'pem arg)
1671 (let (buffer-read-only end)
1672 (goto-char (point-min))
1673 ;; Hide the horrendously ugly "header".
1674 (when (and (search-forward
1675 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1677 (setq end (1+ (match-beginning 0))))
1678 (push 'pem gnus-article-wash-types)
1679 (gnus-article-hide-text-type
1681 (if (search-forward "\n\n" nil t)
1685 ;; Hide the trailer as well
1686 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1688 (gnus-article-hide-text-type
1689 (match-beginning 0) (match-end 0) 'pem)))))))
1691 (defun article-strip-banner ()
1692 "Strip the banner specified by the `banner' group parameter."
1696 (let ((inhibit-point-motion-hooks t)
1697 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1698 (gnus-signature-limit nil)
1699 buffer-read-only beg end)
1703 ((eq banner 'signature)
1704 (when (gnus-article-narrow-to-signature)
1707 (delete-region (point) (point-max))))
1709 (while (re-search-forward banner nil t)
1710 (delete-region (match-beginning 0) (match-end 0))))))))))
1712 (defun article-babel ()
1713 "Translate article using an online translation service."
1717 (set-buffer gnus-article-buffer)
1718 (when (article-goto-body)
1719 (let* ((buffer-read-only nil)
1722 (orig (buffer-substring start end))
1723 (trans (babel-as-string orig)))
1725 (narrow-to-region start end)
1726 (delete-region start end)
1729 (defun article-hide-signature (&optional arg)
1730 "Hide the signature in the current article.
1731 If given a negative prefix, always show; if given a positive prefix,
1733 (interactive (gnus-article-hidden-arg))
1734 (unless (gnus-article-check-hidden-text 'signature arg)
1737 (let ((buffer-read-only nil))
1738 (when (gnus-article-narrow-to-signature)
1739 (gnus-article-hide-text-type
1740 (point-min) (point-max) 'signature)))))))
1742 (defun article-strip-headers-in-body ()
1743 "Strip offensive headers from bodies."
1747 (let ((case-fold-search t))
1748 (when (looking-at "x-no-archive:")
1749 (gnus-delete-line)))))
1751 (defun article-strip-leading-blank-lines ()
1752 "Remove all blank lines from the beginning of the article."
1755 (let ((inhibit-point-motion-hooks t)
1757 (when (article-goto-body)
1758 (while (and (not (eobp))
1759 (looking-at "[ \t]*$"))
1760 (gnus-delete-line))))))
1762 (defun article-narrow-to-head ()
1763 "Narrow the buffer to the head of the message.
1764 Point is left at the beginning of the narrowed-to region."
1766 (goto-char (point-min))
1767 (if (search-forward "\n\n" nil 1)
1770 (goto-char (point-min)))
1772 (defun article-goto-body ()
1773 "Place point at the start of the body."
1774 (goto-char (point-min))
1776 ;; This variable is only bound when dealing with separate
1778 (article-goto-body-goes-to-point-min-p
1780 ((search-forward "\n\n" nil t)
1783 (goto-char (point-max))
1786 (defun article-strip-multiple-blank-lines ()
1787 "Replace consecutive blank lines with one empty line."
1790 (let ((inhibit-point-motion-hooks t)
1792 ;; First make all blank lines empty.
1794 (while (re-search-forward "^[ \t]+$" nil t)
1795 (unless (gnus-annotation-in-region-p
1796 (match-beginning 0) (match-end 0))
1797 (replace-match "" nil t)))
1798 ;; Then replace multiple empty lines with a single empty line.
1800 (while (re-search-forward "\n\n\n+" nil t)
1801 (unless (gnus-annotation-in-region-p
1802 (match-beginning 0) (match-end 0))
1803 (replace-match "\n\n" t t))))))
1805 (defun article-strip-leading-space ()
1806 "Remove all white space from the beginning of the lines in the article."
1809 (let ((inhibit-point-motion-hooks t)
1812 (while (re-search-forward "^[ \t]+" nil t)
1813 (replace-match "" t t)))))
1815 (defun article-strip-trailing-space ()
1816 "Remove all white space from the end of the lines in the article."
1819 (let ((inhibit-point-motion-hooks t)
1822 (while (re-search-forward "[ \t]+$" nil t)
1823 (replace-match "" t t)))))
1825 (defun article-strip-blank-lines ()
1826 "Strip leading, trailing and multiple blank lines."
1828 (article-strip-leading-blank-lines)
1829 (article-remove-trailing-blank-lines)
1830 (article-strip-multiple-blank-lines))
1832 (defun article-strip-all-blank-lines ()
1833 "Strip all blank lines."
1836 (let ((inhibit-point-motion-hooks t)
1839 (while (re-search-forward "^[ \t]*\n" nil t)
1840 (replace-match "" t t)))))
1842 (defun gnus-article-narrow-to-signature ()
1843 "Narrow to the signature; return t if a signature is found, else nil."
1844 (let ((inhibit-point-motion-hooks t))
1845 (when (gnus-article-search-signature)
1847 ;; Check whether we have some limits to what we consider
1848 ;; to be a signature.
1849 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1850 (list gnus-signature-limit)))
1852 (while (setq limit (pop limits))
1853 (if (or (and (integerp limit)
1854 (< (- (point-max) (point)) limit))
1856 (< (count-lines (point) (point-max)) limit))
1857 (and (gnus-functionp limit)
1859 (and (stringp limit)
1860 (not (re-search-forward limit nil t))))
1861 () ; This limit did not succeed.
1865 (narrow-to-region (point) (point-max))
1868 (defun gnus-article-search-signature ()
1869 "Search the current buffer for the signature separator.
1870 Put point at the beginning of the signature separator."
1871 (let ((cur (point)))
1872 (goto-char (point-max))
1873 (if (if (stringp gnus-signature-separator)
1874 (re-search-backward gnus-signature-separator nil t)
1875 (let ((seps gnus-signature-separator))
1877 (not (re-search-backward (car seps) nil t)))
1884 (defun gnus-article-hidden-arg ()
1885 "Return the current prefix arg as a number, or 0 if no prefix."
1886 (list (if current-prefix-arg
1887 (prefix-numeric-value current-prefix-arg)
1890 (defun gnus-article-check-hidden-text (type arg)
1891 "Return nil if hiding is necessary.
1892 Arg can be nil or a number. Nil and positive means hide, negative
1893 means show, 0 means toggle."
1896 (let ((hide (gnus-article-hidden-text-p type)))
1902 (gnus-article-show-hidden-text type))
1904 (if (eq hide 'hidden)
1905 (gnus-article-show-hidden-text type)
1908 (defun gnus-article-hidden-text-p (type)
1909 "Say whether the current buffer contains hidden text of type TYPE."
1910 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1912 (not (get-text-property pos 'invisible))
1913 (not (get-text-property pos 'dummy-invisible)))
1915 (text-property-any (1+ pos) (point-max) 'article-type type)))
1920 (defun gnus-article-show-hidden-text (type &optional hide)
1921 "Show all hidden text of type TYPE.
1922 If HIDE, hide the text instead."
1924 (let ((buffer-read-only nil)
1925 (inhibit-point-motion-hooks t)
1928 (while (setq beg (text-property-any end (point-max) 'article-type type))
1931 (text-property-not-all beg (point-max) 'article-type type)
1934 (gnus-article-hide-text beg end gnus-hidden-properties)
1935 (gnus-article-unhide-text beg end))
1939 (defconst article-time-units
1940 `((year . ,(* 365.25 24 60 60))
1941 (week . ,(* 7 24 60 60))
1942 (day . ,(* 24 60 60))
1946 "Mapping from time units to seconds.")
1948 (defun article-date-ut (&optional type highlight header)
1949 "Convert DATE date to universal time in the current article.
1950 If TYPE is `local', convert to local time; if it is `lapsed', output
1951 how much time has lapsed since DATE. For `lapsed', the value of
1952 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1953 should replace the \"Date:\" one, or should be added below it."
1954 (interactive (list 'ut t))
1955 (let* ((header (or header
1956 (message-fetch-field "date")
1958 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1961 ((not gnus-article-date-lapsed-new-header)
1967 (date (if (vectorp header) (mail-header-date header)
1969 (inhibit-point-motion-hooks t)
1974 (article-narrow-to-head)
1975 (when (re-search-forward tdate-regexp nil t)
1976 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1977 date (or (get-text-property (gnus-point-at-bol)
1980 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1982 (when (and date (not (string= date "")))
1983 (goto-char (point-min))
1984 (let ((buffer-read-only nil))
1985 ;; Delete any old Date headers.
1986 (while (re-search-forward date-regexp nil t)
1988 (delete-region (progn (beginning-of-line) (point))
1989 (progn (forward-line 1) (point)))
1990 (delete-region (progn (beginning-of-line) (point))
1991 (progn (end-of-line) (point)))
1992 (setq pos (point))))
1993 (when (and (not pos) (re-search-forward tdate-regexp nil t))
1995 (if pos (goto-char pos))
1996 (insert (article-make-date-line date (or type 'ut)))
2002 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2003 (put-text-property (match-beginning 1) (1+ (match-end 1))
2004 'original-date date)
2005 (put-text-property (match-beginning 1) (1+ (match-end 1))
2007 (put-text-property (match-beginning 2) (match-end 2)
2010 (defun article-make-date-line (date type)
2011 "Return a DATE line of TYPE."
2012 (let ((time (condition-case ()
2016 ;; Convert to the local timezone. We have to slap a
2017 ;; `condition-case' round the calls to the timezone
2018 ;; functions since they aren't particularly resistant to
2021 (let ((tz (car (current-time-zone time))))
2022 (format "Date: %s %s%02d%02d" (current-time-string time)
2023 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2024 (/ (% (abs tz) 3600) 60))))
2025 ;; Convert to Universal Time.
2028 (current-time-string
2029 (let* ((e (parse-time-string date))
2030 (tm (apply 'encode-time e))
2032 (ls (- (cadr tm) (car (current-time-zone time)))))
2033 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2034 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2037 ;; Get the original date from the article.
2038 ((eq type 'original)
2039 (concat "Date: " (if (string-match "\n+$" date)
2040 (substring date 0 (match-beginning 0))
2042 ;; Let the user define the format.
2044 (if (gnus-functionp gnus-article-time-format)
2045 (funcall gnus-article-time-format time)
2048 (format-time-string gnus-article-time-format time))))
2051 (let ((tz (car (current-time-zone time))))
2054 (format-time-string "%Y%m%dT%H%M%S" time)
2055 (format "%s%02d%02d"
2056 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2057 (/ (% (abs tz) 3600) 60)))))
2058 ;; Do an X-Sent lapsed format.
2060 ;; If the date is seriously mangled, the timezone functions are
2061 ;; liable to bug out, so we ignore all errors.
2062 (let* ((now (current-time))
2063 (real-time (subtract-time now time))
2064 (real-sec (and real-time
2065 (+ (* (float (car real-time)) 65536)
2067 (sec (and real-time (abs real-sec)))
2077 ;; This is a bit convoluted, but basically we go
2078 ;; through the time units for years, weeks, etc,
2079 ;; and divide things to see whether that results
2080 ;; in positive answers.
2083 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2084 ;; The (remaining) seconds are too few to
2085 ;; be divided into this time unit.
2087 ;; It's big enough, so we output it.
2088 (setq sec (- sec (* num (cdr unit))))
2090 (concat (if prev ", " "") (int-to-string
2092 " " (symbol-name (car unit))
2093 (if (> num 1) "s" ""))
2095 article-time-units "")
2096 ;; If dates are odd, then it might appear like the
2097 ;; article was sent in the future.
2100 " in the future"))))))
2102 (error "Unknown conversion type: %s" type)))))
2104 (defun article-date-local (&optional highlight)
2105 "Convert the current article date to the local timezone."
2106 (interactive (list t))
2107 (article-date-ut 'local highlight))
2109 (defun article-date-original (&optional highlight)
2110 "Convert the current article date to what it was originally.
2111 This is only useful if you have used some other date conversion
2112 function and want to see what the date was before converting."
2113 (interactive (list t))
2114 (article-date-ut 'original highlight))
2116 (defun article-date-lapsed (&optional highlight)
2117 "Convert the current article date to time lapsed since it was sent."
2118 (interactive (list t))
2119 (article-date-ut 'lapsed highlight))
2121 (defun article-update-date-lapsed ()
2122 "Function to be run from a timer to update the lapsed time line."
2123 (let (deactivate-mark)
2128 (set-buffer (window-buffer w))
2129 (when (eq major-mode 'gnus-article-mode)
2130 (goto-char (point-min))
2131 (when (re-search-forward "^X-Sent:" nil t)
2132 (article-date-lapsed t))))
2135 (defun gnus-start-date-timer (&optional n)
2136 "Start a timer to update the X-Sent header in the article buffers.
2137 The numerical prefix says how frequently (in seconds) the function
2142 (gnus-stop-date-timer)
2143 (setq article-lapsed-timer
2144 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2146 (defun gnus-stop-date-timer ()
2147 "Stop the X-Sent timer."
2149 (when article-lapsed-timer
2150 (nnheader-cancel-timer article-lapsed-timer)
2151 (setq article-lapsed-timer nil)))
2153 (defun article-date-user (&optional highlight)
2154 "Convert the current article date to the user-defined format.
2155 This format is defined by the `gnus-article-time-format' variable."
2156 (interactive (list t))
2157 (article-date-ut 'user highlight))
2159 (defun article-date-iso8601 (&optional highlight)
2160 "Convert the current article date to ISO8601."
2161 (interactive (list t))
2162 (article-date-ut 'iso8601 highlight))
2164 (defun article-show-all ()
2165 "Show all hidden text in the article buffer."
2168 (let ((buffer-read-only nil))
2169 (gnus-article-unhide-text (point-min) (point-max)))))
2171 (defun article-emphasize (&optional arg)
2172 "Emphasize text according to `gnus-emphasis-alist'."
2173 (interactive (gnus-article-hidden-arg))
2174 (unless (gnus-article-check-hidden-text 'emphasis arg)
2178 (with-current-buffer gnus-summary-buffer
2179 gnus-article-emphasis-alist)
2181 gnus-emphasis-alist))
2182 (buffer-read-only nil)
2183 (props (append '(article-type emphasis)
2184 gnus-hidden-properties))
2185 regexp elem beg invisible visible face)
2188 (while (setq elem (pop alist))
2190 (setq regexp (car elem)
2191 invisible (nth 1 elem)
2192 visible (nth 2 elem)
2194 (while (re-search-forward regexp nil t)
2195 (when (and (match-beginning visible) (match-beginning invisible))
2196 (push 'emphasis gnus-article-wash-types)
2197 (gnus-article-hide-text
2198 (match-beginning invisible) (match-end invisible) props)
2199 (gnus-article-unhide-text-type
2200 (match-beginning visible) (match-end visible) 'emphasis)
2201 (gnus-put-text-property-excluding-newlines
2202 (match-beginning visible) (match-end visible) 'face face)
2203 (goto-char (match-end invisible)))))))))
2205 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2206 "Setup newsgroup emphasis alist."
2207 (unless gnus-article-emphasis-alist
2208 (let ((name (and gnus-newsgroup-name
2209 (gnus-group-real-name gnus-newsgroup-name))))
2210 (make-local-variable 'gnus-article-emphasis-alist)
2211 (setq gnus-article-emphasis-alist
2213 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2214 (while (setq elem (pop alist))
2215 (when (and name (string-match (car elem) name))
2217 highlight (copy-sequence (cdr elem)))))
2219 (copy-sequence highlight-words)
2220 (if gnus-newsgroup-name
2221 (copy-sequence (gnus-group-find-parameter
2222 gnus-newsgroup-name 'highlight-words t)))
2223 gnus-emphasis-alist)))))
2225 (defvar gnus-summary-article-menu)
2226 (defvar gnus-summary-post-menu)
2228 ;;; Saving functions.
2230 (defun gnus-article-save (save-buffer file &optional num)
2231 "Save the currently selected article."
2232 (unless gnus-save-all-headers
2233 ;; Remove headers according to `gnus-saved-headers'.
2234 (let ((gnus-visible-headers
2235 (or gnus-saved-headers gnus-visible-headers))
2236 (gnus-article-buffer save-buffer))
2238 (set-buffer save-buffer)
2239 (article-hide-headers 1 t))))
2240 (save-window-excursion
2241 (if (not gnus-default-article-saver)
2242 (error "No default saver is defined")
2243 ;; !!! Magic! The saving functions all save
2244 ;; `gnus-save-article-buffer' (or so they think), but we
2245 ;; bind that variable to our save-buffer.
2246 (set-buffer gnus-article-buffer)
2247 (let* ((gnus-save-article-buffer save-buffer)
2250 ((not gnus-prompt-before-saving) 'default)
2251 ((eq gnus-prompt-before-saving 'always) nil)
2253 (gnus-number-of-articles-to-be-saved
2254 (when (eq gnus-prompt-before-saving t)
2256 (set-buffer gnus-article-current-summary)
2257 (funcall gnus-default-article-saver filename)))))
2259 (defun gnus-read-save-file-name (prompt &optional filename
2260 function group headers variable)
2262 (funcall function group headers (symbol-value variable)))
2267 ((eq filename 'default)
2273 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2276 (if (and gnus-number-of-articles-to-be-saved
2277 (> gnus-number-of-articles-to-be-saved 1))
2278 (format "these %d articles"
2279 gnus-number-of-articles-to-be-saved)
2282 ;; Let the split methods have their say.
2284 ;; No split name was found.
2287 (concat prompt " (default "
2288 (file-name-nondirectory default-name) ") ")
2289 (file-name-directory default-name)
2291 ;; A single group name is returned.
2292 ((stringp split-name)
2294 (funcall function split-name headers
2295 (symbol-value variable)))
2297 (concat prompt " (default "
2298 (file-name-nondirectory default-name) ") ")
2299 (file-name-directory default-name)
2301 ;; A single split name was found
2302 ((= 1 (length split-name))
2303 (let* ((name (expand-file-name
2304 (car split-name) gnus-article-save-directory))
2305 (dir (cond ((file-directory-p name)
2306 (file-name-as-directory name))
2307 ((file-exists-p name) name)
2308 (t gnus-article-save-directory))))
2310 (concat prompt " (default " name ") ")
2312 ;; A list of splits was found.
2314 (setq split-name (nreverse split-name))
2316 (let ((file-name-history
2317 (nconc split-name file-name-history)))
2321 (concat prompt " (`M-p' for defaults) ")
2322 gnus-article-save-directory
2324 gnus-article-save-directory)))
2325 (car (push result file-name-history)))))))
2326 ;; Create the directory.
2327 (gnus-make-directory (file-name-directory file))
2328 ;; If we have read a directory, we append the default file name.
2329 (when (file-directory-p file)
2330 (setq file (expand-file-name (file-name-nondirectory default-name)
2331 (file-name-as-directory file))))
2332 ;; Possibly translate some characters.
2333 (nnheader-translate-file-chars file)))))
2334 (gnus-make-directory (file-name-directory result))
2335 (set variable result)))
2337 (defun gnus-article-archive-name (group)
2338 "Return the first instance of an \"Archive-name\" in the current buffer."
2339 (let ((case-fold-search t))
2340 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2341 (nnheader-concat gnus-article-save-directory
2342 (match-string 1)))))
2344 (defun gnus-article-nndoc-name (group)
2345 "If GROUP is an nndoc group, return the name of the parent group."
2346 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2347 (gnus-group-get-parameter group 'save-article-group)))
2349 (defun gnus-summary-save-in-rmail (&optional filename)
2350 "Append this article to Rmail file.
2351 Optional argument FILENAME specifies file name.
2352 Directory to save to is default to `gnus-article-save-directory'."
2353 (setq filename (gnus-read-save-file-name
2354 "Save %s in rmail file:" filename
2355 gnus-rmail-save-name gnus-newsgroup-name
2356 gnus-current-headers 'gnus-newsgroup-last-rmail))
2357 (gnus-eval-in-buffer-window gnus-save-article-buffer
2361 (gnus-output-to-rmail filename))))
2364 (defun gnus-summary-save-in-mail (&optional filename)
2365 "Append this article to Unix mail file.
2366 Optional argument FILENAME specifies file name.
2367 Directory to save to is default to `gnus-article-save-directory'."
2368 (setq filename (gnus-read-save-file-name
2369 "Save %s in Unix mail file:" filename
2370 gnus-mail-save-name gnus-newsgroup-name
2371 gnus-current-headers 'gnus-newsgroup-last-mail))
2372 (gnus-eval-in-buffer-window gnus-save-article-buffer
2376 (if (and (file-readable-p filename)
2377 (mail-file-babyl-p filename))
2378 (rmail-output-to-rmail-file filename t)
2379 (gnus-output-to-mail filename)))))
2382 (defun gnus-summary-save-in-file (&optional filename overwrite)
2383 "Append this article to file.
2384 Optional argument FILENAME specifies file name.
2385 Directory to save to is default to `gnus-article-save-directory'."
2386 (setq filename (gnus-read-save-file-name
2387 "Save %s in file:" filename
2388 gnus-file-save-name gnus-newsgroup-name
2389 gnus-current-headers 'gnus-newsgroup-last-file))
2390 (gnus-eval-in-buffer-window gnus-save-article-buffer
2394 (when (and overwrite
2395 (file-exists-p filename))
2396 (delete-file filename))
2397 (gnus-output-to-file filename))))
2400 (defun gnus-summary-write-to-file (&optional filename)
2401 "Write this article to a file.
2402 Optional argument FILENAME specifies file name.
2403 The directory to save in defaults to `gnus-article-save-directory'."
2404 (gnus-summary-save-in-file nil t))
2406 (defun gnus-summary-save-body-in-file (&optional filename)
2407 "Append this article body to a file.
2408 Optional argument FILENAME specifies file name.
2409 The directory to save in defaults to `gnus-article-save-directory'."
2410 (setq filename (gnus-read-save-file-name
2411 "Save %s body in file:" filename
2412 gnus-file-save-name gnus-newsgroup-name
2413 gnus-current-headers 'gnus-newsgroup-last-file))
2414 (gnus-eval-in-buffer-window gnus-save-article-buffer
2418 (when (article-goto-body)
2419 (narrow-to-region (point) (point-max)))
2420 (gnus-output-to-file filename))))
2423 (defun gnus-summary-save-in-pipe (&optional command)
2424 "Pipe this article to subprocess."
2426 (cond ((and (eq command 'default)
2427 gnus-last-shell-command)
2428 gnus-last-shell-command)
2432 "Shell command on %s: "
2433 (if (and gnus-number-of-articles-to-be-saved
2434 (> gnus-number-of-articles-to-be-saved 1))
2435 (format "these %d articles"
2436 gnus-number-of-articles-to-be-saved)
2438 gnus-last-shell-command))))
2439 (when (string-equal command "")
2440 (setq command gnus-last-shell-command))
2441 (gnus-eval-in-buffer-window gnus-article-buffer
2444 (shell-command-on-region (point-min) (point-max) command nil)))
2445 (setq gnus-last-shell-command command))
2447 ;;; Article file names when saving.
2449 (defun gnus-capitalize-newsgroup (newsgroup)
2450 "Capitalize NEWSGROUP name."
2451 (when (not (zerop (length newsgroup)))
2452 (concat (char-to-string (upcase (aref newsgroup 0)))
2453 (substring newsgroup 1))))
2455 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2456 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2457 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2458 Otherwise, it is like ~/News/news/group/num."
2461 (concat (if (gnus-use-long-file-name 'not-save)
2462 (gnus-capitalize-newsgroup newsgroup)
2463 (gnus-newsgroup-directory-form newsgroup))
2464 "/" (int-to-string (mail-header-number headers)))
2465 gnus-article-save-directory)))
2467 (string-equal (file-name-directory default)
2468 (file-name-directory last-file))
2469 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2471 (or last-file default))))
2473 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2474 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2475 If variable `gnus-use-long-file-name' is non-nil, it is
2476 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2479 (concat (if (gnus-use-long-file-name 'not-save)
2481 (gnus-newsgroup-directory-form newsgroup))
2482 "/" (int-to-string (mail-header-number headers)))
2483 gnus-article-save-directory)))
2485 (string-equal (file-name-directory default)
2486 (file-name-directory last-file))
2487 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2489 (or last-file default))))
2491 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2492 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2493 If variable `gnus-use-long-file-name' is non-nil, it is
2494 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2497 (if (gnus-use-long-file-name 'not-save)
2499 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2500 gnus-article-save-directory)))
2507 (setq afunc (car func)
2510 gfunc (intern (format "gnus-%s" func))))
2513 `(lambda (&optional interactive &rest args)
2514 ,(documentation afunc t)
2515 (interactive (list t))
2517 (set-buffer gnus-article-buffer)
2519 (call-interactively ',afunc)
2520 (apply ',afunc args))))))))
2521 '(article-hide-headers
2522 article-hide-boring-headers
2523 article-treat-overstrike
2524 article-fill-long-lines
2525 article-capitalize-sentences
2527 article-display-x-face
2528 article-de-quoted-unreadable
2529 article-de-base64-unreadable
2532 article-hide-list-identifiers
2534 article-strip-banner
2537 article-hide-signature
2538 article-strip-headers-in-body
2539 article-remove-trailing-blank-lines
2540 article-strip-leading-blank-lines
2541 article-strip-multiple-blank-lines
2542 article-strip-leading-space
2543 article-strip-trailing-space
2544 article-strip-blank-lines
2545 article-strip-all-blank-lines
2547 article-date-iso8601
2548 article-date-original
2550 article-decode-mime-words
2551 article-decode-charset
2552 article-decode-encoded-words
2556 article-treat-dumbquotes
2557 article-normalize-headers
2558 (article-show-all . gnus-article-show-all-headers))))
2561 ;;; Gnus article mode
2564 (put 'gnus-article-mode 'mode-class 'special)
2566 (set-keymap-parent gnus-article-mode-map widget-keymap)
2568 (gnus-define-keys gnus-article-mode-map
2569 " " gnus-article-goto-next-page
2570 "\177" gnus-article-goto-prev-page
2571 [delete] gnus-article-goto-prev-page
2572 [backspace] gnus-article-goto-prev-page
2573 "\C-c^" gnus-article-refer-article
2574 "h" gnus-article-show-summary
2575 "s" gnus-article-show-summary
2576 "\C-c\C-m" gnus-article-mail
2577 "?" gnus-article-describe-briefly
2578 "e" gnus-summary-edit-article
2579 "<" beginning-of-buffer
2581 "\C-c\C-i" gnus-info-find-node
2584 "\C-d" gnus-article-read-summary-keys
2585 "\M-*" gnus-article-read-summary-keys
2586 "\M-#" gnus-article-read-summary-keys
2587 "\M-^" gnus-article-read-summary-keys
2588 "\M-g" gnus-article-read-summary-keys)
2590 (substitute-key-definition
2591 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2593 (defun gnus-article-make-menu-bar ()
2594 (gnus-turn-off-edit-menu 'article)
2595 (unless (boundp 'gnus-article-article-menu)
2597 gnus-article-article-menu gnus-article-mode-map ""
2599 ["Scroll forwards" gnus-article-goto-next-page t]
2600 ["Scroll backwards" gnus-article-goto-prev-page t]
2601 ["Show summary" gnus-article-show-summary t]
2602 ["Fetch Message-ID at point" gnus-article-refer-article t]
2603 ["Mail to address at point" gnus-article-mail t]
2604 ["Send a bug report" gnus-bug t]))
2607 gnus-article-treatment-menu gnus-article-mode-map ""
2609 ["Hide headers" gnus-article-hide-headers t]
2610 ["Hide signature" gnus-article-hide-signature t]
2611 ["Hide citation" gnus-article-hide-citation t]
2612 ["Treat overstrike" gnus-article-treat-overstrike t]
2613 ["Remove carriage return" gnus-article-remove-cr t]
2614 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2615 ["Remove base64" gnus-article-de-base64-unreadable t]
2616 ["Treat html" gnus-article-wash-html t]
2617 ["Decode HZ" gnus-article-decode-HZ t]))
2619 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2621 (when (boundp 'gnus-summary-post-menu)
2622 (define-key gnus-article-mode-map [menu-bar post]
2623 (cons "Post" gnus-summary-post-menu)))
2625 (gnus-run-hooks 'gnus-article-menu-hook)))
2627 (defun gnus-article-mode ()
2628 "Major mode for displaying an article.
2630 All normal editing commands are switched off.
2632 The following commands are available in addition to all summary mode
2634 \\<gnus-article-mode-map>
2635 \\[gnus-article-next-page]\t Scroll the article one page forwards
2636 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2637 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2638 \\[gnus-article-show-summary]\t Display the summary buffer
2639 \\[gnus-article-mail]\t Send a reply to the address near point
2640 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2641 \\[gnus-info-find-node]\t Go to the Gnus info node"
2643 (when (gnus-visual-p 'article-menu 'menu)
2644 (gnus-article-make-menu-bar))
2645 (gnus-simplify-mode-line)
2646 (setq mode-name "Article")
2647 (setq major-mode 'gnus-article-mode)
2648 (make-local-variable 'minor-mode-alist)
2649 (use-local-map gnus-article-mode-map)
2650 (gnus-update-format-specifications nil 'article-mode)
2651 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2652 (make-local-variable 'gnus-page-broken)
2653 (make-local-variable 'gnus-button-marker-list)
2654 (make-local-variable 'gnus-article-current-summary)
2655 (make-local-variable 'gnus-article-mime-handles)
2656 (make-local-variable 'gnus-article-decoded-p)
2657 (make-local-variable 'gnus-article-mime-handle-alist)
2658 (make-local-variable 'gnus-article-wash-types)
2659 (gnus-set-default-directory)
2660 (buffer-disable-undo)
2661 (setq buffer-read-only t)
2662 (set-syntax-table gnus-article-mode-syntax-table)
2663 (mm-enable-multibyte)
2664 (gnus-run-hooks 'gnus-article-mode-hook))
2666 (defun gnus-article-setup-buffer ()
2667 "Initialize the article buffer."
2668 (let* ((name (if gnus-single-article-buffer "*Article*"
2669 (concat "*Article " gnus-newsgroup-name "*")))
2671 (progn (string-match "\\*Article" name)
2672 (concat " *Original Article"
2673 (substring name (match-end 0))))))
2674 (setq gnus-article-buffer name)
2675 (setq gnus-original-article-buffer original)
2676 (setq gnus-article-mime-handle-alist nil)
2677 ;; This might be a variable local to the summary buffer.
2678 (unless gnus-single-article-buffer
2680 (set-buffer gnus-summary-buffer)
2681 (setq gnus-article-buffer name)
2682 (setq gnus-original-article-buffer original)
2683 (gnus-set-global-variables)))
2684 (gnus-article-setup-highlight-words)
2685 ;; Init original article buffer.
2687 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2688 (mm-enable-multibyte)
2689 (setq major-mode 'gnus-original-article-mode)
2690 (make-local-variable 'gnus-original-article))
2691 (if (get-buffer name)
2694 (when gnus-article-mime-handles
2695 (mm-destroy-parts gnus-article-mime-handles)
2696 (setq gnus-article-mime-handles nil))
2697 ;; Set it to nil in article-buffer!
2698 (setq gnus-article-mime-handle-alist nil)
2699 (buffer-disable-undo)
2700 (setq buffer-read-only t)
2701 (unless (eq major-mode 'gnus-article-mode)
2702 (gnus-article-mode))
2705 (set-buffer (gnus-get-buffer-create name))
2707 (make-local-variable 'gnus-summary-buffer)
2708 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2709 (current-buffer)))))
2711 ;; Set article window start at LINE, where LINE is the number of lines
2712 ;; from the head of the article.
2713 (defun gnus-article-set-window-start (&optional line)
2715 (get-buffer-window gnus-article-buffer t)
2717 (set-buffer gnus-article-buffer)
2718 (goto-char (point-min))
2721 (gnus-message 6 "Moved to bookmark")
2722 (search-forward "\n\n" nil t)
2726 (defun gnus-article-prepare (article &optional all-headers header)
2727 "Prepare ARTICLE in article mode buffer.
2728 ARTICLE should either be an article number or a Message-ID.
2729 If ARTICLE is an id, HEADER should be the article headers.
2730 If ALL-HEADERS is non-nil, no headers are hidden."
2732 ;; Make sure we start in a summary buffer.
2733 (unless (eq major-mode 'gnus-summary-mode)
2734 (set-buffer gnus-summary-buffer))
2735 (setq gnus-summary-buffer (current-buffer))
2736 (let* ((gnus-article (if header (mail-header-number header) article))
2737 (summary-buffer (current-buffer))
2738 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2739 (group gnus-newsgroup-name)
2742 (gnus-article-setup-buffer)
2743 (set-buffer gnus-article-buffer)
2744 ;; Deactivate active regions.
2745 (when (and (boundp 'transient-mark-mode)
2746 transient-mark-mode)
2747 (setq mark-active nil))
2748 (if (not (setq result (let ((buffer-read-only nil))
2749 (gnus-request-article-this-buffer
2751 ;; There is no such article.
2753 (when (and (numberp article)
2754 (not (memq article gnus-newsgroup-sparse)))
2755 (setq gnus-article-current
2756 (cons gnus-newsgroup-name article))
2757 (set-buffer gnus-summary-buffer)
2758 (setq gnus-current-article article)
2759 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2761 (gnus-summary-set-agent-mark article)
2762 (message "Message marked for downloading"))
2763 (gnus-summary-mark-article article gnus-canceled-mark)
2764 (unless (memq article gnus-newsgroup-sparse)
2765 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2766 (if (or (eq result 'pseudo)
2767 (eq result 'nneething))
2770 (set-buffer summary-buffer)
2771 (push article gnus-newsgroup-history)
2772 (setq gnus-last-article gnus-current-article
2773 gnus-current-article 0
2774 gnus-current-headers nil
2775 gnus-article-current nil)
2776 (if (eq result 'nneething)
2777 (gnus-configure-windows 'summary)
2778 (gnus-configure-windows 'article))
2779 (gnus-set-global-variables))
2780 (let ((gnus-article-mime-handle-alist-1
2781 gnus-article-mime-handle-alist))
2782 (gnus-set-mode-line 'article)))
2783 ;; The result from the `request' was an actual article -
2784 ;; or at least some text that is now displayed in the
2786 (when (and (numberp article)
2787 (not (eq article gnus-current-article)))
2788 ;; Seems like a new article has been selected.
2789 ;; `gnus-current-article' must be an article number.
2791 (set-buffer summary-buffer)
2792 (push article gnus-newsgroup-history)
2793 (setq gnus-last-article gnus-current-article
2794 gnus-current-article article
2795 gnus-current-headers
2796 (gnus-summary-article-header gnus-current-article)
2797 gnus-article-current
2798 (cons gnus-newsgroup-name gnus-current-article))
2799 (unless (vectorp gnus-current-headers)
2800 (setq gnus-current-headers nil))
2801 (gnus-summary-goto-subject gnus-current-article)
2802 (when (gnus-summary-show-thread)
2803 ;; If the summary buffer really was folded, the
2804 ;; previous goto may not actually have gone to
2805 ;; the right article, but the thread root instead.
2807 (gnus-summary-goto-subject gnus-current-article))
2808 (gnus-run-hooks 'gnus-mark-article-hook)
2809 (gnus-set-mode-line 'summary)
2810 (when (gnus-visual-p 'article-highlight 'highlight)
2811 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2812 ;; Set the global newsgroup variables here.
2813 (gnus-set-global-variables)
2814 (setq gnus-have-all-headers
2815 (or all-headers gnus-show-all-headers))))
2816 (when (or (numberp article)
2818 (gnus-article-prepare-display)
2820 (goto-char (point-min))
2821 (setq gnus-page-broken
2822 (when gnus-break-pages
2823 (gnus-narrow-to-page)
2825 (let ((gnus-article-mime-handle-alist-1
2826 gnus-article-mime-handle-alist))
2827 (gnus-set-mode-line 'article))
2829 (set-window-point (get-buffer-window (current-buffer)) (point))
2830 (gnus-configure-windows 'article)
2834 (defun gnus-article-prepare-display ()
2835 "Make the current buffer look like a nice article."
2836 ;; Hooks for getting information from the article.
2837 ;; This hook must be called before being narrowed.
2838 (let ((gnus-article-buffer (current-buffer))
2840 (unless (eq major-mode 'gnus-article-mode)
2841 (gnus-article-mode))
2842 (setq buffer-read-only nil
2843 gnus-article-wash-types nil)
2844 (gnus-run-hooks 'gnus-tmp-internal-hook)
2845 (when gnus-display-mime-function
2846 (funcall gnus-display-mime-function))
2847 (gnus-run-hooks 'gnus-article-prepare-hook)))
2850 ;;; Gnus MIME viewing functions
2853 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2854 "The following specs can be used:
2856 %T MIME type, along with additional info
2857 %n The `name' parameter
2858 %d The description, if any
2859 %l The length of the encoded part
2860 %p The part identifier number
2861 %e Dots if the part isn't displayed")
2863 (defvar gnus-mime-button-line-format-alist
2864 '((?t gnus-tmp-type ?s)
2865 (?T gnus-tmp-type-long ?s)
2866 (?n gnus-tmp-name ?s)
2867 (?d gnus-tmp-description ?s)
2869 (?l gnus-tmp-length ?d)
2870 (?e gnus-tmp-dots ?s)))
2872 (defvar gnus-mime-button-commands
2873 '((gnus-article-press-button "\r" "Toggle Display")
2874 (gnus-mime-view-part "v" "View Interactively...")
2875 (gnus-mime-view-part-as-type "t" "View As Type...")
2876 (gnus-mime-save-part "o" "Save...")
2877 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2878 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2879 (gnus-mime-internalize-part "E" "View Internally")
2880 (gnus-mime-externalize-part "e" "View Externally")
2881 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2883 (defun gnus-article-mime-part-status ()
2884 (if gnus-article-mime-handle-alist-1
2885 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2888 (defvar gnus-mime-button-map
2889 (let ((map (make-sparse-keymap)))
2890 (set-keymap-parent map gnus-article-mode-map)
2891 (define-key map gnus-mouse-2 'gnus-article-push-button)
2892 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
2893 (dolist (c gnus-mime-button-commands)
2894 (define-key map (cadr c) (car c)))
2897 (defun gnus-mime-button-menu (event)
2898 "Construct a context-sensitive menu of MIME commands."
2901 (let ((pos (event-start event)))
2902 (set-buffer (window-buffer (posn-window pos)))
2903 (goto-char (posn-point pos))
2904 (gnus-article-check-buffer)
2905 (let ((response (x-popup-menu
2907 ("" ,@(mapcar (lambda (c)
2908 (cons (caddr c) (car c)))
2909 gnus-mime-button-commands))))))
2911 (call-interactively response))))))
2913 (defun gnus-mime-view-all-parts (&optional handles)
2914 "View all the MIME parts."
2916 (save-current-buffer
2917 (set-buffer gnus-article-buffer)
2918 (let ((handles (or handles gnus-article-mime-handles))
2919 (mail-parse-charset gnus-newsgroup-charset)
2920 (mail-parse-ignored-charsets
2921 (save-excursion (set-buffer gnus-summary-buffer)
2922 gnus-newsgroup-ignored-charsets)))
2923 (if (stringp (car handles))
2924 (gnus-mime-view-all-parts (cdr handles))
2925 (mapcar 'mm-display-part handles)))))
2927 (defun gnus-mime-save-part ()
2928 "Save the MIME part under point."
2930 (gnus-article-check-buffer)
2931 (let ((data (get-text-property (point) 'gnus-data)))
2932 (mm-save-part data)))
2934 (defun gnus-mime-pipe-part ()
2935 "Pipe the MIME part under point to a process."
2937 (gnus-article-check-buffer)
2938 (let ((data (get-text-property (point) 'gnus-data)))
2939 (mm-pipe-part data)))
2941 (defun gnus-mime-view-part ()
2942 "Interactively choose a viewing method for the MIME part under point."
2944 (gnus-article-check-buffer)
2945 (let ((data (get-text-property (point) 'gnus-data)))
2946 (mm-interactively-view-part data)))
2948 (defun gnus-mime-view-part-as-type-internal ()
2949 (gnus-article-check-buffer)
2950 (let* ((name (mail-content-type-get
2951 (mm-handle-type (get-text-property (point) 'gnus-data))
2953 (def-type (and name (mm-default-file-encoding name))))
2954 (and def-type (cons def-type 0))))
2956 (defun gnus-mime-view-part-as-type (mime-type)
2957 "Choose a MIME media type, and view the part as such."
2959 (list (completing-read
2960 "View as MIME type: "
2961 (mapcar #'list (mailcap-mime-types))
2963 (gnus-mime-view-part-as-type-internal))))
2964 (gnus-article-check-buffer)
2965 (let ((handle (get-text-property (point) 'gnus-data)))
2966 (gnus-mm-display-part
2967 (mm-make-handle (mm-handle-buffer handle)
2968 (cons mime-type (cdr (mm-handle-type handle)))
2969 (mm-handle-encoding handle)
2970 (mm-handle-undisplayer handle)
2971 (mm-handle-disposition handle)
2972 (mm-handle-description handle)
2973 (mm-handle-cache handle)
2974 (mm-handle-id handle)))))
2976 (defun gnus-mime-copy-part (&optional handle)
2977 "Put the the MIME part under point into a new buffer."
2979 (gnus-article-check-buffer)
2980 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2981 (contents (mm-get-part handle))|
2982 (base (file-name-nondirectory
2984 (mail-content-type-get (mm-handle-type handle) 'name)
2985 (mail-content-type-get (mm-handle-type handle)
2988 (buffer (generate-new-buffer base)))
2989 (switch-to-buffer buffer)
2991 ;; We do it this way to make `normal-mode' set the appropriate mode.
2994 (setq buffer-file-name (expand-file-name base))
2996 (setq buffer-file-name nil))
2997 (goto-char (point-min))))
2999 (defun gnus-mime-inline-part (&optional handle)
3000 "Insert the MIME part under point into the current buffer."
3002 (gnus-article-check-buffer)
3003 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3007 (if (mm-handle-undisplayer handle)
3008 (mm-remove-part handle)
3009 (setq contents (mm-get-part handle))
3011 (mm-insert-inline handle contents)
3014 (defun gnus-mime-externalize-part (&optional handle)
3015 "View the MIME part under point with an external viewer."
3017 (gnus-article-check-buffer)
3018 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3019 (mm-user-display-methods nil)
3020 (mm-inlined-types nil)
3021 (mail-parse-charset gnus-newsgroup-charset)
3022 (mail-parse-ignored-charsets
3023 (save-excursion (set-buffer gnus-summary-buffer)
3024 gnus-newsgroup-ignored-charsets)))
3025 (if (mm-handle-undisplayer handle)
3026 (mm-remove-part handle)
3027 (mm-display-part handle))))
3029 (defun gnus-mime-internalize-part (&optional handle)
3030 "View the MIME part under point with an internal viewer.
3031 In no internal viewer is available, use an external viewer."
3033 (gnus-article-check-buffer)
3034 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3035 (mm-inlined-types '(".*"))
3036 (mm-inline-large-images t)
3037 (mail-parse-charset gnus-newsgroup-charset)
3038 (mail-parse-ignored-charsets
3039 (save-excursion (set-buffer gnus-summary-buffer)
3040 gnus-newsgroup-ignored-charsets)))
3041 (if (mm-handle-undisplayer handle)
3042 (mm-remove-part handle)
3043 (mm-display-part handle))))
3045 (defun gnus-article-part-wrapper (n function)
3046 (save-current-buffer
3047 (set-buffer gnus-article-buffer)
3048 (when (> n (length gnus-article-mime-handle-alist))
3049 (error "No such part"))
3050 (gnus-article-goto-part n)
3051 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3052 (funcall function handle))))
3054 (defun gnus-article-pipe-part (n)
3055 "Pipe MIME part N, which is the numerical prefix."
3057 (gnus-article-part-wrapper n 'mm-pipe-part))
3059 (defun gnus-article-save-part (n)
3060 "Save MIME part N, which is the numerical prefix."
3062 (gnus-article-part-wrapper n 'mm-save-part))
3064 (defun gnus-article-interactively-view-part (n)
3065 "View MIME part N interactively, which is the numerical prefix."
3067 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3069 (defun gnus-article-copy-part (n)
3070 "Copy MIME part N, which is the numerical prefix."
3072 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3074 (defun gnus-article-externalize-part (n)
3075 "View MIME part N externally, which is the numerical prefix."
3077 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3079 (defun gnus-article-inline-part (n)
3080 "Inline MIME part N, which is the numerical prefix."
3082 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3084 (defun gnus-article-mime-match-handle-first (condition)
3086 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3087 (while (setq ihandle (pop alist))
3089 ((functionp condition)
3090 (funcall condition (cdr ihandle)))
3091 ((eq condition 'undisplayed)
3092 (not (or (mm-handle-undisplayer (cdr ihandle))
3093 (equal (mm-handle-media-type (cdr ihandle))
3094 "multipart/alternative"))))
3095 ((eq condition 'undisplayed-alternative)
3096 (not (mm-handle-undisplayer (cdr ihandle))))
3098 (gnus-article-goto-part (car ihandle))
3099 (or (not n) (< (car ihandle) n)))
3100 (setq n (car ihandle))))
3104 (defun gnus-article-view-part (&optional n)
3105 "View MIME part N, which is the numerical prefix."
3107 (save-current-buffer
3108 (set-buffer gnus-article-buffer)
3109 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3110 gnus-article-mime-match-handle-function)))
3111 (when (> n (length gnus-article-mime-handle-alist))
3112 (error "No such part"))
3113 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3114 (when (gnus-article-goto-part n)
3115 (if (equal (car handle) "multipart/alternative")
3116 (gnus-article-press-button)
3117 (when (eq (gnus-mm-display-part handle) 'internal)
3118 (gnus-set-window-start)))))))
3120 (defun gnus-mm-display-part (handle)
3121 "Display HANDLE and fix MIME button."
3122 (let ((id (get-text-property (point) 'gnus-part))
3127 (let ((window (selected-window))
3128 (mail-parse-charset gnus-newsgroup-charset)
3129 (mail-parse-ignored-charsets
3130 (save-excursion (set-buffer gnus-summary-buffer)
3131 gnus-newsgroup-ignored-charsets)))
3134 (let ((win (get-buffer-window (current-buffer) t))
3137 (select-window win))
3140 (if (mm-handle-displayed-p handle)
3141 ;; This will remove the part.
3142 (mm-display-part handle)
3144 (narrow-to-region (point) (1+ (point)))
3145 (mm-display-part handle)
3146 ;; We narrow to the part itself and
3147 ;; then call the treatment functions.
3148 (goto-char (point-min))
3150 (narrow-to-region (point) (point-max))
3153 (1- (length gnus-article-mime-handles))
3154 (mm-handle-media-type handle)))))
3155 (select-window window))))
3157 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3158 (gnus-insert-mime-button
3159 handle id (list (mm-handle-displayed-p handle)))
3160 (goto-char point))))
3162 (defun gnus-article-goto-part (n)
3163 "Go to MIME part N."
3164 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3166 (goto-char point))))
3168 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3169 (let ((gnus-tmp-name
3170 (or (mail-content-type-get (mm-handle-type handle)
3172 (mail-content-type-get (mm-handle-disposition handle)
3175 (gnus-tmp-type (mm-handle-media-type handle))
3176 (gnus-tmp-description
3177 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3180 (if (if displayed (car displayed)
3181 (mm-handle-displayed-p handle))
3183 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3185 gnus-tmp-type-long b e)
3186 (when (string-match ".*/" gnus-tmp-name)
3187 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3188 (setq gnus-tmp-type-long (concat gnus-tmp-type
3189 (and (not (equal gnus-tmp-name ""))
3190 (concat "; " gnus-tmp-name))))
3191 (or (equal gnus-tmp-description "")
3192 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3197 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3198 `(local-map ,gnus-mime-button-map
3199 keymap ,gnus-mime-button-map
3200 gnus-callback gnus-mm-display-part
3201 gnus-part ,gnus-tmp-id
3202 article-type annotation
3205 (widget-convert-button
3208 :action 'gnus-widget-press-button
3209 :button-keymap gnus-mime-button-map
3211 (lambda (widget/window &optional overlay pos)
3212 ;; Needed to properly clear the message due to a bug in
3213 ;; wid-edit (XEmacs only).
3214 (if (boundp 'help-echo-owns-message)
3215 (setq help-echo-owns-message t))
3217 "%S: %s the MIME part; %S: more options"
3218 (aref gnus-mouse-2 0)
3219 ;; XEmacs will get a single widget arg; Emacs 21 will get
3220 ;; window, overlay, position.
3221 (if (mm-handle-displayed-p
3223 (with-current-buffer (overlay-buffer overlay)
3224 (widget-get (widget-at (overlay-start overlay))
3226 (widget-get widget/window :mime-handle)))
3228 (aref gnus-down-mouse-3 0))))))
3230 (defun gnus-widget-press-button (elems el)
3231 (goto-char (widget-get elems :from))
3232 (gnus-article-press-button))
3234 (defvar gnus-displaying-mime nil)
3236 (defun gnus-display-mime (&optional ihandles)
3237 "Display the MIME parts."
3239 (save-selected-window
3240 (let ((window (get-buffer-window gnus-article-buffer))
3243 (select-window window)
3244 ;; We have to do this since selecting the window
3245 ;; may change the point. So we set the window point.
3246 (set-window-point window point)))
3247 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3248 buffer-read-only handle name type b e display)
3249 (when (and (not ihandles)
3250 (not gnus-displaying-mime))
3251 ;; Top-level call; we clean up.
3252 (when gnus-article-mime-handles
3253 (mm-destroy-parts gnus-article-mime-handles)
3254 (setq gnus-article-mime-handle-alist nil));; A trick.
3255 (setq gnus-article-mime-handles handles)
3256 ;; We allow users to glean info from the handles.
3257 (when gnus-article-mime-part-function
3258 (gnus-mime-part-function handles)))
3260 (or (not (stringp (car handles)))
3263 (when (and (not ihandles)
3264 (not gnus-displaying-mime))
3265 ;; Clean up for mime parts.
3267 (delete-region (point) (point-max)))
3268 (let ((gnus-displaying-mime t))
3269 (gnus-mime-display-part handles)))
3272 (narrow-to-region (point) (point-max))
3273 (gnus-treat-article nil 1 1)
3276 ;; Highlight the headers.
3280 (narrow-to-region (point-min) (point))
3281 (gnus-treat-article 'head))))))))
3283 (defvar gnus-mime-display-multipart-as-mixed nil)
3285 (defun gnus-mime-display-part (handle)
3288 ((not (stringp (car handle)))
3289 (gnus-mime-display-single handle))
3290 ;; User-defined multipart
3291 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3292 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3294 ;; multipart/alternative
3295 ((and (equal (car handle) "multipart/alternative")
3296 (not gnus-mime-display-multipart-as-mixed))
3297 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3298 (push (cons id handle) gnus-article-mime-handle-alist)
3299 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3300 ;; multipart/related
3301 ((and (equal (car handle) "multipart/related")
3302 (not gnus-mime-display-multipart-as-mixed))
3303 ;;;!!!We should find the start part, but we just default
3304 ;;;!!!to the first part.
3305 (gnus-mime-display-part (cadr handle)))
3306 ;; Other multiparts are handled like multipart/mixed.
3308 (gnus-mime-display-mixed (cdr handle)))))
3310 (defun gnus-mime-part-function (handles)
3311 (if (stringp (car handles))
3312 (mapcar 'gnus-mime-part-function (cdr handles))
3313 (funcall gnus-article-mime-part-function handles)))
3315 (defun gnus-mime-display-mixed (handles)
3316 (mapcar 'gnus-mime-display-part handles))
3318 (defun gnus-mime-display-single (handle)
3319 (let ((type (mm-handle-media-type handle))
3320 (ignored gnus-ignored-mime-types)
3327 (when (string-match (pop ignored) type)
3328 (throw 'ignored nil)))
3329 (if (and (setq not-attachment
3330 (and (not (mm-inline-override-p handle))
3331 (or (not (mm-handle-disposition handle))
3332 (equal (car (mm-handle-disposition handle))
3334 (mm-attachment-override-p handle))))
3335 (mm-automatic-display-p handle)
3336 (or (mm-inlined-p handle)
3337 (mm-automatic-external-display-p type)))
3339 (when (equal (mm-handle-media-supertype handle) "text")
3341 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3342 (push (cons id handle) gnus-article-mime-handle-alist)
3343 (when (or (not display)
3344 (not (gnus-unbuttonized-mime-type-p type)))
3345 ;(gnus-article-insert-newline)
3346 (gnus-insert-mime-button
3347 handle id (list (or display (and not-attachment text))))
3348 (gnus-article-insert-newline)
3349 ;(gnus-article-insert-newline)
3351 (let ((beg (point)))
3357 (let ((mail-parse-charset gnus-newsgroup-charset)
3358 (mail-parse-ignored-charsets
3359 (save-excursion (condition-case ()
3360 (set-buffer gnus-summary-buffer)
3362 gnus-newsgroup-ignored-charsets)))
3363 (mm-display-part handle t))
3364 (goto-char (point-max)))
3365 ((and text not-attachment)
3369 (gnus-article-insert-newline)
3370 (mm-insert-inline handle (mm-get-part handle))
3371 (goto-char (point-max))))
3375 (narrow-to-region beg (point))
3377 nil (length gnus-article-mime-handle-alist)
3378 (1- (length gnus-article-mime-handles))
3379 (mm-handle-media-type handle)))))))))
3381 (defun gnus-unbuttonized-mime-type-p (type)
3382 "Say whether TYPE is to be unbuttonized."
3383 (unless gnus-inhibit-mime-unbuttonizing
3385 (let ((types gnus-unbuttonized-mime-types))
3387 (when (string-match (pop types) type)
3388 (throw 'found t)))))))
3390 (defun gnus-article-insert-newline ()
3391 "Insert a newline, but mark it as undeletable."
3392 (gnus-put-text-property
3393 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3395 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3396 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3399 handle buffer-read-only from props begend not-pref)
3400 (save-window-excursion
3403 (narrow-to-region (car ibegend)
3406 (goto-char (car ibegend))
3409 (delete-region (point-min) (point-max))
3410 (mm-remove-parts handles))
3411 (setq begend (list (point-marker)))
3413 (unless (setq not-pref (cadr (member preferred ihandles)))
3414 (setq not-pref (car ihandles)))
3416 (not (gnus-unbuttonized-mime-type-p
3417 "multipart/alternative")))
3418 (gnus-add-text-properties
3421 (insert (format "%d. " id))
3425 (unless ,(not ibegend)
3426 (setq gnus-article-mime-handle-alist
3427 ',gnus-article-mime-handle-alist))
3428 (gnus-mime-display-alternative
3429 ',ihandles ',not-pref ',begend ,id))
3430 local-map ,gnus-mime-button-map
3431 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3432 face ,gnus-article-button-face
3433 keymap ,gnus-mime-button-map
3436 (widget-convert-button 'link from (point)
3437 :action 'gnus-widget-press-button
3438 :button-keymap gnus-widget-button-keymap)
3440 (while (setq handle (pop handles))
3441 (gnus-add-text-properties
3444 (insert (format "(%c) %-18s"
3445 (if (equal handle preferred) ?* ? )
3446 (mm-handle-media-type handle)))
3450 (unless ,(not ibegend)
3451 (setq gnus-article-mime-handle-alist
3452 ',gnus-article-mime-handle-alist))
3453 (gnus-mime-display-alternative
3454 ',ihandles ',handle ',begend ,id))
3455 local-map ,gnus-mime-button-map
3456 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3457 face ,gnus-article-button-face
3458 keymap ,gnus-mime-button-map
3461 (widget-convert-button 'link from (point)
3462 :action 'gnus-widget-press-button
3463 :button-keymap gnus-widget-button-keymap)
3467 (if (stringp (car preferred))
3468 (gnus-display-mime preferred)
3469 (let ((mail-parse-charset gnus-newsgroup-charset)
3470 (mail-parse-ignored-charsets
3471 (save-excursion (set-buffer gnus-summary-buffer)
3472 gnus-newsgroup-ignored-charsets)))
3473 (mm-display-part preferred)
3477 (narrow-to-region (car begend) (point-max))
3479 nil (length gnus-article-mime-handle-alist)
3480 (1- (length gnus-article-mime-handles))
3481 (mm-handle-media-type handle))))))
3482 (goto-char (point-max))
3483 (setcdr begend (point-marker)))))
3485 (goto-char point))))
3487 (defun gnus-article-wash-status ()
3488 "Return a string which display status of article washing."
3490 (set-buffer gnus-article-buffer)
3491 (let ((cite (memq 'cite gnus-article-wash-types))
3492 (headers (memq 'headers gnus-article-wash-types))
3493 (boring (memq 'boring-headers gnus-article-wash-types))
3494 (pgp (memq 'pgp gnus-article-wash-types))
3495 (pem (memq 'pem gnus-article-wash-types))
3496 (signature (memq 'signature gnus-article-wash-types))
3497 (overstrike (memq 'overstrike gnus-article-wash-types))
3498 (emphasis (memq 'emphasis gnus-article-wash-types)))
3499 (format "%c%c%c%c%c%c"
3501 (if (or headers boring) ?h ? )
3502 (if (or pgp pem) ?p ? )
3503 (if signature ?s ? )
3504 (if overstrike ?o ? )
3505 (if emphasis ?e ? )))))
3507 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3509 (defun gnus-article-maybe-hide-headers ()
3510 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3511 Provided for backwards compatibility."
3512 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3513 (not (save-excursion (set-buffer gnus-summary-buffer)
3514 gnus-have-all-headers)))
3515 (not gnus-inhibit-hiding))
3516 (gnus-article-hide-headers)))
3520 (defun gnus-output-to-file (file-name)
3521 "Append the current article to a file named FILE-NAME."
3522 (let ((artbuf (current-buffer)))
3524 (insert-buffer-substring artbuf)
3525 ;; Append newline at end of the buffer as separator, and then
3527 (goto-char (point-max))
3529 (mm-append-to-file (point-min) (point-max) file-name)
3532 (defun gnus-narrow-to-page (&optional arg)
3533 "Narrow the article buffer to a page.
3534 If given a numerical ARG, move forward ARG pages."
3536 (setq arg (if arg (prefix-numeric-value arg) 0))
3538 (set-buffer gnus-article-buffer)
3539 (goto-char (point-min))
3541 ;; Remove any old next/prev buttons.
3542 (when (gnus-visual-p 'page-marker)
3543 (let ((buffer-read-only nil))
3544 (gnus-remove-text-with-property 'gnus-prev)
3545 (gnus-remove-text-with-property 'gnus-next)))
3548 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3550 (re-search-forward page-delimiter nil 'move arg)))
3551 (goto-char (match-end 0)))
3554 (if (re-search-forward page-delimiter nil 'move)
3557 (when (and (gnus-visual-p 'page-marker)
3558 (not (= (point-min) 1)))
3560 (goto-char (point-min))
3561 (gnus-insert-prev-page-button)))
3562 (when (and (gnus-visual-p 'page-marker)
3563 (< (+ (point-max) 2) (buffer-size)))
3565 (goto-char (point-max))
3566 (gnus-insert-next-page-button)))))
3568 ;; Article mode commands
3570 (defun gnus-article-goto-next-page ()
3571 "Show the next page of the article."
3573 (when (gnus-article-next-page)
3574 (goto-char (point-min))
3575 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3577 (defun gnus-article-goto-prev-page ()
3578 "Show the next page of the article."
3580 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3581 (gnus-article-prev-page nil)))
3583 (defun gnus-article-next-page (&optional lines)
3584 "Show the next page of the current article.
3585 If end of article, return non-nil. Otherwise return nil.
3586 Argument LINES specifies lines to be scrolled up."
3588 (move-to-window-line -1)
3591 (and (pos-visible-in-window-p) ;Not continuation line.
3593 ;; Nothing in this page.
3594 (if (or (not gnus-page-broken)
3597 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3599 (gnus-narrow-to-page 1) ;Go to next page.
3601 ;; More in this page.
3602 (let ((scroll-in-place nil))
3606 ;; Long lines may cause an end-of-buffer error.
3607 (goto-char (point-max)))))
3608 (move-to-window-line 0)
3611 (defun gnus-article-prev-page (&optional lines)
3612 "Show previous page of current article.
3613 Argument LINES specifies lines to be scrolled down."
3615 (move-to-window-line 0)
3616 (if (and gnus-page-broken
3618 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3620 (gnus-narrow-to-page -1) ;Go to previous page.
3621 (goto-char (point-max))
3623 (let ((scroll-in-place nil))
3627 (beginning-of-buffer
3628 (goto-char (point-min))))
3629 (move-to-window-line 0)))))
3631 (defun gnus-article-refer-article ()
3632 "Read article specified by message-id around point."
3634 (let ((point (point)))
3635 (search-forward ">" nil t) ;Move point to end of "<....>".
3636 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3637 (let ((message-id (match-string 1)))
3639 (set-buffer gnus-summary-buffer)
3640 (gnus-summary-refer-article message-id))
3642 (error "No references around point"))))
3644 (defun gnus-article-show-summary ()
3645 "Reconfigure windows to show summary buffer."
3647 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3648 (error "There is no summary buffer for this article buffer")
3649 (gnus-article-set-globals)
3650 (gnus-configure-windows 'article)
3651 (gnus-summary-goto-subject gnus-current-article)
3652 (gnus-summary-position-point)))
3654 (defun gnus-article-describe-briefly ()
3655 "Describe article mode commands briefly."
3657 (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")))
3659 (defun gnus-article-summary-command ()
3660 "Execute the last keystroke in the summary buffer."
3662 (let ((obuf (current-buffer))
3663 (owin (current-window-configuration))
3665 (switch-to-buffer gnus-article-current-summary 'norecord)
3666 (setq func (lookup-key (current-local-map) (this-command-keys)))
3667 (call-interactively func)
3669 (set-window-configuration owin)
3670 (set-window-point (get-buffer-window (current-buffer)) (point))))
3672 (defun gnus-article-summary-command-nosave ()
3673 "Execute the last keystroke in the summary buffer."
3676 (pop-to-buffer gnus-article-current-summary 'norecord)
3677 (setq func (lookup-key (current-local-map) (this-command-keys)))
3678 (call-interactively func)))
3680 (defun gnus-article-check-buffer ()
3681 "Beep if not in an article buffer."
3682 (unless (equal major-mode 'gnus-article-mode)
3683 (error "Command invoked outside of a Gnus article buffer")))
3685 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3686 "Read a summary buffer key sequence and execute it from the article buffer."
3688 (gnus-article-check-buffer)
3690 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3691 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3692 "=" "^" "\M-^" "|"))
3698 '("n" "Gn" "p" "Gp"))
3701 (set-buffer gnus-article-current-summary)
3702 (let (gnus-pick-mode)
3703 (push (or key last-command-event) unread-command-events)
3704 (setq keys (if gnus-xemacs
3705 (events-to-keys (read-key-sequence nil))
3706 (read-key-sequence nil)))))
3710 (if (or (member keys nosaves)
3711 (member keys nosave-but-article)
3712 (member keys nosave-in-article))
3714 (save-window-excursion
3715 (pop-to-buffer gnus-article-current-summary 'norecord)
3716 ;; We disable the pick minor mode commands.
3717 (let (gnus-pick-mode)
3718 (setq func (lookup-key (current-local-map) keys))))
3722 (unless (member keys nosave-in-article)
3723 (set-buffer gnus-article-current-summary))
3724 (call-interactively func)
3725 (setq new-sum-point (point)))
3726 (when (member keys nosave-but-article)
3727 (pop-to-buffer gnus-article-buffer 'norecord)))
3728 ;; These commands should restore window configuration.
3729 (let ((obuf (current-buffer))
3730 (owin (current-window-configuration))
3732 (summary gnus-article-current-summary)
3733 func in-buffer selected)
3734 (if not-restore-window
3735 (pop-to-buffer summary 'norecord)
3736 (switch-to-buffer summary 'norecord))
3737 (setq in-buffer (current-buffer))
3738 ;; We disable the pick minor mode commands.
3739 (if (setq func (let (gnus-pick-mode)
3740 (lookup-key (current-local-map) keys)))
3742 (call-interactively func)
3743 (setq new-sum-point (point)))
3745 (when (eq in-buffer (current-buffer))
3746 (setq selected (gnus-summary-select-article))
3748 (unless not-restore-window
3749 (set-window-configuration owin))
3750 (when (eq selected 'old)
3752 (set-window-start (get-buffer-window (current-buffer))
3754 (set-window-point (get-buffer-window (current-buffer))
3756 (let ((win (get-buffer-window gnus-article-current-summary)))
3758 (set-window-point win new-sum-point))))))))
3760 (defun gnus-article-hide (&optional arg force)
3761 "Hide all the gruft in the current article.
3762 This means that PGP stuff, signatures, cited text and (some)
3763 headers will be hidden.
3764 If given a prefix, show the hidden text instead."
3765 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3766 (gnus-article-hide-headers arg)
3767 (gnus-article-hide-list-identifiers arg)
3768 (gnus-article-hide-pgp arg)
3769 (gnus-article-hide-citation-maybe arg force)
3770 (gnus-article-hide-signature arg))
3772 (defun gnus-article-maybe-highlight ()
3773 "Do some article highlighting if article highlighting is requested."
3774 (when (gnus-visual-p 'article-highlight 'highlight)
3775 (gnus-article-highlight-some)))
3777 (defun gnus-check-group-server ()
3778 ;; Make sure the connection to the server is alive.
3779 (unless (gnus-server-opened
3780 (gnus-find-method-for-group gnus-newsgroup-name))
3781 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3782 (gnus-request-group gnus-newsgroup-name t)))
3784 (defun gnus-request-article-this-buffer (article group)
3785 "Get an article and insert it into this buffer."
3786 (let (do-update-line sparse-header)
3790 (gnus-kill-all-overlays)
3791 (setq group (or group gnus-newsgroup-name))
3793 ;; Using `gnus-request-article' directly will insert the article into
3794 ;; `nntp-server-buffer' - so we'll save some time by not having to
3795 ;; copy it from the server buffer into the article buffer.
3797 ;; We only request an article by message-id when we do not have the
3798 ;; headers for it, so we'll have to get those.
3799 (when (stringp article)
3800 (gnus-read-header article))
3802 ;; If the article number is negative, that means that this article
3803 ;; doesn't belong in this newsgroup (possibly), so we find its
3804 ;; message-id and request it by id instead of number.
3805 (when (and (numberp article)
3807 (get-buffer gnus-summary-buffer)
3808 (gnus-buffer-exists-p gnus-summary-buffer))
3810 (set-buffer gnus-summary-buffer)
3811 (let ((header (gnus-summary-article-header article)))
3814 ((memq article gnus-newsgroup-sparse)
3815 ;; This is a sparse gap article.
3816 (setq do-update-line article)
3817 (setq article (mail-header-id header))
3818 (setq sparse-header (gnus-read-header article))
3819 (setq gnus-newsgroup-sparse
3820 (delq article gnus-newsgroup-sparse)))
3822 ;; It's a real article.
3823 (setq article (mail-header-id header)))
3825 ;; It is an extracted pseudo-article.
3826 (setq article 'pseudo)
3827 (gnus-request-pseudo-article header))))
3829 (let ((method (gnus-find-method-for-group
3830 gnus-newsgroup-name)))
3831 (when (and (eq (car method) 'nneething)
3833 (let ((dir (expand-file-name
3834 (mail-header-subject header)
3835 (file-name-as-directory
3836 (or (cadr (assq 'nneething-address method))
3838 (when (file-directory-p dir)
3839 (setq article 'nneething)
3840 (gnus-group-enter-directory dir))))))))
3843 ;; Refuse to select canceled articles.
3844 ((and (numberp article)
3846 (get-buffer gnus-summary-buffer)
3847 (gnus-buffer-exists-p gnus-summary-buffer)
3848 (eq (cdr (save-excursion
3849 (set-buffer gnus-summary-buffer)
3850 (assq article gnus-newsgroup-reads)))
3851 gnus-canceled-mark))
3853 ;; We first check `gnus-original-article-buffer'.
3854 ((and (get-buffer gnus-original-article-buffer)
3857 (set-buffer gnus-original-article-buffer)
3858 (and (equal (car gnus-original-article) group)
3859 (eq (cdr gnus-original-article) article))))
3860 (insert-buffer-substring gnus-original-article-buffer)
3862 ;; Check the backlog.
3863 ((and gnus-keep-backlog
3864 (gnus-backlog-request-article group article (current-buffer)))
3866 ;; Check asynchronous pre-fetch.
3867 ((gnus-async-request-fetched-article group article (current-buffer))
3868 (gnus-async-prefetch-next group article gnus-summary-buffer)
3869 (when (and (numberp article) gnus-keep-backlog)
3870 (gnus-backlog-enter-article group article (current-buffer)))
3873 ((and gnus-use-cache
3875 (gnus-cache-request-article article group))
3877 ;; Get the article and put into the article buffer.
3878 ((or (stringp article)
3880 (let ((gnus-override-method gnus-override-method)
3881 (methods (and (stringp article)
3882 gnus-refer-article-method))
3884 (buffer-read-only nil))
3889 (when (and (null gnus-override-method)
3891 (setq gnus-override-method (pop methods)))
3893 (when (eq gnus-override-method 'current)
3894 (setq gnus-override-method gnus-current-select-method))
3896 (gnus-kill-all-overlays)
3897 (let ((gnus-newsgroup-name group))
3898 (gnus-check-group-server))
3899 (when (gnus-request-article article group (current-buffer))
3900 (when (numberp article)
3901 (gnus-async-prefetch-next group article
3902 gnus-summary-buffer)
3903 (when gnus-keep-backlog
3904 (gnus-backlog-enter-article
3905 group article (current-buffer))))
3906 (setq result 'article))
3909 (setq gnus-override-method (pop methods))
3910 (setq result 'done))))
3911 (and (eq result 'article) 'article)))
3915 ;; Associate this article with the current summary buffer.
3916 (setq gnus-article-current-summary gnus-summary-buffer)
3918 ;; Take the article from the original article buffer
3919 ;; and place it in the buffer it's supposed to be in.
3920 (when (and (get-buffer gnus-article-buffer)
3921 (equal (buffer-name (current-buffer))
3922 (buffer-name (get-buffer gnus-article-buffer))))
3924 (if (get-buffer gnus-original-article-buffer)
3925 (set-buffer gnus-original-article-buffer)
3926 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3927 (buffer-disable-undo)
3928 (setq major-mode 'gnus-original-article-mode)
3929 (setq buffer-read-only t))
3930 (let (buffer-read-only)
3932 (insert-buffer-substring gnus-article-buffer))
3933 (setq gnus-original-article (cons group article)))
3936 (run-hooks 'gnus-article-decode-hook)
3937 ;; Mark article as decoded or not.
3938 (setq gnus-article-decoded-p gnus-article-decode-hook))
3940 ;; Update sparse articles.
3941 (when (and do-update-line
3942 (or (numberp article)
3944 (let ((buf (current-buffer)))
3945 (set-buffer gnus-summary-buffer)
3946 (gnus-summary-update-article do-update-line sparse-header)
3947 (gnus-summary-goto-subject do-update-line nil t)
3948 (set-window-point (get-buffer-window (current-buffer) t)
3950 (set-buffer buf))))))
3956 (defcustom gnus-article-edit-mode-hook nil
3957 "Hook run in article edit mode buffers."
3958 :group 'gnus-article-various
3961 (defvar gnus-article-edit-done-function nil)
3963 (defvar gnus-article-edit-mode-map nil)
3965 ;; Should we be using derived.el for this?
3966 (unless gnus-article-edit-mode-map
3967 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3968 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3970 (gnus-define-keys gnus-article-edit-mode-map
3971 "\C-c\C-c" gnus-article-edit-done
3972 "\C-c\C-k" gnus-article-edit-exit)
3974 (gnus-define-keys (gnus-article-edit-wash-map
3975 "\C-c\C-w" gnus-article-edit-mode-map)
3976 "f" gnus-article-edit-full-stops))
3978 (defun gnus-article-edit-mode ()
3979 "Major mode for editing articles.
3980 This is an extended text-mode.
3982 \\{gnus-article-edit-mode-map}"
3984 (setq major-mode 'gnus-article-edit-mode)
3985 (setq mode-name "Article Edit")
3986 (use-local-map gnus-article-edit-mode-map)
3987 (make-local-variable 'gnus-article-edit-done-function)
3988 (make-local-variable 'gnus-prev-winconf)
3989 (setq buffer-read-only nil)
3990 (buffer-enable-undo)
3992 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3994 (defun gnus-article-edit (&optional force)
3995 "Edit the current article.
3996 This will have permanent effect only in mail groups.
3997 If FORCE is non-nil, allow editing of articles even in read-only
4000 (when (and (not force)
4001 (gnus-group-read-only-p))
4002 (error "The current newsgroup does not support article editing"))
4003 (gnus-article-date-original)
4004 (gnus-article-edit-article
4006 `(lambda (no-highlight)
4008 (gnus-summary-edit-article-done
4009 ,(or (mail-header-references gnus-current-headers) "")
4010 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4012 (defun gnus-article-edit-article (start-func exit-func)
4013 "Start editing the contents of the current article buffer."
4014 (let ((winconf (current-window-configuration)))
4015 (set-buffer gnus-article-buffer)
4016 (gnus-article-edit-mode)
4017 (funcall start-func)
4018 (gnus-configure-windows 'edit-article)
4019 (setq gnus-article-edit-done-function exit-func)
4020 (setq gnus-prev-winconf winconf)
4021 (gnus-message 6 "C-c C-c to end edits")))
4023 (defun gnus-article-edit-done (&optional arg)
4024 "Update the article edits and exit."
4029 (when (article-goto-body)
4030 (let ((lines (count-lines (point) (point-max)))
4031 (length (- (point-max) (point)))
4032 (case-fold-search t)
4033 (body (copy-marker (point))))
4034 (goto-char (point-min))
4035 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
4036 (delete-region (match-beginning 1) (match-end 1))
4037 (insert (number-to-string length)))
4038 (goto-char (point-min))
4039 (when (re-search-forward
4040 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
4041 (delete-region (match-beginning 1) (match-end 1))
4042 (insert (number-to-string length)))
4043 (goto-char (point-min))
4044 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
4045 (delete-region (match-beginning 1) (match-end 1))
4046 (insert (number-to-string lines)))))))
4047 (let ((func gnus-article-edit-done-function)
4048 (buf (current-buffer))
4049 (start (window-start)))
4050 (gnus-article-edit-exit)
4053 (let ((buffer-read-only nil))
4055 ;; The cache and backlog have to be flushed somewhat.
4056 (when gnus-keep-backlog
4057 (gnus-backlog-remove-article
4058 (car gnus-article-current) (cdr gnus-article-current)))
4059 ;; Flush original article as well.
4061 (when (get-buffer gnus-original-article-buffer)
4062 (set-buffer gnus-original-article-buffer)
4063 (setq gnus-original-article nil)))
4064 (when gnus-use-cache
4065 (gnus-cache-update-article
4066 (car gnus-article-current) (cdr gnus-article-current))))
4068 (set-window-start (get-buffer-window buf) start)
4069 (set-window-point (get-buffer-window buf) (point))))
4071 (defun gnus-article-edit-exit ()
4072 "Exit the article editing without updating."
4074 ;; We remove all text props from the article buffer.
4075 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4076 (curbuf (current-buffer))
4078 (window-start (window-start)))
4081 (let ((winconf gnus-prev-winconf))
4083 (set-window-configuration winconf)
4084 ;; Tippy-toe some to make sure that point remains where it was.
4085 (save-current-buffer
4087 (set-window-start (get-buffer-window (current-buffer)) window-start)
4090 (defun gnus-article-edit-full-stops ()
4091 "Interactively repair spacing at end of sentences."
4094 (goto-char (point-min))
4095 (search-forward-regexp "^$" nil t)
4096 (let ((case-fold-search nil))
4097 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4100 ;;; Article highlights
4103 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4105 ;;; Internal Variables:
4107 (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\\)\\)"
4108 "Regular expression that matches URLs."
4109 :group 'gnus-article-buttons
4112 (defcustom gnus-button-alist
4113 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4114 0 t gnus-button-message-id 2)
4115 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4116 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4118 gnus-button-fetch-group 4)
4119 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4120 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4121 t gnus-button-message-id 3)
4122 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4123 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4124 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4125 ;; This is how URLs _should_ be embedded in text...
4126 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4128 (,gnus-button-url-regexp 0 t browse-url 0))
4129 "*Alist of regexps matching buttons in article bodies.
4131 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4132 REGEXP: is the string matching text around the button,
4133 BUTTON: is the number of the regexp grouping actually matching the button,
4134 FORM: is a lisp expression which must eval to true for the button to
4136 CALLBACK: is the function to call when the user push this button, and each
4137 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4139 CALLBACK can also be a variable, in that case the value of that
4140 variable it the real callback function."
4141 :group 'gnus-article-buttons
4142 :type '(repeat (list regexp
4143 (integer :tag "Button")
4145 (function :tag "Callback")
4148 (integer :tag "Regexp group")))))
4150 (defcustom gnus-header-button-alist
4151 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4152 0 t gnus-button-message-id 0)
4153 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4154 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4155 0 t gnus-button-mailto 0)
4156 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4157 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4158 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4159 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4160 gnus-button-message-id 3))
4161 "*Alist of headers and regexps to match buttons in article heads.
4163 This alist is very similar to `gnus-button-alist', except that each
4164 alist has an additional HEADER element first in each entry:
4166 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4168 HEADER is a regexp to match a header. For a fuller explanation, see
4169 `gnus-button-alist'."
4170 :group 'gnus-article-buttons
4171 :group 'gnus-article-headers
4172 :type '(repeat (list (regexp :tag "Header")
4174 (integer :tag "Button")
4176 (function :tag "Callback")
4179 (integer :tag "Regexp group")))))
4181 (defvar gnus-button-regexp nil)
4182 (defvar gnus-button-marker-list nil)
4183 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4185 (defvar gnus-button-last nil)
4186 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4190 (defun gnus-article-push-button (event)
4191 "Check text under the mouse pointer for a callback function.
4192 If the text under the mouse pointer has a `gnus-callback' property,
4193 call it with the value of the `gnus-data' text property."
4195 (set-buffer (window-buffer (posn-window (event-start event))))
4196 (let* ((pos (posn-point (event-start event)))
4197 (data (get-text-property pos 'gnus-data))
4198 (fun (get-text-property pos 'gnus-callback)))
4201 (funcall fun data))))
4203 (defun gnus-article-press-button ()
4204 "Check text at point for a callback function.
4205 If the text at point has a `gnus-callback' property,
4206 call it with the value of the `gnus-data' text property."
4208 (let* ((data (get-text-property (point) 'gnus-data))
4209 (fun (get-text-property (point) 'gnus-callback)))
4211 (funcall fun data))))
4213 (defun gnus-article-highlight (&optional force)
4214 "Highlight current article.
4215 This function calls `gnus-article-highlight-headers',
4216 `gnus-article-highlight-citation',
4217 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4218 do the highlighting. See the documentation for those functions."
4219 (interactive (list 'force))
4220 (gnus-article-highlight-headers)
4221 (gnus-article-highlight-citation force)
4222 (gnus-article-highlight-signature)
4223 (gnus-article-add-buttons force)
4224 (gnus-article-add-buttons-to-head))
4226 (defun gnus-article-highlight-some (&optional force)
4227 "Highlight current article.
4228 This function calls `gnus-article-highlight-headers',
4229 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4230 do the highlighting. See the documentation for those functions."
4231 (interactive (list 'force))
4232 (gnus-article-highlight-headers)
4233 (gnus-article-highlight-signature)
4234 (gnus-article-add-buttons))
4236 (defun gnus-article-highlight-headers ()
4237 "Highlight article headers as specified by `gnus-header-face-alist'."
4240 (set-buffer gnus-article-buffer)
4242 (let ((alist gnus-header-face-alist)
4243 (buffer-read-only nil)
4244 (case-fold-search t)
4245 (inhibit-point-motion-hooks t)
4246 entry regexp header-face field-face from hpoints fpoints)
4247 (article-narrow-to-head)
4248 (while (setq entry (pop alist))
4249 (goto-char (point-min))
4250 (setq regexp (concat "^\\("
4251 (if (string-equal "" (nth 0 entry))
4255 header-face (nth 1 entry)
4256 field-face (nth 2 entry))
4257 (while (and (re-search-forward regexp nil t)
4261 (unless (search-forward ":" nil t)
4263 (when (and header-face
4264 (not (memq (point) hpoints)))
4265 (push (point) hpoints)
4266 (gnus-put-text-property from (point) 'face header-face))
4267 (when (and field-face
4268 (not (memq (setq from (point)) fpoints)))
4270 (if (re-search-forward "^[^ \t]" nil t)
4272 (goto-char (point-max)))
4273 (gnus-put-text-property from (point) 'face field-face))))))))
4275 (defun gnus-article-highlight-signature ()
4276 "Highlight the signature in an article.
4277 It does this by highlighting everything after
4278 `gnus-signature-separator' using `gnus-signature-face'."
4281 (set-buffer gnus-article-buffer)
4282 (let ((buffer-read-only nil)
4283 (inhibit-point-motion-hooks t))
4285 (when (and gnus-signature-face
4286 (gnus-article-narrow-to-signature))
4287 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4288 'face gnus-signature-face)
4290 (gnus-article-search-signature)
4291 (let ((start (match-beginning 0))
4292 (end (set-marker (make-marker) (1+ (match-end 0)))))
4293 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4296 (defun gnus-button-in-region-p (b e prop)
4297 "Say whether PROP exists in the region."
4298 (text-property-not-all b e prop nil))
4300 (defun gnus-article-add-buttons (&optional force)
4301 "Find external references in the article and make buttons of them.
4302 \"External references\" are things like Message-IDs and URLs, as
4303 specified by `gnus-button-alist'."
4304 (interactive (list 'force))
4306 (set-buffer gnus-article-buffer)
4307 (let ((buffer-read-only nil)
4308 (inhibit-point-motion-hooks t)
4309 (case-fold-search t)
4310 (alist gnus-button-alist)
4312 ;; Remove all old markers.
4313 (let (marker entry new-list)
4314 (while (setq marker (pop gnus-button-marker-list))
4315 (if (or (< marker (point-min)) (>= marker (point-max)))
4316 (push marker new-list)
4318 (when (setq entry (gnus-button-entry))
4319 (put-text-property (match-beginning (nth 1 entry))
4320 (match-end (nth 1 entry))
4321 'gnus-callback nil))
4322 (set-marker marker nil)))
4323 (setq gnus-button-marker-list new-list))
4324 ;; We skip the headers.
4327 (while (setq entry (pop alist))
4328 (setq regexp (car entry))
4330 (while (re-search-forward regexp nil t)
4331 (let* ((start (and entry (match-beginning (nth 1 entry))))
4332 (end (and entry (match-end (nth 1 entry))))
4333 (from (match-beginning 0)))
4334 (when (and (or (eq t (nth 2 entry))
4335 (eval (nth 2 entry)))
4336 (not (gnus-button-in-region-p
4337 start end 'gnus-callback)))
4338 ;; That optional form returned non-nil, so we add the
4340 (gnus-article-add-button
4341 start end 'gnus-button-push
4342 (car (push (set-marker (make-marker) from)
4343 gnus-button-marker-list))))))))))
4345 ;; Add buttons to the head of an article.
4346 (defun gnus-article-add-buttons-to-head ()
4347 "Add buttons to the head of the article."
4350 (set-buffer gnus-article-buffer)
4352 (let ((buffer-read-only nil)
4353 (inhibit-point-motion-hooks t)
4354 (case-fold-search t)
4355 (alist gnus-header-button-alist)
4357 (article-narrow-to-head)
4359 ;; Each alist entry.
4360 (setq entry (car alist)
4362 (goto-char (point-min))
4363 (while (re-search-forward (car entry) nil t)
4364 ;; Each header matching the entry.
4365 (setq beg (match-beginning 0))
4366 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4367 (match-beginning 0))
4370 (while (re-search-forward (nth 1 entry) end t)
4371 ;; Each match within a header.
4372 (let* ((entry (cdr entry))
4373 (start (match-beginning (nth 1 entry)))
4374 (end (match-end (nth 1 entry)))
4375 (form (nth 2 entry)))
4376 (goto-char (match-end 0))
4378 (gnus-article-add-button
4379 start end (nth 3 entry)
4380 (buffer-substring (match-beginning (nth 4 entry))
4381 (match-end (nth 4 entry)))))))
4382 (goto-char end)))))))
4384 ;;; External functions:
4386 (defun gnus-article-add-button (from to fun &optional data)
4387 "Create a button between FROM and TO with callback FUN and data DATA."
4388 (when gnus-article-button-face
4389 (gnus-overlay-put (gnus-make-overlay from to)
4390 'face gnus-article-button-face))
4391 (gnus-add-text-properties
4393 (nconc (and gnus-article-mouse-face
4394 (list gnus-mouse-face-prop gnus-article-mouse-face))
4395 (list 'gnus-callback fun)
4396 (and data (list 'gnus-data data))))
4397 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4398 :button-keymap gnus-widget-button-keymap))
4400 ;;; Internal functions:
4402 (defun gnus-article-set-globals ()
4404 (set-buffer gnus-summary-buffer)
4405 (gnus-set-global-variables)))
4407 (defun gnus-signature-toggle (end)
4409 (set-buffer gnus-article-buffer)
4410 (let ((buffer-read-only nil)
4411 (inhibit-point-motion-hooks t))
4412 (if (get-text-property end 'invisible)
4413 (gnus-article-unhide-text end (point-max))
4414 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4416 (defun gnus-button-entry ()
4417 ;; Return the first entry in `gnus-button-alist' matching this place.
4418 (let ((alist gnus-button-alist)
4421 (setq entry (pop alist))
4422 (if (looking-at (car entry))
4427 (defun gnus-button-push (marker)
4428 ;; Push button starting at MARKER.
4431 (let* ((entry (gnus-button-entry))
4432 (inhibit-point-motion-hooks t)
4434 (args (mapcar (lambda (group)
4435 (let ((string (match-string group)))
4436 (gnus-set-text-properties
4437 0 (length string) nil string)
4444 (fboundp (symbol-value fun)))
4445 (apply (symbol-value fun) args))
4447 (gnus-message 1 "You must define `%S' to use this button"
4448 (cons fun args)))))))
4450 (defun gnus-button-message-id (message-id)
4453 (set-buffer gnus-summary-buffer)
4454 (gnus-summary-refer-article message-id)))
4456 (defun gnus-button-fetch-group (address)
4457 "Fetch GROUP specified by ADDRESS."
4458 (if (not (string-match "[:/]" address))
4459 ;; This is just a simple group url.
4460 (gnus-group-read-ephemeral-group address gnus-select-method)
4461 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4463 (error "Can't parse %s" address)
4464 (gnus-group-read-ephemeral-group
4465 (match-string 4 address)
4466 `(nntp ,(match-string 1 address)
4467 (nntp-address ,(match-string 1 address))
4468 (nntp-port-number ,(if (match-end 3)
4469 (match-string 3 address)
4472 (defun gnus-url-parse-query-string (query &optional downcase)
4473 (let (retval pairs cur key val)
4474 (setq pairs (split-string query "&"))
4476 (setq cur (car pairs)
4478 (if (not (string-match "=" cur))
4480 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4481 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4483 (setq key (downcase key)))
4484 (setq cur (assoc key retval))
4486 (setcdr cur (cons val (cdr cur)))
4487 (setq retval (cons (list key val) retval)))))
4490 (defun gnus-url-unhex (x)
4497 (defun gnus-url-unhex-string (str &optional allow-newlines)
4498 "Remove %XXX embedded spaces, etc in a url.
4499 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4500 decoding of carriage returns and line feeds in the string, which is normally
4501 forbidden in URL encoding."
4502 (setq str (or str ""))
4504 (case-fold-search t))
4505 (while (string-match "%[0-9a-f][0-9a-f]" str)
4506 (let* ((start (match-beginning 0))
4507 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4509 (gnus-url-unhex (elt str (+ start 2))))))
4511 tmp (substring str 0 start)
4514 (char-to-string code))
4515 ((or (= code ?\n) (= code ?\r))
4517 (t (char-to-string code))))
4518 str (substring str (match-end 0)))))
4519 (setq tmp (concat tmp str))
4522 (defun gnus-url-mailto (url)
4523 ;; Send mail to someone
4524 (when (string-match "mailto:/*\\(.*\\)" url)
4525 (setq url (substring url (match-beginning 1) nil)))
4526 (let (to args subject func)
4527 (if (string-match (regexp-quote "?") url)
4528 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4529 args (gnus-url-parse-query-string
4530 (substring url (match-end 0) nil) t))
4531 (setq to (gnus-url-unhex-string url)))
4532 (setq args (cons (list "to" to) args)
4533 subject (cdr-safe (assoc "subject" args)))
4536 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4539 (message-position-on-field (caar args)))
4540 (insert (mapconcat 'identity (cdar args) ", "))
4541 (setq args (cdr args)))
4544 (message-goto-subject))))
4546 (defun gnus-button-mailto (address)
4548 (set-buffer (gnus-copy-article-buffer))
4549 (message-reply address))
4551 (defun gnus-button-reply (address)
4552 ;; Reply to ADDRESS.
4553 (message-reply address))
4555 (defun gnus-button-embedded-url (address)
4557 (browse-url (gnus-strip-whitespace address)))
4559 ;;; Next/prev buttons in the article buffer.
4561 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4562 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4564 (defvar gnus-prev-page-map nil)
4565 (unless gnus-prev-page-map
4566 (setq gnus-prev-page-map (make-sparse-keymap))
4567 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4568 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4570 (defun gnus-insert-prev-page-button ()
4571 (let ((buffer-read-only nil))
4573 gnus-prev-page-line-format nil
4574 `(gnus-prev t local-map ,gnus-prev-page-map
4575 gnus-callback gnus-article-button-prev-page
4576 article-type annotation))))
4578 (defvar gnus-next-page-map nil)
4579 (unless gnus-next-page-map
4580 (setq gnus-next-page-map (make-keymap))
4581 (suppress-keymap gnus-prev-page-map)
4582 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4583 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4585 (defun gnus-button-next-page ()
4586 "Go to the next page."
4588 (let ((win (selected-window)))
4589 (select-window (get-buffer-window gnus-article-buffer t))
4590 (gnus-article-next-page)
4591 (select-window win)))
4593 (defun gnus-button-prev-page ()
4594 "Go to the prev page."
4596 (let ((win (selected-window)))
4597 (select-window (get-buffer-window gnus-article-buffer t))
4598 (gnus-article-prev-page)
4599 (select-window win)))
4601 (defun gnus-insert-next-page-button ()
4602 (let ((buffer-read-only nil))
4603 (gnus-eval-format gnus-next-page-line-format nil
4605 t local-map ,gnus-next-page-map
4606 gnus-callback gnus-article-button-next-page
4607 article-type annotation))))
4609 (defun gnus-article-button-next-page (arg)
4610 "Go to the next page."
4612 (let ((win (selected-window)))
4613 (select-window (get-buffer-window gnus-article-buffer t))
4614 (gnus-article-next-page)
4615 (select-window win)))
4617 (defun gnus-article-button-prev-page (arg)
4618 "Go to the prev page."
4620 (let ((win (selected-window)))
4621 (select-window (get-buffer-window gnus-article-buffer t))
4622 (gnus-article-prev-page)
4623 (select-window win)))
4625 (defvar gnus-decode-header-methods
4626 '(mail-decode-encoded-word-region)
4627 "List of methods used to decode headers.
4629 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4630 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4631 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4632 whose names match REGEXP.
4635 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4636 mail-decode-encoded-word-region
4637 (\"chinese\" . rfc1843-decode-region))
4640 (defvar gnus-decode-header-methods-cache nil)
4642 (defun gnus-multi-decode-header (start end)
4643 "Apply the functions from `gnus-encoded-word-methods' that match."
4644 (unless (and gnus-decode-header-methods-cache
4645 (eq gnus-newsgroup-name
4646 (car gnus-decode-header-methods-cache)))
4647 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4650 (nconc gnus-decode-header-methods-cache (list x))
4651 (if (and gnus-newsgroup-name
4652 (string-match (car x) gnus-newsgroup-name))
4653 (nconc gnus-decode-header-methods-cache
4655 gnus-decode-header-methods))
4656 (let ((xlist gnus-decode-header-methods-cache))
4659 (narrow-to-region start end)
4661 (funcall (pop xlist) (point-min) (point-max))))))
4664 ;;; Treatment top-level handling.
4667 (defun gnus-treat-article (condition &optional part-number total-parts type)
4668 (let ((length (- (point-max) (point-min)))
4669 (alist gnus-treatment-function-alist)
4670 (article-goto-body-goes-to-point-min-p t)
4674 (let ((list gnus-article-treat-types))
4676 (when (string-match (pop list) type)
4677 (throw 'found t)))))))
4678 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4680 (gnus-run-hooks 'gnus-part-display-hook)
4681 (while (setq elem (pop alist))
4684 (if (gnus-buffer-live-p gnus-summary-buffer)
4685 (set-buffer gnus-summary-buffer))
4686 (symbol-value (car elem))))
4687 (when (and (or (consp val)
4689 (gnus-treat-predicate val)
4690 (or (not (get (car elem) 'highlight))
4693 (funcall (cadr elem)))))))
4695 ;; Dynamic variables.
4696 (defvar part-number)
4697 (defvar total-parts)
4701 (defun gnus-treat-predicate (val)
4706 (stringp (car val)))
4707 (apply 'gnus-or (mapcar `(lambda (s)
4708 (string-match s ,(or gnus-newsgroup-name "")))
4711 (let ((pred (pop val)))
4714 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4716 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4718 (not (gnus-treat-predicate (car val))))
4720 (equal (car val) type))
4722 (error "%S is not a valid predicate" pred)))))
4730 (eq part-number total-parts))
4734 (error "%S is not a valid value" val))))
4740 (run-hooks 'gnus-art-load-hook)
4742 ;;; gnus-art.el ends here