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)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%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
620 ;;; The treatment variables
623 (defvar gnus-part-display-hook nil
624 "Hook called on parts that are to receive treatment.")
626 (defvar gnus-article-treat-custom
627 '(choice (const :tag "Off" nil)
629 (const :tag "Header" head)
630 (const :tag "Last" last)
631 (integer :tag "Less")
632 (repeat :tag "Groups" regexp)
633 (sexp :tag "Predicate")))
635 (defvar gnus-article-treat-head-custom
636 '(choice (const :tag "Off" nil)
637 (const :tag "Header" head)))
639 (defvar gnus-article-treat-types '("text/plain")
642 (defvar gnus-inhibit-treatment nil
643 "Whether to inhibit treatment.")
645 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
646 "Highlight the signature.
647 Valid values are nil, t, `head', `last', an integer or a predicate.
648 See the manual for details."
649 :group 'gnus-article-treat
650 :type gnus-article-treat-custom)
651 (put 'gnus-treat-highlight-signature 'highlight t)
653 (defcustom gnus-treat-buttonize t
655 Valid values are nil, t, `head', `last', an integer or a predicate.
656 See the manual for details."
657 :group 'gnus-article-treat
658 :type gnus-article-treat-custom)
659 (put 'gnus-treat-buttonize 'highlight t)
661 (defcustom gnus-treat-buttonize-head 'head
662 "Add buttons to the head.
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-head-custom)
667 (put 'gnus-treat-buttonize-head 'highlight t)
669 (defcustom gnus-treat-emphasize t
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-emphasize 'highlight t)
677 (defcustom gnus-treat-strip-cr nil
678 "Remove carriage returns.
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-custom)
684 (defcustom gnus-treat-hide-headers 'head
686 Valid values are nil, t, `head', `last', an integer or a predicate.
687 See the manual for details."
688 :group 'gnus-article-treat
689 :type gnus-article-treat-head-custom)
691 (defcustom gnus-treat-hide-boring-headers nil
692 "Hide boring headers.
693 Valid values are nil, t, `head', `last', an integer or a predicate.
694 See the manual for details."
695 :group 'gnus-article-treat
696 :type gnus-article-treat-head-custom)
698 (defcustom gnus-treat-hide-signature nil
700 Valid values are nil, t, `head', `last', an integer or a predicate.
701 See the manual for details."
702 :group 'gnus-article-treat
703 :type gnus-article-treat-custom)
705 (defcustom gnus-treat-fill-article nil
707 Valid values are nil, t, `head', `last', an integer or a predicate.
708 See the manual for details."
709 :group 'gnus-article-treat
710 :type gnus-article-treat-custom)
712 (defcustom gnus-treat-hide-citation nil
714 Valid values are nil, t, `head', `last', an integer or a predicate.
715 See the manual for details."
716 :group 'gnus-article-treat
717 :type gnus-article-treat-custom)
719 (defcustom gnus-treat-strip-list-identifiers 'head
720 "Strip list identifiers from `gnus-list-identifiers`.
721 Valid values are nil, t, `head', `last', an integer or a predicate.
722 See the manual for details."
723 :group 'gnus-article-treat
724 :type gnus-article-treat-custom)
726 (defcustom gnus-treat-strip-pgp t
727 "Strip PGP signatures.
728 Valid values are nil, t, `head', `last', an integer or a predicate.
729 See the manual for details."
730 :group 'gnus-article-treat
731 :type gnus-article-treat-custom)
733 (defcustom gnus-treat-strip-pem nil
734 "Strip PEM signatures.
735 Valid values are nil, t, `head', `last', an integer or a predicate.
736 See the manual for details."
737 :group 'gnus-article-treat
738 :type gnus-article-treat-custom)
740 (defcustom gnus-treat-strip-banner t
741 "Strip banners from articles.
742 The banner to be stripped is specified in the `banner' group parameter.
743 Valid values are nil, t, `head', `last', an integer or a predicate.
744 See the manual for details."
745 :group 'gnus-article-treat
746 :type gnus-article-treat-custom)
748 (defcustom gnus-treat-highlight-headers 'head
749 "Highlight the headers.
750 Valid values are nil, t, `head', `last', an integer or a predicate.
751 See the manual for details."
752 :group 'gnus-article-treat
753 :type gnus-article-treat-head-custom)
754 (put 'gnus-treat-highlight-headers 'highlight t)
756 (defcustom gnus-treat-highlight-citation t
757 "Highlight cited text.
758 Valid values are nil, t, `head', `last', an integer or a predicate.
759 See the manual for details."
760 :group 'gnus-article-treat
761 :type gnus-article-treat-custom)
762 (put 'gnus-treat-highlight-citation 'highlight t)
764 (defcustom gnus-treat-date-ut nil
765 "Display the Date in UT (GMT).
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)
771 (defcustom gnus-treat-date-local nil
772 "Display the Date in the local timezone.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-head-custom)
778 (defcustom gnus-treat-date-lapsed nil
779 "Display the Date header in a way that says how much time has elapsed.
780 Valid values are nil, t, `head', `last', an integer or a predicate.
781 See the manual for details."
782 :group 'gnus-article-treat
783 :type gnus-article-treat-head-custom)
785 (defcustom gnus-treat-date-original nil
786 "Display the date in the original timezone.
787 Valid values are nil, t, `head', `last', an integer or a predicate.
788 See the manual for details."
789 :group 'gnus-article-treat
790 :type gnus-article-treat-head-custom)
792 (defcustom gnus-treat-date-iso8601 nil
793 "Display the date in the ISO8601 format.
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-head-custom)
799 (defcustom gnus-treat-date-user-defined nil
800 "Display the date in a user-defined format.
801 The format is defined by the `gnus-article-time-format' variable.
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-head-custom)
807 (defcustom gnus-treat-strip-headers-in-body t
808 "Strip the X-No-Archive header line from the beginning of the body.
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-custom)
814 (defcustom gnus-treat-strip-trailing-blank-lines nil
815 "Strip trailing blank lines.
816 Valid values are nil, t, `head', `last', an integer or a predicate.
817 See the manual for details."
818 :group 'gnus-article-treat
819 :type gnus-article-treat-custom)
821 (defcustom gnus-treat-strip-leading-blank-lines nil
822 "Strip leading blank lines.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-custom)
828 (defcustom gnus-treat-strip-multiple-blank-lines nil
829 "Strip multiple blank lines.
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-custom)
835 (defcustom gnus-treat-overstrike t
836 "Treat overstrike highlighting.
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-custom)
841 (put 'gnus-treat-overstrike 'highlight t)
843 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
845 "Display X-Face headers.
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-head-custom)
850 (put 'gnus-treat-display-xface 'highlight t)
852 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
856 Valid values are nil, t, `head', `last', an integer or a predicate.
857 See the manual for details."
858 :group 'gnus-article-treat
859 :type gnus-article-treat-custom)
860 (put 'gnus-treat-display-smileys 'highlight t)
862 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
864 Valid values are nil, t, `head', `last', an integer or a predicate.
865 See the manual for details."
866 :group 'gnus-article-treat
867 :type gnus-article-treat-head-custom)
868 (put 'gnus-treat-display-picons 'highlight t)
870 (defcustom gnus-treat-capitalize-sentences nil
871 "Capitalize sentence-starting words.
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)
877 (defcustom gnus-treat-fill-long-lines nil
879 Valid values are nil, t, `head', `last', an integer or a predicate.
880 See the manual for details."
881 :group 'gnus-article-treat
882 :type gnus-article-treat-custom)
884 (defcustom gnus-treat-play-sounds nil
886 Valid values are nil, t, `head', `last', an integer or a predicate.
887 See the manual for details."
888 :group 'gnus-article-treat
889 :type gnus-article-treat-custom)
891 (defcustom gnus-treat-translate nil
892 "Translate articles from one language to another.
893 Valid values are nil, t, `head', `last', an integer or a predicate.
894 See the manual for details."
895 :group 'gnus-article-treat
896 :type gnus-article-treat-custom)
898 ;;; Internal variables
900 (defvar article-goto-body-goes-to-point-min-p nil)
901 (defvar gnus-article-wash-types nil)
902 (defvar gnus-article-emphasis-alist nil)
904 (defvar gnus-article-mime-handle-alist-1 nil)
905 (defvar gnus-treatment-function-alist
906 '((gnus-treat-strip-banner gnus-article-strip-banner)
907 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
908 (gnus-treat-highlight-signature gnus-article-highlight-signature)
909 (gnus-treat-buttonize gnus-article-add-buttons)
910 (gnus-treat-fill-article gnus-article-fill-cited-article)
911 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
912 (gnus-treat-strip-cr gnus-article-remove-cr)
913 (gnus-treat-emphasize gnus-article-emphasize)
914 (gnus-treat-display-xface gnus-article-display-x-face)
915 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
916 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
917 (gnus-treat-hide-signature gnus-article-hide-signature)
918 (gnus-treat-hide-citation gnus-article-hide-citation)
919 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
920 (gnus-treat-strip-pgp gnus-article-hide-pgp)
921 (gnus-treat-strip-pem gnus-article-hide-pem)
922 (gnus-treat-highlight-headers gnus-article-highlight-headers)
923 (gnus-treat-highlight-citation gnus-article-highlight-citation)
924 (gnus-treat-highlight-signature gnus-article-highlight-signature)
925 (gnus-treat-date-ut gnus-article-date-ut)
926 (gnus-treat-date-local gnus-article-date-local)
927 (gnus-treat-date-lapsed gnus-article-date-lapsed)
928 (gnus-treat-date-original gnus-article-date-original)
929 (gnus-treat-date-user-defined gnus-article-date-user)
930 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
931 (gnus-treat-strip-trailing-blank-lines
932 gnus-article-remove-trailing-blank-lines)
933 (gnus-treat-strip-leading-blank-lines
934 gnus-article-strip-leading-blank-lines)
935 (gnus-treat-strip-multiple-blank-lines
936 gnus-article-strip-multiple-blank-lines)
937 (gnus-treat-overstrike gnus-article-treat-overstrike)
938 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
939 (gnus-treat-display-smileys gnus-smiley-display)
940 (gnus-treat-display-picons gnus-article-display-picons)
941 (gnus-treat-play-sounds gnus-earcon-display)))
943 (defvar gnus-article-mime-handle-alist nil)
944 (defvar article-lapsed-timer nil)
945 (defvar gnus-article-current-summary nil)
947 (defvar gnus-article-mode-syntax-table
948 (let ((table (copy-syntax-table text-mode-syntax-table)))
949 (modify-syntax-entry ?- "w" table)
950 (modify-syntax-entry ?> ")" table)
951 (modify-syntax-entry ?< "(" table)
953 "Syntax table used in article mode buffers.
954 Initialized from `text-mode-syntax-table.")
956 (defvar gnus-save-article-buffer nil)
958 (defvar gnus-article-mode-line-format-alist
959 (nconc '((?w (gnus-article-wash-status) ?s)
960 (?m (gnus-article-mime-part-status) ?s))
961 gnus-summary-mode-line-format-alist))
963 (defvar gnus-number-of-articles-to-be-saved nil)
965 (defvar gnus-inhibit-hiding nil)
967 (defsubst gnus-article-hide-text (b e props)
968 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
969 (add-text-properties b e props)
970 (when (memq 'intangible props)
972 (max (1- b) (point-min))
973 b 'intangible (cddr (memq 'intangible props)))))
974 (defsubst gnus-article-unhide-text (b e)
975 "Remove hidden text properties from region between B and E."
976 (remove-text-properties b e gnus-hidden-properties)
977 (when (memq 'intangible gnus-hidden-properties)
978 (put-text-property (max (1- b) (point-min))
981 (defun gnus-article-hide-text-type (b e type)
982 "Hide text of TYPE between B and E."
983 (push type gnus-article-wash-types)
984 (gnus-article-hide-text
985 b e (cons 'article-type (cons type gnus-hidden-properties))))
987 (defun gnus-article-unhide-text-type (b e type)
988 "Unhide text of TYPE between B and E."
989 (setq gnus-article-wash-types
990 (delq type gnus-article-wash-types))
991 (remove-text-properties
992 b e (cons 'article-type (cons type gnus-hidden-properties)))
993 (when (memq 'intangible gnus-hidden-properties)
994 (put-text-property (max (1- b) (point-min))
997 (defun gnus-article-hide-text-of-type (type)
998 "Hide text of TYPE in the current buffer."
1000 (let ((b (point-min))
1002 (while (setq b (text-property-any b e 'article-type type))
1003 (add-text-properties b (incf b) gnus-hidden-properties)))))
1005 (defun gnus-article-delete-text-of-type (type)
1006 "Delete text of TYPE in the current buffer."
1008 (let ((b (point-min)))
1009 (while (setq b (text-property-any b (point-max) 'article-type type))
1011 b (or (text-property-not-all b (point-max) 'article-type type)
1014 (defun gnus-article-delete-invisible-text ()
1015 "Delete all invisible text in the current buffer."
1017 (let ((b (point-min)))
1018 (while (setq b (text-property-any b (point-max) 'invisible t))
1020 b (or (text-property-not-all b (point-max) 'invisible t)
1023 (defun gnus-article-text-type-exists-p (type)
1024 "Say whether any text of type TYPE exists in the buffer."
1025 (text-property-any (point-min) (point-max) 'article-type type))
1027 (defsubst gnus-article-header-rank ()
1028 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1029 (let ((list gnus-sorted-header-list)
1032 (when (looking-at (car list))
1034 (setq list (cdr list))
1038 (defun article-hide-headers (&optional arg delete)
1039 "Hide unwanted headers and possibly sort them as well."
1041 ;; This function might be inhibited.
1042 (unless gnus-inhibit-hiding
1045 (let ((buffer-read-only nil)
1046 (case-fold-search t)
1047 (max (1+ (length gnus-sorted-header-list)))
1048 (ignored (when (not gnus-visible-headers)
1049 (cond ((stringp gnus-ignored-headers)
1050 gnus-ignored-headers)
1051 ((listp gnus-ignored-headers)
1052 (mapconcat 'identity gnus-ignored-headers
1055 (cond ((stringp gnus-visible-headers)
1056 gnus-visible-headers)
1057 ((and gnus-visible-headers
1058 (listp gnus-visible-headers))
1059 (mapconcat 'identity gnus-visible-headers "\\|"))))
1060 (inhibit-point-motion-hooks t)
1062 ;; First we narrow to just the headers.
1063 (article-narrow-to-head)
1064 ;; Hide any "From " lines at the beginning of (mail) articles.
1065 (while (looking-at "From ")
1068 (delete-region (point-min) (point)))
1069 ;; Then treat the rest of the header lines.
1070 ;; Then we use the two regular expressions
1071 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1072 ;; select which header lines is to remain visible in the
1074 (while (re-search-forward "^[^ \t]*:" nil t)
1076 ;; Mark the rank of the header.
1078 (point) (1+ (point)) 'message-rank
1079 (if (or (and visible (looking-at visible))
1081 (not (looking-at ignored))))
1082 (gnus-article-header-rank)
1085 (message-sort-headers-1)
1086 (when (setq beg (text-property-any
1087 (point-min) (point-max) 'message-rank (+ 2 max)))
1088 ;; We delete the unwanted headers.
1089 (push 'headers gnus-article-wash-types)
1090 (add-text-properties (point-min) (+ 5 (point-min))
1091 '(article-type headers dummy-invisible t))
1092 (delete-region beg (point-max))))))))
1094 (defun article-hide-boring-headers (&optional arg)
1095 "Toggle hiding of headers that aren't very interesting.
1096 If given a negative prefix, always show; if given a positive prefix,
1098 (interactive (gnus-article-hidden-arg))
1099 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1100 (not gnus-show-all-headers))
1103 (let ((buffer-read-only nil)
1104 (list gnus-boring-article-headers)
1105 (inhibit-point-motion-hooks t)
1107 (article-narrow-to-head)
1109 (setq elem (pop list))
1110 (goto-char (point-min))
1112 ;; Hide empty headers.
1114 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1116 (gnus-article-hide-text-type
1117 (progn (beginning-of-line) (point))
1120 (if (re-search-forward "^[^ \t]" nil t)
1124 ;; Hide boring Newsgroups header.
1125 ((eq elem 'newsgroups)
1126 (when (equal (gnus-fetch-field "newsgroups")
1127 (gnus-group-real-name
1128 (if (boundp 'gnus-newsgroup-name)
1131 (gnus-article-hide-header "newsgroups")))
1132 ((eq elem 'followup-to)
1133 (when (equal (message-fetch-field "followup-to")
1134 (message-fetch-field "newsgroups"))
1135 (gnus-article-hide-header "followup-to")))
1136 ((eq elem 'reply-to)
1137 (let ((from (message-fetch-field "from"))
1138 (reply-to (message-fetch-field "reply-to")))
1143 (nth 1 (mail-extract-address-components from))
1144 (nth 1 (mail-extract-address-components reply-to)))))
1145 (gnus-article-hide-header "reply-to"))))
1147 (let ((date (message-fetch-field "date")))
1149 (< (days-between (current-time-string) date)
1151 (gnus-article-hide-header "date"))))
1153 (let ((to (message-fetch-field "to")))
1154 (when (> (length to) 1024)
1155 (gnus-article-hide-header "to"))))
1158 (goto-char (point-min))
1159 (while (re-search-forward "^to:" nil t)
1160 (setq to-count (1+ to-count)))
1161 (when (> to-count 1)
1162 (while (> to-count 0)
1163 (goto-char (point-min))
1165 (re-search-forward "^to:" nil nil to-count)
1167 (narrow-to-region (point) (point-max))
1168 (gnus-article-hide-header "to"))
1169 (setq to-count (1- to-count)))))))))))))
1171 (defun gnus-article-hide-header (header)
1173 (goto-char (point-min))
1174 (when (re-search-forward (concat "^" header ":") nil t)
1175 (gnus-article-hide-text-type
1176 (progn (beginning-of-line) (point))
1179 (if (re-search-forward "^[^ \t]" nil t)
1184 (defvar gnus-article-normalized-header-length 40
1185 "Length of normalized headers.")
1187 (defun article-normalize-headers ()
1188 "Make all header lines 40 characters long."
1190 (let ((buffer-read-only nil)
1194 (article-narrow-to-head)
1197 ((< (setq column (- (gnus-point-at-eol) (point)))
1198 gnus-article-normalized-header-length)
1200 (insert (make-string
1201 (- gnus-article-normalized-header-length column)
1203 ((> column gnus-article-normalized-header-length)
1204 (gnus-put-text-property
1206 (forward-char gnus-article-normalized-header-length)
1213 (forward-line 1))))))
1215 (defun article-treat-dumbquotes ()
1216 "Translate M******** sm*rtq**t*s into proper text.
1217 Note that this function guesses whether a character is a sm*rtq**t* or
1218 not, so it should only be used interactively."
1220 (article-translate-strings gnus-article-dumbquotes-map))
1222 (defun article-translate-characters (from to)
1223 "Translate all characters in the body of the article according to FROM and TO.
1224 FROM is a string of characters to translate from; to is a string of
1225 characters to translate to."
1227 (when (article-goto-body)
1228 (let ((buffer-read-only nil)
1229 (x (make-string 225 ?x))
1231 (while (< (incf i) (length x))
1234 (while (< i (length from))
1235 (aset x (aref from i) (aref to i))
1237 (translate-region (point) (point-max) x)))))
1239 (defun article-translate-strings (map)
1240 "Translate all string in the body of the article according to MAP.
1241 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1243 (when (article-goto-body)
1244 (let ((buffer-read-only nil)
1246 (while (setq elem (pop map))
1248 (while (search-forward (car elem) nil t)
1249 (replace-match (cadr elem)))))))))
1251 (defun article-treat-overstrike ()
1252 "Translate overstrikes into bold text."
1255 (when (article-goto-body)
1256 (let ((buffer-read-only nil))
1257 (while (search-forward "\b" nil t)
1258 (let ((next (char-after))
1259 (previous (char-after (- (point) 2))))
1260 ;; We do the boldification/underlining by hiding the
1261 ;; overstrikes and putting the proper text property
1265 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1266 (put-text-property (point) (1+ (point)) 'face 'bold))
1268 (gnus-article-hide-text-type
1269 (1- (point)) (1+ (point)) 'overstrike)
1271 (- (point) 2) (1- (point)) 'face 'underline))
1273 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1275 (point) (1+ (point)) 'face 'underline)))))))))
1277 (defun article-fill-long-lines ()
1278 "Fill lines that are wider than the window width."
1281 (let ((buffer-read-only nil)
1282 (width (window-width (get-buffer-window (current-buffer)))))
1285 (let ((adaptive-fill-mode nil))
1288 (when (>= (current-column) (min fill-column width))
1289 (narrow-to-region (point) (gnus-point-at-bol))
1290 (fill-paragraph nil)
1291 (goto-char (point-max))
1293 (forward-line 1)))))))
1295 (defun article-capitalize-sentences ()
1296 "Capitalize the first word in each sentence."
1299 (let ((buffer-read-only nil)
1300 (paragraph-start "^[\n\^L]"))
1304 (forward-sentence)))))
1306 (defun article-remove-cr ()
1307 "Remove trailing CRs and then translate remaining CRs into LFs."
1310 (let ((buffer-read-only nil))
1311 (goto-char (point-min))
1312 (while (re-search-forward "\r+$" nil t)
1313 (replace-match "" t t))
1314 (goto-char (point-min))
1315 (while (search-forward "\r" nil t)
1316 (replace-match "\n" t t)))))
1318 (defun article-remove-trailing-blank-lines ()
1319 "Remove all trailing blank lines from the article."
1322 (let ((buffer-read-only nil))
1323 (goto-char (point-max))
1327 (while (and (not (bobp))
1328 (looking-at "^[ \t]*$")
1329 (not (gnus-annotation-in-region-p
1330 (point) (gnus-point-at-eol))))
1335 (defun article-display-x-face (&optional force)
1336 "Look for an X-Face header and display it if present."
1337 (interactive (list 'force))
1339 ;; Delete the old process, if any.
1340 (when (process-status "article-x-face")
1341 (delete-process "article-x-face"))
1342 (let ((inhibit-point-motion-hooks t)
1343 (case-fold-search t)
1346 (article-narrow-to-head)
1347 (goto-char (point-min))
1348 (setq from (message-fetch-field "from"))
1349 (goto-char (point-min))
1350 (while (and gnus-article-x-face-command
1353 ;; Check whether this face is censored.
1354 (not gnus-article-x-face-too-ugly)
1355 (and gnus-article-x-face-too-ugly from
1356 (not (string-match gnus-article-x-face-too-ugly
1358 ;; Has to be present.
1359 (re-search-forward "^X-Face: " nil t))
1360 ;; This used to try to do multiple faces (`while' instead of
1361 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1362 ;; work (b) it can crash some versions of Emacs (c) are
1363 ;; multiple faces really something to encourage?
1364 (when (stringp gnus-article-x-face-command)
1366 ;; We now have the area of the buffer where the X-Face is stored.
1369 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1370 ;; We display the face.
1371 (if (symbolp gnus-article-x-face-command)
1372 ;; The command is a lisp function, so we call it.
1373 (if (gnus-functionp gnus-article-x-face-command)
1374 (funcall gnus-article-x-face-command beg end)
1375 (error "%s is not a function" gnus-article-x-face-command))
1376 ;; The command is a string, so we interpret the command
1377 ;; as a, well, command, and fork it off.
1378 (let ((process-connection-type nil))
1379 (process-kill-without-query
1381 "article-x-face" nil shell-file-name shell-command-switch
1382 gnus-article-x-face-command))
1383 (process-send-region "article-x-face" beg end)
1384 (process-send-eof "article-x-face"))))))))))
1386 (defun article-decode-mime-words ()
1387 "Decode all MIME-encoded words in the article."
1390 (set-buffer gnus-article-buffer)
1391 (let ((inhibit-point-motion-hooks t)
1393 (mail-parse-charset gnus-newsgroup-charset)
1394 (mail-parse-ignored-charsets
1395 (save-excursion (set-buffer gnus-summary-buffer)
1396 gnus-newsgroup-ignored-charsets)))
1397 (mail-decode-encoded-word-region (point-min) (point-max)))))
1399 (defun article-decode-charset (&optional prompt)
1400 "Decode charset-encoded text in the article.
1401 If PROMPT (the prefix), prompt for a coding system to use."
1405 (article-narrow-to-head)
1406 (let* ((inhibit-point-motion-hooks t)
1407 (case-fold-search t)
1408 (ct (message-fetch-field "Content-Type" t))
1409 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1410 (ctl (and ct (ignore-errors
1411 (mail-header-parse-content-type ct))))
1414 (mm-read-coding-system "Charset to decode: "))
1416 (mail-content-type-get ctl 'charset))))
1417 (mail-parse-charset gnus-newsgroup-charset)
1418 (mail-parse-ignored-charsets
1419 (save-excursion (condition-case nil
1420 (set-buffer gnus-summary-buffer)
1422 gnus-newsgroup-ignored-charsets))
1424 (if (and ctl (not (string-match "/" (car ctl))))
1426 (goto-char (point-max))
1429 (narrow-to-region (point) (point-max))
1430 (when (and (or (not ctl)
1431 (equal (car ctl) "text/plain"))
1434 charset (and cte (intern (downcase
1435 (gnus-strip-whitespace cte))))
1438 (defun article-decode-encoded-words ()
1439 "Remove encoded-word encoding from headers."
1440 (let ((inhibit-point-motion-hooks t)
1441 (mail-parse-charset gnus-newsgroup-charset)
1442 (mail-parse-ignored-charsets
1443 (save-excursion (set-buffer gnus-summary-buffer)
1444 gnus-newsgroup-ignored-charsets))
1447 (article-narrow-to-head)
1448 (funcall gnus-decode-header-function (point-min) (point-max)))))
1450 (defun article-de-quoted-unreadable (&optional force)
1451 "Translate a quoted-printable-encoded article.
1452 If FORCE, decode the article whether it is marked as quoted-printable
1454 (interactive (list 'force))
1456 (let ((buffer-read-only nil)
1457 (type (gnus-fetch-field "content-transfer-encoding"))
1458 (charset gnus-newsgroup-charset))
1460 (and type (string-match "quoted-printable" (downcase type))))
1463 (narrow-to-region (point) (point-max))
1464 (quoted-printable-decode-region (point-min) (point-max))
1466 (mm-decode-body charset)))))))
1468 (defun article-hide-list-identifiers ()
1469 "Remove any list identifiers in `gnus-list-identifiers' from Subject
1470 header in the current article."
1474 (let ((inhibit-point-motion-hooks t)
1476 (article-narrow-to-head)
1477 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1478 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1480 (goto-char (point-min))
1481 (when (re-search-forward
1482 (concat "^Subject: +\\(Re: +\\)?\\(" regexp " *\\)")
1484 (delete-region (match-beginning 2) (match-end 0)))))))))
1486 (defun article-hide-pgp ()
1487 "Remove any PGP headers and signatures in the current article."
1491 (let ((inhibit-point-motion-hooks t)
1492 buffer-read-only beg end)
1494 ;; Hide the "header".
1495 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1496 (push 'pgp gnus-article-wash-types)
1497 (delete-region (match-beginning 0) (match-end 0))
1498 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1499 (when (looking-at "Hash:.*$")
1500 (delete-region (point) (1+ (gnus-point-at-eol))))
1502 ;; Hide the actual signature.
1503 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1504 (setq end (1+ (match-beginning 0)))
1507 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1509 ;; Perhaps we shouldn't hide to the end of the buffer
1510 ;; if there is no end to the signature?
1512 ;; Hide "- " PGP quotation markers.
1514 (narrow-to-region beg end)
1515 (goto-char (point-min))
1516 (while (re-search-forward "^- " nil t)
1518 (match-beginning 0) (match-end 0)))
1520 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1522 (defun article-hide-pem (&optional arg)
1523 "Toggle hiding of any PEM headers and signatures in the current article.
1524 If given a negative prefix, always show; if given a positive prefix,
1526 (interactive (gnus-article-hidden-arg))
1527 (unless (gnus-article-check-hidden-text 'pem arg)
1529 (let (buffer-read-only end)
1530 (goto-char (point-min))
1531 ;; Hide the horrendously ugly "header".
1532 (when (and (search-forward
1533 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1535 (setq end (1+ (match-beginning 0))))
1536 (push 'pem gnus-article-wash-types)
1537 (gnus-article-hide-text-type
1539 (if (search-forward "\n\n" nil t)
1543 ;; Hide the trailer as well
1544 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1546 (gnus-article-hide-text-type
1547 (match-beginning 0) (match-end 0) 'pem)))))))
1549 (defun article-strip-banner ()
1550 "Strip the banner specified by the `banner' group parameter."
1554 (let ((inhibit-point-motion-hooks t)
1555 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1556 (gnus-signature-limit nil)
1557 buffer-read-only beg end)
1561 ((eq banner 'signature)
1562 (when (gnus-article-narrow-to-signature)
1565 (delete-region (point) (point-max))))
1567 (while (re-search-forward banner nil t)
1568 (delete-region (match-beginning 0) (match-end 0))))))))))
1570 (defun article-babel ()
1571 "Translate article using an online translation service."
1575 (set-buffer gnus-article-buffer)
1576 (when (article-goto-body)
1577 (let* ((buffer-read-only nil)
1580 (orig (buffer-substring start end))
1581 (trans (babel-as-string orig)))
1583 (narrow-to-region start end)
1584 (delete-region start end)
1587 (defun article-hide-signature (&optional arg)
1588 "Hide the signature in the current article.
1589 If given a negative prefix, always show; if given a positive prefix,
1591 (interactive (gnus-article-hidden-arg))
1592 (unless (gnus-article-check-hidden-text 'signature arg)
1595 (let ((buffer-read-only nil))
1596 (when (gnus-article-narrow-to-signature)
1597 (gnus-article-hide-text-type
1598 (point-min) (point-max) 'signature)))))))
1600 (defun article-strip-headers-in-body ()
1601 "Strip offensive headers from bodies."
1605 (let ((case-fold-search t))
1606 (when (looking-at "x-no-archive:")
1607 (gnus-delete-line)))))
1609 (defun article-strip-leading-blank-lines ()
1610 "Remove all blank lines from the beginning of the article."
1613 (let ((inhibit-point-motion-hooks t)
1615 (when (article-goto-body)
1616 (while (and (not (eobp))
1617 (looking-at "[ \t]*$"))
1618 (gnus-delete-line))))))
1620 (defun article-narrow-to-head ()
1621 "Narrow the buffer to the head of the message.
1622 Point is left at the beginning of the narrowed-to region."
1624 (goto-char (point-min))
1625 (if (search-forward "\n\n" nil 1)
1628 (goto-char (point-min)))
1630 (defun article-goto-body ()
1631 "Place point at the start of the body."
1632 (goto-char (point-min))
1634 ;; This variable is only bound when dealing with separate
1636 (article-goto-body-goes-to-point-min-p
1638 ((search-forward "\n\n" nil t)
1641 (goto-char (point-max))
1644 (defun article-strip-multiple-blank-lines ()
1645 "Replace consecutive blank lines with one empty line."
1648 (let ((inhibit-point-motion-hooks t)
1650 ;; First make all blank lines empty.
1652 (while (re-search-forward "^[ \t]+$" nil t)
1653 (unless (gnus-annotation-in-region-p
1654 (match-beginning 0) (match-end 0))
1655 (replace-match "" nil t)))
1656 ;; Then replace multiple empty lines with a single empty line.
1658 (while (re-search-forward "\n\n\n+" nil t)
1659 (unless (gnus-annotation-in-region-p
1660 (match-beginning 0) (match-end 0))
1661 (replace-match "\n\n" t t))))))
1663 (defun article-strip-leading-space ()
1664 "Remove all white space from the beginning of the lines in the article."
1667 (let ((inhibit-point-motion-hooks t)
1670 (while (re-search-forward "^[ \t]+" nil t)
1671 (replace-match "" t t)))))
1673 (defun article-strip-trailing-space ()
1674 "Remove all white space from the end of the lines in the article."
1677 (let ((inhibit-point-motion-hooks t)
1680 (while (re-search-forward "[ \t]+$" nil t)
1681 (replace-match "" t t)))))
1683 (defun article-strip-blank-lines ()
1684 "Strip leading, trailing and multiple blank lines."
1686 (article-strip-leading-blank-lines)
1687 (article-remove-trailing-blank-lines)
1688 (article-strip-multiple-blank-lines))
1690 (defun article-strip-all-blank-lines ()
1691 "Strip all blank lines."
1694 (let ((inhibit-point-motion-hooks t)
1697 (while (re-search-forward "^[ \t]*\n" nil t)
1698 (replace-match "" t t)))))
1700 (defun gnus-article-narrow-to-signature ()
1701 "Narrow to the signature; return t if a signature is found, else nil."
1702 (let ((inhibit-point-motion-hooks t))
1703 (when (gnus-article-search-signature)
1705 ;; Check whether we have some limits to what we consider
1706 ;; to be a signature.
1707 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1708 (list gnus-signature-limit)))
1710 (while (setq limit (pop limits))
1711 (if (or (and (integerp limit)
1712 (< (- (point-max) (point)) limit))
1714 (< (count-lines (point) (point-max)) limit))
1715 (and (gnus-functionp limit)
1717 (and (stringp limit)
1718 (not (re-search-forward limit nil t))))
1719 () ; This limit did not succeed.
1723 (narrow-to-region (point) (point-max))
1726 (defun gnus-article-search-signature ()
1727 "Search the current buffer for the signature separator.
1728 Put point at the beginning of the signature separator."
1729 (let ((cur (point)))
1730 (goto-char (point-max))
1731 (if (if (stringp gnus-signature-separator)
1732 (re-search-backward gnus-signature-separator nil t)
1733 (let ((seps gnus-signature-separator))
1735 (not (re-search-backward (car seps) nil t)))
1742 (defun gnus-article-hidden-arg ()
1743 "Return the current prefix arg as a number, or 0 if no prefix."
1744 (list (if current-prefix-arg
1745 (prefix-numeric-value current-prefix-arg)
1748 (defun gnus-article-check-hidden-text (type arg)
1749 "Return nil if hiding is necessary.
1750 Arg can be nil or a number. Nil and positive means hide, negative
1751 means show, 0 means toggle."
1754 (let ((hide (gnus-article-hidden-text-p type)))
1760 (gnus-article-show-hidden-text type))
1762 (if (eq hide 'hidden)
1763 (gnus-article-show-hidden-text type)
1766 (defun gnus-article-hidden-text-p (type)
1767 "Say whether the current buffer contains hidden text of type TYPE."
1768 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1770 (not (get-text-property pos 'invisible))
1771 (not (get-text-property pos 'dummy-invisible)))
1773 (text-property-any (1+ pos) (point-max) 'article-type type)))
1778 (defun gnus-article-show-hidden-text (type &optional hide)
1779 "Show all hidden text of type TYPE.
1780 If HIDE, hide the text instead."
1782 (let ((buffer-read-only nil)
1783 (inhibit-point-motion-hooks t)
1786 (while (setq beg (text-property-any end (point-max) 'article-type type))
1789 (text-property-not-all beg (point-max) 'article-type type)
1792 (gnus-article-hide-text beg end gnus-hidden-properties)
1793 (gnus-article-unhide-text beg end))
1797 (defconst article-time-units
1798 `((year . ,(* 365.25 24 60 60))
1799 (week . ,(* 7 24 60 60))
1800 (day . ,(* 24 60 60))
1804 "Mapping from time units to seconds.")
1806 (defun article-date-ut (&optional type highlight header)
1807 "Convert DATE date to universal time in the current article.
1808 If TYPE is `local', convert to local time; if it is `lapsed', output
1809 how much time has lapsed since DATE. For `lapsed', the value of
1810 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1811 should replace the \"Date:\" one, or should be added below it."
1812 (interactive (list 'ut t))
1813 (let* ((header (or header
1814 (message-fetch-field "date")
1816 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1819 ((not gnus-article-date-lapsed-new-header)
1825 (date (if (vectorp header) (mail-header-date header)
1827 (inhibit-point-motion-hooks t)
1830 (when (and date (not (string= date "")))
1833 (article-narrow-to-head)
1834 (when (re-search-forward tdate-regexp nil t)
1835 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1836 date (or (get-text-property (gnus-point-at-bol)
1839 eface (get-text-property (1- (gnus-point-at-eol))
1842 (goto-char (point-min))
1843 (let ((buffer-read-only nil))
1844 ;; Delete any old Date headers.
1845 (while (re-search-forward date-regexp nil t)
1847 (delete-region (progn (beginning-of-line) (point))
1848 (progn (forward-line 1) (point)))
1849 (delete-region (progn (beginning-of-line) (point))
1850 (progn (end-of-line) (point)))
1851 (setq pos (point))))
1852 (when (and (not pos) (re-search-forward tdate-regexp nil t))
1854 (if pos (goto-char pos))
1855 (insert (article-make-date-line date (or type 'ut)))
1861 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1862 (put-text-property (match-beginning 1) (1+ (match-end 1))
1863 'original-date date)
1864 (put-text-property (match-beginning 1) (1+ (match-end 1))
1866 (put-text-property (match-beginning 2) (match-end 2)
1869 (defun article-make-date-line (date type)
1870 "Return a DATE line of TYPE."
1871 (let ((time (condition-case ()
1875 ;; Convert to the local timezone. We have to slap a
1876 ;; `condition-case' round the calls to the timezone
1877 ;; functions since they aren't particularly resistant to
1880 (let ((tz (car (current-time-zone time))))
1881 (format "Date: %s %s%02d%02d" (current-time-string time)
1882 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1883 (/ (% (abs tz) 3600) 60))))
1884 ;; Convert to Universal Time.
1887 (current-time-string
1888 (let* ((e (parse-time-string date))
1889 (tm (apply 'encode-time e))
1891 (ls (- (cadr tm) (car (current-time-zone time)))))
1892 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1893 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1896 ;; Get the original date from the article.
1897 ((eq type 'original)
1898 (concat "Date: " (if (string-match "\n+$" date)
1899 (substring date 0 (match-beginning 0))
1901 ;; Let the user define the format.
1903 (if (gnus-functionp gnus-article-time-format)
1904 (funcall gnus-article-time-format time)
1907 (format-time-string gnus-article-time-format time))))
1910 (let ((tz (car (current-time-zone time))))
1913 (format-time-string "%Y%m%dT%H%M%S" time)
1914 (format "%s%02d%02d"
1915 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
1916 (/ (% (abs tz) 3600) 60)))))
1917 ;; Do an X-Sent lapsed format.
1919 ;; If the date is seriously mangled, the timezone functions are
1920 ;; liable to bug out, so we ignore all errors.
1921 (let* ((now (current-time))
1922 (real-time (subtract-time now time))
1923 (real-sec (and real-time
1924 (+ (* (float (car real-time)) 65536)
1926 (sec (and real-time (abs real-sec)))
1936 ;; This is a bit convoluted, but basically we go
1937 ;; through the time units for years, weeks, etc,
1938 ;; and divide things to see whether that results
1939 ;; in positive answers.
1942 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1943 ;; The (remaining) seconds are too few to
1944 ;; be divided into this time unit.
1946 ;; It's big enough, so we output it.
1947 (setq sec (- sec (* num (cdr unit))))
1949 (concat (if prev ", " "") (int-to-string
1951 " " (symbol-name (car unit))
1952 (if (> num 1) "s" ""))
1954 article-time-units "")
1955 ;; If dates are odd, then it might appear like the
1956 ;; article was sent in the future.
1959 " in the future"))))))
1961 (error "Unknown conversion type: %s" type)))))
1963 (defun article-date-local (&optional highlight)
1964 "Convert the current article date to the local timezone."
1965 (interactive (list t))
1966 (article-date-ut 'local highlight))
1968 (defun article-date-original (&optional highlight)
1969 "Convert the current article date to what it was originally.
1970 This is only useful if you have used some other date conversion
1971 function and want to see what the date was before converting."
1972 (interactive (list t))
1973 (article-date-ut 'original highlight))
1975 (defun article-date-lapsed (&optional highlight)
1976 "Convert the current article date to time lapsed since it was sent."
1977 (interactive (list t))
1978 (article-date-ut 'lapsed highlight))
1980 (defun article-update-date-lapsed ()
1981 "Function to be run from a timer to update the lapsed time line."
1982 (let (deactivate-mark)
1987 (set-buffer (window-buffer w))
1988 (when (eq major-mode 'gnus-article-mode)
1989 (goto-char (point-min))
1990 (when (re-search-forward "^X-Sent:" nil t)
1991 (article-date-lapsed t))))
1994 (defun gnus-start-date-timer (&optional n)
1995 "Start a timer to update the X-Sent header in the article buffers.
1996 The numerical prefix says how frequently (in seconds) the function
2001 (gnus-stop-date-timer)
2002 (setq article-lapsed-timer
2003 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2005 (defun gnus-stop-date-timer ()
2006 "Stop the X-Sent timer."
2008 (when article-lapsed-timer
2009 (nnheader-cancel-timer article-lapsed-timer)
2010 (setq article-lapsed-timer nil)))
2012 (defun article-date-user (&optional highlight)
2013 "Convert the current article date to the user-defined format.
2014 This format is defined by the `gnus-article-time-format' variable."
2015 (interactive (list t))
2016 (article-date-ut 'user highlight))
2018 (defun article-date-iso8601 (&optional highlight)
2019 "Convert the current article date to ISO8601."
2020 (interactive (list t))
2021 (article-date-ut 'iso8601 highlight))
2023 (defun article-show-all ()
2024 "Show all hidden text in the article buffer."
2027 (let ((buffer-read-only nil))
2028 (gnus-article-unhide-text (point-min) (point-max)))))
2030 (defun article-emphasize (&optional arg)
2031 "Emphasize text according to `gnus-emphasis-alist'."
2032 (interactive (gnus-article-hidden-arg))
2033 (unless (gnus-article-check-hidden-text 'emphasis arg)
2035 (let ((alist (or (with-current-buffer gnus-summary-buffer
2036 gnus-article-emphasis-alist)
2037 gnus-emphasis-alist))
2038 (buffer-read-only nil)
2039 (props (append '(article-type emphasis)
2040 gnus-hidden-properties))
2041 regexp elem beg invisible visible face)
2044 (while (setq elem (pop alist))
2046 (setq regexp (car elem)
2047 invisible (nth 1 elem)
2048 visible (nth 2 elem)
2050 (while (re-search-forward regexp nil t)
2051 (when (and (match-beginning visible) (match-beginning invisible))
2052 (push 'emphasis gnus-article-wash-types)
2053 (gnus-article-hide-text
2054 (match-beginning invisible) (match-end invisible) props)
2055 (gnus-article-unhide-text-type
2056 (match-beginning visible) (match-end visible) 'emphasis)
2057 (gnus-put-text-property-excluding-newlines
2058 (match-beginning visible) (match-end visible) 'face face)
2059 (goto-char (match-end invisible)))))))))
2061 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2062 "Setup newsgroup emphasis alist."
2063 (unless gnus-article-emphasis-alist
2064 (let ((name (and gnus-newsgroup-name
2065 (gnus-group-real-name gnus-newsgroup-name))))
2066 (make-local-variable 'gnus-article-emphasis-alist)
2067 (setq gnus-article-emphasis-alist
2069 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2070 (while (setq elem (pop alist))
2071 (when (and name (string-match (car elem) name))
2073 highlight (copy-list (cdr elem)))))
2075 (copy-list highlight-words)
2076 (if gnus-newsgroup-name
2077 (copy-list (gnus-group-find-parameter
2078 gnus-newsgroup-name 'highlight-words t)))
2079 gnus-emphasis-alist)))))
2081 (defvar gnus-summary-article-menu)
2082 (defvar gnus-summary-post-menu)
2084 ;;; Saving functions.
2086 (defun gnus-article-save (save-buffer file &optional num)
2087 "Save the currently selected article."
2088 (unless gnus-save-all-headers
2089 ;; Remove headers according to `gnus-saved-headers'.
2090 (let ((gnus-visible-headers
2091 (or gnus-saved-headers gnus-visible-headers))
2092 (gnus-article-buffer save-buffer))
2094 (set-buffer save-buffer)
2095 (article-hide-headers 1 t))))
2096 (save-window-excursion
2097 (if (not gnus-default-article-saver)
2098 (error "No default saver is defined")
2099 ;; !!! Magic! The saving functions all save
2100 ;; `gnus-save-article-buffer' (or so they think), but we
2101 ;; bind that variable to our save-buffer.
2102 (set-buffer gnus-article-buffer)
2103 (let* ((gnus-save-article-buffer save-buffer)
2106 ((not gnus-prompt-before-saving) 'default)
2107 ((eq gnus-prompt-before-saving 'always) nil)
2109 (gnus-number-of-articles-to-be-saved
2110 (when (eq gnus-prompt-before-saving t)
2112 (set-buffer gnus-article-current-summary)
2113 (funcall gnus-default-article-saver filename)))))
2115 (defun gnus-read-save-file-name (prompt &optional filename
2116 function group headers variable)
2118 (funcall function group headers (symbol-value variable)))
2123 ((eq filename 'default)
2129 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2132 (if (and gnus-number-of-articles-to-be-saved
2133 (> gnus-number-of-articles-to-be-saved 1))
2134 (format "these %d articles"
2135 gnus-number-of-articles-to-be-saved)
2138 ;; Let the split methods have their say.
2140 ;; No split name was found.
2143 (concat prompt " (default "
2144 (file-name-nondirectory default-name) ") ")
2145 (file-name-directory default-name)
2147 ;; A single group name is returned.
2148 ((stringp split-name)
2150 (funcall function split-name headers
2151 (symbol-value variable)))
2153 (concat prompt " (default "
2154 (file-name-nondirectory default-name) ") ")
2155 (file-name-directory default-name)
2157 ;; A single split name was found
2158 ((= 1 (length split-name))
2159 (let* ((name (expand-file-name
2160 (car split-name) gnus-article-save-directory))
2161 (dir (cond ((file-directory-p name)
2162 (file-name-as-directory name))
2163 ((file-exists-p name) name)
2164 (t gnus-article-save-directory))))
2166 (concat prompt " (default " name ") ")
2168 ;; A list of splits was found.
2170 (setq split-name (nreverse split-name))
2172 (let ((file-name-history
2173 (nconc split-name file-name-history)))
2177 (concat prompt " (`M-p' for defaults) ")
2178 gnus-article-save-directory
2180 gnus-article-save-directory)))
2181 (car (push result file-name-history)))))))
2182 ;; Create the directory.
2183 (gnus-make-directory (file-name-directory file))
2184 ;; If we have read a directory, we append the default file name.
2185 (when (file-directory-p file)
2186 (setq file (concat (file-name-as-directory file)
2187 (file-name-nondirectory default-name))))
2188 ;; Possibly translate some characters.
2189 (nnheader-translate-file-chars file)))))
2190 (gnus-make-directory (file-name-directory result))
2191 (set variable result)))
2193 (defun gnus-article-archive-name (group)
2194 "Return the first instance of an \"Archive-name\" in the current buffer."
2195 (let ((case-fold-search t))
2196 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2197 (nnheader-concat gnus-article-save-directory
2198 (match-string 1)))))
2200 (defun gnus-article-nndoc-name (group)
2201 "If GROUP is an nndoc group, return the name of the parent group."
2202 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2203 (gnus-group-get-parameter group 'save-article-group)))
2205 (defun gnus-summary-save-in-rmail (&optional filename)
2206 "Append this article to Rmail file.
2207 Optional argument FILENAME specifies file name.
2208 Directory to save to is default to `gnus-article-save-directory'."
2209 (setq filename (gnus-read-save-file-name
2210 "Save %s in rmail file:" filename
2211 gnus-rmail-save-name gnus-newsgroup-name
2212 gnus-current-headers 'gnus-newsgroup-last-rmail))
2213 (gnus-eval-in-buffer-window gnus-save-article-buffer
2217 (gnus-output-to-rmail filename))))
2220 (defun gnus-summary-save-in-mail (&optional filename)
2221 "Append this article to Unix mail file.
2222 Optional argument FILENAME specifies file name.
2223 Directory to save to is default to `gnus-article-save-directory'."
2224 (setq filename (gnus-read-save-file-name
2225 "Save %s in Unix mail file:" filename
2226 gnus-mail-save-name gnus-newsgroup-name
2227 gnus-current-headers 'gnus-newsgroup-last-mail))
2228 (gnus-eval-in-buffer-window gnus-save-article-buffer
2232 (if (and (file-readable-p filename)
2233 (mail-file-babyl-p filename))
2234 (rmail-output-to-rmail-file filename t)
2235 (gnus-output-to-mail filename)))))
2238 (defun gnus-summary-save-in-file (&optional filename overwrite)
2239 "Append this article to file.
2240 Optional argument FILENAME specifies file name.
2241 Directory to save to is default to `gnus-article-save-directory'."
2242 (setq filename (gnus-read-save-file-name
2243 "Save %s in file:" filename
2244 gnus-file-save-name gnus-newsgroup-name
2245 gnus-current-headers 'gnus-newsgroup-last-file))
2246 (gnus-eval-in-buffer-window gnus-save-article-buffer
2250 (when (and overwrite
2251 (file-exists-p filename))
2252 (delete-file filename))
2253 (gnus-output-to-file filename))))
2256 (defun gnus-summary-write-to-file (&optional filename)
2257 "Write this article to a file.
2258 Optional argument FILENAME specifies file name.
2259 The directory to save in defaults to `gnus-article-save-directory'."
2260 (gnus-summary-save-in-file nil t))
2262 (defun gnus-summary-save-body-in-file (&optional filename)
2263 "Append this article body to a file.
2264 Optional argument FILENAME specifies file name.
2265 The directory to save in defaults to `gnus-article-save-directory'."
2266 (setq filename (gnus-read-save-file-name
2267 "Save %s body in file:" filename
2268 gnus-file-save-name gnus-newsgroup-name
2269 gnus-current-headers 'gnus-newsgroup-last-file))
2270 (gnus-eval-in-buffer-window gnus-save-article-buffer
2274 (when (article-goto-body)
2275 (narrow-to-region (point) (point-max)))
2276 (gnus-output-to-file filename))))
2279 (defun gnus-summary-save-in-pipe (&optional command)
2280 "Pipe this article to subprocess."
2282 (cond ((and (eq command 'default)
2283 gnus-last-shell-command)
2284 gnus-last-shell-command)
2288 "Shell command on %s: "
2289 (if (and gnus-number-of-articles-to-be-saved
2290 (> gnus-number-of-articles-to-be-saved 1))
2291 (format "these %d articles"
2292 gnus-number-of-articles-to-be-saved)
2294 gnus-last-shell-command))))
2295 (when (string-equal command "")
2296 (setq command gnus-last-shell-command))
2297 (gnus-eval-in-buffer-window gnus-article-buffer
2300 (shell-command-on-region (point-min) (point-max) command nil)))
2301 (setq gnus-last-shell-command command))
2303 ;;; Article file names when saving.
2305 (defun gnus-capitalize-newsgroup (newsgroup)
2306 "Capitalize NEWSGROUP name."
2307 (when (not (zerop (length newsgroup)))
2308 (concat (char-to-string (upcase (aref newsgroup 0)))
2309 (substring newsgroup 1))))
2311 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2312 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2313 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2314 Otherwise, it is like ~/News/news/group/num."
2317 (concat (if (gnus-use-long-file-name 'not-save)
2318 (gnus-capitalize-newsgroup newsgroup)
2319 (gnus-newsgroup-directory-form newsgroup))
2320 "/" (int-to-string (mail-header-number headers)))
2321 gnus-article-save-directory)))
2323 (string-equal (file-name-directory default)
2324 (file-name-directory last-file))
2325 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2327 (or last-file default))))
2329 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2330 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2331 If variable `gnus-use-long-file-name' is non-nil, it is
2332 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2335 (concat (if (gnus-use-long-file-name 'not-save)
2337 (gnus-newsgroup-directory-form newsgroup))
2338 "/" (int-to-string (mail-header-number headers)))
2339 gnus-article-save-directory)))
2341 (string-equal (file-name-directory default)
2342 (file-name-directory last-file))
2343 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2345 (or last-file default))))
2347 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2348 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2349 If variable `gnus-use-long-file-name' is non-nil, it is
2350 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2353 (if (gnus-use-long-file-name 'not-save)
2354 (gnus-capitalize-newsgroup newsgroup)
2355 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2356 gnus-article-save-directory)))
2358 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2359 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2360 If variable `gnus-use-long-file-name' is non-nil, it is
2361 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2364 (if (gnus-use-long-file-name 'not-save)
2366 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2367 gnus-article-save-directory)))
2374 (setq afunc (car func)
2377 gfunc (intern (format "gnus-%s" func))))
2379 (if (not (fboundp afunc))
2381 `(lambda (&optional interactive &rest args)
2382 ,(documentation afunc t)
2383 (interactive (list t))
2385 (set-buffer gnus-article-buffer)
2387 (call-interactively ',afunc)
2388 (apply ',afunc args))))))))
2389 '(article-hide-headers
2390 article-hide-boring-headers
2391 article-treat-overstrike
2392 article-fill-long-lines
2393 article-capitalize-sentences
2395 article-display-x-face
2396 article-de-quoted-unreadable
2397 article-mime-decode-quoted-printable
2398 article-hide-list-identifiers
2400 article-strip-banner
2403 article-hide-signature
2404 article-strip-headers-in-body
2405 article-remove-trailing-blank-lines
2406 article-strip-leading-blank-lines
2407 article-strip-multiple-blank-lines
2408 article-strip-leading-space
2409 article-strip-trailing-space
2410 article-strip-blank-lines
2411 article-strip-all-blank-lines
2413 article-date-iso8601
2414 article-date-original
2416 article-decode-mime-words
2417 article-decode-charset
2418 article-decode-encoded-words
2422 article-treat-dumbquotes
2423 article-normalize-headers
2424 (article-show-all . gnus-article-show-all-headers))))
2427 ;;; Gnus article mode
2430 (put 'gnus-article-mode 'mode-class 'special)
2432 (set-keymap-parent gnus-article-mode-map widget-keymap)
2434 (gnus-define-keys gnus-article-mode-map
2435 " " gnus-article-goto-next-page
2436 "\177" gnus-article-goto-prev-page
2437 [delete] gnus-article-goto-prev-page
2438 [backspace] gnus-article-goto-prev-page
2439 "\C-c^" gnus-article-refer-article
2440 "h" gnus-article-show-summary
2441 "s" gnus-article-show-summary
2442 "\C-c\C-m" gnus-article-mail
2443 "?" gnus-article-describe-briefly
2444 "e" gnus-article-edit
2445 "<" beginning-of-buffer
2447 "\C-c\C-i" gnus-info-find-node
2450 "\C-d" gnus-article-read-summary-keys
2451 "\M-*" gnus-article-read-summary-keys
2452 "\M-#" gnus-article-read-summary-keys
2453 "\M-^" gnus-article-read-summary-keys
2454 "\M-g" gnus-article-read-summary-keys)
2456 (substitute-key-definition
2457 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2459 (defun gnus-article-make-menu-bar ()
2460 (gnus-turn-off-edit-menu 'article)
2461 (unless (boundp 'gnus-article-article-menu)
2463 gnus-article-article-menu gnus-article-mode-map ""
2465 ["Scroll forwards" gnus-article-goto-next-page t]
2466 ["Scroll backwards" gnus-article-goto-prev-page t]
2467 ["Show summary" gnus-article-show-summary t]
2468 ["Fetch Message-ID at point" gnus-article-refer-article t]
2469 ["Mail to address at point" gnus-article-mail t]
2470 ["Send a bug report" gnus-bug t]))
2473 gnus-article-treatment-menu gnus-article-mode-map ""
2475 ["Hide headers" gnus-article-hide-headers t]
2476 ["Hide signature" gnus-article-hide-signature t]
2477 ["Hide citation" gnus-article-hide-citation t]
2478 ["Treat overstrike" gnus-article-treat-overstrike t]
2479 ["Remove carriage return" gnus-article-remove-cr t]
2480 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2482 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2484 (when (boundp 'gnus-summary-post-menu)
2485 (define-key gnus-article-mode-map [menu-bar post]
2486 (cons "Post" gnus-summary-post-menu)))
2488 (gnus-run-hooks 'gnus-article-menu-hook)))
2490 (defun gnus-article-mode ()
2491 "Major mode for displaying an article.
2493 All normal editing commands are switched off.
2495 The following commands are available in addition to all summary mode
2497 \\<gnus-article-mode-map>
2498 \\[gnus-article-next-page]\t Scroll the article one page forwards
2499 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2500 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2501 \\[gnus-article-show-summary]\t Display the summary buffer
2502 \\[gnus-article-mail]\t Send a reply to the address near point
2503 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2504 \\[gnus-info-find-node]\t Go to the Gnus info node"
2506 (when (gnus-visual-p 'article-menu 'menu)
2507 (gnus-article-make-menu-bar))
2508 (gnus-simplify-mode-line)
2509 (setq mode-name "Article")
2510 (setq major-mode 'gnus-article-mode)
2511 (make-local-variable 'minor-mode-alist)
2512 (use-local-map gnus-article-mode-map)
2513 (gnus-update-format-specifications nil 'article-mode)
2514 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2515 (make-local-variable 'gnus-page-broken)
2516 (make-local-variable 'gnus-button-marker-list)
2517 (make-local-variable 'gnus-article-current-summary)
2518 (make-local-variable 'gnus-article-mime-handles)
2519 (make-local-variable 'gnus-article-decoded-p)
2520 (make-local-variable 'gnus-article-mime-handle-alist)
2521 (make-local-variable 'gnus-article-washed-types)
2522 (gnus-set-default-directory)
2523 (buffer-disable-undo)
2524 (setq buffer-read-only t)
2525 (set-syntax-table gnus-article-mode-syntax-table)
2526 (mm-enable-multibyte)
2527 (gnus-run-hooks 'gnus-article-mode-hook))
2529 (defun gnus-article-setup-buffer ()
2530 "Initialize the article buffer."
2531 (let* ((name (if gnus-single-article-buffer "*Article*"
2532 (concat "*Article " gnus-newsgroup-name "*")))
2534 (progn (string-match "\\*Article" name)
2535 (concat " *Original Article"
2536 (substring name (match-end 0))))))
2537 (setq gnus-article-buffer name)
2538 (setq gnus-original-article-buffer original)
2539 (setq gnus-article-mime-handle-alist nil)
2540 ;; This might be a variable local to the summary buffer.
2541 (unless gnus-single-article-buffer
2543 (set-buffer gnus-summary-buffer)
2544 (setq gnus-article-buffer name)
2545 (setq gnus-original-article-buffer original)
2546 (gnus-set-global-variables)))
2547 (gnus-article-setup-highlight-words)
2548 ;; Init original article buffer.
2550 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2551 (mm-enable-multibyte)
2552 (setq major-mode 'gnus-original-article-mode)
2553 (make-local-variable 'gnus-original-article))
2554 (if (get-buffer name)
2557 (if gnus-article-mime-handles
2558 (mm-destroy-parts gnus-article-mime-handles))
2559 (kill-all-local-variables)
2560 (buffer-disable-undo)
2561 (setq buffer-read-only t)
2562 (unless (eq major-mode 'gnus-article-mode)
2563 (gnus-article-mode))
2566 (set-buffer (gnus-get-buffer-create name))
2568 (make-local-variable 'gnus-summary-buffer)
2569 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2570 (current-buffer)))))
2572 ;; Set article window start at LINE, where LINE is the number of lines
2573 ;; from the head of the article.
2574 (defun gnus-article-set-window-start (&optional line)
2576 (get-buffer-window gnus-article-buffer t)
2578 (set-buffer gnus-article-buffer)
2579 (goto-char (point-min))
2582 (gnus-message 6 "Moved to bookmark")
2583 (search-forward "\n\n" nil t)
2587 (defun gnus-article-prepare (article &optional all-headers header)
2588 "Prepare ARTICLE in article mode buffer.
2589 ARTICLE should either be an article number or a Message-ID.
2590 If ARTICLE is an id, HEADER should be the article headers.
2591 If ALL-HEADERS is non-nil, no headers are hidden."
2593 ;; Make sure we start in a summary buffer.
2594 (unless (eq major-mode 'gnus-summary-mode)
2595 (set-buffer gnus-summary-buffer))
2596 (setq gnus-summary-buffer (current-buffer))
2597 (let* ((gnus-article (if header (mail-header-number header) article))
2598 (summary-buffer (current-buffer))
2599 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2600 (group gnus-newsgroup-name)
2603 (gnus-article-setup-buffer)
2604 (set-buffer gnus-article-buffer)
2605 ;; Deactivate active regions.
2606 (when (and (boundp 'transient-mark-mode)
2607 transient-mark-mode)
2608 (setq mark-active nil))
2609 (if (not (setq result (let ((buffer-read-only nil))
2610 (gnus-request-article-this-buffer
2612 ;; There is no such article.
2614 (when (and (numberp article)
2615 (not (memq article gnus-newsgroup-sparse)))
2616 (setq gnus-article-current
2617 (cons gnus-newsgroup-name article))
2618 (set-buffer gnus-summary-buffer)
2619 (setq gnus-current-article article)
2620 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2622 (gnus-summary-set-agent-mark article)
2623 (message "Message marked for downloading"))
2624 (gnus-summary-mark-article article gnus-canceled-mark)
2625 (unless (memq article gnus-newsgroup-sparse)
2627 "No such article (may have expired or been canceled)")))))
2628 (if (or (eq result 'pseudo)
2629 (eq result 'nneething))
2632 (set-buffer summary-buffer)
2633 (push article gnus-newsgroup-history)
2634 (setq gnus-last-article gnus-current-article
2635 gnus-current-article 0
2636 gnus-current-headers nil
2637 gnus-article-current nil)
2638 (if (eq result 'nneething)
2639 (gnus-configure-windows 'summary)
2640 (gnus-configure-windows 'article))
2641 (gnus-set-global-variables))
2642 (let ((gnus-article-mime-handle-alist-1
2643 gnus-article-mime-handle-alist))
2644 (gnus-set-mode-line 'article)))
2645 ;; The result from the `request' was an actual article -
2646 ;; or at least some text that is now displayed in the
2648 (when (and (numberp article)
2649 (not (eq article gnus-current-article)))
2650 ;; Seems like a new article has been selected.
2651 ;; `gnus-current-article' must be an article number.
2653 (set-buffer summary-buffer)
2654 (push article gnus-newsgroup-history)
2655 (setq gnus-last-article gnus-current-article
2656 gnus-current-article article
2657 gnus-current-headers
2658 (gnus-summary-article-header gnus-current-article)
2659 gnus-article-current
2660 (cons gnus-newsgroup-name gnus-current-article))
2661 (unless (vectorp gnus-current-headers)
2662 (setq gnus-current-headers nil))
2663 (gnus-summary-goto-subject gnus-current-article)
2664 (when (gnus-summary-show-thread)
2665 ;; If the summary buffer really was folded, the
2666 ;; previous goto may not actually have gone to
2667 ;; the right article, but the thread root instead.
2669 (gnus-summary-goto-subject gnus-current-article))
2670 (gnus-run-hooks 'gnus-mark-article-hook)
2671 (gnus-set-mode-line 'summary)
2672 (when (gnus-visual-p 'article-highlight 'highlight)
2673 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2674 ;; Set the global newsgroup variables here.
2675 (gnus-set-global-variables)
2676 (setq gnus-have-all-headers
2677 (or all-headers gnus-show-all-headers))))
2678 (when (or (numberp article)
2680 (gnus-article-prepare-display)
2682 (goto-char (point-min))
2683 (setq gnus-page-broken
2684 (when gnus-break-pages
2685 (gnus-narrow-to-page)
2687 (let ((gnus-article-mime-handle-alist-1
2688 gnus-article-mime-handle-alist))
2689 (gnus-set-mode-line 'article))
2691 (set-window-point (get-buffer-window (current-buffer)) (point))
2692 (gnus-configure-windows 'article)
2696 (defun gnus-article-prepare-display ()
2697 "Make the current buffer look like a nice article."
2698 ;; Hooks for getting information from the article.
2699 ;; This hook must be called before being narrowed.
2700 (let ((gnus-article-buffer (current-buffer))
2702 (unless (eq major-mode 'gnus-article-mode)
2703 (gnus-article-mode))
2704 (setq buffer-read-only nil
2705 gnus-article-wash-types nil)
2706 (gnus-run-hooks 'gnus-tmp-internal-hook)
2707 (gnus-run-hooks 'gnus-article-prepare-hook)
2708 (when gnus-display-mime-function
2709 (funcall gnus-display-mime-function))))
2712 ;;; Gnus MIME viewing functions
2715 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2716 "The following specs can be used:
2718 %T MIME type, along with additional info
2719 %n The `name' parameter
2720 %d The description, if any
2721 %l The length of the encoded part
2722 %p The part identifier number
2723 %e Dots if the part isn't displayed")
2725 (defvar gnus-mime-button-line-format-alist
2726 '((?t gnus-tmp-type ?s)
2727 (?T gnus-tmp-type-long ?s)
2728 (?n gnus-tmp-name ?s)
2729 (?d gnus-tmp-description ?s)
2731 (?l gnus-tmp-length ?d)
2732 (?e gnus-tmp-dots ?s)))
2734 (defvar gnus-mime-button-commands
2735 '((gnus-article-press-button "\r" "Toggle Display")
2736 (gnus-mime-view-part "v" "View Interactively...")
2737 (gnus-mime-view-part-as-type "t" "View As Type...")
2738 (gnus-mime-save-part "o" "Save...")
2739 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2740 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2741 (gnus-mime-internalize-part "E" "View Internally")
2742 (gnus-mime-externalize-part "e" "View Externally")
2743 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2745 (defun gnus-article-mime-part-status ()
2746 (if gnus-article-mime-handle-alist-1
2747 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2750 (defvar gnus-mime-button-map nil)
2751 (unless gnus-mime-button-map
2752 (setq gnus-mime-button-map (make-sparse-keymap))
2753 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2754 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2755 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2757 (define-key gnus-mime-button-map (cadr c) (car c)))
2758 gnus-mime-button-commands))
2760 (defun gnus-mime-button-menu (event)
2761 "Construct a context-sensitive menu of MIME commands."
2764 (let ((pos (event-start event)))
2765 (set-buffer (window-buffer (posn-window pos)))
2766 (goto-char (posn-point pos))
2767 (gnus-article-check-buffer)
2768 (let ((response (x-popup-menu
2770 ("" ,@(mapcar (lambda (c)
2771 (cons (caddr c) (car c)))
2772 gnus-mime-button-commands))))))
2774 (funcall response))))))
2776 (defun gnus-mime-view-all-parts (&optional handles)
2777 "View all the MIME parts."
2779 (save-current-buffer
2780 (set-buffer gnus-article-buffer)
2781 (let ((handles (or handles gnus-article-mime-handles))
2782 (mail-parse-charset gnus-newsgroup-charset)
2783 (mail-parse-ignored-charsets
2784 (save-excursion (set-buffer gnus-summary-buffer)
2785 gnus-newsgroup-ignored-charsets)))
2786 (if (stringp (car handles))
2787 (gnus-mime-view-all-parts (cdr handles))
2788 (mapcar 'mm-display-part handles)))))
2790 (defun gnus-mime-save-part ()
2791 "Save the MIME part under point."
2793 (gnus-article-check-buffer)
2794 (let ((data (get-text-property (point) 'gnus-data)))
2795 (mm-save-part data)))
2797 (defun gnus-mime-pipe-part ()
2798 "Pipe the MIME part under point to a process."
2800 (gnus-article-check-buffer)
2801 (let ((data (get-text-property (point) 'gnus-data)))
2802 (mm-pipe-part data)))
2804 (defun gnus-mime-view-part ()
2805 "Interactively choose a viewing method for the MIME part under point."
2807 (gnus-article-check-buffer)
2808 (let ((data (get-text-property (point) 'gnus-data)))
2809 (mm-interactively-view-part data)))
2811 (defun gnus-mime-view-part-as-type ()
2812 "Choose a MIME media type, and view the part as such."
2814 (list (completing-read "View as MIME type: " mailcap-mime-types)))
2815 (gnus-article-check-buffer)
2816 (let ((handle (get-text-property (point) 'gnus-data)))
2817 (gnus-mm-display-part handle)))
2819 (defun gnus-mime-copy-part (&optional handle)
2820 "Put the the MIME part under point into a new buffer."
2822 (gnus-article-check-buffer)
2823 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2824 (contents (mm-get-part handle))|
2825 (base (file-name-nondirectory
2827 (mail-content-type-get (mm-handle-type handle) 'name)
2828 (mail-content-type-get (mm-handle-type handle)
2831 (buffer (generate-new-buffer base)))
2832 (switch-to-buffer buffer)
2834 ;; We do it this way to make `normal-mode' set the appropriate mode.
2837 (setq buffer-file-name (expand-file-name base))
2839 (setq buffer-file-name nil))
2840 (goto-char (point-min))))
2842 (defun gnus-mime-inline-part (&optional handle)
2843 "Insert the MIME part under point into the current buffer."
2845 (gnus-article-check-buffer)
2846 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2850 (if (mm-handle-undisplayer handle)
2851 (mm-remove-part handle)
2852 (setq contents (mm-get-part handle))
2854 (mm-insert-inline handle contents)
2857 (defun gnus-mime-externalize-part (&optional handle)
2858 "View the MIME part under point with an external viewer."
2860 (gnus-article-check-buffer)
2861 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2862 (mm-user-display-methods nil)
2863 (mm-inline-large-images nil)
2864 (mail-parse-charset gnus-newsgroup-charset)
2865 (mail-parse-ignored-charsets
2866 (save-excursion (set-buffer gnus-summary-buffer)
2867 gnus-newsgroup-ignored-charsets)))
2868 (if (mm-handle-undisplayer handle)
2869 (mm-remove-part handle)
2870 (mm-display-part handle))))
2872 (defun gnus-mime-internalize-part (&optional handle)
2873 "View the MIME part under point with an internal viewer."
2875 (gnus-article-check-buffer)
2876 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2877 (mm-user-display-methods '((".*" . inline)))
2878 (mm-inline-large-images t)
2879 (mail-parse-charset gnus-newsgroup-charset)
2880 (mail-parse-ignored-charsets
2881 (save-excursion (set-buffer gnus-summary-buffer)
2882 gnus-newsgroup-ignored-charsets)))
2883 (if (mm-handle-undisplayer handle)
2884 (mm-remove-part handle)
2885 (mm-display-part handle))))
2887 (defun gnus-article-part-wrapper (n function)
2888 (save-current-buffer
2889 (set-buffer gnus-article-buffer)
2890 (when (> n (length gnus-article-mime-handle-alist))
2891 (error "No such part"))
2892 (gnus-article-goto-part n)
2893 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2894 (funcall function handle))))
2896 (defun gnus-article-pipe-part (n)
2897 "Pipe MIME part N, which is the numerical prefix."
2899 (gnus-article-part-wrapper n 'mm-pipe-part))
2901 (defun gnus-article-save-part (n)
2902 "Save MIME part N, which is the numerical prefix."
2904 (gnus-article-part-wrapper n 'mm-save-part))
2906 (defun gnus-article-interactively-view-part (n)
2907 "View MIME part N interactively, which is the numerical prefix."
2909 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2911 (defun gnus-article-copy-part (n)
2912 "Copy MIME part N, which is the numerical prefix."
2914 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2916 (defun gnus-article-externalize-part (n)
2917 "View MIME part N externally, which is the numerical prefix."
2919 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2921 (defun gnus-article-inline-part (n)
2922 "Inline MIME part N, which is the numerical prefix."
2924 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2926 (defun gnus-article-view-part (n)
2927 "View MIME part N, which is the numerical prefix."
2929 (save-current-buffer
2930 (set-buffer gnus-article-buffer)
2931 (when (> n (length gnus-article-mime-handle-alist))
2932 (error "No such part"))
2933 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2934 (when (gnus-article-goto-part n)
2935 (if (equal (car handle) "multipart/alternative")
2936 (gnus-article-press-button)
2937 (when (eq (gnus-mm-display-part handle) 'internal)
2938 (gnus-set-window-start)))))))
2940 (defun gnus-mm-display-part (handle)
2941 "Display HANDLE and fix MIME button."
2942 (let ((id (get-text-property (point) 'gnus-part))
2947 (let ((window (selected-window))
2948 (mail-parse-charset gnus-newsgroup-charset)
2949 (mail-parse-ignored-charsets
2950 (save-excursion (set-buffer gnus-summary-buffer)
2951 gnus-newsgroup-ignored-charsets)))
2954 (let ((win (get-buffer-window (current-buffer) t))
2957 (select-window win))
2960 (if (mm-handle-displayed-p handle)
2961 ;; This will remove the part.
2962 (mm-display-part handle)
2964 (narrow-to-region (point) (1+ (point)))
2965 (mm-display-part handle)
2966 ;; We narrow to the part itself and
2967 ;; then call the treatment functions.
2968 (goto-char (point-min))
2970 (narrow-to-region (point) (point-max))
2973 (1- (length gnus-article-mime-handles))
2974 (mm-handle-media-type handle)))))
2975 (select-window window))))
2977 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2978 (gnus-insert-mime-button
2979 handle id (list (mm-handle-displayed-p handle)))
2980 (goto-char point))))
2982 (defun gnus-article-goto-part (n)
2983 "Go to MIME part N."
2984 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2986 (goto-char point))))
2988 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2989 (let ((gnus-tmp-name
2990 (or (mail-content-type-get (mm-handle-type handle)
2992 (mail-content-type-get (mm-handle-disposition handle)
2995 (gnus-tmp-type (mm-handle-media-type handle))
2996 (gnus-tmp-description
2997 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3000 (if (if displayed (car displayed)
3001 (mm-handle-displayed-p handle))
3003 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3005 gnus-tmp-type-long b e)
3006 (when (string-match ".*/" gnus-tmp-name)
3007 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3008 (setq gnus-tmp-type-long (concat gnus-tmp-type
3009 (and (not (equal gnus-tmp-name ""))
3010 (concat "; " gnus-tmp-name))))
3011 (or (equal gnus-tmp-description "")
3012 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3017 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3018 `(local-map ,gnus-mime-button-map
3019 keymap ,gnus-mime-button-map
3020 gnus-callback gnus-mm-display-part
3021 gnus-part ,gnus-tmp-id
3022 article-type annotation
3025 (widget-convert-button 'link b e
3027 :action 'gnus-widget-press-button
3028 :button-keymap gnus-mime-button-map
3031 ;; Needed to properly clear the message
3032 ;; due to a bug in wid-edit
3033 (setq help-echo-owns-message t)
3035 "Click to %s the MIME part; %s for more options"
3036 (if (mm-handle-displayed-p
3037 (widget-get widget :mime-handle))
3039 (if gnus-xemacs "button3" "mouse-3"))))))
3041 (defun gnus-widget-press-button (elems el)
3042 (goto-char (widget-get elems :from))
3043 (gnus-article-press-button))
3045 (defvar gnus-displaying-mime nil)
3047 (defun gnus-display-mime (&optional ihandles)
3048 "Display the MIME parts."
3050 (save-selected-window
3051 (let ((window (get-buffer-window gnus-article-buffer))
3054 (select-window window)
3055 ;; We have to do this since selecting the window
3056 ;; may change the point. So we set the window point.
3057 (set-window-point window point)))
3058 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3059 buffer-read-only handle name type b e display)
3060 (when (and (not ihandles)
3061 (not gnus-displaying-mime))
3062 ;; Top-level call; we clean up.
3063 (when gnus-article-mime-handles
3064 (mm-destroy-parts gnus-article-mime-handles)
3065 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3066 (setq gnus-article-mime-handles handles)
3067 ;; We allow users to glean info from the handles.
3068 (when gnus-article-mime-part-function
3069 (gnus-mime-part-function handles)))
3071 (or (not (stringp (car handles)))
3074 (when (and (not ihandles)
3075 (not gnus-displaying-mime))
3076 ;; Clean up for mime parts.
3078 (delete-region (point) (point-max)))
3079 (let ((gnus-displaying-mime t))
3080 (gnus-mime-display-part handles)))
3083 (narrow-to-region (point) (point-max))
3084 (gnus-treat-article nil 1 1)
3087 ;; Highlight the headers.
3091 (narrow-to-region (point-min) (point))
3092 (gnus-treat-article 'head))))))))
3094 (defvar gnus-mime-display-multipart-as-mixed nil)
3096 (defun gnus-mime-display-part (handle)
3099 ((not (stringp (car handle)))
3100 (gnus-mime-display-single handle))
3101 ;; User-defined multipart
3102 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3103 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3105 ;; multipart/alternative
3106 ((and (equal (car handle) "multipart/alternative")
3107 (not gnus-mime-display-multipart-as-mixed))
3108 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3109 (push (cons id handle) gnus-article-mime-handle-alist)
3110 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3111 ;; multipart/related
3112 ((and (equal (car handle) "multipart/related")
3113 (not gnus-mime-display-multipart-as-mixed))
3114 ;;;!!!We should find the start part, but we just default
3115 ;;;!!!to the first part.
3116 (gnus-mime-display-part (cadr handle)))
3117 ;; Other multiparts are handled like multipart/mixed.
3119 (gnus-mime-display-mixed (cdr handle)))))
3121 (defun gnus-mime-part-function (handles)
3122 (if (stringp (car handles))
3123 (mapcar 'gnus-mime-part-function (cdr handles))
3124 (funcall gnus-article-mime-part-function handles)))
3126 (defun gnus-mime-display-mixed (handles)
3127 (mapcar 'gnus-mime-display-part handles))
3129 (defun gnus-mime-display-single (handle)
3130 (let ((type (mm-handle-media-type handle))
3131 (ignored gnus-ignored-mime-types)
3138 (when (string-match (pop ignored) type)
3139 (throw 'ignored nil)))
3140 (if (and (setq not-attachment
3141 (or (not (mm-handle-disposition handle))
3142 (equal (car (mm-handle-disposition handle))
3144 (mm-attachment-override-p handle)))
3145 (mm-automatic-display-p handle)
3146 (or (mm-inlined-p handle)
3147 (mm-automatic-external-display-p type)))
3149 (when (equal (mm-handle-media-supertype handle) "text")
3151 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3152 (push (cons id handle) gnus-article-mime-handle-alist)
3153 (when (or (not display)
3154 (not (gnus-unbuttonized-mime-type-p type)))
3155 (gnus-article-insert-newline)
3156 (gnus-insert-mime-button
3157 handle id (list (or display (and not-attachment text))))
3158 (gnus-article-insert-newline)
3159 (gnus-article-insert-newline)
3161 (let ((beg (point)))
3167 (let ((mail-parse-charset gnus-newsgroup-charset)
3168 (mail-parse-ignored-charsets
3169 (save-excursion (set-buffer gnus-summary-buffer)
3170 gnus-newsgroup-ignored-charsets)))
3171 (mm-display-part handle t))
3172 (goto-char (point-max)))
3173 ((and text not-attachment)
3177 (gnus-article-insert-newline)
3178 (mm-insert-inline handle (mm-get-part handle))
3179 (goto-char (point-max))))
3183 (narrow-to-region beg (point))
3185 nil (length gnus-article-mime-handle-alist)
3186 (1- (length gnus-article-mime-handles))
3187 (mm-handle-media-type handle)))))))))
3189 (defun gnus-unbuttonized-mime-type-p (type)
3190 "Say whether TYPE is to be unbuttonized."
3191 (unless gnus-inhibit-mime-unbuttonizing
3193 (let ((types gnus-unbuttonized-mime-types))
3195 (when (string-match (pop types) type)
3196 (throw 'found t)))))))
3198 (defun gnus-article-insert-newline ()
3199 "Insert a newline, but mark it as undeletable."
3200 (gnus-put-text-property
3201 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3203 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3204 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3207 handle buffer-read-only from props begend not-pref)
3208 (save-window-excursion
3211 (narrow-to-region (car ibegend)
3214 (goto-char (car ibegend))
3217 (delete-region (point-min) (point-max))
3218 (mm-remove-parts handles))
3219 (setq begend (list (point-marker)))
3221 (unless (setq not-pref (cadr (member preferred ihandles)))
3222 (setq not-pref (car ihandles)))
3224 (not (gnus-unbuttonized-mime-type-p
3225 "multipart/alternative")))
3226 (gnus-add-text-properties
3229 (insert (format "%d. " id))
3233 (unless ,(not ibegend)
3234 (setq gnus-article-mime-handle-alist
3235 ',gnus-article-mime-handle-alist))
3236 (gnus-mime-display-alternative
3237 ',ihandles ',not-pref ',begend ,id))
3238 local-map ,gnus-mime-button-map
3239 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3240 face ,gnus-article-button-face
3241 keymap ,gnus-mime-button-map
3244 (widget-convert-button 'link from (point)
3245 :action 'gnus-widget-press-button
3246 :button-keymap gnus-widget-button-keymap)
3248 (while (setq handle (pop handles))
3249 (gnus-add-text-properties
3252 (insert (format "(%c) %-18s"
3253 (if (equal handle preferred) ?* ? )
3254 (mm-handle-media-type handle)))
3258 (unless ,(not ibegend)
3259 (setq gnus-article-mime-handle-alist
3260 ',gnus-article-mime-handle-alist))
3261 (gnus-mime-display-alternative
3262 ',ihandles ',handle ',begend ,id))
3263 local-map ,gnus-mime-button-map
3264 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3265 face ,gnus-article-button-face
3266 keymap ,gnus-mime-button-map
3269 (widget-convert-button 'link from (point)
3270 :action 'gnus-widget-press-button
3271 :button-keymap gnus-widget-button-keymap)
3275 (if (stringp (car preferred))
3276 (gnus-display-mime preferred)
3277 (let ((mail-parse-charset gnus-newsgroup-charset)
3278 (mail-parse-ignored-charsets
3279 (save-excursion (set-buffer gnus-summary-buffer)
3280 gnus-newsgroup-ignored-charsets)))
3281 (mm-display-part preferred)
3285 (narrow-to-region (car begend) (point-max))
3287 nil (length gnus-article-mime-handle-alist)
3288 (1- (length gnus-article-mime-handles))
3289 (mm-handle-media-type handle))))))
3290 (goto-char (point-max))
3291 (setcdr begend (point-marker)))))
3293 (goto-char point))))
3295 (defun gnus-article-wash-status ()
3296 "Return a string which display status of article washing."
3298 (set-buffer gnus-article-buffer)
3299 (let ((cite (memq 'cite gnus-article-wash-types))
3300 (headers (memq 'headers gnus-article-wash-types))
3301 (boring (memq 'boring-headers gnus-article-wash-types))
3302 (pgp (memq 'pgp gnus-article-wash-types))
3303 (pem (memq 'pem gnus-article-wash-types))
3304 (signature (memq 'signature gnus-article-wash-types))
3305 (overstrike (memq 'overstrike gnus-article-wash-types))
3306 (emphasis (memq 'emphasis gnus-article-wash-types)))
3307 (format "%c%c%c%c%c%c"
3309 (if (or headers boring) ?h ? )
3310 (if (or pgp pem) ?p ? )
3311 (if signature ?s ? )
3312 (if overstrike ?o ? )
3313 (if emphasis ?e ? )))))
3315 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3317 (defun gnus-article-maybe-hide-headers ()
3318 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3319 Provided for backwards compatibility."
3320 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3321 (not (save-excursion (set-buffer gnus-summary-buffer)
3322 gnus-have-all-headers)))
3323 (not gnus-inhibit-hiding))
3324 (gnus-article-hide-headers)))
3328 (defun gnus-output-to-file (file-name)
3329 "Append the current article to a file named FILE-NAME."
3330 (let ((artbuf (current-buffer)))
3332 (insert-buffer-substring artbuf)
3333 ;; Append newline at end of the buffer as separator, and then
3335 (goto-char (point-max))
3337 (mm-append-to-file (point-min) (point-max) file-name)
3340 (defun gnus-narrow-to-page (&optional arg)
3341 "Narrow the article buffer to a page.
3342 If given a numerical ARG, move forward ARG pages."
3344 (setq arg (if arg (prefix-numeric-value arg) 0))
3346 (set-buffer gnus-article-buffer)
3347 (goto-char (point-min))
3349 ;; Remove any old next/prev buttons.
3350 (when (gnus-visual-p 'page-marker)
3351 (let ((buffer-read-only nil))
3352 (gnus-remove-text-with-property 'gnus-prev)
3353 (gnus-remove-text-with-property 'gnus-next)))
3356 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3358 (re-search-forward page-delimiter nil 'move arg)))
3359 (goto-char (match-end 0)))
3362 (if (re-search-forward page-delimiter nil 'move)
3365 (when (and (gnus-visual-p 'page-marker)
3366 (not (= (point-min) 1)))
3368 (goto-char (point-min))
3369 (gnus-insert-prev-page-button)))
3370 (when (and (gnus-visual-p 'page-marker)
3371 (< (+ (point-max) 2) (buffer-size)))
3373 (goto-char (point-max))
3374 (gnus-insert-next-page-button)))))
3376 ;; Article mode commands
3378 (defun gnus-article-goto-next-page ()
3379 "Show the next page of the article."
3381 (when (gnus-article-next-page)
3382 (goto-char (point-min))
3383 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3385 (defun gnus-article-goto-prev-page ()
3386 "Show the next page of the article."
3388 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3389 (gnus-article-prev-page nil)))
3391 (defun gnus-article-next-page (&optional lines)
3392 "Show the next page of the current article.
3393 If end of article, return non-nil. Otherwise return nil.
3394 Argument LINES specifies lines to be scrolled up."
3396 (move-to-window-line -1)
3399 (and (pos-visible-in-window-p) ;Not continuation line.
3401 ;; Nothing in this page.
3402 (if (or (not gnus-page-broken)
3405 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3407 (gnus-narrow-to-page 1) ;Go to next page.
3409 ;; More in this page.
3410 (let ((scroll-in-place nil))
3414 ;; Long lines may cause an end-of-buffer error.
3415 (goto-char (point-max)))))
3416 (move-to-window-line 0)
3419 (defun gnus-article-prev-page (&optional lines)
3420 "Show previous page of current article.
3421 Argument LINES specifies lines to be scrolled down."
3423 (move-to-window-line 0)
3424 (if (and gnus-page-broken
3426 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3428 (gnus-narrow-to-page -1) ;Go to previous page.
3429 (goto-char (point-max))
3431 (let ((scroll-in-place nil))
3435 (beginning-of-buffer
3436 (goto-char (point-min))))
3437 (move-to-window-line 0)))))
3439 (defun gnus-article-refer-article ()
3440 "Read article specified by message-id around point."
3442 (let ((point (point)))
3443 (search-forward ">" nil t) ;Move point to end of "<....>".
3444 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3445 (let ((message-id (match-string 1)))
3447 (set-buffer gnus-summary-buffer)
3448 (gnus-summary-refer-article message-id))
3450 (error "No references around point"))))
3452 (defun gnus-article-show-summary ()
3453 "Reconfigure windows to show summary buffer."
3455 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3456 (error "There is no summary buffer for this article buffer")
3457 (gnus-article-set-globals)
3458 (gnus-configure-windows 'article)
3459 (gnus-summary-goto-subject gnus-current-article)
3460 (gnus-summary-position-point)))
3462 (defun gnus-article-describe-briefly ()
3463 "Describe article mode commands briefly."
3465 (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")))
3467 (defun gnus-article-summary-command ()
3468 "Execute the last keystroke in the summary buffer."
3470 (let ((obuf (current-buffer))
3471 (owin (current-window-configuration))
3473 (switch-to-buffer gnus-article-current-summary 'norecord)
3474 (setq func (lookup-key (current-local-map) (this-command-keys)))
3475 (call-interactively func)
3477 (set-window-configuration owin)
3478 (set-window-point (get-buffer-window (current-buffer)) (point))))
3480 (defun gnus-article-summary-command-nosave ()
3481 "Execute the last keystroke in the summary buffer."
3484 (pop-to-buffer gnus-article-current-summary 'norecord)
3485 (setq func (lookup-key (current-local-map) (this-command-keys)))
3486 (call-interactively func)))
3488 (defun gnus-article-check-buffer ()
3489 "Beep if not in an article buffer."
3490 (unless (equal major-mode 'gnus-article-mode)
3491 (error "Command invoked outside of a Gnus article buffer")))
3493 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3494 "Read a summary buffer key sequence and execute it from the article buffer."
3496 (gnus-article-check-buffer)
3498 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3499 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3500 "=" "^" "\M-^" "|"))
3506 '("n" "Gn" "p" "Gp"))
3509 (set-buffer gnus-article-current-summary)
3510 (let (gnus-pick-mode)
3511 (push (or key last-command-event) unread-command-events)
3512 (setq keys (if gnus-xemacs
3513 (events-to-keys (read-key-sequence nil))
3514 (read-key-sequence nil)))))
3518 (if (or (member keys nosaves)
3519 (member keys nosave-but-article)
3520 (member keys nosave-in-article))
3522 (save-window-excursion
3523 (pop-to-buffer gnus-article-current-summary 'norecord)
3524 ;; We disable the pick minor mode commands.
3525 (let (gnus-pick-mode)
3526 (setq func (lookup-key (current-local-map) keys))))
3529 (unless (member keys nosave-in-article)
3530 (set-buffer gnus-article-current-summary))
3531 (call-interactively func)
3532 (setq new-sum-point (point)))
3533 (when (member keys nosave-but-article)
3534 (pop-to-buffer gnus-article-buffer 'norecord)))
3535 ;; These commands should restore window configuration.
3536 (let ((obuf (current-buffer))
3537 (owin (current-window-configuration))
3539 (summary gnus-article-current-summary)
3540 func in-buffer selected)
3541 (if not-restore-window
3542 (pop-to-buffer summary 'norecord)
3543 (switch-to-buffer summary 'norecord))
3544 (setq in-buffer (current-buffer))
3545 ;; We disable the pick minor mode commands.
3546 (if (setq func (let (gnus-pick-mode)
3547 (lookup-key (current-local-map) keys)))
3549 (call-interactively func)
3550 (setq new-sum-point (point)))
3552 (when (eq in-buffer (current-buffer))
3553 (setq selected (gnus-summary-select-article))
3555 (unless not-restore-window
3556 (set-window-configuration owin))
3557 (when (eq selected 'old)
3559 (set-window-start (get-buffer-window (current-buffer))
3561 (set-window-point (get-buffer-window (current-buffer))
3563 (let ((win (get-buffer-window gnus-article-current-summary)))
3565 (set-window-point win new-sum-point))))))))
3567 (defun gnus-article-hide (&optional arg force)
3568 "Hide all the gruft in the current article.
3569 This means that PGP stuff, signatures, cited text and (some)
3570 headers will be hidden.
3571 If given a prefix, show the hidden text instead."
3572 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3573 (gnus-article-hide-headers arg)
3574 (gnus-article-hide-list-identifiers arg)
3575 (gnus-article-hide-pgp arg)
3576 (gnus-article-hide-citation-maybe arg force)
3577 (gnus-article-hide-signature arg))
3579 (defun gnus-article-maybe-highlight ()
3580 "Do some article highlighting if article highlighting is requested."
3581 (when (gnus-visual-p 'article-highlight 'highlight)
3582 (gnus-article-highlight-some)))
3584 (defun gnus-check-group-server ()
3585 ;; Make sure the connection to the server is alive.
3586 (unless (gnus-server-opened
3587 (gnus-find-method-for-group gnus-newsgroup-name))
3588 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3589 (gnus-request-group gnus-newsgroup-name t)))
3591 (defun gnus-request-article-this-buffer (article group)
3592 "Get an article and insert it into this buffer."
3593 (let (do-update-line sparse-header)
3597 (gnus-kill-all-overlays)
3598 (setq group (or group gnus-newsgroup-name))
3600 ;; Using `gnus-request-article' directly will insert the article into
3601 ;; `nntp-server-buffer' - so we'll save some time by not having to
3602 ;; copy it from the server buffer into the article buffer.
3604 ;; We only request an article by message-id when we do not have the
3605 ;; headers for it, so we'll have to get those.
3606 (when (stringp article)
3607 (let ((gnus-override-method gnus-refer-article-method))
3608 (gnus-read-header article)))
3610 ;; If the article number is negative, that means that this article
3611 ;; doesn't belong in this newsgroup (possibly), so we find its
3612 ;; message-id and request it by id instead of number.
3613 (when (and (numberp article)
3615 (get-buffer gnus-summary-buffer)
3616 (gnus-buffer-exists-p gnus-summary-buffer))
3618 (set-buffer gnus-summary-buffer)
3619 (let ((header (gnus-summary-article-header article)))
3622 ((memq article gnus-newsgroup-sparse)
3623 ;; This is a sparse gap article.
3624 (setq do-update-line article)
3625 (setq article (mail-header-id header))
3626 (let ((gnus-override-method gnus-refer-article-method))
3627 (setq sparse-header (gnus-read-header article)))
3628 (setq gnus-newsgroup-sparse
3629 (delq article gnus-newsgroup-sparse)))
3631 ;; It's a real article.
3632 (setq article (mail-header-id header)))
3634 ;; It is an extracted pseudo-article.
3635 (setq article 'pseudo)
3636 (gnus-request-pseudo-article header))))
3638 (let ((method (gnus-find-method-for-group
3639 gnus-newsgroup-name)))
3640 (when (and (eq (car method) 'nneething)
3643 (file-name-as-directory
3644 (or (cadr (assq 'nneething-address method))
3646 (mail-header-subject header))))
3647 (when (file-directory-p dir)
3648 (setq article 'nneething)
3649 (gnus-group-enter-directory dir))))))))
3652 ;; Refuse to select canceled articles.
3653 ((and (numberp article)
3655 (get-buffer gnus-summary-buffer)
3656 (gnus-buffer-exists-p gnus-summary-buffer)
3657 (eq (cdr (save-excursion
3658 (set-buffer gnus-summary-buffer)
3659 (assq article gnus-newsgroup-reads)))
3660 gnus-canceled-mark))
3662 ;; We first check `gnus-original-article-buffer'.
3663 ((and (get-buffer gnus-original-article-buffer)
3666 (set-buffer gnus-original-article-buffer)
3667 (and (equal (car gnus-original-article) group)
3668 (eq (cdr gnus-original-article) article))))
3669 (insert-buffer-substring gnus-original-article-buffer)
3671 ;; Check the backlog.
3672 ((and gnus-keep-backlog
3673 (gnus-backlog-request-article group article (current-buffer)))
3675 ;; Check asynchronous pre-fetch.
3676 ((gnus-async-request-fetched-article group article (current-buffer))
3677 (gnus-async-prefetch-next group article gnus-summary-buffer)
3678 (when (and (numberp article) gnus-keep-backlog)
3679 (gnus-backlog-enter-article group article (current-buffer)))
3682 ((and gnus-use-cache
3684 (gnus-cache-request-article article group))
3686 ;; Get the article and put into the article buffer.
3687 ((or (stringp article) (numberp article))
3688 (let ((gnus-override-method
3689 (and (stringp article) gnus-refer-article-method))
3690 (buffer-read-only nil))
3692 (gnus-kill-all-overlays)
3693 (gnus-check-group-server)
3694 (when (gnus-request-article article group (current-buffer))
3695 (when (numberp article)
3696 (gnus-async-prefetch-next group article gnus-summary-buffer)
3697 (when gnus-keep-backlog
3698 (gnus-backlog-enter-article
3699 group article (current-buffer))))
3704 ;; Associate this article with the current summary buffer.
3705 (setq gnus-article-current-summary gnus-summary-buffer)
3707 ;; Take the article from the original article buffer
3708 ;; and place it in the buffer it's supposed to be in.
3709 (when (and (get-buffer gnus-article-buffer)
3710 (equal (buffer-name (current-buffer))
3711 (buffer-name (get-buffer gnus-article-buffer))))
3713 (if (get-buffer gnus-original-article-buffer)
3714 (set-buffer gnus-original-article-buffer)
3715 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3716 (buffer-disable-undo)
3717 (setq major-mode 'gnus-original-article-mode)
3718 (setq buffer-read-only t))
3719 (let (buffer-read-only)
3721 (insert-buffer-substring gnus-article-buffer))
3722 (setq gnus-original-article (cons group article)))
3725 (run-hooks 'gnus-article-decode-hook)
3726 ;; Mark article as decoded or not.
3727 (setq gnus-article-decoded-p gnus-article-decode-hook))
3729 ;; Update sparse articles.
3730 (when (and do-update-line
3731 (or (numberp article)
3733 (let ((buf (current-buffer)))
3734 (set-buffer gnus-summary-buffer)
3735 (gnus-summary-update-article do-update-line sparse-header)
3736 (gnus-summary-goto-subject do-update-line nil t)
3737 (set-window-point (get-buffer-window (current-buffer) t)
3739 (set-buffer buf))))))
3745 (defcustom gnus-article-edit-mode-hook nil
3746 "Hook run in article edit mode buffers."
3747 :group 'gnus-article-various
3750 (defvar gnus-article-edit-done-function nil)
3752 (defvar gnus-article-edit-mode-map nil)
3754 ;; Should we be using derived.el for this?
3755 (unless gnus-article-edit-mode-map
3756 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3757 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3759 (gnus-define-keys gnus-article-edit-mode-map
3760 "\C-c\C-c" gnus-article-edit-done
3761 "\C-c\C-k" gnus-article-edit-exit)
3763 (gnus-define-keys (gnus-article-edit-wash-map
3764 "\C-c\C-w" gnus-article-edit-mode-map)
3765 "f" gnus-article-edit-full-stops))
3767 (defun gnus-article-edit-mode ()
3768 "Major mode for editing articles.
3769 This is an extended text-mode.
3771 \\{gnus-article-edit-mode-map}"
3773 (setq major-mode 'gnus-article-edit-mode)
3774 (setq mode-name "Article Edit")
3775 (use-local-map gnus-article-edit-mode-map)
3776 (make-local-variable 'gnus-article-edit-done-function)
3777 (make-local-variable 'gnus-prev-winconf)
3778 (setq buffer-read-only nil)
3779 (buffer-enable-undo)
3781 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3783 (defun gnus-article-edit (&optional force)
3784 "Edit the current article.
3785 This will have permanent effect only in mail groups.
3786 If FORCE is non-nil, allow editing of articles even in read-only
3789 (when (and (not force)
3790 (gnus-group-read-only-p))
3791 (error "The current newsgroup does not support article editing"))
3792 (gnus-article-date-original)
3793 (gnus-article-edit-article
3795 `(lambda (no-highlight)
3797 (gnus-summary-edit-article-done
3798 ,(or (mail-header-references gnus-current-headers) "")
3799 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3801 (defun gnus-article-edit-article (start-func exit-func)
3802 "Start editing the contents of the current article buffer."
3803 (let ((winconf (current-window-configuration)))
3804 (set-buffer gnus-article-buffer)
3805 (gnus-article-edit-mode)
3806 (funcall start-func)
3807 (gnus-configure-windows 'edit-article)
3808 (setq gnus-article-edit-done-function exit-func)
3809 (setq gnus-prev-winconf winconf)
3810 (gnus-message 6 "C-c C-c to end edits")))
3812 (defun gnus-article-edit-done (&optional arg)
3813 "Update the article edits and exit."
3818 (when (article-goto-body)
3819 (let ((lines (count-lines (point) (point-max)))
3820 (length (- (point-max) (point)))
3821 (case-fold-search t)
3822 (body (copy-marker (point))))
3823 (goto-char (point-min))
3824 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3825 (delete-region (match-beginning 1) (match-end 1))
3826 (insert (number-to-string length)))
3827 (goto-char (point-min))
3828 (when (re-search-forward
3829 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3830 (delete-region (match-beginning 1) (match-end 1))
3831 (insert (number-to-string length)))
3832 (goto-char (point-min))
3833 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3834 (delete-region (match-beginning 1) (match-end 1))
3835 (insert (number-to-string lines)))))))
3836 (let ((func gnus-article-edit-done-function)
3837 (buf (current-buffer))
3838 (start (window-start)))
3839 (gnus-article-edit-exit)
3842 (let ((buffer-read-only nil))
3844 ;; The cache and backlog have to be flushed somewhat.
3845 (when gnus-keep-backlog
3846 (gnus-backlog-remove-article
3847 (car gnus-article-current) (cdr gnus-article-current)))
3848 ;; Flush original article as well.
3850 (when (get-buffer gnus-original-article-buffer)
3851 (set-buffer gnus-original-article-buffer)
3852 (setq gnus-original-article nil)))
3853 (when gnus-use-cache
3854 (gnus-cache-update-article
3855 (car gnus-article-current) (cdr gnus-article-current))))
3857 (set-window-start (get-buffer-window buf) start)
3858 (set-window-point (get-buffer-window buf) (point))))
3860 (defun gnus-article-edit-exit ()
3861 "Exit the article editing without updating."
3863 ;; We remove all text props from the article buffer.
3864 (let ((buf (format "%s" (buffer-string)))
3865 (curbuf (current-buffer))
3867 (window-start (window-start)))
3870 (let ((winconf gnus-prev-winconf))
3872 (set-window-configuration winconf)
3873 ;; Tippy-toe some to make sure that point remains where it was.
3874 (save-current-buffer
3876 (set-window-start (get-buffer-window (current-buffer)) window-start)
3879 (defun gnus-article-edit-full-stops ()
3880 "Interactively repair spacing at end of sentences."
3883 (goto-char (point-min))
3884 (search-forward-regexp "^$" nil t)
3885 (let ((case-fold-search nil))
3886 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3889 ;;; Article highlights
3892 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3894 ;;; Internal Variables:
3896 (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\\)"
3897 "Regular expression that matches URLs."
3898 :group 'gnus-article-buttons
3901 (defcustom gnus-button-alist
3902 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3903 0 t gnus-button-message-id 2)
3904 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3905 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3907 gnus-button-fetch-group 4)
3908 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3909 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3910 t gnus-button-message-id 3)
3911 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3912 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3913 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3914 ;; This is how URLs _should_ be embedded in text...
3915 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3917 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3918 "*Alist of regexps matching buttons in article bodies.
3920 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3921 REGEXP: is the string matching text around the button,
3922 BUTTON: is the number of the regexp grouping actually matching the button,
3923 FORM: is a lisp expression which must eval to true for the button to
3925 CALLBACK: is the function to call when the user push this button, and each
3926 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3928 CALLBACK can also be a variable, in that case the value of that
3929 variable it the real callback function."
3930 :group 'gnus-article-buttons
3931 :type '(repeat (list regexp
3932 (integer :tag "Button")
3934 (function :tag "Callback")
3937 (integer :tag "Regexp group")))))
3939 (defcustom gnus-header-button-alist
3940 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3941 0 t gnus-button-message-id 0)
3942 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3943 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3944 0 t gnus-button-mailto 0)
3945 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3946 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3947 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3948 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3949 gnus-button-message-id 3))
3950 "*Alist of headers and regexps to match buttons in article heads.
3952 This alist is very similar to `gnus-button-alist', except that each
3953 alist has an additional HEADER element first in each entry:
3955 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3957 HEADER is a regexp to match a header. For a fuller explanation, see
3958 `gnus-button-alist'."
3959 :group 'gnus-article-buttons
3960 :group 'gnus-article-headers
3961 :type '(repeat (list (regexp :tag "Header")
3963 (integer :tag "Button")
3965 (function :tag "Callback")
3968 (integer :tag "Regexp group")))))
3970 (defvar gnus-button-regexp nil)
3971 (defvar gnus-button-marker-list nil)
3972 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3974 (defvar gnus-button-last nil)
3975 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3979 (defun gnus-article-push-button (event)
3980 "Check text under the mouse pointer for a callback function.
3981 If the text under the mouse pointer has a `gnus-callback' property,
3982 call it with the value of the `gnus-data' text property."
3984 (set-buffer (window-buffer (posn-window (event-start event))))
3985 (let* ((pos (posn-point (event-start event)))
3986 (data (get-text-property pos 'gnus-data))
3987 (fun (get-text-property pos 'gnus-callback)))
3990 (funcall fun data))))
3992 (defun gnus-article-press-button ()
3993 "Check text at point for a callback function.
3994 If the text at point has a `gnus-callback' property,
3995 call it with the value of the `gnus-data' text property."
3997 (let* ((data (get-text-property (point) 'gnus-data))
3998 (fun (get-text-property (point) 'gnus-callback)))
4000 (funcall fun data))))
4002 (defun gnus-article-highlight (&optional force)
4003 "Highlight current article.
4004 This function calls `gnus-article-highlight-headers',
4005 `gnus-article-highlight-citation',
4006 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4007 do the highlighting. See the documentation for those functions."
4008 (interactive (list 'force))
4009 (gnus-article-highlight-headers)
4010 (gnus-article-highlight-citation force)
4011 (gnus-article-highlight-signature)
4012 (gnus-article-add-buttons force)
4013 (gnus-article-add-buttons-to-head))
4015 (defun gnus-article-highlight-some (&optional force)
4016 "Highlight current article.
4017 This function calls `gnus-article-highlight-headers',
4018 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4019 do the highlighting. See the documentation for those functions."
4020 (interactive (list 'force))
4021 (gnus-article-highlight-headers)
4022 (gnus-article-highlight-signature)
4023 (gnus-article-add-buttons))
4025 (defun gnus-article-highlight-headers ()
4026 "Highlight article headers as specified by `gnus-header-face-alist'."
4029 (set-buffer gnus-article-buffer)
4031 (let ((alist gnus-header-face-alist)
4032 (buffer-read-only nil)
4033 (case-fold-search t)
4034 (inhibit-point-motion-hooks t)
4035 entry regexp header-face field-face from hpoints fpoints)
4036 (article-narrow-to-head)
4037 (while (setq entry (pop alist))
4038 (goto-char (point-min))
4039 (setq regexp (concat "^\\("
4040 (if (string-equal "" (nth 0 entry))
4044 header-face (nth 1 entry)
4045 field-face (nth 2 entry))
4046 (while (and (re-search-forward regexp nil t)
4050 (unless (search-forward ":" nil t)
4052 (when (and header-face
4053 (not (memq (point) hpoints)))
4054 (push (point) hpoints)
4055 (gnus-put-text-property from (point) 'face header-face))
4056 (when (and field-face
4057 (not (memq (setq from (point)) fpoints)))
4059 (if (re-search-forward "^[^ \t]" nil t)
4061 (goto-char (point-max)))
4062 (gnus-put-text-property from (point) 'face field-face))))))))
4064 (defun gnus-article-highlight-signature ()
4065 "Highlight the signature in an article.
4066 It does this by highlighting everything after
4067 `gnus-signature-separator' using `gnus-signature-face'."
4070 (set-buffer gnus-article-buffer)
4071 (let ((buffer-read-only nil)
4072 (inhibit-point-motion-hooks t))
4074 (when (and gnus-signature-face
4075 (gnus-article-narrow-to-signature))
4076 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4077 'face gnus-signature-face)
4079 (gnus-article-search-signature)
4080 (let ((start (match-beginning 0))
4081 (end (set-marker (make-marker) (1+ (match-end 0)))))
4082 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4085 (defun gnus-button-in-region-p (b e prop)
4086 "Say whether PROP exists in the region."
4087 (text-property-not-all b e prop nil))
4089 (defun gnus-article-add-buttons (&optional force)
4090 "Find external references in the article and make buttons of them.
4091 \"External references\" are things like Message-IDs and URLs, as
4092 specified by `gnus-button-alist'."
4093 (interactive (list 'force))
4095 (set-buffer gnus-article-buffer)
4096 (let ((buffer-read-only nil)
4097 (inhibit-point-motion-hooks t)
4098 (case-fold-search t)
4099 (alist gnus-button-alist)
4101 ;; Remove all old markers.
4102 (let (marker entry new-list)
4103 (while (setq marker (pop gnus-button-marker-list))
4104 (if (or (< marker (point-min)) (>= marker (point-max)))
4105 (push marker new-list)
4107 (when (setq entry (gnus-button-entry))
4108 (put-text-property (match-beginning (nth 1 entry))
4109 (match-end (nth 1 entry))
4110 'gnus-callback nil))
4111 (set-marker marker nil)))
4112 (setq gnus-button-marker-list new-list))
4113 ;; We skip the headers.
4116 (while (setq entry (pop alist))
4117 (setq regexp (car entry))
4119 (while (re-search-forward regexp nil t)
4120 (let* ((start (and entry (match-beginning (nth 1 entry))))
4121 (end (and entry (match-end (nth 1 entry))))
4122 (from (match-beginning 0)))
4123 (when (and (or (eq t (nth 2 entry))
4124 (eval (nth 2 entry)))
4125 (not (gnus-button-in-region-p
4126 start end 'gnus-callback)))
4127 ;; That optional form returned non-nil, so we add the
4129 (gnus-article-add-button
4130 start end 'gnus-button-push
4131 (car (push (set-marker (make-marker) from)
4132 gnus-button-marker-list))))))))))
4134 ;; Add buttons to the head of an article.
4135 (defun gnus-article-add-buttons-to-head ()
4136 "Add buttons to the head of the article."
4139 (set-buffer gnus-article-buffer)
4141 (let ((buffer-read-only nil)
4142 (inhibit-point-motion-hooks t)
4143 (case-fold-search t)
4144 (alist gnus-header-button-alist)
4146 (article-narrow-to-head)
4148 ;; Each alist entry.
4149 (setq entry (car alist)
4151 (goto-char (point-min))
4152 (while (re-search-forward (car entry) nil t)
4153 ;; Each header matching the entry.
4154 (setq beg (match-beginning 0))
4155 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4156 (match-beginning 0))
4159 (while (re-search-forward (nth 1 entry) end t)
4160 ;; Each match within a header.
4161 (let* ((entry (cdr entry))
4162 (start (match-beginning (nth 1 entry)))
4163 (end (match-end (nth 1 entry)))
4164 (form (nth 2 entry)))
4165 (goto-char (match-end 0))
4167 (gnus-article-add-button
4168 start end (nth 3 entry)
4169 (buffer-substring (match-beginning (nth 4 entry))
4170 (match-end (nth 4 entry)))))))
4171 (goto-char end)))))))
4173 ;;; External functions:
4175 (defun gnus-article-add-button (from to fun &optional data)
4176 "Create a button between FROM and TO with callback FUN and data DATA."
4177 (when gnus-article-button-face
4178 (gnus-overlay-put (gnus-make-overlay from to)
4179 'face gnus-article-button-face))
4180 (gnus-add-text-properties
4182 (nconc (and gnus-article-mouse-face
4183 (list gnus-mouse-face-prop gnus-article-mouse-face))
4184 (list 'gnus-callback fun)
4185 (and data (list 'gnus-data data))))
4186 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4187 :button-keymap gnus-widget-button-keymap))
4189 ;;; Internal functions:
4191 (defun gnus-article-set-globals ()
4193 (set-buffer gnus-summary-buffer)
4194 (gnus-set-global-variables)))
4196 (defun gnus-signature-toggle (end)
4198 (set-buffer gnus-article-buffer)
4199 (let ((buffer-read-only nil)
4200 (inhibit-point-motion-hooks t))
4201 (if (get-text-property end 'invisible)
4202 (gnus-article-unhide-text end (point-max))
4203 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4205 (defun gnus-button-entry ()
4206 ;; Return the first entry in `gnus-button-alist' matching this place.
4207 (let ((alist gnus-button-alist)
4210 (setq entry (pop alist))
4211 (if (looking-at (car entry))
4216 (defun gnus-button-push (marker)
4217 ;; Push button starting at MARKER.
4220 (let* ((entry (gnus-button-entry))
4221 (inhibit-point-motion-hooks t)
4223 (args (mapcar (lambda (group)
4224 (let ((string (match-string group)))
4225 (gnus-set-text-properties
4226 0 (length string) nil string)
4233 (fboundp (symbol-value fun)))
4234 (apply (symbol-value fun) args))
4236 (gnus-message 1 "You must define `%S' to use this button"
4237 (cons fun args)))))))
4239 (defun gnus-button-message-id (message-id)
4242 (set-buffer gnus-summary-buffer)
4243 (gnus-summary-refer-article message-id)))
4245 (defun gnus-button-fetch-group (address)
4246 "Fetch GROUP specified by ADDRESS."
4247 (if (not (string-match "[:/]" address))
4248 ;; This is just a simple group url.
4249 (gnus-group-read-ephemeral-group address gnus-select-method)
4250 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4252 (error "Can't parse %s" address)
4253 (gnus-group-read-ephemeral-group
4254 (match-string 4 address)
4255 `(nntp ,(match-string 1 address)
4256 (nntp-address ,(match-string 1 address))
4257 (nntp-port-number ,(if (match-end 3)
4258 (match-string 3 address)
4261 (defun gnus-url-parse-query-string (query &optional downcase)
4262 (let (retval pairs cur key val)
4263 (setq pairs (split-string query "&"))
4265 (setq cur (car pairs)
4267 (if (not (string-match "=" cur))
4269 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4270 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4272 (setq key (downcase key)))
4273 (setq cur (assoc key retval))
4275 (setcdr cur (cons val (cdr cur)))
4276 (setq retval (cons (list key val) retval)))))
4279 (defun gnus-url-unhex (x)
4286 (defun gnus-url-unhex-string (str &optional allow-newlines)
4287 "Remove %XXX embedded spaces, etc in a url.
4288 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4289 decoding of carriage returns and line feeds in the string, which is normally
4290 forbidden in URL encoding."
4291 (setq str (or str ""))
4293 (case-fold-search t))
4294 (while (string-match "%[0-9a-f][0-9a-f]" str)
4295 (let* ((start (match-beginning 0))
4296 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4298 (gnus-url-unhex (elt str (+ start 2))))))
4300 tmp (substring str 0 start)
4303 (char-to-string code))
4304 ((or (= code ?\n) (= code ?\r))
4306 (t (char-to-string code))))
4307 str (substring str (match-end 0)))))
4308 (setq tmp (concat tmp str))
4311 (defun gnus-url-mailto (url)
4312 ;; Send mail to someone
4313 (when (string-match "mailto:/*\\(.*\\)" url)
4314 (setq url (substring url (match-beginning 1) nil)))
4315 (let (to args subject func)
4316 (if (string-match (regexp-quote "?") url)
4317 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4318 args (gnus-url-parse-query-string
4319 (substring url (match-end 0) nil) t))
4320 (setq to (gnus-url-unhex-string url)))
4321 (setq args (cons (list "to" to) args)
4322 subject (cdr-safe (assoc "subject" args)))
4325 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4328 (message-position-on-field (caar args)))
4329 (insert (mapconcat 'identity (cdar args) ", "))
4330 (setq args (cdr args)))
4333 (message-goto-subject))))
4335 (defun gnus-button-mailto (address)
4337 (set-buffer (gnus-copy-article-buffer))
4338 (message-reply address))
4340 (defun gnus-button-reply (address)
4341 ;; Reply to ADDRESS.
4342 (message-reply address))
4344 (defun gnus-button-url (address)
4346 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4347 (if (listp browse-url-browser-function)
4348 (browse-url address)
4349 (funcall browse-url-browser-function address)))
4351 (defun gnus-button-embedded-url (address)
4353 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4354 (if (listp browse-url-browser-function)
4355 (browse-url (gnus-strip-whitespace address))
4356 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4358 ;;; Next/prev buttons in the article buffer.
4360 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4361 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4363 (defvar gnus-prev-page-map nil)
4364 (unless gnus-prev-page-map
4365 (setq gnus-prev-page-map (make-sparse-keymap))
4366 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4367 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4369 (defun gnus-insert-prev-page-button ()
4370 (let ((buffer-read-only nil))
4372 gnus-prev-page-line-format nil
4373 `(gnus-prev t local-map ,gnus-prev-page-map
4374 gnus-callback gnus-article-button-prev-page
4375 article-type annotation))))
4377 (defvar gnus-next-page-map nil)
4378 (unless gnus-next-page-map
4379 (setq gnus-next-page-map (make-keymap))
4380 (suppress-keymap gnus-prev-page-map)
4381 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4382 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4384 (defun gnus-button-next-page ()
4385 "Go to the next page."
4387 (let ((win (selected-window)))
4388 (select-window (get-buffer-window gnus-article-buffer t))
4389 (gnus-article-next-page)
4390 (select-window win)))
4392 (defun gnus-button-prev-page ()
4393 "Go to the prev page."
4395 (let ((win (selected-window)))
4396 (select-window (get-buffer-window gnus-article-buffer t))
4397 (gnus-article-prev-page)
4398 (select-window win)))
4400 (defun gnus-insert-next-page-button ()
4401 (let ((buffer-read-only nil))
4402 (gnus-eval-format gnus-next-page-line-format nil
4404 t local-map ,gnus-next-page-map
4405 gnus-callback gnus-article-button-next-page
4406 article-type annotation))))
4408 (defun gnus-article-button-next-page (arg)
4409 "Go to the next page."
4411 (let ((win (selected-window)))
4412 (select-window (get-buffer-window gnus-article-buffer t))
4413 (gnus-article-next-page)
4414 (select-window win)))
4416 (defun gnus-article-button-prev-page (arg)
4417 "Go to the prev page."
4419 (let ((win (selected-window)))
4420 (select-window (get-buffer-window gnus-article-buffer t))
4421 (gnus-article-prev-page)
4422 (select-window win)))
4424 (defvar gnus-decode-header-methods
4425 '(mail-decode-encoded-word-region)
4426 "List of methods used to decode headers.
4428 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4429 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4430 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4431 whose names match REGEXP.
4434 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4435 mail-decode-encoded-word-region
4436 (\"chinese\" . rfc1843-decode-region))
4439 (defvar gnus-decode-header-methods-cache nil)
4441 (defun gnus-multi-decode-header (start end)
4442 "Apply the functions from `gnus-encoded-word-methods' that match."
4443 (unless (and gnus-decode-header-methods-cache
4444 (eq gnus-newsgroup-name
4445 (car gnus-decode-header-methods-cache)))
4446 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4449 (nconc gnus-decode-header-methods-cache (list x))
4450 (if (and gnus-newsgroup-name
4451 (string-match (car x) gnus-newsgroup-name))
4452 (nconc gnus-decode-header-methods-cache
4454 gnus-decode-header-methods))
4455 (let ((xlist gnus-decode-header-methods-cache))
4458 (narrow-to-region start end)
4460 (funcall (pop xlist) (point-min) (point-max))))))
4463 ;;; Treatment top-level handling.
4466 (defun gnus-treat-article (condition &optional part-number total-parts type)
4467 (let ((length (- (point-max) (point-min)))
4468 (alist gnus-treatment-function-alist)
4469 (article-goto-body-goes-to-point-min-p t)
4473 (let ((list gnus-article-treat-types))
4475 (when (string-match (pop list) type)
4476 (throw 'found t)))))))
4477 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4479 (gnus-run-hooks 'gnus-part-display-hook)
4480 (while (setq elem (pop alist))
4481 (setq val (symbol-value (car elem)))
4482 (when (and (or (consp val)
4484 (gnus-treat-predicate val)
4485 (or (not (get (car elem) 'highlight))
4488 (funcall (cadr elem)))))))
4490 ;; Dynamic variables.
4491 (defvar part-number)
4492 (defvar total-parts)
4496 (defun gnus-treat-predicate (val)
4507 (eq part-number total-parts))
4511 (stringp (car val)))
4512 (apply 'gnus-or (mapcar `(lambda (s)
4513 (string-match s ,(or gnus-newsgroup-name "")))
4516 (let ((pred (pop val)))
4519 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4521 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
4523 (not (gnus-treat-predicate (car val))))
4525 (equal (cadr val) type))
4527 (error "%S is not a valid predicate" pred)))))
4529 (error "%S is not a valid value" val))))
4535 (run-hooks 'gnus-art-load-hook)
4537 ;;; gnus-art.el ends here