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****s*** 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 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1529 in an attempt to provide more quoting characters. If you see
1530 something like \222 or \264 where you're expecting some kind of
1531 apostrophe or quotation mark, then try this wash."
1533 (article-translate-strings gnus-article-dumbquotes-map))
1535 (defun article-translate-characters (from to)
1536 "Translate all characters in the body of the article according to FROM and TO.
1537 FROM is a string of characters to translate from; to is a string of
1538 characters to translate to."
1540 (when (article-goto-body)
1541 (let ((buffer-read-only nil)
1542 (x (make-string 225 ?x))
1544 (while (< (incf i) (length x))
1547 (while (< i (length from))
1548 (aset x (aref from i) (aref to i))
1550 (translate-region (point) (point-max) x)))))
1552 (defun article-translate-strings (map)
1553 "Translate all string in the body of the article according to MAP.
1554 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1556 (when (article-goto-body)
1557 (let ((buffer-read-only nil)
1559 (while (setq elem (pop map))
1561 (while (search-forward (car elem) nil t)
1562 (replace-match (cadr elem)))))))))
1564 (defun article-treat-overstrike ()
1565 "Translate overstrikes into bold text."
1568 (when (article-goto-body)
1569 (let ((buffer-read-only nil))
1570 (while (search-forward "\b" nil t)
1571 (let ((next (char-after))
1575 previous (char-after))
1579 ;; We do the boldification/underlining by hiding the
1580 ;; overstrikes and putting the proper text property
1584 (gnus-article-hide-text-type start (point) 'overstrike)
1585 (put-text-property (point) end 'face 'bold))
1587 (gnus-article-hide-text-type
1588 (1- (point)) (1+ (point)) 'overstrike)
1590 start (1- (point)) 'face 'underline))
1592 (gnus-article-hide-text-type start (point) 'overstrike)
1594 (point) end 'face 'underline)))))))))
1596 (defun article-fill-long-lines ()
1597 "Fill lines that are wider than the window width."
1600 (let ((buffer-read-only nil)
1601 (width (window-width (get-buffer-window (current-buffer)))))
1604 (let ((adaptive-fill-mode nil))
1607 (when (>= (current-column) (min fill-column width))
1608 (narrow-to-region (point) (gnus-point-at-bol))
1609 (fill-paragraph nil)
1610 (goto-char (point-max))
1612 (forward-line 1)))))))
1614 (defun article-capitalize-sentences ()
1615 "Capitalize the first word in each sentence."
1618 (let ((buffer-read-only nil)
1619 (paragraph-start "^[\n\^L]"))
1623 (forward-sentence)))))
1625 (defun article-remove-cr ()
1626 "Remove trailing CRs and then translate remaining CRs into LFs."
1629 (let ((buffer-read-only nil))
1630 (goto-char (point-min))
1631 (while (re-search-forward "\r+$" nil t)
1632 (replace-match "" t t))
1633 (goto-char (point-min))
1634 (while (search-forward "\r" nil t)
1635 (replace-match "\n" t t)))))
1637 (defun article-remove-trailing-blank-lines ()
1638 "Remove all trailing blank lines from the article."
1641 (let ((buffer-read-only nil))
1642 (goto-char (point-max))
1646 (while (and (not (bobp))
1647 (looking-at "^[ \t]*$")
1648 (not (gnus-annotation-in-region-p
1649 (point) (gnus-point-at-eol))))
1654 (defun article-display-x-face (&optional force)
1655 "Look for an X-Face header and display it if present."
1656 (interactive (list 'force))
1658 ;; Delete the old process, if any.
1659 (when (process-status "article-x-face")
1660 (delete-process "article-x-face"))
1661 (let ((inhibit-point-motion-hooks t)
1662 (case-fold-search t)
1665 (article-narrow-to-head)
1666 (goto-char (point-min))
1667 (setq from (message-fetch-field "from"))
1668 (goto-char (point-min))
1669 (while (and gnus-article-x-face-command
1672 ;; Check whether this face is censored.
1673 (not gnus-article-x-face-too-ugly)
1674 (and gnus-article-x-face-too-ugly from
1675 (not (string-match gnus-article-x-face-too-ugly
1677 ;; Has to be present.
1678 (re-search-forward "^X-Face:[ \t]*" nil t))
1679 ;; This used to try to do multiple faces (`while' instead of
1680 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1681 ;; work (b) it can crash some versions of Emacs (c) are
1682 ;; multiple faces really something to encourage?
1683 (when (stringp gnus-article-x-face-command)
1685 ;; We now have the area of the buffer where the X-Face is stored.
1688 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1689 ;; We display the face.
1690 (if (symbolp gnus-article-x-face-command)
1691 ;; The command is a lisp function, so we call it.
1692 (if (gnus-functionp gnus-article-x-face-command)
1693 (funcall gnus-article-x-face-command beg end)
1694 (error "%s is not a function" gnus-article-x-face-command))
1695 ;; The command is a string, so we interpret the command
1696 ;; as a, well, command, and fork it off.
1697 (let ((process-connection-type nil))
1698 (process-kill-without-query
1700 "article-x-face" nil shell-file-name shell-command-switch
1701 gnus-article-x-face-command))
1702 (process-send-region "article-x-face" beg end)
1703 (process-send-eof "article-x-face"))))))))))
1705 (defun article-decode-mime-words ()
1706 "Decode all MIME-encoded words in the article."
1709 (set-buffer gnus-article-buffer)
1710 (let ((inhibit-point-motion-hooks t)
1712 (mail-parse-charset gnus-newsgroup-charset)
1713 (mail-parse-ignored-charsets
1714 (save-excursion (set-buffer gnus-summary-buffer)
1715 gnus-newsgroup-ignored-charsets)))
1716 (mail-decode-encoded-word-region (point-min) (point-max)))))
1718 (defun article-decode-charset (&optional prompt)
1719 "Decode charset-encoded text in the article.
1720 If PROMPT (the prefix), prompt for a coding system to use."
1722 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1724 (mail-parse-charset gnus-newsgroup-charset)
1725 (mail-parse-ignored-charsets
1726 (save-excursion (condition-case nil
1727 (set-buffer gnus-summary-buffer)
1729 gnus-newsgroup-ignored-charsets))
1730 ct cte ctl charset format)
1733 (article-narrow-to-head)
1734 (setq ct (message-fetch-field "Content-Type" t)
1735 cte (message-fetch-field "Content-Transfer-Encoding" t)
1736 ctl (and ct (ignore-errors
1737 (mail-header-parse-content-type ct)))
1740 (mm-read-coding-system "Charset to decode: "))
1742 (mail-content-type-get ctl 'charset)))
1743 format (and ctl (mail-content-type-get ctl 'format)))
1745 (setq cte (mail-header-strip cte)))
1746 (if (and ctl (not (string-match "/" (car ctl))))
1748 (goto-char (point-max)))
1751 (narrow-to-region (point) (point-max))
1752 (when (and (eq mail-parse-charset 'gnus-decoded)
1753 (eq (mm-body-7-or-8) '8bit))
1754 ;; The text code could have been decoded.
1755 (setq charset mail-parse-charset))
1756 (when (and (or (not ctl)
1757 (equal (car ctl) "text/plain"))
1758 (not format)) ;; article with format will decode later.
1760 charset (and cte (intern (downcase
1761 (gnus-strip-whitespace cte))))
1764 (defun article-decode-encoded-words ()
1765 "Remove encoded-word encoding from headers."
1766 (let (buffer-read-only)
1767 (let ((charset (save-excursion
1768 (set-buffer gnus-summary-buffer)
1769 default-mime-charset)))
1770 (mime-decode-header-in-buffer charset)
1773 (defun article-de-quoted-unreadable (&optional force)
1774 "Translate a quoted-printable-encoded article.
1775 If FORCE, decode the article whether it is marked as quoted-printable
1777 (interactive (list 'force))
1779 (let ((buffer-read-only nil) type charset)
1780 (if (gnus-buffer-live-p gnus-original-article-buffer)
1781 (with-current-buffer gnus-original-article-buffer
1783 (gnus-fetch-field "content-transfer-encoding"))
1784 (let* ((ct (gnus-fetch-field "content-type"))
1787 (mail-header-parse-content-type ct)))))
1788 (setq charset (and ctl
1789 (mail-content-type-get ctl 'charset)))
1790 (if (stringp charset)
1791 (setq charset (intern (downcase charset)))))))
1793 (setq charset gnus-newsgroup-charset))
1795 (and type (let ((case-fold-search t))
1796 (string-match "quoted-printable" type))))
1798 (quoted-printable-decode-region
1799 (point) (point-max) (mm-charset-to-coding-system charset))))))
1801 (defun article-de-base64-unreadable (&optional force)
1802 "Translate a base64 article.
1803 If FORCE, decode the article whether it is marked as base64 not."
1804 (interactive (list 'force))
1806 (let ((buffer-read-only nil) type charset)
1807 (if (gnus-buffer-live-p gnus-original-article-buffer)
1808 (with-current-buffer gnus-original-article-buffer
1810 (gnus-fetch-field "content-transfer-encoding"))
1811 (let* ((ct (gnus-fetch-field "content-type"))
1814 (mail-header-parse-content-type ct)))))
1815 (setq charset (and ctl
1816 (mail-content-type-get ctl 'charset)))
1817 (if (stringp charset)
1818 (setq charset (intern (downcase charset)))))))
1820 (setq charset gnus-newsgroup-charset))
1822 (and type (let ((case-fold-search t))
1823 (string-match "base64" type))))
1826 (narrow-to-region (point) (point-max))
1827 (base64-decode-region (point-min) (point-max))
1828 (mm-decode-coding-region
1829 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1834 (defun article-decode-HZ ()
1835 "Translate a HZ-encoded article."
1839 (let ((buffer-read-only nil))
1840 (rfc1843-decode-region (point-min) (point-max)))))
1842 (defun article-wash-html ()
1843 "Format an html article."
1846 (let ((buffer-read-only nil)
1848 (if (gnus-buffer-live-p gnus-original-article-buffer)
1849 (with-current-buffer gnus-original-article-buffer
1850 (let* ((ct (gnus-fetch-field "content-type"))
1853 (mail-header-parse-content-type ct)))))
1854 (setq charset (and ctl
1855 (mail-content-type-get ctl 'charset)))
1856 (if (stringp charset)
1857 (setq charset (intern (downcase charset)))))))
1859 (setq charset gnus-newsgroup-charset))
1861 (save-window-excursion
1863 (narrow-to-region (point) (point-max))
1865 (let ((w3-strict-width (window-width))
1866 (url-standalone-mode t))
1868 (w3-region (point-min) (point-max))
1871 (defun article-hide-list-identifiers ()
1872 "Remove list identifies from the Subject header.
1873 The `gnus-list-identifiers' variable specifies what to do."
1877 (let ((inhibit-point-motion-hooks t)
1879 (article-narrow-to-head)
1880 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1881 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1883 (goto-char (point-min))
1884 (when (re-search-forward
1885 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1886 " *\\)\\)+\\(Re: +\\)?\\)")
1888 (let ((s (or (match-string 3) (match-string 5))))
1889 (delete-region (match-beginning 1) (match-end 1))
1891 (goto-char (match-beginning 1))
1894 (defun article-hide-pgp ()
1895 "Remove any PGP headers and signatures in the current article."
1899 (let ((inhibit-point-motion-hooks t)
1900 buffer-read-only beg end)
1902 ;; Hide the "header".
1903 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1904 (push 'pgp gnus-article-wash-types)
1905 (delete-region (match-beginning 0) (match-end 0))
1906 ;; Remove armor headers (rfc2440 6.2)
1907 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1910 ;; Hide the actual signature.
1911 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1912 (setq end (1+ (match-beginning 0)))
1915 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1917 ;; Perhaps we shouldn't hide to the end of the buffer
1918 ;; if there is no end to the signature?
1920 ;; Hide "- " PGP quotation markers.
1922 (narrow-to-region beg end)
1923 (goto-char (point-min))
1924 (while (re-search-forward "^- " nil t)
1926 (match-beginning 0) (match-end 0)))
1928 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1930 (defun article-hide-pem (&optional arg)
1931 "Toggle hiding of any PEM headers and signatures in the current article.
1932 If given a negative prefix, always show; if given a positive prefix,
1934 (interactive (gnus-article-hidden-arg))
1935 (unless (gnus-article-check-hidden-text 'pem arg)
1937 (let (buffer-read-only end)
1938 (goto-char (point-min))
1939 ;; Hide the horrendously ugly "header".
1940 (when (and (search-forward
1941 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1943 (setq end (1+ (match-beginning 0))))
1944 (push 'pem gnus-article-wash-types)
1945 (gnus-article-hide-text-type
1947 (if (search-forward "\n\n" nil t)
1951 ;; Hide the trailer as well
1952 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1954 (gnus-article-hide-text-type
1955 (match-beginning 0) (match-end 0) 'pem)))))))
1957 (defun article-strip-banner ()
1958 "Strip the banner specified by the `banner' group parameter."
1962 (let ((inhibit-point-motion-hooks t)
1963 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1964 (gnus-signature-limit nil)
1965 buffer-read-only beg end)
1969 ((eq banner 'signature)
1970 (when (gnus-article-narrow-to-signature)
1973 (delete-region (point) (point-max))))
1975 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1976 (while (re-search-forward banner nil t)
1977 (delete-region (match-beginning 0) (match-end 0)))))
1979 (while (re-search-forward banner nil t)
1980 (delete-region (match-beginning 0) (match-end 0))))))))))
1982 (defun article-babel ()
1983 "Translate article using an online translation service."
1987 (set-buffer gnus-article-buffer)
1988 (when (article-goto-body)
1989 (let* ((buffer-read-only nil)
1992 (orig (buffer-substring start end))
1993 (trans (babel-as-string orig)))
1995 (narrow-to-region start end)
1996 (delete-region start end)
1999 (defun article-hide-signature (&optional arg)
2000 "Hide the signature in the current article.
2001 If given a negative prefix, always show; if given a positive prefix,
2003 (interactive (gnus-article-hidden-arg))
2009 (article-goto-body))
2010 (goto-char (point-min)))
2011 (unless (gnus-article-check-hidden-text 'signature arg)
2012 (let ((buffer-read-only nil)
2014 (while (setq button (text-property-any button (point-max)
2016 'gnus-signature-toggle))
2017 (setq button (text-property-not-all button (point-max)
2019 'gnus-signature-toggle))
2020 (when (and button (not (eobp)))
2021 (gnus-article-hide-text-type
2023 (next-single-property-change (1+ button) 'mime-view-entity
2027 (defun article-strip-headers-in-body ()
2028 "Strip offensive headers from bodies."
2032 (let ((case-fold-search t))
2033 (when (looking-at "x-no-archive:")
2034 (gnus-delete-line)))))
2036 (defun article-strip-leading-blank-lines ()
2037 "Remove all blank lines from the beginning of the article."
2040 (let ((inhibit-point-motion-hooks t)
2042 (when (article-goto-body)
2043 (while (and (not (eobp))
2044 (looking-at "[ \t]*$"))
2045 (gnus-delete-line))))))
2047 (defun article-narrow-to-head ()
2048 "Narrow the buffer to the head of the message.
2049 Point is left at the beginning of the narrowed-to region."
2051 (goto-char (point-min))
2052 (if (search-forward "\n\n" nil 1)
2055 (goto-char (point-min)))
2057 (defun article-goto-body ()
2058 "Place point at the start of the body."
2059 (goto-char (point-min))
2061 ;; This variable is only bound when dealing with separate
2063 (article-goto-body-goes-to-point-min-p
2065 ((search-forward "\n\n" nil t)
2068 (goto-char (point-max))
2071 (defun article-strip-multiple-blank-lines ()
2072 "Replace consecutive blank lines with one empty line."
2075 (let ((inhibit-point-motion-hooks t)
2077 ;; First make all blank lines empty.
2079 (while (re-search-forward "^[ \t]+$" nil t)
2080 (unless (gnus-annotation-in-region-p
2081 (match-beginning 0) (match-end 0))
2082 (replace-match "" nil t)))
2083 ;; Then replace multiple empty lines with a single empty line.
2085 (while (re-search-forward "\n\n\n+" nil t)
2086 (unless (gnus-annotation-in-region-p
2087 (match-beginning 0) (match-end 0))
2088 (replace-match "\n\n" t t))))))
2090 (defun article-strip-leading-space ()
2091 "Remove all white space from the beginning of the lines in the article."
2094 (let ((inhibit-point-motion-hooks t)
2097 (while (re-search-forward "^[ \t]+" nil t)
2098 (replace-match "" t t)))))
2100 (defun article-strip-trailing-space ()
2101 "Remove all white space from the end of the lines in the article."
2104 (let ((inhibit-point-motion-hooks t)
2107 (while (re-search-forward "[ \t]+$" nil t)
2108 (replace-match "" t t)))))
2110 (defun article-strip-blank-lines ()
2111 "Strip leading, trailing and multiple blank lines."
2113 (article-strip-leading-blank-lines)
2114 (article-remove-trailing-blank-lines)
2115 (article-strip-multiple-blank-lines))
2117 (defun article-strip-all-blank-lines ()
2118 "Strip all blank lines."
2121 (let ((inhibit-point-motion-hooks t)
2124 (while (re-search-forward "^[ \t]*\n" nil t)
2125 (replace-match "" t t)))))
2127 (defun gnus-article-narrow-to-signature ()
2128 "Narrow to the signature; return t if a signature is found, else nil."
2129 (let ((inhibit-point-motion-hooks t))
2130 (when (gnus-article-search-signature)
2132 ;; Check whether we have some limits to what we consider
2133 ;; to be a signature.
2134 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2135 (list gnus-signature-limit)))
2137 (while (setq limit (pop limits))
2138 (if (or (and (integerp limit)
2139 (< (- (point-max) (point)) limit))
2141 (< (count-lines (point) (point-max)) limit))
2142 (and (gnus-functionp limit)
2144 (and (stringp limit)
2145 (not (re-search-forward limit nil t))))
2146 () ; This limit did not succeed.
2150 (narrow-to-region (point) (point-max))
2153 (defun gnus-article-search-signature ()
2154 "Search the current buffer for the signature separator.
2155 Put point at the beginning of the signature separator."
2156 (let ((cur (point)))
2157 (goto-char (point-max))
2158 (if (if (stringp gnus-signature-separator)
2159 (re-search-backward gnus-signature-separator nil t)
2160 (let ((seps gnus-signature-separator))
2162 (not (re-search-backward (car seps) nil t)))
2169 (defun gnus-article-hidden-arg ()
2170 "Return the current prefix arg as a number, or 0 if no prefix."
2171 (list (if current-prefix-arg
2172 (prefix-numeric-value current-prefix-arg)
2175 (defun gnus-article-check-hidden-text (type arg)
2176 "Return nil if hiding is necessary.
2177 Arg can be nil or a number. Nil and positive means hide, negative
2178 means show, 0 means toggle."
2181 (let ((hide (gnus-article-hidden-text-p type)))
2187 (gnus-article-show-hidden-text type))
2189 (if (eq hide 'hidden)
2190 (gnus-article-show-hidden-text type)
2193 (defun gnus-article-hidden-text-p (type)
2194 "Say whether the current buffer contains hidden text of type TYPE."
2195 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2197 (not (get-text-property pos 'invisible))
2198 (not (get-text-property pos 'dummy-invisible)))
2200 (text-property-any (1+ pos) (point-max) 'article-type type)))
2205 (defun gnus-article-show-hidden-text (type &optional dummy)
2206 "Show all hidden text of type TYPE.
2207 Originally it is hide instead of DUMMY."
2208 (let ((buffer-read-only nil)
2209 (inhibit-point-motion-hooks t))
2210 (gnus-remove-text-properties-when
2212 (point-min) (point-max)
2213 (cons 'article-type (cons type
2214 gnus-hidden-properties)))))
2216 (defconst article-time-units
2217 `((year . ,(* 365.25 24 60 60))
2218 (week . ,(* 7 24 60 60))
2219 (day . ,(* 24 60 60))
2223 "Mapping from time units to seconds.")
2225 (defun article-date-ut (&optional type highlight header)
2226 "Convert DATE date to universal time in the current article.
2227 If TYPE is `local', convert to local time; if it is `lapsed', output
2228 how much time has lapsed since DATE. For `lapsed', the value of
2229 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2230 should replace the \"Date:\" one, or should be added below it."
2231 (interactive (list 'ut t))
2232 (let* ((header (or header
2233 (and (eq 1 (point-min))
2234 (mail-header-date (save-excursion
2235 (set-buffer gnus-summary-buffer)
2236 gnus-current-headers)))
2237 (message-fetch-field "date")
2239 (date (if (vectorp header) (mail-header-date header)
2241 (inhibit-point-motion-hooks t)
2242 bface eface date-pos)
2243 (when (and date (not (string= date "")))
2246 (article-narrow-to-head)
2247 (when (or (and (eq type 'lapsed)
2248 gnus-article-date-lapsed-new-header
2249 ;; Attempt to get the face of X-Sent first.
2250 (re-search-forward "^X-Sent:[ \t]" nil t))
2251 (re-search-forward "^Date:[ \t]" nil t)
2252 ;; If Date is missing, try again for X-Sent.
2253 (re-search-forward "^X-Sent:[ \t]" nil t))
2254 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2255 date (or (get-text-property (gnus-point-at-bol)
2258 eface (get-text-property (1- (gnus-point-at-eol))
2260 (let ((buffer-read-only nil))
2261 ;; Delete any old X-Sent headers.
2262 (when (setq date-pos
2263 (text-property-any (point-min) (point-max)
2264 'article-date-lapsed t))
2265 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2266 (delete-region (match-beginning 0)
2267 (progn (forward-line 1) (point))))
2268 (goto-char (point-min))
2269 ;; Delete any old Date headers.
2270 (while (re-search-forward "^Date:[ \t]" nil t)
2272 (setq date-pos (match-beginning 0)))
2273 (unless (and (eq type 'lapsed)
2274 gnus-article-date-lapsed-new-header)
2275 (delete-region (match-beginning 0)
2276 (progn (message-next-header) (point)))))
2279 (goto-char date-pos)
2281 ;; Possibly, Date has been deleted.
2283 (when (and (eq type 'lapsed)
2284 gnus-article-date-lapsed-new-header
2285 (looking-at "Date:"))
2287 (goto-char (point-min)))
2288 (insert (article-make-date-line date type))
2289 (when (eq type 'lapsed)
2290 (put-text-property (gnus-point-at-bol) (point)
2291 'article-date-lapsed t))
2295 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2296 (put-text-property (match-beginning 1) (1+ (match-end 1))
2297 'original-date date)
2298 (put-text-property (match-beginning 1) (1+ (match-end 1))
2300 (put-text-property (match-beginning 2) (match-end 2)
2303 (defun article-make-date-line (date type)
2304 "Return a DATE line of TYPE."
2305 (let ((time (condition-case ()
2309 ;; Convert to the local timezone. We have to slap a
2310 ;; `condition-case' round the calls to the timezone
2311 ;; functions since they aren't particularly resistant to
2314 (let ((tz (car (current-time-zone time))))
2315 (format "Date: %s %s%02d%02d" (current-time-string time)
2316 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2317 (/ (% (abs tz) 3600) 60))))
2318 ;; Convert to Universal Time.
2321 (current-time-string
2322 (let* ((e (parse-time-string date))
2323 (tm (apply 'encode-time e))
2325 (ls (- (cadr tm) (car (current-time-zone time)))))
2326 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2327 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2330 ;; Get the original date from the article.
2331 ((eq type 'original)
2332 (concat "Date: " (if (string-match "\n+$" date)
2333 (substring date 0 (match-beginning 0))
2335 ;; Let the user define the format.
2337 (if (gnus-functionp gnus-article-time-format)
2338 (funcall gnus-article-time-format time)
2341 (format-time-string gnus-article-time-format time))))
2344 (let ((tz (car (current-time-zone time))))
2347 (format-time-string "%Y%m%dT%H%M%S" time)
2348 (format "%s%02d%02d"
2349 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2350 (/ (% (abs tz) 3600) 60)))))
2351 ;; Do an X-Sent lapsed format.
2353 ;; If the date is seriously mangled, the timezone functions are
2354 ;; liable to bug out, so we ignore all errors.
2355 (let* ((now (current-time))
2356 (real-time (subtract-time now time))
2357 (real-sec (and real-time
2358 (+ (* (float (car real-time)) 65536)
2360 (sec (and real-time (abs real-sec)))
2370 ;; This is a bit convoluted, but basically we go
2371 ;; through the time units for years, weeks, etc,
2372 ;; and divide things to see whether that results
2373 ;; in positive answers.
2376 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2377 ;; The (remaining) seconds are too few to
2378 ;; be divided into this time unit.
2380 ;; It's big enough, so we output it.
2381 (setq sec (- sec (* num (cdr unit))))
2383 (concat (if prev ", " "") (int-to-string
2385 " " (symbol-name (car unit))
2386 (if (> num 1) "s" ""))
2388 article-time-units "")
2389 ;; If dates are odd, then it might appear like the
2390 ;; article was sent in the future.
2393 " in the future"))))))
2395 (error "Unknown conversion type: %s" type)))))
2397 (defun article-date-local (&optional highlight)
2398 "Convert the current article date to the local timezone."
2399 (interactive (list t))
2400 (article-date-ut 'local highlight))
2402 (defun article-date-original (&optional highlight)
2403 "Convert the current article date to what it was originally.
2404 This is only useful if you have used some other date conversion
2405 function and want to see what the date was before converting."
2406 (interactive (list t))
2407 (article-date-ut 'original highlight))
2409 (defun article-date-lapsed (&optional highlight)
2410 "Convert the current article date to time lapsed since it was sent."
2411 (interactive (list t))
2412 (article-date-ut 'lapsed highlight))
2414 (defun article-update-date-lapsed ()
2415 "Function to be run from a timer to update the lapsed time line."
2416 (let (deactivate-mark)
2421 (set-buffer (window-buffer w))
2422 (when (eq major-mode 'gnus-article-mode)
2423 (goto-char (point-min))
2424 (when (re-search-forward "^X-Sent:" nil t)
2425 (article-date-lapsed t))))
2428 (defun gnus-start-date-timer (&optional n)
2429 "Start a timer to update the X-Sent header in the article buffers.
2430 The numerical prefix says how frequently (in seconds) the function
2435 (gnus-stop-date-timer)
2436 (setq article-lapsed-timer
2437 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2439 (defun gnus-stop-date-timer ()
2440 "Stop the X-Sent timer."
2442 (when article-lapsed-timer
2443 (nnheader-cancel-timer article-lapsed-timer)
2444 (setq article-lapsed-timer nil)))
2446 (defun article-date-user (&optional highlight)
2447 "Convert the current article date to the user-defined format.
2448 This format is defined by the `gnus-article-time-format' variable."
2449 (interactive (list t))
2450 (article-date-ut 'user highlight))
2452 (defun article-date-iso8601 (&optional highlight)
2453 "Convert the current article date to ISO8601."
2454 (interactive (list t))
2455 (article-date-ut 'iso8601 highlight))
2457 (defun article-show-all ()
2458 "Show all hidden text in the article buffer."
2462 (let ((buffer-read-only nil))
2463 (gnus-article-unhide-text (point-min) (point-max))
2464 (gnus-remove-text-with-property 'gnus-prev)
2465 (gnus-remove-text-with-property 'gnus-next))))
2467 (defun article-show-all-headers ()
2468 "Show all hidden headers in the article buffer."
2473 (article-narrow-to-head)
2474 (let ((buffer-read-only nil))
2475 (gnus-article-unhide-text (point-min) (point-max))))))
2477 (defun article-emphasize (&optional arg)
2478 "Emphasize text according to `gnus-emphasis-alist'."
2479 (interactive (gnus-article-hidden-arg))
2480 (unless (gnus-article-check-hidden-text 'emphasis arg)
2484 (with-current-buffer gnus-summary-buffer
2485 gnus-article-emphasis-alist)
2487 gnus-emphasis-alist))
2488 (buffer-read-only nil)
2489 (props (append '(article-type emphasis)
2490 gnus-hidden-properties))
2491 regexp elem beg invisible visible face)
2494 (while (setq elem (pop alist))
2496 (setq regexp (car elem)
2497 invisible (nth 1 elem)
2498 visible (nth 2 elem)
2500 (while (re-search-forward regexp nil t)
2501 (when (and (match-beginning visible) (match-beginning invisible))
2502 (push 'emphasis gnus-article-wash-types)
2503 (gnus-article-hide-text
2504 (match-beginning invisible) (match-end invisible) props)
2505 (gnus-article-unhide-text-type
2506 (match-beginning visible) (match-end visible) 'emphasis)
2507 (gnus-put-text-property-excluding-newlines
2508 (match-beginning visible) (match-end visible) 'face face)
2509 (goto-char (match-end invisible)))))))))
2511 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2512 "Setup newsgroup emphasis alist."
2513 (unless gnus-article-emphasis-alist
2514 (let ((name (and gnus-newsgroup-name
2515 (gnus-group-real-name gnus-newsgroup-name))))
2516 (make-local-variable 'gnus-article-emphasis-alist)
2517 (setq gnus-article-emphasis-alist
2519 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2520 (while (setq elem (pop alist))
2521 (when (and name (string-match (car elem) name))
2523 highlight (copy-sequence (cdr elem)))))
2525 (copy-sequence highlight-words)
2526 (if gnus-newsgroup-name
2527 (copy-sequence (gnus-group-find-parameter
2528 gnus-newsgroup-name 'highlight-words t)))
2529 gnus-emphasis-alist)))))
2531 (defvar gnus-summary-article-menu)
2532 (defvar gnus-summary-post-menu)
2534 ;;; Saving functions.
2536 (defun gnus-article-save (save-buffer file &optional num)
2537 "Save the currently selected article."
2538 (unless gnus-save-all-headers
2539 ;; Remove headers according to `gnus-saved-headers'.
2540 (let ((gnus-visible-headers
2541 (or gnus-saved-headers gnus-visible-headers))
2542 (gnus-article-buffer save-buffer))
2544 (set-buffer save-buffer)
2545 (article-hide-headers 1 t))))
2546 (save-window-excursion
2547 (if (not gnus-default-article-saver)
2548 (error "No default saver is defined")
2549 ;; !!! Magic! The saving functions all save
2550 ;; `gnus-save-article-buffer' (or so they think), but we
2551 ;; bind that variable to our save-buffer.
2552 (set-buffer gnus-article-buffer)
2553 (let* ((gnus-save-article-buffer save-buffer)
2556 ((not gnus-prompt-before-saving) 'default)
2557 ((eq gnus-prompt-before-saving 'always) nil)
2559 (gnus-number-of-articles-to-be-saved
2560 (when (eq gnus-prompt-before-saving t)
2562 (set-buffer gnus-article-current-summary)
2563 (funcall gnus-default-article-saver filename)))))
2565 (defun gnus-read-save-file-name (prompt &optional filename
2566 function group headers variable)
2568 (funcall function group headers (symbol-value variable)))
2573 ((eq filename 'default)
2579 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2582 (if (and gnus-number-of-articles-to-be-saved
2583 (> gnus-number-of-articles-to-be-saved 1))
2584 (format "these %d articles"
2585 gnus-number-of-articles-to-be-saved)
2588 ;; Let the split methods have their say.
2590 ;; No split name was found.
2593 (concat prompt " (default "
2594 (file-name-nondirectory default-name) ") ")
2595 (file-name-directory default-name)
2597 ;; A single group name is returned.
2598 ((stringp split-name)
2600 (funcall function split-name headers
2601 (symbol-value variable)))
2603 (concat prompt " (default "
2604 (file-name-nondirectory default-name) ") ")
2605 (file-name-directory default-name)
2607 ;; A single split name was found
2608 ((= 1 (length split-name))
2609 (let* ((name (expand-file-name
2611 gnus-article-save-directory))
2612 (dir (cond ((file-directory-p name)
2613 (file-name-as-directory name))
2614 ((file-exists-p name) name)
2615 (t gnus-article-save-directory))))
2617 (concat prompt " (default " name ") ")
2619 ;; A list of splits was found.
2621 (setq split-name (nreverse split-name))
2623 (let ((file-name-history
2624 (nconc split-name file-name-history)))
2628 (concat prompt " (`M-p' for defaults) ")
2629 gnus-article-save-directory
2631 gnus-article-save-directory)))
2632 (car (push result file-name-history)))))))
2633 ;; Create the directory.
2634 (gnus-make-directory (file-name-directory file))
2635 ;; If we have read a directory, we append the default file name.
2636 (when (file-directory-p file)
2637 (setq file (expand-file-name (file-name-nondirectory
2639 (file-name-as-directory file))))
2640 ;; Possibly translate some characters.
2641 (nnheader-translate-file-chars file))))))
2642 (gnus-make-directory (file-name-directory result))
2643 (set variable result)))
2645 (defun gnus-article-archive-name (group)
2646 "Return the first instance of an \"Archive-name\" in the current buffer."
2647 (let ((case-fold-search t))
2648 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2649 (nnheader-concat gnus-article-save-directory
2650 (match-string 1)))))
2652 (defun gnus-article-nndoc-name (group)
2653 "If GROUP is an nndoc group, return the name of the parent group."
2654 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2655 (gnus-group-get-parameter group 'save-article-group)))
2657 (defun gnus-summary-save-in-rmail (&optional filename)
2658 "Append this article to Rmail file.
2659 Optional argument FILENAME specifies file name.
2660 Directory to save to is default to `gnus-article-save-directory'."
2661 (setq filename (gnus-read-save-file-name
2662 "Save %s in rmail file:" filename
2663 gnus-rmail-save-name gnus-newsgroup-name
2664 gnus-current-headers 'gnus-newsgroup-last-rmail))
2665 (gnus-eval-in-buffer-window gnus-save-article-buffer
2669 (gnus-output-to-rmail filename))))
2672 (defun gnus-summary-save-in-mail (&optional filename)
2673 "Append this article to Unix mail file.
2674 Optional argument FILENAME specifies file name.
2675 Directory to save to is default to `gnus-article-save-directory'."
2676 (setq filename (gnus-read-save-file-name
2677 "Save %s in Unix mail file:" filename
2678 gnus-mail-save-name gnus-newsgroup-name
2679 gnus-current-headers 'gnus-newsgroup-last-mail))
2680 (gnus-eval-in-buffer-window gnus-save-article-buffer
2684 (if (and (file-readable-p filename)
2685 (mail-file-babyl-p filename))
2686 (rmail-output-to-rmail-file filename t)
2687 (gnus-output-to-mail filename)))))
2690 (defun gnus-summary-save-in-file (&optional filename overwrite)
2691 "Append this article to file.
2692 Optional argument FILENAME specifies file name.
2693 Directory to save to is default to `gnus-article-save-directory'."
2694 (setq filename (gnus-read-save-file-name
2695 "Save %s in file:" filename
2696 gnus-file-save-name gnus-newsgroup-name
2697 gnus-current-headers 'gnus-newsgroup-last-file))
2698 (gnus-eval-in-buffer-window gnus-save-article-buffer
2702 (when (and overwrite
2703 (file-exists-p filename))
2704 (delete-file filename))
2705 (gnus-output-to-file filename))))
2708 (defun gnus-summary-write-to-file (&optional filename)
2709 "Write this article to a file.
2710 Optional argument FILENAME specifies file name.
2711 The directory to save in defaults to `gnus-article-save-directory'."
2712 (gnus-summary-save-in-file nil t))
2714 (defun gnus-summary-save-body-in-file (&optional filename)
2715 "Append this article body to a file.
2716 Optional argument FILENAME specifies file name.
2717 The directory to save in defaults to `gnus-article-save-directory'."
2718 (setq filename (gnus-read-save-file-name
2719 "Save %s body in file:" filename
2720 gnus-file-save-name gnus-newsgroup-name
2721 gnus-current-headers 'gnus-newsgroup-last-file))
2722 (gnus-eval-in-buffer-window gnus-save-article-buffer
2726 (when (article-goto-body)
2727 (narrow-to-region (point) (point-max)))
2728 (gnus-output-to-file filename))))
2731 (defun gnus-summary-save-in-pipe (&optional command)
2732 "Pipe this article to subprocess."
2734 (cond ((and (eq command 'default)
2735 gnus-last-shell-command)
2736 gnus-last-shell-command)
2740 "Shell command on %s: "
2741 (if (and gnus-number-of-articles-to-be-saved
2742 (> gnus-number-of-articles-to-be-saved 1))
2743 (format "these %d articles"
2744 gnus-number-of-articles-to-be-saved)
2746 gnus-last-shell-command))))
2747 (when (string-equal command "")
2748 (setq command gnus-last-shell-command))
2749 (gnus-eval-in-buffer-window gnus-article-buffer
2752 (shell-command-on-region (point-min) (point-max) command nil)))
2753 (setq gnus-last-shell-command command))
2755 ;;; Article file names when saving.
2757 (defun gnus-capitalize-newsgroup (newsgroup)
2758 "Capitalize NEWSGROUP name."
2759 (when (not (zerop (length newsgroup)))
2760 (concat (char-to-string (upcase (aref newsgroup 0)))
2761 (substring newsgroup 1))))
2763 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2764 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2765 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2766 Otherwise, it is like ~/News/news/group/num."
2769 (concat (if (gnus-use-long-file-name 'not-save)
2770 (gnus-capitalize-newsgroup newsgroup)
2771 (gnus-newsgroup-directory-form newsgroup))
2772 "/" (int-to-string (mail-header-number headers)))
2773 gnus-article-save-directory)))
2775 (string-equal (file-name-directory default)
2776 (file-name-directory last-file))
2777 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2779 (or last-file default))))
2781 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2782 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2783 If variable `gnus-use-long-file-name' is non-nil, it is
2784 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2787 (concat (if (gnus-use-long-file-name 'not-save)
2789 (gnus-newsgroup-directory-form newsgroup))
2790 "/" (int-to-string (mail-header-number headers)))
2791 gnus-article-save-directory)))
2793 (string-equal (file-name-directory default)
2794 (file-name-directory last-file))
2795 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2797 (or last-file default))))
2799 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2800 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2801 If variable `gnus-use-long-file-name' is non-nil, it is
2802 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2805 (if (gnus-use-long-file-name 'not-save)
2807 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2808 gnus-article-save-directory)))
2810 (defun article-verify-x-pgp-sig ()
2813 (if (gnus-buffer-live-p gnus-original-article-buffer)
2814 (let ((sig (with-current-buffer gnus-original-article-buffer
2815 (gnus-fetch-field "X-PGP-Sig")))
2819 (mml2015-clear-verify-function))
2821 (insert-buffer gnus-original-article-buffer)
2822 (setq items (split-string sig))
2823 (message-narrow-to-head)
2824 (let ((inhibit-point-motion-hooks t)
2825 (case-fold-search t))
2826 ;; Don't verify multiple headers.
2827 (setq headers (mapconcat (lambda (header)
2829 (mail-fetch-field header) "\n"))
2830 (split-string (nth 1 items) ",") "")))
2831 (delete-region (point-min) (point-max))
2832 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2833 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2838 (if (looking-at "^-")
2841 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2842 (insert "Version: " (car items) "\n\n")
2843 (insert (mapconcat 'identity (cddr items) "\n"))
2844 (insert "\n-----END PGP SIGNATURE-----\n")
2845 (let ((mm-security-handle (list (format "multipart/signed"))))
2846 (mml2015-clean-buffer)
2847 (let ((coding-system-for-write (or gnus-newsgroup-charset
2849 (funcall (mml2015-clear-verify-function)))
2851 (or (mm-handle-multipart-ctl-parameter
2852 mm-security-handle 'gnus-details)
2853 (mm-handle-multipart-ctl-parameter
2854 mm-security-handle 'gnus-info)))))
2856 (let (buffer-read-only bface eface)
2858 (message-narrow-to-head)
2859 (goto-char (point-max))
2861 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2862 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2863 (message-remove-header "X-Gnus-PGP-Verify")
2864 (if (re-search-forward "^X-PGP-Sig:" nil t)
2866 (goto-char (point-max)))
2867 (narrow-to-region (point) (point))
2868 (insert "X-Gnus-PGP-Verify: " info "\n")
2869 (goto-char (point-min))
2872 (if (not (looking-at "^[ \t]"))
2876 (goto-char (point-min))
2877 (when (looking-at "\\([^:]+\\): *")
2878 (put-text-property (match-beginning 1) (1+ (match-end 1))
2880 (put-text-property (match-end 0) (point-max)
2881 'face eface)))))))))
2888 (setq afunc (car func)
2891 gfunc (intern (format "gnus-%s" func))))
2894 `(lambda (&optional interactive &rest args)
2895 ,(documentation afunc t)
2896 (interactive (list t))
2898 (set-buffer gnus-article-buffer)
2900 (call-interactively ',afunc)
2901 (apply ',afunc args))))))))
2902 '(article-hide-headers
2903 article-verify-x-pgp-sig
2904 article-hide-boring-headers
2905 article-toggle-headers
2906 article-treat-overstrike
2907 article-fill-long-lines
2908 article-capitalize-sentences
2910 article-display-x-face
2911 article-de-quoted-unreadable
2912 article-de-base64-unreadable
2915 article-hide-list-identifiers
2917 article-strip-banner
2920 article-hide-signature
2921 article-strip-headers-in-body
2922 article-remove-trailing-blank-lines
2923 article-strip-leading-blank-lines
2924 article-strip-multiple-blank-lines
2925 article-strip-leading-space
2926 article-strip-trailing-space
2927 article-strip-blank-lines
2928 article-strip-all-blank-lines
2930 article-date-iso8601
2931 article-date-original
2933 article-decode-mime-words
2934 article-decode-charset
2935 article-decode-encoded-words
2939 article-treat-dumbquotes
2940 article-normalize-headers
2941 (article-show-all-headers . gnus-article-show-all-headers)
2942 (article-show-all . gnus-article-show-all))))
2945 ;;; Gnus article mode
2948 (put 'gnus-article-mode 'mode-class 'special)
2950 (gnus-define-keys gnus-article-mode-map
2951 " " gnus-article-goto-next-page
2952 "\177" gnus-article-goto-prev-page
2953 [delete] gnus-article-goto-prev-page
2954 [backspace] gnus-article-goto-prev-page
2955 "\C-c^" gnus-article-refer-article
2956 "h" gnus-article-show-summary
2957 "s" gnus-article-show-summary
2958 "\C-c\C-m" gnus-article-mail
2959 "?" gnus-article-describe-briefly
2960 "e" gnus-summary-edit-article
2961 "<" beginning-of-buffer
2963 "\C-c\C-i" gnus-info-find-node
2965 "\C-hk" gnus-article-describe-key
2966 "\C-hc" gnus-article-describe-key-briefly
2968 "\C-d" gnus-article-read-summary-keys
2969 "\M-*" gnus-article-read-summary-keys
2970 "\M-#" gnus-article-read-summary-keys
2971 "\M-^" gnus-article-read-summary-keys
2972 "\M-g" gnus-article-read-summary-keys)
2974 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2977 (unless (lookup-key gnus-article-mode-map key)
2978 (define-key gnus-article-mode-map key
2979 'gnus-article-read-summary-keys)))
2984 (let ((key (car elt)))
2985 (and (> (length key) 0)
2986 (not (eq 'menu-bar (aref key 0)))
2987 (symbolp (lookup-key gnus-summary-mode-map key))
2989 (accessible-keymaps gnus-summary-mode-map))
2993 (push (char-to-string c) keys)
2998 (defvar gnus-article-commands-menu))
3000 (defun gnus-article-make-menu-bar ()
3001 (gnus-turn-off-edit-menu 'article)
3002 (unless (boundp 'gnus-article-article-menu)
3004 gnus-article-article-menu gnus-article-mode-map ""
3006 ["Scroll forwards" gnus-article-goto-next-page t]
3007 ["Scroll backwards" gnus-article-goto-prev-page t]
3008 ["Show summary" gnus-article-show-summary t]
3009 ["Fetch Message-ID at point" gnus-article-refer-article t]
3010 ["Mail to address at point" gnus-article-mail t]
3011 ["Send a bug report" gnus-bug t]))
3014 gnus-article-treatment-menu gnus-article-mode-map ""
3015 ;; Fixme: this should use :active (and maybe :visible).
3017 ["Hide headers" gnus-article-toggle-headers t]
3018 ["Hide signature" gnus-article-hide-signature t]
3019 ["Hide citation" gnus-article-hide-citation t]
3020 ["Treat overstrike" gnus-article-treat-overstrike t]
3021 ["Remove carriage return" gnus-article-remove-cr t]
3022 ["Decode HZ" gnus-article-decode-HZ t]))
3024 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3026 (when (boundp 'gnus-summary-post-menu)
3027 (define-key gnus-article-mode-map [menu-bar post]
3028 (cons "Post" gnus-summary-post-menu)))
3030 (gnus-run-hooks 'gnus-article-menu-hook))
3032 (when (boundp 'gnus-article-commands-menu)
3033 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
3034 (when (boundp 'gnus-summary-post-menu)
3035 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
3037 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3040 (defun gnus-article-mode ()
3041 "Major mode for displaying an article.
3043 All normal editing commands are switched off.
3045 The following commands are available in addition to all summary mode
3047 \\<gnus-article-mode-map>
3048 \\[gnus-article-next-page]\t Scroll the article one page forwards
3049 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3050 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3051 \\[gnus-article-show-summary]\t Display the summary buffer
3052 \\[gnus-article-mail]\t Send a reply to the address near point
3053 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3054 \\[gnus-info-find-node]\t Go to the Gnus info node"
3056 (when (gnus-visual-p 'article-menu 'menu)
3057 (gnus-article-make-menu-bar))
3058 (gnus-simplify-mode-line)
3059 (setq mode-name "Article")
3060 (setq major-mode 'gnus-article-mode)
3061 (make-local-variable 'minor-mode-alist)
3062 (unless (assq 'gnus-show-mime minor-mode-alist)
3063 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3064 (use-local-map gnus-article-mode-map)
3065 (gnus-update-format-specifications nil 'article-mode)
3066 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3067 (make-local-variable 'gnus-page-broken)
3068 (make-local-variable 'gnus-button-marker-list)
3069 (make-local-variable 'gnus-article-current-summary)
3070 (make-local-variable 'gnus-article-mime-handles)
3071 (make-local-variable 'gnus-article-decoded-p)
3072 (make-local-variable 'gnus-article-mime-handle-alist)
3073 (make-local-variable 'gnus-article-wash-types)
3074 (make-local-variable 'gnus-article-charset)
3075 (make-local-variable 'gnus-article-ignored-charsets)
3076 (gnus-set-default-directory)
3077 (buffer-disable-undo)
3078 (setq buffer-read-only t)
3079 (set-syntax-table gnus-article-mode-syntax-table)
3080 (gnus-run-hooks 'gnus-article-mode-hook))
3082 (defun gnus-article-setup-buffer ()
3083 "Initialize the article buffer."
3084 (let* ((name (if gnus-single-article-buffer "*Article*"
3085 (concat "*Article " gnus-newsgroup-name "*")))
3087 (progn (string-match "\\*Article" name)
3088 (concat " *Original Article"
3089 (substring name (match-end 0))))))
3090 (setq gnus-article-buffer name)
3091 (setq gnus-original-article-buffer original)
3092 (setq gnus-article-mime-handle-alist nil)
3093 ;; This might be a variable local to the summary buffer.
3094 (unless gnus-single-article-buffer
3096 (set-buffer gnus-summary-buffer)
3097 (setq gnus-article-buffer name)
3098 (setq gnus-original-article-buffer original)
3099 (gnus-set-global-variables)))
3100 (gnus-article-setup-highlight-words)
3101 ;; Init original article buffer.
3103 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3104 (set-buffer-multibyte nil)
3105 (setq major-mode 'gnus-original-article-mode)
3106 (make-local-variable 'gnus-original-article))
3107 (if (get-buffer name)
3110 (buffer-disable-undo)
3111 (setq buffer-read-only t)
3112 (unless (eq major-mode 'gnus-article-mode)
3113 (gnus-article-mode))
3116 (set-buffer (gnus-get-buffer-create name))
3118 (make-local-variable 'gnus-summary-buffer)
3119 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3120 (current-buffer)))))
3122 ;; Set article window start at LINE, where LINE is the number of lines
3123 ;; from the head of the article.
3124 (defun gnus-article-set-window-start (&optional line)
3126 (get-buffer-window gnus-article-buffer t)
3128 (set-buffer gnus-article-buffer)
3129 (goto-char (point-min))
3132 (gnus-message 6 "Moved to bookmark")
3133 (search-forward "\n\n" nil t)
3137 ;;; @@ article filters
3140 (defun gnus-article-display-mime-message ()
3141 "Article display method for MIME message."
3142 ;; called from `gnus-original-article-buffer'.
3143 (let (charset all-headers)
3144 (with-current-buffer gnus-summary-buffer
3145 (setq charset default-mime-charset
3146 all-headers gnus-have-all-headers))
3147 (make-local-variable 'default-mime-charset)
3148 (setq default-mime-charset charset)
3149 (with-current-buffer (get-buffer-create gnus-article-buffer)
3150 (make-local-variable 'default-mime-charset)
3151 (setq default-mime-charset charset))
3152 (mime-display-message mime-message-structure
3153 gnus-article-buffer nil gnus-article-mode-map)
3155 (gnus-article-hide-headers nil -1)))
3156 (run-hooks 'gnus-mime-article-prepare-hook))
3158 (defun gnus-article-display-traditional-message ()
3159 "Article display method for traditional message."
3160 (set-buffer gnus-article-buffer)
3161 (let (buffer-read-only)
3163 (insert-buffer-substring gnus-original-article-buffer)))
3165 (defun gnus-article-make-full-mail-header (&optional number charset)
3166 "Create a new mail header structure in a raw article buffer."
3167 (unless (and number charset)
3168 (save-current-buffer
3169 (set-buffer gnus-summary-buffer)
3171 (setq number (or (cdr gnus-article-current) 0)))
3173 (setq charset (or default-mime-charset 'x-ctext)))))
3174 (goto-char (point-min))
3175 (let ((header-end (if (search-forward "\n\n" nil t)
3177 (goto-char (point-max))))
3178 (chars (- (point-max) (point)))
3179 (lines (count-lines (point) (point-max)))
3180 (default-mime-charset charset)
3182 (narrow-to-region (point-min) header-end)
3183 (setq xref (std11-fetch-field "xref"))
3185 (make-full-mail-header
3187 (std11-fetch-field "subject")
3188 (std11-fetch-field "from")
3189 (std11-fetch-field "date")
3190 (std11-fetch-field "message-id")
3191 (std11-fetch-field "references")
3194 (when xref (concat "Xref: " xref)))
3197 (defun gnus-article-prepare (article &optional all-headers header)
3198 "Prepare ARTICLE in article mode buffer.
3199 ARTICLE should either be an article number or a Message-ID.
3200 If ARTICLE is an id, HEADER should be the article headers.
3201 If ALL-HEADERS is non-nil, no headers are hidden."
3203 ;; Make sure we start in a summary buffer.
3204 (unless (eq major-mode 'gnus-summary-mode)
3205 (set-buffer gnus-summary-buffer))
3206 (setq gnus-summary-buffer (current-buffer))
3207 (let* ((gnus-article (if header (mail-header-number header) article))
3208 (summary-buffer (current-buffer))
3209 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3210 (group gnus-newsgroup-name)
3213 (gnus-article-setup-buffer)
3214 (set-buffer gnus-original-article-buffer)
3215 ;; Deactivate active regions.
3216 (when (and (boundp 'transient-mark-mode)
3217 transient-mark-mode)
3218 (setq mark-active nil))
3219 (if (not (setq result (let ((buffer-read-only nil))
3220 (gnus-request-article-this-buffer
3222 ;; There is no such article.
3224 (when (and (numberp article)
3225 (not (memq article gnus-newsgroup-sparse)))
3226 (setq gnus-article-current
3227 (cons gnus-newsgroup-name article))
3228 (set-buffer gnus-summary-buffer)
3229 (setq gnus-current-article article)
3230 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3232 (gnus-summary-set-agent-mark article)
3233 (message "Message marked for downloading"))
3234 (gnus-summary-mark-article article gnus-canceled-mark)
3235 (unless (memq article gnus-newsgroup-sparse)
3236 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3237 (if (or (eq result 'pseudo)
3238 (eq result 'nneething))
3241 (set-buffer summary-buffer)
3242 (push article gnus-newsgroup-history)
3243 (setq gnus-last-article gnus-current-article
3244 gnus-current-article 0
3245 gnus-current-headers nil
3246 gnus-article-current nil)
3247 (if (eq result 'nneething)
3248 (gnus-configure-windows 'summary)
3249 (gnus-configure-windows 'article))
3250 (gnus-set-global-variables))
3251 (let ((gnus-article-mime-handle-alist-1
3252 gnus-article-mime-handle-alist))
3253 (gnus-set-mode-line 'article)))
3254 ;; The result from the `request' was an actual article -
3255 ;; or at least some text that is now displayed in the
3257 (when (and (numberp article)
3258 (not (eq article gnus-current-article)))
3259 ;; Seems like a new article has been selected.
3260 ;; `gnus-current-article' must be an article number.
3262 (set-buffer summary-buffer)
3263 (push article gnus-newsgroup-history)
3264 (setq gnus-last-article gnus-current-article
3265 gnus-current-article article
3266 gnus-current-headers
3267 (gnus-summary-article-header gnus-current-article)
3268 gnus-article-current
3269 (cons gnus-newsgroup-name gnus-current-article))
3270 (unless (vectorp gnus-current-headers)
3271 (setq gnus-current-headers nil))
3272 (gnus-summary-goto-subject gnus-current-article)
3273 (when (gnus-summary-show-thread)
3274 ;; If the summary buffer really was folded, the
3275 ;; previous goto may not actually have gone to
3276 ;; the right article, but the thread root instead.
3278 (gnus-summary-goto-subject gnus-current-article))
3279 (gnus-run-hooks 'gnus-mark-article-hook)
3280 (gnus-set-mode-line 'summary)
3281 (when (gnus-visual-p 'article-highlight 'highlight)
3282 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3283 ;; Set the global newsgroup variables here.
3284 (gnus-set-global-variables)
3285 (setq gnus-have-all-headers
3286 (or all-headers gnus-show-all-headers))))
3288 (gnus-configure-windows 'article))
3289 (when (or (numberp article)
3291 (gnus-article-prepare-display)
3293 (goto-char (point-min))
3294 (setq gnus-page-broken
3295 (when gnus-break-pages
3296 (gnus-narrow-to-page)
3298 (let ((gnus-article-mime-handle-alist-1
3299 gnus-article-mime-handle-alist))
3300 (gnus-set-mode-line 'article))
3302 (set-window-point (get-buffer-window (current-buffer)) (point))
3303 (gnus-configure-windows 'article)
3306 (defun gnus-article-prepare-mime-display (&optional number)
3307 (goto-char (point-min))
3308 (when (re-search-forward "^[^\t ]+:" nil t)
3309 (goto-char (match-beginning 0)))
3310 (let ((entity (if (eq 1 (point-min))
3311 (get-text-property 1 'mime-view-entity)
3312 (get-text-property (point) 'mime-view-entity)))
3313 last-entity child-entity next type)
3314 (setq child-entity (mime-entity-children entity))
3316 (setq last-entity (nth (1- (length child-entity))
3318 (setq last-entity entity))
3320 (narrow-to-region (point)
3321 (if (search-forward "\n\n" nil t)
3324 (gnus-treat-article 'head)
3325 (put-text-property (point-min) (point-max) 'article-treated-header t)
3326 (goto-char (point-max)))
3327 (while (and (not (eobp)) entity)
3328 (setq next (set-marker
3330 (next-single-property-change (point) 'mime-view-entity
3332 (let ((types (mime-entity-content-type entity)))
3333 (while (eq 'multipart (mime-content-type-primary-type types))
3334 (setq entity (car (mime-entity-children entity))
3335 types (mime-entity-content-type entity)))
3337 (setq type (format "%s/%s"
3338 (mime-content-type-primary-type types)
3339 (mime-content-type-subtype types)))))
3340 (if (string-equal type "message/rfc822")
3343 (let ((children (mime-entity-children entity))
3346 (setq last-children (nth (1- (length children)) children))
3349 (not (eq last-children
3350 (get-text-property next 'mime-view-entity)))
3352 (next-single-property-change next
3354 nil (point-max)))))))
3355 (setq next (next-single-property-change next 'mime-view-entity
3358 (narrow-to-region (point) next)
3359 (gnus-article-prepare-mime-display)
3360 (goto-char (point-max)))
3361 (setq entity (get-text-property (point) 'mime-view-entity)))
3363 (narrow-to-region (point) next)
3364 ;; Kludge. We have to count true number, but for now,
3365 ;; part number is here only to achieve `last'.
3366 (gnus-treat-article nil 1
3367 (if (eq entity last-entity)
3370 (goto-char (point-max)))
3371 (setq entity (get-text-property next 'mime-view-entity))))))
3374 (defun gnus-article-prepare-display ()
3375 "Make the current buffer look like a nice article."
3376 (setq gnus-article-wash-types nil)
3377 (gnus-run-hooks 'gnus-tmp-internal-hook)
3378 (gnus-run-hooks 'gnus-article-prepare-hook)
3380 (let (mime-display-header-hook mime-display-text/plain-hook)
3381 (funcall (if gnus-show-mime
3383 (setq mime-message-structure gnus-current-headers)
3384 (mime-buffer-entity-set-buffer-internal
3385 mime-message-structure
3386 gnus-original-article-buffer)
3387 (mime-entity-set-representation-type-internal
3388 mime-message-structure 'mime-buffer-entity)
3389 (luna-send mime-message-structure
3390 'initialize-instance
3391 mime-message-structure)
3392 gnus-article-display-method-for-mime)
3393 gnus-article-display-method-for-traditional)))
3394 ;; Associate this article with the current summary buffer.
3395 (setq gnus-article-current-summary gnus-summary-buffer)
3396 ;; Call the treatment functions.
3397 (let ((inhibit-read-only t)
3402 (gnus-article-prepare-mime-display)
3403 (narrow-to-region (goto-char (point-min))
3404 (if (search-forward "\n\n" nil t)
3407 (gnus-treat-article 'head)
3408 (put-text-property (point-min) (point-max) 'article-treated-header t)
3409 (goto-char (point-max))
3411 (narrow-to-region (point) (point-max))
3412 (gnus-treat-article nil))
3413 (put-text-property (point-min) (point-max) 'read-only nil)))
3414 ;; Perform the article display hooks. Incidentally, this hook is
3415 ;; an obsolete variable by now.
3416 (gnus-run-hooks 'gnus-article-display-hook))
3418 (defun gnus-article-decode-article-as-default-mime-charset ()
3419 "Decode an article as `default-mime-charset'. It won't work if the
3420 value of the variable `gnus-show-mime' is non-nil."
3421 (unless gnus-show-mime
3422 (decode-mime-charset-region (point-min) (point-max)
3423 (with-current-buffer gnus-summary-buffer
3424 default-mime-charset))))
3427 ;;; Gnus MIME viewing functions
3430 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3431 "The following specs can be used:
3433 %T MIME type, along with additional info
3434 %n The `name' parameter
3435 %d The description, if any
3436 %l The length of the encoded part
3437 %p The part identifier number
3438 %e Dots if the part isn't displayed")
3440 (defvar gnus-mime-button-line-format-alist
3441 '((?t gnus-tmp-type ?s)
3442 (?T gnus-tmp-type-long ?s)
3443 (?n gnus-tmp-name ?s)
3444 (?d gnus-tmp-description ?s)
3446 (?l gnus-tmp-length ?d)
3447 (?e gnus-tmp-dots ?s)))
3449 (defvar gnus-mime-button-commands
3450 '((gnus-article-press-button "\r" "Toggle Display")
3451 (gnus-mime-view-part "v" "View Interactively...")
3452 (gnus-mime-view-part-as-type "t" "View As Type...")
3453 (gnus-mime-view-part-as-charset "C" "View As charset...")
3454 (gnus-mime-save-part "o" "Save...")
3455 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3456 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3457 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3458 (gnus-mime-internalize-part "E" "View Internally")
3459 (gnus-mime-externalize-part "e" "View Externally")
3460 (gnus-mime-pipe-part "|" "Pipe To Command...")
3461 (gnus-mime-action-on-part "." "Take action on the part")))
3463 (defun gnus-article-mime-part-status ()
3464 (with-current-buffer gnus-article-buffer
3465 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3466 (if (and entity (mime-entity-children entity))
3467 (format " (%d parts)" (length (mime-entity-children entity)))
3470 (defvar gnus-mime-button-map
3471 (let ((map (make-sparse-keymap)))
3472 ;; Not for Emacs 21: fixme better.
3473 ;; (set-keymap-parent map gnus-article-mode-map)
3474 (define-key map gnus-mouse-2 'gnus-article-push-button)
3475 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3476 (dolist (c gnus-mime-button-commands)
3477 (define-key map (cadr c) (car c)))
3480 (defun gnus-mime-button-menu (event)
3481 "Construct a context-sensitive menu of MIME commands."
3483 (save-window-excursion
3484 (let ((pos (event-start event)))
3485 (select-window (posn-window pos))
3486 (goto-char (posn-point pos))
3487 (gnus-article-check-buffer)
3488 (let ((response (x-popup-menu
3490 ("" ,@(mapcar (lambda (c)
3491 (cons (caddr c) (car c)))
3492 gnus-mime-button-commands))))))
3494 (call-interactively response))))))
3496 (defun gnus-mime-view-all-parts (&optional handles)
3497 "View all the MIME parts."
3499 (save-current-buffer
3500 (set-buffer gnus-article-buffer)
3501 (let ((handles (or handles gnus-article-mime-handles))
3502 (mail-parse-charset gnus-newsgroup-charset)
3503 (mail-parse-ignored-charsets
3504 (with-current-buffer gnus-summary-buffer
3505 gnus-newsgroup-ignored-charsets)))
3507 (mm-remove-parts handles)
3508 (goto-char (point-min))
3509 (or (search-forward "\n\n") (goto-char (point-max)))
3510 (let (buffer-read-only)
3511 (delete-region (point) (point-max)))
3512 (mm-display-parts handles)))))
3514 (defun gnus-mime-save-part-and-strip ()
3515 "Save the MIME part under point then replace it with an external body."
3517 (gnus-article-check-buffer)
3518 (let* ((data (get-text-property (point) 'gnus-data))
3519 (file (and data (mm-save-part data)))
3522 (with-current-buffer (mm-handle-buffer data)
3524 (insert "Content-Type: " (mm-handle-media-type data))
3525 (mml-insert-parameter-string (cdr (mm-handle-type data))
3528 (insert "Content-ID: " (message-make-message-id) "\n")
3529 (insert "Content-Transfer-Encoding: binary\n")
3532 (cdr (mm-make-handle nil
3533 `("message/external-body"
3534 (access-type . "LOCAL-FILE")
3536 (set-buffer gnus-summary-buffer)
3537 (gnus-article-edit-article
3540 (let ((mail-parse-charset (or gnus-article-charset
3541 ',gnus-newsgroup-charset))
3542 (mail-parse-ignored-charsets
3543 (or gnus-article-ignored-charsets
3544 ',gnus-newsgroup-ignored-charsets))
3545 (mbl mml-buffer-list))
3546 (setq mml-buffer-list nil)
3547 (insert-buffer gnus-original-article-buffer)
3548 (mime-to-mml gnus-article-mime-handles)
3549 (setq gnus-article-mime-handles nil)
3550 (make-local-hook 'kill-buffer-hook)
3551 (let ((mbl1 mml-buffer-list))
3552 (setq mml-buffer-list mbl)
3553 (set (make-local-variable 'mml-buffer-list) mbl1))
3554 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3555 `(lambda (no-highlight)
3556 (let ((mail-parse-charset (or gnus-article-charset
3557 ',gnus-newsgroup-charset))
3558 (message-options message-options)
3559 (message-options-set-recipient)
3560 (mail-parse-ignored-charsets
3561 (or gnus-article-ignored-charsets
3562 ',gnus-newsgroup-ignored-charsets)))
3564 (mml-destroy-buffers)
3565 (remove-hook 'kill-buffer-hook
3566 'mml-destroy-buffers t)
3567 (kill-local-variable 'mml-buffer-list))
3568 (gnus-summary-edit-article-done
3569 ,(or (mail-header-references gnus-current-headers) "")
3570 ,(gnus-group-read-only-p)
3571 ,gnus-summary-buffer no-highlight))))))
3573 (defun gnus-mime-save-part ()
3574 "Save the MIME part under point."
3576 (gnus-article-check-buffer)
3577 (let ((data (get-text-property (point) 'gnus-data)))
3579 (mm-save-part data))))
3581 (defun gnus-mime-pipe-part ()
3582 "Pipe the MIME part under point to a process."
3584 (gnus-article-check-buffer)
3585 (let ((data (get-text-property (point) 'gnus-data)))
3587 (mm-pipe-part data))))
3589 (defun gnus-mime-view-part ()
3590 "Interactively choose a viewing method for the MIME part under point."
3592 (gnus-article-check-buffer)
3593 (let ((data (get-text-property (point) 'gnus-data)))
3595 (mm-interactively-view-part data))))
3597 (defun gnus-mime-view-part-as-type-internal ()
3598 (gnus-article-check-buffer)
3599 (let* ((name (mail-content-type-get
3600 (mm-handle-type (get-text-property (point) 'gnus-data))
3602 (def-type (and name (mm-default-file-encoding name))))
3603 (and def-type (cons def-type 0))))
3605 (defun gnus-mime-view-part-as-type (mime-type)
3606 "Choose a MIME media type, and view the part as such."
3608 (list (completing-read
3609 "View as MIME type: "
3610 (mapcar #'list (mailcap-mime-types))
3612 (gnus-mime-view-part-as-type-internal))))
3613 (gnus-article-check-buffer)
3614 (let ((handle (get-text-property (point) 'gnus-data)))
3616 (gnus-mm-display-part
3617 (mm-make-handle (mm-handle-buffer handle)
3618 (cons mime-type (cdr (mm-handle-type handle)))
3619 (mm-handle-encoding handle)
3620 (mm-handle-undisplayer handle)
3621 (mm-handle-disposition handle)
3622 (mm-handle-description handle)
3623 (mm-handle-cache handle)
3624 (mm-handle-id handle))))))
3626 (defun gnus-mime-copy-part (&optional handle)
3627 "Put the the MIME part under point into a new buffer."
3629 (gnus-article-check-buffer)
3630 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3631 (contents (and handle (mm-get-part handle)))
3633 (file-name-nondirectory
3635 (mail-content-type-get (mm-handle-type handle) 'name)
3636 (mail-content-type-get (mm-handle-type handle)
3639 (buffer (and base (generate-new-buffer base))))
3641 (switch-to-buffer buffer)
3643 ;; We do it this way to make `normal-mode' set the appropriate mode.
3646 (setq buffer-file-name (expand-file-name base))
3648 (setq buffer-file-name nil))
3649 (goto-char (point-min)))))
3651 (defun gnus-mime-inline-part (&optional handle arg)
3652 "Insert the MIME part under point into the current buffer."
3653 (interactive (list nil current-prefix-arg))
3654 (gnus-article-check-buffer)
3655 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3660 (if (and (not arg) (mm-handle-undisplayer handle))
3661 (mm-remove-part handle)
3662 (setq contents (mm-get-part handle))
3665 (setq charset (or (mail-content-type-get
3666 (mm-handle-type handle) 'charset)
3667 gnus-newsgroup-charset)))
3669 (if (mm-handle-undisplayer handle)
3670 (mm-remove-part handle))
3673 gnus-summary-show-article-charset-alist))
3674 (read-coding-system "Charset: ")))))
3676 (mm-insert-inline handle
3678 (setq charset (mm-charset-to-coding-system
3680 (not (eq charset 'ascii)))
3681 (mm-decode-coding-string contents charset)
3685 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3686 "Insert the MIME part under point into the current buffer."
3687 (interactive (list nil current-prefix-arg))
3688 (gnus-article-check-buffer)
3689 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3694 (if (mm-handle-undisplayer handle)
3695 (mm-remove-part handle))
3696 (let ((gnus-newsgroup-charset
3698 gnus-summary-show-article-charset-alist))
3699 (read-coding-system "Charset: ")))
3700 (gnus-newsgroup-ignored-charsets 'gnus-all))
3701 (gnus-article-press-button)))))
3703 (defun gnus-mime-externalize-part (&optional handle)
3704 "View the MIME part under point with an external viewer."
3706 (gnus-article-check-buffer)
3707 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3708 (mm-user-display-methods nil)
3709 (mm-inlined-types nil)
3710 (mail-parse-charset gnus-newsgroup-charset)
3711 (mail-parse-ignored-charsets
3712 (save-excursion (set-buffer gnus-summary-buffer)
3713 gnus-newsgroup-ignored-charsets)))
3715 (if (mm-handle-undisplayer handle)
3716 (mm-remove-part handle)
3717 (mm-display-part handle)))))
3719 (defun gnus-mime-internalize-part (&optional handle)
3720 "View the MIME part under point with an internal viewer.
3721 In no internal viewer is available, use an external viewer."
3723 (gnus-article-check-buffer)
3724 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3725 (mm-inlined-types '(".*"))
3726 (mm-inline-large-images t)
3727 (mail-parse-charset gnus-newsgroup-charset)
3728 (mail-parse-ignored-charsets
3729 (save-excursion (set-buffer gnus-summary-buffer)
3730 gnus-newsgroup-ignored-charsets)))
3732 (if (mm-handle-undisplayer handle)
3733 (mm-remove-part handle)
3734 (mm-display-part handle)))))
3736 (defun gnus-mime-action-on-part (&optional action)
3737 "Do something with the MIME attachment at \(point\)."
3739 (list (completing-read "Action: " gnus-mime-action-alist)))
3740 (gnus-article-check-buffer)
3741 (let ((action-pair (assoc action gnus-mime-action-alist)))
3743 (funcall (cdr action-pair)))))
3745 (defun gnus-article-part-wrapper (n function)
3746 (save-current-buffer
3747 (set-buffer gnus-article-buffer)
3748 (when (> n (length gnus-article-mime-handle-alist))
3749 (error "No such part"))
3750 (gnus-article-goto-part n)
3751 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3752 (funcall function handle))))
3754 (defun gnus-article-pipe-part (n)
3755 "Pipe MIME part N, which is the numerical prefix."
3757 (gnus-article-part-wrapper n 'mm-pipe-part))
3759 (defun gnus-article-save-part (n)
3760 "Save MIME part N, which is the numerical prefix."
3762 (gnus-article-part-wrapper n 'mm-save-part))
3764 (defun gnus-article-interactively-view-part (n)
3765 "View MIME part N interactively, which is the numerical prefix."
3767 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3769 (defun gnus-article-copy-part (n)
3770 "Copy MIME part N, which is the numerical prefix."
3772 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3774 (defun gnus-article-view-part-as-charset (n)
3775 "Copy MIME part N, which is the numerical prefix."
3777 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3779 (defun gnus-article-externalize-part (n)
3780 "View MIME part N externally, which is the numerical prefix."
3782 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3784 (defun gnus-article-inline-part (n)
3785 "Inline MIME part N, which is the numerical prefix."
3787 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3789 (defun gnus-article-mime-match-handle-first (condition)
3791 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3792 (while (setq ihandle (pop alist))
3794 ((functionp condition)
3795 (funcall condition (cdr ihandle)))
3796 ((eq condition 'undisplayed)
3797 (not (or (mm-handle-undisplayer (cdr ihandle))
3798 (equal (mm-handle-media-type (cdr ihandle))
3799 "multipart/alternative"))))
3800 ((eq condition 'undisplayed-alternative)
3801 (not (mm-handle-undisplayer (cdr ihandle))))
3803 (gnus-article-goto-part (car ihandle))
3804 (or (not n) (< (car ihandle) n)))
3805 (setq n (car ihandle))))
3809 (defun gnus-article-view-part (&optional n)
3810 "View MIME part N, which is the numerical prefix."
3812 (save-current-buffer
3813 (set-buffer gnus-article-buffer)
3814 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3815 gnus-article-mime-match-handle-function)))
3816 (when (> n (length gnus-article-mime-handle-alist))
3817 (error "No such part"))
3818 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3819 (when (gnus-article-goto-part n)
3820 (if (equal (car handle) "multipart/alternative")
3821 (gnus-article-press-button)
3822 (when (eq (gnus-mm-display-part handle) 'internal)
3823 (gnus-set-window-start)))))))
3825 (defsubst gnus-article-mime-total-parts ()
3826 (if (bufferp (car gnus-article-mime-handles))
3828 (1- (length gnus-article-mime-handles))))
3830 (defun gnus-mm-display-part (handle)
3831 "Display HANDLE and fix MIME button."
3832 (let ((id (get-text-property (point) 'gnus-part))
3837 (let ((window (selected-window))
3838 (mail-parse-charset gnus-newsgroup-charset)
3839 (mail-parse-ignored-charsets
3840 (save-excursion (set-buffer gnus-summary-buffer)
3841 gnus-newsgroup-ignored-charsets)))
3844 (let ((win (get-buffer-window (current-buffer) t))
3847 (select-window win))
3850 (if (mm-handle-displayed-p handle)
3851 ;; This will remove the part.
3852 (mm-display-part handle)
3854 (narrow-to-region (point) (1+ (point)))
3855 (mm-display-part handle)
3856 ;; We narrow to the part itself and
3857 ;; then call the treatment functions.
3858 (goto-char (point-min))
3860 (narrow-to-region (point) (point-max))
3863 (gnus-article-mime-total-parts)
3864 (mm-handle-media-type handle)))))
3865 (select-window window))))
3867 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3868 (gnus-insert-mime-button
3869 handle id (list (mm-handle-displayed-p handle)))
3870 (goto-char point))))
3872 (defun gnus-article-goto-part (n)
3873 "Go to MIME part N."
3874 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3876 (goto-char point))))
3878 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3879 (let ((gnus-tmp-name
3880 (or (mail-content-type-get (mm-handle-type handle)
3882 (mail-content-type-get (mm-handle-disposition handle)
3884 (mail-content-type-get (mm-handle-type handle)
3887 (gnus-tmp-type (mm-handle-media-type handle))
3888 (gnus-tmp-description
3889 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3892 (if (if displayed (car displayed)
3893 (mm-handle-displayed-p handle))
3895 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3897 gnus-tmp-type-long b e)
3898 (when (string-match ".*/" gnus-tmp-name)
3899 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3900 (setq gnus-tmp-type-long (concat gnus-tmp-type
3901 (and (not (equal gnus-tmp-name ""))
3902 (concat "; " gnus-tmp-name))))
3903 (or (equal gnus-tmp-description "")
3904 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3909 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3910 `(keymap ,gnus-mime-button-map
3911 ,@(if (>= (string-to-number emacs-version) 21)
3913 (list 'local-map gnus-mime-button-map))
3914 gnus-callback gnus-mm-display-part
3915 gnus-part ,gnus-tmp-id
3916 article-type annotation
3919 (widget-convert-button
3922 :action 'gnus-widget-press-button
3923 :button-keymap gnus-mime-button-map
3925 (lambda (widget/window &optional overlay pos)
3926 ;; Needed to properly clear the message due to a bug in
3927 ;; wid-edit (XEmacs only).
3928 (if (boundp 'help-echo-owns-message)
3929 (setq help-echo-owns-message t))
3931 "%S: %s the MIME part; %S: more options"
3932 (aref gnus-mouse-2 0)
3933 ;; XEmacs will get a single widget arg; Emacs 21 will get
3934 ;; window, overlay, position.
3935 (if (mm-handle-displayed-p
3937 (with-current-buffer (gnus-overlay-buffer overlay)
3938 (widget-get (widget-at (gnus-overlay-start overlay))
3940 (widget-get widget/window :mime-handle)))
3942 (aref gnus-down-mouse-3 0))))))
3944 (defun gnus-widget-press-button (elems el)
3945 (goto-char (widget-get elems :from))
3946 (gnus-article-press-button))
3948 (defvar gnus-displaying-mime nil)
3950 (defun gnus-display-mime (&optional ihandles)
3951 "Display the MIME parts."
3953 (save-selected-window
3954 (let ((window (get-buffer-window gnus-article-buffer))
3957 (select-window window)
3958 ;; We have to do this since selecting the window
3959 ;; may change the point. So we set the window point.
3960 (set-window-point window point)))
3961 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3962 buffer-read-only handle name type b e display)
3963 (when (and (not ihandles)
3964 (not gnus-displaying-mime))
3965 ;; Top-level call; we clean up.
3966 (when gnus-article-mime-handles
3967 (mm-destroy-parts gnus-article-mime-handles)
3968 (setq gnus-article-mime-handle-alist nil));; A trick.
3969 (setq gnus-article-mime-handles handles)
3970 ;; We allow users to glean info from the handles.
3971 (when gnus-article-mime-part-function
3972 (gnus-mime-part-function handles)))
3974 (or (not (stringp (car handles)))
3977 (when (and (not ihandles)
3978 (not gnus-displaying-mime))
3979 ;; Clean up for mime parts.
3981 (delete-region (point) (point-max)))
3982 (let ((gnus-displaying-mime t))
3983 (gnus-mime-display-part handles)))
3986 (narrow-to-region (point) (point-max))
3987 (gnus-treat-article nil 1 1)
3990 ;; Highlight the headers.
3994 (narrow-to-region (point-min) (point))
3995 (gnus-treat-article 'head))))))))
3997 (defvar gnus-mime-display-multipart-as-mixed nil)
3999 (defun gnus-mime-display-part (handle)
4002 ((not (stringp (car handle)))
4003 (gnus-mime-display-single handle))
4004 ;; User-defined multipart
4005 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4006 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4008 ;; multipart/alternative
4009 ((and (equal (car handle) "multipart/alternative")
4010 (not gnus-mime-display-multipart-as-mixed))
4011 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4012 (push (cons id handle) gnus-article-mime-handle-alist)
4013 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4014 ;; multipart/related
4015 ((and (equal (car handle) "multipart/related")
4016 (not gnus-mime-display-multipart-as-mixed))
4017 ;;;!!!We should find the start part, but we just default
4018 ;;;!!!to the first part.
4019 ;;(gnus-mime-display-part (cadr handle))
4020 ;;;!!! Most multipart/related is an HTML message plus images.
4021 ;;;!!! Unfortunately we are unable to let W3 display those
4022 ;;;!!! included images, so we just display it as a mixed multipart.
4023 (gnus-mime-display-mixed (cdr handle)))
4024 ((equal (car handle) "multipart/signed")
4025 (or (memq 'signed gnus-article-wash-types)
4026 (push 'signed gnus-article-wash-types))
4027 (gnus-mime-display-security handle))
4028 ((equal (car handle) "multipart/encrypted")
4029 (or (memq 'encrypted gnus-article-wash-types)
4030 (push 'encrypted gnus-article-wash-types))
4031 (gnus-mime-display-security handle))
4032 ;; Other multiparts are handled like multipart/mixed.
4034 (gnus-mime-display-mixed (cdr handle)))))
4036 (defun gnus-mime-part-function (handles)
4037 (if (stringp (car handles))
4038 (mapcar 'gnus-mime-part-function (cdr handles))
4039 (funcall gnus-article-mime-part-function handles)))
4041 (defun gnus-mime-display-mixed (handles)
4042 (mapcar 'gnus-mime-display-part handles))
4044 (defun gnus-mime-display-single (handle)
4045 (let ((type (mm-handle-media-type handle))
4046 (ignored gnus-ignored-mime-types)
4053 (when (string-match (pop ignored) type)
4054 (throw 'ignored nil)))
4055 (if (and (setq not-attachment
4056 (and (not (mm-inline-override-p handle))
4057 (or (not (mm-handle-disposition handle))
4058 (equal (car (mm-handle-disposition handle))
4060 (mm-attachment-override-p handle))))
4061 (mm-automatic-display-p handle)
4062 (or (mm-inlined-p handle)
4063 (mm-automatic-external-display-p type)))
4065 (when (equal (mm-handle-media-supertype handle) "text")
4067 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4069 (push (cons id handle) gnus-article-mime-handle-alist)
4070 (when (or (not display)
4071 (not (gnus-unbuttonized-mime-type-p type)))
4072 ;(gnus-article-insert-newline)
4073 (gnus-insert-mime-button
4074 handle id (list (or display (and not-attachment text))))
4075 (gnus-article-insert-newline)
4076 ;(gnus-article-insert-newline)
4077 ;; Remember modify the number of forward lines.
4085 (let ((mail-parse-charset gnus-newsgroup-charset)
4086 (mail-parse-ignored-charsets
4087 (save-excursion (condition-case ()
4088 (set-buffer gnus-summary-buffer)
4090 gnus-newsgroup-ignored-charsets)))
4091 (mm-display-part handle t))
4092 (goto-char (point-max)))
4093 ((and text not-attachment)
4097 (gnus-article-insert-newline)
4098 (mm-insert-inline handle (mm-get-part handle))
4099 (goto-char (point-max))))
4103 (narrow-to-region beg (point))
4106 (gnus-article-mime-total-parts)
4107 (mm-handle-media-type handle)))))))))
4109 (defun gnus-unbuttonized-mime-type-p (type)
4110 "Say whether TYPE is to be unbuttonized."
4111 (unless gnus-inhibit-mime-unbuttonizing
4113 (let ((types gnus-unbuttonized-mime-types))
4115 (when (string-match (pop types) type)
4116 (throw 'found t)))))))
4118 (defun gnus-article-insert-newline ()
4119 "Insert a newline, but mark it as undeletable."
4120 (gnus-put-text-property
4121 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4123 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4124 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4127 handle buffer-read-only from props begend not-pref)
4128 (save-window-excursion
4131 (narrow-to-region (car ibegend)
4134 (goto-char (car ibegend))
4137 (delete-region (point-min) (point-max))
4138 (mm-remove-parts handles))
4139 (setq begend (list (point-marker)))
4141 (unless (setq not-pref (cadr (member preferred ihandles)))
4142 (setq not-pref (car ihandles)))
4145 (not (gnus-unbuttonized-mime-type-p
4146 "multipart/alternative")))
4147 (gnus-add-text-properties
4150 (insert (format "%d. " id))
4154 (unless ,(not ibegend)
4155 (setq gnus-article-mime-handle-alist
4156 ',gnus-article-mime-handle-alist))
4157 (gnus-mime-display-alternative
4158 ',ihandles ',not-pref ',begend ,id))
4159 ,@(if (>= (string-to-number emacs-version) 21)
4160 nil ;; XEmacs doesn't care
4161 (list 'local-map gnus-mime-button-map))
4162 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4163 face ,gnus-article-button-face
4164 keymap ,gnus-mime-button-map
4167 (widget-convert-button 'link from (point)
4168 :action 'gnus-widget-press-button
4169 :button-keymap gnus-widget-button-keymap)
4171 (while (setq handle (pop handles))
4172 (gnus-add-text-properties
4175 (insert (format "(%c) %-18s"
4176 (if (equal handle preferred) ?* ? )
4177 (mm-handle-media-type handle)))
4181 (unless ,(not ibegend)
4182 (setq gnus-article-mime-handle-alist
4183 ',gnus-article-mime-handle-alist))
4184 (gnus-mime-display-alternative
4185 ',ihandles ',handle ',begend ,id))
4186 ,@(if (>= (string-to-number emacs-version) 21)
4187 nil ;; XEmacs doesn't care
4188 (list 'local-map gnus-mime-button-map))
4189 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4190 face ,gnus-article-button-face
4191 keymap ,gnus-mime-button-map
4194 (widget-convert-button 'link from (point)
4195 :action 'gnus-widget-press-button
4196 :button-keymap gnus-widget-button-keymap)
4200 (if (stringp (car preferred))
4201 (gnus-display-mime preferred)
4202 (let ((mail-parse-charset gnus-newsgroup-charset)
4203 (mail-parse-ignored-charsets
4204 (save-excursion (set-buffer gnus-summary-buffer)
4205 gnus-newsgroup-ignored-charsets)))
4206 (mm-display-part preferred)
4210 (narrow-to-region (car begend) (point-max))
4212 nil (length gnus-article-mime-handle-alist)
4213 (gnus-article-mime-total-parts)
4214 (mm-handle-media-type handle))))))
4215 (goto-char (point-max))
4216 (setcdr begend (point-marker)))))
4218 (goto-char point))))
4220 (defun gnus-article-wash-status ()
4221 "Return a string which display status of article washing."
4223 (set-buffer gnus-article-buffer)
4224 (let ((cite (memq 'cite gnus-article-wash-types))
4225 (headers (memq 'headers gnus-article-wash-types))
4226 (boring (memq 'boring-headers gnus-article-wash-types))
4227 (pgp (memq 'pgp gnus-article-wash-types))
4228 (pem (memq 'pem gnus-article-wash-types))
4229 (signed (memq 'signed gnus-article-wash-types))
4230 (encrypted (memq 'encrypted gnus-article-wash-types))
4231 (signature (memq 'signature gnus-article-wash-types))
4232 (overstrike (memq 'overstrike gnus-article-wash-types))
4233 (emphasis (memq 'emphasis gnus-article-wash-types)))
4234 (format "%c%c%c%c%c%c%c"
4236 (if (or headers boring) ?h ? )
4237 (if (or pgp pem signed encrypted) ?p ? )
4238 (if signature ?s ? )
4239 (if overstrike ?o ? )
4240 (if gnus-show-mime ?m ? )
4241 (if emphasis ?e ? )))))
4243 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4245 (defun gnus-article-maybe-hide-headers ()
4246 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4247 Provided for backwards compatibility."
4248 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4249 (not (save-excursion (set-buffer gnus-summary-buffer)
4250 gnus-have-all-headers)))
4251 (not gnus-inhibit-hiding))
4252 (gnus-article-hide-headers)))
4256 (defun gnus-output-to-file (file-name)
4257 "Append the current article to a file named FILE-NAME."
4258 (let ((artbuf (current-buffer)))
4260 (insert-buffer-substring artbuf)
4261 ;; Append newline at end of the buffer as separator, and then
4263 (goto-char (point-max))
4265 (write-region-as-binary (point-min) (point-max) file-name 'append)
4268 (defun gnus-narrow-to-page (&optional arg)
4269 "Narrow the article buffer to a page.
4270 If given a numerical ARG, move forward ARG pages."
4272 (setq arg (if arg (prefix-numeric-value arg) 0))
4274 (set-buffer gnus-article-buffer)
4275 (goto-char (point-min))
4277 ;; Remove any old next/prev buttons.
4278 (when (gnus-visual-p 'page-marker)
4279 (let ((buffer-read-only nil))
4280 (gnus-remove-text-with-property 'gnus-prev)
4281 (gnus-remove-text-with-property 'gnus-next)))
4284 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4286 (re-search-forward page-delimiter nil 'move arg)))
4287 (goto-char (match-end 0)))
4290 (if (re-search-forward page-delimiter nil 'move)
4293 (when (and (gnus-visual-p 'page-marker)
4294 (not (= (point-min) 1)))
4296 (goto-char (point-min))
4297 (gnus-insert-prev-page-button)))
4298 (when (and (gnus-visual-p 'page-marker)
4299 (< (+ (point-max) 2) (buffer-size)))
4301 (goto-char (point-max))
4302 (gnus-insert-next-page-button)))))
4304 ;; Article mode commands
4306 (defun gnus-article-goto-next-page ()
4307 "Show the next page of the article."
4309 (when (gnus-article-next-page)
4310 (goto-char (point-min))
4311 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4313 (defun gnus-article-goto-prev-page ()
4314 "Show the next page of the article."
4316 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4317 (gnus-article-prev-page nil)))
4319 (defun gnus-article-next-page (&optional lines)
4320 "Show the next page of the current article.
4321 If end of article, return non-nil. Otherwise return nil.
4322 Argument LINES specifies lines to be scrolled up."
4324 (let ((start (window-start))
4325 end-of-buffer end-of-page)
4327 (move-to-window-line -1)
4328 (if (<= (point) start)
4331 (setq start (point)))
4334 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4335 (and (pos-visible-in-window-p)
4336 (setq end-of-buffer t)))
4338 (setq end-of-page t)))
4340 (move-to-window-line lines)
4341 (unless (search-backward "\n\n" nil t)
4342 (setq start (point)))))
4343 (cond (end-of-buffer t)
4345 (gnus-narrow-to-page 1)
4349 (set-window-start (selected-window) start)
4350 (let (window-pixel-scroll-increment)
4354 (defun gnus-article-prev-page (&optional lines)
4355 "Show previous page of current article.
4356 Argument LINES specifies lines to be scrolled down."
4358 (let (beginning-of-buffer beginning-of-page)
4360 (move-to-window-line 0)
4361 (cond ((eq 1 (point))
4362 (setq beginning-of-buffer t))
4364 (setq beginning-of-page t))))
4365 (cond (beginning-of-buffer)
4367 (gnus-narrow-to-page -1))
4370 (let (window-pixel-scroll-increment)
4371 (scroll-down lines))
4372 (beginning-of-buffer
4373 (goto-char (point-min))))))))
4375 (defun gnus-article-refer-article ()
4376 "Read article specified by message-id around point."
4378 (let ((point (point)))
4379 (search-forward ">" nil t) ;Move point to end of "<....>".
4380 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4381 (let ((message-id (match-string 1)))
4383 (set-buffer gnus-summary-buffer)
4384 (gnus-summary-refer-article message-id))
4386 (error "No references around point"))))
4388 (defun gnus-article-show-summary ()
4389 "Reconfigure windows to show summary buffer."
4391 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4392 (error "There is no summary buffer for this article buffer")
4393 (gnus-article-set-globals)
4394 (gnus-configure-windows 'article)
4395 (gnus-summary-goto-subject gnus-current-article)
4396 (gnus-summary-position-point)))
4398 (defun gnus-article-describe-briefly ()
4399 "Describe article mode commands briefly."
4401 (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")))
4403 (defun gnus-article-summary-command ()
4404 "Execute the last keystroke in the summary buffer."
4406 (let ((obuf (current-buffer))
4407 (owin (current-window-configuration))
4409 (switch-to-buffer gnus-article-current-summary 'norecord)
4410 (setq func (lookup-key (current-local-map) (this-command-keys)))
4411 (call-interactively func)
4413 (set-window-configuration owin)
4414 (set-window-point (get-buffer-window (current-buffer)) (point))))
4416 (defun gnus-article-summary-command-nosave ()
4417 "Execute the last keystroke in the summary buffer."
4420 (pop-to-buffer gnus-article-current-summary 'norecord)
4421 (setq func (lookup-key (current-local-map) (this-command-keys)))
4422 (call-interactively func)))
4424 (defun gnus-article-check-buffer ()
4425 "Beep if not in an article buffer."
4426 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4427 (error "Command invoked outside of a Gnus article buffer")))
4429 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4430 "Read a summary buffer key sequence and execute it from the article buffer."
4432 (gnus-article-check-buffer)
4434 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4435 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4436 "=" "^" "\M-^" "|"))
4442 '("n" "Gn" "p" "Gp"))
4445 (set-buffer gnus-article-current-summary)
4446 (let (gnus-pick-mode)
4447 (push (or key last-command-event) unread-command-events)
4448 (setq keys (static-if (featurep 'xemacs)
4449 (events-to-keys (read-key-sequence nil))
4450 (read-key-sequence nil)))))
4453 (if (or (member keys nosaves)
4454 (member keys nosave-but-article)
4455 (member keys nosave-in-article))
4457 (save-window-excursion
4458 (pop-to-buffer gnus-article-current-summary 'norecord)
4459 ;; We disable the pick minor mode commands.
4460 (let (gnus-pick-mode)
4461 (setq func (lookup-key (current-local-map) keys))))
4465 (unless (member keys nosave-in-article)
4466 (set-buffer gnus-article-current-summary))
4467 (call-interactively func)
4468 (setq new-sum-point (point)))
4469 (when (member keys nosave-but-article)
4470 (pop-to-buffer gnus-article-buffer 'norecord)))
4471 ;; These commands should restore window configuration.
4472 (let ((obuf (current-buffer))
4473 (owin (current-window-configuration))
4475 (summary gnus-article-current-summary)
4476 func in-buffer selected)
4477 (if not-restore-window
4478 (pop-to-buffer summary 'norecord)
4479 (switch-to-buffer summary 'norecord))
4480 (setq in-buffer (current-buffer))
4481 ;; We disable the pick minor mode commands.
4482 (if (and (setq func (let (gnus-pick-mode)
4483 (lookup-key (current-local-map) keys)))
4486 (call-interactively func)
4487 (setq new-sum-point (point))
4488 (when (eq in-buffer (current-buffer))
4489 (setq selected (gnus-summary-select-article))
4491 (unless not-restore-window
4492 (set-window-configuration owin))
4493 (when (eq selected 'old)
4495 (set-window-start (get-buffer-window (current-buffer))
4497 (set-window-point (get-buffer-window (current-buffer))
4499 (let ((win (get-buffer-window gnus-article-current-summary)))
4501 (set-window-point win new-sum-point)))) )
4502 (switch-to-buffer gnus-article-buffer)
4505 (defun gnus-article-describe-key (key)
4506 "Display documentation of the function invoked by KEY. KEY is a string."
4507 (interactive "kDescribe key: ")
4508 (gnus-article-check-buffer)
4509 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4511 (set-buffer gnus-article-current-summary)
4512 (let (gnus-pick-mode)
4513 (push (elt key 0) unread-command-events)
4514 (setq key (if (featurep 'xemacs)
4515 (events-to-keys (read-key-sequence "Describe key: "))
4516 (read-key-sequence "Describe key: "))))
4518 (describe-key key)))
4520 (defun gnus-article-describe-key-briefly (key &optional insert)
4521 "Display documentation of the function invoked by KEY. KEY is a string."
4522 (interactive "kDescribe key: \nP")
4523 (gnus-article-check-buffer)
4524 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4526 (set-buffer gnus-article-current-summary)
4527 (let (gnus-pick-mode)
4528 (push (elt key 0) unread-command-events)
4529 (setq key (if (featurep 'xemacs)
4530 (events-to-keys (read-key-sequence "Describe key: "))
4531 (read-key-sequence "Describe key: "))))
4532 (describe-key-briefly key insert))
4533 (describe-key-briefly key insert)))
4535 (defun gnus-article-hide (&optional arg force)
4536 "Hide all the gruft in the current article.
4537 This means that PGP stuff, signatures, cited text and (some)
4538 headers will be hidden.
4539 If given a prefix, show the hidden text instead."
4540 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4541 (gnus-article-hide-headers arg)
4542 (gnus-article-hide-list-identifiers arg)
4543 (gnus-article-hide-pgp arg)
4544 (gnus-article-hide-citation-maybe arg force)
4545 (gnus-article-hide-signature arg))
4547 (defun gnus-article-maybe-highlight ()
4548 "Do some article highlighting if article highlighting is requested."
4549 (when (gnus-visual-p 'article-highlight 'highlight)
4550 (gnus-article-highlight-some)))
4552 (defun gnus-check-group-server ()
4553 ;; Make sure the connection to the server is alive.
4554 (unless (gnus-server-opened
4555 (gnus-find-method-for-group gnus-newsgroup-name))
4556 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4557 (gnus-request-group gnus-newsgroup-name t)))
4559 (defun gnus-request-article-this-buffer (article group)
4560 "Get an article and insert it into this buffer."
4561 (let (do-update-line sparse-header)
4565 (gnus-kill-all-overlays)
4566 (setq group (or group gnus-newsgroup-name))
4568 ;; Using `gnus-request-article' directly will insert the article into
4569 ;; `nntp-server-buffer' - so we'll save some time by not having to
4570 ;; copy it from the server buffer into the article buffer.
4572 ;; We only request an article by message-id when we do not have the
4573 ;; headers for it, so we'll have to get those.
4574 (when (stringp article)
4575 (gnus-read-header article))
4577 ;; If the article number is negative, that means that this article
4578 ;; doesn't belong in this newsgroup (possibly), so we find its
4579 ;; message-id and request it by id instead of number.
4580 (when (and (numberp article)
4582 (get-buffer gnus-summary-buffer)
4583 (gnus-buffer-exists-p gnus-summary-buffer))
4585 (set-buffer gnus-summary-buffer)
4586 (let ((header (gnus-summary-article-header article)))
4589 ((memq article gnus-newsgroup-sparse)
4590 ;; This is a sparse gap article.
4591 (setq do-update-line article)
4592 (setq article (mail-header-id header))
4593 (setq sparse-header (gnus-read-header article))
4594 (setq gnus-newsgroup-sparse
4595 (delq article gnus-newsgroup-sparse)))
4597 ;; It's a real article.
4598 (setq article (mail-header-id header)))
4600 ;; It is an extracted pseudo-article.
4601 (setq article 'pseudo)
4602 (gnus-request-pseudo-article header))))
4604 (let ((method (gnus-find-method-for-group
4605 gnus-newsgroup-name)))
4606 (when (and (eq (car method) 'nneething)
4608 (let ((dir (expand-file-name
4609 (mail-header-subject header)
4610 (file-name-as-directory
4611 (or (cadr (assq 'nneething-address method))
4613 (when (file-directory-p dir)
4614 (setq article 'nneething)
4615 (gnus-group-enter-directory dir))))))))
4618 ;; Refuse to select canceled articles.
4619 ((and (numberp article)
4621 (get-buffer gnus-summary-buffer)
4622 (gnus-buffer-exists-p gnus-summary-buffer)
4623 (eq (cdr (save-excursion
4624 (set-buffer gnus-summary-buffer)
4625 (assq article gnus-newsgroup-reads)))
4626 gnus-canceled-mark))
4628 ;; Check the backlog.
4629 ((and gnus-keep-backlog
4630 (gnus-backlog-request-article group article (current-buffer)))
4632 ;; Check asynchronous pre-fetch.
4633 ((gnus-async-request-fetched-article group article (current-buffer))
4634 (gnus-async-prefetch-next group article gnus-summary-buffer)
4635 (when (and (numberp article) gnus-keep-backlog)
4636 (gnus-backlog-enter-article group article (current-buffer)))
4639 ((and gnus-use-cache
4641 (gnus-cache-request-article article group))
4643 ;; Get the article and put into the article buffer.
4644 ((or (stringp article)
4646 (let ((gnus-override-method gnus-override-method)
4647 (methods (and (stringp article)
4648 gnus-refer-article-method))
4650 (buffer-read-only nil))
4651 (if (or (not (listp methods))
4652 (and (symbolp (car methods))
4653 (assq (car methods) nnoo-definition-alist)))
4654 (setq methods (list methods)))
4655 (when (and (null gnus-override-method)
4657 (setq gnus-override-method (pop methods)))
4659 (when (eq gnus-override-method 'current)
4660 (setq gnus-override-method gnus-current-select-method))
4662 (gnus-kill-all-overlays)
4663 (let ((gnus-newsgroup-name group))
4664 (gnus-check-group-server))
4665 (when (gnus-request-article article group (current-buffer))
4666 (when (numberp article)
4667 (gnus-async-prefetch-next group article
4668 gnus-summary-buffer)
4669 (when gnus-keep-backlog
4670 (gnus-backlog-enter-article
4671 group article (current-buffer))))
4672 (setq result 'article))
4675 (setq gnus-override-method (pop methods))
4676 (setq result 'done))))
4677 (and (eq result 'article) 'article)))
4681 ;; Associate this article with the current summary buffer.
4682 (setq gnus-article-current-summary gnus-summary-buffer)
4684 ;; Take the article from the original article buffer
4685 ;; and place it in the buffer it's supposed to be in.
4686 (when (and (get-buffer gnus-article-buffer)
4687 (equal (buffer-name (current-buffer))
4688 (buffer-name (get-buffer gnus-article-buffer))))
4690 (if (get-buffer gnus-original-article-buffer)
4691 (set-buffer gnus-original-article-buffer)
4692 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4693 (set-buffer-multibyte nil)
4694 (buffer-disable-undo)
4695 (setq major-mode 'gnus-original-article-mode)
4696 (setq buffer-read-only t))
4697 (let (buffer-read-only)
4699 (insert-buffer-substring gnus-article-buffer))
4700 (setq gnus-original-article (cons group article)))
4703 (run-hooks 'gnus-article-decode-hook)
4704 ;; Mark article as decoded or not.
4705 (setq gnus-article-decoded-p gnus-article-decode-hook))
4707 ;; Update sparse articles.
4708 (when (and do-update-line
4709 (or (numberp article)
4711 (let ((buf (current-buffer)))
4712 (set-buffer gnus-summary-buffer)
4713 (gnus-summary-update-article do-update-line sparse-header)
4714 (gnus-summary-goto-subject do-update-line nil t)
4715 (set-window-point (get-buffer-window (current-buffer) t)
4717 (set-buffer buf))))))
4723 (defcustom gnus-article-edit-mode-hook nil
4724 "Hook run in article edit mode buffers."
4725 :group 'gnus-article-various
4728 (defcustom gnus-article-edit-article-setup-function
4729 'gnus-article-mime-edit-article-setup
4730 "Function called to setup an editing article buffer."
4731 :group 'gnus-article-various
4734 (defvar gnus-article-edit-done-function nil)
4736 (defvar gnus-article-edit-mode-map nil)
4738 ;; Should we be using derived.el for this?
4739 (unless gnus-article-edit-mode-map
4740 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4741 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4743 (gnus-define-keys gnus-article-edit-mode-map
4744 "\C-c\C-c" gnus-article-edit-done
4745 "\C-c\C-k" gnus-article-edit-exit)
4747 (gnus-define-keys (gnus-article-edit-wash-map
4748 "\C-c\C-w" gnus-article-edit-mode-map)
4749 "f" gnus-article-edit-full-stops))
4751 (defun gnus-article-edit-mode ()
4752 "Major mode for editing articles.
4753 This is an extended text-mode.
4755 \\{gnus-article-edit-mode-map}"
4757 (setq major-mode 'gnus-article-edit-mode)
4758 (setq mode-name "Article Edit")
4759 (use-local-map gnus-article-edit-mode-map)
4760 (make-local-variable 'gnus-article-edit-done-function)
4761 (make-local-variable 'gnus-prev-winconf)
4762 (setq buffer-read-only nil)
4763 (buffer-enable-undo)
4765 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4767 (defun gnus-article-edit (&optional force)
4768 "Edit the current article.
4769 This will have permanent effect only in mail groups.
4770 If FORCE is non-nil, allow editing of articles even in read-only
4773 (when (and (not force)
4774 (gnus-group-read-only-p))
4775 (error "The current newsgroup does not support article editing"))
4776 (gnus-article-date-original)
4777 (gnus-article-edit-article
4779 `(lambda (no-highlight)
4781 (gnus-summary-edit-article-done
4782 ,(or (mail-header-references gnus-current-headers) "")
4783 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4785 (defun gnus-article-edit-article (start-func exit-func)
4786 "Start editing the contents of the current article buffer."
4787 (let ((winconf (current-window-configuration)))
4788 (set-buffer gnus-article-buffer)
4789 (gnus-article-edit-mode)
4790 (funcall start-func)
4791 (gnus-configure-windows 'edit-article)
4792 (setq gnus-article-edit-done-function exit-func)
4793 (setq gnus-prev-winconf winconf)
4794 (when gnus-article-edit-article-setup-function
4795 (funcall gnus-article-edit-article-setup-function))
4796 (gnus-message 6 "C-c C-c to end edits")))
4798 (defun gnus-article-edit-done (&optional arg)
4799 "Update the article edits and exit."
4801 (let ((func gnus-article-edit-done-function)
4802 (buf (current-buffer))
4803 (start (window-start)))
4804 (remove-hook 'gnus-article-mode-hook
4805 'gnus-article-mime-edit-article-unwind)
4806 (gnus-article-edit-exit)
4809 (let ((buffer-read-only nil))
4811 ;; The cache and backlog have to be flushed somewhat.
4812 (when gnus-keep-backlog
4813 (gnus-backlog-remove-article
4814 (car gnus-article-current) (cdr gnus-article-current)))
4815 ;; Flush original article as well.
4817 (when (get-buffer gnus-original-article-buffer)
4818 (set-buffer gnus-original-article-buffer)
4819 (setq gnus-original-article nil)))
4820 (when gnus-use-cache
4821 (gnus-cache-update-article
4822 (car gnus-article-current) (cdr gnus-article-current))))
4824 (set-window-start (get-buffer-window buf) start)
4825 (set-window-point (get-buffer-window buf) (point))))
4827 (defun gnus-article-edit-exit ()
4828 "Exit the article editing without updating."
4830 ;; We remove all text props from the article buffer.
4831 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4832 (curbuf (current-buffer))
4834 (window-start (window-start)))
4837 (let ((winconf gnus-prev-winconf))
4839 (set-window-configuration winconf)
4840 ;; Tippy-toe some to make sure that point remains where it was.
4841 (save-current-buffer
4843 (set-window-start (get-buffer-window (current-buffer)) window-start)
4846 (defun gnus-article-edit-full-stops ()
4847 "Interactively repair spacing at end of sentences."
4850 (goto-char (point-min))
4851 (search-forward-regexp "^$" nil t)
4852 (let ((case-fold-search nil))
4853 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4856 ;;; Article editing with MIME-Edit
4859 (defcustom gnus-article-mime-edit-article-setup-hook nil
4860 "Hook run after setting up a MIME editing article buffer."
4861 :group 'gnus-article-various
4864 (defun gnus-article-mime-edit-article-unwind ()
4865 "Unwind `gnus-article-buffer' if article editing was given up."
4866 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4867 (when mime-edit-mode-flag
4868 (mime-edit-exit 'nomime 'no-error)
4870 (when (featurep 'font-lock)
4871 (setq font-lock-defaults nil)
4872 (font-lock-mode 0)))
4874 (defun gnus-article-mime-edit-article-setup ()
4875 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4876 after replacing with the original article."
4877 (setq gnus-show-mime t)
4878 (setq gnus-article-edit-done-function
4879 `(lambda (&rest args)
4880 (when mime-edit-mode-flag
4883 (goto-char (point-min))
4884 (let (case-fold-search)
4885 (when (re-search-forward
4886 (format "^%s$" (regexp-quote mail-header-separator))
4888 (replace-match "")))
4889 (when (featurep 'font-lock)
4890 (setq font-lock-defaults nil)
4892 (apply ,gnus-article-edit-done-function args)
4893 (set-buffer gnus-original-article-buffer)
4895 (insert-buffer gnus-article-buffer)
4896 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4897 (gnus-article-prepare-display)))
4898 (substitute-key-definition
4899 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4900 gnus-article-edit-mode-map)
4902 (insert-buffer gnus-original-article-buffer)
4904 (when (featurep 'font-lock)
4905 (set (make-local-variable 'font-lock-defaults)
4906 '(message-font-lock-keywords t))
4907 (font-lock-set-defaults)
4908 (turn-on-font-lock))
4909 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4910 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4912 (defun gnus-article-mime-edit-exit ()
4913 "Exit the article MIME editing without updating."
4915 (let ((winconf gnus-prev-winconf)
4917 (when mime-edit-mode-flag
4920 (goto-char (point-min))
4921 (let (case-fold-search)
4922 (when (re-search-forward
4923 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4924 (replace-match "")))
4925 (when (featurep 'font-lock)
4926 (setq font-lock-defaults nil)
4928 ;; We remove all text props from the article buffer.
4929 (setq buf (format "%s" (buffer-string)))
4930 (set-buffer (get-buffer-create gnus-original-article-buffer))
4933 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4934 (gnus-article-prepare-display)
4935 (set-window-configuration winconf)))
4938 ;;; Article highlights
4941 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4943 ;;; Internal Variables:
4945 (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\\)\\)"
4946 "Regular expression that matches URLs."
4947 :group 'gnus-article-buttons
4950 (defcustom gnus-button-alist
4951 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4952 0 t gnus-button-message-id 2)
4953 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4954 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4956 gnus-button-fetch-group 4)
4957 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4958 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4959 t gnus-button-message-id 3)
4960 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4961 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4962 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4963 ;; This is how URLs _should_ be embedded in text...
4964 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4966 (,gnus-button-url-regexp 0 t browse-url 0))
4967 "*Alist of regexps matching buttons in article bodies.
4969 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4970 REGEXP: is the string matching text around the button,
4971 BUTTON: is the number of the regexp grouping actually matching the button,
4972 FORM: is a lisp expression which must eval to true for the button to
4974 CALLBACK: is the function to call when the user push this button, and each
4975 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4977 CALLBACK can also be a variable, in that case the value of that
4978 variable it the real callback function."
4979 :group 'gnus-article-buttons
4980 :type '(repeat (list regexp
4981 (integer :tag "Button")
4983 (function :tag "Callback")
4986 (integer :tag "Regexp group")))))
4988 (defcustom gnus-header-button-alist
4989 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4990 0 t gnus-button-message-id 0)
4991 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4992 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4993 0 t gnus-button-mailto 0)
4994 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4995 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4996 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4997 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4998 gnus-button-message-id 3))
4999 "*Alist of headers and regexps to match buttons in article heads.
5001 This alist is very similar to `gnus-button-alist', except that each
5002 alist has an additional HEADER element first in each entry:
5004 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5006 HEADER is a regexp to match a header. For a fuller explanation, see
5007 `gnus-button-alist'."
5008 :group 'gnus-article-buttons
5009 :group 'gnus-article-headers
5010 :type '(repeat (list (regexp :tag "Header")
5012 (integer :tag "Button")
5014 (function :tag "Callback")
5017 (integer :tag "Regexp group")))))
5019 (defvar gnus-button-regexp nil)
5020 (defvar gnus-button-marker-list nil)
5021 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5023 (defvar gnus-button-last nil)
5024 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5028 (defun gnus-article-push-button (event)
5029 "Check text under the mouse pointer for a callback function.
5030 If the text under the mouse pointer has a `gnus-callback' property,
5031 call it with the value of the `gnus-data' text property."
5033 (set-buffer (window-buffer (posn-window (event-start event))))
5034 (let* ((pos (posn-point (event-start event)))
5035 (data (get-text-property pos 'gnus-data))
5036 (fun (get-text-property pos 'gnus-callback)))
5039 (funcall fun data))))
5041 (defun gnus-article-press-button ()
5042 "Check text at point for a callback function.
5043 If the text at point has a `gnus-callback' property,
5044 call it with the value of the `gnus-data' text property."
5046 (let* ((data (get-text-property (point) 'gnus-data))
5047 (fun (get-text-property (point) 'gnus-callback)))
5049 (funcall fun data))))
5051 (defun gnus-article-prev-button (n)
5052 "Move point to N buttons backward.
5053 If N is negative, move forward instead."
5055 (gnus-article-next-button (- n)))
5057 (defun gnus-article-next-button (n)
5058 "Move point to N buttons forward.
5059 If N is negative, move backward instead."
5061 (let ((function (if (< n 0) 'previous-single-property-change
5062 'next-single-property-change))
5063 (inhibit-point-motion-hooks t)
5065 (limit (if (< n 0) (point-min) (point-max))))
5067 (while (and (not (= limit (point)))
5069 ;; Skip past the current button.
5070 (when (get-text-property (point) 'gnus-callback)
5071 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5072 ;; Go to the next (or previous) button.
5073 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5074 ;; Put point at the start of the button.
5075 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5076 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5077 ;; Skip past intangible buttons.
5078 (when (get-text-property (point) 'intangible)
5082 (gnus-message 5 "No more buttons"))
5085 (defun gnus-article-highlight (&optional force)
5086 "Highlight current article.
5087 This function calls `gnus-article-highlight-headers',
5088 `gnus-article-highlight-citation',
5089 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5090 do the highlighting. See the documentation for those functions."
5091 (interactive (list 'force))
5092 (gnus-article-highlight-headers)
5093 (gnus-article-highlight-citation force)
5094 (gnus-article-highlight-signature)
5095 (gnus-article-add-buttons force)
5096 (gnus-article-add-buttons-to-head))
5098 (defun gnus-article-highlight-some (&optional force)
5099 "Highlight current article.
5100 This function calls `gnus-article-highlight-headers',
5101 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5102 do the highlighting. See the documentation for those functions."
5103 (interactive (list 'force))
5104 (gnus-article-highlight-headers)
5105 (gnus-article-highlight-signature)
5106 (gnus-article-add-buttons))
5108 (defun gnus-article-highlight-headers ()
5109 "Highlight article headers as specified by `gnus-header-face-alist'."
5112 (set-buffer gnus-article-buffer)
5114 (let ((alist gnus-header-face-alist)
5115 (buffer-read-only nil)
5116 (case-fold-search t)
5117 (inhibit-point-motion-hooks t)
5118 entry regexp header-face field-face from hpoints fpoints)
5119 (article-narrow-to-head)
5120 (while (setq entry (pop alist))
5121 (goto-char (point-min))
5122 (setq regexp (concat "^\\("
5123 (if (string-equal "" (nth 0 entry))
5127 header-face (nth 1 entry)
5128 field-face (nth 2 entry))
5129 (while (and (re-search-forward regexp nil t)
5133 (unless (search-forward ":" nil t)
5135 (when (and header-face
5136 (not (memq (point) hpoints)))
5137 (push (point) hpoints)
5138 (gnus-put-text-property from (point) 'face header-face))
5139 (when (and field-face
5140 (not (memq (setq from (point)) fpoints)))
5142 (if (re-search-forward "^[^ \t]" nil t)
5144 (goto-char (point-max)))
5145 (gnus-put-text-property from (point) 'face field-face))))))))
5147 (defun gnus-article-highlight-signature ()
5148 "Highlight the signature in an article.
5149 It does this by highlighting everything after
5150 `gnus-signature-separator' using `gnus-signature-face'."
5152 (when gnus-signature-face
5154 (set-buffer gnus-article-buffer)
5155 (let ((buffer-read-only nil)
5156 (inhibit-point-motion-hooks t))
5158 (when (gnus-article-narrow-to-signature)
5159 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5160 'face gnus-signature-face)))))))
5162 (defun gnus-article-buttonize-signature ()
5163 "Add button to the signature."
5166 (set-buffer gnus-article-buffer)
5167 (let ((buffer-read-only nil)
5168 (inhibit-point-motion-hooks t))
5169 (when (gnus-article-search-signature)
5170 (gnus-article-add-button (match-beginning 0) (match-end 0)
5171 'gnus-signature-toggle
5172 (set-marker (make-marker)
5173 (1+ (match-end 0))))))))
5175 (defun gnus-button-in-region-p (b e prop)
5176 "Say whether PROP exists in the region."
5177 (text-property-not-all b e prop nil))
5179 (defun gnus-article-add-buttons (&optional force)
5180 "Find external references in the article and make buttons of them.
5181 \"External references\" are things like Message-IDs and URLs, as
5182 specified by `gnus-button-alist'."
5183 (interactive (list 'force))
5185 (set-buffer gnus-article-buffer)
5186 (let ((buffer-read-only nil)
5187 (inhibit-point-motion-hooks t)
5188 (case-fold-search t)
5189 (alist gnus-button-alist)
5191 ;; Remove all old markers.
5192 (let (marker entry new-list)
5193 (while (setq marker (pop gnus-button-marker-list))
5194 (if (or (< marker (point-min)) (>= marker (point-max)))
5195 (push marker new-list)
5197 (when (setq entry (gnus-button-entry))
5198 (put-text-property (match-beginning (nth 1 entry))
5199 (match-end (nth 1 entry))
5200 'gnus-callback nil))
5201 (set-marker marker nil)))
5202 (setq gnus-button-marker-list new-list))
5203 ;; We skip the headers.
5206 (while (setq entry (pop alist))
5207 (setq regexp (car entry))
5209 (while (re-search-forward regexp nil t)
5210 (let* ((start (and entry (match-beginning (nth 1 entry))))
5211 (end (and entry (match-end (nth 1 entry))))
5212 (from (match-beginning 0)))
5213 (when (and (or (eq t (nth 2 entry))
5214 (eval (nth 2 entry)))
5215 (not (gnus-button-in-region-p
5216 start end 'gnus-callback)))
5217 ;; That optional form returned non-nil, so we add the
5219 (gnus-article-add-button
5220 start end 'gnus-button-push
5221 (car (push (set-marker (make-marker) from)
5222 gnus-button-marker-list))))))))))
5224 ;; Add buttons to the head of an article.
5225 (defun gnus-article-add-buttons-to-head ()
5226 "Add buttons to the head of the article."
5229 (set-buffer gnus-article-buffer)
5231 (let ((buffer-read-only nil)
5232 (inhibit-point-motion-hooks t)
5233 (case-fold-search t)
5234 (alist gnus-header-button-alist)
5236 (article-narrow-to-head)
5238 ;; Each alist entry.
5239 (setq entry (car alist)
5241 (goto-char (point-min))
5242 (while (re-search-forward (car entry) nil t)
5243 ;; Each header matching the entry.
5244 (setq beg (match-beginning 0))
5245 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5246 (match-beginning 0))
5249 (while (re-search-forward (nth 1 entry) end t)
5250 ;; Each match within a header.
5251 (let* ((entry (cdr entry))
5252 (start (match-beginning (nth 1 entry)))
5253 (end (match-end (nth 1 entry)))
5254 (form (nth 2 entry)))
5255 (goto-char (match-end 0))
5257 (gnus-article-add-button
5258 start end (nth 3 entry)
5259 (buffer-substring (match-beginning (nth 4 entry))
5260 (match-end (nth 4 entry)))))))
5261 (goto-char end)))))))
5263 ;;; External functions:
5265 (defun gnus-article-add-button (from to fun &optional data)
5266 "Create a button between FROM and TO with callback FUN and data DATA."
5267 (when gnus-article-button-face
5268 (gnus-overlay-put (gnus-make-overlay from to)
5269 'face gnus-article-button-face))
5270 (gnus-add-text-properties
5272 (nconc (and gnus-article-mouse-face
5273 (list gnus-mouse-face-prop gnus-article-mouse-face))
5274 (list 'gnus-callback fun)
5275 (and data (list 'gnus-data data))))
5276 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5277 ;; Quote `:button-keymap' for Mule 2.3
5278 ;; but it won't work.
5279 ':button-keymap gnus-widget-button-keymap))
5281 ;;; Internal functions:
5283 (defun gnus-article-set-globals ()
5285 (set-buffer gnus-summary-buffer)
5286 (gnus-set-global-variables)))
5288 (defun gnus-signature-toggle (end)
5290 (set-buffer gnus-article-buffer)
5291 (let ((buffer-read-only nil)
5292 (inhibit-point-motion-hooks t)
5293 (limit (next-single-property-change end 'mime-view-entity
5295 (if (text-property-any end limit 'article-type 'signature)
5296 (gnus-remove-text-properties-when
5297 'article-type 'signature end limit
5298 (cons 'article-type (cons 'signature
5299 gnus-hidden-properties)))
5300 (gnus-add-text-properties-when
5301 'article-type nil end limit
5302 (cons 'article-type (cons 'signature
5303 gnus-hidden-properties)))))))
5305 (defun gnus-button-entry ()
5306 ;; Return the first entry in `gnus-button-alist' matching this place.
5307 (let ((alist gnus-button-alist)
5310 (setq entry (pop alist))
5311 (if (looking-at (car entry))
5316 (defun gnus-button-push (marker)
5317 ;; Push button starting at MARKER.
5320 (let* ((entry (gnus-button-entry))
5321 (inhibit-point-motion-hooks t)
5323 (args (mapcar (lambda (group)
5324 (let ((string (match-string group)))
5325 (gnus-set-text-properties
5326 0 (length string) nil string)
5333 (fboundp (symbol-value fun)))
5334 (apply (symbol-value fun) args))
5336 (gnus-message 1 "You must define `%S' to use this button"
5337 (cons fun args)))))))
5339 (defun gnus-button-message-id (message-id)
5342 (set-buffer gnus-summary-buffer)
5343 (gnus-summary-refer-article message-id)))
5345 (defun gnus-button-fetch-group (address)
5346 "Fetch GROUP specified by ADDRESS."
5347 (if (not (string-match "[:/]" address))
5348 ;; This is just a simple group url.
5349 (gnus-group-read-ephemeral-group address gnus-select-method)
5350 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5352 (error "Can't parse %s" address)
5353 (gnus-group-read-ephemeral-group
5354 (match-string 4 address)
5355 `(nntp ,(match-string 1 address)
5356 (nntp-address ,(match-string 1 address))
5357 (nntp-port-number ,(if (match-end 3)
5358 (match-string 3 address)
5361 (defun gnus-url-parse-query-string (query &optional downcase)
5362 (let (retval pairs cur key val)
5363 (setq pairs (split-string query "&"))
5365 (setq cur (car pairs)
5367 (if (not (string-match "=" cur))
5369 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5370 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5372 (setq key (downcase key)))
5373 (setq cur (assoc key retval))
5375 (setcdr cur (cons val (cdr cur)))
5376 (setq retval (cons (list key val) retval)))))
5379 (defun gnus-url-unhex (x)
5386 (defun gnus-url-unhex-string (str &optional allow-newlines)
5387 "Remove %XXX embedded spaces, etc in a url.
5388 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5389 decoding of carriage returns and line feeds in the string, which is normally
5390 forbidden in URL encoding."
5391 (setq str (or str ""))
5393 (case-fold-search t))
5394 (while (string-match "%[0-9a-f][0-9a-f]" str)
5395 (let* ((start (match-beginning 0))
5396 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5398 (gnus-url-unhex (elt str (+ start 2))))))
5400 tmp (substring str 0 start)
5403 (char-to-string code))
5404 ((or (= code ?\n) (= code ?\r))
5406 (t (char-to-string code))))
5407 str (substring str (match-end 0)))))
5408 (setq tmp (concat tmp str))
5411 (defun gnus-url-mailto (url)
5412 ;; Send mail to someone
5413 (when (string-match "mailto:/*\\(.*\\)" url)
5414 (setq url (substring url (match-beginning 1) nil)))
5415 (let (to args subject func)
5416 (if (string-match (regexp-quote "?") url)
5417 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5418 args (gnus-url-parse-query-string
5419 (substring url (match-end 0) nil) t))
5420 (setq to (gnus-url-unhex-string url)))
5421 (setq args (cons (list "to" to) args)
5422 subject (cdr-safe (assoc "subject" args)))
5423 (gnus-setup-message 'reply
5426 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5429 (message-position-on-field (caar args)))
5430 (insert (mapconcat 'identity (cdar args) ", "))
5431 (setq args (cdr args)))
5434 (message-goto-subject)))))
5436 (defun gnus-button-mailto (address)
5438 (set-buffer (gnus-copy-article-buffer))
5439 (message-reply address))
5441 (defalias 'gnus-button-reply 'message-reply)
5443 (defun gnus-button-embedded-url (address)
5444 "Activate ADDRESS with `browse-url'."
5445 (browse-url (gnus-strip-whitespace address)))
5447 (defun gnus-article-smiley-display ()
5448 "Display \"smileys\" as small graphical icons."
5449 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5451 ;;; Next/prev buttons in the article buffer.
5453 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5454 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5456 (defvar gnus-prev-page-map nil)
5457 (unless gnus-prev-page-map
5458 (setq gnus-prev-page-map (make-sparse-keymap))
5459 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5460 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5462 (static-if (featurep 'xemacs)
5463 (defun gnus-insert-prev-page-button ()
5464 (let ((buffer-read-only nil))
5466 gnus-prev-page-line-format nil
5467 `(gnus-prev t local-map ,gnus-prev-page-map
5468 gnus-callback gnus-article-button-prev-page
5469 article-type annotation))))
5470 (defun gnus-insert-prev-page-button ()
5471 (let ((buffer-read-only nil)
5472 (situation (get-text-property (point-min) 'mime-view-situation)))
5473 (set-keymap-parent gnus-prev-page-map (current-local-map))
5475 gnus-prev-page-line-format nil
5476 `(gnus-prev t local-map ,gnus-prev-page-map
5477 gnus-callback gnus-article-button-prev-page
5478 article-type annotation
5479 mime-view-situation ,situation))))
5482 (defvar gnus-next-page-map nil)
5483 (unless gnus-next-page-map
5484 (setq gnus-next-page-map (make-sparse-keymap))
5485 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5486 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5488 (defun gnus-button-next-page ()
5489 "Go to the next page."
5491 (let ((win (selected-window)))
5492 (select-window (get-buffer-window gnus-article-buffer t))
5493 (gnus-article-next-page)
5494 (select-window win)))
5496 (defun gnus-button-prev-page ()
5497 "Go to the prev page."
5499 (let ((win (selected-window)))
5500 (select-window (get-buffer-window gnus-article-buffer t))
5501 (gnus-article-prev-page)
5502 (select-window win)))
5504 (static-if (featurep 'xemacs)
5505 (defun gnus-insert-next-page-button ()
5506 (let ((buffer-read-only nil))
5507 (gnus-eval-format gnus-next-page-line-format nil
5509 t local-map ,gnus-next-page-map
5510 gnus-callback gnus-article-button-next-page
5511 article-type annotation))))
5512 (defun gnus-insert-next-page-button ()
5513 (let ((buffer-read-only nil)
5514 (situation (get-text-property (point-min) 'mime-view-situation)))
5515 (set-keymap-parent gnus-next-page-map (current-local-map))
5516 (gnus-eval-format gnus-next-page-line-format nil
5518 t local-map ,gnus-next-page-map
5519 gnus-callback gnus-article-button-next-page
5520 article-type annotation
5521 mime-view-situation ,situation))))
5524 (defun gnus-article-button-next-page (arg)
5525 "Go to the next page."
5527 (let ((win (selected-window)))
5528 (select-window (get-buffer-window gnus-article-buffer t))
5529 (gnus-article-next-page)
5530 (select-window win)))
5532 (defun gnus-article-button-prev-page (arg)
5533 "Go to the prev page."
5535 (let ((win (selected-window)))
5536 (select-window (get-buffer-window gnus-article-buffer t))
5537 (gnus-article-prev-page)
5538 (select-window win)))
5540 (defvar gnus-decode-header-methods
5541 '(mail-decode-encoded-word-region)
5542 "List of methods used to decode headers.
5544 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5545 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5546 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5547 whose names match REGEXP.
5550 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5551 mail-decode-encoded-word-region
5552 (\"chinese\" . rfc1843-decode-region))
5555 (defvar gnus-decode-header-methods-cache nil)
5557 (defun gnus-multi-decode-header (start end)
5558 "Apply the functions from `gnus-encoded-word-methods' that match."
5559 (unless (and gnus-decode-header-methods-cache
5560 (eq gnus-newsgroup-name
5561 (car gnus-decode-header-methods-cache)))
5562 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5565 (nconc gnus-decode-header-methods-cache (list x))
5566 (if (and gnus-newsgroup-name
5567 (string-match (car x) gnus-newsgroup-name))
5568 (nconc gnus-decode-header-methods-cache
5570 gnus-decode-header-methods))
5571 (let ((xlist gnus-decode-header-methods-cache))
5574 (narrow-to-region start end)
5576 (funcall (pop xlist) (point-min) (point-max))))))
5579 ;;; Treatment top-level handling.
5582 (defun gnus-treat-article (condition &optional part-number total-parts type)
5583 (let ((length (- (point-max) (point-min)))
5584 (alist gnus-treatment-function-alist)
5585 (article-goto-body-goes-to-point-min-p t)
5589 (let ((list gnus-article-treat-types))
5591 (when (string-match (pop list) type)
5592 (throw 'found t)))))))
5593 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5594 (entity (static-unless (featurep 'xemacs)
5595 (when (eq 'head condition)
5596 (get-text-property (point-min) 'mime-view-entity))))
5597 val elem buttonized)
5598 (gnus-run-hooks 'gnus-part-display-hook)
5599 (unless gnus-inhibit-treatment
5600 (while (setq elem (pop alist))
5603 (if (gnus-buffer-live-p gnus-summary-buffer)
5604 (set-buffer gnus-summary-buffer))
5605 (symbol-value (car elem))))
5606 (when (and (or (consp val)
5608 (gnus-treat-predicate val)
5609 (or (not (get (car elem) 'highlight))
5611 (when (and (not buttonized)
5613 '(gnus-treat-hide-signature
5614 gnus-treat-highlight-signature)))
5615 (gnus-article-buttonize-signature)
5616 (setq buttonized t))
5618 (funcall (cadr elem)))))
5619 ;; FSF Emacsen does not inherit the existing text properties
5620 ;; in the new text, so we should do it for `mime-view-entity'.
5621 (static-unless (featurep 'xemacs)
5623 (put-text-property (point-min) (point-max)
5624 'mime-view-entity entity))))))
5626 ;; Dynamic variables.
5628 (defvar part-number)
5629 (defvar total-parts)
5634 (defun gnus-treat-predicate (val)
5639 (stringp (car val)))
5640 (apply 'gnus-or (mapcar `(lambda (s)
5641 (string-match s ,(or gnus-newsgroup-name "")))
5644 (let ((pred (pop val)))
5647 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5649 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5651 (not (gnus-treat-predicate (car val))))
5653 (equal (car val) type))
5655 (error "%S is not a valid predicate" pred)))))
5665 (eq part-number total-parts))
5669 (error "%S is not a valid value" val))))
5671 (defun gnus-article-encrypt-body (protocol &optional n)
5672 "Encrypt the article body."
5675 (or gnus-article-encrypt-protocol
5676 (completing-read "Encrypt protocol: "
5677 gnus-article-encrypt-protocol-alist
5679 current-prefix-arg))
5680 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5682 (error (format "Can't find the encrypt protocol %s" protocol)))
5683 (if (equal gnus-newsgroup-name "nndraft:drafts")
5684 (error "Can't encrypt the article in group nndraft:drafts."))
5685 (if (equal gnus-newsgroup-name "nndraft:queue")
5686 (error "Don't encrypt the article in group nndraft:queue."))
5687 (gnus-summary-iterate n
5689 (set-buffer gnus-summary-buffer)
5690 (let ((mail-parse-charset gnus-newsgroup-charset)
5691 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5692 (summary-buffer gnus-summary-buffer)
5694 (gnus-set-global-variables)
5695 (when (gnus-group-read-only-p)
5696 (error "The current newsgroup does not support article encrypt"))
5697 (gnus-summary-show-article t)
5699 (or (mail-header-references gnus-current-headers) ""))
5700 (set-buffer gnus-article-buffer)
5701 (let* ((buffer-read-only nil)
5703 (mapcar (lambda (field)
5704 (and (save-restriction
5705 (message-narrow-to-head)
5706 (goto-char (point-min))
5707 (search-forward field nil t))
5709 (message-narrow-to-field)
5710 (buffer-substring (point-min) (point-max))
5711 (delete-region (point-min) (point-max))
5713 '("Content-Type:" "Content-Transfer-Encoding:"
5714 "Content-Disposition:"))))
5715 (message-narrow-to-head)
5716 (message-remove-header "MIME-Version")
5717 (goto-char (point-max))
5718 (setq point (point))
5719 (insert (apply 'concat headers))
5721 (narrow-to-region point (point-max))
5722 (let ((message-options message-options))
5723 (message-options-set 'message-sender user-mail-address)
5724 (message-options-set 'message-recipients user-mail-address)
5725 (message-options-set 'message-sign-encrypt 'not)
5727 (goto-char (point-min))
5728 (insert "MIME-Version: 1.0\n")
5730 (gnus-summary-edit-article-done
5731 references nil summary-buffer t))
5732 (when gnus-keep-backlog
5733 (gnus-backlog-remove-article
5734 (car gnus-article-current) (cdr gnus-article-current)))
5736 (when (get-buffer gnus-original-article-buffer)
5737 (set-buffer gnus-original-article-buffer)
5738 (setq gnus-original-article nil)))
5739 (when gnus-use-cache
5740 (gnus-cache-update-article
5741 (car gnus-article-current) (cdr gnus-article-current))))))))
5743 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5744 "The following specs can be used:
5745 %t The security MIME type
5748 %D Details if button is pressed")
5750 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5751 "The following specs can be used:
5752 %t The security MIME type
5755 %D Details if button is pressed")
5757 (defvar gnus-mime-security-button-line-format-alist
5758 '((?t gnus-tmp-type ?s)
5759 (?i gnus-tmp-info ?s)
5760 (?d gnus-tmp-details ?s)
5761 (?D gnus-tmp-pressed-details ?s)))
5763 (defvar gnus-mime-security-button-map
5764 (let ((map (make-sparse-keymap)))
5765 ;; Not for Emacs 21: fixme better.
5766 ;;(set-keymap-parent map gnus-article-mode-map)
5767 (define-key map gnus-mouse-2 'gnus-article-push-button)
5768 (define-key map "\r" 'gnus-article-press-button)
5771 (defvar gnus-mime-security-details-buffer nil)
5773 (defvar gnus-mime-security-button-pressed nil)
5775 (defvar gnus-mime-security-show-details-inline t
5776 "If non-nil, show details in the article buffer.")
5778 (defun gnus-mime-security-verify-or-decrypt (handle)
5779 (mm-remove-parts (cdr handle))
5780 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5783 (delete-region (car region) (cdr region))
5784 (set-marker (car region) nil)
5785 (set-marker (cdr region) nil)))
5786 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5787 (let* ((mm-verify-option 'known)
5788 (mm-decrypt-option 'known)
5789 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5790 (unless (eq nparts (cdr handle))
5791 (mm-destroy-parts (cdr handle))
5792 (setcdr handle nparts))))
5793 (let ((point (point))
5795 (gnus-mime-display-security handle)
5798 (defun gnus-mime-security-show-details (handle)
5799 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5801 (if gnus-mime-security-show-details-inline
5802 (let ((gnus-mime-security-button-pressed t)
5803 (gnus-mime-security-button-line-format
5804 (get-text-property (point) 'gnus-line-format))
5807 (while (eq (get-text-property (point) 'gnus-line-format)
5808 gnus-mime-security-button-line-format)
5811 (delete-region (point)
5812 (or (text-property-not-all
5815 gnus-mime-security-button-line-format)
5817 (gnus-insert-mime-security-button handle))
5818 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5819 (with-current-buffer gnus-mime-security-details-buffer
5822 (setq gnus-mime-security-details-buffer
5823 (gnus-get-buffer-create "*MIME Security Details*")))
5824 (with-current-buffer gnus-mime-security-details-buffer
5826 (goto-char (point-min)))
5827 (pop-to-buffer gnus-mime-security-details-buffer))
5828 (gnus-message 5 "No details."))))
5830 (defun gnus-mime-security-press-button (handle)
5831 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5832 (gnus-mime-security-show-details handle)
5833 (gnus-mime-security-verify-or-decrypt handle)))
5835 (defun gnus-insert-mime-security-button (handle &optional displayed)
5836 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5839 (or (nth 2 (assoc protocol mm-verify-function-alist))
5840 (nth 2 (assoc protocol mm-decrypt-function-alist))
5842 (if (equal (car handle) "multipart/signed")
5843 " Signed" " Encrypted")
5846 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5849 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5850 gnus-tmp-pressed-details
5852 (setq gnus-tmp-details
5853 (if gnus-tmp-details
5854 (concat "\n" gnus-tmp-details) ""))
5855 (setq gnus-tmp-pressed-details
5856 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5861 gnus-mime-security-button-line-format
5862 gnus-mime-security-button-line-format-alist
5863 `(keymap ,gnus-mime-security-button-map
5864 ,@(if (>= (string-to-number emacs-version) 21)
5865 nil ;; XEmacs doesn't care
5866 (list 'local-map gnus-mime-security-button-map))
5867 gnus-callback gnus-mime-security-press-button
5868 gnus-line-format ,gnus-mime-security-button-line-format
5869 article-type annotation
5872 (widget-convert-button
5875 :action 'gnus-widget-press-button
5876 :button-keymap gnus-mime-security-button-map
5878 (lambda (widget/window &optional overlay pos)
5879 ;; Needed to properly clear the message due to a bug in
5880 ;; wid-edit (XEmacs only).
5881 (if (boundp 'help-echo-owns-message)
5882 (setq help-echo-owns-message t))
5885 (aref gnus-mouse-2 0))))))
5887 (defun gnus-mime-display-security (handle)
5889 (narrow-to-region (point) (point))
5890 (gnus-insert-mime-security-button handle)
5891 (gnus-mime-display-mixed (cdr handle))
5894 (let ((gnus-mime-security-button-line-format
5895 gnus-mime-security-button-end-line-format))
5896 (gnus-insert-mime-security-button handle))
5897 (mm-set-handle-multipart-parameter handle 'gnus-region
5898 (cons (set-marker (make-marker)
5900 (set-marker (make-marker)
5907 (defun gnus-article-header-presentation-method (entity situation)
5908 (mime-insert-header entity)
5911 (set-alist 'mime-header-presentation-method-alist
5912 'gnus-original-article-mode
5913 #'gnus-article-header-presentation-method)
5915 (defun gnus-mime-preview-quitting-method ()
5916 (mime-preview-kill-buffer)
5917 (delete-other-windows)
5918 (gnus-article-show-summary)
5919 (gnus-summary-select-article gnus-show-all-headers t))
5921 (set-alist 'mime-preview-quitting-method-alist
5922 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5924 (set-alist 'mime-preview-following-method-alist
5925 'gnus-original-article-mode #'gnus-following-method)
5927 (set-alist 'mime-preview-over-to-previous-method-alist
5928 'gnus-original-article-mode
5930 (if (> (point-min) 1)
5931 (gnus-article-prev-page)
5932 (gnus-article-read-summary-keys
5933 nil (gnus-character-to-event ?P)))))
5935 (set-alist 'mime-preview-over-to-next-method-alist
5936 'gnus-original-article-mode'
5938 (if (< (point-max) (buffer-size))
5939 (gnus-article-next-page)
5940 (gnus-article-read-summary-keys
5941 nil (gnus-character-to-event ?N)))))
5951 (run-hooks 'gnus-art-load-hook)
5953 ;;; gnus-art.el ends here