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-Fingerprint:" "^X-Pgp-Key-Id:"
120 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
121 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
122 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
123 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:")
124 "*All headers that start with this regexp will be hidden.
125 This variable can also be a list of regexps of headers to be ignored.
126 If `gnus-visible-headers' is non-nil, this variable will be ignored."
127 :type '(choice :custom-show nil
130 :group 'gnus-article-hiding)
132 (defcustom gnus-visible-headers
133 "^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:"
134 "*All headers that do not match this regexp will be hidden.
135 This variable can also be a list of regexp of headers to remain visible.
136 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
137 :type '(repeat :value-to-internal (lambda (widget value)
138 (custom-split-regexp-maybe value))
139 :match (lambda (widget value)
141 (widget-editable-list-match widget value)))
143 :group 'gnus-article-hiding)
145 (defcustom gnus-sorted-header-list
146 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
147 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
148 "*This variable is a list of regular expressions.
149 If it is non-nil, headers that match the regular expressions will
150 be placed first in the article buffer in the sequence specified by
152 :type '(repeat regexp)
153 :group 'gnus-article-hiding)
155 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
156 "Headers that are only to be displayed if they have interesting data.
157 Possible values in this list are `empty', `newsgroups', `followup-to',
158 `reply-to', `date', `long-to', and `many-to'."
159 :type '(set (const :tag "Headers with no content." empty)
160 (const :tag "Newsgroups with only one group." newsgroups)
161 (const :tag "Followup-to identical to newsgroups." followup-to)
162 (const :tag "Reply-to identical to from." reply-to)
163 (const :tag "Date less than four days old." date)
164 (const :tag "Very long To header." long-to)
165 (const :tag "Multiple To headers." many-to))
166 :group 'gnus-article-hiding)
168 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
169 "Regexp matching signature separator.
170 This can also be a list of regexps. In that case, it will be checked
171 from head to tail looking for a separator. Searches will be done from
172 the end of the buffer."
173 :type '(repeat string)
174 :group 'gnus-article-signature)
176 (defcustom gnus-signature-limit nil
177 "Provide a limit to what is considered a signature.
178 If it is a number, no signature may not be longer (in characters) than
179 that number. If it is a floating point number, no signature may be
180 longer (in lines) than that number. If it is a function, the function
181 will be called without any parameters, and if it returns nil, there is
182 no signature in the buffer. If it is a string, it will be used as a
183 regexp. If it matches, the text in question is not a signature."
184 :type '(choice (integer :value 200)
186 (function :value fun)
187 (regexp :value ".*"))
188 :group 'gnus-article-signature)
190 (defcustom gnus-hidden-properties '(invisible t intangible t)
191 "Property list to use for hiding text."
193 :group 'gnus-article-hiding)
195 (defcustom gnus-article-x-face-command
196 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | display -"
197 "*String or function to be executed to display an X-Face header.
198 If it is a string, the command will be executed in a sub-shell
199 asynchronously. The compressed face will be piped to this command."
200 :type 'string ;Leave function case to Lisp.
201 :group 'gnus-article-washing)
203 (defcustom gnus-article-x-face-too-ugly nil
204 "Regexp matching posters whose face shouldn't be shown automatically."
205 :type '(choice regexp (const nil))
206 :group 'gnus-article-washing)
208 (defcustom gnus-emphasis-alist
210 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
212 '(("_" "_" underline)
215 ("_/" "/_" underline-italic)
216 ("_\\*" "\\*_" underline-bold)
217 ("\\*/" "/\\*" bold-italic)
218 ("_\\*/" "/\\*_" underline-bold-italic))))
219 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
220 2 3 gnus-emphasis-underline)
224 (format format (car spec) (cadr spec))
225 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
227 "*Alist that says how to fontify certain phrases.
228 Each item looks like this:
230 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
232 The first element is a regular expression to be matched. The second
233 is a number that says what regular expression grouping used to find
234 the entire emphasized word. The third is a number that says what
235 regexp grouping should be displayed and highlighted. The fourth
236 is the face used for highlighting."
237 :type '(repeat (list :value ("" 0 0 default)
239 (integer :tag "Match group")
240 (integer :tag "Emphasize group")
242 :group 'gnus-article-emphasis)
244 (defface gnus-emphasis-bold '((t (:bold t)))
245 "Face used for displaying strong emphasized text (*word*)."
246 :group 'gnus-article-emphasis)
248 (defface gnus-emphasis-italic '((t (:italic t)))
249 "Face used for displaying italic emphasized text (/word/)."
250 :group 'gnus-article-emphasis)
252 (defface gnus-emphasis-underline '((t (:underline t)))
253 "Face used for displaying underlined emphasized text (_word_)."
254 :group 'gnus-article-emphasis)
256 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
257 "Face used for displaying underlined bold emphasized text (_*word*_)."
258 :group 'gnus-article-emphasis)
260 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
261 "Face used for displaying underlined italic emphasized text (_*word*_)."
262 :group 'gnus-article-emphasis)
264 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
265 "Face used for displaying bold italic emphasized text (/*word*/)."
266 :group 'gnus-article-emphasis)
268 (defface gnus-emphasis-underline-bold-italic
269 '((t (:bold t :italic t :underline t)))
270 "Face used for displaying underlined bold italic emphasized text.
271 Esample: (_/*word*/_)."
272 :group 'gnus-article-emphasis)
274 (defface gnus-emphasis-highlight-words
275 '((t (:background "black" :foreground "yellow")))
276 "Face used for displaying highlighted words."
277 :group 'gnus-article-emphasis)
279 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
280 "Format for display of Date headers in article bodies.
281 See `format-time-string' for the possible values.
283 The variable can also be function, which should return a complete Date
284 header. The function is called with one argument, the time, which can
285 be fed to `format-time-string'."
286 :type '(choice string symbol)
287 :link '(custom-manual "(gnus)Article Date")
288 :group 'gnus-article-washing)
291 (autoload 'mail-extract-address-components "mail-extr"))
293 (defcustom gnus-save-all-headers t
294 "*If non-nil, don't remove any headers before saving."
295 :group 'gnus-article-saving
298 (defcustom gnus-prompt-before-saving 'always
299 "*This variable says how much prompting is to be done when saving articles.
300 If it is nil, no prompting will be done, and the articles will be
301 saved to the default files. If this variable is `always', each and
302 every article that is saved will be preceded by a prompt, even when
303 saving large batches of articles. If this variable is neither nil not
304 `always', there the user will be prompted once for a file name for
305 each invocation of the saving commands."
306 :group 'gnus-article-saving
307 :type '(choice (item always)
308 (item :tag "never" nil)
309 (sexp :tag "once" :format "%t\n" :value t)))
311 (defcustom gnus-saved-headers gnus-visible-headers
312 "Headers to keep if `gnus-save-all-headers' is nil.
313 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
314 If that variable is nil, however, all headers that match this regexp
315 will be kept while the rest will be deleted before saving."
316 :group 'gnus-article-saving
319 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
320 "A function to save articles in your favourite format.
321 The function must be interactively callable (in other words, it must
322 be an Emacs command).
324 Gnus provides the following functions:
326 * gnus-summary-save-in-rmail (Rmail format)
327 * gnus-summary-save-in-mail (Unix mail format)
328 * gnus-summary-save-in-folder (MH folder)
329 * gnus-summary-save-in-file (article format)
330 * gnus-summary-save-in-vm (use VM's folder format)
331 * gnus-summary-write-to-file (article format -- overwrite)."
332 :group 'gnus-article-saving
333 :type '(radio (function-item gnus-summary-save-in-rmail)
334 (function-item gnus-summary-save-in-mail)
335 (function-item gnus-summary-save-in-folder)
336 (function-item gnus-summary-save-in-file)
337 (function-item gnus-summary-save-in-vm)
338 (function-item gnus-summary-write-to-file)))
340 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
341 "A function generating a file name to save articles in Rmail format.
342 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
343 :group 'gnus-article-saving
346 (defcustom gnus-mail-save-name 'gnus-plain-save-name
347 "A function generating a file name to save articles in Unix mail format.
348 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
349 :group 'gnus-article-saving
352 (defcustom gnus-folder-save-name 'gnus-folder-save-name
353 "A function generating a file name to save articles in MH folder.
354 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
355 :group 'gnus-article-saving
358 (defcustom gnus-file-save-name 'gnus-numeric-save-name
359 "A function generating a file name to save articles in article format.
360 The function is called with NEWSGROUP, HEADERS, and optional
362 :group 'gnus-article-saving
365 (defcustom gnus-split-methods
366 '((gnus-article-archive-name)
367 (gnus-article-nndoc-name))
368 "*Variable used to suggest where articles are to be saved.
369 For instance, if you would like to save articles related to Gnus in
370 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
371 you could set this variable to something like:
373 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
374 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
376 This variable is an alist where the where the key is the match and the
377 value is a list of possible files to save in if the match is non-nil.
379 If the match is a string, it is used as a regexp match on the
380 article. If the match is a symbol, that symbol will be funcalled
381 from the buffer of the article to be saved with the newsgroup as the
382 parameter. If it is a list, it will be evaled in the same buffer.
384 If this form or function returns a string, this string will be used as
385 a possible file name; and if it returns a non-nil list, that list will
386 be used as possible file names."
387 :group 'gnus-article-saving
388 :type '(repeat (choice (list :value (fun) function)
389 (cons :value ("" "") regexp (repeat string))
392 (defcustom gnus-page-delimiter "^\^L"
393 "*Regexp describing what to use as article page delimiters.
394 The default value is \"^\^L\", which is a form linefeed at the
395 beginning of a line."
397 :group 'gnus-article-various)
399 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
400 "*The format specification for the article mode line.
401 See `gnus-summary-mode-line-format' for a closer description.
403 The following additional specs are available:
405 %w The article washing status.
406 %m The number of MIME parts in the article."
408 :group 'gnus-article-various)
410 (defcustom gnus-article-mode-hook nil
411 "*A hook for Gnus article mode."
413 :group 'gnus-article-various)
415 (defcustom gnus-article-menu-hook nil
416 "*Hook run after the creation of the article mode menu."
418 :group 'gnus-article-various)
420 (defcustom gnus-article-prepare-hook nil
421 "*A hook called after an article has been prepared in the article buffer."
423 :group 'gnus-article-various)
425 (defcustom gnus-article-hide-pgp-hook nil
426 "*A hook called after successfully hiding a PGP signature."
428 :group 'gnus-article-various)
430 (defcustom gnus-article-button-face 'bold
431 "Face used for highlighting buttons in the article buffer.
433 An article button is a piece of text that you can activate by pressing
434 `RET' or `mouse-2' above it."
436 :group 'gnus-article-buttons)
438 (defcustom gnus-article-mouse-face 'highlight
439 "Face used for mouse highlighting in the article buffer.
441 Article buttons will be displayed in this face when the cursor is
444 :group 'gnus-article-buttons)
446 (defcustom gnus-signature-face 'gnus-signature-face
447 "Face used for highlighting a signature in the article buffer.
448 Obsolete; use the face `gnus-signature-face' for customizations instead."
450 :group 'gnus-article-highlight
451 :group 'gnus-article-signature)
453 (defface gnus-signature-face
456 "Face used for highlighting a signature in the article buffer."
457 :group 'gnus-article-highlight
458 :group 'gnus-article-signature)
460 (defface gnus-header-from-face
463 (:foreground "spring green"))
466 (:foreground "red3"))
469 "Face used for displaying from headers."
470 :group 'gnus-article-headers
471 :group 'gnus-article-highlight)
473 (defface gnus-header-subject-face
476 (:foreground "SeaGreen3"))
479 (:foreground "red4"))
481 (:bold t :italic t)))
482 "Face used for displaying subject headers."
483 :group 'gnus-article-headers
484 :group 'gnus-article-highlight)
486 (defface gnus-header-newsgroups-face
489 (:foreground "yellow" :italic t))
492 (:foreground "MidnightBlue" :italic t))
495 "Face used for displaying newsgroups headers."
496 :group 'gnus-article-headers
497 :group 'gnus-article-highlight)
499 (defface gnus-header-name-face
502 (:foreground "SeaGreen"))
505 (:foreground "maroon"))
508 "Face used for displaying header names."
509 :group 'gnus-article-headers
510 :group 'gnus-article-highlight)
512 (defface gnus-header-content-face
515 (:foreground "forest green" :italic t))
518 (:foreground "indianred4" :italic t))
520 (:italic t))) "Face used for displaying header content."
521 :group 'gnus-article-headers
522 :group 'gnus-article-highlight)
524 (defcustom gnus-header-face-alist
525 '(("From" nil gnus-header-from-face)
526 ("Subject" nil gnus-header-subject-face)
527 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
528 ("" gnus-header-name-face gnus-header-content-face))
529 "*Controls highlighting of article header.
531 An alist of the form (HEADER NAME CONTENT).
533 HEADER is a regular expression which should match the name of an
534 header header and NAME and CONTENT are either face names or nil.
536 The name of each header field will be displayed using the face
537 specified by the first element in the list where HEADER match the
538 header name and NAME is non-nil. Similarly, the content will be
539 displayed by the first non-nil matching CONTENT face."
540 :group 'gnus-article-headers
541 :group 'gnus-article-highlight
542 :type '(repeat (list (regexp :tag "Header")
544 (item :tag "skip" nil)
545 (face :value default))
546 (choice :tag "Content"
547 (item :tag "skip" nil)
548 (face :value default)))))
550 (defcustom gnus-article-decode-hook
551 '(article-decode-charset article-decode-encoded-words)
552 "*Hook run to decode charsets in articles."
553 :group 'gnus-article-headers
556 (defcustom gnus-display-mime-function 'gnus-display-mime
557 "Function to display MIME articles."
558 :group 'gnus-article-mime
561 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
562 "Function used to decode headers.")
564 (defvar gnus-article-dumbquotes-map
582 "Table for MS-to-Latin1 translation.")
584 (defcustom gnus-ignored-mime-types nil
585 "List of MIME types that should be ignored by Gnus."
586 :group 'gnus-article-mime
587 :type '(repeat regexp))
589 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
590 "List of MIME types that should not be given buttons when rendered."
591 :group 'gnus-article-mime
592 :type '(repeat regexp))
594 (defcustom gnus-article-mime-part-function nil
595 "Function called with a MIME handle as the argument.
596 This is meant for people who want to do something automatic based
597 on parts -- for instance, adding Vcard info to a database."
598 :group 'gnus-article-mime
601 (defcustom gnus-mime-multipart-functions nil
602 "An alist of MIME types to functions to display them.")
604 (defcustom gnus-article-date-lapsed-new-header nil
605 "Whether the X-Sent and Date headers can coexist.
606 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
607 either replace the old \"Date:\" header (if this variable is nil), or
608 be added below it (otherwise)."
609 :group 'gnus-article-headers
613 ;;; The treatment variables
616 (defvar gnus-part-display-hook nil
617 "Hook called on parts that are to receive treatment.")
619 (defvar gnus-article-treat-custom
620 '(choice (const :tag "Off" nil)
622 (const :tag "Header" head)
623 (const :tag "Last" last)
624 (integer :tag "Less")
625 (repeat :tag "Groups" regexp)
626 (sexp :tag "Predicate")))
628 (defvar gnus-article-treat-head-custom
629 '(choice (const :tag "Off" nil)
630 (const :tag "Header" head)))
632 (defvar gnus-article-treat-types '("text/plain")
635 (defvar gnus-inhibit-treatment nil
636 "Whether to inhibit treatment.")
638 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
639 "Highlight the signature.
640 Valid values are nil, t, `head', `last', an integer or a predicate.
641 See the manual for details."
642 :group 'gnus-article-treat
643 :type gnus-article-treat-custom)
644 (put 'gnus-treat-highlight-signature 'highlight t)
646 (defcustom gnus-treat-buttonize t
648 Valid values are nil, t, `head', `last', an integer or a predicate.
649 See the manual for details."
650 :group 'gnus-article-treat
651 :type gnus-article-treat-custom)
652 (put 'gnus-treat-buttonize 'highlight t)
654 (defcustom gnus-treat-buttonize-head 'head
655 "Add buttons to the head.
656 Valid values are nil, t, `head', `last', an integer or a predicate.
657 See the manual for details."
658 :group 'gnus-article-treat
659 :type gnus-article-treat-head-custom)
660 (put 'gnus-treat-buttonize-head 'highlight t)
662 (defcustom gnus-treat-emphasize t
664 Valid values are nil, t, `head', `last', an integer or a predicate.
665 See the manual for details."
666 :group 'gnus-article-treat
667 :type gnus-article-treat-custom)
668 (put 'gnus-treat-emphasize 'highlight t)
670 (defcustom gnus-treat-strip-cr nil
671 "Remove carriage returns.
672 Valid values are nil, t, `head', `last', an integer or a predicate.
673 See the manual for details."
674 :group 'gnus-article-treat
675 :type gnus-article-treat-custom)
677 (defcustom gnus-treat-hide-headers 'head
679 Valid values are nil, t, `head', `last', an integer or a predicate.
680 See the manual for details."
681 :group 'gnus-article-treat
682 :type gnus-article-treat-head-custom)
684 (defcustom gnus-treat-hide-boring-headers nil
685 "Hide boring headers.
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-signature nil
693 Valid values are nil, t, `head', `last', an integer or a predicate.
694 See the manual for details."
695 :group 'gnus-article-treat
696 :type gnus-article-treat-custom)
698 (defcustom gnus-treat-fill-article 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-hide-citation 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-strip-pgp t
713 "Strip PGP signatures.
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-pem nil
720 "Strip PEM signatures.
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-banner t
727 "Strip banners from articles.
728 The banner to be stripped is specified in the `banner' group parameter.
729 Valid values are nil, t, `head', `last', an integer or a predicate.
730 See the manual for details."
731 :group 'gnus-article-treat
732 :type gnus-article-treat-custom)
734 (defcustom gnus-treat-highlight-headers 'head
735 "Highlight the headers.
736 Valid values are nil, t, `head', `last', an integer or a predicate.
737 See the manual for details."
738 :group 'gnus-article-treat
739 :type gnus-article-treat-head-custom)
740 (put 'gnus-treat-highlight-headers 'highlight t)
742 (defcustom gnus-treat-highlight-citation t
743 "Highlight cited text.
744 Valid values are nil, t, `head', `last', an integer or a predicate.
745 See the manual for details."
746 :group 'gnus-article-treat
747 :type gnus-article-treat-custom)
748 (put 'gnus-treat-highlight-citation 'highlight t)
750 (defcustom gnus-treat-date-ut nil
751 "Display the Date in UT (GMT).
752 Valid values are nil, t, `head', `last', an integer or a predicate.
753 See the manual for details."
754 :group 'gnus-article-treat
755 :type gnus-article-treat-head-custom)
757 (defcustom gnus-treat-date-local nil
758 "Display the Date in the local timezone.
759 Valid values are nil, t, `head', `last', an integer or a predicate.
760 See the manual for details."
761 :group 'gnus-article-treat
762 :type gnus-article-treat-head-custom)
764 (defcustom gnus-treat-date-lapsed nil
765 "Display the Date header in a way that says how much time has elapsed.
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-original nil
772 "Display the date in the original 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-iso8601 nil
779 "Display the date in the ISO8601 format.
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-user-defined nil
786 "Display the date in a user-defined format.
787 The format is defined by the `gnus-article-time-format' variable.
788 Valid values are nil, t, `head', `last', an integer or a predicate.
789 See the manual for details."
790 :group 'gnus-article-treat
791 :type gnus-article-treat-head-custom)
793 (defcustom gnus-treat-strip-headers-in-body t
794 "Strip the X-No-Archive header line from the beginning of the body.
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-custom)
800 (defcustom gnus-treat-strip-trailing-blank-lines nil
801 "Strip trailing blank lines.
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-custom)
807 (defcustom gnus-treat-strip-leading-blank-lines nil
808 "Strip leading blank lines.
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-multiple-blank-lines nil
815 "Strip multiple 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-blank-lines nil
822 "Strip all 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-overstrike t
829 "Treat overstrike highlighting.
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)
834 (put 'gnus-treat-overstrike 'highlight t)
836 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
838 "Display X-Face headers.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-head-custom)
843 (put 'gnus-treat-display-xface 'highlight t)
845 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
849 Valid values are nil, t, `head', `last', an integer or a predicate.
850 See the manual for details."
851 :group 'gnus-article-treat
852 :type gnus-article-treat-custom)
853 (put 'gnus-treat-display-smileys 'highlight t)
855 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
857 Valid values are nil, t, `head', `last', an integer or a predicate.
858 See the manual for details."
859 :group 'gnus-article-treat
860 :type gnus-article-treat-head-custom)
861 (put 'gnus-treat-display-picons 'highlight t)
863 (defcustom gnus-treat-capitalize-sentences nil
864 "Capitalize sentence-starting words.
865 Valid values are nil, t, `head', `last', an integer or a predicate.
866 See the manual for details."
867 :group 'gnus-article-treat
868 :type gnus-article-treat-custom)
870 (defcustom gnus-treat-fill-long-lines nil
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-play-sounds 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-translate nil
885 "Translate articles from one language to another.
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 ;;; Internal variables
893 (defvar article-goto-body-goes-to-point-min-p nil)
894 (defvar gnus-article-wash-types nil)
895 (defvar gnus-article-emphasis-alist nil)
897 (defvar gnus-article-mime-handle-alist-1 nil)
898 (defvar gnus-treatment-function-alist
899 '((gnus-treat-strip-banner gnus-article-strip-banner)
900 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
901 (gnus-treat-highlight-signature gnus-article-highlight-signature)
902 (gnus-treat-buttonize gnus-article-add-buttons)
903 (gnus-treat-fill-article gnus-article-fill-cited-article)
904 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
905 (gnus-treat-strip-cr gnus-article-remove-cr)
906 (gnus-treat-emphasize gnus-article-emphasize)
907 (gnus-treat-display-xface gnus-article-display-x-face)
908 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
909 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
910 (gnus-treat-hide-signature gnus-article-hide-signature)
911 (gnus-treat-hide-citation gnus-article-hide-citation)
912 (gnus-treat-strip-pgp gnus-article-hide-pgp)
913 (gnus-treat-strip-pem gnus-article-hide-pem)
914 (gnus-treat-highlight-headers gnus-article-highlight-headers)
915 (gnus-treat-highlight-citation gnus-article-highlight-citation)
916 (gnus-treat-highlight-signature gnus-article-highlight-signature)
917 (gnus-treat-date-ut gnus-article-date-ut)
918 (gnus-treat-date-local gnus-article-date-local)
919 (gnus-treat-date-lapsed gnus-article-date-lapsed)
920 (gnus-treat-date-original gnus-article-date-original)
921 (gnus-treat-date-user-defined gnus-article-date-user)
922 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
923 (gnus-treat-strip-trailing-blank-lines
924 gnus-article-remove-trailing-blank-lines)
925 (gnus-treat-strip-leading-blank-lines
926 gnus-article-strip-leading-blank-lines)
927 (gnus-treat-strip-multiple-blank-lines
928 gnus-article-strip-multiple-blank-lines)
929 (gnus-treat-strip-blank-lines gnus-article-strip-blank-lines)
930 (gnus-treat-overstrike gnus-article-treat-overstrike)
931 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
932 (gnus-treat-display-smileys gnus-smiley-display)
933 (gnus-treat-display-picons gnus-article-display-picons)
934 (gnus-treat-play-sounds gnus-earcon-display)))
936 (defvar gnus-article-mime-handle-alist nil)
937 (defvar article-lapsed-timer nil)
938 (defvar gnus-article-current-summary nil)
940 (defvar gnus-article-mode-syntax-table
941 (let ((table (copy-syntax-table text-mode-syntax-table)))
942 (modify-syntax-entry ?- "w" table)
943 (modify-syntax-entry ?> ")" table)
944 (modify-syntax-entry ?< "(" table)
946 "Syntax table used in article mode buffers.
947 Initialized from `text-mode-syntax-table.")
949 (defvar gnus-save-article-buffer nil)
951 (defvar gnus-article-mode-line-format-alist
952 (nconc '((?w (gnus-article-wash-status) ?s)
953 (?m (gnus-article-mime-part-status) ?s))
954 gnus-summary-mode-line-format-alist))
956 (defvar gnus-number-of-articles-to-be-saved nil)
958 (defvar gnus-inhibit-hiding nil)
960 (defsubst gnus-article-hide-text (b e props)
961 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
962 (add-text-properties b e props)
963 (when (memq 'intangible props)
965 (max (1- b) (point-min))
966 b 'intangible (cddr (memq 'intangible props)))))
967 (defsubst gnus-article-unhide-text (b e)
968 "Remove hidden text properties from region between B and E."
969 (remove-text-properties b e gnus-hidden-properties)
970 (when (memq 'intangible gnus-hidden-properties)
971 (put-text-property (max (1- b) (point-min))
974 (defun gnus-article-hide-text-type (b e type)
975 "Hide text of TYPE between B and E."
976 (push type gnus-article-wash-types)
977 (gnus-article-hide-text
978 b e (cons 'article-type (cons type gnus-hidden-properties))))
980 (defun gnus-article-unhide-text-type (b e type)
981 "Unhide text of TYPE between B and E."
982 (setq gnus-article-wash-types
983 (delq type gnus-article-wash-types))
984 (remove-text-properties
985 b e (cons 'article-type (cons type gnus-hidden-properties)))
986 (when (memq 'intangible gnus-hidden-properties)
987 (put-text-property (max (1- b) (point-min))
990 (defun gnus-article-hide-text-of-type (type)
991 "Hide text of TYPE in the current buffer."
993 (let ((b (point-min))
995 (while (setq b (text-property-any b e 'article-type type))
996 (add-text-properties b (incf b) gnus-hidden-properties)))))
998 (defun gnus-article-delete-text-of-type (type)
999 "Delete text of TYPE in the current buffer."
1001 (let ((b (point-min)))
1002 (while (setq b (text-property-any b (point-max) 'article-type type))
1004 b (or (text-property-not-all b (point-max) 'article-type type)
1007 (defun gnus-article-delete-invisible-text ()
1008 "Delete all invisible text in the current buffer."
1010 (let ((b (point-min)))
1011 (while (setq b (text-property-any b (point-max) 'invisible t))
1013 b (or (text-property-not-all b (point-max) 'invisible t)
1016 (defun gnus-article-text-type-exists-p (type)
1017 "Say whether any text of type TYPE exists in the buffer."
1018 (text-property-any (point-min) (point-max) 'article-type type))
1020 (defsubst gnus-article-header-rank ()
1021 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1022 (let ((list gnus-sorted-header-list)
1025 (when (looking-at (car list))
1027 (setq list (cdr list))
1031 (defun article-hide-headers (&optional arg delete)
1032 "Hide unwanted headers and possibly sort them as well."
1034 ;; This function might be inhibited.
1035 (unless gnus-inhibit-hiding
1038 (let ((buffer-read-only nil)
1039 (case-fold-search t)
1040 (max (1+ (length gnus-sorted-header-list)))
1041 (ignored (when (not gnus-visible-headers)
1042 (cond ((stringp gnus-ignored-headers)
1043 gnus-ignored-headers)
1044 ((listp gnus-ignored-headers)
1045 (mapconcat 'identity gnus-ignored-headers
1048 (cond ((stringp gnus-visible-headers)
1049 gnus-visible-headers)
1050 ((and gnus-visible-headers
1051 (listp gnus-visible-headers))
1052 (mapconcat 'identity gnus-visible-headers "\\|"))))
1053 (inhibit-point-motion-hooks t)
1055 ;; First we narrow to just the headers.
1056 (article-narrow-to-head)
1057 ;; Hide any "From " lines at the beginning of (mail) articles.
1058 (while (looking-at "From ")
1061 (delete-region (point-min) (point)))
1062 ;; Then treat the rest of the header lines.
1063 ;; Then we use the two regular expressions
1064 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1065 ;; select which header lines is to remain visible in the
1067 (while (re-search-forward "^[^ \t]*:" nil t)
1069 ;; Mark the rank of the header.
1071 (point) (1+ (point)) 'message-rank
1072 (if (or (and visible (looking-at visible))
1074 (not (looking-at ignored))))
1075 (gnus-article-header-rank)
1078 (message-sort-headers-1)
1079 (when (setq beg (text-property-any
1080 (point-min) (point-max) 'message-rank (+ 2 max)))
1081 ;; We delete the unwanted headers.
1082 (add-text-properties (point-min) (+ 5 (point-min))
1083 '(article-type headers dummy-invisible t))
1084 (delete-region beg (point-max))))))))
1086 (defun article-hide-boring-headers (&optional arg)
1087 "Toggle hiding of headers that aren't very interesting.
1088 If given a negative prefix, always show; if given a positive prefix,
1090 (interactive (gnus-article-hidden-arg))
1091 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1092 (not gnus-show-all-headers))
1095 (let ((buffer-read-only nil)
1096 (list gnus-boring-article-headers)
1097 (inhibit-point-motion-hooks t)
1099 (article-narrow-to-head)
1101 (setq elem (pop list))
1102 (goto-char (point-min))
1104 ;; Hide empty headers.
1106 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1108 (gnus-article-hide-text-type
1109 (progn (beginning-of-line) (point))
1112 (if (re-search-forward "^[^ \t]" nil t)
1116 ;; Hide boring Newsgroups header.
1117 ((eq elem 'newsgroups)
1118 (when (equal (gnus-fetch-field "newsgroups")
1119 (gnus-group-real-name
1120 (if (boundp 'gnus-newsgroup-name)
1123 (gnus-article-hide-header "newsgroups")))
1124 ((eq elem 'followup-to)
1125 (when (equal (message-fetch-field "followup-to")
1126 (message-fetch-field "newsgroups"))
1127 (gnus-article-hide-header "followup-to")))
1128 ((eq elem 'reply-to)
1129 (let ((from (message-fetch-field "from"))
1130 (reply-to (message-fetch-field "reply-to")))
1135 (nth 1 (mail-extract-address-components from))
1136 (nth 1 (mail-extract-address-components reply-to)))))
1137 (gnus-article-hide-header "reply-to"))))
1139 (let ((date (message-fetch-field "date")))
1141 (< (days-between (current-time-string) date)
1143 (gnus-article-hide-header "date"))))
1145 (let ((to (message-fetch-field "to")))
1146 (when (> (length to) 1024)
1147 (gnus-article-hide-header "to"))))
1150 (goto-char (point-min))
1151 (while (re-search-forward "^to:" nil t)
1152 (setq to-count (1+ to-count)))
1153 (when (> to-count 1)
1154 (while (> to-count 0)
1155 (goto-char (point-min))
1157 (re-search-forward "^to:" nil nil to-count)
1159 (narrow-to-region (point) (point-max))
1160 (gnus-article-hide-header "to"))
1161 (setq to-count (1- to-count)))))))))))))
1163 (defun gnus-article-hide-header (header)
1165 (goto-char (point-min))
1166 (when (re-search-forward (concat "^" header ":") nil t)
1167 (gnus-article-hide-text-type
1168 (progn (beginning-of-line) (point))
1171 (if (re-search-forward "^[^ \t]" nil t)
1176 (defvar gnus-article-normalized-header-length 40
1177 "Length of normalized headers.")
1179 (defun article-normalize-headers ()
1180 "Make all header lines 40 characters long."
1182 (let ((buffer-read-only nil)
1186 (article-narrow-to-head)
1189 ((< (setq column (- (gnus-point-at-eol) (point)))
1190 gnus-article-normalized-header-length)
1192 (insert (make-string
1193 (- gnus-article-normalized-header-length column)
1195 ((> column gnus-article-normalized-header-length)
1196 (gnus-put-text-property
1198 (forward-char gnus-article-normalized-header-length)
1205 (forward-line 1))))))
1207 (defun article-treat-dumbquotes ()
1208 "Translate M******** sm*rtq**t*s into proper text.
1209 Note that this function guesses whether a character is a sm*rtq**t* or
1210 not, so it should only be used interactively."
1212 (article-translate-strings gnus-article-dumbquotes-map))
1214 (defun article-translate-characters (from to)
1215 "Translate all characters in the body of the article according to FROM and TO.
1216 FROM is a string of characters to translate from; to is a string of
1217 characters to translate to."
1219 (when (article-goto-body)
1220 (let ((buffer-read-only nil)
1221 (x (make-string 225 ?x))
1223 (while (< (incf i) (length x))
1226 (while (< i (length from))
1227 (aset x (aref from i) (aref to i))
1229 (translate-region (point) (point-max) x)))))
1231 (defun article-translate-strings (map)
1232 "Translate all string in the body of the article according to MAP.
1233 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1235 (when (article-goto-body)
1236 (let ((buffer-read-only nil)
1238 (while (setq elem (pop map))
1240 (while (search-forward (car elem) nil t)
1241 (replace-match (cadr elem)))))))))
1243 (defun article-treat-overstrike ()
1244 "Translate overstrikes into bold text."
1247 (when (article-goto-body)
1248 (let ((buffer-read-only nil))
1249 (while (search-forward "\b" nil t)
1250 (let ((next (char-after))
1251 (previous (char-after (- (point) 2))))
1252 ;; We do the boldification/underlining by hiding the
1253 ;; overstrikes and putting the proper text property
1257 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1258 (put-text-property (point) (1+ (point)) 'face 'bold))
1260 (gnus-article-hide-text-type
1261 (1- (point)) (1+ (point)) 'overstrike)
1263 (- (point) 2) (1- (point)) 'face 'underline))
1265 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1267 (point) (1+ (point)) 'face 'underline)))))))))
1269 (defun article-fill-long-lines ()
1270 "Fill lines that are wider than the window width."
1273 (let ((buffer-read-only nil)
1274 (width (window-width (get-buffer-window (current-buffer)))))
1277 (let ((adaptive-fill-mode nil))
1280 (when (>= (current-column) (min fill-column width))
1281 (narrow-to-region (point) (gnus-point-at-bol))
1282 (fill-paragraph nil)
1283 (goto-char (point-max))
1285 (forward-line 1)))))))
1287 (defun article-capitalize-sentences ()
1288 "Capitalize the first word in each sentence."
1291 (let ((buffer-read-only nil)
1292 (paragraph-start "^[\n\^L]"))
1296 (forward-sentence)))))
1298 (defun article-remove-cr ()
1299 "Remove trailing CRs and then translate remaining CRs into LFs."
1302 (let ((buffer-read-only nil))
1303 (goto-char (point-min))
1304 (while (re-search-forward "\r+$" nil t)
1305 (replace-match "" t t))
1306 (goto-char (point-min))
1307 (while (search-forward "\r" nil t)
1308 (replace-match "\n" t t)))))
1310 (defun article-remove-trailing-blank-lines ()
1311 "Remove all trailing blank lines from the article."
1314 (let ((buffer-read-only nil))
1315 (goto-char (point-max))
1319 (while (and (not (bobp))
1320 (looking-at "^[ \t]*$")
1321 (not (gnus-annotation-in-region-p
1322 (point) (gnus-point-at-eol))))
1327 (defun article-display-x-face (&optional force)
1328 "Look for an X-Face header and display it if present."
1329 (interactive (list 'force))
1331 ;; Delete the old process, if any.
1332 (when (process-status "article-x-face")
1333 (delete-process "article-x-face"))
1334 (let ((inhibit-point-motion-hooks t)
1335 (case-fold-search t)
1338 (article-narrow-to-head)
1339 (goto-char (point-min))
1340 (setq from (message-fetch-field "from"))
1341 (goto-char (point-min))
1342 (while (and gnus-article-x-face-command
1345 ;; Check whether this face is censored.
1346 (not gnus-article-x-face-too-ugly)
1347 (and gnus-article-x-face-too-ugly from
1348 (not (string-match gnus-article-x-face-too-ugly
1350 ;; Has to be present.
1351 (re-search-forward "^X-Face: " nil t))
1352 ;; This used to try to do multiple faces (`while' instead of
1353 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1354 ;; work (b) it can crash some versions of Emacs (c) are
1355 ;; multiple faces really something to encourage?
1356 (when (stringp gnus-article-x-face-command)
1358 ;; We now have the area of the buffer where the X-Face is stored.
1361 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1362 ;; We display the face.
1363 (if (symbolp gnus-article-x-face-command)
1364 ;; The command is a lisp function, so we call it.
1365 (if (gnus-functionp gnus-article-x-face-command)
1366 (funcall gnus-article-x-face-command beg end)
1367 (error "%s is not a function" gnus-article-x-face-command))
1368 ;; The command is a string, so we interpret the command
1369 ;; as a, well, command, and fork it off.
1370 (let ((process-connection-type nil))
1371 (process-kill-without-query
1373 "article-x-face" nil shell-file-name shell-command-switch
1374 gnus-article-x-face-command))
1375 (process-send-region "article-x-face" beg end)
1376 (process-send-eof "article-x-face"))))))))))
1378 (defun article-decode-mime-words ()
1379 "Decode all MIME-encoded words in the article."
1382 (set-buffer gnus-article-buffer)
1383 (let ((inhibit-point-motion-hooks t)
1385 (mail-parse-charset gnus-newsgroup-charset)
1386 (mail-parse-ignored-charsets
1387 (save-excursion (set-buffer gnus-summary-buffer)
1388 gnus-newsgroup-ignored-charsets)))
1389 (mail-decode-encoded-word-region (point-min) (point-max)))))
1391 (defun article-decode-charset (&optional prompt)
1392 "Decode charset-encoded text in the article.
1393 If PROMPT (the prefix), prompt for a coding system to use."
1397 (article-narrow-to-head)
1398 (let* ((inhibit-point-motion-hooks t)
1399 (case-fold-search t)
1400 (ct (message-fetch-field "Content-Type" t))
1401 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1402 (ctl (and ct (ignore-errors
1403 (mail-header-parse-content-type ct))))
1406 (mm-read-coding-system "Charset to decode: "))
1408 (mail-content-type-get ctl 'charset))))
1409 (mail-parse-charset gnus-newsgroup-charset)
1410 (mail-parse-ignored-charsets
1411 (save-excursion (set-buffer gnus-summary-buffer)
1412 gnus-newsgroup-ignored-charsets))
1414 (goto-char (point-max))
1417 (narrow-to-region (point) (point-max))
1418 (when (and (or (not ctl)
1419 (equal (car ctl) "text/plain"))
1422 charset (and cte (intern (downcase
1423 (gnus-strip-whitespace cte))))
1426 (defun article-decode-encoded-words ()
1427 "Remove encoded-word encoding from headers."
1428 (let ((inhibit-point-motion-hooks t)
1429 (mail-parse-charset gnus-newsgroup-charset)
1430 (mail-parse-ignored-charsets
1431 (save-excursion (set-buffer gnus-summary-buffer)
1432 gnus-newsgroup-ignored-charsets))
1435 (article-narrow-to-head)
1436 (funcall gnus-decode-header-function (point-min) (point-max)))))
1438 (defun article-de-quoted-unreadable (&optional force)
1439 "Translate a quoted-printable-encoded article.
1440 If FORCE, decode the article whether it is marked as quoted-printable
1442 (interactive (list 'force))
1444 (let ((buffer-read-only nil)
1445 (type (gnus-fetch-field "content-transfer-encoding"))
1446 (charset gnus-newsgroup-charset))
1448 (and type (string-match "quoted-printable" (downcase type))))
1451 (narrow-to-region (point) (point-max))
1452 (quoted-printable-decode-region (point-min) (point-max))
1454 (mm-decode-body charset)))))))
1456 (defun article-hide-pgp ()
1457 "Remove any PGP headers and signatures in the current article."
1461 (let ((inhibit-point-motion-hooks t)
1462 buffer-read-only beg end)
1464 ;; Hide the "header".
1465 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1466 (push 'pgp gnus-article-wash-types)
1467 (delete-region (match-beginning 0) (match-end 0))
1468 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1469 (when (looking-at "Hash:.*$")
1470 (delete-region (point) (1+ (gnus-point-at-eol))))
1472 ;; Hide the actual signature.
1473 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1474 (setq end (1+ (match-beginning 0)))
1477 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1479 ;; Perhaps we shouldn't hide to the end of the buffer
1480 ;; if there is no end to the signature?
1482 ;; Hide "- " PGP quotation markers.
1484 (narrow-to-region beg end)
1485 (goto-char (point-min))
1486 (while (re-search-forward "^- " nil t)
1488 (match-beginning 0) (match-end 0)))
1490 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1492 (defun article-hide-pem (&optional arg)
1493 "Toggle hiding of any PEM headers and signatures in the current article.
1494 If given a negative prefix, always show; if given a positive prefix,
1496 (interactive (gnus-article-hidden-arg))
1497 (unless (gnus-article-check-hidden-text 'pem arg)
1499 (let (buffer-read-only end)
1500 (goto-char (point-min))
1501 ;; Hide the horrendously ugly "header".
1502 (when (and (search-forward
1503 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1505 (setq end (1+ (match-beginning 0))))
1506 (push 'pem gnus-article-wash-types)
1507 (gnus-article-hide-text-type
1509 (if (search-forward "\n\n" nil t)
1513 ;; Hide the trailer as well
1514 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1516 (gnus-article-hide-text-type
1517 (match-beginning 0) (match-end 0) 'pem)))))))
1519 (defun article-strip-banner ()
1520 "Strip the banner specified by the `banner' group parameter."
1524 (let ((inhibit-point-motion-hooks t)
1525 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1526 (gnus-signature-limit nil)
1527 buffer-read-only beg end)
1531 ((eq banner 'signature)
1532 (when (gnus-article-narrow-to-signature)
1535 (delete-region (point) (point-max))))
1537 (while (re-search-forward banner nil t)
1538 (delete-region (match-beginning 0) (match-end 0))))))))))
1540 (defun article-babel-prompt ()
1541 "Prompt for a babel translation."
1543 (completing-read "Translate from: "
1544 babel-translations nil t
1545 (car (car babel-translations))
1548 (defun article-babel (translation)
1549 "Translate article according to TRANSLATION using babelfish."
1550 (interactive (list (article-babel-prompt)))
1553 (set-buffer gnus-article-buffer)
1554 (when (article-goto-body)
1555 (let* ((buffer-read-only nil)
1558 (msg (buffer-substring start end)))
1560 (narrow-to-region start end)
1561 (delete-region start end)
1562 (babel-fetch msg (cdr (assoc translation babel-translations)))
1564 (narrow-to-region start (point-max))
1567 (defun article-hide-signature (&optional arg)
1568 "Hide the signature in the current article.
1569 If given a negative prefix, always show; if given a positive prefix,
1571 (interactive (gnus-article-hidden-arg))
1572 (unless (gnus-article-check-hidden-text 'signature arg)
1575 (let ((buffer-read-only nil))
1576 (when (gnus-article-narrow-to-signature)
1577 (gnus-article-hide-text-type
1578 (point-min) (point-max) 'signature)))))))
1580 (defun article-strip-headers-in-body ()
1581 "Strip offensive headers from bodies."
1585 (let ((case-fold-search t))
1586 (when (looking-at "x-no-archive:")
1587 (gnus-delete-line)))))
1589 (defun article-strip-leading-blank-lines ()
1590 "Remove all blank lines from the beginning of the article."
1593 (let ((inhibit-point-motion-hooks t)
1595 (when (article-goto-body)
1596 (while (and (not (eobp))
1597 (looking-at "[ \t]*$"))
1598 (gnus-delete-line))))))
1600 (defun article-narrow-to-head ()
1601 "Narrow the buffer to the head of the message.
1602 Point is left at the beginning of the narrowed-to region."
1604 (goto-char (point-min))
1605 (if (search-forward "\n\n" nil 1)
1608 (goto-char (point-min)))
1610 (defun article-goto-body ()
1611 "Place point at the start of the body."
1612 (goto-char (point-min))
1614 ;; This variable is only bound when dealing with separate
1616 (article-goto-body-goes-to-point-min-p
1618 ((search-forward "\n\n" nil t)
1621 (goto-char (point-max))
1624 (defun article-strip-multiple-blank-lines ()
1625 "Replace consecutive blank lines with one empty line."
1628 (let ((inhibit-point-motion-hooks t)
1630 ;; First make all blank lines empty.
1632 (while (re-search-forward "^[ \t]+$" nil t)
1633 (unless (gnus-annotation-in-region-p
1634 (match-beginning 0) (match-end 0))
1635 (replace-match "" nil t)))
1636 ;; Then replace multiple empty lines with a single empty line.
1638 (while (re-search-forward "\n\n\n+" nil t)
1639 (unless (gnus-annotation-in-region-p
1640 (match-beginning 0) (match-end 0))
1641 (replace-match "\n\n" t t))))))
1643 (defun article-strip-leading-space ()
1644 "Remove all white space from the beginning of the lines in the article."
1647 (let ((inhibit-point-motion-hooks t)
1650 (while (re-search-forward "^[ \t]+" nil t)
1651 (replace-match "" t t)))))
1653 (defun article-strip-trailing-space ()
1654 "Remove all white space from the end of the lines in the article."
1657 (let ((inhibit-point-motion-hooks t)
1660 (while (re-search-forward "[ \t]+$" nil t)
1661 (replace-match "" t t)))))
1663 (defun article-strip-blank-lines ()
1664 "Strip leading, trailing and multiple blank lines."
1666 (article-strip-leading-blank-lines)
1667 (article-remove-trailing-blank-lines)
1668 (article-strip-multiple-blank-lines))
1670 (defun article-strip-all-blank-lines ()
1671 "Strip all blank lines."
1674 (let ((inhibit-point-motion-hooks t)
1677 (while (re-search-forward "^[ \t]*\n" nil t)
1678 (replace-match "" t t)))))
1680 (defun gnus-article-narrow-to-signature ()
1681 "Narrow to the signature; return t if a signature is found, else nil."
1682 (let ((inhibit-point-motion-hooks t))
1683 (when (gnus-article-search-signature)
1685 ;; Check whether we have some limits to what we consider
1686 ;; to be a signature.
1687 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1688 (list gnus-signature-limit)))
1690 (while (setq limit (pop limits))
1691 (if (or (and (integerp limit)
1692 (< (- (point-max) (point)) limit))
1694 (< (count-lines (point) (point-max)) limit))
1695 (and (gnus-functionp limit)
1697 (and (stringp limit)
1698 (not (re-search-forward limit nil t))))
1699 () ; This limit did not succeed.
1703 (narrow-to-region (point) (point-max))
1706 (defun gnus-article-search-signature ()
1707 "Search the current buffer for the signature separator.
1708 Put point at the beginning of the signature separator."
1709 (let ((cur (point)))
1710 (goto-char (point-max))
1711 (if (if (stringp gnus-signature-separator)
1712 (re-search-backward gnus-signature-separator nil t)
1713 (let ((seps gnus-signature-separator))
1715 (not (re-search-backward (car seps) nil t)))
1722 (defun gnus-article-hidden-arg ()
1723 "Return the current prefix arg as a number, or 0 if no prefix."
1724 (list (if current-prefix-arg
1725 (prefix-numeric-value current-prefix-arg)
1728 (defun gnus-article-check-hidden-text (type arg)
1729 "Return nil if hiding is necessary.
1730 Arg can be nil or a number. Nil and positive means hide, negative
1731 means show, 0 means toggle."
1734 (let ((hide (gnus-article-hidden-text-p type)))
1740 (gnus-article-show-hidden-text type))
1742 (if (eq hide 'hidden)
1743 (gnus-article-show-hidden-text type)
1746 (defun gnus-article-hidden-text-p (type)
1747 "Say whether the current buffer contains hidden text of type TYPE."
1748 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1750 (not (get-text-property pos 'invisible))
1751 (not (get-text-property pos 'dummy-invisible)))
1753 (text-property-any (1+ pos) (point-max) 'article-type type)))
1758 (defun gnus-article-show-hidden-text (type &optional hide)
1759 "Show all hidden text of type TYPE.
1760 If HIDE, hide the text instead."
1762 (let ((buffer-read-only nil)
1763 (inhibit-point-motion-hooks t)
1766 (while (setq beg (text-property-any end (point-max) 'article-type type))
1769 (text-property-not-all beg (point-max) 'article-type type)
1772 (gnus-article-hide-text beg end gnus-hidden-properties)
1773 (gnus-article-unhide-text beg end))
1777 (defconst article-time-units
1778 `((year . ,(* 365.25 24 60 60))
1779 (week . ,(* 7 24 60 60))
1780 (day . ,(* 24 60 60))
1784 "Mapping from time units to seconds.")
1786 (defun article-date-ut (&optional type highlight header)
1787 "Convert DATE date to universal time in the current article.
1788 If TYPE is `local', convert to local time; if it is `lapsed', output
1789 how much time has lapsed since DATE. For `lapsed', the value of
1790 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
1791 should replace the \"Date:\" one, or should be added below it."
1792 (interactive (list 'ut t))
1793 (let* ((header (or header
1794 (message-fetch-field "date")
1796 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1799 ((not gnus-article-date-lapsed-new-header)
1805 (date (if (vectorp header) (mail-header-date header)
1807 (inhibit-point-motion-hooks t)
1810 (when (and date (not (string= date "")))
1813 (article-narrow-to-head)
1814 (when (re-search-forward tdate-regexp nil t)
1815 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1816 eface (get-text-property (1- (gnus-point-at-eol))
1819 (goto-char (point-min))
1820 (let ((buffer-read-only nil))
1821 ;; Delete any old Date headers.
1822 (while (re-search-forward date-regexp nil t)
1824 (delete-region (progn (beginning-of-line) (point))
1825 (progn (end-of-line) (point)))
1826 (delete-region (progn (beginning-of-line) (point))
1827 (progn (forward-line 1) (point))))
1829 (if (re-search-forward tdate-regexp nil t)
1831 (insert (article-make-date-line date type))
1837 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1838 (put-text-property (match-beginning 1) (1+ (match-end 1))
1840 (put-text-property (match-beginning 2) (match-end 2)
1843 (defun article-make-date-line (date type)
1844 "Return a DATE line of TYPE."
1845 (let ((time (condition-case ()
1849 ;; Convert to the local timezone. We have to slap a
1850 ;; `condition-case' round the calls to the timezone
1851 ;; functions since they aren't particularly resistant to
1854 (let ((tz (car (current-time-zone))))
1855 (format "Date: %s %s%04d" (current-time-string time)
1856 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1857 ;; Convert to Universal Time.
1860 (current-time-string
1861 (let* ((e (parse-time-string date))
1862 (tm (apply 'encode-time e))
1864 (ls (- (cadr tm) (car (current-time-zone)))))
1865 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1866 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1869 ;; Get the original date from the article.
1870 ((eq type 'original)
1871 (concat "Date: " (if (string-match "\n+$" date)
1872 (substring date 0 (match-beginning 0))
1874 ;; Let the user define the format.
1876 (if (gnus-functionp gnus-article-time-format)
1877 (funcall gnus-article-time-format time)
1880 (format-time-string gnus-article-time-format time))))
1885 (format-time-string "%Y%m%dT%H%M%S" time)))
1886 ;; Do an X-Sent lapsed format.
1888 ;; If the date is seriously mangled, the timezone functions are
1889 ;; liable to bug out, so we ignore all errors.
1890 (let* ((now (current-time))
1891 (real-time (subtract-time now time))
1892 (real-sec (and real-time
1893 (+ (* (float (car real-time)) 65536)
1895 (sec (and real-time (abs real-sec)))
1905 ;; This is a bit convoluted, but basically we go
1906 ;; through the time units for years, weeks, etc,
1907 ;; and divide things to see whether that results
1908 ;; in positive answers.
1911 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1912 ;; The (remaining) seconds are too few to
1913 ;; be divided into this time unit.
1915 ;; It's big enough, so we output it.
1916 (setq sec (- sec (* num (cdr unit))))
1918 (concat (if prev ", " "") (int-to-string
1920 " " (symbol-name (car unit))
1921 (if (> num 1) "s" ""))
1923 article-time-units "")
1924 ;; If dates are odd, then it might appear like the
1925 ;; article was sent in the future.
1928 " in the future"))))))
1930 (error "Unknown conversion type: %s" type)))))
1932 (defun article-date-local (&optional highlight)
1933 "Convert the current article date to the local timezone."
1934 (interactive (list t))
1935 (article-date-ut 'local highlight))
1937 (defun article-date-original (&optional highlight)
1938 "Convert the current article date to what it was originally.
1939 This is only useful if you have used some other date conversion
1940 function and want to see what the date was before converting."
1941 (interactive (list t))
1942 (article-date-ut 'original highlight))
1944 (defun article-date-lapsed (&optional highlight)
1945 "Convert the current article date to time lapsed since it was sent."
1946 (interactive (list t))
1947 (article-date-ut 'lapsed highlight))
1949 (defun article-update-date-lapsed ()
1950 "Function to be run from a timer to update the lapsed time line."
1951 (let (deactivate-mark)
1956 (set-buffer (window-buffer w))
1957 (when (eq major-mode 'gnus-article-mode)
1958 (goto-char (point-min))
1959 (when (re-search-forward "^X-Sent:" nil t)
1960 (article-date-lapsed t))))
1963 (defun gnus-start-date-timer (&optional n)
1964 "Start a timer to update the X-Sent header in the article buffers.
1965 The numerical prefix says how frequently (in seconds) the function
1970 (gnus-stop-date-timer)
1971 (setq article-lapsed-timer
1972 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1974 (defun gnus-stop-date-timer ()
1975 "Stop the X-Sent timer."
1977 (when article-lapsed-timer
1978 (nnheader-cancel-timer article-lapsed-timer)
1979 (setq article-lapsed-timer nil)))
1981 (defun article-date-user (&optional highlight)
1982 "Convert the current article date to the user-defined format.
1983 This format is defined by the `gnus-article-time-format' variable."
1984 (interactive (list t))
1985 (article-date-ut 'user highlight))
1987 (defun article-date-iso8601 (&optional highlight)
1988 "Convert the current article date to ISO8601."
1989 (interactive (list t))
1990 (article-date-ut 'iso8601 highlight))
1992 (defun article-show-all ()
1993 "Show all hidden text in the article buffer."
1996 (let ((buffer-read-only nil))
1997 (gnus-article-unhide-text (point-min) (point-max)))))
1999 (defun article-emphasize (&optional arg)
2000 "Emphasize text according to `gnus-emphasis-alist'."
2001 (interactive (gnus-article-hidden-arg))
2002 (unless (gnus-article-check-hidden-text 'emphasis arg)
2004 (let ((alist (or (with-current-buffer gnus-summary-buffer
2005 gnus-article-emphasis-alist)
2006 gnus-emphasis-alist))
2007 (buffer-read-only nil)
2008 (props (append '(article-type emphasis)
2009 gnus-hidden-properties))
2010 regexp elem beg invisible visible face)
2013 (while (setq elem (pop alist))
2015 (setq regexp (car elem)
2016 invisible (nth 1 elem)
2017 visible (nth 2 elem)
2019 (while (re-search-forward regexp nil t)
2020 (when (and (match-beginning visible) (match-beginning invisible))
2021 (gnus-article-hide-text
2022 (match-beginning invisible) (match-end invisible) props)
2023 (gnus-article-unhide-text-type
2024 (match-beginning visible) (match-end visible) 'emphasis)
2025 (gnus-put-text-property-excluding-newlines
2026 (match-beginning visible) (match-end visible) 'face face)
2027 (goto-char (match-end invisible)))))))))
2029 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2030 "Setup newsgroup emphasis alist."
2031 (unless gnus-article-emphasis-alist
2032 (let ((name (and gnus-newsgroup-name
2033 (gnus-group-real-name gnus-newsgroup-name))))
2034 (make-local-variable 'gnus-article-emphasis-alist)
2035 (setq gnus-article-emphasis-alist
2037 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2038 (while (setq elem (pop alist))
2039 (when (and name (string-match (car elem) name))
2041 highlight (copy-list (cdr elem)))))
2043 (copy-list highlight-words)
2044 (if gnus-newsgroup-name
2045 (copy-list (gnus-group-find-parameter
2046 gnus-newsgroup-name 'highlight-words t)))
2047 gnus-emphasis-alist)))))
2049 (defvar gnus-summary-article-menu)
2050 (defvar gnus-summary-post-menu)
2052 ;;; Saving functions.
2054 (defun gnus-article-save (save-buffer file &optional num)
2055 "Save the currently selected article."
2056 (unless gnus-save-all-headers
2057 ;; Remove headers according to `gnus-saved-headers'.
2058 (let ((gnus-visible-headers
2059 (or gnus-saved-headers gnus-visible-headers))
2060 (gnus-article-buffer save-buffer))
2062 (set-buffer save-buffer)
2063 (article-hide-headers 1 t))))
2064 (save-window-excursion
2065 (if (not gnus-default-article-saver)
2066 (error "No default saver is defined")
2067 ;; !!! Magic! The saving functions all save
2068 ;; `gnus-save-article-buffer' (or so they think), but we
2069 ;; bind that variable to our save-buffer.
2070 (set-buffer gnus-article-buffer)
2071 (let* ((gnus-save-article-buffer save-buffer)
2074 ((not gnus-prompt-before-saving) 'default)
2075 ((eq gnus-prompt-before-saving 'always) nil)
2077 (gnus-number-of-articles-to-be-saved
2078 (when (eq gnus-prompt-before-saving t)
2080 (set-buffer gnus-article-current-summary)
2081 (funcall gnus-default-article-saver filename)))))
2083 (defun gnus-read-save-file-name (prompt &optional filename
2084 function group headers variable)
2086 (funcall function group headers (symbol-value variable)))
2091 ((eq filename 'default)
2097 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2100 (if (and gnus-number-of-articles-to-be-saved
2101 (> gnus-number-of-articles-to-be-saved 1))
2102 (format "these %d articles"
2103 gnus-number-of-articles-to-be-saved)
2106 ;; Let the split methods have their say.
2108 ;; No split name was found.
2111 (concat prompt " (default "
2112 (file-name-nondirectory default-name) ") ")
2113 (file-name-directory default-name)
2115 ;; A single group name is returned.
2116 ((stringp split-name)
2118 (funcall function split-name headers
2119 (symbol-value variable)))
2121 (concat prompt " (default "
2122 (file-name-nondirectory default-name) ") ")
2123 (file-name-directory default-name)
2125 ;; A single split name was found
2126 ((= 1 (length split-name))
2127 (let* ((name (expand-file-name
2128 (car split-name) gnus-article-save-directory))
2129 (dir (cond ((file-directory-p name)
2130 (file-name-as-directory name))
2131 ((file-exists-p name) name)
2132 (t gnus-article-save-directory))))
2134 (concat prompt " (default " name ") ")
2136 ;; A list of splits was found.
2138 (setq split-name (nreverse split-name))
2140 (let ((file-name-history
2141 (nconc split-name file-name-history)))
2145 (concat prompt " (`M-p' for defaults) ")
2146 gnus-article-save-directory
2148 gnus-article-save-directory)))
2149 (car (push result file-name-history)))))))
2150 ;; Create the directory.
2151 (gnus-make-directory (file-name-directory file))
2152 ;; If we have read a directory, we append the default file name.
2153 (when (file-directory-p file)
2154 (setq file (concat (file-name-as-directory file)
2155 (file-name-nondirectory default-name))))
2156 ;; Possibly translate some characters.
2157 (nnheader-translate-file-chars file)))))
2158 (gnus-make-directory (file-name-directory result))
2159 (set variable result)))
2161 (defun gnus-article-archive-name (group)
2162 "Return the first instance of an \"Archive-name\" in the current buffer."
2163 (let ((case-fold-search t))
2164 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2165 (nnheader-concat gnus-article-save-directory
2166 (match-string 1)))))
2168 (defun gnus-article-nndoc-name (group)
2169 "If GROUP is an nndoc group, return the name of the parent group."
2170 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2171 (gnus-group-get-parameter group 'save-article-group)))
2173 (defun gnus-summary-save-in-rmail (&optional filename)
2174 "Append this article to Rmail file.
2175 Optional argument FILENAME specifies file name.
2176 Directory to save to is default to `gnus-article-save-directory'."
2177 (setq filename (gnus-read-save-file-name
2178 "Save %s in rmail file:" filename
2179 gnus-rmail-save-name gnus-newsgroup-name
2180 gnus-current-headers 'gnus-newsgroup-last-rmail))
2181 (gnus-eval-in-buffer-window gnus-save-article-buffer
2185 (gnus-output-to-rmail filename))))
2188 (defun gnus-summary-save-in-mail (&optional filename)
2189 "Append this article to Unix mail file.
2190 Optional argument FILENAME specifies file name.
2191 Directory to save to is default to `gnus-article-save-directory'."
2192 (setq filename (gnus-read-save-file-name
2193 "Save %s in Unix mail file:" filename
2194 gnus-mail-save-name gnus-newsgroup-name
2195 gnus-current-headers 'gnus-newsgroup-last-mail))
2196 (gnus-eval-in-buffer-window gnus-save-article-buffer
2200 (if (and (file-readable-p filename)
2201 (mail-file-babyl-p filename))
2202 (rmail-output-to-rmail-file filename t)
2203 (gnus-output-to-mail filename)))))
2206 (defun gnus-summary-save-in-file (&optional filename overwrite)
2207 "Append this article to file.
2208 Optional argument FILENAME specifies file name.
2209 Directory to save to is default to `gnus-article-save-directory'."
2210 (setq filename (gnus-read-save-file-name
2211 "Save %s in file:" filename
2212 gnus-file-save-name gnus-newsgroup-name
2213 gnus-current-headers 'gnus-newsgroup-last-file))
2214 (gnus-eval-in-buffer-window gnus-save-article-buffer
2218 (when (and overwrite
2219 (file-exists-p filename))
2220 (delete-file filename))
2221 (gnus-output-to-file filename))))
2224 (defun gnus-summary-write-to-file (&optional filename)
2225 "Write this article to a file.
2226 Optional argument FILENAME specifies file name.
2227 The directory to save in defaults to `gnus-article-save-directory'."
2228 (gnus-summary-save-in-file nil t))
2230 (defun gnus-summary-save-body-in-file (&optional filename)
2231 "Append this article body to a file.
2232 Optional argument FILENAME specifies file name.
2233 The directory to save in defaults to `gnus-article-save-directory'."
2234 (setq filename (gnus-read-save-file-name
2235 "Save %s body in file:" filename
2236 gnus-file-save-name gnus-newsgroup-name
2237 gnus-current-headers 'gnus-newsgroup-last-file))
2238 (gnus-eval-in-buffer-window gnus-save-article-buffer
2242 (when (article-goto-body)
2243 (narrow-to-region (point) (point-max)))
2244 (gnus-output-to-file filename))))
2247 (defun gnus-summary-save-in-pipe (&optional command)
2248 "Pipe this article to subprocess."
2250 (cond ((and (eq command 'default)
2251 gnus-last-shell-command)
2252 gnus-last-shell-command)
2256 "Shell command on %s: "
2257 (if (and gnus-number-of-articles-to-be-saved
2258 (> gnus-number-of-articles-to-be-saved 1))
2259 (format "these %d articles"
2260 gnus-number-of-articles-to-be-saved)
2262 gnus-last-shell-command))))
2263 (when (string-equal command "")
2264 (setq command gnus-last-shell-command))
2265 (gnus-eval-in-buffer-window gnus-article-buffer
2268 (shell-command-on-region (point-min) (point-max) command nil)))
2269 (setq gnus-last-shell-command command))
2271 ;;; Article file names when saving.
2273 (defun gnus-capitalize-newsgroup (newsgroup)
2274 "Capitalize NEWSGROUP name."
2275 (when (not (zerop (length newsgroup)))
2276 (concat (char-to-string (upcase (aref newsgroup 0)))
2277 (substring newsgroup 1))))
2279 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2280 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2281 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2282 Otherwise, it is like ~/News/news/group/num."
2285 (concat (if (gnus-use-long-file-name 'not-save)
2286 (gnus-capitalize-newsgroup newsgroup)
2287 (gnus-newsgroup-directory-form newsgroup))
2288 "/" (int-to-string (mail-header-number headers)))
2289 gnus-article-save-directory)))
2291 (string-equal (file-name-directory default)
2292 (file-name-directory last-file))
2293 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2295 (or last-file default))))
2297 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2298 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2299 If variable `gnus-use-long-file-name' is non-nil, it is
2300 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2303 (concat (if (gnus-use-long-file-name 'not-save)
2305 (gnus-newsgroup-directory-form newsgroup))
2306 "/" (int-to-string (mail-header-number headers)))
2307 gnus-article-save-directory)))
2309 (string-equal (file-name-directory default)
2310 (file-name-directory last-file))
2311 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2313 (or last-file default))))
2315 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2316 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2317 If variable `gnus-use-long-file-name' is non-nil, it is
2318 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2321 (if (gnus-use-long-file-name 'not-save)
2322 (gnus-capitalize-newsgroup newsgroup)
2323 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2324 gnus-article-save-directory)))
2326 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2327 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2328 If variable `gnus-use-long-file-name' is non-nil, it is
2329 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2332 (if (gnus-use-long-file-name 'not-save)
2334 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2335 gnus-article-save-directory)))
2342 (setq afunc (car func)
2345 gfunc (intern (format "gnus-%s" func))))
2347 (if (not (fboundp afunc))
2349 `(lambda (&optional interactive &rest args)
2350 ,(documentation afunc t)
2351 (interactive (list t))
2353 (set-buffer gnus-article-buffer)
2355 (call-interactively ',afunc)
2356 (apply ',afunc args))))))))
2357 '(article-hide-headers
2358 article-hide-boring-headers
2359 article-treat-overstrike
2360 article-fill-long-lines
2361 article-capitalize-sentences
2363 article-display-x-face
2364 article-de-quoted-unreadable
2365 article-mime-decode-quoted-printable
2367 article-strip-banner
2370 article-hide-signature
2371 article-strip-headers-in-body
2372 article-remove-trailing-blank-lines
2373 article-strip-leading-blank-lines
2374 article-strip-multiple-blank-lines
2375 article-strip-leading-space
2376 article-strip-trailing-space
2377 article-strip-blank-lines
2378 article-strip-all-blank-lines
2380 article-date-iso8601
2381 article-date-original
2383 article-decode-mime-words
2384 article-decode-charset
2385 article-decode-encoded-words
2389 article-treat-dumbquotes
2390 article-normalize-headers
2391 (article-show-all . gnus-article-show-all-headers))))
2394 ;;; Gnus article mode
2397 (put 'gnus-article-mode 'mode-class 'special)
2399 (set-keymap-parent gnus-article-mode-map widget-keymap)
2401 (gnus-define-keys gnus-article-mode-map
2402 " " gnus-article-goto-next-page
2403 "\177" gnus-article-goto-prev-page
2404 [delete] gnus-article-goto-prev-page
2405 [backspace] gnus-article-goto-prev-page
2406 "\C-c^" gnus-article-refer-article
2407 "h" gnus-article-show-summary
2408 "s" gnus-article-show-summary
2409 "\C-c\C-m" gnus-article-mail
2410 "?" gnus-article-describe-briefly
2411 "e" gnus-article-edit
2412 "<" beginning-of-buffer
2414 "\C-c\C-i" gnus-info-find-node
2417 "\C-d" gnus-article-read-summary-keys
2418 "\M-*" gnus-article-read-summary-keys
2419 "\M-#" gnus-article-read-summary-keys
2420 "\M-^" gnus-article-read-summary-keys
2421 "\M-g" gnus-article-read-summary-keys)
2423 (substitute-key-definition
2424 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2426 (defun gnus-article-make-menu-bar ()
2427 (gnus-turn-off-edit-menu 'article)
2428 (unless (boundp 'gnus-article-article-menu)
2430 gnus-article-article-menu gnus-article-mode-map ""
2432 ["Scroll forwards" gnus-article-goto-next-page t]
2433 ["Scroll backwards" gnus-article-goto-prev-page t]
2434 ["Show summary" gnus-article-show-summary t]
2435 ["Fetch Message-ID at point" gnus-article-refer-article t]
2436 ["Mail to address at point" gnus-article-mail t]
2437 ["Send a bug report" gnus-bug t]))
2440 gnus-article-treatment-menu gnus-article-mode-map ""
2442 ["Hide headers" gnus-article-hide-headers t]
2443 ["Hide signature" gnus-article-hide-signature t]
2444 ["Hide citation" gnus-article-hide-citation t]
2445 ["Treat overstrike" gnus-article-treat-overstrike t]
2446 ["Remove carriage return" gnus-article-remove-cr t]
2447 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2449 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2451 (when (boundp 'gnus-summary-post-menu)
2452 (define-key gnus-article-mode-map [menu-bar post]
2453 (cons "Post" gnus-summary-post-menu)))
2455 (gnus-run-hooks 'gnus-article-menu-hook)))
2457 (defun gnus-article-mode ()
2458 "Major mode for displaying an article.
2460 All normal editing commands are switched off.
2462 The following commands are available in addition to all summary mode
2464 \\<gnus-article-mode-map>
2465 \\[gnus-article-next-page]\t Scroll the article one page forwards
2466 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2467 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2468 \\[gnus-article-show-summary]\t Display the summary buffer
2469 \\[gnus-article-mail]\t Send a reply to the address near point
2470 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2471 \\[gnus-info-find-node]\t Go to the Gnus info node"
2473 (when (gnus-visual-p 'article-menu 'menu)
2474 (gnus-article-make-menu-bar))
2475 (gnus-simplify-mode-line)
2476 (setq mode-name "Article")
2477 (setq major-mode 'gnus-article-mode)
2478 (make-local-variable 'minor-mode-alist)
2479 (use-local-map gnus-article-mode-map)
2480 (gnus-update-format-specifications nil 'article-mode)
2481 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2482 (make-local-variable 'gnus-page-broken)
2483 (make-local-variable 'gnus-button-marker-list)
2484 (make-local-variable 'gnus-article-current-summary)
2485 (make-local-variable 'gnus-article-mime-handles)
2486 (make-local-variable 'gnus-article-decoded-p)
2487 (make-local-variable 'gnus-article-mime-handle-alist)
2488 (make-local-variable 'gnus-article-washed-types)
2489 (gnus-set-default-directory)
2490 (buffer-disable-undo)
2491 (setq buffer-read-only t)
2492 (set-syntax-table gnus-article-mode-syntax-table)
2493 (mm-enable-multibyte)
2494 (gnus-run-hooks 'gnus-article-mode-hook))
2496 (defun gnus-article-setup-buffer ()
2497 "Initialize the article buffer."
2498 (let* ((name (if gnus-single-article-buffer "*Article*"
2499 (concat "*Article " gnus-newsgroup-name "*")))
2501 (progn (string-match "\\*Article" name)
2502 (concat " *Original Article"
2503 (substring name (match-end 0))))))
2504 (setq gnus-article-buffer name)
2505 (setq gnus-original-article-buffer original)
2506 (setq gnus-article-mime-handle-alist nil)
2507 ;; This might be a variable local to the summary buffer.
2508 (unless gnus-single-article-buffer
2510 (set-buffer gnus-summary-buffer)
2511 (setq gnus-article-buffer name)
2512 (setq gnus-original-article-buffer original)
2513 (gnus-set-global-variables)))
2514 (gnus-article-setup-highlight-words)
2515 ;; Init original article buffer.
2517 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2518 (mm-enable-multibyte)
2519 (setq major-mode 'gnus-original-article-mode)
2520 (make-local-variable 'gnus-original-article))
2521 (if (get-buffer name)
2524 (buffer-disable-undo)
2525 (setq buffer-read-only t)
2526 (unless (eq major-mode 'gnus-article-mode)
2527 (gnus-article-mode))
2530 (set-buffer (gnus-get-buffer-create name))
2532 (make-local-variable 'gnus-summary-buffer)
2533 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2534 (current-buffer)))))
2536 ;; Set article window start at LINE, where LINE is the number of lines
2537 ;; from the head of the article.
2538 (defun gnus-article-set-window-start (&optional line)
2540 (get-buffer-window gnus-article-buffer t)
2542 (set-buffer gnus-article-buffer)
2543 (goto-char (point-min))
2546 (gnus-message 6 "Moved to bookmark")
2547 (search-forward "\n\n" nil t)
2551 (defun gnus-article-prepare (article &optional all-headers header)
2552 "Prepare ARTICLE in article mode buffer.
2553 ARTICLE should either be an article number or a Message-ID.
2554 If ARTICLE is an id, HEADER should be the article headers.
2555 If ALL-HEADERS is non-nil, no headers are hidden."
2557 ;; Make sure we start in a summary buffer.
2558 (unless (eq major-mode 'gnus-summary-mode)
2559 (set-buffer gnus-summary-buffer))
2560 (setq gnus-summary-buffer (current-buffer))
2561 (let* ((gnus-article (if header (mail-header-number header) article))
2562 (summary-buffer (current-buffer))
2563 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2564 (group gnus-newsgroup-name)
2567 (gnus-article-setup-buffer)
2568 (set-buffer gnus-article-buffer)
2569 ;; Deactivate active regions.
2570 (when (and (boundp 'transient-mark-mode)
2571 transient-mark-mode)
2572 (setq mark-active nil))
2573 (if (not (setq result (let ((buffer-read-only nil))
2574 (gnus-request-article-this-buffer
2576 ;; There is no such article.
2578 (when (and (numberp article)
2579 (not (memq article gnus-newsgroup-sparse)))
2580 (setq gnus-article-current
2581 (cons gnus-newsgroup-name article))
2582 (set-buffer gnus-summary-buffer)
2583 (setq gnus-current-article article)
2584 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2586 (gnus-summary-set-agent-mark article)
2587 (message "Message marked for downloading"))
2588 (gnus-summary-mark-article article gnus-canceled-mark)
2589 (unless (memq article gnus-newsgroup-sparse)
2591 "No such article (may have expired or been canceled)")))))
2592 (if (or (eq result 'pseudo)
2593 (eq result 'nneething))
2596 (set-buffer summary-buffer)
2597 (push article gnus-newsgroup-history)
2598 (setq gnus-last-article gnus-current-article
2599 gnus-current-article 0
2600 gnus-current-headers nil
2601 gnus-article-current nil)
2602 (if (eq result 'nneething)
2603 (gnus-configure-windows 'summary)
2604 (gnus-configure-windows 'article))
2605 (gnus-set-global-variables))
2606 (let ((gnus-article-mime-handle-alist-1
2607 gnus-article-mime-handle-alist))
2608 (gnus-set-mode-line 'article)))
2609 ;; The result from the `request' was an actual article -
2610 ;; or at least some text that is now displayed in the
2612 (when (and (numberp article)
2613 (not (eq article gnus-current-article)))
2614 ;; Seems like a new article has been selected.
2615 ;; `gnus-current-article' must be an article number.
2617 (set-buffer summary-buffer)
2618 (push article gnus-newsgroup-history)
2619 (setq gnus-last-article gnus-current-article
2620 gnus-current-article article
2621 gnus-current-headers
2622 (gnus-summary-article-header gnus-current-article)
2623 gnus-article-current
2624 (cons gnus-newsgroup-name gnus-current-article))
2625 (unless (vectorp gnus-current-headers)
2626 (setq gnus-current-headers nil))
2627 (gnus-summary-goto-subject gnus-current-article)
2628 (when (gnus-summary-show-thread)
2629 ;; If the summary buffer really was folded, the
2630 ;; previous goto may not actually have gone to
2631 ;; the right article, but the thread root instead.
2633 (gnus-summary-goto-subject gnus-current-article))
2634 (gnus-run-hooks 'gnus-mark-article-hook)
2635 (gnus-set-mode-line 'summary)
2636 (when (gnus-visual-p 'article-highlight 'highlight)
2637 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2638 ;; Set the global newsgroup variables here.
2639 (gnus-set-global-variables)
2640 (setq gnus-have-all-headers
2641 (or all-headers gnus-show-all-headers))))
2642 (when (or (numberp article)
2644 (gnus-article-prepare-display)
2646 (goto-char (point-min))
2647 (setq gnus-page-broken
2648 (when gnus-break-pages
2649 (gnus-narrow-to-page)
2651 (let ((gnus-article-mime-handle-alist-1
2652 gnus-article-mime-handle-alist))
2653 (gnus-set-mode-line 'article))
2655 (set-window-point (get-buffer-window (current-buffer)) (point))
2656 (gnus-configure-windows 'article)
2660 (defun gnus-article-prepare-display ()
2661 "Make the current buffer look like a nice article."
2662 ;; Hooks for getting information from the article.
2663 ;; This hook must be called before being narrowed.
2664 (let ((gnus-article-buffer (current-buffer))
2666 (unless (eq major-mode 'gnus-article-mode)
2667 (gnus-article-mode))
2668 (setq buffer-read-only nil)
2669 (gnus-run-hooks 'gnus-tmp-internal-hook)
2670 (gnus-run-hooks 'gnus-article-prepare-hook)
2671 (when gnus-display-mime-function
2672 (funcall gnus-display-mime-function))))
2675 ;;; Gnus MIME viewing functions
2678 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2679 "The following specs can be used:
2681 %T MIME type, along with additional info
2682 %n The `name' parameter
2683 %d The description, if any
2684 %l The length of the encoded part
2685 %p The part identifier number
2686 %e Dots if the part isn't displayed")
2688 (defvar gnus-mime-button-line-format-alist
2689 '((?t gnus-tmp-type ?s)
2690 (?T gnus-tmp-type-long ?s)
2691 (?n gnus-tmp-name ?s)
2692 (?d gnus-tmp-description ?s)
2694 (?l gnus-tmp-length ?d)
2695 (?e gnus-tmp-dots ?s)))
2697 (defvar gnus-mime-button-commands
2698 '((gnus-article-press-button "\r" "Toggle Display")
2699 (gnus-mime-view-part "v" "View Interactively...")
2700 (gnus-mime-save-part "o" "Save...")
2701 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2702 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2703 (gnus-mime-internalize-part "E" "View Internally")
2704 (gnus-mime-externalize-part "e" "View Externally")
2705 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2707 (defun gnus-article-mime-part-status ()
2708 (if gnus-article-mime-handle-alist-1
2709 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2712 (defvar gnus-mime-button-map nil)
2713 (unless gnus-mime-button-map
2714 (setq gnus-mime-button-map (make-sparse-keymap))
2715 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2716 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2717 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2719 (define-key gnus-mime-button-map (cadr c) (car c)))
2720 gnus-mime-button-commands))
2722 (defun gnus-mime-button-menu (event)
2723 "Construct a context-sensitive menu of MIME commands."
2726 (let ((pos (event-start event)))
2727 (set-buffer (window-buffer (posn-window pos)))
2728 (goto-char (posn-point pos))
2729 (gnus-article-check-buffer)
2730 (let ((response (x-popup-menu
2732 ("" ,@(mapcar (lambda (c)
2733 (cons (caddr c) (car c)))
2734 gnus-mime-button-commands))))))
2736 (funcall response))))))
2738 (defun gnus-mime-view-all-parts (&optional handles)
2739 "View all the MIME parts."
2741 (save-current-buffer
2742 (set-buffer gnus-article-buffer)
2743 (let ((handles (or handles gnus-article-mime-handles))
2744 (mail-parse-charset gnus-newsgroup-charset)
2745 (mail-parse-ignored-charsets
2746 (save-excursion (set-buffer gnus-summary-buffer)
2747 gnus-newsgroup-ignored-charsets)))
2748 (if (stringp (car handles))
2749 (gnus-mime-view-all-parts (cdr handles))
2750 (mapcar 'mm-display-part handles)))))
2752 (defun gnus-mime-save-part ()
2753 "Save the MIME part under point."
2755 (gnus-article-check-buffer)
2756 (let ((data (get-text-property (point) 'gnus-data)))
2757 (mm-save-part data)))
2759 (defun gnus-mime-pipe-part ()
2760 "Pipe the MIME part under point to a process."
2762 (gnus-article-check-buffer)
2763 (let ((data (get-text-property (point) 'gnus-data)))
2764 (mm-pipe-part data)))
2766 (defun gnus-mime-view-part ()
2767 "Interactively choose a viewing method for the MIME part under point."
2769 (gnus-article-check-buffer)
2770 (let ((data (get-text-property (point) 'gnus-data)))
2771 (mm-interactively-view-part data)))
2773 (defun gnus-mime-copy-part (&optional handle)
2774 "Put the the MIME part under point into a new buffer."
2776 (gnus-article-check-buffer)
2777 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2778 (contents (mm-get-part handle))|
2779 (base (file-name-nondirectory
2781 (mail-content-type-get (mm-handle-type handle) 'name)
2782 (mail-content-type-get (mm-handle-type handle)
2785 (buffer (generate-new-buffer base)))
2786 (switch-to-buffer buffer)
2788 ;; We do it this way to make `normal-mode' set the appropriate mode.
2791 (setq buffer-file-name (expand-file-name base))
2793 (setq buffer-file-name nil))
2794 (goto-char (point-min))))
2796 (defun gnus-mime-inline-part (&optional handle)
2797 "Insert the MIME part under point into the current buffer."
2799 (gnus-article-check-buffer)
2800 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2804 (if (mm-handle-undisplayer handle)
2805 (mm-remove-part handle)
2806 (setq contents (mm-get-part handle))
2808 (mm-insert-inline handle contents)
2811 (defun gnus-mime-externalize-part (&optional handle)
2812 "View the MIME part under point with an external viewer."
2814 (gnus-article-check-buffer)
2815 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2816 (mm-user-display-methods nil)
2817 (mm-inline-large-images nil)
2818 (mail-parse-charset gnus-newsgroup-charset)
2819 (mail-parse-ignored-charsets
2820 (save-excursion (set-buffer gnus-summary-buffer)
2821 gnus-newsgroup-ignored-charsets)))
2822 (if (mm-handle-undisplayer handle)
2823 (mm-remove-part handle)
2824 (mm-display-part handle))))
2826 (defun gnus-mime-internalize-part (&optional handle)
2827 "View the MIME part under point with an internal viewer."
2829 (gnus-article-check-buffer)
2830 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2831 (mm-user-display-methods '((".*" . inline)))
2832 (mm-inline-large-images t)
2833 (mail-parse-charset gnus-newsgroup-charset)
2834 (mail-parse-ignored-charsets
2835 (save-excursion (set-buffer gnus-summary-buffer)
2836 gnus-newsgroup-ignored-charsets)))
2837 (if (mm-handle-undisplayer handle)
2838 (mm-remove-part handle)
2839 (mm-display-part handle))))
2841 (defun gnus-article-part-wrapper (n function)
2842 (save-current-buffer
2843 (set-buffer gnus-article-buffer)
2844 (when (> n (length gnus-article-mime-handle-alist))
2845 (error "No such part"))
2846 (gnus-article-goto-part n)
2847 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2848 (funcall function handle))))
2850 (defun gnus-article-pipe-part (n)
2851 "Pipe MIME part N, which is the numerical prefix."
2853 (gnus-article-part-wrapper n 'mm-pipe-part))
2855 (defun gnus-article-save-part (n)
2856 "Save MIME part N, which is the numerical prefix."
2858 (gnus-article-part-wrapper n 'mm-save-part))
2860 (defun gnus-article-interactively-view-part (n)
2861 "View MIME part N interactively, which is the numerical prefix."
2863 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2865 (defun gnus-article-copy-part (n)
2866 "Copy MIME part N, which is the numerical prefix."
2868 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2870 (defun gnus-article-externalize-part (n)
2871 "View MIME part N externally, which is the numerical prefix."
2873 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2875 (defun gnus-article-inline-part (n)
2876 "Inline MIME part N, which is the numerical prefix."
2878 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2880 (defun gnus-article-view-part (n)
2881 "View MIME part N, which is the numerical prefix."
2883 (save-current-buffer
2884 (set-buffer gnus-article-buffer)
2885 (when (> n (length gnus-article-mime-handle-alist))
2886 (error "No such part"))
2887 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2888 (when (gnus-article-goto-part n)
2889 (if (equal (car handle) "multipart/alternative")
2890 (gnus-article-press-button)
2891 (when (eq (gnus-mm-display-part handle) 'internal)
2892 (gnus-set-window-start)))))))
2894 (defun gnus-mm-display-part (handle)
2895 "Display HANDLE and fix MIME button."
2896 (let ((id (get-text-property (point) 'gnus-part))
2901 (let ((window (selected-window))
2902 (mail-parse-charset gnus-newsgroup-charset)
2903 (mail-parse-ignored-charsets
2904 (save-excursion (set-buffer gnus-summary-buffer)
2905 gnus-newsgroup-ignored-charsets)))
2908 (let ((win (get-buffer-window (current-buffer) t))
2911 (select-window win))
2914 (if (mm-handle-displayed-p handle)
2915 ;; This will remove the part.
2916 (mm-display-part handle)
2918 (narrow-to-region (point) (1+ (point)))
2919 (mm-display-part handle)
2920 ;; We narrow to the part itself and
2921 ;; then call the treatment functions.
2922 (goto-char (point-min))
2924 (narrow-to-region (point) (point-max))
2927 (1- (length gnus-article-mime-handles))
2928 (car (mm-handle-type handle))))))
2929 (select-window window))))
2931 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2932 (gnus-insert-mime-button
2933 handle id (list (mm-handle-displayed-p handle)))
2934 (goto-char point))))
2936 (defun gnus-article-goto-part (n)
2937 "Go to MIME part N."
2938 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2940 (goto-char point))))
2942 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2943 (let ((gnus-tmp-name
2944 (or (mail-content-type-get (mm-handle-type handle)
2946 (mail-content-type-get (mm-handle-disposition handle)
2949 (gnus-tmp-type (car (mm-handle-type handle)))
2950 (gnus-tmp-description
2951 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2954 (if (if displayed (car displayed)
2955 (mm-handle-displayed-p handle))
2957 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2959 gnus-tmp-type-long b e)
2960 (when (string-match ".*/" gnus-tmp-name)
2961 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2962 (setq gnus-tmp-type-long (concat gnus-tmp-type
2963 (and (not (equal gnus-tmp-name ""))
2964 (concat "; " gnus-tmp-name))))
2965 (or (equal gnus-tmp-description "")
2966 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2971 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2972 `(local-map ,gnus-mime-button-map
2973 keymap ,gnus-mime-button-map
2974 gnus-callback gnus-mm-display-part
2975 gnus-part ,gnus-tmp-id
2976 article-type annotation
2979 (widget-convert-button 'link b e
2981 :action 'gnus-widget-press-button
2982 :button-keymap gnus-mime-button-map
2985 ;; Needed to properly clear the message
2986 ;; due to a bug in wid-edit
2987 (setq help-echo-owns-message t)
2989 "Click to %s the MIME part; %s for more options"
2990 (if (mm-handle-displayed-p
2991 (widget-get widget :mime-handle))
2993 (if gnus-xemacs "button3" "mouse-3"))))))
2995 (defun gnus-widget-press-button (elems el)
2996 (goto-char (widget-get elems :from))
2997 (gnus-article-press-button))
2999 (defvar gnus-displaying-mime nil)
3001 (defun gnus-display-mime (&optional ihandles)
3002 "Display the MIME parts."
3004 (save-selected-window
3005 (let ((window (get-buffer-window gnus-article-buffer))
3008 (select-window window)
3009 ;; We have to do this since selecting the window
3010 ;; may change the point. So we set the window point.
3011 (set-window-point window point)))
3012 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3013 buffer-read-only handle name type b e display)
3014 (when (and (not ihandles)
3015 (not gnus-displaying-mime))
3016 ;; Top-level call; we clean up.
3017 (when gnus-article-mime-handles
3018 (mm-destroy-parts gnus-article-mime-handles)
3019 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3020 (setq gnus-article-mime-handles handles)
3021 ;; We allow users to glean info from the handles.
3022 (when gnus-article-mime-part-function
3023 (gnus-mime-part-function handles)))
3025 (or (not (stringp (car handles)))
3028 (when (and (not ihandles)
3029 (not gnus-displaying-mime))
3030 ;; Clean up for mime parts.
3032 (delete-region (point) (point-max)))
3033 (let ((gnus-displaying-mime t))
3034 (gnus-mime-display-part handles)))
3037 (narrow-to-region (point) (point-max))
3038 (gnus-treat-article nil 1 1)
3041 ;; Highlight the headers.
3045 (narrow-to-region (point-min) (point))
3046 (gnus-treat-article 'head))))))))
3048 (defvar gnus-mime-display-multipart-as-mixed nil)
3050 (defun gnus-mime-display-part (handle)
3053 ((not (stringp (car handle)))
3054 (gnus-mime-display-single handle))
3055 ;; User-defined multipart
3056 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3057 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3059 ;; multipart/alternative
3060 ((and (equal (car handle) "multipart/alternative")
3061 (not gnus-mime-display-multipart-as-mixed))
3062 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3063 (push (cons id handle) gnus-article-mime-handle-alist)
3064 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3065 ;; multipart/related
3066 ((and (equal (car handle) "multipart/related")
3067 (not gnus-mime-display-multipart-as-mixed))
3068 ;;;!!!We should find the start part, but we just default
3069 ;;;!!!to the first part.
3070 (gnus-mime-display-part (cadr handle)))
3071 ;; Other multiparts are handled like multipart/mixed.
3073 (gnus-mime-display-mixed (cdr handle)))))
3075 (defun gnus-mime-part-function (handles)
3076 (if (stringp (car handles))
3077 (mapcar 'gnus-mime-part-function (cdr handles))
3078 (funcall gnus-article-mime-part-function handles)))
3080 (defun gnus-mime-display-mixed (handles)
3081 (mapcar 'gnus-mime-display-part handles))
3083 (defun gnus-mime-display-single (handle)
3084 (let ((type (car (mm-handle-type handle)))
3085 (ignored gnus-ignored-mime-types)
3092 (when (string-match (pop ignored) type)
3093 (throw 'ignored nil)))
3094 (if (and (setq not-attachment
3095 (or (not (mm-handle-disposition handle))
3096 (equal (car (mm-handle-disposition handle))
3098 (mm-attachment-override-p handle)))
3099 (mm-automatic-display-p handle)
3100 (or (mm-inlined-p handle)
3101 (mm-automatic-external-display-p type)))
3103 (when (equal (car (split-string type "/"))
3106 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3107 (push (cons id handle) gnus-article-mime-handle-alist)
3108 (when (or (not display)
3109 (not (gnus-unbuttonized-mime-type-p type)))
3110 (gnus-article-insert-newline)
3111 (gnus-insert-mime-button
3112 handle id (list (or display (and not-attachment text))))
3113 (gnus-article-insert-newline)
3114 (gnus-article-insert-newline)
3116 (let ((beg (point)))
3121 (let ((mail-parse-charset gnus-newsgroup-charset)
3122 (mail-parse-ignored-charsets
3123 (save-excursion (set-buffer gnus-summary-buffer)
3124 gnus-newsgroup-ignored-charsets)))
3125 (mm-display-part handle t))
3126 (goto-char (point-max)))
3127 ((and text not-attachment)
3130 (gnus-article-insert-newline)
3131 (mm-insert-inline handle (mm-get-part handle))
3132 (goto-char (point-max))))
3136 (narrow-to-region beg (point))
3138 nil (length gnus-article-mime-handle-alist)
3139 (1- (length gnus-article-mime-handles))
3140 (car (mm-handle-type handle))))))))))
3142 (defun gnus-unbuttonized-mime-type-p (type)
3143 "Say whether TYPE is to be unbuttonized."
3144 (unless gnus-inhibit-mime-unbuttonizing
3146 (let ((types gnus-unbuttonized-mime-types))
3148 (when (string-match (pop types) type)
3149 (throw 'found t)))))))
3151 (defun gnus-article-insert-newline ()
3152 "Insert a newline, but mark it as undeletable."
3153 (gnus-put-text-property
3154 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3156 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3157 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3160 handle buffer-read-only from props begend not-pref)
3161 (save-window-excursion
3164 (narrow-to-region (car ibegend)
3167 (goto-char (car ibegend))
3170 (delete-region (point-min) (point-max))
3171 (mm-remove-parts handles))
3172 (setq begend (list (point-marker)))
3174 (unless (setq not-pref (cadr (member preferred ihandles)))
3175 (setq not-pref (car ihandles)))
3177 (not (gnus-unbuttonized-mime-type-p
3178 "multipart/alternative")))
3179 (gnus-add-text-properties
3182 (insert (format "%d. " id))
3186 (unless ,(not ibegend)
3187 (setq gnus-article-mime-handle-alist
3188 ',gnus-article-mime-handle-alist))
3189 (gnus-mime-display-alternative
3190 ',ihandles ',not-pref ',begend ,id))
3191 local-map ,gnus-mime-button-map
3192 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3193 face ,gnus-article-button-face
3194 keymap ,gnus-mime-button-map
3197 (widget-convert-button 'link from (point)
3198 :action 'gnus-widget-press-button
3199 :button-keymap gnus-widget-button-keymap)
3201 (while (setq handle (pop handles))
3202 (gnus-add-text-properties
3205 (insert (format "(%c) %-18s"
3206 (if (equal handle preferred) ?* ? )
3207 (if (stringp (car handle))
3209 (car (mm-handle-type handle)))))
3213 (unless ,(not ibegend)
3214 (setq gnus-article-mime-handle-alist
3215 ',gnus-article-mime-handle-alist))
3216 (gnus-mime-display-alternative
3217 ',ihandles ',handle ',begend ,id))
3218 local-map ,gnus-mime-button-map
3219 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3220 face ,gnus-article-button-face
3221 keymap ,gnus-mime-button-map
3224 (widget-convert-button 'link from (point)
3225 :action 'gnus-widget-press-button
3226 :button-keymap gnus-widget-button-keymap)
3230 (if (stringp (car preferred))
3231 (gnus-display-mime preferred)
3232 (let ((mail-parse-charset gnus-newsgroup-charset)
3233 (mail-parse-ignored-charsets
3234 (save-excursion (set-buffer gnus-summary-buffer)
3235 gnus-newsgroup-ignored-charsets)))
3236 (mm-display-part preferred)))
3237 (goto-char (point-max))
3238 (setcdr begend (point-marker)))))
3240 (goto-char point))))
3242 (defun gnus-article-wash-status ()
3243 "Return a string which display status of article washing."
3245 (set-buffer gnus-article-buffer)
3246 (let ((cite (memq 'cite gnus-article-wash-types))
3247 (headers (memq 'headers gnus-article-wash-types))
3248 (boring (memq 'boring-headers gnus-article-wash-types))
3249 (pgp (memq 'pgp gnus-article-wash-types))
3250 (pem (memq 'pem gnus-article-wash-types))
3251 (signature (memq 'signature gnus-article-wash-types))
3252 (overstrike (memq 'overstrike gnus-article-wash-types))
3253 (emphasis (memq 'emphasis gnus-article-wash-types)))
3254 (format "%c%c%c%c%c%c"
3256 (if (or headers boring) ?h ? )
3257 (if (or pgp pem) ?p ? )
3258 (if signature ?s ? )
3259 (if overstrike ?o ? )
3260 (if emphasis ?e ? )))))
3262 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3264 (defun gnus-article-maybe-hide-headers ()
3265 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3266 Provided for backwards compatibility."
3267 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3268 (not (save-excursion (set-buffer gnus-summary-buffer)
3269 gnus-have-all-headers)))
3270 (not gnus-inhibit-hiding))
3271 (gnus-article-hide-headers)))
3275 (defun gnus-output-to-file (file-name)
3276 "Append the current article to a file named FILE-NAME."
3277 (let ((artbuf (current-buffer)))
3279 (insert-buffer-substring artbuf)
3280 ;; Append newline at end of the buffer as separator, and then
3282 (goto-char (point-max))
3284 (append-to-file (point-min) (point-max) file-name)
3287 (defun gnus-narrow-to-page (&optional arg)
3288 "Narrow the article buffer to a page.
3289 If given a numerical ARG, move forward ARG pages."
3291 (setq arg (if arg (prefix-numeric-value arg) 0))
3293 (set-buffer gnus-article-buffer)
3294 (goto-char (point-min))
3296 ;; Remove any old next/prev buttons.
3297 (when (gnus-visual-p 'page-marker)
3298 (let ((buffer-read-only nil))
3299 (gnus-remove-text-with-property 'gnus-prev)
3300 (gnus-remove-text-with-property 'gnus-next)))
3303 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3305 (re-search-forward page-delimiter nil 'move arg)))
3306 (goto-char (match-end 0)))
3309 (if (re-search-forward page-delimiter nil 'move)
3312 (when (and (gnus-visual-p 'page-marker)
3313 (not (= (point-min) 1)))
3315 (goto-char (point-min))
3316 (gnus-insert-prev-page-button)))
3317 (when (and (gnus-visual-p 'page-marker)
3318 (< (+ (point-max) 2) (buffer-size)))
3320 (goto-char (point-max))
3321 (gnus-insert-next-page-button)))))
3323 ;; Article mode commands
3325 (defun gnus-article-goto-next-page ()
3326 "Show the next page of the article."
3328 (when (gnus-article-next-page)
3329 (goto-char (point-min))
3330 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3332 (defun gnus-article-goto-prev-page ()
3333 "Show the next page of the article."
3335 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3336 (gnus-article-prev-page nil)))
3338 (defun gnus-article-next-page (&optional lines)
3339 "Show the next page of the current article.
3340 If end of article, return non-nil. Otherwise return nil.
3341 Argument LINES specifies lines to be scrolled up."
3343 (move-to-window-line -1)
3346 (and (pos-visible-in-window-p) ;Not continuation line.
3348 ;; Nothing in this page.
3349 (if (or (not gnus-page-broken)
3352 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3354 (gnus-narrow-to-page 1) ;Go to next page.
3356 ;; More in this page.
3357 (let ((scroll-in-place nil))
3361 ;; Long lines may cause an end-of-buffer error.
3362 (goto-char (point-max)))))
3363 (move-to-window-line 0)
3366 (defun gnus-article-prev-page (&optional lines)
3367 "Show previous page of current article.
3368 Argument LINES specifies lines to be scrolled down."
3370 (move-to-window-line 0)
3371 (if (and gnus-page-broken
3373 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3375 (gnus-narrow-to-page -1) ;Go to previous page.
3376 (goto-char (point-max))
3378 (let ((scroll-in-place nil))
3382 (beginning-of-buffer
3383 (goto-char (point-min))))
3384 (move-to-window-line 0)))))
3386 (defun gnus-article-refer-article ()
3387 "Read article specified by message-id around point."
3389 (let ((point (point)))
3390 (search-forward ">" nil t) ;Move point to end of "<....>".
3391 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3392 (let ((message-id (match-string 1)))
3394 (set-buffer gnus-summary-buffer)
3395 (gnus-summary-refer-article message-id))
3397 (error "No references around point"))))
3399 (defun gnus-article-show-summary ()
3400 "Reconfigure windows to show summary buffer."
3402 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3403 (error "There is no summary buffer for this article buffer")
3404 (gnus-article-set-globals)
3405 (gnus-configure-windows 'article)
3406 (gnus-summary-goto-subject gnus-current-article)
3407 (gnus-summary-position-point)))
3409 (defun gnus-article-describe-briefly ()
3410 "Describe article mode commands briefly."
3412 (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")))
3414 (defun gnus-article-summary-command ()
3415 "Execute the last keystroke in the summary buffer."
3417 (let ((obuf (current-buffer))
3418 (owin (current-window-configuration))
3420 (switch-to-buffer gnus-article-current-summary 'norecord)
3421 (setq func (lookup-key (current-local-map) (this-command-keys)))
3422 (call-interactively func)
3424 (set-window-configuration owin)
3425 (set-window-point (get-buffer-window (current-buffer)) (point))))
3427 (defun gnus-article-summary-command-nosave ()
3428 "Execute the last keystroke in the summary buffer."
3431 (pop-to-buffer gnus-article-current-summary 'norecord)
3432 (setq func (lookup-key (current-local-map) (this-command-keys)))
3433 (call-interactively func)))
3435 (defun gnus-article-check-buffer ()
3436 "Beep if not in an article buffer."
3437 (unless (equal major-mode 'gnus-article-mode)
3438 (error "Command invoked outside of a Gnus article buffer")))
3440 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3441 "Read a summary buffer key sequence and execute it from the article buffer."
3443 (gnus-article-check-buffer)
3445 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3446 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3447 "=" "^" "\M-^" "|"))
3453 '("n" "Gn" "p" "Gp"))
3456 (set-buffer gnus-article-current-summary)
3457 (let (gnus-pick-mode)
3458 (push (or key last-command-event) unread-command-events)
3459 (setq keys (if gnus-xemacs
3460 (events-to-keys (read-key-sequence nil))
3461 (read-key-sequence nil)))))
3465 (if (or (member keys nosaves)
3466 (member keys nosave-but-article)
3467 (member keys nosave-in-article))
3469 (save-window-excursion
3470 (pop-to-buffer gnus-article-current-summary 'norecord)
3471 ;; We disable the pick minor mode commands.
3472 (let (gnus-pick-mode)
3473 (setq func (lookup-key (current-local-map) keys))))
3476 (unless (member keys nosave-in-article)
3477 (set-buffer gnus-article-current-summary))
3478 (call-interactively func)
3479 (setq new-sum-point (point)))
3480 (when (member keys nosave-but-article)
3481 (pop-to-buffer gnus-article-buffer 'norecord)))
3482 ;; These commands should restore window configuration.
3483 (let ((obuf (current-buffer))
3484 (owin (current-window-configuration))
3486 (summary gnus-article-current-summary)
3487 func in-buffer selected)
3488 (if not-restore-window
3489 (pop-to-buffer summary 'norecord)
3490 (switch-to-buffer summary 'norecord))
3491 (setq in-buffer (current-buffer))
3492 ;; We disable the pick minor mode commands.
3493 (if (setq func (let (gnus-pick-mode)
3494 (lookup-key (current-local-map) keys)))
3496 (call-interactively func)
3497 (setq new-sum-point (point)))
3499 (when (eq in-buffer (current-buffer))
3500 (setq selected (gnus-summary-select-article))
3502 (unless not-restore-window
3503 (set-window-configuration owin))
3504 (when (eq selected 'old)
3506 (set-window-start (get-buffer-window (current-buffer))
3508 (set-window-point (get-buffer-window (current-buffer))
3510 (let ((win (get-buffer-window gnus-article-current-summary)))
3512 (set-window-point win new-sum-point))))))))
3514 (defun gnus-article-hide (&optional arg force)
3515 "Hide all the gruft in the current article.
3516 This means that PGP stuff, signatures, cited text and (some)
3517 headers will be hidden.
3518 If given a prefix, show the hidden text instead."
3519 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3520 (gnus-article-hide-headers arg)
3521 (gnus-article-hide-pgp arg)
3522 (gnus-article-hide-citation-maybe arg force)
3523 (gnus-article-hide-signature arg))
3525 (defun gnus-article-maybe-highlight ()
3526 "Do some article highlighting if article highlighting is requested."
3527 (when (gnus-visual-p 'article-highlight 'highlight)
3528 (gnus-article-highlight-some)))
3530 (defun gnus-check-group-server ()
3531 ;; Make sure the connection to the server is alive.
3532 (unless (gnus-server-opened
3533 (gnus-find-method-for-group gnus-newsgroup-name))
3534 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3535 (gnus-request-group gnus-newsgroup-name t)))
3537 (defun gnus-request-article-this-buffer (article group)
3538 "Get an article and insert it into this buffer."
3539 (let (do-update-line sparse-header)
3543 (gnus-kill-all-overlays)
3544 (setq group (or group gnus-newsgroup-name))
3546 ;; Using `gnus-request-article' directly will insert the article into
3547 ;; `nntp-server-buffer' - so we'll save some time by not having to
3548 ;; copy it from the server buffer into the article buffer.
3550 ;; We only request an article by message-id when we do not have the
3551 ;; headers for it, so we'll have to get those.
3552 (when (stringp article)
3553 (let ((gnus-override-method gnus-refer-article-method))
3554 (gnus-read-header article)))
3556 ;; If the article number is negative, that means that this article
3557 ;; doesn't belong in this newsgroup (possibly), so we find its
3558 ;; message-id and request it by id instead of number.
3559 (when (and (numberp article)
3561 (get-buffer gnus-summary-buffer)
3562 (gnus-buffer-exists-p gnus-summary-buffer))
3564 (set-buffer gnus-summary-buffer)
3565 (let ((header (gnus-summary-article-header article)))
3568 ((memq article gnus-newsgroup-sparse)
3569 ;; This is a sparse gap article.
3570 (setq do-update-line article)
3571 (setq article (mail-header-id header))
3572 (let ((gnus-override-method gnus-refer-article-method))
3573 (setq sparse-header (gnus-read-header article)))
3574 (setq gnus-newsgroup-sparse
3575 (delq article gnus-newsgroup-sparse)))
3577 ;; It's a real article.
3578 (setq article (mail-header-id header)))
3580 ;; It is an extracted pseudo-article.
3581 (setq article 'pseudo)
3582 (gnus-request-pseudo-article header))))
3584 (let ((method (gnus-find-method-for-group
3585 gnus-newsgroup-name)))
3586 (when (and (eq (car method) 'nneething)
3589 (file-name-as-directory
3590 (or (cadr (assq 'nneething-address method))
3592 (mail-header-subject header))))
3593 (when (file-directory-p dir)
3594 (setq article 'nneething)
3595 (gnus-group-enter-directory dir))))))))
3598 ;; Refuse to select canceled articles.
3599 ((and (numberp article)
3601 (get-buffer gnus-summary-buffer)
3602 (gnus-buffer-exists-p gnus-summary-buffer)
3603 (eq (cdr (save-excursion
3604 (set-buffer gnus-summary-buffer)
3605 (assq article gnus-newsgroup-reads)))
3606 gnus-canceled-mark))
3608 ;; We first check `gnus-original-article-buffer'.
3609 ((and (get-buffer gnus-original-article-buffer)
3612 (set-buffer gnus-original-article-buffer)
3613 (and (equal (car gnus-original-article) group)
3614 (eq (cdr gnus-original-article) article))))
3615 (insert-buffer-substring gnus-original-article-buffer)
3617 ;; Check the backlog.
3618 ((and gnus-keep-backlog
3619 (gnus-backlog-request-article group article (current-buffer)))
3621 ;; Check asynchronous pre-fetch.
3622 ((gnus-async-request-fetched-article group article (current-buffer))
3623 (gnus-async-prefetch-next group article gnus-summary-buffer)
3624 (when (and (numberp article) gnus-keep-backlog)
3625 (gnus-backlog-enter-article group article (current-buffer)))
3628 ((and gnus-use-cache
3630 (gnus-cache-request-article article group))
3632 ;; Get the article and put into the article buffer.
3633 ((or (stringp article) (numberp article))
3634 (let ((gnus-override-method
3635 (and (stringp article) gnus-refer-article-method))
3636 (buffer-read-only nil))
3638 (gnus-kill-all-overlays)
3639 (gnus-check-group-server)
3640 (when (gnus-request-article article group (current-buffer))
3641 (when (numberp article)
3642 (gnus-async-prefetch-next group article gnus-summary-buffer)
3643 (when gnus-keep-backlog
3644 (gnus-backlog-enter-article
3645 group article (current-buffer))))
3650 ;; Associate this article with the current summary buffer.
3651 (setq gnus-article-current-summary gnus-summary-buffer)
3653 ;; Take the article from the original article buffer
3654 ;; and place it in the buffer it's supposed to be in.
3655 (when (and (get-buffer gnus-article-buffer)
3656 (equal (buffer-name (current-buffer))
3657 (buffer-name (get-buffer gnus-article-buffer))))
3659 (if (get-buffer gnus-original-article-buffer)
3660 (set-buffer gnus-original-article-buffer)
3661 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3662 (buffer-disable-undo)
3663 (setq major-mode 'gnus-original-article-mode)
3664 (setq buffer-read-only t))
3665 (let (buffer-read-only)
3667 (insert-buffer-substring gnus-article-buffer))
3668 (setq gnus-original-article (cons group article)))
3671 (run-hooks 'gnus-article-decode-hook)
3672 ;; Mark article as decoded or not.
3673 (setq gnus-article-decoded-p gnus-article-decode-hook))
3675 ;; Update sparse articles.
3676 (when (and do-update-line
3677 (or (numberp article)
3679 (let ((buf (current-buffer)))
3680 (set-buffer gnus-summary-buffer)
3681 (gnus-summary-update-article do-update-line sparse-header)
3682 (gnus-summary-goto-subject do-update-line nil t)
3683 (set-window-point (get-buffer-window (current-buffer) t)
3685 (set-buffer buf))))))
3691 (defcustom gnus-article-edit-mode-hook nil
3692 "Hook run in article edit mode buffers."
3693 :group 'gnus-article-various
3696 (defvar gnus-article-edit-done-function nil)
3698 (defvar gnus-article-edit-mode-map nil)
3700 ;; Should we be using derived.el for this?
3701 (unless gnus-article-edit-mode-map
3702 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3703 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3705 (gnus-define-keys gnus-article-edit-mode-map
3706 "\C-c\C-c" gnus-article-edit-done
3707 "\C-c\C-k" gnus-article-edit-exit)
3709 (gnus-define-keys (gnus-article-edit-wash-map
3710 "\C-c\C-w" gnus-article-edit-mode-map)
3711 "f" gnus-article-edit-full-stops))
3713 (defun gnus-article-edit-mode ()
3714 "Major mode for editing articles.
3715 This is an extended text-mode.
3717 \\{gnus-article-edit-mode-map}"
3719 (setq major-mode 'gnus-article-edit-mode)
3720 (setq mode-name "Article Edit")
3721 (use-local-map gnus-article-edit-mode-map)
3722 (make-local-variable 'gnus-article-edit-done-function)
3723 (make-local-variable 'gnus-prev-winconf)
3724 (setq buffer-read-only nil)
3725 (buffer-enable-undo)
3727 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3729 (defun gnus-article-edit (&optional force)
3730 "Edit the current article.
3731 This will have permanent effect only in mail groups.
3732 If FORCE is non-nil, allow editing of articles even in read-only
3735 (when (and (not force)
3736 (gnus-group-read-only-p))
3737 (error "The current newsgroup does not support article editing"))
3738 (gnus-article-date-original)
3739 (gnus-article-edit-article
3741 `(lambda (no-highlight)
3743 (gnus-summary-edit-article-done
3744 ,(or (mail-header-references gnus-current-headers) "")
3745 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3747 (defun gnus-article-edit-article (start-func exit-func)
3748 "Start editing the contents of the current article buffer."
3749 (let ((winconf (current-window-configuration)))
3750 (set-buffer gnus-article-buffer)
3751 (gnus-article-edit-mode)
3752 (funcall start-func)
3753 ;;(gnus-article-delete-text-of-type 'annotation)
3754 ;;(gnus-set-text-properties (point-min) (point-max) nil)
3755 (gnus-configure-windows 'edit-article)
3756 (setq gnus-article-edit-done-function exit-func)
3757 (setq gnus-prev-winconf winconf)
3758 (gnus-message 6 "C-c C-c to end edits")))
3760 (defun gnus-article-edit-done (&optional arg)
3761 "Update the article edits and exit."
3766 (when (article-goto-body)
3767 (let ((lines (count-lines (point) (point-max)))
3768 (length (- (point-max) (point)))
3769 (case-fold-search t)
3770 (body (copy-marker (point))))
3771 (goto-char (point-min))
3772 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3773 (delete-region (match-beginning 1) (match-end 1))
3774 (insert (number-to-string length)))
3775 (goto-char (point-min))
3776 (when (re-search-forward
3777 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3778 (delete-region (match-beginning 1) (match-end 1))
3779 (insert (number-to-string length)))
3780 (goto-char (point-min))
3781 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3782 (delete-region (match-beginning 1) (match-end 1))
3783 (insert (number-to-string lines)))))))
3784 (let ((func gnus-article-edit-done-function)
3785 (buf (current-buffer))
3786 (start (window-start)))
3787 (gnus-article-edit-exit)
3790 (let ((buffer-read-only nil))
3792 ;; The cache and backlog have to be flushed somewhat.
3793 (when gnus-keep-backlog
3794 (gnus-backlog-remove-article
3795 (car gnus-article-current) (cdr gnus-article-current)))
3796 ;; Flush original article as well.
3798 (when (get-buffer gnus-original-article-buffer)
3799 (set-buffer gnus-original-article-buffer)
3800 (setq gnus-original-article nil)))
3801 (when gnus-use-cache
3802 (gnus-cache-update-article
3803 (car gnus-article-current) (cdr gnus-article-current))))
3805 (set-window-start (get-buffer-window buf) start)
3806 (set-window-point (get-buffer-window buf) (point))))
3808 (defun gnus-article-edit-exit ()
3809 "Exit the article editing without updating."
3811 ;; We remove all text props from the article buffer.
3812 (let ((buf (format "%s" (buffer-string)))
3813 (curbuf (current-buffer))
3815 (window-start (window-start)))
3818 (let ((winconf gnus-prev-winconf))
3820 (set-window-configuration winconf)
3821 ;; Tippy-toe some to make sure that point remains where it was.
3822 (save-current-buffer
3824 (set-window-start (get-buffer-window (current-buffer)) window-start)
3827 (defun gnus-article-edit-full-stops ()
3828 "Interactively repair spacing at end of sentences."
3831 (goto-char (point-min))
3832 (search-forward-regexp "^$" nil t)
3833 (let ((case-fold-search nil))
3834 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3837 ;;; Article highlights
3840 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3842 ;;; Internal Variables:
3844 (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\\)"
3845 "Regular expression that matches URLs."
3846 :group 'gnus-article-buttons
3849 (defcustom gnus-button-alist
3850 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3851 0 t gnus-button-message-id 2)
3852 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3853 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3855 gnus-button-fetch-group 4)
3856 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3857 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3858 t gnus-button-message-id 3)
3859 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3860 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3861 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3862 ;; This is how URLs _should_ be embedded in text...
3863 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3865 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3866 "*Alist of regexps matching buttons in article bodies.
3868 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3869 REGEXP: is the string matching text around the button,
3870 BUTTON: is the number of the regexp grouping actually matching the button,
3871 FORM: is a lisp expression which must eval to true for the button to
3873 CALLBACK: is the function to call when the user push this button, and each
3874 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3876 CALLBACK can also be a variable, in that case the value of that
3877 variable it the real callback function."
3878 :group 'gnus-article-buttons
3879 :type '(repeat (list regexp
3880 (integer :tag "Button")
3882 (function :tag "Callback")
3885 (integer :tag "Regexp group")))))
3887 (defcustom gnus-header-button-alist
3888 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3889 0 t gnus-button-message-id 0)
3890 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3891 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3892 0 t gnus-button-mailto 0)
3893 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3894 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3895 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3896 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3897 gnus-button-message-id 3))
3898 "*Alist of headers and regexps to match buttons in article heads.
3900 This alist is very similar to `gnus-button-alist', except that each
3901 alist has an additional HEADER element first in each entry:
3903 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3905 HEADER is a regexp to match a header. For a fuller explanation, see
3906 `gnus-button-alist'."
3907 :group 'gnus-article-buttons
3908 :group 'gnus-article-headers
3909 :type '(repeat (list (regexp :tag "Header")
3911 (integer :tag "Button")
3913 (function :tag "Callback")
3916 (integer :tag "Regexp group")))))
3918 (defvar gnus-button-regexp nil)
3919 (defvar gnus-button-marker-list nil)
3920 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3922 (defvar gnus-button-last nil)
3923 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3927 (defun gnus-article-push-button (event)
3928 "Check text under the mouse pointer for a callback function.
3929 If the text under the mouse pointer has a `gnus-callback' property,
3930 call it with the value of the `gnus-data' text property."
3932 (set-buffer (window-buffer (posn-window (event-start event))))
3933 (let* ((pos (posn-point (event-start event)))
3934 (data (get-text-property pos 'gnus-data))
3935 (fun (get-text-property pos 'gnus-callback)))
3938 (funcall fun data))))
3940 (defun gnus-article-press-button ()
3941 "Check text at point for a callback function.
3942 If the text at point has a `gnus-callback' property,
3943 call it with the value of the `gnus-data' text property."
3945 (let* ((data (get-text-property (point) 'gnus-data))
3946 (fun (get-text-property (point) 'gnus-callback)))
3948 (funcall fun data))))
3950 (defun gnus-article-highlight (&optional force)
3951 "Highlight current article.
3952 This function calls `gnus-article-highlight-headers',
3953 `gnus-article-highlight-citation',
3954 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3955 do the highlighting. See the documentation for those functions."
3956 (interactive (list 'force))
3957 (gnus-article-highlight-headers)
3958 (gnus-article-highlight-citation force)
3959 (gnus-article-highlight-signature)
3960 (gnus-article-add-buttons force)
3961 (gnus-article-add-buttons-to-head))
3963 (defun gnus-article-highlight-some (&optional force)
3964 "Highlight current article.
3965 This function calls `gnus-article-highlight-headers',
3966 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3967 do the highlighting. See the documentation for those functions."
3968 (interactive (list 'force))
3969 (gnus-article-highlight-headers)
3970 (gnus-article-highlight-signature)
3971 (gnus-article-add-buttons))
3973 (defun gnus-article-highlight-headers ()
3974 "Highlight article headers as specified by `gnus-header-face-alist'."
3977 (set-buffer gnus-article-buffer)
3979 (let ((alist gnus-header-face-alist)
3980 (buffer-read-only nil)
3981 (case-fold-search t)
3982 (inhibit-point-motion-hooks t)
3983 entry regexp header-face field-face from hpoints fpoints)
3984 (article-narrow-to-head)
3985 (while (setq entry (pop alist))
3986 (goto-char (point-min))
3987 (setq regexp (concat "^\\("
3988 (if (string-equal "" (nth 0 entry))
3992 header-face (nth 1 entry)
3993 field-face (nth 2 entry))
3994 (while (and (re-search-forward regexp nil t)
3998 (unless (search-forward ":" nil t)
4000 (when (and header-face
4001 (not (memq (point) hpoints)))
4002 (push (point) hpoints)
4003 (gnus-put-text-property from (point) 'face header-face))
4004 (when (and field-face
4005 (not (memq (setq from (point)) fpoints)))
4007 (if (re-search-forward "^[^ \t]" nil t)
4009 (goto-char (point-max)))
4010 (gnus-put-text-property from (point) 'face field-face))))))))
4012 (defun gnus-article-highlight-signature ()
4013 "Highlight the signature in an article.
4014 It does this by highlighting everything after
4015 `gnus-signature-separator' using `gnus-signature-face'."
4018 (set-buffer gnus-article-buffer)
4019 (let ((buffer-read-only nil)
4020 (inhibit-point-motion-hooks t))
4022 (when (and gnus-signature-face
4023 (gnus-article-narrow-to-signature))
4024 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4025 'face gnus-signature-face)
4027 (gnus-article-search-signature)
4028 (let ((start (match-beginning 0))
4029 (end (set-marker (make-marker) (1+ (match-end 0)))))
4030 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4033 (defun gnus-button-in-region-p (b e prop)
4034 "Say whether PROP exists in the region."
4035 (text-property-not-all b e prop nil))
4037 (defun gnus-article-add-buttons (&optional force)
4038 "Find external references in the article and make buttons of them.
4039 \"External references\" are things like Message-IDs and URLs, as
4040 specified by `gnus-button-alist'."
4041 (interactive (list 'force))
4043 (set-buffer gnus-article-buffer)
4044 (let ((buffer-read-only nil)
4045 (inhibit-point-motion-hooks t)
4046 (case-fold-search t)
4047 (alist gnus-button-alist)
4049 ;; Remove all old markers.
4051 (while (setq marker (pop gnus-button-marker-list))
4053 (when (setq entry (gnus-button-entry))
4054 (put-text-property (match-beginning (nth 1 entry))
4055 (match-end (nth 1 entry))
4056 'gnus-callback nil))
4057 (set-marker marker nil)))
4058 ;; We skip the headers.
4061 (while (setq entry (pop alist))
4062 (setq regexp (car entry))
4064 (while (re-search-forward regexp nil t)
4065 (let* ((start (and entry (match-beginning (nth 1 entry))))
4066 (end (and entry (match-end (nth 1 entry))))
4067 (from (match-beginning 0)))
4068 (when (and (or (eq t (nth 2 entry))
4069 (eval (nth 2 entry)))
4070 (not (gnus-button-in-region-p
4071 start end 'gnus-callback)))
4072 ;; That optional form returned non-nil, so we add the
4074 (gnus-article-add-button
4075 start end 'gnus-button-push
4076 (car (push (set-marker (make-marker) from)
4077 gnus-button-marker-list))))))))))
4079 ;; Add buttons to the head of an article.
4080 (defun gnus-article-add-buttons-to-head ()
4081 "Add buttons to the head of the article."
4084 (set-buffer gnus-article-buffer)
4086 (let ((buffer-read-only nil)
4087 (inhibit-point-motion-hooks t)
4088 (case-fold-search t)
4089 (alist gnus-header-button-alist)
4091 (article-narrow-to-head)
4093 ;; Each alist entry.
4094 (setq entry (car alist)
4096 (goto-char (point-min))
4097 (while (re-search-forward (car entry) nil t)
4098 ;; Each header matching the entry.
4099 (setq beg (match-beginning 0))
4100 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4101 (match-beginning 0))
4104 (while (re-search-forward (nth 1 entry) end t)
4105 ;; Each match within a header.
4106 (let* ((entry (cdr entry))
4107 (start (match-beginning (nth 1 entry)))
4108 (end (match-end (nth 1 entry)))
4109 (form (nth 2 entry)))
4110 (goto-char (match-end 0))
4112 (gnus-article-add-button
4113 start end (nth 3 entry)
4114 (buffer-substring (match-beginning (nth 4 entry))
4115 (match-end (nth 4 entry)))))))
4116 (goto-char end)))))))
4118 ;;; External functions:
4120 (defun gnus-article-add-button (from to fun &optional data)
4121 "Create a button between FROM and TO with callback FUN and data DATA."
4122 (when gnus-article-button-face
4123 (gnus-overlay-put (gnus-make-overlay from to)
4124 'face gnus-article-button-face))
4125 (gnus-add-text-properties
4127 (nconc (and gnus-article-mouse-face
4128 (list gnus-mouse-face-prop gnus-article-mouse-face))
4129 (list 'gnus-callback fun)
4130 (and data (list 'gnus-data data))))
4131 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4132 :button-keymap gnus-widget-button-keymap))
4134 ;;; Internal functions:
4136 (defun gnus-article-set-globals ()
4138 (set-buffer gnus-summary-buffer)
4139 (gnus-set-global-variables)))
4141 (defun gnus-signature-toggle (end)
4143 (set-buffer gnus-article-buffer)
4144 (let ((buffer-read-only nil)
4145 (inhibit-point-motion-hooks t))
4146 (if (get-text-property end 'invisible)
4147 (gnus-article-unhide-text end (point-max))
4148 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4150 (defun gnus-button-entry ()
4151 ;; Return the first entry in `gnus-button-alist' matching this place.
4152 (let ((alist gnus-button-alist)
4155 (setq entry (pop alist))
4156 (if (looking-at (car entry))
4161 (defun gnus-button-push (marker)
4162 ;; Push button starting at MARKER.
4165 (let* ((entry (gnus-button-entry))
4166 (inhibit-point-motion-hooks t)
4168 (args (mapcar (lambda (group)
4169 (let ((string (match-string group)))
4170 (gnus-set-text-properties
4171 0 (length string) nil string)
4178 (fboundp (symbol-value fun)))
4179 (apply (symbol-value fun) args))
4181 (gnus-message 1 "You must define `%S' to use this button"
4182 (cons fun args)))))))
4184 (defun gnus-button-message-id (message-id)
4187 (set-buffer gnus-summary-buffer)
4188 (gnus-summary-refer-article message-id)))
4190 (defun gnus-button-fetch-group (address)
4191 "Fetch GROUP specified by ADDRESS."
4192 (if (not (string-match "[:/]" address))
4193 ;; This is just a simple group url.
4194 (gnus-group-read-ephemeral-group address gnus-select-method)
4195 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4197 (error "Can't parse %s" address)
4198 (gnus-group-read-ephemeral-group
4199 (match-string 4 address)
4200 `(nntp ,(match-string 1 address)
4201 (nntp-address ,(match-string 1 address))
4202 (nntp-port-number ,(if (match-end 3)
4203 (match-string 3 address)
4206 (defun gnus-url-parse-query-string (query &optional downcase)
4207 (let (retval pairs cur key val)
4208 (setq pairs (split-string query "&"))
4210 (setq cur (car pairs)
4212 (if (not (string-match "=" cur))
4214 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4215 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4217 (setq key (downcase key)))
4218 (setq cur (assoc key retval))
4220 (setcdr cur (cons val (cdr cur)))
4221 (setq retval (cons (list key val) retval)))))
4224 (defun gnus-url-unhex (x)
4231 (defun gnus-url-unhex-string (str &optional allow-newlines)
4232 "Remove %XXX embedded spaces, etc in a url.
4233 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4234 decoding of carriage returns and line feeds in the string, which is normally
4235 forbidden in URL encoding."
4236 (setq str (or str ""))
4238 (case-fold-search t))
4239 (while (string-match "%[0-9a-f][0-9a-f]" str)
4240 (let* ((start (match-beginning 0))
4241 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4243 (gnus-url-unhex (elt str (+ start 2))))))
4245 tmp (substring str 0 start)
4248 (char-to-string code))
4249 ((or (= code ?\n) (= code ?\r))
4251 (t (char-to-string code))))
4252 str (substring str (match-end 0)))))
4253 (setq tmp (concat tmp str))
4256 (defun gnus-url-mailto (url)
4257 ;; Send mail to someone
4258 (when (string-match "mailto:/*\\(.*\\)" url)
4259 (setq url (substring url (match-beginning 1) nil)))
4260 (let (to args subject func)
4261 (if (string-match (regexp-quote "?") url)
4262 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4263 args (gnus-url-parse-query-string
4264 (substring url (match-end 0) nil) t))
4265 (setq to (gnus-url-unhex-string url)))
4266 (setq args (cons (list "to" to) args)
4267 subject (cdr-safe (assoc "subject" args)))
4270 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4273 (message-position-on-field (caar args)))
4274 (insert (mapconcat 'identity (cdar args) ", "))
4275 (setq args (cdr args)))
4278 (message-goto-subject))))
4280 (defun gnus-button-mailto (address)
4282 (set-buffer (gnus-copy-article-buffer))
4283 (message-reply address))
4285 (defun gnus-button-reply (address)
4286 ;; Reply to ADDRESS.
4287 (message-reply address))
4289 (defun gnus-button-url (address)
4291 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4292 (if (listp browse-url-browser-function)
4293 (browse-url address)
4294 (funcall browse-url-browser-function address)))
4296 (defun gnus-button-embedded-url (address)
4298 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4299 (if (listp browse-url-browser-function)
4300 (browse-url (gnus-strip-whitespace address))
4301 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4303 ;;; Next/prev buttons in the article buffer.
4305 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4306 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4308 (defvar gnus-prev-page-map nil)
4309 (unless gnus-prev-page-map
4310 (setq gnus-prev-page-map (make-sparse-keymap))
4311 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4312 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4314 (defun gnus-insert-prev-page-button ()
4315 (let ((buffer-read-only nil))
4317 gnus-prev-page-line-format nil
4318 `(gnus-prev t local-map ,gnus-prev-page-map
4319 gnus-callback gnus-article-button-prev-page
4320 article-type annotation))))
4322 (defvar gnus-next-page-map nil)
4323 (unless gnus-next-page-map
4324 (setq gnus-next-page-map (make-keymap))
4325 (suppress-keymap gnus-prev-page-map)
4326 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4327 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4329 (defun gnus-button-next-page ()
4330 "Go to the next page."
4332 (let ((win (selected-window)))
4333 (select-window (get-buffer-window gnus-article-buffer t))
4334 (gnus-article-next-page)
4335 (select-window win)))
4337 (defun gnus-button-prev-page ()
4338 "Go to the prev page."
4340 (let ((win (selected-window)))
4341 (select-window (get-buffer-window gnus-article-buffer t))
4342 (gnus-article-prev-page)
4343 (select-window win)))
4345 (defun gnus-insert-next-page-button ()
4346 (let ((buffer-read-only nil))
4347 (gnus-eval-format gnus-next-page-line-format nil
4349 t local-map ,gnus-next-page-map
4350 gnus-callback gnus-article-button-next-page
4351 article-type annotation))))
4353 (defun gnus-article-button-next-page (arg)
4354 "Go to the next page."
4356 (let ((win (selected-window)))
4357 (select-window (get-buffer-window gnus-article-buffer t))
4358 (gnus-article-next-page)
4359 (select-window win)))
4361 (defun gnus-article-button-prev-page (arg)
4362 "Go to the prev page."
4364 (let ((win (selected-window)))
4365 (select-window (get-buffer-window gnus-article-buffer t))
4366 (gnus-article-prev-page)
4367 (select-window win)))
4369 (defvar gnus-decode-header-methods
4370 '(mail-decode-encoded-word-region)
4371 "List of methods used to decode headers.
4373 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4374 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4375 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4376 whose names match REGEXP.
4379 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4380 mail-decode-encoded-word-region
4381 (\"chinese\" . rfc1843-decode-region))
4384 (defvar gnus-decode-header-methods-cache nil)
4386 (defun gnus-multi-decode-header (start end)
4387 "Apply the functions from `gnus-encoded-word-methods' that match."
4388 (unless (and gnus-decode-header-methods-cache
4389 (eq gnus-newsgroup-name
4390 (car gnus-decode-header-methods-cache)))
4391 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4394 (nconc gnus-decode-header-methods-cache (list x))
4395 (if (and gnus-newsgroup-name
4396 (string-match (car x) gnus-newsgroup-name))
4397 (nconc gnus-decode-header-methods-cache
4399 gnus-decode-header-methods))
4400 (let ((xlist gnus-decode-header-methods-cache))
4403 (narrow-to-region start end)
4405 (funcall (pop xlist) (point-min) (point-max))))))
4408 ;;; Treatment top-level handling.
4411 (defun gnus-treat-article (condition &optional part-number total-parts type)
4412 (let ((length (- (point-max) (point-min)))
4413 (alist gnus-treatment-function-alist)
4414 (article-goto-body-goes-to-point-min-p t)
4418 (let ((list gnus-article-treat-types))
4420 (when (string-match (pop list) type)
4421 (throw 'found t)))))))
4422 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4424 (gnus-run-hooks 'gnus-part-display-hook)
4425 (while (setq elem (pop alist))
4426 (setq val (symbol-value (car elem)))
4427 (when (and (or (consp val)
4429 (gnus-treat-predicate val)
4430 (or (not (get (car elem) 'highlight))
4433 (funcall (cadr elem)))))))
4435 ;; Dynamic variables.
4436 (defvar part-number)
4437 (defvar total-parts)
4441 (defun gnus-treat-predicate (val)
4452 (eq part-number total-parts))
4456 (stringp (car val)))
4457 (apply 'gnus-or (mapcar `(lambda (s)
4458 (string-match s ,(or gnus-newsgroup-name "")))
4461 (let ((pred (pop val)))
4464 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4466 (apply 'gnus-and (mapcar 'gnus-tread-predicate val)))
4468 (not (gnus-treat-predicate val)))
4470 (equal (cadr val) type))
4472 (error "%S is not a valid predicate" pred)))))
4474 (error "%S is not a valid value" val))))
4480 (run-hooks 'gnus-art-load-hook)
4482 ;;; gnus-art.el ends here