1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996,97,98,99 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))
43 (defgroup gnus-article nil
45 :link '(custom-manual "(gnus)The Article Buffer")
48 (defgroup gnus-article-treat nil
49 "Treating article parts."
50 :link '(custom-manual "(gnus)Article Hiding")
53 (defgroup gnus-article-hiding nil
54 "Hiding article parts."
55 :link '(custom-manual "(gnus)Article Hiding")
58 (defgroup gnus-article-highlight nil
59 "Article highlighting."
60 :link '(custom-manual "(gnus)Article Highlighting")
64 (defgroup gnus-article-signature nil
66 :link '(custom-manual "(gnus)Article Signature")
69 (defgroup gnus-article-headers nil
71 :link '(custom-manual "(gnus)Hiding Headers")
74 (defgroup gnus-article-washing nil
75 "Special commands on articles."
76 :link '(custom-manual "(gnus)Article Washing")
79 (defgroup gnus-article-emphasis nil
80 "Fontisizing articles."
81 :link '(custom-manual "(gnus)Article Fontisizing")
84 (defgroup gnus-article-saving nil
86 :link '(custom-manual "(gnus)Saving Articles")
89 (defgroup gnus-article-mime nil
90 "Worshiping the MIME wonder."
91 :link '(custom-manual "(gnus)Using MIME")
94 (defgroup gnus-article-buttons nil
95 "Pushable buttons in the article buffer."
96 :link '(custom-manual "(gnus)Article Buttons")
99 (defgroup gnus-article-various nil
100 "Other article options."
101 :link '(custom-manual "(gnus)Misc Article")
102 :group 'gnus-article)
104 (defcustom gnus-ignored-headers
105 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
106 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
107 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
108 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
109 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
110 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
111 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
112 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
113 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
114 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
115 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
116 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
117 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
118 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
119 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
120 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
121 "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
122 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
123 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
124 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
125 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
126 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
127 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
128 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
129 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
130 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:")
131 "*All headers that start with this regexp will be hidden.
132 This variable can also be a list of regexps of headers to be ignored.
133 If `gnus-visible-headers' is non-nil, this variable will be ignored."
134 :type '(choice :custom-show nil
137 :group 'gnus-article-hiding)
139 (defcustom gnus-visible-headers
140 "^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:"
141 "*All headers that do not match this regexp will be hidden.
142 This variable can also be a list of regexp of headers to remain visible.
143 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
144 :type '(repeat :value-to-internal (lambda (widget value)
145 (custom-split-regexp-maybe value))
146 :match (lambda (widget value)
148 (widget-editable-list-match widget value)))
150 :group 'gnus-article-hiding)
152 (defcustom gnus-sorted-header-list
153 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
154 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
155 "*This variable is a list of regular expressions.
156 If it is non-nil, headers that match the regular expressions will
157 be placed first in the article buffer in the sequence specified by
159 :type '(repeat regexp)
160 :group 'gnus-article-hiding)
162 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
163 "Headers that are only to be displayed if they have interesting data.
164 Possible values in this list are `empty', `newsgroups', `followup-to',
165 `reply-to', `date', `long-to', and `many-to'."
166 :type '(set (const :tag "Headers with no content." empty)
167 (const :tag "Newsgroups with only one group." newsgroups)
168 (const :tag "Followup-to identical to newsgroups." followup-to)
169 (const :tag "Reply-to identical to from." reply-to)
170 (const :tag "Date less than four days old." date)
171 (const :tag "Very long To header." long-to)
172 (const :tag "Multiple To headers." many-to))
173 :group 'gnus-article-hiding)
175 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
176 "Regexp matching signature separator.
177 This can also be a list of regexps. In that case, it will be checked
178 from head to tail looking for a separator. Searches will be done from
179 the end of the buffer."
180 :type '(repeat string)
181 :group 'gnus-article-signature)
183 (defcustom gnus-signature-limit nil
184 "Provide a limit to what is considered a signature.
185 If it is a number, no signature may not be longer (in characters) than
186 that number. If it is a floating point number, no signature may be
187 longer (in lines) than that number. If it is a function, the function
188 will be called without any parameters, and if it returns nil, there is
189 no signature in the buffer. If it is a string, it will be used as a
190 regexp. If it matches, the text in question is not a signature."
191 :type '(choice (integer :value 200)
193 (function :value fun)
194 (regexp :value ".*"))
195 :group 'gnus-article-signature)
197 (defcustom gnus-hidden-properties '(invisible t intangible t)
198 "Property list to use for hiding text."
200 :group 'gnus-article-hiding)
202 (defcustom gnus-article-x-face-command
203 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
204 "*String or function to be executed to display an X-Face header.
205 If it is a string, the command will be executed in a sub-shell
206 asynchronously. The compressed face will be piped to this command."
207 :type 'string ;Leave function case to Lisp.
208 :group 'gnus-article-washing)
210 (defcustom gnus-article-x-face-too-ugly nil
211 "Regexp matching posters whose face shouldn't be shown automatically."
212 :type '(choice regexp (const nil))
213 :group 'gnus-article-washing)
215 (defcustom gnus-emphasis-alist
217 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
219 '(("_" "_" underline)
222 ("_/" "/_" underline-italic)
223 ("_\\*" "\\*_" underline-bold)
224 ("\\*/" "/\\*" bold-italic)
225 ("_\\*/" "/\\*_" underline-bold-italic))))
226 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
227 2 3 gnus-emphasis-underline)
231 (format format (car spec) (cadr spec))
232 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
234 "*Alist that says how to fontify certain phrases.
235 Each item looks like this:
237 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
239 The first element is a regular expression to be matched. The second
240 is a number that says what regular expression grouping used to find
241 the entire emphasized word. The third is a number that says what
242 regexp grouping should be displayed and highlighted. The fourth
243 is the face used for highlighting."
244 :type '(repeat (list :value ("" 0 0 default)
246 (integer :tag "Match group")
247 (integer :tag "Emphasize group")
249 :group 'gnus-article-emphasis)
251 (defface gnus-emphasis-bold '((t (:bold t)))
252 "Face used for displaying strong emphasized text (*word*)."
253 :group 'gnus-article-emphasis)
255 (defface gnus-emphasis-italic '((t (:italic t)))
256 "Face used for displaying italic emphasized text (/word/)."
257 :group 'gnus-article-emphasis)
259 (defface gnus-emphasis-underline '((t (:underline t)))
260 "Face used for displaying underlined emphasized text (_word_)."
261 :group 'gnus-article-emphasis)
263 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
264 "Face used for displaying underlined bold emphasized text (_*word*_)."
265 :group 'gnus-article-emphasis)
267 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
268 "Face used for displaying underlined italic emphasized text (_/word/_)."
269 :group 'gnus-article-emphasis)
271 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
272 "Face used for displaying bold italic emphasized text (/*word*/)."
273 :group 'gnus-article-emphasis)
275 (defface gnus-emphasis-underline-bold-italic
276 '((t (:bold t :italic t :underline t)))
277 "Face used for displaying underlined bold italic emphasized text.
278 Esample: (_/*word*/_)."
279 :group 'gnus-article-emphasis)
281 (defface gnus-emphasis-highlight-words
282 '((t (:background "black" :foreground "yellow")))
283 "Face used for displaying highlighted words."
284 :group 'gnus-article-emphasis)
286 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
287 "Format for display of Date headers in article bodies.
288 See `format-time-string' for the possible values.
290 The variable can also be function, which should return a complete Date
291 header. The function is called with one argument, the time, which can
292 be fed to `format-time-string'."
293 :type '(choice string symbol)
294 :link '(custom-manual "(gnus)Article Date")
295 :group 'gnus-article-washing)
298 (autoload 'mail-extract-address-components "mail-extr"))
300 (defcustom gnus-save-all-headers t
301 "*If non-nil, don't remove any headers before saving."
302 :group 'gnus-article-saving
305 (defcustom gnus-prompt-before-saving 'always
306 "*This variable says how much prompting is to be done when saving articles.
307 If it is nil, no prompting will be done, and the articles will be
308 saved to the default files. If this variable is `always', each and
309 every article that is saved will be preceded by a prompt, even when
310 saving large batches of articles. If this variable is neither nil not
311 `always', there the user will be prompted once for a file name for
312 each invocation of the saving commands."
313 :group 'gnus-article-saving
314 :type '(choice (item always)
315 (item :tag "never" nil)
316 (sexp :tag "once" :format "%t\n" :value t)))
318 (defcustom gnus-saved-headers gnus-visible-headers
319 "Headers to keep if `gnus-save-all-headers' is nil.
320 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
321 If that variable is nil, however, all headers that match this regexp
322 will be kept while the rest will be deleted before saving."
323 :group 'gnus-article-saving
326 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
327 "A function to save articles in your favourite format.
328 The function must be interactively callable (in other words, it must
329 be an Emacs command).
331 Gnus provides the following functions:
333 * gnus-summary-save-in-rmail (Rmail format)
334 * gnus-summary-save-in-mail (Unix mail format)
335 * gnus-summary-save-in-folder (MH folder)
336 * gnus-summary-save-in-file (article format)
337 * gnus-summary-save-in-vm (use VM's folder format)
338 * gnus-summary-write-to-file (article format -- overwrite)."
339 :group 'gnus-article-saving
340 :type '(radio (function-item gnus-summary-save-in-rmail)
341 (function-item gnus-summary-save-in-mail)
342 (function-item gnus-summary-save-in-folder)
343 (function-item gnus-summary-save-in-file)
344 (function-item gnus-summary-save-in-vm)
345 (function-item gnus-summary-write-to-file)))
347 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
348 "A function generating a file name to save articles in Rmail format.
349 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
350 :group 'gnus-article-saving
353 (defcustom gnus-mail-save-name 'gnus-plain-save-name
354 "A function generating a file name to save articles in Unix mail format.
355 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
356 :group 'gnus-article-saving
359 (defcustom gnus-folder-save-name 'gnus-folder-save-name
360 "A function generating a file name to save articles in MH folder.
361 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
362 :group 'gnus-article-saving
365 (defcustom gnus-file-save-name 'gnus-numeric-save-name
366 "A function generating a file name to save articles in article format.
367 The function is called with NEWSGROUP, HEADERS, and optional
369 :group 'gnus-article-saving
372 (defcustom gnus-split-methods
373 '((gnus-article-archive-name)
374 (gnus-article-nndoc-name))
375 "*Variable used to suggest where articles are to be saved.
376 For instance, if you would like to save articles related to Gnus in
377 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
378 you could set this variable to something like:
380 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
381 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
383 This variable is an alist where the where the key is the match and the
384 value is a list of possible files to save in if the match is non-nil.
386 If the match is a string, it is used as a regexp match on the
387 article. If the match is a symbol, that symbol will be funcalled
388 from the buffer of the article to be saved with the newsgroup as the
389 parameter. If it is a list, it will be evaled in the same buffer.
391 If this form or function returns a string, this string will be used as
392 a possible file name; and if it returns a non-nil list, that list will
393 be used as possible file names."
394 :group 'gnus-article-saving
395 :type '(repeat (choice (list :value (fun) function)
396 (cons :value ("" "") regexp (repeat string))
399 (defcustom gnus-page-delimiter "^\^L"
400 "*Regexp describing what to use as article page delimiters.
401 The default value is \"^\^L\", which is a form linefeed at the
402 beginning of a line."
404 :group 'gnus-article-various)
406 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
407 "*The format specification for the article mode line.
408 See `gnus-summary-mode-line-format' for a closer description.
410 The following additional specs are available:
412 %w The article washing status.
413 %m The number of MIME parts in the article."
415 :group 'gnus-article-various)
417 (defcustom gnus-article-mode-hook nil
418 "*A hook for Gnus article mode."
420 :group 'gnus-article-various)
422 (defcustom gnus-article-menu-hook nil
423 "*Hook run after the creation of the article mode menu."
425 :group 'gnus-article-various)
427 (defcustom gnus-article-prepare-hook nil
428 "*A hook called after an article has been prepared in the article buffer."
430 :group 'gnus-article-various)
432 (defcustom gnus-article-hide-pgp-hook nil
433 "*A hook called after successfully hiding a PGP signature."
435 :group 'gnus-article-various)
437 (defcustom gnus-article-button-face 'bold
438 "Face used for highlighting buttons in the article buffer.
440 An article button is a piece of text that you can activate by pressing
441 `RET' or `mouse-2' above it."
443 :group 'gnus-article-buttons)
445 (defcustom gnus-article-mouse-face 'highlight
446 "Face used for mouse highlighting in the article buffer.
448 Article buttons will be displayed in this face when the cursor is
451 :group 'gnus-article-buttons)
453 (defcustom gnus-signature-face 'gnus-signature-face
454 "Face used for highlighting a signature in the article buffer.
455 Obsolete; use the face `gnus-signature-face' for customizations instead."
457 :group 'gnus-article-highlight
458 :group 'gnus-article-signature)
460 (defface gnus-signature-face
463 "Face used for highlighting a signature in the article buffer."
464 :group 'gnus-article-highlight
465 :group 'gnus-article-signature)
467 (defface gnus-header-from-face
470 (:foreground "spring green"))
473 (:foreground "red3"))
476 "Face used for displaying from headers."
477 :group 'gnus-article-headers
478 :group 'gnus-article-highlight)
480 (defface gnus-header-subject-face
483 (:foreground "SeaGreen3"))
486 (:foreground "red4"))
488 (:bold t :italic t)))
489 "Face used for displaying subject headers."
490 :group 'gnus-article-headers
491 :group 'gnus-article-highlight)
493 (defface gnus-header-newsgroups-face
496 (:foreground "yellow" :italic t))
499 (:foreground "MidnightBlue" :italic t))
502 "Face used for displaying newsgroups headers."
503 :group 'gnus-article-headers
504 :group 'gnus-article-highlight)
506 (defface gnus-header-name-face
509 (:foreground "SeaGreen"))
512 (:foreground "maroon"))
515 "Face used for displaying header names."
516 :group 'gnus-article-headers
517 :group 'gnus-article-highlight)
519 (defface gnus-header-content-face
522 (:foreground "forest green" :italic t))
525 (:foreground "indianred4" :italic t))
527 (:italic t))) "Face used for displaying header content."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defcustom gnus-header-face-alist
532 '(("From" nil gnus-header-from-face)
533 ("Subject" nil gnus-header-subject-face)
534 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
535 ("" gnus-header-name-face gnus-header-content-face))
536 "*Controls highlighting of article header.
538 An alist of the form (HEADER NAME CONTENT).
540 HEADER is a regular expression which should match the name of an
541 header header and NAME and CONTENT are either face names or nil.
543 The name of each header field will be displayed using the face
544 specified by the first element in the list where HEADER match the
545 header name and NAME is non-nil. Similarly, the content will be
546 displayed by the first non-nil matching CONTENT face."
547 :group 'gnus-article-headers
548 :group 'gnus-article-highlight
549 :type '(repeat (list (regexp :tag "Header")
551 (item :tag "skip" nil)
552 (face :value default))
553 (choice :tag "Content"
554 (item :tag "skip" nil)
555 (face :value default)))))
557 (defcustom gnus-article-decode-hook
558 '(article-decode-charset article-decode-encoded-words)
559 "*Hook run to decode charsets in articles."
560 :group 'gnus-article-headers
563 (defcustom gnus-display-mime-function 'gnus-display-mime
564 "Function to display MIME articles."
565 :group 'gnus-article-mime
568 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
569 "Function used to decode headers.")
571 (defvar gnus-article-dumbquotes-map
589 "Table for MS-to-Latin1 translation.")
591 (defcustom gnus-ignored-mime-types nil
592 "List of MIME types that should be ignored by Gnus."
593 :group 'gnus-article-mime
594 :type '(repeat regexp))
596 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
597 "List of MIME types that should not be given buttons when rendered inline."
598 :group 'gnus-article-mime
599 :type '(repeat regexp))
601 (defcustom gnus-article-mime-part-function nil
602 "Function called with a MIME handle as the argument.
603 This is meant for people who want to do something automatic based
604 on parts -- for instance, adding Vcard info to a database."
605 :group 'gnus-article-mime
608 (defcustom gnus-mime-multipart-functions nil
609 "An alist of MIME types to functions to display them.")
611 (defcustom gnus-article-date-lapsed-new-header nil
612 "Whether the X-Sent and Date headers can coexist.
613 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
614 either replace the old \"Date:\" header (if this variable is nil), or
615 be added below it (otherwise)."
616 :group 'gnus-article-headers
619 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
620 "Function called with a MIME handle as the argument.
621 This is meant for people who want to view first matched part.
622 For `undisplayed-alternative' (default), the first undisplayed
623 part or alternative part is used. For `undisplayed', the first
624 undisplayed part is used. For a function, the first part which
625 the function return `t' is used. For `nil', the first part is
627 :group 'gnus-article-mime
629 (item :tag "first" :value nil)
630 (item :tag "undisplayed" :value undisplayed)
631 (item :tag "undisplayed or alternative"
632 :value undisplayed-alternative)
636 ;;; The treatment variables
639 (defvar gnus-part-display-hook nil
640 "Hook called on parts that are to receive treatment.")
642 (defvar gnus-article-treat-custom
643 '(choice (const :tag "Off" nil)
645 (const :tag "Header" head)
646 (const :tag "Last" last)
647 (integer :tag "Less")
648 (repeat :tag "Groups" regexp)
649 (sexp :tag "Predicate")))
651 (defvar gnus-article-treat-head-custom
652 '(choice (const :tag "Off" nil)
653 (const :tag "Header" head)))
655 (defvar gnus-article-treat-types '("text/plain")
658 (defvar gnus-inhibit-treatment nil
659 "Whether to inhibit treatment.")
661 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
662 "Highlight the signature.
663 Valid values are nil, t, `head', `last', an integer or a predicate.
664 See the manual for details."
665 :group 'gnus-article-treat
666 :type gnus-article-treat-custom)
667 (put 'gnus-treat-highlight-signature 'highlight t)
669 (defcustom gnus-treat-buttonize 100000
671 Valid values are nil, t, `head', `last', an integer or a predicate.
672 See the manual for details."
673 :group 'gnus-article-treat
674 :type gnus-article-treat-custom)
675 (put 'gnus-treat-buttonize 'highlight t)
677 (defcustom gnus-treat-buttonize-head 'head
678 "Add buttons to the head.
679 Valid values are nil, t, `head', `last', an integer or a predicate.
680 See the manual for details."
681 :group 'gnus-article-treat
682 :type gnus-article-treat-head-custom)
683 (put 'gnus-treat-buttonize-head 'highlight t)
685 (defcustom gnus-treat-emphasize 50000
687 Valid values are nil, t, `head', `last', an integer or a predicate.
688 See the manual for details."
689 :group 'gnus-article-treat
690 :type gnus-article-treat-custom)
691 (put 'gnus-treat-emphasize 'highlight t)
693 (defcustom gnus-treat-strip-cr nil
694 "Remove carriage returns.
695 Valid values are nil, t, `head', `last', an integer or a predicate.
696 See the manual for details."
697 :group 'gnus-article-treat
698 :type gnus-article-treat-custom)
700 (defcustom gnus-treat-hide-headers 'head
702 Valid values are nil, t, `head', `last', an integer or a predicate.
703 See the manual for details."
704 :group 'gnus-article-treat
705 :type gnus-article-treat-head-custom)
707 (defcustom gnus-treat-hide-boring-headers nil
708 "Hide boring headers.
709 Valid values are nil, t, `head', `last', an integer or a predicate.
710 See the manual for details."
711 :group 'gnus-article-treat
712 :type gnus-article-treat-head-custom)
714 (defcustom gnus-treat-hide-signature nil
716 Valid values are nil, t, `head', `last', an integer or a predicate.
717 See the manual for details."
718 :group 'gnus-article-treat
719 :type gnus-article-treat-custom)
721 (defcustom gnus-treat-fill-article nil
723 Valid values are nil, t, `head', `last', an integer or a predicate.
724 See the manual for details."
725 :group 'gnus-article-treat
726 :type gnus-article-treat-custom)
728 (defcustom gnus-treat-hide-citation nil
730 Valid values are nil, t, `head', `last', an integer or a predicate.
731 See the manual for details."
732 :group 'gnus-article-treat
733 :type gnus-article-treat-custom)
735 (defcustom gnus-treat-strip-list-identifiers 'head
736 "Strip list identifiers from `gnus-list-identifiers`.
737 Valid values are nil, t, `head', `last', an integer or a predicate.
738 See the manual for details."
739 :group 'gnus-article-treat
740 :type gnus-article-treat-custom)
742 (defcustom gnus-treat-strip-pgp t
743 "Strip PGP signatures.
744 Valid values are nil, t, `head', `last', an integer or a predicate.
745 See the manual for details."
746 :group 'gnus-article-treat
747 :type gnus-article-treat-custom)
749 (defcustom gnus-treat-strip-pem nil
750 "Strip PEM signatures.
751 Valid values are nil, t, `head', `last', an integer or a predicate.
752 See the manual for details."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-custom)
756 (defcustom gnus-treat-strip-banner t
757 "Strip banners from articles.
758 The banner to be stripped is specified in the `banner' group parameter.
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-custom)
764 (defcustom gnus-treat-highlight-headers 'head
765 "Highlight the headers.
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-head-custom)
770 (put 'gnus-treat-highlight-headers 'highlight t)
772 (defcustom gnus-treat-highlight-citation t
773 "Highlight cited text.
774 Valid values are nil, t, `head', `last', an integer or a predicate.
775 See the manual for details."
776 :group 'gnus-article-treat
777 :type gnus-article-treat-custom)
778 (put 'gnus-treat-highlight-citation 'highlight t)
780 (defcustom gnus-treat-date-ut nil
781 "Display the Date in UT (GMT).
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-head-custom)
787 (defcustom gnus-treat-date-local nil
788 "Display the Date in the local timezone.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-head-custom)
794 (defcustom gnus-treat-date-lapsed nil
795 "Display the Date header in a way that says how much time has elapsed.
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-head-custom)
801 (defcustom gnus-treat-date-original nil
802 "Display the date in the original timezone.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-head-custom)
808 (defcustom gnus-treat-date-iso8601 nil
809 "Display the date in the ISO8601 format.
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-head-custom)
815 (defcustom gnus-treat-date-user-defined nil
816 "Display the date in a user-defined format.
817 The format is defined by the `gnus-article-time-format' variable.
818 Valid values are nil, t, `head', `last', an integer or a predicate.
819 See the manual for details."
820 :group 'gnus-article-treat
821 :type gnus-article-treat-head-custom)
823 (defcustom gnus-treat-strip-headers-in-body t
824 "Strip the X-No-Archive header line from the beginning of the body.
825 Valid values are nil, t, `head', `last', an integer or a predicate.
826 See the manual for details."
827 :group 'gnus-article-treat
828 :type gnus-article-treat-custom)
830 (defcustom gnus-treat-strip-trailing-blank-lines nil
831 "Strip trailing blank lines.
832 Valid values are nil, t, `head', `last', an integer or a predicate.
833 See the manual for details."
834 :group 'gnus-article-treat
835 :type gnus-article-treat-custom)
837 (defcustom gnus-treat-strip-leading-blank-lines nil
838 "Strip leading blank lines.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-custom)
844 (defcustom gnus-treat-strip-multiple-blank-lines nil
845 "Strip multiple blank lines.
846 Valid values are nil, t, `head', `last', an integer or a predicate.
847 See the manual for details."
848 :group 'gnus-article-treat
849 :type gnus-article-treat-custom)
851 (defcustom gnus-treat-overstrike t
852 "Treat overstrike highlighting.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-custom)
857 (put 'gnus-treat-overstrike 'highlight t)
859 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
861 "Display X-Face headers.
862 Valid values are nil, t, `head', `last', an integer or a predicate.
863 See the manual for details."
864 :group 'gnus-article-treat
865 :type gnus-article-treat-head-custom)
866 (put 'gnus-treat-display-xface 'highlight t)
868 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
872 Valid values are nil, t, `head', `last', an integer or a predicate.
873 See the manual for details."
874 :group 'gnus-article-treat
875 :type gnus-article-treat-custom)
876 (put 'gnus-treat-display-smileys 'highlight t)
878 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882 :group 'gnus-article-treat
883 :type gnus-article-treat-head-custom)
884 (put 'gnus-treat-display-picons 'highlight t)
886 (defcustom gnus-treat-capitalize-sentences nil
887 "Capitalize sentence-starting words.
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-custom)
893 (defcustom gnus-treat-fill-long-lines nil
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-custom)
900 (defcustom gnus-treat-play-sounds nil
902 Valid values are nil, t, `head', `last', an integer or a predicate.
903 See the manual for details."
904 :group 'gnus-article-treat
905 :type gnus-article-treat-custom)
907 (defcustom gnus-treat-translate nil
908 "Translate articles from one language to another.
909 Valid values are nil, t, `head', `last', an integer or a predicate.
910 See the manual for details."
911 :group 'gnus-article-treat
912 :type gnus-article-treat-custom)
914 ;;; Internal variables
916 (defvar article-goto-body-goes-to-point-min-p nil)
917 (defvar gnus-article-wash-types nil)
918 (defvar gnus-article-emphasis-alist nil)
920 (defvar gnus-article-mime-handle-alist-1 nil)
921 (defvar gnus-treatment-function-alist
922 '((gnus-treat-strip-banner gnus-article-strip-banner)
923 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
924 (gnus-treat-highlight-signature gnus-article-highlight-signature)
925 (gnus-treat-buttonize gnus-article-add-buttons)
926 (gnus-treat-fill-article gnus-article-fill-cited-article)
927 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
928 (gnus-treat-strip-cr gnus-article-remove-cr)
929 (gnus-treat-emphasize gnus-article-emphasize)
930 (gnus-treat-display-xface gnus-article-display-x-face)
931 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
932 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
933 (gnus-treat-hide-signature gnus-article-hide-signature)
934 (gnus-treat-hide-citation gnus-article-hide-citation)
935 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
936 (gnus-treat-strip-pgp gnus-article-hide-pgp)
937 (gnus-treat-strip-pem gnus-article-hide-pem)
938 (gnus-treat-highlight-headers gnus-article-highlight-headers)
939 (gnus-treat-highlight-citation gnus-article-highlight-citation)
940 (gnus-treat-highlight-signature gnus-article-highlight-signature)
941 (gnus-treat-date-ut gnus-article-date-ut)
942 (gnus-treat-date-local gnus-article-date-local)
943 (gnus-treat-date-lapsed gnus-article-date-lapsed)
944 (gnus-treat-date-original gnus-article-date-original)
945 (gnus-treat-date-user-defined gnus-article-date-user)
946 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
947 (gnus-treat-strip-trailing-blank-lines
948 gnus-article-remove-trailing-blank-lines)
949 (gnus-treat-strip-leading-blank-lines
950 gnus-article-strip-leading-blank-lines)
951 (gnus-treat-strip-multiple-blank-lines
952 gnus-article-strip-multiple-blank-lines)
953 (gnus-treat-overstrike gnus-article-treat-overstrike)
954 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
955 (gnus-treat-display-smileys gnus-smiley-display)
956 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
957 (gnus-treat-display-picons gnus-article-display-picons)
958 (gnus-treat-play-sounds gnus-earcon-display)))
960 (defvar gnus-article-mime-handle-alist nil)
961 (defvar article-lapsed-timer nil)
962 (defvar gnus-article-current-summary nil)
964 (defvar gnus-article-mode-syntax-table
965 (let ((table (copy-syntax-table text-mode-syntax-table)))
966 (modify-syntax-entry ?- "w" table)
967 (modify-syntax-entry ?> ")" table)
968 (modify-syntax-entry ?< "(" table)
970 "Syntax table used in article mode buffers.
971 Initialized from `text-mode-syntax-table.")
973 (defvar gnus-save-article-buffer nil)
975 (defvar gnus-article-mode-line-format-alist
976 (nconc '((?w (gnus-article-wash-status) ?s)
977 (?m (gnus-article-mime-part-status) ?s))
978 gnus-summary-mode-line-format-alist))
980 (defvar gnus-number-of-articles-to-be-saved nil)
982 (defvar gnus-inhibit-hiding nil)
984 (defsubst gnus-article-hide-text (b e props)
985 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
986 (add-text-properties b e props)
987 (when (memq 'intangible props)
989 (max (1- b) (point-min))
990 b 'intangible (cddr (memq 'intangible props)))))
991 (defsubst gnus-article-unhide-text (b e)
992 "Remove hidden text properties from region between B and E."
993 (remove-text-properties b e gnus-hidden-properties)
994 (when (memq 'intangible gnus-hidden-properties)
995 (put-text-property (max (1- b) (point-min))
998 (defun gnus-article-hide-text-type (b e type)
999 "Hide text of TYPE between B and E."
1000 (push type gnus-article-wash-types)
1001 (gnus-article-hide-text
1002 b e (cons 'article-type (cons type gnus-hidden-properties))))
1004 (defun gnus-article-unhide-text-type (b e type)
1005 "Unhide text of TYPE between B and E."
1006 (setq gnus-article-wash-types
1007 (delq type gnus-article-wash-types))
1008 (remove-text-properties
1009 b e (cons 'article-type (cons type gnus-hidden-properties)))
1010 (when (memq 'intangible gnus-hidden-properties)
1011 (put-text-property (max (1- b) (point-min))
1012 b 'intangible nil)))
1014 (defun gnus-article-hide-text-of-type (type)
1015 "Hide text of TYPE in the current buffer."
1017 (let ((b (point-min))
1019 (while (setq b (text-property-any b e 'article-type type))
1020 (add-text-properties b (incf b) gnus-hidden-properties)))))
1022 (defun gnus-article-delete-text-of-type (type)
1023 "Delete text of TYPE in the current buffer."
1025 (let ((b (point-min)))
1026 (while (setq b (text-property-any b (point-max) 'article-type type))
1028 b (or (text-property-not-all b (point-max) 'article-type type)
1031 (defun gnus-article-delete-invisible-text ()
1032 "Delete all invisible text in the current buffer."
1034 (let ((b (point-min)))
1035 (while (setq b (text-property-any b (point-max) 'invisible t))
1037 b (or (text-property-not-all b (point-max) 'invisible t)
1040 (defun gnus-article-text-type-exists-p (type)
1041 "Say whether any text of type TYPE exists in the buffer."
1042 (text-property-any (point-min) (point-max) 'article-type type))
1044 (defsubst gnus-article-header-rank ()
1045 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1046 (let ((list gnus-sorted-header-list)
1049 (when (looking-at (car list))
1051 (setq list (cdr list))
1055 (defun article-hide-headers (&optional arg delete)
1056 "Hide unwanted headers and possibly sort them as well."
1058 ;; This function might be inhibited.
1059 (unless gnus-inhibit-hiding
1062 (let ((buffer-read-only nil)
1063 (case-fold-search t)
1064 (max (1+ (length gnus-sorted-header-list)))
1065 (ignored (when (not gnus-visible-headers)
1066 (cond ((stringp gnus-ignored-headers)
1067 gnus-ignored-headers)
1068 ((listp gnus-ignored-headers)
1069 (mapconcat 'identity gnus-ignored-headers
1072 (cond ((stringp gnus-visible-headers)
1073 gnus-visible-headers)
1074 ((and gnus-visible-headers
1075 (listp gnus-visible-headers))
1076 (mapconcat 'identity gnus-visible-headers "\\|"))))
1077 (inhibit-point-motion-hooks t)
1079 ;; First we narrow to just the headers.
1080 (article-narrow-to-head)
1081 ;; Hide any "From " lines at the beginning of (mail) articles.
1082 (while (looking-at "From ")
1085 (delete-region (point-min) (point)))
1086 ;; Then treat the rest of the header lines.
1087 ;; Then we use the two regular expressions
1088 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1089 ;; select which header lines is to remain visible in the
1091 (while (re-search-forward "^[^ \t]*:" nil t)
1093 ;; Mark the rank of the header.
1095 (point) (1+ (point)) 'message-rank
1096 (if (or (and visible (looking-at visible))
1098 (not (looking-at ignored))))
1099 (gnus-article-header-rank)
1102 (message-sort-headers-1)
1103 (when (setq beg (text-property-any
1104 (point-min) (point-max) 'message-rank (+ 2 max)))
1105 ;; We delete the unwanted headers.
1106 (push 'headers gnus-article-wash-types)
1107 (add-text-properties (point-min) (+ 5 (point-min))
1108 '(article-type headers dummy-invisible t))
1109 (delete-region beg (point-max))))))))
1111 (defun article-hide-boring-headers (&optional arg)
1112 "Toggle hiding of headers that aren't very interesting.
1113 If given a negative prefix, always show; if given a positive prefix,
1115 (interactive (gnus-article-hidden-arg))
1116 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1117 (not gnus-show-all-headers))
1120 (let ((buffer-read-only nil)
1121 (list gnus-boring-article-headers)
1122 (inhibit-point-motion-hooks t)
1124 (article-narrow-to-head)
1126 (setq elem (pop list))
1127 (goto-char (point-min))
1129 ;; Hide empty headers.
1131 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1133 (gnus-article-hide-text-type
1134 (progn (beginning-of-line) (point))
1137 (if (re-search-forward "^[^ \t]" nil t)
1141 ;; Hide boring Newsgroups header.
1142 ((eq elem 'newsgroups)
1143 (when (equal (gnus-fetch-field "newsgroups")
1144 (gnus-group-real-name
1145 (if (boundp 'gnus-newsgroup-name)
1148 (gnus-article-hide-header "newsgroups")))
1149 ((eq elem 'followup-to)
1150 (when (equal (message-fetch-field "followup-to")
1151 (message-fetch-field "newsgroups"))
1152 (gnus-article-hide-header "followup-to")))
1153 ((eq elem 'reply-to)
1154 (let ((from (message-fetch-field "from"))
1155 (reply-to (message-fetch-field "reply-to")))
1160 (nth 1 (mail-extract-address-components from))
1161 (nth 1 (mail-extract-address-components reply-to)))))
1162 (gnus-article-hide-header "reply-to"))))
1164 (let ((date (message-fetch-field "date")))
1166 (< (days-between (current-time-string) date)
1168 (gnus-article-hide-header "date"))))
1170 (let ((to (message-fetch-field "to")))
1171 (when (> (length to) 1024)
1172 (gnus-article-hide-header "to"))))
1175 (goto-char (point-min))
1176 (while (re-search-forward "^to:" nil t)
1177 (setq to-count (1+ to-count)))
1178 (when (> to-count 1)
1179 (while (> to-count 0)
1180 (goto-char (point-min))
1182 (re-search-forward "^to:" nil nil to-count)
1184 (narrow-to-region (point) (point-max))
1185 (gnus-article-hide-header "to"))
1186 (setq to-count (1- to-count)))))))))))))
1188 (defun gnus-article-hide-header (header)
1190 (goto-char (point-min))
1191 (when (re-search-forward (concat "^" header ":") nil t)
1192 (gnus-article-hide-text-type
1193 (progn (beginning-of-line) (point))
1196 (if (re-search-forward "^[^ \t]" nil t)
1201 (defvar gnus-article-normalized-header-length 40
1202 "Length of normalized headers.")
1204 (defun article-normalize-headers ()
1205 "Make all header lines 40 characters long."
1207 (let ((buffer-read-only nil)
1211 (article-narrow-to-head)
1214 ((< (setq column (- (gnus-point-at-eol) (point)))
1215 gnus-article-normalized-header-length)
1217 (insert (make-string
1218 (- gnus-article-normalized-header-length column)
1220 ((> column gnus-article-normalized-header-length)
1221 (gnus-put-text-property
1223 (forward-char gnus-article-normalized-header-length)
1230 (forward-line 1))))))
1232 (defun article-treat-dumbquotes ()
1233 "Translate M******** sm*rtq**t*s into proper text.
1234 Note that this function guesses whether a character is a sm*rtq**t* or
1235 not, so it should only be used interactively."
1237 (article-translate-strings gnus-article-dumbquotes-map))
1239 (defun article-translate-characters (from to)
1240 "Translate all characters in the body of the article according to FROM and TO.
1241 FROM is a string of characters to translate from; to is a string of
1242 characters to translate to."
1244 (when (article-goto-body)
1245 (let ((buffer-read-only nil)
1246 (x (make-string 225 ?x))
1248 (while (< (incf i) (length x))
1251 (while (< i (length from))
1252 (aset x (aref from i) (aref to i))
1254 (translate-region (point) (point-max) x)))))
1256 (defun article-translate-strings (map)
1257 "Translate all string in the body of the article according to MAP.
1258 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1260 (when (article-goto-body)
1261 (let ((buffer-read-only nil)
1263 (while (setq elem (pop map))
1265 (while (search-forward (car elem) nil t)
1266 (replace-match (cadr elem)))))))))
1268 (defun article-treat-overstrike ()
1269 "Translate overstrikes into bold text."
1272 (when (article-goto-body)
1273 (let ((buffer-read-only nil))
1274 (while (search-forward "\b" nil t)
1275 (let ((next (char-after))
1276 (previous (char-after (- (point) 2))))
1277 ;; We do the boldification/underlining by hiding the
1278 ;; overstrikes and putting the proper text property
1282 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1283 (put-text-property (point) (1+ (point)) 'face 'bold))
1285 (gnus-article-hide-text-type
1286 (1- (point)) (1+ (point)) 'overstrike)
1288 (- (point) 2) (1- (point)) 'face 'underline))
1290 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1292 (point) (1+ (point)) 'face 'underline)))))))))
1294 (defun article-fill-long-lines ()
1295 "Fill lines that are wider than the window width."
1298 (let ((buffer-read-only nil)
1299 (width (window-width (get-buffer-window (current-buffer)))))
1302 (let ((adaptive-fill-mode nil))
1305 (when (>= (current-column) (min fill-column width))
1306 (narrow-to-region (point) (gnus-point-at-bol))
1307 (fill-paragraph nil)
1308 (goto-char (point-max))
1310 (forward-line 1)))))))
1312 (defun article-capitalize-sentences ()
1313 "Capitalize the first word in each sentence."
1316 (let ((buffer-read-only nil)
1317 (paragraph-start "^[\n\^L]"))
1321 (forward-sentence)))))
1323 (defun article-remove-cr ()
1324 "Remove trailing CRs and then translate remaining CRs into LFs."
1327 (let ((buffer-read-only nil))
1328 (goto-char (point-min))
1329 (while (re-search-forward "\r+$" nil t)
1330 (replace-match "" t t))
1331 (goto-char (point-min))
1332 (while (search-forward "\r" nil t)
1333 (replace-match "\n" t t)))))
1335 (defun article-remove-trailing-blank-lines ()
1336 "Remove all trailing blank lines from the article."
1339 (let ((buffer-read-only nil))
1340 (goto-char (point-max))
1344 (while (and (not (bobp))
1345 (looking-at "^[ \t]*$")
1346 (not (gnus-annotation-in-region-p
1347 (point) (gnus-point-at-eol))))
1352 (defun article-display-x-face (&optional force)
1353 "Look for an X-Face header and display it if present."
1354 (interactive (list 'force))
1356 ;; Delete the old process, if any.
1357 (when (process-status "article-x-face")
1358 (delete-process "article-x-face"))
1359 (let ((inhibit-point-motion-hooks t)
1360 (case-fold-search t)
1363 (article-narrow-to-head)
1364 (goto-char (point-min))
1365 (setq from (message-fetch-field "from"))
1366 (goto-char (point-min))
1367 (while (and gnus-article-x-face-command
1370 ;; Check whether this face is censored.
1371 (not gnus-article-x-face-too-ugly)
1372 (and gnus-article-x-face-too-ugly from
1373 (not (string-match gnus-article-x-face-too-ugly
1375 ;; Has to be present.
1376 (re-search-forward "^X-Face: " nil t))
1377 ;; This used to try to do multiple faces (`while' instead of
1378 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1379 ;; work (b) it can crash some versions of Emacs (c) are
1380 ;; multiple faces really something to encourage?
1381 (when (stringp gnus-article-x-face-command)
1383 ;; We now have the area of the buffer where the X-Face is stored.
1386 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1387 ;; We display the face.
1388 (if (symbolp gnus-article-x-face-command)
1389 ;; The command is a lisp function, so we call it.
1390 (if (gnus-functionp gnus-article-x-face-command)
1391 (funcall gnus-article-x-face-command beg end)
1392 (error "%s is not a function" gnus-article-x-face-command))
1393 ;; The command is a string, so we interpret the command
1394 ;; as a, well, command, and fork it off.
1395 (let ((process-connection-type nil))
1396 (process-kill-without-query
1398 "article-x-face" nil shell-file-name shell-command-switch
1399 gnus-article-x-face-command))
1400 (process-send-region "article-x-face" beg end)
1401 (process-send-eof "article-x-face"))))))))))
1403 (defun article-decode-mime-words ()
1404 "Decode all MIME-encoded words in the article."
1407 (set-buffer gnus-article-buffer)
1408 (let ((inhibit-point-motion-hooks t)
1410 (mail-parse-charset gnus-newsgroup-charset)
1411 (mail-parse-ignored-charsets
1412 (save-excursion (set-buffer gnus-summary-buffer)
1413 gnus-newsgroup-ignored-charsets)))
1414 (mail-decode-encoded-word-region (point-min) (point-max)))))
1416 (defun article-decode-charset (&optional prompt)
1417 "Decode charset-encoded text in the article.
1418 If PROMPT (the prefix), prompt for a coding system to use."
1422 (article-narrow-to-head)
1423 (let* ((inhibit-point-motion-hooks t)
1424 (case-fold-search t)
1425 (ct (message-fetch-field "Content-Type" t))
1426 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1427 (ctl (and ct (ignore-errors
1428 (mail-header-parse-content-type ct))))
1431 (mm-read-coding-system "Charset to decode: "))
1433 (mail-content-type-get ctl 'charset))))
1434 (mail-parse-charset gnus-newsgroup-charset)
1435 (mail-parse-ignored-charsets
1436 (save-excursion (condition-case nil
1437 (set-buffer gnus-summary-buffer)
1439 gnus-newsgroup-ignored-charsets))
1441 (if (and ctl (not (string-match "/" (car ctl))))
1443 (goto-char (point-max))
1446 (narrow-to-region (point) (point-max))
1447 (when (and (or (not ctl)
1448 (equal (car ctl) "text/plain")))
1450 charset (and cte (intern (downcase
1451 (gnus-strip-whitespace cte))))
1454 (defun article-decode-encoded-words ()
1455 "Remove encoded-word encoding from headers."
1456 (let ((inhibit-point-motion-hooks t)
1457 (mail-parse-charset gnus-newsgroup-charset)
1458 (mail-parse-ignored-charsets
1459 (save-excursion (condition-case nil
1460 (set-buffer gnus-summary-buffer)
1462 gnus-newsgroup-ignored-charsets))
1465 (article-narrow-to-head)
1466 (funcall gnus-decode-header-function (point-min) (point-max)))))
1468 (defun article-de-quoted-unreadable (&optional force)
1469 "Translate a quoted-printable-encoded article.
1470 If FORCE, decode the article whether it is marked as quoted-printable
1472 (interactive (list 'force))
1474 (let ((buffer-read-only nil)
1475 (type (gnus-fetch-field "content-transfer-encoding"))
1476 (charset gnus-newsgroup-charset))
1478 (and type (string-match "quoted-printable" (downcase type))))
1481 (narrow-to-region (point) (point-max))
1482 (quoted-printable-decode-region (point-min) (point-max))
1484 (mm-decode-body charset)))))))
1486 (defun article-hide-list-identifiers ()
1487 "Remove any list identifiers in `gnus-list-identifiers' from Subject
1488 header in the current article."
1492 (let ((inhibit-point-motion-hooks t)
1494 (article-narrow-to-head)
1495 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1496 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1498 (goto-char (point-min))
1499 (when (re-search-forward
1500 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1502 (delete-region (match-beginning 2) (match-end 0)))))))))
1504 (defun article-hide-pgp ()
1505 "Remove any PGP headers and signatures in the current article."
1509 (let ((inhibit-point-motion-hooks t)
1510 buffer-read-only beg end)
1512 ;; Hide the "header".
1513 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1514 (push 'pgp gnus-article-wash-types)
1515 (delete-region (match-beginning 0) (match-end 0))
1516 ;; Remove armor headers (rfc2440 6.2)
1517 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1520 ;; Hide the actual signature.
1521 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1522 (setq end (1+ (match-beginning 0)))
1525 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1527 ;; Perhaps we shouldn't hide to the end of the buffer
1528 ;; if there is no end to the signature?
1530 ;; Hide "- " PGP quotation markers.
1532 (narrow-to-region beg end)
1533 (goto-char (point-min))
1534 (while (re-search-forward "^- " nil t)
1536 (match-beginning 0) (match-end 0)))
1538 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1540 (defun article-hide-pem (&optional arg)
1541 "Toggle hiding of any PEM headers and signatures in the current article.
1542 If given a negative prefix, always show; if given a positive prefix,
1544 (interactive (gnus-article-hidden-arg))
1545 (unless (gnus-article-check-hidden-text 'pem arg)
1547 (let (buffer-read-only end)
1548 (goto-char (point-min))
1549 ;; Hide the horrendously ugly "header".
1550 (when (and (search-forward
1551 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1553 (setq end (1+ (match-beginning 0))))
1554 (push 'pem gnus-article-wash-types)
1555 (gnus-article-hide-text-type
1557 (if (search-forward "\n\n" nil t)
1561 ;; Hide the trailer as well
1562 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1564 (gnus-article-hide-text-type
1565 (match-beginning 0) (match-end 0) 'pem)))))))
1567 (defun article-strip-banner ()
1568 "Strip the banner specified by the `banner' group parameter."
1572 (let ((inhibit-point-motion-hooks t)
1573 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1574 (gnus-signature-limit nil)
1575 buffer-read-only beg end)
1579 ((eq banner 'signature)
1580 (when (gnus-article-narrow-to-signature)
1583 (delete-region (point) (point-max))))
1585 (while (re-search-forward banner nil t)
1586 (delete-region (match-beginning 0) (match-end 0))))))))))
1588 (defun article-babel ()
1589 "Translate article using an online translation service."
1593 (set-buffer gnus-article-buffer)
1594 (when (article-goto-body)
1595 (let* ((buffer-read-only nil)
1598 (orig (buffer-substring start end))
1599 (trans (babel-as-string orig)))
1601 (narrow-to-region start end)
1602 (delete-region start end)
1605 (defun article-hide-signature (&optional arg)
1606 "Hide the signature in the current article.
1607 If given a negative prefix, always show; if given a positive prefix,
1609 (interactive (gnus-article-hidden-arg))
1610 (unless (gnus-article-check-hidden-text 'signature arg)
1613 (let ((buffer-read-only nil))
1614 (when (gnus-article-narrow-to-signature)
1615 (gnus-article-hide-text-type
1616 (point-min) (point-max) 'signature)))))))
1618 (defun article-strip-headers-in-body ()
1619 "Strip offensive headers from bodies."
1623 (let ((case-fold-search t))
1624 (when (looking-at "x-no-archive:")
1625 (gnus-delete-line)))))
1627 (defun article-strip-leading-blank-lines ()
1628 "Remove all blank lines from the beginning of the article."
1631 (let ((inhibit-point-motion-hooks t)
1633 (when (article-goto-body)
1634 (while (and (not (eobp))
1635 (looking-at "[ \t]*$"))
1636 (gnus-delete-line))))))
1638 (defun article-narrow-to-head ()
1639 "Narrow the buffer to the head of the message.
1640 Point is left at the beginning of the narrowed-to region."
1642 (goto-char (point-min))
1643 (if (search-forward "\n\n" nil 1)
1646 (goto-char (point-min)))
1648 (defun article-goto-body ()
1649 "Place point at the start of the body."
1650 (goto-char (point-min))
1652 ;; This variable is only bound when dealing with separate
1654 (article-goto-body-goes-to-point-min-p
1656 ((search-forward "\n\n" nil t)
1659 (goto-char (point-max))
1662 (defun article-strip-multiple-blank-lines ()
1663 "Replace consecutive blank lines with one empty line."
1666 (let ((inhibit-point-motion-hooks t)
1668 ;; First make all blank lines empty.
1670 (while (re-search-forward "^[ \t]+$" nil t)
1671 (unless (gnus-annotation-in-region-p
1672 (match-beginning 0) (match-end 0))
1673 (replace-match "" nil t)))
1674 ;; Then replace multiple empty lines with a single empty line.
1676 (while (re-search-forward "\n\n\n+" nil t)
1677 (unless (gnus-annotation-in-region-p
1678 (match-beginning 0) (match-end 0))
1679 (replace-match "\n\n" t t))))))
1681 (defun article-strip-leading-space ()
1682 "Remove all white space from the beginning of the lines in the article."
1685 (let ((inhibit-point-motion-hooks t)
1688 (while (re-search-forward "^[ \t]+" nil t)
1689 (replace-match "" t t)))))
1691 (defun article-strip-trailing-space ()
1692 "Remove all white space from the end of the lines in the article."
1695 (let ((inhibit-point-motion-hooks t)
1698 (while (re-search-forward "[ \t]+$" nil t)
1699 (replace-match "" t t)))))
1701 (defun article-strip-blank-lines ()
1702 "Strip leading, trailing and multiple blank lines."
1704 (article-strip-leading-blank-lines)
1705 (article-remove-trailing-blank-lines)
1706 (article-strip-multiple-blank-lines))
1708 (defun article-strip-all-blank-lines ()
1709 "Strip all blank lines."
1712 (let ((inhibit-point-motion-hooks t)
1715 (while (re-search-forward "^[ \t]*\n" nil t)
1716 (replace-match "" t t)))))
1718 (defun gnus-article-narrow-to-signature ()
1719 "Narrow to the signature; return t if a signature is found, else nil."
1720 (let ((inhibit-point-motion-hooks t))
1721 (when (gnus-article-search-signature)
1723 ;; Check whether we have some limits to what we consider
1724 ;; to be a signature.
1725 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1726 (list gnus-signature-limit)))
1728 (while (setq limit (pop limits))
1729 (if (or (and (integerp limit)
1730 (< (- (point-max) (point)) limit))
1732 (< (count-lines (point) (point-max)) limit))
1733 (and (gnus-functionp limit)
1735 (and (stringp limit)
1736 (not (re-search-forward limit nil t))))
1737 () ; This limit did not succeed.
1741 (narrow-to-region (point) (point-max))
1744 (defun gnus-article-search-signature ()
1745 "Search the current buffer for the signature separator.
1746 Put point at the beginning of the signature separator."
1747 (let ((cur (point)))
1748 (goto-char (point-max))
1749 (if (if (stringp gnus-signature-separator)
1750 (re-search-backward gnus-signature-separator nil t)
1751 (let ((seps gnus-signature-separator))
1753 (not (re-search-backward (car seps) nil t)))
1760 (defun gnus-article-hidden-arg ()
1761 "Return the current prefix arg as a number, or 0 if no prefix."
1762 (list (if current-prefix-arg
1763 (prefix-numeric-value current-prefix-arg)
1766 (defun gnus-article-check-hidden-text (type arg)
1767 "Return nil if hiding is necessary.
1768 Arg can be nil or a number. Nil and positive means hide, negative
1769 means show, 0 means toggle."
1772 (let ((hide (gnus-article-hidden-text-p type)))
1778 (gnus-article-show-hidden-text type))
1780 (if (eq hide 'hidden)
1781 (gnus-article-show-hidden-text type)
1784 (defun gnus-article-hidden-text-p (type)
1785 "Say whether the current buffer contains hidden text of type TYPE."
1786 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1788 (not (get-text-property pos 'invisible))
1789 (not (get-text-property pos 'dummy-invisible)))
1791 (text-property-any (1+ pos) (point-max) 'article-type type)))
1796 (defun gnus-article-show-hidden-text (type &optional hide)
1797 "Show all hidden text of type TYPE.
1798 If HIDE, hide the text instead."
1800 (let ((buffer-read-only nil)
1801 (inhibit-point-motion-hooks t)
1804 (while (setq beg (text-property-any end (point-max) 'article-type type))
1807 (text-property-not-all beg (point-max) 'article-type type)
1810 (gnus-article-hide-text beg end gnus-hidden-properties)
1811 (gnus-article-unhide-text beg end))
1815 (defconst article-time-units
1816 `((year . ,(* 365.25 24 60 60))
1817 (week . ,(* 7 24 60 60))
1818 (day . ,(* 24 60 60))
1822 "Mapping from time units to seconds.")
1824 (defun article-date-ut (&optional type highlight header)
1825 "Convert DATE date to universal time in the current article.
1826 If TYPE is `local', convert to local time; if it is `lapsed', output
1827 how much time has lapsed since DATE. For `lapsed', the value of
1828 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1829 should replace the \"Date:\" one, or should be added below it."
1830 (interactive (list 'ut t))
1831 (let* ((header (or header
1832 (message-fetch-field "date")
1834 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1837 ((not gnus-article-date-lapsed-new-header)
1843 (date (if (vectorp header) (mail-header-date header)
1845 (inhibit-point-motion-hooks t)
1850 (article-narrow-to-head)
1851 (when (re-search-forward tdate-regexp nil t)
1852 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1853 date (or (get-text-property (gnus-point-at-bol)
1856 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1858 (when (and date (not (string= date "")))
1859 (goto-char (point-min))
1860 (let ((buffer-read-only nil))
1861 ;; Delete any old Date headers.
1862 (while (re-search-forward date-regexp nil t)
1864 (delete-region (progn (beginning-of-line) (point))
1865 (progn (forward-line 1) (point)))
1866 (delete-region (progn (beginning-of-line) (point))
1867 (progn (end-of-line) (point)))
1868 (setq pos (point))))
1869 (when (and (not pos) (re-search-forward tdate-regexp nil t))
1871 (if pos (goto-char pos))
1872 (insert (article-make-date-line date (or type 'ut)))
1878 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1879 (put-text-property (match-beginning 1) (1+ (match-end 1))
1880 'original-date date)
1881 (put-text-property (match-beginning 1) (1+ (match-end 1))
1883 (put-text-property (match-beginning 2) (match-end 2)
1886 (defun article-make-date-line (date type)
1887 "Return a DATE line of TYPE."
1888 (let ((time (condition-case ()
1892 ;; Convert to the local timezone. We have to slap a
1893 ;; `condition-case' round the calls to the timezone
1894 ;; functions since they aren't particularly resistant to
1897 (let ((tz (car (current-time-zone time))))
1898 (format "Date: %s %s%02d%02d" (current-time-string time)
1899 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1900 (/ (% (abs tz) 3600) 60))))
1901 ;; Convert to Universal Time.
1904 (current-time-string
1905 (let* ((e (parse-time-string date))
1906 (tm (apply 'encode-time e))
1908 (ls (- (cadr tm) (car (current-time-zone time)))))
1909 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1910 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1913 ;; Get the original date from the article.
1914 ((eq type 'original)
1915 (concat "Date: " (if (string-match "\n+$" date)
1916 (substring date 0 (match-beginning 0))
1918 ;; Let the user define the format.
1920 (if (gnus-functionp gnus-article-time-format)
1921 (funcall gnus-article-time-format time)
1924 (format-time-string gnus-article-time-format time))))
1927 (let ((tz (car (current-time-zone time))))
1930 (format-time-string "%Y%m%dT%H%M%S" time)
1931 (format "%s%02d%02d"
1932 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1933 (/ (% (abs tz) 3600) 60)))))
1934 ;; Do an X-Sent lapsed format.
1936 ;; If the date is seriously mangled, the timezone functions are
1937 ;; liable to bug out, so we ignore all errors.
1938 (let* ((now (current-time))
1939 (real-time (subtract-time now time))
1940 (real-sec (and real-time
1941 (+ (* (float (car real-time)) 65536)
1943 (sec (and real-time (abs real-sec)))
1953 ;; This is a bit convoluted, but basically we go
1954 ;; through the time units for years, weeks, etc,
1955 ;; and divide things to see whether that results
1956 ;; in positive answers.
1959 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1960 ;; The (remaining) seconds are too few to
1961 ;; be divided into this time unit.
1963 ;; It's big enough, so we output it.
1964 (setq sec (- sec (* num (cdr unit))))
1966 (concat (if prev ", " "") (int-to-string
1968 " " (symbol-name (car unit))
1969 (if (> num 1) "s" ""))
1971 article-time-units "")
1972 ;; If dates are odd, then it might appear like the
1973 ;; article was sent in the future.
1976 " in the future"))))))
1978 (error "Unknown conversion type: %s" type)))))
1980 (defun article-date-local (&optional highlight)
1981 "Convert the current article date to the local timezone."
1982 (interactive (list t))
1983 (article-date-ut 'local highlight))
1985 (defun article-date-original (&optional highlight)
1986 "Convert the current article date to what it was originally.
1987 This is only useful if you have used some other date conversion
1988 function and want to see what the date was before converting."
1989 (interactive (list t))
1990 (article-date-ut 'original highlight))
1992 (defun article-date-lapsed (&optional highlight)
1993 "Convert the current article date to time lapsed since it was sent."
1994 (interactive (list t))
1995 (article-date-ut 'lapsed highlight))
1997 (defun article-update-date-lapsed ()
1998 "Function to be run from a timer to update the lapsed time line."
1999 (let (deactivate-mark)
2004 (set-buffer (window-buffer w))
2005 (when (eq major-mode 'gnus-article-mode)
2006 (goto-char (point-min))
2007 (when (re-search-forward "^X-Sent:" nil t)
2008 (article-date-lapsed t))))
2011 (defun gnus-start-date-timer (&optional n)
2012 "Start a timer to update the X-Sent header in the article buffers.
2013 The numerical prefix says how frequently (in seconds) the function
2018 (gnus-stop-date-timer)
2019 (setq article-lapsed-timer
2020 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2022 (defun gnus-stop-date-timer ()
2023 "Stop the X-Sent timer."
2025 (when article-lapsed-timer
2026 (nnheader-cancel-timer article-lapsed-timer)
2027 (setq article-lapsed-timer nil)))
2029 (defun article-date-user (&optional highlight)
2030 "Convert the current article date to the user-defined format.
2031 This format is defined by the `gnus-article-time-format' variable."
2032 (interactive (list t))
2033 (article-date-ut 'user highlight))
2035 (defun article-date-iso8601 (&optional highlight)
2036 "Convert the current article date to ISO8601."
2037 (interactive (list t))
2038 (article-date-ut 'iso8601 highlight))
2040 (defun article-show-all ()
2041 "Show all hidden text in the article buffer."
2044 (let ((buffer-read-only nil))
2045 (gnus-article-unhide-text (point-min) (point-max)))))
2047 (defun article-emphasize (&optional arg)
2048 "Emphasize text according to `gnus-emphasis-alist'."
2049 (interactive (gnus-article-hidden-arg))
2050 (unless (gnus-article-check-hidden-text 'emphasis arg)
2054 (with-current-buffer gnus-summary-buffer
2055 gnus-article-emphasis-alist)
2057 gnus-emphasis-alist))
2058 (buffer-read-only nil)
2059 (props (append '(article-type emphasis)
2060 gnus-hidden-properties))
2061 regexp elem beg invisible visible face)
2064 (while (setq elem (pop alist))
2066 (setq regexp (car elem)
2067 invisible (nth 1 elem)
2068 visible (nth 2 elem)
2070 (while (re-search-forward regexp nil t)
2071 (when (and (match-beginning visible) (match-beginning invisible))
2072 (push 'emphasis gnus-article-wash-types)
2073 (gnus-article-hide-text
2074 (match-beginning invisible) (match-end invisible) props)
2075 (gnus-article-unhide-text-type
2076 (match-beginning visible) (match-end visible) 'emphasis)
2077 (gnus-put-text-property-excluding-newlines
2078 (match-beginning visible) (match-end visible) 'face face)
2079 (goto-char (match-end invisible)))))))))
2081 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2082 "Setup newsgroup emphasis alist."
2083 (unless gnus-article-emphasis-alist
2084 (let ((name (and gnus-newsgroup-name
2085 (gnus-group-real-name gnus-newsgroup-name))))
2086 (make-local-variable 'gnus-article-emphasis-alist)
2087 (setq gnus-article-emphasis-alist
2089 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2090 (while (setq elem (pop alist))
2091 (when (and name (string-match (car elem) name))
2093 highlight (copy-list (cdr elem)))))
2095 (copy-list highlight-words)
2096 (if gnus-newsgroup-name
2097 (copy-list (gnus-group-find-parameter
2098 gnus-newsgroup-name 'highlight-words t)))
2099 gnus-emphasis-alist)))))
2101 (defvar gnus-summary-article-menu)
2102 (defvar gnus-summary-post-menu)
2104 ;;; Saving functions.
2106 (defun gnus-article-save (save-buffer file &optional num)
2107 "Save the currently selected article."
2108 (unless gnus-save-all-headers
2109 ;; Remove headers according to `gnus-saved-headers'.
2110 (let ((gnus-visible-headers
2111 (or gnus-saved-headers gnus-visible-headers))
2112 (gnus-article-buffer save-buffer))
2114 (set-buffer save-buffer)
2115 (article-hide-headers 1 t))))
2116 (save-window-excursion
2117 (if (not gnus-default-article-saver)
2118 (error "No default saver is defined")
2119 ;; !!! Magic! The saving functions all save
2120 ;; `gnus-save-article-buffer' (or so they think), but we
2121 ;; bind that variable to our save-buffer.
2122 (set-buffer gnus-article-buffer)
2123 (let* ((gnus-save-article-buffer save-buffer)
2126 ((not gnus-prompt-before-saving) 'default)
2127 ((eq gnus-prompt-before-saving 'always) nil)
2129 (gnus-number-of-articles-to-be-saved
2130 (when (eq gnus-prompt-before-saving t)
2132 (set-buffer gnus-article-current-summary)
2133 (funcall gnus-default-article-saver filename)))))
2135 (defun gnus-read-save-file-name (prompt &optional filename
2136 function group headers variable)
2138 (funcall function group headers (symbol-value variable)))
2143 ((eq filename 'default)
2149 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2152 (if (and gnus-number-of-articles-to-be-saved
2153 (> gnus-number-of-articles-to-be-saved 1))
2154 (format "these %d articles"
2155 gnus-number-of-articles-to-be-saved)
2158 ;; Let the split methods have their say.
2160 ;; No split name was found.
2163 (concat prompt " (default "
2164 (file-name-nondirectory default-name) ") ")
2165 (file-name-directory default-name)
2167 ;; A single group name is returned.
2168 ((stringp split-name)
2170 (funcall function split-name headers
2171 (symbol-value variable)))
2173 (concat prompt " (default "
2174 (file-name-nondirectory default-name) ") ")
2175 (file-name-directory default-name)
2177 ;; A single split name was found
2178 ((= 1 (length split-name))
2179 (let* ((name (expand-file-name
2180 (car split-name) gnus-article-save-directory))
2181 (dir (cond ((file-directory-p name)
2182 (file-name-as-directory name))
2183 ((file-exists-p name) name)
2184 (t gnus-article-save-directory))))
2186 (concat prompt " (default " name ") ")
2188 ;; A list of splits was found.
2190 (setq split-name (nreverse split-name))
2192 (let ((file-name-history
2193 (nconc split-name file-name-history)))
2197 (concat prompt " (`M-p' for defaults) ")
2198 gnus-article-save-directory
2200 gnus-article-save-directory)))
2201 (car (push result file-name-history)))))))
2202 ;; Create the directory.
2203 (gnus-make-directory (file-name-directory file))
2204 ;; If we have read a directory, we append the default file name.
2205 (when (file-directory-p file)
2206 (setq file (concat (file-name-as-directory file)
2207 (file-name-nondirectory default-name))))
2208 ;; Possibly translate some characters.
2209 (nnheader-translate-file-chars file)))))
2210 (gnus-make-directory (file-name-directory result))
2211 (set variable result)))
2213 (defun gnus-article-archive-name (group)
2214 "Return the first instance of an \"Archive-name\" in the current buffer."
2215 (let ((case-fold-search t))
2216 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2217 (nnheader-concat gnus-article-save-directory
2218 (match-string 1)))))
2220 (defun gnus-article-nndoc-name (group)
2221 "If GROUP is an nndoc group, return the name of the parent group."
2222 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2223 (gnus-group-get-parameter group 'save-article-group)))
2225 (defun gnus-summary-save-in-rmail (&optional filename)
2226 "Append this article to Rmail file.
2227 Optional argument FILENAME specifies file name.
2228 Directory to save to is default to `gnus-article-save-directory'."
2229 (setq filename (gnus-read-save-file-name
2230 "Save %s in rmail file:" filename
2231 gnus-rmail-save-name gnus-newsgroup-name
2232 gnus-current-headers 'gnus-newsgroup-last-rmail))
2233 (gnus-eval-in-buffer-window gnus-save-article-buffer
2237 (gnus-output-to-rmail filename))))
2240 (defun gnus-summary-save-in-mail (&optional filename)
2241 "Append this article to Unix mail file.
2242 Optional argument FILENAME specifies file name.
2243 Directory to save to is default to `gnus-article-save-directory'."
2244 (setq filename (gnus-read-save-file-name
2245 "Save %s in Unix mail file:" filename
2246 gnus-mail-save-name gnus-newsgroup-name
2247 gnus-current-headers 'gnus-newsgroup-last-mail))
2248 (gnus-eval-in-buffer-window gnus-save-article-buffer
2252 (if (and (file-readable-p filename)
2253 (mail-file-babyl-p filename))
2254 (rmail-output-to-rmail-file filename t)
2255 (gnus-output-to-mail filename)))))
2258 (defun gnus-summary-save-in-file (&optional filename overwrite)
2259 "Append this article to file.
2260 Optional argument FILENAME specifies file name.
2261 Directory to save to is default to `gnus-article-save-directory'."
2262 (setq filename (gnus-read-save-file-name
2263 "Save %s in file:" filename
2264 gnus-file-save-name gnus-newsgroup-name
2265 gnus-current-headers 'gnus-newsgroup-last-file))
2266 (gnus-eval-in-buffer-window gnus-save-article-buffer
2270 (when (and overwrite
2271 (file-exists-p filename))
2272 (delete-file filename))
2273 (gnus-output-to-file filename))))
2276 (defun gnus-summary-write-to-file (&optional filename)
2277 "Write this article to a file.
2278 Optional argument FILENAME specifies file name.
2279 The directory to save in defaults to `gnus-article-save-directory'."
2280 (gnus-summary-save-in-file nil t))
2282 (defun gnus-summary-save-body-in-file (&optional filename)
2283 "Append this article body to a file.
2284 Optional argument FILENAME specifies file name.
2285 The directory to save in defaults to `gnus-article-save-directory'."
2286 (setq filename (gnus-read-save-file-name
2287 "Save %s body in file:" filename
2288 gnus-file-save-name gnus-newsgroup-name
2289 gnus-current-headers 'gnus-newsgroup-last-file))
2290 (gnus-eval-in-buffer-window gnus-save-article-buffer
2294 (when (article-goto-body)
2295 (narrow-to-region (point) (point-max)))
2296 (gnus-output-to-file filename))))
2299 (defun gnus-summary-save-in-pipe (&optional command)
2300 "Pipe this article to subprocess."
2302 (cond ((and (eq command 'default)
2303 gnus-last-shell-command)
2304 gnus-last-shell-command)
2308 "Shell command on %s: "
2309 (if (and gnus-number-of-articles-to-be-saved
2310 (> gnus-number-of-articles-to-be-saved 1))
2311 (format "these %d articles"
2312 gnus-number-of-articles-to-be-saved)
2314 gnus-last-shell-command))))
2315 (when (string-equal command "")
2316 (setq command gnus-last-shell-command))
2317 (gnus-eval-in-buffer-window gnus-article-buffer
2320 (shell-command-on-region (point-min) (point-max) command nil)))
2321 (setq gnus-last-shell-command command))
2323 ;;; Article file names when saving.
2325 (defun gnus-capitalize-newsgroup (newsgroup)
2326 "Capitalize NEWSGROUP name."
2327 (when (not (zerop (length newsgroup)))
2328 (concat (char-to-string (upcase (aref newsgroup 0)))
2329 (substring newsgroup 1))))
2331 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2332 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2333 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2334 Otherwise, it is like ~/News/news/group/num."
2337 (concat (if (gnus-use-long-file-name 'not-save)
2338 (gnus-capitalize-newsgroup newsgroup)
2339 (gnus-newsgroup-directory-form newsgroup))
2340 "/" (int-to-string (mail-header-number headers)))
2341 gnus-article-save-directory)))
2343 (string-equal (file-name-directory default)
2344 (file-name-directory last-file))
2345 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2347 (or last-file default))))
2349 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2350 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2351 If variable `gnus-use-long-file-name' is non-nil, it is
2352 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2355 (concat (if (gnus-use-long-file-name 'not-save)
2357 (gnus-newsgroup-directory-form newsgroup))
2358 "/" (int-to-string (mail-header-number headers)))
2359 gnus-article-save-directory)))
2361 (string-equal (file-name-directory default)
2362 (file-name-directory last-file))
2363 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2365 (or last-file default))))
2367 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2368 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2369 If variable `gnus-use-long-file-name' is non-nil, it is
2370 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2373 (if (gnus-use-long-file-name 'not-save)
2374 (gnus-capitalize-newsgroup newsgroup)
2375 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2376 gnus-article-save-directory)))
2378 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2379 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2380 If variable `gnus-use-long-file-name' is non-nil, it is
2381 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2384 (if (gnus-use-long-file-name 'not-save)
2386 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2387 gnus-article-save-directory)))
2394 (setq afunc (car func)
2397 gfunc (intern (format "gnus-%s" func))))
2399 (if (not (fboundp afunc))
2401 `(lambda (&optional interactive &rest args)
2402 ,(documentation afunc t)
2403 (interactive (list t))
2405 (set-buffer gnus-article-buffer)
2407 (call-interactively ',afunc)
2408 (apply ',afunc args))))))))
2409 '(article-hide-headers
2410 article-hide-boring-headers
2411 article-treat-overstrike
2412 article-fill-long-lines
2413 article-capitalize-sentences
2415 article-display-x-face
2416 article-de-quoted-unreadable
2417 article-mime-decode-quoted-printable
2418 article-hide-list-identifiers
2420 article-strip-banner
2423 article-hide-signature
2424 article-strip-headers-in-body
2425 article-remove-trailing-blank-lines
2426 article-strip-leading-blank-lines
2427 article-strip-multiple-blank-lines
2428 article-strip-leading-space
2429 article-strip-trailing-space
2430 article-strip-blank-lines
2431 article-strip-all-blank-lines
2433 article-date-iso8601
2434 article-date-original
2436 article-decode-mime-words
2437 article-decode-charset
2438 article-decode-encoded-words
2442 article-treat-dumbquotes
2443 article-normalize-headers
2444 (article-show-all . gnus-article-show-all-headers))))
2447 ;;; Gnus article mode
2450 (put 'gnus-article-mode 'mode-class 'special)
2452 (set-keymap-parent gnus-article-mode-map widget-keymap)
2454 (gnus-define-keys gnus-article-mode-map
2455 " " gnus-article-goto-next-page
2456 "\177" gnus-article-goto-prev-page
2457 [delete] gnus-article-goto-prev-page
2458 [backspace] gnus-article-goto-prev-page
2459 "\C-c^" gnus-article-refer-article
2460 "h" gnus-article-show-summary
2461 "s" gnus-article-show-summary
2462 "\C-c\C-m" gnus-article-mail
2463 "?" gnus-article-describe-briefly
2464 "e" gnus-summary-article-edit
2465 "<" beginning-of-buffer
2467 "\C-c\C-i" gnus-info-find-node
2470 "\C-d" gnus-article-read-summary-keys
2471 "\M-*" gnus-article-read-summary-keys
2472 "\M-#" gnus-article-read-summary-keys
2473 "\M-^" gnus-article-read-summary-keys
2474 "\M-g" gnus-article-read-summary-keys)
2476 (substitute-key-definition
2477 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2479 (defun gnus-article-make-menu-bar ()
2480 (gnus-turn-off-edit-menu 'article)
2481 (unless (boundp 'gnus-article-article-menu)
2483 gnus-article-article-menu gnus-article-mode-map ""
2485 ["Scroll forwards" gnus-article-goto-next-page t]
2486 ["Scroll backwards" gnus-article-goto-prev-page t]
2487 ["Show summary" gnus-article-show-summary t]
2488 ["Fetch Message-ID at point" gnus-article-refer-article t]
2489 ["Mail to address at point" gnus-article-mail t]
2490 ["Send a bug report" gnus-bug t]))
2493 gnus-article-treatment-menu gnus-article-mode-map ""
2495 ["Hide headers" gnus-article-hide-headers t]
2496 ["Hide signature" gnus-article-hide-signature t]
2497 ["Hide citation" gnus-article-hide-citation t]
2498 ["Treat overstrike" gnus-article-treat-overstrike t]
2499 ["Remove carriage return" gnus-article-remove-cr t]
2500 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2502 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2504 (when (boundp 'gnus-summary-post-menu)
2505 (define-key gnus-article-mode-map [menu-bar post]
2506 (cons "Post" gnus-summary-post-menu)))
2508 (gnus-run-hooks 'gnus-article-menu-hook)))
2510 (defun gnus-article-mode ()
2511 "Major mode for displaying an article.
2513 All normal editing commands are switched off.
2515 The following commands are available in addition to all summary mode
2517 \\<gnus-article-mode-map>
2518 \\[gnus-article-next-page]\t Scroll the article one page forwards
2519 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2520 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2521 \\[gnus-article-show-summary]\t Display the summary buffer
2522 \\[gnus-article-mail]\t Send a reply to the address near point
2523 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2524 \\[gnus-info-find-node]\t Go to the Gnus info node"
2526 (when (gnus-visual-p 'article-menu 'menu)
2527 (gnus-article-make-menu-bar))
2528 (gnus-simplify-mode-line)
2529 (setq mode-name "Article")
2530 (setq major-mode 'gnus-article-mode)
2531 (make-local-variable 'minor-mode-alist)
2532 (use-local-map gnus-article-mode-map)
2533 (gnus-update-format-specifications nil 'article-mode)
2534 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2535 (make-local-variable 'gnus-page-broken)
2536 (make-local-variable 'gnus-button-marker-list)
2537 (make-local-variable 'gnus-article-current-summary)
2538 (make-local-variable 'gnus-article-mime-handles)
2539 (make-local-variable 'gnus-article-decoded-p)
2540 (make-local-variable 'gnus-article-mime-handle-alist)
2541 (make-local-variable 'gnus-article-washed-types)
2542 (gnus-set-default-directory)
2543 (buffer-disable-undo)
2544 (setq buffer-read-only t)
2545 (set-syntax-table gnus-article-mode-syntax-table)
2546 (mm-enable-multibyte)
2547 (gnus-run-hooks 'gnus-article-mode-hook))
2549 (defun gnus-article-setup-buffer ()
2550 "Initialize the article buffer."
2551 (let* ((name (if gnus-single-article-buffer "*Article*"
2552 (concat "*Article " gnus-newsgroup-name "*")))
2554 (progn (string-match "\\*Article" name)
2555 (concat " *Original Article"
2556 (substring name (match-end 0))))))
2557 (setq gnus-article-buffer name)
2558 (setq gnus-original-article-buffer original)
2559 (setq gnus-article-mime-handle-alist nil)
2560 ;; This might be a variable local to the summary buffer.
2561 (unless gnus-single-article-buffer
2563 (set-buffer gnus-summary-buffer)
2564 (setq gnus-article-buffer name)
2565 (setq gnus-original-article-buffer original)
2566 (gnus-set-global-variables)))
2567 (gnus-article-setup-highlight-words)
2568 ;; Init original article buffer.
2570 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2571 (mm-enable-multibyte)
2572 (setq major-mode 'gnus-original-article-mode)
2573 (make-local-variable 'gnus-original-article))
2574 (if (get-buffer name)
2577 (if gnus-article-mime-handles
2578 (mm-destroy-parts gnus-article-mime-handles))
2579 (kill-all-local-variables)
2580 (buffer-disable-undo)
2581 (setq buffer-read-only t)
2582 (unless (eq major-mode 'gnus-article-mode)
2583 (gnus-article-mode))
2586 (set-buffer (gnus-get-buffer-create name))
2588 (make-local-variable 'gnus-summary-buffer)
2589 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2590 (current-buffer)))))
2592 ;; Set article window start at LINE, where LINE is the number of lines
2593 ;; from the head of the article.
2594 (defun gnus-article-set-window-start (&optional line)
2596 (get-buffer-window gnus-article-buffer t)
2598 (set-buffer gnus-article-buffer)
2599 (goto-char (point-min))
2602 (gnus-message 6 "Moved to bookmark")
2603 (search-forward "\n\n" nil t)
2607 (defun gnus-article-prepare (article &optional all-headers header)
2608 "Prepare ARTICLE in article mode buffer.
2609 ARTICLE should either be an article number or a Message-ID.
2610 If ARTICLE is an id, HEADER should be the article headers.
2611 If ALL-HEADERS is non-nil, no headers are hidden."
2613 ;; Make sure we start in a summary buffer.
2614 (unless (eq major-mode 'gnus-summary-mode)
2615 (set-buffer gnus-summary-buffer))
2616 (setq gnus-summary-buffer (current-buffer))
2617 (let* ((gnus-article (if header (mail-header-number header) article))
2618 (summary-buffer (current-buffer))
2619 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2620 (group gnus-newsgroup-name)
2623 (gnus-article-setup-buffer)
2624 (set-buffer gnus-article-buffer)
2625 ;; Deactivate active regions.
2626 (when (and (boundp 'transient-mark-mode)
2627 transient-mark-mode)
2628 (setq mark-active nil))
2629 (if (not (setq result (let ((buffer-read-only nil))
2630 (gnus-request-article-this-buffer
2632 ;; There is no such article.
2634 (when (and (numberp article)
2635 (not (memq article gnus-newsgroup-sparse)))
2636 (setq gnus-article-current
2637 (cons gnus-newsgroup-name article))
2638 (set-buffer gnus-summary-buffer)
2639 (setq gnus-current-article article)
2640 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2642 (gnus-summary-set-agent-mark article)
2643 (message "Message marked for downloading"))
2644 (gnus-summary-mark-article article gnus-canceled-mark)
2645 (unless (memq article gnus-newsgroup-sparse)
2647 "No such article (may have expired or been canceled)")))))
2648 (if (or (eq result 'pseudo)
2649 (eq result 'nneething))
2652 (set-buffer summary-buffer)
2653 (push article gnus-newsgroup-history)
2654 (setq gnus-last-article gnus-current-article
2655 gnus-current-article 0
2656 gnus-current-headers nil
2657 gnus-article-current nil)
2658 (if (eq result 'nneething)
2659 (gnus-configure-windows 'summary)
2660 (gnus-configure-windows 'article))
2661 (gnus-set-global-variables))
2662 (let ((gnus-article-mime-handle-alist-1
2663 gnus-article-mime-handle-alist))
2664 (gnus-set-mode-line 'article)))
2665 ;; The result from the `request' was an actual article -
2666 ;; or at least some text that is now displayed in the
2668 (when (and (numberp article)
2669 (not (eq article gnus-current-article)))
2670 ;; Seems like a new article has been selected.
2671 ;; `gnus-current-article' must be an article number.
2673 (set-buffer summary-buffer)
2674 (push article gnus-newsgroup-history)
2675 (setq gnus-last-article gnus-current-article
2676 gnus-current-article article
2677 gnus-current-headers
2678 (gnus-summary-article-header gnus-current-article)
2679 gnus-article-current
2680 (cons gnus-newsgroup-name gnus-current-article))
2681 (unless (vectorp gnus-current-headers)
2682 (setq gnus-current-headers nil))
2683 (gnus-summary-goto-subject gnus-current-article)
2684 (when (gnus-summary-show-thread)
2685 ;; If the summary buffer really was folded, the
2686 ;; previous goto may not actually have gone to
2687 ;; the right article, but the thread root instead.
2689 (gnus-summary-goto-subject gnus-current-article))
2690 (gnus-run-hooks 'gnus-mark-article-hook)
2691 (gnus-set-mode-line 'summary)
2692 (when (gnus-visual-p 'article-highlight 'highlight)
2693 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2694 ;; Set the global newsgroup variables here.
2695 (gnus-set-global-variables)
2696 (setq gnus-have-all-headers
2697 (or all-headers gnus-show-all-headers))))
2698 (when (or (numberp article)
2700 (gnus-article-prepare-display)
2702 (goto-char (point-min))
2703 (setq gnus-page-broken
2704 (when gnus-break-pages
2705 (gnus-narrow-to-page)
2707 (let ((gnus-article-mime-handle-alist-1
2708 gnus-article-mime-handle-alist))
2709 (gnus-set-mode-line 'article))
2711 (set-window-point (get-buffer-window (current-buffer)) (point))
2712 (gnus-configure-windows 'article)
2716 (defun gnus-article-prepare-display ()
2717 "Make the current buffer look like a nice article."
2718 ;; Hooks for getting information from the article.
2719 ;; This hook must be called before being narrowed.
2720 (let ((gnus-article-buffer (current-buffer))
2722 (unless (eq major-mode 'gnus-article-mode)
2723 (gnus-article-mode))
2724 (setq buffer-read-only nil
2725 gnus-article-wash-types nil)
2726 (gnus-run-hooks 'gnus-tmp-internal-hook)
2727 (when gnus-display-mime-function
2728 (funcall gnus-display-mime-function))
2729 (gnus-run-hooks 'gnus-article-prepare-hook)))
2732 ;;; Gnus MIME viewing functions
2735 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2736 "The following specs can be used:
2738 %T MIME type, along with additional info
2739 %n The `name' parameter
2740 %d The description, if any
2741 %l The length of the encoded part
2742 %p The part identifier number
2743 %e Dots if the part isn't displayed")
2745 (defvar gnus-mime-button-line-format-alist
2746 '((?t gnus-tmp-type ?s)
2747 (?T gnus-tmp-type-long ?s)
2748 (?n gnus-tmp-name ?s)
2749 (?d gnus-tmp-description ?s)
2751 (?l gnus-tmp-length ?d)
2752 (?e gnus-tmp-dots ?s)))
2754 (defvar gnus-mime-button-commands
2755 '((gnus-article-press-button "\r" "Toggle Display")
2756 (gnus-mime-view-part "v" "View Interactively...")
2757 (gnus-mime-view-part-as-type "t" "View As Type...")
2758 (gnus-mime-save-part "o" "Save...")
2759 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2760 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2761 (gnus-mime-internalize-part "E" "View Internally")
2762 (gnus-mime-externalize-part "e" "View Externally")
2763 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2765 (defun gnus-article-mime-part-status ()
2766 (if gnus-article-mime-handle-alist-1
2767 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2770 (defvar gnus-mime-button-map nil)
2771 (unless gnus-mime-button-map
2772 (setq gnus-mime-button-map (make-sparse-keymap))
2773 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2774 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2775 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2777 (define-key gnus-mime-button-map (cadr c) (car c)))
2778 gnus-mime-button-commands))
2780 (defun gnus-mime-button-menu (event)
2781 "Construct a context-sensitive menu of MIME commands."
2784 (let ((pos (event-start event)))
2785 (set-buffer (window-buffer (posn-window pos)))
2786 (goto-char (posn-point pos))
2787 (gnus-article-check-buffer)
2788 (let ((response (x-popup-menu
2790 ("" ,@(mapcar (lambda (c)
2791 (cons (caddr c) (car c)))
2792 gnus-mime-button-commands))))))
2794 (funcall response))))))
2796 (defun gnus-mime-view-all-parts (&optional handles)
2797 "View all the MIME parts."
2799 (save-current-buffer
2800 (set-buffer gnus-article-buffer)
2801 (let ((handles (or handles gnus-article-mime-handles))
2802 (mail-parse-charset gnus-newsgroup-charset)
2803 (mail-parse-ignored-charsets
2804 (save-excursion (set-buffer gnus-summary-buffer)
2805 gnus-newsgroup-ignored-charsets)))
2806 (if (stringp (car handles))
2807 (gnus-mime-view-all-parts (cdr handles))
2808 (mapcar 'mm-display-part handles)))))
2810 (defun gnus-mime-save-part ()
2811 "Save the MIME part under point."
2813 (gnus-article-check-buffer)
2814 (let ((data (get-text-property (point) 'gnus-data)))
2815 (mm-save-part data)))
2817 (defun gnus-mime-pipe-part ()
2818 "Pipe the MIME part under point to a process."
2820 (gnus-article-check-buffer)
2821 (let ((data (get-text-property (point) 'gnus-data)))
2822 (mm-pipe-part data)))
2824 (defun gnus-mime-view-part ()
2825 "Interactively choose a viewing method for the MIME part under point."
2827 (gnus-article-check-buffer)
2828 (let ((data (get-text-property (point) 'gnus-data)))
2829 (mm-interactively-view-part data)))
2831 (defun gnus-mime-view-part-as-type ()
2832 "Choose a MIME media type, and view the part as such."
2834 (list (completing-read "View as MIME type: " mailcap-mime-types)))
2835 (gnus-article-check-buffer)
2836 (let ((handle (get-text-property (point) 'gnus-data)))
2837 (gnus-mm-display-part handle)))
2839 (defun gnus-mime-copy-part (&optional handle)
2840 "Put the the MIME part under point into a new buffer."
2842 (gnus-article-check-buffer)
2843 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2844 (contents (mm-get-part handle))|
2845 (base (file-name-nondirectory
2847 (mail-content-type-get (mm-handle-type handle) 'name)
2848 (mail-content-type-get (mm-handle-type handle)
2851 (buffer (generate-new-buffer base)))
2852 (switch-to-buffer buffer)
2854 ;; We do it this way to make `normal-mode' set the appropriate mode.
2857 (setq buffer-file-name (expand-file-name base))
2859 (setq buffer-file-name nil))
2860 (goto-char (point-min))))
2862 (defun gnus-mime-inline-part (&optional handle)
2863 "Insert the MIME part under point into the current buffer."
2865 (gnus-article-check-buffer)
2866 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2870 (if (mm-handle-undisplayer handle)
2871 (mm-remove-part handle)
2872 (setq contents (mm-get-part handle))
2874 (mm-insert-inline handle contents)
2877 (defun gnus-mime-externalize-part (&optional handle)
2878 "View the MIME part under point with an external viewer."
2880 (gnus-article-check-buffer)
2881 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2882 (mm-user-display-methods nil)
2883 (mm-inline-large-images nil)
2884 (mail-parse-charset gnus-newsgroup-charset)
2885 (mail-parse-ignored-charsets
2886 (save-excursion (set-buffer gnus-summary-buffer)
2887 gnus-newsgroup-ignored-charsets)))
2888 (if (mm-handle-undisplayer handle)
2889 (mm-remove-part handle)
2890 (mm-display-part handle))))
2892 (defun gnus-mime-internalize-part (&optional handle)
2893 "View the MIME part under point with an internal viewer.
2894 In no internal viewer is available, use an external viewer."
2896 (gnus-article-check-buffer)
2897 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2898 (mm-inlined-types '(".*"))
2899 (mm-inline-large-images t)
2900 (mail-parse-charset gnus-newsgroup-charset)
2901 (mail-parse-ignored-charsets
2902 (save-excursion (set-buffer gnus-summary-buffer)
2903 gnus-newsgroup-ignored-charsets)))
2904 (if (mm-handle-undisplayer handle)
2905 (mm-remove-part handle)
2906 (mm-display-part handle))))
2908 (defun gnus-article-part-wrapper (n function)
2909 (save-current-buffer
2910 (set-buffer gnus-article-buffer)
2911 (when (> n (length gnus-article-mime-handle-alist))
2912 (error "No such part"))
2913 (gnus-article-goto-part n)
2914 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2915 (funcall function handle))))
2917 (defun gnus-article-pipe-part (n)
2918 "Pipe MIME part N, which is the numerical prefix."
2920 (gnus-article-part-wrapper n 'mm-pipe-part))
2922 (defun gnus-article-save-part (n)
2923 "Save MIME part N, which is the numerical prefix."
2925 (gnus-article-part-wrapper n 'mm-save-part))
2927 (defun gnus-article-interactively-view-part (n)
2928 "View MIME part N interactively, which is the numerical prefix."
2930 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2932 (defun gnus-article-copy-part (n)
2933 "Copy MIME part N, which is the numerical prefix."
2935 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2937 (defun gnus-article-externalize-part (n)
2938 "View MIME part N externally, which is the numerical prefix."
2940 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2942 (defun gnus-article-inline-part (n)
2943 "Inline MIME part N, which is the numerical prefix."
2945 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2947 (defun gnus-article-mime-match-handle-first (condition)
2949 (let ((alist gnus-article-mime-handle-alist) ihandle n)
2950 (while (setq ihandle (pop alist))
2952 ((functionp condition)
2953 (funcall condition (cdr ihandle)))
2954 ((eq condition 'undisplayed)
2955 (not (or (mm-handle-undisplayer (cdr ihandle))
2956 (equal (mm-handle-media-type (cdr ihandle))
2957 "multipart/alternative"))))
2958 ((eq condition 'undisplayed-alternative)
2959 (not (mm-handle-undisplayer (cdr ihandle))))
2961 (gnus-article-goto-part (car ihandle))
2962 (or (not n) (< (car ihandle) n)))
2963 (setq n (car ihandle))))
2967 (defun gnus-article-view-part (&optional n)
2968 "View MIME part N, which is the numerical prefix."
2970 (save-current-buffer
2971 (set-buffer gnus-article-buffer)
2972 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
2973 gnus-article-mime-match-handle-function)))
2974 (when (> n (length gnus-article-mime-handle-alist))
2975 (error "No such part"))
2976 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2977 (when (gnus-article-goto-part n)
2978 (if (equal (car handle) "multipart/alternative")
2979 (gnus-article-press-button)
2980 (when (eq (gnus-mm-display-part handle) 'internal)
2981 (gnus-set-window-start)))))))
2983 (defun gnus-mm-display-part (handle)
2984 "Display HANDLE and fix MIME button."
2985 (let ((id (get-text-property (point) 'gnus-part))
2990 (let ((window (selected-window))
2991 (mail-parse-charset gnus-newsgroup-charset)
2992 (mail-parse-ignored-charsets
2993 (save-excursion (set-buffer gnus-summary-buffer)
2994 gnus-newsgroup-ignored-charsets)))
2997 (let ((win (get-buffer-window (current-buffer) t))
3000 (select-window win))
3003 (if (mm-handle-displayed-p handle)
3004 ;; This will remove the part.
3005 (mm-display-part handle)
3007 (narrow-to-region (point) (1+ (point)))
3008 (mm-display-part handle)
3009 ;; We narrow to the part itself and
3010 ;; then call the treatment functions.
3011 (goto-char (point-min))
3013 (narrow-to-region (point) (point-max))
3016 (1- (length gnus-article-mime-handles))
3017 (mm-handle-media-type handle)))))
3018 (select-window window))))
3020 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3021 (gnus-insert-mime-button
3022 handle id (list (mm-handle-displayed-p handle)))
3023 (goto-char point))))
3025 (defun gnus-article-goto-part (n)
3026 "Go to MIME part N."
3027 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3029 (goto-char point))))
3031 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3032 (let ((gnus-tmp-name
3033 (or (mail-content-type-get (mm-handle-type handle)
3035 (mail-content-type-get (mm-handle-disposition handle)
3038 (gnus-tmp-type (mm-handle-media-type handle))
3039 (gnus-tmp-description
3040 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3043 (if (if displayed (car displayed)
3044 (mm-handle-displayed-p handle))
3046 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3048 gnus-tmp-type-long b e)
3049 (when (string-match ".*/" gnus-tmp-name)
3050 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3051 (setq gnus-tmp-type-long (concat gnus-tmp-type
3052 (and (not (equal gnus-tmp-name ""))
3053 (concat "; " gnus-tmp-name))))
3054 (or (equal gnus-tmp-description "")
3055 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3060 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3061 `(local-map ,gnus-mime-button-map
3062 keymap ,gnus-mime-button-map
3063 gnus-callback gnus-mm-display-part
3064 gnus-part ,gnus-tmp-id
3065 article-type annotation
3068 (widget-convert-button 'link b e
3070 :action 'gnus-widget-press-button
3071 :button-keymap gnus-mime-button-map
3074 ;; Needed to properly clear the message
3075 ;; due to a bug in wid-edit
3076 (setq help-echo-owns-message t)
3078 "Click to %s the MIME part; %s for more options"
3079 (if (mm-handle-displayed-p
3080 (widget-get widget :mime-handle))
3082 (if gnus-xemacs "button3" "mouse-3"))))))
3084 (defun gnus-widget-press-button (elems el)
3085 (goto-char (widget-get elems :from))
3086 (gnus-article-press-button))
3088 (defvar gnus-displaying-mime nil)
3090 (defun gnus-display-mime (&optional ihandles)
3091 "Display the MIME parts."
3093 (save-selected-window
3094 (let ((window (get-buffer-window gnus-article-buffer))
3097 (select-window window)
3098 ;; We have to do this since selecting the window
3099 ;; may change the point. So we set the window point.
3100 (set-window-point window point)))
3101 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3102 buffer-read-only handle name type b e display)
3103 (when (and (not ihandles)
3104 (not gnus-displaying-mime))
3105 ;; Top-level call; we clean up.
3106 (when gnus-article-mime-handles
3107 (mm-destroy-parts gnus-article-mime-handles)
3108 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3109 (setq gnus-article-mime-handles handles)
3110 ;; We allow users to glean info from the handles.
3111 (when gnus-article-mime-part-function
3112 (gnus-mime-part-function handles)))
3114 (or (not (stringp (car handles)))
3117 (when (and (not ihandles)
3118 (not gnus-displaying-mime))
3119 ;; Clean up for mime parts.
3121 (delete-region (point) (point-max)))
3122 (let ((gnus-displaying-mime t))
3123 (gnus-mime-display-part handles)))
3126 (narrow-to-region (point) (point-max))
3127 (gnus-treat-article nil 1 1)
3130 ;; Highlight the headers.
3134 (narrow-to-region (point-min) (point))
3135 (gnus-treat-article 'head))))))))
3137 (defvar gnus-mime-display-multipart-as-mixed nil)
3139 (defun gnus-mime-display-part (handle)
3142 ((not (stringp (car handle)))
3143 (gnus-mime-display-single handle))
3144 ;; User-defined multipart
3145 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3146 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3148 ;; multipart/alternative
3149 ((and (equal (car handle) "multipart/alternative")
3150 (not gnus-mime-display-multipart-as-mixed))
3151 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3152 (push (cons id handle) gnus-article-mime-handle-alist)
3153 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3154 ;; multipart/related
3155 ((and (equal (car handle) "multipart/related")
3156 (not gnus-mime-display-multipart-as-mixed))
3157 ;;;!!!We should find the start part, but we just default
3158 ;;;!!!to the first part.
3159 (gnus-mime-display-part (cadr handle)))
3160 ;; Other multiparts are handled like multipart/mixed.
3162 (gnus-mime-display-mixed (cdr handle)))))
3164 (defun gnus-mime-part-function (handles)
3165 (if (stringp (car handles))
3166 (mapcar 'gnus-mime-part-function (cdr handles))
3167 (funcall gnus-article-mime-part-function handles)))
3169 (defun gnus-mime-display-mixed (handles)
3170 (mapcar 'gnus-mime-display-part handles))
3172 (defun gnus-mime-display-single (handle)
3173 (let ((type (mm-handle-media-type handle))
3174 (ignored gnus-ignored-mime-types)
3181 (when (string-match (pop ignored) type)
3182 (throw 'ignored nil)))
3183 (if (and (setq not-attachment
3184 (and (not (mm-inline-override-p handle))
3185 (or (not (mm-handle-disposition handle))
3186 (equal (car (mm-handle-disposition handle))
3188 (mm-attachment-override-p handle))))
3189 (mm-automatic-display-p handle)
3190 (or (mm-inlined-p handle)
3191 (mm-automatic-external-display-p type)))
3193 (when (equal (mm-handle-media-supertype handle) "text")
3195 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3196 (push (cons id handle) gnus-article-mime-handle-alist)
3197 (when (or (not display)
3198 (not (gnus-unbuttonized-mime-type-p type)))
3199 (gnus-article-insert-newline)
3200 (gnus-insert-mime-button
3201 handle id (list (or display (and not-attachment text))))
3202 (gnus-article-insert-newline)
3203 (gnus-article-insert-newline)
3205 (let ((beg (point)))
3211 (let ((mail-parse-charset gnus-newsgroup-charset)
3212 (mail-parse-ignored-charsets
3213 (save-excursion (condition-case ()
3214 (set-buffer gnus-summary-buffer)
3216 gnus-newsgroup-ignored-charsets)))
3217 (mm-display-part handle t))
3218 (goto-char (point-max)))
3219 ((and text not-attachment)
3223 (gnus-article-insert-newline)
3224 (mm-insert-inline handle (mm-get-part handle))
3225 (goto-char (point-max))))
3229 (narrow-to-region beg (point))
3231 nil (length gnus-article-mime-handle-alist)
3232 (1- (length gnus-article-mime-handles))
3233 (mm-handle-media-type handle)))))))))
3235 (defun gnus-unbuttonized-mime-type-p (type)
3236 "Say whether TYPE is to be unbuttonized."
3237 (unless gnus-inhibit-mime-unbuttonizing
3239 (let ((types gnus-unbuttonized-mime-types))
3241 (when (string-match (pop types) type)
3242 (throw 'found t)))))))
3244 (defun gnus-article-insert-newline ()
3245 "Insert a newline, but mark it as undeletable."
3246 (gnus-put-text-property
3247 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3249 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3250 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3253 handle buffer-read-only from props begend not-pref)
3254 (save-window-excursion
3257 (narrow-to-region (car ibegend)
3260 (goto-char (car ibegend))
3263 (delete-region (point-min) (point-max))
3264 (mm-remove-parts handles))
3265 (setq begend (list (point-marker)))
3267 (unless (setq not-pref (cadr (member preferred ihandles)))
3268 (setq not-pref (car ihandles)))
3270 (not (gnus-unbuttonized-mime-type-p
3271 "multipart/alternative")))
3272 (gnus-add-text-properties
3275 (insert (format "%d. " id))
3279 (unless ,(not ibegend)
3280 (setq gnus-article-mime-handle-alist
3281 ',gnus-article-mime-handle-alist))
3282 (gnus-mime-display-alternative
3283 ',ihandles ',not-pref ',begend ,id))
3284 local-map ,gnus-mime-button-map
3285 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3286 face ,gnus-article-button-face
3287 keymap ,gnus-mime-button-map
3290 (widget-convert-button 'link from (point)
3291 :action 'gnus-widget-press-button
3292 :button-keymap gnus-widget-button-keymap)
3294 (while (setq handle (pop handles))
3295 (gnus-add-text-properties
3298 (insert (format "(%c) %-18s"
3299 (if (equal handle preferred) ?* ? )
3300 (mm-handle-media-type handle)))
3304 (unless ,(not ibegend)
3305 (setq gnus-article-mime-handle-alist
3306 ',gnus-article-mime-handle-alist))
3307 (gnus-mime-display-alternative
3308 ',ihandles ',handle ',begend ,id))
3309 local-map ,gnus-mime-button-map
3310 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3311 face ,gnus-article-button-face
3312 keymap ,gnus-mime-button-map
3315 (widget-convert-button 'link from (point)
3316 :action 'gnus-widget-press-button
3317 :button-keymap gnus-widget-button-keymap)
3321 (if (stringp (car preferred))
3322 (gnus-display-mime preferred)
3323 (let ((mail-parse-charset gnus-newsgroup-charset)
3324 (mail-parse-ignored-charsets
3325 (save-excursion (set-buffer gnus-summary-buffer)
3326 gnus-newsgroup-ignored-charsets)))
3327 (mm-display-part preferred)
3331 (narrow-to-region (car begend) (point-max))
3333 nil (length gnus-article-mime-handle-alist)
3334 (1- (length gnus-article-mime-handles))
3335 (mm-handle-media-type handle))))))
3336 (goto-char (point-max))
3337 (setcdr begend (point-marker)))))
3339 (goto-char point))))
3341 (defun gnus-article-wash-status ()
3342 "Return a string which display status of article washing."
3344 (set-buffer gnus-article-buffer)
3345 (let ((cite (memq 'cite gnus-article-wash-types))
3346 (headers (memq 'headers gnus-article-wash-types))
3347 (boring (memq 'boring-headers gnus-article-wash-types))
3348 (pgp (memq 'pgp gnus-article-wash-types))
3349 (pem (memq 'pem gnus-article-wash-types))
3350 (signature (memq 'signature gnus-article-wash-types))
3351 (overstrike (memq 'overstrike gnus-article-wash-types))
3352 (emphasis (memq 'emphasis gnus-article-wash-types)))
3353 (format "%c%c%c%c%c%c"
3355 (if (or headers boring) ?h ? )
3356 (if (or pgp pem) ?p ? )
3357 (if signature ?s ? )
3358 (if overstrike ?o ? )
3359 (if emphasis ?e ? )))))
3361 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3363 (defun gnus-article-maybe-hide-headers ()
3364 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3365 Provided for backwards compatibility."
3366 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3367 (not (save-excursion (set-buffer gnus-summary-buffer)
3368 gnus-have-all-headers)))
3369 (not gnus-inhibit-hiding))
3370 (gnus-article-hide-headers)))
3374 (defun gnus-output-to-file (file-name)
3375 "Append the current article to a file named FILE-NAME."
3376 (let ((artbuf (current-buffer)))
3378 (insert-buffer-substring artbuf)
3379 ;; Append newline at end of the buffer as separator, and then
3381 (goto-char (point-max))
3383 (mm-append-to-file (point-min) (point-max) file-name)
3386 (defun gnus-narrow-to-page (&optional arg)
3387 "Narrow the article buffer to a page.
3388 If given a numerical ARG, move forward ARG pages."
3390 (setq arg (if arg (prefix-numeric-value arg) 0))
3392 (set-buffer gnus-article-buffer)
3393 (goto-char (point-min))
3395 ;; Remove any old next/prev buttons.
3396 (when (gnus-visual-p 'page-marker)
3397 (let ((buffer-read-only nil))
3398 (gnus-remove-text-with-property 'gnus-prev)
3399 (gnus-remove-text-with-property 'gnus-next)))
3402 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3404 (re-search-forward page-delimiter nil 'move arg)))
3405 (goto-char (match-end 0)))
3408 (if (re-search-forward page-delimiter nil 'move)
3411 (when (and (gnus-visual-p 'page-marker)
3412 (not (= (point-min) 1)))
3414 (goto-char (point-min))
3415 (gnus-insert-prev-page-button)))
3416 (when (and (gnus-visual-p 'page-marker)
3417 (< (+ (point-max) 2) (buffer-size)))
3419 (goto-char (point-max))
3420 (gnus-insert-next-page-button)))))
3422 ;; Article mode commands
3424 (defun gnus-article-goto-next-page ()
3425 "Show the next page of the article."
3427 (when (gnus-article-next-page)
3428 (goto-char (point-min))
3429 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3431 (defun gnus-article-goto-prev-page ()
3432 "Show the next page of the article."
3434 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3435 (gnus-article-prev-page nil)))
3437 (defun gnus-article-next-page (&optional lines)
3438 "Show the next page of the current article.
3439 If end of article, return non-nil. Otherwise return nil.
3440 Argument LINES specifies lines to be scrolled up."
3442 (move-to-window-line -1)
3445 (and (pos-visible-in-window-p) ;Not continuation line.
3447 ;; Nothing in this page.
3448 (if (or (not gnus-page-broken)
3451 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3453 (gnus-narrow-to-page 1) ;Go to next page.
3455 ;; More in this page.
3456 (let ((scroll-in-place nil))
3460 ;; Long lines may cause an end-of-buffer error.
3461 (goto-char (point-max)))))
3462 (move-to-window-line 0)
3465 (defun gnus-article-prev-page (&optional lines)
3466 "Show previous page of current article.
3467 Argument LINES specifies lines to be scrolled down."
3469 (move-to-window-line 0)
3470 (if (and gnus-page-broken
3472 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3474 (gnus-narrow-to-page -1) ;Go to previous page.
3475 (goto-char (point-max))
3477 (let ((scroll-in-place nil))
3481 (beginning-of-buffer
3482 (goto-char (point-min))))
3483 (move-to-window-line 0)))))
3485 (defun gnus-article-refer-article ()
3486 "Read article specified by message-id around point."
3488 (let ((point (point)))
3489 (search-forward ">" nil t) ;Move point to end of "<....>".
3490 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3491 (let ((message-id (match-string 1)))
3493 (set-buffer gnus-summary-buffer)
3494 (gnus-summary-refer-article message-id))
3496 (error "No references around point"))))
3498 (defun gnus-article-show-summary ()
3499 "Reconfigure windows to show summary buffer."
3501 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3502 (error "There is no summary buffer for this article buffer")
3503 (gnus-article-set-globals)
3504 (gnus-configure-windows 'article)
3505 (gnus-summary-goto-subject gnus-current-article)
3506 (gnus-summary-position-point)))
3508 (defun gnus-article-describe-briefly ()
3509 "Describe article mode commands briefly."
3511 (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")))
3513 (defun gnus-article-summary-command ()
3514 "Execute the last keystroke in the summary buffer."
3516 (let ((obuf (current-buffer))
3517 (owin (current-window-configuration))
3519 (switch-to-buffer gnus-article-current-summary 'norecord)
3520 (setq func (lookup-key (current-local-map) (this-command-keys)))
3521 (call-interactively func)
3523 (set-window-configuration owin)
3524 (set-window-point (get-buffer-window (current-buffer)) (point))))
3526 (defun gnus-article-summary-command-nosave ()
3527 "Execute the last keystroke in the summary buffer."
3530 (pop-to-buffer gnus-article-current-summary 'norecord)
3531 (setq func (lookup-key (current-local-map) (this-command-keys)))
3532 (call-interactively func)))
3534 (defun gnus-article-check-buffer ()
3535 "Beep if not in an article buffer."
3536 (unless (equal major-mode 'gnus-article-mode)
3537 (error "Command invoked outside of a Gnus article buffer")))
3539 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3540 "Read a summary buffer key sequence and execute it from the article buffer."
3542 (gnus-article-check-buffer)
3544 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3545 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3546 "=" "^" "\M-^" "|"))
3552 '("n" "Gn" "p" "Gp"))
3555 (set-buffer gnus-article-current-summary)
3556 (let (gnus-pick-mode)
3557 (push (or key last-command-event) unread-command-events)
3558 (setq keys (if gnus-xemacs
3559 (events-to-keys (read-key-sequence nil))
3560 (read-key-sequence nil)))))
3564 (if (or (member keys nosaves)
3565 (member keys nosave-but-article)
3566 (member keys nosave-in-article))
3568 (save-window-excursion
3569 (pop-to-buffer gnus-article-current-summary 'norecord)
3570 ;; We disable the pick minor mode commands.
3571 (let (gnus-pick-mode)
3572 (setq func (lookup-key (current-local-map) keys))))
3575 (unless (member keys nosave-in-article)
3576 (set-buffer gnus-article-current-summary))
3577 (call-interactively func)
3578 (setq new-sum-point (point)))
3579 (when (member keys nosave-but-article)
3580 (pop-to-buffer gnus-article-buffer 'norecord)))
3581 ;; These commands should restore window configuration.
3582 (let ((obuf (current-buffer))
3583 (owin (current-window-configuration))
3585 (summary gnus-article-current-summary)
3586 func in-buffer selected)
3587 (if not-restore-window
3588 (pop-to-buffer summary 'norecord)
3589 (switch-to-buffer summary 'norecord))
3590 (setq in-buffer (current-buffer))
3591 ;; We disable the pick minor mode commands.
3592 (if (setq func (let (gnus-pick-mode)
3593 (lookup-key (current-local-map) keys)))
3595 (call-interactively func)
3596 (setq new-sum-point (point)))
3598 (when (eq in-buffer (current-buffer))
3599 (setq selected (gnus-summary-select-article))
3601 (unless not-restore-window
3602 (set-window-configuration owin))
3603 (when (eq selected 'old)
3605 (set-window-start (get-buffer-window (current-buffer))
3607 (set-window-point (get-buffer-window (current-buffer))
3609 (let ((win (get-buffer-window gnus-article-current-summary)))
3611 (set-window-point win new-sum-point))))))))
3613 (defun gnus-article-hide (&optional arg force)
3614 "Hide all the gruft in the current article.
3615 This means that PGP stuff, signatures, cited text and (some)
3616 headers will be hidden.
3617 If given a prefix, show the hidden text instead."
3618 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3619 (gnus-article-hide-headers arg)
3620 (gnus-article-hide-list-identifiers arg)
3621 (gnus-article-hide-pgp arg)
3622 (gnus-article-hide-citation-maybe arg force)
3623 (gnus-article-hide-signature arg))
3625 (defun gnus-article-maybe-highlight ()
3626 "Do some article highlighting if article highlighting is requested."
3627 (when (gnus-visual-p 'article-highlight 'highlight)
3628 (gnus-article-highlight-some)))
3630 (defun gnus-check-group-server ()
3631 ;; Make sure the connection to the server is alive.
3632 (unless (gnus-server-opened
3633 (gnus-find-method-for-group gnus-newsgroup-name))
3634 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3635 (gnus-request-group gnus-newsgroup-name t)))
3637 (defun gnus-request-article-this-buffer (article group)
3638 "Get an article and insert it into this buffer."
3639 (let (do-update-line sparse-header)
3643 (gnus-kill-all-overlays)
3644 (setq group (or group gnus-newsgroup-name))
3646 ;; Using `gnus-request-article' directly will insert the article into
3647 ;; `nntp-server-buffer' - so we'll save some time by not having to
3648 ;; copy it from the server buffer into the article buffer.
3650 ;; We only request an article by message-id when we do not have the
3651 ;; headers for it, so we'll have to get those.
3652 (when (stringp article)
3653 (let ((gnus-override-method gnus-refer-article-method))
3654 (gnus-read-header article)))
3656 ;; If the article number is negative, that means that this article
3657 ;; doesn't belong in this newsgroup (possibly), so we find its
3658 ;; message-id and request it by id instead of number.
3659 (when (and (numberp article)
3661 (get-buffer gnus-summary-buffer)
3662 (gnus-buffer-exists-p gnus-summary-buffer))
3664 (set-buffer gnus-summary-buffer)
3665 (let ((header (gnus-summary-article-header article)))
3668 ((memq article gnus-newsgroup-sparse)
3669 ;; This is a sparse gap article.
3670 (setq do-update-line article)
3671 (setq article (mail-header-id header))
3672 (let ((gnus-override-method gnus-refer-article-method))
3673 (setq sparse-header (gnus-read-header article)))
3674 (setq gnus-newsgroup-sparse
3675 (delq article gnus-newsgroup-sparse)))
3677 ;; It's a real article.
3678 (setq article (mail-header-id header)))
3680 ;; It is an extracted pseudo-article.
3681 (setq article 'pseudo)
3682 (gnus-request-pseudo-article header))))
3684 (let ((method (gnus-find-method-for-group
3685 gnus-newsgroup-name)))
3686 (when (and (eq (car method) 'nneething)
3689 (file-name-as-directory
3690 (or (cadr (assq 'nneething-address method))
3692 (mail-header-subject header))))
3693 (when (file-directory-p dir)
3694 (setq article 'nneething)
3695 (gnus-group-enter-directory dir))))))))
3698 ;; Refuse to select canceled articles.
3699 ((and (numberp article)
3701 (get-buffer gnus-summary-buffer)
3702 (gnus-buffer-exists-p gnus-summary-buffer)
3703 (eq (cdr (save-excursion
3704 (set-buffer gnus-summary-buffer)
3705 (assq article gnus-newsgroup-reads)))
3706 gnus-canceled-mark))
3708 ;; We first check `gnus-original-article-buffer'.
3709 ((and (get-buffer gnus-original-article-buffer)
3712 (set-buffer gnus-original-article-buffer)
3713 (and (equal (car gnus-original-article) group)
3714 (eq (cdr gnus-original-article) article))))
3715 (insert-buffer-substring gnus-original-article-buffer)
3717 ;; Check the backlog.
3718 ((and gnus-keep-backlog
3719 (gnus-backlog-request-article group article (current-buffer)))
3721 ;; Check asynchronous pre-fetch.
3722 ((gnus-async-request-fetched-article group article (current-buffer))
3723 (gnus-async-prefetch-next group article gnus-summary-buffer)
3724 (when (and (numberp article) gnus-keep-backlog)
3725 (gnus-backlog-enter-article group article (current-buffer)))
3728 ((and gnus-use-cache
3730 (gnus-cache-request-article article group))
3732 ;; Get the article and put into the article buffer.
3733 ((or (stringp article) (numberp article))
3734 (let ((gnus-override-method
3735 (and (stringp article) gnus-refer-article-method))
3736 (buffer-read-only nil))
3738 (gnus-kill-all-overlays)
3739 (let ((gnus-newsgroup-name group))
3740 (gnus-check-group-server))
3741 (when (gnus-request-article article group (current-buffer))
3742 (when (numberp article)
3743 (gnus-async-prefetch-next group article gnus-summary-buffer)
3744 (when gnus-keep-backlog
3745 (gnus-backlog-enter-article
3746 group article (current-buffer))))
3751 ;; Associate this article with the current summary buffer.
3752 (setq gnus-article-current-summary gnus-summary-buffer)
3754 ;; Take the article from the original article buffer
3755 ;; and place it in the buffer it's supposed to be in.
3756 (when (and (get-buffer gnus-article-buffer)
3757 (equal (buffer-name (current-buffer))
3758 (buffer-name (get-buffer gnus-article-buffer))))
3760 (if (get-buffer gnus-original-article-buffer)
3761 (set-buffer gnus-original-article-buffer)
3762 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3763 (buffer-disable-undo)
3764 (setq major-mode 'gnus-original-article-mode)
3765 (setq buffer-read-only t))
3766 (let (buffer-read-only)
3768 (insert-buffer-substring gnus-article-buffer))
3769 (setq gnus-original-article (cons group article)))
3772 (run-hooks 'gnus-article-decode-hook)
3773 ;; Mark article as decoded or not.
3774 (setq gnus-article-decoded-p gnus-article-decode-hook))
3776 ;; Update sparse articles.
3777 (when (and do-update-line
3778 (or (numberp article)
3780 (let ((buf (current-buffer)))
3781 (set-buffer gnus-summary-buffer)
3782 (gnus-summary-update-article do-update-line sparse-header)
3783 (gnus-summary-goto-subject do-update-line nil t)
3784 (set-window-point (get-buffer-window (current-buffer) t)
3786 (set-buffer buf))))))
3792 (defcustom gnus-article-edit-mode-hook nil
3793 "Hook run in article edit mode buffers."
3794 :group 'gnus-article-various
3797 (defvar gnus-article-edit-done-function nil)
3799 (defvar gnus-article-edit-mode-map nil)
3801 ;; Should we be using derived.el for this?
3802 (unless gnus-article-edit-mode-map
3803 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3804 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3806 (gnus-define-keys gnus-article-edit-mode-map
3807 "\C-c\C-c" gnus-article-edit-done
3808 "\C-c\C-k" gnus-article-edit-exit)
3810 (gnus-define-keys (gnus-article-edit-wash-map
3811 "\C-c\C-w" gnus-article-edit-mode-map)
3812 "f" gnus-article-edit-full-stops))
3814 (defun gnus-article-edit-mode ()
3815 "Major mode for editing articles.
3816 This is an extended text-mode.
3818 \\{gnus-article-edit-mode-map}"
3820 (setq major-mode 'gnus-article-edit-mode)
3821 (setq mode-name "Article Edit")
3822 (use-local-map gnus-article-edit-mode-map)
3823 (make-local-variable 'gnus-article-edit-done-function)
3824 (make-local-variable 'gnus-prev-winconf)
3825 (setq buffer-read-only nil)
3826 (buffer-enable-undo)
3828 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3830 (defun gnus-article-edit (&optional force)
3831 "Edit the current article.
3832 This will have permanent effect only in mail groups.
3833 If FORCE is non-nil, allow editing of articles even in read-only
3836 (when (and (not force)
3837 (gnus-group-read-only-p))
3838 (error "The current newsgroup does not support article editing"))
3839 (gnus-article-date-original)
3840 (gnus-article-edit-article
3842 `(lambda (no-highlight)
3844 (gnus-summary-edit-article-done
3845 ,(or (mail-header-references gnus-current-headers) "")
3846 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3848 (defun gnus-article-edit-article (start-func exit-func)
3849 "Start editing the contents of the current article buffer."
3850 (let ((winconf (current-window-configuration)))
3851 (set-buffer gnus-article-buffer)
3852 (gnus-article-edit-mode)
3853 (funcall start-func)
3854 (gnus-configure-windows 'edit-article)
3855 (setq gnus-article-edit-done-function exit-func)
3856 (setq gnus-prev-winconf winconf)
3857 (gnus-message 6 "C-c C-c to end edits")))
3859 (defun gnus-article-edit-done (&optional arg)
3860 "Update the article edits and exit."
3865 (when (article-goto-body)
3866 (let ((lines (count-lines (point) (point-max)))
3867 (length (- (point-max) (point)))
3868 (case-fold-search t)
3869 (body (copy-marker (point))))
3870 (goto-char (point-min))
3871 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3872 (delete-region (match-beginning 1) (match-end 1))
3873 (insert (number-to-string length)))
3874 (goto-char (point-min))
3875 (when (re-search-forward
3876 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3877 (delete-region (match-beginning 1) (match-end 1))
3878 (insert (number-to-string length)))
3879 (goto-char (point-min))
3880 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3881 (delete-region (match-beginning 1) (match-end 1))
3882 (insert (number-to-string lines)))))))
3883 (let ((func gnus-article-edit-done-function)
3884 (buf (current-buffer))
3885 (start (window-start)))
3886 (gnus-article-edit-exit)
3889 (let ((buffer-read-only nil))
3891 ;; The cache and backlog have to be flushed somewhat.
3892 (when gnus-keep-backlog
3893 (gnus-backlog-remove-article
3894 (car gnus-article-current) (cdr gnus-article-current)))
3895 ;; Flush original article as well.
3897 (when (get-buffer gnus-original-article-buffer)
3898 (set-buffer gnus-original-article-buffer)
3899 (setq gnus-original-article nil)))
3900 (when gnus-use-cache
3901 (gnus-cache-update-article
3902 (car gnus-article-current) (cdr gnus-article-current))))
3904 (set-window-start (get-buffer-window buf) start)
3905 (set-window-point (get-buffer-window buf) (point))))
3907 (defun gnus-article-edit-exit ()
3908 "Exit the article editing without updating."
3910 ;; We remove all text props from the article buffer.
3911 (let ((buf (format "%s" (buffer-string)))
3912 (curbuf (current-buffer))
3914 (window-start (window-start)))
3917 (let ((winconf gnus-prev-winconf))
3919 (set-window-configuration winconf)
3920 ;; Tippy-toe some to make sure that point remains where it was.
3921 (save-current-buffer
3923 (set-window-start (get-buffer-window (current-buffer)) window-start)
3926 (defun gnus-article-edit-full-stops ()
3927 "Interactively repair spacing at end of sentences."
3930 (goto-char (point-min))
3931 (search-forward-regexp "^$" nil t)
3932 (let ((case-fold-search nil))
3933 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3936 ;;; Article highlights
3939 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3941 ;;; Internal Variables:
3943 (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\\)"
3944 "Regular expression that matches URLs."
3945 :group 'gnus-article-buttons
3948 (defcustom gnus-button-alist
3949 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3950 0 t gnus-button-message-id 2)
3951 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3952 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3954 gnus-button-fetch-group 4)
3955 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3956 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3957 t gnus-button-message-id 3)
3958 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3959 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3960 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3961 ;; This is how URLs _should_ be embedded in text...
3962 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3964 (,gnus-button-url-regexp 0 t browse-url 0))
3965 "*Alist of regexps matching buttons in article bodies.
3967 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3968 REGEXP: is the string matching text around the button,
3969 BUTTON: is the number of the regexp grouping actually matching the button,
3970 FORM: is a lisp expression which must eval to true for the button to
3972 CALLBACK: is the function to call when the user push this button, and each
3973 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3975 CALLBACK can also be a variable, in that case the value of that
3976 variable it the real callback function."
3977 :group 'gnus-article-buttons
3978 :type '(repeat (list regexp
3979 (integer :tag "Button")
3981 (function :tag "Callback")
3984 (integer :tag "Regexp group")))))
3986 (defcustom gnus-header-button-alist
3987 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3988 0 t gnus-button-message-id 0)
3989 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3990 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3991 0 t gnus-button-mailto 0)
3992 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
3993 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
3994 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
3995 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3996 gnus-button-message-id 3))
3997 "*Alist of headers and regexps to match buttons in article heads.
3999 This alist is very similar to `gnus-button-alist', except that each
4000 alist has an additional HEADER element first in each entry:
4002 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4004 HEADER is a regexp to match a header. For a fuller explanation, see
4005 `gnus-button-alist'."
4006 :group 'gnus-article-buttons
4007 :group 'gnus-article-headers
4008 :type '(repeat (list (regexp :tag "Header")
4010 (integer :tag "Button")
4012 (function :tag "Callback")
4015 (integer :tag "Regexp group")))))
4017 (defvar gnus-button-regexp nil)
4018 (defvar gnus-button-marker-list nil)
4019 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4021 (defvar gnus-button-last nil)
4022 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4026 (defun gnus-article-push-button (event)
4027 "Check text under the mouse pointer for a callback function.
4028 If the text under the mouse pointer has a `gnus-callback' property,
4029 call it with the value of the `gnus-data' text property."
4031 (set-buffer (window-buffer (posn-window (event-start event))))
4032 (let* ((pos (posn-point (event-start event)))
4033 (data (get-text-property pos 'gnus-data))
4034 (fun (get-text-property pos 'gnus-callback)))
4037 (funcall fun data))))
4039 (defun gnus-article-press-button ()
4040 "Check text at point for a callback function.
4041 If the text at point has a `gnus-callback' property,
4042 call it with the value of the `gnus-data' text property."
4044 (let* ((data (get-text-property (point) 'gnus-data))
4045 (fun (get-text-property (point) 'gnus-callback)))
4047 (funcall fun data))))
4049 (defun gnus-article-highlight (&optional force)
4050 "Highlight current article.
4051 This function calls `gnus-article-highlight-headers',
4052 `gnus-article-highlight-citation',
4053 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4054 do the highlighting. See the documentation for those functions."
4055 (interactive (list 'force))
4056 (gnus-article-highlight-headers)
4057 (gnus-article-highlight-citation force)
4058 (gnus-article-highlight-signature)
4059 (gnus-article-add-buttons force)
4060 (gnus-article-add-buttons-to-head))
4062 (defun gnus-article-highlight-some (&optional force)
4063 "Highlight current article.
4064 This function calls `gnus-article-highlight-headers',
4065 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4066 do the highlighting. See the documentation for those functions."
4067 (interactive (list 'force))
4068 (gnus-article-highlight-headers)
4069 (gnus-article-highlight-signature)
4070 (gnus-article-add-buttons))
4072 (defun gnus-article-highlight-headers ()
4073 "Highlight article headers as specified by `gnus-header-face-alist'."
4076 (set-buffer gnus-article-buffer)
4078 (let ((alist gnus-header-face-alist)
4079 (buffer-read-only nil)
4080 (case-fold-search t)
4081 (inhibit-point-motion-hooks t)
4082 entry regexp header-face field-face from hpoints fpoints)
4083 (article-narrow-to-head)
4084 (while (setq entry (pop alist))
4085 (goto-char (point-min))
4086 (setq regexp (concat "^\\("
4087 (if (string-equal "" (nth 0 entry))
4091 header-face (nth 1 entry)
4092 field-face (nth 2 entry))
4093 (while (and (re-search-forward regexp nil t)
4097 (unless (search-forward ":" nil t)
4099 (when (and header-face
4100 (not (memq (point) hpoints)))
4101 (push (point) hpoints)
4102 (gnus-put-text-property from (point) 'face header-face))
4103 (when (and field-face
4104 (not (memq (setq from (point)) fpoints)))
4106 (if (re-search-forward "^[^ \t]" nil t)
4108 (goto-char (point-max)))
4109 (gnus-put-text-property from (point) 'face field-face))))))))
4111 (defun gnus-article-highlight-signature ()
4112 "Highlight the signature in an article.
4113 It does this by highlighting everything after
4114 `gnus-signature-separator' using `gnus-signature-face'."
4117 (set-buffer gnus-article-buffer)
4118 (let ((buffer-read-only nil)
4119 (inhibit-point-motion-hooks t))
4121 (when (and gnus-signature-face
4122 (gnus-article-narrow-to-signature))
4123 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4124 'face gnus-signature-face)
4126 (gnus-article-search-signature)
4127 (let ((start (match-beginning 0))
4128 (end (set-marker (make-marker) (1+ (match-end 0)))))
4129 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4132 (defun gnus-button-in-region-p (b e prop)
4133 "Say whether PROP exists in the region."
4134 (text-property-not-all b e prop nil))
4136 (defun gnus-article-add-buttons (&optional force)
4137 "Find external references in the article and make buttons of them.
4138 \"External references\" are things like Message-IDs and URLs, as
4139 specified by `gnus-button-alist'."
4140 (interactive (list 'force))
4142 (set-buffer gnus-article-buffer)
4143 (let ((buffer-read-only nil)
4144 (inhibit-point-motion-hooks t)
4145 (case-fold-search t)
4146 (alist gnus-button-alist)
4148 ;; Remove all old markers.
4149 (let (marker entry new-list)
4150 (while (setq marker (pop gnus-button-marker-list))
4151 (if (or (< marker (point-min)) (>= marker (point-max)))
4152 (push marker new-list)
4154 (when (setq entry (gnus-button-entry))
4155 (put-text-property (match-beginning (nth 1 entry))
4156 (match-end (nth 1 entry))
4157 'gnus-callback nil))
4158 (set-marker marker nil)))
4159 (setq gnus-button-marker-list new-list))
4160 ;; We skip the headers.
4163 (while (setq entry (pop alist))
4164 (setq regexp (car entry))
4166 (while (re-search-forward regexp nil t)
4167 (let* ((start (and entry (match-beginning (nth 1 entry))))
4168 (end (and entry (match-end (nth 1 entry))))
4169 (from (match-beginning 0)))
4170 (when (and (or (eq t (nth 2 entry))
4171 (eval (nth 2 entry)))
4172 (not (gnus-button-in-region-p
4173 start end 'gnus-callback)))
4174 ;; That optional form returned non-nil, so we add the
4176 (gnus-article-add-button
4177 start end 'gnus-button-push
4178 (car (push (set-marker (make-marker) from)
4179 gnus-button-marker-list))))))))))
4181 ;; Add buttons to the head of an article.
4182 (defun gnus-article-add-buttons-to-head ()
4183 "Add buttons to the head of the article."
4186 (set-buffer gnus-article-buffer)
4188 (let ((buffer-read-only nil)
4189 (inhibit-point-motion-hooks t)
4190 (case-fold-search t)
4191 (alist gnus-header-button-alist)
4193 (article-narrow-to-head)
4195 ;; Each alist entry.
4196 (setq entry (car alist)
4198 (goto-char (point-min))
4199 (while (re-search-forward (car entry) nil t)
4200 ;; Each header matching the entry.
4201 (setq beg (match-beginning 0))
4202 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4203 (match-beginning 0))
4206 (while (re-search-forward (nth 1 entry) end t)
4207 ;; Each match within a header.
4208 (let* ((entry (cdr entry))
4209 (start (match-beginning (nth 1 entry)))
4210 (end (match-end (nth 1 entry)))
4211 (form (nth 2 entry)))
4212 (goto-char (match-end 0))
4214 (gnus-article-add-button
4215 start end (nth 3 entry)
4216 (buffer-substring (match-beginning (nth 4 entry))
4217 (match-end (nth 4 entry)))))))
4218 (goto-char end)))))))
4220 ;;; External functions:
4222 (defun gnus-article-add-button (from to fun &optional data)
4223 "Create a button between FROM and TO with callback FUN and data DATA."
4224 (when gnus-article-button-face
4225 (gnus-overlay-put (gnus-make-overlay from to)
4226 'face gnus-article-button-face))
4227 (gnus-add-text-properties
4229 (nconc (and gnus-article-mouse-face
4230 (list gnus-mouse-face-prop gnus-article-mouse-face))
4231 (list 'gnus-callback fun)
4232 (and data (list 'gnus-data data))))
4233 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4234 :button-keymap gnus-widget-button-keymap))
4236 ;;; Internal functions:
4238 (defun gnus-article-set-globals ()
4240 (set-buffer gnus-summary-buffer)
4241 (gnus-set-global-variables)))
4243 (defun gnus-signature-toggle (end)
4245 (set-buffer gnus-article-buffer)
4246 (let ((buffer-read-only nil)
4247 (inhibit-point-motion-hooks t))
4248 (if (get-text-property end 'invisible)
4249 (gnus-article-unhide-text end (point-max))
4250 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4252 (defun gnus-button-entry ()
4253 ;; Return the first entry in `gnus-button-alist' matching this place.
4254 (let ((alist gnus-button-alist)
4257 (setq entry (pop alist))
4258 (if (looking-at (car entry))
4263 (defun gnus-button-push (marker)
4264 ;; Push button starting at MARKER.
4267 (let* ((entry (gnus-button-entry))
4268 (inhibit-point-motion-hooks t)
4270 (args (mapcar (lambda (group)
4271 (let ((string (match-string group)))
4272 (gnus-set-text-properties
4273 0 (length string) nil string)
4280 (fboundp (symbol-value fun)))
4281 (apply (symbol-value fun) args))
4283 (gnus-message 1 "You must define `%S' to use this button"
4284 (cons fun args)))))))
4286 (defun gnus-button-message-id (message-id)
4289 (set-buffer gnus-summary-buffer)
4290 (gnus-summary-refer-article message-id)))
4292 (defun gnus-button-fetch-group (address)
4293 "Fetch GROUP specified by ADDRESS."
4294 (if (not (string-match "[:/]" address))
4295 ;; This is just a simple group url.
4296 (gnus-group-read-ephemeral-group address gnus-select-method)
4297 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4299 (error "Can't parse %s" address)
4300 (gnus-group-read-ephemeral-group
4301 (match-string 4 address)
4302 `(nntp ,(match-string 1 address)
4303 (nntp-address ,(match-string 1 address))
4304 (nntp-port-number ,(if (match-end 3)
4305 (match-string 3 address)
4308 (defun gnus-url-parse-query-string (query &optional downcase)
4309 (let (retval pairs cur key val)
4310 (setq pairs (split-string query "&"))
4312 (setq cur (car pairs)
4314 (if (not (string-match "=" cur))
4316 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4317 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4319 (setq key (downcase key)))
4320 (setq cur (assoc key retval))
4322 (setcdr cur (cons val (cdr cur)))
4323 (setq retval (cons (list key val) retval)))))
4326 (defun gnus-url-unhex (x)
4333 (defun gnus-url-unhex-string (str &optional allow-newlines)
4334 "Remove %XXX embedded spaces, etc in a url.
4335 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4336 decoding of carriage returns and line feeds in the string, which is normally
4337 forbidden in URL encoding."
4338 (setq str (or str ""))
4340 (case-fold-search t))
4341 (while (string-match "%[0-9a-f][0-9a-f]" str)
4342 (let* ((start (match-beginning 0))
4343 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4345 (gnus-url-unhex (elt str (+ start 2))))))
4347 tmp (substring str 0 start)
4350 (char-to-string code))
4351 ((or (= code ?\n) (= code ?\r))
4353 (t (char-to-string code))))
4354 str (substring str (match-end 0)))))
4355 (setq tmp (concat tmp str))
4358 (defun gnus-url-mailto (url)
4359 ;; Send mail to someone
4360 (when (string-match "mailto:/*\\(.*\\)" url)
4361 (setq url (substring url (match-beginning 1) nil)))
4362 (let (to args subject func)
4363 (if (string-match (regexp-quote "?") url)
4364 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4365 args (gnus-url-parse-query-string
4366 (substring url (match-end 0) nil) t))
4367 (setq to (gnus-url-unhex-string url)))
4368 (setq args (cons (list "to" to) args)
4369 subject (cdr-safe (assoc "subject" args)))
4372 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4375 (message-position-on-field (caar args)))
4376 (insert (mapconcat 'identity (cdar args) ", "))
4377 (setq args (cdr args)))
4380 (message-goto-subject))))
4382 (defun gnus-button-mailto (address)
4384 (set-buffer (gnus-copy-article-buffer))
4385 (message-reply address))
4387 (defun gnus-button-reply (address)
4388 ;; Reply to ADDRESS.
4389 (message-reply address))
4391 (defun gnus-button-embedded-url (address)
4393 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4394 (if (listp browse-url-browser-function)
4395 (browse-url (gnus-strip-whitespace address))
4396 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4398 ;;; Next/prev buttons in the article buffer.
4400 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4401 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4403 (defvar gnus-prev-page-map nil)
4404 (unless gnus-prev-page-map
4405 (setq gnus-prev-page-map (make-sparse-keymap))
4406 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4407 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4409 (defun gnus-insert-prev-page-button ()
4410 (let ((buffer-read-only nil))
4412 gnus-prev-page-line-format nil
4413 `(gnus-prev t local-map ,gnus-prev-page-map
4414 gnus-callback gnus-article-button-prev-page
4415 article-type annotation))))
4417 (defvar gnus-next-page-map nil)
4418 (unless gnus-next-page-map
4419 (setq gnus-next-page-map (make-keymap))
4420 (suppress-keymap gnus-prev-page-map)
4421 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4422 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4424 (defun gnus-button-next-page ()
4425 "Go to the next page."
4427 (let ((win (selected-window)))
4428 (select-window (get-buffer-window gnus-article-buffer t))
4429 (gnus-article-next-page)
4430 (select-window win)))
4432 (defun gnus-button-prev-page ()
4433 "Go to the prev page."
4435 (let ((win (selected-window)))
4436 (select-window (get-buffer-window gnus-article-buffer t))
4437 (gnus-article-prev-page)
4438 (select-window win)))
4440 (defun gnus-insert-next-page-button ()
4441 (let ((buffer-read-only nil))
4442 (gnus-eval-format gnus-next-page-line-format nil
4444 t local-map ,gnus-next-page-map
4445 gnus-callback gnus-article-button-next-page
4446 article-type annotation))))
4448 (defun gnus-article-button-next-page (arg)
4449 "Go to the next page."
4451 (let ((win (selected-window)))
4452 (select-window (get-buffer-window gnus-article-buffer t))
4453 (gnus-article-next-page)
4454 (select-window win)))
4456 (defun gnus-article-button-prev-page (arg)
4457 "Go to the prev page."
4459 (let ((win (selected-window)))
4460 (select-window (get-buffer-window gnus-article-buffer t))
4461 (gnus-article-prev-page)
4462 (select-window win)))
4464 (defvar gnus-decode-header-methods
4465 '(mail-decode-encoded-word-region)
4466 "List of methods used to decode headers.
4468 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4469 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4470 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4471 whose names match REGEXP.
4474 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4475 mail-decode-encoded-word-region
4476 (\"chinese\" . rfc1843-decode-region))
4479 (defvar gnus-decode-header-methods-cache nil)
4481 (defun gnus-multi-decode-header (start end)
4482 "Apply the functions from `gnus-encoded-word-methods' that match."
4483 (unless (and gnus-decode-header-methods-cache
4484 (eq gnus-newsgroup-name
4485 (car gnus-decode-header-methods-cache)))
4486 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4489 (nconc gnus-decode-header-methods-cache (list x))
4490 (if (and gnus-newsgroup-name
4491 (string-match (car x) gnus-newsgroup-name))
4492 (nconc gnus-decode-header-methods-cache
4494 gnus-decode-header-methods))
4495 (let ((xlist gnus-decode-header-methods-cache))
4498 (narrow-to-region start end)
4500 (funcall (pop xlist) (point-min) (point-max))))))
4503 ;;; Treatment top-level handling.
4506 (defun gnus-treat-article (condition &optional part-number total-parts type)
4507 (let ((length (- (point-max) (point-min)))
4508 (alist gnus-treatment-function-alist)
4509 (article-goto-body-goes-to-point-min-p t)
4513 (let ((list gnus-article-treat-types))
4515 (when (string-match (pop list) type)
4516 (throw 'found t)))))))
4517 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4519 (gnus-run-hooks 'gnus-part-display-hook)
4520 (while (setq elem (pop alist))
4521 (setq val (symbol-value (car elem)))
4522 (when (and (or (consp val)
4524 (gnus-treat-predicate val)
4525 (or (not (get (car elem) 'highlight))
4528 (funcall (cadr elem)))))))
4530 ;; Dynamic variables.
4531 (defvar part-number)
4532 (defvar total-parts)
4536 (defun gnus-treat-predicate (val)
4541 (stringp (car val)))
4542 (apply 'gnus-or (mapcar `(lambda (s)
4543 (string-match s ,(or gnus-newsgroup-name "")))
4546 (let ((pred (pop val)))
4549 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4551 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4553 (not (gnus-treat-predicate (car val))))
4555 (equal (car val) type))
4557 (error "%S is not a valid predicate" pred)))))
4565 (eq part-number total-parts))
4569 (error "%S is not a valid value" val))))
4575 (run-hooks 'gnus-art-load-hook)
4577 ;;; gnus-art.el ends here