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 (defcustom gnus-article-banner-alist nil
256 "Banner alist for stripping.
258 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
260 :type '(repeat (cons symbol regexp))
261 :group 'gnus-article-washing)
263 (defcustom gnus-emphasis-alist
265 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
267 '(("_" "_" underline)
270 ("_/" "/_" underline-italic)
271 ("_\\*" "\\*_" underline-bold)
272 ("\\*/" "/\\*" bold-italic)
273 ("_\\*/" "/\\*_" underline-bold-italic))))
274 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
275 2 3 gnus-emphasis-underline)
279 (format format (car spec) (car (cdr spec)))
280 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
282 "*Alist that says how to fontify certain phrases.
283 Each item looks like this:
285 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
287 The first element is a regular expression to be matched. The second
288 is a number that says what regular expression grouping used to find
289 the entire emphasized word. The third is a number that says what
290 regexp grouping should be displayed and highlighted. The fourth
291 is the face used for highlighting."
292 :type '(repeat (list :value ("" 0 0 default)
294 (integer :tag "Match group")
295 (integer :tag "Emphasize group")
297 :group 'gnus-article-emphasis)
299 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
300 "A regexp to describe whitespace which should not be emphasized.
301 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
302 The former avoids underlining of leading and trailing whitespace,
303 and the latter avoids underlining any whitespace at all."
305 :group 'gnus-article-emphasis
308 (defface gnus-emphasis-bold '((t (:bold t)))
309 "Face used for displaying strong emphasized text (*word*)."
310 :group 'gnus-article-emphasis)
312 (defface gnus-emphasis-italic '((t (:italic t)))
313 "Face used for displaying italic emphasized text (/word/)."
314 :group 'gnus-article-emphasis)
316 (defface gnus-emphasis-underline '((t (:underline t)))
317 "Face used for displaying underlined emphasized text (_word_)."
318 :group 'gnus-article-emphasis)
320 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
321 "Face used for displaying underlined bold emphasized text (_*word*_)."
322 :group 'gnus-article-emphasis)
324 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
325 "Face used for displaying underlined italic emphasized text (_/word/_)."
326 :group 'gnus-article-emphasis)
328 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
329 "Face used for displaying bold italic emphasized text (/*word*/)."
330 :group 'gnus-article-emphasis)
332 (defface gnus-emphasis-underline-bold-italic
333 '((t (:bold t :italic t :underline t)))
334 "Face used for displaying underlined bold italic emphasized text.
335 Esample: (_/*word*/_)."
336 :group 'gnus-article-emphasis)
338 (defface gnus-emphasis-highlight-words
339 '((t (:background "black" :foreground "yellow")))
340 "Face used for displaying highlighted words."
341 :group 'gnus-article-emphasis)
343 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
344 "Format for display of Date headers in article bodies.
345 See `format-time-string' for the possible values.
347 The variable can also be function, which should return a complete Date
348 header. The function is called with one argument, the time, which can
349 be fed to `format-time-string'."
350 :type '(choice string symbol)
351 :link '(custom-manual "(gnus)Article Date")
352 :group 'gnus-article-washing)
355 (autoload 'mail-extract-address-components "mail-extr"))
357 (defcustom gnus-save-all-headers t
358 "*If non-nil, don't remove any headers before saving."
359 :group 'gnus-article-saving
362 (defcustom gnus-prompt-before-saving 'always
363 "*This variable says how much prompting is to be done when saving articles.
364 If it is nil, no prompting will be done, and the articles will be
365 saved to the default files. If this variable is `always', each and
366 every article that is saved will be preceded by a prompt, even when
367 saving large batches of articles. If this variable is neither nil not
368 `always', there the user will be prompted once for a file name for
369 each invocation of the saving commands."
370 :group 'gnus-article-saving
371 :type '(choice (item always)
372 (item :tag "never" nil)
373 (sexp :tag "once" :format "%t\n" :value t)))
375 (defcustom gnus-saved-headers gnus-visible-headers
376 "Headers to keep if `gnus-save-all-headers' is nil.
377 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
378 If that variable is nil, however, all headers that match this regexp
379 will be kept while the rest will be deleted before saving."
380 :group 'gnus-article-saving
383 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
384 "A function to save articles in your favourite format.
385 The function must be interactively callable (in other words, it must
386 be an Emacs command).
388 Gnus provides the following functions:
390 * gnus-summary-save-in-rmail (Rmail format)
391 * gnus-summary-save-in-mail (Unix mail format)
392 * gnus-summary-save-in-folder (MH folder)
393 * gnus-summary-save-in-file (article format)
394 * gnus-summary-save-in-vm (use VM's folder format)
395 * gnus-summary-write-to-file (article format -- overwrite)."
396 :group 'gnus-article-saving
397 :type '(radio (function-item gnus-summary-save-in-rmail)
398 (function-item gnus-summary-save-in-mail)
399 (function-item gnus-summary-save-in-folder)
400 (function-item gnus-summary-save-in-file)
401 (function-item gnus-summary-save-in-vm)
402 (function-item gnus-summary-write-to-file)))
404 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
405 "A function generating a file name to save articles in Rmail format.
406 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
407 :group 'gnus-article-saving
410 (defcustom gnus-mail-save-name 'gnus-plain-save-name
411 "A function generating a file name to save articles in Unix mail format.
412 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
413 :group 'gnus-article-saving
416 (defcustom gnus-folder-save-name 'gnus-folder-save-name
417 "A function generating a file name to save articles in MH folder.
418 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
419 :group 'gnus-article-saving
422 (defcustom gnus-file-save-name 'gnus-numeric-save-name
423 "A function generating a file name to save articles in article format.
424 The function is called with NEWSGROUP, HEADERS, and optional
426 :group 'gnus-article-saving
429 (defcustom gnus-split-methods
430 '((gnus-article-archive-name)
431 (gnus-article-nndoc-name))
432 "*Variable used to suggest where articles are to be saved.
433 For instance, if you would like to save articles related to Gnus in
434 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
435 you could set this variable to something like:
437 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
438 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
440 This variable is an alist where the where the key is the match and the
441 value is a list of possible files to save in if the match is non-nil.
443 If the match is a string, it is used as a regexp match on the
444 article. If the match is a symbol, that symbol will be funcalled
445 from the buffer of the article to be saved with the newsgroup as the
446 parameter. If it is a list, it will be evaled in the same buffer.
448 If this form or function returns a string, this string will be used as
449 a possible file name; and if it returns a non-nil list, that list will
450 be used as possible file names."
451 :group 'gnus-article-saving
452 :type '(repeat (choice (list :value (fun) function)
453 (cons :value ("" "") regexp (repeat string))
456 (defcustom gnus-article-display-method-for-mime
457 'gnus-article-display-mime-message
458 "Function to display a MIME message.
459 The function is called from the article buffer."
460 :group 'gnus-article-mime
463 (defcustom gnus-article-display-method-for-traditional
464 'gnus-article-display-traditional-message
465 "*Function to display a traditional message.
466 The function is called from the article buffer."
467 :group 'gnus-article-mime
470 (defcustom gnus-page-delimiter "^\^L"
471 "*Regexp describing what to use as article page delimiters.
472 The default value is \"^\^L\", which is a form linefeed at the
473 beginning of a line."
475 :group 'gnus-article-various)
477 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
478 "*The format specification for the article mode line.
479 See `gnus-summary-mode-line-format' for a closer description.
481 The following additional specs are available:
483 %w The article washing status.
484 %m The number of MIME parts in the article."
486 :group 'gnus-article-various)
488 (defcustom gnus-article-mode-hook nil
489 "*A hook for Gnus article mode."
491 :group 'gnus-article-various)
493 (defcustom gnus-article-menu-hook nil
494 "*Hook run after the creation of the article mode menu."
496 :group 'gnus-article-various)
498 (defcustom gnus-article-prepare-hook nil
499 "*A hook called after an article has been prepared in the article buffer."
501 :group 'gnus-article-various)
503 (defcustom gnus-article-hide-pgp-hook nil
504 "*A hook called after successfully hiding a PGP signature."
506 :group 'gnus-article-various)
508 (defcustom gnus-article-button-face 'bold
509 "Face used for highlighting buttons in the article buffer.
511 An article button is a piece of text that you can activate by pressing
512 `RET' or `mouse-2' above it."
514 :group 'gnus-article-buttons)
516 (defcustom gnus-article-mouse-face 'highlight
517 "Face used for mouse highlighting in the article buffer.
519 Article buttons will be displayed in this face when the cursor is
522 :group 'gnus-article-buttons)
524 (defcustom gnus-signature-face 'gnus-signature-face
525 "Face used for highlighting a signature in the article buffer.
526 Obsolete; use the face `gnus-signature-face' for customizations instead."
528 :group 'gnus-article-highlight
529 :group 'gnus-article-signature)
531 (defface gnus-signature-face
534 "Face used for highlighting a signature in the article buffer."
535 :group 'gnus-article-highlight
536 :group 'gnus-article-signature)
538 (defface gnus-header-from-face
541 (:foreground "spring green"))
544 (:foreground "red3"))
547 "Face used for displaying from headers."
548 :group 'gnus-article-headers
549 :group 'gnus-article-highlight)
551 (defface gnus-header-subject-face
554 (:foreground "SeaGreen3"))
557 (:foreground "red4"))
559 (:bold t :italic t)))
560 "Face used for displaying subject headers."
561 :group 'gnus-article-headers
562 :group 'gnus-article-highlight)
564 (defface gnus-header-newsgroups-face
567 (:foreground "yellow" :italic t))
570 (:foreground "MidnightBlue" :italic t))
573 "Face used for displaying newsgroups headers."
574 :group 'gnus-article-headers
575 :group 'gnus-article-highlight)
577 (defface gnus-header-name-face
580 (:foreground "SeaGreen"))
583 (:foreground "maroon"))
586 "Face used for displaying header names."
587 :group 'gnus-article-headers
588 :group 'gnus-article-highlight)
590 (defface gnus-header-content-face
593 (:foreground "forest green" :italic t))
596 (:foreground "indianred4" :italic t))
598 (:italic t))) "Face used for displaying header content."
599 :group 'gnus-article-headers
600 :group 'gnus-article-highlight)
602 (defcustom gnus-header-face-alist
603 '(("From" nil gnus-header-from-face)
604 ("Subject" nil gnus-header-subject-face)
605 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
606 ("" gnus-header-name-face gnus-header-content-face))
607 "*Controls highlighting of article header.
609 An alist of the form (HEADER NAME CONTENT).
611 HEADER is a regular expression which should match the name of an
612 header header and NAME and CONTENT are either face names or nil.
614 The name of each header field will be displayed using the face
615 specified by the first element in the list where HEADER match the
616 header name and NAME is non-nil. Similarly, the content will be
617 displayed by the first non-nil matching CONTENT face."
618 :group 'gnus-article-headers
619 :group 'gnus-article-highlight
620 :type '(repeat (list (regexp :tag "Header")
622 (item :tag "skip" nil)
623 (face :value default))
624 (choice :tag "Content"
625 (item :tag "skip" nil)
626 (face :value default)))))
628 (defcustom gnus-article-decode-hook nil
629 "*Hook run to decode charsets in articles."
630 :group 'gnus-article-headers
633 (defcustom gnus-display-mime-function 'gnus-display-mime
634 "Function to display MIME articles."
635 :group 'gnus-article-mime
638 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
639 "Function used to decode headers.")
641 (defvar gnus-article-dumbquotes-map
660 "Table for MS-to-Latin1 translation.")
662 (defcustom gnus-ignored-mime-types nil
663 "List of MIME types that should be ignored by Gnus."
665 :group 'gnus-article-mime
666 :type '(repeat regexp))
668 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
669 "List of MIME types that should not be given buttons when rendered inline."
671 :group 'gnus-article-mime
672 :type '(repeat regexp))
674 (defcustom gnus-article-mime-part-function nil
675 "Function called with a MIME handle as the argument.
676 This is meant for people who want to do something automatic based
677 on parts -- for instance, adding Vcard info to a database."
678 :group 'gnus-article-mime
681 (defcustom gnus-mime-multipart-functions nil
682 "An alist of MIME types to functions to display them."
684 :group 'gnus-article-mime
687 (defcustom gnus-article-date-lapsed-new-header nil
688 "Whether the X-Sent and Date headers can coexist.
689 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
690 either replace the old \"Date:\" header (if this variable is nil), or
691 be added below it (otherwise)."
693 :group 'gnus-article-headers
696 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
697 "Function called with a MIME handle as the argument.
698 This is meant for people who want to view first matched part.
699 For `undisplayed-alternative' (default), the first undisplayed
700 part or alternative part is used. For `undisplayed', the first
701 undisplayed part is used. For a function, the first part which
702 the function return `t' is used. For `nil', the first part is
705 :group 'gnus-article-mime
707 (item :tag "first" :value nil)
708 (item :tag "undisplayed" :value undisplayed)
709 (item :tag "undisplayed or alternative"
710 :value undisplayed-alternative)
713 (defcustom gnus-mime-action-alist
714 '(("save to file" . gnus-mime-save-part)
715 ("save and strip" . gnus-mime-save-part-and-strip)
716 ("display as text" . gnus-mime-inline-part)
717 ("view the part" . gnus-mime-view-part)
718 ("pipe to command" . gnus-mime-pipe-part)
719 ("toggle display" . gnus-article-press-button)
720 ("toggle display" . gnus-article-view-part-as-charset)
721 ("view as type" . gnus-mime-view-part-as-type)
722 ("internalize type" . gnus-mime-internalize-part)
723 ("externalize type" . gnus-mime-externalize-part))
724 "An alist of actions that run on the MIME attachment."
725 :group 'gnus-article-mime
726 :type '(repeat (cons (string :tag "name")
729 (defcustom gnus-mime-action-alist
730 '(("save to file" . gnus-mime-save-part)
731 ("display as text" . gnus-mime-inline-part)
732 ("view the part" . gnus-mime-view-part)
733 ("pipe to command" . gnus-mime-pipe-part)
734 ("toggle display" . gnus-article-press-button)
735 ("view as type" . gnus-mime-view-part-as-type)
736 ("internalize type" . gnus-mime-internalize-part)
737 ("externalize type" . gnus-mime-externalize-part))
738 "An alist of actions that run on the MIME attachment."
740 :group 'gnus-article-mime
741 :type '(repeat (cons (string :tag "name")
745 ;;; The treatment variables
748 (defvar gnus-part-display-hook nil
749 "Hook called on parts that are to receive treatment.")
751 (defvar gnus-article-treat-custom
752 '(choice (const :tag "Off" nil)
754 (const :tag "Header" head)
755 (const :tag "Last" last)
756 (const :tag "Mime" mime)
757 (integer :tag "Less")
758 (repeat :tag "Groups" regexp)
759 (sexp :tag "Predicate")))
761 (defvar gnus-article-treat-head-custom
762 '(choice (const :tag "Off" nil)
763 (const :tag "Header" head)))
765 (defvar gnus-article-treat-types '("text/plain")
768 (defvar gnus-inhibit-treatment nil
769 "Whether to inhibit treatment.")
771 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
772 "Highlight the signature.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-custom)
777 (put 'gnus-treat-highlight-signature 'highlight t)
779 (defcustom gnus-treat-buttonize 100000
781 Valid values are nil, t, `head', `last', an integer or a predicate.
782 See the manual for details."
783 :group 'gnus-article-treat
784 :type gnus-article-treat-custom)
785 (put 'gnus-treat-buttonize 'highlight t)
787 (defcustom gnus-treat-buttonize-head 'head
788 "Add buttons to the head.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-head-custom)
793 (put 'gnus-treat-buttonize-head 'highlight t)
795 (defcustom gnus-treat-emphasize nil
797 Valid values are nil, t, `head', `last', an integer or a predicate.
798 See the manual for details."
799 :group 'gnus-article-treat
800 :type gnus-article-treat-custom)
801 (put 'gnus-treat-emphasize 'highlight t)
803 (defcustom gnus-treat-strip-cr nil
804 "Remove carriage returns.
805 Valid values are nil, t, `head', `last', an integer or a predicate.
806 See the manual for details."
807 :group 'gnus-article-treat
808 :type gnus-article-treat-custom)
810 (defcustom gnus-treat-hide-headers 'head
812 Valid values are nil, t, `head', `last', an integer or a predicate.
813 See the manual for details."
814 :group 'gnus-article-treat
815 :type gnus-article-treat-head-custom)
817 (defcustom gnus-treat-hide-boring-headers nil
818 "Hide boring headers.
819 Valid values are nil, t, `head', `last', an integer or a predicate.
820 See the manual for details."
821 :group 'gnus-article-treat
822 :type gnus-article-treat-head-custom)
824 (defcustom gnus-treat-hide-signature nil
826 Valid values are nil, t, `head', `last', an integer or a predicate.
827 See the manual for details."
828 :group 'gnus-article-treat
829 :type gnus-article-treat-custom)
831 (defcustom gnus-treat-fill-article nil
833 Valid values are nil, t, `head', `last', an integer or a predicate.
834 See the manual for details."
835 :group 'gnus-article-treat
836 :type gnus-article-treat-custom)
838 (defcustom gnus-treat-hide-citation nil
840 Valid values are nil, t, `head', `last', an integer or a predicate.
841 See the manual for details."
842 :group 'gnus-article-treat
843 :type gnus-article-treat-custom)
845 (defcustom gnus-treat-hide-citation-maybe nil
847 Valid values are nil, t, `head', `last', an integer or a predicate.
848 See the manual for details."
849 :group 'gnus-article-treat
850 :type gnus-article-treat-custom)
852 (defcustom gnus-treat-hide-citation-maybe nil
854 Valid values are nil, t, `head', `last', an integer or a predicate.
855 See the manual for details."
856 :group 'gnus-article-treat
857 :type gnus-article-treat-custom)
859 (defcustom gnus-treat-strip-list-identifiers 'head
860 "Strip list identifiers from `gnus-list-identifiers`.
861 Valid values are nil, t, `head', `last', an integer or a predicate.
862 See the manual for details."
864 :group 'gnus-article-treat
865 :type gnus-article-treat-custom)
867 (defcustom gnus-treat-strip-pgp t
868 "Strip PGP signatures.
869 Valid values are nil, t, `head', `last', an integer or a predicate.
870 See the manual for details."
871 :group 'gnus-article-treat
872 :type gnus-article-treat-custom)
874 (defcustom gnus-treat-strip-pem nil
875 "Strip PEM signatures.
876 Valid values are nil, t, `head', `last', an integer or a predicate.
877 See the manual for details."
878 :group 'gnus-article-treat
879 :type gnus-article-treat-custom)
881 (defcustom gnus-treat-strip-banner t
882 "Strip banners from articles.
883 The banner to be stripped is specified in the `banner' group parameter.
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-custom)
889 (defcustom gnus-treat-highlight-headers 'head
890 "Highlight the headers.
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893 :group 'gnus-article-treat
894 :type gnus-article-treat-head-custom)
895 (put 'gnus-treat-highlight-headers 'highlight t)
897 (defcustom gnus-treat-highlight-citation t
898 "Highlight cited text.
899 Valid values are nil, t, `head', `last', an integer or a predicate.
900 See the manual for details."
901 :group 'gnus-article-treat
902 :type gnus-article-treat-custom)
903 (put 'gnus-treat-highlight-citation 'highlight t)
905 (defcustom gnus-treat-date-ut nil
906 "Display the Date in UT (GMT).
907 Valid values are nil, t, `head', `last', an integer or a predicate.
908 See the manual for details."
909 :group 'gnus-article-treat
910 :type gnus-article-treat-head-custom)
912 (defcustom gnus-treat-date-local nil
913 "Display the Date in the local timezone.
914 Valid values are nil, t, `head', `last', an integer or a predicate.
915 See the manual for details."
916 :group 'gnus-article-treat
917 :type gnus-article-treat-head-custom)
919 (defcustom gnus-treat-date-lapsed nil
920 "Display the Date header in a way that says how much time has elapsed.
921 Valid values are nil, t, `head', `last', an integer or a predicate.
922 See the manual for details."
923 :group 'gnus-article-treat
924 :type gnus-article-treat-head-custom)
926 (defcustom gnus-treat-date-original nil
927 "Display the date in the original timezone.
928 Valid values are nil, t, `head', `last', an integer or a predicate.
929 See the manual for details."
930 :group 'gnus-article-treat
931 :type gnus-article-treat-head-custom)
933 (defcustom gnus-treat-date-iso8601 nil
934 "Display the date in the ISO8601 format.
935 Valid values are nil, t, `head', `last', an integer or a predicate.
936 See the manual for details."
938 :group 'gnus-article-treat
939 :type gnus-article-treat-head-custom)
941 (defcustom gnus-treat-date-user-defined nil
942 "Display the date in a user-defined format.
943 The format is defined by the `gnus-article-time-format' variable.
944 Valid values are nil, t, `head', `last', an integer or a predicate.
945 See the manual for details."
946 :group 'gnus-article-treat
947 :type gnus-article-treat-head-custom)
949 (defcustom gnus-treat-strip-headers-in-body t
950 "Strip the X-No-Archive header line from the beginning of the body.
951 Valid values are nil, t, `head', `last', an integer or a predicate.
952 See the manual for details."
954 :group 'gnus-article-treat
955 :type gnus-article-treat-custom)
957 (defcustom gnus-treat-strip-trailing-blank-lines nil
958 "Strip trailing blank lines.
959 Valid values are nil, t, `head', `last', an integer or a predicate.
960 See the manual for details."
961 :group 'gnus-article-treat
962 :type gnus-article-treat-custom)
964 (defcustom gnus-treat-strip-leading-blank-lines nil
965 "Strip leading blank lines.
966 Valid values are nil, t, `head', `last', an integer or a predicate.
967 See the manual for details."
968 :group 'gnus-article-treat
969 :type gnus-article-treat-custom)
971 (defcustom gnus-treat-strip-multiple-blank-lines nil
972 "Strip multiple blank lines.
973 Valid values are nil, t, `head', `last', an integer or a predicate.
974 See the manual for details."
975 :group 'gnus-article-treat
976 :type gnus-article-treat-custom)
978 (defcustom gnus-treat-overstrike t
979 "Treat overstrike highlighting.
980 Valid values are nil, t, `head', `last', an integer or a predicate.
981 See the manual for details."
982 :group 'gnus-article-treat
983 :type gnus-article-treat-custom)
984 (put 'gnus-treat-overstrike 'highlight t)
986 (defcustom gnus-treat-display-xface
987 (and (or (and (fboundp 'image-type-available-p)
988 (image-type-available-p 'xbm)
989 (string-match "^0x" (shell-command-to-string "uncompface")))
990 (and (featurep 'xemacs) (featurep 'xface))
991 (eq 'x-face-mule-gnus-article-display-x-face
992 gnus-article-x-face-command))
994 "Display X-Face headers.
995 Valid values are nil, t, `head', `last', an integer or a predicate.
996 See the manual for details."
997 :group 'gnus-article-treat
998 :type gnus-article-treat-head-custom)
999 (put 'gnus-treat-display-xface 'highlight t)
1001 (defcustom gnus-treat-display-smileys
1002 (if (or (and (featurep 'xemacs)
1004 (and (fboundp 'image-type-available-p)
1005 (image-type-available-p 'pbm))
1006 (and (not (featurep 'xemacs))
1008 (module-installed-p 'gnus-bitmap)))
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-custom)
1016 (put 'gnus-treat-display-smileys 'highlight t)
1018 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1020 Valid values are nil, t, `head', `last', an integer or a predicate.
1021 See the manual for details."
1022 :group 'gnus-article-treat
1023 :type gnus-article-treat-head-custom)
1024 (put 'gnus-treat-display-picons 'highlight t)
1026 (defcustom gnus-treat-capitalize-sentences nil
1027 "Capitalize sentence-starting words.
1028 Valid values are nil, t, `head', `last', an integer or a predicate.
1029 See the manual for details."
1031 :group 'gnus-article-treat
1032 :type gnus-article-treat-custom)
1034 (defcustom gnus-treat-fill-long-lines nil
1036 Valid values are nil, t, `head', `last', an integer or a predicate.
1037 See the manual for details."
1038 :group 'gnus-article-treat
1039 :type gnus-article-treat-custom)
1041 (defcustom gnus-treat-play-sounds nil
1043 Valid values are nil, t, `head', `last', an integer or a predicate.
1044 See the manual for details."
1046 :group 'gnus-article-treat
1047 :type gnus-article-treat-custom)
1049 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1050 "Decode an article as `default-mime-charset'. For instance, if you want to
1051 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1052 you could set this variable to something like: nil for don't decode, t for
1053 decode the body, '(or header t) for the whole article, etc."
1054 :group 'gnus-article-treat
1055 :type '(radio (const :tag "Off" nil)
1056 (const :tag "Decode body" t)
1057 (const :tag "Decode all" (or head t))))
1059 (defcustom gnus-treat-translate nil
1060 "Translate articles from one language to another.
1061 Valid values are nil, t, `head', `last', an integer or a predicate.
1062 See the manual for details."
1064 :group 'gnus-article-treat
1065 :type gnus-article-treat-custom)
1067 (defcustom gnus-treat-x-pgp-sig nil
1069 To automatically treat X-PGP-Sig, set it to head.
1070 Valid values are nil, t, `head', `last', an integer or a predicate.
1071 See the manual for details."
1072 :group 'gnus-article-treat
1073 :group 'mime-security
1074 :type gnus-article-treat-custom)
1076 (defvar gnus-article-encrypt-protocol-alist
1077 '(("PGP" . mml2015-self-encrypt)))
1079 ;; Set to nil if more than one protocol added to
1080 ;; gnus-article-encrypt-protocol-alist.
1081 (defcustom gnus-article-encrypt-protocol "PGP"
1082 "The protocol used for encrypt articles.
1083 It is a string, such as \"PGP\". If nil, ask user."
1085 :group 'mime-security)
1087 ;;; Internal variables
1089 (defvar article-goto-body-goes-to-point-min-p nil)
1090 (defvar gnus-article-wash-types nil)
1091 (defvar gnus-article-emphasis-alist nil)
1093 (defvar gnus-article-mime-handle-alist-1 nil)
1094 (defvar gnus-treatment-function-alist
1095 '((gnus-treat-decode-article-as-default-mime-charset
1096 gnus-article-decode-article-as-default-mime-charset)
1097 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1098 (gnus-treat-strip-banner gnus-article-strip-banner)
1099 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1100 (gnus-treat-buttonize gnus-article-add-buttons)
1101 (gnus-treat-fill-article gnus-article-fill-cited-article)
1102 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1103 (gnus-treat-strip-cr gnus-article-remove-cr)
1104 (gnus-treat-display-xface gnus-article-display-x-face)
1105 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1106 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1107 (gnus-treat-hide-signature gnus-article-hide-signature)
1108 (gnus-treat-hide-citation gnus-article-hide-citation)
1109 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1110 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1111 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1112 (gnus-treat-strip-pem gnus-article-hide-pem)
1113 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1114 (gnus-treat-emphasize gnus-article-emphasize)
1115 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1116 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1117 (gnus-treat-date-ut gnus-article-date-ut)
1118 (gnus-treat-date-local gnus-article-date-local)
1119 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1120 (gnus-treat-date-original gnus-article-date-original)
1121 (gnus-treat-date-user-defined gnus-article-date-user)
1122 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1123 (gnus-treat-strip-trailing-blank-lines
1124 gnus-article-remove-trailing-blank-lines)
1125 (gnus-treat-strip-leading-blank-lines
1126 gnus-article-strip-leading-blank-lines)
1127 (gnus-treat-strip-multiple-blank-lines
1128 gnus-article-strip-multiple-blank-lines)
1129 (gnus-treat-overstrike gnus-article-treat-overstrike)
1130 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1131 (gnus-treat-display-smileys gnus-article-smiley-display)
1132 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1133 (gnus-treat-display-picons gnus-article-display-picons)
1134 (gnus-treat-play-sounds gnus-earcon-display)))
1136 (defvar gnus-article-mime-handle-alist nil)
1137 (defvar article-lapsed-timer nil)
1138 (defvar gnus-article-current-summary nil)
1140 (defvar gnus-article-mode-syntax-table
1141 (let ((table (copy-syntax-table text-mode-syntax-table)))
1142 ;; This causes the citation match run O(2^n).
1143 ;; (modify-syntax-entry ?- "w" table)
1144 (modify-syntax-entry ?> ")" table)
1145 (modify-syntax-entry ?< "(" table)
1147 "Syntax table used in article mode buffers.
1148 Initialized from `text-mode-syntax-table.")
1150 (defvar gnus-save-article-buffer nil)
1152 (defvar gnus-article-mode-line-format-alist
1153 (nconc '((?w (gnus-article-wash-status) ?s)
1154 (?m (gnus-article-mime-part-status) ?s))
1155 gnus-summary-mode-line-format-alist))
1157 (defvar gnus-number-of-articles-to-be-saved nil)
1159 (defvar gnus-inhibit-hiding nil)
1161 (defsubst gnus-article-hide-text (b e props)
1162 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1163 (gnus-add-text-properties-when 'article-type nil b e props)
1164 (when (memq 'intangible props)
1166 (max (1- b) (point-min))
1167 b 'intangible (cddr (memq 'intangible props)))))
1169 (defsubst gnus-article-unhide-text (b e)
1170 "Remove hidden text properties from region between B and E."
1171 (remove-text-properties b e gnus-hidden-properties)
1172 (when (memq 'intangible gnus-hidden-properties)
1173 (put-text-property (max (1- b) (point-min))
1174 b 'intangible nil)))
1176 (defun gnus-article-hide-text-type (b e type)
1177 "Hide text of TYPE between B and E."
1178 (push type gnus-article-wash-types)
1179 (gnus-article-hide-text
1180 b e (cons 'article-type (cons type gnus-hidden-properties))))
1182 (defun gnus-article-unhide-text-type (b e type)
1183 "Unhide text of TYPE between B and E."
1184 (setq gnus-article-wash-types
1185 (delq type gnus-article-wash-types))
1186 (remove-text-properties
1187 b e (cons 'article-type (cons type gnus-hidden-properties)))
1188 (when (memq 'intangible gnus-hidden-properties)
1189 (put-text-property (max (1- b) (point-min))
1190 b 'intangible nil)))
1192 (defun gnus-article-hide-text-of-type (type)
1193 "Hide text of TYPE in the current buffer."
1195 (let ((b (point-min))
1197 (while (setq b (text-property-any b e 'article-type type))
1198 (add-text-properties b (incf b) gnus-hidden-properties)))))
1200 (defun gnus-article-delete-text-of-type (type)
1201 "Delete text of TYPE in the current buffer."
1203 (let ((b (point-min)))
1204 (while (setq b (text-property-any b (point-max) 'article-type type))
1206 b (or (text-property-not-all b (point-max) 'article-type type)
1209 (defun gnus-article-delete-invisible-text ()
1210 "Delete all invisible text in the current buffer."
1212 (let ((b (point-min)))
1213 (while (setq b (text-property-any b (point-max) 'invisible t))
1215 b (or (text-property-not-all b (point-max) 'invisible t)
1218 (defun gnus-article-text-type-exists-p (type)
1219 "Say whether any text of type TYPE exists in the buffer."
1220 (text-property-any (point-min) (point-max) 'article-type type))
1222 (defsubst gnus-article-header-rank ()
1223 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1224 (let ((list gnus-sorted-header-list)
1227 (when (looking-at (car list))
1229 (setq list (cdr list))
1233 (defun article-hide-headers (&optional arg delete)
1234 "Hide unwanted headers and possibly sort them as well."
1235 (interactive (gnus-article-hidden-arg))
1236 ;; Lars said that this function might be inhibited.
1237 (if (gnus-article-check-hidden-text 'headers arg)
1239 ;; Show boring headers as well.
1240 (gnus-article-show-hidden-text 'boring-headers)
1241 (when (eq 1 (point-min))
1242 (set-window-start (get-buffer-window (current-buffer)) 1)))
1243 (unless gnus-inhibit-hiding
1246 (let ((buffer-read-only nil)
1247 (inhibit-read-only t)
1248 (case-fold-search t)
1249 (max (1+ (length gnus-sorted-header-list)))
1250 (ignored (when (not gnus-visible-headers)
1251 (cond ((stringp gnus-ignored-headers)
1252 gnus-ignored-headers)
1253 ((listp gnus-ignored-headers)
1254 (mapconcat 'identity gnus-ignored-headers
1257 (cond ((stringp gnus-visible-headers)
1258 gnus-visible-headers)
1259 ((and gnus-visible-headers
1260 (listp gnus-visible-headers))
1261 (mapconcat 'identity gnus-visible-headers "\\|"))))
1262 (inhibit-point-motion-hooks t)
1264 ;; First we narrow to just the headers.
1265 (article-narrow-to-head)
1266 ;; Hide any "From " lines at the beginning of (mail) articles.
1267 (while (looking-at "From ")
1271 (delete-region (point-min) (point))
1272 (gnus-article-hide-text (point-min) (point)
1273 (nconc (list 'article-type 'headers)
1274 gnus-hidden-properties))))
1275 ;; Then treat the rest of the header lines.
1276 ;; Then we use the two regular expressions
1277 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1278 ;; select which header lines is to remain visible in the
1280 (while (re-search-forward "^[^ \t]*:" nil t)
1282 ;; Mark the rank of the header.
1284 (point) (1+ (point)) 'message-rank
1285 (if (or (and visible (looking-at visible))
1287 (not (looking-at ignored))))
1288 (gnus-article-header-rank)
1291 (message-sort-headers-1)
1292 (when (setq beg (text-property-any
1293 (point-min) (point-max) 'message-rank (+ 2 max)))
1294 ;; We delete or make invisible the unwanted headers.
1295 (push 'headers gnus-article-wash-types)
1298 (add-text-properties
1299 (point-min) (+ 5 (point-min))
1300 '(article-type headers dummy-invisible t))
1301 (delete-region beg (point-max)))
1302 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1305 (defun article-hide-boring-headers (&optional arg)
1306 "Toggle hiding of headers that aren't very interesting.
1307 If given a negative prefix, always show; if given a positive prefix,
1309 (interactive (gnus-article-hidden-arg))
1310 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1311 (not gnus-show-all-headers))
1314 (let ((buffer-read-only nil)
1315 (list gnus-boring-article-headers)
1316 (inhibit-point-motion-hooks t)
1318 (article-narrow-to-head)
1320 (setq elem (pop list))
1321 (goto-char (point-min))
1323 ;; Hide empty headers.
1325 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1327 (gnus-article-hide-text-type
1328 (progn (beginning-of-line) (point))
1331 (if (re-search-forward "^[^ \t]" nil t)
1335 ;; Hide boring Newsgroups header.
1336 ((eq elem 'newsgroups)
1337 (when (equal (gnus-fetch-field "newsgroups")
1338 (gnus-group-real-name
1339 (if (boundp 'gnus-newsgroup-name)
1342 (gnus-article-hide-header "newsgroups")))
1343 ((eq elem 'followup-to)
1344 (when (equal (message-fetch-field "followup-to")
1345 (message-fetch-field "newsgroups"))
1346 (gnus-article-hide-header "followup-to")))
1347 ((eq elem 'reply-to)
1348 (let ((from (message-fetch-field "from"))
1349 (reply-to (message-fetch-field "reply-to")))
1354 (nth 1 (funcall gnus-extract-address-components from))
1355 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1356 (gnus-article-hide-header "reply-to"))))
1358 (let ((date (message-fetch-field "date")))
1360 (< (days-between (current-time-string) date)
1362 (gnus-article-hide-header "date"))))
1364 (let ((to (message-fetch-field "to"))
1365 (cc (message-fetch-field "cc")))
1366 (when (> (length to) 1024)
1367 (gnus-article-hide-header "to"))
1368 (when (> (length cc) 1024)
1369 (gnus-article-hide-header "cc"))))
1373 (goto-char (point-min))
1374 (while (re-search-forward "^to:" nil t)
1375 (setq to-count (1+ to-count)))
1376 (when (> to-count 1)
1377 (while (> to-count 0)
1378 (goto-char (point-min))
1380 (re-search-forward "^to:" nil nil to-count)
1382 (narrow-to-region (point) (point-max))
1383 (gnus-article-hide-header "to"))
1384 (setq to-count (1- to-count))))
1385 (goto-char (point-min))
1386 (while (re-search-forward "^cc:" nil t)
1387 (setq cc-count (1+ cc-count)))
1388 (when (> cc-count 1)
1389 (while (> cc-count 0)
1390 (goto-char (point-min))
1392 (re-search-forward "^cc:" nil nil cc-count)
1394 (narrow-to-region (point) (point-max))
1395 (gnus-article-hide-header "cc"))
1396 (setq cc-count (1- cc-count)))))))))))))
1398 (defun gnus-article-hide-header (header)
1400 (goto-char (point-min))
1401 (when (re-search-forward (concat "^" header ":") nil t)
1402 (gnus-article-hide-text-type
1403 (progn (beginning-of-line) (point))
1406 (if (re-search-forward "^[^ \t]" nil t)
1411 (defun article-toggle-headers (&optional arg)
1412 "Toggle hiding of headers. If given a negative prefix, always show;
1413 if given a positive prefix, always hide."
1414 (interactive (gnus-article-hidden-arg))
1415 (let ((force (when (numberp arg)
1416 (cond ((> arg 0) 'always-hide)
1417 ((< arg 0) 'always-show))))
1418 (window (get-buffer-window gnus-article-buffer))
1419 (header-end (point-min))
1420 header-start field-end field-start
1421 (inhibit-point-motion-hooks t)
1422 (inhibit-read-only t)
1426 (while (and (setq header-start
1427 (text-property-any header-end (point-max)
1428 'article-treated-header t))
1430 (text-property-not-all header-start (point-max)
1431 'article-treated-header t)))
1432 (setq field-end header-start)
1434 (;; Hide exposed invisible fields.
1435 (and (not (eq 'always-show force))
1437 (text-property-any field-end header-end
1438 'exposed-invisible-field t)))
1439 (while (and field-start
1440 (setq field-end (text-property-not-all
1441 field-start header-end
1442 'exposed-invisible-field t)))
1443 (add-text-properties field-start field-end gnus-hidden-properties)
1444 (setq field-start (text-property-any field-end header-end
1445 'exposed-invisible-field t)))
1446 (put-text-property header-start header-end
1447 'exposed-invisible-field nil))
1448 (;; Expose invisible fields.
1449 (and (not (eq 'always-hide force))
1451 (text-property-any field-end header-end 'invisible t)))
1452 (while (and field-start
1453 (setq field-end (text-property-not-all
1454 field-start header-end
1456 ;; If the invisible text is not terminated with newline, we
1457 ;; won't expose it. Because it may be created by x-face-mule.
1458 ;; BTW, XEmacs sometimes fail in putting a invisible text
1459 ;; property with `gnus-article-hide-text' (really?). In that
1460 ;; case, the invisible text might be started from the middle of
1461 ;; a line so we will expose the sort of thing.
1462 (when (or (not (or (eq header-start field-start)
1463 (eq ?\n (char-before field-start))))
1464 (eq ?\n (char-before field-end)))
1465 (remove-text-properties field-start field-end
1466 gnus-hidden-properties)
1467 (put-text-property field-start field-end
1468 'exposed-invisible-field t))
1469 (setq field-start (text-property-any field-end header-end
1472 (not (eq 'always-show force))
1473 (narrow-to-region header-start header-end)
1474 (article-hide-headers)
1475 ;; Re-display X-Face image under XEmacs.
1476 (when (and (featurep 'xemacs)
1477 (gnus-functionp gnus-article-x-face-command))
1478 (let ((func (cadr (assq 'gnus-treat-display-xface
1479 gnus-treatment-function-alist)))
1481 (when (and (not gnus-inhibit-treatment)
1483 (gnus-treat-predicate gnus-treat-display-xface))
1485 (put-text-property header-start header-end 'read-only nil))))
1488 (goto-char (point-min))
1490 (set-window-start window (point-min))))))
1492 (defvar gnus-article-normalized-header-length 40
1493 "Length of normalized headers.")
1495 (defun article-normalize-headers ()
1496 "Make all header lines 40 characters long."
1498 (let ((buffer-read-only nil)
1502 (article-narrow-to-head)
1505 ((< (setq column (- (gnus-point-at-eol) (point)))
1506 gnus-article-normalized-header-length)
1508 (insert (make-string
1509 (- gnus-article-normalized-header-length column)
1511 ((> column gnus-article-normalized-header-length)
1512 (gnus-put-text-property
1514 (forward-char gnus-article-normalized-header-length)
1521 (forward-line 1))))))
1523 (defun article-treat-dumbquotes ()
1524 "Translate M******** sm*rtq**t*s into proper text.
1525 Note that this function guesses whether a character is a sm*rtq**t* or
1526 not, so it should only be used interactively."
1528 (article-translate-strings gnus-article-dumbquotes-map))
1530 (defun article-translate-characters (from to)
1531 "Translate all characters in the body of the article according to FROM and TO.
1532 FROM is a string of characters to translate from; to is a string of
1533 characters to translate to."
1535 (when (article-goto-body)
1536 (let ((buffer-read-only nil)
1537 (x (make-string 225 ?x))
1539 (while (< (incf i) (length x))
1542 (while (< i (length from))
1543 (aset x (aref from i) (aref to i))
1545 (translate-region (point) (point-max) x)))))
1547 (defun article-translate-strings (map)
1548 "Translate all string in the body of the article according to MAP.
1549 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1551 (when (article-goto-body)
1552 (let ((buffer-read-only nil)
1554 (while (setq elem (pop map))
1556 (while (search-forward (car elem) nil t)
1557 (replace-match (cadr elem)))))))))
1559 (defun article-treat-overstrike ()
1560 "Translate overstrikes into bold text."
1563 (when (article-goto-body)
1564 (let ((buffer-read-only nil))
1565 (while (search-forward "\b" nil t)
1566 (let ((next (char-after))
1570 previous (char-after))
1574 ;; We do the boldification/underlining by hiding the
1575 ;; overstrikes and putting the proper text property
1579 (gnus-article-hide-text-type start (point) 'overstrike)
1580 (put-text-property (point) end 'face 'bold))
1582 (gnus-article-hide-text-type
1583 (1- (point)) (1+ (point)) 'overstrike)
1585 start (1- (point)) 'face 'underline))
1587 (gnus-article-hide-text-type start (point) 'overstrike)
1589 (point) end 'face 'underline)))))))))
1591 (defun article-fill-long-lines ()
1592 "Fill lines that are wider than the window width."
1595 (let ((buffer-read-only nil)
1596 (width (window-width (get-buffer-window (current-buffer)))))
1599 (let ((adaptive-fill-mode nil))
1602 (when (>= (current-column) (min fill-column width))
1603 (narrow-to-region (point) (gnus-point-at-bol))
1604 (fill-paragraph nil)
1605 (goto-char (point-max))
1607 (forward-line 1)))))))
1609 (defun article-capitalize-sentences ()
1610 "Capitalize the first word in each sentence."
1613 (let ((buffer-read-only nil)
1614 (paragraph-start "^[\n\^L]"))
1618 (forward-sentence)))))
1620 (defun article-remove-cr ()
1621 "Remove trailing CRs and then translate remaining CRs into LFs."
1624 (let ((buffer-read-only nil))
1625 (goto-char (point-min))
1626 (while (re-search-forward "\r+$" nil t)
1627 (replace-match "" t t))
1628 (goto-char (point-min))
1629 (while (search-forward "\r" nil t)
1630 (replace-match "\n" t t)))))
1632 (defun article-remove-trailing-blank-lines ()
1633 "Remove all trailing blank lines from the article."
1636 (let ((buffer-read-only nil))
1637 (goto-char (point-max))
1641 (while (and (not (bobp))
1642 (looking-at "^[ \t]*$")
1643 (not (gnus-annotation-in-region-p
1644 (point) (gnus-point-at-eol))))
1649 (defun article-display-x-face (&optional force)
1650 "Look for an X-Face header and display it if present."
1651 (interactive (list 'force))
1653 ;; Delete the old process, if any.
1654 (when (process-status "article-x-face")
1655 (delete-process "article-x-face"))
1656 (let ((inhibit-point-motion-hooks t)
1657 (case-fold-search t)
1660 (article-narrow-to-head)
1661 (goto-char (point-min))
1662 (setq from (message-fetch-field "from"))
1663 (goto-char (point-min))
1664 (while (and gnus-article-x-face-command
1667 ;; Check whether this face is censored.
1668 (not gnus-article-x-face-too-ugly)
1669 (and gnus-article-x-face-too-ugly from
1670 (not (string-match gnus-article-x-face-too-ugly
1672 ;; Has to be present.
1673 (re-search-forward "^X-Face:[ \t]*" nil t))
1674 ;; This used to try to do multiple faces (`while' instead of
1675 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1676 ;; work (b) it can crash some versions of Emacs (c) are
1677 ;; multiple faces really something to encourage?
1678 (when (stringp gnus-article-x-face-command)
1680 ;; We now have the area of the buffer where the X-Face is stored.
1683 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1684 ;; We display the face.
1685 (if (symbolp gnus-article-x-face-command)
1686 ;; The command is a lisp function, so we call it.
1687 (if (gnus-functionp gnus-article-x-face-command)
1688 (funcall gnus-article-x-face-command beg end)
1689 (error "%s is not a function" gnus-article-x-face-command))
1690 ;; The command is a string, so we interpret the command
1691 ;; as a, well, command, and fork it off.
1692 (let ((process-connection-type nil))
1693 (process-kill-without-query
1695 "article-x-face" nil shell-file-name shell-command-switch
1696 gnus-article-x-face-command))
1697 (process-send-region "article-x-face" beg end)
1698 (process-send-eof "article-x-face"))))))))))
1700 (defun article-decode-mime-words ()
1701 "Decode all MIME-encoded words in the article."
1704 (set-buffer gnus-article-buffer)
1705 (let ((inhibit-point-motion-hooks t)
1707 (mail-parse-charset gnus-newsgroup-charset)
1708 (mail-parse-ignored-charsets
1709 (save-excursion (set-buffer gnus-summary-buffer)
1710 gnus-newsgroup-ignored-charsets)))
1711 (mail-decode-encoded-word-region (point-min) (point-max)))))
1713 (defun article-decode-charset (&optional prompt)
1714 "Decode charset-encoded text in the article.
1715 If PROMPT (the prefix), prompt for a coding system to use."
1717 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1719 (mail-parse-charset gnus-newsgroup-charset)
1720 (mail-parse-ignored-charsets
1721 (save-excursion (condition-case nil
1722 (set-buffer gnus-summary-buffer)
1724 gnus-newsgroup-ignored-charsets))
1725 ct cte ctl charset format)
1728 (article-narrow-to-head)
1729 (setq ct (message-fetch-field "Content-Type" t)
1730 cte (message-fetch-field "Content-Transfer-Encoding" t)
1731 ctl (and ct (ignore-errors
1732 (mail-header-parse-content-type ct)))
1735 (mm-read-coding-system "Charset to decode: "))
1737 (mail-content-type-get ctl 'charset)))
1738 format (and ctl (mail-content-type-get ctl 'format)))
1740 (setq cte (mail-header-strip cte)))
1741 (if (and ctl (not (string-match "/" (car ctl))))
1743 (goto-char (point-max)))
1746 (narrow-to-region (point) (point-max))
1747 (when (and (eq mail-parse-charset 'gnus-decoded)
1748 (eq (mm-body-7-or-8) '8bit))
1749 ;; The text code could have been decoded.
1750 (setq charset mail-parse-charset))
1751 (when (and (or (not ctl)
1752 (equal (car ctl) "text/plain"))
1753 (not format)) ;; article with format will decode later.
1755 charset (and cte (intern (downcase
1756 (gnus-strip-whitespace cte))))
1759 (defun article-decode-encoded-words ()
1760 "Remove encoded-word encoding from headers."
1761 (let (buffer-read-only)
1762 (let ((charset (save-excursion
1763 (set-buffer gnus-summary-buffer)
1764 default-mime-charset)))
1765 (mime-decode-header-in-buffer charset)
1768 (defun article-de-quoted-unreadable (&optional force)
1769 "Translate a quoted-printable-encoded article.
1770 If FORCE, decode the article whether it is marked as quoted-printable
1772 (interactive (list 'force))
1774 (let ((buffer-read-only nil) type charset)
1775 (if (gnus-buffer-live-p gnus-original-article-buffer)
1776 (with-current-buffer gnus-original-article-buffer
1778 (gnus-fetch-field "content-transfer-encoding"))
1779 (let* ((ct (gnus-fetch-field "content-type"))
1782 (mail-header-parse-content-type ct)))))
1783 (setq charset (and ctl
1784 (mail-content-type-get ctl 'charset)))
1785 (if (stringp charset)
1786 (setq charset (intern (downcase charset)))))))
1788 (setq charset gnus-newsgroup-charset))
1790 (and type (let ((case-fold-search t))
1791 (string-match "quoted-printable" type))))
1793 (quoted-printable-decode-region
1794 (point) (point-max) (mm-charset-to-coding-system charset))))))
1796 (defun article-de-base64-unreadable (&optional force)
1797 "Translate a base64 article.
1798 If FORCE, decode the article whether it is marked as base64 not."
1799 (interactive (list 'force))
1801 (let ((buffer-read-only nil) type charset)
1802 (if (gnus-buffer-live-p gnus-original-article-buffer)
1803 (with-current-buffer gnus-original-article-buffer
1805 (gnus-fetch-field "content-transfer-encoding"))
1806 (let* ((ct (gnus-fetch-field "content-type"))
1809 (mail-header-parse-content-type ct)))))
1810 (setq charset (and ctl
1811 (mail-content-type-get ctl 'charset)))
1812 (if (stringp charset)
1813 (setq charset (intern (downcase charset)))))))
1815 (setq charset gnus-newsgroup-charset))
1817 (and type (let ((case-fold-search t))
1818 (string-match "base64" type))))
1821 (narrow-to-region (point) (point-max))
1822 (base64-decode-region (point-min) (point-max))
1823 (mm-decode-coding-region
1824 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1829 (defun article-decode-HZ ()
1830 "Translate a HZ-encoded article."
1834 (let ((buffer-read-only nil))
1835 (rfc1843-decode-region (point-min) (point-max)))))
1837 (defun article-wash-html ()
1838 "Format an html article."
1841 (let ((buffer-read-only nil)
1843 (if (gnus-buffer-live-p gnus-original-article-buffer)
1844 (with-current-buffer gnus-original-article-buffer
1845 (let* ((ct (gnus-fetch-field "content-type"))
1848 (mail-header-parse-content-type ct)))))
1849 (setq charset (and ctl
1850 (mail-content-type-get ctl 'charset)))
1851 (if (stringp charset)
1852 (setq charset (intern (downcase charset)))))))
1854 (setq charset gnus-newsgroup-charset))
1856 (save-window-excursion
1858 (narrow-to-region (point) (point-max))
1860 (let ((w3-strict-width (window-width))
1861 (url-standalone-mode t))
1863 (w3-region (point-min) (point-max))
1866 (defun article-hide-list-identifiers ()
1867 "Remove list identifies from the Subject header.
1868 The `gnus-list-identifiers' variable specifies what to do."
1872 (let ((inhibit-point-motion-hooks t)
1874 (article-narrow-to-head)
1875 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1876 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1878 (goto-char (point-min))
1879 (when (re-search-forward
1880 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1881 " *\\)\\)+\\(Re: +\\)?\\)")
1883 (let ((s (or (match-string 3) (match-string 5))))
1884 (delete-region (match-beginning 1) (match-end 1))
1886 (goto-char (match-beginning 1))
1889 (defun article-hide-pgp ()
1890 "Remove any PGP headers and signatures in the current article."
1894 (let ((inhibit-point-motion-hooks t)
1895 buffer-read-only beg end)
1897 ;; Hide the "header".
1898 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1899 (push 'pgp gnus-article-wash-types)
1900 (delete-region (match-beginning 0) (match-end 0))
1901 ;; Remove armor headers (rfc2440 6.2)
1902 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1905 ;; Hide the actual signature.
1906 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1907 (setq end (1+ (match-beginning 0)))
1910 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1912 ;; Perhaps we shouldn't hide to the end of the buffer
1913 ;; if there is no end to the signature?
1915 ;; Hide "- " PGP quotation markers.
1917 (narrow-to-region beg end)
1918 (goto-char (point-min))
1919 (while (re-search-forward "^- " nil t)
1921 (match-beginning 0) (match-end 0)))
1923 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1925 (defun article-hide-pem (&optional arg)
1926 "Toggle hiding of any PEM headers and signatures in the current article.
1927 If given a negative prefix, always show; if given a positive prefix,
1929 (interactive (gnus-article-hidden-arg))
1930 (unless (gnus-article-check-hidden-text 'pem arg)
1932 (let (buffer-read-only end)
1933 (goto-char (point-min))
1934 ;; Hide the horrendously ugly "header".
1935 (when (and (search-forward
1936 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1938 (setq end (1+ (match-beginning 0))))
1939 (push 'pem gnus-article-wash-types)
1940 (gnus-article-hide-text-type
1942 (if (search-forward "\n\n" nil t)
1946 ;; Hide the trailer as well
1947 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1949 (gnus-article-hide-text-type
1950 (match-beginning 0) (match-end 0) 'pem)))))))
1952 (defun article-strip-banner ()
1953 "Strip the banner specified by the `banner' group parameter."
1957 (let ((inhibit-point-motion-hooks t)
1958 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1959 (gnus-signature-limit nil)
1960 buffer-read-only beg end)
1964 ((eq banner 'signature)
1965 (when (gnus-article-narrow-to-signature)
1968 (delete-region (point) (point-max))))
1970 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1971 (while (re-search-forward banner nil t)
1972 (delete-region (match-beginning 0) (match-end 0)))))
1974 (while (re-search-forward banner nil t)
1975 (delete-region (match-beginning 0) (match-end 0))))))))))
1977 (defun article-babel ()
1978 "Translate article using an online translation service."
1982 (set-buffer gnus-article-buffer)
1983 (when (article-goto-body)
1984 (let* ((buffer-read-only nil)
1987 (orig (buffer-substring start end))
1988 (trans (babel-as-string orig)))
1990 (narrow-to-region start end)
1991 (delete-region start end)
1994 (defun article-hide-signature (&optional arg)
1995 "Hide the signature in the current article.
1996 If given a negative prefix, always show; if given a positive prefix,
1998 (interactive (gnus-article-hidden-arg))
2004 (article-goto-body))
2005 (goto-char (point-min)))
2006 (unless (gnus-article-check-hidden-text 'signature arg)
2007 (let ((buffer-read-only nil)
2009 (while (setq button (text-property-any button (point-max)
2011 'gnus-signature-toggle))
2012 (setq button (text-property-not-all button (point-max)
2014 'gnus-signature-toggle))
2015 (when (and button (not (eobp)))
2016 (gnus-article-hide-text-type
2018 (next-single-property-change (1+ button) 'mime-view-entity
2022 (defun article-strip-headers-in-body ()
2023 "Strip offensive headers from bodies."
2027 (let ((case-fold-search t))
2028 (when (looking-at "x-no-archive:")
2029 (gnus-delete-line)))))
2031 (defun article-strip-leading-blank-lines ()
2032 "Remove all blank lines from the beginning of the article."
2035 (let ((inhibit-point-motion-hooks t)
2037 (when (article-goto-body)
2038 (while (and (not (eobp))
2039 (looking-at "[ \t]*$"))
2040 (gnus-delete-line))))))
2042 (defun article-narrow-to-head ()
2043 "Narrow the buffer to the head of the message.
2044 Point is left at the beginning of the narrowed-to region."
2046 (goto-char (point-min))
2047 (if (search-forward "\n\n" nil 1)
2050 (goto-char (point-min)))
2052 (defun article-goto-body ()
2053 "Place point at the start of the body."
2054 (goto-char (point-min))
2056 ;; This variable is only bound when dealing with separate
2058 (article-goto-body-goes-to-point-min-p
2060 ((search-forward "\n\n" nil t)
2063 (goto-char (point-max))
2066 (defun article-strip-multiple-blank-lines ()
2067 "Replace consecutive blank lines with one empty line."
2070 (let ((inhibit-point-motion-hooks t)
2072 ;; First make all blank lines empty.
2074 (while (re-search-forward "^[ \t]+$" nil t)
2075 (unless (gnus-annotation-in-region-p
2076 (match-beginning 0) (match-end 0))
2077 (replace-match "" nil t)))
2078 ;; Then replace multiple empty lines with a single empty line.
2080 (while (re-search-forward "\n\n\n+" nil t)
2081 (unless (gnus-annotation-in-region-p
2082 (match-beginning 0) (match-end 0))
2083 (replace-match "\n\n" t t))))))
2085 (defun article-strip-leading-space ()
2086 "Remove all white space from the beginning of the lines in the article."
2089 (let ((inhibit-point-motion-hooks t)
2092 (while (re-search-forward "^[ \t]+" nil t)
2093 (replace-match "" t t)))))
2095 (defun article-strip-trailing-space ()
2096 "Remove all white space from the end of the lines in the article."
2099 (let ((inhibit-point-motion-hooks t)
2102 (while (re-search-forward "[ \t]+$" nil t)
2103 (replace-match "" t t)))))
2105 (defun article-strip-blank-lines ()
2106 "Strip leading, trailing and multiple blank lines."
2108 (article-strip-leading-blank-lines)
2109 (article-remove-trailing-blank-lines)
2110 (article-strip-multiple-blank-lines))
2112 (defun article-strip-all-blank-lines ()
2113 "Strip all blank lines."
2116 (let ((inhibit-point-motion-hooks t)
2119 (while (re-search-forward "^[ \t]*\n" nil t)
2120 (replace-match "" t t)))))
2122 (defun gnus-article-narrow-to-signature ()
2123 "Narrow to the signature; return t if a signature is found, else nil."
2124 (let ((inhibit-point-motion-hooks t))
2125 (when (gnus-article-search-signature)
2127 ;; Check whether we have some limits to what we consider
2128 ;; to be a signature.
2129 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2130 (list gnus-signature-limit)))
2132 (while (setq limit (pop limits))
2133 (if (or (and (integerp limit)
2134 (< (- (point-max) (point)) limit))
2136 (< (count-lines (point) (point-max)) limit))
2137 (and (gnus-functionp limit)
2139 (and (stringp limit)
2140 (not (re-search-forward limit nil t))))
2141 () ; This limit did not succeed.
2145 (narrow-to-region (point) (point-max))
2148 (defun gnus-article-search-signature ()
2149 "Search the current buffer for the signature separator.
2150 Put point at the beginning of the signature separator."
2151 (let ((cur (point)))
2152 (goto-char (point-max))
2153 (if (if (stringp gnus-signature-separator)
2154 (re-search-backward gnus-signature-separator nil t)
2155 (let ((seps gnus-signature-separator))
2157 (not (re-search-backward (car seps) nil t)))
2164 (defun gnus-article-hidden-arg ()
2165 "Return the current prefix arg as a number, or 0 if no prefix."
2166 (list (if current-prefix-arg
2167 (prefix-numeric-value current-prefix-arg)
2170 (defun gnus-article-check-hidden-text (type arg)
2171 "Return nil if hiding is necessary.
2172 Arg can be nil or a number. Nil and positive means hide, negative
2173 means show, 0 means toggle."
2176 (let ((hide (gnus-article-hidden-text-p type)))
2182 (gnus-article-show-hidden-text type))
2184 (if (eq hide 'hidden)
2185 (gnus-article-show-hidden-text type)
2188 (defun gnus-article-hidden-text-p (type)
2189 "Say whether the current buffer contains hidden text of type TYPE."
2190 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2192 (not (get-text-property pos 'invisible))
2193 (not (get-text-property pos 'dummy-invisible)))
2195 (text-property-any (1+ pos) (point-max) 'article-type type)))
2200 (defun gnus-article-show-hidden-text (type &optional dummy)
2201 "Show all hidden text of type TYPE.
2202 Originally it is hide instead of DUMMY."
2203 (let ((buffer-read-only nil)
2204 (inhibit-point-motion-hooks t))
2205 (gnus-remove-text-properties-when
2207 (point-min) (point-max)
2208 (cons 'article-type (cons type
2209 gnus-hidden-properties)))))
2211 (defconst article-time-units
2212 `((year . ,(* 365.25 24 60 60))
2213 (week . ,(* 7 24 60 60))
2214 (day . ,(* 24 60 60))
2218 "Mapping from time units to seconds.")
2220 (defun article-date-ut (&optional type highlight header)
2221 "Convert DATE date to universal time in the current article.
2222 If TYPE is `local', convert to local time; if it is `lapsed', output
2223 how much time has lapsed since DATE. For `lapsed', the value of
2224 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2225 should replace the \"Date:\" one, or should be added below it."
2226 (interactive (list 'ut t))
2227 (let* ((header (or header
2228 (and (eq 1 (point-min))
2229 (mail-header-date (save-excursion
2230 (set-buffer gnus-summary-buffer)
2231 gnus-current-headers)))
2232 (message-fetch-field "date")
2234 (date (if (vectorp header) (mail-header-date header)
2236 (inhibit-point-motion-hooks t)
2237 bface eface date-pos)
2238 (when (and date (not (string= date "")))
2241 (article-narrow-to-head)
2242 (when (or (and (eq type 'lapsed)
2243 gnus-article-date-lapsed-new-header
2244 ;; Attempt to get the face of X-Sent first.
2245 (re-search-forward "^X-Sent:[ \t]" nil t))
2246 (re-search-forward "^Date:[ \t]" nil t)
2247 ;; If Date is missing, try again for X-Sent.
2248 (re-search-forward "^X-Sent:[ \t]" nil t))
2249 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2250 date (or (get-text-property (gnus-point-at-bol)
2253 eface (get-text-property (1- (gnus-point-at-eol))
2255 (let ((buffer-read-only nil))
2256 ;; Delete any old X-Sent headers.
2257 (when (setq date-pos
2258 (text-property-any (point-min) (point-max)
2259 'article-date-lapsed t))
2260 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2261 (delete-region (match-beginning 0)
2262 (progn (forward-line 1) (point))))
2263 (goto-char (point-min))
2264 ;; Delete any old Date headers.
2265 (while (re-search-forward "^Date:[ \t]" nil t)
2267 (setq date-pos (match-beginning 0)))
2268 (unless (and (eq type 'lapsed)
2269 gnus-article-date-lapsed-new-header)
2270 (delete-region (match-beginning 0)
2271 (progn (message-next-header) (point)))))
2274 (goto-char date-pos)
2276 ;; Possibly, Date has been deleted.
2278 (when (and (eq type 'lapsed)
2279 gnus-article-date-lapsed-new-header
2280 (looking-at "Date:"))
2282 (goto-char (point-min)))
2283 (insert (article-make-date-line date type))
2284 (when (eq type 'lapsed)
2285 (put-text-property (gnus-point-at-bol) (point)
2286 'article-date-lapsed t))
2290 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2291 (put-text-property (match-beginning 1) (1+ (match-end 1))
2292 'original-date date)
2293 (put-text-property (match-beginning 1) (1+ (match-end 1))
2295 (put-text-property (match-beginning 2) (match-end 2)
2298 (defun article-make-date-line (date type)
2299 "Return a DATE line of TYPE."
2300 (let ((time (condition-case ()
2304 ;; Convert to the local timezone. We have to slap a
2305 ;; `condition-case' round the calls to the timezone
2306 ;; functions since they aren't particularly resistant to
2309 (let ((tz (car (current-time-zone time))))
2310 (format "Date: %s %s%02d%02d" (current-time-string time)
2311 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2312 (/ (% (abs tz) 3600) 60))))
2313 ;; Convert to Universal Time.
2316 (current-time-string
2317 (let* ((e (parse-time-string date))
2318 (tm (apply 'encode-time e))
2320 (ls (- (cadr tm) (car (current-time-zone time)))))
2321 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2322 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2325 ;; Get the original date from the article.
2326 ((eq type 'original)
2327 (concat "Date: " (if (string-match "\n+$" date)
2328 (substring date 0 (match-beginning 0))
2330 ;; Let the user define the format.
2332 (if (gnus-functionp gnus-article-time-format)
2333 (funcall gnus-article-time-format time)
2336 (format-time-string gnus-article-time-format time))))
2339 (let ((tz (car (current-time-zone time))))
2342 (format-time-string "%Y%m%dT%H%M%S" time)
2343 (format "%s%02d%02d"
2344 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2345 (/ (% (abs tz) 3600) 60)))))
2346 ;; Do an X-Sent lapsed format.
2348 ;; If the date is seriously mangled, the timezone functions are
2349 ;; liable to bug out, so we ignore all errors.
2350 (let* ((now (current-time))
2351 (real-time (subtract-time now time))
2352 (real-sec (and real-time
2353 (+ (* (float (car real-time)) 65536)
2355 (sec (and real-time (abs real-sec)))
2365 ;; This is a bit convoluted, but basically we go
2366 ;; through the time units for years, weeks, etc,
2367 ;; and divide things to see whether that results
2368 ;; in positive answers.
2371 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2372 ;; The (remaining) seconds are too few to
2373 ;; be divided into this time unit.
2375 ;; It's big enough, so we output it.
2376 (setq sec (- sec (* num (cdr unit))))
2378 (concat (if prev ", " "") (int-to-string
2380 " " (symbol-name (car unit))
2381 (if (> num 1) "s" ""))
2383 article-time-units "")
2384 ;; If dates are odd, then it might appear like the
2385 ;; article was sent in the future.
2388 " in the future"))))))
2390 (error "Unknown conversion type: %s" type)))))
2392 (defun article-date-local (&optional highlight)
2393 "Convert the current article date to the local timezone."
2394 (interactive (list t))
2395 (article-date-ut 'local highlight))
2397 (defun article-date-original (&optional highlight)
2398 "Convert the current article date to what it was originally.
2399 This is only useful if you have used some other date conversion
2400 function and want to see what the date was before converting."
2401 (interactive (list t))
2402 (article-date-ut 'original highlight))
2404 (defun article-date-lapsed (&optional highlight)
2405 "Convert the current article date to time lapsed since it was sent."
2406 (interactive (list t))
2407 (article-date-ut 'lapsed highlight))
2409 (defun article-update-date-lapsed ()
2410 "Function to be run from a timer to update the lapsed time line."
2411 (let (deactivate-mark)
2416 (set-buffer (window-buffer w))
2417 (when (eq major-mode 'gnus-article-mode)
2418 (goto-char (point-min))
2419 (when (re-search-forward "^X-Sent:" nil t)
2420 (article-date-lapsed t))))
2423 (defun gnus-start-date-timer (&optional n)
2424 "Start a timer to update the X-Sent header in the article buffers.
2425 The numerical prefix says how frequently (in seconds) the function
2430 (gnus-stop-date-timer)
2431 (setq article-lapsed-timer
2432 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2434 (defun gnus-stop-date-timer ()
2435 "Stop the X-Sent timer."
2437 (when article-lapsed-timer
2438 (nnheader-cancel-timer article-lapsed-timer)
2439 (setq article-lapsed-timer nil)))
2441 (defun article-date-user (&optional highlight)
2442 "Convert the current article date to the user-defined format.
2443 This format is defined by the `gnus-article-time-format' variable."
2444 (interactive (list t))
2445 (article-date-ut 'user highlight))
2447 (defun article-date-iso8601 (&optional highlight)
2448 "Convert the current article date to ISO8601."
2449 (interactive (list t))
2450 (article-date-ut 'iso8601 highlight))
2452 (defun article-show-all ()
2453 "Show all hidden text in the article buffer."
2457 (let ((buffer-read-only nil))
2458 (gnus-article-unhide-text (point-min) (point-max))
2459 (gnus-remove-text-with-property 'gnus-prev)
2460 (gnus-remove-text-with-property 'gnus-next))))
2462 (defun article-show-all-headers ()
2463 "Show all hidden headers in the article buffer."
2468 (article-narrow-to-head)
2469 (let ((buffer-read-only nil))
2470 (gnus-article-unhide-text (point-min) (point-max))))))
2472 (defun article-emphasize (&optional arg)
2473 "Emphasize text according to `gnus-emphasis-alist'."
2474 (interactive (gnus-article-hidden-arg))
2475 (unless (gnus-article-check-hidden-text 'emphasis arg)
2479 (with-current-buffer gnus-summary-buffer
2480 gnus-article-emphasis-alist)
2482 gnus-emphasis-alist))
2483 (buffer-read-only nil)
2484 (props (append '(article-type emphasis)
2485 gnus-hidden-properties))
2486 regexp elem beg invisible visible face)
2489 (while (setq elem (pop alist))
2491 (setq regexp (car elem)
2492 invisible (nth 1 elem)
2493 visible (nth 2 elem)
2495 (while (re-search-forward regexp nil t)
2496 (when (and (match-beginning visible) (match-beginning invisible))
2497 (push 'emphasis gnus-article-wash-types)
2498 (gnus-article-hide-text
2499 (match-beginning invisible) (match-end invisible) props)
2500 (gnus-article-unhide-text-type
2501 (match-beginning visible) (match-end visible) 'emphasis)
2502 (gnus-put-text-property-excluding-newlines
2503 (match-beginning visible) (match-end visible) 'face face)
2504 (goto-char (match-end invisible)))))))))
2506 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2507 "Setup newsgroup emphasis alist."
2508 (unless gnus-article-emphasis-alist
2509 (let ((name (and gnus-newsgroup-name
2510 (gnus-group-real-name gnus-newsgroup-name))))
2511 (make-local-variable 'gnus-article-emphasis-alist)
2512 (setq gnus-article-emphasis-alist
2514 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2515 (while (setq elem (pop alist))
2516 (when (and name (string-match (car elem) name))
2518 highlight (copy-sequence (cdr elem)))))
2520 (copy-sequence highlight-words)
2521 (if gnus-newsgroup-name
2522 (copy-sequence (gnus-group-find-parameter
2523 gnus-newsgroup-name 'highlight-words t)))
2524 gnus-emphasis-alist)))))
2526 (defvar gnus-summary-article-menu)
2527 (defvar gnus-summary-post-menu)
2529 ;;; Saving functions.
2531 (defun gnus-article-save (save-buffer file &optional num)
2532 "Save the currently selected article."
2533 (unless gnus-save-all-headers
2534 ;; Remove headers according to `gnus-saved-headers'.
2535 (let ((gnus-visible-headers
2536 (or gnus-saved-headers gnus-visible-headers))
2537 (gnus-article-buffer save-buffer))
2539 (set-buffer save-buffer)
2540 (article-hide-headers 1 t))))
2541 (save-window-excursion
2542 (if (not gnus-default-article-saver)
2543 (error "No default saver is defined")
2544 ;; !!! Magic! The saving functions all save
2545 ;; `gnus-save-article-buffer' (or so they think), but we
2546 ;; bind that variable to our save-buffer.
2547 (set-buffer gnus-article-buffer)
2548 (let* ((gnus-save-article-buffer save-buffer)
2551 ((not gnus-prompt-before-saving) 'default)
2552 ((eq gnus-prompt-before-saving 'always) nil)
2554 (gnus-number-of-articles-to-be-saved
2555 (when (eq gnus-prompt-before-saving t)
2557 (set-buffer gnus-article-current-summary)
2558 (funcall gnus-default-article-saver filename)))))
2560 (defun gnus-read-save-file-name (prompt &optional filename
2561 function group headers variable)
2563 (funcall function group headers (symbol-value variable)))
2568 ((eq filename 'default)
2574 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2577 (if (and gnus-number-of-articles-to-be-saved
2578 (> gnus-number-of-articles-to-be-saved 1))
2579 (format "these %d articles"
2580 gnus-number-of-articles-to-be-saved)
2583 ;; Let the split methods have their say.
2585 ;; No split name was found.
2588 (concat prompt " (default "
2589 (file-name-nondirectory default-name) ") ")
2590 (file-name-directory default-name)
2592 ;; A single group name is returned.
2593 ((stringp split-name)
2595 (funcall function split-name headers
2596 (symbol-value variable)))
2598 (concat prompt " (default "
2599 (file-name-nondirectory default-name) ") ")
2600 (file-name-directory default-name)
2602 ;; A single split name was found
2603 ((= 1 (length split-name))
2604 (let* ((name (expand-file-name
2606 gnus-article-save-directory))
2607 (dir (cond ((file-directory-p name)
2608 (file-name-as-directory name))
2609 ((file-exists-p name) name)
2610 (t gnus-article-save-directory))))
2612 (concat prompt " (default " name ") ")
2614 ;; A list of splits was found.
2616 (setq split-name (nreverse split-name))
2618 (let ((file-name-history
2619 (nconc split-name file-name-history)))
2623 (concat prompt " (`M-p' for defaults) ")
2624 gnus-article-save-directory
2626 gnus-article-save-directory)))
2627 (car (push result file-name-history)))))))
2628 ;; Create the directory.
2629 (gnus-make-directory (file-name-directory file))
2630 ;; If we have read a directory, we append the default file name.
2631 (when (file-directory-p file)
2632 (setq file (expand-file-name (file-name-nondirectory
2634 (file-name-as-directory file))))
2635 ;; Possibly translate some characters.
2636 (nnheader-translate-file-chars file))))))
2637 (gnus-make-directory (file-name-directory result))
2638 (set variable result)))
2640 (defun gnus-article-archive-name (group)
2641 "Return the first instance of an \"Archive-name\" in the current buffer."
2642 (let ((case-fold-search t))
2643 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2644 (nnheader-concat gnus-article-save-directory
2645 (match-string 1)))))
2647 (defun gnus-article-nndoc-name (group)
2648 "If GROUP is an nndoc group, return the name of the parent group."
2649 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2650 (gnus-group-get-parameter group 'save-article-group)))
2652 (defun gnus-summary-save-in-rmail (&optional filename)
2653 "Append this article to Rmail file.
2654 Optional argument FILENAME specifies file name.
2655 Directory to save to is default to `gnus-article-save-directory'."
2656 (setq filename (gnus-read-save-file-name
2657 "Save %s in rmail file:" filename
2658 gnus-rmail-save-name gnus-newsgroup-name
2659 gnus-current-headers 'gnus-newsgroup-last-rmail))
2660 (gnus-eval-in-buffer-window gnus-save-article-buffer
2664 (gnus-output-to-rmail filename))))
2667 (defun gnus-summary-save-in-mail (&optional filename)
2668 "Append this article to Unix mail file.
2669 Optional argument FILENAME specifies file name.
2670 Directory to save to is default to `gnus-article-save-directory'."
2671 (setq filename (gnus-read-save-file-name
2672 "Save %s in Unix mail file:" filename
2673 gnus-mail-save-name gnus-newsgroup-name
2674 gnus-current-headers 'gnus-newsgroup-last-mail))
2675 (gnus-eval-in-buffer-window gnus-save-article-buffer
2679 (if (and (file-readable-p filename)
2680 (mail-file-babyl-p filename))
2681 (rmail-output-to-rmail-file filename t)
2682 (gnus-output-to-mail filename)))))
2685 (defun gnus-summary-save-in-file (&optional filename overwrite)
2686 "Append this article to file.
2687 Optional argument FILENAME specifies file name.
2688 Directory to save to is default to `gnus-article-save-directory'."
2689 (setq filename (gnus-read-save-file-name
2690 "Save %s in file:" filename
2691 gnus-file-save-name gnus-newsgroup-name
2692 gnus-current-headers 'gnus-newsgroup-last-file))
2693 (gnus-eval-in-buffer-window gnus-save-article-buffer
2697 (when (and overwrite
2698 (file-exists-p filename))
2699 (delete-file filename))
2700 (gnus-output-to-file filename))))
2703 (defun gnus-summary-write-to-file (&optional filename)
2704 "Write this article to a file.
2705 Optional argument FILENAME specifies file name.
2706 The directory to save in defaults to `gnus-article-save-directory'."
2707 (gnus-summary-save-in-file nil t))
2709 (defun gnus-summary-save-body-in-file (&optional filename)
2710 "Append this article body to a file.
2711 Optional argument FILENAME specifies file name.
2712 The directory to save in defaults to `gnus-article-save-directory'."
2713 (setq filename (gnus-read-save-file-name
2714 "Save %s body in file:" filename
2715 gnus-file-save-name gnus-newsgroup-name
2716 gnus-current-headers 'gnus-newsgroup-last-file))
2717 (gnus-eval-in-buffer-window gnus-save-article-buffer
2721 (when (article-goto-body)
2722 (narrow-to-region (point) (point-max)))
2723 (gnus-output-to-file filename))))
2726 (defun gnus-summary-save-in-pipe (&optional command)
2727 "Pipe this article to subprocess."
2729 (cond ((and (eq command 'default)
2730 gnus-last-shell-command)
2731 gnus-last-shell-command)
2735 "Shell command on %s: "
2736 (if (and gnus-number-of-articles-to-be-saved
2737 (> gnus-number-of-articles-to-be-saved 1))
2738 (format "these %d articles"
2739 gnus-number-of-articles-to-be-saved)
2741 gnus-last-shell-command))))
2742 (when (string-equal command "")
2743 (setq command gnus-last-shell-command))
2744 (gnus-eval-in-buffer-window gnus-article-buffer
2747 (shell-command-on-region (point-min) (point-max) command nil)))
2748 (setq gnus-last-shell-command command))
2750 ;;; Article file names when saving.
2752 (defun gnus-capitalize-newsgroup (newsgroup)
2753 "Capitalize NEWSGROUP name."
2754 (when (not (zerop (length newsgroup)))
2755 (concat (char-to-string (upcase (aref newsgroup 0)))
2756 (substring newsgroup 1))))
2758 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2759 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2760 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2761 Otherwise, it is like ~/News/news/group/num."
2764 (concat (if (gnus-use-long-file-name 'not-save)
2765 (gnus-capitalize-newsgroup newsgroup)
2766 (gnus-newsgroup-directory-form newsgroup))
2767 "/" (int-to-string (mail-header-number headers)))
2768 gnus-article-save-directory)))
2770 (string-equal (file-name-directory default)
2771 (file-name-directory last-file))
2772 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2774 (or last-file default))))
2776 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2777 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2778 If variable `gnus-use-long-file-name' is non-nil, it is
2779 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2782 (concat (if (gnus-use-long-file-name 'not-save)
2784 (gnus-newsgroup-directory-form newsgroup))
2785 "/" (int-to-string (mail-header-number headers)))
2786 gnus-article-save-directory)))
2788 (string-equal (file-name-directory default)
2789 (file-name-directory last-file))
2790 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2792 (or last-file default))))
2794 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2795 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2796 If variable `gnus-use-long-file-name' is non-nil, it is
2797 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2800 (if (gnus-use-long-file-name 'not-save)
2802 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2803 gnus-article-save-directory)))
2805 (defun article-verify-x-pgp-sig ()
2808 (if (gnus-buffer-live-p gnus-original-article-buffer)
2809 (let ((sig (with-current-buffer gnus-original-article-buffer
2810 (gnus-fetch-field "X-PGP-Sig")))
2814 (mml2015-clear-verify-function))
2816 (insert-buffer gnus-original-article-buffer)
2817 (setq items (split-string sig))
2818 (message-narrow-to-head)
2819 (let ((inhibit-point-motion-hooks t)
2820 (case-fold-search t))
2821 ;; Don't verify multiple headers.
2822 (setq headers (mapconcat (lambda (header)
2824 (mail-fetch-field header) "\n"))
2825 (split-string (nth 1 items) ",") "")))
2826 (delete-region (point-min) (point-max))
2827 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2828 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2833 (if (looking-at "^-")
2836 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2837 (insert "Version: " (car items) "\n\n")
2838 (insert (mapconcat 'identity (cddr items) "\n"))
2839 (insert "\n-----END PGP SIGNATURE-----\n")
2840 (let ((mm-security-handle (list (format "multipart/signed"))))
2841 (mml2015-clean-buffer)
2842 (let ((coding-system-for-write (or gnus-newsgroup-charset
2844 (funcall (mml2015-clear-verify-function)))
2846 (or (mm-handle-multipart-ctl-parameter
2847 mm-security-handle 'gnus-details)
2848 (mm-handle-multipart-ctl-parameter
2849 mm-security-handle 'gnus-info)))))
2851 (let (buffer-read-only bface eface)
2853 (message-narrow-to-head)
2854 (goto-char (point-max))
2856 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2857 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2858 (message-remove-header "X-Gnus-PGP-Verify")
2859 (if (re-search-forward "^X-PGP-Sig:" nil t)
2861 (goto-char (point-max)))
2862 (narrow-to-region (point) (point))
2863 (insert "X-Gnus-PGP-Verify: " info "\n")
2864 (goto-char (point-min))
2867 (if (not (looking-at "^[ \t]"))
2871 (goto-char (point-min))
2872 (when (looking-at "\\([^:]+\\): *")
2873 (put-text-property (match-beginning 1) (1+ (match-end 1))
2875 (put-text-property (match-end 0) (point-max)
2876 'face eface)))))))))
2883 (setq afunc (car func)
2886 gfunc (intern (format "gnus-%s" func))))
2889 `(lambda (&optional interactive &rest args)
2890 ,(documentation afunc t)
2891 (interactive (list t))
2893 (set-buffer gnus-article-buffer)
2895 (call-interactively ',afunc)
2896 (apply ',afunc args))))))))
2897 '(article-hide-headers
2898 article-verify-x-pgp-sig
2899 article-hide-boring-headers
2900 article-toggle-headers
2901 article-treat-overstrike
2902 article-fill-long-lines
2903 article-capitalize-sentences
2905 article-display-x-face
2906 article-de-quoted-unreadable
2907 article-de-base64-unreadable
2910 article-hide-list-identifiers
2912 article-strip-banner
2915 article-hide-signature
2916 article-strip-headers-in-body
2917 article-remove-trailing-blank-lines
2918 article-strip-leading-blank-lines
2919 article-strip-multiple-blank-lines
2920 article-strip-leading-space
2921 article-strip-trailing-space
2922 article-strip-blank-lines
2923 article-strip-all-blank-lines
2925 article-date-iso8601
2926 article-date-original
2928 article-decode-mime-words
2929 article-decode-charset
2930 article-decode-encoded-words
2934 article-treat-dumbquotes
2935 article-normalize-headers
2936 (article-show-all-headers . gnus-article-show-all-headers)
2937 (article-show-all . gnus-article-show-all))))
2940 ;;; Gnus article mode
2943 (put 'gnus-article-mode 'mode-class 'special)
2945 (gnus-define-keys gnus-article-mode-map
2946 " " gnus-article-goto-next-page
2947 "\177" gnus-article-goto-prev-page
2948 [delete] gnus-article-goto-prev-page
2949 [backspace] gnus-article-goto-prev-page
2950 "\C-c^" gnus-article-refer-article
2951 "h" gnus-article-show-summary
2952 "s" gnus-article-show-summary
2953 "\C-c\C-m" gnus-article-mail
2954 "?" gnus-article-describe-briefly
2955 "e" gnus-summary-edit-article
2956 "<" beginning-of-buffer
2958 "\C-c\C-i" gnus-info-find-node
2960 "\C-hk" gnus-article-describe-key
2961 "\C-hc" gnus-article-describe-key-briefly
2963 "\C-d" gnus-article-read-summary-keys
2964 "\M-*" gnus-article-read-summary-keys
2965 "\M-#" gnus-article-read-summary-keys
2966 "\M-^" gnus-article-read-summary-keys
2967 "\M-g" gnus-article-read-summary-keys)
2969 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2972 (unless (lookup-key gnus-article-mode-map key)
2973 (define-key gnus-article-mode-map key
2974 'gnus-article-read-summary-keys)))
2979 (let ((key (car elt)))
2980 (and (> (length key) 0)
2981 (not (eq 'menu-bar (aref key 0)))
2982 (symbolp (lookup-key gnus-summary-mode-map key))
2984 (accessible-keymaps gnus-summary-mode-map))
2988 (push (char-to-string c) keys)
2993 (defvar gnus-article-commands-menu))
2995 (defun gnus-article-make-menu-bar ()
2996 (gnus-turn-off-edit-menu 'article)
2997 (unless (boundp 'gnus-article-article-menu)
2999 gnus-article-article-menu gnus-article-mode-map ""
3001 ["Scroll forwards" gnus-article-goto-next-page t]
3002 ["Scroll backwards" gnus-article-goto-prev-page t]
3003 ["Show summary" gnus-article-show-summary t]
3004 ["Fetch Message-ID at point" gnus-article-refer-article t]
3005 ["Mail to address at point" gnus-article-mail t]
3006 ["Send a bug report" gnus-bug t]))
3009 gnus-article-treatment-menu gnus-article-mode-map ""
3010 ;; Fixme: this should use :active (and maybe :visible).
3012 ["Hide headers" gnus-article-toggle-headers t]
3013 ["Hide signature" gnus-article-hide-signature t]
3014 ["Hide citation" gnus-article-hide-citation t]
3015 ["Treat overstrike" gnus-article-treat-overstrike t]
3016 ["Remove carriage return" gnus-article-remove-cr t]
3017 ["Decode HZ" gnus-article-decode-HZ t]))
3019 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3021 (when (boundp 'gnus-summary-post-menu)
3022 (define-key gnus-article-mode-map [menu-bar post]
3023 (cons "Post" gnus-summary-post-menu)))
3025 (gnus-run-hooks 'gnus-article-menu-hook))
3027 (when (boundp 'gnus-article-commands-menu)
3028 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
3029 (when (boundp 'gnus-summary-post-menu)
3030 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
3032 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3035 (defun gnus-article-mode ()
3036 "Major mode for displaying an article.
3038 All normal editing commands are switched off.
3040 The following commands are available in addition to all summary mode
3042 \\<gnus-article-mode-map>
3043 \\[gnus-article-next-page]\t Scroll the article one page forwards
3044 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3045 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3046 \\[gnus-article-show-summary]\t Display the summary buffer
3047 \\[gnus-article-mail]\t Send a reply to the address near point
3048 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3049 \\[gnus-info-find-node]\t Go to the Gnus info node"
3051 (when (gnus-visual-p 'article-menu 'menu)
3052 (gnus-article-make-menu-bar))
3053 (gnus-simplify-mode-line)
3054 (setq mode-name "Article")
3055 (setq major-mode 'gnus-article-mode)
3056 (make-local-variable 'minor-mode-alist)
3057 (unless (assq 'gnus-show-mime minor-mode-alist)
3058 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3059 (use-local-map gnus-article-mode-map)
3060 (gnus-update-format-specifications nil 'article-mode)
3061 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3062 (make-local-variable 'gnus-page-broken)
3063 (make-local-variable 'gnus-button-marker-list)
3064 (make-local-variable 'gnus-article-current-summary)
3065 (make-local-variable 'gnus-article-mime-handles)
3066 (make-local-variable 'gnus-article-decoded-p)
3067 (make-local-variable 'gnus-article-mime-handle-alist)
3068 (make-local-variable 'gnus-article-wash-types)
3069 (make-local-variable 'gnus-article-charset)
3070 (make-local-variable 'gnus-article-ignored-charsets)
3071 (gnus-set-default-directory)
3072 (buffer-disable-undo)
3073 (setq buffer-read-only t)
3074 (set-syntax-table gnus-article-mode-syntax-table)
3075 (gnus-run-hooks 'gnus-article-mode-hook))
3077 (defun gnus-article-setup-buffer ()
3078 "Initialize the article buffer."
3079 (let* ((name (if gnus-single-article-buffer "*Article*"
3080 (concat "*Article " gnus-newsgroup-name "*")))
3082 (progn (string-match "\\*Article" name)
3083 (concat " *Original Article"
3084 (substring name (match-end 0))))))
3085 (setq gnus-article-buffer name)
3086 (setq gnus-original-article-buffer original)
3087 (setq gnus-article-mime-handle-alist nil)
3088 ;; This might be a variable local to the summary buffer.
3089 (unless gnus-single-article-buffer
3091 (set-buffer gnus-summary-buffer)
3092 (setq gnus-article-buffer name)
3093 (setq gnus-original-article-buffer original)
3094 (gnus-set-global-variables)))
3095 (gnus-article-setup-highlight-words)
3096 ;; Init original article buffer.
3098 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3099 (set-buffer-multibyte nil)
3100 (setq major-mode 'gnus-original-article-mode)
3101 (make-local-variable 'gnus-original-article))
3102 (if (get-buffer name)
3105 (buffer-disable-undo)
3106 (setq buffer-read-only t)
3107 (unless (eq major-mode 'gnus-article-mode)
3108 (gnus-article-mode))
3111 (set-buffer (gnus-get-buffer-create name))
3113 (make-local-variable 'gnus-summary-buffer)
3114 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3115 (current-buffer)))))
3117 ;; Set article window start at LINE, where LINE is the number of lines
3118 ;; from the head of the article.
3119 (defun gnus-article-set-window-start (&optional line)
3121 (get-buffer-window gnus-article-buffer t)
3123 (set-buffer gnus-article-buffer)
3124 (goto-char (point-min))
3127 (gnus-message 6 "Moved to bookmark")
3128 (search-forward "\n\n" nil t)
3132 ;;; @@ article filters
3135 (defun gnus-article-display-mime-message ()
3136 "Article display method for MIME message."
3137 ;; called from `gnus-original-article-buffer'.
3138 (let (charset all-headers)
3139 (with-current-buffer gnus-summary-buffer
3140 (setq charset default-mime-charset
3141 all-headers gnus-have-all-headers))
3142 (make-local-variable 'default-mime-charset)
3143 (setq default-mime-charset charset)
3144 (with-current-buffer (get-buffer-create gnus-article-buffer)
3145 (make-local-variable 'default-mime-charset)
3146 (setq default-mime-charset charset))
3147 (mime-display-message mime-message-structure
3148 gnus-article-buffer nil gnus-article-mode-map)
3150 (gnus-article-hide-headers nil -1)))
3151 (run-hooks 'gnus-mime-article-prepare-hook))
3153 (defun gnus-article-display-traditional-message ()
3154 "Article display method for traditional message."
3155 (set-buffer gnus-article-buffer)
3156 (let (buffer-read-only)
3158 (insert-buffer-substring gnus-original-article-buffer)))
3160 (defun gnus-article-make-full-mail-header (&optional number charset)
3161 "Create a new mail header structure in a raw article buffer."
3162 (unless (and number charset)
3163 (save-current-buffer
3164 (set-buffer gnus-summary-buffer)
3166 (setq number (or (cdr gnus-article-current) 0)))
3168 (setq charset (or default-mime-charset 'x-ctext)))))
3169 (goto-char (point-min))
3170 (let ((header-end (if (search-forward "\n\n" nil t)
3172 (goto-char (point-max))))
3173 (chars (- (point-max) (point)))
3174 (lines (count-lines (point) (point-max)))
3175 (default-mime-charset charset)
3177 (narrow-to-region (point-min) header-end)
3178 (setq xref (std11-fetch-field "xref"))
3180 (make-full-mail-header
3182 (std11-fetch-field "subject")
3183 (std11-fetch-field "from")
3184 (std11-fetch-field "date")
3185 (std11-fetch-field "message-id")
3186 (std11-fetch-field "references")
3189 (when xref (concat "Xref: " xref)))
3192 (defun gnus-article-prepare (article &optional all-headers header)
3193 "Prepare ARTICLE in article mode buffer.
3194 ARTICLE should either be an article number or a Message-ID.
3195 If ARTICLE is an id, HEADER should be the article headers.
3196 If ALL-HEADERS is non-nil, no headers are hidden."
3198 ;; Make sure we start in a summary buffer.
3199 (unless (eq major-mode 'gnus-summary-mode)
3200 (set-buffer gnus-summary-buffer))
3201 (setq gnus-summary-buffer (current-buffer))
3202 (let* ((gnus-article (if header (mail-header-number header) article))
3203 (summary-buffer (current-buffer))
3204 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3205 (group gnus-newsgroup-name)
3208 (gnus-article-setup-buffer)
3209 (set-buffer gnus-original-article-buffer)
3210 ;; Deactivate active regions.
3211 (when (and (boundp 'transient-mark-mode)
3212 transient-mark-mode)
3213 (setq mark-active nil))
3214 (if (not (setq result (let ((buffer-read-only nil))
3215 (gnus-request-article-this-buffer
3217 ;; There is no such article.
3219 (when (and (numberp article)
3220 (not (memq article gnus-newsgroup-sparse)))
3221 (setq gnus-article-current
3222 (cons gnus-newsgroup-name article))
3223 (set-buffer gnus-summary-buffer)
3224 (setq gnus-current-article article)
3225 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3227 (gnus-summary-set-agent-mark article)
3228 (message "Message marked for downloading"))
3229 (gnus-summary-mark-article article gnus-canceled-mark)
3230 (unless (memq article gnus-newsgroup-sparse)
3231 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3232 (if (or (eq result 'pseudo)
3233 (eq result 'nneething))
3236 (set-buffer summary-buffer)
3237 (push article gnus-newsgroup-history)
3238 (setq gnus-last-article gnus-current-article
3239 gnus-current-article 0
3240 gnus-current-headers nil
3241 gnus-article-current nil)
3242 (if (eq result 'nneething)
3243 (gnus-configure-windows 'summary)
3244 (gnus-configure-windows 'article))
3245 (gnus-set-global-variables))
3246 (let ((gnus-article-mime-handle-alist-1
3247 gnus-article-mime-handle-alist))
3248 (gnus-set-mode-line 'article)))
3249 ;; The result from the `request' was an actual article -
3250 ;; or at least some text that is now displayed in the
3252 (when (and (numberp article)
3253 (not (eq article gnus-current-article)))
3254 ;; Seems like a new article has been selected.
3255 ;; `gnus-current-article' must be an article number.
3257 (set-buffer summary-buffer)
3258 (push article gnus-newsgroup-history)
3259 (setq gnus-last-article gnus-current-article
3260 gnus-current-article article
3261 gnus-current-headers
3262 (gnus-summary-article-header gnus-current-article)
3263 gnus-article-current
3264 (cons gnus-newsgroup-name gnus-current-article))
3265 (unless (vectorp gnus-current-headers)
3266 (setq gnus-current-headers nil))
3267 (gnus-summary-goto-subject gnus-current-article)
3268 (when (gnus-summary-show-thread)
3269 ;; If the summary buffer really was folded, the
3270 ;; previous goto may not actually have gone to
3271 ;; the right article, but the thread root instead.
3273 (gnus-summary-goto-subject gnus-current-article))
3274 (gnus-run-hooks 'gnus-mark-article-hook)
3275 (gnus-set-mode-line 'summary)
3276 (when (gnus-visual-p 'article-highlight 'highlight)
3277 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3278 ;; Set the global newsgroup variables here.
3279 (gnus-set-global-variables)
3280 (setq gnus-have-all-headers
3281 (or all-headers gnus-show-all-headers))))
3283 (gnus-configure-windows 'article))
3284 (when (or (numberp article)
3286 (gnus-article-prepare-display)
3288 (goto-char (point-min))
3289 (setq gnus-page-broken
3290 (when gnus-break-pages
3291 (gnus-narrow-to-page)
3293 (let ((gnus-article-mime-handle-alist-1
3294 gnus-article-mime-handle-alist))
3295 (gnus-set-mode-line 'article))
3297 (set-window-point (get-buffer-window (current-buffer)) (point))
3298 (gnus-configure-windows 'article)
3301 (defun gnus-article-prepare-mime-display (&optional number)
3302 (goto-char (point-min))
3303 (when (re-search-forward "^[^\t ]+:" nil t)
3304 (goto-char (match-beginning 0)))
3305 (let ((entity (if (eq 1 (point-min))
3306 (get-text-property 1 'mime-view-entity)
3307 (get-text-property (point) 'mime-view-entity)))
3308 last-entity child-entity next type)
3309 (setq child-entity (mime-entity-children entity))
3311 (setq last-entity (nth (1- (length child-entity))
3313 (setq last-entity entity))
3315 (narrow-to-region (point)
3316 (if (search-forward "\n\n" nil t)
3319 (gnus-treat-article 'head)
3320 (put-text-property (point-min) (point-max) 'article-treated-header t)
3321 (goto-char (point-max)))
3322 (while (and (not (eobp)) entity)
3323 (setq next (set-marker
3325 (next-single-property-change (point) 'mime-view-entity
3327 (let ((types (mime-entity-content-type entity)))
3328 (while (eq 'multipart (mime-content-type-primary-type types))
3329 (setq entity (car (mime-entity-children entity))
3330 types (mime-entity-content-type entity)))
3332 (setq type (format "%s/%s"
3333 (mime-content-type-primary-type types)
3334 (mime-content-type-subtype types)))))
3335 (if (string-equal type "message/rfc822")
3338 (let ((children (mime-entity-children entity))
3341 (setq last-children (nth (1- (length children)) children))
3344 (not (eq last-children
3345 (get-text-property next 'mime-view-entity)))
3347 (next-single-property-change next
3349 nil (point-max)))))))
3350 (setq next (next-single-property-change next 'mime-view-entity
3353 (narrow-to-region (point) next)
3354 (gnus-article-prepare-mime-display)
3355 (goto-char (point-max)))
3356 (setq entity (get-text-property (point) 'mime-view-entity)))
3358 (narrow-to-region (point) next)
3359 ;; Kludge. We have to count true number, but for now,
3360 ;; part number is here only to achieve `last'.
3361 (gnus-treat-article nil 1
3362 (if (eq entity last-entity)
3365 (goto-char (point-max)))
3366 (setq entity (get-text-property next 'mime-view-entity))))))
3369 (defun gnus-article-prepare-display ()
3370 "Make the current buffer look like a nice article."
3371 (setq gnus-article-wash-types nil)
3372 (gnus-run-hooks 'gnus-tmp-internal-hook)
3373 (gnus-run-hooks 'gnus-article-prepare-hook)
3375 (let (mime-display-header-hook mime-display-text/plain-hook)
3376 (funcall (if gnus-show-mime
3378 (setq mime-message-structure gnus-current-headers)
3379 (mime-buffer-entity-set-buffer-internal
3380 mime-message-structure
3381 gnus-original-article-buffer)
3382 (mime-entity-set-representation-type-internal
3383 mime-message-structure 'mime-buffer-entity)
3384 (luna-send mime-message-structure
3385 'initialize-instance
3386 mime-message-structure)
3387 gnus-article-display-method-for-mime)
3388 gnus-article-display-method-for-traditional)))
3389 ;; Associate this article with the current summary buffer.
3390 (setq gnus-article-current-summary gnus-summary-buffer)
3391 ;; Call the treatment functions.
3392 (let ((inhibit-read-only t)
3397 (gnus-article-prepare-mime-display)
3398 (narrow-to-region (goto-char (point-min))
3399 (if (search-forward "\n\n" nil t)
3402 (gnus-treat-article 'head)
3403 (put-text-property (point-min) (point-max) 'article-treated-header t)
3404 (goto-char (point-max))
3406 (narrow-to-region (point) (point-max))
3407 (gnus-treat-article nil))
3408 (put-text-property (point-min) (point-max) 'read-only nil)))
3409 ;; Perform the article display hooks. Incidentally, this hook is
3410 ;; an obsolete variable by now.
3411 (gnus-run-hooks 'gnus-article-display-hook))
3413 (defun gnus-article-decode-article-as-default-mime-charset ()
3414 "Decode an article as `default-mime-charset'. It won't work if the
3415 value of the variable `gnus-show-mime' is non-nil."
3416 (unless gnus-show-mime
3417 (decode-mime-charset-region (point-min) (point-max)
3418 (with-current-buffer gnus-summary-buffer
3419 default-mime-charset))))
3422 ;;; Gnus MIME viewing functions
3425 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3426 "The following specs can be used:
3428 %T MIME type, along with additional info
3429 %n The `name' parameter
3430 %d The description, if any
3431 %l The length of the encoded part
3432 %p The part identifier number
3433 %e Dots if the part isn't displayed")
3435 (defvar gnus-mime-button-line-format-alist
3436 '((?t gnus-tmp-type ?s)
3437 (?T gnus-tmp-type-long ?s)
3438 (?n gnus-tmp-name ?s)
3439 (?d gnus-tmp-description ?s)
3441 (?l gnus-tmp-length ?d)
3442 (?e gnus-tmp-dots ?s)))
3444 (defvar gnus-mime-button-commands
3445 '((gnus-article-press-button "\r" "Toggle Display")
3446 (gnus-mime-view-part "v" "View Interactively...")
3447 (gnus-mime-view-part-as-type "t" "View As Type...")
3448 (gnus-mime-view-part-as-charset "C" "View As charset...")
3449 (gnus-mime-save-part "o" "Save...")
3450 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3451 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3452 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3453 (gnus-mime-internalize-part "E" "View Internally")
3454 (gnus-mime-externalize-part "e" "View Externally")
3455 (gnus-mime-pipe-part "|" "Pipe To Command...")
3456 (gnus-mime-action-on-part "." "Take action on the part")))
3458 (defun gnus-article-mime-part-status ()
3459 (with-current-buffer gnus-article-buffer
3460 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3461 (if (and entity (mime-entity-children entity))
3462 (format " (%d parts)" (length (mime-entity-children entity)))
3465 (defvar gnus-mime-button-map
3466 (let ((map (make-sparse-keymap)))
3467 ;; Not for Emacs 21: fixme better.
3468 ;; (set-keymap-parent map gnus-article-mode-map)
3469 (define-key map gnus-mouse-2 'gnus-article-push-button)
3470 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3471 (dolist (c gnus-mime-button-commands)
3472 (define-key map (cadr c) (car c)))
3475 (defun gnus-mime-button-menu (event)
3476 "Construct a context-sensitive menu of MIME commands."
3478 (save-window-excursion
3479 (let ((pos (event-start event)))
3480 (select-window (posn-window pos))
3481 (goto-char (posn-point pos))
3482 (gnus-article-check-buffer)
3483 (let ((response (x-popup-menu
3485 ("" ,@(mapcar (lambda (c)
3486 (cons (caddr c) (car c)))
3487 gnus-mime-button-commands))))))
3489 (call-interactively response))))))
3491 (defun gnus-mime-view-all-parts (&optional handles)
3492 "View all the MIME parts."
3494 (save-current-buffer
3495 (set-buffer gnus-article-buffer)
3496 (let ((handles (or handles gnus-article-mime-handles))
3497 (mail-parse-charset gnus-newsgroup-charset)
3498 (mail-parse-ignored-charsets
3499 (with-current-buffer gnus-summary-buffer
3500 gnus-newsgroup-ignored-charsets)))
3501 (mm-remove-parts handles)
3502 (goto-char (point-min))
3503 (or (search-forward "\n\n") (goto-char (point-max)))
3504 (let (buffer-read-only)
3505 (delete-region (point) (point-max)))
3506 (mm-display-parts handles))))
3508 (defun gnus-mime-save-part-and-strip ()
3509 "Save the MIME part under point then replace it with an external body."
3511 (gnus-article-check-buffer)
3512 (let* ((data (get-text-property (point) 'gnus-data))
3513 (file (mm-save-part data))
3516 (with-current-buffer (mm-handle-buffer data)
3518 (insert "Content-Type: " (mm-handle-media-type data))
3519 (mml-insert-parameter-string (cdr (mm-handle-type data))
3522 (insert "Content-ID: " (message-make-message-id) "\n")
3523 (insert "Content-Transfer-Encoding: binary\n")
3526 (cdr (mm-make-handle nil
3527 `("message/external-body"
3528 (access-type . "LOCAL-FILE")
3530 (set-buffer gnus-summary-buffer)
3531 (gnus-article-edit-article
3534 (let ((mail-parse-charset (or gnus-article-charset
3535 ',gnus-newsgroup-charset))
3536 (mail-parse-ignored-charsets
3537 (or gnus-article-ignored-charsets
3538 ',gnus-newsgroup-ignored-charsets))
3539 (mbl mml-buffer-list))
3540 (setq mml-buffer-list nil)
3541 (insert-buffer gnus-original-article-buffer)
3542 (mime-to-mml gnus-article-mime-handles)
3543 (setq gnus-article-mime-handles nil)
3544 (make-local-hook 'kill-buffer-hook)
3545 (let ((mbl1 mml-buffer-list))
3546 (setq mml-buffer-list mbl)
3547 (set (make-local-variable 'mml-buffer-list) mbl1))
3548 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3549 `(lambda (no-highlight)
3550 (let ((mail-parse-charset (or gnus-article-charset
3551 ',gnus-newsgroup-charset))
3552 (message-options message-options)
3553 (message-options-set-recipient)
3554 (mail-parse-ignored-charsets
3555 (or gnus-article-ignored-charsets
3556 ',gnus-newsgroup-ignored-charsets)))
3558 (mml-destroy-buffers)
3559 (remove-hook 'kill-buffer-hook
3560 'mml-destroy-buffers t)
3561 (kill-local-variable 'mml-buffer-list))
3562 (gnus-summary-edit-article-done
3563 ,(or (mail-header-references gnus-current-headers) "")
3564 ,(gnus-group-read-only-p)
3565 ,gnus-summary-buffer no-highlight))))))
3567 (defun gnus-mime-save-part ()
3568 "Save the MIME part under point."
3570 (gnus-article-check-buffer)
3571 (let ((data (get-text-property (point) 'gnus-data)))
3572 (mm-save-part data)))
3574 (defun gnus-mime-pipe-part ()
3575 "Pipe the MIME part under point to a process."
3577 (gnus-article-check-buffer)
3578 (let ((data (get-text-property (point) 'gnus-data)))
3579 (mm-pipe-part data)))
3581 (defun gnus-mime-view-part ()
3582 "Interactively choose a viewing method for the MIME part under point."
3584 (gnus-article-check-buffer)
3585 (let ((data (get-text-property (point) 'gnus-data)))
3586 (mm-interactively-view-part data)))
3588 (defun gnus-mime-view-part-as-type-internal ()
3589 (gnus-article-check-buffer)
3590 (let* ((name (mail-content-type-get
3591 (mm-handle-type (get-text-property (point) 'gnus-data))
3593 (def-type (and name (mm-default-file-encoding name))))
3594 (and def-type (cons def-type 0))))
3596 (defun gnus-mime-view-part-as-type (mime-type)
3597 "Choose a MIME media type, and view the part as such."
3599 (list (completing-read
3600 "View as MIME type: "
3601 (mapcar #'list (mailcap-mime-types))
3603 (gnus-mime-view-part-as-type-internal))))
3604 (gnus-article-check-buffer)
3605 (let ((handle (get-text-property (point) 'gnus-data)))
3606 (gnus-mm-display-part
3607 (mm-make-handle (mm-handle-buffer handle)
3608 (cons mime-type (cdr (mm-handle-type handle)))
3609 (mm-handle-encoding handle)
3610 (mm-handle-undisplayer handle)
3611 (mm-handle-disposition handle)
3612 (mm-handle-description handle)
3613 (mm-handle-cache handle)
3614 (mm-handle-id handle)))))
3616 (defun gnus-mime-copy-part (&optional handle)
3617 "Put the the MIME part under point into a new buffer."
3619 (gnus-article-check-buffer)
3620 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3621 (contents (mm-get-part handle))|
3622 (base (file-name-nondirectory
3624 (mail-content-type-get (mm-handle-type handle) 'name)
3625 (mail-content-type-get (mm-handle-type handle)
3628 (buffer (generate-new-buffer base)))
3629 (switch-to-buffer buffer)
3631 ;; We do it this way to make `normal-mode' set the appropriate mode.
3634 (setq buffer-file-name (expand-file-name base))
3636 (setq buffer-file-name nil))
3637 (goto-char (point-min))))
3639 (defun gnus-mime-inline-part (&optional handle arg)
3640 "Insert the MIME part under point into the current buffer."
3641 (interactive (list nil current-prefix-arg))
3642 (gnus-article-check-buffer)
3643 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3647 (if (and (not arg) (mm-handle-undisplayer handle))
3648 (mm-remove-part handle)
3649 (setq contents (mm-get-part handle))
3652 (setq charset (or (mail-content-type-get
3653 (mm-handle-type handle) 'charset)
3654 gnus-newsgroup-charset)))
3656 (if (mm-handle-undisplayer handle)
3657 (mm-remove-part handle))
3660 gnus-summary-show-article-charset-alist))
3661 (read-coding-system "Charset: ")))))
3663 (mm-insert-inline handle
3665 (setq charset (mm-charset-to-coding-system
3667 (not (eq charset 'ascii)))
3668 (mm-decode-coding-string contents charset)
3672 (defun gnus-mime-view-part-as-charset (&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)))
3680 (if (mm-handle-undisplayer handle)
3681 (mm-remove-part handle))
3682 (let ((gnus-newsgroup-charset
3684 gnus-summary-show-article-charset-alist))
3685 (read-coding-system "Charset: ")))
3686 (gnus-newsgroup-ignored-charsets 'gnus-all))
3687 (gnus-article-press-button))))
3689 (defun gnus-mime-externalize-part (&optional handle)
3690 "View the MIME part under point with an external viewer."
3692 (gnus-article-check-buffer)
3693 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3694 (mm-user-display-methods nil)
3695 (mm-inlined-types nil)
3696 (mail-parse-charset gnus-newsgroup-charset)
3697 (mail-parse-ignored-charsets
3698 (save-excursion (set-buffer gnus-summary-buffer)
3699 gnus-newsgroup-ignored-charsets)))
3700 (if (mm-handle-undisplayer handle)
3701 (mm-remove-part handle)
3702 (mm-display-part handle))))
3704 (defun gnus-mime-internalize-part (&optional handle)
3705 "View the MIME part under point with an internal viewer.
3706 In no internal viewer is available, use an external viewer."
3708 (gnus-article-check-buffer)
3709 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3710 (mm-inlined-types '(".*"))
3711 (mm-inline-large-images t)
3712 (mail-parse-charset gnus-newsgroup-charset)
3713 (mail-parse-ignored-charsets
3714 (save-excursion (set-buffer gnus-summary-buffer)
3715 gnus-newsgroup-ignored-charsets)))
3716 (if (mm-handle-undisplayer handle)
3717 (mm-remove-part handle)
3718 (mm-display-part handle))))
3720 (defun gnus-mime-action-on-part (&optional action)
3721 "Do something with the MIME attachment at \(point\)."
3723 (list (completing-read "Action: " gnus-mime-action-alist)))
3724 (gnus-article-check-buffer)
3725 (let ((action-pair (assoc action gnus-mime-action-alist)))
3727 (funcall (cdr action-pair)))))
3729 (defun gnus-article-part-wrapper (n function)
3730 (save-current-buffer
3731 (set-buffer gnus-article-buffer)
3732 (when (> n (length gnus-article-mime-handle-alist))
3733 (error "No such part"))
3734 (gnus-article-goto-part n)
3735 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3736 (funcall function handle))))
3738 (defun gnus-article-pipe-part (n)
3739 "Pipe MIME part N, which is the numerical prefix."
3741 (gnus-article-part-wrapper n 'mm-pipe-part))
3743 (defun gnus-article-save-part (n)
3744 "Save MIME part N, which is the numerical prefix."
3746 (gnus-article-part-wrapper n 'mm-save-part))
3748 (defun gnus-article-interactively-view-part (n)
3749 "View MIME part N interactively, which is the numerical prefix."
3751 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3753 (defun gnus-article-copy-part (n)
3754 "Copy MIME part N, which is the numerical prefix."
3756 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3758 (defun gnus-article-view-part-as-charset (n)
3759 "Copy MIME part N, which is the numerical prefix."
3761 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3763 (defun gnus-article-externalize-part (n)
3764 "View MIME part N externally, which is the numerical prefix."
3766 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3768 (defun gnus-article-inline-part (n)
3769 "Inline MIME part N, which is the numerical prefix."
3771 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3773 (defun gnus-article-mime-match-handle-first (condition)
3775 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3776 (while (setq ihandle (pop alist))
3778 ((functionp condition)
3779 (funcall condition (cdr ihandle)))
3780 ((eq condition 'undisplayed)
3781 (not (or (mm-handle-undisplayer (cdr ihandle))
3782 (equal (mm-handle-media-type (cdr ihandle))
3783 "multipart/alternative"))))
3784 ((eq condition 'undisplayed-alternative)
3785 (not (mm-handle-undisplayer (cdr ihandle))))
3787 (gnus-article-goto-part (car ihandle))
3788 (or (not n) (< (car ihandle) n)))
3789 (setq n (car ihandle))))
3793 (defun gnus-article-view-part (&optional n)
3794 "View MIME part N, which is the numerical prefix."
3796 (save-current-buffer
3797 (set-buffer gnus-article-buffer)
3798 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3799 gnus-article-mime-match-handle-function)))
3800 (when (> n (length gnus-article-mime-handle-alist))
3801 (error "No such part"))
3802 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3803 (when (gnus-article-goto-part n)
3804 (if (equal (car handle) "multipart/alternative")
3805 (gnus-article-press-button)
3806 (when (eq (gnus-mm-display-part handle) 'internal)
3807 (gnus-set-window-start)))))))
3809 (defsubst gnus-article-mime-total-parts ()
3810 (if (bufferp (car gnus-article-mime-handles))
3812 (1- (length gnus-article-mime-handles))))
3814 (defun gnus-mm-display-part (handle)
3815 "Display HANDLE and fix MIME button."
3816 (let ((id (get-text-property (point) 'gnus-part))
3821 (let ((window (selected-window))
3822 (mail-parse-charset gnus-newsgroup-charset)
3823 (mail-parse-ignored-charsets
3824 (save-excursion (set-buffer gnus-summary-buffer)
3825 gnus-newsgroup-ignored-charsets)))
3828 (let ((win (get-buffer-window (current-buffer) t))
3831 (select-window win))
3834 (if (mm-handle-displayed-p handle)
3835 ;; This will remove the part.
3836 (mm-display-part handle)
3838 (narrow-to-region (point) (1+ (point)))
3839 (mm-display-part handle)
3840 ;; We narrow to the part itself and
3841 ;; then call the treatment functions.
3842 (goto-char (point-min))
3844 (narrow-to-region (point) (point-max))
3847 (gnus-article-mime-total-parts)
3848 (mm-handle-media-type handle)))))
3849 (select-window window))))
3851 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3852 (gnus-insert-mime-button
3853 handle id (list (mm-handle-displayed-p handle)))
3854 (goto-char point))))
3856 (defun gnus-article-goto-part (n)
3857 "Go to MIME part N."
3858 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3860 (goto-char point))))
3862 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3863 (let ((gnus-tmp-name
3864 (or (mail-content-type-get (mm-handle-type handle)
3866 (mail-content-type-get (mm-handle-disposition handle)
3868 (mail-content-type-get (mm-handle-type handle)
3871 (gnus-tmp-type (mm-handle-media-type handle))
3872 (gnus-tmp-description
3873 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3876 (if (if displayed (car displayed)
3877 (mm-handle-displayed-p handle))
3879 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3881 gnus-tmp-type-long b e)
3882 (when (string-match ".*/" gnus-tmp-name)
3883 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3884 (setq gnus-tmp-type-long (concat gnus-tmp-type
3885 (and (not (equal gnus-tmp-name ""))
3886 (concat "; " gnus-tmp-name))))
3887 (or (equal gnus-tmp-description "")
3888 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3893 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3894 `(keymap ,gnus-mime-button-map
3895 ,@(if (>= (string-to-number emacs-version) 21)
3897 (list 'local-map gnus-mime-button-map))
3898 gnus-callback gnus-mm-display-part
3899 gnus-part ,gnus-tmp-id
3900 article-type annotation
3903 (widget-convert-button
3906 :action 'gnus-widget-press-button
3907 :button-keymap gnus-mime-button-map
3909 (lambda (widget/window &optional overlay pos)
3910 ;; Needed to properly clear the message due to a bug in
3911 ;; wid-edit (XEmacs only).
3912 (if (boundp 'help-echo-owns-message)
3913 (setq help-echo-owns-message t))
3915 "%S: %s the MIME part; %S: more options"
3916 (aref gnus-mouse-2 0)
3917 ;; XEmacs will get a single widget arg; Emacs 21 will get
3918 ;; window, overlay, position.
3919 (if (mm-handle-displayed-p
3921 (with-current-buffer (gnus-overlay-buffer overlay)
3922 (widget-get (widget-at (gnus-overlay-start overlay))
3924 (widget-get widget/window :mime-handle)))
3926 (aref gnus-down-mouse-3 0))))))
3928 (defun gnus-widget-press-button (elems el)
3929 (goto-char (widget-get elems :from))
3930 (gnus-article-press-button))
3932 (defvar gnus-displaying-mime nil)
3934 (defun gnus-display-mime (&optional ihandles)
3935 "Display the MIME parts."
3937 (save-selected-window
3938 (let ((window (get-buffer-window gnus-article-buffer))
3941 (select-window window)
3942 ;; We have to do this since selecting the window
3943 ;; may change the point. So we set the window point.
3944 (set-window-point window point)))
3945 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3946 buffer-read-only handle name type b e display)
3947 (when (and (not ihandles)
3948 (not gnus-displaying-mime))
3949 ;; Top-level call; we clean up.
3950 (when gnus-article-mime-handles
3951 (mm-destroy-parts gnus-article-mime-handles)
3952 (setq gnus-article-mime-handle-alist nil));; A trick.
3953 (setq gnus-article-mime-handles handles)
3954 ;; We allow users to glean info from the handles.
3955 (when gnus-article-mime-part-function
3956 (gnus-mime-part-function handles)))
3958 (or (not (stringp (car handles)))
3961 (when (and (not ihandles)
3962 (not gnus-displaying-mime))
3963 ;; Clean up for mime parts.
3965 (delete-region (point) (point-max)))
3966 (let ((gnus-displaying-mime t))
3967 (gnus-mime-display-part handles)))
3970 (narrow-to-region (point) (point-max))
3971 (gnus-treat-article nil 1 1)
3974 ;; Highlight the headers.
3978 (narrow-to-region (point-min) (point))
3979 (gnus-treat-article 'head))))))))
3981 (defvar gnus-mime-display-multipart-as-mixed nil)
3983 (defun gnus-mime-display-part (handle)
3986 ((not (stringp (car handle)))
3987 (gnus-mime-display-single handle))
3988 ;; User-defined multipart
3989 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3990 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3992 ;; multipart/alternative
3993 ((and (equal (car handle) "multipart/alternative")
3994 (not gnus-mime-display-multipart-as-mixed))
3995 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3996 (push (cons id handle) gnus-article-mime-handle-alist)
3997 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3998 ;; multipart/related
3999 ((and (equal (car handle) "multipart/related")
4000 (not gnus-mime-display-multipart-as-mixed))
4001 ;;;!!!We should find the start part, but we just default
4002 ;;;!!!to the first part.
4003 ;;(gnus-mime-display-part (cadr handle))
4004 ;;;!!! Most multipart/related is an HTML message plus images.
4005 ;;;!!! Unfortunately we are unable to let W3 display those
4006 ;;;!!! included images, so we just display it as a mixed multipart.
4007 (gnus-mime-display-mixed (cdr handle)))
4008 ((equal (car handle) "multipart/signed")
4009 (or (memq 'signed gnus-article-wash-types)
4010 (push 'signed gnus-article-wash-types))
4011 (gnus-mime-display-security handle))
4012 ((equal (car handle) "multipart/encrypted")
4013 (or (memq 'encrypted gnus-article-wash-types)
4014 (push 'encrypted gnus-article-wash-types))
4015 (gnus-mime-display-security handle))
4016 ;; Other multiparts are handled like multipart/mixed.
4018 (gnus-mime-display-mixed (cdr handle)))))
4020 (defun gnus-mime-part-function (handles)
4021 (if (stringp (car handles))
4022 (mapcar 'gnus-mime-part-function (cdr handles))
4023 (funcall gnus-article-mime-part-function handles)))
4025 (defun gnus-mime-display-mixed (handles)
4026 (mapcar 'gnus-mime-display-part handles))
4028 (defun gnus-mime-display-single (handle)
4029 (let ((type (mm-handle-media-type handle))
4030 (ignored gnus-ignored-mime-types)
4037 (when (string-match (pop ignored) type)
4038 (throw 'ignored nil)))
4039 (if (and (setq not-attachment
4040 (and (not (mm-inline-override-p handle))
4041 (or (not (mm-handle-disposition handle))
4042 (equal (car (mm-handle-disposition handle))
4044 (mm-attachment-override-p handle))))
4045 (mm-automatic-display-p handle)
4046 (or (mm-inlined-p handle)
4047 (mm-automatic-external-display-p type)))
4049 (when (equal (mm-handle-media-supertype handle) "text")
4051 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4053 (push (cons id handle) gnus-article-mime-handle-alist)
4054 (when (or (not display)
4055 (not (gnus-unbuttonized-mime-type-p type)))
4056 ;(gnus-article-insert-newline)
4057 (gnus-insert-mime-button
4058 handle id (list (or display (and not-attachment text))))
4059 (gnus-article-insert-newline)
4060 ;(gnus-article-insert-newline)
4061 ;; Remember modify the number of forward lines.
4069 (let ((mail-parse-charset gnus-newsgroup-charset)
4070 (mail-parse-ignored-charsets
4071 (save-excursion (condition-case ()
4072 (set-buffer gnus-summary-buffer)
4074 gnus-newsgroup-ignored-charsets)))
4075 (mm-display-part handle t))
4076 (goto-char (point-max)))
4077 ((and text not-attachment)
4081 (gnus-article-insert-newline)
4082 (mm-insert-inline handle (mm-get-part handle))
4083 (goto-char (point-max))))
4087 (narrow-to-region beg (point))
4090 (gnus-article-mime-total-parts)
4091 (mm-handle-media-type handle)))))))))
4093 (defun gnus-unbuttonized-mime-type-p (type)
4094 "Say whether TYPE is to be unbuttonized."
4095 (unless gnus-inhibit-mime-unbuttonizing
4097 (let ((types gnus-unbuttonized-mime-types))
4099 (when (string-match (pop types) type)
4100 (throw 'found t)))))))
4102 (defun gnus-article-insert-newline ()
4103 "Insert a newline, but mark it as undeletable."
4104 (gnus-put-text-property
4105 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4107 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4108 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4111 handle buffer-read-only from props begend not-pref)
4112 (save-window-excursion
4115 (narrow-to-region (car ibegend)
4118 (goto-char (car ibegend))
4121 (delete-region (point-min) (point-max))
4122 (mm-remove-parts handles))
4123 (setq begend (list (point-marker)))
4125 (unless (setq not-pref (cadr (member preferred ihandles)))
4126 (setq not-pref (car ihandles)))
4129 (not (gnus-unbuttonized-mime-type-p
4130 "multipart/alternative")))
4131 (gnus-add-text-properties
4134 (insert (format "%d. " id))
4138 (unless ,(not ibegend)
4139 (setq gnus-article-mime-handle-alist
4140 ',gnus-article-mime-handle-alist))
4141 (gnus-mime-display-alternative
4142 ',ihandles ',not-pref ',begend ,id))
4143 ,@(if (>= (string-to-number emacs-version) 21)
4144 nil ;; XEmacs doesn't care
4145 (list 'local-map gnus-mime-button-map))
4146 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4147 face ,gnus-article-button-face
4148 keymap ,gnus-mime-button-map
4151 (widget-convert-button 'link from (point)
4152 :action 'gnus-widget-press-button
4153 :button-keymap gnus-widget-button-keymap)
4155 (while (setq handle (pop handles))
4156 (gnus-add-text-properties
4159 (insert (format "(%c) %-18s"
4160 (if (equal handle preferred) ?* ? )
4161 (mm-handle-media-type handle)))
4165 (unless ,(not ibegend)
4166 (setq gnus-article-mime-handle-alist
4167 ',gnus-article-mime-handle-alist))
4168 (gnus-mime-display-alternative
4169 ',ihandles ',handle ',begend ,id))
4170 ,@(if (>= (string-to-number emacs-version) 21)
4171 nil ;; XEmacs doesn't care
4172 (list 'local-map gnus-mime-button-map))
4173 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4174 face ,gnus-article-button-face
4175 keymap ,gnus-mime-button-map
4178 (widget-convert-button 'link from (point)
4179 :action 'gnus-widget-press-button
4180 :button-keymap gnus-widget-button-keymap)
4184 (if (stringp (car preferred))
4185 (gnus-display-mime preferred)
4186 (let ((mail-parse-charset gnus-newsgroup-charset)
4187 (mail-parse-ignored-charsets
4188 (save-excursion (set-buffer gnus-summary-buffer)
4189 gnus-newsgroup-ignored-charsets)))
4190 (mm-display-part preferred)
4194 (narrow-to-region (car begend) (point-max))
4196 nil (length gnus-article-mime-handle-alist)
4197 (gnus-article-mime-total-parts)
4198 (mm-handle-media-type handle))))))
4199 (goto-char (point-max))
4200 (setcdr begend (point-marker)))))
4202 (goto-char point))))
4204 (defun gnus-article-wash-status ()
4205 "Return a string which display status of article washing."
4207 (set-buffer gnus-article-buffer)
4208 (let ((cite (memq 'cite gnus-article-wash-types))
4209 (headers (memq 'headers gnus-article-wash-types))
4210 (boring (memq 'boring-headers gnus-article-wash-types))
4211 (pgp (memq 'pgp gnus-article-wash-types))
4212 (pem (memq 'pem gnus-article-wash-types))
4213 (signed (memq 'signed gnus-article-wash-types))
4214 (encrypted (memq 'encrypted gnus-article-wash-types))
4215 (signature (memq 'signature gnus-article-wash-types))
4216 (overstrike (memq 'overstrike gnus-article-wash-types))
4217 (emphasis (memq 'emphasis gnus-article-wash-types)))
4218 (format "%c%c%c%c%c%c%c"
4220 (if (or headers boring) ?h ? )
4221 (if (or pgp pem signed encrypted) ?p ? )
4222 (if signature ?s ? )
4223 (if overstrike ?o ? )
4224 (if gnus-show-mime ?m ? )
4225 (if emphasis ?e ? )))))
4227 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4229 (defun gnus-article-maybe-hide-headers ()
4230 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4231 Provided for backwards compatibility."
4232 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4233 (not (save-excursion (set-buffer gnus-summary-buffer)
4234 gnus-have-all-headers)))
4235 (not gnus-inhibit-hiding))
4236 (gnus-article-hide-headers)))
4240 (defun gnus-output-to-file (file-name)
4241 "Append the current article to a file named FILE-NAME."
4242 (let ((artbuf (current-buffer)))
4244 (insert-buffer-substring artbuf)
4245 ;; Append newline at end of the buffer as separator, and then
4247 (goto-char (point-max))
4249 (write-region-as-binary (point-min) (point-max) file-name 'append)
4252 (defun gnus-narrow-to-page (&optional arg)
4253 "Narrow the article buffer to a page.
4254 If given a numerical ARG, move forward ARG pages."
4256 (setq arg (if arg (prefix-numeric-value arg) 0))
4258 (set-buffer gnus-article-buffer)
4259 (goto-char (point-min))
4261 ;; Remove any old next/prev buttons.
4262 (when (gnus-visual-p 'page-marker)
4263 (let ((buffer-read-only nil))
4264 (gnus-remove-text-with-property 'gnus-prev)
4265 (gnus-remove-text-with-property 'gnus-next)))
4268 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4270 (re-search-forward page-delimiter nil 'move arg)))
4271 (goto-char (match-end 0)))
4274 (if (re-search-forward page-delimiter nil 'move)
4277 (when (and (gnus-visual-p 'page-marker)
4278 (not (= (point-min) 1)))
4280 (goto-char (point-min))
4281 (gnus-insert-prev-page-button)))
4282 (when (and (gnus-visual-p 'page-marker)
4283 (< (+ (point-max) 2) (buffer-size)))
4285 (goto-char (point-max))
4286 (gnus-insert-next-page-button)))))
4288 ;; Article mode commands
4290 (defun gnus-article-goto-next-page ()
4291 "Show the next page of the article."
4293 (when (gnus-article-next-page)
4294 (goto-char (point-min))
4295 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4297 (defun gnus-article-goto-prev-page ()
4298 "Show the next page of the article."
4300 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4301 (gnus-article-prev-page nil)))
4303 (defun gnus-article-next-page (&optional lines)
4304 "Show the next page of the current article.
4305 If end of article, return non-nil. Otherwise return nil.
4306 Argument LINES specifies lines to be scrolled up."
4308 (let ((start (window-start))
4309 end-of-buffer end-of-page)
4311 (move-to-window-line -1)
4312 (if (<= (point) start)
4315 (setq start (point)))
4318 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4319 (and (pos-visible-in-window-p)
4320 (setq end-of-buffer t)))
4322 (setq end-of-page t)))
4324 (move-to-window-line lines)
4325 (unless (search-backward "\n\n" nil t)
4326 (setq start (point)))))
4327 (cond (end-of-buffer t)
4329 (gnus-narrow-to-page 1)
4333 (set-window-start (selected-window) start)
4334 (let (window-pixel-scroll-increment)
4338 (defun gnus-article-prev-page (&optional lines)
4339 "Show previous page of current article.
4340 Argument LINES specifies lines to be scrolled down."
4342 (let (beginning-of-buffer beginning-of-page)
4344 (move-to-window-line 0)
4345 (cond ((eq 1 (point))
4346 (setq beginning-of-buffer t))
4348 (setq beginning-of-page t))))
4349 (cond (beginning-of-buffer)
4351 (gnus-narrow-to-page -1))
4354 (let (window-pixel-scroll-increment)
4355 (scroll-down lines))
4356 (beginning-of-buffer
4357 (goto-char (point-min))))))))
4359 (defun gnus-article-refer-article ()
4360 "Read article specified by message-id around point."
4362 (let ((point (point)))
4363 (search-forward ">" nil t) ;Move point to end of "<....>".
4364 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4365 (let ((message-id (match-string 1)))
4367 (set-buffer gnus-summary-buffer)
4368 (gnus-summary-refer-article message-id))
4370 (error "No references around point"))))
4372 (defun gnus-article-show-summary ()
4373 "Reconfigure windows to show summary buffer."
4375 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4376 (error "There is no summary buffer for this article buffer")
4377 (gnus-article-set-globals)
4378 (gnus-configure-windows 'article)
4379 (gnus-summary-goto-subject gnus-current-article)
4380 (gnus-summary-position-point)))
4382 (defun gnus-article-describe-briefly ()
4383 "Describe article mode commands briefly."
4385 (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")))
4387 (defun gnus-article-summary-command ()
4388 "Execute the last keystroke in the summary buffer."
4390 (let ((obuf (current-buffer))
4391 (owin (current-window-configuration))
4393 (switch-to-buffer gnus-article-current-summary 'norecord)
4394 (setq func (lookup-key (current-local-map) (this-command-keys)))
4395 (call-interactively func)
4397 (set-window-configuration owin)
4398 (set-window-point (get-buffer-window (current-buffer)) (point))))
4400 (defun gnus-article-summary-command-nosave ()
4401 "Execute the last keystroke in the summary buffer."
4404 (pop-to-buffer gnus-article-current-summary 'norecord)
4405 (setq func (lookup-key (current-local-map) (this-command-keys)))
4406 (call-interactively func)))
4408 (defun gnus-article-check-buffer ()
4409 "Beep if not in an article buffer."
4410 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4411 (error "Command invoked outside of a Gnus article buffer")))
4413 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4414 "Read a summary buffer key sequence and execute it from the article buffer."
4416 (gnus-article-check-buffer)
4418 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4419 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4420 "=" "^" "\M-^" "|"))
4426 '("n" "Gn" "p" "Gp"))
4429 (set-buffer gnus-article-current-summary)
4430 (let (gnus-pick-mode)
4431 (push (or key last-command-event) unread-command-events)
4432 (setq keys (static-if (featurep 'xemacs)
4433 (events-to-keys (read-key-sequence nil))
4434 (read-key-sequence nil)))))
4437 (if (or (member keys nosaves)
4438 (member keys nosave-but-article)
4439 (member keys nosave-in-article))
4441 (save-window-excursion
4442 (pop-to-buffer gnus-article-current-summary 'norecord)
4443 ;; We disable the pick minor mode commands.
4444 (let (gnus-pick-mode)
4445 (setq func (lookup-key (current-local-map) keys))))
4449 (unless (member keys nosave-in-article)
4450 (set-buffer gnus-article-current-summary))
4451 (call-interactively func)
4452 (setq new-sum-point (point)))
4453 (when (member keys nosave-but-article)
4454 (pop-to-buffer gnus-article-buffer 'norecord)))
4455 ;; These commands should restore window configuration.
4456 (let ((obuf (current-buffer))
4457 (owin (current-window-configuration))
4459 (summary gnus-article-current-summary)
4460 func in-buffer selected)
4461 (if not-restore-window
4462 (pop-to-buffer summary 'norecord)
4463 (switch-to-buffer summary 'norecord))
4464 (setq in-buffer (current-buffer))
4465 ;; We disable the pick minor mode commands.
4466 (if (and (setq func (let (gnus-pick-mode)
4467 (lookup-key (current-local-map) keys)))
4470 (call-interactively func)
4471 (setq new-sum-point (point))
4472 (when (eq in-buffer (current-buffer))
4473 (setq selected (gnus-summary-select-article))
4475 (unless not-restore-window
4476 (set-window-configuration owin))
4477 (when (eq selected 'old)
4479 (set-window-start (get-buffer-window (current-buffer))
4481 (set-window-point (get-buffer-window (current-buffer))
4483 (let ((win (get-buffer-window gnus-article-current-summary)))
4485 (set-window-point win new-sum-point)))) )
4486 (switch-to-buffer gnus-article-buffer)
4489 (defun gnus-article-describe-key (key)
4490 "Display documentation of the function invoked by KEY. KEY is a string."
4491 (interactive "kDescribe key: ")
4492 (gnus-article-check-buffer)
4493 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4495 (set-buffer gnus-article-current-summary)
4496 (let (gnus-pick-mode)
4497 (push (elt key 0) unread-command-events)
4498 (setq key (if (featurep 'xemacs)
4499 (events-to-keys (read-key-sequence "Describe key: "))
4500 (read-key-sequence "Describe key: "))))
4502 (describe-key key)))
4504 (defun gnus-article-describe-key-briefly (key &optional insert)
4505 "Display documentation of the function invoked by KEY. KEY is a string."
4506 (interactive "kDescribe key: \nP")
4507 (gnus-article-check-buffer)
4508 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4510 (set-buffer gnus-article-current-summary)
4511 (let (gnus-pick-mode)
4512 (push (elt key 0) unread-command-events)
4513 (setq key (if (featurep 'xemacs)
4514 (events-to-keys (read-key-sequence "Describe key: "))
4515 (read-key-sequence "Describe key: "))))
4516 (describe-key-briefly key insert))
4517 (describe-key-briefly key insert)))
4519 (defun gnus-article-hide (&optional arg force)
4520 "Hide all the gruft in the current article.
4521 This means that PGP stuff, signatures, cited text and (some)
4522 headers will be hidden.
4523 If given a prefix, show the hidden text instead."
4524 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4525 (gnus-article-hide-headers arg)
4526 (gnus-article-hide-list-identifiers arg)
4527 (gnus-article-hide-pgp arg)
4528 (gnus-article-hide-citation-maybe arg force)
4529 (gnus-article-hide-signature arg))
4531 (defun gnus-article-maybe-highlight ()
4532 "Do some article highlighting if article highlighting is requested."
4533 (when (gnus-visual-p 'article-highlight 'highlight)
4534 (gnus-article-highlight-some)))
4536 (defun gnus-check-group-server ()
4537 ;; Make sure the connection to the server is alive.
4538 (unless (gnus-server-opened
4539 (gnus-find-method-for-group gnus-newsgroup-name))
4540 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4541 (gnus-request-group gnus-newsgroup-name t)))
4543 (defun gnus-request-article-this-buffer (article group)
4544 "Get an article and insert it into this buffer."
4545 (let (do-update-line sparse-header)
4549 (gnus-kill-all-overlays)
4550 (setq group (or group gnus-newsgroup-name))
4552 ;; Using `gnus-request-article' directly will insert the article into
4553 ;; `nntp-server-buffer' - so we'll save some time by not having to
4554 ;; copy it from the server buffer into the article buffer.
4556 ;; We only request an article by message-id when we do not have the
4557 ;; headers for it, so we'll have to get those.
4558 (when (stringp article)
4559 (gnus-read-header article))
4561 ;; If the article number is negative, that means that this article
4562 ;; doesn't belong in this newsgroup (possibly), so we find its
4563 ;; message-id and request it by id instead of number.
4564 (when (and (numberp article)
4566 (get-buffer gnus-summary-buffer)
4567 (gnus-buffer-exists-p gnus-summary-buffer))
4569 (set-buffer gnus-summary-buffer)
4570 (let ((header (gnus-summary-article-header article)))
4573 ((memq article gnus-newsgroup-sparse)
4574 ;; This is a sparse gap article.
4575 (setq do-update-line article)
4576 (setq article (mail-header-id header))
4577 (setq sparse-header (gnus-read-header article))
4578 (setq gnus-newsgroup-sparse
4579 (delq article gnus-newsgroup-sparse)))
4581 ;; It's a real article.
4582 (setq article (mail-header-id header)))
4584 ;; It is an extracted pseudo-article.
4585 (setq article 'pseudo)
4586 (gnus-request-pseudo-article header))))
4588 (let ((method (gnus-find-method-for-group
4589 gnus-newsgroup-name)))
4590 (when (and (eq (car method) 'nneething)
4592 (let ((dir (expand-file-name
4593 (mail-header-subject header)
4594 (file-name-as-directory
4595 (or (cadr (assq 'nneething-address method))
4597 (when (file-directory-p dir)
4598 (setq article 'nneething)
4599 (gnus-group-enter-directory dir))))))))
4602 ;; Refuse to select canceled articles.
4603 ((and (numberp article)
4605 (get-buffer gnus-summary-buffer)
4606 (gnus-buffer-exists-p gnus-summary-buffer)
4607 (eq (cdr (save-excursion
4608 (set-buffer gnus-summary-buffer)
4609 (assq article gnus-newsgroup-reads)))
4610 gnus-canceled-mark))
4612 ;; Check the backlog.
4613 ((and gnus-keep-backlog
4614 (gnus-backlog-request-article group article (current-buffer)))
4616 ;; Check asynchronous pre-fetch.
4617 ((gnus-async-request-fetched-article group article (current-buffer))
4618 (gnus-async-prefetch-next group article gnus-summary-buffer)
4619 (when (and (numberp article) gnus-keep-backlog)
4620 (gnus-backlog-enter-article group article (current-buffer)))
4623 ((and gnus-use-cache
4625 (gnus-cache-request-article article group))
4627 ;; Get the article and put into the article buffer.
4628 ((or (stringp article)
4630 (let ((gnus-override-method gnus-override-method)
4631 (methods (and (stringp article)
4632 gnus-refer-article-method))
4634 (buffer-read-only nil))
4635 (if (or (not (listp methods))
4636 (and (symbolp (car methods))
4637 (assq (car methods) nnoo-definition-alist)))
4638 (setq methods (list methods)))
4639 (when (and (null gnus-override-method)
4641 (setq gnus-override-method (pop methods)))
4643 (when (eq gnus-override-method 'current)
4644 (setq gnus-override-method gnus-current-select-method))
4646 (gnus-kill-all-overlays)
4647 (let ((gnus-newsgroup-name group))
4648 (gnus-check-group-server))
4649 (when (gnus-request-article article group (current-buffer))
4650 (when (numberp article)
4651 (gnus-async-prefetch-next group article
4652 gnus-summary-buffer)
4653 (when gnus-keep-backlog
4654 (gnus-backlog-enter-article
4655 group article (current-buffer))))
4656 (setq result 'article))
4659 (setq gnus-override-method (pop methods))
4660 (setq result 'done))))
4661 (and (eq result 'article) 'article)))
4665 ;; Associate this article with the current summary buffer.
4666 (setq gnus-article-current-summary gnus-summary-buffer)
4668 ;; Take the article from the original article buffer
4669 ;; and place it in the buffer it's supposed to be in.
4670 (when (and (get-buffer gnus-article-buffer)
4671 (equal (buffer-name (current-buffer))
4672 (buffer-name (get-buffer gnus-article-buffer))))
4674 (if (get-buffer gnus-original-article-buffer)
4675 (set-buffer gnus-original-article-buffer)
4676 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4677 (set-buffer-multibyte nil)
4678 (buffer-disable-undo)
4679 (setq major-mode 'gnus-original-article-mode)
4680 (setq buffer-read-only t))
4681 (let (buffer-read-only)
4683 (insert-buffer-substring gnus-article-buffer))
4684 (setq gnus-original-article (cons group article)))
4687 (run-hooks 'gnus-article-decode-hook)
4688 ;; Mark article as decoded or not.
4689 (setq gnus-article-decoded-p gnus-article-decode-hook))
4691 ;; Update sparse articles.
4692 (when (and do-update-line
4693 (or (numberp article)
4695 (let ((buf (current-buffer)))
4696 (set-buffer gnus-summary-buffer)
4697 (gnus-summary-update-article do-update-line sparse-header)
4698 (gnus-summary-goto-subject do-update-line nil t)
4699 (set-window-point (get-buffer-window (current-buffer) t)
4701 (set-buffer buf))))))
4707 (defcustom gnus-article-edit-mode-hook nil
4708 "Hook run in article edit mode buffers."
4709 :group 'gnus-article-various
4712 (defcustom gnus-article-edit-article-setup-function
4713 'gnus-article-mime-edit-article-setup
4714 "Function called to setup an editing article buffer."
4715 :group 'gnus-article-various
4718 (defvar gnus-article-edit-done-function nil)
4720 (defvar gnus-article-edit-mode-map nil)
4722 ;; Should we be using derived.el for this?
4723 (unless gnus-article-edit-mode-map
4724 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4725 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4727 (gnus-define-keys gnus-article-edit-mode-map
4728 "\C-c\C-c" gnus-article-edit-done
4729 "\C-c\C-k" gnus-article-edit-exit)
4731 (gnus-define-keys (gnus-article-edit-wash-map
4732 "\C-c\C-w" gnus-article-edit-mode-map)
4733 "f" gnus-article-edit-full-stops))
4735 (defun gnus-article-edit-mode ()
4736 "Major mode for editing articles.
4737 This is an extended text-mode.
4739 \\{gnus-article-edit-mode-map}"
4741 (setq major-mode 'gnus-article-edit-mode)
4742 (setq mode-name "Article Edit")
4743 (use-local-map gnus-article-edit-mode-map)
4744 (make-local-variable 'gnus-article-edit-done-function)
4745 (make-local-variable 'gnus-prev-winconf)
4746 (setq buffer-read-only nil)
4747 (buffer-enable-undo)
4749 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4751 (defun gnus-article-edit (&optional force)
4752 "Edit the current article.
4753 This will have permanent effect only in mail groups.
4754 If FORCE is non-nil, allow editing of articles even in read-only
4757 (when (and (not force)
4758 (gnus-group-read-only-p))
4759 (error "The current newsgroup does not support article editing"))
4760 (gnus-article-date-original)
4761 (gnus-article-edit-article
4763 `(lambda (no-highlight)
4765 (gnus-summary-edit-article-done
4766 ,(or (mail-header-references gnus-current-headers) "")
4767 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4769 (defun gnus-article-edit-article (start-func exit-func)
4770 "Start editing the contents of the current article buffer."
4771 (let ((winconf (current-window-configuration)))
4772 (set-buffer gnus-article-buffer)
4773 (gnus-article-edit-mode)
4774 (funcall start-func)
4775 (gnus-configure-windows 'edit-article)
4776 (setq gnus-article-edit-done-function exit-func)
4777 (setq gnus-prev-winconf winconf)
4778 (when gnus-article-edit-article-setup-function
4779 (funcall gnus-article-edit-article-setup-function))
4780 (gnus-message 6 "C-c C-c to end edits")))
4782 (defun gnus-article-edit-done (&optional arg)
4783 "Update the article edits and exit."
4785 (let ((func gnus-article-edit-done-function)
4786 (buf (current-buffer))
4787 (start (window-start)))
4788 (remove-hook 'gnus-article-mode-hook
4789 'gnus-article-mime-edit-article-unwind)
4790 (gnus-article-edit-exit)
4793 (let ((buffer-read-only nil))
4795 ;; The cache and backlog have to be flushed somewhat.
4796 (when gnus-keep-backlog
4797 (gnus-backlog-remove-article
4798 (car gnus-article-current) (cdr gnus-article-current)))
4799 ;; Flush original article as well.
4801 (when (get-buffer gnus-original-article-buffer)
4802 (set-buffer gnus-original-article-buffer)
4803 (setq gnus-original-article nil)))
4804 (when gnus-use-cache
4805 (gnus-cache-update-article
4806 (car gnus-article-current) (cdr gnus-article-current))))
4808 (set-window-start (get-buffer-window buf) start)
4809 (set-window-point (get-buffer-window buf) (point))))
4811 (defun gnus-article-edit-exit ()
4812 "Exit the article editing without updating."
4814 ;; We remove all text props from the article buffer.
4815 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4816 (curbuf (current-buffer))
4818 (window-start (window-start)))
4821 (let ((winconf gnus-prev-winconf))
4823 (set-window-configuration winconf)
4824 ;; Tippy-toe some to make sure that point remains where it was.
4825 (save-current-buffer
4827 (set-window-start (get-buffer-window (current-buffer)) window-start)
4830 (defun gnus-article-edit-full-stops ()
4831 "Interactively repair spacing at end of sentences."
4834 (goto-char (point-min))
4835 (search-forward-regexp "^$" nil t)
4836 (let ((case-fold-search nil))
4837 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4840 ;;; Article editing with MIME-Edit
4843 (defcustom gnus-article-mime-edit-article-setup-hook nil
4844 "Hook run after setting up a MIME editing article buffer."
4845 :group 'gnus-article-various
4848 (defun gnus-article-mime-edit-article-unwind ()
4849 "Unwind `gnus-article-buffer' if article editing was given up."
4850 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4851 (when mime-edit-mode-flag
4852 (mime-edit-exit 'nomime 'no-error)
4854 (when (featurep 'font-lock)
4855 (setq font-lock-defaults nil)
4856 (font-lock-mode 0)))
4858 (defun gnus-article-mime-edit-article-setup ()
4859 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4860 after replacing with the original article."
4861 (setq gnus-show-mime t)
4862 (setq gnus-article-edit-done-function
4863 `(lambda (&rest args)
4864 (when mime-edit-mode-flag
4867 (goto-char (point-min))
4868 (let (case-fold-search)
4869 (when (re-search-forward
4870 (format "^%s$" (regexp-quote mail-header-separator))
4872 (replace-match "")))
4873 (when (featurep 'font-lock)
4874 (setq font-lock-defaults nil)
4876 (apply ,gnus-article-edit-done-function args)
4877 (set-buffer gnus-original-article-buffer)
4879 (insert-buffer gnus-article-buffer)
4880 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4881 (gnus-article-prepare-display)))
4882 (substitute-key-definition
4883 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4884 gnus-article-edit-mode-map)
4886 (insert-buffer gnus-original-article-buffer)
4888 (when (featurep 'font-lock)
4889 (set (make-local-variable 'font-lock-defaults)
4890 '(message-font-lock-keywords t))
4891 (font-lock-set-defaults)
4892 (turn-on-font-lock))
4893 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4894 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4896 (defun gnus-article-mime-edit-exit ()
4897 "Exit the article MIME editing without updating."
4899 (let ((winconf gnus-prev-winconf)
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)) nil t)
4908 (replace-match "")))
4909 (when (featurep 'font-lock)
4910 (setq font-lock-defaults nil)
4912 ;; We remove all text props from the article buffer.
4913 (setq buf (format "%s" (buffer-string)))
4914 (set-buffer (get-buffer-create gnus-original-article-buffer))
4917 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4918 (gnus-article-prepare-display)
4919 (set-window-configuration winconf)))
4922 ;;; Article highlights
4925 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4927 ;;; Internal Variables:
4929 (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\\)\\)"
4930 "Regular expression that matches URLs."
4931 :group 'gnus-article-buttons
4934 (defcustom gnus-button-alist
4935 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4936 0 t gnus-button-message-id 2)
4937 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4938 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4940 gnus-button-fetch-group 4)
4941 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4942 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4943 t gnus-button-message-id 3)
4944 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4945 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4946 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4947 ;; This is how URLs _should_ be embedded in text...
4948 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4950 (,gnus-button-url-regexp 0 t browse-url 0))
4951 "*Alist of regexps matching buttons in article bodies.
4953 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4954 REGEXP: is the string matching text around the button,
4955 BUTTON: is the number of the regexp grouping actually matching the button,
4956 FORM: is a lisp expression which must eval to true for the button to
4958 CALLBACK: is the function to call when the user push this button, and each
4959 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4961 CALLBACK can also be a variable, in that case the value of that
4962 variable it the real callback function."
4963 :group 'gnus-article-buttons
4964 :type '(repeat (list regexp
4965 (integer :tag "Button")
4967 (function :tag "Callback")
4970 (integer :tag "Regexp group")))))
4972 (defcustom gnus-header-button-alist
4973 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4974 0 t gnus-button-message-id 0)
4975 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4976 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4977 0 t gnus-button-mailto 0)
4978 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4979 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4980 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4981 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4982 gnus-button-message-id 3))
4983 "*Alist of headers and regexps to match buttons in article heads.
4985 This alist is very similar to `gnus-button-alist', except that each
4986 alist has an additional HEADER element first in each entry:
4988 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4990 HEADER is a regexp to match a header. For a fuller explanation, see
4991 `gnus-button-alist'."
4992 :group 'gnus-article-buttons
4993 :group 'gnus-article-headers
4994 :type '(repeat (list (regexp :tag "Header")
4996 (integer :tag "Button")
4998 (function :tag "Callback")
5001 (integer :tag "Regexp group")))))
5003 (defvar gnus-button-regexp nil)
5004 (defvar gnus-button-marker-list nil)
5005 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5007 (defvar gnus-button-last nil)
5008 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5012 (defun gnus-article-push-button (event)
5013 "Check text under the mouse pointer for a callback function.
5014 If the text under the mouse pointer has a `gnus-callback' property,
5015 call it with the value of the `gnus-data' text property."
5017 (set-buffer (window-buffer (posn-window (event-start event))))
5018 (let* ((pos (posn-point (event-start event)))
5019 (data (get-text-property pos 'gnus-data))
5020 (fun (get-text-property pos 'gnus-callback)))
5023 (funcall fun data))))
5025 (defun gnus-article-press-button ()
5026 "Check text at point for a callback function.
5027 If the text at point has a `gnus-callback' property,
5028 call it with the value of the `gnus-data' text property."
5030 (let* ((data (get-text-property (point) 'gnus-data))
5031 (fun (get-text-property (point) 'gnus-callback)))
5033 (funcall fun data))))
5035 (defun gnus-article-prev-button (n)
5036 "Move point to N buttons backward.
5037 If N is negative, move forward instead."
5039 (gnus-article-next-button (- n)))
5041 (defun gnus-article-next-button (n)
5042 "Move point to N buttons forward.
5043 If N is negative, move backward instead."
5045 (let ((function (if (< n 0) 'previous-single-property-change
5046 'next-single-property-change))
5047 (inhibit-point-motion-hooks t)
5049 (limit (if (< n 0) (point-min) (point-max))))
5051 (while (and (not (= limit (point)))
5053 ;; Skip past the current button.
5054 (when (get-text-property (point) 'gnus-callback)
5055 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5056 ;; Go to the next (or previous) button.
5057 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5058 ;; Put point at the start of the button.
5059 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5060 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5061 ;; Skip past intangible buttons.
5062 (when (get-text-property (point) 'intangible)
5066 (gnus-message 5 "No more buttons"))
5069 (defun gnus-article-highlight (&optional force)
5070 "Highlight current article.
5071 This function calls `gnus-article-highlight-headers',
5072 `gnus-article-highlight-citation',
5073 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5074 do the highlighting. See the documentation for those functions."
5075 (interactive (list 'force))
5076 (gnus-article-highlight-headers)
5077 (gnus-article-highlight-citation force)
5078 (gnus-article-highlight-signature)
5079 (gnus-article-add-buttons force)
5080 (gnus-article-add-buttons-to-head))
5082 (defun gnus-article-highlight-some (&optional force)
5083 "Highlight current article.
5084 This function calls `gnus-article-highlight-headers',
5085 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5086 do the highlighting. See the documentation for those functions."
5087 (interactive (list 'force))
5088 (gnus-article-highlight-headers)
5089 (gnus-article-highlight-signature)
5090 (gnus-article-add-buttons))
5092 (defun gnus-article-highlight-headers ()
5093 "Highlight article headers as specified by `gnus-header-face-alist'."
5096 (set-buffer gnus-article-buffer)
5098 (let ((alist gnus-header-face-alist)
5099 (buffer-read-only nil)
5100 (case-fold-search t)
5101 (inhibit-point-motion-hooks t)
5102 entry regexp header-face field-face from hpoints fpoints)
5103 (article-narrow-to-head)
5104 (while (setq entry (pop alist))
5105 (goto-char (point-min))
5106 (setq regexp (concat "^\\("
5107 (if (string-equal "" (nth 0 entry))
5111 header-face (nth 1 entry)
5112 field-face (nth 2 entry))
5113 (while (and (re-search-forward regexp nil t)
5117 (unless (search-forward ":" nil t)
5119 (when (and header-face
5120 (not (memq (point) hpoints)))
5121 (push (point) hpoints)
5122 (gnus-put-text-property from (point) 'face header-face))
5123 (when (and field-face
5124 (not (memq (setq from (point)) fpoints)))
5126 (if (re-search-forward "^[^ \t]" nil t)
5128 (goto-char (point-max)))
5129 (gnus-put-text-property from (point) 'face field-face))))))))
5131 (defun gnus-article-highlight-signature ()
5132 "Highlight the signature in an article.
5133 It does this by highlighting everything after
5134 `gnus-signature-separator' using `gnus-signature-face'."
5136 (when gnus-signature-face
5138 (set-buffer gnus-article-buffer)
5139 (let ((buffer-read-only nil)
5140 (inhibit-point-motion-hooks t))
5142 (when (gnus-article-narrow-to-signature)
5143 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5144 'face gnus-signature-face)))))))
5146 (defun gnus-article-buttonize-signature ()
5147 "Add button to the signature."
5150 (set-buffer gnus-article-buffer)
5151 (let ((buffer-read-only nil)
5152 (inhibit-point-motion-hooks t))
5153 (when (gnus-article-search-signature)
5154 (gnus-article-add-button (match-beginning 0) (match-end 0)
5155 'gnus-signature-toggle
5156 (set-marker (make-marker)
5157 (1+ (match-end 0))))))))
5159 (defun gnus-button-in-region-p (b e prop)
5160 "Say whether PROP exists in the region."
5161 (text-property-not-all b e prop nil))
5163 (defun gnus-article-add-buttons (&optional force)
5164 "Find external references in the article and make buttons of them.
5165 \"External references\" are things like Message-IDs and URLs, as
5166 specified by `gnus-button-alist'."
5167 (interactive (list 'force))
5169 (set-buffer gnus-article-buffer)
5170 (let ((buffer-read-only nil)
5171 (inhibit-point-motion-hooks t)
5172 (case-fold-search t)
5173 (alist gnus-button-alist)
5175 ;; Remove all old markers.
5176 (let (marker entry new-list)
5177 (while (setq marker (pop gnus-button-marker-list))
5178 (if (or (< marker (point-min)) (>= marker (point-max)))
5179 (push marker new-list)
5181 (when (setq entry (gnus-button-entry))
5182 (put-text-property (match-beginning (nth 1 entry))
5183 (match-end (nth 1 entry))
5184 'gnus-callback nil))
5185 (set-marker marker nil)))
5186 (setq gnus-button-marker-list new-list))
5187 ;; We skip the headers.
5190 (while (setq entry (pop alist))
5191 (setq regexp (car entry))
5193 (while (re-search-forward regexp nil t)
5194 (let* ((start (and entry (match-beginning (nth 1 entry))))
5195 (end (and entry (match-end (nth 1 entry))))
5196 (from (match-beginning 0)))
5197 (when (and (or (eq t (nth 2 entry))
5198 (eval (nth 2 entry)))
5199 (not (gnus-button-in-region-p
5200 start end 'gnus-callback)))
5201 ;; That optional form returned non-nil, so we add the
5203 (gnus-article-add-button
5204 start end 'gnus-button-push
5205 (car (push (set-marker (make-marker) from)
5206 gnus-button-marker-list))))))))))
5208 ;; Add buttons to the head of an article.
5209 (defun gnus-article-add-buttons-to-head ()
5210 "Add buttons to the head of the article."
5213 (set-buffer gnus-article-buffer)
5215 (let ((buffer-read-only nil)
5216 (inhibit-point-motion-hooks t)
5217 (case-fold-search t)
5218 (alist gnus-header-button-alist)
5220 (article-narrow-to-head)
5222 ;; Each alist entry.
5223 (setq entry (car alist)
5225 (goto-char (point-min))
5226 (while (re-search-forward (car entry) nil t)
5227 ;; Each header matching the entry.
5228 (setq beg (match-beginning 0))
5229 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5230 (match-beginning 0))
5233 (while (re-search-forward (nth 1 entry) end t)
5234 ;; Each match within a header.
5235 (let* ((entry (cdr entry))
5236 (start (match-beginning (nth 1 entry)))
5237 (end (match-end (nth 1 entry)))
5238 (form (nth 2 entry)))
5239 (goto-char (match-end 0))
5241 (gnus-article-add-button
5242 start end (nth 3 entry)
5243 (buffer-substring (match-beginning (nth 4 entry))
5244 (match-end (nth 4 entry)))))))
5245 (goto-char end)))))))
5247 ;;; External functions:
5249 (defun gnus-article-add-button (from to fun &optional data)
5250 "Create a button between FROM and TO with callback FUN and data DATA."
5251 (when gnus-article-button-face
5252 (gnus-overlay-put (gnus-make-overlay from to)
5253 'face gnus-article-button-face))
5254 (gnus-add-text-properties
5256 (nconc (and gnus-article-mouse-face
5257 (list gnus-mouse-face-prop gnus-article-mouse-face))
5258 (list 'gnus-callback fun)
5259 (and data (list 'gnus-data data))))
5260 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5261 ;; Quote `:button-keymap' for Mule 2.3
5262 ;; but it won't work.
5263 ':button-keymap gnus-widget-button-keymap))
5265 ;;; Internal functions:
5267 (defun gnus-article-set-globals ()
5269 (set-buffer gnus-summary-buffer)
5270 (gnus-set-global-variables)))
5272 (defun gnus-signature-toggle (end)
5274 (set-buffer gnus-article-buffer)
5275 (let ((buffer-read-only nil)
5276 (inhibit-point-motion-hooks t)
5277 (limit (next-single-property-change end 'mime-view-entity
5279 (if (text-property-any end limit 'article-type 'signature)
5280 (gnus-remove-text-properties-when
5281 'article-type 'signature end limit
5282 (cons 'article-type (cons 'signature
5283 gnus-hidden-properties)))
5284 (gnus-add-text-properties-when
5285 'article-type nil end limit
5286 (cons 'article-type (cons 'signature
5287 gnus-hidden-properties)))))))
5289 (defun gnus-button-entry ()
5290 ;; Return the first entry in `gnus-button-alist' matching this place.
5291 (let ((alist gnus-button-alist)
5294 (setq entry (pop alist))
5295 (if (looking-at (car entry))
5300 (defun gnus-button-push (marker)
5301 ;; Push button starting at MARKER.
5304 (let* ((entry (gnus-button-entry))
5305 (inhibit-point-motion-hooks t)
5307 (args (mapcar (lambda (group)
5308 (let ((string (match-string group)))
5309 (gnus-set-text-properties
5310 0 (length string) nil string)
5317 (fboundp (symbol-value fun)))
5318 (apply (symbol-value fun) args))
5320 (gnus-message 1 "You must define `%S' to use this button"
5321 (cons fun args)))))))
5323 (defun gnus-button-message-id (message-id)
5326 (set-buffer gnus-summary-buffer)
5327 (gnus-summary-refer-article message-id)))
5329 (defun gnus-button-fetch-group (address)
5330 "Fetch GROUP specified by ADDRESS."
5331 (if (not (string-match "[:/]" address))
5332 ;; This is just a simple group url.
5333 (gnus-group-read-ephemeral-group address gnus-select-method)
5334 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5336 (error "Can't parse %s" address)
5337 (gnus-group-read-ephemeral-group
5338 (match-string 4 address)
5339 `(nntp ,(match-string 1 address)
5340 (nntp-address ,(match-string 1 address))
5341 (nntp-port-number ,(if (match-end 3)
5342 (match-string 3 address)
5345 (defun gnus-url-parse-query-string (query &optional downcase)
5346 (let (retval pairs cur key val)
5347 (setq pairs (split-string query "&"))
5349 (setq cur (car pairs)
5351 (if (not (string-match "=" cur))
5353 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5354 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5356 (setq key (downcase key)))
5357 (setq cur (assoc key retval))
5359 (setcdr cur (cons val (cdr cur)))
5360 (setq retval (cons (list key val) retval)))))
5363 (defun gnus-url-unhex (x)
5370 (defun gnus-url-unhex-string (str &optional allow-newlines)
5371 "Remove %XXX embedded spaces, etc in a url.
5372 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5373 decoding of carriage returns and line feeds in the string, which is normally
5374 forbidden in URL encoding."
5375 (setq str (or str ""))
5377 (case-fold-search t))
5378 (while (string-match "%[0-9a-f][0-9a-f]" str)
5379 (let* ((start (match-beginning 0))
5380 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5382 (gnus-url-unhex (elt str (+ start 2))))))
5384 tmp (substring str 0 start)
5387 (char-to-string code))
5388 ((or (= code ?\n) (= code ?\r))
5390 (t (char-to-string code))))
5391 str (substring str (match-end 0)))))
5392 (setq tmp (concat tmp str))
5395 (defun gnus-url-mailto (url)
5396 ;; Send mail to someone
5397 (when (string-match "mailto:/*\\(.*\\)" url)
5398 (setq url (substring url (match-beginning 1) nil)))
5399 (let (to args subject func)
5400 (if (string-match (regexp-quote "?") url)
5401 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5402 args (gnus-url-parse-query-string
5403 (substring url (match-end 0) nil) t))
5404 (setq to (gnus-url-unhex-string url)))
5405 (setq args (cons (list "to" to) args)
5406 subject (cdr-safe (assoc "subject" args)))
5407 (gnus-setup-message 'reply
5410 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5413 (message-position-on-field (caar args)))
5414 (insert (mapconcat 'identity (cdar args) ", "))
5415 (setq args (cdr args)))
5418 (message-goto-subject)))))
5420 (defun gnus-button-mailto (address)
5422 (set-buffer (gnus-copy-article-buffer))
5423 (message-reply address))
5425 (defalias 'gnus-button-reply 'message-reply)
5427 (defun gnus-button-embedded-url (address)
5428 "Activate ADDRESS with `browse-url'."
5429 (browse-url (gnus-strip-whitespace address)))
5431 (defun gnus-article-smiley-display ()
5432 "Display \"smileys\" as small graphical icons."
5433 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5435 ;;; Next/prev buttons in the article buffer.
5437 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5438 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5440 (defvar gnus-prev-page-map nil)
5441 (unless gnus-prev-page-map
5442 (setq gnus-prev-page-map (make-sparse-keymap))
5443 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5444 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5446 (static-if (featurep 'xemacs)
5447 (defun gnus-insert-prev-page-button ()
5448 (let ((buffer-read-only nil))
5450 gnus-prev-page-line-format nil
5451 `(gnus-prev t local-map ,gnus-prev-page-map
5452 gnus-callback gnus-article-button-prev-page
5453 article-type annotation))))
5454 (defun gnus-insert-prev-page-button ()
5455 (let ((buffer-read-only nil)
5456 (situation (get-text-property (point-min) 'mime-view-situation)))
5457 (set-keymap-parent gnus-prev-page-map (current-local-map))
5459 gnus-prev-page-line-format nil
5460 `(gnus-prev t local-map ,gnus-prev-page-map
5461 gnus-callback gnus-article-button-prev-page
5462 article-type annotation
5463 mime-view-situation ,situation))))
5466 (defvar gnus-next-page-map nil)
5467 (unless gnus-next-page-map
5468 (setq gnus-next-page-map (make-sparse-keymap))
5469 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5470 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5472 (defun gnus-button-next-page ()
5473 "Go to the next page."
5475 (let ((win (selected-window)))
5476 (select-window (get-buffer-window gnus-article-buffer t))
5477 (gnus-article-next-page)
5478 (select-window win)))
5480 (defun gnus-button-prev-page ()
5481 "Go to the prev page."
5483 (let ((win (selected-window)))
5484 (select-window (get-buffer-window gnus-article-buffer t))
5485 (gnus-article-prev-page)
5486 (select-window win)))
5488 (static-if (featurep 'xemacs)
5489 (defun gnus-insert-next-page-button ()
5490 (let ((buffer-read-only nil))
5491 (gnus-eval-format gnus-next-page-line-format nil
5493 t local-map ,gnus-next-page-map
5494 gnus-callback gnus-article-button-next-page
5495 article-type annotation))))
5496 (defun gnus-insert-next-page-button ()
5497 (let ((buffer-read-only nil)
5498 (situation (get-text-property (point-min) 'mime-view-situation)))
5499 (set-keymap-parent gnus-next-page-map (current-local-map))
5500 (gnus-eval-format gnus-next-page-line-format nil
5502 t local-map ,gnus-next-page-map
5503 gnus-callback gnus-article-button-next-page
5504 article-type annotation
5505 mime-view-situation ,situation))))
5508 (defun gnus-article-button-next-page (arg)
5509 "Go to the next page."
5511 (let ((win (selected-window)))
5512 (select-window (get-buffer-window gnus-article-buffer t))
5513 (gnus-article-next-page)
5514 (select-window win)))
5516 (defun gnus-article-button-prev-page (arg)
5517 "Go to the prev page."
5519 (let ((win (selected-window)))
5520 (select-window (get-buffer-window gnus-article-buffer t))
5521 (gnus-article-prev-page)
5522 (select-window win)))
5524 (defvar gnus-decode-header-methods
5525 '(mail-decode-encoded-word-region)
5526 "List of methods used to decode headers.
5528 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5529 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5530 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5531 whose names match REGEXP.
5534 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5535 mail-decode-encoded-word-region
5536 (\"chinese\" . rfc1843-decode-region))
5539 (defvar gnus-decode-header-methods-cache nil)
5541 (defun gnus-multi-decode-header (start end)
5542 "Apply the functions from `gnus-encoded-word-methods' that match."
5543 (unless (and gnus-decode-header-methods-cache
5544 (eq gnus-newsgroup-name
5545 (car gnus-decode-header-methods-cache)))
5546 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5549 (nconc gnus-decode-header-methods-cache (list x))
5550 (if (and gnus-newsgroup-name
5551 (string-match (car x) gnus-newsgroup-name))
5552 (nconc gnus-decode-header-methods-cache
5554 gnus-decode-header-methods))
5555 (let ((xlist gnus-decode-header-methods-cache))
5558 (narrow-to-region start end)
5560 (funcall (pop xlist) (point-min) (point-max))))))
5563 ;;; Treatment top-level handling.
5566 (defun gnus-treat-article (condition &optional part-number total-parts type)
5567 (let ((length (- (point-max) (point-min)))
5568 (alist gnus-treatment-function-alist)
5569 (article-goto-body-goes-to-point-min-p t)
5573 (let ((list gnus-article-treat-types))
5575 (when (string-match (pop list) type)
5576 (throw 'found t)))))))
5577 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5578 (entity (static-unless (featurep 'xemacs)
5579 (when (eq 'head condition)
5580 (get-text-property (point-min) 'mime-view-entity))))
5581 val elem buttonized)
5582 (gnus-run-hooks 'gnus-part-display-hook)
5583 (unless gnus-inhibit-treatment
5584 (while (setq elem (pop alist))
5587 (if (gnus-buffer-live-p gnus-summary-buffer)
5588 (set-buffer gnus-summary-buffer))
5589 (symbol-value (car elem))))
5590 (when (and (or (consp val)
5592 (gnus-treat-predicate val)
5593 (or (not (get (car elem) 'highlight))
5595 (when (and (not buttonized)
5597 '(gnus-treat-hide-signature
5598 gnus-treat-highlight-signature)))
5599 (gnus-article-buttonize-signature)
5600 (setq buttonized t))
5602 (funcall (cadr elem)))))
5603 ;; FSF Emacsen does not inherit the existing text properties
5604 ;; in the new text, so we should do it for `mime-view-entity'.
5605 (static-unless (featurep 'xemacs)
5607 (put-text-property (point-min) (point-max)
5608 'mime-view-entity entity))))))
5610 ;; Dynamic variables.
5612 (defvar part-number)
5613 (defvar total-parts)
5618 (defun gnus-treat-predicate (val)
5623 (stringp (car val)))
5624 (apply 'gnus-or (mapcar `(lambda (s)
5625 (string-match s ,(or gnus-newsgroup-name "")))
5628 (let ((pred (pop val)))
5631 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5633 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5635 (not (gnus-treat-predicate (car val))))
5637 (equal (car val) type))
5639 (error "%S is not a valid predicate" pred)))))
5649 (eq part-number total-parts))
5653 (error "%S is not a valid value" val))))
5655 (defun gnus-article-encrypt-body (protocol &optional n)
5656 "Encrypt the article body."
5659 (or gnus-article-encrypt-protocol
5660 (completing-read "Encrypt protocol: "
5661 gnus-article-encrypt-protocol-alist
5663 current-prefix-arg))
5664 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5666 (error (format "Can't find the encrypt protocol %s" protocol)))
5667 (if (equal gnus-newsgroup-name "nndraft:drafts")
5668 (error "Can't encrypt the article in group nndraft:drafts."))
5669 (if (equal gnus-newsgroup-name "nndraft:queue")
5670 (error "Don't encrypt the article in group nndraft:queue."))
5671 (gnus-summary-iterate n
5673 (set-buffer gnus-summary-buffer)
5674 (let ((mail-parse-charset gnus-newsgroup-charset)
5675 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5676 (summary-buffer gnus-summary-buffer)
5678 (gnus-set-global-variables)
5679 (when (gnus-group-read-only-p)
5680 (error "The current newsgroup does not support article encrypt"))
5681 (gnus-summary-show-article t)
5683 (or (mail-header-references gnus-current-headers) ""))
5684 (set-buffer gnus-article-buffer)
5685 (let* ((buffer-read-only nil)
5687 (mapcar (lambda (field)
5688 (and (save-restriction
5689 (message-narrow-to-head)
5690 (goto-char (point-min))
5691 (search-forward field nil t))
5693 (message-narrow-to-field)
5694 (buffer-substring (point-min) (point-max))
5695 (delete-region (point-min) (point-max))
5697 '("Content-Type:" "Content-Transfer-Encoding:"
5698 "Content-Disposition:"))))
5699 (message-narrow-to-head)
5700 (message-remove-header "MIME-Version")
5701 (goto-char (point-max))
5702 (setq point (point))
5703 (insert (apply 'concat headers))
5705 (narrow-to-region point (point-max))
5706 (let ((message-options message-options))
5707 (message-options-set 'message-sender user-mail-address)
5708 (message-options-set 'message-recipients user-mail-address)
5709 (message-options-set 'message-sign-encrypt 'not)
5711 (goto-char (point-min))
5712 (insert "MIME-Version: 1.0\n")
5714 (gnus-summary-edit-article-done
5715 references nil summary-buffer t))
5716 (when gnus-keep-backlog
5717 (gnus-backlog-remove-article
5718 (car gnus-article-current) (cdr gnus-article-current)))
5720 (when (get-buffer gnus-original-article-buffer)
5721 (set-buffer gnus-original-article-buffer)
5722 (setq gnus-original-article nil)))
5723 (when gnus-use-cache
5724 (gnus-cache-update-article
5725 (car gnus-article-current) (cdr gnus-article-current))))))))
5727 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5728 "The following specs can be used:
5729 %t The security MIME type
5732 %D Details if button is pressed")
5734 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5735 "The following specs can be used:
5736 %t The security MIME type
5739 %D Details if button is pressed")
5741 (defvar gnus-mime-security-button-line-format-alist
5742 '((?t gnus-tmp-type ?s)
5743 (?i gnus-tmp-info ?s)
5744 (?d gnus-tmp-details ?s)
5745 (?D gnus-tmp-pressed-details ?s)))
5747 (defvar gnus-mime-security-button-map
5748 (let ((map (make-sparse-keymap)))
5749 ;; Not for Emacs 21: fixme better.
5750 ;;(set-keymap-parent map gnus-article-mode-map)
5751 (define-key map gnus-mouse-2 'gnus-article-push-button)
5752 (define-key map "\r" 'gnus-article-press-button)
5755 (defvar gnus-mime-security-details-buffer nil)
5757 (defvar gnus-mime-security-button-pressed nil)
5759 (defvar gnus-mime-security-show-details-inline t
5760 "If non-nil, show details in the article buffer.")
5762 (defun gnus-mime-security-verify-or-decrypt (handle)
5763 (mm-remove-parts (cdr handle))
5764 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5767 (delete-region (car region) (cdr region))
5768 (set-marker (car region) nil)
5769 (set-marker (cdr region) nil)))
5770 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5771 (let* ((mm-verify-option 'known)
5772 (mm-decrypt-option 'known)
5773 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5774 (unless (eq nparts (cdr handle))
5775 (mm-destroy-parts (cdr handle))
5776 (setcdr handle nparts))))
5777 (let ((point (point))
5779 (gnus-mime-display-security handle)
5782 (defun gnus-mime-security-show-details (handle)
5783 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5785 (if gnus-mime-security-show-details-inline
5786 (let ((gnus-mime-security-button-pressed t)
5787 (gnus-mime-security-button-line-format
5788 (get-text-property (point) 'gnus-line-format))
5791 (while (eq (get-text-property (point) 'gnus-line-format)
5792 gnus-mime-security-button-line-format)
5795 (delete-region (point)
5796 (or (text-property-not-all
5799 gnus-mime-security-button-line-format)
5801 (gnus-insert-mime-security-button handle))
5802 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5803 (with-current-buffer gnus-mime-security-details-buffer
5806 (setq gnus-mime-security-details-buffer
5807 (gnus-get-buffer-create "*MIME Security Details*")))
5808 (with-current-buffer gnus-mime-security-details-buffer
5810 (goto-char (point-min)))
5811 (pop-to-buffer gnus-mime-security-details-buffer))
5812 (gnus-message 5 "No details."))))
5814 (defun gnus-mime-security-press-button (handle)
5815 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5816 (gnus-mime-security-show-details handle)
5817 (gnus-mime-security-verify-or-decrypt handle)))
5819 (defun gnus-insert-mime-security-button (handle &optional displayed)
5820 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5823 (or (nth 2 (assoc protocol mm-verify-function-alist))
5824 (nth 2 (assoc protocol mm-decrypt-function-alist))
5826 (if (equal (car handle) "multipart/signed")
5827 " Signed" " Encrypted")
5830 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5833 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5834 gnus-tmp-pressed-details
5836 (setq gnus-tmp-details
5837 (if gnus-tmp-details
5838 (concat "\n" gnus-tmp-details) ""))
5839 (setq gnus-tmp-pressed-details
5840 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5845 gnus-mime-security-button-line-format
5846 gnus-mime-security-button-line-format-alist
5847 `(keymap ,gnus-mime-security-button-map
5848 ,@(if (>= (string-to-number emacs-version) 21)
5849 nil ;; XEmacs doesn't care
5850 (list 'local-map gnus-mime-security-button-map))
5851 gnus-callback gnus-mime-security-press-button
5852 gnus-line-format ,gnus-mime-security-button-line-format
5853 article-type annotation
5856 (widget-convert-button
5859 :action 'gnus-widget-press-button
5860 :button-keymap gnus-mime-security-button-map
5862 (lambda (widget/window &optional overlay pos)
5863 ;; Needed to properly clear the message due to a bug in
5864 ;; wid-edit (XEmacs only).
5865 (if (boundp 'help-echo-owns-message)
5866 (setq help-echo-owns-message t))
5869 (aref gnus-mouse-2 0))))))
5871 (defun gnus-mime-display-security (handle)
5873 (narrow-to-region (point) (point))
5874 (gnus-insert-mime-security-button handle)
5875 (gnus-mime-display-mixed (cdr handle))
5878 (let ((gnus-mime-security-button-line-format
5879 gnus-mime-security-button-end-line-format))
5880 (gnus-insert-mime-security-button handle))
5881 (mm-set-handle-multipart-parameter handle 'gnus-region
5882 (cons (set-marker (make-marker)
5884 (set-marker (make-marker)
5891 (defun gnus-article-header-presentation-method (entity situation)
5892 (mime-insert-header entity)
5895 (set-alist 'mime-header-presentation-method-alist
5896 'gnus-original-article-mode
5897 #'gnus-article-header-presentation-method)
5899 (defun gnus-mime-preview-quitting-method ()
5900 (mime-preview-kill-buffer)
5901 (delete-other-windows)
5902 (gnus-article-show-summary)
5903 (gnus-summary-select-article gnus-show-all-headers t))
5905 (set-alist 'mime-preview-quitting-method-alist
5906 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5908 (set-alist 'mime-preview-following-method-alist
5909 'gnus-original-article-mode #'gnus-following-method)
5911 (set-alist 'mime-preview-over-to-previous-method-alist
5912 'gnus-original-article-mode
5914 (if (> (point-min) 1)
5915 (gnus-article-prev-page)
5916 (gnus-article-read-summary-keys
5917 nil (gnus-character-to-event ?P)))))
5919 (set-alist 'mime-preview-over-to-next-method-alist
5920 'gnus-original-article-mode'
5922 (if (< (point-max) (buffer-size))
5923 (gnus-article-next-page)
5924 (gnus-article-read-summary-keys
5925 nil (gnus-character-to-event ?N)))))
5935 (run-hooks 'gnus-art-load-hook)
5937 ;;; gnus-art.el ends here