1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'static))
43 ;; Avoid byte-compile warnings.
52 (autoload 'gnus-msg-mail "gnus-msg" nil t)
53 (autoload 'gnus-button-mailto "gnus-msg")
54 (autoload 'gnus-button-reply "gnus-msg" nil t)
56 (defgroup gnus-article nil
58 :link '(custom-manual "(gnus)The Article Buffer")
61 (defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
71 (defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
77 (defgroup gnus-article-signature nil
79 :link '(custom-manual "(gnus)Article Signature")
82 (defgroup gnus-article-headers nil
84 :link '(custom-manual "(gnus)Hiding Headers")
87 (defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
92 (defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
97 (defgroup gnus-article-saving nil
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
102 (defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
107 (defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
112 (defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
117 (defcustom gnus-ignored-headers
118 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
119 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
120 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
121 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
122 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
123 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
124 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
125 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
126 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
127 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
128 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
129 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
130 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
131 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
132 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
133 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
134 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
135 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
136 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
137 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
138 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
139 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
140 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
141 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
142 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
143 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
144 "^X-Received:" "^Content-length:" "X-precedence:"
145 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
146 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
148 "*All headers that start with this regexp will be hidden.
149 This variable can also be a list of regexps of headers to be ignored.
150 If `gnus-visible-headers' is non-nil, this variable will be ignored."
151 :type '(choice :custom-show nil
154 :group 'gnus-article-hiding)
156 (defcustom gnus-visible-headers
157 "^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:"
158 "*All headers that do not match this regexp will be hidden.
159 This variable can also be a list of regexp of headers to remain visible.
160 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
161 :type '(repeat :value-to-internal (lambda (widget value)
162 (custom-split-regexp-maybe value))
163 :match (lambda (widget value)
165 (widget-editable-list-match widget value)))
167 :group 'gnus-article-hiding)
169 (defcustom gnus-sorted-header-list
170 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
171 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
172 "*This variable is a list of regular expressions.
173 If it is non-nil, headers that match the regular expressions will
174 be placed first in the article buffer in the sequence specified by
176 :type '(repeat regexp)
177 :group 'gnus-article-hiding)
179 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
180 "Headers that are only to be displayed if they have interesting data.
181 Possible values in this list are:
183 'empty Headers with no content.
184 'newsgroups Newsgroup identical to Gnus group.
185 'to-address To identical to To-address.
186 'followup-to Followup-to identical to Newsgroups.
187 'reply-to Reply-to identical to From.
188 'date Date less than four days old.
189 'long-to To and/or Cc longer than 1024 characters.
190 'many-to Multiple To and/or Cc."
191 :type '(set (const :tag "Headers with no content." empty)
192 (const :tag "Newsgroups identical to Gnus group." newsgroups)
193 (const :tag "To identical to To-address." to-address)
194 (const :tag "Followup-to identical to Newsgroups." followup-to)
195 (const :tag "Reply-to identical to From." reply-to)
196 (const :tag "Date less than four days old." date)
197 (const :tag "To and/or Cc longer than 1024 characters." long-to)
198 (const :tag "Multiple To and/or Cc headers." many-to))
199 :group 'gnus-article-hiding)
201 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
202 "Regexp matching signature separator.
203 This can also be a list of regexps. In that case, it will be checked
204 from head to tail looking for a separator. Searches will be done from
205 the end of the buffer."
206 :type '(repeat string)
207 :group 'gnus-article-signature)
209 (defcustom gnus-signature-limit nil
210 "Provide a limit to what is considered a signature.
211 If it is a number, no signature may not be longer (in characters) than
212 that number. If it is a floating point number, no signature may be
213 longer (in lines) than that number. If it is a function, the function
214 will be called without any parameters, and if it returns nil, there is
215 no signature in the buffer. If it is a string, it will be used as a
216 regexp. If it matches, the text in question is not a signature."
217 :type '(choice (integer :value 200)
219 (function :value fun)
220 (regexp :value ".*"))
221 :group 'gnus-article-signature)
223 (defcustom gnus-hidden-properties '(invisible t intangible t)
224 "Property list to use for hiding text."
226 :group 'gnus-article-hiding)
228 ;; Fixme: This isn't the right thing for mixed graphical and and
229 ;; non-graphical frames in a session.
230 ;; gnus-xmas.el overrides this for XEmacs.
231 (defcustom gnus-article-x-face-command
233 ((and (fboundp 'image-type-available-p)
234 (module-installed-p 'x-face-e21))
235 'x-face-decode-message-header)
236 ((and (fboundp 'image-type-available-p)
237 (image-type-available-p 'xbm))
238 'gnus-article-display-xface)
239 ((and (not (featurep 'xemacs))
241 (module-installed-p 'x-face-mule))
242 'x-face-mule-gnus-article-display-x-face)
243 (gnus-article-compface-xbm
244 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -")
246 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
248 "*String or function to be executed to display an X-Face header.
249 If it is a string, the command will be executed in a sub-shell
250 asynchronously. The compressed face will be piped to this command."
251 :type '(choice string
253 :tag "x-face-decode-message-header (x-face-e21)"
254 x-face-decode-message-header)
255 (function-item gnus-article-display-xface)
256 (function-item x-face-mule-gnus-article-display-x-face)
259 :group 'gnus-article-washing)
261 (defcustom gnus-article-x-face-too-ugly nil
262 "Regexp matching posters whose face shouldn't be shown automatically."
263 :type '(choice regexp (const nil))
264 :group 'gnus-article-washing)
266 (defcustom gnus-article-banner-alist nil
267 "Banner alist for stripping.
269 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
271 :type '(repeat (cons symbol regexp))
272 :group 'gnus-article-washing)
274 (gnus-define-group-parameter
277 "Alist of regexps (to match group names) and banner."
278 :variable-group gnus-article-washing
280 '(choice :tag "Banner"
282 (const :tag "Remove signature" signature)
283 (symbol :tag "Item in `gnus-article-banner-alist'" none)
285 (const :tag "None" nil))
287 "If non-nil, specify how to remove `banners' from articles.
289 Symbol `signature' means to remove signatures delimited by
290 `gnus-signature-separator'. Any other symbol is used to look up a
291 regular expression to match the banner in `gnus-article-banner-alist'.
292 A string is used as a regular expression to match the banner
295 (defcustom gnus-emphasis-alist
297 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
299 '(("_" "_" underline)
302 ("_/" "/_" underline-italic)
303 ("_\\*" "\\*_" underline-bold)
304 ("\\*/" "/\\*" bold-italic)
305 ("_\\*/" "/\\*_" underline-bold-italic))))
306 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
307 2 3 gnus-emphasis-underline)
311 (format format (car spec) (car (cdr spec)))
312 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
314 "*Alist that says how to fontify certain phrases.
315 Each item looks like this:
317 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
319 The first element is a regular expression to be matched. The second
320 is a number that says what regular expression grouping used to find
321 the entire emphasized word. The third is a number that says what
322 regexp grouping should be displayed and highlighted. The fourth
323 is the face used for highlighting."
324 :type '(repeat (list :value ("" 0 0 default)
326 (integer :tag "Match group")
327 (integer :tag "Emphasize group")
329 :group 'gnus-article-emphasis)
331 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
332 "A regexp to describe whitespace which should not be emphasized.
333 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
334 The former avoids underlining of leading and trailing whitespace,
335 and the latter avoids underlining any whitespace at all."
337 :group 'gnus-article-emphasis
340 (defface gnus-emphasis-bold '((t (:bold t)))
341 "Face used for displaying strong emphasized text (*word*)."
342 :group 'gnus-article-emphasis)
344 (defface gnus-emphasis-italic '((t (:italic t)))
345 "Face used for displaying italic emphasized text (/word/)."
346 :group 'gnus-article-emphasis)
348 (defface gnus-emphasis-underline '((t (:underline t)))
349 "Face used for displaying underlined emphasized text (_word_)."
350 :group 'gnus-article-emphasis)
352 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
353 "Face used for displaying underlined bold emphasized text (_*word*_)."
354 :group 'gnus-article-emphasis)
356 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
357 "Face used for displaying underlined italic emphasized text (_/word/_)."
358 :group 'gnus-article-emphasis)
360 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
361 "Face used for displaying bold italic emphasized text (/*word*/)."
362 :group 'gnus-article-emphasis)
364 (defface gnus-emphasis-underline-bold-italic
365 '((t (:bold t :italic t :underline t)))
366 "Face used for displaying underlined bold italic emphasized text.
367 Esample: (_/*word*/_)."
368 :group 'gnus-article-emphasis)
370 (defface gnus-emphasis-highlight-words
371 '((t (:background "black" :foreground "yellow")))
372 "Face used for displaying highlighted words."
373 :group 'gnus-article-emphasis)
375 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
376 "Format for display of Date headers in article bodies.
377 See `format-time-string' for the possible values.
379 The variable can also be function, which should return a complete Date
380 header. The function is called with one argument, the time, which can
381 be fed to `format-time-string'."
382 :type '(choice string symbol)
383 :link '(custom-manual "(gnus)Article Date")
384 :group 'gnus-article-washing)
387 (autoload 'mail-extract-address-components "mail-extr"))
389 (defcustom gnus-save-all-headers t
390 "*If non-nil, don't remove any headers before saving."
391 :group 'gnus-article-saving
394 (defcustom gnus-prompt-before-saving 'always
395 "*This variable says how much prompting is to be done when saving articles.
396 If it is nil, no prompting will be done, and the articles will be
397 saved to the default files. If this variable is `always', each and
398 every article that is saved will be preceded by a prompt, even when
399 saving large batches of articles. If this variable is neither nil not
400 `always', there the user will be prompted once for a file name for
401 each invocation of the saving commands."
402 :group 'gnus-article-saving
403 :type '(choice (item always)
404 (item :tag "never" nil)
405 (sexp :tag "once" :format "%t\n" :value t)))
407 (defcustom gnus-saved-headers gnus-visible-headers
408 "Headers to keep if `gnus-save-all-headers' is nil.
409 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
410 If that variable is nil, however, all headers that match this regexp
411 will be kept while the rest will be deleted before saving."
412 :group 'gnus-article-saving
415 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
416 "A function to save articles in your favourite format.
417 The function must be interactively callable (in other words, it must
418 be an Emacs command).
420 Gnus provides the following functions:
422 * gnus-summary-save-in-rmail (Rmail format)
423 * gnus-summary-save-in-mail (Unix mail format)
424 * gnus-summary-save-in-folder (MH folder)
425 * gnus-summary-save-in-file (article format)
426 * gnus-summary-save-in-vm (use VM's folder format)
427 * gnus-summary-write-to-file (article format -- overwrite)."
428 :group 'gnus-article-saving
429 :type '(radio (function-item gnus-summary-save-in-rmail)
430 (function-item gnus-summary-save-in-mail)
431 (function-item gnus-summary-save-in-folder)
432 (function-item gnus-summary-save-in-file)
433 (function-item gnus-summary-save-in-vm)
434 (function-item gnus-summary-write-to-file)))
436 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
437 "A function generating a file name to save articles in Rmail format.
438 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
439 :group 'gnus-article-saving
442 (defcustom gnus-mail-save-name 'gnus-plain-save-name
443 "A function generating a file name to save articles in Unix mail format.
444 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
445 :group 'gnus-article-saving
448 (defcustom gnus-folder-save-name 'gnus-folder-save-name
449 "A function generating a file name to save articles in MH folder.
450 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
451 :group 'gnus-article-saving
454 (defcustom gnus-file-save-name 'gnus-numeric-save-name
455 "A function generating a file name to save articles in article format.
456 The function is called with NEWSGROUP, HEADERS, and optional
458 :group 'gnus-article-saving
461 (defcustom gnus-split-methods
462 '((gnus-article-archive-name)
463 (gnus-article-nndoc-name))
464 "*Variable used to suggest where articles are to be saved.
465 For instance, if you would like to save articles related to Gnus in
466 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
467 you could set this variable to something like:
469 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
470 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
472 This variable is an alist where the where the key is the match and the
473 value is a list of possible files to save in if the match is non-nil.
475 If the match is a string, it is used as a regexp match on the
476 article. If the match is a symbol, that symbol will be funcalled
477 from the buffer of the article to be saved with the newsgroup as the
478 parameter. If it is a list, it will be evaled in the same buffer.
480 If this form or function returns a string, this string will be used as
481 a possible file name; and if it returns a non-nil list, that list will
482 be used as possible file names."
483 :group 'gnus-article-saving
484 :type '(repeat (choice (list :value (fun) function)
485 (cons :value ("" "") regexp (repeat string))
488 (defcustom gnus-article-display-method-for-mime
489 'gnus-article-display-mime-message
490 "Function to display a MIME message.
491 The function is called from the article buffer."
492 :group 'gnus-article-mime
495 (defcustom gnus-article-display-method-for-traditional
496 'gnus-article-display-traditional-message
497 "*Function to display a traditional message.
498 The function is called from the article buffer."
499 :group 'gnus-article-mime
502 (defcustom gnus-page-delimiter "^\^L"
503 "*Regexp describing what to use as article page delimiters.
504 The default value is \"^\^L\", which is a form linefeed at the
505 beginning of a line."
507 :group 'gnus-article-various)
509 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
510 "*The format specification for the article mode line.
511 See `gnus-summary-mode-line-format' for a closer description.
513 The following additional specs are available:
515 %w The article washing status.
516 %m The number of MIME parts in the article."
518 :group 'gnus-article-various)
520 (defcustom gnus-article-mode-hook nil
521 "*A hook for Gnus article mode."
523 :group 'gnus-article-various)
525 (when (featurep 'xemacs)
526 ;; Extracted from gnus-xmas-define in order to preserve user settings
527 (when (fboundp 'turn-off-scroll-in-place)
528 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
529 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
530 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
532 (defcustom gnus-article-menu-hook nil
533 "*Hook run after the creation of the article mode menu."
535 :group 'gnus-article-various)
537 (defcustom gnus-article-prepare-hook nil
538 "*A hook called after an article has been prepared in the article buffer."
540 :group 'gnus-article-various)
542 (defcustom gnus-article-hide-pgp-hook nil
543 "*A hook called after successfully hiding a PGP signature."
545 :group 'gnus-article-various)
547 (defcustom gnus-article-button-face 'bold
548 "Face used for highlighting buttons in the article buffer.
550 An article button is a piece of text that you can activate by pressing
551 `RET' or `mouse-2' above it."
553 :group 'gnus-article-buttons)
555 (defcustom gnus-article-mouse-face 'highlight
556 "Face used for mouse highlighting in the article buffer.
558 Article buttons will be displayed in this face when the cursor is
561 :group 'gnus-article-buttons)
563 (defcustom gnus-signature-face 'gnus-signature-face
564 "Face used for highlighting a signature in the article buffer.
565 Obsolete; use the face `gnus-signature-face' for customizations instead."
567 :group 'gnus-article-highlight
568 :group 'gnus-article-signature)
570 (defface gnus-signature-face
573 "Face used for highlighting a signature in the article buffer."
574 :group 'gnus-article-highlight
575 :group 'gnus-article-signature)
577 (defface gnus-header-from-face
580 (:foreground "spring green"))
583 (:foreground "red3"))
586 "Face used for displaying from headers."
587 :group 'gnus-article-headers
588 :group 'gnus-article-highlight)
590 (defface gnus-header-subject-face
593 (:foreground "SeaGreen3"))
596 (:foreground "red4"))
598 (:bold t :italic t)))
599 "Face used for displaying subject headers."
600 :group 'gnus-article-headers
601 :group 'gnus-article-highlight)
603 (defface gnus-header-newsgroups-face
606 (:foreground "yellow" :italic t))
609 (:foreground "MidnightBlue" :italic t))
612 "Face used for displaying newsgroups headers."
613 :group 'gnus-article-headers
614 :group 'gnus-article-highlight)
616 (defface gnus-header-name-face
619 (:foreground "SeaGreen"))
622 (:foreground "maroon"))
625 "Face used for displaying header names."
626 :group 'gnus-article-headers
627 :group 'gnus-article-highlight)
629 (defface gnus-header-content-face
632 (:foreground "forest green" :italic t))
635 (:foreground "indianred4" :italic t))
638 "Face used for displaying header content."
639 :group 'gnus-article-headers
640 :group 'gnus-article-highlight)
642 (defcustom gnus-header-face-alist
643 '(("From" nil gnus-header-from-face)
644 ("Subject" nil gnus-header-subject-face)
645 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
646 ("" gnus-header-name-face gnus-header-content-face))
647 "*Controls highlighting of article header.
649 An alist of the form (HEADER NAME CONTENT).
651 HEADER is a regular expression which should match the name of an
652 header header and NAME and CONTENT are either face names or nil.
654 The name of each header field will be displayed using the face
655 specified by the first element in the list where HEADER match the
656 header name and NAME is non-nil. Similarly, the content will be
657 displayed by the first non-nil matching CONTENT face."
658 :group 'gnus-article-headers
659 :group 'gnus-article-highlight
660 :type '(repeat (list (regexp :tag "Header")
662 (item :tag "skip" nil)
663 (face :value default))
664 (choice :tag "Content"
665 (item :tag "skip" nil)
666 (face :value default)))))
668 (defcustom gnus-article-decode-hook nil
669 "*Hook run to decode charsets in articles."
670 :group 'gnus-article-headers
673 (defcustom gnus-display-mime-function 'gnus-display-mime
674 "Function to display MIME articles."
675 :group 'gnus-article-mime
678 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
679 "Function used to decode headers.")
681 (defvar gnus-article-dumbquotes-map
700 "Table for MS-to-Latin1 translation.")
702 (defcustom gnus-ignored-mime-types nil
703 "List of MIME types that should be ignored by Gnus."
705 :group 'gnus-article-mime
706 :type '(repeat regexp))
708 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
709 "List of MIME types that should not be given buttons when rendered inline."
711 :group 'gnus-article-mime
712 :type '(repeat regexp))
714 (defcustom gnus-article-mime-part-function nil
715 "Function called with a MIME handle as the argument.
716 This is meant for people who want to do something automatic based
717 on parts -- for instance, adding Vcard info to a database."
718 :group 'gnus-article-mime
721 (defcustom gnus-mime-multipart-functions nil
722 "An alist of MIME types to functions to display them."
724 :group 'gnus-article-mime
727 (defcustom gnus-article-date-lapsed-new-header nil
728 "Whether the X-Sent and Date headers can coexist.
729 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
730 either replace the old \"Date:\" header (if this variable is nil), or
731 be added below it (otherwise)."
733 :group 'gnus-article-headers
736 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
737 "Function called with a MIME handle as the argument.
738 This is meant for people who want to view first matched part.
739 For `undisplayed-alternative' (default), the first undisplayed
740 part or alternative part is used. For `undisplayed', the first
741 undisplayed part is used. For a function, the first part which
742 the function return `t' is used. For `nil', the first part is
745 :group 'gnus-article-mime
747 (item :tag "first" :value nil)
748 (item :tag "undisplayed" :value undisplayed)
749 (item :tag "undisplayed or alternative"
750 :value undisplayed-alternative)
753 (defcustom gnus-mime-action-alist
754 '(("save to file" . gnus-mime-save-part)
755 ("save and strip" . gnus-mime-save-part-and-strip)
756 ("display as text" . gnus-mime-inline-part)
757 ("view the part" . gnus-mime-view-part)
758 ("pipe to command" . gnus-mime-pipe-part)
759 ("toggle display" . gnus-article-press-button)
760 ("toggle display" . gnus-article-view-part-as-charset)
761 ("view as type" . gnus-mime-view-part-as-type)
762 ("internalize type" . gnus-mime-internalize-part)
763 ("externalize type" . gnus-mime-externalize-part))
764 "An alist of actions that run on the MIME attachment."
765 :group 'gnus-article-mime
766 :type '(repeat (cons (string :tag "name")
769 (defcustom gnus-mime-action-alist
770 '(("save to file" . gnus-mime-save-part)
771 ("display as text" . gnus-mime-inline-part)
772 ("view the part" . gnus-mime-view-part)
773 ("pipe to command" . gnus-mime-pipe-part)
774 ("toggle display" . gnus-article-press-button)
775 ("view as type" . gnus-mime-view-part-as-type)
776 ("internalize type" . gnus-mime-internalize-part)
777 ("externalize type" . gnus-mime-externalize-part))
778 "An alist of actions that run on the MIME attachment."
780 :group 'gnus-article-mime
781 :type '(repeat (cons (string :tag "name")
785 ;;; The treatment variables
788 (defvar gnus-part-display-hook nil
789 "Hook called on parts that are to receive treatment.")
791 (defvar gnus-article-treat-custom
792 '(choice (const :tag "Off" nil)
794 (const :tag "Header" head)
795 (const :tag "Last" last)
796 (const :tag "Mime" mime)
797 (integer :tag "Less")
798 (repeat :tag "Groups" regexp)
799 (sexp :tag "Predicate")))
801 (defvar gnus-article-treat-head-custom
802 '(choice (const :tag "Off" nil)
803 (const :tag "Header" head)))
805 (defvar gnus-article-treat-types '("text/plain")
808 (defvar gnus-inhibit-treatment nil
809 "Whether to inhibit treatment.")
811 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
812 "Highlight the signature.
813 Valid values are nil, t, `head', `last', an integer or a predicate.
814 See the manual for details."
815 :group 'gnus-article-treat
816 :type gnus-article-treat-custom)
817 (put 'gnus-treat-highlight-signature 'highlight t)
819 (defcustom gnus-treat-buttonize 100000
821 Valid values are nil, t, `head', `last', an integer or a predicate.
822 See the manual for details."
823 :group 'gnus-article-treat
824 :type gnus-article-treat-custom)
825 (put 'gnus-treat-buttonize 'highlight t)
827 (defcustom gnus-treat-buttonize-head 'head
828 "Add buttons to the head.
829 Valid values are nil, t, `head', `last', an integer or a predicate.
830 See the manual for details."
831 :group 'gnus-article-treat
832 :type gnus-article-treat-head-custom)
833 (put 'gnus-treat-buttonize-head 'highlight t)
835 (defcustom gnus-treat-emphasize
836 (and (or window-system
838 (>= (string-to-number emacs-version) 21))
841 Valid values are nil, t, `head', `last', an integer or a predicate.
842 See the manual for details."
843 :group 'gnus-article-treat
844 :type gnus-article-treat-custom)
845 (put 'gnus-treat-emphasize 'highlight t)
847 (defcustom gnus-treat-strip-cr nil
848 "Remove carriage returns.
849 Valid values are nil, t, `head', `last', an integer or a predicate.
850 See the manual for details."
851 :group 'gnus-article-treat
852 :type gnus-article-treat-custom)
854 (defcustom gnus-treat-leading-whitespace nil
855 "Remove leading whitespace in headers.
856 Valid values are nil, t, `head', `last', an integer or a predicate.
857 See the manual for details."
858 :group 'gnus-article-treat
859 :type gnus-article-treat-custom)
861 (defcustom gnus-treat-hide-headers 'head
863 Valid values are nil, t, `head', `last', an integer or a predicate.
864 See the manual for details."
865 :group 'gnus-article-treat
866 :type gnus-article-treat-head-custom)
868 (defcustom gnus-treat-hide-boring-headers nil
869 "Hide boring headers.
870 Valid values are nil, t, `head', `last', an integer or a predicate.
871 See the manual for details."
872 :group 'gnus-article-treat
873 :type gnus-article-treat-head-custom)
875 (defcustom gnus-treat-hide-signature nil
877 Valid values are nil, t, `head', `last', an integer or a predicate.
878 See the manual for details."
879 :group 'gnus-article-treat
880 :type gnus-article-treat-custom)
882 (defcustom gnus-treat-fill-article nil
884 Valid values are nil, t, `head', `last', an integer or a predicate.
885 See the manual for details."
886 :group 'gnus-article-treat
887 :type gnus-article-treat-custom)
889 (defcustom gnus-treat-hide-citation nil
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893 :group 'gnus-article-treat
894 :type gnus-article-treat-custom)
896 (defcustom gnus-treat-hide-citation-maybe nil
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-custom)
903 (defcustom gnus-treat-hide-citation-maybe nil
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See the manual for details."
907 :group 'gnus-article-treat
908 :type gnus-article-treat-custom)
910 (defcustom gnus-treat-strip-list-identifiers 'head
911 "Strip list identifiers from `gnus-list-identifiers`.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
915 :group 'gnus-article-treat
916 :type gnus-article-treat-custom)
918 (defcustom gnus-treat-strip-pgp t
919 "Strip PGP signatures.
920 Valid values are nil, t, `head', `last', an integer or a predicate.
921 See the manual for details."
922 :group 'gnus-article-treat
923 :type gnus-article-treat-custom)
925 (defcustom gnus-treat-strip-pem nil
926 "Strip PEM signatures.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See the manual for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-custom)
932 (defcustom gnus-treat-strip-banner t
933 "Strip banners from articles.
934 The banner to be stripped is specified in the `banner' group parameter.
935 Valid values are nil, t, `head', `last', an integer or a predicate.
936 See the manual for details."
937 :group 'gnus-article-treat
938 :type gnus-article-treat-custom)
940 (defcustom gnus-treat-highlight-headers 'head
941 "Highlight the headers.
942 Valid values are nil, t, `head', `last', an integer or a predicate.
943 See the manual for details."
944 :group 'gnus-article-treat
945 :type gnus-article-treat-head-custom)
946 (put 'gnus-treat-highlight-headers 'highlight t)
948 (defcustom gnus-treat-highlight-citation t
949 "Highlight cited text.
950 Valid values are nil, t, `head', `last', an integer or a predicate.
951 See the manual for details."
952 :group 'gnus-article-treat
953 :type gnus-article-treat-custom)
954 (put 'gnus-treat-highlight-citation 'highlight t)
956 (defcustom gnus-treat-date-ut nil
957 "Display the Date in UT (GMT).
958 Valid values are nil, t, `head', `last', an integer or a predicate.
959 See the manual for details."
960 :group 'gnus-article-treat
961 :type gnus-article-treat-head-custom)
963 (defcustom gnus-treat-date-local nil
964 "Display the Date in the local timezone.
965 Valid values are nil, t, `head', `last', an integer or a predicate.
966 See the manual for details."
967 :group 'gnus-article-treat
968 :type gnus-article-treat-head-custom)
970 (defcustom gnus-treat-date-english nil
971 "Display the Date in a format that can be read aloud in English.
972 Valid values are nil, t, `head', `last', an integer or a predicate.
973 See the manual for details."
974 :group 'gnus-article-treat
975 :type gnus-article-treat-head-custom)
977 (defcustom gnus-treat-date-lapsed nil
978 "Display the Date header in a way that says how much time has elapsed.
979 Valid values are nil, t, `head', `last', an integer or a predicate.
980 See the manual for details."
981 :group 'gnus-article-treat
982 :type gnus-article-treat-head-custom)
984 (defcustom gnus-treat-date-original nil
985 "Display the date in the original timezone.
986 Valid values are nil, t, `head', `last', an integer or a predicate.
987 See the manual for details."
988 :group 'gnus-article-treat
989 :type gnus-article-treat-head-custom)
991 (defcustom gnus-treat-date-iso8601 nil
992 "Display the date in the ISO8601 format.
993 Valid values are nil, t, `head', `last', an integer or a predicate.
994 See the manual for details."
996 :group 'gnus-article-treat
997 :type gnus-article-treat-head-custom)
999 (defcustom gnus-treat-date-user-defined nil
1000 "Display the date in a user-defined format.
1001 The format is defined by the `gnus-article-time-format' variable.
1002 Valid values are nil, t, `head', `last', an integer or a predicate.
1003 See the manual for details."
1004 :group 'gnus-article-treat
1005 :type gnus-article-treat-head-custom)
1007 (defcustom gnus-treat-strip-headers-in-body t
1008 "Strip the X-No-Archive header line from the beginning of the body.
1009 Valid values are nil, t, `head', `last', an integer or a predicate.
1010 See the manual for details."
1012 :group 'gnus-article-treat
1013 :type gnus-article-treat-custom)
1015 (defcustom gnus-treat-strip-trailing-blank-lines nil
1016 "Strip trailing blank lines.
1017 Valid values are nil, t, `head', `last', an integer or a predicate.
1018 See the manual for details."
1019 :group 'gnus-article-treat
1020 :type gnus-article-treat-custom)
1022 (defcustom gnus-treat-strip-leading-blank-lines nil
1023 "Strip leading blank lines.
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-custom)
1029 (defcustom gnus-treat-strip-multiple-blank-lines nil
1030 "Strip multiple blank lines.
1031 Valid values are nil, t, `head', `last', an integer or a predicate.
1032 See the manual for details."
1033 :group 'gnus-article-treat
1034 :type gnus-article-treat-custom)
1036 (defcustom gnus-treat-overstrike t
1037 "Treat overstrike highlighting.
1038 Valid values are nil, t, `head', `last', an integer or a predicate.
1039 See the manual for details."
1040 :group 'gnus-article-treat
1041 :type gnus-article-treat-custom)
1042 (put 'gnus-treat-overstrike 'highlight t)
1044 (defcustom gnus-treat-display-xface
1045 (and (or (and (fboundp 'image-type-available-p)
1046 (image-type-available-p 'xbm)
1047 (string-match "^0x" (shell-command-to-string "uncompface")))
1048 (and (featurep 'xemacs) (featurep 'xface))
1049 (eq 'x-face-mule-gnus-article-display-x-face
1050 gnus-article-x-face-command))
1052 "Display X-Face headers.
1053 Valid values are nil, t, `head', `last', an integer or a predicate.
1054 See the manual for details."
1055 :group 'gnus-article-treat
1057 :type gnus-article-treat-head-custom)
1058 (put 'gnus-treat-display-xface 'highlight t)
1060 (defcustom gnus-treat-display-smileys
1061 (if (or (and (featurep 'xemacs)
1063 (and (fboundp 'image-type-available-p)
1064 (image-type-available-p 'pbm))
1065 (and (not (featurep 'xemacs))
1067 (module-installed-p 'smiley-mule)))
1071 Valid values are nil, t, `head', `last', an integer or a predicate.
1072 See the manual for details."
1073 :group 'gnus-article-treat
1075 :type gnus-article-treat-custom)
1076 (put 'gnus-treat-display-smileys 'highlight t)
1078 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1080 Valid values are nil, t, `head', `last', an integer or a predicate.
1081 See the manual for details."
1082 :group 'gnus-article-treat
1083 :type gnus-article-treat-head-custom)
1084 (put 'gnus-treat-display-picons 'highlight t)
1086 (defcustom gnus-treat-capitalize-sentences nil
1087 "Capitalize sentence-starting words.
1088 Valid values are nil, t, `head', `last', an integer or a predicate.
1089 See the manual for details."
1091 :group 'gnus-article-treat
1092 :type gnus-article-treat-custom)
1094 (defcustom gnus-treat-fill-long-lines nil
1096 Valid values are nil, t, `head', `last', an integer or a predicate.
1097 See the manual for details."
1098 :group 'gnus-article-treat
1099 :type gnus-article-treat-custom)
1101 (defcustom gnus-treat-play-sounds nil
1103 Valid values are nil, t, `head', `last', an integer or a predicate.
1104 See the manual for details."
1106 :group 'gnus-article-treat
1107 :type gnus-article-treat-custom)
1109 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1110 "Decode an article as `default-mime-charset'. For instance, if you want to
1111 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1112 you could set this variable to something like: nil for don't decode, t for
1113 decode the body, '(or header t) for the whole article, etc."
1114 :group 'gnus-article-treat
1115 :type '(radio (const :tag "Off" nil)
1116 (const :tag "Decode body" t)
1117 (const :tag "Decode all" (or head t))))
1119 (defcustom gnus-treat-translate nil
1120 "Translate articles from one language to another.
1121 Valid values are nil, t, `head', `last', an integer or a predicate.
1122 See the manual for details."
1124 :group 'gnus-article-treat
1125 :type gnus-article-treat-custom)
1127 (defcustom gnus-treat-x-pgp-sig nil
1129 To automatically treat X-PGP-Sig, set it to head.
1130 Valid values are nil, t, `head', `last', an integer or a predicate.
1131 See the manual for details."
1132 :group 'gnus-article-treat
1133 :group 'mime-security
1134 :type gnus-article-treat-custom)
1136 (defvar gnus-article-encrypt-protocol-alist
1137 '(("PGP" . mml2015-self-encrypt)))
1139 ;; Set to nil if more than one protocol added to
1140 ;; gnus-article-encrypt-protocol-alist.
1141 (defcustom gnus-article-encrypt-protocol "PGP"
1142 "The protocol used for encrypt articles.
1143 It is a string, such as \"PGP\". If nil, ask user."
1145 :group 'mime-security)
1147 ;;; Internal variables
1149 (defvar gnus-english-month-names
1150 '("January" "February" "March" "April" "May" "June" "July" "August"
1151 "September" "October" "November" "December"))
1153 (defvar article-goto-body-goes-to-point-min-p nil)
1154 (defvar gnus-article-wash-types nil)
1155 (defvar gnus-article-emphasis-alist nil)
1157 (defvar gnus-article-mime-handle-alist-1 nil)
1158 (defvar gnus-treatment-function-alist
1159 `((gnus-treat-decode-article-as-default-mime-charset
1160 gnus-article-decode-article-as-default-mime-charset)
1161 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1162 (gnus-treat-strip-banner gnus-article-strip-banner)
1163 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1164 (gnus-treat-buttonize gnus-article-add-buttons)
1165 (gnus-treat-fill-article gnus-article-fill-cited-article)
1166 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1167 (gnus-treat-strip-cr gnus-article-remove-cr)
1168 (gnus-treat-display-xface gnus-article-display-x-face)
1169 (gnus-treat-date-ut gnus-article-date-ut)
1170 (gnus-treat-date-local gnus-article-date-local)
1171 (gnus-treat-date-english gnus-article-date-english)
1172 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1173 (gnus-treat-date-original gnus-article-date-original)
1174 (gnus-treat-date-user-defined gnus-article-date-user)
1175 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1176 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1177 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1178 (gnus-treat-hide-signature gnus-article-hide-signature)
1179 (gnus-treat-hide-citation gnus-article-hide-citation)
1180 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1181 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1182 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1183 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1184 (gnus-treat-strip-pem gnus-article-hide-pem)
1185 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1186 (gnus-treat-emphasize gnus-article-emphasize)
1187 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1188 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1189 (gnus-treat-strip-trailing-blank-lines
1190 gnus-article-remove-trailing-blank-lines)
1191 (gnus-treat-strip-leading-blank-lines
1192 gnus-article-strip-leading-blank-lines)
1193 (gnus-treat-strip-multiple-blank-lines
1194 gnus-article-strip-multiple-blank-lines)
1195 (gnus-treat-overstrike gnus-article-treat-overstrike)
1196 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1197 (gnus-treat-display-smileys ,(if (or (featurep 'xemacs)
1198 (>= emacs-major-version 21))
1199 'gnus-smiley-display
1200 'gnus-article-smiley-display))
1201 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1202 (gnus-treat-display-picons gnus-article-display-picons)
1203 (gnus-treat-play-sounds gnus-earcon-display)))
1205 (defvar gnus-article-mime-handle-alist nil)
1206 (defvar article-lapsed-timer nil)
1207 (defvar gnus-article-current-summary nil)
1209 (defvar gnus-article-mode-syntax-table
1210 (let ((table (copy-syntax-table text-mode-syntax-table)))
1211 ;; This causes the citation match run O(2^n).
1212 ;; (modify-syntax-entry ?- "w" table)
1213 (modify-syntax-entry ?> ")" table)
1214 (modify-syntax-entry ?< "(" table)
1216 "Syntax table used in article mode buffers.
1217 Initialized from `text-mode-syntax-table.")
1219 (defvar gnus-save-article-buffer nil)
1221 (defvar gnus-article-mode-line-format-alist
1222 (nconc '((?w (gnus-article-wash-status) ?s)
1223 (?m (gnus-article-mime-part-status) ?s))
1224 gnus-summary-mode-line-format-alist))
1226 (defvar gnus-number-of-articles-to-be-saved nil)
1228 (defvar gnus-inhibit-hiding nil)
1230 (defsubst gnus-article-hide-text (b e props)
1231 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1232 (gnus-add-text-properties-when 'article-type nil b e props)
1233 (when (memq 'intangible props)
1235 (max (1- b) (point-min))
1236 b 'intangible (cddr (memq 'intangible props)))))
1238 (defsubst gnus-article-unhide-text (b e)
1239 "Remove hidden text properties from region between B and E."
1240 (remove-text-properties b e gnus-hidden-properties)
1241 (when (memq 'intangible gnus-hidden-properties)
1242 (put-text-property (max (1- b) (point-min))
1243 b 'intangible nil)))
1245 (defun gnus-article-hide-text-type (b e type)
1246 "Hide text of TYPE between B and E."
1247 (push type gnus-article-wash-types)
1248 (gnus-article-hide-text
1249 b e (cons 'article-type (cons type gnus-hidden-properties))))
1251 (defun gnus-article-unhide-text-type (b e type)
1252 "Unhide text of TYPE between B and E."
1253 (setq gnus-article-wash-types
1254 (delq type gnus-article-wash-types))
1255 (remove-text-properties
1256 b e (cons 'article-type (cons type gnus-hidden-properties)))
1257 (when (memq 'intangible gnus-hidden-properties)
1258 (put-text-property (max (1- b) (point-min))
1259 b 'intangible nil)))
1261 (defun gnus-article-hide-text-of-type (type)
1262 "Hide text of TYPE in the current buffer."
1264 (let ((b (point-min))
1266 (while (setq b (text-property-any b e 'article-type type))
1267 (add-text-properties b (incf b) gnus-hidden-properties)))))
1269 (defun gnus-article-delete-text-of-type (type)
1270 "Delete text of TYPE in the current buffer."
1272 (let ((b (point-min)))
1273 (while (setq b (text-property-any b (point-max) 'article-type type))
1275 b (or (text-property-not-all b (point-max) 'article-type type)
1278 (defun gnus-article-delete-invisible-text ()
1279 "Delete all invisible text in the current buffer."
1281 (let ((b (point-min)))
1282 (while (setq b (text-property-any b (point-max) 'invisible t))
1284 b (or (text-property-not-all b (point-max) 'invisible t)
1287 (defun gnus-article-text-type-exists-p (type)
1288 "Say whether any text of type TYPE exists in the buffer."
1289 (text-property-any (point-min) (point-max) 'article-type type))
1291 (defsubst gnus-article-header-rank ()
1292 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1293 (let ((list gnus-sorted-header-list)
1296 (when (looking-at (car list))
1298 (setq list (cdr list))
1302 (defun article-hide-headers (&optional arg delete)
1303 "Hide unwanted headers and possibly sort them as well."
1304 (interactive (gnus-article-hidden-arg))
1305 ;; Lars said that this function might be inhibited.
1306 (if (gnus-article-check-hidden-text 'headers arg)
1308 ;; Show boring headers as well.
1309 (gnus-article-show-hidden-text 'boring-headers)
1310 (when (eq 1 (point-min))
1311 (set-window-start (get-buffer-window (current-buffer)) 1)))
1312 (unless gnus-inhibit-hiding
1315 (let ((inhibit-read-only t)
1316 (case-fold-search t)
1317 (max (1+ (length gnus-sorted-header-list)))
1318 (ignored (when (not gnus-visible-headers)
1319 (cond ((stringp gnus-ignored-headers)
1320 gnus-ignored-headers)
1321 ((listp gnus-ignored-headers)
1322 (mapconcat 'identity gnus-ignored-headers
1325 (cond ((stringp gnus-visible-headers)
1326 gnus-visible-headers)
1327 ((and gnus-visible-headers
1328 (listp gnus-visible-headers))
1329 (mapconcat 'identity gnus-visible-headers "\\|"))))
1330 (inhibit-point-motion-hooks t)
1332 ;; First we narrow to just the headers.
1333 (article-narrow-to-head)
1334 ;; Hide any "From " lines at the beginning of (mail) articles.
1335 (while (looking-at "From ")
1339 (delete-region (point-min) (point))
1340 (gnus-article-hide-text (point-min) (point)
1341 (nconc (list 'article-type 'headers)
1342 gnus-hidden-properties))))
1343 ;; Then treat the rest of the header lines.
1344 ;; Then we use the two regular expressions
1345 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1346 ;; select which header lines is to remain visible in the
1348 (while (re-search-forward "^[^ \t:]*:" nil t)
1350 ;; Mark the rank of the header.
1352 (point) (1+ (point)) 'message-rank
1353 (if (or (and visible (looking-at visible))
1355 (not (looking-at ignored))))
1356 (gnus-article-header-rank)
1359 (message-sort-headers-1)
1360 (when (setq beg (text-property-any
1361 (point-min) (point-max) 'message-rank (+ 2 max)))
1362 ;; We delete or make invisible the unwanted headers.
1363 (push 'headers gnus-article-wash-types)
1366 (add-text-properties
1367 (point-min) (+ 5 (point-min))
1368 '(article-type headers dummy-invisible t))
1369 (delete-region beg (point-max)))
1370 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1373 (defun article-hide-boring-headers (&optional arg)
1374 "Toggle hiding of headers that aren't very interesting.
1375 If given a negative prefix, always show; if given a positive prefix,
1377 (interactive (gnus-article-hidden-arg))
1378 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1379 (not gnus-show-all-headers))
1382 (let ((buffer-read-only nil)
1383 (list gnus-boring-article-headers)
1384 (inhibit-point-motion-hooks t)
1386 (article-narrow-to-head)
1388 (setq elem (pop list))
1389 (goto-char (point-min))
1391 ;; Hide empty headers.
1393 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1395 (gnus-article-hide-text-type
1396 (progn (beginning-of-line) (point))
1399 (if (re-search-forward "^[^ \t]" nil t)
1403 ;; Hide boring Newsgroups header.
1404 ((eq elem 'newsgroups)
1405 (when (gnus-string-equal
1406 (gnus-fetch-field "newsgroups")
1407 (gnus-group-real-name
1408 (if (boundp 'gnus-newsgroup-name)
1411 (gnus-article-hide-header "newsgroups")))
1412 ((eq elem 'to-address)
1413 (let ((to (message-fetch-field "to"))
1415 (gnus-parameter-to-address
1416 (if (boundp 'gnus-newsgroup-name)
1417 gnus-newsgroup-name ""))))
1418 (when (and to to-address
1421 ;; only one address in To
1422 (nth 1 (mail-extract-address-components to))
1424 (gnus-article-hide-header "to"))))
1425 ((eq elem 'followup-to)
1426 (when (gnus-string-equal
1427 (message-fetch-field "followup-to")
1428 (message-fetch-field "newsgroups"))
1429 (gnus-article-hide-header "followup-to")))
1430 ((eq elem 'reply-to)
1431 (let ((from (message-fetch-field "from"))
1432 (reply-to (message-fetch-field "reply-to")))
1437 (nth 1 (mail-extract-address-components from))
1438 (nth 1 (mail-extract-address-components reply-to)))))
1439 (gnus-article-hide-header "reply-to"))))
1441 (let ((date (message-fetch-field "date")))
1443 (< (days-between (current-time-string) date)
1445 (gnus-article-hide-header "date"))))
1447 (let ((to (message-fetch-field "to"))
1448 (cc (message-fetch-field "cc")))
1449 (when (> (length to) 1024)
1450 (gnus-article-hide-header "to"))
1451 (when (> (length cc) 1024)
1452 (gnus-article-hide-header "cc"))))
1456 (goto-char (point-min))
1457 (while (re-search-forward "^to:" nil t)
1458 (setq to-count (1+ to-count)))
1459 (when (> to-count 1)
1460 (while (> to-count 0)
1461 (goto-char (point-min))
1463 (re-search-forward "^to:" nil nil to-count)
1465 (narrow-to-region (point) (point-max))
1466 (gnus-article-hide-header "to"))
1467 (setq to-count (1- to-count))))
1468 (goto-char (point-min))
1469 (while (re-search-forward "^cc:" nil t)
1470 (setq cc-count (1+ cc-count)))
1471 (when (> cc-count 1)
1472 (while (> cc-count 0)
1473 (goto-char (point-min))
1475 (re-search-forward "^cc:" nil nil cc-count)
1477 (narrow-to-region (point) (point-max))
1478 (gnus-article-hide-header "cc"))
1479 (setq cc-count (1- cc-count)))))))))))))
1481 (defun gnus-article-hide-header (header)
1483 (goto-char (point-min))
1484 (when (re-search-forward (concat "^" header ":") nil t)
1485 (gnus-article-hide-text-type
1486 (progn (beginning-of-line) (point))
1489 (if (re-search-forward "^[^ \t]" nil t)
1494 (defun article-toggle-headers (&optional arg)
1495 "Toggle hiding of headers. If given a negative prefix, always show;
1496 if given a positive prefix, always hide."
1497 (interactive (gnus-article-hidden-arg))
1498 (let ((force (when (numberp arg)
1499 (cond ((> arg 0) 'always-hide)
1500 ((< arg 0) 'always-show))))
1501 (window (get-buffer-window gnus-article-buffer))
1502 (header-end (point-min))
1503 header-start field-end field-start
1504 (inhibit-point-motion-hooks t)
1505 (inhibit-read-only t))
1508 (while (and (setq header-start
1509 (text-property-any header-end (point-max)
1510 'article-treated-header t))
1512 (text-property-not-all header-start (point-max)
1513 'article-treated-header t)))
1514 (setq field-end header-start)
1516 (;; Hide exposed invisible fields.
1517 (and (not (eq 'always-show force))
1519 (text-property-any field-end header-end
1520 'exposed-invisible-field t)))
1521 (while (and field-start
1522 (setq field-end (text-property-not-all
1523 field-start header-end
1524 'exposed-invisible-field t)))
1525 (add-text-properties field-start field-end gnus-hidden-properties)
1526 (setq field-start (text-property-any field-end header-end
1527 'exposed-invisible-field t)))
1528 (put-text-property header-start header-end
1529 'exposed-invisible-field nil))
1530 (;; Expose invisible fields.
1531 (and (not (eq 'always-hide force))
1533 (text-property-any field-end header-end 'invisible t)))
1534 (while (and field-start
1535 (setq field-end (text-property-not-all
1536 field-start header-end
1538 ;; If the invisible text is not terminated with newline, we
1539 ;; won't expose it. Because it may be created by x-face-mule.
1540 ;; BTW, XEmacs sometimes fail in putting a invisible text
1541 ;; property with `gnus-article-hide-text' (really?). In that
1542 ;; case, the invisible text might be started from the middle of
1543 ;; a line so we will expose the sort of thing.
1544 (when (or (not (or (eq header-start field-start)
1545 (eq ?\n (char-before field-start))))
1546 (eq ?\n (char-before field-end)))
1547 (remove-text-properties field-start field-end
1548 gnus-hidden-properties)
1549 (put-text-property field-start field-end
1550 'exposed-invisible-field t))
1551 (setq field-start (text-property-any field-end header-end
1554 (not (eq 'always-show force))
1555 (narrow-to-region header-start header-end)
1556 (article-hide-headers)
1557 ;; Re-display X-Face image under XEmacs.
1558 (when (and (featurep 'xemacs)
1559 (gnus-functionp gnus-article-x-face-command))
1560 (let ((func (cadr (assq 'gnus-treat-display-xface
1561 gnus-treatment-function-alist)))
1563 (when (and (not gnus-inhibit-treatment)
1565 (gnus-treat-predicate gnus-treat-display-xface))
1567 (put-text-property header-start header-end 'read-only nil))))
1570 (goto-char (point-min))
1572 (set-window-start window (point-min))))))
1574 (defvar gnus-article-normalized-header-length 40
1575 "Length of normalized headers.")
1577 (defun article-normalize-headers ()
1578 "Make all header lines 40 characters long."
1580 (let ((buffer-read-only nil)
1584 (article-narrow-to-head)
1587 ((< (setq column (- (gnus-point-at-eol) (point)))
1588 gnus-article-normalized-header-length)
1590 (insert (make-string
1591 (- gnus-article-normalized-header-length column)
1593 ((> column gnus-article-normalized-header-length)
1594 (gnus-put-text-property
1596 (forward-char gnus-article-normalized-header-length)
1603 (forward-line 1))))))
1605 (defun article-treat-dumbquotes ()
1606 "Translate M****s*** sm*rtq**t*s into proper text.
1607 Note that this function guesses whether a character is a sm*rtq**t* or
1608 not, so it should only be used interactively.
1610 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1611 in an attempt to provide more quoting characters. If you see
1612 something like \\222 or \\264 where you're expecting some kind of
1613 apostrophe or quotation mark, then try this wash."
1615 (article-translate-strings gnus-article-dumbquotes-map))
1617 (defun article-translate-characters (from to)
1618 "Translate all characters in the body of the article according to FROM and TO.
1619 FROM is a string of characters to translate from; to is a string of
1620 characters to translate to."
1622 (when (article-goto-body)
1623 (let ((buffer-read-only nil)
1624 (x (make-string 225 ?x))
1626 (while (< (incf i) (length x))
1629 (while (< i (length from))
1630 (aset x (aref from i) (aref to i))
1632 (translate-region (point) (point-max) x)))))
1634 (defun article-translate-strings (map)
1635 "Translate all string in the body of the article according to MAP.
1636 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1638 (when (article-goto-body)
1639 (let ((buffer-read-only nil)
1641 (while (setq elem (pop map))
1643 (while (search-forward (car elem) nil t)
1644 (replace-match (cadr elem)))))))))
1646 (defun article-treat-overstrike ()
1647 "Translate overstrikes into bold text."
1650 (when (article-goto-body)
1651 (let ((buffer-read-only nil))
1652 (while (search-forward "\b" nil t)
1653 (let ((next (char-after))
1657 previous (char-after))
1661 ;; We do the boldification/underlining by hiding the
1662 ;; overstrikes and putting the proper text property
1666 (gnus-article-hide-text-type start (point) 'overstrike)
1667 (put-text-property (point) end 'face 'bold))
1669 (gnus-article-hide-text-type
1670 (1- (point)) (1+ (point)) 'overstrike)
1672 start (1- (point)) 'face 'underline))
1674 (gnus-article-hide-text-type start (point) 'overstrike)
1676 (point) end 'face 'underline)))))))))
1678 (defun article-fill-long-lines ()
1679 "Fill lines that are wider than the window width."
1682 (let ((buffer-read-only nil)
1683 (width (window-width (get-buffer-window (current-buffer)))))
1686 (let ((adaptive-fill-mode nil)) ;Why? -sm
1689 (when (>= (current-column) (min fill-column width))
1690 (narrow-to-region (point) (gnus-point-at-bol))
1691 (fill-paragraph nil)
1692 (goto-char (point-max))
1694 (forward-line 1)))))))
1696 (defun article-capitalize-sentences ()
1697 "Capitalize the first word in each sentence."
1700 (let ((buffer-read-only nil)
1701 (paragraph-start "^[\n\^L]"))
1705 (forward-sentence)))))
1707 (defun article-remove-cr ()
1708 "Remove trailing CRs and then translate remaining CRs into LFs."
1711 (let ((buffer-read-only nil))
1712 (goto-char (point-min))
1713 (while (re-search-forward "\r+$" nil t)
1714 (replace-match "" t t))
1715 (goto-char (point-min))
1716 (while (search-forward "\r" nil t)
1717 (replace-match "\n" t t)))))
1719 (defun article-remove-trailing-blank-lines ()
1720 "Remove all trailing blank lines from the article."
1723 (let ((buffer-read-only nil))
1724 (goto-char (point-max))
1728 (while (and (not (bobp))
1729 (looking-at "^[ \t]*$")
1730 (not (gnus-annotation-in-region-p
1731 (point) (gnus-point-at-eol))))
1736 (defun article-display-x-face (&optional force)
1737 "Look for an X-Face header and display it if present."
1738 (interactive (list 'force))
1740 ;; Delete the old process, if any.
1741 (when (process-status "article-x-face")
1742 (delete-process "article-x-face"))
1743 (let ((inhibit-point-motion-hooks t)
1745 (case-fold-search t)
1748 (article-narrow-to-head)
1749 ;; (when (and buffer-read-only ;; When type `W f'
1751 ;; (goto-char (point-min))
1752 ;; (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1753 ;; (gnus-buffer-live-p gnus-original-article-buffer))
1754 ;; (with-current-buffer gnus-original-article-buffer
1755 ;; (save-restriction
1756 ;; (article-narrow-to-head)
1757 ;; (while (re-search-forward "^X-Face:" nil t)
1761 ;; (buffer-substring
1762 ;; (match-beginning 0)
1763 ;; (1- (re-search-forward
1764 ;; "^\\($\\|[^ \t]\\)" nil t))))))))
1766 ;; (let (point start bface eface buffer-read-only)
1767 ;; (goto-char (point-max))
1768 ;; (forward-line -1)
1769 ;; (setq bface (get-text-property (gnus-point-at-bol) 'face)
1770 ;; eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1771 ;; (goto-char (point-max))
1772 ;; (setq point (point))
1774 ;; (goto-char point)
1775 ;; (while (looking-at "\\([^:]+\\): *")
1776 ;; (put-text-property (match-beginning 1) (1+ (match-end 1))
1778 ;; (setq start (match-end 0))
1780 ;; (while (looking-at "[\t ]")
1781 ;; (forward-line 1))
1782 ;; (put-text-property start (point)
1784 (goto-char (point-min))
1785 (setq from (message-fetch-field "from"))
1786 (goto-char (point-min))
1787 (while (and gnus-article-x-face-command
1790 ;; Check whether this face is censored.
1791 (not gnus-article-x-face-too-ugly)
1792 (and gnus-article-x-face-too-ugly from
1793 (not (string-match gnus-article-x-face-too-ugly
1795 ;; Has to be present.
1796 (re-search-forward "^X-Face:[\t ]*" nil t))
1797 ;; This used to try to do multiple faces (`while' instead of
1798 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1799 ;; work (b) it can crash some versions of Emacs (c) are
1800 ;; multiple faces really something to encourage?
1801 (when (stringp gnus-article-x-face-command)
1803 ;; We now have the area of the buffer where the X-Face is stored.
1806 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1807 ;; We display the face.
1808 (if (symbolp gnus-article-x-face-command)
1809 ;; The command is a lisp function, so we call it.
1810 (if (gnus-functionp gnus-article-x-face-command)
1811 (funcall gnus-article-x-face-command beg end)
1812 (error "%s is not a function" gnus-article-x-face-command))
1813 ;; The command is a string, so we interpret the command
1814 ;; as a, well, command, and fork it off.
1815 (let ((process-connection-type nil))
1816 (process-kill-without-query
1818 "article-x-face" nil shell-file-name shell-command-switch
1819 gnus-article-x-face-command))
1820 (process-send-region "article-x-face" beg end)
1821 (process-send-eof "article-x-face"))))))))))
1823 (defun article-decode-mime-words ()
1824 "Decode all MIME-encoded words in the article."
1827 (set-buffer gnus-article-buffer)
1828 (let ((inhibit-point-motion-hooks t)
1830 (mail-parse-charset gnus-newsgroup-charset)
1831 (mail-parse-ignored-charsets
1832 (save-excursion (set-buffer gnus-summary-buffer)
1833 gnus-newsgroup-ignored-charsets)))
1834 (mail-decode-encoded-word-region (point-min) (point-max)))))
1836 (defun article-decode-charset (&optional prompt)
1837 "Decode charset-encoded text in the article.
1838 If PROMPT (the prefix), prompt for a coding system to use."
1840 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1842 (mail-parse-charset gnus-newsgroup-charset)
1843 (mail-parse-ignored-charsets
1844 (save-excursion (condition-case nil
1845 (set-buffer gnus-summary-buffer)
1847 gnus-newsgroup-ignored-charsets))
1848 ct cte ctl charset format)
1851 (article-narrow-to-head)
1852 (setq ct (message-fetch-field "Content-Type" t)
1853 cte (message-fetch-field "Content-Transfer-Encoding" t)
1854 ctl (and ct (ignore-errors
1855 (mail-header-parse-content-type ct)))
1858 (mm-read-coding-system "Charset to decode: "))
1860 (mail-content-type-get ctl 'charset)))
1861 format (and ctl (mail-content-type-get ctl 'format)))
1863 (setq cte (mail-header-strip cte)))
1864 (if (and ctl (not (string-match "/" (car ctl))))
1866 (goto-char (point-max)))
1869 (narrow-to-region (point) (point-max))
1870 (when (and (eq mail-parse-charset 'gnus-decoded)
1871 (eq (mm-body-7-or-8) '8bit))
1872 ;; The text code could have been decoded.
1873 (setq charset mail-parse-charset))
1874 (when (and (or (not ctl)
1875 (equal (car ctl) "text/plain"))
1876 (not format)) ;; article with format will decode later.
1878 charset (and cte (intern (downcase
1879 (gnus-strip-whitespace cte))))
1882 (defun article-decode-encoded-words ()
1883 "Remove encoded-word encoding from headers."
1884 (let (buffer-read-only)
1885 (let ((charset (save-excursion
1886 (set-buffer gnus-summary-buffer)
1887 default-mime-charset)))
1888 (mime-decode-header-in-buffer charset)
1891 (defun article-de-quoted-unreadable (&optional force read-charset)
1892 "Translate a quoted-printable-encoded article.
1893 If FORCE, decode the article whether it is marked as quoted-printable
1895 If READ-CHARSET, ask for a coding system."
1896 (interactive (list 'force current-prefix-arg))
1898 (let ((buffer-read-only nil) type charset)
1899 (if (gnus-buffer-live-p gnus-original-article-buffer)
1900 (with-current-buffer gnus-original-article-buffer
1902 (gnus-fetch-field "content-transfer-encoding"))
1903 (let* ((ct (gnus-fetch-field "content-type"))
1906 (mail-header-parse-content-type ct)))))
1907 (setq charset (and ctl
1908 (mail-content-type-get ctl 'charset)))
1909 (if (stringp charset)
1910 (setq charset (intern (downcase charset)))))))
1912 (setq charset (mm-read-coding-system "Charset: " charset)))
1914 (setq charset gnus-newsgroup-charset))
1916 (and type (let ((case-fold-search t))
1917 (string-match "quoted-printable" type))))
1919 (quoted-printable-decode-region
1920 (point) (point-max) (mm-charset-to-coding-system charset))))))
1922 (defun article-de-base64-unreadable (&optional force read-charset)
1923 "Translate a base64 article.
1924 If FORCE, decode the article whether it is marked as base64 not.
1925 If READ-CHARSET, ask for a coding system."
1926 (interactive (list 'force current-prefix-arg))
1928 (let ((buffer-read-only nil) type charset)
1929 (if (gnus-buffer-live-p gnus-original-article-buffer)
1930 (with-current-buffer gnus-original-article-buffer
1932 (gnus-fetch-field "content-transfer-encoding"))
1933 (let* ((ct (gnus-fetch-field "content-type"))
1936 (mail-header-parse-content-type ct)))))
1937 (setq charset (and ctl
1938 (mail-content-type-get ctl 'charset)))
1939 (if (stringp charset)
1940 (setq charset (intern (downcase charset)))))))
1942 (setq charset (mm-read-coding-system "Charset: " charset)))
1944 (setq charset gnus-newsgroup-charset))
1946 (and type (let ((case-fold-search t))
1947 (string-match "base64" type))))
1950 (narrow-to-region (point) (point-max))
1951 (base64-decode-region (point-min) (point-max))
1952 (mm-decode-coding-region
1953 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1958 (defun article-decode-HZ ()
1959 "Translate a HZ-encoded article."
1963 (let ((buffer-read-only nil))
1964 (rfc1843-decode-region (point-min) (point-max)))))
1966 (defun article-wash-html (&optional read-charset)
1967 "Format an html article.
1968 If READ-CHARSET, ask for a coding system."
1971 (let ((buffer-read-only nil)
1973 (if (gnus-buffer-live-p gnus-original-article-buffer)
1974 (with-current-buffer gnus-original-article-buffer
1975 (let* ((ct (gnus-fetch-field "content-type"))
1978 (mail-header-parse-content-type ct)))))
1979 (setq charset (and ctl
1980 (mail-content-type-get ctl 'charset)))
1981 (if (stringp charset)
1982 (setq charset (intern (downcase charset)))))))
1984 (setq charset (mm-read-coding-system "Charset: " charset)))
1986 (setq charset gnus-newsgroup-charset))
1988 (save-window-excursion
1990 (narrow-to-region (point) (point-max))
1992 (let ((w3-strict-width (window-width))
1993 (url-standalone-mode t))
1995 (w3-region (point-min) (point-max))
1998 (defun article-hide-list-identifiers ()
1999 "Remove list identifies from the Subject header.
2000 The `gnus-list-identifiers' variable specifies what to do."
2002 (let ((inhibit-point-motion-hooks t)
2003 (regexp (if (consp gnus-list-identifiers)
2004 (mapconcat 'identity gnus-list-identifiers " *\\|")
2005 gnus-list-identifiers))
2010 (article-narrow-to-head)
2011 (goto-char (point-min))
2012 (while (re-search-forward
2013 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2015 (delete-region (match-beginning 2) (match-end 0))
2016 (beginning-of-line))
2017 (when (re-search-forward
2018 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2019 (delete-region (match-beginning 1) (match-end 1))))))))
2021 (defun article-hide-pgp ()
2022 "Remove any PGP headers and signatures in the current article."
2026 (let ((inhibit-point-motion-hooks t)
2027 buffer-read-only beg end)
2029 ;; Hide the "header".
2030 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2031 (push 'pgp gnus-article-wash-types)
2032 (delete-region (match-beginning 0) (match-end 0))
2033 ;; Remove armor headers (rfc2440 6.2)
2034 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2037 ;; Hide the actual signature.
2038 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2039 (setq end (1+ (match-beginning 0)))
2042 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2044 ;; Perhaps we shouldn't hide to the end of the buffer
2045 ;; if there is no end to the signature?
2047 ;; Hide "- " PGP quotation markers.
2049 (narrow-to-region beg end)
2050 (goto-char (point-min))
2051 (while (re-search-forward "^- " nil t)
2053 (match-beginning 0) (match-end 0)))
2055 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2057 (defun article-hide-pem (&optional arg)
2058 "Toggle hiding of any PEM headers and signatures in the current article.
2059 If given a negative prefix, always show; if given a positive prefix,
2061 (interactive (gnus-article-hidden-arg))
2062 (unless (gnus-article-check-hidden-text 'pem arg)
2064 (let (buffer-read-only end)
2065 (goto-char (point-min))
2066 ;; Hide the horrendously ugly "header".
2067 (when (and (search-forward
2068 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2070 (setq end (1+ (match-beginning 0))))
2071 (push 'pem gnus-article-wash-types)
2072 (gnus-article-hide-text-type
2074 (if (search-forward "\n\n" nil t)
2078 ;; Hide the trailer as well
2079 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2081 (gnus-article-hide-text-type
2082 (match-beginning 0) (match-end 0) 'pem)))))))
2084 (defun article-strip-banner ()
2085 "Strip the banner specified by the `banner' group parameter."
2089 (let ((inhibit-point-motion-hooks t)
2090 (banner (gnus-parameter-banner gnus-newsgroup-name))
2091 (gnus-signature-limit nil)
2092 buffer-read-only beg end)
2096 ((eq banner 'signature)
2097 (when (gnus-article-narrow-to-signature)
2100 (delete-region (point) (point-max))))
2102 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2103 (while (re-search-forward banner nil t)
2104 (delete-region (match-beginning 0) (match-end 0)))))
2106 (while (re-search-forward banner nil t)
2107 (delete-region (match-beginning 0) (match-end 0))))))))))
2109 (defun article-babel ()
2110 "Translate article using an online translation service."
2114 (set-buffer gnus-article-buffer)
2115 (when (article-goto-body)
2116 (let* ((buffer-read-only nil)
2119 (orig (buffer-substring start end))
2120 (trans (babel-as-string orig)))
2122 (narrow-to-region start end)
2123 (delete-region start end)
2126 (defun article-hide-signature (&optional arg)
2127 "Hide the signature in the current article.
2128 If given a negative prefix, always show; if given a positive prefix,
2130 (interactive (gnus-article-hidden-arg))
2136 (article-goto-body))
2137 (goto-char (point-min)))
2138 (unless (gnus-article-check-hidden-text 'signature arg)
2139 (let ((buffer-read-only nil)
2141 (while (setq button (text-property-any button (point-max)
2143 'gnus-signature-toggle))
2144 (setq button (text-property-not-all button (point-max)
2146 'gnus-signature-toggle))
2147 (when (and button (not (eobp)))
2148 (gnus-article-hide-text-type
2150 (next-single-property-change (1+ button) 'mime-view-entity
2154 (defun article-strip-headers-in-body ()
2155 "Strip offensive headers from bodies."
2159 (let ((case-fold-search t))
2160 (when (looking-at "x-no-archive:")
2161 (gnus-delete-line)))))
2163 (defun article-strip-leading-blank-lines ()
2164 "Remove all blank lines from the beginning of the article."
2167 (let ((inhibit-point-motion-hooks t)
2169 (when (article-goto-body)
2170 (while (and (not (eobp))
2171 (looking-at "[ \t]*$"))
2172 (gnus-delete-line))))))
2174 (defun article-narrow-to-head ()
2175 "Narrow the buffer to the head of the message.
2176 Point is left at the beginning of the narrowed-to region."
2178 (goto-char (point-min))
2179 (if (search-forward "\n\n" nil 1)
2182 (goto-char (point-min)))
2184 (defun article-goto-body ()
2185 "Place point at the start of the body."
2186 (goto-char (point-min))
2188 ;; This variable is only bound when dealing with separate
2190 (article-goto-body-goes-to-point-min-p
2192 ((search-forward "\n\n" nil t)
2195 (goto-char (point-max))
2198 (defun article-strip-multiple-blank-lines ()
2199 "Replace consecutive blank lines with one empty line."
2202 (let ((inhibit-point-motion-hooks t)
2204 ;; First make all blank lines empty.
2206 (while (re-search-forward "^[ \t]+$" nil t)
2207 (unless (gnus-annotation-in-region-p
2208 (match-beginning 0) (match-end 0))
2209 (replace-match "" nil t)))
2210 ;; Then replace multiple empty lines with a single empty line.
2212 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2213 (unless (gnus-annotation-in-region-p
2214 (match-beginning 0) (match-end 0))
2215 (delete-region (match-beginning 1) (match-end 1)))))))
2217 (defun article-strip-leading-space ()
2218 "Remove all white space from the beginning of the lines in the article."
2221 (let ((inhibit-point-motion-hooks t)
2224 (while (re-search-forward "^[ \t]+" nil t)
2225 (replace-match "" t t)))))
2227 (defun article-strip-trailing-space ()
2228 "Remove all white space from the end of the lines in the article."
2231 (let ((inhibit-point-motion-hooks t)
2234 (while (re-search-forward "[ \t]+$" nil t)
2235 (replace-match "" t t)))))
2237 (defun article-strip-blank-lines ()
2238 "Strip leading, trailing and multiple blank lines."
2240 (article-strip-leading-blank-lines)
2241 (article-remove-trailing-blank-lines)
2242 (article-strip-multiple-blank-lines))
2244 (defun article-strip-all-blank-lines ()
2245 "Strip all blank lines."
2248 (let ((inhibit-point-motion-hooks t)
2251 (while (re-search-forward "^[ \t]*\n" nil t)
2252 (replace-match "" t t)))))
2254 (defun gnus-article-narrow-to-signature ()
2255 "Narrow to the signature; return t if a signature is found, else nil."
2256 (let ((inhibit-point-motion-hooks t))
2257 (when (gnus-article-search-signature)
2259 ;; Check whether we have some limits to what we consider
2260 ;; to be a signature.
2261 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2262 (list gnus-signature-limit)))
2264 (while (setq limit (pop limits))
2265 (if (or (and (integerp limit)
2266 (< (- (point-max) (point)) limit))
2268 (< (count-lines (point) (point-max)) limit))
2269 (and (gnus-functionp limit)
2271 (and (stringp limit)
2272 (not (re-search-forward limit nil t))))
2273 () ; This limit did not succeed.
2277 (narrow-to-region (point) (point-max))
2280 (defun gnus-article-search-signature ()
2281 "Search the current buffer for the signature separator.
2282 Put point at the beginning of the signature separator."
2283 (let ((cur (point)))
2284 (goto-char (point-max))
2285 (if (if (stringp gnus-signature-separator)
2286 (re-search-backward gnus-signature-separator nil t)
2287 (let ((seps gnus-signature-separator))
2289 (not (re-search-backward (car seps) nil t)))
2296 (defun gnus-article-hidden-arg ()
2297 "Return the current prefix arg as a number, or 0 if no prefix."
2298 (list (if current-prefix-arg
2299 (prefix-numeric-value current-prefix-arg)
2302 (defun gnus-article-check-hidden-text (type arg)
2303 "Return nil if hiding is necessary.
2304 Arg can be nil or a number. Nil and positive means hide, negative
2305 means show, 0 means toggle."
2308 (let ((hide (gnus-article-hidden-text-p type)))
2314 (gnus-article-show-hidden-text type)
2317 (if (eq hide 'hidden)
2319 (gnus-article-show-hidden-text type)
2323 (defun gnus-article-hidden-text-p (type)
2324 "Say whether the current buffer contains hidden text of type TYPE."
2325 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2327 (not (get-text-property pos 'invisible))
2328 (not (get-text-property pos 'dummy-invisible)))
2330 (text-property-any (1+ pos) (point-max) 'article-type type)))
2335 (defun gnus-article-show-hidden-text (type &optional dummy)
2336 "Show all hidden text of type TYPE.
2337 Originally it is hide instead of DUMMY."
2338 (let ((buffer-read-only nil)
2339 (inhibit-point-motion-hooks t))
2340 (gnus-remove-text-properties-when
2342 (point-min) (point-max)
2343 (cons 'article-type (cons type
2344 gnus-hidden-properties)))))
2346 (defconst article-time-units
2347 `((year . ,(* 365.25 24 60 60))
2348 (week . ,(* 7 24 60 60))
2349 (day . ,(* 24 60 60))
2353 "Mapping from time units to seconds.")
2355 (defun article-date-ut (&optional type highlight header)
2356 "Convert DATE date to universal time in the current article.
2357 If TYPE is `local', convert to local time; if it is `lapsed', output
2358 how much time has lapsed since DATE. For `lapsed', the value of
2359 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2360 should replace the \"Date:\" one, or should be added below it."
2361 (interactive (list 'ut t))
2362 (let* ((header (or header
2363 (and (eq 1 (point-min))
2364 (mail-header-date (save-excursion
2365 (set-buffer gnus-summary-buffer)
2366 gnus-current-headers)))
2367 (message-fetch-field "date")
2369 (date (if (vectorp header) (mail-header-date header)
2371 (inhibit-point-motion-hooks t)
2372 bface eface date-pos)
2373 (when (and date (not (string= date "")))
2376 (article-narrow-to-head)
2377 (when (or (and (eq type 'lapsed)
2378 gnus-article-date-lapsed-new-header
2379 ;; Attempt to get the face of X-Sent first.
2380 (re-search-forward "^X-Sent:[ \t]" nil t))
2381 (re-search-forward "^Date:[ \t]" nil t)
2382 ;; If Date is missing, try again for X-Sent.
2383 (re-search-forward "^X-Sent:[ \t]" nil t))
2384 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2385 date (or (get-text-property (gnus-point-at-bol)
2388 eface (get-text-property (1- (gnus-point-at-eol))
2390 (let ((buffer-read-only nil))
2391 ;; Delete any old X-Sent headers.
2392 (when (setq date-pos
2393 (text-property-any (point-min) (point-max)
2394 'article-date-lapsed t))
2395 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2396 (delete-region (match-beginning 0)
2397 (progn (forward-line 1) (point))))
2398 (goto-char (point-min))
2399 ;; Delete any old Date headers.
2400 (while (re-search-forward "^Date:[ \t]" nil t)
2402 (setq date-pos (match-beginning 0)))
2403 (unless (and (eq type 'lapsed)
2404 gnus-article-date-lapsed-new-header)
2405 (delete-region (match-beginning 0)
2406 (progn (message-next-header) (point)))))
2409 (goto-char date-pos)
2411 ;; Possibly, Date has been deleted.
2413 (when (and (eq type 'lapsed)
2414 gnus-article-date-lapsed-new-header
2415 (looking-at "Date:"))
2417 (goto-char (point-min)))
2418 (insert (article-make-date-line date type))
2419 (when (eq type 'lapsed)
2420 (put-text-property (gnus-point-at-bol) (point)
2421 'article-date-lapsed t))
2425 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2426 (put-text-property (match-beginning 1) (1+ (match-end 1))
2427 'original-date date)
2428 (put-text-property (match-beginning 1) (1+ (match-end 1))
2430 (put-text-property (match-beginning 2) (match-end 2)
2433 (defun article-make-date-line (date type)
2434 "Return a DATE line of TYPE."
2435 (unless (memq type '(local ut original user iso8601 lapsed english))
2436 (error "Unknown conversion type: %s" type))
2438 (let ((time (date-to-time date)))
2440 ;; Convert to the local timezone.
2442 (let ((tz (car (current-time-zone time))))
2443 (format "Date: %s %s%02d%02d" (current-time-string time)
2444 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2445 (/ (% (abs tz) 3600) 60))))
2446 ;; Convert to Universal Time.
2449 (current-time-string
2450 (let* ((e (parse-time-string date))
2451 (tm (apply 'encode-time e))
2453 (ls (- (cadr tm) (car (current-time-zone time)))))
2454 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2455 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2458 ;; Get the original date from the article.
2459 ((eq type 'original)
2460 (concat "Date: " (if (string-match "\n+$" date)
2461 (substring date 0 (match-beginning 0))
2463 ;; Let the user define the format.
2465 (if (gnus-functionp gnus-article-time-format)
2466 (funcall gnus-article-time-format time)
2469 (format-time-string gnus-article-time-format time))))
2472 (let ((tz (car (current-time-zone time))))
2475 (format-time-string "%Y%m%dT%H%M%S" time)
2476 (format "%s%02d%02d"
2477 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2478 (/ (% (abs tz) 3600) 60)))))
2479 ;; Do an X-Sent lapsed format.
2481 ;; If the date is seriously mangled, the timezone functions are
2482 ;; liable to bug out, so we ignore all errors.
2483 (let* ((now (current-time))
2484 (real-time (subtract-time now time))
2485 (real-sec (and real-time
2486 (+ (* (float (car real-time)) 65536)
2488 (sec (and real-time (abs real-sec)))
2498 ;; This is a bit convoluted, but basically we go
2499 ;; through the time units for years, weeks, etc,
2500 ;; and divide things to see whether that results
2501 ;; in positive answers.
2504 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2505 ;; The (remaining) seconds are too few to
2506 ;; be divided into this time unit.
2508 ;; It's big enough, so we output it.
2509 (setq sec (- sec (* num (cdr unit))))
2511 (concat (if prev ", " "") (int-to-string
2513 " " (symbol-name (car unit))
2514 (if (> num 1) "s" ""))
2516 article-time-units "")
2517 ;; If dates are odd, then it might appear like the
2518 ;; article was sent in the future.
2521 " in the future"))))))
2522 ;; Display the date in proper English
2524 (let ((dtime (decode-time time)))
2527 (number-to-string (nth 3 dtime))
2528 (let ((digit (% (nth 3 dtime) 10)))
2530 ((memq (nth 3 dtime) '(11 12 13)) "th")
2536 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2538 (number-to-string (nth 5 dtime))
2540 (format "%02d" (nth 2 dtime))
2542 (format "%02d" (nth 1 dtime)))))))
2544 (format "Date: %s (from Oort)" date))))
2546 (defun article-date-local (&optional highlight)
2547 "Convert the current article date to the local timezone."
2548 (interactive (list t))
2549 (article-date-ut 'local highlight))
2551 (defun article-date-english (&optional highlight)
2552 "Convert the current article date to something that is proper English."
2553 (interactive (list t))
2554 (article-date-ut 'english highlight))
2556 (defun article-date-original (&optional highlight)
2557 "Convert the current article date to what it was originally.
2558 This is only useful if you have used some other date conversion
2559 function and want to see what the date was before converting."
2560 (interactive (list t))
2561 (article-date-ut 'original highlight))
2563 (defun article-date-lapsed (&optional highlight)
2564 "Convert the current article date to time lapsed since it was sent."
2565 (interactive (list t))
2566 (article-date-ut 'lapsed highlight))
2568 (defun article-update-date-lapsed ()
2569 "Function to be run from a timer to update the lapsed time line."
2570 (let (deactivate-mark)
2575 (set-buffer (window-buffer w))
2576 (when (eq major-mode 'gnus-article-mode)
2577 (goto-char (point-min))
2578 (when (re-search-forward "^X-Sent:" nil t)
2579 (article-date-lapsed t))))
2582 (defun gnus-start-date-timer (&optional n)
2583 "Start a timer to update the X-Sent header in the article buffers.
2584 The numerical prefix says how frequently (in seconds) the function
2589 (gnus-stop-date-timer)
2590 (setq article-lapsed-timer
2591 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2593 (defun gnus-stop-date-timer ()
2594 "Stop the X-Sent timer."
2596 (when article-lapsed-timer
2597 (nnheader-cancel-timer article-lapsed-timer)
2598 (setq article-lapsed-timer nil)))
2600 (defun article-date-user (&optional highlight)
2601 "Convert the current article date to the user-defined format.
2602 This format is defined by the `gnus-article-time-format' variable."
2603 (interactive (list t))
2604 (article-date-ut 'user highlight))
2606 (defun article-date-iso8601 (&optional highlight)
2607 "Convert the current article date to ISO8601."
2608 (interactive (list t))
2609 (article-date-ut 'iso8601 highlight))
2611 (defun article-show-all ()
2612 "Show all hidden text in the article buffer."
2616 (let ((buffer-read-only nil))
2617 (gnus-article-unhide-text (point-min) (point-max))
2618 (gnus-remove-text-with-property 'gnus-prev)
2619 (gnus-remove-text-with-property 'gnus-next))))
2621 (defun article-show-all-headers ()
2622 "Show all hidden headers in the article buffer."
2627 (article-narrow-to-head)
2628 (let ((buffer-read-only nil))
2629 (gnus-article-unhide-text (point-min) (point-max))))))
2631 (defun article-remove-leading-whitespace ()
2632 "Remove excessive whitespace from all headers."
2636 (let ((buffer-read-only nil))
2637 (article-narrow-to-head)
2638 (goto-char (point-min))
2639 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2640 (delete-region (match-beginning 1) (match-end 1)))))))
2642 (defun article-emphasize (&optional arg)
2643 "Emphasize text according to `gnus-emphasis-alist'."
2644 (interactive (gnus-article-hidden-arg))
2645 (unless (gnus-article-check-hidden-text 'emphasis arg)
2649 (with-current-buffer gnus-summary-buffer
2650 gnus-article-emphasis-alist)
2652 gnus-emphasis-alist))
2653 (buffer-read-only nil)
2654 (props (append '(article-type emphasis)
2655 gnus-hidden-properties))
2656 regexp elem beg invisible visible face)
2659 (while (setq elem (pop alist))
2661 (setq regexp (car elem)
2662 invisible (nth 1 elem)
2663 visible (nth 2 elem)
2665 (while (re-search-forward regexp nil t)
2666 (when (and (match-beginning visible) (match-beginning invisible))
2667 (push 'emphasis gnus-article-wash-types)
2668 (gnus-article-hide-text
2669 (match-beginning invisible) (match-end invisible) props)
2670 (gnus-article-unhide-text-type
2671 (match-beginning visible) (match-end visible) 'emphasis)
2672 (gnus-put-text-property-excluding-newlines
2673 (match-beginning visible) (match-end visible) 'face face)
2674 (goto-char (match-end invisible)))))))))
2676 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2677 "Setup newsgroup emphasis alist."
2678 (unless gnus-article-emphasis-alist
2679 (let ((name (and gnus-newsgroup-name
2680 (gnus-group-real-name gnus-newsgroup-name))))
2681 (make-local-variable 'gnus-article-emphasis-alist)
2682 (setq gnus-article-emphasis-alist
2684 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2685 (while (setq elem (pop alist))
2686 (when (and name (string-match (car elem) name))
2688 highlight (copy-sequence (cdr elem)))))
2690 (copy-sequence highlight-words)
2691 (if gnus-newsgroup-name
2692 (copy-sequence (gnus-group-find-parameter
2693 gnus-newsgroup-name 'highlight-words t)))
2694 gnus-emphasis-alist)))))
2697 (defvar gnus-summary-article-menu)
2698 (defvar gnus-summary-post-menu))
2700 ;;; Saving functions.
2702 (defun gnus-article-save (save-buffer file &optional num)
2703 "Save the currently selected article."
2704 (unless gnus-save-all-headers
2705 ;; Remove headers according to `gnus-saved-headers'.
2706 (let ((gnus-visible-headers
2707 (or gnus-saved-headers gnus-visible-headers))
2708 (gnus-article-buffer save-buffer))
2710 (set-buffer save-buffer)
2711 (article-hide-headers 1 t))))
2712 (save-window-excursion
2713 (if (not gnus-default-article-saver)
2714 (error "No default saver is defined")
2715 ;; !!! Magic! The saving functions all save
2716 ;; `gnus-save-article-buffer' (or so they think), but we
2717 ;; bind that variable to our save-buffer.
2718 (set-buffer gnus-article-buffer)
2719 (let* ((gnus-save-article-buffer save-buffer)
2722 ((not gnus-prompt-before-saving) 'default)
2723 ((eq gnus-prompt-before-saving 'always) nil)
2725 (gnus-number-of-articles-to-be-saved
2726 (when (eq gnus-prompt-before-saving t)
2728 (set-buffer gnus-article-current-summary)
2729 (funcall gnus-default-article-saver filename)))))
2731 (defun gnus-read-save-file-name (prompt &optional filename
2732 function group headers variable)
2734 (funcall function group headers (symbol-value variable)))
2739 ((eq filename 'default)
2745 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2748 (if (and gnus-number-of-articles-to-be-saved
2749 (> gnus-number-of-articles-to-be-saved 1))
2750 (format "these %d articles"
2751 gnus-number-of-articles-to-be-saved)
2754 ;; Let the split methods have their say.
2756 ;; No split name was found.
2759 (concat prompt " (default "
2760 (file-name-nondirectory default-name) ") ")
2761 (file-name-directory default-name)
2763 ;; A single group name is returned.
2764 ((stringp split-name)
2766 (funcall function split-name headers
2767 (symbol-value variable)))
2769 (concat prompt " (default "
2770 (file-name-nondirectory default-name) ") ")
2771 (file-name-directory default-name)
2773 ;; A single split name was found
2774 ((= 1 (length split-name))
2775 (let* ((name (expand-file-name
2777 gnus-article-save-directory))
2778 (dir (cond ((file-directory-p name)
2779 (file-name-as-directory name))
2780 ((file-exists-p name) name)
2781 (t gnus-article-save-directory))))
2783 (concat prompt " (default " name ") ")
2785 ;; A list of splits was found.
2787 (setq split-name (nreverse split-name))
2789 (let ((file-name-history
2790 (nconc split-name file-name-history)))
2794 (concat prompt " (`M-p' for defaults) ")
2795 gnus-article-save-directory
2797 gnus-article-save-directory)))
2798 (car (push result file-name-history)))))))
2799 ;; Create the directory.
2800 (gnus-make-directory (file-name-directory file))
2801 ;; If we have read a directory, we append the default file name.
2802 (when (file-directory-p file)
2803 (setq file (expand-file-name (file-name-nondirectory
2805 (file-name-as-directory file))))
2806 ;; Possibly translate some characters.
2807 (nnheader-translate-file-chars file))))))
2808 (gnus-make-directory (file-name-directory result))
2809 (set variable result)))
2811 (defun gnus-article-archive-name (group)
2812 "Return the first instance of an \"Archive-name\" in the current buffer."
2813 (let ((case-fold-search t))
2814 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2815 (nnheader-concat gnus-article-save-directory
2816 (match-string 1)))))
2818 (defun gnus-article-nndoc-name (group)
2819 "If GROUP is an nndoc group, return the name of the parent group."
2820 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2821 (gnus-group-get-parameter group 'save-article-group)))
2823 (defun gnus-summary-save-in-rmail (&optional filename)
2824 "Append this article to Rmail file.
2825 Optional argument FILENAME specifies file name.
2826 Directory to save to is default to `gnus-article-save-directory'."
2827 (setq filename (gnus-read-save-file-name
2828 "Save %s in rmail file:" filename
2829 gnus-rmail-save-name gnus-newsgroup-name
2830 gnus-current-headers 'gnus-newsgroup-last-rmail))
2831 (gnus-eval-in-buffer-window gnus-save-article-buffer
2835 (gnus-output-to-rmail filename))))
2838 (defun gnus-summary-save-in-mail (&optional filename)
2839 "Append this article to Unix mail file.
2840 Optional argument FILENAME specifies file name.
2841 Directory to save to is default to `gnus-article-save-directory'."
2842 (setq filename (gnus-read-save-file-name
2843 "Save %s in Unix mail file:" filename
2844 gnus-mail-save-name gnus-newsgroup-name
2845 gnus-current-headers 'gnus-newsgroup-last-mail))
2846 (gnus-eval-in-buffer-window gnus-save-article-buffer
2850 (if (and (file-readable-p filename)
2851 (mail-file-babyl-p filename))
2852 (rmail-output-to-rmail-file filename t)
2853 (gnus-output-to-mail filename)))))
2856 (defun gnus-summary-save-in-file (&optional filename overwrite)
2857 "Append this article to file.
2858 Optional argument FILENAME specifies file name.
2859 Directory to save to is default to `gnus-article-save-directory'."
2860 (setq filename (gnus-read-save-file-name
2861 "Save %s in file:" filename
2862 gnus-file-save-name gnus-newsgroup-name
2863 gnus-current-headers 'gnus-newsgroup-last-file))
2864 (gnus-eval-in-buffer-window gnus-save-article-buffer
2868 (when (and overwrite
2869 (file-exists-p filename))
2870 (delete-file filename))
2871 (gnus-output-to-file filename))))
2874 (defun gnus-summary-write-to-file (&optional filename)
2875 "Write this article to a file.
2876 Optional argument FILENAME specifies file name.
2877 The directory to save in defaults to `gnus-article-save-directory'."
2878 (gnus-summary-save-in-file nil t))
2880 (defun gnus-summary-save-body-in-file (&optional filename)
2881 "Append this article body to a file.
2882 Optional argument FILENAME specifies file name.
2883 The directory to save in defaults to `gnus-article-save-directory'."
2884 (setq filename (gnus-read-save-file-name
2885 "Save %s body in file:" filename
2886 gnus-file-save-name gnus-newsgroup-name
2887 gnus-current-headers 'gnus-newsgroup-last-file))
2888 (gnus-eval-in-buffer-window gnus-save-article-buffer
2892 (when (article-goto-body)
2893 (narrow-to-region (point) (point-max)))
2894 (gnus-output-to-file filename))))
2897 (defun gnus-summary-save-in-pipe (&optional command)
2898 "Pipe this article to subprocess."
2900 (cond ((and (eq command 'default)
2901 gnus-last-shell-command)
2902 gnus-last-shell-command)
2907 "Shell command on %s: "
2908 (if (and gnus-number-of-articles-to-be-saved
2909 (> gnus-number-of-articles-to-be-saved 1))
2910 (format "these %d articles"
2911 gnus-number-of-articles-to-be-saved)
2913 gnus-last-shell-command))))
2914 (when (string-equal command "")
2915 (if gnus-last-shell-command
2916 (setq command gnus-last-shell-command)
2917 (error "A command is required")))
2918 (gnus-eval-in-buffer-window gnus-article-buffer
2921 (shell-command-on-region (point-min) (point-max) command nil)))
2922 (setq gnus-last-shell-command command))
2924 ;;; Article file names when saving.
2926 (defun gnus-capitalize-newsgroup (newsgroup)
2927 "Capitalize NEWSGROUP name."
2928 (when (not (zerop (length newsgroup)))
2929 (concat (char-to-string (upcase (aref newsgroup 0)))
2930 (substring newsgroup 1))))
2932 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2933 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2934 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2935 Otherwise, it is like ~/News/news/group/num."
2938 (concat (if (gnus-use-long-file-name 'not-save)
2939 (gnus-capitalize-newsgroup newsgroup)
2940 (gnus-newsgroup-directory-form newsgroup))
2941 "/" (int-to-string (mail-header-number headers)))
2942 gnus-article-save-directory)))
2944 (string-equal (file-name-directory default)
2945 (file-name-directory last-file))
2946 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2948 (or last-file default))))
2950 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2951 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2952 If variable `gnus-use-long-file-name' is non-nil, it is
2953 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2956 (concat (if (gnus-use-long-file-name 'not-save)
2958 (gnus-newsgroup-directory-form newsgroup))
2959 "/" (int-to-string (mail-header-number headers)))
2960 gnus-article-save-directory)))
2962 (string-equal (file-name-directory default)
2963 (file-name-directory last-file))
2964 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2966 (or last-file default))))
2968 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2969 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2970 If variable `gnus-use-long-file-name' is non-nil, it is
2971 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2974 (if (gnus-use-long-file-name 'not-save)
2977 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2979 gnus-article-save-directory)))
2981 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2982 "Generate file name from sender."
2983 (let ((from (mail-header-from headers)))
2985 (if (and from (string-match "\\([^ <]+\\)@" from))
2986 (match-string 1 from)
2988 gnus-article-save-directory)))
2990 (defun article-verify-x-pgp-sig ()
2993 (if (gnus-buffer-live-p gnus-original-article-buffer)
2994 (let ((sig (with-current-buffer gnus-original-article-buffer
2995 (gnus-fetch-field "X-PGP-Sig")))
2999 (mml2015-clear-verify-function))
3001 (insert-buffer gnus-original-article-buffer)
3002 (setq items (split-string sig))
3003 (message-narrow-to-head)
3004 (let ((inhibit-point-motion-hooks t)
3005 (case-fold-search t))
3006 ;; Don't verify multiple headers.
3007 (setq headers (mapconcat (lambda (header)
3009 (mail-fetch-field header) "\n"))
3010 (split-string (nth 1 items) ",") "")))
3011 (delete-region (point-min) (point-max))
3012 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3013 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3018 (if (looking-at "^-")
3021 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3022 (insert "Version: " (car items) "\n\n")
3023 (insert (mapconcat 'identity (cddr items) "\n"))
3024 (insert "\n-----END PGP SIGNATURE-----\n")
3025 (let ((mm-security-handle (list (format "multipart/signed"))))
3026 (mml2015-clean-buffer)
3027 (let ((coding-system-for-write (or gnus-newsgroup-charset
3029 (funcall (mml2015-clear-verify-function)))
3031 (or (mm-handle-multipart-ctl-parameter
3032 mm-security-handle 'gnus-details)
3033 (mm-handle-multipart-ctl-parameter
3034 mm-security-handle 'gnus-info)))))
3036 (let (buffer-read-only bface eface)
3038 (message-narrow-to-head)
3039 (goto-char (point-max))
3041 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3042 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3043 (message-remove-header "X-Gnus-PGP-Verify")
3044 (if (re-search-forward "^X-PGP-Sig:" nil t)
3046 (goto-char (point-max)))
3047 (narrow-to-region (point) (point))
3048 (insert "X-Gnus-PGP-Verify: " info "\n")
3049 (goto-char (point-min))
3052 (if (not (looking-at "^[ \t]"))
3056 (goto-char (point-min))
3057 (when (looking-at "\\([^:]+\\): *")
3058 (put-text-property (match-beginning 1) (1+ (match-end 1))
3060 (put-text-property (match-end 0) (point-max)
3061 'face eface)))))))))
3068 (setq afunc (car func)
3071 gfunc (intern (format "gnus-%s" func))))
3074 `(lambda (&optional interactive &rest args)
3075 ,(documentation afunc t)
3076 (interactive (list t))
3078 (set-buffer gnus-article-buffer)
3080 (call-interactively ',afunc)
3081 (apply ',afunc args))))))))
3082 '(article-hide-headers
3083 article-verify-x-pgp-sig
3084 article-hide-boring-headers
3085 article-toggle-headers
3086 article-treat-overstrike
3087 article-fill-long-lines
3088 article-capitalize-sentences
3090 article-remove-leading-whitespace
3091 article-display-x-face
3092 article-de-quoted-unreadable
3093 article-de-base64-unreadable
3096 article-hide-list-identifiers
3098 article-strip-banner
3101 article-hide-signature
3102 article-strip-headers-in-body
3103 article-remove-trailing-blank-lines
3104 article-strip-leading-blank-lines
3105 article-strip-multiple-blank-lines
3106 article-strip-leading-space
3107 article-strip-trailing-space
3108 article-strip-blank-lines
3109 article-strip-all-blank-lines
3111 article-date-english
3112 article-date-iso8601
3113 article-date-original
3115 article-decode-mime-words
3116 article-decode-charset
3117 article-decode-encoded-words
3121 article-treat-dumbquotes
3122 article-normalize-headers
3123 (article-show-all-headers . gnus-article-show-all-headers)
3124 (article-show-all . gnus-article-show-all))))
3127 ;;; Gnus article mode
3130 (put 'gnus-article-mode 'mode-class 'special)
3132 (gnus-define-keys gnus-article-mode-map
3133 " " gnus-article-goto-next-page
3134 "\177" gnus-article-goto-prev-page
3135 [delete] gnus-article-goto-prev-page
3136 [backspace] gnus-article-goto-prev-page
3137 "\C-c^" gnus-article-refer-article
3138 "h" gnus-article-show-summary
3139 "s" gnus-article-show-summary
3140 "\C-c\C-m" gnus-article-mail
3141 "?" gnus-article-describe-briefly
3142 "e" gnus-summary-edit-article
3143 "<" beginning-of-buffer
3145 "\C-c\C-i" gnus-info-find-node
3147 "\C-hk" gnus-article-describe-key
3148 "\C-hc" gnus-article-describe-key-briefly
3150 "\C-d" gnus-article-read-summary-keys
3151 "\M-*" gnus-article-read-summary-keys
3152 "\M-#" gnus-article-read-summary-keys
3153 "\M-^" gnus-article-read-summary-keys
3154 "\M-g" gnus-article-read-summary-keys)
3156 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3160 (push (char-to-string key) keys)
3162 (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3163 (setq key (car elem))
3164 (when (and (> (length key) 0)
3165 (not (eq 'menu-bar (aref key 0)))
3166 (symbolp (lookup-key gnus-summary-mode-map key)))
3169 (unless (lookup-key gnus-article-mode-map key)
3170 (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3172 (defun gnus-article-make-menu-bar ()
3173 (unless (boundp 'gnus-article-commands-menu)
3174 (gnus-summary-make-menu-bar))
3175 (gnus-turn-off-edit-menu 'article)
3176 (unless (boundp 'gnus-article-article-menu)
3178 gnus-article-article-menu gnus-article-mode-map ""
3180 ["Scroll forwards" gnus-article-goto-next-page t]
3181 ["Scroll backwards" gnus-article-goto-prev-page t]
3182 ["Show summary" gnus-article-show-summary t]
3183 ["Fetch Message-ID at point" gnus-article-refer-article t]
3184 ["Mail to address at point" gnus-article-mail t]
3185 ["Send a bug report" gnus-bug t]))
3188 gnus-article-treatment-menu gnus-article-mode-map ""
3189 ;; Fixme: this should use :active (and maybe :visible).
3191 ["Hide headers" gnus-article-toggle-headers t]
3192 ["Hide signature" gnus-article-hide-signature t]
3193 ["Hide citation" gnus-article-hide-citation t]
3194 ["Treat overstrike" gnus-article-treat-overstrike t]
3195 ["Remove carriage return" gnus-article-remove-cr t]
3196 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3197 ["Decode HZ" gnus-article-decode-HZ t]))
3199 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3201 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3203 (gnus-run-hooks 'gnus-article-menu-hook)))
3205 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3208 (defun gnus-article-mode ()
3209 "Major mode for displaying an article.
3211 All normal editing commands are switched off.
3213 The following commands are available in addition to all summary mode
3215 \\<gnus-article-mode-map>
3216 \\[gnus-article-next-page]\t Scroll the article one page forwards
3217 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3218 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3219 \\[gnus-article-show-summary]\t Display the summary buffer
3220 \\[gnus-article-mail]\t Send a reply to the address near point
3221 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3222 \\[gnus-info-find-node]\t Go to the Gnus info node"
3224 (gnus-simplify-mode-line)
3225 (setq mode-name "Article")
3226 (setq major-mode 'gnus-article-mode)
3227 (make-local-variable 'minor-mode-alist)
3228 (unless (assq 'gnus-show-mime minor-mode-alist)
3229 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3230 (use-local-map gnus-article-mode-map)
3231 (when (gnus-visual-p 'article-menu 'menu)
3232 (gnus-article-make-menu-bar))
3233 (gnus-update-format-specifications nil 'article-mode)
3234 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3235 (make-local-variable 'gnus-page-broken)
3236 (make-local-variable 'gnus-button-marker-list)
3237 (make-local-variable 'gnus-article-current-summary)
3238 (make-local-variable 'gnus-article-mime-handles)
3239 (make-local-variable 'gnus-article-decoded-p)
3240 (make-local-variable 'gnus-article-mime-handle-alist)
3241 (make-local-variable 'gnus-article-wash-types)
3242 (make-local-variable 'gnus-article-charset)
3243 (make-local-variable 'gnus-article-ignored-charsets)
3244 (gnus-set-default-directory)
3245 (buffer-disable-undo)
3246 (setq buffer-read-only t)
3247 (set-syntax-table gnus-article-mode-syntax-table)
3248 (gnus-run-hooks 'gnus-article-mode-hook))
3250 (defun gnus-article-setup-buffer ()
3251 "Initialize the article buffer."
3252 (let* ((name (if gnus-single-article-buffer "*Article*"
3253 (concat "*Article " gnus-newsgroup-name "*")))
3255 (progn (string-match "\\*Article" name)
3256 (concat " *Original Article"
3257 (substring name (match-end 0))))))
3258 (setq gnus-article-buffer name)
3259 (setq gnus-original-article-buffer original)
3260 (setq gnus-article-mime-handle-alist nil)
3261 ;; This might be a variable local to the summary buffer.
3262 (unless gnus-single-article-buffer
3264 (set-buffer gnus-summary-buffer)
3265 (setq gnus-article-buffer name)
3266 (setq gnus-original-article-buffer original)
3267 (gnus-set-global-variables)))
3268 (gnus-article-setup-highlight-words)
3269 ;; Init original article buffer.
3271 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3272 (set-buffer-multibyte nil)
3273 (setq major-mode 'gnus-original-article-mode)
3274 (make-local-variable 'gnus-original-article))
3275 (if (get-buffer name)
3278 (buffer-disable-undo)
3279 (setq buffer-read-only t)
3280 (unless (eq major-mode 'gnus-article-mode)
3281 (gnus-article-mode))
3284 (set-buffer (gnus-get-buffer-create name))
3286 (make-local-variable 'gnus-summary-buffer)
3287 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3288 (current-buffer)))))
3290 ;; Set article window start at LINE, where LINE is the number of lines
3291 ;; from the head of the article.
3292 (defun gnus-article-set-window-start (&optional line)
3294 (get-buffer-window gnus-article-buffer t)
3296 (set-buffer gnus-article-buffer)
3297 (goto-char (point-min))
3300 (gnus-message 6 "Moved to bookmark")
3301 (search-forward "\n\n" nil t)
3305 ;;; @@ article filters
3308 (defun gnus-article-display-mime-message ()
3309 "Article display method for MIME message."
3310 ;; called from `gnus-original-article-buffer'.
3311 (let (charset all-headers)
3312 (with-current-buffer gnus-summary-buffer
3313 (setq charset default-mime-charset
3314 all-headers gnus-have-all-headers))
3315 (make-local-variable 'default-mime-charset)
3316 (setq default-mime-charset charset)
3317 (with-current-buffer (get-buffer-create gnus-article-buffer)
3318 (make-local-variable 'default-mime-charset)
3319 (setq default-mime-charset charset))
3320 (mime-display-message mime-message-structure
3321 gnus-article-buffer nil gnus-article-mode-map)
3323 (gnus-article-hide-headers nil -1)))
3324 (run-hooks 'gnus-mime-article-prepare-hook))
3326 (defun gnus-article-display-traditional-message ()
3327 "Article display method for traditional message."
3328 (set-buffer gnus-article-buffer)
3329 (let (buffer-read-only)
3331 (insert-buffer-substring gnus-original-article-buffer)))
3333 (defun gnus-article-make-full-mail-header (&optional number charset)
3334 "Create a new mail header structure in a raw article buffer."
3335 (unless (and number charset)
3336 (save-current-buffer
3337 (set-buffer gnus-summary-buffer)
3339 (setq number (or (cdr gnus-article-current) 0)))
3341 (setq charset (or default-mime-charset 'x-ctext)))))
3342 (goto-char (point-min))
3343 (let ((header-end (if (search-forward "\n\n" nil t)
3345 (goto-char (point-max))))
3346 (chars (- (point-max) (point)))
3347 (lines (count-lines (point) (point-max)))
3348 (default-mime-charset charset)
3350 (narrow-to-region (point-min) header-end)
3351 (setq xref (std11-fetch-field "xref"))
3353 (make-full-mail-header
3355 (std11-fetch-field "subject")
3356 (std11-fetch-field "from")
3357 (std11-fetch-field "date")
3358 (std11-fetch-field "message-id")
3359 (std11-fetch-field "references")
3362 (when xref (concat "Xref: " xref)))
3365 (defun gnus-article-prepare (article &optional all-headers header)
3366 "Prepare ARTICLE in article mode buffer.
3367 ARTICLE should either be an article number or a Message-ID.
3368 If ARTICLE is an id, HEADER should be the article headers.
3369 If ALL-HEADERS is non-nil, no headers are hidden."
3371 ;; Make sure we start in a summary buffer.
3372 (unless (eq major-mode 'gnus-summary-mode)
3373 (set-buffer gnus-summary-buffer))
3374 (setq gnus-summary-buffer (current-buffer))
3375 (let* ((gnus-article (if header (mail-header-number header) article))
3376 (summary-buffer (current-buffer))
3377 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3378 (group gnus-newsgroup-name)
3381 (gnus-article-setup-buffer)
3382 (set-buffer gnus-article-buffer)
3383 ;; Deactivate active regions.
3384 (when (and (boundp 'transient-mark-mode)
3385 transient-mark-mode)
3386 (setq mark-active nil))
3387 (if (not (setq result (let ((buffer-read-only nil))
3388 (gnus-request-article-this-buffer
3390 ;; There is no such article.
3392 (when (and (numberp article)
3393 (not (memq article gnus-newsgroup-sparse)))
3394 (setq gnus-article-current
3395 (cons gnus-newsgroup-name article))
3396 (set-buffer gnus-summary-buffer)
3397 (setq gnus-current-article article)
3398 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3400 (gnus-summary-set-agent-mark article)
3401 (message "Message marked for downloading"))
3402 (gnus-summary-mark-article article gnus-canceled-mark)
3403 (unless (memq article gnus-newsgroup-sparse)
3404 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3405 (if (or (eq result 'pseudo)
3406 (eq result 'nneething))
3409 (set-buffer summary-buffer)
3410 (push article gnus-newsgroup-history)
3411 (setq gnus-last-article gnus-current-article
3412 gnus-current-article 0
3413 gnus-current-headers nil
3414 gnus-article-current nil)
3415 (if (eq result 'nneething)
3416 (gnus-configure-windows 'summary)
3417 (gnus-configure-windows 'article))
3418 (gnus-set-global-variables))
3419 (let ((gnus-article-mime-handle-alist-1
3420 gnus-article-mime-handle-alist))
3421 (gnus-set-mode-line 'article)))
3422 ;; The result from the `request' was an actual article -
3423 ;; or at least some text that is now displayed in the
3425 (when (and (numberp article)
3426 (not (eq article gnus-current-article)))
3427 ;; Seems like a new article has been selected.
3428 ;; `gnus-current-article' must be an article number.
3430 (set-buffer summary-buffer)
3431 (push article gnus-newsgroup-history)
3432 (setq gnus-last-article gnus-current-article
3433 gnus-current-article article
3434 gnus-current-headers
3435 (gnus-summary-article-header gnus-current-article)
3436 gnus-article-current
3437 (cons gnus-newsgroup-name gnus-current-article))
3438 (unless (vectorp gnus-current-headers)
3439 (setq gnus-current-headers nil))
3440 (gnus-summary-goto-subject gnus-current-article)
3441 (when (gnus-summary-show-thread)
3442 ;; If the summary buffer really was folded, the
3443 ;; previous goto may not actually have gone to
3444 ;; the right article, but the thread root instead.
3446 (gnus-summary-goto-subject gnus-current-article))
3447 (gnus-run-hooks 'gnus-mark-article-hook)
3448 (gnus-set-mode-line 'summary)
3449 (when (gnus-visual-p 'article-highlight 'highlight)
3450 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3451 ;; Set the global newsgroup variables here.
3452 (gnus-set-global-variables)
3453 (setq gnus-have-all-headers
3454 (or all-headers gnus-show-all-headers))))
3456 (gnus-configure-windows 'article))
3457 (when (or (numberp article)
3459 (gnus-article-prepare-display)
3461 (goto-char (point-min))
3462 (setq gnus-page-broken
3463 (when gnus-break-pages
3464 (gnus-narrow-to-page)
3466 (let ((gnus-article-mime-handle-alist-1
3467 gnus-article-mime-handle-alist))
3468 (gnus-set-mode-line 'article))
3470 (set-window-point (get-buffer-window (current-buffer)) (point))
3471 (gnus-configure-windows 'article)
3474 (defun gnus-article-prepare-mime-display (&optional number)
3475 (goto-char (point-min))
3476 (when (re-search-forward "^[^\t ]+:" nil t)
3477 (goto-char (match-beginning 0)))
3478 (let ((entity (if (eq 1 (point-min))
3479 (get-text-property 1 'mime-view-entity)
3480 (get-text-property (point) 'mime-view-entity)))
3481 last-entity child-entity next type)
3482 (setq child-entity (mime-entity-children entity))
3484 (setq last-entity (nth (1- (length child-entity))
3486 (setq last-entity entity))
3488 (narrow-to-region (point)
3489 (if (search-forward "\n\n" nil t)
3492 (gnus-treat-article 'head)
3493 (put-text-property (point-min) (point-max) 'article-treated-header t)
3494 (goto-char (point-max)))
3495 (while (and (not (eobp)) entity)
3496 (setq next (set-marker
3498 (next-single-property-change (point) 'mime-view-entity
3500 (let ((types (mime-entity-content-type entity)))
3501 (while (eq 'multipart (mime-content-type-primary-type types))
3502 (setq entity (car (mime-entity-children entity))
3503 types (mime-entity-content-type entity)))
3505 (setq type (format "%s/%s"
3506 (mime-content-type-primary-type types)
3507 (mime-content-type-subtype types)))))
3508 (if (string-equal type "message/rfc822")
3511 (let ((children (mime-entity-children entity))
3514 (setq last-children (nth (1- (length children)) children))
3517 (not (eq last-children
3518 (get-text-property next 'mime-view-entity)))
3520 (next-single-property-change next
3522 nil (point-max)))))))
3523 (setq next (next-single-property-change next 'mime-view-entity
3526 (narrow-to-region (point) next)
3527 (gnus-article-prepare-mime-display)
3528 (goto-char (point-max)))
3529 (setq entity (get-text-property (point) 'mime-view-entity)))
3531 (narrow-to-region (point) next)
3532 ;; Kludge. We have to count true number, but for now,
3533 ;; part number is here only to achieve `last'.
3534 (gnus-treat-article nil 1
3535 (if (eq entity last-entity)
3538 (goto-char (point-max)))
3539 (setq entity (get-text-property next 'mime-view-entity))))))
3542 (defun gnus-article-prepare-display ()
3543 "Make the current buffer look like a nice article."
3544 (let ((gnus-article-buffer (current-buffer))
3546 (unless (eq major-mode 'gnus-article-mode)
3547 (gnus-article-mode))
3548 (setq buffer-read-only nil
3549 gnus-button-marker-list nil
3550 gnus-article-wash-types nil)
3553 (static-if (featurep 'xemacs)
3554 (map-extents (lambda (extent maparg) (delete-extent extent)))
3555 (let ((lists (overlay-lists)))
3556 (dolist (overlay (nconc (car lists) (cdr lists)))
3557 (delete-overlay overlay)))))
3558 (gnus-run-hooks 'gnus-tmp-internal-hook))
3559 (set-buffer gnus-original-article-buffer)
3561 (setq mime-message-structure gnus-current-headers)
3562 (mime-buffer-entity-set-buffer-internal mime-message-structure
3563 gnus-original-article-buffer)
3564 (mime-entity-set-representation-type-internal mime-message-structure
3565 'mime-buffer-entity)
3566 (luna-send mime-message-structure 'initialize-instance
3567 mime-message-structure)
3569 (let (mime-display-header-hook mime-display-text/plain-hook)
3570 (funcall gnus-article-display-method-for-mime))
3571 (funcall gnus-article-display-method-for-traditional))
3572 ;; Call the treatment functions.
3573 (let ((inhibit-read-only t))
3577 (gnus-article-prepare-mime-display)
3578 (narrow-to-region (goto-char (point-min))
3579 (if (search-forward "\n\n" nil t)
3582 (gnus-treat-article 'head)
3583 (put-text-property (point-min) (point-max) 'article-treated-header t)
3584 (goto-char (point-max))
3586 (narrow-to-region (point) (point-max))
3587 (gnus-treat-article nil))
3588 (put-text-property (point-min) (point-max) 'read-only nil)))
3589 (gnus-run-hooks 'gnus-article-prepare-hook))
3591 (defun gnus-article-decode-article-as-default-mime-charset ()
3592 "Decode an article as `default-mime-charset'. It won't work if the
3593 value of the variable `gnus-show-mime' is non-nil."
3594 (unless gnus-show-mime
3595 (set (make-local-variable 'default-mime-charset)
3596 (with-current-buffer gnus-summary-buffer
3597 default-mime-charset))
3598 (decode-mime-charset-region (point-min) (point-max)
3599 default-mime-charset)))
3602 ;;; Gnus MIME viewing functions
3605 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3606 "The following specs can be used:
3608 %T MIME type, along with additional info
3609 %n The `name' parameter
3610 %d The description, if any
3611 %l The length of the encoded part
3612 %p The part identifier number
3613 %e Dots if the part isn't displayed")
3615 (defvar gnus-mime-button-line-format-alist
3616 '((?t gnus-tmp-type ?s)
3617 (?T gnus-tmp-type-long ?s)
3618 (?n gnus-tmp-name ?s)
3619 (?d gnus-tmp-description ?s)
3621 (?l gnus-tmp-length ?d)
3622 (?e gnus-tmp-dots ?s)))
3624 (defvar gnus-mime-button-commands
3625 '((gnus-article-press-button "\r" "Toggle Display")
3626 (gnus-mime-view-part "v" "View Interactively...")
3627 (gnus-mime-view-part-as-type "t" "View As Type...")
3628 (gnus-mime-view-part-as-charset "C" "View As charset...")
3629 (gnus-mime-save-part "o" "Save...")
3630 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3631 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3632 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3633 (gnus-mime-internalize-part "E" "View Internally")
3634 (gnus-mime-externalize-part "e" "View Externally")
3635 (gnus-mime-pipe-part "|" "Pipe To Command...")
3636 (gnus-mime-action-on-part "." "Take action on the part")))
3638 (defun gnus-article-mime-part-status ()
3639 (with-current-buffer gnus-article-buffer
3640 (let ((entity (get-text-property (point-min) 'mime-view-entity))
3643 (setq children (mime-entity-children entity))
3644 (setq children (length children)))
3647 (format " (%d parts)" children))
3650 (defvar gnus-mime-button-map
3651 (let ((map (make-sparse-keymap)))
3652 (unless (>= (string-to-number emacs-version) 21)
3653 ;; XEmacs doesn't care.
3654 (set-keymap-parent map gnus-article-mode-map))
3655 (define-key map gnus-mouse-2 'gnus-article-push-button)
3656 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3657 (dolist (c gnus-mime-button-commands)
3658 (define-key map (cadr c) (car c)))
3661 (defun gnus-mime-button-menu (event)
3662 "Construct a context-sensitive menu of MIME commands."
3664 (save-window-excursion
3665 (let ((pos (event-start event)))
3666 (select-window (posn-window pos))
3667 (goto-char (posn-point pos))
3668 (gnus-article-check-buffer)
3669 (let ((response (x-popup-menu
3671 ("" ,@(mapcar (lambda (c)
3672 (cons (caddr c) (car c)))
3673 gnus-mime-button-commands))))))
3675 (call-interactively response))))))
3677 (defun gnus-mime-view-all-parts (&optional handles)
3678 "View all the MIME parts."
3680 (save-current-buffer
3681 (set-buffer gnus-article-buffer)
3682 (let ((handles (or handles gnus-article-mime-handles))
3683 (mail-parse-charset gnus-newsgroup-charset)
3684 (mail-parse-ignored-charsets
3685 (with-current-buffer gnus-summary-buffer
3686 gnus-newsgroup-ignored-charsets)))
3688 (mm-remove-parts handles)
3689 (goto-char (point-min))
3690 (or (search-forward "\n\n") (goto-char (point-max)))
3691 (let (buffer-read-only)
3692 (delete-region (point) (point-max))
3693 (mm-display-parts handles))))))
3695 (defun gnus-mime-save-part-and-strip ()
3696 "Save the MIME part under point then replace it with an external body."
3698 (gnus-article-check-buffer)
3699 (let* ((data (get-text-property (point) 'gnus-data))
3701 (handles gnus-article-mime-handles))
3702 (if (mm-multiple-handles gnus-article-mime-handles)
3703 (error "This function is not implemented"))
3704 (setq file (and data (mm-save-part data)))
3706 (with-current-buffer (mm-handle-buffer data)
3708 (insert "Content-Type: " (mm-handle-media-type data))
3709 (mml-insert-parameter-string (cdr (mm-handle-type data))
3712 (insert "Content-ID: " (message-make-message-id) "\n")
3713 (insert "Content-Transfer-Encoding: binary\n")
3716 (cdr (mm-make-handle nil
3717 `("message/external-body"
3718 (access-type . "LOCAL-FILE")
3720 (set-buffer gnus-summary-buffer)
3721 (gnus-article-edit-article
3724 (let ((mail-parse-charset (or gnus-article-charset
3725 ',gnus-newsgroup-charset))
3726 (mail-parse-ignored-charsets
3727 (or gnus-article-ignored-charsets
3728 ',gnus-newsgroup-ignored-charsets))
3729 (mbl mml-buffer-list))
3730 (setq mml-buffer-list nil)
3731 (insert-buffer gnus-original-article-buffer)
3732 (mime-to-mml ',handles)
3733 (setq gnus-article-mime-handles nil)
3734 (let ((mbl1 mml-buffer-list))
3735 (setq mml-buffer-list mbl)
3736 (set (make-local-variable 'mml-buffer-list) mbl1))
3737 ;; LOCAL argument of add-hook differs between GNU Emacs
3738 ;; and XEmacs. make-local-hook makes sure they are local.
3739 (make-local-hook 'kill-buffer-hook)
3740 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3741 `(lambda (no-highlight)
3742 (let ((mail-parse-charset (or gnus-article-charset
3743 ',gnus-newsgroup-charset))
3744 (message-options message-options)
3745 (message-options-set-recipient)
3746 (mail-parse-ignored-charsets
3747 (or gnus-article-ignored-charsets
3748 ',gnus-newsgroup-ignored-charsets)))
3750 (mml-destroy-buffers)
3751 (remove-hook 'kill-buffer-hook
3752 'mml-destroy-buffers t)
3753 (kill-local-variable 'mml-buffer-list))
3754 (gnus-summary-edit-article-done
3755 ,(or (mail-header-references gnus-current-headers) "")
3756 ,(gnus-group-read-only-p)
3757 ,gnus-summary-buffer no-highlight))))))
3759 (defun gnus-mime-save-part ()
3760 "Save the MIME part under point."
3762 (gnus-article-check-buffer)
3763 (let ((data (get-text-property (point) 'gnus-data)))
3765 (mm-save-part data))))
3767 (defun gnus-mime-pipe-part ()
3768 "Pipe the MIME part under point to a process."
3770 (gnus-article-check-buffer)
3771 (let ((data (get-text-property (point) 'gnus-data)))
3773 (mm-pipe-part data))))
3775 (defun gnus-mime-view-part ()
3776 "Interactively choose a viewing method for the MIME part under point."
3778 (gnus-article-check-buffer)
3779 (let ((data (get-text-property (point) 'gnus-data)))
3781 (setq gnus-article-mime-handles
3783 gnus-article-mime-handles (setq data (copy-sequence data))))
3784 (mm-interactively-view-part data))))
3786 (defun gnus-mime-view-part-as-type-internal ()
3787 (gnus-article-check-buffer)
3788 (let* ((name (mail-content-type-get
3789 (mm-handle-type (get-text-property (point) 'gnus-data))
3791 (def-type (and name (mm-default-file-encoding name))))
3792 (and def-type (cons def-type 0))))
3794 (defun gnus-mime-view-part-as-type (&optional mime-type)
3795 "Choose a MIME media type, and view the part as such."
3798 (setq mime-type (completing-read
3799 "View as MIME type: "
3800 (mapcar #'list (mailcap-mime-types))
3802 (gnus-mime-view-part-as-type-internal))))
3803 (gnus-article-check-buffer)
3804 (let ((handle (get-text-property (point) 'gnus-data)))
3807 (mm-make-handle (mm-handle-buffer handle)
3808 (cons mime-type (cdr (mm-handle-type handle)))
3809 (mm-handle-encoding handle)
3810 (mm-handle-undisplayer handle)
3811 (mm-handle-disposition handle)
3812 (mm-handle-description handle)
3814 (mm-handle-id handle)))
3815 (setq gnus-article-mime-handles
3816 (mm-merge-handles gnus-article-mime-handles handle))
3817 (gnus-mm-display-part handle))))
3819 (defun gnus-mime-copy-part (&optional handle)
3820 "Put the the MIME part under point into a new buffer."
3822 (gnus-article-check-buffer)
3823 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3824 (contents (and handle (mm-get-part handle)))
3826 (file-name-nondirectory
3828 (mail-content-type-get (mm-handle-type handle) 'name)
3829 (mail-content-type-get (mm-handle-type handle)
3832 (buffer (and base (generate-new-buffer base))))
3834 (switch-to-buffer buffer)
3836 ;; We do it this way to make `normal-mode' set the appropriate mode.
3839 (setq buffer-file-name (expand-file-name base))
3841 (setq buffer-file-name nil))
3842 (goto-char (point-min)))))
3844 (defun gnus-mime-inline-part (&optional handle arg)
3845 "Insert the MIME part under point into the current buffer."
3846 (interactive (list nil current-prefix-arg))
3847 (gnus-article-check-buffer)
3848 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3853 (if (and (not arg) (mm-handle-undisplayer handle))
3854 (mm-remove-part handle)
3855 (setq contents (mm-get-part handle))
3858 (setq charset (or (mail-content-type-get
3859 (mm-handle-type handle) 'charset)
3860 gnus-newsgroup-charset)))
3862 (if (mm-handle-undisplayer handle)
3863 (mm-remove-part handle))
3866 gnus-summary-show-article-charset-alist))
3867 (mm-read-coding-system "Charset: ")))))
3869 (mm-insert-inline handle
3871 (setq charset (mm-charset-to-coding-system
3873 (not (eq charset 'ascii)))
3874 (mm-decode-coding-string contents charset)
3878 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3879 "Insert the MIME part under point into the current buffer using the
3881 (interactive (list nil current-prefix-arg))
3882 (gnus-article-check-buffer)
3883 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3888 (if (mm-handle-undisplayer handle)
3889 (mm-remove-part handle))
3890 (let ((gnus-newsgroup-charset
3892 gnus-summary-show-article-charset-alist))
3893 (mm-read-coding-system "Charset: ")))
3894 (gnus-newsgroup-ignored-charsets 'gnus-all))
3895 (gnus-article-press-button)))))
3897 (defun gnus-mime-externalize-part (&optional handle)
3898 "View the MIME part under point with an external viewer."
3900 (gnus-article-check-buffer)
3901 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3902 (mm-user-display-methods nil)
3903 (mm-inlined-types nil)
3904 (mail-parse-charset gnus-newsgroup-charset)
3905 (mail-parse-ignored-charsets
3906 (save-excursion (set-buffer gnus-summary-buffer)
3907 gnus-newsgroup-ignored-charsets)))
3909 (if (mm-handle-undisplayer handle)
3910 (mm-remove-part handle)
3911 (mm-display-part handle)))))
3913 (defun gnus-mime-internalize-part (&optional handle)
3914 "View the MIME part under point with an internal viewer.
3915 If no internal viewer is available, use an external viewer."
3917 (gnus-article-check-buffer)
3918 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3919 (mm-inlined-types '(".*"))
3920 (mm-inline-large-images t)
3921 (mail-parse-charset gnus-newsgroup-charset)
3922 (mail-parse-ignored-charsets
3923 (save-excursion (set-buffer gnus-summary-buffer)
3924 gnus-newsgroup-ignored-charsets)))
3926 (if (mm-handle-undisplayer handle)
3927 (mm-remove-part handle)
3928 (mm-display-part handle)))))
3930 (defun gnus-mime-action-on-part (&optional action)
3931 "Do something with the MIME attachment at \(point\)."
3933 (list (completing-read "Action: " gnus-mime-action-alist)))
3934 (gnus-article-check-buffer)
3935 (let ((action-pair (assoc action gnus-mime-action-alist)))
3937 (funcall (cdr action-pair)))))
3939 (defun gnus-article-part-wrapper (n function)
3940 (save-current-buffer
3941 (set-buffer gnus-article-buffer)
3942 (when (> n (length gnus-article-mime-handle-alist))
3943 (error "No such part"))
3944 (gnus-article-goto-part n)
3945 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3946 (funcall function handle))))
3948 (defun gnus-article-pipe-part (n)
3949 "Pipe MIME part N, which is the numerical prefix."
3951 (gnus-article-part-wrapper n 'mm-pipe-part))
3953 (defun gnus-article-save-part (n)
3954 "Save MIME part N, which is the numerical prefix."
3956 (gnus-article-part-wrapper n 'mm-save-part))
3958 (defun gnus-article-interactively-view-part (n)
3959 "View MIME part N interactively, which is the numerical prefix."
3961 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3963 (defun gnus-article-copy-part (n)
3964 "Copy MIME part N, which is the numerical prefix."
3966 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3968 (defun gnus-article-view-part-as-charset (n)
3969 "Copy MIME part N, which is the numerical prefix."
3971 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3973 (defun gnus-article-externalize-part (n)
3974 "View MIME part N externally, which is the numerical prefix."
3976 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3978 (defun gnus-article-inline-part (n)
3979 "Inline MIME part N, which is the numerical prefix."
3981 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3983 (defun gnus-article-mime-match-handle-first (condition)
3985 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3986 (while (setq ihandle (pop alist))
3988 ((functionp condition)
3989 (funcall condition (cdr ihandle)))
3990 ((eq condition 'undisplayed)
3991 (not (or (mm-handle-undisplayer (cdr ihandle))
3992 (equal (mm-handle-media-type (cdr ihandle))
3993 "multipart/alternative"))))
3994 ((eq condition 'undisplayed-alternative)
3995 (not (mm-handle-undisplayer (cdr ihandle))))
3997 (gnus-article-goto-part (car ihandle))
3998 (or (not n) (< (car ihandle) n)))
3999 (setq n (car ihandle))))
4003 (defun gnus-article-view-part (&optional n)
4004 "View MIME part N, which is the numerical prefix."
4006 (save-current-buffer
4007 (set-buffer gnus-article-buffer)
4008 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4009 gnus-article-mime-match-handle-function)))
4010 (when (> n (length gnus-article-mime-handle-alist))
4011 (error "No such part"))
4012 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4013 (when (gnus-article-goto-part n)
4014 (if (equal (car handle) "multipart/alternative")
4015 (gnus-article-press-button)
4016 (when (eq (gnus-mm-display-part handle) 'internal)
4017 (gnus-set-window-start)))))))
4019 (defsubst gnus-article-mime-total-parts ()
4020 (if (bufferp (car gnus-article-mime-handles))
4022 (1- (length gnus-article-mime-handles))))
4024 (defun gnus-mm-display-part (handle)
4025 "Display HANDLE and fix MIME button."
4026 (let ((id (get-text-property (point) 'gnus-part))
4031 (let ((window (selected-window))
4032 (mail-parse-charset gnus-newsgroup-charset)
4033 (mail-parse-ignored-charsets
4034 (save-excursion (set-buffer gnus-summary-buffer)
4035 gnus-newsgroup-ignored-charsets)))
4038 (let ((win (get-buffer-window (current-buffer) t))
4041 (select-window win))
4044 (if (mm-handle-displayed-p handle)
4045 ;; This will remove the part.
4046 (mm-display-part handle)
4048 (narrow-to-region (point)
4049 (if (eobp) (point) (1+ (point))))
4050 (mm-display-part handle)
4051 ;; We narrow to the part itself and
4052 ;; then call the treatment functions.
4053 (goto-char (point-min))
4055 (narrow-to-region (point) (point-max))
4058 (gnus-article-mime-total-parts)
4059 (mm-handle-media-type handle)))))
4060 (if (window-live-p window)
4061 (select-window window)))))
4063 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4064 (gnus-insert-mime-button
4065 handle id (list (mm-handle-displayed-p handle)))
4066 (goto-char point))))
4068 (defun gnus-article-goto-part (n)
4069 "Go to MIME part N."
4070 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4072 (goto-char point))))
4074 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4075 (let ((gnus-tmp-name
4076 (or (mail-content-type-get (mm-handle-type handle)
4078 (mail-content-type-get (mm-handle-disposition handle)
4080 (mail-content-type-get (mm-handle-type handle)
4083 (gnus-tmp-type (mm-handle-media-type handle))
4084 (gnus-tmp-description
4085 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4088 (if (if displayed (car displayed)
4089 (mm-handle-displayed-p handle))
4091 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4093 gnus-tmp-type-long b e)
4094 (when (string-match ".*/" gnus-tmp-name)
4095 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4096 (setq gnus-tmp-type-long (concat gnus-tmp-type
4097 (and (not (equal gnus-tmp-name ""))
4098 (concat "; " gnus-tmp-name))))
4099 (or (equal gnus-tmp-description "")
4100 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4105 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4106 `(keymap ,gnus-mime-button-map
4107 ,@(if (>= (string-to-number emacs-version) 21)
4109 (list 'local-map gnus-mime-button-map))
4110 gnus-callback gnus-mm-display-part
4111 gnus-part ,gnus-tmp-id
4112 article-type annotation
4115 (widget-convert-button
4118 :action 'gnus-widget-press-button
4119 :button-keymap gnus-mime-button-map
4121 (lambda (widget/window &optional overlay pos)
4122 ;; Needed to properly clear the message due to a bug in
4123 ;; wid-edit (XEmacs only).
4124 (if (boundp 'help-echo-owns-message)
4125 (setq help-echo-owns-message t))
4127 "%S: %s the MIME part; %S: more options"
4128 (aref gnus-mouse-2 0)
4129 ;; XEmacs will get a single widget arg; Emacs 21 will get
4130 ;; window, overlay, position.
4131 (if (mm-handle-displayed-p
4133 (with-current-buffer (gnus-overlay-buffer overlay)
4134 (widget-get (widget-at (gnus-overlay-start overlay))
4136 (widget-get widget/window :mime-handle)))
4138 (aref gnus-down-mouse-3 0))))))
4140 (defun gnus-widget-press-button (elems el)
4141 (goto-char (widget-get elems :from))
4142 (gnus-article-press-button))
4144 (defvar gnus-displaying-mime nil)
4146 (defun gnus-display-mime (&optional ihandles)
4147 "Display the MIME parts."
4149 (save-selected-window
4150 (let ((window (get-buffer-window gnus-article-buffer))
4153 (select-window window)
4154 ;; We have to do this since selecting the window
4155 ;; may change the point. So we set the window point.
4156 (set-window-point window point)))
4157 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
4158 buffer-read-only handle name type b e display)
4159 (when (and (not ihandles)
4160 (not gnus-displaying-mime))
4161 ;; Top-level call; we clean up.
4162 (when gnus-article-mime-handles
4163 (mm-destroy-parts gnus-article-mime-handles)
4164 (setq gnus-article-mime-handle-alist nil));; A trick.
4165 (setq gnus-article-mime-handles handles)
4166 ;; We allow users to glean info from the handles.
4167 (when gnus-article-mime-part-function
4168 (gnus-mime-part-function handles)))
4170 (or (not (stringp (car handles)))
4173 (when (and (not ihandles)
4174 (not gnus-displaying-mime))
4175 ;; Clean up for mime parts.
4177 (delete-region (point) (point-max)))
4178 (let ((gnus-displaying-mime t))
4179 (gnus-mime-display-part handles)))
4182 (narrow-to-region (point) (point-max))
4183 (gnus-treat-article nil 1 1)
4186 ;; Highlight the headers.
4190 (narrow-to-region (point-min) (point))
4191 (gnus-treat-article 'head))))))))
4193 (defvar gnus-mime-display-multipart-as-mixed nil)
4194 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
4195 (defvar gnus-mime-display-multipart-related-as-mixed nil)
4197 (defun gnus-mime-display-part (handle)
4200 ((not (stringp (car handle)))
4201 (gnus-mime-display-single handle))
4202 ;; User-defined multipart
4203 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4204 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4206 ;; multipart/alternative
4207 ((and (equal (car handle) "multipart/alternative")
4208 (not (or gnus-mime-display-multipart-as-mixed
4209 gnus-mime-display-multipart-alternative-as-mixed)))
4210 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4211 (push (cons id handle) gnus-article-mime-handle-alist)
4212 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4213 ;; multipart/related
4214 ((and (equal (car handle) "multipart/related")
4215 (not (or gnus-mime-display-multipart-as-mixed
4216 gnus-mime-display-multipart-related-as-mixed)))
4217 ;;;!!!We should find the start part, but we just default
4218 ;;;!!!to the first part.
4219 ;;(gnus-mime-display-part (cadr handle))
4220 ;;;!!! Most multipart/related is an HTML message plus images.
4221 ;;;!!! Unfortunately we are unable to let W3 display those
4222 ;;;!!! included images, so we just display it as a mixed multipart.
4223 ;;(gnus-mime-display-mixed (cdr handle))
4224 ;;;!!! No, w3 can display everything just fine.
4225 (gnus-mime-display-part (cadr handle)))
4226 ((equal (car handle) "multipart/signed")
4227 (or (memq 'signed gnus-article-wash-types)
4228 (push 'signed gnus-article-wash-types))
4229 (gnus-mime-display-security handle))
4230 ((equal (car handle) "multipart/encrypted")
4231 (or (memq 'encrypted gnus-article-wash-types)
4232 (push 'encrypted gnus-article-wash-types))
4233 (gnus-mime-display-security handle))
4234 ;; Other multiparts are handled like multipart/mixed.
4236 (gnus-mime-display-mixed (cdr handle)))))
4238 (defun gnus-mime-part-function (handles)
4239 (if (stringp (car handles))
4240 (mapcar 'gnus-mime-part-function (cdr handles))
4241 (funcall gnus-article-mime-part-function handles)))
4243 (defun gnus-mime-display-mixed (handles)
4244 (mapcar 'gnus-mime-display-part handles))
4246 (defun gnus-mime-display-single (handle)
4247 (let ((type (mm-handle-media-type handle))
4248 (ignored gnus-ignored-mime-types)
4255 (when (string-match (pop ignored) type)
4256 (throw 'ignored nil)))
4257 (if (and (setq not-attachment
4258 (and (not (mm-inline-override-p handle))
4259 (or (not (mm-handle-disposition handle))
4260 (equal (car (mm-handle-disposition handle))
4262 (mm-attachment-override-p handle))))
4263 (mm-automatic-display-p handle)
4265 (mm-inlinable-p handle)
4266 (mm-inlined-p handle))
4267 (mm-automatic-external-display-p type)))
4269 (when (equal (mm-handle-media-supertype handle) "text")
4271 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4273 (push (cons id handle) gnus-article-mime-handle-alist)
4274 (when (or (not display)
4275 (not (gnus-unbuttonized-mime-type-p type)))
4276 ;(gnus-article-insert-newline)
4277 (gnus-insert-mime-button
4278 handle id (list (or display (and not-attachment text))))
4279 (gnus-article-insert-newline)
4280 ;(gnus-article-insert-newline)
4281 ;; Remember modify the number of forward lines.
4289 (let ((mail-parse-charset gnus-newsgroup-charset)
4290 (mail-parse-ignored-charsets
4291 (save-excursion (condition-case ()
4292 (set-buffer gnus-summary-buffer)
4294 gnus-newsgroup-ignored-charsets)))
4295 (mm-display-part handle t))
4296 (goto-char (point-max)))
4297 ((and text not-attachment)
4301 (gnus-article-insert-newline)
4302 (mm-insert-inline handle (mm-get-part handle))
4303 (goto-char (point-max))))
4307 (narrow-to-region beg (point))
4310 (gnus-article-mime-total-parts)
4311 (mm-handle-media-type handle)))))))))
4313 (defun gnus-unbuttonized-mime-type-p (type)
4314 "Say whether TYPE is to be unbuttonized."
4315 (unless gnus-inhibit-mime-unbuttonizing
4317 (let ((types gnus-unbuttonized-mime-types))
4319 (when (string-match (pop types) type)
4320 (throw 'found t)))))))
4322 (defun gnus-article-insert-newline ()
4323 "Insert a newline, but mark it as undeletable."
4324 (gnus-put-text-property
4325 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4327 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4328 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4331 handle buffer-read-only from props begend not-pref)
4332 (save-window-excursion
4335 (narrow-to-region (car ibegend)
4338 (goto-char (car ibegend))
4341 (delete-region (point-min) (point-max))
4342 (mm-remove-parts handles))
4343 (setq begend (list (point-marker)))
4345 (unless (setq not-pref (cadr (member preferred ihandles)))
4346 (setq not-pref (car ihandles)))
4349 (not (gnus-unbuttonized-mime-type-p
4350 "multipart/alternative")))
4351 (gnus-add-text-properties
4354 (insert (format "%d. " id))
4358 (unless ,(not ibegend)
4359 (setq gnus-article-mime-handle-alist
4360 ',gnus-article-mime-handle-alist))
4361 (gnus-mime-display-alternative
4362 ',ihandles ',not-pref ',begend ,id))
4363 ,@(if (>= (string-to-number emacs-version) 21)
4364 nil ;; XEmacs doesn't care
4365 (list 'local-map gnus-mime-button-map))
4366 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4367 face ,gnus-article-button-face
4368 keymap ,gnus-mime-button-map
4371 (widget-convert-button 'link from (point)
4372 :action 'gnus-widget-press-button
4373 :button-keymap gnus-widget-button-keymap)
4375 (while (setq handle (pop handles))
4376 (gnus-add-text-properties
4379 (insert (format "(%c) %-18s"
4380 (if (equal handle preferred) ?* ? )
4381 (mm-handle-media-type handle)))
4385 (unless ,(not ibegend)
4386 (setq gnus-article-mime-handle-alist
4387 ',gnus-article-mime-handle-alist))
4388 (gnus-mime-display-alternative
4389 ',ihandles ',handle ',begend ,id))
4390 ,@(if (>= (string-to-number emacs-version) 21)
4391 nil ;; XEmacs doesn't care
4392 (list 'local-map gnus-mime-button-map))
4393 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4394 face ,gnus-article-button-face
4395 keymap ,gnus-mime-button-map
4398 (widget-convert-button 'link from (point)
4399 :action 'gnus-widget-press-button
4400 :button-keymap gnus-widget-button-keymap)
4404 (if (stringp (car preferred))
4405 (gnus-display-mime preferred)
4406 (let ((mail-parse-charset gnus-newsgroup-charset)
4407 (mail-parse-ignored-charsets
4408 (save-excursion (set-buffer gnus-summary-buffer)
4409 gnus-newsgroup-ignored-charsets)))
4410 (mm-display-part preferred)
4414 (narrow-to-region (car begend) (point-max))
4416 nil (length gnus-article-mime-handle-alist)
4417 (gnus-article-mime-total-parts)
4418 (mm-handle-media-type handle))))))
4419 (goto-char (point-max))
4420 (setcdr begend (point-marker)))))
4422 (goto-char point))))
4424 (defun gnus-article-wash-status ()
4425 "Return a string which display status of article washing."
4427 (set-buffer gnus-article-buffer)
4428 (let ((cite (memq 'cite gnus-article-wash-types))
4429 (headers (memq 'headers gnus-article-wash-types))
4430 (boring (memq 'boring-headers gnus-article-wash-types))
4431 (pgp (memq 'pgp gnus-article-wash-types))
4432 (pem (memq 'pem gnus-article-wash-types))
4433 (signed (memq 'signed gnus-article-wash-types))
4434 (encrypted (memq 'encrypted gnus-article-wash-types))
4435 (signature (memq 'signature gnus-article-wash-types))
4436 (overstrike (memq 'overstrike gnus-article-wash-types))
4437 (emphasis (memq 'emphasis gnus-article-wash-types)))
4438 (format "%c%c%c%c%c%c%c"
4440 (if (or headers boring) ?h ? )
4441 (if (or pgp pem signed encrypted) ?p ? )
4442 (if signature ?s ? )
4443 (if overstrike ?o ? )
4444 (if gnus-show-mime ?m ? )
4445 (if emphasis ?e ? )))))
4447 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4449 (defun gnus-article-maybe-hide-headers ()
4450 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4451 Provided for backwards compatibility."
4452 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4453 (not (save-excursion (set-buffer gnus-summary-buffer)
4454 gnus-have-all-headers)))
4455 (not gnus-inhibit-hiding))
4456 (gnus-article-hide-headers)))
4460 (defun gnus-output-to-file (file-name)
4461 "Append the current article to a file named FILE-NAME."
4462 (let ((artbuf (current-buffer)))
4464 (insert-buffer-substring artbuf)
4465 ;; Append newline at end of the buffer as separator, and then
4467 (goto-char (point-max))
4469 (let ((file-name-coding-system nnmail-pathname-coding-system)
4470 (pathname-coding-system nnmail-pathname-coding-system))
4471 (write-region-as-binary (point-min) (point-max) file-name 'append))
4474 (defun gnus-narrow-to-page (&optional arg)
4475 "Narrow the article buffer to a page.
4476 If given a numerical ARG, move forward ARG pages."
4478 (setq arg (if arg (prefix-numeric-value arg) 0))
4480 (set-buffer gnus-article-buffer)
4481 (goto-char (point-min))
4483 ;; Remove any old next/prev buttons.
4484 (when (gnus-visual-p 'page-marker)
4485 (let ((buffer-read-only nil))
4486 (gnus-remove-text-with-property 'gnus-prev)
4487 (gnus-remove-text-with-property 'gnus-next)))
4490 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4492 (re-search-forward page-delimiter nil 'move arg)))
4493 (goto-char (match-end 0)))
4496 (if (re-search-forward page-delimiter nil 'move)
4499 (when (and (gnus-visual-p 'page-marker)
4500 (not (= (point-min) 1)))
4502 (goto-char (point-min))
4503 (gnus-insert-prev-page-button)))
4504 (when (and (gnus-visual-p 'page-marker)
4505 (< (+ (point-max) 2) (buffer-size)))
4507 (goto-char (point-max))
4508 (gnus-insert-next-page-button)))))
4510 ;; Article mode commands
4512 (defun gnus-article-goto-next-page ()
4513 "Show the next page of the article."
4515 (when (gnus-article-next-page)
4516 (goto-char (point-min))
4517 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4519 (defun gnus-article-goto-prev-page ()
4520 "Show the next page of the article."
4522 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4523 (gnus-article-prev-page nil)))
4525 (defun gnus-article-next-page (&optional lines)
4526 "Show the next page of the current article.
4527 If end of article, return non-nil. Otherwise return nil.
4528 Argument LINES specifies lines to be scrolled up."
4530 (let ((start (window-start))
4531 end-of-buffer end-of-page)
4533 (move-to-window-line -1)
4534 (if (<= (point) start)
4537 (setq start (point)))
4540 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4541 (and (pos-visible-in-window-p)
4542 (setq end-of-buffer t)))
4544 (setq end-of-page t)))
4546 (move-to-window-line lines)
4547 (unless (search-backward "\n\n" nil t)
4548 (setq start (point)))))
4549 (cond (end-of-buffer t)
4551 (gnus-narrow-to-page 1)
4555 (set-window-start (selected-window) start)
4556 (let (window-pixel-scroll-increment)
4560 (defun gnus-article-prev-page (&optional lines)
4561 "Show previous page of current article.
4562 Argument LINES specifies lines to be scrolled down."
4564 (let (beginning-of-buffer beginning-of-page)
4566 (move-to-window-line 0)
4567 (cond ((eq 1 (point))
4568 (setq beginning-of-buffer t))
4570 (setq beginning-of-page t))))
4571 (cond (beginning-of-buffer)
4573 (gnus-narrow-to-page -1))
4576 (let (window-pixel-scroll-increment)
4577 (scroll-down lines))
4578 (beginning-of-buffer
4579 (goto-char (point-min))))))))
4581 (defun gnus-article-refer-article ()
4582 "Read article specified by message-id around point."
4584 (let ((point (point)))
4585 (search-forward ">" nil t) ;Move point to end of "<....>".
4586 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4587 (let ((message-id (match-string 1)))
4589 (set-buffer gnus-summary-buffer)
4590 (gnus-summary-refer-article message-id))
4592 (error "No references around point"))))
4594 (defun gnus-article-show-summary ()
4595 "Reconfigure windows to show summary buffer."
4597 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4598 (error "There is no summary buffer for this article buffer")
4599 (gnus-article-set-globals)
4600 (gnus-configure-windows 'article)
4601 (gnus-summary-goto-subject gnus-current-article)
4602 (gnus-summary-position-point)))
4604 (defun gnus-article-describe-briefly ()
4605 "Describe article mode commands briefly."
4607 (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")))
4609 (defun gnus-article-summary-command ()
4610 "Execute the last keystroke in the summary buffer."
4612 (let ((obuf (current-buffer))
4613 (owin (current-window-configuration))
4615 (switch-to-buffer gnus-article-current-summary 'norecord)
4616 (setq func (lookup-key (current-local-map) (this-command-keys)))
4617 (call-interactively func)
4619 (set-window-configuration owin)
4620 (set-window-point (get-buffer-window (current-buffer)) (point))))
4622 (defun gnus-article-summary-command-nosave ()
4623 "Execute the last keystroke in the summary buffer."
4626 (pop-to-buffer gnus-article-current-summary 'norecord)
4627 (setq func (lookup-key (current-local-map) (this-command-keys)))
4628 (call-interactively func)))
4630 (defun gnus-article-check-buffer ()
4631 "Beep if not in an article buffer."
4632 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4633 (error "Command invoked outside of a Gnus article buffer")))
4635 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4636 "Read a summary buffer key sequence and execute it from the article buffer."
4638 (gnus-article-check-buffer)
4640 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4641 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4642 "=" "^" "\M-^" "|"))
4648 '("n" "Gn" "p" "Gp"))
4651 (set-buffer gnus-article-current-summary)
4652 (let (gnus-pick-mode)
4653 (push (or key last-command-event) unread-command-events)
4654 (setq keys (static-if (featurep 'xemacs)
4655 (events-to-keys (read-key-sequence nil))
4656 (read-key-sequence nil)))))
4659 (if (or (member keys nosaves)
4660 (member keys nosave-but-article)
4661 (member keys nosave-in-article))
4663 (save-window-excursion
4664 (pop-to-buffer gnus-article-current-summary 'norecord)
4665 ;; We disable the pick minor mode commands.
4666 (let (gnus-pick-mode)
4667 (setq func (lookup-key (current-local-map) keys))))
4671 (unless (member keys nosave-in-article)
4672 (set-buffer gnus-article-current-summary))
4673 (call-interactively func)
4674 (setq new-sum-point (point)))
4675 (when (member keys nosave-but-article)
4676 (pop-to-buffer gnus-article-buffer 'norecord)))
4677 ;; These commands should restore window configuration.
4678 (let ((obuf (current-buffer))
4679 (owin (current-window-configuration))
4681 (summary gnus-article-current-summary)
4682 func in-buffer selected)
4683 (if not-restore-window
4684 (pop-to-buffer summary 'norecord)
4685 (switch-to-buffer summary 'norecord))
4686 (setq in-buffer (current-buffer))
4687 ;; We disable the pick minor mode commands.
4688 (if (and (setq func (let (gnus-pick-mode)
4689 (lookup-key (current-local-map) keys)))
4692 (call-interactively func)
4693 (setq new-sum-point (point))
4694 (when (eq in-buffer (current-buffer))
4695 (setq selected (gnus-summary-select-article))
4697 (unless not-restore-window
4698 (set-window-configuration owin))
4699 (when (eq selected 'old)
4701 (set-window-start (get-buffer-window (current-buffer))
4703 (set-window-point (get-buffer-window (current-buffer))
4705 (let ((win (get-buffer-window gnus-article-current-summary)))
4707 (set-window-point win new-sum-point)))) )
4708 (switch-to-buffer gnus-article-buffer)
4711 (defun gnus-article-describe-key (key)
4712 "Display documentation of the function invoked by KEY. KEY is a string."
4713 (interactive "kDescribe key: ")
4714 (gnus-article-check-buffer)
4715 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4717 (set-buffer gnus-article-current-summary)
4718 (let (gnus-pick-mode)
4719 (if (featurep 'xemacs)
4721 (push (elt key 0) unread-command-events)
4722 (setq key (events-to-keys
4723 (read-key-sequence "Describe key: "))))
4724 (setq unread-command-events
4726 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4728 (setq key (read-key-sequence "Describe key: "))))
4730 (describe-key key)))
4732 (defun gnus-article-describe-key-briefly (key &optional insert)
4733 "Display documentation of the function invoked by KEY. KEY is a string."
4734 (interactive "kDescribe key: \nP")
4735 (gnus-article-check-buffer)
4736 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4738 (set-buffer gnus-article-current-summary)
4739 (let (gnus-pick-mode)
4740 (if (featurep 'xemacs)
4742 (push (elt key 0) unread-command-events)
4743 (setq key (events-to-keys
4744 (read-key-sequence "Describe key: "))))
4745 (setq unread-command-events
4747 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4749 (setq key (read-key-sequence "Describe key: "))))
4750 (describe-key-briefly key insert))
4751 (describe-key-briefly key insert)))
4753 (defun gnus-article-hide (&optional arg force)
4754 "Hide all the gruft in the current article.
4755 This means that PGP stuff, signatures, cited text and (some)
4756 headers will be hidden.
4757 If given a prefix, show the hidden text instead."
4758 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4759 (gnus-article-hide-headers arg)
4760 (gnus-article-hide-list-identifiers arg)
4761 (gnus-article-hide-pgp arg)
4762 (gnus-article-hide-citation-maybe arg force)
4763 (gnus-article-hide-signature arg))
4765 (defun gnus-article-maybe-highlight ()
4766 "Do some article highlighting if article highlighting is requested."
4767 (when (gnus-visual-p 'article-highlight 'highlight)
4768 (gnus-article-highlight-some)))
4770 (defun gnus-check-group-server ()
4771 ;; Make sure the connection to the server is alive.
4772 (unless (gnus-server-opened
4773 (gnus-find-method-for-group gnus-newsgroup-name))
4774 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4775 (gnus-request-group gnus-newsgroup-name t)))
4777 (defun gnus-request-article-this-buffer (article group)
4778 "Get an article and insert it into this buffer."
4779 (let (do-update-line sparse-header)
4783 (gnus-kill-all-overlays)
4784 (setq group (or group gnus-newsgroup-name))
4786 ;; Using `gnus-request-article' directly will insert the article into
4787 ;; `nntp-server-buffer' - so we'll save some time by not having to
4788 ;; copy it from the server buffer into the article buffer.
4790 ;; We only request an article by message-id when we do not have the
4791 ;; headers for it, so we'll have to get those.
4792 (when (stringp article)
4793 (gnus-read-header article))
4795 ;; If the article number is negative, that means that this article
4796 ;; doesn't belong in this newsgroup (possibly), so we find its
4797 ;; message-id and request it by id instead of number.
4798 (when (and (numberp article)
4800 (get-buffer gnus-summary-buffer)
4801 (gnus-buffer-exists-p gnus-summary-buffer))
4803 (set-buffer gnus-summary-buffer)
4804 (let ((header (gnus-summary-article-header article)))
4807 ((memq article gnus-newsgroup-sparse)
4808 ;; This is a sparse gap article.
4809 (setq do-update-line article)
4810 (setq article (mail-header-id header))
4811 (setq sparse-header (gnus-read-header article))
4812 (setq gnus-newsgroup-sparse
4813 (delq article gnus-newsgroup-sparse)))
4815 ;; It's a real article.
4816 (setq article (mail-header-id header)))
4818 ;; It is an extracted pseudo-article.
4819 (setq article 'pseudo)
4820 (gnus-request-pseudo-article header))))
4822 (let ((method (gnus-find-method-for-group
4823 gnus-newsgroup-name)))
4824 (when (and (eq (car method) 'nneething)
4826 (let ((dir (expand-file-name
4827 (mail-header-subject header)
4828 (file-name-as-directory
4829 (or (cadr (assq 'nneething-address method))
4831 (when (file-directory-p dir)
4832 (setq article 'nneething)
4833 (gnus-group-enter-directory dir))))))))
4836 ;; Refuse to select canceled articles.
4837 ((and (numberp article)
4839 (get-buffer gnus-summary-buffer)
4840 (gnus-buffer-exists-p gnus-summary-buffer)
4841 (eq (cdr (save-excursion
4842 (set-buffer gnus-summary-buffer)
4843 (assq article gnus-newsgroup-reads)))
4844 gnus-canceled-mark))
4846 ;; Check the backlog.
4847 ((and gnus-keep-backlog
4848 (gnus-backlog-request-article group article (current-buffer)))
4850 ;; Check asynchronous pre-fetch.
4851 ((gnus-async-request-fetched-article group article (current-buffer))
4852 (gnus-async-prefetch-next group article gnus-summary-buffer)
4853 (when (and (numberp article) gnus-keep-backlog)
4854 (gnus-backlog-enter-article group article (current-buffer)))
4857 ((and gnus-use-cache
4859 (gnus-cache-request-article article group))
4861 ;; Get the article and put into the article buffer.
4862 ((or (stringp article)
4864 (let ((gnus-override-method gnus-override-method)
4865 (methods (and (stringp article)
4866 gnus-refer-article-method))
4868 (buffer-read-only nil))
4869 (if (or (not (listp methods))
4870 (and (symbolp (car methods))
4871 (assq (car methods) nnoo-definition-alist)))
4872 (setq methods (list methods)))
4873 (when (and (null gnus-override-method)
4875 (setq gnus-override-method (pop methods)))
4877 (when (eq gnus-override-method 'current)
4878 (setq gnus-override-method gnus-current-select-method))
4880 (gnus-kill-all-overlays)
4881 (let ((gnus-newsgroup-name group))
4882 (gnus-check-group-server))
4883 (when (gnus-request-article article group (current-buffer))
4884 (when (numberp article)
4885 (gnus-async-prefetch-next group article
4886 gnus-summary-buffer)
4887 (when gnus-keep-backlog
4888 (gnus-backlog-enter-article
4889 group article (current-buffer))))
4890 (setq result 'article))
4893 (setq gnus-override-method (pop methods))
4894 (setq result 'done))))
4895 (and (eq result 'article) 'article)))
4899 ;; Associate this article with the current summary buffer.
4900 (setq gnus-article-current-summary gnus-summary-buffer)
4902 ;; Take the article from the original article buffer
4903 ;; and place it in the buffer it's supposed to be in.
4904 (when (and (get-buffer gnus-article-buffer)
4905 (equal (buffer-name (current-buffer))
4906 (buffer-name (get-buffer gnus-article-buffer))))
4908 (if (get-buffer gnus-original-article-buffer)
4909 (set-buffer gnus-original-article-buffer)
4910 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4911 (set-buffer-multibyte nil)
4912 (buffer-disable-undo)
4913 (setq major-mode 'gnus-original-article-mode)
4914 (setq buffer-read-only t))
4915 (let (buffer-read-only)
4917 (insert-buffer-substring gnus-article-buffer))
4918 (setq gnus-original-article (cons group article)))
4921 (run-hooks 'gnus-article-decode-hook)
4922 ;; Mark article as decoded or not.
4923 (setq gnus-article-decoded-p gnus-article-decode-hook))
4925 ;; Update sparse articles.
4926 (when (and do-update-line
4927 (or (numberp article)
4929 (let ((buf (current-buffer)))
4930 (set-buffer gnus-summary-buffer)
4931 (gnus-summary-update-article do-update-line sparse-header)
4932 (gnus-summary-goto-subject do-update-line nil t)
4933 (set-window-point (get-buffer-window (current-buffer) t)
4935 (set-buffer buf))))))
4941 (defcustom gnus-article-edit-mode-hook nil
4942 "Hook run in article edit mode buffers."
4943 :group 'gnus-article-various
4946 (defcustom gnus-article-edit-article-setup-function
4947 'gnus-article-mime-edit-article-setup
4948 "Function called to setup an editing article buffer."
4949 :group 'gnus-article-various
4952 (defvar gnus-article-edit-done-function nil)
4954 (defvar gnus-article-edit-mode-map nil)
4956 ;; Should we be using derived.el for this?
4957 (unless gnus-article-edit-mode-map
4958 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4959 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4961 (gnus-define-keys gnus-article-edit-mode-map
4962 "\C-c\C-c" gnus-article-edit-done
4963 "\C-c\C-k" gnus-article-edit-exit)
4965 (gnus-define-keys (gnus-article-edit-wash-map
4966 "\C-c\C-w" gnus-article-edit-mode-map)
4967 "f" gnus-article-edit-full-stops))
4969 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
4970 "Major mode for editing articles.
4971 This is an extended text-mode.
4973 \\{gnus-article-edit-mode-map}"
4974 (make-local-variable 'gnus-article-edit-done-function)
4975 (make-local-variable 'gnus-prev-winconf)
4976 (set (make-local-variable 'font-lock-defaults)
4977 '(message-font-lock-keywords t))
4978 (setq buffer-read-only nil)
4979 (buffer-enable-undo)
4982 (defun gnus-article-edit (&optional force)
4983 "Edit the current article.
4984 This will have permanent effect only in mail groups.
4985 If FORCE is non-nil, allow editing of articles even in read-only
4988 (when (and (not force)
4989 (gnus-group-read-only-p))
4990 (error "The current newsgroup does not support article editing"))
4991 (gnus-article-date-original)
4992 (gnus-article-edit-article
4994 `(lambda (no-highlight)
4996 (gnus-summary-edit-article-done
4997 ,(or (mail-header-references gnus-current-headers) "")
4998 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5000 (defun gnus-article-edit-article (start-func exit-func)
5001 "Start editing the contents of the current article buffer."
5002 (let ((winconf (current-window-configuration)))
5003 (set-buffer gnus-article-buffer)
5004 (gnus-article-edit-mode)
5005 (funcall start-func)
5006 (set-buffer-modified-p nil)
5007 (gnus-configure-windows 'edit-article)
5008 (setq gnus-article-edit-done-function exit-func)
5009 (setq gnus-prev-winconf winconf)
5010 (when gnus-article-edit-article-setup-function
5011 (funcall gnus-article-edit-article-setup-function))
5012 (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
5014 (defun gnus-article-edit-done (&optional arg)
5015 "Update the article edits and exit."
5017 (let ((func gnus-article-edit-done-function)
5018 (buf (current-buffer))
5019 (start (window-start)))
5020 (remove-hook 'gnus-article-mode-hook
5021 'gnus-article-mime-edit-article-unwind)
5022 ;; We remove all text props from the article buffer.
5024 (buffer-substring-no-properties (point-min) (point-max)))
5028 (let ((winconf gnus-prev-winconf))
5030 (set-window-configuration winconf)
5031 ;; Tippy-toe some to make sure that point remains where it was.
5032 (save-current-buffer
5034 (set-window-start (get-buffer-window (current-buffer)) start)
5038 (let ((buffer-read-only nil))
5040 ;; The cache and backlog have to be flushed somewhat.
5041 (when gnus-keep-backlog
5042 (gnus-backlog-remove-article
5043 (car gnus-article-current) (cdr gnus-article-current)))
5044 ;; Flush original article as well.
5046 (when (get-buffer gnus-original-article-buffer)
5047 (set-buffer gnus-original-article-buffer)
5048 (setq gnus-original-article nil)))
5049 (when gnus-use-cache
5050 (gnus-cache-update-article
5051 (car gnus-article-current) (cdr gnus-article-current))))
5053 (set-window-start (get-buffer-window buf) start)
5054 (set-window-point (get-buffer-window buf) (point))))
5056 (defun gnus-article-edit-exit ()
5057 "Exit the article editing without updating."
5059 (when (or (not (buffer-modified-p))
5060 (yes-or-no-p "Article modified; kill anyway? "))
5061 (let ((curbuf (current-buffer))
5063 (window-start (window-start)))
5065 (if (gnus-buffer-live-p gnus-original-article-buffer)
5066 (insert-buffer gnus-original-article-buffer))
5067 (let ((winconf gnus-prev-winconf))
5069 (set-window-configuration winconf)
5070 ;; Tippy-toe some to make sure that point remains where it was.
5071 (save-current-buffer
5073 (set-window-start (get-buffer-window (current-buffer)) window-start)
5076 (defun gnus-article-edit-full-stops ()
5077 "Interactively repair spacing at end of sentences."
5080 (goto-char (point-min))
5081 (search-forward-regexp "^$" nil t)
5082 (let ((case-fold-search nil))
5083 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5086 ;;; Article editing with MIME-Edit
5089 (defcustom gnus-article-mime-edit-article-setup-hook nil
5090 "Hook run after setting up a MIME editing article buffer."
5091 :group 'gnus-article-various
5094 (defun gnus-article-mime-edit-article-unwind ()
5095 "Unwind `gnus-article-buffer' if article editing was given up."
5096 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5097 (when (featurep 'font-lock)
5098 (setq font-lock-defaults nil)
5099 (font-lock-mode -1))
5100 (when mime-edit-mode-flag
5101 (mime-edit-exit 'nomime 'no-error)
5104 (defun gnus-article-mime-edit-article-setup ()
5105 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5106 after replacing with the original article."
5107 (setq gnus-show-mime t)
5108 (setq gnus-article-edit-done-function
5109 `(lambda (&rest args)
5110 (when mime-edit-mode-flag
5111 (let (mime-edit-insert-user-agent-field)
5114 (goto-char (point-min))
5115 (let (case-fold-search)
5116 (when (re-search-forward
5117 (format "^%s$" (regexp-quote mail-header-separator))
5119 (replace-match "")))
5120 (apply ,gnus-article-edit-done-function args)
5123 (buffer-substring-no-properties (point-min) (point-max))
5124 (set-buffer (get-buffer-create gnus-original-article-buffer))
5126 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5127 (set-buffer gnus-article-buffer)
5128 (gnus-article-prepare-display)))
5129 (substitute-key-definition 'gnus-article-edit-done
5130 'gnus-article-mime-edit-done
5131 gnus-article-edit-mode-map)
5132 (substitute-key-definition 'gnus-article-edit-exit
5133 'gnus-article-mime-edit-exit
5134 gnus-article-edit-mode-map)
5136 (insert-buffer gnus-original-article-buffer)
5137 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
5138 (fset 'mime-edit-decode-single-part-in-buffer
5139 (lambda (&rest args)
5140 (if (let ((content-type (car args)))
5141 (and (eq 'message (mime-content-type-primary-type
5143 (eq 'rfc822 (mime-content-type-subtype content-type))))
5144 (setcar (cdr args) 'not-decode-text))
5148 (fset 'mime-edit-decode-single-part-in-buffer ofn)))
5149 (when (featurep 'font-lock)
5150 (set (make-local-variable 'font-lock-defaults)
5151 '(message-font-lock-keywords t))
5152 (font-lock-set-defaults)
5153 (turn-on-font-lock))
5154 (set-buffer-modified-p nil)
5155 (delete-other-windows)
5156 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5157 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5159 (defun gnus-article-mime-edit-done (&optional arg)
5160 "Update the article MIME edits and exit."
5162 (when (featurep 'font-lock)
5163 (setq font-lock-defaults nil)
5164 (font-lock-mode -1))
5165 (gnus-article-edit-done arg))
5167 (defun gnus-article-mime-edit-exit ()
5168 "Exit the article MIME editing without updating."
5170 (when (or (not (buffer-modified-p))
5171 (yes-or-no-p "Article modified; kill anyway? "))
5172 (when (featurep 'font-lock)
5173 (setq font-lock-defaults nil)
5174 (font-lock-mode -1))
5175 (when mime-edit-mode-flag
5176 (let (mime-edit-insert-user-agent-field)
5179 (goto-char (point-min))
5180 (let (case-fold-search)
5181 (when (re-search-forward
5182 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5183 (replace-match "")))
5184 (let ((winconf gnus-prev-winconf))
5186 (buffer-substring-no-properties (point-min) (point-max))
5187 (set-buffer (get-buffer-create gnus-original-article-buffer))
5189 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5190 (set-buffer gnus-article-buffer)
5191 (gnus-article-prepare-display)
5192 (set-window-configuration winconf))))
5195 ;;; Article highlights
5198 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5200 ;;; Internal Variables:
5202 (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\\)\\)"
5203 "Regular expression that matches URLs."
5204 :group 'gnus-article-buttons
5207 (defcustom gnus-button-alist
5208 `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5209 0 t gnus-button-handle-news 3)
5210 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
5211 gnus-button-handle-news 2)
5212 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5214 gnus-button-fetch-group 4)
5215 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5216 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5217 t gnus-button-message-id 3)
5218 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5219 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5220 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5221 ;; This is how URLs _should_ be embedded in text...
5222 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
5224 (,gnus-button-url-regexp 0 t browse-url 0))
5225 "*Alist of regexps matching buttons in article bodies.
5227 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5228 REGEXP: is the string matching text around the button,
5229 BUTTON: is the number of the regexp grouping actually matching the button,
5230 FORM: is a lisp expression which must eval to true for the button to
5232 CALLBACK: is the function to call when the user push this button, and each
5233 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5235 CALLBACK can also be a variable, in that case the value of that
5236 variable it the real callback function."
5237 :group 'gnus-article-buttons
5238 :type '(repeat (list regexp
5239 (integer :tag "Button")
5241 (function :tag "Callback")
5244 (integer :tag "Regexp group")))))
5246 (defcustom gnus-header-button-alist
5247 `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
5248 0 t gnus-button-message-id 0)
5249 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5250 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5251 0 t gnus-button-mailto 0)
5252 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5253 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5254 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5255 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5256 gnus-button-message-id 3))
5257 "*Alist of headers and regexps to match buttons in article heads.
5259 This alist is very similar to `gnus-button-alist', except that each
5260 alist has an additional HEADER element first in each entry:
5262 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5264 HEADER is a regexp to match a header. For a fuller explanation, see
5265 `gnus-button-alist'."
5266 :group 'gnus-article-buttons
5267 :group 'gnus-article-headers
5268 :type '(repeat (list (regexp :tag "Header")
5270 (integer :tag "Button")
5272 (function :tag "Callback")
5275 (integer :tag "Regexp group")))))
5277 (defvar gnus-button-regexp nil)
5278 (defvar gnus-button-marker-list nil)
5279 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5281 (defvar gnus-button-last nil)
5282 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5286 (defun gnus-article-push-button (event)
5287 "Check text under the mouse pointer for a callback function.
5288 If the text under the mouse pointer has a `gnus-callback' property,
5289 call it with the value of the `gnus-data' text property."
5291 (set-buffer (window-buffer (posn-window (event-start event))))
5292 (let* ((pos (posn-point (event-start event)))
5293 (data (get-text-property pos 'gnus-data))
5294 (fun (get-text-property pos 'gnus-callback)))
5297 (funcall fun data))))
5299 (defun gnus-article-press-button ()
5300 "Check text at point for a callback function.
5301 If the text at point has a `gnus-callback' property,
5302 call it with the value of the `gnus-data' text property."
5304 (let* ((data (get-text-property (point) 'gnus-data))
5305 (fun (get-text-property (point) 'gnus-callback)))
5307 (funcall fun data))))
5309 (defun gnus-article-prev-button (n)
5310 "Move point to N buttons backward.
5311 If N is negative, move forward instead."
5313 (gnus-article-next-button (- n)))
5315 (defun gnus-article-next-button (n)
5316 "Move point to N buttons forward.
5317 If N is negative, move backward instead."
5319 (let ((function (if (< n 0) 'previous-single-property-change
5320 'next-single-property-change))
5321 (inhibit-point-motion-hooks t)
5323 (limit (if (< n 0) (point-min) (point-max))))
5325 (while (and (not (= limit (point)))
5327 ;; Skip past the current button.
5328 (when (get-text-property (point) 'gnus-callback)
5329 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5330 ;; Go to the next (or previous) button.
5331 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5332 ;; Put point at the start of the button.
5333 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5334 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5335 ;; Skip past intangible buttons.
5336 (when (get-text-property (point) 'intangible)
5340 (gnus-message 5 "No more buttons"))
5343 (defun gnus-article-highlight (&optional force)
5344 "Highlight current article.
5345 This function calls `gnus-article-highlight-headers',
5346 `gnus-article-highlight-citation',
5347 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5348 do the highlighting. See the documentation for those functions."
5349 (interactive (list 'force))
5350 (gnus-article-highlight-headers)
5351 (gnus-article-highlight-citation force)
5352 (gnus-article-highlight-signature)
5353 (gnus-article-add-buttons force)
5354 (gnus-article-add-buttons-to-head))
5356 (defun gnus-article-highlight-some (&optional force)
5357 "Highlight current article.
5358 This function calls `gnus-article-highlight-headers',
5359 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5360 do the highlighting. See the documentation for those functions."
5361 (interactive (list 'force))
5362 (gnus-article-highlight-headers)
5363 (gnus-article-highlight-signature)
5364 (gnus-article-add-buttons))
5366 (defun gnus-article-highlight-headers ()
5367 "Highlight article headers as specified by `gnus-header-face-alist'."
5370 (set-buffer gnus-article-buffer)
5372 (let ((alist gnus-header-face-alist)
5373 (buffer-read-only nil)
5374 (case-fold-search t)
5375 (inhibit-point-motion-hooks t)
5376 entry regexp header-face field-face from hpoints fpoints)
5377 (article-narrow-to-head)
5378 (while (setq entry (pop alist))
5379 (goto-char (point-min))
5380 (setq regexp (concat "^\\("
5381 (if (string-equal "" (nth 0 entry))
5385 header-face (nth 1 entry)
5386 field-face (nth 2 entry))
5387 (while (and (re-search-forward regexp nil t)
5391 (unless (search-forward ":" nil t)
5393 (when (and header-face
5394 (not (memq (point) hpoints)))
5395 (push (point) hpoints)
5396 (gnus-put-text-property from (point) 'face header-face))
5397 (when (and field-face
5398 (not (memq (setq from (point)) fpoints)))
5400 (if (re-search-forward "^[^ \t]" nil t)
5402 (goto-char (point-max)))
5403 (gnus-put-text-property from (point) 'face field-face))))))))
5405 (defun gnus-article-highlight-signature ()
5406 "Highlight the signature in an article.
5407 It does this by highlighting everything after
5408 `gnus-signature-separator' using `gnus-signature-face'."
5410 (when gnus-signature-face
5412 (set-buffer gnus-article-buffer)
5413 (let ((buffer-read-only nil)
5414 (inhibit-point-motion-hooks t))
5416 (when (gnus-article-narrow-to-signature)
5417 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5418 'face gnus-signature-face)))))))
5420 (defun gnus-article-buttonize-signature ()
5421 "Add button to the signature."
5424 (set-buffer gnus-article-buffer)
5425 (let ((buffer-read-only nil)
5426 (inhibit-point-motion-hooks t))
5427 (when (gnus-article-search-signature)
5428 (gnus-article-add-button (match-beginning 0) (match-end 0)
5429 'gnus-signature-toggle
5430 (set-marker (make-marker)
5431 (1+ (match-end 0))))))))
5433 (defun gnus-button-in-region-p (b e prop)
5434 "Say whether PROP exists in the region."
5435 (text-property-not-all b e prop nil))
5437 (defun gnus-article-add-buttons (&optional force)
5438 "Find external references in the article and make buttons of them.
5439 \"External references\" are things like Message-IDs and URLs, as
5440 specified by `gnus-button-alist'."
5441 (interactive (list 'force))
5443 (set-buffer gnus-article-buffer)
5444 (let ((buffer-read-only nil)
5445 (inhibit-point-motion-hooks t)
5446 (case-fold-search t)
5447 (alist gnus-button-alist)
5449 ;; Remove all old markers.
5450 (let (marker entry new-list)
5451 (while (setq marker (pop gnus-button-marker-list))
5452 (if (or (< marker (point-min)) (>= marker (point-max)))
5453 (push marker new-list)
5455 (when (setq entry (gnus-button-entry))
5456 (put-text-property (match-beginning (nth 1 entry))
5457 (match-end (nth 1 entry))
5458 'gnus-callback nil))
5459 (set-marker marker nil)))
5460 (setq gnus-button-marker-list new-list))
5461 ;; We skip the headers.
5464 (while (setq entry (pop alist))
5465 (setq regexp (car entry))
5467 (while (re-search-forward regexp nil t)
5468 (let* ((start (and entry (match-beginning (nth 1 entry))))
5469 (end (and entry (match-end (nth 1 entry))))
5470 (from (match-beginning 0)))
5471 (when (and (or (eq t (nth 2 entry))
5472 (eval (nth 2 entry)))
5473 (not (gnus-button-in-region-p
5474 start end 'gnus-callback)))
5475 ;; That optional form returned non-nil, so we add the
5477 (gnus-article-add-button
5478 start end 'gnus-button-push
5479 (car (push (set-marker (make-marker) from)
5480 gnus-button-marker-list))))))))))
5482 ;; Add buttons to the head of an article.
5483 (defun gnus-article-add-buttons-to-head ()
5484 "Add buttons to the head of the article."
5487 (set-buffer gnus-article-buffer)
5489 (let ((buffer-read-only nil)
5490 (inhibit-point-motion-hooks t)
5491 (case-fold-search t)
5492 (alist gnus-header-button-alist)
5494 (article-narrow-to-head)
5496 ;; Each alist entry.
5497 (setq entry (car alist)
5499 (goto-char (point-min))
5500 (while (re-search-forward (car entry) nil t)
5501 ;; Each header matching the entry.
5502 (setq beg (match-beginning 0))
5503 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5504 (match-beginning 0))
5507 (while (re-search-forward (nth 1 entry) end t)
5508 ;; Each match within a header.
5509 (let* ((entry (cdr entry))
5510 (start (match-beginning (nth 1 entry)))
5511 (end (match-end (nth 1 entry)))
5512 (form (nth 2 entry)))
5513 (goto-char (match-end 0))
5515 (gnus-article-add-button
5516 start end (nth 3 entry)
5517 (buffer-substring (match-beginning (nth 4 entry))
5518 (match-end (nth 4 entry)))))))
5519 (goto-char end)))))))
5521 ;;; External functions:
5523 (defun gnus-article-add-button (from to fun &optional data)
5524 "Create a button between FROM and TO with callback FUN and data DATA."
5525 (when gnus-article-button-face
5526 (gnus-overlay-put (gnus-make-overlay from to)
5527 'face gnus-article-button-face))
5528 (gnus-add-text-properties
5530 (nconc (and gnus-article-mouse-face
5531 (list gnus-mouse-face-prop gnus-article-mouse-face))
5532 (list 'gnus-callback fun)
5533 (and data (list 'gnus-data data))))
5534 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5535 ;; Quote `:button-keymap' for Mule 2.3
5536 ;; but it won't work.
5537 ':button-keymap gnus-widget-button-keymap))
5539 ;;; Internal functions:
5541 (defun gnus-article-set-globals ()
5543 (set-buffer gnus-summary-buffer)
5544 (gnus-set-global-variables)))
5546 (defun gnus-signature-toggle (end)
5548 (set-buffer gnus-article-buffer)
5549 (let ((buffer-read-only nil)
5550 (inhibit-point-motion-hooks t)
5551 (limit (next-single-property-change end 'mime-view-entity
5553 (if (text-property-any end limit 'article-type 'signature)
5554 (gnus-remove-text-properties-when
5555 'article-type 'signature end limit
5556 (cons 'article-type (cons 'signature
5557 gnus-hidden-properties)))
5558 (gnus-add-text-properties-when
5559 'article-type nil end limit
5560 (cons 'article-type (cons 'signature
5561 gnus-hidden-properties)))))))
5563 (defun gnus-button-entry ()
5564 ;; Return the first entry in `gnus-button-alist' matching this place.
5565 (let ((alist gnus-button-alist)
5568 (setq entry (pop alist))
5569 (if (looking-at (car entry))
5574 (defun gnus-button-push (marker)
5575 ;; Push button starting at MARKER.
5578 (let* ((entry (gnus-button-entry))
5579 (inhibit-point-motion-hooks t)
5581 (args (mapcar (lambda (group)
5582 (let ((string (match-string group)))
5583 (gnus-set-text-properties
5584 0 (length string) nil string)
5591 (fboundp (symbol-value fun)))
5592 (apply (symbol-value fun) args))
5594 (gnus-message 1 "You must define `%S' to use this button"
5595 (cons fun args)))))))
5597 (defun gnus-parse-news-url (url)
5598 (let (scheme server group message-id articles)
5601 (goto-char (point-min))
5602 (when (looking-at "\\([A-Za-z]+\\):")
5603 (setq scheme (match-string 1))
5604 (goto-char (match-end 0)))
5605 (when (looking-at "//\\([^/]+\\)/")
5606 (setq server (match-string 1))
5607 (goto-char (match-end 0)))
5610 ((looking-at "\\(.*@.*\\)")
5611 (setq message-id (match-string 1)))
5612 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
5613 (setq group (match-string 1)
5614 articles (split-string (match-string 2) "-")))
5615 ((looking-at "\\([^/]+\\)/?")
5616 (setq group (match-string 1)))
5618 (error "Unknown news URL syntax"))))
5619 (list scheme server group message-id articles)))
5621 (defun gnus-button-handle-news (url)
5623 (destructuring-bind (scheme server group message-id articles)
5624 (gnus-parse-news-url url)
5628 (set-buffer gnus-summary-buffer)
5630 (let ((gnus-refer-article-method (list (list 'nntp server))))
5631 (gnus-summary-refer-article message-id))
5632 (gnus-summary-refer-article message-id))))
5634 (gnus-button-fetch-group url)))))
5636 (defun gnus-button-message-id (message-id)
5639 (set-buffer gnus-summary-buffer)
5640 (gnus-summary-refer-article message-id)))
5642 (defun gnus-button-fetch-group (address)
5643 "Fetch GROUP specified by ADDRESS."
5644 (if (not (string-match "[:/]" address))
5645 ;; This is just a simple group url.
5646 (gnus-group-read-ephemeral-group address gnus-select-method)
5649 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
5651 (error "Can't parse %s" address)
5652 (gnus-group-read-ephemeral-group
5653 (match-string 4 address)
5654 `(nntp ,(match-string 1 address)
5655 (nntp-address ,(match-string 1 address))
5656 (nntp-port-number ,(if (match-end 3)
5657 (match-string 3 address)
5660 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
5662 (defun gnus-url-parse-query-string (query &optional downcase)
5663 (let (retval pairs cur key val)
5664 (setq pairs (split-string query "&"))
5666 (setq cur (car pairs)
5668 (if (not (string-match "=" cur))
5670 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5671 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5673 (setq key (downcase key)))
5674 (setq cur (assoc key retval))
5676 (setcdr cur (cons val (cdr cur)))
5677 (setq retval (cons (list key val) retval)))))
5680 (defun gnus-url-unhex (x)
5687 (defun gnus-url-unhex-string (str &optional allow-newlines)
5688 "Remove %XXX embedded spaces, etc in a url.
5689 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5690 decoding of carriage returns and line feeds in the string, which is normally
5691 forbidden in URL encoding."
5692 (setq str (or str ""))
5694 (case-fold-search t))
5695 (while (string-match "%[0-9a-f][0-9a-f]" str)
5696 (let* ((start (match-beginning 0))
5697 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5699 (gnus-url-unhex (elt str (+ start 2))))))
5701 tmp (substring str 0 start)
5704 (char-to-string code))
5705 ((or (= code ?\n) (= code ?\r))
5707 (t (char-to-string code))))
5708 str (substring str (match-end 0)))))
5709 (setq tmp (concat tmp str))
5712 (defun gnus-url-mailto (url)
5713 ;; Send mail to someone
5714 (when (string-match "mailto:/*\\(.*\\)" url)
5715 (setq url (substring url (match-beginning 1) nil)))
5716 (let (to args subject func)
5717 (if (string-match (regexp-quote "?") url)
5718 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5719 args (gnus-url-parse-query-string
5720 (substring url (match-end 0) nil) t))
5721 (setq to (gnus-url-unhex-string url)))
5722 (setq args (cons (list "to" to) args)
5723 subject (cdr-safe (assoc "subject" args)))
5726 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5729 (message-position-on-field (caar args)))
5730 (insert (mapconcat 'identity (cdar args) ", "))
5731 (setq args (cdr args)))
5734 (message-goto-subject))))
5736 (defun gnus-button-embedded-url (address)
5737 "Activate ADDRESS with `browse-url'."
5738 (browse-url (gnus-strip-whitespace address)))
5741 ;; Silence the byte-compiler.
5742 (autoload 'smiley-toggle-buffer "gnus-bitmap"))
5743 (defun gnus-article-smiley-display ()
5744 "Display \"smileys\" as small graphical icons."
5745 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5747 ;;; Next/prev buttons in the article buffer.
5749 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5750 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5752 (defvar gnus-prev-page-map nil)
5753 (unless gnus-prev-page-map
5754 (setq gnus-prev-page-map (make-sparse-keymap))
5755 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5756 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5758 (static-if (featurep 'xemacs)
5759 (defun gnus-insert-prev-page-button ()
5760 (let ((buffer-read-only nil))
5762 gnus-prev-page-line-format nil
5763 `(gnus-prev t local-map ,gnus-prev-page-map
5764 gnus-callback gnus-article-button-prev-page
5765 article-type annotation))))
5766 (defun gnus-insert-prev-page-button ()
5767 (let ((buffer-read-only nil)
5768 (situation (get-text-property (point-min) 'mime-view-situation)))
5769 (set-keymap-parent gnus-prev-page-map (current-local-map))
5771 gnus-prev-page-line-format nil
5772 `(gnus-prev t local-map ,gnus-prev-page-map
5773 gnus-callback gnus-article-button-prev-page
5774 article-type annotation
5775 mime-view-situation ,situation))))
5778 (defvar gnus-next-page-map nil)
5779 (unless gnus-next-page-map
5780 (setq gnus-next-page-map (make-sparse-keymap))
5781 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5782 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5784 (defun gnus-button-next-page ()
5785 "Go to the next page."
5787 (let ((win (selected-window)))
5788 (select-window (get-buffer-window gnus-article-buffer t))
5789 (gnus-article-next-page)
5790 (select-window win)))
5792 (defun gnus-button-prev-page ()
5793 "Go to the prev page."
5795 (let ((win (selected-window)))
5796 (select-window (get-buffer-window gnus-article-buffer t))
5797 (gnus-article-prev-page)
5798 (select-window win)))
5800 (static-if (featurep 'xemacs)
5801 (defun gnus-insert-next-page-button ()
5802 (let ((buffer-read-only nil))
5803 (gnus-eval-format gnus-next-page-line-format nil
5805 t local-map ,gnus-next-page-map
5806 gnus-callback gnus-article-button-next-page
5807 article-type annotation))))
5808 (defun gnus-insert-next-page-button ()
5809 (let ((buffer-read-only nil)
5810 (situation (get-text-property (point-min) 'mime-view-situation)))
5811 (set-keymap-parent gnus-next-page-map (current-local-map))
5812 (gnus-eval-format gnus-next-page-line-format nil
5814 t local-map ,gnus-next-page-map
5815 gnus-callback gnus-article-button-next-page
5816 article-type annotation
5817 mime-view-situation ,situation))))
5820 (defun gnus-article-button-next-page (arg)
5821 "Go to the next page."
5823 (let ((win (selected-window)))
5824 (select-window (get-buffer-window gnus-article-buffer t))
5825 (gnus-article-next-page)
5826 (select-window win)))
5828 (defun gnus-article-button-prev-page (arg)
5829 "Go to the prev page."
5831 (let ((win (selected-window)))
5832 (select-window (get-buffer-window gnus-article-buffer t))
5833 (gnus-article-prev-page)
5834 (select-window win)))
5836 (defvar gnus-decode-header-methods
5837 '(mail-decode-encoded-word-region)
5838 "List of methods used to decode headers.
5840 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5841 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5842 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5843 whose names match REGEXP.
5846 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5847 mail-decode-encoded-word-region
5848 (\"chinese\" . rfc1843-decode-region))
5851 (defvar gnus-decode-header-methods-cache nil)
5853 (defun gnus-multi-decode-header (start end)
5854 "Apply the functions from `gnus-encoded-word-methods' that match."
5855 (unless (and gnus-decode-header-methods-cache
5856 (eq gnus-newsgroup-name
5857 (car gnus-decode-header-methods-cache)))
5858 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5861 (nconc gnus-decode-header-methods-cache (list x))
5862 (if (and gnus-newsgroup-name
5863 (string-match (car x) gnus-newsgroup-name))
5864 (nconc gnus-decode-header-methods-cache
5866 gnus-decode-header-methods))
5867 (let ((xlist gnus-decode-header-methods-cache))
5870 (narrow-to-region start end)
5872 (funcall (pop xlist) (point-min) (point-max))))))
5875 ;;; Treatment top-level handling.
5878 (defun gnus-treat-article (condition &optional part-number total-parts type)
5879 (let ((length (- (point-max) (point-min)))
5880 (alist gnus-treatment-function-alist)
5881 (article-goto-body-goes-to-point-min-p t)
5885 (let ((list gnus-article-treat-types))
5887 (when (string-match (pop list) type)
5888 (throw 'found t)))))))
5889 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5890 (entity (static-unless (featurep 'xemacs)
5891 (when (eq 'head condition)
5892 (get-text-property (point-min) 'mime-view-entity))))
5893 val elem buttonized)
5894 (gnus-run-hooks 'gnus-part-display-hook)
5895 (unless gnus-inhibit-treatment
5896 (while (setq elem (pop alist))
5899 (if (gnus-buffer-live-p gnus-summary-buffer)
5900 (set-buffer gnus-summary-buffer))
5901 (symbol-value (car elem))))
5902 (when (and (or (consp val)
5904 (gnus-treat-predicate val)
5905 (or (not (get (car elem) 'highlight))
5907 (when (and (not buttonized)
5909 '(gnus-treat-hide-signature
5910 gnus-treat-highlight-signature)))
5911 (gnus-article-buttonize-signature)
5912 (setq buttonized t))
5914 (funcall (cadr elem)))))
5915 ;; FSF Emacsen does not inherit the existing text properties
5916 ;; in the new text, so we should do it for `mime-view-entity'.
5917 (static-unless (featurep 'xemacs)
5919 (put-text-property (point-min) (point-max)
5920 'mime-view-entity entity))))))
5922 ;; Dynamic variables.
5924 (defvar part-number)
5925 (defvar total-parts)
5930 (defun gnus-treat-predicate (val)
5935 (stringp (car val)))
5936 (apply 'gnus-or (mapcar `(lambda (s)
5937 (string-match s ,(or gnus-newsgroup-name "")))
5940 (let ((pred (pop val)))
5943 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5945 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5947 (not (gnus-treat-predicate (car val))))
5949 (equal (car val) type))
5951 (error "%S is not a valid predicate" pred)))))
5961 (eq part-number total-parts))
5965 (error "%S is not a valid value" val))))
5967 (defun gnus-article-encrypt-body (protocol &optional n)
5968 "Encrypt the article body."
5971 (or gnus-article-encrypt-protocol
5972 (completing-read "Encrypt protocol: "
5973 gnus-article-encrypt-protocol-alist
5975 current-prefix-arg))
5976 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5978 (error (format "Can't find the encrypt protocol %s" protocol)))
5979 (if (equal gnus-newsgroup-name "nndraft:drafts")
5980 (error "Can't encrypt the article in group nndraft:drafts"))
5981 (if (equal gnus-newsgroup-name "nndraft:queue")
5982 (error "Don't encrypt the article in group nndraft:queue"))
5983 (gnus-summary-iterate n
5985 (set-buffer gnus-summary-buffer)
5986 (let ((mail-parse-charset gnus-newsgroup-charset)
5987 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5988 (summary-buffer gnus-summary-buffer)
5990 (gnus-set-global-variables)
5991 (when (gnus-group-read-only-p)
5992 (error "The current newsgroup does not support article encrypt"))
5993 (gnus-summary-show-article t)
5995 (or (mail-header-references gnus-current-headers) ""))
5996 (set-buffer gnus-article-buffer)
5997 (let* ((buffer-read-only nil)
5999 (mapcar (lambda (field)
6000 (and (save-restriction
6001 (message-narrow-to-head)
6002 (goto-char (point-min))
6003 (search-forward field nil t))
6005 (message-narrow-to-field)
6006 (buffer-substring (point-min) (point-max))
6007 (delete-region (point-min) (point-max))
6009 '("Content-Type:" "Content-Transfer-Encoding:"
6010 "Content-Disposition:"))))
6011 (message-narrow-to-head)
6012 (message-remove-header "MIME-Version")
6013 (goto-char (point-max))
6014 (setq point (point))
6015 (insert (apply 'concat headers))
6017 (narrow-to-region point (point-max))
6018 (let ((message-options message-options))
6019 (message-options-set 'message-sender user-mail-address)
6020 (message-options-set 'message-recipients user-mail-address)
6021 (message-options-set 'message-sign-encrypt 'not)
6023 (goto-char (point-min))
6024 (insert "MIME-Version: 1.0\n")
6026 (gnus-summary-edit-article-done
6027 references nil summary-buffer t))
6028 (when gnus-keep-backlog
6029 (gnus-backlog-remove-article
6030 (car gnus-article-current) (cdr gnus-article-current)))
6032 (when (get-buffer gnus-original-article-buffer)
6033 (set-buffer gnus-original-article-buffer)
6034 (setq gnus-original-article nil)))
6035 (when gnus-use-cache
6036 (gnus-cache-update-article
6037 (car gnus-article-current) (cdr gnus-article-current))))))))
6039 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
6040 "The following specs can be used:
6041 %t The security MIME type
6044 %D Details if button is pressed")
6046 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
6047 "The following specs can be used:
6048 %t The security MIME type
6051 %D Details if button is pressed")
6053 (defvar gnus-mime-security-button-line-format-alist
6054 '((?t gnus-tmp-type ?s)
6055 (?i gnus-tmp-info ?s)
6056 (?d gnus-tmp-details ?s)
6057 (?D gnus-tmp-pressed-details ?s)))
6059 (defvar gnus-mime-security-button-map
6060 (let ((map (make-sparse-keymap)))
6061 (unless (>= (string-to-number emacs-version) 21)
6062 (set-keymap-parent map gnus-article-mode-map))
6063 (define-key map gnus-mouse-2 'gnus-article-push-button)
6064 (define-key map "\r" 'gnus-article-press-button)
6067 (defvar gnus-mime-security-details-buffer nil)
6069 (defvar gnus-mime-security-button-pressed nil)
6071 (defvar gnus-mime-security-show-details-inline t
6072 "If non-nil, show details in the article buffer.")
6074 (defun gnus-mime-security-verify-or-decrypt (handle)
6075 (mm-remove-parts (cdr handle))
6076 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
6077 point buffer-read-only)
6079 (goto-char (car region)))
6081 (narrow-to-region (point) (point))
6082 (with-current-buffer (mm-handle-multipart-original-buffer handle)
6083 (let* ((mm-verify-option 'known)
6084 (mm-decrypt-option 'known)
6085 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
6086 (unless (eq nparts (cdr handle))
6087 (mm-destroy-parts (cdr handle))
6088 (setcdr handle nparts))))
6089 (setq point (point))
6090 (gnus-mime-display-security handle)
6091 (goto-char (point-max)))
6093 (delete-region (point) (cdr region))
6094 (set-marker (car region) nil)
6095 (set-marker (cdr region) nil))
6098 (defun gnus-mime-security-show-details (handle)
6099 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
6101 (if gnus-mime-security-show-details-inline
6102 (let ((gnus-mime-security-button-pressed t)
6103 (gnus-mime-security-button-line-format
6104 (get-text-property (point) 'gnus-line-format))
6107 (while (eq (get-text-property (point) 'gnus-line-format)
6108 gnus-mime-security-button-line-format)
6112 (narrow-to-region (point) (point))
6113 (gnus-insert-mime-security-button handle))
6114 (delete-region (point)
6115 (or (text-property-not-all
6118 gnus-mime-security-button-line-format)
6120 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
6121 (with-current-buffer gnus-mime-security-details-buffer
6124 (setq gnus-mime-security-details-buffer
6125 (gnus-get-buffer-create "*MIME Security Details*")))
6126 (with-current-buffer gnus-mime-security-details-buffer
6128 (goto-char (point-min)))
6129 (pop-to-buffer gnus-mime-security-details-buffer))
6130 (gnus-message 5 "No details."))))
6132 (defun gnus-mime-security-press-button (handle)
6133 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6134 (gnus-mime-security-show-details handle)
6135 (gnus-mime-security-verify-or-decrypt handle)))
6137 (defun gnus-insert-mime-security-button (handle &optional displayed)
6138 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
6141 (or (nth 2 (assoc protocol mm-verify-function-alist))
6142 (nth 2 (assoc protocol mm-decrypt-function-alist))
6144 (if (equal (car handle) "multipart/signed")
6145 " Signed" " Encrypted")
6148 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
6151 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
6152 gnus-tmp-pressed-details
6154 (setq gnus-tmp-details
6155 (if gnus-tmp-details
6156 (concat "\n" gnus-tmp-details) ""))
6157 (setq gnus-tmp-pressed-details
6158 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
6163 gnus-mime-security-button-line-format
6164 gnus-mime-security-button-line-format-alist
6165 `(keymap ,gnus-mime-security-button-map
6166 ,@(if (>= (string-to-number emacs-version) 21)
6167 nil ;; XEmacs doesn't care
6168 (list 'local-map gnus-mime-security-button-map))
6169 gnus-callback gnus-mime-security-press-button
6170 gnus-line-format ,gnus-mime-security-button-line-format
6171 article-type annotation
6174 (widget-convert-button
6177 :action 'gnus-widget-press-button
6178 :button-keymap gnus-mime-security-button-map
6180 (lambda (widget/window &optional overlay pos)
6181 ;; Needed to properly clear the message due to a bug in
6182 ;; wid-edit (XEmacs only).
6183 (if (boundp 'help-echo-owns-message)
6184 (setq help-echo-owns-message t))
6187 (aref gnus-mouse-2 0))))))
6189 (defun gnus-mime-display-security (handle)
6191 (narrow-to-region (point) (point))
6192 (gnus-insert-mime-security-button handle)
6193 (gnus-mime-display-mixed (cdr handle))
6196 (let ((gnus-mime-security-button-line-format
6197 gnus-mime-security-button-end-line-format))
6198 (gnus-insert-mime-security-button handle))
6199 (mm-set-handle-multipart-parameter
6201 (cons (set-marker (make-marker) (point-min))
6202 (set-marker (make-marker) (point-max))))))
6208 (defun gnus-article-header-presentation-method (entity situation)
6209 (mime-insert-header entity)
6212 (set-alist 'mime-header-presentation-method-alist
6213 'gnus-original-article-mode
6214 #'gnus-article-header-presentation-method)
6216 (defun gnus-mime-preview-quitting-method ()
6217 (mime-preview-kill-buffer)
6218 (delete-other-windows)
6219 (gnus-article-show-summary)
6220 (gnus-summary-select-article gnus-show-all-headers t))
6222 (set-alist 'mime-preview-quitting-method-alist
6223 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6225 (set-alist 'mime-preview-following-method-alist
6226 'gnus-original-article-mode #'gnus-following-method)
6228 (set-alist 'mime-preview-over-to-previous-method-alist
6229 'gnus-original-article-mode
6231 (if (> (point-min) 1)
6232 (gnus-article-prev-page)
6233 (gnus-article-read-summary-keys
6234 nil (gnus-character-to-event ?P)))))
6236 (set-alist 'mime-preview-over-to-next-method-alist
6237 'gnus-original-article-mode'
6239 (if (< (point-max) (buffer-size))
6240 (gnus-article-next-page)
6241 (gnus-article-read-summary-keys
6242 nil (gnus-character-to-event ?N)))))
6252 (run-hooks 'gnus-art-load-hook)
6254 ;;; gnus-art.el ends here