1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
41 ;; Avoid byte-compile warnings.
43 (defvar gnus-article-decoded-p)
44 (defvar gnus-article-mime-handles)
53 (defgroup gnus-article nil
55 :link '(custom-manual "(gnus)The Article Buffer")
58 (defgroup gnus-article-treat nil
59 "Treating article parts."
60 :link '(custom-manual "(gnus)Article Hiding")
63 (defgroup gnus-article-hiding nil
64 "Hiding article parts."
65 :link '(custom-manual "(gnus)Article Hiding")
68 (defgroup gnus-article-highlight nil
69 "Article highlighting."
70 :link '(custom-manual "(gnus)Article Highlighting")
74 (defgroup gnus-article-signature nil
76 :link '(custom-manual "(gnus)Article Signature")
79 (defgroup gnus-article-headers nil
81 :link '(custom-manual "(gnus)Hiding Headers")
84 (defgroup gnus-article-washing nil
85 "Special commands on articles."
86 :link '(custom-manual "(gnus)Article Washing")
89 (defgroup gnus-article-emphasis nil
90 "Fontisizing articles."
91 :link '(custom-manual "(gnus)Article Fontisizing")
94 (defgroup gnus-article-saving nil
96 :link '(custom-manual "(gnus)Saving Articles")
99 (defgroup gnus-article-mime nil
100 "Worshiping the MIME wonder."
101 :link '(custom-manual "(gnus)Using MIME")
102 :group 'gnus-article)
104 (defgroup gnus-article-buttons nil
105 "Pushable buttons in the article buffer."
106 :link '(custom-manual "(gnus)Article Buttons")
107 :group 'gnus-article)
109 (defgroup gnus-article-various nil
110 "Other article options."
111 :link '(custom-manual "(gnus)Misc Article")
112 :group 'gnus-article)
114 (defcustom gnus-ignored-headers
115 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
116 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
117 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
118 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
119 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
120 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
121 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
122 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
123 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
124 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
125 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
126 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
127 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
128 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
129 "^Old-Received:" "^X-Pgp-Fingerprint:" "^X-Pgp-Key-Id:"
130 "^X-Pgp-Public-Key-Url:" "^X-Auth:" "^X-From-Line:"
131 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
132 "^X-Mailing-List:" "^MBOX-Line" "^Priority:" "^X-Pgp" "^X400-[-A-Za-z]+:"
134 "*All headers that start with this regexp will be hidden.
135 This variable can also be a list of regexps of headers to be ignored.
136 If `gnus-visible-headers' is non-nil, this variable will be ignored."
137 :type '(choice :custom-show nil
140 :group 'gnus-article-hiding)
142 (defcustom gnus-visible-headers
143 "^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:"
144 "*All headers that do not match this regexp will be hidden.
145 This variable can also be a list of regexp of headers to remain visible.
146 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
147 :type '(repeat :value-to-internal (lambda (widget value)
148 (custom-split-regexp-maybe value))
149 :match (lambda (widget value)
151 (widget-editable-list-match widget value)))
153 :group 'gnus-article-hiding)
155 (defcustom gnus-sorted-header-list
156 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
157 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
158 "*This variable is a list of regular expressions.
159 If it is non-nil, headers that match the regular expressions will
160 be placed first in the article buffer in the sequence specified by
162 :type '(repeat regexp)
163 :group 'gnus-article-hiding)
165 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
166 "Headers that are only to be displayed if they have interesting data.
167 Possible values in this list are `empty', `newsgroups', `followup-to',
168 `reply-to', `date', `long-to', and `many-to'."
169 :type '(set (const :tag "Headers with no content." empty)
170 (const :tag "Newsgroups with only one group." newsgroups)
171 (const :tag "Followup-to identical to newsgroups." followup-to)
172 (const :tag "Reply-to identical to from." reply-to)
173 (const :tag "Date less than four days old." date)
174 (const :tag "Very long To header." long-to)
175 (const :tag "Multiple To headers." many-to))
176 :group 'gnus-article-hiding)
178 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
179 "Regexp matching signature separator.
180 This can also be a list of regexps. In that case, it will be checked
181 from head to tail looking for a separator. Searches will be done from
182 the end of the buffer."
183 :type '(repeat string)
184 :group 'gnus-article-signature)
186 (defcustom gnus-signature-limit nil
187 "Provide a limit to what is considered a signature.
188 If it is a number, no signature may not be longer (in characters) than
189 that number. If it is a floating point number, no signature may be
190 longer (in lines) than that number. If it is a function, the function
191 will be called without any parameters, and if it returns nil, there is
192 no signature in the buffer. If it is a string, it will be used as a
193 regexp. If it matches, the text in question is not a signature."
194 :type '(choice (integer :value 200)
196 (function :value fun)
197 (regexp :value ".*"))
198 :group 'gnus-article-signature)
200 (defcustom gnus-hidden-properties '(invisible t intangible t)
201 "Property list to use for hiding text."
203 :group 'gnus-article-hiding)
205 (defcustom gnus-article-x-face-command
206 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
207 "*String or function to be executed to display an X-Face header.
208 If it is a string, the command will be executed in a sub-shell
209 asynchronously. The compressed face will be piped to this command."
210 :type 'string ;Leave function case to Lisp.
211 :group 'gnus-article-washing)
213 (defcustom gnus-article-x-face-too-ugly nil
214 "Regexp matching posters whose face shouldn't be shown automatically."
215 :type '(choice regexp (const nil))
216 :group 'gnus-article-washing)
218 (defcustom gnus-emphasis-alist
220 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\|\\s)\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"]\\|\\s(\\|\\s)\\)")
222 '(("_" "_" underline)
225 ("_/" "/_" underline-italic)
226 ("_\\*" "\\*_" underline-bold)
227 ("\\*/" "/\\*" bold-italic)
228 ("_\\*/" "/\\*_" underline-bold-italic))))
229 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
230 2 3 gnus-emphasis-underline)
234 (format format (car spec) (cadr spec))
235 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
237 "*Alist that says how to fontify certain phrases.
238 Each item looks like this:
240 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
242 The first element is a regular expression to be matched. The second
243 is a number that says what regular expression grouping used to find
244 the entire emphasized word. The third is a number that says what
245 regexp grouping should be displayed and highlighted. The fourth
246 is the face used for highlighting."
247 :type '(repeat (list :value ("" 0 0 default)
249 (integer :tag "Match group")
250 (integer :tag "Emphasize group")
252 :group 'gnus-article-emphasis)
254 (defface gnus-emphasis-bold '((t (:bold t)))
255 "Face used for displaying strong emphasized text (*word*)."
256 :group 'gnus-article-emphasis)
258 (defface gnus-emphasis-italic '((t (:italic t)))
259 "Face used for displaying italic emphasized text (/word/)."
260 :group 'gnus-article-emphasis)
262 (defface gnus-emphasis-underline '((t (:underline t)))
263 "Face used for displaying underlined emphasized text (_word_)."
264 :group 'gnus-article-emphasis)
266 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
267 "Face used for displaying underlined bold emphasized text (_*word*_)."
268 :group 'gnus-article-emphasis)
270 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
271 "Face used for displaying underlined italic emphasized text (_*word*_)."
272 :group 'gnus-article-emphasis)
274 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
275 "Face used for displaying bold italic emphasized text (/*word*/)."
276 :group 'gnus-article-emphasis)
278 (defface gnus-emphasis-underline-bold-italic
279 '((t (:bold t :italic t :underline t)))
280 "Face used for displaying underlined bold italic emphasized text.
281 Esample: (_/*word*/_)."
282 :group 'gnus-article-emphasis)
284 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
285 "Format for display of Date headers in article bodies.
286 See `format-time-string' for the possible values.
288 The variable can also be function, which should return a complete Date
289 header. The function is called with one argument, the time, which can
290 be fed to `format-time-string'."
291 :type '(choice string symbol)
292 :link '(custom-manual "(gnus)Article Date")
293 :group 'gnus-article-washing)
296 (autoload 'mail-extract-address-components "mail-extr"))
298 (defcustom gnus-save-all-headers t
299 "*If non-nil, don't remove any headers before saving."
300 :group 'gnus-article-saving
303 (defcustom gnus-prompt-before-saving 'always
304 "*This variable says how much prompting is to be done when saving articles.
305 If it is nil, no prompting will be done, and the articles will be
306 saved to the default files. If this variable is `always', each and
307 every article that is saved will be preceded by a prompt, even when
308 saving large batches of articles. If this variable is neither nil not
309 `always', there the user will be prompted once for a file name for
310 each invocation of the saving commands."
311 :group 'gnus-article-saving
312 :type '(choice (item always)
313 (item :tag "never" nil)
314 (sexp :tag "once" :format "%t\n" :value t)))
316 (defcustom gnus-saved-headers gnus-visible-headers
317 "Headers to keep if `gnus-save-all-headers' is nil.
318 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
319 If that variable is nil, however, all headers that match this regexp
320 will be kept while the rest will be deleted before saving."
321 :group 'gnus-article-saving
324 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
325 "A function to save articles in your favourite format.
326 The function must be interactively callable (in other words, it must
327 be an Emacs command).
329 Gnus provides the following functions:
331 * gnus-summary-save-in-rmail (Rmail format)
332 * gnus-summary-save-in-mail (Unix mail format)
333 * gnus-summary-save-in-folder (MH folder)
334 * gnus-summary-save-in-file (article format)
335 * gnus-summary-save-in-vm (use VM's folder format)
336 * gnus-summary-write-to-file (article format -- overwrite)."
337 :group 'gnus-article-saving
338 :type '(radio (function-item gnus-summary-save-in-rmail)
339 (function-item gnus-summary-save-in-mail)
340 (function-item gnus-summary-save-in-folder)
341 (function-item gnus-summary-save-in-file)
342 (function-item gnus-summary-save-in-vm)
343 (function-item gnus-summary-write-to-file)))
345 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
346 "A function generating a file name to save articles in Rmail format.
347 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
348 :group 'gnus-article-saving
351 (defcustom gnus-mail-save-name 'gnus-plain-save-name
352 "A function generating a file name to save articles in Unix mail format.
353 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
354 :group 'gnus-article-saving
357 (defcustom gnus-folder-save-name 'gnus-folder-save-name
358 "A function generating a file name to save articles in MH folder.
359 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
360 :group 'gnus-article-saving
363 (defcustom gnus-file-save-name 'gnus-numeric-save-name
364 "A function generating a file name to save articles in article format.
365 The function is called with NEWSGROUP, HEADERS, and optional
367 :group 'gnus-article-saving
370 (defcustom gnus-split-methods
371 '((gnus-article-archive-name)
372 (gnus-article-nndoc-name))
373 "*Variable used to suggest where articles are to be saved.
374 For instance, if you would like to save articles related to Gnus in
375 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
376 you could set this variable to something like:
378 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
379 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
381 This variable is an alist where the where the key is the match and the
382 value is a list of possible files to save in if the match is non-nil.
384 If the match is a string, it is used as a regexp match on the
385 article. If the match is a symbol, that symbol will be funcalled
386 from the buffer of the article to be saved with the newsgroup as the
387 parameter. If it is a list, it will be evaled in the same buffer.
389 If this form or function returns a string, this string will be used as
390 a possible file name; and if it returns a non-nil list, that list will
391 be used as possible file names."
392 :group 'gnus-article-saving
393 :type '(repeat (choice (list :value (fun) function)
394 (cons :value ("" "") regexp (repeat string))
397 (defcustom gnus-article-display-method-for-mime
398 'gnus-article-display-mime-message
399 "Function to display a MIME message.
400 The function is called from the article buffer."
401 :group 'gnus-article-mime
404 (defcustom gnus-article-display-method-for-traditional
405 'gnus-article-display-traditional-message
406 "*Function to display a traditional message.
407 The function is called from the article buffer."
408 :group 'gnus-article-mime
411 (defcustom gnus-page-delimiter "^\^L"
412 "*Regexp describing what to use as article page delimiters.
413 The default value is \"^\^L\", which is a form linefeed at the
414 beginning of a line."
416 :group 'gnus-article-various)
418 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
419 "*The format specification for the article mode line.
420 See `gnus-summary-mode-line-format' for a closer description.
422 The following additional specs are available:
424 %w The article washing status.
425 %m The number of MIME parts in the article."
427 :group 'gnus-article-various)
429 (defcustom gnus-article-mode-hook nil
430 "*A hook for Gnus article mode."
432 :group 'gnus-article-various)
434 (defcustom gnus-article-menu-hook nil
435 "*Hook run after the creation of the article mode menu."
437 :group 'gnus-article-various)
439 (defcustom gnus-article-prepare-hook nil
440 "*A hook called after an article has been prepared in the article buffer."
442 :group 'gnus-article-various)
444 (defcustom gnus-article-hide-pgp-hook nil
445 "*A hook called after successfully hiding a PGP signature."
447 :group 'gnus-article-various)
449 (defcustom gnus-article-button-face 'bold
450 "Face used for highlighting buttons in the article buffer.
452 An article button is a piece of text that you can activate by pressing
453 `RET' or `mouse-2' above it."
455 :group 'gnus-article-buttons)
457 (defcustom gnus-article-mouse-face 'highlight
458 "Face used for mouse highlighting in the article buffer.
460 Article buttons will be displayed in this face when the cursor is
463 :group 'gnus-article-buttons)
465 (defcustom gnus-signature-face 'gnus-signature-face
466 "Face used for highlighting a signature in the article buffer.
467 Obsolete; use the face `gnus-signature-face' for customizations instead."
469 :group 'gnus-article-highlight
470 :group 'gnus-article-signature)
472 (defface gnus-signature-face
475 "Face used for highlighting a signature in the article buffer."
476 :group 'gnus-article-highlight
477 :group 'gnus-article-signature)
479 (defface gnus-header-from-face
482 (:foreground "spring green"))
485 (:foreground "red3"))
488 "Face used for displaying from headers."
489 :group 'gnus-article-headers
490 :group 'gnus-article-highlight)
492 (defface gnus-header-subject-face
495 (:foreground "SeaGreen3"))
498 (:foreground "red4"))
500 (:bold t :italic t)))
501 "Face used for displaying subject headers."
502 :group 'gnus-article-headers
503 :group 'gnus-article-highlight)
505 (defface gnus-header-newsgroups-face
508 (:foreground "yellow" :italic t))
511 (:foreground "MidnightBlue" :italic t))
514 "Face used for displaying newsgroups headers."
515 :group 'gnus-article-headers
516 :group 'gnus-article-highlight)
518 (defface gnus-header-name-face
521 (:foreground "SeaGreen"))
524 (:foreground "maroon"))
527 "Face used for displaying header names."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defface gnus-header-content-face
534 (:foreground "forest green" :italic t))
537 (:foreground "indianred4" :italic t))
539 (:italic t))) "Face used for displaying header content."
540 :group 'gnus-article-headers
541 :group 'gnus-article-highlight)
543 (defcustom gnus-header-face-alist
544 '(("From" nil gnus-header-from-face)
545 ("Subject" nil gnus-header-subject-face)
546 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
547 ("" gnus-header-name-face gnus-header-content-face))
548 "*Controls highlighting of article header.
550 An alist of the form (HEADER NAME CONTENT).
552 HEADER is a regular expression which should match the name of an
553 header header and NAME and CONTENT are either face names or nil.
555 The name of each header field will be displayed using the face
556 specified by the first element in the list where HEADER match the
557 header name and NAME is non-nil. Similarly, the content will be
558 displayed by the first non-nil matching CONTENT face."
559 :group 'gnus-article-headers
560 :group 'gnus-article-highlight
561 :type '(repeat (list (regexp :tag "Header")
563 (item :tag "skip" nil)
564 (face :value default))
565 (choice :tag "Content"
566 (item :tag "skip" nil)
567 (face :value default)))))
569 (defcustom gnus-article-decode-hook nil
570 "*Hook run to decode charsets in articles."
571 :group 'gnus-article-headers
574 (defcustom gnus-display-mime-function 'gnus-display-mime
575 "Function to display MIME articles."
576 :group 'gnus-article-mime
579 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
580 "Function used to decode headers.")
582 (defvar gnus-article-dumbquotes-map
600 "Table for MS-to-Latin1 translation.")
602 (defcustom gnus-ignored-mime-types nil
603 "List of MIME types that should be ignored by Gnus."
604 :group 'gnus-article-mime
605 :type '(repeat regexp))
607 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
608 "List of MIME types that should not be given buttons when rendered."
609 :group 'gnus-article-mime
610 :type '(repeat regexp))
612 (defcustom gnus-article-mime-part-function nil
613 "Function called with a MIME handle as the argument.
614 This is meant for people who want to do something automatic based
615 on parts -- for instance, adding Vcard info to a database."
616 :group 'gnus-article-mime
620 ;;; The treatment variables
623 (defvar gnus-part-display-hook nil
624 "Hook called on parts that are to receive treatment.")
626 (defvar gnus-article-treat-custom
627 '(choice (const :tag "Off" nil)
629 (const :tag "Header" head)
630 (const :tag "Last" last)
631 (integer :tag "Less")
632 (sexp :tag "Predicate")))
634 (defvar gnus-article-treat-head-custom
635 '(choice (const :tag "Off" nil)
636 (const :tag "Header" head)))
638 (defvar gnus-article-treat-types '("text/plain")
641 (defvar gnus-inhibit-treatment nil
642 "Whether to inhibit treatment.")
644 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
645 "Highlight the signature."
646 :group 'gnus-article-treat
647 :type gnus-article-treat-custom)
649 (defcustom gnus-treat-buttonize t
651 :group 'gnus-article-treat
652 :type gnus-article-treat-custom)
654 (defcustom gnus-treat-buttonize-head 'head
655 "Add buttons to the head."
656 :group 'gnus-article-treat
657 :type gnus-article-treat-head-custom)
659 (defcustom gnus-treat-emphasize t
661 :group 'gnus-article-treat
662 :type gnus-article-treat-custom)
664 (defcustom gnus-treat-strip-cr nil
665 "Remove carriage returns."
666 :group 'gnus-article-treat
667 :type gnus-article-treat-custom)
669 (defcustom gnus-treat-hide-headers 'head
671 :group 'gnus-article-treat
672 :type gnus-article-treat-head-custom)
674 (defcustom gnus-treat-hide-boring-headers nil
675 "Hide boring headers."
676 :group 'gnus-article-treat
677 :type gnus-article-treat-head-custom)
679 (defcustom gnus-treat-hide-signature nil
680 "Hide the signature."
681 :group 'gnus-article-treat
682 :type gnus-article-treat-custom)
684 (defcustom gnus-treat-fill-article nil
686 :group 'gnus-article-treat
687 :type gnus-article-treat-custom)
689 (defcustom gnus-treat-hide-citation nil
691 :group 'gnus-article-treat
692 :type gnus-article-treat-custom)
694 (defcustom gnus-treat-strip-pgp t
695 "Strip PGP signatures."
696 :group 'gnus-article-treat
697 :type gnus-article-treat-custom)
699 (defcustom gnus-treat-strip-pem nil
700 "Strip PEM signatures."
701 :group 'gnus-article-treat
702 :type gnus-article-treat-custom)
704 (defcustom gnus-treat-strip-banner t
705 "Strip banners from articles.
706 The banner to be stripped is specified in the `banner' group parameter."
707 :group 'gnus-article-treat
708 :type gnus-article-treat-custom)
710 (defcustom gnus-treat-highlight-headers 'head
711 "Highlight the headers."
712 :group 'gnus-article-treat
713 :type gnus-article-treat-head-custom)
715 (defcustom gnus-treat-highlight-citation t
716 "Highlight cited text."
717 :group 'gnus-article-treat
718 :type gnus-article-treat-custom)
720 (defcustom gnus-treat-date-ut nil
721 "Display the Date in UT (GMT)."
722 :group 'gnus-article-treat
723 :type gnus-article-treat-head-custom)
725 (defcustom gnus-treat-date-local nil
726 "Display the Date in the local timezone."
727 :group 'gnus-article-treat
728 :type gnus-article-treat-head-custom)
730 (defcustom gnus-treat-date-lapsed nil
731 "Display the Date header in a way that says how much time has elapsed."
732 :group 'gnus-article-treat
733 :type gnus-article-treat-head-custom)
735 (defcustom gnus-treat-date-original nil
736 "Display the date in the original timezone."
737 :group 'gnus-article-treat
738 :type gnus-article-treat-head-custom)
740 (defcustom gnus-treat-date-iso8601 nil
741 "Display the date in the ISO8601 format."
742 :group 'gnus-article-treat
743 :type gnus-article-treat-head-custom)
745 (defcustom gnus-treat-date-user-defined nil
746 "Display the date in a user-defined format.
747 The format is defined by the `gnus-article-time-format' variable."
748 :group 'gnus-article-treat
749 :type gnus-article-treat-head-custom)
751 (defcustom gnus-treat-strip-trailing-blank-lines nil
752 "Strip trailing blank lines."
753 :group 'gnus-article-treat
754 :type gnus-article-treat-custom)
756 (defcustom gnus-treat-strip-leading-blank-lines nil
757 "Strip leading blank lines."
758 :group 'gnus-article-treat
759 :type gnus-article-treat-custom)
761 (defcustom gnus-treat-strip-multiple-blank-lines nil
762 "Strip multiple blank lines."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-custom)
766 (defcustom gnus-treat-strip-blank-lines nil
767 "Strip all blank lines."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-custom)
771 (defcustom gnus-treat-overstrike t
772 "Treat overstrike highlighting."
773 :group 'gnus-article-treat
774 :type gnus-article-treat-custom)
776 (defcustom gnus-treat-display-xface (if (and gnus-xemacs (featurep 'xface))
778 "Display X-Face headers."
779 :group 'gnus-article-treat
780 :type gnus-article-treat-head-custom)
782 (defcustom gnus-treat-display-smileys (if (and gnus-xemacs
786 :group 'gnus-article-treat
787 :type gnus-article-treat-custom)
789 (defcustom gnus-treat-display-picons (if gnus-xemacs 'head nil)
791 :group 'gnus-article-treat
792 :type gnus-article-treat-head-custom)
794 (defcustom gnus-treat-capitalize-sentences nil
795 "Capitalize sentence-starting words."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
799 (defcustom gnus-treat-fill-long-lines nil
801 :group 'gnus-article-treat
802 :type gnus-article-treat-custom)
804 (defcustom gnus-treat-play-sounds nil
806 :group 'gnus-article-treat
807 :type gnus-article-treat-custom)
809 ;;; Internal variables
811 (defvar article-goto-body-goes-to-point-min-p nil)
812 (defvar gnus-article-wash-types nil)
814 (defvar gnus-article-mime-handle-alist-1 nil)
815 (defvar gnus-treatment-function-alist
816 '((gnus-treat-strip-banner gnus-article-strip-banner)
817 (gnus-treat-highlight-signature gnus-article-highlight-signature)
818 (gnus-treat-buttonize gnus-article-add-buttons)
819 (gnus-treat-fill-article gnus-article-fill-cited-article)
820 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
821 (gnus-treat-strip-cr gnus-article-remove-cr)
822 (gnus-treat-hide-headers gnus-article-hide-headers)
823 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
824 (gnus-treat-hide-signature gnus-article-hide-signature)
825 (gnus-treat-hide-citation gnus-article-hide-citation)
826 (gnus-treat-strip-pgp gnus-article-hide-pgp)
827 (gnus-treat-strip-pem gnus-article-hide-pem)
828 (gnus-treat-highlight-headers gnus-article-highlight-headers)
829 (gnus-treat-highlight-citation gnus-article-highlight-citation)
830 (gnus-treat-highlight-signature gnus-article-highlight-signature)
831 (gnus-treat-emphasize gnus-article-emphasize)
832 (gnus-treat-date-ut gnus-article-date-ut)
833 (gnus-treat-date-local gnus-article-date-local)
834 (gnus-treat-date-lapsed gnus-article-date-lapsed)
835 (gnus-treat-date-original gnus-article-date-original)
836 (gnus-treat-date-user-defined gnus-article-date-user)
837 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
838 (gnus-treat-strip-trailing-blank-lines
839 gnus-article-remove-trailing-blank-lines)
840 (gnus-treat-strip-leading-blank-lines
841 gnus-article-strip-leading-blank-lines)
842 (gnus-treat-strip-multiple-blank-lines
843 gnus-article-strip-multiple-blank-lines)
844 (gnus-treat-strip-blank-lines gnus-article-strip-blank-lines)
845 (gnus-treat-overstrike gnus-article-treat-overstrike)
846 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
847 (gnus-treat-display-xface gnus-article-display-x-face)
848 (gnus-treat-display-smileys gnus-smiley-display)
849 (gnus-treat-display-picons gnus-article-display-picons)
850 (gnus-treat-play-sounds gnus-earcon-display)))
852 (defvar gnus-article-mime-handle-alist nil)
853 (defvar article-lapsed-timer nil)
854 (defvar gnus-article-current-summary nil)
856 (defvar gnus-article-mode-syntax-table
857 (let ((table (copy-syntax-table text-mode-syntax-table)))
858 (modify-syntax-entry ?- "w" table)
859 (modify-syntax-entry ?> ")" table)
860 (modify-syntax-entry ?< "(" table)
862 "Syntax table used in article mode buffers.
863 Initialized from `text-mode-syntax-table.")
865 (defvar gnus-save-article-buffer nil)
867 (defvar gnus-article-mode-line-format-alist
868 (nconc '((?w (gnus-article-wash-status) ?s)
869 (?m (gnus-article-mime-part-status) ?s))
870 gnus-summary-mode-line-format-alist))
872 (defvar gnus-number-of-articles-to-be-saved nil)
874 (defvar gnus-inhibit-hiding nil)
876 (defsubst gnus-article-hide-text (b e props)
877 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
878 (add-text-properties b e props)
879 (when (memq 'intangible props)
881 (max (1- b) (point-min))
882 b 'intangible (cddr (memq 'intangible props)))))
884 (defmacro gnus-with-article (article &rest forms)
885 "Select ARTICLE and perform FORMS in the original article buffer.
886 Then replace the article with the result."
888 ;; We don't want the article to be marked as read.
889 (let (gnus-mark-article-hook)
890 (gnus-summary-select-article t t nil ,article))
891 (set-buffer gnus-original-article-buffer)
893 (if (not (gnus-check-backend-function
894 'request-replace-article (car gnus-article-current)))
895 (gnus-message 5 "Read-only group; not replacing")
896 (unless (gnus-request-replace-article
897 ,article (car gnus-article-current)
899 (error "Couldn't replace article")))
900 ;; The cache and backlog have to be flushed somewhat.
901 (when gnus-keep-backlog
902 (gnus-backlog-remove-article
903 (car gnus-article-current) (cdr gnus-article-current)))
905 (gnus-cache-update-article
906 (car gnus-article-current) (cdr gnus-article-current)))))
908 (put 'gnus-with-article 'lisp-indent-function 1)
909 (put 'gnus-with-article 'edebug-form-spec '(form body))
911 (defsubst gnus-article-unhide-text (b e)
912 "Remove hidden text properties from region between B and E."
913 (remove-text-properties b e gnus-hidden-properties)
914 (when (memq 'intangible gnus-hidden-properties)
915 (put-text-property (max (1- b) (point-min))
918 (defun gnus-article-hide-text-type (b e type)
919 "Hide text of TYPE between B and E."
920 (push type gnus-article-wash-types)
921 (gnus-article-hide-text
922 b e (cons 'article-type (cons type gnus-hidden-properties))))
924 (defun gnus-article-unhide-text-type (b e type)
925 "Unhide text of TYPE between B and E."
926 (setq gnus-article-wash-types
927 (delq type gnus-article-wash-types))
928 (remove-text-properties
929 b e (cons 'article-type (cons type gnus-hidden-properties)))
930 (when (memq 'intangible gnus-hidden-properties)
931 (put-text-property (max (1- b) (point-min))
934 (defun gnus-article-hide-text-of-type (type)
935 "Hide text of TYPE in the current buffer."
937 (let ((b (point-min))
939 (while (setq b (text-property-any b e 'article-type type))
940 (add-text-properties b (incf b) gnus-hidden-properties)))))
942 (defun gnus-article-delete-text-of-type (type)
943 "Delete text of TYPE in the current buffer."
945 (let ((b (point-min)))
946 (while (setq b (text-property-any b (point-max) 'article-type type))
948 b (or (text-property-not-all b (point-max) 'article-type type)
951 (defun gnus-article-delete-invisible-text ()
952 "Delete all invisible text in the current buffer."
954 (let ((b (point-min)))
955 (while (setq b (text-property-any b (point-max) 'invisible t))
957 b (or (text-property-not-all b (point-max) 'invisible t)
960 (defun gnus-article-text-type-exists-p (type)
961 "Say whether any text of type TYPE exists in the buffer."
962 (text-property-any (point-min) (point-max) 'article-type type))
964 (defsubst gnus-article-header-rank ()
965 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
966 (let ((list gnus-sorted-header-list)
969 (when (looking-at (car list))
971 (setq list (cdr list))
975 (defun article-hide-headers (&optional arg delete)
976 "Toggle whether to hide unwanted headers and possibly sort them as well.
977 If given a negative prefix, always show; if given a positive prefix,
979 (interactive (gnus-article-hidden-arg))
981 (if (gnus-article-check-hidden-text 'headers arg)
982 ;; Show boring headers as well.
984 (gnus-article-show-hidden-text 'boring-headers)
985 (when (eq 1 (point-min))
986 (set-window-start (get-buffer-window (current-buffer)) 1)))
987 ;; This function might be inhibited.
988 (unless gnus-inhibit-hiding
991 (let ((buffer-read-only nil)
993 (props (nconc (list 'article-type 'headers)
994 gnus-hidden-properties))
995 (max (1+ (length gnus-sorted-header-list)))
996 (ignored (when (not gnus-visible-headers)
997 (cond ((stringp gnus-ignored-headers)
998 gnus-ignored-headers)
999 ((listp gnus-ignored-headers)
1000 (mapconcat 'identity gnus-ignored-headers
1003 (cond ((stringp gnus-visible-headers)
1004 gnus-visible-headers)
1005 ((and gnus-visible-headers
1006 (listp gnus-visible-headers))
1007 (mapconcat 'identity gnus-visible-headers "\\|"))))
1008 (inhibit-point-motion-hooks t)
1010 ;; First we narrow to just the headers.
1011 (goto-char (point-min))
1012 ;; Hide any "From " lines at the beginning of (mail) articles.
1013 (while (looking-at "From ")
1017 (delete-region (point-min) (point))
1018 (gnus-article-hide-text (point-min) (point) props)))
1019 ;; Then treat the rest of the header lines.
1022 (if (search-forward "\n\n" nil t) ; if there's a body
1023 (progn (forward-line -1) (point))
1025 ;; Then we use the two regular expressions
1026 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1027 ;; select which header lines is to remain visible in the
1029 (goto-char (point-min))
1030 (while (re-search-forward "^[^ \t]*:" nil t)
1032 ;; Mark the rank of the header.
1034 (point) (1+ (point)) 'message-rank
1035 (if (or (and visible (looking-at visible))
1037 (not (looking-at ignored))))
1038 (gnus-article-header-rank)
1041 (message-sort-headers-1)
1042 (when (setq beg (text-property-any
1043 (point-min) (point-max) 'message-rank (+ 2 max)))
1044 ;; We make the unwanted headers invisible.
1046 (delete-region beg (point-max))
1047 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
1048 (gnus-article-hide-text-type beg (point-max) 'headers))
1049 ;; Work around XEmacs lossage.
1050 (put-text-property (point-min) beg 'invisible nil))))))))
1052 (defun article-hide-boring-headers (&optional arg)
1053 "Toggle hiding of headers that aren't very interesting.
1054 If given a negative prefix, always show; if given a positive prefix,
1056 (interactive (gnus-article-hidden-arg))
1057 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1058 (not gnus-show-all-headers))
1061 (let ((buffer-read-only nil)
1062 (list gnus-boring-article-headers)
1063 (inhibit-point-motion-hooks t)
1065 (article-narrow-to-head)
1067 (setq elem (pop list))
1068 (goto-char (point-min))
1070 ;; Hide empty headers.
1072 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t)
1074 (gnus-article-hide-text-type
1075 (progn (beginning-of-line) (point))
1078 (if (re-search-forward "^[^ \t]" nil t)
1082 ;; Hide boring Newsgroups header.
1083 ((eq elem 'newsgroups)
1084 (when (equal (gnus-fetch-field "newsgroups")
1085 (gnus-group-real-name
1086 (if (boundp 'gnus-newsgroup-name)
1089 (gnus-article-hide-header "newsgroups")))
1090 ((eq elem 'followup-to)
1091 (when (equal (message-fetch-field "followup-to")
1092 (message-fetch-field "newsgroups"))
1093 (gnus-article-hide-header "followup-to")))
1094 ((eq elem 'reply-to)
1095 (let ((from (message-fetch-field "from"))
1096 (reply-to (message-fetch-field "reply-to")))
1101 (nth 1 (funcall gnus-extract-address-components from))
1102 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1103 (gnus-article-hide-header "reply-to"))))
1105 (let ((date (message-fetch-field "date")))
1107 (< (days-between (current-time-string) date)
1109 (gnus-article-hide-header "date"))))
1111 (let ((to (message-fetch-field "to")))
1112 (when (> (length to) 1024)
1113 (gnus-article-hide-header "to"))))
1116 (goto-char (point-min))
1117 (while (re-search-forward "^to:" nil t)
1118 (setq to-count (1+ to-count)))
1119 (when (> to-count 1)
1120 (while (> to-count 0)
1121 (goto-char (point-min))
1123 (re-search-forward "^to:" nil nil to-count)
1125 (narrow-to-region (point) (point-max))
1126 (gnus-article-hide-header "to"))
1127 (setq to-count (1- to-count)))))))))))))
1129 (defun gnus-article-hide-header (header)
1131 (goto-char (point-min))
1132 (when (re-search-forward (concat "^" header ":") nil t)
1133 (gnus-article-hide-text-type
1134 (progn (beginning-of-line) (point))
1137 (if (re-search-forward "^[^ \t]" nil t)
1142 (defvar gnus-article-normalized-header-length 40
1143 "Length of normalized headers.")
1145 (defun article-normalize-headers ()
1146 "Make all header lines 40 characters long."
1148 (let ((buffer-read-only nil)
1152 (article-narrow-to-head)
1155 ((< (setq column (- (gnus-point-at-eol) (point)))
1156 gnus-article-normalized-header-length)
1158 (insert (make-string
1159 (- gnus-article-normalized-header-length column)
1161 ((> column gnus-article-normalized-header-length)
1162 (gnus-put-text-property
1164 (forward-char gnus-article-normalized-header-length)
1171 (forward-line 1))))))
1173 (defun article-treat-dumbquotes ()
1174 "Translate M******** sm*rtq**t*s into proper text.
1175 Note that this function guesses whether a character is a sm*rtq**t* or
1176 not, so it should only be used interactively."
1178 (article-translate-strings gnus-article-dumbquotes-map))
1180 (defun article-translate-characters (from to)
1181 "Translate all characters in the body of the article according to FROM and TO.
1182 FROM is a string of characters to translate from; to is a string of
1183 characters to translate to."
1185 (when (article-goto-body)
1186 (let ((buffer-read-only nil)
1187 (x (make-string 225 ?x))
1189 (while (< (incf i) (length x))
1192 (while (< i (length from))
1193 (aset x (aref from i) (aref to i))
1195 (translate-region (point) (point-max) x)))))
1197 (defun article-translate-strings (map)
1198 "Translate all string in the body of the article according to MAP.
1199 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1201 (when (article-goto-body)
1202 (let ((buffer-read-only nil)
1204 (while (setq elem (pop map))
1206 (while (search-forward (car elem) nil t)
1207 (replace-match (cadr elem)))))))))
1209 (defun article-treat-overstrike ()
1210 "Translate overstrikes into bold text."
1213 (when (article-goto-body)
1214 (let ((buffer-read-only nil))
1215 (while (search-forward "\b" nil t)
1216 (let ((next (char-after))
1217 (previous (char-after (- (point) 2))))
1218 ;; We do the boldification/underlining by hiding the
1219 ;; overstrikes and putting the proper text property
1223 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1224 (put-text-property (point) (1+ (point)) 'face 'bold))
1226 (gnus-article-hide-text-type
1227 (1- (point)) (1+ (point)) 'overstrike)
1229 (- (point) 2) (1- (point)) 'face 'underline))
1231 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1233 (point) (1+ (point)) 'face 'underline)))))))))
1235 (defun article-fill-long-lines ()
1236 "Fill lines that are wider than the window width."
1239 (let ((buffer-read-only nil)
1240 (width (window-width (get-buffer-window (current-buffer)))))
1243 (let ((adaptive-fill-mode nil))
1246 (when (>= (current-column) (min fill-column width))
1247 (narrow-to-region (point) (gnus-point-at-bol))
1248 (fill-paragraph nil)
1249 (goto-char (point-max))
1251 (forward-line 1)))))))
1253 (defun article-capitalize-sentences ()
1254 "Capitalize the first word in each sentence."
1257 (let ((buffer-read-only nil)
1258 (paragraph-start "^[\n\^L]"))
1262 (forward-sentence)))))
1264 (defun article-remove-cr ()
1265 "Translate CRLF pairs into LF, and then CR into LF.."
1268 (let ((buffer-read-only nil))
1269 (goto-char (point-min))
1270 (while (search-forward "\r$" nil t)
1271 (replace-match "" t t))
1272 (goto-char (point-min))
1273 (while (search-forward "\r" nil t)
1274 (replace-match "\n" t t)))))
1276 (defun article-remove-trailing-blank-lines ()
1277 "Remove all trailing blank lines from the article."
1280 (let ((buffer-read-only nil))
1281 (goto-char (point-max))
1285 (while (and (not (bobp))
1286 (looking-at "^[ \t]*$")
1287 (not (gnus-annotation-in-region-p
1288 (point) (gnus-point-at-eol))))
1293 (defun article-display-x-face (&optional force)
1294 "Look for an X-Face header and display it if present."
1295 (interactive (list 'force))
1297 ;; Delete the old process, if any.
1298 (when (process-status "article-x-face")
1299 (delete-process "article-x-face"))
1300 (let ((inhibit-point-motion-hooks t)
1301 (case-fold-search t)
1304 (article-narrow-to-head)
1305 (goto-char (point-min))
1306 (setq from (message-fetch-field "from"))
1307 (goto-char (point-min))
1308 (while (and gnus-article-x-face-command
1311 ;; Check whether this face is censored.
1312 (not gnus-article-x-face-too-ugly)
1313 (and gnus-article-x-face-too-ugly from
1314 (not (string-match gnus-article-x-face-too-ugly
1316 ;; Has to be present.
1317 (re-search-forward "^X-Face: " nil t))
1318 ;; This used to try to do multiple faces (`while' instead of
1319 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1320 ;; work (b) it can crash some versions of Emacs (c) are
1321 ;; multiple faces really something to encourage?
1322 (when (stringp gnus-article-x-face-command)
1324 ;; We now have the area of the buffer where the X-Face is stored.
1327 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1328 ;; We display the face.
1329 (if (symbolp gnus-article-x-face-command)
1330 ;; The command is a lisp function, so we call it.
1331 (if (gnus-functionp gnus-article-x-face-command)
1332 (funcall gnus-article-x-face-command beg end)
1333 (error "%s is not a function" gnus-article-x-face-command))
1334 ;; The command is a string, so we interpret the command
1335 ;; as a, well, command, and fork it off.
1336 (let ((process-connection-type nil))
1337 (process-kill-without-query
1339 "article-x-face" nil shell-file-name shell-command-switch
1340 gnus-article-x-face-command))
1341 (process-send-region "article-x-face" beg end)
1342 (process-send-eof "article-x-face"))))))))))
1344 (defun article-decode-mime-words ()
1345 "Decode all MIME-encoded words in the article."
1348 (set-buffer gnus-article-buffer)
1349 (let ((inhibit-point-motion-hooks t)
1351 (mail-parse-charset gnus-newsgroup-charset))
1352 (mail-decode-encoded-word-region (point-min) (point-max)))))
1354 (defun article-decode-charset (&optional prompt)
1355 "Decode charset-encoded text in the article.
1356 If PROMPT (the prefix), prompt for a coding system to use."
1360 (article-narrow-to-head)
1361 (let* ((inhibit-point-motion-hooks t)
1362 (case-fold-search t)
1363 (ct (message-fetch-field "Content-Type" t))
1364 (cte (message-fetch-field "Content-Transfer-Encoding" t))
1365 (ctl (and ct (ignore-errors
1366 (mail-header-parse-content-type ct))))
1369 (mm-read-coding-system "Charset to decode: "))
1371 (mail-content-type-get ctl 'charset))))
1372 (mail-parse-charset gnus-newsgroup-charset)
1374 (when (memq charset gnus-newsgroup-ignored-charsets)
1376 (goto-char (point-max))
1379 (narrow-to-region (point) (point-max))
1380 (when (and (or (not ctl)
1381 (equal (car ctl) "text/plain"))
1384 charset (and cte (intern (downcase
1385 (gnus-strip-whitespace cte))))
1388 (defun article-decode-encoded-words ()
1389 "Remove encoded-word encoding from headers."
1390 (let (buffer-read-only)
1391 (let ((charset (save-excursion
1392 (set-buffer gnus-summary-buffer)
1393 default-mime-charset)))
1394 (mime-decode-header-in-buffer charset)
1397 (defun article-de-quoted-unreadable (&optional force)
1398 "Translate a quoted-printable-encoded article.
1399 If FORCE, decode the article whether it is marked as quoted-printable
1401 (interactive (list 'force))
1403 (let ((buffer-read-only nil)
1404 (type (gnus-fetch-field "content-transfer-encoding"))
1405 (charset gnus-newsgroup-charset))
1407 (and type (string-match "quoted-printable" (downcase type))))
1410 (narrow-to-region (point) (point-max))
1411 (quoted-printable-decode-region (point-min) (point-max))
1413 (mm-decode-body charset)))))))
1415 (defun article-hide-pgp ()
1416 "Remove any PGP headers and signatures in the current article."
1420 (let ((inhibit-point-motion-hooks t)
1421 buffer-read-only beg end)
1423 ;; Hide the "header".
1424 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1425 (push 'pgp gnus-article-wash-types)
1426 (delete-region (match-beginning 0) (match-end 0))
1427 ;; PGP 5 and GNU PG add a `Hash: <>' comment, hide that too
1428 (when (looking-at "Hash:.*$")
1429 (delete-region (point) (1+ (gnus-point-at-eol))))
1431 ;; Hide the actual signature.
1432 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1433 (setq end (1+ (match-beginning 0)))
1436 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1438 ;; Perhaps we shouldn't hide to the end of the buffer
1439 ;; if there is no end to the signature?
1441 ;; Hide "- " PGP quotation markers.
1443 (narrow-to-region beg end)
1444 (goto-char (point-min))
1445 (while (re-search-forward "^- " nil t)
1447 (match-beginning 0) (match-end 0)))
1449 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1451 (defun article-hide-pem (&optional arg)
1452 "Toggle hiding of any PEM headers and signatures in the current article.
1453 If given a negative prefix, always show; if given a positive prefix,
1455 (interactive (gnus-article-hidden-arg))
1456 (unless (gnus-article-check-hidden-text 'pem arg)
1458 (let (buffer-read-only end)
1459 (goto-char (point-min))
1460 ;; Hide the horrendously ugly "header".
1461 (when (and (search-forward
1462 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1464 (setq end (1+ (match-beginning 0))))
1465 (push 'pem gnus-article-wash-types)
1466 (gnus-article-hide-text-type
1468 (if (search-forward "\n\n" nil t)
1472 ;; Hide the trailer as well
1473 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1475 (gnus-article-hide-text-type
1476 (match-beginning 0) (match-end 0) 'pem)))))))
1478 (defun article-strip-banner ()
1479 "Strip the banner specified by the `banner' group parameter."
1483 (let ((inhibit-point-motion-hooks t)
1484 (banner (gnus-group-get-parameter gnus-newsgroup-name 'banner))
1485 (gnus-signature-limit nil)
1486 buffer-read-only beg end)
1490 ((eq banner 'signature)
1491 (when (gnus-article-narrow-to-signature)
1494 (delete-region (point) (point-max))))
1496 (while (re-search-forward banner nil t)
1497 (delete-region (match-beginning 0) (match-end 0))))))))))
1499 (defun article-hide-signature (&optional arg)
1500 "Hide the signature in the current article.
1501 If given a negative prefix, always show; if given a positive prefix,
1503 (interactive (gnus-article-hidden-arg))
1504 (unless (gnus-article-check-hidden-text 'signature arg)
1507 (let ((buffer-read-only nil))
1508 (when (gnus-article-narrow-to-signature)
1509 (gnus-article-hide-text-type
1510 (point-min) (point-max) 'signature)))))))
1512 (defun article-strip-leading-blank-lines ()
1513 "Remove all blank lines from the beginning of the article."
1516 (let ((inhibit-point-motion-hooks t)
1518 (when (article-goto-body)
1519 (while (and (not (eobp))
1520 (looking-at "[ \t]*$"))
1521 (gnus-delete-line))))))
1523 (defun article-narrow-to-head ()
1524 "Narrow the buffer to the head of the message.
1525 Point is left at the beginning of the narrowed-to region."
1527 (goto-char (point-min))
1528 (if (search-forward "\n\n" nil 1)
1531 (goto-char (point-min)))
1533 (defun article-goto-body ()
1534 "Place point at the start of the body."
1535 (goto-char (point-min))
1537 ;; This variable is only bound when dealing with separate
1539 (article-goto-body-goes-to-point-min-p
1541 ((search-forward "\n\n" nil t)
1544 (goto-char (point-max))
1547 (defun article-strip-multiple-blank-lines ()
1548 "Replace consecutive blank lines with one empty line."
1551 (let ((inhibit-point-motion-hooks t)
1553 ;; First make all blank lines empty.
1555 (while (re-search-forward "^[ \t]+$" nil t)
1556 (unless (gnus-annotation-in-region-p
1557 (match-beginning 0) (match-end 0))
1558 (replace-match "" nil t)))
1559 ;; Then replace multiple empty lines with a single empty line.
1561 (while (re-search-forward "\n\n\n+" nil t)
1562 (unless (gnus-annotation-in-region-p
1563 (match-beginning 0) (match-end 0))
1564 (replace-match "\n\n" t t))))))
1566 (defun article-strip-leading-space ()
1567 "Remove all white space from the beginning of the lines in the article."
1570 (let ((inhibit-point-motion-hooks t)
1573 (while (re-search-forward "^[ \t]+" nil t)
1574 (replace-match "" t t)))))
1576 (defun article-strip-trailing-space ()
1577 "Remove all white space from the end of the lines in the article."
1580 (let ((inhibit-point-motion-hooks t)
1583 (while (re-search-forward "[ \t]+$" nil t)
1584 (replace-match "" t t)))))
1586 (defun article-strip-blank-lines ()
1587 "Strip leading, trailing and multiple blank lines."
1589 (article-strip-leading-blank-lines)
1590 (article-remove-trailing-blank-lines)
1591 (article-strip-multiple-blank-lines))
1593 (defun article-strip-all-blank-lines ()
1594 "Strip all blank lines."
1597 (let ((inhibit-point-motion-hooks t)
1600 (while (re-search-forward "^[ \t]*\n" nil t)
1601 (replace-match "" t t)))))
1603 (defun gnus-article-narrow-to-signature ()
1604 "Narrow to the signature; return t if a signature is found, else nil."
1605 (let ((inhibit-point-motion-hooks t))
1606 (when (gnus-article-search-signature)
1608 ;; Check whether we have some limits to what we consider
1609 ;; to be a signature.
1610 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1611 (list gnus-signature-limit)))
1613 (while (setq limit (pop limits))
1614 (if (or (and (integerp limit)
1615 (< (- (point-max) (point)) limit))
1617 (< (count-lines (point) (point-max)) limit))
1618 (and (gnus-functionp limit)
1620 (and (stringp limit)
1621 (not (re-search-forward limit nil t))))
1622 () ; This limit did not succeed.
1626 (narrow-to-region (point) (point-max))
1629 (defun gnus-article-search-signature ()
1630 "Search the current buffer for the signature separator.
1631 Put point at the beginning of the signature separator."
1632 (let ((cur (point)))
1633 (goto-char (point-max))
1634 (if (if (stringp gnus-signature-separator)
1635 (re-search-backward gnus-signature-separator nil t)
1636 (let ((seps gnus-signature-separator))
1638 (not (re-search-backward (car seps) nil t)))
1645 (defun gnus-article-hidden-arg ()
1646 "Return the current prefix arg as a number, or 0 if no prefix."
1647 (list (if current-prefix-arg
1648 (prefix-numeric-value current-prefix-arg)
1651 (defun gnus-article-check-hidden-text (type arg)
1652 "Return nil if hiding is necessary.
1653 Arg can be nil or a number. Nil and positive means hide, negative
1654 means show, 0 means toggle."
1657 (let ((hide (gnus-article-hidden-text-p type)))
1663 (gnus-article-show-hidden-text type))
1665 (if (eq hide 'hidden)
1666 (gnus-article-show-hidden-text type)
1669 (defun gnus-article-hidden-text-p (type)
1670 "Say whether the current buffer contains hidden text of type TYPE."
1671 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
1673 (not (get-text-property pos 'invisible)))
1675 (text-property-any (1+ pos) (point-max) 'article-type type)))
1680 (defun gnus-article-show-hidden-text (type &optional hide)
1681 "Show all hidden text of type TYPE.
1682 If HIDE, hide the text instead."
1684 (let ((buffer-read-only nil)
1685 (inhibit-point-motion-hooks t)
1688 (while (setq beg (text-property-any end (point-max) 'article-type type))
1691 (text-property-not-all beg (point-max) 'article-type type)
1694 (gnus-article-hide-text beg end gnus-hidden-properties)
1695 (gnus-article-unhide-text beg end))
1699 (defconst article-time-units
1700 `((year . ,(* 365.25 24 60 60))
1701 (week . ,(* 7 24 60 60))
1702 (day . ,(* 24 60 60))
1706 "Mapping from time units to seconds.")
1708 (defun article-date-ut (&optional type highlight header)
1709 "Convert DATE date to universal time in the current article.
1710 If TYPE is `local', convert to local time; if it is `lapsed', output
1711 how much time has lapsed since DATE."
1712 (interactive (list 'ut t))
1713 (let* ((header (or header
1714 (mail-header-date (save-excursion
1715 (set-buffer gnus-summary-buffer)
1716 gnus-current-headers))
1717 (message-fetch-field "date")
1719 (date (if (vectorp header) (mail-header-date header)
1721 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
1722 (inhibit-point-motion-hooks t)
1723 bface eface newline)
1724 (when (and date (not (string= date "")))
1727 (article-narrow-to-head)
1728 (let ((buffer-read-only nil))
1729 ;; Delete any old Date headers.
1730 (if (re-search-forward date-regexp nil t)
1732 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1733 eface (get-text-property (1- (gnus-point-at-eol))
1735 (delete-region (progn (beginning-of-line) (point))
1736 (progn (end-of-line) (point)))
1737 (beginning-of-line))
1738 (goto-char (point-max))
1740 (insert (article-make-date-line date type))
1743 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
1744 (put-text-property (match-beginning 1) (1+ (match-end 1))
1746 (put-text-property (match-beginning 2) (match-end 2)
1750 (insert "\n"))))))))
1752 (defun article-make-date-line (date type)
1753 "Return a DATE line of TYPE."
1754 (let ((time (condition-case ()
1758 ;; Convert to the local timezone. We have to slap a
1759 ;; `condition-case' round the calls to the timezone
1760 ;; functions since they aren't particularly resistant to
1763 (let ((tz (car (current-time-zone))))
1764 (format "Date: %s %s%04d" (current-time-string time)
1765 (if (> tz 0) "+" "-") (abs (/ tz 36)))))
1766 ;; Convert to Universal Time.
1769 (current-time-string
1770 (let* ((e (parse-time-string date))
1771 (tm (apply 'encode-time e))
1773 (ls (- (cadr tm) (car (current-time-zone)))))
1774 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
1775 ((> ls 65535) (list (1+ ms) (- ls 65536)))
1778 ;; Get the original date from the article.
1779 ((eq type 'original)
1780 (concat "Date: " (if (string-match "\n+$" date)
1781 (substring date 0 (match-beginning 0))
1783 ;; Let the user define the format.
1785 (if (gnus-functionp gnus-article-time-format)
1786 (funcall gnus-article-time-format time)
1789 (format-time-string gnus-article-time-format time))))
1794 (format-time-string "%Y%m%dT%H%M%S" time)))
1795 ;; Do an X-Sent lapsed format.
1797 ;; If the date is seriously mangled, the timezone functions are
1798 ;; liable to bug out, so we ignore all errors.
1799 (let* ((now (current-time))
1800 (real-time (subtract-time now time))
1801 (real-sec (and real-time
1802 (+ (* (float (car real-time)) 65536)
1804 (sec (and real-time (abs real-sec)))
1814 ;; This is a bit convoluted, but basically we go
1815 ;; through the time units for years, weeks, etc,
1816 ;; and divide things to see whether that results
1817 ;; in positive answers.
1820 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
1821 ;; The (remaining) seconds are too few to
1822 ;; be divided into this time unit.
1824 ;; It's big enough, so we output it.
1825 (setq sec (- sec (* num (cdr unit))))
1827 (concat (if prev ", " "") (int-to-string
1829 " " (symbol-name (car unit))
1830 (if (> num 1) "s" ""))
1832 article-time-units "")
1833 ;; If dates are odd, then it might appear like the
1834 ;; article was sent in the future.
1837 " in the future"))))))
1839 (error "Unknown conversion type: %s" type)))))
1841 (defun article-date-local (&optional highlight)
1842 "Convert the current article date to the local timezone."
1843 (interactive (list t))
1844 (article-date-ut 'local highlight))
1846 (defun article-date-original (&optional highlight)
1847 "Convert the current article date to what it was originally.
1848 This is only useful if you have used some other date conversion
1849 function and want to see what the date was before converting."
1850 (interactive (list t))
1851 (article-date-ut 'original highlight))
1853 (defun article-date-lapsed (&optional highlight)
1854 "Convert the current article date to time lapsed since it was sent."
1855 (interactive (list t))
1856 (article-date-ut 'lapsed highlight))
1858 (defun article-update-date-lapsed ()
1859 "Function to be run from a timer to update the lapsed time line."
1860 (let (deactivate-mark)
1865 (set-buffer (window-buffer w))
1866 (when (eq major-mode 'gnus-article-mode)
1867 (goto-char (point-min))
1868 (when (re-search-forward "^X-Sent:" nil t)
1869 (article-date-lapsed t))))
1872 (defun gnus-start-date-timer (&optional n)
1873 "Start a timer to update the X-Sent header in the article buffers.
1874 The numerical prefix says how frequently (in seconds) the function
1879 (gnus-stop-date-timer)
1880 (setq article-lapsed-timer
1881 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
1883 (defun gnus-stop-date-timer ()
1884 "Stop the X-Sent timer."
1886 (when article-lapsed-timer
1887 (nnheader-cancel-timer article-lapsed-timer)
1888 (setq article-lapsed-timer nil)))
1890 (defun article-date-user (&optional highlight)
1891 "Convert the current article date to the user-defined format.
1892 This format is defined by the `gnus-article-time-format' variable."
1893 (interactive (list t))
1894 (article-date-ut 'user highlight))
1896 (defun article-date-iso8601 (&optional highlight)
1897 "Convert the current article date to ISO8601."
1898 (interactive (list t))
1899 (article-date-ut 'iso8601 highlight))
1901 (defun article-show-all ()
1902 "Show all hidden text in the article buffer."
1905 (let ((buffer-read-only nil))
1906 (gnus-article-unhide-text (point-min) (point-max)))))
1908 (defun article-emphasize (&optional arg)
1909 "Emphasize text according to `gnus-emphasis-alist'."
1910 (interactive (gnus-article-hidden-arg))
1911 (unless (gnus-article-check-hidden-text 'emphasis arg)
1913 (let ((alist gnus-emphasis-alist)
1914 (buffer-read-only nil)
1915 (props (append '(article-type emphasis)
1916 gnus-hidden-properties))
1917 regexp elem beg invisible visible face)
1920 (while (setq elem (pop alist))
1922 (setq regexp (car elem)
1923 invisible (nth 1 elem)
1924 visible (nth 2 elem)
1926 (while (re-search-forward regexp nil t)
1927 (when (and (match-beginning visible) (match-beginning invisible))
1928 (gnus-article-hide-text
1929 (match-beginning invisible) (match-end invisible) props)
1930 (gnus-article-unhide-text-type
1931 (match-beginning visible) (match-end visible) 'emphasis)
1932 (gnus-put-text-property-excluding-newlines
1933 (match-beginning visible) (match-end visible) 'face face)
1934 (goto-char (match-end invisible)))))))))
1936 (defvar gnus-summary-article-menu)
1937 (defvar gnus-summary-post-menu)
1939 ;;; Saving functions.
1941 (defun gnus-article-save (save-buffer file &optional num)
1942 "Save the currently selected article."
1943 (unless gnus-save-all-headers
1944 ;; Remove headers according to `gnus-saved-headers'.
1945 (let ((gnus-visible-headers
1946 (or gnus-saved-headers gnus-visible-headers))
1947 (gnus-article-buffer save-buffer))
1949 (set-buffer save-buffer)
1950 (article-hide-headers 1 t))))
1951 (save-window-excursion
1952 (if (not gnus-default-article-saver)
1953 (error "No default saver is defined")
1954 ;; !!! Magic! The saving functions all save
1955 ;; `gnus-save-article-buffer' (or so they think), but we
1956 ;; bind that variable to our save-buffer.
1957 (set-buffer gnus-article-buffer)
1958 (let* ((gnus-save-article-buffer save-buffer)
1961 ((not gnus-prompt-before-saving) 'default)
1962 ((eq gnus-prompt-before-saving 'always) nil)
1964 (gnus-number-of-articles-to-be-saved
1965 (when (eq gnus-prompt-before-saving t)
1967 (set-buffer gnus-article-current-summary)
1968 (funcall gnus-default-article-saver filename)))))
1970 (defun gnus-read-save-file-name (prompt &optional filename
1971 function group headers variable)
1973 (funcall function group headers (symbol-value variable)))
1978 ((eq filename 'default)
1984 (let* ((split-name (gnus-get-split-value gnus-split-methods))
1987 (if (and gnus-number-of-articles-to-be-saved
1988 (> gnus-number-of-articles-to-be-saved 1))
1989 (format "these %d articles"
1990 gnus-number-of-articles-to-be-saved)
1993 ;; Let the split methods have their say.
1995 ;; No split name was found.
1998 (concat prompt " (default "
1999 (file-name-nondirectory default-name) ") ")
2000 (file-name-directory default-name)
2002 ;; A single group name is returned.
2003 ((stringp split-name)
2005 (funcall function split-name headers
2006 (symbol-value variable)))
2008 (concat prompt " (default "
2009 (file-name-nondirectory default-name) ") ")
2010 (file-name-directory default-name)
2012 ;; A single split name was found
2013 ((= 1 (length split-name))
2014 (let* ((name (expand-file-name
2015 (car split-name) gnus-article-save-directory))
2016 (dir (cond ((file-directory-p name)
2017 (file-name-as-directory name))
2018 ((file-exists-p name) name)
2019 (t gnus-article-save-directory))))
2021 (concat prompt " (default " name ") ")
2023 ;; A list of splits was found.
2025 (setq split-name (nreverse split-name))
2027 (let ((file-name-history
2028 (nconc split-name file-name-history)))
2032 (concat prompt " (`M-p' for defaults) ")
2033 gnus-article-save-directory
2035 gnus-article-save-directory)))
2036 (car (push result file-name-history)))))))
2037 ;; Create the directory.
2038 (gnus-make-directory (file-name-directory file))
2039 ;; If we have read a directory, we append the default file name.
2040 (when (file-directory-p file)
2041 (setq file (concat (file-name-as-directory file)
2042 (file-name-nondirectory default-name))))
2043 ;; Possibly translate some characters.
2044 (nnheader-translate-file-chars file)))))
2045 (gnus-make-directory (file-name-directory result))
2046 (set variable result)))
2048 (defun gnus-article-archive-name (group)
2049 "Return the first instance of an \"Archive-name\" in the current buffer."
2050 (let ((case-fold-search t))
2051 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2052 (nnheader-concat gnus-article-save-directory
2053 (match-string 1)))))
2055 (defun gnus-article-nndoc-name (group)
2056 "If GROUP is an nndoc group, return the name of the parent group."
2057 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2058 (gnus-group-get-parameter group 'save-article-group)))
2060 (defun gnus-summary-save-in-rmail (&optional filename)
2061 "Append this article to Rmail file.
2062 Optional argument FILENAME specifies file name.
2063 Directory to save to is default to `gnus-article-save-directory'."
2064 (setq filename (gnus-read-save-file-name
2065 "Save %s in rmail file:" filename
2066 gnus-rmail-save-name gnus-newsgroup-name
2067 gnus-current-headers 'gnus-newsgroup-last-rmail))
2068 (gnus-eval-in-buffer-window gnus-save-article-buffer
2072 (gnus-output-to-rmail filename))))
2075 (defun gnus-summary-save-in-mail (&optional filename)
2076 "Append this article to Unix mail file.
2077 Optional argument FILENAME specifies file name.
2078 Directory to save to is default to `gnus-article-save-directory'."
2079 (setq filename (gnus-read-save-file-name
2080 "Save %s in Unix mail file:" filename
2081 gnus-mail-save-name gnus-newsgroup-name
2082 gnus-current-headers 'gnus-newsgroup-last-mail))
2083 (gnus-eval-in-buffer-window gnus-save-article-buffer
2087 (if (and (file-readable-p filename)
2088 (mail-file-babyl-p filename))
2089 (rmail-output-to-rmail-file filename t)
2090 (gnus-output-to-mail filename)))))
2093 (defun gnus-summary-save-in-file (&optional filename overwrite)
2094 "Append this article to file.
2095 Optional argument FILENAME specifies file name.
2096 Directory to save to is default to `gnus-article-save-directory'."
2097 (setq filename (gnus-read-save-file-name
2098 "Save %s in file:" filename
2099 gnus-file-save-name gnus-newsgroup-name
2100 gnus-current-headers 'gnus-newsgroup-last-file))
2101 (gnus-eval-in-buffer-window gnus-save-article-buffer
2105 (when (and overwrite
2106 (file-exists-p filename))
2107 (delete-file filename))
2108 (gnus-output-to-file filename))))
2111 (defun gnus-summary-write-to-file (&optional filename)
2112 "Write this article to a file.
2113 Optional argument FILENAME specifies file name.
2114 The directory to save in defaults to `gnus-article-save-directory'."
2115 (gnus-summary-save-in-file nil t))
2117 (defun gnus-summary-save-body-in-file (&optional filename)
2118 "Append this article body to a file.
2119 Optional argument FILENAME specifies file name.
2120 The directory to save in defaults to `gnus-article-save-directory'."
2121 (setq filename (gnus-read-save-file-name
2122 "Save %s body in file:" filename
2123 gnus-file-save-name gnus-newsgroup-name
2124 gnus-current-headers 'gnus-newsgroup-last-file))
2125 (gnus-eval-in-buffer-window gnus-save-article-buffer
2129 (when (article-goto-body)
2130 (narrow-to-region (point) (point-max)))
2131 (gnus-output-to-file filename))))
2134 (defun gnus-summary-save-in-pipe (&optional command)
2135 "Pipe this article to subprocess."
2137 (cond ((and (eq command 'default)
2138 gnus-last-shell-command)
2139 gnus-last-shell-command)
2143 "Shell command on %s: "
2144 (if (and gnus-number-of-articles-to-be-saved
2145 (> gnus-number-of-articles-to-be-saved 1))
2146 (format "these %d articles"
2147 gnus-number-of-articles-to-be-saved)
2149 gnus-last-shell-command))))
2150 (when (string-equal command "")
2151 (setq command gnus-last-shell-command))
2152 (gnus-eval-in-buffer-window gnus-article-buffer
2155 (shell-command-on-region (point-min) (point-max) command nil)))
2156 (setq gnus-last-shell-command command))
2158 ;;; Article file names when saving.
2160 (defun gnus-capitalize-newsgroup (newsgroup)
2161 "Capitalize NEWSGROUP name."
2162 (when (not (zerop (length newsgroup)))
2163 (concat (char-to-string (upcase (aref newsgroup 0)))
2164 (substring newsgroup 1))))
2166 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2167 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2168 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2169 Otherwise, it is like ~/News/news/group/num."
2172 (concat (if (gnus-use-long-file-name 'not-save)
2173 (gnus-capitalize-newsgroup newsgroup)
2174 (gnus-newsgroup-directory-form newsgroup))
2175 "/" (int-to-string (mail-header-number headers)))
2176 gnus-article-save-directory)))
2178 (string-equal (file-name-directory default)
2179 (file-name-directory last-file))
2180 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2182 (or last-file default))))
2184 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2185 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2186 If variable `gnus-use-long-file-name' is non-nil, it is
2187 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2190 (concat (if (gnus-use-long-file-name 'not-save)
2192 (gnus-newsgroup-directory-form newsgroup))
2193 "/" (int-to-string (mail-header-number headers)))
2194 gnus-article-save-directory)))
2196 (string-equal (file-name-directory default)
2197 (file-name-directory last-file))
2198 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2200 (or last-file default))))
2202 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2203 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2204 If variable `gnus-use-long-file-name' is non-nil, it is
2205 ~/News/News.group. Otherwise, it is like ~/News/news/group/news."
2208 (if (gnus-use-long-file-name 'not-save)
2209 (gnus-capitalize-newsgroup newsgroup)
2210 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2211 gnus-article-save-directory)))
2213 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2214 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2215 If variable `gnus-use-long-file-name' is non-nil, it is
2216 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2219 (if (gnus-use-long-file-name 'not-save)
2221 (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2222 gnus-article-save-directory)))
2229 (setq afunc (car func)
2232 gfunc (intern (format "gnus-%s" func))))
2234 (if (not (fboundp afunc))
2236 `(lambda (&optional interactive &rest args)
2237 ,(documentation afunc t)
2238 (interactive (list t))
2240 (set-buffer gnus-article-buffer)
2242 (call-interactively ',afunc)
2243 (apply ',afunc args))))))))
2244 '(article-hide-headers
2245 article-hide-boring-headers
2246 article-treat-overstrike
2247 article-fill-long-lines
2248 article-capitalize-sentences
2250 article-display-x-face
2251 article-de-quoted-unreadable
2252 article-mime-decode-quoted-printable
2254 article-strip-banner
2256 article-hide-signature
2257 article-remove-trailing-blank-lines
2258 article-strip-leading-blank-lines
2259 article-strip-multiple-blank-lines
2260 article-strip-leading-space
2261 article-strip-trailing-space
2262 article-strip-blank-lines
2263 article-strip-all-blank-lines
2265 article-date-iso8601
2266 article-date-original
2268 article-decode-mime-words
2269 article-decode-charset
2270 article-decode-encoded-words
2274 article-treat-dumbquotes
2275 article-normalize-headers
2276 (article-show-all . gnus-article-show-all-headers))))
2279 ;;; Gnus article mode
2282 (put 'gnus-article-mode 'mode-class 'special)
2284 (gnus-define-keys gnus-article-mode-map
2285 " " gnus-article-goto-next-page
2286 "\177" gnus-article-goto-prev-page
2287 [delete] gnus-article-goto-prev-page
2288 [backspace] gnus-article-goto-prev-page
2289 "\C-c^" gnus-article-refer-article
2290 "h" gnus-article-show-summary
2291 "s" gnus-article-show-summary
2292 "\C-c\C-m" gnus-article-mail
2293 "?" gnus-article-describe-briefly
2294 gnus-mouse-2 gnus-article-push-button
2295 "\r" gnus-article-press-button
2296 "\t" gnus-article-next-button
2297 "\M-\t" gnus-article-prev-button
2298 "e" gnus-article-edit
2299 "<" beginning-of-buffer
2301 "\C-c\C-i" gnus-info-find-node
2304 "\C-d" gnus-article-read-summary-keys
2305 "\M-*" gnus-article-read-summary-keys
2306 "\M-#" gnus-article-read-summary-keys
2307 "\M-^" gnus-article-read-summary-keys
2308 "\M-g" gnus-article-read-summary-keys)
2310 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2313 (unless (lookup-key gnus-article-mode-map key)
2314 (define-key gnus-article-mode-map key
2315 'gnus-article-read-summary-keys)))
2320 (let ((key (car elt)))
2321 (and (> (length key) 0)
2322 (not (eq 'menu-bar (aref key 0)))
2323 (symbolp (lookup-key gnus-summary-mode-map key))
2325 (accessible-keymaps gnus-summary-mode-map))
2329 (push (char-to-string c) keys)
2333 (defun gnus-article-make-menu-bar ()
2334 (gnus-turn-off-edit-menu 'article)
2335 (unless (boundp 'gnus-article-article-menu)
2337 gnus-article-article-menu gnus-article-mode-map ""
2339 ["Scroll forwards" gnus-article-goto-next-page t]
2340 ["Scroll backwards" gnus-article-goto-prev-page t]
2341 ["Show summary" gnus-article-show-summary t]
2342 ["Fetch Message-ID at point" gnus-article-refer-article t]
2343 ["Mail to address at point" gnus-article-mail t]
2344 ["Send a bug report" gnus-bug t]))
2347 gnus-article-treatment-menu gnus-article-mode-map ""
2349 ["Hide headers" gnus-article-hide-headers t]
2350 ["Hide signature" gnus-article-hide-signature t]
2351 ["Hide citation" gnus-article-hide-citation t]
2352 ["Treat overstrike" gnus-article-treat-overstrike t]
2353 ["Remove carriage return" gnus-article-remove-cr t]))
2355 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2357 (when (boundp 'gnus-summary-post-menu)
2358 (define-key gnus-article-mode-map [menu-bar post]
2359 (cons "Post" gnus-summary-post-menu)))
2361 (gnus-run-hooks 'gnus-article-menu-hook)))
2363 (defun gnus-article-mode ()
2364 "Major mode for displaying an article.
2366 All normal editing commands are switched off.
2368 The following commands are available in addition to all summary mode
2370 \\<gnus-article-mode-map>
2371 \\[gnus-article-next-page]\t Scroll the article one page forwards
2372 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2373 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2374 \\[gnus-article-show-summary]\t Display the summary buffer
2375 \\[gnus-article-mail]\t Send a reply to the address near point
2376 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2377 \\[gnus-info-find-node]\t Go to the Gnus info node"
2379 (when (gnus-visual-p 'article-menu 'menu)
2380 (gnus-article-make-menu-bar))
2381 (gnus-simplify-mode-line)
2382 (setq mode-name "Article")
2383 (setq major-mode 'gnus-article-mode)
2384 (make-local-variable 'minor-mode-alist)
2385 (unless (assq 'gnus-show-mime minor-mode-alist)
2386 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
2387 (use-local-map gnus-article-mode-map)
2388 (gnus-update-format-specifications nil 'article-mode)
2389 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2390 (make-local-variable 'gnus-page-broken)
2391 (make-local-variable 'gnus-button-marker-list)
2392 (make-local-variable 'gnus-article-current-summary)
2393 (make-local-variable 'gnus-article-mime-handles)
2394 (make-local-variable 'gnus-article-decoded-p)
2395 (make-local-variable 'gnus-article-mime-handle-alist)
2396 (make-local-variable 'gnus-article-washed-types)
2397 (gnus-set-default-directory)
2398 (buffer-disable-undo)
2399 (setq buffer-read-only t)
2400 (set-syntax-table gnus-article-mode-syntax-table)
2401 (gnus-run-hooks 'gnus-article-mode-hook))
2403 (defun gnus-article-setup-buffer ()
2404 "Initialize the article buffer."
2405 (let* ((name (if gnus-single-article-buffer "*Article*"
2406 (concat "*Article " gnus-newsgroup-name "*")))
2408 (progn (string-match "\\*Article" name)
2409 (concat " *Original Article"
2410 (substring name (match-end 0))))))
2411 (setq gnus-article-buffer name)
2412 (setq gnus-original-article-buffer original)
2413 (setq gnus-article-mime-handle-alist nil)
2414 ;; This might be a variable local to the summary buffer.
2415 (unless gnus-single-article-buffer
2417 (set-buffer gnus-summary-buffer)
2418 (setq gnus-article-buffer name)
2419 (setq gnus-original-article-buffer original)
2420 (gnus-set-global-variables)))
2421 ;; Init original article buffer.
2423 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2424 (setq major-mode 'gnus-original-article-mode)
2425 (make-local-variable 'gnus-original-article))
2426 (if (get-buffer name)
2429 (buffer-disable-undo)
2430 (setq buffer-read-only t)
2431 (unless (eq major-mode 'gnus-article-mode)
2432 (gnus-article-mode))
2435 (set-buffer (gnus-get-buffer-create name))
2437 (make-local-variable 'gnus-summary-buffer)
2438 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2439 (current-buffer)))))
2441 ;; Set article window start at LINE, where LINE is the number of lines
2442 ;; from the head of the article.
2443 (defun gnus-article-set-window-start (&optional line)
2445 (get-buffer-window gnus-article-buffer t)
2447 (set-buffer gnus-article-buffer)
2448 (goto-char (point-min))
2451 (gnus-message 6 "Moved to bookmark")
2452 (search-forward "\n\n" nil t)
2456 ;;; @@ article filters
2459 (defun gnus-article-display-mime-message ()
2460 "Article display method for MIME message."
2461 ;; called from `gnus-original-article-buffer'.
2462 (let (charset all-headers)
2463 (with-current-buffer gnus-summary-buffer
2464 (setq charset default-mime-charset
2465 all-headers gnus-have-all-headers))
2466 (make-local-variable 'default-mime-charset)
2467 (setq default-mime-charset charset)
2468 (mime-display-message mime-message-structure
2469 gnus-article-buffer nil gnus-article-mode-map)
2471 (gnus-article-hide-headers nil -1))
2472 (make-local-variable 'default-mime-charset)
2473 (setq default-mime-charset charset)
2475 ;; `mime-display-message' changes current buffer to `gnus-article-buffer'.
2476 (make-local-variable 'mime-button-mother-dispatcher)
2477 (setq mime-button-mother-dispatcher
2478 (function gnus-article-push-button))
2479 (run-hooks 'gnus-mime-article-prepare-hook))
2481 (defun gnus-article-display-traditional-message ()
2482 "Article display method for traditional message."
2483 (set-buffer gnus-article-buffer)
2484 (let (buffer-read-only)
2486 (insert-buffer-substring gnus-original-article-buffer)))
2488 (defun gnus-article-make-full-mail-header (&optional number charset)
2489 "Create a new mail header structure in a raw article buffer."
2490 (unless (and number charset)
2491 (save-current-buffer
2492 (set-buffer gnus-summary-buffer)
2494 (setq number (or (cdr gnus-article-current) 0)))
2496 (setq charset (or default-mime-charset 'x-ctext)))))
2497 (goto-char (point-min))
2498 (let ((header-end (if (search-forward "\n\n" nil t)
2500 (goto-char (point-max))))
2501 (chars (- (point-max) (point)))
2502 (lines (count-lines (point) (point-max)))
2503 (default-mime-charset charset)
2505 (narrow-to-region (point-min) header-end)
2506 (setq xref (std11-fetch-field "xref"))
2508 (make-full-mail-header
2510 (std11-fetch-field "subject")
2511 (std11-fetch-field "from")
2512 (std11-fetch-field "date")
2513 (std11-fetch-field "message-id")
2514 (std11-fetch-field "references")
2517 (when xref (concat "Xref: " xref)))
2520 (defun gnus-article-prepare (article &optional all-headers header)
2521 "Prepare ARTICLE in article mode buffer.
2522 ARTICLE should either be an article number or a Message-ID.
2523 If ARTICLE is an id, HEADER should be the article headers.
2524 If ALL-HEADERS is non-nil, no headers are hidden."
2526 ;; Make sure we start in a summary buffer.
2527 (unless (eq major-mode 'gnus-summary-mode)
2528 (set-buffer gnus-summary-buffer))
2529 (setq gnus-summary-buffer (current-buffer))
2530 (let* ((gnus-article (if header (mail-header-number header) article))
2531 (summary-buffer (current-buffer))
2532 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2533 (group gnus-newsgroup-name)
2536 (gnus-article-setup-buffer)
2537 (set-buffer gnus-original-article-buffer)
2538 ;; Deactivate active regions.
2539 (when (and (boundp 'transient-mark-mode)
2540 transient-mark-mode)
2541 (setq mark-active nil))
2542 (if (not (setq result (let ((buffer-read-only nil))
2543 (gnus-request-article-this-buffer
2545 ;; There is no such article.
2547 (when (and (numberp article)
2548 (not (memq article gnus-newsgroup-sparse)))
2549 (setq gnus-article-current
2550 (cons gnus-newsgroup-name article))
2551 (set-buffer gnus-summary-buffer)
2552 (setq gnus-current-article article)
2553 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2555 (gnus-summary-set-agent-mark article)
2556 (message "Message marked for downloading"))
2557 (gnus-summary-mark-article article gnus-canceled-mark)
2558 (unless (memq article gnus-newsgroup-sparse)
2560 "No such article (may have expired or been canceled)")))))
2561 (if (or (eq result 'pseudo)
2562 (eq result 'nneething))
2565 (set-buffer summary-buffer)
2566 (push article gnus-newsgroup-history)
2567 (setq gnus-last-article gnus-current-article
2568 gnus-current-article 0
2569 gnus-current-headers nil
2570 gnus-article-current nil)
2571 (if (eq result 'nneething)
2572 (gnus-configure-windows 'summary)
2573 (gnus-configure-windows 'article))
2574 (gnus-set-global-variables))
2575 (let ((gnus-article-mime-handle-alist-1
2576 gnus-article-mime-handle-alist))
2577 (gnus-set-mode-line 'article)))
2578 ;; The result from the `request' was an actual article -
2579 ;; or at least some text that is now displayed in the
2581 (when (and (numberp article)
2582 (not (eq article gnus-current-article)))
2583 ;; Seems like a new article has been selected.
2584 ;; `gnus-current-article' must be an article number.
2586 (set-buffer summary-buffer)
2587 (push article gnus-newsgroup-history)
2588 (setq gnus-last-article gnus-current-article
2589 gnus-current-article article
2590 gnus-current-headers
2591 (gnus-summary-article-header gnus-current-article)
2592 gnus-article-current
2593 (cons gnus-newsgroup-name gnus-current-article))
2594 (unless (vectorp gnus-current-headers)
2595 (setq gnus-current-headers nil))
2596 (gnus-summary-goto-subject gnus-current-article)
2597 (when (gnus-summary-show-thread)
2598 ;; If the summary buffer really was folded, the
2599 ;; previous goto may not actually have gone to
2600 ;; the right article, but the thread root instead.
2602 (gnus-summary-goto-subject gnus-current-article))
2603 (gnus-run-hooks 'gnus-mark-article-hook)
2604 (gnus-set-mode-line 'summary)
2605 (when (gnus-visual-p 'article-highlight 'highlight)
2606 (gnus-run-hooks 'gnus-visual-mark-article-hook))
2607 ;; Set the global newsgroup variables here.
2608 ;; Suggested by Jim Sisolak
2609 ;; <sisolak@trans4.neep.wisc.edu>.
2610 (gnus-set-global-variables)
2611 (setq gnus-have-all-headers
2612 (or all-headers gnus-show-all-headers))))
2613 (when (or (numberp article)
2615 (gnus-article-prepare-display)
2617 (goto-char (point-min))
2618 (setq gnus-page-broken
2619 (when gnus-break-pages
2620 (gnus-narrow-to-page)
2622 (let ((gnus-article-mime-handle-alist-1
2623 gnus-article-mime-handle-alist))
2624 (gnus-set-mode-line 'article))
2626 (set-window-point (get-buffer-window (current-buffer)) (point))
2627 (gnus-configure-windows 'article)
2631 (defun gnus-article-prepare-display ()
2632 "Make the current buffer look like a nice article."
2636 (setq mime-message-structure gnus-current-headers)
2637 gnus-article-display-method-for-mime)
2638 gnus-article-display-method-for-traditional)))
2639 (gnus-run-hooks 'gnus-tmp-internal-hook)
2640 (gnus-run-hooks 'gnus-article-prepare-hook)
2643 ;; Associate this article with the current summary buffer.
2644 (setq gnus-article-current-summary gnus-summary-buffer)
2645 ;; Perform the article display hooks.
2646 (gnus-run-hooks 'gnus-article-display-hook)))
2649 ;;; Gnus MIME viewing functions
2652 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
2653 "The following specs can be used:
2655 %T MIME type, along with additional info
2656 %n The `name' parameter
2657 %d The description, if any
2658 %l The length of the encoded part
2659 %p The part identifier number
2660 %e Dots if the part isn't displayed")
2662 (defvar gnus-mime-button-line-format-alist
2663 '((?t gnus-tmp-type ?s)
2664 (?T gnus-tmp-type-long ?s)
2665 (?n gnus-tmp-name ?s)
2666 (?d gnus-tmp-description ?s)
2668 (?l gnus-tmp-length ?d)
2669 (?e gnus-tmp-dots ?s)))
2671 (defvar gnus-mime-button-commands
2672 '((gnus-article-press-button "\r" "Toggle Display")
2673 (gnus-mime-view-part "v" "View Interactively...")
2674 (gnus-mime-save-part "o" "Save...")
2675 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
2676 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
2677 (gnus-mime-internalize-part "E" "View Internally")
2678 (gnus-mime-externalize-part "e" "View Externally")
2679 (gnus-mime-pipe-part "|" "Pipe To Command...")))
2681 (defun gnus-article-mime-part-status ()
2682 (if gnus-article-mime-handle-alist-1
2683 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
2686 (defvar gnus-mime-button-map nil)
2687 (unless gnus-mime-button-map
2688 (setq gnus-mime-button-map (make-sparse-keymap))
2689 (set-keymap-parent gnus-mime-button-map gnus-article-mode-map)
2690 (define-key gnus-mime-button-map gnus-mouse-2 'gnus-article-push-button)
2691 (define-key gnus-mime-button-map gnus-down-mouse-3 'gnus-mime-button-menu)
2693 (define-key gnus-mime-button-map (cadr c) (car c)))
2694 gnus-mime-button-commands))
2696 (defun gnus-mime-button-menu (event)
2697 "Construct a context-sensitive menu of MIME commands."
2700 (let ((pos (event-start event)))
2701 (set-buffer (window-buffer (posn-window pos)))
2702 (goto-char (posn-point pos))
2703 (gnus-article-check-buffer)
2704 (let ((response (x-popup-menu
2706 ("" ,@(mapcar (lambda (c)
2707 (cons (caddr c) (car c)))
2708 gnus-mime-button-commands))))))
2710 (funcall response))))))
2712 (defun gnus-mime-view-all-parts (&optional handles)
2713 "View all the MIME parts."
2715 (save-current-buffer
2716 (set-buffer gnus-article-buffer)
2717 (let ((handles (or handles gnus-article-mime-handles))
2718 (mail-parse-charset gnus-newsgroup-charset))
2719 (if (stringp (car handles))
2720 (gnus-mime-view-all-parts (cdr handles))
2721 (mapcar 'mm-display-part handles)))))
2723 (defun gnus-mime-save-part ()
2724 "Save the MIME part under point."
2726 (gnus-article-check-buffer)
2727 (let ((data (get-text-property (point) 'gnus-data)))
2728 (mm-save-part data)))
2730 (defun gnus-mime-pipe-part ()
2731 "Pipe the MIME part under point to a process."
2733 (gnus-article-check-buffer)
2734 (let ((data (get-text-property (point) 'gnus-data)))
2735 (mm-pipe-part data)))
2737 (defun gnus-mime-view-part ()
2738 "Interactively choose a view method for the MIME part under point."
2740 (gnus-article-check-buffer)
2741 (let ((data (get-text-property (point) 'gnus-data)))
2742 (mm-interactively-view-part data)))
2744 (defun gnus-mime-copy-part (&optional handle)
2745 "Put the the MIME part under point into a new buffer."
2747 (gnus-article-check-buffer)
2748 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2749 (contents (mm-get-part handle))|
2750 (base (file-name-nondirectory
2752 (mail-content-type-get (mm-handle-type handle) 'name)
2753 (mail-content-type-get (mm-handle-type handle)
2756 (buffer (generate-new-buffer base)))
2757 (switch-to-buffer buffer)
2759 ;; We do it this way to make `normal-mode' set the appropriate mode.
2762 (setq buffer-file-name (expand-file-name base))
2764 (setq buffer-file-name nil))
2765 (goto-char (point-min))))
2767 (defun gnus-mime-inline-part (&optional charset)
2768 "Insert the MIME part under point into the current buffer."
2769 (interactive "P") ; For compatibility reasons we are not using "z".
2770 (gnus-article-check-buffer)
2771 (let* ((data (get-text-property (point) 'gnus-data))
2775 (if (mm-handle-undisplayer data)
2776 (mm-remove-part data)
2777 (setq contents (mm-get-part data))
2780 (unless (symbolp charset)
2781 (setq charset (mm-read-coding-system "Charset: ")))
2782 (setq contents (mm-decode-coding-string contents charset)))
2783 (mm-insert-inline data contents)
2786 (defun gnus-mime-externalize-part (&optional handle)
2787 "View the MIME part under point with an external viewer."
2789 (gnus-article-check-buffer)
2790 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2791 (mm-user-display-methods nil)
2792 (mm-all-images-fit t)
2793 (mail-parse-charset gnus-newsgroup-charset))
2794 (if (mm-handle-undisplayer handle)
2795 (mm-remove-part handle)
2796 (mm-display-part handle))))
2798 (defun gnus-mime-internalize-part (&optional handle)
2799 "View the MIME part under point with an internal viewer."
2801 (gnus-article-check-buffer)
2802 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
2803 (mm-user-display-methods '((".*" . inline)))
2804 (mm-all-images-fit t)
2805 (mail-parse-charset gnus-newsgroup-charset))
2806 (if (mm-handle-undisplayer handle)
2807 (mm-remove-part handle)
2808 (mm-display-part handle))))
2810 (defun gnus-article-part-wrapper (n function)
2811 (save-current-buffer
2812 (set-buffer gnus-article-buffer)
2813 (when (> n (length gnus-article-mime-handle-alist))
2814 (error "No such part"))
2815 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2816 (funcall function handle))))
2818 (defun gnus-article-pipe-part (n)
2819 "Pipe MIME part N, which is the numerical prefix."
2821 (gnus-article-part-wrapper n 'mm-pipe-part))
2823 (defun gnus-article-save-part (n)
2824 "Save MIME part N, which is the numerical prefix."
2826 (gnus-article-part-wrapper n 'mm-save-part))
2828 (defun gnus-article-interactively-view-part (n)
2829 "View MIME part N interactively, which is the numerical prefix."
2831 (gnus-article-part-wrapper n 'mm-interactively-view-part))
2833 (defun gnus-article-copy-part (n)
2834 "Copy MIME part N, which is the numerical prefix."
2836 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
2838 (defun gnus-article-externalize-part (n)
2839 "View MIME part N externally, which is the numerical prefix."
2841 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
2843 (defun gnus-article-inline-part (n)
2844 "Inline MIME part N, which is the numerical prefix."
2846 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
2848 (defun gnus-article-view-part (n)
2849 "View MIME part N, which is the numerical prefix."
2851 (save-current-buffer
2852 (set-buffer gnus-article-buffer)
2853 (when (> n (length gnus-article-mime-handle-alist))
2854 (error "No such part"))
2855 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
2856 (when (gnus-article-goto-part n)
2857 (if (equal (car handle) "multipart/alternative")
2858 (gnus-article-press-button)
2859 (when (eq (gnus-mm-display-part handle) 'internal)
2860 (gnus-set-window-start)))))))
2862 (defun gnus-mm-display-part (handle)
2863 "Display HANDLE and fix MIME button."
2864 (let ((id (get-text-property (point) 'gnus-part))
2869 (let ((window (selected-window))
2870 (mail-parse-charset gnus-newsgroup-charset))
2873 (let ((win (get-buffer-window (current-buffer) t))
2876 (select-window win))
2879 (if (mm-handle-displayed-p handle)
2880 ;; This will remove the part.
2881 (mm-display-part handle)
2883 (narrow-to-region (point) (1+ (point)))
2884 (mm-display-part handle)
2887 (1- (length gnus-article-mime-handles))
2888 (car (mm-handle-type handle))))))
2889 (select-window window))))
2891 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
2892 (gnus-insert-mime-button
2893 handle id (list (mm-handle-displayed-p handle)))
2894 (goto-char point))))
2896 (defun gnus-article-goto-part (n)
2897 "Go to MIME part N."
2898 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
2900 (goto-char point))))
2902 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
2903 (let ((gnus-tmp-name
2904 (or (mail-content-type-get (mm-handle-type handle)
2906 (mail-content-type-get (mm-handle-disposition handle)
2909 (gnus-tmp-type (car (mm-handle-type handle)))
2910 (gnus-tmp-description
2911 (mail-decode-encoded-word-string (or (mm-handle-description handle)
2914 (if (if displayed (car displayed)
2915 (mm-handle-displayed-p handle))
2917 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
2919 gnus-tmp-type-long b e)
2920 (when (string-match ".*/" gnus-tmp-name)
2921 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
2922 (setq gnus-tmp-type-long (concat gnus-tmp-type
2923 (and (not (equal gnus-tmp-name ""))
2924 (concat "; " gnus-tmp-name))))
2925 (or (equal gnus-tmp-description "")
2926 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
2931 gnus-mime-button-line-format gnus-mime-button-line-format-alist
2932 `(local-map ,gnus-mime-button-map
2933 keymap ,gnus-mime-button-map
2934 gnus-callback gnus-mm-display-part
2935 gnus-part ,gnus-tmp-id
2936 article-type annotation
2939 (widget-convert-button 'link b e
2941 :action 'gnus-widget-press-button
2942 :button-keymap gnus-mime-button-map
2945 ;; Needed to properly clear the message
2946 ;; due to a bug in wid-edit
2947 (setq help-echo-owns-message t)
2949 "Click to %s the MIME part; %s for more options"
2950 (if (mm-handle-displayed-p
2951 (widget-get widget :mime-handle))
2953 (if gnus-xemacs "button3" "mouse-3"))))))
2955 (defun gnus-widget-press-button (elems el)
2956 (goto-char (widget-get elems :from))
2957 (gnus-article-press-button))
2959 (defvar gnus-displaying-mime nil)
2961 (defun gnus-display-mime (&optional ihandles)
2962 "Display the MIME parts."
2964 (save-selected-window
2965 (let ((window (get-buffer-window gnus-article-buffer))
2968 (select-window window)
2969 ;; We have to do this since selecting the window
2970 ;; may change the point. So we set the window point.
2971 (set-window-point window point)))
2972 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
2973 buffer-read-only handle name type b e display)
2974 (when (and (not ihandles)
2975 (not gnus-displaying-mime))
2976 ;; Top-level call; we clean up.
2977 (mm-destroy-parts gnus-article-mime-handles)
2978 (setq gnus-article-mime-handles handles
2979 gnus-article-mime-handle-alist nil)
2980 ;; We allow users to glean info from the handles.
2981 (when gnus-article-mime-part-function
2982 (gnus-mime-part-function handles)))
2984 (or (not (stringp (car handles)))
2987 (when (and (not ihandles)
2988 (not gnus-displaying-mime))
2989 ;; Clean up for mime parts.
2991 (delete-region (point) (point-max)))
2992 (let ((gnus-displaying-mime t))
2993 (gnus-mime-display-part handles)))
2996 (narrow-to-region (point) (point-max))
2997 (gnus-treat-article nil 1 1)
2999 ;; Highlight the headers.
3003 (narrow-to-region (point-min) (point))
3004 (gnus-treat-article 'head)))))))
3006 (defvar gnus-mime-display-multipart-as-mixed nil)
3008 (defun gnus-mime-display-part (handle)
3011 ((not (stringp (car handle)))
3012 (gnus-mime-display-single handle))
3013 ;; multipart/alternative
3014 ((and (equal (car handle) "multipart/alternative")
3015 (not gnus-mime-display-multipart-as-mixed))
3016 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3017 (push (cons id handle) gnus-article-mime-handle-alist)
3018 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3019 ;; multipart/related
3020 ((and (equal (car handle) "multipart/related")
3021 (not gnus-mime-display-multipart-as-mixed))
3022 ;;;!!!We should find the start part, but we just default
3023 ;;;!!!to the first part.
3024 (gnus-mime-display-part (cadr handle)))
3025 ;; Other multiparts are handled like multipart/mixed.
3027 (gnus-mime-display-mixed (cdr handle)))))
3029 (defun gnus-mime-part-function (handles)
3030 (if (stringp (car handles))
3031 (mapcar 'gnus-mime-part-function (cdr handles))
3032 (funcall gnus-article-mime-part-function handles)))
3034 (defun gnus-mime-display-mixed (handles)
3035 (mapcar 'gnus-mime-display-part handles))
3037 (defun gnus-mime-display-single (handle)
3038 (let ((type (car (mm-handle-type handle)))
3039 (ignored gnus-ignored-mime-types)
3046 (when (string-match (pop ignored) type)
3047 (throw 'ignored nil)))
3048 (if (and (setq not-attachment
3049 (or (not (mm-handle-disposition handle))
3050 (equal (car (mm-handle-disposition handle))
3052 (mm-attachment-override-p type)))
3053 (mm-automatic-display-p type)
3054 (or (mm-inlinable-part-p type)
3055 (mm-automatic-external-display-p type)))
3057 (when (equal (car (split-string type "/"))
3060 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3061 (push (cons id handle) gnus-article-mime-handle-alist)
3062 (when (or (not display)
3063 (not (gnus-unbuttonized-mime-type-p type)))
3064 (gnus-article-insert-newline)
3065 (gnus-insert-mime-button
3066 handle id (list (or display (and not-attachment text))))
3067 (gnus-article-insert-newline)
3068 (gnus-article-insert-newline)
3070 (let ((beg (point)))
3075 (let ((mail-parse-charset gnus-newsgroup-charset))
3076 (mm-display-part handle t))
3077 (goto-char (point-max)))
3078 ((and text not-attachment)
3081 (gnus-article-insert-newline)
3082 (mm-insert-inline handle (mm-get-part handle))
3083 (goto-char (point-max))))
3087 (narrow-to-region beg (point))
3089 nil (length gnus-article-mime-handle-alist)
3090 (1- (length gnus-article-mime-handles))
3091 (car (mm-handle-type handle))))))))))
3093 (defun gnus-unbuttonized-mime-type-p (type)
3094 "Say whether TYPE is to be unbuttonized."
3095 (unless gnus-inhibit-mime-unbuttonizing
3097 (let ((types gnus-unbuttonized-mime-types))
3099 (when (string-match (pop types) type)
3100 (throw 'found t)))))))
3102 (defun gnus-article-insert-newline ()
3103 "Insert a newline, but mark it as undeletable."
3104 (gnus-put-text-property
3105 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3107 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3108 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3111 handle buffer-read-only from props begend not-pref)
3112 (save-window-excursion
3115 (narrow-to-region (car ibegend)
3118 (goto-char (car ibegend))
3121 (delete-region (point-min) (point-max))
3122 (mm-remove-parts handles))
3123 (setq begend (list (point-marker)))
3125 (unless (setq not-pref (cadr (member preferred ihandles)))
3126 (setq not-pref (car ihandles)))
3128 (not (gnus-unbuttonized-mime-type-p
3129 "multipart/alternative")))
3130 (gnus-add-text-properties
3133 (insert (format "%d. " id))
3137 (unless ,(not ibegend)
3138 (setq gnus-article-mime-handle-alist
3139 ',gnus-article-mime-handle-alist))
3140 (gnus-mime-display-alternative
3141 ',ihandles ',not-pref ',begend ,id))
3142 local-map ,gnus-mime-button-map
3143 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3144 face ,gnus-article-button-face
3145 keymap ,gnus-mime-button-map
3148 (widget-convert-button 'link from (point)
3149 :action 'gnus-widget-press-button
3150 :button-keymap gnus-widget-button-keymap)
3152 (while (setq handle (pop handles))
3153 (gnus-add-text-properties
3156 (insert (format "(%c) %-18s"
3157 (if (equal handle preferred) ?* ? )
3158 (if (stringp (car handle))
3160 (car (mm-handle-type handle)))))
3164 (unless ,(not ibegend)
3165 (setq gnus-article-mime-handle-alist
3166 ',gnus-article-mime-handle-alist))
3167 (gnus-mime-display-alternative
3168 ',ihandles ',handle ',begend ,id))
3169 local-map ,gnus-mime-button-map
3170 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3171 face ,gnus-article-button-face
3172 keymap ,gnus-mime-button-map
3175 (widget-convert-button 'link from (point)
3176 :action 'gnus-widget-press-button
3177 :button-keymap gnus-widget-button-keymap)
3181 (if (stringp (car preferred))
3182 (gnus-display-mime preferred)
3183 (let ((mail-parse-charset gnus-newsgroup-charset))
3184 (mm-display-part preferred)))
3185 (goto-char (point-max))
3186 (setcdr begend (point-marker)))))
3188 (goto-char point))))
3190 (defun gnus-article-wash-status ()
3191 "Return a string which display status of article washing."
3193 (set-buffer gnus-article-buffer)
3194 (let ((cite (gnus-article-hidden-text-p 'cite))
3195 (headers (gnus-article-hidden-text-p 'headers))
3196 (boring (gnus-article-hidden-text-p 'boring-headers))
3197 (pgp (gnus-article-hidden-text-p 'pgp))
3198 (pem (gnus-article-hidden-text-p 'pem))
3199 (signature (gnus-article-hidden-text-p 'signature))
3200 (overstrike (gnus-article-hidden-text-p 'overstrike))
3201 (emphasis (gnus-article-hidden-text-p 'emphasis))
3202 (mime gnus-show-mime))
3203 (format "%c%c%c%c%c%c%c"
3205 (if (or headers boring) ?h ? )
3206 (if (or pgp pem) ?p ? )
3207 (if signature ?s ? )
3208 (if overstrike ?o ? )
3210 (if emphasis ?e ? )))))
3212 (fset 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3214 (defun gnus-article-maybe-hide-headers ()
3215 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3216 Provided for backwards compatibility."
3217 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3218 (not (save-excursion (set-buffer gnus-summary-buffer)
3219 gnus-have-all-headers)))
3220 (not gnus-inhibit-hiding))
3221 (gnus-article-hide-headers)))
3225 (defun gnus-output-to-file (file-name)
3226 "Append the current article to a file named FILE-NAME."
3227 (let ((artbuf (current-buffer)))
3229 (insert-buffer-substring artbuf)
3230 ;; Append newline at end of the buffer as separator, and then
3232 (goto-char (point-max))
3234 (append-to-file (point-min) (point-max) file-name)
3237 (defun gnus-narrow-to-page (&optional arg)
3238 "Narrow the article buffer to a page.
3239 If given a numerical ARG, move forward ARG pages."
3241 (setq arg (if arg (prefix-numeric-value arg) 0))
3243 (set-buffer gnus-article-buffer)
3244 (goto-char (point-min))
3246 ;; Remove any old next/prev buttons.
3247 (when (gnus-visual-p 'page-marker)
3248 (let ((buffer-read-only nil))
3249 (gnus-remove-text-with-property 'gnus-prev)
3250 (gnus-remove-text-with-property 'gnus-next)))
3253 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3255 (re-search-forward page-delimiter nil 'move arg)))
3256 (goto-char (match-end 0)))
3259 (if (re-search-forward page-delimiter nil 'move)
3262 (when (and (gnus-visual-p 'page-marker)
3263 (not (= (point-min) 1)))
3265 (goto-char (point-min))
3266 (gnus-insert-prev-page-button)))
3267 (when (and (gnus-visual-p 'page-marker)
3268 (< (+ (point-max) 2) (buffer-size)))
3270 (goto-char (point-max))
3271 (gnus-insert-next-page-button)))))
3273 ;; Article mode commands
3275 (defun gnus-article-goto-next-page ()
3276 "Show the next page of the article."
3278 (when (gnus-article-next-page)
3279 (goto-char (point-min))
3280 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3282 (defun gnus-article-goto-prev-page ()
3283 "Show the next page of the article."
3285 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3286 (gnus-article-prev-page nil)))
3288 (defun gnus-article-next-page (&optional lines)
3289 "Show the next page of the current article.
3290 If end of article, return non-nil. Otherwise return nil.
3291 Argument LINES specifies lines to be scrolled up."
3293 (move-to-window-line -1)
3296 (and (pos-visible-in-window-p) ;Not continuation line.
3298 ;; Nothing in this page.
3299 (if (or (not gnus-page-broken)
3302 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3304 (gnus-narrow-to-page 1) ;Go to next page.
3306 ;; More in this page.
3307 (let ((scroll-in-place nil))
3311 ;; Long lines may cause an end-of-buffer error.
3312 (goto-char (point-max)))))
3313 (move-to-window-line 0)
3316 (defun gnus-article-prev-page (&optional lines)
3317 "Show previous page of current article.
3318 Argument LINES specifies lines to be scrolled down."
3320 (move-to-window-line 0)
3321 (if (and gnus-page-broken
3323 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
3325 (gnus-narrow-to-page -1) ;Go to previous page.
3326 (goto-char (point-max))
3328 (let ((scroll-in-place nil))
3332 (beginning-of-buffer
3333 (goto-char (point-min))))
3334 (move-to-window-line 0)))))
3336 (defun gnus-article-refer-article ()
3337 "Read article specified by message-id around point."
3339 (let ((point (point)))
3340 (search-forward ">" nil t) ;Move point to end of "<....>".
3341 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
3342 (let ((message-id (match-string 1)))
3344 (set-buffer gnus-summary-buffer)
3345 (gnus-summary-refer-article message-id))
3347 (error "No references around point"))))
3349 (defun gnus-article-show-summary ()
3350 "Reconfigure windows to show summary buffer."
3352 (if (not (gnus-buffer-live-p gnus-summary-buffer))
3353 (error "There is no summary buffer for this article buffer")
3354 (gnus-article-set-globals)
3355 (gnus-configure-windows 'article)
3356 (gnus-summary-goto-subject gnus-current-article)
3357 (gnus-summary-position-point)))
3359 (defun gnus-article-describe-briefly ()
3360 "Describe article mode commands briefly."
3362 (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")))
3364 (defun gnus-article-summary-command ()
3365 "Execute the last keystroke in the summary buffer."
3367 (let ((obuf (current-buffer))
3368 (owin (current-window-configuration))
3370 (switch-to-buffer gnus-article-current-summary 'norecord)
3371 (setq func (lookup-key (current-local-map) (this-command-keys)))
3372 (call-interactively func)
3374 (set-window-configuration owin)
3375 (set-window-point (get-buffer-window (current-buffer)) (point))))
3377 (defun gnus-article-summary-command-nosave ()
3378 "Execute the last keystroke in the summary buffer."
3381 (pop-to-buffer gnus-article-current-summary 'norecord)
3382 (setq func (lookup-key (current-local-map) (this-command-keys)))
3383 (call-interactively func)))
3385 (defun gnus-article-check-buffer ()
3386 "Beep if not in an article buffer."
3387 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
3388 (error "Command invoked outside of a Gnus article buffer")))
3390 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
3391 "Read a summary buffer key sequence and execute it from the article buffer."
3393 (gnus-article-check-buffer)
3395 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
3396 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
3397 "=" "^" "\M-^" "|"))
3403 '("n" "Gn" "p" "Gp"))
3406 (set-buffer gnus-article-current-summary)
3407 (let (gnus-pick-mode)
3408 (push (or key last-command-event) unread-command-events)
3409 (setq keys (read-key-sequence nil))))
3412 (if (or (member keys nosaves)
3413 (member keys nosave-but-article)
3414 (member keys nosave-in-article))
3416 (save-window-excursion
3417 (pop-to-buffer gnus-article-current-summary 'norecord)
3418 ;; We disable the pick minor mode commands.
3419 (let (gnus-pick-mode)
3420 (setq func (lookup-key (current-local-map) keys))))
3423 (unless (member keys nosave-in-article)
3424 (set-buffer gnus-article-current-summary))
3425 (call-interactively func)
3426 (setq new-sum-point (point)))
3427 (when (member keys nosave-but-article)
3428 (pop-to-buffer gnus-article-buffer 'norecord)))
3429 ;; These commands should restore window configuration.
3430 (let ((obuf (current-buffer))
3431 (owin (current-window-configuration))
3433 (summary gnus-article-current-summary)
3434 func in-buffer selected)
3435 (if not-restore-window
3436 (pop-to-buffer summary 'norecord)
3437 (switch-to-buffer summary 'norecord))
3438 (setq in-buffer (current-buffer))
3439 ;; We disable the pick minor mode commands.
3440 (if (setq func (let (gnus-pick-mode)
3441 (lookup-key (current-local-map) keys)))
3443 (call-interactively func)
3444 (setq new-sum-point (point)))
3446 (when (eq in-buffer (current-buffer))
3447 (setq selected (gnus-summary-select-article))
3449 (unless not-restore-window
3450 (set-window-configuration owin))
3451 (when (eq selected 'old)
3453 (set-window-start (get-buffer-window (current-buffer))
3455 (set-window-point (get-buffer-window (current-buffer))
3457 (let ((win (get-buffer-window gnus-article-current-summary)))
3459 (set-window-point win new-sum-point))))))))
3461 (defun gnus-article-hide (&optional arg force)
3462 "Hide all the gruft in the current article.
3463 This means that PGP stuff, signatures, cited text and (some)
3464 headers will be hidden.
3465 If given a prefix, show the hidden text instead."
3466 (interactive (append (gnus-article-hidden-arg) (list 'force)))
3467 (gnus-article-hide-headers arg)
3468 (gnus-article-hide-pgp arg)
3469 (gnus-article-hide-citation-maybe arg force)
3470 (gnus-article-hide-signature arg))
3472 (defun gnus-article-maybe-highlight ()
3473 "Do some article highlighting if article highlighting is requested."
3474 (when (gnus-visual-p 'article-highlight 'highlight)
3475 (gnus-article-highlight-some)))
3477 (defun gnus-check-group-server ()
3478 ;; Make sure the connection to the server is alive.
3479 (unless (gnus-server-opened
3480 (gnus-find-method-for-group gnus-newsgroup-name))
3481 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
3482 (gnus-request-group gnus-newsgroup-name t)))
3484 (defun gnus-request-article-this-buffer (article group)
3485 "Get an article and insert it into this buffer."
3486 (let (do-update-line sparse-header)
3490 (gnus-kill-all-overlays)
3491 (setq group (or group gnus-newsgroup-name))
3493 ;; Using `gnus-request-article' directly will insert the article into
3494 ;; `nntp-server-buffer' - so we'll save some time by not having to
3495 ;; copy it from the server buffer into the article buffer.
3497 ;; We only request an article by message-id when we do not have the
3498 ;; headers for it, so we'll have to get those.
3499 (when (stringp article)
3500 (let ((gnus-override-method gnus-refer-article-method))
3501 (gnus-read-header article)))
3503 ;; If the article number is negative, that means that this article
3504 ;; doesn't belong in this newsgroup (possibly), so we find its
3505 ;; message-id and request it by id instead of number.
3506 (when (and (numberp article)
3508 (get-buffer gnus-summary-buffer)
3509 (gnus-buffer-exists-p gnus-summary-buffer))
3511 (set-buffer gnus-summary-buffer)
3512 (let ((header (gnus-summary-article-header article)))
3515 ((memq article gnus-newsgroup-sparse)
3516 ;; This is a sparse gap article.
3517 (setq do-update-line article)
3518 (setq article (mail-header-id header))
3519 (let ((gnus-override-method gnus-refer-article-method))
3520 (setq sparse-header (gnus-read-header article)))
3521 (setq gnus-newsgroup-sparse
3522 (delq article gnus-newsgroup-sparse)))
3524 ;; It's a real article.
3525 (setq article (mail-header-id header)))
3527 ;; It is an extracted pseudo-article.
3528 (setq article 'pseudo)
3529 (gnus-request-pseudo-article header))))
3531 (let ((method (gnus-find-method-for-group
3532 gnus-newsgroup-name)))
3533 (when (and (eq (car method) 'nneething)
3536 (file-name-as-directory
3537 (or (cadr (assq 'nneething-address method))
3539 (mail-header-subject header))))
3540 (when (file-directory-p dir)
3541 (setq article 'nneething)
3542 (gnus-group-enter-directory dir))))))))
3545 ;; Refuse to select canceled articles.
3546 ((and (numberp article)
3548 (get-buffer gnus-summary-buffer)
3549 (gnus-buffer-exists-p gnus-summary-buffer)
3550 (eq (cdr (save-excursion
3551 (set-buffer gnus-summary-buffer)
3552 (assq article gnus-newsgroup-reads)))
3553 gnus-canceled-mark))
3555 ;; Check the backlog.
3556 ((and gnus-keep-backlog
3557 (gnus-backlog-request-article group article (current-buffer)))
3559 ;; Check asynchronous pre-fetch.
3560 ((gnus-async-request-fetched-article group article (current-buffer))
3561 (gnus-async-prefetch-next group article gnus-summary-buffer)
3562 (when (and (numberp article) gnus-keep-backlog)
3563 (gnus-backlog-enter-article group article (current-buffer)))
3566 ((and gnus-use-cache
3568 (gnus-cache-request-article article group))
3570 ;; Get the article and put into the article buffer.
3571 ((or (stringp article) (numberp article))
3572 (let ((gnus-override-method
3573 (and (stringp article) gnus-refer-article-method))
3574 (buffer-read-only nil))
3576 (gnus-kill-all-overlays)
3577 (gnus-check-group-server)
3578 (when (gnus-request-article article group (current-buffer))
3579 (when (numberp article)
3580 (gnus-async-prefetch-next group article gnus-summary-buffer)
3581 (when gnus-keep-backlog
3582 (gnus-backlog-enter-article
3583 group article (current-buffer))))
3588 ;; Associate this article with the current summary buffer.
3589 (setq gnus-article-current-summary gnus-summary-buffer)
3591 ;; Take the article from the original article buffer
3592 ;; and place it in the buffer it's supposed to be in.
3593 (when (and (get-buffer gnus-article-buffer)
3594 (equal (buffer-name (current-buffer))
3595 (buffer-name (get-buffer gnus-article-buffer))))
3597 (if (get-buffer gnus-original-article-buffer)
3598 (set-buffer gnus-original-article-buffer)
3599 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3600 (buffer-disable-undo)
3601 (setq major-mode 'gnus-original-article-mode)
3602 (setq buffer-read-only t))
3603 (let (buffer-read-only)
3605 (insert-buffer-substring gnus-article-buffer))
3606 (setq gnus-original-article (cons group article)))
3609 (run-hooks 'gnus-article-decode-hook)
3610 ;; Mark article as decoded or not.
3611 (setq gnus-article-decoded-p gnus-article-decode-hook))
3613 ;; Update sparse articles.
3614 (when (and do-update-line
3615 (or (numberp article)
3617 (let ((buf (current-buffer)))
3618 (set-buffer gnus-summary-buffer)
3619 (gnus-summary-update-article do-update-line sparse-header)
3620 (gnus-summary-goto-subject do-update-line nil t)
3621 (set-window-point (get-buffer-window (current-buffer) t)
3623 (set-buffer buf))))))
3629 (defcustom gnus-article-edit-mode-hook nil
3630 "Hook run in article edit mode buffers."
3631 :group 'gnus-article-various
3634 (defcustom gnus-article-edit-article-setup-function
3635 'gnus-article-mime-edit-article-setup
3636 "Function called to setup an editing article buffer."
3637 :group 'gnus-article-various
3640 (defvar gnus-article-edit-done-function nil)
3642 (defvar gnus-article-edit-mode-map nil)
3644 ;; Should we be using derived.el for this?
3645 (unless gnus-article-edit-mode-map
3646 (setq gnus-article-edit-mode-map (make-sparse-keymap))
3647 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
3649 (gnus-define-keys gnus-article-edit-mode-map
3650 "\C-c\C-c" gnus-article-edit-done
3651 "\C-c\C-k" gnus-article-edit-exit)
3653 (gnus-define-keys (gnus-article-edit-wash-map
3654 "\C-c\C-w" gnus-article-edit-mode-map)
3655 "f" gnus-article-edit-full-stops))
3657 (defun gnus-article-edit-mode ()
3658 "Major mode for editing articles.
3659 This is an extended text-mode.
3661 \\{gnus-article-edit-mode-map}"
3663 (setq major-mode 'gnus-article-edit-mode)
3664 (setq mode-name "Article Edit")
3665 (use-local-map gnus-article-edit-mode-map)
3666 (make-local-variable 'gnus-article-edit-done-function)
3667 (make-local-variable 'gnus-prev-winconf)
3668 (setq buffer-read-only nil)
3669 (buffer-enable-undo)
3671 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
3673 (defun gnus-article-edit (&optional force)
3674 "Edit the current article.
3675 This will have permanent effect only in mail groups.
3676 If FORCE is non-nil, allow editing of articles even in read-only
3679 (when (and (not force)
3680 (gnus-group-read-only-p))
3681 (error "The current newsgroup does not support article editing"))
3682 (gnus-article-date-original)
3683 (gnus-article-edit-article
3685 `(lambda (no-highlight)
3687 (gnus-summary-edit-article-done
3688 ,(or (mail-header-references gnus-current-headers) "")
3689 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
3691 (defun gnus-article-edit-article (start-func exit-func)
3692 "Start editing the contents of the current article buffer."
3693 (let ((winconf (current-window-configuration)))
3694 (set-buffer gnus-article-buffer)
3695 (gnus-article-edit-mode)
3696 (funcall start-func)
3697 ;;(gnus-article-delete-text-of-type 'annotation)
3698 ;;(gnus-set-text-properties (point-min) (point-max) nil)
3699 (gnus-configure-windows 'edit-article)
3700 (setq gnus-article-edit-done-function exit-func)
3701 (setq gnus-prev-winconf winconf)
3702 (when gnus-article-edit-article-setup-function
3703 (funcall gnus-article-edit-article-setup-function))
3704 (gnus-message 6 "C-c C-c to end edits")))
3706 (defun gnus-article-edit-done (&optional arg)
3707 "Update the article edits and exit."
3712 (when (article-goto-body)
3713 (let ((lines (count-lines (point) (point-max)))
3714 (length (- (point-max) (point)))
3715 (case-fold-search t)
3716 (body (copy-marker (point))))
3717 (goto-char (point-min))
3718 (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
3719 (delete-region (match-beginning 1) (match-end 1))
3720 (insert (number-to-string length)))
3721 (goto-char (point-min))
3722 (when (re-search-forward
3723 "^x-content-length:[ \t]\\([0-9]+\\)" body t)
3724 (delete-region (match-beginning 1) (match-end 1))
3725 (insert (number-to-string length)))
3726 (goto-char (point-min))
3727 (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
3728 (delete-region (match-beginning 1) (match-end 1))
3729 (insert (number-to-string lines)))))))
3730 (let ((func gnus-article-edit-done-function)
3731 (buf (current-buffer))
3732 (start (window-start)))
3733 (remove-hook 'gnus-article-mode-hook
3734 'gnus-article-mime-edit-article-unwind)
3735 (gnus-article-edit-exit)
3738 (let ((buffer-read-only nil))
3740 ;; The cache and backlog have to be flushed somewhat.
3741 (when gnus-keep-backlog
3742 (gnus-backlog-remove-article
3743 (car gnus-article-current) (cdr gnus-article-current)))
3744 ;; Flush original article as well.
3746 (when (get-buffer gnus-original-article-buffer)
3747 (set-buffer gnus-original-article-buffer)
3748 (setq gnus-original-article nil)))
3749 (when gnus-use-cache
3750 (gnus-cache-update-article
3751 (car gnus-article-current) (cdr gnus-article-current))))
3753 (set-window-start (get-buffer-window buf) start)
3754 (set-window-point (get-buffer-window buf) (point))))
3756 (defun gnus-article-edit-exit ()
3757 "Exit the article editing without updating."
3759 ;; We remove all text props from the article buffer.
3760 (let ((buf (format "%s" (buffer-string)))
3761 (curbuf (current-buffer))
3763 (window-start (window-start)))
3766 (let ((winconf gnus-prev-winconf))
3768 (set-window-configuration winconf)
3769 ;; Tippy-toe some to make sure that point remains where it was.
3770 (save-current-buffer
3772 (set-window-start (get-buffer-window (current-buffer)) window-start)
3775 (defun gnus-article-edit-full-stops ()
3776 "Interactively repair spacing at end of sentences."
3779 (goto-char (point-min))
3780 (search-forward-regexp "^$" nil t)
3781 (let ((case-fold-search nil))
3782 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
3785 ;;; Article editing with MIME-Edit
3788 (defcustom gnus-article-mime-edit-article-setup-hook nil
3789 "Hook run after setting up a MIME editing article buffer."
3790 :group 'gnus-article-various
3793 (defun gnus-article-mime-edit-article-unwind ()
3794 "Unwind `gnus-article-buffer' if article editing was given up."
3795 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3796 (when mime-edit-mode-flag
3797 (mime-edit-exit 'nomime 'no-error)
3799 (when (featurep 'font-lock)
3800 (setq font-lock-defaults nil)
3801 (font-lock-mode 0)))
3803 (defun gnus-article-mime-edit-article-setup ()
3804 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
3805 after replacing with the original article."
3806 (setq gnus-show-mime t)
3807 (setq gnus-article-edit-done-function
3808 `(lambda (&rest args)
3809 (when mime-edit-mode-flag
3812 (goto-char (point-min))
3813 (let (case-fold-search)
3814 (when (re-search-forward
3815 (format "^%s$" (regexp-quote mail-header-separator))
3817 (replace-match "")))
3818 (when (featurep 'font-lock)
3819 (setq font-lock-defaults nil)
3821 (apply ,gnus-article-edit-done-function args)
3822 (set-buffer gnus-original-article-buffer)
3824 (insert-buffer gnus-article-buffer)
3825 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3826 (gnus-article-prepare-display)))
3827 (substitute-key-definition
3828 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
3829 gnus-article-edit-mode-map)
3831 (insert-buffer gnus-original-article-buffer)
3833 (when (featurep 'font-lock)
3834 (set (make-local-variable 'font-lock-defaults)
3835 '(message-font-lock-keywords t))
3836 (font-lock-set-defaults)
3837 (turn-on-font-lock))
3838 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
3839 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
3841 (defun gnus-article-mime-edit-exit ()
3842 "Exit the article MIME editing without updating."
3844 (let ((winconf gnus-prev-winconf)
3846 (when mime-edit-mode-flag
3849 (goto-char (point-min))
3850 (let (case-fold-search)
3851 (when (re-search-forward
3852 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
3853 (replace-match "")))
3854 (when (featurep 'font-lock)
3855 (setq font-lock-defaults nil)
3857 ;; We remove all text props from the article buffer.
3858 (setq buf (format "%s" (buffer-string)))
3859 (set-buffer (get-buffer-create gnus-original-article-buffer))
3862 (setq gnus-current-headers (gnus-article-make-full-mail-header))
3863 (gnus-article-prepare-display)
3864 (set-window-configuration winconf)))
3867 ;;; Article highlights
3870 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
3872 ;;; Internal Variables:
3874 (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\\)"
3875 "Regular expression that matches URLs."
3876 :group 'gnus-article-buttons
3879 (defcustom gnus-button-alist
3880 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
3881 0 t gnus-button-message-id 2)
3882 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
3883 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
3885 gnus-button-fetch-group 4)
3886 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
3887 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
3888 t gnus-button-message-id 3)
3889 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
3890 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
3891 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
3892 ;; This is how URLs _should_ be embedded in text...
3893 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1)
3895 (,gnus-button-url-regexp 0 t gnus-button-url 0))
3896 "*Alist of regexps matching buttons in article bodies.
3898 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
3899 REGEXP: is the string matching text around the button,
3900 BUTTON: is the number of the regexp grouping actually matching the button,
3901 FORM: is a lisp expression which must eval to true for the button to
3903 CALLBACK: is the function to call when the user push this button, and each
3904 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
3906 CALLBACK can also be a variable, in that case the value of that
3907 variable it the real callback function."
3908 :group 'gnus-article-buttons
3909 :type '(repeat (list regexp
3910 (integer :tag "Button")
3912 (function :tag "Callback")
3915 (integer :tag "Regexp group")))))
3917 (defcustom gnus-header-button-alist
3918 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
3919 0 t gnus-button-message-id 0)
3920 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
3921 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
3922 0 t gnus-button-mailto 0)
3923 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3924 ("^Subject:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3925 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0)
3926 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
3927 gnus-button-message-id 3))
3928 "*Alist of headers and regexps to match buttons in article heads.
3930 This alist is very similar to `gnus-button-alist', except that each
3931 alist has an additional HEADER element first in each entry:
3933 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
3935 HEADER is a regexp to match a header. For a fuller explanation, see
3936 `gnus-button-alist'."
3937 :group 'gnus-article-buttons
3938 :group 'gnus-article-headers
3939 :type '(repeat (list (regexp :tag "Header")
3941 (integer :tag "Button")
3943 (function :tag "Callback")
3946 (integer :tag "Regexp group")))))
3948 (defvar gnus-button-regexp nil)
3949 (defvar gnus-button-marker-list nil)
3950 ;; Regexp matching any of the regexps from `gnus-button-alist'.
3952 (defvar gnus-button-last nil)
3953 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
3957 (defun gnus-article-push-button (event)
3958 "Check text under the mouse pointer for a callback function.
3959 If the text under the mouse pointer has a `gnus-callback' property,
3960 call it with the value of the `gnus-data' text property."
3962 (set-buffer (window-buffer (posn-window (event-start event))))
3963 (let* ((pos (posn-point (event-start event)))
3964 (data (get-text-property pos 'gnus-data))
3965 (fun (get-text-property pos 'gnus-callback)))
3968 (funcall fun data))))
3970 (defun gnus-article-press-button ()
3971 "Check text at point for a callback function.
3972 If the text at point has a `gnus-callback' property,
3973 call it with the value of the `gnus-data' text property."
3975 (let* ((data (get-text-property (point) 'gnus-data))
3976 (fun (get-text-property (point) 'gnus-callback)))
3978 (funcall fun data))))
3980 (defun gnus-article-prev-button (n)
3981 "Move point to N buttons backward.
3982 If N is negative, move forward instead."
3984 (gnus-article-next-button (- n)))
3986 (defun gnus-article-next-button (n)
3987 "Move point to N buttons forward.
3988 If N is negative, move backward instead."
3990 (let ((function (if (< n 0) 'previous-single-property-change
3991 'next-single-property-change))
3992 (inhibit-point-motion-hooks t)
3994 (limit (if (< n 0) (point-min) (point-max))))
3996 (while (and (not (= limit (point)))
3998 ;; Skip past the current button.
3999 (when (get-text-property (point) 'gnus-callback)
4000 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4001 ;; Go to the next (or previous) button.
4002 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
4003 ;; Put point at the start of the button.
4004 (when (and backward (not (get-text-property (point) 'gnus-callback)))
4005 (goto-char (funcall function (point) 'gnus-callback nil limit)))
4006 ;; Skip past intangible buttons.
4007 (when (get-text-property (point) 'intangible)
4011 (gnus-message 5 "No more buttons"))
4014 (defun gnus-article-highlight (&optional force)
4015 "Highlight current article.
4016 This function calls `gnus-article-highlight-headers',
4017 `gnus-article-highlight-citation',
4018 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4019 do the highlighting. See the documentation for those functions."
4020 (interactive (list 'force))
4021 (gnus-article-highlight-headers)
4022 (gnus-article-highlight-citation force)
4023 (gnus-article-highlight-signature)
4024 (gnus-article-add-buttons force)
4025 (gnus-article-add-buttons-to-head))
4027 (defun gnus-article-highlight-some (&optional force)
4028 "Highlight current article.
4029 This function calls `gnus-article-highlight-headers',
4030 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4031 do the highlighting. See the documentation for those functions."
4032 (interactive (list 'force))
4033 (gnus-article-highlight-headers)
4034 (gnus-article-highlight-signature)
4035 (gnus-article-add-buttons))
4037 (defun gnus-article-highlight-headers ()
4038 "Highlight article headers as specified by `gnus-header-face-alist'."
4041 (set-buffer gnus-article-buffer)
4043 (let ((alist gnus-header-face-alist)
4044 (buffer-read-only nil)
4045 (case-fold-search t)
4046 (inhibit-point-motion-hooks t)
4047 entry regexp header-face field-face from hpoints fpoints)
4048 (article-narrow-to-head)
4049 (while (setq entry (pop alist))
4050 (goto-char (point-min))
4051 (setq regexp (concat "^\\("
4052 (if (string-equal "" (nth 0 entry))
4056 header-face (nth 1 entry)
4057 field-face (nth 2 entry))
4058 (while (and (re-search-forward regexp nil t)
4062 (unless (search-forward ":" nil t)
4064 (when (and header-face
4065 (not (memq (point) hpoints)))
4066 (push (point) hpoints)
4067 (gnus-put-text-property from (point) 'face header-face))
4068 (when (and field-face
4069 (not (memq (setq from (point)) fpoints)))
4071 (if (re-search-forward "^[^ \t]" nil t)
4073 (goto-char (point-max)))
4074 (gnus-put-text-property from (point) 'face field-face))))))))
4076 (defun gnus-article-highlight-signature ()
4077 "Highlight the signature in an article.
4078 It does this by highlighting everything after
4079 `gnus-signature-separator' using `gnus-signature-face'."
4082 (set-buffer gnus-article-buffer)
4083 (let ((buffer-read-only nil)
4084 (inhibit-point-motion-hooks t))
4086 (when (and gnus-signature-face
4087 (gnus-article-narrow-to-signature))
4088 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4089 'face gnus-signature-face)
4091 (gnus-article-search-signature)
4092 (let ((start (match-beginning 0))
4093 (end (set-marker (make-marker) (1+ (match-end 0)))))
4094 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4097 (defun gnus-button-in-region-p (b e prop)
4098 "Say whether PROP exists in the region."
4099 (text-property-not-all b e prop nil))
4101 (defun gnus-article-add-buttons (&optional force)
4102 "Find external references in the article and make buttons of them.
4103 \"External references\" are things like Message-IDs and URLs, as
4104 specified by `gnus-button-alist'."
4105 (interactive (list 'force))
4107 (set-buffer gnus-article-buffer)
4108 (let ((buffer-read-only nil)
4109 (inhibit-point-motion-hooks t)
4110 (case-fold-search t)
4111 (alist gnus-button-alist)
4113 ;; Remove all old markers.
4115 (while (setq marker (pop gnus-button-marker-list))
4117 (when (setq entry (gnus-button-entry))
4118 (put-text-property (match-beginning (nth 1 entry))
4119 (match-end (nth 1 entry))
4120 'gnus-callback nil))
4121 (set-marker marker nil)))
4122 ;; We skip the headers.
4125 (while (setq entry (pop alist))
4126 (setq regexp (car entry))
4128 (while (re-search-forward regexp nil t)
4129 (let* ((start (and entry (match-beginning (nth 1 entry))))
4130 (end (and entry (match-end (nth 1 entry))))
4131 (from (match-beginning 0)))
4132 (when (and (or (eq t (nth 2 entry))
4133 (eval (nth 2 entry)))
4134 (not (gnus-button-in-region-p
4135 start end 'gnus-callback)))
4136 ;; That optional form returned non-nil, so we add the
4138 (gnus-article-add-button
4139 start end 'gnus-button-push
4140 (car (push (set-marker (make-marker) from)
4141 gnus-button-marker-list))))))))))
4143 ;; Add buttons to the head of an article.
4144 (defun gnus-article-add-buttons-to-head ()
4145 "Add buttons to the head of the article."
4148 (set-buffer gnus-article-buffer)
4150 (let ((buffer-read-only nil)
4151 (inhibit-point-motion-hooks t)
4152 (case-fold-search t)
4153 (alist gnus-header-button-alist)
4155 (article-narrow-to-head)
4157 ;; Each alist entry.
4158 (setq entry (car alist)
4160 (goto-char (point-min))
4161 (while (re-search-forward (car entry) nil t)
4162 ;; Each header matching the entry.
4163 (setq beg (match-beginning 0))
4164 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4165 (match-beginning 0))
4168 (while (re-search-forward (nth 1 entry) end t)
4169 ;; Each match within a header.
4170 (let* ((entry (cdr entry))
4171 (start (match-beginning (nth 1 entry)))
4172 (end (match-end (nth 1 entry)))
4173 (form (nth 2 entry)))
4174 (goto-char (match-end 0))
4176 (gnus-article-add-button
4177 start end (nth 3 entry)
4178 (buffer-substring (match-beginning (nth 4 entry))
4179 (match-end (nth 4 entry)))))))
4180 (goto-char end)))))))
4182 ;;; External functions:
4184 (defun gnus-article-add-button (from to fun &optional data)
4185 "Create a button between FROM and TO with callback FUN and data DATA."
4186 (when gnus-article-button-face
4187 (gnus-overlay-put (gnus-make-overlay from to)
4188 'face gnus-article-button-face))
4189 (gnus-add-text-properties
4191 (nconc (and gnus-article-mouse-face
4192 (list gnus-mouse-face-prop gnus-article-mouse-face))
4193 (list 'gnus-callback fun)
4194 (and data (list 'gnus-data data)))))
4196 ;;; Internal functions:
4198 (defun gnus-article-set-globals ()
4200 (set-buffer gnus-summary-buffer)
4201 (gnus-set-global-variables)))
4203 (defun gnus-signature-toggle (end)
4205 (set-buffer gnus-article-buffer)
4206 (let ((buffer-read-only nil)
4207 (inhibit-point-motion-hooks t))
4208 (if (get-text-property end 'invisible)
4209 (gnus-article-unhide-text end (point-max))
4210 (gnus-article-hide-text end (point-max) gnus-hidden-properties)))))
4212 (defun gnus-button-entry ()
4213 ;; Return the first entry in `gnus-button-alist' matching this place.
4214 (let ((alist gnus-button-alist)
4217 (setq entry (pop alist))
4218 (if (looking-at (car entry))
4223 (defun gnus-button-push (marker)
4224 ;; Push button starting at MARKER.
4227 (let* ((entry (gnus-button-entry))
4228 (inhibit-point-motion-hooks t)
4230 (args (mapcar (lambda (group)
4231 (let ((string (match-string group)))
4232 (gnus-set-text-properties
4233 0 (length string) nil string)
4240 (fboundp (symbol-value fun)))
4241 (apply (symbol-value fun) args))
4243 (gnus-message 1 "You must define `%S' to use this button"
4244 (cons fun args)))))))
4246 (defun gnus-button-message-id (message-id)
4249 (set-buffer gnus-summary-buffer)
4250 (gnus-summary-refer-article message-id)))
4252 (defun gnus-button-fetch-group (address)
4253 "Fetch GROUP specified by ADDRESS."
4254 (if (not (string-match "[:/]" address))
4255 ;; This is just a simple group url.
4256 (gnus-group-read-ephemeral-group address gnus-select-method)
4257 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4259 (error "Can't parse %s" address)
4260 (gnus-group-read-ephemeral-group
4261 (match-string 4 address)
4262 `(nntp ,(match-string 1 address)
4263 (nntp-address ,(match-string 1 address))
4264 (nntp-port-number ,(if (match-end 3)
4265 (match-string 3 address)
4268 (defun gnus-url-parse-query-string (query &optional downcase)
4269 (let (retval pairs cur key val)
4270 (setq pairs (split-string query "&"))
4272 (setq cur (car pairs)
4274 (if (not (string-match "=" cur))
4276 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4277 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4279 (setq key (downcase key)))
4280 (setq cur (assoc key retval))
4282 (setcdr cur (cons val (cdr cur)))
4283 (setq retval (cons (list key val) retval)))))
4286 (defun gnus-url-unhex (x)
4293 (defun gnus-url-unhex-string (str &optional allow-newlines)
4294 "Remove %XXX embedded spaces, etc in a url.
4295 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4296 decoding of carriage returns and line feeds in the string, which is normally
4297 forbidden in URL encoding."
4298 (setq str (or str ""))
4300 (case-fold-search t))
4301 (while (string-match "%[0-9a-f][0-9a-f]" str)
4302 (let* ((start (match-beginning 0))
4303 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4305 (gnus-url-unhex (elt str (+ start 2))))))
4307 tmp (substring str 0 start)
4310 (char-to-string code))
4311 ((or (= code ?\n) (= code ?\r))
4313 (t (char-to-string code))))
4314 str (substring str (match-end 0)))))
4315 (setq tmp (concat tmp str))
4318 (defun gnus-url-mailto (url)
4319 ;; Send mail to someone
4320 (when (string-match "mailto:/*\\(.*\\)" url)
4321 (setq url (substring url (match-beginning 1) nil)))
4322 (let (to args subject func)
4323 (if (string-match (regexp-quote "?") url)
4324 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4325 args (gnus-url-parse-query-string
4326 (substring url (match-end 0) nil) t))
4327 (setq to (gnus-url-unhex-string url)))
4328 (setq args (cons (list "to" to) args)
4329 subject (cdr-safe (assoc "subject" args)))
4330 (gnus-setup-message 'reply
4333 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4336 (message-position-on-field (caar args)))
4337 (insert (mapconcat 'identity (cdar args) ", "))
4338 (setq args (cdr args)))
4341 (message-goto-subject)))))
4343 (defun gnus-button-mailto (address)
4345 (set-buffer (gnus-copy-article-buffer))
4346 (gnus-setup-message 'reply
4347 (message-reply address)))
4349 (defun gnus-button-reply (address)
4350 ;; Reply to ADDRESS.
4351 (gnus-setup-message 'reply
4352 (message-reply address)))
4354 (defun gnus-button-url (address)
4356 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4357 (if (listp browse-url-browser-function)
4358 (browse-url address)
4359 (funcall browse-url-browser-function address)))
4361 (defun gnus-button-embedded-url (address)
4363 ;; In Emacs 20, `browse-url-browser-function' may be an alist.
4364 (if (listp browse-url-browser-function)
4365 (browse-url (gnus-strip-whitespace address))
4366 (funcall browse-url-browser-function (gnus-strip-whitespace address))))
4368 ;;; Next/prev buttons in the article buffer.
4370 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4371 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4373 (defvar gnus-prev-page-map nil)
4374 (unless gnus-prev-page-map
4375 (setq gnus-prev-page-map (make-sparse-keymap))
4376 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4377 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4379 (defun gnus-insert-prev-page-button ()
4380 (let ((buffer-read-only nil))
4382 gnus-prev-page-line-format nil
4383 `(gnus-prev t local-map ,gnus-prev-page-map
4384 gnus-callback gnus-article-button-prev-page
4385 article-type annotation))))
4387 (defvar gnus-next-page-map nil)
4388 (unless gnus-next-page-map
4389 (setq gnus-next-page-map (make-keymap))
4390 (suppress-keymap gnus-prev-page-map)
4391 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4392 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4394 (defun gnus-button-next-page ()
4395 "Go to the next page."
4397 (let ((win (selected-window)))
4398 (select-window (get-buffer-window gnus-article-buffer t))
4399 (gnus-article-next-page)
4400 (select-window win)))
4402 (defun gnus-button-prev-page ()
4403 "Go to the prev page."
4405 (let ((win (selected-window)))
4406 (select-window (get-buffer-window gnus-article-buffer t))
4407 (gnus-article-prev-page)
4408 (select-window win)))
4410 (defun gnus-insert-next-page-button ()
4411 (let ((buffer-read-only nil))
4412 (gnus-eval-format gnus-next-page-line-format nil
4414 t local-map ,gnus-next-page-map
4415 gnus-callback gnus-article-button-next-page
4416 article-type annotation))))
4418 (defun gnus-article-button-next-page (arg)
4419 "Go to the next page."
4421 (let ((win (selected-window)))
4422 (select-window (get-buffer-window gnus-article-buffer t))
4423 (gnus-article-next-page)
4424 (select-window win)))
4426 (defun gnus-article-button-prev-page (arg)
4427 "Go to the prev page."
4429 (let ((win (selected-window)))
4430 (select-window (get-buffer-window gnus-article-buffer t))
4431 (gnus-article-prev-page)
4432 (select-window win)))
4434 (defvar gnus-decode-header-methods
4435 '(mail-decode-encoded-word-region)
4436 "List of methods used to decode headers.
4438 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item is
4439 FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
4440 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
4441 whose names match REGEXP.
4444 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
4445 mail-decode-encoded-word-region
4446 (\"chinese\" . rfc1843-decode-region))
4449 (defvar gnus-decode-header-methods-cache nil)
4451 (defun gnus-multi-decode-header (start end)
4452 "Apply the functions from `gnus-encoded-word-methods' that match."
4453 (unless (and gnus-decode-header-methods-cache
4454 (eq gnus-newsgroup-name
4455 (car gnus-decode-header-methods-cache)))
4456 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
4459 (nconc gnus-decode-header-methods-cache (list x))
4460 (if (and gnus-newsgroup-name
4461 (string-match (car x) gnus-newsgroup-name))
4462 (nconc gnus-decode-header-methods-cache
4464 gnus-decode-header-methods))
4465 (let ((xlist gnus-decode-header-methods-cache))
4468 (narrow-to-region start end)
4470 (funcall (pop xlist) (point-min) (point-max))))))
4473 ;;; Treatment top-level handling.
4476 (defun gnus-treat-article (condition &optional part-number total-parts type)
4477 (let ((length (- (point-max) (point-min)))
4478 (alist gnus-treatment-function-alist)
4479 (article-goto-body-goes-to-point-min-p t)
4483 (let ((list gnus-article-treat-types))
4485 (when (string-match (pop list) type)
4486 (throw 'found t)))))))
4488 (when (gnus-visual-p 'article-highlight 'highlight)
4489 (gnus-run-hooks 'gnus-part-display-hook)
4490 (while (setq elem (pop alist))
4491 (setq val (symbol-value (car elem)))
4492 (when (and (or (consp val)
4494 (gnus-treat-predicate val))
4496 (funcall (cadr elem))))))))
4498 ;; Dynamic variables.
4499 (defvar part-number)
4500 (defvar total-parts)
4504 (defun gnus-treat-predicate (val)
4515 (eq part-number total-parts))
4519 (let ((pred (pop val)))
4522 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
4524 (apply 'gnus-and (mapcar 'gnus-tread-predicate val)))
4526 (not (gnus-treat-predicate val)))
4528 (equal (cadr val) type))
4530 (error "%S is not a valid predicate" pred)))))
4532 (error "%S is not a valid value" val))))
4538 (defun gnus-article-header-presentation-method (entity situation)
4539 (mime-insert-header entity)
4542 (set-alist 'mime-header-presentation-method-alist
4543 'gnus-original-article-mode
4544 #'gnus-article-header-presentation-method)
4546 (defun gnus-mime-preview-quitting-method ()
4547 (mime-preview-kill-buffer)
4548 (delete-other-windows)
4549 (gnus-article-show-summary)
4550 (gnus-summary-select-article gnus-show-all-headers t))
4552 (set-alist 'mime-preview-quitting-method-alist
4553 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
4555 (defun gnus-following-method (buf)
4558 (message-yank-original)
4560 (goto-char (point-min))
4563 (set-alist 'mime-preview-following-method-alist
4564 'gnus-original-article-mode #'gnus-following-method)
4566 (set-alist 'mime-preview-over-to-previous-method-alist
4567 'gnus-original-article-mode
4569 (gnus-article-read-summary-keys
4570 nil (gnus-character-to-event ?P))))
4572 (set-alist 'mime-preview-over-to-next-method-alist
4573 'gnus-original-article-mode'
4575 (gnus-article-read-summary-keys
4576 nil (gnus-character-to-event ?N))))
4586 (run-hooks 'gnus-art-load-hook)
4588 ;;; gnus-art.el ends here