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
796 (and (or window-system
798 (>= (string-to-number emacs-version) 21))
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See the manual for details."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-custom)
805 (put 'gnus-treat-emphasize 'highlight t)
807 (defcustom gnus-treat-strip-cr nil
808 "Remove carriage returns.
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-custom)
814 (defcustom gnus-treat-hide-headers 'head
816 Valid values are nil, t, `head', `last', an integer or a predicate.
817 See the manual for details."
818 :group 'gnus-article-treat
819 :type gnus-article-treat-head-custom)
821 (defcustom gnus-treat-hide-boring-headers nil
822 "Hide boring headers.
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-head-custom)
828 (defcustom gnus-treat-hide-signature nil
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-custom)
835 (defcustom gnus-treat-fill-article nil
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-custom)
842 (defcustom gnus-treat-hide-citation nil
844 Valid values are nil, t, `head', `last', an integer or a predicate.
845 See the manual for details."
846 :group 'gnus-article-treat
847 :type gnus-article-treat-custom)
849 (defcustom gnus-treat-hide-citation-maybe nil
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-custom)
856 (defcustom gnus-treat-hide-citation-maybe nil
858 Valid values are nil, t, `head', `last', an integer or a predicate.
859 See the manual for details."
860 :group 'gnus-article-treat
861 :type gnus-article-treat-custom)
863 (defcustom gnus-treat-strip-list-identifiers 'head
864 "Strip list identifiers from `gnus-list-identifiers`.
865 Valid values are nil, t, `head', `last', an integer or a predicate.
866 See the manual for details."
868 :group 'gnus-article-treat
869 :type gnus-article-treat-custom)
871 (defcustom gnus-treat-strip-pgp t
872 "Strip PGP signatures.
873 Valid values are nil, t, `head', `last', an integer or a predicate.
874 See the manual for details."
875 :group 'gnus-article-treat
876 :type gnus-article-treat-custom)
878 (defcustom gnus-treat-strip-pem nil
879 "Strip PEM signatures.
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882 :group 'gnus-article-treat
883 :type gnus-article-treat-custom)
885 (defcustom gnus-treat-strip-banner t
886 "Strip banners from articles.
887 The banner to be stripped is specified in the `banner' group parameter.
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-custom)
893 (defcustom gnus-treat-highlight-headers 'head
894 "Highlight the headers.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-head-custom)
899 (put 'gnus-treat-highlight-headers 'highlight t)
901 (defcustom gnus-treat-highlight-citation t
902 "Highlight cited text.
903 Valid values are nil, t, `head', `last', an integer or a predicate.
904 See the manual for details."
905 :group 'gnus-article-treat
906 :type gnus-article-treat-custom)
907 (put 'gnus-treat-highlight-citation 'highlight t)
909 (defcustom gnus-treat-date-ut nil
910 "Display the Date in UT (GMT).
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See the manual for details."
913 :group 'gnus-article-treat
914 :type gnus-article-treat-head-custom)
916 (defcustom gnus-treat-date-local nil
917 "Display the Date in the local timezone.
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-head-custom)
923 (defcustom gnus-treat-date-lapsed nil
924 "Display the Date header in a way that says how much time has elapsed.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-head-custom)
930 (defcustom gnus-treat-date-original nil
931 "Display the date in the original timezone.
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934 :group 'gnus-article-treat
935 :type gnus-article-treat-head-custom)
937 (defcustom gnus-treat-date-iso8601 nil
938 "Display the date in the ISO8601 format.
939 Valid values are nil, t, `head', `last', an integer or a predicate.
940 See the manual for details."
942 :group 'gnus-article-treat
943 :type gnus-article-treat-head-custom)
945 (defcustom gnus-treat-date-user-defined nil
946 "Display the date in a user-defined format.
947 The format is defined by the `gnus-article-time-format' variable.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-head-custom)
953 (defcustom gnus-treat-strip-headers-in-body t
954 "Strip the X-No-Archive header line from the beginning of the body.
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See the manual for details."
958 :group 'gnus-article-treat
959 :type gnus-article-treat-custom)
961 (defcustom gnus-treat-strip-trailing-blank-lines nil
962 "Strip trailing blank lines.
963 Valid values are nil, t, `head', `last', an integer or a predicate.
964 See the manual for details."
965 :group 'gnus-article-treat
966 :type gnus-article-treat-custom)
968 (defcustom gnus-treat-strip-leading-blank-lines nil
969 "Strip leading blank lines.
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See the manual for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-custom)
975 (defcustom gnus-treat-strip-multiple-blank-lines nil
976 "Strip multiple blank lines.
977 Valid values are nil, t, `head', `last', an integer or a predicate.
978 See the manual for details."
979 :group 'gnus-article-treat
980 :type gnus-article-treat-custom)
982 (defcustom gnus-treat-overstrike t
983 "Treat overstrike highlighting.
984 Valid values are nil, t, `head', `last', an integer or a predicate.
985 See the manual for details."
986 :group 'gnus-article-treat
987 :type gnus-article-treat-custom)
988 (put 'gnus-treat-overstrike 'highlight t)
990 (defcustom gnus-treat-display-xface
991 (and (or (and (fboundp 'image-type-available-p)
992 (image-type-available-p 'xbm)
993 (string-match "^0x" (shell-command-to-string "uncompface")))
994 (and (featurep 'xemacs) (featurep 'xface))
995 (eq 'x-face-mule-gnus-article-display-x-face
996 gnus-article-x-face-command))
998 "Display X-Face headers.
999 Valid values are nil, t, `head', `last', an integer or a predicate.
1000 See the manual for details."
1001 :group 'gnus-article-treat
1002 :type gnus-article-treat-head-custom)
1003 (put 'gnus-treat-display-xface 'highlight t)
1005 (defcustom gnus-treat-display-smileys
1006 (if (or (and (featurep 'xemacs)
1008 (and (fboundp 'image-type-available-p)
1009 (image-type-available-p 'pbm))
1010 (and (not (featurep 'xemacs))
1012 (module-installed-p 'gnus-bitmap)))
1016 Valid values are nil, t, `head', `last', an integer or a predicate.
1017 See the manual for details."
1018 :group 'gnus-article-treat
1019 :type gnus-article-treat-custom)
1020 (put 'gnus-treat-display-smileys 'highlight t)
1022 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1024 Valid values are nil, t, `head', `last', an integer or a predicate.
1025 See the manual for details."
1026 :group 'gnus-article-treat
1027 :type gnus-article-treat-head-custom)
1028 (put 'gnus-treat-display-picons 'highlight t)
1030 (defcustom gnus-treat-capitalize-sentences nil
1031 "Capitalize sentence-starting words.
1032 Valid values are nil, t, `head', `last', an integer or a predicate.
1033 See the manual for details."
1035 :group 'gnus-article-treat
1036 :type gnus-article-treat-custom)
1038 (defcustom gnus-treat-fill-long-lines nil
1040 Valid values are nil, t, `head', `last', an integer or a predicate.
1041 See the manual for details."
1042 :group 'gnus-article-treat
1043 :type gnus-article-treat-custom)
1045 (defcustom gnus-treat-play-sounds nil
1047 Valid values are nil, t, `head', `last', an integer or a predicate.
1048 See the manual for details."
1050 :group 'gnus-article-treat
1051 :type gnus-article-treat-custom)
1053 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1054 "Decode an article as `default-mime-charset'. For instance, if you want to
1055 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1056 you could set this variable to something like: nil for don't decode, t for
1057 decode the body, '(or header t) for the whole article, etc."
1058 :group 'gnus-article-treat
1059 :type '(radio (const :tag "Off" nil)
1060 (const :tag "Decode body" t)
1061 (const :tag "Decode all" (or head t))))
1063 (defcustom gnus-treat-translate nil
1064 "Translate articles from one language to another.
1065 Valid values are nil, t, `head', `last', an integer or a predicate.
1066 See the manual for details."
1068 :group 'gnus-article-treat
1069 :type gnus-article-treat-custom)
1071 (defcustom gnus-treat-x-pgp-sig nil
1073 To automatically treat X-PGP-Sig, set it to head.
1074 Valid values are nil, t, `head', `last', an integer or a predicate.
1075 See the manual for details."
1076 :group 'gnus-article-treat
1077 :group 'mime-security
1078 :type gnus-article-treat-custom)
1080 (defvar gnus-article-encrypt-protocol-alist
1081 '(("PGP" . mml2015-self-encrypt)))
1083 ;; Set to nil if more than one protocol added to
1084 ;; gnus-article-encrypt-protocol-alist.
1085 (defcustom gnus-article-encrypt-protocol "PGP"
1086 "The protocol used for encrypt articles.
1087 It is a string, such as \"PGP\". If nil, ask user."
1089 :group 'mime-security)
1091 ;;; Internal variables
1093 (defvar article-goto-body-goes-to-point-min-p nil)
1094 (defvar gnus-article-wash-types nil)
1095 (defvar gnus-article-emphasis-alist nil)
1097 (defvar gnus-article-mime-handle-alist-1 nil)
1098 (defvar gnus-treatment-function-alist
1099 '((gnus-treat-decode-article-as-default-mime-charset
1100 gnus-article-decode-article-as-default-mime-charset)
1101 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1102 (gnus-treat-strip-banner gnus-article-strip-banner)
1103 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1104 (gnus-treat-buttonize gnus-article-add-buttons)
1105 (gnus-treat-fill-article gnus-article-fill-cited-article)
1106 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1107 (gnus-treat-strip-cr gnus-article-remove-cr)
1108 (gnus-treat-display-xface gnus-article-display-x-face)
1109 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1110 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1111 (gnus-treat-hide-signature gnus-article-hide-signature)
1112 (gnus-treat-hide-citation gnus-article-hide-citation)
1113 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1114 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1115 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1116 (gnus-treat-strip-pem gnus-article-hide-pem)
1117 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1118 (gnus-treat-emphasize gnus-article-emphasize)
1119 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1120 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1121 (gnus-treat-date-ut gnus-article-date-ut)
1122 (gnus-treat-date-local gnus-article-date-local)
1123 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1124 (gnus-treat-date-original gnus-article-date-original)
1125 (gnus-treat-date-user-defined gnus-article-date-user)
1126 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1127 (gnus-treat-strip-trailing-blank-lines
1128 gnus-article-remove-trailing-blank-lines)
1129 (gnus-treat-strip-leading-blank-lines
1130 gnus-article-strip-leading-blank-lines)
1131 (gnus-treat-strip-multiple-blank-lines
1132 gnus-article-strip-multiple-blank-lines)
1133 (gnus-treat-overstrike gnus-article-treat-overstrike)
1134 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1135 (gnus-treat-display-smileys gnus-article-smiley-display)
1136 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1137 (gnus-treat-display-picons gnus-article-display-picons)
1138 (gnus-treat-play-sounds gnus-earcon-display)))
1140 (defvar gnus-article-mime-handle-alist nil)
1141 (defvar article-lapsed-timer nil)
1142 (defvar gnus-article-current-summary nil)
1144 (defvar gnus-article-mode-syntax-table
1145 (let ((table (copy-syntax-table text-mode-syntax-table)))
1146 ;; This causes the citation match run O(2^n).
1147 ;; (modify-syntax-entry ?- "w" table)
1148 (modify-syntax-entry ?> ")" table)
1149 (modify-syntax-entry ?< "(" table)
1151 "Syntax table used in article mode buffers.
1152 Initialized from `text-mode-syntax-table.")
1154 (defvar gnus-save-article-buffer nil)
1156 (defvar gnus-article-mode-line-format-alist
1157 (nconc '((?w (gnus-article-wash-status) ?s)
1158 (?m (gnus-article-mime-part-status) ?s))
1159 gnus-summary-mode-line-format-alist))
1161 (defvar gnus-number-of-articles-to-be-saved nil)
1163 (defvar gnus-inhibit-hiding nil)
1165 (defsubst gnus-article-hide-text (b e props)
1166 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1167 (gnus-add-text-properties-when 'article-type nil b e props)
1168 (when (memq 'intangible props)
1170 (max (1- b) (point-min))
1171 b 'intangible (cddr (memq 'intangible props)))))
1173 (defsubst gnus-article-unhide-text (b e)
1174 "Remove hidden text properties from region between B and E."
1175 (remove-text-properties b e gnus-hidden-properties)
1176 (when (memq 'intangible gnus-hidden-properties)
1177 (put-text-property (max (1- b) (point-min))
1178 b 'intangible nil)))
1180 (defun gnus-article-hide-text-type (b e type)
1181 "Hide text of TYPE between B and E."
1182 (push type gnus-article-wash-types)
1183 (gnus-article-hide-text
1184 b e (cons 'article-type (cons type gnus-hidden-properties))))
1186 (defun gnus-article-unhide-text-type (b e type)
1187 "Unhide text of TYPE between B and E."
1188 (setq gnus-article-wash-types
1189 (delq type gnus-article-wash-types))
1190 (remove-text-properties
1191 b e (cons 'article-type (cons type gnus-hidden-properties)))
1192 (when (memq 'intangible gnus-hidden-properties)
1193 (put-text-property (max (1- b) (point-min))
1194 b 'intangible nil)))
1196 (defun gnus-article-hide-text-of-type (type)
1197 "Hide text of TYPE in the current buffer."
1199 (let ((b (point-min))
1201 (while (setq b (text-property-any b e 'article-type type))
1202 (add-text-properties b (incf b) gnus-hidden-properties)))))
1204 (defun gnus-article-delete-text-of-type (type)
1205 "Delete text of TYPE in the current buffer."
1207 (let ((b (point-min)))
1208 (while (setq b (text-property-any b (point-max) 'article-type type))
1210 b (or (text-property-not-all b (point-max) 'article-type type)
1213 (defun gnus-article-delete-invisible-text ()
1214 "Delete all invisible text in the current buffer."
1216 (let ((b (point-min)))
1217 (while (setq b (text-property-any b (point-max) 'invisible t))
1219 b (or (text-property-not-all b (point-max) 'invisible t)
1222 (defun gnus-article-text-type-exists-p (type)
1223 "Say whether any text of type TYPE exists in the buffer."
1224 (text-property-any (point-min) (point-max) 'article-type type))
1226 (defsubst gnus-article-header-rank ()
1227 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1228 (let ((list gnus-sorted-header-list)
1231 (when (looking-at (car list))
1233 (setq list (cdr list))
1237 (defun article-hide-headers (&optional arg delete)
1238 "Hide unwanted headers and possibly sort them as well."
1239 (interactive (gnus-article-hidden-arg))
1240 ;; Lars said that this function might be inhibited.
1241 (if (gnus-article-check-hidden-text 'headers arg)
1243 ;; Show boring headers as well.
1244 (gnus-article-show-hidden-text 'boring-headers)
1245 (when (eq 1 (point-min))
1246 (set-window-start (get-buffer-window (current-buffer)) 1)))
1247 (unless gnus-inhibit-hiding
1250 (let ((buffer-read-only nil)
1251 (inhibit-read-only t)
1252 (case-fold-search t)
1253 (max (1+ (length gnus-sorted-header-list)))
1254 (ignored (when (not gnus-visible-headers)
1255 (cond ((stringp gnus-ignored-headers)
1256 gnus-ignored-headers)
1257 ((listp gnus-ignored-headers)
1258 (mapconcat 'identity gnus-ignored-headers
1261 (cond ((stringp gnus-visible-headers)
1262 gnus-visible-headers)
1263 ((and gnus-visible-headers
1264 (listp gnus-visible-headers))
1265 (mapconcat 'identity gnus-visible-headers "\\|"))))
1266 (inhibit-point-motion-hooks t)
1268 ;; First we narrow to just the headers.
1269 (article-narrow-to-head)
1270 ;; Hide any "From " lines at the beginning of (mail) articles.
1271 (while (looking-at "From ")
1275 (delete-region (point-min) (point))
1276 (gnus-article-hide-text (point-min) (point)
1277 (nconc (list 'article-type 'headers)
1278 gnus-hidden-properties))))
1279 ;; Then treat the rest of the header lines.
1280 ;; Then we use the two regular expressions
1281 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1282 ;; select which header lines is to remain visible in the
1284 (while (re-search-forward "^[^ \t]*:" nil t)
1286 ;; Mark the rank of the header.
1288 (point) (1+ (point)) 'message-rank
1289 (if (or (and visible (looking-at visible))
1291 (not (looking-at ignored))))
1292 (gnus-article-header-rank)
1295 (message-sort-headers-1)
1296 (when (setq beg (text-property-any
1297 (point-min) (point-max) 'message-rank (+ 2 max)))
1298 ;; We delete or make invisible the unwanted headers.
1299 (push 'headers gnus-article-wash-types)
1302 (add-text-properties
1303 (point-min) (+ 5 (point-min))
1304 '(article-type headers dummy-invisible t))
1305 (delete-region beg (point-max)))
1306 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1309 (defun article-hide-boring-headers (&optional arg)
1310 "Toggle hiding of headers that aren't very interesting.
1311 If given a negative prefix, always show; if given a positive prefix,
1313 (interactive (gnus-article-hidden-arg))
1314 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1315 (not gnus-show-all-headers))
1318 (let ((buffer-read-only nil)
1319 (list gnus-boring-article-headers)
1320 (inhibit-point-motion-hooks t)
1322 (article-narrow-to-head)
1324 (setq elem (pop list))
1325 (goto-char (point-min))
1327 ;; Hide empty headers.
1329 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1331 (gnus-article-hide-text-type
1332 (progn (beginning-of-line) (point))
1335 (if (re-search-forward "^[^ \t]" nil t)
1339 ;; Hide boring Newsgroups header.
1340 ((eq elem 'newsgroups)
1341 (when (equal (gnus-fetch-field "newsgroups")
1342 (gnus-group-real-name
1343 (if (boundp 'gnus-newsgroup-name)
1346 (gnus-article-hide-header "newsgroups")))
1347 ((eq elem 'followup-to)
1348 (when (equal (message-fetch-field "followup-to")
1349 (message-fetch-field "newsgroups"))
1350 (gnus-article-hide-header "followup-to")))
1351 ((eq elem 'reply-to)
1352 (let ((from (message-fetch-field "from"))
1353 (reply-to (message-fetch-field "reply-to")))
1358 (nth 1 (funcall gnus-extract-address-components from))
1359 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1360 (gnus-article-hide-header "reply-to"))))
1362 (let ((date (message-fetch-field "date")))
1364 (< (days-between (current-time-string) date)
1366 (gnus-article-hide-header "date"))))
1368 (let ((to (message-fetch-field "to"))
1369 (cc (message-fetch-field "cc")))
1370 (when (> (length to) 1024)
1371 (gnus-article-hide-header "to"))
1372 (when (> (length cc) 1024)
1373 (gnus-article-hide-header "cc"))))
1377 (goto-char (point-min))
1378 (while (re-search-forward "^to:" nil t)
1379 (setq to-count (1+ to-count)))
1380 (when (> to-count 1)
1381 (while (> to-count 0)
1382 (goto-char (point-min))
1384 (re-search-forward "^to:" nil nil to-count)
1386 (narrow-to-region (point) (point-max))
1387 (gnus-article-hide-header "to"))
1388 (setq to-count (1- to-count))))
1389 (goto-char (point-min))
1390 (while (re-search-forward "^cc:" nil t)
1391 (setq cc-count (1+ cc-count)))
1392 (when (> cc-count 1)
1393 (while (> cc-count 0)
1394 (goto-char (point-min))
1396 (re-search-forward "^cc:" nil nil cc-count)
1398 (narrow-to-region (point) (point-max))
1399 (gnus-article-hide-header "cc"))
1400 (setq cc-count (1- cc-count)))))))))))))
1402 (defun gnus-article-hide-header (header)
1404 (goto-char (point-min))
1405 (when (re-search-forward (concat "^" header ":") nil t)
1406 (gnus-article-hide-text-type
1407 (progn (beginning-of-line) (point))
1410 (if (re-search-forward "^[^ \t]" nil t)
1415 (defun article-toggle-headers (&optional arg)
1416 "Toggle hiding of headers. If given a negative prefix, always show;
1417 if given a positive prefix, always hide."
1418 (interactive (gnus-article-hidden-arg))
1419 (let ((force (when (numberp arg)
1420 (cond ((> arg 0) 'always-hide)
1421 ((< arg 0) 'always-show))))
1422 (window (get-buffer-window gnus-article-buffer))
1423 (header-end (point-min))
1424 header-start field-end field-start
1425 (inhibit-point-motion-hooks t)
1426 (inhibit-read-only t)
1430 (while (and (setq header-start
1431 (text-property-any header-end (point-max)
1432 'article-treated-header t))
1434 (text-property-not-all header-start (point-max)
1435 'article-treated-header t)))
1436 (setq field-end header-start)
1438 (;; Hide exposed invisible fields.
1439 (and (not (eq 'always-show force))
1441 (text-property-any field-end header-end
1442 'exposed-invisible-field t)))
1443 (while (and field-start
1444 (setq field-end (text-property-not-all
1445 field-start header-end
1446 'exposed-invisible-field t)))
1447 (add-text-properties field-start field-end gnus-hidden-properties)
1448 (setq field-start (text-property-any field-end header-end
1449 'exposed-invisible-field t)))
1450 (put-text-property header-start header-end
1451 'exposed-invisible-field nil))
1452 (;; Expose invisible fields.
1453 (and (not (eq 'always-hide force))
1455 (text-property-any field-end header-end 'invisible t)))
1456 (while (and field-start
1457 (setq field-end (text-property-not-all
1458 field-start header-end
1460 ;; If the invisible text is not terminated with newline, we
1461 ;; won't expose it. Because it may be created by x-face-mule.
1462 ;; BTW, XEmacs sometimes fail in putting a invisible text
1463 ;; property with `gnus-article-hide-text' (really?). In that
1464 ;; case, the invisible text might be started from the middle of
1465 ;; a line so we will expose the sort of thing.
1466 (when (or (not (or (eq header-start field-start)
1467 (eq ?\n (char-before field-start))))
1468 (eq ?\n (char-before field-end)))
1469 (remove-text-properties field-start field-end
1470 gnus-hidden-properties)
1471 (put-text-property field-start field-end
1472 'exposed-invisible-field t))
1473 (setq field-start (text-property-any field-end header-end
1476 (not (eq 'always-show force))
1477 (narrow-to-region header-start header-end)
1478 (article-hide-headers)
1479 ;; Re-display X-Face image under XEmacs.
1480 (when (and (featurep 'xemacs)
1481 (gnus-functionp gnus-article-x-face-command))
1482 (let ((func (cadr (assq 'gnus-treat-display-xface
1483 gnus-treatment-function-alist)))
1485 (when (and (not gnus-inhibit-treatment)
1487 (gnus-treat-predicate gnus-treat-display-xface))
1489 (put-text-property header-start header-end 'read-only nil))))
1492 (goto-char (point-min))
1494 (set-window-start window (point-min))))))
1496 (defvar gnus-article-normalized-header-length 40
1497 "Length of normalized headers.")
1499 (defun article-normalize-headers ()
1500 "Make all header lines 40 characters long."
1502 (let ((buffer-read-only nil)
1506 (article-narrow-to-head)
1509 ((< (setq column (- (gnus-point-at-eol) (point)))
1510 gnus-article-normalized-header-length)
1512 (insert (make-string
1513 (- gnus-article-normalized-header-length column)
1515 ((> column gnus-article-normalized-header-length)
1516 (gnus-put-text-property
1518 (forward-char gnus-article-normalized-header-length)
1525 (forward-line 1))))))
1527 (defun article-treat-dumbquotes ()
1528 "Translate M****s*** sm*rtq**t*s into proper text.
1529 Note that this function guesses whether a character is a sm*rtq**t* or
1530 not, so it should only be used interactively.
1532 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1533 in an attempt to provide more quoting characters. If you see
1534 something like \\222 or \\264 where you're expecting some kind of
1535 apostrophe or quotation mark, then try this wash."
1537 (article-translate-strings gnus-article-dumbquotes-map))
1539 (defun article-translate-characters (from to)
1540 "Translate all characters in the body of the article according to FROM and TO.
1541 FROM is a string of characters to translate from; to is a string of
1542 characters to translate to."
1544 (when (article-goto-body)
1545 (let ((buffer-read-only nil)
1546 (x (make-string 225 ?x))
1548 (while (< (incf i) (length x))
1551 (while (< i (length from))
1552 (aset x (aref from i) (aref to i))
1554 (translate-region (point) (point-max) x)))))
1556 (defun article-translate-strings (map)
1557 "Translate all string in the body of the article according to MAP.
1558 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1560 (when (article-goto-body)
1561 (let ((buffer-read-only nil)
1563 (while (setq elem (pop map))
1565 (while (search-forward (car elem) nil t)
1566 (replace-match (cadr elem)))))))))
1568 (defun article-treat-overstrike ()
1569 "Translate overstrikes into bold text."
1572 (when (article-goto-body)
1573 (let ((buffer-read-only nil))
1574 (while (search-forward "\b" nil t)
1575 (let ((next (char-after))
1579 previous (char-after))
1583 ;; We do the boldification/underlining by hiding the
1584 ;; overstrikes and putting the proper text property
1588 (gnus-article-hide-text-type start (point) 'overstrike)
1589 (put-text-property (point) end 'face 'bold))
1591 (gnus-article-hide-text-type
1592 (1- (point)) (1+ (point)) 'overstrike)
1594 start (1- (point)) 'face 'underline))
1596 (gnus-article-hide-text-type start (point) 'overstrike)
1598 (point) end 'face 'underline)))))))))
1600 (defun article-fill-long-lines ()
1601 "Fill lines that are wider than the window width."
1604 (let ((buffer-read-only nil)
1605 (width (window-width (get-buffer-window (current-buffer)))))
1608 (let ((adaptive-fill-mode nil))
1611 (when (>= (current-column) (min fill-column width))
1612 (narrow-to-region (point) (gnus-point-at-bol))
1613 (fill-paragraph nil)
1614 (goto-char (point-max))
1616 (forward-line 1)))))))
1618 (defun article-capitalize-sentences ()
1619 "Capitalize the first word in each sentence."
1622 (let ((buffer-read-only nil)
1623 (paragraph-start "^[\n\^L]"))
1627 (forward-sentence)))))
1629 (defun article-remove-cr ()
1630 "Remove trailing CRs and then translate remaining CRs into LFs."
1633 (let ((buffer-read-only nil))
1634 (goto-char (point-min))
1635 (while (re-search-forward "\r+$" nil t)
1636 (replace-match "" t t))
1637 (goto-char (point-min))
1638 (while (search-forward "\r" nil t)
1639 (replace-match "\n" t t)))))
1641 (defun article-remove-trailing-blank-lines ()
1642 "Remove all trailing blank lines from the article."
1645 (let ((buffer-read-only nil))
1646 (goto-char (point-max))
1650 (while (and (not (bobp))
1651 (looking-at "^[ \t]*$")
1652 (not (gnus-annotation-in-region-p
1653 (point) (gnus-point-at-eol))))
1658 (defun article-display-x-face (&optional force)
1659 "Look for an X-Face header and display it if present."
1660 (interactive (list 'force))
1662 ;; Delete the old process, if any.
1663 (when (process-status "article-x-face")
1664 (delete-process "article-x-face"))
1665 (let ((inhibit-point-motion-hooks t)
1666 (case-fold-search t)
1669 (article-narrow-to-head)
1670 (goto-char (point-min))
1671 (setq from (message-fetch-field "from"))
1672 (goto-char (point-min))
1673 (while (and gnus-article-x-face-command
1676 ;; Check whether this face is censored.
1677 (not gnus-article-x-face-too-ugly)
1678 (and gnus-article-x-face-too-ugly from
1679 (not (string-match gnus-article-x-face-too-ugly
1681 ;; Has to be present.
1682 (re-search-forward "^X-Face:[ \t]*" nil t))
1683 ;; This used to try to do multiple faces (`while' instead of
1684 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1685 ;; work (b) it can crash some versions of Emacs (c) are
1686 ;; multiple faces really something to encourage?
1687 (when (stringp gnus-article-x-face-command)
1689 ;; We now have the area of the buffer where the X-Face is stored.
1692 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1693 ;; We display the face.
1694 (if (symbolp gnus-article-x-face-command)
1695 ;; The command is a lisp function, so we call it.
1696 (if (gnus-functionp gnus-article-x-face-command)
1697 (funcall gnus-article-x-face-command beg end)
1698 (error "%s is not a function" gnus-article-x-face-command))
1699 ;; The command is a string, so we interpret the command
1700 ;; as a, well, command, and fork it off.
1701 (let ((process-connection-type nil))
1702 (process-kill-without-query
1704 "article-x-face" nil shell-file-name shell-command-switch
1705 gnus-article-x-face-command))
1706 (process-send-region "article-x-face" beg end)
1707 (process-send-eof "article-x-face"))))))))))
1709 (defun article-decode-mime-words ()
1710 "Decode all MIME-encoded words in the article."
1713 (set-buffer gnus-article-buffer)
1714 (let ((inhibit-point-motion-hooks t)
1716 (mail-parse-charset gnus-newsgroup-charset)
1717 (mail-parse-ignored-charsets
1718 (save-excursion (set-buffer gnus-summary-buffer)
1719 gnus-newsgroup-ignored-charsets)))
1720 (mail-decode-encoded-word-region (point-min) (point-max)))))
1722 (defun article-decode-charset (&optional prompt)
1723 "Decode charset-encoded text in the article.
1724 If PROMPT (the prefix), prompt for a coding system to use."
1726 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1728 (mail-parse-charset gnus-newsgroup-charset)
1729 (mail-parse-ignored-charsets
1730 (save-excursion (condition-case nil
1731 (set-buffer gnus-summary-buffer)
1733 gnus-newsgroup-ignored-charsets))
1734 ct cte ctl charset format)
1737 (article-narrow-to-head)
1738 (setq ct (message-fetch-field "Content-Type" t)
1739 cte (message-fetch-field "Content-Transfer-Encoding" t)
1740 ctl (and ct (ignore-errors
1741 (mail-header-parse-content-type ct)))
1744 (mm-read-coding-system "Charset to decode: "))
1746 (mail-content-type-get ctl 'charset)))
1747 format (and ctl (mail-content-type-get ctl 'format)))
1749 (setq cte (mail-header-strip cte)))
1750 (if (and ctl (not (string-match "/" (car ctl))))
1752 (goto-char (point-max)))
1755 (narrow-to-region (point) (point-max))
1756 (when (and (eq mail-parse-charset 'gnus-decoded)
1757 (eq (mm-body-7-or-8) '8bit))
1758 ;; The text code could have been decoded.
1759 (setq charset mail-parse-charset))
1760 (when (and (or (not ctl)
1761 (equal (car ctl) "text/plain"))
1762 (not format)) ;; article with format will decode later.
1764 charset (and cte (intern (downcase
1765 (gnus-strip-whitespace cte))))
1768 (defun article-decode-encoded-words ()
1769 "Remove encoded-word encoding from headers."
1770 (let (buffer-read-only)
1771 (let ((charset (save-excursion
1772 (set-buffer gnus-summary-buffer)
1773 default-mime-charset)))
1774 (mime-decode-header-in-buffer charset)
1777 (defun article-de-quoted-unreadable (&optional force)
1778 "Translate a quoted-printable-encoded article.
1779 If FORCE, decode the article whether it is marked as quoted-printable
1781 (interactive (list 'force))
1783 (let ((buffer-read-only nil) type charset)
1784 (if (gnus-buffer-live-p gnus-original-article-buffer)
1785 (with-current-buffer gnus-original-article-buffer
1787 (gnus-fetch-field "content-transfer-encoding"))
1788 (let* ((ct (gnus-fetch-field "content-type"))
1791 (mail-header-parse-content-type ct)))))
1792 (setq charset (and ctl
1793 (mail-content-type-get ctl 'charset)))
1794 (if (stringp charset)
1795 (setq charset (intern (downcase charset)))))))
1797 (setq charset gnus-newsgroup-charset))
1799 (and type (let ((case-fold-search t))
1800 (string-match "quoted-printable" type))))
1802 (quoted-printable-decode-region
1803 (point) (point-max) (mm-charset-to-coding-system charset))))))
1805 (defun article-de-base64-unreadable (&optional force)
1806 "Translate a base64 article.
1807 If FORCE, decode the article whether it is marked as base64 not."
1808 (interactive (list 'force))
1810 (let ((buffer-read-only nil) type charset)
1811 (if (gnus-buffer-live-p gnus-original-article-buffer)
1812 (with-current-buffer gnus-original-article-buffer
1814 (gnus-fetch-field "content-transfer-encoding"))
1815 (let* ((ct (gnus-fetch-field "content-type"))
1818 (mail-header-parse-content-type ct)))))
1819 (setq charset (and ctl
1820 (mail-content-type-get ctl 'charset)))
1821 (if (stringp charset)
1822 (setq charset (intern (downcase charset)))))))
1824 (setq charset gnus-newsgroup-charset))
1826 (and type (let ((case-fold-search t))
1827 (string-match "base64" type))))
1830 (narrow-to-region (point) (point-max))
1831 (base64-decode-region (point-min) (point-max))
1832 (mm-decode-coding-region
1833 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1838 (defun article-decode-HZ ()
1839 "Translate a HZ-encoded article."
1843 (let ((buffer-read-only nil))
1844 (rfc1843-decode-region (point-min) (point-max)))))
1846 (defun article-wash-html ()
1847 "Format an html article."
1850 (let ((buffer-read-only nil)
1852 (if (gnus-buffer-live-p gnus-original-article-buffer)
1853 (with-current-buffer gnus-original-article-buffer
1854 (let* ((ct (gnus-fetch-field "content-type"))
1857 (mail-header-parse-content-type ct)))))
1858 (setq charset (and ctl
1859 (mail-content-type-get ctl 'charset)))
1860 (if (stringp charset)
1861 (setq charset (intern (downcase charset)))))))
1863 (setq charset gnus-newsgroup-charset))
1865 (save-window-excursion
1867 (narrow-to-region (point) (point-max))
1869 (let ((w3-strict-width (window-width))
1870 (url-standalone-mode t))
1872 (w3-region (point-min) (point-max))
1875 (defun article-hide-list-identifiers ()
1876 "Remove list identifies from the Subject header.
1877 The `gnus-list-identifiers' variable specifies what to do."
1881 (let ((inhibit-point-motion-hooks t)
1883 (article-narrow-to-head)
1884 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1885 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1887 (goto-char (point-min))
1888 (when (re-search-forward
1889 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1890 " *\\)\\)+\\(Re: +\\)?\\)")
1892 (let ((s (or (match-string 3) (match-string 5))))
1893 (delete-region (match-beginning 1) (match-end 1))
1895 (goto-char (match-beginning 1))
1898 (defun article-hide-pgp ()
1899 "Remove any PGP headers and signatures in the current article."
1903 (let ((inhibit-point-motion-hooks t)
1904 buffer-read-only beg end)
1906 ;; Hide the "header".
1907 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1908 (push 'pgp gnus-article-wash-types)
1909 (delete-region (match-beginning 0) (match-end 0))
1910 ;; Remove armor headers (rfc2440 6.2)
1911 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1914 ;; Hide the actual signature.
1915 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1916 (setq end (1+ (match-beginning 0)))
1919 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1921 ;; Perhaps we shouldn't hide to the end of the buffer
1922 ;; if there is no end to the signature?
1924 ;; Hide "- " PGP quotation markers.
1926 (narrow-to-region beg end)
1927 (goto-char (point-min))
1928 (while (re-search-forward "^- " nil t)
1930 (match-beginning 0) (match-end 0)))
1932 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1934 (defun article-hide-pem (&optional arg)
1935 "Toggle hiding of any PEM headers and signatures in the current article.
1936 If given a negative prefix, always show; if given a positive prefix,
1938 (interactive (gnus-article-hidden-arg))
1939 (unless (gnus-article-check-hidden-text 'pem arg)
1941 (let (buffer-read-only end)
1942 (goto-char (point-min))
1943 ;; Hide the horrendously ugly "header".
1944 (when (and (search-forward
1945 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1947 (setq end (1+ (match-beginning 0))))
1948 (push 'pem gnus-article-wash-types)
1949 (gnus-article-hide-text-type
1951 (if (search-forward "\n\n" nil t)
1955 ;; Hide the trailer as well
1956 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1958 (gnus-article-hide-text-type
1959 (match-beginning 0) (match-end 0) 'pem)))))))
1961 (defun article-strip-banner ()
1962 "Strip the banner specified by the `banner' group parameter."
1966 (let ((inhibit-point-motion-hooks t)
1967 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1968 (gnus-signature-limit nil)
1969 buffer-read-only beg end)
1973 ((eq banner 'signature)
1974 (when (gnus-article-narrow-to-signature)
1977 (delete-region (point) (point-max))))
1979 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1980 (while (re-search-forward banner nil t)
1981 (delete-region (match-beginning 0) (match-end 0)))))
1983 (while (re-search-forward banner nil t)
1984 (delete-region (match-beginning 0) (match-end 0))))))))))
1986 (defun article-babel ()
1987 "Translate article using an online translation service."
1991 (set-buffer gnus-article-buffer)
1992 (when (article-goto-body)
1993 (let* ((buffer-read-only nil)
1996 (orig (buffer-substring start end))
1997 (trans (babel-as-string orig)))
1999 (narrow-to-region start end)
2000 (delete-region start end)
2003 (defun article-hide-signature (&optional arg)
2004 "Hide the signature in the current article.
2005 If given a negative prefix, always show; if given a positive prefix,
2007 (interactive (gnus-article-hidden-arg))
2013 (article-goto-body))
2014 (goto-char (point-min)))
2015 (unless (gnus-article-check-hidden-text 'signature arg)
2016 (let ((buffer-read-only nil)
2018 (while (setq button (text-property-any button (point-max)
2020 'gnus-signature-toggle))
2021 (setq button (text-property-not-all button (point-max)
2023 'gnus-signature-toggle))
2024 (when (and button (not (eobp)))
2025 (gnus-article-hide-text-type
2027 (next-single-property-change (1+ button) 'mime-view-entity
2031 (defun article-strip-headers-in-body ()
2032 "Strip offensive headers from bodies."
2036 (let ((case-fold-search t))
2037 (when (looking-at "x-no-archive:")
2038 (gnus-delete-line)))))
2040 (defun article-strip-leading-blank-lines ()
2041 "Remove all blank lines from the beginning of the article."
2044 (let ((inhibit-point-motion-hooks t)
2046 (when (article-goto-body)
2047 (while (and (not (eobp))
2048 (looking-at "[ \t]*$"))
2049 (gnus-delete-line))))))
2051 (defun article-narrow-to-head ()
2052 "Narrow the buffer to the head of the message.
2053 Point is left at the beginning of the narrowed-to region."
2055 (goto-char (point-min))
2056 (if (search-forward "\n\n" nil 1)
2059 (goto-char (point-min)))
2061 (defun article-goto-body ()
2062 "Place point at the start of the body."
2063 (goto-char (point-min))
2065 ;; This variable is only bound when dealing with separate
2067 (article-goto-body-goes-to-point-min-p
2069 ((search-forward "\n\n" nil t)
2072 (goto-char (point-max))
2075 (defun article-strip-multiple-blank-lines ()
2076 "Replace consecutive blank lines with one empty line."
2079 (let ((inhibit-point-motion-hooks t)
2081 ;; First make all blank lines empty.
2083 (while (re-search-forward "^[ \t]+$" nil t)
2084 (unless (gnus-annotation-in-region-p
2085 (match-beginning 0) (match-end 0))
2086 (replace-match "" nil t)))
2087 ;; Then replace multiple empty lines with a single empty line.
2089 (while (re-search-forward "\n\n\n+" nil t)
2090 (unless (gnus-annotation-in-region-p
2091 (match-beginning 0) (match-end 0))
2092 (replace-match "\n\n" t t))))))
2094 (defun article-strip-leading-space ()
2095 "Remove all white space from the beginning of the lines in the article."
2098 (let ((inhibit-point-motion-hooks t)
2101 (while (re-search-forward "^[ \t]+" nil t)
2102 (replace-match "" t t)))))
2104 (defun article-strip-trailing-space ()
2105 "Remove all white space from the end of the lines in the article."
2108 (let ((inhibit-point-motion-hooks t)
2111 (while (re-search-forward "[ \t]+$" nil t)
2112 (replace-match "" t t)))))
2114 (defun article-strip-blank-lines ()
2115 "Strip leading, trailing and multiple blank lines."
2117 (article-strip-leading-blank-lines)
2118 (article-remove-trailing-blank-lines)
2119 (article-strip-multiple-blank-lines))
2121 (defun article-strip-all-blank-lines ()
2122 "Strip all blank lines."
2125 (let ((inhibit-point-motion-hooks t)
2128 (while (re-search-forward "^[ \t]*\n" nil t)
2129 (replace-match "" t t)))))
2131 (defun gnus-article-narrow-to-signature ()
2132 "Narrow to the signature; return t if a signature is found, else nil."
2133 (let ((inhibit-point-motion-hooks t))
2134 (when (gnus-article-search-signature)
2136 ;; Check whether we have some limits to what we consider
2137 ;; to be a signature.
2138 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2139 (list gnus-signature-limit)))
2141 (while (setq limit (pop limits))
2142 (if (or (and (integerp limit)
2143 (< (- (point-max) (point)) limit))
2145 (< (count-lines (point) (point-max)) limit))
2146 (and (gnus-functionp limit)
2148 (and (stringp limit)
2149 (not (re-search-forward limit nil t))))
2150 () ; This limit did not succeed.
2154 (narrow-to-region (point) (point-max))
2157 (defun gnus-article-search-signature ()
2158 "Search the current buffer for the signature separator.
2159 Put point at the beginning of the signature separator."
2160 (let ((cur (point)))
2161 (goto-char (point-max))
2162 (if (if (stringp gnus-signature-separator)
2163 (re-search-backward gnus-signature-separator nil t)
2164 (let ((seps gnus-signature-separator))
2166 (not (re-search-backward (car seps) nil t)))
2173 (defun gnus-article-hidden-arg ()
2174 "Return the current prefix arg as a number, or 0 if no prefix."
2175 (list (if current-prefix-arg
2176 (prefix-numeric-value current-prefix-arg)
2179 (defun gnus-article-check-hidden-text (type arg)
2180 "Return nil if hiding is necessary.
2181 Arg can be nil or a number. Nil and positive means hide, negative
2182 means show, 0 means toggle."
2185 (let ((hide (gnus-article-hidden-text-p type)))
2191 (gnus-article-show-hidden-text type))
2193 (if (eq hide 'hidden)
2194 (gnus-article-show-hidden-text type)
2197 (defun gnus-article-hidden-text-p (type)
2198 "Say whether the current buffer contains hidden text of type TYPE."
2199 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2201 (not (get-text-property pos 'invisible))
2202 (not (get-text-property pos 'dummy-invisible)))
2204 (text-property-any (1+ pos) (point-max) 'article-type type)))
2209 (defun gnus-article-show-hidden-text (type &optional dummy)
2210 "Show all hidden text of type TYPE.
2211 Originally it is hide instead of DUMMY."
2212 (let ((buffer-read-only nil)
2213 (inhibit-point-motion-hooks t))
2214 (gnus-remove-text-properties-when
2216 (point-min) (point-max)
2217 (cons 'article-type (cons type
2218 gnus-hidden-properties)))))
2220 (defconst article-time-units
2221 `((year . ,(* 365.25 24 60 60))
2222 (week . ,(* 7 24 60 60))
2223 (day . ,(* 24 60 60))
2227 "Mapping from time units to seconds.")
2229 (defun article-date-ut (&optional type highlight header)
2230 "Convert DATE date to universal time in the current article.
2231 If TYPE is `local', convert to local time; if it is `lapsed', output
2232 how much time has lapsed since DATE. For `lapsed', the value of
2233 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2234 should replace the \"Date:\" one, or should be added below it."
2235 (interactive (list 'ut t))
2236 (let* ((header (or header
2237 (and (eq 1 (point-min))
2238 (mail-header-date (save-excursion
2239 (set-buffer gnus-summary-buffer)
2240 gnus-current-headers)))
2241 (message-fetch-field "date")
2243 (date (if (vectorp header) (mail-header-date header)
2245 (inhibit-point-motion-hooks t)
2246 bface eface date-pos)
2247 (when (and date (not (string= date "")))
2250 (article-narrow-to-head)
2251 (when (or (and (eq type 'lapsed)
2252 gnus-article-date-lapsed-new-header
2253 ;; Attempt to get the face of X-Sent first.
2254 (re-search-forward "^X-Sent:[ \t]" nil t))
2255 (re-search-forward "^Date:[ \t]" nil t)
2256 ;; If Date is missing, try again for X-Sent.
2257 (re-search-forward "^X-Sent:[ \t]" nil t))
2258 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2259 date (or (get-text-property (gnus-point-at-bol)
2262 eface (get-text-property (1- (gnus-point-at-eol))
2264 (let ((buffer-read-only nil))
2265 ;; Delete any old X-Sent headers.
2266 (when (setq date-pos
2267 (text-property-any (point-min) (point-max)
2268 'article-date-lapsed t))
2269 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2270 (delete-region (match-beginning 0)
2271 (progn (forward-line 1) (point))))
2272 (goto-char (point-min))
2273 ;; Delete any old Date headers.
2274 (while (re-search-forward "^Date:[ \t]" nil t)
2276 (setq date-pos (match-beginning 0)))
2277 (unless (and (eq type 'lapsed)
2278 gnus-article-date-lapsed-new-header)
2279 (delete-region (match-beginning 0)
2280 (progn (message-next-header) (point)))))
2283 (goto-char date-pos)
2285 ;; Possibly, Date has been deleted.
2287 (when (and (eq type 'lapsed)
2288 gnus-article-date-lapsed-new-header
2289 (looking-at "Date:"))
2291 (goto-char (point-min)))
2292 (insert (article-make-date-line date type))
2293 (when (eq type 'lapsed)
2294 (put-text-property (gnus-point-at-bol) (point)
2295 'article-date-lapsed t))
2299 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2300 (put-text-property (match-beginning 1) (1+ (match-end 1))
2301 'original-date date)
2302 (put-text-property (match-beginning 1) (1+ (match-end 1))
2304 (put-text-property (match-beginning 2) (match-end 2)
2307 (defun article-make-date-line (date type)
2308 "Return a DATE line of TYPE."
2309 (let ((time (condition-case ()
2313 ;; Convert to the local timezone. We have to slap a
2314 ;; `condition-case' round the calls to the timezone
2315 ;; functions since they aren't particularly resistant to
2318 (let ((tz (car (current-time-zone time))))
2319 (format "Date: %s %s%02d%02d" (current-time-string time)
2320 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2321 (/ (% (abs tz) 3600) 60))))
2322 ;; Convert to Universal Time.
2325 (current-time-string
2326 (let* ((e (parse-time-string date))
2327 (tm (apply 'encode-time e))
2329 (ls (- (cadr tm) (car (current-time-zone time)))))
2330 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2331 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2334 ;; Get the original date from the article.
2335 ((eq type 'original)
2336 (concat "Date: " (if (string-match "\n+$" date)
2337 (substring date 0 (match-beginning 0))
2339 ;; Let the user define the format.
2341 (if (gnus-functionp gnus-article-time-format)
2342 (funcall gnus-article-time-format time)
2345 (format-time-string gnus-article-time-format time))))
2348 (let ((tz (car (current-time-zone time))))
2351 (format-time-string "%Y%m%dT%H%M%S" time)
2352 (format "%s%02d%02d"
2353 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2354 (/ (% (abs tz) 3600) 60)))))
2355 ;; Do an X-Sent lapsed format.
2357 ;; If the date is seriously mangled, the timezone functions are
2358 ;; liable to bug out, so we ignore all errors.
2359 (let* ((now (current-time))
2360 (real-time (subtract-time now time))
2361 (real-sec (and real-time
2362 (+ (* (float (car real-time)) 65536)
2364 (sec (and real-time (abs real-sec)))
2374 ;; This is a bit convoluted, but basically we go
2375 ;; through the time units for years, weeks, etc,
2376 ;; and divide things to see whether that results
2377 ;; in positive answers.
2380 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2381 ;; The (remaining) seconds are too few to
2382 ;; be divided into this time unit.
2384 ;; It's big enough, so we output it.
2385 (setq sec (- sec (* num (cdr unit))))
2387 (concat (if prev ", " "") (int-to-string
2389 " " (symbol-name (car unit))
2390 (if (> num 1) "s" ""))
2392 article-time-units "")
2393 ;; If dates are odd, then it might appear like the
2394 ;; article was sent in the future.
2397 " in the future"))))))
2399 (error "Unknown conversion type: %s" type)))))
2401 (defun article-date-local (&optional highlight)
2402 "Convert the current article date to the local timezone."
2403 (interactive (list t))
2404 (article-date-ut 'local highlight))
2406 (defun article-date-original (&optional highlight)
2407 "Convert the current article date to what it was originally.
2408 This is only useful if you have used some other date conversion
2409 function and want to see what the date was before converting."
2410 (interactive (list t))
2411 (article-date-ut 'original highlight))
2413 (defun article-date-lapsed (&optional highlight)
2414 "Convert the current article date to time lapsed since it was sent."
2415 (interactive (list t))
2416 (article-date-ut 'lapsed highlight))
2418 (defun article-update-date-lapsed ()
2419 "Function to be run from a timer to update the lapsed time line."
2420 (let (deactivate-mark)
2425 (set-buffer (window-buffer w))
2426 (when (eq major-mode 'gnus-article-mode)
2427 (goto-char (point-min))
2428 (when (re-search-forward "^X-Sent:" nil t)
2429 (article-date-lapsed t))))
2432 (defun gnus-start-date-timer (&optional n)
2433 "Start a timer to update the X-Sent header in the article buffers.
2434 The numerical prefix says how frequently (in seconds) the function
2439 (gnus-stop-date-timer)
2440 (setq article-lapsed-timer
2441 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2443 (defun gnus-stop-date-timer ()
2444 "Stop the X-Sent timer."
2446 (when article-lapsed-timer
2447 (nnheader-cancel-timer article-lapsed-timer)
2448 (setq article-lapsed-timer nil)))
2450 (defun article-date-user (&optional highlight)
2451 "Convert the current article date to the user-defined format.
2452 This format is defined by the `gnus-article-time-format' variable."
2453 (interactive (list t))
2454 (article-date-ut 'user highlight))
2456 (defun article-date-iso8601 (&optional highlight)
2457 "Convert the current article date to ISO8601."
2458 (interactive (list t))
2459 (article-date-ut 'iso8601 highlight))
2461 (defun article-show-all ()
2462 "Show all hidden text in the article buffer."
2466 (let ((buffer-read-only nil))
2467 (gnus-article-unhide-text (point-min) (point-max))
2468 (gnus-remove-text-with-property 'gnus-prev)
2469 (gnus-remove-text-with-property 'gnus-next))))
2471 (defun article-show-all-headers ()
2472 "Show all hidden headers in the article buffer."
2477 (article-narrow-to-head)
2478 (let ((buffer-read-only nil))
2479 (gnus-article-unhide-text (point-min) (point-max))))))
2481 (defun article-emphasize (&optional arg)
2482 "Emphasize text according to `gnus-emphasis-alist'."
2483 (interactive (gnus-article-hidden-arg))
2484 (unless (gnus-article-check-hidden-text 'emphasis arg)
2488 (with-current-buffer gnus-summary-buffer
2489 gnus-article-emphasis-alist)
2491 gnus-emphasis-alist))
2492 (buffer-read-only nil)
2493 (props (append '(article-type emphasis)
2494 gnus-hidden-properties))
2495 regexp elem beg invisible visible face)
2498 (while (setq elem (pop alist))
2500 (setq regexp (car elem)
2501 invisible (nth 1 elem)
2502 visible (nth 2 elem)
2504 (while (re-search-forward regexp nil t)
2505 (when (and (match-beginning visible) (match-beginning invisible))
2506 (push 'emphasis gnus-article-wash-types)
2507 (gnus-article-hide-text
2508 (match-beginning invisible) (match-end invisible) props)
2509 (gnus-article-unhide-text-type
2510 (match-beginning visible) (match-end visible) 'emphasis)
2511 (gnus-put-text-property-excluding-newlines
2512 (match-beginning visible) (match-end visible) 'face face)
2513 (goto-char (match-end invisible)))))))))
2515 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2516 "Setup newsgroup emphasis alist."
2517 (unless gnus-article-emphasis-alist
2518 (let ((name (and gnus-newsgroup-name
2519 (gnus-group-real-name gnus-newsgroup-name))))
2520 (make-local-variable 'gnus-article-emphasis-alist)
2521 (setq gnus-article-emphasis-alist
2523 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2524 (while (setq elem (pop alist))
2525 (when (and name (string-match (car elem) name))
2527 highlight (copy-sequence (cdr elem)))))
2529 (copy-sequence highlight-words)
2530 (if gnus-newsgroup-name
2531 (copy-sequence (gnus-group-find-parameter
2532 gnus-newsgroup-name 'highlight-words t)))
2533 gnus-emphasis-alist)))))
2535 (defvar gnus-summary-article-menu)
2536 (defvar gnus-summary-post-menu)
2538 ;;; Saving functions.
2540 (defun gnus-article-save (save-buffer file &optional num)
2541 "Save the currently selected article."
2542 (unless gnus-save-all-headers
2543 ;; Remove headers according to `gnus-saved-headers'.
2544 (let ((gnus-visible-headers
2545 (or gnus-saved-headers gnus-visible-headers))
2546 (gnus-article-buffer save-buffer))
2548 (set-buffer save-buffer)
2549 (article-hide-headers 1 t))))
2550 (save-window-excursion
2551 (if (not gnus-default-article-saver)
2552 (error "No default saver is defined")
2553 ;; !!! Magic! The saving functions all save
2554 ;; `gnus-save-article-buffer' (or so they think), but we
2555 ;; bind that variable to our save-buffer.
2556 (set-buffer gnus-article-buffer)
2557 (let* ((gnus-save-article-buffer save-buffer)
2560 ((not gnus-prompt-before-saving) 'default)
2561 ((eq gnus-prompt-before-saving 'always) nil)
2563 (gnus-number-of-articles-to-be-saved
2564 (when (eq gnus-prompt-before-saving t)
2566 (set-buffer gnus-article-current-summary)
2567 (funcall gnus-default-article-saver filename)))))
2569 (defun gnus-read-save-file-name (prompt &optional filename
2570 function group headers variable)
2572 (funcall function group headers (symbol-value variable)))
2577 ((eq filename 'default)
2583 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2586 (if (and gnus-number-of-articles-to-be-saved
2587 (> gnus-number-of-articles-to-be-saved 1))
2588 (format "these %d articles"
2589 gnus-number-of-articles-to-be-saved)
2592 ;; Let the split methods have their say.
2594 ;; No split name was found.
2597 (concat prompt " (default "
2598 (file-name-nondirectory default-name) ") ")
2599 (file-name-directory default-name)
2601 ;; A single group name is returned.
2602 ((stringp split-name)
2604 (funcall function split-name headers
2605 (symbol-value variable)))
2607 (concat prompt " (default "
2608 (file-name-nondirectory default-name) ") ")
2609 (file-name-directory default-name)
2611 ;; A single split name was found
2612 ((= 1 (length split-name))
2613 (let* ((name (expand-file-name
2615 gnus-article-save-directory))
2616 (dir (cond ((file-directory-p name)
2617 (file-name-as-directory name))
2618 ((file-exists-p name) name)
2619 (t gnus-article-save-directory))))
2621 (concat prompt " (default " name ") ")
2623 ;; A list of splits was found.
2625 (setq split-name (nreverse split-name))
2627 (let ((file-name-history
2628 (nconc split-name file-name-history)))
2632 (concat prompt " (`M-p' for defaults) ")
2633 gnus-article-save-directory
2635 gnus-article-save-directory)))
2636 (car (push result file-name-history)))))))
2637 ;; Create the directory.
2638 (gnus-make-directory (file-name-directory file))
2639 ;; If we have read a directory, we append the default file name.
2640 (when (file-directory-p file)
2641 (setq file (expand-file-name (file-name-nondirectory
2643 (file-name-as-directory file))))
2644 ;; Possibly translate some characters.
2645 (nnheader-translate-file-chars file))))))
2646 (gnus-make-directory (file-name-directory result))
2647 (set variable result)))
2649 (defun gnus-article-archive-name (group)
2650 "Return the first instance of an \"Archive-name\" in the current buffer."
2651 (let ((case-fold-search t))
2652 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2653 (nnheader-concat gnus-article-save-directory
2654 (match-string 1)))))
2656 (defun gnus-article-nndoc-name (group)
2657 "If GROUP is an nndoc group, return the name of the parent group."
2658 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2659 (gnus-group-get-parameter group 'save-article-group)))
2661 (defun gnus-summary-save-in-rmail (&optional filename)
2662 "Append this article to Rmail file.
2663 Optional argument FILENAME specifies file name.
2664 Directory to save to is default to `gnus-article-save-directory'."
2665 (setq filename (gnus-read-save-file-name
2666 "Save %s in rmail file:" filename
2667 gnus-rmail-save-name gnus-newsgroup-name
2668 gnus-current-headers 'gnus-newsgroup-last-rmail))
2669 (gnus-eval-in-buffer-window gnus-save-article-buffer
2673 (gnus-output-to-rmail filename))))
2676 (defun gnus-summary-save-in-mail (&optional filename)
2677 "Append this article to Unix mail file.
2678 Optional argument FILENAME specifies file name.
2679 Directory to save to is default to `gnus-article-save-directory'."
2680 (setq filename (gnus-read-save-file-name
2681 "Save %s in Unix mail file:" filename
2682 gnus-mail-save-name gnus-newsgroup-name
2683 gnus-current-headers 'gnus-newsgroup-last-mail))
2684 (gnus-eval-in-buffer-window gnus-save-article-buffer
2688 (if (and (file-readable-p filename)
2689 (mail-file-babyl-p filename))
2690 (rmail-output-to-rmail-file filename t)
2691 (gnus-output-to-mail filename)))))
2694 (defun gnus-summary-save-in-file (&optional filename overwrite)
2695 "Append this article to file.
2696 Optional argument FILENAME specifies file name.
2697 Directory to save to is default to `gnus-article-save-directory'."
2698 (setq filename (gnus-read-save-file-name
2699 "Save %s in file:" filename
2700 gnus-file-save-name gnus-newsgroup-name
2701 gnus-current-headers 'gnus-newsgroup-last-file))
2702 (gnus-eval-in-buffer-window gnus-save-article-buffer
2706 (when (and overwrite
2707 (file-exists-p filename))
2708 (delete-file filename))
2709 (gnus-output-to-file filename))))
2712 (defun gnus-summary-write-to-file (&optional filename)
2713 "Write this article to a file.
2714 Optional argument FILENAME specifies file name.
2715 The directory to save in defaults to `gnus-article-save-directory'."
2716 (gnus-summary-save-in-file nil t))
2718 (defun gnus-summary-save-body-in-file (&optional filename)
2719 "Append this article body to a file.
2720 Optional argument FILENAME specifies file name.
2721 The directory to save in defaults to `gnus-article-save-directory'."
2722 (setq filename (gnus-read-save-file-name
2723 "Save %s body in file:" filename
2724 gnus-file-save-name gnus-newsgroup-name
2725 gnus-current-headers 'gnus-newsgroup-last-file))
2726 (gnus-eval-in-buffer-window gnus-save-article-buffer
2730 (when (article-goto-body)
2731 (narrow-to-region (point) (point-max)))
2732 (gnus-output-to-file filename))))
2735 (defun gnus-summary-save-in-pipe (&optional command)
2736 "Pipe this article to subprocess."
2738 (cond ((and (eq command 'default)
2739 gnus-last-shell-command)
2740 gnus-last-shell-command)
2744 "Shell command on %s: "
2745 (if (and gnus-number-of-articles-to-be-saved
2746 (> gnus-number-of-articles-to-be-saved 1))
2747 (format "these %d articles"
2748 gnus-number-of-articles-to-be-saved)
2750 gnus-last-shell-command))))
2751 (when (string-equal command "")
2752 (setq command gnus-last-shell-command))
2753 (gnus-eval-in-buffer-window gnus-article-buffer
2756 (shell-command-on-region (point-min) (point-max) command nil)))
2757 (setq gnus-last-shell-command command))
2759 ;;; Article file names when saving.
2761 (defun gnus-capitalize-newsgroup (newsgroup)
2762 "Capitalize NEWSGROUP name."
2763 (when (not (zerop (length newsgroup)))
2764 (concat (char-to-string (upcase (aref newsgroup 0)))
2765 (substring newsgroup 1))))
2767 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2768 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2769 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2770 Otherwise, it is like ~/News/news/group/num."
2773 (concat (if (gnus-use-long-file-name 'not-save)
2774 (gnus-capitalize-newsgroup newsgroup)
2775 (gnus-newsgroup-directory-form newsgroup))
2776 "/" (int-to-string (mail-header-number headers)))
2777 gnus-article-save-directory)))
2779 (string-equal (file-name-directory default)
2780 (file-name-directory last-file))
2781 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2783 (or last-file default))))
2785 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2786 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2787 If variable `gnus-use-long-file-name' is non-nil, it is
2788 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2791 (concat (if (gnus-use-long-file-name 'not-save)
2793 (gnus-newsgroup-directory-form newsgroup))
2794 "/" (int-to-string (mail-header-number headers)))
2795 gnus-article-save-directory)))
2797 (string-equal (file-name-directory default)
2798 (file-name-directory last-file))
2799 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2801 (or last-file default))))
2803 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2804 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2805 If variable `gnus-use-long-file-name' is non-nil, it is
2806 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2809 (if (gnus-use-long-file-name 'not-save)
2811 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2812 gnus-article-save-directory)))
2814 (defun article-verify-x-pgp-sig ()
2817 (if (gnus-buffer-live-p gnus-original-article-buffer)
2818 (let ((sig (with-current-buffer gnus-original-article-buffer
2819 (gnus-fetch-field "X-PGP-Sig")))
2823 (mml2015-clear-verify-function))
2825 (insert-buffer gnus-original-article-buffer)
2826 (setq items (split-string sig))
2827 (message-narrow-to-head)
2828 (let ((inhibit-point-motion-hooks t)
2829 (case-fold-search t))
2830 ;; Don't verify multiple headers.
2831 (setq headers (mapconcat (lambda (header)
2833 (mail-fetch-field header) "\n"))
2834 (split-string (nth 1 items) ",") "")))
2835 (delete-region (point-min) (point-max))
2836 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2837 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2842 (if (looking-at "^-")
2845 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2846 (insert "Version: " (car items) "\n\n")
2847 (insert (mapconcat 'identity (cddr items) "\n"))
2848 (insert "\n-----END PGP SIGNATURE-----\n")
2849 (let ((mm-security-handle (list (format "multipart/signed"))))
2850 (mml2015-clean-buffer)
2851 (let ((coding-system-for-write (or gnus-newsgroup-charset
2853 (funcall (mml2015-clear-verify-function)))
2855 (or (mm-handle-multipart-ctl-parameter
2856 mm-security-handle 'gnus-details)
2857 (mm-handle-multipart-ctl-parameter
2858 mm-security-handle 'gnus-info)))))
2860 (let (buffer-read-only bface eface)
2862 (message-narrow-to-head)
2863 (goto-char (point-max))
2865 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2866 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2867 (message-remove-header "X-Gnus-PGP-Verify")
2868 (if (re-search-forward "^X-PGP-Sig:" nil t)
2870 (goto-char (point-max)))
2871 (narrow-to-region (point) (point))
2872 (insert "X-Gnus-PGP-Verify: " info "\n")
2873 (goto-char (point-min))
2876 (if (not (looking-at "^[ \t]"))
2880 (goto-char (point-min))
2881 (when (looking-at "\\([^:]+\\): *")
2882 (put-text-property (match-beginning 1) (1+ (match-end 1))
2884 (put-text-property (match-end 0) (point-max)
2885 'face eface)))))))))
2892 (setq afunc (car func)
2895 gfunc (intern (format "gnus-%s" func))))
2898 `(lambda (&optional interactive &rest args)
2899 ,(documentation afunc t)
2900 (interactive (list t))
2902 (set-buffer gnus-article-buffer)
2904 (call-interactively ',afunc)
2905 (apply ',afunc args))))))))
2906 '(article-hide-headers
2907 article-verify-x-pgp-sig
2908 article-hide-boring-headers
2909 article-toggle-headers
2910 article-treat-overstrike
2911 article-fill-long-lines
2912 article-capitalize-sentences
2914 article-display-x-face
2915 article-de-quoted-unreadable
2916 article-de-base64-unreadable
2919 article-hide-list-identifiers
2921 article-strip-banner
2924 article-hide-signature
2925 article-strip-headers-in-body
2926 article-remove-trailing-blank-lines
2927 article-strip-leading-blank-lines
2928 article-strip-multiple-blank-lines
2929 article-strip-leading-space
2930 article-strip-trailing-space
2931 article-strip-blank-lines
2932 article-strip-all-blank-lines
2934 article-date-iso8601
2935 article-date-original
2937 article-decode-mime-words
2938 article-decode-charset
2939 article-decode-encoded-words
2943 article-treat-dumbquotes
2944 article-normalize-headers
2945 (article-show-all-headers . gnus-article-show-all-headers)
2946 (article-show-all . gnus-article-show-all))))
2949 ;;; Gnus article mode
2952 (put 'gnus-article-mode 'mode-class 'special)
2954 (gnus-define-keys gnus-article-mode-map
2955 " " gnus-article-goto-next-page
2956 "\177" gnus-article-goto-prev-page
2957 [delete] gnus-article-goto-prev-page
2958 [backspace] gnus-article-goto-prev-page
2959 "\C-c^" gnus-article-refer-article
2960 "h" gnus-article-show-summary
2961 "s" gnus-article-show-summary
2962 "\C-c\C-m" gnus-article-mail
2963 "?" gnus-article-describe-briefly
2964 "e" gnus-summary-edit-article
2965 "<" beginning-of-buffer
2967 "\C-c\C-i" gnus-info-find-node
2969 "\C-hk" gnus-article-describe-key
2970 "\C-hc" gnus-article-describe-key-briefly
2972 "\C-d" gnus-article-read-summary-keys
2973 "\M-*" gnus-article-read-summary-keys
2974 "\M-#" gnus-article-read-summary-keys
2975 "\M-^" gnus-article-read-summary-keys
2976 "\M-g" gnus-article-read-summary-keys)
2978 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2981 (unless (lookup-key gnus-article-mode-map key)
2982 (define-key gnus-article-mode-map key
2983 'gnus-article-read-summary-keys)))
2988 (let ((key (car elt)))
2989 (and (> (length key) 0)
2990 (not (eq 'menu-bar (aref key 0)))
2991 (symbolp (lookup-key gnus-summary-mode-map key))
2993 (accessible-keymaps gnus-summary-mode-map))
2997 (push (char-to-string c) keys)
3002 (defvar gnus-article-commands-menu))
3004 (defun gnus-article-make-menu-bar ()
3005 (gnus-turn-off-edit-menu 'article)
3006 (unless (boundp 'gnus-article-article-menu)
3008 gnus-article-article-menu gnus-article-mode-map ""
3010 ["Scroll forwards" gnus-article-goto-next-page t]
3011 ["Scroll backwards" gnus-article-goto-prev-page t]
3012 ["Show summary" gnus-article-show-summary t]
3013 ["Fetch Message-ID at point" gnus-article-refer-article t]
3014 ["Mail to address at point" gnus-article-mail t]
3015 ["Send a bug report" gnus-bug t]))
3018 gnus-article-treatment-menu gnus-article-mode-map ""
3019 ;; Fixme: this should use :active (and maybe :visible).
3021 ["Hide headers" gnus-article-toggle-headers t]
3022 ["Hide signature" gnus-article-hide-signature t]
3023 ["Hide citation" gnus-article-hide-citation t]
3024 ["Treat overstrike" gnus-article-treat-overstrike t]
3025 ["Remove carriage return" gnus-article-remove-cr t]
3026 ["Decode HZ" gnus-article-decode-HZ t]))
3028 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3030 (when (boundp 'gnus-summary-post-menu)
3031 (define-key gnus-article-mode-map [menu-bar post]
3032 (cons "Post" gnus-summary-post-menu)))
3034 (gnus-run-hooks 'gnus-article-menu-hook))
3036 (when (boundp 'gnus-article-commands-menu)
3037 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
3038 (when (boundp 'gnus-summary-post-menu)
3039 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
3041 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3044 (defun gnus-article-mode ()
3045 "Major mode for displaying an article.
3047 All normal editing commands are switched off.
3049 The following commands are available in addition to all summary mode
3051 \\<gnus-article-mode-map>
3052 \\[gnus-article-next-page]\t Scroll the article one page forwards
3053 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3054 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3055 \\[gnus-article-show-summary]\t Display the summary buffer
3056 \\[gnus-article-mail]\t Send a reply to the address near point
3057 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3058 \\[gnus-info-find-node]\t Go to the Gnus info node"
3060 (when (gnus-visual-p 'article-menu 'menu)
3061 (gnus-article-make-menu-bar))
3062 (gnus-simplify-mode-line)
3063 (setq mode-name "Article")
3064 (setq major-mode 'gnus-article-mode)
3065 (make-local-variable 'minor-mode-alist)
3066 (unless (assq 'gnus-show-mime minor-mode-alist)
3067 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3068 (use-local-map gnus-article-mode-map)
3069 (gnus-update-format-specifications nil 'article-mode)
3070 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3071 (make-local-variable 'gnus-page-broken)
3072 (make-local-variable 'gnus-button-marker-list)
3073 (make-local-variable 'gnus-article-current-summary)
3074 (make-local-variable 'gnus-article-mime-handles)
3075 (make-local-variable 'gnus-article-decoded-p)
3076 (make-local-variable 'gnus-article-mime-handle-alist)
3077 (make-local-variable 'gnus-article-wash-types)
3078 (make-local-variable 'gnus-article-charset)
3079 (make-local-variable 'gnus-article-ignored-charsets)
3080 (gnus-set-default-directory)
3081 (buffer-disable-undo)
3082 (setq buffer-read-only t)
3083 (set-syntax-table gnus-article-mode-syntax-table)
3084 (gnus-run-hooks 'gnus-article-mode-hook))
3086 (defun gnus-article-setup-buffer ()
3087 "Initialize the article buffer."
3088 (let* ((name (if gnus-single-article-buffer "*Article*"
3089 (concat "*Article " gnus-newsgroup-name "*")))
3091 (progn (string-match "\\*Article" name)
3092 (concat " *Original Article"
3093 (substring name (match-end 0))))))
3094 (setq gnus-article-buffer name)
3095 (setq gnus-original-article-buffer original)
3096 (setq gnus-article-mime-handle-alist nil)
3097 ;; This might be a variable local to the summary buffer.
3098 (unless gnus-single-article-buffer
3100 (set-buffer gnus-summary-buffer)
3101 (setq gnus-article-buffer name)
3102 (setq gnus-original-article-buffer original)
3103 (gnus-set-global-variables)))
3104 (gnus-article-setup-highlight-words)
3105 ;; Init original article buffer.
3107 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3108 (set-buffer-multibyte nil)
3109 (setq major-mode 'gnus-original-article-mode)
3110 (make-local-variable 'gnus-original-article))
3111 (if (get-buffer name)
3114 (buffer-disable-undo)
3115 (setq buffer-read-only t)
3116 (unless (eq major-mode 'gnus-article-mode)
3117 (gnus-article-mode))
3120 (set-buffer (gnus-get-buffer-create name))
3122 (make-local-variable 'gnus-summary-buffer)
3123 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3124 (current-buffer)))))
3126 ;; Set article window start at LINE, where LINE is the number of lines
3127 ;; from the head of the article.
3128 (defun gnus-article-set-window-start (&optional line)
3130 (get-buffer-window gnus-article-buffer t)
3132 (set-buffer gnus-article-buffer)
3133 (goto-char (point-min))
3136 (gnus-message 6 "Moved to bookmark")
3137 (search-forward "\n\n" nil t)
3141 ;;; @@ article filters
3144 (defun gnus-article-display-mime-message ()
3145 "Article display method for MIME message."
3146 ;; called from `gnus-original-article-buffer'.
3147 (let (charset all-headers)
3148 (with-current-buffer gnus-summary-buffer
3149 (setq charset default-mime-charset
3150 all-headers gnus-have-all-headers))
3151 (make-local-variable 'default-mime-charset)
3152 (setq default-mime-charset charset)
3153 (with-current-buffer (get-buffer-create gnus-article-buffer)
3154 (make-local-variable 'default-mime-charset)
3155 (setq default-mime-charset charset))
3156 (mime-display-message mime-message-structure
3157 gnus-article-buffer nil gnus-article-mode-map)
3159 (gnus-article-hide-headers nil -1)))
3160 (run-hooks 'gnus-mime-article-prepare-hook))
3162 (defun gnus-article-display-traditional-message ()
3163 "Article display method for traditional message."
3164 (set-buffer gnus-article-buffer)
3165 (let (buffer-read-only)
3167 (insert-buffer-substring gnus-original-article-buffer)))
3169 (defun gnus-article-make-full-mail-header (&optional number charset)
3170 "Create a new mail header structure in a raw article buffer."
3171 (unless (and number charset)
3172 (save-current-buffer
3173 (set-buffer gnus-summary-buffer)
3175 (setq number (or (cdr gnus-article-current) 0)))
3177 (setq charset (or default-mime-charset 'x-ctext)))))
3178 (goto-char (point-min))
3179 (let ((header-end (if (search-forward "\n\n" nil t)
3181 (goto-char (point-max))))
3182 (chars (- (point-max) (point)))
3183 (lines (count-lines (point) (point-max)))
3184 (default-mime-charset charset)
3186 (narrow-to-region (point-min) header-end)
3187 (setq xref (std11-fetch-field "xref"))
3189 (make-full-mail-header
3191 (std11-fetch-field "subject")
3192 (std11-fetch-field "from")
3193 (std11-fetch-field "date")
3194 (std11-fetch-field "message-id")
3195 (std11-fetch-field "references")
3198 (when xref (concat "Xref: " xref)))
3201 (defun gnus-article-prepare (article &optional all-headers header)
3202 "Prepare ARTICLE in article mode buffer.
3203 ARTICLE should either be an article number or a Message-ID.
3204 If ARTICLE is an id, HEADER should be the article headers.
3205 If ALL-HEADERS is non-nil, no headers are hidden."
3207 ;; Make sure we start in a summary buffer.
3208 (unless (eq major-mode 'gnus-summary-mode)
3209 (set-buffer gnus-summary-buffer))
3210 (setq gnus-summary-buffer (current-buffer))
3211 (let* ((gnus-article (if header (mail-header-number header) article))
3212 (summary-buffer (current-buffer))
3213 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3214 (group gnus-newsgroup-name)
3217 (gnus-article-setup-buffer)
3218 (set-buffer gnus-original-article-buffer)
3219 ;; Deactivate active regions.
3220 (when (and (boundp 'transient-mark-mode)
3221 transient-mark-mode)
3222 (setq mark-active nil))
3223 (if (not (setq result (let ((buffer-read-only nil))
3224 (gnus-request-article-this-buffer
3226 ;; There is no such article.
3228 (when (and (numberp article)
3229 (not (memq article gnus-newsgroup-sparse)))
3230 (setq gnus-article-current
3231 (cons gnus-newsgroup-name article))
3232 (set-buffer gnus-summary-buffer)
3233 (setq gnus-current-article article)
3234 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3236 (gnus-summary-set-agent-mark article)
3237 (message "Message marked for downloading"))
3238 (gnus-summary-mark-article article gnus-canceled-mark)
3239 (unless (memq article gnus-newsgroup-sparse)
3240 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3241 (if (or (eq result 'pseudo)
3242 (eq result 'nneething))
3245 (set-buffer summary-buffer)
3246 (push article gnus-newsgroup-history)
3247 (setq gnus-last-article gnus-current-article
3248 gnus-current-article 0
3249 gnus-current-headers nil
3250 gnus-article-current nil)
3251 (if (eq result 'nneething)
3252 (gnus-configure-windows 'summary)
3253 (gnus-configure-windows 'article))
3254 (gnus-set-global-variables))
3255 (let ((gnus-article-mime-handle-alist-1
3256 gnus-article-mime-handle-alist))
3257 (gnus-set-mode-line 'article)))
3258 ;; The result from the `request' was an actual article -
3259 ;; or at least some text that is now displayed in the
3261 (when (and (numberp article)
3262 (not (eq article gnus-current-article)))
3263 ;; Seems like a new article has been selected.
3264 ;; `gnus-current-article' must be an article number.
3266 (set-buffer summary-buffer)
3267 (push article gnus-newsgroup-history)
3268 (setq gnus-last-article gnus-current-article
3269 gnus-current-article article
3270 gnus-current-headers
3271 (gnus-summary-article-header gnus-current-article)
3272 gnus-article-current
3273 (cons gnus-newsgroup-name gnus-current-article))
3274 (unless (vectorp gnus-current-headers)
3275 (setq gnus-current-headers nil))
3276 (gnus-summary-goto-subject gnus-current-article)
3277 (when (gnus-summary-show-thread)
3278 ;; If the summary buffer really was folded, the
3279 ;; previous goto may not actually have gone to
3280 ;; the right article, but the thread root instead.
3282 (gnus-summary-goto-subject gnus-current-article))
3283 (gnus-run-hooks 'gnus-mark-article-hook)
3284 (gnus-set-mode-line 'summary)
3285 (when (gnus-visual-p 'article-highlight 'highlight)
3286 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3287 ;; Set the global newsgroup variables here.
3288 (gnus-set-global-variables)
3289 (setq gnus-have-all-headers
3290 (or all-headers gnus-show-all-headers))))
3292 (gnus-configure-windows 'article))
3293 (when (or (numberp article)
3295 (gnus-article-prepare-display)
3297 (goto-char (point-min))
3298 (setq gnus-page-broken
3299 (when gnus-break-pages
3300 (gnus-narrow-to-page)
3302 (let ((gnus-article-mime-handle-alist-1
3303 gnus-article-mime-handle-alist))
3304 (gnus-set-mode-line 'article))
3306 (set-window-point (get-buffer-window (current-buffer)) (point))
3307 (gnus-configure-windows 'article)
3310 (defun gnus-article-prepare-mime-display (&optional number)
3311 (goto-char (point-min))
3312 (when (re-search-forward "^[^\t ]+:" nil t)
3313 (goto-char (match-beginning 0)))
3314 (let ((entity (if (eq 1 (point-min))
3315 (get-text-property 1 'mime-view-entity)
3316 (get-text-property (point) 'mime-view-entity)))
3317 last-entity child-entity next type)
3318 (setq child-entity (mime-entity-children entity))
3320 (setq last-entity (nth (1- (length child-entity))
3322 (setq last-entity entity))
3324 (narrow-to-region (point)
3325 (if (search-forward "\n\n" nil t)
3328 (gnus-treat-article 'head)
3329 (put-text-property (point-min) (point-max) 'article-treated-header t)
3330 (goto-char (point-max)))
3331 (while (and (not (eobp)) entity)
3332 (setq next (set-marker
3334 (next-single-property-change (point) 'mime-view-entity
3336 (let ((types (mime-entity-content-type entity)))
3337 (while (eq 'multipart (mime-content-type-primary-type types))
3338 (setq entity (car (mime-entity-children entity))
3339 types (mime-entity-content-type entity)))
3341 (setq type (format "%s/%s"
3342 (mime-content-type-primary-type types)
3343 (mime-content-type-subtype types)))))
3344 (if (string-equal type "message/rfc822")
3347 (let ((children (mime-entity-children entity))
3350 (setq last-children (nth (1- (length children)) children))
3353 (not (eq last-children
3354 (get-text-property next 'mime-view-entity)))
3356 (next-single-property-change next
3358 nil (point-max)))))))
3359 (setq next (next-single-property-change next 'mime-view-entity
3362 (narrow-to-region (point) next)
3363 (gnus-article-prepare-mime-display)
3364 (goto-char (point-max)))
3365 (setq entity (get-text-property (point) 'mime-view-entity)))
3367 (narrow-to-region (point) next)
3368 ;; Kludge. We have to count true number, but for now,
3369 ;; part number is here only to achieve `last'.
3370 (gnus-treat-article nil 1
3371 (if (eq entity last-entity)
3374 (goto-char (point-max)))
3375 (setq entity (get-text-property next 'mime-view-entity))))))
3378 (defun gnus-article-prepare-display ()
3379 "Make the current buffer look like a nice article."
3380 (setq gnus-article-wash-types nil)
3381 (gnus-run-hooks 'gnus-tmp-internal-hook)
3382 (gnus-run-hooks 'gnus-article-prepare-hook)
3384 (let (mime-display-header-hook mime-display-text/plain-hook)
3385 (funcall (if gnus-show-mime
3387 (setq mime-message-structure gnus-current-headers)
3388 (mime-buffer-entity-set-buffer-internal
3389 mime-message-structure
3390 gnus-original-article-buffer)
3391 (mime-entity-set-representation-type-internal
3392 mime-message-structure 'mime-buffer-entity)
3393 (luna-send mime-message-structure
3394 'initialize-instance
3395 mime-message-structure)
3396 gnus-article-display-method-for-mime)
3397 gnus-article-display-method-for-traditional)))
3398 ;; Associate this article with the current summary buffer.
3399 (setq gnus-article-current-summary gnus-summary-buffer)
3400 ;; Call the treatment functions.
3401 (let ((inhibit-read-only t)
3406 (gnus-article-prepare-mime-display)
3407 (narrow-to-region (goto-char (point-min))
3408 (if (search-forward "\n\n" nil t)
3411 (gnus-treat-article 'head)
3412 (put-text-property (point-min) (point-max) 'article-treated-header t)
3413 (goto-char (point-max))
3415 (narrow-to-region (point) (point-max))
3416 (gnus-treat-article nil))
3417 (put-text-property (point-min) (point-max) 'read-only nil)))
3418 ;; Perform the article display hooks. Incidentally, this hook is
3419 ;; an obsolete variable by now.
3420 (gnus-run-hooks 'gnus-article-display-hook))
3422 (defun gnus-article-decode-article-as-default-mime-charset ()
3423 "Decode an article as `default-mime-charset'. It won't work if the
3424 value of the variable `gnus-show-mime' is non-nil."
3425 (unless gnus-show-mime
3426 (decode-mime-charset-region (point-min) (point-max)
3427 (with-current-buffer gnus-summary-buffer
3428 default-mime-charset))))
3431 ;;; Gnus MIME viewing functions
3434 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3435 "The following specs can be used:
3437 %T MIME type, along with additional info
3438 %n The `name' parameter
3439 %d The description, if any
3440 %l The length of the encoded part
3441 %p The part identifier number
3442 %e Dots if the part isn't displayed")
3444 (defvar gnus-mime-button-line-format-alist
3445 '((?t gnus-tmp-type ?s)
3446 (?T gnus-tmp-type-long ?s)
3447 (?n gnus-tmp-name ?s)
3448 (?d gnus-tmp-description ?s)
3450 (?l gnus-tmp-length ?d)
3451 (?e gnus-tmp-dots ?s)))
3453 (defvar gnus-mime-button-commands
3454 '((gnus-article-press-button "\r" "Toggle Display")
3455 (gnus-mime-view-part "v" "View Interactively...")
3456 (gnus-mime-view-part-as-type "t" "View As Type...")
3457 (gnus-mime-view-part-as-charset "C" "View As charset...")
3458 (gnus-mime-save-part "o" "Save...")
3459 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3460 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3461 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3462 (gnus-mime-internalize-part "E" "View Internally")
3463 (gnus-mime-externalize-part "e" "View Externally")
3464 (gnus-mime-pipe-part "|" "Pipe To Command...")
3465 (gnus-mime-action-on-part "." "Take action on the part")))
3467 (defun gnus-article-mime-part-status ()
3468 (with-current-buffer gnus-article-buffer
3469 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3470 (if (and entity (mime-entity-children entity))
3471 (format " (%d parts)" (length (mime-entity-children entity)))
3474 (defvar gnus-mime-button-map
3475 (let ((map (make-sparse-keymap)))
3476 ;; Not for Emacs 21: fixme better.
3477 ;; (set-keymap-parent map gnus-article-mode-map)
3478 (define-key map gnus-mouse-2 'gnus-article-push-button)
3479 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3480 (dolist (c gnus-mime-button-commands)
3481 (define-key map (cadr c) (car c)))
3484 (defun gnus-mime-button-menu (event)
3485 "Construct a context-sensitive menu of MIME commands."
3487 (save-window-excursion
3488 (let ((pos (event-start event)))
3489 (select-window (posn-window pos))
3490 (goto-char (posn-point pos))
3491 (gnus-article-check-buffer)
3492 (let ((response (x-popup-menu
3494 ("" ,@(mapcar (lambda (c)
3495 (cons (caddr c) (car c)))
3496 gnus-mime-button-commands))))))
3498 (call-interactively response))))))
3500 (defun gnus-mime-view-all-parts (&optional handles)
3501 "View all the MIME parts."
3503 (save-current-buffer
3504 (set-buffer gnus-article-buffer)
3505 (let ((handles (or handles gnus-article-mime-handles))
3506 (mail-parse-charset gnus-newsgroup-charset)
3507 (mail-parse-ignored-charsets
3508 (with-current-buffer gnus-summary-buffer
3509 gnus-newsgroup-ignored-charsets)))
3511 (mm-remove-parts handles)
3512 (goto-char (point-min))
3513 (or (search-forward "\n\n") (goto-char (point-max)))
3514 (let (buffer-read-only)
3515 (delete-region (point) (point-max)))
3516 (mm-display-parts handles)))))
3518 (defun gnus-mime-save-part-and-strip ()
3519 "Save the MIME part under point then replace it with an external body."
3521 (gnus-article-check-buffer)
3522 (let* ((data (get-text-property (point) 'gnus-data))
3523 (file (and data (mm-save-part data)))
3526 (with-current-buffer (mm-handle-buffer data)
3528 (insert "Content-Type: " (mm-handle-media-type data))
3529 (mml-insert-parameter-string (cdr (mm-handle-type data))
3532 (insert "Content-ID: " (message-make-message-id) "\n")
3533 (insert "Content-Transfer-Encoding: binary\n")
3536 (cdr (mm-make-handle nil
3537 `("message/external-body"
3538 (access-type . "LOCAL-FILE")
3540 (set-buffer gnus-summary-buffer)
3541 (gnus-article-edit-article
3544 (let ((mail-parse-charset (or gnus-article-charset
3545 ',gnus-newsgroup-charset))
3546 (mail-parse-ignored-charsets
3547 (or gnus-article-ignored-charsets
3548 ',gnus-newsgroup-ignored-charsets))
3549 (mbl mml-buffer-list))
3550 (setq mml-buffer-list nil)
3551 (insert-buffer gnus-original-article-buffer)
3552 (mime-to-mml gnus-article-mime-handles)
3553 (setq gnus-article-mime-handles nil)
3554 (make-local-hook 'kill-buffer-hook)
3555 (let ((mbl1 mml-buffer-list))
3556 (setq mml-buffer-list mbl)
3557 (set (make-local-variable 'mml-buffer-list) mbl1))
3558 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3559 `(lambda (no-highlight)
3560 (let ((mail-parse-charset (or gnus-article-charset
3561 ',gnus-newsgroup-charset))
3562 (message-options message-options)
3563 (message-options-set-recipient)
3564 (mail-parse-ignored-charsets
3565 (or gnus-article-ignored-charsets
3566 ',gnus-newsgroup-ignored-charsets)))
3568 (mml-destroy-buffers)
3569 (remove-hook 'kill-buffer-hook
3570 'mml-destroy-buffers t)
3571 (kill-local-variable 'mml-buffer-list))
3572 (gnus-summary-edit-article-done
3573 ,(or (mail-header-references gnus-current-headers) "")
3574 ,(gnus-group-read-only-p)
3575 ,gnus-summary-buffer no-highlight))))))
3577 (defun gnus-mime-save-part ()
3578 "Save the MIME part under point."
3580 (gnus-article-check-buffer)
3581 (let ((data (get-text-property (point) 'gnus-data)))
3583 (mm-save-part data))))
3585 (defun gnus-mime-pipe-part ()
3586 "Pipe the MIME part under point to a process."
3588 (gnus-article-check-buffer)
3589 (let ((data (get-text-property (point) 'gnus-data)))
3591 (mm-pipe-part data))))
3593 (defun gnus-mime-view-part ()
3594 "Interactively choose a viewing method for the MIME part under point."
3596 (gnus-article-check-buffer)
3597 (let ((data (get-text-property (point) 'gnus-data)))
3599 (mm-interactively-view-part data))))
3601 (defun gnus-mime-view-part-as-type-internal ()
3602 (gnus-article-check-buffer)
3603 (let* ((name (mail-content-type-get
3604 (mm-handle-type (get-text-property (point) 'gnus-data))
3606 (def-type (and name (mm-default-file-encoding name))))
3607 (and def-type (cons def-type 0))))
3609 (defun gnus-mime-view-part-as-type (mime-type)
3610 "Choose a MIME media type, and view the part as such."
3612 (list (completing-read
3613 "View as MIME type: "
3614 (mapcar #'list (mailcap-mime-types))
3616 (gnus-mime-view-part-as-type-internal))))
3617 (gnus-article-check-buffer)
3618 (let ((handle (get-text-property (point) 'gnus-data)))
3620 (gnus-mm-display-part
3621 (mm-make-handle (mm-handle-buffer handle)
3622 (cons mime-type (cdr (mm-handle-type handle)))
3623 (mm-handle-encoding handle)
3624 (mm-handle-undisplayer handle)
3625 (mm-handle-disposition handle)
3626 (mm-handle-description handle)
3627 (mm-handle-cache handle)
3628 (mm-handle-id handle))))))
3630 (defun gnus-mime-copy-part (&optional handle)
3631 "Put the the MIME part under point into a new buffer."
3633 (gnus-article-check-buffer)
3634 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3635 (contents (and handle (mm-get-part handle)))
3637 (file-name-nondirectory
3639 (mail-content-type-get (mm-handle-type handle) 'name)
3640 (mail-content-type-get (mm-handle-type handle)
3643 (buffer (and base (generate-new-buffer base))))
3645 (switch-to-buffer buffer)
3647 ;; We do it this way to make `normal-mode' set the appropriate mode.
3650 (setq buffer-file-name (expand-file-name base))
3652 (setq buffer-file-name nil))
3653 (goto-char (point-min)))))
3655 (defun gnus-mime-inline-part (&optional handle arg)
3656 "Insert the MIME part under point into the current buffer."
3657 (interactive (list nil current-prefix-arg))
3658 (gnus-article-check-buffer)
3659 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3664 (if (and (not arg) (mm-handle-undisplayer handle))
3665 (mm-remove-part handle)
3666 (setq contents (mm-get-part handle))
3669 (setq charset (or (mail-content-type-get
3670 (mm-handle-type handle) 'charset)
3671 gnus-newsgroup-charset)))
3673 (if (mm-handle-undisplayer handle)
3674 (mm-remove-part handle))
3677 gnus-summary-show-article-charset-alist))
3678 (read-coding-system "Charset: ")))))
3680 (mm-insert-inline handle
3682 (setq charset (mm-charset-to-coding-system
3684 (not (eq charset 'ascii)))
3685 (mm-decode-coding-string contents charset)
3689 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3690 "Insert the MIME part under point into the current buffer."
3691 (interactive (list nil current-prefix-arg))
3692 (gnus-article-check-buffer)
3693 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3698 (if (mm-handle-undisplayer handle)
3699 (mm-remove-part handle))
3700 (let ((gnus-newsgroup-charset
3702 gnus-summary-show-article-charset-alist))
3703 (read-coding-system "Charset: ")))
3704 (gnus-newsgroup-ignored-charsets 'gnus-all))
3705 (gnus-article-press-button)))))
3707 (defun gnus-mime-externalize-part (&optional handle)
3708 "View the MIME part under point with an external viewer."
3710 (gnus-article-check-buffer)
3711 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3712 (mm-user-display-methods nil)
3713 (mm-inlined-types nil)
3714 (mail-parse-charset gnus-newsgroup-charset)
3715 (mail-parse-ignored-charsets
3716 (save-excursion (set-buffer gnus-summary-buffer)
3717 gnus-newsgroup-ignored-charsets)))
3719 (if (mm-handle-undisplayer handle)
3720 (mm-remove-part handle)
3721 (mm-display-part handle)))))
3723 (defun gnus-mime-internalize-part (&optional handle)
3724 "View the MIME part under point with an internal viewer.
3725 In no internal viewer is available, use an external viewer."
3727 (gnus-article-check-buffer)
3728 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3729 (mm-inlined-types '(".*"))
3730 (mm-inline-large-images t)
3731 (mail-parse-charset gnus-newsgroup-charset)
3732 (mail-parse-ignored-charsets
3733 (save-excursion (set-buffer gnus-summary-buffer)
3734 gnus-newsgroup-ignored-charsets)))
3736 (if (mm-handle-undisplayer handle)
3737 (mm-remove-part handle)
3738 (mm-display-part handle)))))
3740 (defun gnus-mime-action-on-part (&optional action)
3741 "Do something with the MIME attachment at \(point\)."
3743 (list (completing-read "Action: " gnus-mime-action-alist)))
3744 (gnus-article-check-buffer)
3745 (let ((action-pair (assoc action gnus-mime-action-alist)))
3747 (funcall (cdr action-pair)))))
3749 (defun gnus-article-part-wrapper (n function)
3750 (save-current-buffer
3751 (set-buffer gnus-article-buffer)
3752 (when (> n (length gnus-article-mime-handle-alist))
3753 (error "No such part"))
3754 (gnus-article-goto-part n)
3755 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3756 (funcall function handle))))
3758 (defun gnus-article-pipe-part (n)
3759 "Pipe MIME part N, which is the numerical prefix."
3761 (gnus-article-part-wrapper n 'mm-pipe-part))
3763 (defun gnus-article-save-part (n)
3764 "Save MIME part N, which is the numerical prefix."
3766 (gnus-article-part-wrapper n 'mm-save-part))
3768 (defun gnus-article-interactively-view-part (n)
3769 "View MIME part N interactively, which is the numerical prefix."
3771 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3773 (defun gnus-article-copy-part (n)
3774 "Copy MIME part N, which is the numerical prefix."
3776 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3778 (defun gnus-article-view-part-as-charset (n)
3779 "Copy MIME part N, which is the numerical prefix."
3781 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3783 (defun gnus-article-externalize-part (n)
3784 "View MIME part N externally, which is the numerical prefix."
3786 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3788 (defun gnus-article-inline-part (n)
3789 "Inline MIME part N, which is the numerical prefix."
3791 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3793 (defun gnus-article-mime-match-handle-first (condition)
3795 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3796 (while (setq ihandle (pop alist))
3798 ((functionp condition)
3799 (funcall condition (cdr ihandle)))
3800 ((eq condition 'undisplayed)
3801 (not (or (mm-handle-undisplayer (cdr ihandle))
3802 (equal (mm-handle-media-type (cdr ihandle))
3803 "multipart/alternative"))))
3804 ((eq condition 'undisplayed-alternative)
3805 (not (mm-handle-undisplayer (cdr ihandle))))
3807 (gnus-article-goto-part (car ihandle))
3808 (or (not n) (< (car ihandle) n)))
3809 (setq n (car ihandle))))
3813 (defun gnus-article-view-part (&optional n)
3814 "View MIME part N, which is the numerical prefix."
3816 (save-current-buffer
3817 (set-buffer gnus-article-buffer)
3818 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3819 gnus-article-mime-match-handle-function)))
3820 (when (> n (length gnus-article-mime-handle-alist))
3821 (error "No such part"))
3822 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3823 (when (gnus-article-goto-part n)
3824 (if (equal (car handle) "multipart/alternative")
3825 (gnus-article-press-button)
3826 (when (eq (gnus-mm-display-part handle) 'internal)
3827 (gnus-set-window-start)))))))
3829 (defsubst gnus-article-mime-total-parts ()
3830 (if (bufferp (car gnus-article-mime-handles))
3832 (1- (length gnus-article-mime-handles))))
3834 (defun gnus-mm-display-part (handle)
3835 "Display HANDLE and fix MIME button."
3836 (let ((id (get-text-property (point) 'gnus-part))
3841 (let ((window (selected-window))
3842 (mail-parse-charset gnus-newsgroup-charset)
3843 (mail-parse-ignored-charsets
3844 (save-excursion (set-buffer gnus-summary-buffer)
3845 gnus-newsgroup-ignored-charsets)))
3848 (let ((win (get-buffer-window (current-buffer) t))
3851 (select-window win))
3854 (if (mm-handle-displayed-p handle)
3855 ;; This will remove the part.
3856 (mm-display-part handle)
3858 (narrow-to-region (point) (1+ (point)))
3859 (mm-display-part handle)
3860 ;; We narrow to the part itself and
3861 ;; then call the treatment functions.
3862 (goto-char (point-min))
3864 (narrow-to-region (point) (point-max))
3867 (gnus-article-mime-total-parts)
3868 (mm-handle-media-type handle)))))
3869 (select-window window))))
3871 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3872 (gnus-insert-mime-button
3873 handle id (list (mm-handle-displayed-p handle)))
3874 (goto-char point))))
3876 (defun gnus-article-goto-part (n)
3877 "Go to MIME part N."
3878 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3880 (goto-char point))))
3882 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3883 (let ((gnus-tmp-name
3884 (or (mail-content-type-get (mm-handle-type handle)
3886 (mail-content-type-get (mm-handle-disposition handle)
3888 (mail-content-type-get (mm-handle-type handle)
3891 (gnus-tmp-type (mm-handle-media-type handle))
3892 (gnus-tmp-description
3893 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3896 (if (if displayed (car displayed)
3897 (mm-handle-displayed-p handle))
3899 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3901 gnus-tmp-type-long b e)
3902 (when (string-match ".*/" gnus-tmp-name)
3903 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3904 (setq gnus-tmp-type-long (concat gnus-tmp-type
3905 (and (not (equal gnus-tmp-name ""))
3906 (concat "; " gnus-tmp-name))))
3907 (or (equal gnus-tmp-description "")
3908 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3913 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3914 `(keymap ,gnus-mime-button-map
3915 ,@(if (>= (string-to-number emacs-version) 21)
3917 (list 'local-map gnus-mime-button-map))
3918 gnus-callback gnus-mm-display-part
3919 gnus-part ,gnus-tmp-id
3920 article-type annotation
3923 (widget-convert-button
3926 :action 'gnus-widget-press-button
3927 :button-keymap gnus-mime-button-map
3929 (lambda (widget/window &optional overlay pos)
3930 ;; Needed to properly clear the message due to a bug in
3931 ;; wid-edit (XEmacs only).
3932 (if (boundp 'help-echo-owns-message)
3933 (setq help-echo-owns-message t))
3935 "%S: %s the MIME part; %S: more options"
3936 (aref gnus-mouse-2 0)
3937 ;; XEmacs will get a single widget arg; Emacs 21 will get
3938 ;; window, overlay, position.
3939 (if (mm-handle-displayed-p
3941 (with-current-buffer (gnus-overlay-buffer overlay)
3942 (widget-get (widget-at (gnus-overlay-start overlay))
3944 (widget-get widget/window :mime-handle)))
3946 (aref gnus-down-mouse-3 0))))))
3948 (defun gnus-widget-press-button (elems el)
3949 (goto-char (widget-get elems :from))
3950 (gnus-article-press-button))
3952 (defvar gnus-displaying-mime nil)
3954 (defun gnus-display-mime (&optional ihandles)
3955 "Display the MIME parts."
3957 (save-selected-window
3958 (let ((window (get-buffer-window gnus-article-buffer))
3961 (select-window window)
3962 ;; We have to do this since selecting the window
3963 ;; may change the point. So we set the window point.
3964 (set-window-point window point)))
3965 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3966 buffer-read-only handle name type b e display)
3967 (when (and (not ihandles)
3968 (not gnus-displaying-mime))
3969 ;; Top-level call; we clean up.
3970 (when gnus-article-mime-handles
3971 (mm-destroy-parts gnus-article-mime-handles)
3972 (setq gnus-article-mime-handle-alist nil));; A trick.
3973 (setq gnus-article-mime-handles handles)
3974 ;; We allow users to glean info from the handles.
3975 (when gnus-article-mime-part-function
3976 (gnus-mime-part-function handles)))
3978 (or (not (stringp (car handles)))
3981 (when (and (not ihandles)
3982 (not gnus-displaying-mime))
3983 ;; Clean up for mime parts.
3985 (delete-region (point) (point-max)))
3986 (let ((gnus-displaying-mime t))
3987 (gnus-mime-display-part handles)))
3990 (narrow-to-region (point) (point-max))
3991 (gnus-treat-article nil 1 1)
3994 ;; Highlight the headers.
3998 (narrow-to-region (point-min) (point))
3999 (gnus-treat-article 'head))))))))
4001 (defvar gnus-mime-display-multipart-as-mixed nil)
4003 (defun gnus-mime-display-part (handle)
4006 ((not (stringp (car handle)))
4007 (gnus-mime-display-single handle))
4008 ;; User-defined multipart
4009 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4010 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4012 ;; multipart/alternative
4013 ((and (equal (car handle) "multipart/alternative")
4014 (not gnus-mime-display-multipart-as-mixed))
4015 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4016 (push (cons id handle) gnus-article-mime-handle-alist)
4017 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4018 ;; multipart/related
4019 ((and (equal (car handle) "multipart/related")
4020 (not gnus-mime-display-multipart-as-mixed))
4021 ;;;!!!We should find the start part, but we just default
4022 ;;;!!!to the first part.
4023 ;;(gnus-mime-display-part (cadr handle))
4024 ;;;!!! Most multipart/related is an HTML message plus images.
4025 ;;;!!! Unfortunately we are unable to let W3 display those
4026 ;;;!!! included images, so we just display it as a mixed multipart.
4027 (gnus-mime-display-mixed (cdr handle)))
4028 ((equal (car handle) "multipart/signed")
4029 (or (memq 'signed gnus-article-wash-types)
4030 (push 'signed gnus-article-wash-types))
4031 (gnus-mime-display-security handle))
4032 ((equal (car handle) "multipart/encrypted")
4033 (or (memq 'encrypted gnus-article-wash-types)
4034 (push 'encrypted gnus-article-wash-types))
4035 (gnus-mime-display-security handle))
4036 ;; Other multiparts are handled like multipart/mixed.
4038 (gnus-mime-display-mixed (cdr handle)))))
4040 (defun gnus-mime-part-function (handles)
4041 (if (stringp (car handles))
4042 (mapcar 'gnus-mime-part-function (cdr handles))
4043 (funcall gnus-article-mime-part-function handles)))
4045 (defun gnus-mime-display-mixed (handles)
4046 (mapcar 'gnus-mime-display-part handles))
4048 (defun gnus-mime-display-single (handle)
4049 (let ((type (mm-handle-media-type handle))
4050 (ignored gnus-ignored-mime-types)
4057 (when (string-match (pop ignored) type)
4058 (throw 'ignored nil)))
4059 (if (and (setq not-attachment
4060 (and (not (mm-inline-override-p handle))
4061 (or (not (mm-handle-disposition handle))
4062 (equal (car (mm-handle-disposition handle))
4064 (mm-attachment-override-p handle))))
4065 (mm-automatic-display-p handle)
4066 (or (mm-inlined-p handle)
4067 (mm-automatic-external-display-p type)))
4069 (when (equal (mm-handle-media-supertype handle) "text")
4071 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4073 (push (cons id handle) gnus-article-mime-handle-alist)
4074 (when (or (not display)
4075 (not (gnus-unbuttonized-mime-type-p type)))
4076 ;(gnus-article-insert-newline)
4077 (gnus-insert-mime-button
4078 handle id (list (or display (and not-attachment text))))
4079 (gnus-article-insert-newline)
4080 ;(gnus-article-insert-newline)
4081 ;; Remember modify the number of forward lines.
4089 (let ((mail-parse-charset gnus-newsgroup-charset)
4090 (mail-parse-ignored-charsets
4091 (save-excursion (condition-case ()
4092 (set-buffer gnus-summary-buffer)
4094 gnus-newsgroup-ignored-charsets)))
4095 (mm-display-part handle t))
4096 (goto-char (point-max)))
4097 ((and text not-attachment)
4101 (gnus-article-insert-newline)
4102 (mm-insert-inline handle (mm-get-part handle))
4103 (goto-char (point-max))))
4107 (narrow-to-region beg (point))
4110 (gnus-article-mime-total-parts)
4111 (mm-handle-media-type handle)))))))))
4113 (defun gnus-unbuttonized-mime-type-p (type)
4114 "Say whether TYPE is to be unbuttonized."
4115 (unless gnus-inhibit-mime-unbuttonizing
4117 (let ((types gnus-unbuttonized-mime-types))
4119 (when (string-match (pop types) type)
4120 (throw 'found t)))))))
4122 (defun gnus-article-insert-newline ()
4123 "Insert a newline, but mark it as undeletable."
4124 (gnus-put-text-property
4125 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4127 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4128 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4131 handle buffer-read-only from props begend not-pref)
4132 (save-window-excursion
4135 (narrow-to-region (car ibegend)
4138 (goto-char (car ibegend))
4141 (delete-region (point-min) (point-max))
4142 (mm-remove-parts handles))
4143 (setq begend (list (point-marker)))
4145 (unless (setq not-pref (cadr (member preferred ihandles)))
4146 (setq not-pref (car ihandles)))
4149 (not (gnus-unbuttonized-mime-type-p
4150 "multipart/alternative")))
4151 (gnus-add-text-properties
4154 (insert (format "%d. " id))
4158 (unless ,(not ibegend)
4159 (setq gnus-article-mime-handle-alist
4160 ',gnus-article-mime-handle-alist))
4161 (gnus-mime-display-alternative
4162 ',ihandles ',not-pref ',begend ,id))
4163 ,@(if (>= (string-to-number emacs-version) 21)
4164 nil ;; XEmacs doesn't care
4165 (list 'local-map gnus-mime-button-map))
4166 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4167 face ,gnus-article-button-face
4168 keymap ,gnus-mime-button-map
4171 (widget-convert-button 'link from (point)
4172 :action 'gnus-widget-press-button
4173 :button-keymap gnus-widget-button-keymap)
4175 (while (setq handle (pop handles))
4176 (gnus-add-text-properties
4179 (insert (format "(%c) %-18s"
4180 (if (equal handle preferred) ?* ? )
4181 (mm-handle-media-type handle)))
4185 (unless ,(not ibegend)
4186 (setq gnus-article-mime-handle-alist
4187 ',gnus-article-mime-handle-alist))
4188 (gnus-mime-display-alternative
4189 ',ihandles ',handle ',begend ,id))
4190 ,@(if (>= (string-to-number emacs-version) 21)
4191 nil ;; XEmacs doesn't care
4192 (list 'local-map gnus-mime-button-map))
4193 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4194 face ,gnus-article-button-face
4195 keymap ,gnus-mime-button-map
4198 (widget-convert-button 'link from (point)
4199 :action 'gnus-widget-press-button
4200 :button-keymap gnus-widget-button-keymap)
4204 (if (stringp (car preferred))
4205 (gnus-display-mime preferred)
4206 (let ((mail-parse-charset gnus-newsgroup-charset)
4207 (mail-parse-ignored-charsets
4208 (save-excursion (set-buffer gnus-summary-buffer)
4209 gnus-newsgroup-ignored-charsets)))
4210 (mm-display-part preferred)
4214 (narrow-to-region (car begend) (point-max))
4216 nil (length gnus-article-mime-handle-alist)
4217 (gnus-article-mime-total-parts)
4218 (mm-handle-media-type handle))))))
4219 (goto-char (point-max))
4220 (setcdr begend (point-marker)))))
4222 (goto-char point))))
4224 (defun gnus-article-wash-status ()
4225 "Return a string which display status of article washing."
4227 (set-buffer gnus-article-buffer)
4228 (let ((cite (memq 'cite gnus-article-wash-types))
4229 (headers (memq 'headers gnus-article-wash-types))
4230 (boring (memq 'boring-headers gnus-article-wash-types))
4231 (pgp (memq 'pgp gnus-article-wash-types))
4232 (pem (memq 'pem gnus-article-wash-types))
4233 (signed (memq 'signed gnus-article-wash-types))
4234 (encrypted (memq 'encrypted gnus-article-wash-types))
4235 (signature (memq 'signature gnus-article-wash-types))
4236 (overstrike (memq 'overstrike gnus-article-wash-types))
4237 (emphasis (memq 'emphasis gnus-article-wash-types)))
4238 (format "%c%c%c%c%c%c%c"
4240 (if (or headers boring) ?h ? )
4241 (if (or pgp pem signed encrypted) ?p ? )
4242 (if signature ?s ? )
4243 (if overstrike ?o ? )
4244 (if gnus-show-mime ?m ? )
4245 (if emphasis ?e ? )))))
4247 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4249 (defun gnus-article-maybe-hide-headers ()
4250 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4251 Provided for backwards compatibility."
4252 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4253 (not (save-excursion (set-buffer gnus-summary-buffer)
4254 gnus-have-all-headers)))
4255 (not gnus-inhibit-hiding))
4256 (gnus-article-hide-headers)))
4260 (defun gnus-output-to-file (file-name)
4261 "Append the current article to a file named FILE-NAME."
4262 (let ((artbuf (current-buffer)))
4264 (insert-buffer-substring artbuf)
4265 ;; Append newline at end of the buffer as separator, and then
4267 (goto-char (point-max))
4269 (write-region-as-binary (point-min) (point-max) file-name 'append)
4272 (defun gnus-narrow-to-page (&optional arg)
4273 "Narrow the article buffer to a page.
4274 If given a numerical ARG, move forward ARG pages."
4276 (setq arg (if arg (prefix-numeric-value arg) 0))
4278 (set-buffer gnus-article-buffer)
4279 (goto-char (point-min))
4281 ;; Remove any old next/prev buttons.
4282 (when (gnus-visual-p 'page-marker)
4283 (let ((buffer-read-only nil))
4284 (gnus-remove-text-with-property 'gnus-prev)
4285 (gnus-remove-text-with-property 'gnus-next)))
4288 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4290 (re-search-forward page-delimiter nil 'move arg)))
4291 (goto-char (match-end 0)))
4294 (if (re-search-forward page-delimiter nil 'move)
4297 (when (and (gnus-visual-p 'page-marker)
4298 (not (= (point-min) 1)))
4300 (goto-char (point-min))
4301 (gnus-insert-prev-page-button)))
4302 (when (and (gnus-visual-p 'page-marker)
4303 (< (+ (point-max) 2) (buffer-size)))
4305 (goto-char (point-max))
4306 (gnus-insert-next-page-button)))))
4308 ;; Article mode commands
4310 (defun gnus-article-goto-next-page ()
4311 "Show the next page of the article."
4313 (when (gnus-article-next-page)
4314 (goto-char (point-min))
4315 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4317 (defun gnus-article-goto-prev-page ()
4318 "Show the next page of the article."
4320 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4321 (gnus-article-prev-page nil)))
4323 (defun gnus-article-next-page (&optional lines)
4324 "Show the next page of the current article.
4325 If end of article, return non-nil. Otherwise return nil.
4326 Argument LINES specifies lines to be scrolled up."
4328 (let ((start (window-start))
4329 end-of-buffer end-of-page)
4331 (move-to-window-line -1)
4332 (if (<= (point) start)
4335 (setq start (point)))
4338 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4339 (and (pos-visible-in-window-p)
4340 (setq end-of-buffer t)))
4342 (setq end-of-page t)))
4344 (move-to-window-line lines)
4345 (unless (search-backward "\n\n" nil t)
4346 (setq start (point)))))
4347 (cond (end-of-buffer t)
4349 (gnus-narrow-to-page 1)
4353 (set-window-start (selected-window) start)
4354 (let (window-pixel-scroll-increment)
4358 (defun gnus-article-prev-page (&optional lines)
4359 "Show previous page of current article.
4360 Argument LINES specifies lines to be scrolled down."
4362 (let (beginning-of-buffer beginning-of-page)
4364 (move-to-window-line 0)
4365 (cond ((eq 1 (point))
4366 (setq beginning-of-buffer t))
4368 (setq beginning-of-page t))))
4369 (cond (beginning-of-buffer)
4371 (gnus-narrow-to-page -1))
4374 (let (window-pixel-scroll-increment)
4375 (scroll-down lines))
4376 (beginning-of-buffer
4377 (goto-char (point-min))))))))
4379 (defun gnus-article-refer-article ()
4380 "Read article specified by message-id around point."
4382 (let ((point (point)))
4383 (search-forward ">" nil t) ;Move point to end of "<....>".
4384 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4385 (let ((message-id (match-string 1)))
4387 (set-buffer gnus-summary-buffer)
4388 (gnus-summary-refer-article message-id))
4390 (error "No references around point"))))
4392 (defun gnus-article-show-summary ()
4393 "Reconfigure windows to show summary buffer."
4395 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4396 (error "There is no summary buffer for this article buffer")
4397 (gnus-article-set-globals)
4398 (gnus-configure-windows 'article)
4399 (gnus-summary-goto-subject gnus-current-article)
4400 (gnus-summary-position-point)))
4402 (defun gnus-article-describe-briefly ()
4403 "Describe article mode commands briefly."
4405 (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")))
4407 (defun gnus-article-summary-command ()
4408 "Execute the last keystroke in the summary buffer."
4410 (let ((obuf (current-buffer))
4411 (owin (current-window-configuration))
4413 (switch-to-buffer gnus-article-current-summary 'norecord)
4414 (setq func (lookup-key (current-local-map) (this-command-keys)))
4415 (call-interactively func)
4417 (set-window-configuration owin)
4418 (set-window-point (get-buffer-window (current-buffer)) (point))))
4420 (defun gnus-article-summary-command-nosave ()
4421 "Execute the last keystroke in the summary buffer."
4424 (pop-to-buffer gnus-article-current-summary 'norecord)
4425 (setq func (lookup-key (current-local-map) (this-command-keys)))
4426 (call-interactively func)))
4428 (defun gnus-article-check-buffer ()
4429 "Beep if not in an article buffer."
4430 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4431 (error "Command invoked outside of a Gnus article buffer")))
4433 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4434 "Read a summary buffer key sequence and execute it from the article buffer."
4436 (gnus-article-check-buffer)
4438 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4439 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4440 "=" "^" "\M-^" "|"))
4446 '("n" "Gn" "p" "Gp"))
4449 (set-buffer gnus-article-current-summary)
4450 (let (gnus-pick-mode)
4451 (push (or key last-command-event) unread-command-events)
4452 (setq keys (static-if (featurep 'xemacs)
4453 (events-to-keys (read-key-sequence nil))
4454 (read-key-sequence nil)))))
4457 (if (or (member keys nosaves)
4458 (member keys nosave-but-article)
4459 (member keys nosave-in-article))
4461 (save-window-excursion
4462 (pop-to-buffer gnus-article-current-summary 'norecord)
4463 ;; We disable the pick minor mode commands.
4464 (let (gnus-pick-mode)
4465 (setq func (lookup-key (current-local-map) keys))))
4469 (unless (member keys nosave-in-article)
4470 (set-buffer gnus-article-current-summary))
4471 (call-interactively func)
4472 (setq new-sum-point (point)))
4473 (when (member keys nosave-but-article)
4474 (pop-to-buffer gnus-article-buffer 'norecord)))
4475 ;; These commands should restore window configuration.
4476 (let ((obuf (current-buffer))
4477 (owin (current-window-configuration))
4479 (summary gnus-article-current-summary)
4480 func in-buffer selected)
4481 (if not-restore-window
4482 (pop-to-buffer summary 'norecord)
4483 (switch-to-buffer summary 'norecord))
4484 (setq in-buffer (current-buffer))
4485 ;; We disable the pick minor mode commands.
4486 (if (and (setq func (let (gnus-pick-mode)
4487 (lookup-key (current-local-map) keys)))
4490 (call-interactively func)
4491 (setq new-sum-point (point))
4492 (when (eq in-buffer (current-buffer))
4493 (setq selected (gnus-summary-select-article))
4495 (unless not-restore-window
4496 (set-window-configuration owin))
4497 (when (eq selected 'old)
4499 (set-window-start (get-buffer-window (current-buffer))
4501 (set-window-point (get-buffer-window (current-buffer))
4503 (let ((win (get-buffer-window gnus-article-current-summary)))
4505 (set-window-point win new-sum-point)))) )
4506 (switch-to-buffer gnus-article-buffer)
4509 (defun gnus-article-describe-key (key)
4510 "Display documentation of the function invoked by KEY. KEY is a string."
4511 (interactive "kDescribe key: ")
4512 (gnus-article-check-buffer)
4513 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4515 (set-buffer gnus-article-current-summary)
4516 (let (gnus-pick-mode)
4517 (push (elt key 0) unread-command-events)
4518 (setq key (if (featurep 'xemacs)
4519 (events-to-keys (read-key-sequence "Describe key: "))
4520 (read-key-sequence "Describe key: "))))
4522 (describe-key key)))
4524 (defun gnus-article-describe-key-briefly (key &optional insert)
4525 "Display documentation of the function invoked by KEY. KEY is a string."
4526 (interactive "kDescribe key: \nP")
4527 (gnus-article-check-buffer)
4528 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4530 (set-buffer gnus-article-current-summary)
4531 (let (gnus-pick-mode)
4532 (push (elt key 0) unread-command-events)
4533 (setq key (if (featurep 'xemacs)
4534 (events-to-keys (read-key-sequence "Describe key: "))
4535 (read-key-sequence "Describe key: "))))
4536 (describe-key-briefly key insert))
4537 (describe-key-briefly key insert)))
4539 (defun gnus-article-hide (&optional arg force)
4540 "Hide all the gruft in the current article.
4541 This means that PGP stuff, signatures, cited text and (some)
4542 headers will be hidden.
4543 If given a prefix, show the hidden text instead."
4544 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4545 (gnus-article-hide-headers arg)
4546 (gnus-article-hide-list-identifiers arg)
4547 (gnus-article-hide-pgp arg)
4548 (gnus-article-hide-citation-maybe arg force)
4549 (gnus-article-hide-signature arg))
4551 (defun gnus-article-maybe-highlight ()
4552 "Do some article highlighting if article highlighting is requested."
4553 (when (gnus-visual-p 'article-highlight 'highlight)
4554 (gnus-article-highlight-some)))
4556 (defun gnus-check-group-server ()
4557 ;; Make sure the connection to the server is alive.
4558 (unless (gnus-server-opened
4559 (gnus-find-method-for-group gnus-newsgroup-name))
4560 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4561 (gnus-request-group gnus-newsgroup-name t)))
4563 (defun gnus-request-article-this-buffer (article group)
4564 "Get an article and insert it into this buffer."
4565 (let (do-update-line sparse-header)
4569 (gnus-kill-all-overlays)
4570 (setq group (or group gnus-newsgroup-name))
4572 ;; Using `gnus-request-article' directly will insert the article into
4573 ;; `nntp-server-buffer' - so we'll save some time by not having to
4574 ;; copy it from the server buffer into the article buffer.
4576 ;; We only request an article by message-id when we do not have the
4577 ;; headers for it, so we'll have to get those.
4578 (when (stringp article)
4579 (gnus-read-header article))
4581 ;; If the article number is negative, that means that this article
4582 ;; doesn't belong in this newsgroup (possibly), so we find its
4583 ;; message-id and request it by id instead of number.
4584 (when (and (numberp article)
4586 (get-buffer gnus-summary-buffer)
4587 (gnus-buffer-exists-p gnus-summary-buffer))
4589 (set-buffer gnus-summary-buffer)
4590 (let ((header (gnus-summary-article-header article)))
4593 ((memq article gnus-newsgroup-sparse)
4594 ;; This is a sparse gap article.
4595 (setq do-update-line article)
4596 (setq article (mail-header-id header))
4597 (setq sparse-header (gnus-read-header article))
4598 (setq gnus-newsgroup-sparse
4599 (delq article gnus-newsgroup-sparse)))
4601 ;; It's a real article.
4602 (setq article (mail-header-id header)))
4604 ;; It is an extracted pseudo-article.
4605 (setq article 'pseudo)
4606 (gnus-request-pseudo-article header))))
4608 (let ((method (gnus-find-method-for-group
4609 gnus-newsgroup-name)))
4610 (when (and (eq (car method) 'nneething)
4612 (let ((dir (expand-file-name
4613 (mail-header-subject header)
4614 (file-name-as-directory
4615 (or (cadr (assq 'nneething-address method))
4617 (when (file-directory-p dir)
4618 (setq article 'nneething)
4619 (gnus-group-enter-directory dir))))))))
4622 ;; Refuse to select canceled articles.
4623 ((and (numberp article)
4625 (get-buffer gnus-summary-buffer)
4626 (gnus-buffer-exists-p gnus-summary-buffer)
4627 (eq (cdr (save-excursion
4628 (set-buffer gnus-summary-buffer)
4629 (assq article gnus-newsgroup-reads)))
4630 gnus-canceled-mark))
4632 ;; Check the backlog.
4633 ((and gnus-keep-backlog
4634 (gnus-backlog-request-article group article (current-buffer)))
4636 ;; Check asynchronous pre-fetch.
4637 ((gnus-async-request-fetched-article group article (current-buffer))
4638 (gnus-async-prefetch-next group article gnus-summary-buffer)
4639 (when (and (numberp article) gnus-keep-backlog)
4640 (gnus-backlog-enter-article group article (current-buffer)))
4643 ((and gnus-use-cache
4645 (gnus-cache-request-article article group))
4647 ;; Get the article and put into the article buffer.
4648 ((or (stringp article)
4650 (let ((gnus-override-method gnus-override-method)
4651 (methods (and (stringp article)
4652 gnus-refer-article-method))
4654 (buffer-read-only nil))
4655 (if (or (not (listp methods))
4656 (and (symbolp (car methods))
4657 (assq (car methods) nnoo-definition-alist)))
4658 (setq methods (list methods)))
4659 (when (and (null gnus-override-method)
4661 (setq gnus-override-method (pop methods)))
4663 (when (eq gnus-override-method 'current)
4664 (setq gnus-override-method gnus-current-select-method))
4666 (gnus-kill-all-overlays)
4667 (let ((gnus-newsgroup-name group))
4668 (gnus-check-group-server))
4669 (when (gnus-request-article article group (current-buffer))
4670 (when (numberp article)
4671 (gnus-async-prefetch-next group article
4672 gnus-summary-buffer)
4673 (when gnus-keep-backlog
4674 (gnus-backlog-enter-article
4675 group article (current-buffer))))
4676 (setq result 'article))
4679 (setq gnus-override-method (pop methods))
4680 (setq result 'done))))
4681 (and (eq result 'article) 'article)))
4685 ;; Associate this article with the current summary buffer.
4686 (setq gnus-article-current-summary gnus-summary-buffer)
4688 ;; Take the article from the original article buffer
4689 ;; and place it in the buffer it's supposed to be in.
4690 (when (and (get-buffer gnus-article-buffer)
4691 (equal (buffer-name (current-buffer))
4692 (buffer-name (get-buffer gnus-article-buffer))))
4694 (if (get-buffer gnus-original-article-buffer)
4695 (set-buffer gnus-original-article-buffer)
4696 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4697 (set-buffer-multibyte nil)
4698 (buffer-disable-undo)
4699 (setq major-mode 'gnus-original-article-mode)
4700 (setq buffer-read-only t))
4701 (let (buffer-read-only)
4703 (insert-buffer-substring gnus-article-buffer))
4704 (setq gnus-original-article (cons group article)))
4707 (run-hooks 'gnus-article-decode-hook)
4708 ;; Mark article as decoded or not.
4709 (setq gnus-article-decoded-p gnus-article-decode-hook))
4711 ;; Update sparse articles.
4712 (when (and do-update-line
4713 (or (numberp article)
4715 (let ((buf (current-buffer)))
4716 (set-buffer gnus-summary-buffer)
4717 (gnus-summary-update-article do-update-line sparse-header)
4718 (gnus-summary-goto-subject do-update-line nil t)
4719 (set-window-point (get-buffer-window (current-buffer) t)
4721 (set-buffer buf))))))
4727 (defcustom gnus-article-edit-mode-hook nil
4728 "Hook run in article edit mode buffers."
4729 :group 'gnus-article-various
4732 (defcustom gnus-article-edit-article-setup-function
4733 'gnus-article-mime-edit-article-setup
4734 "Function called to setup an editing article buffer."
4735 :group 'gnus-article-various
4738 (defvar gnus-article-edit-done-function nil)
4740 (defvar gnus-article-edit-mode-map nil)
4742 ;; Should we be using derived.el for this?
4743 (unless gnus-article-edit-mode-map
4744 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4745 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4747 (gnus-define-keys gnus-article-edit-mode-map
4748 "\C-c\C-c" gnus-article-edit-done
4749 "\C-c\C-k" gnus-article-edit-exit)
4751 (gnus-define-keys (gnus-article-edit-wash-map
4752 "\C-c\C-w" gnus-article-edit-mode-map)
4753 "f" gnus-article-edit-full-stops))
4755 (defun gnus-article-edit-mode ()
4756 "Major mode for editing articles.
4757 This is an extended text-mode.
4759 \\{gnus-article-edit-mode-map}"
4761 (setq major-mode 'gnus-article-edit-mode)
4762 (setq mode-name "Article Edit")
4763 (use-local-map gnus-article-edit-mode-map)
4764 (make-local-variable 'gnus-article-edit-done-function)
4765 (make-local-variable 'gnus-prev-winconf)
4766 (setq buffer-read-only nil)
4767 (buffer-enable-undo)
4769 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4771 (defun gnus-article-edit (&optional force)
4772 "Edit the current article.
4773 This will have permanent effect only in mail groups.
4774 If FORCE is non-nil, allow editing of articles even in read-only
4777 (when (and (not force)
4778 (gnus-group-read-only-p))
4779 (error "The current newsgroup does not support article editing"))
4780 (gnus-article-date-original)
4781 (gnus-article-edit-article
4783 `(lambda (no-highlight)
4785 (gnus-summary-edit-article-done
4786 ,(or (mail-header-references gnus-current-headers) "")
4787 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4789 (defun gnus-article-edit-article (start-func exit-func)
4790 "Start editing the contents of the current article buffer."
4791 (let ((winconf (current-window-configuration)))
4792 (set-buffer gnus-article-buffer)
4793 (gnus-article-edit-mode)
4794 (funcall start-func)
4795 (gnus-configure-windows 'edit-article)
4796 (setq gnus-article-edit-done-function exit-func)
4797 (setq gnus-prev-winconf winconf)
4798 (when gnus-article-edit-article-setup-function
4799 (funcall gnus-article-edit-article-setup-function))
4800 (gnus-message 6 "C-c C-c to end edits")))
4802 (defun gnus-article-edit-done (&optional arg)
4803 "Update the article edits and exit."
4805 (let ((func gnus-article-edit-done-function)
4806 (buf (current-buffer))
4807 (start (window-start)))
4808 (remove-hook 'gnus-article-mode-hook
4809 'gnus-article-mime-edit-article-unwind)
4810 (gnus-article-edit-exit)
4813 (let ((buffer-read-only nil))
4815 ;; The cache and backlog have to be flushed somewhat.
4816 (when gnus-keep-backlog
4817 (gnus-backlog-remove-article
4818 (car gnus-article-current) (cdr gnus-article-current)))
4819 ;; Flush original article as well.
4821 (when (get-buffer gnus-original-article-buffer)
4822 (set-buffer gnus-original-article-buffer)
4823 (setq gnus-original-article nil)))
4824 (when gnus-use-cache
4825 (gnus-cache-update-article
4826 (car gnus-article-current) (cdr gnus-article-current))))
4828 (set-window-start (get-buffer-window buf) start)
4829 (set-window-point (get-buffer-window buf) (point))))
4831 (defun gnus-article-edit-exit ()
4832 "Exit the article editing without updating."
4834 ;; We remove all text props from the article buffer.
4835 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4836 (curbuf (current-buffer))
4838 (window-start (window-start)))
4841 (let ((winconf gnus-prev-winconf))
4843 (set-window-configuration winconf)
4844 ;; Tippy-toe some to make sure that point remains where it was.
4845 (save-current-buffer
4847 (set-window-start (get-buffer-window (current-buffer)) window-start)
4850 (defun gnus-article-edit-full-stops ()
4851 "Interactively repair spacing at end of sentences."
4854 (goto-char (point-min))
4855 (search-forward-regexp "^$" nil t)
4856 (let ((case-fold-search nil))
4857 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4860 ;;; Article editing with MIME-Edit
4863 (defcustom gnus-article-mime-edit-article-setup-hook nil
4864 "Hook run after setting up a MIME editing article buffer."
4865 :group 'gnus-article-various
4868 (defun gnus-article-mime-edit-article-unwind ()
4869 "Unwind `gnus-article-buffer' if article editing was given up."
4870 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4871 (when mime-edit-mode-flag
4872 (mime-edit-exit 'nomime 'no-error)
4874 (when (featurep 'font-lock)
4875 (setq font-lock-defaults nil)
4876 (font-lock-mode 0)))
4878 (defun gnus-article-mime-edit-article-setup ()
4879 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4880 after replacing with the original article."
4881 (setq gnus-show-mime t)
4882 (setq gnus-article-edit-done-function
4883 `(lambda (&rest args)
4884 (when mime-edit-mode-flag
4887 (goto-char (point-min))
4888 (let (case-fold-search)
4889 (when (re-search-forward
4890 (format "^%s$" (regexp-quote mail-header-separator))
4892 (replace-match "")))
4893 (when (featurep 'font-lock)
4894 (setq font-lock-defaults nil)
4896 (apply ,gnus-article-edit-done-function args)
4897 (set-buffer gnus-original-article-buffer)
4899 (insert-buffer gnus-article-buffer)
4900 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4901 (gnus-article-prepare-display)))
4902 (substitute-key-definition
4903 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4904 gnus-article-edit-mode-map)
4906 (insert-buffer gnus-original-article-buffer)
4908 (when (featurep 'font-lock)
4909 (set (make-local-variable 'font-lock-defaults)
4910 '(message-font-lock-keywords t))
4911 (font-lock-set-defaults)
4912 (turn-on-font-lock))
4913 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4914 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4916 (defun gnus-article-mime-edit-exit ()
4917 "Exit the article MIME editing without updating."
4919 (let ((winconf gnus-prev-winconf)
4921 (when mime-edit-mode-flag
4924 (goto-char (point-min))
4925 (let (case-fold-search)
4926 (when (re-search-forward
4927 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4928 (replace-match "")))
4929 (when (featurep 'font-lock)
4930 (setq font-lock-defaults nil)
4932 ;; We remove all text props from the article buffer.
4933 (setq buf (format "%s" (buffer-string)))
4934 (set-buffer (get-buffer-create gnus-original-article-buffer))
4937 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4938 (gnus-article-prepare-display)
4939 (set-window-configuration winconf)))
4942 ;;; Article highlights
4945 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4947 ;;; Internal Variables:
4949 (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\\)\\)"
4950 "Regular expression that matches URLs."
4951 :group 'gnus-article-buttons
4954 (defcustom gnus-button-alist
4955 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4956 0 t gnus-button-message-id 2)
4957 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4958 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4960 gnus-button-fetch-group 4)
4961 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4962 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4963 t gnus-button-message-id 3)
4964 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4965 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4966 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4967 ;; This is how URLs _should_ be embedded in text...
4968 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4970 (,gnus-button-url-regexp 0 t browse-url 0))
4971 "*Alist of regexps matching buttons in article bodies.
4973 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4974 REGEXP: is the string matching text around the button,
4975 BUTTON: is the number of the regexp grouping actually matching the button,
4976 FORM: is a lisp expression which must eval to true for the button to
4978 CALLBACK: is the function to call when the user push this button, and each
4979 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4981 CALLBACK can also be a variable, in that case the value of that
4982 variable it the real callback function."
4983 :group 'gnus-article-buttons
4984 :type '(repeat (list regexp
4985 (integer :tag "Button")
4987 (function :tag "Callback")
4990 (integer :tag "Regexp group")))))
4992 (defcustom gnus-header-button-alist
4993 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4994 0 t gnus-button-message-id 0)
4995 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4996 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4997 0 t gnus-button-mailto 0)
4998 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4999 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5000 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5001 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5002 gnus-button-message-id 3))
5003 "*Alist of headers and regexps to match buttons in article heads.
5005 This alist is very similar to `gnus-button-alist', except that each
5006 alist has an additional HEADER element first in each entry:
5008 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5010 HEADER is a regexp to match a header. For a fuller explanation, see
5011 `gnus-button-alist'."
5012 :group 'gnus-article-buttons
5013 :group 'gnus-article-headers
5014 :type '(repeat (list (regexp :tag "Header")
5016 (integer :tag "Button")
5018 (function :tag "Callback")
5021 (integer :tag "Regexp group")))))
5023 (defvar gnus-button-regexp nil)
5024 (defvar gnus-button-marker-list nil)
5025 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5027 (defvar gnus-button-last nil)
5028 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5032 (defun gnus-article-push-button (event)
5033 "Check text under the mouse pointer for a callback function.
5034 If the text under the mouse pointer has a `gnus-callback' property,
5035 call it with the value of the `gnus-data' text property."
5037 (set-buffer (window-buffer (posn-window (event-start event))))
5038 (let* ((pos (posn-point (event-start event)))
5039 (data (get-text-property pos 'gnus-data))
5040 (fun (get-text-property pos 'gnus-callback)))
5043 (funcall fun data))))
5045 (defun gnus-article-press-button ()
5046 "Check text at point for a callback function.
5047 If the text at point has a `gnus-callback' property,
5048 call it with the value of the `gnus-data' text property."
5050 (let* ((data (get-text-property (point) 'gnus-data))
5051 (fun (get-text-property (point) 'gnus-callback)))
5053 (funcall fun data))))
5055 (defun gnus-article-prev-button (n)
5056 "Move point to N buttons backward.
5057 If N is negative, move forward instead."
5059 (gnus-article-next-button (- n)))
5061 (defun gnus-article-next-button (n)
5062 "Move point to N buttons forward.
5063 If N is negative, move backward instead."
5065 (let ((function (if (< n 0) 'previous-single-property-change
5066 'next-single-property-change))
5067 (inhibit-point-motion-hooks t)
5069 (limit (if (< n 0) (point-min) (point-max))))
5071 (while (and (not (= limit (point)))
5073 ;; Skip past the current button.
5074 (when (get-text-property (point) 'gnus-callback)
5075 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5076 ;; Go to the next (or previous) button.
5077 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5078 ;; Put point at the start of the button.
5079 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5080 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5081 ;; Skip past intangible buttons.
5082 (when (get-text-property (point) 'intangible)
5086 (gnus-message 5 "No more buttons"))
5089 (defun gnus-article-highlight (&optional force)
5090 "Highlight current article.
5091 This function calls `gnus-article-highlight-headers',
5092 `gnus-article-highlight-citation',
5093 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5094 do the highlighting. See the documentation for those functions."
5095 (interactive (list 'force))
5096 (gnus-article-highlight-headers)
5097 (gnus-article-highlight-citation force)
5098 (gnus-article-highlight-signature)
5099 (gnus-article-add-buttons force)
5100 (gnus-article-add-buttons-to-head))
5102 (defun gnus-article-highlight-some (&optional force)
5103 "Highlight current article.
5104 This function calls `gnus-article-highlight-headers',
5105 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5106 do the highlighting. See the documentation for those functions."
5107 (interactive (list 'force))
5108 (gnus-article-highlight-headers)
5109 (gnus-article-highlight-signature)
5110 (gnus-article-add-buttons))
5112 (defun gnus-article-highlight-headers ()
5113 "Highlight article headers as specified by `gnus-header-face-alist'."
5116 (set-buffer gnus-article-buffer)
5118 (let ((alist gnus-header-face-alist)
5119 (buffer-read-only nil)
5120 (case-fold-search t)
5121 (inhibit-point-motion-hooks t)
5122 entry regexp header-face field-face from hpoints fpoints)
5123 (article-narrow-to-head)
5124 (while (setq entry (pop alist))
5125 (goto-char (point-min))
5126 (setq regexp (concat "^\\("
5127 (if (string-equal "" (nth 0 entry))
5131 header-face (nth 1 entry)
5132 field-face (nth 2 entry))
5133 (while (and (re-search-forward regexp nil t)
5137 (unless (search-forward ":" nil t)
5139 (when (and header-face
5140 (not (memq (point) hpoints)))
5141 (push (point) hpoints)
5142 (gnus-put-text-property from (point) 'face header-face))
5143 (when (and field-face
5144 (not (memq (setq from (point)) fpoints)))
5146 (if (re-search-forward "^[^ \t]" nil t)
5148 (goto-char (point-max)))
5149 (gnus-put-text-property from (point) 'face field-face))))))))
5151 (defun gnus-article-highlight-signature ()
5152 "Highlight the signature in an article.
5153 It does this by highlighting everything after
5154 `gnus-signature-separator' using `gnus-signature-face'."
5156 (when gnus-signature-face
5158 (set-buffer gnus-article-buffer)
5159 (let ((buffer-read-only nil)
5160 (inhibit-point-motion-hooks t))
5162 (when (gnus-article-narrow-to-signature)
5163 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5164 'face gnus-signature-face)))))))
5166 (defun gnus-article-buttonize-signature ()
5167 "Add button to the signature."
5170 (set-buffer gnus-article-buffer)
5171 (let ((buffer-read-only nil)
5172 (inhibit-point-motion-hooks t))
5173 (when (gnus-article-search-signature)
5174 (gnus-article-add-button (match-beginning 0) (match-end 0)
5175 'gnus-signature-toggle
5176 (set-marker (make-marker)
5177 (1+ (match-end 0))))))))
5179 (defun gnus-button-in-region-p (b e prop)
5180 "Say whether PROP exists in the region."
5181 (text-property-not-all b e prop nil))
5183 (defun gnus-article-add-buttons (&optional force)
5184 "Find external references in the article and make buttons of them.
5185 \"External references\" are things like Message-IDs and URLs, as
5186 specified by `gnus-button-alist'."
5187 (interactive (list 'force))
5189 (set-buffer gnus-article-buffer)
5190 (let ((buffer-read-only nil)
5191 (inhibit-point-motion-hooks t)
5192 (case-fold-search t)
5193 (alist gnus-button-alist)
5195 ;; Remove all old markers.
5196 (let (marker entry new-list)
5197 (while (setq marker (pop gnus-button-marker-list))
5198 (if (or (< marker (point-min)) (>= marker (point-max)))
5199 (push marker new-list)
5201 (when (setq entry (gnus-button-entry))
5202 (put-text-property (match-beginning (nth 1 entry))
5203 (match-end (nth 1 entry))
5204 'gnus-callback nil))
5205 (set-marker marker nil)))
5206 (setq gnus-button-marker-list new-list))
5207 ;; We skip the headers.
5210 (while (setq entry (pop alist))
5211 (setq regexp (car entry))
5213 (while (re-search-forward regexp nil t)
5214 (let* ((start (and entry (match-beginning (nth 1 entry))))
5215 (end (and entry (match-end (nth 1 entry))))
5216 (from (match-beginning 0)))
5217 (when (and (or (eq t (nth 2 entry))
5218 (eval (nth 2 entry)))
5219 (not (gnus-button-in-region-p
5220 start end 'gnus-callback)))
5221 ;; That optional form returned non-nil, so we add the
5223 (gnus-article-add-button
5224 start end 'gnus-button-push
5225 (car (push (set-marker (make-marker) from)
5226 gnus-button-marker-list))))))))))
5228 ;; Add buttons to the head of an article.
5229 (defun gnus-article-add-buttons-to-head ()
5230 "Add buttons to the head of the article."
5233 (set-buffer gnus-article-buffer)
5235 (let ((buffer-read-only nil)
5236 (inhibit-point-motion-hooks t)
5237 (case-fold-search t)
5238 (alist gnus-header-button-alist)
5240 (article-narrow-to-head)
5242 ;; Each alist entry.
5243 (setq entry (car alist)
5245 (goto-char (point-min))
5246 (while (re-search-forward (car entry) nil t)
5247 ;; Each header matching the entry.
5248 (setq beg (match-beginning 0))
5249 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5250 (match-beginning 0))
5253 (while (re-search-forward (nth 1 entry) end t)
5254 ;; Each match within a header.
5255 (let* ((entry (cdr entry))
5256 (start (match-beginning (nth 1 entry)))
5257 (end (match-end (nth 1 entry)))
5258 (form (nth 2 entry)))
5259 (goto-char (match-end 0))
5261 (gnus-article-add-button
5262 start end (nth 3 entry)
5263 (buffer-substring (match-beginning (nth 4 entry))
5264 (match-end (nth 4 entry)))))))
5265 (goto-char end)))))))
5267 ;;; External functions:
5269 (defun gnus-article-add-button (from to fun &optional data)
5270 "Create a button between FROM and TO with callback FUN and data DATA."
5271 (when gnus-article-button-face
5272 (gnus-overlay-put (gnus-make-overlay from to)
5273 'face gnus-article-button-face))
5274 (gnus-add-text-properties
5276 (nconc (and gnus-article-mouse-face
5277 (list gnus-mouse-face-prop gnus-article-mouse-face))
5278 (list 'gnus-callback fun)
5279 (and data (list 'gnus-data data))))
5280 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5281 ;; Quote `:button-keymap' for Mule 2.3
5282 ;; but it won't work.
5283 ':button-keymap gnus-widget-button-keymap))
5285 ;;; Internal functions:
5287 (defun gnus-article-set-globals ()
5289 (set-buffer gnus-summary-buffer)
5290 (gnus-set-global-variables)))
5292 (defun gnus-signature-toggle (end)
5294 (set-buffer gnus-article-buffer)
5295 (let ((buffer-read-only nil)
5296 (inhibit-point-motion-hooks t)
5297 (limit (next-single-property-change end 'mime-view-entity
5299 (if (text-property-any end limit 'article-type 'signature)
5300 (gnus-remove-text-properties-when
5301 'article-type 'signature end limit
5302 (cons 'article-type (cons 'signature
5303 gnus-hidden-properties)))
5304 (gnus-add-text-properties-when
5305 'article-type nil end limit
5306 (cons 'article-type (cons 'signature
5307 gnus-hidden-properties)))))))
5309 (defun gnus-button-entry ()
5310 ;; Return the first entry in `gnus-button-alist' matching this place.
5311 (let ((alist gnus-button-alist)
5314 (setq entry (pop alist))
5315 (if (looking-at (car entry))
5320 (defun gnus-button-push (marker)
5321 ;; Push button starting at MARKER.
5324 (let* ((entry (gnus-button-entry))
5325 (inhibit-point-motion-hooks t)
5327 (args (mapcar (lambda (group)
5328 (let ((string (match-string group)))
5329 (gnus-set-text-properties
5330 0 (length string) nil string)
5337 (fboundp (symbol-value fun)))
5338 (apply (symbol-value fun) args))
5340 (gnus-message 1 "You must define `%S' to use this button"
5341 (cons fun args)))))))
5343 (defun gnus-button-message-id (message-id)
5346 (set-buffer gnus-summary-buffer)
5347 (gnus-summary-refer-article message-id)))
5349 (defun gnus-button-fetch-group (address)
5350 "Fetch GROUP specified by ADDRESS."
5351 (if (not (string-match "[:/]" address))
5352 ;; This is just a simple group url.
5353 (gnus-group-read-ephemeral-group address gnus-select-method)
5354 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5356 (error "Can't parse %s" address)
5357 (gnus-group-read-ephemeral-group
5358 (match-string 4 address)
5359 `(nntp ,(match-string 1 address)
5360 (nntp-address ,(match-string 1 address))
5361 (nntp-port-number ,(if (match-end 3)
5362 (match-string 3 address)
5365 (defun gnus-url-parse-query-string (query &optional downcase)
5366 (let (retval pairs cur key val)
5367 (setq pairs (split-string query "&"))
5369 (setq cur (car pairs)
5371 (if (not (string-match "=" cur))
5373 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5374 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5376 (setq key (downcase key)))
5377 (setq cur (assoc key retval))
5379 (setcdr cur (cons val (cdr cur)))
5380 (setq retval (cons (list key val) retval)))))
5383 (defun gnus-url-unhex (x)
5390 (defun gnus-url-unhex-string (str &optional allow-newlines)
5391 "Remove %XXX embedded spaces, etc in a url.
5392 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5393 decoding of carriage returns and line feeds in the string, which is normally
5394 forbidden in URL encoding."
5395 (setq str (or str ""))
5397 (case-fold-search t))
5398 (while (string-match "%[0-9a-f][0-9a-f]" str)
5399 (let* ((start (match-beginning 0))
5400 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5402 (gnus-url-unhex (elt str (+ start 2))))))
5404 tmp (substring str 0 start)
5407 (char-to-string code))
5408 ((or (= code ?\n) (= code ?\r))
5410 (t (char-to-string code))))
5411 str (substring str (match-end 0)))))
5412 (setq tmp (concat tmp str))
5415 (defun gnus-url-mailto (url)
5416 ;; Send mail to someone
5417 (when (string-match "mailto:/*\\(.*\\)" url)
5418 (setq url (substring url (match-beginning 1) nil)))
5419 (let (to args subject func)
5420 (if (string-match (regexp-quote "?") url)
5421 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5422 args (gnus-url-parse-query-string
5423 (substring url (match-end 0) nil) t))
5424 (setq to (gnus-url-unhex-string url)))
5425 (setq args (cons (list "to" to) args)
5426 subject (cdr-safe (assoc "subject" args)))
5427 (gnus-setup-message 'reply
5430 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5433 (message-position-on-field (caar args)))
5434 (insert (mapconcat 'identity (cdar args) ", "))
5435 (setq args (cdr args)))
5438 (message-goto-subject)))))
5440 (defun gnus-button-mailto (address)
5442 (set-buffer (gnus-copy-article-buffer))
5443 (message-reply address))
5445 (defalias 'gnus-button-reply 'message-reply)
5447 (defun gnus-button-embedded-url (address)
5448 "Activate ADDRESS with `browse-url'."
5449 (browse-url (gnus-strip-whitespace address)))
5451 (defun gnus-article-smiley-display ()
5452 "Display \"smileys\" as small graphical icons."
5453 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5455 ;;; Next/prev buttons in the article buffer.
5457 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5458 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5460 (defvar gnus-prev-page-map nil)
5461 (unless gnus-prev-page-map
5462 (setq gnus-prev-page-map (make-sparse-keymap))
5463 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5464 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5466 (static-if (featurep 'xemacs)
5467 (defun gnus-insert-prev-page-button ()
5468 (let ((buffer-read-only nil))
5470 gnus-prev-page-line-format nil
5471 `(gnus-prev t local-map ,gnus-prev-page-map
5472 gnus-callback gnus-article-button-prev-page
5473 article-type annotation))))
5474 (defun gnus-insert-prev-page-button ()
5475 (let ((buffer-read-only nil)
5476 (situation (get-text-property (point-min) 'mime-view-situation)))
5477 (set-keymap-parent gnus-prev-page-map (current-local-map))
5479 gnus-prev-page-line-format nil
5480 `(gnus-prev t local-map ,gnus-prev-page-map
5481 gnus-callback gnus-article-button-prev-page
5482 article-type annotation
5483 mime-view-situation ,situation))))
5486 (defvar gnus-next-page-map nil)
5487 (unless gnus-next-page-map
5488 (setq gnus-next-page-map (make-sparse-keymap))
5489 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5490 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5492 (defun gnus-button-next-page ()
5493 "Go to the next page."
5495 (let ((win (selected-window)))
5496 (select-window (get-buffer-window gnus-article-buffer t))
5497 (gnus-article-next-page)
5498 (select-window win)))
5500 (defun gnus-button-prev-page ()
5501 "Go to the prev page."
5503 (let ((win (selected-window)))
5504 (select-window (get-buffer-window gnus-article-buffer t))
5505 (gnus-article-prev-page)
5506 (select-window win)))
5508 (static-if (featurep 'xemacs)
5509 (defun gnus-insert-next-page-button ()
5510 (let ((buffer-read-only nil))
5511 (gnus-eval-format gnus-next-page-line-format nil
5513 t local-map ,gnus-next-page-map
5514 gnus-callback gnus-article-button-next-page
5515 article-type annotation))))
5516 (defun gnus-insert-next-page-button ()
5517 (let ((buffer-read-only nil)
5518 (situation (get-text-property (point-min) 'mime-view-situation)))
5519 (set-keymap-parent gnus-next-page-map (current-local-map))
5520 (gnus-eval-format gnus-next-page-line-format nil
5522 t local-map ,gnus-next-page-map
5523 gnus-callback gnus-article-button-next-page
5524 article-type annotation
5525 mime-view-situation ,situation))))
5528 (defun gnus-article-button-next-page (arg)
5529 "Go to the next page."
5531 (let ((win (selected-window)))
5532 (select-window (get-buffer-window gnus-article-buffer t))
5533 (gnus-article-next-page)
5534 (select-window win)))
5536 (defun gnus-article-button-prev-page (arg)
5537 "Go to the prev page."
5539 (let ((win (selected-window)))
5540 (select-window (get-buffer-window gnus-article-buffer t))
5541 (gnus-article-prev-page)
5542 (select-window win)))
5544 (defvar gnus-decode-header-methods
5545 '(mail-decode-encoded-word-region)
5546 "List of methods used to decode headers.
5548 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5549 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5550 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5551 whose names match REGEXP.
5554 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5555 mail-decode-encoded-word-region
5556 (\"chinese\" . rfc1843-decode-region))
5559 (defvar gnus-decode-header-methods-cache nil)
5561 (defun gnus-multi-decode-header (start end)
5562 "Apply the functions from `gnus-encoded-word-methods' that match."
5563 (unless (and gnus-decode-header-methods-cache
5564 (eq gnus-newsgroup-name
5565 (car gnus-decode-header-methods-cache)))
5566 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5569 (nconc gnus-decode-header-methods-cache (list x))
5570 (if (and gnus-newsgroup-name
5571 (string-match (car x) gnus-newsgroup-name))
5572 (nconc gnus-decode-header-methods-cache
5574 gnus-decode-header-methods))
5575 (let ((xlist gnus-decode-header-methods-cache))
5578 (narrow-to-region start end)
5580 (funcall (pop xlist) (point-min) (point-max))))))
5583 ;;; Treatment top-level handling.
5586 (defun gnus-treat-article (condition &optional part-number total-parts type)
5587 (let ((length (- (point-max) (point-min)))
5588 (alist gnus-treatment-function-alist)
5589 (article-goto-body-goes-to-point-min-p t)
5593 (let ((list gnus-article-treat-types))
5595 (when (string-match (pop list) type)
5596 (throw 'found t)))))))
5597 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5598 (entity (static-unless (featurep 'xemacs)
5599 (when (eq 'head condition)
5600 (get-text-property (point-min) 'mime-view-entity))))
5601 val elem buttonized)
5602 (gnus-run-hooks 'gnus-part-display-hook)
5603 (unless gnus-inhibit-treatment
5604 (while (setq elem (pop alist))
5607 (if (gnus-buffer-live-p gnus-summary-buffer)
5608 (set-buffer gnus-summary-buffer))
5609 (symbol-value (car elem))))
5610 (when (and (or (consp val)
5612 (gnus-treat-predicate val)
5613 (or (not (get (car elem) 'highlight))
5615 (when (and (not buttonized)
5617 '(gnus-treat-hide-signature
5618 gnus-treat-highlight-signature)))
5619 (gnus-article-buttonize-signature)
5620 (setq buttonized t))
5622 (funcall (cadr elem)))))
5623 ;; FSF Emacsen does not inherit the existing text properties
5624 ;; in the new text, so we should do it for `mime-view-entity'.
5625 (static-unless (featurep 'xemacs)
5627 (put-text-property (point-min) (point-max)
5628 'mime-view-entity entity))))))
5630 ;; Dynamic variables.
5632 (defvar part-number)
5633 (defvar total-parts)
5638 (defun gnus-treat-predicate (val)
5643 (stringp (car val)))
5644 (apply 'gnus-or (mapcar `(lambda (s)
5645 (string-match s ,(or gnus-newsgroup-name "")))
5648 (let ((pred (pop val)))
5651 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5653 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5655 (not (gnus-treat-predicate (car val))))
5657 (equal (car val) type))
5659 (error "%S is not a valid predicate" pred)))))
5669 (eq part-number total-parts))
5673 (error "%S is not a valid value" val))))
5675 (defun gnus-article-encrypt-body (protocol &optional n)
5676 "Encrypt the article body."
5679 (or gnus-article-encrypt-protocol
5680 (completing-read "Encrypt protocol: "
5681 gnus-article-encrypt-protocol-alist
5683 current-prefix-arg))
5684 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5686 (error (format "Can't find the encrypt protocol %s" protocol)))
5687 (if (equal gnus-newsgroup-name "nndraft:drafts")
5688 (error "Can't encrypt the article in group nndraft:drafts."))
5689 (if (equal gnus-newsgroup-name "nndraft:queue")
5690 (error "Don't encrypt the article in group nndraft:queue."))
5691 (gnus-summary-iterate n
5693 (set-buffer gnus-summary-buffer)
5694 (let ((mail-parse-charset gnus-newsgroup-charset)
5695 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5696 (summary-buffer gnus-summary-buffer)
5698 (gnus-set-global-variables)
5699 (when (gnus-group-read-only-p)
5700 (error "The current newsgroup does not support article encrypt"))
5701 (gnus-summary-show-article t)
5703 (or (mail-header-references gnus-current-headers) ""))
5704 (set-buffer gnus-article-buffer)
5705 (let* ((buffer-read-only nil)
5707 (mapcar (lambda (field)
5708 (and (save-restriction
5709 (message-narrow-to-head)
5710 (goto-char (point-min))
5711 (search-forward field nil t))
5713 (message-narrow-to-field)
5714 (buffer-substring (point-min) (point-max))
5715 (delete-region (point-min) (point-max))
5717 '("Content-Type:" "Content-Transfer-Encoding:"
5718 "Content-Disposition:"))))
5719 (message-narrow-to-head)
5720 (message-remove-header "MIME-Version")
5721 (goto-char (point-max))
5722 (setq point (point))
5723 (insert (apply 'concat headers))
5725 (narrow-to-region point (point-max))
5726 (let ((message-options message-options))
5727 (message-options-set 'message-sender user-mail-address)
5728 (message-options-set 'message-recipients user-mail-address)
5729 (message-options-set 'message-sign-encrypt 'not)
5731 (goto-char (point-min))
5732 (insert "MIME-Version: 1.0\n")
5734 (gnus-summary-edit-article-done
5735 references nil summary-buffer t))
5736 (when gnus-keep-backlog
5737 (gnus-backlog-remove-article
5738 (car gnus-article-current) (cdr gnus-article-current)))
5740 (when (get-buffer gnus-original-article-buffer)
5741 (set-buffer gnus-original-article-buffer)
5742 (setq gnus-original-article nil)))
5743 (when gnus-use-cache
5744 (gnus-cache-update-article
5745 (car gnus-article-current) (cdr gnus-article-current))))))))
5747 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5748 "The following specs can be used:
5749 %t The security MIME type
5752 %D Details if button is pressed")
5754 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5755 "The following specs can be used:
5756 %t The security MIME type
5759 %D Details if button is pressed")
5761 (defvar gnus-mime-security-button-line-format-alist
5762 '((?t gnus-tmp-type ?s)
5763 (?i gnus-tmp-info ?s)
5764 (?d gnus-tmp-details ?s)
5765 (?D gnus-tmp-pressed-details ?s)))
5767 (defvar gnus-mime-security-button-map
5768 (let ((map (make-sparse-keymap)))
5769 ;; Not for Emacs 21: fixme better.
5770 ;;(set-keymap-parent map gnus-article-mode-map)
5771 (define-key map gnus-mouse-2 'gnus-article-push-button)
5772 (define-key map "\r" 'gnus-article-press-button)
5775 (defvar gnus-mime-security-details-buffer nil)
5777 (defvar gnus-mime-security-button-pressed nil)
5779 (defvar gnus-mime-security-show-details-inline t
5780 "If non-nil, show details in the article buffer.")
5782 (defun gnus-mime-security-verify-or-decrypt (handle)
5783 (mm-remove-parts (cdr handle))
5784 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5787 (delete-region (car region) (cdr region))
5788 (set-marker (car region) nil)
5789 (set-marker (cdr region) nil)))
5790 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5791 (let* ((mm-verify-option 'known)
5792 (mm-decrypt-option 'known)
5793 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5794 (unless (eq nparts (cdr handle))
5795 (mm-destroy-parts (cdr handle))
5796 (setcdr handle nparts))))
5797 (let ((point (point))
5799 (gnus-mime-display-security handle)
5802 (defun gnus-mime-security-show-details (handle)
5803 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5805 (if gnus-mime-security-show-details-inline
5806 (let ((gnus-mime-security-button-pressed t)
5807 (gnus-mime-security-button-line-format
5808 (get-text-property (point) 'gnus-line-format))
5811 (while (eq (get-text-property (point) 'gnus-line-format)
5812 gnus-mime-security-button-line-format)
5815 (delete-region (point)
5816 (or (text-property-not-all
5819 gnus-mime-security-button-line-format)
5821 (gnus-insert-mime-security-button handle))
5822 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5823 (with-current-buffer gnus-mime-security-details-buffer
5826 (setq gnus-mime-security-details-buffer
5827 (gnus-get-buffer-create "*MIME Security Details*")))
5828 (with-current-buffer gnus-mime-security-details-buffer
5830 (goto-char (point-min)))
5831 (pop-to-buffer gnus-mime-security-details-buffer))
5832 (gnus-message 5 "No details."))))
5834 (defun gnus-mime-security-press-button (handle)
5835 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5836 (gnus-mime-security-show-details handle)
5837 (gnus-mime-security-verify-or-decrypt handle)))
5839 (defun gnus-insert-mime-security-button (handle &optional displayed)
5840 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5843 (or (nth 2 (assoc protocol mm-verify-function-alist))
5844 (nth 2 (assoc protocol mm-decrypt-function-alist))
5846 (if (equal (car handle) "multipart/signed")
5847 " Signed" " Encrypted")
5850 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5853 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5854 gnus-tmp-pressed-details
5856 (setq gnus-tmp-details
5857 (if gnus-tmp-details
5858 (concat "\n" gnus-tmp-details) ""))
5859 (setq gnus-tmp-pressed-details
5860 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5865 gnus-mime-security-button-line-format
5866 gnus-mime-security-button-line-format-alist
5867 `(keymap ,gnus-mime-security-button-map
5868 ,@(if (>= (string-to-number emacs-version) 21)
5869 nil ;; XEmacs doesn't care
5870 (list 'local-map gnus-mime-security-button-map))
5871 gnus-callback gnus-mime-security-press-button
5872 gnus-line-format ,gnus-mime-security-button-line-format
5873 article-type annotation
5876 (widget-convert-button
5879 :action 'gnus-widget-press-button
5880 :button-keymap gnus-mime-security-button-map
5882 (lambda (widget/window &optional overlay pos)
5883 ;; Needed to properly clear the message due to a bug in
5884 ;; wid-edit (XEmacs only).
5885 (if (boundp 'help-echo-owns-message)
5886 (setq help-echo-owns-message t))
5889 (aref gnus-mouse-2 0))))))
5891 (defun gnus-mime-display-security (handle)
5893 (narrow-to-region (point) (point))
5894 (gnus-insert-mime-security-button handle)
5895 (gnus-mime-display-mixed (cdr handle))
5898 (let ((gnus-mime-security-button-line-format
5899 gnus-mime-security-button-end-line-format))
5900 (gnus-insert-mime-security-button handle))
5901 (mm-set-handle-multipart-parameter handle 'gnus-region
5902 (cons (set-marker (make-marker)
5904 (set-marker (make-marker)
5911 (defun gnus-article-header-presentation-method (entity situation)
5912 (mime-insert-header entity)
5915 (set-alist 'mime-header-presentation-method-alist
5916 'gnus-original-article-mode
5917 #'gnus-article-header-presentation-method)
5919 (defun gnus-mime-preview-quitting-method ()
5920 (mime-preview-kill-buffer)
5921 (delete-other-windows)
5922 (gnus-article-show-summary)
5923 (gnus-summary-select-article gnus-show-all-headers t))
5925 (set-alist 'mime-preview-quitting-method-alist
5926 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5928 (set-alist 'mime-preview-following-method-alist
5929 'gnus-original-article-mode #'gnus-following-method)
5931 (set-alist 'mime-preview-over-to-previous-method-alist
5932 'gnus-original-article-mode
5934 (if (> (point-min) 1)
5935 (gnus-article-prev-page)
5936 (gnus-article-read-summary-keys
5937 nil (gnus-character-to-event ?P)))))
5939 (set-alist 'mime-preview-over-to-next-method-alist
5940 'gnus-original-article-mode'
5942 (if (< (point-max) (buffer-size))
5943 (gnus-article-next-page)
5944 (gnus-article-read-summary-keys
5945 nil (gnus-character-to-event ?N)))))
5955 (run-hooks 'gnus-art-load-hook)
5957 ;;; gnus-art.el ends here