1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 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))
31 (eval-when-compile (require 'static))
42 ;; Avoid byte-compile warnings.
51 (defgroup gnus-article nil
53 :link '(custom-manual "(gnus)The Article Buffer")
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
72 (defgroup gnus-article-signature nil
74 :link '(custom-manual "(gnus)Article Signature")
77 (defgroup gnus-article-headers nil
79 :link '(custom-manual "(gnus)Hiding Headers")
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
92 (defgroup gnus-article-saving nil
94 :link '(custom-manual "(gnus)Saving Articles")
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
113 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
114 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
115 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
116 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
117 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
118 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
119 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
120 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
121 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
122 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
123 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
124 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
125 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
126 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
127 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
128 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
129 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
130 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
131 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
132 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
133 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
134 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
135 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
136 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
137 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
138 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
139 "^X-Received:" "^Content-length:" "X-precedence:")
140 "*All headers that start with this regexp will be hidden.
141 This variable can also be a list of regexps of headers to be ignored.
142 If `gnus-visible-headers' is non-nil, this variable will be ignored."
143 :type '(choice :custom-show nil
146 :group 'gnus-article-hiding)
148 (defcustom gnus-visible-headers
149 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
150 "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153 :type '(repeat :value-to-internal (lambda (widget value)
154 (custom-split-regexp-maybe value))
155 :match (lambda (widget value)
157 (widget-editable-list-match widget value)))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-sorted-header-list
162 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164 "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
168 :type '(repeat regexp)
169 :group 'gnus-article-hiding)
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172 "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175 :type '(set (const :tag "Headers with no content." empty)
176 (const :tag "Newsgroups with only one group." newsgroups)
177 (const :tag "Followup-to identical to newsgroups." followup-to)
178 (const :tag "Reply-to identical to from." reply-to)
179 (const :tag "Date less than four days old." date)
180 (const :tag "Very long To and/or Cc header." long-to)
181 (const :tag "Multiple To and/or Cc headers." many-to))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185 "Regexp matching signature separator.
186 This can also be a list of regexps. In that case, it will be checked
187 from head to tail looking for a separator. Searches will be done from
188 the end of the buffer."
189 :type '(repeat string)
190 :group 'gnus-article-signature)
192 (defcustom gnus-signature-limit nil
193 "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number. If it is a floating point number, no signature may be
196 longer (in lines) than that number. If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer. If it is a string, it will be used as a
199 regexp. If it matches, the text in question is not a signature."
200 :type '(choice (integer :value 200)
202 (function :value fun)
203 (regexp :value ".*"))
204 :group 'gnus-article-signature)
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207 "Property list to use for hiding text."
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-x-face-command
213 ;; Fixme: This isn't the right thing for mixed graphical and and
214 ;; non-graphical frames in a session.
215 ;; gnus-xmas.el overrides this for XEmacs.
216 ((and (fboundp 'image-type-available-p)
217 (image-type-available-p 'xbm))
218 (if (module-installed-p 'x-face-e21)
219 'x-face-decode-message-header
220 'gnus-article-display-xface))
221 ((and (not (featurep 'xemacs))
223 (module-installed-p 'x-face-mule))
224 'x-face-mule-gnus-article-display-x-face)
225 (gnus-article-compface-xbm
226 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -")
228 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
230 "*String or function to be executed to display an X-Face header.
231 If it is a string, the command will be executed in a sub-shell
232 asynchronously. The compressed face will be piped to this command."
233 :type '(choice string
235 :tag "x-face-decode-message-header (x-face-e21)"
236 x-face-decode-message-header)
237 (function-item gnus-article-display-xface)
238 (function-item x-face-mule-gnus-article-display-x-face)
240 :group 'gnus-article-washing)
242 (defcustom gnus-article-x-face-too-ugly nil
243 "Regexp matching posters whose face shouldn't be shown automatically."
244 :type '(choice regexp (const nil))
245 :group 'gnus-article-washing)
247 (defcustom gnus-article-banner-alist nil
248 "Banner alist for stripping.
250 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
252 :type '(repeat (cons symbol regexp))
253 :group 'gnus-article-washing)
255 (gnus-define-group-parameter
258 "Alist of regexps (to match group names) and banner."
259 :variable-group gnus-article-washing
261 '(choice :tag "Banner"
263 (const :tag "Remove signature" signature)
264 (symbol :tag "Item in `gnus-article-banner-alist'" none)
266 (const :tag "None" nil))
268 "If non-nil, specify how to remove `banners' from articles.
270 Symbol `signature' means to remove signatures delimited by
271 `gnus-signature-separator'. Any other symbol is used to look up a
272 regular expression to match the banner in `gnus-article-banner-alist'.
273 A string is used as a regular expression to match the banner
276 (defcustom gnus-emphasis-alist
278 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
280 '(("_" "_" underline)
283 ("_/" "/_" underline-italic)
284 ("_\\*" "\\*_" underline-bold)
285 ("\\*/" "/\\*" bold-italic)
286 ("_\\*/" "/\\*_" underline-bold-italic))))
287 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
288 2 3 gnus-emphasis-underline)
292 (format format (car spec) (car (cdr spec)))
293 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
295 "*Alist that says how to fontify certain phrases.
296 Each item looks like this:
298 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
300 The first element is a regular expression to be matched. The second
301 is a number that says what regular expression grouping used to find
302 the entire emphasized word. The third is a number that says what
303 regexp grouping should be displayed and highlighted. The fourth
304 is the face used for highlighting."
305 :type '(repeat (list :value ("" 0 0 default)
307 (integer :tag "Match group")
308 (integer :tag "Emphasize group")
310 :group 'gnus-article-emphasis)
312 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
313 "A regexp to describe whitespace which should not be emphasized.
314 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
315 The former avoids underlining of leading and trailing whitespace,
316 and the latter avoids underlining any whitespace at all."
318 :group 'gnus-article-emphasis
321 (defface gnus-emphasis-bold '((t (:bold t)))
322 "Face used for displaying strong emphasized text (*word*)."
323 :group 'gnus-article-emphasis)
325 (defface gnus-emphasis-italic '((t (:italic t)))
326 "Face used for displaying italic emphasized text (/word/)."
327 :group 'gnus-article-emphasis)
329 (defface gnus-emphasis-underline '((t (:underline t)))
330 "Face used for displaying underlined emphasized text (_word_)."
331 :group 'gnus-article-emphasis)
333 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
334 "Face used for displaying underlined bold emphasized text (_*word*_)."
335 :group 'gnus-article-emphasis)
337 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
338 "Face used for displaying underlined italic emphasized text (_/word/_)."
339 :group 'gnus-article-emphasis)
341 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
342 "Face used for displaying bold italic emphasized text (/*word*/)."
343 :group 'gnus-article-emphasis)
345 (defface gnus-emphasis-underline-bold-italic
346 '((t (:bold t :italic t :underline t)))
347 "Face used for displaying underlined bold italic emphasized text.
348 Esample: (_/*word*/_)."
349 :group 'gnus-article-emphasis)
351 (defface gnus-emphasis-highlight-words
352 '((t (:background "black" :foreground "yellow")))
353 "Face used for displaying highlighted words."
354 :group 'gnus-article-emphasis)
356 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
357 "Format for display of Date headers in article bodies.
358 See `format-time-string' for the possible values.
360 The variable can also be function, which should return a complete Date
361 header. The function is called with one argument, the time, which can
362 be fed to `format-time-string'."
363 :type '(choice string symbol)
364 :link '(custom-manual "(gnus)Article Date")
365 :group 'gnus-article-washing)
368 (autoload 'mail-extract-address-components "mail-extr"))
370 (defcustom gnus-save-all-headers t
371 "*If non-nil, don't remove any headers before saving."
372 :group 'gnus-article-saving
375 (defcustom gnus-prompt-before-saving 'always
376 "*This variable says how much prompting is to be done when saving articles.
377 If it is nil, no prompting will be done, and the articles will be
378 saved to the default files. If this variable is `always', each and
379 every article that is saved will be preceded by a prompt, even when
380 saving large batches of articles. If this variable is neither nil not
381 `always', there the user will be prompted once for a file name for
382 each invocation of the saving commands."
383 :group 'gnus-article-saving
384 :type '(choice (item always)
385 (item :tag "never" nil)
386 (sexp :tag "once" :format "%t\n" :value t)))
388 (defcustom gnus-saved-headers gnus-visible-headers
389 "Headers to keep if `gnus-save-all-headers' is nil.
390 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
391 If that variable is nil, however, all headers that match this regexp
392 will be kept while the rest will be deleted before saving."
393 :group 'gnus-article-saving
396 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
397 "A function to save articles in your favourite format.
398 The function must be interactively callable (in other words, it must
399 be an Emacs command).
401 Gnus provides the following functions:
403 * gnus-summary-save-in-rmail (Rmail format)
404 * gnus-summary-save-in-mail (Unix mail format)
405 * gnus-summary-save-in-folder (MH folder)
406 * gnus-summary-save-in-file (article format)
407 * gnus-summary-save-in-vm (use VM's folder format)
408 * gnus-summary-write-to-file (article format -- overwrite)."
409 :group 'gnus-article-saving
410 :type '(radio (function-item gnus-summary-save-in-rmail)
411 (function-item gnus-summary-save-in-mail)
412 (function-item gnus-summary-save-in-folder)
413 (function-item gnus-summary-save-in-file)
414 (function-item gnus-summary-save-in-vm)
415 (function-item gnus-summary-write-to-file)))
417 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
418 "A function generating a file name to save articles in Rmail format.
419 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
420 :group 'gnus-article-saving
423 (defcustom gnus-mail-save-name 'gnus-plain-save-name
424 "A function generating a file name to save articles in Unix mail format.
425 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
426 :group 'gnus-article-saving
429 (defcustom gnus-folder-save-name 'gnus-folder-save-name
430 "A function generating a file name to save articles in MH folder.
431 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
432 :group 'gnus-article-saving
435 (defcustom gnus-file-save-name 'gnus-numeric-save-name
436 "A function generating a file name to save articles in article format.
437 The function is called with NEWSGROUP, HEADERS, and optional
439 :group 'gnus-article-saving
442 (defcustom gnus-split-methods
443 '((gnus-article-archive-name)
444 (gnus-article-nndoc-name))
445 "*Variable used to suggest where articles are to be saved.
446 For instance, if you would like to save articles related to Gnus in
447 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
448 you could set this variable to something like:
450 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
451 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
453 This variable is an alist where the where the key is the match and the
454 value is a list of possible files to save in if the match is non-nil.
456 If the match is a string, it is used as a regexp match on the
457 article. If the match is a symbol, that symbol will be funcalled
458 from the buffer of the article to be saved with the newsgroup as the
459 parameter. If it is a list, it will be evaled in the same buffer.
461 If this form or function returns a string, this string will be used as
462 a possible file name; and if it returns a non-nil list, that list will
463 be used as possible file names."
464 :group 'gnus-article-saving
465 :type '(repeat (choice (list :value (fun) function)
466 (cons :value ("" "") regexp (repeat string))
469 (defcustom gnus-article-display-method-for-mime
470 'gnus-article-display-mime-message
471 "Function to display a MIME message.
472 The function is called from the article buffer."
473 :group 'gnus-article-mime
476 (defcustom gnus-article-display-method-for-traditional
477 'gnus-article-display-traditional-message
478 "*Function to display a traditional message.
479 The function is called from the article buffer."
480 :group 'gnus-article-mime
483 (defcustom gnus-page-delimiter "^\^L"
484 "*Regexp describing what to use as article page delimiters.
485 The default value is \"^\^L\", which is a form linefeed at the
486 beginning of a line."
488 :group 'gnus-article-various)
490 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
491 "*The format specification for the article mode line.
492 See `gnus-summary-mode-line-format' for a closer description.
494 The following additional specs are available:
496 %w The article washing status.
497 %m The number of MIME parts in the article."
499 :group 'gnus-article-various)
501 (defcustom gnus-article-mode-hook nil
502 "*A hook for Gnus article mode."
504 :group 'gnus-article-various)
506 (defcustom gnus-article-menu-hook nil
507 "*Hook run after the creation of the article mode menu."
509 :group 'gnus-article-various)
511 (defcustom gnus-article-prepare-hook nil
512 "*A hook called after an article has been prepared in the article buffer."
514 :group 'gnus-article-various)
516 (defcustom gnus-article-hide-pgp-hook nil
517 "*A hook called after successfully hiding a PGP signature."
519 :group 'gnus-article-various)
521 (defcustom gnus-article-button-face 'bold
522 "Face used for highlighting buttons in the article buffer.
524 An article button is a piece of text that you can activate by pressing
525 `RET' or `mouse-2' above it."
527 :group 'gnus-article-buttons)
529 (defcustom gnus-article-mouse-face 'highlight
530 "Face used for mouse highlighting in the article buffer.
532 Article buttons will be displayed in this face when the cursor is
535 :group 'gnus-article-buttons)
537 (defcustom gnus-signature-face 'gnus-signature-face
538 "Face used for highlighting a signature in the article buffer.
539 Obsolete; use the face `gnus-signature-face' for customizations instead."
541 :group 'gnus-article-highlight
542 :group 'gnus-article-signature)
544 (defface gnus-signature-face
547 "Face used for highlighting a signature in the article buffer."
548 :group 'gnus-article-highlight
549 :group 'gnus-article-signature)
551 (defface gnus-header-from-face
554 (:foreground "spring green"))
557 (:foreground "red3"))
560 "Face used for displaying from headers."
561 :group 'gnus-article-headers
562 :group 'gnus-article-highlight)
564 (defface gnus-header-subject-face
567 (:foreground "SeaGreen3"))
570 (:foreground "red4"))
572 (:bold t :italic t)))
573 "Face used for displaying subject headers."
574 :group 'gnus-article-headers
575 :group 'gnus-article-highlight)
577 (defface gnus-header-newsgroups-face
580 (:foreground "yellow" :italic t))
583 (:foreground "MidnightBlue" :italic t))
586 "Face used for displaying newsgroups headers."
587 :group 'gnus-article-headers
588 :group 'gnus-article-highlight)
590 (defface gnus-header-name-face
593 (:foreground "SeaGreen"))
596 (:foreground "maroon"))
599 "Face used for displaying header names."
600 :group 'gnus-article-headers
601 :group 'gnus-article-highlight)
603 (defface gnus-header-content-face
606 (:foreground "forest green" :italic t))
609 (:foreground "indianred4" :italic t))
611 (:italic t))) "Face used for displaying header content."
612 :group 'gnus-article-headers
613 :group 'gnus-article-highlight)
615 (defcustom gnus-header-face-alist
616 '(("From" nil gnus-header-from-face)
617 ("Subject" nil gnus-header-subject-face)
618 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
619 ("" gnus-header-name-face gnus-header-content-face))
620 "*Controls highlighting of article header.
622 An alist of the form (HEADER NAME CONTENT).
624 HEADER is a regular expression which should match the name of an
625 header header and NAME and CONTENT are either face names or nil.
627 The name of each header field will be displayed using the face
628 specified by the first element in the list where HEADER match the
629 header name and NAME is non-nil. Similarly, the content will be
630 displayed by the first non-nil matching CONTENT face."
631 :group 'gnus-article-headers
632 :group 'gnus-article-highlight
633 :type '(repeat (list (regexp :tag "Header")
635 (item :tag "skip" nil)
636 (face :value default))
637 (choice :tag "Content"
638 (item :tag "skip" nil)
639 (face :value default)))))
641 (defcustom gnus-article-decode-hook nil
642 "*Hook run to decode charsets in articles."
643 :group 'gnus-article-headers
646 (defcustom gnus-display-mime-function 'gnus-display-mime
647 "Function to display MIME articles."
648 :group 'gnus-article-mime
651 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
652 "Function used to decode headers.")
654 (defvar gnus-article-dumbquotes-map
673 "Table for MS-to-Latin1 translation.")
675 (defcustom gnus-ignored-mime-types nil
676 "List of MIME types that should be ignored by Gnus."
678 :group 'gnus-article-mime
679 :type '(repeat regexp))
681 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
682 "List of MIME types that should not be given buttons when rendered inline."
684 :group 'gnus-article-mime
685 :type '(repeat regexp))
687 (defcustom gnus-article-mime-part-function nil
688 "Function called with a MIME handle as the argument.
689 This is meant for people who want to do something automatic based
690 on parts -- for instance, adding Vcard info to a database."
691 :group 'gnus-article-mime
694 (defcustom gnus-mime-multipart-functions nil
695 "An alist of MIME types to functions to display them."
697 :group 'gnus-article-mime
700 (defcustom gnus-article-date-lapsed-new-header nil
701 "Whether the X-Sent and Date headers can coexist.
702 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
703 either replace the old \"Date:\" header (if this variable is nil), or
704 be added below it (otherwise)."
706 :group 'gnus-article-headers
709 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
710 "Function called with a MIME handle as the argument.
711 This is meant for people who want to view first matched part.
712 For `undisplayed-alternative' (default), the first undisplayed
713 part or alternative part is used. For `undisplayed', the first
714 undisplayed part is used. For a function, the first part which
715 the function return `t' is used. For `nil', the first part is
718 :group 'gnus-article-mime
720 (item :tag "first" :value nil)
721 (item :tag "undisplayed" :value undisplayed)
722 (item :tag "undisplayed or alternative"
723 :value undisplayed-alternative)
726 (defcustom gnus-mime-action-alist
727 '(("save to file" . gnus-mime-save-part)
728 ("save and strip" . gnus-mime-save-part-and-strip)
729 ("display as text" . gnus-mime-inline-part)
730 ("view the part" . gnus-mime-view-part)
731 ("pipe to command" . gnus-mime-pipe-part)
732 ("toggle display" . gnus-article-press-button)
733 ("toggle display" . gnus-article-view-part-as-charset)
734 ("view as type" . gnus-mime-view-part-as-type)
735 ("internalize type" . gnus-mime-internalize-part)
736 ("externalize type" . gnus-mime-externalize-part))
737 "An alist of actions that run on the MIME attachment."
738 :group 'gnus-article-mime
739 :type '(repeat (cons (string :tag "name")
742 (defcustom gnus-mime-action-alist
743 '(("save to file" . gnus-mime-save-part)
744 ("display as text" . gnus-mime-inline-part)
745 ("view the part" . gnus-mime-view-part)
746 ("pipe to command" . gnus-mime-pipe-part)
747 ("toggle display" . gnus-article-press-button)
748 ("view as type" . gnus-mime-view-part-as-type)
749 ("internalize type" . gnus-mime-internalize-part)
750 ("externalize type" . gnus-mime-externalize-part))
751 "An alist of actions that run on the MIME attachment."
753 :group 'gnus-article-mime
754 :type '(repeat (cons (string :tag "name")
758 ;;; The treatment variables
761 (defvar gnus-part-display-hook nil
762 "Hook called on parts that are to receive treatment.")
764 (defvar gnus-article-treat-custom
765 '(choice (const :tag "Off" nil)
767 (const :tag "Header" head)
768 (const :tag "Last" last)
769 (const :tag "Mime" mime)
770 (integer :tag "Less")
771 (repeat :tag "Groups" regexp)
772 (sexp :tag "Predicate")))
774 (defvar gnus-article-treat-head-custom
775 '(choice (const :tag "Off" nil)
776 (const :tag "Header" head)))
778 (defvar gnus-article-treat-types '("text/plain")
781 (defvar gnus-inhibit-treatment nil
782 "Whether to inhibit treatment.")
784 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
785 "Highlight the signature.
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
790 (put 'gnus-treat-highlight-signature 'highlight t)
792 (defcustom gnus-treat-buttonize 100000
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
798 (put 'gnus-treat-buttonize 'highlight t)
800 (defcustom gnus-treat-buttonize-head 'head
801 "Add buttons to the head.
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-head-custom)
806 (put 'gnus-treat-buttonize-head 'highlight t)
808 (defcustom gnus-treat-emphasize
809 (and (or window-system
811 (>= (string-to-number emacs-version) 21))
814 Valid values are nil, t, `head', `last', an integer or a predicate.
815 See the manual for details."
816 :group 'gnus-article-treat
817 :type gnus-article-treat-custom)
818 (put 'gnus-treat-emphasize 'highlight t)
820 (defcustom gnus-treat-strip-cr nil
821 "Remove carriage returns.
822 Valid values are nil, t, `head', `last', an integer or a predicate.
823 See the manual for details."
824 :group 'gnus-article-treat
825 :type gnus-article-treat-custom)
827 (defcustom gnus-treat-hide-headers 'head
829 Valid values are nil, t, `head', `last', an integer or a predicate.
830 See the manual for details."
831 :group 'gnus-article-treat
832 :type gnus-article-treat-head-custom)
834 (defcustom gnus-treat-hide-boring-headers nil
835 "Hide boring headers.
836 Valid values are nil, t, `head', `last', an integer or a predicate.
837 See the manual for details."
838 :group 'gnus-article-treat
839 :type gnus-article-treat-head-custom)
841 (defcustom gnus-treat-hide-signature nil
843 Valid values are nil, t, `head', `last', an integer or a predicate.
844 See the manual for details."
845 :group 'gnus-article-treat
846 :type gnus-article-treat-custom)
848 (defcustom gnus-treat-fill-article nil
850 Valid values are nil, t, `head', `last', an integer or a predicate.
851 See the manual for details."
852 :group 'gnus-article-treat
853 :type gnus-article-treat-custom)
855 (defcustom gnus-treat-hide-citation nil
857 Valid values are nil, t, `head', `last', an integer or a predicate.
858 See the manual for details."
859 :group 'gnus-article-treat
860 :type gnus-article-treat-custom)
862 (defcustom gnus-treat-hide-citation-maybe nil
864 Valid values are nil, t, `head', `last', an integer or a predicate.
865 See the manual for details."
866 :group 'gnus-article-treat
867 :type gnus-article-treat-custom)
869 (defcustom gnus-treat-hide-citation-maybe nil
871 Valid values are nil, t, `head', `last', an integer or a predicate.
872 See the manual for details."
873 :group 'gnus-article-treat
874 :type gnus-article-treat-custom)
876 (defcustom gnus-treat-strip-list-identifiers 'head
877 "Strip list identifiers from `gnus-list-identifiers`.
878 Valid values are nil, t, `head', `last', an integer or a predicate.
879 See the manual for details."
881 :group 'gnus-article-treat
882 :type gnus-article-treat-custom)
884 (defcustom gnus-treat-strip-pgp t
885 "Strip PGP signatures.
886 Valid values are nil, t, `head', `last', an integer or a predicate.
887 See the manual for details."
888 :group 'gnus-article-treat
889 :type gnus-article-treat-custom)
891 (defcustom gnus-treat-strip-pem nil
892 "Strip PEM signatures.
893 Valid values are nil, t, `head', `last', an integer or a predicate.
894 See the manual for details."
895 :group 'gnus-article-treat
896 :type gnus-article-treat-custom)
898 (defcustom gnus-treat-strip-banner t
899 "Strip banners from articles.
900 The banner to be stripped is specified in the `banner' group parameter.
901 Valid values are nil, t, `head', `last', an integer or a predicate.
902 See the manual for details."
903 :group 'gnus-article-treat
904 :type gnus-article-treat-custom)
906 (defcustom gnus-treat-highlight-headers 'head
907 "Highlight the headers.
908 Valid values are nil, t, `head', `last', an integer or a predicate.
909 See the manual for details."
910 :group 'gnus-article-treat
911 :type gnus-article-treat-head-custom)
912 (put 'gnus-treat-highlight-headers 'highlight t)
914 (defcustom gnus-treat-highlight-citation t
915 "Highlight cited text.
916 Valid values are nil, t, `head', `last', an integer or a predicate.
917 See the manual for details."
918 :group 'gnus-article-treat
919 :type gnus-article-treat-custom)
920 (put 'gnus-treat-highlight-citation 'highlight t)
922 (defcustom gnus-treat-date-ut nil
923 "Display the Date in UT (GMT).
924 Valid values are nil, t, `head', `last', an integer or a predicate.
925 See the manual for details."
926 :group 'gnus-article-treat
927 :type gnus-article-treat-head-custom)
929 (defcustom gnus-treat-date-local nil
930 "Display the Date in the local timezone.
931 Valid values are nil, t, `head', `last', an integer or a predicate.
932 See the manual for details."
933 :group 'gnus-article-treat
934 :type gnus-article-treat-head-custom)
936 (defcustom gnus-treat-date-lapsed nil
937 "Display the Date header in a way that says how much time has elapsed.
938 Valid values are nil, t, `head', `last', an integer or a predicate.
939 See the manual for details."
940 :group 'gnus-article-treat
941 :type gnus-article-treat-head-custom)
943 (defcustom gnus-treat-date-original nil
944 "Display the date in the original timezone.
945 Valid values are nil, t, `head', `last', an integer or a predicate.
946 See the manual for details."
947 :group 'gnus-article-treat
948 :type gnus-article-treat-head-custom)
950 (defcustom gnus-treat-date-iso8601 nil
951 "Display the date in the ISO8601 format.
952 Valid values are nil, t, `head', `last', an integer or a predicate.
953 See the manual for details."
955 :group 'gnus-article-treat
956 :type gnus-article-treat-head-custom)
958 (defcustom gnus-treat-date-user-defined nil
959 "Display the date in a user-defined format.
960 The format is defined by the `gnus-article-time-format' variable.
961 Valid values are nil, t, `head', `last', an integer or a predicate.
962 See the manual for details."
963 :group 'gnus-article-treat
964 :type gnus-article-treat-head-custom)
966 (defcustom gnus-treat-strip-headers-in-body t
967 "Strip the X-No-Archive header line from the beginning of the body.
968 Valid values are nil, t, `head', `last', an integer or a predicate.
969 See the manual for details."
971 :group 'gnus-article-treat
972 :type gnus-article-treat-custom)
974 (defcustom gnus-treat-strip-trailing-blank-lines nil
975 "Strip trailing blank lines.
976 Valid values are nil, t, `head', `last', an integer or a predicate.
977 See the manual for details."
978 :group 'gnus-article-treat
979 :type gnus-article-treat-custom)
981 (defcustom gnus-treat-strip-leading-blank-lines nil
982 "Strip leading blank lines.
983 Valid values are nil, t, `head', `last', an integer or a predicate.
984 See the manual for details."
985 :group 'gnus-article-treat
986 :type gnus-article-treat-custom)
988 (defcustom gnus-treat-strip-multiple-blank-lines nil
989 "Strip multiple blank lines.
990 Valid values are nil, t, `head', `last', an integer or a predicate.
991 See the manual for details."
992 :group 'gnus-article-treat
993 :type gnus-article-treat-custom)
995 (defcustom gnus-treat-overstrike t
996 "Treat overstrike highlighting.
997 Valid values are nil, t, `head', `last', an integer or a predicate.
998 See the manual for details."
999 :group 'gnus-article-treat
1000 :type gnus-article-treat-custom)
1001 (put 'gnus-treat-overstrike 'highlight t)
1003 (defcustom gnus-treat-display-xface
1004 (and (or (and (fboundp 'image-type-available-p)
1005 (image-type-available-p 'xbm)
1006 (string-match "^0x" (shell-command-to-string "uncompface")))
1007 (and (featurep 'xemacs) (featurep 'xface))
1008 (eq 'x-face-mule-gnus-article-display-x-face
1009 gnus-article-x-face-command))
1011 "Display X-Face headers.
1012 Valid values are nil, t, `head', `last', an integer or a predicate.
1013 See the manual for details."
1014 :group 'gnus-article-treat
1015 :type gnus-article-treat-head-custom)
1016 (put 'gnus-treat-display-xface 'highlight t)
1018 (defcustom gnus-treat-display-smileys
1019 (if (or (and (featurep 'xemacs)
1021 (and (fboundp 'image-type-available-p)
1022 (image-type-available-p 'pbm))
1023 (and (not (featurep 'xemacs))
1025 (module-installed-p 'gnus-bitmap)))
1029 Valid values are nil, t, `head', `last', an integer or a predicate.
1030 See the manual for details."
1031 :group 'gnus-article-treat
1032 :type gnus-article-treat-custom)
1033 (put 'gnus-treat-display-smileys 'highlight t)
1035 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1037 Valid values are nil, t, `head', `last', an integer or a predicate.
1038 See the manual for details."
1039 :group 'gnus-article-treat
1040 :type gnus-article-treat-head-custom)
1041 (put 'gnus-treat-display-picons 'highlight t)
1043 (defcustom gnus-treat-capitalize-sentences nil
1044 "Capitalize sentence-starting words.
1045 Valid values are nil, t, `head', `last', an integer or a predicate.
1046 See the manual for details."
1048 :group 'gnus-article-treat
1049 :type gnus-article-treat-custom)
1051 (defcustom gnus-treat-fill-long-lines nil
1053 Valid values are nil, t, `head', `last', an integer or a predicate.
1054 See the manual for details."
1055 :group 'gnus-article-treat
1056 :type gnus-article-treat-custom)
1058 (defcustom gnus-treat-play-sounds nil
1060 Valid values are nil, t, `head', `last', an integer or a predicate.
1061 See the manual for details."
1063 :group 'gnus-article-treat
1064 :type gnus-article-treat-custom)
1066 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1067 "Decode an article as `default-mime-charset'. For instance, if you want to
1068 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1069 you could set this variable to something like: nil for don't decode, t for
1070 decode the body, '(or header t) for the whole article, etc."
1071 :group 'gnus-article-treat
1072 :type '(radio (const :tag "Off" nil)
1073 (const :tag "Decode body" t)
1074 (const :tag "Decode all" (or head t))))
1076 (defcustom gnus-treat-translate nil
1077 "Translate articles from one language to another.
1078 Valid values are nil, t, `head', `last', an integer or a predicate.
1079 See the manual for details."
1081 :group 'gnus-article-treat
1082 :type gnus-article-treat-custom)
1084 (defcustom gnus-treat-x-pgp-sig nil
1086 To automatically treat X-PGP-Sig, set it to head.
1087 Valid values are nil, t, `head', `last', an integer or a predicate.
1088 See the manual for details."
1089 :group 'gnus-article-treat
1090 :group 'mime-security
1091 :type gnus-article-treat-custom)
1093 (defvar gnus-article-encrypt-protocol-alist
1094 '(("PGP" . mml2015-self-encrypt)))
1096 ;; Set to nil if more than one protocol added to
1097 ;; gnus-article-encrypt-protocol-alist.
1098 (defcustom gnus-article-encrypt-protocol "PGP"
1099 "The protocol used for encrypt articles.
1100 It is a string, such as \"PGP\". If nil, ask user."
1102 :group 'mime-security)
1104 ;;; Internal variables
1106 (defvar article-goto-body-goes-to-point-min-p nil)
1107 (defvar gnus-article-wash-types nil)
1108 (defvar gnus-article-emphasis-alist nil)
1110 (defvar gnus-article-mime-handle-alist-1 nil)
1111 (defvar gnus-treatment-function-alist
1112 '((gnus-treat-decode-article-as-default-mime-charset
1113 gnus-article-decode-article-as-default-mime-charset)
1114 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1115 (gnus-treat-strip-banner gnus-article-strip-banner)
1116 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1117 (gnus-treat-buttonize gnus-article-add-buttons)
1118 (gnus-treat-fill-article gnus-article-fill-cited-article)
1119 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1120 (gnus-treat-strip-cr gnus-article-remove-cr)
1121 (gnus-treat-display-xface gnus-article-display-x-face)
1122 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1123 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1124 (gnus-treat-hide-signature gnus-article-hide-signature)
1125 (gnus-treat-hide-citation gnus-article-hide-citation)
1126 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1127 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1128 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1129 (gnus-treat-strip-pem gnus-article-hide-pem)
1130 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1131 (gnus-treat-emphasize gnus-article-emphasize)
1132 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1133 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1134 (gnus-treat-date-ut gnus-article-date-ut)
1135 (gnus-treat-date-local gnus-article-date-local)
1136 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1137 (gnus-treat-date-original gnus-article-date-original)
1138 (gnus-treat-date-user-defined gnus-article-date-user)
1139 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1140 (gnus-treat-strip-trailing-blank-lines
1141 gnus-article-remove-trailing-blank-lines)
1142 (gnus-treat-strip-leading-blank-lines
1143 gnus-article-strip-leading-blank-lines)
1144 (gnus-treat-strip-multiple-blank-lines
1145 gnus-article-strip-multiple-blank-lines)
1146 (gnus-treat-overstrike gnus-article-treat-overstrike)
1147 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1148 (gnus-treat-display-smileys gnus-article-smiley-display)
1149 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1150 (gnus-treat-display-picons gnus-article-display-picons)
1151 (gnus-treat-play-sounds gnus-earcon-display)))
1153 (defvar gnus-article-mime-handle-alist nil)
1154 (defvar article-lapsed-timer nil)
1155 (defvar gnus-article-current-summary nil)
1157 (defvar gnus-article-mode-syntax-table
1158 (let ((table (copy-syntax-table text-mode-syntax-table)))
1159 ;; This causes the citation match run O(2^n).
1160 ;; (modify-syntax-entry ?- "w" table)
1161 (modify-syntax-entry ?> ")" table)
1162 (modify-syntax-entry ?< "(" table)
1164 "Syntax table used in article mode buffers.
1165 Initialized from `text-mode-syntax-table.")
1167 (defvar gnus-save-article-buffer nil)
1169 (defvar gnus-article-mode-line-format-alist
1170 (nconc '((?w (gnus-article-wash-status) ?s)
1171 (?m (gnus-article-mime-part-status) ?s))
1172 gnus-summary-mode-line-format-alist))
1174 (defvar gnus-number-of-articles-to-be-saved nil)
1176 (defvar gnus-inhibit-hiding nil)
1178 (defsubst gnus-article-hide-text (b e props)
1179 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1180 (gnus-add-text-properties-when 'article-type nil b e props)
1181 (when (memq 'intangible props)
1183 (max (1- b) (point-min))
1184 b 'intangible (cddr (memq 'intangible props)))))
1186 (defsubst gnus-article-unhide-text (b e)
1187 "Remove hidden text properties from region between B and E."
1188 (remove-text-properties b e gnus-hidden-properties)
1189 (when (memq 'intangible gnus-hidden-properties)
1190 (put-text-property (max (1- b) (point-min))
1191 b 'intangible nil)))
1193 (defun gnus-article-hide-text-type (b e type)
1194 "Hide text of TYPE between B and E."
1195 (push type gnus-article-wash-types)
1196 (gnus-article-hide-text
1197 b e (cons 'article-type (cons type gnus-hidden-properties))))
1199 (defun gnus-article-unhide-text-type (b e type)
1200 "Unhide text of TYPE between B and E."
1201 (setq gnus-article-wash-types
1202 (delq type gnus-article-wash-types))
1203 (remove-text-properties
1204 b e (cons 'article-type (cons type gnus-hidden-properties)))
1205 (when (memq 'intangible gnus-hidden-properties)
1206 (put-text-property (max (1- b) (point-min))
1207 b 'intangible nil)))
1209 (defun gnus-article-hide-text-of-type (type)
1210 "Hide text of TYPE in the current buffer."
1212 (let ((b (point-min))
1214 (while (setq b (text-property-any b e 'article-type type))
1215 (add-text-properties b (incf b) gnus-hidden-properties)))))
1217 (defun gnus-article-delete-text-of-type (type)
1218 "Delete text of TYPE in the current buffer."
1220 (let ((b (point-min)))
1221 (while (setq b (text-property-any b (point-max) 'article-type type))
1223 b (or (text-property-not-all b (point-max) 'article-type type)
1226 (defun gnus-article-delete-invisible-text ()
1227 "Delete all invisible text in the current buffer."
1229 (let ((b (point-min)))
1230 (while (setq b (text-property-any b (point-max) 'invisible t))
1232 b (or (text-property-not-all b (point-max) 'invisible t)
1235 (defun gnus-article-text-type-exists-p (type)
1236 "Say whether any text of type TYPE exists in the buffer."
1237 (text-property-any (point-min) (point-max) 'article-type type))
1239 (defsubst gnus-article-header-rank ()
1240 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1241 (let ((list gnus-sorted-header-list)
1244 (when (looking-at (car list))
1246 (setq list (cdr list))
1250 (defun article-hide-headers (&optional arg delete)
1251 "Hide unwanted headers and possibly sort them as well."
1252 (interactive (gnus-article-hidden-arg))
1253 ;; Lars said that this function might be inhibited.
1254 (if (gnus-article-check-hidden-text 'headers arg)
1256 ;; Show boring headers as well.
1257 (gnus-article-show-hidden-text 'boring-headers)
1258 (when (eq 1 (point-min))
1259 (set-window-start (get-buffer-window (current-buffer)) 1)))
1260 (unless gnus-inhibit-hiding
1263 (let ((buffer-read-only nil)
1264 (inhibit-read-only t)
1265 (case-fold-search t)
1266 (max (1+ (length gnus-sorted-header-list)))
1267 (ignored (when (not gnus-visible-headers)
1268 (cond ((stringp gnus-ignored-headers)
1269 gnus-ignored-headers)
1270 ((listp gnus-ignored-headers)
1271 (mapconcat 'identity gnus-ignored-headers
1274 (cond ((stringp gnus-visible-headers)
1275 gnus-visible-headers)
1276 ((and gnus-visible-headers
1277 (listp gnus-visible-headers))
1278 (mapconcat 'identity gnus-visible-headers "\\|"))))
1279 (inhibit-point-motion-hooks t)
1281 ;; First we narrow to just the headers.
1282 (article-narrow-to-head)
1283 ;; Hide any "From " lines at the beginning of (mail) articles.
1284 (while (looking-at "From ")
1288 (delete-region (point-min) (point))
1289 (gnus-article-hide-text (point-min) (point)
1290 (nconc (list 'article-type 'headers)
1291 gnus-hidden-properties))))
1292 ;; Then treat the rest of the header lines.
1293 ;; Then we use the two regular expressions
1294 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1295 ;; select which header lines is to remain visible in the
1297 (while (re-search-forward "^[^ \t]*:" nil t)
1299 ;; Mark the rank of the header.
1301 (point) (1+ (point)) 'message-rank
1302 (if (or (and visible (looking-at visible))
1304 (not (looking-at ignored))))
1305 (gnus-article-header-rank)
1308 (message-sort-headers-1)
1309 (when (setq beg (text-property-any
1310 (point-min) (point-max) 'message-rank (+ 2 max)))
1311 ;; We delete or make invisible the unwanted headers.
1312 (push 'headers gnus-article-wash-types)
1315 (add-text-properties
1316 (point-min) (+ 5 (point-min))
1317 '(article-type headers dummy-invisible t))
1318 (delete-region beg (point-max)))
1319 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1322 (defun article-hide-boring-headers (&optional arg)
1323 "Toggle hiding of headers that aren't very interesting.
1324 If given a negative prefix, always show; if given a positive prefix,
1326 (interactive (gnus-article-hidden-arg))
1327 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1328 (not gnus-show-all-headers))
1331 (let ((buffer-read-only nil)
1332 (list gnus-boring-article-headers)
1333 (inhibit-point-motion-hooks t)
1335 (article-narrow-to-head)
1337 (setq elem (pop list))
1338 (goto-char (point-min))
1340 ;; Hide empty headers.
1342 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1344 (gnus-article-hide-text-type
1345 (progn (beginning-of-line) (point))
1348 (if (re-search-forward "^[^ \t]" nil t)
1352 ;; Hide boring Newsgroups header.
1353 ((eq elem 'newsgroups)
1354 (when (equal (gnus-fetch-field "newsgroups")
1355 (gnus-group-real-name
1356 (if (boundp 'gnus-newsgroup-name)
1359 (gnus-article-hide-header "newsgroups")))
1360 ((eq elem 'followup-to)
1361 (when (equal (message-fetch-field "followup-to")
1362 (message-fetch-field "newsgroups"))
1363 (gnus-article-hide-header "followup-to")))
1364 ((eq elem 'reply-to)
1365 (let ((from (message-fetch-field "from"))
1366 (reply-to (message-fetch-field "reply-to")))
1371 (nth 1 (funcall gnus-extract-address-components from))
1372 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1373 (gnus-article-hide-header "reply-to"))))
1375 (let ((date (message-fetch-field "date")))
1377 (< (days-between (current-time-string) date)
1379 (gnus-article-hide-header "date"))))
1381 (let ((to (message-fetch-field "to"))
1382 (cc (message-fetch-field "cc")))
1383 (when (> (length to) 1024)
1384 (gnus-article-hide-header "to"))
1385 (when (> (length cc) 1024)
1386 (gnus-article-hide-header "cc"))))
1390 (goto-char (point-min))
1391 (while (re-search-forward "^to:" nil t)
1392 (setq to-count (1+ to-count)))
1393 (when (> to-count 1)
1394 (while (> to-count 0)
1395 (goto-char (point-min))
1397 (re-search-forward "^to:" nil nil to-count)
1399 (narrow-to-region (point) (point-max))
1400 (gnus-article-hide-header "to"))
1401 (setq to-count (1- to-count))))
1402 (goto-char (point-min))
1403 (while (re-search-forward "^cc:" nil t)
1404 (setq cc-count (1+ cc-count)))
1405 (when (> cc-count 1)
1406 (while (> cc-count 0)
1407 (goto-char (point-min))
1409 (re-search-forward "^cc:" nil nil cc-count)
1411 (narrow-to-region (point) (point-max))
1412 (gnus-article-hide-header "cc"))
1413 (setq cc-count (1- cc-count)))))))))))))
1415 (defun gnus-article-hide-header (header)
1417 (goto-char (point-min))
1418 (when (re-search-forward (concat "^" header ":") nil t)
1419 (gnus-article-hide-text-type
1420 (progn (beginning-of-line) (point))
1423 (if (re-search-forward "^[^ \t]" nil t)
1428 (defun article-toggle-headers (&optional arg)
1429 "Toggle hiding of headers. If given a negative prefix, always show;
1430 if given a positive prefix, always hide."
1431 (interactive (gnus-article-hidden-arg))
1432 (let ((force (when (numberp arg)
1433 (cond ((> arg 0) 'always-hide)
1434 ((< arg 0) 'always-show))))
1435 (window (get-buffer-window gnus-article-buffer))
1436 (header-end (point-min))
1437 header-start field-end field-start
1438 (inhibit-point-motion-hooks t)
1439 (inhibit-read-only t)
1443 (while (and (setq header-start
1444 (text-property-any header-end (point-max)
1445 'article-treated-header t))
1447 (text-property-not-all header-start (point-max)
1448 'article-treated-header t)))
1449 (setq field-end header-start)
1451 (;; Hide exposed invisible fields.
1452 (and (not (eq 'always-show force))
1454 (text-property-any field-end header-end
1455 'exposed-invisible-field t)))
1456 (while (and field-start
1457 (setq field-end (text-property-not-all
1458 field-start header-end
1459 'exposed-invisible-field t)))
1460 (add-text-properties field-start field-end gnus-hidden-properties)
1461 (setq field-start (text-property-any field-end header-end
1462 'exposed-invisible-field t)))
1463 (put-text-property header-start header-end
1464 'exposed-invisible-field nil))
1465 (;; Expose invisible fields.
1466 (and (not (eq 'always-hide force))
1468 (text-property-any field-end header-end 'invisible t)))
1469 (while (and field-start
1470 (setq field-end (text-property-not-all
1471 field-start header-end
1473 ;; If the invisible text is not terminated with newline, we
1474 ;; won't expose it. Because it may be created by x-face-mule.
1475 ;; BTW, XEmacs sometimes fail in putting a invisible text
1476 ;; property with `gnus-article-hide-text' (really?). In that
1477 ;; case, the invisible text might be started from the middle of
1478 ;; a line so we will expose the sort of thing.
1479 (when (or (not (or (eq header-start field-start)
1480 (eq ?\n (char-before field-start))))
1481 (eq ?\n (char-before field-end)))
1482 (remove-text-properties field-start field-end
1483 gnus-hidden-properties)
1484 (put-text-property field-start field-end
1485 'exposed-invisible-field t))
1486 (setq field-start (text-property-any field-end header-end
1489 (not (eq 'always-show force))
1490 (narrow-to-region header-start header-end)
1491 (article-hide-headers)
1492 ;; Re-display X-Face image under XEmacs.
1493 (when (and (featurep 'xemacs)
1494 (gnus-functionp gnus-article-x-face-command))
1495 (let ((func (cadr (assq 'gnus-treat-display-xface
1496 gnus-treatment-function-alist)))
1498 (when (and (not gnus-inhibit-treatment)
1500 (gnus-treat-predicate gnus-treat-display-xface))
1502 (put-text-property header-start header-end 'read-only nil))))
1505 (goto-char (point-min))
1507 (set-window-start window (point-min))))))
1509 (defvar gnus-article-normalized-header-length 40
1510 "Length of normalized headers.")
1512 (defun article-normalize-headers ()
1513 "Make all header lines 40 characters long."
1515 (let ((buffer-read-only nil)
1519 (article-narrow-to-head)
1522 ((< (setq column (- (gnus-point-at-eol) (point)))
1523 gnus-article-normalized-header-length)
1525 (insert (make-string
1526 (- gnus-article-normalized-header-length column)
1528 ((> column gnus-article-normalized-header-length)
1529 (gnus-put-text-property
1531 (forward-char gnus-article-normalized-header-length)
1538 (forward-line 1))))))
1540 (defun article-treat-dumbquotes ()
1541 "Translate M****s*** sm*rtq**t*s into proper text.
1542 Note that this function guesses whether a character is a sm*rtq**t* or
1543 not, so it should only be used interactively.
1545 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1546 in an attempt to provide more quoting characters. If you see
1547 something like \\222 or \\264 where you're expecting some kind of
1548 apostrophe or quotation mark, then try this wash."
1550 (article-translate-strings gnus-article-dumbquotes-map))
1552 (defun article-translate-characters (from to)
1553 "Translate all characters in the body of the article according to FROM and TO.
1554 FROM is a string of characters to translate from; to is a string of
1555 characters to translate to."
1557 (when (article-goto-body)
1558 (let ((buffer-read-only nil)
1559 (x (make-string 225 ?x))
1561 (while (< (incf i) (length x))
1564 (while (< i (length from))
1565 (aset x (aref from i) (aref to i))
1567 (translate-region (point) (point-max) x)))))
1569 (defun article-translate-strings (map)
1570 "Translate all string in the body of the article according to MAP.
1571 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1573 (when (article-goto-body)
1574 (let ((buffer-read-only nil)
1576 (while (setq elem (pop map))
1578 (while (search-forward (car elem) nil t)
1579 (replace-match (cadr elem)))))))))
1581 (defun article-treat-overstrike ()
1582 "Translate overstrikes into bold text."
1585 (when (article-goto-body)
1586 (let ((buffer-read-only nil))
1587 (while (search-forward "\b" nil t)
1588 (let ((next (char-after))
1592 previous (char-after))
1596 ;; We do the boldification/underlining by hiding the
1597 ;; overstrikes and putting the proper text property
1601 (gnus-article-hide-text-type start (point) 'overstrike)
1602 (put-text-property (point) end 'face 'bold))
1604 (gnus-article-hide-text-type
1605 (1- (point)) (1+ (point)) 'overstrike)
1607 start (1- (point)) 'face 'underline))
1609 (gnus-article-hide-text-type start (point) 'overstrike)
1611 (point) end 'face 'underline)))))))))
1613 (defun article-fill-long-lines ()
1614 "Fill lines that are wider than the window width."
1617 (let ((buffer-read-only nil)
1618 (width (window-width (get-buffer-window (current-buffer)))))
1621 (let ((adaptive-fill-mode nil))
1624 (when (>= (current-column) (min fill-column width))
1625 (narrow-to-region (point) (gnus-point-at-bol))
1626 (fill-paragraph nil)
1627 (goto-char (point-max))
1629 (forward-line 1)))))))
1631 (defun article-capitalize-sentences ()
1632 "Capitalize the first word in each sentence."
1635 (let ((buffer-read-only nil)
1636 (paragraph-start "^[\n\^L]"))
1640 (forward-sentence)))))
1642 (defun article-remove-cr ()
1643 "Remove trailing CRs and then translate remaining CRs into LFs."
1646 (let ((buffer-read-only nil))
1647 (goto-char (point-min))
1648 (while (re-search-forward "\r+$" nil t)
1649 (replace-match "" t t))
1650 (goto-char (point-min))
1651 (while (search-forward "\r" nil t)
1652 (replace-match "\n" t t)))))
1654 (defun article-remove-trailing-blank-lines ()
1655 "Remove all trailing blank lines from the article."
1658 (let ((buffer-read-only nil))
1659 (goto-char (point-max))
1663 (while (and (not (bobp))
1664 (looking-at "^[ \t]*$")
1665 (not (gnus-annotation-in-region-p
1666 (point) (gnus-point-at-eol))))
1671 (defun article-display-x-face (&optional force)
1672 "Look for an X-Face header and display it if present."
1673 (interactive (list 'force))
1675 ;; Delete the old process, if any.
1676 (when (process-status "article-x-face")
1677 (delete-process "article-x-face"))
1678 (let ((inhibit-point-motion-hooks t)
1679 (case-fold-search t)
1682 (article-narrow-to-head)
1683 (goto-char (point-min))
1684 (setq from (message-fetch-field "from"))
1685 (goto-char (point-min))
1686 (while (and gnus-article-x-face-command
1689 ;; Check whether this face is censored.
1690 (not gnus-article-x-face-too-ugly)
1691 (and gnus-article-x-face-too-ugly from
1692 (not (string-match gnus-article-x-face-too-ugly
1694 ;; Has to be present.
1695 (re-search-forward "^X-Face:[ \t]*" nil t))
1696 ;; This used to try to do multiple faces (`while' instead of
1697 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1698 ;; work (b) it can crash some versions of Emacs (c) are
1699 ;; multiple faces really something to encourage?
1700 (when (stringp gnus-article-x-face-command)
1702 ;; We now have the area of the buffer where the X-Face is stored.
1705 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1706 ;; We display the face.
1707 (if (symbolp gnus-article-x-face-command)
1708 ;; The command is a lisp function, so we call it.
1709 (if (gnus-functionp gnus-article-x-face-command)
1710 (funcall gnus-article-x-face-command beg end)
1711 (error "%s is not a function" gnus-article-x-face-command))
1712 ;; The command is a string, so we interpret the command
1713 ;; as a, well, command, and fork it off.
1714 (let ((process-connection-type nil))
1715 (process-kill-without-query
1717 "article-x-face" nil shell-file-name shell-command-switch
1718 gnus-article-x-face-command))
1719 (process-send-region "article-x-face" beg end)
1720 (process-send-eof "article-x-face"))))))))))
1722 (defun article-decode-mime-words ()
1723 "Decode all MIME-encoded words in the article."
1726 (set-buffer gnus-article-buffer)
1727 (let ((inhibit-point-motion-hooks t)
1729 (mail-parse-charset gnus-newsgroup-charset)
1730 (mail-parse-ignored-charsets
1731 (save-excursion (set-buffer gnus-summary-buffer)
1732 gnus-newsgroup-ignored-charsets)))
1733 (mail-decode-encoded-word-region (point-min) (point-max)))))
1735 (defun article-decode-charset (&optional prompt)
1736 "Decode charset-encoded text in the article.
1737 If PROMPT (the prefix), prompt for a coding system to use."
1739 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1741 (mail-parse-charset gnus-newsgroup-charset)
1742 (mail-parse-ignored-charsets
1743 (save-excursion (condition-case nil
1744 (set-buffer gnus-summary-buffer)
1746 gnus-newsgroup-ignored-charsets))
1747 ct cte ctl charset format)
1750 (article-narrow-to-head)
1751 (setq ct (message-fetch-field "Content-Type" t)
1752 cte (message-fetch-field "Content-Transfer-Encoding" t)
1753 ctl (and ct (ignore-errors
1754 (mail-header-parse-content-type ct)))
1757 (mm-read-coding-system "Charset to decode: "))
1759 (mail-content-type-get ctl 'charset)))
1760 format (and ctl (mail-content-type-get ctl 'format)))
1762 (setq cte (mail-header-strip cte)))
1763 (if (and ctl (not (string-match "/" (car ctl))))
1765 (goto-char (point-max)))
1768 (narrow-to-region (point) (point-max))
1769 (when (and (eq mail-parse-charset 'gnus-decoded)
1770 (eq (mm-body-7-or-8) '8bit))
1771 ;; The text code could have been decoded.
1772 (setq charset mail-parse-charset))
1773 (when (and (or (not ctl)
1774 (equal (car ctl) "text/plain"))
1775 (not format)) ;; article with format will decode later.
1777 charset (and cte (intern (downcase
1778 (gnus-strip-whitespace cte))))
1781 (defun article-decode-encoded-words ()
1782 "Remove encoded-word encoding from headers."
1783 (let (buffer-read-only)
1784 (let ((charset (save-excursion
1785 (set-buffer gnus-summary-buffer)
1786 default-mime-charset)))
1787 (mime-decode-header-in-buffer charset)
1790 (defun article-de-quoted-unreadable (&optional force)
1791 "Translate a quoted-printable-encoded article.
1792 If FORCE, decode the article whether it is marked as quoted-printable
1794 (interactive (list 'force))
1796 (let ((buffer-read-only nil) type charset)
1797 (if (gnus-buffer-live-p gnus-original-article-buffer)
1798 (with-current-buffer gnus-original-article-buffer
1800 (gnus-fetch-field "content-transfer-encoding"))
1801 (let* ((ct (gnus-fetch-field "content-type"))
1804 (mail-header-parse-content-type ct)))))
1805 (setq charset (and ctl
1806 (mail-content-type-get ctl 'charset)))
1807 (if (stringp charset)
1808 (setq charset (intern (downcase charset)))))))
1810 (setq charset gnus-newsgroup-charset))
1812 (and type (let ((case-fold-search t))
1813 (string-match "quoted-printable" type))))
1815 (quoted-printable-decode-region
1816 (point) (point-max) (mm-charset-to-coding-system charset))))))
1818 (defun article-de-base64-unreadable (&optional force)
1819 "Translate a base64 article.
1820 If FORCE, decode the article whether it is marked as base64 not."
1821 (interactive (list 'force))
1823 (let ((buffer-read-only nil) type charset)
1824 (if (gnus-buffer-live-p gnus-original-article-buffer)
1825 (with-current-buffer gnus-original-article-buffer
1827 (gnus-fetch-field "content-transfer-encoding"))
1828 (let* ((ct (gnus-fetch-field "content-type"))
1831 (mail-header-parse-content-type ct)))))
1832 (setq charset (and ctl
1833 (mail-content-type-get ctl 'charset)))
1834 (if (stringp charset)
1835 (setq charset (intern (downcase charset)))))))
1837 (setq charset gnus-newsgroup-charset))
1839 (and type (let ((case-fold-search t))
1840 (string-match "base64" type))))
1843 (narrow-to-region (point) (point-max))
1844 (base64-decode-region (point-min) (point-max))
1845 (mm-decode-coding-region
1846 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1851 (defun article-decode-HZ ()
1852 "Translate a HZ-encoded article."
1856 (let ((buffer-read-only nil))
1857 (rfc1843-decode-region (point-min) (point-max)))))
1859 (defun article-wash-html ()
1860 "Format an html article."
1863 (let ((buffer-read-only nil)
1865 (if (gnus-buffer-live-p gnus-original-article-buffer)
1866 (with-current-buffer gnus-original-article-buffer
1867 (let* ((ct (gnus-fetch-field "content-type"))
1870 (mail-header-parse-content-type ct)))))
1871 (setq charset (and ctl
1872 (mail-content-type-get ctl 'charset)))
1873 (if (stringp charset)
1874 (setq charset (intern (downcase charset)))))))
1876 (setq charset gnus-newsgroup-charset))
1878 (save-window-excursion
1880 (narrow-to-region (point) (point-max))
1882 (let ((w3-strict-width (window-width))
1883 (url-standalone-mode t))
1885 (w3-region (point-min) (point-max))
1888 (defun article-hide-list-identifiers ()
1889 "Remove list identifies from the Subject header.
1890 The `gnus-list-identifiers' variable specifies what to do."
1894 (let ((inhibit-point-motion-hooks t)
1896 (article-narrow-to-head)
1897 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1898 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1900 (goto-char (point-min))
1901 (when (re-search-forward
1902 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1903 " *\\)\\)+\\(Re: +\\)?\\)")
1905 (let ((s (or (match-string 3) (match-string 5))))
1906 (delete-region (match-beginning 1) (match-end 1))
1908 (goto-char (match-beginning 1))
1911 (defun article-hide-pgp ()
1912 "Remove any PGP headers and signatures in the current article."
1916 (let ((inhibit-point-motion-hooks t)
1917 buffer-read-only beg end)
1919 ;; Hide the "header".
1920 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1921 (push 'pgp gnus-article-wash-types)
1922 (delete-region (match-beginning 0) (match-end 0))
1923 ;; Remove armor headers (rfc2440 6.2)
1924 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1927 ;; Hide the actual signature.
1928 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1929 (setq end (1+ (match-beginning 0)))
1932 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1934 ;; Perhaps we shouldn't hide to the end of the buffer
1935 ;; if there is no end to the signature?
1937 ;; Hide "- " PGP quotation markers.
1939 (narrow-to-region beg end)
1940 (goto-char (point-min))
1941 (while (re-search-forward "^- " nil t)
1943 (match-beginning 0) (match-end 0)))
1945 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1947 (defun article-hide-pem (&optional arg)
1948 "Toggle hiding of any PEM headers and signatures in the current article.
1949 If given a negative prefix, always show; if given a positive prefix,
1951 (interactive (gnus-article-hidden-arg))
1952 (unless (gnus-article-check-hidden-text 'pem arg)
1954 (let (buffer-read-only end)
1955 (goto-char (point-min))
1956 ;; Hide the horrendously ugly "header".
1957 (when (and (search-forward
1958 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1960 (setq end (1+ (match-beginning 0))))
1961 (push 'pem gnus-article-wash-types)
1962 (gnus-article-hide-text-type
1964 (if (search-forward "\n\n" nil t)
1968 ;; Hide the trailer as well
1969 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1971 (gnus-article-hide-text-type
1972 (match-beginning 0) (match-end 0) 'pem)))))))
1974 (defun article-strip-banner ()
1975 "Strip the banner specified by the `banner' group parameter."
1979 (let ((inhibit-point-motion-hooks t)
1980 (banner (gnus-parameter-banner gnus-newsgroup-name))
1981 (gnus-signature-limit nil)
1982 buffer-read-only beg end)
1986 ((eq banner 'signature)
1987 (when (gnus-article-narrow-to-signature)
1990 (delete-region (point) (point-max))))
1992 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1993 (while (re-search-forward banner nil t)
1994 (delete-region (match-beginning 0) (match-end 0)))))
1996 (while (re-search-forward banner nil t)
1997 (delete-region (match-beginning 0) (match-end 0))))))))))
1999 (defun article-babel ()
2000 "Translate article using an online translation service."
2004 (set-buffer gnus-article-buffer)
2005 (when (article-goto-body)
2006 (let* ((buffer-read-only nil)
2009 (orig (buffer-substring start end))
2010 (trans (babel-as-string orig)))
2012 (narrow-to-region start end)
2013 (delete-region start end)
2016 (defun article-hide-signature (&optional arg)
2017 "Hide the signature in the current article.
2018 If given a negative prefix, always show; if given a positive prefix,
2020 (interactive (gnus-article-hidden-arg))
2026 (article-goto-body))
2027 (goto-char (point-min)))
2028 (unless (gnus-article-check-hidden-text 'signature arg)
2029 (let ((buffer-read-only nil)
2031 (while (setq button (text-property-any button (point-max)
2033 'gnus-signature-toggle))
2034 (setq button (text-property-not-all button (point-max)
2036 'gnus-signature-toggle))
2037 (when (and button (not (eobp)))
2038 (gnus-article-hide-text-type
2040 (next-single-property-change (1+ button) 'mime-view-entity
2044 (defun article-strip-headers-in-body ()
2045 "Strip offensive headers from bodies."
2049 (let ((case-fold-search t))
2050 (when (looking-at "x-no-archive:")
2051 (gnus-delete-line)))))
2053 (defun article-strip-leading-blank-lines ()
2054 "Remove all blank lines from the beginning of the article."
2057 (let ((inhibit-point-motion-hooks t)
2059 (when (article-goto-body)
2060 (while (and (not (eobp))
2061 (looking-at "[ \t]*$"))
2062 (gnus-delete-line))))))
2064 (defun article-narrow-to-head ()
2065 "Narrow the buffer to the head of the message.
2066 Point is left at the beginning of the narrowed-to region."
2068 (goto-char (point-min))
2069 (if (search-forward "\n\n" nil 1)
2072 (goto-char (point-min)))
2074 (defun article-goto-body ()
2075 "Place point at the start of the body."
2076 (goto-char (point-min))
2078 ;; This variable is only bound when dealing with separate
2080 (article-goto-body-goes-to-point-min-p
2082 ((search-forward "\n\n" nil t)
2085 (goto-char (point-max))
2088 (defun article-strip-multiple-blank-lines ()
2089 "Replace consecutive blank lines with one empty line."
2092 (let ((inhibit-point-motion-hooks t)
2094 ;; First make all blank lines empty.
2096 (while (re-search-forward "^[ \t]+$" nil t)
2097 (unless (gnus-annotation-in-region-p
2098 (match-beginning 0) (match-end 0))
2099 (replace-match "" nil t)))
2100 ;; Then replace multiple empty lines with a single empty line.
2102 (while (re-search-forward "\n\n\n+" nil t)
2103 (unless (gnus-annotation-in-region-p
2104 (match-beginning 0) (match-end 0))
2105 (replace-match "\n\n" t t))))))
2107 (defun article-strip-leading-space ()
2108 "Remove all white space from the beginning of the lines in the article."
2111 (let ((inhibit-point-motion-hooks t)
2114 (while (re-search-forward "^[ \t]+" nil t)
2115 (replace-match "" t t)))))
2117 (defun article-strip-trailing-space ()
2118 "Remove all white space from the end of the lines in the article."
2121 (let ((inhibit-point-motion-hooks t)
2124 (while (re-search-forward "[ \t]+$" nil t)
2125 (replace-match "" t t)))))
2127 (defun article-strip-blank-lines ()
2128 "Strip leading, trailing and multiple blank lines."
2130 (article-strip-leading-blank-lines)
2131 (article-remove-trailing-blank-lines)
2132 (article-strip-multiple-blank-lines))
2134 (defun article-strip-all-blank-lines ()
2135 "Strip all blank lines."
2138 (let ((inhibit-point-motion-hooks t)
2141 (while (re-search-forward "^[ \t]*\n" nil t)
2142 (replace-match "" t t)))))
2144 (defun gnus-article-narrow-to-signature ()
2145 "Narrow to the signature; return t if a signature is found, else nil."
2146 (let ((inhibit-point-motion-hooks t))
2147 (when (gnus-article-search-signature)
2149 ;; Check whether we have some limits to what we consider
2150 ;; to be a signature.
2151 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2152 (list gnus-signature-limit)))
2154 (while (setq limit (pop limits))
2155 (if (or (and (integerp limit)
2156 (< (- (point-max) (point)) limit))
2158 (< (count-lines (point) (point-max)) limit))
2159 (and (gnus-functionp limit)
2161 (and (stringp limit)
2162 (not (re-search-forward limit nil t))))
2163 () ; This limit did not succeed.
2167 (narrow-to-region (point) (point-max))
2170 (defun gnus-article-search-signature ()
2171 "Search the current buffer for the signature separator.
2172 Put point at the beginning of the signature separator."
2173 (let ((cur (point)))
2174 (goto-char (point-max))
2175 (if (if (stringp gnus-signature-separator)
2176 (re-search-backward gnus-signature-separator nil t)
2177 (let ((seps gnus-signature-separator))
2179 (not (re-search-backward (car seps) nil t)))
2186 (defun gnus-article-hidden-arg ()
2187 "Return the current prefix arg as a number, or 0 if no prefix."
2188 (list (if current-prefix-arg
2189 (prefix-numeric-value current-prefix-arg)
2192 (defun gnus-article-check-hidden-text (type arg)
2193 "Return nil if hiding is necessary.
2194 Arg can be nil or a number. Nil and positive means hide, negative
2195 means show, 0 means toggle."
2198 (let ((hide (gnus-article-hidden-text-p type)))
2204 (gnus-article-show-hidden-text type)
2207 (if (eq hide 'hidden)
2209 (gnus-article-show-hidden-text type)
2213 (defun gnus-article-hidden-text-p (type)
2214 "Say whether the current buffer contains hidden text of type TYPE."
2215 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2217 (not (get-text-property pos 'invisible))
2218 (not (get-text-property pos 'dummy-invisible)))
2220 (text-property-any (1+ pos) (point-max) 'article-type type)))
2225 (defun gnus-article-show-hidden-text (type &optional dummy)
2226 "Show all hidden text of type TYPE.
2227 Originally it is hide instead of DUMMY."
2228 (let ((buffer-read-only nil)
2229 (inhibit-point-motion-hooks t))
2230 (gnus-remove-text-properties-when
2232 (point-min) (point-max)
2233 (cons 'article-type (cons type
2234 gnus-hidden-properties)))))
2236 (defconst article-time-units
2237 `((year . ,(* 365.25 24 60 60))
2238 (week . ,(* 7 24 60 60))
2239 (day . ,(* 24 60 60))
2243 "Mapping from time units to seconds.")
2245 (defun article-date-ut (&optional type highlight header)
2246 "Convert DATE date to universal time in the current article.
2247 If TYPE is `local', convert to local time; if it is `lapsed', output
2248 how much time has lapsed since DATE. For `lapsed', the value of
2249 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2250 should replace the \"Date:\" one, or should be added below it."
2251 (interactive (list 'ut t))
2252 (let* ((header (or header
2253 (and (eq 1 (point-min))
2254 (mail-header-date (save-excursion
2255 (set-buffer gnus-summary-buffer)
2256 gnus-current-headers)))
2257 (message-fetch-field "date")
2259 (date (if (vectorp header) (mail-header-date header)
2261 (inhibit-point-motion-hooks t)
2262 bface eface date-pos)
2263 (when (and date (not (string= date "")))
2266 (article-narrow-to-head)
2267 (when (or (and (eq type 'lapsed)
2268 gnus-article-date-lapsed-new-header
2269 ;; Attempt to get the face of X-Sent first.
2270 (re-search-forward "^X-Sent:[ \t]" nil t))
2271 (re-search-forward "^Date:[ \t]" nil t)
2272 ;; If Date is missing, try again for X-Sent.
2273 (re-search-forward "^X-Sent:[ \t]" nil t))
2274 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2275 date (or (get-text-property (gnus-point-at-bol)
2278 eface (get-text-property (1- (gnus-point-at-eol))
2280 (let ((buffer-read-only nil))
2281 ;; Delete any old X-Sent headers.
2282 (when (setq date-pos
2283 (text-property-any (point-min) (point-max)
2284 'article-date-lapsed t))
2285 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2286 (delete-region (match-beginning 0)
2287 (progn (forward-line 1) (point))))
2288 (goto-char (point-min))
2289 ;; Delete any old Date headers.
2290 (while (re-search-forward "^Date:[ \t]" nil t)
2292 (setq date-pos (match-beginning 0)))
2293 (unless (and (eq type 'lapsed)
2294 gnus-article-date-lapsed-new-header)
2295 (delete-region (match-beginning 0)
2296 (progn (message-next-header) (point)))))
2299 (goto-char date-pos)
2301 ;; Possibly, Date has been deleted.
2303 (when (and (eq type 'lapsed)
2304 gnus-article-date-lapsed-new-header
2305 (looking-at "Date:"))
2307 (goto-char (point-min)))
2308 (insert (article-make-date-line date type))
2309 (when (eq type 'lapsed)
2310 (put-text-property (gnus-point-at-bol) (point)
2311 'article-date-lapsed t))
2315 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2316 (put-text-property (match-beginning 1) (1+ (match-end 1))
2317 'original-date date)
2318 (put-text-property (match-beginning 1) (1+ (match-end 1))
2320 (put-text-property (match-beginning 2) (match-end 2)
2323 (defun article-make-date-line (date type)
2324 "Return a DATE line of TYPE."
2325 (let ((time (condition-case ()
2329 ;; Convert to the local timezone. We have to slap a
2330 ;; `condition-case' round the calls to the timezone
2331 ;; functions since they aren't particularly resistant to
2334 (let ((tz (car (current-time-zone time))))
2335 (format "Date: %s %s%02d%02d" (current-time-string time)
2336 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2337 (/ (% (abs tz) 3600) 60))))
2338 ;; Convert to Universal Time.
2341 (current-time-string
2342 (let* ((e (parse-time-string date))
2343 (tm (apply 'encode-time e))
2345 (ls (- (cadr tm) (car (current-time-zone time)))))
2346 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2347 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2350 ;; Get the original date from the article.
2351 ((eq type 'original)
2352 (concat "Date: " (if (string-match "\n+$" date)
2353 (substring date 0 (match-beginning 0))
2355 ;; Let the user define the format.
2357 (if (gnus-functionp gnus-article-time-format)
2358 (funcall gnus-article-time-format time)
2361 (format-time-string gnus-article-time-format time))))
2364 (let ((tz (car (current-time-zone time))))
2367 (format-time-string "%Y%m%dT%H%M%S" time)
2368 (format "%s%02d%02d"
2369 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2370 (/ (% (abs tz) 3600) 60)))))
2371 ;; Do an X-Sent lapsed format.
2373 ;; If the date is seriously mangled, the timezone functions are
2374 ;; liable to bug out, so we ignore all errors.
2375 (let* ((now (current-time))
2376 (real-time (subtract-time now time))
2377 (real-sec (and real-time
2378 (+ (* (float (car real-time)) 65536)
2380 (sec (and real-time (abs real-sec)))
2390 ;; This is a bit convoluted, but basically we go
2391 ;; through the time units for years, weeks, etc,
2392 ;; and divide things to see whether that results
2393 ;; in positive answers.
2396 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2397 ;; The (remaining) seconds are too few to
2398 ;; be divided into this time unit.
2400 ;; It's big enough, so we output it.
2401 (setq sec (- sec (* num (cdr unit))))
2403 (concat (if prev ", " "") (int-to-string
2405 " " (symbol-name (car unit))
2406 (if (> num 1) "s" ""))
2408 article-time-units "")
2409 ;; If dates are odd, then it might appear like the
2410 ;; article was sent in the future.
2413 " in the future"))))))
2415 (error "Unknown conversion type: %s" type)))))
2417 (defun article-date-local (&optional highlight)
2418 "Convert the current article date to the local timezone."
2419 (interactive (list t))
2420 (article-date-ut 'local highlight))
2422 (defun article-date-original (&optional highlight)
2423 "Convert the current article date to what it was originally.
2424 This is only useful if you have used some other date conversion
2425 function and want to see what the date was before converting."
2426 (interactive (list t))
2427 (article-date-ut 'original highlight))
2429 (defun article-date-lapsed (&optional highlight)
2430 "Convert the current article date to time lapsed since it was sent."
2431 (interactive (list t))
2432 (article-date-ut 'lapsed highlight))
2434 (defun article-update-date-lapsed ()
2435 "Function to be run from a timer to update the lapsed time line."
2436 (let (deactivate-mark)
2441 (set-buffer (window-buffer w))
2442 (when (eq major-mode 'gnus-article-mode)
2443 (goto-char (point-min))
2444 (when (re-search-forward "^X-Sent:" nil t)
2445 (article-date-lapsed t))))
2448 (defun gnus-start-date-timer (&optional n)
2449 "Start a timer to update the X-Sent header in the article buffers.
2450 The numerical prefix says how frequently (in seconds) the function
2455 (gnus-stop-date-timer)
2456 (setq article-lapsed-timer
2457 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2459 (defun gnus-stop-date-timer ()
2460 "Stop the X-Sent timer."
2462 (when article-lapsed-timer
2463 (nnheader-cancel-timer article-lapsed-timer)
2464 (setq article-lapsed-timer nil)))
2466 (defun article-date-user (&optional highlight)
2467 "Convert the current article date to the user-defined format.
2468 This format is defined by the `gnus-article-time-format' variable."
2469 (interactive (list t))
2470 (article-date-ut 'user highlight))
2472 (defun article-date-iso8601 (&optional highlight)
2473 "Convert the current article date to ISO8601."
2474 (interactive (list t))
2475 (article-date-ut 'iso8601 highlight))
2477 (defun article-show-all ()
2478 "Show all hidden text in the article buffer."
2482 (let ((buffer-read-only nil))
2483 (gnus-article-unhide-text (point-min) (point-max))
2484 (gnus-remove-text-with-property 'gnus-prev)
2485 (gnus-remove-text-with-property 'gnus-next))))
2487 (defun article-show-all-headers ()
2488 "Show all hidden headers in the article buffer."
2493 (article-narrow-to-head)
2494 (let ((buffer-read-only nil))
2495 (gnus-article-unhide-text (point-min) (point-max))))))
2497 (defun article-emphasize (&optional arg)
2498 "Emphasize text according to `gnus-emphasis-alist'."
2499 (interactive (gnus-article-hidden-arg))
2500 (unless (gnus-article-check-hidden-text 'emphasis arg)
2504 (with-current-buffer gnus-summary-buffer
2505 gnus-article-emphasis-alist)
2507 gnus-emphasis-alist))
2508 (buffer-read-only nil)
2509 (props (append '(article-type emphasis)
2510 gnus-hidden-properties))
2511 regexp elem beg invisible visible face)
2514 (while (setq elem (pop alist))
2516 (setq regexp (car elem)
2517 invisible (nth 1 elem)
2518 visible (nth 2 elem)
2520 (while (re-search-forward regexp nil t)
2521 (when (and (match-beginning visible) (match-beginning invisible))
2522 (push 'emphasis gnus-article-wash-types)
2523 (gnus-article-hide-text
2524 (match-beginning invisible) (match-end invisible) props)
2525 (gnus-article-unhide-text-type
2526 (match-beginning visible) (match-end visible) 'emphasis)
2527 (gnus-put-text-property-excluding-newlines
2528 (match-beginning visible) (match-end visible) 'face face)
2529 (goto-char (match-end invisible)))))))))
2531 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2532 "Setup newsgroup emphasis alist."
2533 (unless gnus-article-emphasis-alist
2534 (let ((name (and gnus-newsgroup-name
2535 (gnus-group-real-name gnus-newsgroup-name))))
2536 (make-local-variable 'gnus-article-emphasis-alist)
2537 (setq gnus-article-emphasis-alist
2539 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2540 (while (setq elem (pop alist))
2541 (when (and name (string-match (car elem) name))
2543 highlight (copy-sequence (cdr elem)))))
2545 (copy-sequence highlight-words)
2546 (if gnus-newsgroup-name
2547 (copy-sequence (gnus-group-find-parameter
2548 gnus-newsgroup-name 'highlight-words t)))
2549 gnus-emphasis-alist)))))
2551 (defvar gnus-summary-article-menu)
2552 (defvar gnus-summary-post-menu)
2554 ;;; Saving functions.
2556 (defun gnus-article-save (save-buffer file &optional num)
2557 "Save the currently selected article."
2558 (unless gnus-save-all-headers
2559 ;; Remove headers according to `gnus-saved-headers'.
2560 (let ((gnus-visible-headers
2561 (or gnus-saved-headers gnus-visible-headers))
2562 (gnus-article-buffer save-buffer))
2564 (set-buffer save-buffer)
2565 (article-hide-headers 1 t))))
2566 (save-window-excursion
2567 (if (not gnus-default-article-saver)
2568 (error "No default saver is defined")
2569 ;; !!! Magic! The saving functions all save
2570 ;; `gnus-save-article-buffer' (or so they think), but we
2571 ;; bind that variable to our save-buffer.
2572 (set-buffer gnus-article-buffer)
2573 (let* ((gnus-save-article-buffer save-buffer)
2576 ((not gnus-prompt-before-saving) 'default)
2577 ((eq gnus-prompt-before-saving 'always) nil)
2579 (gnus-number-of-articles-to-be-saved
2580 (when (eq gnus-prompt-before-saving t)
2582 (set-buffer gnus-article-current-summary)
2583 (funcall gnus-default-article-saver filename)))))
2585 (defun gnus-read-save-file-name (prompt &optional filename
2586 function group headers variable)
2588 (funcall function group headers (symbol-value variable)))
2593 ((eq filename 'default)
2599 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2602 (if (and gnus-number-of-articles-to-be-saved
2603 (> gnus-number-of-articles-to-be-saved 1))
2604 (format "these %d articles"
2605 gnus-number-of-articles-to-be-saved)
2608 ;; Let the split methods have their say.
2610 ;; No split name was found.
2613 (concat prompt " (default "
2614 (file-name-nondirectory default-name) ") ")
2615 (file-name-directory default-name)
2617 ;; A single group name is returned.
2618 ((stringp split-name)
2620 (funcall function split-name headers
2621 (symbol-value variable)))
2623 (concat prompt " (default "
2624 (file-name-nondirectory default-name) ") ")
2625 (file-name-directory default-name)
2627 ;; A single split name was found
2628 ((= 1 (length split-name))
2629 (let* ((name (expand-file-name
2631 gnus-article-save-directory))
2632 (dir (cond ((file-directory-p name)
2633 (file-name-as-directory name))
2634 ((file-exists-p name) name)
2635 (t gnus-article-save-directory))))
2637 (concat prompt " (default " name ") ")
2639 ;; A list of splits was found.
2641 (setq split-name (nreverse split-name))
2643 (let ((file-name-history
2644 (nconc split-name file-name-history)))
2648 (concat prompt " (`M-p' for defaults) ")
2649 gnus-article-save-directory
2651 gnus-article-save-directory)))
2652 (car (push result file-name-history)))))))
2653 ;; Create the directory.
2654 (gnus-make-directory (file-name-directory file))
2655 ;; If we have read a directory, we append the default file name.
2656 (when (file-directory-p file)
2657 (setq file (expand-file-name (file-name-nondirectory
2659 (file-name-as-directory file))))
2660 ;; Possibly translate some characters.
2661 (nnheader-translate-file-chars file))))))
2662 (gnus-make-directory (file-name-directory result))
2663 (set variable result)))
2665 (defun gnus-article-archive-name (group)
2666 "Return the first instance of an \"Archive-name\" in the current buffer."
2667 (let ((case-fold-search t))
2668 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2669 (nnheader-concat gnus-article-save-directory
2670 (match-string 1)))))
2672 (defun gnus-article-nndoc-name (group)
2673 "If GROUP is an nndoc group, return the name of the parent group."
2674 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2675 (gnus-group-get-parameter group 'save-article-group)))
2677 (defun gnus-summary-save-in-rmail (&optional filename)
2678 "Append this article to Rmail file.
2679 Optional argument FILENAME specifies file name.
2680 Directory to save to is default to `gnus-article-save-directory'."
2681 (setq filename (gnus-read-save-file-name
2682 "Save %s in rmail file:" filename
2683 gnus-rmail-save-name gnus-newsgroup-name
2684 gnus-current-headers 'gnus-newsgroup-last-rmail))
2685 (gnus-eval-in-buffer-window gnus-save-article-buffer
2689 (gnus-output-to-rmail filename))))
2692 (defun gnus-summary-save-in-mail (&optional filename)
2693 "Append this article to Unix mail file.
2694 Optional argument FILENAME specifies file name.
2695 Directory to save to is default to `gnus-article-save-directory'."
2696 (setq filename (gnus-read-save-file-name
2697 "Save %s in Unix mail file:" filename
2698 gnus-mail-save-name gnus-newsgroup-name
2699 gnus-current-headers 'gnus-newsgroup-last-mail))
2700 (gnus-eval-in-buffer-window gnus-save-article-buffer
2704 (if (and (file-readable-p filename)
2705 (mail-file-babyl-p filename))
2706 (rmail-output-to-rmail-file filename t)
2707 (gnus-output-to-mail filename)))))
2710 (defun gnus-summary-save-in-file (&optional filename overwrite)
2711 "Append this article to file.
2712 Optional argument FILENAME specifies file name.
2713 Directory to save to is default to `gnus-article-save-directory'."
2714 (setq filename (gnus-read-save-file-name
2715 "Save %s in file:" filename
2716 gnus-file-save-name gnus-newsgroup-name
2717 gnus-current-headers 'gnus-newsgroup-last-file))
2718 (gnus-eval-in-buffer-window gnus-save-article-buffer
2722 (when (and overwrite
2723 (file-exists-p filename))
2724 (delete-file filename))
2725 (gnus-output-to-file filename))))
2728 (defun gnus-summary-write-to-file (&optional filename)
2729 "Write this article to a file.
2730 Optional argument FILENAME specifies file name.
2731 The directory to save in defaults to `gnus-article-save-directory'."
2732 (gnus-summary-save-in-file nil t))
2734 (defun gnus-summary-save-body-in-file (&optional filename)
2735 "Append this article body to a file.
2736 Optional argument FILENAME specifies file name.
2737 The directory to save in defaults to `gnus-article-save-directory'."
2738 (setq filename (gnus-read-save-file-name
2739 "Save %s body in file:" filename
2740 gnus-file-save-name gnus-newsgroup-name
2741 gnus-current-headers 'gnus-newsgroup-last-file))
2742 (gnus-eval-in-buffer-window gnus-save-article-buffer
2746 (when (article-goto-body)
2747 (narrow-to-region (point) (point-max)))
2748 (gnus-output-to-file filename))))
2751 (defun gnus-summary-save-in-pipe (&optional command)
2752 "Pipe this article to subprocess."
2754 (cond ((and (eq command 'default)
2755 gnus-last-shell-command)
2756 gnus-last-shell-command)
2760 "Shell command on %s: "
2761 (if (and gnus-number-of-articles-to-be-saved
2762 (> gnus-number-of-articles-to-be-saved 1))
2763 (format "these %d articles"
2764 gnus-number-of-articles-to-be-saved)
2766 gnus-last-shell-command))))
2767 (when (string-equal command "")
2768 (setq command gnus-last-shell-command))
2769 (gnus-eval-in-buffer-window gnus-article-buffer
2772 (shell-command-on-region (point-min) (point-max) command nil)))
2773 (setq gnus-last-shell-command command))
2775 ;;; Article file names when saving.
2777 (defun gnus-capitalize-newsgroup (newsgroup)
2778 "Capitalize NEWSGROUP name."
2779 (when (not (zerop (length newsgroup)))
2780 (concat (char-to-string (upcase (aref newsgroup 0)))
2781 (substring newsgroup 1))))
2783 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2784 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2785 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2786 Otherwise, it is like ~/News/news/group/num."
2789 (concat (if (gnus-use-long-file-name 'not-save)
2790 (gnus-capitalize-newsgroup newsgroup)
2791 (gnus-newsgroup-directory-form newsgroup))
2792 "/" (int-to-string (mail-header-number headers)))
2793 gnus-article-save-directory)))
2795 (string-equal (file-name-directory default)
2796 (file-name-directory last-file))
2797 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2799 (or last-file default))))
2801 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2802 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2803 If variable `gnus-use-long-file-name' is non-nil, it is
2804 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2807 (concat (if (gnus-use-long-file-name 'not-save)
2809 (gnus-newsgroup-directory-form newsgroup))
2810 "/" (int-to-string (mail-header-number headers)))
2811 gnus-article-save-directory)))
2813 (string-equal (file-name-directory default)
2814 (file-name-directory last-file))
2815 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2817 (or last-file default))))
2819 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2820 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2821 If variable `gnus-use-long-file-name' is non-nil, it is
2822 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2825 (if (gnus-use-long-file-name 'not-save)
2827 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2828 gnus-article-save-directory)))
2830 (defun article-verify-x-pgp-sig ()
2833 (if (gnus-buffer-live-p gnus-original-article-buffer)
2834 (let ((sig (with-current-buffer gnus-original-article-buffer
2835 (gnus-fetch-field "X-PGP-Sig")))
2839 (mml2015-clear-verify-function))
2841 (insert-buffer gnus-original-article-buffer)
2842 (setq items (split-string sig))
2843 (message-narrow-to-head)
2844 (let ((inhibit-point-motion-hooks t)
2845 (case-fold-search t))
2846 ;; Don't verify multiple headers.
2847 (setq headers (mapconcat (lambda (header)
2849 (mail-fetch-field header) "\n"))
2850 (split-string (nth 1 items) ",") "")))
2851 (delete-region (point-min) (point-max))
2852 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2853 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2858 (if (looking-at "^-")
2861 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2862 (insert "Version: " (car items) "\n\n")
2863 (insert (mapconcat 'identity (cddr items) "\n"))
2864 (insert "\n-----END PGP SIGNATURE-----\n")
2865 (let ((mm-security-handle (list (format "multipart/signed"))))
2866 (mml2015-clean-buffer)
2867 (let ((coding-system-for-write (or gnus-newsgroup-charset
2869 (funcall (mml2015-clear-verify-function)))
2871 (or (mm-handle-multipart-ctl-parameter
2872 mm-security-handle 'gnus-details)
2873 (mm-handle-multipart-ctl-parameter
2874 mm-security-handle 'gnus-info)))))
2876 (let (buffer-read-only bface eface)
2878 (message-narrow-to-head)
2879 (goto-char (point-max))
2881 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2882 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2883 (message-remove-header "X-Gnus-PGP-Verify")
2884 (if (re-search-forward "^X-PGP-Sig:" nil t)
2886 (goto-char (point-max)))
2887 (narrow-to-region (point) (point))
2888 (insert "X-Gnus-PGP-Verify: " info "\n")
2889 (goto-char (point-min))
2892 (if (not (looking-at "^[ \t]"))
2896 (goto-char (point-min))
2897 (when (looking-at "\\([^:]+\\): *")
2898 (put-text-property (match-beginning 1) (1+ (match-end 1))
2900 (put-text-property (match-end 0) (point-max)
2901 'face eface)))))))))
2908 (setq afunc (car func)
2911 gfunc (intern (format "gnus-%s" func))))
2914 `(lambda (&optional interactive &rest args)
2915 ,(documentation afunc t)
2916 (interactive (list t))
2918 (set-buffer gnus-article-buffer)
2920 (call-interactively ',afunc)
2921 (apply ',afunc args))))))))
2922 '(article-hide-headers
2923 article-verify-x-pgp-sig
2924 article-hide-boring-headers
2925 article-toggle-headers
2926 article-treat-overstrike
2927 article-fill-long-lines
2928 article-capitalize-sentences
2930 article-display-x-face
2931 article-de-quoted-unreadable
2932 article-de-base64-unreadable
2935 article-hide-list-identifiers
2937 article-strip-banner
2940 article-hide-signature
2941 article-strip-headers-in-body
2942 article-remove-trailing-blank-lines
2943 article-strip-leading-blank-lines
2944 article-strip-multiple-blank-lines
2945 article-strip-leading-space
2946 article-strip-trailing-space
2947 article-strip-blank-lines
2948 article-strip-all-blank-lines
2950 article-date-iso8601
2951 article-date-original
2953 article-decode-mime-words
2954 article-decode-charset
2955 article-decode-encoded-words
2959 article-treat-dumbquotes
2960 article-normalize-headers
2961 (article-show-all-headers . gnus-article-show-all-headers)
2962 (article-show-all . gnus-article-show-all))))
2965 ;;; Gnus article mode
2968 (put 'gnus-article-mode 'mode-class 'special)
2970 (gnus-define-keys gnus-article-mode-map
2971 " " gnus-article-goto-next-page
2972 "\177" gnus-article-goto-prev-page
2973 [delete] gnus-article-goto-prev-page
2974 [backspace] gnus-article-goto-prev-page
2975 "\C-c^" gnus-article-refer-article
2976 "h" gnus-article-show-summary
2977 "s" gnus-article-show-summary
2978 "\C-c\C-m" gnus-article-mail
2979 "?" gnus-article-describe-briefly
2980 "e" gnus-summary-edit-article
2981 "<" beginning-of-buffer
2983 "\C-c\C-i" gnus-info-find-node
2985 "\C-hk" gnus-article-describe-key
2986 "\C-hc" gnus-article-describe-key-briefly
2988 "\C-d" gnus-article-read-summary-keys
2989 "\M-*" gnus-article-read-summary-keys
2990 "\M-#" gnus-article-read-summary-keys
2991 "\M-^" gnus-article-read-summary-keys
2992 "\M-g" gnus-article-read-summary-keys)
2994 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2997 (unless (lookup-key gnus-article-mode-map key)
2998 (define-key gnus-article-mode-map key
2999 'gnus-article-read-summary-keys)))
3004 (let ((key (car elt)))
3005 (and (> (length key) 0)
3006 (not (eq 'menu-bar (aref key 0)))
3007 (symbolp (lookup-key gnus-summary-mode-map key))
3009 (accessible-keymaps gnus-summary-mode-map))
3013 (push (char-to-string c) keys)
3018 (defvar gnus-article-commands-menu))
3020 (defun gnus-article-make-menu-bar ()
3021 (gnus-turn-off-edit-menu 'article)
3022 (unless (boundp 'gnus-article-article-menu)
3024 gnus-article-article-menu gnus-article-mode-map ""
3026 ["Scroll forwards" gnus-article-goto-next-page t]
3027 ["Scroll backwards" gnus-article-goto-prev-page t]
3028 ["Show summary" gnus-article-show-summary t]
3029 ["Fetch Message-ID at point" gnus-article-refer-article t]
3030 ["Mail to address at point" gnus-article-mail t]
3031 ["Send a bug report" gnus-bug t]))
3034 gnus-article-treatment-menu gnus-article-mode-map ""
3035 ;; Fixme: this should use :active (and maybe :visible).
3037 ["Hide headers" gnus-article-toggle-headers t]
3038 ["Hide signature" gnus-article-hide-signature t]
3039 ["Hide citation" gnus-article-hide-citation t]
3040 ["Treat overstrike" gnus-article-treat-overstrike t]
3041 ["Remove carriage return" gnus-article-remove-cr t]
3042 ["Decode HZ" gnus-article-decode-HZ t]))
3044 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3046 (when (boundp 'gnus-summary-post-menu)
3047 (define-key gnus-article-mode-map [menu-bar post]
3048 (cons "Post" gnus-summary-post-menu)))
3050 (gnus-run-hooks 'gnus-article-menu-hook))
3052 (when (boundp 'gnus-article-commands-menu)
3053 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
3054 (when (boundp 'gnus-summary-post-menu)
3055 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
3057 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3060 (defun gnus-article-mode ()
3061 "Major mode for displaying an article.
3063 All normal editing commands are switched off.
3065 The following commands are available in addition to all summary mode
3067 \\<gnus-article-mode-map>
3068 \\[gnus-article-next-page]\t Scroll the article one page forwards
3069 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3070 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3071 \\[gnus-article-show-summary]\t Display the summary buffer
3072 \\[gnus-article-mail]\t Send a reply to the address near point
3073 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3074 \\[gnus-info-find-node]\t Go to the Gnus info node"
3076 (when (gnus-visual-p 'article-menu 'menu)
3077 (gnus-article-make-menu-bar))
3078 (gnus-simplify-mode-line)
3079 (setq mode-name "Article")
3080 (setq major-mode 'gnus-article-mode)
3081 (make-local-variable 'minor-mode-alist)
3082 (unless (assq 'gnus-show-mime minor-mode-alist)
3083 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3084 (use-local-map gnus-article-mode-map)
3085 (gnus-update-format-specifications nil 'article-mode)
3086 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3087 (make-local-variable 'gnus-page-broken)
3088 (make-local-variable 'gnus-button-marker-list)
3089 (make-local-variable 'gnus-article-current-summary)
3090 (make-local-variable 'gnus-article-mime-handles)
3091 (make-local-variable 'gnus-article-decoded-p)
3092 (make-local-variable 'gnus-article-mime-handle-alist)
3093 (make-local-variable 'gnus-article-wash-types)
3094 (make-local-variable 'gnus-article-charset)
3095 (make-local-variable 'gnus-article-ignored-charsets)
3096 (gnus-set-default-directory)
3097 (buffer-disable-undo)
3098 (setq buffer-read-only t)
3099 (set-syntax-table gnus-article-mode-syntax-table)
3100 (gnus-run-hooks 'gnus-article-mode-hook))
3102 (defun gnus-article-setup-buffer ()
3103 "Initialize the article buffer."
3104 (let* ((name (if gnus-single-article-buffer "*Article*"
3105 (concat "*Article " gnus-newsgroup-name "*")))
3107 (progn (string-match "\\*Article" name)
3108 (concat " *Original Article"
3109 (substring name (match-end 0))))))
3110 (setq gnus-article-buffer name)
3111 (setq gnus-original-article-buffer original)
3112 (setq gnus-article-mime-handle-alist nil)
3113 ;; This might be a variable local to the summary buffer.
3114 (unless gnus-single-article-buffer
3116 (set-buffer gnus-summary-buffer)
3117 (setq gnus-article-buffer name)
3118 (setq gnus-original-article-buffer original)
3119 (gnus-set-global-variables)))
3120 (gnus-article-setup-highlight-words)
3121 ;; Init original article buffer.
3123 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3124 (set-buffer-multibyte nil)
3125 (setq major-mode 'gnus-original-article-mode)
3126 (make-local-variable 'gnus-original-article))
3127 (if (get-buffer name)
3130 (buffer-disable-undo)
3131 (setq buffer-read-only t)
3132 (unless (eq major-mode 'gnus-article-mode)
3133 (gnus-article-mode))
3136 (set-buffer (gnus-get-buffer-create name))
3138 (make-local-variable 'gnus-summary-buffer)
3139 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3140 (current-buffer)))))
3142 ;; Set article window start at LINE, where LINE is the number of lines
3143 ;; from the head of the article.
3144 (defun gnus-article-set-window-start (&optional line)
3146 (get-buffer-window gnus-article-buffer t)
3148 (set-buffer gnus-article-buffer)
3149 (goto-char (point-min))
3152 (gnus-message 6 "Moved to bookmark")
3153 (search-forward "\n\n" nil t)
3157 ;;; @@ article filters
3160 (defun gnus-article-display-mime-message ()
3161 "Article display method for MIME message."
3162 ;; called from `gnus-original-article-buffer'.
3163 (let (charset all-headers)
3164 (with-current-buffer gnus-summary-buffer
3165 (setq charset default-mime-charset
3166 all-headers gnus-have-all-headers))
3167 (make-local-variable 'default-mime-charset)
3168 (setq default-mime-charset charset)
3169 (with-current-buffer (get-buffer-create gnus-article-buffer)
3170 (make-local-variable 'default-mime-charset)
3171 (setq default-mime-charset charset))
3172 (mime-display-message mime-message-structure
3173 gnus-article-buffer nil gnus-article-mode-map)
3175 (gnus-article-hide-headers nil -1)))
3176 (run-hooks 'gnus-mime-article-prepare-hook))
3178 (defun gnus-article-display-traditional-message ()
3179 "Article display method for traditional message."
3180 (set-buffer gnus-article-buffer)
3181 (let (buffer-read-only)
3183 (insert-buffer-substring gnus-original-article-buffer)))
3185 (defun gnus-article-make-full-mail-header (&optional number charset)
3186 "Create a new mail header structure in a raw article buffer."
3187 (unless (and number charset)
3188 (save-current-buffer
3189 (set-buffer gnus-summary-buffer)
3191 (setq number (or (cdr gnus-article-current) 0)))
3193 (setq charset (or default-mime-charset 'x-ctext)))))
3194 (goto-char (point-min))
3195 (let ((header-end (if (search-forward "\n\n" nil t)
3197 (goto-char (point-max))))
3198 (chars (- (point-max) (point)))
3199 (lines (count-lines (point) (point-max)))
3200 (default-mime-charset charset)
3202 (narrow-to-region (point-min) header-end)
3203 (setq xref (std11-fetch-field "xref"))
3205 (make-full-mail-header
3207 (std11-fetch-field "subject")
3208 (std11-fetch-field "from")
3209 (std11-fetch-field "date")
3210 (std11-fetch-field "message-id")
3211 (std11-fetch-field "references")
3214 (when xref (concat "Xref: " xref)))
3217 (defun gnus-article-prepare (article &optional all-headers header)
3218 "Prepare ARTICLE in article mode buffer.
3219 ARTICLE should either be an article number or a Message-ID.
3220 If ARTICLE is an id, HEADER should be the article headers.
3221 If ALL-HEADERS is non-nil, no headers are hidden."
3223 ;; Make sure we start in a summary buffer.
3224 (unless (eq major-mode 'gnus-summary-mode)
3225 (set-buffer gnus-summary-buffer))
3226 (setq gnus-summary-buffer (current-buffer))
3227 (let* ((gnus-article (if header (mail-header-number header) article))
3228 (summary-buffer (current-buffer))
3229 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3230 (group gnus-newsgroup-name)
3233 (gnus-article-setup-buffer)
3234 (set-buffer gnus-original-article-buffer)
3235 ;; Deactivate active regions.
3236 (when (and (boundp 'transient-mark-mode)
3237 transient-mark-mode)
3238 (setq mark-active nil))
3239 (if (not (setq result (let ((buffer-read-only nil))
3240 (gnus-request-article-this-buffer
3242 ;; There is no such article.
3244 (when (and (numberp article)
3245 (not (memq article gnus-newsgroup-sparse)))
3246 (setq gnus-article-current
3247 (cons gnus-newsgroup-name article))
3248 (set-buffer gnus-summary-buffer)
3249 (setq gnus-current-article article)
3250 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3252 (gnus-summary-set-agent-mark article)
3253 (message "Message marked for downloading"))
3254 (gnus-summary-mark-article article gnus-canceled-mark)
3255 (unless (memq article gnus-newsgroup-sparse)
3256 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3257 (if (or (eq result 'pseudo)
3258 (eq result 'nneething))
3261 (set-buffer summary-buffer)
3262 (push article gnus-newsgroup-history)
3263 (setq gnus-last-article gnus-current-article
3264 gnus-current-article 0
3265 gnus-current-headers nil
3266 gnus-article-current nil)
3267 (if (eq result 'nneething)
3268 (gnus-configure-windows 'summary)
3269 (gnus-configure-windows 'article))
3270 (gnus-set-global-variables))
3271 (let ((gnus-article-mime-handle-alist-1
3272 gnus-article-mime-handle-alist))
3273 (gnus-set-mode-line 'article)))
3274 ;; The result from the `request' was an actual article -
3275 ;; or at least some text that is now displayed in the
3277 (when (and (numberp article)
3278 (not (eq article gnus-current-article)))
3279 ;; Seems like a new article has been selected.
3280 ;; `gnus-current-article' must be an article number.
3282 (set-buffer summary-buffer)
3283 (push article gnus-newsgroup-history)
3284 (setq gnus-last-article gnus-current-article
3285 gnus-current-article article
3286 gnus-current-headers
3287 (gnus-summary-article-header gnus-current-article)
3288 gnus-article-current
3289 (cons gnus-newsgroup-name gnus-current-article))
3290 (unless (vectorp gnus-current-headers)
3291 (setq gnus-current-headers nil))
3292 (gnus-summary-goto-subject gnus-current-article)
3293 (when (gnus-summary-show-thread)
3294 ;; If the summary buffer really was folded, the
3295 ;; previous goto may not actually have gone to
3296 ;; the right article, but the thread root instead.
3298 (gnus-summary-goto-subject gnus-current-article))
3299 (gnus-run-hooks 'gnus-mark-article-hook)
3300 (gnus-set-mode-line 'summary)
3301 (when (gnus-visual-p 'article-highlight 'highlight)
3302 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3303 ;; Set the global newsgroup variables here.
3304 (gnus-set-global-variables)
3305 (setq gnus-have-all-headers
3306 (or all-headers gnus-show-all-headers))))
3308 (gnus-configure-windows 'article))
3309 (when (or (numberp article)
3311 (gnus-article-prepare-display)
3313 (goto-char (point-min))
3314 (setq gnus-page-broken
3315 (when gnus-break-pages
3316 (gnus-narrow-to-page)
3318 (let ((gnus-article-mime-handle-alist-1
3319 gnus-article-mime-handle-alist))
3320 (gnus-set-mode-line 'article))
3322 (set-window-point (get-buffer-window (current-buffer)) (point))
3323 (gnus-configure-windows 'article)
3326 (defun gnus-article-prepare-mime-display (&optional number)
3327 (goto-char (point-min))
3328 (when (re-search-forward "^[^\t ]+:" nil t)
3329 (goto-char (match-beginning 0)))
3330 (let ((entity (if (eq 1 (point-min))
3331 (get-text-property 1 'mime-view-entity)
3332 (get-text-property (point) 'mime-view-entity)))
3333 last-entity child-entity next type)
3334 (setq child-entity (mime-entity-children entity))
3336 (setq last-entity (nth (1- (length child-entity))
3338 (setq last-entity entity))
3340 (narrow-to-region (point)
3341 (if (search-forward "\n\n" nil t)
3344 (gnus-treat-article 'head)
3345 (put-text-property (point-min) (point-max) 'article-treated-header t)
3346 (goto-char (point-max)))
3347 (while (and (not (eobp)) entity)
3348 (setq next (set-marker
3350 (next-single-property-change (point) 'mime-view-entity
3352 (let ((types (mime-entity-content-type entity)))
3353 (while (eq 'multipart (mime-content-type-primary-type types))
3354 (setq entity (car (mime-entity-children entity))
3355 types (mime-entity-content-type entity)))
3357 (setq type (format "%s/%s"
3358 (mime-content-type-primary-type types)
3359 (mime-content-type-subtype types)))))
3360 (if (string-equal type "message/rfc822")
3363 (let ((children (mime-entity-children entity))
3366 (setq last-children (nth (1- (length children)) children))
3369 (not (eq last-children
3370 (get-text-property next 'mime-view-entity)))
3372 (next-single-property-change next
3374 nil (point-max)))))))
3375 (setq next (next-single-property-change next 'mime-view-entity
3378 (narrow-to-region (point) next)
3379 (gnus-article-prepare-mime-display)
3380 (goto-char (point-max)))
3381 (setq entity (get-text-property (point) 'mime-view-entity)))
3383 (narrow-to-region (point) next)
3384 ;; Kludge. We have to count true number, but for now,
3385 ;; part number is here only to achieve `last'.
3386 (gnus-treat-article nil 1
3387 (if (eq entity last-entity)
3390 (goto-char (point-max)))
3391 (setq entity (get-text-property next 'mime-view-entity))))))
3394 (defun gnus-article-prepare-display ()
3395 "Make the current buffer look like a nice article."
3396 (setq gnus-article-wash-types nil)
3397 (gnus-run-hooks 'gnus-tmp-internal-hook)
3398 (gnus-run-hooks 'gnus-article-prepare-hook)
3400 (let (mime-display-header-hook mime-display-text/plain-hook)
3401 (funcall (if gnus-show-mime
3403 (setq mime-message-structure gnus-current-headers)
3404 (mime-buffer-entity-set-buffer-internal
3405 mime-message-structure
3406 gnus-original-article-buffer)
3407 (mime-entity-set-representation-type-internal
3408 mime-message-structure 'mime-buffer-entity)
3409 (luna-send mime-message-structure
3410 'initialize-instance
3411 mime-message-structure)
3412 gnus-article-display-method-for-mime)
3413 gnus-article-display-method-for-traditional)))
3414 ;; Associate this article with the current summary buffer.
3415 (setq gnus-article-current-summary gnus-summary-buffer)
3416 ;; Call the treatment functions.
3417 (let ((inhibit-read-only t)
3422 (gnus-article-prepare-mime-display)
3423 (narrow-to-region (goto-char (point-min))
3424 (if (search-forward "\n\n" nil t)
3427 (gnus-treat-article 'head)
3428 (put-text-property (point-min) (point-max) 'article-treated-header t)
3429 (goto-char (point-max))
3431 (narrow-to-region (point) (point-max))
3432 (gnus-treat-article nil))
3433 (put-text-property (point-min) (point-max) 'read-only nil)))
3434 ;; Perform the article display hooks. Incidentally, this hook is
3435 ;; an obsolete variable by now.
3436 (gnus-run-hooks 'gnus-article-display-hook))
3438 (defun gnus-article-decode-article-as-default-mime-charset ()
3439 "Decode an article as `default-mime-charset'. It won't work if the
3440 value of the variable `gnus-show-mime' is non-nil."
3441 (unless gnus-show-mime
3442 (decode-mime-charset-region (point-min) (point-max)
3443 (with-current-buffer gnus-summary-buffer
3444 default-mime-charset))))
3447 ;;; Gnus MIME viewing functions
3450 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3451 "The following specs can be used:
3453 %T MIME type, along with additional info
3454 %n The `name' parameter
3455 %d The description, if any
3456 %l The length of the encoded part
3457 %p The part identifier number
3458 %e Dots if the part isn't displayed")
3460 (defvar gnus-mime-button-line-format-alist
3461 '((?t gnus-tmp-type ?s)
3462 (?T gnus-tmp-type-long ?s)
3463 (?n gnus-tmp-name ?s)
3464 (?d gnus-tmp-description ?s)
3466 (?l gnus-tmp-length ?d)
3467 (?e gnus-tmp-dots ?s)))
3469 (defvar gnus-mime-button-commands
3470 '((gnus-article-press-button "\r" "Toggle Display")
3471 (gnus-mime-view-part "v" "View Interactively...")
3472 (gnus-mime-view-part-as-type "t" "View As Type...")
3473 (gnus-mime-view-part-as-charset "C" "View As charset...")
3474 (gnus-mime-save-part "o" "Save...")
3475 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3476 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3477 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3478 (gnus-mime-internalize-part "E" "View Internally")
3479 (gnus-mime-externalize-part "e" "View Externally")
3480 (gnus-mime-pipe-part "|" "Pipe To Command...")
3481 (gnus-mime-action-on-part "." "Take action on the part")))
3483 (defun gnus-article-mime-part-status ()
3484 (with-current-buffer gnus-article-buffer
3485 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3486 (if (and entity (mime-entity-children entity))
3487 (format " (%d parts)" (length (mime-entity-children entity)))
3490 (defvar gnus-mime-button-map
3491 (let ((map (make-sparse-keymap)))
3492 (unless (>= (string-to-number emacs-version) 21)
3493 ;; XEmacs doesn't care.
3494 (set-keymap-parent map gnus-article-mode-map))
3495 (define-key map gnus-mouse-2 'gnus-article-push-button)
3496 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3497 (dolist (c gnus-mime-button-commands)
3498 (define-key map (cadr c) (car c)))
3501 (defun gnus-mime-button-menu (event)
3502 "Construct a context-sensitive menu of MIME commands."
3504 (save-window-excursion
3505 (let ((pos (event-start event)))
3506 (select-window (posn-window pos))
3507 (goto-char (posn-point pos))
3508 (gnus-article-check-buffer)
3509 (let ((response (x-popup-menu
3511 ("" ,@(mapcar (lambda (c)
3512 (cons (caddr c) (car c)))
3513 gnus-mime-button-commands))))))
3515 (call-interactively response))))))
3517 (defun gnus-mime-view-all-parts (&optional handles)
3518 "View all the MIME parts."
3520 (save-current-buffer
3521 (set-buffer gnus-article-buffer)
3522 (let ((handles (or handles gnus-article-mime-handles))
3523 (mail-parse-charset gnus-newsgroup-charset)
3524 (mail-parse-ignored-charsets
3525 (with-current-buffer gnus-summary-buffer
3526 gnus-newsgroup-ignored-charsets)))
3528 (mm-remove-parts handles)
3529 (goto-char (point-min))
3530 (or (search-forward "\n\n") (goto-char (point-max)))
3531 (let (buffer-read-only)
3532 (delete-region (point) (point-max)))
3533 (mm-display-parts handles)))))
3535 (defun gnus-mime-save-part-and-strip ()
3536 "Save the MIME part under point then replace it with an external body."
3538 (gnus-article-check-buffer)
3539 (let* ((data (get-text-property (point) 'gnus-data))
3540 (file (and data (mm-save-part data)))
3543 (with-current-buffer (mm-handle-buffer data)
3545 (insert "Content-Type: " (mm-handle-media-type data))
3546 (mml-insert-parameter-string (cdr (mm-handle-type data))
3549 (insert "Content-ID: " (message-make-message-id) "\n")
3550 (insert "Content-Transfer-Encoding: binary\n")
3553 (cdr (mm-make-handle nil
3554 `("message/external-body"
3555 (access-type . "LOCAL-FILE")
3557 (set-buffer gnus-summary-buffer)
3558 (gnus-article-edit-article
3561 (let ((mail-parse-charset (or gnus-article-charset
3562 ',gnus-newsgroup-charset))
3563 (mail-parse-ignored-charsets
3564 (or gnus-article-ignored-charsets
3565 ',gnus-newsgroup-ignored-charsets))
3566 (mbl mml-buffer-list))
3567 (setq mml-buffer-list nil)
3568 (insert-buffer gnus-original-article-buffer)
3569 (mime-to-mml gnus-article-mime-handles)
3570 (setq gnus-article-mime-handles nil)
3571 (make-local-hook 'kill-buffer-hook)
3572 (let ((mbl1 mml-buffer-list))
3573 (setq mml-buffer-list mbl)
3574 (set (make-local-variable 'mml-buffer-list) mbl1))
3575 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3576 `(lambda (no-highlight)
3577 (let ((mail-parse-charset (or gnus-article-charset
3578 ',gnus-newsgroup-charset))
3579 (message-options message-options)
3580 (message-options-set-recipient)
3581 (mail-parse-ignored-charsets
3582 (or gnus-article-ignored-charsets
3583 ',gnus-newsgroup-ignored-charsets)))
3585 (mml-destroy-buffers)
3586 (remove-hook 'kill-buffer-hook
3587 'mml-destroy-buffers t)
3588 (kill-local-variable 'mml-buffer-list))
3589 (gnus-summary-edit-article-done
3590 ,(or (mail-header-references gnus-current-headers) "")
3591 ,(gnus-group-read-only-p)
3592 ,gnus-summary-buffer no-highlight))))))
3594 (defun gnus-mime-save-part ()
3595 "Save the MIME part under point."
3597 (gnus-article-check-buffer)
3598 (let ((data (get-text-property (point) 'gnus-data)))
3600 (mm-save-part data))))
3602 (defun gnus-mime-pipe-part ()
3603 "Pipe the MIME part under point to a process."
3605 (gnus-article-check-buffer)
3606 (let ((data (get-text-property (point) 'gnus-data)))
3608 (mm-pipe-part data))))
3610 (defun gnus-mime-view-part ()
3611 "Interactively choose a viewing method for the MIME part under point."
3613 (gnus-article-check-buffer)
3614 (let ((data (get-text-property (point) 'gnus-data)))
3616 (mm-interactively-view-part data))))
3618 (defun gnus-mime-view-part-as-type-internal ()
3619 (gnus-article-check-buffer)
3620 (let* ((name (mail-content-type-get
3621 (mm-handle-type (get-text-property (point) 'gnus-data))
3623 (def-type (and name (mm-default-file-encoding name))))
3624 (and def-type (cons def-type 0))))
3626 (defun gnus-mime-view-part-as-type (mime-type)
3627 "Choose a MIME media type, and view the part as such."
3629 (list (completing-read
3630 "View as MIME type: "
3631 (mapcar #'list (mailcap-mime-types))
3633 (gnus-mime-view-part-as-type-internal))))
3634 (gnus-article-check-buffer)
3635 (let ((handle (get-text-property (point) 'gnus-data)))
3637 (gnus-mm-display-part
3638 (mm-make-handle (mm-handle-buffer handle)
3639 (cons mime-type (cdr (mm-handle-type handle)))
3640 (mm-handle-encoding handle)
3641 (mm-handle-undisplayer handle)
3642 (mm-handle-disposition handle)
3643 (mm-handle-description handle)
3644 (mm-handle-cache handle)
3645 (mm-handle-id handle))))))
3647 (defun gnus-mime-copy-part (&optional handle)
3648 "Put the the MIME part under point into a new buffer."
3650 (gnus-article-check-buffer)
3651 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3652 (contents (and handle (mm-get-part handle)))
3654 (file-name-nondirectory
3656 (mail-content-type-get (mm-handle-type handle) 'name)
3657 (mail-content-type-get (mm-handle-type handle)
3660 (buffer (and base (generate-new-buffer base))))
3662 (switch-to-buffer buffer)
3664 ;; We do it this way to make `normal-mode' set the appropriate mode.
3667 (setq buffer-file-name (expand-file-name base))
3669 (setq buffer-file-name nil))
3670 (goto-char (point-min)))))
3672 (defun gnus-mime-inline-part (&optional handle arg)
3673 "Insert the MIME part under point into the current buffer."
3674 (interactive (list nil current-prefix-arg))
3675 (gnus-article-check-buffer)
3676 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3681 (if (and (not arg) (mm-handle-undisplayer handle))
3682 (mm-remove-part handle)
3683 (setq contents (mm-get-part handle))
3686 (setq charset (or (mail-content-type-get
3687 (mm-handle-type handle) 'charset)
3688 gnus-newsgroup-charset)))
3690 (if (mm-handle-undisplayer handle)
3691 (mm-remove-part handle))
3694 gnus-summary-show-article-charset-alist))
3695 (read-coding-system "Charset: ")))))
3697 (mm-insert-inline handle
3699 (setq charset (mm-charset-to-coding-system
3701 (not (eq charset 'ascii)))
3702 (mm-decode-coding-string contents charset)
3706 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3707 "Insert the MIME part under point into the current buffer."
3708 (interactive (list nil current-prefix-arg))
3709 (gnus-article-check-buffer)
3710 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3715 (if (mm-handle-undisplayer handle)
3716 (mm-remove-part handle))
3717 (let ((gnus-newsgroup-charset
3719 gnus-summary-show-article-charset-alist))
3720 (read-coding-system "Charset: ")))
3721 (gnus-newsgroup-ignored-charsets 'gnus-all))
3722 (gnus-article-press-button)))))
3724 (defun gnus-mime-externalize-part (&optional handle)
3725 "View the MIME part under point with an external viewer."
3727 (gnus-article-check-buffer)
3728 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3729 (mm-user-display-methods nil)
3730 (mm-inlined-types nil)
3731 (mail-parse-charset gnus-newsgroup-charset)
3732 (mail-parse-ignored-charsets
3733 (save-excursion (set-buffer gnus-summary-buffer)
3734 gnus-newsgroup-ignored-charsets)))
3736 (if (mm-handle-undisplayer handle)
3737 (mm-remove-part handle)
3738 (mm-display-part handle)))))
3740 (defun gnus-mime-internalize-part (&optional handle)
3741 "View the MIME part under point with an internal viewer.
3742 In no internal viewer is available, use an external viewer."
3744 (gnus-article-check-buffer)
3745 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3746 (mm-inlined-types '(".*"))
3747 (mm-inline-large-images t)
3748 (mail-parse-charset gnus-newsgroup-charset)
3749 (mail-parse-ignored-charsets
3750 (save-excursion (set-buffer gnus-summary-buffer)
3751 gnus-newsgroup-ignored-charsets)))
3753 (if (mm-handle-undisplayer handle)
3754 (mm-remove-part handle)
3755 (mm-display-part handle)))))
3757 (defun gnus-mime-action-on-part (&optional action)
3758 "Do something with the MIME attachment at \(point\)."
3760 (list (completing-read "Action: " gnus-mime-action-alist)))
3761 (gnus-article-check-buffer)
3762 (let ((action-pair (assoc action gnus-mime-action-alist)))
3764 (funcall (cdr action-pair)))))
3766 (defun gnus-article-part-wrapper (n function)
3767 (save-current-buffer
3768 (set-buffer gnus-article-buffer)
3769 (when (> n (length gnus-article-mime-handle-alist))
3770 (error "No such part"))
3771 (gnus-article-goto-part n)
3772 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3773 (funcall function handle))))
3775 (defun gnus-article-pipe-part (n)
3776 "Pipe MIME part N, which is the numerical prefix."
3778 (gnus-article-part-wrapper n 'mm-pipe-part))
3780 (defun gnus-article-save-part (n)
3781 "Save MIME part N, which is the numerical prefix."
3783 (gnus-article-part-wrapper n 'mm-save-part))
3785 (defun gnus-article-interactively-view-part (n)
3786 "View MIME part N interactively, which is the numerical prefix."
3788 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3790 (defun gnus-article-copy-part (n)
3791 "Copy MIME part N, which is the numerical prefix."
3793 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3795 (defun gnus-article-view-part-as-charset (n)
3796 "Copy MIME part N, which is the numerical prefix."
3798 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3800 (defun gnus-article-externalize-part (n)
3801 "View MIME part N externally, which is the numerical prefix."
3803 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3805 (defun gnus-article-inline-part (n)
3806 "Inline MIME part N, which is the numerical prefix."
3808 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3810 (defun gnus-article-mime-match-handle-first (condition)
3812 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3813 (while (setq ihandle (pop alist))
3815 ((functionp condition)
3816 (funcall condition (cdr ihandle)))
3817 ((eq condition 'undisplayed)
3818 (not (or (mm-handle-undisplayer (cdr ihandle))
3819 (equal (mm-handle-media-type (cdr ihandle))
3820 "multipart/alternative"))))
3821 ((eq condition 'undisplayed-alternative)
3822 (not (mm-handle-undisplayer (cdr ihandle))))
3824 (gnus-article-goto-part (car ihandle))
3825 (or (not n) (< (car ihandle) n)))
3826 (setq n (car ihandle))))
3830 (defun gnus-article-view-part (&optional n)
3831 "View MIME part N, which is the numerical prefix."
3833 (save-current-buffer
3834 (set-buffer gnus-article-buffer)
3835 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3836 gnus-article-mime-match-handle-function)))
3837 (when (> n (length gnus-article-mime-handle-alist))
3838 (error "No such part"))
3839 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3840 (when (gnus-article-goto-part n)
3841 (if (equal (car handle) "multipart/alternative")
3842 (gnus-article-press-button)
3843 (when (eq (gnus-mm-display-part handle) 'internal)
3844 (gnus-set-window-start)))))))
3846 (defsubst gnus-article-mime-total-parts ()
3847 (if (bufferp (car gnus-article-mime-handles))
3849 (1- (length gnus-article-mime-handles))))
3851 (defun gnus-mm-display-part (handle)
3852 "Display HANDLE and fix MIME button."
3853 (let ((id (get-text-property (point) 'gnus-part))
3858 (let ((window (selected-window))
3859 (mail-parse-charset gnus-newsgroup-charset)
3860 (mail-parse-ignored-charsets
3861 (save-excursion (set-buffer gnus-summary-buffer)
3862 gnus-newsgroup-ignored-charsets)))
3865 (let ((win (get-buffer-window (current-buffer) t))
3868 (select-window win))
3871 (if (mm-handle-displayed-p handle)
3872 ;; This will remove the part.
3873 (mm-display-part handle)
3875 (narrow-to-region (point) (1+ (point)))
3876 (mm-display-part handle)
3877 ;; We narrow to the part itself and
3878 ;; then call the treatment functions.
3879 (goto-char (point-min))
3881 (narrow-to-region (point) (point-max))
3884 (gnus-article-mime-total-parts)
3885 (mm-handle-media-type handle)))))
3886 (select-window window))))
3888 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3889 (gnus-insert-mime-button
3890 handle id (list (mm-handle-displayed-p handle)))
3891 (goto-char point))))
3893 (defun gnus-article-goto-part (n)
3894 "Go to MIME part N."
3895 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3897 (goto-char point))))
3899 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3900 (let ((gnus-tmp-name
3901 (or (mail-content-type-get (mm-handle-type handle)
3903 (mail-content-type-get (mm-handle-disposition handle)
3905 (mail-content-type-get (mm-handle-type handle)
3908 (gnus-tmp-type (mm-handle-media-type handle))
3909 (gnus-tmp-description
3910 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3913 (if (if displayed (car displayed)
3914 (mm-handle-displayed-p handle))
3916 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3918 gnus-tmp-type-long b e)
3919 (when (string-match ".*/" gnus-tmp-name)
3920 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3921 (setq gnus-tmp-type-long (concat gnus-tmp-type
3922 (and (not (equal gnus-tmp-name ""))
3923 (concat "; " gnus-tmp-name))))
3924 (or (equal gnus-tmp-description "")
3925 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3930 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3931 `(keymap ,gnus-mime-button-map
3932 ,@(if (>= (string-to-number emacs-version) 21)
3934 (list 'local-map gnus-mime-button-map))
3935 gnus-callback gnus-mm-display-part
3936 gnus-part ,gnus-tmp-id
3937 article-type annotation
3940 (widget-convert-button
3943 :action 'gnus-widget-press-button
3944 :button-keymap gnus-mime-button-map
3946 (lambda (widget/window &optional overlay pos)
3947 ;; Needed to properly clear the message due to a bug in
3948 ;; wid-edit (XEmacs only).
3949 (if (boundp 'help-echo-owns-message)
3950 (setq help-echo-owns-message t))
3952 "%S: %s the MIME part; %S: more options"
3953 (aref gnus-mouse-2 0)
3954 ;; XEmacs will get a single widget arg; Emacs 21 will get
3955 ;; window, overlay, position.
3956 (if (mm-handle-displayed-p
3958 (with-current-buffer (gnus-overlay-buffer overlay)
3959 (widget-get (widget-at (gnus-overlay-start overlay))
3961 (widget-get widget/window :mime-handle)))
3963 (aref gnus-down-mouse-3 0))))))
3965 (defun gnus-widget-press-button (elems el)
3966 (goto-char (widget-get elems :from))
3967 (gnus-article-press-button))
3969 (defvar gnus-displaying-mime nil)
3971 (defun gnus-display-mime (&optional ihandles)
3972 "Display the MIME parts."
3974 (save-selected-window
3975 (let ((window (get-buffer-window gnus-article-buffer))
3978 (select-window window)
3979 ;; We have to do this since selecting the window
3980 ;; may change the point. So we set the window point.
3981 (set-window-point window point)))
3982 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3983 buffer-read-only handle name type b e display)
3984 (when (and (not ihandles)
3985 (not gnus-displaying-mime))
3986 ;; Top-level call; we clean up.
3987 (when gnus-article-mime-handles
3988 (mm-destroy-parts gnus-article-mime-handles)
3989 (setq gnus-article-mime-handle-alist nil));; A trick.
3990 (setq gnus-article-mime-handles handles)
3991 ;; We allow users to glean info from the handles.
3992 (when gnus-article-mime-part-function
3993 (gnus-mime-part-function handles)))
3995 (or (not (stringp (car handles)))
3998 (when (and (not ihandles)
3999 (not gnus-displaying-mime))
4000 ;; Clean up for mime parts.
4002 (delete-region (point) (point-max)))
4003 (let ((gnus-displaying-mime t))
4004 (gnus-mime-display-part handles)))
4007 (narrow-to-region (point) (point-max))
4008 (gnus-treat-article nil 1 1)
4011 ;; Highlight the headers.
4015 (narrow-to-region (point-min) (point))
4016 (gnus-treat-article 'head))))))))
4018 (defvar gnus-mime-display-multipart-as-mixed nil)
4020 (defun gnus-mime-display-part (handle)
4023 ((not (stringp (car handle)))
4024 (gnus-mime-display-single handle))
4025 ;; User-defined multipart
4026 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4027 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4029 ;; multipart/alternative
4030 ((and (equal (car handle) "multipart/alternative")
4031 (not gnus-mime-display-multipart-as-mixed))
4032 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4033 (push (cons id handle) gnus-article-mime-handle-alist)
4034 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4035 ;; multipart/related
4036 ((and (equal (car handle) "multipart/related")
4037 (not gnus-mime-display-multipart-as-mixed))
4038 ;;;!!!We should find the start part, but we just default
4039 ;;;!!!to the first part.
4040 ;;(gnus-mime-display-part (cadr handle))
4041 ;;;!!! Most multipart/related is an HTML message plus images.
4042 ;;;!!! Unfortunately we are unable to let W3 display those
4043 ;;;!!! included images, so we just display it as a mixed multipart.
4044 (gnus-mime-display-mixed (cdr handle)))
4045 ((equal (car handle) "multipart/signed")
4046 (or (memq 'signed gnus-article-wash-types)
4047 (push 'signed gnus-article-wash-types))
4048 (gnus-mime-display-security handle))
4049 ((equal (car handle) "multipart/encrypted")
4050 (or (memq 'encrypted gnus-article-wash-types)
4051 (push 'encrypted gnus-article-wash-types))
4052 (gnus-mime-display-security handle))
4053 ;; Other multiparts are handled like multipart/mixed.
4055 (gnus-mime-display-mixed (cdr handle)))))
4057 (defun gnus-mime-part-function (handles)
4058 (if (stringp (car handles))
4059 (mapcar 'gnus-mime-part-function (cdr handles))
4060 (funcall gnus-article-mime-part-function handles)))
4062 (defun gnus-mime-display-mixed (handles)
4063 (mapcar 'gnus-mime-display-part handles))
4065 (defun gnus-mime-display-single (handle)
4066 (let ((type (mm-handle-media-type handle))
4067 (ignored gnus-ignored-mime-types)
4074 (when (string-match (pop ignored) type)
4075 (throw 'ignored nil)))
4076 (if (and (setq not-attachment
4077 (and (not (mm-inline-override-p handle))
4078 (or (not (mm-handle-disposition handle))
4079 (equal (car (mm-handle-disposition handle))
4081 (mm-attachment-override-p handle))))
4082 (mm-automatic-display-p handle)
4083 (or (mm-inlined-p handle)
4084 (mm-automatic-external-display-p type)))
4086 (when (equal (mm-handle-media-supertype handle) "text")
4088 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4090 (push (cons id handle) gnus-article-mime-handle-alist)
4091 (when (or (not display)
4092 (not (gnus-unbuttonized-mime-type-p type)))
4093 ;(gnus-article-insert-newline)
4094 (gnus-insert-mime-button
4095 handle id (list (or display (and not-attachment text))))
4096 (gnus-article-insert-newline)
4097 ;(gnus-article-insert-newline)
4098 ;; Remember modify the number of forward lines.
4106 (let ((mail-parse-charset gnus-newsgroup-charset)
4107 (mail-parse-ignored-charsets
4108 (save-excursion (condition-case ()
4109 (set-buffer gnus-summary-buffer)
4111 gnus-newsgroup-ignored-charsets)))
4112 (mm-display-part handle t))
4113 (goto-char (point-max)))
4114 ((and text not-attachment)
4118 (gnus-article-insert-newline)
4119 (mm-insert-inline handle (mm-get-part handle))
4120 (goto-char (point-max))))
4124 (narrow-to-region beg (point))
4127 (gnus-article-mime-total-parts)
4128 (mm-handle-media-type handle)))))))))
4130 (defun gnus-unbuttonized-mime-type-p (type)
4131 "Say whether TYPE is to be unbuttonized."
4132 (unless gnus-inhibit-mime-unbuttonizing
4134 (let ((types gnus-unbuttonized-mime-types))
4136 (when (string-match (pop types) type)
4137 (throw 'found t)))))))
4139 (defun gnus-article-insert-newline ()
4140 "Insert a newline, but mark it as undeletable."
4141 (gnus-put-text-property
4142 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4144 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4145 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4148 handle buffer-read-only from props begend not-pref)
4149 (save-window-excursion
4152 (narrow-to-region (car ibegend)
4155 (goto-char (car ibegend))
4158 (delete-region (point-min) (point-max))
4159 (mm-remove-parts handles))
4160 (setq begend (list (point-marker)))
4162 (unless (setq not-pref (cadr (member preferred ihandles)))
4163 (setq not-pref (car ihandles)))
4166 (not (gnus-unbuttonized-mime-type-p
4167 "multipart/alternative")))
4168 (gnus-add-text-properties
4171 (insert (format "%d. " id))
4175 (unless ,(not ibegend)
4176 (setq gnus-article-mime-handle-alist
4177 ',gnus-article-mime-handle-alist))
4178 (gnus-mime-display-alternative
4179 ',ihandles ',not-pref ',begend ,id))
4180 ,@(if (>= (string-to-number emacs-version) 21)
4181 nil ;; XEmacs doesn't care
4182 (list 'local-map gnus-mime-button-map))
4183 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4184 face ,gnus-article-button-face
4185 keymap ,gnus-mime-button-map
4188 (widget-convert-button 'link from (point)
4189 :action 'gnus-widget-press-button
4190 :button-keymap gnus-widget-button-keymap)
4192 (while (setq handle (pop handles))
4193 (gnus-add-text-properties
4196 (insert (format "(%c) %-18s"
4197 (if (equal handle preferred) ?* ? )
4198 (mm-handle-media-type handle)))
4202 (unless ,(not ibegend)
4203 (setq gnus-article-mime-handle-alist
4204 ',gnus-article-mime-handle-alist))
4205 (gnus-mime-display-alternative
4206 ',ihandles ',handle ',begend ,id))
4207 ,@(if (>= (string-to-number emacs-version) 21)
4208 nil ;; XEmacs doesn't care
4209 (list 'local-map gnus-mime-button-map))
4210 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4211 face ,gnus-article-button-face
4212 keymap ,gnus-mime-button-map
4215 (widget-convert-button 'link from (point)
4216 :action 'gnus-widget-press-button
4217 :button-keymap gnus-widget-button-keymap)
4221 (if (stringp (car preferred))
4222 (gnus-display-mime preferred)
4223 (let ((mail-parse-charset gnus-newsgroup-charset)
4224 (mail-parse-ignored-charsets
4225 (save-excursion (set-buffer gnus-summary-buffer)
4226 gnus-newsgroup-ignored-charsets)))
4227 (mm-display-part preferred)
4231 (narrow-to-region (car begend) (point-max))
4233 nil (length gnus-article-mime-handle-alist)
4234 (gnus-article-mime-total-parts)
4235 (mm-handle-media-type handle))))))
4236 (goto-char (point-max))
4237 (setcdr begend (point-marker)))))
4239 (goto-char point))))
4241 (defun gnus-article-wash-status ()
4242 "Return a string which display status of article washing."
4244 (set-buffer gnus-article-buffer)
4245 (let ((cite (memq 'cite gnus-article-wash-types))
4246 (headers (memq 'headers gnus-article-wash-types))
4247 (boring (memq 'boring-headers gnus-article-wash-types))
4248 (pgp (memq 'pgp gnus-article-wash-types))
4249 (pem (memq 'pem gnus-article-wash-types))
4250 (signed (memq 'signed gnus-article-wash-types))
4251 (encrypted (memq 'encrypted gnus-article-wash-types))
4252 (signature (memq 'signature gnus-article-wash-types))
4253 (overstrike (memq 'overstrike gnus-article-wash-types))
4254 (emphasis (memq 'emphasis gnus-article-wash-types)))
4255 (format "%c%c%c%c%c%c%c"
4257 (if (or headers boring) ?h ? )
4258 (if (or pgp pem signed encrypted) ?p ? )
4259 (if signature ?s ? )
4260 (if overstrike ?o ? )
4261 (if gnus-show-mime ?m ? )
4262 (if emphasis ?e ? )))))
4264 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4266 (defun gnus-article-maybe-hide-headers ()
4267 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4268 Provided for backwards compatibility."
4269 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4270 (not (save-excursion (set-buffer gnus-summary-buffer)
4271 gnus-have-all-headers)))
4272 (not gnus-inhibit-hiding))
4273 (gnus-article-hide-headers)))
4277 (defun gnus-output-to-file (file-name)
4278 "Append the current article to a file named FILE-NAME."
4279 (let ((artbuf (current-buffer)))
4281 (insert-buffer-substring artbuf)
4282 ;; Append newline at end of the buffer as separator, and then
4284 (goto-char (point-max))
4286 (write-region-as-binary (point-min) (point-max) file-name 'append)
4289 (defun gnus-narrow-to-page (&optional arg)
4290 "Narrow the article buffer to a page.
4291 If given a numerical ARG, move forward ARG pages."
4293 (setq arg (if arg (prefix-numeric-value arg) 0))
4295 (set-buffer gnus-article-buffer)
4296 (goto-char (point-min))
4298 ;; Remove any old next/prev buttons.
4299 (when (gnus-visual-p 'page-marker)
4300 (let ((buffer-read-only nil))
4301 (gnus-remove-text-with-property 'gnus-prev)
4302 (gnus-remove-text-with-property 'gnus-next)))
4305 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4307 (re-search-forward page-delimiter nil 'move arg)))
4308 (goto-char (match-end 0)))
4311 (if (re-search-forward page-delimiter nil 'move)
4314 (when (and (gnus-visual-p 'page-marker)
4315 (not (= (point-min) 1)))
4317 (goto-char (point-min))
4318 (gnus-insert-prev-page-button)))
4319 (when (and (gnus-visual-p 'page-marker)
4320 (< (+ (point-max) 2) (buffer-size)))
4322 (goto-char (point-max))
4323 (gnus-insert-next-page-button)))))
4325 ;; Article mode commands
4327 (defun gnus-article-goto-next-page ()
4328 "Show the next page of the article."
4330 (when (gnus-article-next-page)
4331 (goto-char (point-min))
4332 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4334 (defun gnus-article-goto-prev-page ()
4335 "Show the next page of the article."
4337 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4338 (gnus-article-prev-page nil)))
4340 (defun gnus-article-next-page (&optional lines)
4341 "Show the next page of the current article.
4342 If end of article, return non-nil. Otherwise return nil.
4343 Argument LINES specifies lines to be scrolled up."
4345 (let ((start (window-start))
4346 end-of-buffer end-of-page)
4348 (move-to-window-line -1)
4349 (if (<= (point) start)
4352 (setq start (point)))
4355 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4356 (and (pos-visible-in-window-p)
4357 (setq end-of-buffer t)))
4359 (setq end-of-page t)))
4361 (move-to-window-line lines)
4362 (unless (search-backward "\n\n" nil t)
4363 (setq start (point)))))
4364 (cond (end-of-buffer t)
4366 (gnus-narrow-to-page 1)
4370 (set-window-start (selected-window) start)
4371 (let (window-pixel-scroll-increment)
4375 (defun gnus-article-prev-page (&optional lines)
4376 "Show previous page of current article.
4377 Argument LINES specifies lines to be scrolled down."
4379 (let (beginning-of-buffer beginning-of-page)
4381 (move-to-window-line 0)
4382 (cond ((eq 1 (point))
4383 (setq beginning-of-buffer t))
4385 (setq beginning-of-page t))))
4386 (cond (beginning-of-buffer)
4388 (gnus-narrow-to-page -1))
4391 (let (window-pixel-scroll-increment)
4392 (scroll-down lines))
4393 (beginning-of-buffer
4394 (goto-char (point-min))))))))
4396 (defun gnus-article-refer-article ()
4397 "Read article specified by message-id around point."
4399 (let ((point (point)))
4400 (search-forward ">" nil t) ;Move point to end of "<....>".
4401 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4402 (let ((message-id (match-string 1)))
4404 (set-buffer gnus-summary-buffer)
4405 (gnus-summary-refer-article message-id))
4407 (error "No references around point"))))
4409 (defun gnus-article-show-summary ()
4410 "Reconfigure windows to show summary buffer."
4412 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4413 (error "There is no summary buffer for this article buffer")
4414 (gnus-article-set-globals)
4415 (gnus-configure-windows 'article)
4416 (gnus-summary-goto-subject gnus-current-article)
4417 (gnus-summary-position-point)))
4419 (defun gnus-article-describe-briefly ()
4420 "Describe article mode commands briefly."
4422 (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")))
4424 (defun gnus-article-summary-command ()
4425 "Execute the last keystroke in the summary buffer."
4427 (let ((obuf (current-buffer))
4428 (owin (current-window-configuration))
4430 (switch-to-buffer gnus-article-current-summary 'norecord)
4431 (setq func (lookup-key (current-local-map) (this-command-keys)))
4432 (call-interactively func)
4434 (set-window-configuration owin)
4435 (set-window-point (get-buffer-window (current-buffer)) (point))))
4437 (defun gnus-article-summary-command-nosave ()
4438 "Execute the last keystroke in the summary buffer."
4441 (pop-to-buffer gnus-article-current-summary 'norecord)
4442 (setq func (lookup-key (current-local-map) (this-command-keys)))
4443 (call-interactively func)))
4445 (defun gnus-article-check-buffer ()
4446 "Beep if not in an article buffer."
4447 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4448 (error "Command invoked outside of a Gnus article buffer")))
4450 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4451 "Read a summary buffer key sequence and execute it from the article buffer."
4453 (gnus-article-check-buffer)
4455 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4456 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4457 "=" "^" "\M-^" "|"))
4463 '("n" "Gn" "p" "Gp"))
4466 (set-buffer gnus-article-current-summary)
4467 (let (gnus-pick-mode)
4468 (push (or key last-command-event) unread-command-events)
4469 (setq keys (static-if (featurep 'xemacs)
4470 (events-to-keys (read-key-sequence nil))
4471 (read-key-sequence nil)))))
4474 (if (or (member keys nosaves)
4475 (member keys nosave-but-article)
4476 (member keys nosave-in-article))
4478 (save-window-excursion
4479 (pop-to-buffer gnus-article-current-summary 'norecord)
4480 ;; We disable the pick minor mode commands.
4481 (let (gnus-pick-mode)
4482 (setq func (lookup-key (current-local-map) keys))))
4486 (unless (member keys nosave-in-article)
4487 (set-buffer gnus-article-current-summary))
4488 (call-interactively func)
4489 (setq new-sum-point (point)))
4490 (when (member keys nosave-but-article)
4491 (pop-to-buffer gnus-article-buffer 'norecord)))
4492 ;; These commands should restore window configuration.
4493 (let ((obuf (current-buffer))
4494 (owin (current-window-configuration))
4496 (summary gnus-article-current-summary)
4497 func in-buffer selected)
4498 (if not-restore-window
4499 (pop-to-buffer summary 'norecord)
4500 (switch-to-buffer summary 'norecord))
4501 (setq in-buffer (current-buffer))
4502 ;; We disable the pick minor mode commands.
4503 (if (and (setq func (let (gnus-pick-mode)
4504 (lookup-key (current-local-map) keys)))
4507 (call-interactively func)
4508 (setq new-sum-point (point))
4509 (when (eq in-buffer (current-buffer))
4510 (setq selected (gnus-summary-select-article))
4512 (unless not-restore-window
4513 (set-window-configuration owin))
4514 (when (eq selected 'old)
4516 (set-window-start (get-buffer-window (current-buffer))
4518 (set-window-point (get-buffer-window (current-buffer))
4520 (let ((win (get-buffer-window gnus-article-current-summary)))
4522 (set-window-point win new-sum-point)))) )
4523 (switch-to-buffer gnus-article-buffer)
4526 (defun gnus-article-describe-key (key)
4527 "Display documentation of the function invoked by KEY. KEY is a string."
4528 (interactive "kDescribe key: ")
4529 (gnus-article-check-buffer)
4530 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4532 (set-buffer gnus-article-current-summary)
4533 (let (gnus-pick-mode)
4534 (push (elt key 0) unread-command-events)
4535 (setq key (if (featurep 'xemacs)
4536 (events-to-keys (read-key-sequence "Describe key: "))
4537 (read-key-sequence "Describe key: "))))
4539 (describe-key key)))
4541 (defun gnus-article-describe-key-briefly (key &optional insert)
4542 "Display documentation of the function invoked by KEY. KEY is a string."
4543 (interactive "kDescribe key: \nP")
4544 (gnus-article-check-buffer)
4545 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4547 (set-buffer gnus-article-current-summary)
4548 (let (gnus-pick-mode)
4549 (push (elt key 0) unread-command-events)
4550 (setq key (if (featurep 'xemacs)
4551 (events-to-keys (read-key-sequence "Describe key: "))
4552 (read-key-sequence "Describe key: "))))
4553 (describe-key-briefly key insert))
4554 (describe-key-briefly key insert)))
4556 (defun gnus-article-hide (&optional arg force)
4557 "Hide all the gruft in the current article.
4558 This means that PGP stuff, signatures, cited text and (some)
4559 headers will be hidden.
4560 If given a prefix, show the hidden text instead."
4561 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4562 (gnus-article-hide-headers arg)
4563 (gnus-article-hide-list-identifiers arg)
4564 (gnus-article-hide-pgp arg)
4565 (gnus-article-hide-citation-maybe arg force)
4566 (gnus-article-hide-signature arg))
4568 (defun gnus-article-maybe-highlight ()
4569 "Do some article highlighting if article highlighting is requested."
4570 (when (gnus-visual-p 'article-highlight 'highlight)
4571 (gnus-article-highlight-some)))
4573 (defun gnus-check-group-server ()
4574 ;; Make sure the connection to the server is alive.
4575 (unless (gnus-server-opened
4576 (gnus-find-method-for-group gnus-newsgroup-name))
4577 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4578 (gnus-request-group gnus-newsgroup-name t)))
4580 (defun gnus-request-article-this-buffer (article group)
4581 "Get an article and insert it into this buffer."
4582 (let (do-update-line sparse-header)
4586 (gnus-kill-all-overlays)
4587 (setq group (or group gnus-newsgroup-name))
4589 ;; Using `gnus-request-article' directly will insert the article into
4590 ;; `nntp-server-buffer' - so we'll save some time by not having to
4591 ;; copy it from the server buffer into the article buffer.
4593 ;; We only request an article by message-id when we do not have the
4594 ;; headers for it, so we'll have to get those.
4595 (when (stringp article)
4596 (gnus-read-header article))
4598 ;; If the article number is negative, that means that this article
4599 ;; doesn't belong in this newsgroup (possibly), so we find its
4600 ;; message-id and request it by id instead of number.
4601 (when (and (numberp article)
4603 (get-buffer gnus-summary-buffer)
4604 (gnus-buffer-exists-p gnus-summary-buffer))
4606 (set-buffer gnus-summary-buffer)
4607 (let ((header (gnus-summary-article-header article)))
4610 ((memq article gnus-newsgroup-sparse)
4611 ;; This is a sparse gap article.
4612 (setq do-update-line article)
4613 (setq article (mail-header-id header))
4614 (setq sparse-header (gnus-read-header article))
4615 (setq gnus-newsgroup-sparse
4616 (delq article gnus-newsgroup-sparse)))
4618 ;; It's a real article.
4619 (setq article (mail-header-id header)))
4621 ;; It is an extracted pseudo-article.
4622 (setq article 'pseudo)
4623 (gnus-request-pseudo-article header))))
4625 (let ((method (gnus-find-method-for-group
4626 gnus-newsgroup-name)))
4627 (when (and (eq (car method) 'nneething)
4629 (let ((dir (expand-file-name
4630 (mail-header-subject header)
4631 (file-name-as-directory
4632 (or (cadr (assq 'nneething-address method))
4634 (when (file-directory-p dir)
4635 (setq article 'nneething)
4636 (gnus-group-enter-directory dir))))))))
4639 ;; Refuse to select canceled articles.
4640 ((and (numberp article)
4642 (get-buffer gnus-summary-buffer)
4643 (gnus-buffer-exists-p gnus-summary-buffer)
4644 (eq (cdr (save-excursion
4645 (set-buffer gnus-summary-buffer)
4646 (assq article gnus-newsgroup-reads)))
4647 gnus-canceled-mark))
4649 ;; Check the backlog.
4650 ((and gnus-keep-backlog
4651 (gnus-backlog-request-article group article (current-buffer)))
4653 ;; Check asynchronous pre-fetch.
4654 ((gnus-async-request-fetched-article group article (current-buffer))
4655 (gnus-async-prefetch-next group article gnus-summary-buffer)
4656 (when (and (numberp article) gnus-keep-backlog)
4657 (gnus-backlog-enter-article group article (current-buffer)))
4660 ((and gnus-use-cache
4662 (gnus-cache-request-article article group))
4664 ;; Get the article and put into the article buffer.
4665 ((or (stringp article)
4667 (let ((gnus-override-method gnus-override-method)
4668 (methods (and (stringp article)
4669 gnus-refer-article-method))
4671 (buffer-read-only nil))
4672 (if (or (not (listp methods))
4673 (and (symbolp (car methods))
4674 (assq (car methods) nnoo-definition-alist)))
4675 (setq methods (list methods)))
4676 (when (and (null gnus-override-method)
4678 (setq gnus-override-method (pop methods)))
4680 (when (eq gnus-override-method 'current)
4681 (setq gnus-override-method gnus-current-select-method))
4683 (gnus-kill-all-overlays)
4684 (let ((gnus-newsgroup-name group))
4685 (gnus-check-group-server))
4686 (when (gnus-request-article article group (current-buffer))
4687 (when (numberp article)
4688 (gnus-async-prefetch-next group article
4689 gnus-summary-buffer)
4690 (when gnus-keep-backlog
4691 (gnus-backlog-enter-article
4692 group article (current-buffer))))
4693 (setq result 'article))
4696 (setq gnus-override-method (pop methods))
4697 (setq result 'done))))
4698 (and (eq result 'article) 'article)))
4702 ;; Associate this article with the current summary buffer.
4703 (setq gnus-article-current-summary gnus-summary-buffer)
4705 ;; Take the article from the original article buffer
4706 ;; and place it in the buffer it's supposed to be in.
4707 (when (and (get-buffer gnus-article-buffer)
4708 (equal (buffer-name (current-buffer))
4709 (buffer-name (get-buffer gnus-article-buffer))))
4711 (if (get-buffer gnus-original-article-buffer)
4712 (set-buffer gnus-original-article-buffer)
4713 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4714 (set-buffer-multibyte nil)
4715 (buffer-disable-undo)
4716 (setq major-mode 'gnus-original-article-mode)
4717 (setq buffer-read-only t))
4718 (let (buffer-read-only)
4720 (insert-buffer-substring gnus-article-buffer))
4721 (setq gnus-original-article (cons group article)))
4724 (run-hooks 'gnus-article-decode-hook)
4725 ;; Mark article as decoded or not.
4726 (setq gnus-article-decoded-p gnus-article-decode-hook))
4728 ;; Update sparse articles.
4729 (when (and do-update-line
4730 (or (numberp article)
4732 (let ((buf (current-buffer)))
4733 (set-buffer gnus-summary-buffer)
4734 (gnus-summary-update-article do-update-line sparse-header)
4735 (gnus-summary-goto-subject do-update-line nil t)
4736 (set-window-point (get-buffer-window (current-buffer) t)
4738 (set-buffer buf))))))
4744 (defcustom gnus-article-edit-mode-hook nil
4745 "Hook run in article edit mode buffers."
4746 :group 'gnus-article-various
4749 (defcustom gnus-article-edit-article-setup-function
4750 'gnus-article-mime-edit-article-setup
4751 "Function called to setup an editing article buffer."
4752 :group 'gnus-article-various
4755 (defvar gnus-article-edit-done-function nil)
4757 (defvar gnus-article-edit-mode-map nil)
4759 ;; Should we be using derived.el for this?
4760 (unless gnus-article-edit-mode-map
4761 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4762 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4764 (gnus-define-keys gnus-article-edit-mode-map
4765 "\C-c\C-c" gnus-article-edit-done
4766 "\C-c\C-k" gnus-article-edit-exit)
4768 (gnus-define-keys (gnus-article-edit-wash-map
4769 "\C-c\C-w" gnus-article-edit-mode-map)
4770 "f" gnus-article-edit-full-stops))
4772 (defun gnus-article-edit-mode ()
4773 "Major mode for editing articles.
4774 This is an extended text-mode.
4776 \\{gnus-article-edit-mode-map}"
4778 (setq major-mode 'gnus-article-edit-mode)
4779 (setq mode-name "Article Edit")
4780 (use-local-map gnus-article-edit-mode-map)
4781 (make-local-variable 'gnus-article-edit-done-function)
4782 (make-local-variable 'gnus-prev-winconf)
4783 (setq buffer-read-only nil)
4784 (buffer-enable-undo)
4786 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4788 (defun gnus-article-edit (&optional force)
4789 "Edit the current article.
4790 This will have permanent effect only in mail groups.
4791 If FORCE is non-nil, allow editing of articles even in read-only
4794 (when (and (not force)
4795 (gnus-group-read-only-p))
4796 (error "The current newsgroup does not support article editing"))
4797 (gnus-article-date-original)
4798 (gnus-article-edit-article
4800 `(lambda (no-highlight)
4802 (gnus-summary-edit-article-done
4803 ,(or (mail-header-references gnus-current-headers) "")
4804 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4806 (defun gnus-article-edit-article (start-func exit-func)
4807 "Start editing the contents of the current article buffer."
4808 (let ((winconf (current-window-configuration)))
4809 (set-buffer gnus-article-buffer)
4810 (gnus-article-edit-mode)
4811 (funcall start-func)
4812 (gnus-configure-windows 'edit-article)
4813 (setq gnus-article-edit-done-function exit-func)
4814 (setq gnus-prev-winconf winconf)
4815 (when gnus-article-edit-article-setup-function
4816 (funcall gnus-article-edit-article-setup-function))
4817 (gnus-message 6 "C-c C-c to end edits")))
4819 (defun gnus-article-edit-done (&optional arg)
4820 "Update the article edits and exit."
4822 (let ((func gnus-article-edit-done-function)
4823 (buf (current-buffer))
4824 (start (window-start)))
4825 (remove-hook 'gnus-article-mode-hook
4826 'gnus-article-mime-edit-article-unwind)
4827 (gnus-article-edit-exit)
4830 (let ((buffer-read-only nil))
4832 ;; The cache and backlog have to be flushed somewhat.
4833 (when gnus-keep-backlog
4834 (gnus-backlog-remove-article
4835 (car gnus-article-current) (cdr gnus-article-current)))
4836 ;; Flush original article as well.
4838 (when (get-buffer gnus-original-article-buffer)
4839 (set-buffer gnus-original-article-buffer)
4840 (setq gnus-original-article nil)))
4841 (when gnus-use-cache
4842 (gnus-cache-update-article
4843 (car gnus-article-current) (cdr gnus-article-current))))
4845 (set-window-start (get-buffer-window buf) start)
4846 (set-window-point (get-buffer-window buf) (point))))
4848 (defun gnus-article-edit-exit ()
4849 "Exit the article editing without updating."
4851 ;; We remove all text props from the article buffer.
4852 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4853 (curbuf (current-buffer))
4855 (window-start (window-start)))
4858 (let ((winconf gnus-prev-winconf))
4860 (set-window-configuration winconf)
4861 ;; Tippy-toe some to make sure that point remains where it was.
4862 (save-current-buffer
4864 (set-window-start (get-buffer-window (current-buffer)) window-start)
4867 (defun gnus-article-edit-full-stops ()
4868 "Interactively repair spacing at end of sentences."
4871 (goto-char (point-min))
4872 (search-forward-regexp "^$" nil t)
4873 (let ((case-fold-search nil))
4874 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4877 ;;; Article editing with MIME-Edit
4880 (defcustom gnus-article-mime-edit-article-setup-hook nil
4881 "Hook run after setting up a MIME editing article buffer."
4882 :group 'gnus-article-various
4885 (defun gnus-article-mime-edit-article-unwind ()
4886 "Unwind `gnus-article-buffer' if article editing was given up."
4887 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4888 (when mime-edit-mode-flag
4889 (mime-edit-exit 'nomime 'no-error)
4891 (when (featurep 'font-lock)
4892 (setq font-lock-defaults nil)
4893 (font-lock-mode 0)))
4895 (defun gnus-article-mime-edit-article-setup ()
4896 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4897 after replacing with the original article."
4898 (setq gnus-show-mime t)
4899 (setq gnus-article-edit-done-function
4900 `(lambda (&rest args)
4901 (when mime-edit-mode-flag
4904 (goto-char (point-min))
4905 (let (case-fold-search)
4906 (when (re-search-forward
4907 (format "^%s$" (regexp-quote mail-header-separator))
4909 (replace-match "")))
4910 (when (featurep 'font-lock)
4911 (setq font-lock-defaults nil)
4913 (apply ,gnus-article-edit-done-function args)
4914 (set-buffer gnus-original-article-buffer)
4916 (insert-buffer gnus-article-buffer)
4917 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4918 (gnus-article-prepare-display)))
4919 (substitute-key-definition
4920 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4921 gnus-article-edit-mode-map)
4923 (insert-buffer gnus-original-article-buffer)
4925 (when (featurep 'font-lock)
4926 (set (make-local-variable 'font-lock-defaults)
4927 '(message-font-lock-keywords t))
4928 (font-lock-set-defaults)
4929 (turn-on-font-lock))
4930 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4931 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4933 (defun gnus-article-mime-edit-exit ()
4934 "Exit the article MIME editing without updating."
4936 (let ((winconf gnus-prev-winconf)
4938 (when mime-edit-mode-flag
4941 (goto-char (point-min))
4942 (let (case-fold-search)
4943 (when (re-search-forward
4944 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4945 (replace-match "")))
4946 (when (featurep 'font-lock)
4947 (setq font-lock-defaults nil)
4949 ;; We remove all text props from the article buffer.
4950 (setq buf (format "%s" (buffer-string)))
4951 (set-buffer (get-buffer-create gnus-original-article-buffer))
4954 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4955 (gnus-article-prepare-display)
4956 (set-window-configuration winconf)))
4959 ;;; Article highlights
4962 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4964 ;;; Internal Variables:
4966 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(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\\)\\)"
4967 "Regular expression that matches URLs."
4968 :group 'gnus-article-buttons
4971 (defcustom gnus-button-alist
4972 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4973 0 t gnus-button-message-id 2)
4974 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4975 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4977 gnus-button-fetch-group 4)
4978 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4979 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4980 t gnus-button-message-id 3)
4981 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4982 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4983 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4984 ;; This is how URLs _should_ be embedded in text...
4985 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4987 (,gnus-button-url-regexp 0 t browse-url 0))
4988 "*Alist of regexps matching buttons in article bodies.
4990 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4991 REGEXP: is the string matching text around the button,
4992 BUTTON: is the number of the regexp grouping actually matching the button,
4993 FORM: is a lisp expression which must eval to true for the button to
4995 CALLBACK: is the function to call when the user push this button, and each
4996 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4998 CALLBACK can also be a variable, in that case the value of that
4999 variable it the real callback function."
5000 :group 'gnus-article-buttons
5001 :type '(repeat (list regexp
5002 (integer :tag "Button")
5004 (function :tag "Callback")
5007 (integer :tag "Regexp group")))))
5009 (defcustom gnus-header-button-alist
5010 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
5011 0 t gnus-button-message-id 0)
5012 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5013 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5014 0 t gnus-button-mailto 0)
5015 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5016 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5017 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5018 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5019 gnus-button-message-id 3))
5020 "*Alist of headers and regexps to match buttons in article heads.
5022 This alist is very similar to `gnus-button-alist', except that each
5023 alist has an additional HEADER element first in each entry:
5025 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5027 HEADER is a regexp to match a header. For a fuller explanation, see
5028 `gnus-button-alist'."
5029 :group 'gnus-article-buttons
5030 :group 'gnus-article-headers
5031 :type '(repeat (list (regexp :tag "Header")
5033 (integer :tag "Button")
5035 (function :tag "Callback")
5038 (integer :tag "Regexp group")))))
5040 (defvar gnus-button-regexp nil)
5041 (defvar gnus-button-marker-list nil)
5042 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5044 (defvar gnus-button-last nil)
5045 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5049 (defun gnus-article-push-button (event)
5050 "Check text under the mouse pointer for a callback function.
5051 If the text under the mouse pointer has a `gnus-callback' property,
5052 call it with the value of the `gnus-data' text property."
5054 (set-buffer (window-buffer (posn-window (event-start event))))
5055 (let* ((pos (posn-point (event-start event)))
5056 (data (get-text-property pos 'gnus-data))
5057 (fun (get-text-property pos 'gnus-callback)))
5060 (funcall fun data))))
5062 (defun gnus-article-press-button ()
5063 "Check text at point for a callback function.
5064 If the text at point has a `gnus-callback' property,
5065 call it with the value of the `gnus-data' text property."
5067 (let* ((data (get-text-property (point) 'gnus-data))
5068 (fun (get-text-property (point) 'gnus-callback)))
5070 (funcall fun data))))
5072 (defun gnus-article-prev-button (n)
5073 "Move point to N buttons backward.
5074 If N is negative, move forward instead."
5076 (gnus-article-next-button (- n)))
5078 (defun gnus-article-next-button (n)
5079 "Move point to N buttons forward.
5080 If N is negative, move backward instead."
5082 (let ((function (if (< n 0) 'previous-single-property-change
5083 'next-single-property-change))
5084 (inhibit-point-motion-hooks t)
5086 (limit (if (< n 0) (point-min) (point-max))))
5088 (while (and (not (= limit (point)))
5090 ;; Skip past the current button.
5091 (when (get-text-property (point) 'gnus-callback)
5092 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5093 ;; Go to the next (or previous) button.
5094 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5095 ;; Put point at the start of the button.
5096 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5097 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5098 ;; Skip past intangible buttons.
5099 (when (get-text-property (point) 'intangible)
5103 (gnus-message 5 "No more buttons"))
5106 (defun gnus-article-highlight (&optional force)
5107 "Highlight current article.
5108 This function calls `gnus-article-highlight-headers',
5109 `gnus-article-highlight-citation',
5110 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5111 do the highlighting. See the documentation for those functions."
5112 (interactive (list 'force))
5113 (gnus-article-highlight-headers)
5114 (gnus-article-highlight-citation force)
5115 (gnus-article-highlight-signature)
5116 (gnus-article-add-buttons force)
5117 (gnus-article-add-buttons-to-head))
5119 (defun gnus-article-highlight-some (&optional force)
5120 "Highlight current article.
5121 This function calls `gnus-article-highlight-headers',
5122 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5123 do the highlighting. See the documentation for those functions."
5124 (interactive (list 'force))
5125 (gnus-article-highlight-headers)
5126 (gnus-article-highlight-signature)
5127 (gnus-article-add-buttons))
5129 (defun gnus-article-highlight-headers ()
5130 "Highlight article headers as specified by `gnus-header-face-alist'."
5133 (set-buffer gnus-article-buffer)
5135 (let ((alist gnus-header-face-alist)
5136 (buffer-read-only nil)
5137 (case-fold-search t)
5138 (inhibit-point-motion-hooks t)
5139 entry regexp header-face field-face from hpoints fpoints)
5140 (article-narrow-to-head)
5141 (while (setq entry (pop alist))
5142 (goto-char (point-min))
5143 (setq regexp (concat "^\\("
5144 (if (string-equal "" (nth 0 entry))
5148 header-face (nth 1 entry)
5149 field-face (nth 2 entry))
5150 (while (and (re-search-forward regexp nil t)
5154 (unless (search-forward ":" nil t)
5156 (when (and header-face
5157 (not (memq (point) hpoints)))
5158 (push (point) hpoints)
5159 (gnus-put-text-property from (point) 'face header-face))
5160 (when (and field-face
5161 (not (memq (setq from (point)) fpoints)))
5163 (if (re-search-forward "^[^ \t]" nil t)
5165 (goto-char (point-max)))
5166 (gnus-put-text-property from (point) 'face field-face))))))))
5168 (defun gnus-article-highlight-signature ()
5169 "Highlight the signature in an article.
5170 It does this by highlighting everything after
5171 `gnus-signature-separator' using `gnus-signature-face'."
5173 (when gnus-signature-face
5175 (set-buffer gnus-article-buffer)
5176 (let ((buffer-read-only nil)
5177 (inhibit-point-motion-hooks t))
5179 (when (gnus-article-narrow-to-signature)
5180 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5181 'face gnus-signature-face)))))))
5183 (defun gnus-article-buttonize-signature ()
5184 "Add button to the signature."
5187 (set-buffer gnus-article-buffer)
5188 (let ((buffer-read-only nil)
5189 (inhibit-point-motion-hooks t))
5190 (when (gnus-article-search-signature)
5191 (gnus-article-add-button (match-beginning 0) (match-end 0)
5192 'gnus-signature-toggle
5193 (set-marker (make-marker)
5194 (1+ (match-end 0))))))))
5196 (defun gnus-button-in-region-p (b e prop)
5197 "Say whether PROP exists in the region."
5198 (text-property-not-all b e prop nil))
5200 (defun gnus-article-add-buttons (&optional force)
5201 "Find external references in the article and make buttons of them.
5202 \"External references\" are things like Message-IDs and URLs, as
5203 specified by `gnus-button-alist'."
5204 (interactive (list 'force))
5206 (set-buffer gnus-article-buffer)
5207 (let ((buffer-read-only nil)
5208 (inhibit-point-motion-hooks t)
5209 (case-fold-search t)
5210 (alist gnus-button-alist)
5212 ;; Remove all old markers.
5213 (let (marker entry new-list)
5214 (while (setq marker (pop gnus-button-marker-list))
5215 (if (or (< marker (point-min)) (>= marker (point-max)))
5216 (push marker new-list)
5218 (when (setq entry (gnus-button-entry))
5219 (put-text-property (match-beginning (nth 1 entry))
5220 (match-end (nth 1 entry))
5221 'gnus-callback nil))
5222 (set-marker marker nil)))
5223 (setq gnus-button-marker-list new-list))
5224 ;; We skip the headers.
5227 (while (setq entry (pop alist))
5228 (setq regexp (car entry))
5230 (while (re-search-forward regexp nil t)
5231 (let* ((start (and entry (match-beginning (nth 1 entry))))
5232 (end (and entry (match-end (nth 1 entry))))
5233 (from (match-beginning 0)))
5234 (when (and (or (eq t (nth 2 entry))
5235 (eval (nth 2 entry)))
5236 (not (gnus-button-in-region-p
5237 start end 'gnus-callback)))
5238 ;; That optional form returned non-nil, so we add the
5240 (gnus-article-add-button
5241 start end 'gnus-button-push
5242 (car (push (set-marker (make-marker) from)
5243 gnus-button-marker-list))))))))))
5245 ;; Add buttons to the head of an article.
5246 (defun gnus-article-add-buttons-to-head ()
5247 "Add buttons to the head of the article."
5250 (set-buffer gnus-article-buffer)
5252 (let ((buffer-read-only nil)
5253 (inhibit-point-motion-hooks t)
5254 (case-fold-search t)
5255 (alist gnus-header-button-alist)
5257 (article-narrow-to-head)
5259 ;; Each alist entry.
5260 (setq entry (car alist)
5262 (goto-char (point-min))
5263 (while (re-search-forward (car entry) nil t)
5264 ;; Each header matching the entry.
5265 (setq beg (match-beginning 0))
5266 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5267 (match-beginning 0))
5270 (while (re-search-forward (nth 1 entry) end t)
5271 ;; Each match within a header.
5272 (let* ((entry (cdr entry))
5273 (start (match-beginning (nth 1 entry)))
5274 (end (match-end (nth 1 entry)))
5275 (form (nth 2 entry)))
5276 (goto-char (match-end 0))
5278 (gnus-article-add-button
5279 start end (nth 3 entry)
5280 (buffer-substring (match-beginning (nth 4 entry))
5281 (match-end (nth 4 entry)))))))
5282 (goto-char end)))))))
5284 ;;; External functions:
5286 (defun gnus-article-add-button (from to fun &optional data)
5287 "Create a button between FROM and TO with callback FUN and data DATA."
5288 (when gnus-article-button-face
5289 (gnus-overlay-put (gnus-make-overlay from to)
5290 'face gnus-article-button-face))
5291 (gnus-add-text-properties
5293 (nconc (and gnus-article-mouse-face
5294 (list gnus-mouse-face-prop gnus-article-mouse-face))
5295 (list 'gnus-callback fun)
5296 (and data (list 'gnus-data data))))
5297 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5298 ;; Quote `:button-keymap' for Mule 2.3
5299 ;; but it won't work.
5300 ':button-keymap gnus-widget-button-keymap))
5302 ;;; Internal functions:
5304 (defun gnus-article-set-globals ()
5306 (set-buffer gnus-summary-buffer)
5307 (gnus-set-global-variables)))
5309 (defun gnus-signature-toggle (end)
5311 (set-buffer gnus-article-buffer)
5312 (let ((buffer-read-only nil)
5313 (inhibit-point-motion-hooks t)
5314 (limit (next-single-property-change end 'mime-view-entity
5316 (if (text-property-any end limit 'article-type 'signature)
5317 (gnus-remove-text-properties-when
5318 'article-type 'signature end limit
5319 (cons 'article-type (cons 'signature
5320 gnus-hidden-properties)))
5321 (gnus-add-text-properties-when
5322 'article-type nil end limit
5323 (cons 'article-type (cons 'signature
5324 gnus-hidden-properties)))))))
5326 (defun gnus-button-entry ()
5327 ;; Return the first entry in `gnus-button-alist' matching this place.
5328 (let ((alist gnus-button-alist)
5331 (setq entry (pop alist))
5332 (if (looking-at (car entry))
5337 (defun gnus-button-push (marker)
5338 ;; Push button starting at MARKER.
5341 (let* ((entry (gnus-button-entry))
5342 (inhibit-point-motion-hooks t)
5344 (args (mapcar (lambda (group)
5345 (let ((string (match-string group)))
5346 (gnus-set-text-properties
5347 0 (length string) nil string)
5354 (fboundp (symbol-value fun)))
5355 (apply (symbol-value fun) args))
5357 (gnus-message 1 "You must define `%S' to use this button"
5358 (cons fun args)))))))
5360 (defun gnus-button-message-id (message-id)
5363 (set-buffer gnus-summary-buffer)
5364 (gnus-summary-refer-article message-id)))
5366 (defun gnus-button-fetch-group (address)
5367 "Fetch GROUP specified by ADDRESS."
5368 (if (not (string-match "[:/]" address))
5369 ;; This is just a simple group url.
5370 (gnus-group-read-ephemeral-group address gnus-select-method)
5371 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5373 (error "Can't parse %s" address)
5374 (gnus-group-read-ephemeral-group
5375 (match-string 4 address)
5376 `(nntp ,(match-string 1 address)
5377 (nntp-address ,(match-string 1 address))
5378 (nntp-port-number ,(if (match-end 3)
5379 (match-string 3 address)
5382 (defun gnus-url-parse-query-string (query &optional downcase)
5383 (let (retval pairs cur key val)
5384 (setq pairs (split-string query "&"))
5386 (setq cur (car pairs)
5388 (if (not (string-match "=" cur))
5390 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5391 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5393 (setq key (downcase key)))
5394 (setq cur (assoc key retval))
5396 (setcdr cur (cons val (cdr cur)))
5397 (setq retval (cons (list key val) retval)))))
5400 (defun gnus-url-unhex (x)
5407 (defun gnus-url-unhex-string (str &optional allow-newlines)
5408 "Remove %XXX embedded spaces, etc in a url.
5409 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5410 decoding of carriage returns and line feeds in the string, which is normally
5411 forbidden in URL encoding."
5412 (setq str (or str ""))
5414 (case-fold-search t))
5415 (while (string-match "%[0-9a-f][0-9a-f]" str)
5416 (let* ((start (match-beginning 0))
5417 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5419 (gnus-url-unhex (elt str (+ start 2))))))
5421 tmp (substring str 0 start)
5424 (char-to-string code))
5425 ((or (= code ?\n) (= code ?\r))
5427 (t (char-to-string code))))
5428 str (substring str (match-end 0)))))
5429 (setq tmp (concat tmp str))
5432 (defun gnus-url-mailto (url)
5433 ;; Send mail to someone
5434 (when (string-match "mailto:/*\\(.*\\)" url)
5435 (setq url (substring url (match-beginning 1) nil)))
5436 (let (to args subject func)
5437 (if (string-match (regexp-quote "?") url)
5438 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5439 args (gnus-url-parse-query-string
5440 (substring url (match-end 0) nil) t))
5441 (setq to (gnus-url-unhex-string url)))
5442 (setq args (cons (list "to" to) args)
5443 subject (cdr-safe (assoc "subject" args)))
5444 (gnus-setup-message 'reply
5447 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5450 (message-position-on-field (caar args)))
5451 (insert (mapconcat 'identity (cdar args) ", "))
5452 (setq args (cdr args)))
5455 (message-goto-subject)))))
5457 (defun gnus-button-mailto (address)
5459 (set-buffer (gnus-copy-article-buffer))
5460 (message-reply address))
5462 (defalias 'gnus-button-reply 'message-reply)
5464 (defun gnus-button-embedded-url (address)
5465 "Activate ADDRESS with `browse-url'."
5466 (browse-url (gnus-strip-whitespace address)))
5468 (defun gnus-article-smiley-display ()
5469 "Display \"smileys\" as small graphical icons."
5470 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5472 ;;; Next/prev buttons in the article buffer.
5474 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5475 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5477 (defvar gnus-prev-page-map nil)
5478 (unless gnus-prev-page-map
5479 (setq gnus-prev-page-map (make-sparse-keymap))
5480 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5481 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5483 (static-if (featurep 'xemacs)
5484 (defun gnus-insert-prev-page-button ()
5485 (let ((buffer-read-only nil))
5487 gnus-prev-page-line-format nil
5488 `(gnus-prev t local-map ,gnus-prev-page-map
5489 gnus-callback gnus-article-button-prev-page
5490 article-type annotation))))
5491 (defun gnus-insert-prev-page-button ()
5492 (let ((buffer-read-only nil)
5493 (situation (get-text-property (point-min) 'mime-view-situation)))
5494 (set-keymap-parent gnus-prev-page-map (current-local-map))
5496 gnus-prev-page-line-format nil
5497 `(gnus-prev t local-map ,gnus-prev-page-map
5498 gnus-callback gnus-article-button-prev-page
5499 article-type annotation
5500 mime-view-situation ,situation))))
5503 (defvar gnus-next-page-map nil)
5504 (unless gnus-next-page-map
5505 (setq gnus-next-page-map (make-sparse-keymap))
5506 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5507 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5509 (defun gnus-button-next-page ()
5510 "Go to the next page."
5512 (let ((win (selected-window)))
5513 (select-window (get-buffer-window gnus-article-buffer t))
5514 (gnus-article-next-page)
5515 (select-window win)))
5517 (defun gnus-button-prev-page ()
5518 "Go to the prev page."
5520 (let ((win (selected-window)))
5521 (select-window (get-buffer-window gnus-article-buffer t))
5522 (gnus-article-prev-page)
5523 (select-window win)))
5525 (static-if (featurep 'xemacs)
5526 (defun gnus-insert-next-page-button ()
5527 (let ((buffer-read-only nil))
5528 (gnus-eval-format gnus-next-page-line-format nil
5530 t local-map ,gnus-next-page-map
5531 gnus-callback gnus-article-button-next-page
5532 article-type annotation))))
5533 (defun gnus-insert-next-page-button ()
5534 (let ((buffer-read-only nil)
5535 (situation (get-text-property (point-min) 'mime-view-situation)))
5536 (set-keymap-parent gnus-next-page-map (current-local-map))
5537 (gnus-eval-format gnus-next-page-line-format nil
5539 t local-map ,gnus-next-page-map
5540 gnus-callback gnus-article-button-next-page
5541 article-type annotation
5542 mime-view-situation ,situation))))
5545 (defun gnus-article-button-next-page (arg)
5546 "Go to the next page."
5548 (let ((win (selected-window)))
5549 (select-window (get-buffer-window gnus-article-buffer t))
5550 (gnus-article-next-page)
5551 (select-window win)))
5553 (defun gnus-article-button-prev-page (arg)
5554 "Go to the prev page."
5556 (let ((win (selected-window)))
5557 (select-window (get-buffer-window gnus-article-buffer t))
5558 (gnus-article-prev-page)
5559 (select-window win)))
5561 (defvar gnus-decode-header-methods
5562 '(mail-decode-encoded-word-region)
5563 "List of methods used to decode headers.
5565 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5566 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5567 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5568 whose names match REGEXP.
5571 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5572 mail-decode-encoded-word-region
5573 (\"chinese\" . rfc1843-decode-region))
5576 (defvar gnus-decode-header-methods-cache nil)
5578 (defun gnus-multi-decode-header (start end)
5579 "Apply the functions from `gnus-encoded-word-methods' that match."
5580 (unless (and gnus-decode-header-methods-cache
5581 (eq gnus-newsgroup-name
5582 (car gnus-decode-header-methods-cache)))
5583 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5586 (nconc gnus-decode-header-methods-cache (list x))
5587 (if (and gnus-newsgroup-name
5588 (string-match (car x) gnus-newsgroup-name))
5589 (nconc gnus-decode-header-methods-cache
5591 gnus-decode-header-methods))
5592 (let ((xlist gnus-decode-header-methods-cache))
5595 (narrow-to-region start end)
5597 (funcall (pop xlist) (point-min) (point-max))))))
5600 ;;; Treatment top-level handling.
5603 (defun gnus-treat-article (condition &optional part-number total-parts type)
5604 (let ((length (- (point-max) (point-min)))
5605 (alist gnus-treatment-function-alist)
5606 (article-goto-body-goes-to-point-min-p t)
5610 (let ((list gnus-article-treat-types))
5612 (when (string-match (pop list) type)
5613 (throw 'found t)))))))
5614 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5615 (entity (static-unless (featurep 'xemacs)
5616 (when (eq 'head condition)
5617 (get-text-property (point-min) 'mime-view-entity))))
5618 val elem buttonized)
5619 (gnus-run-hooks 'gnus-part-display-hook)
5620 (unless gnus-inhibit-treatment
5621 (while (setq elem (pop alist))
5624 (if (gnus-buffer-live-p gnus-summary-buffer)
5625 (set-buffer gnus-summary-buffer))
5626 (symbol-value (car elem))))
5627 (when (and (or (consp val)
5629 (gnus-treat-predicate val)
5630 (or (not (get (car elem) 'highlight))
5632 (when (and (not buttonized)
5634 '(gnus-treat-hide-signature
5635 gnus-treat-highlight-signature)))
5636 (gnus-article-buttonize-signature)
5637 (setq buttonized t))
5639 (funcall (cadr elem)))))
5640 ;; FSF Emacsen does not inherit the existing text properties
5641 ;; in the new text, so we should do it for `mime-view-entity'.
5642 (static-unless (featurep 'xemacs)
5644 (put-text-property (point-min) (point-max)
5645 'mime-view-entity entity))))))
5647 ;; Dynamic variables.
5649 (defvar part-number)
5650 (defvar total-parts)
5655 (defun gnus-treat-predicate (val)
5660 (stringp (car val)))
5661 (apply 'gnus-or (mapcar `(lambda (s)
5662 (string-match s ,(or gnus-newsgroup-name "")))
5665 (let ((pred (pop val)))
5668 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5670 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5672 (not (gnus-treat-predicate (car val))))
5674 (equal (car val) type))
5676 (error "%S is not a valid predicate" pred)))))
5686 (eq part-number total-parts))
5690 (error "%S is not a valid value" val))))
5692 (defun gnus-article-encrypt-body (protocol &optional n)
5693 "Encrypt the article body."
5696 (or gnus-article-encrypt-protocol
5697 (completing-read "Encrypt protocol: "
5698 gnus-article-encrypt-protocol-alist
5700 current-prefix-arg))
5701 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5703 (error (format "Can't find the encrypt protocol %s" protocol)))
5704 (if (equal gnus-newsgroup-name "nndraft:drafts")
5705 (error "Can't encrypt the article in group nndraft:drafts."))
5706 (if (equal gnus-newsgroup-name "nndraft:queue")
5707 (error "Don't encrypt the article in group nndraft:queue."))
5708 (gnus-summary-iterate n
5710 (set-buffer gnus-summary-buffer)
5711 (let ((mail-parse-charset gnus-newsgroup-charset)
5712 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5713 (summary-buffer gnus-summary-buffer)
5715 (gnus-set-global-variables)
5716 (when (gnus-group-read-only-p)
5717 (error "The current newsgroup does not support article encrypt"))
5718 (gnus-summary-show-article t)
5720 (or (mail-header-references gnus-current-headers) ""))
5721 (set-buffer gnus-article-buffer)
5722 (let* ((buffer-read-only nil)
5724 (mapcar (lambda (field)
5725 (and (save-restriction
5726 (message-narrow-to-head)
5727 (goto-char (point-min))
5728 (search-forward field nil t))
5730 (message-narrow-to-field)
5731 (buffer-substring (point-min) (point-max))
5732 (delete-region (point-min) (point-max))
5734 '("Content-Type:" "Content-Transfer-Encoding:"
5735 "Content-Disposition:"))))
5736 (message-narrow-to-head)
5737 (message-remove-header "MIME-Version")
5738 (goto-char (point-max))
5739 (setq point (point))
5740 (insert (apply 'concat headers))
5742 (narrow-to-region point (point-max))
5743 (let ((message-options message-options))
5744 (message-options-set 'message-sender user-mail-address)
5745 (message-options-set 'message-recipients user-mail-address)
5746 (message-options-set 'message-sign-encrypt 'not)
5748 (goto-char (point-min))
5749 (insert "MIME-Version: 1.0\n")
5751 (gnus-summary-edit-article-done
5752 references nil summary-buffer t))
5753 (when gnus-keep-backlog
5754 (gnus-backlog-remove-article
5755 (car gnus-article-current) (cdr gnus-article-current)))
5757 (when (get-buffer gnus-original-article-buffer)
5758 (set-buffer gnus-original-article-buffer)
5759 (setq gnus-original-article nil)))
5760 (when gnus-use-cache
5761 (gnus-cache-update-article
5762 (car gnus-article-current) (cdr gnus-article-current))))))))
5764 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5765 "The following specs can be used:
5766 %t The security MIME type
5769 %D Details if button is pressed")
5771 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5772 "The following specs can be used:
5773 %t The security MIME type
5776 %D Details if button is pressed")
5778 (defvar gnus-mime-security-button-line-format-alist
5779 '((?t gnus-tmp-type ?s)
5780 (?i gnus-tmp-info ?s)
5781 (?d gnus-tmp-details ?s)
5782 (?D gnus-tmp-pressed-details ?s)))
5784 (defvar gnus-mime-security-button-map
5785 (let ((map (make-sparse-keymap)))
5786 (unless (>= (string-to-number emacs-version) 21)
5787 (set-keymap-parent map gnus-article-mode-map))
5788 (define-key map gnus-mouse-2 'gnus-article-push-button)
5789 (define-key map "\r" 'gnus-article-press-button)
5792 (defvar gnus-mime-security-details-buffer nil)
5794 (defvar gnus-mime-security-button-pressed nil)
5796 (defvar gnus-mime-security-show-details-inline t
5797 "If non-nil, show details in the article buffer.")
5799 (defun gnus-mime-security-verify-or-decrypt (handle)
5800 (mm-remove-parts (cdr handle))
5801 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5804 (delete-region (car region) (cdr region))
5805 (set-marker (car region) nil)
5806 (set-marker (cdr region) nil)))
5807 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5808 (let* ((mm-verify-option 'known)
5809 (mm-decrypt-option 'known)
5810 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5811 (unless (eq nparts (cdr handle))
5812 (mm-destroy-parts (cdr handle))
5813 (setcdr handle nparts))))
5814 (let ((point (point))
5816 (gnus-mime-display-security handle)
5819 (defun gnus-mime-security-show-details (handle)
5820 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5822 (if gnus-mime-security-show-details-inline
5823 (let ((gnus-mime-security-button-pressed t)
5824 (gnus-mime-security-button-line-format
5825 (get-text-property (point) 'gnus-line-format))
5828 (while (eq (get-text-property (point) 'gnus-line-format)
5829 gnus-mime-security-button-line-format)
5832 (delete-region (point)
5833 (or (text-property-not-all
5836 gnus-mime-security-button-line-format)
5838 (gnus-insert-mime-security-button handle))
5839 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5840 (with-current-buffer gnus-mime-security-details-buffer
5843 (setq gnus-mime-security-details-buffer
5844 (gnus-get-buffer-create "*MIME Security Details*")))
5845 (with-current-buffer gnus-mime-security-details-buffer
5847 (goto-char (point-min)))
5848 (pop-to-buffer gnus-mime-security-details-buffer))
5849 (gnus-message 5 "No details."))))
5851 (defun gnus-mime-security-press-button (handle)
5852 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5853 (gnus-mime-security-show-details handle)
5854 (gnus-mime-security-verify-or-decrypt handle)))
5856 (defun gnus-insert-mime-security-button (handle &optional displayed)
5857 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5860 (or (nth 2 (assoc protocol mm-verify-function-alist))
5861 (nth 2 (assoc protocol mm-decrypt-function-alist))
5863 (if (equal (car handle) "multipart/signed")
5864 " Signed" " Encrypted")
5867 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5870 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5871 gnus-tmp-pressed-details
5873 (setq gnus-tmp-details
5874 (if gnus-tmp-details
5875 (concat "\n" gnus-tmp-details) ""))
5876 (setq gnus-tmp-pressed-details
5877 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5882 gnus-mime-security-button-line-format
5883 gnus-mime-security-button-line-format-alist
5884 `(keymap ,gnus-mime-security-button-map
5885 ,@(if (>= (string-to-number emacs-version) 21)
5886 nil ;; XEmacs doesn't care
5887 (list 'local-map gnus-mime-security-button-map))
5888 gnus-callback gnus-mime-security-press-button
5889 gnus-line-format ,gnus-mime-security-button-line-format
5890 article-type annotation
5893 (widget-convert-button
5896 :action 'gnus-widget-press-button
5897 :button-keymap gnus-mime-security-button-map
5899 (lambda (widget/window &optional overlay pos)
5900 ;; Needed to properly clear the message due to a bug in
5901 ;; wid-edit (XEmacs only).
5902 (if (boundp 'help-echo-owns-message)
5903 (setq help-echo-owns-message t))
5906 (aref gnus-mouse-2 0))))))
5908 (defun gnus-mime-display-security (handle)
5910 (narrow-to-region (point) (point))
5911 (gnus-insert-mime-security-button handle)
5912 (gnus-mime-display-mixed (cdr handle))
5915 (let ((gnus-mime-security-button-line-format
5916 gnus-mime-security-button-end-line-format))
5917 (gnus-insert-mime-security-button handle))
5918 (mm-set-handle-multipart-parameter handle 'gnus-region
5919 (cons (set-marker (make-marker)
5921 (set-marker (make-marker)
5928 (defun gnus-article-header-presentation-method (entity situation)
5929 (mime-insert-header entity)
5932 (set-alist 'mime-header-presentation-method-alist
5933 'gnus-original-article-mode
5934 #'gnus-article-header-presentation-method)
5936 (defun gnus-mime-preview-quitting-method ()
5937 (mime-preview-kill-buffer)
5938 (delete-other-windows)
5939 (gnus-article-show-summary)
5940 (gnus-summary-select-article gnus-show-all-headers t))
5942 (set-alist 'mime-preview-quitting-method-alist
5943 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5945 (set-alist 'mime-preview-following-method-alist
5946 'gnus-original-article-mode #'gnus-following-method)
5948 (set-alist 'mime-preview-over-to-previous-method-alist
5949 'gnus-original-article-mode
5951 (if (> (point-min) 1)
5952 (gnus-article-prev-page)
5953 (gnus-article-read-summary-keys
5954 nil (gnus-character-to-event ?P)))))
5956 (set-alist 'mime-preview-over-to-next-method-alist
5957 'gnus-original-article-mode'
5959 (if (< (point-max) (buffer-size))
5960 (gnus-article-next-page)
5961 (gnus-article-read-summary-keys
5962 nil (gnus-character-to-event ?N)))))
5972 (run-hooks 'gnus-art-load-hook)
5974 ;;; gnus-art.el ends here