1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
42 (autoload 'gnus-msg-mail "gnus-msg" nil t)
43 (autoload 'gnus-button-mailto "gnus-msg")
44 (autoload 'gnus-button-reply "gnus-msg" nil t)
46 (defgroup gnus-article nil
48 :link '(custom-manual "(gnus)The Article Buffer")
51 (defgroup gnus-article-treat nil
52 "Treating article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-hiding nil
57 "Hiding article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-highlight nil
62 "Article highlighting."
63 :link '(custom-manual "(gnus)Article Highlighting")
67 (defgroup gnus-article-signature nil
69 :link '(custom-manual "(gnus)Article Signature")
72 (defgroup gnus-article-headers nil
74 :link '(custom-manual "(gnus)Hiding Headers")
77 (defgroup gnus-article-washing nil
78 "Special commands on articles."
79 :link '(custom-manual "(gnus)Article Washing")
82 (defgroup gnus-article-emphasis nil
83 "Fontisizing articles."
84 :link '(custom-manual "(gnus)Article Fontisizing")
87 (defgroup gnus-article-saving nil
89 :link '(custom-manual "(gnus)Saving Articles")
92 (defgroup gnus-article-mime nil
93 "Worshiping the MIME wonder."
94 :link '(custom-manual "(gnus)Using MIME")
97 (defgroup gnus-article-buttons nil
98 "Pushable buttons in the article buffer."
99 :link '(custom-manual "(gnus)Article Buttons")
100 :group 'gnus-article)
102 (defgroup gnus-article-various nil
103 "Other article options."
104 :link '(custom-manual "(gnus)Misc Article")
105 :group 'gnus-article)
107 (defcustom gnus-ignored-headers
108 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
109 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
110 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
111 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
112 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
113 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
114 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
115 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
116 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
117 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
118 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
119 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
120 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
121 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
122 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
123 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
124 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
125 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
126 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
127 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
128 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
129 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
130 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
131 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
132 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
133 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
134 "^X-Received:" "^Content-length:" "X-precedence:"
135 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
136 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
138 "*All headers that start with this regexp will be hidden.
139 This variable can also be a list of regexps of headers to be ignored.
140 If `gnus-visible-headers' is non-nil, this variable will be ignored."
141 :type '(choice :custom-show nil
144 :group 'gnus-article-hiding)
146 (defcustom gnus-visible-headers
147 "^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:"
148 "*All headers that do not match this regexp will be hidden.
149 This variable can also be a list of regexp of headers to remain visible.
150 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
151 :type '(repeat :value-to-internal (lambda (widget value)
152 (custom-split-regexp-maybe value))
153 :match (lambda (widget value)
155 (widget-editable-list-match widget value)))
157 :group 'gnus-article-hiding)
159 (defcustom gnus-sorted-header-list
160 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
161 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
162 "*This variable is a list of regular expressions.
163 If it is non-nil, headers that match the regular expressions will
164 be placed first in the article buffer in the sequence specified by
166 :type '(repeat regexp)
167 :group 'gnus-article-hiding)
169 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
170 "Headers that are only to be displayed if they have interesting data.
171 Possible values in this list are `empty', `newsgroups', `followup-to',
172 `to-address', `reply-to', `date', `long-to', and `many-to'."
173 :type '(set (const :tag "Headers with no content." empty)
174 (const :tag "Newsgroups with only one group." newsgroups)
175 (const :tag "To identical to to-address." to-address)
176 (const :tag "Followup-to identical to newsgroups." followup-to)
177 (const :tag "Reply-to identical to from." reply-to)
178 (const :tag "Date less than four days old." date)
179 (const :tag "Very long To and/or Cc header." long-to)
180 (const :tag "Multiple To and/or Cc headers." many-to))
181 :group 'gnus-article-hiding)
183 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
184 "Regexp matching signature separator.
185 This can also be a list of regexps. In that case, it will be checked
186 from head to tail looking for a separator. Searches will be done from
187 the end of the buffer."
188 :type '(repeat string)
189 :group 'gnus-article-signature)
191 (defcustom gnus-signature-limit nil
192 "Provide a limit to what is considered a signature.
193 If it is a number, no signature may not be longer (in characters) than
194 that number. If it is a floating point number, no signature may be
195 longer (in lines) than that number. If it is a function, the function
196 will be called without any parameters, and if it returns nil, there is
197 no signature in the buffer. If it is a string, it will be used as a
198 regexp. If it matches, the text in question is not a signature."
199 :type '(choice (integer :value 200)
201 (function :value fun)
202 (regexp :value ".*"))
203 :group 'gnus-article-signature)
205 (defcustom gnus-hidden-properties '(invisible t intangible t)
206 "Property list to use for hiding text."
208 :group 'gnus-article-hiding)
210 ;; Fixme: This isn't the right thing for mixed graphical and and
211 ;; non-graphical frames in a session.
212 ;; gnus-xmas.el overrides this for XEmacs.
213 (defcustom gnus-article-x-face-command
214 (if (and (fboundp 'image-type-available-p)
215 (image-type-available-p 'xbm))
216 'gnus-article-display-xface
217 (if gnus-article-compface-xbm
218 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
219 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
221 "*String or function to be executed to display an X-Face header.
222 If it is a string, the command will be executed in a sub-shell
223 asynchronously. The compressed face will be piped to this command."
224 :type '(choice string
225 (function-item gnus-article-display-xface)
228 :group 'gnus-article-washing)
230 (defcustom gnus-article-x-face-too-ugly nil
231 "Regexp matching posters whose face shouldn't be shown automatically."
232 :type '(choice regexp (const nil))
233 :group 'gnus-article-washing)
235 (defcustom gnus-article-banner-alist nil
236 "Banner alist for stripping.
238 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
240 :type '(repeat (cons symbol regexp))
241 :group 'gnus-article-washing)
243 (gnus-define-group-parameter
246 "Alist of regexps (to match group names) and banner."
247 :variable-group gnus-article-washing
249 '(choice :tag "Banner"
251 (const :tag "Remove signature" signature)
252 (symbol :tag "Item in `gnus-article-banner-alist'" none)
254 (const :tag "None" nil))
256 "If non-nil, specify how to remove `banners' from articles.
258 Symbol `signature' means to remove signatures delimited by
259 `gnus-signature-separator'. Any other symbol is used to look up a
260 regular expression to match the banner in `gnus-article-banner-alist'.
261 A string is used as a regular expression to match the banner
264 (defcustom gnus-emphasis-alist
266 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
268 '(("_" "_" underline)
271 ("_/" "/_" underline-italic)
272 ("_\\*" "\\*_" underline-bold)
273 ("\\*/" "/\\*" bold-italic)
274 ("_\\*/" "/\\*_" underline-bold-italic))))
275 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
276 2 3 gnus-emphasis-underline)
280 (format format (car spec) (cadr spec))
281 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
283 "*Alist that says how to fontify certain phrases.
284 Each item looks like this:
286 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
288 The first element is a regular expression to be matched. The second
289 is a number that says what regular expression grouping used to find
290 the entire emphasized word. The third is a number that says what
291 regexp grouping should be displayed and highlighted. The fourth
292 is the face used for highlighting."
293 :type '(repeat (list :value ("" 0 0 default)
295 (integer :tag "Match group")
296 (integer :tag "Emphasize group")
298 :group 'gnus-article-emphasis)
300 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
301 "A regexp to describe whitespace which should not be emphasized.
302 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
303 The former avoids underlining of leading and trailing whitespace,
304 and the latter avoids underlining any whitespace at all."
306 :group 'gnus-article-emphasis
309 (defface gnus-emphasis-bold '((t (:bold t)))
310 "Face used for displaying strong emphasized text (*word*)."
311 :group 'gnus-article-emphasis)
313 (defface gnus-emphasis-italic '((t (:italic t)))
314 "Face used for displaying italic emphasized text (/word/)."
315 :group 'gnus-article-emphasis)
317 (defface gnus-emphasis-underline '((t (:underline t)))
318 "Face used for displaying underlined emphasized text (_word_)."
319 :group 'gnus-article-emphasis)
321 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
322 "Face used for displaying underlined bold emphasized text (_*word*_)."
323 :group 'gnus-article-emphasis)
325 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
326 "Face used for displaying underlined italic emphasized text (_/word/_)."
327 :group 'gnus-article-emphasis)
329 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
330 "Face used for displaying bold italic emphasized text (/*word*/)."
331 :group 'gnus-article-emphasis)
333 (defface gnus-emphasis-underline-bold-italic
334 '((t (:bold t :italic t :underline t)))
335 "Face used for displaying underlined bold italic emphasized text.
336 Esample: (_/*word*/_)."
337 :group 'gnus-article-emphasis)
339 (defface gnus-emphasis-highlight-words
340 '((t (:background "black" :foreground "yellow")))
341 "Face used for displaying highlighted words."
342 :group 'gnus-article-emphasis)
344 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
345 "Format for display of Date headers in article bodies.
346 See `format-time-string' for the possible values.
348 The variable can also be function, which should return a complete Date
349 header. The function is called with one argument, the time, which can
350 be fed to `format-time-string'."
351 :type '(choice string symbol)
352 :link '(custom-manual "(gnus)Article Date")
353 :group 'gnus-article-washing)
356 (autoload 'mail-extract-address-components "mail-extr"))
358 (defcustom gnus-save-all-headers t
359 "*If non-nil, don't remove any headers before saving."
360 :group 'gnus-article-saving
363 (defcustom gnus-prompt-before-saving 'always
364 "*This variable says how much prompting is to be done when saving articles.
365 If it is nil, no prompting will be done, and the articles will be
366 saved to the default files. If this variable is `always', each and
367 every article that is saved will be preceded by a prompt, even when
368 saving large batches of articles. If this variable is neither nil not
369 `always', there the user will be prompted once for a file name for
370 each invocation of the saving commands."
371 :group 'gnus-article-saving
372 :type '(choice (item always)
373 (item :tag "never" nil)
374 (sexp :tag "once" :format "%t\n" :value t)))
376 (defcustom gnus-saved-headers gnus-visible-headers
377 "Headers to keep if `gnus-save-all-headers' is nil.
378 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
379 If that variable is nil, however, all headers that match this regexp
380 will be kept while the rest will be deleted before saving."
381 :group 'gnus-article-saving
384 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
385 "A function to save articles in your favourite format.
386 The function must be interactively callable (in other words, it must
387 be an Emacs command).
389 Gnus provides the following functions:
391 * gnus-summary-save-in-rmail (Rmail format)
392 * gnus-summary-save-in-mail (Unix mail format)
393 * gnus-summary-save-in-folder (MH folder)
394 * gnus-summary-save-in-file (article format)
395 * gnus-summary-save-in-vm (use VM's folder format)
396 * gnus-summary-write-to-file (article format -- overwrite)."
397 :group 'gnus-article-saving
398 :type '(radio (function-item gnus-summary-save-in-rmail)
399 (function-item gnus-summary-save-in-mail)
400 (function-item gnus-summary-save-in-folder)
401 (function-item gnus-summary-save-in-file)
402 (function-item gnus-summary-save-in-vm)
403 (function-item gnus-summary-write-to-file)))
405 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
406 "A function generating a file name to save articles in Rmail format.
407 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
408 :group 'gnus-article-saving
411 (defcustom gnus-mail-save-name 'gnus-plain-save-name
412 "A function generating a file name to save articles in Unix mail format.
413 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
414 :group 'gnus-article-saving
417 (defcustom gnus-folder-save-name 'gnus-folder-save-name
418 "A function generating a file name to save articles in MH folder.
419 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
420 :group 'gnus-article-saving
423 (defcustom gnus-file-save-name 'gnus-numeric-save-name
424 "A function generating a file name to save articles in article format.
425 The function is called with NEWSGROUP, HEADERS, and optional
427 :group 'gnus-article-saving
430 (defcustom gnus-split-methods
431 '((gnus-article-archive-name)
432 (gnus-article-nndoc-name))
433 "*Variable used to suggest where articles are to be saved.
434 For instance, if you would like to save articles related to Gnus in
435 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
436 you could set this variable to something like:
438 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
439 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
441 This variable is an alist where the where the key is the match and the
442 value is a list of possible files to save in if the match is non-nil.
444 If the match is a string, it is used as a regexp match on the
445 article. If the match is a symbol, that symbol will be funcalled
446 from the buffer of the article to be saved with the newsgroup as the
447 parameter. If it is a list, it will be evaled in the same buffer.
449 If this form or function returns a string, this string will be used as
450 a possible file name; and if it returns a non-nil list, that list will
451 be used as possible file names."
452 :group 'gnus-article-saving
453 :type '(repeat (choice (list :value (fun) function)
454 (cons :value ("" "") regexp (repeat string))
457 (defcustom gnus-page-delimiter "^\^L"
458 "*Regexp describing what to use as article page delimiters.
459 The default value is \"^\^L\", which is a form linefeed at the
460 beginning of a line."
462 :group 'gnus-article-various)
464 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
465 "*The format specification for the article mode line.
466 See `gnus-summary-mode-line-format' for a closer description.
468 The following additional specs are available:
470 %w The article washing status.
471 %m The number of MIME parts in the article."
473 :group 'gnus-article-various)
475 (defcustom gnus-article-mode-hook nil
476 "*A hook for Gnus article mode."
478 :group 'gnus-article-various)
480 (when (featurep 'xemacs)
481 ;; Extracted from gnus-xmas-define in order to preserve user settings
482 (when (fboundp 'turn-off-scroll-in-place)
483 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
484 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
485 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
487 (defcustom gnus-article-menu-hook nil
488 "*Hook run after the creation of the article mode menu."
490 :group 'gnus-article-various)
492 (defcustom gnus-article-prepare-hook nil
493 "*A hook called after an article has been prepared in the article buffer."
495 :group 'gnus-article-various)
497 (defcustom gnus-article-hide-pgp-hook nil
498 "*A hook called after successfully hiding a PGP signature."
500 :group 'gnus-article-various)
502 (defcustom gnus-article-button-face 'bold
503 "Face used for highlighting buttons in the article buffer.
505 An article button is a piece of text that you can activate by pressing
506 `RET' or `mouse-2' above it."
508 :group 'gnus-article-buttons)
510 (defcustom gnus-article-mouse-face 'highlight
511 "Face used for mouse highlighting in the article buffer.
513 Article buttons will be displayed in this face when the cursor is
516 :group 'gnus-article-buttons)
518 (defcustom gnus-signature-face 'gnus-signature-face
519 "Face used for highlighting a signature in the article buffer.
520 Obsolete; use the face `gnus-signature-face' for customizations instead."
522 :group 'gnus-article-highlight
523 :group 'gnus-article-signature)
525 (defface gnus-signature-face
528 "Face used for highlighting a signature in the article buffer."
529 :group 'gnus-article-highlight
530 :group 'gnus-article-signature)
532 (defface gnus-header-from-face
535 (:foreground "spring green"))
538 (:foreground "red3"))
541 "Face used for displaying from headers."
542 :group 'gnus-article-headers
543 :group 'gnus-article-highlight)
545 (defface gnus-header-subject-face
548 (:foreground "SeaGreen3"))
551 (:foreground "red4"))
553 (:bold t :italic t)))
554 "Face used for displaying subject headers."
555 :group 'gnus-article-headers
556 :group 'gnus-article-highlight)
558 (defface gnus-header-newsgroups-face
561 (:foreground "yellow" :italic t))
564 (:foreground "MidnightBlue" :italic t))
567 "Face used for displaying newsgroups headers."
568 :group 'gnus-article-headers
569 :group 'gnus-article-highlight)
571 (defface gnus-header-name-face
574 (:foreground "SeaGreen"))
577 (:foreground "maroon"))
580 "Face used for displaying header names."
581 :group 'gnus-article-headers
582 :group 'gnus-article-highlight)
584 (defface gnus-header-content-face
587 (:foreground "forest green" :italic t))
590 (:foreground "indianred4" :italic t))
592 (:italic t))) "Face used for displaying header content."
593 :group 'gnus-article-headers
594 :group 'gnus-article-highlight)
596 (defcustom gnus-header-face-alist
597 '(("From" nil gnus-header-from-face)
598 ("Subject" nil gnus-header-subject-face)
599 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
600 ("" gnus-header-name-face gnus-header-content-face))
601 "*Controls highlighting of article header.
603 An alist of the form (HEADER NAME CONTENT).
605 HEADER is a regular expression which should match the name of an
606 header header and NAME and CONTENT are either face names or nil.
608 The name of each header field will be displayed using the face
609 specified by the first element in the list where HEADER match the
610 header name and NAME is non-nil. Similarly, the content will be
611 displayed by the first non-nil matching CONTENT face."
612 :group 'gnus-article-headers
613 :group 'gnus-article-highlight
614 :type '(repeat (list (regexp :tag "Header")
616 (item :tag "skip" nil)
617 (face :value default))
618 (choice :tag "Content"
619 (item :tag "skip" nil)
620 (face :value default)))))
622 (defcustom gnus-article-decode-hook
623 '(article-decode-charset article-decode-encoded-words)
624 "*Hook run to decode charsets in articles."
625 :group 'gnus-article-headers
628 (defcustom gnus-display-mime-function 'gnus-display-mime
629 "Function to display MIME articles."
630 :group 'gnus-article-mime
633 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
634 "Function used to decode headers.")
636 (defvar gnus-article-dumbquotes-map
655 "Table for MS-to-Latin1 translation.")
657 (defcustom gnus-ignored-mime-types nil
658 "List of MIME types that should be ignored by Gnus."
660 :group 'gnus-article-mime
661 :type '(repeat regexp))
663 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
664 "List of MIME types that should not be given buttons when rendered inline."
666 :group 'gnus-article-mime
667 :type '(repeat regexp))
669 (defcustom gnus-article-mime-part-function nil
670 "Function called with a MIME handle as the argument.
671 This is meant for people who want to do something automatic based
672 on parts -- for instance, adding Vcard info to a database."
673 :group 'gnus-article-mime
676 (defcustom gnus-mime-multipart-functions nil
677 "An alist of MIME types to functions to display them."
679 :group 'gnus-article-mime
682 (defcustom gnus-article-date-lapsed-new-header nil
683 "Whether the X-Sent and Date headers can coexist.
684 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
685 either replace the old \"Date:\" header (if this variable is nil), or
686 be added below it (otherwise)."
688 :group 'gnus-article-headers
691 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
692 "Function called with a MIME handle as the argument.
693 This is meant for people who want to view first matched part.
694 For `undisplayed-alternative' (default), the first undisplayed
695 part or alternative part is used. For `undisplayed', the first
696 undisplayed part is used. For a function, the first part which
697 the function return `t' is used. For `nil', the first part is
700 :group 'gnus-article-mime
702 (item :tag "first" :value nil)
703 (item :tag "undisplayed" :value undisplayed)
704 (item :tag "undisplayed or alternative"
705 :value undisplayed-alternative)
708 (defcustom gnus-mime-action-alist
709 '(("save to file" . gnus-mime-save-part)
710 ("save and strip" . gnus-mime-save-part-and-strip)
711 ("display as text" . gnus-mime-inline-part)
712 ("view the part" . gnus-mime-view-part)
713 ("pipe to command" . gnus-mime-pipe-part)
714 ("toggle display" . gnus-article-press-button)
715 ("toggle display" . gnus-article-view-part-as-charset)
716 ("view as type" . gnus-mime-view-part-as-type)
717 ("internalize type" . gnus-mime-internalize-part)
718 ("externalize type" . gnus-mime-externalize-part))
719 "An alist of actions that run on the MIME attachment."
720 :group 'gnus-article-mime
721 :type '(repeat (cons (string :tag "name")
724 (defcustom gnus-mime-action-alist
725 '(("save to file" . gnus-mime-save-part)
726 ("display as text" . gnus-mime-inline-part)
727 ("view the part" . gnus-mime-view-part)
728 ("pipe to command" . gnus-mime-pipe-part)
729 ("toggle display" . gnus-article-press-button)
730 ("view as type" . gnus-mime-view-part-as-type)
731 ("internalize type" . gnus-mime-internalize-part)
732 ("externalize type" . gnus-mime-externalize-part))
733 "An alist of actions that run on the MIME attachment."
735 :group 'gnus-article-mime
736 :type '(repeat (cons (string :tag "name")
740 ;;; The treatment variables
743 (defvar gnus-part-display-hook nil
744 "Hook called on parts that are to receive treatment.")
746 (defvar gnus-article-treat-custom
747 '(choice (const :tag "Off" nil)
749 (const :tag "Header" head)
750 (const :tag "Last" last)
751 (integer :tag "Less")
752 (repeat :tag "Groups" regexp)
753 (sexp :tag "Predicate")))
755 (defvar gnus-article-treat-head-custom
756 '(choice (const :tag "Off" nil)
757 (const :tag "Header" head)))
759 (defvar gnus-article-treat-types '("text/plain")
762 (defvar gnus-inhibit-treatment nil
763 "Whether to inhibit treatment.")
765 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
766 "Highlight the signature.
767 Valid values are nil, t, `head', `last', an integer or a predicate.
768 See the manual for details."
769 :group 'gnus-article-treat
770 :type gnus-article-treat-custom)
771 (put 'gnus-treat-highlight-signature 'highlight t)
773 (defcustom gnus-treat-buttonize 100000
775 Valid values are nil, t, `head', `last', an integer or a predicate.
776 See the manual for details."
777 :group 'gnus-article-treat
778 :type gnus-article-treat-custom)
779 (put 'gnus-treat-buttonize 'highlight t)
781 (defcustom gnus-treat-buttonize-head 'head
782 "Add buttons to the head.
783 Valid values are nil, t, `head', `last', an integer or a predicate.
784 See the manual for details."
785 :group 'gnus-article-treat
786 :type gnus-article-treat-head-custom)
787 (put 'gnus-treat-buttonize-head 'highlight t)
789 (defcustom gnus-treat-emphasize
790 (and (or window-system
792 (>= (string-to-number emacs-version) 21))
795 Valid values are nil, t, `head', `last', an integer or a predicate.
796 See the manual for details."
797 :group 'gnus-article-treat
798 :type gnus-article-treat-custom)
799 (put 'gnus-treat-emphasize 'highlight t)
801 (defcustom gnus-treat-strip-cr nil
802 "Remove carriage returns.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-custom)
808 (defcustom gnus-treat-leading-whitespace nil
809 "Remove leading whitespace in headers.
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-custom)
815 (defcustom gnus-treat-hide-headers 'head
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-head-custom)
822 (defcustom gnus-treat-hide-boring-headers nil
823 "Hide boring headers.
824 Valid values are nil, t, `head', `last', an integer or a predicate.
825 See the manual for details."
826 :group 'gnus-article-treat
827 :type gnus-article-treat-head-custom)
829 (defcustom gnus-treat-hide-signature nil
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833 :group 'gnus-article-treat
834 :type gnus-article-treat-custom)
836 (defcustom gnus-treat-fill-article nil
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840 :group 'gnus-article-treat
841 :type gnus-article-treat-custom)
843 (defcustom gnus-treat-hide-citation nil
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-custom)
850 (defcustom gnus-treat-hide-citation-maybe nil
852 Valid values are nil, t, `head', `last', an integer or a predicate.
853 See the manual for details."
854 :group 'gnus-article-treat
855 :type gnus-article-treat-custom)
857 (defcustom gnus-treat-hide-citation-maybe nil
859 Valid values are nil, t, `head', `last', an integer or a predicate.
860 See the manual for details."
861 :group 'gnus-article-treat
862 :type gnus-article-treat-custom)
864 (defcustom gnus-treat-strip-list-identifiers 'head
865 "Strip list identifiers from `gnus-list-identifiers`.
866 Valid values are nil, t, `head', `last', an integer or a predicate.
867 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
872 (defcustom gnus-treat-strip-pgp t
873 "Strip PGP signatures.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876 :group 'gnus-article-treat
877 :type gnus-article-treat-custom)
879 (defcustom gnus-treat-strip-pem nil
880 "Strip PEM signatures.
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-custom)
886 (defcustom gnus-treat-strip-banner t
887 "Strip banners from articles.
888 The banner to be stripped is specified in the `banner' group parameter.
889 Valid values are nil, t, `head', `last', an integer or a predicate.
890 See the manual for details."
891 :group 'gnus-article-treat
892 :type gnus-article-treat-custom)
894 (defcustom gnus-treat-highlight-headers 'head
895 "Highlight the headers.
896 Valid values are nil, t, `head', `last', an integer or a predicate.
897 See the manual for details."
898 :group 'gnus-article-treat
899 :type gnus-article-treat-head-custom)
900 (put 'gnus-treat-highlight-headers 'highlight t)
902 (defcustom gnus-treat-highlight-citation t
903 "Highlight cited text.
904 Valid values are nil, t, `head', `last', an integer or a predicate.
905 See the manual for details."
906 :group 'gnus-article-treat
907 :type gnus-article-treat-custom)
908 (put 'gnus-treat-highlight-citation 'highlight t)
910 (defcustom gnus-treat-date-ut nil
911 "Display the Date in UT (GMT).
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914 :group 'gnus-article-treat
915 :type gnus-article-treat-head-custom)
917 (defcustom gnus-treat-date-local nil
918 "Display the Date in the local timezone.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-head-custom)
924 (defcustom gnus-treat-date-english nil
925 "Display the Date in a format that can be read aloud in English.
926 Valid values are nil, t, `head', `last', an integer or a predicate.
927 See the manual for details."
928 :group 'gnus-article-treat
929 :type gnus-article-treat-head-custom)
931 (defcustom gnus-treat-date-lapsed nil
932 "Display the Date header in a way that says how much time has elapsed.
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
935 :group 'gnus-article-treat
936 :type gnus-article-treat-head-custom)
938 (defcustom gnus-treat-date-original nil
939 "Display the date in the original timezone.
940 Valid values are nil, t, `head', `last', an integer or a predicate.
941 See the manual for details."
942 :group 'gnus-article-treat
943 :type gnus-article-treat-head-custom)
945 (defcustom gnus-treat-date-iso8601 nil
946 "Display the date in the ISO8601 format.
947 Valid values are nil, t, `head', `last', an integer or a predicate.
948 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-head-custom)
953 (defcustom gnus-treat-date-user-defined nil
954 "Display the date in a user-defined format.
955 The format is defined by the `gnus-article-time-format' variable.
956 Valid values are nil, t, `head', `last', an integer or a predicate.
957 See the manual for details."
958 :group 'gnus-article-treat
959 :type gnus-article-treat-head-custom)
961 (defcustom gnus-treat-strip-headers-in-body t
962 "Strip the X-No-Archive header line from the beginning of the body.
963 Valid values are nil, t, `head', `last', an integer or a predicate.
964 See the manual for details."
966 :group 'gnus-article-treat
967 :type gnus-article-treat-custom)
969 (defcustom gnus-treat-strip-trailing-blank-lines nil
970 "Strip trailing blank lines.
971 Valid values are nil, t, `head', `last', an integer or a predicate.
972 See the manual for details."
973 :group 'gnus-article-treat
974 :type gnus-article-treat-custom)
976 (defcustom gnus-treat-strip-leading-blank-lines nil
977 "Strip leading blank lines.
978 Valid values are nil, t, `head', `last', an integer or a predicate.
979 See the manual for details."
980 :group 'gnus-article-treat
981 :type gnus-article-treat-custom)
983 (defcustom gnus-treat-strip-multiple-blank-lines nil
984 "Strip multiple blank lines.
985 Valid values are nil, t, `head', `last', an integer or a predicate.
986 See the manual for details."
987 :group 'gnus-article-treat
988 :type gnus-article-treat-custom)
990 (defcustom gnus-treat-overstrike t
991 "Treat overstrike highlighting.
992 Valid values are nil, t, `head', `last', an integer or a predicate.
993 See the manual for details."
994 :group 'gnus-article-treat
995 :type gnus-article-treat-custom)
996 (put 'gnus-treat-overstrike 'highlight t)
998 (defcustom gnus-treat-display-xface
999 (and (or (and (fboundp 'image-type-available-p)
1000 (image-type-available-p 'xbm)
1001 (string-match "^0x" (shell-command-to-string "uncompface")))
1002 (and (featurep 'xemacs) (featurep 'xface)))
1004 "Display X-Face headers.
1005 Valid values are nil, t, `head', `last', an integer or a predicate.
1006 See the manual for details."
1007 :group 'gnus-article-treat
1009 :type gnus-article-treat-head-custom)
1010 (put 'gnus-treat-display-xface 'highlight t)
1012 (defcustom gnus-treat-display-smileys
1013 (if (or (and (featurep 'xemacs)
1015 (and (fboundp 'image-type-available-p)
1016 (image-type-available-p 'pbm)))
1019 Valid values are nil, t, `head', `last', an integer or a predicate.
1020 See the manual for details."
1021 :group 'gnus-article-treat
1023 :type gnus-article-treat-custom)
1024 (put 'gnus-treat-display-smileys 'highlight t)
1026 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1028 Valid values are nil, t, `head', `last', an integer or a predicate.
1029 See the manual for details."
1030 :group 'gnus-article-treat
1031 :type gnus-article-treat-head-custom)
1032 (put 'gnus-treat-display-picons 'highlight t)
1034 (defcustom gnus-treat-capitalize-sentences nil
1035 "Capitalize sentence-starting words.
1036 Valid values are nil, t, `head', `last', an integer or a predicate.
1037 See the manual for details."
1039 :group 'gnus-article-treat
1040 :type gnus-article-treat-custom)
1042 (defcustom gnus-treat-fill-long-lines nil
1044 Valid values are nil, t, `head', `last', an integer or a predicate.
1045 See the manual for details."
1046 :group 'gnus-article-treat
1047 :type gnus-article-treat-custom)
1049 (defcustom gnus-treat-play-sounds nil
1051 Valid values are nil, t, `head', `last', an integer or a predicate.
1052 See the manual for details."
1054 :group 'gnus-article-treat
1055 :type gnus-article-treat-custom)
1057 (defcustom gnus-treat-translate nil
1058 "Translate articles from one language to another.
1059 Valid values are nil, t, `head', `last', an integer or a predicate.
1060 See the manual for details."
1062 :group 'gnus-article-treat
1063 :type gnus-article-treat-custom)
1065 (defcustom gnus-treat-x-pgp-sig nil
1067 To automatically treat X-PGP-Sig, set it to head.
1068 Valid values are nil, t, `head', `last', an integer or a predicate.
1069 See the manual for details."
1070 :group 'gnus-article-treat
1071 :group 'mime-security
1072 :type gnus-article-treat-custom)
1074 (defvar gnus-article-encrypt-protocol-alist
1075 '(("PGP" . mml2015-self-encrypt)))
1077 ;; Set to nil if more than one protocol added to
1078 ;; gnus-article-encrypt-protocol-alist.
1079 (defcustom gnus-article-encrypt-protocol "PGP"
1080 "The protocol used for encrypt articles.
1081 It is a string, such as \"PGP\". If nil, ask user."
1083 :group 'mime-security)
1085 ;;; Internal variables
1087 (defvar gnus-english-month-names
1088 '("January" "February" "March" "April" "May" "June" "July" "August"
1089 "September" "October" "November" "December"))
1091 (defvar article-goto-body-goes-to-point-min-p nil)
1092 (defvar gnus-article-wash-types nil)
1093 (defvar gnus-article-emphasis-alist nil)
1095 (defvar gnus-article-mime-handle-alist-1 nil)
1096 (defvar gnus-treatment-function-alist
1097 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1098 (gnus-treat-strip-banner gnus-article-strip-banner)
1099 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1100 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1101 (gnus-treat-buttonize gnus-article-add-buttons)
1102 (gnus-treat-fill-article gnus-article-fill-cited-article)
1103 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1104 (gnus-treat-strip-cr gnus-article-remove-cr)
1105 (gnus-treat-emphasize gnus-article-emphasize)
1106 (gnus-treat-display-xface gnus-article-display-x-face)
1107 (gnus-treat-date-ut gnus-article-date-ut)
1108 (gnus-treat-date-local gnus-article-date-local)
1109 (gnus-treat-date-english gnus-article-date-english)
1110 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1111 (gnus-treat-date-original gnus-article-date-original)
1112 (gnus-treat-date-user-defined gnus-article-date-user)
1113 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1114 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1115 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1116 (gnus-treat-hide-signature gnus-article-hide-signature)
1117 (gnus-treat-hide-citation gnus-article-hide-citation)
1118 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1119 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1120 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1121 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1122 (gnus-treat-strip-pem gnus-article-hide-pem)
1123 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1124 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1125 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1126 (gnus-treat-strip-trailing-blank-lines
1127 gnus-article-remove-trailing-blank-lines)
1128 (gnus-treat-strip-leading-blank-lines
1129 gnus-article-strip-leading-blank-lines)
1130 (gnus-treat-strip-multiple-blank-lines
1131 gnus-article-strip-multiple-blank-lines)
1132 (gnus-treat-overstrike gnus-article-treat-overstrike)
1133 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1134 (gnus-treat-display-smileys gnus-smiley-display)
1135 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1136 (gnus-treat-display-picons gnus-article-display-picons)
1137 (gnus-treat-play-sounds gnus-earcon-display)))
1139 (defvar gnus-article-mime-handle-alist nil)
1140 (defvar article-lapsed-timer nil)
1141 (defvar gnus-article-current-summary nil)
1143 (defvar gnus-article-mode-syntax-table
1144 (let ((table (copy-syntax-table text-mode-syntax-table)))
1145 ;; This causes the citation match run O(2^n).
1146 ;; (modify-syntax-entry ?- "w" table)
1147 (modify-syntax-entry ?> ")" table)
1148 (modify-syntax-entry ?< "(" table)
1150 "Syntax table used in article mode buffers.
1151 Initialized from `text-mode-syntax-table.")
1153 (defvar gnus-save-article-buffer nil)
1155 (defvar gnus-article-mode-line-format-alist
1156 (nconc '((?w (gnus-article-wash-status) ?s)
1157 (?m (gnus-article-mime-part-status) ?s))
1158 gnus-summary-mode-line-format-alist))
1160 (defvar gnus-number-of-articles-to-be-saved nil)
1162 (defvar gnus-inhibit-hiding nil)
1164 (defsubst gnus-article-hide-text (b e props)
1165 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1166 (gnus-add-text-properties-when 'article-type nil b e props)
1167 (when (memq 'intangible props)
1169 (max (1- b) (point-min))
1170 b 'intangible (cddr (memq 'intangible props)))))
1172 (defsubst gnus-article-unhide-text (b e)
1173 "Remove hidden text properties from region between B and E."
1174 (remove-text-properties b e gnus-hidden-properties)
1175 (when (memq 'intangible gnus-hidden-properties)
1176 (put-text-property (max (1- b) (point-min))
1177 b 'intangible nil)))
1179 (defun gnus-article-hide-text-type (b e type)
1180 "Hide text of TYPE between B and E."
1181 (push type gnus-article-wash-types)
1182 (gnus-article-hide-text
1183 b e (cons 'article-type (cons type gnus-hidden-properties))))
1185 (defun gnus-article-unhide-text-type (b e type)
1186 "Unhide text of TYPE between B and E."
1187 (setq gnus-article-wash-types
1188 (delq type gnus-article-wash-types))
1189 (remove-text-properties
1190 b e (cons 'article-type (cons type gnus-hidden-properties)))
1191 (when (memq 'intangible gnus-hidden-properties)
1192 (put-text-property (max (1- b) (point-min))
1193 b 'intangible nil)))
1195 (defun gnus-article-hide-text-of-type (type)
1196 "Hide text of TYPE in the current buffer."
1198 (let ((b (point-min))
1200 (while (setq b (text-property-any b e 'article-type type))
1201 (add-text-properties b (incf b) gnus-hidden-properties)))))
1203 (defun gnus-article-delete-text-of-type (type)
1204 "Delete text of TYPE in the current buffer."
1206 (let ((b (point-min)))
1207 (while (setq b (text-property-any b (point-max) 'article-type type))
1209 b (or (text-property-not-all b (point-max) 'article-type type)
1212 (defun gnus-article-delete-invisible-text ()
1213 "Delete all invisible text in the current buffer."
1215 (let ((b (point-min)))
1216 (while (setq b (text-property-any b (point-max) 'invisible t))
1218 b (or (text-property-not-all b (point-max) 'invisible t)
1221 (defun gnus-article-text-type-exists-p (type)
1222 "Say whether any text of type TYPE exists in the buffer."
1223 (text-property-any (point-min) (point-max) 'article-type type))
1225 (defsubst gnus-article-header-rank ()
1226 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1227 (let ((list gnus-sorted-header-list)
1230 (when (looking-at (car list))
1232 (setq list (cdr list))
1236 (defun article-hide-headers (&optional arg delete)
1237 "Hide unwanted headers and possibly sort them as well."
1239 ;; This function might be inhibited.
1240 (unless gnus-inhibit-hiding
1243 (let ((buffer-read-only nil)
1244 (case-fold-search t)
1245 (max (1+ (length gnus-sorted-header-list)))
1246 (ignored (when (not gnus-visible-headers)
1247 (cond ((stringp gnus-ignored-headers)
1248 gnus-ignored-headers)
1249 ((listp gnus-ignored-headers)
1250 (mapconcat 'identity gnus-ignored-headers
1253 (cond ((stringp gnus-visible-headers)
1254 gnus-visible-headers)
1255 ((and gnus-visible-headers
1256 (listp gnus-visible-headers))
1257 (mapconcat 'identity gnus-visible-headers "\\|"))))
1258 (inhibit-point-motion-hooks t)
1260 ;; First we narrow to just the headers.
1261 (article-narrow-to-head)
1262 ;; Hide any "From " lines at the beginning of (mail) articles.
1263 (while (looking-at "From ")
1266 (delete-region (point-min) (point)))
1267 ;; Then treat the rest of the header lines.
1268 ;; Then we use the two regular expressions
1269 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1270 ;; select which header lines is to remain visible in the
1272 (while (re-search-forward "^[^ \t]*:" nil t)
1274 ;; Mark the rank of the header.
1276 (point) (1+ (point)) 'message-rank
1277 (if (or (and visible (looking-at visible))
1279 (not (looking-at ignored))))
1280 (gnus-article-header-rank)
1283 (message-sort-headers-1)
1284 (when (setq beg (text-property-any
1285 (point-min) (point-max) 'message-rank (+ 2 max)))
1286 ;; We delete the unwanted headers.
1287 (push 'headers gnus-article-wash-types)
1288 (add-text-properties (point-min) (+ 5 (point-min))
1289 '(article-type headers dummy-invisible t))
1290 (delete-region beg (point-max))))))))
1292 (defun article-hide-boring-headers (&optional arg)
1293 "Toggle hiding of headers that aren't very interesting.
1294 If given a negative prefix, always show; if given a positive prefix,
1296 (interactive (gnus-article-hidden-arg))
1297 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1298 (not gnus-show-all-headers))
1301 (let ((buffer-read-only nil)
1302 (list gnus-boring-article-headers)
1303 (inhibit-point-motion-hooks t)
1305 (article-narrow-to-head)
1307 (setq elem (pop list))
1308 (goto-char (point-min))
1310 ;; Hide empty headers.
1312 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1314 (gnus-article-hide-text-type
1315 (progn (beginning-of-line) (point))
1318 (if (re-search-forward "^[^ \t]" nil t)
1322 ;; Hide boring Newsgroups header.
1323 ((eq elem 'newsgroups)
1324 (when (gnus-string-equal
1325 (gnus-fetch-field "newsgroups")
1326 (gnus-group-real-name
1327 (if (boundp 'gnus-newsgroup-name)
1330 (gnus-article-hide-header "newsgroups")))
1331 ((eq elem 'to-address)
1332 (let ((to (message-fetch-field "to"))
1334 (gnus-parameter-to-address
1335 (if (boundp 'gnus-newsgroup-name)
1336 gnus-newsgroup-name ""))))
1337 (when (and to to-address
1340 ;; only one address in To
1341 (nth 1 (mail-extract-address-components to))
1343 (gnus-article-hide-header "to"))))
1344 ((eq elem 'followup-to)
1345 (when (gnus-string-equal
1346 (message-fetch-field "followup-to")
1347 (message-fetch-field "newsgroups"))
1348 (gnus-article-hide-header "followup-to")))
1349 ((eq elem 'reply-to)
1350 (let ((from (message-fetch-field "from"))
1351 (reply-to (message-fetch-field "reply-to")))
1356 (nth 1 (mail-extract-address-components from))
1357 (nth 1 (mail-extract-address-components reply-to)))))
1358 (gnus-article-hide-header "reply-to"))))
1360 (let ((date (message-fetch-field "date")))
1362 (< (days-between (current-time-string) date)
1364 (gnus-article-hide-header "date"))))
1366 (let ((to (message-fetch-field "to"))
1367 (cc (message-fetch-field "cc")))
1368 (when (> (length to) 1024)
1369 (gnus-article-hide-header "to"))
1370 (when (> (length cc) 1024)
1371 (gnus-article-hide-header "cc"))))
1375 (goto-char (point-min))
1376 (while (re-search-forward "^to:" nil t)
1377 (setq to-count (1+ to-count)))
1378 (when (> to-count 1)
1379 (while (> to-count 0)
1380 (goto-char (point-min))
1382 (re-search-forward "^to:" nil nil to-count)
1384 (narrow-to-region (point) (point-max))
1385 (gnus-article-hide-header "to"))
1386 (setq to-count (1- to-count))))
1387 (goto-char (point-min))
1388 (while (re-search-forward "^cc:" nil t)
1389 (setq cc-count (1+ cc-count)))
1390 (when (> cc-count 1)
1391 (while (> cc-count 0)
1392 (goto-char (point-min))
1394 (re-search-forward "^cc:" nil nil cc-count)
1396 (narrow-to-region (point) (point-max))
1397 (gnus-article-hide-header "cc"))
1398 (setq cc-count (1- cc-count)))))))))))))
1400 (defun gnus-article-hide-header (header)
1402 (goto-char (point-min))
1403 (when (re-search-forward (concat "^" header ":") nil t)
1404 (gnus-article-hide-text-type
1405 (progn (beginning-of-line) (point))
1408 (if (re-search-forward "^[^ \t]" nil t)
1413 (defvar gnus-article-normalized-header-length 40
1414 "Length of normalized headers.")
1416 (defun article-normalize-headers ()
1417 "Make all header lines 40 characters long."
1419 (let ((buffer-read-only nil)
1423 (article-narrow-to-head)
1426 ((< (setq column (- (gnus-point-at-eol) (point)))
1427 gnus-article-normalized-header-length)
1429 (insert (make-string
1430 (- gnus-article-normalized-header-length column)
1432 ((> column gnus-article-normalized-header-length)
1433 (gnus-put-text-property
1435 (forward-char gnus-article-normalized-header-length)
1442 (forward-line 1))))))
1444 (defun article-treat-dumbquotes ()
1445 "Translate M****s*** sm*rtq**t*s into proper text.
1446 Note that this function guesses whether a character is a sm*rtq**t* or
1447 not, so it should only be used interactively.
1449 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1450 in an attempt to provide more quoting characters. If you see
1451 something like \\222 or \\264 where you're expecting some kind of
1452 apostrophe or quotation mark, then try this wash."
1454 (article-translate-strings gnus-article-dumbquotes-map))
1456 (defun article-translate-characters (from to)
1457 "Translate all characters in the body of the article according to FROM and TO.
1458 FROM is a string of characters to translate from; to is a string of
1459 characters to translate to."
1461 (when (article-goto-body)
1462 (let ((buffer-read-only nil)
1463 (x (make-string 225 ?x))
1465 (while (< (incf i) (length x))
1468 (while (< i (length from))
1469 (aset x (aref from i) (aref to i))
1471 (translate-region (point) (point-max) x)))))
1473 (defun article-translate-strings (map)
1474 "Translate all string in the body of the article according to MAP.
1475 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1477 (when (article-goto-body)
1478 (let ((buffer-read-only nil)
1480 (while (setq elem (pop map))
1482 (while (search-forward (car elem) nil t)
1483 (replace-match (cadr elem)))))))))
1485 (defun article-treat-overstrike ()
1486 "Translate overstrikes into bold text."
1489 (when (article-goto-body)
1490 (let ((buffer-read-only nil))
1491 (while (search-forward "\b" nil t)
1492 (let ((next (char-after))
1493 (previous (char-after (- (point) 2))))
1494 ;; We do the boldification/underlining by hiding the
1495 ;; overstrikes and putting the proper text property
1499 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1500 (put-text-property (point) (1+ (point)) 'face 'bold))
1502 (gnus-article-hide-text-type
1503 (1- (point)) (1+ (point)) 'overstrike)
1505 (- (point) 2) (1- (point)) 'face 'underline))
1507 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1509 (point) (1+ (point)) 'face 'underline)))))))))
1511 (defun article-fill-long-lines ()
1512 "Fill lines that are wider than the window width."
1515 (let ((buffer-read-only nil)
1516 (width (window-width (get-buffer-window (current-buffer)))))
1519 (let ((adaptive-fill-mode nil))
1522 (when (>= (current-column) (min fill-column width))
1523 (narrow-to-region (point) (gnus-point-at-bol))
1524 (fill-paragraph nil)
1525 (goto-char (point-max))
1527 (forward-line 1)))))))
1529 (defun article-capitalize-sentences ()
1530 "Capitalize the first word in each sentence."
1533 (let ((buffer-read-only nil)
1534 (paragraph-start "^[\n\^L]"))
1538 (forward-sentence)))))
1540 (defun article-remove-cr ()
1541 "Remove trailing CRs and then translate remaining CRs into LFs."
1544 (let ((buffer-read-only nil))
1545 (goto-char (point-min))
1546 (while (re-search-forward "\r+$" nil t)
1547 (replace-match "" t t))
1548 (goto-char (point-min))
1549 (while (search-forward "\r" nil t)
1550 (replace-match "\n" t t)))))
1552 (defun article-remove-trailing-blank-lines ()
1553 "Remove all trailing blank lines from the article."
1556 (let ((buffer-read-only nil))
1557 (goto-char (point-max))
1561 (while (and (not (bobp))
1562 (looking-at "^[ \t]*$")
1563 (not (gnus-annotation-in-region-p
1564 (point) (gnus-point-at-eol))))
1569 (defun article-display-x-face (&optional force)
1570 "Look for an X-Face header and display it if present."
1571 (interactive (list 'force))
1573 ;; Delete the old process, if any.
1574 (when (process-status "article-x-face")
1575 (delete-process "article-x-face"))
1576 (let ((inhibit-point-motion-hooks t)
1578 (case-fold-search t)
1581 (article-narrow-to-head)
1582 (when (and buffer-read-only ;; When type `W f'
1584 (goto-char (point-min))
1585 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1586 (gnus-buffer-live-p gnus-original-article-buffer))
1587 (with-current-buffer gnus-original-article-buffer
1589 (article-narrow-to-head)
1590 (while (re-search-forward "^X-Face:" nil t)
1596 (1- (re-search-forward
1597 "^\\($\\|[^ \t]\\)" nil t))))))))
1599 (let (point start bface eface buffer-read-only)
1600 (goto-char (point-max))
1602 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1603 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1604 (goto-char (point-max))
1605 (setq point (point))
1608 (while (looking-at "\\([^:]+\\): *")
1609 (put-text-property (match-beginning 1) (1+ (match-end 1))
1611 (setq start (match-end 0))
1613 (while (looking-at "[\t ]")
1615 (put-text-property start (point)
1617 (goto-char (point-min))
1618 (setq from (message-fetch-field "from"))
1619 (goto-char (point-min))
1620 (while (and gnus-article-x-face-command
1623 ;; Check whether this face is censored.
1624 (not gnus-article-x-face-too-ugly)
1625 (and gnus-article-x-face-too-ugly from
1626 (not (string-match gnus-article-x-face-too-ugly
1628 ;; Has to be present.
1629 (re-search-forward "^X-Face:[\t ]*" nil t))
1630 ;; This used to try to do multiple faces (`while' instead of
1631 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1632 ;; work (b) it can crash some versions of Emacs (c) are
1633 ;; multiple faces really something to encourage?
1634 (when (stringp gnus-article-x-face-command)
1636 ;; We now have the area of the buffer where the X-Face is stored.
1639 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1640 ;; We display the face.
1641 (if (symbolp gnus-article-x-face-command)
1642 ;; The command is a lisp function, so we call it.
1643 (if (gnus-functionp gnus-article-x-face-command)
1644 (funcall gnus-article-x-face-command beg end)
1645 (error "%s is not a function" gnus-article-x-face-command))
1646 ;; The command is a string, so we interpret the command
1647 ;; as a, well, command, and fork it off.
1648 (let ((process-connection-type nil))
1649 (process-kill-without-query
1651 "article-x-face" nil shell-file-name shell-command-switch
1652 gnus-article-x-face-command))
1653 (process-send-region "article-x-face" beg end)
1654 (process-send-eof "article-x-face"))))))))))
1656 (defun article-decode-mime-words ()
1657 "Decode all MIME-encoded words in the article."
1660 (set-buffer gnus-article-buffer)
1661 (let ((inhibit-point-motion-hooks t)
1663 (mail-parse-charset gnus-newsgroup-charset)
1664 (mail-parse-ignored-charsets
1665 (save-excursion (set-buffer gnus-summary-buffer)
1666 gnus-newsgroup-ignored-charsets)))
1667 (mail-decode-encoded-word-region (point-min) (point-max)))))
1669 (defun article-decode-charset (&optional prompt)
1670 "Decode charset-encoded text in the article.
1671 If PROMPT (the prefix), prompt for a coding system to use."
1673 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1675 (mail-parse-charset gnus-newsgroup-charset)
1676 (mail-parse-ignored-charsets
1677 (save-excursion (condition-case nil
1678 (set-buffer gnus-summary-buffer)
1680 gnus-newsgroup-ignored-charsets))
1681 ct cte ctl charset format)
1684 (article-narrow-to-head)
1685 (setq ct (message-fetch-field "Content-Type" t)
1686 cte (message-fetch-field "Content-Transfer-Encoding" t)
1687 ctl (and ct (ignore-errors
1688 (mail-header-parse-content-type ct)))
1691 (mm-read-coding-system "Charset to decode: "))
1693 (mail-content-type-get ctl 'charset)))
1694 format (and ctl (mail-content-type-get ctl 'format)))
1696 (setq cte (mail-header-strip cte)))
1697 (if (and ctl (not (string-match "/" (car ctl))))
1699 (goto-char (point-max)))
1702 (narrow-to-region (point) (point-max))
1703 (when (and (eq mail-parse-charset 'gnus-decoded)
1704 (eq (mm-body-7-or-8) '8bit))
1705 ;; The text code could have been decoded.
1706 (setq charset mail-parse-charset))
1707 (when (and (or (not ctl)
1708 (equal (car ctl) "text/plain"))
1709 (not format)) ;; article with format will decode later.
1711 charset (and cte (intern (downcase
1712 (gnus-strip-whitespace cte))))
1715 (defun article-decode-encoded-words ()
1716 "Remove encoded-word encoding from headers."
1717 (let ((inhibit-point-motion-hooks t)
1718 (mail-parse-charset gnus-newsgroup-charset)
1719 (mail-parse-ignored-charsets
1720 (save-excursion (condition-case nil
1721 (set-buffer gnus-summary-buffer)
1723 gnus-newsgroup-ignored-charsets))
1726 (article-narrow-to-head)
1727 (funcall gnus-decode-header-function (point-min) (point-max)))))
1729 (defun article-de-quoted-unreadable (&optional force)
1730 "Translate a quoted-printable-encoded article.
1731 If FORCE, decode the article whether it is marked as quoted-printable
1733 (interactive (list 'force))
1735 (let ((buffer-read-only nil) type charset)
1736 (if (gnus-buffer-live-p gnus-original-article-buffer)
1737 (with-current-buffer gnus-original-article-buffer
1739 (gnus-fetch-field "content-transfer-encoding"))
1740 (let* ((ct (gnus-fetch-field "content-type"))
1743 (mail-header-parse-content-type ct)))))
1744 (setq charset (and ctl
1745 (mail-content-type-get ctl 'charset)))
1746 (if (stringp charset)
1747 (setq charset (intern (downcase charset)))))))
1749 (setq charset gnus-newsgroup-charset))
1751 (and type (let ((case-fold-search t))
1752 (string-match "quoted-printable" type))))
1754 (quoted-printable-decode-region
1755 (point) (point-max) (mm-charset-to-coding-system charset))))))
1757 (defun article-de-base64-unreadable (&optional force)
1758 "Translate a base64 article.
1759 If FORCE, decode the article whether it is marked as base64 not."
1760 (interactive (list 'force))
1762 (let ((buffer-read-only nil) type charset)
1763 (if (gnus-buffer-live-p gnus-original-article-buffer)
1764 (with-current-buffer gnus-original-article-buffer
1766 (gnus-fetch-field "content-transfer-encoding"))
1767 (let* ((ct (gnus-fetch-field "content-type"))
1770 (mail-header-parse-content-type ct)))))
1771 (setq charset (and ctl
1772 (mail-content-type-get ctl 'charset)))
1773 (if (stringp charset)
1774 (setq charset (intern (downcase charset)))))))
1776 (setq charset gnus-newsgroup-charset))
1778 (and type (let ((case-fold-search t))
1779 (string-match "base64" type))))
1782 (narrow-to-region (point) (point-max))
1783 (base64-decode-region (point-min) (point-max))
1784 (mm-decode-coding-region
1785 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1790 (defun article-decode-HZ ()
1791 "Translate a HZ-encoded article."
1795 (let ((buffer-read-only nil))
1796 (rfc1843-decode-region (point-min) (point-max)))))
1798 (defun article-wash-html ()
1799 "Format an html article."
1802 (let ((buffer-read-only nil)
1804 (if (gnus-buffer-live-p gnus-original-article-buffer)
1805 (with-current-buffer gnus-original-article-buffer
1806 (let* ((ct (gnus-fetch-field "content-type"))
1809 (mail-header-parse-content-type ct)))))
1810 (setq charset (and ctl
1811 (mail-content-type-get ctl 'charset)))
1812 (if (stringp charset)
1813 (setq charset (intern (downcase charset)))))))
1815 (setq charset gnus-newsgroup-charset))
1817 (save-window-excursion
1819 (narrow-to-region (point) (point-max))
1821 (let ((w3-strict-width (window-width))
1822 (url-standalone-mode t))
1824 (w3-region (point-min) (point-max))
1827 (defun article-hide-list-identifiers ()
1828 "Remove list identifies from the Subject header.
1829 The `gnus-list-identifiers' variable specifies what to do."
1831 (let ((inhibit-point-motion-hooks t)
1832 (regexp (if (consp gnus-list-identifiers)
1833 (mapconcat 'identity gnus-list-identifiers " *\\|")
1834 gnus-list-identifiers))
1839 (article-narrow-to-head)
1840 (goto-char (point-min))
1841 (while (re-search-forward
1842 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
1844 (delete-region (match-beginning 2) (match-end 0))
1845 (beginning-of-line))
1846 (when (re-search-forward
1847 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
1848 (delete-region (match-beginning 1) (match-end 1))))))))
1850 (defun article-hide-pgp ()
1851 "Remove any PGP headers and signatures in the current article."
1855 (let ((inhibit-point-motion-hooks t)
1856 buffer-read-only beg end)
1858 ;; Hide the "header".
1859 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1860 (push 'pgp gnus-article-wash-types)
1861 (delete-region (match-beginning 0) (match-end 0))
1862 ;; Remove armor headers (rfc2440 6.2)
1863 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1866 ;; Hide the actual signature.
1867 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1868 (setq end (1+ (match-beginning 0)))
1871 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1873 ;; Perhaps we shouldn't hide to the end of the buffer
1874 ;; if there is no end to the signature?
1876 ;; Hide "- " PGP quotation markers.
1878 (narrow-to-region beg end)
1879 (goto-char (point-min))
1880 (while (re-search-forward "^- " nil t)
1882 (match-beginning 0) (match-end 0)))
1884 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1886 (defun article-hide-pem (&optional arg)
1887 "Toggle hiding of any PEM headers and signatures in the current article.
1888 If given a negative prefix, always show; if given a positive prefix,
1890 (interactive (gnus-article-hidden-arg))
1891 (unless (gnus-article-check-hidden-text 'pem arg)
1893 (let (buffer-read-only end)
1894 (goto-char (point-min))
1895 ;; Hide the horrendously ugly "header".
1896 (when (and (search-forward
1897 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1899 (setq end (1+ (match-beginning 0))))
1900 (push 'pem gnus-article-wash-types)
1901 (gnus-article-hide-text-type
1903 (if (search-forward "\n\n" nil t)
1907 ;; Hide the trailer as well
1908 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1910 (gnus-article-hide-text-type
1911 (match-beginning 0) (match-end 0) 'pem)))))))
1913 (defun article-strip-banner ()
1914 "Strip the banner specified by the `banner' group parameter."
1918 (let ((inhibit-point-motion-hooks t)
1919 (banner (gnus-parameter-banner gnus-newsgroup-name))
1920 (gnus-signature-limit nil)
1921 buffer-read-only beg end)
1925 ((eq banner 'signature)
1926 (when (gnus-article-narrow-to-signature)
1929 (delete-region (point) (point-max))))
1931 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1932 (while (re-search-forward banner nil t)
1933 (delete-region (match-beginning 0) (match-end 0)))))
1935 (while (re-search-forward banner nil t)
1936 (delete-region (match-beginning 0) (match-end 0))))))))))
1938 (defun article-babel ()
1939 "Translate article using an online translation service."
1943 (set-buffer gnus-article-buffer)
1944 (when (article-goto-body)
1945 (let* ((buffer-read-only nil)
1948 (orig (buffer-substring start end))
1949 (trans (babel-as-string orig)))
1951 (narrow-to-region start end)
1952 (delete-region start end)
1955 (defun article-hide-signature (&optional arg)
1956 "Hide the signature in the current article.
1957 If given a negative prefix, always show; if given a positive prefix,
1959 (interactive (gnus-article-hidden-arg))
1960 (unless (gnus-article-check-hidden-text 'signature arg)
1963 (let ((buffer-read-only nil))
1964 (when (gnus-article-narrow-to-signature)
1965 (gnus-article-hide-text-type
1966 (point-min) (point-max) 'signature)))))))
1968 (defun article-strip-headers-in-body ()
1969 "Strip offensive headers from bodies."
1973 (let ((case-fold-search t))
1974 (when (looking-at "x-no-archive:")
1975 (gnus-delete-line)))))
1977 (defun article-strip-leading-blank-lines ()
1978 "Remove all blank lines from the beginning of the article."
1981 (let ((inhibit-point-motion-hooks t)
1983 (when (article-goto-body)
1984 (while (and (not (eobp))
1985 (looking-at "[ \t]*$"))
1986 (gnus-delete-line))))))
1988 (defun article-narrow-to-head ()
1989 "Narrow the buffer to the head of the message.
1990 Point is left at the beginning of the narrowed-to region."
1992 (goto-char (point-min))
1993 (if (search-forward "\n\n" nil 1)
1996 (goto-char (point-min)))
1998 (defun article-goto-body ()
1999 "Place point at the start of the body."
2000 (goto-char (point-min))
2002 ;; This variable is only bound when dealing with separate
2004 (article-goto-body-goes-to-point-min-p
2006 ((search-forward "\n\n" nil t)
2009 (goto-char (point-max))
2012 (defun article-strip-multiple-blank-lines ()
2013 "Replace consecutive blank lines with one empty line."
2016 (let ((inhibit-point-motion-hooks t)
2018 ;; First make all blank lines empty.
2020 (while (re-search-forward "^[ \t]+$" nil t)
2021 (unless (gnus-annotation-in-region-p
2022 (match-beginning 0) (match-end 0))
2023 (replace-match "" nil t)))
2024 ;; Then replace multiple empty lines with a single empty line.
2026 (while (re-search-forward "\n\n\n+" nil t)
2027 (unless (gnus-annotation-in-region-p
2028 (match-beginning 0) (match-end 0))
2029 (replace-match "\n\n" t t))))))
2031 (defun article-strip-leading-space ()
2032 "Remove all white space from the beginning of the lines in the article."
2035 (let ((inhibit-point-motion-hooks t)
2038 (while (re-search-forward "^[ \t]+" nil t)
2039 (replace-match "" t t)))))
2041 (defun article-strip-trailing-space ()
2042 "Remove all white space from the end of the lines in the article."
2045 (let ((inhibit-point-motion-hooks t)
2048 (while (re-search-forward "[ \t]+$" nil t)
2049 (replace-match "" t t)))))
2051 (defun article-strip-blank-lines ()
2052 "Strip leading, trailing and multiple blank lines."
2054 (article-strip-leading-blank-lines)
2055 (article-remove-trailing-blank-lines)
2056 (article-strip-multiple-blank-lines))
2058 (defun article-strip-all-blank-lines ()
2059 "Strip all blank lines."
2062 (let ((inhibit-point-motion-hooks t)
2065 (while (re-search-forward "^[ \t]*\n" nil t)
2066 (replace-match "" t t)))))
2068 (defun gnus-article-narrow-to-signature ()
2069 "Narrow to the signature; return t if a signature is found, else nil."
2070 (let ((inhibit-point-motion-hooks t))
2071 (when (gnus-article-search-signature)
2073 ;; Check whether we have some limits to what we consider
2074 ;; to be a signature.
2075 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2076 (list gnus-signature-limit)))
2078 (while (setq limit (pop limits))
2079 (if (or (and (integerp limit)
2080 (< (- (point-max) (point)) limit))
2082 (< (count-lines (point) (point-max)) limit))
2083 (and (gnus-functionp limit)
2085 (and (stringp limit)
2086 (not (re-search-forward limit nil t))))
2087 () ; This limit did not succeed.
2091 (narrow-to-region (point) (point-max))
2094 (defun gnus-article-search-signature ()
2095 "Search the current buffer for the signature separator.
2096 Put point at the beginning of the signature separator."
2097 (let ((cur (point)))
2098 (goto-char (point-max))
2099 (if (if (stringp gnus-signature-separator)
2100 (re-search-backward gnus-signature-separator nil t)
2101 (let ((seps gnus-signature-separator))
2103 (not (re-search-backward (car seps) nil t)))
2110 (defun gnus-article-hidden-arg ()
2111 "Return the current prefix arg as a number, or 0 if no prefix."
2112 (list (if current-prefix-arg
2113 (prefix-numeric-value current-prefix-arg)
2116 (defun gnus-article-check-hidden-text (type arg)
2117 "Return nil if hiding is necessary.
2118 Arg can be nil or a number. Nil and positive means hide, negative
2119 means show, 0 means toggle."
2122 (let ((hide (gnus-article-hidden-text-p type)))
2128 (gnus-article-show-hidden-text type)
2131 (if (eq hide 'hidden)
2133 (gnus-article-show-hidden-text type)
2137 (defun gnus-article-hidden-text-p (type)
2138 "Say whether the current buffer contains hidden text of type TYPE."
2139 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2141 (not (get-text-property pos 'invisible))
2142 (not (get-text-property pos 'dummy-invisible)))
2144 (text-property-any (1+ pos) (point-max) 'article-type type)))
2149 (defun gnus-article-show-hidden-text (type &optional dummy)
2150 "Show all hidden text of type TYPE.
2151 Originally it is hide instead of DUMMY."
2152 (let ((buffer-read-only nil)
2153 (inhibit-point-motion-hooks t))
2154 (gnus-remove-text-properties-when
2156 (point-min) (point-max)
2157 (cons 'article-type (cons type
2158 gnus-hidden-properties)))))
2160 (defconst article-time-units
2161 `((year . ,(* 365.25 24 60 60))
2162 (week . ,(* 7 24 60 60))
2163 (day . ,(* 24 60 60))
2167 "Mapping from time units to seconds.")
2169 (defun article-date-ut (&optional type highlight header)
2170 "Convert DATE date to universal time in the current article.
2171 If TYPE is `local', convert to local time; if it is `lapsed', output
2172 how much time has lapsed since DATE. For `lapsed', the value of
2173 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2174 should replace the \"Date:\" one, or should be added below it."
2175 (interactive (list 'ut t))
2176 (let* ((header (or header
2177 (message-fetch-field "date")
2179 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2182 ((not gnus-article-date-lapsed-new-header)
2188 (date (if (vectorp header) (mail-header-date header)
2190 (inhibit-point-motion-hooks t)
2195 (article-narrow-to-head)
2196 (when (re-search-forward tdate-regexp nil t)
2197 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2198 date (or (get-text-property (gnus-point-at-bol)
2201 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2203 (when (and date (not (string= date "")))
2204 (goto-char (point-min))
2205 (let ((buffer-read-only nil))
2206 ;; Delete any old Date headers.
2207 (while (re-search-forward date-regexp nil t)
2209 (delete-region (progn (beginning-of-line) (point))
2210 (progn (forward-line 1) (point)))
2211 (delete-region (progn (beginning-of-line) (point))
2212 (progn (end-of-line) (point)))
2213 (setq pos (point))))
2214 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2216 (if pos (goto-char pos))
2217 (insert (article-make-date-line date (or type 'ut)))
2223 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2224 (put-text-property (match-beginning 1) (1+ (match-end 1))
2225 'original-date date)
2226 (put-text-property (match-beginning 1) (1+ (match-end 1))
2228 (put-text-property (match-beginning 2) (match-end 2)
2231 (defun article-make-date-line (date type)
2232 "Return a DATE line of TYPE."
2233 (unless (memq type '(local ut original user iso8601 lapsed english))
2234 (error "Unknown conversion type: %s" type))
2236 (let ((time (date-to-time date)))
2238 ;; Convert to the local timezone.
2240 (let ((tz (car (current-time-zone time))))
2241 (format "Date: %s %s%02d%02d" (current-time-string time)
2242 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2243 (/ (% (abs tz) 3600) 60))))
2244 ;; Convert to Universal Time.
2247 (current-time-string
2248 (let* ((e (parse-time-string date))
2249 (tm (apply 'encode-time e))
2251 (ls (- (cadr tm) (car (current-time-zone time)))))
2252 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2253 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2256 ;; Get the original date from the article.
2257 ((eq type 'original)
2258 (concat "Date: " (if (string-match "\n+$" date)
2259 (substring date 0 (match-beginning 0))
2261 ;; Let the user define the format.
2263 (if (gnus-functionp gnus-article-time-format)
2264 (funcall gnus-article-time-format time)
2267 (format-time-string gnus-article-time-format time))))
2270 (let ((tz (car (current-time-zone time))))
2273 (format-time-string "%Y%m%dT%H%M%S" time)
2274 (format "%s%02d%02d"
2275 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2276 (/ (% (abs tz) 3600) 60)))))
2277 ;; Do an X-Sent lapsed format.
2279 ;; If the date is seriously mangled, the timezone functions are
2280 ;; liable to bug out, so we ignore all errors.
2281 (let* ((now (current-time))
2282 (real-time (subtract-time now time))
2283 (real-sec (and real-time
2284 (+ (* (float (car real-time)) 65536)
2286 (sec (and real-time (abs real-sec)))
2296 ;; This is a bit convoluted, but basically we go
2297 ;; through the time units for years, weeks, etc,
2298 ;; and divide things to see whether that results
2299 ;; in positive answers.
2302 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2303 ;; The (remaining) seconds are too few to
2304 ;; be divided into this time unit.
2306 ;; It's big enough, so we output it.
2307 (setq sec (- sec (* num (cdr unit))))
2309 (concat (if prev ", " "") (int-to-string
2311 " " (symbol-name (car unit))
2312 (if (> num 1) "s" ""))
2314 article-time-units "")
2315 ;; If dates are odd, then it might appear like the
2316 ;; article was sent in the future.
2319 " in the future"))))))
2320 ;; Display the date in proper English
2322 (let ((dtime (decode-time time)))
2325 (number-to-string (nth 3 dtime))
2326 (let ((digit (% (nth 3 dtime) 10)))
2328 ((memq (nth 3 dtime) '(11 12 13)) "th")
2334 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2336 (number-to-string (nth 5 dtime))
2338 (format "%02d" (nth 2 dtime))
2340 (format "%02d" (nth 1 dtime)))))))
2342 (format "Date: %s (from Oort)" date))))
2344 (defun article-date-local (&optional highlight)
2345 "Convert the current article date to the local timezone."
2346 (interactive (list t))
2347 (article-date-ut 'local highlight))
2349 (defun article-date-english (&optional highlight)
2350 "Convert the current article date to something that is proper English."
2351 (interactive (list t))
2352 (article-date-ut 'english highlight))
2354 (defun article-date-original (&optional highlight)
2355 "Convert the current article date to what it was originally.
2356 This is only useful if you have used some other date conversion
2357 function and want to see what the date was before converting."
2358 (interactive (list t))
2359 (article-date-ut 'original highlight))
2361 (defun article-date-lapsed (&optional highlight)
2362 "Convert the current article date to time lapsed since it was sent."
2363 (interactive (list t))
2364 (article-date-ut 'lapsed highlight))
2366 (defun article-update-date-lapsed ()
2367 "Function to be run from a timer to update the lapsed time line."
2368 (let (deactivate-mark)
2373 (set-buffer (window-buffer w))
2374 (when (eq major-mode 'gnus-article-mode)
2375 (goto-char (point-min))
2376 (when (re-search-forward "^X-Sent:" nil t)
2377 (article-date-lapsed t))))
2380 (defun gnus-start-date-timer (&optional n)
2381 "Start a timer to update the X-Sent header in the article buffers.
2382 The numerical prefix says how frequently (in seconds) the function
2387 (gnus-stop-date-timer)
2388 (setq article-lapsed-timer
2389 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2391 (defun gnus-stop-date-timer ()
2392 "Stop the X-Sent timer."
2394 (when article-lapsed-timer
2395 (nnheader-cancel-timer article-lapsed-timer)
2396 (setq article-lapsed-timer nil)))
2398 (defun article-date-user (&optional highlight)
2399 "Convert the current article date to the user-defined format.
2400 This format is defined by the `gnus-article-time-format' variable."
2401 (interactive (list t))
2402 (article-date-ut 'user highlight))
2404 (defun article-date-iso8601 (&optional highlight)
2405 "Convert the current article date to ISO8601."
2406 (interactive (list t))
2407 (article-date-ut 'iso8601 highlight))
2409 (defun article-show-all ()
2410 "Show all hidden text in the article buffer."
2413 (let ((buffer-read-only nil))
2414 (gnus-article-unhide-text (point-min) (point-max)))))
2416 (defun article-remove-leading-whitespace ()
2417 "Remove excessive whitespace from all headers."
2421 (let ((buffer-read-only nil))
2422 (article-narrow-to-head)
2423 (goto-char (point-min))
2424 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2425 (delete-region (match-beginning 1) (match-end 1)))))))
2427 (defun article-emphasize (&optional arg)
2428 "Emphasize text according to `gnus-emphasis-alist'."
2429 (interactive (gnus-article-hidden-arg))
2430 (unless (gnus-article-check-hidden-text 'emphasis arg)
2434 (with-current-buffer gnus-summary-buffer
2435 gnus-article-emphasis-alist)
2437 gnus-emphasis-alist))
2438 (buffer-read-only nil)
2439 (props (append '(article-type emphasis)
2440 gnus-hidden-properties))
2441 regexp elem beg invisible visible face)
2444 (while (setq elem (pop alist))
2446 (setq regexp (car elem)
2447 invisible (nth 1 elem)
2448 visible (nth 2 elem)
2450 (while (re-search-forward regexp nil t)
2451 (when (and (match-beginning visible) (match-beginning invisible))
2452 (push 'emphasis gnus-article-wash-types)
2453 (gnus-article-hide-text
2454 (match-beginning invisible) (match-end invisible) props)
2455 (gnus-article-unhide-text-type
2456 (match-beginning visible) (match-end visible) 'emphasis)
2457 (gnus-put-text-property-excluding-newlines
2458 (match-beginning visible) (match-end visible) 'face face)
2459 (goto-char (match-end invisible)))))))))
2461 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2462 "Setup newsgroup emphasis alist."
2463 (unless gnus-article-emphasis-alist
2464 (let ((name (and gnus-newsgroup-name
2465 (gnus-group-real-name gnus-newsgroup-name))))
2466 (make-local-variable 'gnus-article-emphasis-alist)
2467 (setq gnus-article-emphasis-alist
2469 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2470 (while (setq elem (pop alist))
2471 (when (and name (string-match (car elem) name))
2473 highlight (copy-sequence (cdr elem)))))
2475 (copy-sequence highlight-words)
2476 (if gnus-newsgroup-name
2477 (copy-sequence (gnus-group-find-parameter
2478 gnus-newsgroup-name 'highlight-words t)))
2479 gnus-emphasis-alist)))))
2482 (defvar gnus-summary-article-menu)
2483 (defvar gnus-summary-post-menu))
2485 ;;; Saving functions.
2487 (defun gnus-article-save (save-buffer file &optional num)
2488 "Save the currently selected article."
2489 (unless gnus-save-all-headers
2490 ;; Remove headers according to `gnus-saved-headers'.
2491 (let ((gnus-visible-headers
2492 (or gnus-saved-headers gnus-visible-headers))
2493 (gnus-article-buffer save-buffer))
2495 (set-buffer save-buffer)
2496 (article-hide-headers 1 t))))
2497 (save-window-excursion
2498 (if (not gnus-default-article-saver)
2499 (error "No default saver is defined")
2500 ;; !!! Magic! The saving functions all save
2501 ;; `gnus-save-article-buffer' (or so they think), but we
2502 ;; bind that variable to our save-buffer.
2503 (set-buffer gnus-article-buffer)
2504 (let* ((gnus-save-article-buffer save-buffer)
2507 ((not gnus-prompt-before-saving) 'default)
2508 ((eq gnus-prompt-before-saving 'always) nil)
2510 (gnus-number-of-articles-to-be-saved
2511 (when (eq gnus-prompt-before-saving t)
2513 (set-buffer gnus-article-current-summary)
2514 (funcall gnus-default-article-saver filename)))))
2516 (defun gnus-read-save-file-name (prompt &optional filename
2517 function group headers variable)
2519 (funcall function group headers (symbol-value variable)))
2524 ((eq filename 'default)
2530 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2533 (if (and gnus-number-of-articles-to-be-saved
2534 (> gnus-number-of-articles-to-be-saved 1))
2535 (format "these %d articles"
2536 gnus-number-of-articles-to-be-saved)
2539 ;; Let the split methods have their say.
2541 ;; No split name was found.
2544 (concat prompt " (default "
2545 (file-name-nondirectory default-name) ") ")
2546 (file-name-directory default-name)
2548 ;; A single group name is returned.
2549 ((stringp split-name)
2551 (funcall function split-name headers
2552 (symbol-value variable)))
2554 (concat prompt " (default "
2555 (file-name-nondirectory default-name) ") ")
2556 (file-name-directory default-name)
2558 ;; A single split name was found
2559 ((= 1 (length split-name))
2560 (let* ((name (expand-file-name
2562 gnus-article-save-directory))
2563 (dir (cond ((file-directory-p name)
2564 (file-name-as-directory name))
2565 ((file-exists-p name) name)
2566 (t gnus-article-save-directory))))
2568 (concat prompt " (default " name ") ")
2570 ;; A list of splits was found.
2572 (setq split-name (nreverse split-name))
2574 (let ((file-name-history
2575 (nconc split-name file-name-history)))
2579 (concat prompt " (`M-p' for defaults) ")
2580 gnus-article-save-directory
2582 gnus-article-save-directory)))
2583 (car (push result file-name-history)))))))
2584 ;; Create the directory.
2585 (gnus-make-directory (file-name-directory file))
2586 ;; If we have read a directory, we append the default file name.
2587 (when (file-directory-p file)
2588 (setq file (expand-file-name (file-name-nondirectory
2590 (file-name-as-directory file))))
2591 ;; Possibly translate some characters.
2592 (nnheader-translate-file-chars file))))))
2593 (gnus-make-directory (file-name-directory result))
2594 (set variable result)))
2596 (defun gnus-article-archive-name (group)
2597 "Return the first instance of an \"Archive-name\" in the current buffer."
2598 (let ((case-fold-search t))
2599 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2600 (nnheader-concat gnus-article-save-directory
2601 (match-string 1)))))
2603 (defun gnus-article-nndoc-name (group)
2604 "If GROUP is an nndoc group, return the name of the parent group."
2605 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2606 (gnus-group-get-parameter group 'save-article-group)))
2608 (defun gnus-summary-save-in-rmail (&optional filename)
2609 "Append this article to Rmail file.
2610 Optional argument FILENAME specifies file name.
2611 Directory to save to is default to `gnus-article-save-directory'."
2612 (setq filename (gnus-read-save-file-name
2613 "Save %s in rmail file:" filename
2614 gnus-rmail-save-name gnus-newsgroup-name
2615 gnus-current-headers 'gnus-newsgroup-last-rmail))
2616 (gnus-eval-in-buffer-window gnus-save-article-buffer
2620 (gnus-output-to-rmail filename))))
2623 (defun gnus-summary-save-in-mail (&optional filename)
2624 "Append this article to Unix mail file.
2625 Optional argument FILENAME specifies file name.
2626 Directory to save to is default to `gnus-article-save-directory'."
2627 (setq filename (gnus-read-save-file-name
2628 "Save %s in Unix mail file:" filename
2629 gnus-mail-save-name gnus-newsgroup-name
2630 gnus-current-headers 'gnus-newsgroup-last-mail))
2631 (gnus-eval-in-buffer-window gnus-save-article-buffer
2635 (if (and (file-readable-p filename)
2636 (mail-file-babyl-p filename))
2637 (rmail-output-to-rmail-file filename t)
2638 (gnus-output-to-mail filename)))))
2641 (defun gnus-summary-save-in-file (&optional filename overwrite)
2642 "Append this article to file.
2643 Optional argument FILENAME specifies file name.
2644 Directory to save to is default to `gnus-article-save-directory'."
2645 (setq filename (gnus-read-save-file-name
2646 "Save %s in file:" filename
2647 gnus-file-save-name gnus-newsgroup-name
2648 gnus-current-headers 'gnus-newsgroup-last-file))
2649 (gnus-eval-in-buffer-window gnus-save-article-buffer
2653 (when (and overwrite
2654 (file-exists-p filename))
2655 (delete-file filename))
2656 (gnus-output-to-file filename))))
2659 (defun gnus-summary-write-to-file (&optional filename)
2660 "Write this article to a file.
2661 Optional argument FILENAME specifies file name.
2662 The directory to save in defaults to `gnus-article-save-directory'."
2663 (gnus-summary-save-in-file nil t))
2665 (defun gnus-summary-save-body-in-file (&optional filename)
2666 "Append this article body to a file.
2667 Optional argument FILENAME specifies file name.
2668 The directory to save in defaults to `gnus-article-save-directory'."
2669 (setq filename (gnus-read-save-file-name
2670 "Save %s body in file:" filename
2671 gnus-file-save-name gnus-newsgroup-name
2672 gnus-current-headers 'gnus-newsgroup-last-file))
2673 (gnus-eval-in-buffer-window gnus-save-article-buffer
2677 (when (article-goto-body)
2678 (narrow-to-region (point) (point-max)))
2679 (gnus-output-to-file filename))))
2682 (defun gnus-summary-save-in-pipe (&optional command)
2683 "Pipe this article to subprocess."
2685 (cond ((and (eq command 'default)
2686 gnus-last-shell-command)
2687 gnus-last-shell-command)
2692 "Shell command on %s: "
2693 (if (and gnus-number-of-articles-to-be-saved
2694 (> gnus-number-of-articles-to-be-saved 1))
2695 (format "these %d articles"
2696 gnus-number-of-articles-to-be-saved)
2698 gnus-last-shell-command))))
2699 (when (string-equal command "")
2700 (if gnus-last-shell-command
2701 (setq command gnus-last-shell-command)
2702 (error "A command is required.")))
2703 (gnus-eval-in-buffer-window gnus-article-buffer
2706 (shell-command-on-region (point-min) (point-max) command nil)))
2707 (setq gnus-last-shell-command command))
2709 ;;; Article file names when saving.
2711 (defun gnus-capitalize-newsgroup (newsgroup)
2712 "Capitalize NEWSGROUP name."
2713 (when (not (zerop (length newsgroup)))
2714 (concat (char-to-string (upcase (aref newsgroup 0)))
2715 (substring newsgroup 1))))
2717 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2718 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2719 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2720 Otherwise, it is like ~/News/news/group/num."
2723 (concat (if (gnus-use-long-file-name 'not-save)
2724 (gnus-capitalize-newsgroup newsgroup)
2725 (gnus-newsgroup-directory-form newsgroup))
2726 "/" (int-to-string (mail-header-number headers)))
2727 gnus-article-save-directory)))
2729 (string-equal (file-name-directory default)
2730 (file-name-directory last-file))
2731 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2733 (or last-file default))))
2735 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2736 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2737 If variable `gnus-use-long-file-name' is non-nil, it is
2738 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2741 (concat (if (gnus-use-long-file-name 'not-save)
2743 (gnus-newsgroup-directory-form newsgroup))
2744 "/" (int-to-string (mail-header-number headers)))
2745 gnus-article-save-directory)))
2747 (string-equal (file-name-directory default)
2748 (file-name-directory last-file))
2749 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2751 (or last-file default))))
2753 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2754 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2755 If variable `gnus-use-long-file-name' is non-nil, it is
2756 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2759 (if (gnus-use-long-file-name 'not-save)
2761 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2762 gnus-article-save-directory)))
2764 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2765 "Generate file name from sender."
2766 (let ((from (mail-header-from headers)))
2768 (if (and from (string-match "\\([^ <]+\\)@" from))
2769 (match-string 1 from)
2771 gnus-article-save-directory)))
2773 (defun article-verify-x-pgp-sig ()
2776 (if (gnus-buffer-live-p gnus-original-article-buffer)
2777 (let ((sig (with-current-buffer gnus-original-article-buffer
2778 (gnus-fetch-field "X-PGP-Sig")))
2782 (mml2015-clear-verify-function))
2784 (insert-buffer gnus-original-article-buffer)
2785 (setq items (split-string sig))
2786 (message-narrow-to-head)
2787 (let ((inhibit-point-motion-hooks t)
2788 (case-fold-search t))
2789 ;; Don't verify multiple headers.
2790 (setq headers (mapconcat (lambda (header)
2792 (mail-fetch-field header) "\n"))
2793 (split-string (nth 1 items) ",") "")))
2794 (delete-region (point-min) (point-max))
2795 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2796 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2801 (if (looking-at "^-")
2804 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2805 (insert "Version: " (car items) "\n\n")
2806 (insert (mapconcat 'identity (cddr items) "\n"))
2807 (insert "\n-----END PGP SIGNATURE-----\n")
2808 (let ((mm-security-handle (list (format "multipart/signed"))))
2809 (mml2015-clean-buffer)
2810 (let ((coding-system-for-write (or gnus-newsgroup-charset
2812 (funcall (mml2015-clear-verify-function)))
2814 (or (mm-handle-multipart-ctl-parameter
2815 mm-security-handle 'gnus-details)
2816 (mm-handle-multipart-ctl-parameter
2817 mm-security-handle 'gnus-info)))))
2819 (let (buffer-read-only bface eface)
2821 (message-narrow-to-head)
2822 (goto-char (point-max))
2824 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2825 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2826 (message-remove-header "X-Gnus-PGP-Verify")
2827 (if (re-search-forward "^X-PGP-Sig:" nil t)
2829 (goto-char (point-max)))
2830 (narrow-to-region (point) (point))
2831 (insert "X-Gnus-PGP-Verify: " info "\n")
2832 (goto-char (point-min))
2835 (if (not (looking-at "^[ \t]"))
2839 (goto-char (point-min))
2840 (when (looking-at "\\([^:]+\\): *")
2841 (put-text-property (match-beginning 1) (1+ (match-end 1))
2843 (put-text-property (match-end 0) (point-max)
2844 'face eface)))))))))
2851 (setq afunc (car func)
2854 gfunc (intern (format "gnus-%s" func))))
2857 `(lambda (&optional interactive &rest args)
2858 ,(documentation afunc t)
2859 (interactive (list t))
2861 (set-buffer gnus-article-buffer)
2863 (call-interactively ',afunc)
2864 (apply ',afunc args))))))))
2865 '(article-hide-headers
2866 article-verify-x-pgp-sig
2867 article-hide-boring-headers
2868 article-treat-overstrike
2869 article-fill-long-lines
2870 article-capitalize-sentences
2872 article-remove-leading-whitespace
2873 article-display-x-face
2874 article-de-quoted-unreadable
2875 article-de-base64-unreadable
2878 article-hide-list-identifiers
2880 article-strip-banner
2883 article-hide-signature
2884 article-strip-headers-in-body
2885 article-remove-trailing-blank-lines
2886 article-strip-leading-blank-lines
2887 article-strip-multiple-blank-lines
2888 article-strip-leading-space
2889 article-strip-trailing-space
2890 article-strip-blank-lines
2891 article-strip-all-blank-lines
2893 article-date-english
2894 article-date-iso8601
2895 article-date-original
2897 article-decode-mime-words
2898 article-decode-charset
2899 article-decode-encoded-words
2903 article-treat-dumbquotes
2904 article-normalize-headers
2905 (article-show-all . gnus-article-show-all-headers))))
2908 ;;; Gnus article mode
2911 (put 'gnus-article-mode 'mode-class 'special)
2913 (set-keymap-parent gnus-article-mode-map widget-keymap)
2915 (gnus-define-keys gnus-article-mode-map
2916 " " gnus-article-goto-next-page
2917 "\177" gnus-article-goto-prev-page
2918 [delete] gnus-article-goto-prev-page
2919 [backspace] gnus-article-goto-prev-page
2920 "\C-c^" gnus-article-refer-article
2921 "h" gnus-article-show-summary
2922 "s" gnus-article-show-summary
2923 "\C-c\C-m" gnus-article-mail
2924 "?" gnus-article-describe-briefly
2925 "e" gnus-summary-edit-article
2926 "<" beginning-of-buffer
2928 "\C-c\C-i" gnus-info-find-node
2930 "\C-hk" gnus-article-describe-key
2931 "\C-hc" gnus-article-describe-key-briefly
2933 "\C-d" gnus-article-read-summary-keys
2934 "\M-*" gnus-article-read-summary-keys
2935 "\M-#" gnus-article-read-summary-keys
2936 "\M-^" gnus-article-read-summary-keys
2937 "\M-g" gnus-article-read-summary-keys)
2939 (substitute-key-definition
2940 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2942 (defun gnus-article-make-menu-bar ()
2943 (unless (boundp 'gnus-article-commands-menu)
2944 (gnus-summary-make-menu-bar))
2945 (gnus-turn-off-edit-menu 'article)
2946 (unless (boundp 'gnus-article-article-menu)
2948 gnus-article-article-menu gnus-article-mode-map ""
2950 ["Scroll forwards" gnus-article-goto-next-page t]
2951 ["Scroll backwards" gnus-article-goto-prev-page t]
2952 ["Show summary" gnus-article-show-summary t]
2953 ["Fetch Message-ID at point" gnus-article-refer-article t]
2954 ["Mail to address at point" gnus-article-mail t]
2955 ["Send a bug report" gnus-bug t]))
2958 gnus-article-treatment-menu gnus-article-mode-map ""
2959 ;; Fixme: this should use :active (and maybe :visible).
2961 ["Hide headers" gnus-article-hide-headers t]
2962 ["Hide signature" gnus-article-hide-signature t]
2963 ["Hide citation" gnus-article-hide-citation t]
2964 ["Treat overstrike" gnus-article-treat-overstrike t]
2965 ["Remove carriage return" gnus-article-remove-cr t]
2966 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
2967 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2968 ["Remove base64" gnus-article-de-base64-unreadable t]
2969 ["Treat html" gnus-article-wash-html t]
2970 ["Decode HZ" gnus-article-decode-HZ t]))
2972 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2974 ;; Note "Post" menu is defined in gnus-sum.el for consistency
2976 (gnus-run-hooks 'gnus-article-menu-hook)))
2978 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2981 (defun gnus-article-mode ()
2982 "Major mode for displaying an article.
2984 All normal editing commands are switched off.
2986 The following commands are available in addition to all summary mode
2988 \\<gnus-article-mode-map>
2989 \\[gnus-article-next-page]\t Scroll the article one page forwards
2990 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2991 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2992 \\[gnus-article-show-summary]\t Display the summary buffer
2993 \\[gnus-article-mail]\t Send a reply to the address near point
2994 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2995 \\[gnus-info-find-node]\t Go to the Gnus info node"
2997 (gnus-simplify-mode-line)
2998 (setq mode-name "Article")
2999 (setq major-mode 'gnus-article-mode)
3000 (make-local-variable 'minor-mode-alist)
3001 (use-local-map gnus-article-mode-map)
3002 (when (gnus-visual-p 'article-menu 'menu)
3003 (gnus-article-make-menu-bar))
3004 (gnus-update-format-specifications nil 'article-mode)
3005 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3006 (make-local-variable 'gnus-page-broken)
3007 (make-local-variable 'gnus-button-marker-list)
3008 (make-local-variable 'gnus-article-current-summary)
3009 (make-local-variable 'gnus-article-mime-handles)
3010 (make-local-variable 'gnus-article-decoded-p)
3011 (make-local-variable 'gnus-article-mime-handle-alist)
3012 (make-local-variable 'gnus-article-wash-types)
3013 (make-local-variable 'gnus-article-charset)
3014 (make-local-variable 'gnus-article-ignored-charsets)
3015 (gnus-set-default-directory)
3016 (buffer-disable-undo)
3017 (setq buffer-read-only t)
3018 (set-syntax-table gnus-article-mode-syntax-table)
3019 (mm-enable-multibyte)
3020 (gnus-run-hooks 'gnus-article-mode-hook))
3022 (defun gnus-article-setup-buffer ()
3023 "Initialize the article buffer."
3024 (let* ((name (if gnus-single-article-buffer "*Article*"
3025 (concat "*Article " gnus-newsgroup-name "*")))
3027 (progn (string-match "\\*Article" name)
3028 (concat " *Original Article"
3029 (substring name (match-end 0))))))
3030 (setq gnus-article-buffer name)
3031 (setq gnus-original-article-buffer original)
3032 (setq gnus-article-mime-handle-alist nil)
3033 ;; This might be a variable local to the summary buffer.
3034 (unless gnus-single-article-buffer
3036 (set-buffer gnus-summary-buffer)
3037 (setq gnus-article-buffer name)
3038 (setq gnus-original-article-buffer original)
3039 (gnus-set-global-variables)))
3040 (gnus-article-setup-highlight-words)
3041 ;; Init original article buffer.
3043 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3044 (mm-enable-multibyte)
3045 (setq major-mode 'gnus-original-article-mode)
3046 (make-local-variable 'gnus-original-article))
3047 (if (get-buffer name)
3050 (when gnus-article-mime-handles
3051 (mm-destroy-parts gnus-article-mime-handles)
3052 (setq gnus-article-mime-handles nil))
3053 ;; Set it to nil in article-buffer!
3054 (setq gnus-article-mime-handle-alist nil)
3055 (buffer-disable-undo)
3056 (setq buffer-read-only t)
3057 (unless (eq major-mode 'gnus-article-mode)
3058 (gnus-article-mode))
3061 (set-buffer (gnus-get-buffer-create name))
3063 (make-local-variable 'gnus-summary-buffer)
3064 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3065 (current-buffer)))))
3067 ;; Set article window start at LINE, where LINE is the number of lines
3068 ;; from the head of the article.
3069 (defun gnus-article-set-window-start (&optional line)
3071 (get-buffer-window gnus-article-buffer t)
3073 (set-buffer gnus-article-buffer)
3074 (goto-char (point-min))
3077 (gnus-message 6 "Moved to bookmark")
3078 (search-forward "\n\n" nil t)
3082 (defun gnus-article-prepare (article &optional all-headers header)
3083 "Prepare ARTICLE in article mode buffer.
3084 ARTICLE should either be an article number or a Message-ID.
3085 If ARTICLE is an id, HEADER should be the article headers.
3086 If ALL-HEADERS is non-nil, no headers are hidden."
3088 ;; Make sure we start in a summary buffer.
3089 (unless (eq major-mode 'gnus-summary-mode)
3090 (set-buffer gnus-summary-buffer))
3091 (setq gnus-summary-buffer (current-buffer))
3092 (let* ((gnus-article (if header (mail-header-number header) article))
3093 (summary-buffer (current-buffer))
3094 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3095 (group gnus-newsgroup-name)
3098 (gnus-article-setup-buffer)
3099 (set-buffer gnus-article-buffer)
3100 ;; Deactivate active regions.
3101 (when (and (boundp 'transient-mark-mode)
3102 transient-mark-mode)
3103 (setq mark-active nil))
3104 (if (not (setq result (let ((buffer-read-only nil))
3105 (gnus-request-article-this-buffer
3107 ;; There is no such article.
3109 (when (and (numberp article)
3110 (not (memq article gnus-newsgroup-sparse)))
3111 (setq gnus-article-current
3112 (cons gnus-newsgroup-name article))
3113 (set-buffer gnus-summary-buffer)
3114 (setq gnus-current-article article)
3115 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3117 (gnus-summary-set-agent-mark article)
3118 (message "Message marked for downloading"))
3119 (gnus-summary-mark-article article gnus-canceled-mark)
3120 (unless (memq article gnus-newsgroup-sparse)
3121 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3122 (if (or (eq result 'pseudo)
3123 (eq result 'nneething))
3126 (set-buffer summary-buffer)
3127 (push article gnus-newsgroup-history)
3128 (setq gnus-last-article gnus-current-article
3129 gnus-current-article 0
3130 gnus-current-headers nil
3131 gnus-article-current nil)
3132 (if (eq result 'nneething)
3133 (gnus-configure-windows 'summary)
3134 (gnus-configure-windows 'article))
3135 (gnus-set-global-variables))
3136 (let ((gnus-article-mime-handle-alist-1
3137 gnus-article-mime-handle-alist))
3138 (gnus-set-mode-line 'article)))
3139 ;; The result from the `request' was an actual article -
3140 ;; or at least some text that is now displayed in the
3142 (when (and (numberp article)
3143 (not (eq article gnus-current-article)))
3144 ;; Seems like a new article has been selected.
3145 ;; `gnus-current-article' must be an article number.
3147 (set-buffer summary-buffer)
3148 (push article gnus-newsgroup-history)
3149 (setq gnus-last-article gnus-current-article
3150 gnus-current-article article
3151 gnus-current-headers
3152 (gnus-summary-article-header gnus-current-article)
3153 gnus-article-current
3154 (cons gnus-newsgroup-name gnus-current-article))
3155 (unless (vectorp gnus-current-headers)
3156 (setq gnus-current-headers nil))
3157 (gnus-summary-goto-subject gnus-current-article)
3158 (when (gnus-summary-show-thread)
3159 ;; If the summary buffer really was folded, the
3160 ;; previous goto may not actually have gone to
3161 ;; the right article, but the thread root instead.
3163 (gnus-summary-goto-subject gnus-current-article))
3164 (gnus-run-hooks 'gnus-mark-article-hook)
3165 (gnus-set-mode-line 'summary)
3166 (when (gnus-visual-p 'article-highlight 'highlight)
3167 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3168 ;; Set the global newsgroup variables here.
3169 (gnus-set-global-variables)
3170 (setq gnus-have-all-headers
3171 (or all-headers gnus-show-all-headers))))
3173 (gnus-configure-windows 'article))
3174 (when (or (numberp article)
3176 (gnus-article-prepare-display)
3178 (goto-char (point-min))
3179 (setq gnus-page-broken
3180 (when gnus-break-pages
3181 (gnus-narrow-to-page)
3183 (let ((gnus-article-mime-handle-alist-1
3184 gnus-article-mime-handle-alist))
3185 (gnus-set-mode-line 'article))
3187 (set-window-point (get-buffer-window (current-buffer)) (point))
3188 (gnus-configure-windows 'article)
3192 (defun gnus-article-prepare-display ()
3193 "Make the current buffer look like a nice article."
3194 ;; Hooks for getting information from the article.
3195 ;; This hook must be called before being narrowed.
3196 (let ((gnus-article-buffer (current-buffer))
3198 (unless (eq major-mode 'gnus-article-mode)
3199 (gnus-article-mode))
3200 (setq buffer-read-only nil
3201 gnus-article-wash-types nil)
3202 (gnus-run-hooks 'gnus-tmp-internal-hook)
3203 (when gnus-display-mime-function
3204 (funcall gnus-display-mime-function))
3205 (gnus-run-hooks 'gnus-article-prepare-hook)))
3208 ;;; Gnus MIME viewing functions
3211 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3212 "The following specs can be used:
3214 %T MIME type, along with additional info
3215 %n The `name' parameter
3216 %d The description, if any
3217 %l The length of the encoded part
3218 %p The part identifier number
3219 %e Dots if the part isn't displayed")
3221 (defvar gnus-mime-button-line-format-alist
3222 '((?t gnus-tmp-type ?s)
3223 (?T gnus-tmp-type-long ?s)
3224 (?n gnus-tmp-name ?s)
3225 (?d gnus-tmp-description ?s)
3227 (?l gnus-tmp-length ?d)
3228 (?e gnus-tmp-dots ?s)))
3230 (defvar gnus-mime-button-commands
3231 '((gnus-article-press-button "\r" "Toggle Display")
3232 (gnus-mime-view-part "v" "View Interactively...")
3233 (gnus-mime-view-part-as-type "t" "View As Type...")
3234 (gnus-mime-view-part-as-charset "C" "View As charset...")
3235 (gnus-mime-save-part "o" "Save...")
3236 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3237 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3238 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3239 (gnus-mime-internalize-part "E" "View Internally")
3240 (gnus-mime-externalize-part "e" "View Externally")
3241 (gnus-mime-pipe-part "|" "Pipe To Command...")
3242 (gnus-mime-action-on-part "." "Take action on the part")))
3244 (defun gnus-article-mime-part-status ()
3245 (if gnus-article-mime-handle-alist-1
3246 (if (eq 1 (length gnus-article-mime-handle-alist-1))
3248 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3251 (defvar gnus-mime-button-map
3252 (let ((map (make-sparse-keymap)))
3253 (unless (>= (string-to-number emacs-version) 21)
3254 ;; XEmacs doesn't care.
3255 (set-keymap-parent map gnus-article-mode-map))
3256 (define-key map gnus-mouse-2 'gnus-article-push-button)
3257 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3258 (dolist (c gnus-mime-button-commands)
3259 (define-key map (cadr c) (car c)))
3262 (defun gnus-mime-button-menu (event)
3263 "Construct a context-sensitive menu of MIME commands."
3265 (save-window-excursion
3266 (let ((pos (event-start event)))
3267 (select-window (posn-window pos))
3268 (goto-char (posn-point pos))
3269 (gnus-article-check-buffer)
3270 (let ((response (x-popup-menu
3272 ("" ,@(mapcar (lambda (c)
3273 (cons (caddr c) (car c)))
3274 gnus-mime-button-commands))))))
3276 (call-interactively response))))))
3278 (defun gnus-mime-view-all-parts (&optional handles)
3279 "View all the MIME parts."
3281 (save-current-buffer
3282 (set-buffer gnus-article-buffer)
3283 (let ((handles (or handles gnus-article-mime-handles))
3284 (mail-parse-charset gnus-newsgroup-charset)
3285 (mail-parse-ignored-charsets
3286 (with-current-buffer gnus-summary-buffer
3287 gnus-newsgroup-ignored-charsets)))
3289 (mm-remove-parts handles)
3290 (goto-char (point-min))
3291 (or (search-forward "\n\n") (goto-char (point-max)))
3292 (let (buffer-read-only)
3293 (delete-region (point) (point-max)))
3294 (mm-display-parts handles)))))
3296 (defun gnus-mime-save-part-and-strip ()
3297 "Save the MIME part under point then replace it with an external body."
3299 (gnus-article-check-buffer)
3300 (let* ((data (get-text-property (point) 'gnus-data))
3302 (if (mm-multiple-handles gnus-article-mime-handles)
3303 (error "This function is not implemented."))
3304 (setq file (and data (mm-save-part data)))
3306 (with-current-buffer (mm-handle-buffer data)
3308 (insert "Content-Type: " (mm-handle-media-type data))
3309 (mml-insert-parameter-string (cdr (mm-handle-type data))
3312 (insert "Content-ID: " (message-make-message-id) "\n")
3313 (insert "Content-Transfer-Encoding: binary\n")
3316 (cdr (mm-make-handle nil
3317 `("message/external-body"
3318 (access-type . "LOCAL-FILE")
3320 (set-buffer gnus-summary-buffer)
3321 (gnus-article-edit-article
3324 (let ((mail-parse-charset (or gnus-article-charset
3325 ',gnus-newsgroup-charset))
3326 (mail-parse-ignored-charsets
3327 (or gnus-article-ignored-charsets
3328 ',gnus-newsgroup-ignored-charsets))
3329 (mbl mml-buffer-list))
3330 (setq mml-buffer-list nil)
3331 (insert-buffer gnus-original-article-buffer)
3332 (mime-to-mml gnus-article-mime-handles)
3333 (setq gnus-article-mime-handles nil)
3334 (make-local-hook 'kill-buffer-hook)
3335 (let ((mbl1 mml-buffer-list))
3336 (setq mml-buffer-list mbl)
3337 (set (make-local-variable 'mml-buffer-list) mbl1))
3338 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3339 `(lambda (no-highlight)
3340 (let ((mail-parse-charset (or gnus-article-charset
3341 ',gnus-newsgroup-charset))
3342 (message-options message-options)
3343 (message-options-set-recipient)
3344 (mail-parse-ignored-charsets
3345 (or gnus-article-ignored-charsets
3346 ',gnus-newsgroup-ignored-charsets)))
3348 (mml-destroy-buffers)
3349 (remove-hook 'kill-buffer-hook
3350 'mml-destroy-buffers t)
3351 (kill-local-variable 'mml-buffer-list))
3352 (gnus-summary-edit-article-done
3353 ,(or (mail-header-references gnus-current-headers) "")
3354 ,(gnus-group-read-only-p)
3355 ,gnus-summary-buffer no-highlight))))))
3357 (defun gnus-mime-save-part ()
3358 "Save the MIME part under point."
3360 (gnus-article-check-buffer)
3361 (let ((data (get-text-property (point) 'gnus-data)))
3363 (mm-save-part data))))
3365 (defun gnus-mime-pipe-part ()
3366 "Pipe the MIME part under point to a process."
3368 (gnus-article-check-buffer)
3369 (let ((data (get-text-property (point) 'gnus-data)))
3371 (mm-pipe-part data))))
3373 (defun gnus-mime-view-part ()
3374 "Interactively choose a viewing method for the MIME part under point."
3376 (gnus-article-check-buffer)
3377 (let ((data (get-text-property (point) 'gnus-data)))
3379 (setq gnus-article-mime-handles
3381 gnus-article-mime-handles (setq data (copy-sequence data))))
3382 (mm-interactively-view-part data))))
3384 (defun gnus-mime-view-part-as-type-internal ()
3385 (gnus-article-check-buffer)
3386 (let* ((name (mail-content-type-get
3387 (mm-handle-type (get-text-property (point) 'gnus-data))
3389 (def-type (and name (mm-default-file-encoding name))))
3390 (and def-type (cons def-type 0))))
3392 (defun gnus-mime-view-part-as-type (&optional mime-type)
3393 "Choose a MIME media type, and view the part as such."
3396 (setq mime-type (completing-read
3397 "View as MIME type: "
3398 (mapcar #'list (mailcap-mime-types))
3400 (gnus-mime-view-part-as-type-internal))))
3401 (gnus-article-check-buffer)
3402 (let ((handle (get-text-property (point) 'gnus-data)))
3405 (mm-make-handle (mm-handle-buffer handle)
3406 (cons mime-type (cdr (mm-handle-type handle)))
3407 (mm-handle-encoding handle)
3408 (mm-handle-undisplayer handle)
3409 (mm-handle-disposition handle)
3410 (mm-handle-description handle)
3411 (mm-handle-cache handle)
3412 (mm-handle-id handle)))
3413 (setq gnus-article-mime-handles
3414 (mm-merge-handles gnus-article-mime-handles handle))
3415 (gnus-mm-display-part handle))))
3417 (defun gnus-mime-copy-part (&optional handle)
3418 "Put the the MIME part under point into a new buffer."
3420 (gnus-article-check-buffer)
3421 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3422 (contents (and handle (mm-get-part handle)))
3424 (file-name-nondirectory
3426 (mail-content-type-get (mm-handle-type handle) 'name)
3427 (mail-content-type-get (mm-handle-type handle)
3430 (buffer (and base (generate-new-buffer base))))
3432 (switch-to-buffer buffer)
3434 ;; We do it this way to make `normal-mode' set the appropriate mode.
3437 (setq buffer-file-name (expand-file-name base))
3439 (setq buffer-file-name nil))
3440 (goto-char (point-min)))))
3442 (defun gnus-mime-inline-part (&optional handle arg)
3443 "Insert the MIME part under point into the current buffer."
3444 (interactive (list nil current-prefix-arg))
3445 (gnus-article-check-buffer)
3446 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3451 (if (and (not arg) (mm-handle-undisplayer handle))
3452 (mm-remove-part handle)
3453 (setq contents (mm-get-part handle))
3456 (setq charset (or (mail-content-type-get
3457 (mm-handle-type handle) 'charset)
3458 gnus-newsgroup-charset)))
3460 (if (mm-handle-undisplayer handle)
3461 (mm-remove-part handle))
3464 gnus-summary-show-article-charset-alist))
3465 (read-coding-system "Charset: ")))))
3467 (mm-insert-inline handle
3469 (setq charset (mm-charset-to-coding-system
3471 (not (eq charset 'ascii)))
3472 (mm-decode-coding-string contents charset)
3476 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3477 "Insert the MIME part under point into the current buffer."
3478 (interactive (list nil current-prefix-arg))
3479 (gnus-article-check-buffer)
3480 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3485 (if (mm-handle-undisplayer handle)
3486 (mm-remove-part handle))
3487 (let ((gnus-newsgroup-charset
3489 gnus-summary-show-article-charset-alist))
3490 (read-coding-system "Charset: ")))
3491 (gnus-newsgroup-ignored-charsets 'gnus-all))
3492 (gnus-article-press-button)))))
3494 (defun gnus-mime-externalize-part (&optional handle)
3495 "View the MIME part under point with an external viewer."
3497 (gnus-article-check-buffer)
3498 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3499 (mm-user-display-methods nil)
3500 (mm-inlined-types nil)
3501 (mail-parse-charset gnus-newsgroup-charset)
3502 (mail-parse-ignored-charsets
3503 (save-excursion (set-buffer gnus-summary-buffer)
3504 gnus-newsgroup-ignored-charsets)))
3506 (if (mm-handle-undisplayer handle)
3507 (mm-remove-part handle)
3508 (mm-display-part handle)))))
3510 (defun gnus-mime-internalize-part (&optional handle)
3511 "View the MIME part under point with an internal viewer.
3512 In no internal viewer is available, use an external viewer."
3514 (gnus-article-check-buffer)
3515 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3516 (mm-inlined-types '(".*"))
3517 (mm-inline-large-images t)
3518 (mail-parse-charset gnus-newsgroup-charset)
3519 (mail-parse-ignored-charsets
3520 (save-excursion (set-buffer gnus-summary-buffer)
3521 gnus-newsgroup-ignored-charsets)))
3523 (if (mm-handle-undisplayer handle)
3524 (mm-remove-part handle)
3525 (mm-display-part handle)))))
3527 (defun gnus-mime-action-on-part (&optional action)
3528 "Do something with the MIME attachment at \(point\)."
3530 (list (completing-read "Action: " gnus-mime-action-alist)))
3531 (gnus-article-check-buffer)
3532 (let ((action-pair (assoc action gnus-mime-action-alist)))
3534 (funcall (cdr action-pair)))))
3536 (defun gnus-article-part-wrapper (n function)
3537 (save-current-buffer
3538 (set-buffer gnus-article-buffer)
3539 (when (> n (length gnus-article-mime-handle-alist))
3540 (error "No such part"))
3541 (gnus-article-goto-part n)
3542 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3543 (funcall function handle))))
3545 (defun gnus-article-pipe-part (n)
3546 "Pipe MIME part N, which is the numerical prefix."
3548 (gnus-article-part-wrapper n 'mm-pipe-part))
3550 (defun gnus-article-save-part (n)
3551 "Save MIME part N, which is the numerical prefix."
3553 (gnus-article-part-wrapper n 'mm-save-part))
3555 (defun gnus-article-interactively-view-part (n)
3556 "View MIME part N interactively, which is the numerical prefix."
3558 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3560 (defun gnus-article-copy-part (n)
3561 "Copy MIME part N, which is the numerical prefix."
3563 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3565 (defun gnus-article-view-part-as-charset (n)
3566 "Copy MIME part N, which is the numerical prefix."
3568 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3570 (defun gnus-article-externalize-part (n)
3571 "View MIME part N externally, which is the numerical prefix."
3573 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3575 (defun gnus-article-inline-part (n)
3576 "Inline MIME part N, which is the numerical prefix."
3578 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3580 (defun gnus-article-mime-match-handle-first (condition)
3582 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3583 (while (setq ihandle (pop alist))
3585 ((functionp condition)
3586 (funcall condition (cdr ihandle)))
3587 ((eq condition 'undisplayed)
3588 (not (or (mm-handle-undisplayer (cdr ihandle))
3589 (equal (mm-handle-media-type (cdr ihandle))
3590 "multipart/alternative"))))
3591 ((eq condition 'undisplayed-alternative)
3592 (not (mm-handle-undisplayer (cdr ihandle))))
3594 (gnus-article-goto-part (car ihandle))
3595 (or (not n) (< (car ihandle) n)))
3596 (setq n (car ihandle))))
3600 (defun gnus-article-view-part (&optional n)
3601 "View MIME part N, which is the numerical prefix."
3603 (save-current-buffer
3604 (set-buffer gnus-article-buffer)
3605 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3606 gnus-article-mime-match-handle-function)))
3607 (when (> n (length gnus-article-mime-handle-alist))
3608 (error "No such part"))
3609 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3610 (when (gnus-article-goto-part n)
3611 (if (equal (car handle) "multipart/alternative")
3612 (gnus-article-press-button)
3613 (when (eq (gnus-mm-display-part handle) 'internal)
3614 (gnus-set-window-start)))))))
3616 (defsubst gnus-article-mime-total-parts ()
3617 (if (bufferp (car gnus-article-mime-handles))
3619 (1- (length gnus-article-mime-handles))))
3621 (defun gnus-mm-display-part (handle)
3622 "Display HANDLE and fix MIME button."
3623 (let ((id (get-text-property (point) 'gnus-part))
3628 (let ((window (selected-window))
3629 (mail-parse-charset gnus-newsgroup-charset)
3630 (mail-parse-ignored-charsets
3631 (save-excursion (set-buffer gnus-summary-buffer)
3632 gnus-newsgroup-ignored-charsets)))
3635 (let ((win (get-buffer-window (current-buffer) t))
3638 (select-window win))
3641 (if (mm-handle-displayed-p handle)
3642 ;; This will remove the part.
3643 (mm-display-part handle)
3645 (narrow-to-region (point) (1+ (point)))
3646 (mm-display-part handle)
3647 ;; We narrow to the part itself and
3648 ;; then call the treatment functions.
3649 (goto-char (point-min))
3651 (narrow-to-region (point) (point-max))
3654 (gnus-article-mime-total-parts)
3655 (mm-handle-media-type handle)))))
3656 (select-window window))))
3658 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3659 (gnus-insert-mime-button
3660 handle id (list (mm-handle-displayed-p handle)))
3661 (goto-char point))))
3663 (defun gnus-article-goto-part (n)
3664 "Go to MIME part N."
3665 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3667 (goto-char point))))
3669 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3670 (let ((gnus-tmp-name
3671 (or (mail-content-type-get (mm-handle-type handle)
3673 (mail-content-type-get (mm-handle-disposition handle)
3675 (mail-content-type-get (mm-handle-type handle)
3678 (gnus-tmp-type (mm-handle-media-type handle))
3679 (gnus-tmp-description
3680 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3683 (if (if displayed (car displayed)
3684 (mm-handle-displayed-p handle))
3686 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3688 gnus-tmp-type-long b e)
3689 (when (string-match ".*/" gnus-tmp-name)
3690 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3691 (setq gnus-tmp-type-long (concat gnus-tmp-type
3692 (and (not (equal gnus-tmp-name ""))
3693 (concat "; " gnus-tmp-name))))
3694 (or (equal gnus-tmp-description "")
3695 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3700 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3701 `(keymap ,gnus-mime-button-map
3702 ,@(if (>= (string-to-number emacs-version) 21)
3704 (list 'local-map gnus-mime-button-map))
3705 gnus-callback gnus-mm-display-part
3706 gnus-part ,gnus-tmp-id
3707 article-type annotation
3710 (widget-convert-button
3713 :action 'gnus-widget-press-button
3714 :button-keymap gnus-mime-button-map
3716 (lambda (widget/window &optional overlay pos)
3717 ;; Needed to properly clear the message due to a bug in
3718 ;; wid-edit (XEmacs only).
3719 (if (boundp 'help-echo-owns-message)
3720 (setq help-echo-owns-message t))
3722 "%S: %s the MIME part; %S: more options"
3723 (aref gnus-mouse-2 0)
3724 ;; XEmacs will get a single widget arg; Emacs 21 will get
3725 ;; window, overlay, position.
3726 (if (mm-handle-displayed-p
3728 (with-current-buffer (gnus-overlay-buffer overlay)
3729 (widget-get (widget-at (gnus-overlay-start overlay))
3731 (widget-get widget/window :mime-handle)))
3733 (aref gnus-down-mouse-3 0))))))
3735 (defun gnus-widget-press-button (elems el)
3736 (goto-char (widget-get elems :from))
3737 (gnus-article-press-button))
3739 (defvar gnus-displaying-mime nil)
3741 (defun gnus-display-mime (&optional ihandles)
3742 "Display the MIME parts."
3744 (save-selected-window
3745 (let ((window (get-buffer-window gnus-article-buffer))
3748 (select-window window)
3749 ;; We have to do this since selecting the window
3750 ;; may change the point. So we set the window point.
3751 (set-window-point window point)))
3752 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3753 buffer-read-only handle name type b e display)
3754 (when (and (not ihandles)
3755 (not gnus-displaying-mime))
3756 ;; Top-level call; we clean up.
3757 (when gnus-article-mime-handles
3758 (mm-destroy-parts gnus-article-mime-handles)
3759 (setq gnus-article-mime-handle-alist nil));; A trick.
3760 (setq gnus-article-mime-handles handles)
3761 ;; We allow users to glean info from the handles.
3762 (when gnus-article-mime-part-function
3763 (gnus-mime-part-function handles)))
3765 (or (not (stringp (car handles)))
3768 (when (and (not ihandles)
3769 (not gnus-displaying-mime))
3770 ;; Clean up for mime parts.
3772 (delete-region (point) (point-max)))
3773 (let ((gnus-displaying-mime t))
3774 (gnus-mime-display-part handles)))
3777 (narrow-to-region (point) (point-max))
3778 (gnus-treat-article nil 1 1)
3781 ;; Highlight the headers.
3785 (narrow-to-region (point-min) (point))
3786 (gnus-treat-article 'head))))))))
3788 (defvar gnus-mime-display-multipart-as-mixed nil)
3789 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
3790 (defvar gnus-mime-display-multipart-related-as-mixed nil)
3792 (defun gnus-mime-display-part (handle)
3795 ((not (stringp (car handle)))
3796 (gnus-mime-display-single handle))
3797 ;; User-defined multipart
3798 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3799 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3801 ;; multipart/alternative
3802 ((and (equal (car handle) "multipart/alternative")
3803 (not (or gnus-mime-display-multipart-as-mixed
3804 gnus-mime-display-multipart-alternative-as-mixed)))
3805 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3806 (push (cons id handle) gnus-article-mime-handle-alist)
3807 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3808 ;; multipart/related
3809 ((and (equal (car handle) "multipart/related")
3810 (not (or gnus-mime-display-multipart-as-mixed
3811 gnus-mime-display-multipart-related-as-mixed)))
3812 ;;;!!!We should find the start part, but we just default
3813 ;;;!!!to the first part.
3814 ;;(gnus-mime-display-part (cadr handle))
3815 ;;;!!! Most multipart/related is an HTML message plus images.
3816 ;;;!!! Unfortunately we are unable to let W3 display those
3817 ;;;!!! included images, so we just display it as a mixed multipart.
3818 ;;(gnus-mime-display-mixed (cdr handle))
3819 ;;;!!! No, w3 can display everything just fine.
3820 (gnus-mime-display-part (cadr handle)))
3821 ((equal (car handle) "multipart/signed")
3822 (or (memq 'signed gnus-article-wash-types)
3823 (push 'signed gnus-article-wash-types))
3824 (gnus-mime-display-security handle))
3825 ((equal (car handle) "multipart/encrypted")
3826 (or (memq 'encrypted gnus-article-wash-types)
3827 (push 'encrypted gnus-article-wash-types))
3828 (gnus-mime-display-security handle))
3829 ;; Other multiparts are handled like multipart/mixed.
3831 (gnus-mime-display-mixed (cdr handle)))))
3833 (defun gnus-mime-part-function (handles)
3834 (if (stringp (car handles))
3835 (mapcar 'gnus-mime-part-function (cdr handles))
3836 (funcall gnus-article-mime-part-function handles)))
3838 (defun gnus-mime-display-mixed (handles)
3839 (mapcar 'gnus-mime-display-part handles))
3841 (defun gnus-mime-display-single (handle)
3842 (let ((type (mm-handle-media-type handle))
3843 (ignored gnus-ignored-mime-types)
3850 (when (string-match (pop ignored) type)
3851 (throw 'ignored nil)))
3852 (if (and (setq not-attachment
3853 (and (not (mm-inline-override-p handle))
3854 (or (not (mm-handle-disposition handle))
3855 (equal (car (mm-handle-disposition handle))
3857 (mm-attachment-override-p handle))))
3858 (mm-automatic-display-p handle)
3859 (or (mm-inlined-p handle)
3860 (mm-automatic-external-display-p type)))
3862 (when (equal (mm-handle-media-supertype handle) "text")
3864 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3866 (push (cons id handle) gnus-article-mime-handle-alist)
3867 (when (or (not display)
3868 (not (gnus-unbuttonized-mime-type-p type)))
3869 ;(gnus-article-insert-newline)
3870 (gnus-insert-mime-button
3871 handle id (list (or display (and not-attachment text))))
3872 (gnus-article-insert-newline)
3873 ;(gnus-article-insert-newline)
3874 ;; Remember modify the number of forward lines.
3882 (let ((mail-parse-charset gnus-newsgroup-charset)
3883 (mail-parse-ignored-charsets
3884 (save-excursion (condition-case ()
3885 (set-buffer gnus-summary-buffer)
3887 gnus-newsgroup-ignored-charsets)))
3888 (mm-display-part handle t))
3889 (goto-char (point-max)))
3890 ((and text not-attachment)
3894 (gnus-article-insert-newline)
3895 (mm-insert-inline handle (mm-get-part handle))
3896 (goto-char (point-max))))
3900 (narrow-to-region beg (point))
3903 (gnus-article-mime-total-parts)
3904 (mm-handle-media-type handle)))))))))
3906 (defun gnus-unbuttonized-mime-type-p (type)
3907 "Say whether TYPE is to be unbuttonized."
3908 (unless gnus-inhibit-mime-unbuttonizing
3910 (let ((types gnus-unbuttonized-mime-types))
3912 (when (string-match (pop types) type)
3913 (throw 'found t)))))))
3915 (defun gnus-article-insert-newline ()
3916 "Insert a newline, but mark it as undeletable."
3917 (gnus-put-text-property
3918 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3920 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3921 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3924 handle buffer-read-only from props begend not-pref)
3925 (save-window-excursion
3928 (narrow-to-region (car ibegend)
3931 (goto-char (car ibegend))
3934 (delete-region (point-min) (point-max))
3935 (mm-remove-parts handles))
3936 (setq begend (list (point-marker)))
3938 (unless (setq not-pref (cadr (member preferred ihandles)))
3939 (setq not-pref (car ihandles)))
3942 (not (gnus-unbuttonized-mime-type-p
3943 "multipart/alternative")))
3944 (gnus-add-text-properties
3947 (insert (format "%d. " id))
3951 (unless ,(not ibegend)
3952 (setq gnus-article-mime-handle-alist
3953 ',gnus-article-mime-handle-alist))
3954 (gnus-mime-display-alternative
3955 ',ihandles ',not-pref ',begend ,id))
3956 ,@(if (>= (string-to-number emacs-version) 21)
3957 nil ;; XEmacs doesn't care
3958 (list 'local-map gnus-mime-button-map))
3959 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3960 face ,gnus-article-button-face
3961 keymap ,gnus-mime-button-map
3964 (widget-convert-button 'link from (point)
3965 :action 'gnus-widget-press-button
3966 :button-keymap gnus-widget-button-keymap)
3968 (while (setq handle (pop handles))
3969 (gnus-add-text-properties
3972 (insert (format "(%c) %-18s"
3973 (if (equal handle preferred) ?* ? )
3974 (mm-handle-media-type handle)))
3978 (unless ,(not ibegend)
3979 (setq gnus-article-mime-handle-alist
3980 ',gnus-article-mime-handle-alist))
3981 (gnus-mime-display-alternative
3982 ',ihandles ',handle ',begend ,id))
3983 ,@(if (>= (string-to-number emacs-version) 21)
3984 nil ;; XEmacs doesn't care
3985 (list 'local-map gnus-mime-button-map))
3986 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3987 face ,gnus-article-button-face
3988 keymap ,gnus-mime-button-map
3991 (widget-convert-button 'link from (point)
3992 :action 'gnus-widget-press-button
3993 :button-keymap gnus-widget-button-keymap)
3997 (if (stringp (car preferred))
3998 (gnus-display-mime preferred)
3999 (let ((mail-parse-charset gnus-newsgroup-charset)
4000 (mail-parse-ignored-charsets
4001 (save-excursion (set-buffer gnus-summary-buffer)
4002 gnus-newsgroup-ignored-charsets)))
4003 (mm-display-part preferred)
4007 (narrow-to-region (car begend) (point-max))
4009 nil (length gnus-article-mime-handle-alist)
4010 (gnus-article-mime-total-parts)
4011 (mm-handle-media-type handle))))))
4012 (goto-char (point-max))
4013 (setcdr begend (point-marker)))))
4015 (goto-char point))))
4017 (defun gnus-article-wash-status ()
4018 "Return a string which display status of article washing."
4020 (set-buffer gnus-article-buffer)
4021 (let ((cite (memq 'cite gnus-article-wash-types))
4022 (headers (memq 'headers gnus-article-wash-types))
4023 (boring (memq 'boring-headers gnus-article-wash-types))
4024 (pgp (memq 'pgp gnus-article-wash-types))
4025 (pem (memq 'pem gnus-article-wash-types))
4026 (signed (memq 'signed gnus-article-wash-types))
4027 (encrypted (memq 'encrypted gnus-article-wash-types))
4028 (signature (memq 'signature gnus-article-wash-types))
4029 (overstrike (memq 'overstrike gnus-article-wash-types))
4030 (emphasis (memq 'emphasis gnus-article-wash-types)))
4031 (format "%c%c%c%c%c%c"
4033 (if (or headers boring) ?h ? )
4034 (if (or pgp pem signed encrypted) ?p ? )
4035 (if signature ?s ? )
4036 (if overstrike ?o ? )
4037 (if emphasis ?e ? )))))
4039 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4041 (defun gnus-article-maybe-hide-headers ()
4042 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4043 Provided for backwards compatibility."
4044 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4045 (not (save-excursion (set-buffer gnus-summary-buffer)
4046 gnus-have-all-headers)))
4047 (not gnus-inhibit-hiding))
4048 (gnus-article-hide-headers)))
4052 (defun gnus-output-to-file (file-name)
4053 "Append the current article to a file named FILE-NAME."
4054 (let ((artbuf (current-buffer)))
4056 (insert-buffer-substring artbuf)
4057 ;; Append newline at end of the buffer as separator, and then
4059 (goto-char (point-max))
4061 (mm-append-to-file (point-min) (point-max) file-name)
4064 (defun gnus-narrow-to-page (&optional arg)
4065 "Narrow the article buffer to a page.
4066 If given a numerical ARG, move forward ARG pages."
4068 (setq arg (if arg (prefix-numeric-value arg) 0))
4070 (set-buffer gnus-article-buffer)
4071 (goto-char (point-min))
4073 ;; Remove any old next/prev buttons.
4074 (when (gnus-visual-p 'page-marker)
4075 (let ((buffer-read-only nil))
4076 (gnus-remove-text-with-property 'gnus-prev)
4077 (gnus-remove-text-with-property 'gnus-next)))
4080 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4082 (re-search-forward page-delimiter nil 'move arg)))
4083 (goto-char (match-end 0)))
4086 (if (re-search-forward page-delimiter nil 'move)
4089 (when (and (gnus-visual-p 'page-marker)
4090 (not (= (point-min) 1)))
4092 (goto-char (point-min))
4093 (gnus-insert-prev-page-button)))
4094 (when (and (gnus-visual-p 'page-marker)
4095 (< (+ (point-max) 2) (buffer-size)))
4097 (goto-char (point-max))
4098 (gnus-insert-next-page-button)))))
4100 ;; Article mode commands
4102 (defun gnus-article-goto-next-page ()
4103 "Show the next page of the article."
4105 (when (gnus-article-next-page)
4106 (goto-char (point-min))
4107 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4109 (defun gnus-article-goto-prev-page ()
4110 "Show the next page of the article."
4112 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4113 (gnus-article-prev-page nil)))
4115 (defun gnus-article-next-page (&optional lines)
4116 "Show the next page of the current article.
4117 If end of article, return non-nil. Otherwise return nil.
4118 Argument LINES specifies lines to be scrolled up."
4120 (move-to-window-line -1)
4123 (and (pos-visible-in-window-p) ;Not continuation line.
4125 ;; Nothing in this page.
4126 (if (or (not gnus-page-broken)
4129 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4131 (gnus-narrow-to-page 1) ;Go to next page.
4133 ;; More in this page.
4134 (let ((scroll-in-place nil))
4138 ;; Long lines may cause an end-of-buffer error.
4139 (goto-char (point-max)))))
4140 (move-to-window-line 0)
4143 (defun gnus-article-prev-page (&optional lines)
4144 "Show previous page of current article.
4145 Argument LINES specifies lines to be scrolled down."
4147 (move-to-window-line 0)
4148 (if (and gnus-page-broken
4150 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4152 (gnus-narrow-to-page -1) ;Go to previous page.
4153 (goto-char (point-max))
4155 (let ((scroll-in-place nil))
4159 (beginning-of-buffer
4160 (goto-char (point-min))))
4161 (move-to-window-line 0)))))
4163 (defun gnus-article-refer-article ()
4164 "Read article specified by message-id around point."
4166 (let ((point (point)))
4167 (search-forward ">" nil t) ;Move point to end of "<....>".
4168 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4169 (let ((message-id (match-string 1)))
4171 (set-buffer gnus-summary-buffer)
4172 (gnus-summary-refer-article message-id))
4174 (error "No references around point"))))
4176 (defun gnus-article-show-summary ()
4177 "Reconfigure windows to show summary buffer."
4179 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4180 (error "There is no summary buffer for this article buffer")
4181 (gnus-article-set-globals)
4182 (gnus-configure-windows 'article)
4183 (gnus-summary-goto-subject gnus-current-article)
4184 (gnus-summary-position-point)))
4186 (defun gnus-article-describe-briefly ()
4187 "Describe article mode commands briefly."
4189 (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")))
4191 (defun gnus-article-summary-command ()
4192 "Execute the last keystroke in the summary buffer."
4194 (let ((obuf (current-buffer))
4195 (owin (current-window-configuration))
4197 (switch-to-buffer gnus-article-current-summary 'norecord)
4198 (setq func (lookup-key (current-local-map) (this-command-keys)))
4199 (call-interactively func)
4201 (set-window-configuration owin)
4202 (set-window-point (get-buffer-window (current-buffer)) (point))))
4204 (defun gnus-article-summary-command-nosave ()
4205 "Execute the last keystroke in the summary buffer."
4208 (pop-to-buffer gnus-article-current-summary 'norecord)
4209 (setq func (lookup-key (current-local-map) (this-command-keys)))
4210 (call-interactively func)))
4212 (defun gnus-article-check-buffer ()
4213 "Beep if not in an article buffer."
4214 (unless (equal major-mode 'gnus-article-mode)
4215 (error "Command invoked outside of a Gnus article buffer")))
4217 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4218 "Read a summary buffer key sequence and execute it from the article buffer."
4220 (gnus-article-check-buffer)
4222 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4223 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4224 "=" "^" "\M-^" "|"))
4230 '("n" "Gn" "p" "Gp"))
4233 (set-buffer gnus-article-current-summary)
4234 (let (gnus-pick-mode)
4235 (push (or key last-command-event) unread-command-events)
4236 (setq keys (if (featurep 'xemacs)
4237 (events-to-keys (read-key-sequence nil))
4238 (read-key-sequence nil)))))
4242 (if (or (member keys nosaves)
4243 (member keys nosave-but-article)
4244 (member keys nosave-in-article))
4246 (save-window-excursion
4247 (pop-to-buffer gnus-article-current-summary 'norecord)
4248 ;; We disable the pick minor mode commands.
4249 (let (gnus-pick-mode)
4250 (setq func (lookup-key (current-local-map) keys))))
4254 (unless (member keys nosave-in-article)
4255 (set-buffer gnus-article-current-summary))
4256 (call-interactively func)
4257 (setq new-sum-point (point)))
4258 (when (member keys nosave-but-article)
4259 (pop-to-buffer gnus-article-buffer 'norecord)))
4260 ;; These commands should restore window configuration.
4261 (let ((obuf (current-buffer))
4262 (owin (current-window-configuration))
4264 (summary gnus-article-current-summary)
4265 func in-buffer selected)
4266 (if not-restore-window
4267 (pop-to-buffer summary 'norecord)
4268 (switch-to-buffer summary 'norecord))
4269 (setq in-buffer (current-buffer))
4270 ;; We disable the pick minor mode commands.
4271 (if (and (setq func (let (gnus-pick-mode)
4272 (lookup-key (current-local-map) keys)))
4275 (call-interactively func)
4276 (setq new-sum-point (point))
4277 (when (eq in-buffer (current-buffer))
4278 (setq selected (gnus-summary-select-article))
4280 (unless not-restore-window
4281 (set-window-configuration owin))
4282 (when (eq selected 'old)
4284 (set-window-start (get-buffer-window (current-buffer))
4286 (set-window-point (get-buffer-window (current-buffer))
4288 (let ((win (get-buffer-window gnus-article-current-summary)))
4290 (set-window-point win new-sum-point)))) )
4291 (switch-to-buffer gnus-article-buffer)
4294 (defun gnus-article-describe-key (key)
4295 "Display documentation of the function invoked by KEY. KEY is a string."
4296 (interactive "kDescribe key: ")
4297 (gnus-article-check-buffer)
4298 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4300 (set-buffer gnus-article-current-summary)
4301 (let (gnus-pick-mode)
4302 (if (featurep 'xemacs)
4304 (push (elt key 0) unread-command-events)
4305 (setq key (events-to-keys
4306 (read-key-sequence "Describe key: "))))
4307 (setq unread-command-events
4309 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4310 (string-to-list key)))
4311 (setq key (read-key-sequence "Describe key: "))))
4313 (describe-key key)))
4315 (defun gnus-article-describe-key-briefly (key &optional insert)
4316 "Display documentation of the function invoked by KEY. KEY is a string."
4317 (interactive "kDescribe key: \nP")
4318 (gnus-article-check-buffer)
4319 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4321 (set-buffer gnus-article-current-summary)
4322 (let (gnus-pick-mode)
4323 (if (featurep 'xemacs)
4325 (push (elt key 0) unread-command-events)
4326 (setq key (events-to-keys
4327 (read-key-sequence "Describe key: "))))
4328 (setq unread-command-events
4330 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4331 (string-to-list key)))
4332 (setq key (read-key-sequence "Describe key: "))))
4333 (describe-key-briefly key insert))
4334 (describe-key-briefly key insert)))
4336 (defun gnus-article-hide (&optional arg force)
4337 "Hide all the gruft in the current article.
4338 This means that PGP stuff, signatures, cited text and (some)
4339 headers will be hidden.
4340 If given a prefix, show the hidden text instead."
4341 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4342 (gnus-article-hide-headers arg)
4343 (gnus-article-hide-list-identifiers arg)
4344 (gnus-article-hide-pgp arg)
4345 (gnus-article-hide-citation-maybe arg force)
4346 (gnus-article-hide-signature arg))
4348 (defun gnus-article-maybe-highlight ()
4349 "Do some article highlighting if article highlighting is requested."
4350 (when (gnus-visual-p 'article-highlight 'highlight)
4351 (gnus-article-highlight-some)))
4353 (defun gnus-check-group-server ()
4354 ;; Make sure the connection to the server is alive.
4355 (unless (gnus-server-opened
4356 (gnus-find-method-for-group gnus-newsgroup-name))
4357 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4358 (gnus-request-group gnus-newsgroup-name t)))
4360 (defun gnus-request-article-this-buffer (article group)
4361 "Get an article and insert it into this buffer."
4362 (let (do-update-line sparse-header)
4366 (gnus-kill-all-overlays)
4367 (setq group (or group gnus-newsgroup-name))
4369 ;; Using `gnus-request-article' directly will insert the article into
4370 ;; `nntp-server-buffer' - so we'll save some time by not having to
4371 ;; copy it from the server buffer into the article buffer.
4373 ;; We only request an article by message-id when we do not have the
4374 ;; headers for it, so we'll have to get those.
4375 (when (stringp article)
4376 (gnus-read-header article))
4378 ;; If the article number is negative, that means that this article
4379 ;; doesn't belong in this newsgroup (possibly), so we find its
4380 ;; message-id and request it by id instead of number.
4381 (when (and (numberp article)
4383 (get-buffer gnus-summary-buffer)
4384 (gnus-buffer-exists-p gnus-summary-buffer))
4386 (set-buffer gnus-summary-buffer)
4387 (let ((header (gnus-summary-article-header article)))
4390 ((memq article gnus-newsgroup-sparse)
4391 ;; This is a sparse gap article.
4392 (setq do-update-line article)
4393 (setq article (mail-header-id header))
4394 (setq sparse-header (gnus-read-header article))
4395 (setq gnus-newsgroup-sparse
4396 (delq article gnus-newsgroup-sparse)))
4398 ;; It's a real article.
4399 (setq article (mail-header-id header)))
4401 ;; It is an extracted pseudo-article.
4402 (setq article 'pseudo)
4403 (gnus-request-pseudo-article header))))
4405 (let ((method (gnus-find-method-for-group
4406 gnus-newsgroup-name)))
4407 (when (and (eq (car method) 'nneething)
4409 (let ((dir (expand-file-name
4410 (mail-header-subject header)
4411 (file-name-as-directory
4412 (or (cadr (assq 'nneething-address method))
4414 (when (file-directory-p dir)
4415 (setq article 'nneething)
4416 (gnus-group-enter-directory dir))))))))
4419 ;; Refuse to select canceled articles.
4420 ((and (numberp article)
4422 (get-buffer gnus-summary-buffer)
4423 (gnus-buffer-exists-p gnus-summary-buffer)
4424 (eq (cdr (save-excursion
4425 (set-buffer gnus-summary-buffer)
4426 (assq article gnus-newsgroup-reads)))
4427 gnus-canceled-mark))
4429 ;; We first check `gnus-original-article-buffer'.
4430 ((and (get-buffer gnus-original-article-buffer)
4433 (set-buffer gnus-original-article-buffer)
4434 (and (equal (car gnus-original-article) group)
4435 (eq (cdr gnus-original-article) article))))
4436 (insert-buffer-substring gnus-original-article-buffer)
4438 ;; Check the backlog.
4439 ((and gnus-keep-backlog
4440 (gnus-backlog-request-article group article (current-buffer)))
4442 ;; Check asynchronous pre-fetch.
4443 ((gnus-async-request-fetched-article group article (current-buffer))
4444 (gnus-async-prefetch-next group article gnus-summary-buffer)
4445 (when (and (numberp article) gnus-keep-backlog)
4446 (gnus-backlog-enter-article group article (current-buffer)))
4449 ((and gnus-use-cache
4451 (gnus-cache-request-article article group))
4453 ;; Get the article and put into the article buffer.
4454 ((or (stringp article)
4456 (let ((gnus-override-method gnus-override-method)
4457 (methods (and (stringp article)
4458 gnus-refer-article-method))
4460 (buffer-read-only nil))
4461 (if (or (not (listp methods))
4462 (and (symbolp (car methods))
4463 (assq (car methods) nnoo-definition-alist)))
4464 (setq methods (list methods)))
4465 (when (and (null gnus-override-method)
4467 (setq gnus-override-method (pop methods)))
4469 (when (eq gnus-override-method 'current)
4470 (setq gnus-override-method gnus-current-select-method))
4472 (gnus-kill-all-overlays)
4473 (let ((gnus-newsgroup-name group))
4474 (gnus-check-group-server))
4475 (when (gnus-request-article article group (current-buffer))
4476 (when (numberp article)
4477 (gnus-async-prefetch-next group article
4478 gnus-summary-buffer)
4479 (when gnus-keep-backlog
4480 (gnus-backlog-enter-article
4481 group article (current-buffer))))
4482 (setq result 'article))
4485 (setq gnus-override-method (pop methods))
4486 (setq result 'done))))
4487 (and (eq result 'article) 'article)))
4491 ;; Associate this article with the current summary buffer.
4492 (setq gnus-article-current-summary gnus-summary-buffer)
4494 ;; Take the article from the original article buffer
4495 ;; and place it in the buffer it's supposed to be in.
4496 (when (and (get-buffer gnus-article-buffer)
4497 (equal (buffer-name (current-buffer))
4498 (buffer-name (get-buffer gnus-article-buffer))))
4500 (if (get-buffer gnus-original-article-buffer)
4501 (set-buffer gnus-original-article-buffer)
4502 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4503 (buffer-disable-undo)
4504 (setq major-mode 'gnus-original-article-mode)
4505 (setq buffer-read-only t))
4506 (let (buffer-read-only)
4508 (insert-buffer-substring gnus-article-buffer))
4509 (setq gnus-original-article (cons group article)))
4512 (run-hooks 'gnus-article-decode-hook)
4513 ;; Mark article as decoded or not.
4514 (setq gnus-article-decoded-p gnus-article-decode-hook))
4516 ;; Update sparse articles.
4517 (when (and do-update-line
4518 (or (numberp article)
4520 (let ((buf (current-buffer)))
4521 (set-buffer gnus-summary-buffer)
4522 (gnus-summary-update-article do-update-line sparse-header)
4523 (gnus-summary-goto-subject do-update-line nil t)
4524 (set-window-point (get-buffer-window (current-buffer) t)
4526 (set-buffer buf))))))
4532 (defcustom gnus-article-edit-mode-hook nil
4533 "Hook run in article edit mode buffers."
4534 :group 'gnus-article-various
4537 (defvar gnus-article-edit-done-function nil)
4539 (defvar gnus-article-edit-mode-map nil)
4541 ;; Should we be using derived.el for this?
4542 (unless gnus-article-edit-mode-map
4543 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4544 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4546 (gnus-define-keys gnus-article-edit-mode-map
4547 "\C-c\C-c" gnus-article-edit-done
4548 "\C-c\C-k" gnus-article-edit-exit)
4550 (gnus-define-keys (gnus-article-edit-wash-map
4551 "\C-c\C-w" gnus-article-edit-mode-map)
4552 "f" gnus-article-edit-full-stops))
4554 (defun gnus-article-edit-mode ()
4555 "Major mode for editing articles.
4556 This is an extended text-mode.
4558 \\{gnus-article-edit-mode-map}"
4560 (setq major-mode 'gnus-article-edit-mode)
4561 (setq mode-name "Article Edit")
4562 (use-local-map gnus-article-edit-mode-map)
4563 (make-local-variable 'gnus-article-edit-done-function)
4564 (make-local-variable 'gnus-prev-winconf)
4565 (setq buffer-read-only nil)
4566 (buffer-enable-undo)
4568 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4570 (defun gnus-article-edit (&optional force)
4571 "Edit the current article.
4572 This will have permanent effect only in mail groups.
4573 If FORCE is non-nil, allow editing of articles even in read-only
4576 (when (and (not force)
4577 (gnus-group-read-only-p))
4578 (error "The current newsgroup does not support article editing"))
4579 (gnus-article-date-original)
4580 (gnus-article-edit-article
4582 `(lambda (no-highlight)
4584 (gnus-summary-edit-article-done
4585 ,(or (mail-header-references gnus-current-headers) "")
4586 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4588 (defun gnus-article-edit-article (start-func exit-func)
4589 "Start editing the contents of the current article buffer."
4590 (let ((winconf (current-window-configuration)))
4591 (set-buffer gnus-article-buffer)
4592 (gnus-article-edit-mode)
4593 (funcall start-func)
4594 (set-buffer-modified-p nil)
4595 (gnus-configure-windows 'edit-article)
4596 (setq gnus-article-edit-done-function exit-func)
4597 (setq gnus-prev-winconf winconf)
4598 (gnus-message 6 "C-c C-c to end edits")))
4600 (defun gnus-article-edit-done (&optional arg)
4601 "Update the article edits and exit."
4603 (let ((func gnus-article-edit-done-function)
4604 (buf (current-buffer))
4605 (start (window-start)))
4606 ;; We remove all text props from the article buffer.
4608 (buffer-substring-no-properties (point-min) (point-max)))
4612 (let ((winconf gnus-prev-winconf))
4614 (set-window-configuration winconf)
4615 ;; Tippy-toe some to make sure that point remains where it was.
4616 (save-current-buffer
4618 (set-window-start (get-buffer-window (current-buffer)) start)
4622 (let ((buffer-read-only nil))
4624 ;; The cache and backlog have to be flushed somewhat.
4625 (when gnus-keep-backlog
4626 (gnus-backlog-remove-article
4627 (car gnus-article-current) (cdr gnus-article-current)))
4628 ;; Flush original article as well.
4630 (when (get-buffer gnus-original-article-buffer)
4631 (set-buffer gnus-original-article-buffer)
4632 (setq gnus-original-article nil)))
4633 (when gnus-use-cache
4634 (gnus-cache-update-article
4635 (car gnus-article-current) (cdr gnus-article-current))))
4637 (set-window-start (get-buffer-window buf) start)
4638 (set-window-point (get-buffer-window buf) (point))))
4640 (defun gnus-article-edit-exit ()
4641 "Exit the article editing without updating."
4643 (when (or (not (buffer-modified-p))
4644 (yes-or-no-p "Article modified; kill anyway? "))
4645 (let ((curbuf (current-buffer))
4647 (window-start (window-start)))
4649 (if (gnus-buffer-live-p gnus-original-article-buffer)
4650 (insert-buffer gnus-original-article-buffer))
4651 (let ((winconf gnus-prev-winconf))
4653 (set-window-configuration winconf)
4654 ;; Tippy-toe some to make sure that point remains where it was.
4655 (save-current-buffer
4657 (set-window-start (get-buffer-window (current-buffer)) window-start)
4660 (defun gnus-article-edit-full-stops ()
4661 "Interactively repair spacing at end of sentences."
4664 (goto-char (point-min))
4665 (search-forward-regexp "^$" nil t)
4666 (let ((case-fold-search nil))
4667 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4670 ;;; Article highlights
4673 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4675 ;;; Internal Variables:
4677 (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\\)\\)"
4678 "Regular expression that matches URLs."
4679 :group 'gnus-article-buttons
4682 (defcustom gnus-button-alist
4683 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4684 0 t gnus-button-message-id 2)
4685 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4686 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4688 gnus-button-fetch-group 4)
4689 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4690 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4691 t gnus-button-message-id 3)
4692 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4693 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
4694 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4695 ;; This is how URLs _should_ be embedded in text...
4696 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4698 (,gnus-button-url-regexp 0 t browse-url 0))
4699 "*Alist of regexps matching buttons in article bodies.
4701 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4702 REGEXP: is the string matching text around the button,
4703 BUTTON: is the number of the regexp grouping actually matching the button,
4704 FORM: is a lisp expression which must eval to true for the button to
4706 CALLBACK: is the function to call when the user push this button, and each
4707 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4709 CALLBACK can also be a variable, in that case the value of that
4710 variable it the real callback function."
4711 :group 'gnus-article-buttons
4712 :type '(repeat (list regexp
4713 (integer :tag "Button")
4715 (function :tag "Callback")
4718 (integer :tag "Regexp group")))))
4720 (defcustom gnus-header-button-alist
4721 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4722 0 t gnus-button-message-id 0)
4723 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4724 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4725 0 t gnus-button-mailto 0)
4726 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4727 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4728 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4729 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4730 gnus-button-message-id 3))
4731 "*Alist of headers and regexps to match buttons in article heads.
4733 This alist is very similar to `gnus-button-alist', except that each
4734 alist has an additional HEADER element first in each entry:
4736 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4738 HEADER is a regexp to match a header. For a fuller explanation, see
4739 `gnus-button-alist'."
4740 :group 'gnus-article-buttons
4741 :group 'gnus-article-headers
4742 :type '(repeat (list (regexp :tag "Header")
4744 (integer :tag "Button")
4746 (function :tag "Callback")
4749 (integer :tag "Regexp group")))))
4751 (defvar gnus-button-regexp nil)
4752 (defvar gnus-button-marker-list nil)
4753 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4755 (defvar gnus-button-last nil)
4756 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4760 (defun gnus-article-push-button (event)
4761 "Check text under the mouse pointer for a callback function.
4762 If the text under the mouse pointer has a `gnus-callback' property,
4763 call it with the value of the `gnus-data' text property."
4765 (set-buffer (window-buffer (posn-window (event-start event))))
4766 (let* ((pos (posn-point (event-start event)))
4767 (data (get-text-property pos 'gnus-data))
4768 (fun (get-text-property pos 'gnus-callback)))
4771 (funcall fun data))))
4773 (defun gnus-article-press-button ()
4774 "Check text at point for a callback function.
4775 If the text at point has a `gnus-callback' property,
4776 call it with the value of the `gnus-data' text property."
4778 (let* ((data (get-text-property (point) 'gnus-data))
4779 (fun (get-text-property (point) 'gnus-callback)))
4781 (funcall fun data))))
4783 (defun gnus-article-highlight (&optional force)
4784 "Highlight current article.
4785 This function calls `gnus-article-highlight-headers',
4786 `gnus-article-highlight-citation',
4787 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4788 do the highlighting. See the documentation for those functions."
4789 (interactive (list 'force))
4790 (gnus-article-highlight-headers)
4791 (gnus-article-highlight-citation force)
4792 (gnus-article-highlight-signature)
4793 (gnus-article-add-buttons force)
4794 (gnus-article-add-buttons-to-head))
4796 (defun gnus-article-highlight-some (&optional force)
4797 "Highlight current article.
4798 This function calls `gnus-article-highlight-headers',
4799 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4800 do the highlighting. See the documentation for those functions."
4801 (interactive (list 'force))
4802 (gnus-article-highlight-headers)
4803 (gnus-article-highlight-signature)
4804 (gnus-article-add-buttons))
4806 (defun gnus-article-highlight-headers ()
4807 "Highlight article headers as specified by `gnus-header-face-alist'."
4810 (set-buffer gnus-article-buffer)
4812 (let ((alist gnus-header-face-alist)
4813 (buffer-read-only nil)
4814 (case-fold-search t)
4815 (inhibit-point-motion-hooks t)
4816 entry regexp header-face field-face from hpoints fpoints)
4817 (article-narrow-to-head)
4818 (while (setq entry (pop alist))
4819 (goto-char (point-min))
4820 (setq regexp (concat "^\\("
4821 (if (string-equal "" (nth 0 entry))
4825 header-face (nth 1 entry)
4826 field-face (nth 2 entry))
4827 (while (and (re-search-forward regexp nil t)
4831 (unless (search-forward ":" nil t)
4833 (when (and header-face
4834 (not (memq (point) hpoints)))
4835 (push (point) hpoints)
4836 (gnus-put-text-property from (point) 'face header-face))
4837 (when (and field-face
4838 (not (memq (setq from (point)) fpoints)))
4840 (if (re-search-forward "^[^ \t]" nil t)
4842 (goto-char (point-max)))
4843 (gnus-put-text-property from (point) 'face field-face))))))))
4845 (defun gnus-article-highlight-signature ()
4846 "Highlight the signature in an article.
4847 It does this by highlighting everything after
4848 `gnus-signature-separator' using `gnus-signature-face'."
4851 (set-buffer gnus-article-buffer)
4852 (let ((buffer-read-only nil)
4853 (inhibit-point-motion-hooks t))
4855 (when (and gnus-signature-face
4856 (gnus-article-narrow-to-signature))
4857 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4858 'face gnus-signature-face)
4860 (gnus-article-search-signature)
4861 (let ((start (match-beginning 0))
4862 (end (set-marker (make-marker) (1+ (match-end 0)))))
4863 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4866 (defun gnus-button-in-region-p (b e prop)
4867 "Say whether PROP exists in the region."
4868 (text-property-not-all b e prop nil))
4870 (defun gnus-article-add-buttons (&optional force)
4871 "Find external references in the article and make buttons of them.
4872 \"External references\" are things like Message-IDs and URLs, as
4873 specified by `gnus-button-alist'."
4874 (interactive (list 'force))
4876 (set-buffer gnus-article-buffer)
4877 (let ((buffer-read-only nil)
4878 (inhibit-point-motion-hooks t)
4879 (case-fold-search t)
4880 (alist gnus-button-alist)
4882 ;; Remove all old markers.
4883 (let (marker entry new-list)
4884 (while (setq marker (pop gnus-button-marker-list))
4885 (if (or (< marker (point-min)) (>= marker (point-max)))
4886 (push marker new-list)
4888 (when (setq entry (gnus-button-entry))
4889 (put-text-property (match-beginning (nth 1 entry))
4890 (match-end (nth 1 entry))
4891 'gnus-callback nil))
4892 (set-marker marker nil)))
4893 (setq gnus-button-marker-list new-list))
4894 ;; We skip the headers.
4897 (while (setq entry (pop alist))
4898 (setq regexp (car entry))
4900 (while (re-search-forward regexp nil t)
4901 (let* ((start (and entry (match-beginning (nth 1 entry))))
4902 (end (and entry (match-end (nth 1 entry))))
4903 (from (match-beginning 0)))
4904 (when (and (or (eq t (nth 2 entry))
4905 (eval (nth 2 entry)))
4906 (not (gnus-button-in-region-p
4907 start end 'gnus-callback)))
4908 ;; That optional form returned non-nil, so we add the
4910 (gnus-article-add-button
4911 start end 'gnus-button-push
4912 (car (push (set-marker (make-marker) from)
4913 gnus-button-marker-list))))))))))
4915 ;; Add buttons to the head of an article.
4916 (defun gnus-article-add-buttons-to-head ()
4917 "Add buttons to the head of the article."
4920 (set-buffer gnus-article-buffer)
4922 (let ((buffer-read-only nil)
4923 (inhibit-point-motion-hooks t)
4924 (case-fold-search t)
4925 (alist gnus-header-button-alist)
4927 (article-narrow-to-head)
4929 ;; Each alist entry.
4930 (setq entry (car alist)
4932 (goto-char (point-min))
4933 (while (re-search-forward (car entry) nil t)
4934 ;; Each header matching the entry.
4935 (setq beg (match-beginning 0))
4936 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4937 (match-beginning 0))
4940 (while (re-search-forward (nth 1 entry) end t)
4941 ;; Each match within a header.
4942 (let* ((entry (cdr entry))
4943 (start (match-beginning (nth 1 entry)))
4944 (end (match-end (nth 1 entry)))
4945 (form (nth 2 entry)))
4946 (goto-char (match-end 0))
4948 (gnus-article-add-button
4949 start end (nth 3 entry)
4950 (buffer-substring (match-beginning (nth 4 entry))
4951 (match-end (nth 4 entry)))))))
4952 (goto-char end)))))))
4954 ;;; External functions:
4956 (defun gnus-article-add-button (from to fun &optional data)
4957 "Create a button between FROM and TO with callback FUN and data DATA."
4958 (when gnus-article-button-face
4959 (gnus-overlay-put (gnus-make-overlay from to)
4960 'face gnus-article-button-face))
4961 (gnus-add-text-properties
4963 (nconc (and gnus-article-mouse-face
4964 (list gnus-mouse-face-prop gnus-article-mouse-face))
4965 (list 'gnus-callback fun)
4966 (and data (list 'gnus-data data))))
4967 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4968 :button-keymap gnus-widget-button-keymap))
4970 ;;; Internal functions:
4972 (defun gnus-article-set-globals ()
4974 (set-buffer gnus-summary-buffer)
4975 (gnus-set-global-variables)))
4977 (defun gnus-signature-toggle (end)
4979 (set-buffer gnus-article-buffer)
4980 (let ((buffer-read-only nil)
4981 (inhibit-point-motion-hooks t))
4982 (if (text-property-any end (point-max) 'article-type 'signature)
4983 (gnus-remove-text-properties-when
4984 'article-type 'signature end (point-max)
4985 (cons 'article-type (cons 'signature
4986 gnus-hidden-properties)))
4987 (gnus-add-text-properties-when
4988 'article-type nil end (point-max)
4989 (cons 'article-type (cons 'signature
4990 gnus-hidden-properties)))))))
4992 (defun gnus-button-entry ()
4993 ;; Return the first entry in `gnus-button-alist' matching this place.
4994 (let ((alist gnus-button-alist)
4997 (setq entry (pop alist))
4998 (if (looking-at (car entry))
5003 (defun gnus-button-push (marker)
5004 ;; Push button starting at MARKER.
5007 (let* ((entry (gnus-button-entry))
5008 (inhibit-point-motion-hooks t)
5010 (args (mapcar (lambda (group)
5011 (let ((string (match-string group)))
5012 (gnus-set-text-properties
5013 0 (length string) nil string)
5020 (fboundp (symbol-value fun)))
5021 (apply (symbol-value fun) args))
5023 (gnus-message 1 "You must define `%S' to use this button"
5024 (cons fun args)))))))
5026 (defun gnus-button-message-id (message-id)
5029 (set-buffer gnus-summary-buffer)
5030 (gnus-summary-refer-article message-id)))
5032 (defun gnus-button-fetch-group (address)
5033 "Fetch GROUP specified by ADDRESS."
5034 (if (not (string-match "[:/]" address))
5035 ;; This is just a simple group url.
5036 (gnus-group-read-ephemeral-group address gnus-select-method)
5037 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5039 (error "Can't parse %s" address)
5040 (gnus-group-read-ephemeral-group
5041 (match-string 4 address)
5042 `(nntp ,(match-string 1 address)
5043 (nntp-address ,(match-string 1 address))
5044 (nntp-port-number ,(if (match-end 3)
5045 (match-string 3 address)
5048 (defun gnus-url-parse-query-string (query &optional downcase)
5049 (let (retval pairs cur key val)
5050 (setq pairs (split-string query "&"))
5052 (setq cur (car pairs)
5054 (if (not (string-match "=" cur))
5056 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5057 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5059 (setq key (downcase key)))
5060 (setq cur (assoc key retval))
5062 (setcdr cur (cons val (cdr cur)))
5063 (setq retval (cons (list key val) retval)))))
5066 (defun gnus-url-unhex (x)
5073 (defun gnus-url-unhex-string (str &optional allow-newlines)
5074 "Remove %XXX embedded spaces, etc in a url.
5075 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5076 decoding of carriage returns and line feeds in the string, which is normally
5077 forbidden in URL encoding."
5078 (setq str (or str ""))
5080 (case-fold-search t))
5081 (while (string-match "%[0-9a-f][0-9a-f]" str)
5082 (let* ((start (match-beginning 0))
5083 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5085 (gnus-url-unhex (elt str (+ start 2))))))
5087 tmp (substring str 0 start)
5090 (char-to-string code))
5091 ((or (= code ?\n) (= code ?\r))
5093 (t (char-to-string code))))
5094 str (substring str (match-end 0)))))
5095 (setq tmp (concat tmp str))
5098 (defun gnus-url-mailto (url)
5099 ;; Send mail to someone
5100 (when (string-match "mailto:/*\\(.*\\)" url)
5101 (setq url (substring url (match-beginning 1) nil)))
5102 (let (to args subject func)
5103 (if (string-match (regexp-quote "?") url)
5104 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5105 args (gnus-url-parse-query-string
5106 (substring url (match-end 0) nil) t))
5107 (setq to (gnus-url-unhex-string url)))
5108 (setq args (cons (list "to" to) args)
5109 subject (cdr-safe (assoc "subject" args)))
5112 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5115 (message-position-on-field (caar args)))
5116 (insert (mapconcat 'identity (cdar args) ", "))
5117 (setq args (cdr args)))
5120 (message-goto-subject))))
5122 (defun gnus-button-embedded-url (address)
5123 "Activate ADDRESS with `browse-url'."
5124 (browse-url (gnus-strip-whitespace address)))
5126 ;;; Next/prev buttons in the article buffer.
5128 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5129 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5131 (defvar gnus-prev-page-map nil)
5132 (unless gnus-prev-page-map
5133 (setq gnus-prev-page-map (make-sparse-keymap))
5134 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5135 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5137 (defun gnus-insert-prev-page-button ()
5138 (let ((buffer-read-only nil))
5140 gnus-prev-page-line-format nil
5141 `(gnus-prev t local-map ,gnus-prev-page-map
5142 gnus-callback gnus-article-button-prev-page
5143 article-type annotation))))
5145 (defvar gnus-next-page-map nil)
5146 (unless gnus-next-page-map
5147 (setq gnus-next-page-map (make-keymap))
5148 (suppress-keymap gnus-prev-page-map)
5149 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5150 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5152 (defun gnus-button-next-page ()
5153 "Go to the next page."
5155 (let ((win (selected-window)))
5156 (select-window (get-buffer-window gnus-article-buffer t))
5157 (gnus-article-next-page)
5158 (select-window win)))
5160 (defun gnus-button-prev-page ()
5161 "Go to the prev page."
5163 (let ((win (selected-window)))
5164 (select-window (get-buffer-window gnus-article-buffer t))
5165 (gnus-article-prev-page)
5166 (select-window win)))
5168 (defun gnus-insert-next-page-button ()
5169 (let ((buffer-read-only nil))
5170 (gnus-eval-format gnus-next-page-line-format nil
5172 t local-map ,gnus-next-page-map
5173 gnus-callback gnus-article-button-next-page
5174 article-type annotation))))
5176 (defun gnus-article-button-next-page (arg)
5177 "Go to the next page."
5179 (let ((win (selected-window)))
5180 (select-window (get-buffer-window gnus-article-buffer t))
5181 (gnus-article-next-page)
5182 (select-window win)))
5184 (defun gnus-article-button-prev-page (arg)
5185 "Go to the prev page."
5187 (let ((win (selected-window)))
5188 (select-window (get-buffer-window gnus-article-buffer t))
5189 (gnus-article-prev-page)
5190 (select-window win)))
5192 (defvar gnus-decode-header-methods
5193 '(mail-decode-encoded-word-region)
5194 "List of methods used to decode headers.
5196 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5197 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5198 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5199 whose names match REGEXP.
5202 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5203 mail-decode-encoded-word-region
5204 (\"chinese\" . rfc1843-decode-region))
5207 (defvar gnus-decode-header-methods-cache nil)
5209 (defun gnus-multi-decode-header (start end)
5210 "Apply the functions from `gnus-encoded-word-methods' that match."
5211 (unless (and gnus-decode-header-methods-cache
5212 (eq gnus-newsgroup-name
5213 (car gnus-decode-header-methods-cache)))
5214 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5217 (nconc gnus-decode-header-methods-cache (list x))
5218 (if (and gnus-newsgroup-name
5219 (string-match (car x) gnus-newsgroup-name))
5220 (nconc gnus-decode-header-methods-cache
5222 gnus-decode-header-methods))
5223 (let ((xlist gnus-decode-header-methods-cache))
5226 (narrow-to-region start end)
5228 (funcall (pop xlist) (point-min) (point-max))))))
5231 ;;; Treatment top-level handling.
5234 (defun gnus-treat-article (condition &optional part-number total-parts type)
5235 (let ((length (- (point-max) (point-min)))
5236 (alist gnus-treatment-function-alist)
5237 (article-goto-body-goes-to-point-min-p t)
5241 (let ((list gnus-article-treat-types))
5243 (when (string-match (pop list) type)
5244 (throw 'found t)))))))
5245 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5247 (gnus-run-hooks 'gnus-part-display-hook)
5248 (while (setq elem (pop alist))
5251 (if (gnus-buffer-live-p gnus-summary-buffer)
5252 (set-buffer gnus-summary-buffer))
5253 (symbol-value (car elem))))
5254 (when (and (or (consp val)
5256 (gnus-treat-predicate val)
5257 (or (not (get (car elem) 'highlight))
5260 (funcall (cadr elem)))))))
5262 ;; Dynamic variables.
5264 (defvar part-number)
5265 (defvar total-parts)
5270 (defun gnus-treat-predicate (val)
5275 (stringp (car val)))
5276 (apply 'gnus-or (mapcar `(lambda (s)
5277 (string-match s ,(or gnus-newsgroup-name "")))
5280 (let ((pred (pop val)))
5283 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5285 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5287 (not (gnus-treat-predicate (car val))))
5289 (equal (car val) type))
5291 (error "%S is not a valid predicate" pred)))))
5299 (eq part-number total-parts))
5303 (error "%S is not a valid value" val))))
5305 (defun gnus-article-encrypt-body (protocol &optional n)
5306 "Encrypt the article body."
5309 (or gnus-article-encrypt-protocol
5310 (completing-read "Encrypt protocol: "
5311 gnus-article-encrypt-protocol-alist
5313 current-prefix-arg))
5314 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5316 (error (format "Can't find the encrypt protocol %s" protocol)))
5317 (if (equal gnus-newsgroup-name "nndraft:drafts")
5318 (error "Can't encrypt the article in group nndraft:drafts."))
5319 (if (equal gnus-newsgroup-name "nndraft:queue")
5320 (error "Don't encrypt the article in group nndraft:queue."))
5321 (gnus-summary-iterate n
5323 (set-buffer gnus-summary-buffer)
5324 (let ((mail-parse-charset gnus-newsgroup-charset)
5325 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5326 (summary-buffer gnus-summary-buffer)
5328 (gnus-set-global-variables)
5329 (when (gnus-group-read-only-p)
5330 (error "The current newsgroup does not support article encrypt"))
5331 (gnus-summary-show-article t)
5333 (or (mail-header-references gnus-current-headers) ""))
5334 (set-buffer gnus-article-buffer)
5335 (let* ((buffer-read-only nil)
5337 (mapcar (lambda (field)
5338 (and (save-restriction
5339 (message-narrow-to-head)
5340 (goto-char (point-min))
5341 (search-forward field nil t))
5343 (message-narrow-to-field)
5344 (buffer-substring (point-min) (point-max))
5345 (delete-region (point-min) (point-max))
5347 '("Content-Type:" "Content-Transfer-Encoding:"
5348 "Content-Disposition:"))))
5349 (message-narrow-to-head)
5350 (message-remove-header "MIME-Version")
5351 (goto-char (point-max))
5352 (setq point (point))
5353 (insert (apply 'concat headers))
5355 (narrow-to-region point (point-max))
5356 (let ((message-options message-options))
5357 (message-options-set 'message-sender user-mail-address)
5358 (message-options-set 'message-recipients user-mail-address)
5359 (message-options-set 'message-sign-encrypt 'not)
5361 (goto-char (point-min))
5362 (insert "MIME-Version: 1.0\n")
5364 (gnus-summary-edit-article-done
5365 references nil summary-buffer t))
5366 (when gnus-keep-backlog
5367 (gnus-backlog-remove-article
5368 (car gnus-article-current) (cdr gnus-article-current)))
5370 (when (get-buffer gnus-original-article-buffer)
5371 (set-buffer gnus-original-article-buffer)
5372 (setq gnus-original-article nil)))
5373 (when gnus-use-cache
5374 (gnus-cache-update-article
5375 (car gnus-article-current) (cdr gnus-article-current))))))))
5377 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5378 "The following specs can be used:
5379 %t The security MIME type
5382 %D Details if button is pressed")
5384 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5385 "The following specs can be used:
5386 %t The security MIME type
5389 %D Details if button is pressed")
5391 (defvar gnus-mime-security-button-line-format-alist
5392 '((?t gnus-tmp-type ?s)
5393 (?i gnus-tmp-info ?s)
5394 (?d gnus-tmp-details ?s)
5395 (?D gnus-tmp-pressed-details ?s)))
5397 (defvar gnus-mime-security-button-map
5398 (let ((map (make-sparse-keymap)))
5399 (unless (>= (string-to-number emacs-version) 21)
5400 (set-keymap-parent map gnus-article-mode-map))
5401 (define-key map gnus-mouse-2 'gnus-article-push-button)
5402 (define-key map "\r" 'gnus-article-press-button)
5405 (defvar gnus-mime-security-details-buffer nil)
5407 (defvar gnus-mime-security-button-pressed nil)
5409 (defvar gnus-mime-security-show-details-inline t
5410 "If non-nil, show details in the article buffer.")
5412 (defun gnus-mime-security-verify-or-decrypt (handle)
5413 (mm-remove-parts (cdr handle))
5414 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5417 (delete-region (car region) (cdr region))
5418 (set-marker (car region) nil)
5419 (set-marker (cdr region) nil)))
5420 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5421 (let* ((mm-verify-option 'known)
5422 (mm-decrypt-option 'known)
5423 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5424 (unless (eq nparts (cdr handle))
5425 (mm-destroy-parts (cdr handle))
5426 (setcdr handle nparts))))
5427 (let ((point (point))
5429 (gnus-mime-display-security handle)
5432 (defun gnus-mime-security-show-details (handle)
5433 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5435 (if gnus-mime-security-show-details-inline
5436 (let ((gnus-mime-security-button-pressed t)
5437 (gnus-mime-security-button-line-format
5438 (get-text-property (point) 'gnus-line-format))
5441 (while (eq (get-text-property (point) 'gnus-line-format)
5442 gnus-mime-security-button-line-format)
5445 (delete-region (point)
5446 (or (text-property-not-all
5449 gnus-mime-security-button-line-format)
5451 (gnus-insert-mime-security-button handle))
5452 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5453 (with-current-buffer gnus-mime-security-details-buffer
5456 (setq gnus-mime-security-details-buffer
5457 (gnus-get-buffer-create "*MIME Security Details*")))
5458 (with-current-buffer gnus-mime-security-details-buffer
5460 (goto-char (point-min)))
5461 (pop-to-buffer gnus-mime-security-details-buffer))
5462 (gnus-message 5 "No details."))))
5464 (defun gnus-mime-security-press-button (handle)
5465 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5466 (gnus-mime-security-show-details handle)
5467 (gnus-mime-security-verify-or-decrypt handle)))
5469 (defun gnus-insert-mime-security-button (handle &optional displayed)
5470 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5473 (or (nth 2 (assoc protocol mm-verify-function-alist))
5474 (nth 2 (assoc protocol mm-decrypt-function-alist))
5476 (if (equal (car handle) "multipart/signed")
5477 " Signed" " Encrypted")
5480 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5483 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5484 gnus-tmp-pressed-details
5486 (setq gnus-tmp-details
5487 (if gnus-tmp-details
5488 (concat "\n" gnus-tmp-details) ""))
5489 (setq gnus-tmp-pressed-details
5490 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5495 gnus-mime-security-button-line-format
5496 gnus-mime-security-button-line-format-alist
5497 `(keymap ,gnus-mime-security-button-map
5498 ,@(if (>= (string-to-number emacs-version) 21)
5499 nil ;; XEmacs doesn't care
5500 (list 'local-map gnus-mime-security-button-map))
5501 gnus-callback gnus-mime-security-press-button
5502 gnus-line-format ,gnus-mime-security-button-line-format
5503 article-type annotation
5506 (widget-convert-button
5509 :action 'gnus-widget-press-button
5510 :button-keymap gnus-mime-security-button-map
5512 (lambda (widget/window &optional overlay pos)
5513 ;; Needed to properly clear the message due to a bug in
5514 ;; wid-edit (XEmacs only).
5515 (if (boundp 'help-echo-owns-message)
5516 (setq help-echo-owns-message t))
5519 (aref gnus-mouse-2 0))))))
5521 (defun gnus-mime-display-security (handle)
5523 (narrow-to-region (point) (point))
5524 (gnus-insert-mime-security-button handle)
5525 (gnus-mime-display-mixed (cdr handle))
5528 (let ((gnus-mime-security-button-line-format
5529 gnus-mime-security-button-end-line-format))
5530 (gnus-insert-mime-security-button handle))
5531 (mm-set-handle-multipart-parameter
5533 (cons (set-marker (make-marker) (point-min))
5534 (set-marker (make-marker) (point-max))))))
5540 (run-hooks 'gnus-art-load-hook)
5542 ;;; gnus-art.el ends here