1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
62 (defgroup gnus-article-signature nil
64 :link '(custom-manual "(gnus)Article Signature")
67 (defgroup gnus-article-headers nil
69 :link '(custom-manual "(gnus)Hiding Headers")
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
82 (defgroup gnus-article-saving nil
84 :link '(custom-manual "(gnus)Saving Articles")
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
102 (defcustom gnus-ignored-headers
103 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
104 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
105 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
106 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
107 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
108 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
109 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
110 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
111 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
112 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
113 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
114 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
115 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
116 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
117 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
120 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
121 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
122 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
123 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
124 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
125 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
126 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
127 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
128 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
129 "^X-Received:" "^Content-length:" "X-precedence:")
130 "*All headers that start with this regexp will be hidden.
131 This variable can also be a list of regexps of headers to be ignored.
132 If `gnus-visible-headers' is non-nil, this variable will be ignored."
133 :type '(choice :custom-show nil
136 :group 'gnus-article-hiding)
138 (defcustom gnus-visible-headers
139 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
140 "*All headers that do not match this regexp will be hidden.
141 This variable can also be a list of regexp of headers to remain visible.
142 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
143 :type '(repeat :value-to-internal (lambda (widget value)
144 (custom-split-regexp-maybe value))
145 :match (lambda (widget value)
147 (widget-editable-list-match widget value)))
149 :group 'gnus-article-hiding)
151 (defcustom gnus-sorted-header-list
152 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
153 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
154 "*This variable is a list of regular expressions.
155 If it is non-nil, headers that match the regular expressions will
156 be placed first in the article buffer in the sequence specified by
158 :type '(repeat regexp)
159 :group 'gnus-article-hiding)
161 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
162 "Headers that are only to be displayed if they have interesting data.
163 Possible values in this list are `empty', `newsgroups', `followup-to',
164 `reply-to', `date', `long-to', and `many-to'."
165 :type '(set (const :tag "Headers with no content." empty)
166 (const :tag "Newsgroups with only one group." newsgroups)
167 (const :tag "Followup-to identical to newsgroups." followup-to)
168 (const :tag "Reply-to identical to from." reply-to)
169 (const :tag "Date less than four days old." date)
170 (const :tag "Very long To and/or Cc header." long-to)
171 (const :tag "Multiple To and/or Cc headers." many-to))
172 :group 'gnus-article-hiding)
174 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
175 "Regexp matching signature separator.
176 This can also be a list of regexps. In that case, it will be checked
177 from head to tail looking for a separator. Searches will be done from
178 the end of the buffer."
179 :type '(repeat string)
180 :group 'gnus-article-signature)
182 (defcustom gnus-signature-limit nil
183 "Provide a limit to what is considered a signature.
184 If it is a number, no signature may not be longer (in characters) than
185 that number. If it is a floating point number, no signature may be
186 longer (in lines) than that number. If it is a function, the function
187 will be called without any parameters, and if it returns nil, there is
188 no signature in the buffer. If it is a string, it will be used as a
189 regexp. If it matches, the text in question is not a signature."
190 :type '(choice (integer :value 200)
192 (function :value fun)
193 (regexp :value ".*"))
194 :group 'gnus-article-signature)
196 (defcustom gnus-hidden-properties '(invisible t intangible t)
197 "Property list to use for hiding text."
199 :group 'gnus-article-hiding)
201 (defcustom gnus-article-x-face-command
202 (if (and (fboundp 'image-type-available-p)
203 (or (image-type-available-p 'xpm)
204 (image-type-available-p 'xbm)))
205 'gnus-article-display-xface
206 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -")
207 "*String or function to be executed to display an X-Face header.
208 If it is a string, the command will be executed in a sub-shell
209 asynchronously. The compressed face will be piped to this command."
210 :type '(choice string
211 (function-item gnus-article-display-xface)
213 :group 'gnus-article-washing)
215 (defcustom gnus-article-x-face-too-ugly nil
216 "Regexp matching posters whose face shouldn't be shown automatically."
217 :type '(choice regexp (const nil))
218 :group 'gnus-article-washing)
220 (defcustom gnus-emphasis-alist
222 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
224 '(("_" "_" underline)
227 ("_/" "/_" underline-italic)
228 ("_\\*" "\\*_" underline-bold)
229 ("\\*/" "/\\*" bold-italic)
230 ("_\\*/" "/\\*_" underline-bold-italic))))
231 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
232 2 3 gnus-emphasis-underline)
236 (format format (car spec) (cadr spec))
237 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
239 "*Alist that says how to fontify certain phrases.
240 Each item looks like this:
242 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
244 The first element is a regular expression to be matched. The second
245 is a number that says what regular expression grouping used to find
246 the entire emphasized word. The third is a number that says what
247 regexp grouping should be displayed and highlighted. The fourth
248 is the face used for highlighting."
249 :type '(repeat (list :value ("" 0 0 default)
251 (integer :tag "Match group")
252 (integer :tag "Emphasize group")
254 :group 'gnus-article-emphasis)
256 (defface gnus-emphasis-bold '((t (:bold t)))
257 "Face used for displaying strong emphasized text (*word*)."
258 :group 'gnus-article-emphasis)
260 (defface gnus-emphasis-italic '((t (:italic t)))
261 "Face used for displaying italic emphasized text (/word/)."
262 :group 'gnus-article-emphasis)
264 (defface gnus-emphasis-underline '((t (:underline t)))
265 "Face used for displaying underlined emphasized text (_word_)."
266 :group 'gnus-article-emphasis)
268 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
269 "Face used for displaying underlined bold emphasized text (_*word*_)."
270 :group 'gnus-article-emphasis)
272 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
273 "Face used for displaying underlined italic emphasized text (_/word/_)."
274 :group 'gnus-article-emphasis)
276 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
277 "Face used for displaying bold italic emphasized text (/*word*/)."
278 :group 'gnus-article-emphasis)
280 (defface gnus-emphasis-underline-bold-italic
281 '((t (:bold t :italic t :underline t)))
282 "Face used for displaying underlined bold italic emphasized text.
283 Esample: (_/*word*/_)."
284 :group 'gnus-article-emphasis)
286 (defface gnus-emphasis-highlight-words
287 '((t (:background "black" :foreground "yellow")))
288 "Face used for displaying highlighted words."
289 :group 'gnus-article-emphasis)
291 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
292 "Format for display of Date headers in article bodies.
293 See `format-time-string' for the possible values.
295 The variable can also be function, which should return a complete Date
296 header. The function is called with one argument, the time, which can
297 be fed to `format-time-string'."
298 :type '(choice string symbol)
299 :link '(custom-manual "(gnus)Article Date")
300 :group 'gnus-article-washing)
303 (autoload 'mail-extract-address-components "mail-extr"))
305 (defcustom gnus-save-all-headers t
306 "*If non-nil, don't remove any headers before saving."
307 :group 'gnus-article-saving
310 (defcustom gnus-prompt-before-saving 'always
311 "*This variable says how much prompting is to be done when saving articles.
312 If it is nil, no prompting will be done, and the articles will be
313 saved to the default files. If this variable is `always', each and
314 every article that is saved will be preceded by a prompt, even when
315 saving large batches of articles. If this variable is neither nil not
316 `always', there the user will be prompted once for a file name for
317 each invocation of the saving commands."
318 :group 'gnus-article-saving
319 :type '(choice (item always)
320 (item :tag "never" nil)
321 (sexp :tag "once" :format "%t\n" :value t)))
323 (defcustom gnus-saved-headers gnus-visible-headers
324 "Headers to keep if `gnus-save-all-headers' is nil.
325 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
326 If that variable is nil, however, all headers that match this regexp
327 will be kept while the rest will be deleted before saving."
328 :group 'gnus-article-saving
331 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
332 "A function to save articles in your favourite format.
333 The function must be interactively callable (in other words, it must
334 be an Emacs command).
336 Gnus provides the following functions:
338 * gnus-summary-save-in-rmail (Rmail format)
339 * gnus-summary-save-in-mail (Unix mail format)
340 * gnus-summary-save-in-folder (MH folder)
341 * gnus-summary-save-in-file (article format)
342 * gnus-summary-save-in-vm (use VM's folder format)
343 * gnus-summary-write-to-file (article format -- overwrite)."
344 :group 'gnus-article-saving
345 :type '(radio (function-item gnus-summary-save-in-rmail)
346 (function-item gnus-summary-save-in-mail)
347 (function-item gnus-summary-save-in-folder)
348 (function-item gnus-summary-save-in-file)
349 (function-item gnus-summary-save-in-vm)
350 (function-item gnus-summary-write-to-file)))
352 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
353 "A function generating a file name to save articles in Rmail format.
354 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
355 :group 'gnus-article-saving
358 (defcustom gnus-mail-save-name 'gnus-plain-save-name
359 "A function generating a file name to save articles in Unix mail format.
360 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
361 :group 'gnus-article-saving
364 (defcustom gnus-folder-save-name 'gnus-folder-save-name
365 "A function generating a file name to save articles in MH folder.
366 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
367 :group 'gnus-article-saving
370 (defcustom gnus-file-save-name 'gnus-numeric-save-name
371 "A function generating a file name to save articles in article format.
372 The function is called with NEWSGROUP, HEADERS, and optional
374 :group 'gnus-article-saving
377 (defcustom gnus-split-methods
378 '((gnus-article-archive-name)
379 (gnus-article-nndoc-name))
380 "*Variable used to suggest where articles are to be saved.
381 For instance, if you would like to save articles related to Gnus in
382 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
383 you could set this variable to something like:
385 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
386 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
388 This variable is an alist where the where the key is the match and the
389 value is a list of possible files to save in if the match is non-nil.
391 If the match is a string, it is used as a regexp match on the
392 article. If the match is a symbol, that symbol will be funcalled
393 from the buffer of the article to be saved with the newsgroup as the
394 parameter. If it is a list, it will be evaled in the same buffer.
396 If this form or function returns a string, this string will be used as
397 a possible file name; and if it returns a non-nil list, that list will
398 be used as possible file names."
399 :group 'gnus-article-saving
400 :type '(repeat (choice (list :value (fun) function)
401 (cons :value ("" "") regexp (repeat string))
404 (defcustom gnus-page-delimiter "^\^L"
405 "*Regexp describing what to use as article page delimiters.
406 The default value is \"^\^L\", which is a form linefeed at the
407 beginning of a line."
409 :group 'gnus-article-various)
411 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
412 "*The format specification for the article mode line.
413 See `gnus-summary-mode-line-format' for a closer description.
415 The following additional specs are available:
417 %w The article washing status.
418 %m The number of MIME parts in the article."
420 :group 'gnus-article-various)
422 (defcustom gnus-article-mode-hook nil
423 "*A hook for Gnus article mode."
425 :group 'gnus-article-various)
427 (defcustom gnus-article-menu-hook nil
428 "*Hook run after the creation of the article mode menu."
430 :group 'gnus-article-various)
432 (defcustom gnus-article-prepare-hook nil
433 "*A hook called after an article has been prepared in the article buffer."
435 :group 'gnus-article-various)
437 (defcustom gnus-article-hide-pgp-hook nil
438 "*A hook called after successfully hiding a PGP signature."
440 :group 'gnus-article-various)
442 (defcustom gnus-article-button-face 'bold
443 "Face used for highlighting buttons in the article buffer.
445 An article button is a piece of text that you can activate by pressing
446 `RET' or `mouse-2' above it."
448 :group 'gnus-article-buttons)
450 (defcustom gnus-article-mouse-face 'highlight
451 "Face used for mouse highlighting in the article buffer.
453 Article buttons will be displayed in this face when the cursor is
456 :group 'gnus-article-buttons)
458 (defcustom gnus-signature-face 'gnus-signature-face
459 "Face used for highlighting a signature in the article buffer.
460 Obsolete; use the face `gnus-signature-face' for customizations instead."
462 :group 'gnus-article-highlight
463 :group 'gnus-article-signature)
465 (defface gnus-signature-face
468 "Face used for highlighting a signature in the article buffer."
469 :group 'gnus-article-highlight
470 :group 'gnus-article-signature)
472 (defface gnus-header-from-face
475 (:foreground "spring green"))
478 (:foreground "red3"))
481 "Face used for displaying from headers."
482 :group 'gnus-article-headers
483 :group 'gnus-article-highlight)
485 (defface gnus-header-subject-face
488 (:foreground "SeaGreen3"))
491 (:foreground "red4"))
493 (:bold t :italic t)))
494 "Face used for displaying subject headers."
495 :group 'gnus-article-headers
496 :group 'gnus-article-highlight)
498 (defface gnus-header-newsgroups-face
501 (:foreground "yellow" :italic t))
504 (:foreground "MidnightBlue" :italic t))
507 "Face used for displaying newsgroups headers."
508 :group 'gnus-article-headers
509 :group 'gnus-article-highlight)
511 (defface gnus-header-name-face
514 (:foreground "SeaGreen"))
517 (:foreground "maroon"))
520 "Face used for displaying header names."
521 :group 'gnus-article-headers
522 :group 'gnus-article-highlight)
524 (defface gnus-header-content-face
527 (:foreground "forest green" :italic t))
530 (:foreground "indianred4" :italic t))
532 (:italic t))) "Face used for displaying header content."
533 :group 'gnus-article-headers
534 :group 'gnus-article-highlight)
536 (defcustom gnus-header-face-alist
537 '(("From" nil gnus-header-from-face)
538 ("Subject" nil gnus-header-subject-face)
539 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
540 ("" gnus-header-name-face gnus-header-content-face))
541 "*Controls highlighting of article header.
543 An alist of the form (HEADER NAME CONTENT).
545 HEADER is a regular expression which should match the name of an
546 header header and NAME and CONTENT are either face names or nil.
548 The name of each header field will be displayed using the face
549 specified by the first element in the list where HEADER match the
550 header name and NAME is non-nil. Similarly, the content will be
551 displayed by the first non-nil matching CONTENT face."
552 :group 'gnus-article-headers
553 :group 'gnus-article-highlight
554 :type '(repeat (list (regexp :tag "Header")
556 (item :tag "skip" nil)
557 (face :value default))
558 (choice :tag "Content"
559 (item :tag "skip" nil)
560 (face :value default)))))
562 (defcustom gnus-article-decode-hook
563 '(article-decode-charset article-decode-encoded-words)
564 "*Hook run to decode charsets in articles."
565 :group 'gnus-article-headers
568 (defcustom gnus-display-mime-function 'gnus-display-mime
569 "Function to display MIME articles."
570 :group 'gnus-article-mime
573 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
574 "Function used to decode headers.")
576 (defvar gnus-article-dumbquotes-map
594 "Table for MS-to-Latin1 translation.")
596 (defcustom gnus-ignored-mime-types nil
597 "List of MIME types that should be ignored by Gnus."
598 :group 'gnus-article-mime
599 :type '(repeat regexp))
601 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
602 "List of MIME types that should not be given buttons when rendered inline."
603 :group 'gnus-article-mime
604 :type '(repeat regexp))
606 (defcustom gnus-article-mime-part-function nil
607 "Function called with a MIME handle as the argument.
608 This is meant for people who want to do something automatic based
609 on parts -- for instance, adding Vcard info to a database."
610 :group 'gnus-article-mime
613 (defcustom gnus-mime-multipart-functions nil
614 "An alist of MIME types to functions to display them.")
616 (defcustom gnus-article-date-lapsed-new-header nil
617 "Whether the X-Sent and Date headers can coexist.
618 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
619 either replace the old \"Date:\" header (if this variable is nil), or
620 be added below it (otherwise)."
621 :group 'gnus-article-headers
624 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
625 "Function called with a MIME handle as the argument.
626 This is meant for people who want to view first matched part.
627 For `undisplayed-alternative' (default), the first undisplayed
628 part or alternative part is used. For `undisplayed', the first
629 undisplayed part is used. For a function, the first part which
630 the function return `t' is used. For `nil', the first part is
632 :group 'gnus-article-mime
634 (item :tag "first" :value nil)
635 (item :tag "undisplayed" :value undisplayed)
636 (item :tag "undisplayed or alternative"
637 :value undisplayed-alternative)
641 ;;; The treatment variables
644 (defvar gnus-part-display-hook nil
645 "Hook called on parts that are to receive treatment.")
647 (defvar gnus-article-treat-custom
648 '(choice (const :tag "Off" nil)
650 (const :tag "Header" head)
651 (const :tag "Last" last)
652 (integer :tag "Less")
653 (repeat :tag "Groups" regexp)
654 (sexp :tag "Predicate")))
656 (defvar gnus-article-treat-head-custom
657 '(choice (const :tag "Off" nil)
658 (const :tag "Header" head)))
660 (defvar gnus-article-treat-types '("text/plain")
663 (defvar gnus-inhibit-treatment nil
664 "Whether to inhibit treatment.")
666 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
667 "Highlight the signature.
668 Valid values are nil, t, `head', `last', an integer or a predicate.
669 See the manual for details."
670 :group 'gnus-article-treat
671 :type gnus-article-treat-custom)
672 (put 'gnus-treat-highlight-signature 'highlight t)
674 (defcustom gnus-treat-buttonize 100000
676 Valid values are nil, t, `head', `last', an integer or a predicate.
677 See the manual for details."
678 :group 'gnus-article-treat
679 :type gnus-article-treat-custom)
680 (put 'gnus-treat-buttonize 'highlight t)
682 (defcustom gnus-treat-buttonize-head 'head
683 "Add buttons to the head.
684 Valid values are nil, t, `head', `last', an integer or a predicate.
685 See the manual for details."
686 :group 'gnus-article-treat
687 :type gnus-article-treat-head-custom)
688 (put 'gnus-treat-buttonize-head 'highlight t)
690 (defcustom gnus-treat-emphasize 50000
692 Valid values are nil, t, `head', `last', an integer or a predicate.
693 See the manual for details."
694 :group 'gnus-article-treat
695 :type gnus-article-treat-custom)
696 (put 'gnus-treat-emphasize 'highlight t)
698 (defcustom gnus-treat-strip-cr nil
699 "Remove carriage returns.
700 Valid values are nil, t, `head', `last', an integer or a predicate.
701 See the manual for details."
702 :group 'gnus-article-treat
703 :type gnus-article-treat-custom)
705 (defcustom gnus-treat-hide-headers 'head
707 Valid values are nil, t, `head', `last', an integer or a predicate.
708 See the manual for details."
709 :group 'gnus-article-treat
710 :type gnus-article-treat-head-custom)
712 (defcustom gnus-treat-hide-boring-headers nil
713 "Hide boring headers.
714 Valid values are nil, t, `head', `last', an integer or a predicate.
715 See the manual for details."
716 :group 'gnus-article-treat
717 :type gnus-article-treat-head-custom)
719 (defcustom gnus-treat-hide-signature nil
721 Valid values are nil, t, `head', `last', an integer or a predicate.
722 See the manual for details."
723 :group 'gnus-article-treat
724 :type gnus-article-treat-custom)
726 (defcustom gnus-treat-fill-article nil
728 Valid values are nil, t, `head', `last', an integer or a predicate.
729 See the manual for details."
730 :group 'gnus-article-treat
731 :type gnus-article-treat-custom)
733 (defcustom gnus-treat-hide-citation nil
735 Valid values are nil, t, `head', `last', an integer or a predicate.
736 See the manual for details."
737 :group 'gnus-article-treat
738 :type gnus-article-treat-custom)
740 (defcustom gnus-treat-strip-list-identifiers 'head
741 "Strip list identifiers from `gnus-list-identifiers`.
742 Valid values are nil, t, `head', `last', an integer or a predicate.
743 See the manual for details."
744 :group 'gnus-article-treat
745 :type gnus-article-treat-custom)
747 (defcustom gnus-treat-strip-pgp t
748 "Strip PGP signatures.
749 Valid values are nil, t, `head', `last', an integer or a predicate.
750 See the manual for details."
751 :group 'gnus-article-treat
752 :type gnus-article-treat-custom)
754 (defcustom gnus-treat-strip-pem nil
755 "Strip PEM signatures.
756 Valid values are nil, t, `head', `last', an integer or a predicate.
757 See the manual for details."
758 :group 'gnus-article-treat
759 :type gnus-article-treat-custom)
761 (defcustom gnus-treat-strip-banner t
762 "Strip banners from articles.
763 The banner to be stripped is specified in the `banner' group parameter.
764 Valid values are nil, t, `head', `last', an integer or a predicate.
765 See the manual for details."
766 :group 'gnus-article-treat
767 :type gnus-article-treat-custom)
769 (defcustom gnus-treat-highlight-headers 'head
770 "Highlight the headers.
771 Valid values are nil, t, `head', `last', an integer or a predicate.
772 See the manual for details."
773 :group 'gnus-article-treat
774 :type gnus-article-treat-head-custom)
775 (put 'gnus-treat-highlight-headers 'highlight t)
777 (defcustom gnus-treat-highlight-citation t
778 "Highlight cited text.
779 Valid values are nil, t, `head', `last', an integer or a predicate.
780 See the manual for details."
781 :group 'gnus-article-treat
782 :type gnus-article-treat-custom)
783 (put 'gnus-treat-highlight-citation 'highlight t)
785 (defcustom gnus-treat-date-ut nil
786 "Display the Date in UT (GMT).
787 Valid values are nil, t, `head', `last', an integer or a predicate.
788 See the manual for details."
789 :group 'gnus-article-treat
790 :type gnus-article-treat-head-custom)
792 (defcustom gnus-treat-date-local nil
793 "Display the Date in the local timezone.
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-head-custom)
799 (defcustom gnus-treat-date-lapsed nil
800 "Display the Date header in a way that says how much time has elapsed.
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See the manual for details."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-head-custom)
806 (defcustom gnus-treat-date-original nil
807 "Display the date in the original timezone.
808 Valid values are nil, t, `head', `last', an integer or a predicate.
809 See the manual for details."
810 :group 'gnus-article-treat
811 :type gnus-article-treat-head-custom)
813 (defcustom gnus-treat-date-iso8601 nil
814 "Display the date in the ISO8601 format.
815 Valid values are nil, t, `head', `last', an integer or a predicate.
816 See the manual for details."
817 :group 'gnus-article-treat
818 :type gnus-article-treat-head-custom)
820 (defcustom gnus-treat-date-user-defined nil
821 "Display the date in a user-defined format.
822 The format is defined by the `gnus-article-time-format' variable.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-head-custom)
828 (defcustom gnus-treat-strip-headers-in-body t
829 "Strip the X-No-Archive header line from the beginning of the body.
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-custom)
835 (defcustom gnus-treat-strip-trailing-blank-lines nil
836 "Strip trailing blank lines.
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-custom)
842 (defcustom gnus-treat-strip-leading-blank-lines nil
843 "Strip leading blank lines.
844 Valid values are nil, t, `head', `last', an integer or a predicate.
845 See the manual for details."
846 :group 'gnus-article-treat
847 :type gnus-article-treat-custom)
849 (defcustom gnus-treat-strip-multiple-blank-lines nil
850 "Strip multiple blank lines.
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-custom)
856 (defcustom gnus-treat-overstrike t
857 "Treat overstrike highlighting.
858 Valid values are nil, t, `head', `last', an integer or a predicate.
859 See the manual for details."
860 :group 'gnus-article-treat
861 :type gnus-article-treat-custom)
862 (put 'gnus-treat-overstrike 'highlight t)
864 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
866 "Display X-Face headers.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-head-custom)
871 (put 'gnus-treat-display-xface 'highlight t)
873 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See the manual for details."
879 :group 'gnus-article-treat
880 :type gnus-article-treat-custom)
881 (put 'gnus-treat-display-smileys 'highlight t)
883 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
885 Valid values are nil, t, `head', `last', an integer or a predicate.
886 See the manual for details."
887 :group 'gnus-article-treat
888 :type gnus-article-treat-head-custom)
889 (put 'gnus-treat-display-picons 'highlight t)
891 (defcustom gnus-treat-capitalize-sentences nil
892 "Capitalize sentence-starting words.
893 Valid values are nil, t, `head', `last', an integer or a predicate.
894 See the manual for details."
895 :group 'gnus-article-treat
896 :type gnus-article-treat-custom)
898 (defcustom gnus-treat-fill-long-lines nil
900 Valid values are nil, t, `head', `last', an integer or a predicate.
901 See the manual for details."
902 :group 'gnus-article-treat
903 :type gnus-article-treat-custom)
905 (defcustom gnus-treat-play-sounds nil
907 Valid values are nil, t, `head', `last', an integer or a predicate.
908 See the manual for details."
909 :group 'gnus-article-treat
910 :type gnus-article-treat-custom)
912 (defcustom gnus-treat-translate nil
913 "Translate articles from one language to another.
914 Valid values are nil, t, `head', `last', an integer or a predicate.
915 See the manual for details."
916 :group 'gnus-article-treat
917 :type gnus-article-treat-custom)
919 ;;; Internal variables
921 (defvar article-goto-body-goes-to-point-min-p nil)
922 (defvar gnus-article-wash-types nil)
923 (defvar gnus-article-emphasis-alist nil)
925 (defvar gnus-article-mime-handle-alist-1 nil)
926 (defvar gnus-treatment-function-alist
927 '((gnus-treat-strip-banner gnus-article-strip-banner)
928 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
929 (gnus-treat-highlight-signature gnus-article-highlight-signature)
930 (gnus-treat-buttonize gnus-article-add-buttons)
931 (gnus-treat-fill-article gnus-article-fill-cited-article)
932 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
933 (gnus-treat-strip-cr gnus-article-remove-cr)
934 (gnus-treat-emphasize gnus-article-emphasize)
935 (gnus-treat-display-xface gnus-article-display-x-face)
936 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
937 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
938 (gnus-treat-hide-signature gnus-article-hide-signature)
939 (gnus-treat-hide-citation gnus-article-hide-citation)
940 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
941 (gnus-treat-strip-pgp gnus-article-hide-pgp)
942 (gnus-treat-strip-pem gnus-article-hide-pem)
943 (gnus-treat-highlight-headers gnus-article-highlight-headers)
944 (gnus-treat-highlight-citation gnus-article-highlight-citation)
945 (gnus-treat-highlight-signature gnus-article-highlight-signature)
946 (gnus-treat-date-ut gnus-article-date-ut)
947 (gnus-treat-date-local gnus-article-date-local)
948 (gnus-treat-date-lapsed gnus-article-date-lapsed)
949 (gnus-treat-date-original gnus-article-date-original)
950 (gnus-treat-date-user-defined gnus-article-date-user)
951 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
952 (gnus-treat-strip-trailing-blank-lines
953 gnus-article-remove-trailing-blank-lines)
954 (gnus-treat-strip-leading-blank-lines
955 gnus-article-strip-leading-blank-lines)
956 (gnus-treat-strip-multiple-blank-lines
957 gnus-article-strip-multiple-blank-lines)
958 (gnus-treat-overstrike gnus-article-treat-overstrike)
959 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
960 (gnus-treat-display-smileys gnus-smiley-display)
961 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
962 (gnus-treat-display-picons gnus-article-display-picons)
963 (gnus-treat-play-sounds gnus-earcon-display)))
965 (defvar gnus-article-mime-handle-alist nil)
966 (defvar article-lapsed-timer nil)
967 (defvar gnus-article-current-summary nil)
969 (defvar gnus-article-mode-syntax-table
970 (let ((table (copy-syntax-table text-mode-syntax-table)))
971 (modify-syntax-entry ?- "w" table)
972 (modify-syntax-entry ?> ")" table)
973 (modify-syntax-entry ?< "(" table)
975 "Syntax table used in article mode buffers.
976 Initialized from `text-mode-syntax-table.")
978 (defvar gnus-save-article-buffer nil)
980 (defvar gnus-article-mode-line-format-alist
981 (nconc '((?w (gnus-article-wash-status) ?s)
982 (?m (gnus-article-mime-part-status) ?s))
983 gnus-summary-mode-line-format-alist))
985 (defvar gnus-number-of-articles-to-be-saved nil)
987 (defvar gnus-inhibit-hiding nil)
989 (defsubst gnus-article-hide-text (b e props)
990 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
991 (add-text-properties b e props)
992 (when (memq 'intangible props)
994 (max (1- b) (point-min))
995 b 'intangible (cddr (memq 'intangible props)))))
996 (defsubst gnus-article-unhide-text (b e)
997 "Remove hidden text properties from region between B and E."
998 (remove-text-properties b e gnus-hidden-properties)
999 (when (memq 'intangible gnus-hidden-properties)
1000 (put-text-property (max (1- b) (point-min))
1001 b 'intangible nil)))
1003 (defun gnus-article-hide-text-type (b e type)
1004 "Hide text of TYPE between B and E."
1005 (push type gnus-article-wash-types)
1006 (gnus-article-hide-text
1007 b e (cons 'article-type (cons type gnus-hidden-properties))))
1009 (defun gnus-article-unhide-text-type (b e type)
1010 "Unhide text of TYPE between B and E."
1011 (setq gnus-article-wash-types
1012 (delq type gnus-article-wash-types))
1013 (remove-text-properties
1014 b e (cons 'article-type (cons type gnus-hidden-properties)))
1015 (when (memq 'intangible gnus-hidden-properties)
1016 (put-text-property (max (1- b) (point-min))
1017 b 'intangible nil)))
1019 (defun gnus-article-hide-text-of-type (type)
1020 "Hide text of TYPE in the current buffer."
1022 (let ((b (point-min))
1024 (while (setq b (text-property-any b e 'article-type type))
1025 (add-text-properties b (incf b) gnus-hidden-properties)))))
1027 (defun gnus-article-delete-text-of-type (type)
1028 "Delete text of TYPE in the current buffer."
1030 (let ((b (point-min)))
1031 (while (setq b (text-property-any b (point-max) 'article-type type))
1033 b (or (text-property-not-all b (point-max) 'article-type type)
1036 (defun gnus-article-delete-invisible-text ()
1037 "Delete all invisible text in the current buffer."
1039 (let ((b (point-min)))
1040 (while (setq b (text-property-any b (point-max) 'invisible t))
1042 b (or (text-property-not-all b (point-max) 'invisible t)
1045 (defun gnus-article-text-type-exists-p (type)
1046 "Say whether any text of type TYPE exists in the buffer."
1047 (text-property-any (point-min) (point-max) 'article-type type))
1049 (defsubst gnus-article-header-rank ()
1050 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1051 (let ((list gnus-sorted-header-list)
1054 (when (looking-at (car list))
1056 (setq list (cdr list))
1060 (defun article-hide-headers (&optional arg delete)
1061 "Hide unwanted headers and possibly sort them as well."
1063 ;; This function might be inhibited.
1064 (unless gnus-inhibit-hiding
1067 (let ((buffer-read-only nil)
1068 (case-fold-search t)
1069 (max (1+ (length gnus-sorted-header-list)))
1070 (ignored (when (not gnus-visible-headers)
1071 (cond ((stringp gnus-ignored-headers)
1072 gnus-ignored-headers)
1073 ((listp gnus-ignored-headers)
1074 (mapconcat 'identity gnus-ignored-headers
1077 (cond ((stringp gnus-visible-headers)
1078 gnus-visible-headers)
1079 ((and gnus-visible-headers
1080 (listp gnus-visible-headers))
1081 (mapconcat 'identity gnus-visible-headers "\\|"))))
1082 (inhibit-point-motion-hooks t)
1084 ;; First we narrow to just the headers.
1085 (article-narrow-to-head)
1086 ;; Hide any "From " lines at the beginning of (mail) articles.
1087 (while (looking-at "From ")
1090 (delete-region (point-min) (point)))
1091 ;; Then treat the rest of the header lines.
1092 ;; Then we use the two regular expressions
1093 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1094 ;; select which header lines is to remain visible in the
1096 (while (re-search-forward "^[^ \t]*:" nil t)
1098 ;; Mark the rank of the header.
1100 (point) (1+ (point)) 'message-rank
1101 (if (or (and visible (looking-at visible))
1103 (not (looking-at ignored))))
1104 (gnus-article-header-rank)
1107 (message-sort-headers-1)
1108 (when (setq beg (text-property-any
1109 (point-min) (point-max) 'message-rank (+ 2 max)))
1110 ;; We delete the unwanted headers.
1111 (push 'headers gnus-article-wash-types)
1112 (add-text-properties (point-min) (+ 5 (point-min))
1113 '(article-type headers dummy-invisible t))
1114 (delete-region beg (point-max))))))))
1116 (defun article-hide-boring-headers (&optional arg)
1117 "Toggle hiding of headers that aren't very interesting.
1118 If given a negative prefix, always show; if given a positive prefix,
1120 (interactive (gnus-article-hidden-arg))
1121 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1122 (not gnus-show-all-headers))
1125 (let ((buffer-read-only nil)
1126 (list gnus-boring-article-headers)
1127 (inhibit-point-motion-hooks t)
1129 (article-narrow-to-head)
1131 (setq elem (pop list))
1132 (goto-char (point-min))
1134 ;; Hide empty headers.
1136 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1138 (gnus-article-hide-text-type
1139 (progn (beginning-of-line) (point))
1142 (if (re-search-forward "^[^ \t]" nil t)
1146 ;; Hide boring Newsgroups header.
1147 ((eq elem 'newsgroups)
1148 (when (equal (gnus-fetch-field "newsgroups")
1149 (gnus-group-real-name
1150 (if (boundp 'gnus-newsgroup-name)
1153 (gnus-article-hide-header "newsgroups")))
1154 ((eq elem 'followup-to)
1155 (when (equal (message-fetch-field "followup-to")
1156 (message-fetch-field "newsgroups"))
1157 (gnus-article-hide-header "followup-to")))
1158 ((eq elem 'reply-to)
1159 (let ((from (message-fetch-field "from"))
1160 (reply-to (message-fetch-field "reply-to")))
1165 (nth 1 (mail-extract-address-components from))
1166 (nth 1 (mail-extract-address-components reply-to)))))
1167 (gnus-article-hide-header "reply-to"))))
1169 (let ((date (message-fetch-field "date")))
1171 (< (days-between (current-time-string) date)
1173 (gnus-article-hide-header "date"))))
1175 (let ((to (message-fetch-field "to"))
1176 (cc (message-fetch-field "cc")))
1177 (when (> (length to) 1024)
1178 (gnus-article-hide-header "to"))
1179 (when (> (length cc) 1024)
1180 (gnus-article-hide-header "cc"))))
1184 (goto-char (point-min))
1185 (while (re-search-forward "^to:" nil t)
1186 (setq to-count (1+ to-count)))
1187 (when (> to-count 1)
1188 (while (> to-count 0)
1189 (goto-char (point-min))
1191 (re-search-forward "^to:" nil nil to-count)
1193 (narrow-to-region (point) (point-max))
1194 (gnus-article-hide-header "to"))
1195 (setq to-count (1- to-count))))
1196 (goto-char (point-min))
1197 (while (re-search-forward "^cc:" nil t)
1198 (setq cc-count (1+ cc-count)))
1199 (when (> cc-count 1)
1200 (while (> cc-count 0)
1201 (goto-char (point-min))
1203 (re-search-forward "^cc:" nil nil cc-count)
1205 (narrow-to-region (point) (point-max))
1206 (gnus-article-hide-header "cc"))
1207 (setq cc-count (1- cc-count)))))))))))))
1209 (defun gnus-article-hide-header (header)
1211 (goto-char (point-min))
1212 (when (re-search-forward (concat "^" header ":") nil t)
1213 (gnus-article-hide-text-type
1214 (progn (beginning-of-line) (point))
1217 (if (re-search-forward "^[^ \t]" nil t)
1222 (defvar gnus-article-normalized-header-length 40
1223 "Length of normalized headers.")
1225 (defun article-normalize-headers ()
1226 "Make all header lines 40 characters long."
1228 (let ((buffer-read-only nil)
1232 (article-narrow-to-head)
1235 ((< (setq column (- (gnus-point-at-eol) (point)))
1236 gnus-article-normalized-header-length)
1238 (insert (make-string
1239 (- gnus-article-normalized-header-length column)
1241 ((> column gnus-article-normalized-header-length)
1242 (gnus-put-text-property
1244 (forward-char gnus-article-normalized-header-length)
1251 (forward-line 1))))))
1253 (defun article-treat-dumbquotes ()
1254 "Translate M******** sm*rtq**t*s into proper text.
1255 Note that this function guesses whether a character is a sm*rtq**t* or
1256 not, so it should only be used interactively."
1258 (article-translate-strings gnus-article-dumbquotes-map))
1260 (defun article-translate-characters (from to)
1261 "Translate all characters in the body of the article according to FROM and TO.
1262 FROM is a string of characters to translate from; to is a string of
1263 characters to translate to."
1265 (when (article-goto-body)
1266 (let ((buffer-read-only nil)
1267 (x (make-string 225 ?x))
1269 (while (< (incf i) (length x))
1272 (while (< i (length from))
1273 (aset x (aref from i) (aref to i))
1275 (translate-region (point) (point-max) x)))))
1277 (defun article-translate-strings (map)
1278 "Translate all string in the body of the article according to MAP.
1279 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1281 (when (article-goto-body)
1282 (let ((buffer-read-only nil)
1284 (while (setq elem (pop map))
1286 (while (search-forward (car elem) nil t)
1287 (replace-match (cadr elem)))))))))
1289 (defun article-treat-overstrike ()
1290 "Translate overstrikes into bold text."
1293 (when (article-goto-body)
1294 (let ((buffer-read-only nil))
1295 (while (search-forward "\b" nil t)
1296 (let ((next (char-after))
1297 (previous (char-after (- (point) 2))))
1298 ;; We do the boldification/underlining by hiding the
1299 ;; overstrikes and putting the proper text property
1303 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1304 (put-text-property (point) (1+ (point)) 'face 'bold))
1306 (gnus-article-hide-text-type
1307 (1- (point)) (1+ (point)) 'overstrike)
1309 (- (point) 2) (1- (point)) 'face 'underline))
1311 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1313 (point) (1+ (point)) 'face 'underline)))))))))
1315 (defun article-fill-long-lines ()
1316 "Fill lines that are wider than the window width."
1319 (let ((buffer-read-only nil)
1320 (width (window-width (get-buffer-window (current-buffer)))))
1323 (let ((adaptive-fill-mode nil))
1326 (when (>= (current-column) (min fill-column width))
1327 (narrow-to-region (point) (gnus-point-at-bol))
1328 (fill-paragraph nil)
1329 (goto-char (point-max))
1331 (forward-line 1)))))))
1333 (defun article-capitalize-sentences ()
1334 "Capitalize the first word in each sentence."
1337 (let ((buffer-read-only nil)
1338 (paragraph-start "^[\n\^L]"))
1342 (forward-sentence)))))
1344 (defun article-remove-cr ()
1345 "Remove trailing CRs and then translate remaining CRs into LFs."
1348 (let ((buffer-read-only nil))
1349 (goto-char (point-min))
1350 (while (re-search-forward "\r+$" nil t)
1351 (replace-match "" t t))
1352 (goto-char (point-min))
1353 (while (search-forward "\r" nil t)
1354 (replace-match "\n" t t)))))
1356 (defun article-remove-trailing-blank-lines ()
1357 "Remove all trailing blank lines from the article."
1360 (let ((buffer-read-only nil))
1361 (goto-char (point-max))
1365 (while (and (not (bobp))
1366 (looking-at "^[ \t]*$")
1367 (not (gnus-annotation-in-region-p
1368 (point) (gnus-point-at-eol))))
1373 (defun article-display-x-face (&optional force)
1374 "Look for an X-Face header and display it if present."
1375 (interactive (list 'force))
1377 ;; Delete the old process, if any.
1378 (when (process-status "article-x-face")
1379 (delete-process "article-x-face"))
1380 (let ((inhibit-point-motion-hooks t)
1381 (case-fold-search t)
1384 (article-narrow-to-head)
1385 (goto-char (point-min))
1386 (setq from (message-fetch-field "from"))
1387 (goto-char (point-min))
1388 (while (and gnus-article-x-face-command
1391 ;; Check whether this face is censored.
1392 (not gnus-article-x-face-too-ugly)
1393 (and gnus-article-x-face-too-ugly from
1394 (not (string-match gnus-article-x-face-too-ugly
1396 ;; Has to be present.
1397 (re-search-forward "^X-Face: " nil t))
1398 ;; This used to try to do multiple faces (`while' instead of
1399 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1400 ;; work (b) it can crash some versions of Emacs (c) are
1401 ;; multiple faces really something to encourage?
1402 (when (stringp gnus-article-x-face-command)
1404 ;; We now have the area of the buffer where the X-Face is stored.
1407 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1408 ;; We display the face.
1409 (if (symbolp gnus-article-x-face-command)
1410 ;; The command is a lisp function, so we call it.
1411 (if (gnus-functionp gnus-article-x-face-command)
1412 (funcall gnus-article-x-face-command beg end)
1413 (error "%s is not a function" gnus-article-x-face-command))
1414 ;; The command is a string, so we interpret the command
1415 ;; as a, well, command, and fork it off.
1416 (let ((process-connection-type nil))
1417 (process-kill-without-query
1419 "article-x-face" nil shell-file-name shell-command-switch
1420 gnus-article-x-face-command))
1421 (process-send-region "article-x-face" beg end)
1422 (process-send-eof "article-x-face"))))))))))
1424 (defun article-decode-mime-words ()
1425 "Decode all MIME-encoded words in the article."
1428 (set-buffer gnus-article-buffer)
1429 (let ((inhibit-point-motion-hooks t)
1431 (mail-parse-charset gnus-newsgroup-charset)
1432 (mail-parse-ignored-charsets
1433 (save-excursion (set-buffer gnus-summary-buffer)
1434 gnus-newsgroup-ignored-charsets)))
1435 (mail-decode-encoded-word-region (point-min) (point-max)))))
1437 (defun article-decode-charset (&optional prompt)
1438 "Decode charset-encoded text in the article.
1439 If PROMPT (the prefix), prompt for a coding system to use."
1441 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1443 (mail-parse-charset gnus-newsgroup-charset)
1444 (mail-parse-ignored-charsets
1445 (save-excursion (condition-case nil
1446 (set-buffer gnus-summary-buffer)
1448 gnus-newsgroup-ignored-charsets))
1452 (article-narrow-to-head)
1453 (setq ct (message-fetch-field "Content-Type" t)
1454 cte (message-fetch-field "Content-Transfer-Encoding" t)
1455 ctl (and ct (ignore-errors
1456 (mail-header-parse-content-type ct)))
1459 (mm-read-coding-system "Charset to decode: "))
1461 (mail-content-type-get ctl 'charset))))
1463 (setq cte (mail-header-strip cte)))
1464 (if (and ctl (not (string-match "/" (car ctl))))
1466 (goto-char (point-max)))
1469 (narrow-to-region (point) (point-max))
1470 (when (and (or (not ctl)
1471 (equal (car ctl) "text/plain")))
1473 charset (and cte (intern (downcase
1474 (gnus-strip-whitespace cte))))
1477 (defun article-decode-encoded-words ()
1478 "Remove encoded-word encoding from headers."
1479 (let ((inhibit-point-motion-hooks t)
1480 (mail-parse-charset gnus-newsgroup-charset)
1481 (mail-parse-ignored-charsets
1482 (save-excursion (condition-case nil
1483 (set-buffer gnus-summary-buffer)
1485 gnus-newsgroup-ignored-charsets))
1488 (article-narrow-to-head)
1489 (funcall gnus-decode-header-function (point-min) (point-max)))))
1491 (defun article-de-quoted-unreadable (&optional force)
1492 "Translate a quoted-printable-encoded article.
1493 If FORCE, decode the article whether it is marked as quoted-printable
1495 (interactive (list 'force))
1497 (let ((buffer-read-only nil)
1498 (type (gnus-fetch-field "content-transfer-encoding"))
1499 (charset gnus-newsgroup-charset))
1501 (and type (string-match "quoted-printable" (downcase type))))
1503 (quoted-printable-decode-region (point) (point-max) charset)))))
1508 (defun article-decode-HZ ()
1509 "Translate a HZ-encoded article."
1513 (let ((buffer-read-only nil))
1514 (rfc1843-decode-region (point-min) (point-max)))))
1516 (defun article-hide-list-identifiers ()
1517 "Remove list identifies from the Subject header.
1518 The `gnus-list-identifiers' variable specifies what to do."
1522 (let ((inhibit-point-motion-hooks t)
1524 (article-narrow-to-head)
1525 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1526 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1528 (goto-char (point-min))
1529 (when (re-search-forward
1530 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1532 (delete-region (match-beginning 2) (match-end 0)))))))))
1534 (defun article-hide-pgp ()
1535 "Remove any PGP headers and signatures in the current article."
1539 (let ((inhibit-point-motion-hooks t)
1540 buffer-read-only beg end)
1542 ;; Hide the "header".
1543 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1544 (push 'pgp gnus-article-wash-types)
1545 (delete-region (match-beginning 0) (match-end 0))
1546 ;; Remove armor headers (rfc2440 6.2)
1547 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1550 ;; Hide the actual signature.
1551 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1552 (setq end (1+ (match-beginning 0)))
1555 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1557 ;; Perhaps we shouldn't hide to the end of the buffer
1558 ;; if there is no end to the signature?
1560 ;; Hide "- " PGP quotation markers.
1562 (narrow-to-region beg end)
1563 (goto-char (point-min))
1564 (while (re-search-forward "^- " nil t)
1566 (match-beginning 0) (match-end 0)))
1568 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1570 (defun article-hide-pem (&optional arg)
1571 "Toggle hiding of any PEM headers and signatures in the current article.
1572 If given a negative prefix, always show; if given a positive prefix,
1574 (interactive (gnus-article-hidden-arg))
1575 (unless (gnus-article-check-hidden-text 'pem arg)
1577 (let (buffer-read-only end)
1578 (goto-char (point-min))
1579 ;; Hide the horrendously ugly "header".
1580 (when (and (search-forward
1581 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1583 (setq end (1+ (match-beginning 0))))
1584 (push 'pem gnus-article-wash-types)
1585 (gnus-article-hide-text-type
1587 (if (search-forward "\n\n" nil t)
1591 ;; Hide the trailer as well
1592 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1594 (gnus-article-hide-text-type
1595 (match-beginning 0) (match-end 0) 'pem)))))))
1597 (defun article-strip-banner ()
1598 "Strip the banner specified by the `banner' group parameter."
1602 (let ((inhibit-point-motion-hooks t)
1603 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1604 (gnus-signature-limit nil)
1605 buffer-read-only beg end)
1609 ((eq banner 'signature)
1610 (when (gnus-article-narrow-to-signature)
1613 (delete-region (point) (point-max))))
1615 (while (re-search-forward banner nil t)
1616 (delete-region (match-beginning 0) (match-end 0))))))))))
1618 (defun article-babel ()
1619 "Translate article using an online translation service."
1623 (set-buffer gnus-article-buffer)
1624 (when (article-goto-body)
1625 (let* ((buffer-read-only nil)
1628 (orig (buffer-substring start end))
1629 (trans (babel-as-string orig)))
1631 (narrow-to-region start end)
1632 (delete-region start end)
1635 (defun article-hide-signature (&optional arg)
1636 "Hide the signature in the current article.
1637 If given a negative prefix, always show; if given a positive prefix,
1639 (interactive (gnus-article-hidden-arg))
1640 (unless (gnus-article-check-hidden-text 'signature arg)
1643 (let ((buffer-read-only nil))
1644 (when (gnus-article-narrow-to-signature)
1645 (gnus-article-hide-text-type
1646 (point-min) (point-max) 'signature)))))))
1648 (defun article-strip-headers-in-body ()
1649 "Strip offensive headers from bodies."
1653 (let ((case-fold-search t))
1654 (when (looking-at "x-no-archive:")
1655 (gnus-delete-line)))))
1657 (defun article-strip-leading-blank-lines ()
1658 "Remove all blank lines from the beginning of the article."
1661 (let ((inhibit-point-motion-hooks t)
1663 (when (article-goto-body)
1664 (while (and (not (eobp))
1665 (looking-at "[ \t]*$"))
1666 (gnus-delete-line))))))
1668 (defun article-narrow-to-head ()
1669 "Narrow the buffer to the head of the message.
1670 Point is left at the beginning of the narrowed-to region."
1672 (goto-char (point-min))
1673 (if (search-forward "\n\n" nil 1)
1676 (goto-char (point-min)))
1678 (defun article-goto-body ()
1679 "Place point at the start of the body."
1680 (goto-char (point-min))
1682 ;; This variable is only bound when dealing with separate
1684 (article-goto-body-goes-to-point-min-p
1686 ((search-forward "\n\n" nil t)
1689 (goto-char (point-max))
1692 (defun article-strip-multiple-blank-lines ()
1693 "Replace consecutive blank lines with one empty line."
1696 (let ((inhibit-point-motion-hooks t)
1698 ;; First make all blank lines empty.
1700 (while (re-search-forward "^[ \t]+$" nil t)
1701 (unless (gnus-annotation-in-region-p
1702 (match-beginning 0) (match-end 0))
1703 (replace-match "" nil t)))
1704 ;; Then replace multiple empty lines with a single empty line.
1706 (while (re-search-forward "\n\n\n+" nil t)
1707 (unless (gnus-annotation-in-region-p
1708 (match-beginning 0) (match-end 0))
1709 (replace-match "\n\n" t t))))))
1711 (defun article-strip-leading-space ()
1712 "Remove all white space from the beginning of the lines in the article."
1715 (let ((inhibit-point-motion-hooks t)
1718 (while (re-search-forward "^[ \t]+" nil t)
1719 (replace-match "" t t)))))
1721 (defun article-strip-trailing-space ()
1722 "Remove all white space from the end of the lines in the article."
1725 (let ((inhibit-point-motion-hooks t)
1728 (while (re-search-forward "[ \t]+$" nil t)
1729 (replace-match "" t t)))))
1731 (defun article-strip-blank-lines ()
1732 "Strip leading, trailing and multiple blank lines."
1734 (article-strip-leading-blank-lines)
1735 (article-remove-trailing-blank-lines)
1736 (article-strip-multiple-blank-lines))
1738 (defun article-strip-all-blank-lines ()
1739 "Strip all blank lines."
1742 (let ((inhibit-point-motion-hooks t)
1745 (while (re-search-forward "^[ \t]*\n" nil t)
1746 (replace-match "" t t)))))
1748 (defun gnus-article-narrow-to-signature ()
1749 "Narrow to the signature; return t if a signature is found, else nil."
1750 (let ((inhibit-point-motion-hooks t))
1751 (when (gnus-article-search-signature)
1753 ;; Check whether we have some limits to what we consider
1754 ;; to be a signature.
1755 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1756 (list gnus-signature-limit)))
1758 (while (setq limit (pop limits))
1759 (if (or (and (integerp limit)
1760 (< (- (point-max) (point)) limit))
1762 (< (count-lines (point) (point-max)) limit))
1763 (and (gnus-functionp limit)
1765 (and (stringp limit)
1766 (not (re-search-forward limit nil t))))
1767 () ; This limit did not succeed.
1771 (narrow-to-region (point) (point-max))
1774 (defun gnus-article-search-signature ()
1775 "Search the current buffer for the signature separator.
1776 Put point at the beginning of the signature separator."
1777 (let ((cur (point)))
1778 (goto-char (point-max))
1779 (if (if (stringp gnus-signature-separator)
1780 (re-search-backward gnus-signature-separator nil t)
1781 (let ((seps gnus-signature-separator))
1783 (not (re-search-backward (car seps) nil t)))
1790 (defun gnus-article-hidden-arg ()
1791 "Return the current prefix arg as a number, or 0 if no prefix."
1792 (list (if current-prefix-arg
1793 (prefix-numeric-value current-prefix-arg)
1796 (defun gnus-article-check-hidden-text (type arg)
1797 "Return nil if hiding is necessary.
1798 Arg can be nil or a number. Nil and positive means hide, negative
1799 means show, 0 means toggle."
1802 (let ((hide (gnus-article-hidden-text-p type)))
1808 (gnus-article-show-hidden-text type))
1810 (if (eq hide 'hidden)
1811 (gnus-article-show-hidden-text type)
1814 (defun gnus-article-hidden-text-p (type)
1815 "Say whether the current buffer contains hidden text of type TYPE."
1816 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1818 (not (get-text-property pos 'invisible))
1819 (not (get-text-property pos 'dummy-invisible)))
1821 (text-property-any (1+ pos) (point-max) 'article-type type)))
1826 (defun gnus-article-show-hidden-text (type &optional hide)
1827 "Show all hidden text of type TYPE.
1828 If HIDE, hide the text instead."
1830 (let ((buffer-read-only nil)
1831 (inhibit-point-motion-hooks t)
1834 (while (setq beg (text-property-any end (point-max) 'article-type type))
1837 (text-property-not-all beg (point-max) 'article-type type)
1840 (gnus-article-hide-text beg end gnus-hidden-properties)
1841 (gnus-article-unhide-text beg end))
1845 (defconst article-time-units
1846 `((year . ,(* 365.25 24 60 60))
1847 (week . ,(* 7 24 60 60))
1848 (day . ,(* 24 60 60))
1852 "Mapping from time units to seconds.")
1854 (defun article-date-ut (&optional type highlight header)
1855 "Convert DATE date to universal time in the current article.
1856 If TYPE is `local', convert to local time; if it is `lapsed', output
1857 how much time has lapsed since DATE. For `lapsed', the value of
1858 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1859 should replace the \"Date:\" one, or should be added below it."
1860 (interactive (list 'ut t))
1861 (let* ((header (or header
1862 (message-fetch-field "date")
1864 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1867 ((not gnus-article-date-lapsed-new-header)
1873 (date (if (vectorp header) (mail-header-date header)
1875 (inhibit-point-motion-hooks t)
1880 (article-narrow-to-head)
1881 (when (re-search-forward tdate-regexp nil t)
1882 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1883 date (or (get-text-property (gnus-point-at-bol)
1886 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1888 (when (and date (not (string= date "")))
1889 (goto-char (point-min))
1890 (let ((buffer-read-only nil))
1891 ;; Delete any old Date headers.
1892 (while (re-search-forward date-regexp nil t)
1894 (delete-region (progn (beginning-of-line) (point))
1895 (progn (forward-line 1) (point)))
1896 (delete-region (progn (beginning-of-line) (point))
1897 (progn (end-of-line) (point)))
1898 (setq pos (point))))
1899 (when (and (not pos) (re-search-forward tdate-regexp nil t))
1901 (if pos (goto-char pos))
1902 (insert (article-make-date-line date (or type 'ut)))
1908 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1909 (put-text-property (match-beginning 1) (1+ (match-end 1))
1910 'original-date date)
1911 (put-text-property (match-beginning 1) (1+ (match-end 1))
1913 (put-text-property (match-beginning 2) (match-end 2)
1916 (defun article-make-date-line (date type)
1917 "Return a DATE line of TYPE."
1918 (let ((time (condition-case ()
1922 ;; Convert to the local timezone. We have to slap a
1923 ;; `condition-case' round the calls to the timezone
1924 ;; functions since they aren't particularly resistant to
1927 (let ((tz (car (current-time-zone time))))
1928 (format "Date: %s %s%02d%02d" (current-time-string time)
1929 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1930 (/ (% (abs tz) 3600) 60))))
1931 ;; Convert to Universal Time.
1934 (current-time-string
1935 (let* ((e (parse-time-string date))
1936 (tm (apply 'encode-time e))
1938 (ls (- (cadr tm) (car (current-time-zone time)))))
1939 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1940 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1943 ;; Get the original date from the article.
1944 ((eq type 'original)
1945 (concat "Date: " (if (string-match "\n+$" date)
1946 (substring date 0 (match-beginning 0))
1948 ;; Let the user define the format.
1950 (if (gnus-functionp gnus-article-time-format)
1951 (funcall gnus-article-time-format time)
1954 (format-time-string gnus-article-time-format time))))
1957 (let ((tz (car (current-time-zone time))))
1960 (format-time-string "%Y%m%dT%H%M%S" time)
1961 (format "%s%02d%02d"
1962 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1963 (/ (% (abs tz) 3600) 60)))))
1964 ;; Do an X-Sent lapsed format.
1966 ;; If the date is seriously mangled, the timezone functions are
1967 ;; liable to bug out, so we ignore all errors.
1968 (let* ((now (current-time))
1969 (real-time (subtract-time now time))
1970 (real-sec (and real-time
1971 (+ (* (float (car real-time)) 65536)
1973 (sec (and real-time (abs real-sec)))
1983 ;; This is a bit convoluted, but basically we go
1984 ;; through the time units for years, weeks, etc,
1985 ;; and divide things to see whether that results
1986 ;; in positive answers.
1989 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1990 ;; The (remaining) seconds are too few to
1991 ;; be divided into this time unit.
1993 ;; It's big enough, so we output it.
1994 (setq sec (- sec (* num (cdr unit))))
1996 (concat (if prev ", " "") (int-to-string
1998 " " (symbol-name (car unit))
1999 (if (> num 1) "s" ""))
2001 article-time-units "")
2002 ;; If dates are odd, then it might appear like the
2003 ;; article was sent in the future.
2006 " in the future"))))))
2008 (error "Unknown conversion type: %s" type)))))
2010 (defun article-date-local (&optional highlight)
2011 "Convert the current article date to the local timezone."
2012 (interactive (list t))
2013 (article-date-ut 'local highlight))
2015 (defun article-date-original (&optional highlight)
2016 "Convert the current article date to what it was originally.
2017 This is only useful if you have used some other date conversion
2018 function and want to see what the date was before converting."
2019 (interactive (list t))
2020 (article-date-ut 'original highlight))
2022 (defun article-date-lapsed (&optional highlight)
2023 "Convert the current article date to time lapsed since it was sent."
2024 (interactive (list t))
2025 (article-date-ut 'lapsed highlight))
2027 (defun article-update-date-lapsed ()
2028 "Function to be run from a timer to update the lapsed time line."
2029 (let (deactivate-mark)
2034 (set-buffer (window-buffer w))
2035 (when (eq major-mode 'gnus-article-mode)
2036 (goto-char (point-min))
2037 (when (re-search-forward "^X-Sent:" nil t)
2038 (article-date-lapsed t))))
2041 (defun gnus-start-date-timer (&optional n)
2042 "Start a timer to update the X-Sent header in the article buffers.
2043 The numerical prefix says how frequently (in seconds) the function
2048 (gnus-stop-date-timer)
2049 (setq article-lapsed-timer
2050 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2052 (defun gnus-stop-date-timer ()
2053 "Stop the X-Sent timer."
2055 (when article-lapsed-timer
2056 (nnheader-cancel-timer article-lapsed-timer)
2057 (setq article-lapsed-timer nil)))
2059 (defun article-date-user (&optional highlight)
2060 "Convert the current article date to the user-defined format.
2061 This format is defined by the `gnus-article-time-format' variable."
2062 (interactive (list t))
2063 (article-date-ut 'user highlight))
2065 (defun article-date-iso8601 (&optional highlight)
2066 "Convert the current article date to ISO8601."
2067 (interactive (list t))
2068 (article-date-ut 'iso8601 highlight))
2070 (defun article-show-all ()
2071 "Show all hidden text in the article buffer."
2074 (let ((buffer-read-only nil))
2075 (gnus-article-unhide-text (point-min) (point-max)))))
2077 (defun article-emphasize (&optional arg)
2078 "Emphasize text according to `gnus-emphasis-alist'."
2079 (interactive (gnus-article-hidden-arg))
2080 (unless (gnus-article-check-hidden-text 'emphasis arg)
2084 (with-current-buffer gnus-summary-buffer
2085 gnus-article-emphasis-alist)
2087 gnus-emphasis-alist))
2088 (buffer-read-only nil)
2089 (props (append '(article-type emphasis)
2090 gnus-hidden-properties))
2091 regexp elem beg invisible visible face)
2094 (while (setq elem (pop alist))
2096 (setq regexp (car elem)
2097 invisible (nth 1 elem)
2098 visible (nth 2 elem)
2100 (while (re-search-forward regexp nil t)
2101 (when (and (match-beginning visible) (match-beginning invisible))
2102 (push 'emphasis gnus-article-wash-types)
2103 (gnus-article-hide-text
2104 (match-beginning invisible) (match-end invisible) props)
2105 (gnus-article-unhide-text-type
2106 (match-beginning visible) (match-end visible) 'emphasis)
2107 (gnus-put-text-property-excluding-newlines
2108 (match-beginning visible) (match-end visible) 'face face)
2109 (goto-char (match-end invisible)))))))))
2111 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2112 "Setup newsgroup emphasis alist."
2113 (unless gnus-article-emphasis-alist
2114 (let ((name (and gnus-newsgroup-name
2115 (gnus-group-real-name gnus-newsgroup-name))))
2116 (make-local-variable 'gnus-article-emphasis-alist)
2117 (setq gnus-article-emphasis-alist
2119 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2120 (while (setq elem (pop alist))
2121 (when (and name (string-match (car elem) name))
2123 highlight (copy-sequence (cdr elem)))))
2125 (copy-sequence highlight-words)
2126 (if gnus-newsgroup-name
2127 (copy-sequence (gnus-group-find-parameter
2128 gnus-newsgroup-name 'highlight-words t)))
2129 gnus-emphasis-alist)))))
2131 (defvar gnus-summary-article-menu)
2132 (defvar gnus-summary-post-menu)
2134 ;;; Saving functions.
2136 (defun gnus-article-save (save-buffer file &optional num)
2137 "Save the currently selected article."
2138 (unless gnus-save-all-headers
2139 ;; Remove headers according to `gnus-saved-headers'.
2140 (let ((gnus-visible-headers
2141 (or gnus-saved-headers gnus-visible-headers))
2142 (gnus-article-buffer save-buffer))
2144 (set-buffer save-buffer)
2145 (article-hide-headers 1 t))))
2146 (save-window-excursion
2147 (if (not gnus-default-article-saver)
2148 (error "No default saver is defined")
2149 ;; !!! Magic! The saving functions all save
2150 ;; `gnus-save-article-buffer' (or so they think), but we
2151 ;; bind that variable to our save-buffer.
2152 (set-buffer gnus-article-buffer)
2153 (let* ((gnus-save-article-buffer save-buffer)
2156 ((not gnus-prompt-before-saving) 'default)
2157 ((eq gnus-prompt-before-saving 'always) nil)
2159 (gnus-number-of-articles-to-be-saved
2160 (when (eq gnus-prompt-before-saving t)
2162 (set-buffer gnus-article-current-summary)
2163 (funcall gnus-default-article-saver filename)))))
2165 (defun gnus-read-save-file-name (prompt &optional filename
2166 function group headers variable)
2168 (funcall function group headers (symbol-value variable)))
2173 ((eq filename 'default)
2179 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2182 (if (and gnus-number-of-articles-to-be-saved
2183 (> gnus-number-of-articles-to-be-saved 1))
2184 (format "these %d articles"
2185 gnus-number-of-articles-to-be-saved)
2188 ;; Let the split methods have their say.
2190 ;; No split name was found.
2193 (concat prompt " (default "
2194 (file-name-nondirectory default-name) ") ")
2195 (file-name-directory default-name)
2197 ;; A single group name is returned.
2198 ((stringp split-name)
2200 (funcall function split-name headers
2201 (symbol-value variable)))
2203 (concat prompt " (default "
2204 (file-name-nondirectory default-name) ") ")
2205 (file-name-directory default-name)
2207 ;; A single split name was found
2208 ((= 1 (length split-name))
2209 (let* ((name (expand-file-name
2210 (car split-name) gnus-article-save-directory))
2211 (dir (cond ((file-directory-p name)
2212 (file-name-as-directory name))
2213 ((file-exists-p name) name)
2214 (t gnus-article-save-directory))))
2216 (concat prompt " (default " name ") ")
2218 ;; A list of splits was found.
2220 (setq split-name (nreverse split-name))
2222 (let ((file-name-history
2223 (nconc split-name file-name-history)))
2227 (concat prompt " (`M-p' for defaults) ")
2228 gnus-article-save-directory
2230 gnus-article-save-directory)))
2231 (car (push result file-name-history)))))))
2232 ;; Create the directory.
2233 (gnus-make-directory (file-name-directory file))
2234 ;; If we have read a directory, we append the default file name.
2235 (when (file-directory-p file)
2236 (setq file (concat (file-name-as-directory file)
2237 (file-name-nondirectory default-name))))
2238 ;; Possibly translate some characters.
2239 (nnheader-translate-file-chars file)))))
2240 (gnus-make-directory (file-name-directory result))
2241 (set variable result)))
2243 (defun gnus-article-archive-name (group)
2244 "Return the first instance of an \"Archive-name\" in the current buffer."
2245 (let ((case-fold-search t))
2246 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2247 (nnheader-concat gnus-article-save-directory
2248 (match-string 1)))))
2250 (defun gnus-article-nndoc-name (group)
2251 "If GROUP is an nndoc group, return the name of the parent group."
2252 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2253 (gnus-group-get-parameter group 'save-article-group)))
2255 (defun gnus-summary-save-in-rmail (&optional filename)
2256 "Append this article to Rmail file.
2257 Optional argument FILENAME specifies file name.
2258 Directory to save to is default to `gnus-article-save-directory'."
2259 (setq filename (gnus-read-save-file-name
2260 "Save %s in rmail file:" filename
2261 gnus-rmail-save-name gnus-newsgroup-name
2262 gnus-current-headers 'gnus-newsgroup-last-rmail))
2263 (gnus-eval-in-buffer-window gnus-save-article-buffer
2267 (gnus-output-to-rmail filename))))
2270 (defun gnus-summary-save-in-mail (&optional filename)
2271 "Append this article to Unix mail file.
2272 Optional argument FILENAME specifies file name.
2273 Directory to save to is default to `gnus-article-save-directory'."
2274 (setq filename (gnus-read-save-file-name
2275 "Save %s in Unix mail file:" filename
2276 gnus-mail-save-name gnus-newsgroup-name
2277 gnus-current-headers 'gnus-newsgroup-last-mail))
2278 (gnus-eval-in-buffer-window gnus-save-article-buffer
2282 (if (and (file-readable-p filename)
2283 (mail-file-babyl-p filename))
2284 (rmail-output-to-rmail-file filename t)
2285 (gnus-output-to-mail filename)))))
2288 (defun gnus-summary-save-in-file (&optional filename overwrite)
2289 "Append this article to file.
2290 Optional argument FILENAME specifies file name.
2291 Directory to save to is default to `gnus-article-save-directory'."
2292 (setq filename (gnus-read-save-file-name
2293 "Save %s in file:" filename
2294 gnus-file-save-name gnus-newsgroup-name
2295 gnus-current-headers 'gnus-newsgroup-last-file))
2296 (gnus-eval-in-buffer-window gnus-save-article-buffer
2300 (when (and overwrite
2301 (file-exists-p filename))
2302 (delete-file filename))
2303 (gnus-output-to-file filename))))
2306 (defun gnus-summary-write-to-file (&optional filename)
2307 "Write this article to a file.
2308 Optional argument FILENAME specifies file name.
2309 The directory to save in defaults to `gnus-article-save-directory'."
2310 (gnus-summary-save-in-file nil t))
2312 (defun gnus-summary-save-body-in-file (&optional filename)
2313 "Append this article body to a file.
2314 Optional argument FILENAME specifies file name.
2315 The directory to save in defaults to `gnus-article-save-directory'."
2316 (setq filename (gnus-read-save-file-name
2317 "Save %s body in file:" filename
2318 gnus-file-save-name gnus-newsgroup-name
2319 gnus-current-headers 'gnus-newsgroup-last-file))
2320 (gnus-eval-in-buffer-window gnus-save-article-buffer
2324 (when (article-goto-body)
2325 (narrow-to-region (point) (point-max)))
2326 (gnus-output-to-file filename))))
2329 (defun gnus-summary-save-in-pipe (&optional command)
2330 "Pipe this article to subprocess."
2332 (cond ((and (eq command 'default)
2333 gnus-last-shell-command)
2334 gnus-last-shell-command)
2338 "Shell command on %s: "
2339 (if (and gnus-number-of-articles-to-be-saved
2340 (> gnus-number-of-articles-to-be-saved 1))
2341 (format "these %d articles"
2342 gnus-number-of-articles-to-be-saved)
2344 gnus-last-shell-command))))
2345 (when (string-equal command "")
2346 (setq command gnus-last-shell-command))
2347 (gnus-eval-in-buffer-window gnus-article-buffer
2350 (shell-command-on-region (point-min) (point-max) command nil)))
2351 (setq gnus-last-shell-command command))
2353 ;;; Article file names when saving.
2355 (defun gnus-capitalize-newsgroup (newsgroup)
2356 "Capitalize NEWSGROUP name."
2357 (when (not (zerop (length newsgroup)))
2358 (concat (char-to-string (upcase (aref newsgroup 0)))
2359 (substring newsgroup 1))))
2361 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2362 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2363 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2364 Otherwise, it is like ~/News/news/group/num."
2367 (concat (if (gnus-use-long-file-name 'not-save)
2368 (gnus-capitalize-newsgroup newsgroup)
2369 (gnus-newsgroup-directory-form newsgroup))
2370 "/" (int-to-string (mail-header-number headers)))
2371 gnus-article-save-directory)))
2373 (string-equal (file-name-directory default)
2374 (file-name-directory last-file))
2375 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2377 (or last-file default))))
2379 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2380 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2381 If variable `gnus-use-long-file-name' is non-nil, it is
2382 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2385 (concat (if (gnus-use-long-file-name 'not-save)
2387 (gnus-newsgroup-directory-form newsgroup))
2388 "/" (int-to-string (mail-header-number headers)))
2389 gnus-article-save-directory)))
2391 (string-equal (file-name-directory default)
2392 (file-name-directory last-file))
2393 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2395 (or last-file default))))
2397 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2398 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2399 If variable `gnus-use-long-file-name' is non-nil, it is
2400 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2403 (if (gnus-use-long-file-name 'not-save)
2404 (gnus-capitalize-newsgroup newsgroup)
2405 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2406 gnus-article-save-directory)))
2408 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2409 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2410 If variable `gnus-use-long-file-name' is non-nil, it is
2411 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2414 (if (gnus-use-long-file-name 'not-save)
2416 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2417 gnus-article-save-directory)))
2424 (setq afunc (car func)
2427 gfunc (intern (format "gnus-%s" func))))
2429 (if (not (fboundp afunc))
2431 `(lambda (&optional interactive &rest args)
2432 ,(documentation afunc t)
2433 (interactive (list t))
2435 (set-buffer gnus-article-buffer)
2437 (call-interactively ',afunc)
2438 (apply ',afunc args))))))))
2439 '(article-hide-headers
2440 article-hide-boring-headers
2441 article-treat-overstrike
2442 article-fill-long-lines
2443 article-capitalize-sentences
2445 article-display-x-face
2446 article-de-quoted-unreadable
2448 article-mime-decode-quoted-printable
2449 article-hide-list-identifiers
2451 article-strip-banner
2454 article-hide-signature
2455 article-strip-headers-in-body
2456 article-remove-trailing-blank-lines
2457 article-strip-leading-blank-lines
2458 article-strip-multiple-blank-lines
2459 article-strip-leading-space
2460 article-strip-trailing-space
2461 article-strip-blank-lines
2462 article-strip-all-blank-lines
2464 article-date-iso8601
2465 article-date-original
2467 article-decode-mime-words
2468 article-decode-charset
2469 article-decode-encoded-words
2473 article-treat-dumbquotes
2474 article-normalize-headers
2475 (article-show-all . gnus-article-show-all-headers))))
2478 ;;; Gnus article mode
2481 (put 'gnus-article-mode 'mode-class 'special)
2483 (set-keymap-parent gnus-article-mode-map widget-keymap)
2485 (gnus-define-keys gnus-article-mode-map
2486 " " gnus-article-goto-next-page
2487 "\177" gnus-article-goto-prev-page
2488 [delete] gnus-article-goto-prev-page
2489 [backspace] gnus-article-goto-prev-page
2490 "\C-c^" gnus-article-refer-article
2491 "h" gnus-article-show-summary
2492 "s" gnus-article-show-summary
2493 "\C-c\C-m" gnus-article-mail
2494 "?" gnus-article-describe-briefly
2495 "e" gnus-summary-edit-article
2496 "<" beginning-of-buffer
2498 "\C-c\C-i" gnus-info-find-node
2501 "\C-d" gnus-article-read-summary-keys
2502 "\M-*" gnus-article-read-summary-keys
2503 "\M-#" gnus-article-read-summary-keys
2504 "\M-^" gnus-article-read-summary-keys
2505 "\M-g" gnus-article-read-summary-keys)
2507 (substitute-key-definition
2508 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2510 (defun gnus-article-make-menu-bar ()
2511 (gnus-turn-off-edit-menu 'article)
2512 (unless (boundp 'gnus-article-article-menu)
2514 gnus-article-article-menu gnus-article-mode-map ""
2516 ["Scroll forwards" gnus-article-goto-next-page t]
2517 ["Scroll backwards" gnus-article-goto-prev-page t]
2518 ["Show summary" gnus-article-show-summary t]
2519 ["Fetch Message-ID at point" gnus-article-refer-article t]
2520 ["Mail to address at point" gnus-article-mail t]
2521 ["Send a bug report" gnus-bug t]))
2524 gnus-article-treatment-menu gnus-article-mode-map ""
2526 ["Hide headers" gnus-article-hide-headers t]
2527 ["Hide signature" gnus-article-hide-signature t]
2528 ["Hide citation" gnus-article-hide-citation t]
2529 ["Treat overstrike" gnus-article-treat-overstrike t]
2530 ["Remove carriage return" gnus-article-remove-cr t]
2531 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2532 ["Decode HZ" gnus-article-decode-HZ t]))
2534 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2536 (when (boundp 'gnus-summary-post-menu)
2537 (define-key gnus-article-mode-map [menu-bar post]
2538 (cons "Post" gnus-summary-post-menu)))
2540 (gnus-run-hooks 'gnus-article-menu-hook)))
2542 (defun gnus-article-mode ()
2543 "Major mode for displaying an article.
2545 All normal editing commands are switched off.
2547 The following commands are available in addition to all summary mode
2549 \\<gnus-article-mode-map>
2550 \\[gnus-article-next-page]\t Scroll the article one page forwards
2551 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2552 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2553 \\[gnus-article-show-summary]\t Display the summary buffer
2554 \\[gnus-article-mail]\t Send a reply to the address near point
2555 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2556 \\[gnus-info-find-node]\t Go to the Gnus info node"
2558 (when (gnus-visual-p 'article-menu 'menu)
2559 (gnus-article-make-menu-bar))
2560 (gnus-simplify-mode-line)
2561 (setq mode-name "Article")
2562 (setq major-mode 'gnus-article-mode)
2563 (make-local-variable 'minor-mode-alist)
2564 (use-local-map gnus-article-mode-map)
2565 (gnus-update-format-specifications nil 'article-mode)
2566 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2567 (make-local-variable 'gnus-page-broken)
2568 (make-local-variable 'gnus-button-marker-list)
2569 (make-local-variable 'gnus-article-current-summary)
2570 (make-local-variable 'gnus-article-mime-handles)
2571 (make-local-variable 'gnus-article-decoded-p)
2572 (make-local-variable 'gnus-article-mime-handle-alist)
2573 (make-local-variable 'gnus-article-wash-types)
2574 (gnus-set-default-directory)
2575 (buffer-disable-undo)
2576 (setq buffer-read-only t)
2577 (set-syntax-table gnus-article-mode-syntax-table)
2578 (mm-enable-multibyte)
2579 (gnus-run-hooks 'gnus-article-mode-hook))
2581 (defun gnus-article-setup-buffer ()
2582 "Initialize the article buffer."
2583 (let* ((name (if gnus-single-article-buffer "*Article*"
2584 (concat "*Article " gnus-newsgroup-name "*")))
2586 (progn (string-match "\\*Article" name)
2587 (concat " *Original Article"
2588 (substring name (match-end 0))))))
2589 (setq gnus-article-buffer name)
2590 (setq gnus-original-article-buffer original)
2591 (setq gnus-article-mime-handle-alist nil)
2592 ;; This might be a variable local to the summary buffer.
2593 (unless gnus-single-article-buffer
2595 (set-buffer gnus-summary-buffer)
2596 (setq gnus-article-buffer name)
2597 (setq gnus-original-article-buffer original)
2598 (gnus-set-global-variables)))
2599 (gnus-article-setup-highlight-words)
2600 ;; Init original article buffer.
2602 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2603 (mm-enable-multibyte)
2604 (setq major-mode 'gnus-original-article-mode)
2605 (make-local-variable 'gnus-original-article))
2606 (if (get-buffer name)
2609 (when gnus-article-mime-handles
2610 (mm-destroy-parts gnus-article-mime-handles))
2611 (buffer-disable-undo)
2612 (setq buffer-read-only t)
2613 (unless (eq major-mode 'gnus-article-mode)
2614 (gnus-article-mode))
2617 (set-buffer (gnus-get-buffer-create name))
2619 (make-local-variable 'gnus-summary-buffer)
2620 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2621 (current-buffer)))))
2623 ;; Set article window start at LINE, where LINE is the number of lines
2624 ;; from the head of the article.
2625 (defun gnus-article-set-window-start (&optional line)
2627 (get-buffer-window gnus-article-buffer t)
2629 (set-buffer gnus-article-buffer)
2630 (goto-char (point-min))
2633 (gnus-message 6 "Moved to bookmark")
2634 (search-forward "\n\n" nil t)
2638 (defun gnus-article-prepare (article &optional all-headers header)
2639 "Prepare ARTICLE in article mode buffer.
2640 ARTICLE should either be an article number or a Message-ID.
2641 If ARTICLE is an id, HEADER should be the article headers.
2642 If ALL-HEADERS is non-nil, no headers are hidden."
2644 ;; Make sure we start in a summary buffer.
2645 (unless (eq major-mode 'gnus-summary-mode)
2646 (set-buffer gnus-summary-buffer))
2647 (setq gnus-summary-buffer (current-buffer))
2648 (let* ((gnus-article (if header (mail-header-number header) article))
2649 (summary-buffer (current-buffer))
2650 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2651 (group gnus-newsgroup-name)
2654 (gnus-article-setup-buffer)
2655 (set-buffer gnus-article-buffer)
2656 ;; Deactivate active regions.
2657 (when (and (boundp 'transient-mark-mode)
2658 transient-mark-mode)
2659 (setq mark-active nil))
2660 (if (not (setq result (let ((buffer-read-only nil))
2661 (gnus-request-article-this-buffer
2663 ;; There is no such article.
2665 (when (and (numberp article)
2666 (not (memq article gnus-newsgroup-sparse)))
2667 (setq gnus-article-current
2668 (cons gnus-newsgroup-name article))
2669 (set-buffer gnus-summary-buffer)
2670 (setq gnus-current-article article)
2671 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2673 (gnus-summary-set-agent-mark article)
2674 (message "Message marked for downloading"))
2675 (gnus-summary-mark-article article gnus-canceled-mark)
2676 (unless (memq article gnus-newsgroup-sparse)
2677 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2678 (if (or (eq result 'pseudo)
2679 (eq result 'nneething))
2682 (set-buffer summary-buffer)
2683 (push article gnus-newsgroup-history)
2684 (setq gnus-last-article gnus-current-article
2685 gnus-current-article 0
2686 gnus-current-headers nil
2687 gnus-article-current nil)
2688 (if (eq result 'nneething)
2689 (gnus-configure-windows 'summary)
2690 (gnus-configure-windows 'article))
2691 (gnus-set-global-variables))
2692 (let ((gnus-article-mime-handle-alist-1
2693 gnus-article-mime-handle-alist))
2694 (gnus-set-mode-line 'article)))
2695 ;; The result from the `request' was an actual article -
2696 ;; or at least some text that is now displayed in the
2698 (when (and (numberp article)
2699 (not (eq article gnus-current-article)))
2700 ;; Seems like a new article has been selected.
2701 ;; `gnus-current-article' must be an article number.
2703 (set-buffer summary-buffer)
2704 (push article gnus-newsgroup-history)
2705 (setq gnus-last-article gnus-current-article
2706 gnus-current-article article
2707 gnus-current-headers
2708 (gnus-summary-article-header gnus-current-article)
2709 gnus-article-current
2710 (cons gnus-newsgroup-name gnus-current-article))
2711 (unless (vectorp gnus-current-headers)
2712 (setq gnus-current-headers nil))
2713 (gnus-summary-goto-subject gnus-current-article)
2714 (when (gnus-summary-show-thread)
2715 ;; If the summary buffer really was folded, the
2716 ;; previous goto may not actually have gone to
2717 ;; the right article, but the thread root instead.
2719 (gnus-summary-goto-subject gnus-current-article))
2720 (gnus-run-hooks 'gnus-mark-article-hook)
2721 (gnus-set-mode-line 'summary)
2722 (when (gnus-visual-p 'article-highlight 'highlight)
2723 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2724 ;; Set the global newsgroup variables here.
2725 (gnus-set-global-variables)
2726 (setq gnus-have-all-headers
2727 (or all-headers gnus-show-all-headers))))
2728 (when (or (numberp article)
2730 (gnus-article-prepare-display)
2732 (goto-char (point-min))
2733 (setq gnus-page-broken
2734 (when gnus-break-pages
2735 (gnus-narrow-to-page)
2737 (let ((gnus-article-mime-handle-alist-1
2738 gnus-article-mime-handle-alist))
2739 (gnus-set-mode-line 'article))
2741 (set-window-point (get-buffer-window (current-buffer)) (point))
2742 (gnus-configure-windows 'article)
2746 (defun gnus-article-prepare-display ()
2747 "Make the current buffer look like a nice article."
2748 ;; Hooks for getting information from the article.
2749 ;; This hook must be called before being narrowed.
2750 (let ((gnus-article-buffer (current-buffer))
2752 (unless (eq major-mode 'gnus-article-mode)
2753 (gnus-article-mode))
2754 (setq buffer-read-only nil
2755 gnus-article-wash-types nil)
2756 (gnus-run-hooks 'gnus-tmp-internal-hook)
2757 (when gnus-display-mime-function
2758 (funcall gnus-display-mime-function))
2759 (gnus-run-hooks 'gnus-article-prepare-hook)))
2762 ;;; Gnus MIME viewing functions
2765 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2766 "The following specs can be used:
2768 %T MIME type, along with additional info
2769 %n The `name' parameter
2770 %d The description, if any
2771 %l The length of the encoded part
2772 %p The part identifier number
2773 %e Dots if the part isn't displayed")
2775 (defvar gnus-mime-button-line-format-alist
2776 '((?t gnus-tmp-type ?s)
2777 (?T gnus-tmp-type-long ?s)
2778 (?n gnus-tmp-name ?s)
2779 (?d gnus-tmp-description ?s)
2781 (?l gnus-tmp-length ?d)
2782 (?e gnus-tmp-dots ?s)))
2784 (defvar gnus-mime-button-commands
2785 '((gnus-article-press-button "\r" "Toggle Display")
2786 (gnus-mime-view-part "v" "View Interactively...")
2787 (gnus-mime-view-part-as-type "t" "View As Type...")
2788 (gnus-mime-save-part "o" "Save...")
2789 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2790 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2791 (gnus-mime-internalize-part "E" "View Internally")
2792 (gnus-mime-externalize-part "e" "View Externally")
2793 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2795 (defun gnus-article-mime-part-status ()
2796 (if gnus-article-mime-handle-alist-1
2797 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2800 (defvar gnus-mime-button-map nil)
2801 (unless gnus-mime-button-map
2802 (setq gnus-mime-button-map (make-sparse-keymap))
2803 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2804 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2805 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2807 (define-key gnus-mime-button-map (cadr c) (car c)))
2808 gnus-mime-button-commands))
2810 (defun gnus-mime-button-menu (event)
2811 "Construct a context-sensitive menu of MIME commands."
2814 (let ((pos (event-start event)))
2815 (set-buffer (window-buffer (posn-window pos)))
2816 (goto-char (posn-point pos))
2817 (gnus-article-check-buffer)
2818 (let ((response (x-popup-menu
2820 ("" ,@(mapcar (lambda (c)
2821 (cons (caddr c) (car c)))
2822 gnus-mime-button-commands))))))
2824 (funcall response))))))
2826 (defun gnus-mime-view-all-parts (&optional handles)
2827 "View all the MIME parts."
2829 (save-current-buffer
2830 (set-buffer gnus-article-buffer)
2831 (let ((handles (or handles gnus-article-mime-handles))
2832 (mail-parse-charset gnus-newsgroup-charset)
2833 (mail-parse-ignored-charsets
2834 (save-excursion (set-buffer gnus-summary-buffer)
2835 gnus-newsgroup-ignored-charsets)))
2836 (if (stringp (car handles))
2837 (gnus-mime-view-all-parts (cdr handles))
2838 (mapcar 'mm-display-part handles)))))
2840 (defun gnus-mime-save-part ()
2841 "Save the MIME part under point."
2843 (gnus-article-check-buffer)
2844 (let ((data (get-text-property (point) 'gnus-data)))
2845 (mm-save-part data)))
2847 (defun gnus-mime-pipe-part ()
2848 "Pipe the MIME part under point to a process."
2850 (gnus-article-check-buffer)
2851 (let ((data (get-text-property (point) 'gnus-data)))
2852 (mm-pipe-part data)))
2854 (defun gnus-mime-view-part ()
2855 "Interactively choose a viewing method for the MIME part under point."
2857 (gnus-article-check-buffer)
2858 (let ((data (get-text-property (point) 'gnus-data)))
2859 (mm-interactively-view-part data)))
2861 (defun gnus-mime-view-part-as-type-internal ()
2862 (gnus-article-check-buffer)
2863 (let* ((name (mail-content-type-get
2864 (mm-handle-type (get-text-property (point) 'gnus-data))
2866 (def-type (and name (mm-default-file-encoding name))))
2867 (and def-type (cons def-type 0))))
2869 (defun gnus-mime-view-part-as-type (mime-type)
2870 "Choose a MIME media type, and view the part as such."
2872 (list (completing-read
2873 "View as MIME type: "
2874 (mapcar (lambda (i) (list i i)) (mailcap-mime-types))
2876 (gnus-mime-view-part-as-type-internal))))
2877 (gnus-article-check-buffer)
2878 (let ((handle (get-text-property (point) 'gnus-data)))
2879 (gnus-mm-display-part
2880 (mm-make-handle (mm-handle-buffer handle)
2881 (cons mime-type (cdr (mm-handle-type handle)))
2882 (mm-handle-encoding handle)
2883 (mm-handle-undisplayer handle)
2884 (mm-handle-disposition handle)
2885 (mm-handle-description handle)
2886 (mm-handle-cache handle)
2887 (mm-handle-id handle)))))
2889 (defun gnus-mime-copy-part (&optional handle)
2890 "Put the the MIME part under point into a new buffer."
2892 (gnus-article-check-buffer)
2893 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2894 (contents (mm-get-part handle))|
2895 (base (file-name-nondirectory
2897 (mail-content-type-get (mm-handle-type handle) 'name)
2898 (mail-content-type-get (mm-handle-type handle)
2901 (buffer (generate-new-buffer base)))
2902 (switch-to-buffer buffer)
2904 ;; We do it this way to make `normal-mode' set the appropriate mode.
2907 (setq buffer-file-name (expand-file-name base))
2909 (setq buffer-file-name nil))
2910 (goto-char (point-min))))
2912 (defun gnus-mime-inline-part (&optional handle)
2913 "Insert the MIME part under point into the current buffer."
2915 (gnus-article-check-buffer)
2916 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2920 (if (mm-handle-undisplayer handle)
2921 (mm-remove-part handle)
2922 (setq contents (mm-get-part handle))
2924 (mm-insert-inline handle contents)
2927 (defun gnus-mime-externalize-part (&optional handle)
2928 "View the MIME part under point with an external viewer."
2930 (gnus-article-check-buffer)
2931 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2932 (mm-user-display-methods nil)
2933 (mm-inline-large-images nil)
2934 (mail-parse-charset gnus-newsgroup-charset)
2935 (mail-parse-ignored-charsets
2936 (save-excursion (set-buffer gnus-summary-buffer)
2937 gnus-newsgroup-ignored-charsets)))
2938 (if (mm-handle-undisplayer handle)
2939 (mm-remove-part handle)
2940 (mm-display-part handle))))
2942 (defun gnus-mime-internalize-part (&optional handle)
2943 "View the MIME part under point with an internal viewer.
2944 In no internal viewer is available, use an external viewer."
2946 (gnus-article-check-buffer)
2947 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2948 (mm-inlined-types '(".*"))
2949 (mm-inline-large-images t)
2950 (mail-parse-charset gnus-newsgroup-charset)
2951 (mail-parse-ignored-charsets
2952 (save-excursion (set-buffer gnus-summary-buffer)
2953 gnus-newsgroup-ignored-charsets)))
2954 (if (mm-handle-undisplayer handle)
2955 (mm-remove-part handle)
2956 (mm-display-part handle))))
2958 (defun gnus-article-part-wrapper (n function)
2959 (save-current-buffer
2960 (set-buffer gnus-article-buffer)
2961 (when (> n (length gnus-article-mime-handle-alist))
2962 (error "No such part"))
2963 (gnus-article-goto-part n)
2964 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2965 (funcall function handle))))
2967 (defun gnus-article-pipe-part (n)
2968 "Pipe MIME part N, which is the numerical prefix."
2970 (gnus-article-part-wrapper n 'mm-pipe-part))
2972 (defun gnus-article-save-part (n)
2973 "Save MIME part N, which is the numerical prefix."
2975 (gnus-article-part-wrapper n 'mm-save-part))
2977 (defun gnus-article-interactively-view-part (n)
2978 "View MIME part N interactively, which is the numerical prefix."
2980 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2982 (defun gnus-article-copy-part (n)
2983 "Copy MIME part N, which is the numerical prefix."
2985 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2987 (defun gnus-article-externalize-part (n)
2988 "View MIME part N externally, which is the numerical prefix."
2990 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2992 (defun gnus-article-inline-part (n)
2993 "Inline MIME part N, which is the numerical prefix."
2995 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2997 (defun gnus-article-mime-match-handle-first (condition)
2999 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3000 (while (setq ihandle (pop alist))
3002 ((functionp condition)
3003 (funcall condition (cdr ihandle)))
3004 ((eq condition 'undisplayed)
3005 (not (or (mm-handle-undisplayer (cdr ihandle))
3006 (equal (mm-handle-media-type (cdr ihandle))
3007 "multipart/alternative"))))
3008 ((eq condition 'undisplayed-alternative)
3009 (not (mm-handle-undisplayer (cdr ihandle))))
3011 (gnus-article-goto-part (car ihandle))
3012 (or (not n) (< (car ihandle) n)))
3013 (setq n (car ihandle))))
3017 (defun gnus-article-view-part (&optional n)
3018 "View MIME part N, which is the numerical prefix."
3020 (save-current-buffer
3021 (set-buffer gnus-article-buffer)
3022 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3023 gnus-article-mime-match-handle-function)))
3024 (when (> n (length gnus-article-mime-handle-alist))
3025 (error "No such part"))
3026 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3027 (when (gnus-article-goto-part n)
3028 (if (equal (car handle) "multipart/alternative")
3029 (gnus-article-press-button)
3030 (when (eq (gnus-mm-display-part handle) 'internal)
3031 (gnus-set-window-start)))))))
3033 (defun gnus-mm-display-part (handle)
3034 "Display HANDLE and fix MIME button."
3035 (let ((id (get-text-property (point) 'gnus-part))
3040 (let ((window (selected-window))
3041 (mail-parse-charset gnus-newsgroup-charset)
3042 (mail-parse-ignored-charsets
3043 (save-excursion (set-buffer gnus-summary-buffer)
3044 gnus-newsgroup-ignored-charsets)))
3047 (let ((win (get-buffer-window (current-buffer) t))
3050 (select-window win))
3053 (if (mm-handle-displayed-p handle)
3054 ;; This will remove the part.
3055 (mm-display-part handle)
3057 (narrow-to-region (point) (1+ (point)))
3058 (mm-display-part handle)
3059 ;; We narrow to the part itself and
3060 ;; then call the treatment functions.
3061 (goto-char (point-min))
3063 (narrow-to-region (point) (point-max))
3066 (1- (length gnus-article-mime-handles))
3067 (mm-handle-media-type handle)))))
3068 (select-window window))))
3070 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3071 (gnus-insert-mime-button
3072 handle id (list (mm-handle-displayed-p handle)))
3073 (goto-char point))))
3075 (defun gnus-article-goto-part (n)
3076 "Go to MIME part N."
3077 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3079 (goto-char point))))
3081 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3082 (let ((gnus-tmp-name
3083 (or (mail-content-type-get (mm-handle-type handle)
3085 (mail-content-type-get (mm-handle-disposition handle)
3088 (gnus-tmp-type (mm-handle-media-type handle))
3089 (gnus-tmp-description
3090 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3093 (if (if displayed (car displayed)
3094 (mm-handle-displayed-p handle))
3096 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3098 gnus-tmp-type-long b e)
3099 (when (string-match ".*/" gnus-tmp-name)
3100 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3101 (setq gnus-tmp-type-long (concat gnus-tmp-type
3102 (and (not (equal gnus-tmp-name ""))
3103 (concat "; " gnus-tmp-name))))
3104 (or (equal gnus-tmp-description "")
3105 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3110 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3111 `(local-map ,gnus-mime-button-map
3112 keymap ,gnus-mime-button-map
3113 gnus-callback gnus-mm-display-part
3114 gnus-part ,gnus-tmp-id
3115 article-type annotation
3118 (widget-convert-button 'link b e
3120 :action 'gnus-widget-press-button
3121 :button-keymap gnus-mime-button-map
3124 ;; Needed to properly clear the message
3125 ;; due to a bug in wid-edit
3126 (setq help-echo-owns-message t)
3128 "Click to %s the MIME part; %s for more options"
3129 (if (mm-handle-displayed-p
3130 (widget-get widget :mime-handle))
3132 (if gnus-xemacs "button3" "mouse-3"))))))
3134 (defun gnus-widget-press-button (elems el)
3135 (goto-char (widget-get elems :from))
3136 (gnus-article-press-button))
3138 (defvar gnus-displaying-mime nil)
3140 (defun gnus-display-mime (&optional ihandles)
3141 "Display the MIME parts."
3143 (save-selected-window
3144 (let ((window (get-buffer-window gnus-article-buffer))
3147 (select-window window)
3148 ;; We have to do this since selecting the window
3149 ;; may change the point. So we set the window point.
3150 (set-window-point window point)))
3151 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3152 buffer-read-only handle name type b e display)
3153 (when (and (not ihandles)
3154 (not gnus-displaying-mime))
3155 ;; Top-level call; we clean up.
3156 (when gnus-article-mime-handles
3157 (mm-destroy-parts gnus-article-mime-handles)
3158 (setq gnus-article-mime-handle-alist nil));; A trick.
3159 (setq gnus-article-mime-handles handles)
3160 ;; We allow users to glean info from the handles.
3161 (when gnus-article-mime-part-function
3162 (gnus-mime-part-function handles)))
3164 (or (not (stringp (car handles)))
3167 (when (and (not ihandles)
3168 (not gnus-displaying-mime))
3169 ;; Clean up for mime parts.
3171 (delete-region (point) (point-max)))
3172 (let ((gnus-displaying-mime t))
3173 (gnus-mime-display-part handles)))
3176 (narrow-to-region (point) (point-max))
3177 (gnus-treat-article nil 1 1)
3180 ;; Highlight the headers.
3184 (narrow-to-region (point-min) (point))
3185 (gnus-treat-article 'head))))))))
3187 (defvar gnus-mime-display-multipart-as-mixed nil)
3189 (defun gnus-mime-display-part (handle)
3192 ((not (stringp (car handle)))
3193 (gnus-mime-display-single handle))
3194 ;; User-defined multipart
3195 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3196 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3198 ;; multipart/alternative
3199 ((and (equal (car handle) "multipart/alternative")
3200 (not gnus-mime-display-multipart-as-mixed))
3201 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3202 (push (cons id handle) gnus-article-mime-handle-alist)
3203 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3204 ;; multipart/related
3205 ((and (equal (car handle) "multipart/related")
3206 (not gnus-mime-display-multipart-as-mixed))
3207 ;;;!!!We should find the start part, but we just default
3208 ;;;!!!to the first part.
3209 (gnus-mime-display-part (cadr handle)))
3210 ;; Other multiparts are handled like multipart/mixed.
3212 (gnus-mime-display-mixed (cdr handle)))))
3214 (defun gnus-mime-part-function (handles)
3215 (if (stringp (car handles))
3216 (mapcar 'gnus-mime-part-function (cdr handles))
3217 (funcall gnus-article-mime-part-function handles)))
3219 (defun gnus-mime-display-mixed (handles)
3220 (mapcar 'gnus-mime-display-part handles))
3222 (defun gnus-mime-display-single (handle)
3223 (let ((type (mm-handle-media-type handle))
3224 (ignored gnus-ignored-mime-types)
3231 (when (string-match (pop ignored) type)
3232 (throw 'ignored nil)))
3233 (if (and (setq not-attachment
3234 (and (not (mm-inline-override-p handle))
3235 (or (not (mm-handle-disposition handle))
3236 (equal (car (mm-handle-disposition handle))
3238 (mm-attachment-override-p handle))))
3239 (mm-automatic-display-p handle)
3240 (or (mm-inlined-p handle)
3241 (mm-automatic-external-display-p type)))
3243 (when (equal (mm-handle-media-supertype handle) "text")
3245 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3246 (push (cons id handle) gnus-article-mime-handle-alist)
3247 (when (or (not display)
3248 (not (gnus-unbuttonized-mime-type-p type)))
3249 ;(gnus-article-insert-newline)
3250 (gnus-insert-mime-button
3251 handle id (list (or display (and not-attachment text))))
3252 (gnus-article-insert-newline)
3253 ;(gnus-article-insert-newline)
3255 (let ((beg (point)))
3261 (let ((mail-parse-charset gnus-newsgroup-charset)
3262 (mail-parse-ignored-charsets
3263 (save-excursion (condition-case ()
3264 (set-buffer gnus-summary-buffer)
3266 gnus-newsgroup-ignored-charsets)))
3267 (mm-display-part handle t))
3268 (goto-char (point-max)))
3269 ((and text not-attachment)
3273 (gnus-article-insert-newline)
3274 (mm-insert-inline handle (mm-get-part handle))
3275 (goto-char (point-max))))
3279 (narrow-to-region beg (point))
3281 nil (length gnus-article-mime-handle-alist)
3282 (1- (length gnus-article-mime-handles))
3283 (mm-handle-media-type handle)))))))))
3285 (defun gnus-unbuttonized-mime-type-p (type)
3286 "Say whether TYPE is to be unbuttonized."
3287 (unless gnus-inhibit-mime-unbuttonizing
3289 (let ((types gnus-unbuttonized-mime-types))
3291 (when (string-match (pop types) type)
3292 (throw 'found t)))))))
3294 (defun gnus-article-insert-newline ()
3295 "Insert a newline, but mark it as undeletable."
3296 (gnus-put-text-property
3297 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3299 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3300 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3303 handle buffer-read-only from props begend not-pref)
3304 (save-window-excursion
3307 (narrow-to-region (car ibegend)
3310 (goto-char (car ibegend))
3313 (delete-region (point-min) (point-max))
3314 (mm-remove-parts handles))
3315 (setq begend (list (point-marker)))
3317 (unless (setq not-pref (cadr (member preferred ihandles)))
3318 (setq not-pref (car ihandles)))
3320 (not (gnus-unbuttonized-mime-type-p
3321 "multipart/alternative")))
3322 (gnus-add-text-properties
3325 (insert (format "%d. " id))
3329 (unless ,(not ibegend)
3330 (setq gnus-article-mime-handle-alist
3331 ',gnus-article-mime-handle-alist))
3332 (gnus-mime-display-alternative
3333 ',ihandles ',not-pref ',begend ,id))
3334 local-map ,gnus-mime-button-map
3335 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3336 face ,gnus-article-button-face
3337 keymap ,gnus-mime-button-map
3340 (widget-convert-button 'link from (point)
3341 :action 'gnus-widget-press-button
3342 :button-keymap gnus-widget-button-keymap)
3344 (while (setq handle (pop handles))
3345 (gnus-add-text-properties
3348 (insert (format "(%c) %-18s"
3349 (if (equal handle preferred) ?* ? )
3350 (mm-handle-media-type handle)))
3354 (unless ,(not ibegend)
3355 (setq gnus-article-mime-handle-alist
3356 ',gnus-article-mime-handle-alist))
3357 (gnus-mime-display-alternative
3358 ',ihandles ',handle ',begend ,id))
3359 local-map ,gnus-mime-button-map
3360 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3361 face ,gnus-article-button-face
3362 keymap ,gnus-mime-button-map
3365 (widget-convert-button 'link from (point)
3366 :action 'gnus-widget-press-button
3367 :button-keymap gnus-widget-button-keymap)
3371 (if (stringp (car preferred))
3372 (gnus-display-mime preferred)
3373 (let ((mail-parse-charset gnus-newsgroup-charset)
3374 (mail-parse-ignored-charsets
3375 (save-excursion (set-buffer gnus-summary-buffer)
3376 gnus-newsgroup-ignored-charsets)))
3377 (mm-display-part preferred)
3381 (narrow-to-region (car begend) (point-max))
3383 nil (length gnus-article-mime-handle-alist)
3384 (1- (length gnus-article-mime-handles))
3385 (mm-handle-media-type handle))))))
3386 (goto-char (point-max))
3387 (setcdr begend (point-marker)))))
3389 (goto-char point))))
3391 (defun gnus-article-wash-status ()
3392 "Return a string which display status of article washing."
3394 (set-buffer gnus-article-buffer)
3395 (let ((cite (memq 'cite gnus-article-wash-types))
3396 (headers (memq 'headers gnus-article-wash-types))
3397 (boring (memq 'boring-headers gnus-article-wash-types))
3398 (pgp (memq 'pgp gnus-article-wash-types))
3399 (pem (memq 'pem gnus-article-wash-types))
3400 (signature (memq 'signature gnus-article-wash-types))
3401 (overstrike (memq 'overstrike gnus-article-wash-types))
3402 (emphasis (memq 'emphasis gnus-article-wash-types)))
3403 (format "%c%c%c%c%c%c"
3405 (if (or headers boring) ?h ? )
3406 (if (or pgp pem) ?p ? )
3407 (if signature ?s ? )
3408 (if overstrike ?o ? )
3409 (if emphasis ?e ? )))))
3411 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3413 (defun gnus-article-maybe-hide-headers ()
3414 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3415 Provided for backwards compatibility."
3416 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3417 (not (save-excursion (set-buffer gnus-summary-buffer)
3418 gnus-have-all-headers)))
3419 (not gnus-inhibit-hiding))
3420 (gnus-article-hide-headers)))
3424 (defun gnus-output-to-file (file-name)
3425 "Append the current article to a file named FILE-NAME."
3426 (let ((artbuf (current-buffer)))
3428 (insert-buffer-substring artbuf)
3429 ;; Append newline at end of the buffer as separator, and then
3431 (goto-char (point-max))
3433 (mm-append-to-file (point-min) (point-max) file-name)
3436 (defun gnus-narrow-to-page (&optional arg)
3437 "Narrow the article buffer to a page.
3438 If given a numerical ARG, move forward ARG pages."
3440 (setq arg (if arg (prefix-numeric-value arg) 0))
3442 (set-buffer gnus-article-buffer)
3443 (goto-char (point-min))
3445 ;; Remove any old next/prev buttons.
3446 (when (gnus-visual-p 'page-marker)
3447 (let ((buffer-read-only nil))
3448 (gnus-remove-text-with-property 'gnus-prev)
3449 (gnus-remove-text-with-property 'gnus-next)))
3452 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3454 (re-search-forward page-delimiter nil 'move arg)))
3455 (goto-char (match-end 0)))
3458 (if (re-search-forward page-delimiter nil 'move)
3461 (when (and (gnus-visual-p 'page-marker)
3462 (not (= (point-min) 1)))
3464 (goto-char (point-min))
3465 (gnus-insert-prev-page-button)))
3466 (when (and (gnus-visual-p 'page-marker)
3467 (< (+ (point-max) 2) (buffer-size)))
3469 (goto-char (point-max))
3470 (gnus-insert-next-page-button)))))
3472 ;; Article mode commands
3474 (defun gnus-article-goto-next-page ()
3475 "Show the next page of the article."
3477 (when (gnus-article-next-page)
3478 (goto-char (point-min))
3479 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3481 (defun gnus-article-goto-prev-page ()
3482 "Show the next page of the article."
3484 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3485 (gnus-article-prev-page nil)))
3487 (defun gnus-article-next-page (&optional lines)
3488 "Show the next page of the current article.
3489 If end of article, return non-nil. Otherwise return nil.
3490 Argument LINES specifies lines to be scrolled up."
3492 (move-to-window-line -1)
3495 (and (pos-visible-in-window-p) ;Not continuation line.
3497 ;; Nothing in this page.
3498 (if (or (not gnus-page-broken)
3501 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3503 (gnus-narrow-to-page 1) ;Go to next page.
3505 ;; More in this page.
3506 (let ((scroll-in-place nil))
3510 ;; Long lines may cause an end-of-buffer error.
3511 (goto-char (point-max)))))
3512 (move-to-window-line 0)
3515 (defun gnus-article-prev-page (&optional lines)
3516 "Show previous page of current article.
3517 Argument LINES specifies lines to be scrolled down."
3519 (move-to-window-line 0)
3520 (if (and gnus-page-broken
3522 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3524 (gnus-narrow-to-page -1) ;Go to previous page.
3525 (goto-char (point-max))
3527 (let ((scroll-in-place nil))
3531 (beginning-of-buffer
3532 (goto-char (point-min))))
3533 (move-to-window-line 0)))))
3535 (defun gnus-article-refer-article ()
3536 "Read article specified by message-id around point."
3538 (let ((point (point)))
3539 (search-forward ">" nil t) ;Move point to end of "<....>".
3540 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3541 (let ((message-id (match-string 1)))
3543 (set-buffer gnus-summary-buffer)
3544 (gnus-summary-refer-article message-id))
3546 (error "No references around point"))))
3548 (defun gnus-article-show-summary ()
3549 "Reconfigure windows to show summary buffer."
3551 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3552 (error "There is no summary buffer for this article buffer")
3553 (gnus-article-set-globals)
3554 (gnus-configure-windows 'article)
3555 (gnus-summary-goto-subject gnus-current-article)
3556 (gnus-summary-position-point)))
3558 (defun gnus-article-describe-briefly ()
3559 "Describe article mode commands briefly."
3561 (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")))
3563 (defun gnus-article-summary-command ()
3564 "Execute the last keystroke in the summary buffer."
3566 (let ((obuf (current-buffer))
3567 (owin (current-window-configuration))
3569 (switch-to-buffer gnus-article-current-summary 'norecord)
3570 (setq func (lookup-key (current-local-map) (this-command-keys)))
3571 (call-interactively func)
3573 (set-window-configuration owin)
3574 (set-window-point (get-buffer-window (current-buffer)) (point))))
3576 (defun gnus-article-summary-command-nosave ()
3577 "Execute the last keystroke in the summary buffer."
3580 (pop-to-buffer gnus-article-current-summary 'norecord)
3581 (setq func (lookup-key (current-local-map) (this-command-keys)))
3582 (call-interactively func)))
3584 (defun gnus-article-check-buffer ()
3585 "Beep if not in an article buffer."
3586 (unless (equal major-mode 'gnus-article-mode)
3587 (error "Command invoked outside of a Gnus article buffer")))
3589 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3590 "Read a summary buffer key sequence and execute it from the article buffer."
3592 (gnus-article-check-buffer)
3594 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3595 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3596 "=" "^" "\M-^" "|"))
3602 '("n" "Gn" "p" "Gp"))
3605 (set-buffer gnus-article-current-summary)
3606 (let (gnus-pick-mode)
3607 (push (or key last-command-event) unread-command-events)
3608 (setq keys (if gnus-xemacs
3609 (events-to-keys (read-key-sequence nil))
3610 (read-key-sequence nil)))))
3614 (if (or (member keys nosaves)
3615 (member keys nosave-but-article)
3616 (member keys nosave-in-article))
3618 (save-window-excursion
3619 (pop-to-buffer gnus-article-current-summary 'norecord)
3620 ;; We disable the pick minor mode commands.
3621 (let (gnus-pick-mode)
3622 (setq func (lookup-key (current-local-map) keys))))
3626 (unless (member keys nosave-in-article)
3627 (set-buffer gnus-article-current-summary))
3628 (call-interactively func)
3629 (setq new-sum-point (point)))
3630 (when (member keys nosave-but-article)
3631 (pop-to-buffer gnus-article-buffer 'norecord)))
3632 ;; These commands should restore window configuration.
3633 (let ((obuf (current-buffer))
3634 (owin (current-window-configuration))
3636 (summary gnus-article-current-summary)
3637 func in-buffer selected)
3638 (if not-restore-window
3639 (pop-to-buffer summary 'norecord)
3640 (switch-to-buffer summary 'norecord))
3641 (setq in-buffer (current-buffer))
3642 ;; We disable the pick minor mode commands.
3643 (if (setq func (let (gnus-pick-mode)
3644 (lookup-key (current-local-map) keys)))
3646 (call-interactively func)
3647 (setq new-sum-point (point)))
3649 (when (eq in-buffer (current-buffer))
3650 (setq selected (gnus-summary-select-article))
3652 (unless not-restore-window
3653 (set-window-configuration owin))
3654 (when (eq selected 'old)
3656 (set-window-start (get-buffer-window (current-buffer))
3658 (set-window-point (get-buffer-window (current-buffer))
3660 (let ((win (get-buffer-window gnus-article-current-summary)))
3662 (set-window-point win new-sum-point))))))))
3664 (defun gnus-article-hide (&optional arg force)
3665 "Hide all the gruft in the current article.
3666 This means that PGP stuff, signatures, cited text and (some)
3667 headers will be hidden.
3668 If given a prefix, show the hidden text instead."
3669 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3670 (gnus-article-hide-headers arg)
3671 (gnus-article-hide-list-identifiers arg)
3672 (gnus-article-hide-pgp arg)
3673 (gnus-article-hide-citation-maybe arg force)
3674 (gnus-article-hide-signature arg))
3676 (defun gnus-article-maybe-highlight ()
3677 "Do some article highlighting if article highlighting is requested."
3678 (when (gnus-visual-p 'article-highlight 'highlight)
3679 (gnus-article-highlight-some)))
3681 (defun gnus-check-group-server ()
3682 ;; Make sure the connection to the server is alive.
3683 (unless (gnus-server-opened
3684 (gnus-find-method-for-group gnus-newsgroup-name))
3685 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3686 (gnus-request-group gnus-newsgroup-name t)))
3688 (defun gnus-request-article-this-buffer (article group)
3689 "Get an article and insert it into this buffer."
3690 (let (do-update-line sparse-header)
3694 (gnus-kill-all-overlays)
3695 (setq group (or group gnus-newsgroup-name))
3697 ;; Using `gnus-request-article' directly will insert the article into
3698 ;; `nntp-server-buffer' - so we'll save some time by not having to
3699 ;; copy it from the server buffer into the article buffer.
3701 ;; We only request an article by message-id when we do not have the
3702 ;; headers for it, so we'll have to get those.
3703 (when (stringp article)
3704 (gnus-read-header article))
3706 ;; If the article number is negative, that means that this article
3707 ;; doesn't belong in this newsgroup (possibly), so we find its
3708 ;; message-id and request it by id instead of number.
3709 (when (and (numberp article)
3711 (get-buffer gnus-summary-buffer)
3712 (gnus-buffer-exists-p gnus-summary-buffer))
3714 (set-buffer gnus-summary-buffer)
3715 (let ((header (gnus-summary-article-header article)))
3718 ((memq article gnus-newsgroup-sparse)
3719 ;; This is a sparse gap article.
3720 (setq do-update-line article)
3721 (setq article (mail-header-id header))
3722 (setq sparse-header (gnus-read-header article))
3723 (setq gnus-newsgroup-sparse
3724 (delq article gnus-newsgroup-sparse)))
3726 ;; It's a real article.
3727 (setq article (mail-header-id header)))
3729 ;; It is an extracted pseudo-article.
3730 (setq article 'pseudo)
3731 (gnus-request-pseudo-article header))))
3733 (let ((method (gnus-find-method-for-group
3734 gnus-newsgroup-name)))
3735 (when (and (eq (car method) 'nneething)
3738 (file-name-as-directory
3739 (or (cadr (assq 'nneething-address method))
3741 (mail-header-subject header))))
3742 (when (file-directory-p dir)
3743 (setq article 'nneething)
3744 (gnus-group-enter-directory dir))))))))
3747 ;; Refuse to select canceled articles.
3748 ((and (numberp article)
3750 (get-buffer gnus-summary-buffer)
3751 (gnus-buffer-exists-p gnus-summary-buffer)
3752 (eq (cdr (save-excursion
3753 (set-buffer gnus-summary-buffer)
3754 (assq article gnus-newsgroup-reads)))
3755 gnus-canceled-mark))
3757 ;; We first check `gnus-original-article-buffer'.
3758 ((and (get-buffer gnus-original-article-buffer)
3761 (set-buffer gnus-original-article-buffer)
3762 (and (equal (car gnus-original-article) group)
3763 (eq (cdr gnus-original-article) article))))
3764 (insert-buffer-substring gnus-original-article-buffer)
3766 ;; Check the backlog.
3767 ((and gnus-keep-backlog
3768 (gnus-backlog-request-article group article (current-buffer)))
3770 ;; Check asynchronous pre-fetch.
3771 ((gnus-async-request-fetched-article group article (current-buffer))
3772 (gnus-async-prefetch-next group article gnus-summary-buffer)
3773 (when (and (numberp article) gnus-keep-backlog)
3774 (gnus-backlog-enter-article group article (current-buffer)))
3777 ((and gnus-use-cache
3779 (gnus-cache-request-article article group))
3781 ;; Get the article and put into the article buffer.
3782 ((or (stringp article)
3784 (let ((gnus-override-method gnus-override-method)
3785 (methods (and (stringp article)
3786 gnus-refer-article-method))
3788 (buffer-read-only nil))
3793 (when (and (null gnus-override-method)
3795 (setq gnus-override-method (pop methods)))
3797 (when (eq gnus-override-method 'current)
3798 (setq gnus-override-method gnus-current-select-method))
3800 (gnus-kill-all-overlays)
3801 (let ((gnus-newsgroup-name group))
3802 (gnus-check-group-server))
3803 (when (gnus-request-article article group (current-buffer))
3804 (when (numberp article)
3805 (gnus-async-prefetch-next group article
3806 gnus-summary-buffer)
3807 (when gnus-keep-backlog
3808 (gnus-backlog-enter-article
3809 group article (current-buffer))))
3810 (setq result 'article))
3813 (setq gnus-override-method (pop methods))
3814 (setq result 'done))))
3815 (and (eq result 'article) 'article)))
3819 ;; Associate this article with the current summary buffer.
3820 (setq gnus-article-current-summary gnus-summary-buffer)
3822 ;; Take the article from the original article buffer
3823 ;; and place it in the buffer it's supposed to be in.
3824 (when (and (get-buffer gnus-article-buffer)
3825 (equal (buffer-name (current-buffer))
3826 (buffer-name (get-buffer gnus-article-buffer))))
3828 (if (get-buffer gnus-original-article-buffer)
3829 (set-buffer gnus-original-article-buffer)
3830 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3831 (buffer-disable-undo)
3832 (setq major-mode 'gnus-original-article-mode)
3833 (setq buffer-read-only t))
3834 (let (buffer-read-only)
3836 (insert-buffer-substring gnus-article-buffer))
3837 (setq gnus-original-article (cons group article)))
3840 (run-hooks 'gnus-article-decode-hook)
3841 ;; Mark article as decoded or not.
3842 (setq gnus-article-decoded-p gnus-article-decode-hook))
3844 ;; Update sparse articles.
3845 (when (and do-update-line
3846 (or (numberp article)
3848 (let ((buf (current-buffer)))
3849 (set-buffer gnus-summary-buffer)
3850 (gnus-summary-update-article do-update-line sparse-header)
3851 (gnus-summary-goto-subject do-update-line nil t)
3852 (set-window-point (get-buffer-window (current-buffer) t)
3854 (set-buffer buf))))))
3860 (defcustom gnus-article-edit-mode-hook nil
3861 "Hook run in article edit mode buffers."
3862 :group 'gnus-article-various
3865 (defvar gnus-article-edit-done-function nil)
3867 (defvar gnus-article-edit-mode-map nil)
3869 ;; Should we be using derived.el for this?
3870 (unless gnus-article-edit-mode-map
3871 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3872 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3874 (gnus-define-keys gnus-article-edit-mode-map
3875 "\C-c\C-c" gnus-article-edit-done
3876 "\C-c\C-k" gnus-article-edit-exit)
3878 (gnus-define-keys (gnus-article-edit-wash-map
3879 "\C-c\C-w" gnus-article-edit-mode-map)
3880 "f" gnus-article-edit-full-stops))
3882 (defun gnus-article-edit-mode ()
3883 "Major mode for editing articles.
3884 This is an extended text-mode.
3886 \\{gnus-article-edit-mode-map}"
3888 (setq major-mode 'gnus-article-edit-mode)
3889 (setq mode-name "Article Edit")
3890 (use-local-map gnus-article-edit-mode-map)
3891 (make-local-variable 'gnus-article-edit-done-function)
3892 (make-local-variable 'gnus-prev-winconf)
3893 (setq buffer-read-only nil)
3894 (buffer-enable-undo)
3896 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3898 (defun gnus-article-edit (&optional force)
3899 "Edit the current article.
3900 This will have permanent effect only in mail groups.
3901 If FORCE is non-nil, allow editing of articles even in read-only
3904 (when (and (not force)
3905 (gnus-group-read-only-p))
3906 (error "The current newsgroup does not support article editing"))
3907 (gnus-article-date-original)
3908 (gnus-article-edit-article
3910 `(lambda (no-highlight)
3912 (gnus-summary-edit-article-done
3913 ,(or (mail-header-references gnus-current-headers) "")
3914 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3916 (defun gnus-article-edit-article (start-func exit-func)
3917 "Start editing the contents of the current article buffer."
3918 (let ((winconf (current-window-configuration)))
3919 (set-buffer gnus-article-buffer)
3920 (gnus-article-edit-mode)
3921 (funcall start-func)
3922 (gnus-configure-windows 'edit-article)
3923 (setq gnus-article-edit-done-function exit-func)
3924 (setq gnus-prev-winconf winconf)
3925 (gnus-message 6 "C-c C-c to end edits")))
3927 (defun gnus-article-edit-done (&optional arg)
3928 "Update the article edits and exit."
3933 (when (article-goto-body)
3934 (let ((lines (count-lines (point) (point-max)))
3935 (length (- (point-max) (point)))
3936 (case-fold-search t)
3937 (body (copy-marker (point))))
3938 (goto-char (point-min))
3939 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3940 (delete-region (match-beginning 1) (match-end 1))
3941 (insert (number-to-string length)))
3942 (goto-char (point-min))
3943 (when (re-search-forward
3944 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3945 (delete-region (match-beginning 1) (match-end 1))
3946 (insert (number-to-string length)))
3947 (goto-char (point-min))
3948 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3949 (delete-region (match-beginning 1) (match-end 1))
3950 (insert (number-to-string lines)))))))
3951 (let ((func gnus-article-edit-done-function)
3952 (buf (current-buffer))
3953 (start (window-start)))
3954 (gnus-article-edit-exit)
3957 (let ((buffer-read-only nil))
3959 ;; The cache and backlog have to be flushed somewhat.
3960 (when gnus-keep-backlog
3961 (gnus-backlog-remove-article
3962 (car gnus-article-current) (cdr gnus-article-current)))
3963 ;; Flush original article as well.
3965 (when (get-buffer gnus-original-article-buffer)
3966 (set-buffer gnus-original-article-buffer)
3967 (setq gnus-original-article nil)))
3968 (when gnus-use-cache
3969 (gnus-cache-update-article
3970 (car gnus-article-current) (cdr gnus-article-current))))
3972 (set-window-start (get-buffer-window buf) start)
3973 (set-window-point (get-buffer-window buf) (point))))
3975 (defun gnus-article-edit-exit ()
3976 "Exit the article editing without updating."
3978 ;; We remove all text props from the article buffer.
3979 (let ((buf (format "%s" (buffer-string)))
3980 (curbuf (current-buffer))
3982 (window-start (window-start)))
3985 (let ((winconf gnus-prev-winconf))
3987 (set-window-configuration winconf)
3988 ;; Tippy-toe some to make sure that point remains where it was.
3989 (save-current-buffer
3991 (set-window-start (get-buffer-window (current-buffer)) window-start)
3994 (defun gnus-article-edit-full-stops ()
3995 "Interactively repair spacing at end of sentences."
3998 (goto-char (point-min))
3999 (search-forward-regexp "^$" nil t)
4000 (let ((case-fold-search nil))
4001 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4004 ;;; Article highlights
4007 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4009 ;;; Internal Variables:
4011 (defcustom gnus-button-url-regexp "\\b\\(\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)\\|[-a-zA-Z0-9_]+\\.[-a-zA-Z0-9_]+\\(\\.[-a-zA-Z0-9_]+[-a-zA-Z0-9_/]+\\)+"
4012 "Regular expression that matches URLs."
4013 :group 'gnus-article-buttons
4016 (defcustom gnus-button-alist
4017 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4018 0 t gnus-button-message-id 2)
4019 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4020 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4022 gnus-button-fetch-group 4)
4023 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4024 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4025 t gnus-button-message-id 3)
4026 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4027 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4028 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4029 ;; This is how URLs _should_ be embedded in text...
4030 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4032 (,gnus-button-url-regexp 0 t browse-url 0))
4033 "*Alist of regexps matching buttons in article bodies.
4035 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4036 REGEXP: is the string matching text around the button,
4037 BUTTON: is the number of the regexp grouping actually matching the button,
4038 FORM: is a lisp expression which must eval to true for the button to
4040 CALLBACK: is the function to call when the user push this button, and each
4041 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4043 CALLBACK can also be a variable, in that case the value of that
4044 variable it the real callback function."
4045 :group 'gnus-article-buttons
4046 :type '(repeat (list regexp
4047 (integer :tag "Button")
4049 (function :tag "Callback")
4052 (integer :tag "Regexp group")))))
4054 (defcustom gnus-header-button-alist
4055 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4056 0 t gnus-button-message-id 0)
4057 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4058 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4059 0 t gnus-button-mailto 0)
4060 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4061 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4062 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4063 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4064 gnus-button-message-id 3))
4065 "*Alist of headers and regexps to match buttons in article heads.
4067 This alist is very similar to `gnus-button-alist', except that each
4068 alist has an additional HEADER element first in each entry:
4070 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4072 HEADER is a regexp to match a header. For a fuller explanation, see
4073 `gnus-button-alist'."
4074 :group 'gnus-article-buttons
4075 :group 'gnus-article-headers
4076 :type '(repeat (list (regexp :tag "Header")
4078 (integer :tag "Button")
4080 (function :tag "Callback")
4083 (integer :tag "Regexp group")))))
4085 (defvar gnus-button-regexp nil)
4086 (defvar gnus-button-marker-list nil)
4087 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4089 (defvar gnus-button-last nil)
4090 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4094 (defun gnus-article-push-button (event)
4095 "Check text under the mouse pointer for a callback function.
4096 If the text under the mouse pointer has a `gnus-callback' property,
4097 call it with the value of the `gnus-data' text property."
4099 (set-buffer (window-buffer (posn-window (event-start event))))
4100 (let* ((pos (posn-point (event-start event)))
4101 (data (get-text-property pos 'gnus-data))
4102 (fun (get-text-property pos 'gnus-callback)))
4105 (funcall fun data))))
4107 (defun gnus-article-press-button ()
4108 "Check text at point for a callback function.
4109 If the text at point has a `gnus-callback' property,
4110 call it with the value of the `gnus-data' text property."
4112 (let* ((data (get-text-property (point) 'gnus-data))
4113 (fun (get-text-property (point) 'gnus-callback)))
4115 (funcall fun data))))
4117 (defun gnus-article-highlight (&optional force)
4118 "Highlight current article.
4119 This function calls `gnus-article-highlight-headers',
4120 `gnus-article-highlight-citation',
4121 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4122 do the highlighting. See the documentation for those functions."
4123 (interactive (list 'force))
4124 (gnus-article-highlight-headers)
4125 (gnus-article-highlight-citation force)
4126 (gnus-article-highlight-signature)
4127 (gnus-article-add-buttons force)
4128 (gnus-article-add-buttons-to-head))
4130 (defun gnus-article-highlight-some (&optional force)
4131 "Highlight current article.
4132 This function calls `gnus-article-highlight-headers',
4133 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4134 do the highlighting. See the documentation for those functions."
4135 (interactive (list 'force))
4136 (gnus-article-highlight-headers)
4137 (gnus-article-highlight-signature)
4138 (gnus-article-add-buttons))
4140 (defun gnus-article-highlight-headers ()
4141 "Highlight article headers as specified by `gnus-header-face-alist'."
4144 (set-buffer gnus-article-buffer)
4146 (let ((alist gnus-header-face-alist)
4147 (buffer-read-only nil)
4148 (case-fold-search t)
4149 (inhibit-point-motion-hooks t)
4150 entry regexp header-face field-face from hpoints fpoints)
4151 (article-narrow-to-head)
4152 (while (setq entry (pop alist))
4153 (goto-char (point-min))
4154 (setq regexp (concat "^\\("
4155 (if (string-equal "" (nth 0 entry))
4159 header-face (nth 1 entry)
4160 field-face (nth 2 entry))
4161 (while (and (re-search-forward regexp nil t)
4165 (unless (search-forward ":" nil t)
4167 (when (and header-face
4168 (not (memq (point) hpoints)))
4169 (push (point) hpoints)
4170 (gnus-put-text-property from (point) 'face header-face))
4171 (when (and field-face
4172 (not (memq (setq from (point)) fpoints)))
4174 (if (re-search-forward "^[^ \t]" nil t)
4176 (goto-char (point-max)))
4177 (gnus-put-text-property from (point) 'face field-face))))))))
4179 (defun gnus-article-highlight-signature ()
4180 "Highlight the signature in an article.
4181 It does this by highlighting everything after
4182 `gnus-signature-separator' using `gnus-signature-face'."
4185 (set-buffer gnus-article-buffer)
4186 (let ((buffer-read-only nil)
4187 (inhibit-point-motion-hooks t))
4189 (when (and gnus-signature-face
4190 (gnus-article-narrow-to-signature))
4191 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4192 'face gnus-signature-face)
4194 (gnus-article-search-signature)
4195 (let ((start (match-beginning 0))
4196 (end (set-marker (make-marker) (1+ (match-end 0)))))
4197 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4200 (defun gnus-button-in-region-p (b e prop)
4201 "Say whether PROP exists in the region."
4202 (text-property-not-all b e prop nil))
4204 (defun gnus-article-add-buttons (&optional force)
4205 "Find external references in the article and make buttons of them.
4206 \"External references\" are things like Message-IDs and URLs, as
4207 specified by `gnus-button-alist'."
4208 (interactive (list 'force))
4210 (set-buffer gnus-article-buffer)
4211 (let ((buffer-read-only nil)
4212 (inhibit-point-motion-hooks t)
4213 (case-fold-search t)
4214 (alist gnus-button-alist)
4216 ;; Remove all old markers.
4217 (let (marker entry new-list)
4218 (while (setq marker (pop gnus-button-marker-list))
4219 (if (or (< marker (point-min)) (>= marker (point-max)))
4220 (push marker new-list)
4222 (when (setq entry (gnus-button-entry))
4223 (put-text-property (match-beginning (nth 1 entry))
4224 (match-end (nth 1 entry))
4225 'gnus-callback nil))
4226 (set-marker marker nil)))
4227 (setq gnus-button-marker-list new-list))
4228 ;; We skip the headers.
4231 (while (setq entry (pop alist))
4232 (setq regexp (car entry))
4234 (while (re-search-forward regexp nil t)
4235 (let* ((start (and entry (match-beginning (nth 1 entry))))
4236 (end (and entry (match-end (nth 1 entry))))
4237 (from (match-beginning 0)))
4238 (when (and (or (eq t (nth 2 entry))
4239 (eval (nth 2 entry)))
4240 (not (gnus-button-in-region-p
4241 start end 'gnus-callback)))
4242 ;; That optional form returned non-nil, so we add the
4244 (gnus-article-add-button
4245 start end 'gnus-button-push
4246 (car (push (set-marker (make-marker) from)
4247 gnus-button-marker-list))))))))))
4249 ;; Add buttons to the head of an article.
4250 (defun gnus-article-add-buttons-to-head ()
4251 "Add buttons to the head of the article."
4254 (set-buffer gnus-article-buffer)
4256 (let ((buffer-read-only nil)
4257 (inhibit-point-motion-hooks t)
4258 (case-fold-search t)
4259 (alist gnus-header-button-alist)
4261 (article-narrow-to-head)
4263 ;; Each alist entry.
4264 (setq entry (car alist)
4266 (goto-char (point-min))
4267 (while (re-search-forward (car entry) nil t)
4268 ;; Each header matching the entry.
4269 (setq beg (match-beginning 0))
4270 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4271 (match-beginning 0))
4274 (while (re-search-forward (nth 1 entry) end t)
4275 ;; Each match within a header.
4276 (let* ((entry (cdr entry))
4277 (start (match-beginning (nth 1 entry)))
4278 (end (match-end (nth 1 entry)))
4279 (form (nth 2 entry)))
4280 (goto-char (match-end 0))
4282 (gnus-article-add-button
4283 start end (nth 3 entry)
4284 (buffer-substring (match-beginning (nth 4 entry))
4285 (match-end (nth 4 entry)))))))
4286 (goto-char end)))))))
4288 ;;; External functions:
4290 (defun gnus-article-add-button (from to fun &optional data)
4291 "Create a button between FROM and TO with callback FUN and data DATA."
4292 (when gnus-article-button-face
4293 (gnus-overlay-put (gnus-make-overlay from to)
4294 'face gnus-article-button-face))
4295 (gnus-add-text-properties
4297 (nconc (and gnus-article-mouse-face
4298 (list gnus-mouse-face-prop gnus-article-mouse-face))
4299 (list 'gnus-callback fun)
4300 (and data (list 'gnus-data data))))
4301 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4302 :button-keymap gnus-widget-button-keymap))
4304 ;;; Internal functions:
4306 (defun gnus-article-set-globals ()
4308 (set-buffer gnus-summary-buffer)
4309 (gnus-set-global-variables)))
4311 (defun gnus-signature-toggle (end)
4313 (set-buffer gnus-article-buffer)
4314 (let ((buffer-read-only nil)
4315 (inhibit-point-motion-hooks t))
4316 (if (get-text-property end 'invisible)
4317 (gnus-article-unhide-text end (point-max))
4318 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4320 (defun gnus-button-entry ()
4321 ;; Return the first entry in `gnus-button-alist' matching this place.
4322 (let ((alist gnus-button-alist)
4325 (setq entry (pop alist))
4326 (if (looking-at (car entry))
4331 (defun gnus-button-push (marker)
4332 ;; Push button starting at MARKER.
4335 (let* ((entry (gnus-button-entry))
4336 (inhibit-point-motion-hooks t)
4338 (args (mapcar (lambda (group)
4339 (let ((string (match-string group)))
4340 (gnus-set-text-properties
4341 0 (length string) nil string)
4348 (fboundp (symbol-value fun)))
4349 (apply (symbol-value fun) args))
4351 (gnus-message 1 "You must define `%S' to use this button"
4352 (cons fun args)))))))
4354 (defun gnus-button-message-id (message-id)
4357 (set-buffer gnus-summary-buffer)
4358 (gnus-summary-refer-article message-id)))
4360 (defun gnus-button-fetch-group (address)
4361 "Fetch GROUP specified by ADDRESS."
4362 (if (not (string-match "[:/]" address))
4363 ;; This is just a simple group url.
4364 (gnus-group-read-ephemeral-group address gnus-select-method)
4365 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4367 (error "Can't parse %s" address)
4368 (gnus-group-read-ephemeral-group
4369 (match-string 4 address)
4370 `(nntp ,(match-string 1 address)
4371 (nntp-address ,(match-string 1 address))
4372 (nntp-port-number ,(if (match-end 3)
4373 (match-string 3 address)
4376 (defun gnus-url-parse-query-string (query &optional downcase)
4377 (let (retval pairs cur key val)
4378 (setq pairs (split-string query "&"))
4380 (setq cur (car pairs)
4382 (if (not (string-match "=" cur))
4384 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4385 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4387 (setq key (downcase key)))
4388 (setq cur (assoc key retval))
4390 (setcdr cur (cons val (cdr cur)))
4391 (setq retval (cons (list key val) retval)))))
4394 (defun gnus-url-unhex (x)
4401 (defun gnus-url-unhex-string (str &optional allow-newlines)
4402 "Remove %XXX embedded spaces, etc in a url.
4403 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4404 decoding of carriage returns and line feeds in the string, which is normally
4405 forbidden in URL encoding."
4406 (setq str (or str ""))
4408 (case-fold-search t))
4409 (while (string-match "%[0-9a-f][0-9a-f]" str)
4410 (let* ((start (match-beginning 0))
4411 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4413 (gnus-url-unhex (elt str (+ start 2))))))
4415 tmp (substring str 0 start)
4418 (char-to-string code))
4419 ((or (= code ?\n) (= code ?\r))
4421 (t (char-to-string code))))
4422 str (substring str (match-end 0)))))
4423 (setq tmp (concat tmp str))
4426 (defun gnus-url-mailto (url)
4427 ;; Send mail to someone
4428 (when (string-match "mailto:/*\\(.*\\)" url)
4429 (setq url (substring url (match-beginning 1) nil)))
4430 (let (to args subject func)
4431 (if (string-match (regexp-quote "?") url)
4432 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4433 args (gnus-url-parse-query-string
4434 (substring url (match-end 0) nil) t))
4435 (setq to (gnus-url-unhex-string url)))
4436 (setq args (cons (list "to" to) args)
4437 subject (cdr-safe (assoc "subject" args)))
4440 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4443 (message-position-on-field (caar args)))
4444 (insert (mapconcat 'identity (cdar args) ", "))
4445 (setq args (cdr args)))
4448 (message-goto-subject))))
4450 (defun gnus-button-mailto (address)
4452 (set-buffer (gnus-copy-article-buffer))
4453 (message-reply address))
4455 (defun gnus-button-reply (address)
4456 ;; Reply to ADDRESS.
4457 (message-reply address))
4459 (defun gnus-button-embedded-url (address)
4461 (browse-url (gnus-strip-whitespace address)))
4463 ;;; Next/prev buttons in the article buffer.
4465 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4466 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4468 (defvar gnus-prev-page-map nil)
4469 (unless gnus-prev-page-map
4470 (setq gnus-prev-page-map (make-sparse-keymap))
4471 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4472 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4474 (defun gnus-insert-prev-page-button ()
4475 (let ((buffer-read-only nil))
4477 gnus-prev-page-line-format nil
4478 `(gnus-prev t local-map ,gnus-prev-page-map
4479 gnus-callback gnus-article-button-prev-page
4480 article-type annotation))))
4482 (defvar gnus-next-page-map nil)
4483 (unless gnus-next-page-map
4484 (setq gnus-next-page-map (make-keymap))
4485 (suppress-keymap gnus-prev-page-map)
4486 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4487 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4489 (defun gnus-button-next-page ()
4490 "Go to the next page."
4492 (let ((win (selected-window)))
4493 (select-window (get-buffer-window gnus-article-buffer t))
4494 (gnus-article-next-page)
4495 (select-window win)))
4497 (defun gnus-button-prev-page ()
4498 "Go to the prev page."
4500 (let ((win (selected-window)))
4501 (select-window (get-buffer-window gnus-article-buffer t))
4502 (gnus-article-prev-page)
4503 (select-window win)))
4505 (defun gnus-insert-next-page-button ()
4506 (let ((buffer-read-only nil))
4507 (gnus-eval-format gnus-next-page-line-format nil
4509 t local-map ,gnus-next-page-map
4510 gnus-callback gnus-article-button-next-page
4511 article-type annotation))))
4513 (defun gnus-article-button-next-page (arg)
4514 "Go to the next page."
4516 (let ((win (selected-window)))
4517 (select-window (get-buffer-window gnus-article-buffer t))
4518 (gnus-article-next-page)
4519 (select-window win)))
4521 (defun gnus-article-button-prev-page (arg)
4522 "Go to the prev page."
4524 (let ((win (selected-window)))
4525 (select-window (get-buffer-window gnus-article-buffer t))
4526 (gnus-article-prev-page)
4527 (select-window win)))
4529 (defvar gnus-decode-header-methods
4530 '(mail-decode-encoded-word-region)
4531 "List of methods used to decode headers.
4533 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
4534 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4535 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4536 whose names match REGEXP.
4539 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4540 mail-decode-encoded-word-region
4541 (\"chinese\" . rfc1843-decode-region))
4544 (defvar gnus-decode-header-methods-cache nil)
4546 (defun gnus-multi-decode-header (start end)
4547 "Apply the functions from `gnus-encoded-word-methods' that match."
4548 (unless (and gnus-decode-header-methods-cache
4549 (eq gnus-newsgroup-name
4550 (car gnus-decode-header-methods-cache)))
4551 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4554 (nconc gnus-decode-header-methods-cache (list x))
4555 (if (and gnus-newsgroup-name
4556 (string-match (car x) gnus-newsgroup-name))
4557 (nconc gnus-decode-header-methods-cache
4559 gnus-decode-header-methods))
4560 (let ((xlist gnus-decode-header-methods-cache))
4563 (narrow-to-region start end)
4565 (funcall (pop xlist) (point-min) (point-max))))))
4568 ;;; Treatment top-level handling.
4571 (defun gnus-treat-article (condition &optional part-number total-parts type)
4572 (let ((length (- (point-max) (point-min)))
4573 (alist gnus-treatment-function-alist)
4574 (article-goto-body-goes-to-point-min-p t)
4578 (let ((list gnus-article-treat-types))
4580 (when (string-match (pop list) type)
4581 (throw 'found t)))))))
4582 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4584 (gnus-run-hooks 'gnus-part-display-hook)
4585 (while (setq elem (pop alist))
4588 (if (gnus-buffer-live-p gnus-summary-buffer)
4589 (set-buffer gnus-summary-buffer))
4590 (symbol-value (car elem))))
4591 (when (and (or (consp val)
4593 (gnus-treat-predicate val)
4594 (or (not (get (car elem) 'highlight))
4597 (funcall (cadr elem)))))))
4599 ;; Dynamic variables.
4600 (defvar part-number)
4601 (defvar total-parts)
4605 (defun gnus-treat-predicate (val)
4610 (stringp (car val)))
4611 (apply 'gnus-or (mapcar `(lambda (s)
4612 (string-match s ,(or gnus-newsgroup-name "")))
4615 (let ((pred (pop val)))
4618 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4620 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4622 (not (gnus-treat-predicate (car val))))
4624 (equal (car val) type))
4626 (error "%S is not a valid predicate" pred)))))
4634 (eq part-number total-parts))
4638 (error "%S is not a valid value" val))))
4644 (run-hooks 'gnus-art-load-hook)
4646 ;;; gnus-art.el ends here