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 (mail-header-date (save-excursion
1795 (set-buffer gnus-summary-buffer)
1796 gnus-current-headers))
1797 (message-fetch-field "date")
1799 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1802 ((not gnus-article-date-lapsed-new-header)
1808 (date (if (vectorp header) (mail-header-date header)
1810 (inhibit-point-motion-hooks t)
1813 (when (and date (not (string= date "")))
1816 (article-narrow-to-head)
1817 (when (re-search-forward tdate-regexp nil t)
1818 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1819 eface (get-text-property (1- (gnus-point-at-eol))
1822 (goto-char (point-min))
1823 (let ((buffer-read-only nil))
1824 ;; Delete any old Date headers.
1825 (while (re-search-forward date-regexp nil t)
1827 (delete-region (progn (beginning-of-line) (point))
1828 (progn (end-of-line) (point)))
1829 (delete-region (progn (beginning-of-line) (point))
1830 (progn (forward-line 1) (point))))
1832 (if (re-search-forward tdate-regexp nil t)
1834 (insert (article-make-date-line date type))
1840 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1841 (put-text-property (match-beginning 1) (1+ (match-end 1))
1843 (put-text-property (match-beginning 2) (match-end 2)
1846 (defun article-make-date-line (date type)
1847 "Return a DATE line of TYPE."
1848 (let ((time (condition-case ()
1852 ;; Convert to the local timezone. We have to slap a
1853 ;; `condition-case' round the calls to the timezone
1854 ;; functions since they aren't particularly resistant to
1857 (let ((tz (car (current-time-zone))))
1858 (format "Date: %s %s%04d" (current-time-string time)
1859 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1860 ;; Convert to Universal Time.
1863 (current-time-string
1864 (let* ((e (parse-time-string date))
1865 (tm (apply 'encode-time e))
1867 (ls (- (cadr tm) (car (current-time-zone)))))
1868 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1869 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1872 ;; Get the original date from the article.
1873 ((eq type 'original)
1874 (concat "Date: " (if (string-match "\n+$" date)
1875 (substring date 0 (match-beginning 0))
1877 ;; Let the user define the format.
1879 (if (gnus-functionp gnus-article-time-format)
1880 (funcall gnus-article-time-format time)
1883 (format-time-string gnus-article-time-format time))))
1888 (format-time-string "%Y%m%dT%H%M%S" time)))
1889 ;; Do an X-Sent lapsed format.
1891 ;; If the date is seriously mangled, the timezone functions are
1892 ;; liable to bug out, so we ignore all errors.
1893 (let* ((now (current-time))
1894 (real-time (subtract-time now time))
1895 (real-sec (and real-time
1896 (+ (* (float (car real-time)) 65536)
1898 (sec (and real-time (abs real-sec)))
1908 ;; This is a bit convoluted, but basically we go
1909 ;; through the time units for years, weeks, etc,
1910 ;; and divide things to see whether that results
1911 ;; in positive answers.
1914 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1915 ;; The (remaining) seconds are too few to
1916 ;; be divided into this time unit.
1918 ;; It's big enough, so we output it.
1919 (setq sec (- sec (* num (cdr unit))))
1921 (concat (if prev ", " "") (int-to-string
1923 " " (symbol-name (car unit))
1924 (if (> num 1) "s" ""))
1926 article-time-units "")
1927 ;; If dates are odd, then it might appear like the
1928 ;; article was sent in the future.
1931 " in the future"))))))
1933 (error "Unknown conversion type: %s" type)))))
1935 (defun article-date-local (&optional highlight)
1936 "Convert the current article date to the local timezone."
1937 (interactive (list t))
1938 (article-date-ut 'local highlight))
1940 (defun article-date-original (&optional highlight)
1941 "Convert the current article date to what it was originally.
1942 This is only useful if you have used some other date conversion
1943 function and want to see what the date was before converting."
1944 (interactive (list t))
1945 (article-date-ut 'original highlight))
1947 (defun article-date-lapsed (&optional highlight)
1948 "Convert the current article date to time lapsed since it was sent."
1949 (interactive (list t))
1950 (article-date-ut 'lapsed highlight))
1952 (defun article-update-date-lapsed ()
1953 "Function to be run from a timer to update the lapsed time line."
1954 (let (deactivate-mark)
1959 (set-buffer (window-buffer w))
1960 (when (eq major-mode 'gnus-article-mode)
1961 (goto-char (point-min))
1962 (when (re-search-forward "^X-Sent:" nil t)
1963 (article-date-lapsed t))))
1966 (defun gnus-start-date-timer (&optional n)
1967 "Start a timer to update the X-Sent header in the article buffers.
1968 The numerical prefix says how frequently (in seconds) the function
1973 (gnus-stop-date-timer)
1974 (setq article-lapsed-timer
1975 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1977 (defun gnus-stop-date-timer ()
1978 "Stop the X-Sent timer."
1980 (when article-lapsed-timer
1981 (nnheader-cancel-timer article-lapsed-timer)
1982 (setq article-lapsed-timer nil)))
1984 (defun article-date-user (&optional highlight)
1985 "Convert the current article date to the user-defined format.
1986 This format is defined by the `gnus-article-time-format' variable."
1987 (interactive (list t))
1988 (article-date-ut 'user highlight))
1990 (defun article-date-iso8601 (&optional highlight)
1991 "Convert the current article date to ISO8601."
1992 (interactive (list t))
1993 (article-date-ut 'iso8601 highlight))
1995 (defun article-show-all ()
1996 "Show all hidden text in the article buffer."
1999 (let ((buffer-read-only nil))
2000 (gnus-article-unhide-text (point-min) (point-max)))))
2002 (defun article-emphasize (&optional arg)
2003 "Emphasize text according to `gnus-emphasis-alist'."
2004 (interactive (gnus-article-hidden-arg))
2005 (unless (gnus-article-check-hidden-text 'emphasis arg)
2007 (let ((alist (or gnus-article-emphasis-alist gnus-emphasis-alist))
2008 (buffer-read-only nil)
2009 (props (append '(article-type emphasis)
2010 gnus-hidden-properties))
2011 regexp elem beg invisible visible face)
2014 (while (setq elem (pop alist))
2016 (setq regexp (car elem)
2017 invisible (nth 1 elem)
2018 visible (nth 2 elem)
2020 (while (re-search-forward regexp nil t)
2021 (when (and (match-beginning visible) (match-beginning invisible))
2022 (gnus-article-hide-text
2023 (match-beginning invisible) (match-end invisible) props)
2024 (gnus-article-unhide-text-type
2025 (match-beginning visible) (match-end visible) 'emphasis)
2026 (gnus-put-text-property-excluding-newlines
2027 (match-beginning visible) (match-end visible) 'face face)
2028 (goto-char (match-end invisible)))))))))
2030 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2031 "Setup newsgroup emphasis alist."
2032 (unless gnus-article-emphasis-alist
2033 (let ((name (and gnus-newsgroup-name
2034 (gnus-group-real-name gnus-newsgroup-name))))
2035 (make-local-variable 'gnus-article-emphasis-alist)
2036 (setq gnus-article-emphasis-alist
2038 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2039 (while (setq elem (pop alist))
2040 (when (and name (string-match (car elem) name))
2042 highlight (copy-list (cdr elem)))))
2044 (copy-list highlight-words)
2045 (if gnus-newsgroup-name
2046 (copy-list (gnus-group-find-parameter
2047 gnus-newsgroup-name 'highlight-words t)))
2048 gnus-emphasis-alist)))))
2050 (defvar gnus-summary-article-menu)
2051 (defvar gnus-summary-post-menu)
2053 ;;; Saving functions.
2055 (defun gnus-article-save (save-buffer file &optional num)
2056 "Save the currently selected article."
2057 (unless gnus-save-all-headers
2058 ;; Remove headers according to `gnus-saved-headers'.
2059 (let ((gnus-visible-headers
2060 (or gnus-saved-headers gnus-visible-headers))
2061 (gnus-article-buffer save-buffer))
2063 (set-buffer save-buffer)
2064 (article-hide-headers 1 t))))
2065 (save-window-excursion
2066 (if (not gnus-default-article-saver)
2067 (error "No default saver is defined")
2068 ;; !!! Magic! The saving functions all save
2069 ;; `gnus-save-article-buffer' (or so they think), but we
2070 ;; bind that variable to our save-buffer.
2071 (set-buffer gnus-article-buffer)
2072 (let* ((gnus-save-article-buffer save-buffer)
2075 ((not gnus-prompt-before-saving) 'default)
2076 ((eq gnus-prompt-before-saving 'always) nil)
2078 (gnus-number-of-articles-to-be-saved
2079 (when (eq gnus-prompt-before-saving t)
2081 (set-buffer gnus-article-current-summary)
2082 (funcall gnus-default-article-saver filename)))))
2084 (defun gnus-read-save-file-name (prompt &optional filename
2085 function group headers variable)
2087 (funcall function group headers (symbol-value variable)))
2092 ((eq filename 'default)
2098 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2101 (if (and gnus-number-of-articles-to-be-saved
2102 (> gnus-number-of-articles-to-be-saved 1))
2103 (format "these %d articles"
2104 gnus-number-of-articles-to-be-saved)
2107 ;; Let the split methods have their say.
2109 ;; No split name was found.
2112 (concat prompt " (default "
2113 (file-name-nondirectory default-name) ") ")
2114 (file-name-directory default-name)
2116 ;; A single group name is returned.
2117 ((stringp split-name)
2119 (funcall function split-name headers
2120 (symbol-value variable)))
2122 (concat prompt " (default "
2123 (file-name-nondirectory default-name) ") ")
2124 (file-name-directory default-name)
2126 ;; A single split name was found
2127 ((= 1 (length split-name))
2128 (let* ((name (expand-file-name
2129 (car split-name) gnus-article-save-directory))
2130 (dir (cond ((file-directory-p name)
2131 (file-name-as-directory name))
2132 ((file-exists-p name) name)
2133 (t gnus-article-save-directory))))
2135 (concat prompt " (default " name ") ")
2137 ;; A list of splits was found.
2139 (setq split-name (nreverse split-name))
2141 (let ((file-name-history
2142 (nconc split-name file-name-history)))
2146 (concat prompt " (`M-p' for defaults) ")
2147 gnus-article-save-directory
2149 gnus-article-save-directory)))
2150 (car (push result file-name-history)))))))
2151 ;; Create the directory.
2152 (gnus-make-directory (file-name-directory file))
2153 ;; If we have read a directory, we append the default file name.
2154 (when (file-directory-p file)
2155 (setq file (concat (file-name-as-directory file)
2156 (file-name-nondirectory default-name))))
2157 ;; Possibly translate some characters.
2158 (nnheader-translate-file-chars file)))))
2159 (gnus-make-directory (file-name-directory result))
2160 (set variable result)))
2162 (defun gnus-article-archive-name (group)
2163 "Return the first instance of an \"Archive-name\" in the current buffer."
2164 (let ((case-fold-search t))
2165 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2166 (nnheader-concat gnus-article-save-directory
2167 (match-string 1)))))
2169 (defun gnus-article-nndoc-name (group)
2170 "If GROUP is an nndoc group, return the name of the parent group."
2171 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2172 (gnus-group-get-parameter group 'save-article-group)))
2174 (defun gnus-summary-save-in-rmail (&optional filename)
2175 "Append this article to Rmail file.
2176 Optional argument FILENAME specifies file name.
2177 Directory to save to is default to `gnus-article-save-directory'."
2178 (setq filename (gnus-read-save-file-name
2179 "Save %s in rmail file:" filename
2180 gnus-rmail-save-name gnus-newsgroup-name
2181 gnus-current-headers 'gnus-newsgroup-last-rmail))
2182 (gnus-eval-in-buffer-window gnus-save-article-buffer
2186 (gnus-output-to-rmail filename))))
2189 (defun gnus-summary-save-in-mail (&optional filename)
2190 "Append this article to Unix mail file.
2191 Optional argument FILENAME specifies file name.
2192 Directory to save to is default to `gnus-article-save-directory'."
2193 (setq filename (gnus-read-save-file-name
2194 "Save %s in Unix mail file:" filename
2195 gnus-mail-save-name gnus-newsgroup-name
2196 gnus-current-headers 'gnus-newsgroup-last-mail))
2197 (gnus-eval-in-buffer-window gnus-save-article-buffer
2201 (if (and (file-readable-p filename)
2202 (mail-file-babyl-p filename))
2203 (rmail-output-to-rmail-file filename t)
2204 (gnus-output-to-mail filename)))))
2207 (defun gnus-summary-save-in-file (&optional filename overwrite)
2208 "Append this article to file.
2209 Optional argument FILENAME specifies file name.
2210 Directory to save to is default to `gnus-article-save-directory'."
2211 (setq filename (gnus-read-save-file-name
2212 "Save %s in file:" filename
2213 gnus-file-save-name gnus-newsgroup-name
2214 gnus-current-headers 'gnus-newsgroup-last-file))
2215 (gnus-eval-in-buffer-window gnus-save-article-buffer
2219 (when (and overwrite
2220 (file-exists-p filename))
2221 (delete-file filename))
2222 (gnus-output-to-file filename))))
2225 (defun gnus-summary-write-to-file (&optional filename)
2226 "Write this article to a file.
2227 Optional argument FILENAME specifies file name.
2228 The directory to save in defaults to `gnus-article-save-directory'."
2229 (gnus-summary-save-in-file nil t))
2231 (defun gnus-summary-save-body-in-file (&optional filename)
2232 "Append this article body to a file.
2233 Optional argument FILENAME specifies file name.
2234 The directory to save in defaults to `gnus-article-save-directory'."
2235 (setq filename (gnus-read-save-file-name
2236 "Save %s body in file:" filename
2237 gnus-file-save-name gnus-newsgroup-name
2238 gnus-current-headers 'gnus-newsgroup-last-file))
2239 (gnus-eval-in-buffer-window gnus-save-article-buffer
2243 (when (article-goto-body)
2244 (narrow-to-region (point) (point-max)))
2245 (gnus-output-to-file filename))))
2248 (defun gnus-summary-save-in-pipe (&optional command)
2249 "Pipe this article to subprocess."
2251 (cond ((and (eq command 'default)
2252 gnus-last-shell-command)
2253 gnus-last-shell-command)
2257 "Shell command on %s: "
2258 (if (and gnus-number-of-articles-to-be-saved
2259 (> gnus-number-of-articles-to-be-saved 1))
2260 (format "these %d articles"
2261 gnus-number-of-articles-to-be-saved)
2263 gnus-last-shell-command))))
2264 (when (string-equal command "")
2265 (setq command gnus-last-shell-command))
2266 (gnus-eval-in-buffer-window gnus-article-buffer
2269 (shell-command-on-region (point-min) (point-max) command nil)))
2270 (setq gnus-last-shell-command command))
2272 ;;; Article file names when saving.
2274 (defun gnus-capitalize-newsgroup (newsgroup)
2275 "Capitalize NEWSGROUP name."
2276 (when (not (zerop (length newsgroup)))
2277 (concat (char-to-string (upcase (aref newsgroup 0)))
2278 (substring newsgroup 1))))
2280 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2281 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2282 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2283 Otherwise, it is like ~/News/news/group/num."
2286 (concat (if (gnus-use-long-file-name 'not-save)
2287 (gnus-capitalize-newsgroup newsgroup)
2288 (gnus-newsgroup-directory-form newsgroup))
2289 "/" (int-to-string (mail-header-number headers)))
2290 gnus-article-save-directory)))
2292 (string-equal (file-name-directory default)
2293 (file-name-directory last-file))
2294 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2296 (or last-file default))))
2298 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2299 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2300 If variable `gnus-use-long-file-name' is non-nil, it is
2301 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2304 (concat (if (gnus-use-long-file-name 'not-save)
2306 (gnus-newsgroup-directory-form newsgroup))
2307 "/" (int-to-string (mail-header-number headers)))
2308 gnus-article-save-directory)))
2310 (string-equal (file-name-directory default)
2311 (file-name-directory last-file))
2312 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2314 (or last-file default))))
2316 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2317 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2318 If variable `gnus-use-long-file-name' is non-nil, it is
2319 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2322 (if (gnus-use-long-file-name 'not-save)
2323 (gnus-capitalize-newsgroup newsgroup)
2324 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2325 gnus-article-save-directory)))
2327 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2328 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2329 If variable `gnus-use-long-file-name' is non-nil, it is
2330 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2333 (if (gnus-use-long-file-name 'not-save)
2335 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2336 gnus-article-save-directory)))
2343 (setq afunc (car func)
2346 gfunc (intern (format "gnus-%s" func))))
2348 (if (not (fboundp afunc))
2350 `(lambda (&optional interactive &rest args)
2351 ,(documentation afunc t)
2352 (interactive (list t))
2354 (set-buffer gnus-article-buffer)
2356 (call-interactively ',afunc)
2357 (apply ',afunc args))))))))
2358 '(article-hide-headers
2359 article-hide-boring-headers
2360 article-treat-overstrike
2361 article-fill-long-lines
2362 article-capitalize-sentences
2364 article-display-x-face
2365 article-de-quoted-unreadable
2366 article-mime-decode-quoted-printable
2368 article-strip-banner
2371 article-hide-signature
2372 article-strip-headers-in-body
2373 article-remove-trailing-blank-lines
2374 article-strip-leading-blank-lines
2375 article-strip-multiple-blank-lines
2376 article-strip-leading-space
2377 article-strip-trailing-space
2378 article-strip-blank-lines
2379 article-strip-all-blank-lines
2381 article-date-iso8601
2382 article-date-original
2384 article-decode-mime-words
2385 article-decode-charset
2386 article-decode-encoded-words
2390 article-treat-dumbquotes
2391 article-normalize-headers
2392 (article-show-all . gnus-article-show-all-headers))))
2395 ;;; Gnus article mode
2398 (put 'gnus-article-mode 'mode-class 'special)
2400 (set-keymap-parent gnus-article-mode-map widget-keymap)
2402 (gnus-define-keys gnus-article-mode-map
2403 " " gnus-article-goto-next-page
2404 "\177" gnus-article-goto-prev-page
2405 [delete] gnus-article-goto-prev-page
2406 [backspace] gnus-article-goto-prev-page
2407 "\C-c^" gnus-article-refer-article
2408 "h" gnus-article-show-summary
2409 "s" gnus-article-show-summary
2410 "\C-c\C-m" gnus-article-mail
2411 "?" gnus-article-describe-briefly
2412 "e" gnus-article-edit
2413 "<" beginning-of-buffer
2415 "\C-c\C-i" gnus-info-find-node
2418 "\C-d" gnus-article-read-summary-keys
2419 "\M-*" gnus-article-read-summary-keys
2420 "\M-#" gnus-article-read-summary-keys
2421 "\M-^" gnus-article-read-summary-keys
2422 "\M-g" gnus-article-read-summary-keys)
2424 (substitute-key-definition
2425 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2427 (defun gnus-article-make-menu-bar ()
2428 (gnus-turn-off-edit-menu 'article)
2429 (unless (boundp 'gnus-article-article-menu)
2431 gnus-article-article-menu gnus-article-mode-map ""
2433 ["Scroll forwards" gnus-article-goto-next-page t]
2434 ["Scroll backwards" gnus-article-goto-prev-page t]
2435 ["Show summary" gnus-article-show-summary t]
2436 ["Fetch Message-ID at point" gnus-article-refer-article t]
2437 ["Mail to address at point" gnus-article-mail t]
2438 ["Send a bug report" gnus-bug t]))
2441 gnus-article-treatment-menu gnus-article-mode-map ""
2443 ["Hide headers" gnus-article-hide-headers t]
2444 ["Hide signature" gnus-article-hide-signature t]
2445 ["Hide citation" gnus-article-hide-citation t]
2446 ["Treat overstrike" gnus-article-treat-overstrike t]
2447 ["Remove carriage return" gnus-article-remove-cr t]
2448 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]))
2450 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2452 (when (boundp 'gnus-summary-post-menu)
2453 (define-key gnus-article-mode-map [menu-bar post]
2454 (cons "Post" gnus-summary-post-menu)))
2456 (gnus-run-hooks 'gnus-article-menu-hook)))
2458 (defun gnus-article-mode ()
2459 "Major mode for displaying an article.
2461 All normal editing commands are switched off.
2463 The following commands are available in addition to all summary mode
2465 \\<gnus-article-mode-map>
2466 \\[gnus-article-next-page]\t Scroll the article one page forwards
2467 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2468 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2469 \\[gnus-article-show-summary]\t Display the summary buffer
2470 \\[gnus-article-mail]\t Send a reply to the address near point
2471 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2472 \\[gnus-info-find-node]\t Go to the Gnus info node"
2474 (when (gnus-visual-p 'article-menu 'menu)
2475 (gnus-article-make-menu-bar))
2476 (gnus-simplify-mode-line)
2477 (setq mode-name "Article")
2478 (setq major-mode 'gnus-article-mode)
2479 (make-local-variable 'minor-mode-alist)
2480 (use-local-map gnus-article-mode-map)
2481 (gnus-update-format-specifications nil 'article-mode)
2482 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2483 (make-local-variable 'gnus-page-broken)
2484 (make-local-variable 'gnus-button-marker-list)
2485 (make-local-variable 'gnus-article-current-summary)
2486 (make-local-variable 'gnus-article-mime-handles)
2487 (make-local-variable 'gnus-article-decoded-p)
2488 (make-local-variable 'gnus-article-mime-handle-alist)
2489 (make-local-variable 'gnus-article-washed-types)
2490 (gnus-set-default-directory)
2491 (buffer-disable-undo)
2492 (setq buffer-read-only t)
2493 (set-syntax-table gnus-article-mode-syntax-table)
2494 (mm-enable-multibyte)
2495 (gnus-run-hooks 'gnus-article-mode-hook))
2497 (defun gnus-article-setup-buffer ()
2498 "Initialize the article buffer."
2499 (let* ((name (if gnus-single-article-buffer "*Article*"
2500 (concat "*Article " gnus-newsgroup-name "*")))
2502 (progn (string-match "\\*Article" name)
2503 (concat " *Original Article"
2504 (substring name (match-end 0))))))
2505 (setq gnus-article-buffer name)
2506 (setq gnus-original-article-buffer original)
2507 (setq gnus-article-mime-handle-alist nil)
2508 ;; This might be a variable local to the summary buffer.
2509 (unless gnus-single-article-buffer
2511 (set-buffer gnus-summary-buffer)
2512 (setq gnus-article-buffer name)
2513 (setq gnus-original-article-buffer original)
2514 (gnus-set-global-variables)))
2515 (gnus-article-setup-highlight-words)
2516 ;; Init original article buffer.
2518 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2519 (mm-enable-multibyte)
2520 (setq major-mode 'gnus-original-article-mode)
2521 (make-local-variable 'gnus-original-article))
2522 (if (get-buffer name)
2525 (buffer-disable-undo)
2526 (setq buffer-read-only t)
2527 (unless (eq major-mode 'gnus-article-mode)
2528 (gnus-article-mode))
2531 (set-buffer (gnus-get-buffer-create name))
2533 (make-local-variable 'gnus-summary-buffer)
2534 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2535 (current-buffer)))))
2537 ;; Set article window start at LINE, where LINE is the number of lines
2538 ;; from the head of the article.
2539 (defun gnus-article-set-window-start (&optional line)
2541 (get-buffer-window gnus-article-buffer t)
2543 (set-buffer gnus-article-buffer)
2544 (goto-char (point-min))
2547 (gnus-message 6 "Moved to bookmark")
2548 (search-forward "\n\n" nil t)
2552 (defun gnus-article-prepare (article &optional all-headers header)
2553 "Prepare ARTICLE in article mode buffer.
2554 ARTICLE should either be an article number or a Message-ID.
2555 If ARTICLE is an id, HEADER should be the article headers.
2556 If ALL-HEADERS is non-nil, no headers are hidden."
2558 ;; Make sure we start in a summary buffer.
2559 (unless (eq major-mode 'gnus-summary-mode)
2560 (set-buffer gnus-summary-buffer))
2561 (setq gnus-summary-buffer (current-buffer))
2562 (let* ((gnus-article (if header (mail-header-number header) article))
2563 (summary-buffer (current-buffer))
2564 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2565 (group gnus-newsgroup-name)
2568 (gnus-article-setup-buffer)
2569 (set-buffer gnus-article-buffer)
2570 ;; Deactivate active regions.
2571 (when (and (boundp 'transient-mark-mode)
2572 transient-mark-mode)
2573 (setq mark-active nil))
2574 (if (not (setq result (let ((buffer-read-only nil))
2575 (gnus-request-article-this-buffer
2577 ;; There is no such article.
2579 (when (and (numberp article)
2580 (not (memq article gnus-newsgroup-sparse)))
2581 (setq gnus-article-current
2582 (cons gnus-newsgroup-name article))
2583 (set-buffer gnus-summary-buffer)
2584 (setq gnus-current-article article)
2585 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2587 (gnus-summary-set-agent-mark article)
2588 (message "Message marked for downloading"))
2589 (gnus-summary-mark-article article gnus-canceled-mark)
2590 (unless (memq article gnus-newsgroup-sparse)
2592 "No such article (may have expired or been canceled)")))))
2593 (if (or (eq result 'pseudo)
2594 (eq result 'nneething))
2597 (set-buffer summary-buffer)
2598 (push article gnus-newsgroup-history)
2599 (setq gnus-last-article gnus-current-article
2600 gnus-current-article 0
2601 gnus-current-headers nil
2602 gnus-article-current nil)
2603 (if (eq result 'nneething)
2604 (gnus-configure-windows 'summary)
2605 (gnus-configure-windows 'article))
2606 (gnus-set-global-variables))
2607 (let ((gnus-article-mime-handle-alist-1
2608 gnus-article-mime-handle-alist))
2609 (gnus-set-mode-line 'article)))
2610 ;; The result from the `request' was an actual article -
2611 ;; or at least some text that is now displayed in the
2613 (when (and (numberp article)
2614 (not (eq article gnus-current-article)))
2615 ;; Seems like a new article has been selected.
2616 ;; `gnus-current-article' must be an article number.
2618 (set-buffer summary-buffer)
2619 (push article gnus-newsgroup-history)
2620 (setq gnus-last-article gnus-current-article
2621 gnus-current-article article
2622 gnus-current-headers
2623 (gnus-summary-article-header gnus-current-article)
2624 gnus-article-current
2625 (cons gnus-newsgroup-name gnus-current-article))
2626 (unless (vectorp gnus-current-headers)
2627 (setq gnus-current-headers nil))
2628 (gnus-summary-goto-subject gnus-current-article)
2629 (when (gnus-summary-show-thread)
2630 ;; If the summary buffer really was folded, the
2631 ;; previous goto may not actually have gone to
2632 ;; the right article, but the thread root instead.
2634 (gnus-summary-goto-subject gnus-current-article))
2635 (gnus-run-hooks 'gnus-mark-article-hook)
2636 (gnus-set-mode-line 'summary)
2637 (when (gnus-visual-p 'article-highlight 'highlight)
2638 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2639 ;; Set the global newsgroup variables here.
2640 (gnus-set-global-variables)
2641 (setq gnus-have-all-headers
2642 (or all-headers gnus-show-all-headers))))
2643 (when (or (numberp article)
2645 (gnus-article-prepare-display)
2647 (goto-char (point-min))
2648 (setq gnus-page-broken
2649 (when gnus-break-pages
2650 (gnus-narrow-to-page)
2652 (let ((gnus-article-mime-handle-alist-1
2653 gnus-article-mime-handle-alist))
2654 (gnus-set-mode-line 'article))
2656 (set-window-point (get-buffer-window (current-buffer)) (point))
2657 (gnus-configure-windows 'article)
2661 (defun gnus-article-prepare-display ()
2662 "Make the current buffer look like a nice article."
2663 ;; Hooks for getting information from the article.
2664 ;; This hook must be called before being narrowed.
2665 (let ((gnus-article-buffer (current-buffer))
2667 (unless (eq major-mode 'gnus-article-mode)
2668 (gnus-article-mode))
2669 (setq buffer-read-only nil)
2670 (gnus-run-hooks 'gnus-tmp-internal-hook)
2671 (gnus-run-hooks 'gnus-article-prepare-hook)
2672 (when gnus-display-mime-function
2673 (funcall gnus-display-mime-function))))
2676 ;;; Gnus MIME viewing functions
2679 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2680 "The following specs can be used:
2682 %T MIME type, along with additional info
2683 %n The `name' parameter
2684 %d The description, if any
2685 %l The length of the encoded part
2686 %p The part identifier number
2687 %e Dots if the part isn't displayed")
2689 (defvar gnus-mime-button-line-format-alist
2690 '((?t gnus-tmp-type ?s)
2691 (?T gnus-tmp-type-long ?s)
2692 (?n gnus-tmp-name ?s)
2693 (?d gnus-tmp-description ?s)
2695 (?l gnus-tmp-length ?d)
2696 (?e gnus-tmp-dots ?s)))
2698 (defvar gnus-mime-button-commands
2699 '((gnus-article-press-button "\r" "Toggle Display")
2700 (gnus-mime-view-part "v" "View Interactively...")
2701 (gnus-mime-save-part "o" "Save...")
2702 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2703 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2704 (gnus-mime-internalize-part "E" "View Internally")
2705 (gnus-mime-externalize-part "e" "View Externally")
2706 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2708 (defun gnus-article-mime-part-status ()
2709 (if gnus-article-mime-handle-alist-1
2710 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2713 (defvar gnus-mime-button-map nil)
2714 (unless gnus-mime-button-map
2715 (setq gnus-mime-button-map (make-sparse-keymap))
2716 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2717 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2718 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2720 (define-key gnus-mime-button-map (cadr c) (car c)))
2721 gnus-mime-button-commands))
2723 (defun gnus-mime-button-menu (event)
2724 "Construct a context-sensitive menu of MIME commands."
2727 (let ((pos (event-start event)))
2728 (set-buffer (window-buffer (posn-window pos)))
2729 (goto-char (posn-point pos))
2730 (gnus-article-check-buffer)
2731 (let ((response (x-popup-menu
2733 ("" ,@(mapcar (lambda (c)
2734 (cons (caddr c) (car c)))
2735 gnus-mime-button-commands))))))
2737 (funcall response))))))
2739 (defun gnus-mime-view-all-parts (&optional handles)
2740 "View all the MIME parts."
2742 (save-current-buffer
2743 (set-buffer gnus-article-buffer)
2744 (let ((handles (or handles gnus-article-mime-handles))
2745 (mail-parse-charset gnus-newsgroup-charset)
2746 (mail-parse-ignored-charsets
2747 (save-excursion (set-buffer gnus-summary-buffer)
2748 gnus-newsgroup-ignored-charsets)))
2749 (if (stringp (car handles))
2750 (gnus-mime-view-all-parts (cdr handles))
2751 (mapcar 'mm-display-part handles)))))
2753 (defun gnus-mime-save-part ()
2754 "Save the MIME part under point."
2756 (gnus-article-check-buffer)
2757 (let ((data (get-text-property (point) 'gnus-data)))
2758 (mm-save-part data)))
2760 (defun gnus-mime-pipe-part ()
2761 "Pipe the MIME part under point to a process."
2763 (gnus-article-check-buffer)
2764 (let ((data (get-text-property (point) 'gnus-data)))
2765 (mm-pipe-part data)))
2767 (defun gnus-mime-view-part ()
2768 "Interactively choose a view method for the MIME part under point."
2770 (gnus-article-check-buffer)
2771 (let ((data (get-text-property (point) 'gnus-data)))
2772 (mm-interactively-view-part data)))
2774 (defun gnus-mime-copy-part (&optional handle)
2775 "Put the the MIME part under point into a new buffer."
2777 (gnus-article-check-buffer)
2778 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2779 (contents (mm-get-part handle))|
2780 (base (file-name-nondirectory
2782 (mail-content-type-get (mm-handle-type handle) 'name)
2783 (mail-content-type-get (mm-handle-type handle)
2786 (buffer (generate-new-buffer base)))
2787 (switch-to-buffer buffer)
2789 ;; We do it this way to make `normal-mode' set the appropriate mode.
2792 (setq buffer-file-name (expand-file-name base))
2794 (setq buffer-file-name nil))
2795 (goto-char (point-min))))
2797 (defun gnus-mime-inline-part (&optional handle)
2798 "Insert the MIME part under point into the current buffer."
2800 (gnus-article-check-buffer)
2801 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2805 (if (mm-handle-undisplayer handle)
2806 (mm-remove-part handle)
2807 (setq contents (mm-get-part handle))
2809 (mm-insert-inline handle contents)
2812 (defun gnus-mime-externalize-part (&optional handle)
2813 "View the MIME part under point with an external viewer."
2815 (gnus-article-check-buffer)
2816 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2817 (mm-user-display-methods nil)
2818 (mm-all-images-fit t)
2819 (mail-parse-charset gnus-newsgroup-charset)
2820 (mail-parse-ignored-charsets
2821 (save-excursion (set-buffer gnus-summary-buffer)
2822 gnus-newsgroup-ignored-charsets)))
2823 (if (mm-handle-undisplayer handle)
2824 (mm-remove-part handle)
2825 (mm-display-part handle))))
2827 (defun gnus-mime-internalize-part (&optional handle)
2828 "View the MIME part under point with an internal viewer."
2830 (gnus-article-check-buffer)
2831 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2832 (mm-user-display-methods '((".*" . inline)))
2833 (mm-all-images-fit t)
2834 (mail-parse-charset gnus-newsgroup-charset)
2835 (mail-parse-ignored-charsets
2836 (save-excursion (set-buffer gnus-summary-buffer)
2837 gnus-newsgroup-ignored-charsets)))
2838 (if (mm-handle-undisplayer handle)
2839 (mm-remove-part handle)
2840 (mm-display-part handle))))
2842 (defun gnus-article-part-wrapper (n function)
2843 (save-current-buffer
2844 (set-buffer gnus-article-buffer)
2845 (when (> n (length gnus-article-mime-handle-alist))
2846 (error "No such part"))
2847 (gnus-article-goto-part n)
2848 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2849 (funcall function handle))))
2851 (defun gnus-article-pipe-part (n)
2852 "Pipe MIME part N, which is the numerical prefix."
2854 (gnus-article-part-wrapper n 'mm-pipe-part))
2856 (defun gnus-article-save-part (n)
2857 "Save MIME part N, which is the numerical prefix."
2859 (gnus-article-part-wrapper n 'mm-save-part))
2861 (defun gnus-article-interactively-view-part (n)
2862 "View MIME part N interactively, which is the numerical prefix."
2864 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2866 (defun gnus-article-copy-part (n)
2867 "Copy MIME part N, which is the numerical prefix."
2869 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2871 (defun gnus-article-externalize-part (n)
2872 "View MIME part N externally, which is the numerical prefix."
2874 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2876 (defun gnus-article-inline-part (n)
2877 "Inline MIME part N, which is the numerical prefix."
2879 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2881 (defun gnus-article-view-part (n)
2882 "View MIME part N, which is the numerical prefix."
2884 (save-current-buffer
2885 (set-buffer gnus-article-buffer)
2886 (when (> n (length gnus-article-mime-handle-alist))
2887 (error "No such part"))
2888 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2889 (when (gnus-article-goto-part n)
2890 (if (equal (car handle) "multipart/alternative")
2891 (gnus-article-press-button)
2892 (when (eq (gnus-mm-display-part handle) 'internal)
2893 (gnus-set-window-start)))))))
2895 (defun gnus-mm-display-part (handle)
2896 "Display HANDLE and fix MIME button."
2897 (let ((id (get-text-property (point) 'gnus-part))
2902 (let ((window (selected-window))
2903 (mail-parse-charset gnus-newsgroup-charset)
2904 (mail-parse-ignored-charsets
2905 (save-excursion (set-buffer gnus-summary-buffer)
2906 gnus-newsgroup-ignored-charsets)))
2909 (let ((win (get-buffer-window (current-buffer) t))
2912 (select-window win))
2915 (if (mm-handle-displayed-p handle)
2916 ;; This will remove the part.
2917 (mm-display-part handle)
2919 (narrow-to-region (point) (1+ (point)))
2920 (mm-display-part handle)
2921 ;; We narrow to the part itself and
2922 ;; then call the treatment functions.
2923 (goto-char (point-min))
2925 (narrow-to-region (point) (point-max))
2928 (1- (length gnus-article-mime-handles))
2929 (car (mm-handle-type handle))))))
2930 (select-window window))))
2932 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2933 (gnus-insert-mime-button
2934 handle id (list (mm-handle-displayed-p handle)))
2935 (goto-char point))))
2937 (defun gnus-article-goto-part (n)
2938 "Go to MIME part N."
2939 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2941 (goto-char point))))
2943 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2944 (let ((gnus-tmp-name
2945 (or (mail-content-type-get (mm-handle-type handle)
2947 (mail-content-type-get (mm-handle-disposition handle)
2950 (gnus-tmp-type (car (mm-handle-type handle)))
2951 (gnus-tmp-description
2952 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2955 (if (if displayed (car displayed)
2956 (mm-handle-displayed-p handle))
2958 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2960 gnus-tmp-type-long b e)
2961 (when (string-match ".*/" gnus-tmp-name)
2962 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2963 (setq gnus-tmp-type-long (concat gnus-tmp-type
2964 (and (not (equal gnus-tmp-name ""))
2965 (concat "; " gnus-tmp-name))))
2966 (or (equal gnus-tmp-description "")
2967 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2972 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2973 `(local-map ,gnus-mime-button-map
2974 keymap ,gnus-mime-button-map
2975 gnus-callback gnus-mm-display-part
2976 gnus-part ,gnus-tmp-id
2977 article-type annotation
2980 (widget-convert-button 'link b e
2982 :action 'gnus-widget-press-button
2983 :button-keymap gnus-mime-button-map
2986 ;; Needed to properly clear the message
2987 ;; due to a bug in wid-edit
2988 (setq help-echo-owns-message t)
2990 "Click to %s the MIME part; %s for more options"
2991 (if (mm-handle-displayed-p
2992 (widget-get widget :mime-handle))
2994 (if gnus-xemacs "button3" "mouse-3"))))))
2996 (defun gnus-widget-press-button (elems el)
2997 (goto-char (widget-get elems :from))
2998 (gnus-article-press-button))
3000 (defvar gnus-displaying-mime nil)
3002 (defun gnus-display-mime (&optional ihandles)
3003 "Display the MIME parts."
3005 (save-selected-window
3006 (let ((window (get-buffer-window gnus-article-buffer))
3009 (select-window window)
3010 ;; We have to do this since selecting the window
3011 ;; may change the point. So we set the window point.
3012 (set-window-point window point)))
3013 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3014 buffer-read-only handle name type b e display)
3015 (when (and (not ihandles)
3016 (not gnus-displaying-mime))
3017 ;; Top-level call; we clean up.
3018 (when gnus-article-mime-handles
3019 (mm-destroy-parts gnus-article-mime-handles)
3020 (setq gnus-article-mime-handle-alist nil)) ;; A trick.
3021 (setq gnus-article-mime-handles handles)
3022 ;; We allow users to glean info from the handles.
3023 (when gnus-article-mime-part-function
3024 (gnus-mime-part-function handles)))
3026 (or (not (stringp (car handles)))
3029 (when (and (not ihandles)
3030 (not gnus-displaying-mime))
3031 ;; Clean up for mime parts.
3033 (delete-region (point) (point-max)))
3034 (let ((gnus-displaying-mime t))
3035 (gnus-mime-display-part handles)))
3038 (narrow-to-region (point) (point-max))
3039 (gnus-treat-article nil 1 1)
3042 ;; Highlight the headers.
3046 (narrow-to-region (point-min) (point))
3047 (gnus-treat-article 'head))))))))
3049 (defvar gnus-mime-display-multipart-as-mixed nil)
3051 (defun gnus-mime-display-part (handle)
3054 ((not (stringp (car handle)))
3055 (gnus-mime-display-single handle))
3056 ;; User-defined multipart
3057 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3058 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3060 ;; multipart/alternative
3061 ((and (equal (car handle) "multipart/alternative")
3062 (not gnus-mime-display-multipart-as-mixed))
3063 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3064 (push (cons id handle) gnus-article-mime-handle-alist)
3065 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3066 ;; multipart/related
3067 ((and (equal (car handle) "multipart/related")
3068 (not gnus-mime-display-multipart-as-mixed))
3069 ;;;!!!We should find the start part, but we just default
3070 ;;;!!!to the first part.
3071 (gnus-mime-display-part (cadr handle)))
3072 ;; Other multiparts are handled like multipart/mixed.
3074 (gnus-mime-display-mixed (cdr handle)))))
3076 (defun gnus-mime-part-function (handles)
3077 (if (stringp (car handles))
3078 (mapcar 'gnus-mime-part-function (cdr handles))
3079 (funcall gnus-article-mime-part-function handles)))
3081 (defun gnus-mime-display-mixed (handles)
3082 (mapcar 'gnus-mime-display-part handles))
3084 (defun gnus-mime-display-single (handle)
3085 (let ((type (car (mm-handle-type handle)))
3086 (ignored gnus-ignored-mime-types)
3093 (when (string-match (pop ignored) type)
3094 (throw 'ignored nil)))
3095 (if (and (setq not-attachment
3096 (or (not (mm-handle-disposition handle))
3097 (equal (car (mm-handle-disposition handle))
3099 (mm-attachment-override-p type)))
3100 (mm-automatic-display-p type)
3101 (or (mm-inlinable-part-p type)
3102 (mm-automatic-external-display-p type)))
3104 (when (equal (car (split-string type "/"))
3107 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3108 (push (cons id handle) gnus-article-mime-handle-alist)
3109 (when (or (not display)
3110 (not (gnus-unbuttonized-mime-type-p type)))
3111 (gnus-article-insert-newline)
3112 (gnus-insert-mime-button
3113 handle id (list (or display (and not-attachment text))))
3114 (gnus-article-insert-newline)
3115 (gnus-article-insert-newline)
3117 (let ((beg (point)))
3122 (let ((mail-parse-charset gnus-newsgroup-charset)
3123 (mail-parse-ignored-charsets
3124 (save-excursion (set-buffer gnus-summary-buffer)
3125 gnus-newsgroup-ignored-charsets)))
3126 (mm-display-part handle t))
3127 (goto-char (point-max)))
3128 ((and text not-attachment)
3131 (gnus-article-insert-newline)
3132 (mm-insert-inline handle (mm-get-part handle))
3133 (goto-char (point-max))))
3137 (narrow-to-region beg (point))
3139 nil (length gnus-article-mime-handle-alist)
3140 (1- (length gnus-article-mime-handles))
3141 (car (mm-handle-type handle))))))))))
3143 (defun gnus-unbuttonized-mime-type-p (type)
3144 "Say whether TYPE is to be unbuttonized."
3145 (unless gnus-inhibit-mime-unbuttonizing
3147 (let ((types gnus-unbuttonized-mime-types))
3149 (when (string-match (pop types) type)
3150 (throw 'found t)))))))
3152 (defun gnus-article-insert-newline ()
3153 "Insert a newline, but mark it as undeletable."
3154 (gnus-put-text-property
3155 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3157 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3158 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3161 handle buffer-read-only from props begend not-pref)
3162 (save-window-excursion
3165 (narrow-to-region (car ibegend)
3168 (goto-char (car ibegend))
3171 (delete-region (point-min) (point-max))
3172 (mm-remove-parts handles))
3173 (setq begend (list (point-marker)))
3175 (unless (setq not-pref (cadr (member preferred ihandles)))
3176 (setq not-pref (car ihandles)))
3178 (not (gnus-unbuttonized-mime-type-p
3179 "multipart/alternative")))
3180 (gnus-add-text-properties
3183 (insert (format "%d. " id))
3187 (unless ,(not ibegend)
3188 (setq gnus-article-mime-handle-alist
3189 ',gnus-article-mime-handle-alist))
3190 (gnus-mime-display-alternative
3191 ',ihandles ',not-pref ',begend ,id))
3192 local-map ,gnus-mime-button-map
3193 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3194 face ,gnus-article-button-face
3195 keymap ,gnus-mime-button-map
3198 (widget-convert-button 'link from (point)
3199 :action 'gnus-widget-press-button
3200 :button-keymap gnus-widget-button-keymap)
3202 (while (setq handle (pop handles))
3203 (gnus-add-text-properties
3206 (insert (format "(%c) %-18s"
3207 (if (equal handle preferred) ?* ? )
3208 (if (stringp (car handle))
3210 (car (mm-handle-type handle)))))
3214 (unless ,(not ibegend)
3215 (setq gnus-article-mime-handle-alist
3216 ',gnus-article-mime-handle-alist))
3217 (gnus-mime-display-alternative
3218 ',ihandles ',handle ',begend ,id))
3219 local-map ,gnus-mime-button-map
3220 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3221 face ,gnus-article-button-face
3222 keymap ,gnus-mime-button-map
3225 (widget-convert-button 'link from (point)
3226 :action 'gnus-widget-press-button
3227 :button-keymap gnus-widget-button-keymap)
3231 (if (stringp (car preferred))
3232 (gnus-display-mime preferred)
3233 (let ((mail-parse-charset gnus-newsgroup-charset)
3234 (mail-parse-ignored-charsets
3235 (save-excursion (set-buffer gnus-summary-buffer)
3236 gnus-newsgroup-ignored-charsets)))
3237 (mm-display-part preferred)))
3238 (goto-char (point-max))
3239 (setcdr begend (point-marker)))))
3241 (goto-char point))))
3243 (defun gnus-article-wash-status ()
3244 "Return a string which display status of article washing."
3246 (set-buffer gnus-article-buffer)
3247 (let ((cite (memq 'cite gnus-article-wash-types))
3248 (headers (memq 'headers gnus-article-wash-types))
3249 (boring (memq 'boring-headers gnus-article-wash-types))
3250 (pgp (memq 'pgp gnus-article-wash-types))
3251 (pem (memq 'pem gnus-article-wash-types))
3252 (signature (memq 'signature gnus-article-wash-types))
3253 (overstrike (memq 'overstrike gnus-article-wash-types))
3254 (emphasis (memq 'emphasis gnus-article-wash-types)))
3255 (format "%c%c%c%c%c%c"
3257 (if (or headers boring) ?h ? )
3258 (if (or pgp pem) ?p ? )
3259 (if signature ?s ? )
3260 (if overstrike ?o ? )
3261 (if emphasis ?e ? )))))
3263 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3265 (defun gnus-article-maybe-hide-headers ()
3266 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3267 Provided for backwards compatibility."
3268 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3269 (not (save-excursion (set-buffer gnus-summary-buffer)
3270 gnus-have-all-headers)))
3271 (not gnus-inhibit-hiding))
3272 (gnus-article-hide-headers)))
3276 (defun gnus-output-to-file (file-name)
3277 "Append the current article to a file named FILE-NAME."
3278 (let ((artbuf (current-buffer)))
3280 (insert-buffer-substring artbuf)
3281 ;; Append newline at end of the buffer as separator, and then
3283 (goto-char (point-max))
3285 (append-to-file (point-min) (point-max) file-name)
3288 (defun gnus-narrow-to-page (&optional arg)
3289 "Narrow the article buffer to a page.
3290 If given a numerical ARG, move forward ARG pages."
3292 (setq arg (if arg (prefix-numeric-value arg) 0))
3294 (set-buffer gnus-article-buffer)
3295 (goto-char (point-min))
3297 ;; Remove any old next/prev buttons.
3298 (when (gnus-visual-p 'page-marker)
3299 (let ((buffer-read-only nil))
3300 (gnus-remove-text-with-property 'gnus-prev)
3301 (gnus-remove-text-with-property 'gnus-next)))
3304 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3306 (re-search-forward page-delimiter nil 'move arg)))
3307 (goto-char (match-end 0)))
3310 (if (re-search-forward page-delimiter nil 'move)
3313 (when (and (gnus-visual-p 'page-marker)
3314 (not (= (point-min) 1)))
3316 (goto-char (point-min))
3317 (gnus-insert-prev-page-button)))
3318 (when (and (gnus-visual-p 'page-marker)
3319 (< (+ (point-max) 2) (buffer-size)))
3321 (goto-char (point-max))
3322 (gnus-insert-next-page-button)))))
3324 ;; Article mode commands
3326 (defun gnus-article-goto-next-page ()
3327 "Show the next page of the article."
3329 (when (gnus-article-next-page)
3330 (goto-char (point-min))
3331 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3333 (defun gnus-article-goto-prev-page ()
3334 "Show the next page of the article."
3336 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3337 (gnus-article-prev-page nil)))
3339 (defun gnus-article-next-page (&optional lines)
3340 "Show the next page of the current article.
3341 If end of article, return non-nil. Otherwise return nil.
3342 Argument LINES specifies lines to be scrolled up."
3344 (move-to-window-line -1)
3347 (and (pos-visible-in-window-p) ;Not continuation line.
3349 ;; Nothing in this page.
3350 (if (or (not gnus-page-broken)
3353 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3355 (gnus-narrow-to-page 1) ;Go to next page.
3357 ;; More in this page.
3358 (let ((scroll-in-place nil))
3362 ;; Long lines may cause an end-of-buffer error.
3363 (goto-char (point-max)))))
3364 (move-to-window-line 0)
3367 (defun gnus-article-prev-page (&optional lines)
3368 "Show previous page of current article.
3369 Argument LINES specifies lines to be scrolled down."
3371 (move-to-window-line 0)
3372 (if (and gnus-page-broken
3374 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3376 (gnus-narrow-to-page -1) ;Go to previous page.
3377 (goto-char (point-max))
3379 (let ((scroll-in-place nil))
3383 (beginning-of-buffer
3384 (goto-char (point-min))))
3385 (move-to-window-line 0)))))
3387 (defun gnus-article-refer-article ()
3388 "Read article specified by message-id around point."
3390 (let ((point (point)))
3391 (search-forward ">" nil t) ;Move point to end of "<....>".
3392 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3393 (let ((message-id (match-string 1)))
3395 (set-buffer gnus-summary-buffer)
3396 (gnus-summary-refer-article message-id))
3398 (error "No references around point"))))
3400 (defun gnus-article-show-summary ()
3401 "Reconfigure windows to show summary buffer."
3403 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3404 (error "There is no summary buffer for this article buffer")
3405 (gnus-article-set-globals)
3406 (gnus-configure-windows 'article)
3407 (gnus-summary-goto-subject gnus-current-article)
3408 (gnus-summary-position-point)))
3410 (defun gnus-article-describe-briefly ()
3411 "Describe article mode commands briefly."
3413 (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")))
3415 (defun gnus-article-summary-command ()
3416 "Execute the last keystroke in the summary buffer."
3418 (let ((obuf (current-buffer))
3419 (owin (current-window-configuration))
3421 (switch-to-buffer gnus-article-current-summary 'norecord)
3422 (setq func (lookup-key (current-local-map) (this-command-keys)))
3423 (call-interactively func)
3425 (set-window-configuration owin)
3426 (set-window-point (get-buffer-window (current-buffer)) (point))))
3428 (defun gnus-article-summary-command-nosave ()
3429 "Execute the last keystroke in the summary buffer."
3432 (pop-to-buffer gnus-article-current-summary 'norecord)
3433 (setq func (lookup-key (current-local-map) (this-command-keys)))
3434 (call-interactively func)))
3436 (defun gnus-article-check-buffer ()
3437 "Beep if not in an article buffer."
3438 (unless (equal major-mode 'gnus-article-mode)
3439 (error "Command invoked outside of a Gnus article buffer")))
3441 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3442 "Read a summary buffer key sequence and execute it from the article buffer."
3444 (gnus-article-check-buffer)
3446 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3447 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3448 "=" "^" "\M-^" "|"))
3454 '("n" "Gn" "p" "Gp"))
3457 (set-buffer gnus-article-current-summary)
3458 (let (gnus-pick-mode)
3459 (push (or key last-command-event) unread-command-events)
3460 (setq keys (if gnus-xemacs
3461 (events-to-keys (read-key-sequence nil))
3462 (read-key-sequence nil)))))
3466 (if (or (member keys nosaves)
3467 (member keys nosave-but-article)
3468 (member keys nosave-in-article))
3470 (save-window-excursion
3471 (pop-to-buffer gnus-article-current-summary 'norecord)
3472 ;; We disable the pick minor mode commands.
3473 (let (gnus-pick-mode)
3474 (setq func (lookup-key (current-local-map) keys))))
3477 (unless (member keys nosave-in-article)
3478 (set-buffer gnus-article-current-summary))
3479 (call-interactively func)
3480 (setq new-sum-point (point)))
3481 (when (member keys nosave-but-article)
3482 (pop-to-buffer gnus-article-buffer 'norecord)))
3483 ;; These commands should restore window configuration.
3484 (let ((obuf (current-buffer))
3485 (owin (current-window-configuration))
3487 (summary gnus-article-current-summary)
3488 func in-buffer selected)
3489 (if not-restore-window
3490 (pop-to-buffer summary 'norecord)
3491 (switch-to-buffer summary 'norecord))
3492 (setq in-buffer (current-buffer))
3493 ;; We disable the pick minor mode commands.
3494 (if (setq func (let (gnus-pick-mode)
3495 (lookup-key (current-local-map) keys)))
3497 (call-interactively func)
3498 (setq new-sum-point (point)))
3500 (when (eq in-buffer (current-buffer))
3501 (setq selected (gnus-summary-select-article))
3503 (unless not-restore-window
3504 (set-window-configuration owin))
3505 (when (eq selected 'old)
3507 (set-window-start (get-buffer-window (current-buffer))
3509 (set-window-point (get-buffer-window (current-buffer))
3511 (let ((win (get-buffer-window gnus-article-current-summary)))
3513 (set-window-point win new-sum-point))))))))
3515 (defun gnus-article-hide (&optional arg force)
3516 "Hide all the gruft in the current article.
3517 This means that PGP stuff, signatures, cited text and (some)
3518 headers will be hidden.
3519 If given a prefix, show the hidden text instead."
3520 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3521 (gnus-article-hide-headers arg)
3522 (gnus-article-hide-pgp arg)
3523 (gnus-article-hide-citation-maybe arg force)
3524 (gnus-article-hide-signature arg))
3526 (defun gnus-article-maybe-highlight ()
3527 "Do some article highlighting if article highlighting is requested."
3528 (when (gnus-visual-p 'article-highlight 'highlight)
3529 (gnus-article-highlight-some)))
3531 (defun gnus-check-group-server ()
3532 ;; Make sure the connection to the server is alive.
3533 (unless (gnus-server-opened
3534 (gnus-find-method-for-group gnus-newsgroup-name))
3535 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3536 (gnus-request-group gnus-newsgroup-name t)))
3538 (defun gnus-request-article-this-buffer (article group)
3539 "Get an article and insert it into this buffer."
3540 (let (do-update-line sparse-header)
3544 (gnus-kill-all-overlays)
3545 (setq group (or group gnus-newsgroup-name))
3547 ;; Using `gnus-request-article' directly will insert the article into
3548 ;; `nntp-server-buffer' - so we'll save some time by not having to
3549 ;; copy it from the server buffer into the article buffer.
3551 ;; We only request an article by message-id when we do not have the
3552 ;; headers for it, so we'll have to get those.
3553 (when (stringp article)
3554 (let ((gnus-override-method gnus-refer-article-method))
3555 (gnus-read-header article)))
3557 ;; If the article number is negative, that means that this article
3558 ;; doesn't belong in this newsgroup (possibly), so we find its
3559 ;; message-id and request it by id instead of number.
3560 (when (and (numberp article)
3562 (get-buffer gnus-summary-buffer)
3563 (gnus-buffer-exists-p gnus-summary-buffer))
3565 (set-buffer gnus-summary-buffer)
3566 (let ((header (gnus-summary-article-header article)))
3569 ((memq article gnus-newsgroup-sparse)
3570 ;; This is a sparse gap article.
3571 (setq do-update-line article)
3572 (setq article (mail-header-id header))
3573 (let ((gnus-override-method gnus-refer-article-method))
3574 (setq sparse-header (gnus-read-header article)))
3575 (setq gnus-newsgroup-sparse
3576 (delq article gnus-newsgroup-sparse)))
3578 ;; It's a real article.
3579 (setq article (mail-header-id header)))
3581 ;; It is an extracted pseudo-article.
3582 (setq article 'pseudo)
3583 (gnus-request-pseudo-article header))))
3585 (let ((method (gnus-find-method-for-group
3586 gnus-newsgroup-name)))
3587 (when (and (eq (car method) 'nneething)
3590 (file-name-as-directory
3591 (or (cadr (assq 'nneething-address method))
3593 (mail-header-subject header))))
3594 (when (file-directory-p dir)
3595 (setq article 'nneething)
3596 (gnus-group-enter-directory dir))))))))
3599 ;; Refuse to select canceled articles.
3600 ((and (numberp article)
3602 (get-buffer gnus-summary-buffer)
3603 (gnus-buffer-exists-p gnus-summary-buffer)
3604 (eq (cdr (save-excursion
3605 (set-buffer gnus-summary-buffer)
3606 (assq article gnus-newsgroup-reads)))
3607 gnus-canceled-mark))
3609 ;; We first check `gnus-original-article-buffer'.
3610 ((and (get-buffer gnus-original-article-buffer)
3613 (set-buffer gnus-original-article-buffer)
3614 (and (equal (car gnus-original-article) group)
3615 (eq (cdr gnus-original-article) article))))
3616 (insert-buffer-substring gnus-original-article-buffer)
3618 ;; Check the backlog.
3619 ((and gnus-keep-backlog
3620 (gnus-backlog-request-article group article (current-buffer)))
3622 ;; Check asynchronous pre-fetch.
3623 ((gnus-async-request-fetched-article group article (current-buffer))
3624 (gnus-async-prefetch-next group article gnus-summary-buffer)
3625 (when (and (numberp article) gnus-keep-backlog)
3626 (gnus-backlog-enter-article group article (current-buffer)))
3629 ((and gnus-use-cache
3631 (gnus-cache-request-article article group))
3633 ;; Get the article and put into the article buffer.
3634 ((or (stringp article) (numberp article))
3635 (let ((gnus-override-method
3636 (and (stringp article) gnus-refer-article-method))
3637 (buffer-read-only nil))
3639 (gnus-kill-all-overlays)
3640 (gnus-check-group-server)
3641 (when (gnus-request-article article group (current-buffer))
3642 (when (numberp article)
3643 (gnus-async-prefetch-next group article gnus-summary-buffer)
3644 (when gnus-keep-backlog
3645 (gnus-backlog-enter-article
3646 group article (current-buffer))))
3651 ;; Associate this article with the current summary buffer.
3652 (setq gnus-article-current-summary gnus-summary-buffer)
3654 ;; Take the article from the original article buffer
3655 ;; and place it in the buffer it's supposed to be in.
3656 (when (and (get-buffer gnus-article-buffer)
3657 (equal (buffer-name (current-buffer))
3658 (buffer-name (get-buffer gnus-article-buffer))))
3660 (if (get-buffer gnus-original-article-buffer)
3661 (set-buffer gnus-original-article-buffer)
3662 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3663 (buffer-disable-undo)
3664 (setq major-mode 'gnus-original-article-mode)
3665 (setq buffer-read-only t))
3666 (let (buffer-read-only)
3668 (insert-buffer-substring gnus-article-buffer))
3669 (setq gnus-original-article (cons group article)))
3672 (run-hooks 'gnus-article-decode-hook)
3673 ;; Mark article as decoded or not.
3674 (setq gnus-article-decoded-p gnus-article-decode-hook))
3676 ;; Update sparse articles.
3677 (when (and do-update-line
3678 (or (numberp article)
3680 (let ((buf (current-buffer)))
3681 (set-buffer gnus-summary-buffer)
3682 (gnus-summary-update-article do-update-line sparse-header)
3683 (gnus-summary-goto-subject do-update-line nil t)
3684 (set-window-point (get-buffer-window (current-buffer) t)
3686 (set-buffer buf))))))
3692 (defcustom gnus-article-edit-mode-hook nil
3693 "Hook run in article edit mode buffers."
3694 :group 'gnus-article-various
3697 (defvar gnus-article-edit-done-function nil)
3699 (defvar gnus-article-edit-mode-map nil)
3701 ;; Should we be using derived.el for this?
3702 (unless gnus-article-edit-mode-map
3703 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3704 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3706 (gnus-define-keys gnus-article-edit-mode-map
3707 "\C-c\C-c" gnus-article-edit-done
3708 "\C-c\C-k" gnus-article-edit-exit)
3710 (gnus-define-keys (gnus-article-edit-wash-map
3711 "\C-c\C-w" gnus-article-edit-mode-map)
3712 "f" gnus-article-edit-full-stops))
3714 (defun gnus-article-edit-mode ()
3715 "Major mode for editing articles.
3716 This is an extended text-mode.
3718 \\{gnus-article-edit-mode-map}"
3720 (setq major-mode 'gnus-article-edit-mode)
3721 (setq mode-name "Article Edit")
3722 (use-local-map gnus-article-edit-mode-map)
3723 (make-local-variable 'gnus-article-edit-done-function)
3724 (make-local-variable 'gnus-prev-winconf)
3725 (setq buffer-read-only nil)
3726 (buffer-enable-undo)
3728 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3730 (defun gnus-article-edit (&optional force)
3731 "Edit the current article.
3732 This will have permanent effect only in mail groups.
3733 If FORCE is non-nil, allow editing of articles even in read-only
3736 (when (and (not force)
3737 (gnus-group-read-only-p))
3738 (error "The current newsgroup does not support article editing"))
3739 (gnus-article-date-original)
3740 (gnus-article-edit-article
3742 `(lambda (no-highlight)
3744 (gnus-summary-edit-article-done
3745 ,(or (mail-header-references gnus-current-headers) "")
3746 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3748 (defun gnus-article-edit-article (start-func exit-func)
3749 "Start editing the contents of the current article buffer."
3750 (let ((winconf (current-window-configuration)))
3751 (set-buffer gnus-article-buffer)
3752 (gnus-article-edit-mode)
3753 (funcall start-func)
3754 ;;(gnus-article-delete-text-of-type 'annotation)
3755 ;;(gnus-set-text-properties (point-min) (point-max) nil)
3756 (gnus-configure-windows 'edit-article)
3757 (setq gnus-article-edit-done-function exit-func)
3758 (setq gnus-prev-winconf winconf)
3759 (gnus-message 6 "C-c C-c to end edits")))
3761 (defun gnus-article-edit-done (&optional arg)
3762 "Update the article edits and exit."
3767 (when (article-goto-body)
3768 (let ((lines (count-lines (point) (point-max)))
3769 (length (- (point-max) (point)))
3770 (case-fold-search t)
3771 (body (copy-marker (point))))
3772 (goto-char (point-min))
3773 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3774 (delete-region (match-beginning 1) (match-end 1))
3775 (insert (number-to-string length)))
3776 (goto-char (point-min))
3777 (when (re-search-forward
3778 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3779 (delete-region (match-beginning 1) (match-end 1))
3780 (insert (number-to-string length)))
3781 (goto-char (point-min))
3782 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3783 (delete-region (match-beginning 1) (match-end 1))
3784 (insert (number-to-string lines)))))))
3785 (let ((func gnus-article-edit-done-function)
3786 (buf (current-buffer))
3787 (start (window-start)))
3788 (gnus-article-edit-exit)
3791 (let ((buffer-read-only nil))
3793 ;; The cache and backlog have to be flushed somewhat.
3794 (when gnus-keep-backlog
3795 (gnus-backlog-remove-article
3796 (car gnus-article-current) (cdr gnus-article-current)))
3797 ;; Flush original article as well.
3799 (when (get-buffer gnus-original-article-buffer)
3800 (set-buffer gnus-original-article-buffer)
3801 (setq gnus-original-article nil)))
3802 (when gnus-use-cache
3803 (gnus-cache-update-article
3804 (car gnus-article-current) (cdr gnus-article-current))))
3806 (set-window-start (get-buffer-window buf) start)
3807 (set-window-point (get-buffer-window buf) (point))))
3809 (defun gnus-article-edit-exit ()
3810 "Exit the article editing without updating."
3812 ;; We remove all text props from the article buffer.
3813 (let ((buf (format "%s" (buffer-string)))
3814 (curbuf (current-buffer))
3816 (window-start (window-start)))
3819 (let ((winconf gnus-prev-winconf))
3821 (set-window-configuration winconf)
3822 ;; Tippy-toe some to make sure that point remains where it was.
3823 (save-current-buffer
3825 (set-window-start (get-buffer-window (current-buffer)) window-start)
3828 (defun gnus-article-edit-full-stops ()
3829 "Interactively repair spacing at end of sentences."
3832 (goto-char (point-min))
3833 (search-forward-regexp "^$" nil t)
3834 (let ((case-fold-search nil))
3835 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3838 ;;; Article highlights
3841 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3843 ;;; Internal Variables:
3845 (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\\)"
3846 "Regular expression that matches URLs."
3847 :group 'gnus-article-buttons
3850 (defcustom gnus-button-alist
3851 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3852 0 t gnus-button-message-id 2)
3853 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3854 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3856 gnus-button-fetch-group 4)
3857 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3858 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3859 t gnus-button-message-id 3)
3860 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3861 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3862 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3863 ;; This is how URLs _should_ be embedded in text...
3864 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3866 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3867 "*Alist of regexps matching buttons in article bodies.
3869 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3870 REGEXP: is the string matching text around the button,
3871 BUTTON: is the number of the regexp grouping actually matching the button,
3872 FORM: is a lisp expression which must eval to true for the button to
3874 CALLBACK: is the function to call when the user push this button, and each
3875 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3877 CALLBACK can also be a variable, in that case the value of that
3878 variable it the real callback function."
3879 :group 'gnus-article-buttons
3880 :type '(repeat (list regexp
3881 (integer :tag "Button")
3883 (function :tag "Callback")
3886 (integer :tag "Regexp group")))))
3888 (defcustom gnus-header-button-alist
3889 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3890 0 t gnus-button-message-id 0)
3891 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3892 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3893 0 t gnus-button-mailto 0)
3894 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3895 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3896 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3897 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3898 gnus-button-message-id 3))
3899 "*Alist of headers and regexps to match buttons in article heads.
3901 This alist is very similar to `gnus-button-alist', except that each
3902 alist has an additional HEADER element first in each entry:
3904 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3906 HEADER is a regexp to match a header. For a fuller explanation, see
3907 `gnus-button-alist'."
3908 :group 'gnus-article-buttons
3909 :group 'gnus-article-headers
3910 :type '(repeat (list (regexp :tag "Header")
3912 (integer :tag "Button")
3914 (function :tag "Callback")
3917 (integer :tag "Regexp group")))))
3919 (defvar gnus-button-regexp nil)
3920 (defvar gnus-button-marker-list nil)
3921 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3923 (defvar gnus-button-last nil)
3924 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3928 (defun gnus-article-push-button (event)
3929 "Check text under the mouse pointer for a callback function.
3930 If the text under the mouse pointer has a `gnus-callback' property,
3931 call it with the value of the `gnus-data' text property."
3933 (set-buffer (window-buffer (posn-window (event-start event))))
3934 (let* ((pos (posn-point (event-start event)))
3935 (data (get-text-property pos 'gnus-data))
3936 (fun (get-text-property pos 'gnus-callback)))
3939 (funcall fun data))))
3941 (defun gnus-article-press-button ()
3942 "Check text at point for a callback function.
3943 If the text at point has a `gnus-callback' property,
3944 call it with the value of the `gnus-data' text property."
3946 (let* ((data (get-text-property (point) 'gnus-data))
3947 (fun (get-text-property (point) 'gnus-callback)))
3949 (funcall fun data))))
3951 (defun gnus-article-highlight (&optional force)
3952 "Highlight current article.
3953 This function calls `gnus-article-highlight-headers',
3954 `gnus-article-highlight-citation',
3955 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3956 do the highlighting. See the documentation for those functions."
3957 (interactive (list 'force))
3958 (gnus-article-highlight-headers)
3959 (gnus-article-highlight-citation force)
3960 (gnus-article-highlight-signature)
3961 (gnus-article-add-buttons force)
3962 (gnus-article-add-buttons-to-head))
3964 (defun gnus-article-highlight-some (&optional force)
3965 "Highlight current article.
3966 This function calls `gnus-article-highlight-headers',
3967 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
3968 do the highlighting. See the documentation for those functions."
3969 (interactive (list 'force))
3970 (gnus-article-highlight-headers)
3971 (gnus-article-highlight-signature)
3972 (gnus-article-add-buttons))
3974 (defun gnus-article-highlight-headers ()
3975 "Highlight article headers as specified by `gnus-header-face-alist'."
3978 (set-buffer gnus-article-buffer)
3980 (let ((alist gnus-header-face-alist)
3981 (buffer-read-only nil)
3982 (case-fold-search t)
3983 (inhibit-point-motion-hooks t)
3984 entry regexp header-face field-face from hpoints fpoints)
3985 (article-narrow-to-head)
3986 (while (setq entry (pop alist))
3987 (goto-char (point-min))
3988 (setq regexp (concat "^\\("
3989 (if (string-equal "" (nth 0 entry))
3993 header-face (nth 1 entry)
3994 field-face (nth 2 entry))
3995 (while (and (re-search-forward regexp nil t)
3999 (unless (search-forward ":" nil t)
4001 (when (and header-face
4002 (not (memq (point) hpoints)))
4003 (push (point) hpoints)
4004 (gnus-put-text-property from (point) 'face header-face))
4005 (when (and field-face
4006 (not (memq (setq from (point)) fpoints)))
4008 (if (re-search-forward "^[^ \t]" nil t)
4010 (goto-char (point-max)))
4011 (gnus-put-text-property from (point) 'face field-face))))))))
4013 (defun gnus-article-highlight-signature ()
4014 "Highlight the signature in an article.
4015 It does this by highlighting everything after
4016 `gnus-signature-separator' using `gnus-signature-face'."
4019 (set-buffer gnus-article-buffer)
4020 (let ((buffer-read-only nil)
4021 (inhibit-point-motion-hooks t))
4023 (when (and gnus-signature-face
4024 (gnus-article-narrow-to-signature))
4025 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4026 'face gnus-signature-face)
4028 (gnus-article-search-signature)
4029 (let ((start (match-beginning 0))
4030 (end (set-marker (make-marker) (1+ (match-end 0)))))
4031 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4034 (defun gnus-button-in-region-p (b e prop)
4035 "Say whether PROP exists in the region."
4036 (text-property-not-all b e prop nil))
4038 (defun gnus-article-add-buttons (&optional force)
4039 "Find external references in the article and make buttons of them.
4040 \"External references\" are things like Message-IDs and URLs, as
4041 specified by `gnus-button-alist'."
4042 (interactive (list 'force))
4044 (set-buffer gnus-article-buffer)
4045 (let ((buffer-read-only nil)
4046 (inhibit-point-motion-hooks t)
4047 (case-fold-search t)
4048 (alist gnus-button-alist)
4050 ;; Remove all old markers.
4052 (while (setq marker (pop gnus-button-marker-list))
4054 (when (setq entry (gnus-button-entry))
4055 (put-text-property (match-beginning (nth 1 entry))
4056 (match-end (nth 1 entry))
4057 'gnus-callback nil))
4058 (set-marker marker nil)))
4059 ;; We skip the headers.
4062 (while (setq entry (pop alist))
4063 (setq regexp (car entry))
4065 (while (re-search-forward regexp nil t)
4066 (let* ((start (and entry (match-beginning (nth 1 entry))))
4067 (end (and entry (match-end (nth 1 entry))))
4068 (from (match-beginning 0)))
4069 (when (and (or (eq t (nth 2 entry))
4070 (eval (nth 2 entry)))
4071 (not (gnus-button-in-region-p
4072 start end 'gnus-callback)))
4073 ;; That optional form returned non-nil, so we add the
4075 (gnus-article-add-button
4076 start end 'gnus-button-push
4077 (car (push (set-marker (make-marker) from)
4078 gnus-button-marker-list))))))))))
4080 ;; Add buttons to the head of an article.
4081 (defun gnus-article-add-buttons-to-head ()
4082 "Add buttons to the head of the article."
4085 (set-buffer gnus-article-buffer)
4087 (let ((buffer-read-only nil)
4088 (inhibit-point-motion-hooks t)
4089 (case-fold-search t)
4090 (alist gnus-header-button-alist)
4092 (article-narrow-to-head)
4094 ;; Each alist entry.
4095 (setq entry (car alist)
4097 (goto-char (point-min))
4098 (while (re-search-forward (car entry) nil t)
4099 ;; Each header matching the entry.
4100 (setq beg (match-beginning 0))
4101 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4102 (match-beginning 0))
4105 (while (re-search-forward (nth 1 entry) end t)
4106 ;; Each match within a header.
4107 (let* ((entry (cdr entry))
4108 (start (match-beginning (nth 1 entry)))
4109 (end (match-end (nth 1 entry)))
4110 (form (nth 2 entry)))
4111 (goto-char (match-end 0))
4113 (gnus-article-add-button
4114 start end (nth 3 entry)
4115 (buffer-substring (match-beginning (nth 4 entry))
4116 (match-end (nth 4 entry)))))))
4117 (goto-char end)))))))
4119 ;;; External functions:
4121 (defun gnus-article-add-button (from to fun &optional data)
4122 "Create a button between FROM and TO with callback FUN and data DATA."
4123 (when gnus-article-button-face
4124 (gnus-overlay-put (gnus-make-overlay from to)
4125 'face gnus-article-button-face))
4126 (gnus-add-text-properties
4128 (nconc (and gnus-article-mouse-face
4129 (list gnus-mouse-face-prop gnus-article-mouse-face))
4130 (list 'gnus-callback fun)
4131 (and data (list 'gnus-data data))))
4132 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4133 :button-keymap gnus-widget-button-keymap))
4135 ;;; Internal functions:
4137 (defun gnus-article-set-globals ()
4139 (set-buffer gnus-summary-buffer)
4140 (gnus-set-global-variables)))
4142 (defun gnus-signature-toggle (end)
4144 (set-buffer gnus-article-buffer)
4145 (let ((buffer-read-only nil)
4146 (inhibit-point-motion-hooks t))
4147 (if (get-text-property end 'invisible)
4148 (gnus-article-unhide-text end (point-max))
4149 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4151 (defun gnus-button-entry ()
4152 ;; Return the first entry in `gnus-button-alist' matching this place.
4153 (let ((alist gnus-button-alist)
4156 (setq entry (pop alist))
4157 (if (looking-at (car entry))
4162 (defun gnus-button-push (marker)
4163 ;; Push button starting at MARKER.
4166 (let* ((entry (gnus-button-entry))
4167 (inhibit-point-motion-hooks t)
4169 (args (mapcar (lambda (group)
4170 (let ((string (match-string group)))
4171 (gnus-set-text-properties
4172 0 (length string) nil string)
4179 (fboundp (symbol-value fun)))
4180 (apply (symbol-value fun) args))
4182 (gnus-message 1 "You must define `%S' to use this button"
4183 (cons fun args)))))))
4185 (defun gnus-button-message-id (message-id)
4188 (set-buffer gnus-summary-buffer)
4189 (gnus-summary-refer-article message-id)))
4191 (defun gnus-button-fetch-group (address)
4192 "Fetch GROUP specified by ADDRESS."
4193 (if (not (string-match "[:/]" address))
4194 ;; This is just a simple group url.
4195 (gnus-group-read-ephemeral-group address gnus-select-method)
4196 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4198 (error "Can't parse %s" address)
4199 (gnus-group-read-ephemeral-group
4200 (match-string 4 address)
4201 `(nntp ,(match-string 1 address)
4202 (nntp-address ,(match-string 1 address))
4203 (nntp-port-number ,(if (match-end 3)
4204 (match-string 3 address)
4207 (defun gnus-url-parse-query-string (query &optional downcase)
4208 (let (retval pairs cur key val)
4209 (setq pairs (split-string query "&"))
4211 (setq cur (car pairs)
4213 (if (not (string-match "=" cur))
4215 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4216 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4218 (setq key (downcase key)))
4219 (setq cur (assoc key retval))
4221 (setcdr cur (cons val (cdr cur)))
4222 (setq retval (cons (list key val) retval)))))
4225 (defun gnus-url-unhex (x)
4232 (defun gnus-url-unhex-string (str &optional allow-newlines)
4233 "Remove %XXX embedded spaces, etc in a url.
4234 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4235 decoding of carriage returns and line feeds in the string, which is normally
4236 forbidden in URL encoding."
4237 (setq str (or str ""))
4239 (case-fold-search t))
4240 (while (string-match "%[0-9a-f][0-9a-f]" str)
4241 (let* ((start (match-beginning 0))
4242 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4244 (gnus-url-unhex (elt str (+ start 2))))))
4246 tmp (substring str 0 start)
4249 (char-to-string code))
4250 ((or (= code ?\n) (= code ?\r))
4252 (t (char-to-string code))))
4253 str (substring str (match-end 0)))))
4254 (setq tmp (concat tmp str))
4257 (defun gnus-url-mailto (url)
4258 ;; Send mail to someone
4259 (when (string-match "mailto:/*\\(.*\\)" url)
4260 (setq url (substring url (match-beginning 1) nil)))
4261 (let (to args subject func)
4262 (if (string-match (regexp-quote "?") url)
4263 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4264 args (gnus-url-parse-query-string
4265 (substring url (match-end 0) nil) t))
4266 (setq to (gnus-url-unhex-string url)))
4267 (setq args (cons (list "to" to) args)
4268 subject (cdr-safe (assoc "subject" args)))
4271 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4274 (message-position-on-field (caar args)))
4275 (insert (mapconcat 'identity (cdar args) ", "))
4276 (setq args (cdr args)))
4279 (message-goto-subject))))
4281 (defun gnus-button-mailto (address)
4283 (set-buffer (gnus-copy-article-buffer))
4284 (message-reply address))
4286 (defun gnus-button-reply (address)
4287 ;; Reply to ADDRESS.
4288 (message-reply address))
4290 (defun gnus-button-url (address)
4292 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4293 (if (listp browse-url-browser-function)
4294 (browse-url address)
4295 (funcall browse-url-browser-function address)))
4297 (defun gnus-button-embedded-url (address)
4299 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4300 (if (listp browse-url-browser-function)
4301 (browse-url (gnus-strip-whitespace address))
4302 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4304 ;;; Next/prev buttons in the article buffer.
4306 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4307 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4309 (defvar gnus-prev-page-map nil)
4310 (unless gnus-prev-page-map
4311 (setq gnus-prev-page-map (make-sparse-keymap))
4312 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4313 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4315 (defun gnus-insert-prev-page-button ()
4316 (let ((buffer-read-only nil))
4318 gnus-prev-page-line-format nil
4319 `(gnus-prev t local-map ,gnus-prev-page-map
4320 gnus-callback gnus-article-button-prev-page
4321 article-type annotation))))
4323 (defvar gnus-next-page-map nil)
4324 (unless gnus-next-page-map
4325 (setq gnus-next-page-map (make-keymap))
4326 (suppress-keymap gnus-prev-page-map)
4327 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4328 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4330 (defun gnus-button-next-page ()
4331 "Go to the next page."
4333 (let ((win (selected-window)))
4334 (select-window (get-buffer-window gnus-article-buffer t))
4335 (gnus-article-next-page)
4336 (select-window win)))
4338 (defun gnus-button-prev-page ()
4339 "Go to the prev page."
4341 (let ((win (selected-window)))
4342 (select-window (get-buffer-window gnus-article-buffer t))
4343 (gnus-article-prev-page)
4344 (select-window win)))
4346 (defun gnus-insert-next-page-button ()
4347 (let ((buffer-read-only nil))
4348 (gnus-eval-format gnus-next-page-line-format nil
4350 t local-map ,gnus-next-page-map
4351 gnus-callback gnus-article-button-next-page
4352 article-type annotation))))
4354 (defun gnus-article-button-next-page (arg)
4355 "Go to the next page."
4357 (let ((win (selected-window)))
4358 (select-window (get-buffer-window gnus-article-buffer t))
4359 (gnus-article-next-page)
4360 (select-window win)))
4362 (defun gnus-article-button-prev-page (arg)
4363 "Go to the prev page."
4365 (let ((win (selected-window)))
4366 (select-window (get-buffer-window gnus-article-buffer t))
4367 (gnus-article-prev-page)
4368 (select-window win)))
4370 (defvar gnus-decode-header-methods
4371 '(mail-decode-encoded-word-region)
4372 "List of methods used to decode headers.
4374 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4375 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4376 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4377 whose names match REGEXP.
4380 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4381 mail-decode-encoded-word-region
4382 (\"chinese\" . rfc1843-decode-region))
4385 (defvar gnus-decode-header-methods-cache nil)
4387 (defun gnus-multi-decode-header (start end)
4388 "Apply the functions from `gnus-encoded-word-methods' that match."
4389 (unless (and gnus-decode-header-methods-cache
4390 (eq gnus-newsgroup-name
4391 (car gnus-decode-header-methods-cache)))
4392 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4395 (nconc gnus-decode-header-methods-cache (list x))
4396 (if (and gnus-newsgroup-name
4397 (string-match (car x) gnus-newsgroup-name))
4398 (nconc gnus-decode-header-methods-cache
4400 gnus-decode-header-methods))
4401 (let ((xlist gnus-decode-header-methods-cache))
4404 (narrow-to-region start end)
4406 (funcall (pop xlist) (point-min) (point-max))))))
4409 ;;; Treatment top-level handling.
4412 (defun gnus-treat-article (condition &optional part-number total-parts type)
4413 (let ((length (- (point-max) (point-min)))
4414 (alist gnus-treatment-function-alist)
4415 (article-goto-body-goes-to-point-min-p t)
4419 (let ((list gnus-article-treat-types))
4421 (when (string-match (pop list) type)
4422 (throw 'found t)))))))
4423 (highlightp (gnus-visual-p 'article-highlight 'highlight))
4425 (gnus-run-hooks 'gnus-part-display-hook)
4426 (while (setq elem (pop alist))
4427 (setq val (symbol-value (car elem)))
4428 (when (and (or (consp val)
4430 (gnus-treat-predicate val)
4431 (or (not (get (car elem) 'highlight))
4434 (funcall (cadr elem)))))))
4436 ;; Dynamic variables.
4437 (defvar part-number)
4438 (defvar total-parts)
4442 (defun gnus-treat-predicate (val)
4453 (eq part-number total-parts))
4457 (stringp (car val)))
4458 (apply 'gnus-or (mapcar `(lambda (s)
4459 (string-match s ,(or gnus-newsgroup-name "")))
4462 (let ((pred (pop val)))
4465 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4467 (apply 'gnus-and (mapcar 'gnus-tread-predicate val)))
4469 (not (gnus-treat-predicate val)))
4471 (equal (cadr val) type))
4473 (error "%S is not a valid predicate" pred)))))
4475 (error "%S is not a valid value" val))))
4481 (run-hooks 'gnus-art-load-hook)
4483 ;;; gnus-art.el ends here