1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (eval-when-compile (require 'cl))
41 (defgroup gnus-article nil
43 :link '(custom-manual "(gnus)The Article Buffer")
46 (defgroup gnus-article-treat nil
47 "Treating article parts."
48 :link '(custom-manual "(gnus)Article Hiding")
51 (defgroup gnus-article-hiding nil
52 "Hiding article parts."
53 :link '(custom-manual "(gnus)Article Hiding")
56 (defgroup gnus-article-highlight nil
57 "Article highlighting."
58 :link '(custom-manual "(gnus)Article Highlighting")
62 (defgroup gnus-article-signature nil
64 :link '(custom-manual "(gnus)Article Signature")
67 (defgroup gnus-article-headers nil
69 :link '(custom-manual "(gnus)Hiding Headers")
72 (defgroup gnus-article-washing nil
73 "Special commands on articles."
74 :link '(custom-manual "(gnus)Article Washing")
77 (defgroup gnus-article-emphasis nil
78 "Fontisizing articles."
79 :link '(custom-manual "(gnus)Article Fontisizing")
82 (defgroup gnus-article-saving nil
84 :link '(custom-manual "(gnus)Saving Articles")
87 (defgroup gnus-article-mime nil
88 "Worshiping the MIME wonder."
89 :link '(custom-manual "(gnus)Using MIME")
92 (defgroup gnus-article-buttons nil
93 "Pushable buttons in the article buffer."
94 :link '(custom-manual "(gnus)Article Buttons")
97 (defgroup gnus-article-various nil
98 "Other article options."
99 :link '(custom-manual "(gnus)Misc Article")
100 :group 'gnus-article)
102 (defcustom gnus-ignored-headers
103 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
104 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
105 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
106 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
107 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
108 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
109 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
110 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
111 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
112 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
113 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
114 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
115 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
116 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
117 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
118 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
119 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
120 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
121 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
122 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
123 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
124 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
125 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
126 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
127 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
128 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
129 "^X-Received:" "^Content-length:" "X-precedence:"
130 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
131 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
133 "*All headers that start with this regexp will be hidden.
134 This variable can also be a list of regexps of headers to be ignored.
135 If `gnus-visible-headers' is non-nil, this variable will be ignored."
136 :type '(choice :custom-show nil
139 :group 'gnus-article-hiding)
141 (defcustom gnus-visible-headers
142 "^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:"
143 "*All headers that do not match this regexp will be hidden.
144 This variable can also be a list of regexp of headers to remain visible.
145 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
146 :type '(repeat :value-to-internal (lambda (widget value)
147 (custom-split-regexp-maybe value))
148 :match (lambda (widget value)
150 (widget-editable-list-match widget value)))
152 :group 'gnus-article-hiding)
154 (defcustom gnus-sorted-header-list
155 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
156 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
157 "*This variable is a list of regular expressions.
158 If it is non-nil, headers that match the regular expressions will
159 be placed first in the article buffer in the sequence specified by
161 :type '(repeat regexp)
162 :group 'gnus-article-hiding)
164 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
165 "Headers that are only to be displayed if they have interesting data.
166 Possible values in this list are `empty', `newsgroups', `followup-to',
167 `reply-to', `date', `long-to', and `many-to'."
168 :type '(set (const :tag "Headers with no content." empty)
169 (const :tag "Newsgroups with only one group." newsgroups)
170 (const :tag "Followup-to identical to newsgroups." followup-to)
171 (const :tag "Reply-to identical to from." reply-to)
172 (const :tag "Date less than four days old." date)
173 (const :tag "Very long To and/or Cc header." long-to)
174 (const :tag "Multiple To and/or Cc headers." many-to))
175 :group 'gnus-article-hiding)
177 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
178 "Regexp matching signature separator.
179 This can also be a list of regexps. In that case, it will be checked
180 from head to tail looking for a separator. Searches will be done from
181 the end of the buffer."
182 :type '(repeat string)
183 :group 'gnus-article-signature)
185 (defcustom gnus-signature-limit nil
186 "Provide a limit to what is considered a signature.
187 If it is a number, no signature may not be longer (in characters) than
188 that number. If it is a floating point number, no signature may be
189 longer (in lines) than that number. If it is a function, the function
190 will be called without any parameters, and if it returns nil, there is
191 no signature in the buffer. If it is a string, it will be used as a
192 regexp. If it matches, the text in question is not a signature."
193 :type '(choice (integer :value 200)
195 (function :value fun)
196 (regexp :value ".*"))
197 :group 'gnus-article-signature)
199 (defcustom gnus-hidden-properties '(invisible t intangible t)
200 "Property list to use for hiding text."
202 :group 'gnus-article-hiding)
204 ;; Fixme: This isn't the right thing for mixed graphical and and
205 ;; non-graphical frames in a session.
206 ;; gnus-xmas.el overrides this for XEmacs.
207 (defcustom gnus-article-x-face-command
208 (if (and (fboundp 'image-type-available-p)
209 (image-type-available-p 'xbm))
210 'gnus-article-display-xface
211 (if gnus-article-compface-xbm
212 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
213 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
215 "*String or function to be executed to display an X-Face header.
216 If it is a string, the command will be executed in a sub-shell
217 asynchronously. The compressed face will be piped to this command."
218 :type '(choice string
219 (function-item gnus-article-display-xface)
221 :group 'gnus-article-washing)
223 (defcustom gnus-article-x-face-too-ugly nil
224 "Regexp matching posters whose face shouldn't be shown automatically."
225 :type '(choice regexp (const nil))
226 :group 'gnus-article-washing)
228 (defcustom gnus-article-banner-alist nil
229 "Banner alist for stripping.
231 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
233 :type '(repeat (cons symbol regexp))
234 :group 'gnus-article-washing)
236 (gnus-define-group-parameter
239 "Alist of regexps (to match group names) and banner."
240 :variable-group gnus-article-washing
242 '(choice :tag "Banner"
244 (const :tag "Remove signature" signature)
245 (symbol :tag "Item in `gnus-article-banner-alist'" none)
247 (const :tag "None" nil))
249 "If non-nil, specify how to remove `banners' from articles.
251 Symbol `signature' means to remove signatures delimited by
252 `gnus-signature-separator'. Any other symbol is used to look up a
253 regular expression to match the banner in `gnus-article-banner-alist'.
254 A string is used as a regular expression to match the banner
257 (defcustom gnus-emphasis-alist
259 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
261 '(("_" "_" underline)
264 ("_/" "/_" underline-italic)
265 ("_\\*" "\\*_" underline-bold)
266 ("\\*/" "/\\*" bold-italic)
267 ("_\\*/" "/\\*_" underline-bold-italic))))
268 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
269 2 3 gnus-emphasis-underline)
273 (format format (car spec) (cadr spec))
274 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
276 "*Alist that says how to fontify certain phrases.
277 Each item looks like this:
279 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
281 The first element is a regular expression to be matched. The second
282 is a number that says what regular expression grouping used to find
283 the entire emphasized word. The third is a number that says what
284 regexp grouping should be displayed and highlighted. The fourth
285 is the face used for highlighting."
286 :type '(repeat (list :value ("" 0 0 default)
288 (integer :tag "Match group")
289 (integer :tag "Emphasize group")
291 :group 'gnus-article-emphasis)
293 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
294 "A regexp to describe whitespace which should not be emphasized.
295 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
296 The former avoids underlining of leading and trailing whitespace,
297 and the latter avoids underlining any whitespace at all."
299 :group 'gnus-article-emphasis
302 (defface gnus-emphasis-bold '((t (:bold t)))
303 "Face used for displaying strong emphasized text (*word*)."
304 :group 'gnus-article-emphasis)
306 (defface gnus-emphasis-italic '((t (:italic t)))
307 "Face used for displaying italic emphasized text (/word/)."
308 :group 'gnus-article-emphasis)
310 (defface gnus-emphasis-underline '((t (:underline t)))
311 "Face used for displaying underlined emphasized text (_word_)."
312 :group 'gnus-article-emphasis)
314 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
315 "Face used for displaying underlined bold emphasized text (_*word*_)."
316 :group 'gnus-article-emphasis)
318 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
319 "Face used for displaying underlined italic emphasized text (_/word/_)."
320 :group 'gnus-article-emphasis)
322 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
323 "Face used for displaying bold italic emphasized text (/*word*/)."
324 :group 'gnus-article-emphasis)
326 (defface gnus-emphasis-underline-bold-italic
327 '((t (:bold t :italic t :underline t)))
328 "Face used for displaying underlined bold italic emphasized text.
329 Esample: (_/*word*/_)."
330 :group 'gnus-article-emphasis)
332 (defface gnus-emphasis-highlight-words
333 '((t (:background "black" :foreground "yellow")))
334 "Face used for displaying highlighted words."
335 :group 'gnus-article-emphasis)
337 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
338 "Format for display of Date headers in article bodies.
339 See `format-time-string' for the possible values.
341 The variable can also be function, which should return a complete Date
342 header. The function is called with one argument, the time, which can
343 be fed to `format-time-string'."
344 :type '(choice string symbol)
345 :link '(custom-manual "(gnus)Article Date")
346 :group 'gnus-article-washing)
349 (autoload 'mail-extract-address-components "mail-extr"))
351 (defcustom gnus-save-all-headers t
352 "*If non-nil, don't remove any headers before saving."
353 :group 'gnus-article-saving
356 (defcustom gnus-prompt-before-saving 'always
357 "*This variable says how much prompting is to be done when saving articles.
358 If it is nil, no prompting will be done, and the articles will be
359 saved to the default files. If this variable is `always', each and
360 every article that is saved will be preceded by a prompt, even when
361 saving large batches of articles. If this variable is neither nil not
362 `always', there the user will be prompted once for a file name for
363 each invocation of the saving commands."
364 :group 'gnus-article-saving
365 :type '(choice (item always)
366 (item :tag "never" nil)
367 (sexp :tag "once" :format "%t\n" :value t)))
369 (defcustom gnus-saved-headers gnus-visible-headers
370 "Headers to keep if `gnus-save-all-headers' is nil.
371 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
372 If that variable is nil, however, all headers that match this regexp
373 will be kept while the rest will be deleted before saving."
374 :group 'gnus-article-saving
377 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
378 "A function to save articles in your favourite format.
379 The function must be interactively callable (in other words, it must
380 be an Emacs command).
382 Gnus provides the following functions:
384 * gnus-summary-save-in-rmail (Rmail format)
385 * gnus-summary-save-in-mail (Unix mail format)
386 * gnus-summary-save-in-folder (MH folder)
387 * gnus-summary-save-in-file (article format)
388 * gnus-summary-save-in-vm (use VM's folder format)
389 * gnus-summary-write-to-file (article format -- overwrite)."
390 :group 'gnus-article-saving
391 :type '(radio (function-item gnus-summary-save-in-rmail)
392 (function-item gnus-summary-save-in-mail)
393 (function-item gnus-summary-save-in-folder)
394 (function-item gnus-summary-save-in-file)
395 (function-item gnus-summary-save-in-vm)
396 (function-item gnus-summary-write-to-file)))
398 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
399 "A function generating a file name to save articles in Rmail format.
400 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
401 :group 'gnus-article-saving
404 (defcustom gnus-mail-save-name 'gnus-plain-save-name
405 "A function generating a file name to save articles in Unix mail format.
406 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
407 :group 'gnus-article-saving
410 (defcustom gnus-folder-save-name 'gnus-folder-save-name
411 "A function generating a file name to save articles in MH folder.
412 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
413 :group 'gnus-article-saving
416 (defcustom gnus-file-save-name 'gnus-numeric-save-name
417 "A function generating a file name to save articles in article format.
418 The function is called with NEWSGROUP, HEADERS, and optional
420 :group 'gnus-article-saving
423 (defcustom gnus-split-methods
424 '((gnus-article-archive-name)
425 (gnus-article-nndoc-name))
426 "*Variable used to suggest where articles are to be saved.
427 For instance, if you would like to save articles related to Gnus in
428 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
429 you could set this variable to something like:
431 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
432 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
434 This variable is an alist where the where the key is the match and the
435 value is a list of possible files to save in if the match is non-nil.
437 If the match is a string, it is used as a regexp match on the
438 article. If the match is a symbol, that symbol will be funcalled
439 from the buffer of the article to be saved with the newsgroup as the
440 parameter. If it is a list, it will be evaled in the same buffer.
442 If this form or function returns a string, this string will be used as
443 a possible file name; and if it returns a non-nil list, that list will
444 be used as possible file names."
445 :group 'gnus-article-saving
446 :type '(repeat (choice (list :value (fun) function)
447 (cons :value ("" "") regexp (repeat string))
450 (defcustom gnus-page-delimiter "^\^L"
451 "*Regexp describing what to use as article page delimiters.
452 The default value is \"^\^L\", which is a form linefeed at the
453 beginning of a line."
455 :group 'gnus-article-various)
457 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
458 "*The format specification for the article mode line.
459 See `gnus-summary-mode-line-format' for a closer description.
461 The following additional specs are available:
463 %w The article washing status.
464 %m The number of MIME parts in the article."
466 :group 'gnus-article-various)
468 (defcustom gnus-article-mode-hook nil
469 "*A hook for Gnus article mode."
471 :group 'gnus-article-various)
473 (when (featurep 'xemacs)
474 ;; Extracted from gnus-xmas-define in order to preserve user settings
475 (when (fboundp 'turn-off-scroll-in-place)
476 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
477 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
478 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
480 (defcustom gnus-article-menu-hook nil
481 "*Hook run after the creation of the article mode menu."
483 :group 'gnus-article-various)
485 (defcustom gnus-article-prepare-hook nil
486 "*A hook called after an article has been prepared in the article buffer."
488 :group 'gnus-article-various)
490 (defcustom gnus-article-hide-pgp-hook nil
491 "*A hook called after successfully hiding a PGP signature."
493 :group 'gnus-article-various)
495 (defcustom gnus-article-button-face 'bold
496 "Face used for highlighting buttons in the article buffer.
498 An article button is a piece of text that you can activate by pressing
499 `RET' or `mouse-2' above it."
501 :group 'gnus-article-buttons)
503 (defcustom gnus-article-mouse-face 'highlight
504 "Face used for mouse highlighting in the article buffer.
506 Article buttons will be displayed in this face when the cursor is
509 :group 'gnus-article-buttons)
511 (defcustom gnus-signature-face 'gnus-signature-face
512 "Face used for highlighting a signature in the article buffer.
513 Obsolete; use the face `gnus-signature-face' for customizations instead."
515 :group 'gnus-article-highlight
516 :group 'gnus-article-signature)
518 (defface gnus-signature-face
521 "Face used for highlighting a signature in the article buffer."
522 :group 'gnus-article-highlight
523 :group 'gnus-article-signature)
525 (defface gnus-header-from-face
528 (:foreground "spring green"))
531 (:foreground "red3"))
534 "Face used for displaying from headers."
535 :group 'gnus-article-headers
536 :group 'gnus-article-highlight)
538 (defface gnus-header-subject-face
541 (:foreground "SeaGreen3"))
544 (:foreground "red4"))
546 (:bold t :italic t)))
547 "Face used for displaying subject headers."
548 :group 'gnus-article-headers
549 :group 'gnus-article-highlight)
551 (defface gnus-header-newsgroups-face
554 (:foreground "yellow" :italic t))
557 (:foreground "MidnightBlue" :italic t))
560 "Face used for displaying newsgroups headers."
561 :group 'gnus-article-headers
562 :group 'gnus-article-highlight)
564 (defface gnus-header-name-face
567 (:foreground "SeaGreen"))
570 (:foreground "maroon"))
573 "Face used for displaying header names."
574 :group 'gnus-article-headers
575 :group 'gnus-article-highlight)
577 (defface gnus-header-content-face
580 (:foreground "forest green" :italic t))
583 (:foreground "indianred4" :italic t))
585 (:italic t))) "Face used for displaying header content."
586 :group 'gnus-article-headers
587 :group 'gnus-article-highlight)
589 (defcustom gnus-header-face-alist
590 '(("From" nil gnus-header-from-face)
591 ("Subject" nil gnus-header-subject-face)
592 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
593 ("" gnus-header-name-face gnus-header-content-face))
594 "*Controls highlighting of article header.
596 An alist of the form (HEADER NAME CONTENT).
598 HEADER is a regular expression which should match the name of an
599 header header and NAME and CONTENT are either face names or nil.
601 The name of each header field will be displayed using the face
602 specified by the first element in the list where HEADER match the
603 header name and NAME is non-nil. Similarly, the content will be
604 displayed by the first non-nil matching CONTENT face."
605 :group 'gnus-article-headers
606 :group 'gnus-article-highlight
607 :type '(repeat (list (regexp :tag "Header")
609 (item :tag "skip" nil)
610 (face :value default))
611 (choice :tag "Content"
612 (item :tag "skip" nil)
613 (face :value default)))))
615 (defcustom gnus-article-decode-hook
616 '(article-decode-charset article-decode-encoded-words)
617 "*Hook run to decode charsets in articles."
618 :group 'gnus-article-headers
621 (defcustom gnus-display-mime-function 'gnus-display-mime
622 "Function to display MIME articles."
623 :group 'gnus-article-mime
626 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
627 "Function used to decode headers.")
629 (defvar gnus-article-dumbquotes-map
648 "Table for MS-to-Latin1 translation.")
650 (defcustom gnus-ignored-mime-types nil
651 "List of MIME types that should be ignored by Gnus."
653 :group 'gnus-article-mime
654 :type '(repeat regexp))
656 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
657 "List of MIME types that should not be given buttons when rendered inline."
659 :group 'gnus-article-mime
660 :type '(repeat regexp))
662 (defcustom gnus-article-mime-part-function nil
663 "Function called with a MIME handle as the argument.
664 This is meant for people who want to do something automatic based
665 on parts -- for instance, adding Vcard info to a database."
666 :group 'gnus-article-mime
669 (defcustom gnus-mime-multipart-functions nil
670 "An alist of MIME types to functions to display them."
672 :group 'gnus-article-mime
675 (defcustom gnus-article-date-lapsed-new-header nil
676 "Whether the X-Sent and Date headers can coexist.
677 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
678 either replace the old \"Date:\" header (if this variable is nil), or
679 be added below it (otherwise)."
681 :group 'gnus-article-headers
684 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
685 "Function called with a MIME handle as the argument.
686 This is meant for people who want to view first matched part.
687 For `undisplayed-alternative' (default), the first undisplayed
688 part or alternative part is used. For `undisplayed', the first
689 undisplayed part is used. For a function, the first part which
690 the function return `t' is used. For `nil', the first part is
693 :group 'gnus-article-mime
695 (item :tag "first" :value nil)
696 (item :tag "undisplayed" :value undisplayed)
697 (item :tag "undisplayed or alternative"
698 :value undisplayed-alternative)
701 (defcustom gnus-mime-action-alist
702 '(("save to file" . gnus-mime-save-part)
703 ("save and strip" . gnus-mime-save-part-and-strip)
704 ("display as text" . gnus-mime-inline-part)
705 ("view the part" . gnus-mime-view-part)
706 ("pipe to command" . gnus-mime-pipe-part)
707 ("toggle display" . gnus-article-press-button)
708 ("toggle display" . gnus-article-view-part-as-charset)
709 ("view as type" . gnus-mime-view-part-as-type)
710 ("internalize type" . gnus-mime-internalize-part)
711 ("externalize type" . gnus-mime-externalize-part))
712 "An alist of actions that run on the MIME attachment."
713 :group 'gnus-article-mime
714 :type '(repeat (cons (string :tag "name")
717 (defcustom gnus-mime-action-alist
718 '(("save to file" . gnus-mime-save-part)
719 ("display as text" . gnus-mime-inline-part)
720 ("view the part" . gnus-mime-view-part)
721 ("pipe to command" . gnus-mime-pipe-part)
722 ("toggle display" . gnus-article-press-button)
723 ("view as type" . gnus-mime-view-part-as-type)
724 ("internalize type" . gnus-mime-internalize-part)
725 ("externalize type" . gnus-mime-externalize-part))
726 "An alist of actions that run on the MIME attachment."
728 :group 'gnus-article-mime
729 :type '(repeat (cons (string :tag "name")
733 ;;; The treatment variables
736 (defvar gnus-part-display-hook nil
737 "Hook called on parts that are to receive treatment.")
739 (defvar gnus-article-treat-custom
740 '(choice (const :tag "Off" nil)
742 (const :tag "Header" head)
743 (const :tag "Last" last)
744 (integer :tag "Less")
745 (repeat :tag "Groups" regexp)
746 (sexp :tag "Predicate")))
748 (defvar gnus-article-treat-head-custom
749 '(choice (const :tag "Off" nil)
750 (const :tag "Header" head)))
752 (defvar gnus-article-treat-types '("text/plain")
755 (defvar gnus-inhibit-treatment nil
756 "Whether to inhibit treatment.")
758 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
759 "Highlight the signature.
760 Valid values are nil, t, `head', `last', an integer or a predicate.
761 See the manual for details."
762 :group 'gnus-article-treat
763 :type gnus-article-treat-custom)
764 (put 'gnus-treat-highlight-signature 'highlight t)
766 (defcustom gnus-treat-buttonize 100000
768 Valid values are nil, t, `head', `last', an integer or a predicate.
769 See the manual for details."
770 :group 'gnus-article-treat
771 :type gnus-article-treat-custom)
772 (put 'gnus-treat-buttonize 'highlight t)
774 (defcustom gnus-treat-buttonize-head 'head
775 "Add buttons to the head.
776 Valid values are nil, t, `head', `last', an integer or a predicate.
777 See the manual for details."
778 :group 'gnus-article-treat
779 :type gnus-article-treat-head-custom)
780 (put 'gnus-treat-buttonize-head 'highlight t)
782 (defcustom gnus-treat-emphasize
783 (and (or window-system
785 (>= (string-to-number emacs-version) 21))
788 Valid values are nil, t, `head', `last', an integer or a predicate.
789 See the manual for details."
790 :group 'gnus-article-treat
791 :type gnus-article-treat-custom)
792 (put 'gnus-treat-emphasize 'highlight t)
794 (defcustom gnus-treat-strip-cr nil
795 "Remove carriage returns.
796 Valid values are nil, t, `head', `last', an integer or a predicate.
797 See the manual for details."
798 :group 'gnus-article-treat
799 :type gnus-article-treat-custom)
801 (defcustom gnus-treat-hide-headers 'head
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-head-custom)
808 (defcustom gnus-treat-hide-boring-headers nil
809 "Hide boring headers.
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-head-custom)
815 (defcustom gnus-treat-hide-signature nil
817 Valid values are nil, t, `head', `last', an integer or a predicate.
818 See the manual for details."
819 :group 'gnus-article-treat
820 :type gnus-article-treat-custom)
822 (defcustom gnus-treat-fill-article nil
824 Valid values are nil, t, `head', `last', an integer or a predicate.
825 See the manual for details."
826 :group 'gnus-article-treat
827 :type gnus-article-treat-custom)
829 (defcustom gnus-treat-hide-citation nil
831 Valid values are nil, t, `head', `last', an integer or a predicate.
832 See the manual for details."
833 :group 'gnus-article-treat
834 :type gnus-article-treat-custom)
836 (defcustom gnus-treat-hide-citation-maybe nil
838 Valid values are nil, t, `head', `last', an integer or a predicate.
839 See the manual for details."
840 :group 'gnus-article-treat
841 :type gnus-article-treat-custom)
843 (defcustom gnus-treat-hide-citation-maybe nil
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
847 :group 'gnus-article-treat
848 :type gnus-article-treat-custom)
850 (defcustom gnus-treat-strip-list-identifiers 'head
851 "Strip list identifiers from `gnus-list-identifiers`.
852 Valid values are nil, t, `head', `last', an integer or a predicate.
853 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-custom)
858 (defcustom gnus-treat-strip-pgp t
859 "Strip PGP signatures.
860 Valid values are nil, t, `head', `last', an integer or a predicate.
861 See the manual for details."
862 :group 'gnus-article-treat
863 :type gnus-article-treat-custom)
865 (defcustom gnus-treat-strip-pem nil
866 "Strip PEM signatures.
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
872 (defcustom gnus-treat-strip-banner t
873 "Strip banners from articles.
874 The banner to be stripped is specified in the `banner' group parameter.
875 Valid values are nil, t, `head', `last', an integer or a predicate.
876 See the manual for details."
877 :group 'gnus-article-treat
878 :type gnus-article-treat-custom)
880 (defcustom gnus-treat-highlight-headers 'head
881 "Highlight the headers.
882 Valid values are nil, t, `head', `last', an integer or a predicate.
883 See the manual for details."
884 :group 'gnus-article-treat
885 :type gnus-article-treat-head-custom)
886 (put 'gnus-treat-highlight-headers 'highlight t)
888 (defcustom gnus-treat-highlight-citation t
889 "Highlight cited text.
890 Valid values are nil, t, `head', `last', an integer or a predicate.
891 See the manual for details."
892 :group 'gnus-article-treat
893 :type gnus-article-treat-custom)
894 (put 'gnus-treat-highlight-citation 'highlight t)
896 (defcustom gnus-treat-date-ut nil
897 "Display the Date in UT (GMT).
898 Valid values are nil, t, `head', `last', an integer or a predicate.
899 See the manual for details."
900 :group 'gnus-article-treat
901 :type gnus-article-treat-head-custom)
903 (defcustom gnus-treat-date-local nil
904 "Display the Date in the local timezone.
905 Valid values are nil, t, `head', `last', an integer or a predicate.
906 See the manual for details."
907 :group 'gnus-article-treat
908 :type gnus-article-treat-head-custom)
910 (defcustom gnus-treat-date-english nil
911 "Display the Date in a format that can be read aloud in English.
912 Valid values are nil, t, `head', `last', an integer or a predicate.
913 See the manual for details."
914 :group 'gnus-article-treat
915 :type gnus-article-treat-head-custom)
917 (defcustom gnus-treat-date-lapsed nil
918 "Display the Date header in a way that says how much time has elapsed.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-head-custom)
924 (defcustom gnus-treat-date-original nil
925 "Display the date in the original timezone.
926 Valid values are nil, t, `head', `last', an integer or a predicate.
927 See the manual for details."
928 :group 'gnus-article-treat
929 :type gnus-article-treat-head-custom)
931 (defcustom gnus-treat-date-iso8601 nil
932 "Display the date in the ISO8601 format.
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
936 :group 'gnus-article-treat
937 :type gnus-article-treat-head-custom)
939 (defcustom gnus-treat-date-user-defined nil
940 "Display the date in a user-defined format.
941 The format is defined by the `gnus-article-time-format' variable.
942 Valid values are nil, t, `head', `last', an integer or a predicate.
943 See the manual for details."
944 :group 'gnus-article-treat
945 :type gnus-article-treat-head-custom)
947 (defcustom gnus-treat-strip-headers-in-body t
948 "Strip the X-No-Archive header line from the beginning of the body.
949 Valid values are nil, t, `head', `last', an integer or a predicate.
950 See the manual for details."
952 :group 'gnus-article-treat
953 :type gnus-article-treat-custom)
955 (defcustom gnus-treat-strip-trailing-blank-lines nil
956 "Strip trailing blank lines.
957 Valid values are nil, t, `head', `last', an integer or a predicate.
958 See the manual for details."
959 :group 'gnus-article-treat
960 :type gnus-article-treat-custom)
962 (defcustom gnus-treat-strip-leading-blank-lines nil
963 "Strip leading blank lines.
964 Valid values are nil, t, `head', `last', an integer or a predicate.
965 See the manual for details."
966 :group 'gnus-article-treat
967 :type gnus-article-treat-custom)
969 (defcustom gnus-treat-strip-multiple-blank-lines nil
970 "Strip multiple blank lines.
971 Valid values are nil, t, `head', `last', an integer or a predicate.
972 See the manual for details."
973 :group 'gnus-article-treat
974 :type gnus-article-treat-custom)
976 (defcustom gnus-treat-overstrike t
977 "Treat overstrike highlighting.
978 Valid values are nil, t, `head', `last', an integer or a predicate.
979 See the manual for details."
980 :group 'gnus-article-treat
981 :type gnus-article-treat-custom)
982 (put 'gnus-treat-overstrike 'highlight t)
984 (defcustom gnus-treat-display-xface
985 (and (or (and (fboundp 'image-type-available-p)
986 (image-type-available-p 'xbm)
987 (string-match "^0x" (shell-command-to-string "uncompface")))
988 (and (featurep 'xemacs) (featurep 'xface)))
990 "Display X-Face headers.
991 Valid values are nil, t, `head', `last', an integer or a predicate.
992 See the manual for details."
993 :group 'gnus-article-treat
994 :type gnus-article-treat-head-custom)
995 (put 'gnus-treat-display-xface 'highlight t)
997 (defcustom gnus-treat-display-smileys
998 (if (or (and (featurep 'xemacs)
1000 (and (fboundp 'image-type-available-p)
1001 (image-type-available-p 'pbm)))
1004 Valid values are nil, t, `head', `last', an integer or a predicate.
1005 See the manual for details."
1006 :group 'gnus-article-treat
1007 :type gnus-article-treat-custom)
1008 (put 'gnus-treat-display-smileys 'highlight t)
1010 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1012 Valid values are nil, t, `head', `last', an integer or a predicate.
1013 See the manual for details."
1014 :group 'gnus-article-treat
1015 :type gnus-article-treat-head-custom)
1016 (put 'gnus-treat-display-picons 'highlight t)
1018 (defcustom gnus-treat-capitalize-sentences nil
1019 "Capitalize sentence-starting words.
1020 Valid values are nil, t, `head', `last', an integer or a predicate.
1021 See the manual for details."
1023 :group 'gnus-article-treat
1024 :type gnus-article-treat-custom)
1026 (defcustom gnus-treat-fill-long-lines nil
1028 Valid values are nil, t, `head', `last', an integer or a predicate.
1029 See the manual for details."
1030 :group 'gnus-article-treat
1031 :type gnus-article-treat-custom)
1033 (defcustom gnus-treat-play-sounds nil
1035 Valid values are nil, t, `head', `last', an integer or a predicate.
1036 See the manual for details."
1038 :group 'gnus-article-treat
1039 :type gnus-article-treat-custom)
1041 (defcustom gnus-treat-translate nil
1042 "Translate articles from one language to another.
1043 Valid values are nil, t, `head', `last', an integer or a predicate.
1044 See the manual for details."
1046 :group 'gnus-article-treat
1047 :type gnus-article-treat-custom)
1049 (defcustom gnus-treat-x-pgp-sig nil
1051 To automatically treat X-PGP-Sig, set it to head.
1052 Valid values are nil, t, `head', `last', an integer or a predicate.
1053 See the manual for details."
1054 :group 'gnus-article-treat
1055 :group 'mime-security
1056 :type gnus-article-treat-custom)
1058 (defvar gnus-article-encrypt-protocol-alist
1059 '(("PGP" . mml2015-self-encrypt)))
1061 ;; Set to nil if more than one protocol added to
1062 ;; gnus-article-encrypt-protocol-alist.
1063 (defcustom gnus-article-encrypt-protocol "PGP"
1064 "The protocol used for encrypt articles.
1065 It is a string, such as \"PGP\". If nil, ask user."
1067 :group 'mime-security)
1069 ;;; Internal variables
1071 (defvar gnus-english-month-names
1072 '("January" "February" "March" "April" "May" "June" "July" "August"
1073 "September" "October" "November" "December"))
1075 (defvar article-goto-body-goes-to-point-min-p nil)
1076 (defvar gnus-article-wash-types nil)
1077 (defvar gnus-article-emphasis-alist nil)
1079 (defvar gnus-article-mime-handle-alist-1 nil)
1080 (defvar gnus-treatment-function-alist
1081 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1082 (gnus-treat-strip-banner gnus-article-strip-banner)
1083 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1084 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1085 (gnus-treat-buttonize gnus-article-add-buttons)
1086 (gnus-treat-fill-article gnus-article-fill-cited-article)
1087 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1088 (gnus-treat-strip-cr gnus-article-remove-cr)
1089 (gnus-treat-emphasize gnus-article-emphasize)
1090 (gnus-treat-display-xface gnus-article-display-x-face)
1091 (gnus-treat-date-ut gnus-article-date-ut)
1092 (gnus-treat-date-local gnus-article-date-local)
1093 (gnus-treat-date-english gnus-article-date-english)
1094 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1095 (gnus-treat-date-original gnus-article-date-original)
1096 (gnus-treat-date-user-defined gnus-article-date-user)
1097 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1098 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1099 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1100 (gnus-treat-hide-signature gnus-article-hide-signature)
1101 (gnus-treat-hide-citation gnus-article-hide-citation)
1102 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1103 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1104 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1105 (gnus-treat-strip-pem gnus-article-hide-pem)
1106 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1107 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1108 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1109 (gnus-treat-strip-trailing-blank-lines
1110 gnus-article-remove-trailing-blank-lines)
1111 (gnus-treat-strip-leading-blank-lines
1112 gnus-article-strip-leading-blank-lines)
1113 (gnus-treat-strip-multiple-blank-lines
1114 gnus-article-strip-multiple-blank-lines)
1115 (gnus-treat-overstrike gnus-article-treat-overstrike)
1116 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1117 (gnus-treat-display-smileys gnus-smiley-display)
1118 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1119 (gnus-treat-display-picons gnus-article-display-picons)
1120 (gnus-treat-play-sounds gnus-earcon-display)))
1122 (defvar gnus-article-mime-handle-alist nil)
1123 (defvar article-lapsed-timer nil)
1124 (defvar gnus-article-current-summary nil)
1126 (defvar gnus-article-mode-syntax-table
1127 (let ((table (copy-syntax-table text-mode-syntax-table)))
1128 ;; This causes the citation match run O(2^n).
1129 ;; (modify-syntax-entry ?- "w" table)
1130 (modify-syntax-entry ?> ")" table)
1131 (modify-syntax-entry ?< "(" table)
1133 "Syntax table used in article mode buffers.
1134 Initialized from `text-mode-syntax-table.")
1136 (defvar gnus-save-article-buffer nil)
1138 (defvar gnus-article-mode-line-format-alist
1139 (nconc '((?w (gnus-article-wash-status) ?s)
1140 (?m (gnus-article-mime-part-status) ?s))
1141 gnus-summary-mode-line-format-alist))
1143 (defvar gnus-number-of-articles-to-be-saved nil)
1145 (defvar gnus-inhibit-hiding nil)
1147 (defsubst gnus-article-hide-text (b e props)
1148 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1149 (gnus-add-text-properties-when 'article-type nil b e props)
1150 (when (memq 'intangible props)
1152 (max (1- b) (point-min))
1153 b 'intangible (cddr (memq 'intangible props)))))
1155 (defsubst gnus-article-unhide-text (b e)
1156 "Remove hidden text properties from region between B and E."
1157 (remove-text-properties b e gnus-hidden-properties)
1158 (when (memq 'intangible gnus-hidden-properties)
1159 (put-text-property (max (1- b) (point-min))
1160 b 'intangible nil)))
1162 (defun gnus-article-hide-text-type (b e type)
1163 "Hide text of TYPE between B and E."
1164 (push type gnus-article-wash-types)
1165 (gnus-article-hide-text
1166 b e (cons 'article-type (cons type gnus-hidden-properties))))
1168 (defun gnus-article-unhide-text-type (b e type)
1169 "Unhide text of TYPE between B and E."
1170 (setq gnus-article-wash-types
1171 (delq type gnus-article-wash-types))
1172 (remove-text-properties
1173 b e (cons 'article-type (cons type gnus-hidden-properties)))
1174 (when (memq 'intangible gnus-hidden-properties)
1175 (put-text-property (max (1- b) (point-min))
1176 b 'intangible nil)))
1178 (defun gnus-article-hide-text-of-type (type)
1179 "Hide text of TYPE in the current buffer."
1181 (let ((b (point-min))
1183 (while (setq b (text-property-any b e 'article-type type))
1184 (add-text-properties b (incf b) gnus-hidden-properties)))))
1186 (defun gnus-article-delete-text-of-type (type)
1187 "Delete text of TYPE in the current buffer."
1189 (let ((b (point-min)))
1190 (while (setq b (text-property-any b (point-max) 'article-type type))
1192 b (or (text-property-not-all b (point-max) 'article-type type)
1195 (defun gnus-article-delete-invisible-text ()
1196 "Delete all invisible text in the current buffer."
1198 (let ((b (point-min)))
1199 (while (setq b (text-property-any b (point-max) 'invisible t))
1201 b (or (text-property-not-all b (point-max) 'invisible t)
1204 (defun gnus-article-text-type-exists-p (type)
1205 "Say whether any text of type TYPE exists in the buffer."
1206 (text-property-any (point-min) (point-max) 'article-type type))
1208 (defsubst gnus-article-header-rank ()
1209 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1210 (let ((list gnus-sorted-header-list)
1213 (when (looking-at (car list))
1215 (setq list (cdr list))
1219 (defun article-hide-headers (&optional arg delete)
1220 "Hide unwanted headers and possibly sort them as well."
1222 ;; This function might be inhibited.
1223 (unless gnus-inhibit-hiding
1226 (let ((buffer-read-only nil)
1227 (case-fold-search t)
1228 (max (1+ (length gnus-sorted-header-list)))
1229 (ignored (when (not gnus-visible-headers)
1230 (cond ((stringp gnus-ignored-headers)
1231 gnus-ignored-headers)
1232 ((listp gnus-ignored-headers)
1233 (mapconcat 'identity gnus-ignored-headers
1236 (cond ((stringp gnus-visible-headers)
1237 gnus-visible-headers)
1238 ((and gnus-visible-headers
1239 (listp gnus-visible-headers))
1240 (mapconcat 'identity gnus-visible-headers "\\|"))))
1241 (inhibit-point-motion-hooks t)
1243 ;; First we narrow to just the headers.
1244 (article-narrow-to-head)
1245 ;; Hide any "From " lines at the beginning of (mail) articles.
1246 (while (looking-at "From ")
1249 (delete-region (point-min) (point)))
1250 ;; Then treat the rest of the header lines.
1251 ;; Then we use the two regular expressions
1252 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1253 ;; select which header lines is to remain visible in the
1255 (while (re-search-forward "^[^ \t]*:" nil t)
1257 ;; Mark the rank of the header.
1259 (point) (1+ (point)) 'message-rank
1260 (if (or (and visible (looking-at visible))
1262 (not (looking-at ignored))))
1263 (gnus-article-header-rank)
1266 (message-sort-headers-1)
1267 (when (setq beg (text-property-any
1268 (point-min) (point-max) 'message-rank (+ 2 max)))
1269 ;; We delete the unwanted headers.
1270 (push 'headers gnus-article-wash-types)
1271 (add-text-properties (point-min) (+ 5 (point-min))
1272 '(article-type headers dummy-invisible t))
1273 (delete-region beg (point-max))))))))
1275 (defun article-hide-boring-headers (&optional arg)
1276 "Toggle hiding of headers that aren't very interesting.
1277 If given a negative prefix, always show; if given a positive prefix,
1279 (interactive (gnus-article-hidden-arg))
1280 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1281 (not gnus-show-all-headers))
1284 (let ((buffer-read-only nil)
1285 (list gnus-boring-article-headers)
1286 (inhibit-point-motion-hooks t)
1288 (article-narrow-to-head)
1290 (setq elem (pop list))
1291 (goto-char (point-min))
1293 ;; Hide empty headers.
1295 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1297 (gnus-article-hide-text-type
1298 (progn (beginning-of-line) (point))
1301 (if (re-search-forward "^[^ \t]" nil t)
1305 ;; Hide boring Newsgroups header.
1306 ((eq elem 'newsgroups)
1307 (when (equal (gnus-fetch-field "newsgroups")
1308 (gnus-group-real-name
1309 (if (boundp 'gnus-newsgroup-name)
1312 (gnus-article-hide-header "newsgroups")))
1313 ((eq elem 'followup-to)
1314 (when (equal (message-fetch-field "followup-to")
1315 (message-fetch-field "newsgroups"))
1316 (gnus-article-hide-header "followup-to")))
1317 ((eq elem 'reply-to)
1318 (let ((from (message-fetch-field "from"))
1319 (reply-to (message-fetch-field "reply-to")))
1324 (nth 1 (mail-extract-address-components from))
1325 (nth 1 (mail-extract-address-components reply-to)))))
1326 (gnus-article-hide-header "reply-to"))))
1328 (let ((date (message-fetch-field "date")))
1330 (< (days-between (current-time-string) date)
1332 (gnus-article-hide-header "date"))))
1334 (let ((to (message-fetch-field "to"))
1335 (cc (message-fetch-field "cc")))
1336 (when (> (length to) 1024)
1337 (gnus-article-hide-header "to"))
1338 (when (> (length cc) 1024)
1339 (gnus-article-hide-header "cc"))))
1343 (goto-char (point-min))
1344 (while (re-search-forward "^to:" nil t)
1345 (setq to-count (1+ to-count)))
1346 (when (> to-count 1)
1347 (while (> to-count 0)
1348 (goto-char (point-min))
1350 (re-search-forward "^to:" nil nil to-count)
1352 (narrow-to-region (point) (point-max))
1353 (gnus-article-hide-header "to"))
1354 (setq to-count (1- to-count))))
1355 (goto-char (point-min))
1356 (while (re-search-forward "^cc:" nil t)
1357 (setq cc-count (1+ cc-count)))
1358 (when (> cc-count 1)
1359 (while (> cc-count 0)
1360 (goto-char (point-min))
1362 (re-search-forward "^cc:" nil nil cc-count)
1364 (narrow-to-region (point) (point-max))
1365 (gnus-article-hide-header "cc"))
1366 (setq cc-count (1- cc-count)))))))))))))
1368 (defun gnus-article-hide-header (header)
1370 (goto-char (point-min))
1371 (when (re-search-forward (concat "^" header ":") nil t)
1372 (gnus-article-hide-text-type
1373 (progn (beginning-of-line) (point))
1376 (if (re-search-forward "^[^ \t]" nil t)
1381 (defvar gnus-article-normalized-header-length 40
1382 "Length of normalized headers.")
1384 (defun article-normalize-headers ()
1385 "Make all header lines 40 characters long."
1387 (let ((buffer-read-only nil)
1391 (article-narrow-to-head)
1394 ((< (setq column (- (gnus-point-at-eol) (point)))
1395 gnus-article-normalized-header-length)
1397 (insert (make-string
1398 (- gnus-article-normalized-header-length column)
1400 ((> column gnus-article-normalized-header-length)
1401 (gnus-put-text-property
1403 (forward-char gnus-article-normalized-header-length)
1410 (forward-line 1))))))
1412 (defun article-treat-dumbquotes ()
1413 "Translate M****s*** sm*rtq**t*s into proper text.
1414 Note that this function guesses whether a character is a sm*rtq**t* or
1415 not, so it should only be used interactively.
1417 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1418 in an attempt to provide more quoting characters. If you see
1419 something like \\222 or \\264 where you're expecting some kind of
1420 apostrophe or quotation mark, then try this wash."
1422 (article-translate-strings gnus-article-dumbquotes-map))
1424 (defun article-translate-characters (from to)
1425 "Translate all characters in the body of the article according to FROM and TO.
1426 FROM is a string of characters to translate from; to is a string of
1427 characters to translate to."
1429 (when (article-goto-body)
1430 (let ((buffer-read-only nil)
1431 (x (make-string 225 ?x))
1433 (while (< (incf i) (length x))
1436 (while (< i (length from))
1437 (aset x (aref from i) (aref to i))
1439 (translate-region (point) (point-max) x)))))
1441 (defun article-translate-strings (map)
1442 "Translate all string in the body of the article according to MAP.
1443 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1445 (when (article-goto-body)
1446 (let ((buffer-read-only nil)
1448 (while (setq elem (pop map))
1450 (while (search-forward (car elem) nil t)
1451 (replace-match (cadr elem)))))))))
1453 (defun article-treat-overstrike ()
1454 "Translate overstrikes into bold text."
1457 (when (article-goto-body)
1458 (let ((buffer-read-only nil))
1459 (while (search-forward "\b" nil t)
1460 (let ((next (char-after))
1461 (previous (char-after (- (point) 2))))
1462 ;; We do the boldification/underlining by hiding the
1463 ;; overstrikes and putting the proper text property
1467 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1468 (put-text-property (point) (1+ (point)) 'face 'bold))
1470 (gnus-article-hide-text-type
1471 (1- (point)) (1+ (point)) 'overstrike)
1473 (- (point) 2) (1- (point)) 'face 'underline))
1475 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1477 (point) (1+ (point)) 'face 'underline)))))))))
1479 (defun article-fill-long-lines ()
1480 "Fill lines that are wider than the window width."
1483 (let ((buffer-read-only nil)
1484 (width (window-width (get-buffer-window (current-buffer)))))
1487 (let ((adaptive-fill-mode nil))
1490 (when (>= (current-column) (min fill-column width))
1491 (narrow-to-region (point) (gnus-point-at-bol))
1492 (fill-paragraph nil)
1493 (goto-char (point-max))
1495 (forward-line 1)))))))
1497 (defun article-capitalize-sentences ()
1498 "Capitalize the first word in each sentence."
1501 (let ((buffer-read-only nil)
1502 (paragraph-start "^[\n\^L]"))
1506 (forward-sentence)))))
1508 (defun article-remove-cr ()
1509 "Remove trailing CRs and then translate remaining CRs into LFs."
1512 (let ((buffer-read-only nil))
1513 (goto-char (point-min))
1514 (while (re-search-forward "\r+$" nil t)
1515 (replace-match "" t t))
1516 (goto-char (point-min))
1517 (while (search-forward "\r" nil t)
1518 (replace-match "\n" t t)))))
1520 (defun article-remove-trailing-blank-lines ()
1521 "Remove all trailing blank lines from the article."
1524 (let ((buffer-read-only nil))
1525 (goto-char (point-max))
1529 (while (and (not (bobp))
1530 (looking-at "^[ \t]*$")
1531 (not (gnus-annotation-in-region-p
1532 (point) (gnus-point-at-eol))))
1537 (defun article-display-x-face (&optional force)
1538 "Look for an X-Face header and display it if present."
1539 (interactive (list 'force))
1541 ;; Delete the old process, if any.
1542 (when (process-status "article-x-face")
1543 (delete-process "article-x-face"))
1544 (let ((inhibit-point-motion-hooks t)
1545 (case-fold-search t)
1548 (article-narrow-to-head)
1549 (goto-char (point-min))
1550 (setq from (message-fetch-field "from"))
1551 (goto-char (point-min))
1552 (while (and gnus-article-x-face-command
1555 ;; Check whether this face is censored.
1556 (not gnus-article-x-face-too-ugly)
1557 (and gnus-article-x-face-too-ugly from
1558 (not (string-match gnus-article-x-face-too-ugly
1560 ;; Has to be present.
1561 (re-search-forward "^X-Face: " nil t))
1562 ;; This used to try to do multiple faces (`while' instead of
1563 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1564 ;; work (b) it can crash some versions of Emacs (c) are
1565 ;; multiple faces really something to encourage?
1566 (when (stringp gnus-article-x-face-command)
1568 ;; We now have the area of the buffer where the X-Face is stored.
1571 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1572 ;; We display the face.
1573 (if (symbolp gnus-article-x-face-command)
1574 ;; The command is a lisp function, so we call it.
1575 (if (gnus-functionp gnus-article-x-face-command)
1576 (funcall gnus-article-x-face-command beg end)
1577 (error "%s is not a function" gnus-article-x-face-command))
1578 ;; The command is a string, so we interpret the command
1579 ;; as a, well, command, and fork it off.
1580 (let ((process-connection-type nil))
1581 (process-kill-without-query
1583 "article-x-face" nil shell-file-name shell-command-switch
1584 gnus-article-x-face-command))
1585 (process-send-region "article-x-face" beg end)
1586 (process-send-eof "article-x-face"))))))))))
1588 (defun article-decode-mime-words ()
1589 "Decode all MIME-encoded words in the article."
1592 (set-buffer gnus-article-buffer)
1593 (let ((inhibit-point-motion-hooks t)
1595 (mail-parse-charset gnus-newsgroup-charset)
1596 (mail-parse-ignored-charsets
1597 (save-excursion (set-buffer gnus-summary-buffer)
1598 gnus-newsgroup-ignored-charsets)))
1599 (mail-decode-encoded-word-region (point-min) (point-max)))))
1601 (defun article-decode-charset (&optional prompt)
1602 "Decode charset-encoded text in the article.
1603 If PROMPT (the prefix), prompt for a coding system to use."
1605 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1607 (mail-parse-charset gnus-newsgroup-charset)
1608 (mail-parse-ignored-charsets
1609 (save-excursion (condition-case nil
1610 (set-buffer gnus-summary-buffer)
1612 gnus-newsgroup-ignored-charsets))
1613 ct cte ctl charset format)
1616 (article-narrow-to-head)
1617 (setq ct (message-fetch-field "Content-Type" t)
1618 cte (message-fetch-field "Content-Transfer-Encoding" t)
1619 ctl (and ct (ignore-errors
1620 (mail-header-parse-content-type ct)))
1623 (mm-read-coding-system "Charset to decode: "))
1625 (mail-content-type-get ctl 'charset)))
1626 format (and ctl (mail-content-type-get ctl 'format)))
1628 (setq cte (mail-header-strip cte)))
1629 (if (and ctl (not (string-match "/" (car ctl))))
1631 (goto-char (point-max)))
1634 (narrow-to-region (point) (point-max))
1635 (when (and (eq mail-parse-charset 'gnus-decoded)
1636 (eq (mm-body-7-or-8) '8bit))
1637 ;; The text code could have been decoded.
1638 (setq charset mail-parse-charset))
1639 (when (and (or (not ctl)
1640 (equal (car ctl) "text/plain"))
1641 (not format)) ;; article with format will decode later.
1643 charset (and cte (intern (downcase
1644 (gnus-strip-whitespace cte))))
1647 (defun article-decode-encoded-words ()
1648 "Remove encoded-word encoding from headers."
1649 (let ((inhibit-point-motion-hooks t)
1650 (mail-parse-charset gnus-newsgroup-charset)
1651 (mail-parse-ignored-charsets
1652 (save-excursion (condition-case nil
1653 (set-buffer gnus-summary-buffer)
1655 gnus-newsgroup-ignored-charsets))
1658 (article-narrow-to-head)
1659 (funcall gnus-decode-header-function (point-min) (point-max)))))
1661 (defun article-de-quoted-unreadable (&optional force)
1662 "Translate a quoted-printable-encoded article.
1663 If FORCE, decode the article whether it is marked as quoted-printable
1665 (interactive (list 'force))
1667 (let ((buffer-read-only nil) type charset)
1668 (if (gnus-buffer-live-p gnus-original-article-buffer)
1669 (with-current-buffer gnus-original-article-buffer
1671 (gnus-fetch-field "content-transfer-encoding"))
1672 (let* ((ct (gnus-fetch-field "content-type"))
1675 (mail-header-parse-content-type ct)))))
1676 (setq charset (and ctl
1677 (mail-content-type-get ctl 'charset)))
1678 (if (stringp charset)
1679 (setq charset (intern (downcase charset)))))))
1681 (setq charset gnus-newsgroup-charset))
1683 (and type (let ((case-fold-search t))
1684 (string-match "quoted-printable" type))))
1686 (quoted-printable-decode-region
1687 (point) (point-max) (mm-charset-to-coding-system charset))))))
1689 (defun article-de-base64-unreadable (&optional force)
1690 "Translate a base64 article.
1691 If FORCE, decode the article whether it is marked as base64 not."
1692 (interactive (list 'force))
1694 (let ((buffer-read-only nil) type charset)
1695 (if (gnus-buffer-live-p gnus-original-article-buffer)
1696 (with-current-buffer gnus-original-article-buffer
1698 (gnus-fetch-field "content-transfer-encoding"))
1699 (let* ((ct (gnus-fetch-field "content-type"))
1702 (mail-header-parse-content-type ct)))))
1703 (setq charset (and ctl
1704 (mail-content-type-get ctl 'charset)))
1705 (if (stringp charset)
1706 (setq charset (intern (downcase charset)))))))
1708 (setq charset gnus-newsgroup-charset))
1710 (and type (let ((case-fold-search t))
1711 (string-match "base64" type))))
1714 (narrow-to-region (point) (point-max))
1715 (base64-decode-region (point-min) (point-max))
1716 (mm-decode-coding-region
1717 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1722 (defun article-decode-HZ ()
1723 "Translate a HZ-encoded article."
1727 (let ((buffer-read-only nil))
1728 (rfc1843-decode-region (point-min) (point-max)))))
1730 (defun article-wash-html ()
1731 "Format an html article."
1734 (let ((buffer-read-only nil)
1736 (if (gnus-buffer-live-p gnus-original-article-buffer)
1737 (with-current-buffer gnus-original-article-buffer
1738 (let* ((ct (gnus-fetch-field "content-type"))
1741 (mail-header-parse-content-type ct)))))
1742 (setq charset (and ctl
1743 (mail-content-type-get ctl 'charset)))
1744 (if (stringp charset)
1745 (setq charset (intern (downcase charset)))))))
1747 (setq charset gnus-newsgroup-charset))
1749 (save-window-excursion
1751 (narrow-to-region (point) (point-max))
1753 (let ((w3-strict-width (window-width))
1754 (url-standalone-mode t))
1756 (w3-region (point-min) (point-max))
1759 (defun article-hide-list-identifiers ()
1760 "Remove list identifies from the Subject header.
1761 The `gnus-list-identifiers' variable specifies what to do."
1765 (let ((inhibit-point-motion-hooks t)
1767 (article-narrow-to-head)
1768 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1769 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1771 (goto-char (point-min))
1772 (when (re-search-forward
1773 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1774 " *\\)\\)+\\(Re: +\\)?\\)")
1776 (let ((s (or (match-string 3) (match-string 5))))
1777 (delete-region (match-beginning 1) (match-end 1))
1779 (goto-char (match-beginning 1))
1782 (defun article-hide-pgp ()
1783 "Remove any PGP headers and signatures in the current article."
1787 (let ((inhibit-point-motion-hooks t)
1788 buffer-read-only beg end)
1790 ;; Hide the "header".
1791 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1792 (push 'pgp gnus-article-wash-types)
1793 (delete-region (match-beginning 0) (match-end 0))
1794 ;; Remove armor headers (rfc2440 6.2)
1795 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1798 ;; Hide the actual signature.
1799 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1800 (setq end (1+ (match-beginning 0)))
1803 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1805 ;; Perhaps we shouldn't hide to the end of the buffer
1806 ;; if there is no end to the signature?
1808 ;; Hide "- " PGP quotation markers.
1810 (narrow-to-region beg end)
1811 (goto-char (point-min))
1812 (while (re-search-forward "^- " nil t)
1814 (match-beginning 0) (match-end 0)))
1816 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1818 (defun article-hide-pem (&optional arg)
1819 "Toggle hiding of any PEM headers and signatures in the current article.
1820 If given a negative prefix, always show; if given a positive prefix,
1822 (interactive (gnus-article-hidden-arg))
1823 (unless (gnus-article-check-hidden-text 'pem arg)
1825 (let (buffer-read-only end)
1826 (goto-char (point-min))
1827 ;; Hide the horrendously ugly "header".
1828 (when (and (search-forward
1829 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1831 (setq end (1+ (match-beginning 0))))
1832 (push 'pem gnus-article-wash-types)
1833 (gnus-article-hide-text-type
1835 (if (search-forward "\n\n" nil t)
1839 ;; Hide the trailer as well
1840 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1842 (gnus-article-hide-text-type
1843 (match-beginning 0) (match-end 0) 'pem)))))))
1845 (defun article-strip-banner ()
1846 "Strip the banner specified by the `banner' group parameter."
1850 (let ((inhibit-point-motion-hooks t)
1851 (banner (gnus-parameter-banner gnus-newsgroup-name))
1852 (gnus-signature-limit nil)
1853 buffer-read-only beg end)
1857 ((eq banner 'signature)
1858 (when (gnus-article-narrow-to-signature)
1861 (delete-region (point) (point-max))))
1863 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1864 (while (re-search-forward banner nil t)
1865 (delete-region (match-beginning 0) (match-end 0)))))
1867 (while (re-search-forward banner nil t)
1868 (delete-region (match-beginning 0) (match-end 0))))))))))
1870 (defun article-babel ()
1871 "Translate article using an online translation service."
1875 (set-buffer gnus-article-buffer)
1876 (when (article-goto-body)
1877 (let* ((buffer-read-only nil)
1880 (orig (buffer-substring start end))
1881 (trans (babel-as-string orig)))
1883 (narrow-to-region start end)
1884 (delete-region start end)
1887 (defun article-hide-signature (&optional arg)
1888 "Hide the signature in the current article.
1889 If given a negative prefix, always show; if given a positive prefix,
1891 (interactive (gnus-article-hidden-arg))
1892 (unless (gnus-article-check-hidden-text 'signature arg)
1895 (let ((buffer-read-only nil))
1896 (when (gnus-article-narrow-to-signature)
1897 (gnus-article-hide-text-type
1898 (point-min) (point-max) 'signature)))))))
1900 (defun article-strip-headers-in-body ()
1901 "Strip offensive headers from bodies."
1905 (let ((case-fold-search t))
1906 (when (looking-at "x-no-archive:")
1907 (gnus-delete-line)))))
1909 (defun article-strip-leading-blank-lines ()
1910 "Remove all blank lines from the beginning of the article."
1913 (let ((inhibit-point-motion-hooks t)
1915 (when (article-goto-body)
1916 (while (and (not (eobp))
1917 (looking-at "[ \t]*$"))
1918 (gnus-delete-line))))))
1920 (defun article-narrow-to-head ()
1921 "Narrow the buffer to the head of the message.
1922 Point is left at the beginning of the narrowed-to region."
1924 (goto-char (point-min))
1925 (if (search-forward "\n\n" nil 1)
1928 (goto-char (point-min)))
1930 (defun article-goto-body ()
1931 "Place point at the start of the body."
1932 (goto-char (point-min))
1934 ;; This variable is only bound when dealing with separate
1936 (article-goto-body-goes-to-point-min-p
1938 ((search-forward "\n\n" nil t)
1941 (goto-char (point-max))
1944 (defun article-strip-multiple-blank-lines ()
1945 "Replace consecutive blank lines with one empty line."
1948 (let ((inhibit-point-motion-hooks t)
1950 ;; First make all blank lines empty.
1952 (while (re-search-forward "^[ \t]+$" nil t)
1953 (unless (gnus-annotation-in-region-p
1954 (match-beginning 0) (match-end 0))
1955 (replace-match "" nil t)))
1956 ;; Then replace multiple empty lines with a single empty line.
1958 (while (re-search-forward "\n\n\n+" nil t)
1959 (unless (gnus-annotation-in-region-p
1960 (match-beginning 0) (match-end 0))
1961 (replace-match "\n\n" t t))))))
1963 (defun article-strip-leading-space ()
1964 "Remove all white space from the beginning of the lines in the article."
1967 (let ((inhibit-point-motion-hooks t)
1970 (while (re-search-forward "^[ \t]+" nil t)
1971 (replace-match "" t t)))))
1973 (defun article-strip-trailing-space ()
1974 "Remove all white space from the end of the lines in the article."
1977 (let ((inhibit-point-motion-hooks t)
1980 (while (re-search-forward "[ \t]+$" nil t)
1981 (replace-match "" t t)))))
1983 (defun article-strip-blank-lines ()
1984 "Strip leading, trailing and multiple blank lines."
1986 (article-strip-leading-blank-lines)
1987 (article-remove-trailing-blank-lines)
1988 (article-strip-multiple-blank-lines))
1990 (defun article-strip-all-blank-lines ()
1991 "Strip all blank lines."
1994 (let ((inhibit-point-motion-hooks t)
1997 (while (re-search-forward "^[ \t]*\n" nil t)
1998 (replace-match "" t t)))))
2000 (defun gnus-article-narrow-to-signature ()
2001 "Narrow to the signature; return t if a signature is found, else nil."
2002 (let ((inhibit-point-motion-hooks t))
2003 (when (gnus-article-search-signature)
2005 ;; Check whether we have some limits to what we consider
2006 ;; to be a signature.
2007 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2008 (list gnus-signature-limit)))
2010 (while (setq limit (pop limits))
2011 (if (or (and (integerp limit)
2012 (< (- (point-max) (point)) limit))
2014 (< (count-lines (point) (point-max)) limit))
2015 (and (gnus-functionp limit)
2017 (and (stringp limit)
2018 (not (re-search-forward limit nil t))))
2019 () ; This limit did not succeed.
2023 (narrow-to-region (point) (point-max))
2026 (defun gnus-article-search-signature ()
2027 "Search the current buffer for the signature separator.
2028 Put point at the beginning of the signature separator."
2029 (let ((cur (point)))
2030 (goto-char (point-max))
2031 (if (if (stringp gnus-signature-separator)
2032 (re-search-backward gnus-signature-separator nil t)
2033 (let ((seps gnus-signature-separator))
2035 (not (re-search-backward (car seps) nil t)))
2042 (defun gnus-article-hidden-arg ()
2043 "Return the current prefix arg as a number, or 0 if no prefix."
2044 (list (if current-prefix-arg
2045 (prefix-numeric-value current-prefix-arg)
2048 (defun gnus-article-check-hidden-text (type arg)
2049 "Return nil if hiding is necessary.
2050 Arg can be nil or a number. Nil and positive means hide, negative
2051 means show, 0 means toggle."
2054 (let ((hide (gnus-article-hidden-text-p type)))
2060 (gnus-article-show-hidden-text type)
2063 (if (eq hide 'hidden)
2065 (gnus-article-show-hidden-text type)
2069 (defun gnus-article-hidden-text-p (type)
2070 "Say whether the current buffer contains hidden text of type TYPE."
2071 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2073 (not (get-text-property pos 'invisible))
2074 (not (get-text-property pos 'dummy-invisible)))
2076 (text-property-any (1+ pos) (point-max) 'article-type type)))
2081 (defun gnus-article-show-hidden-text (type &optional dummy)
2082 "Show all hidden text of type TYPE.
2083 Originally it is hide instead of DUMMY."
2084 (let ((buffer-read-only nil)
2085 (inhibit-point-motion-hooks t))
2086 (gnus-remove-text-properties-when
2088 (point-min) (point-max)
2089 (cons 'article-type (cons type
2090 gnus-hidden-properties)))))
2092 (defconst article-time-units
2093 `((year . ,(* 365.25 24 60 60))
2094 (week . ,(* 7 24 60 60))
2095 (day . ,(* 24 60 60))
2099 "Mapping from time units to seconds.")
2101 (defun article-date-ut (&optional type highlight header)
2102 "Convert DATE date to universal time in the current article.
2103 If TYPE is `local', convert to local time; if it is `lapsed', output
2104 how much time has lapsed since DATE. For `lapsed', the value of
2105 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2106 should replace the \"Date:\" one, or should be added below it."
2107 (interactive (list 'ut t))
2108 (let* ((header (or header
2109 (message-fetch-field "date")
2111 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2114 ((not gnus-article-date-lapsed-new-header)
2120 (date (if (vectorp header) (mail-header-date header)
2122 (inhibit-point-motion-hooks t)
2127 (article-narrow-to-head)
2128 (when (re-search-forward tdate-regexp nil t)
2129 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2130 date (or (get-text-property (gnus-point-at-bol)
2133 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2135 (when (and date (not (string= date "")))
2136 (goto-char (point-min))
2137 (let ((buffer-read-only nil))
2138 ;; Delete any old Date headers.
2139 (while (re-search-forward date-regexp nil t)
2141 (delete-region (progn (beginning-of-line) (point))
2142 (progn (forward-line 1) (point)))
2143 (delete-region (progn (beginning-of-line) (point))
2144 (progn (end-of-line) (point)))
2145 (setq pos (point))))
2146 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2148 (if pos (goto-char pos))
2149 (insert (article-make-date-line date (or type 'ut)))
2155 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2156 (put-text-property (match-beginning 1) (1+ (match-end 1))
2157 'original-date date)
2158 (put-text-property (match-beginning 1) (1+ (match-end 1))
2160 (put-text-property (match-beginning 2) (match-end 2)
2163 (defun article-make-date-line (date type)
2164 "Return a DATE line of TYPE."
2165 (let ((time (condition-case ()
2169 ;; Convert to the local timezone. We have to slap a
2170 ;; `condition-case' round the calls to the timezone
2171 ;; functions since they aren't particularly resistant to
2174 (let ((tz (car (current-time-zone time))))
2175 (format "Date: %s %s%02d%02d" (current-time-string time)
2176 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2177 (/ (% (abs tz) 3600) 60))))
2178 ;; Convert to Universal Time.
2181 (current-time-string
2182 (let* ((e (parse-time-string date))
2183 (tm (apply 'encode-time e))
2185 (ls (- (cadr tm) (car (current-time-zone time)))))
2186 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2187 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2190 ;; Get the original date from the article.
2191 ((eq type 'original)
2192 (concat "Date: " (if (string-match "\n+$" date)
2193 (substring date 0 (match-beginning 0))
2195 ;; Let the user define the format.
2197 (if (gnus-functionp gnus-article-time-format)
2198 (funcall gnus-article-time-format time)
2201 (format-time-string gnus-article-time-format time))))
2204 (let ((tz (car (current-time-zone time))))
2207 (format-time-string "%Y%m%dT%H%M%S" time)
2208 (format "%s%02d%02d"
2209 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2210 (/ (% (abs tz) 3600) 60)))))
2211 ;; Do an X-Sent lapsed format.
2213 ;; If the date is seriously mangled, the timezone functions are
2214 ;; liable to bug out, so we ignore all errors.
2215 (let* ((now (current-time))
2216 (real-time (subtract-time now time))
2217 (real-sec (and real-time
2218 (+ (* (float (car real-time)) 65536)
2220 (sec (and real-time (abs real-sec)))
2230 ;; This is a bit convoluted, but basically we go
2231 ;; through the time units for years, weeks, etc,
2232 ;; and divide things to see whether that results
2233 ;; in positive answers.
2236 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2237 ;; The (remaining) seconds are too few to
2238 ;; be divided into this time unit.
2240 ;; It's big enough, so we output it.
2241 (setq sec (- sec (* num (cdr unit))))
2243 (concat (if prev ", " "") (int-to-string
2245 " " (symbol-name (car unit))
2246 (if (> num 1) "s" ""))
2248 article-time-units "")
2249 ;; If dates are odd, then it might appear like the
2250 ;; article was sent in the future.
2253 " in the future"))))))
2254 ;; Display the date in proper English
2256 (let ((dtime (decode-time time)))
2259 (number-to-string (nth 3 dtime))
2260 (let ((digit (% (nth 3 dtime) 10)))
2262 ((memq (nth 3 dtime) '(11 12)) "th")
2268 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2270 (number-to-string (nth 5 dtime))
2272 (format "%02d" (nth 2 dtime))
2274 (format "%02d" (nth 1 dtime)))))
2276 (error "Unknown conversion type: %s" type)))))
2278 (defun article-date-local (&optional highlight)
2279 "Convert the current article date to the local timezone."
2280 (interactive (list t))
2281 (article-date-ut 'local highlight))
2283 (defun article-date-english (&optional highlight)
2284 "Convert the current article date to something that is proper English."
2285 (interactive (list t))
2286 (article-date-ut 'english highlight))
2288 (defun article-date-original (&optional highlight)
2289 "Convert the current article date to what it was originally.
2290 This is only useful if you have used some other date conversion
2291 function and want to see what the date was before converting."
2292 (interactive (list t))
2293 (article-date-ut 'original highlight))
2295 (defun article-date-lapsed (&optional highlight)
2296 "Convert the current article date to time lapsed since it was sent."
2297 (interactive (list t))
2298 (article-date-ut 'lapsed highlight))
2300 (defun article-update-date-lapsed ()
2301 "Function to be run from a timer to update the lapsed time line."
2302 (let (deactivate-mark)
2307 (set-buffer (window-buffer w))
2308 (when (eq major-mode 'gnus-article-mode)
2309 (goto-char (point-min))
2310 (when (re-search-forward "^X-Sent:" nil t)
2311 (article-date-lapsed t))))
2314 (defun gnus-start-date-timer (&optional n)
2315 "Start a timer to update the X-Sent header in the article buffers.
2316 The numerical prefix says how frequently (in seconds) the function
2321 (gnus-stop-date-timer)
2322 (setq article-lapsed-timer
2323 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2325 (defun gnus-stop-date-timer ()
2326 "Stop the X-Sent timer."
2328 (when article-lapsed-timer
2329 (nnheader-cancel-timer article-lapsed-timer)
2330 (setq article-lapsed-timer nil)))
2332 (defun article-date-user (&optional highlight)
2333 "Convert the current article date to the user-defined format.
2334 This format is defined by the `gnus-article-time-format' variable."
2335 (interactive (list t))
2336 (article-date-ut 'user highlight))
2338 (defun article-date-iso8601 (&optional highlight)
2339 "Convert the current article date to ISO8601."
2340 (interactive (list t))
2341 (article-date-ut 'iso8601 highlight))
2343 (defun article-show-all ()
2344 "Show all hidden text in the article buffer."
2347 (let ((buffer-read-only nil))
2348 (gnus-article-unhide-text (point-min) (point-max)))))
2350 (defun article-emphasize (&optional arg)
2351 "Emphasize text according to `gnus-emphasis-alist'."
2352 (interactive (gnus-article-hidden-arg))
2353 (unless (gnus-article-check-hidden-text 'emphasis arg)
2357 (with-current-buffer gnus-summary-buffer
2358 gnus-article-emphasis-alist)
2360 gnus-emphasis-alist))
2361 (buffer-read-only nil)
2362 (props (append '(article-type emphasis)
2363 gnus-hidden-properties))
2364 regexp elem beg invisible visible face)
2367 (while (setq elem (pop alist))
2369 (setq regexp (car elem)
2370 invisible (nth 1 elem)
2371 visible (nth 2 elem)
2373 (while (re-search-forward regexp nil t)
2374 (when (and (match-beginning visible) (match-beginning invisible))
2375 (push 'emphasis gnus-article-wash-types)
2376 (gnus-article-hide-text
2377 (match-beginning invisible) (match-end invisible) props)
2378 (gnus-article-unhide-text-type
2379 (match-beginning visible) (match-end visible) 'emphasis)
2380 (gnus-put-text-property-excluding-newlines
2381 (match-beginning visible) (match-end visible) 'face face)
2382 (goto-char (match-end invisible)))))))))
2384 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2385 "Setup newsgroup emphasis alist."
2386 (unless gnus-article-emphasis-alist
2387 (let ((name (and gnus-newsgroup-name
2388 (gnus-group-real-name gnus-newsgroup-name))))
2389 (make-local-variable 'gnus-article-emphasis-alist)
2390 (setq gnus-article-emphasis-alist
2392 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2393 (while (setq elem (pop alist))
2394 (when (and name (string-match (car elem) name))
2396 highlight (copy-sequence (cdr elem)))))
2398 (copy-sequence highlight-words)
2399 (if gnus-newsgroup-name
2400 (copy-sequence (gnus-group-find-parameter
2401 gnus-newsgroup-name 'highlight-words t)))
2402 gnus-emphasis-alist)))))
2404 (defvar gnus-summary-article-menu)
2405 (defvar gnus-summary-post-menu)
2407 ;;; Saving functions.
2409 (defun gnus-article-save (save-buffer file &optional num)
2410 "Save the currently selected article."
2411 (unless gnus-save-all-headers
2412 ;; Remove headers according to `gnus-saved-headers'.
2413 (let ((gnus-visible-headers
2414 (or gnus-saved-headers gnus-visible-headers))
2415 (gnus-article-buffer save-buffer))
2417 (set-buffer save-buffer)
2418 (article-hide-headers 1 t))))
2419 (save-window-excursion
2420 (if (not gnus-default-article-saver)
2421 (error "No default saver is defined")
2422 ;; !!! Magic! The saving functions all save
2423 ;; `gnus-save-article-buffer' (or so they think), but we
2424 ;; bind that variable to our save-buffer.
2425 (set-buffer gnus-article-buffer)
2426 (let* ((gnus-save-article-buffer save-buffer)
2429 ((not gnus-prompt-before-saving) 'default)
2430 ((eq gnus-prompt-before-saving 'always) nil)
2432 (gnus-number-of-articles-to-be-saved
2433 (when (eq gnus-prompt-before-saving t)
2435 (set-buffer gnus-article-current-summary)
2436 (funcall gnus-default-article-saver filename)))))
2438 (defun gnus-read-save-file-name (prompt &optional filename
2439 function group headers variable)
2441 (funcall function group headers (symbol-value variable)))
2446 ((eq filename 'default)
2452 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2455 (if (and gnus-number-of-articles-to-be-saved
2456 (> gnus-number-of-articles-to-be-saved 1))
2457 (format "these %d articles"
2458 gnus-number-of-articles-to-be-saved)
2461 ;; Let the split methods have their say.
2463 ;; No split name was found.
2466 (concat prompt " (default "
2467 (file-name-nondirectory default-name) ") ")
2468 (file-name-directory default-name)
2470 ;; A single group name is returned.
2471 ((stringp split-name)
2473 (funcall function split-name headers
2474 (symbol-value variable)))
2476 (concat prompt " (default "
2477 (file-name-nondirectory default-name) ") ")
2478 (file-name-directory default-name)
2480 ;; A single split name was found
2481 ((= 1 (length split-name))
2482 (let* ((name (expand-file-name
2484 gnus-article-save-directory))
2485 (dir (cond ((file-directory-p name)
2486 (file-name-as-directory name))
2487 ((file-exists-p name) name)
2488 (t gnus-article-save-directory))))
2490 (concat prompt " (default " name ") ")
2492 ;; A list of splits was found.
2494 (setq split-name (nreverse split-name))
2496 (let ((file-name-history
2497 (nconc split-name file-name-history)))
2501 (concat prompt " (`M-p' for defaults) ")
2502 gnus-article-save-directory
2504 gnus-article-save-directory)))
2505 (car (push result file-name-history)))))))
2506 ;; Create the directory.
2507 (gnus-make-directory (file-name-directory file))
2508 ;; If we have read a directory, we append the default file name.
2509 (when (file-directory-p file)
2510 (setq file (expand-file-name (file-name-nondirectory
2512 (file-name-as-directory file))))
2513 ;; Possibly translate some characters.
2514 (nnheader-translate-file-chars file))))))
2515 (gnus-make-directory (file-name-directory result))
2516 (set variable result)))
2518 (defun gnus-article-archive-name (group)
2519 "Return the first instance of an \"Archive-name\" in the current buffer."
2520 (let ((case-fold-search t))
2521 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2522 (nnheader-concat gnus-article-save-directory
2523 (match-string 1)))))
2525 (defun gnus-article-nndoc-name (group)
2526 "If GROUP is an nndoc group, return the name of the parent group."
2527 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2528 (gnus-group-get-parameter group 'save-article-group)))
2530 (defun gnus-summary-save-in-rmail (&optional filename)
2531 "Append this article to Rmail file.
2532 Optional argument FILENAME specifies file name.
2533 Directory to save to is default to `gnus-article-save-directory'."
2534 (setq filename (gnus-read-save-file-name
2535 "Save %s in rmail file:" filename
2536 gnus-rmail-save-name gnus-newsgroup-name
2537 gnus-current-headers 'gnus-newsgroup-last-rmail))
2538 (gnus-eval-in-buffer-window gnus-save-article-buffer
2542 (gnus-output-to-rmail filename))))
2545 (defun gnus-summary-save-in-mail (&optional filename)
2546 "Append this article to Unix mail file.
2547 Optional argument FILENAME specifies file name.
2548 Directory to save to is default to `gnus-article-save-directory'."
2549 (setq filename (gnus-read-save-file-name
2550 "Save %s in Unix mail file:" filename
2551 gnus-mail-save-name gnus-newsgroup-name
2552 gnus-current-headers 'gnus-newsgroup-last-mail))
2553 (gnus-eval-in-buffer-window gnus-save-article-buffer
2557 (if (and (file-readable-p filename)
2558 (mail-file-babyl-p filename))
2559 (rmail-output-to-rmail-file filename t)
2560 (gnus-output-to-mail filename)))))
2563 (defun gnus-summary-save-in-file (&optional filename overwrite)
2564 "Append this article to file.
2565 Optional argument FILENAME specifies file name.
2566 Directory to save to is default to `gnus-article-save-directory'."
2567 (setq filename (gnus-read-save-file-name
2568 "Save %s in file:" filename
2569 gnus-file-save-name gnus-newsgroup-name
2570 gnus-current-headers 'gnus-newsgroup-last-file))
2571 (gnus-eval-in-buffer-window gnus-save-article-buffer
2575 (when (and overwrite
2576 (file-exists-p filename))
2577 (delete-file filename))
2578 (gnus-output-to-file filename))))
2581 (defun gnus-summary-write-to-file (&optional filename)
2582 "Write this article to a file.
2583 Optional argument FILENAME specifies file name.
2584 The directory to save in defaults to `gnus-article-save-directory'."
2585 (gnus-summary-save-in-file nil t))
2587 (defun gnus-summary-save-body-in-file (&optional filename)
2588 "Append this article body to a file.
2589 Optional argument FILENAME specifies file name.
2590 The directory to save in defaults to `gnus-article-save-directory'."
2591 (setq filename (gnus-read-save-file-name
2592 "Save %s body in file:" filename
2593 gnus-file-save-name gnus-newsgroup-name
2594 gnus-current-headers 'gnus-newsgroup-last-file))
2595 (gnus-eval-in-buffer-window gnus-save-article-buffer
2599 (when (article-goto-body)
2600 (narrow-to-region (point) (point-max)))
2601 (gnus-output-to-file filename))))
2604 (defun gnus-summary-save-in-pipe (&optional command)
2605 "Pipe this article to subprocess."
2607 (cond ((and (eq command 'default)
2608 gnus-last-shell-command)
2609 gnus-last-shell-command)
2613 "Shell command on %s: "
2614 (if (and gnus-number-of-articles-to-be-saved
2615 (> gnus-number-of-articles-to-be-saved 1))
2616 (format "these %d articles"
2617 gnus-number-of-articles-to-be-saved)
2619 gnus-last-shell-command))))
2620 (when (string-equal command "")
2621 (setq command gnus-last-shell-command))
2622 (gnus-eval-in-buffer-window gnus-article-buffer
2625 (shell-command-on-region (point-min) (point-max) command nil)))
2626 (setq gnus-last-shell-command command))
2628 ;;; Article file names when saving.
2630 (defun gnus-capitalize-newsgroup (newsgroup)
2631 "Capitalize NEWSGROUP name."
2632 (when (not (zerop (length newsgroup)))
2633 (concat (char-to-string (upcase (aref newsgroup 0)))
2634 (substring newsgroup 1))))
2636 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2637 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2638 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2639 Otherwise, it is like ~/News/news/group/num."
2642 (concat (if (gnus-use-long-file-name 'not-save)
2643 (gnus-capitalize-newsgroup newsgroup)
2644 (gnus-newsgroup-directory-form newsgroup))
2645 "/" (int-to-string (mail-header-number headers)))
2646 gnus-article-save-directory)))
2648 (string-equal (file-name-directory default)
2649 (file-name-directory last-file))
2650 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2652 (or last-file default))))
2654 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2655 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2656 If variable `gnus-use-long-file-name' is non-nil, it is
2657 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2660 (concat (if (gnus-use-long-file-name 'not-save)
2662 (gnus-newsgroup-directory-form newsgroup))
2663 "/" (int-to-string (mail-header-number headers)))
2664 gnus-article-save-directory)))
2666 (string-equal (file-name-directory default)
2667 (file-name-directory last-file))
2668 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2670 (or last-file default))))
2672 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2673 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2674 If variable `gnus-use-long-file-name' is non-nil, it is
2675 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2678 (if (gnus-use-long-file-name 'not-save)
2680 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2681 gnus-article-save-directory)))
2683 (defun article-verify-x-pgp-sig ()
2686 (if (gnus-buffer-live-p gnus-original-article-buffer)
2687 (let ((sig (with-current-buffer gnus-original-article-buffer
2688 (gnus-fetch-field "X-PGP-Sig")))
2692 (mml2015-clear-verify-function))
2694 (insert-buffer gnus-original-article-buffer)
2695 (setq items (split-string sig))
2696 (message-narrow-to-head)
2697 (let ((inhibit-point-motion-hooks t)
2698 (case-fold-search t))
2699 ;; Don't verify multiple headers.
2700 (setq headers (mapconcat (lambda (header)
2702 (mail-fetch-field header) "\n"))
2703 (split-string (nth 1 items) ",") "")))
2704 (delete-region (point-min) (point-max))
2705 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2706 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2711 (if (looking-at "^-")
2714 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2715 (insert "Version: " (car items) "\n\n")
2716 (insert (mapconcat 'identity (cddr items) "\n"))
2717 (insert "\n-----END PGP SIGNATURE-----\n")
2718 (let ((mm-security-handle (list (format "multipart/signed"))))
2719 (mml2015-clean-buffer)
2720 (let ((coding-system-for-write (or gnus-newsgroup-charset
2722 (funcall (mml2015-clear-verify-function)))
2724 (or (mm-handle-multipart-ctl-parameter
2725 mm-security-handle 'gnus-details)
2726 (mm-handle-multipart-ctl-parameter
2727 mm-security-handle 'gnus-info)))))
2729 (let (buffer-read-only bface eface)
2731 (message-narrow-to-head)
2732 (goto-char (point-max))
2734 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2735 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2736 (message-remove-header "X-Gnus-PGP-Verify")
2737 (if (re-search-forward "^X-PGP-Sig:" nil t)
2739 (goto-char (point-max)))
2740 (narrow-to-region (point) (point))
2741 (insert "X-Gnus-PGP-Verify: " info "\n")
2742 (goto-char (point-min))
2745 (if (not (looking-at "^[ \t]"))
2749 (goto-char (point-min))
2750 (when (looking-at "\\([^:]+\\): *")
2751 (put-text-property (match-beginning 1) (1+ (match-end 1))
2753 (put-text-property (match-end 0) (point-max)
2754 'face eface)))))))))
2761 (setq afunc (car func)
2764 gfunc (intern (format "gnus-%s" func))))
2767 `(lambda (&optional interactive &rest args)
2768 ,(documentation afunc t)
2769 (interactive (list t))
2771 (set-buffer gnus-article-buffer)
2773 (call-interactively ',afunc)
2774 (apply ',afunc args))))))))
2775 '(article-hide-headers
2776 article-verify-x-pgp-sig
2777 article-hide-boring-headers
2778 article-treat-overstrike
2779 article-fill-long-lines
2780 article-capitalize-sentences
2782 article-display-x-face
2783 article-de-quoted-unreadable
2784 article-de-base64-unreadable
2787 article-hide-list-identifiers
2789 article-strip-banner
2792 article-hide-signature
2793 article-strip-headers-in-body
2794 article-remove-trailing-blank-lines
2795 article-strip-leading-blank-lines
2796 article-strip-multiple-blank-lines
2797 article-strip-leading-space
2798 article-strip-trailing-space
2799 article-strip-blank-lines
2800 article-strip-all-blank-lines
2802 article-date-english
2803 article-date-iso8601
2804 article-date-original
2806 article-decode-mime-words
2807 article-decode-charset
2808 article-decode-encoded-words
2812 article-treat-dumbquotes
2813 article-normalize-headers
2814 (article-show-all . gnus-article-show-all-headers))))
2817 ;;; Gnus article mode
2820 (put 'gnus-article-mode 'mode-class 'special)
2822 (set-keymap-parent gnus-article-mode-map widget-keymap)
2824 (gnus-define-keys gnus-article-mode-map
2825 " " gnus-article-goto-next-page
2826 "\177" gnus-article-goto-prev-page
2827 [delete] gnus-article-goto-prev-page
2828 [backspace] gnus-article-goto-prev-page
2829 "\C-c^" gnus-article-refer-article
2830 "h" gnus-article-show-summary
2831 "s" gnus-article-show-summary
2832 "\C-c\C-m" gnus-article-mail
2833 "?" gnus-article-describe-briefly
2834 "e" gnus-summary-edit-article
2835 "<" beginning-of-buffer
2837 "\C-c\C-i" gnus-info-find-node
2839 "\C-hk" gnus-article-describe-key
2840 "\C-hc" gnus-article-describe-key-briefly
2842 "\C-d" gnus-article-read-summary-keys
2843 "\M-*" gnus-article-read-summary-keys
2844 "\M-#" gnus-article-read-summary-keys
2845 "\M-^" gnus-article-read-summary-keys
2846 "\M-g" gnus-article-read-summary-keys)
2848 (substitute-key-definition
2849 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2852 (defvar gnus-article-commands-menu))
2854 (defun gnus-article-make-menu-bar ()
2855 (gnus-turn-off-edit-menu 'article)
2856 (unless (boundp 'gnus-article-article-menu)
2858 gnus-article-article-menu gnus-article-mode-map ""
2860 ["Scroll forwards" gnus-article-goto-next-page t]
2861 ["Scroll backwards" gnus-article-goto-prev-page t]
2862 ["Show summary" gnus-article-show-summary t]
2863 ["Fetch Message-ID at point" gnus-article-refer-article t]
2864 ["Mail to address at point" gnus-article-mail t]
2865 ["Send a bug report" gnus-bug t]))
2868 gnus-article-treatment-menu gnus-article-mode-map ""
2869 ;; Fixme: this should use :active (and maybe :visible).
2871 ["Hide headers" gnus-article-hide-headers t]
2872 ["Hide signature" gnus-article-hide-signature t]
2873 ["Hide citation" gnus-article-hide-citation t]
2874 ["Treat overstrike" gnus-article-treat-overstrike t]
2875 ["Remove carriage return" gnus-article-remove-cr t]
2876 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2877 ["Remove base64" gnus-article-de-base64-unreadable t]
2878 ["Treat html" gnus-article-wash-html t]
2879 ["Decode HZ" gnus-article-decode-HZ t]))
2881 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2883 (when (boundp 'gnus-summary-post-menu)
2884 (define-key gnus-article-mode-map [menu-bar post]
2885 (cons "Post" gnus-summary-post-menu)))
2887 (gnus-run-hooks 'gnus-article-menu-hook))
2889 (when (boundp 'gnus-article-commands-menu)
2890 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
2891 (when (boundp 'gnus-summary-post-menu)
2892 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
2894 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2897 (defun gnus-article-mode ()
2898 "Major mode for displaying an article.
2900 All normal editing commands are switched off.
2902 The following commands are available in addition to all summary mode
2904 \\<gnus-article-mode-map>
2905 \\[gnus-article-next-page]\t Scroll the article one page forwards
2906 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2907 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2908 \\[gnus-article-show-summary]\t Display the summary buffer
2909 \\[gnus-article-mail]\t Send a reply to the address near point
2910 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2911 \\[gnus-info-find-node]\t Go to the Gnus info node"
2913 (when (gnus-visual-p 'article-menu 'menu)
2914 (gnus-article-make-menu-bar))
2915 (gnus-simplify-mode-line)
2916 (setq mode-name "Article")
2917 (setq major-mode 'gnus-article-mode)
2918 (make-local-variable 'minor-mode-alist)
2919 (use-local-map gnus-article-mode-map)
2920 (gnus-update-format-specifications nil 'article-mode)
2921 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2922 (make-local-variable 'gnus-page-broken)
2923 (make-local-variable 'gnus-button-marker-list)
2924 (make-local-variable 'gnus-article-current-summary)
2925 (make-local-variable 'gnus-article-mime-handles)
2926 (make-local-variable 'gnus-article-decoded-p)
2927 (make-local-variable 'gnus-article-mime-handle-alist)
2928 (make-local-variable 'gnus-article-wash-types)
2929 (make-local-variable 'gnus-article-charset)
2930 (make-local-variable 'gnus-article-ignored-charsets)
2931 (gnus-set-default-directory)
2932 (buffer-disable-undo)
2933 (setq buffer-read-only t)
2934 (set-syntax-table gnus-article-mode-syntax-table)
2935 (mm-enable-multibyte)
2936 (gnus-run-hooks 'gnus-article-mode-hook))
2938 (defun gnus-article-setup-buffer ()
2939 "Initialize the article buffer."
2940 (let* ((name (if gnus-single-article-buffer "*Article*"
2941 (concat "*Article " gnus-newsgroup-name "*")))
2943 (progn (string-match "\\*Article" name)
2944 (concat " *Original Article"
2945 (substring name (match-end 0))))))
2946 (setq gnus-article-buffer name)
2947 (setq gnus-original-article-buffer original)
2948 (setq gnus-article-mime-handle-alist nil)
2949 ;; This might be a variable local to the summary buffer.
2950 (unless gnus-single-article-buffer
2952 (set-buffer gnus-summary-buffer)
2953 (setq gnus-article-buffer name)
2954 (setq gnus-original-article-buffer original)
2955 (gnus-set-global-variables)))
2956 (gnus-article-setup-highlight-words)
2957 ;; Init original article buffer.
2959 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2960 (mm-enable-multibyte)
2961 (setq major-mode 'gnus-original-article-mode)
2962 (make-local-variable 'gnus-original-article))
2963 (if (get-buffer name)
2966 (when gnus-article-mime-handles
2967 (mm-destroy-parts gnus-article-mime-handles)
2968 (setq gnus-article-mime-handles nil))
2969 ;; Set it to nil in article-buffer!
2970 (setq gnus-article-mime-handle-alist nil)
2971 (buffer-disable-undo)
2972 (setq buffer-read-only t)
2973 (unless (eq major-mode 'gnus-article-mode)
2974 (gnus-article-mode))
2977 (set-buffer (gnus-get-buffer-create name))
2979 (make-local-variable 'gnus-summary-buffer)
2980 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2981 (current-buffer)))))
2983 ;; Set article window start at LINE, where LINE is the number of lines
2984 ;; from the head of the article.
2985 (defun gnus-article-set-window-start (&optional line)
2987 (get-buffer-window gnus-article-buffer t)
2989 (set-buffer gnus-article-buffer)
2990 (goto-char (point-min))
2993 (gnus-message 6 "Moved to bookmark")
2994 (search-forward "\n\n" nil t)
2998 (defun gnus-article-prepare (article &optional all-headers header)
2999 "Prepare ARTICLE in article mode buffer.
3000 ARTICLE should either be an article number or a Message-ID.
3001 If ARTICLE is an id, HEADER should be the article headers.
3002 If ALL-HEADERS is non-nil, no headers are hidden."
3004 ;; Make sure we start in a summary buffer.
3005 (unless (eq major-mode 'gnus-summary-mode)
3006 (set-buffer gnus-summary-buffer))
3007 (setq gnus-summary-buffer (current-buffer))
3008 (let* ((gnus-article (if header (mail-header-number header) article))
3009 (summary-buffer (current-buffer))
3010 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3011 (group gnus-newsgroup-name)
3014 (gnus-article-setup-buffer)
3015 (set-buffer gnus-article-buffer)
3016 ;; Deactivate active regions.
3017 (when (and (boundp 'transient-mark-mode)
3018 transient-mark-mode)
3019 (setq mark-active nil))
3020 (if (not (setq result (let ((buffer-read-only nil))
3021 (gnus-request-article-this-buffer
3023 ;; There is no such article.
3025 (when (and (numberp article)
3026 (not (memq article gnus-newsgroup-sparse)))
3027 (setq gnus-article-current
3028 (cons gnus-newsgroup-name article))
3029 (set-buffer gnus-summary-buffer)
3030 (setq gnus-current-article article)
3031 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3033 (gnus-summary-set-agent-mark article)
3034 (message "Message marked for downloading"))
3035 (gnus-summary-mark-article article gnus-canceled-mark)
3036 (unless (memq article gnus-newsgroup-sparse)
3037 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3038 (if (or (eq result 'pseudo)
3039 (eq result 'nneething))
3042 (set-buffer summary-buffer)
3043 (push article gnus-newsgroup-history)
3044 (setq gnus-last-article gnus-current-article
3045 gnus-current-article 0
3046 gnus-current-headers nil
3047 gnus-article-current nil)
3048 (if (eq result 'nneething)
3049 (gnus-configure-windows 'summary)
3050 (gnus-configure-windows 'article))
3051 (gnus-set-global-variables))
3052 (let ((gnus-article-mime-handle-alist-1
3053 gnus-article-mime-handle-alist))
3054 (gnus-set-mode-line 'article)))
3055 ;; The result from the `request' was an actual article -
3056 ;; or at least some text that is now displayed in the
3058 (when (and (numberp article)
3059 (not (eq article gnus-current-article)))
3060 ;; Seems like a new article has been selected.
3061 ;; `gnus-current-article' must be an article number.
3063 (set-buffer summary-buffer)
3064 (push article gnus-newsgroup-history)
3065 (setq gnus-last-article gnus-current-article
3066 gnus-current-article article
3067 gnus-current-headers
3068 (gnus-summary-article-header gnus-current-article)
3069 gnus-article-current
3070 (cons gnus-newsgroup-name gnus-current-article))
3071 (unless (vectorp gnus-current-headers)
3072 (setq gnus-current-headers nil))
3073 (gnus-summary-goto-subject gnus-current-article)
3074 (when (gnus-summary-show-thread)
3075 ;; If the summary buffer really was folded, the
3076 ;; previous goto may not actually have gone to
3077 ;; the right article, but the thread root instead.
3079 (gnus-summary-goto-subject gnus-current-article))
3080 (gnus-run-hooks 'gnus-mark-article-hook)
3081 (gnus-set-mode-line 'summary)
3082 (when (gnus-visual-p 'article-highlight 'highlight)
3083 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3084 ;; Set the global newsgroup variables here.
3085 (gnus-set-global-variables)
3086 (setq gnus-have-all-headers
3087 (or all-headers gnus-show-all-headers))))
3089 (gnus-configure-windows 'article))
3090 (when (or (numberp article)
3092 (gnus-article-prepare-display)
3094 (goto-char (point-min))
3095 (setq gnus-page-broken
3096 (when gnus-break-pages
3097 (gnus-narrow-to-page)
3099 (let ((gnus-article-mime-handle-alist-1
3100 gnus-article-mime-handle-alist))
3101 (gnus-set-mode-line 'article))
3103 (set-window-point (get-buffer-window (current-buffer)) (point))
3104 (gnus-configure-windows 'article)
3108 (defun gnus-article-prepare-display ()
3109 "Make the current buffer look like a nice article."
3110 ;; Hooks for getting information from the article.
3111 ;; This hook must be called before being narrowed.
3112 (let ((gnus-article-buffer (current-buffer))
3114 (unless (eq major-mode 'gnus-article-mode)
3115 (gnus-article-mode))
3116 (setq buffer-read-only nil
3117 gnus-article-wash-types nil)
3118 (gnus-run-hooks 'gnus-tmp-internal-hook)
3119 (when gnus-display-mime-function
3120 (funcall gnus-display-mime-function))
3121 (gnus-run-hooks 'gnus-article-prepare-hook)))
3124 ;;; Gnus MIME viewing functions
3127 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3128 "The following specs can be used:
3130 %T MIME type, along with additional info
3131 %n The `name' parameter
3132 %d The description, if any
3133 %l The length of the encoded part
3134 %p The part identifier number
3135 %e Dots if the part isn't displayed")
3137 (defvar gnus-mime-button-line-format-alist
3138 '((?t gnus-tmp-type ?s)
3139 (?T gnus-tmp-type-long ?s)
3140 (?n gnus-tmp-name ?s)
3141 (?d gnus-tmp-description ?s)
3143 (?l gnus-tmp-length ?d)
3144 (?e gnus-tmp-dots ?s)))
3146 (defvar gnus-mime-button-commands
3147 '((gnus-article-press-button "\r" "Toggle Display")
3148 (gnus-mime-view-part "v" "View Interactively...")
3149 (gnus-mime-view-part-as-type "t" "View As Type...")
3150 (gnus-mime-view-part-as-charset "C" "View As charset...")
3151 (gnus-mime-save-part "o" "Save...")
3152 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3153 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3154 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3155 (gnus-mime-internalize-part "E" "View Internally")
3156 (gnus-mime-externalize-part "e" "View Externally")
3157 (gnus-mime-pipe-part "|" "Pipe To Command...")
3158 (gnus-mime-action-on-part "." "Take action on the part")))
3160 (defun gnus-article-mime-part-status ()
3161 (if gnus-article-mime-handle-alist-1
3162 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
3165 (defvar gnus-mime-button-map
3166 (let ((map (make-sparse-keymap)))
3167 (unless (>= (string-to-number emacs-version) 21)
3168 ;; XEmacs doesn't care.
3169 (set-keymap-parent map gnus-article-mode-map))
3170 (define-key map gnus-mouse-2 'gnus-article-push-button)
3171 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3172 (dolist (c gnus-mime-button-commands)
3173 (define-key map (cadr c) (car c)))
3176 (defun gnus-mime-button-menu (event)
3177 "Construct a context-sensitive menu of MIME commands."
3179 (save-window-excursion
3180 (let ((pos (event-start event)))
3181 (select-window (posn-window pos))
3182 (goto-char (posn-point pos))
3183 (gnus-article-check-buffer)
3184 (let ((response (x-popup-menu
3186 ("" ,@(mapcar (lambda (c)
3187 (cons (caddr c) (car c)))
3188 gnus-mime-button-commands))))))
3190 (call-interactively response))))))
3192 (defun gnus-mime-view-all-parts (&optional handles)
3193 "View all the MIME parts."
3195 (save-current-buffer
3196 (set-buffer gnus-article-buffer)
3197 (let ((handles (or handles gnus-article-mime-handles))
3198 (mail-parse-charset gnus-newsgroup-charset)
3199 (mail-parse-ignored-charsets
3200 (with-current-buffer gnus-summary-buffer
3201 gnus-newsgroup-ignored-charsets)))
3203 (mm-remove-parts handles)
3204 (goto-char (point-min))
3205 (or (search-forward "\n\n") (goto-char (point-max)))
3206 (let (buffer-read-only)
3207 (delete-region (point) (point-max)))
3208 (mm-display-parts handles)))))
3210 (defun gnus-mime-save-part-and-strip ()
3211 "Save the MIME part under point then replace it with an external body."
3213 (gnus-article-check-buffer)
3214 (let* ((data (get-text-property (point) 'gnus-data))
3215 (file (and data (mm-save-part data)))
3218 (with-current-buffer (mm-handle-buffer data)
3220 (insert "Content-Type: " (mm-handle-media-type data))
3221 (mml-insert-parameter-string (cdr (mm-handle-type data))
3224 (insert "Content-ID: " (message-make-message-id) "\n")
3225 (insert "Content-Transfer-Encoding: binary\n")
3228 (cdr (mm-make-handle nil
3229 `("message/external-body"
3230 (access-type . "LOCAL-FILE")
3232 (set-buffer gnus-summary-buffer)
3233 (gnus-article-edit-article
3236 (let ((mail-parse-charset (or gnus-article-charset
3237 ',gnus-newsgroup-charset))
3238 (mail-parse-ignored-charsets
3239 (or gnus-article-ignored-charsets
3240 ',gnus-newsgroup-ignored-charsets))
3241 (mbl mml-buffer-list))
3242 (setq mml-buffer-list nil)
3243 (insert-buffer gnus-original-article-buffer)
3244 (mime-to-mml gnus-article-mime-handles)
3245 (setq gnus-article-mime-handles nil)
3246 (make-local-hook 'kill-buffer-hook)
3247 (let ((mbl1 mml-buffer-list))
3248 (setq mml-buffer-list mbl)
3249 (set (make-local-variable 'mml-buffer-list) mbl1))
3250 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3251 `(lambda (no-highlight)
3252 (let ((mail-parse-charset (or gnus-article-charset
3253 ',gnus-newsgroup-charset))
3254 (message-options message-options)
3255 (message-options-set-recipient)
3256 (mail-parse-ignored-charsets
3257 (or gnus-article-ignored-charsets
3258 ',gnus-newsgroup-ignored-charsets)))
3260 (mml-destroy-buffers)
3261 (remove-hook 'kill-buffer-hook
3262 'mml-destroy-buffers t)
3263 (kill-local-variable 'mml-buffer-list))
3264 (gnus-summary-edit-article-done
3265 ,(or (mail-header-references gnus-current-headers) "")
3266 ,(gnus-group-read-only-p)
3267 ,gnus-summary-buffer no-highlight))))))
3269 (defun gnus-mime-save-part ()
3270 "Save the MIME part under point."
3272 (gnus-article-check-buffer)
3273 (let ((data (get-text-property (point) 'gnus-data)))
3275 (mm-save-part data))))
3277 (defun gnus-mime-pipe-part ()
3278 "Pipe the MIME part under point to a process."
3280 (gnus-article-check-buffer)
3281 (let ((data (get-text-property (point) 'gnus-data)))
3283 (mm-pipe-part data))))
3285 (defun gnus-mime-view-part ()
3286 "Interactively choose a viewing method for the MIME part under point."
3288 (gnus-article-check-buffer)
3289 (let ((data (get-text-property (point) 'gnus-data)))
3291 (push (setq data (copy-sequence data)) gnus-article-mime-handles)
3292 (mm-interactively-view-part data))))
3294 (defun gnus-mime-view-part-as-type-internal ()
3295 (gnus-article-check-buffer)
3296 (let* ((name (mail-content-type-get
3297 (mm-handle-type (get-text-property (point) 'gnus-data))
3299 (def-type (and name (mm-default-file-encoding name))))
3300 (and def-type (cons def-type 0))))
3302 (defun gnus-mime-view-part-as-type (&optional mime-type)
3303 "Choose a MIME media type, and view the part as such."
3306 (setq mime-type (completing-read
3307 "View as MIME type: "
3308 (mapcar #'list (mailcap-mime-types))
3310 (gnus-mime-view-part-as-type-internal))))
3311 (gnus-article-check-buffer)
3312 (let ((handle (get-text-property (point) 'gnus-data)))
3315 (mm-make-handle (mm-handle-buffer handle)
3316 (cons mime-type (cdr (mm-handle-type handle)))
3317 (mm-handle-encoding handle)
3318 (mm-handle-undisplayer handle)
3319 (mm-handle-disposition handle)
3320 (mm-handle-description handle)
3321 (mm-handle-cache handle)
3322 (mm-handle-id handle)))
3323 (push handle gnus-article-mime-handles)
3324 (gnus-mm-display-part handle))))
3326 (defun gnus-mime-copy-part (&optional handle)
3327 "Put the the MIME part under point into a new buffer."
3329 (gnus-article-check-buffer)
3330 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3331 (contents (and handle (mm-get-part handle)))
3333 (file-name-nondirectory
3335 (mail-content-type-get (mm-handle-type handle) 'name)
3336 (mail-content-type-get (mm-handle-type handle)
3339 (buffer (and base (generate-new-buffer base))))
3341 (switch-to-buffer buffer)
3343 ;; We do it this way to make `normal-mode' set the appropriate mode.
3346 (setq buffer-file-name (expand-file-name base))
3348 (setq buffer-file-name nil))
3349 (goto-char (point-min)))))
3351 (defun gnus-mime-inline-part (&optional handle arg)
3352 "Insert the MIME part under point into the current buffer."
3353 (interactive (list nil current-prefix-arg))
3354 (gnus-article-check-buffer)
3355 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3360 (if (and (not arg) (mm-handle-undisplayer handle))
3361 (mm-remove-part handle)
3362 (setq contents (mm-get-part handle))
3365 (setq charset (or (mail-content-type-get
3366 (mm-handle-type handle) 'charset)
3367 gnus-newsgroup-charset)))
3369 (if (mm-handle-undisplayer handle)
3370 (mm-remove-part handle))
3373 gnus-summary-show-article-charset-alist))
3374 (read-coding-system "Charset: ")))))
3376 (mm-insert-inline handle
3378 (setq charset (mm-charset-to-coding-system
3380 (not (eq charset 'ascii)))
3381 (mm-decode-coding-string contents charset)
3385 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3386 "Insert the MIME part under point into the current buffer."
3387 (interactive (list nil current-prefix-arg))
3388 (gnus-article-check-buffer)
3389 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3394 (if (mm-handle-undisplayer handle)
3395 (mm-remove-part handle))
3396 (let ((gnus-newsgroup-charset
3398 gnus-summary-show-article-charset-alist))
3399 (read-coding-system "Charset: ")))
3400 (gnus-newsgroup-ignored-charsets 'gnus-all))
3401 (gnus-article-press-button)))))
3403 (defun gnus-mime-externalize-part (&optional handle)
3404 "View the MIME part under point with an external viewer."
3406 (gnus-article-check-buffer)
3407 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3408 (mm-user-display-methods nil)
3409 (mm-inlined-types nil)
3410 (mail-parse-charset gnus-newsgroup-charset)
3411 (mail-parse-ignored-charsets
3412 (save-excursion (set-buffer gnus-summary-buffer)
3413 gnus-newsgroup-ignored-charsets)))
3415 (if (mm-handle-undisplayer handle)
3416 (mm-remove-part handle)
3417 (mm-display-part handle)))))
3419 (defun gnus-mime-internalize-part (&optional handle)
3420 "View the MIME part under point with an internal viewer.
3421 In no internal viewer is available, use an external viewer."
3423 (gnus-article-check-buffer)
3424 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3425 (mm-inlined-types '(".*"))
3426 (mm-inline-large-images t)
3427 (mail-parse-charset gnus-newsgroup-charset)
3428 (mail-parse-ignored-charsets
3429 (save-excursion (set-buffer gnus-summary-buffer)
3430 gnus-newsgroup-ignored-charsets)))
3432 (if (mm-handle-undisplayer handle)
3433 (mm-remove-part handle)
3434 (mm-display-part handle)))))
3436 (defun gnus-mime-action-on-part (&optional action)
3437 "Do something with the MIME attachment at \(point\)."
3439 (list (completing-read "Action: " gnus-mime-action-alist)))
3440 (gnus-article-check-buffer)
3441 (let ((action-pair (assoc action gnus-mime-action-alist)))
3443 (funcall (cdr action-pair)))))
3445 (defun gnus-article-part-wrapper (n function)
3446 (save-current-buffer
3447 (set-buffer gnus-article-buffer)
3448 (when (> n (length gnus-article-mime-handle-alist))
3449 (error "No such part"))
3450 (gnus-article-goto-part n)
3451 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3452 (funcall function handle))))
3454 (defun gnus-article-pipe-part (n)
3455 "Pipe MIME part N, which is the numerical prefix."
3457 (gnus-article-part-wrapper n 'mm-pipe-part))
3459 (defun gnus-article-save-part (n)
3460 "Save MIME part N, which is the numerical prefix."
3462 (gnus-article-part-wrapper n 'mm-save-part))
3464 (defun gnus-article-interactively-view-part (n)
3465 "View MIME part N interactively, which is the numerical prefix."
3467 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3469 (defun gnus-article-copy-part (n)
3470 "Copy MIME part N, which is the numerical prefix."
3472 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3474 (defun gnus-article-view-part-as-charset (n)
3475 "Copy MIME part N, which is the numerical prefix."
3477 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3479 (defun gnus-article-externalize-part (n)
3480 "View MIME part N externally, which is the numerical prefix."
3482 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3484 (defun gnus-article-inline-part (n)
3485 "Inline MIME part N, which is the numerical prefix."
3487 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3489 (defun gnus-article-mime-match-handle-first (condition)
3491 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3492 (while (setq ihandle (pop alist))
3494 ((functionp condition)
3495 (funcall condition (cdr ihandle)))
3496 ((eq condition 'undisplayed)
3497 (not (or (mm-handle-undisplayer (cdr ihandle))
3498 (equal (mm-handle-media-type (cdr ihandle))
3499 "multipart/alternative"))))
3500 ((eq condition 'undisplayed-alternative)
3501 (not (mm-handle-undisplayer (cdr ihandle))))
3503 (gnus-article-goto-part (car ihandle))
3504 (or (not n) (< (car ihandle) n)))
3505 (setq n (car ihandle))))
3509 (defun gnus-article-view-part (&optional n)
3510 "View MIME part N, which is the numerical prefix."
3512 (save-current-buffer
3513 (set-buffer gnus-article-buffer)
3514 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3515 gnus-article-mime-match-handle-function)))
3516 (when (> n (length gnus-article-mime-handle-alist))
3517 (error "No such part"))
3518 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3519 (when (gnus-article-goto-part n)
3520 (if (equal (car handle) "multipart/alternative")
3521 (gnus-article-press-button)
3522 (when (eq (gnus-mm-display-part handle) 'internal)
3523 (gnus-set-window-start)))))))
3525 (defsubst gnus-article-mime-total-parts ()
3526 (if (bufferp (car gnus-article-mime-handles))
3528 (1- (length gnus-article-mime-handles))))
3530 (defun gnus-mm-display-part (handle)
3531 "Display HANDLE and fix MIME button."
3532 (let ((id (get-text-property (point) 'gnus-part))
3537 (let ((window (selected-window))
3538 (mail-parse-charset gnus-newsgroup-charset)
3539 (mail-parse-ignored-charsets
3540 (save-excursion (set-buffer gnus-summary-buffer)
3541 gnus-newsgroup-ignored-charsets)))
3544 (let ((win (get-buffer-window (current-buffer) t))
3547 (select-window win))
3550 (if (mm-handle-displayed-p handle)
3551 ;; This will remove the part.
3552 (mm-display-part handle)
3554 (narrow-to-region (point) (1+ (point)))
3555 (mm-display-part handle)
3556 ;; We narrow to the part itself and
3557 ;; then call the treatment functions.
3558 (goto-char (point-min))
3560 (narrow-to-region (point) (point-max))
3563 (gnus-article-mime-total-parts)
3564 (mm-handle-media-type handle)))))
3565 (select-window window))))
3567 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3568 (gnus-insert-mime-button
3569 handle id (list (mm-handle-displayed-p handle)))
3570 (goto-char point))))
3572 (defun gnus-article-goto-part (n)
3573 "Go to MIME part N."
3574 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3576 (goto-char point))))
3578 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3579 (let ((gnus-tmp-name
3580 (or (mail-content-type-get (mm-handle-type handle)
3582 (mail-content-type-get (mm-handle-disposition handle)
3584 (mail-content-type-get (mm-handle-type handle)
3587 (gnus-tmp-type (mm-handle-media-type handle))
3588 (gnus-tmp-description
3589 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3592 (if (if displayed (car displayed)
3593 (mm-handle-displayed-p handle))
3595 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3597 gnus-tmp-type-long b e)
3598 (when (string-match ".*/" gnus-tmp-name)
3599 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3600 (setq gnus-tmp-type-long (concat gnus-tmp-type
3601 (and (not (equal gnus-tmp-name ""))
3602 (concat "; " gnus-tmp-name))))
3603 (or (equal gnus-tmp-description "")
3604 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3609 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3610 `(keymap ,gnus-mime-button-map
3611 ,@(if (>= (string-to-number emacs-version) 21)
3613 (list 'local-map gnus-mime-button-map))
3614 gnus-callback gnus-mm-display-part
3615 gnus-part ,gnus-tmp-id
3616 article-type annotation
3619 (widget-convert-button
3622 :action 'gnus-widget-press-button
3623 :button-keymap gnus-mime-button-map
3625 (lambda (widget/window &optional overlay pos)
3626 ;; Needed to properly clear the message due to a bug in
3627 ;; wid-edit (XEmacs only).
3628 (if (boundp 'help-echo-owns-message)
3629 (setq help-echo-owns-message t))
3631 "%S: %s the MIME part; %S: more options"
3632 (aref gnus-mouse-2 0)
3633 ;; XEmacs will get a single widget arg; Emacs 21 will get
3634 ;; window, overlay, position.
3635 (if (mm-handle-displayed-p
3637 (with-current-buffer (gnus-overlay-buffer overlay)
3638 (widget-get (widget-at (gnus-overlay-start overlay))
3640 (widget-get widget/window :mime-handle)))
3642 (aref gnus-down-mouse-3 0))))))
3644 (defun gnus-widget-press-button (elems el)
3645 (goto-char (widget-get elems :from))
3646 (gnus-article-press-button))
3648 (defvar gnus-displaying-mime nil)
3650 (defun gnus-display-mime (&optional ihandles)
3651 "Display the MIME parts."
3653 (save-selected-window
3654 (let ((window (get-buffer-window gnus-article-buffer))
3657 (select-window window)
3658 ;; We have to do this since selecting the window
3659 ;; may change the point. So we set the window point.
3660 (set-window-point window point)))
3661 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3662 buffer-read-only handle name type b e display)
3663 (when (and (not ihandles)
3664 (not gnus-displaying-mime))
3665 ;; Top-level call; we clean up.
3666 (when gnus-article-mime-handles
3667 (mm-destroy-parts gnus-article-mime-handles)
3668 (setq gnus-article-mime-handle-alist nil));; A trick.
3669 (setq gnus-article-mime-handles handles)
3670 ;; We allow users to glean info from the handles.
3671 (when gnus-article-mime-part-function
3672 (gnus-mime-part-function handles)))
3674 (or (not (stringp (car handles)))
3677 (when (and (not ihandles)
3678 (not gnus-displaying-mime))
3679 ;; Clean up for mime parts.
3681 (delete-region (point) (point-max)))
3682 (let ((gnus-displaying-mime t))
3683 (gnus-mime-display-part handles)))
3686 (narrow-to-region (point) (point-max))
3687 (gnus-treat-article nil 1 1)
3690 ;; Highlight the headers.
3694 (narrow-to-region (point-min) (point))
3695 (gnus-treat-article 'head))))))))
3697 (defvar gnus-mime-display-multipart-as-mixed nil)
3699 (defun gnus-mime-display-part (handle)
3702 ((not (stringp (car handle)))
3703 (gnus-mime-display-single handle))
3704 ;; User-defined multipart
3705 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3706 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3708 ;; multipart/alternative
3709 ((and (equal (car handle) "multipart/alternative")
3710 (not gnus-mime-display-multipart-as-mixed))
3711 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3712 (push (cons id handle) gnus-article-mime-handle-alist)
3713 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3714 ;; multipart/related
3715 ((and (equal (car handle) "multipart/related")
3716 (not gnus-mime-display-multipart-as-mixed))
3717 ;;;!!!We should find the start part, but we just default
3718 ;;;!!!to the first part.
3719 ;;(gnus-mime-display-part (cadr handle))
3720 ;;;!!! Most multipart/related is an HTML message plus images.
3721 ;;;!!! Unfortunately we are unable to let W3 display those
3722 ;;;!!! included images, so we just display it as a mixed multipart.
3723 ;;(gnus-mime-display-mixed (cdr handle))
3724 ;;;!!! No, w3 can display everything just fine.
3725 (gnus-mime-display-part (cadr handle)))
3726 ((equal (car handle) "multipart/signed")
3727 (or (memq 'signed gnus-article-wash-types)
3728 (push 'signed gnus-article-wash-types))
3729 (gnus-mime-display-security handle))
3730 ((equal (car handle) "multipart/encrypted")
3731 (or (memq 'encrypted gnus-article-wash-types)
3732 (push 'encrypted gnus-article-wash-types))
3733 (gnus-mime-display-security handle))
3734 ;; Other multiparts are handled like multipart/mixed.
3736 (gnus-mime-display-mixed (cdr handle)))))
3738 (defun gnus-mime-part-function (handles)
3739 (if (stringp (car handles))
3740 (mapcar 'gnus-mime-part-function (cdr handles))
3741 (funcall gnus-article-mime-part-function handles)))
3743 (defun gnus-mime-display-mixed (handles)
3744 (mapcar 'gnus-mime-display-part handles))
3746 (defun gnus-mime-display-single (handle)
3747 (let ((type (mm-handle-media-type handle))
3748 (ignored gnus-ignored-mime-types)
3755 (when (string-match (pop ignored) type)
3756 (throw 'ignored nil)))
3757 (if (and (setq not-attachment
3758 (and (not (mm-inline-override-p handle))
3759 (or (not (mm-handle-disposition handle))
3760 (equal (car (mm-handle-disposition handle))
3762 (mm-attachment-override-p handle))))
3763 (mm-automatic-display-p handle)
3764 (or (mm-inlined-p handle)
3765 (mm-automatic-external-display-p type)))
3767 (when (equal (mm-handle-media-supertype handle) "text")
3769 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3771 (push (cons id handle) gnus-article-mime-handle-alist)
3772 (when (or (not display)
3773 (not (gnus-unbuttonized-mime-type-p type)))
3774 ;(gnus-article-insert-newline)
3775 (gnus-insert-mime-button
3776 handle id (list (or display (and not-attachment text))))
3777 (gnus-article-insert-newline)
3778 ;(gnus-article-insert-newline)
3779 ;; Remember modify the number of forward lines.
3787 (let ((mail-parse-charset gnus-newsgroup-charset)
3788 (mail-parse-ignored-charsets
3789 (save-excursion (condition-case ()
3790 (set-buffer gnus-summary-buffer)
3792 gnus-newsgroup-ignored-charsets)))
3793 (mm-display-part handle t))
3794 (goto-char (point-max)))
3795 ((and text not-attachment)
3799 (gnus-article-insert-newline)
3800 (mm-insert-inline handle (mm-get-part handle))
3801 (goto-char (point-max))))
3805 (narrow-to-region beg (point))
3808 (gnus-article-mime-total-parts)
3809 (mm-handle-media-type handle)))))))))
3811 (defun gnus-unbuttonized-mime-type-p (type)
3812 "Say whether TYPE is to be unbuttonized."
3813 (unless gnus-inhibit-mime-unbuttonizing
3815 (let ((types gnus-unbuttonized-mime-types))
3817 (when (string-match (pop types) type)
3818 (throw 'found t)))))))
3820 (defun gnus-article-insert-newline ()
3821 "Insert a newline, but mark it as undeletable."
3822 (gnus-put-text-property
3823 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3825 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3826 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3829 handle buffer-read-only from props begend not-pref)
3830 (save-window-excursion
3833 (narrow-to-region (car ibegend)
3836 (goto-char (car ibegend))
3839 (delete-region (point-min) (point-max))
3840 (mm-remove-parts handles))
3841 (setq begend (list (point-marker)))
3843 (unless (setq not-pref (cadr (member preferred ihandles)))
3844 (setq not-pref (car ihandles)))
3847 (not (gnus-unbuttonized-mime-type-p
3848 "multipart/alternative")))
3849 (gnus-add-text-properties
3852 (insert (format "%d. " id))
3856 (unless ,(not ibegend)
3857 (setq gnus-article-mime-handle-alist
3858 ',gnus-article-mime-handle-alist))
3859 (gnus-mime-display-alternative
3860 ',ihandles ',not-pref ',begend ,id))
3861 ,@(if (>= (string-to-number emacs-version) 21)
3862 nil ;; XEmacs doesn't care
3863 (list 'local-map gnus-mime-button-map))
3864 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3865 face ,gnus-article-button-face
3866 keymap ,gnus-mime-button-map
3869 (widget-convert-button 'link from (point)
3870 :action 'gnus-widget-press-button
3871 :button-keymap gnus-widget-button-keymap)
3873 (while (setq handle (pop handles))
3874 (gnus-add-text-properties
3877 (insert (format "(%c) %-18s"
3878 (if (equal handle preferred) ?* ? )
3879 (mm-handle-media-type handle)))
3883 (unless ,(not ibegend)
3884 (setq gnus-article-mime-handle-alist
3885 ',gnus-article-mime-handle-alist))
3886 (gnus-mime-display-alternative
3887 ',ihandles ',handle ',begend ,id))
3888 ,@(if (>= (string-to-number emacs-version) 21)
3889 nil ;; XEmacs doesn't care
3890 (list 'local-map gnus-mime-button-map))
3891 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3892 face ,gnus-article-button-face
3893 keymap ,gnus-mime-button-map
3896 (widget-convert-button 'link from (point)
3897 :action 'gnus-widget-press-button
3898 :button-keymap gnus-widget-button-keymap)
3902 (if (stringp (car preferred))
3903 (gnus-display-mime preferred)
3904 (let ((mail-parse-charset gnus-newsgroup-charset)
3905 (mail-parse-ignored-charsets
3906 (save-excursion (set-buffer gnus-summary-buffer)
3907 gnus-newsgroup-ignored-charsets)))
3908 (mm-display-part preferred)
3912 (narrow-to-region (car begend) (point-max))
3914 nil (length gnus-article-mime-handle-alist)
3915 (gnus-article-mime-total-parts)
3916 (mm-handle-media-type handle))))))
3917 (goto-char (point-max))
3918 (setcdr begend (point-marker)))))
3920 (goto-char point))))
3922 (defun gnus-article-wash-status ()
3923 "Return a string which display status of article washing."
3925 (set-buffer gnus-article-buffer)
3926 (let ((cite (memq 'cite gnus-article-wash-types))
3927 (headers (memq 'headers gnus-article-wash-types))
3928 (boring (memq 'boring-headers gnus-article-wash-types))
3929 (pgp (memq 'pgp gnus-article-wash-types))
3930 (pem (memq 'pem gnus-article-wash-types))
3931 (signed (memq 'signed gnus-article-wash-types))
3932 (encrypted (memq 'encrypted gnus-article-wash-types))
3933 (signature (memq 'signature gnus-article-wash-types))
3934 (overstrike (memq 'overstrike gnus-article-wash-types))
3935 (emphasis (memq 'emphasis gnus-article-wash-types)))
3936 (format "%c%c%c%c%c%c"
3938 (if (or headers boring) ?h ? )
3939 (if (or pgp pem signed encrypted) ?p ? )
3940 (if signature ?s ? )
3941 (if overstrike ?o ? )
3942 (if emphasis ?e ? )))))
3944 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3946 (defun gnus-article-maybe-hide-headers ()
3947 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3948 Provided for backwards compatibility."
3949 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3950 (not (save-excursion (set-buffer gnus-summary-buffer)
3951 gnus-have-all-headers)))
3952 (not gnus-inhibit-hiding))
3953 (gnus-article-hide-headers)))
3957 (defun gnus-output-to-file (file-name)
3958 "Append the current article to a file named FILE-NAME."
3959 (let ((artbuf (current-buffer)))
3961 (insert-buffer-substring artbuf)
3962 ;; Append newline at end of the buffer as separator, and then
3964 (goto-char (point-max))
3966 (mm-append-to-file (point-min) (point-max) file-name)
3969 (defun gnus-narrow-to-page (&optional arg)
3970 "Narrow the article buffer to a page.
3971 If given a numerical ARG, move forward ARG pages."
3973 (setq arg (if arg (prefix-numeric-value arg) 0))
3975 (set-buffer gnus-article-buffer)
3976 (goto-char (point-min))
3978 ;; Remove any old next/prev buttons.
3979 (when (gnus-visual-p 'page-marker)
3980 (let ((buffer-read-only nil))
3981 (gnus-remove-text-with-property 'gnus-prev)
3982 (gnus-remove-text-with-property 'gnus-next)))
3985 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3987 (re-search-forward page-delimiter nil 'move arg)))
3988 (goto-char (match-end 0)))
3991 (if (re-search-forward page-delimiter nil 'move)
3994 (when (and (gnus-visual-p 'page-marker)
3995 (not (= (point-min) 1)))
3997 (goto-char (point-min))
3998 (gnus-insert-prev-page-button)))
3999 (when (and (gnus-visual-p 'page-marker)
4000 (< (+ (point-max) 2) (buffer-size)))
4002 (goto-char (point-max))
4003 (gnus-insert-next-page-button)))))
4005 ;; Article mode commands
4007 (defun gnus-article-goto-next-page ()
4008 "Show the next page of the article."
4010 (when (gnus-article-next-page)
4011 (goto-char (point-min))
4012 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4014 (defun gnus-article-goto-prev-page ()
4015 "Show the next page of the article."
4017 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4018 (gnus-article-prev-page nil)))
4020 (defun gnus-article-next-page (&optional lines)
4021 "Show the next page of the current article.
4022 If end of article, return non-nil. Otherwise return nil.
4023 Argument LINES specifies lines to be scrolled up."
4025 (move-to-window-line -1)
4028 (and (pos-visible-in-window-p) ;Not continuation line.
4030 ;; Nothing in this page.
4031 (if (or (not gnus-page-broken)
4034 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4036 (gnus-narrow-to-page 1) ;Go to next page.
4038 ;; More in this page.
4039 (let ((scroll-in-place nil))
4043 ;; Long lines may cause an end-of-buffer error.
4044 (goto-char (point-max)))))
4045 (move-to-window-line 0)
4048 (defun gnus-article-prev-page (&optional lines)
4049 "Show previous page of current article.
4050 Argument LINES specifies lines to be scrolled down."
4052 (move-to-window-line 0)
4053 (if (and gnus-page-broken
4055 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4057 (gnus-narrow-to-page -1) ;Go to previous page.
4058 (goto-char (point-max))
4060 (let ((scroll-in-place nil))
4064 (beginning-of-buffer
4065 (goto-char (point-min))))
4066 (move-to-window-line 0)))))
4068 (defun gnus-article-refer-article ()
4069 "Read article specified by message-id around point."
4071 (let ((point (point)))
4072 (search-forward ">" nil t) ;Move point to end of "<....>".
4073 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4074 (let ((message-id (match-string 1)))
4076 (set-buffer gnus-summary-buffer)
4077 (gnus-summary-refer-article message-id))
4079 (error "No references around point"))))
4081 (defun gnus-article-show-summary ()
4082 "Reconfigure windows to show summary buffer."
4084 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4085 (error "There is no summary buffer for this article buffer")
4086 (gnus-article-set-globals)
4087 (gnus-configure-windows 'article)
4088 (gnus-summary-goto-subject gnus-current-article)
4089 (gnus-summary-position-point)))
4091 (defun gnus-article-describe-briefly ()
4092 "Describe article mode commands briefly."
4094 (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")))
4096 (defun gnus-article-summary-command ()
4097 "Execute the last keystroke in the summary buffer."
4099 (let ((obuf (current-buffer))
4100 (owin (current-window-configuration))
4102 (switch-to-buffer gnus-article-current-summary 'norecord)
4103 (setq func (lookup-key (current-local-map) (this-command-keys)))
4104 (call-interactively func)
4106 (set-window-configuration owin)
4107 (set-window-point (get-buffer-window (current-buffer)) (point))))
4109 (defun gnus-article-summary-command-nosave ()
4110 "Execute the last keystroke in the summary buffer."
4113 (pop-to-buffer gnus-article-current-summary 'norecord)
4114 (setq func (lookup-key (current-local-map) (this-command-keys)))
4115 (call-interactively func)))
4117 (defun gnus-article-check-buffer ()
4118 "Beep if not in an article buffer."
4119 (unless (equal major-mode 'gnus-article-mode)
4120 (error "Command invoked outside of a Gnus article buffer")))
4122 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4123 "Read a summary buffer key sequence and execute it from the article buffer."
4125 (gnus-article-check-buffer)
4127 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4128 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4129 "=" "^" "\M-^" "|"))
4135 '("n" "Gn" "p" "Gp"))
4138 (set-buffer gnus-article-current-summary)
4139 (let (gnus-pick-mode)
4140 (push (or key last-command-event) unread-command-events)
4141 (setq keys (if (featurep 'xemacs)
4142 (events-to-keys (read-key-sequence nil))
4143 (read-key-sequence nil)))))
4147 (if (or (member keys nosaves)
4148 (member keys nosave-but-article)
4149 (member keys nosave-in-article))
4151 (save-window-excursion
4152 (pop-to-buffer gnus-article-current-summary 'norecord)
4153 ;; We disable the pick minor mode commands.
4154 (let (gnus-pick-mode)
4155 (setq func (lookup-key (current-local-map) keys))))
4159 (unless (member keys nosave-in-article)
4160 (set-buffer gnus-article-current-summary))
4161 (call-interactively func)
4162 (setq new-sum-point (point)))
4163 (when (member keys nosave-but-article)
4164 (pop-to-buffer gnus-article-buffer 'norecord)))
4165 ;; These commands should restore window configuration.
4166 (let ((obuf (current-buffer))
4167 (owin (current-window-configuration))
4169 (summary gnus-article-current-summary)
4170 func in-buffer selected)
4171 (if not-restore-window
4172 (pop-to-buffer summary 'norecord)
4173 (switch-to-buffer summary 'norecord))
4174 (setq in-buffer (current-buffer))
4175 ;; We disable the pick minor mode commands.
4176 (if (and (setq func (let (gnus-pick-mode)
4177 (lookup-key (current-local-map) keys)))
4180 (call-interactively func)
4181 (setq new-sum-point (point))
4182 (when (eq in-buffer (current-buffer))
4183 (setq selected (gnus-summary-select-article))
4185 (unless not-restore-window
4186 (set-window-configuration owin))
4187 (when (eq selected 'old)
4189 (set-window-start (get-buffer-window (current-buffer))
4191 (set-window-point (get-buffer-window (current-buffer))
4193 (let ((win (get-buffer-window gnus-article-current-summary)))
4195 (set-window-point win new-sum-point)))) )
4196 (switch-to-buffer gnus-article-buffer)
4199 (defun gnus-article-describe-key (key)
4200 "Display documentation of the function invoked by KEY. KEY is a string."
4201 (interactive "kDescribe key: ")
4202 (gnus-article-check-buffer)
4203 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4205 (set-buffer gnus-article-current-summary)
4206 (let (gnus-pick-mode)
4207 (push (elt key 0) unread-command-events)
4208 (setq key (if (featurep 'xemacs)
4209 (events-to-keys (read-key-sequence "Describe key: "))
4210 (read-key-sequence "Describe key: "))))
4212 (describe-key key)))
4214 (defun gnus-article-describe-key-briefly (key &optional insert)
4215 "Display documentation of the function invoked by KEY. KEY is a string."
4216 (interactive "kDescribe key: \nP")
4217 (gnus-article-check-buffer)
4218 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4220 (set-buffer gnus-article-current-summary)
4221 (let (gnus-pick-mode)
4222 (push (elt key 0) unread-command-events)
4223 (setq key (if (featurep 'xemacs)
4224 (events-to-keys (read-key-sequence "Describe key: "))
4225 (read-key-sequence "Describe key: "))))
4226 (describe-key-briefly key insert))
4227 (describe-key-briefly key insert)))
4229 (defun gnus-article-hide (&optional arg force)
4230 "Hide all the gruft in the current article.
4231 This means that PGP stuff, signatures, cited text and (some)
4232 headers will be hidden.
4233 If given a prefix, show the hidden text instead."
4234 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4235 (gnus-article-hide-headers arg)
4236 (gnus-article-hide-list-identifiers arg)
4237 (gnus-article-hide-pgp arg)
4238 (gnus-article-hide-citation-maybe arg force)
4239 (gnus-article-hide-signature arg))
4241 (defun gnus-article-maybe-highlight ()
4242 "Do some article highlighting if article highlighting is requested."
4243 (when (gnus-visual-p 'article-highlight 'highlight)
4244 (gnus-article-highlight-some)))
4246 (defun gnus-check-group-server ()
4247 ;; Make sure the connection to the server is alive.
4248 (unless (gnus-server-opened
4249 (gnus-find-method-for-group gnus-newsgroup-name))
4250 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4251 (gnus-request-group gnus-newsgroup-name t)))
4253 (defun gnus-request-article-this-buffer (article group)
4254 "Get an article and insert it into this buffer."
4255 (let (do-update-line sparse-header)
4259 (gnus-kill-all-overlays)
4260 (setq group (or group gnus-newsgroup-name))
4262 ;; Using `gnus-request-article' directly will insert the article into
4263 ;; `nntp-server-buffer' - so we'll save some time by not having to
4264 ;; copy it from the server buffer into the article buffer.
4266 ;; We only request an article by message-id when we do not have the
4267 ;; headers for it, so we'll have to get those.
4268 (when (stringp article)
4269 (gnus-read-header article))
4271 ;; If the article number is negative, that means that this article
4272 ;; doesn't belong in this newsgroup (possibly), so we find its
4273 ;; message-id and request it by id instead of number.
4274 (when (and (numberp article)
4276 (get-buffer gnus-summary-buffer)
4277 (gnus-buffer-exists-p gnus-summary-buffer))
4279 (set-buffer gnus-summary-buffer)
4280 (let ((header (gnus-summary-article-header article)))
4283 ((memq article gnus-newsgroup-sparse)
4284 ;; This is a sparse gap article.
4285 (setq do-update-line article)
4286 (setq article (mail-header-id header))
4287 (setq sparse-header (gnus-read-header article))
4288 (setq gnus-newsgroup-sparse
4289 (delq article gnus-newsgroup-sparse)))
4291 ;; It's a real article.
4292 (setq article (mail-header-id header)))
4294 ;; It is an extracted pseudo-article.
4295 (setq article 'pseudo)
4296 (gnus-request-pseudo-article header))))
4298 (let ((method (gnus-find-method-for-group
4299 gnus-newsgroup-name)))
4300 (when (and (eq (car method) 'nneething)
4302 (let ((dir (expand-file-name
4303 (mail-header-subject header)
4304 (file-name-as-directory
4305 (or (cadr (assq 'nneething-address method))
4307 (when (file-directory-p dir)
4308 (setq article 'nneething)
4309 (gnus-group-enter-directory dir))))))))
4312 ;; Refuse to select canceled articles.
4313 ((and (numberp article)
4315 (get-buffer gnus-summary-buffer)
4316 (gnus-buffer-exists-p gnus-summary-buffer)
4317 (eq (cdr (save-excursion
4318 (set-buffer gnus-summary-buffer)
4319 (assq article gnus-newsgroup-reads)))
4320 gnus-canceled-mark))
4322 ;; We first check `gnus-original-article-buffer'.
4323 ((and (get-buffer gnus-original-article-buffer)
4326 (set-buffer gnus-original-article-buffer)
4327 (and (equal (car gnus-original-article) group)
4328 (eq (cdr gnus-original-article) article))))
4329 (insert-buffer-substring gnus-original-article-buffer)
4331 ;; Check the backlog.
4332 ((and gnus-keep-backlog
4333 (gnus-backlog-request-article group article (current-buffer)))
4335 ;; Check asynchronous pre-fetch.
4336 ((gnus-async-request-fetched-article group article (current-buffer))
4337 (gnus-async-prefetch-next group article gnus-summary-buffer)
4338 (when (and (numberp article) gnus-keep-backlog)
4339 (gnus-backlog-enter-article group article (current-buffer)))
4342 ((and gnus-use-cache
4344 (gnus-cache-request-article article group))
4346 ;; Get the article and put into the article buffer.
4347 ((or (stringp article)
4349 (let ((gnus-override-method gnus-override-method)
4350 (methods (and (stringp article)
4351 gnus-refer-article-method))
4353 (buffer-read-only nil))
4354 (if (or (not (listp methods))
4355 (and (symbolp (car methods))
4356 (assq (car methods) nnoo-definition-alist)))
4357 (setq methods (list methods)))
4358 (when (and (null gnus-override-method)
4360 (setq gnus-override-method (pop methods)))
4362 (when (eq gnus-override-method 'current)
4363 (setq gnus-override-method gnus-current-select-method))
4365 (gnus-kill-all-overlays)
4366 (let ((gnus-newsgroup-name group))
4367 (gnus-check-group-server))
4368 (when (gnus-request-article article group (current-buffer))
4369 (when (numberp article)
4370 (gnus-async-prefetch-next group article
4371 gnus-summary-buffer)
4372 (when gnus-keep-backlog
4373 (gnus-backlog-enter-article
4374 group article (current-buffer))))
4375 (setq result 'article))
4378 (setq gnus-override-method (pop methods))
4379 (setq result 'done))))
4380 (and (eq result 'article) 'article)))
4384 ;; Associate this article with the current summary buffer.
4385 (setq gnus-article-current-summary gnus-summary-buffer)
4387 ;; Take the article from the original article buffer
4388 ;; and place it in the buffer it's supposed to be in.
4389 (when (and (get-buffer gnus-article-buffer)
4390 (equal (buffer-name (current-buffer))
4391 (buffer-name (get-buffer gnus-article-buffer))))
4393 (if (get-buffer gnus-original-article-buffer)
4394 (set-buffer gnus-original-article-buffer)
4395 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4396 (buffer-disable-undo)
4397 (setq major-mode 'gnus-original-article-mode)
4398 (setq buffer-read-only t))
4399 (let (buffer-read-only)
4401 (insert-buffer-substring gnus-article-buffer))
4402 (setq gnus-original-article (cons group article)))
4405 (run-hooks 'gnus-article-decode-hook)
4406 ;; Mark article as decoded or not.
4407 (setq gnus-article-decoded-p gnus-article-decode-hook))
4409 ;; Update sparse articles.
4410 (when (and do-update-line
4411 (or (numberp article)
4413 (let ((buf (current-buffer)))
4414 (set-buffer gnus-summary-buffer)
4415 (gnus-summary-update-article do-update-line sparse-header)
4416 (gnus-summary-goto-subject do-update-line nil t)
4417 (set-window-point (get-buffer-window (current-buffer) t)
4419 (set-buffer buf))))))
4425 (defcustom gnus-article-edit-mode-hook nil
4426 "Hook run in article edit mode buffers."
4427 :group 'gnus-article-various
4430 (defvar gnus-article-edit-done-function nil)
4432 (defvar gnus-article-edit-mode-map nil)
4434 ;; Should we be using derived.el for this?
4435 (unless gnus-article-edit-mode-map
4436 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4437 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4439 (gnus-define-keys gnus-article-edit-mode-map
4440 "\C-c\C-c" gnus-article-edit-done
4441 "\C-c\C-k" gnus-article-edit-exit)
4443 (gnus-define-keys (gnus-article-edit-wash-map
4444 "\C-c\C-w" gnus-article-edit-mode-map)
4445 "f" gnus-article-edit-full-stops))
4447 (defun gnus-article-edit-mode ()
4448 "Major mode for editing articles.
4449 This is an extended text-mode.
4451 \\{gnus-article-edit-mode-map}"
4453 (setq major-mode 'gnus-article-edit-mode)
4454 (setq mode-name "Article Edit")
4455 (use-local-map gnus-article-edit-mode-map)
4456 (make-local-variable 'gnus-article-edit-done-function)
4457 (make-local-variable 'gnus-prev-winconf)
4458 (setq buffer-read-only nil)
4459 (buffer-enable-undo)
4461 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4463 (defun gnus-article-edit (&optional force)
4464 "Edit the current article.
4465 This will have permanent effect only in mail groups.
4466 If FORCE is non-nil, allow editing of articles even in read-only
4469 (when (and (not force)
4470 (gnus-group-read-only-p))
4471 (error "The current newsgroup does not support article editing"))
4472 (gnus-article-date-original)
4473 (gnus-article-edit-article
4475 `(lambda (no-highlight)
4477 (gnus-summary-edit-article-done
4478 ,(or (mail-header-references gnus-current-headers) "")
4479 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4481 (defun gnus-article-edit-article (start-func exit-func)
4482 "Start editing the contents of the current article buffer."
4483 (let ((winconf (current-window-configuration)))
4484 (set-buffer gnus-article-buffer)
4485 (gnus-article-edit-mode)
4486 (funcall start-func)
4487 (gnus-configure-windows 'edit-article)
4488 (setq gnus-article-edit-done-function exit-func)
4489 (setq gnus-prev-winconf winconf)
4490 (gnus-message 6 "C-c C-c to end edits")))
4492 (defun gnus-article-edit-done (&optional arg)
4493 "Update the article edits and exit."
4495 (let ((func gnus-article-edit-done-function)
4496 (buf (current-buffer))
4497 (start (window-start)))
4498 (gnus-article-edit-exit)
4501 (let ((buffer-read-only nil))
4503 ;; The cache and backlog have to be flushed somewhat.
4504 (when gnus-keep-backlog
4505 (gnus-backlog-remove-article
4506 (car gnus-article-current) (cdr gnus-article-current)))
4507 ;; Flush original article as well.
4509 (when (get-buffer gnus-original-article-buffer)
4510 (set-buffer gnus-original-article-buffer)
4511 (setq gnus-original-article nil)))
4512 (when gnus-use-cache
4513 (gnus-cache-update-article
4514 (car gnus-article-current) (cdr gnus-article-current))))
4516 (set-window-start (get-buffer-window buf) start)
4517 (set-window-point (get-buffer-window buf) (point))))
4519 (defun gnus-article-edit-exit ()
4520 "Exit the article editing without updating."
4522 ;; We remove all text props from the article buffer.
4523 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4524 (curbuf (current-buffer))
4526 (window-start (window-start)))
4529 (let ((winconf gnus-prev-winconf))
4531 (set-window-configuration winconf)
4532 ;; Tippy-toe some to make sure that point remains where it was.
4533 (save-current-buffer
4535 (set-window-start (get-buffer-window (current-buffer)) window-start)
4538 (defun gnus-article-edit-full-stops ()
4539 "Interactively repair spacing at end of sentences."
4542 (goto-char (point-min))
4543 (search-forward-regexp "^$" nil t)
4544 (let ((case-fold-search nil))
4545 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4548 ;;; Article highlights
4551 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4553 ;;; Internal Variables:
4555 (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\\)\\)"
4556 "Regular expression that matches URLs."
4557 :group 'gnus-article-buttons
4560 (defcustom gnus-button-alist
4561 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4562 0 t gnus-button-message-id 2)
4563 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4564 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4566 gnus-button-fetch-group 4)
4567 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4568 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4569 t gnus-button-message-id 3)
4570 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4571 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4572 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4573 ;; This is how URLs _should_ be embedded in text...
4574 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4576 (,gnus-button-url-regexp 0 t browse-url 0))
4577 "*Alist of regexps matching buttons in article bodies.
4579 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4580 REGEXP: is the string matching text around the button,
4581 BUTTON: is the number of the regexp grouping actually matching the button,
4582 FORM: is a lisp expression which must eval to true for the button to
4584 CALLBACK: is the function to call when the user push this button, and each
4585 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4587 CALLBACK can also be a variable, in that case the value of that
4588 variable it the real callback function."
4589 :group 'gnus-article-buttons
4590 :type '(repeat (list regexp
4591 (integer :tag "Button")
4593 (function :tag "Callback")
4596 (integer :tag "Regexp group")))))
4598 (defcustom gnus-header-button-alist
4599 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4600 0 t gnus-button-message-id 0)
4601 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4602 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4603 0 t gnus-button-mailto 0)
4604 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4605 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4606 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4607 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4608 gnus-button-message-id 3))
4609 "*Alist of headers and regexps to match buttons in article heads.
4611 This alist is very similar to `gnus-button-alist', except that each
4612 alist has an additional HEADER element first in each entry:
4614 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4616 HEADER is a regexp to match a header. For a fuller explanation, see
4617 `gnus-button-alist'."
4618 :group 'gnus-article-buttons
4619 :group 'gnus-article-headers
4620 :type '(repeat (list (regexp :tag "Header")
4622 (integer :tag "Button")
4624 (function :tag "Callback")
4627 (integer :tag "Regexp group")))))
4629 (defvar gnus-button-regexp nil)
4630 (defvar gnus-button-marker-list nil)
4631 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4633 (defvar gnus-button-last nil)
4634 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4638 (defun gnus-article-push-button (event)
4639 "Check text under the mouse pointer for a callback function.
4640 If the text under the mouse pointer has a `gnus-callback' property,
4641 call it with the value of the `gnus-data' text property."
4643 (set-buffer (window-buffer (posn-window (event-start event))))
4644 (let* ((pos (posn-point (event-start event)))
4645 (data (get-text-property pos 'gnus-data))
4646 (fun (get-text-property pos 'gnus-callback)))
4649 (funcall fun data))))
4651 (defun gnus-article-press-button ()
4652 "Check text at point for a callback function.
4653 If the text at point has a `gnus-callback' property,
4654 call it with the value of the `gnus-data' text property."
4656 (let* ((data (get-text-property (point) 'gnus-data))
4657 (fun (get-text-property (point) 'gnus-callback)))
4659 (funcall fun data))))
4661 (defun gnus-article-highlight (&optional force)
4662 "Highlight current article.
4663 This function calls `gnus-article-highlight-headers',
4664 `gnus-article-highlight-citation',
4665 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4666 do the highlighting. See the documentation for those functions."
4667 (interactive (list 'force))
4668 (gnus-article-highlight-headers)
4669 (gnus-article-highlight-citation force)
4670 (gnus-article-highlight-signature)
4671 (gnus-article-add-buttons force)
4672 (gnus-article-add-buttons-to-head))
4674 (defun gnus-article-highlight-some (&optional force)
4675 "Highlight current article.
4676 This function calls `gnus-article-highlight-headers',
4677 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4678 do the highlighting. See the documentation for those functions."
4679 (interactive (list 'force))
4680 (gnus-article-highlight-headers)
4681 (gnus-article-highlight-signature)
4682 (gnus-article-add-buttons))
4684 (defun gnus-article-highlight-headers ()
4685 "Highlight article headers as specified by `gnus-header-face-alist'."
4688 (set-buffer gnus-article-buffer)
4690 (let ((alist gnus-header-face-alist)
4691 (buffer-read-only nil)
4692 (case-fold-search t)
4693 (inhibit-point-motion-hooks t)
4694 entry regexp header-face field-face from hpoints fpoints)
4695 (article-narrow-to-head)
4696 (while (setq entry (pop alist))
4697 (goto-char (point-min))
4698 (setq regexp (concat "^\\("
4699 (if (string-equal "" (nth 0 entry))
4703 header-face (nth 1 entry)
4704 field-face (nth 2 entry))
4705 (while (and (re-search-forward regexp nil t)
4709 (unless (search-forward ":" nil t)
4711 (when (and header-face
4712 (not (memq (point) hpoints)))
4713 (push (point) hpoints)
4714 (gnus-put-text-property from (point) 'face header-face))
4715 (when (and field-face
4716 (not (memq (setq from (point)) fpoints)))
4718 (if (re-search-forward "^[^ \t]" nil t)
4720 (goto-char (point-max)))
4721 (gnus-put-text-property from (point) 'face field-face))))))))
4723 (defun gnus-article-highlight-signature ()
4724 "Highlight the signature in an article.
4725 It does this by highlighting everything after
4726 `gnus-signature-separator' using `gnus-signature-face'."
4729 (set-buffer gnus-article-buffer)
4730 (let ((buffer-read-only nil)
4731 (inhibit-point-motion-hooks t))
4733 (when (and gnus-signature-face
4734 (gnus-article-narrow-to-signature))
4735 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4736 'face gnus-signature-face)
4738 (gnus-article-search-signature)
4739 (let ((start (match-beginning 0))
4740 (end (set-marker (make-marker) (1+ (match-end 0)))))
4741 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4744 (defun gnus-button-in-region-p (b e prop)
4745 "Say whether PROP exists in the region."
4746 (text-property-not-all b e prop nil))
4748 (defun gnus-article-add-buttons (&optional force)
4749 "Find external references in the article and make buttons of them.
4750 \"External references\" are things like Message-IDs and URLs, as
4751 specified by `gnus-button-alist'."
4752 (interactive (list 'force))
4754 (set-buffer gnus-article-buffer)
4755 (let ((buffer-read-only nil)
4756 (inhibit-point-motion-hooks t)
4757 (case-fold-search t)
4758 (alist gnus-button-alist)
4760 ;; Remove all old markers.
4761 (let (marker entry new-list)
4762 (while (setq marker (pop gnus-button-marker-list))
4763 (if (or (< marker (point-min)) (>= marker (point-max)))
4764 (push marker new-list)
4766 (when (setq entry (gnus-button-entry))
4767 (put-text-property (match-beginning (nth 1 entry))
4768 (match-end (nth 1 entry))
4769 'gnus-callback nil))
4770 (set-marker marker nil)))
4771 (setq gnus-button-marker-list new-list))
4772 ;; We skip the headers.
4775 (while (setq entry (pop alist))
4776 (setq regexp (car entry))
4778 (while (re-search-forward regexp nil t)
4779 (let* ((start (and entry (match-beginning (nth 1 entry))))
4780 (end (and entry (match-end (nth 1 entry))))
4781 (from (match-beginning 0)))
4782 (when (and (or (eq t (nth 2 entry))
4783 (eval (nth 2 entry)))
4784 (not (gnus-button-in-region-p
4785 start end 'gnus-callback)))
4786 ;; That optional form returned non-nil, so we add the
4788 (gnus-article-add-button
4789 start end 'gnus-button-push
4790 (car (push (set-marker (make-marker) from)
4791 gnus-button-marker-list))))))))))
4793 ;; Add buttons to the head of an article.
4794 (defun gnus-article-add-buttons-to-head ()
4795 "Add buttons to the head of the article."
4798 (set-buffer gnus-article-buffer)
4800 (let ((buffer-read-only nil)
4801 (inhibit-point-motion-hooks t)
4802 (case-fold-search t)
4803 (alist gnus-header-button-alist)
4805 (article-narrow-to-head)
4807 ;; Each alist entry.
4808 (setq entry (car alist)
4810 (goto-char (point-min))
4811 (while (re-search-forward (car entry) nil t)
4812 ;; Each header matching the entry.
4813 (setq beg (match-beginning 0))
4814 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4815 (match-beginning 0))
4818 (while (re-search-forward (nth 1 entry) end t)
4819 ;; Each match within a header.
4820 (let* ((entry (cdr entry))
4821 (start (match-beginning (nth 1 entry)))
4822 (end (match-end (nth 1 entry)))
4823 (form (nth 2 entry)))
4824 (goto-char (match-end 0))
4826 (gnus-article-add-button
4827 start end (nth 3 entry)
4828 (buffer-substring (match-beginning (nth 4 entry))
4829 (match-end (nth 4 entry)))))))
4830 (goto-char end)))))))
4832 ;;; External functions:
4834 (defun gnus-article-add-button (from to fun &optional data)
4835 "Create a button between FROM and TO with callback FUN and data DATA."
4836 (when gnus-article-button-face
4837 (gnus-overlay-put (gnus-make-overlay from to)
4838 'face gnus-article-button-face))
4839 (gnus-add-text-properties
4841 (nconc (and gnus-article-mouse-face
4842 (list gnus-mouse-face-prop gnus-article-mouse-face))
4843 (list 'gnus-callback fun)
4844 (and data (list 'gnus-data data))))
4845 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4846 :button-keymap gnus-widget-button-keymap))
4848 ;;; Internal functions:
4850 (defun gnus-article-set-globals ()
4852 (set-buffer gnus-summary-buffer)
4853 (gnus-set-global-variables)))
4855 (defun gnus-signature-toggle (end)
4857 (set-buffer gnus-article-buffer)
4858 (let ((buffer-read-only nil)
4859 (inhibit-point-motion-hooks t))
4860 (if (text-property-any end (point-max) 'article-type 'signature)
4861 (gnus-remove-text-properties-when
4862 'article-type 'signature end (point-max)
4863 (cons 'article-type (cons 'signature
4864 gnus-hidden-properties)))
4865 (gnus-add-text-properties-when
4866 'article-type nil end (point-max)
4867 (cons 'article-type (cons 'signature
4868 gnus-hidden-properties)))))))
4870 (defun gnus-button-entry ()
4871 ;; Return the first entry in `gnus-button-alist' matching this place.
4872 (let ((alist gnus-button-alist)
4875 (setq entry (pop alist))
4876 (if (looking-at (car entry))
4881 (defun gnus-button-push (marker)
4882 ;; Push button starting at MARKER.
4885 (let* ((entry (gnus-button-entry))
4886 (inhibit-point-motion-hooks t)
4888 (args (mapcar (lambda (group)
4889 (let ((string (match-string group)))
4890 (gnus-set-text-properties
4891 0 (length string) nil string)
4898 (fboundp (symbol-value fun)))
4899 (apply (symbol-value fun) args))
4901 (gnus-message 1 "You must define `%S' to use this button"
4902 (cons fun args)))))))
4904 (defun gnus-button-message-id (message-id)
4907 (set-buffer gnus-summary-buffer)
4908 (gnus-summary-refer-article message-id)))
4910 (defun gnus-button-fetch-group (address)
4911 "Fetch GROUP specified by ADDRESS."
4912 (if (not (string-match "[:/]" address))
4913 ;; This is just a simple group url.
4914 (gnus-group-read-ephemeral-group address gnus-select-method)
4915 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4917 (error "Can't parse %s" address)
4918 (gnus-group-read-ephemeral-group
4919 (match-string 4 address)
4920 `(nntp ,(match-string 1 address)
4921 (nntp-address ,(match-string 1 address))
4922 (nntp-port-number ,(if (match-end 3)
4923 (match-string 3 address)
4926 (defun gnus-url-parse-query-string (query &optional downcase)
4927 (let (retval pairs cur key val)
4928 (setq pairs (split-string query "&"))
4930 (setq cur (car pairs)
4932 (if (not (string-match "=" cur))
4934 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4935 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4937 (setq key (downcase key)))
4938 (setq cur (assoc key retval))
4940 (setcdr cur (cons val (cdr cur)))
4941 (setq retval (cons (list key val) retval)))))
4944 (defun gnus-url-unhex (x)
4951 (defun gnus-url-unhex-string (str &optional allow-newlines)
4952 "Remove %XXX embedded spaces, etc in a url.
4953 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4954 decoding of carriage returns and line feeds in the string, which is normally
4955 forbidden in URL encoding."
4956 (setq str (or str ""))
4958 (case-fold-search t))
4959 (while (string-match "%[0-9a-f][0-9a-f]" str)
4960 (let* ((start (match-beginning 0))
4961 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4963 (gnus-url-unhex (elt str (+ start 2))))))
4965 tmp (substring str 0 start)
4968 (char-to-string code))
4969 ((or (= code ?\n) (= code ?\r))
4971 (t (char-to-string code))))
4972 str (substring str (match-end 0)))))
4973 (setq tmp (concat tmp str))
4976 (defun gnus-url-mailto (url)
4977 ;; Send mail to someone
4978 (when (string-match "mailto:/*\\(.*\\)" url)
4979 (setq url (substring url (match-beginning 1) nil)))
4980 (let (to args subject func)
4981 (if (string-match (regexp-quote "?") url)
4982 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4983 args (gnus-url-parse-query-string
4984 (substring url (match-end 0) nil) t))
4985 (setq to (gnus-url-unhex-string url)))
4986 (setq args (cons (list "to" to) args)
4987 subject (cdr-safe (assoc "subject" args)))
4990 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4993 (message-position-on-field (caar args)))
4994 (insert (mapconcat 'identity (cdar args) ", "))
4995 (setq args (cdr args)))
4998 (message-goto-subject))))
5000 (defun gnus-button-mailto (address)
5002 (set-buffer (gnus-copy-article-buffer))
5003 (message-reply address))
5005 (defalias 'gnus-button-reply 'message-reply)
5007 (defun gnus-button-embedded-url (address)
5008 "Activate ADDRESS with `browse-url'."
5009 (browse-url (gnus-strip-whitespace address)))
5011 ;;; Next/prev buttons in the article buffer.
5013 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5014 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5016 (defvar gnus-prev-page-map nil)
5017 (unless gnus-prev-page-map
5018 (setq gnus-prev-page-map (make-sparse-keymap))
5019 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5020 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5022 (defun gnus-insert-prev-page-button ()
5023 (let ((buffer-read-only nil))
5025 gnus-prev-page-line-format nil
5026 `(gnus-prev t local-map ,gnus-prev-page-map
5027 gnus-callback gnus-article-button-prev-page
5028 article-type annotation))))
5030 (defvar gnus-next-page-map nil)
5031 (unless gnus-next-page-map
5032 (setq gnus-next-page-map (make-keymap))
5033 (suppress-keymap gnus-prev-page-map)
5034 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5035 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5037 (defun gnus-button-next-page ()
5038 "Go to the next page."
5040 (let ((win (selected-window)))
5041 (select-window (get-buffer-window gnus-article-buffer t))
5042 (gnus-article-next-page)
5043 (select-window win)))
5045 (defun gnus-button-prev-page ()
5046 "Go to the prev page."
5048 (let ((win (selected-window)))
5049 (select-window (get-buffer-window gnus-article-buffer t))
5050 (gnus-article-prev-page)
5051 (select-window win)))
5053 (defun gnus-insert-next-page-button ()
5054 (let ((buffer-read-only nil))
5055 (gnus-eval-format gnus-next-page-line-format nil
5057 t local-map ,gnus-next-page-map
5058 gnus-callback gnus-article-button-next-page
5059 article-type annotation))))
5061 (defun gnus-article-button-next-page (arg)
5062 "Go to the next page."
5064 (let ((win (selected-window)))
5065 (select-window (get-buffer-window gnus-article-buffer t))
5066 (gnus-article-next-page)
5067 (select-window win)))
5069 (defun gnus-article-button-prev-page (arg)
5070 "Go to the prev page."
5072 (let ((win (selected-window)))
5073 (select-window (get-buffer-window gnus-article-buffer t))
5074 (gnus-article-prev-page)
5075 (select-window win)))
5077 (defvar gnus-decode-header-methods
5078 '(mail-decode-encoded-word-region)
5079 "List of methods used to decode headers.
5081 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5082 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5083 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5084 whose names match REGEXP.
5087 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5088 mail-decode-encoded-word-region
5089 (\"chinese\" . rfc1843-decode-region))
5092 (defvar gnus-decode-header-methods-cache nil)
5094 (defun gnus-multi-decode-header (start end)
5095 "Apply the functions from `gnus-encoded-word-methods' that match."
5096 (unless (and gnus-decode-header-methods-cache
5097 (eq gnus-newsgroup-name
5098 (car gnus-decode-header-methods-cache)))
5099 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5102 (nconc gnus-decode-header-methods-cache (list x))
5103 (if (and gnus-newsgroup-name
5104 (string-match (car x) gnus-newsgroup-name))
5105 (nconc gnus-decode-header-methods-cache
5107 gnus-decode-header-methods))
5108 (let ((xlist gnus-decode-header-methods-cache))
5111 (narrow-to-region start end)
5113 (funcall (pop xlist) (point-min) (point-max))))))
5116 ;;; Treatment top-level handling.
5119 (defun gnus-treat-article (condition &optional part-number total-parts type)
5120 (let ((length (- (point-max) (point-min)))
5121 (alist gnus-treatment-function-alist)
5122 (article-goto-body-goes-to-point-min-p t)
5126 (let ((list gnus-article-treat-types))
5128 (when (string-match (pop list) type)
5129 (throw 'found t)))))))
5130 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5132 (gnus-run-hooks 'gnus-part-display-hook)
5133 (while (setq elem (pop alist))
5136 (if (gnus-buffer-live-p gnus-summary-buffer)
5137 (set-buffer gnus-summary-buffer))
5138 (symbol-value (car elem))))
5139 (when (and (or (consp val)
5141 (gnus-treat-predicate val)
5142 (or (not (get (car elem) 'highlight))
5145 (funcall (cadr elem)))))))
5147 ;; Dynamic variables.
5149 (defvar part-number)
5150 (defvar total-parts)
5155 (defun gnus-treat-predicate (val)
5160 (stringp (car val)))
5161 (apply 'gnus-or (mapcar `(lambda (s)
5162 (string-match s ,(or gnus-newsgroup-name "")))
5165 (let ((pred (pop val)))
5168 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5170 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5172 (not (gnus-treat-predicate (car val))))
5174 (equal (car val) type))
5176 (error "%S is not a valid predicate" pred)))))
5184 (eq part-number total-parts))
5188 (error "%S is not a valid value" val))))
5190 (defun gnus-article-encrypt-body (protocol &optional n)
5191 "Encrypt the article body."
5194 (or gnus-article-encrypt-protocol
5195 (completing-read "Encrypt protocol: "
5196 gnus-article-encrypt-protocol-alist
5198 current-prefix-arg))
5199 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5201 (error (format "Can't find the encrypt protocol %s" protocol)))
5202 (if (equal gnus-newsgroup-name "nndraft:drafts")
5203 (error "Can't encrypt the article in group nndraft:drafts."))
5204 (if (equal gnus-newsgroup-name "nndraft:queue")
5205 (error "Don't encrypt the article in group nndraft:queue."))
5206 (gnus-summary-iterate n
5208 (set-buffer gnus-summary-buffer)
5209 (let ((mail-parse-charset gnus-newsgroup-charset)
5210 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5211 (summary-buffer gnus-summary-buffer)
5213 (gnus-set-global-variables)
5214 (when (gnus-group-read-only-p)
5215 (error "The current newsgroup does not support article encrypt"))
5216 (gnus-summary-show-article t)
5218 (or (mail-header-references gnus-current-headers) ""))
5219 (set-buffer gnus-article-buffer)
5220 (let* ((buffer-read-only nil)
5222 (mapcar (lambda (field)
5223 (and (save-restriction
5224 (message-narrow-to-head)
5225 (goto-char (point-min))
5226 (search-forward field nil t))
5228 (message-narrow-to-field)
5229 (buffer-substring (point-min) (point-max))
5230 (delete-region (point-min) (point-max))
5232 '("Content-Type:" "Content-Transfer-Encoding:"
5233 "Content-Disposition:"))))
5234 (message-narrow-to-head)
5235 (message-remove-header "MIME-Version")
5236 (goto-char (point-max))
5237 (setq point (point))
5238 (insert (apply 'concat headers))
5240 (narrow-to-region point (point-max))
5241 (let ((message-options message-options))
5242 (message-options-set 'message-sender user-mail-address)
5243 (message-options-set 'message-recipients user-mail-address)
5244 (message-options-set 'message-sign-encrypt 'not)
5246 (goto-char (point-min))
5247 (insert "MIME-Version: 1.0\n")
5249 (gnus-summary-edit-article-done
5250 references nil summary-buffer t))
5251 (when gnus-keep-backlog
5252 (gnus-backlog-remove-article
5253 (car gnus-article-current) (cdr gnus-article-current)))
5255 (when (get-buffer gnus-original-article-buffer)
5256 (set-buffer gnus-original-article-buffer)
5257 (setq gnus-original-article nil)))
5258 (when gnus-use-cache
5259 (gnus-cache-update-article
5260 (car gnus-article-current) (cdr gnus-article-current))))))))
5262 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5263 "The following specs can be used:
5264 %t The security MIME type
5267 %D Details if button is pressed")
5269 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5270 "The following specs can be used:
5271 %t The security MIME type
5274 %D Details if button is pressed")
5276 (defvar gnus-mime-security-button-line-format-alist
5277 '((?t gnus-tmp-type ?s)
5278 (?i gnus-tmp-info ?s)
5279 (?d gnus-tmp-details ?s)
5280 (?D gnus-tmp-pressed-details ?s)))
5282 (defvar gnus-mime-security-button-map
5283 (let ((map (make-sparse-keymap)))
5284 (unless (>= (string-to-number emacs-version) 21)
5285 (set-keymap-parent map gnus-article-mode-map))
5286 (define-key map gnus-mouse-2 'gnus-article-push-button)
5287 (define-key map "\r" 'gnus-article-press-button)
5290 (defvar gnus-mime-security-details-buffer nil)
5292 (defvar gnus-mime-security-button-pressed nil)
5294 (defvar gnus-mime-security-show-details-inline t
5295 "If non-nil, show details in the article buffer.")
5297 (defun gnus-mime-security-verify-or-decrypt (handle)
5298 (mm-remove-parts (cdr handle))
5299 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5302 (delete-region (car region) (cdr region))
5303 (set-marker (car region) nil)
5304 (set-marker (cdr region) nil)))
5305 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5306 (let* ((mm-verify-option 'known)
5307 (mm-decrypt-option 'known)
5308 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5309 (unless (eq nparts (cdr handle))
5310 (mm-destroy-parts (cdr handle))
5311 (setcdr handle nparts))))
5312 (let ((point (point))
5314 (gnus-mime-display-security handle)
5317 (defun gnus-mime-security-show-details (handle)
5318 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5320 (if gnus-mime-security-show-details-inline
5321 (let ((gnus-mime-security-button-pressed t)
5322 (gnus-mime-security-button-line-format
5323 (get-text-property (point) 'gnus-line-format))
5326 (while (eq (get-text-property (point) 'gnus-line-format)
5327 gnus-mime-security-button-line-format)
5330 (delete-region (point)
5331 (or (text-property-not-all
5334 gnus-mime-security-button-line-format)
5336 (gnus-insert-mime-security-button handle))
5337 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5338 (with-current-buffer gnus-mime-security-details-buffer
5341 (setq gnus-mime-security-details-buffer
5342 (gnus-get-buffer-create "*MIME Security Details*")))
5343 (with-current-buffer gnus-mime-security-details-buffer
5345 (goto-char (point-min)))
5346 (pop-to-buffer gnus-mime-security-details-buffer))
5347 (gnus-message 5 "No details."))))
5349 (defun gnus-mime-security-press-button (handle)
5350 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5351 (gnus-mime-security-show-details handle)
5352 (gnus-mime-security-verify-or-decrypt handle)))
5354 (defun gnus-insert-mime-security-button (handle &optional displayed)
5355 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5358 (or (nth 2 (assoc protocol mm-verify-function-alist))
5359 (nth 2 (assoc protocol mm-decrypt-function-alist))
5361 (if (equal (car handle) "multipart/signed")
5362 " Signed" " Encrypted")
5365 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5368 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5369 gnus-tmp-pressed-details
5371 (setq gnus-tmp-details
5372 (if gnus-tmp-details
5373 (concat "\n" gnus-tmp-details) ""))
5374 (setq gnus-tmp-pressed-details
5375 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5380 gnus-mime-security-button-line-format
5381 gnus-mime-security-button-line-format-alist
5382 `(keymap ,gnus-mime-security-button-map
5383 ,@(if (>= (string-to-number emacs-version) 21)
5384 nil ;; XEmacs doesn't care
5385 (list 'local-map gnus-mime-security-button-map))
5386 gnus-callback gnus-mime-security-press-button
5387 gnus-line-format ,gnus-mime-security-button-line-format
5388 article-type annotation
5391 (widget-convert-button
5394 :action 'gnus-widget-press-button
5395 :button-keymap gnus-mime-security-button-map
5397 (lambda (widget/window &optional overlay pos)
5398 ;; Needed to properly clear the message due to a bug in
5399 ;; wid-edit (XEmacs only).
5400 (if (boundp 'help-echo-owns-message)
5401 (setq help-echo-owns-message t))
5404 (aref gnus-mouse-2 0))))))
5406 (defun gnus-mime-display-security (handle)
5408 (narrow-to-region (point) (point))
5409 (gnus-insert-mime-security-button handle)
5410 (gnus-mime-display-mixed (cdr handle))
5413 (let ((gnus-mime-security-button-line-format
5414 gnus-mime-security-button-end-line-format))
5415 (gnus-insert-mime-security-button handle))
5416 (mm-set-handle-multipart-parameter
5418 (cons (set-marker (make-marker) (point-min))
5419 (set-marker (make-marker) (point-max))))))
5425 (run-hooks 'gnus-art-load-hook)
5427 ;;; gnus-art.el ends here