1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
62 (defgroup gnus-article-signature nil
64 :link '(custom-manual "(gnus)Article Signature")
67 (defgroup gnus-article-headers nil
69 :link '(custom-manual "(gnus)Hiding Headers")
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
82 (defgroup gnus-article-saving nil
84 :link '(custom-manual "(gnus)Saving Articles")
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
102 (defcustom gnus-ignored-headers
103 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
104 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
105 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
106 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
107 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
108 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
109 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
110 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
111 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
112 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
113 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
114 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
115 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
116 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
117 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
120 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
121 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
122 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
123 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
124 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
125 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
126 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
127 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
128 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
129 "^X-Received:" "^Content-length:" "X-precedence:")
130 "*All headers that start with this regexp will be hidden.
131 This variable can also be a list of regexps of headers to be ignored.
132 If `gnus-visible-headers' is non-nil, this variable will be ignored."
133 :type '(choice :custom-show nil
136 :group 'gnus-article-hiding)
138 (defcustom gnus-visible-headers
139 "^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:"
140 "*All headers that do not match this regexp will be hidden.
141 This variable can also be a list of regexp of headers to remain visible.
142 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
143 :type '(repeat :value-to-internal (lambda (widget value)
144 (custom-split-regexp-maybe value))
145 :match (lambda (widget value)
147 (widget-editable-list-match widget value)))
149 :group 'gnus-article-hiding)
151 (defcustom gnus-sorted-header-list
152 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
153 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
154 "*This variable is a list of regular expressions.
155 If it is non-nil, headers that match the regular expressions will
156 be placed first in the article buffer in the sequence specified by
158 :type '(repeat regexp)
159 :group 'gnus-article-hiding)
161 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
162 "Headers that are only to be displayed if they have interesting data.
163 Possible values in this list are `empty', `newsgroups', `followup-to',
164 `reply-to', `date', `long-to', and `many-to'."
165 :type '(set (const :tag "Headers with no content." empty)
166 (const :tag "Newsgroups with only one group." newsgroups)
167 (const :tag "Followup-to identical to newsgroups." followup-to)
168 (const :tag "Reply-to identical to from." reply-to)
169 (const :tag "Date less than four days old." date)
170 (const :tag "Very long To and/or Cc header." long-to)
171 (const :tag "Multiple To and/or Cc headers." many-to))
172 :group 'gnus-article-hiding)
174 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
175 "Regexp matching signature separator.
176 This can also be a list of regexps. In that case, it will be checked
177 from head to tail looking for a separator. Searches will be done from
178 the end of the buffer."
179 :type '(repeat string)
180 :group 'gnus-article-signature)
182 (defcustom gnus-signature-limit nil
183 "Provide a limit to what is considered a signature.
184 If it is a number, no signature may not be longer (in characters) than
185 that number. If it is a floating point number, no signature may be
186 longer (in lines) than that number. If it is a function, the function
187 will be called without any parameters, and if it returns nil, there is
188 no signature in the buffer. If it is a string, it will be used as a
189 regexp. If it matches, the text in question is not a signature."
190 :type '(choice (integer :value 200)
192 (function :value fun)
193 (regexp :value ".*"))
194 :group 'gnus-article-signature)
196 (defcustom gnus-hidden-properties '(invisible t intangible t)
197 "Property list to use for hiding text."
199 :group 'gnus-article-hiding)
201 ;; Fixme: This isn't the right thing for mixed graphical and and
202 ;; non-graphical frames in a session.
203 ;; gnus-xmas.el overrides this for XEmacs.
204 (defcustom gnus-article-x-face-command
205 (if (and (fboundp 'image-type-available-p)
206 (image-type-available-p 'xbm))
207 'gnus-article-display-xface
208 (if gnus-article-compface-xbm
209 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
210 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
212 "*String or function to be executed to display an X-Face header.
213 If it is a string, the command will be executed in a sub-shell
214 asynchronously. The compressed face will be piped to this command."
215 :type '(choice string
216 (function-item gnus-article-display-xface)
218 :group 'gnus-article-washing)
220 (defcustom gnus-article-x-face-too-ugly nil
221 "Regexp matching posters whose face shouldn't be shown automatically."
222 :type '(choice regexp (const nil))
223 :group 'gnus-article-washing)
225 (defcustom gnus-article-banner-alist nil
226 "Banner alist for stripping.
228 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
230 :type '(repeat (cons symbol regexp))
231 :group 'gnus-article-washing)
233 (gnus-define-group-parameter
236 "Alist of regexps (to match group names) and banner."
237 :variable-group gnus-article-washing
239 '(choice :tag "Banner"
241 (const :tag "Remove signature" signature)
242 (symbol :tag "Item in `gnus-article-banner-alist'" none)
244 (const :tag "None" nil))
246 "If non-nil, specify how to remove `banners' from articles.
248 Symbol `signature' means to remove signatures delimited by
249 `gnus-signature-separator'. Any other symbol is used to look up a
250 regular expression to match the banner in `gnus-article-banner-alist'.
251 A string is used as a regular expression to match the banner
254 (defcustom gnus-emphasis-alist
256 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
258 '(("_" "_" underline)
261 ("_/" "/_" underline-italic)
262 ("_\\*" "\\*_" underline-bold)
263 ("\\*/" "/\\*" bold-italic)
264 ("_\\*/" "/\\*_" underline-bold-italic))))
265 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
266 2 3 gnus-emphasis-underline)
270 (format format (car spec) (cadr spec))
271 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
273 "*Alist that says how to fontify certain phrases.
274 Each item looks like this:
276 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
278 The first element is a regular expression to be matched. The second
279 is a number that says what regular expression grouping used to find
280 the entire emphasized word. The third is a number that says what
281 regexp grouping should be displayed and highlighted. The fourth
282 is the face used for highlighting."
283 :type '(repeat (list :value ("" 0 0 default)
285 (integer :tag "Match group")
286 (integer :tag "Emphasize group")
288 :group 'gnus-article-emphasis)
290 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
291 "A regexp to describe whitespace which should not be emphasized.
292 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
293 The former avoids underlining of leading and trailing whitespace,
294 and the latter avoids underlining any whitespace at all."
296 :group 'gnus-article-emphasis
299 (defface gnus-emphasis-bold '((t (:bold t)))
300 "Face used for displaying strong emphasized text (*word*)."
301 :group 'gnus-article-emphasis)
303 (defface gnus-emphasis-italic '((t (:italic t)))
304 "Face used for displaying italic emphasized text (/word/)."
305 :group 'gnus-article-emphasis)
307 (defface gnus-emphasis-underline '((t (:underline t)))
308 "Face used for displaying underlined emphasized text (_word_)."
309 :group 'gnus-article-emphasis)
311 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
312 "Face used for displaying underlined bold emphasized text (_*word*_)."
313 :group 'gnus-article-emphasis)
315 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
316 "Face used for displaying underlined italic emphasized text (_/word/_)."
317 :group 'gnus-article-emphasis)
319 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
320 "Face used for displaying bold italic emphasized text (/*word*/)."
321 :group 'gnus-article-emphasis)
323 (defface gnus-emphasis-underline-bold-italic
324 '((t (:bold t :italic t :underline t)))
325 "Face used for displaying underlined bold italic emphasized text.
326 Esample: (_/*word*/_)."
327 :group 'gnus-article-emphasis)
329 (defface gnus-emphasis-highlight-words
330 '((t (:background "black" :foreground "yellow")))
331 "Face used for displaying highlighted words."
332 :group 'gnus-article-emphasis)
334 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
335 "Format for display of Date headers in article bodies.
336 See `format-time-string' for the possible values.
338 The variable can also be function, which should return a complete Date
339 header. The function is called with one argument, the time, which can
340 be fed to `format-time-string'."
341 :type '(choice string symbol)
342 :link '(custom-manual "(gnus)Article Date")
343 :group 'gnus-article-washing)
346 (autoload 'mail-extract-address-components "mail-extr"))
348 (defcustom gnus-save-all-headers t
349 "*If non-nil, don't remove any headers before saving."
350 :group 'gnus-article-saving
353 (defcustom gnus-prompt-before-saving 'always
354 "*This variable says how much prompting is to be done when saving articles.
355 If it is nil, no prompting will be done, and the articles will be
356 saved to the default files. If this variable is `always', each and
357 every article that is saved will be preceded by a prompt, even when
358 saving large batches of articles. If this variable is neither nil not
359 `always', there the user will be prompted once for a file name for
360 each invocation of the saving commands."
361 :group 'gnus-article-saving
362 :type '(choice (item always)
363 (item :tag "never" nil)
364 (sexp :tag "once" :format "%t\n" :value t)))
366 (defcustom gnus-saved-headers gnus-visible-headers
367 "Headers to keep if `gnus-save-all-headers' is nil.
368 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
369 If that variable is nil, however, all headers that match this regexp
370 will be kept while the rest will be deleted before saving."
371 :group 'gnus-article-saving
374 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
375 "A function to save articles in your favourite format.
376 The function must be interactively callable (in other words, it must
377 be an Emacs command).
379 Gnus provides the following functions:
381 * gnus-summary-save-in-rmail (Rmail format)
382 * gnus-summary-save-in-mail (Unix mail format)
383 * gnus-summary-save-in-folder (MH folder)
384 * gnus-summary-save-in-file (article format)
385 * gnus-summary-save-in-vm (use VM's folder format)
386 * gnus-summary-write-to-file (article format -- overwrite)."
387 :group 'gnus-article-saving
388 :type '(radio (function-item gnus-summary-save-in-rmail)
389 (function-item gnus-summary-save-in-mail)
390 (function-item gnus-summary-save-in-folder)
391 (function-item gnus-summary-save-in-file)
392 (function-item gnus-summary-save-in-vm)
393 (function-item gnus-summary-write-to-file)))
395 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
396 "A function generating a file name to save articles in Rmail format.
397 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
398 :group 'gnus-article-saving
401 (defcustom gnus-mail-save-name 'gnus-plain-save-name
402 "A function generating a file name to save articles in Unix mail format.
403 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
404 :group 'gnus-article-saving
407 (defcustom gnus-folder-save-name 'gnus-folder-save-name
408 "A function generating a file name to save articles in MH folder.
409 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
410 :group 'gnus-article-saving
413 (defcustom gnus-file-save-name 'gnus-numeric-save-name
414 "A function generating a file name to save articles in article format.
415 The function is called with NEWSGROUP, HEADERS, and optional
417 :group 'gnus-article-saving
420 (defcustom gnus-split-methods
421 '((gnus-article-archive-name)
422 (gnus-article-nndoc-name))
423 "*Variable used to suggest where articles are to be saved.
424 For instance, if you would like to save articles related to Gnus in
425 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
426 you could set this variable to something like:
428 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
429 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
431 This variable is an alist where the where the key is the match and the
432 value is a list of possible files to save in if the match is non-nil.
434 If the match is a string, it is used as a regexp match on the
435 article. If the match is a symbol, that symbol will be funcalled
436 from the buffer of the article to be saved with the newsgroup as the
437 parameter. If it is a list, it will be evaled in the same buffer.
439 If this form or function returns a string, this string will be used as
440 a possible file name; and if it returns a non-nil list, that list will
441 be used as possible file names."
442 :group 'gnus-article-saving
443 :type '(repeat (choice (list :value (fun) function)
444 (cons :value ("" "") regexp (repeat string))
447 (defcustom gnus-page-delimiter "^\^L"
448 "*Regexp describing what to use as article page delimiters.
449 The default value is \"^\^L\", which is a form linefeed at the
450 beginning of a line."
452 :group 'gnus-article-various)
454 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
455 "*The format specification for the article mode line.
456 See `gnus-summary-mode-line-format' for a closer description.
458 The following additional specs are available:
460 %w The article washing status.
461 %m The number of MIME parts in the article."
463 :group 'gnus-article-various)
465 (defcustom gnus-article-mode-hook nil
466 "*A hook for Gnus article mode."
468 :group 'gnus-article-various)
470 (defcustom gnus-article-menu-hook nil
471 "*Hook run after the creation of the article mode menu."
473 :group 'gnus-article-various)
475 (defcustom gnus-article-prepare-hook nil
476 "*A hook called after an article has been prepared in the article buffer."
478 :group 'gnus-article-various)
480 (defcustom gnus-article-hide-pgp-hook nil
481 "*A hook called after successfully hiding a PGP signature."
483 :group 'gnus-article-various)
485 (defcustom gnus-article-button-face 'bold
486 "Face used for highlighting buttons in the article buffer.
488 An article button is a piece of text that you can activate by pressing
489 `RET' or `mouse-2' above it."
491 :group 'gnus-article-buttons)
493 (defcustom gnus-article-mouse-face 'highlight
494 "Face used for mouse highlighting in the article buffer.
496 Article buttons will be displayed in this face when the cursor is
499 :group 'gnus-article-buttons)
501 (defcustom gnus-signature-face 'gnus-signature-face
502 "Face used for highlighting a signature in the article buffer.
503 Obsolete; use the face `gnus-signature-face' for customizations instead."
505 :group 'gnus-article-highlight
506 :group 'gnus-article-signature)
508 (defface gnus-signature-face
511 "Face used for highlighting a signature in the article buffer."
512 :group 'gnus-article-highlight
513 :group 'gnus-article-signature)
515 (defface gnus-header-from-face
518 (:foreground "spring green"))
521 (:foreground "red3"))
524 "Face used for displaying from headers."
525 :group 'gnus-article-headers
526 :group 'gnus-article-highlight)
528 (defface gnus-header-subject-face
531 (:foreground "SeaGreen3"))
534 (:foreground "red4"))
536 (:bold t :italic t)))
537 "Face used for displaying subject headers."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight)
541 (defface gnus-header-newsgroups-face
544 (:foreground "yellow" :italic t))
547 (:foreground "MidnightBlue" :italic t))
550 "Face used for displaying newsgroups headers."
551 :group 'gnus-article-headers
552 :group 'gnus-article-highlight)
554 (defface gnus-header-name-face
557 (:foreground "SeaGreen"))
560 (:foreground "maroon"))
563 "Face used for displaying header names."
564 :group 'gnus-article-headers
565 :group 'gnus-article-highlight)
567 (defface gnus-header-content-face
570 (:foreground "forest green" :italic t))
573 (:foreground "indianred4" :italic t))
575 (:italic t))) "Face used for displaying header content."
576 :group 'gnus-article-headers
577 :group 'gnus-article-highlight)
579 (defcustom gnus-header-face-alist
580 '(("From" nil gnus-header-from-face)
581 ("Subject" nil gnus-header-subject-face)
582 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
583 ("" gnus-header-name-face gnus-header-content-face))
584 "*Controls highlighting of article header.
586 An alist of the form (HEADER NAME CONTENT).
588 HEADER is a regular expression which should match the name of an
589 header header and NAME and CONTENT are either face names or nil.
591 The name of each header field will be displayed using the face
592 specified by the first element in the list where HEADER match the
593 header name and NAME is non-nil. Similarly, the content will be
594 displayed by the first non-nil matching CONTENT face."
595 :group 'gnus-article-headers
596 :group 'gnus-article-highlight
597 :type '(repeat (list (regexp :tag "Header")
599 (item :tag "skip" nil)
600 (face :value default))
601 (choice :tag "Content"
602 (item :tag "skip" nil)
603 (face :value default)))))
605 (defcustom gnus-article-decode-hook
606 '(article-decode-charset article-decode-encoded-words)
607 "*Hook run to decode charsets in articles."
608 :group 'gnus-article-headers
611 (defcustom gnus-display-mime-function 'gnus-display-mime
612 "Function to display MIME articles."
613 :group 'gnus-article-mime
616 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
617 "Function used to decode headers.")
619 (defvar gnus-article-dumbquotes-map
638 "Table for MS-to-Latin1 translation.")
640 (defcustom gnus-ignored-mime-types nil
641 "List of MIME types that should be ignored by Gnus."
643 :group 'gnus-article-mime
644 :type '(repeat regexp))
646 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
647 "List of MIME types that should not be given buttons when rendered inline."
649 :group 'gnus-article-mime
650 :type '(repeat regexp))
652 (defcustom gnus-article-mime-part-function nil
653 "Function called with a MIME handle as the argument.
654 This is meant for people who want to do something automatic based
655 on parts -- for instance, adding Vcard info to a database."
656 :group 'gnus-article-mime
659 (defcustom gnus-mime-multipart-functions nil
660 "An alist of MIME types to functions to display them."
662 :group 'gnus-article-mime
665 (defcustom gnus-article-date-lapsed-new-header nil
666 "Whether the X-Sent and Date headers can coexist.
667 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
668 either replace the old \"Date:\" header (if this variable is nil), or
669 be added below it (otherwise)."
671 :group 'gnus-article-headers
674 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
675 "Function called with a MIME handle as the argument.
676 This is meant for people who want to view first matched part.
677 For `undisplayed-alternative' (default), the first undisplayed
678 part or alternative part is used. For `undisplayed', the first
679 undisplayed part is used. For a function, the first part which
680 the function return `t' is used. For `nil', the first part is
683 :group 'gnus-article-mime
685 (item :tag "first" :value nil)
686 (item :tag "undisplayed" :value undisplayed)
687 (item :tag "undisplayed or alternative"
688 :value undisplayed-alternative)
691 (defcustom gnus-mime-action-alist
692 '(("save to file" . gnus-mime-save-part)
693 ("save and strip" . gnus-mime-save-part-and-strip)
694 ("display as text" . gnus-mime-inline-part)
695 ("view the part" . gnus-mime-view-part)
696 ("pipe to command" . gnus-mime-pipe-part)
697 ("toggle display" . gnus-article-press-button)
698 ("toggle display" . gnus-article-view-part-as-charset)
699 ("view as type" . gnus-mime-view-part-as-type)
700 ("internalize type" . gnus-mime-internalize-part)
701 ("externalize type" . gnus-mime-externalize-part))
702 "An alist of actions that run on the MIME attachment."
703 :group 'gnus-article-mime
704 :type '(repeat (cons (string :tag "name")
707 (defcustom gnus-mime-action-alist
708 '(("save to file" . gnus-mime-save-part)
709 ("display as text" . gnus-mime-inline-part)
710 ("view the part" . gnus-mime-view-part)
711 ("pipe to command" . gnus-mime-pipe-part)
712 ("toggle display" . gnus-article-press-button)
713 ("view as type" . gnus-mime-view-part-as-type)
714 ("internalize type" . gnus-mime-internalize-part)
715 ("externalize type" . gnus-mime-externalize-part))
716 "An alist of actions that run on the MIME attachment."
718 :group 'gnus-article-mime
719 :type '(repeat (cons (string :tag "name")
723 ;;; The treatment variables
726 (defvar gnus-part-display-hook nil
727 "Hook called on parts that are to receive treatment.")
729 (defvar gnus-article-treat-custom
730 '(choice (const :tag "Off" nil)
732 (const :tag "Header" head)
733 (const :tag "Last" last)
734 (integer :tag "Less")
735 (repeat :tag "Groups" regexp)
736 (sexp :tag "Predicate")))
738 (defvar gnus-article-treat-head-custom
739 '(choice (const :tag "Off" nil)
740 (const :tag "Header" head)))
742 (defvar gnus-article-treat-types '("text/plain")
745 (defvar gnus-inhibit-treatment nil
746 "Whether to inhibit treatment.")
748 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
749 "Highlight the signature.
750 Valid values are nil, t, `head', `last', an integer or a predicate.
751 See the manual for details."
752 :group 'gnus-article-treat
753 :type gnus-article-treat-custom)
754 (put 'gnus-treat-highlight-signature 'highlight t)
756 (defcustom gnus-treat-buttonize 100000
758 Valid values are nil, t, `head', `last', an integer or a predicate.
759 See the manual for details."
760 :group 'gnus-article-treat
761 :type gnus-article-treat-custom)
762 (put 'gnus-treat-buttonize 'highlight t)
764 (defcustom gnus-treat-buttonize-head 'head
765 "Add buttons to the head.
766 Valid values are nil, t, `head', `last', an integer or a predicate.
767 See the manual for details."
768 :group 'gnus-article-treat
769 :type gnus-article-treat-head-custom)
770 (put 'gnus-treat-buttonize-head 'highlight t)
772 (defcustom gnus-treat-emphasize
773 (and (or window-system
775 (>= (string-to-number emacs-version) 21))
778 Valid values are nil, t, `head', `last', an integer or a predicate.
779 See the manual for details."
780 :group 'gnus-article-treat
781 :type gnus-article-treat-custom)
782 (put 'gnus-treat-emphasize 'highlight t)
784 (defcustom gnus-treat-strip-cr nil
785 "Remove carriage returns.
786 Valid values are nil, t, `head', `last', an integer or a predicate.
787 See the manual for details."
788 :group 'gnus-article-treat
789 :type gnus-article-treat-custom)
791 (defcustom gnus-treat-hide-headers 'head
793 Valid values are nil, t, `head', `last', an integer or a predicate.
794 See the manual for details."
795 :group 'gnus-article-treat
796 :type gnus-article-treat-head-custom)
798 (defcustom gnus-treat-hide-boring-headers nil
799 "Hide boring headers.
800 Valid values are nil, t, `head', `last', an integer or a predicate.
801 See the manual for details."
802 :group 'gnus-article-treat
803 :type gnus-article-treat-head-custom)
805 (defcustom gnus-treat-hide-signature nil
807 Valid values are nil, t, `head', `last', an integer or a predicate.
808 See the manual for details."
809 :group 'gnus-article-treat
810 :type gnus-article-treat-custom)
812 (defcustom gnus-treat-fill-article nil
814 Valid values are nil, t, `head', `last', an integer or a predicate.
815 See the manual for details."
816 :group 'gnus-article-treat
817 :type gnus-article-treat-custom)
819 (defcustom gnus-treat-hide-citation nil
821 Valid values are nil, t, `head', `last', an integer or a predicate.
822 See the manual for details."
823 :group 'gnus-article-treat
824 :type gnus-article-treat-custom)
826 (defcustom gnus-treat-hide-citation-maybe nil
828 Valid values are nil, t, `head', `last', an integer or a predicate.
829 See the manual for details."
830 :group 'gnus-article-treat
831 :type gnus-article-treat-custom)
833 (defcustom gnus-treat-hide-citation-maybe nil
835 Valid values are nil, t, `head', `last', an integer or a predicate.
836 See the manual for details."
837 :group 'gnus-article-treat
838 :type gnus-article-treat-custom)
840 (defcustom gnus-treat-strip-list-identifiers 'head
841 "Strip list identifiers from `gnus-list-identifiers`.
842 Valid values are nil, t, `head', `last', an integer or a predicate.
843 See the manual for details."
845 :group 'gnus-article-treat
846 :type gnus-article-treat-custom)
848 (defcustom gnus-treat-strip-pgp t
849 "Strip PGP signatures.
850 Valid values are nil, t, `head', `last', an integer or a predicate.
851 See the manual for details."
852 :group 'gnus-article-treat
853 :type gnus-article-treat-custom)
855 (defcustom gnus-treat-strip-pem nil
856 "Strip PEM signatures.
857 Valid values are nil, t, `head', `last', an integer or a predicate.
858 See the manual for details."
859 :group 'gnus-article-treat
860 :type gnus-article-treat-custom)
862 (defcustom gnus-treat-strip-banner t
863 "Strip banners from articles.
864 The banner to be stripped is specified in the `banner' group parameter.
865 Valid values are nil, t, `head', `last', an integer or a predicate.
866 See the manual for details."
867 :group 'gnus-article-treat
868 :type gnus-article-treat-custom)
870 (defcustom gnus-treat-highlight-headers 'head
871 "Highlight the headers.
872 Valid values are nil, t, `head', `last', an integer or a predicate.
873 See the manual for details."
874 :group 'gnus-article-treat
875 :type gnus-article-treat-head-custom)
876 (put 'gnus-treat-highlight-headers 'highlight t)
878 (defcustom gnus-treat-highlight-citation t
879 "Highlight cited text.
880 Valid values are nil, t, `head', `last', an integer or a predicate.
881 See the manual for details."
882 :group 'gnus-article-treat
883 :type gnus-article-treat-custom)
884 (put 'gnus-treat-highlight-citation 'highlight t)
886 (defcustom gnus-treat-date-ut nil
887 "Display the Date in UT (GMT).
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-head-custom)
893 (defcustom gnus-treat-date-local nil
894 "Display the Date in the local timezone.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-head-custom)
900 (defcustom gnus-treat-date-lapsed nil
901 "Display the Date header in a way that says how much time has elapsed.
902 Valid values are nil, t, `head', `last', an integer or a predicate.
903 See the manual for details."
904 :group 'gnus-article-treat
905 :type gnus-article-treat-head-custom)
907 (defcustom gnus-treat-date-original nil
908 "Display the date in the original timezone.
909 Valid values are nil, t, `head', `last', an integer or a predicate.
910 See the manual for details."
911 :group 'gnus-article-treat
912 :type gnus-article-treat-head-custom)
914 (defcustom gnus-treat-date-iso8601 nil
915 "Display the date in the ISO8601 format.
916 Valid values are nil, t, `head', `last', an integer or a predicate.
917 See the manual for details."
919 :group 'gnus-article-treat
920 :type gnus-article-treat-head-custom)
922 (defcustom gnus-treat-date-user-defined nil
923 "Display the date in a user-defined format.
924 The format is defined by the `gnus-article-time-format' variable.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-head-custom)
930 (defcustom gnus-treat-strip-headers-in-body t
931 "Strip the X-No-Archive header line from the beginning of the body.
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
935 :group 'gnus-article-treat
936 :type gnus-article-treat-custom)
938 (defcustom gnus-treat-strip-trailing-blank-lines nil
939 "Strip trailing blank lines.
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-custom)
945 (defcustom gnus-treat-strip-leading-blank-lines nil
946 "Strip leading blank lines.
947 Valid values are nil, t, `head', `last', an integer or a predicate.
948 See the manual for details."
949 :group 'gnus-article-treat
950 :type gnus-article-treat-custom)
952 (defcustom gnus-treat-strip-multiple-blank-lines nil
953 "Strip multiple blank lines.
954 Valid values are nil, t, `head', `last', an integer or a predicate.
955 See the manual for details."
956 :group 'gnus-article-treat
957 :type gnus-article-treat-custom)
959 (defcustom gnus-treat-overstrike t
960 "Treat overstrike highlighting.
961 Valid values are nil, t, `head', `last', an integer or a predicate.
962 See the manual for details."
963 :group 'gnus-article-treat
964 :type gnus-article-treat-custom)
965 (put 'gnus-treat-overstrike 'highlight t)
967 (defcustom gnus-treat-display-xface
968 (and (or (and (fboundp 'image-type-available-p)
969 (image-type-available-p 'xbm)
970 (string-match "^0x" (shell-command-to-string "uncompface")))
971 (and (featurep 'xemacs) (featurep 'xface)))
973 "Display X-Face headers.
974 Valid values are nil, t, `head', `last', an integer or a predicate.
975 See the manual for details."
976 :group 'gnus-article-treat
977 :type gnus-article-treat-head-custom)
978 (put 'gnus-treat-display-xface 'highlight t)
980 (defcustom gnus-treat-display-smileys
981 (if (or (and (featurep 'xemacs)
983 (and (fboundp 'image-type-available-p)
984 (image-type-available-p 'pbm)))
987 Valid values are nil, t, `head', `last', an integer or a predicate.
988 See the manual for details."
989 :group 'gnus-article-treat
990 :type gnus-article-treat-custom)
991 (put 'gnus-treat-display-smileys 'highlight t)
993 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
995 Valid values are nil, t, `head', `last', an integer or a predicate.
996 See the manual for details."
997 :group 'gnus-article-treat
998 :type gnus-article-treat-head-custom)
999 (put 'gnus-treat-display-picons 'highlight t)
1001 (defcustom gnus-treat-capitalize-sentences nil
1002 "Capitalize sentence-starting words.
1003 Valid values are nil, t, `head', `last', an integer or a predicate.
1004 See the manual for details."
1006 :group 'gnus-article-treat
1007 :type gnus-article-treat-custom)
1009 (defcustom gnus-treat-fill-long-lines nil
1011 Valid values are nil, t, `head', `last', an integer or a predicate.
1012 See the manual for details."
1013 :group 'gnus-article-treat
1014 :type gnus-article-treat-custom)
1016 (defcustom gnus-treat-play-sounds nil
1018 Valid values are nil, t, `head', `last', an integer or a predicate.
1019 See the manual for details."
1021 :group 'gnus-article-treat
1022 :type gnus-article-treat-custom)
1024 (defcustom gnus-treat-translate nil
1025 "Translate articles from one language to another.
1026 Valid values are nil, t, `head', `last', an integer or a predicate.
1027 See the manual for details."
1029 :group 'gnus-article-treat
1030 :type gnus-article-treat-custom)
1032 (defcustom gnus-treat-x-pgp-sig nil
1034 To automatically treat X-PGP-Sig, set it to head.
1035 Valid values are nil, t, `head', `last', an integer or a predicate.
1036 See the manual for details."
1037 :group 'gnus-article-treat
1038 :group 'mime-security
1039 :type gnus-article-treat-custom)
1041 (defvar gnus-article-encrypt-protocol-alist
1042 '(("PGP" . mml2015-self-encrypt)))
1044 ;; Set to nil if more than one protocol added to
1045 ;; gnus-article-encrypt-protocol-alist.
1046 (defcustom gnus-article-encrypt-protocol "PGP"
1047 "The protocol used for encrypt articles.
1048 It is a string, such as \"PGP\". If nil, ask user."
1050 :group 'mime-security)
1052 ;;; Internal variables
1054 (defvar article-goto-body-goes-to-point-min-p nil)
1055 (defvar gnus-article-wash-types nil)
1056 (defvar gnus-article-emphasis-alist nil)
1058 (defvar gnus-article-mime-handle-alist-1 nil)
1059 (defvar gnus-treatment-function-alist
1060 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1061 (gnus-treat-strip-banner gnus-article-strip-banner)
1062 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1063 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1064 (gnus-treat-buttonize gnus-article-add-buttons)
1065 (gnus-treat-fill-article gnus-article-fill-cited-article)
1066 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1067 (gnus-treat-strip-cr gnus-article-remove-cr)
1068 (gnus-treat-emphasize gnus-article-emphasize)
1069 (gnus-treat-display-xface gnus-article-display-x-face)
1070 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1071 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1072 (gnus-treat-hide-signature gnus-article-hide-signature)
1073 (gnus-treat-hide-citation gnus-article-hide-citation)
1074 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1075 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1076 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1077 (gnus-treat-strip-pem gnus-article-hide-pem)
1078 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1079 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1080 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1081 (gnus-treat-date-ut gnus-article-date-ut)
1082 (gnus-treat-date-local gnus-article-date-local)
1083 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1084 (gnus-treat-date-original gnus-article-date-original)
1085 (gnus-treat-date-user-defined gnus-article-date-user)
1086 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1087 (gnus-treat-strip-trailing-blank-lines
1088 gnus-article-remove-trailing-blank-lines)
1089 (gnus-treat-strip-leading-blank-lines
1090 gnus-article-strip-leading-blank-lines)
1091 (gnus-treat-strip-multiple-blank-lines
1092 gnus-article-strip-multiple-blank-lines)
1093 (gnus-treat-overstrike gnus-article-treat-overstrike)
1094 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1095 (gnus-treat-display-smileys gnus-smiley-display)
1096 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1097 (gnus-treat-display-picons gnus-article-display-picons)
1098 (gnus-treat-play-sounds gnus-earcon-display)))
1100 (defvar gnus-article-mime-handle-alist nil)
1101 (defvar article-lapsed-timer nil)
1102 (defvar gnus-article-current-summary nil)
1104 (defvar gnus-article-mode-syntax-table
1105 (let ((table (copy-syntax-table text-mode-syntax-table)))
1106 ;; This causes the citation match run O(2^n).
1107 ;; (modify-syntax-entry ?- "w" table)
1108 (modify-syntax-entry ?> ")" table)
1109 (modify-syntax-entry ?< "(" table)
1111 "Syntax table used in article mode buffers.
1112 Initialized from `text-mode-syntax-table.")
1114 (defvar gnus-save-article-buffer nil)
1116 (defvar gnus-article-mode-line-format-alist
1117 (nconc '((?w (gnus-article-wash-status) ?s)
1118 (?m (gnus-article-mime-part-status) ?s))
1119 gnus-summary-mode-line-format-alist))
1121 (defvar gnus-number-of-articles-to-be-saved nil)
1123 (defvar gnus-inhibit-hiding nil)
1125 (defsubst gnus-article-hide-text (b e props)
1126 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1127 (gnus-add-text-properties-when 'article-type nil b e props)
1128 (when (memq 'intangible props)
1130 (max (1- b) (point-min))
1131 b 'intangible (cddr (memq 'intangible props)))))
1133 (defsubst gnus-article-unhide-text (b e)
1134 "Remove hidden text properties from region between B and E."
1135 (remove-text-properties b e gnus-hidden-properties)
1136 (when (memq 'intangible gnus-hidden-properties)
1137 (put-text-property (max (1- b) (point-min))
1138 b 'intangible nil)))
1140 (defun gnus-article-hide-text-type (b e type)
1141 "Hide text of TYPE between B and E."
1142 (push type gnus-article-wash-types)
1143 (gnus-article-hide-text
1144 b e (cons 'article-type (cons type gnus-hidden-properties))))
1146 (defun gnus-article-unhide-text-type (b e type)
1147 "Unhide text of TYPE between B and E."
1148 (setq gnus-article-wash-types
1149 (delq type gnus-article-wash-types))
1150 (remove-text-properties
1151 b e (cons 'article-type (cons type gnus-hidden-properties)))
1152 (when (memq 'intangible gnus-hidden-properties)
1153 (put-text-property (max (1- b) (point-min))
1154 b 'intangible nil)))
1156 (defun gnus-article-hide-text-of-type (type)
1157 "Hide text of TYPE in the current buffer."
1159 (let ((b (point-min))
1161 (while (setq b (text-property-any b e 'article-type type))
1162 (add-text-properties b (incf b) gnus-hidden-properties)))))
1164 (defun gnus-article-delete-text-of-type (type)
1165 "Delete text of TYPE in the current buffer."
1167 (let ((b (point-min)))
1168 (while (setq b (text-property-any b (point-max) 'article-type type))
1170 b (or (text-property-not-all b (point-max) 'article-type type)
1173 (defun gnus-article-delete-invisible-text ()
1174 "Delete all invisible text in the current buffer."
1176 (let ((b (point-min)))
1177 (while (setq b (text-property-any b (point-max) 'invisible t))
1179 b (or (text-property-not-all b (point-max) 'invisible t)
1182 (defun gnus-article-text-type-exists-p (type)
1183 "Say whether any text of type TYPE exists in the buffer."
1184 (text-property-any (point-min) (point-max) 'article-type type))
1186 (defsubst gnus-article-header-rank ()
1187 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1188 (let ((list gnus-sorted-header-list)
1191 (when (looking-at (car list))
1193 (setq list (cdr list))
1197 (defun article-hide-headers (&optional arg delete)
1198 "Hide unwanted headers and possibly sort them as well."
1200 ;; This function might be inhibited.
1201 (unless gnus-inhibit-hiding
1204 (let ((buffer-read-only nil)
1205 (case-fold-search t)
1206 (max (1+ (length gnus-sorted-header-list)))
1207 (ignored (when (not gnus-visible-headers)
1208 (cond ((stringp gnus-ignored-headers)
1209 gnus-ignored-headers)
1210 ((listp gnus-ignored-headers)
1211 (mapconcat 'identity gnus-ignored-headers
1214 (cond ((stringp gnus-visible-headers)
1215 gnus-visible-headers)
1216 ((and gnus-visible-headers
1217 (listp gnus-visible-headers))
1218 (mapconcat 'identity gnus-visible-headers "\\|"))))
1219 (inhibit-point-motion-hooks t)
1221 ;; First we narrow to just the headers.
1222 (article-narrow-to-head)
1223 ;; Hide any "From " lines at the beginning of (mail) articles.
1224 (while (looking-at "From ")
1227 (delete-region (point-min) (point)))
1228 ;; Then treat the rest of the header lines.
1229 ;; Then we use the two regular expressions
1230 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1231 ;; select which header lines is to remain visible in the
1233 (while (re-search-forward "^[^ \t]*:" nil t)
1235 ;; Mark the rank of the header.
1237 (point) (1+ (point)) 'message-rank
1238 (if (or (and visible (looking-at visible))
1240 (not (looking-at ignored))))
1241 (gnus-article-header-rank)
1244 (message-sort-headers-1)
1245 (when (setq beg (text-property-any
1246 (point-min) (point-max) 'message-rank (+ 2 max)))
1247 ;; We delete the unwanted headers.
1248 (push 'headers gnus-article-wash-types)
1249 (add-text-properties (point-min) (+ 5 (point-min))
1250 '(article-type headers dummy-invisible t))
1251 (delete-region beg (point-max))))))))
1253 (defun article-hide-boring-headers (&optional arg)
1254 "Toggle hiding of headers that aren't very interesting.
1255 If given a negative prefix, always show; if given a positive prefix,
1257 (interactive (gnus-article-hidden-arg))
1258 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1259 (not gnus-show-all-headers))
1262 (let ((buffer-read-only nil)
1263 (list gnus-boring-article-headers)
1264 (inhibit-point-motion-hooks t)
1266 (article-narrow-to-head)
1268 (setq elem (pop list))
1269 (goto-char (point-min))
1271 ;; Hide empty headers.
1273 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1275 (gnus-article-hide-text-type
1276 (progn (beginning-of-line) (point))
1279 (if (re-search-forward "^[^ \t]" nil t)
1283 ;; Hide boring Newsgroups header.
1284 ((eq elem 'newsgroups)
1285 (when (equal (gnus-fetch-field "newsgroups")
1286 (gnus-group-real-name
1287 (if (boundp 'gnus-newsgroup-name)
1290 (gnus-article-hide-header "newsgroups")))
1291 ((eq elem 'followup-to)
1292 (when (equal (message-fetch-field "followup-to")
1293 (message-fetch-field "newsgroups"))
1294 (gnus-article-hide-header "followup-to")))
1295 ((eq elem 'reply-to)
1296 (let ((from (message-fetch-field "from"))
1297 (reply-to (message-fetch-field "reply-to")))
1302 (nth 1 (mail-extract-address-components from))
1303 (nth 1 (mail-extract-address-components reply-to)))))
1304 (gnus-article-hide-header "reply-to"))))
1306 (let ((date (message-fetch-field "date")))
1308 (< (days-between (current-time-string) date)
1310 (gnus-article-hide-header "date"))))
1312 (let ((to (message-fetch-field "to"))
1313 (cc (message-fetch-field "cc")))
1314 (when (> (length to) 1024)
1315 (gnus-article-hide-header "to"))
1316 (when (> (length cc) 1024)
1317 (gnus-article-hide-header "cc"))))
1321 (goto-char (point-min))
1322 (while (re-search-forward "^to:" nil t)
1323 (setq to-count (1+ to-count)))
1324 (when (> to-count 1)
1325 (while (> to-count 0)
1326 (goto-char (point-min))
1328 (re-search-forward "^to:" nil nil to-count)
1330 (narrow-to-region (point) (point-max))
1331 (gnus-article-hide-header "to"))
1332 (setq to-count (1- to-count))))
1333 (goto-char (point-min))
1334 (while (re-search-forward "^cc:" nil t)
1335 (setq cc-count (1+ cc-count)))
1336 (when (> cc-count 1)
1337 (while (> cc-count 0)
1338 (goto-char (point-min))
1340 (re-search-forward "^cc:" nil nil cc-count)
1342 (narrow-to-region (point) (point-max))
1343 (gnus-article-hide-header "cc"))
1344 (setq cc-count (1- cc-count)))))))))))))
1346 (defun gnus-article-hide-header (header)
1348 (goto-char (point-min))
1349 (when (re-search-forward (concat "^" header ":") nil t)
1350 (gnus-article-hide-text-type
1351 (progn (beginning-of-line) (point))
1354 (if (re-search-forward "^[^ \t]" nil t)
1359 (defvar gnus-article-normalized-header-length 40
1360 "Length of normalized headers.")
1362 (defun article-normalize-headers ()
1363 "Make all header lines 40 characters long."
1365 (let ((buffer-read-only nil)
1369 (article-narrow-to-head)
1372 ((< (setq column (- (gnus-point-at-eol) (point)))
1373 gnus-article-normalized-header-length)
1375 (insert (make-string
1376 (- gnus-article-normalized-header-length column)
1378 ((> column gnus-article-normalized-header-length)
1379 (gnus-put-text-property
1381 (forward-char gnus-article-normalized-header-length)
1388 (forward-line 1))))))
1390 (defun article-treat-dumbquotes ()
1391 "Translate M****s*** sm*rtq**t*s into proper text.
1392 Note that this function guesses whether a character is a sm*rtq**t* or
1393 not, so it should only be used interactively.
1395 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1396 in an attempt to provide more quoting characters. If you see
1397 something like \\222 or \\264 where you're expecting some kind of
1398 apostrophe or quotation mark, then try this wash."
1400 (article-translate-strings gnus-article-dumbquotes-map))
1402 (defun article-translate-characters (from to)
1403 "Translate all characters in the body of the article according to FROM and TO.
1404 FROM is a string of characters to translate from; to is a string of
1405 characters to translate to."
1407 (when (article-goto-body)
1408 (let ((buffer-read-only nil)
1409 (x (make-string 225 ?x))
1411 (while (< (incf i) (length x))
1414 (while (< i (length from))
1415 (aset x (aref from i) (aref to i))
1417 (translate-region (point) (point-max) x)))))
1419 (defun article-translate-strings (map)
1420 "Translate all string in the body of the article according to MAP.
1421 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1423 (when (article-goto-body)
1424 (let ((buffer-read-only nil)
1426 (while (setq elem (pop map))
1428 (while (search-forward (car elem) nil t)
1429 (replace-match (cadr elem)))))))))
1431 (defun article-treat-overstrike ()
1432 "Translate overstrikes into bold text."
1435 (when (article-goto-body)
1436 (let ((buffer-read-only nil))
1437 (while (search-forward "\b" nil t)
1438 (let ((next (char-after))
1439 (previous (char-after (- (point) 2))))
1440 ;; We do the boldification/underlining by hiding the
1441 ;; overstrikes and putting the proper text property
1445 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1446 (put-text-property (point) (1+ (point)) 'face 'bold))
1448 (gnus-article-hide-text-type
1449 (1- (point)) (1+ (point)) 'overstrike)
1451 (- (point) 2) (1- (point)) 'face 'underline))
1453 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1455 (point) (1+ (point)) 'face 'underline)))))))))
1457 (defun article-fill-long-lines ()
1458 "Fill lines that are wider than the window width."
1461 (let ((buffer-read-only nil)
1462 (width (window-width (get-buffer-window (current-buffer)))))
1465 (let ((adaptive-fill-mode nil))
1468 (when (>= (current-column) (min fill-column width))
1469 (narrow-to-region (point) (gnus-point-at-bol))
1470 (fill-paragraph nil)
1471 (goto-char (point-max))
1473 (forward-line 1)))))))
1475 (defun article-capitalize-sentences ()
1476 "Capitalize the first word in each sentence."
1479 (let ((buffer-read-only nil)
1480 (paragraph-start "^[\n\^L]"))
1484 (forward-sentence)))))
1486 (defun article-remove-cr ()
1487 "Remove trailing CRs and then translate remaining CRs into LFs."
1490 (let ((buffer-read-only nil))
1491 (goto-char (point-min))
1492 (while (re-search-forward "\r+$" nil t)
1493 (replace-match "" t t))
1494 (goto-char (point-min))
1495 (while (search-forward "\r" nil t)
1496 (replace-match "\n" t t)))))
1498 (defun article-remove-trailing-blank-lines ()
1499 "Remove all trailing blank lines from the article."
1502 (let ((buffer-read-only nil))
1503 (goto-char (point-max))
1507 (while (and (not (bobp))
1508 (looking-at "^[ \t]*$")
1509 (not (gnus-annotation-in-region-p
1510 (point) (gnus-point-at-eol))))
1515 (defun article-display-x-face (&optional force)
1516 "Look for an X-Face header and display it if present."
1517 (interactive (list 'force))
1519 ;; Delete the old process, if any.
1520 (when (process-status "article-x-face")
1521 (delete-process "article-x-face"))
1522 (let ((inhibit-point-motion-hooks t)
1523 (case-fold-search t)
1526 (article-narrow-to-head)
1527 (goto-char (point-min))
1528 (setq from (message-fetch-field "from"))
1529 (goto-char (point-min))
1530 (while (and gnus-article-x-face-command
1533 ;; Check whether this face is censored.
1534 (not gnus-article-x-face-too-ugly)
1535 (and gnus-article-x-face-too-ugly from
1536 (not (string-match gnus-article-x-face-too-ugly
1538 ;; Has to be present.
1539 (re-search-forward "^X-Face: " nil t))
1540 ;; This used to try to do multiple faces (`while' instead of
1541 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1542 ;; work (b) it can crash some versions of Emacs (c) are
1543 ;; multiple faces really something to encourage?
1544 (when (stringp gnus-article-x-face-command)
1546 ;; We now have the area of the buffer where the X-Face is stored.
1549 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1550 ;; We display the face.
1551 (if (symbolp gnus-article-x-face-command)
1552 ;; The command is a lisp function, so we call it.
1553 (if (gnus-functionp gnus-article-x-face-command)
1554 (funcall gnus-article-x-face-command beg end)
1555 (error "%s is not a function" gnus-article-x-face-command))
1556 ;; The command is a string, so we interpret the command
1557 ;; as a, well, command, and fork it off.
1558 (let ((process-connection-type nil))
1559 (process-kill-without-query
1561 "article-x-face" nil shell-file-name shell-command-switch
1562 gnus-article-x-face-command))
1563 (process-send-region "article-x-face" beg end)
1564 (process-send-eof "article-x-face"))))))))))
1566 (defun article-decode-mime-words ()
1567 "Decode all MIME-encoded words in the article."
1570 (set-buffer gnus-article-buffer)
1571 (let ((inhibit-point-motion-hooks t)
1573 (mail-parse-charset gnus-newsgroup-charset)
1574 (mail-parse-ignored-charsets
1575 (save-excursion (set-buffer gnus-summary-buffer)
1576 gnus-newsgroup-ignored-charsets)))
1577 (mail-decode-encoded-word-region (point-min) (point-max)))))
1579 (defun article-decode-charset (&optional prompt)
1580 "Decode charset-encoded text in the article.
1581 If PROMPT (the prefix), prompt for a coding system to use."
1583 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1585 (mail-parse-charset gnus-newsgroup-charset)
1586 (mail-parse-ignored-charsets
1587 (save-excursion (condition-case nil
1588 (set-buffer gnus-summary-buffer)
1590 gnus-newsgroup-ignored-charsets))
1591 ct cte ctl charset format)
1594 (article-narrow-to-head)
1595 (setq ct (message-fetch-field "Content-Type" t)
1596 cte (message-fetch-field "Content-Transfer-Encoding" t)
1597 ctl (and ct (ignore-errors
1598 (mail-header-parse-content-type ct)))
1601 (mm-read-coding-system "Charset to decode: "))
1603 (mail-content-type-get ctl 'charset)))
1604 format (and ctl (mail-content-type-get ctl 'format)))
1606 (setq cte (mail-header-strip cte)))
1607 (if (and ctl (not (string-match "/" (car ctl))))
1609 (goto-char (point-max)))
1612 (narrow-to-region (point) (point-max))
1613 (when (and (eq mail-parse-charset 'gnus-decoded)
1614 (eq (mm-body-7-or-8) '8bit))
1615 ;; The text code could have been decoded.
1616 (setq charset mail-parse-charset))
1617 (when (and (or (not ctl)
1618 (equal (car ctl) "text/plain"))
1619 (not format)) ;; article with format will decode later.
1621 charset (and cte (intern (downcase
1622 (gnus-strip-whitespace cte))))
1625 (defun article-decode-encoded-words ()
1626 "Remove encoded-word encoding from headers."
1627 (let ((inhibit-point-motion-hooks t)
1628 (mail-parse-charset gnus-newsgroup-charset)
1629 (mail-parse-ignored-charsets
1630 (save-excursion (condition-case nil
1631 (set-buffer gnus-summary-buffer)
1633 gnus-newsgroup-ignored-charsets))
1636 (article-narrow-to-head)
1637 (funcall gnus-decode-header-function (point-min) (point-max)))))
1639 (defun article-de-quoted-unreadable (&optional force)
1640 "Translate a quoted-printable-encoded article.
1641 If FORCE, decode the article whether it is marked as quoted-printable
1643 (interactive (list 'force))
1645 (let ((buffer-read-only nil) type charset)
1646 (if (gnus-buffer-live-p gnus-original-article-buffer)
1647 (with-current-buffer gnus-original-article-buffer
1649 (gnus-fetch-field "content-transfer-encoding"))
1650 (let* ((ct (gnus-fetch-field "content-type"))
1653 (mail-header-parse-content-type ct)))))
1654 (setq charset (and ctl
1655 (mail-content-type-get ctl 'charset)))
1656 (if (stringp charset)
1657 (setq charset (intern (downcase charset)))))))
1659 (setq charset gnus-newsgroup-charset))
1661 (and type (let ((case-fold-search t))
1662 (string-match "quoted-printable" type))))
1664 (quoted-printable-decode-region
1665 (point) (point-max) (mm-charset-to-coding-system charset))))))
1667 (defun article-de-base64-unreadable (&optional force)
1668 "Translate a base64 article.
1669 If FORCE, decode the article whether it is marked as base64 not."
1670 (interactive (list 'force))
1672 (let ((buffer-read-only nil) type charset)
1673 (if (gnus-buffer-live-p gnus-original-article-buffer)
1674 (with-current-buffer gnus-original-article-buffer
1676 (gnus-fetch-field "content-transfer-encoding"))
1677 (let* ((ct (gnus-fetch-field "content-type"))
1680 (mail-header-parse-content-type ct)))))
1681 (setq charset (and ctl
1682 (mail-content-type-get ctl 'charset)))
1683 (if (stringp charset)
1684 (setq charset (intern (downcase charset)))))))
1686 (setq charset gnus-newsgroup-charset))
1688 (and type (let ((case-fold-search t))
1689 (string-match "base64" type))))
1692 (narrow-to-region (point) (point-max))
1693 (base64-decode-region (point-min) (point-max))
1694 (mm-decode-coding-region
1695 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1700 (defun article-decode-HZ ()
1701 "Translate a HZ-encoded article."
1705 (let ((buffer-read-only nil))
1706 (rfc1843-decode-region (point-min) (point-max)))))
1708 (defun article-wash-html ()
1709 "Format an html article."
1712 (let ((buffer-read-only nil)
1714 (if (gnus-buffer-live-p gnus-original-article-buffer)
1715 (with-current-buffer gnus-original-article-buffer
1716 (let* ((ct (gnus-fetch-field "content-type"))
1719 (mail-header-parse-content-type ct)))))
1720 (setq charset (and ctl
1721 (mail-content-type-get ctl 'charset)))
1722 (if (stringp charset)
1723 (setq charset (intern (downcase charset)))))))
1725 (setq charset gnus-newsgroup-charset))
1727 (save-window-excursion
1729 (narrow-to-region (point) (point-max))
1731 (let ((w3-strict-width (window-width))
1732 (url-standalone-mode t))
1734 (w3-region (point-min) (point-max))
1737 (defun article-hide-list-identifiers ()
1738 "Remove list identifies from the Subject header.
1739 The `gnus-list-identifiers' variable specifies what to do."
1743 (let ((inhibit-point-motion-hooks t)
1745 (article-narrow-to-head)
1746 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1747 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1749 (goto-char (point-min))
1750 (when (re-search-forward
1751 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1752 " *\\)\\)+\\(Re: +\\)?\\)")
1754 (let ((s (or (match-string 3) (match-string 5))))
1755 (delete-region (match-beginning 1) (match-end 1))
1757 (goto-char (match-beginning 1))
1760 (defun article-hide-pgp ()
1761 "Remove any PGP headers and signatures in the current article."
1765 (let ((inhibit-point-motion-hooks t)
1766 buffer-read-only beg end)
1768 ;; Hide the "header".
1769 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1770 (push 'pgp gnus-article-wash-types)
1771 (delete-region (match-beginning 0) (match-end 0))
1772 ;; Remove armor headers (rfc2440 6.2)
1773 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1776 ;; Hide the actual signature.
1777 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1778 (setq end (1+ (match-beginning 0)))
1781 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1783 ;; Perhaps we shouldn't hide to the end of the buffer
1784 ;; if there is no end to the signature?
1786 ;; Hide "- " PGP quotation markers.
1788 (narrow-to-region beg end)
1789 (goto-char (point-min))
1790 (while (re-search-forward "^- " nil t)
1792 (match-beginning 0) (match-end 0)))
1794 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1796 (defun article-hide-pem (&optional arg)
1797 "Toggle hiding of any PEM headers and signatures in the current article.
1798 If given a negative prefix, always show; if given a positive prefix,
1800 (interactive (gnus-article-hidden-arg))
1801 (unless (gnus-article-check-hidden-text 'pem arg)
1803 (let (buffer-read-only end)
1804 (goto-char (point-min))
1805 ;; Hide the horrendously ugly "header".
1806 (when (and (search-forward
1807 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1809 (setq end (1+ (match-beginning 0))))
1810 (push 'pem gnus-article-wash-types)
1811 (gnus-article-hide-text-type
1813 (if (search-forward "\n\n" nil t)
1817 ;; Hide the trailer as well
1818 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1820 (gnus-article-hide-text-type
1821 (match-beginning 0) (match-end 0) 'pem)))))))
1823 (defun article-strip-banner ()
1824 "Strip the banner specified by the `banner' group parameter."
1828 (let ((inhibit-point-motion-hooks t)
1829 (banner (gnus-parameter-banner gnus-newsgroup-name))
1830 (gnus-signature-limit nil)
1831 buffer-read-only beg end)
1835 ((eq banner 'signature)
1836 (when (gnus-article-narrow-to-signature)
1839 (delete-region (point) (point-max))))
1841 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1842 (while (re-search-forward banner nil t)
1843 (delete-region (match-beginning 0) (match-end 0)))))
1845 (while (re-search-forward banner nil t)
1846 (delete-region (match-beginning 0) (match-end 0))))))))))
1848 (defun article-babel ()
1849 "Translate article using an online translation service."
1853 (set-buffer gnus-article-buffer)
1854 (when (article-goto-body)
1855 (let* ((buffer-read-only nil)
1858 (orig (buffer-substring start end))
1859 (trans (babel-as-string orig)))
1861 (narrow-to-region start end)
1862 (delete-region start end)
1865 (defun article-hide-signature (&optional arg)
1866 "Hide the signature in the current article.
1867 If given a negative prefix, always show; if given a positive prefix,
1869 (interactive (gnus-article-hidden-arg))
1870 (unless (gnus-article-check-hidden-text 'signature arg)
1873 (let ((buffer-read-only nil))
1874 (when (gnus-article-narrow-to-signature)
1875 (gnus-article-hide-text-type
1876 (point-min) (point-max) 'signature)))))))
1878 (defun article-strip-headers-in-body ()
1879 "Strip offensive headers from bodies."
1883 (let ((case-fold-search t))
1884 (when (looking-at "x-no-archive:")
1885 (gnus-delete-line)))))
1887 (defun article-strip-leading-blank-lines ()
1888 "Remove all blank lines from the beginning of the article."
1891 (let ((inhibit-point-motion-hooks t)
1893 (when (article-goto-body)
1894 (while (and (not (eobp))
1895 (looking-at "[ \t]*$"))
1896 (gnus-delete-line))))))
1898 (defun article-narrow-to-head ()
1899 "Narrow the buffer to the head of the message.
1900 Point is left at the beginning of the narrowed-to region."
1902 (goto-char (point-min))
1903 (if (search-forward "\n\n" nil 1)
1906 (goto-char (point-min)))
1908 (defun article-goto-body ()
1909 "Place point at the start of the body."
1910 (goto-char (point-min))
1912 ;; This variable is only bound when dealing with separate
1914 (article-goto-body-goes-to-point-min-p
1916 ((search-forward "\n\n" nil t)
1919 (goto-char (point-max))
1922 (defun article-strip-multiple-blank-lines ()
1923 "Replace consecutive blank lines with one empty line."
1926 (let ((inhibit-point-motion-hooks t)
1928 ;; First make all blank lines empty.
1930 (while (re-search-forward "^[ \t]+$" nil t)
1931 (unless (gnus-annotation-in-region-p
1932 (match-beginning 0) (match-end 0))
1933 (replace-match "" nil t)))
1934 ;; Then replace multiple empty lines with a single empty line.
1936 (while (re-search-forward "\n\n\n+" nil t)
1937 (unless (gnus-annotation-in-region-p
1938 (match-beginning 0) (match-end 0))
1939 (replace-match "\n\n" t t))))))
1941 (defun article-strip-leading-space ()
1942 "Remove all white space from the beginning of the lines in the article."
1945 (let ((inhibit-point-motion-hooks t)
1948 (while (re-search-forward "^[ \t]+" nil t)
1949 (replace-match "" t t)))))
1951 (defun article-strip-trailing-space ()
1952 "Remove all white space from the end of the lines in the article."
1955 (let ((inhibit-point-motion-hooks t)
1958 (while (re-search-forward "[ \t]+$" nil t)
1959 (replace-match "" t t)))))
1961 (defun article-strip-blank-lines ()
1962 "Strip leading, trailing and multiple blank lines."
1964 (article-strip-leading-blank-lines)
1965 (article-remove-trailing-blank-lines)
1966 (article-strip-multiple-blank-lines))
1968 (defun article-strip-all-blank-lines ()
1969 "Strip all blank lines."
1972 (let ((inhibit-point-motion-hooks t)
1975 (while (re-search-forward "^[ \t]*\n" nil t)
1976 (replace-match "" t t)))))
1978 (defun gnus-article-narrow-to-signature ()
1979 "Narrow to the signature; return t if a signature is found, else nil."
1980 (let ((inhibit-point-motion-hooks t))
1981 (when (gnus-article-search-signature)
1983 ;; Check whether we have some limits to what we consider
1984 ;; to be a signature.
1985 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
1986 (list gnus-signature-limit)))
1988 (while (setq limit (pop limits))
1989 (if (or (and (integerp limit)
1990 (< (- (point-max) (point)) limit))
1992 (< (count-lines (point) (point-max)) limit))
1993 (and (gnus-functionp limit)
1995 (and (stringp limit)
1996 (not (re-search-forward limit nil t))))
1997 () ; This limit did not succeed.
2001 (narrow-to-region (point) (point-max))
2004 (defun gnus-article-search-signature ()
2005 "Search the current buffer for the signature separator.
2006 Put point at the beginning of the signature separator."
2007 (let ((cur (point)))
2008 (goto-char (point-max))
2009 (if (if (stringp gnus-signature-separator)
2010 (re-search-backward gnus-signature-separator nil t)
2011 (let ((seps gnus-signature-separator))
2013 (not (re-search-backward (car seps) nil t)))
2020 (defun gnus-article-hidden-arg ()
2021 "Return the current prefix arg as a number, or 0 if no prefix."
2022 (list (if current-prefix-arg
2023 (prefix-numeric-value current-prefix-arg)
2026 (defun gnus-article-check-hidden-text (type arg)
2027 "Return nil if hiding is necessary.
2028 Arg can be nil or a number. Nil and positive means hide, negative
2029 means show, 0 means toggle."
2032 (let ((hide (gnus-article-hidden-text-p type)))
2038 (gnus-article-show-hidden-text type)
2041 (if (eq hide 'hidden)
2043 (gnus-article-show-hidden-text type)
2047 (defun gnus-article-hidden-text-p (type)
2048 "Say whether the current buffer contains hidden text of type TYPE."
2049 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2051 (not (get-text-property pos 'invisible))
2052 (not (get-text-property pos 'dummy-invisible)))
2054 (text-property-any (1+ pos) (point-max) 'article-type type)))
2059 (defun gnus-article-show-hidden-text (type &optional dummy)
2060 "Show all hidden text of type TYPE.
2061 Originally it is hide instead of DUMMY."
2062 (let ((buffer-read-only nil)
2063 (inhibit-point-motion-hooks t))
2064 (gnus-remove-text-properties-when
2066 (point-min) (point-max)
2067 (cons 'article-type (cons type
2068 gnus-hidden-properties)))))
2070 (defconst article-time-units
2071 `((year . ,(* 365.25 24 60 60))
2072 (week . ,(* 7 24 60 60))
2073 (day . ,(* 24 60 60))
2077 "Mapping from time units to seconds.")
2079 (defun article-date-ut (&optional type highlight header)
2080 "Convert DATE date to universal time in the current article.
2081 If TYPE is `local', convert to local time; if it is `lapsed', output
2082 how much time has lapsed since DATE. For `lapsed', the value of
2083 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2084 should replace the \"Date:\" one, or should be added below it."
2085 (interactive (list 'ut t))
2086 (let* ((header (or header
2087 (message-fetch-field "date")
2089 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2092 ((not gnus-article-date-lapsed-new-header)
2098 (date (if (vectorp header) (mail-header-date header)
2100 (inhibit-point-motion-hooks t)
2105 (article-narrow-to-head)
2106 (when (re-search-forward tdate-regexp nil t)
2107 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2108 date (or (get-text-property (gnus-point-at-bol)
2111 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2113 (when (and date (not (string= date "")))
2114 (goto-char (point-min))
2115 (let ((buffer-read-only nil))
2116 ;; Delete any old Date headers.
2117 (while (re-search-forward date-regexp nil t)
2119 (delete-region (progn (beginning-of-line) (point))
2120 (progn (forward-line 1) (point)))
2121 (delete-region (progn (beginning-of-line) (point))
2122 (progn (end-of-line) (point)))
2123 (setq pos (point))))
2124 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2126 (if pos (goto-char pos))
2127 (insert (article-make-date-line date (or type 'ut)))
2133 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2134 (put-text-property (match-beginning 1) (1+ (match-end 1))
2135 'original-date date)
2136 (put-text-property (match-beginning 1) (1+ (match-end 1))
2138 (put-text-property (match-beginning 2) (match-end 2)
2141 (defun article-make-date-line (date type)
2142 "Return a DATE line of TYPE."
2143 (let ((time (condition-case ()
2147 ;; Convert to the local timezone. We have to slap a
2148 ;; `condition-case' round the calls to the timezone
2149 ;; functions since they aren't particularly resistant to
2152 (let ((tz (car (current-time-zone time))))
2153 (format "Date: %s %s%02d%02d" (current-time-string time)
2154 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2155 (/ (% (abs tz) 3600) 60))))
2156 ;; Convert to Universal Time.
2159 (current-time-string
2160 (let* ((e (parse-time-string date))
2161 (tm (apply 'encode-time e))
2163 (ls (- (cadr tm) (car (current-time-zone time)))))
2164 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2165 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2168 ;; Get the original date from the article.
2169 ((eq type 'original)
2170 (concat "Date: " (if (string-match "\n+$" date)
2171 (substring date 0 (match-beginning 0))
2173 ;; Let the user define the format.
2175 (if (gnus-functionp gnus-article-time-format)
2176 (funcall gnus-article-time-format time)
2179 (format-time-string gnus-article-time-format time))))
2182 (let ((tz (car (current-time-zone time))))
2185 (format-time-string "%Y%m%dT%H%M%S" time)
2186 (format "%s%02d%02d"
2187 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2188 (/ (% (abs tz) 3600) 60)))))
2189 ;; Do an X-Sent lapsed format.
2191 ;; If the date is seriously mangled, the timezone functions are
2192 ;; liable to bug out, so we ignore all errors.
2193 (let* ((now (current-time))
2194 (real-time (subtract-time now time))
2195 (real-sec (and real-time
2196 (+ (* (float (car real-time)) 65536)
2198 (sec (and real-time (abs real-sec)))
2208 ;; This is a bit convoluted, but basically we go
2209 ;; through the time units for years, weeks, etc,
2210 ;; and divide things to see whether that results
2211 ;; in positive answers.
2214 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2215 ;; The (remaining) seconds are too few to
2216 ;; be divided into this time unit.
2218 ;; It's big enough, so we output it.
2219 (setq sec (- sec (* num (cdr unit))))
2221 (concat (if prev ", " "") (int-to-string
2223 " " (symbol-name (car unit))
2224 (if (> num 1) "s" ""))
2226 article-time-units "")
2227 ;; If dates are odd, then it might appear like the
2228 ;; article was sent in the future.
2231 " in the future"))))))
2233 (error "Unknown conversion type: %s" type)))))
2235 (defun article-date-local (&optional highlight)
2236 "Convert the current article date to the local timezone."
2237 (interactive (list t))
2238 (article-date-ut 'local highlight))
2240 (defun article-date-original (&optional highlight)
2241 "Convert the current article date to what it was originally.
2242 This is only useful if you have used some other date conversion
2243 function and want to see what the date was before converting."
2244 (interactive (list t))
2245 (article-date-ut 'original highlight))
2247 (defun article-date-lapsed (&optional highlight)
2248 "Convert the current article date to time lapsed since it was sent."
2249 (interactive (list t))
2250 (article-date-ut 'lapsed highlight))
2252 (defun article-update-date-lapsed ()
2253 "Function to be run from a timer to update the lapsed time line."
2254 (let (deactivate-mark)
2259 (set-buffer (window-buffer w))
2260 (when (eq major-mode 'gnus-article-mode)
2261 (goto-char (point-min))
2262 (when (re-search-forward "^X-Sent:" nil t)
2263 (article-date-lapsed t))))
2266 (defun gnus-start-date-timer (&optional n)
2267 "Start a timer to update the X-Sent header in the article buffers.
2268 The numerical prefix says how frequently (in seconds) the function
2273 (gnus-stop-date-timer)
2274 (setq article-lapsed-timer
2275 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2277 (defun gnus-stop-date-timer ()
2278 "Stop the X-Sent timer."
2280 (when article-lapsed-timer
2281 (nnheader-cancel-timer article-lapsed-timer)
2282 (setq article-lapsed-timer nil)))
2284 (defun article-date-user (&optional highlight)
2285 "Convert the current article date to the user-defined format.
2286 This format is defined by the `gnus-article-time-format' variable."
2287 (interactive (list t))
2288 (article-date-ut 'user highlight))
2290 (defun article-date-iso8601 (&optional highlight)
2291 "Convert the current article date to ISO8601."
2292 (interactive (list t))
2293 (article-date-ut 'iso8601 highlight))
2295 (defun article-show-all ()
2296 "Show all hidden text in the article buffer."
2299 (let ((buffer-read-only nil))
2300 (gnus-article-unhide-text (point-min) (point-max)))))
2302 (defun article-emphasize (&optional arg)
2303 "Emphasize text according to `gnus-emphasis-alist'."
2304 (interactive (gnus-article-hidden-arg))
2305 (unless (gnus-article-check-hidden-text 'emphasis arg)
2309 (with-current-buffer gnus-summary-buffer
2310 gnus-article-emphasis-alist)
2312 gnus-emphasis-alist))
2313 (buffer-read-only nil)
2314 (props (append '(article-type emphasis)
2315 gnus-hidden-properties))
2316 regexp elem beg invisible visible face)
2319 (while (setq elem (pop alist))
2321 (setq regexp (car elem)
2322 invisible (nth 1 elem)
2323 visible (nth 2 elem)
2325 (while (re-search-forward regexp nil t)
2326 (when (and (match-beginning visible) (match-beginning invisible))
2327 (push 'emphasis gnus-article-wash-types)
2328 (gnus-article-hide-text
2329 (match-beginning invisible) (match-end invisible) props)
2330 (gnus-article-unhide-text-type
2331 (match-beginning visible) (match-end visible) 'emphasis)
2332 (gnus-put-text-property-excluding-newlines
2333 (match-beginning visible) (match-end visible) 'face face)
2334 (goto-char (match-end invisible)))))))))
2336 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2337 "Setup newsgroup emphasis alist."
2338 (unless gnus-article-emphasis-alist
2339 (let ((name (and gnus-newsgroup-name
2340 (gnus-group-real-name gnus-newsgroup-name))))
2341 (make-local-variable 'gnus-article-emphasis-alist)
2342 (setq gnus-article-emphasis-alist
2344 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2345 (while (setq elem (pop alist))
2346 (when (and name (string-match (car elem) name))
2348 highlight (copy-sequence (cdr elem)))))
2350 (copy-sequence highlight-words)
2351 (if gnus-newsgroup-name
2352 (copy-sequence (gnus-group-find-parameter
2353 gnus-newsgroup-name 'highlight-words t)))
2354 gnus-emphasis-alist)))))
2356 (defvar gnus-summary-article-menu)
2357 (defvar gnus-summary-post-menu)
2359 ;;; Saving functions.
2361 (defun gnus-article-save (save-buffer file &optional num)
2362 "Save the currently selected article."
2363 (unless gnus-save-all-headers
2364 ;; Remove headers according to `gnus-saved-headers'.
2365 (let ((gnus-visible-headers
2366 (or gnus-saved-headers gnus-visible-headers))
2367 (gnus-article-buffer save-buffer))
2369 (set-buffer save-buffer)
2370 (article-hide-headers 1 t))))
2371 (save-window-excursion
2372 (if (not gnus-default-article-saver)
2373 (error "No default saver is defined")
2374 ;; !!! Magic! The saving functions all save
2375 ;; `gnus-save-article-buffer' (or so they think), but we
2376 ;; bind that variable to our save-buffer.
2377 (set-buffer gnus-article-buffer)
2378 (let* ((gnus-save-article-buffer save-buffer)
2381 ((not gnus-prompt-before-saving) 'default)
2382 ((eq gnus-prompt-before-saving 'always) nil)
2384 (gnus-number-of-articles-to-be-saved
2385 (when (eq gnus-prompt-before-saving t)
2387 (set-buffer gnus-article-current-summary)
2388 (funcall gnus-default-article-saver filename)))))
2390 (defun gnus-read-save-file-name (prompt &optional filename
2391 function group headers variable)
2393 (funcall function group headers (symbol-value variable)))
2398 ((eq filename 'default)
2404 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2407 (if (and gnus-number-of-articles-to-be-saved
2408 (> gnus-number-of-articles-to-be-saved 1))
2409 (format "these %d articles"
2410 gnus-number-of-articles-to-be-saved)
2413 ;; Let the split methods have their say.
2415 ;; No split name was found.
2418 (concat prompt " (default "
2419 (file-name-nondirectory default-name) ") ")
2420 (file-name-directory default-name)
2422 ;; A single group name is returned.
2423 ((stringp split-name)
2425 (funcall function split-name headers
2426 (symbol-value variable)))
2428 (concat prompt " (default "
2429 (file-name-nondirectory default-name) ") ")
2430 (file-name-directory default-name)
2432 ;; A single split name was found
2433 ((= 1 (length split-name))
2434 (let* ((name (expand-file-name
2436 gnus-article-save-directory))
2437 (dir (cond ((file-directory-p name)
2438 (file-name-as-directory name))
2439 ((file-exists-p name) name)
2440 (t gnus-article-save-directory))))
2442 (concat prompt " (default " name ") ")
2444 ;; A list of splits was found.
2446 (setq split-name (nreverse split-name))
2448 (let ((file-name-history
2449 (nconc split-name file-name-history)))
2453 (concat prompt " (`M-p' for defaults) ")
2454 gnus-article-save-directory
2456 gnus-article-save-directory)))
2457 (car (push result file-name-history)))))))
2458 ;; Create the directory.
2459 (gnus-make-directory (file-name-directory file))
2460 ;; If we have read a directory, we append the default file name.
2461 (when (file-directory-p file)
2462 (setq file (expand-file-name (file-name-nondirectory
2464 (file-name-as-directory file))))
2465 ;; Possibly translate some characters.
2466 (nnheader-translate-file-chars file))))))
2467 (gnus-make-directory (file-name-directory result))
2468 (set variable result)))
2470 (defun gnus-article-archive-name (group)
2471 "Return the first instance of an \"Archive-name\" in the current buffer."
2472 (let ((case-fold-search t))
2473 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2474 (nnheader-concat gnus-article-save-directory
2475 (match-string 1)))))
2477 (defun gnus-article-nndoc-name (group)
2478 "If GROUP is an nndoc group, return the name of the parent group."
2479 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2480 (gnus-group-get-parameter group 'save-article-group)))
2482 (defun gnus-summary-save-in-rmail (&optional filename)
2483 "Append this article to Rmail file.
2484 Optional argument FILENAME specifies file name.
2485 Directory to save to is default to `gnus-article-save-directory'."
2486 (setq filename (gnus-read-save-file-name
2487 "Save %s in rmail file:" filename
2488 gnus-rmail-save-name gnus-newsgroup-name
2489 gnus-current-headers 'gnus-newsgroup-last-rmail))
2490 (gnus-eval-in-buffer-window gnus-save-article-buffer
2494 (gnus-output-to-rmail filename))))
2497 (defun gnus-summary-save-in-mail (&optional filename)
2498 "Append this article to Unix mail file.
2499 Optional argument FILENAME specifies file name.
2500 Directory to save to is default to `gnus-article-save-directory'."
2501 (setq filename (gnus-read-save-file-name
2502 "Save %s in Unix mail file:" filename
2503 gnus-mail-save-name gnus-newsgroup-name
2504 gnus-current-headers 'gnus-newsgroup-last-mail))
2505 (gnus-eval-in-buffer-window gnus-save-article-buffer
2509 (if (and (file-readable-p filename)
2510 (mail-file-babyl-p filename))
2511 (rmail-output-to-rmail-file filename t)
2512 (gnus-output-to-mail filename)))))
2515 (defun gnus-summary-save-in-file (&optional filename overwrite)
2516 "Append this article to file.
2517 Optional argument FILENAME specifies file name.
2518 Directory to save to is default to `gnus-article-save-directory'."
2519 (setq filename (gnus-read-save-file-name
2520 "Save %s in file:" filename
2521 gnus-file-save-name gnus-newsgroup-name
2522 gnus-current-headers 'gnus-newsgroup-last-file))
2523 (gnus-eval-in-buffer-window gnus-save-article-buffer
2527 (when (and overwrite
2528 (file-exists-p filename))
2529 (delete-file filename))
2530 (gnus-output-to-file filename))))
2533 (defun gnus-summary-write-to-file (&optional filename)
2534 "Write this article to a file.
2535 Optional argument FILENAME specifies file name.
2536 The directory to save in defaults to `gnus-article-save-directory'."
2537 (gnus-summary-save-in-file nil t))
2539 (defun gnus-summary-save-body-in-file (&optional filename)
2540 "Append this article body to a file.
2541 Optional argument FILENAME specifies file name.
2542 The directory to save in defaults to `gnus-article-save-directory'."
2543 (setq filename (gnus-read-save-file-name
2544 "Save %s body in file:" filename
2545 gnus-file-save-name gnus-newsgroup-name
2546 gnus-current-headers 'gnus-newsgroup-last-file))
2547 (gnus-eval-in-buffer-window gnus-save-article-buffer
2551 (when (article-goto-body)
2552 (narrow-to-region (point) (point-max)))
2553 (gnus-output-to-file filename))))
2556 (defun gnus-summary-save-in-pipe (&optional command)
2557 "Pipe this article to subprocess."
2559 (cond ((and (eq command 'default)
2560 gnus-last-shell-command)
2561 gnus-last-shell-command)
2565 "Shell command on %s: "
2566 (if (and gnus-number-of-articles-to-be-saved
2567 (> gnus-number-of-articles-to-be-saved 1))
2568 (format "these %d articles"
2569 gnus-number-of-articles-to-be-saved)
2571 gnus-last-shell-command))))
2572 (when (string-equal command "")
2573 (setq command gnus-last-shell-command))
2574 (gnus-eval-in-buffer-window gnus-article-buffer
2577 (shell-command-on-region (point-min) (point-max) command nil)))
2578 (setq gnus-last-shell-command command))
2580 ;;; Article file names when saving.
2582 (defun gnus-capitalize-newsgroup (newsgroup)
2583 "Capitalize NEWSGROUP name."
2584 (when (not (zerop (length newsgroup)))
2585 (concat (char-to-string (upcase (aref newsgroup 0)))
2586 (substring newsgroup 1))))
2588 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2589 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2590 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2591 Otherwise, it is like ~/News/news/group/num."
2594 (concat (if (gnus-use-long-file-name 'not-save)
2595 (gnus-capitalize-newsgroup newsgroup)
2596 (gnus-newsgroup-directory-form newsgroup))
2597 "/" (int-to-string (mail-header-number headers)))
2598 gnus-article-save-directory)))
2600 (string-equal (file-name-directory default)
2601 (file-name-directory last-file))
2602 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2604 (or last-file default))))
2606 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2607 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2608 If variable `gnus-use-long-file-name' is non-nil, it is
2609 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2612 (concat (if (gnus-use-long-file-name 'not-save)
2614 (gnus-newsgroup-directory-form newsgroup))
2615 "/" (int-to-string (mail-header-number headers)))
2616 gnus-article-save-directory)))
2618 (string-equal (file-name-directory default)
2619 (file-name-directory last-file))
2620 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2622 (or last-file default))))
2624 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2625 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2626 If variable `gnus-use-long-file-name' is non-nil, it is
2627 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2630 (if (gnus-use-long-file-name 'not-save)
2632 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2633 gnus-article-save-directory)))
2635 (defun article-verify-x-pgp-sig ()
2638 (if (gnus-buffer-live-p gnus-original-article-buffer)
2639 (let ((sig (with-current-buffer gnus-original-article-buffer
2640 (gnus-fetch-field "X-PGP-Sig")))
2644 (mml2015-clear-verify-function))
2646 (insert-buffer gnus-original-article-buffer)
2647 (setq items (split-string sig))
2648 (message-narrow-to-head)
2649 (let ((inhibit-point-motion-hooks t)
2650 (case-fold-search t))
2651 ;; Don't verify multiple headers.
2652 (setq headers (mapconcat (lambda (header)
2654 (mail-fetch-field header) "\n"))
2655 (split-string (nth 1 items) ",") "")))
2656 (delete-region (point-min) (point-max))
2657 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2658 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2663 (if (looking-at "^-")
2666 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2667 (insert "Version: " (car items) "\n\n")
2668 (insert (mapconcat 'identity (cddr items) "\n"))
2669 (insert "\n-----END PGP SIGNATURE-----\n")
2670 (let ((mm-security-handle (list (format "multipart/signed"))))
2671 (mml2015-clean-buffer)
2672 (let ((coding-system-for-write (or gnus-newsgroup-charset
2674 (funcall (mml2015-clear-verify-function)))
2676 (or (mm-handle-multipart-ctl-parameter
2677 mm-security-handle 'gnus-details)
2678 (mm-handle-multipart-ctl-parameter
2679 mm-security-handle 'gnus-info)))))
2681 (let (buffer-read-only bface eface)
2683 (message-narrow-to-head)
2684 (goto-char (point-max))
2686 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2687 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2688 (message-remove-header "X-Gnus-PGP-Verify")
2689 (if (re-search-forward "^X-PGP-Sig:" nil t)
2691 (goto-char (point-max)))
2692 (narrow-to-region (point) (point))
2693 (insert "X-Gnus-PGP-Verify: " info "\n")
2694 (goto-char (point-min))
2697 (if (not (looking-at "^[ \t]"))
2701 (goto-char (point-min))
2702 (when (looking-at "\\([^:]+\\): *")
2703 (put-text-property (match-beginning 1) (1+ (match-end 1))
2705 (put-text-property (match-end 0) (point-max)
2706 'face eface)))))))))
2713 (setq afunc (car func)
2716 gfunc (intern (format "gnus-%s" func))))
2719 `(lambda (&optional interactive &rest args)
2720 ,(documentation afunc t)
2721 (interactive (list t))
2723 (set-buffer gnus-article-buffer)
2725 (call-interactively ',afunc)
2726 (apply ',afunc args))))))))
2727 '(article-hide-headers
2728 article-verify-x-pgp-sig
2729 article-hide-boring-headers
2730 article-treat-overstrike
2731 article-fill-long-lines
2732 article-capitalize-sentences
2734 article-display-x-face
2735 article-de-quoted-unreadable
2736 article-de-base64-unreadable
2739 article-hide-list-identifiers
2741 article-strip-banner
2744 article-hide-signature
2745 article-strip-headers-in-body
2746 article-remove-trailing-blank-lines
2747 article-strip-leading-blank-lines
2748 article-strip-multiple-blank-lines
2749 article-strip-leading-space
2750 article-strip-trailing-space
2751 article-strip-blank-lines
2752 article-strip-all-blank-lines
2754 article-date-iso8601
2755 article-date-original
2757 article-decode-mime-words
2758 article-decode-charset
2759 article-decode-encoded-words
2763 article-treat-dumbquotes
2764 article-normalize-headers
2765 (article-show-all . gnus-article-show-all-headers))))
2768 ;;; Gnus article mode
2771 (put 'gnus-article-mode 'mode-class 'special)
2773 (set-keymap-parent gnus-article-mode-map widget-keymap)
2775 (gnus-define-keys gnus-article-mode-map
2776 " " gnus-article-goto-next-page
2777 "\177" gnus-article-goto-prev-page
2778 [delete] gnus-article-goto-prev-page
2779 [backspace] gnus-article-goto-prev-page
2780 "\C-c^" gnus-article-refer-article
2781 "h" gnus-article-show-summary
2782 "s" gnus-article-show-summary
2783 "\C-c\C-m" gnus-article-mail
2784 "?" gnus-article-describe-briefly
2785 "e" gnus-summary-edit-article
2786 "<" beginning-of-buffer
2788 "\C-c\C-i" gnus-info-find-node
2790 "\C-hk" gnus-article-describe-key
2791 "\C-hc" gnus-article-describe-key-briefly
2793 "\C-d" gnus-article-read-summary-keys
2794 "\M-*" gnus-article-read-summary-keys
2795 "\M-#" gnus-article-read-summary-keys
2796 "\M-^" gnus-article-read-summary-keys
2797 "\M-g" gnus-article-read-summary-keys)
2799 (substitute-key-definition
2800 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2803 (defvar gnus-article-commands-menu))
2805 (defun gnus-article-make-menu-bar ()
2806 (gnus-turn-off-edit-menu 'article)
2807 (unless (boundp 'gnus-article-article-menu)
2809 gnus-article-article-menu gnus-article-mode-map ""
2811 ["Scroll forwards" gnus-article-goto-next-page t]
2812 ["Scroll backwards" gnus-article-goto-prev-page t]
2813 ["Show summary" gnus-article-show-summary t]
2814 ["Fetch Message-ID at point" gnus-article-refer-article t]
2815 ["Mail to address at point" gnus-article-mail t]
2816 ["Send a bug report" gnus-bug t]))
2819 gnus-article-treatment-menu gnus-article-mode-map ""
2820 ;; Fixme: this should use :active (and maybe :visible).
2822 ["Hide headers" gnus-article-hide-headers t]
2823 ["Hide signature" gnus-article-hide-signature t]
2824 ["Hide citation" gnus-article-hide-citation t]
2825 ["Treat overstrike" gnus-article-treat-overstrike t]
2826 ["Remove carriage return" gnus-article-remove-cr t]
2827 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2828 ["Remove base64" gnus-article-de-base64-unreadable t]
2829 ["Treat html" gnus-article-wash-html t]
2830 ["Decode HZ" gnus-article-decode-HZ t]))
2832 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2834 (when (boundp 'gnus-summary-post-menu)
2835 (define-key gnus-article-mode-map [menu-bar post]
2836 (cons "Post" gnus-summary-post-menu)))
2838 (gnus-run-hooks 'gnus-article-menu-hook))
2840 (when (boundp 'gnus-article-commands-menu)
2841 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
2842 (when (boundp 'gnus-summary-post-menu)
2843 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
2845 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2848 (defun gnus-article-mode ()
2849 "Major mode for displaying an article.
2851 All normal editing commands are switched off.
2853 The following commands are available in addition to all summary mode
2855 \\<gnus-article-mode-map>
2856 \\[gnus-article-next-page]\t Scroll the article one page forwards
2857 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2858 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2859 \\[gnus-article-show-summary]\t Display the summary buffer
2860 \\[gnus-article-mail]\t Send a reply to the address near point
2861 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2862 \\[gnus-info-find-node]\t Go to the Gnus info node"
2864 (when (gnus-visual-p 'article-menu 'menu)
2865 (gnus-article-make-menu-bar))
2866 (gnus-simplify-mode-line)
2867 (setq mode-name "Article")
2868 (setq major-mode 'gnus-article-mode)
2869 (make-local-variable 'minor-mode-alist)
2870 (use-local-map gnus-article-mode-map)
2871 (gnus-update-format-specifications nil 'article-mode)
2872 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2873 (make-local-variable 'gnus-page-broken)
2874 (make-local-variable 'gnus-button-marker-list)
2875 (make-local-variable 'gnus-article-current-summary)
2876 (make-local-variable 'gnus-article-mime-handles)
2877 (make-local-variable 'gnus-article-decoded-p)
2878 (make-local-variable 'gnus-article-mime-handle-alist)
2879 (make-local-variable 'gnus-article-wash-types)
2880 (make-local-variable 'gnus-article-charset)
2881 (make-local-variable 'gnus-article-ignored-charsets)
2882 (gnus-set-default-directory)
2883 (buffer-disable-undo)
2884 (setq buffer-read-only t)
2885 (set-syntax-table gnus-article-mode-syntax-table)
2886 (mm-enable-multibyte)
2887 (gnus-run-hooks 'gnus-article-mode-hook))
2889 (defun gnus-article-setup-buffer ()
2890 "Initialize the article buffer."
2891 (let* ((name (if gnus-single-article-buffer "*Article*"
2892 (concat "*Article " gnus-newsgroup-name "*")))
2894 (progn (string-match "\\*Article" name)
2895 (concat " *Original Article"
2896 (substring name (match-end 0))))))
2897 (setq gnus-article-buffer name)
2898 (setq gnus-original-article-buffer original)
2899 (setq gnus-article-mime-handle-alist nil)
2900 ;; This might be a variable local to the summary buffer.
2901 (unless gnus-single-article-buffer
2903 (set-buffer gnus-summary-buffer)
2904 (setq gnus-article-buffer name)
2905 (setq gnus-original-article-buffer original)
2906 (gnus-set-global-variables)))
2907 (gnus-article-setup-highlight-words)
2908 ;; Init original article buffer.
2910 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2911 (mm-enable-multibyte)
2912 (setq major-mode 'gnus-original-article-mode)
2913 (make-local-variable 'gnus-original-article))
2914 (if (get-buffer name)
2917 (when gnus-article-mime-handles
2918 (mm-destroy-parts gnus-article-mime-handles)
2919 (setq gnus-article-mime-handles nil))
2920 ;; Set it to nil in article-buffer!
2921 (setq gnus-article-mime-handle-alist nil)
2922 (buffer-disable-undo)
2923 (setq buffer-read-only t)
2924 (unless (eq major-mode 'gnus-article-mode)
2925 (gnus-article-mode))
2928 (set-buffer (gnus-get-buffer-create name))
2930 (make-local-variable 'gnus-summary-buffer)
2931 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2932 (current-buffer)))))
2934 ;; Set article window start at LINE, where LINE is the number of lines
2935 ;; from the head of the article.
2936 (defun gnus-article-set-window-start (&optional line)
2938 (get-buffer-window gnus-article-buffer t)
2940 (set-buffer gnus-article-buffer)
2941 (goto-char (point-min))
2944 (gnus-message 6 "Moved to bookmark")
2945 (search-forward "\n\n" nil t)
2949 (defun gnus-article-prepare (article &optional all-headers header)
2950 "Prepare ARTICLE in article mode buffer.
2951 ARTICLE should either be an article number or a Message-ID.
2952 If ARTICLE is an id, HEADER should be the article headers.
2953 If ALL-HEADERS is non-nil, no headers are hidden."
2955 ;; Make sure we start in a summary buffer.
2956 (unless (eq major-mode 'gnus-summary-mode)
2957 (set-buffer gnus-summary-buffer))
2958 (setq gnus-summary-buffer (current-buffer))
2959 (let* ((gnus-article (if header (mail-header-number header) article))
2960 (summary-buffer (current-buffer))
2961 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
2962 (group gnus-newsgroup-name)
2965 (gnus-article-setup-buffer)
2966 (set-buffer gnus-article-buffer)
2967 ;; Deactivate active regions.
2968 (when (and (boundp 'transient-mark-mode)
2969 transient-mark-mode)
2970 (setq mark-active nil))
2971 (if (not (setq result (let ((buffer-read-only nil))
2972 (gnus-request-article-this-buffer
2974 ;; There is no such article.
2976 (when (and (numberp article)
2977 (not (memq article gnus-newsgroup-sparse)))
2978 (setq gnus-article-current
2979 (cons gnus-newsgroup-name article))
2980 (set-buffer gnus-summary-buffer)
2981 (setq gnus-current-article article)
2982 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
2984 (gnus-summary-set-agent-mark article)
2985 (message "Message marked for downloading"))
2986 (gnus-summary-mark-article article gnus-canceled-mark)
2987 (unless (memq article gnus-newsgroup-sparse)
2988 (gnus-error 1 "No such article (may have expired or been canceled)")))))
2989 (if (or (eq result 'pseudo)
2990 (eq result 'nneething))
2993 (set-buffer summary-buffer)
2994 (push article gnus-newsgroup-history)
2995 (setq gnus-last-article gnus-current-article
2996 gnus-current-article 0
2997 gnus-current-headers nil
2998 gnus-article-current nil)
2999 (if (eq result 'nneething)
3000 (gnus-configure-windows 'summary)
3001 (gnus-configure-windows 'article))
3002 (gnus-set-global-variables))
3003 (let ((gnus-article-mime-handle-alist-1
3004 gnus-article-mime-handle-alist))
3005 (gnus-set-mode-line 'article)))
3006 ;; The result from the `request' was an actual article -
3007 ;; or at least some text that is now displayed in the
3009 (when (and (numberp article)
3010 (not (eq article gnus-current-article)))
3011 ;; Seems like a new article has been selected.
3012 ;; `gnus-current-article' must be an article number.
3014 (set-buffer summary-buffer)
3015 (push article gnus-newsgroup-history)
3016 (setq gnus-last-article gnus-current-article
3017 gnus-current-article article
3018 gnus-current-headers
3019 (gnus-summary-article-header gnus-current-article)
3020 gnus-article-current
3021 (cons gnus-newsgroup-name gnus-current-article))
3022 (unless (vectorp gnus-current-headers)
3023 (setq gnus-current-headers nil))
3024 (gnus-summary-goto-subject gnus-current-article)
3025 (when (gnus-summary-show-thread)
3026 ;; If the summary buffer really was folded, the
3027 ;; previous goto may not actually have gone to
3028 ;; the right article, but the thread root instead.
3030 (gnus-summary-goto-subject gnus-current-article))
3031 (gnus-run-hooks 'gnus-mark-article-hook)
3032 (gnus-set-mode-line 'summary)
3033 (when (gnus-visual-p 'article-highlight 'highlight)
3034 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3035 ;; Set the global newsgroup variables here.
3036 (gnus-set-global-variables)
3037 (setq gnus-have-all-headers
3038 (or all-headers gnus-show-all-headers))))
3040 (gnus-configure-windows 'article))
3041 (when (or (numberp article)
3043 (gnus-article-prepare-display)
3045 (goto-char (point-min))
3046 (setq gnus-page-broken
3047 (when gnus-break-pages
3048 (gnus-narrow-to-page)
3050 (let ((gnus-article-mime-handle-alist-1
3051 gnus-article-mime-handle-alist))
3052 (gnus-set-mode-line 'article))
3054 (set-window-point (get-buffer-window (current-buffer)) (point))
3055 (gnus-configure-windows 'article)
3059 (defun gnus-article-prepare-display ()
3060 "Make the current buffer look like a nice article."
3061 ;; Hooks for getting information from the article.
3062 ;; This hook must be called before being narrowed.
3063 (let ((gnus-article-buffer (current-buffer))
3065 (unless (eq major-mode 'gnus-article-mode)
3066 (gnus-article-mode))
3067 (setq buffer-read-only nil
3068 gnus-article-wash-types nil)
3069 (gnus-run-hooks 'gnus-tmp-internal-hook)
3070 (when gnus-display-mime-function
3071 (funcall gnus-display-mime-function))
3072 (gnus-run-hooks 'gnus-article-prepare-hook)))
3075 ;;; Gnus MIME viewing functions
3078 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3079 "The following specs can be used:
3081 %T MIME type, along with additional info
3082 %n The `name' parameter
3083 %d The description, if any
3084 %l The length of the encoded part
3085 %p The part identifier number
3086 %e Dots if the part isn't displayed")
3088 (defvar gnus-mime-button-line-format-alist
3089 '((?t gnus-tmp-type ?s)
3090 (?T gnus-tmp-type-long ?s)
3091 (?n gnus-tmp-name ?s)
3092 (?d gnus-tmp-description ?s)
3094 (?l gnus-tmp-length ?d)
3095 (?e gnus-tmp-dots ?s)))
3097 (defvar gnus-mime-button-commands
3098 '((gnus-article-press-button "\r" "Toggle Display")
3099 (gnus-mime-view-part "v" "View Interactively...")
3100 (gnus-mime-view-part-as-type "t" "View As Type...")
3101 (gnus-mime-view-part-as-charset "C" "View As charset...")
3102 (gnus-mime-save-part "o" "Save...")
3103 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3104 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3105 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3106 (gnus-mime-internalize-part "E" "View Internally")
3107 (gnus-mime-externalize-part "e" "View Externally")
3108 (gnus-mime-pipe-part "|" "Pipe To Command...")
3109 (gnus-mime-action-on-part "." "Take action on the part")))
3111 (defun gnus-article-mime-part-status ()
3112 (if gnus-article-mime-handle-alist-1
3113 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
3116 (defvar gnus-mime-button-map
3117 (let ((map (make-sparse-keymap)))
3118 (unless (>= (string-to-number emacs-version) 21)
3119 ;; XEmacs doesn't care.
3120 (set-keymap-parent map gnus-article-mode-map))
3121 (define-key map gnus-mouse-2 'gnus-article-push-button)
3122 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3123 (dolist (c gnus-mime-button-commands)
3124 (define-key map (cadr c) (car c)))
3127 (defun gnus-mime-button-menu (event)
3128 "Construct a context-sensitive menu of MIME commands."
3130 (save-window-excursion
3131 (let ((pos (event-start event)))
3132 (select-window (posn-window pos))
3133 (goto-char (posn-point pos))
3134 (gnus-article-check-buffer)
3135 (let ((response (x-popup-menu
3137 ("" ,@(mapcar (lambda (c)
3138 (cons (caddr c) (car c)))
3139 gnus-mime-button-commands))))))
3141 (call-interactively response))))))
3143 (defun gnus-mime-view-all-parts (&optional handles)
3144 "View all the MIME parts."
3146 (save-current-buffer
3147 (set-buffer gnus-article-buffer)
3148 (let ((handles (or handles gnus-article-mime-handles))
3149 (mail-parse-charset gnus-newsgroup-charset)
3150 (mail-parse-ignored-charsets
3151 (with-current-buffer gnus-summary-buffer
3152 gnus-newsgroup-ignored-charsets)))
3154 (mm-remove-parts handles)
3155 (goto-char (point-min))
3156 (or (search-forward "\n\n") (goto-char (point-max)))
3157 (let (buffer-read-only)
3158 (delete-region (point) (point-max)))
3159 (mm-display-parts handles)))))
3161 (defun gnus-mime-save-part-and-strip ()
3162 "Save the MIME part under point then replace it with an external body."
3164 (gnus-article-check-buffer)
3165 (let* ((data (get-text-property (point) 'gnus-data))
3166 (file (and data (mm-save-part data)))
3169 (with-current-buffer (mm-handle-buffer data)
3171 (insert "Content-Type: " (mm-handle-media-type data))
3172 (mml-insert-parameter-string (cdr (mm-handle-type data))
3175 (insert "Content-ID: " (message-make-message-id) "\n")
3176 (insert "Content-Transfer-Encoding: binary\n")
3179 (cdr (mm-make-handle nil
3180 `("message/external-body"
3181 (access-type . "LOCAL-FILE")
3183 (set-buffer gnus-summary-buffer)
3184 (gnus-article-edit-article
3187 (let ((mail-parse-charset (or gnus-article-charset
3188 ',gnus-newsgroup-charset))
3189 (mail-parse-ignored-charsets
3190 (or gnus-article-ignored-charsets
3191 ',gnus-newsgroup-ignored-charsets))
3192 (mbl mml-buffer-list))
3193 (setq mml-buffer-list nil)
3194 (insert-buffer gnus-original-article-buffer)
3195 (mime-to-mml gnus-article-mime-handles)
3196 (setq gnus-article-mime-handles nil)
3197 (make-local-hook 'kill-buffer-hook)
3198 (let ((mbl1 mml-buffer-list))
3199 (setq mml-buffer-list mbl)
3200 (set (make-local-variable 'mml-buffer-list) mbl1))
3201 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3202 `(lambda (no-highlight)
3203 (let ((mail-parse-charset (or gnus-article-charset
3204 ',gnus-newsgroup-charset))
3205 (message-options message-options)
3206 (message-options-set-recipient)
3207 (mail-parse-ignored-charsets
3208 (or gnus-article-ignored-charsets
3209 ',gnus-newsgroup-ignored-charsets)))
3211 (mml-destroy-buffers)
3212 (remove-hook 'kill-buffer-hook
3213 'mml-destroy-buffers t)
3214 (kill-local-variable 'mml-buffer-list))
3215 (gnus-summary-edit-article-done
3216 ,(or (mail-header-references gnus-current-headers) "")
3217 ,(gnus-group-read-only-p)
3218 ,gnus-summary-buffer no-highlight))))))
3220 (defun gnus-mime-save-part ()
3221 "Save the MIME part under point."
3223 (gnus-article-check-buffer)
3224 (let ((data (get-text-property (point) 'gnus-data)))
3226 (mm-save-part data))))
3228 (defun gnus-mime-pipe-part ()
3229 "Pipe the MIME part under point to a process."
3231 (gnus-article-check-buffer)
3232 (let ((data (get-text-property (point) 'gnus-data)))
3234 (mm-pipe-part data))))
3236 (defun gnus-mime-view-part ()
3237 "Interactively choose a viewing method for the MIME part under point."
3239 (gnus-article-check-buffer)
3240 (let ((data (get-text-property (point) 'gnus-data)))
3242 (mm-interactively-view-part data))))
3244 (defun gnus-mime-view-part-as-type-internal ()
3245 (gnus-article-check-buffer)
3246 (let* ((name (mail-content-type-get
3247 (mm-handle-type (get-text-property (point) 'gnus-data))
3249 (def-type (and name (mm-default-file-encoding name))))
3250 (and def-type (cons def-type 0))))
3252 (defun gnus-mime-view-part-as-type (mime-type)
3253 "Choose a MIME media type, and view the part as such."
3255 (list (completing-read
3256 "View as MIME type: "
3257 (mapcar #'list (mailcap-mime-types))
3259 (gnus-mime-view-part-as-type-internal))))
3260 (gnus-article-check-buffer)
3261 (let ((handle (get-text-property (point) 'gnus-data)))
3263 (gnus-mm-display-part
3264 (mm-make-handle (mm-handle-buffer handle)
3265 (cons mime-type (cdr (mm-handle-type handle)))
3266 (mm-handle-encoding handle)
3267 (mm-handle-undisplayer handle)
3268 (mm-handle-disposition handle)
3269 (mm-handle-description handle)
3270 (mm-handle-cache handle)
3271 (mm-handle-id handle))))))
3273 (defun gnus-mime-copy-part (&optional handle)
3274 "Put the the MIME part under point into a new buffer."
3276 (gnus-article-check-buffer)
3277 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3278 (contents (and handle (mm-get-part handle)))
3280 (file-name-nondirectory
3282 (mail-content-type-get (mm-handle-type handle) 'name)
3283 (mail-content-type-get (mm-handle-type handle)
3286 (buffer (and base (generate-new-buffer base))))
3288 (switch-to-buffer buffer)
3290 ;; We do it this way to make `normal-mode' set the appropriate mode.
3293 (setq buffer-file-name (expand-file-name base))
3295 (setq buffer-file-name nil))
3296 (goto-char (point-min)))))
3298 (defun gnus-mime-inline-part (&optional handle arg)
3299 "Insert the MIME part under point into the current buffer."
3300 (interactive (list nil current-prefix-arg))
3301 (gnus-article-check-buffer)
3302 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3307 (if (and (not arg) (mm-handle-undisplayer handle))
3308 (mm-remove-part handle)
3309 (setq contents (mm-get-part handle))
3312 (setq charset (or (mail-content-type-get
3313 (mm-handle-type handle) 'charset)
3314 gnus-newsgroup-charset)))
3316 (if (mm-handle-undisplayer handle)
3317 (mm-remove-part handle))
3320 gnus-summary-show-article-charset-alist))
3321 (read-coding-system "Charset: ")))))
3323 (mm-insert-inline handle
3325 (setq charset (mm-charset-to-coding-system
3327 (not (eq charset 'ascii)))
3328 (mm-decode-coding-string contents charset)
3332 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3333 "Insert the MIME part under point into the current buffer."
3334 (interactive (list nil current-prefix-arg))
3335 (gnus-article-check-buffer)
3336 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3341 (if (mm-handle-undisplayer handle)
3342 (mm-remove-part handle))
3343 (let ((gnus-newsgroup-charset
3345 gnus-summary-show-article-charset-alist))
3346 (read-coding-system "Charset: ")))
3347 (gnus-newsgroup-ignored-charsets 'gnus-all))
3348 (gnus-article-press-button)))))
3350 (defun gnus-mime-externalize-part (&optional handle)
3351 "View the MIME part under point with an external viewer."
3353 (gnus-article-check-buffer)
3354 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3355 (mm-user-display-methods nil)
3356 (mm-inlined-types nil)
3357 (mail-parse-charset gnus-newsgroup-charset)
3358 (mail-parse-ignored-charsets
3359 (save-excursion (set-buffer gnus-summary-buffer)
3360 gnus-newsgroup-ignored-charsets)))
3362 (if (mm-handle-undisplayer handle)
3363 (mm-remove-part handle)
3364 (mm-display-part handle)))))
3366 (defun gnus-mime-internalize-part (&optional handle)
3367 "View the MIME part under point with an internal viewer.
3368 In no internal viewer is available, use an external viewer."
3370 (gnus-article-check-buffer)
3371 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3372 (mm-inlined-types '(".*"))
3373 (mm-inline-large-images t)
3374 (mail-parse-charset gnus-newsgroup-charset)
3375 (mail-parse-ignored-charsets
3376 (save-excursion (set-buffer gnus-summary-buffer)
3377 gnus-newsgroup-ignored-charsets)))
3379 (if (mm-handle-undisplayer handle)
3380 (mm-remove-part handle)
3381 (mm-display-part handle)))))
3383 (defun gnus-mime-action-on-part (&optional action)
3384 "Do something with the MIME attachment at \(point\)."
3386 (list (completing-read "Action: " gnus-mime-action-alist)))
3387 (gnus-article-check-buffer)
3388 (let ((action-pair (assoc action gnus-mime-action-alist)))
3390 (funcall (cdr action-pair)))))
3392 (defun gnus-article-part-wrapper (n function)
3393 (save-current-buffer
3394 (set-buffer gnus-article-buffer)
3395 (when (> n (length gnus-article-mime-handle-alist))
3396 (error "No such part"))
3397 (gnus-article-goto-part n)
3398 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3399 (funcall function handle))))
3401 (defun gnus-article-pipe-part (n)
3402 "Pipe MIME part N, which is the numerical prefix."
3404 (gnus-article-part-wrapper n 'mm-pipe-part))
3406 (defun gnus-article-save-part (n)
3407 "Save MIME part N, which is the numerical prefix."
3409 (gnus-article-part-wrapper n 'mm-save-part))
3411 (defun gnus-article-interactively-view-part (n)
3412 "View MIME part N interactively, which is the numerical prefix."
3414 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3416 (defun gnus-article-copy-part (n)
3417 "Copy MIME part N, which is the numerical prefix."
3419 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3421 (defun gnus-article-view-part-as-charset (n)
3422 "Copy MIME part N, which is the numerical prefix."
3424 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3426 (defun gnus-article-externalize-part (n)
3427 "View MIME part N externally, which is the numerical prefix."
3429 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3431 (defun gnus-article-inline-part (n)
3432 "Inline MIME part N, which is the numerical prefix."
3434 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3436 (defun gnus-article-mime-match-handle-first (condition)
3438 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3439 (while (setq ihandle (pop alist))
3441 ((functionp condition)
3442 (funcall condition (cdr ihandle)))
3443 ((eq condition 'undisplayed)
3444 (not (or (mm-handle-undisplayer (cdr ihandle))
3445 (equal (mm-handle-media-type (cdr ihandle))
3446 "multipart/alternative"))))
3447 ((eq condition 'undisplayed-alternative)
3448 (not (mm-handle-undisplayer (cdr ihandle))))
3450 (gnus-article-goto-part (car ihandle))
3451 (or (not n) (< (car ihandle) n)))
3452 (setq n (car ihandle))))
3456 (defun gnus-article-view-part (&optional n)
3457 "View MIME part N, which is the numerical prefix."
3459 (save-current-buffer
3460 (set-buffer gnus-article-buffer)
3461 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3462 gnus-article-mime-match-handle-function)))
3463 (when (> n (length gnus-article-mime-handle-alist))
3464 (error "No such part"))
3465 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3466 (when (gnus-article-goto-part n)
3467 (if (equal (car handle) "multipart/alternative")
3468 (gnus-article-press-button)
3469 (when (eq (gnus-mm-display-part handle) 'internal)
3470 (gnus-set-window-start)))))))
3472 (defsubst gnus-article-mime-total-parts ()
3473 (if (bufferp (car gnus-article-mime-handles))
3475 (1- (length gnus-article-mime-handles))))
3477 (defun gnus-mm-display-part (handle)
3478 "Display HANDLE and fix MIME button."
3479 (let ((id (get-text-property (point) 'gnus-part))
3484 (let ((window (selected-window))
3485 (mail-parse-charset gnus-newsgroup-charset)
3486 (mail-parse-ignored-charsets
3487 (save-excursion (set-buffer gnus-summary-buffer)
3488 gnus-newsgroup-ignored-charsets)))
3491 (let ((win (get-buffer-window (current-buffer) t))
3494 (select-window win))
3497 (if (mm-handle-displayed-p handle)
3498 ;; This will remove the part.
3499 (mm-display-part handle)
3501 (narrow-to-region (point) (1+ (point)))
3502 (mm-display-part handle)
3503 ;; We narrow to the part itself and
3504 ;; then call the treatment functions.
3505 (goto-char (point-min))
3507 (narrow-to-region (point) (point-max))
3510 (gnus-article-mime-total-parts)
3511 (mm-handle-media-type handle)))))
3512 (select-window window))))
3514 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3515 (gnus-insert-mime-button
3516 handle id (list (mm-handle-displayed-p handle)))
3517 (goto-char point))))
3519 (defun gnus-article-goto-part (n)
3520 "Go to MIME part N."
3521 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3523 (goto-char point))))
3525 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3526 (let ((gnus-tmp-name
3527 (or (mail-content-type-get (mm-handle-type handle)
3529 (mail-content-type-get (mm-handle-disposition handle)
3531 (mail-content-type-get (mm-handle-type handle)
3534 (gnus-tmp-type (mm-handle-media-type handle))
3535 (gnus-tmp-description
3536 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3539 (if (if displayed (car displayed)
3540 (mm-handle-displayed-p handle))
3542 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3544 gnus-tmp-type-long b e)
3545 (when (string-match ".*/" gnus-tmp-name)
3546 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3547 (setq gnus-tmp-type-long (concat gnus-tmp-type
3548 (and (not (equal gnus-tmp-name ""))
3549 (concat "; " gnus-tmp-name))))
3550 (or (equal gnus-tmp-description "")
3551 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3556 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3557 `(keymap ,gnus-mime-button-map
3558 ,@(if (>= (string-to-number emacs-version) 21)
3560 (list 'local-map gnus-mime-button-map))
3561 gnus-callback gnus-mm-display-part
3562 gnus-part ,gnus-tmp-id
3563 article-type annotation
3566 (widget-convert-button
3569 :action 'gnus-widget-press-button
3570 :button-keymap gnus-mime-button-map
3572 (lambda (widget/window &optional overlay pos)
3573 ;; Needed to properly clear the message due to a bug in
3574 ;; wid-edit (XEmacs only).
3575 (if (boundp 'help-echo-owns-message)
3576 (setq help-echo-owns-message t))
3578 "%S: %s the MIME part; %S: more options"
3579 (aref gnus-mouse-2 0)
3580 ;; XEmacs will get a single widget arg; Emacs 21 will get
3581 ;; window, overlay, position.
3582 (if (mm-handle-displayed-p
3584 (with-current-buffer (gnus-overlay-buffer overlay)
3585 (widget-get (widget-at (gnus-overlay-start overlay))
3587 (widget-get widget/window :mime-handle)))
3589 (aref gnus-down-mouse-3 0))))))
3591 (defun gnus-widget-press-button (elems el)
3592 (goto-char (widget-get elems :from))
3593 (gnus-article-press-button))
3595 (defvar gnus-displaying-mime nil)
3597 (defun gnus-display-mime (&optional ihandles)
3598 "Display the MIME parts."
3600 (save-selected-window
3601 (let ((window (get-buffer-window gnus-article-buffer))
3604 (select-window window)
3605 ;; We have to do this since selecting the window
3606 ;; may change the point. So we set the window point.
3607 (set-window-point window point)))
3608 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3609 buffer-read-only handle name type b e display)
3610 (when (and (not ihandles)
3611 (not gnus-displaying-mime))
3612 ;; Top-level call; we clean up.
3613 (when gnus-article-mime-handles
3614 (mm-destroy-parts gnus-article-mime-handles)
3615 (setq gnus-article-mime-handle-alist nil));; A trick.
3616 (setq gnus-article-mime-handles handles)
3617 ;; We allow users to glean info from the handles.
3618 (when gnus-article-mime-part-function
3619 (gnus-mime-part-function handles)))
3621 (or (not (stringp (car handles)))
3624 (when (and (not ihandles)
3625 (not gnus-displaying-mime))
3626 ;; Clean up for mime parts.
3628 (delete-region (point) (point-max)))
3629 (let ((gnus-displaying-mime t))
3630 (gnus-mime-display-part handles)))
3633 (narrow-to-region (point) (point-max))
3634 (gnus-treat-article nil 1 1)
3637 ;; Highlight the headers.
3641 (narrow-to-region (point-min) (point))
3642 (gnus-treat-article 'head))))))))
3644 (defvar gnus-mime-display-multipart-as-mixed nil)
3646 (defun gnus-mime-display-part (handle)
3649 ((not (stringp (car handle)))
3650 (gnus-mime-display-single handle))
3651 ;; User-defined multipart
3652 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3653 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3655 ;; multipart/alternative
3656 ((and (equal (car handle) "multipart/alternative")
3657 (not gnus-mime-display-multipart-as-mixed))
3658 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3659 (push (cons id handle) gnus-article-mime-handle-alist)
3660 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3661 ;; multipart/related
3662 ((and (equal (car handle) "multipart/related")
3663 (not gnus-mime-display-multipart-as-mixed))
3664 ;;;!!!We should find the start part, but we just default
3665 ;;;!!!to the first part.
3666 ;;(gnus-mime-display-part (cadr handle))
3667 ;;;!!! Most multipart/related is an HTML message plus images.
3668 ;;;!!! Unfortunately we are unable to let W3 display those
3669 ;;;!!! included images, so we just display it as a mixed multipart.
3670 (gnus-mime-display-mixed (cdr handle)))
3671 ((equal (car handle) "multipart/signed")
3672 (or (memq 'signed gnus-article-wash-types)
3673 (push 'signed gnus-article-wash-types))
3674 (gnus-mime-display-security handle))
3675 ((equal (car handle) "multipart/encrypted")
3676 (or (memq 'encrypted gnus-article-wash-types)
3677 (push 'encrypted gnus-article-wash-types))
3678 (gnus-mime-display-security handle))
3679 ;; Other multiparts are handled like multipart/mixed.
3681 (gnus-mime-display-mixed (cdr handle)))))
3683 (defun gnus-mime-part-function (handles)
3684 (if (stringp (car handles))
3685 (mapcar 'gnus-mime-part-function (cdr handles))
3686 (funcall gnus-article-mime-part-function handles)))
3688 (defun gnus-mime-display-mixed (handles)
3689 (mapcar 'gnus-mime-display-part handles))
3691 (defun gnus-mime-display-single (handle)
3692 (let ((type (mm-handle-media-type handle))
3693 (ignored gnus-ignored-mime-types)
3700 (when (string-match (pop ignored) type)
3701 (throw 'ignored nil)))
3702 (if (and (setq not-attachment
3703 (and (not (mm-inline-override-p handle))
3704 (or (not (mm-handle-disposition handle))
3705 (equal (car (mm-handle-disposition handle))
3707 (mm-attachment-override-p handle))))
3708 (mm-automatic-display-p handle)
3709 (or (mm-inlined-p handle)
3710 (mm-automatic-external-display-p type)))
3712 (when (equal (mm-handle-media-supertype handle) "text")
3714 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3716 (push (cons id handle) gnus-article-mime-handle-alist)
3717 (when (or (not display)
3718 (not (gnus-unbuttonized-mime-type-p type)))
3719 ;(gnus-article-insert-newline)
3720 (gnus-insert-mime-button
3721 handle id (list (or display (and not-attachment text))))
3722 (gnus-article-insert-newline)
3723 ;(gnus-article-insert-newline)
3724 ;; Remember modify the number of forward lines.
3732 (let ((mail-parse-charset gnus-newsgroup-charset)
3733 (mail-parse-ignored-charsets
3734 (save-excursion (condition-case ()
3735 (set-buffer gnus-summary-buffer)
3737 gnus-newsgroup-ignored-charsets)))
3738 (mm-display-part handle t))
3739 (goto-char (point-max)))
3740 ((and text not-attachment)
3744 (gnus-article-insert-newline)
3745 (mm-insert-inline handle (mm-get-part handle))
3746 (goto-char (point-max))))
3750 (narrow-to-region beg (point))
3753 (gnus-article-mime-total-parts)
3754 (mm-handle-media-type handle)))))))))
3756 (defun gnus-unbuttonized-mime-type-p (type)
3757 "Say whether TYPE is to be unbuttonized."
3758 (unless gnus-inhibit-mime-unbuttonizing
3760 (let ((types gnus-unbuttonized-mime-types))
3762 (when (string-match (pop types) type)
3763 (throw 'found t)))))))
3765 (defun gnus-article-insert-newline ()
3766 "Insert a newline, but mark it as undeletable."
3767 (gnus-put-text-property
3768 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3770 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3771 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3774 handle buffer-read-only from props begend not-pref)
3775 (save-window-excursion
3778 (narrow-to-region (car ibegend)
3781 (goto-char (car ibegend))
3784 (delete-region (point-min) (point-max))
3785 (mm-remove-parts handles))
3786 (setq begend (list (point-marker)))
3788 (unless (setq not-pref (cadr (member preferred ihandles)))
3789 (setq not-pref (car ihandles)))
3792 (not (gnus-unbuttonized-mime-type-p
3793 "multipart/alternative")))
3794 (gnus-add-text-properties
3797 (insert (format "%d. " id))
3801 (unless ,(not ibegend)
3802 (setq gnus-article-mime-handle-alist
3803 ',gnus-article-mime-handle-alist))
3804 (gnus-mime-display-alternative
3805 ',ihandles ',not-pref ',begend ,id))
3806 ,@(if (>= (string-to-number emacs-version) 21)
3807 nil ;; XEmacs doesn't care
3808 (list 'local-map gnus-mime-button-map))
3809 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3810 face ,gnus-article-button-face
3811 keymap ,gnus-mime-button-map
3814 (widget-convert-button 'link from (point)
3815 :action 'gnus-widget-press-button
3816 :button-keymap gnus-widget-button-keymap)
3818 (while (setq handle (pop handles))
3819 (gnus-add-text-properties
3822 (insert (format "(%c) %-18s"
3823 (if (equal handle preferred) ?* ? )
3824 (mm-handle-media-type handle)))
3828 (unless ,(not ibegend)
3829 (setq gnus-article-mime-handle-alist
3830 ',gnus-article-mime-handle-alist))
3831 (gnus-mime-display-alternative
3832 ',ihandles ',handle ',begend ,id))
3833 ,@(if (>= (string-to-number emacs-version) 21)
3834 nil ;; XEmacs doesn't care
3835 (list 'local-map gnus-mime-button-map))
3836 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3837 face ,gnus-article-button-face
3838 keymap ,gnus-mime-button-map
3841 (widget-convert-button 'link from (point)
3842 :action 'gnus-widget-press-button
3843 :button-keymap gnus-widget-button-keymap)
3847 (if (stringp (car preferred))
3848 (gnus-display-mime preferred)
3849 (let ((mail-parse-charset gnus-newsgroup-charset)
3850 (mail-parse-ignored-charsets
3851 (save-excursion (set-buffer gnus-summary-buffer)
3852 gnus-newsgroup-ignored-charsets)))
3853 (mm-display-part preferred)
3857 (narrow-to-region (car begend) (point-max))
3859 nil (length gnus-article-mime-handle-alist)
3860 (gnus-article-mime-total-parts)
3861 (mm-handle-media-type handle))))))
3862 (goto-char (point-max))
3863 (setcdr begend (point-marker)))))
3865 (goto-char point))))
3867 (defun gnus-article-wash-status ()
3868 "Return a string which display status of article washing."
3870 (set-buffer gnus-article-buffer)
3871 (let ((cite (memq 'cite gnus-article-wash-types))
3872 (headers (memq 'headers gnus-article-wash-types))
3873 (boring (memq 'boring-headers gnus-article-wash-types))
3874 (pgp (memq 'pgp gnus-article-wash-types))
3875 (pem (memq 'pem gnus-article-wash-types))
3876 (signed (memq 'signed gnus-article-wash-types))
3877 (encrypted (memq 'encrypted gnus-article-wash-types))
3878 (signature (memq 'signature gnus-article-wash-types))
3879 (overstrike (memq 'overstrike gnus-article-wash-types))
3880 (emphasis (memq 'emphasis gnus-article-wash-types)))
3881 (format "%c%c%c%c%c%c"
3883 (if (or headers boring) ?h ? )
3884 (if (or pgp pem signed encrypted) ?p ? )
3885 (if signature ?s ? )
3886 (if overstrike ?o ? )
3887 (if emphasis ?e ? )))))
3889 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3891 (defun gnus-article-maybe-hide-headers ()
3892 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3893 Provided for backwards compatibility."
3894 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3895 (not (save-excursion (set-buffer gnus-summary-buffer)
3896 gnus-have-all-headers)))
3897 (not gnus-inhibit-hiding))
3898 (gnus-article-hide-headers)))
3902 (defun gnus-output-to-file (file-name)
3903 "Append the current article to a file named FILE-NAME."
3904 (let ((artbuf (current-buffer)))
3906 (insert-buffer-substring artbuf)
3907 ;; Append newline at end of the buffer as separator, and then
3909 (goto-char (point-max))
3911 (mm-append-to-file (point-min) (point-max) file-name)
3914 (defun gnus-narrow-to-page (&optional arg)
3915 "Narrow the article buffer to a page.
3916 If given a numerical ARG, move forward ARG pages."
3918 (setq arg (if arg (prefix-numeric-value arg) 0))
3920 (set-buffer gnus-article-buffer)
3921 (goto-char (point-min))
3923 ;; Remove any old next/prev buttons.
3924 (when (gnus-visual-p 'page-marker)
3925 (let ((buffer-read-only nil))
3926 (gnus-remove-text-with-property 'gnus-prev)
3927 (gnus-remove-text-with-property 'gnus-next)))
3930 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3932 (re-search-forward page-delimiter nil 'move arg)))
3933 (goto-char (match-end 0)))
3936 (if (re-search-forward page-delimiter nil 'move)
3939 (when (and (gnus-visual-p 'page-marker)
3940 (not (= (point-min) 1)))
3942 (goto-char (point-min))
3943 (gnus-insert-prev-page-button)))
3944 (when (and (gnus-visual-p 'page-marker)
3945 (< (+ (point-max) 2) (buffer-size)))
3947 (goto-char (point-max))
3948 (gnus-insert-next-page-button)))))
3950 ;; Article mode commands
3952 (defun gnus-article-goto-next-page ()
3953 "Show the next page of the article."
3955 (when (gnus-article-next-page)
3956 (goto-char (point-min))
3957 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
3959 (defun gnus-article-goto-prev-page ()
3960 "Show the next page of the article."
3962 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
3963 (gnus-article-prev-page nil)))
3965 (defun gnus-article-next-page (&optional lines)
3966 "Show the next page of the current article.
3967 If end of article, return non-nil. Otherwise return nil.
3968 Argument LINES specifies lines to be scrolled up."
3970 (move-to-window-line -1)
3973 (and (pos-visible-in-window-p) ;Not continuation line.
3975 ;; Nothing in this page.
3976 (if (or (not gnus-page-broken)
3979 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
3981 (gnus-narrow-to-page 1) ;Go to next page.
3983 ;; More in this page.
3984 (let ((scroll-in-place nil))
3988 ;; Long lines may cause an end-of-buffer error.
3989 (goto-char (point-max)))))
3990 (move-to-window-line 0)
3993 (defun gnus-article-prev-page (&optional lines)
3994 "Show previous page of current article.
3995 Argument LINES specifies lines to be scrolled down."
3997 (move-to-window-line 0)
3998 (if (and gnus-page-broken
4000 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4002 (gnus-narrow-to-page -1) ;Go to previous page.
4003 (goto-char (point-max))
4005 (let ((scroll-in-place nil))
4009 (beginning-of-buffer
4010 (goto-char (point-min))))
4011 (move-to-window-line 0)))))
4013 (defun gnus-article-refer-article ()
4014 "Read article specified by message-id around point."
4016 (let ((point (point)))
4017 (search-forward ">" nil t) ;Move point to end of "<....>".
4018 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4019 (let ((message-id (match-string 1)))
4021 (set-buffer gnus-summary-buffer)
4022 (gnus-summary-refer-article message-id))
4024 (error "No references around point"))))
4026 (defun gnus-article-show-summary ()
4027 "Reconfigure windows to show summary buffer."
4029 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4030 (error "There is no summary buffer for this article buffer")
4031 (gnus-article-set-globals)
4032 (gnus-configure-windows 'article)
4033 (gnus-summary-goto-subject gnus-current-article)
4034 (gnus-summary-position-point)))
4036 (defun gnus-article-describe-briefly ()
4037 "Describe article mode commands briefly."
4039 (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")))
4041 (defun gnus-article-summary-command ()
4042 "Execute the last keystroke in the summary buffer."
4044 (let ((obuf (current-buffer))
4045 (owin (current-window-configuration))
4047 (switch-to-buffer gnus-article-current-summary 'norecord)
4048 (setq func (lookup-key (current-local-map) (this-command-keys)))
4049 (call-interactively func)
4051 (set-window-configuration owin)
4052 (set-window-point (get-buffer-window (current-buffer)) (point))))
4054 (defun gnus-article-summary-command-nosave ()
4055 "Execute the last keystroke in the summary buffer."
4058 (pop-to-buffer gnus-article-current-summary 'norecord)
4059 (setq func (lookup-key (current-local-map) (this-command-keys)))
4060 (call-interactively func)))
4062 (defun gnus-article-check-buffer ()
4063 "Beep if not in an article buffer."
4064 (unless (equal major-mode 'gnus-article-mode)
4065 (error "Command invoked outside of a Gnus article buffer")))
4067 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4068 "Read a summary buffer key sequence and execute it from the article buffer."
4070 (gnus-article-check-buffer)
4072 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4073 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4074 "=" "^" "\M-^" "|"))
4080 '("n" "Gn" "p" "Gp"))
4083 (set-buffer gnus-article-current-summary)
4084 (let (gnus-pick-mode)
4085 (push (or key last-command-event) unread-command-events)
4086 (setq keys (if (featurep 'xemacs)
4087 (events-to-keys (read-key-sequence nil))
4088 (read-key-sequence nil)))))
4092 (if (or (member keys nosaves)
4093 (member keys nosave-but-article)
4094 (member keys nosave-in-article))
4096 (save-window-excursion
4097 (pop-to-buffer gnus-article-current-summary 'norecord)
4098 ;; We disable the pick minor mode commands.
4099 (let (gnus-pick-mode)
4100 (setq func (lookup-key (current-local-map) keys))))
4104 (unless (member keys nosave-in-article)
4105 (set-buffer gnus-article-current-summary))
4106 (call-interactively func)
4107 (setq new-sum-point (point)))
4108 (when (member keys nosave-but-article)
4109 (pop-to-buffer gnus-article-buffer 'norecord)))
4110 ;; These commands should restore window configuration.
4111 (let ((obuf (current-buffer))
4112 (owin (current-window-configuration))
4114 (summary gnus-article-current-summary)
4115 func in-buffer selected)
4116 (if not-restore-window
4117 (pop-to-buffer summary 'norecord)
4118 (switch-to-buffer summary 'norecord))
4119 (setq in-buffer (current-buffer))
4120 ;; We disable the pick minor mode commands.
4121 (if (and (setq func (let (gnus-pick-mode)
4122 (lookup-key (current-local-map) keys)))
4125 (call-interactively func)
4126 (setq new-sum-point (point))
4127 (when (eq in-buffer (current-buffer))
4128 (setq selected (gnus-summary-select-article))
4130 (unless not-restore-window
4131 (set-window-configuration owin))
4132 (when (eq selected 'old)
4134 (set-window-start (get-buffer-window (current-buffer))
4136 (set-window-point (get-buffer-window (current-buffer))
4138 (let ((win (get-buffer-window gnus-article-current-summary)))
4140 (set-window-point win new-sum-point)))) )
4141 (switch-to-buffer gnus-article-buffer)
4144 (defun gnus-article-describe-key (key)
4145 "Display documentation of the function invoked by KEY. KEY is a string."
4146 (interactive "kDescribe key: ")
4147 (gnus-article-check-buffer)
4148 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4150 (set-buffer gnus-article-current-summary)
4151 (let (gnus-pick-mode)
4152 (push (elt key 0) unread-command-events)
4153 (setq key (if (featurep 'xemacs)
4154 (events-to-keys (read-key-sequence "Describe key: "))
4155 (read-key-sequence "Describe key: "))))
4157 (describe-key key)))
4159 (defun gnus-article-describe-key-briefly (key &optional insert)
4160 "Display documentation of the function invoked by KEY. KEY is a string."
4161 (interactive "kDescribe key: \nP")
4162 (gnus-article-check-buffer)
4163 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4165 (set-buffer gnus-article-current-summary)
4166 (let (gnus-pick-mode)
4167 (push (elt key 0) unread-command-events)
4168 (setq key (if (featurep 'xemacs)
4169 (events-to-keys (read-key-sequence "Describe key: "))
4170 (read-key-sequence "Describe key: "))))
4171 (describe-key-briefly key insert))
4172 (describe-key-briefly key insert)))
4174 (defun gnus-article-hide (&optional arg force)
4175 "Hide all the gruft in the current article.
4176 This means that PGP stuff, signatures, cited text and (some)
4177 headers will be hidden.
4178 If given a prefix, show the hidden text instead."
4179 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4180 (gnus-article-hide-headers arg)
4181 (gnus-article-hide-list-identifiers arg)
4182 (gnus-article-hide-pgp arg)
4183 (gnus-article-hide-citation-maybe arg force)
4184 (gnus-article-hide-signature arg))
4186 (defun gnus-article-maybe-highlight ()
4187 "Do some article highlighting if article highlighting is requested."
4188 (when (gnus-visual-p 'article-highlight 'highlight)
4189 (gnus-article-highlight-some)))
4191 (defun gnus-check-group-server ()
4192 ;; Make sure the connection to the server is alive.
4193 (unless (gnus-server-opened
4194 (gnus-find-method-for-group gnus-newsgroup-name))
4195 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4196 (gnus-request-group gnus-newsgroup-name t)))
4198 (defun gnus-request-article-this-buffer (article group)
4199 "Get an article and insert it into this buffer."
4200 (let (do-update-line sparse-header)
4204 (gnus-kill-all-overlays)
4205 (setq group (or group gnus-newsgroup-name))
4207 ;; Using `gnus-request-article' directly will insert the article into
4208 ;; `nntp-server-buffer' - so we'll save some time by not having to
4209 ;; copy it from the server buffer into the article buffer.
4211 ;; We only request an article by message-id when we do not have the
4212 ;; headers for it, so we'll have to get those.
4213 (when (stringp article)
4214 (gnus-read-header article))
4216 ;; If the article number is negative, that means that this article
4217 ;; doesn't belong in this newsgroup (possibly), so we find its
4218 ;; message-id and request it by id instead of number.
4219 (when (and (numberp article)
4221 (get-buffer gnus-summary-buffer)
4222 (gnus-buffer-exists-p gnus-summary-buffer))
4224 (set-buffer gnus-summary-buffer)
4225 (let ((header (gnus-summary-article-header article)))
4228 ((memq article gnus-newsgroup-sparse)
4229 ;; This is a sparse gap article.
4230 (setq do-update-line article)
4231 (setq article (mail-header-id header))
4232 (setq sparse-header (gnus-read-header article))
4233 (setq gnus-newsgroup-sparse
4234 (delq article gnus-newsgroup-sparse)))
4236 ;; It's a real article.
4237 (setq article (mail-header-id header)))
4239 ;; It is an extracted pseudo-article.
4240 (setq article 'pseudo)
4241 (gnus-request-pseudo-article header))))
4243 (let ((method (gnus-find-method-for-group
4244 gnus-newsgroup-name)))
4245 (when (and (eq (car method) 'nneething)
4247 (let ((dir (expand-file-name
4248 (mail-header-subject header)
4249 (file-name-as-directory
4250 (or (cadr (assq 'nneething-address method))
4252 (when (file-directory-p dir)
4253 (setq article 'nneething)
4254 (gnus-group-enter-directory dir))))))))
4257 ;; Refuse to select canceled articles.
4258 ((and (numberp article)
4260 (get-buffer gnus-summary-buffer)
4261 (gnus-buffer-exists-p gnus-summary-buffer)
4262 (eq (cdr (save-excursion
4263 (set-buffer gnus-summary-buffer)
4264 (assq article gnus-newsgroup-reads)))
4265 gnus-canceled-mark))
4267 ;; We first check `gnus-original-article-buffer'.
4268 ((and (get-buffer gnus-original-article-buffer)
4271 (set-buffer gnus-original-article-buffer)
4272 (and (equal (car gnus-original-article) group)
4273 (eq (cdr gnus-original-article) article))))
4274 (insert-buffer-substring gnus-original-article-buffer)
4276 ;; Check the backlog.
4277 ((and gnus-keep-backlog
4278 (gnus-backlog-request-article group article (current-buffer)))
4280 ;; Check asynchronous pre-fetch.
4281 ((gnus-async-request-fetched-article group article (current-buffer))
4282 (gnus-async-prefetch-next group article gnus-summary-buffer)
4283 (when (and (numberp article) gnus-keep-backlog)
4284 (gnus-backlog-enter-article group article (current-buffer)))
4287 ((and gnus-use-cache
4289 (gnus-cache-request-article article group))
4291 ;; Get the article and put into the article buffer.
4292 ((or (stringp article)
4294 (let ((gnus-override-method gnus-override-method)
4295 (methods (and (stringp article)
4296 gnus-refer-article-method))
4298 (buffer-read-only nil))
4299 (if (or (not (listp methods))
4300 (and (symbolp (car methods))
4301 (assq (car methods) nnoo-definition-alist)))
4302 (setq methods (list methods)))
4303 (when (and (null gnus-override-method)
4305 (setq gnus-override-method (pop methods)))
4307 (when (eq gnus-override-method 'current)
4308 (setq gnus-override-method gnus-current-select-method))
4310 (gnus-kill-all-overlays)
4311 (let ((gnus-newsgroup-name group))
4312 (gnus-check-group-server))
4313 (when (gnus-request-article article group (current-buffer))
4314 (when (numberp article)
4315 (gnus-async-prefetch-next group article
4316 gnus-summary-buffer)
4317 (when gnus-keep-backlog
4318 (gnus-backlog-enter-article
4319 group article (current-buffer))))
4320 (setq result 'article))
4323 (setq gnus-override-method (pop methods))
4324 (setq result 'done))))
4325 (and (eq result 'article) 'article)))
4329 ;; Associate this article with the current summary buffer.
4330 (setq gnus-article-current-summary gnus-summary-buffer)
4332 ;; Take the article from the original article buffer
4333 ;; and place it in the buffer it's supposed to be in.
4334 (when (and (get-buffer gnus-article-buffer)
4335 (equal (buffer-name (current-buffer))
4336 (buffer-name (get-buffer gnus-article-buffer))))
4338 (if (get-buffer gnus-original-article-buffer)
4339 (set-buffer gnus-original-article-buffer)
4340 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4341 (buffer-disable-undo)
4342 (setq major-mode 'gnus-original-article-mode)
4343 (setq buffer-read-only t))
4344 (let (buffer-read-only)
4346 (insert-buffer-substring gnus-article-buffer))
4347 (setq gnus-original-article (cons group article)))
4350 (run-hooks 'gnus-article-decode-hook)
4351 ;; Mark article as decoded or not.
4352 (setq gnus-article-decoded-p gnus-article-decode-hook))
4354 ;; Update sparse articles.
4355 (when (and do-update-line
4356 (or (numberp article)
4358 (let ((buf (current-buffer)))
4359 (set-buffer gnus-summary-buffer)
4360 (gnus-summary-update-article do-update-line sparse-header)
4361 (gnus-summary-goto-subject do-update-line nil t)
4362 (set-window-point (get-buffer-window (current-buffer) t)
4364 (set-buffer buf))))))
4370 (defcustom gnus-article-edit-mode-hook nil
4371 "Hook run in article edit mode buffers."
4372 :group 'gnus-article-various
4375 (defvar gnus-article-edit-done-function nil)
4377 (defvar gnus-article-edit-mode-map nil)
4379 ;; Should we be using derived.el for this?
4380 (unless gnus-article-edit-mode-map
4381 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4382 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4384 (gnus-define-keys gnus-article-edit-mode-map
4385 "\C-c\C-c" gnus-article-edit-done
4386 "\C-c\C-k" gnus-article-edit-exit)
4388 (gnus-define-keys (gnus-article-edit-wash-map
4389 "\C-c\C-w" gnus-article-edit-mode-map)
4390 "f" gnus-article-edit-full-stops))
4392 (defun gnus-article-edit-mode ()
4393 "Major mode for editing articles.
4394 This is an extended text-mode.
4396 \\{gnus-article-edit-mode-map}"
4398 (setq major-mode 'gnus-article-edit-mode)
4399 (setq mode-name "Article Edit")
4400 (use-local-map gnus-article-edit-mode-map)
4401 (make-local-variable 'gnus-article-edit-done-function)
4402 (make-local-variable 'gnus-prev-winconf)
4403 (setq buffer-read-only nil)
4404 (buffer-enable-undo)
4406 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4408 (defun gnus-article-edit (&optional force)
4409 "Edit the current article.
4410 This will have permanent effect only in mail groups.
4411 If FORCE is non-nil, allow editing of articles even in read-only
4414 (when (and (not force)
4415 (gnus-group-read-only-p))
4416 (error "The current newsgroup does not support article editing"))
4417 (gnus-article-date-original)
4418 (gnus-article-edit-article
4420 `(lambda (no-highlight)
4422 (gnus-summary-edit-article-done
4423 ,(or (mail-header-references gnus-current-headers) "")
4424 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4426 (defun gnus-article-edit-article (start-func exit-func)
4427 "Start editing the contents of the current article buffer."
4428 (let ((winconf (current-window-configuration)))
4429 (set-buffer gnus-article-buffer)
4430 (gnus-article-edit-mode)
4431 (funcall start-func)
4432 (gnus-configure-windows 'edit-article)
4433 (setq gnus-article-edit-done-function exit-func)
4434 (setq gnus-prev-winconf winconf)
4435 (gnus-message 6 "C-c C-c to end edits")))
4437 (defun gnus-article-edit-done (&optional arg)
4438 "Update the article edits and exit."
4440 (let ((func gnus-article-edit-done-function)
4441 (buf (current-buffer))
4442 (start (window-start)))
4443 (gnus-article-edit-exit)
4446 (let ((buffer-read-only nil))
4448 ;; The cache and backlog have to be flushed somewhat.
4449 (when gnus-keep-backlog
4450 (gnus-backlog-remove-article
4451 (car gnus-article-current) (cdr gnus-article-current)))
4452 ;; Flush original article as well.
4454 (when (get-buffer gnus-original-article-buffer)
4455 (set-buffer gnus-original-article-buffer)
4456 (setq gnus-original-article nil)))
4457 (when gnus-use-cache
4458 (gnus-cache-update-article
4459 (car gnus-article-current) (cdr gnus-article-current))))
4461 (set-window-start (get-buffer-window buf) start)
4462 (set-window-point (get-buffer-window buf) (point))))
4464 (defun gnus-article-edit-exit ()
4465 "Exit the article editing without updating."
4467 ;; We remove all text props from the article buffer.
4468 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4469 (curbuf (current-buffer))
4471 (window-start (window-start)))
4474 (let ((winconf gnus-prev-winconf))
4476 (set-window-configuration winconf)
4477 ;; Tippy-toe some to make sure that point remains where it was.
4478 (save-current-buffer
4480 (set-window-start (get-buffer-window (current-buffer)) window-start)
4483 (defun gnus-article-edit-full-stops ()
4484 "Interactively repair spacing at end of sentences."
4487 (goto-char (point-min))
4488 (search-forward-regexp "^$" nil t)
4489 (let ((case-fold-search nil))
4490 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4493 ;;; Article highlights
4496 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4498 ;;; Internal Variables:
4500 (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\\)\\)"
4501 "Regular expression that matches URLs."
4502 :group 'gnus-article-buttons
4505 (defcustom gnus-button-alist
4506 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4507 0 t gnus-button-message-id 2)
4508 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4509 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4511 gnus-button-fetch-group 4)
4512 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4513 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4514 t gnus-button-message-id 3)
4515 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4516 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4517 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4518 ;; This is how URLs _should_ be embedded in text...
4519 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4521 (,gnus-button-url-regexp 0 t browse-url 0))
4522 "*Alist of regexps matching buttons in article bodies.
4524 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4525 REGEXP: is the string matching text around the button,
4526 BUTTON: is the number of the regexp grouping actually matching the button,
4527 FORM: is a lisp expression which must eval to true for the button to
4529 CALLBACK: is the function to call when the user push this button, and each
4530 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4532 CALLBACK can also be a variable, in that case the value of that
4533 variable it the real callback function."
4534 :group 'gnus-article-buttons
4535 :type '(repeat (list regexp
4536 (integer :tag "Button")
4538 (function :tag "Callback")
4541 (integer :tag "Regexp group")))))
4543 (defcustom gnus-header-button-alist
4544 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4545 0 t gnus-button-message-id 0)
4546 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4547 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4548 0 t gnus-button-mailto 0)
4549 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4550 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4551 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4552 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4553 gnus-button-message-id 3))
4554 "*Alist of headers and regexps to match buttons in article heads.
4556 This alist is very similar to `gnus-button-alist', except that each
4557 alist has an additional HEADER element first in each entry:
4559 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4561 HEADER is a regexp to match a header. For a fuller explanation, see
4562 `gnus-button-alist'."
4563 :group 'gnus-article-buttons
4564 :group 'gnus-article-headers
4565 :type '(repeat (list (regexp :tag "Header")
4567 (integer :tag "Button")
4569 (function :tag "Callback")
4572 (integer :tag "Regexp group")))))
4574 (defvar gnus-button-regexp nil)
4575 (defvar gnus-button-marker-list nil)
4576 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4578 (defvar gnus-button-last nil)
4579 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4583 (defun gnus-article-push-button (event)
4584 "Check text under the mouse pointer for a callback function.
4585 If the text under the mouse pointer has a `gnus-callback' property,
4586 call it with the value of the `gnus-data' text property."
4588 (set-buffer (window-buffer (posn-window (event-start event))))
4589 (let* ((pos (posn-point (event-start event)))
4590 (data (get-text-property pos 'gnus-data))
4591 (fun (get-text-property pos 'gnus-callback)))
4594 (funcall fun data))))
4596 (defun gnus-article-press-button ()
4597 "Check text at point for a callback function.
4598 If the text at point has a `gnus-callback' property,
4599 call it with the value of the `gnus-data' text property."
4601 (let* ((data (get-text-property (point) 'gnus-data))
4602 (fun (get-text-property (point) 'gnus-callback)))
4604 (funcall fun data))))
4606 (defun gnus-article-highlight (&optional force)
4607 "Highlight current article.
4608 This function calls `gnus-article-highlight-headers',
4609 `gnus-article-highlight-citation',
4610 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4611 do the highlighting. See the documentation for those functions."
4612 (interactive (list 'force))
4613 (gnus-article-highlight-headers)
4614 (gnus-article-highlight-citation force)
4615 (gnus-article-highlight-signature)
4616 (gnus-article-add-buttons force)
4617 (gnus-article-add-buttons-to-head))
4619 (defun gnus-article-highlight-some (&optional force)
4620 "Highlight current article.
4621 This function calls `gnus-article-highlight-headers',
4622 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4623 do the highlighting. See the documentation for those functions."
4624 (interactive (list 'force))
4625 (gnus-article-highlight-headers)
4626 (gnus-article-highlight-signature)
4627 (gnus-article-add-buttons))
4629 (defun gnus-article-highlight-headers ()
4630 "Highlight article headers as specified by `gnus-header-face-alist'."
4633 (set-buffer gnus-article-buffer)
4635 (let ((alist gnus-header-face-alist)
4636 (buffer-read-only nil)
4637 (case-fold-search t)
4638 (inhibit-point-motion-hooks t)
4639 entry regexp header-face field-face from hpoints fpoints)
4640 (article-narrow-to-head)
4641 (while (setq entry (pop alist))
4642 (goto-char (point-min))
4643 (setq regexp (concat "^\\("
4644 (if (string-equal "" (nth 0 entry))
4648 header-face (nth 1 entry)
4649 field-face (nth 2 entry))
4650 (while (and (re-search-forward regexp nil t)
4654 (unless (search-forward ":" nil t)
4656 (when (and header-face
4657 (not (memq (point) hpoints)))
4658 (push (point) hpoints)
4659 (gnus-put-text-property from (point) 'face header-face))
4660 (when (and field-face
4661 (not (memq (setq from (point)) fpoints)))
4663 (if (re-search-forward "^[^ \t]" nil t)
4665 (goto-char (point-max)))
4666 (gnus-put-text-property from (point) 'face field-face))))))))
4668 (defun gnus-article-highlight-signature ()
4669 "Highlight the signature in an article.
4670 It does this by highlighting everything after
4671 `gnus-signature-separator' using `gnus-signature-face'."
4674 (set-buffer gnus-article-buffer)
4675 (let ((buffer-read-only nil)
4676 (inhibit-point-motion-hooks t))
4678 (when (and gnus-signature-face
4679 (gnus-article-narrow-to-signature))
4680 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4681 'face gnus-signature-face)
4683 (gnus-article-search-signature)
4684 (let ((start (match-beginning 0))
4685 (end (set-marker (make-marker) (1+ (match-end 0)))))
4686 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4689 (defun gnus-button-in-region-p (b e prop)
4690 "Say whether PROP exists in the region."
4691 (text-property-not-all b e prop nil))
4693 (defun gnus-article-add-buttons (&optional force)
4694 "Find external references in the article and make buttons of them.
4695 \"External references\" are things like Message-IDs and URLs, as
4696 specified by `gnus-button-alist'."
4697 (interactive (list 'force))
4699 (set-buffer gnus-article-buffer)
4700 (let ((buffer-read-only nil)
4701 (inhibit-point-motion-hooks t)
4702 (case-fold-search t)
4703 (alist gnus-button-alist)
4705 ;; Remove all old markers.
4706 (let (marker entry new-list)
4707 (while (setq marker (pop gnus-button-marker-list))
4708 (if (or (< marker (point-min)) (>= marker (point-max)))
4709 (push marker new-list)
4711 (when (setq entry (gnus-button-entry))
4712 (put-text-property (match-beginning (nth 1 entry))
4713 (match-end (nth 1 entry))
4714 'gnus-callback nil))
4715 (set-marker marker nil)))
4716 (setq gnus-button-marker-list new-list))
4717 ;; We skip the headers.
4720 (while (setq entry (pop alist))
4721 (setq regexp (car entry))
4723 (while (re-search-forward regexp nil t)
4724 (let* ((start (and entry (match-beginning (nth 1 entry))))
4725 (end (and entry (match-end (nth 1 entry))))
4726 (from (match-beginning 0)))
4727 (when (and (or (eq t (nth 2 entry))
4728 (eval (nth 2 entry)))
4729 (not (gnus-button-in-region-p
4730 start end 'gnus-callback)))
4731 ;; That optional form returned non-nil, so we add the
4733 (gnus-article-add-button
4734 start end 'gnus-button-push
4735 (car (push (set-marker (make-marker) from)
4736 gnus-button-marker-list))))))))))
4738 ;; Add buttons to the head of an article.
4739 (defun gnus-article-add-buttons-to-head ()
4740 "Add buttons to the head of the article."
4743 (set-buffer gnus-article-buffer)
4745 (let ((buffer-read-only nil)
4746 (inhibit-point-motion-hooks t)
4747 (case-fold-search t)
4748 (alist gnus-header-button-alist)
4750 (article-narrow-to-head)
4752 ;; Each alist entry.
4753 (setq entry (car alist)
4755 (goto-char (point-min))
4756 (while (re-search-forward (car entry) nil t)
4757 ;; Each header matching the entry.
4758 (setq beg (match-beginning 0))
4759 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4760 (match-beginning 0))
4763 (while (re-search-forward (nth 1 entry) end t)
4764 ;; Each match within a header.
4765 (let* ((entry (cdr entry))
4766 (start (match-beginning (nth 1 entry)))
4767 (end (match-end (nth 1 entry)))
4768 (form (nth 2 entry)))
4769 (goto-char (match-end 0))
4771 (gnus-article-add-button
4772 start end (nth 3 entry)
4773 (buffer-substring (match-beginning (nth 4 entry))
4774 (match-end (nth 4 entry)))))))
4775 (goto-char end)))))))
4777 ;;; External functions:
4779 (defun gnus-article-add-button (from to fun &optional data)
4780 "Create a button between FROM and TO with callback FUN and data DATA."
4781 (when gnus-article-button-face
4782 (gnus-overlay-put (gnus-make-overlay from to)
4783 'face gnus-article-button-face))
4784 (gnus-add-text-properties
4786 (nconc (and gnus-article-mouse-face
4787 (list gnus-mouse-face-prop gnus-article-mouse-face))
4788 (list 'gnus-callback fun)
4789 (and data (list 'gnus-data data))))
4790 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4791 :button-keymap gnus-widget-button-keymap))
4793 ;;; Internal functions:
4795 (defun gnus-article-set-globals ()
4797 (set-buffer gnus-summary-buffer)
4798 (gnus-set-global-variables)))
4800 (defun gnus-signature-toggle (end)
4802 (set-buffer gnus-article-buffer)
4803 (let ((buffer-read-only nil)
4804 (inhibit-point-motion-hooks t))
4805 (if (text-property-any end (point-max) 'article-type 'signature)
4806 (gnus-remove-text-properties-when
4807 'article-type 'signature end (point-max)
4808 (cons 'article-type (cons 'signature
4809 gnus-hidden-properties)))
4810 (gnus-add-text-properties-when
4811 'article-type nil end (point-max)
4812 (cons 'article-type (cons 'signature
4813 gnus-hidden-properties)))))))
4815 (defun gnus-button-entry ()
4816 ;; Return the first entry in `gnus-button-alist' matching this place.
4817 (let ((alist gnus-button-alist)
4820 (setq entry (pop alist))
4821 (if (looking-at (car entry))
4826 (defun gnus-button-push (marker)
4827 ;; Push button starting at MARKER.
4830 (let* ((entry (gnus-button-entry))
4831 (inhibit-point-motion-hooks t)
4833 (args (mapcar (lambda (group)
4834 (let ((string (match-string group)))
4835 (gnus-set-text-properties
4836 0 (length string) nil string)
4843 (fboundp (symbol-value fun)))
4844 (apply (symbol-value fun) args))
4846 (gnus-message 1 "You must define `%S' to use this button"
4847 (cons fun args)))))))
4849 (defun gnus-button-message-id (message-id)
4852 (set-buffer gnus-summary-buffer)
4853 (gnus-summary-refer-article message-id)))
4855 (defun gnus-button-fetch-group (address)
4856 "Fetch GROUP specified by ADDRESS."
4857 (if (not (string-match "[:/]" address))
4858 ;; This is just a simple group url.
4859 (gnus-group-read-ephemeral-group address gnus-select-method)
4860 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4862 (error "Can't parse %s" address)
4863 (gnus-group-read-ephemeral-group
4864 (match-string 4 address)
4865 `(nntp ,(match-string 1 address)
4866 (nntp-address ,(match-string 1 address))
4867 (nntp-port-number ,(if (match-end 3)
4868 (match-string 3 address)
4871 (defun gnus-url-parse-query-string (query &optional downcase)
4872 (let (retval pairs cur key val)
4873 (setq pairs (split-string query "&"))
4875 (setq cur (car pairs)
4877 (if (not (string-match "=" cur))
4879 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4880 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4882 (setq key (downcase key)))
4883 (setq cur (assoc key retval))
4885 (setcdr cur (cons val (cdr cur)))
4886 (setq retval (cons (list key val) retval)))))
4889 (defun gnus-url-unhex (x)
4896 (defun gnus-url-unhex-string (str &optional allow-newlines)
4897 "Remove %XXX embedded spaces, etc in a url.
4898 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4899 decoding of carriage returns and line feeds in the string, which is normally
4900 forbidden in URL encoding."
4901 (setq str (or str ""))
4903 (case-fold-search t))
4904 (while (string-match "%[0-9a-f][0-9a-f]" str)
4905 (let* ((start (match-beginning 0))
4906 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4908 (gnus-url-unhex (elt str (+ start 2))))))
4910 tmp (substring str 0 start)
4913 (char-to-string code))
4914 ((or (= code ?\n) (= code ?\r))
4916 (t (char-to-string code))))
4917 str (substring str (match-end 0)))))
4918 (setq tmp (concat tmp str))
4921 (defun gnus-url-mailto (url)
4922 ;; Send mail to someone
4923 (when (string-match "mailto:/*\\(.*\\)" url)
4924 (setq url (substring url (match-beginning 1) nil)))
4925 (let (to args subject func)
4926 (if (string-match (regexp-quote "?") url)
4927 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4928 args (gnus-url-parse-query-string
4929 (substring url (match-end 0) nil) t))
4930 (setq to (gnus-url-unhex-string url)))
4931 (setq args (cons (list "to" to) args)
4932 subject (cdr-safe (assoc "subject" args)))
4935 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4938 (message-position-on-field (caar args)))
4939 (insert (mapconcat 'identity (cdar args) ", "))
4940 (setq args (cdr args)))
4943 (message-goto-subject))))
4945 (defun gnus-button-mailto (address)
4947 (set-buffer (gnus-copy-article-buffer))
4948 (message-reply address))
4950 (defalias 'gnus-button-reply 'message-reply)
4952 (defun gnus-button-embedded-url (address)
4953 "Activate ADDRESS with `browse-url'."
4954 (browse-url (gnus-strip-whitespace address)))
4956 ;;; Next/prev buttons in the article buffer.
4958 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
4959 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
4961 (defvar gnus-prev-page-map nil)
4962 (unless gnus-prev-page-map
4963 (setq gnus-prev-page-map (make-sparse-keymap))
4964 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
4965 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
4967 (defun gnus-insert-prev-page-button ()
4968 (let ((buffer-read-only nil))
4970 gnus-prev-page-line-format nil
4971 `(gnus-prev t local-map ,gnus-prev-page-map
4972 gnus-callback gnus-article-button-prev-page
4973 article-type annotation))))
4975 (defvar gnus-next-page-map nil)
4976 (unless gnus-next-page-map
4977 (setq gnus-next-page-map (make-keymap))
4978 (suppress-keymap gnus-prev-page-map)
4979 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
4980 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
4982 (defun gnus-button-next-page ()
4983 "Go to the next page."
4985 (let ((win (selected-window)))
4986 (select-window (get-buffer-window gnus-article-buffer t))
4987 (gnus-article-next-page)
4988 (select-window win)))
4990 (defun gnus-button-prev-page ()
4991 "Go to the prev page."
4993 (let ((win (selected-window)))
4994 (select-window (get-buffer-window gnus-article-buffer t))
4995 (gnus-article-prev-page)
4996 (select-window win)))
4998 (defun gnus-insert-next-page-button ()
4999 (let ((buffer-read-only nil))
5000 (gnus-eval-format gnus-next-page-line-format nil
5002 t local-map ,gnus-next-page-map
5003 gnus-callback gnus-article-button-next-page
5004 article-type annotation))))
5006 (defun gnus-article-button-next-page (arg)
5007 "Go to the next page."
5009 (let ((win (selected-window)))
5010 (select-window (get-buffer-window gnus-article-buffer t))
5011 (gnus-article-next-page)
5012 (select-window win)))
5014 (defun gnus-article-button-prev-page (arg)
5015 "Go to the prev page."
5017 (let ((win (selected-window)))
5018 (select-window (get-buffer-window gnus-article-buffer t))
5019 (gnus-article-prev-page)
5020 (select-window win)))
5022 (defvar gnus-decode-header-methods
5023 '(mail-decode-encoded-word-region)
5024 "List of methods used to decode headers.
5026 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5027 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5028 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5029 whose names match REGEXP.
5032 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5033 mail-decode-encoded-word-region
5034 (\"chinese\" . rfc1843-decode-region))
5037 (defvar gnus-decode-header-methods-cache nil)
5039 (defun gnus-multi-decode-header (start end)
5040 "Apply the functions from `gnus-encoded-word-methods' that match."
5041 (unless (and gnus-decode-header-methods-cache
5042 (eq gnus-newsgroup-name
5043 (car gnus-decode-header-methods-cache)))
5044 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5047 (nconc gnus-decode-header-methods-cache (list x))
5048 (if (and gnus-newsgroup-name
5049 (string-match (car x) gnus-newsgroup-name))
5050 (nconc gnus-decode-header-methods-cache
5052 gnus-decode-header-methods))
5053 (let ((xlist gnus-decode-header-methods-cache))
5056 (narrow-to-region start end)
5058 (funcall (pop xlist) (point-min) (point-max))))))
5061 ;;; Treatment top-level handling.
5064 (defun gnus-treat-article (condition &optional part-number total-parts type)
5065 (let ((length (- (point-max) (point-min)))
5066 (alist gnus-treatment-function-alist)
5067 (article-goto-body-goes-to-point-min-p t)
5071 (let ((list gnus-article-treat-types))
5073 (when (string-match (pop list) type)
5074 (throw 'found t)))))))
5075 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5077 (gnus-run-hooks 'gnus-part-display-hook)
5078 (while (setq elem (pop alist))
5081 (if (gnus-buffer-live-p gnus-summary-buffer)
5082 (set-buffer gnus-summary-buffer))
5083 (symbol-value (car elem))))
5084 (when (and (or (consp val)
5086 (gnus-treat-predicate val)
5087 (or (not (get (car elem) 'highlight))
5090 (funcall (cadr elem)))))))
5092 ;; Dynamic variables.
5094 (defvar part-number)
5095 (defvar total-parts)
5100 (defun gnus-treat-predicate (val)
5105 (stringp (car val)))
5106 (apply 'gnus-or (mapcar `(lambda (s)
5107 (string-match s ,(or gnus-newsgroup-name "")))
5110 (let ((pred (pop val)))
5113 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5115 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5117 (not (gnus-treat-predicate (car val))))
5119 (equal (car val) type))
5121 (error "%S is not a valid predicate" pred)))))
5129 (eq part-number total-parts))
5133 (error "%S is not a valid value" val))))
5135 (defun gnus-article-encrypt-body (protocol &optional n)
5136 "Encrypt the article body."
5139 (or gnus-article-encrypt-protocol
5140 (completing-read "Encrypt protocol: "
5141 gnus-article-encrypt-protocol-alist
5143 current-prefix-arg))
5144 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5146 (error (format "Can't find the encrypt protocol %s" protocol)))
5147 (if (equal gnus-newsgroup-name "nndraft:drafts")
5148 (error "Can't encrypt the article in group nndraft:drafts."))
5149 (if (equal gnus-newsgroup-name "nndraft:queue")
5150 (error "Don't encrypt the article in group nndraft:queue."))
5151 (gnus-summary-iterate n
5153 (set-buffer gnus-summary-buffer)
5154 (let ((mail-parse-charset gnus-newsgroup-charset)
5155 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5156 (summary-buffer gnus-summary-buffer)
5158 (gnus-set-global-variables)
5159 (when (gnus-group-read-only-p)
5160 (error "The current newsgroup does not support article encrypt"))
5161 (gnus-summary-show-article t)
5163 (or (mail-header-references gnus-current-headers) ""))
5164 (set-buffer gnus-article-buffer)
5165 (let* ((buffer-read-only nil)
5167 (mapcar (lambda (field)
5168 (and (save-restriction
5169 (message-narrow-to-head)
5170 (goto-char (point-min))
5171 (search-forward field nil t))
5173 (message-narrow-to-field)
5174 (buffer-substring (point-min) (point-max))
5175 (delete-region (point-min) (point-max))
5177 '("Content-Type:" "Content-Transfer-Encoding:"
5178 "Content-Disposition:"))))
5179 (message-narrow-to-head)
5180 (message-remove-header "MIME-Version")
5181 (goto-char (point-max))
5182 (setq point (point))
5183 (insert (apply 'concat headers))
5185 (narrow-to-region point (point-max))
5186 (let ((message-options message-options))
5187 (message-options-set 'message-sender user-mail-address)
5188 (message-options-set 'message-recipients user-mail-address)
5189 (message-options-set 'message-sign-encrypt 'not)
5191 (goto-char (point-min))
5192 (insert "MIME-Version: 1.0\n")
5194 (gnus-summary-edit-article-done
5195 references nil summary-buffer t))
5196 (when gnus-keep-backlog
5197 (gnus-backlog-remove-article
5198 (car gnus-article-current) (cdr gnus-article-current)))
5200 (when (get-buffer gnus-original-article-buffer)
5201 (set-buffer gnus-original-article-buffer)
5202 (setq gnus-original-article nil)))
5203 (when gnus-use-cache
5204 (gnus-cache-update-article
5205 (car gnus-article-current) (cdr gnus-article-current))))))))
5207 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5208 "The following specs can be used:
5209 %t The security MIME type
5212 %D Details if button is pressed")
5214 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5215 "The following specs can be used:
5216 %t The security MIME type
5219 %D Details if button is pressed")
5221 (defvar gnus-mime-security-button-line-format-alist
5222 '((?t gnus-tmp-type ?s)
5223 (?i gnus-tmp-info ?s)
5224 (?d gnus-tmp-details ?s)
5225 (?D gnus-tmp-pressed-details ?s)))
5227 (defvar gnus-mime-security-button-map
5228 (let ((map (make-sparse-keymap)))
5229 (unless (>= (string-to-number emacs-version) 21)
5230 (set-keymap-parent map gnus-article-mode-map))
5231 (define-key map gnus-mouse-2 'gnus-article-push-button)
5232 (define-key map "\r" 'gnus-article-press-button)
5235 (defvar gnus-mime-security-details-buffer nil)
5237 (defvar gnus-mime-security-button-pressed nil)
5239 (defvar gnus-mime-security-show-details-inline t
5240 "If non-nil, show details in the article buffer.")
5242 (defun gnus-mime-security-verify-or-decrypt (handle)
5243 (mm-remove-parts (cdr handle))
5244 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5247 (delete-region (car region) (cdr region))
5248 (set-marker (car region) nil)
5249 (set-marker (cdr region) nil)))
5250 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5251 (let* ((mm-verify-option 'known)
5252 (mm-decrypt-option 'known)
5253 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5254 (unless (eq nparts (cdr handle))
5255 (mm-destroy-parts (cdr handle))
5256 (setcdr handle nparts))))
5257 (let ((point (point))
5259 (gnus-mime-display-security handle)
5262 (defun gnus-mime-security-show-details (handle)
5263 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5265 (if gnus-mime-security-show-details-inline
5266 (let ((gnus-mime-security-button-pressed t)
5267 (gnus-mime-security-button-line-format
5268 (get-text-property (point) 'gnus-line-format))
5271 (while (eq (get-text-property (point) 'gnus-line-format)
5272 gnus-mime-security-button-line-format)
5275 (delete-region (point)
5276 (or (text-property-not-all
5279 gnus-mime-security-button-line-format)
5281 (gnus-insert-mime-security-button handle))
5282 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5283 (with-current-buffer gnus-mime-security-details-buffer
5286 (setq gnus-mime-security-details-buffer
5287 (gnus-get-buffer-create "*MIME Security Details*")))
5288 (with-current-buffer gnus-mime-security-details-buffer
5290 (goto-char (point-min)))
5291 (pop-to-buffer gnus-mime-security-details-buffer))
5292 (gnus-message 5 "No details."))))
5294 (defun gnus-mime-security-press-button (handle)
5295 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5296 (gnus-mime-security-show-details handle)
5297 (gnus-mime-security-verify-or-decrypt handle)))
5299 (defun gnus-insert-mime-security-button (handle &optional displayed)
5300 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5303 (or (nth 2 (assoc protocol mm-verify-function-alist))
5304 (nth 2 (assoc protocol mm-decrypt-function-alist))
5306 (if (equal (car handle) "multipart/signed")
5307 " Signed" " Encrypted")
5310 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5313 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5314 gnus-tmp-pressed-details
5316 (setq gnus-tmp-details
5317 (if gnus-tmp-details
5318 (concat "\n" gnus-tmp-details) ""))
5319 (setq gnus-tmp-pressed-details
5320 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5325 gnus-mime-security-button-line-format
5326 gnus-mime-security-button-line-format-alist
5327 `(keymap ,gnus-mime-security-button-map
5328 ,@(if (>= (string-to-number emacs-version) 21)
5329 nil ;; XEmacs doesn't care
5330 (list 'local-map gnus-mime-security-button-map))
5331 gnus-callback gnus-mime-security-press-button
5332 gnus-line-format ,gnus-mime-security-button-line-format
5333 article-type annotation
5336 (widget-convert-button
5339 :action 'gnus-widget-press-button
5340 :button-keymap gnus-mime-security-button-map
5342 (lambda (widget/window &optional overlay pos)
5343 ;; Needed to properly clear the message due to a bug in
5344 ;; wid-edit (XEmacs only).
5345 (if (boundp 'help-echo-owns-message)
5346 (setq help-echo-owns-message t))
5349 (aref gnus-mouse-2 0))))))
5351 (defun gnus-mime-display-security (handle)
5353 (narrow-to-region (point) (point))
5354 (gnus-insert-mime-security-button handle)
5355 (gnus-mime-display-mixed (cdr handle))
5358 (let ((gnus-mime-security-button-line-format
5359 gnus-mime-security-button-end-line-format))
5360 (gnus-insert-mime-security-button handle))
5361 (mm-set-handle-multipart-parameter handle 'gnus-region
5362 (cons (set-marker (make-marker)
5364 (set-marker (make-marker)
5371 (run-hooks 'gnus-art-load-hook)
5373 ;;; gnus-art.el ends here