1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
42 (autoload 'gnus-msg-mail "gnus-msg" nil t)
43 (autoload 'gnus-button-mailto "gnus-msg")
44 (autoload 'gnus-button-reply "gnus-msg" nil t)
46 (defgroup gnus-article nil
48 :link '(custom-manual "(gnus)The Article Buffer")
51 (defgroup gnus-article-treat nil
52 "Treating article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-hiding nil
57 "Hiding article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-highlight nil
62 "Article highlighting."
63 :link '(custom-manual "(gnus)Article Highlighting")
67 (defgroup gnus-article-signature nil
69 :link '(custom-manual "(gnus)Article Signature")
72 (defgroup gnus-article-headers nil
74 :link '(custom-manual "(gnus)Hiding Headers")
77 (defgroup gnus-article-washing nil
78 "Special commands on articles."
79 :link '(custom-manual "(gnus)Article Washing")
82 (defgroup gnus-article-emphasis nil
83 "Fontisizing articles."
84 :link '(custom-manual "(gnus)Article Fontisizing")
87 (defgroup gnus-article-saving nil
89 :link '(custom-manual "(gnus)Saving Articles")
92 (defgroup gnus-article-mime nil
93 "Worshiping the MIME wonder."
94 :link '(custom-manual "(gnus)Using MIME")
97 (defgroup gnus-article-buttons nil
98 "Pushable buttons in the article buffer."
99 :link '(custom-manual "(gnus)Article Buttons")
100 :group 'gnus-article)
102 (defgroup gnus-article-various nil
103 "Other article options."
104 :link '(custom-manual "(gnus)Misc Article")
105 :group 'gnus-article)
107 (defcustom gnus-ignored-headers
108 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
109 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
110 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
111 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
112 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
113 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
114 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
115 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
116 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
117 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
118 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
119 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
120 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
121 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
122 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
123 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
124 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
125 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
126 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
127 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
128 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
129 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
130 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
131 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
132 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
133 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
134 "^X-Received:" "^Content-length:" "X-precedence:"
135 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
136 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
138 "*All headers that start with this regexp will be hidden.
139 This variable can also be a list of regexps of headers to be ignored.
140 If `gnus-visible-headers' is non-nil, this variable will be ignored."
141 :type '(choice :custom-show nil
144 :group 'gnus-article-hiding)
146 (defcustom gnus-visible-headers
147 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
148 "*All headers that do not match this regexp will be hidden.
149 This variable can also be a list of regexp of headers to remain visible.
150 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
151 :type '(repeat :value-to-internal (lambda (widget value)
152 (custom-split-regexp-maybe value))
153 :match (lambda (widget value)
155 (widget-editable-list-match widget value)))
157 :group 'gnus-article-hiding)
159 (defcustom gnus-sorted-header-list
160 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
161 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
162 "*This variable is a list of regular expressions.
163 If it is non-nil, headers that match the regular expressions will
164 be placed first in the article buffer in the sequence specified by
166 :type '(repeat regexp)
167 :group 'gnus-article-hiding)
169 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
170 "Headers that are only to be displayed if they have interesting data.
171 Possible values in this list are `empty', `newsgroups', `followup-to',
172 `to-address', `reply-to', `date', `long-to', and `many-to'."
173 :type '(set (const :tag "Headers with no content." empty)
174 (const :tag "Newsgroups with only one group." newsgroups)
175 (const :tag "To identical to to-address." to-address)
176 (const :tag "Followup-to identical to newsgroups." followup-to)
177 (const :tag "Reply-to identical to from." reply-to)
178 (const :tag "Date less than four days old." date)
179 (const :tag "Very long To and/or Cc header." long-to)
180 (const :tag "Multiple To and/or Cc headers." many-to))
181 :group 'gnus-article-hiding)
183 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
184 "Regexp matching signature separator.
185 This can also be a list of regexps. In that case, it will be checked
186 from head to tail looking for a separator. Searches will be done from
187 the end of the buffer."
188 :type '(repeat string)
189 :group 'gnus-article-signature)
191 (defcustom gnus-signature-limit nil
192 "Provide a limit to what is considered a signature.
193 If it is a number, no signature may not be longer (in characters) than
194 that number. If it is a floating point number, no signature may be
195 longer (in lines) than that number. If it is a function, the function
196 will be called without any parameters, and if it returns nil, there is
197 no signature in the buffer. If it is a string, it will be used as a
198 regexp. If it matches, the text in question is not a signature."
199 :type '(choice (integer :value 200)
201 (function :value fun)
202 (regexp :value ".*"))
203 :group 'gnus-article-signature)
205 (defcustom gnus-hidden-properties '(invisible t intangible t)
206 "Property list to use for hiding text."
208 :group 'gnus-article-hiding)
210 ;; Fixme: This isn't the right thing for mixed graphical and and
211 ;; non-graphical frames in a session.
212 ;; gnus-xmas.el overrides this for XEmacs.
213 (defcustom gnus-article-x-face-command
214 (if (and (fboundp 'image-type-available-p)
215 (image-type-available-p 'xbm))
216 'gnus-article-display-xface
217 (if gnus-article-compface-xbm
218 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
219 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
221 "*String or function to be executed to display an X-Face header.
222 If it is a string, the command will be executed in a sub-shell
223 asynchronously. The compressed face will be piped to this command."
224 :type '(choice string
225 (function-item gnus-article-display-xface)
227 :group 'gnus-article-washing)
229 (defcustom gnus-article-x-face-too-ugly nil
230 "Regexp matching posters whose face shouldn't be shown automatically."
231 :type '(choice regexp (const nil))
232 :group 'gnus-article-washing)
234 (defcustom gnus-article-banner-alist nil
235 "Banner alist for stripping.
237 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
239 :type '(repeat (cons symbol regexp))
240 :group 'gnus-article-washing)
242 (gnus-define-group-parameter
245 "Alist of regexps (to match group names) and banner."
246 :variable-group gnus-article-washing
248 '(choice :tag "Banner"
250 (const :tag "Remove signature" signature)
251 (symbol :tag "Item in `gnus-article-banner-alist'" none)
253 (const :tag "None" nil))
255 "If non-nil, specify how to remove `banners' from articles.
257 Symbol `signature' means to remove signatures delimited by
258 `gnus-signature-separator'. Any other symbol is used to look up a
259 regular expression to match the banner in `gnus-article-banner-alist'.
260 A string is used as a regular expression to match the banner
263 (defcustom gnus-emphasis-alist
265 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
267 '(("_" "_" underline)
270 ("_/" "/_" underline-italic)
271 ("_\\*" "\\*_" underline-bold)
272 ("\\*/" "/\\*" bold-italic)
273 ("_\\*/" "/\\*_" underline-bold-italic))))
274 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
275 2 3 gnus-emphasis-underline)
279 (format format (car spec) (cadr spec))
280 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
282 "*Alist that says how to fontify certain phrases.
283 Each item looks like this:
285 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
287 The first element is a regular expression to be matched. The second
288 is a number that says what regular expression grouping used to find
289 the entire emphasized word. The third is a number that says what
290 regexp grouping should be displayed and highlighted. The fourth
291 is the face used for highlighting."
292 :type '(repeat (list :value ("" 0 0 default)
294 (integer :tag "Match group")
295 (integer :tag "Emphasize group")
297 :group 'gnus-article-emphasis)
299 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
300 "A regexp to describe whitespace which should not be emphasized.
301 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
302 The former avoids underlining of leading and trailing whitespace,
303 and the latter avoids underlining any whitespace at all."
305 :group 'gnus-article-emphasis
308 (defface gnus-emphasis-bold '((t (:bold t)))
309 "Face used for displaying strong emphasized text (*word*)."
310 :group 'gnus-article-emphasis)
312 (defface gnus-emphasis-italic '((t (:italic t)))
313 "Face used for displaying italic emphasized text (/word/)."
314 :group 'gnus-article-emphasis)
316 (defface gnus-emphasis-underline '((t (:underline t)))
317 "Face used for displaying underlined emphasized text (_word_)."
318 :group 'gnus-article-emphasis)
320 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
321 "Face used for displaying underlined bold emphasized text (_*word*_)."
322 :group 'gnus-article-emphasis)
324 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
325 "Face used for displaying underlined italic emphasized text (_/word/_)."
326 :group 'gnus-article-emphasis)
328 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
329 "Face used for displaying bold italic emphasized text (/*word*/)."
330 :group 'gnus-article-emphasis)
332 (defface gnus-emphasis-underline-bold-italic
333 '((t (:bold t :italic t :underline t)))
334 "Face used for displaying underlined bold italic emphasized text.
335 Esample: (_/*word*/_)."
336 :group 'gnus-article-emphasis)
338 (defface gnus-emphasis-highlight-words
339 '((t (:background "black" :foreground "yellow")))
340 "Face used for displaying highlighted words."
341 :group 'gnus-article-emphasis)
343 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
344 "Format for display of Date headers in article bodies.
345 See `format-time-string' for the possible values.
347 The variable can also be function, which should return a complete Date
348 header. The function is called with one argument, the time, which can
349 be fed to `format-time-string'."
350 :type '(choice string symbol)
351 :link '(custom-manual "(gnus)Article Date")
352 :group 'gnus-article-washing)
355 (autoload 'mail-extract-address-components "mail-extr"))
357 (defcustom gnus-save-all-headers t
358 "*If non-nil, don't remove any headers before saving."
359 :group 'gnus-article-saving
362 (defcustom gnus-prompt-before-saving 'always
363 "*This variable says how much prompting is to be done when saving articles.
364 If it is nil, no prompting will be done, and the articles will be
365 saved to the default files. If this variable is `always', each and
366 every article that is saved will be preceded by a prompt, even when
367 saving large batches of articles. If this variable is neither nil not
368 `always', there the user will be prompted once for a file name for
369 each invocation of the saving commands."
370 :group 'gnus-article-saving
371 :type '(choice (item always)
372 (item :tag "never" nil)
373 (sexp :tag "once" :format "%t\n" :value t)))
375 (defcustom gnus-saved-headers gnus-visible-headers
376 "Headers to keep if `gnus-save-all-headers' is nil.
377 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
378 If that variable is nil, however, all headers that match this regexp
379 will be kept while the rest will be deleted before saving."
380 :group 'gnus-article-saving
383 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
384 "A function to save articles in your favourite format.
385 The function must be interactively callable (in other words, it must
386 be an Emacs command).
388 Gnus provides the following functions:
390 * gnus-summary-save-in-rmail (Rmail format)
391 * gnus-summary-save-in-mail (Unix mail format)
392 * gnus-summary-save-in-folder (MH folder)
393 * gnus-summary-save-in-file (article format)
394 * gnus-summary-save-in-vm (use VM's folder format)
395 * gnus-summary-write-to-file (article format -- overwrite)."
396 :group 'gnus-article-saving
397 :type '(radio (function-item gnus-summary-save-in-rmail)
398 (function-item gnus-summary-save-in-mail)
399 (function-item gnus-summary-save-in-folder)
400 (function-item gnus-summary-save-in-file)
401 (function-item gnus-summary-save-in-vm)
402 (function-item gnus-summary-write-to-file)))
404 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
405 "A function generating a file name to save articles in Rmail format.
406 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
407 :group 'gnus-article-saving
410 (defcustom gnus-mail-save-name 'gnus-plain-save-name
411 "A function generating a file name to save articles in Unix mail format.
412 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
413 :group 'gnus-article-saving
416 (defcustom gnus-folder-save-name 'gnus-folder-save-name
417 "A function generating a file name to save articles in MH folder.
418 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
419 :group 'gnus-article-saving
422 (defcustom gnus-file-save-name 'gnus-numeric-save-name
423 "A function generating a file name to save articles in article format.
424 The function is called with NEWSGROUP, HEADERS, and optional
426 :group 'gnus-article-saving
429 (defcustom gnus-split-methods
430 '((gnus-article-archive-name)
431 (gnus-article-nndoc-name))
432 "*Variable used to suggest where articles are to be saved.
433 For instance, if you would like to save articles related to Gnus in
434 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
435 you could set this variable to something like:
437 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
438 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
440 This variable is an alist where the where the key is the match and the
441 value is a list of possible files to save in if the match is non-nil.
443 If the match is a string, it is used as a regexp match on the
444 article. If the match is a symbol, that symbol will be funcalled
445 from the buffer of the article to be saved with the newsgroup as the
446 parameter. If it is a list, it will be evaled in the same buffer.
448 If this form or function returns a string, this string will be used as
449 a possible file name; and if it returns a non-nil list, that list will
450 be used as possible file names."
451 :group 'gnus-article-saving
452 :type '(repeat (choice (list :value (fun) function)
453 (cons :value ("" "") regexp (repeat string))
456 (defcustom gnus-page-delimiter "^\^L"
457 "*Regexp describing what to use as article page delimiters.
458 The default value is \"^\^L\", which is a form linefeed at the
459 beginning of a line."
461 :group 'gnus-article-various)
463 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
464 "*The format specification for the article mode line.
465 See `gnus-summary-mode-line-format' for a closer description.
467 The following additional specs are available:
469 %w The article washing status.
470 %m The number of MIME parts in the article."
472 :group 'gnus-article-various)
474 (defcustom gnus-article-mode-hook nil
475 "*A hook for Gnus article mode."
477 :group 'gnus-article-various)
479 (when (featurep 'xemacs)
480 ;; Extracted from gnus-xmas-define in order to preserve user settings
481 (when (fboundp 'turn-off-scroll-in-place)
482 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
483 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
484 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
486 (defcustom gnus-article-menu-hook nil
487 "*Hook run after the creation of the article mode menu."
489 :group 'gnus-article-various)
491 (defcustom gnus-article-prepare-hook nil
492 "*A hook called after an article has been prepared in the article buffer."
494 :group 'gnus-article-various)
496 (defcustom gnus-article-hide-pgp-hook nil
497 "*A hook called after successfully hiding a PGP signature."
499 :group 'gnus-article-various)
501 (defcustom gnus-article-button-face 'bold
502 "Face used for highlighting buttons in the article buffer.
504 An article button is a piece of text that you can activate by pressing
505 `RET' or `mouse-2' above it."
507 :group 'gnus-article-buttons)
509 (defcustom gnus-article-mouse-face 'highlight
510 "Face used for mouse highlighting in the article buffer.
512 Article buttons will be displayed in this face when the cursor is
515 :group 'gnus-article-buttons)
517 (defcustom gnus-signature-face 'gnus-signature-face
518 "Face used for highlighting a signature in the article buffer.
519 Obsolete; use the face `gnus-signature-face' for customizations instead."
521 :group 'gnus-article-highlight
522 :group 'gnus-article-signature)
524 (defface gnus-signature-face
527 "Face used for highlighting a signature in the article buffer."
528 :group 'gnus-article-highlight
529 :group 'gnus-article-signature)
531 (defface gnus-header-from-face
534 (:foreground "spring green"))
537 (:foreground "red3"))
540 "Face used for displaying from headers."
541 :group 'gnus-article-headers
542 :group 'gnus-article-highlight)
544 (defface gnus-header-subject-face
547 (:foreground "SeaGreen3"))
550 (:foreground "red4"))
552 (:bold t :italic t)))
553 "Face used for displaying subject headers."
554 :group 'gnus-article-headers
555 :group 'gnus-article-highlight)
557 (defface gnus-header-newsgroups-face
560 (:foreground "yellow" :italic t))
563 (:foreground "MidnightBlue" :italic t))
566 "Face used for displaying newsgroups headers."
567 :group 'gnus-article-headers
568 :group 'gnus-article-highlight)
570 (defface gnus-header-name-face
573 (:foreground "SeaGreen"))
576 (:foreground "maroon"))
579 "Face used for displaying header names."
580 :group 'gnus-article-headers
581 :group 'gnus-article-highlight)
583 (defface gnus-header-content-face
586 (:foreground "forest green" :italic t))
589 (:foreground "indianred4" :italic t))
591 (:italic t))) "Face used for displaying header content."
592 :group 'gnus-article-headers
593 :group 'gnus-article-highlight)
595 (defcustom gnus-header-face-alist
596 '(("From" nil gnus-header-from-face)
597 ("Subject" nil gnus-header-subject-face)
598 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
599 ("" gnus-header-name-face gnus-header-content-face))
600 "*Controls highlighting of article header.
602 An alist of the form (HEADER NAME CONTENT).
604 HEADER is a regular expression which should match the name of an
605 header header and NAME and CONTENT are either face names or nil.
607 The name of each header field will be displayed using the face
608 specified by the first element in the list where HEADER match the
609 header name and NAME is non-nil. Similarly, the content will be
610 displayed by the first non-nil matching CONTENT face."
611 :group 'gnus-article-headers
612 :group 'gnus-article-highlight
613 :type '(repeat (list (regexp :tag "Header")
615 (item :tag "skip" nil)
616 (face :value default))
617 (choice :tag "Content"
618 (item :tag "skip" nil)
619 (face :value default)))))
621 (defcustom gnus-article-decode-hook
622 '(article-decode-charset article-decode-encoded-words)
623 "*Hook run to decode charsets in articles."
624 :group 'gnus-article-headers
627 (defcustom gnus-display-mime-function 'gnus-display-mime
628 "Function to display MIME articles."
629 :group 'gnus-article-mime
632 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
633 "Function used to decode headers.")
635 (defvar gnus-article-dumbquotes-map
654 "Table for MS-to-Latin1 translation.")
656 (defcustom gnus-ignored-mime-types nil
657 "List of MIME types that should be ignored by Gnus."
659 :group 'gnus-article-mime
660 :type '(repeat regexp))
662 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
663 "List of MIME types that should not be given buttons when rendered inline."
665 :group 'gnus-article-mime
666 :type '(repeat regexp))
668 (defcustom gnus-article-mime-part-function nil
669 "Function called with a MIME handle as the argument.
670 This is meant for people who want to do something automatic based
671 on parts -- for instance, adding Vcard info to a database."
672 :group 'gnus-article-mime
675 (defcustom gnus-mime-multipart-functions nil
676 "An alist of MIME types to functions to display them."
678 :group 'gnus-article-mime
681 (defcustom gnus-article-date-lapsed-new-header nil
682 "Whether the X-Sent and Date headers can coexist.
683 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
684 either replace the old \"Date:\" header (if this variable is nil), or
685 be added below it (otherwise)."
687 :group 'gnus-article-headers
690 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
691 "Function called with a MIME handle as the argument.
692 This is meant for people who want to view first matched part.
693 For `undisplayed-alternative' (default), the first undisplayed
694 part or alternative part is used. For `undisplayed', the first
695 undisplayed part is used. For a function, the first part which
696 the function return `t' is used. For `nil', the first part is
699 :group 'gnus-article-mime
701 (item :tag "first" :value nil)
702 (item :tag "undisplayed" :value undisplayed)
703 (item :tag "undisplayed or alternative"
704 :value undisplayed-alternative)
707 (defcustom gnus-mime-action-alist
708 '(("save to file" . gnus-mime-save-part)
709 ("save and strip" . gnus-mime-save-part-and-strip)
710 ("display as text" . gnus-mime-inline-part)
711 ("view the part" . gnus-mime-view-part)
712 ("pipe to command" . gnus-mime-pipe-part)
713 ("toggle display" . gnus-article-press-button)
714 ("toggle display" . gnus-article-view-part-as-charset)
715 ("view as type" . gnus-mime-view-part-as-type)
716 ("internalize type" . gnus-mime-internalize-part)
717 ("externalize type" . gnus-mime-externalize-part))
718 "An alist of actions that run on the MIME attachment."
719 :group 'gnus-article-mime
720 :type '(repeat (cons (string :tag "name")
723 (defcustom gnus-mime-action-alist
724 '(("save to file" . gnus-mime-save-part)
725 ("display as text" . gnus-mime-inline-part)
726 ("view the part" . gnus-mime-view-part)
727 ("pipe to command" . gnus-mime-pipe-part)
728 ("toggle display" . gnus-article-press-button)
729 ("view as type" . gnus-mime-view-part-as-type)
730 ("internalize type" . gnus-mime-internalize-part)
731 ("externalize type" . gnus-mime-externalize-part))
732 "An alist of actions that run on the MIME attachment."
734 :group 'gnus-article-mime
735 :type '(repeat (cons (string :tag "name")
739 ;;; The treatment variables
742 (defvar gnus-part-display-hook nil
743 "Hook called on parts that are to receive treatment.")
745 (defvar gnus-article-treat-custom
746 '(choice (const :tag "Off" nil)
748 (const :tag "Header" head)
749 (const :tag "Last" last)
750 (integer :tag "Less")
751 (repeat :tag "Groups" regexp)
752 (sexp :tag "Predicate")))
754 (defvar gnus-article-treat-head-custom
755 '(choice (const :tag "Off" nil)
756 (const :tag "Header" head)))
758 (defvar gnus-article-treat-types '("text/plain")
761 (defvar gnus-inhibit-treatment nil
762 "Whether to inhibit treatment.")
764 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
765 "Highlight the signature.
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-custom)
770 (put 'gnus-treat-highlight-signature 'highlight t)
772 (defcustom gnus-treat-buttonize 100000
774 Valid values are nil, t, `head', `last', an integer or a predicate.
775 See the manual for details."
776 :group 'gnus-article-treat
777 :type gnus-article-treat-custom)
778 (put 'gnus-treat-buttonize 'highlight t)
780 (defcustom gnus-treat-buttonize-head 'head
781 "Add buttons to the head.
782 Valid values are nil, t, `head', `last', an integer or a predicate.
783 See the manual for details."
784 :group 'gnus-article-treat
785 :type gnus-article-treat-head-custom)
786 (put 'gnus-treat-buttonize-head 'highlight t)
788 (defcustom gnus-treat-emphasize
789 (and (or window-system
791 (>= (string-to-number emacs-version) 21))
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
798 (put 'gnus-treat-emphasize 'highlight t)
800 (defcustom gnus-treat-strip-cr nil
801 "Remove carriage returns.
802 Valid values are nil, t, `head', `last', an integer or a predicate.
803 See the manual for details."
804 :group 'gnus-article-treat
805 :type gnus-article-treat-custom)
807 (defcustom gnus-treat-hide-headers 'head
809 Valid values are nil, t, `head', `last', an integer or a predicate.
810 See the manual for details."
811 :group 'gnus-article-treat
812 :type gnus-article-treat-head-custom)
814 (defcustom gnus-treat-hide-boring-headers nil
815 "Hide boring headers.
816 Valid values are nil, t, `head', `last', an integer or a predicate.
817 See the manual for details."
818 :group 'gnus-article-treat
819 :type gnus-article-treat-head-custom)
821 (defcustom gnus-treat-hide-signature nil
823 Valid values are nil, t, `head', `last', an integer or a predicate.
824 See the manual for details."
825 :group 'gnus-article-treat
826 :type gnus-article-treat-custom)
828 (defcustom gnus-treat-fill-article nil
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-custom)
835 (defcustom gnus-treat-hide-citation nil
837 Valid values are nil, t, `head', `last', an integer or a predicate.
838 See the manual for details."
839 :group 'gnus-article-treat
840 :type gnus-article-treat-custom)
842 (defcustom gnus-treat-hide-citation-maybe nil
844 Valid values are nil, t, `head', `last', an integer or a predicate.
845 See the manual for details."
846 :group 'gnus-article-treat
847 :type gnus-article-treat-custom)
849 (defcustom gnus-treat-hide-citation-maybe nil
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-custom)
856 (defcustom gnus-treat-strip-list-identifiers 'head
857 "Strip list identifiers from `gnus-list-identifiers`.
858 Valid values are nil, t, `head', `last', an integer or a predicate.
859 See the manual for details."
861 :group 'gnus-article-treat
862 :type gnus-article-treat-custom)
864 (defcustom gnus-treat-strip-pgp t
865 "Strip PGP signatures.
866 Valid values are nil, t, `head', `last', an integer or a predicate.
867 See the manual for details."
868 :group 'gnus-article-treat
869 :type gnus-article-treat-custom)
871 (defcustom gnus-treat-strip-pem nil
872 "Strip PEM signatures.
873 Valid values are nil, t, `head', `last', an integer or a predicate.
874 See the manual for details."
875 :group 'gnus-article-treat
876 :type gnus-article-treat-custom)
878 (defcustom gnus-treat-strip-banner t
879 "Strip banners from articles.
880 The banner to be stripped is specified in the `banner' group parameter.
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-custom)
886 (defcustom gnus-treat-highlight-headers 'head
887 "Highlight the headers.
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)
892 (put 'gnus-treat-highlight-headers 'highlight t)
894 (defcustom gnus-treat-highlight-citation t
895 "Highlight cited text.
896 Valid values are nil, t, `head', `last', an integer or a predicate.
897 See the manual for details."
898 :group 'gnus-article-treat
899 :type gnus-article-treat-custom)
900 (put 'gnus-treat-highlight-citation 'highlight t)
902 (defcustom gnus-treat-date-ut nil
903 "Display the Date in UT (GMT).
904 Valid values are nil, t, `head', `last', an integer or a predicate.
905 See the manual for details."
906 :group 'gnus-article-treat
907 :type gnus-article-treat-head-custom)
909 (defcustom gnus-treat-date-local nil
910 "Display the Date in the local timezone.
911 Valid values are nil, t, `head', `last', an integer or a predicate.
912 See the manual for details."
913 :group 'gnus-article-treat
914 :type gnus-article-treat-head-custom)
916 (defcustom gnus-treat-date-english nil
917 "Display the Date in a format that can be read aloud in English.
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-head-custom)
923 (defcustom gnus-treat-date-lapsed nil
924 "Display the Date header in a way that says how much time has elapsed.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-head-custom)
930 (defcustom gnus-treat-date-original nil
931 "Display the date in the original timezone.
932 Valid values are nil, t, `head', `last', an integer or a predicate.
933 See the manual for details."
934 :group 'gnus-article-treat
935 :type gnus-article-treat-head-custom)
937 (defcustom gnus-treat-date-iso8601 nil
938 "Display the date in the ISO8601 format.
939 Valid values are nil, t, `head', `last', an integer or a predicate.
940 See the manual for details."
942 :group 'gnus-article-treat
943 :type gnus-article-treat-head-custom)
945 (defcustom gnus-treat-date-user-defined nil
946 "Display the date in a user-defined format.
947 The format is defined by the `gnus-article-time-format' variable.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-head-custom)
953 (defcustom gnus-treat-strip-headers-in-body t
954 "Strip the X-No-Archive header line from the beginning of the body.
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See the manual for details."
958 :group 'gnus-article-treat
959 :type gnus-article-treat-custom)
961 (defcustom gnus-treat-strip-trailing-blank-lines nil
962 "Strip trailing blank lines.
963 Valid values are nil, t, `head', `last', an integer or a predicate.
964 See the manual for details."
965 :group 'gnus-article-treat
966 :type gnus-article-treat-custom)
968 (defcustom gnus-treat-strip-leading-blank-lines nil
969 "Strip leading blank lines.
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See the manual for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-custom)
975 (defcustom gnus-treat-strip-multiple-blank-lines nil
976 "Strip multiple blank lines.
977 Valid values are nil, t, `head', `last', an integer or a predicate.
978 See the manual for details."
979 :group 'gnus-article-treat
980 :type gnus-article-treat-custom)
982 (defcustom gnus-treat-overstrike t
983 "Treat overstrike highlighting.
984 Valid values are nil, t, `head', `last', an integer or a predicate.
985 See the manual for details."
986 :group 'gnus-article-treat
987 :type gnus-article-treat-custom)
988 (put 'gnus-treat-overstrike 'highlight t)
990 (defcustom gnus-treat-display-xface
991 (and (or (and (fboundp 'image-type-available-p)
992 (image-type-available-p 'xbm)
993 (string-match "^0x" (shell-command-to-string "uncompface")))
994 (and (featurep 'xemacs) (featurep 'xface)))
996 "Display X-Face headers.
997 Valid values are nil, t, `head', `last', an integer or a predicate.
998 See the manual for details."
999 :group 'gnus-article-treat
1000 :type gnus-article-treat-head-custom)
1001 (put 'gnus-treat-display-xface 'highlight t)
1003 (defcustom gnus-treat-display-smileys
1004 (if (or (and (featurep 'xemacs)
1006 (and (fboundp 'image-type-available-p)
1007 (image-type-available-p 'pbm)))
1010 Valid values are nil, t, `head', `last', an integer or a predicate.
1011 See the manual for details."
1012 :group 'gnus-article-treat
1013 :type gnus-article-treat-custom)
1014 (put 'gnus-treat-display-smileys 'highlight t)
1016 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1018 Valid values are nil, t, `head', `last', an integer or a predicate.
1019 See the manual for details."
1020 :group 'gnus-article-treat
1021 :type gnus-article-treat-head-custom)
1022 (put 'gnus-treat-display-picons 'highlight t)
1024 (defcustom gnus-treat-capitalize-sentences nil
1025 "Capitalize sentence-starting words.
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-fill-long-lines nil
1034 Valid values are nil, t, `head', `last', an integer or a predicate.
1035 See the manual for details."
1036 :group 'gnus-article-treat
1037 :type gnus-article-treat-custom)
1039 (defcustom gnus-treat-play-sounds nil
1041 Valid values are nil, t, `head', `last', an integer or a predicate.
1042 See the manual for details."
1044 :group 'gnus-article-treat
1045 :type gnus-article-treat-custom)
1047 (defcustom gnus-treat-translate nil
1048 "Translate articles from one language to another.
1049 Valid values are nil, t, `head', `last', an integer or a predicate.
1050 See the manual for details."
1052 :group 'gnus-article-treat
1053 :type gnus-article-treat-custom)
1055 (defcustom gnus-treat-x-pgp-sig nil
1057 To automatically treat X-PGP-Sig, set it to head.
1058 Valid values are nil, t, `head', `last', an integer or a predicate.
1059 See the manual for details."
1060 :group 'gnus-article-treat
1061 :group 'mime-security
1062 :type gnus-article-treat-custom)
1064 (defvar gnus-article-encrypt-protocol-alist
1065 '(("PGP" . mml2015-self-encrypt)))
1067 ;; Set to nil if more than one protocol added to
1068 ;; gnus-article-encrypt-protocol-alist.
1069 (defcustom gnus-article-encrypt-protocol "PGP"
1070 "The protocol used for encrypt articles.
1071 It is a string, such as \"PGP\". If nil, ask user."
1073 :group 'mime-security)
1075 ;;; Internal variables
1077 (defvar gnus-english-month-names
1078 '("January" "February" "March" "April" "May" "June" "July" "August"
1079 "September" "October" "November" "December"))
1081 (defvar article-goto-body-goes-to-point-min-p nil)
1082 (defvar gnus-article-wash-types nil)
1083 (defvar gnus-article-emphasis-alist nil)
1085 (defvar gnus-article-mime-handle-alist-1 nil)
1086 (defvar gnus-treatment-function-alist
1087 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1088 (gnus-treat-strip-banner gnus-article-strip-banner)
1089 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1090 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1091 (gnus-treat-buttonize gnus-article-add-buttons)
1092 (gnus-treat-fill-article gnus-article-fill-cited-article)
1093 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1094 (gnus-treat-strip-cr gnus-article-remove-cr)
1095 (gnus-treat-emphasize gnus-article-emphasize)
1096 (gnus-treat-display-xface gnus-article-display-x-face)
1097 (gnus-treat-date-ut gnus-article-date-ut)
1098 (gnus-treat-date-local gnus-article-date-local)
1099 (gnus-treat-date-english gnus-article-date-english)
1100 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1101 (gnus-treat-date-original gnus-article-date-original)
1102 (gnus-treat-date-user-defined gnus-article-date-user)
1103 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1104 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1105 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1106 (gnus-treat-hide-signature gnus-article-hide-signature)
1107 (gnus-treat-hide-citation gnus-article-hide-citation)
1108 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1109 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1110 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1111 (gnus-treat-strip-pem gnus-article-hide-pem)
1112 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1113 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1114 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1115 (gnus-treat-strip-trailing-blank-lines
1116 gnus-article-remove-trailing-blank-lines)
1117 (gnus-treat-strip-leading-blank-lines
1118 gnus-article-strip-leading-blank-lines)
1119 (gnus-treat-strip-multiple-blank-lines
1120 gnus-article-strip-multiple-blank-lines)
1121 (gnus-treat-overstrike gnus-article-treat-overstrike)
1122 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1123 (gnus-treat-display-smileys gnus-smiley-display)
1124 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1125 (gnus-treat-display-picons gnus-article-display-picons)
1126 (gnus-treat-play-sounds gnus-earcon-display)))
1128 (defvar gnus-article-mime-handle-alist nil)
1129 (defvar article-lapsed-timer nil)
1130 (defvar gnus-article-current-summary nil)
1132 (defvar gnus-article-mode-syntax-table
1133 (let ((table (copy-syntax-table text-mode-syntax-table)))
1134 ;; This causes the citation match run O(2^n).
1135 ;; (modify-syntax-entry ?- "w" table)
1136 (modify-syntax-entry ?> ")" table)
1137 (modify-syntax-entry ?< "(" table)
1139 "Syntax table used in article mode buffers.
1140 Initialized from `text-mode-syntax-table.")
1142 (defvar gnus-save-article-buffer nil)
1144 (defvar gnus-article-mode-line-format-alist
1145 (nconc '((?w (gnus-article-wash-status) ?s)
1146 (?m (gnus-article-mime-part-status) ?s))
1147 gnus-summary-mode-line-format-alist))
1149 (defvar gnus-number-of-articles-to-be-saved nil)
1151 (defvar gnus-inhibit-hiding nil)
1153 (defsubst gnus-article-hide-text (b e props)
1154 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1155 (gnus-add-text-properties-when 'article-type nil b e props)
1156 (when (memq 'intangible props)
1158 (max (1- b) (point-min))
1159 b 'intangible (cddr (memq 'intangible props)))))
1161 (defsubst gnus-article-unhide-text (b e)
1162 "Remove hidden text properties from region between B and E."
1163 (remove-text-properties b e gnus-hidden-properties)
1164 (when (memq 'intangible gnus-hidden-properties)
1165 (put-text-property (max (1- b) (point-min))
1166 b 'intangible nil)))
1168 (defun gnus-article-hide-text-type (b e type)
1169 "Hide text of TYPE between B and E."
1170 (push type gnus-article-wash-types)
1171 (gnus-article-hide-text
1172 b e (cons 'article-type (cons type gnus-hidden-properties))))
1174 (defun gnus-article-unhide-text-type (b e type)
1175 "Unhide text of TYPE between B and E."
1176 (setq gnus-article-wash-types
1177 (delq type gnus-article-wash-types))
1178 (remove-text-properties
1179 b e (cons 'article-type (cons type gnus-hidden-properties)))
1180 (when (memq 'intangible gnus-hidden-properties)
1181 (put-text-property (max (1- b) (point-min))
1182 b 'intangible nil)))
1184 (defun gnus-article-hide-text-of-type (type)
1185 "Hide text of TYPE in the current buffer."
1187 (let ((b (point-min))
1189 (while (setq b (text-property-any b e 'article-type type))
1190 (add-text-properties b (incf b) gnus-hidden-properties)))))
1192 (defun gnus-article-delete-text-of-type (type)
1193 "Delete text of TYPE in the current buffer."
1195 (let ((b (point-min)))
1196 (while (setq b (text-property-any b (point-max) 'article-type type))
1198 b (or (text-property-not-all b (point-max) 'article-type type)
1201 (defun gnus-article-delete-invisible-text ()
1202 "Delete all invisible text in the current buffer."
1204 (let ((b (point-min)))
1205 (while (setq b (text-property-any b (point-max) 'invisible t))
1207 b (or (text-property-not-all b (point-max) 'invisible t)
1210 (defun gnus-article-text-type-exists-p (type)
1211 "Say whether any text of type TYPE exists in the buffer."
1212 (text-property-any (point-min) (point-max) 'article-type type))
1214 (defsubst gnus-article-header-rank ()
1215 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1216 (let ((list gnus-sorted-header-list)
1219 (when (looking-at (car list))
1221 (setq list (cdr list))
1225 (defun article-hide-headers (&optional arg delete)
1226 "Hide unwanted headers and possibly sort them as well."
1228 ;; This function might be inhibited.
1229 (unless gnus-inhibit-hiding
1232 (let ((buffer-read-only nil)
1233 (case-fold-search t)
1234 (max (1+ (length gnus-sorted-header-list)))
1235 (ignored (when (not gnus-visible-headers)
1236 (cond ((stringp gnus-ignored-headers)
1237 gnus-ignored-headers)
1238 ((listp gnus-ignored-headers)
1239 (mapconcat 'identity gnus-ignored-headers
1242 (cond ((stringp gnus-visible-headers)
1243 gnus-visible-headers)
1244 ((and gnus-visible-headers
1245 (listp gnus-visible-headers))
1246 (mapconcat 'identity gnus-visible-headers "\\|"))))
1247 (inhibit-point-motion-hooks t)
1249 ;; First we narrow to just the headers.
1250 (article-narrow-to-head)
1251 ;; Hide any "From " lines at the beginning of (mail) articles.
1252 (while (looking-at "From ")
1255 (delete-region (point-min) (point)))
1256 ;; Then treat the rest of the header lines.
1257 ;; Then we use the two regular expressions
1258 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1259 ;; select which header lines is to remain visible in the
1261 (while (re-search-forward "^[^ \t]*:" nil t)
1263 ;; Mark the rank of the header.
1265 (point) (1+ (point)) 'message-rank
1266 (if (or (and visible (looking-at visible))
1268 (not (looking-at ignored))))
1269 (gnus-article-header-rank)
1272 (message-sort-headers-1)
1273 (when (setq beg (text-property-any
1274 (point-min) (point-max) 'message-rank (+ 2 max)))
1275 ;; We delete the unwanted headers.
1276 (push 'headers gnus-article-wash-types)
1277 (add-text-properties (point-min) (+ 5 (point-min))
1278 '(article-type headers dummy-invisible t))
1279 (delete-region beg (point-max))))))))
1281 (defun article-hide-boring-headers (&optional arg)
1282 "Toggle hiding of headers that aren't very interesting.
1283 If given a negative prefix, always show; if given a positive prefix,
1285 (interactive (gnus-article-hidden-arg))
1286 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1287 (not gnus-show-all-headers))
1290 (let ((buffer-read-only nil)
1291 (list gnus-boring-article-headers)
1292 (inhibit-point-motion-hooks t)
1294 (article-narrow-to-head)
1296 (setq elem (pop list))
1297 (goto-char (point-min))
1299 ;; Hide empty headers.
1301 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1303 (gnus-article-hide-text-type
1304 (progn (beginning-of-line) (point))
1307 (if (re-search-forward "^[^ \t]" nil t)
1311 ;; Hide boring Newsgroups header.
1312 ((eq elem 'newsgroups)
1313 (when (equal (gnus-fetch-field "newsgroups")
1314 (gnus-group-real-name
1315 (if (boundp 'gnus-newsgroup-name)
1318 (gnus-article-hide-header "newsgroups")))
1319 ((eq elem 'to-address)
1320 (let ((to (message-fetch-field "to"))
1322 (gnus-group-find-parameter
1323 (if (boundp 'gnus-newsgroup-name)
1324 gnus-newsgroup-name "") 'to-address)))
1325 (when (and to to-address
1328 ;; only one address in To
1329 (nth 1 (mail-extract-address-components to))
1331 (gnus-article-hide-header "to"))))
1332 ((eq elem 'followup-to)
1333 (when (equal (message-fetch-field "followup-to")
1334 (message-fetch-field "newsgroups"))
1335 (gnus-article-hide-header "followup-to")))
1336 ((eq elem 'reply-to)
1337 (let ((from (message-fetch-field "from"))
1338 (reply-to (message-fetch-field "reply-to")))
1343 (nth 1 (mail-extract-address-components from))
1344 (nth 1 (mail-extract-address-components reply-to)))))
1345 (gnus-article-hide-header "reply-to"))))
1347 (let ((date (message-fetch-field "date")))
1349 (< (days-between (current-time-string) date)
1351 (gnus-article-hide-header "date"))))
1353 (let ((to (message-fetch-field "to"))
1354 (cc (message-fetch-field "cc")))
1355 (when (> (length to) 1024)
1356 (gnus-article-hide-header "to"))
1357 (when (> (length cc) 1024)
1358 (gnus-article-hide-header "cc"))))
1362 (goto-char (point-min))
1363 (while (re-search-forward "^to:" nil t)
1364 (setq to-count (1+ to-count)))
1365 (when (> to-count 1)
1366 (while (> to-count 0)
1367 (goto-char (point-min))
1369 (re-search-forward "^to:" nil nil to-count)
1371 (narrow-to-region (point) (point-max))
1372 (gnus-article-hide-header "to"))
1373 (setq to-count (1- to-count))))
1374 (goto-char (point-min))
1375 (while (re-search-forward "^cc:" nil t)
1376 (setq cc-count (1+ cc-count)))
1377 (when (> cc-count 1)
1378 (while (> cc-count 0)
1379 (goto-char (point-min))
1381 (re-search-forward "^cc:" nil nil cc-count)
1383 (narrow-to-region (point) (point-max))
1384 (gnus-article-hide-header "cc"))
1385 (setq cc-count (1- cc-count)))))))))))))
1387 (defun gnus-article-hide-header (header)
1389 (goto-char (point-min))
1390 (when (re-search-forward (concat "^" header ":") nil t)
1391 (gnus-article-hide-text-type
1392 (progn (beginning-of-line) (point))
1395 (if (re-search-forward "^[^ \t]" nil t)
1400 (defvar gnus-article-normalized-header-length 40
1401 "Length of normalized headers.")
1403 (defun article-normalize-headers ()
1404 "Make all header lines 40 characters long."
1406 (let ((buffer-read-only nil)
1410 (article-narrow-to-head)
1413 ((< (setq column (- (gnus-point-at-eol) (point)))
1414 gnus-article-normalized-header-length)
1416 (insert (make-string
1417 (- gnus-article-normalized-header-length column)
1419 ((> column gnus-article-normalized-header-length)
1420 (gnus-put-text-property
1422 (forward-char gnus-article-normalized-header-length)
1429 (forward-line 1))))))
1431 (defun article-treat-dumbquotes ()
1432 "Translate M****s*** sm*rtq**t*s into proper text.
1433 Note that this function guesses whether a character is a sm*rtq**t* or
1434 not, so it should only be used interactively.
1436 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1437 in an attempt to provide more quoting characters. If you see
1438 something like \\222 or \\264 where you're expecting some kind of
1439 apostrophe or quotation mark, then try this wash."
1441 (article-translate-strings gnus-article-dumbquotes-map))
1443 (defun article-translate-characters (from to)
1444 "Translate all characters in the body of the article according to FROM and TO.
1445 FROM is a string of characters to translate from; to is a string of
1446 characters to translate to."
1448 (when (article-goto-body)
1449 (let ((buffer-read-only nil)
1450 (x (make-string 225 ?x))
1452 (while (< (incf i) (length x))
1455 (while (< i (length from))
1456 (aset x (aref from i) (aref to i))
1458 (translate-region (point) (point-max) x)))))
1460 (defun article-translate-strings (map)
1461 "Translate all string in the body of the article according to MAP.
1462 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1464 (when (article-goto-body)
1465 (let ((buffer-read-only nil)
1467 (while (setq elem (pop map))
1469 (while (search-forward (car elem) nil t)
1470 (replace-match (cadr elem)))))))))
1472 (defun article-treat-overstrike ()
1473 "Translate overstrikes into bold text."
1476 (when (article-goto-body)
1477 (let ((buffer-read-only nil))
1478 (while (search-forward "\b" nil t)
1479 (let ((next (char-after))
1480 (previous (char-after (- (point) 2))))
1481 ;; We do the boldification/underlining by hiding the
1482 ;; overstrikes and putting the proper text property
1486 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1487 (put-text-property (point) (1+ (point)) 'face 'bold))
1489 (gnus-article-hide-text-type
1490 (1- (point)) (1+ (point)) 'overstrike)
1492 (- (point) 2) (1- (point)) 'face 'underline))
1494 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1496 (point) (1+ (point)) 'face 'underline)))))))))
1498 (defun article-fill-long-lines ()
1499 "Fill lines that are wider than the window width."
1502 (let ((buffer-read-only nil)
1503 (width (window-width (get-buffer-window (current-buffer)))))
1506 (let ((adaptive-fill-mode nil))
1509 (when (>= (current-column) (min fill-column width))
1510 (narrow-to-region (point) (gnus-point-at-bol))
1511 (fill-paragraph nil)
1512 (goto-char (point-max))
1514 (forward-line 1)))))))
1516 (defun article-capitalize-sentences ()
1517 "Capitalize the first word in each sentence."
1520 (let ((buffer-read-only nil)
1521 (paragraph-start "^[\n\^L]"))
1525 (forward-sentence)))))
1527 (defun article-remove-cr ()
1528 "Remove trailing CRs and then translate remaining CRs into LFs."
1531 (let ((buffer-read-only nil))
1532 (goto-char (point-min))
1533 (while (re-search-forward "\r+$" nil t)
1534 (replace-match "" t t))
1535 (goto-char (point-min))
1536 (while (search-forward "\r" nil t)
1537 (replace-match "\n" t t)))))
1539 (defun article-remove-trailing-blank-lines ()
1540 "Remove all trailing blank lines from the article."
1543 (let ((buffer-read-only nil))
1544 (goto-char (point-max))
1548 (while (and (not (bobp))
1549 (looking-at "^[ \t]*$")
1550 (not (gnus-annotation-in-region-p
1551 (point) (gnus-point-at-eol))))
1556 (defun article-display-x-face (&optional force)
1557 "Look for an X-Face header and display it if present."
1558 (interactive (list 'force))
1560 ;; Delete the old process, if any.
1561 (when (process-status "article-x-face")
1562 (delete-process "article-x-face"))
1563 (let ((inhibit-point-motion-hooks t)
1565 (case-fold-search t)
1568 (article-narrow-to-head)
1569 (when (and buffer-read-only ;; When type `W f'
1571 (goto-char (point-min))
1572 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1573 (gnus-buffer-live-p gnus-original-article-buffer))
1574 (with-current-buffer gnus-original-article-buffer
1576 (article-narrow-to-head)
1577 (while (re-search-forward "^X-Face:" nil t)
1583 (1- (re-search-forward
1584 "^\\($\\|[^ \t]\\)" nil t))))))))
1586 (let (point start bface eface buffer-read-only)
1587 (goto-char (point-max))
1589 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1590 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1591 (goto-char (point-max))
1592 (setq point (point))
1595 (while (looking-at "\\([^:]+\\): *")
1596 (put-text-property (match-beginning 1) (1+ (match-end 1))
1598 (setq start (match-end 0))
1600 (while (looking-at "[\t ]")
1602 (put-text-property start (point)
1604 (goto-char (point-min))
1605 (setq from (message-fetch-field "from"))
1606 (goto-char (point-min))
1607 (while (and gnus-article-x-face-command
1610 ;; Check whether this face is censored.
1611 (not gnus-article-x-face-too-ugly)
1612 (and gnus-article-x-face-too-ugly from
1613 (not (string-match gnus-article-x-face-too-ugly
1615 ;; Has to be present.
1616 (re-search-forward "^X-Face:[\t ]*" nil t))
1617 ;; This used to try to do multiple faces (`while' instead of
1618 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1619 ;; work (b) it can crash some versions of Emacs (c) are
1620 ;; multiple faces really something to encourage?
1621 (when (stringp gnus-article-x-face-command)
1623 ;; We now have the area of the buffer where the X-Face is stored.
1626 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1627 ;; We display the face.
1628 (if (symbolp gnus-article-x-face-command)
1629 ;; The command is a lisp function, so we call it.
1630 (if (gnus-functionp gnus-article-x-face-command)
1631 (funcall gnus-article-x-face-command beg end)
1632 (error "%s is not a function" gnus-article-x-face-command))
1633 ;; The command is a string, so we interpret the command
1634 ;; as a, well, command, and fork it off.
1635 (let ((process-connection-type nil))
1636 (process-kill-without-query
1638 "article-x-face" nil shell-file-name shell-command-switch
1639 gnus-article-x-face-command))
1640 (process-send-region "article-x-face" beg end)
1641 (process-send-eof "article-x-face"))))))))))
1643 (defun article-decode-mime-words ()
1644 "Decode all MIME-encoded words in the article."
1647 (set-buffer gnus-article-buffer)
1648 (let ((inhibit-point-motion-hooks t)
1650 (mail-parse-charset gnus-newsgroup-charset)
1651 (mail-parse-ignored-charsets
1652 (save-excursion (set-buffer gnus-summary-buffer)
1653 gnus-newsgroup-ignored-charsets)))
1654 (mail-decode-encoded-word-region (point-min) (point-max)))))
1656 (defun article-decode-charset (&optional prompt)
1657 "Decode charset-encoded text in the article.
1658 If PROMPT (the prefix), prompt for a coding system to use."
1660 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1662 (mail-parse-charset gnus-newsgroup-charset)
1663 (mail-parse-ignored-charsets
1664 (save-excursion (condition-case nil
1665 (set-buffer gnus-summary-buffer)
1667 gnus-newsgroup-ignored-charsets))
1668 ct cte ctl charset format)
1671 (article-narrow-to-head)
1672 (setq ct (message-fetch-field "Content-Type" t)
1673 cte (message-fetch-field "Content-Transfer-Encoding" t)
1674 ctl (and ct (ignore-errors
1675 (mail-header-parse-content-type ct)))
1678 (mm-read-coding-system "Charset to decode: "))
1680 (mail-content-type-get ctl 'charset)))
1681 format (and ctl (mail-content-type-get ctl 'format)))
1683 (setq cte (mail-header-strip cte)))
1684 (if (and ctl (not (string-match "/" (car ctl))))
1686 (goto-char (point-max)))
1689 (narrow-to-region (point) (point-max))
1690 (when (and (eq mail-parse-charset 'gnus-decoded)
1691 (eq (mm-body-7-or-8) '8bit))
1692 ;; The text code could have been decoded.
1693 (setq charset mail-parse-charset))
1694 (when (and (or (not ctl)
1695 (equal (car ctl) "text/plain"))
1696 (not format)) ;; article with format will decode later.
1698 charset (and cte (intern (downcase
1699 (gnus-strip-whitespace cte))))
1702 (defun article-decode-encoded-words ()
1703 "Remove encoded-word encoding from headers."
1704 (let ((inhibit-point-motion-hooks t)
1705 (mail-parse-charset gnus-newsgroup-charset)
1706 (mail-parse-ignored-charsets
1707 (save-excursion (condition-case nil
1708 (set-buffer gnus-summary-buffer)
1710 gnus-newsgroup-ignored-charsets))
1713 (article-narrow-to-head)
1714 (funcall gnus-decode-header-function (point-min) (point-max)))))
1716 (defun article-de-quoted-unreadable (&optional force)
1717 "Translate a quoted-printable-encoded article.
1718 If FORCE, decode the article whether it is marked as quoted-printable
1720 (interactive (list 'force))
1722 (let ((buffer-read-only nil) type charset)
1723 (if (gnus-buffer-live-p gnus-original-article-buffer)
1724 (with-current-buffer gnus-original-article-buffer
1726 (gnus-fetch-field "content-transfer-encoding"))
1727 (let* ((ct (gnus-fetch-field "content-type"))
1730 (mail-header-parse-content-type ct)))))
1731 (setq charset (and ctl
1732 (mail-content-type-get ctl 'charset)))
1733 (if (stringp charset)
1734 (setq charset (intern (downcase charset)))))))
1736 (setq charset gnus-newsgroup-charset))
1738 (and type (let ((case-fold-search t))
1739 (string-match "quoted-printable" type))))
1741 (quoted-printable-decode-region
1742 (point) (point-max) (mm-charset-to-coding-system charset))))))
1744 (defun article-de-base64-unreadable (&optional force)
1745 "Translate a base64 article.
1746 If FORCE, decode the article whether it is marked as base64 not."
1747 (interactive (list 'force))
1749 (let ((buffer-read-only nil) type charset)
1750 (if (gnus-buffer-live-p gnus-original-article-buffer)
1751 (with-current-buffer gnus-original-article-buffer
1753 (gnus-fetch-field "content-transfer-encoding"))
1754 (let* ((ct (gnus-fetch-field "content-type"))
1757 (mail-header-parse-content-type ct)))))
1758 (setq charset (and ctl
1759 (mail-content-type-get ctl 'charset)))
1760 (if (stringp charset)
1761 (setq charset (intern (downcase charset)))))))
1763 (setq charset gnus-newsgroup-charset))
1765 (and type (let ((case-fold-search t))
1766 (string-match "base64" type))))
1769 (narrow-to-region (point) (point-max))
1770 (base64-decode-region (point-min) (point-max))
1771 (mm-decode-coding-region
1772 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1777 (defun article-decode-HZ ()
1778 "Translate a HZ-encoded article."
1782 (let ((buffer-read-only nil))
1783 (rfc1843-decode-region (point-min) (point-max)))))
1785 (defun article-wash-html ()
1786 "Format an html article."
1789 (let ((buffer-read-only nil)
1791 (if (gnus-buffer-live-p gnus-original-article-buffer)
1792 (with-current-buffer gnus-original-article-buffer
1793 (let* ((ct (gnus-fetch-field "content-type"))
1796 (mail-header-parse-content-type ct)))))
1797 (setq charset (and ctl
1798 (mail-content-type-get ctl 'charset)))
1799 (if (stringp charset)
1800 (setq charset (intern (downcase charset)))))))
1802 (setq charset gnus-newsgroup-charset))
1804 (save-window-excursion
1806 (narrow-to-region (point) (point-max))
1808 (let ((w3-strict-width (window-width))
1809 (url-standalone-mode t))
1811 (w3-region (point-min) (point-max))
1814 (defun article-hide-list-identifiers ()
1815 "Remove list identifies from the Subject header.
1816 The `gnus-list-identifiers' variable specifies what to do."
1820 (let ((inhibit-point-motion-hooks t)
1822 (article-narrow-to-head)
1823 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1824 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1826 (goto-char (point-min))
1827 (when (re-search-forward
1828 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1829 " *\\)\\)+\\(Re: +\\)?\\)")
1831 (let ((s (or (match-string 3) (match-string 5))))
1832 (delete-region (match-beginning 1) (match-end 1))
1834 (goto-char (match-beginning 1))
1837 (defun article-hide-pgp ()
1838 "Remove any PGP headers and signatures in the current article."
1842 (let ((inhibit-point-motion-hooks t)
1843 buffer-read-only beg end)
1845 ;; Hide the "header".
1846 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1847 (push 'pgp gnus-article-wash-types)
1848 (delete-region (match-beginning 0) (match-end 0))
1849 ;; Remove armor headers (rfc2440 6.2)
1850 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1853 ;; Hide the actual signature.
1854 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1855 (setq end (1+ (match-beginning 0)))
1858 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1860 ;; Perhaps we shouldn't hide to the end of the buffer
1861 ;; if there is no end to the signature?
1863 ;; Hide "- " PGP quotation markers.
1865 (narrow-to-region beg end)
1866 (goto-char (point-min))
1867 (while (re-search-forward "^- " nil t)
1869 (match-beginning 0) (match-end 0)))
1871 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1873 (defun article-hide-pem (&optional arg)
1874 "Toggle hiding of any PEM headers and signatures in the current article.
1875 If given a negative prefix, always show; if given a positive prefix,
1877 (interactive (gnus-article-hidden-arg))
1878 (unless (gnus-article-check-hidden-text 'pem arg)
1880 (let (buffer-read-only end)
1881 (goto-char (point-min))
1882 ;; Hide the horrendously ugly "header".
1883 (when (and (search-forward
1884 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1886 (setq end (1+ (match-beginning 0))))
1887 (push 'pem gnus-article-wash-types)
1888 (gnus-article-hide-text-type
1890 (if (search-forward "\n\n" nil t)
1894 ;; Hide the trailer as well
1895 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1897 (gnus-article-hide-text-type
1898 (match-beginning 0) (match-end 0) 'pem)))))))
1900 (defun article-strip-banner ()
1901 "Strip the banner specified by the `banner' group parameter."
1905 (let ((inhibit-point-motion-hooks t)
1906 (banner (gnus-parameter-banner gnus-newsgroup-name))
1907 (gnus-signature-limit nil)
1908 buffer-read-only beg end)
1912 ((eq banner 'signature)
1913 (when (gnus-article-narrow-to-signature)
1916 (delete-region (point) (point-max))))
1918 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1919 (while (re-search-forward banner nil t)
1920 (delete-region (match-beginning 0) (match-end 0)))))
1922 (while (re-search-forward banner nil t)
1923 (delete-region (match-beginning 0) (match-end 0))))))))))
1925 (defun article-babel ()
1926 "Translate article using an online translation service."
1930 (set-buffer gnus-article-buffer)
1931 (when (article-goto-body)
1932 (let* ((buffer-read-only nil)
1935 (orig (buffer-substring start end))
1936 (trans (babel-as-string orig)))
1938 (narrow-to-region start end)
1939 (delete-region start end)
1942 (defun article-hide-signature (&optional arg)
1943 "Hide the signature in the current article.
1944 If given a negative prefix, always show; if given a positive prefix,
1946 (interactive (gnus-article-hidden-arg))
1947 (unless (gnus-article-check-hidden-text 'signature arg)
1950 (let ((buffer-read-only nil))
1951 (when (gnus-article-narrow-to-signature)
1952 (gnus-article-hide-text-type
1953 (point-min) (point-max) 'signature)))))))
1955 (defun article-strip-headers-in-body ()
1956 "Strip offensive headers from bodies."
1960 (let ((case-fold-search t))
1961 (when (looking-at "x-no-archive:")
1962 (gnus-delete-line)))))
1964 (defun article-strip-leading-blank-lines ()
1965 "Remove all blank lines from the beginning of the article."
1968 (let ((inhibit-point-motion-hooks t)
1970 (when (article-goto-body)
1971 (while (and (not (eobp))
1972 (looking-at "[ \t]*$"))
1973 (gnus-delete-line))))))
1975 (defun article-narrow-to-head ()
1976 "Narrow the buffer to the head of the message.
1977 Point is left at the beginning of the narrowed-to region."
1979 (goto-char (point-min))
1980 (if (search-forward "\n\n" nil 1)
1983 (goto-char (point-min)))
1985 (defun article-goto-body ()
1986 "Place point at the start of the body."
1987 (goto-char (point-min))
1989 ;; This variable is only bound when dealing with separate
1991 (article-goto-body-goes-to-point-min-p
1993 ((search-forward "\n\n" nil t)
1996 (goto-char (point-max))
1999 (defun article-strip-multiple-blank-lines ()
2000 "Replace consecutive blank lines with one empty line."
2003 (let ((inhibit-point-motion-hooks t)
2005 ;; First make all blank lines empty.
2007 (while (re-search-forward "^[ \t]+$" nil t)
2008 (unless (gnus-annotation-in-region-p
2009 (match-beginning 0) (match-end 0))
2010 (replace-match "" nil t)))
2011 ;; Then replace multiple empty lines with a single empty line.
2013 (while (re-search-forward "\n\n\n+" nil t)
2014 (unless (gnus-annotation-in-region-p
2015 (match-beginning 0) (match-end 0))
2016 (replace-match "\n\n" t t))))))
2018 (defun article-strip-leading-space ()
2019 "Remove all white space from the beginning of the lines in the article."
2022 (let ((inhibit-point-motion-hooks t)
2025 (while (re-search-forward "^[ \t]+" nil t)
2026 (replace-match "" t t)))))
2028 (defun article-strip-trailing-space ()
2029 "Remove all white space from the end of the lines in the article."
2032 (let ((inhibit-point-motion-hooks t)
2035 (while (re-search-forward "[ \t]+$" nil t)
2036 (replace-match "" t t)))))
2038 (defun article-strip-blank-lines ()
2039 "Strip leading, trailing and multiple blank lines."
2041 (article-strip-leading-blank-lines)
2042 (article-remove-trailing-blank-lines)
2043 (article-strip-multiple-blank-lines))
2045 (defun article-strip-all-blank-lines ()
2046 "Strip all blank lines."
2049 (let ((inhibit-point-motion-hooks t)
2052 (while (re-search-forward "^[ \t]*\n" nil t)
2053 (replace-match "" t t)))))
2055 (defun gnus-article-narrow-to-signature ()
2056 "Narrow to the signature; return t if a signature is found, else nil."
2057 (let ((inhibit-point-motion-hooks t))
2058 (when (gnus-article-search-signature)
2060 ;; Check whether we have some limits to what we consider
2061 ;; to be a signature.
2062 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2063 (list gnus-signature-limit)))
2065 (while (setq limit (pop limits))
2066 (if (or (and (integerp limit)
2067 (< (- (point-max) (point)) limit))
2069 (< (count-lines (point) (point-max)) limit))
2070 (and (gnus-functionp limit)
2072 (and (stringp limit)
2073 (not (re-search-forward limit nil t))))
2074 () ; This limit did not succeed.
2078 (narrow-to-region (point) (point-max))
2081 (defun gnus-article-search-signature ()
2082 "Search the current buffer for the signature separator.
2083 Put point at the beginning of the signature separator."
2084 (let ((cur (point)))
2085 (goto-char (point-max))
2086 (if (if (stringp gnus-signature-separator)
2087 (re-search-backward gnus-signature-separator nil t)
2088 (let ((seps gnus-signature-separator))
2090 (not (re-search-backward (car seps) nil t)))
2097 (defun gnus-article-hidden-arg ()
2098 "Return the current prefix arg as a number, or 0 if no prefix."
2099 (list (if current-prefix-arg
2100 (prefix-numeric-value current-prefix-arg)
2103 (defun gnus-article-check-hidden-text (type arg)
2104 "Return nil if hiding is necessary.
2105 Arg can be nil or a number. Nil and positive means hide, negative
2106 means show, 0 means toggle."
2109 (let ((hide (gnus-article-hidden-text-p type)))
2115 (gnus-article-show-hidden-text type)
2118 (if (eq hide 'hidden)
2120 (gnus-article-show-hidden-text type)
2124 (defun gnus-article-hidden-text-p (type)
2125 "Say whether the current buffer contains hidden text of type TYPE."
2126 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2128 (not (get-text-property pos 'invisible))
2129 (not (get-text-property pos 'dummy-invisible)))
2131 (text-property-any (1+ pos) (point-max) 'article-type type)))
2136 (defun gnus-article-show-hidden-text (type &optional dummy)
2137 "Show all hidden text of type TYPE.
2138 Originally it is hide instead of DUMMY."
2139 (let ((buffer-read-only nil)
2140 (inhibit-point-motion-hooks t))
2141 (gnus-remove-text-properties-when
2143 (point-min) (point-max)
2144 (cons 'article-type (cons type
2145 gnus-hidden-properties)))))
2147 (defconst article-time-units
2148 `((year . ,(* 365.25 24 60 60))
2149 (week . ,(* 7 24 60 60))
2150 (day . ,(* 24 60 60))
2154 "Mapping from time units to seconds.")
2156 (defun article-date-ut (&optional type highlight header)
2157 "Convert DATE date to universal time in the current article.
2158 If TYPE is `local', convert to local time; if it is `lapsed', output
2159 how much time has lapsed since DATE. For `lapsed', the value of
2160 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2161 should replace the \"Date:\" one, or should be added below it."
2162 (interactive (list 'ut t))
2163 (let* ((header (or header
2164 (message-fetch-field "date")
2166 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2169 ((not gnus-article-date-lapsed-new-header)
2175 (date (if (vectorp header) (mail-header-date header)
2177 (inhibit-point-motion-hooks t)
2182 (article-narrow-to-head)
2183 (when (re-search-forward tdate-regexp nil t)
2184 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2185 date (or (get-text-property (gnus-point-at-bol)
2188 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2190 (when (and date (not (string= date "")))
2191 (goto-char (point-min))
2192 (let ((buffer-read-only nil))
2193 ;; Delete any old Date headers.
2194 (while (re-search-forward date-regexp nil t)
2196 (delete-region (progn (beginning-of-line) (point))
2197 (progn (forward-line 1) (point)))
2198 (delete-region (progn (beginning-of-line) (point))
2199 (progn (end-of-line) (point)))
2200 (setq pos (point))))
2201 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2203 (if pos (goto-char pos))
2204 (insert (article-make-date-line date (or type 'ut)))
2210 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2211 (put-text-property (match-beginning 1) (1+ (match-end 1))
2212 'original-date date)
2213 (put-text-property (match-beginning 1) (1+ (match-end 1))
2215 (put-text-property (match-beginning 2) (match-end 2)
2218 (defun article-make-date-line (date type)
2219 "Return a DATE line of TYPE."
2220 (let ((time (condition-case ()
2224 ;; Convert to the local timezone. We have to slap a
2225 ;; `condition-case' round the calls to the timezone
2226 ;; functions since they aren't particularly resistant to
2229 (let ((tz (car (current-time-zone time))))
2230 (format "Date: %s %s%02d%02d" (current-time-string time)
2231 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2232 (/ (% (abs tz) 3600) 60))))
2233 ;; Convert to Universal Time.
2236 (current-time-string
2237 (let* ((e (parse-time-string date))
2238 (tm (apply 'encode-time e))
2240 (ls (- (cadr tm) (car (current-time-zone time)))))
2241 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2242 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2245 ;; Get the original date from the article.
2246 ((eq type 'original)
2247 (concat "Date: " (if (string-match "\n+$" date)
2248 (substring date 0 (match-beginning 0))
2250 ;; Let the user define the format.
2252 (if (gnus-functionp gnus-article-time-format)
2253 (funcall gnus-article-time-format time)
2256 (format-time-string gnus-article-time-format time))))
2259 (let ((tz (car (current-time-zone time))))
2262 (format-time-string "%Y%m%dT%H%M%S" time)
2263 (format "%s%02d%02d"
2264 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2265 (/ (% (abs tz) 3600) 60)))))
2266 ;; Do an X-Sent lapsed format.
2268 ;; If the date is seriously mangled, the timezone functions are
2269 ;; liable to bug out, so we ignore all errors.
2270 (let* ((now (current-time))
2271 (real-time (subtract-time now time))
2272 (real-sec (and real-time
2273 (+ (* (float (car real-time)) 65536)
2275 (sec (and real-time (abs real-sec)))
2285 ;; This is a bit convoluted, but basically we go
2286 ;; through the time units for years, weeks, etc,
2287 ;; and divide things to see whether that results
2288 ;; in positive answers.
2291 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2292 ;; The (remaining) seconds are too few to
2293 ;; be divided into this time unit.
2295 ;; It's big enough, so we output it.
2296 (setq sec (- sec (* num (cdr unit))))
2298 (concat (if prev ", " "") (int-to-string
2300 " " (symbol-name (car unit))
2301 (if (> num 1) "s" ""))
2303 article-time-units "")
2304 ;; If dates are odd, then it might appear like the
2305 ;; article was sent in the future.
2308 " in the future"))))))
2309 ;; Display the date in proper English
2311 (let ((dtime (decode-time time)))
2314 (number-to-string (nth 3 dtime))
2315 (let ((digit (% (nth 3 dtime) 10)))
2317 ((memq (nth 3 dtime) '(11 12 13)) "th")
2323 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2325 (number-to-string (nth 5 dtime))
2327 (format "%02d" (nth 2 dtime))
2329 (format "%02d" (nth 1 dtime)))))
2331 (error "Unknown conversion type: %s" type)))))
2333 (defun article-date-local (&optional highlight)
2334 "Convert the current article date to the local timezone."
2335 (interactive (list t))
2336 (article-date-ut 'local highlight))
2338 (defun article-date-english (&optional highlight)
2339 "Convert the current article date to something that is proper English."
2340 (interactive (list t))
2341 (article-date-ut 'english highlight))
2343 (defun article-date-original (&optional highlight)
2344 "Convert the current article date to what it was originally.
2345 This is only useful if you have used some other date conversion
2346 function and want to see what the date was before converting."
2347 (interactive (list t))
2348 (article-date-ut 'original highlight))
2350 (defun article-date-lapsed (&optional highlight)
2351 "Convert the current article date to time lapsed since it was sent."
2352 (interactive (list t))
2353 (article-date-ut 'lapsed highlight))
2355 (defun article-update-date-lapsed ()
2356 "Function to be run from a timer to update the lapsed time line."
2357 (let (deactivate-mark)
2362 (set-buffer (window-buffer w))
2363 (when (eq major-mode 'gnus-article-mode)
2364 (goto-char (point-min))
2365 (when (re-search-forward "^X-Sent:" nil t)
2366 (article-date-lapsed t))))
2369 (defun gnus-start-date-timer (&optional n)
2370 "Start a timer to update the X-Sent header in the article buffers.
2371 The numerical prefix says how frequently (in seconds) the function
2376 (gnus-stop-date-timer)
2377 (setq article-lapsed-timer
2378 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2380 (defun gnus-stop-date-timer ()
2381 "Stop the X-Sent timer."
2383 (when article-lapsed-timer
2384 (nnheader-cancel-timer article-lapsed-timer)
2385 (setq article-lapsed-timer nil)))
2387 (defun article-date-user (&optional highlight)
2388 "Convert the current article date to the user-defined format.
2389 This format is defined by the `gnus-article-time-format' variable."
2390 (interactive (list t))
2391 (article-date-ut 'user highlight))
2393 (defun article-date-iso8601 (&optional highlight)
2394 "Convert the current article date to ISO8601."
2395 (interactive (list t))
2396 (article-date-ut 'iso8601 highlight))
2398 (defun article-show-all ()
2399 "Show all hidden text in the article buffer."
2402 (let ((buffer-read-only nil))
2403 (gnus-article-unhide-text (point-min) (point-max)))))
2405 (defun article-emphasize (&optional arg)
2406 "Emphasize text according to `gnus-emphasis-alist'."
2407 (interactive (gnus-article-hidden-arg))
2408 (unless (gnus-article-check-hidden-text 'emphasis arg)
2412 (with-current-buffer gnus-summary-buffer
2413 gnus-article-emphasis-alist)
2415 gnus-emphasis-alist))
2416 (buffer-read-only nil)
2417 (props (append '(article-type emphasis)
2418 gnus-hidden-properties))
2419 regexp elem beg invisible visible face)
2422 (while (setq elem (pop alist))
2424 (setq regexp (car elem)
2425 invisible (nth 1 elem)
2426 visible (nth 2 elem)
2428 (while (re-search-forward regexp nil t)
2429 (when (and (match-beginning visible) (match-beginning invisible))
2430 (push 'emphasis gnus-article-wash-types)
2431 (gnus-article-hide-text
2432 (match-beginning invisible) (match-end invisible) props)
2433 (gnus-article-unhide-text-type
2434 (match-beginning visible) (match-end visible) 'emphasis)
2435 (gnus-put-text-property-excluding-newlines
2436 (match-beginning visible) (match-end visible) 'face face)
2437 (goto-char (match-end invisible)))))))))
2439 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2440 "Setup newsgroup emphasis alist."
2441 (unless gnus-article-emphasis-alist
2442 (let ((name (and gnus-newsgroup-name
2443 (gnus-group-real-name gnus-newsgroup-name))))
2444 (make-local-variable 'gnus-article-emphasis-alist)
2445 (setq gnus-article-emphasis-alist
2447 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2448 (while (setq elem (pop alist))
2449 (when (and name (string-match (car elem) name))
2451 highlight (copy-sequence (cdr elem)))))
2453 (copy-sequence highlight-words)
2454 (if gnus-newsgroup-name
2455 (copy-sequence (gnus-group-find-parameter
2456 gnus-newsgroup-name 'highlight-words t)))
2457 gnus-emphasis-alist)))))
2459 (defvar gnus-summary-article-menu)
2460 (defvar gnus-summary-post-menu)
2462 ;;; Saving functions.
2464 (defun gnus-article-save (save-buffer file &optional num)
2465 "Save the currently selected article."
2466 (unless gnus-save-all-headers
2467 ;; Remove headers according to `gnus-saved-headers'.
2468 (let ((gnus-visible-headers
2469 (or gnus-saved-headers gnus-visible-headers))
2470 (gnus-article-buffer save-buffer))
2472 (set-buffer save-buffer)
2473 (article-hide-headers 1 t))))
2474 (save-window-excursion
2475 (if (not gnus-default-article-saver)
2476 (error "No default saver is defined")
2477 ;; !!! Magic! The saving functions all save
2478 ;; `gnus-save-article-buffer' (or so they think), but we
2479 ;; bind that variable to our save-buffer.
2480 (set-buffer gnus-article-buffer)
2481 (let* ((gnus-save-article-buffer save-buffer)
2484 ((not gnus-prompt-before-saving) 'default)
2485 ((eq gnus-prompt-before-saving 'always) nil)
2487 (gnus-number-of-articles-to-be-saved
2488 (when (eq gnus-prompt-before-saving t)
2490 (set-buffer gnus-article-current-summary)
2491 (funcall gnus-default-article-saver filename)))))
2493 (defun gnus-read-save-file-name (prompt &optional filename
2494 function group headers variable)
2496 (funcall function group headers (symbol-value variable)))
2501 ((eq filename 'default)
2507 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2510 (if (and gnus-number-of-articles-to-be-saved
2511 (> gnus-number-of-articles-to-be-saved 1))
2512 (format "these %d articles"
2513 gnus-number-of-articles-to-be-saved)
2516 ;; Let the split methods have their say.
2518 ;; No split name was found.
2521 (concat prompt " (default "
2522 (file-name-nondirectory default-name) ") ")
2523 (file-name-directory default-name)
2525 ;; A single group name is returned.
2526 ((stringp split-name)
2528 (funcall function split-name headers
2529 (symbol-value variable)))
2531 (concat prompt " (default "
2532 (file-name-nondirectory default-name) ") ")
2533 (file-name-directory default-name)
2535 ;; A single split name was found
2536 ((= 1 (length split-name))
2537 (let* ((name (expand-file-name
2539 gnus-article-save-directory))
2540 (dir (cond ((file-directory-p name)
2541 (file-name-as-directory name))
2542 ((file-exists-p name) name)
2543 (t gnus-article-save-directory))))
2545 (concat prompt " (default " name ") ")
2547 ;; A list of splits was found.
2549 (setq split-name (nreverse split-name))
2551 (let ((file-name-history
2552 (nconc split-name file-name-history)))
2556 (concat prompt " (`M-p' for defaults) ")
2557 gnus-article-save-directory
2559 gnus-article-save-directory)))
2560 (car (push result file-name-history)))))))
2561 ;; Create the directory.
2562 (gnus-make-directory (file-name-directory file))
2563 ;; If we have read a directory, we append the default file name.
2564 (when (file-directory-p file)
2565 (setq file (expand-file-name (file-name-nondirectory
2567 (file-name-as-directory file))))
2568 ;; Possibly translate some characters.
2569 (nnheader-translate-file-chars file))))))
2570 (gnus-make-directory (file-name-directory result))
2571 (set variable result)))
2573 (defun gnus-article-archive-name (group)
2574 "Return the first instance of an \"Archive-name\" in the current buffer."
2575 (let ((case-fold-search t))
2576 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2577 (nnheader-concat gnus-article-save-directory
2578 (match-string 1)))))
2580 (defun gnus-article-nndoc-name (group)
2581 "If GROUP is an nndoc group, return the name of the parent group."
2582 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2583 (gnus-group-get-parameter group 'save-article-group)))
2585 (defun gnus-summary-save-in-rmail (&optional filename)
2586 "Append this article to Rmail file.
2587 Optional argument FILENAME specifies file name.
2588 Directory to save to is default to `gnus-article-save-directory'."
2589 (setq filename (gnus-read-save-file-name
2590 "Save %s in rmail file:" filename
2591 gnus-rmail-save-name gnus-newsgroup-name
2592 gnus-current-headers 'gnus-newsgroup-last-rmail))
2593 (gnus-eval-in-buffer-window gnus-save-article-buffer
2597 (gnus-output-to-rmail filename))))
2600 (defun gnus-summary-save-in-mail (&optional filename)
2601 "Append this article to Unix mail file.
2602 Optional argument FILENAME specifies file name.
2603 Directory to save to is default to `gnus-article-save-directory'."
2604 (setq filename (gnus-read-save-file-name
2605 "Save %s in Unix mail file:" filename
2606 gnus-mail-save-name gnus-newsgroup-name
2607 gnus-current-headers 'gnus-newsgroup-last-mail))
2608 (gnus-eval-in-buffer-window gnus-save-article-buffer
2612 (if (and (file-readable-p filename)
2613 (mail-file-babyl-p filename))
2614 (rmail-output-to-rmail-file filename t)
2615 (gnus-output-to-mail filename)))))
2618 (defun gnus-summary-save-in-file (&optional filename overwrite)
2619 "Append this article to file.
2620 Optional argument FILENAME specifies file name.
2621 Directory to save to is default to `gnus-article-save-directory'."
2622 (setq filename (gnus-read-save-file-name
2623 "Save %s in file:" filename
2624 gnus-file-save-name gnus-newsgroup-name
2625 gnus-current-headers 'gnus-newsgroup-last-file))
2626 (gnus-eval-in-buffer-window gnus-save-article-buffer
2630 (when (and overwrite
2631 (file-exists-p filename))
2632 (delete-file filename))
2633 (gnus-output-to-file filename))))
2636 (defun gnus-summary-write-to-file (&optional filename)
2637 "Write this article to a file.
2638 Optional argument FILENAME specifies file name.
2639 The directory to save in defaults to `gnus-article-save-directory'."
2640 (gnus-summary-save-in-file nil t))
2642 (defun gnus-summary-save-body-in-file (&optional filename)
2643 "Append this article body to a file.
2644 Optional argument FILENAME specifies file name.
2645 The directory to save in defaults to `gnus-article-save-directory'."
2646 (setq filename (gnus-read-save-file-name
2647 "Save %s body in file:" filename
2648 gnus-file-save-name gnus-newsgroup-name
2649 gnus-current-headers 'gnus-newsgroup-last-file))
2650 (gnus-eval-in-buffer-window gnus-save-article-buffer
2654 (when (article-goto-body)
2655 (narrow-to-region (point) (point-max)))
2656 (gnus-output-to-file filename))))
2659 (defun gnus-summary-save-in-pipe (&optional command)
2660 "Pipe this article to subprocess."
2662 (cond ((and (eq command 'default)
2663 gnus-last-shell-command)
2664 gnus-last-shell-command)
2668 "Shell command on %s: "
2669 (if (and gnus-number-of-articles-to-be-saved
2670 (> gnus-number-of-articles-to-be-saved 1))
2671 (format "these %d articles"
2672 gnus-number-of-articles-to-be-saved)
2674 gnus-last-shell-command))))
2675 (when (string-equal command "")
2676 (setq command gnus-last-shell-command))
2677 (gnus-eval-in-buffer-window gnus-article-buffer
2680 (shell-command-on-region (point-min) (point-max) command nil)))
2681 (setq gnus-last-shell-command command))
2683 ;;; Article file names when saving.
2685 (defun gnus-capitalize-newsgroup (newsgroup)
2686 "Capitalize NEWSGROUP name."
2687 (when (not (zerop (length newsgroup)))
2688 (concat (char-to-string (upcase (aref newsgroup 0)))
2689 (substring newsgroup 1))))
2691 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2692 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2693 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2694 Otherwise, it is like ~/News/news/group/num."
2697 (concat (if (gnus-use-long-file-name 'not-save)
2698 (gnus-capitalize-newsgroup newsgroup)
2699 (gnus-newsgroup-directory-form newsgroup))
2700 "/" (int-to-string (mail-header-number headers)))
2701 gnus-article-save-directory)))
2703 (string-equal (file-name-directory default)
2704 (file-name-directory last-file))
2705 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2707 (or last-file default))))
2709 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2710 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2711 If variable `gnus-use-long-file-name' is non-nil, it is
2712 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2715 (concat (if (gnus-use-long-file-name 'not-save)
2717 (gnus-newsgroup-directory-form newsgroup))
2718 "/" (int-to-string (mail-header-number headers)))
2719 gnus-article-save-directory)))
2721 (string-equal (file-name-directory default)
2722 (file-name-directory last-file))
2723 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2725 (or last-file default))))
2727 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2728 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2729 If variable `gnus-use-long-file-name' is non-nil, it is
2730 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2733 (if (gnus-use-long-file-name 'not-save)
2735 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2736 gnus-article-save-directory)))
2738 (defun article-verify-x-pgp-sig ()
2741 (if (gnus-buffer-live-p gnus-original-article-buffer)
2742 (let ((sig (with-current-buffer gnus-original-article-buffer
2743 (gnus-fetch-field "X-PGP-Sig")))
2747 (mml2015-clear-verify-function))
2749 (insert-buffer gnus-original-article-buffer)
2750 (setq items (split-string sig))
2751 (message-narrow-to-head)
2752 (let ((inhibit-point-motion-hooks t)
2753 (case-fold-search t))
2754 ;; Don't verify multiple headers.
2755 (setq headers (mapconcat (lambda (header)
2757 (mail-fetch-field header) "\n"))
2758 (split-string (nth 1 items) ",") "")))
2759 (delete-region (point-min) (point-max))
2760 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2761 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2766 (if (looking-at "^-")
2769 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2770 (insert "Version: " (car items) "\n\n")
2771 (insert (mapconcat 'identity (cddr items) "\n"))
2772 (insert "\n-----END PGP SIGNATURE-----\n")
2773 (let ((mm-security-handle (list (format "multipart/signed"))))
2774 (mml2015-clean-buffer)
2775 (let ((coding-system-for-write (or gnus-newsgroup-charset
2777 (funcall (mml2015-clear-verify-function)))
2779 (or (mm-handle-multipart-ctl-parameter
2780 mm-security-handle 'gnus-details)
2781 (mm-handle-multipart-ctl-parameter
2782 mm-security-handle 'gnus-info)))))
2784 (let (buffer-read-only bface eface)
2786 (message-narrow-to-head)
2787 (goto-char (point-max))
2789 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2790 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2791 (message-remove-header "X-Gnus-PGP-Verify")
2792 (if (re-search-forward "^X-PGP-Sig:" nil t)
2794 (goto-char (point-max)))
2795 (narrow-to-region (point) (point))
2796 (insert "X-Gnus-PGP-Verify: " info "\n")
2797 (goto-char (point-min))
2800 (if (not (looking-at "^[ \t]"))
2804 (goto-char (point-min))
2805 (when (looking-at "\\([^:]+\\): *")
2806 (put-text-property (match-beginning 1) (1+ (match-end 1))
2808 (put-text-property (match-end 0) (point-max)
2809 'face eface)))))))))
2816 (setq afunc (car func)
2819 gfunc (intern (format "gnus-%s" func))))
2822 `(lambda (&optional interactive &rest args)
2823 ,(documentation afunc t)
2824 (interactive (list t))
2826 (set-buffer gnus-article-buffer)
2828 (call-interactively ',afunc)
2829 (apply ',afunc args))))))))
2830 '(article-hide-headers
2831 article-verify-x-pgp-sig
2832 article-hide-boring-headers
2833 article-treat-overstrike
2834 article-fill-long-lines
2835 article-capitalize-sentences
2837 article-display-x-face
2838 article-de-quoted-unreadable
2839 article-de-base64-unreadable
2842 article-hide-list-identifiers
2844 article-strip-banner
2847 article-hide-signature
2848 article-strip-headers-in-body
2849 article-remove-trailing-blank-lines
2850 article-strip-leading-blank-lines
2851 article-strip-multiple-blank-lines
2852 article-strip-leading-space
2853 article-strip-trailing-space
2854 article-strip-blank-lines
2855 article-strip-all-blank-lines
2857 article-date-english
2858 article-date-iso8601
2859 article-date-original
2861 article-decode-mime-words
2862 article-decode-charset
2863 article-decode-encoded-words
2867 article-treat-dumbquotes
2868 article-normalize-headers
2869 (article-show-all . gnus-article-show-all-headers))))
2872 ;;; Gnus article mode
2875 (put 'gnus-article-mode 'mode-class 'special)
2877 (set-keymap-parent gnus-article-mode-map widget-keymap)
2879 (gnus-define-keys gnus-article-mode-map
2880 " " gnus-article-goto-next-page
2881 "\177" gnus-article-goto-prev-page
2882 [delete] gnus-article-goto-prev-page
2883 [backspace] gnus-article-goto-prev-page
2884 "\C-c^" gnus-article-refer-article
2885 "h" gnus-article-show-summary
2886 "s" gnus-article-show-summary
2887 "\C-c\C-m" gnus-article-mail
2888 "?" gnus-article-describe-briefly
2889 "e" gnus-summary-edit-article
2890 "<" beginning-of-buffer
2892 "\C-c\C-i" gnus-info-find-node
2894 "\C-hk" gnus-article-describe-key
2895 "\C-hc" gnus-article-describe-key-briefly
2897 "\C-d" gnus-article-read-summary-keys
2898 "\M-*" gnus-article-read-summary-keys
2899 "\M-#" gnus-article-read-summary-keys
2900 "\M-^" gnus-article-read-summary-keys
2901 "\M-g" gnus-article-read-summary-keys)
2903 (substitute-key-definition
2904 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2907 (defvar gnus-article-commands-menu))
2909 (defun gnus-article-make-menu-bar ()
2910 (gnus-turn-off-edit-menu 'article)
2911 (unless (boundp 'gnus-article-article-menu)
2913 gnus-article-article-menu gnus-article-mode-map ""
2915 ["Scroll forwards" gnus-article-goto-next-page t]
2916 ["Scroll backwards" gnus-article-goto-prev-page t]
2917 ["Show summary" gnus-article-show-summary t]
2918 ["Fetch Message-ID at point" gnus-article-refer-article t]
2919 ["Mail to address at point" gnus-article-mail t]
2920 ["Send a bug report" gnus-bug t]))
2923 gnus-article-treatment-menu gnus-article-mode-map ""
2924 ;; Fixme: this should use :active (and maybe :visible).
2926 ["Hide headers" gnus-article-hide-headers t]
2927 ["Hide signature" gnus-article-hide-signature t]
2928 ["Hide citation" gnus-article-hide-citation t]
2929 ["Treat overstrike" gnus-article-treat-overstrike t]
2930 ["Remove carriage return" gnus-article-remove-cr t]
2931 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2932 ["Remove base64" gnus-article-de-base64-unreadable t]
2933 ["Treat html" gnus-article-wash-html t]
2934 ["Decode HZ" gnus-article-decode-HZ t]))
2936 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2938 (when (boundp 'gnus-summary-post-menu)
2939 (define-key gnus-article-mode-map [menu-bar post]
2940 (cons "Post" gnus-summary-post-menu)))
2942 (gnus-run-hooks 'gnus-article-menu-hook))
2944 (when (boundp 'gnus-article-commands-menu)
2945 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
2946 (when (boundp 'gnus-summary-post-menu)
2947 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
2949 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2952 (defun gnus-article-mode ()
2953 "Major mode for displaying an article.
2955 All normal editing commands are switched off.
2957 The following commands are available in addition to all summary mode
2959 \\<gnus-article-mode-map>
2960 \\[gnus-article-next-page]\t Scroll the article one page forwards
2961 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2962 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2963 \\[gnus-article-show-summary]\t Display the summary buffer
2964 \\[gnus-article-mail]\t Send a reply to the address near point
2965 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2966 \\[gnus-info-find-node]\t Go to the Gnus info node"
2968 (when (gnus-visual-p 'article-menu 'menu)
2969 (gnus-article-make-menu-bar))
2970 (gnus-simplify-mode-line)
2971 (setq mode-name "Article")
2972 (setq major-mode 'gnus-article-mode)
2973 (make-local-variable 'minor-mode-alist)
2974 (use-local-map gnus-article-mode-map)
2975 (gnus-update-format-specifications nil 'article-mode)
2976 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2977 (make-local-variable 'gnus-page-broken)
2978 (make-local-variable 'gnus-button-marker-list)
2979 (make-local-variable 'gnus-article-current-summary)
2980 (make-local-variable 'gnus-article-mime-handles)
2981 (make-local-variable 'gnus-article-decoded-p)
2982 (make-local-variable 'gnus-article-mime-handle-alist)
2983 (make-local-variable 'gnus-article-wash-types)
2984 (make-local-variable 'gnus-article-charset)
2985 (make-local-variable 'gnus-article-ignored-charsets)
2986 (gnus-set-default-directory)
2987 (buffer-disable-undo)
2988 (setq buffer-read-only t)
2989 (set-syntax-table gnus-article-mode-syntax-table)
2990 (mm-enable-multibyte)
2991 (gnus-run-hooks 'gnus-article-mode-hook))
2993 (defun gnus-article-setup-buffer ()
2994 "Initialize the article buffer."
2995 (let* ((name (if gnus-single-article-buffer "*Article*"
2996 (concat "*Article " gnus-newsgroup-name "*")))
2998 (progn (string-match "\\*Article" name)
2999 (concat " *Original Article"
3000 (substring name (match-end 0))))))
3001 (setq gnus-article-buffer name)
3002 (setq gnus-original-article-buffer original)
3003 (setq gnus-article-mime-handle-alist nil)
3004 ;; This might be a variable local to the summary buffer.
3005 (unless gnus-single-article-buffer
3007 (set-buffer gnus-summary-buffer)
3008 (setq gnus-article-buffer name)
3009 (setq gnus-original-article-buffer original)
3010 (gnus-set-global-variables)))
3011 (gnus-article-setup-highlight-words)
3012 ;; Init original article buffer.
3014 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3015 (mm-enable-multibyte)
3016 (setq major-mode 'gnus-original-article-mode)
3017 (make-local-variable 'gnus-original-article))
3018 (if (get-buffer name)
3021 (when gnus-article-mime-handles
3022 (mm-destroy-parts gnus-article-mime-handles)
3023 (setq gnus-article-mime-handles nil))
3024 ;; Set it to nil in article-buffer!
3025 (setq gnus-article-mime-handle-alist nil)
3026 (buffer-disable-undo)
3027 (setq buffer-read-only t)
3028 (unless (eq major-mode 'gnus-article-mode)
3029 (gnus-article-mode))
3032 (set-buffer (gnus-get-buffer-create name))
3034 (make-local-variable 'gnus-summary-buffer)
3035 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3036 (current-buffer)))))
3038 ;; Set article window start at LINE, where LINE is the number of lines
3039 ;; from the head of the article.
3040 (defun gnus-article-set-window-start (&optional line)
3042 (get-buffer-window gnus-article-buffer t)
3044 (set-buffer gnus-article-buffer)
3045 (goto-char (point-min))
3048 (gnus-message 6 "Moved to bookmark")
3049 (search-forward "\n\n" nil t)
3053 (defun gnus-article-prepare (article &optional all-headers header)
3054 "Prepare ARTICLE in article mode buffer.
3055 ARTICLE should either be an article number or a Message-ID.
3056 If ARTICLE is an id, HEADER should be the article headers.
3057 If ALL-HEADERS is non-nil, no headers are hidden."
3059 ;; Make sure we start in a summary buffer.
3060 (unless (eq major-mode 'gnus-summary-mode)
3061 (set-buffer gnus-summary-buffer))
3062 (setq gnus-summary-buffer (current-buffer))
3063 (let* ((gnus-article (if header (mail-header-number header) article))
3064 (summary-buffer (current-buffer))
3065 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3066 (group gnus-newsgroup-name)
3069 (gnus-article-setup-buffer)
3070 (set-buffer gnus-article-buffer)
3071 ;; Deactivate active regions.
3072 (when (and (boundp 'transient-mark-mode)
3073 transient-mark-mode)
3074 (setq mark-active nil))
3075 (if (not (setq result (let ((buffer-read-only nil))
3076 (gnus-request-article-this-buffer
3078 ;; There is no such article.
3080 (when (and (numberp article)
3081 (not (memq article gnus-newsgroup-sparse)))
3082 (setq gnus-article-current
3083 (cons gnus-newsgroup-name article))
3084 (set-buffer gnus-summary-buffer)
3085 (setq gnus-current-article article)
3086 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3088 (gnus-summary-set-agent-mark article)
3089 (message "Message marked for downloading"))
3090 (gnus-summary-mark-article article gnus-canceled-mark)
3091 (unless (memq article gnus-newsgroup-sparse)
3092 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3093 (if (or (eq result 'pseudo)
3094 (eq result 'nneething))
3097 (set-buffer summary-buffer)
3098 (push article gnus-newsgroup-history)
3099 (setq gnus-last-article gnus-current-article
3100 gnus-current-article 0
3101 gnus-current-headers nil
3102 gnus-article-current nil)
3103 (if (eq result 'nneething)
3104 (gnus-configure-windows 'summary)
3105 (gnus-configure-windows 'article))
3106 (gnus-set-global-variables))
3107 (let ((gnus-article-mime-handle-alist-1
3108 gnus-article-mime-handle-alist))
3109 (gnus-set-mode-line 'article)))
3110 ;; The result from the `request' was an actual article -
3111 ;; or at least some text that is now displayed in the
3113 (when (and (numberp article)
3114 (not (eq article gnus-current-article)))
3115 ;; Seems like a new article has been selected.
3116 ;; `gnus-current-article' must be an article number.
3118 (set-buffer summary-buffer)
3119 (push article gnus-newsgroup-history)
3120 (setq gnus-last-article gnus-current-article
3121 gnus-current-article article
3122 gnus-current-headers
3123 (gnus-summary-article-header gnus-current-article)
3124 gnus-article-current
3125 (cons gnus-newsgroup-name gnus-current-article))
3126 (unless (vectorp gnus-current-headers)
3127 (setq gnus-current-headers nil))
3128 (gnus-summary-goto-subject gnus-current-article)
3129 (when (gnus-summary-show-thread)
3130 ;; If the summary buffer really was folded, the
3131 ;; previous goto may not actually have gone to
3132 ;; the right article, but the thread root instead.
3134 (gnus-summary-goto-subject gnus-current-article))
3135 (gnus-run-hooks 'gnus-mark-article-hook)
3136 (gnus-set-mode-line 'summary)
3137 (when (gnus-visual-p 'article-highlight 'highlight)
3138 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3139 ;; Set the global newsgroup variables here.
3140 (gnus-set-global-variables)
3141 (setq gnus-have-all-headers
3142 (or all-headers gnus-show-all-headers))))
3144 (gnus-configure-windows 'article))
3145 (when (or (numberp article)
3147 (gnus-article-prepare-display)
3149 (goto-char (point-min))
3150 (setq gnus-page-broken
3151 (when gnus-break-pages
3152 (gnus-narrow-to-page)
3154 (let ((gnus-article-mime-handle-alist-1
3155 gnus-article-mime-handle-alist))
3156 (gnus-set-mode-line 'article))
3158 (set-window-point (get-buffer-window (current-buffer)) (point))
3159 (gnus-configure-windows 'article)
3163 (defun gnus-article-prepare-display ()
3164 "Make the current buffer look like a nice article."
3165 ;; Hooks for getting information from the article.
3166 ;; This hook must be called before being narrowed.
3167 (let ((gnus-article-buffer (current-buffer))
3169 (unless (eq major-mode 'gnus-article-mode)
3170 (gnus-article-mode))
3171 (setq buffer-read-only nil
3172 gnus-article-wash-types nil)
3173 (gnus-run-hooks 'gnus-tmp-internal-hook)
3174 (when gnus-display-mime-function
3175 (funcall gnus-display-mime-function))
3176 (gnus-run-hooks 'gnus-article-prepare-hook)))
3179 ;;; Gnus MIME viewing functions
3182 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3183 "The following specs can be used:
3185 %T MIME type, along with additional info
3186 %n The `name' parameter
3187 %d The description, if any
3188 %l The length of the encoded part
3189 %p The part identifier number
3190 %e Dots if the part isn't displayed")
3192 (defvar gnus-mime-button-line-format-alist
3193 '((?t gnus-tmp-type ?s)
3194 (?T gnus-tmp-type-long ?s)
3195 (?n gnus-tmp-name ?s)
3196 (?d gnus-tmp-description ?s)
3198 (?l gnus-tmp-length ?d)
3199 (?e gnus-tmp-dots ?s)))
3201 (defvar gnus-mime-button-commands
3202 '((gnus-article-press-button "\r" "Toggle Display")
3203 (gnus-mime-view-part "v" "View Interactively...")
3204 (gnus-mime-view-part-as-type "t" "View As Type...")
3205 (gnus-mime-view-part-as-charset "C" "View As charset...")
3206 (gnus-mime-save-part "o" "Save...")
3207 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3208 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3209 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3210 (gnus-mime-internalize-part "E" "View Internally")
3211 (gnus-mime-externalize-part "e" "View Externally")
3212 (gnus-mime-pipe-part "|" "Pipe To Command...")
3213 (gnus-mime-action-on-part "." "Take action on the part")))
3215 (defun gnus-article-mime-part-status ()
3216 (if gnus-article-mime-handle-alist-1
3217 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
3220 (defvar gnus-mime-button-map
3221 (let ((map (make-sparse-keymap)))
3222 (unless (>= (string-to-number emacs-version) 21)
3223 ;; XEmacs doesn't care.
3224 (set-keymap-parent map gnus-article-mode-map))
3225 (define-key map gnus-mouse-2 'gnus-article-push-button)
3226 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3227 (dolist (c gnus-mime-button-commands)
3228 (define-key map (cadr c) (car c)))
3231 (defun gnus-mime-button-menu (event)
3232 "Construct a context-sensitive menu of MIME commands."
3234 (save-window-excursion
3235 (let ((pos (event-start event)))
3236 (select-window (posn-window pos))
3237 (goto-char (posn-point pos))
3238 (gnus-article-check-buffer)
3239 (let ((response (x-popup-menu
3241 ("" ,@(mapcar (lambda (c)
3242 (cons (caddr c) (car c)))
3243 gnus-mime-button-commands))))))
3245 (call-interactively response))))))
3247 (defun gnus-mime-view-all-parts (&optional handles)
3248 "View all the MIME parts."
3250 (save-current-buffer
3251 (set-buffer gnus-article-buffer)
3252 (let ((handles (or handles gnus-article-mime-handles))
3253 (mail-parse-charset gnus-newsgroup-charset)
3254 (mail-parse-ignored-charsets
3255 (with-current-buffer gnus-summary-buffer
3256 gnus-newsgroup-ignored-charsets)))
3258 (mm-remove-parts handles)
3259 (goto-char (point-min))
3260 (or (search-forward "\n\n") (goto-char (point-max)))
3261 (let (buffer-read-only)
3262 (delete-region (point) (point-max)))
3263 (mm-display-parts handles)))))
3265 (defun gnus-mime-save-part-and-strip ()
3266 "Save the MIME part under point then replace it with an external body."
3268 (gnus-article-check-buffer)
3269 (let* ((data (get-text-property (point) 'gnus-data))
3270 (file (and data (mm-save-part data)))
3273 (with-current-buffer (mm-handle-buffer data)
3275 (insert "Content-Type: " (mm-handle-media-type data))
3276 (mml-insert-parameter-string (cdr (mm-handle-type data))
3279 (insert "Content-ID: " (message-make-message-id) "\n")
3280 (insert "Content-Transfer-Encoding: binary\n")
3283 (cdr (mm-make-handle nil
3284 `("message/external-body"
3285 (access-type . "LOCAL-FILE")
3287 (set-buffer gnus-summary-buffer)
3288 (gnus-article-edit-article
3291 (let ((mail-parse-charset (or gnus-article-charset
3292 ',gnus-newsgroup-charset))
3293 (mail-parse-ignored-charsets
3294 (or gnus-article-ignored-charsets
3295 ',gnus-newsgroup-ignored-charsets))
3296 (mbl mml-buffer-list))
3297 (setq mml-buffer-list nil)
3298 (insert-buffer gnus-original-article-buffer)
3299 (mime-to-mml gnus-article-mime-handles)
3300 (setq gnus-article-mime-handles nil)
3301 (make-local-hook 'kill-buffer-hook)
3302 (let ((mbl1 mml-buffer-list))
3303 (setq mml-buffer-list mbl)
3304 (set (make-local-variable 'mml-buffer-list) mbl1))
3305 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3306 `(lambda (no-highlight)
3307 (let ((mail-parse-charset (or gnus-article-charset
3308 ',gnus-newsgroup-charset))
3309 (message-options message-options)
3310 (message-options-set-recipient)
3311 (mail-parse-ignored-charsets
3312 (or gnus-article-ignored-charsets
3313 ',gnus-newsgroup-ignored-charsets)))
3315 (mml-destroy-buffers)
3316 (remove-hook 'kill-buffer-hook
3317 'mml-destroy-buffers t)
3318 (kill-local-variable 'mml-buffer-list))
3319 (gnus-summary-edit-article-done
3320 ,(or (mail-header-references gnus-current-headers) "")
3321 ,(gnus-group-read-only-p)
3322 ,gnus-summary-buffer no-highlight))))))
3324 (defun gnus-mime-save-part ()
3325 "Save the MIME part under point."
3327 (gnus-article-check-buffer)
3328 (let ((data (get-text-property (point) 'gnus-data)))
3330 (mm-save-part data))))
3332 (defun gnus-mime-pipe-part ()
3333 "Pipe the MIME part under point to a process."
3335 (gnus-article-check-buffer)
3336 (let ((data (get-text-property (point) 'gnus-data)))
3338 (mm-pipe-part data))))
3340 (defun gnus-mime-view-part ()
3341 "Interactively choose a viewing method for the MIME part under point."
3343 (gnus-article-check-buffer)
3344 (let ((data (get-text-property (point) 'gnus-data)))
3346 (push (setq data (copy-sequence data)) gnus-article-mime-handles)
3347 (mm-interactively-view-part data))))
3349 (defun gnus-mime-view-part-as-type-internal ()
3350 (gnus-article-check-buffer)
3351 (let* ((name (mail-content-type-get
3352 (mm-handle-type (get-text-property (point) 'gnus-data))
3354 (def-type (and name (mm-default-file-encoding name))))
3355 (and def-type (cons def-type 0))))
3357 (defun gnus-mime-view-part-as-type (&optional mime-type)
3358 "Choose a MIME media type, and view the part as such."
3361 (setq mime-type (completing-read
3362 "View as MIME type: "
3363 (mapcar #'list (mailcap-mime-types))
3365 (gnus-mime-view-part-as-type-internal))))
3366 (gnus-article-check-buffer)
3367 (let ((handle (get-text-property (point) 'gnus-data)))
3370 (mm-make-handle (mm-handle-buffer handle)
3371 (cons mime-type (cdr (mm-handle-type handle)))
3372 (mm-handle-encoding handle)
3373 (mm-handle-undisplayer handle)
3374 (mm-handle-disposition handle)
3375 (mm-handle-description handle)
3376 (mm-handle-cache handle)
3377 (mm-handle-id handle)))
3378 (push handle gnus-article-mime-handles)
3379 (gnus-mm-display-part handle))))
3381 (defun gnus-mime-copy-part (&optional handle)
3382 "Put the the MIME part under point into a new buffer."
3384 (gnus-article-check-buffer)
3385 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3386 (contents (and handle (mm-get-part handle)))
3388 (file-name-nondirectory
3390 (mail-content-type-get (mm-handle-type handle) 'name)
3391 (mail-content-type-get (mm-handle-type handle)
3394 (buffer (and base (generate-new-buffer base))))
3396 (switch-to-buffer buffer)
3398 ;; We do it this way to make `normal-mode' set the appropriate mode.
3401 (setq buffer-file-name (expand-file-name base))
3403 (setq buffer-file-name nil))
3404 (goto-char (point-min)))))
3406 (defun gnus-mime-inline-part (&optional handle arg)
3407 "Insert the MIME part under point into the current buffer."
3408 (interactive (list nil current-prefix-arg))
3409 (gnus-article-check-buffer)
3410 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3415 (if (and (not arg) (mm-handle-undisplayer handle))
3416 (mm-remove-part handle)
3417 (setq contents (mm-get-part handle))
3420 (setq charset (or (mail-content-type-get
3421 (mm-handle-type handle) 'charset)
3422 gnus-newsgroup-charset)))
3424 (if (mm-handle-undisplayer handle)
3425 (mm-remove-part handle))
3428 gnus-summary-show-article-charset-alist))
3429 (read-coding-system "Charset: ")))))
3431 (mm-insert-inline handle
3433 (setq charset (mm-charset-to-coding-system
3435 (not (eq charset 'ascii)))
3436 (mm-decode-coding-string contents charset)
3440 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3441 "Insert the MIME part under point into the current buffer."
3442 (interactive (list nil current-prefix-arg))
3443 (gnus-article-check-buffer)
3444 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3449 (if (mm-handle-undisplayer handle)
3450 (mm-remove-part handle))
3451 (let ((gnus-newsgroup-charset
3453 gnus-summary-show-article-charset-alist))
3454 (read-coding-system "Charset: ")))
3455 (gnus-newsgroup-ignored-charsets 'gnus-all))
3456 (gnus-article-press-button)))))
3458 (defun gnus-mime-externalize-part (&optional handle)
3459 "View the MIME part under point with an external viewer."
3461 (gnus-article-check-buffer)
3462 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3463 (mm-user-display-methods nil)
3464 (mm-inlined-types nil)
3465 (mail-parse-charset gnus-newsgroup-charset)
3466 (mail-parse-ignored-charsets
3467 (save-excursion (set-buffer gnus-summary-buffer)
3468 gnus-newsgroup-ignored-charsets)))
3470 (if (mm-handle-undisplayer handle)
3471 (mm-remove-part handle)
3472 (mm-display-part handle)))))
3474 (defun gnus-mime-internalize-part (&optional handle)
3475 "View the MIME part under point with an internal viewer.
3476 In no internal viewer is available, use an external viewer."
3478 (gnus-article-check-buffer)
3479 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3480 (mm-inlined-types '(".*"))
3481 (mm-inline-large-images t)
3482 (mail-parse-charset gnus-newsgroup-charset)
3483 (mail-parse-ignored-charsets
3484 (save-excursion (set-buffer gnus-summary-buffer)
3485 gnus-newsgroup-ignored-charsets)))
3487 (if (mm-handle-undisplayer handle)
3488 (mm-remove-part handle)
3489 (mm-display-part handle)))))
3491 (defun gnus-mime-action-on-part (&optional action)
3492 "Do something with the MIME attachment at \(point\)."
3494 (list (completing-read "Action: " gnus-mime-action-alist)))
3495 (gnus-article-check-buffer)
3496 (let ((action-pair (assoc action gnus-mime-action-alist)))
3498 (funcall (cdr action-pair)))))
3500 (defun gnus-article-part-wrapper (n function)
3501 (save-current-buffer
3502 (set-buffer gnus-article-buffer)
3503 (when (> n (length gnus-article-mime-handle-alist))
3504 (error "No such part"))
3505 (gnus-article-goto-part n)
3506 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3507 (funcall function handle))))
3509 (defun gnus-article-pipe-part (n)
3510 "Pipe MIME part N, which is the numerical prefix."
3512 (gnus-article-part-wrapper n 'mm-pipe-part))
3514 (defun gnus-article-save-part (n)
3515 "Save MIME part N, which is the numerical prefix."
3517 (gnus-article-part-wrapper n 'mm-save-part))
3519 (defun gnus-article-interactively-view-part (n)
3520 "View MIME part N interactively, which is the numerical prefix."
3522 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3524 (defun gnus-article-copy-part (n)
3525 "Copy MIME part N, which is the numerical prefix."
3527 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3529 (defun gnus-article-view-part-as-charset (n)
3530 "Copy MIME part N, which is the numerical prefix."
3532 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3534 (defun gnus-article-externalize-part (n)
3535 "View MIME part N externally, which is the numerical prefix."
3537 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3539 (defun gnus-article-inline-part (n)
3540 "Inline MIME part N, which is the numerical prefix."
3542 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3544 (defun gnus-article-mime-match-handle-first (condition)
3546 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3547 (while (setq ihandle (pop alist))
3549 ((functionp condition)
3550 (funcall condition (cdr ihandle)))
3551 ((eq condition 'undisplayed)
3552 (not (or (mm-handle-undisplayer (cdr ihandle))
3553 (equal (mm-handle-media-type (cdr ihandle))
3554 "multipart/alternative"))))
3555 ((eq condition 'undisplayed-alternative)
3556 (not (mm-handle-undisplayer (cdr ihandle))))
3558 (gnus-article-goto-part (car ihandle))
3559 (or (not n) (< (car ihandle) n)))
3560 (setq n (car ihandle))))
3564 (defun gnus-article-view-part (&optional n)
3565 "View MIME part N, which is the numerical prefix."
3567 (save-current-buffer
3568 (set-buffer gnus-article-buffer)
3569 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3570 gnus-article-mime-match-handle-function)))
3571 (when (> n (length gnus-article-mime-handle-alist))
3572 (error "No such part"))
3573 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3574 (when (gnus-article-goto-part n)
3575 (if (equal (car handle) "multipart/alternative")
3576 (gnus-article-press-button)
3577 (when (eq (gnus-mm-display-part handle) 'internal)
3578 (gnus-set-window-start)))))))
3580 (defsubst gnus-article-mime-total-parts ()
3581 (if (bufferp (car gnus-article-mime-handles))
3583 (1- (length gnus-article-mime-handles))))
3585 (defun gnus-mm-display-part (handle)
3586 "Display HANDLE and fix MIME button."
3587 (let ((id (get-text-property (point) 'gnus-part))
3592 (let ((window (selected-window))
3593 (mail-parse-charset gnus-newsgroup-charset)
3594 (mail-parse-ignored-charsets
3595 (save-excursion (set-buffer gnus-summary-buffer)
3596 gnus-newsgroup-ignored-charsets)))
3599 (let ((win (get-buffer-window (current-buffer) t))
3602 (select-window win))
3605 (if (mm-handle-displayed-p handle)
3606 ;; This will remove the part.
3607 (mm-display-part handle)
3609 (narrow-to-region (point) (1+ (point)))
3610 (mm-display-part handle)
3611 ;; We narrow to the part itself and
3612 ;; then call the treatment functions.
3613 (goto-char (point-min))
3615 (narrow-to-region (point) (point-max))
3618 (gnus-article-mime-total-parts)
3619 (mm-handle-media-type handle)))))
3620 (select-window window))))
3622 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3623 (gnus-insert-mime-button
3624 handle id (list (mm-handle-displayed-p handle)))
3625 (goto-char point))))
3627 (defun gnus-article-goto-part (n)
3628 "Go to MIME part N."
3629 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3631 (goto-char point))))
3633 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3634 (let ((gnus-tmp-name
3635 (or (mail-content-type-get (mm-handle-type handle)
3637 (mail-content-type-get (mm-handle-disposition handle)
3639 (mail-content-type-get (mm-handle-type handle)
3642 (gnus-tmp-type (mm-handle-media-type handle))
3643 (gnus-tmp-description
3644 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3647 (if (if displayed (car displayed)
3648 (mm-handle-displayed-p handle))
3650 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3652 gnus-tmp-type-long b e)
3653 (when (string-match ".*/" gnus-tmp-name)
3654 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3655 (setq gnus-tmp-type-long (concat gnus-tmp-type
3656 (and (not (equal gnus-tmp-name ""))
3657 (concat "; " gnus-tmp-name))))
3658 (or (equal gnus-tmp-description "")
3659 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3664 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3665 `(keymap ,gnus-mime-button-map
3666 ,@(if (>= (string-to-number emacs-version) 21)
3668 (list 'local-map gnus-mime-button-map))
3669 gnus-callback gnus-mm-display-part
3670 gnus-part ,gnus-tmp-id
3671 article-type annotation
3674 (widget-convert-button
3677 :action 'gnus-widget-press-button
3678 :button-keymap gnus-mime-button-map
3680 (lambda (widget/window &optional overlay pos)
3681 ;; Needed to properly clear the message due to a bug in
3682 ;; wid-edit (XEmacs only).
3683 (if (boundp 'help-echo-owns-message)
3684 (setq help-echo-owns-message t))
3686 "%S: %s the MIME part; %S: more options"
3687 (aref gnus-mouse-2 0)
3688 ;; XEmacs will get a single widget arg; Emacs 21 will get
3689 ;; window, overlay, position.
3690 (if (mm-handle-displayed-p
3692 (with-current-buffer (gnus-overlay-buffer overlay)
3693 (widget-get (widget-at (gnus-overlay-start overlay))
3695 (widget-get widget/window :mime-handle)))
3697 (aref gnus-down-mouse-3 0))))))
3699 (defun gnus-widget-press-button (elems el)
3700 (goto-char (widget-get elems :from))
3701 (gnus-article-press-button))
3703 (defvar gnus-displaying-mime nil)
3705 (defun gnus-display-mime (&optional ihandles)
3706 "Display the MIME parts."
3708 (save-selected-window
3709 (let ((window (get-buffer-window gnus-article-buffer))
3712 (select-window window)
3713 ;; We have to do this since selecting the window
3714 ;; may change the point. So we set the window point.
3715 (set-window-point window point)))
3716 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3717 buffer-read-only handle name type b e display)
3718 (when (and (not ihandles)
3719 (not gnus-displaying-mime))
3720 ;; Top-level call; we clean up.
3721 (when gnus-article-mime-handles
3722 (mm-destroy-parts gnus-article-mime-handles)
3723 (setq gnus-article-mime-handle-alist nil));; A trick.
3724 (setq gnus-article-mime-handles handles)
3725 ;; We allow users to glean info from the handles.
3726 (when gnus-article-mime-part-function
3727 (gnus-mime-part-function handles)))
3729 (or (not (stringp (car handles)))
3732 (when (and (not ihandles)
3733 (not gnus-displaying-mime))
3734 ;; Clean up for mime parts.
3736 (delete-region (point) (point-max)))
3737 (let ((gnus-displaying-mime t))
3738 (gnus-mime-display-part handles)))
3741 (narrow-to-region (point) (point-max))
3742 (gnus-treat-article nil 1 1)
3745 ;; Highlight the headers.
3749 (narrow-to-region (point-min) (point))
3750 (gnus-treat-article 'head))))))))
3752 (defvar gnus-mime-display-multipart-as-mixed nil)
3754 (defun gnus-mime-display-part (handle)
3757 ((not (stringp (car handle)))
3758 (gnus-mime-display-single handle))
3759 ;; User-defined multipart
3760 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3761 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3763 ;; multipart/alternative
3764 ((and (equal (car handle) "multipart/alternative")
3765 (not gnus-mime-display-multipart-as-mixed))
3766 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3767 (push (cons id handle) gnus-article-mime-handle-alist)
3768 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3769 ;; multipart/related
3770 ((and (equal (car handle) "multipart/related")
3771 (not gnus-mime-display-multipart-as-mixed))
3772 ;;;!!!We should find the start part, but we just default
3773 ;;;!!!to the first part.
3774 ;;(gnus-mime-display-part (cadr handle))
3775 ;;;!!! Most multipart/related is an HTML message plus images.
3776 ;;;!!! Unfortunately we are unable to let W3 display those
3777 ;;;!!! included images, so we just display it as a mixed multipart.
3778 ;;(gnus-mime-display-mixed (cdr handle))
3779 ;;;!!! No, w3 can display everything just fine.
3780 (gnus-mime-display-part (cadr handle)))
3781 ((equal (car handle) "multipart/signed")
3782 (or (memq 'signed gnus-article-wash-types)
3783 (push 'signed gnus-article-wash-types))
3784 (gnus-mime-display-security handle))
3785 ((equal (car handle) "multipart/encrypted")
3786 (or (memq 'encrypted gnus-article-wash-types)
3787 (push 'encrypted gnus-article-wash-types))
3788 (gnus-mime-display-security handle))
3789 ;; Other multiparts are handled like multipart/mixed.
3791 (gnus-mime-display-mixed (cdr handle)))))
3793 (defun gnus-mime-part-function (handles)
3794 (if (stringp (car handles))
3795 (mapcar 'gnus-mime-part-function (cdr handles))
3796 (funcall gnus-article-mime-part-function handles)))
3798 (defun gnus-mime-display-mixed (handles)
3799 (mapcar 'gnus-mime-display-part handles))
3801 (defun gnus-mime-display-single (handle)
3802 (let ((type (mm-handle-media-type handle))
3803 (ignored gnus-ignored-mime-types)
3810 (when (string-match (pop ignored) type)
3811 (throw 'ignored nil)))
3812 (if (and (setq not-attachment
3813 (and (not (mm-inline-override-p handle))
3814 (or (not (mm-handle-disposition handle))
3815 (equal (car (mm-handle-disposition handle))
3817 (mm-attachment-override-p handle))))
3818 (mm-automatic-display-p handle)
3819 (or (mm-inlined-p handle)
3820 (mm-automatic-external-display-p type)))
3822 (when (equal (mm-handle-media-supertype handle) "text")
3824 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3826 (push (cons id handle) gnus-article-mime-handle-alist)
3827 (when (or (not display)
3828 (not (gnus-unbuttonized-mime-type-p type)))
3829 ;(gnus-article-insert-newline)
3830 (gnus-insert-mime-button
3831 handle id (list (or display (and not-attachment text))))
3832 (gnus-article-insert-newline)
3833 ;(gnus-article-insert-newline)
3834 ;; Remember modify the number of forward lines.
3842 (let ((mail-parse-charset gnus-newsgroup-charset)
3843 (mail-parse-ignored-charsets
3844 (save-excursion (condition-case ()
3845 (set-buffer gnus-summary-buffer)
3847 gnus-newsgroup-ignored-charsets)))
3848 (mm-display-part handle t))
3849 (goto-char (point-max)))
3850 ((and text not-attachment)
3854 (gnus-article-insert-newline)
3855 (mm-insert-inline handle (mm-get-part handle))
3856 (goto-char (point-max))))
3860 (narrow-to-region beg (point))
3863 (gnus-article-mime-total-parts)
3864 (mm-handle-media-type handle)))))))))
3866 (defun gnus-unbuttonized-mime-type-p (type)
3867 "Say whether TYPE is to be unbuttonized."
3868 (unless gnus-inhibit-mime-unbuttonizing
3870 (let ((types gnus-unbuttonized-mime-types))
3872 (when (string-match (pop types) type)
3873 (throw 'found t)))))))
3875 (defun gnus-article-insert-newline ()
3876 "Insert a newline, but mark it as undeletable."
3877 (gnus-put-text-property
3878 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3880 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3881 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3884 handle buffer-read-only from props begend not-pref)
3885 (save-window-excursion
3888 (narrow-to-region (car ibegend)
3891 (goto-char (car ibegend))
3894 (delete-region (point-min) (point-max))
3895 (mm-remove-parts handles))
3896 (setq begend (list (point-marker)))
3898 (unless (setq not-pref (cadr (member preferred ihandles)))
3899 (setq not-pref (car ihandles)))
3902 (not (gnus-unbuttonized-mime-type-p
3903 "multipart/alternative")))
3904 (gnus-add-text-properties
3907 (insert (format "%d. " id))
3911 (unless ,(not ibegend)
3912 (setq gnus-article-mime-handle-alist
3913 ',gnus-article-mime-handle-alist))
3914 (gnus-mime-display-alternative
3915 ',ihandles ',not-pref ',begend ,id))
3916 ,@(if (>= (string-to-number emacs-version) 21)
3917 nil ;; XEmacs doesn't care
3918 (list 'local-map gnus-mime-button-map))
3919 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3920 face ,gnus-article-button-face
3921 keymap ,gnus-mime-button-map
3924 (widget-convert-button 'link from (point)
3925 :action 'gnus-widget-press-button
3926 :button-keymap gnus-widget-button-keymap)
3928 (while (setq handle (pop handles))
3929 (gnus-add-text-properties
3932 (insert (format "(%c) %-18s"
3933 (if (equal handle preferred) ?* ? )
3934 (mm-handle-media-type handle)))
3938 (unless ,(not ibegend)
3939 (setq gnus-article-mime-handle-alist
3940 ',gnus-article-mime-handle-alist))
3941 (gnus-mime-display-alternative
3942 ',ihandles ',handle ',begend ,id))
3943 ,@(if (>= (string-to-number emacs-version) 21)
3944 nil ;; XEmacs doesn't care
3945 (list 'local-map gnus-mime-button-map))
3946 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3947 face ,gnus-article-button-face
3948 keymap ,gnus-mime-button-map
3951 (widget-convert-button 'link from (point)
3952 :action 'gnus-widget-press-button
3953 :button-keymap gnus-widget-button-keymap)
3957 (if (stringp (car preferred))
3958 (gnus-display-mime preferred)
3959 (let ((mail-parse-charset gnus-newsgroup-charset)
3960 (mail-parse-ignored-charsets
3961 (save-excursion (set-buffer gnus-summary-buffer)
3962 gnus-newsgroup-ignored-charsets)))
3963 (mm-display-part preferred)
3967 (narrow-to-region (car begend) (point-max))
3969 nil (length gnus-article-mime-handle-alist)
3970 (gnus-article-mime-total-parts)
3971 (mm-handle-media-type handle))))))
3972 (goto-char (point-max))
3973 (setcdr begend (point-marker)))))
3975 (goto-char point))))
3977 (defun gnus-article-wash-status ()
3978 "Return a string which display status of article washing."
3980 (set-buffer gnus-article-buffer)
3981 (let ((cite (memq 'cite gnus-article-wash-types))
3982 (headers (memq 'headers gnus-article-wash-types))
3983 (boring (memq 'boring-headers gnus-article-wash-types))
3984 (pgp (memq 'pgp gnus-article-wash-types))
3985 (pem (memq 'pem gnus-article-wash-types))
3986 (signed (memq 'signed gnus-article-wash-types))
3987 (encrypted (memq 'encrypted gnus-article-wash-types))
3988 (signature (memq 'signature gnus-article-wash-types))
3989 (overstrike (memq 'overstrike gnus-article-wash-types))
3990 (emphasis (memq 'emphasis gnus-article-wash-types)))
3991 (format "%c%c%c%c%c%c"
3993 (if (or headers boring) ?h ? )
3994 (if (or pgp pem signed encrypted) ?p ? )
3995 (if signature ?s ? )
3996 (if overstrike ?o ? )
3997 (if emphasis ?e ? )))))
3999 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4001 (defun gnus-article-maybe-hide-headers ()
4002 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4003 Provided for backwards compatibility."
4004 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4005 (not (save-excursion (set-buffer gnus-summary-buffer)
4006 gnus-have-all-headers)))
4007 (not gnus-inhibit-hiding))
4008 (gnus-article-hide-headers)))
4012 (defun gnus-output-to-file (file-name)
4013 "Append the current article to a file named FILE-NAME."
4014 (let ((artbuf (current-buffer)))
4016 (insert-buffer-substring artbuf)
4017 ;; Append newline at end of the buffer as separator, and then
4019 (goto-char (point-max))
4021 (mm-append-to-file (point-min) (point-max) file-name)
4024 (defun gnus-narrow-to-page (&optional arg)
4025 "Narrow the article buffer to a page.
4026 If given a numerical ARG, move forward ARG pages."
4028 (setq arg (if arg (prefix-numeric-value arg) 0))
4030 (set-buffer gnus-article-buffer)
4031 (goto-char (point-min))
4033 ;; Remove any old next/prev buttons.
4034 (when (gnus-visual-p 'page-marker)
4035 (let ((buffer-read-only nil))
4036 (gnus-remove-text-with-property 'gnus-prev)
4037 (gnus-remove-text-with-property 'gnus-next)))
4040 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4042 (re-search-forward page-delimiter nil 'move arg)))
4043 (goto-char (match-end 0)))
4046 (if (re-search-forward page-delimiter nil 'move)
4049 (when (and (gnus-visual-p 'page-marker)
4050 (not (= (point-min) 1)))
4052 (goto-char (point-min))
4053 (gnus-insert-prev-page-button)))
4054 (when (and (gnus-visual-p 'page-marker)
4055 (< (+ (point-max) 2) (buffer-size)))
4057 (goto-char (point-max))
4058 (gnus-insert-next-page-button)))))
4060 ;; Article mode commands
4062 (defun gnus-article-goto-next-page ()
4063 "Show the next page of the article."
4065 (when (gnus-article-next-page)
4066 (goto-char (point-min))
4067 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4069 (defun gnus-article-goto-prev-page ()
4070 "Show the next page of the article."
4072 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4073 (gnus-article-prev-page nil)))
4075 (defun gnus-article-next-page (&optional lines)
4076 "Show the next page of the current article.
4077 If end of article, return non-nil. Otherwise return nil.
4078 Argument LINES specifies lines to be scrolled up."
4080 (move-to-window-line -1)
4083 (and (pos-visible-in-window-p) ;Not continuation line.
4085 ;; Nothing in this page.
4086 (if (or (not gnus-page-broken)
4089 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4091 (gnus-narrow-to-page 1) ;Go to next page.
4093 ;; More in this page.
4094 (let ((scroll-in-place nil))
4098 ;; Long lines may cause an end-of-buffer error.
4099 (goto-char (point-max)))))
4100 (move-to-window-line 0)
4103 (defun gnus-article-prev-page (&optional lines)
4104 "Show previous page of current article.
4105 Argument LINES specifies lines to be scrolled down."
4107 (move-to-window-line 0)
4108 (if (and gnus-page-broken
4110 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4112 (gnus-narrow-to-page -1) ;Go to previous page.
4113 (goto-char (point-max))
4115 (let ((scroll-in-place nil))
4119 (beginning-of-buffer
4120 (goto-char (point-min))))
4121 (move-to-window-line 0)))))
4123 (defun gnus-article-refer-article ()
4124 "Read article specified by message-id around point."
4126 (let ((point (point)))
4127 (search-forward ">" nil t) ;Move point to end of "<....>".
4128 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4129 (let ((message-id (match-string 1)))
4131 (set-buffer gnus-summary-buffer)
4132 (gnus-summary-refer-article message-id))
4134 (error "No references around point"))))
4136 (defun gnus-article-show-summary ()
4137 "Reconfigure windows to show summary buffer."
4139 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4140 (error "There is no summary buffer for this article buffer")
4141 (gnus-article-set-globals)
4142 (gnus-configure-windows 'article)
4143 (gnus-summary-goto-subject gnus-current-article)
4144 (gnus-summary-position-point)))
4146 (defun gnus-article-describe-briefly ()
4147 "Describe article mode commands briefly."
4149 (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")))
4151 (defun gnus-article-summary-command ()
4152 "Execute the last keystroke in the summary buffer."
4154 (let ((obuf (current-buffer))
4155 (owin (current-window-configuration))
4157 (switch-to-buffer gnus-article-current-summary 'norecord)
4158 (setq func (lookup-key (current-local-map) (this-command-keys)))
4159 (call-interactively func)
4161 (set-window-configuration owin)
4162 (set-window-point (get-buffer-window (current-buffer)) (point))))
4164 (defun gnus-article-summary-command-nosave ()
4165 "Execute the last keystroke in the summary buffer."
4168 (pop-to-buffer gnus-article-current-summary 'norecord)
4169 (setq func (lookup-key (current-local-map) (this-command-keys)))
4170 (call-interactively func)))
4172 (defun gnus-article-check-buffer ()
4173 "Beep if not in an article buffer."
4174 (unless (equal major-mode 'gnus-article-mode)
4175 (error "Command invoked outside of a Gnus article buffer")))
4177 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4178 "Read a summary buffer key sequence and execute it from the article buffer."
4180 (gnus-article-check-buffer)
4182 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4183 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4184 "=" "^" "\M-^" "|"))
4190 '("n" "Gn" "p" "Gp"))
4193 (set-buffer gnus-article-current-summary)
4194 (let (gnus-pick-mode)
4195 (push (or key last-command-event) unread-command-events)
4196 (setq keys (if (featurep 'xemacs)
4197 (events-to-keys (read-key-sequence nil))
4198 (read-key-sequence nil)))))
4202 (if (or (member keys nosaves)
4203 (member keys nosave-but-article)
4204 (member keys nosave-in-article))
4206 (save-window-excursion
4207 (pop-to-buffer gnus-article-current-summary 'norecord)
4208 ;; We disable the pick minor mode commands.
4209 (let (gnus-pick-mode)
4210 (setq func (lookup-key (current-local-map) keys))))
4214 (unless (member keys nosave-in-article)
4215 (set-buffer gnus-article-current-summary))
4216 (call-interactively func)
4217 (setq new-sum-point (point)))
4218 (when (member keys nosave-but-article)
4219 (pop-to-buffer gnus-article-buffer 'norecord)))
4220 ;; These commands should restore window configuration.
4221 (let ((obuf (current-buffer))
4222 (owin (current-window-configuration))
4224 (summary gnus-article-current-summary)
4225 func in-buffer selected)
4226 (if not-restore-window
4227 (pop-to-buffer summary 'norecord)
4228 (switch-to-buffer summary 'norecord))
4229 (setq in-buffer (current-buffer))
4230 ;; We disable the pick minor mode commands.
4231 (if (and (setq func (let (gnus-pick-mode)
4232 (lookup-key (current-local-map) keys)))
4235 (call-interactively func)
4236 (setq new-sum-point (point))
4237 (when (eq in-buffer (current-buffer))
4238 (setq selected (gnus-summary-select-article))
4240 (unless not-restore-window
4241 (set-window-configuration owin))
4242 (when (eq selected 'old)
4244 (set-window-start (get-buffer-window (current-buffer))
4246 (set-window-point (get-buffer-window (current-buffer))
4248 (let ((win (get-buffer-window gnus-article-current-summary)))
4250 (set-window-point win new-sum-point)))) )
4251 (switch-to-buffer gnus-article-buffer)
4254 (defun gnus-article-describe-key (key)
4255 "Display documentation of the function invoked by KEY. KEY is a string."
4256 (interactive "kDescribe key: ")
4257 (gnus-article-check-buffer)
4258 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4260 (set-buffer gnus-article-current-summary)
4261 (let (gnus-pick-mode)
4262 (push (elt key 0) unread-command-events)
4263 (setq key (if (featurep 'xemacs)
4264 (events-to-keys (read-key-sequence "Describe key: "))
4265 (read-key-sequence "Describe key: "))))
4267 (describe-key key)))
4269 (defun gnus-article-describe-key-briefly (key &optional insert)
4270 "Display documentation of the function invoked by KEY. KEY is a string."
4271 (interactive "kDescribe key: \nP")
4272 (gnus-article-check-buffer)
4273 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4275 (set-buffer gnus-article-current-summary)
4276 (let (gnus-pick-mode)
4277 (push (elt key 0) unread-command-events)
4278 (setq key (if (featurep 'xemacs)
4279 (events-to-keys (read-key-sequence "Describe key: "))
4280 (read-key-sequence "Describe key: "))))
4281 (describe-key-briefly key insert))
4282 (describe-key-briefly key insert)))
4284 (defun gnus-article-hide (&optional arg force)
4285 "Hide all the gruft in the current article.
4286 This means that PGP stuff, signatures, cited text and (some)
4287 headers will be hidden.
4288 If given a prefix, show the hidden text instead."
4289 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4290 (gnus-article-hide-headers arg)
4291 (gnus-article-hide-list-identifiers arg)
4292 (gnus-article-hide-pgp arg)
4293 (gnus-article-hide-citation-maybe arg force)
4294 (gnus-article-hide-signature arg))
4296 (defun gnus-article-maybe-highlight ()
4297 "Do some article highlighting if article highlighting is requested."
4298 (when (gnus-visual-p 'article-highlight 'highlight)
4299 (gnus-article-highlight-some)))
4301 (defun gnus-check-group-server ()
4302 ;; Make sure the connection to the server is alive.
4303 (unless (gnus-server-opened
4304 (gnus-find-method-for-group gnus-newsgroup-name))
4305 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4306 (gnus-request-group gnus-newsgroup-name t)))
4308 (defun gnus-request-article-this-buffer (article group)
4309 "Get an article and insert it into this buffer."
4310 (let (do-update-line sparse-header)
4314 (gnus-kill-all-overlays)
4315 (setq group (or group gnus-newsgroup-name))
4317 ;; Using `gnus-request-article' directly will insert the article into
4318 ;; `nntp-server-buffer' - so we'll save some time by not having to
4319 ;; copy it from the server buffer into the article buffer.
4321 ;; We only request an article by message-id when we do not have the
4322 ;; headers for it, so we'll have to get those.
4323 (when (stringp article)
4324 (gnus-read-header article))
4326 ;; If the article number is negative, that means that this article
4327 ;; doesn't belong in this newsgroup (possibly), so we find its
4328 ;; message-id and request it by id instead of number.
4329 (when (and (numberp article)
4331 (get-buffer gnus-summary-buffer)
4332 (gnus-buffer-exists-p gnus-summary-buffer))
4334 (set-buffer gnus-summary-buffer)
4335 (let ((header (gnus-summary-article-header article)))
4338 ((memq article gnus-newsgroup-sparse)
4339 ;; This is a sparse gap article.
4340 (setq do-update-line article)
4341 (setq article (mail-header-id header))
4342 (setq sparse-header (gnus-read-header article))
4343 (setq gnus-newsgroup-sparse
4344 (delq article gnus-newsgroup-sparse)))
4346 ;; It's a real article.
4347 (setq article (mail-header-id header)))
4349 ;; It is an extracted pseudo-article.
4350 (setq article 'pseudo)
4351 (gnus-request-pseudo-article header))))
4353 (let ((method (gnus-find-method-for-group
4354 gnus-newsgroup-name)))
4355 (when (and (eq (car method) 'nneething)
4357 (let ((dir (expand-file-name
4358 (mail-header-subject header)
4359 (file-name-as-directory
4360 (or (cadr (assq 'nneething-address method))
4362 (when (file-directory-p dir)
4363 (setq article 'nneething)
4364 (gnus-group-enter-directory dir))))))))
4367 ;; Refuse to select canceled articles.
4368 ((and (numberp article)
4370 (get-buffer gnus-summary-buffer)
4371 (gnus-buffer-exists-p gnus-summary-buffer)
4372 (eq (cdr (save-excursion
4373 (set-buffer gnus-summary-buffer)
4374 (assq article gnus-newsgroup-reads)))
4375 gnus-canceled-mark))
4377 ;; We first check `gnus-original-article-buffer'.
4378 ((and (get-buffer gnus-original-article-buffer)
4381 (set-buffer gnus-original-article-buffer)
4382 (and (equal (car gnus-original-article) group)
4383 (eq (cdr gnus-original-article) article))))
4384 (insert-buffer-substring gnus-original-article-buffer)
4386 ;; Check the backlog.
4387 ((and gnus-keep-backlog
4388 (gnus-backlog-request-article group article (current-buffer)))
4390 ;; Check asynchronous pre-fetch.
4391 ((gnus-async-request-fetched-article group article (current-buffer))
4392 (gnus-async-prefetch-next group article gnus-summary-buffer)
4393 (when (and (numberp article) gnus-keep-backlog)
4394 (gnus-backlog-enter-article group article (current-buffer)))
4397 ((and gnus-use-cache
4399 (gnus-cache-request-article article group))
4401 ;; Get the article and put into the article buffer.
4402 ((or (stringp article)
4404 (let ((gnus-override-method gnus-override-method)
4405 (methods (and (stringp article)
4406 gnus-refer-article-method))
4408 (buffer-read-only nil))
4409 (if (or (not (listp methods))
4410 (and (symbolp (car methods))
4411 (assq (car methods) nnoo-definition-alist)))
4412 (setq methods (list methods)))
4413 (when (and (null gnus-override-method)
4415 (setq gnus-override-method (pop methods)))
4417 (when (eq gnus-override-method 'current)
4418 (setq gnus-override-method gnus-current-select-method))
4420 (gnus-kill-all-overlays)
4421 (let ((gnus-newsgroup-name group))
4422 (gnus-check-group-server))
4423 (when (gnus-request-article article group (current-buffer))
4424 (when (numberp article)
4425 (gnus-async-prefetch-next group article
4426 gnus-summary-buffer)
4427 (when gnus-keep-backlog
4428 (gnus-backlog-enter-article
4429 group article (current-buffer))))
4430 (setq result 'article))
4433 (setq gnus-override-method (pop methods))
4434 (setq result 'done))))
4435 (and (eq result 'article) 'article)))
4439 ;; Associate this article with the current summary buffer.
4440 (setq gnus-article-current-summary gnus-summary-buffer)
4442 ;; Take the article from the original article buffer
4443 ;; and place it in the buffer it's supposed to be in.
4444 (when (and (get-buffer gnus-article-buffer)
4445 (equal (buffer-name (current-buffer))
4446 (buffer-name (get-buffer gnus-article-buffer))))
4448 (if (get-buffer gnus-original-article-buffer)
4449 (set-buffer gnus-original-article-buffer)
4450 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4451 (buffer-disable-undo)
4452 (setq major-mode 'gnus-original-article-mode)
4453 (setq buffer-read-only t))
4454 (let (buffer-read-only)
4456 (insert-buffer-substring gnus-article-buffer))
4457 (setq gnus-original-article (cons group article)))
4460 (run-hooks 'gnus-article-decode-hook)
4461 ;; Mark article as decoded or not.
4462 (setq gnus-article-decoded-p gnus-article-decode-hook))
4464 ;; Update sparse articles.
4465 (when (and do-update-line
4466 (or (numberp article)
4468 (let ((buf (current-buffer)))
4469 (set-buffer gnus-summary-buffer)
4470 (gnus-summary-update-article do-update-line sparse-header)
4471 (gnus-summary-goto-subject do-update-line nil t)
4472 (set-window-point (get-buffer-window (current-buffer) t)
4474 (set-buffer buf))))))
4480 (defcustom gnus-article-edit-mode-hook nil
4481 "Hook run in article edit mode buffers."
4482 :group 'gnus-article-various
4485 (defvar gnus-article-edit-done-function nil)
4487 (defvar gnus-article-edit-mode-map nil)
4489 ;; Should we be using derived.el for this?
4490 (unless gnus-article-edit-mode-map
4491 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4492 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4494 (gnus-define-keys gnus-article-edit-mode-map
4495 "\C-c\C-c" gnus-article-edit-done
4496 "\C-c\C-k" gnus-article-edit-exit)
4498 (gnus-define-keys (gnus-article-edit-wash-map
4499 "\C-c\C-w" gnus-article-edit-mode-map)
4500 "f" gnus-article-edit-full-stops))
4502 (defun gnus-article-edit-mode ()
4503 "Major mode for editing articles.
4504 This is an extended text-mode.
4506 \\{gnus-article-edit-mode-map}"
4508 (setq major-mode 'gnus-article-edit-mode)
4509 (setq mode-name "Article Edit")
4510 (use-local-map gnus-article-edit-mode-map)
4511 (make-local-variable 'gnus-article-edit-done-function)
4512 (make-local-variable 'gnus-prev-winconf)
4513 (setq buffer-read-only nil)
4514 (buffer-enable-undo)
4516 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4518 (defun gnus-article-edit (&optional force)
4519 "Edit the current article.
4520 This will have permanent effect only in mail groups.
4521 If FORCE is non-nil, allow editing of articles even in read-only
4524 (when (and (not force)
4525 (gnus-group-read-only-p))
4526 (error "The current newsgroup does not support article editing"))
4527 (gnus-article-date-original)
4528 (gnus-article-edit-article
4530 `(lambda (no-highlight)
4532 (gnus-summary-edit-article-done
4533 ,(or (mail-header-references gnus-current-headers) "")
4534 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4536 (defun gnus-article-edit-article (start-func exit-func)
4537 "Start editing the contents of the current article buffer."
4538 (let ((winconf (current-window-configuration)))
4539 (set-buffer gnus-article-buffer)
4540 (gnus-article-edit-mode)
4541 (funcall start-func)
4542 (gnus-configure-windows 'edit-article)
4543 (setq gnus-article-edit-done-function exit-func)
4544 (setq gnus-prev-winconf winconf)
4545 (gnus-message 6 "C-c C-c to end edits")))
4547 (defun gnus-article-edit-done (&optional arg)
4548 "Update the article edits and exit."
4550 (let ((func gnus-article-edit-done-function)
4551 (buf (current-buffer))
4552 (start (window-start)))
4553 (gnus-article-edit-exit)
4556 (let ((buffer-read-only nil))
4558 ;; The cache and backlog have to be flushed somewhat.
4559 (when gnus-keep-backlog
4560 (gnus-backlog-remove-article
4561 (car gnus-article-current) (cdr gnus-article-current)))
4562 ;; Flush original article as well.
4564 (when (get-buffer gnus-original-article-buffer)
4565 (set-buffer gnus-original-article-buffer)
4566 (setq gnus-original-article nil)))
4567 (when gnus-use-cache
4568 (gnus-cache-update-article
4569 (car gnus-article-current) (cdr gnus-article-current))))
4571 (set-window-start (get-buffer-window buf) start)
4572 (set-window-point (get-buffer-window buf) (point))))
4574 (defun gnus-article-edit-exit ()
4575 "Exit the article editing without updating."
4577 ;; We remove all text props from the article buffer.
4578 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4579 (curbuf (current-buffer))
4581 (window-start (window-start)))
4584 (let ((winconf gnus-prev-winconf))
4586 (set-window-configuration winconf)
4587 ;; Tippy-toe some to make sure that point remains where it was.
4588 (save-current-buffer
4590 (set-window-start (get-buffer-window (current-buffer)) window-start)
4593 (defun gnus-article-edit-full-stops ()
4594 "Interactively repair spacing at end of sentences."
4597 (goto-char (point-min))
4598 (search-forward-regexp "^$" nil t)
4599 (let ((case-fold-search nil))
4600 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4603 ;;; Article highlights
4606 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4608 ;;; Internal Variables:
4610 (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\\)\\)"
4611 "Regular expression that matches URLs."
4612 :group 'gnus-article-buttons
4615 (defcustom gnus-button-alist
4616 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4617 0 t gnus-button-message-id 2)
4618 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4619 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4621 gnus-button-fetch-group 4)
4622 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4623 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4624 t gnus-button-message-id 3)
4625 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4626 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
4627 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4628 ;; This is how URLs _should_ be embedded in text...
4629 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4631 (,gnus-button-url-regexp 0 t browse-url 0))
4632 "*Alist of regexps matching buttons in article bodies.
4634 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4635 REGEXP: is the string matching text around the button,
4636 BUTTON: is the number of the regexp grouping actually matching the button,
4637 FORM: is a lisp expression which must eval to true for the button to
4639 CALLBACK: is the function to call when the user push this button, and each
4640 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4642 CALLBACK can also be a variable, in that case the value of that
4643 variable it the real callback function."
4644 :group 'gnus-article-buttons
4645 :type '(repeat (list regexp
4646 (integer :tag "Button")
4648 (function :tag "Callback")
4651 (integer :tag "Regexp group")))))
4653 (defcustom gnus-header-button-alist
4654 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4655 0 t gnus-button-message-id 0)
4656 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4657 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4658 0 t gnus-button-mailto 0)
4659 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4660 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4661 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4662 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4663 gnus-button-message-id 3))
4664 "*Alist of headers and regexps to match buttons in article heads.
4666 This alist is very similar to `gnus-button-alist', except that each
4667 alist has an additional HEADER element first in each entry:
4669 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4671 HEADER is a regexp to match a header. For a fuller explanation, see
4672 `gnus-button-alist'."
4673 :group 'gnus-article-buttons
4674 :group 'gnus-article-headers
4675 :type '(repeat (list (regexp :tag "Header")
4677 (integer :tag "Button")
4679 (function :tag "Callback")
4682 (integer :tag "Regexp group")))))
4684 (defvar gnus-button-regexp nil)
4685 (defvar gnus-button-marker-list nil)
4686 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4688 (defvar gnus-button-last nil)
4689 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4693 (defun gnus-article-push-button (event)
4694 "Check text under the mouse pointer for a callback function.
4695 If the text under the mouse pointer has a `gnus-callback' property,
4696 call it with the value of the `gnus-data' text property."
4698 (set-buffer (window-buffer (posn-window (event-start event))))
4699 (let* ((pos (posn-point (event-start event)))
4700 (data (get-text-property pos 'gnus-data))
4701 (fun (get-text-property pos 'gnus-callback)))
4704 (funcall fun data))))
4706 (defun gnus-article-press-button ()
4707 "Check text at point for a callback function.
4708 If the text at point has a `gnus-callback' property,
4709 call it with the value of the `gnus-data' text property."
4711 (let* ((data (get-text-property (point) 'gnus-data))
4712 (fun (get-text-property (point) 'gnus-callback)))
4714 (funcall fun data))))
4716 (defun gnus-article-highlight (&optional force)
4717 "Highlight current article.
4718 This function calls `gnus-article-highlight-headers',
4719 `gnus-article-highlight-citation',
4720 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4721 do the highlighting. See the documentation for those functions."
4722 (interactive (list 'force))
4723 (gnus-article-highlight-headers)
4724 (gnus-article-highlight-citation force)
4725 (gnus-article-highlight-signature)
4726 (gnus-article-add-buttons force)
4727 (gnus-article-add-buttons-to-head))
4729 (defun gnus-article-highlight-some (&optional force)
4730 "Highlight current article.
4731 This function calls `gnus-article-highlight-headers',
4732 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4733 do the highlighting. See the documentation for those functions."
4734 (interactive (list 'force))
4735 (gnus-article-highlight-headers)
4736 (gnus-article-highlight-signature)
4737 (gnus-article-add-buttons))
4739 (defun gnus-article-highlight-headers ()
4740 "Highlight article headers as specified by `gnus-header-face-alist'."
4743 (set-buffer gnus-article-buffer)
4745 (let ((alist gnus-header-face-alist)
4746 (buffer-read-only nil)
4747 (case-fold-search t)
4748 (inhibit-point-motion-hooks t)
4749 entry regexp header-face field-face from hpoints fpoints)
4750 (article-narrow-to-head)
4751 (while (setq entry (pop alist))
4752 (goto-char (point-min))
4753 (setq regexp (concat "^\\("
4754 (if (string-equal "" (nth 0 entry))
4758 header-face (nth 1 entry)
4759 field-face (nth 2 entry))
4760 (while (and (re-search-forward regexp nil t)
4764 (unless (search-forward ":" nil t)
4766 (when (and header-face
4767 (not (memq (point) hpoints)))
4768 (push (point) hpoints)
4769 (gnus-put-text-property from (point) 'face header-face))
4770 (when (and field-face
4771 (not (memq (setq from (point)) fpoints)))
4773 (if (re-search-forward "^[^ \t]" nil t)
4775 (goto-char (point-max)))
4776 (gnus-put-text-property from (point) 'face field-face))))))))
4778 (defun gnus-article-highlight-signature ()
4779 "Highlight the signature in an article.
4780 It does this by highlighting everything after
4781 `gnus-signature-separator' using `gnus-signature-face'."
4784 (set-buffer gnus-article-buffer)
4785 (let ((buffer-read-only nil)
4786 (inhibit-point-motion-hooks t))
4788 (when (and gnus-signature-face
4789 (gnus-article-narrow-to-signature))
4790 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4791 'face gnus-signature-face)
4793 (gnus-article-search-signature)
4794 (let ((start (match-beginning 0))
4795 (end (set-marker (make-marker) (1+ (match-end 0)))))
4796 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4799 (defun gnus-button-in-region-p (b e prop)
4800 "Say whether PROP exists in the region."
4801 (text-property-not-all b e prop nil))
4803 (defun gnus-article-add-buttons (&optional force)
4804 "Find external references in the article and make buttons of them.
4805 \"External references\" are things like Message-IDs and URLs, as
4806 specified by `gnus-button-alist'."
4807 (interactive (list 'force))
4809 (set-buffer gnus-article-buffer)
4810 (let ((buffer-read-only nil)
4811 (inhibit-point-motion-hooks t)
4812 (case-fold-search t)
4813 (alist gnus-button-alist)
4815 ;; Remove all old markers.
4816 (let (marker entry new-list)
4817 (while (setq marker (pop gnus-button-marker-list))
4818 (if (or (< marker (point-min)) (>= marker (point-max)))
4819 (push marker new-list)
4821 (when (setq entry (gnus-button-entry))
4822 (put-text-property (match-beginning (nth 1 entry))
4823 (match-end (nth 1 entry))
4824 'gnus-callback nil))
4825 (set-marker marker nil)))
4826 (setq gnus-button-marker-list new-list))
4827 ;; We skip the headers.
4830 (while (setq entry (pop alist))
4831 (setq regexp (car entry))
4833 (while (re-search-forward regexp nil t)
4834 (let* ((start (and entry (match-beginning (nth 1 entry))))
4835 (end (and entry (match-end (nth 1 entry))))
4836 (from (match-beginning 0)))
4837 (when (and (or (eq t (nth 2 entry))
4838 (eval (nth 2 entry)))
4839 (not (gnus-button-in-region-p
4840 start end 'gnus-callback)))
4841 ;; That optional form returned non-nil, so we add the
4843 (gnus-article-add-button
4844 start end 'gnus-button-push
4845 (car (push (set-marker (make-marker) from)
4846 gnus-button-marker-list))))))))))
4848 ;; Add buttons to the head of an article.
4849 (defun gnus-article-add-buttons-to-head ()
4850 "Add buttons to the head of the article."
4853 (set-buffer gnus-article-buffer)
4855 (let ((buffer-read-only nil)
4856 (inhibit-point-motion-hooks t)
4857 (case-fold-search t)
4858 (alist gnus-header-button-alist)
4860 (article-narrow-to-head)
4862 ;; Each alist entry.
4863 (setq entry (car alist)
4865 (goto-char (point-min))
4866 (while (re-search-forward (car entry) nil t)
4867 ;; Each header matching the entry.
4868 (setq beg (match-beginning 0))
4869 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4870 (match-beginning 0))
4873 (while (re-search-forward (nth 1 entry) end t)
4874 ;; Each match within a header.
4875 (let* ((entry (cdr entry))
4876 (start (match-beginning (nth 1 entry)))
4877 (end (match-end (nth 1 entry)))
4878 (form (nth 2 entry)))
4879 (goto-char (match-end 0))
4881 (gnus-article-add-button
4882 start end (nth 3 entry)
4883 (buffer-substring (match-beginning (nth 4 entry))
4884 (match-end (nth 4 entry)))))))
4885 (goto-char end)))))))
4887 ;;; External functions:
4889 (defun gnus-article-add-button (from to fun &optional data)
4890 "Create a button between FROM and TO with callback FUN and data DATA."
4891 (when gnus-article-button-face
4892 (gnus-overlay-put (gnus-make-overlay from to)
4893 'face gnus-article-button-face))
4894 (gnus-add-text-properties
4896 (nconc (and gnus-article-mouse-face
4897 (list gnus-mouse-face-prop gnus-article-mouse-face))
4898 (list 'gnus-callback fun)
4899 (and data (list 'gnus-data data))))
4900 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4901 :button-keymap gnus-widget-button-keymap))
4903 ;;; Internal functions:
4905 (defun gnus-article-set-globals ()
4907 (set-buffer gnus-summary-buffer)
4908 (gnus-set-global-variables)))
4910 (defun gnus-signature-toggle (end)
4912 (set-buffer gnus-article-buffer)
4913 (let ((buffer-read-only nil)
4914 (inhibit-point-motion-hooks t))
4915 (if (text-property-any end (point-max) 'article-type 'signature)
4916 (gnus-remove-text-properties-when
4917 'article-type 'signature end (point-max)
4918 (cons 'article-type (cons 'signature
4919 gnus-hidden-properties)))
4920 (gnus-add-text-properties-when
4921 'article-type nil end (point-max)
4922 (cons 'article-type (cons 'signature
4923 gnus-hidden-properties)))))))
4925 (defun gnus-button-entry ()
4926 ;; Return the first entry in `gnus-button-alist' matching this place.
4927 (let ((alist gnus-button-alist)
4930 (setq entry (pop alist))
4931 (if (looking-at (car entry))
4936 (defun gnus-button-push (marker)
4937 ;; Push button starting at MARKER.
4940 (let* ((entry (gnus-button-entry))
4941 (inhibit-point-motion-hooks t)
4943 (args (mapcar (lambda (group)
4944 (let ((string (match-string group)))
4945 (gnus-set-text-properties
4946 0 (length string) nil string)
4953 (fboundp (symbol-value fun)))
4954 (apply (symbol-value fun) args))
4956 (gnus-message 1 "You must define `%S' to use this button"
4957 (cons fun args)))))))
4959 (defun gnus-button-message-id (message-id)
4962 (set-buffer gnus-summary-buffer)
4963 (gnus-summary-refer-article message-id)))
4965 (defun gnus-button-fetch-group (address)
4966 "Fetch GROUP specified by ADDRESS."
4967 (if (not (string-match "[:/]" address))
4968 ;; This is just a simple group url.
4969 (gnus-group-read-ephemeral-group address gnus-select-method)
4970 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4972 (error "Can't parse %s" address)
4973 (gnus-group-read-ephemeral-group
4974 (match-string 4 address)
4975 `(nntp ,(match-string 1 address)
4976 (nntp-address ,(match-string 1 address))
4977 (nntp-port-number ,(if (match-end 3)
4978 (match-string 3 address)
4981 (defun gnus-url-parse-query-string (query &optional downcase)
4982 (let (retval pairs cur key val)
4983 (setq pairs (split-string query "&"))
4985 (setq cur (car pairs)
4987 (if (not (string-match "=" cur))
4989 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4990 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4992 (setq key (downcase key)))
4993 (setq cur (assoc key retval))
4995 (setcdr cur (cons val (cdr cur)))
4996 (setq retval (cons (list key val) retval)))))
4999 (defun gnus-url-unhex (x)
5006 (defun gnus-url-unhex-string (str &optional allow-newlines)
5007 "Remove %XXX embedded spaces, etc in a url.
5008 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5009 decoding of carriage returns and line feeds in the string, which is normally
5010 forbidden in URL encoding."
5011 (setq str (or str ""))
5013 (case-fold-search t))
5014 (while (string-match "%[0-9a-f][0-9a-f]" str)
5015 (let* ((start (match-beginning 0))
5016 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5018 (gnus-url-unhex (elt str (+ start 2))))))
5020 tmp (substring str 0 start)
5023 (char-to-string code))
5024 ((or (= code ?\n) (= code ?\r))
5026 (t (char-to-string code))))
5027 str (substring str (match-end 0)))))
5028 (setq tmp (concat tmp str))
5031 (defun gnus-url-mailto (url)
5032 ;; Send mail to someone
5033 (when (string-match "mailto:/*\\(.*\\)" url)
5034 (setq url (substring url (match-beginning 1) nil)))
5035 (let (to args subject func)
5036 (if (string-match (regexp-quote "?") url)
5037 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5038 args (gnus-url-parse-query-string
5039 (substring url (match-end 0) nil) t))
5040 (setq to (gnus-url-unhex-string url)))
5041 (setq args (cons (list "to" to) args)
5042 subject (cdr-safe (assoc "subject" args)))
5045 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5048 (message-position-on-field (caar args)))
5049 (insert (mapconcat 'identity (cdar args) ", "))
5050 (setq args (cdr args)))
5053 (message-goto-subject))))
5055 (defun gnus-button-embedded-url (address)
5056 "Activate ADDRESS with `browse-url'."
5057 (browse-url (gnus-strip-whitespace address)))
5059 ;;; Next/prev buttons in the article buffer.
5061 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5062 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5064 (defvar gnus-prev-page-map nil)
5065 (unless gnus-prev-page-map
5066 (setq gnus-prev-page-map (make-sparse-keymap))
5067 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5068 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5070 (defun gnus-insert-prev-page-button ()
5071 (let ((buffer-read-only nil))
5073 gnus-prev-page-line-format nil
5074 `(gnus-prev t local-map ,gnus-prev-page-map
5075 gnus-callback gnus-article-button-prev-page
5076 article-type annotation))))
5078 (defvar gnus-next-page-map nil)
5079 (unless gnus-next-page-map
5080 (setq gnus-next-page-map (make-keymap))
5081 (suppress-keymap gnus-prev-page-map)
5082 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5083 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5085 (defun gnus-button-next-page ()
5086 "Go to the next page."
5088 (let ((win (selected-window)))
5089 (select-window (get-buffer-window gnus-article-buffer t))
5090 (gnus-article-next-page)
5091 (select-window win)))
5093 (defun gnus-button-prev-page ()
5094 "Go to the prev page."
5096 (let ((win (selected-window)))
5097 (select-window (get-buffer-window gnus-article-buffer t))
5098 (gnus-article-prev-page)
5099 (select-window win)))
5101 (defun gnus-insert-next-page-button ()
5102 (let ((buffer-read-only nil))
5103 (gnus-eval-format gnus-next-page-line-format nil
5105 t local-map ,gnus-next-page-map
5106 gnus-callback gnus-article-button-next-page
5107 article-type annotation))))
5109 (defun gnus-article-button-next-page (arg)
5110 "Go to the next page."
5112 (let ((win (selected-window)))
5113 (select-window (get-buffer-window gnus-article-buffer t))
5114 (gnus-article-next-page)
5115 (select-window win)))
5117 (defun gnus-article-button-prev-page (arg)
5118 "Go to the prev page."
5120 (let ((win (selected-window)))
5121 (select-window (get-buffer-window gnus-article-buffer t))
5122 (gnus-article-prev-page)
5123 (select-window win)))
5125 (defvar gnus-decode-header-methods
5126 '(mail-decode-encoded-word-region)
5127 "List of methods used to decode headers.
5129 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5130 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5131 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5132 whose names match REGEXP.
5135 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5136 mail-decode-encoded-word-region
5137 (\"chinese\" . rfc1843-decode-region))
5140 (defvar gnus-decode-header-methods-cache nil)
5142 (defun gnus-multi-decode-header (start end)
5143 "Apply the functions from `gnus-encoded-word-methods' that match."
5144 (unless (and gnus-decode-header-methods-cache
5145 (eq gnus-newsgroup-name
5146 (car gnus-decode-header-methods-cache)))
5147 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5150 (nconc gnus-decode-header-methods-cache (list x))
5151 (if (and gnus-newsgroup-name
5152 (string-match (car x) gnus-newsgroup-name))
5153 (nconc gnus-decode-header-methods-cache
5155 gnus-decode-header-methods))
5156 (let ((xlist gnus-decode-header-methods-cache))
5159 (narrow-to-region start end)
5161 (funcall (pop xlist) (point-min) (point-max))))))
5164 ;;; Treatment top-level handling.
5167 (defun gnus-treat-article (condition &optional part-number total-parts type)
5168 (let ((length (- (point-max) (point-min)))
5169 (alist gnus-treatment-function-alist)
5170 (article-goto-body-goes-to-point-min-p t)
5174 (let ((list gnus-article-treat-types))
5176 (when (string-match (pop list) type)
5177 (throw 'found t)))))))
5178 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5180 (gnus-run-hooks 'gnus-part-display-hook)
5181 (while (setq elem (pop alist))
5184 (if (gnus-buffer-live-p gnus-summary-buffer)
5185 (set-buffer gnus-summary-buffer))
5186 (symbol-value (car elem))))
5187 (when (and (or (consp val)
5189 (gnus-treat-predicate val)
5190 (or (not (get (car elem) 'highlight))
5193 (funcall (cadr elem)))))))
5195 ;; Dynamic variables.
5197 (defvar part-number)
5198 (defvar total-parts)
5203 (defun gnus-treat-predicate (val)
5208 (stringp (car val)))
5209 (apply 'gnus-or (mapcar `(lambda (s)
5210 (string-match s ,(or gnus-newsgroup-name "")))
5213 (let ((pred (pop val)))
5216 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5218 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5220 (not (gnus-treat-predicate (car val))))
5222 (equal (car val) type))
5224 (error "%S is not a valid predicate" pred)))))
5232 (eq part-number total-parts))
5236 (error "%S is not a valid value" val))))
5238 (defun gnus-article-encrypt-body (protocol &optional n)
5239 "Encrypt the article body."
5242 (or gnus-article-encrypt-protocol
5243 (completing-read "Encrypt protocol: "
5244 gnus-article-encrypt-protocol-alist
5246 current-prefix-arg))
5247 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5249 (error (format "Can't find the encrypt protocol %s" protocol)))
5250 (if (equal gnus-newsgroup-name "nndraft:drafts")
5251 (error "Can't encrypt the article in group nndraft:drafts."))
5252 (if (equal gnus-newsgroup-name "nndraft:queue")
5253 (error "Don't encrypt the article in group nndraft:queue."))
5254 (gnus-summary-iterate n
5256 (set-buffer gnus-summary-buffer)
5257 (let ((mail-parse-charset gnus-newsgroup-charset)
5258 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5259 (summary-buffer gnus-summary-buffer)
5261 (gnus-set-global-variables)
5262 (when (gnus-group-read-only-p)
5263 (error "The current newsgroup does not support article encrypt"))
5264 (gnus-summary-show-article t)
5266 (or (mail-header-references gnus-current-headers) ""))
5267 (set-buffer gnus-article-buffer)
5268 (let* ((buffer-read-only nil)
5270 (mapcar (lambda (field)
5271 (and (save-restriction
5272 (message-narrow-to-head)
5273 (goto-char (point-min))
5274 (search-forward field nil t))
5276 (message-narrow-to-field)
5277 (buffer-substring (point-min) (point-max))
5278 (delete-region (point-min) (point-max))
5280 '("Content-Type:" "Content-Transfer-Encoding:"
5281 "Content-Disposition:"))))
5282 (message-narrow-to-head)
5283 (message-remove-header "MIME-Version")
5284 (goto-char (point-max))
5285 (setq point (point))
5286 (insert (apply 'concat headers))
5288 (narrow-to-region point (point-max))
5289 (let ((message-options message-options))
5290 (message-options-set 'message-sender user-mail-address)
5291 (message-options-set 'message-recipients user-mail-address)
5292 (message-options-set 'message-sign-encrypt 'not)
5294 (goto-char (point-min))
5295 (insert "MIME-Version: 1.0\n")
5297 (gnus-summary-edit-article-done
5298 references nil summary-buffer t))
5299 (when gnus-keep-backlog
5300 (gnus-backlog-remove-article
5301 (car gnus-article-current) (cdr gnus-article-current)))
5303 (when (get-buffer gnus-original-article-buffer)
5304 (set-buffer gnus-original-article-buffer)
5305 (setq gnus-original-article nil)))
5306 (when gnus-use-cache
5307 (gnus-cache-update-article
5308 (car gnus-article-current) (cdr gnus-article-current))))))))
5310 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5311 "The following specs can be used:
5312 %t The security MIME type
5315 %D Details if button is pressed")
5317 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5318 "The following specs can be used:
5319 %t The security MIME type
5322 %D Details if button is pressed")
5324 (defvar gnus-mime-security-button-line-format-alist
5325 '((?t gnus-tmp-type ?s)
5326 (?i gnus-tmp-info ?s)
5327 (?d gnus-tmp-details ?s)
5328 (?D gnus-tmp-pressed-details ?s)))
5330 (defvar gnus-mime-security-button-map
5331 (let ((map (make-sparse-keymap)))
5332 (unless (>= (string-to-number emacs-version) 21)
5333 (set-keymap-parent map gnus-article-mode-map))
5334 (define-key map gnus-mouse-2 'gnus-article-push-button)
5335 (define-key map "\r" 'gnus-article-press-button)
5338 (defvar gnus-mime-security-details-buffer nil)
5340 (defvar gnus-mime-security-button-pressed nil)
5342 (defvar gnus-mime-security-show-details-inline t
5343 "If non-nil, show details in the article buffer.")
5345 (defun gnus-mime-security-verify-or-decrypt (handle)
5346 (mm-remove-parts (cdr handle))
5347 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5350 (delete-region (car region) (cdr region))
5351 (set-marker (car region) nil)
5352 (set-marker (cdr region) nil)))
5353 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5354 (let* ((mm-verify-option 'known)
5355 (mm-decrypt-option 'known)
5356 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5357 (unless (eq nparts (cdr handle))
5358 (mm-destroy-parts (cdr handle))
5359 (setcdr handle nparts))))
5360 (let ((point (point))
5362 (gnus-mime-display-security handle)
5365 (defun gnus-mime-security-show-details (handle)
5366 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5368 (if gnus-mime-security-show-details-inline
5369 (let ((gnus-mime-security-button-pressed t)
5370 (gnus-mime-security-button-line-format
5371 (get-text-property (point) 'gnus-line-format))
5374 (while (eq (get-text-property (point) 'gnus-line-format)
5375 gnus-mime-security-button-line-format)
5378 (delete-region (point)
5379 (or (text-property-not-all
5382 gnus-mime-security-button-line-format)
5384 (gnus-insert-mime-security-button handle))
5385 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5386 (with-current-buffer gnus-mime-security-details-buffer
5389 (setq gnus-mime-security-details-buffer
5390 (gnus-get-buffer-create "*MIME Security Details*")))
5391 (with-current-buffer gnus-mime-security-details-buffer
5393 (goto-char (point-min)))
5394 (pop-to-buffer gnus-mime-security-details-buffer))
5395 (gnus-message 5 "No details."))))
5397 (defun gnus-mime-security-press-button (handle)
5398 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5399 (gnus-mime-security-show-details handle)
5400 (gnus-mime-security-verify-or-decrypt handle)))
5402 (defun gnus-insert-mime-security-button (handle &optional displayed)
5403 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5406 (or (nth 2 (assoc protocol mm-verify-function-alist))
5407 (nth 2 (assoc protocol mm-decrypt-function-alist))
5409 (if (equal (car handle) "multipart/signed")
5410 " Signed" " Encrypted")
5413 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5416 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5417 gnus-tmp-pressed-details
5419 (setq gnus-tmp-details
5420 (if gnus-tmp-details
5421 (concat "\n" gnus-tmp-details) ""))
5422 (setq gnus-tmp-pressed-details
5423 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5428 gnus-mime-security-button-line-format
5429 gnus-mime-security-button-line-format-alist
5430 `(keymap ,gnus-mime-security-button-map
5431 ,@(if (>= (string-to-number emacs-version) 21)
5432 nil ;; XEmacs doesn't care
5433 (list 'local-map gnus-mime-security-button-map))
5434 gnus-callback gnus-mime-security-press-button
5435 gnus-line-format ,gnus-mime-security-button-line-format
5436 article-type annotation
5439 (widget-convert-button
5442 :action 'gnus-widget-press-button
5443 :button-keymap gnus-mime-security-button-map
5445 (lambda (widget/window &optional overlay pos)
5446 ;; Needed to properly clear the message due to a bug in
5447 ;; wid-edit (XEmacs only).
5448 (if (boundp 'help-echo-owns-message)
5449 (setq help-echo-owns-message t))
5452 (aref gnus-mouse-2 0))))))
5454 (defun gnus-mime-display-security (handle)
5456 (narrow-to-region (point) (point))
5457 (gnus-insert-mime-security-button handle)
5458 (gnus-mime-display-mixed (cdr handle))
5461 (let ((gnus-mime-security-button-line-format
5462 gnus-mime-security-button-end-line-format))
5463 (gnus-insert-mime-security-button handle))
5464 (mm-set-handle-multipart-parameter
5466 (cons (set-marker (make-marker) (point-min))
5467 (set-marker (make-marker) (point-max))))))
5473 (run-hooks 'gnus-art-load-hook)
5475 ;;; gnus-art.el ends here